示例#1
0
/**
* k4 Bulletin Board, editor.php
*
* Copyright (c) 2005, Peter Goodman
*
* This library is free software; you can redistribute it and/orextension=php_gd2.dll
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
* 
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
* Lesser General Public License for more details.
* 
* Licensed under the LGPL license
* http://www.gnu.org/copyleft/lesser.html
*
* @author Peter Goodman
* @version $Id: k4_template.php 134 2005-06-25 15:41:13Z Peter Goodman $
* @package k4-2.0-dev
*/
function create_editor(&$request, $text, $place, $forum = FALSE)
{
    global $_LANG;
    $can_bbcode = 0;
    $request['template']->setVar('use_rteextras', 1);
    if (isset($place) && $place != '') {
        switch ($place) {
            case 'quickreply':
                $request['template']->setVar('use_rteextras', 0);
            case 'post':
                $can_bbcode = $request['user']->get('perms') < get_map('bbcode', 'can_add', array('forum_id' => $forum['forum_id'])) ? 0 : 1;
                break;
            case 'signature':
                $can_bbcode = intval($request['template']->getVar('allowbbcodesignatures')) == 1 ? 1 : 0;
                break;
            case 'pm':
                $can_bbcode = intval($request['template']->getVar('privallowbbcode')) == 1 ? 1 : 0;
                break;
        }
    }
    $request['template']->setVar('has_bbcode_perms', $can_bbcode);
    $request['template']->setVar('editor_input_id', 'editor_area');
    $request['template']->setVar('use_wysiwyg', USE_WYSIWYG ? 1 : 0);
    $request['template']->setVar('use_bbcode', USE_WYSIWYG ? 0 : 1);
    $editor_text = USE_WYSIWYG ? '<br />' : '';
    if ($text != '') {
        $parser =& new BBParser();
        $editor_text = $parser->revert($text);
    }
    $request['template']->setVar('editor_text_reverted', $editor_text);
    $request['template']->setVar('editor_enabled', 1);
}
 /**
  * The function which calls everything from the controller
  * and render the template(s).
  * @param mixed template	The template variable, holds all current
  *							template information
  * @param mixed session		The session variable, holds all current
  *							session information
  * @return					method template render
  * @see Template
  * @see Session
  */
 function Execute(&$template)
 {
     global $_DBA, $_URL, $_SETTINGS;
     /**
      * General Variable Setting
      */
     /* Start the timer */
     $this->timer =& new Timer();
     /* Merge the post and get arrays */
     $request = array_merge($this->get, $this->post, $this->cookie);
     /* Strip annoying slashes on everything */
     foreach ($request as $key => $val) {
         if (!is_array($val)) {
             $request[$key] = stripslashes($val);
         }
     }
     $result = FALSE;
     /* Get the act var */
     $act_var = get_setting('application', 'action_var') or $act_var = 'act';
     /* get the session and user variables */
     $session =& $_SESSION;
     $user =& $_SESSION['user']->info;
     /**
      * Member/Guest Settings
      */
     /* Figure out which styleset, imageset and templateset to use */
     $styleset = is_a($session['user'], 'Member') && $user['styleset'] != '' || is_a($session['user'], 'Guest') && $user['styleset'] != '' ? $user['styleset'] : $template->getVar('styleset');
     $imageset = is_a($session['user'], 'Member') && $user['imgset'] != '' ? $user['imgset'] : $template->getVar('imageset');
     $templateset = is_a($session['user'], 'Member') && $user['tplset'] != '' ? $user['tplset'] : $template->getVar('templateset');
     /* Set the style, template and image sets */
     $this->template->setVar('css_styles', get_cached_styleset($styleset, $template->getVar('styleset')));
     $template_dir = FORUM_BASE_DIR . DIRECTORY_SEPARATOR . 'templates' . DIRECTORY_SEPARATOR;
     $imgs_dir = FORUM_BASE_DIR . DIRECTORY_SEPARATOR . 'Images' . DIRECTORY_SEPARATOR;
     /* Should we get the template set that goes with this styleset? */
     $templateset = is_dir($template_dir . $styleset) ? $template_dir . $styleset : $template_dir . $templateset;
     /* Should we get the image set that goes with this styleset? */
     $imageset = is_dir($imgs_dir . $styleset) ? $styleset : $imageset;
     /* Check to see if our templates directory exists */
     if (!is_dir($templateset)) {
         exit('Invalid template set for: ' . $templateset);
     }
     /* Check to see if our images directory exists */
     if (!is_dir($imgs_dir . $imageset)) {
         exit('Invalid image set for: ' . $imageset);
     }
     /* Set the template an image sets */
     $this->template->setDirname($templateset);
     $this->template->setVar('IMG_DIR', $imageset);
     /* Determine which language to get, and then include the appropriate file */
     $language = is_a($session['user'], 'Member') ? strtolower($user['language']) : strtolower(get_setting('application', 'lang'));
     /* Check to see if this is an invalid language file */
     if (!file_exists(FORUM_BASE_DIR . '/includes/lang/' . $language . '/lang.php')) {
         exit('Invalid Language file.');
     }
     /* Require the language file */
     include FORUM_BASE_DIR . '/includes/lang/' . $language . '/lang.php';
     /* Set the language variable to the template */
     $template->setVar('LANG', $language);
     global $lang;
     /* Check if the language function exists */
     if (!isset($lang) || !is_array($lang) || empty($lang)) {
         exit('Invalid Language file.');
     }
     /* Set the locale to which language we are using */
     setlocale(LC_ALL, $lang['locale']);
     /* Set the language array */
     $template->setVarArray($lang);
     /* Memory Saving */
     unset($lang);
     /**
      * Event Execution
      */
     if (get_map($user, 'can_see_board', 'can_view', array()) > $user['perms']) {
         /* This user doesn't have permission to see the bb */
         $template = BreadCrumbs($template, $template->getVar('L_INFORMATION'));
         $template->setInfo('content', $template->getVar('L_YOUNEEDPERMS'));
     } else {
         if (intval($_SETTINGS['bbactive']) == 0 && $user['perms'] < SUPERMOD) {
             /* The board is closed */
             $template = BreadCrumbs($template, $template->getVar('L_INFORMATION'));
             $template->setInfo('content', $_SETTINGS['bbclosedreason']);
         } else {
             /* get the result of our event call */
             if (isset($request[$act_var]) && isset($this->events[$request[$act_var]])) {
                 $result = $this->events[$request[$act_var]]->Execute(&$template, $request, &$_DBA, &$session, &$user);
             }
             /* If the result is false, execute our defaultevent class */
             if ($result == FALSE) {
                 $this->default->Execute(&$template, $request, &$_DBA, &$session, &$user);
             }
         }
     }
     /**
      * User Information
      */
     /* Clear the session and user variables */
     $session =& $_SESSION;
     $user =& $_SESSION['user']->info;
     /**
      * Filters
      */
     /* Apply each Filter to the request */
     for ($i = 0; $i < count($this->filters); $i++) {
         $this->filters[$i]->Execute(&$template, &$session, $this->cookie, $this->post, $this->get);
     }
     /* If the user is logged in, set all of his user info to the template */
     if (is_a($session['user'], 'Member')) {
         foreach ($user as $key => $val) {
             $this->template->setVar('user_' . $key, $val);
         }
     }
     /* Set the number of queries */
     $template->setVar('num_queries', $_DBA->num_queries);
     /* Set the Load time */
     $template->setVar('load_time', $this->timer->__toString());
     if (DEBUG_SQL) {
         $debug_url =& new Url($_URL->__toString());
         $debug_url->args['debug'] = 1;
         $template->setVar('debug_url', $debug_url->__toString());
         $template->show('sql_debug');
         if (isset($request['debug']) && $request['debug'] == 1) {
             /* Output our debugged SQL */
             debug_sql();
         }
     }
     /* Do the mail queue */
     execute_mail_queue();
     /* Do the topic queue */
     execute_topic_queue();
     /**
      * Render the template 
      */
     error::reset();
     $template->Render();
     if (error::grab()) {
         critical_error();
     }
 }
示例#3
0
 function Execute(&$template, $request, &$dba, &$session, &$user)
 {
     global $_QUERYPARAMS, $_DATASTORE, $_USERGROUPS;
     if (!isset($request['id']) || !$request['id'] || intval($request['id']) == 0) {
         /* set the breadcrumbs bit */
         $template = BreadCrumbs($template, $template->getVar('L_INVALIDTOPIC'));
         $template->setInfo('content', $template->getVar('L_TOPICDOESNTEXIST'), FALSE);
         return TRUE;
     }
     /* Get our topic */
     $topic = $dba->getRow("SELECT " . $_QUERYPARAMS['info'] . $_QUERYPARAMS['topic'] . " FROM " . TOPICS . " t LEFT JOIN " . INFO . " i ON t.topic_id = i.id WHERE i.id = " . intval($request['id']));
     if (!$topic || !is_array($topic) || empty($topic)) {
         /* set the breadcrumbs bit */
         $template = BreadCrumbs($template, $template->getVar('L_INVALIDTOPIC'));
         $template->setInfo('content', $template->getVar('L_TOPICDOESNTEXIST'), FALSE);
         return TRUE;
     }
     $forum = $dba->getRow("SELECT " . $_QUERYPARAMS['info'] . $_QUERYPARAMS['forum'] . " FROM " . FORUMS . " f LEFT JOIN " . INFO . " i ON f.forum_id = i.id WHERE i.id = " . intval($topic['forum_id']));
     /* Check the forum data given */
     if (!$forum || !is_array($forum) || empty($forum)) {
         /* set the breadcrumbs bit */
         $template = BreadCrumbs($template, $template->getVar('L_INVALIDFORUM'));
         $template->setInfo('content', $template->getVar('L_FORUMDOESNTEXIST'), FALSE);
         return TRUE;
     }
     /* Make sure the we are trying to delete from a forum */
     if (!($forum['row_type'] & FORUM)) {
         /* set the breadcrumbs bit */
         $template = BreadCrumbs($template, $template->getVar('L_INFORMATION'));
         $template->setInfo('content', $template->getVar('L_CANTDELFROMNONFORUM'), FALSE);
         return TRUE;
     }
     if (get_map($user, 'closed', 'can_add', array('forum_id' => $forum['id'])) > $user['perms']) {
         /* set the breadcrumbs bit */
         $template = BreadCrumbs($template, $template->getVar('L_INFORMATION'));
         $template->setInfo('content', $template->getVar('L_YOUNEEDPERMS'), FALSE);
         return TRUE;
     }
     /* set the breadcrumbs bit */
     $template = BreadCrumbs($template, $template->getVar('L_UNLOCKTOPIC'), $topic['row_left'], $topic['row_right']);
     /* Lock the topic */
     $lock =& $dba->prepareStatement("UPDATE " . TOPICS . " SET topic_locked=0 WHERE topic_id=?");
     $lock->setInt(1, $topic['id']);
     $lock->executeUpdate();
     /* Redirect the user */
     $template->setInfo('content', sprintf($template->getVar('L_UNLOCKEDTOPIC'), $topic['name']));
     $template->setRedirect('viewtopic.php?id=' . $topic['id'], 3);
     return TRUE;
 }
示例#4
0
    define("RANGE", 49);
    $range = (RANGE - 7) / 2;
    for ($x = $basic_x - $range; $x <= $basic_x + $range; $x = $x + 7) {
        for ($y = $basic_y - $range; $y <= $basic_y + $range; $y = $y + 7) {
            // xp=-124&yp=-54&s1.x=&s1.y=&s1=ok
            $postfields = "xp={$x}&yp={$y}&s1.x=&s1.y=&s1=ok";
            echo $postfields . "\n";
            $ch = my_curl_init();
            curl_setopt($ch, CURLOPT_URL, $url);
            curl_setopt($ch, CURLOPT_POST, 1);
            curl_setopt($ch, CURLOPT_POSTFIELDS, $postfields);
            curl_setopt($ch, CURLOPT_REFERER, $url);
            $result = curl_exec($ch);
            curl_close($ch);
            parse($result, $my_villages);
        }
    }
}
// ----------------------------------------------------------------------------
// Main
// ----------------------------------------------------------------------------
require_once 'common.php';
require_once 'db.php';
require_once 'attack_ac.php';
// load my villages
$my_villages = load_my_villages();
get_map(94, 28, $my_villages);
$sql = "delete from populations where `daystamp` < to_days(now()) - 5";
if (!mysql_query($sql)) {
    die(mysql_error());
}
示例#5
0
    unset($_SESSION['path_riskmaps']);
    unset($_SESSION['riskmap']);
}
$_SESSION['default_riskmap'] = $default_map;
$map = $_GET['map'] != '' ? $_GET['map'] : $default_map;
$map = $_GET['back_map'] != '' ? $_GET['back_map'] : $map;
if (empty($_GET['back_map'])) {
    $_SESSION['path_riskmaps'][$map] = $_SESSION['riskmap'] == '' ? $_SESSION['default_riskmap'] : $_SESSION['riskmap'];
}
$_SESSION['riskmap'] = $map;
$hide_others = 1;
ossim_valid($map, OSS_HEX, 'illegal:' . _('Map'));
if (ossim_error()) {
    die(ossim_error());
}
$map = get_map($conn, $map);
if (empty($map)) {
    echo ossim_error(_("You do not have any available map."), AV_NOTICE);
    exit;
}
$perms = array();
$query = "SELECT HEX(map) AS map, perm FROM risk_maps";
if ($result = $conn->Execute($query)) {
    while (!$result->EOF) {
        $perms[$result->fields['map']][$result->fields['perm']]++;
        $result->MoveNext();
    }
}
$query = "SELECT HEX(map) AS map, perm, name FROM risk_maps";
$result = $conn->Execute($query);
while (!$result->EOF) {
示例#6
0
function delete_map($conn, $id)
{
    ossim_valid($id, OSS_HEX, 'illegal:' . _('Map'));
    if (ossim_error()) {
        $info_error = "Error: " . ossim_get_error();
        ossim_clean_error();
        $return['error'] = TRUE;
        $return['msg'] = $info_error;
        return $return;
    }
    if (!is_map_editable($conn, $id)) {
        $return['error'] = TRUE;
        $return['msg'] = _("You do not have permission to edit this map");
        return $return;
    }
    $map_name = "map" . $id . ".jpg";
    if (getimagesize("maps/{$map_name}")) {
        unlink("maps/{$map_name}");
        //Deleting the indicators that appear in the map to be deleted.
        $query = "DELETE FROM risk_indicators WHERE map=unhex(?)";
        $params = array($id);
        $result = $conn->Execute($query, $params);
        //Deleting the indicator that are linking to the map to be deleted.
        $query = "DELETE FROM risk_indicators WHERE url='view.php?map={$id}'";
        $result = $conn->Execute($query);
        //Deleting the map.
        $query = "DELETE FROM risk_maps WHERE map=unhex(?)";
        $params = array($id);
        $result = $conn->Execute($query, $params);
        $config = new User_config($conn);
        $login = Session::get_session_user();
        $default_map = $config->get($login, "riskmap", 'simple', 'main');
        if (strcasecmp($default_map, $id) == 0) {
            $map = get_map($conn, '00000000000000000000000000000001');
            if (!empty($map)) {
                set_default_map($conn, $map);
            }
        }
        $return['error'] = FALSE;
        $return['msg'] = _("Map deleted successfully");
        return $return;
    }
    $return['error'] = TRUE;
    $return['msg'] = _("The map couldn't be deleted");
    return $return;
}
示例#7
0
    // 21x21 35x35 49x49
    define("RANGE", 35);
    $range = (RANGE - 7) / 2;
    for ($x = $basic_x - $range; $x <= $basic_x + $range; $x = $x + 7) {
        for ($y = $basic_y - $range; $y <= $basic_y + $range; $y = $y + 7) {
            // xp=-124&yp=-54&s1.x=&s1.y=&s1=ok
            $postfields = "xp={$x}&yp={$y}&s1.x=&s1.y=&s1=ok";
            echo $postfields . "\n";
            $ch = my_curl_init();
            curl_setopt($ch, CURLOPT_URL, $url);
            curl_setopt($ch, CURLOPT_POST, 1);
            curl_setopt($ch, CURLOPT_POSTFIELDS, $postfields);
            curl_setopt($ch, CURLOPT_REFERER, $url);
            $result = curl_exec($ch);
            curl_close($ch);
            parse($result, $my_villages);
        }
    }
}
// ----------------------------------------------------------------------------
// Main
// ----------------------------------------------------------------------------
require_once 'common.php';
require_once 'db.php';
// load my villages
$my_villages = load_my_villages();
get_map(-60, -64, $my_villages);
$sql = "delete from populations where `daystamp` < to_days(now()) - 5";
if (!mysql_query($sql)) {
    die(mysql_error());
}
示例#8
0
 function to_bbcode()
 {
     if (get_map($this->instance->user, 'html', 'can_add', array('forum_id' => $this->instance->forum_id)) <= $this->instance->user['perms']) {
         $html = get_map($this->instance->user, 'html', 'value', array('forum_id' => $this->instance->forum_id));
         $html = str_replace(' ', '', $html);
         $tags = explode(",", $html);
         foreach ($tags as $tag) {
             // $this->instance->text
             switch ($tag) {
                 case 'a':
                     break;
                 case 'br':
                     break;
                 default:
                     $this->instance->text = preg_replace('~<!-- HTML ' . $tag . ' --><' . $tag . '>(.+)</' . $tag . '><!-- / HTML ' . $tag . ' -->~i', '<' . $tag . '>\\1</' . $tag . '>', $this->instance->text);
                     break;
             }
         }
     }
     unset($this->lang);
     return $this->instance->text;
 }
