예제 #1
0
 /**
  * Delete a shoutbox post
  *
  * @param int $id
  *
  * @throws \paul999\ajaxshoutbox\exceptions\shoutbox_exception
  */
 public function delete_post($id)
 {
     if (!$id) {
         $id = $this->request->variable('id', 0);
     }
     $sql = 'SELECT user_id FROM ' . $this->table . ' WHERE shout_id = ' . (int) $id;
     $result = $this->db->sql_query($sql);
     $row = $this->db->sql_fetchrow();
     $this->db->sql_freeresult($result);
     if (!$row) {
         throw new shoutbox_exception('AJAX_SHOUTBOX_NO_SUCH_POST');
     }
     if (!$this->auth->acl_get('m_shoutbox_delete')) {
         // User has no m_ permission.
         if ($row['user_id'] != $this->user->data['user_id']) {
             throw new shoutbox_exception('AJAX_SHOUTBOX_NO_SUCH_POST');
         }
         if (!$this->auth->acl_get('u_shoutbox_delete')) {
             throw new shoutbox_exception('AJAX_SHOUTBOX_NO_PERMISSION');
         }
     }
     if ($this->push->canPush()) {
         if ($this->push->delete($id) === false) {
             throw new shoutbox_exception('AJAX_SHOUTBOX_PUSH_NOT_AVAIL');
         }
     }
     $sql = 'DELETE FROM ' . $this->table . ' WHERE shout_id =  ' . (int) $id;
     $this->db->sql_query($sql);
 }
 /**
  * Post a new message to the shoutbox.
  *
  * @return \Symfony\Component\HttpFoundation\JsonResponse
  */
 public function post()
 {
     // We always disallow guests to post in the shoutbox.
     if (!$this->auth->acl_get('u_shoutbox_post') || $this->user->data['user_id'] == ANONYMOUS) {
         return $this->error('AJAX_SHOUTBOX_ERROR', 'AJAX_SHOUTBOX_NO_PERMISSION', 403);
     }
     if ($this->request->is_ajax()) {
         $message = $msg = trim(utf8_normalize_nfc($this->request->variable('text_shoutbox', '', true)));
         if (empty($message)) {
             return $this->error('AJAX_SHOUTBOX_ERROR', 'AJAX_SHOUTBOX_MESSAGE_EMPTY', 500);
         }
         $uid = $bitfield = $options = '';
         $allow_bbcode = $this->auth->acl_get('u_shoutbox_bbcode');
         $allow_urls = $allow_smilies = true;
         if (!function_exists('generate_text_for_storage')) {
             include $this->root_path . 'includes/functions_content.' . $this->php_ext;
         }
         generate_text_for_storage($message, $uid, $bitfield, $options, $allow_bbcode, $allow_urls, $allow_smilies);
         $insert = array('post_message' => $message, 'post_time' => time(), 'user_id' => $this->user->data['user_id'], 'bbcode_options' => $options, 'bbcode_bitfield' => $bitfield, 'bbcode_uid' => $uid);
         $sql = 'INSERT INTO ' . $this->table . ' ' . $this->db->sql_build_array('INSERT', $insert);
         $this->db->sql_query($sql);
         if ($this->push->canPush()) {
             // User configured us to submit the shoutbox post to the iOS/Android app
             $this->push->post($msg, $insert['post_time'], $this->user->data['username'], $this->db->sql_nextid());
         }
         return new JsonResponse(array('OK'));
     } else {
         return $this->error('AJAX_SHOUTBOX_ERROR', 'AJAX_SHOUTBOX_ONLY_AJAX', 500);
     }
 }