Esempio n. 1
0
 /**
  * Likes controller for route /like_post/{like}
  *
  * @param  int   @post_id  The post to be edited.
  */
 public function like_post($post_id)
 {
     // If unknown user or bot, cannot like.
     if ($this->user->data['user_id'] == ANONYMOUS || $this->user->data['is_bot']) {
         return;
     }
     // Add language variables for response.
     $this->user->add_lang_ext('nuleaf/likes', 'likes');
     // Grab forum id for permission.
     $sql = 'SELECT forum_id
 FROM ' . POSTS_TABLE . '
 WHERE post_id = ' . $post_id;
     $result = $this->db->sql_query_limit($sql, 1);
     $forum_id = $this->db->sql_fetchrow($result)['forum_id'];
     $this->db->sql_freeresult($result);
     // Does the user have permission to like posts in this forum?
     if ($this->auth->acl_get('!f_like', $forum_id)) {
         $json_response = new json_response();
         $json_response->send(array('error' => $this->user->lang('LIKE_NOT_AUTHORIZED')));
         return;
     }
     if ($this->request->is_ajax()) {
         $liked = $this->likes_manager->is_liked($post_id);
         if ($liked) {
             // If post is already liked, unlike it.
             $likes_count = $this->likes_manager->unlike($post_id);
         } else {
             // Else like the post.
             $likes_count = $this->likes_manager->like($post_id);
         }
         // Since the post has now been liked/unliked, $liked is reversed.
         $json_response = new json_response();
         $json_response->send(array('likes_count' => $likes_count, 'liked' => !$liked, 'LIKE_POST' => $this->user->lang('LIKE_POST'), 'UNLIKE_POST' => $this->user->lang('UNLIKE_POST'), 'LIKE_BUTTON' => $this->user->lang('LIKE_BUTTON'), 'UNLIKE_BUTTON' => $this->user->lang('UNLIKE_BUTTON')));
     }
 }
Esempio n. 2
0
 /**
  * Gets suggestions for tags based on a ajax request, route: /tags/suggest
  *
  * @param php://input raw post data must contain a json-encoded object of this structure: {"query":"...", "exclude":["...", "...", ...]}
  */
 public function suggest_tags()
 {
     if (false && $this->request->is_ajax()) {
         $data = json_decode(file_get_contents('php://input'), true);
         $query = $data['query'];
         $exclude = $data['exclude'];
         $tags = $this->tags_manager->get_tag_suggestions($query, $exclude, 5);
         $json_response = new json_response();
         $json_response->send($tags);
     }
     // fake a 404
     return $this->helper->error($this->user->lang('RH_TOPICTAGS_TAG_SUGGEST_TAG_ROUTE_ERROR', $this->helper->get_current_url()), 404);
 }
Esempio n. 3
0
 /**
  * Gets suggestions for tags based on a ajax request, route: /tags/suggest
  *
  * @param php://input raw post data must contain a json-encoded object of this structure: {"query":"...", "exclude":["...", "...", ...]}
  */
 public function suggest_tags()
 {
     if ($this->request->is_ajax()) {
         $data = json_decode(file_get_contents('php://input'), true);
         $query = $data['query'];
         $exclude = $data['exclude'];
         $tags = $this->tags_manager->get_tag_suggestions($query, $exclude, 5);
         $json_response = new json_response();
         $json_response->send($tags);
     }
     // fake a 404
     return $this->helper->error('No route found for "' . $this->helper->get_current_url() . '"', 404);
 }
Esempio n. 4
0
 /**
  * @param int $id
  * @param boolean $active
  */
 private function activate($id, $active)
 {
     $sql = 'UPDATE ' . $this->versions_table . ' SET active = ' . (int) $active . ' WHERE release_id = ' . (int) $id;
     $this->db->sql_query($sql);
     $result = new json_response();
     $result->send(array('result' => true));
 }
 /**
  * Creates an ajax response or a normal response depending on the request.
  *
  * @param string $u_action phpbb acp-u_action
  * @param string $msg the message for the normal response
  * @param boolean $success whether the response is marked successful (default) or not
  * @param array $ajax_response optional values to response in ajax_response. If no values are
  *                             given the response will be for success==true:
  *                                <pre>array(
  *                                  'success' => true,
  *                                  'msg' => base64_encode(rawurlencode($msg))
  *                                )</pre>
  *                             and for success==false:
  *                                <pre>array(
  *                                  'success' => false,
  *                                  'error_msg' => base64_encode(rawurlencode($msg))
  *                                )</pre>
  */
 private function simple_response($u_action, $msg, $success = true, array $ajax_response = array())
 {
     if ($this->request->is_ajax()) {
         if (empty($ajax_response)) {
             $msg_key = $success ? 'msg' : 'error_msg';
             $ajax_response = array('success' => $success, $msg_key => base64_encode(rawurlencode($msg)));
         }
         $response = new json_response();
         $response->send($ajax_response);
     }
     if ($success) {
         trigger_error($msg . adm_back_link($u_action));
     } else {
         trigger_error($msg . adm_back_link($u_action), E_USER_WARNING);
     }
 }