示例#9
0
 function flatten($noparse = FALSE)
 {
     if ($noparse) {
         return $this->getUnparsed($noparse);
     }
     $body = parent::flatten($noparse);
     $question = trim($this->_attrib);
     $items = explode('[*]', $body);
     $param = $this->_attrib;
     $maxpolloptions = intval(Globals::getGlobal('maxpolloptions'));
     $forum_id = intval(Globals::getGlobal('forum_id'));
     if (!Globals::getGlobal('num_polls')) {
         Globals::setGlobal('num_polls', 0);
     }
     $can_poll = $forum_id > 0 && $_SESSION['user']->get('perms') >= get_map('bbcode', 'can_add', array('forum_id' => $forum_id));
     $ret = '';
     if (count($items) > 0 && $maxpolloptions > 0 && $can_poll && $question != '' && Globals::getGlobal('num_polls') <= Globals::getGlobal('maxpollquestions')) {
         global $_DBA;
         $question = $_DBA->quote(k4_htmlentities($question, ENT_QUOTES));
         $insert_question = $_DBA->executeUpdate("INSERT INTO " . K4POLLQUESTIONS . " (question, created, user_id, user_name) VALUES ('{$question}', " . time() . ", " . intval($_SESSION['user']->get('id')) . ", '" . $_DBA->quote($_SESSION['user']->get('name')) . "')");
         $question_id = $_DBA->getInsertId(K4POLLQUESTIONS, 'id');
         $buffer = '';
         $i = 0;
         foreach ($items as $item) {
             if ($i >= $maxpolloptions) {
                 break;
             }
             $item = trim(strip_tags(preg_replace("~(\r\n|\r|\n|\t|<br>|<br\\/>|<br \\/>)~i", "", $item)));
             if ($item != '') {
                 $_DBA->executeUpdate("INSERT INTO " . K4POLLANSWERS . " (question_id,answer) VALUES (" . intval($question_id) . ", '" . $_DBA->quote(k4_htmlentities($item, ENT_QUOTES)) . "')");
                 $i++;
             }
         }
         Globals::setGlobal('is_poll', TRUE);
         Globals::setGlobal('num_polls', Globals::getGlobal('num_polls') + 1);
         $ret = "[poll={$question_id}]";
     }
     return $ret;
 }
示例#10
0
 function Execute(&$template, $request, &$dba, &$session, &$user)
 {
     global $_QUERYPARAMS;
     /**
      * Error checking 
      */
     if (!isset($request['id']) || !$request['id'] || intval($request['id']) == 0) {
         /* set the breadcrumbs bit */
         $template = BreadCrumbs($template, $template->getVar('L_INVALIDTOPIC'));
         $template->setInfo('content', $template->getVar('L_TOPICDOESNTEXIST'), FALSE);
         return TRUE;
     }
     /* Get our topic */
     $topic = $dba->getRow("SELECT " . $_QUERYPARAMS['info'] . $_QUERYPARAMS['topic'] . " FROM " . TOPICS . " t LEFT JOIN " . INFO . " i ON t.topic_id = i.id WHERE i.id = " . intval($request['id']));
     if (!$topic || !is_array($topic) || empty($topic)) {
         /* set the breadcrumbs bit */
         $template = BreadCrumbs($template, $template->getVar('L_INVALIDTOPIC'));
         $template->setInfo('content', $template->getVar('L_TOPICDOESNTEXIST'), FALSE);
         return TRUE;
     }
     $forum = $dba->getRow("SELECT " . $_QUERYPARAMS['info'] . $_QUERYPARAMS['forum'] . " FROM " . FORUMS . " f LEFT JOIN " . INFO . " i ON f.forum_id = i.id WHERE i.id = " . intval($topic['forum_id']));
     /* Check the forum data given */
     if (!$forum || !is_array($forum) || empty($forum)) {
         /* set the breadcrumbs bit */
         $template = BreadCrumbs($template, $template->getVar('L_INVALIDFORUM'));
         $template->setInfo('content', $template->getVar('L_FORUMDOESNTEXIST'), FALSE);
         return TRUE;
     }
     /* Make sure the we are trying to delete from a forum */
     if (!($forum['row_type'] & FORUM)) {
         /* set the breadcrumbs bit */
         $template = BreadCrumbs($template, $template->getVar('L_INFORMATION'));
         $template->setInfo('content', $template->getVar('L_CANTDELFROMNONFORUM'), FALSE);
         return TRUE;
     }
     /* Do we have permission to post to this topic in this forum? */
     if ($user['perms'] < get_map($user, 'replies', 'can_add', array('forum_id' => $forum['id']))) {
         /* set the breadcrumbs bit */
         $template = BreadCrumbs($template, $template->getVar('L_INFORMATION'));
         return $template->setInfo('content', $template->getVar('L_PERMCANTPOST'), FALSE);
     }
     if (isset($request['r']) && intval($request['r']) != 0) {
         $reply = $dba->getRow("SELECT " . $_QUERYPARAMS['info'] . $_QUERYPARAMS['reply'] . " FROM " . REPLIES . " r LEFT JOIN " . INFO . " i ON r.reply_id = i.id WHERE i.id = " . intval($request['r']));
         if (!$reply || !is_array($reply) || empty($reply)) {
             /* set the breadcrumbs bit */
             $template = BreadCrumbs($template, $template->getVar('L_INVALIDREPLY'));
             $template->setInfo('content', $template->getVar('L_REPLYDOESNTEXIST'), FALSE);
             return TRUE;
         } else {
             $template->show('parent_id');
             $template->setVar('parent_id', $reply['id']);
         }
     }
     /* Prevent post flooding */
     $last_topic = $dba->getRow("SELECT " . $_QUERYPARAMS['info'] . $_QUERYPARAMS['topic'] . " FROM " . TOPICS . " t LEFT JOIN " . INFO . " i ON t.topic_id = i.id WHERE t.poster_ip = '" . USER_IP . "' ORDER BY i.created DESC LIMIT 1");
     $last_reply = $dba->getRow("SELECT " . $_QUERYPARAMS['info'] . $_QUERYPARAMS['reply'] . " FROM " . REPLIES . " r LEFT JOIN " . INFO . " i ON r.reply_id = i.id WHERE r.poster_ip = '" . USER_IP . "' ORDER BY i.created DESC LIMIT 1");
     if (is_array($last_topic) && !empty($last_topic)) {
         if (intval($last_topic['created']) + POST_IMPULSE_LIMIT > time()) {
             /* set the breadcrumbs bit */
             $template = BreadCrumbs($template, $template->getVar('L_INFORMATION'));
             $template->setInfo('content', $template->getVar('L_MUSTWAITSECSTOPOST'), TRUE);
             return TRUE;
         }
     }
     if (is_array($last_reply) && !empty($last_reply)) {
         if (intval($last_reply['created']) + POST_IMPULSE_LIMIT > time()) {
             /* set the breadcrumbs bit */
             $template = BreadCrumbs($template, $template->getVar('L_INFORMATION'));
             $template->setInfo('content', $template->getVar('L_MUSTWAITSECSTOPOST'), TRUE);
             return TRUE;
         }
     }
     $parent = isset($reply) && is_array($reply) ? $reply : $topic;
     /**
      * Start setting useful template information
      */
     /* Get and set the emoticons and post icons to the template */
     $emoticons =& $dba->executeQuery("SELECT * FROM " . EMOTICONS . " WHERE clickable = 1");
     $posticons =& $dba->executeQuery("SELECT * FROM " . POSTICONS);
     $template->setList('emoticons', $emoticons);
     $template->setList('posticons', $posticons);
     $template->setVar('emoticons_per_row', $template->getVar('smcolumns'));
     $template->setVar('emoticons_per_row_remainder', $template->getVar('smcolumns') - 1);
     $template = topic_post_options($template, $user, $forum);
     /* Set the forum and topic info to the template */
     foreach ($forum as $key => $val) {
         $template->setVar('forum_' . $key, $val);
     }
     /* We set topic information to be reply information */
     foreach ($topic as $key => $val) {
         /* Omit the body text variable */
         if ($key != 'body_text') {
             $template->setVar('reply_' . $key, $val);
         }
     }
     /* If this is a quote, put quote tags around the message */
     if (isset($request['quote']) && intval($request['quote']) == 1) {
         $bbcode =& new BBCodex($user, $parent['body_text'], $forum['id'], TRUE, TRUE, TRUE, TRUE);
         $template->setVar('reply_body_text', '[quote=' . $parent['poster_name'] . ']' . $bbcode->revert() . '[/quote]');
     }
     /* Set the title variable */
     if (isset($reply)) {
         $template->setVar('reply_name', $template->getVar('L_RE') . ': ' . $reply['name']);
     } else {
         $template->setVar('reply_name', $template->getVar('L_RE') . ': ' . $topic['name']);
     }
     $template->setVar('newtopic_action', 'newreply.php?act=postreply');
     /* set the breadcrumbs bit */
     $template = BreadCrumbs($template, $template->getVar('L_POSTREPLY'), $parent['row_left'], $parent['row_right']);
     foreach ($parent as $key => $val) {
         $template->setVar('parent_' . $key, $val);
     }
     /* Get the number of replies to this topic */
     $num_replies = @intval(($topic['row_right'] - $topic['row_left'] - 1) / 2);
     /* Get replies that are above this point */
     if ($num_replies > $forum['postsperpage']) {
         /* This will get all parent replies */
         $query = "SELECT " . $_QUERYPARAMS['info'] . $_QUERYPARAMS['reply'] . " FROM " . REPLIES . " r LEFT JOIN " . INFO . " i ON i.id = r.reply_id WHERE i.row_left >= " . $parent['row_left'] . " AND i.row_right <= " . $parent['row_right'] . " AND i.row_type = " . REPLY . " ORDER BY i.created DESC LIMIT 10";
     } else {
         /* Get generalized replies */
         $query = "SELECT " . $_QUERYPARAMS['info'] . $_QUERYPARAMS['reply'] . " FROM " . REPLIES . " r LEFT JOIN " . INFO . " i ON i.id = r.reply_id WHERE r.topic_id = " . $topic['id'] . " AND i.row_type = " . REPLY . " ORDER BY i.created DESC LIMIT 10";
     }
     $replies =& $dba->executeQuery($query);
     /* Set the form actiob */
     $template->setVar('newreply_act', 'newreply.php?act=postreply');
     $template->setList('topic_review', new TopicReviewIterator($topic, $replies, $user));
     /* Set the post topic form */
     $template->setFile('content', 'newreply.html');
     return TRUE;
 }
