Example #1
0
/**
* A version of cache_moderators that can be safely called multiple times
* without doing extra work.
*/
function cache_moderators_once($userid = null)
{
    global $imodcache;
    if (!isset($imodcache)) {
        cache_moderators($userid);
    }
}
 /**
  * Run Tool
  *
  * Does the actual stuff we want the tool to do after submission
  */
 function run_tool()
 {
     if (!function_exists('cache_moderators')) {
         global $phpbb_root_path, $phpEx;
         include "{$phpbb_root_path}includes/functions_admin.{$phpEx}";
     }
     cache_moderators();
     trigger_error('RECACHE_MODERATORS_COMPLETE');
 }
Example #3
0
 /**
  * Run Tool
  *
  * Does the actual stuff we want the tool to do after submission
  */
 function run_tool(&$error)
 {
     global $auth, $cache;
     $cache->purge();
     // Clear permissions
     $auth->acl_clear_prefetch();
     cache_moderators();
     add_log('admin', 'LOG_PURGE_CACHE');
     trigger_error('PURGE_CACHE_COMPLETE');
 }
Example #4
0
 public function fetch_validated_list($user, $ids, $gids)
 {
     require_once DIR . '/includes/functions_forumlist.php';
     cache_moderators();
     $list = array_fill_keys($ids, false);
     foreach (vB_Legacy_Thread::create_array($ids) as $key => $thread) {
         $item = vBForum_Search_Result_Thread::create_from_thread($thread);
         if ($item->can_search($user)) {
             $list[$key] = $item;
         }
     }
     $retval = array('list' => $list, 'groups_rejected' => $rejected_groups);
     ($hook = vBulletinHook::fetch_hook('search_validated_list')) ? eval($hook) : false;
     return $retval;
 }
