| [ Index ] |
|
Code source de Serendipity 1.2 |
1 <?php # $Id: serendipity_plugin_shoutbox.php 692 2005-11-13 07:15:39Z elf2000 $ 2 3 /* Contributed by Matthias Lange (http://blog.dinnri.de/ml/) */ 4 5 // Probe for a language include with constants. Still include defines later on, if some constants were missing 6 $probelang = dirname(__FILE__) . '/' . $serendipity['charset'] . 'lang_' . $serendipity['lang'] . '.inc.php'; 7 if (file_exists($probelang)) { 8 include $probelang; 9 } 10 11 include dirname(__FILE__) . '/lang_en.inc.php'; 12 13 class serendipity_plugin_shoutbox extends serendipity_plugin 14 { 15 var $title = PLUGIN_SHOUTBOX_NAME; 16 17 function introspect(&$propbag) 18 { 19 global $serendipity; 20 21 $propbag->add('name', PLUGIN_SHOUTBOX_NAME); 22 $propbag->add('description', PLUGIN_SHOUTBOX_BLAHBLAH); 23 $propbag->add('stackable', false); 24 $propbag->add('author', 'Matthias Lange'); 25 $propbag->add('version', '1.01'); 26 $propbag->add('requirements', array( 27 'serendipity' => '0.8', 28 'smarty' => '2.6.7', 29 'php' => '4.1.0' 30 )); 31 32 $propbag->add('configuration', array( 33 'wordwrap', 34 'max_chars', 35 'max_entries', 36 'dateformat')); 37 $propbag->add('groups', array('FRONTEND_FEATURES')); 38 } 39 40 function introspect_config_item($name, &$propbag) 41 { 42 switch($name) { 43 case 'wordwrap': 44 $propbag->add('type', 'string'); 45 $propbag->add('name', PLUGIN_SHOUTBOX_WORDWRAP); 46 $propbag->add('description', PLUGIN_SHOUTBOX_WORDWRAP_BLAHBLAH); 47 $propbag->add('default', 30); 48 break; 49 50 case 'max_chars': 51 $propbag->add('type', 'string'); 52 $propbag->add('name', PLUGIN_SHOUTBOX_MAXCHARS); 53 $propbag->add('description', PLUGIN_SHOUTBOX_MAXCHARS_BLAHBLAH); 54 $propbag->add('default', 120); 55 break; 56 57 case 'max_entries': 58 $propbag->add('type', 'string'); 59 $propbag->add('name', PLUGIN_SHOUTBOX_MAXENTRIES); 60 $propbag->add('description', PLUGIN_SHOUTBOX_MAXENTRIES_BLAHBLAH); 61 $propbag->add('default', 15); 62 break; 63 64 case 'dateformat': 65 $propbag->add('type', 'string'); 66 $propbag->add('name', GENERAL_PLUGIN_DATEFORMAT); 67 $propbag->add('description', sprintf(GENERAL_PLUGIN_DATEFORMAT_BLAHBLAH, '%a, %m.%m.%Y %H:%M')); 68 $propbag->add('default', '%a, %d.%m.%Y %H:%M'); 69 break; 70 71 default: 72 return false; 73 } 74 return true; 75 } 76 77 function generate_content(&$title) 78 { 79 global $serendipity; 80 81 $title = $this->title; 82 $max_entries = $this->get_config('max_entries'); 83 $max_chars = $this->get_config('max_chars'); 84 $wordwrap = $this->get_config('wordwrap'); 85 $dateformat = $this->get_config('dateformat'); 86 87 // Create table, if not yet existant 88 if ($this->get_config('version') != '1.0') { 89 $q = "CREATE TABLE {$serendipity['dbPrefix']}shoutbox ( 90 id {AUTOINCREMENT} {PRIMARY}, 91 timestamp int(10) {UNSIGNED} NULL, 92 ip varchar(15) default NULL, 93 body text 94 )"; 95 $sql = serendipity_db_schema_import($q); 96 $this->set_config('version', '1.0'); 97 } 98 99 //Put new shout into the database if necessary 100 if (!empty($_REQUEST['action']) && $_REQUEST['action'] == 'fillshoutbox' && $_REQUEST['serendipity']['shouttext'] != '') { 101 102 $sql = sprintf( 103 "INSERT INTO %sshoutbox ( 104 timestamp, 105 ip, 106 body 107 ) VALUES ( 108 %s, 109 '%s', 110 '%s' 111 )", 112 113 $serendipity['dbPrefix'], 114 time(), 115 serendipity_db_escape_string($_SERVER['REMOTE_ADDR']), 116 serendipity_db_escape_string($_REQUEST['serendipity']['shouttext'])); 117 serendipity_db_query($sql); 118 } 119 if (!empty($serendipity['GET']['action']) && $serendipity['GET']['action'] == 'shoutboxdelete' 120 && $_SESSION['serendipityAuthedUser'] === true) { 121 $sql = sprintf("DELETE from %sshoutbox 122 WHERE id = %d", 123 $serendipity['dbPrefix'], 124 (int)$serendipity['GET']['comment_id']); 125 serendipity_db_query($sql); 126 } 127 128 if (!$max_entries || !is_numeric($max_entries) || $max_entries < 1) { 129 $max_entries = 15; 130 } 131 132 if (!$max_chars || !is_numeric($max_chars) || $max_chars < 1) { 133 $max_chars = 120; 134 } 135 136 if (!$wordwrap || !is_numeric($wordwrap) || $wordwrap < 1) { 137 $wordwrap = 30; 138 } 139 140 if (!$dateformat || strlen($dateformat) < 1) { 141 $dateformat = '%a, %d.%m.%Y %H:%M'; 142 } 143 ?> 144 <form action="<?php echo serendipity_currentURL(); ?>" method="post"> 145 <div> 146 <input type="hidden" name="action" value="fillshoutbox" /> 147 <textarea name="serendipity[shouttext]" rows="4" cols="15" style="width: 90%"></textarea> 148 <input name='submit' type='submit' value='<?php echo PLUGIN_SHOUTBOX_SUBMIT; ?>' /> 149 </div> 150 </form><br /> 151 <?php 152 $q = 'SELECT s.body AS comment, 153 s.timestamp AS stamp, 154 s.id AS comment_id 155 FROM '.$serendipity['dbPrefix'].'shoutbox AS s 156 ORDER BY s.timestamp DESC 157 LIMIT ' . $max_entries; 158 ?> 159 <div style="margin: 0px; padding: 0px; text-align: left;"> 160 <?php 161 $sql = serendipity_db_query($q); 162 if ($sql && is_array($sql)) { 163 foreach($sql AS $key => $row) { 164 $comments = wordwrap(strip_tags($row['comment']), $max_chars, '@@@', 1); 165 $aComment = explode('@@@', $comments); 166 $comment = $aComment[0]; 167 if (count($aComment) > 1) { 168 $comment .= ' [...]'; 169 } 170 171 $deleteLink = ""; 172 if ($_SESSION['serendipityAuthedUser'] === true) { 173 $deleteLink = ' | <a href="' . $serendipity['baseURL'] 174 . '?serendipity[action]=shoutboxdelete&serendipity[comment_id]=' 175 . $row['comment_id'] . '">' . PLUGIN_SHOUTBOX_DELETE . '</a>'; 176 } 177 $entry = array('comment' => $comment); 178 serendipity_plugin_api::hook_event('frontend_display', $entry); 179 $entry['comment'] = wordwrap($entry['comment'], $wordwrap, "\n", 1); 180 181 echo "<b>" . htmlspecialchars(serendipity_strftime($dateformat, $row['stamp'])) . '</b> <br />' . "\n" 182 . $entry['comment'] 183 . $deleteLink 184 . '<br /><br /><br />' . "\n\n"; 185 } 186 } 187 ?> 188 </div> 189 <?php 190 } 191 } 192 193 /* vim: set sts=4 ts=4 expandtab : */ 194 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
| Généré le : Sat Nov 24 09:00:37 2007 | par Balluche grâce à PHPXref 0.7 |
|