×

Notice

The forum is in read only mode.
Welcome, Guest
Username: Password: Remember me
  • Page:
  • 1

TOPIC: [patch] Customize autopublishing with plugins

[patch] Customize autopublishing with plugins 14 years 10 months ago #4490

  • Leonid
  • Leonid's Avatar Topic Author
  • Offline
  • Fresh Boarder
  • Fresh Boarder
  • Posts: 3
  • Thank you received: 0
Well, my solution is quite dirty and hardcoded. On post inserted event onCommentAutoPublishing triggered. Each event handler return true if message is published otherwise false. Message autopublished if no false values was returned by plugins.

Plugin parameters:
Just small amount of context data passed. Maybe we should pass $this reference instead?
  1. comment (BB-tagged text message)
  2. ip
  3. email
  4. website
Plugin result:
  • true (message published)
  • false (message is not published)
diff --git a/joscomment/comment.class.php b/joscomment/comment.class.php
index bb04ded..d98a760 100644
--- a/joscomment/comment.class.php
+++ b/joscomment/comment.class.php
@@ -976,6 +976,16 @@ class JOSC_board extends JOSC_visual {
         return JOSC_utils::censorText($text,$this->_censorship_enable,$this->_censorship_words,$this->_censorship_case_sensitive);
     }
 
+    private function _isPublished($ip, $email, $website, $comment)
+    {
+        $dispatcher = JDispatcher::getInstance();
+        $result = $dispatcher->trigger('onCommentAutoPublishing', array('comment' => $comment, 'ip' => $ip, 'email' => $email, 'website' => $website));
+        $custom_filters = true;
+        foreach ($result as $row) {
+            $custom_filters = $custom_filters && $row;
+        }
+        return ($this->_autopublish && $custom_filters) || JOSC_utils::isModerator($this->_moderator);
+    }
     function insertNewPost($ajax = false)
     {
         $ip = $_SERVER['REMOTE_ADDR'];
@@ -997,7 +1007,7 @@ class JOSC_board extends JOSC_visual {
         $title = $this->censorText(JOSC_utils::mysql_escape_string(strip_tags($this->_ttitle)));
         $comment = $this->censorText(JOSC_utils::mysql_escape_string(strip_tags($this->_tcomment)));
         if (!$comment) $comment = _JOOMLACOMMENT_EMPTYCOMMENT;
-        $published = $this->_autopublish || JOSC_utils::isModerator($this->_moderator);
+        $published = $this->_isPublished($ip, $email, $website, $comment);
         $parent_id = $this->_parent_id;
         $database->SetQuery("
             INSERT INTO jos_comment

And here sample plugin, discontinuing comments with hyperlinks inside:
defined( '_JEXEC' ) or die( 'Restricted access' );
jimport('joomla.plugin.plugin');
 
class plgSystemJocom_Nolink extends JPlugin
{
        public function onCommentAutoPublishing($comment, $ip, $email, $website)
        {
                return stripos($comment, '[url') === false;
        }       
}

[patch] Customize autopublishing with plugins 14 years 3 weeks ago #9402

  • Daniel Dimitrov
  • Daniel Dimitrov's Avatar
  • Offline
  • Administrator
  • Administrator
  • Posts: 9618
  • Karma: 155
  • Thank you received: 1081
Hey Leonid,
The next version will support plugins for sure :)
  • Page:
  • 1
Time to create page: 0.126 seconds