Viewing file: subscriptions.php (7.46 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('../');
$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);
require($phpbb_root_path . 'includes/functions_display.' . $phpEx);
include($phpbb_root_path . 'includes/message_parser.' . $phpEx);
fr_set_debug();
// Start session management
$user->session_begin();
$auth->acl($user->data);
$user->setup('ucp');
$user->page['root_script_path'] = str_replace('/forumrunner', '', $user->page['root_script_path']);
function
do_get_subscriptions ()
{
global $user, $db, $template, $config, $cache, $auth, $phpbb_root_path, $phpEx;
$table = TOPICS_WATCH_TABLE;
// We send page & num, figure out start
$page = request_var('page', 1);
$perpage = request_var('perpage', 15);
$config['topics_per_page'] = $perpage;
$start = (($page - 1) * $perpage);
$thread_data = array();
// Grab icons
$icons = $cache->obtain_icons();
$sql_array = array(
'SELECT' => 'COUNT(t.topic_id) as topics_count',
'FROM' => array(
$table => 'i',
TOPICS_TABLE => 't'
),
'WHERE' => 'i.topic_id = t.topic_id
AND i.user_id = ' . $user->data['user_id'] . '
AND ' . $db->sql_in_set('t.forum_id', $forbidden_forum_ary, true, true),
);
$sql = $db->sql_build_query('SELECT', $sql_array);
$result = $db->sql_query($sql);
$topics_count = (int) $db->sql_fetchfield('topics_count');
$db->sql_freeresult($result);
$sql_array = array(
'SELECT' => 't.*, f.forum_name',
'FROM' => array(
TOPICS_WATCH_TABLE => 'tw',
TOPICS_TABLE => 't'
),
'WHERE' => 'tw.user_id = ' . $user->data['user_id'] . '
AND t.topic_id = tw.topic_id
AND ' . $db->sql_in_set('t.forum_id', $forbidden_forum_ary, true, true),
'ORDER_BY' => 't.topic_last_post_time DESC'
);
$sql_array['LEFT_JOIN'] = array();
$sql_array['LEFT_JOIN'][] = array('FROM' => array(FORUMS_TABLE => 'f'), 'ON' => 't.forum_id = f.forum_id');
if ($config['load_db_lastread'])
{
$sql_array['LEFT_JOIN'][] = array('FROM' => array(FORUMS_TRACK_TABLE => 'ft'), 'ON' => 'ft.forum_id = t.forum_id AND ft.user_id = ' . $user->data['user_id']);
$sql_array['LEFT_JOIN'][] = array('FROM' => array(TOPICS_TRACK_TABLE => 'tt'), 'ON' => 'tt.topic_id = t.topic_id AND tt.user_id = ' . $user->data['user_id']);
$sql_array['SELECT'] .= ', tt.mark_time, ft.mark_time AS forum_mark_time';
}
$sql = $db->sql_build_query('SELECT', $sql_array);
$result = $db->sql_query_limit($sql, $config['topics_per_page'], $start);
$topic_list = $topic_forum_list = $global_announce_list = $rowset = array();
while ($row = $db->sql_fetchrow($result))
{
$topic_id = (isset($row['b_topic_id'])) ? $row['b_topic_id'] : $row['topic_id'];
$topic_list[] = $topic_id;
$rowset[$topic_id] = $row;
$topic_forum_list[$row['forum_id']]['forum_mark_time'] = ($config['load_db_lastread']) ? $row['forum_mark_time'] : 0;
$topic_forum_list[$row['forum_id']]['topics'][] = $topic_id;
if ($row['topic_type'] == POST_GLOBAL)
{
$global_announce_list[] = $topic_id;
}
}
$db->sql_freeresult($result);
$topic_tracking_info = array();
if ($config['load_db_lastread'])
{
foreach ($topic_forum_list as $f_id => $topic_row)
{
$topic_tracking_info += get_topic_tracking($f_id, $topic_row['topics'], $rowset, array($f_id => $topic_row['forum_mark_time']), ($f_id == 0) ? $global_announce_list : false);
}
}
else
{
foreach ($topic_forum_list as $f_id => $topic_row)
{
$topic_tracking_info += get_complete_topic_tracking($f_id, $topic_row['topics'], $global_announce_list);
}
}
foreach ($topic_list as $topic_id)
{
$row = &$rowset[$topic_id];
$forum_id = $row['forum_id'];
$topic_id = (isset($row['b_topic_id'])) ? $row['b_topic_id'] : $row['topic_id'];
$unread_topic = (isset($topic_tracking_info[$topic_id]) && $row['topic_last_post_time'] > $topic_tracking_info[$topic_id]) ? true : false;
// Replies
$replies = ($auth->acl_get('m_approve', $forum_id)) ? $row['topic_replies_real'] : $row['topic_replies'];
if ($row['topic_status'] == ITEM_MOVED && !empty($row['topic_moved_id']))
{
$topic_id = $row['topic_moved_id'];
}
// Get folder img, topic status/type related information
$folder_img = $folder_alt = $topic_type = '';
topic_status($row, $replies, $unread_topic, $folder_img, $folder_alt, $topic_type);
$view_topic_url_params = "f=$forum_id&t=$topic_id";
$view_topic_url = append_sid("{$phpbb_root_path}viewtopic.$phpEx", $view_topic_url_params);
$avresult = $db->sql_query("
SELECT u.user_avatar, u.user_avatar_type, u.user_avatar_width, u.user_avatar_height
FROM " . POSTS_TABLE . " p
LEFT JOIN " . USERS_TABLE . " u
ON u.user_id = p.poster_id
WHERE p.post_id = {$row['topic_first_post_id']}
");
$avrow = $db->sql_fetchrow($avresult);
$db->sql_freeresult($avresult);
$avatarurl = process_avatarurl(fr_get_user_avatar($avrow['user_avatar'], $avrow['user_avatar_type'], $avrow['user_avatar_width'], $avrow['user_avatar_height']));
$tmp = array(
'thread_id' => $topic_id,
'new_posts' => $unread_topic,
'forum_id' => $forum_id,
'forum_title' => prepare_utf8_string($row['forum_name']),
'thread_title' => prepare_utf8_string(censor_text($row['topic_title'])),
'thread_preview' => prepare_utf8_string(fr_get_preview($row['topic_first_post_id'])),
'post_userid' => $row['topic_poster'],
'post_lastposttime' => prepare_utf8_string(date_trunc($user->format_date($row['topic_last_post_time']))),
'post_username' => prepare_utf8_string(strip_tags($row['topic_first_poster_name'])),
);
if ($avatarurl != '') {
$tmp['avatarurl'] = $avatarurl;
}
if ($row['topic_attachment']) {
$tmp['attach'] = true;
}
if ($row['poll_start']) {
$tmp['poll'] = true;
}
$thread_data[] = $tmp;
}
return array(
'threads' => $thread_data,
'total_threads' => $topics_count,
);
}
function
do_unsubscribe_thread ()
{
global $user, $db;
if (!$user->data['is_registered']) {
json_error(ERR_INVALID_LOGGEDIN, RV_NOT_LOGGED_IN);
}
$topic_id = request_var('threadid', 0);
if (!$topic_id) {
json_error(ERR_INVALID_SUB);
}
$db->sql_query('DELETE FROM ' . TOPICS_WATCH_TABLE . '
WHERE topic_id = ' . $topic_id . '
AND user_id = ' . $user->data['user_id']
);
return array(
'success' => true,
);
}
function
do_subscribe_thread ()
{
global $user, $db;
if (!$user->data['is_registered']) {
json_error(ERR_INVALID_LOGGEDIN, RV_NOT_LOGGED_IN);
}
$topic_id = request_var('threadid', 0);
if (!$topic_id) {
json_error(ERR_INVALID_SUB);
}
$db->sql_query('DELETE FROM ' . TOPICS_WATCH_TABLE . '
WHERE topic_id = ' . $topic_id . '
AND user_id = ' . $user->data['user_id']
);
$db->sql_query("INSERT INTO " . TOPICS_WATCH_TABLE . " (user_id, topic_id, notify_status)
VALUES (" . $user->data['user_id'] . ", {$topic_id}, 0)
");
return array(
'success' => true,
);
}
?>
|