Example #1
0
 function Execute(&$template, $request, &$dba, &$session, &$user)
 {
     global $_QUERYPARAMS, $_DATASTORE, $_SETTINGS;
     /* 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;
     }
     /* General error checking */
     if (!isset($request['name']) || $request['name'] == '') {
         /* set the breadcrumbs bit */
         $template = BreadCrumbs($template, $template->getVar('L_INFORMATION'), $forum['row_left'], $forum['row_right']);
         $template->setInfo('content', $template->getVar('L_INSERTTOPICNAME'), TRUE);
         return TRUE;
     }
     if (!isset($request['message']) || $request['message'] == '') {
         /* set the breadcrumbs bit */
         $template = BreadCrumbs($template, $template->getVar('L_INFORMATION'), $forum['row_left'], $forum['row_right']);
         $template->setInfo('content', $template->getVar('L_INSERTTOPICMESSAGE'), TRUE);
         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['topic_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;
     }
     $type = $topic['poll'] == 1 ? 'polls' : 'topics';
     /* Does this person have permission to edit this topic? */
     if ($topic['poster_id'] == $user['id']) {
         if (get_map($user, $type, 'can_edit', array('forum_id' => $forum['id'])) > $user['perms']) {
             $template->setInfo('content', $template->getVar('L_YOUNEEDPERMS'), FALSE);
             return TRUE;
         }
     } else {
         if (get_map($user, 'other_' . $type, 'can_edit', array('forum_id' => $forum['id'])) > $user['perms']) {
             $template->setInfo('content', $template->getVar('L_YOUNEEDPERMS'), FALSE);
             return TRUE;
         }
     }
     /* Does this user have permission to edit this topic if it is locked? */
     if ($topic['topic_locked'] == 1 && get_map($user, 'closed', 'can_edit', 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_EDITTOPIC'), $forum['row_left'], $forum['row_right']);
     /* Initialize the bbcode parser with the topic message */
     $request['message'] = substr($request['message'], 0, $_SETTINGS['postmaxchars']);
     $bbcode =& new BBCodex(&$user, $request['message'], $forum['id'], iif(isset($request['disable_html']) && $request['disable_html'] == 'on', FALSE, TRUE), iif(isset($request['disable_bbcode']) && $request['disable_bbcode'] == 'on', FALSE, TRUE), iif(isset($request['disable_emoticons']) && $request['disable_emoticons'] == 'on', FALSE, TRUE), iif(isset($request['disable_aurls']) && $request['disable_aurls'] == 'on', FALSE, TRUE));
     /* Parse the bbcode */
     $body_text = $bbcode->parse();
     $template->setVar('newtopic_action', 'newtopic.php?act=updatetopic');
     /* Get the topic type */
     $topic_type = isset($request['topic_type']) && intval($request['topic_type']) != 0 ? $request['topic_type'] : TOPIC_NORMAL;
     /* Check the topic type and check if this user has permission to post that type of topic */
     if ($topic_type == TOPIC_STICKY && $user['perms'] < get_map($user, 'sticky', 'can_add', array('forum_id' => $forum['id']))) {
         $topic_type = TOPIC_NORMAL;
     } else {
         if ($topic_type == TOPIC_ANNOUNCE && $user['perms'] < get_map($user, 'announce', 'can_add', array('forum_id' => $forum['id']))) {
             $topic_type = TOPIC_NORMAL;
         } else {
             if ($topic_type == TOPIC_GLOBAL && $user['perms'] < get_map($user, 'global', 'can_add', array('forum_id' => $forum['id']))) {
                 $topic_type = TOPIC_NORMAL;
             }
         }
     }
     /* Is this a featured topic? */
     $is_feature = isset($request['is_feature']) && $request['is_feature'] == 'yes' ? 1 : 0;
     if ($is_feature == 1 && $user['perms'] < get_map($user, 'feature', 'can_add', array('forum_id' => $forum['id']))) {
         $is_feature = 0;
     }
     /* If we are saving thos topic */
     if ($request['submit'] == $template->getVar('L_SUBMIT')) {
         /**
          * Build the queries to update the topic
          */
         $update_a = $dba->prepareStatement("UPDATE " . INFO . " SET name=? WHERE id=?");
         $update_b = $dba->prepareStatement("UPDATE " . TOPICS . " SET body_text=?,posticon=?,disable_html=?,disable_bbcode=?,disable_emoticons=?,disable_sig=?,disable_areply=?,disable_aurls=?,is_draft=?,edited_time=?,edited_username=?,edited_userid=?,is_feature=?,topic_type=?,topic_expire=? WHERE topic_id=?");
         $update_a->setString(1, htmlentities($request['name'], ENT_QUOTES));
         $update_a->setInt(2, $topic['id']);
         $update_b->setString(1, $body_text);
         $update_b->setString(2, iif($user['perms'] >= get_map($user, 'posticons', 'can_add', array('forum_id' => $forum['id'])), isset($request['posticon']) ? $request['posticon'] : 'clear.gif', 'clear.gif'));
         $update_b->setInt(3, iif(isset($request['disable_html']) && $request['disable_html'] == 'on', 1, 0));
         $update_b->setInt(4, iif(isset($request['disable_bbcode']) && $request['disable_bbcode'] == 'on', 1, 0));
         $update_b->setInt(5, iif(isset($request['disable_emoticons']) && $request['disable_emoticons'] == 'on', 1, 0));
         $update_b->setInt(6, iif(isset($request['enable_sig']) && $request['enable_sig'] == 'on', 0, 1));
         $update_b->setInt(7, iif(isset($request['disable_areply']) && $request['disable_areply'] == 'on', 1, 0));
         $update_b->setInt(8, iif(isset($request['disable_aurls']) && $request['disable_aurls'] == 'on', 1, 0));
         $update_b->setInt(9, 0);
         $update_b->setInt(10, time());
         $update_b->setString(11, iif($user['id'] <= 0, htmlentities(isset($request['poster_name']) ? $request['poster_name'] : '', ENT_QUOTES), $user['name']));
         $update_b->setInt(12, $user['id']);
         $update_b->setInt(13, $is_feature);
         $update_b->setInt(14, $topic_type);
         $update_b->setInt(15, iif($topic_type > TOPIC_NORMAL, intval(isset($request['topic_expire']) ? $request['topic_expire'] : 0), 0));
         $update_b->setInt(16, $topic['id']);
         /**
          * Do the queries
          */
         $update_a->executeUpdate();
         $update_b->executeUpdate();
         /**
          * Subscribe/Unsubscribe this user to the topic
          */
         $is_subscribed = $dba->getRow("SELECT * FROM " . SUBSCRIPTIONS . " WHERE user_id = " . intval($user['id']) . " AND topic_id = " . intval($topic['id']));
         if (isset($request['disable_areply']) && $request['disable_areply'] == 'on') {
             if (!is_array($is_subscribed) || empty($is_subscribed)) {
                 $subscribe =& $dba->prepareStatement("INSERT INTO " . SUBSCRIPTIONS . " (user_id,user_name,topic_id,forum_id,email,category_id) VALUES (?,?,?,?,?,?)");
                 $subscribe->setInt(1, $user['id']);
                 $subscribe->setString(2, $user['name']);
                 $subscribe->setInt(3, $topic['id']);
                 $subscribe->setInt(4, $forum['id']);
                 $subscribe->setString(5, $user['email']);
                 $subscribe->setInt(6, $forum['category_id']);
                 $subscribe->executeUpdate();
             }
         } else {
             if (!isset($request['disable_areply']) || !$request['disable_areply']) {
                 if (is_array($is_subscribed) && !empty($is_subscribed)) {
                     $subscribe =& $dba->prepareStatement("DELETE FROM " . SUBSCRIPTIONS . " WHERE user_id=? AND topic_id=?");
                     $subscribe->setInt(1, $user['id']);
                     $subscribe->setInt(2, $topic['id']);
                     $subscribe->executeUpdate();
                 }
             }
         }
         /* Redirect the user */
         $template->setInfo('content', sprintf($template->getVar('L_UPDATEDTOPIC'), htmlentities($request['name'], ENT_QUOTES)));
         $template->setRedirect('viewtopic.php?id=' . $topic['id'], 3);
     } else {
         /**
          * Post Previewing
          */
         /* 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);
         $topic_preview = array('id' => @$topic['id'], 'name' => htmlentities($request['name'], ENT_QUOTES), 'posticon' => isset($request['posticon']) ? $request['posticon'] : 'clear.gif', 'body_text' => $body_text, 'poster_name' => html_entity_decode($topic['poster_name'], ENT_QUOTES), 'poster_id' => $user['id'], 'row_left' => 0, 'row_right' => 0, 'topic_type' => $topic_type, 'is_feature' => $is_feature, 'disable_html' => iif(isset($request['disable_html']) && $request['disable_html'] == 'on', 1, 0), 'disable_sig' => iif(isset($request['enable_sig']) && $request['enable_sig'] == 'on', 0, 1), 'disable_bbcode' => iif(isset($request['disable_bbcode']) && $request['disable_bbcode'] == 'on', 1, 0), 'disable_emoticons' => iif(isset($request['disable_emoticons']) && $request['disable_emoticons'] == 'on', 1, 0), 'disable_areply' => iif(isset($request['disable_areply']) && $request['disable_areply'] == 'on', 1, 0), 'disable_aurls' => iif(isset($request['disable_aurls']) && $request['disable_aurls'] == 'on', 1, 0));
         /* Add the topic information to the template */
         $topic_iterator =& new TopicIterator($topic_preview, FALSE);
         $template->setList('topic', $topic_iterator);
         /* Assign the topic preview values to the template */
         $topic_preview['body_text'] = $request['message'];
         foreach ($topic_preview as $key => $val) {
             $template->setVar('topic_' . $key, $val);
         }
         /* Assign the forum information to the template */
         foreach ($forum as $key => $val) {
             $template->setVar('forum_' . $key, $val);
         }
         /* Set the the button display options */
         $template->hide('save_draft');
         $template->hide('load_button');
         $template->show('edit_topic');
         $template->show('topic_id');
         $template->hide('post_topic');
         $template->show('edit_post');
         /* set the breadcrumbs bit */
         $template = BreadCrumbs($template, $template->getVar('L_POSTTOPIC'), $forum['row_left'], $forum['row_right']);
         /* Set the post topic form */
         $template->setFile('preview', 'post_preview.html');
         $template->setFile('content', 'newtopic.html');
     }
     return TRUE;
 }
 function execute(&$request)
 {
     global $_QUERYPARAMS, $_DATASTORE;
     /* set the breadcrumbs bit */
     k4_bread_crumbs($request['template'], $request['dba'], 'L_INFORMATION');
     /* 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_DRAFTDOESNTEXIST'), 'content', FALSE);
         return $action->execute($request);
     }
     $request['template']->setVar('attach_post_id', $topic['post_id']);
     $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 $action->execute($request);
     }
     /* Make sure the we are trying to post into a forum */
     if (!($forum['row_type'] & FORUM)) {
         $action = new K4InformationAction(new K4LanguageElement('L_CANTPOSTTONONFORUM'), 'content', FALSE);
         return $action->execute($request);
     }
     /* set the breadcrumbs bit */
     k4_bread_crumbs($request['template'], $request['dba'], 'L_EDITTOPIC', $topic, $forum);
     if ($topic['poster_id'] == $request['user']->get('id')) {
         if (get_map('topics', '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_topics', '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);
         }
     }
     /* Does this user have permission to edit this topic if it 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);
     }
     post_attachment_options($request, $forum, $topic);
     topic_post_options($request['template'], $request['user'], $forum);
     /* 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);
     $request['template']->setVar('newtopic_action', 'newtopic.php?act=updatetopic');
     $request['template']->setVar('is_topic', 1);
     /* Create our editor */
     create_editor($request, $topic['body_text'], 'post', $forum);
     foreach ($topic 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('save_draft', FALSE);
     $request['template']->setVisibility('load_button', FALSE);
     $request['template']->setVisibility('edit_topic', TRUE);
     $request['template']->setVisibility('post_id', TRUE);
     $request['template']->setVisibility('post_topic', FALSE);
     $request['template']->setVisibility('edit_post', TRUE);
     /* Set the post topic form */
     $request['template']->setVar('forum_forum_id', $forum['forum_id']);
     //$request['template']->setFile('preview', 'post_preview.html');
     $request['template']->setFile('content', 'newtopic.html');
     $request['template']->setVar('L_TITLETOOSHORT', sprintf($request['template']->getVar('L_TITLETOOSHORT'), $request['template']->getVar('topicminchars'), $request['template']->getVar('topicmaxchars')));
     return TRUE;
 }
Example #3
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;
 }
 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;
 }
Example #5
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;
 }
 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['forum_id']) || !$_REQUEST['forum_id'] || intval($_REQUEST['forum_id']) == 0) {
         $action = new K4InformationAction(new K4LanguageElement('L_FORUMDOESNTEXIST'), 'content', FALSE);
         return !USE_XMLHTTP ? $action->execute($request) : xmlhttp_message('L_FORUMDOESNTEXIST');
     }
     $forum = $request['dba']->getRow("SELECT * FROM " . K4FORUMS . " WHERE forum_id=" . intval($_REQUEST['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) : xmlhttp_message('L_FORUMDOESNTEXIST');
     }
     /* Make sure the we are trying to edit in a forum */
     if (!($forum['row_type'] & FORUM) || $forum['forum_id'] == GARBAGE_BIN) {
         $action = new K4InformationAction(new K4LanguageElement('L_CANTEDITTONONFORUM'), 'content', FALSE);
         return !USE_XMLHTTP ? $action->execute($request) : xmlhttp_message('L_CANTEDITTONONFORUM');
     }
     /* General error checking */
     if ($this->row_type & TOPIC) {
         if (!isset($_REQUEST['name']) || $_REQUEST['name'] == '') {
             $action = new K4InformationAction(new K4LanguageElement('L_INSERTTOPICNAME'), 'content', TRUE);
             return !USE_XMLHTTP ? $action->execute($request) : xmlhttp_message('L_INSERTTOPICNAME');
         }
         $len = strlen($_REQUEST['name']);
         if ($len < intval($_SETTINGS['topicminchars']) || $len > 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(new K4LanguageElement('L_TITLETOOSHORT', intval($_SETTINGS['topicminchars']), intval($_SETTINGS['topicmaxchars'])));
         }
     }
     if (!isset($_REQUEST['message']) || $_REQUEST['message'] == '') {
         $action = new K4InformationAction(new K4LanguageElement('L_INSERTTOPICMESSAGE'), 'content', TRUE);
         return !USE_XMLHTTP ? $action->execute($request) : xmlhttp_message('L_INSERTTOPICMESSAGE');
     }
     /* Get our post */
     $post = $request['dba']->getRow("SELECT * FROM " . K4POSTS . " WHERE post_id = " . intval($_REQUEST['post_id']));
     if (!is_array($post) || empty($post)) {
         $action = new K4InformationAction(new K4LanguageElement('L_POSTDOESNTEXIST'), 'content', FALSE);
         return !USE_XMLHTTP ? $action->execute($request) : xmlhttp_message('L_POSTDOESNTEXIST');
     }
     $type = $this->row_type & TOPIC ? 'topics' : 'replies';
     /* Does this person have permission to edit this topic? */
     if ($post['poster_id'] == $request['user']->get('id')) {
         if (get_map($type, 'can_edit', array('forum_id' => $forum['forum_id'])) > $request['user']->get('perms')) {
             $action = new K4InformationAction(new K4LanguageElement('L_YOUNEEDPERMS'), 'content', FALSE);
             return !USE_XMLHTTP ? $action->execute($request) : xmlhttp_message('L_YOUNEEDPERMS');
         }
     } else {
         if (get_map('other_' . $type, 'can_edit', array('forum_id' => $forum['forum_id'])) > $request['user']->get('perms')) {
             $action = new K4InformationAction(new K4LanguageElement('L_YOUNEEDPERMS'), 'content', FALSE);
             return !USE_XMLHTTP ? $action->execute($request) : xmlhttp_message('L_YOUNEEDPERMS');
         }
     }
     if ($post['is_poll'] == 1) {
         // TODO: something here.
     }
     /* Does this user have permission to edit this topic if it is locked? */
     if ($post['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 !USE_XMLHTTP ? $action->execute($request) : xmlhttp_message('L_YOUNEEDPERMS');
     }
     /* set the breadcrumbs bit */
     k4_bread_crumbs($request['template'], $request['dba'], $this->row_type & TOPIC ? 'L_EDITTOPIC' : 'L_EDITREPLY', $post, $forum);
     /* Initialize the bbcode parser with the topic message */
     $_REQUEST['message'] = substr($_REQUEST['message'], 0, $_SETTINGS['postmaxchars']);
     /* Parse the bbcode */
     $body_text = $_REQUEST['message'];
     $submit_type = isset($_REQUEST['submit_type']) ? $_REQUEST['submit_type'] : 'post';
     if (!isset($_REQUEST['disable_bbcode']) || !$_REQUEST['disable_bbcode']) {
         $parser =& new BBParser();
         Globals::setGlobal('forum_id', $forum['forum_id']);
         Globals::setGlobal('maxpolloptions', $request['template']->getVar('maxpolloptions') > $forum['maxpolloptions'] ? $forum['maxpolloptions'] : $request['template']->getVar('maxpolloptions'));
         Globals::setGlobal('maxpollquestions', $request['template']->getVar('maxpollquestions') > $forum['maxpollquestions'] ? $forum['maxpollquestions'] : $request['template']->getVar('maxpollquestions'));
         if ($submit_type == 'post' || isset($_REQUEST['post'])) {
             $parser->register('BBPollNode');
         }
         $body_text = $parser->parse($body_text);
         if ($submit_type == 'post' || isset($_REQUEST['post'])) {
             $body_text = $parser->comparePolls($post['post_id'], $body_text, $post['body_text'], $request['dba']);
         }
         $is_poll = Globals::getGlobal('is_poll');
     }
     // permissions are taken into account inside the poller
     //$poller		= &new K4BBPolls($body_text, $topic['body_text'], $forum, $topic['post_id']);
     $request['template']->setVar('newtopic_action', 'newtopic.php?act=updatetopic');
     if ($this->row_type & TOPIC) {
         /* Get the topic type */
         $post_type = isset($_REQUEST['post_type']) && intval($_REQUEST['post_type']) != 0 ? $_REQUEST['post_type'] : TOPIC_NORMAL;
         /* Check the topic type and check if this user has permission to post that type of topic */
         if ($post_type == TOPIC_STICKY && $request['user']->get('perms') < get_map('sticky', 'can_add', array('forum_id' => $forum['forum_id']))) {
             $post_type = TOPIC_NORMAL;
         } else {
             if ($post_type == TOPIC_ANNOUNCE && $request['user']->get('perms') < get_map('announce', 'can_add', array('forum_id' => $forum['forum_id']))) {
                 $post_type = TOPIC_NORMAL;
             }
         }
         /* Is this a featured topic? */
         $is_feature = isset($_REQUEST['is_feature']) && $_REQUEST['is_feature'] == 'yes' ? 1 : 0;
         if ($is_feature == 1 && $request['user']->get('perms') < get_map('feature', 'can_add', array('forum_id' => $forum['forum_id']))) {
             $is_feature = 0;
         }
     } else {
         $post_type = TOPIC_NORMAL;
         $is_feature = 0;
     }
     /* If we are saving this topic */
     if ($submit_type == 'post' || isset($_REQUEST['post'])) {
         $posticon = iif($request['user']->get('perms') >= get_map('posticons', 'can_add', array('forum_id' => $forum['forum_id'])), isset($_REQUEST['posticon']) ? $_REQUEST['posticon'] : 'clear.gif', 'clear.gif');
         $time = time();
         $name = k4_htmlentities($_REQUEST['name'], ENT_QUOTES);
         /**
          * Build the queries to update the topic
          */
         $update_a = $request['dba']->prepareStatement("UPDATE " . K4POSTS . " SET name=?,body_text=?,posticon=?,disable_html=?,disable_bbcode=?,disable_emoticons=?,disable_sig=?,disable_areply=?,disable_aurls=?,is_draft=?,edited_time=?,edited_username=?,edited_userid=?,is_feature=?,post_type=?,post_expire=?,is_poll=? WHERE post_id=?");
         $update_a->setString(1, $name);
         $update_a->setString(2, $body_text);
         $update_a->setString(3, $posticon);
         $update_a->setInt(4, isset($_REQUEST['disable_html']) && $_REQUEST['disable_html'] ? 1 : 0);
         $update_a->setInt(5, isset($_REQUEST['disable_bbcode']) && $_REQUEST['disable_bbcode'] ? 1 : 0);
         $update_a->setInt(6, isset($_REQUEST['disable_emoticons']) && $_REQUEST['disable_emoticons'] ? 1 : 0);
         $update_a->setInt(7, isset($_REQUEST['enable_sig']) && $_REQUEST['enable_sig'] ? 0 : 1);
         $update_a->setInt(8, isset($_REQUEST['disable_areply']) && $_REQUEST['disable_areply'] ? 1 : 0);
         $update_a->setInt(9, isset($_REQUEST['disable_aurls']) && $_REQUEST['disable_aurls'] ? 1 : 0);
         $update_a->setInt(10, 0);
         $update_a->setInt(11, $time);
         $update_a->setString(12, $request['user']->get('id') <= 0 ? k4_htmlentities(isset($_REQUEST['poster_name']) ? $_REQUEST['poster_name'] : '', ENT_QUOTES) : $request['user']->get('name'));
         $update_a->setInt(13, $request['user']->get('id'));
         $update_a->setInt(14, $is_feature);
         $update_a->setInt(15, $post_type);
         $update_a->setInt(16, $post_type > TOPIC_NORMAL ? intval(isset($_REQUEST['post_expire']) ? $_REQUEST['post_expire'] : 0) : 0);
         $update_a->setInt(17, $is_poll);
         $update_a->setInt(18, $post['post_id']);
         $update_a->executeUpdate();
         /* If this topic is a redirect/ connects to one, update the original */
         if ($this->row_type & TOPIC && ($post['moved_new_post_id'] > 0 || $post['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, $post['moved_new_post_id'] > 0 ? $post['moved_new_post_id'] : $post['moved_old_post_id']);
             $redirect->executeUpdate();
             /**
              * Subscribe/Unsubscribe this user to the topic
              */
             $is_subscribed = $request['dba']->getRow("SELECT * FROM " . K4SUBSCRIPTIONS . " WHERE user_id = " . intval($request['user']->get('id')) . " AND post_id = " . intval($post['post_id']));
             if (isset($_REQUEST['disable_areply']) && $_REQUEST['disable_areply']) {
                 if (!is_array($is_subscribed) || empty($is_subscribed)) {
                     $subscribe = $request['dba']->prepareStatement("INSERT INTO " . K4SUBSCRIPTIONS . " (user_id,post_id,forum_id,email) VALUES (?,?,?,?)");
                     $subscribe->setInt(1, $request['user']->get('id'));
                     $subscribe->setInt(2, $topic['post_id']);
                     $subscribe->setInt(3, $forum['forum_id']);
                     $subscribe->setString(4, $request['user']->get('email'));
                     $subscribe->executeUpdate();
                 }
             } else {
                 if (!isset($_REQUEST['disable_areply']) || !$_REQUEST['disable_areply']) {
                     if (is_array($is_subscribed) && !empty($is_subscribed)) {
                         $subscribe = $request['dba']->prepareStatement("DELETE FROM " . K4SUBSCRIPTIONS . " WHERE user_id=? AND post_id=?");
                         $subscribe->setInt(1, $request['user']->get('id'));
                         $subscribe->setInt(2, $topic['post_id']);
                         $subscribe->executeUpdate();
                     }
                 }
             }
         }
         // deal with attachments
         if ($request['template']->getVar('nojs') == 0) {
             attach_files($request, $forum, $post);
         }
         /* Should we update the forum's last post info? */
         if ($forum['lastpost_id'] == $post['post_id']) {
             // if this topic is the forums last post
             if ($forum['lastpost_id'] == $post['post_id'] && $forum['lastpost_created'] == $post['created']) {
                 $forum_topic_update = $request['dba']->prepareStatement("UPDATE " . K4FORUMS . " SET lastpost_name=?,lastpost_posticon=? WHERE forum_id=?");
                 $forum_topic_update->setString(1, $name);
                 $forum_topic_update->setString(2, $posticon);
                 $forum_topic_update->setInt(3, $forum['forum_id']);
                 $forum_topic_update->executeUpdate();
             }
         }
         /* Redirect the user */
         $action = new K4InformationAction(new K4LanguageElement($this->row_type & TOPIC ? 'L_UPDATEDTOPIC' : 'L_UPDATEDREPLY', $name), 'content', FALSE, 'findpost.php?id=' . $post['post_id'], 3);
         return $action->execute($request);
     } else {
         /**
          * Post Previewing
          */
         if (!USE_XMLHTTP) {
             $request['template']->setVar('L_TITLETOOSHORT', sprintf($request['template']->getVar('L_TITLETOOSHORT'), $request['template']->getVar('topicminchars'), $request['template']->getVar('topicmaxchars')));
             /* 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);
             post_attachment_options($request, $forum, $post);
             topic_post_options($request['template'], $request['user'], $forum);
             /* Create our editor */
             create_editor($request, $_REQUEST['message'], 'post', $forum);
         }
         $topic_preview = array('post_id' => @$post['post_id'], 'name' => $name, 'posticon' => isset($_REQUEST['posticon']) ? $_REQUEST['posticon'] : 'clear.gif', 'body_text' => $body_text, 'poster_name' => html_entity_decode($topic['poster_name'], ENT_QUOTES), 'poster_id' => $request['user']->get('id'), 'is_poll' => $topic['is_poll'], 'row_left' => 0, 'row_right' => 0, 'post_type' => $post_type, 'is_feature' => $is_feature, 'disable_html' => isset($_REQUEST['disable_html']) && $_REQUEST['disable_html'] ? 1 : 0, 'disable_sig' => isset($_REQUEST['enable_sig']) && $_REQUEST['enable_sig'] ? 1 : 0, 'disable_bbcode' => isset($_REQUEST['disable_bbcode']) && $_REQUEST['disable_bbcode'] ? 1 : 0, 'disable_emoticons' => isset($_REQUEST['disable_emoticons']) && $_REQUEST['disable_emoticons'] ? 1 : 0, 'disable_areply' => isset($_REQUEST['disable_areply']) && $_REQUEST['disable_areply'] ? 1 : 0, 'disable_aurls' => isset($_REQUEST['disable_aurls']) && $_REQUEST['disable_aurls'] ? 1 : 0);
         /* Add the topic information to the template */
         $topic_iterator =& new TopicIterator($request['dba'], $request['user'], $topic_preview, FALSE);
         $request['template']->setList('topic', $topic_iterator);
         /* Assign the topic preview values to the template */
         $topic_preview['body_text'] = $_REQUEST['message'];
         foreach ($topic_preview as $key => $val) {
             $request['template']->setVar('topic_' . $key, $val);
         }
         /* Assign the forum information to the template */
         foreach ($forum as $key => $val) {
             $request['template']->setVar('forum_' . $key, $val);
         }
         if (!USE_XMLHTTP) {
             /* Set the the button display options */
             $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('post_topic', FALSE);
             $request['template']->setVisibility('edit_post', TRUE);
             /* set the breadcrumbs bit */
             k4_bread_crumbs($request['template'], $request['dba'], 'L_POSTTOPIC', $forum);
             /* Set the post topic form */
             $request['template']->setVar('forum_forum_id', $forum['forum_id']);
             $request['template']->setFile('preview', 'post_preview.html');
             $request['template']->setFile('content', 'newtopic.html');
         } else {
             $templateset = $request['user']->isMember() ? $request['user']->get('templateset') : $forum['defaultstyle'];
             xmlhttp_header();
             echo $request['template']->run(BB_BASE_DIR . '/templates/' . $templateset . '/post_preview.html');
             xmlhttp_footer();
         }
     }
     return TRUE;
 }
Example #7
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;
 }
Example #8
0
 function execute(&$request)
 {
     global $_QUERYPARAMS, $_URL;
     /**
      * Error checking 
      */
     /* 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 $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);
     }
     // set the topic id to the template
     $request['template']->setVar('topic_id', $topic['post_id']);
     // get the forum
     $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 $action->execute($request);
     }
     /* Make sure the we are trying to post to a forum */
     if (!($forum['row_type'] & FORUM) || $forum['forum_id'] == GARBAGE_BIN) {
         no_perms_error($request);
         return TRUE;
     }
     /* Do we have permission to post to this topic in this forum? */
     if ($request['user']->get('perms') < get_map('replies', 'can_add', array('forum_id' => $forum['forum_id']))) {
         no_perms_error($request);
         return TRUE;
     }
     if (isset($_REQUEST['r']) && intval($_REQUEST['r']) != 0) {
         $reply = $request['dba']->getRow("SELECT * FROM " . K4POSTS . " WHERE post_id = " . intval($_REQUEST['r']));
         if (!$reply || !is_array($reply) || empty($reply)) {
             $action = new K4InformationAction(new K4LanguageElement('L_REPLYDOESNTEXIST'), 'content', FALSE);
             return $action->execute($request);
         } else {
             $request['template']->setVisibility('parent_id', TRUE);
             $request['template']->setVar('parent_id', $reply['post_id']);
         }
     }
     /* 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);
         }
     }
     $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 = $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);
     /* Set to the template what posting perms this user has */
     topic_post_options($request['template'], $request['user'], $forum);
     /**
      * Deal with reply attachments
      */
     $num_attachments = 0;
     /**
      * Deal with file attachments
      */
     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);
         }
     }
     /* Set the forum and topic info to the template */
     foreach ($forum as $key => $val) {
         $request['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') {
             $request['template']->setVar('post_' . $key, $val);
         }
     }
     $body_text = '';
     /* If this is a quote, put quote tags around the message */
     if (isset($_REQUEST['quote']) && intval($_REQUEST['quote']) == 1) {
         // are we quoting a poll?
         if ($parent['is_poll'] == 1) {
             // does this reply have a/some poll(s) ?
             preg_match_all('~\\[poll=([0-9]+?)\\]~i', $parent['body_text'], $poll_matches, PREG_SET_ORDER);
             if (count($poll_matches) > 0) {
                 $url = new FAUrl($_URL->__toString());
                 $url->args = array();
                 $url->anchor = FALSE;
                 $url->file = 'viewpoll.php';
                 foreach ($poll_matches as $poll) {
                     $parent['body_text'] = str_replace('[poll=' . $poll[1] . ']', $request['template']->getVar('L_POLL') . ': [b][url=' . $url->__toString() . '?id=' . $poll[1] . ']' . $request['dba']->getValue("SELECT question FROM " . K4POLLQUESTIONS . " WHERE id = " . intval($poll[1])) . '[/url][/b]', $parent['body_text']);
                 }
             }
         }
         // revert the text with the bbcode parser
         $parser =& new BBParser();
         $body_text = '[quote=' . ($parent['poster_name'] == '' ? $request['template']->getVar('L_GUEST') : $parent['poster_name']) . ']' . $parser->revert($parent['body_text']) . '[/quote]';
     }
     /* Set the title variable */
     $request['template']->setVar('post_name', $request['template']->getVar('L_RE') . ': ' . (isset($reply) ? $reply['name'] : $topic['name']));
     $request['template']->setVar('L_TITLETOOSHORT', sprintf($request['template']->getVar('L_TITLETOOSHORT'), $request['template']->getVar('topicminchars'), $request['template']->getVar('topicmaxchars')));
     /* set the breadcrumbs bit */
     k4_bread_crumbs($request['template'], $request['dba'], 'L_POSTREPLY', $parent, $forum);
     foreach ($parent as $key => $val) {
         $request['template']->setVar('parent_' . $key, $val);
     }
     $query = "SELECT * FROM " . K4POSTS . " WHERE post_id = " . intval($topic['post_id']) . " ORDER BY created DESC LIMIT 10";
     $replies = $request['dba']->executeQuery($query);
     /* Set the form actiob */
     $request['template']->setVar('newreply_act', 'newreply.php?act=postreply');
     $it =& new TopicReviewIterator($request['dba'], $topic, $replies, $request['user']->getInfoArray());
     $request['template']->setList('topic_review', $it);
     /* Set the post topic form */
     $request['template']->setFile('content', 'newreply.html');
     /* Create our editor */
     create_editor($request, $body_text, 'post', $forum);
     /* Clear up some memory */
     unset($it, $body_text, $forum, $replies, $bbcode, $last_topic, $last_reply, $topic);
     return TRUE;
 }