* @author: Robert Bienert * @version: 1.3 * @date: 2009-01-04 * * Dieses Plugin schliesst nach einer bestimmten, festzulegenden * Laufzeit die Kommentare eines Artikels. * * Konstanten-Praefix: COMMENT_CLOSER */ define('COMMENT_CLOSER_CFG_FILE', JLOG_BASEPATH . 'personal' . DIRECTORY_SEPARATOR . 'settings.CommentCloser.inc.php'); if (@file_exists(COMMENT_CLOSER_CFG_FILE)) include_once COMMENT_CLOSER_CFG_FILE; class CommentCloser extends JlogPlugin { var $_units = array('SECOND', 'MINUTE', 'HOUR', 'DAY', 'WEEK', 'MONTH', 'YEAR', ); // Dieses Array kann lokalisiert werden: var $_unit_desc = array('Sekunden', 'Minuten', 'Stunden', 'Tagen', 'Wochen', 'Monaten', 'Jahren' ); // Konfigurationsoberflaeche function hook_adminContent($output) { $lifeTime = defined('COMMENT_CLOSER_LIFETIME') ? COMMENT_CLOSER_LIFETIME : ''; $timeUnit = defined('COMMENT_CLOSER_TIMEUNIT') ? COMMENT_CLOSER_TIMEUNIT : ''; $self = htmlspecialchars($_SERVER['REQUEST_URI']); if (array_key_exists('commclose_do', $_POST)) { $lifeTime = $_POST['commclose_lifetime']; $timeUnit = $_POST['commclose_unit']; // Einheiten pruefen if (! in_array($timeUnit, $this->_units)) $timeUnit = ''; // keine (negative) Zeit XXX implicit cast if ($lifeTime + 0 <= 0) $lifeTime = 0; # XXX MySQL bug: WEEK wird bei mir nicht # erkannt, deshalb manuelles Umrechnen: if ($timeUnit == 'WEEK') { $lifeTime *= 7; $timeUnit = 'DAY'; } $mask = umask(0); if (($f = @fopen(COMMENT_CLOSER_CFG_FILE, 'wb'))) { @fwrite($f, "'); @fclose($f); } umask($mask); } $output = <<

Nach der angegeben Zeit können Beiträge nicht mehr kommentiert werden.

EOT; return $output; } // Pruefen auf zu schliessende Beitraege function hook_onUpdate($data) { // Kein Schliessen gewuenscht, Plugin nicht konfiguriert // oder ungueltige Werte gesetzt: if (!defined('COMMENT_CLOSER_LIFETIME') || COMMENT_CLOSER_LIFETIME+0 <= 0 || !defined('COMMENT_CLOSER_TIMEUNIT') || !in_array(COMMENT_CLOSER_TIMEUNIT, $this->_units)) { return $data; } $q = new Query('UPDATE ' . JLOG_DB_PREFIX . 'content SET comments=0 ' . 'WHERE date < DATE_SUB(NOW(), INTERVAL ' . COMMENT_CLOSER_LIFETIME . ' ' . COMMENT_CLOSER_TIMEUNIT . ') AND comments=1'); # TODO error handling return $data; } } ?>