<?php
/*
* buzzword
* Copyright (c) 2003 Jon Tai
*
* $Id: display.inc 267 2004-03-31 03:14:55Z bradt $
*
* This file is part of buzzword.
*
* buzzword is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* buzzword is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with buzzword; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
// format an author
function get_display_author($author, $email, $email_is_private) {
if ( ( (defined('ADMIN_LOGGED_IN')) || (!$email_is_private) ) && ($email != '') )
return "<a href=\"mailto:".htmlspecialchars($email)."\">$author</a>";
return $author;
}
// convert $string\n\n => <p>$string</p>\n
// and $string\n => $string<br>\n
// (thanks, http://photomatt.net/scripts/autop)
function nl2p($string) {
$string = preg_replace("/(\r\n|\n|\r)/", "\n", $string); // cross-platform newlines
$string = preg_replace("/\n\n+/", "\n\n", $string); // take care of duplicates
$string = preg_replace('/\n?(.+?)(\n\n|\z)/s', "<p>$1</p>\n", $string); // make paragraphs, including one at the end
$string = preg_replace('/<p>(<(?:table|[ou]l|li|pre|select|form|blockquote)>)/', "$1", $string);
$string = preg_replace('!(</?(?:table|[ou]l|li|pre|select|form|blockquote)>)</p>!', "$1", $string);
$string = preg_replace('|(?<!</p>)\s*\n|', "<br />\n", $string); // optionally make line breaks
$string = preg_replace('!(<(?:table|[ou]l|li|pre|select|form|blockquote)>)<br />!', "$1", $string);
$string = preg_replace('!(</(?:table|[ou]l|li|pre|select|form|blockquote)>)<br />!', "$1", $string);
$string = str_replace('<p><p>', '<p>', $string);
$string = str_replace('</p></p>', '</p>', $string);
return $string;
}
// truncate a string on a word boundary
function str_trunc($string, $length, $title_tag) {
if (strlen($string) <= $length)
return ($title_tag) ?
"<span title=\"".htmlspecialchars(strip_tags($string))."\">$string</span>":
$string;
// allowable tags must be close-able in any order,
// so for example, <tr> and <td>'s wouldn't work.
$allowable_tags = array('p', 'b', 'i', 'u', 'a');
$newstring = '';
$words = explode(' ', strip_tags($string, '<'.join('><', $allowable_tags).'>'));
foreach ($words as $word) {
if (strlen("$newstring $word") > $length) {
foreach ($allowable_tags as $tag) {
$open_tags = substr_count(strtolower($newstring), '<'.$tag);
$close_tags = substr_count(strtolower($newstring), '</'.$tag);
if ($open_tags > $close_tags)
$newstring .= str_repeat('</'.$tag.'>', $open_tags - $close_tags);
}
return ($title_tag) ?
"<span title=\"".htmlspecialchars(strip_tags($string))."\">$newstring...</span>":
"$newstring...";
}
$newstring .= "$word ";
}
}
// display a singular or plural string
function str_plural($count, $singular, $plural) {
if ($count == 0)
return "no $plural";
if ($count == 1)
return "1 $singular";
return number_format($count).' '.$plural;
}
function stylesheet_hook() {
$stylesheets = '';
global $BUZZWORD_HOOKS;
if (!is_array($BUZZWORD_HOOKS['stylesheet']))
return $stylesheets;
sort($BUZZWORD_HOOKS['stylesheet']);
foreach ($BUZZWORD_HOOKS['stylesheet'] as $hook)
$stylesheets .= "<link rel=\"stylesheet\" type=\"text/css\" href=\"{$hook[1]}\">\n";
return $stylesheets;
}
function javascript_hook() {
$scripts = '';
global $BUZZWORD_HOOKS;
if (!is_array($BUZZWORD_HOOKS['javascript']))
return $scripts;
sort($BUZZWORD_HOOKS['javascript']);
foreach ($BUZZWORD_HOOKS['javascript'] as $hook)
$scripts .= "<script language=\"JavaScript\" type=\"text/javascript\" src=\"{$hook[1]}\"></script>\n";
return $scripts;
}
function navigation_hook() {
$navigation = '';
global $BUZZWORD_HOOKS;
if (!is_array($BUZZWORD_HOOKS['navigation']))
return $navigation;
sort($BUZZWORD_HOOKS['navigation']);
foreach ($BUZZWORD_HOOKS['navigation'] as $hook)
$navigation .= "<a href=\"{$hook[1]}\">{$hook[2]}</a>\n";
return $navigation;
}
// toolbar that inserts common HTML elements
function toolbar_hook($form_name, $element_name) {
$toolbar = "<div class=\"toolbar\">\n";
$toolbar .= "<a href=\"#\" onClick=\"insert_hyperlink(document.$form_name.$element_name); return false;\"><img \n";
$toolbar .= " src=\"../images/toolbar-hyperlink.gif\" alt=\"Hyperlink\" title=\"Hyperlink\" \n";
$toolbar .= " border=\"0\" width=\"22\" height=\"21\"></a>\n";
$toolbar .= "<a href=\"#\" onClick=\"insert_bold_text(document.$form_name.$element_name); return false;\"><img \n";
$toolbar .= " src=\"../images/toolbar-bold.gif\" alt=\"Bold\" title=\"Bold\" \n";
$toolbar .= " border=\"0\" width=\"22\" height=\"21\"></a>\n";
$toolbar .= "<a href=\"#\" onClick=\"insert_italic_text(document.$form_name.$element_name); return false;\"><img \n";
$toolbar .= " src=\"../images/toolbar-italic.gif\" alt=\"Italic\" title=\"Italic\" \n";
$toolbar .= " border=\"0\" width=\"22\" height=\"21\"></a>\n";
$toolbar .= "<a href=\"#\" onClick=\"insert_underlined_text(document.$form_name.$element_name); return false;\"><img \n";
$toolbar .= " src=\"../images/toolbar-underline.gif\" alt=\"Underline\" title=\"Underline\" \n";
$toolbar .= " border=\"0\" width=\"22\" height=\"21\"></a>\n";
$toolbar .= "<a href=\"#\" onClick=\"insert_ordered_list(document.$form_name.$element_name); return false;\"><img \n";
$toolbar .= " src=\"../images/toolbar-ordered-list.gif\" alt=\"Numbering\" title=\"Numbering\" \n";
$toolbar .= " border=\"0\" width=\"22\" height=\"21\"></a>\n";
$toolbar .= "<a href=\"#\" onClick=\"insert_unordered_list(document.$form_name.$element_name); return false;\"><img \n";
$toolbar .= " src=\"../images/toolbar-unordered-list.gif\" alt=\"Bullets\" title=\"Bullets\" \n";
$toolbar .= " border=\"0\" width=\"22\" height=\"21\"></a>\n";
$toolbar .= "<a href=\"#\" onClick=\"insert_horizontal_rule(document.$form_name.$element_name); return false;\"><img \n";
$toolbar .= " src=\"../images/toolbar-horizontal-rule.gif\" alt=\"Horizontal Rule\" title=\"Horizontal Rule\" \n";
$toolbar .= " border=\"0\" width=\"22\" height=\"21\"></a>\n";
global $BUZZWORD_HOOKS;
if (!is_array($BUZZWORD_HOOKS['toolbar']))
return "$toolbar</div>\n";
sort($BUZZWORD_HOOKS['toolbar']);
foreach ($BUZZWORD_HOOKS['toolbar'] as $hook) {
$callback = $hook[1];
$toolbar .= $callback($form_name, $element_name);
}
$toolbar .= "</div>\n";
return $toolbar;
}
function longtext_hook($string) {
global $BUZZWORD_HOOKS;
if (!is_array($BUZZWORD_HOOKS['longtext']))
return $string;
sort($BUZZWORD_HOOKS['longtext']);
foreach ($BUZZWORD_HOOKS['longtext'] as $hook) {
$callback = $hook[1];
$string = $callback($string);
}
return $string;
}
?>