示例#11
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['post_id']) || intval($_REQUEST['post_id']) == 0) {
         $action = new K4InformationAction(new K4LanguageElement('L_TOPICDOESNTEXIST'), 'content', FALSE);
         return $action->execute($request);
     }
     /* Get our topic */
     $post = $request['dba']->getRow("SELECT * FROM " . K4POSTS . " WHERE post_id = " . intval($_REQUEST['post_id']));
     if (!$post || !is_array($post) || empty($post)) {
         $action = new K4InformationAction(new K4LanguageElement('L_POSTDOESNTEXIST'), 'content', FALSE);
         return $action->execute($request);
     }
     /* Should we redirect this user? */
     if ($post['moved_new_post_id'] > 0) {
         header("Location: viewpost.php?post_id=" . intval($post['moved_new_post_id']));
     }
     /* Get the current forum */
     $forum = $request['dba']->getRow("SELECT * FROM " . K4FORUMS . " WHERE forum_id = " . intval($post['forum_id']));
     if (!$forum || !is_array($forum) || empty($forum)) {
         $action = new K4InformationAction(new K4LanguageElement('L_FORUMDOESNTEXIST'), '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'], $post['name'], $forum);
     /**
      * Now tell the cookies that we've read this topic
      */
     $cookieinfo[$post['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);
     /**
      * More error checking
      */
     if ($post['is_draft'] == 1 || $post['display'] == 0 || $post['queue'] == 1 && !$moderator) {
         no_perms_error($request);
         return TRUE;
     }
     if (get_map('forums', 'can_view', array()) > $request['user']->get('perms') || get_map($post['row_type'] & TOPIC ? 'topics' : 'replies', '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);
     }
     /**
      * Is this topic expired?
      */
     $extra = '';
     if ($post['post_type'] > TOPIC_NORMAL && $post['post_expire'] > 0) {
         if ($post['created'] + 3600 * 24 * $post['post_expire'] > time()) {
             $extra = ",post_expire=0,post_type=" . TOPIC_NORMAL;
         }
     }
     /* Add the topic info to the template */
     foreach ($post as $key => $val) {
         $request['template']->setVar('post_' . $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($post['post_id']));
     /* set the topic iterator */
     if ($post['row_type'] & TOPIC) {
         $request['template']->setVar('next_oldest', intval($request['dba']->getValue("SELECT post_id FROM " . K4POSTS . " WHERE post_id < " . $post['post_id'] . " LIMIT 1")));
         $request['template']->setVar('next_newest', intval($request['dba']->getValue("SELECT post_id FROM " . K4POSTS . " WHERE post_id > " . $post['post_id'] . " LIMIT 1")));
         /**
          * Topic subscription stuff
          */
         if ($request['user']->isMember()) {
             $subscribed = $request['dba']->executeQuery("SELECT * FROM " . K4SUBSCRIPTIONS . " WHERE post_id = " . intval($post['post_id']) . " AND user_id = " . $request['user']->get('id'));
             $request['template']->setVar('is_subscribed', iif($subscribed->numRows() > 0, 1, 0));
         }
     }
     $request['template']->setVar('header_text', $use_reply ? $reply['name'] : $post['name']);
     $request['template']->setVar('show_close_button', 1);
     $request['template']->setFile('content', 'post_preview.html');
     return TRUE;
 }
 function execute(&$request)
 {
     global $_SETTINGS;
     if ($request['user']->get('perms') < get_map('warnuser', 'can_add', array())) {
         no_perms_error($request);
         return TRUE;
     }
     if (isset($_REQUEST['id'])) {
         $user = $request['dba']->getRow("SELECT * FROM " . K4USERS . " WHERE id = " . intval($_REQUEST['id']));
         k4_bread_crumbs($request['template'], $request['dba'], 'L_WARNUSER');
         if (!isset($_REQUEST['warning']) || $_REQUEST['warning'] == '') {
             $action = new K4InformationAction(new K4LanguageElement('L_PASTPAGELIMIT'), 'content', FALSE, 'mod.php?act=findusers&username='******'&limit=' . $perpage . '&page=' . $num_pages, 3);
             return $action->execute($request);
         }
         if (!is_array($user) || empty($user)) {
             k4_bread_crumbs($request['template'], $request['dba'], 'L_INFORMATION');
             $action = new K4InformationAction(new K4LanguageElement('L_INSERTWARNING'), 'content', TRUE);
             return $action->execute($request);
         }
         $request['dba']->executeUpdate("UPDATE " . K4USERS . " SET warn_level=warn_level+1 WHERE id = " . intval($user['id']));
         email_user($user['email'], $request['template']->getVar('L_WARNING'), $_REQUEST['warning']);
         $action = new K4InformationAction(new K4LanguageElement('L_SENTWARNING', $user['name']), 'content', TRUE, 'index.php', 3);
         return $action->execute($request);
     } else {
         k4_bread_crumbs($request['template'], $request['dba'], 'L_WARNUSER');
         $request['template']->setFile('content', 'finduser.html');
     }
 }
 function execute(&$request)
 {
     global $_QUERYPARAMS;
     k4_bread_crumbs($request['template'], $request['dba'], 'L_INFORMATION');
     if (!isset($_REQUEST['id']) || intval($_REQUEST['id']) == 0) {
         $action = new K4InformationAction(new K4LanguageElement('L_BADATTACHMENT'), 'content', FALSE);
         return $action->execute($request);
     }
     $attachment = $request['dba']->getRow("SELECT * FROM " . K4ATTACHMENTS . " WHERE id = " . intval($_REQUEST['id']));
     if (!is_array($attachment) || empty($attachment)) {
         $action = new K4InformationAction(new K4LanguageElement('L_BADATTACHMENT'), 'content', FALSE);
         return $action->execute($request);
     }
     if (isset($_REQUEST['post_id']) && intval($_REQUEST['post_id']) != 0) {
         $post = $request['dba']->getRow("SELECT * FROM " . K4POSTS . " WHERE post_id = " . intval($_REQUEST['post_id']));
     } else {
         //$action = new K4InformationAction(new K4LanguageElement('L_POSTDOESNTEXIST'), 'content', FALSE);
         //return $action->execute($request);
         $post = array('post_id' => 0, 'forum_id' => $attachment['forum_id'], 'row_type' => 0);
     }
     if (!is_array($post) || empty($post)) {
         $action = new K4InformationAction(new K4LanguageElement('L_POSTDOESNTEXIST'), 'content', FALSE);
         return $action->execute($request);
     }
     /* Get the current forum */
     $forum = $request['dba']->getRow("SELECT * FROM " . K4FORUMS . " WHERE forum_id = " . intval($post['forum_id']));
     if (!$forum || !is_array($forum) || empty($forum)) {
         $action = new K4InformationAction(new K4LanguageElement('L_FORUMDOESNTEXIST'), 'content', FALSE);
         return $action->execute($request);
     }
     k4_bread_crumbs($request['template'], $request['dba'], 'L_INFORMATION');
     /* Do we have permission to delete attachments in this forum? */
     if ($request['user']->get('perms') < get_map('attachments', 'can_del', array('forum_id' => $forum['forum_id']))) {
         no_perms_error($request);
         return TRUE;
     }
     if ($request['user']->get('id') != 0 && $request['user']->get('id') == $attachment['user_id'] || is_moderator($request['user']->getInfoArray(), $forum)) {
         k4_bread_crumbs($request['template'], $request['dba'], 'L_REMOVEATTACHMENT');
         $request['dba']->executeUpdate("DELETE FROM " . K4ATTACHMENTS . " WHERE id = " . intval($attachment['id']));
         if ($post['post_id'] > 0) {
             $request['dba']->executeUpdate("UPDATE " . K4POSTS . " SET total_attachments=total_attachments-1, attachments=attachments-1 WHERE post_id=" . intval($post['row_type'] & REPLY ? $post['parent_id'] : $post['post_id']));
             if ($post['row_type'] & REPLY) {
                 $request['dba']->executeUpdate("UPDATE " . K4POSTS . " SET attachments=attachments-1 WHERE post_id=" . intval($post['post_id']));
             }
         }
         $referer = basename(referer());
         if (strpos($referer, 'misc.php') === FALSE) {
             $action = new K4InformationAction(new K4LanguageElement('L_REMOVEDATTACHMENT', k4_htmlentities($attachment['file_name'], ENT_QUOTES)), 'content', TRUE, referer(), 3);
             return $action->execute($request);
         } else {
             header("Location: misc.php?act=attachments_manager&post_id=" . $post['post_id'] . "&forum_id=" . $post['forum_id'] . "");
             exit;
         }
     } else {
         no_perms_error($request);
         return TRUE;
     }
 }
 function execute(&$request)
 {
     // check the perms
     if (!$request['user']->isMember()) {
         no_perms_error($request, 'usercp_content');
         return TRUE;
     }
     if ($request['user']->get('perms') < get_map('private_messaging', 'can_view', array())) {
         no_perms_error($request, 'usercp_content');
         return TRUE;
     }
 }
示例#15
0
 function execute(&$request)
 {
     global $_QUERYPARAMS, $_DATASTORE;
     /* set the breadcrumbs bit */
     k4_bread_crumbs($request['template'], $request['dba'], 'L_INFORMATION');
     /* Get our reply */
     $reply = $request['dba']->getRow("SELECT * FROM " . K4POSTS . " WHERE post_id = " . intval($_REQUEST['id']));
     if (!$reply || !is_array($reply) || empty($reply)) {
         $action = new K4InformationAction(new K4LanguageElement('L_REPLYDOESNTEXIST'), 'content', FALSE);
         return $action->execute($request);
     }
     $request['template']->setVar('attach_post_id', $reply['post_id']);
     $topic = $request['dba']->getRow("SELECT * FROM " . K4POSTS . " WHERE post_id = " . intval($reply['post_id']));
     if (!$topic || !is_array($topic) || empty($topic)) {
         $action = new K4InformationAction(new K4LanguageElement('L_TOPICDOESNTEXIST'), 'content', FALSE);
         return $action->execute($request);
     }
     $forum = $request['dba']->getRow("SELECT * FROM " . K4FORUMS . " WHERE forum_id = " . intval($reply['forum_id']));
     /* Check the forum data given */
     if (!$forum || !is_array($forum) || empty($forum)) {
         $action = new K4InformationAction(new K4LanguageElement('L_FORUMDOESNTEXIST'), 'content', FALSE);
         return $action->execute($request);
     }
     /* Make sure the we are trying to post into a forum */
     if (!($forum['row_type'] & FORUM) || $forum['forum_id'] == GARBAGE_BIN) {
         $action = new K4InformationAction(new K4LanguageElement('L_CANTPOSTTONONFORUM'), 'content', FALSE);
         return $action->execute($request);
     }
     /* Does this user have permission to edit theirreply if the topic is locked? */
     if ($topic['post_locked'] == 1 && get_map('closed', 'can_edit', array('forum_id' => $forum['forum_id'])) > $request['user']->get('perms')) {
         $action = new K4InformationAction(new K4LanguageElement('L_YOUNEEDPERMS'), 'content', FALSE);
         return $action->execute($request);
     }
     /* set the breadcrumbs bit */
     k4_bread_crumbs($request['template'], $request['dba'], 'L_EDITREPLY', $reply, $forum);
     if ($reply['poster_id'] == $request['user']->get('id')) {
         if (get_map('replies', 'can_edit', array('forum_id' => $forum['forum_id'])) > $request['user']->get('perms')) {
             $action = new K4InformationAction(new K4LanguageElement('L_YOUNEEDPERMS'), 'content', FALSE);
             return $action->execute($request);
         }
     } else {
         if (get_map('other_replies', 'can_edit', array('forum_id' => $forum['forum_id'])) > $request['user']->get('perms')) {
             $action = new K4InformationAction(new K4LanguageElement('L_YOUNEEDPERMS'), 'content', FALSE);
             return $action->execute($request);
         }
     }
     //$bbcode				= &new BBCodex($request['dba'], $request['user']->getInfoArray(), $reply['body_text'], $forum['forum_id'], TRUE, TRUE, TRUE, TRUE);
     $parser =& new BBParser();
     Globals::setGlobal('forum_id', $forum['forum_id']);
     Globals::setGlobal('maxpolloptions', $forum['maxpolloptions']);
     /* Get and set the emoticons and post icons to the template */
     $emoticons = $request['dba']->executeQuery("SELECT * FROM " . K4EMOTICONS . " WHERE clickable = 1");
     $posticons = $request['dba']->executeQuery("SELECT * FROM " . K4POSTICONS);
     $request['template']->setList('emoticons', $emoticons);
     $request['template']->setList('posticons', $posticons);
     $request['template']->setVar('emoticons_per_row', $request['template']->getVar('smcolumns'));
     $request['template']->setVar('emoticons_per_row_remainder', $request['template']->getVar('smcolumns') - 1);
     /* Get the posting options */
     topic_post_options($request['template'], $request['user'], $forum);
     post_attachment_options($request, $forum, $reply);
     $reply['body_text'] = $parser->revert($reply['body_text']);
     foreach ($reply as $key => $val) {
         $request['template']->setVar('post_' . $key, $val);
     }
     /* Assign the forum information to the template */
     foreach ($forum as $key => $val) {
         $request['template']->setVar('forum_' . $key, $val);
     }
     /* Set the the button display options */
     $request['template']->setVisibility('edit_reply', TRUE);
     $request['template']->setVisibility('post_id', TRUE);
     $request['template']->setVisibility('post_reply', FALSE);
     $request['template']->setVisibility('edit_post', TRUE);
     /* Set the form actiob */
     $request['template']->setVar('newreply_act', 'newreply.php?act=updatereply');
     /* Get 10 replies that are above this reply to set as a topic review */
     // TODO: work on this a bit.
     $result = $request['dba']->executeQuery("SELECT * FROM " . K4POSTS . " WHERE (post_id=" . intval($topic['post_id']) . " OR parent_id=" . intval($topic['post_id']) . ") ORDER BY created DESC LIMIT 10");
     $it =& new PostsIterator($request, $result);
     $request['template']->setList('topic_review', $it);
     /* set the breadcrumbs bit */
     k4_bread_crumbs($request['template'], $request['dba'], 'L_EDITREPLY', $topic, $forum);
     /* Create our editor */
     create_editor($request, $reply['body_text'], 'post', $forum);
     /* Set the post topic form */
     //$request['template']->setFile('preview', 'post_preview.html');
     $request['template']->setFile('content', 'newreply.html');
     $request['template']->setVar('L_TITLETOOSHORT', sprintf($request['template']->getVar('L_TITLETOOSHORT'), $request['template']->getVar('topicminchars'), $request['template']->getVar('topicmaxchars')));
     return TRUE;
 }
示例#16
0
function run_map($result, $expr)
{
    $res = "";
    $odd = false;
    $map = get_map($expr);
    foreach (nanolexify_replacements($result) as $i) {
        $odd = !$odd;
        if ($odd) {
            $res .= $i;
            continue;
        }
        $res .= "\\\$\\{" . $map($i) . "\\}";
    }
    return $res;
}
示例#17
0
 function Execute(&$template, $request, &$dba, &$session, &$user)
 {
     global $_URL, $_QUERYPARAMS, $_USERGROUPS, $_SESS, $_ALLFORUMS;
     if (!isset($request['id']) || !$request['id'] || intval($request['id']) == 0) {
         /* set the breadcrumbs bit */
         $template = BreadCrumbs($template, $template->getVar('L_INVALIDFORUM'));
         $template->setInfo('content', $template->getVar('L_FORUMDOESNTEXIST'), FALSE);
         return TRUE;
     }
     /* Get the current forum/category */
     $forum = $_ALLFORUMS[$request['id']];
     $query = $forum['row_type'] & FORUM ? "SELECT " . $_QUERYPARAMS['info'] . $_QUERYPARAMS['forum'] . " FROM " . FORUMS . " f LEFT JOIN " . INFO . " i ON f.forum_id = i.id WHERE i.id = " . intval($request['id']) : "SELECT " . $_QUERYPARAMS['info'] . $_QUERYPARAMS['category'] . " FROM " . CATEGORIES . " c LEFT JOIN " . INFO . " i ON c.category_id = i.id WHERE i.id = " . intval($request['id']);
     $forum = $dba->getRow($query);
     if (!$forum || !is_array($forum) || empty($forum)) {
         /* set the breadcrumbs bit */
         $template = BreadCrumbs($template, $template->getVar('L_INVALIDFORUM'));
         $template->setInfo('content', $template->getVar('L_FORUMDOESNTEXIST'), FALSE);
         return TRUE;
     }
     if ($forum['row_type'] == FORUM && @$forum['is_link'] == 1) {
         $template = BreadCrumbs($template, $template->getVar('L_INFORMATION'), $forum['row_left'], $forum['row_right']);
         $template->setInfo('content', $template->getVar('L_REDIRECTING'));
         if ($forum['link_show_redirects'] == 1) {
             $template->setRedirect('redirect.php?id=' . $forum['id'], 3);
         } else {
             $template->setRedirect($forum['link_href'], 3);
         }
         return TRUE;
     }
     /* Set the extra SQL query fields to check */
     $extra = " AND s.location_file = '" . $dba->Quote($_URL->file) . "' AND s.location_id = " . intval($forum['id']);
     $forum_can_view = $forum['row_type'] & CATEGORY ? get_map($user, 'categories', 'can_view', array()) : get_map($user, 'forums', 'can_view', array());
     $expired = time() - ini_get('session.gc_maxlifetime');
     $num_online_total = $dba->getValue("SELECT COUNT(s.id) as num_online_total FROM " . SESSIONS . " s WHERE s.seen >= {$expired} {$extra}");
     /* If there are more than 0 people browsing the forum, display the stats */
     if ($num_online_total > 0 && $forum_can_view <= $user['perms'] && ($forum['row_type'] & CATEGORY || $forum['row_type'] & FORUM)) {
         $users_browsing =& new OnlineUsersIterator($extra);
         /* Set the users browsing list */
         $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';
         $template->setVar('num_online_members', $stats['num_online_members']);
         $template->setVar('users_browsing', $template->getVar($element));
         $template->setVar('online_stats', sprintf($template->getVar('L_USERSBROWSINGSTATS'), $stats['num_online_total'], $stats['num_online_members'], $stats['num_guests'], $stats['num_invisible']));
         /* Set the User's Browsing file */
         $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);
         $template->setList('usergroups_legend', $groups);
     }
     if ($forum_can_view > $user['perms']) {
         /* set the breadcrumbs bit */
         $template = BreadCrumbs($template, $template->getVar('L_INFORMATION'), $forum['row_left'], $forum['row_right']);
         $template->setInfo('content', $template->getVar('L_PERMCANTVIEW'), FALSE);
         return TRUE;
     }
     /* Set the breadcrumbs bit */
     $template = BreadCrumbs($template, NULL, $forum['row_left'], $forum['row_right']);
     /* Set all of the category/forum info to the template */
     $template->setVarArray($forum);
     /* If we are looking at a category */
     if ($forum['row_type'] & CATEGORY) {
         if (get_map($user, 'categories', 'can_view', array()) > $user['perms']) {
             /* set the breadcrumbs bit */
             $template = BreadCrumbs($template, $template->getVar('L_INFORMATION'), $forum['row_left'], $forum['row_right']);
             $template->setInfo('content', $template->getVar('L_PERMCANTVIEW'));
             return TRUE;
         }
         /* Set the proper query params */
         $query_params = $_QUERYPARAMS['info'] . $_QUERYPARAMS['category'];
         /* Set the Categories list */
         $categories =& new CategoriesIterator("SELECT {$query_params} FROM " . INFO . " i LEFT JOIN " . CATEGORIES . " c ON c.category_id = i.id WHERE i.row_type = " . CATEGORY . " AND i.row_left = " . $forum['row_left'] . " AND i.row_right = " . $forum['row_right'] . " AND i.id = " . $forum['id'] . " ORDER BY i.row_order ASC");
         $template->setList('categories', $categories);
         /* Hide the welcome message at the top of the forums.html template */
         $template->hide('welcome_msg');
         /* Show the forum status icons */
         $template->show('forum_status_icons');
         /* Show the 'Mark these forums Read' link */
         $template->show('mark_these_forums');
         /* Set the forums template to content variable */
         $template->setFile('content', 'forums.html');
         /* If we are looking at a forum */
     } else {
         if ($forum['row_type'] & FORUM) {
             /* Add the forum info to the template */
             foreach ($forum as $key => $val) {
                 $template->setVar('forum_' . $key, $val);
             }
             /* If this forum has sub-forums */
             if (isset_forum_cache_item('subforums', $forum['id']) && $forum['subforums'] == 1) {
                 /* Cache this forum as having subforums */
                 set_forum_cache_item('subforums', 1, $forum['id']);
                 /* Show the table that holds the subforums */
                 $template->show('subforums');
                 /* Set the proper query params */
                 $query_params = $_QUERYPARAMS['info'] . $_QUERYPARAMS['forum'];
                 /* Set the sub-forums list */
                 $template->setList('subforums', new ForumsIterator("SELECT {$query_params} FROM " . INFO . " i LEFT JOIN " . FORUMS . " f ON f.forum_id = i.id WHERE i.row_left > " . $forum['row_left'] . " AND i.row_right < " . $forum['row_right'] . " AND i.row_type = " . FORUM . " AND i.parent_id = " . $forum['id'] . " ORDER BY i.row_order ASC"));
                 $template->setFile('content', 'subforums.html');
             }
             if (get_map($user, 'topics', 'can_view', array('forum_id' => $forum['id'])) > $user['perms']) {
                 /* set the breadcrumbs bit */
                 $template = BreadCrumbs($template, $template->getVar('L_INFORMATION'), $forum['row_left'], $forum['row_right']);
                 $template->setInfo('content_extra', $template->getVar('L_CANTVIEWFORUMTOPICS'), FALSE);
                 return TRUE;
             }
             /**
              * Forum settings
              */
             /* Set the topics template to the content variable */
             $template->setFile('content_extra', 'topics.html');
             /* Set what this user can/cannot do in this forum */
             $template->setVar('forum_user_topic_options', sprintf($template->getVar('L_FORUMUSERTOPICPERMS'), iif(get_map($user, 'topics', 'can_add', array('forum_id' => $forum['id'])) > $user['perms'], $template->getVar('L_CANNOT'), $template->getVar('L_CAN')), iif(get_map($user, 'topics', 'can_edit', array('forum_id' => $forum['id'])) > $user['perms'], $template->getVar('L_CANNOT'), $template->getVar('L_CAN')), iif(get_map($user, 'topics', 'can_del', array('forum_id' => $forum['id'])) > $user['perms'], $template->getVar('L_CANNOT'), $template->getVar('L_CAN')), iif(get_map($user, 'attachments', 'can_add', array('forum_id' => $forum['id'])) > $user['perms'], $template->getVar('L_CANNOT'), $template->getVar('L_CAN'))));
             $template->setVar('forum_user_reply_options', sprintf($template->getVar('L_FORUMUSERREPLYPERMS'), iif(get_map($user, 'replies', 'can_add', array('forum_id' => $forum['id'])) > $user['perms'], $template->getVar('L_CANNOT'), $template->getVar('L_CAN')), iif(get_map($user, 'replies', 'can_edit', array('forum_id' => $forum['id'])) > $user['perms'], $template->getVar('L_CANNOT'), $template->getVar('L_CAN')), iif(get_map($user, 'replies', 'can_del', array('forum_id' => $forum['id'])) > $user['perms'], $template->getVar('L_CANNOT'), $template->getVar('L_CAN'))));
             /* Create an array with all of the possible sort orders we can have */
             $sort_orders = array('name', 'reply_time', 'num_replies', 'views', 'reply_uname', 'rating');
             /**
              * Pagination
              */
             /* Create the Pagination */
             $resultsperpage = $forum['topicsperpage'];
             $num_results = $forum['topics'];
             $perpage = isset($request['limit']) && ctype_digit($request['limit']) && intval($request['limit']) > 0 ? intval($request['limit']) : $resultsperpage;
             $num_pages = ceil($num_results / $perpage);
             $page = isset($request['page']) && ctype_digit($request['page']) && intval($request['page']) > 0 ? intval($request['page']) : 1;
             $pager =& new TPL_Paginator($_URL, $num_results, $page, $perpage);
             if ($num_results > $perpage) {
                 $template->setPager('topics_pager', $pager);
             }
             /* Get the topics for this forum */
             $daysprune = isset($request['daysprune']) && ctype_digit($request['daysprune']) ? iif($request['daysprune'] == -1, 0, intval($request['daysprune'])) : 30;
             $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'] : 'created';
             $start = ($page - 1) * $perpage;
             if ($forum['topics'] > 0) {
                 /**
                  * Topic Setting
                  */
                 /* get the topics */
                 $topics =& $dba->prepareStatement("SELECT " . $_QUERYPARAMS['info'] . $_QUERYPARAMS['topic'] . " FROM " . TOPICS . " t LEFT JOIN " . INFO . " i ON t.topic_id = i.id WHERE i.created>=? AND t.is_draft=0 AND t.queue = 0 AND t.display = 1 AND i.row_type=" . TOPIC . " AND t.forum_id = " . intval($forum['id']) . " AND (t.topic_type <> " . TOPIC_GLOBAL . " AND t.topic_type <> " . TOPIC_ANNOUNCE . " AND t.topic_type <> " . TOPIC_STICKY . " AND t.is_feature = 0) ORDER BY {$sortedby} {$sortorder} LIMIT ?,?");
                 /* Set the query values */
                 $topics->setInt(1, $daysprune * (3600 * 24));
                 $topics->setInt(2, $start);
                 $topics->setInt(3, $perpage);
                 /* Execute the query */
                 $result =& $topics->executeQuery();
                 /* Apply the topics iterator */
                 $it =& new TopicsIterator($result, &$session, $template->getVar('IMG_DIR'), $forum);
                 $template->setList('topics', $it);
                 /**
                  * Get announcement/global topics
                  */
                 if ($page == 1) {
                     $announcements =& $dba->executeQuery("SELECT " . $_QUERYPARAMS['info'] . $_QUERYPARAMS['topic'] . " FROM " . TOPICS . " t LEFT JOIN " . INFO . " i ON t.topic_id = i.id WHERE t.is_draft=0 AND t.queue = 0 AND t.display = 1 AND i.row_type=" . TOPIC . " AND t.forum_id = " . intval($forum['id']) . " AND (t.topic_type = " . TOPIC_GLOBAL . " OR t.topic_type = " . TOPIC_ANNOUNCE . ") ORDER BY i.created DESC");
                     if ($announcements->numrows() > 0) {
                         $a_it =& new TopicsIterator($announcements, &$session, $template->getVar('IMG_DIR'), $forum);
                         $template->setList('announcements', $a_it);
                     }
                 }
                 /**
                  * Get sticky/feature topics
                  */
                 $importants =& $dba->executeQuery("SELECT " . $_QUERYPARAMS['info'] . $_QUERYPARAMS['topic'] . " FROM " . TOPICS . " t LEFT JOIN " . INFO . " i ON t.topic_id = i.id WHERE t.is_draft=0 AND t.queue = 0 AND t.display = 1 AND i.row_type=" . TOPIC . " AND t.forum_id = " . intval($forum['id']) . " AND (t.topic_type <> " . TOPIC_GLOBAL . " AND t.topic_type <> " . TOPIC_ANNOUNCE . ") AND (t.topic_type = " . TOPIC_STICKY . " OR t.is_feature = 1) ORDER BY i.created DESC");
                 if ($importants->numrows() > 0) {
                     $i_it =& new TopicsIterator($importants, &$session, $template->getVar('IMG_DIR'), $forum);
                     $template->setList('importants', $i_it);
                 }
                 /* Outside valid page range, redirect */
                 if (!$pager->hasPage($page) && $num_results > $resultsperpage) {
                     $template->setVar('topics_message', $template->getVar('L_PASTPAGELIMIT'));
                     $template->setRedirect('viewforum.php?id=' . $forum['id'] . '&limit=' . $perpage . '&page=' . $num_pages, 3);
                     return TRUE;
                 }
             }
             /* If there are no topics, set the right messageto display */
             if ($forum['topics'] <= 0) {
                 $template->show('no_topics');
                 $template->setVar('topics_message', iif($daysprune == 0, $template->getVar('L_NOPOSTSINFORUM'), sprintf($template->getVar('L_FORUMNOPOSTSSINCE'), $daysprune)));
                 return TRUE;
             }
             /**
              * Moderator functions
              */
             $template->setVar('modpanel', 0);
             if (is_moderator($user, $forum)) {
                 $template->setVar('modpanel', 1);
             }
         } else {
             /* set the breadcrumbs bit */
             $template = BreadCrumbs($template, $template->getVar('L_INVALIDFORUM'));
             $template->setInfo('content', $template->getVar('L_FORUMDOESNTEXIST'), FALSE);
             return TRUE;
         }
     }
     /* Add the cookies for this forum's topics */
     bb_execute_topiccache();
     return TRUE;
 }
示例#18
0
 function execute(&$request)
 {
     // do we have permission to use the advanced search?
     if (get_map('advsearch', 'can_view', array()) > $request['user']->get('perms')) {
         exit;
     }
     // put query and loop and stuff here
     exit;
     return TRUE;
 }
示例#19
0
 function execute(&$request)
 {
     global $_QUERYPARAMS, $_DATASTORE, $_USERGROUPS;
     /* set the breadcrumbs bit */
     k4_bread_crumbs($request['template'], $request['dba'], 'L_INFORMATION');
     if (!isset($_REQUEST['id']) || !$_REQUEST['id'] || intval($_REQUEST['id']) == 0) {
         $action = new K4InformationAction(new K4LanguageElement('L_TOPICDOESNTEXIST'), 'content', FALSE);
         return !USE_XMLHTTP ? $action->execute($request) : exit;
     }
     /* 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 !USE_XMLHTTP ? $action->execute($request) : exit;
     }
     $forum = $request['dba']->getRow("SELECT * FROM " . K4FORUMS . " WHERE forum_id = " . intval($topic['forum_id']));
     /* Check the forum data given */
     if (!$forum || !is_array($forum) || empty($forum)) {
         $action = new K4InformationAction(new K4LanguageElement('L_FORUMDOESNTEXIST'), 'content', FALSE);
         return !USE_XMLHTTP ? $action->execute($request) : exit;
     }
     /* Make sure the we are trying to delete from a forum */
     if (!($forum['row_type'] & FORUM)) {
         $action = new K4InformationAction(new K4LanguageElement('L_CANTDELFROMNONFORUM'), 'content', FALSE);
         return !USE_XMLHTTP ? $action->execute($request) : exit;
     }
     if (get_map('closed', 'can_add', array('forum_id' => $forum['forum_id'])) > $request['user']->get('perms')) {
         $request['template']->setFile('content', '../login_form.html');
         $request['template']->setVisibility('no_perms', TRUE);
         return !USE_XMLHTTP ? TRUE : exit;
     }
     if (!is_moderator($request['user']->getInfoArray(), $forum)) {
         $request['template']->setFile('content', '../login_form.html');
         $request['template']->setVisibility('no_perms', TRUE);
         return !USE_XMLHTTP ? TRUE : exit;
     }
     /* set the breadcrumbs bit */
     k4_bread_crumbs($request['template'], $request['dba'], 'L_LOCKTOPIC', $topic, $forum);
     /* Lock the topic */
     $lock = $request['dba']->prepareStatement("UPDATE " . K4POSTS . " SET post_locked=" . $this->lock . " WHERE post_id=?");
     $lock->setInt(1, $topic['post_id']);
     $lock->executeUpdate();
     // remove any post report associated with this topic
     if ($this->lock == 1) {
         $request['dba']->executeUpdate("DELETE FROM " . K4BADPOSTREPORTS . " WHERE post_id = " . intval($topic['post_id']) . " AND post_id = 0");
     }
     /* Redirect the user */
     if (!USE_XMLHTTP) {
         $action = new K4InformationAction(new K4LanguageElement($this->lock == 1 ? 'L_LOCKEDTOPIC' : 'L_UNLOCKEDTOPIC', $topic['name']), 'content', FALSE, 'viewtopic.php?id=' . $topic['post_id'], 3);
         return $action->execute($request);
     } else {
         echo $this->lock == 1 ? 'locked' : 'unlocked';
         exit;
     }
 }
示例#20
0
 function Execute(&$template, $request, &$dba, &$session, &$user)
 {
     global $_QUERYPARAMS, $_DATASTORE;
     /* Check the request ID */
     if (!isset($request['forum_id']) || !$request['forum_id'] || intval($request['forum_id']) == 0) {
         /* set the breadcrumbs bit */
         $template = BreadCrumbs($template, $template->getVar('L_INVALIDFORUM'));
         $template->setInfo('content', $template->getVar('L_FORUMDOESNTEXIST'), FALSE);
         return TRUE;
     }
     $forum = $dba->getRow("SELECT " . $_QUERYPARAMS['info'] . $_QUERYPARAMS['forum'] . " FROM " . FORUMS . " f LEFT JOIN " . INFO . " i ON f.forum_id = i.id WHERE i.id = " . intval($request['forum_id']));
     /* Check the forum data given */
     if (!$forum || !is_array($forum) || empty($forum)) {
         /* set the breadcrumbs bit */
         $template = BreadCrumbs($template, $template->getVar('L_INVALIDFORUM'));
         $template->setInfo('content', $template->getVar('L_FORUMDOESNTEXIST'), FALSE);
         return TRUE;
     }
     /* Make sure the we are trying to edit in a forum */
     if (!($forum['row_type'] & FORUM)) {
         /* set the breadcrumbs bit */
         $template = BreadCrumbs($template, $template->getVar('L_INFORMATION'));
         $template->setInfo('content', $template->getVar('L_CANTEDITTONONFORUM'), FALSE);
         return TRUE;
     }
     if (!isset($request['id']) || !$request['id'] || intval($request['id']) == 0) {
         /* set the breadcrumbs bit */
         $template = BreadCrumbs($template, $template->getVar('L_INVALIDTOPIC'));
         $template->setInfo('content', $template->getVar('L_TOPICDOESNTEXIST'), FALSE);
         return TRUE;
     }
     /* Get our topic */
     $topic = $dba->getRow("SELECT " . $_QUERYPARAMS['info'] . $_QUERYPARAMS['topic'] . " FROM " . TOPICS . " t LEFT JOIN " . INFO . " i ON t.topic_id = i.id WHERE i.id = " . intval($request['id']));
     if (!$topic || !is_array($topic) || empty($topic)) {
         /* set the breadcrumbs bit */
         $template = BreadCrumbs($template, $template->getVar('L_INVALIDTOPIC'));
         $template->setInfo('content', $template->getVar('L_TOPICDOESNTEXIST'), FALSE);
         return TRUE;
     }
     if (!isset($request['name']) || $request['name'] == '') {
         $name = $topic['name'];
     } else {
         $name = $request['name'];
     }
     if (!is_moderator($user, $forum)) {
         $template = BreadCrumbs($template, $template->getVar('L_INFORMATION'));
         $template->setFile('content', 'login_form.html');
         $template->show('no_perms');
         return TRUE;
     }
     if ($topic['poster_id'] == $user['id']) {
         if ($user['perms'] < get_map($user, 'topics', 'can_edit', array('forum_id' => $forum['id']))) {
             $template = BreadCrumbs($template, $template->getVar('L_INFORMATION'));
             $template->setFile('content', 'login_form.html');
             $template->show('no_perms');
             return TRUE;
         }
     } else {
         if ($user['perms'] < get_map($user, 'other_topics', 'can_edit', array('forum_id' => $forum['id']))) {
             $template = BreadCrumbs($template, $template->getVar('L_INFORMATION'));
             $template->setFile('content', 'login_form.html');
             $template->show('no_perms');
             return TRUE;
         }
     }
     $update_a =& $dba->prepareStatement("UPDATE " . INFO . " SET name=? WHERE id=?");
     $update_b =& $dba->prepareStatement("UPDATE " . TOPICS . " SET edited_time=?,edited_username=?,edited_userid=? WHERE topic_id=?");
     $update_a->setString(1, $name);
     $update_a->setInt(2, $topic['id']);
     $update_b->setInt(1, time());
     $update_b->setString(2, $user['name']);
     $update_b->setInt(3, $user['id']);
     $update_b->setInt(4, $topic['id']);
     $update_a->executeUpdate();
     $update_b->executeUpdate();
     if ($forum['topic_id'] == $topic['id']) {
         $update_c =& $dba->prepareStatement("UPDATE " . FORUMS . " SET topic_name=? WHERE forum_id=?");
         $update_c->setString(1, $name);
         $update_c->setInt(2, $forum['id']);
         $update_c->executeUpdate();
     }
     if ($forum['post_id'] == $topic['id']) {
         $update_d =& $dba->prepareStatement("UPDATE " . FORUMS . " SET post_name=? WHERE forum_id=?");
         $update_d->setString(1, $name);
         $update_d->setInt(2, $forum['id']);
         $update_d->executeUpdate();
     }
     $template = BreadCrumbs($template, $template->getVar('L_EDITTOPIC'), $forum['row_left'], $forum['row_right']);
     $template->setInfo('content', sprintf($template->getVar('L_UPDATEDTOPIC'), $topic['name']));
     $template->setRedirect(referer(), 3);
     return TRUE;
 }
 function execute(&$request)
 {
     global $_QUERYPARAMS, $_DATASTORE, $_SETTINGS;
     /* set the breadcrumbs bit */
     k4_bread_crumbs($request['template'], $request['dba'], 'L_INFORMATION');
     /* Check the request ID */
     if (!isset($_REQUEST['id']) || !$_REQUEST['id'] || intval($_REQUEST['id']) == 0) {
         $action = new K4InformationAction(new K4LanguageElement('L_TOPICDOESNTEXIST'), 'content', FALSE);
         return !USE_XMLHTTP ? $action->execute($request) : xmlhttp_message('L_TOPICDOESNTEXIST');
     }
     /* 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 !USE_XMLHTTP ? $action->execute($request) : xmlhttp_message('L_TOPICDOESNTEXIST');
     }
     $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 !USE_XMLHTTP ? $action->execute($request) : xmlhttp_message('L_FORUMDOESNTEXIST');
     }
     if (!isset($_REQUEST['name']) || $_REQUEST['name'] == '') {
         $name = $topic['name'];
     } else {
         $name = strip_tags($_REQUEST['name']);
     }
     $name = $name == '' ? $topic['name'] : $name;
     if (strlen($name) < intval($_SETTINGS['topicminchars']) || strlen($name) > intval($_SETTINGS['topicmaxchars'])) {
         $action = new K4InformationAction(new K4LanguageElement('L_TITLETOOSHORT', intval($_SETTINGS['topicminchars']), intval($_SETTINGS['topicmaxchars'])), 'content', TRUE);
         return !USE_XMLHTTP ? $action->execute($request) : xmlhttp_message(sprintf('L_TITLETOOSHORT', intval($_SETTINGS['topicminchars']), intval($_SETTINGS['topicmaxchars'])));
     }
     if ($name != $topic['name']) {
         $name = k4_htmlentities($name, ENT_QUOTES);
         if (!is_moderator($request['user']->getInfoArray(), $forum)) {
             no_perms_error($request);
             return !USE_XMLHTTP ? TRUE : xmlhttp_message('L_NEEDPERMS');
         }
         if ($topic['poster_id'] == $request['user']->get('id')) {
             if ($request['user']->get('perms') < get_map('topics', 'can_edit', array('forum_id' => $topic['forum_id']))) {
                 no_perms_error($request);
                 return !USE_XMLHTTP ? TRUE : xmlhttp_message('L_NEEDPERMS');
             }
         } else {
             if ($request['user']->get('perms') < get_map('other_topics', 'can_edit', array('forum_id' => $topic['forum_id']))) {
                 no_perms_error($request);
                 return !USE_XMLHTTP ? TRUE : xmlhttp_message('L_NEEDPERMS');
             }
         }
         /* If this topic is a redirect/ connects to one, update the original */
         if ($topic['moved_new_post_id'] > 0 || $topic['moved_old_post_id'] > 0) {
             $redirect = $request['dba']->prepareStatement("UPDATE " . K4POSTS . " SET name=?,edited_time=?,edited_username=?,edited_userid=? WHERE post_id=?");
             $redirect->setString(1, $name);
             $redirect->setInt(2, time());
             $redirect->setString(3, $request['user']->get('name'));
             $redirect->setInt(4, $request['user']->get('id'));
             $redirect->setInt(5, $topic['moved_new_post_id'] > 0 ? $topic['moved_new_post_id'] : $topic['moved_old_post_id']);
             $redirect->executeUpdate();
         }
         $update_a = $request['dba']->prepareStatement("UPDATE " . K4POSTS . " SET name=?,edited_time=?,edited_username=?,edited_userid=? WHERE post_id=?");
         $update_a->setString(1, $name);
         $update_a->setInt(2, time());
         $update_a->setString(3, $request['user']->get('name'));
         $update_a->setInt(4, $request['user']->get('id'));
         $update_a->setInt(5, $topic['post_id']);
         $update_a->executeUpdate();
         if ($forum['post_id'] == $topic['post_id']) {
             $update_c = $request['dba']->prepareStatement("UPDATE " . K4FORUMS . " SET post_name=? WHERE forum_id=?");
             $update_c->setString(1, $name);
             $update_c->setInt(2, $forum['forum_id']);
             $update_c->executeUpdate();
         }
         // id this is the last post in a forum
         if ($forum['post_id'] == $topic['post_id'] && $forum['post_created'] == $topic['created']) {
             $update_d = $request['dba']->prepareStatement("UPDATE " . K4FORUMS . " SET post_name=? WHERE forum_id=?");
             $update_d->setString(1, $name);
             $update_d->setInt(2, $forum['forum_id']);
             $update_d->executeUpdate();
         }
     }
     if (!USE_XMLHTTP) {
         k4_bread_crumbs($request['template'], $request['dba'], 'L_EDITTOPIC', $forum);
         $action = new K4InformationAction(new K4LanguageElement('L_UPDATEDTOPIC', $topic['name']), 'content', FALSE, referer(), 3);
         return $action->execute($request);
     } else {
         xmlhttp_header();
         echo '<a href="viewtopic.php?id=' . $topic['post_id'] . '" title="' . $name . '" style="font-size: 13px;">' . (strlen($name) > 40 ? substr($name, 0, 40) . '...' : $name) . '</a>';
         xmlhttp_footer();
     }
 }
示例#22
0
 function execute(&$request)
 {
     global $_QUERYPARAMS, $_DATASTORE, $_USERGROUPS;
     /* set the breadcrumbs bit */
     k4_bread_crumbs($request['template'], $request['dba'], 'L_INFORMATION');
     if (!isset($_REQUEST['id']) || intval($_REQUEST['id']) == 0) {
         $action = new K4InformationAction(new K4LanguageElement('L_POSTDOESNTEXIST'), 'content', FALSE);
         return $action->execute($request);
     }
     /* Get our topic */
     $post = $request['dba']->getRow("SELECT * FROM " . K4POSTS . " WHERE post_id = " . intval($_REQUEST['id']));
     if (!$post || !is_array($post) || empty($post)) {
         $action = new K4InformationAction(new K4LanguageElement('L_POSTDOESNTEXIST'), 'content', FALSE);
         return $action->execute($request);
     }
     $forum = $request['dba']->getRow("SELECT * FROM " . K4FORUMS . " WHERE forum_id = " . intval($post['forum_id']));
     /* Check the forum data given */
     if (!$forum || !is_array($forum) || empty($forum)) {
         $action = new K4InformationAction(new K4LanguageElement('L_FORUMDOESNTEXIST'), 'content', FALSE);
         return $action->execute($request);
     }
     $delete_topic = FALSE;
     if ($forum['forum_id'] == GARBAGE_BIN && $this->row_type & TOPIC) {
         $delete_topic = TRUE;
     }
     /* Make sure the we are trying to delete from a forum */
     if (!($forum['row_type'] & FORUM)) {
         $action = new K4InformationAction(new K4LanguageElement('L_CANTDELFROMNONFORUM'), 'content', FALSE);
         return $action->execute($request);
     }
     /* set the breadcrumbs bit */
     k4_bread_crumbs($request['template'], $request['dba'], $this->row_type & REPLY ? 'L_DELETEREPLY' : 'L_DELETETOPIC', $post, $forum);
     $maps_var = $this->row_type & TOPIC ? 'topics' : 'replies';
     /* Does this person have permission to remove this post? */
     if ($post['poster_id'] == $request['user']->get('id')) {
         if (get_map($maps_var, 'can_del', array('forum_id' => $forum['forum_id'])) > $request['user']->get('perms')) {
             no_perms_error($request);
             return TRUE;
         }
     } else {
         if (get_map('other_' . $maps_var, 'can_del', array('forum_id' => $forum['forum_id'])) > $request['user']->get('perms')) {
             no_perms_error($request);
             return TRUE;
         }
     }
     $user_usergroups = $request['user']->get('usergroups') != '' ? explode('|', $request['user']->get('usergroups')) : array();
     $forum_usergroups = $forum['moderating_groups'] != '' ? explode('|', $forum['moderating_groups']) : array();
     if (!is_moderator($request['user']->getInfoArray(), $forum)) {
         no_perms_error($request);
         return TRUE;
     }
     /* Begin the SQL transaction */
     $request['dba']->beginTransaction();
     /**
      * Should we update the topic?
      */
     if ($this->row_type & REPLY) {
         $topic_last_reply = $request['dba']->getRow("SELECT * FROM " . K4POSTS . " WHERE post_id <> " . intval($post['post_id']) . " AND parent_id=" . intval($post['parent_id']) . " ORDER BY created DESC LIMIT 1");
         $topic_update = $request['dba']->prepareStatement("UPDATE " . K4POSTS . " SET lastpost_created=?,lastpost_uname=?,lastpost_uid=?,lastpost_id=?,num_replies=? WHERE post_id=?");
         $topic_update->setInt(1, $topic_last_reply['created']);
         $topic_update->setString(2, $topic_last_reply['poster_name']);
         $topic_update->setInt(3, $topic_last_reply['poster_id']);
         $topic_update->setInt(4, $topic_last_reply['post_id']);
         $topic_update->setInt(5, intval($request['dba']->getValue("SELECT COUNT(*) FROM " . K4POSTS . " WHERE parent_id=" . intval($post['parent_id'])) - 1));
         // use this to make sure we get the right count
         $topic_update->setInt(6, $post['parent_id']);
         $topic_update->executeUpdate();
     }
     /**
      * Remove any bad post reports, get a count of replies, change
      * user post counts and remove attachments! WOAH!
      */
     $num_replies_to_remove = 1;
     if ($this->row_type & REPLY) {
         $request['dba']->executeUpdate("DELETE FROM " . K4BADPOSTREPORTS . " WHERE post_id = " . intval($post['post_id']));
     } else {
         $posts = $request['dba']->executeQuery("SELECT post_id,poster_id,attachments FROM " . K4POSTS . " WHERE ( (parent_id=" . intval($post['post_id']) . " AND row_type=" . REPLY . ") OR (post_id=" . intval($post['post_id']) . " AND row_type=" . TOPIC . ") )");
         $num_replies_to_remove = intval($posts->numrows() - 1);
         while ($posts->next()) {
             $p = $posts->current();
             // remove bad post report
             $request['dba']->executeUpdate("DELETE FROM " . K4BADPOSTREPORTS . " WHERE post_id = " . intval($p['post_id']));
             // change user post count
             if ($delete_topic || $this->row_type & REPLY) {
                 $request['dba']->executeUpdate("UPDATE " . K4USERINFO . " SET num_posts=num_posts-1 WHERE user_id=" . intval($p['poster_id']));
             }
             if ($p['attachments'] > 0) {
                 remove_attachments($request, $p, FALSE);
             }
         }
     }
     /**
      * Delete/Move the post 
      */
     if ($delete_topic || $this->row_type & REPLY) {
         $request['dba']->executeUpdate("DELETE FROM " . K4POSTS . " WHERE post_id = " . intval($post['post_id']));
         // change or remove replies
         if ($this->row_type & REPLY) {
             $request['dba']->executeUpdate("UPDATE " . K4POSTS . " SET row_order=row_order-1 WHERE row_order>" . intval($post['row_order']) . " AND post_id=" . intval($post['forum_id']));
         } else {
             $request['dba']->executeUpdate("DELETE FROM " . K4POSTS . " WHERE parent_id=" . intval($post['post_id']));
             $request['dba']->executeUpdate("DELETE FROM " . K4RATINGS . " WHERE post_id = " . intval($post['post_id']));
         }
     } else {
         /* Move this topic and its replies to the garbage bin */
         if ($this->row_type & TOPIC) {
             // parent_id is left as the current forum id
             $request['dba']->executeUpdate("UPDATE " . K4POSTS . " SET forum_id=" . GARBAGE_BIN . " WHERE ( (parent_id=" . intval($post['post_id']) . " AND row_type=" . REPLY . ") OR post_id=" . intval($post['post_id']) . ")");
             // update the garbage bin
             $newpost_created = $request['dba']->getRow("SELECT * FROM " . K4POSTS . " WHERE forum_id=" . GARBAGE_BIN . " ORDER BY created DESC LIMIT 1");
             $forum_update = $request['dba']->prepareStatement("UPDATE " . K4FORUMS . " SET posts=posts+?,replies=replies+?,topics=topics+?,post_created=?,post_name=?,post_uname=?,post_id=?,post_uid=?,post_posticon=? WHERE forum_id=?");
             $forum_update->setInt(1, $this->row_type & REPLY ? $num_replies_to_remove : $num_replies_to_remove + 1);
             $forum_update->setInt(2, $num_replies_to_remove);
             $forum_update->setInt(3, $this->row_type & REPLY ? 0 : 1);
             $forum_update->setInt(4, $newpost_created['created']);
             $forum_update->setString(5, $newpost_created['name']);
             $forum_update->setString(6, $newpost_created['poster_name']);
             $forum_update->setInt(7, $newpost_created['post_id']);
             $forum_update->setInt(8, $newpost_created['poster_id']);
             $forum_update->setString(9, $newpost_created['posticon']);
             $forum_update->setInt(10, GARBAGE_BIN);
             $forum_update->executeUpdate();
         }
     }
     /* Get that last post in this forum that's not part of/from this topic */
     $lastpost_created = $request['dba']->getRow("SELECT * FROM " . K4POSTS . " WHERE forum_id=" . intval($post['forum_id']) . " ORDER BY created DESC LIMIT 1");
     if (!is_array($lastpost_created) || empty($lastpost_created)) {
         $lastpost_created = array('created' => 0, 'name' => '', 'poster_name' => '', 'post_id' => 0, 'poster_id' => 0, 'posticon' => '');
     }
     /**
      * Update the forum and the datastore
      */
     $forum_update = $request['dba']->prepareStatement("UPDATE " . K4FORUMS . " SET posts=posts-?,replies=replies-?,topics=topics-?,post_created=?,post_name=?,post_uname=?,post_id=?,post_uid=?,post_posticon=? WHERE forum_id=?");
     /* Set the forum values */
     $forum_update->setInt(1, $this->row_type & REPLY ? $num_replies_to_remove : $num_replies_to_remove + 1);
     $forum_update->setInt(2, $num_replies_to_remove);
     $forum_update->setInt(3, $this->row_type & REPLY ? 0 : 1);
     $forum_update->setInt(4, $lastpost_created['created']);
     $forum_update->setString(5, $lastpost_created['name']);
     $forum_update->setString(6, $lastpost_created['poster_name']);
     $forum_update->setInt(7, $lastpost_created['post_id']);
     $forum_update->setInt(8, $lastpost_created['poster_id']);
     $forum_update->setString(9, $lastpost_created['posticon']);
     $forum_update->setInt(10, $forum['forum_id']);
     $forum_update->executeUpdate();
     /* Set the datastore values */
     if ($delete_topic || $this->row_type & REPLY) {
         $datastore_update = $request['dba']->prepareStatement("UPDATE " . K4DATASTORE . " SET data=? WHERE varname=?");
         $datastore = $_DATASTORE['forumstats'];
         $datastore['num_replies'] = $request['dba']->getValue("SELECT COUNT(*) FROM " . K4POSTS . " WHERE row_type=" . REPLY);
         $datastore['num_topics'] = $request['dba']->getValue("SELECT COUNT(*) FROM " . K4POSTS . " WHERE row_type=" . TOPIC);
         $datastore_update->setString(1, serialize($datastore));
         $datastore_update->setString(2, 'forumstats');
         /* Execute datastore update query */
         $datastore_update->executeUpdate();
         // Update the datastore cache
         reset_cache('datastore');
     }
     $request['dba']->commitTransaction();
     /* Redirect the user */
     $action = new K4InformationAction(new K4LanguageElement($this->row_type & REPLY ? 'L_DELETEDREPLY' : 'L_DELETEDTOPIC', $post['name']), 'content', FALSE, $this->row_type & REPLY ? 'viewtopic.php?id=' . $post['parent_id'] : 'viewforum.php?f=' . $post['forum_id'], 3);
     return $action->execute($request);
 }
示例#23
0
 function execute(&$request)
 {
     global $_QUERYPARAMS;
     /* set the breadcrumbs bit */
     k4_bread_crumbs($request['template'], $request['dba'], 'L_INFORMATION');
     /* Check the request ID */
     if (!isset($_REQUEST['id']) || !$_REQUEST['id'] || intval($_REQUEST['id']) == 0) {
         $action = new K4InformationAction(new K4LanguageElement('L_FORUMDOESNTEXIST'), 'content', FALSE);
         return $action->execute($request);
     }
     $forum = $request['dba']->getRow("SELECT * FROM " . K4FORUMS . " WHERE forum_id = " . intval($_REQUEST['id']));
     /* Check the forum data given */
     if (!$forum || !is_array($forum) || empty($forum)) {
         $action = new K4InformationAction(new K4LanguageElement('L_FORUMDOESNTEXIST'), 'content', FALSE);
         return $action->execute($request);
     }
     /* Make sure the we are trying to post into a forum */
     if (!($forum['row_type'] & FORUM) || $forum['forum_id'] == GARBAGE_BIN) {
         no_perms_error($request);
         return TRUE;
     }
     $is_poll = isset($_REQUEST['poll']) && intval($_REQUEST['poll']) == 1 ? TRUE : FALSE;
     $perm = $is_poll ? 'polls' : 'topics';
     /* Do we have permission to post to this forum? */
     if ($request['user']->get('perms') < get_map($perm, 'can_add', array('forum_id' => $forum['forum_id']))) {
         no_perms_error($request);
         return TRUE;
     }
     /* Prevent post flooding */
     $last_topic = $request['dba']->getRow("SELECT * FROM " . K4POSTS . " WHERE poster_ip = '" . USER_IP . "' ORDER BY created DESC LIMIT 1");
     $last_reply = $request['dba']->getRow("SELECT * FROM " . K4POSTS . " WHERE poster_ip = '" . USER_IP . "' ORDER BY created DESC LIMIT 1");
     if (is_array($last_topic) && !empty($last_topic)) {
         if (intval($last_topic['created']) + POST_IMPULSE_LIMIT > time() && $request['user']->get('perms') < MODERATOR) {
             $action = new K4InformationAction(new K4LanguageElement('L_MUSTWAITSECSTOPOST'), 'content', TRUE);
             return $action->execute($request);
         }
     }
     if (is_array($last_reply) && !empty($last_reply)) {
         if (intval($last_reply['created']) + POST_IMPULSE_LIMIT > time() && $request['user']->get('perms') < MODERATOR) {
             $action = new K4InformationAction(new K4LanguageElement('L_MUSTWAITSECSTOPOST'), 'content', TRUE);
             return $action->execute($request);
         }
     }
     /**
      * Start setting useful template information
      */
     if ($is_poll) {
         $request['template']->setVar('poll', 1);
     }
     /* Get and set the emoticons and post icons to the template */
     $emoticons = $request['dba']->executeQuery("SELECT * FROM " . K4EMOTICONS . " WHERE clickable = 1");
     $posticons = $request['dba']->executeQuery("SELECT * FROM " . K4POSTICONS);
     $request['template']->setList('emoticons', $emoticons);
     $request['template']->setList('posticons', $posticons);
     $request['template']->setVar('emoticons_per_row', $request['template']->getVar('smcolumns'));
     $request['template']->setVar('emoticons_per_row_remainder', $request['template']->getVar('smcolumns') - 1);
     topic_post_options($request['template'], $request['user'], $forum);
     /* Set the forum info to the template */
     foreach ($forum as $key => $val) {
         $request['template']->setVar('forum_' . $key, $val);
     }
     $request['template']->setVar('newtopic_action', 'newtopic.php?act=posttopic');
     // set the default number of available attachments to 0
     // if a draft is loaded, we might subtract from that ;)
     $num_attachments = 0;
     /**
      * Get topic drafts for this forum
      */
     $body_text = '';
     $drafts = $request['dba']->executeQuery("SELECT * FROM " . K4POSTS . " WHERE forum_id = " . intval($forum['forum_id']) . " AND is_draft = 1 AND poster_id = " . intval($request['user']->get('id')));
     if ($drafts->numrows() > 0) {
         $request['template']->setVisibility('load_button', TRUE);
         if (isset($_REQUEST['load_drafts']) && $_REQUEST['load_drafts'] == 1) {
             $request['template']->setVisibility('load_button', FALSE);
             $request['template']->setFile('drafts', 'post_drafts.html');
             $request['template']->setList('drafts', $drafts);
         }
         if (isset($_REQUEST['draft']) && intval($_REQUEST['draft']) != 0) {
             /* Get our topic */
             $draft = $request['dba']->getRow("SELECT * FROM " . K4POSTS . " WHERE post_id=" . intval($_REQUEST['draft']) . " AND is_draft=1 AND poster_id=" . intval($request['user']->get('id')));
             if (!$draft || !is_array($draft) || empty($draft)) {
                 k4_bread_crumbs($request['template'], $request['dba'], 'L_INVALIDDRAFT');
                 $action = new K4InformationAction(new K4LanguageElement('L_DRAFTDOESNTEXIST'), 'content', FALSE);
                 return $action->execute($request);
             }
             $request['template']->setVar('attach_post_id', $draft['post_id']);
             $request['template']->setVar('newtopic_action', 'newtopic.php?act=postdraft');
             //$action = new K4InformationAction(new K4LanguageElement('L_DRAFTLOADED'), 'drafts', FALSE);
             /* Turn the draft text back into bbcode */
             $parser =& new BBParser();
             $draft['body_text'] = $parser->revert($draft['body_text']);
             $body_text = $draft['body_text'];
             $request['template']->setVisibility('save_draft', FALSE);
             $request['template']->setVisibility('load_button', FALSE);
             $request['template']->setVisibility('edit_topic', TRUE);
             $request['template']->setVisibility('post_id', TRUE);
             $request['template']->setVisibility('br', TRUE);
             $num_attachments = $draft['attachments'];
             /* Assign the draft information to the template */
             foreach ($draft as $key => $val) {
                 $request['template']->setVar('post_' . $key, $val);
             }
             if ($request['template']->getVar('nojs') == 0) {
                 post_attachment_options($request, $forum, $draft);
             }
             //$action->execute($request);
         }
     }
     /**
      * Deal with file attachments
      */
     if ($request['template']->getVar('nojs') == 0) {
         if ($request['template']->getVar('attach_inputs') == '') {
             if ($request['user']->get('perms') >= get_map('attachments', 'can_add', array('forum_id' => $forum['forum_id']))) {
                 $num_attachments = $request['template']->getVar('nummaxattaches') - $num_attachments;
                 $attach_inputs = '';
                 for ($i = 1; $i <= $num_attachments; $i++) {
                     $attach_inputs .= '<br /><input type="file" class="inputbox" name="attach' . $i . '" id="attach' . $i . '" value="" size="55" />';
                 }
                 $request['template']->setVar('attach_inputs', $attach_inputs);
             }
         }
     }
     /* Create our editor */
     create_editor($request, $body_text, 'post', $forum);
     /* set the breadcrumbs bit */
     k4_bread_crumbs($request['template'], $request['dba'], 'L_POSTTOPIC', $forum);
     /* Set the post topic form */
     $request['template']->setVar('is_topic', 1);
     $request['template']->setFile('content', 'newtopic.html');
     $request['template']->setVar('forum_forum_id', $forum['forum_id']);
     $request['template']->setVisibility('post_topic', TRUE);
     $request['template']->setVar('L_TITLETOOSHORT', sprintf($request['template']->getVar('L_TITLETOOSHORT'), $request['template']->getVar('topicminchars'), $request['template']->getVar('topicmaxchars')));
     return TRUE;
 }
示例#24
0
 function Execute(&$template, $request, &$dba, &$session, &$user)
 {
     global $_QUERYPARAMS;
     /* Check the request ID */
     if (!isset($request['id']) || !$request['id'] || intval($request['id']) == 0) {
         /* set the breadcrumbs bit */
         $template = BreadCrumbs($template, $template->getVar('L_INVALIDFORUM'));
         return $template->setInfo('content', $template->getVar('L_FORUMDOESNTEXIST'), FALSE);
     }
     $forum = $dba->getRow("SELECT " . $_QUERYPARAMS['info'] . $_QUERYPARAMS['forum'] . " FROM " . FORUMS . " f LEFT JOIN " . INFO . " i ON f.forum_id = i.id WHERE i.id = " . intval($request['id']));
     /* Check the forum data given */
     if (!$forum || !is_array($forum) || empty($forum)) {
         /* set the breadcrumbs bit */
         $template = BreadCrumbs($template, $template->getVar('L_INVALIDFORUM'));
         $template->setInfo('content', $template->getVar('L_FORUMDOESNTEXIST'), FALSE);
         return TRUE;
     }
     /* Make sure the we are trying to post into a forum */
     if (!($forum['row_type'] & FORUM)) {
         /* set the breadcrumbs bit */
         $template = BreadCrumbs($template, $template->getVar('L_INFORMATION'));
         $template->setInfo('content', $template->getVar('L_CANTPOSTTOCATEGORY'), FALSE);
         return TRUE;
     }
     $is_poll = isset($request['poll']) && intval($request['poll']) == 1 ? TRUE : FALSE;
     $perm = $is_poll ? 'polls' : 'topics';
     /* Do we have permission to post to this forum? */
     if ($user['perms'] < get_map($user, $perm, 'can_add', array('forum_id' => $forum['id']))) {
         /* set the breadcrumbs bit */
         $template = BreadCrumbs($template, $template->getVar('L_INFORMATION'));
         $template->setInfo('content', $template->getVar('L_PERMCANTPOST'), FALSE);
         return TRUE;
     }
     /* Prevent post flooding */
     $last_topic = $dba->getRow("SELECT " . $_QUERYPARAMS['info'] . $_QUERYPARAMS['topic'] . " FROM " . TOPICS . " t LEFT JOIN " . INFO . " i ON t.topic_id = i.id WHERE t.poster_ip = '" . USER_IP . "' ORDER BY i.created DESC LIMIT 1");
     $last_reply = $dba->getRow("SELECT " . $_QUERYPARAMS['info'] . $_QUERYPARAMS['reply'] . " FROM " . REPLIES . " r LEFT JOIN " . INFO . " i ON r.reply_id = i.id WHERE r.poster_ip = '" . USER_IP . "' ORDER BY i.created DESC LIMIT 1");
     if (is_array($last_topic) && !empty($last_topic)) {
         if (intval($last_topic['created']) + POST_IMPULSE_LIMIT > time()) {
             /* set the breadcrumbs bit */
             $template = BreadCrumbs($template, $template->getVar('L_INFORMATION'));
             $template->setInfo('content', $template->getVar('L_MUSTWAITSECSTOPOST'), TRUE);
             return TRUE;
         }
     }
     if (is_array($last_reply) && !empty($last_reply)) {
         if (intval($last_reply['created']) + POST_IMPULSE_LIMIT > time()) {
             /* set the breadcrumbs bit */
             $template = BreadCrumbs($template, $template->getVar('L_INFORMATION'));
             $template->setInfo('content', $template->getVar('L_MUSTWAITSECSTOPOST'), TRUE);
             return TRUE;
         }
     }
     /**
      * Start setting useful template information
      */
     if ($is_poll) {
         $template->setVar('poll', 1);
     }
     /* Get and set the emoticons and post icons to the template */
     $emoticons =& $dba->executeQuery("SELECT * FROM " . EMOTICONS . " WHERE clickable = 1");
     $posticons =& $dba->executeQuery("SELECT * FROM " . POSTICONS);
     $template->setList('emoticons', $emoticons);
     $template->setList('posticons', $posticons);
     $template->setVar('emoticons_per_row', $template->getVar('smcolumns'));
     $template->setVar('emoticons_per_row_remainder', $template->getVar('smcolumns') - 1);
     $template = topic_post_options($template, $user, $forum);
     /* Set the forum info to the template */
     foreach ($forum as $key => $val) {
         $template->setVar('forum_' . $key, $val);
     }
     $template->setVar('newtopic_action', 'newtopic.php?act=posttopic');
     /**
      * Get topic drafts for this forum
      */
     $drafts = $dba->executeQuery("SELECT " . $_QUERYPARAMS['info'] . $_QUERYPARAMS['topic'] . " FROM " . TOPICS . " t LEFT JOIN " . INFO . " i ON t.topic_id = i.id WHERE t.forum_id = " . intval($forum['id']) . " AND t.is_draft = 1 AND t.poster_id = " . intval($user['id']));
     if ($drafts->numrows() > 0) {
         $template->show('load_button');
         if (isset($request['load_drafts']) && $request['load_drafts'] == 1) {
             $template->hide('load_button');
             $template->setFile('drafts', 'post_drafts.html');
             $template->setList('drafts', $drafts);
         }
         if (isset($request['draft']) && intval($request['draft']) != 0) {
             /* Get our topic */
             $draft = $dba->getRow("SELECT " . $_QUERYPARAMS['info'] . $_QUERYPARAMS['topic'] . " FROM " . TOPICS . " t LEFT JOIN " . INFO . " i ON t.topic_id = i.id WHERE i.id = " . intval($request['draft']) . " AND t.is_draft = 1 AND t.poster_id = " . intval($user['id']));
             if (!$draft || !is_array($draft) || empty($draft)) {
                 /* set the breadcrumbs bit */
                 $template = BreadCrumbs($template, $template->getVar('L_INVALIDDRAFT'));
                 $template->setInfo('content', $template->getVar('L_DRAFTDOESNTEXIST'), FALSE);
                 return TRUE;
             }
             $template->setVar('newtopic_action', 'newtopic.php?act=postdraft');
             $template->setInfo('drafts', $template->getVar('L_DRAFTLOADED'), FALSE, '<br />');
             /* Turn the draft text back into bbcode */
             $bbcode = new BBCodex($user, $draft['body_text'], $forum['id'], TRUE, TRUE, TRUE, TRUE);
             $draft['body_text'] = $bbcode->revert();
             $template->hide('save_draft');
             $template->hide('load_button');
             $template->show('edit_topic');
             $template->show('topic_id');
             /* Assign the draft information to the template */
             foreach ($draft as $key => $val) {
                 $template->setVar('topic_' . $key, $val);
             }
         }
     }
     /* set the breadcrumbs bit */
     $template = BreadCrumbs($template, $template->getVar('L_POSTTOPIC'), $forum['row_left'], $forum['row_right']);
     /* Set the post topic form */
     $template->setFile('content', 'newtopic.html');
     return TRUE;
 }
示例#25
0
 function Execute(&$template, $request, &$dba, &$session, &$user)
 {
     global $_URL, $_QUERYPARAMS, $_USERGROUPS, $_SESS;
     /**
      * Error Checking
      */
     if (!isset($request['id']) || !$request['id'] || intval($request['id']) == 0) {
         /* set the breadcrumbs bit */
         $template = BreadCrumbs($template, $template->getVar('L_INVALIDTOPIC'));
         $template->setInfo('content', $template->getVar('L_TOPICDOESNTEXIST'), FALSE);
         return TRUE;
     }
     /* Get our topic */
     $topic = $dba->getRow("SELECT " . $_QUERYPARAMS['info'] . $_QUERYPARAMS['topic'] . " FROM " . TOPICS . " t LEFT JOIN " . INFO . " i ON t.topic_id = i.id WHERE i.id = " . intval($request['id']));
     if (!$topic || !is_array($topic) || empty($topic)) {
         /* set the breadcrumbs bit */
         $template = BreadCrumbs($template, $template->getVar('L_INVALIDTOPIC'));
         $template->setInfo('content', $template->getVar('L_TOPICDOESNTEXIST'), FALSE);
         return TRUE;
     }
     if ($topic['is_draft'] == 1) {
         /* set the breadcrumbs bit */
         $template = BreadCrumbs($template, $template->getVar('L_INVALIDTOPICVIEW'));
         $template->setInfo('content', $template->getVar('L_CANTVIEWDRAFT'), FALSE);
         return TRUE;
     }
     if ($topic['queue'] == 1) {
         /* set the breadcrumbs bit */
         $template = BreadCrumbs($template, $template->getVar('L_INVALIDTOPICVIEW'));
         $template->setInfo('content', $template->getVar('L_TOPICPENDINGMOD'), FALSE);
         return TRUE;
     }
     if ($topic['display'] == 0) {
         /* set the breadcrumbs bit */
         $template = BreadCrumbs($template, $template->getVar('L_INVALIDTOPICVIEW'));
         $template->setInfo('content', $template->getVar('L_TOPICISHIDDEN'), FALSE);
         return TRUE;
     }
     /* Get the current forum */
     $forum = $dba->getRow("SELECT " . $_QUERYPARAMS['info'] . $_QUERYPARAMS['forum'] . " FROM " . FORUMS . " f LEFT JOIN " . INFO . " i ON f.forum_id = i.id WHERE i.id = " . intval($topic['forum_id']));
     if (!$forum || !is_array($forum) || empty($forum)) {
         /* set the breadcrumbs bit */
         $template = BreadCrumbs($template, $template->getVar('L_INVALIDFORUM'));
         $template->setInfo('content', $template->getVar('L_FORUMDOESNTEXIST'), FALSE);
         return TRUE;
     }
     if (get_map($user, 'forums', 'can_view', array()) > $user['perms'] || get_map($user, 'topics', 'can_view', array('forum_id' => $forum['id'])) > $user['perms']) {
         /* set the breadcrumbs bit */
         $template = BreadCrumbs($template, $template->getVar('L_INFORMATION'), $forum['row_left'], $forum['row_right']);
         $template->setInfo('content', $template->getVar('L_PERMCANTVIEWTOPIC'), FALSE);
         return TRUE;
     }
     /**
      * Set the new breadcrumbs bit
      */
     $template = BreadCrumbs($template, $topic['name'], iif($topic['topic_type'] == TOPIC_GLOBAL, FALSE, $forum['row_left']), iif($topic['topic_type'] == TOPIC_GLOBAL, FALSE, $forum['row_right']));
     /** 
      * Get the users Browsing this topic 
      */
     /* Set the extra SQL query fields to check */
     $extra = " AND s.location_file = '" . $dba->Quote($_URL->file) . "' AND s.location_id = " . intval($topic['id']);
     $expired = time() - ini_get('session.gc_maxlifetime');
     $num_online_total = $dba->getValue("SELECT COUNT(s.id) FROM " . SESSIONS . " s WHERE s.seen >= {$expired} {$extra}");
     if ($num_online_total > 0) {
         $users_browsing =& new OnlineUsersIterator($extra);
         /* Set the users browsing list */
         $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'];
         $template->setVar('num_online_members', $stats['num_online_members']);
         $template->setVar('users_browsing', $template->getVar('L_USERSBROWSINGTOPIC'));
         $template->setVar('online_stats', sprintf($template->getVar('L_USERSBROWSINGSTATS'), $stats['num_online_total'], $stats['num_online_members'], $stats['num_guests'], $stats['num_invisible']));
         /* Set the User's Browsing file */
         $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);
         $template->setList('usergroups_legend', $groups);
     }
     /**
      * Is this topic expired?
      */
     $extra = '';
     if ($topic['topic_type'] > TOPIC_NORMAL && $topic['topic_expire'] > 0) {
         if ($topic['created'] + 3600 * 24 * $topic['topic_expire'] > time()) {
             $extra = ",topic_expire=0,topic_type=" . TOPIC_NORMAL;
         }
     }
     /**
      * Is this user subscribed to this topic?
      */
     $subscription = $dba->getRow("SELECT * FROM " . SUBSCRIPTIONS . " WHERE topic_id = " . intval($topic['id']) . " AND user_id = " . intval($user['id']));
     if (is_array($subscription) && !empty($subscription)) {
         if ($subscription['last_visit'] < $topic['reply_time']) {
             /* Set the user to keep subscribing to this topic */
             $dba->executeUpdate("UPDATE " . SUBSCRIPTIONS . " SET requires_revisit = 0, last_visit = " . time() . " WHERE topic_id = " . intval($topic['id']) . " AND user_id = " . intval($user['id']));
         }
     }
     /* Add the topic info to the template */
     foreach ($topic as $key => $val) {
         $template->setVar('topic_' . $key, $val);
     }
     /* Update the number of views for this topic */
     $dba->executeUpdate("UPDATE " . TOPICS . " SET views=views+1 {$extra} WHERE topic_id=" . intval($topic['id']));
     $resultsperpage = $forum['postsperpage'];
     $num_results = @(($topic['row_right'] - $topic['row_left'] - 1) / 2);
     $perpage = isset($request['limit']) && ctype_digit($request['limit']) && intval($request['limit']) > 0 ? intval($request['limit']) : $resultsperpage;
     $num_pages = ceil($num_results / $perpage);
     $page = isset($request['page']) && ctype_digit($request['page']) && intval($request['page']) > 0 ? intval($request['page']) : 1;
     $pager =& new TPL_Paginator($_URL, $num_results, $page, $perpage);
     if ($num_results > $perpage) {
         $template->setPager('replies_pager', $pager);
     }
     /* Outside valid page range, redirect */
     if (!$pager->hasPage($page) && $num_results > $resultsperpage) {
         $template->setInfo('content', $template->getVar('L_PASTPAGELIMIT'));
         $template->setRedirect('viewtopic.php?id=' . $topic['id'] . '&limit=' . $perpage . '&page=' . $num_pages, 3);
     }
     $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? */
     $result =& $dba->executeQuery("SELECT " . $_QUERYPARAMS['info'] . $_QUERYPARAMS['topic'] . " FROM " . TOPICS . " t LEFT JOIN " . INFO . " i ON t.topic_id = i.id WHERE ((lower(i.name) LIKE lower('%" . $dba->quote($topic['name']) . "%') OR lower(i.name) LIKE lower('%" . $dba->quote($topic['body_text']) . "%')) OR (lower(t.body_text) LIKE lower('%" . $dba->quote($topic['name']) . "%') OR lower(t.body_text) LIKE lower('%" . $dba->quote($topic['body_text']) . "%'))) AND t.is_draft = 0 AND i.id <> " . intval($topic['id']));
     if ($result->numrows() > 0) {
         $it =& new TopicsIterator($result, &$session, $template->getVar('IMG_DIR'), $forum);
         $template->setList('similar_topics', $it);
         $template->setFile('similar_topics', 'similar_topics.html');
     }
     /* set the topic iterator */
     $topic_list =& new TopicIterator($topic, TRUE);
     $template->setList('topic', $topic_list);
     $template->setVar('next_oldest', intval($dba->getValue("SELECT id FROM " . INFO . " WHERE id < " . $topic['id'] . " AND row_type = " . TOPIC . " LIMIT 1")));
     $template->setVar('next_newest', intval($dba->getValue("SELECT id FROM " . INFO . " WHERE id > " . $topic['id'] . " AND row_type = " . TOPIC . " LIMIT 1")));
     /* Set the file we need */
     $template->setFile('content', 'viewtopic.html');
     return TRUE;
 }
