Example #1
0
 /**
  * Unlikes a post that you previously liked ... no negatives though, hurts feelings :'(
  * It redirects back to the referrer afterward.
  * It is accessed via ?action=like,sa=unlikepost.
  */
 public function action_unlikepost()
 {
     global $user_info, $topic, $txt, $modSettings;
     $this->_id_liked = !empty($_REQUEST['msg']) ? (int) $_REQUEST['msg'] : 0;
     // We used to like these
     require_once SUBSDIR . '/Likes.subs.php';
     require_once SUBSDIR . '/Messages.subs.php';
     // Have to be able to access it to unlike it now
     if ($this->prepare_like() && canAccessMessage($this->_id_liked)) {
         $liked_message = basicMessageInfo($this->_id_liked, true, true);
         if ($liked_message) {
             $likeResult = likePost($user_info['id'], $liked_message, '-');
             if ($likeResult === true) {
                 // Oh noes, taking the like back, let them know so they can complain
                 if (!empty($modSettings['mentions_enabled'])) {
                     require_once CONTROLLERDIR . '/Mentions.controller.php';
                     $mentions = new Mentions_Controller();
                     $mentions->setData(array('id_member' => $liked_message['id_member'], 'type' => 'rlike', 'id_msg' => $this->_id_liked));
                     // Notifying that likes were removed ?
                     if (!empty($modSettings['mentions_dont_notify_rlike'])) {
                         $mentions->action_rlike();
                     } else {
                         $mentions->action_add();
                     }
                 }
             } elseif ($this->_api) {
                 $this->_likes_response = array('result' => false, 'data' => $likeResult);
             }
         } elseif ($this->_api) {
             loadLanguage('Errors');
             $this->_likes_response = array('result' => false, 'data' => $txt['like_unlike_error']);
         }
     }
     // Back we go
     if ($this->_api) {
         $this->likeResponse();
     } elseif (!isset($_REQUEST['profile'])) {
         redirectexit('topic=' . $topic . '.msg' . $this->_id_liked . '#msg' . $this->_id_liked);
     } else {
         redirectexit('action=profile;area=showlikes;sa=given;u=' . $user_info['id']);
     }
 }