Example #1
0
 function execute(&$request)
 {
     global $_QUERYPARAMS, $_USERGROUPS;
     k4_bread_crumbs($request['template'], $request['dba'], 'L_CALENDAR');
     # get the year month and day from request vars
     $year = isset($_REQUEST['y']) && intval($_REQUEST['y']) > 0 ? $_REQUEST['y'] : date('Y', time());
     $month = isset($_REQUEST['m']) && intval($_REQUEST['m']) > 0 ? $_REQUEST['m'] : date('n', time());
     $day = isset($_REQUEST['d']) && intval($_REQUEST['d']) > 0 ? $_REQUEST['j'] : 1;
     # new k4Calendar instance
     $c =& new K4Calendar($year, $month, $day);
     # The next and previous months, do this all first.
     $year = $month == 1 ? $year - 1 : $year;
     $html = $this->mini_month($c->getPrevMonth(), $year, $request);
     $request['template']->setVar('prev_month_cal', $html);
     $year = $month == 12 ? $year + 1 : $year;
     $html = $this->mini_month($c->getNextMonth(), $year, $request);
     $request['template']->setVar('next_month_cal', $html);
     # Get user birthdays
     $birthdays = $request['dba']->executeQuery("SELECT {$_QUERYPARAMS['user']}{$_QUERYPARAMS['userinfo']} FROM " . K4USERS . " u LEFT JOIN " . K4USERINFO . " ui ON u.id=ui.user_id WHERE ui.birthday LIKE '" . str_pad($month, 2, '0', STR_PAD_LEFT) . "/%'");
     $bdays = array();
     if ($birthdays->hasNext()) {
         while ($birthdays->next()) {
             $user = $birthdays->current();
             $parts = explode("/", $user['birthday']);
             $group = get_user_max_group($user, $_USERGROUPS);
             $user['group_color'] = !isset($group['color']) || $group['color'] == '' ? '000000' : $group['color'];
             $user['age'] = $year - intval($parts[2]);
             $user['U_MEMBERURL'] = K4Url::getMemberUrl($user['id']);
             $bdays[$parts[1]][] = $user;
         }
     }
     # Add the iterator to the template
     $c->month = $month;
     $c->year = $year;
     $iteration_c = new K4CalendarIterator($c->getData(), $c->getWeek($month, $day, $year), $bdays);
     $iteration_d = new FAArrayIterator($c->getWeekdays());
     //print_r($c->getWeekRange($month, $day, $year)); exit;
     $request['template']->setList('calendar', $iteration_c);
     $request['template']->setList('weekdays', $iteration_d);
     # url's, need fixing
     $request['template']->setVarArray(array('U_CALENDARPREVYEARURL' => K4Url::getGenUrl('calendar', 'y=' . $c->getPrevYear() . '&m=' . $c->getMonth()), 'U_CALENDARNEXTYEARURL' => K4Url::getGenUrl('calendar', 'y=' . $c->getNextYear() . '&m=' . $c->getMonth()), 'U_CALENDARPREVMONTHURL' => K4Url::getGenUrl('calendar', 'y=' . $c->getYear() . '&m=' . $c->getPrevMonth()), 'U_CALENDARNEXTMONTHURL' => K4Url::getGenUrl('calendar', 'y=' . $c->getYear() . '&m=' . $c->getNextMonth())));
     # The rest
     $request['template']->setVar('month_label', date('F', mktime(0, 0, 0, $c->getMonth(), 1, $c->getYear())));
     $request['template']->setVar('year_label', $c->getYear());
     $request['template']->setVar('month_next', $c->getNextMonth());
     $request['template']->setVar('month_prev', $c->getPrevMonth());
     $request['template']->setVar('year_next', $c->getNextYear());
     $request['template']->setVar('year_prev', $c->getPrevYear());
     $request['template']->setVar('nav_prev', $c->checkPrevYear());
     $request['template']->setVar('nav_next', $c->checkNextYear());
     $request['template']->setFile('content', 'calendar_index.html');
 }
Example #2
0
 function current()
 {
     $temp = parent::current();
     // if there are more than one answers
     if ($temp['num_answers'] > 0) {
         $temp['sub_answers'] = $this->dba->executeQuery("SELECT * FROM " . K4FAQANSWERS . " WHERE category_id = " . intval($temp['category_id']) . " AND can_view <= " . intval($_SESSION['user']->get('perms')) . " ORDER BY row_order ASC");
     }
     // if there are more than one sub-categories
     if ($temp['num_categories'] > 0) {
         $temp['sub_categories'] = $this->dba->executeQuery("SELECT * FROM " . K4FAQCATEGORIES . " WHERE parent_id = " . intval($temp['category_id']) . " AND can_view <= " . intval($_SESSION['user']->get('perms')));
     }
     // custom url's
     $temp['U_FAQANSWER'] = K4Url::getGenUrl('faq', 'c=' . $temp['category_id'] . '#faq' . $temp['answer_id']);
     $temp['U_FAQCATEGORY'] = K4Url::getGenUrl('faq', 'c=' . $temp['category_id']);
     /* Should we free the result? */
     if (!$this->hasNext()) {
         $this->result->free();
     }
     return $temp;
 }
 function current()
 {
     $temp = parent::current();
     if ($temp['invisible'] == 1) {
         Globals::setGlobal('num_online_invisible', Globals::getGlobal('num_online_invisible') + 1);
     }
     if ($temp['user_id'] >= 0) {
         $group = get_user_max_group($temp, $this->groups);
         $temp['color'] = !isset($group['color']) || $group['color'] == '' ? '000000' : $group['color'];
         $temp['font_weight'] = @$group['min_perm'] > MEMBER ? 'bold' : 'normal';
     }
     /* Should we free the result? */
     if (!$this->hasNext()) {
         $this->result->free();
     }
     $temp['U_MEMBERURL'] = K4Url::getMemberUrl($temp['user_id']);
     //if($temp['name'] != '') {
     //	if(((isset($temp['invisible']) && $temp['invisible'] == 0) || !isset($temp['invisible']))) {
     return $temp;
     //	}
     //}
 }
Example #4
0
 function current()
 {
     $temp = parent::current();
     $group = get_user_max_group($temp, $this->groups);
     $temp['group_color'] = !isset($group['color']) || $group['color'] == '' ? '000000' : $group['color'];
     $temp['group_nicename'] = $group['nicename'];
     $temp['group_avatar'] = $group['avatar'];
     $temp['online'] = time() - ini_get('session.gc_maxlifetime') > $temp['seen'] ? 'offline' : 'online';
     // custom url's
     $temp['U_MEMBERURL'] = K4Url::getMemberUrl($temp['user_id']);
     /* Should we free the result? */
     if (!$this->hasNext()) {
         $this->result->free();
     }
     return $temp;
 }
 function current()
 {
     $temp = parent::current();
     // set the week the the data
     $temp['week'] = $this->week;
     // set a users iterator
     $temp['user_bdays'] = 0;
     if (isset($this->user_bdays[$temp['day']])) {
         $temp['users'] =& new FAArrayIterator($this->user_bdays[$temp['day']]);
         $temp['user_bdays'] = 1;
     }
     // increment the week number
     if ($this->iteration % 7 == 0) {
         $this->week++;
     }
     // increment something to keep track of how many days we have iterated over
     $this->iteration++;
     // urls
     $temp['U_CALENDARDAYURL'] = K4Url::getGenUrl('calendar', 'view=day&amp;y=' . $temp['year'] . '&amp;m=' . $temp['month'] . '&amp;d=' . $temp['day'] . '&amp;w=' . $temp['week']);
     $temp['U_CALENDARWEEKURL'] = K4Url::getGenUrl('calendar', 'view=week&amp;y=' . $temp['year'] . '&amp;m=' . $temp['month'] . '&amp;w=' . $temp['week']);
     // Return the formatted info
     return $temp;
 }
 function current()
 {
     $temp = parent::current();
     $temp['posticon'] = @$temp['posticon'] != '' ? file_exists(BB_BASE_DIR . '/tmp/upload/posticons/' . @$temp['posticon']) ? @$temp['posticon'] : 'clear.gif' : 'clear.gif';
     $temp['post_id'] = 't' . $temp['post_id'];
     if ($temp['poster_id'] > 0) {
         $temp['post_display_user_ddmenu'] = 1;
         if (!isset($this->users[$temp['poster_id']])) {
             $user = $this->dba->getRow("SELECT " . $this->qp['user'] . $this->qp['userinfo'] . " FROM " . K4USERS . " u LEFT JOIN " . K4USERINFO . " ui ON u.id=ui.user_id WHERE u.id=" . intval($temp['poster_id']));
             if (is_array($user) && !empty($user)) {
                 $group = get_user_max_group($user, $this->groups);
                 $user['group_color'] = !isset($group['color']) || $group['color'] == '' ? '000000' : $group['color'];
                 $user['group_nicename'] = isset($group['nicename']) ? $group['nicename'] : '';
                 $user['group_avatar'] = isset($group['avatar']) ? $group['avatar'] : '';
                 $user['online'] = time() - ini_get('session.gc_maxlifetime') > $user['seen'] ? 'offline' : 'online';
                 $this->users[$user['id']] = $user;
             }
         } else {
             $user = $this->users[$temp['poster_id']];
         }
         if (is_array($user) && !empty($user)) {
             if ($user['flag_level'] > 0 && $_SESSION['user']->get('perms') >= MODERATOR) {
                 $temp['post_user_background'] = 'background-color: #FFFF00;';
             }
             foreach ($user as $key => $val) {
                 $temp['post_user_' . $key] = $val;
             }
             $temp['profilefields'] =& new FAArrayIterator(get_profile_fields($this->fields, $temp));
             $temp['post_user_title'] = $user['user_title'];
             $temp['post_user_user_title'] = get_user_title($user['user_title'], $user['num_posts']);
         }
         if (!isset($temp['post_user_online'])) {
             $temp['post_user_online'] = 'offline';
         }
         /* This array holds all of the userinfo for users that post to this topic */
         $this->users[$user['id']] = $user;
     } else {
         $temp['post_user_id'] = 0;
         $temp['post_user_name'] = $temp['poster_name'];
     }
     /* Deal with acronyms */
     replace_acronyms($temp['body_text']);
     /* word censors */
     replace_censors($temp['body_text']);
     replace_censors($temp['name']);
     /* Do any polls if they exist */
     do_post_polls($temp, $this->dba);
     /* do we have any attachments? */
     if (isset($temp['attachments']) && $temp['attachments'] > 0) {
         $temp['attachment_files'] = new K4AttachmentsIterator($this->dba, $this->user, $temp['post_id'], 0);
     }
     // url's
     $temp['U_TOPICURL'] = K4Url::getTopicUrl($temp['post_id']);
     $temp['U_POSTURL'] = K4Url::getPostUrl($temp['post_id']);
     $temp['U_MEMBERURL'] = K4Url::getMemberUrl($temp['poster_id']);
     if ($this->sr && $temp['num_replies'] > 0) {
         $this->result = $this->dba->executeQuery("SELECT * FROM " . K4POSTS . " WHERE parent_id = " . intval($temp['post_id']) . " AND row_type=" . REPLY . " " . ($this->post_id ? "AND post_id = " . $this->post_id : "") . " AND created >= " . 3600 * 24 * intval($temp['daysprune']) . " ORDER BY " . $temp['sortedby'] . " " . $temp['sortorder'] . " LIMIT " . intval($temp['start']) . "," . intval($temp['postsperpage']));
         $temp['replies'] = new RepliesIterator($this->user, $this->dba, $this->result, $this->qp, $this->users, $this->groups, $this->fields);
     }
     return $temp;
 }
