Update of /cvsroot/php-blog/serendipity/plugins/serendipity_plugin_shoutbox
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv6619/serendipity_plugin_shoutbox
Added Files:
serendipity_plugin_shoutbox.php
Log Message:
added contributed shoutbox plugin
--- NEW FILE: serendipity_plugin_shoutbox.php ---
<?php # $Id: serendipity_plugin_shoutbox.php,v 1.1 2004/03/16 08:59:37 garvinhicking Exp $
/* Contributed by Matthias Lange (http://blog.dinnri.de/ml/) */
switch ($serendipity['lang']) {
case 'de':
@define('PLUGIN_SHOUTBOX_NAME', 'Shoutbox');
@define('PLUGIN_SHOUTBOX_BLAHBLAH', 'Zeigt eine Shoutbox für beliebige Kommentare');
@define('PLUGIN_SHOUTBOX_WORDWRAP', 'Zeilenumbruch');
@define('PLUGIN_SHOUTBOX_WORDWRAP_BLAHBLAH', 'Nach wievielen Wörtern soll ein Zeilenumbruch eingefügt werden? (Standard: 30)');
@define('PLUGIN_SHOUTBOX_MAXCHARS', 'Zeichen pro Kommentar');
@define('PLUGIN_SHOUTBOX_MAXCHARS_BLAHBLAH', 'Wieviele Zeichen sollen pro Kommentar gezeigt werden? (Standard: 120)');
@define('PLUGIN_SHOUTBOX_MAXENTRIES', 'Anzahl an Kommentaren');
@define('PLUGIN_SHOUTBOX_MAXENTRIES_BLAHBLAH', 'Wieviele Kommentare sollen gezeigt werden? (Standard: 15)');
break;
case 'en':
case 'es':
default:
@define('PLUGIN_SHOUTBOX_NAME', 'Shoutbox');
@define('PLUGIN_SHOUTBOX_BLAHBLAH', 'Displays a shoutbox for unrelated comments');
@define('PLUGIN_SHOUTBOX_WORDWRAP', 'Wordwrap');
@define('PLUGIN_SHOUTBOX_WORDWRAP_BLAHBLAH', 'How many words until a wordwrap will occur? (Default: 30)');
@define('PLUGIN_SHOUTBOX_MAXCHARS', 'Maximum chars per comment');
@define('PLUGIN_SHOUTBOX_MAXCHARS_BLAHBLAH', 'How many chars will be displayed for each comment? (Default: 120)');
@define('PLUGIN_SHOUTBOX_MAXENTRIES', 'Maximum number of comments');
@define('PLUGIN_SHOUTBOX_MAXENTRIES_BLAHBLAH', 'How many comments will be shown? (Default: 15)');
break;
}
class serendipity_plugin_shoutbox extends serendipity_plugin
{
function introspect(&$propbag)
{
global $serendipity;
$propbag->add('name', PLUGIN_SHOUTBOX_NAME);
$propbag->add('description', PLUGIN_SHOUTBOX_BLAHBLAH);
$propbag->add('configuration', array(
'wordwrap',
'max_chars',
'max_entries',
'language',
'dateformat'));
if ($this->get_config('version') != '1.0') {
$q = "CREATE TABLE {$serendipity['dbPrefix']}shoutbox (
id {AUTOINCREMENT} {PRIMARY},
timestamp int(10) {UNSIGNED} NULL,
ip varchar(15) default NULL,
body text
)";
$sql = serendipity_db_schema_import($q);
$this->set_config('version', '1.0');
}
}
function introspect_config_item($name, &$propbag)
{
switch($name) {
case 'wordwrap':
$propbag->add('type', 'string');
$propbag->add('name', PLUGIN_SHOUTBOX_WORDWRAP);
$propbag->add('description', PLUGIN_SHOUTBOX_WORDWRAP_BLAHBLAH);
break;
case 'max_chars':
$propbag->add('type', 'string');
$propbag->add('name', PLUGIN_SHOUTBOX_MAXCHARS);
$propbag->add('description', PLUGIN_SHOUTBOX_MAXCHARS_BLAHBLAH);
break;
case 'max_entries':
$propbag->add('type', 'string');
$propbag->add('name', PLUGIN_SHOUTBOX_MAXENTRIES);
$propbag->add('description', PLUGIN_SHOUTBOX_MAXENTRIES_BLAHBLAH);
break;
case 'language':
$propbag->add('type', 'string');
$propbag->add('name', GENERAL_PLUGIN_LANGUAGE);
$propbag->add('description', GENERAL_PLUGIN_LANGUAGE_BLAHBLAH);
break;
case 'dateformat':
$propbag->add('type', 'string');
$propbag->add('name', GENERAL_PLUGIN_DATEFORMAT);
$propbag->add('description', sprintf(GENERAL_PLUGIN_DATEFORMAT_BLAHBLAH, '%a, %m.%m.%Y %H:%M'));
break;
default:
return false;
}
return true;
}
function generate_content(&$title)
{
global $serendipity;
$title = PLUGIN_SHOUTBOX_NAME;
$lang = strtolower($this->get_config('language'));
$max_entries = $this->get_config('max_entries');
$max_chars = $this->get_config('max_chars');
$wordwrap = $this->get_config('wordwrap');
$dateformat = $this->get_config('dateformat');
//Put new shout into the database if necessary
if ($_REQUEST['action'] == 'fillshoutbox' && $_REQUEST['serendipity']['shouttext'] != '') {
$sql = sprintf(
"INSERT INTO %sshoutbox (
timestamp,
ip,
body
) VALUES (
%s,
'%s',
'%s'
)",
$serendipity['dbPrefix'],
time(),
$_SERVER['REMOTE_ADDR'],
serendipity_db_escape_string($_REQUEST['serendipity']['shouttext']));
serendipity_db_query($sql);
}
if (!$max_entries || !is_numeric($max_entries) || $max_entries < 1) {
$max_entries = 15;
}
if (!$max_chars || !is_numeric($max_chars) || $max_chars < 1) {
$max_chars = 120;
}
if (!$wordwrap || !is_numeric($wordwrap) || $wordwrap < 1) {
$wordwrap = 30;
}
if (!$dateformat || strlen($dateformat) < 1) {
$dateformat = '%a, %d.%m.%Y %H:%M';
}
if ($lang != 'de' && $lang != 'en') {
$lang = 'en';
}
switch($lang) {
case 'de':
$loc = setlocale(LC_ALL, 'de_DE');
if (!$loc) $loc = setlocale(LC_ALL, 'de');
break;
case 'en':
$loc = setlocale(LC_ALL, 'en_US');
if (!$loc) $loc = setlocale(LC_ALL, 'en');
break;
}
?>
<form action="<?php echo $_SERVER['REQUEST_URI']; ?>" method="post">
<div>
<input type="hidden" name="action" value="fillshoutbox" />
<textarea name="serendipity[shouttext]" rows="4" style="width: 90%"></textarea>
<input name='submit' type='submit' value='Abschicken' />
</div>
</form><br />
<?php
$q = 'SELECT s.body AS comment,
s.timestamp AS stamp,
s.id AS comment_id
FROM '.$serendipity['dbPrefix'].'shoutbox AS s
ORDER BY s.timestamp DESC
LIMIT ' . $max_entries;
?>
<div style="margin: 0px; padding: 0px; text-align: left;">
<?php
$sql = serendipity_db_query($q);
if ($sql && is_array($sql)) {
foreach($sql AS $key => $row) {
$comments = wordwrap(strip_tags($row['comment']), $max_chars, '@@@', 1);
$aComment = explode('@@@', $comments);
$comment = $aComment[0];
$entry = array('comment' => wordwrap($comment, $wordwrap, "\n"));
serendipity_plugin_api::hook_event('frontend_display', $entry);
echo "<b>" . htmlentities(strftime($dateformat, $row['stamp'])) . "</b><br />\n"
. $entry['comment']
. "<br /><br /><br />\n\n";
}
}
?>
</div>
<?php
}
}
/* vim: set sts=4 ts=4 expandtab : */
?>
|