Exemple #1
0
 /**
  * Like an item. Update ajax count
  * @param string $element   Can either be core object (photos/videos) or a plugins (plugins,plugin_name)
  * @param mixed $itemId	    Unique id to identify object item
  *
  */
 public function ajaxLike($element, $itemId)
 {
     if (!COwnerHelper::isRegisteredUser()) {
         return $this->ajaxBlockUnregister();
     }
     // @rule: Only display likes html codes when likes is allowed.
     $config =& CFactory::getConfig();
     if (!$config->get('likes_' . $element)) {
         return;
     }
     $my = CFactory::getUser();
     $objResponse = new JAXResponse();
     // Load libraries
     CFactory::load('libraries', 'like');
     $likes = new CLike();
     $result = $likes->addLike($element, $itemId);
     if (!$result) {
         $msg = JText::_('CC LIKE ERROR');
         $objResponse->addScriptCall('cWindowShow', '', JText::_('CC LIKE'), 430, 100);
         $objResponse->addAssign('cWindowContent', 'innerHTML', $msg);
     } else {
         $like = new CLike();
         $html = $like->getHTML($element, $itemId, $my->id);
         $objResponse->addScriptCall('__callback', $html);
     }
     return $objResponse->sendResponse();
 }
Exemple #2
0
 /**
  *
  */
 public function ajaxStreamAddLike($actid, $type = null)
 {
     $filter = JFilterInput::getInstance();
     $actid = $filter->clean($actid, 'int');
     $objResponse = new JAXResponse();
     $wallModel = CFactory::getModel('wall');
     $like = new CLike();
     $act = JTable::getInstance('Activity', 'CTable');
     $act->load($actid);
     //guest cannot like
     $user = CFactory::getUser();
     if (!$user->id) {
         die;
     }
     /**
      * some like_type are missing and causing stream id cannot be like, in this case, group create.
      * This condition is used to fix the existing activity with such issue.
      */
     if ($act->comment_type == 'groups.create' && empty($act->like_type)) {
         $act->like_type = 'groups.create';
         $act->store();
     }
     if ($type == 'comment') {
         $act = JTable::getInstance('Wall', 'CTable');
         $act->load($actid);
         $act->like_type = 'comment';
         $act->like_id = $act->id;
     }
     $params = new CParameter($act->params);
     // this is used to seperate the like from the actual pictures
     if (isset($act->app) && $act->app == 'photos' && $params->get('batchcount', 0) >= 1) {
         $act->like_type = 'album.self.share';
         $act->like_id = $act->id;
     } else {
         if (isset($act->app) && $act->app == 'videos') {
             $act->like_type = 'videos.self.share';
             $act->like_id = $act->id;
         }
     }
     // Count before the add
     $oldLikeCount = $like->getLikeCount($act->like_type, $act->like_id);
     $like->addLike($act->like_type, $act->like_id);
     $likeCount = $like->getLikeCount($act->like_type, $act->like_id);
     $json = array();
     $json['success'] = true;
     // If the like count is 1, then, the like bar most likely not there before
     // but, people might just click twice, hence the need to compare it before
     // the actual like
     if ($likeCount == 1 && $oldLikeCount != $likeCount) {
         // Clear old like status
         $objResponse->addScriptCall("joms.jQuery('#wall-cmt-{$actid} .cStream-Likes').remove", '');
         $objResponse->addScriptCall("joms.jQuery('#wall-cmt-{$actid}').prepend", '<div class="cStream-Likes"></div>');
     }
     if ($type == 'comment') {
         $json['html'] = $this->_commentShowLikes($objResponse, $act->id);
     } else {
         $json['html'] = $this->_streamShowLikes($objResponse, $act->id, $act->like_type, $act->like_id);
     }
     die(json_encode($json));
 }
Exemple #3
0
 /**
  *
  */
 public function ajaxStreamAddLike($actid)
 {
     $filter = JFilterInput::getInstance();
     $actid = $filter->clean($actid, 'int');
     $objResponse = new JAXResponse();
     $wallModel = CFactory::getModel('wall');
     CFactory::load('libraries', 'like');
     CFactory::load('libraries', 'wall');
     $like = new CLike();
     $act =& JTable::getInstance('Activity', 'CTable');
     $act->load($actid);
     // Count before the add
     $oldLikeCount = $like->getLikeCount($act->like_type, $act->like_id);
     $like->addLike($act->like_type, $act->like_id);
     $likeCount = $like->getLikeCount($act->like_type, $act->like_id);
     // If the like count is 1, then, the like bar most likely not there before
     // but, people might just click twice, hence the need to compare it before
     // the actual like
     if ($likeCount == 1 && $oldLikeCount != $likeCount) {
         // Clear old like status
         $objResponse->addScriptCall("joms.jQuery('#wall-cmt-{$actid} .wallicon-like').remove", '');
         $objResponse->addScriptCall("joms.jQuery('#wall-cmt-{$actid}').prepend", '<div class="cComment wallinfo wallicon-like"></div>');
     }
     $this->_streamShowLikes($objResponse, $actid, $act->like_type, $act->like_id);
     $script = "joms.jQuery('#like_id" . $actid . "').replaceWith('<a id=like_id" . $actid . " href=#unlike onclick=\"jax.call(\\'community\\',\\'system,ajaxStreamUnlike\\'," . $actid . ");return false;\">" . JText::_('COM_COMMUNITY_UNLIKE') . "</a>');";
     $objResponse->addScriptCall($script);
     return $objResponse->sendResponse();
 }