====== Modificare plugin Discussion per usarlo sul blog di Dokuwiki ====== Autore: **//Fabio Di Matteo//** \\ Ultima revisione: **//17/09/2008//** \\ \\ Potrebbe capitare di voler usare il software cms Dokuwiki per creare un blog e si potrebbe avere l'esigenza di attivare il plugin per i commenti (Discussion). E fin qui nulla di strano, tranne che non esiste un sistema di notifica dei commenti, ovvero se non si va a guardare nel blog non si sarà informati sull'invio di nuovi commenti. \\ // Lo scopo di questa guida e' creare un sistema di notifica dei commenti e fare in modo che i commenti inviati vengano pubblicati solo dopo che l'amministratore li abbia moderati. // ===== Quello che serve ===== - [[http://wiki.splitbrain.org/wiki:dokuwiki|Dokuwiki]] - [[http://wiki.splitbrain.org/plugin:discussion|Plugin Discussion]] 2008-08-08 ===== Scriviamo il sistema di notifica dei commenti ===== Il sistema di notifica dei commenti farà le seguenti cose: - Ci informerà via mail dell'invio di un commento - scriverà su un file di log ip, data commento e posta elettronica dell'utente. Per prima cosa è necessario installare il **plugin Discussion ** dopodichè si dovrà provvedere a modificare il file ''{dokuwiki}/lib/plugins/discussion/action.php'' aggiungendo il codice qui sotto dentro la funzione ''function _notify($comment, $subscribers) '' : Ecco solo il codice da aggiungere,nella funzione ''function _notify($comment, $subscribers) '' invece nel paragra successivo pubblico la funzione nella sua interezza (contenuta sempre nel file ''{dokuwiki}/lib/plugins/discussion/action.php'' . //Notifica sempre all'amministratore $replace = array( $ID, $conf['title'], strftime($conf['dformat'], $comment['date']['created']), $comment['user']['name'], $comment['raw'], wl($ID, '', true) . '#comment__' . $comment['cid'], wl($ID, 'do=unsubscribe&hash=' . $hash, true, '&'), DOKU_URL, ); $admin_mails="admin@fml.org"; $body = str_replace($search, $replace, $text); mail_send($admin_mails, $subject, $body, $conf['mailfrom']); //fine notifica all'amministratore **Non e' il caso di scrivere le istruzioni per implementare il sistema dei log, in quanto i log di tutti i commenti stanno nel file ** ''{dokuwiki}/data/meta/_comments.changes'' . ===== La funzione _notify($comment, $subscribers) modificata ===== Codice relativo alla versione al plugin Discussion 2008-08-08 . function _notify($comment, $subscribers) { global $conf; global $ID; $text = io_readfile($this->localfn('subscribermail')); $subject = '['.$conf['title'].'] '.$this->getLang('mail_newcomment'); $search = array( '@PAGE@', '@TITLE@', '@DATE@', '@NAME@', '@TEXT@', '@COMMENTURL@', '@UNSUBSCRIBE@', '@DOKUWIKIURL@', ); // notify page subscribers if (($conf['subscribers']) && ($conf['notify'])) { $bcc = subscriber_addresslist($ID); $to = $conf['notify']; $replace = array( $ID, $conf['title'], strftime($conf['dformat'], $comment['date']['created']), $comment['user']['name'], $comment['raw'], wl($ID, '', true) . '#comment__' . $comment['cid'], wl($ID, 'do=unsubscribe', true, '&'), DOKU_URL, ); $body = str_replace($search, $replace, $text); mail_send($to, $subject, $body, $conf['mailfrom'], '', $bcc); } // notify comment subscribers if (!empty($subscribers)) { foreach($subscribers as $mail => $hash) { $to = $mail; $replace = array( $ID, $conf['title'], strftime($conf['dformat'], $comment['date']['created']), $comment['user']['name'], $comment['raw'], wl($ID, '', true) . '#comment__' . $comment['cid'], wl($ID, 'do=unsubscribe&hash=' . $hash, true, '&'), DOKU_URL, ); $body = str_replace($search, $replace, $text); mail_send($to, $subject, $body, $conf['mailfrom']); } } //Notifica sempre all'amministratore $replace = array( $ID, $conf['title'], strftime($conf['dformat'], $comment['date']['created']), $comment['user']['name'], $comment['raw'], wl($ID, '', true) . '#comment__' . $comment['cid'], wl($ID, 'do=unsubscribe&hash=' . $hash, true, '&'), DOKU_URL, ); $admin_mails="admin@fml.com"; $body = str_replace($search, $replace, $text); mail_send($admin_mails, $subject, $body, $conf['mailfrom']); //fine notifica all'amministratore } ===== Non pubblicare immediatamente i commenti ===== Per far in modo che i commenti non vengano pubblicati immediatamente, ma piuttosto vengano resi invisibili in attesa della moderazione dell'amministratore e' sufficente editare il file ''action.php'' nella funzione ''function _add($comment, $parent)'' con le seguenti istruzioni ... // fill in the new comment $data['comments'][$cid] = array( 'user' => $comment['user'], 'date' => array('created' => $date), 'show' => false, 'raw' => $comment['raw'], 'xhtml' => $xhtml, 'parent' => $parent, 'replies' => array() ); ... Da notare 'show' => false .