/**
 * Function to apply a template to polls inside topics/posts
 * @param string text			The text that the poll is in
 * @param object dba			Database object
 * @param integer poll_id		The poll id
 * @param text replace_text		The text that will be replaced by the poll template
 *
 * @author Peter Goodman
 */
function poll_template(&$text, &$dba, $poll_id, $replace_text, $post_id, $post_id = FALSE)
{
    global $_URL, $_LANG;
    // attempt to get our poll question
    $question = $dba->getRow("SELECT * FROM " . K4POLLQUESTIONS . " WHERE id = " . intval($poll_id));
    // is this person logges it?
    $show_results = $_SESSION['user']->isMember() ? FALSE : TRUE;
    // do we show the results or not?
    $show_results = isset($_REQUEST['sr' . intval($poll_id)]) && intval($_REQUEST['sr' . intval($poll_id)]) == 1 ? TRUE : $show_results;
    // if the question is valid
    if (is_array($question) && !empty($question)) {
        $has_voted = $dba->executeQuery("SELECT * FROM " . K4POLLVOTES . " WHERE question_id = " . intval($question['id']) . " AND user_id = " . intval($_SESSION['user']->get('id')));
        $can_vote = TRUE;
        if ($has_voted->numRows() > 0) {
            $show_results = TRUE;
            $can_vote = FALSE;
        }
        /**
         * POLL TEMPLATE HEADER
         */
        $tpl = '<a name="poll' . intval($question['id']) . '" id="poll' . intval($question['id']) . '"></a><div align="center"><div align="center" style="width: 75%;">';
        //$tpl	.=	'	<div style="width: 75%;" class="inset_box_small">';
        if (!$show_results) {
            $tpl .= '<form action="' . K4Url::getGenUrl('viewpoll', 'act=vote&amp;id=' . intval($question['id'])) . '" method="post" enctype="multipart/form-data">';
            $tpl .= '<input type="hidden" name="post_id" value="' . intval($post_id) . '" />';
            $tpl .= '<input type="hidden" name="post_id" value="' . intval($post_id) . '" />';
        }
        $tpl .= '	<div class="subheader"><a href="' . K4Url::getGenUrl('viewpoll', 'id=' . $question['id'] . '" title="' . $question['question']) . '">' . $question['question'] . '</a> : ' . $_LANG['L_POLLOPTIONS'] . '</div>';
        $tpl .= '	<div class="spacer">';
        $tpl .= '		<table width="100%" cellpadding="0" cellspacing="' . K4_TABLE_CELLSPACING . '" border="0" class="table">';
        /**
         * / POLL TEMPLATE HEADER
         */
        // get the answers
        $answers = $dba->executeQuery("SELECT * FROM " . K4POLLANSWERS . " WHERE question_id = " . intval($question['id']) . " ORDER BY id ASC");
        $i = 0;
        // loop through the answers
        while ($answers->next()) {
            $answer = $answers->current();
            $tpl .= '			<tr class="' . iif($i % 2 == 0, 'alt1', 'alt2') . '">';
            if ($show_results) {
                $num_votes = $dba->getValue("SELECT COUNT(*) FROM " . K4POLLVOTES . " WHERE question_id = " . $question['id'] . " AND answer_id = " . $answer['id']);
                $percent = @ceil($num_votes / $question['num_votes'] * 100);
                $tpl .= '	<td align="left"><div class="smalltext">' . k4_htmlentities($answer['answer'], ENT_QUOTES) . '</div></td>';
                $tpl .= '	<td width="100" align="left"><div class="smalltext"><div style="float: left;border: 1px solid #333333;width: 100px;height: 18px;background-color: #FFFFFF;"><div style="float: left; height: 18px; width: ' . $percent . '%;background-color: #666666;"></div></div><br />(' . $percent . '%, ' . $num_votes . ' ' . $_LANG['L_VOTES'] . ')</div></td>';
            } else {
                $tpl .= '	<td align="left"><div class="smalltext"><label for="vote' . $answer['id'] . '">' . k4_htmlentities($answer['answer'], ENT_QUOTES) . '</label></div></td>';
                $tpl .= '	<td align="center"><div class="smalltext"><input type="radio" id="vote' . $answer['id'] . '" name="vote" value="' . $answer['id'] . '" /></div></td>';
            }
            $tpl .= '			</tr>';
            $i++;
        }
        /**
         * POLL TEMPLATE FOOTER
         */
        if (!$show_results) {
            $tpl .= '			<tr class="base3">';
            $tpl .= '				<td colspan="2" style="text-align:center;"><input type="submit" class="button" value="' . $_LANG['L_VOTE'] . '" /></td>';
            $tpl .= '			</tr>';
        }
        if (!$show_results) {
            $url =& new FAUrl($_URL->__toString());
            $url->args['sr' . $question['id']] = 1;
            $url->anchor = FALSE;
            $tpl .= '			<tr class="alt3">';
            $tpl .= '				<td colspan="2" style="text-align:center;"><a class="smalltext" href="' . $url->__toString() . '#poll' . intval($question['id']) . '" title="' . $_LANG['L_VIEWRESULTS'] . '">' . $_LANG['L_VIEWRESULTS'] . '</a></td>';
            $tpl .= '			</tr>';
        } else {
            $url =& new FAUrl($_URL->__toString());
            unset($url->args['sr' . $question['id']]);
            if ($can_vote) {
                $tpl .= '		<tr class="alt3">';
                $tpl .= '			<td colspan="2" style="text-align:center;"><a class="smalltext" href="' . $url->__toString() . '#poll' . intval($question['id']) . '" title="' . $_LANG['L_VIEWOPTIONS'] . '">' . $_LANG['L_VIEWOPTIONS'] . '</a></td>';
                $tpl .= '		</tr>';
            }
        }
        $tpl .= '		</table>';
        $tpl .= '	</div>';
        if (!$show_results) {
            $tpl .= '</form>';
        }
        $tpl .= '</div></div>';
        /**
         * / POLL TEMPLATE FOOTER
         */
        // replace the poll tag with this poll template
        $text = str_replace($replace_text, $tpl, $text);
    } else {
        $text = str_replace($replace_text, '', $text);
    }
}
 function current()
 {
     $temp = parent::current();
     $group = get_user_max_group($temp, $this->groups);
     $temp['group_color'] = !isset($group['color']) || $group['color'] == '' ? '000000' : $group['color'];
     $temp['group_nicename'] = $group['nicename'];
     $temp['group_avatar'] = $group['avatar'];
     $temp['font_weight'] = isset($group['min_perm']) && $group['min_perm'] > MEMBER ? 'bold' : 'normal';
     $temp['warn_color'] = get_warning_color($temp['warn_level']);
     // urls
     $temp['U_MEMBERURL'] = K4Url::getMemberUrl($temp['user_id']);
     if (!$this->hasNext()) {
         $this->result->free();
     }
     return $temp;
 }