Example #5
0
function do_get_profile()
{
    global $vbulletin;
    $userinfo = vB_Api::instance('user')->fetchUserInfo();
    $cleaned = vB::getCleaner()->cleanArray($_REQUEST, array('userid' => vB_Cleaner::TYPE_UINT));
    if (!$userinfo['userid'] && !$cleaned['userid']) {
        return json_error(ERR_INVALID_LOGGEDIN, RV_NOT_LOGGED_IN);
    }
    if (!$cleaned['userid']) {
        $cleaned['userid'] = $userinfo['userid'];
    }
    $profile = vB_Api::instance('user')->fetchProfileInfo($cleaned['userid']);
    if (empty($profile)) {
        return json_error(ERR_NO_PERMISSION);
    }
    $values = array();
    foreach ($profile['customFields']['default'] as $name => $value) {
        $value = $value['val'];
        if ($value === null) {
            $value = '';
        }
        $values[] = array('name' => (string) new vB_Phrase('cprofilefield', $name), 'value' => $value);
    }
    $groups = array();
    $groups[] = array('name' => 'about', 'values' => $values);
    $out = array('username' => prepare_utf8_string($profile['username']), 'joindate' => prepare_utf8_string(fr_date($profile['joindate'])), 'posts' => $profile['posts'], 'online' => fr_get_user_online($profile['lastactivity']), 'avatar_upload' => $profile['canuseavatar'] ? true : false, 'groups' => $groups);
    $avatarurl = vB_Library::instance('vb4_functions')->avatarUrl($cleaned['userid']);
    if ($avatarurl) {
        $out['avatarurl'] = $avatarurl;
    }
    cache_moderators();
    cache_permissions($vbulletin->userinfo);
    $canbanuser = ($vbulletin->userinfo['permissions']['adminpermissions'] & $vbulletin->bf_ugp_adminpermissions['cancontrolpanel'] or can_moderate(0, 'canbanusers'));
    if ($canbanuser) {
        $out['ban'] = true;
    }
    return $out;
}
    print_description_row("<b><a href=\"forumpermission.php?" . vB::getCurrentSession()->get('sessionurl') . "do=duplicate\">" . $vbphrase['permission_duplication_tools'] . "</a> | <a href=\"forumpermission.php?" . vB::getCurrentSession()->get('sessionurl') . "do=quickedit\">" . $vbphrase['permissions_quick_editor'] . "</a> | <a href=\"forumpermission.php?" . vB::getCurrentSession()->get('sessionurl') . "do=quickforum\">" . $vbphrase['quick_channel_permission_setup'] . "</a></b>", 0, 2, '', 'center');
    print_table_footer();
    print_form_header('', '');
    print_table_header($vbphrase['view_channel_permissions_gcppermission']);
    print_description_row('
		<div class="darkbg" style="border: 2px inset"><ul class="darkbg">
		<li><b>' . $vbphrase['color_key'] . '</b></li>
		<li class="col-g">' . $vbphrase['standard_using_default_channel_permissions'] . '</li>
		<li class="col-c">' . $vbphrase['customized_using_custom_permissions_for_this_usergroup_gcppermission'] . '</li>
		<li class="col-i">' . $vbphrase['inherited_using_custom_permissions_inherited_channel_a_parent_channel'] . '</li>
		</ul></div>
	');
    print_table_footer();
    require_once DIR . '/includes/functions_forumlist.php';
    // get moderators
    cache_moderators();
    //query channel permissions
    $result = vB::getDbAssertor()->assertQuery('vBForum:permission', array(vB_dB_Query::TYPE_KEY => vB_dB_Query::QUERY_SELECT));
    $npermscache = array();
    foreach ($result as $permission) {
        $npermscache[$permission['nodeid']][$permission['groupid']] = $permission;
    }
    // get usergroup default permissions
    $permissions = array();
    $usergroupcache = vB::getDatastore()->getValue('usergroupcache');
    foreach ($usergroupcache as $usergroupid => $usergroup) {
        $permissions["{$usergroupid}"] = $usergroup['forumpermissions'];
    }
    //build_channel_permissions();
    ?>
<center>
Example #7
0
	/**
	* Finish conversion, the last function to be called.
	*/
	function finish_conversion()
	{
		global $db, $phpbb_root_path, $phpEx, $convert, $config, $language, $user, $template;

		$db->sql_query('DELETE FROM ' . CONFIG_TABLE . "
			WHERE config_name = 'convert_progress'
				OR config_name = 'convert_options'
				OR config_name = 'convert_db_server'
				OR config_name = 'convert_db_user'");
		$db->sql_query('DELETE FROM ' . SESSIONS_TABLE);

		@unlink($phpbb_root_path . 'cache/data_global.' . $phpEx);
		cache_moderators();

		// And finally, add a note to the log
		add_log('admin', 'LOG_INSTALL_CONVERTED', $convert->convertor_data['forum_name'], $config['version']);

		$url = $this->p_master->module_url . "?mode={$this->mode}&amp;sub=final&amp;language=$language";

		$template->assign_vars(array(
			'L_SUBMIT'		=> $user->lang['FINAL_STEP'],
			'U_ACTION'		=> $url,
		));

		$this->meta_refresh($url);
		return;
	}
Example #8
0
 /**
  * Remove permissions
  */
 function remove_permissions($mode, $permission_type, &$auth_admin, &$user_id, &$group_id, &$forum_id)
 {
     global $user, $db, $auth;
     // User or group to be set?
     $ug_type = sizeof($user_id) ? 'user' : 'group';
     // Check the permission setting again
     if (!$auth->acl_get('a_' . str_replace('_', '', $permission_type) . 'auth') || !$auth->acl_get('a_auth' . $ug_type . 's')) {
         trigger_error($user->lang['NO_AUTH_OPERATION'] . adm_back_link($this->u_action), E_USER_WARNING);
     }
     $auth_admin->acl_delete($ug_type, $ug_type == 'user' ? $user_id : $group_id, sizeof($forum_id) ? $forum_id : false, $permission_type);
     // Do we need to recache the moderator lists?
     if ($permission_type == 'm_') {
         cache_moderators();
     }
     $this->log_action($mode, 'del', $permission_type, $ug_type, $ug_type == 'user' ? $user_id : $group_id, sizeof($forum_id) ? $forum_id : array(0 => 0));
     if ($mode == 'setting_forum_local' || $mode == 'setting_mod_local') {
         trigger_error($user->lang['AUTH_UPDATED'] . adm_back_link($this->u_action . '&amp;forum_id[]=' . implode('&amp;forum_id[]=', $forum_id)));
     } else {
         trigger_error($user->lang['AUTH_UPDATED'] . adm_back_link($this->u_action));
     }
 }
 /**
  * Handles copying permissions from one forum to others
  */
 function copy_forum_permissions()
 {
     global $auth, $cache, $template, $user;
     $user->add_lang('acp/forums');
     $submit = isset($_POST['submit']) ? true : false;
     if ($submit) {
         $src = request_var('src_forum_id', 0);
         $dest = request_var('dest_forum_ids', array(0));
         if (confirm_box(true)) {
             if (copy_forum_permissions($src, $dest)) {
                 cache_moderators();
                 $auth->acl_clear_prefetch();
                 $cache->destroy('sql', FORUMS_TABLE);
                 trigger_error($user->lang['AUTH_UPDATED'] . adm_back_link($this->u_action));
             } else {
                 trigger_error($user->lang['SELECTED_FORUM_NOT_EXIST'] . adm_back_link($this->u_action), E_USER_WARNING);
             }
         } else {
             $s_hidden_fields = array('submit' => $submit, 'src_forum_id' => $src, 'dest_forum_ids' => $dest);
             $s_hidden_fields = build_hidden_fields($s_hidden_fields);
             confirm_box(false, $user->lang['COPY_PERMISSIONS_CONFIRM'], $s_hidden_fields);
         }
     }
     $template->assign_vars(array('S_FORUM_OPTIONS' => make_forum_select(false, false, false, false, false)));
 }
Example #10
0
function do_get_profile()
{
    global $vbulletin, $db, $show, $vbphrase, $permissions, $imodcache;
    $vbulletin->input->clean_array_gpc('r', array('userid' => TYPE_UINT));
    if (!$vbulletin->userinfo['userid'] && !$vbulletin->GPC['userid']) {
        json_error(ERR_INVALID_LOGGEDIN, RV_NOT_LOGGED_IN);
    }
    if (!($permissions['forumpermissions'] & $vbulletin->bf_ugp_forumpermissions['canview']) or !($permissions['genericpermissions'] & $vbulletin->bf_ugp_genericpermissions['canviewmembers'])) {
        json_error(ERR_NO_PERMISSION);
    }
    if (!$vbulletin->GPC['userid']) {
        $vbulletin->GPC['userid'] = $vbulletin->userinfo['userid'];
    }
    $fetch_userinfo_options = FETCH_USERINFO_AVATAR | FETCH_USERINFO_LOCATION | FETCH_USERINFO_PROFILEPIC | FETCH_USERINFO_SIGPIC | FETCH_USERINFO_USERCSS | FETCH_USERINFO_ISFRIEND;
    $userinfo = verify_id('user', $vbulletin->GPC['userid'], 1, $fetch_userinfo_options);
    if ($userinfo['usergroupid'] == 4 and !($permissions['adminpermissions'] & $vbulletin->bf_ugp_adminpermissions['cancontrolpanel'])) {
        json_error(ERR_NO_PERMISSION);
    }
    $posts = $userinfo['posts'];
    $joindate = vbdate($vbulletin->options['dateformat'], $userinfo['joindate']);
    $out = array('username' => html_entity_decode($userinfo['username']), 'online' => fetch_online_status($userinfo, false), 'avatar_upload' => $vbulletin->options['avatarenabled'] && $permissions['genericpermissions'] & $vbulletin->bf_ugp_genericpermissions['canuseavatar'], 'posts' => $posts, 'joindate' => $joindate);
    $avatarurl_info = fetch_avatar_url($userinfo['userid']);
    if ($avatarurl_info) {
        $out['avatarurl'] = process_avatarurl($avatarurl_info[0]);
    }
    cache_moderators();
    $canbanuser = ($vbulletin->userinfo['permissions']['adminpermissions'] & $vbulletin->bf_ugp_adminpermissions['cancontrolpanel'] or can_moderate(0, 'canbanusers'));
    if ($canbanuser) {
        $out['ban'] = true;
    }
    $groups = array();
    // About
    $out_group = array('name' => 'about', 'values' => array(array('name' => prepare_utf8_string($vbphrase['posts']), 'value' => strval(vb_number_format($userinfo['posts']))), array('name' => prepare_utf8_string($vbphrase['join_date']), 'value' => vbdate($vbulletin->options['dateformat'], $userinfo['joindate']))));
    if (function_exists('itrader_user')) {
        itrader_user($userinfo);
        $out_group['values'][] = array('name' => 'iTrader', 'value' => vb_number_format($userinfo['tradescore']) . ', ' . $userinfo['tradepcnt'] . '%');
        $out += array('itrader_score' => vb_number_format($userinfo['tradescore']), 'itrader_percent' => $userinfo['tradepcnt'] . '%');
    }
    $groups[] = $out_group;
    $profileobj = new vB_UserProfile($vbulletin, $userinfo);
    $blockfactory = new vB_ProfileBlockFactory($vbulletin, $profileobj);
    $profileblock =& $blockfactory->fetch('ProfileFields');
    $profileblock->build_field_data(false);
    $profile = $profileblock->categories[0];
    // Additional information
    if (count($profile)) {
        $out_group = array('name' => 'additional');
        foreach ($profile as $profilefield) {
            $field_value = $userinfo["field{$profilefield['profilefieldid']}"];
            fetch_profilefield_display($profilefield, $field_value);
            if (!strlen(trim($field_value))) {
                continue;
            }
            $out_group['values'][] = array('name' => prepare_utf8_string($profilefield['title']), 'value' => prepare_utf8_string($profilefield['value']));
        }
        if (count($out_group['values'])) {
            $groups[] = $out_group;
        }
    }
    $out['groups'] = $groups;
    return $out;
}
Example #11
0
/**
* Re-cache moderators and foes if group has a_ or m_ permissions
*/
function group_update_listings($group_id)
{
    global $auth;
    $hold_ary = $auth->acl_group_raw_data($group_id, array('a_', 'm_'));
    if (!sizeof($hold_ary)) {
        return;
    }
    $mod_permissions = $admin_permissions = false;
    foreach ($hold_ary as $g_id => $forum_ary) {
        foreach ($forum_ary as $forum_id => $auth_ary) {
            foreach ($auth_ary as $auth_option => $setting) {
                if ($mod_permissions && $admin_permissions) {
                    break 3;
                }
                if ($setting != ACL_YES) {
                    continue;
                }
                if ($auth_option == 'm_') {
                    $mod_permissions = true;
                }
                if ($auth_option == 'a_') {
                    $admin_permissions = true;
                }
            }
        }
    }
    if ($mod_permissions) {
        if (!function_exists('cache_moderators')) {
            global $phpbb_root_path, $phpEx;
            include $phpbb_root_path . 'includes/functions_admin.' . $phpEx;
        }
        cache_moderators();
    }
    if ($mod_permissions || $admin_permissions) {
        if (!function_exists('update_foes')) {
            global $phpbb_root_path, $phpEx;
            include $phpbb_root_path . 'includes/functions_admin.' . $phpEx;
        }
        update_foes(array($group_id));
    }
}
Example #12
0
function do_get_forum()
{
    global $vbulletin, $db, $show, $vbphrase, $foruminfo;
    $canpost = true;
    $vbulletin->input->clean_array_gpc('r', array('fid' => TYPE_INT, 'previewtype' => TYPE_INT));
    $previewtype = $vbulletin->GPC['previewtype'];
    if (!$previewtype) {
        $previewtype = 1;
    }
    if (empty($foruminfo['forumid'])) {
        $forumid = -1;
    } else {
        $vbulletin->input->clean_array_gpc('r', array('password' => TYPE_STR));
        // Check the forum password
        if ($vbulletin->GPC['password'] && $foruminfo['password'] == $vbulletin->GPC['password']) {
            // Set a temp cookie for guests
            if (!$vbulletin->userinfo['userid']) {
                set_bbarray_cookie('forumpwd', $foruminfo['forumid'], md5($vbulletin->userinfo['userid'] . $vbulletin->GPC['password']));
            } else {
                set_bbarray_cookie('forumpwd', $foruminfo['forumid'], md5($vbulletin->userinfo['userid'] . $vbulletin->GPC['password']), 1);
            }
        }
        $perpage = $vbulletin->input->clean_gpc('r', 'perpage', TYPE_UINT);
        $pagenumber = $vbulletin->input->clean_gpc('r', 'pagenumber', TYPE_UINT);
        $daysprune = $vbulletin->input->clean_gpc('r', 'daysprune', TYPE_INT);
        $sortfield = $vbulletin->input->clean_gpc('r', 'sortfield', TYPE_STR);
        // get permission to view forum
        $_permsgetter_ = 'forumdisplay';
        $forumperms = fetch_permissions($foruminfo['forumid']);
        if (!($forumperms & $vbulletin->bf_ugp_forumpermissions['canview'])) {
            json_error(ERR_NO_PERMISSION);
        }
        // Check for forum password!
        if (!verify_forum_password($foruminfo['forumid'], $foruminfo['password'], false)) {
            json_error(ERR_NEED_PASSWORD, RV_NEED_FORUM_PASSWORD);
        }
        // Can we post in this forum?
        if (!($forumperms & $vbulletin->bf_ugp_forumpermissions['canpostnew'])) {
            $canpost = false;
        }
        $forumid = $foruminfo['forumid'];
    }
    // Can forum contain threads?
    $announcements_out = array();
    // These $_REQUEST values will get used in the sort template so they are assigned to normal variables
    $perpage = $vbulletin->input->clean_gpc('r', 'perpage', TYPE_UINT);
    $pagenumber = $vbulletin->input->clean_gpc('r', 'pagenumber', TYPE_UINT);
    $daysprune = $vbulletin->input->clean_gpc('r', 'daysprune', TYPE_INT);
    $sortfield = $vbulletin->input->clean_gpc('r', 'sortfield', TYPE_STR);
    // get permission to view forum
    $_permsgetter_ = 'forumdisplay';
    $forumperms = fetch_permissions($foruminfo['forumid']);
    if (!($forumperms & $vbulletin->bf_ugp_forumpermissions['canview'])) {
        json_error(ERR_NO_PERMISSION);
    }
    // disable thread preview if we can't view threads
    if (!($forumperms & $vbulletin->bf_ugp_forumpermissions['canviewthreads'])) {
        $vbulletin->options['threadpreview'] = 0;
    }
    // check if there is a forum password and if so, ensure the user has it set
    verify_forum_password($foruminfo['forumid'], $foruminfo['password']);
    // verify that we are at the canonical SEO url
    // and redirect to this if not
    //verify_seo_url('forum', $foruminfo, array('pagenumber' => $_REQUEST['pagenumber']));
    // get vbulletin->iforumcache - for use by makeforumjump and forums list
    // fetch the forum even if they are invisible since its needed
    // for the title but we'll unset that further down
    // also fetch subscription info for $show['subscribed'] variable
    cache_ordered_forums(1, 1, $vbulletin->userinfo['userid']);
    $show['newthreadlink'] = iif(!$show['search_engine'] and $foruminfo['allowposting'], true, false);
    $show['threadicons'] = iif($foruminfo['allowicons'], true, false);
    $show['threadratings'] = iif($foruminfo['allowratings'], true, false);
    $show['subscribed_to_forum'] = $vbulletin->forumcache["{$foruminfo['forumid']}"]['subscribeforumid'] != '' ? true : false;
    if (!$daysprune) {
        if ($vbulletin->userinfo['daysprune']) {
            $daysprune = $vbulletin->userinfo['daysprune'];
        } else {
            $daysprune = iif($foruminfo['daysprune'], $foruminfo['daysprune'], 30);
        }
    }
    $daysprune = -1;
    // FRNR
    // ### GET FORUMS, PERMISSIONS, MODERATOR iCACHES ########################
    cache_moderators();
    // draw nav bar
    $navbits = array();
    $navbits[$vbulletin->options['forumhome'] . '.php' . $vbulletin->session->vars['sessionurl_q']] = $vbphrase['forum'];
    $parentlist = array_reverse(explode(',', substr($foruminfo['parentlist'], 0, -3)));
    foreach ($parentlist as $forumID) {
        $forumTitle = $vbulletin->forumcache["{$forumID}"]['title'];
        $navbits[fetch_seo_url('forum', array('forumid' => $forumID, 'title' => $forumTitle))] = $forumTitle;
    }
    // pop the last element off the end of the $nav array so that we can show it without a link
    array_pop($navbits);
    $navbits[''] = $foruminfo['title'];
    $navbits = construct_navbits($navbits);
    $navbar = render_navbar_template($navbits);
    $moderatorslist = '';
    $listexploded = explode(',', $foruminfo['parentlist']);
    $showmods = array();
    $show['moderators'] = false;
    $totalmods = 0;
    foreach ($listexploded as $parentforumid) {
        if (!$imodcache["{$parentforumid}"] or $parentforumid == -1) {
            continue;
        }
        foreach ($imodcache["{$parentforumid}"] as $moderator) {
            if ($showmods["{$moderator['userid']}"] === true) {
                continue;
            }
            $showmods["{$moderator['userid']}"] = true;
            $show['comma_leader'] = $moderatorslist != '';
            $show['moderators'] = true;
            $totalmods++;
        }
    }
    // ### BUILD FORUMS LIST #################################################
    // get an array of child forum ids for this forum
    $foruminfo['childlist'] = explode(',', $foruminfo['childlist']);
    // define max depth for forums display based on $vbulletin->options[forumhomedepth]
    define('MAXFORUMDEPTH', $vbulletin->options['forumdisplaydepth']);
    if (($vbulletin->options['showforumusers'] == 1 or $vbulletin->options['showforumusers'] == 2 or $vbulletin->options['showforumusers'] > 2 and $vbulletin->userinfo['userid']) and !$show['search_engine']) {
        $datecut = TIMENOW - $vbulletin->options['cookietimeout'];
        $forumusers = $db->query_read_slave("\n    \t\tSELECT user.username, (user.options & " . $vbulletin->bf_misc_useroptions['invisible'] . ") AS invisible, user.usergroupid,\n    \t\t\tsession.userid, session.inforum, session.lastactivity, session.badlocation,\n    \t\t\tIF(displaygroupid=0, user.usergroupid, displaygroupid) AS displaygroupid, infractiongroupid\n    \t\tFROM " . TABLE_PREFIX . "session AS session\n    \t\tLEFT JOIN " . TABLE_PREFIX . "user AS user ON(user.userid = session.userid)\n    \t\tWHERE session.lastactivity > {$datecut}\n    \t\tORDER BY" . iif($vbulletin->options['showforumusers'] == 1 or $vbulletin->options['showforumusers'] == 3, " username ASC,") . " lastactivity DESC\n    \t");
        $numberregistered = 0;
        $numberguest = 0;
        $doneuser = array();
        if ($vbulletin->userinfo['userid']) {
            // fakes the user being in this forum
            $loggedin = array('userid' => $vbulletin->userinfo['userid'], 'username' => $vbulletin->userinfo['username'], 'invisible' => $vbulletin->userinfo['invisible'], 'invisiblemark' => $vbulletin->userinfo['invisiblemark'], 'inforum' => $foruminfo['forumid'], 'lastactivity' => TIMENOW, 'musername' => $vbulletin->userinfo['musername']);
            $numberregistered = 1;
            fetch_online_status($loggedin);
            $show['comma_leader'] = false;
            $doneuser["{$vbulletin->userinfo['userid']}"] = 1;
        }
        $inforum = array();
        // this require the query to have lastactivity ordered by DESC so that the latest location will be the first encountered.
        while ($loggedin = $db->fetch_array($forumusers)) {
            if ($loggedin['badlocation']) {
                continue;
            }
            if (empty($doneuser["{$loggedin['userid']}"])) {
                if (in_array($loggedin['inforum'], $foruminfo['childlist']) and $loggedin['inforum'] != -1) {
                    if (!$loggedin['userid']) {
                        // this is a guest
                        $numberguest++;
                        $inforum["{$loggedin['inforum']}"]++;
                    } else {
                        $numberregistered++;
                        $inforum["{$loggedin['inforum']}"]++;
                        if (fetch_online_status($loggedin)) {
                            fetch_musername($loggedin);
                            $show['comma_leader'] = $activeusers != '';
                        }
                    }
                }
                if ($loggedin['userid']) {
                    $doneuser["{$loggedin['userid']}"] = 1;
                }
            }
        }
        if (!$vbulletin->userinfo['userid']) {
            $numberguest = $numberguest == 0 ? 1 : $numberguest;
        }
        $totalonline = $numberregistered + $numberguest;
        unset($joingroupid, $key, $datecut, $invisibleuser, $userinfo, $userid, $loggedin, $index, $value, $forumusers, $parentarray);
        $show['activeusers'] = true;
    } else {
        $show['activeusers'] = false;
    }
    // #############################################################################
    // get read status for this forum and children
    $unreadchildforums = 0;
    foreach ($foruminfo['childlist'] as $val) {
        if ($val == -1 or $val == $foruminfo['forumid']) {
            continue;
        }
        if ($vbulletin->options['threadmarking'] and $vbulletin->userinfo['userid']) {
            $lastread_child = max($vbulletin->forumcache["{$val}"]['forumread'], TIMENOW - $vbulletin->options['markinglimit'] * 86400);
        } else {
            $lastread_child = max(intval(fetch_bbarray_cookie('forum_view', $val)), $vbulletin->userinfo['lastvisit']);
        }
        if ($vbulletin->forumcache["{$val}"]['lastpost'] > $lastread_child) {
            $unreadchildforums = 1;
            break;
        }
    }
    $forumbits = fr_construct_forum_bit($forumid);
    // admin tools
    $show['post_queue'] = can_moderate($foruminfo['forumid'], 'canmoderateposts');
    $show['attachment_queue'] = can_moderate($foruminfo['forumid'], 'canmoderateattachments');
    $show['mass_move'] = can_moderate($foruminfo['forumid'], 'canmassmove');
    $show['mass_prune'] = can_moderate($foruminfo['forumid'], 'canmassprune');
    $show['post_new_announcement'] = can_moderate($foruminfo['forumid'], 'canannounce');
    $show['addmoderator'] = $permissions['adminpermissions'] & $vbulletin->bf_ugp_adminpermissions['cancontrolpanel'];
    $show['adminoptions'] = ($show['post_queue'] or $show['attachment_queue'] or $show['mass_move'] or $show['mass_prune'] or $show['addmoderator'] or $show['post_new_announcement']);
    $navpopup = array('id' => 'forumdisplay_navpopup', 'title' => $foruminfo['title_clean'], 'link' => fetch_seo_url('forum', $foruminfo));
    construct_quick_nav($navpopup);
    /////////////////////////////////
    if ($foruminfo['cancontainthreads']) {
        /////////////////////////////////
        if ($vbulletin->options['threadmarking'] and $vbulletin->userinfo['userid']) {
            $foruminfo['forumread'] = $vbulletin->forumcache["{$foruminfo['forumid']}"]['forumread'];
            $lastread = max($foruminfo['forumread'], TIMENOW - $vbulletin->options['markinglimit'] * 86400);
        } else {
            $bbforumview = intval(fetch_bbarray_cookie('forum_view', $foruminfo['forumid']));
            $lastread = max($bbforumview, $vbulletin->userinfo['lastvisit']);
        }
        // Inline Moderation
        $show['movethread'] = can_moderate($forumid, 'canmanagethreads') ? true : false;
        $show['deletethread'] = (can_moderate($forumid, 'candeleteposts') or can_moderate($forumid, 'canremoveposts')) ? true : false;
        $show['approvethread'] = can_moderate($forumid, 'canmoderateposts') ? true : false;
        $show['openthread'] = can_moderate($forumid, 'canopenclose') ? true : false;
        $show['inlinemod'] = ($show['movethread'] or $show['deletethread'] or $show['approvethread'] or $show['openthread']) ? true : false;
        $show['spamctrls'] = ($show['inlinemod'] and $show['deletethread']);
        $url = $show['inlinemod'] ? SCRIPTPATH : '';
        // fetch popup menu
        if ($show['popups'] and $show['inlinemod']) {
        } else {
            $threadadmin_imod_thread_menu = '';
        }
        // get announcements
        $announcebits = '';
        if ($show['threadicons'] and $show['inlinemod']) {
            $announcecolspan = 6;
        } else {
            if (!$show['threadicons'] and !$show['inlinemod']) {
                $announcecolspan = 4;
            } else {
                $announcecolspan = 5;
            }
        }
        $mindate = TIMENOW - 2592000;
        // 30 days
        $hook_query_fields = $hook_query_joins = $hook_query_where = '';
        $announcements = $db->query_read_slave("\n    \t\tSELECT\n    \t\t\tannouncement.announcementid, startdate, title, announcement.views,\n    \t\t\tuser.username, user.userid, user.usertitle, user.customtitle, user.usergroupid,\n    \t\t\tIF(displaygroupid=0, user.usergroupid, displaygroupid) AS displaygroupid, infractiongroupid\n    \t\t\t" . ($vbulletin->userinfo['userid'] ? ", NOT ISNULL(announcementread.announcementid) AS readannounce" : "") . "\n    \t\t\t{$hook_query_fields}\n    \t\tFROM " . TABLE_PREFIX . "announcement AS announcement\n    \t\t" . ($vbulletin->userinfo['userid'] ? "LEFT JOIN " . TABLE_PREFIX . "announcementread AS announcementread ON (announcementread.announcementid = announcement.announcementid AND announcementread.userid = " . $vbulletin->userinfo['userid'] . ")" : "") . "\n    \t\tLEFT JOIN " . TABLE_PREFIX . "user AS user ON(user.userid = announcement.userid)\n    \t\t{$hook_query_joins}\n    \t\tWHERE startdate <= " . TIMENOW . "\n    \t\t\tAND enddate >= " . TIMENOW . "\n    \t\t\tAND " . fetch_forum_clause_sql($foruminfo['forumid'], 'forumid') . "\n    \t\t\t{$hook_query_where}\n    \t\tORDER BY startdate DESC, announcement.announcementid DESC\n    \t\t" . iif($vbulletin->options['oneannounce'], "LIMIT 1"));
        while ($announcement = $db->fetch_array($announcements)) {
            fetch_musername($announcement);
            $announcement['title'] = fetch_censored_text($announcement['title']);
            $announcement['postdate'] = vbdate($vbulletin->options['dateformat'], $announcement['startdate']);
            if ($announcement['readannounce'] or $announcement['startdate'] <= $mindate) {
                $announcement['statusicon'] = 'old';
            } else {
                $announcement['statusicon'] = 'new';
            }
            $announcement['views'] = vb_number_format($announcement['views']);
            $announcementidlink = iif(!$vbulletin->options['oneannounce'], "&amp;a={$announcement['announcementid']}");
            // FRNR START
            if ($pagenumber == 1) {
                $avatarurl = '';
                $userinfoavatar = fetch_userinfo($announcement['userid'], FETCH_USERINFO_AVATAR);
                fetch_avatar_from_userinfo($userinfoavatar, true, false);
                if ($userinfoavatar['avatarurl'] != '') {
                    $avatarurl = process_avatarurl($userinfoavatar['avatarurl']);
                }
                unset($userinfoavatar);
                $tmp = array('thread_id' => $foruminfo['forumid'], 'announcement' => 1, 'new_posts' => $announcement['readannounce'] ? 0 : 1, 'thread_title' => prepare_utf8_string(strip_tags($announcement['title'])), 'thread_preview' => prepare_utf8_string(preview_chop(html_entity_decode($announcement['pagetext']), FR_PREVIEW_LEN)), 'post_userid' => $announcement['userid'], 'post_lastposttime' => prepare_utf8_string(date_trunc($announcement['postdate'])), 'post_username' => prepare_utf8_string(strip_tags($announcement['username'])));
                if ($avatarurl != '') {
                    $tmp['avatarurl'] = $avatarurl;
                }
                $announcements_out[] = $tmp;
            }
            // FRNR END
        }
        // display threads
        if (!($forumperms & $vbulletin->bf_ugp_forumpermissions['canviewothers'])) {
            $limitothers = "AND postuserid = " . $vbulletin->userinfo['userid'] . " AND " . $vbulletin->userinfo['userid'] . " <> 0";
        } else {
            $limitothers = '';
        }
        if (can_moderate($foruminfo['forumid'])) {
            $redirectjoin = "LEFT JOIN " . TABLE_PREFIX . "threadredirect AS threadredirect ON(thread.open = 10 AND thread.threadid = threadredirect.threadid)";
        } else {
            $redirectjoin = '';
        }
        // filter out deletion notices if can't be seen
        if ($forumperms & $vbulletin->bf_ugp_forumpermissions['canseedelnotice'] or can_moderate($foruminfo['forumid'])) {
            $canseedelnotice = true;
            $deljoin = "LEFT JOIN " . TABLE_PREFIX . "deletionlog AS deletionlog ON(thread.threadid = deletionlog.primaryid AND deletionlog.type = 'thread')";
        } else {
            $canseedelnotice = false;
            $deljoin = '';
        }
        // remove threads from users on the global ignore list if user is not a moderator
        if ($Coventry = fetch_coventry('string') and !can_moderate($foruminfo['forumid'])) {
            $globalignore = "AND postuserid NOT IN ({$Coventry}) ";
        } else {
            $globalignore = '';
        }
        // look at thread limiting options
        $stickyids = '';
        $stickycount = 0;
        if ($daysprune != -1) {
            if ($vbulletin->userinfo['userid'] and in_coventry($vbulletin->userinfo['userid'], true)) {
                $tachyjoin = "LEFT JOIN " . TABLE_PREFIX . "tachythreadpost AS tachythreadpost ON " . "(tachythreadpost.threadid = thread.threadid AND tachythreadpost.userid = " . $vbulletin->userinfo['userid'] . ")";
                $datecut = " AND (thread.lastpost >= " . (TIMENOW - $daysprune * 86400) . " OR tachythreadpost.lastpost >= " . (TIMENOW - $daysprune * 86400) . ")";
            } else {
                $datecut = "AND lastpost >= " . (TIMENOW - $daysprune * 86400);
                $tachyjoin = "";
            }
            $show['noposts'] = false;
        } else {
            $tachyjoin = "";
            $datecut = "";
            $show['noposts'] = true;
        }
        // complete form fields on page
        $daysprunesel = iif($daysprune == -1, 'all', $daysprune);
        $daysprunesel = array($daysprunesel => 'selected="selected"');
        $vbulletin->input->clean_array_gpc('r', array('sortorder' => TYPE_NOHTML, 'prefixid' => TYPE_NOHTML));
        // prefix options
        $prefix_options = fetch_prefix_html($foruminfo['forumid'], $vbulletin->GPC['prefixid']);
        $prefix_selected = array('anythread', 'anythread' => '', 'none' => '');
        if ($vbulletin->GPC['prefixid']) {
            //no prefix id
            if ($vbulletin->GPC['prefixid'] == '-1') {
                $prefix_filter = "AND thread.prefixid = ''";
                $prefix_selected['none'] = ' selected="selected"';
            } else {
                if ($vbulletin->GPC['prefixid'] == '-2') {
                    $prefix_filter = "AND thread.prefixid <> ''";
                    $prefix_selected['anyprefix'] = ' selected="selected"';
                } else {
                    $prefix_filter = "AND thread.prefixid = '" . $db->escape_string($vbulletin->GPC['prefixid']) . "'";
                }
            }
        } else {
            $prefix_filter = '';
            $prefix_selected['anythread'] = ' selected="selected"';
        }
        // default sorting methods
        if (empty($sortfield)) {
            $sortfield = $foruminfo['defaultsortfield'];
        }
        if (empty($vbulletin->GPC['sortorder'])) {
            $vbulletin->GPC['sortorder'] = $foruminfo['defaultsortorder'];
        }
        // look at sorting options:
        if ('asc' != ($sortorder = $vbulletin->GPC['sortorder'])) {
            $sqlsortorder = 'DESC';
            $order = array('desc' => 'checked="checked"');
            $vbulletin->GPC['sortorder'] = 'desc';
        } else {
            $sqlsortorder = '';
            $order = array('asc' => 'checked="checked"');
        }
        $sqlsortfield2 = '';
        switch ($sortfield) {
            case 'title':
                $sqlsortfield = 'thread.title';
                break;
            case 'lastpost':
                $sqlsortfield = 'lastpost';
                break;
            case 'replycount':
            case 'views':
                $sqlsortfield = 'views';
            case 'postusername':
                $sqlsortfield = $sortfield;
                break;
            case 'voteavg':
                if ($foruminfo['allowratings']) {
                    $sqlsortfield = 'voteavg';
                    $sqlsortfield2 = 'votenum';
                    break;
                }
            case 'dateline':
                $sqlsortfield = 'thread.dateline';
                break;
                // else, use last post
            // else, use last post
            default:
                $handled = false;
                if (!$handled) {
                    $sqlsortfield = 'lastpost';
                    $sortfield = 'lastpost';
                }
        }
        $sort = array($sortfield => 'selected="selected"');
        $visiblethreads = " AND visible = 1";
        /*if (!can_moderate($forumid, 'canmoderateposts'))
            	{
            		if (!($forumperms & $vbulletin->bf_ugp_forumpermissions['canseedelnotice']))
            		{
            			$visiblethreads = " AND visible = 1 ";
            		}
            		else
            		{
            			$visiblethreads = " AND visible IN (1,2)";
            		}
            	}
            	else
            	{
            		$visiblethreads = " AND visible IN (0,1,2)";
        	}*/
        $hook_query_fields = $hook_query_joins = $hook_query_where = '';
        # Include visible IN (0,1,2) in order to hit upon the 4 column index
        $threadscount = $db->query_first_slave("\n    \t\tSELECT COUNT(*) AS threads, SUM(IF(thread.lastpost > {$lastread} AND open <> 10, 1, 0)) AS newthread\n    \t\t{$hook_query_fields}\n    \t\tFROM " . TABLE_PREFIX . "thread AS thread\n    \t\t{$tachyjoin}\n    \t\t{$hook_query_joins}\n    \t\tWHERE forumid = {$foruminfo['forumid']}\n    \t\t\tAND sticky = 0\n    \t\t\t{$prefix_filter}\n    \t\t\t{$visiblethreads}\n    \t\t\t{$globalignore}\n    \t\t\t{$limitothers}\n    \t\t\t{$datecut}\n    \t\t\t{$hook_query_where}\n    \t");
        $totalthreads = $threadscount['threads'];
        $newthreads = $threadscount['newthread'];
        // set defaults
        sanitize_pageresults($totalthreads, $pagenumber, $perpage, 200, $vbulletin->options['maxthreads']);
        // get number of sticky threads for the first page
        // on the first page there will be the sticky threads PLUS the $perpage other normal threads
        // not quite a bug, but a deliberate feature!
        if ($pagenumber == 1) {
            $stickies = $db->query_read_slave("\n    \t\t\tSELECT thread.threadid, lastpost, open\n    \t\t\tFROM " . TABLE_PREFIX . "thread AS thread\n    \t\t\tWHERE forumid = {$foruminfo['forumid']}\n    \t\t\t\tAND sticky = 1\n    \t\t\t\t{$prefix_filter}\n    \t\t\t\t{$visiblethreads}\n    \t\t\t\t{$limitothers}\n    \t\t\t\t{$globalignore}\n    \t\t");
            while ($thissticky = $db->fetch_array($stickies)) {
                $stickycount++;
                if ($thissticky['lastpost'] >= $lastread and $thissticky['open'] != 10) {
                    $newthreads++;
                }
                $stickyids .= ",{$thissticky['threadid']}";
            }
            $db->free_result($stickies);
            unset($thissticky, $stickies);
        }
        $limitlower = ($pagenumber - 1) * $perpage;
        $limitupper = $pagenumber * $perpage;
        if ($limitupper > $totalthreads) {
            $limitupper = $totalthreads;
            if ($limitlower > $totalthreads) {
                $limitlower = $totalthreads - $perpage - 1;
            }
        }
        if ($limitlower < 0) {
            $limitlower = 0;
        }
        if ($foruminfo['allowratings']) {
            $vbulletin->options['showvotes'] = intval($vbulletin->options['showvotes']);
            $votequery = "\n    \t\t\tIF(votenum >= " . $vbulletin->options['showvotes'] . ", votenum, 0) AS votenum,\n    \t\t\tIF(votenum >= " . $vbulletin->options['showvotes'] . " AND votenum > 0, votetotal / votenum, 0) AS voteavg,\n    \t\t";
        } else {
            $votequery = '';
        }
        if ($previewtype == 1) {
            $previewfield = "post.pagetext AS preview, post.username AS lastpost_username, post.userid AS lastpost_userid,";
            $previewjoin = "LEFT JOIN " . TABLE_PREFIX . "post AS post ON(post.postid = thread.firstpostid)";
        } else {
            $previewfield = "post.pagetext AS preview, post.username AS lastpost_username, post.userid AS lastpost_userid,";
            $previewjoin = "LEFT JOIN " . TABLE_PREFIX . "post AS post ON(post.postid = thread.lastpostid)";
        }
        if ($vbulletin->userinfo['userid'] and in_coventry($vbulletin->userinfo['userid'], true)) {
            $tachyjoin = "\n    \t\t\tLEFT JOIN " . TABLE_PREFIX . "tachythreadpost AS tachythreadpost ON\n    \t\t\t\t(tachythreadpost.threadid = thread.threadid AND tachythreadpost.userid = " . $vbulletin->userinfo['userid'] . ")\n    \t\t\tLEFT JOIN " . TABLE_PREFIX . "tachythreadcounter AS tachythreadcounter ON\n    \t\t\t\t(tachythreadcounter.threadid = thread.threadid AND tachythreadcounter.userid = " . $vbulletin->userinfo['userid'] . ")\n    \t\t";
            $tachy_columns = "\n    \t\t\tIF(tachythreadpost.userid IS NULL, thread.lastpost, tachythreadpost.lastpost) AS lastpost,\n    \t\t\tIF(tachythreadpost.userid IS NULL, thread.lastposter, tachythreadpost.lastposter) AS lastposter,\n    \t\t\tIF(tachythreadpost.userid IS NULL, thread.lastposterid, tachythreadpost.lastposterid) AS lastposterid,\n    \t\t\tIF(tachythreadpost.userid IS NULL, thread.lastpostid, tachythreadpost.lastpostid) AS lastpostid,\n    \t\t\tIF(tachythreadcounter.userid IS NULL, thread.replycount, thread.replycount + tachythreadcounter.replycount) AS replycount,\n    \t\t\tIF(thread.views<=IF(tachythreadcounter.userid IS NULL, thread.replycount, thread.replycount + tachythreadcounter.replycount), IF(tachythreadcounter.userid IS NULL, thread.replycount, thread.replycount + tachythreadcounter.replycount)+1, thread.views) AS views\n    \t\t";
        } else {
            $tachyjoin = '';
            $tachy_columns = 'thread.lastpost, thread.lastposter, thread.lastposterid, thread.lastpostid, thread.replycount, IF(thread.views<=thread.replycount, thread.replycount+1, thread.views) AS views';
        }
        $hook_query_fields = $hook_query_joins = $hook_query_where = '';
        $getthreadids = $db->query_read_slave("\n    \t\tSELECT " . iif($sortfield == 'voteavg', $votequery) . " thread.threadid,\n    \t\t\t{$tachy_columns}\n    \t\t\t{$hook_query_fields}\n    \t\tFROM " . TABLE_PREFIX . "thread AS thread\n    \t\t{$tachyjoin}\n    \t\t{$hook_query_joins}\n    \t\tWHERE forumid = {$foruminfo['forumid']}\n    \t\t\tAND sticky = 0\n    \t\t\t{$prefix_filter}\n    \t\t\t{$visiblethreads}\n    \t\t\t{$globalignore}\n    \t\t\t{$limitothers}\n    \t\t\t{$datecut}\n    \t\t\t{$hook_query_where}\n    \t\tORDER BY sticky DESC, {$sqlsortfield} {$sqlsortorder}" . (!empty($sqlsortfield2) ? ", {$sqlsortfield2} {$sqlsortorder}" : '') . "\n    \t\tLIMIT {$limitlower}, {$perpage}\n    \t");
        $ids = '';
        while ($thread = $db->fetch_array($getthreadids)) {
            $ids .= ',' . $thread['threadid'];
        }
        $ids .= $stickyids;
        $db->free_result($getthreadids);
        unset($thread, $getthreadids);
        $hook_query_fields = $hook_query_joins = $hook_query_where = '';
        $threads = $db->query_read_slave("\n    \t\tSELECT {$votequery} {$previewfield}\n    \t\t\tthread.threadid, thread.title AS threadtitle, thread.forumid, pollid, open, postusername, postuserid, thread.iconid AS threadiconid,\n    \t\t\tthread.dateline, notes, thread.visible, sticky, votetotal, thread.attach, {$tachy_columns},\n    \t\t\tthread.prefixid, thread.taglist, hiddencount, deletedcount,\n    \t\t\tuser.usergroupid, user.homepage, user.options AS useroptions, IF(userlist.friend = 'yes', 1, 0) AS isfriend\n    \t\t\t" . (($vbulletin->options['threadsubscribed'] and $vbulletin->userinfo['userid']) ? ", NOT ISNULL(subscribethread.subscribethreadid) AS issubscribed" : "") . "\n    \t\t\t" . ($deljoin ? ", deletionlog.userid AS del_userid, deletionlog.username AS del_username, deletionlog.reason AS del_reason" : "") . "\n    \t\t\t" . (($vbulletin->options['threadmarking'] and $vbulletin->userinfo['userid']) ? ", threadread.readtime AS threadread" : "") . "\n    \t\t\t" . ($redirectjoin ? ", threadredirect.expires" : "") . "\n    \t\t\t{$hook_query_fields}\n    \t\tFROM " . TABLE_PREFIX . "thread AS thread\n    \t\t\tLEFT JOIN " . TABLE_PREFIX . "user AS user ON (user.userid = thread.lastposterid)\n    \t\t\tLEFT JOIN " . TABLE_PREFIX . "userlist AS userlist ON (userlist.relationid = user.userid AND userlist.type = 'buddy' AND userlist.userid = " . $vbulletin->userinfo['userid'] . ")\n    \t\t\t{$deljoin}\n    \t\t\t" . (($vbulletin->options['threadsubscribed'] and $vbulletin->userinfo['userid']) ? " LEFT JOIN " . TABLE_PREFIX . "subscribethread AS subscribethread ON(subscribethread.threadid = thread.threadid AND subscribethread.userid = " . $vbulletin->userinfo['userid'] . " AND canview = 1)" : "") . "\n    \t\t\t" . (($vbulletin->options['threadmarking'] and $vbulletin->userinfo['userid']) ? " LEFT JOIN " . TABLE_PREFIX . "threadread AS threadread ON (threadread.threadid = thread.threadid AND threadread.userid = " . $vbulletin->userinfo['userid'] . ")" : "") . "\n    \t\t\t{$previewjoin}\n    \t\t\t{$tachyjoin}\n    \t\t\t{$redirectjoin}\n    \t\t\t{$hook_query_joins}\n    \t\tWHERE thread.threadid IN (0{$ids}) {$hook_query_where}\n    \t\tORDER BY sticky DESC, {$sqlsortfield} {$sqlsortorder}" . (!empty($sqlsortfield2) ? ", {$sqlsortfield2} {$sqlsortorder}" : '') . "\n    \t");
        unset($limitothers, $delthreadlimit, $deljoin, $datecut, $votequery, $sqlsortfield, $sqlsortorder, $threadids, $sqlsortfield2);
        // Get Dot Threads
        $dotthreads = fetch_dot_threads_array($ids);
        if ($vbulletin->options['showdots'] and $vbulletin->userinfo['userid']) {
            $show['dotthreads'] = true;
        } else {
            $show['dotthreads'] = false;
        }
        unset($ids);
        $pageinfo = array();
        if ($vbulletin->GPC['prefixid']) {
            $pageinfo['prefixid'] = $vbulletin->GPC['prefixid'];
        }
        if ($vbulletin->GPC['daysprune']) {
            $pageinfo['daysprune'] = $daysprune;
        }
        $show['fetchseo'] = true;
        $oppositesort = $vbulletin->GPC['sortorder'] == 'asc' ? 'desc' : 'asc';
        $pageinfo_voteavg = $pageinfo + array('sort' => 'voteavg', 'order' => 'voteavg' == $sortfield ? $oppositesort : 'desc');
        $pageinfo_title = $pageinfo + array('sort' => 'title', 'order' => 'title' == $sortfield ? $oppositesort : 'asc');
        $pageinfo_postusername = $pageinfo + array('sort' => 'postusername', 'order' => 'postusername' == $sortfield ? $oppositesort : 'asc');
        $pageinfo_flastpost = $pageinfo + array('sort' => 'lastpost', 'order' => 'lastpost' == $sortfield ? $oppositesort : 'asc');
        $pageinfo_replycount = $pageinfo + array('sort' => 'replycount', 'order' => 'replycount' == $sortfield ? $oppositesort : 'desc');
        $pageinfo_views = $pageinfo + array('sort' => 'views', 'order' => 'views' == $sortfield ? $oppositesort : 'desc');
        $pageinfo_sort = $pageinfo + array(sort => $sortfield, 'order' => $oppositesort, 'pp' => $perpage, 'page' => $pagenumber);
        if ($totalthreads > 0 or $stickyids) {
            if ($totalthreads > 0) {
                $limitlower++;
            }
            // check to see if there are any threads to display. If there are, do so, otherwise, show message
            if ($vbulletin->options['threadpreview'] > 0) {
                // Get Buddy List
                $buddy = array();
                if (trim($vbulletin->userinfo['buddylist'])) {
                    $buddylist = preg_split('/( )+/', trim($vbulletin->userinfo['buddylist']), -1, PREG_SPLIT_NO_EMPTY);
                    foreach ($buddylist as $buddyuserid) {
                        $buddy["{$buddyuserid}"] = 1;
                    }
                }
                DEVDEBUG('buddies: ' . implode(', ', array_keys($buddy)));
                // Get Ignore Users
                $ignore = array();
                if (trim($vbulletin->userinfo['ignorelist'])) {
                    $ignorelist = preg_split('/( )+/', trim($vbulletin->userinfo['ignorelist']), -1, PREG_SPLIT_NO_EMPTY);
                    foreach ($ignorelist as $ignoreuserid) {
                        if (!$buddy["{$ignoreuserid}"]) {
                            $ignore["{$ignoreuserid}"] = 1;
                        }
                    }
                }
                DEVDEBUG('ignored users: ' . implode(', ', array_keys($ignore)));
            }
            $show['threads'] = true;
            $threadbits = '';
            $threadbits_sticky = '';
            $counter = 0;
            $toread = 0;
            while ($thread = $db->fetch_array($threads)) {
                // AND $counter++ < $perpage)
                // build thread data
                $thread = process_thread_array($thread, $lastread, $foruminfo['allowicons']);
                $realthreadid = $thread['realthreadid'];
                if ($thread['sticky']) {
                    $threadbit =& $threadbits_sticky;
                } else {
                    $threadbit =& $threadbits;
                }
                // Soft Deleted Thread
                if ($thread['visible'] == 2) {
                    $thread['deletedcount']++;
                    $show['threadtitle'] = (can_moderate($forumid) or $vbulletin->userinfo['userid'] != 0 and $vbulletin->userinfo['userid'] == $thread['postuserid']) ? true : false;
                    $show['deletereason'] = !empty($thread['del_reason']) ? true : false;
                    $show['viewthread'] = can_moderate($forumid) ? true : false;
                    $show['managethread'] = (can_moderate($forumid, 'candeleteposts') or can_moderate($forumid, 'canremoveposts')) ? true : false;
                    $show['moderated'] = ($thread['hiddencount'] > 0 and can_moderate($forumid, 'canmoderateposts')) ? true : false;
                    $show['deletedthread'] = $canseedelnotice;
                } else {
                    if (!$thread['visible']) {
                        $thread['hiddencount']++;
                    }
                    $show['moderated'] = ($thread['hiddencount'] > 0 and can_moderate($forumid, 'canmoderateposts')) ? true : false;
                    $show['deletedthread'] = ($thread['deletedcount'] > 0 and $canseedelnotice) ? true : false;
                    $pageinfo_lastpage = array();
                    if ($show['pagenavmore']) {
                        $pageinfo_lastpage['page'] = $thread['totalpages'];
                    }
                    $pageinfo_newpost = array('goto' => 'newpost');
                    $pageinfo_lastpost = array('p' => $thread['lastpostid']);
                    // prepare the member action drop-down menu
                    $memberaction_dropdown = construct_memberaction_dropdown(fetch_lastposter_userinfo($thread));
                }
                // FRNR Start
                $avatarurl = '';
                if ($thread['lastpost_userid'] > 0) {
                    $userinfoavatar = fetch_userinfo($thread['lastpost_userid'], FETCH_USERINFO_AVATAR);
                    fetch_avatar_from_userinfo($userinfoavatar, true, false);
                    if ($userinfoavatar['avatarurl'] != '') {
                        $avatarurl = process_avatarurl($userinfoavatar['avatarurl']);
                    }
                    unset($userinfoavatar);
                }
                $tmp = array('thread_id' => $thread['threadid'], 'new_posts' => $show['gotonewpost'] ? 1 : 0, 'forum_id' => $thread['forumid'], 'total_posts' => $thread['totalposts'] ? $thread['totalposts'] : 0, 'thread_title' => prepare_utf8_string(strip_tags($thread['threadtitle'])), 'thread_preview' => prepare_utf8_string(preview_chop(html_entity_decode($thread['preview']), FR_PREVIEW_LEN)), 'post_userid' => $thread['lastpost_userid'], 'post_lastposttime' => prepare_utf8_string(date_trunc($thread['lastpostdate']) . ' ' . $thread['lastposttime']), 'post_username' => prepare_utf8_string(strip_tags($thread['lastpost_username'])));
                if ($avatarurl != '') {
                    $tmp['avatarurl'] = $avatarurl;
                }
                if ($thread['prefixid']) {
                    $tmp['prefix'] = prepare_utf8_string(strip_tags($vbphrase["prefix_{$thread['prefixid']}_title_plain"]));
                }
                if ($thread['attach']) {
                    $tmp['attach'] = true;
                }
                if ($thread['pollid']) {
                    $tmp['poll'] = true;
                }
                if ($thread['open'] == 10) {
                    // Special case for redirect threads
                    $tmp = array_merge($tmp, array('post_userid' => $thread['postuserid'], 'post_username' => prepare_utf8_string(strip_tags($thread['postusername'])), 'poll' => false));
                }
                if ($thread['sticky']) {
                    $thread_data_sticky[] = $tmp;
                } else {
                    $thread_data[] = $tmp;
                }
                // FRNR Stop
            }
            $db->free_result($threads);
            unset($thread, $counter);
            $pageinfo_pagenav = array();
            if (!empty($vbulletin->GPC['perpage'])) {
                $pageinfo_pagenav['pp'] = $perpage;
            }
            if (!empty($vbulletin->GPC['prefixid'])) {
                $pageinfo_pagenav['prefixid'] = $vbulletin->GPC['prefixid'];
            }
            if (!empty($vbulletin->GPC['sortfield'])) {
                $pageinfo_pagenav['sort'] = $sortfield;
            }
            if (!empty($vbulletin->GPC['sortorder'])) {
                $pageinfo_pagenav['order'] = $vbulletin->GPC['sortorder'];
            }
            if (!empty($vbulletin->GPC['daysprune'])) {
                $pageinfo_pagenav['daysprune'] = $daysprune;
            }
            $pagenav = construct_page_nav($pagenumber, $perpage, $totalthreads, 'forumdisplay.php?' . $vbulletin->session->vars['sessionurl'] . "f={$foruminfo['forumid']}", '', '', 'forum', $foruminfo, $pageinfo_pagenav);
        }
        unset($threads, $dotthreads);
        // get colspan for bottom bar
        $foruminfo['bottomcolspan'] = 5;
        if ($foruminfo['allowicons']) {
            $foruminfo['bottomcolspan']++;
        }
        if ($show['inlinemod']) {
            $foruminfo['bottomcolspan']++;
        }
        $show['threadslist'] = true;
        /////////////////////////////////
    } else {
        $show['threadslist'] = false;
        $canpost = false;
        // FRNR
    }
    /////////////////////////////////
    if (!$vbulletin->GPC['prefixid'] and $newthreads < 1 and $unreadchildforums < 1) {
        mark_forum_read($foruminfo, $vbulletin->userinfo['userid'], TIMENOW);
    }
    // FNRN Below
    $out = array();
    if (is_array($thread_data) && count($thread_data) > 0) {
        $out['threads'] = $thread_data;
    } else {
        $out['threads'] = array();
    }
    if (is_array($thread_data_sticky) && count($thread_data_sticky) > 0) {
        $out['threads_sticky'] = $thread_data_sticky;
        $out['total_sticky_threads'] = count($thread_data_sticky);
    } else {
        $out['threads_sticky'] = array();
        $out['total_sticky_threads'] = 0;
    }
    // Announcements become #1 on the threads
    if (is_array($announcements_out) && count($announcements_out) == 1) {
        array_unshift($out['threads'], $announcements_out[0]);
        $totalthreads++;
    }
    $out['total_threads'] = $totalthreads ? $totalthreads : 0;
    if ($forumbits) {
        $out['forums'] = $forumbits;
    } else {
        $out['forums'] = array();
    }
    $out['canpost'] = $canpost ? 1 : 0;
    $out['canattach'] = ($forumperms & $vbulletin->bf_ugp_forumpermissions['canpostattachment'] and $vbulletin->userinfo['userid']);
    // Get thread prefixes for this forum (if any)
    $prefix_out = array();
    if ($prefixsets = fetch_prefix_array($forumid)) {
        foreach ($prefixsets as $prefixsetid => $prefixes) {
            $optgroup_options = '';
            foreach ($prefixes as $prefixid => $prefix) {
                if ($permcheck and !can_use_prefix($prefixid, $prefix['restrictions'])) {
                    continue;
                }
                $optionvalue = $prefixid;
                $optiontitle = htmlspecialchars_uni($vbphrase["prefix_{$prefixid}_title_plain"]);
                $prefix_out[] = array('prefixid' => $prefixid, 'prefixcaption' => prepare_utf8_string($optiontitle));
            }
        }
    }
    if ($foruminfo['options'] & $vbulletin->bf_misc_forumoptions['prefixrequired']) {
        $out['prefixrequired'] = true;
    } else {
        $out['prefixrequired'] = false;
    }
    $out['prefixes'] = $prefix_out;
    return $out;
}
Example #13
0
function print_channels($parentid = 0, $indent = "\t")
{
    global $vbulletin, $imodcache, $accesscache, $vbphrase;
    // check to see if we need to do the queries
    if (!is_array($imodcache)) {
        require_once DIR . '/includes/functions_forumlist.php';
        cache_moderators();
    }
    if ($parentid === 0) {
        $channels = vB_Api::instanceInternal('search')->getChannels(false);
    } else {
        $channels = vB_Api::instanceInternal('search')->getChannels(true);
        if (empty($channels["{$parentid}"]) or empty($channels["{$parentid}"]['channels'])) {
            return;
        }
        $channels = $channels["{$parentid}"]['channels'];
    }
    // check to see if this channel actually exists / has children
    foreach ($channels as $nodeid => $node) {
        echo "{$indent}<ul class=\"lsq\">\n";
        // node title and links
        echo "{$indent}<li><b><a name=\"node{$nodeid}\" href=\"forum.php?" . vB::getCurrentSession()->get('sessionurl') . "do=edit&amp;n={$nodeid}\">{$node['htmltitle']}</a> <span class=\"smallfont\">(" . construct_link_code($vbphrase['reset'], "accessmask.php?" . vB::getCurrentSession()->get('sessionurl') . "do=resetchannel&amp;n={$nodeid}&amp;hash=" . CP_SESSIONHASH) . ")</span></b>";
        // get moderators
        if (is_array($imodcache["{$nodeid}"])) {
            echo "<span class=\"smallfont\"><br /> - <i>" . $vbphrase['moderators'] . ":";
            foreach ($imodcache["{$nodeid}"] as $moderator) {
                // moderator username and links
                echo " <a href=\"moderator.php?" . vB::getCurrentSession()->get('sessionurl') . "do=edit&amp;moderatorid={$moderator['moderatorid']}\">{$moderator['username']}</a>";
            }
            echo "</i></span>";
        }
        $allaccessmasks = 0;
        $forbidden = '';
        $permitted = '';
        $deny = $accesscache["{$nodeid}"]['0'];
        $permit = $accesscache["{$nodeid}"]['1'];
        /*echo "<pre>--$nodeid--\n";
        		print_r($accesscache["$nodeid"]);
        		echo '</pre>';*/
        if (is_array($deny)) {
            $forbidden = "{$indent}\t<li class=\"am-deny\"><b>" . construct_phrase($vbphrase['access_denied_x_users'], $deny['count']) . '</b>' . construct_link_code($vbphrase['display_users'], "accessmask.php?" . vB::getCurrentSession()->get('sessionurl') . "&do=edit&n={$nodeid}&accessmask={$deny['accessmask']}") . "</li>\n";
            $allaccessmasks = $deny['count'];
        }
        if (is_array($permit)) {
            $permitted = "{$indent}\t<li class=\"am-grant\"><b>" . construct_phrase($vbphrase['access_granted_x_users'], $permit['count']) . '</b>' . construct_link_code($vbphrase['display_users'], "accessmask.php?" . vB::getCurrentSession()->get('sessionurl') . "&do=edit&n={$nodeid}&accessmask={$permit['accessmask']}") . "</li>\n";
            $allaccessmasks = $allaccessmasks + $permit['count'];
        }
        if ($allaccessmasks > 0) {
            echo "{$indent}\t<ul class=\"usergroups\">\n";
            echo "{$indent}\t<li>" . construct_phrase($vbphrase['x_access_masks_set'], $allaccessmasks) . ' ' . construct_link_code('<b>' . $vbphrase['display_all_users'] . '</b>', "accessmask.php?" . vB::getCurrentSession()->get('sessionurl') . "&do=edit&n={$nodeid}&accessmask=2") . "</li>";
            echo $permitted;
            echo $forbidden;
            echo "{$indent}\t</ul><br />\n";
        } else {
            echo "{$indent}\t\n";
            echo "{$indent}\t<br />\n";
        }
        print_channels($nodeid, "{$indent}\t");
        echo "{$indent}</li>\n";
        echo "{$indent}</ul>\n";
        if ($node['parentid'] == 0) {
            echo "<hr size=\"1\" />\n";
        }
    }
}
    function main($id, $mode)
    {
        global $config, $db, $user, $auth, $template;
        global $phpbb_root_path, $phpbb_admin_path, $phpEx;
        // Show restore permissions notice
        if ($user->data['user_perm_from'] && $auth->acl_get('a_switchperm')) {
            $this->tpl_name = 'acp_main';
            $this->page_title = 'ACP_MAIN';
            $sql = 'SELECT user_id, username, user_colour
				FROM ' . USERS_TABLE . '
				WHERE user_id = ' . $user->data['user_perm_from'];
            $result = $db->sql_query($sql);
            $user_row = $db->sql_fetchrow($result);
            $db->sql_freeresult($result);
            $perm_from = '<strong' . ($user_row['user_colour'] ? ' style="color: #' . $user_row['user_colour'] . '">' : '>');
            $perm_from .= $user_row['user_id'] != ANONYMOUS ? '<a href="' . append_sid("{$phpbb_root_path}memberlist.{$phpEx}", 'mode=viewprofile&amp;u=' . $user_row['user_id']) . '">' : '';
            $perm_from .= $user_row['username'];
            $perm_from .= $user_row['user_id'] != ANONYMOUS ? '</a>' : '';
            $perm_from .= '</strong>';
            $template->assign_vars(array('S_RESTORE_PERMISSIONS' => true, 'U_RESTORE_PERMISSIONS' => append_sid("{$phpbb_root_path}ucp.{$phpEx}", 'mode=restore_perm'), 'PERM_FROM' => $perm_from, 'L_PERMISSIONS_TRANSFERRED_EXPLAIN' => sprintf($user->lang['PERMISSIONS_TRANSFERRED_EXPLAIN'], $perm_from, append_sid("{$phpbb_root_path}ucp.{$phpEx}", 'mode=restore_perm'))));
            return;
        }
        $action = request_var('action', '');
        if ($action) {
            if ($action === 'admlogout') {
                $user->unset_admin();
                $redirect_url = append_sid("{$phpbb_root_path}index.{$phpEx}");
                meta_refresh(3, $redirect_url);
                trigger_error($user->lang['ADM_LOGGED_OUT'] . '<br /><br />' . sprintf($user->lang['RETURN_INDEX'], '<a href="' . $redirect_url . '">', '</a>'));
            }
            if (!confirm_box(true)) {
                switch ($action) {
                    case 'online':
                        $confirm = true;
                        $confirm_lang = 'RESET_ONLINE_CONFIRM';
                        break;
                    case 'stats':
                        $confirm = true;
                        $confirm_lang = 'RESYNC_STATS_CONFIRM';
                        break;
                    case 'user':
                        $confirm = true;
                        $confirm_lang = 'RESYNC_POSTCOUNTS_CONFIRM';
                        break;
                    case 'date':
                        $confirm = true;
                        $confirm_lang = 'RESET_DATE_CONFIRM';
                        break;
                    case 'db_track':
                        $confirm = true;
                        $confirm_lang = 'RESYNC_POST_MARKING_CONFIRM';
                        break;
                    case 'purge_cache':
                        $confirm = true;
                        $confirm_lang = 'PURGE_CACHE_CONFIRM';
                        break;
                    default:
                        $confirm = true;
                        $confirm_lang = 'CONFIRM_OPERATION';
                }
                if ($confirm) {
                    confirm_box(false, $user->lang[$confirm_lang], build_hidden_fields(array('i' => $id, 'mode' => $mode, 'action' => $action)));
                }
            } else {
                switch ($action) {
                    case 'online':
                        if (!$auth->acl_get('a_board')) {
                            trigger_error($user->lang['NO_AUTH_OPERATION'] . adm_back_link($this->u_action), E_USER_WARNING);
                        }
                        set_config('record_online_users', 1, true);
                        set_config('record_online_date', time(), true);
                        add_log('admin', 'LOG_RESET_ONLINE');
                        break;
                    case 'stats':
                        if (!$auth->acl_get('a_board')) {
                            trigger_error($user->lang['NO_AUTH_OPERATION'] . adm_back_link($this->u_action), E_USER_WARNING);
                        }
                        $sql = 'SELECT COUNT(post_id) AS stat
							FROM ' . POSTS_TABLE . '
							WHERE post_approved = 1';
                        $result = $db->sql_query($sql);
                        set_config('num_posts', (int) $db->sql_fetchfield('stat'), true);
                        $db->sql_freeresult($result);
                        $sql = 'SELECT COUNT(topic_id) AS stat
							FROM ' . TOPICS_TABLE . '
							WHERE topic_approved = 1';
                        $result = $db->sql_query($sql);
                        set_config('num_topics', (int) $db->sql_fetchfield('stat'), true);
                        $db->sql_freeresult($result);
                        $sql = 'SELECT COUNT(user_id) AS stat
							FROM ' . USERS_TABLE . '
							WHERE user_type IN (' . USER_NORMAL . ',' . USER_FOUNDER . ')';
                        $result = $db->sql_query($sql);
                        set_config('num_users', (int) $db->sql_fetchfield('stat'), true);
                        $db->sql_freeresult($result);
                        $sql = 'SELECT COUNT(attach_id) as stat
							FROM ' . ATTACHMENTS_TABLE . '
							WHERE is_orphan = 0';
                        $result = $db->sql_query($sql);
                        set_config('num_files', (int) $db->sql_fetchfield('stat'), true);
                        $db->sql_freeresult($result);
                        $sql = 'SELECT SUM(filesize) as stat
							FROM ' . ATTACHMENTS_TABLE . '
							WHERE is_orphan = 0';
                        $result = $db->sql_query($sql);
                        set_config('upload_dir_size', (double) $db->sql_fetchfield('stat'), true);
                        $db->sql_freeresult($result);
                        if (!function_exists('update_last_username')) {
                            include $phpbb_root_path . "includes/functions_user.{$phpEx}";
                        }
                        update_last_username();
                        add_log('admin', 'LOG_RESYNC_STATS');
                        break;
                    case 'user':
                        if (!$auth->acl_get('a_board')) {
                            trigger_error($user->lang['NO_AUTH_OPERATION'] . adm_back_link($this->u_action), E_USER_WARNING);
                        }
                        // Resync post counts
                        $start = $max_post_id = 0;
                        // Find the maximum post ID, we can only stop the cycle when we've reached it
                        $sql = 'SELECT MAX(forum_last_post_id) as max_post_id
							FROM ' . FORUMS_TABLE;
                        $result = $db->sql_query($sql);
                        $max_post_id = (int) $db->sql_fetchfield('max_post_id');
                        $db->sql_freeresult($result);
                        // No maximum post id? :o
                        if (!$max_post_id) {
                            $sql = 'SELECT MAX(post_id)
								FROM ' . POSTS_TABLE;
                            $result = $db->sql_query($sql);
                            $max_post_id = (int) $db->sql_fetchfield('max_post_id');
                            $db->sql_freeresult($result);
                        }
                        // Still no maximum post id? Then we are finished
                        if (!$max_post_id) {
                            add_log('admin', 'LOG_RESYNC_POSTCOUNTS');
                            break;
                        }
                        $step = $config['num_posts'] ? max((int) ($config['num_posts'] / 5), 20000) : 20000;
                        $db->sql_query('UPDATE ' . USERS_TABLE . ' SET user_posts = 0');
                        while ($start < $max_post_id) {
                            $sql = 'SELECT COUNT(post_id) AS num_posts, poster_id
								FROM ' . POSTS_TABLE . '
								WHERE post_id BETWEEN ' . ($start + 1) . ' AND ' . ($start + $step) . '
									AND post_postcount = 1 AND post_approved = 1
								GROUP BY poster_id';
                            $result = $db->sql_query($sql);
                            if ($row = $db->sql_fetchrow($result)) {
                                do {
                                    $sql = 'UPDATE ' . USERS_TABLE . " SET user_posts = user_posts + {$row['num_posts']} WHERE user_id = {$row['poster_id']}";
                                    $db->sql_query($sql);
                                } while ($row = $db->sql_fetchrow($result));
                            }
                            $db->sql_freeresult($result);
                            $start += $step;
                        }
                        add_log('admin', 'LOG_RESYNC_POSTCOUNTS');
                        break;
                    case 'date':
                        if (!$auth->acl_get('a_board')) {
                            trigger_error($user->lang['NO_AUTH_OPERATION'] . adm_back_link($this->u_action), E_USER_WARNING);
                        }
                        set_config('board_startdate', time() - 1);
                        add_log('admin', 'LOG_RESET_DATE');
                        break;
                    case 'db_track':
                        switch ($db->sql_layer) {
                            case 'sqlite':
                            case 'firebird':
                                $db->sql_query('DELETE FROM ' . TOPICS_POSTED_TABLE);
                                break;
                            default:
                                $db->sql_query('TRUNCATE TABLE ' . TOPICS_POSTED_TABLE);
                                break;
                        }
                        // This can get really nasty... therefore we only do the last six months
                        $get_from_time = time() - 6 * 4 * 7 * 24 * 60 * 60;
                        // Select forum ids, do not include categories
                        $sql = 'SELECT forum_id
							FROM ' . FORUMS_TABLE . '
							WHERE forum_type <> ' . FORUM_CAT;
                        $result = $db->sql_query($sql);
                        $forum_ids = array();
                        while ($row = $db->sql_fetchrow($result)) {
                            $forum_ids[] = $row['forum_id'];
                        }
                        $db->sql_freeresult($result);
                        // Any global announcements? ;)
                        $forum_ids[] = 0;
                        // Now go through the forums and get us some topics...
                        foreach ($forum_ids as $forum_id) {
                            $sql = 'SELECT p.poster_id, p.topic_id
								FROM ' . POSTS_TABLE . ' p, ' . TOPICS_TABLE . ' t
								WHERE t.forum_id = ' . $forum_id . '
									AND t.topic_moved_id = 0
									AND t.topic_last_post_time > ' . $get_from_time . '
									AND t.topic_id = p.topic_id
									AND p.poster_id <> ' . ANONYMOUS . '
								GROUP BY p.poster_id, p.topic_id';
                            $result = $db->sql_query($sql);
                            $posted = array();
                            while ($row = $db->sql_fetchrow($result)) {
                                $posted[$row['poster_id']][] = $row['topic_id'];
                            }
                            $db->sql_freeresult($result);
                            $sql_ary = array();
                            foreach ($posted as $user_id => $topic_row) {
                                foreach ($topic_row as $topic_id) {
                                    $sql_ary[] = array('user_id' => (int) $user_id, 'topic_id' => (int) $topic_id, 'topic_posted' => 1);
                                }
                            }
                            unset($posted);
                            if (sizeof($sql_ary)) {
                                $db->sql_multi_insert(TOPICS_POSTED_TABLE, $sql_ary);
                            }
                        }
                        add_log('admin', 'LOG_RESYNC_POST_MARKING');
                        break;
                    case 'purge_cache':
                        if ((int) $user->data['user_type'] !== USER_FOUNDER) {
                            trigger_error($user->lang['NO_AUTH_OPERATION'] . adm_back_link($this->u_action), E_USER_WARNING);
                        }
                        global $cache;
                        $cache->purge();
                        // Clear permissions
                        $auth->acl_clear_prefetch();
                        cache_moderators();
                        add_log('admin', 'LOG_PURGE_CACHE');
                        break;
                }
            }
        }
        // Get forum statistics
        $total_posts = $config['num_posts'];
        $total_topics = $config['num_topics'];
        $total_users = $config['num_users'];
        $total_files = $config['num_files'];
        $start_date = $user->format_date($config['board_startdate']);
        $boarddays = (time() - $config['board_startdate']) / 86400;
        $posts_per_day = sprintf('%.2f', $total_posts / $boarddays);
        $topics_per_day = sprintf('%.2f', $total_topics / $boarddays);
        $users_per_day = sprintf('%.2f', $total_users / $boarddays);
        $files_per_day = sprintf('%.2f', $total_files / $boarddays);
        $upload_dir_size = get_formatted_filesize($config['upload_dir_size']);
        $avatar_dir_size = 0;
        if ($avatar_dir = @opendir($phpbb_root_path . $config['avatar_path'])) {
            while (($file = readdir($avatar_dir)) !== false) {
                if ($file[0] != '.' && $file != 'CVS' && strpos($file, 'index.') === false) {
                    $avatar_dir_size += filesize($phpbb_root_path . $config['avatar_path'] . '/' . $file);
                }
            }
            closedir($avatar_dir);
            $avatar_dir_size = get_formatted_filesize($avatar_dir_size);
        } else {
            // Couldn't open Avatar dir.
            $avatar_dir_size = $user->lang['NOT_AVAILABLE'];
        }
        if ($posts_per_day > $total_posts) {
            $posts_per_day = $total_posts;
        }
        if ($topics_per_day > $total_topics) {
            $topics_per_day = $total_topics;
        }
        if ($users_per_day > $total_users) {
            $users_per_day = $total_users;
        }
        if ($files_per_day > $total_files) {
            $files_per_day = $total_files;
        }
        if ($config['allow_attachments'] || $config['allow_pm_attach']) {
            $sql = 'SELECT COUNT(attach_id) AS total_orphan
				FROM ' . ATTACHMENTS_TABLE . '
				WHERE is_orphan = 1
					AND filetime < ' . (time() - 3 * 60 * 60);
            $result = $db->sql_query($sql);
            $total_orphan = (int) $db->sql_fetchfield('total_orphan');
            $db->sql_freeresult($result);
        } else {
            $total_orphan = false;
        }
        $dbsize = get_database_size();
        $template->assign_vars(array('TOTAL_POSTS' => $total_posts, 'POSTS_PER_DAY' => $posts_per_day, 'TOTAL_TOPICS' => $total_topics, 'TOPICS_PER_DAY' => $topics_per_day, 'TOTAL_USERS' => $total_users, 'USERS_PER_DAY' => $users_per_day, 'TOTAL_FILES' => $total_files, 'FILES_PER_DAY' => $files_per_day, 'START_DATE' => $start_date, 'AVATAR_DIR_SIZE' => $avatar_dir_size, 'DBSIZE' => $dbsize, 'UPLOAD_DIR_SIZE' => $upload_dir_size, 'TOTAL_ORPHAN' => $total_orphan, 'S_TOTAL_ORPHAN' => $total_orphan === false ? false : true, 'GZIP_COMPRESSION' => $config['gzip_compress'] ? $user->lang['ON'] : $user->lang['OFF'], 'DATABASE_INFO' => $db->sql_server_info(), 'BOARD_VERSION' => $config['version'], 'U_ACTION' => $this->u_action, 'U_ADMIN_LOG' => append_sid("{$phpbb_admin_path}index.{$phpEx}", 'i=logs&amp;mode=admin'), 'U_INACTIVE_USERS' => append_sid("{$phpbb_admin_path}index.{$phpEx}", 'i=inactive&amp;mode=list'), 'S_ACTION_OPTIONS' => $auth->acl_get('a_board') ? true : false, 'S_FOUNDER' => $user->data['user_type'] == USER_FOUNDER ? true : false));
        $log_data = array();
        $log_count = 0;
        if ($auth->acl_get('a_viewlogs')) {
            view_log('admin', $log_data, $log_count, 5);
            foreach ($log_data as $row) {
                $template->assign_block_vars('log', array('USERNAME' => $row['username_full'], 'IP' => $row['ip'], 'DATE' => $user->format_date($row['time']), 'ACTION' => $row['action']));
            }
        }
        if ($auth->acl_get('a_user')) {
            $inactive = array();
            $inactive_count = 0;
            view_inactive_users($inactive, $inactive_count, 10);
            foreach ($inactive as $row) {
                $template->assign_block_vars('inactive', array('INACTIVE_DATE' => $user->format_date($row['user_inactive_time']), 'JOINED' => $user->format_date($row['user_regdate']), 'LAST_VISIT' => !$row['user_lastvisit'] ? ' - ' : $user->format_date($row['user_lastvisit']), 'REASON' => $row['inactive_reason'], 'USER_ID' => $row['user_id'], 'USERNAME' => $row['username'], 'U_USER_ADMIN' => append_sid("{$phpbb_admin_path}index.{$phpEx}", "i=users&amp;mode=overview&amp;u={$row['user_id']}")));
            }
            $option_ary = array('activate' => 'ACTIVATE', 'delete' => 'DELETE');
            if ($config['email_enable']) {
                $option_ary += array('remind' => 'REMIND');
            }
            $template->assign_vars(array('S_INACTIVE_USERS' => true, 'S_INACTIVE_OPTIONS' => build_select($option_ary)));
        }
        // Warn if install is still present
        if (file_exists($phpbb_root_path . 'install')) {
            $template->assign_var('S_REMOVE_INSTALL', true);
        }
        if (!defined('PHPBB_DISABLE_CONFIG_CHECK') && file_exists($phpbb_root_path . 'config.' . $phpEx) && is_writable($phpbb_root_path . 'config.' . $phpEx)) {
            // World-Writable? (000x)
            $template->assign_var('S_WRITABLE_CONFIG', (bool) (@fileperms($phpbb_root_path . 'config.' . $phpEx) & 0x2));
        }
        $this->tpl_name = 'acp_main';
        $this->page_title = 'ACP_MAIN';
    }
Example #15
0
    function main($id, $mode)
    {
        global $db, $user, $auth, $template, $cache;
        global $config, $phpbb_admin_path, $phpbb_root_path, $phpEx;
        $user->add_lang('acp/forums');
        $this->tpl_name = 'acp_forums';
        $this->page_title = 'ACP_MANAGE_FORUMS';
        $form_key = 'acp_forums';
        add_form_key($form_key);
        $action = request_var('action', '');
        $update = isset($_POST['update']) ? true : false;
        $forum_id = request_var('f', 0);
        $this->parent_id = request_var('parent_id', 0);
        $forum_data = $errors = array();
        if ($update && !check_form_key($form_key)) {
            $update = false;
            $errors[] = $user->lang['FORM_INVALID'];
        }
        // Check additional permissions
        switch ($action) {
            case 'progress_bar':
                $start = request_var('start', 0);
                $total = request_var('total', 0);
                $this->display_progress_bar($start, $total);
                break;
            case 'delete':
                if (!$auth->acl_get('a_forumdel')) {
                    trigger_error($user->lang['NO_PERMISSION_FORUM_DELETE'] . adm_back_link($this->u_action . '&amp;parent_id=' . $this->parent_id), E_USER_WARNING);
                }
                break;
            case 'add':
                if (!$auth->acl_get('a_forumadd')) {
                    trigger_error($user->lang['NO_PERMISSION_FORUM_ADD'] . adm_back_link($this->u_action . '&amp;parent_id=' . $this->parent_id), E_USER_WARNING);
                }
                break;
        }
        // Major routines
        if ($update) {
            switch ($action) {
                case 'delete':
                    $action_subforums = request_var('action_subforums', '');
                    $subforums_to_id = request_var('subforums_to_id', 0);
                    $action_posts = request_var('action_posts', '');
                    $posts_to_id = request_var('posts_to_id', 0);
                    $errors = $this->delete_forum($forum_id, $action_posts, $action_subforums, $posts_to_id, $subforums_to_id);
                    if (sizeof($errors)) {
                        break;
                    }
                    $auth->acl_clear_prefetch();
                    $cache->destroy('sql', FORUMS_TABLE);
                    trigger_error($user->lang['FORUM_DELETED'] . adm_back_link($this->u_action . '&amp;parent_id=' . $this->parent_id));
                    break;
                case 'edit':
                    $forum_data = array('forum_id' => $forum_id);
                    // No break here
                // No break here
                case 'add':
                    $forum_data += array('parent_id' => request_var('forum_parent_id', $this->parent_id), 'forum_type' => request_var('forum_type', FORUM_POST), 'type_action' => request_var('type_action', ''), 'forum_status' => request_var('forum_status', ITEM_UNLOCKED), 'forum_parents' => '', 'forum_name' => utf8_normalize_nfc(request_var('forum_name', '', true)), 'forum_link' => request_var('forum_link', ''), 'forum_link_track' => request_var('forum_link_track', false), 'forum_desc' => utf8_normalize_nfc(request_var('forum_desc', '', true)), 'forum_desc_uid' => '', 'forum_desc_options' => 7, 'forum_desc_bitfield' => '', 'forum_rules' => utf8_normalize_nfc(request_var('forum_rules', '', true)), 'forum_rules_uid' => '', 'forum_rules_options' => 7, 'forum_rules_bitfield' => '', 'forum_rules_link' => request_var('forum_rules_link', ''), 'forum_image' => request_var('forum_image', ''), 'forum_style' => request_var('forum_style', 0), 'display_subforum_list' => request_var('display_subforum_list', false), 'display_on_index' => request_var('display_on_index', false), 'forum_topics_per_page' => request_var('topics_per_page', 0), 'enable_indexing' => request_var('enable_indexing', true), 'enable_icons' => request_var('enable_icons', false), 'enable_prune' => request_var('enable_prune', false), 'enable_post_review' => request_var('enable_post_review', true), 'enable_quick_reply' => request_var('enable_quick_reply', false), 'prune_days' => request_var('prune_days', 7), 'prune_viewed' => request_var('prune_viewed', 7), 'prune_freq' => request_var('prune_freq', 1), 'prune_old_polls' => request_var('prune_old_polls', false), 'prune_announce' => request_var('prune_announce', false), 'prune_sticky' => request_var('prune_sticky', false), 'forum_password' => request_var('forum_password', '', true), 'forum_password_confirm' => request_var('forum_password_confirm', '', true), 'forum_password_unset' => request_var('forum_password_unset', false));
                    // On add, add empty forum_options... else do not consider it (not updating it)
                    if ($action == 'add') {
                        $forum_data['forum_options'] = 0;
                    }
                    // Use link_display_on_index setting if forum type is link
                    if ($forum_data['forum_type'] == FORUM_LINK) {
                        $forum_data['display_on_index'] = request_var('link_display_on_index', false);
                    }
                    // Linked forums and categories are not able to be locked...
                    if ($forum_data['forum_type'] == FORUM_LINK || $forum_data['forum_type'] == FORUM_CAT) {
                        $forum_data['forum_status'] = ITEM_UNLOCKED;
                    }
                    $forum_data['show_active'] = $forum_data['forum_type'] == FORUM_POST ? request_var('display_recent', true) : request_var('display_active', false);
                    // Get data for forum rules if specified...
                    if ($forum_data['forum_rules']) {
                        generate_text_for_storage($forum_data['forum_rules'], $forum_data['forum_rules_uid'], $forum_data['forum_rules_bitfield'], $forum_data['forum_rules_options'], request_var('rules_parse_bbcode', false), request_var('rules_parse_urls', false), request_var('rules_parse_smilies', false));
                    }
                    // Get data for forum description if specified
                    if ($forum_data['forum_desc']) {
                        generate_text_for_storage($forum_data['forum_desc'], $forum_data['forum_desc_uid'], $forum_data['forum_desc_bitfield'], $forum_data['forum_desc_options'], request_var('desc_parse_bbcode', false), request_var('desc_parse_urls', false), request_var('desc_parse_smilies', false));
                    }
                    $errors = $this->update_forum_data($forum_data);
                    if (!sizeof($errors)) {
                        $forum_perm_from = request_var('forum_perm_from', 0);
                        $cache->destroy('sql', FORUMS_TABLE);
                        $copied_permissions = false;
                        // Copy permissions?
                        if ($forum_perm_from && $forum_perm_from != $forum_data['forum_id'] && ($action != 'edit' || empty($forum_id) || $auth->acl_get('a_fauth') && $auth->acl_get('a_authusers') && $auth->acl_get('a_authgroups') && $auth->acl_get('a_mauth'))) {
                            copy_forum_permissions($forum_perm_from, $forum_data['forum_id'], $action == 'edit' ? true : false);
                            cache_moderators();
                            $copied_permissions = true;
                        }
                        /* Commented out because of questionable UI workflow - re-visit for 3.0.7
                        						else if (!$this->parent_id && $action != 'edit' && $auth->acl_get('a_fauth') && $auth->acl_get('a_authusers') && $auth->acl_get('a_authgroups') && $auth->acl_get('a_mauth'))
                        						{
                        							$this->copy_permission_page($forum_data);
                        							return;
                        						}
                        */
                        $auth->acl_clear_prefetch();
                        $acl_url = '&amp;mode=setting_forum_local&amp;forum_id[]=' . $forum_data['forum_id'];
                        $message = $action == 'add' ? $user->lang['FORUM_CREATED'] : $user->lang['FORUM_UPDATED'];
                        // redirect directly to permission settings screen if authed
                        if ($action == 'add' && !$copied_permissions && $auth->acl_get('a_fauth')) {
                            $message .= '<br /><br />' . sprintf($user->lang['REDIRECT_ACL'], '<a href="' . append_sid("{$phpbb_admin_path}index.{$phpEx}", 'i=permissions' . $acl_url) . '">', '</a>');
                            meta_refresh(4, append_sid("{$phpbb_admin_path}index.{$phpEx}", 'i=permissions' . $acl_url));
                        }
                        trigger_error($message . adm_back_link($this->u_action . '&amp;parent_id=' . $this->parent_id));
                    }
                    break;
            }
        }
        switch ($action) {
            case 'move_up':
            case 'move_down':
                if (!$forum_id) {
                    trigger_error($user->lang['NO_FORUM'] . adm_back_link($this->u_action . '&amp;parent_id=' . $this->parent_id), E_USER_WARNING);
                }
                $sql = 'SELECT *
					FROM ' . FORUMS_TABLE . "\n\t\t\t\t\tWHERE forum_id = {$forum_id}";
                $result = $db->sql_query($sql);
                $row = $db->sql_fetchrow($result);
                $db->sql_freeresult($result);
                if (!$row) {
                    trigger_error($user->lang['NO_FORUM'] . adm_back_link($this->u_action . '&amp;parent_id=' . $this->parent_id), E_USER_WARNING);
                }
                $move_forum_name = $this->move_forum_by($row, $action, 1);
                if ($move_forum_name !== false) {
                    add_log('admin', 'LOG_FORUM_' . strtoupper($action), $row['forum_name'], $move_forum_name);
                    $cache->destroy('sql', FORUMS_TABLE);
                }
                break;
            case 'sync':
                if (!$forum_id) {
                    trigger_error($user->lang['NO_FORUM'] . adm_back_link($this->u_action . '&amp;parent_id=' . $this->parent_id), E_USER_WARNING);
                }
                @set_time_limit(0);
                $sql = 'SELECT forum_name, forum_topics_real
					FROM ' . FORUMS_TABLE . "\n\t\t\t\t\tWHERE forum_id = {$forum_id}";
                $result = $db->sql_query($sql);
                $row = $db->sql_fetchrow($result);
                $db->sql_freeresult($result);
                if (!$row) {
                    trigger_error($user->lang['NO_FORUM'] . adm_back_link($this->u_action . '&amp;parent_id=' . $this->parent_id), E_USER_WARNING);
                }
                if ($row['forum_topics_real']) {
                    $sql = 'SELECT MIN(topic_id) as min_topic_id, MAX(topic_id) as max_topic_id
						FROM ' . TOPICS_TABLE . '
						WHERE forum_id = ' . $forum_id;
                    $result = $db->sql_query($sql);
                    $row2 = $db->sql_fetchrow($result);
                    $db->sql_freeresult($result);
                    // Typecast to int if there is no data available
                    $row2['min_topic_id'] = (int) $row2['min_topic_id'];
                    $row2['max_topic_id'] = (int) $row2['max_topic_id'];
                    $start = request_var('start', $row2['min_topic_id']);
                    $batch_size = 2000;
                    $end = $start + $batch_size;
                    // Sync all topics in batch mode...
                    sync('topic_approved', 'range', 'topic_id BETWEEN ' . $start . ' AND ' . $end, true, false);
                    sync('topic', 'range', 'topic_id BETWEEN ' . $start . ' AND ' . $end, true, true);
                    if ($end < $row2['max_topic_id']) {
                        // We really need to find a way of showing statistics... no progress here
                        $sql = 'SELECT COUNT(topic_id) as num_topics
							FROM ' . TOPICS_TABLE . '
							WHERE forum_id = ' . $forum_id . '
								AND topic_id BETWEEN ' . $start . ' AND ' . $end;
                        $result = $db->sql_query($sql);
                        $topics_done = request_var('topics_done', 0) + (int) $db->sql_fetchfield('num_topics');
                        $db->sql_freeresult($result);
                        $start += $batch_size;
                        $url = $this->u_action . "&amp;parent_id={$this->parent_id}&amp;f={$forum_id}&amp;action=sync&amp;start={$start}&amp;topics_done={$topics_done}&amp;total={$row['forum_topics_real']}";
                        meta_refresh(0, $url);
                        $template->assign_vars(array('U_PROGRESS_BAR' => $this->u_action . "&amp;action=progress_bar&amp;start={$topics_done}&amp;total={$row['forum_topics_real']}", 'UA_PROGRESS_BAR' => addslashes($this->u_action . "&amp;action=progress_bar&amp;start={$topics_done}&amp;total={$row['forum_topics_real']}"), 'S_CONTINUE_SYNC' => true, 'L_PROGRESS_EXPLAIN' => sprintf($user->lang['SYNC_IN_PROGRESS_EXPLAIN'], $topics_done, $row['forum_topics_real'])));
                        return;
                    }
                }
                $url = $this->u_action . "&amp;parent_id={$this->parent_id}&amp;f={$forum_id}&amp;action=sync_forum";
                meta_refresh(0, $url);
                $template->assign_vars(array('U_PROGRESS_BAR' => $this->u_action . '&amp;action=progress_bar', 'UA_PROGRESS_BAR' => addslashes($this->u_action . '&amp;action=progress_bar'), 'S_CONTINUE_SYNC' => true, 'L_PROGRESS_EXPLAIN' => sprintf($user->lang['SYNC_IN_PROGRESS_EXPLAIN'], 0, $row['forum_topics_real'])));
                return;
                break;
            case 'sync_forum':
                $sql = 'SELECT forum_name, forum_type
					FROM ' . FORUMS_TABLE . "\n\t\t\t\t\tWHERE forum_id = {$forum_id}";
                $result = $db->sql_query($sql);
                $row = $db->sql_fetchrow($result);
                $db->sql_freeresult($result);
                if (!$row) {
                    trigger_error($user->lang['NO_FORUM'] . adm_back_link($this->u_action . '&amp;parent_id=' . $this->parent_id), E_USER_WARNING);
                }
                sync('forum', 'forum_id', $forum_id, false, true);
                add_log('admin', 'LOG_FORUM_SYNC', $row['forum_name']);
                $cache->destroy('sql', FORUMS_TABLE);
                $template->assign_var('L_FORUM_RESYNCED', sprintf($user->lang['FORUM_RESYNCED'], $row['forum_name']));
                break;
            case 'add':
            case 'edit':
                if ($update) {
                    $forum_data['forum_flags'] = 0;
                    $forum_data['forum_flags'] += request_var('forum_link_track', false) ? FORUM_FLAG_LINK_TRACK : 0;
                    $forum_data['forum_flags'] += request_var('prune_old_polls', false) ? FORUM_FLAG_PRUNE_POLL : 0;
                    $forum_data['forum_flags'] += request_var('prune_announce', false) ? FORUM_FLAG_PRUNE_ANNOUNCE : 0;
                    $forum_data['forum_flags'] += request_var('prune_sticky', false) ? FORUM_FLAG_PRUNE_STICKY : 0;
                    $forum_data['forum_flags'] += $forum_data['show_active'] ? FORUM_FLAG_ACTIVE_TOPICS : 0;
                    $forum_data['forum_flags'] += request_var('enable_post_review', true) ? FORUM_FLAG_POST_REVIEW : 0;
                    $forum_data['forum_flags'] += request_var('enable_quick_reply', false) ? FORUM_FLAG_QUICK_REPLY : 0;
                }
                // Show form to create/modify a forum
                if ($action == 'edit') {
                    $this->page_title = 'EDIT_FORUM';
                    $row = $this->get_forum_info($forum_id);
                    $old_forum_type = $row['forum_type'];
                    if (!$update) {
                        $forum_data = $row;
                    } else {
                        $forum_data['left_id'] = $row['left_id'];
                        $forum_data['right_id'] = $row['right_id'];
                    }
                    // Make sure no direct child forums are able to be selected as parents.
                    $exclude_forums = array();
                    foreach (get_forum_branch($forum_id, 'children') as $row) {
                        $exclude_forums[] = $row['forum_id'];
                    }
                    $parents_list = make_forum_select($forum_data['parent_id'], $exclude_forums, false, false, false);
                    $forum_data['forum_password_confirm'] = $forum_data['forum_password'];
                } else {
                    $this->page_title = 'CREATE_FORUM';
                    $forum_id = $this->parent_id;
                    $parents_list = make_forum_select($this->parent_id, false, false, false, false);
                    // Fill forum data with default values
                    if (!$update) {
                        $forum_data = array('parent_id' => $this->parent_id, 'forum_type' => FORUM_POST, 'forum_status' => ITEM_UNLOCKED, 'forum_name' => utf8_normalize_nfc(request_var('forum_name', '', true)), 'forum_link' => '', 'forum_link_track' => false, 'forum_desc' => '', 'forum_rules' => '', 'forum_rules_link' => '', 'forum_image' => '', 'forum_style' => 0, 'display_subforum_list' => true, 'display_on_index' => false, 'forum_topics_per_page' => 0, 'enable_indexing' => true, 'enable_icons' => false, 'enable_prune' => false, 'prune_days' => 7, 'prune_viewed' => 7, 'prune_freq' => 1, 'forum_flags' => FORUM_FLAG_POST_REVIEW + FORUM_FLAG_ACTIVE_TOPICS, 'forum_options' => 0, 'forum_password' => '', 'forum_password_confirm' => '');
                    }
                }
                $forum_rules_data = array('text' => $forum_data['forum_rules'], 'allow_bbcode' => true, 'allow_smilies' => true, 'allow_urls' => true);
                $forum_desc_data = array('text' => $forum_data['forum_desc'], 'allow_bbcode' => true, 'allow_smilies' => true, 'allow_urls' => true);
                $forum_rules_preview = '';
                // Parse rules if specified
                if ($forum_data['forum_rules']) {
                    if (!isset($forum_data['forum_rules_uid'])) {
                        // Before we are able to display the preview and plane text, we need to parse our request_var()'d value...
                        $forum_data['forum_rules_uid'] = '';
                        $forum_data['forum_rules_bitfield'] = '';
                        $forum_data['forum_rules_options'] = 0;
                        generate_text_for_storage($forum_data['forum_rules'], $forum_data['forum_rules_uid'], $forum_data['forum_rules_bitfield'], $forum_data['forum_rules_options'], request_var('rules_allow_bbcode', false), request_var('rules_allow_urls', false), request_var('rules_allow_smilies', false));
                    }
                    // Generate preview content
                    $forum_rules_preview = generate_text_for_display($forum_data['forum_rules'], $forum_data['forum_rules_uid'], $forum_data['forum_rules_bitfield'], $forum_data['forum_rules_options']);
                    // decode...
                    $forum_rules_data = generate_text_for_edit($forum_data['forum_rules'], $forum_data['forum_rules_uid'], $forum_data['forum_rules_options']);
                }
                // Parse desciption if specified
                if ($forum_data['forum_desc']) {
                    if (!isset($forum_data['forum_desc_uid'])) {
                        // Before we are able to display the preview and plane text, we need to parse our request_var()'d value...
                        $forum_data['forum_desc_uid'] = '';
                        $forum_data['forum_desc_bitfield'] = '';
                        $forum_data['forum_desc_options'] = 0;
                        generate_text_for_storage($forum_data['forum_desc'], $forum_data['forum_desc_uid'], $forum_data['forum_desc_bitfield'], $forum_data['forum_desc_options'], request_var('desc_allow_bbcode', false), request_var('desc_allow_urls', false), request_var('desc_allow_smilies', false));
                    }
                    // decode...
                    $forum_desc_data = generate_text_for_edit($forum_data['forum_desc'], $forum_data['forum_desc_uid'], $forum_data['forum_desc_options']);
                }
                $forum_type_options = '';
                $forum_type_ary = array(FORUM_CAT => 'CAT', FORUM_POST => 'FORUM', FORUM_LINK => 'LINK');
                foreach ($forum_type_ary as $value => $lang) {
                    $forum_type_options .= '<option value="' . $value . '"' . ($value == $forum_data['forum_type'] ? ' selected="selected"' : '') . '>' . $user->lang['TYPE_' . $lang] . '</option>';
                }
                $styles_list = style_select($forum_data['forum_style'], true);
                $statuslist = '<option value="' . ITEM_UNLOCKED . '"' . ($forum_data['forum_status'] == ITEM_UNLOCKED ? ' selected="selected"' : '') . '>' . $user->lang['UNLOCKED'] . '</option><option value="' . ITEM_LOCKED . '"' . ($forum_data['forum_status'] == ITEM_LOCKED ? ' selected="selected"' : '') . '>' . $user->lang['LOCKED'] . '</option>';
                $sql = 'SELECT forum_id
					FROM ' . FORUMS_TABLE . '
					WHERE forum_type = ' . FORUM_POST . "\n\t\t\t\t\t\tAND forum_id <> {$forum_id}";
                $result = $db->sql_query_limit($sql, 1);
                $postable_forum_exists = false;
                if ($db->sql_fetchrow($result)) {
                    $postable_forum_exists = true;
                }
                $db->sql_freeresult($result);
                // Subforum move options
                if ($action == 'edit' && $forum_data['forum_type'] == FORUM_CAT) {
                    $subforums_id = array();
                    $subforums = get_forum_branch($forum_id, 'children');
                    foreach ($subforums as $row) {
                        $subforums_id[] = $row['forum_id'];
                    }
                    $forums_list = make_forum_select($forum_data['parent_id'], $subforums_id);
                    if ($postable_forum_exists) {
                        $template->assign_vars(array('S_MOVE_FORUM_OPTIONS' => make_forum_select($forum_data['parent_id'], $subforums_id)));
                    }
                    $template->assign_vars(array('S_HAS_SUBFORUMS' => $forum_data['right_id'] - $forum_data['left_id'] > 1 ? true : false, 'S_FORUMS_LIST' => $forums_list));
                } else {
                    if ($postable_forum_exists) {
                        $template->assign_vars(array('S_MOVE_FORUM_OPTIONS' => make_forum_select($forum_data['parent_id'], $forum_id, false, true, false)));
                    }
                }
                $s_show_display_on_index = false;
                if ($forum_data['parent_id'] > 0) {
                    // if this forum is a subforum put the "display on index" checkbox
                    if ($parent_info = $this->get_forum_info($forum_data['parent_id'])) {
                        if ($parent_info['parent_id'] > 0 || $parent_info['forum_type'] == FORUM_CAT) {
                            $s_show_display_on_index = true;
                        }
                    }
                }
                if (strlen($forum_data['forum_password']) == 32) {
                    $errors[] = $user->lang['FORUM_PASSWORD_OLD'];
                }
                $template->assign_vars(array('S_EDIT_FORUM' => true, 'S_ERROR' => sizeof($errors) ? true : false, 'S_PARENT_ID' => $this->parent_id, 'S_FORUM_PARENT_ID' => $forum_data['parent_id'], 'S_ADD_ACTION' => $action == 'add' ? true : false, 'U_BACK' => $this->u_action . '&amp;parent_id=' . $this->parent_id, 'U_EDIT_ACTION' => $this->u_action . "&amp;parent_id={$this->parent_id}&amp;action={$action}&amp;f={$forum_id}", 'L_COPY_PERMISSIONS_EXPLAIN' => $user->lang['COPY_PERMISSIONS_' . strtoupper($action) . '_EXPLAIN'], 'L_TITLE' => $user->lang[$this->page_title], 'ERROR_MSG' => sizeof($errors) ? implode('<br />', $errors) : '', 'FORUM_NAME' => $forum_data['forum_name'], 'FORUM_DATA_LINK' => $forum_data['forum_link'], 'FORUM_IMAGE' => $forum_data['forum_image'], 'FORUM_IMAGE_SRC' => $forum_data['forum_image'] ? $phpbb_root_path . $forum_data['forum_image'] : '', 'FORUM_POST' => FORUM_POST, 'FORUM_LINK' => FORUM_LINK, 'FORUM_CAT' => FORUM_CAT, 'PRUNE_FREQ' => $forum_data['prune_freq'], 'PRUNE_DAYS' => $forum_data['prune_days'], 'PRUNE_VIEWED' => $forum_data['prune_viewed'], 'TOPICS_PER_PAGE' => $forum_data['forum_topics_per_page'], 'FORUM_RULES_LINK' => $forum_data['forum_rules_link'], 'FORUM_RULES' => $forum_data['forum_rules'], 'FORUM_RULES_PREVIEW' => $forum_rules_preview, 'FORUM_RULES_PLAIN' => $forum_rules_data['text'], 'S_BBCODE_CHECKED' => $forum_rules_data['allow_bbcode'] ? true : false, 'S_SMILIES_CHECKED' => $forum_rules_data['allow_smilies'] ? true : false, 'S_URLS_CHECKED' => $forum_rules_data['allow_urls'] ? true : false, 'S_FORUM_PASSWORD_SET' => empty($forum_data['forum_password']) ? false : true, 'FORUM_DESC' => $forum_desc_data['text'], 'S_DESC_BBCODE_CHECKED' => $forum_desc_data['allow_bbcode'] ? true : false, 'S_DESC_SMILIES_CHECKED' => $forum_desc_data['allow_smilies'] ? true : false, 'S_DESC_URLS_CHECKED' => $forum_desc_data['allow_urls'] ? true : false, 'S_FORUM_TYPE_OPTIONS' => $forum_type_options, 'S_STATUS_OPTIONS' => $statuslist, 'S_PARENT_OPTIONS' => $parents_list, 'S_STYLES_OPTIONS' => $styles_list, 'S_FORUM_OPTIONS' => make_forum_select($action == 'add' ? $forum_data['parent_id'] : false, $action == 'edit' ? $forum_data['forum_id'] : false, false, false, false), 'S_SHOW_DISPLAY_ON_INDEX' => $s_show_display_on_index, 'S_FORUM_POST' => $forum_data['forum_type'] == FORUM_POST ? true : false, 'S_FORUM_ORIG_POST' => isset($old_forum_type) && $old_forum_type == FORUM_POST ? true : false, 'S_FORUM_ORIG_CAT' => isset($old_forum_type) && $old_forum_type == FORUM_CAT ? true : false, 'S_FORUM_ORIG_LINK' => isset($old_forum_type) && $old_forum_type == FORUM_LINK ? true : false, 'S_FORUM_LINK' => $forum_data['forum_type'] == FORUM_LINK ? true : false, 'S_FORUM_CAT' => $forum_data['forum_type'] == FORUM_CAT ? true : false, 'S_ENABLE_INDEXING' => $forum_data['enable_indexing'] ? true : false, 'S_TOPIC_ICONS' => $forum_data['enable_icons'] ? true : false, 'S_DISPLAY_SUBFORUM_LIST' => $forum_data['display_subforum_list'] ? true : false, 'S_DISPLAY_ON_INDEX' => $forum_data['display_on_index'] ? true : false, 'S_PRUNE_ENABLE' => $forum_data['enable_prune'] ? true : false, 'S_FORUM_LINK_TRACK' => $forum_data['forum_flags'] & FORUM_FLAG_LINK_TRACK ? true : false, 'S_PRUNE_OLD_POLLS' => $forum_data['forum_flags'] & FORUM_FLAG_PRUNE_POLL ? true : false, 'S_PRUNE_ANNOUNCE' => $forum_data['forum_flags'] & FORUM_FLAG_PRUNE_ANNOUNCE ? true : false, 'S_PRUNE_STICKY' => $forum_data['forum_flags'] & FORUM_FLAG_PRUNE_STICKY ? true : false, 'S_DISPLAY_ACTIVE_TOPICS' => $forum_data['forum_type'] == FORUM_POST ? $forum_data['forum_flags'] & FORUM_FLAG_ACTIVE_TOPICS : true, 'S_ENABLE_ACTIVE_TOPICS' => $forum_data['forum_type'] == FORUM_CAT ? $forum_data['forum_flags'] & FORUM_FLAG_ACTIVE_TOPICS : false, 'S_ENABLE_POST_REVIEW' => $forum_data['forum_flags'] & FORUM_FLAG_POST_REVIEW ? true : false, 'S_ENABLE_QUICK_REPLY' => $forum_data['forum_flags'] & FORUM_FLAG_QUICK_REPLY ? true : false, 'S_CAN_COPY_PERMISSIONS' => $action != 'edit' || empty($forum_id) || $auth->acl_get('a_fauth') && $auth->acl_get('a_authusers') && $auth->acl_get('a_authgroups') && $auth->acl_get('a_mauth') ? true : false));
                return;
                break;
            case 'delete':
                if (!$forum_id) {
                    trigger_error($user->lang['NO_FORUM'] . adm_back_link($this->u_action . '&amp;parent_id=' . $this->parent_id), E_USER_WARNING);
                }
                $forum_data = $this->get_forum_info($forum_id);
                $subforums_id = array();
                $subforums = get_forum_branch($forum_id, 'children');
                foreach ($subforums as $row) {
                    $subforums_id[] = $row['forum_id'];
                }
                $forums_list = make_forum_select($forum_data['parent_id'], $subforums_id);
                $sql = 'SELECT forum_id
					FROM ' . FORUMS_TABLE . '
					WHERE forum_type = ' . FORUM_POST . "\n\t\t\t\t\t\tAND forum_id <> {$forum_id}";
                $result = $db->sql_query_limit($sql, 1);
                if ($db->sql_fetchrow($result)) {
                    $template->assign_vars(array('S_MOVE_FORUM_OPTIONS' => make_forum_select($forum_data['parent_id'], $subforums_id, false, true)));
                }
                $db->sql_freeresult($result);
                $parent_id = $this->parent_id == $forum_id ? 0 : $this->parent_id;
                $template->assign_vars(array('S_DELETE_FORUM' => true, 'U_ACTION' => $this->u_action . "&amp;parent_id={$parent_id}&amp;action=delete&amp;f={$forum_id}", 'U_BACK' => $this->u_action . '&amp;parent_id=' . $this->parent_id, 'FORUM_NAME' => $forum_data['forum_name'], 'S_FORUM_POST' => $forum_data['forum_type'] == FORUM_POST ? true : false, 'S_FORUM_LINK' => $forum_data['forum_type'] == FORUM_LINK ? true : false, 'S_HAS_SUBFORUMS' => $forum_data['right_id'] - $forum_data['left_id'] > 1 ? true : false, 'S_FORUMS_LIST' => $forums_list, 'S_ERROR' => sizeof($errors) ? true : false, 'ERROR_MSG' => sizeof($errors) ? implode('<br />', $errors) : ''));
                return;
                break;
            case 'copy_perm':
                $forum_perm_from = request_var('forum_perm_from', 0);
                // Copy permissions?
                if (!empty($forum_perm_from) && $forum_perm_from != $forum_id) {
                    copy_forum_permissions($forum_perm_from, $forum_id, true);
                    cache_moderators();
                    $auth->acl_clear_prefetch();
                    $cache->destroy('sql', FORUMS_TABLE);
                    $acl_url = '&amp;mode=setting_forum_local&amp;forum_id[]=' . $forum_id;
                    $message = $user->lang['FORUM_UPDATED'];
                    // Redirect to permissions
                    if ($auth->acl_get('a_fauth')) {
                        $message .= '<br /><br />' . sprintf($user->lang['REDIRECT_ACL'], '<a href="' . append_sid("{$phpbb_admin_path}index.{$phpEx}", 'i=permissions' . $acl_url) . '">', '</a>');
                    }
                    trigger_error($message . adm_back_link($this->u_action . '&amp;parent_id=' . $this->parent_id));
                }
                break;
        }
        // Default management page
        if (!$this->parent_id) {
            $navigation = $user->lang['FORUM_INDEX'];
        } else {
            $navigation = '<a href="' . $this->u_action . '">' . $user->lang['FORUM_INDEX'] . '</a>';
            $forums_nav = get_forum_branch($this->parent_id, 'parents', 'descending');
            foreach ($forums_nav as $row) {
                if ($row['forum_id'] == $this->parent_id) {
                    $navigation .= ' -&gt; ' . $row['forum_name'];
                } else {
                    $navigation .= ' -&gt; <a href="' . $this->u_action . '&amp;parent_id=' . $row['forum_id'] . '">' . $row['forum_name'] . '</a>';
                }
            }
        }
        // Jumpbox
        $forum_box = make_forum_select($this->parent_id, false, false, false, false);
        //make_forum_select($this->parent_id);
        if ($action == 'sync' || $action == 'sync_forum') {
            $template->assign_var('S_RESYNCED', true);
        }
        $sql = 'SELECT *
			FROM ' . FORUMS_TABLE . "\n\t\t\tWHERE parent_id = {$this->parent_id}\n\t\t\tORDER BY left_id";
        $result = $db->sql_query($sql);
        if ($row = $db->sql_fetchrow($result)) {
            do {
                $forum_type = $row['forum_type'];
                if ($row['forum_status'] == ITEM_LOCKED) {
                    $folder_image = '<img src="images/icon_folder_lock.gif" alt="' . $user->lang['LOCKED'] . '" />';
                } else {
                    switch ($forum_type) {
                        case FORUM_LINK:
                            $folder_image = '<img src="images/icon_folder_link.gif" alt="' . $user->lang['LINK'] . '" />';
                            break;
                        default:
                            $folder_image = $row['left_id'] + 1 != $row['right_id'] ? '<img src="images/icon_subfolder.gif" alt="' . $user->lang['SUBFORUM'] . '" />' : '<img src="images/icon_folder.gif" alt="' . $user->lang['FOLDER'] . '" />';
                            break;
                    }
                }
                $url = $this->u_action . "&amp;parent_id={$this->parent_id}&amp;f={$row['forum_id']}";
                $template->assign_block_vars('forums', array('FOLDER_IMAGE' => $folder_image, 'FORUM_IMAGE' => $row['forum_image'] ? '<img src="' . $phpbb_root_path . $row['forum_image'] . '" alt="" />' : '', 'FORUM_IMAGE_SRC' => $row['forum_image'] ? $phpbb_root_path . $row['forum_image'] : '', 'FORUM_NAME' => $row['forum_name'], 'FORUM_DESCRIPTION' => generate_text_for_display($row['forum_desc'], $row['forum_desc_uid'], $row['forum_desc_bitfield'], $row['forum_desc_options']), 'FORUM_TOPICS' => $row['forum_topics'], 'FORUM_POSTS' => $row['forum_posts'], 'S_FORUM_LINK' => $forum_type == FORUM_LINK ? true : false, 'S_FORUM_POST' => $forum_type == FORUM_POST ? true : false, 'U_FORUM' => $this->u_action . '&amp;parent_id=' . $row['forum_id'], 'U_MOVE_UP' => $url . '&amp;action=move_up', 'U_MOVE_DOWN' => $url . '&amp;action=move_down', 'U_EDIT' => $url . '&amp;action=edit', 'U_DELETE' => $url . '&amp;action=delete', 'U_SYNC' => $url . '&amp;action=sync'));
            } while ($row = $db->sql_fetchrow($result));
        } else {
            if ($this->parent_id) {
                $row = $this->get_forum_info($this->parent_id);
                $url = $this->u_action . '&amp;parent_id=' . $this->parent_id . '&amp;f=' . $row['forum_id'];
                $template->assign_vars(array('S_NO_FORUMS' => true, 'U_EDIT' => $url . '&amp;action=edit', 'U_DELETE' => $url . '&amp;action=delete', 'U_SYNC' => $url . '&amp;action=sync'));
            }
        }
        $db->sql_freeresult($result);
        $template->assign_vars(array('ERROR_MSG' => sizeof($errors) ? implode('<br />', $errors) : '', 'NAVIGATION' => $navigation, 'FORUM_BOX' => $forum_box, 'U_SEL_ACTION' => $this->u_action, 'U_ACTION' => $this->u_action . '&amp;parent_id=' . $this->parent_id, 'U_PROGRESS_BAR' => $this->u_action . '&amp;action=progress_bar', 'UA_PROGRESS_BAR' => addslashes($this->u_action . '&amp;action=progress_bar')));
    }
Example #16
0
// pre-cache templates used by all actions
$globaltemplates = array('USERCP_SHELL', 'usercp_nav_folderbit');
// pre-cache templates used by specific actions
$actiontemplates = array('viewthreads' => array('forumdisplay_sortarrow', 'moderation_threads', 'threadadmin_imod_menu_thread', 'threadbit', 'threadbit_deleted'), 'viewposts' => array('moderation_posts', 'search_results_postbit', 'threadadmin_imod_menu_post'), 'viewvms' => array('moderation_filter', 'moderation_visitormessages', 'memberinfo_visitormessage', 'memberinfo_visitormessage_deleted', 'memberinfo_visitormessage_ignored', 'memberinfo_css'), 'viewgms' => array('moderation_filter', 'moderation_groupmessages', 'memberinfo_css', 'socialgroups_message', 'socialgroups_message_deleted', 'socialgroups_message_ignored'), 'viewpcs' => array('moderation_filter', 'moderation_picturecomments', 'picturecomment_css', 'picturecomment_message_moderatedview'), 'viewpics' => array('moderation_filter', 'moderation_picturebit', 'moderation_pictures', 'picturecomment_css'));
$actiontemplates['none'] =& $actiontemplates['viewthreads'];
// ######################### REQUIRE BACK-END ############################
require_once './global.php';
require_once DIR . '/includes/functions_user.php';
require_once DIR . '/includes/functions_forumlist.php';
// #######################################################################
// ######################## START MAIN SCRIPT ############################
// #######################################################################
if (empty($_REQUEST['do'])) {
    $_REQUEST['do'] = 'viewthreads';
}
cache_moderators($vbulletin->userinfo['userid']);
// start the navbits breadcrumb
$navbits = array('usercp.php' . $vbulletin->session->vars['sessionurl_q'] => $vbphrase['user_control_panel']);
($hook = vBulletinHook::fetch_hook('moderation_start')) ? eval($hook) : false;
// ############################### start view threads ###############################
if ($_REQUEST['do'] == 'viewthreads') {
    $vbulletin->input->clean_array_gpc('r', array('perpage' => TYPE_UINT, 'pagenumber' => TYPE_UINT, 'daysprune' => TYPE_INT, 'sortfield' => TYPE_NOHTML, 'sortorder' => TYPE_NOHTML, 'type' => TYPE_NOHTML, 'forumid' => TYPE_UINT));
    ($hook = vBulletinHook::fetch_hook('moderation_threads_start')) ? eval($hook) : false;
    // Values that are reused in templates
    $sortfield =& $vbulletin->GPC['sortfield'];
    $perpage =& $vbulletin->GPC['perpage'];
    $pagenumber =& $vbulletin->GPC['pagenumber'];
    $daysprune =& $vbulletin->GPC['daysprune'];
    $type =& $vbulletin->GPC['type'];
    $forumid =& $vbulletin->GPC['forumid'];
    if ($type == 'deleted') {
Example #17
0
function print_forums($parentid = -1, $indent = "\t")
{
    // new version - DRASTICALLY reduces queries...
    global $vbulletin, $imodcache, $accesscache, $vbphrase;
    // check to see if we need to do the queries
    if (empty($vbulletin->iforumcache)) {
        cache_ordered_forums(0, 1);
    }
    if (!is_array($imodcache)) {
        require_once DIR . '/includes/functions_forumlist.php';
        cache_moderators();
    }
    // check to see if this forum actually exists / has children
    if (empty($vbulletin->iforumcache["{$parentid}"])) {
        return;
    }
    foreach ($vbulletin->iforumcache["{$parentid}"] as $forumid) {
        $forum =& $vbulletin->forumcache["{$forumid}"];
        echo "{$indent}<ul class=\"lsq\">\n";
        // forum title and links
        echo "{$indent}<li><b><a name=\"forum{$forumid}\" href=\"forum.php?{$session['sessionurl']}do=edit&amp;f={$forumid}\">{$forum['title']}</a> <span class=\"smallfont\">(" . construct_link_code($vbphrase['reset'], "accessmask.php?{$session['sessionurl']}do=resetforum&amp;f={$forumid}&amp;hash=" . CP_SESSIONHASH) . ")</span></b>";
        // get moderators
        if (is_array($imodcache["{$forumid}"])) {
            echo "<span class=\"smallfont\"><br /> - <i>" . $vbphrase['moderators'] . ":";
            foreach ($imodcache["{$forumid}"] as $moderator) {
                // moderator username and links
                echo " <a href=\"moderator.php?" . $vbulletin->session->vars['sessionurl'] . "do=edit&amp;moderatorid={$moderator['moderatorid']}\">{$moderator['username']}</a>";
            }
            echo "</i></span>";
        }
        $allaccessmasks = 0;
        $forbidden = '';
        $permitted = '';
        $deny = $accesscache["{$forumid}"]['0'];
        $permit = $accesscache["{$forumid}"]['1'];
        /*echo "<pre>--$forumid--\n";
        		print_r($accesscache["$forumid"]);
        		echo '</pre>';*/
        if (is_array($deny)) {
            $forbidden = "{$indent}\t<li class=\"am-deny\"><b>" . construct_phrase($vbphrase['access_denied_x_users'], $deny['count']) . '</b>' . construct_link_code($vbphrase['display_users'], "accessmask.php?" . $vbulletin->session->vars['sessionurl'] . "&do=edit&f={$forumid}&accessmask={$deny['accessmask']}") . "</li>\n";
            $allaccessmasks = $deny['count'];
        }
        if (is_array($permit)) {
            $permitted = "{$indent}\t<li class=\"am-grant\"><b>" . construct_phrase($vbphrase['access_granted_x_users'], $permit['count']) . '</b>' . construct_link_code($vbphrase['display_users'], "accessmask.php?" . $vbulletin->session->vars['sessionurl'] . "&do=edit&f={$forumid}&accessmask={$permit['accessmask']}") . "</li>\n";
            $allaccessmasks = $allaccessmasks + $permit['count'];
        }
        if ($allaccessmasks > 0) {
            echo "{$indent}\t<ul class=\"usergroups\">\n";
            echo "{$indent}\t<li>" . construct_phrase($vbphrase['x_access_masks_set'], $allaccessmasks) . ' ' . construct_link_code('<b>' . $vbphrase['display_all_users'] . '</b>', "accessmask.php?" . $vbulletin->session->vars['sessionurl'] . "&do=edit&f={$forum['forumid']}&accessmask=2") . "</li>";
            echo $permitted;
            echo $forbidden;
            echo "{$indent}\t</ul><br />\n";
        } else {
            echo "{$indent}\t\n";
            echo "{$indent}\t<br />\n";
        }
        print_forums($forumid, "{$indent}\t");
        echo "{$indent}</li>\n";
        echo "{$indent}</ul>\n";
        if ($forum['parentid'] == -1) {
            echo "<hr size=\"1\" />\n";
        }
    }
    unset($vbulletin->iforumcache["{$parentid}"]);
}
Example #18
0
 /**
  * Constructor
  *
  * @param	vB_Registry
  * @param	integer			Unique id of this contenttype (forum post, blog entry, etc)
  *
  * @return	void
  */
 public function __construct(&$registry, $contenttypeid)
 {
     parent::__construct($registry);
     $this->contenttypeid = $contenttypeid;
     require_once DIR . '/includes/functions_forumlist.php';
     cache_moderators($registry->userinfo['userid']);
 }
/**
* Re-cache moderators and foes if group has a_ or m_ permissions
*/
function group_update_listings($group_id)
{
    global $auth;
    $hold_ary = $auth->acl_group_raw_data($group_id, array('a_', 'm_'));
    if (!sizeof($hold_ary)) {
        return;
    }
    $mod_permissions = $admin_permissions = false;
    foreach ($hold_ary as $g_id => $forum_ary) {
        foreach ($forum_ary as $forum_id => $auth_ary) {
            foreach ($auth_ary as $auth_option => $setting) {
                if ($mod_permissions && $admin_permissions) {
                    break 3;
                }
                if ($setting != ACL_YES) {
                    continue;
                }
                if ($auth_option == 'm_') {
                    $mod_permissions = true;
                }
                if ($auth_option == 'a_') {
                    $admin_permissions = true;
                }
            }
        }
    }
    if ($mod_permissions) {
        cache_moderators();
    }
}