Пример #1
0
 public function mapPost($row, $strip_tags = '', $text_length = 0, $skip = array())
 {
     $config = EasyBlogHelper::getConfig();
     $blog = EB::table('Blog');
     $blog->load($row->id);
     $profile = EB::table('Profile', 'Table');
     $profile->load($row->created_by);
     $created = EasyBlogDate::dateWithOffSet($row->created);
     $formatDate = true;
     if (EasyBlogHelper::getJoomlaVersion() >= '1.6') {
         $eb_lang = new EasyBlogString();
         $langCode = $eb_lang->getLangCode();
         if ($langCode != 'en-GB' || $langCode != 'en-US') {
             $formatDate = false;
         }
     }
     $blog->created = $created->toMySQL();
     $blog->text = $row->intro . $row->content;
     $config->set('max_video_width', 320);
     $config->set('max_video_width', 180);
     $blog->text = EasyBlogHelper::helper('Videos')->processVideos($blog->text);
     $adsnc = new EasyBlogAdsense();
     $blog->text = $adsnc->stripAdsenseCode($blog->text);
     $category = EB::table('Category', 'Table');
     $category->load($row->category_id);
     $item = new PostSimpleSchema();
     $item->textplain = $blog->text;
     // @TODO : Take care of a case when strip tags and length are used together
     if ($strip_tags) {
         $item->textplain = strip_tags($blog->text, $strip_tags);
     }
     if ($text_length > 0) {
         $pos = JString::strpos(strip_tags($item->textplain), ' ', false);
         $item->textplain = JString::substr(strip_tags($blog->text), 0, $pos);
     }
     //$image_data = json_decode($blog->image);
     $item->postid = $blog->id;
     $item->title = $blog->title;
     $item->text = $blog->text;
     $item->textplain = $this->sanitize($item->textplain);
     $item->image = new stdClass();
     if ($row->image) {
         //$item->image->url = $blog->getImage();
         $item->image->url = $row->getImage('large');
         $item->image->url = 'http:' . $item->image->url;
         //$item->image->url = ltrim($item->image->url,'//');
     } else {
         $item->image->url = null;
     }
     //$item->image->url = ($image_data->url)?$image_data->url:'';
     //$item->image->url = null;
     $item->created_date = $blog->created;
     $ebdate = new EasyBlogDate();
     $item->created_date_elapsed = $ebdate->getLapsedTime($blog->created);
     $item->author->name = $profile->nickname;
     $item->author->photo = JURI::root() . $profile->avatar;
     $item->category->categoryid = $category->id;
     $item->category->title = $category->title;
     $item->url = JURI::root() . trim(EasyBlogRouter::_('index.php?option=com_easyblog&view=entry&id=' . $blog->id), '/');
     // Tags
     $modelPT = EasyBlogHelper::getModel('PostTag');
     $item->tags = $modelPT->getBlogTags($blog->id);
     foreach ($skip as $v) {
         unset($item->{$v});
     }
     //handle image path
     if (strpos($item->text, 'src="data:image') == false) {
         if (strpos($item->text, 'href="index')) {
             $item->introtext = str_replace('href="index', 'href="' . JURI::root() . 'index', $item->introtext);
             $item->text = str_replace('href="index', 'href="' . JURI::root() . 'index', $item->text);
             //$item->text = str_replace('src="','src="'.JURI::root(),$item->text);
         }
         if (strpos($item->text, 'href="images')) {
             $item->introtext = str_replace('href="images', 'href="' . JURI::root() . 'images', $item->introtext);
             $item->text = str_replace('href="images', 'href="' . JURI::root() . 'images', $item->text);
             //$item->text = str_replace('src="','src="'.JURI::root(),$item->text);
         }
         if (strpos($item->text, 'src="images') || strpos($item->introtext, 'src="images')) {
             $item->introtext = str_replace('src="', 'src="' . JURI::root(), $item->introtext);
             $item->text = str_replace('src="', 'src="' . JURI::root(), $item->text);
         }
         if (strpos($item->text, 'src="/')) {
             $item->introtext = str_replace('src="/', 'src="' . 'http://', $item->introtext);
             $item->text = str_replace('src="/', 'src="' . 'http://', $item->text);
         }
         if (strpos($item->text, 'href="/')) {
             $item->introtext = str_replace('href="/', 'href="' . 'http://', $item->introtext);
             $item->text = str_replace('href="/', 'href="' . 'http://', $item->text);
         }
     }
     return $item;
 }
Пример #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);
 }