Example #9
0
 function execute(&$request)
 {
     global $_QUERYPARAMS, $_USERGROUPS, $_URL;
     /* set the breadcrumbs bit */
     k4_bread_crumbs($request['template'], $request['dba'], 'L_INFORMATION');
     if (isset($_REQUEST['f']) && intval($_REQUEST['f']) != 0 || isset($_REQUEST['c']) && intval($_REQUEST['c']) != 0) {
         $thing = isset($_REQUEST['f']) ? 'f' : 'c';
         $forum = $request['dba']->getRow("SELECT * FROM " . K4FORUMS . " WHERE forum_id = " . intval($_REQUEST[$thing]));
     } else {
         $action = new K4InformationAction(new K4LanguageElement('L_FORUMDOESNTEXIST'), 'content', TRUE);
         return $action->execute($request);
     }
     if (!$forum || !is_array($forum) || empty($forum)) {
         $action = new K4InformationAction(new K4LanguageElement('L_FORUMDOESNTEXIST'), 'content', FALSE);
         return $action->execute($request);
     }
     if ($forum['row_type'] & FORUM && $forum['is_link'] == 1) {
         if ($forum['link_show_redirects'] == 1) {
             $action = new K4InformationAction(new K4LanguageElement('L_REDIRECTING'), 'content', FALSE, 'redirect.php?id=' . $forum['forum_id'], 3);
         } else {
             $action = new K4InformationAction(new K4LanguageElement('L_REDIRECTING'), 'content', FALSE, $forum['link_href'], 3);
         }
         return $action->execute($request);
     }
     /* Set the extra SQL query fields to check */
     $extra = " AND location_file = '" . $request['dba']->Quote($_URL->file) . "' AND location_id = " . ($forum['row_type'] & CATEGORY ? intval($forum['category_id']) : intval($forum['forum_id']));
     $user_extra = $request['user']->isMember() ? ' OR (seen > 0 AND user_id = ' . intval($request['user']->get('id')) . ')' : '';
     $forum_can_view = $forum['row_type'] & CATEGORY ? get_map('', 'can_view', array('category_id' => $forum['category_id'])) : get_map('', 'can_view', array('forum_id' => $forum['forum_id']));
     $expired = time() - ini_get('session.gc_maxlifetime');
     $num_online_total = $request['dba']->getValue("SELECT COUNT(id) FROM " . K4SESSIONS . " WHERE ((seen >= {$expired} {$extra}) {$user_extra})");
     $num_online_total = !$request['user']->isMember() ? $num_online_total + 1 : $num_online_total;
     /* If there are more than 0 people browsing the forum, display the stats */
     if ($num_online_total > 0 && $forum_can_view <= $request['user']->get('perms')) {
         $query = "SELECT * FROM " . K4SESSIONS . " WHERE ((seen >= {$expired} {$extra}) {$user_extra}) AND ((user_id > 0) OR (user_id = 0 AND name <> '')) GROUP BY name ORDER BY seen DESC";
         $users_browsing =& new K4OnlineUsersIterator($request['dba'], '', $request['dba']->executeQuery($query));
         /* Set the users browsing list */
         $request['template']->setList('users_browsing', $users_browsing);
         $stats = array('num_online_members' => Globals::getGlobal('num_online_members'), 'num_invisible' => Globals::getGlobal('num_online_invisible'), 'num_online_total' => $num_online_total);
         $stats['num_guests'] = $stats['num_online_total'] - $stats['num_online_members'] - $stats['num_invisible'];
         $element = $forum['row_type'] & CATEGORY ? 'L_USERSBROWSINGCAT' : 'L_USERSBROWSINGFORUM';
         $request['template']->setVar('num_online_members', $stats['num_online_members']);
         $request['template']->setVar('users_browsing', $request['template']->getVar($element));
         $request['template']->setVar('online_stats', sprintf($request['template']->getVar('L_USERSBROWSINGSTATS'), $stats['num_online_total'], $stats['num_online_members'], $stats['num_guests'], $stats['num_invisible']));
         /* Set the User's Browsing file */
         $request['template']->setFile('users_browsing', 'users_browsing.html');
         $groups = array();
         /* Set the usergroups legend list */
         foreach ($_USERGROUPS as $group) {
             if ($group['display_legend'] == 1) {
                 $groups[] = $group;
             }
         }
         $groups =& new FAArrayIterator($groups);
         $request['template']->setList('usergroups_legend', $groups);
     }
     if ($forum_can_view > $request['user']->get('perms')) {
         $action = new K4InformationAction(new K4LanguageElement('L_PERMCANTVIEW'), 'content', FALSE);
         return $action->execute($request);
     }
     /**
      * Breadcrumbs 
      */
     /* Set the breadcrumbs bit */
     k4_bread_crumbs($request['template'], $request['dba'], NULL, $forum);
     /* Set if this breadcrumb should be 'new' or not */
     $icon = NULL;
     $new = $forum['row_type'] & FORUM ? forum_icon($forum, $icon) : FALSE;
     $request['template']->setVar('breadcrumb_new', $new == TRUE ? 'new' : '');
     /**
      * Forum/cateogry checking
      */
     /* Set all of the category/forum info to the template */
     $request['template']->setVarArray($forum);
     /**
      *
      * CATEGORY
      *
      */
     if ($forum['row_type'] & CATEGORY) {
         if (get_map('categories', 'can_view', array()) > $request['user']->get('perms')) {
             $action = new K4InformationAction(new K4LanguageElement('L_PERMCANTVIEW'), 'content', FALSE);
             return $action->execute($request);
         }
         /* Set the Categories list */
         $categories =& new K4ForumsIterator($request['dba'], "SELECT * FROM " . K4FORUMS . " WHERE forum_id = " . $forum['forum_id'] . " ORDER BY row_order ASC");
         $request['template']->setList('tlforums', $categories);
         /* Hide the welcome message at the top of the forums.html template */
         $request['template']->setVisibility('welcome_msg', FALSE);
         /* Show the forum status icons */
         $request['template']->setVisibility('forum_status_icons', TRUE);
         /* Show the 'Mark these forums Read' link */
         $request['template']->setVisibility('mark_these_forums', TRUE);
         /* Set the forums template to content variable */
         $request['template']->setFile('content', 'forums.html');
         /**
          *
          * FORUM / META FORUM
          *
          */
     } else {
         if ($forum['row_type'] & FORUM || $forum['row_type'] & METAFORUM || $forum['row_type'] & ARCHIVEFORUM) {
             /* Add the forum info to the template */
             foreach ($forum as $key => $val) {
                 $request['template']->setVar('forum_' . $key, $val);
             }
             /* If this forum has sub-forums */
             if (isset_forum_cache_item('subforums', $forum['forum_id']) && $forum['subforums'] >= 1) {
                 /* Cache this forum as having subforums */
                 set_forum_cache_item('subforums', 1, $forum['forum_id']);
                 /* Show the table that holds the subforums */
                 $request['template']->setVisibility('subforums', TRUE);
                 /* Set the sub-forums list */
                 $it =& new K4ForumsIterator($request['dba'], "SELECT * FROM " . K4FORUMS . " WHERE parent_id = " . $forum['forum_id'] . " ORDER BY row_order ASC");
                 $request['template']->setList('forums', $it);
             }
             if (get_map('topics', 'can_view', array('forum_id' => $forum['forum_id'])) > $request['user']->get('perms')) {
                 $action = new K4InformationAction(new K4LanguageElement('L_CANTVIEWFORUMTOPICS'), 'content_extra', FALSE);
                 return $action->execute($request);
             }
             /**
              * Forum settings
              */
             /* Set the topics template to the content variable */
             $request['template']->setFile('content', 'viewforum.html');
             /* Set what this user can/cannot do in this forum */
             $request['template']->setVar('forum_user_topic_options', sprintf($request['template']->getVar('L_FORUMUSERTOPICPERMS'), get_map('topics', 'can_add', array('forum_id' => $forum['forum_id'])) > $request['user']->get('perms') ? $request['template']->getVar('L_CANNOT') : $request['template']->getVar('L_CAN'), get_map('topics', 'can_edit', array('forum_id' => $forum['forum_id'])) > $request['user']->get('perms') ? $request['template']->getVar('L_CANNOT') : $request['template']->getVar('L_CAN'), get_map('topics', 'can_del', array('forum_id' => $forum['forum_id'])) > $request['user']->get('perms') ? $request['template']->getVar('L_CANNOT') : $request['template']->getVar('L_CAN'), get_map('attachments', 'can_add', array('forum_id' => $forum['forum_id'])) > $request['user']->get('perms') ? $request['template']->getVar('L_CANNOT') : $request['template']->getVar('L_CAN')));
             $request['template']->setVar('forum_user_reply_options', sprintf($request['template']->getVar('L_FORUMUSERREPLYPERMS'), get_map('replies', 'can_add', array('forum_id' => $forum['forum_id'])) > $request['user']->get('perms') ? $request['template']->getVar('L_CANNOT') : $request['template']->getVar('L_CAN'), get_map('replies', 'can_edit', array('forum_id' => $forum['forum_id'])) > $request['user']->get('perms') ? $request['template']->getVar('L_CANNOT') : $request['template']->getVar('L_CAN'), get_map('replies', 'can_del', array('forum_id' => $forum['forum_id'])) > $request['user']->get('perms') ? $request['template']->getVar('L_CANNOT') : $request['template']->getVar('L_CAN')));
             /* Create an array with all of the possible sort orders we can have */
             $sort_orders = array('name', 'lastpost_created', 'num_replies', 'views', 'lastpost_uname', 'rating', 'poster_name');
             //$extra_topics		= intval(@$_ALLFORUMS[GLBL_ANNOUNCEMENTS]['topics']);
             $extra_topics = 0;
             // TODO: need only Announcements from global announcements
             /**
              * Pagination
              */
             /* Create the Pagination */
             $resultsperpage = $request['user']->get('topicsperpage') <= 0 ? $forum['topicsperpage'] : $request['user']->get('topicsperpage');
             $num_results = $forum['topics'] + $extra_topics;
             $perpage = isset($_REQUEST['limit']) && ctype_digit($_REQUEST['limit']) && intval($_REQUEST['limit']) > 0 ? intval($_REQUEST['limit']) : $resultsperpage;
             $perpage = $perpage > 100 ? 100 : $perpage;
             $num_pages = intval(@ceil($num_results / $perpage));
             $page = isset($_REQUEST['page']) && ctype_digit($_REQUEST['page']) && intval($_REQUEST['page']) > 0 ? intval($_REQUEST['page']) : 1;
             $pager =& new FAPaginator($_URL, $num_results, $page, $perpage);
             if ($num_results > $perpage) {
                 $request['template']->setPager('topics_pager', $pager);
                 /* Create a friendly url for our pager jump */
                 $page_jumper = new FAUrl($_URL->__toString());
                 $page_jumper->args['limit'] = $perpage;
                 $page_jumper->args['page'] = FALSE;
                 $page_jumper->anchor = FALSE;
                 $request['template']->setVar('pagejumper_url', preg_replace('~&amp;~i', '&', $page_jumper->__toString()));
             }
             /* Get the topics for this forum */
             $daysprune = $_daysprune = isset($_REQUEST['daysprune']) && ctype_digit($_REQUEST['daysprune']) ? $_REQUEST['daysprune'] == 0 ? 0 : intval($_REQUEST['daysprune']) : 365;
             $daysprune = $daysprune > 0 ? time() - @($daysprune * 86400) : 0;
             $sortorder = isset($_REQUEST['order']) && ($_REQUEST['order'] == 'ASC' || $_REQUEST['order'] == 'DESC') ? $_REQUEST['order'] : 'DESC';
             $sortedby = isset($_REQUEST['sort']) && in_array($_REQUEST['sort'], $sort_orders) ? $_REQUEST['sort'] : 'lastpost_created';
             $start = ($page - 1) * $perpage;
             /* Apply the directional arrow to the sorting of topics */
             $request['template']->setVar('order', $sortorder == 'DESC' ? 'ASC' : 'DESC');
             $image = '<img src="Images/' . $request['template']->getVar('IMG_DIR') . '/Icons/arrow_' . ($sortorder == 'DESC' ? 'down' : 'up') . '.gif" alt="" border="0" />';
             $request['template']->setVar($sortedby . '_sort', $image);
             /* If there are no topics, set the right message to display */
             if ($forum['topics'] <= 0) {
                 $request['template']->setVisibility('no_topics', TRUE);
                 $request['template']->setVar('topics_message', $daysprune == 0 ? $request['template']->getVar('L_NOPOSTSINFORUM') : sprintf($request['template']->getVar('L_FORUMNOPOSTSSINCE'), $_daysprune));
             }
             if ($forum['topics'] + $extra_topics > 0 || $forum['row_type'] > GALLERY) {
                 /**
                  * Moderator Functions
                  */
                 $extra = 'AND queue = 0';
                 $request['template']->setVar('modpanel', 0);
                 /* is this user a moderator */
                 if (is_moderator($request['user']->getInfoArray(), $forum) && $forum['row_type'] <= GALLERY) {
                     $request['template']->setVar('modpanel', 1);
                     if (isset($_REQUEST['queued']) || isset($_REQUEST['locked'])) {
                         if (isset($_REQUEST['queued'])) {
                             $extra = 'AND queue = 1';
                         } elseif (isset($_REQUEST['locked'])) {
                             $extra = ' AND queue = 0 AND post_locked = 1';
                         }
                     }
                 }
                 /**
                  * Topic Setting
                  */
                 /* Make our query */
                 $query = "SELECT * FROM " . K4POSTS . " WHERE created>={$daysprune} AND is_draft=0 AND display=1 AND row_type=" . TOPIC . " AND forum_id=" . intval($forum['forum_id']) . " AND (post_type <> " . TOPIC_ANNOUNCE . " AND post_type <> " . TOPIC_STICKY . " AND is_feature = 0) {$extra} ORDER BY {$sortedby} {$sortorder} LIMIT {$start},{$perpage}";
                 if ($forum['row_type'] & METAFORUM) {
                     global $_FILTERS, $_FORUMFILTERS;
                     $query = "SELECT * FROM " . K4POSTS . " WHERE row_type=" . TOPIC . " AND forum_id<>" . GARBAGE_BIN . " ";
                     // loop through the filters being applied to this forum
                     $forum_filters = array();
                     if (isset($_FORUMFILTERS[$forum['forum_id']])) {
                         foreach ($_FORUMFILTERS[$forum['forum_id']] as $forum_filter) {
                             if (isset($_FILTERS[$forum_filter['filter_id']])) {
                                 $forum_filters[] = array('name' => $_FILTERS[$forum_filter['filter_id']]['filter_name']);
                                 $query .= " AND " . sprintf($_FILTERS[$forum_filter['filter_id']]['filter_query'], $request['dba']->quote($forum_filter['insert1']), $request['dba']->quote($forum_filter['insert2']), $request['dba']->quote($forum_filter['insert3'])) . " ";
                             }
                         }
                     }
                     $request['template']->setList('forum_filters', new FAArrayIterator($forum_filters));
                     $query .= " {$extra} ORDER BY {$sortedby} {$sortorder} LIMIT {$start},{$perpage}";
                     $query = str_replace('**', '%', $query);
                 }
                 /* get the topics */
                 $result = $request['dba']->executeQuery($query);
                 /* Apply the topics iterator */
                 $it =& new TopicsIterator($request['dba'], $request['user'], $result, $request['template']->getVar('IMG_DIR'), $forum);
                 $request['template']->setList('topics', $it);
                 // let's just make sure..
                 if ($result->hasNext()) {
                     $request['template']->setVisibility('no_topics', FALSE);
                 }
                 if ($forum['row_type'] <= GALLERY) {
                     /**
                      * Get announcement/global topics
                      */
                     if ($page == 1) {
                         $announcements = $request['dba']->executeQuery("SELECT * FROM " . K4POSTS . " WHERE (is_draft=0 AND display=1) AND row_type=" . TOPIC . " AND post_type = " . TOPIC_ANNOUNCE . " AND (forum_id = " . intval($forum['forum_id']) . " OR forum_id = " . GLBL_ANNOUNCEMENTS . ") {$extra} ORDER BY lastpost_created DESC");
                         if ($announcements->hasNext()) {
                             $a_it =& new TopicsIterator($request['dba'], $request['user'], $announcements, $request['template']->getVar('IMG_DIR'), $forum);
                             $request['template']->setList('announcements', $a_it);
                         }
                     }
                     /**
                      * Get sticky/feature topics
                      */
                     $importants = $request['dba']->executeQuery("SELECT * FROM " . K4POSTS . " WHERE is_draft=0 AND row_type=" . TOPIC . " AND display = 1 AND forum_id = " . intval($forum['forum_id']) . " AND (post_type <> " . TOPIC_ANNOUNCE . ") AND (post_type = " . TOPIC_STICKY . " OR is_feature = 1) {$extra} ORDER BY lastpost_created DESC");
                     if ($importants->hasNext()) {
                         $i_it =& new TopicsIterator($request['dba'], $request['user'], $importants, $request['template']->getVar('IMG_DIR'), $forum);
                         $request['template']->setList('importants', $i_it);
                     }
                 }
                 /* Outside valid page range, redirect */
                 if (!$pager->hasPage($page) && $num_pages > 0) {
                     $action = new K4InformationAction(new K4LanguageElement('L_PASTPAGELIMIT'), 'content', FALSE, 'viewforum.php?f=' . $forum['forum_id'] . '&limit=' . $perpage . '&page=' . $num_pages, 3);
                     return $action->execute($request);
                 }
             }
             /**
              * Forum Subscriptions
              */
             if ($request['user']->isMember() && $forum['topics'] > 0) {
                 $subscribed = $request['dba']->executeQuery("SELECT * FROM " . K4SUBSCRIPTIONS . " WHERE forum_id = " . intval($forum['forum_id']) . " AND post_id = 0 AND user_id = " . $request['user']->get('id'));
                 $request['template']->setVar('is_subscribed', $subscribed->numRows() > 0 ? 1 : 0);
             }
             /**
              *
              * GALLERY
              *
              */
         } else {
             if ($forum['row_type'] & GALLERY) {
                 $request['template']->setFile('content', 'viewgallery.html');
                 /**
                  *
                  * ERROR
                  *
                  */
             } else {
                 $action = new K4InformationAction(new K4LanguageElement('L_FORUMDOESNTEXIST'), 'content', FALSE);
                 return $action->execute($request);
             }
         }
     }
     /**
      * Can we post in here?
      */
     $can_post_in_forum = 1;
     if ($forum['forum_id'] == GARBAGE_BIN || $forum['row_type'] > GALLERY) {
         $can_post_in_forum = 0;
     }
     $request['template']->setVar('can_post_in_forum', $can_post_in_forum);
     // urls
     $request['template']->setVar('U_FORUMRSSURL', K4Url::getGenUrl('rss', 'f=' . $forum['forum_id']));
     /* Add the cookies for this forum's topics */
     bb_execute_topiccache();
     // show the midsection of the forum
     $request['template']->setVisibility('forum_midsection', TRUE);
     return TRUE;
 }
 function current()
 {
     $temp = parent::current();
     /* Cache this forum in the session */
     cache_forum($temp);
     /**
      * Do the icon
      */
     switch ($temp['row_type']) {
         case FORUM:
             $temp['forum_icon'] = 'forum_off';
             forum_icon($temp, $temp['forum_icon']);
             break;
         case GALLERY:
             $temp['forum_icon'] = 'forum_gallery';
             break;
         case METAFORUM:
             $temp['forum_icon'] = 'forum_meta';
             break;
         case ARCHIVEFORUM:
             $temp['forum_icon'] = 'forum_archive';
             break;
     }
     /* Set a nice representation of what level we're on */
     $temp['level'] = @str_repeat('&nbsp;&nbsp;&nbsp;', $this->level);
     /* Should we query down to the next level of forums? */
     if ($temp['row_type'] & CATEGORY) {
         $temp['forums'] =& new K4ForumsIterator($this->dba, "SELECT * FROM " . K4FORUMS . " WHERE parent_id = " . $temp['forum_id'] . " ORDER BY row_order ASC", TRUE, $this->level + 1);
     }
     if ($this->do_recurse) {
         if ($temp['subforums'] > 0 && $this->settings['showsubforums'] == 1) {
             $it = new K4ForumsIterator($this->dba, "SELECT * FROM " . K4FORUMS . " WHERE parent_id = " . intval($temp['forum_id']) . " ORDER BY row_order ASC", FALSE, $this->level + 1);
             if ($it->hasNext()) {
                 // add the iterator
                 $temp['subforums_list'] = $it;
             } else {
                 // if this forum doesn't actually have subforums, fix it
                 $this->dba->executeUpdate("UPDATE " . K4FORUMS . " SET subforums=0 WHERE forum_id = " . intval($temp['forum_id']));
             }
         }
     }
     /**
      * Get the moderators
      */
     $temp['moderators'] = array();
     $temp['are_moderators'] = 0;
     if ($temp['moderating_groups'] != '') {
         $groups = explode('|', $temp['moderating_groups']);
         if (is_array($groups)) {
             foreach ($groups as $g) {
                 if (isset($this->usergroups[$g])) {
                     $temp['U_USERGROUPURL'] = K4Url::getUserGroupUrl($g);
                     $temp['moderators'][] = $this->usergroups[$g];
                 }
             }
             $temp['are_moderators'] = 1;
         }
     }
     if ($temp['moderating_users'] != '') {
         $users = force_unserialize($temp['moderating_users']);
         if (is_array($users) && !empty($users)) {
             foreach ($users as $user_id => $username) {
                 $temp['U_GMEMBERURL'] = K4Url::getMemberUrl($user_id);
                 $temp['moderators'][] = array('user_id' => $user_id, 'name' => $username);
             }
             $temp['are_moderators'] = 1;
         }
     }
     $temp['moderators'] =& new FAArrayIterator($temp['moderators']);
     /* Replace topic/post names with censors */
     replace_censors($temp['topic_name']);
     replace_censors($temp['post_name']);
     $temp['topics'] = number_format($temp['topics']);
     $temp['replies'] = number_format($temp['replies']);
     $temp['posts'] = number_format($temp['posts']);
     //		/* Set cookies for all of the topics */
     //		bb_settopic_cache_item('forums', serialize($this->forums), time() + 3600 * 25 * 5);
     $temp['safe_description'] = strip_tags($temp['description']);
     $temp['forum'] = $temp['row_type'] == CATEGORY ? 0 : 1;
     // custom url's
     $temp['U_FORUMURL'] = K4Url::getForumUrl($temp['forum_id']);
     $temp['U_TOPICURL'] = K4Url::getTopicUrl($temp['post_id']);
     $temp['U_POSTURL'] = K4Url::getPostUrl($temp['post_id']);
     $temp['U_FINDPOSTURL'] = K4Url::getPostUrl($temp['post_id']);
     $temp['U_MEMBERURL'] = K4Url::getMemberUrl($temp['post_uid']);
     $temp['U_REDIRECTURL'] = K4Url::getRedirectUrl($temp['forum_id']);
     /* Return the formatted forum info */
     return $temp;
 }
