Exemple #1
0
 public function get()
 {
     $input = JFactory::getApplication()->input;
     $model = EasyBlogHelper::getModel('Blog');
     //$id = $input->get('id', null, 'INT');
     $id = 0;
     $search = $input->get('search', '', 'STRING');
     $featured = $input->get('featured', 0, 'INT');
     $tags = $input->get('tags', 0, 'INT');
     $user_id = $input->get('user_id', 0, 'INT');
     $posts = array();
     // If we have an id try to fetch the user
     $blog = EasyBlogHelper::table('Blog');
     $blog->load($id);
     $modelPT = EasyBlogHelper::getModel('PostTag');
     if ($tags) {
         $rows = $model->getTaggedBlogs($tags);
     } else {
         if ($featured) {
             $rows = $this->getfeature_Blog();
             $sorting = $this->plugin->params->get('sorting', 'featured');
         } else {
             if ($user_id) {
                 $blogs = EasyBlogHelper::getModel('Blog');
                 $rows = $blogs->getBlogsBy('blogger', $user_id, 'latest');
             } else {
                 //to get latest blog
                 //$sorting	= $this->plugin->params->get( 'sorting' , 'latest' );
                 //$rows 	= $model->getBlogsBy( $sorting , '' , $sorting , 0, EBLOG_FILTER_PUBLISHED, $search );
                 $rows = $model->getBlogsBy('', '', 'latest', 0, EBLOG_FILTER_PUBLISHED, null, true, array(), false, false, true, '', '', null, 'listlength', false);
                 //$rows = EB::formatter('list', $rows, false);
             }
         }
     }
     $rows = EB::formatter('list', $rows, false);
     //data mapping
     foreach ($rows as $k => $v) {
         //$item = EB::helper( 'simpleschema' )->mapPost($v,'', 100, array('text'));
         $scm_obj = new EasyBlogSimpleSchema_plg();
         $item = $scm_obj->mapPost($v, '', 100, array('text'));
         $item->tags = $modelPT->getBlogTags($item->postid);
         $item->isowner = $v->created_by == $this->plugin->get('user')->id ? true : false;
         if ($v->blogpassword != '') {
             $item->ispassword = true;
         } else {
             $item->ispassword = false;
         }
         $item->blogpassword = $v->blogpassword;
         $model = EasyBlogHelper::getModel('Ratings');
         $ratingValue = $model->getRatingValues($item->postid, 'entry');
         $item->rate = $ratingValue;
         $item->isVoted = $model->hasVoted($item->postid, 'entry', $this->plugin->get('user')->id);
         if ($item->rate->ratings == 0) {
             $item->rate->ratings = -2;
         }
         $posts[] = $item;
     }
     $this->plugin->setResponse($posts);
 }
Exemple #2
0
 public function setRatings()
 {
     $input = JFactory::getApplication()->input;
     $user_id = $input->get('uid', 0, 'INT');
     $blog_id = $input->get('blogid', 0, 'INT');
     $values = $input->get('values', 0, 'INT');
     $model = EasyBlogHelper::table('Ratings');
     $model->uid = $blog_id;
     $model->created_by = $user_id;
     $model->value = $values;
     $model->type = 'entry';
     //$model->fill($user_id,$blog_id,'entry');
     $ratingValue = $model->store();
     return $ratingValue;
 }