示例#26
0
 function execute(&$request)
 {
     if (isset($_REQUEST['forum_id']) && intval($_REQUEST['forum_id']) != 0) {
         $forum = $request['dba']->getRow("SELECT * FROM " . K4FORUMS . " WHERE forum_id = " . intval($_REQUEST['forum_id']));
         if (!is_array($forum) || empty($forum)) {
             exit;
         }
     } else {
         exit;
     }
     if ($request['user']->get('perms') < get_map($request['user'], 'attachments', 'can_add', array('forum_id' => $forum['forum_id']))) {
         exit;
     }
     $num_attachments = 0;
     $post_id = 0;
     $row_type = 0;
     $parent_id = 0;
     // check for a post id and add attachments accordingly
     if (isset($_REQUEST['post_id']) && intval($_REQUEST['post_id']) > 0) {
         $post = $request['dba']->getRow("SELECT * FROM " . K4POSTS . " WHERE post_id=" . intval($_REQUEST['post_id']) . " AND poster_id=" . intval($request['user']->get('id')));
         if (!$post || !is_array($post) || empty($post)) {
             exit;
         }
         $post_id = $post['post_id'];
         $row_type = $post['row_type'];
         $parent_id = $post['parent_id'];
     } else {
         $post = array('post_id' => $post_id, 'parent_id' => $parent_id, 'row_type' => $row_type);
     }
     $result = attach_files($request, $forum, $post);
     $error_str = '';
     if (is_array($result) && !empty($result)) {
         $error_str = implode('|', $result);
     }
     header("Location: misc.php?act=attachments_manager&post_id=" . $post['post_id'] . "&forum_id=" . $forum['forum_id'] . "&error=" . $error_str);
     return TRUE;
 }