Example #11
0
 function current()
 {
     $temp = parent::current();
     $temp['posticon'] = isset($temp['posticon']) && @$temp['posticon'] != '' ? file_exists(BB_BASE_DIR . '/tmp/upload/posticons/' . @$temp['posticon']) ? @$temp['posticon'] : 'clear.gif' : 'clear.gif';
     if ($temp['poster_id'] > 0) {
         if (!isset($this->users[$temp['poster_id']])) {
             $temp['post_display_user_ddmenu'] = 1;
             // display a ddmenu
             $user = $this->dba->getRow("SELECT " . $this->qp['user'] . $this->qp['userinfo'] . " FROM " . K4USERS . " u LEFT JOIN " . K4USERINFO . " ui ON u.id=ui.user_id WHERE u.id=" . intval($temp['poster_id']));
             if (is_array($user) && !empty($user)) {
                 $group = get_user_max_group($user, $this->groups);
                 $user['group_color'] = !isset($group['color']) || $group['color'] == '' ? '000000' : $group['color'];
                 $user['group_nicename'] = $group['nicename'];
                 $user['group_avatar'] = $group['avatar'];
                 $user['online'] = time() - ini_get('session.gc_maxlifetime') > $user['seen'] ? 'offline' : 'online';
                 $this->users[$user['id']] = $user;
             }
         } else {
             $temp['post_display_user_ddmenu'] = $this->result->hasPrev() ? 0 : 1;
             // use a different ddmenu
             $user = $this->users[$temp['poster_id']];
         }
         if (is_array($user) && !empty($user)) {
             if ($user['flag_level'] > 0 && $_SESSION['user']->get('perms') >= MODERATOR) {
                 $temp['post_user_background'] = 'background-color: #FFFF00;';
             }
             foreach ($user as $key => $val) {
                 $temp['post_user_' . $key] = $val;
             }
             $temp['profilefields'] = new FAArrayIterator(get_profile_fields($this->fields, $temp));
             $temp['post_user_title'] = $user['user_title'];
             $temp['post_user_user_title'] = get_user_title($user['user_title'], $user['num_posts']);
         }
         if (!isset($temp['post_user_online'])) {
             $temp['post_user_online'] = 'offline';
         }
     } else {
         $temp['post_user_id'] = 0;
         $temp['post_user_name'] = $temp['poster_name'];
     }
     /* do we have any attachments? */
     if (isset($temp['attachments']) && $temp['attachments'] > 0) {
         $temp['attachment_files'] = new K4AttachmentsIterator($this->dba, $this->user, $temp['post_id']);
     }
     /* Deal with acronyms */
     replace_acronyms($temp['body_text']);
     /* word censors!! */
     replace_censors($temp['body_text']);
     replace_censors($temp['name']);
     /* Do any polls if they exist */
     do_post_polls($temp, $this->dba);
     // url's
     $temp['U_TOPICURL'] = K4Url::getTopicUrl($temp['post_id']);
     $temp['U_POSTURL'] = K4Url::getPostUrl($temp['post_id']);
     $temp['U_MEMBERURL'] = K4Url::getMemberUrl($temp['poster_id']);
     return $temp;
 }