Exemple #3
0
 public function getBlogsubscribers()
 {
     $app = JFactory::getApplication();
     $blogid = $app->input->get('blogid', 0, 'INT');
     $db = EasyBlogHelper::db();
     $where = array();
     //Making query for getting count of blog subscription.
     $query = 'select count(1) from `#__easyblog_post_subscription` as a';
     $query .= ' where  a.post_id = ' . $db->Quote($blogid);
     $db->setQuery($query);
     $val = $db->loadResult();
     $result['count'] = $val;
     $btable = EasyBlogHelper::table('Blog');
     //try to save blog id in table
     $btable->load($blogid);
     $result['data'] = $btable->getSubscribers(array());
     return $result;
 }
 public function getEasyBlog_user()
 {
     $app = JFactory::getApplication();
     $limitstart = $app->input->get('limitstart', 0, 'INT');
     $limit = $app->input->get('limit', 0, 'INT');
     $search = $app->input->get('search', '', 'STRING');
     $ob1 = new EasyBlogModelBlogger();
     $ob1->setState('limitstart', $limitstart);
     //$bloggers = $ob1->getAllBloggers('latest',$limit, $filter='showallblogger' , $search );
     $bloggers = $ob1->getBloggers('latest', $limit, $filter = 'showallblogger', $search);
     $blogger = EasyBlogHelper::table('Profile');
     foreach ($bloggers as $usr) {
         $blogger->load($usr->id);
         //$avatar = $blogger->getAvatar();
         $usr->avatar = $blogger->getAvatar();
     }
     return $bloggers;
 }
 public function getEasyBlog_user()
 {
     $app = JFactory::getApplication();
     $limitstart = $app->input->get('limitstart', 0, 'INT');
     $limit = $app->input->get('limit', 0, 'INT');
     $search = $app->input->get('search', '', 'STRING');
     //order options are
     //latest,alphabet,featured,latestpost,postcount,active
     $orderBy = $app->input->get('orderby', 'alphabet', 'STRING');
     $ob1 = new EasyBlogModelBlogger();
     $ob1->setState('limitstart', $limitstart);
     //$bloggers = $ob1->getAllBloggers('latest',$limit, $filter='showallblogger' , $search );
     $bloggers = $ob1->getBloggers($orderBy, $limit, $filter = 'showallblogger', $search);
     $blogger = EasyBlogHelper::table('Profile');
     foreach ($bloggers as $usr) {
         $blogger->load($usr->id);
         //$avatar = $blogger->getAvatar();
         $usr->avatar = $blogger->getAvatar();
     }
     return $bloggers;
 }
Exemple #6
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);
 }
Exemple #7
0
 public function delete_blog()
 {
     $app = JFactory::getApplication();
     $id = $app->input->get('id', 0, 'INT');
     $blog = EasyBlogHelper::table('Blog', 'Table');
     $blog->load($id);
     if (!$blog->id || !$id) {
         $res->status = 0;
         $res->message = 'blog not exists';
         return $res;
     } else {
         $val = $blog->delete($id);
         $re->status = $val;
         $res->message = 'blog deleted successfully';
         return $res;
     }
 }
Exemple #8
0
 public function get()
 {
     $input = JFactory::getApplication()->input;
     $model = EasyBlogHelper::getModel('Blog');
     $category = EasyBlogHelper::table('Category', 'Table');
     $id = $input->get('id', null, 'INT');
     $search = $input->get('search', null, 'STRING');
     $posts = array();
     if (!isset($id)) {
         $categoriesmodel = EasyBlogHelper::getModel('Categories');
         $categories = $categoriesmodel->getCategoryTree('ordering');
         $this->plugin->setResponse($categories);
         return;
     }
     $category->load($id);
     // private category shouldn't allow to access.
     $privacy = $category->checkPrivacy();
     if (!$category->id || !$privacy->allowed) {
         $this->plugin->setResponse($this->getErrorResponse(404, 'Category not found'));
         return;
     }
     //new code
     $category = EB::table('Category');
     $category->load($id);
     //get the nested categories
     $category->childs = null;
     // Build nested childsets
     EB::buildNestedCategories($category->id, $category, false, true);
     $catIds = array();
     $catIds[] = $category->id;
     EB::accessNestedCategoriesId($category, $catIds);
     // Get the category model
     $model = EB::model('Category');
     // Get total posts in this category
     $category->cnt = $model->getTotalPostCount($category->id);
     // Get teamblog posts count
     // $teamBlogCount = $model->getTeamBlogCount($category->id);
     $limit = EB::call('Pagination', 'getLimit', array(EBLOG_PAGINATION_CATEGORIES));
     // Get the posts in the category
     $data = $model->getPosts($catIds, $limit);
     $rows = EB::formatter('list', $data);
     //end
     foreach ($rows as $k => $v) {
         //$item = EasyBlogHelper::getHelper( 'SimpleSchema' )->mapPost($v, '', 100, array('text'));
         $scm_obj = new EasyBlogSimpleSchema_plg();
         $item = $scm_obj->mapPost($v, '', 100, array('text'));
         $item->isowner = $v->created_by == $this->plugin->get('user')->id ? true : false;
         if ($v->blogpassword != '') {
             $item->ispassword = true;
         } else {
             $item->ispassword = false;
         }
         $item->blogpassword = $v->blogpassword;
         $model = EasyBlogHelper::getModel('Ratings');
         $ratingValue = $model->getRatingValues($item->postid, 'entry');
         $item->rate = $ratingValue;
         $item->isVoted = $model->hasVoted($item->postid, 'entry', $this->plugin->get('user')->id);
         if ($item->rate->ratings == 0) {
             $item->rate->ratings = -2;
         }
         $posts[] = $item;
     }
     $this->plugin->setResponse($posts);
 }