function subscribe_topic_func($xmlrpc_params)
{
    global $db, $lang, $theme, $plugins, $mybb, $session, $settings, $cache, $time, $mybbgroups;
    $lang->load("usercp");
    $input = Tapatalk_Input::filterXmlInput(array('topic_id' => Tapatalk_Input::INT), $xmlrpc_params);
    $thread = get_thread($input['topic_id']);
    if (!$thread['tid']) {
        return xmlrespfalse($lang->error_invalidthread);
    }
    $forumpermissions = forum_permissions($thread['fid']);
    if ($forumpermissions['canview'] == 0 || $forumpermissions['canviewthreads'] == 0) {
        return tt_no_permission();
    }
    add_subscribed_thread($thread['tid'], 0);
    return xmlresptrue();
}
Example #2
0
    // Is the currently logged in user a moderator of this forum?
    if (is_moderator($thread['fid'])) {
        $ismod = true;
    } else {
        $ismod = false;
    }
    // Make sure we are looking at a real thread here.
    if ($thread['visible'] != 1 && $ismod == false || $thread['visible'] > 1 && $ismod == true) {
        error($lang->error_invalidthread);
    }
    $forumpermissions = forum_permissions($thread['fid']);
    if ($forumpermissions['canview'] == 0 || $forumpermissions['canviewthreads'] == 0 || isset($forumpermissions['canonlyviewownthreads']) && $forumpermissions['canonlyviewownthreads'] != 0 && $thread['uid'] != $mybb->user['uid']) {
        error_no_permission();
    }
    $plugins->run_hooks("usercp2_do_addsubscription");
    add_subscribed_thread($thread['tid'], $mybb->get_input('notification', MyBB::INPUT_INT));
    if ($mybb->get_input('referrer')) {
        $url = htmlspecialchars_uni($mybb->get_input('referrer'));
    } else {
        $url = get_thread_link($thread['tid']);
    }
    redirect($url, $lang->redirect_subscriptionadded);
} elseif ($mybb->get_input('action') == "addsubscription") {
    if ($mybb->get_input('type') == "forum") {
        $forum = get_forum($mybb->get_input('fid', MyBB::INPUT_INT));
        if (!$forum) {
            error($lang->error_invalidforum);
        }
        $forumpermissions = forum_permissions($forum['fid']);
        if ($forumpermissions['canview'] == 0 || $forumpermissions['canviewthreads'] == 0) {
            error_no_permission();
Example #3
0
 /**
  * Updates a post that is already in the database.
  *
  */
 function update_post()
 {
     global $db, $mybb, $plugins;
     // Yes, validating is required.
     if ($this->get_validated() != true) {
         die("The post needs to be validated before inserting it into the DB.");
     }
     if (count($this->get_errors()) > 0) {
         die("The post is not valid.");
     }
     $post =& $this->data;
     $post['pid'] = (int) $post['pid'];
     $existing_post = get_post($post['pid']);
     $post['tid'] = $existing_post['tid'];
     $post['fid'] = $existing_post['fid'];
     $forum = get_forum($post['fid']);
     $forumpermissions = forum_permissions($post['fid'], $post['uid']);
     // Check if this is the first post in a thread.
     $options = array("order_by" => "dateline", "order_dir" => "asc", "limit_start" => 0, "limit" => 1);
     $query = $db->simple_select("posts", "pid", "tid='" . (int) $post['tid'] . "'", $options);
     $first_post_check = $db->fetch_array($query);
     if ($first_post_check['pid'] == $post['pid']) {
         $first_post = true;
     } else {
         $first_post = false;
     }
     // Decide on the visibility of this post.
     $ismod = is_moderator($post['fid'], "", $post['uid']);
     // Keep visibility for unapproved and deleted posts
     if ($existing_post['visible'] == 0) {
         $visible = 0;
     } elseif ($existing_post['visible'] == -1) {
         $visible = -1;
     } elseif ($forumpermissions['mod_edit_posts'] == 1 && !$ismod) {
         $visible = 0;
         require_once MYBB_ROOT . "inc/class_moderation.php";
         $moderation = new Moderation();
         $moderation->unapprove_posts(array($post['pid']));
     } else {
         $visible = 1;
     }
     // Update the thread details that might have been changed first.
     if ($first_post) {
         $this->tid = $post['tid'];
         if (isset($post['prefix'])) {
             $this->thread_update_data['prefix'] = (int) $post['prefix'];
         }
         if (isset($post['subject'])) {
             $this->thread_update_data['subject'] = $db->escape_string($post['subject']);
         }
         if (isset($post['icon'])) {
             $this->thread_update_data['icon'] = (int) $post['icon'];
         }
         if (count($this->thread_update_data) > 0) {
             $plugins->run_hooks("datahandler_post_update_thread", $this);
             $db->update_query("threads", $this->thread_update_data, "tid='" . (int) $post['tid'] . "'");
         }
     }
     // Prepare array for post updating.
     $this->pid = $post['pid'];
     if (isset($post['subject'])) {
         $this->post_update_data['subject'] = $db->escape_string($post['subject']);
     }
     if (isset($post['message'])) {
         $this->post_update_data['message'] = $db->escape_string($post['message']);
     }
     if (isset($post['editreason']) && trim($post['editreason']) != '') {
         $this->post_update_data['editreason'] = $db->escape_string(trim($post['editreason']));
     }
     if (isset($post['icon'])) {
         $this->post_update_data['icon'] = (int) $post['icon'];
     }
     if (isset($post['options'])) {
         if (isset($post['options']['disablesmilies'])) {
             $this->post_update_data['smilieoff'] = $db->escape_string($post['options']['disablesmilies']);
         }
         if (isset($post['options']['signature'])) {
             $this->post_update_data['includesig'] = $db->escape_string($post['options']['signature']);
         }
     }
     // If we need to show the edited by, let's do so.
     if ($mybb->settings['showeditedby'] == 1 && !is_moderator($post['fid'], "caneditposts", $post['edit_uid']) || $mybb->settings['showeditedbyadmin'] == 1 && is_moderator($post['fid'], "caneditposts", $post['edit_uid'])) {
         $this->post_update_data['edituid'] = (int) $post['edit_uid'];
         $this->post_update_data['edittime'] = TIME_NOW;
     }
     $plugins->run_hooks("datahandler_post_update", $this);
     $db->update_query("posts", $this->post_update_data, "pid='" . (int) $post['pid'] . "'");
     // Automatic subscription to the thread
     if ($post['options']['subscriptionmethod'] != "" && $post['uid'] > 0) {
         switch ($post['options']['subscriptionmethod']) {
             case "pm":
                 $notification = 2;
                 break;
             case "email":
                 $notification = 1;
                 break;
             default:
                 $notification = 0;
         }
         require_once MYBB_ROOT . "inc/functions_user.php";
         add_subscribed_thread($post['tid'], $notification, $post['uid']);
     } else {
         $db->delete_query("threadsubscriptions", "uid='" . (int) $post['uid'] . "' AND tid='" . (int) $post['tid'] . "'");
     }
     update_forum_lastpost($post['fid']);
     update_last_post($post['tid']);
     // Return the thread's first post id and whether or not it is visible.
     $this->return_values = array('visible' => $visible, 'first_post' => $first_post);
     $plugins->run_hooks("datahandler_post_update_end", $this);
     return $this->return_values;
 }
// Verify incoming POST request
verify_post_check($mybb->input['my_post_key']);
$lang->load("usercp");
usercp_menu();
$server_http_referer = htmlentities($_SERVER['HTTP_REFERER']);
if ($mybb->input['action'] == "do_addsubscription") {
    if ($mybb->input['type'] != "forum") {
        $thread = get_thread($mybb->input['tid']);
        if (!$thread['tid']) {
            error($lang->error_invalidthread);
        }
        $forumpermissions = forum_permissions($thread['fid']);
        if ($forumpermissions['canview'] == 0 || $forumpermissions['canviewthreads'] == 0 || $forumpermissions['canonlyviewownthreads'] != 0 && $thread['uid'] != $mybb->user['uid']) {
            error_no_permission();
        }
        add_subscribed_thread($thread['tid'], $mybb->input['notification']);
        if ($mybb->input['referrer']) {
            $url = htmlspecialchars_uni(addslashes($mybb->input['referrer']));
        } else {
            $url = get_thread_link($thread['tid']);
        }
        redirect($url, $lang->redirect_subscriptionadded);
    }
}
if ($mybb->input['action'] == "addsubscription") {
    if ($mybb->input['type'] == "forum") {
        $forum = get_forum($mybb->input['fid']);
        if (!$forum['fid']) {
            error($lang->error_invalidforum);
        }
        $forumpermissions = forum_permissions($forum['fid']);
 /**
  * Updates a post that is already in the database.
  *
  */
 function update_post()
 {
     global $db, $mybb, $plugins;
     // Yes, validating is required.
     if ($this->get_validated() != true) {
         die("The post needs to be validated before inserting it into the DB.");
     }
     if (count($this->get_errors()) > 0) {
         die("The post is not valid.");
     }
     $post =& $this->data;
     $post['pid'] = intval($post['pid']);
     $existing_post = get_post($post['pid']);
     $post['tid'] = $existing_post['tid'];
     $post['fid'] = $existing_post['fid'];
     $forum = get_forum($post['fid']);
     // Decide on the visibility of this post.
     if (isset($post['visible']) && $post['visible'] != $existing_post['visible']) {
         if ($forum['mod_edit_posts'] == 1 && !is_moderator($post['fid'], "", $post['uid'])) {
             if ($existing_post['visible'] == 1) {
                 update_thread_data($existing_post['tid']);
                 update_thread_counters($existing_post['tid'], array('replies' => '-1', 'unapprovedposts' => '+1'));
                 update_forum_counters($existing_post['fid'], array('unapprovedthreads' => '+1', 'unapprovedposts' => '+1'));
                 // Subtract from the users post count
                 // Update the post count if this forum allows post counts to be tracked
                 if ($forum['usepostcounts'] != 0) {
                     $db->write_query("UPDATE " . TABLE_PREFIX . "users SET postnum=postnum-1 WHERE uid='{$existing_post['uid']}'");
                 }
             }
             $visible = 0;
         } else {
             if ($existing_post['visible'] == 0) {
                 update_thread_data($existing_post['tid']);
                 update_thread_counters($existing_post['tid'], array('replies' => '+1', 'unapprovedposts' => '-1'));
                 update_forum_counters($existing_post['fid'], array('unapprovedthreads' => '-1', 'unapprovedposts' => '-1'));
                 // Update the post count if this forum allows post counts to be tracked
                 if ($forum['usepostcounts'] != 0) {
                     $db->write_query("UPDATE " . TABLE_PREFIX . "users SET postnum=postnum+1 WHERE uid='{$existing_post['uid']}'");
                 }
             }
             $visible = 1;
         }
     } else {
         $visible = 0;
         if ($forum['mod_edit_posts'] != 1 || is_moderator($post['fid'], "", $post['uid'])) {
             $visible = 1;
         }
     }
     // Check if this is the first post in a thread.
     $options = array("order_by" => "dateline", "order_dir" => "asc", "limit_start" => 0, "limit" => 1);
     $query = $db->simple_select("posts", "pid", "tid='" . intval($post['tid']) . "'", $options);
     $first_post_check = $db->fetch_array($query);
     if ($first_post_check['pid'] == $post['pid']) {
         $first_post = true;
     } else {
         $first_post = false;
     }
     if ($existing_post['visible'] == 0) {
         $visible = 0;
     }
     // Update the thread details that might have been changed first.
     if ($first_post) {
         $this->tid = $post['tid'];
         $this->thread_update_data['visible'] = $visible;
         if (isset($post['prefix'])) {
             $this->thread_update_data['prefix'] = intval($post['prefix']);
         }
         if (isset($post['subject'])) {
             $this->thread_update_data['subject'] = $db->escape_string($post['subject']);
         }
         if (isset($post['icon'])) {
             $this->thread_update_data['icon'] = intval($post['icon']);
         }
         if (count($this->thread_update_data) > 0) {
             $plugins->run_hooks("datahandler_post_update_thread", $this);
             $db->update_query("threads", $this->thread_update_data, "tid='" . intval($post['tid']) . "'");
         }
     }
     // Prepare array for post updating.
     $this->pid = $post['pid'];
     if (isset($post['subject'])) {
         $this->post_update_data['subject'] = $db->escape_string($post['subject']);
     }
     if (isset($post['message'])) {
         $this->post_update_data['message'] = $db->escape_string($post['message']);
     }
     if (isset($post['icon'])) {
         $this->post_update_data['icon'] = intval($post['icon']);
     }
     if (isset($post['options'])) {
         if (isset($post['options']['disablesmilies'])) {
             $this->post_update_data['smilieoff'] = $db->escape_string($post['options']['disablesmilies']);
         }
         if (isset($post['options']['signature'])) {
             $this->post_update_data['includesig'] = $db->escape_string($post['options']['signature']);
         }
     }
     // If we need to show the edited by, let's do so.
     if ($mybb->settings['showeditedby'] == 1 && !is_moderator($post['fid'], "caneditposts", $post['edit_uid']) || $mybb->settings['showeditedbyadmin'] == 1 && is_moderator($post['fid'], "caneditposts", $post['edit_uid'])) {
         $this->post_update_data['edituid'] = intval($post['edit_uid']);
         $this->post_update_data['edittime'] = TIME_NOW;
     }
     $this->post_update_data['visible'] = $visible;
     $plugins->run_hooks("datahandler_post_update", $this);
     $db->update_query("posts", $this->post_update_data, "pid='" . intval($post['pid']) . "'");
     // Automatic subscription to the thread
     if ($post['options']['subscriptionmethod'] != "" && $post['uid'] > 0) {
         switch ($post['options']['subscriptionmethod']) {
             case "instant":
                 $notification = 1;
                 break;
             default:
                 $notification = 0;
         }
         require_once MYBB_ROOT . "inc/functions_user.php";
         add_subscribed_thread($post['tid'], $notification, $post['uid']);
     } else {
         $db->delete_query("threadsubscriptions", "uid='" . intval($post['uid']) . "' AND tid='" . intval($post['tid']) . "'");
     }
     update_forum_lastpost($post['fid']);
     return array('visible' => $visible, 'first_post' => $first_post);
 }
Example #6
0
/**
 * Change who a thread is assigned to.
 *
 * @param array Information about the thread.
 * @param int The UID of who we're assigning it to now.
 * @param bool If this is changing the assigned user of multiple threads.
**/
function mysupport_change_assign($thread_info, $assign, $multiple = false)
{
    global $mybb, $db, $lang;
    if ($multiple) {
        $fid = -1;
        $tid = -1;
        $old_assign = -1;
    } else {
        $fid = intval($thread_info['fid']);
        $tid = intval($thread_info['tid']);
        $old_assign = intval($thread_info['assign']);
    }
    // this'll be the same wherever so set this here
    if ($multiple) {
        $tids = implode(",", array_map("intval", $thread_info));
        $where_sql = "tid IN (" . $db->escape_string($tids) . ")";
    } else {
        $where_sql = "tid = '" . intval($tid) . "'";
    }
    // because we can assign a thread to somebody if it's already assigned to somebody else, we need to get a list of all the users who have been assigned the threads we're dealing with, so we can recount the number of assigned threads for all these users after the assignment has been chnaged
    $query = $db->simple_select("threads", "DISTINCT assign", $where_sql . " AND assign != '0'");
    $assign_users = array($assign => $assign);
    while ($user = $db->fetch_field($query, "assign")) {
        $assign_users[$user] = $user;
    }
    // if we're unassigning it
    if ($assign == "-1") {
        $update = array("assign" => 0, "assignuid" => 0);
        // remove the assignment on the thread
        $db->update_query("threads", $update, $where_sql);
        // get information on who it was assigned to
        $user = get_user($old_assign);
        if ($multiple) {
            mysupport_mod_log_action(6, $lang->sprintf($lang->unassigned_from_success_multi, count($thread_info)));
            mysupport_redirect_message($lang->sprintf($lang->unassigned_from_success_multi, count($thread_info)));
        } else {
            mysupport_mod_log_action(6, $lang->sprintf($lang->unassigned_from_success, $user['username']));
            mysupport_redirect_message($lang->sprintf($lang->unassigned_from_success, htmlspecialchars_uni($user['username'])));
        }
    } else {
        $update = array("assign" => intval($assign), "assignuid" => intval($mybb->user['uid']));
        if ($multiple) {
            // when assigning via the form in a thread, you can't assign a thread if it's solved
            // here, it's not as easy to check for that; instead, only assign a thread if it isn't solved
            $where_sql .= " AND status != '1'";
        }
        // assign the thread
        $db->update_query("threads", $update, $where_sql);
        $user = get_user($assign);
        $username = $db->escape_string($user['username']);
        if ($mybb->settings['mysupportassignpm'] == 1) {
            // send the PM
            mysupport_send_assign_pm($assign, $fid, $tid);
        }
        if ($mybb->settings['mysupportassignsubscribe'] == 1) {
            if ($multiple) {
                $tids = $thread_info;
            } else {
                $tids = array($thread_info['tid']);
            }
            foreach ($tids as $tid) {
                $query = $db->simple_select("threadsubscriptions", "*", "uid = '{$assign}' AND tid = '{$tid}'");
                // only do this if they're not already subscribed
                if ($db->num_rows($query) == 0) {
                    if ($user['subscriptionmethod'] == 2) {
                        $subscription_method = 2;
                    } else {
                        $subscription_method = 1;
                    }
                    require_once MYBB_ROOT . "inc/functions_user.php";
                    add_subscribed_thread($tid, $subscription_method, $assign);
                }
            }
        }
        if ($multiple) {
            mysupport_mod_log_action(5, $lang->sprintf($lang->assigned_to_success_multi, count($thread_info), $user['username']));
            mysupport_redirect_message($lang->sprintf($lang->assigned_to_success_multi, count($thread_info), htmlspecialchars_uni($user['username'])));
        } else {
            mysupport_mod_log_action(5, $lang->sprintf($lang->assigned_to_success, $username));
            mysupport_redirect_message($lang->sprintf($lang->assigned_to_success, htmlspecialchars_uni($username)));
        }
    }
    foreach ($assign_users as $user) {
        mysupport_recount_assigned_threads($user);
    }
}