示例#27
0
 function execute(&$request)
 {
     /* set the breadcrumbs bit */
     k4_bread_crumbs($request['template'], $request['dba'], 'L_INFORMATION');
     $rss_version = isset($_REQUEST['v']) && intval($_REQUEST['v']) == 2 ? '2.0' : '0.92';
     $request['template']->setVar('xml_definition', "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n");
     /**
      * Forum
      */
     if (isset($_REQUEST['f']) && intval($_REQUEST['f']) > 0) {
         $forum = $request['dba']->getRow("SELECT * FROM " . K4FORUMS . " WHERE forum_id = " . intval($_REQUEST['f']));
         if (!is_array($forum) || empty($forum)) {
             $action = new K4InformationAction(new K4LanguageElement('L_FORUMDOESNTEXIST'), 'content', FALSE);
             return $action->execute($request);
         }
         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);
         }
         k4_bread_crumbs($request['template'], $request['dba'], NULL, $forum);
         /**
          * Pagination
          */
         //$extra_topics		= intval(@$_ALLFORUMS[GLBL_ANNOUNCEMENTS]['topics']);
         $extra_topics = 0;
         // TODO: need only Announcements from global announcements
         /* 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;
         $page = isset($_REQUEST['page']) && ctype_digit($_REQUEST['page']) && intval($_REQUEST['page']) > 0 ? intval($_REQUEST['page']) : 1;
         /* 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;
         if ($page == 1) {
             $announcements = $request['dba']->executeQuery("SELECT * FROM " . K4POSTS . " WHERE row_type=" . TOPIC . " AND (is_draft=0 AND display=1) AND post_type = " . TOPIC_ANNOUNCE . " AND (forum_id = " . intval($forum['forum_id']) . " OR forum_id = " . GLBL_ANNOUNCEMENTS . ") ORDER BY lastpost_created DESC");
         }
         $importants = $request['dba']->executeQuery("SELECT * FROM " . K4POSTS . " WHERE row_type=" . TOPIC . " AND is_draft=0 AND display = 1 AND forum_id = " . intval($forum['forum_id']) . " AND (post_type <> " . TOPIC_ANNOUNCE . ") AND (post_type = " . TOPIC_STICKY . " OR is_feature = 1) ORDER BY lastpost_created DESC");
         /* get the topics */
         $result = $request['dba']->prepareStatement("SELECT * FROM " . K4POSTS . " WHERE row_type=" . TOPIC . " AND created>=? AND is_draft=0 AND display = 1 AND forum_id = " . intval($forum['forum_id']) . " AND (post_type <> " . TOPIC_ANNOUNCE . " AND post_type <> " . TOPIC_STICKY . " AND is_feature = 0) ORDER BY {$sortedby} {$sortorder} LIMIT ?,?");
         /* Set the query values */
         $result->setInt(1, $daysprune);
         $result->setInt(2, $start);
         $result->setInt(3, $perpage);
         /* Execute the query */
         $topics = $result->executeQuery();
         if (isset($announcements)) {
             $it = new FAChainedIterator($announcements);
             $it->addIterator($importants);
         } else {
             $it = new FAChainedIterator($importants);
         }
         $it->addIterator($topics);
         $request['template']->setList('topics', new RSSPostIterator($it));
         $request['template']->setVarArray($forum);
         $xml = $request['template']->render(BB_BASE_DIR . '/templates/RSS/rss-' . $rss_version . '/forum.xml');
         header("Content-Type: text/xml");
         echo $xml;
         exit;
         /**
          * Topic
          */
     } else {
         if (isset($_REQUEST['t']) && intval($_REQUEST['t']) > 0) {
             $result = $request['dba']->executeQuery("SELECT * FROM " . K4POSTS . " WHERE post_id=" . intval($_REQUEST['t']) . " LIMIT 1");
             $topic = $result->next();
             $result->reset();
             // reset the pointer of the iterator
             if (!is_array($topic) || empty($topic)) {
                 $action = new K4InformationAction(new K4LanguageElement('L_TOPICDOESNTEXIST'), 'content', FALSE);
                 return $action->execute($request);
             }
             if (get_map('topics', 'can_view', array('forum_id' => $topic['forum_id'])) > $request['user']->get('perms')) {
                 $action = new K4InformationAction(new K4LanguageElement('L_CANTVIEWFORUMTOPICS'), 'content_extra', FALSE);
                 return $action->execute($request);
             }
             $forum = $request['dba']->getRow("SELECT * FROM " . K4FORUMS . " WHERE forum_id = " . intval($topic['forum_id']));
             if (!is_array($forum) || empty($forum)) {
                 $action = new K4InformationAction(new K4LanguageElement('L_FORUMDOESNTEXIST'), 'content', FALSE);
                 return $action->execute($request);
             }
             $it = new FAChainedIterator($result);
             if (get_map('replies', 'can_view', array('forum_id' => $topic['forum_id'])) <= $request['user']->get('perms')) {
                 if ($topic['num_replies'] > 0) {
                     $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;
                     $num_pages = @ceil($num_results / $perpage);
                     $page = isset($_REQUEST['page']) && ctype_digit($_REQUEST['page']) && intval($_REQUEST['page']) > 0 ? intval($_REQUEST['page']) : 1;
                     $daysprune = isset($_REQUEST['daysprune']) && ctype_digit($_REQUEST['daysprune']) ? iif($_REQUEST['daysprune'] == -1, 0, intval($_REQUEST['daysprune'])) : 0;
                     $sortorder = isset($_REQUEST['order']) && ($_REQUEST['order'] == 'ASC' || $_REQUEST['order'] == 'DESC') ? $_REQUEST['order'] : 'ASC';
                     $sortedby = isset($_REQUEST['sort']) && in_array($_REQUEST['sort'], $sort_orders) ? $_REQUEST['sort'] : 'created';
                     $start = ($page - 1) * $perpage;
                     $replies = $request['dba']->executeQuery("SELECT * FROM " . K4POSTS . " WHERE parent_id=" . intval($topic['post_id']) . " AND row_level>1 AND created>=" . 3600 * 24 * intval($daysprune) . " ORDER BY " . $sortedby . " " . $sortorder . " LIMIT " . intval($start) . "," . intval($perpage));
                     $it->addIterator($replies);
                 }
             }
             $request['template']->setList('posts', new RSSPostIterator($it));
             $xml = $request['template']->render(BB_BASE_DIR . '/templates/RSS/rss-' . $rss_version . '/topic.xml');
             header("Content-Type: text/xml");
             echo $xml;
             exit;
             /**
              * Error
              */
         } else {
             no_perms_error($request);
         }
     }
     return TRUE;
 }