Example #12
0
function follow_faqc_ids($breadcrumbs, $category)
{
    $category['location'] = K4Url::getGenUrl('faq', 'c=' . $category['category_id']);
    $breadcrumbs[] = $category;
    if (isset($category['parent_id']) && $category['parent_id'] > 0) {
        global $_FAQCATEGORIES;
        $breadcrumbs = follow_faqc_ids($breadcrumbs, $_FAQCATEGORIES[$category['parent_id']]);
    }
    return $breadcrumbs;
}
Example #13
0
 function __construct($template)
 {
     global $_URL;
     parent::__construct();
     $request = $this->getRequest();
     $request['load_timer'] =& new FATimer(3);
     $request['template'] =& new K4Template();
     // request filters
     $this->addFilter(new K4RequestFilter());
     // Open our database
     $this->addFilter(new K4DatabaseFilter());
     // cache filters
     $this->addFilter(new K4GeneralCacheFilter());
     // general filters
     $this->addFilter(new K4SessionFilter());
     $this->addFilter(new K4UserFilter());
     $this->addFilter(new K4LanguageFilter());
     $this->addFilter(new K4BannedUsersFilter());
     $this->addFilter(new K4LoginFilter());
     $this->addFilter(new K4LogoutFilter());
     $this->addFilter(new K4TemplateFilter($template));
     $this->addFilter(new K4ServerLoadFilter());
     // general template info
     $this->addFilter(new K4GeneralInformation());
     // SQL debugging filters
     $this->addFilter(new K4SqlDebugPreFilter());
     $this->addFilter(new K4SqlDebugPostFilter());
     // Mass emailer filter
     $this->addFilter(new K4MassMailFilter());
     // Board closed filter
     $this->addFilter(new K4CloseBoardFilter());
     // Search result destroyer
     $this->addFilter(new K4SearchDestroyerFilter());
     // invalid action
     $this->setInvalidAction(new K4InformationAction(new K4LanguageElement('L_PAGEDOESNTEXIST'), 'content', TRUE));
     /**
      * Set some important template variables
      */
     $request['template']->setVar('load_time', $request['load_timer']->__toString());
     $url =& new FAUrl($_URL->__toString());
     $request['template']->setVar('curr_url', $url->__toString());
     $url->args = array();
     $url->anchor = $url->file = FALSE;
     $request['template']->setVar('forum_url', $url->__toString());
     $request['template']->setVar('style_cellspacing', K4_TABLE_CELLSPACING);
     $request['template']->setVarArray(array('quicklinks' => 'quicklinks', 'modcp' => 'modcp'));
     $request['template']->setVar('nojs', isset($url->args['nojs']) && intval($url->args['nojs']) == 1 ? 1 : 0);
     $request['template']->setVar('anchor', isset($url->anchor) && $url->anchor != '' ? $url->anchor : '');
     $request['template']->setVar('domain', get_domain());
     $request['template']->setVar('garbage_bin_id', GARBAGE_BIN);
     // custom url's
     $request['template']->setVarArray(array('U_INDEXURL' => K4Url::getGenUrl('index', ''), 'U_MEMBERLISTURL' => K4Url::getGenUrl('member', 'act=list&amp;start=0&amp;limit=30&amp;letter=*'), 'U_FAQURL' => K4Url::getGenUrl('faq', ''), 'U_MARKFORUMSURL' => K4Url::getGenUrl('index', 'act=markforums'), 'U_RSSNEWPOSTSURL' => K4Url::getGenUrl('rss', 'act=new_posts'), 'U_FORGOTPWURL' => K4Url::getGenUrl('member', 'act=forgotpw'), 'U_RESENDMAILURL' => K4Url::getGenUrl('member', 'act=resendemail'), 'U_REGISTERURL' => K4Url::getGenUrl('member', 'act=register')));
     $this->setRequest($request);
     return TRUE;
 }
