Example #1
0
 public static function parseBBCode($text)
 {
     //$text	= htmlspecialchars($text , ENT_NOQUOTES );
     $text = trim($text);
     //$text   = nl2br( $text );
     //$text = preg_replace_callback('/\[code\](.*?)\[\/code\]/ms', "escape", $text);
     $text = preg_replace_callback('/\\[code( type="(.*?)")?\\](.*?)\\[\\/code\\]/ms', 'escape', $text);
     // BBCode to find...
     $in = array('/\\[b\\](.*?)\\[\\/b\\]/ms', '/\\[i\\](.*?)\\[\\/i\\]/ms', '/\\[u\\](.*?)\\[\\/u\\]/ms', '/\\[img\\](.*?)\\[\\/img\\]/ms', '/\\[email\\](.*?)\\[\\/email\\]/ms', '/\\[url\\="?(.*?)"?\\](.*?)\\[\\/url\\]/ms', '/\\[size\\="?(.*?)"?\\](.*?)\\[\\/size\\]/ms', '/\\[color\\="?(.*?)"?\\](.*?)\\[\\/color\\]/ms', '/\\[quote](.*?)\\[\\/quote\\]/ms', '/\\[list\\=(.*?)\\](.*?)\\[\\/list\\]/ms', '/\\[list\\](.*?)\\[\\/list\\]/ms', '/\\[\\*\\]\\s?(.*?)\\n/ms');
     // And replace them by...
     $out = array('<strong>\\1</strong>', '<em>\\1</em>', '<u>\\1</u>', '<img src="\\1" alt="\\1" />', '<a href="mailto:\\1">\\1</a>', '<a href="\\1">\\2</a>', '<span style="font-size:\\1%">\\2</span>', '<span style="color:\\1">\\2</span>', '<blockquote>\\1</blockquote>', '<ol start="\\1">\\2</ol>', '<ul>\\1</ul>', '<li>\\1</li>');
     $tmp = preg_replace($in, '', $text);
     $config = EasyBlogHelper::getConfig();
     if ($config->get('comment_autohyperlink')) {
         $text = EasyBlogComment::replaceURL($tmp, $text);
     }
     $text = preg_replace($in, $out, $text);
     // Smileys to find...
     $in = array(':D', ':)', ':o', ':p', ':(', ';)');
     // And replace them by...
     $out = array('<img alt=":D" src="' . EBLOG_EMOTICONS_DIR . 'emoticon-happy.png" />', '<img alt=":)" src="' . EBLOG_EMOTICONS_DIR . 'emoticon-smile.png" />', '<img alt=":o" src="' . EBLOG_EMOTICONS_DIR . 'emoticon-surprised.png" />', '<img alt=":p" src="' . EBLOG_EMOTICONS_DIR . 'emoticon-tongue.png" />', '<img alt=":(" src="' . EBLOG_EMOTICONS_DIR . 'emoticon-unhappy.png" />', '<img alt=";)" src="' . EBLOG_EMOTICONS_DIR . 'emoticon-wink.png" />');
     $text = str_replace($in, $out, $text);
     // paragraphs
     $text = str_replace("\r", "", $text);
     $text = "<p>" . preg_replace("/(\n){2,}/", "</p><p>", $text) . "</p>";
     $text = preg_replace_callback('/<pre>(.*?)<\\/pre>/ms', "removeBr", $text);
     $text = preg_replace('/<p><pre>(.*?)<\\/pre><\\/p>/ms', "<pre>\\1</pre>", $text);
     $text = preg_replace_callback('/<ul>(.*?)<\\/ul>/ms', "removeBr", $text);
     $text = preg_replace('/<p><ul>(.*?)<\\/ul><\\/p>/ms', "<ul>\\1</ul>", $text);
     return $text;
 }