示例#28
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;
 }
示例#29
0
 function execute(&$request)
 {
     global $_QUERYPARAMS, $_URL;
     /* Create the ancestors bar */
     k4_bread_crumbs($request['template'], $request['dba'], 'L_MEMBERLIST');
     if (get_map('memberlist', 'can_view', array()) > $request['user']->get('perms')) {
         no_perms_error($request);
         return TRUE;
     }
     $letters =& new K4MemberSortMenu();
     $letters->execute($request);
     $request['template']->setFile('content', 'memberlist.html');
     if (isset($_GET['letter']) && $_REQUEST['letter'] != '*') {
         $like = $request['dba']->quote(strtolower($_REQUEST['letter'])) . '%';
         $letter = strtolower($_REQUEST['letter']);
     } else {
         $letter = '*';
         $like = '%';
     }
     $orders = array('name', 'created', 'last_seen');
     $page = isset($_REQUEST['page']) && ctype_digit($_REQUEST['page']) && intval($_REQUEST['page']) > 0 ? intval($_REQUEST['page']) : 1;
     $limit = isset($_REQUEST['limit']) ? intval($_REQUEST['limit']) : intval($request['template']->getVar('memberlistperpage'));
     $limit = $limit > 100 ? 100 : $limit;
     //$start		= isset($_REQUEST['start']) ? intval($_REQUEST['start']) : 0;
     $start = $limit * $page - $limit;
     $sort = isset($_REQUEST['order']) && in_array($_REQUEST['order'], $orders) ? $_REQUEST['order'] : 'id';
     $order = isset($_REQUEST['order']) && $_REQUEST['order'] == 'DESC' ? 'DESC' : 'ASC';
     $num_results = $request['dba']->getValue("SELECT COUNT(*) FROM " . K4USERS . " WHERE name LIKE '{$like}'");
     $result = $request['dba']->executeQuery("SELECT " . $_QUERYPARAMS['user'] . $_QUERYPARAMS['userinfo'] . " FROM " . K4USERS . " u LEFT JOIN " . K4USERINFO . " ui ON u.id=ui.user_id WHERE name LIKE '{$like}' ORDER BY {$sort} {$order} LIMIT {$start},{$limit}");
     $url = new FAUrl($_URL->__toString());
     /* Create the Pagination */
     $num_pages = ceil($num_results / $limit);
     $pager =& new FAPaginator($url, $num_results, $page, $limit);
     if ($num_results > $limit) {
         $request['template']->setPager('memberlist_pager', $pager);
         /* Create a friendly url for our pager jump */
         $page_jumper = new FAUrl($_URL->__toString());
         $page_jumper->args['limit'] = $limit;
         $page_jumper->args['page'] = FALSE;
         $page_jumper->anchor = FALSE;
         $request['template']->setVar('pagejumper_url', preg_replace('~&amp;~i', '&', $page_jumper->__toString()));
     }
     $it = new MemberListIterator($result);
     $request['template']->setVar('ml_letter', $letter);
     $request['template']->setVar('ml_sort', $sort);
     $request['template']->setVar('ml_order', $order);
     $request['template']->setVar('ml_limit', $limit);
     $request['template']->setList('memberlist', $it);
     return TRUE;
 }
示例#30
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;
 }