Example #14
0
 function execute(&$request)
 {
     global $_QUERYPARAMS, $_USERGROUPS, $_URL;
     /* set the breadcrumbs bit */
     k4_bread_crumbs($request['template'], $request['dba'], 'L_INFORMATION');
     /**
      * Error Checking
      */
     if (!isset($_REQUEST['id']) || !$_REQUEST['id'] || intval($_REQUEST['id']) == 0) {
         $action = new K4InformationAction(new K4LanguageElement('L_TOPICDOESNTEXIST'), 'content', FALSE);
         return $action->execute($request);
     }
     /* Get our topic */
     $topic = $request['dba']->getRow("SELECT * FROM " . K4POSTS . " WHERE post_id = " . intval($_REQUEST['id']));
     if (!$topic || !is_array($topic) || empty($topic)) {
         $action = new K4InformationAction(new K4LanguageElement('L_TOPICDOESNTEXIST'), 'content', FALSE);
         return $action->execute($request);
     }
     /* Should we redirect this user? */
     if ($topic['moved_new_post_id'] > 0) {
         header("Location: viewtopic.php?id=" . intval($topic['moved_new_post_id']));
     }
     /* Get the current forum */
     $forum = $request['dba']->getRow("SELECT * FROM " . K4FORUMS . " WHERE forum_id = " . intval($topic['forum_id']));
     if (!$forum || !is_array($forum) || empty($forum)) {
         $action = new K4InformationAction(new K4LanguageElement('L_FORUMDOESNTEXIST'), 'content', FALSE);
         return $action->execute($request);
     }
     if ($topic['is_draft'] == 1) {
         $action = new K4InformationAction(new K4LanguageElement('L_CANTVIEWDRAFT'), 'content', FALSE);
         return $action->execute($request);
     }
     if (get_map('forums', 'can_view', array()) > $request['user']->get('perms') || get_map('topics', 'can_view', array('forum_id' => $forum['forum_id'])) > $request['user']->get('perms')) {
         $action = new K4InformationAction(new K4LanguageElement('L_PERMCANTVIEWTOPIC'), 'content', FALSE);
         return $action->execute($request);
     }
     // get the page number up here, the header call needs it!
     // this is also used down below for pagination
     $page = isset($_REQUEST['page']) && ctype_digit($_REQUEST['page']) && intval($_REQUEST['page']) > 0 ? intval($_REQUEST['page']) : 1;
     /**
      * Are we in an archive??
      */
     if ($forum['row_type'] & ARCHIVEFORUM) {
         if (!file_exists(BB_BASE_DIR . '/archive/' . intval($forum['forum_id']) . '/' . intval($topic['post_id']) . '-' . $page . '.xml')) {
             $archiver = new k4Archiver();
             $archiver->archiveTopicXML($request, $forum, $topic);
         }
         // redirect us!
         header("Location: archive.php?forum=" . intval($forum['forum_id']) . "&topic=" . intval($topic['post_id']) . "&page=" . $page);
         exit;
     }
     /**
      * Moderator functions
      */
     $request['template']->setVar('modpanel', 0);
     $moderator = FALSE;
     if (is_moderator($request['user']->getInfoArray(), $forum)) {
         $request['template']->setVar('modpanel', 1);
         $moderator = TRUE;
     }
     /**
      * More error checking
      */
     if ($topic['queue'] == 1 && !$moderator) {
         $action = new K4InformationAction(new K4LanguageElement('L_TOPICPENDINGMOD'), 'content', FALSE);
         return $action->execute($request);
     }
     if ($topic['display'] == 0 && !$moderator) {
         $action = new K4InformationAction(new K4LanguageElement('L_TOPICISHIDDEN'), 'content', FALSE);
         return $action->execute($request);
     }
     /**
      * This sets the last time that we've seen this forum
      */
     $cookieinfo = get_forum_cookies();
     $cookieinfo[$forum['forum_id']] = time();
     $cookiestr = '';
     foreach ($cookieinfo as $key => $val) {
         $cookiestr .= ',' . $key . ',' . intval($val);
     }
     $domain = get_domain();
     setcookie(K4FORUMINFO, trim($cookiestr, ','), time() + 2592000, $domain);
     unset($cookieinfo, $cookiestr);
     $cookieinfo = get_topic_cookies();
     /**
      * Set the new breadcrumbs bit
      */
     k4_bread_crumbs($request['template'], $request['dba'], $topic['name'], $forum);
     /* Set if this breadcrumb should be 'new' or not */
     $new = topic_icon($cookieinfo, $topic, '');
     $request['template']->setVar('breadcrumb_new', $new == TRUE ? 'new' : '');
     /**
      * Now tell the cookies that we've read this topic
      */
     $cookieinfo[$topic['post_id']] = time();
     $cookiestr = '';
     foreach ($cookieinfo as $key => $val) {
         // make sure to weed out 30-day old topic views
         if ((time() - intval($val)) / 30 <= 2592000) {
             $cookiestr .= ',' . $key . ',' . intval($val);
         }
     }
     setcookie(K4TOPICINFO, trim($cookiestr, ','), time() + 2592000, $domain);
     unset($cookieinfo, $cookiestr);
     /** 
      * Get the users Browsing this topic 
      */
     /* Set the extra SQL query fields to check */
     $extra = " AND location_file = '" . $request['dba']->quote($_URL->file) . "' AND location_id = " . intval($topic['post_id']);
     $expired = time() - ini_get('session.gc_maxlifetime');
     $user_extra = $request['user']->isMember() ? ' OR (seen > 0 AND user_id = ' . intval($request['user']->get('id')) . ')' : '';
     $num_online_total = $request['dba']->getValue("SELECT COUNT(id) FROM " . K4SESSIONS . " WHERE ((seen >= {$expired} {$extra}) {$user_extra})");
     $num_online_total = !$request['user']->isMember() ? $num_online_total + 1 : $num_online_total;
     if ($num_online_total > 0) {
         $query = "SELECT * FROM " . K4SESSIONS . " WHERE ((seen >= {$expired} {$extra}) {$user_extra}) AND ((user_id > 0) OR (user_id = 0 AND name <> '')) GROUP BY name ORDER BY seen DESC";
         $users_browsing =& new K4OnlineUsersIterator($request['dba'], '', $request['dba']->executeQuery($query));
         /* Set the users browsing list */
         $request['template']->setList('users_browsing', $users_browsing);
         $stats = array('num_online_members' => Globals::getGlobal('num_online_members'), 'num_invisible' => Globals::getGlobal('num_online_invisible'), 'num_online_total' => $num_online_total);
         $stats['num_guests'] = $stats['num_online_total'] - $stats['num_online_members'] - $stats['num_invisible'];
         $request['template']->setVar('num_online_members', $stats['num_online_members']);
         $request['template']->setVar('users_browsing', $request['template']->getVar('L_USERSBROWSINGTOPIC'));
         $request['template']->setVar('online_stats', sprintf($request['template']->getVar('L_USERSBROWSINGSTATS'), $stats['num_online_total'], $stats['num_online_members'], $stats['num_guests'], $stats['num_invisible']));
         /* Set the User's Browsing file */
         $request['template']->setFile('users_browsing', 'users_browsing.html');
         $groups = array();
         /* Set the usergroups legend list */
         foreach ($_USERGROUPS as $group) {
             if ($group['display_legend'] == 1) {
                 $groups[] = $group;
             }
         }
         $groups =& new FAArrayIterator($groups);
         $request['template']->setList('usergroups_legend', $groups);
     }
     /**
      * Is this topic expired?
      */
     $extra = '';
     if ($topic['post_type'] > TOPIC_NORMAL && $topic['post_expire'] > 0) {
         if ($topic['created'] + 3600 * 24 * $topic['post_expire'] > time()) {
             $extra = ",post_expire=0,post_type=" . TOPIC_NORMAL;
         }
     }
     /* Add the topic info to the template */
     foreach ($topic as $key => $val) {
         $request['template']->setVar('topic_' . $key, $val);
     }
     /* Add the forum info to the template */
     foreach ($forum as $key => $val) {
         $request['template']->setVar('forum_' . $key, $val);
     }
     /* Update the number of views for this topic */
     $request['dba']->executeUpdate("UPDATE " . K4POSTS . " SET views=views+1 {$extra} WHERE post_id=" . intval($topic['post_id']));
     $resultsperpage = $request['user']->get('postsperpage') <= 0 ? $forum['postsperpage'] : $request['user']->get('postsperpage');
     $num_results = $topic['num_replies'];
     $perpage = isset($_REQUEST['limit']) && ctype_digit($_REQUEST['limit']) && intval($_REQUEST['limit']) > 0 ? intval($_REQUEST['limit']) : $resultsperpage;
     $perpage = $perpage > 50 ? 50 : $perpage;
     $num_pages = @ceil($num_results / $perpage);
     // the $page is set above so that the archive options can use it ;)
     $request['template']->setVar('page', $page);
     $url =& new FAUrl($_URL->__toString());
     $pager =& new FAPaginator($url, $num_results, $page, $perpage);
     if ($num_results > $perpage) {
         $request['template']->setPager('replies_pager', $pager);
         /* Create a friendly url for our pager jump */
         $page_jumper = $url;
         $page_jumper->args['limit'] = $perpage;
         $page_jumper->args['page'] = FALSE;
         $page_jumper->anchor = FALSE;
         $request['template']->setVar('pagejumper_url', preg_replace('~&amp;~i', '&', $page_jumper->__toString()));
     }
     /* Outside valid page range, redirect */
     if (!$pager->hasPage($page) && $num_pages > 0) {
         $action = new K4InformationAction(new K4LanguageElement('L_PASTPAGELIMIT'), 'content', FALSE, 'viewtopic.php?id=' . $topic['post_id'] . '&limit=' . $perpage . '&page=' . $num_pages, 3);
         return $action->execute($request);
     }
     $sort_orders = array('name', 'created', 'id', 'poster_name');
     /* Get the replies for this topic */
     $topic['daysprune'] = isset($_REQUEST['daysprune']) && ctype_digit($_REQUEST['daysprune']) ? iif($_REQUEST['daysprune'] == -1, 0, intval($_REQUEST['daysprune'])) : 0;
     $topic['sortorder'] = isset($_REQUEST['order']) && ($_REQUEST['order'] == 'ASC' || $_REQUEST['order'] == 'DESC') ? $_REQUEST['order'] : 'ASC';
     $topic['sortedby'] = isset($_REQUEST['sort']) && in_array($_REQUEST['sort'], $sort_orders) ? $_REQUEST['sort'] : 'created';
     $topic['start'] = ($page - 1) * $perpage;
     $topic['postsperpage'] = $perpage;
     /* Do we set the similar topics? */
     $similar_topics = $request['dba']->executeQuery("SELECT * FROM " . K4POSTS . " WHERE ((lower(name) LIKE lower('%" . $request['dba']->quote($topic['name']) . "%') OR lower(name) LIKE lower('%" . $request['dba']->quote($topic['body_text']) . "%')) OR (lower(body_text) LIKE lower('%" . $request['dba']->quote($topic['name']) . "%') OR lower(body_text) LIKE lower('%" . $request['dba']->quote($topic['body_text']) . "%'))) AND row_type=" . TOPIC . " AND is_draft = 0 AND post_id <> " . intval($topic['post_id']) . " ORDER BY lastpost_created DESC LIMIT 10");
     if ($similar_topics->hasNext()) {
         //$it = new PostsIterator($request, $similar_topics);
         $it =& new TopicsIterator($request['dba'], $request['user'], $similar_topics, $request['template']->getVar('IMG_DIR'), $forum);
         $request['template']->setList('similar_topics', $it);
         $request['template']->setFile('similar_topics', 'similar_topics.html');
     }
     /* Do we show the replies or show the threaded view? */
     $show_replies = $request['user']->get('topic_threaded') == 1 ? FALSE : TRUE;
     $show_replies = $request['user']->get('topic_threaded') == 1 && isset($_REQUEST['p']) && intval($_REQUEST['p']) > 0 ? TRUE : $show_replies;
     $single_reply = $request['user']->get('topic_threaded') == 1 && isset($_REQUEST['p']) && intval($_REQUEST['p']) > 0 ? intval($_REQUEST['p']) : FALSE;
     /* set the topic iterator */
     //$topic_list			= new TopicIterator($request['dba'], $request['user'], $topic, $show_replies, $single_reply);
     $result = $request['dba']->executeQuery("SELECT * FROM " . K4POSTS . " WHERE (" . ($page <= 1 ? "post_id=" . $topic['post_id'] . " OR" : '') . " (parent_id=" . intval($topic['post_id']) . " AND row_level>1)) AND created >= " . 3600 * 24 * intval($topic['daysprune']) . " ORDER BY " . $topic['sortedby'] . " " . $topic['sortorder'] . " LIMIT " . intval($topic['start']) . "," . intval($topic['postsperpage']));
     $posts = new PostsIterator($request, $result);
     $request['template']->setList('posts', $posts);
     $request['template']->setVar('next_oldest', intval($request['dba']->getValue("SELECT post_id FROM " . K4POSTS . " WHERE post_id < " . $topic['post_id'] . " LIMIT 1")));
     $request['template']->setVar('next_newest', intval($request['dba']->getValue("SELECT post_id FROM " . K4POSTS . " WHERE post_id > " . $topic['post_id'] . " LIMIT 1")));
     /* Show the threaded view if necessary */
     if ($request['user']->get('topic_threaded') == 1) {
         if ($topic['num_replies'] > 0) {
             $request['template']->setFile('topic_threaded', 'topic_threaded.html');
             $replies = $request['dba']->executeQuery("SELECT * FROM " . K4POSTS . " WHERE parent_id=" . intval($topic['post_id']) . " AND row_level>1 ORDER BY row_order ASC");
             $it =& new ThreadedRepliesIterator($replies, $topic['row_level']);
             $request['template']->setList('threaded_replies', $it);
         }
     }
     /**
      * Topic subscription stuff
      */
     if ($request['user']->isMember()) {
         $subscribed = $request['dba']->executeQuery("SELECT * FROM " . K4SUBSCRIPTIONS . " WHERE post_id = " . intval($topic['post_id']) . " AND user_id = " . $request['user']->get('id'));
         $request['template']->setVar('is_subscribed', iif($subscribed->numRows() > 0, 1, 0));
     }
     /**
      * HTML toggling stuff
      */
     $topic_row = 0;
     $reply_row = 0;
     $perms = $request['user']->get('perms');
     if ($perms >= get_map('replies', 'can_add', array('forum_id' => $topic['forum_id'])) || $perms >= get_map('topics', 'can_edit', array('forum_id' => $topic['forum_id'])) || $perms >= get_map('topics', 'can_del', array('forum_id' => $topic['forum_id'])) || $perms >= get_map('other_topics', 'can_edit', array('forum_id' => $topic['forum_id'])) || $perms >= get_map('other_topics', 'can_del', array('forum_id' => $topic['forum_id']))) {
         $topic_row = 1;
     }
     if ($perms >= get_map('replies', 'can_add', array('forum_id' => $topic['forum_id'])) || $perms >= get_map('replies', 'can_edit', array('forum_id' => $topic['forum_id'])) || $perms >= get_map('replies', 'can_del', array('forum_id' => $topic['forum_id'])) || $perms >= get_map('other_replies', 'can_edit', array('forum_id' => $topic['forum_id'])) || $perms >= get_map('other_replies', 'can_del', array('forum_id' => $topic['forum_id']))) {
         $reply_row = 1;
     }
     $request['template']->setVar('topic_row', $topic_row);
     $request['template']->setVar('reply_row', $reply_row);
     $request['template']->setVar('newreply_act', K4Url::getGenUrl('newreply', 'act=postreply'));
     $request['template']->setVar('U_TOPICRSSURL', K4Url::getGenUrl('rss', 't=' . $topic['post_id']));
     /**
      * Topic display
      */
     $request['template']->setFile('topic_file', 'topic' . ($request['user']->get('topic_display') == 0 ? '' : '_linear') . '.html');
     $request['template']->setFile('reply_file', 'reply' . ($request['user']->get('topic_display') == 0 ? '' : '_linear') . '.html');
     /* Set the file we need */
     $request['template']->setVar('forum_forum_id', $forum['forum_id']);
     $request['template']->setFile('content', 'viewtopic.html');
     if (USE_WYSIWYG) {
         $request['template']->setList('emoticons', $request['dba']->executeQuery("SELECT * FROM " . K4EMOTICONS . " WHERE clickable = 1"));
         $request['template']->setVar('emoticons_per_row', $request['template']->getVar('smcolumns'));
         $request['template']->setVar('emoticons_per_row_remainder', $request['template']->getVar('smcolumns') - 1);
     }
     /* Create our editor for the quick reply */
     create_editor($request, '', 'quickreply', $forum);
     // show the midsection of the forum
     $request['template']->setVisibility('forum_midsection', TRUE);
     return TRUE;
 }