Example #2
0
 public function post()
 {
     $app = JFactory::getApplication();
     $my = $this->plugin->getUser();
     $config = EasyBlogHelper::getConfig();
     //$acl = EasyBlogACLHelper::getRuleSet();
     $acl = EB::acl();
     $post = $app->input->post->getArray();
     if (empty($acl->rules->allow_comment) && (empty($my->id) && !$config->get('main_allowguestcomment'))) {
         $this->plugin->setResponse($this->getErrorResponse(500, JText::_('COM_EASYBLOG_NO_PERMISSION_TO_POST_COMMENT')));
     }
     $isModerated = false;
     $parentId = isset($post['parent_id']) ? $post['parent_id'] : 0;
     $commentDepth = isset($post['comment_depth']) ? $post['comment_depth'] : 0;
     $blogId = isset($post['id']) ? $post['id'] : 0;
     $subscribeBlog = isset($post['subscribe-to-blog']) ? true : false;
     if (!$blogId) {
         $this->plugin->setResponse($this->getErrorResponse(404, 'Invalid Blog'));
     }
     // @task: Cleanup posted values.
     array_walk($post, array($this, '_trim'));
     array_walk($post, array($this, '_revertValue'));
     if (!$config->get('comment_require_email') && !isset($post['esemail'])) {
         $post['esemail'] = '';
     }
     // @task: Run some validation tests on the posted values.
     if (!$this->_validateFields($post)) {
         $this->plugin->setResponse($this->getErrorResponse(500, $this->err[0]));
     }
     // @task: Akismet detection service.
     if ($config->get('comment_akismet')) {
         $data = array('author' => $post['esname'], 'email' => $post['esname'], 'website' => JURI::root(), 'body' => $post['comment'], 'permalink' => EasyBlogRouter::_('index.php?option=com_easyblog&view=entry&id=' . $post['id']));
         if (EasyBlogHelper::getHelper('Akismet')->isSpam($data)) {
             $this->plugin->setResponse($this->getErrorResponse(500, JText::_('COM_EASYBLOG_SPAM_DETECTED_IN_COMMENT')));
         }
     }
     // @task: Retrieve the comments model
     $model = EasyBlogHelper::getModel('Comment');
     // @task: Retrieve the comment's table
     $comment = EasyBlogHelper::table('Comment');
     // We need to rename the esname and esemail back to name and email.
     $post['post_id'] = $post['id'];
     $post['name'] = $post['esname'];
     $post['email'] = $post['esemail'];
     unset($post['id']);
     unset($post['esname']);
     unset($post['esemail']);
     // @task: Bind posted values into the table.
     $comment->bindPost($post);
     // @task: Process registrations
     $registerUser = isset($post['esregister']) ? true : false;
     $fullname = isset($post['name']) ? $post['name'] : '';
     $username = isset($post['esusername']) ? $post['esusername'] : '';
     $email = $post['email'];
     $message = '';
     $newUserId = 0;
     // @task: Process registrations if necessary
     if ($registerUser && $my->id <= 0) {
         $state = $this->processRegistrations($post, $username, $email, $ajax);
         if (!is_numeric($state)) {
             $this->plugin->setResponse($this->getErrorResponse(500, $state));
         }
         $newUserId = $state;
     }
     $totalComments = empty($post['totalComment']) ? 1 : $post['totalComment'];
     //$date 	= EasyBlogHelper::getDate();
     $date = EasyBlogDate::getDate();
     $comment->set('created', $date->toMySQL());
     $comment->set('modified', $date->toMySQL());
     $comment->set('published', 1);
     $comment->set('parent_id', $parentId);
     $comment->set('sent', 0);
     $comment->set('created_by', $my->id);
     // @rule: Update the user's id if they have just registered earlier.
     if ($newUserId != 0) {
         $comment->set('created_by', $newUserId);
     }
     // @rule: Update publish status if the comment requires moderation
     if ($config->get('comment_moderatecomment') == 1 || $my->id == 0 && $config->get('comment_moderateguestcomment') == 1) {
         $comment->set('published', EBLOG_COMMENT_STATUS_MODERATED);
         $isModerated = true;
     }
     $blog = EasyBlogHelper::table('Blog');
     $blog->load($blogId);
     // If moderation for author is disabled, ensure that the comment is published.
     // If the author is the owner of the blog, it should never be moderated.
     if (!$config->get('comment_moderateauthorcomment') && $blog->created_by == $my->id) {
         $comment->set('published', 1);
         $isModerated = false;
     }
     if (!$comment->store()) {
         $this->plugin->setResponse($this->getErrorResponse(500, 'There was a problem saving the comment'));
     }
     // @rule: Process subscription for blog automatically when the user submits a new comment and wants to subscribe to the blog.
     if ($subscribeBlog && $config->get('main_subscription') && $blog->subscription) {
         $isSubscribed = false;
         $userId = $my->id;
         $blogModel = EasyblogHelper::getModel('Blog');
         if ($userId == 0) {
             $sid = $blogModel->isBlogSubscribedEmail($blog->id, $email);
             if (empty($sid)) {
                 $isSubscribed = $blogModel->addBlogSubscription($blog->id, $email, '', $fullname);
             }
         } else {
             $sid = $blogModel->isBlogSubscribedUser($blog->id, $userId, $email);
             if (!empty($sid)) {
                 // @task: User found, update the email address
                 $blogModel->updateBlogSubscriptionEmail($sid, $userId, $email);
             } else {
                 $isSubscribed = $blogModel->addBlogSubscription($blog->id, $email, $userId, $fullname);
             }
         }
     }
     $row = $comment;
     $creator = EasyBlogHelper::table('Profile');
     $creator->load($my->id);
     $row->poster = $creator;
     $row->comment = nl2br($row->comment);
     $row->comment = EasyBlogComment::parseBBCode($row->comment);
     $row->depth = is_null($commentDepth) ? '0' : $commentDepth;
     $row->likesAuthor = '';
     // @rule: Process notifications
     $comment->processEmails($isModerated, $blog);
     //update the sent flag to sent
     $comment->updateSent();
     // @TODO - Move this to a map comment function
     $item = new CommentSimpleSchema();
     $item->commentid = $comment->id;
     $item->postid = $comment->post_id;
     $item->title = $comment->title;
     $item->text = EasyBlogComment::parseBBCode($comment->comment);
     $item->textplain = strip_tags(EasyBlogComment::parseBBCode($comment->comment));
     $item->created_date = $comment->created;
     $item->created_date_elapsed = EasyBlogDate::getLapsedTime($comment->created);
     $item->updated_date = $comment->modified;
     // Author
     $item->author->name = isset($comment->poster->nickname) ? $comment->poster->nickname : $comment->name;
     $item->author->photo = isset($comment->poster->avatar) ? $comment->poster->avatar : 'default_blogger.png';
     $item->author->photo = JURI::root() . 'components/com_easyblog/assets/images/' . $item->author->photo;
     $item->author->email = $comment->email;
     $item->author->website = isset($comment->poster->url) ? $comment->poster->url : $comment->url;
     $this->plugin->setResponse($item);
 }