Viewing file: misc.php (6.73 KB) -rw-rw-r-- Select action/file-type: (+) | (+) | (+) | Code (+) | Session (+) | (+) | SDB (+) | (+) | (+) | (+) | (+) | (+) |
<?php
/**
*
* @author Robert Johnston
*
* @package Forum Runner
* @version CVS/SVN: $Id: $
* @copyright (c) 2010 End of Time Studios, LLC
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
*
*/
chdir(MCWD);
chdir('../');
define('IN_LOGIN', true);
$phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './';
$phpEx = substr(strrchr(__FILE__, '.'), 1);
require($phpbb_root_path . 'common.' . $phpEx);
require($phpbb_root_path . 'includes/functions_user.' . $phpEx);
fr_set_debug();
// Start session management
$user->session_begin();
$auth->acl($user->data);
$user->setup(array('ucp', 'mcp'));
$user->page['root_script_path'] = str_replace('/forumrunner', '', $user->page['root_script_path']);
function
do_mark_read ()
{
global $user, $db, $table_prefix;
$forum_id = request_var('forumid', -1);
if (!$user->data['is_registered']) {
json_error(ERR_NO_PERMISSION);
}
if ($forum_id == -1) {
markread('all');
$result = $db->sql_query("
SHOW TABLES LIKE '{$table_prefix}forumrunner_push_users'
");
$row = $db->sql_fetchrow($result);
$db->sql_freeresult($result);
if ($row) {
$db->sql_query("
UPDATE {$table_prefix}forumrunner_push_data
SET subsent = 0, topicread = " . time() . "
WHERE userid = {$user->data['user_id']} AND topicid > 0
");
}
} else {
// Recursive phun!
$sql = 'SELECT left_id, right_id FROM ' . FORUMS_TABLE . ' WHERE forum_id = ' . $forum_id;
$result = $db->sql_query($sql);
$row = $db->sql_fetchrow($result);
$db->sql_freeresult($result);
$sql = $db->sql_build_query('SELECT', array(
'SELECT' => 'f.forum_id',
'FROM' => array(
FORUMS_TABLE => 'f',
),
'WHERE' => 'left_id > ' . $row['left_id'] . ' AND right_id < ' . $row['right_id']
));
$result = $db->sql_query($sql);
$forum_ids = array();
$forum_ids[] = $forum_id;
while ($row = $db->sql_fetchrow($result)) {
$forum_ids[] = $row['forum_id'];
}
$forum_ids[] = 0;
markread('topics', $forum_ids);
$result = $db->sql_query("
SHOW TABLES LIKE '{$table_prefix}forumrunner_push_users'
");
$row = $db->sql_fetchrow($result);
$db->sql_freeresult($result);
if ($row) {
$db->sql_query("
UPDATE {$table_prefix}forumrunner_push_data AS forumrunner_push_data
LEFT JOIN {$table_prefix}topics AS topics
ON topics.topic_id = forumrunner_push_data.topicid
SET subsent = 0, topicread = " . time() . "
WHERE userid = {$user->data['user_id']} AND topics.forum_id IN (" . join(',', $forum_ids) . ")
");
}
}
return array(
'success' => 1,
);
}
function
do_get_new_updates ()
{
global $auth, $config;
$username = request_var('username', '');
$password = request_var('password', '');
$fr_username = request_var('fr_username', '');
$fr_b = request_var('fr_b', false);
if ($username == '' || $password == '') {
json_error(ERR_NO_PERMISSION);
}
$result = $auth->login($username, $password);
if ($result['status'] != LOGIN_SUCCESS) {
json_error(ERR_NO_PERMISSION);
}
fr_update_push_user($fr_username, $fr_b);
return array(
'pm_notices' => fr_get_pm_unread(),
'sub_notices' => fr_get_sub_thread_updates(),
);
}
function
do_version ()
{
global $fr_version, $fr_platform, $db, $table_prefix;
require_once(MCWD . '/sitekey.php');
$push_enabled = false;
$result = $db->sql_query("
SHOW TABLES LIKE '{$table_prefix}forumrunner_push_users'
");
$row = $db->sql_fetchrow($result);
$db->sql_freeresult($result);
if ($row) {
$push_enabled = true;
}
return array(
'version' => $fr_version,
'platform' => $fr_platform,
'charset' => get_local_charset(),
'push_enabled' => $push_enabled,
'sitekey_setup' => (!$mykey || $mykey == '') ? false : true,
);
}
function
do_report ()
{
global $auth, $config, $user, $db;
// We default to first report id
$forum_id = request_var('forumid', 0);
$post_id = request_var('postid', 0);
$pm_id = 0;
$report_text = utf8_normalize_nfc(request_var('reason', '', true));
$user_notify = false;
if (!$post_id && (!$pm_id || !$config['allow_pm_report']))
{
trigger_error('NO_POST_SELECTED');
}
// Grab all relevant data
$sql = 'SELECT t.*, p.*
FROM ' . POSTS_TABLE . ' p, ' . TOPICS_TABLE . " t
WHERE p.post_id = $post_id
AND p.topic_id = t.topic_id";
$result = $db->sql_query($sql);
$report_data = $db->sql_fetchrow($result);
$db->sql_freeresult($result);
if (!$report_data)
{
trigger_error('POST_NOT_EXIST');
}
$forum_id = (int) ($report_data['forum_id']) ? $report_data['forum_id'] : $forum_id;
$topic_id = (int) $report_data['topic_id'];
$sql = 'SELECT *
FROM ' . FORUMS_TABLE . '
WHERE forum_id = ' . $forum_id;
$result = $db->sql_query($sql);
$forum_data = $db->sql_fetchrow($result);
$db->sql_freeresult($result);
if (!$forum_data)
{
trigger_error('FORUM_NOT_EXIST');
}
// Check required permissions
$acl_check_ary = array('f_list' => 'POST_NOT_EXIST', 'f_read' => 'USER_CANNOT_READ', 'f_report' => 'USER_CANNOT_REPORT');
foreach ($acl_check_ary as $acl => $error)
{
if (!$auth->acl_get($acl, $forum_id))
{
trigger_error($error);
}
}
unset($acl_check_ary);
if ($report_data['post_reported'])
{
$message = $user->lang['ALREADY_REPORTED'];
trigger_error($message);
}
$sql = 'SELECT *
FROM ' . REPORTS_REASONS_TABLE . "
WHERE reason_title = 'other'";
$result = $db->sql_query($sql);
$row = $db->sql_fetchrow($result);
$db->sql_freeresult($result);
if (!$row || (!$report_text && strtolower($row['reason_title']) == 'other'))
{
trigger_error('EMPTY_REPORT');
}
$reason_id = $row['reason_id'];
$sql_ary = array(
'reason_id' => (int) $reason_id,
'post_id' => $post_id,
'pm_id' => $pm_id,
'user_id' => (int) $user->data['user_id'],
'user_notify' => (int) $user_notify,
'report_closed' => 0,
'report_time' => (int) time(),
'report_text' => (string) $report_text
);
$sql = 'INSERT INTO ' . REPORTS_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary);
$db->sql_query($sql);
$report_id = $db->sql_nextid();
$sql = 'UPDATE ' . POSTS_TABLE . '
SET post_reported = 1
WHERE post_id = ' . $post_id;
$db->sql_query($sql);
if (!$report_data['topic_reported'])
{
$sql = 'UPDATE ' . TOPICS_TABLE . '
SET topic_reported = 1
WHERE topic_id = ' . $report_data['topic_id'] . '
OR topic_moved_id = ' . $report_data['topic_id'];
$db->sql_query($sql);
}
return array();
}
?>
|