Example #15
0
 function execute(&$action, &$request)
 {
     global $_LANG;
     if (isset($_GET['logout'])) {
         // Ok, a logout attempt is being made
         k4_bread_crumbs($request['template'], $request['dba'], 'L_LOGOUT');
         $url =& new FAUrl($_SERVER['REQUEST_URI']);
         unset($url->args['logout']);
         if (!$request['user']->isMember()) {
             // Oops, trying to login when already logged in
             $action = new K4InformationAction(new K4LanguageElement('L_NEEDLOGGEDIN'), 'content');
         } else {
             k4_set_logout($request['dba'], $request['user']);
             // make sure we go to the right place!
             $logout_url = basename($url->__toString());
             if (strpos($logout_url, 'login') !== FALSE) {
                 $logout_url = K4Url::getGenUrl('index', '');
             }
             $action = new K4InformationAction(new K4LanguageElement('L_LOGGEDOUTSUCCESS'), 'content', FALSE, $logout_url, 3);
         }
     }
 }
Example #16
0
 function execute(&$request)
 {
     //$action = new AdminCSSRequestAction();
     //return $action->execute($request);
     global $_DATASTORE, $_USERGROUPS, $_QUERYPARAMS;
     // Member/Guest specifics
     if (!$request['user']->isMember()) {
         $request['template']->setVar('welcome_title', sprintf($request['template']->getVar('L_WELCOMETITLE'), $request['template']->getVar('bbtitle')));
         $request['template']->setFile('quick_login', 'login_form_quick.html');
         $request['template']->setVisibility('welcome_msg', TRUE);
     }
     // The content panel
     $request['template']->setFile('content', 'forums.html');
     $forums =& new K4ForumsIterator($request['dba'], "SELECT * FROM " . K4FORUMS . " WHERE parent_id=0 ORDER BY row_order ASC");
     //$categories	= &new K4ForumsIterator($request['dba'], "SELECT * FROM ". K4FORUMS ." WHERE row_type=". CATEGORY ." AND parent_id = 0 ORDER BY row_order ASC");
     $request['template']->setVisibility('no_forums', !$forums->hasNext() ? TRUE : FALSE);
     $request['template']->setList('tlforums', $forums);
     //$request['template']->setList('categories', $categories);
     // Set the online users list
     $user_extra = $request['user']->isMember() ? ' OR (seen > 0 AND user_id = ' . intval($request['user']->get('id')) . ')' : '';
     $expired = time() - ini_get('session.gc_maxlifetime');
     $online_users = $request['dba']->executeQuery("SELECT * FROM " . K4SESSIONS . " WHERE ((seen >= {$expired}) {$user_extra}) AND ((user_id > 0) OR (user_id = 0 AND name <> '')) GROUP BY name ORDER BY seen DESC");
     $online_users =& new K4OnlineUsersIterator($request['dba'], '', $online_users);
     $request['template']->setList('online_users', $online_users);
     //$newest_user						= $request['dba']->getRow("SELECT name, id FROM ". K4USERS ." ORDER BY id DESC LIMIT 1");
     $expired = time() - ini_get('session.gc_maxlifetime');
     //print_r($_DATASTORE); exit;
     $stats = array('num_online_members' => intval(Globals::getGlobal('num_online_members')), 'num_invisible' => intval(Globals::getGlobal('num_online_invisible')), 'num_topics' => intval($_DATASTORE['forumstats']['num_topics']), 'num_replies' => intval($_DATASTORE['forumstats']['num_replies']), 'num_members' => intval($_DATASTORE['forumstats']['num_members']), 'num_guests' => $request['dba']->getValue("SELECT COUNT(*) FROM " . K4SESSIONS . " WHERE seen >= {$expired} AND user_id=0"), 'newest_uid' => $_DATASTORE['forumstats']['newest_user_id'], 'newest_user' => $_DATASTORE['forumstats']['newest_user_name']);
     $stats['num_online_total'] = $stats['num_online_members'] + $stats['num_invisible'] + $stats['num_guests'];
     $request['template']->setVar('num_online_members', $stats['num_online_members']);
     $request['template']->setVar('newest_member', sprintf($request['template']->getVar('L_NEWESTMEMBER'), $stats['newest_uid'], $stats['newest_user']));
     $request['template']->setVar('total_users', sprintf($request['template']->getVar('L_TOTALUSERS'), $stats['num_members']));
     $request['template']->setVar('total_posts', sprintf($request['template']->getVar('L_TOTALPOSTS'), $stats['num_topics'] + $stats['num_replies'], $stats['num_topics'], $stats['num_replies']));
     $request['template']->setVar('online_stats', sprintf($request['template']->getVar('L_ONLINEUSERSTATS'), $stats['num_online_total'], $stats['num_online_members'], $stats['num_guests'], $stats['num_invisible']));
     $request['template']->setVar('most_users_ever', sprintf($request['template']->getVar('L_MOSTUSERSEVERONLINE'), $_DATASTORE['maxloggedin']['maxonline'], date("n/j/Y", bbtime($_DATASTORE['maxloggedin']['maxonlinedate'])), date("g:ia", bbtime($_DATASTORE['maxloggedin']['maxonlinedate']))));
     if ($stats['num_online_total'] >= $_DATASTORE['maxloggedin']['maxonline']) {
         $maxloggedin = array('maxonline' => $stats['num_online_total'], 'maxonlinedate' => time());
         $query = $request['dba']->prepareStatement("UPDATE " . K4DATASTORE . " SET data = ? WHERE varname = ?");
         $query->setString(1, serialize($maxloggedin));
         $query->setString(2, 'maxloggedin');
         $query->executeUpdate();
         reset_cache('datastore');
     }
     // Show the forum status icons
     $request['template']->setVisibility('forum_status_icons', TRUE);
     $request['template']->setFile('content_extra', 'forum_status_icons.html');
     if ($request['user']->get('perms') >= get_map('can_see_board', 'can_add', array())) {
         $request['template']->setVisibility('forum_midsection', TRUE);
         $groups = array();
         // Set the usergroups legend list
         if (is_array($_USERGROUPS) && !empty($_USERGROUPS)) {
             foreach ($_USERGROUPS as $group) {
                 if ($group['display_legend'] == 1) {
                     $group['U_USERGROUPURL'] = K4Url::getUserGroupUrl($group['id']);
                     $groups[] = $group;
                 }
             }
         }
     }
     $groups =& new FAArrayIterator($groups);
     $request['template']->setList('usergroups_legend', $groups);
     /* Set the forum stats */
     $request['template']->setFile('forum_info', 'forum_info.html');
     $request['template']->setVar('can_see_board', get_map('can_see_board', 'can_view', array()));
     k4_bread_crumbs($request['template'], $request['dba'], 'L_HOME');
 }