Esempio n. 1
0
File: add.php Progetto: qinzhi/taoj
                            <div class="col-sm-8">
                                <input type="text" id="intro" name="intro" class="form-control">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label no-padding-right" for="sort">排序</label>
                            <div class="col-sm-8">
                                <input type="text" id="sort" name="sort" class="form-control">
                            </div>
                        </div>

                        <div class="form-group">
                            <label class="col-sm-2 control-label no-padding-right" for="url">详情*</label>
                            <div class="col-sm-8">
                                <?php 
create_editor('detail');
?>
                            </div>
                        </div>
                    </form>
                </div>
            </div><!--Widget Body-->
        </div><!--Widget-->
    </div>
</div>
<script>
    $(function(){
        $('.btn-success').click(function(){
            $(document).find('form').submit();
        });
    });
Esempio n. 2
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;
 }
Esempio n. 3
0
 public function template_edit($id_template = null)
 {
     $languages = $this->pg_language->languages;
     $lang_ids = array_keys($languages);
     $this->load->model('notifications/models/Templates_model');
     if ($id_template) {
         $data = $this->Templates_model->get_template_by_id($id_template);
         $data_content = $this->Templates_model->get_template_content($id_template, $lang_ids);
     } else {
         $data = array("content_type" => "text");
         $data_content = array();
     }
     if ($this->input->post('btn_save')) {
         $error = false;
         if ($this->allow_template_edit) {
             $post_data = array("name" => $this->input->post('name', true), "gid" => $this->input->post('gid', true), "content_type" => $this->input->post('content_type', true));
             if ($this->allow_template_var_edit) {
                 $post_data["vars"] = $this->input->post('vars', true);
             }
             $validate_data = $this->Templates_model->validate_template($id_template, $post_data);
             if (!empty($validate_data["errors"])) {
                 $this->system_messages->add_message('error', $validate_data["errors"]);
                 $data = array_merge($data, $validate_data["data"]);
                 $error = true;
             } else {
                 $data = $validate_data["data"];
                 $id_template_new = $this->Templates_model->save_template($id_template, $data);
                 $this->system_messages->add_message('success', $id_template ? l('success_update_template', 'notifications') : l('success_add_template', 'notifications'));
                 $id_template = $id_template_new;
             }
         }
         if (!$error) {
             //// safe content there
             $post_content_text = $this->input->post('content', true);
             $post_subject = $this->input->post('subject', true);
             foreach ($languages as $lang_id => $lang) {
                 $save_content[$lang_id] = array("subject" => isset($post_subject[$lang_id]) ? $post_subject[$lang_id] : "", "content" => isset($post_content_text[$lang_id]) ? $post_content_text[$lang_id] : "");
             }
             $this->Templates_model->set_template_content($id_template, $save_content);
             $data_content = array_merge($data_content, $save_content);
             $current_settings = $_SESSION["nf_templates_list"];
             $url = site_url() . "admin/notifications/templates/" . $current_settings["filter"] . "/" . $current_settings["order"] . "/" . $current_settings["order_direction"] . "/" . $current_settings["page"] . "";
             redirect($url);
         }
     }
     $data = $this->Templates_model->format_template($data);
     if ($data["content_type"] == "html") {
         $this->load->plugin('fckeditor');
         foreach ($languages as $lang_id => $lang) {
             $content = isset($data_content[$lang_id]) ? $data_content[$lang_id] : array();
             $data_content[$lang_id]["content_fck"] = create_editor("content[" . $lang_id . "]", isset($content["content"]) ? $content["content"] : "", 550, 400, 'Middle');
         }
     }
     $this->template_lite->assign('langs', $languages);
     $this->template_lite->assign('data', $data);
     $this->template_lite->assign('data_content', $data_content);
     $this->template_lite->assign('global_vars', $this->Templates_model->global_vars);
     $this->template_lite->assign('allow_edit', $this->allow_template_edit);
     $this->template_lite->assign('allow_var_edit', $this->allow_template_var_edit);
     $this->system_messages->set_data('header', l('admin_header_template_edit', 'notifications'));
     $this->template_lite->view('edit_template_form');
 }
Esempio n. 4
0
 /**
  * Edit news data
  * 
  * @param integer $news_id news identifier
  * @param string $section_gid section GUID
  * @return void
  */
 public function edit($news_id = null, $section_gid = 'text')
 {
     $languages = $this->pg_language->languages;
     if ($news_id) {
         $data = $this->News_model->get_news_by_id($news_id, array_keys($languages));
     } else {
         $data = array();
     }
     if ($this->input->post('btn_save')) {
         switch ($section_gid) {
             case 'text':
                 $post_data = array("gid" => $this->input->post('gid', true), 'id_lang' => $this->input->post('id_lang', true), "news_type" => "news");
                 foreach ($languages as $lid => $lang_data) {
                     $post_data["name_" . $lid] = $this->input->post('name_' . $lid, true);
                     $post_data["annotation_" . $lid] = $this->input->post('annotation_' . $lid, true);
                     $post_data["content_" . $lid] = $this->input->post('content_' . $lid);
                 }
                 $validate_data = $this->News_model->validate_news($news_id, $post_data, 'news_icon', 'news_video');
                 if (!empty($validate_data["errors"])) {
                     $this->system_messages->add_message('error', $validate_data["errors"]);
                     $data = array_merge($data, $post_data);
                 } else {
                     if ($this->input->post('news_icon_delete') && $news_id && $data["img"]) {
                         $this->load->model("Uploads_model");
                         $format = $this->News_model->format_single_news($data);
                         $this->Uploads_model->delete_upload($this->News_model->upload_config_id, $format["prefix"], $format["img"]);
                         $validate_data["data"]["img"] = '';
                     }
                     if ($this->input->post('news_video_delete') && $news_id && $data["video"]) {
                         $this->load->model("Video_uploads_model");
                         $format = $this->News_model->format_single_news($data);
                         $this->Video_uploads_model->delete_upload($this->News_model->video_config_id, $format["prefix"], $format["video"], $format["video_image"], $format["video_data"]["data"]["upload_type"]);
                         $validate_data["data"]["video"] = $validate_data["data"]["video_image"] = $validate_data["data"]["video_data"] = '';
                     }
                     $flag_add = empty($news_id) ? true : false;
                     if ($flag_add) {
                         $validate_data["data"]["status"] = 1;
                     }
                     $news_id = $this->News_model->save_news($news_id, $validate_data["data"], 'news_icon', 'news_video');
                     $this->system_messages->add_message('success', !$flag_add ? l('success_update_news', 'news') : l('success_add_news', 'news'));
                     $data = array_merge($data, $validate_data["data"]);
                     $data = $this->News_model->format_single_news($data);
                     $url = site_url() . "admin/news/edit/" . $news_id . '/' . $section_gid;
                     redirect($url);
                 }
                 break;
             case 'seo':
                 $this->load->model('Seo_advanced_model');
                 $seo_fields = $this->Seo_advanced_model->get_seo_fields();
                 foreach ($seo_fields as $key => $section_data) {
                     if ($this->input->post('btn_save_' . $section_data['gid'])) {
                         $post_data = array();
                         $post_data[$section_data['gid']] = $this->input->post($section_data['gid'], true);
                         $validate_data = $this->Seo_advanced_model->validate_seo_tags($news_id, $post_data);
                         if (empty($validate_data['errors'])) {
                             $news_data['id_seo_settings'] = $this->Seo_advanced_model->save_seo_tags($data['id_seo_settings'], $validate_data['data']);
                             if (!$data['id_seo_settings']) {
                                 $data['id_seo_settings'] = $news_data['id_seo_settings'];
                                 $this->News_model->save_news($news_id, $news_data);
                             }
                             $this->system_messages->add_message('success', l('success_settings_updated', 'seo'));
                             $url = site_url() . "admin/news/edit/" . $news_id . '/' . $section_gid;
                             redirect($url);
                         }
                         $data = array_merge($data, $post_data);
                         break;
                     }
                 }
                 break;
         }
     }
     $data = $this->News_model->format_single_news($data);
     switch ($section_gid) {
         case 'text':
             $this->load->plugin('fckeditor');
             foreach ($languages as $lid => $lang_data) {
                 $data["content_fck"][$lid] = create_editor("content_" . $lid, isset($data["content_" . $lid]) ? $data["content_" . $lid] : "", 700, 400, 'Middle');
             }
             break;
         case 'seo':
             $this->load->model('Seo_advanced_model');
             $seo_fields = $this->Seo_advanced_model->get_seo_fields();
             $this->template_lite->assign('seo_fields', $seo_fields);
             $languages = $this->pg_language->languages;
             $this->template_lite->assign('languages', $languages);
             $current_lang_id = $this->pg_language->current_lang_id;
             $this->template_lite->assign('lang_id', $current_lang_id);
             if ($data['id_seo_settings']) {
                 $seo_settings = $this->Seo_advanced_model->get_seo_tags($data['id_seo_settings']);
                 $this->template_lite->assign('seo_settings', $seo_settings);
             }
             break;
     }
     $this->template_lite->assign('data', $data);
     $this->template_lite->assign('section_gid', $section_gid);
     $this->template_lite->assign('current_lang_id', $this->pg_language->current_lang_id);
     $this->template_lite->assign('languages', $languages);
     $this->Menu_model->set_menu_active_item('admin_news_menu', 'news_list_item');
     $this->system_messages->set_data('header', l('admin_header_news_list', 'news'));
     $this->template_lite->view('edit_news');
 }
 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;
 }
Esempio n. 6
0
 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;
 }
Esempio n. 7
0
<table class="table-form" width="100%">
    <colgroup>
        <col width="150px">
        <col>
    </colgroup>
    <tbody>
    <tr>
        <th>商品描述:</th>
        <td class="no-padding-top no-padding-bottom"><?php 
create_editor('detail', $goods['detail']);
?>
</td>
    </tr>
    </tbody>
</table>
Esempio n. 8
0
 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;
 }
Esempio n. 9
0
File: edit.php Progetto: qinzhi/taoj
                            <div class="col-sm-8">
                                <input type="text" id="intro" name="intro" class="form-control" value="{$expert.intro}">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label no-padding-right" for="sort">排序</label>
                            <div class="col-sm-8">
                                <input type="text" id="sort" name="sort" class="form-control" value="{$expert.sort}">
                            </div>
                        </div>

                        <div class="form-group">
                            <label class="col-sm-2 control-label no-padding-right" for="url">详情*</label>
                            <div class="col-sm-8">
                                <?php 
create_editor('detail', $expert['detail']);
?>
                            </div>
                        </div>
                    </form>
                </div>
                <div class="alert alert-warning fade in radius-bordered alert-shadowed">
                    <button data-dismiss="alert" class="close">
                        ×
                    </button>
                    <strong>注意:</strong> 头像图片尺寸120 * 120
                </div>
            </div><!--Widget Body-->
        </div><!--Widget-->
    </div>
</div>
Esempio n. 10
0
                                                </td>
                                            </tr>
                                            </tbody>
                                        </table>
                                    </div>
                                    <div class="tab-pane" id="tab-detail">
                                        <table class="table-form" width="100%">
                                            <colgroup>
                                                <col width="150px">
                                                <col>
                                            </colgroup>
                                            <tbody>
                                            <tr>
                                                <th>文章详情:</th>
                                                <td class="no-padding-top no-padding-bottom"><?php 
create_editor('detail', $article['detail']);
?>
</td>
                                            </tr>
                                            </tbody>
                                        </table>
                                    </div>
                                </div>
                            </form>
                        </div>
                    </div>
                </div><!--Widget Body-->
            </div><!--Widget-->
        </div>
    </div>
</block>
 function execute(&$request)
 {
     /* set the breadcrumbs bit */
     k4_bread_crumbs($request['template'], $request['dba'], 'L_USERCONTROLPANEL');
     global $_SETTINGS;
     $check = new K4PMCheckPerms();
     $check->execute($request);
     if (get_map('pm_message', 'can_add', array()) > $request['user']->get('perms')) {
         no_perms_error($request);
         return TRUE;
     }
     $num_pms = $request['dba']->getValue("SELECT COUNT(*) FROM " . K4PRIVMESSAGES . " WHERE poster_id = " . intval($request['user']->get('id')));
     $max_pms = intval($request['template']->getVar('pmquota'));
     if ($num_pms >= $max_pms) {
         $action = new K4InformationAction(new K4LanguageElement('L_TOOMANYPMS', $num_pms, $max_pms), 'usercp_content', FALSE);
         return !USE_XMLHTTP ? $action->execute($request) : xmlhttp_message(new K4LanguageElement('L_TOOMANYPMS', $num_pms, $max_pms));
     }
     k4_bread_crumbs($request['template'], $request['dba'], 'L_USERCONTROLPANEL');
     $request['template']->setFile('content', 'usercp.html');
     /**
      * Get who the message is going to
      */
     if (!$this->runPostFilter('to', new FARequiredFilter())) {
         $action = new K4InformationAction(new K4LanguageElement('L_NEEDSENDPMTOSOMEONE'), 'usercp_content', TRUE);
         return !USE_XMLHTTP ? $action->execute($request) : xmlhttp_message('L_NEEDSENDPMTOSOMEONE');
     }
     $users = isset($_REQUEST['to']) && $_REQUEST['to'] != '' ? explode(",", $_REQUEST['to']) : array($_REQUEST['to']);
     $users = isset($_REQUEST['cc']) && $_REQUEST['cc'] != '' ? array_merge($users, explode(",", $_REQUEST['to'])) : $users;
     $valid_users = array();
     $draft_users = array();
     foreach ($users as $username) {
         $username = trim($username);
         if (!in_array($username, $draft_users) && $username != $request['user']->get('name') && $username != '') {
             $user = $request['dba']->getRow("SELECT * FROM " . K4USERS . " WHERE name = '" . $request['dba']->quote(k4_htmlentities($username, ENT_QUOTES)) . "'");
             if (is_array($user) && !empty($user)) {
                 if (get_map('pm_message', 'can_view', array()) <= $user['perms']) {
                     $valid_users[] = $user;
                     $draft_users[] = $user['name'];
                 }
             }
         }
     }
     if (!is_array($valid_users) || empty($valid_users)) {
         $action = new K4InformationAction(new K4LanguageElement('L_PMNOVALIDRECIEVERS'), 'usercp_content', TRUE);
         return !USE_XMLHTTP ? $action->execute($request) : xmlhttp_message('L_PMNOVALIDRECIEVERS');
     }
     /**
      * Check over posting inputs
      */
     /* General error checking */
     if (!$this->runPostFilter('name', new FARequiredFilter())) {
         $action = new K4InformationAction(new K4LanguageElement('L_INSERTTOPICNAME'), 'usercp_content', TRUE);
         return !USE_XMLHTTP ? $action->execute($request) : xmlhttp_message('L_INSERTPMSUBJECT');
     }
     if (!$this->runPostFilter('name', new FALengthFilter(intval($_SETTINGS['topicmaxchars'])))) {
         $action = new K4InformationAction(new K4LanguageElement('L_PMSUBJECTTOOSHORT', intval($_SETTINGS['topicminchars']), intval($_SETTINGS['topicmaxchars'])), 'usercp_content', TRUE);
         return !USE_XMLHTTP ? $action->execute($request) : xmlhttp_message(new K4LanguageElement('L_PMSUBJECTTOOSHORT', intval($_SETTINGS['topicminchars']), intval($_SETTINGS['topicmaxchars'])));
     }
     if (!$this->runPostFilter('name', new FALengthFilter(intval($_SETTINGS['topicmaxchars']), intval($_SETTINGS['topicminchars'])))) {
         $action = new K4InformationAction(new K4LanguageElement('L_PMSUBJECTTOOSHORT', intval($_SETTINGS['topicminchars']), intval($_SETTINGS['topicmaxchars'])), 'usercp_content', TRUE);
         return !USE_XMLHTTP ? $action->execute($request) : xmlhttp_message(new K4LanguageElement('L_PMSUBJECTTOOSHORT', intval($_SETTINGS['topicminchars']), intval($_SETTINGS['topicmaxchars'])));
     }
     if (!isset($_REQUEST['message']) || $_REQUEST['message'] == '') {
         $action = new K4InformationAction(new K4LanguageElement('L_INSERTPMMESSAGE'), 'usercp_content', TRUE);
         return !USE_XMLHTTP ? $action->execute($request) : xmlhttp_message('L_INSERTPMMESSAGE');
     }
     /* Set the message created time */
     $created = time();
     $_REQUEST['message'] = substr($_REQUEST['message'], 0, $_SETTINGS['pmmaxchars']);
     /* Initialize the bbcode parser with the topic message */
     /*$bbcode	= &new BBCodex($request['dba'], $request['user']->getInfoArray(), $_REQUEST['message'], 0, 
     		iif((isset($_REQUEST['disable_html']) && $_REQUEST['disable_html']), FALSE, TRUE), 
     		iif((isset($_REQUEST['disable_bbcode']) && $_REQUEST['disable_bbcode']), FALSE, TRUE), 
     		iif((isset($_REQUEST['disable_emoticons']) && $_REQUEST['disable_emoticons']), FALSE, TRUE), 
     		iif((isset($_REQUEST['disable_aurls']) && $_REQUEST['disable_aurls']), FALSE, TRUE));*/
     /* Parse the bbcode */
     $body_text = $_REQUEST['message'];
     if (!isset($_REQUEST['disable_bbcode']) || !$_REQUEST['disable_bbcode']) {
         $parser =& new BBParser();
         Globals::setGlobal('forum_id', 0);
         Globals::setGlobal('maxpolloptions', 0);
         $body_text = $parser->parse($body_text);
     }
     $parent_id = 0;
     $message_id = 0;
     /**
      * Was this message originally a draft?
      */
     $draft_loaded = FALSE;
     if (isset($_REQUEST['draft']) && intval($_REQUEST['draft']) > 0) {
         $draft = $request['dba']->getRow("SELECT * FROM " . K4PRIVMESSAGES . " WHERE pm_id = " . intval($_REQUEST['draft']) . " AND is_draft = 1");
         if (is_array($draft) && !empty($draft)) {
             $draft_loaded = TRUE;
         }
     }
     if (isset($_REQUEST['reply']) && intval($_REQUEST['reply']) > 0 || $draft_loaded && $draft['message_id'] > 0) {
         $post_id = isset($_REQUEST['reply']) ? $_REQUEST['reply'] : $draft['message_id'];
         $message = $request['dba']->getRow("SELECT * FROM " . K4PRIVMESSAGES . " WHERE pm_id = " . intval($post_id));
         if (is_array($message) && !empty($message)) {
             $parent_id = intval($message['pm_id']);
             $message_id = intval($message['message_id']) == 0 ? intval($message['pm_id']) : intval($message['message_id']);
         }
     }
     if (isset($_REQUEST['submit_type']) && ($_REQUEST['submit_type'] == 'post' || $_REQUEST['submit_type'] == 'draft') || (isset($_REQUEST['post']) || isset($_REQUEST['draft']))) {
         $is_draft = 0;
         $folder = PM_INBOX;
         /**
          * Does this person have permission to post a draft? 
          */
         if (!$draft_loaded && ($_REQUEST['submit_type'] == 'draft' || isset($_REQUEST['draft']))) {
             if ($request['user']->get('perms') < get_map('pm_message_save', 'can_add', array())) {
                 $action = new K4InformationAction(new K4LanguageElement('L_YOUNEEDPERMS'), 'content', FALSE);
                 return $action->execute($request);
             }
             $is_draft = 1;
             $folder = PM_SAVEDITEMS;
             $valid_users = array($request['user']->getInfoArray());
         }
         /**
          * Should we save this message too?
          */
         $do_save = isset($_REQUEST['save_message']) && $_REQUEST['save_message'] ? TRUE : FALSE;
         if (!$draft_loaded && $do_save && $is_draft == 0) {
             $valid_users[] = $request['user']->getInfoArray();
         }
         /** 
          * Can / Do we track this message?
          */
         $track = FALSE;
         if (isset($_REQUEST['track_message'])) {
             $track = FALSE;
             // TODO: Message Tracking
         }
         /**
          * Build the queries
          */
         $request['dba']->beginTransaction();
         $sending_id = md5(uniqid(rand(), true));
         $tracker_id = md5(uniqid(rand(), true));
         /**
          * Loop through the users and send the private message to them
          */
         $i = 0;
         foreach ($valid_users as $user) {
             /* Make sure to add a limit to how many messages can be sent if there is one */
             if ($i < $request['template']->getVar('maxsendtopms') && $request['template']->getVar('maxsendtopms') > 0) {
                 /* Prepare the inserting statement */
                 $insert_a = $request['dba']->prepareStatement("INSERT INTO " . K4PRIVMESSAGES . " (name,folder_id,poster_name,poster_id,body_text,posticon,disable_html,disable_bbcode,disable_emoticons,disable_sig,disable_areply,disable_aurls,is_draft,created,member_id,member_name,member_has_read,tracker_id,sending_id,parent_id,message_id) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)");
                 $insert_a->setString(1, k4_htmlentities(html_entity_decode($_REQUEST['name']), ENT_QUOTES));
                 $insert_a->setInt(2, $user['id'] != $request['user']->get('id') || $is_draft == 1 ? $folder : PM_SENTITEMS);
                 $insert_a->setString(3, $request['user']->get('name'));
                 $insert_a->setInt(4, $request['user']->get('id'));
                 $insert_a->setString(5, $body_text);
                 $insert_a->setString(6, iif($request['user']->get('perms') >= get_map('pm_posticons', 'can_add', array()), isset($_REQUEST['posticon']) ? $_REQUEST['posticon'] : 'clear.gif', 'clear.gif'));
                 $insert_a->setInt(7, iif(isset($_REQUEST['disable_html']) && $_REQUEST['disable_html'], 1, 0));
                 $insert_a->setInt(8, iif(isset($_REQUEST['disable_bbcode']) && $_REQUEST['disable_bbcode'], 1, 0));
                 $insert_a->setInt(9, iif(isset($_REQUEST['disable_emoticons']) && $_REQUEST['disable_emoticons'], 1, 0));
                 $insert_a->setInt(10, iif(isset($_REQUEST['enable_sig']) && $_REQUEST['enable_sig'], 0, 1));
                 $insert_a->setInt(11, iif(isset($_REQUEST['disable_areply']) && $_REQUEST['disable_areply'], 1, 0));
                 $insert_a->setInt(12, iif(isset($_REQUEST['disable_aurls']) && $_REQUEST['disable_aurls'], 1, 0));
                 $insert_a->setInt(13, $is_draft);
                 $insert_a->setInt(14, $created);
                 $insert_a->setInt(15, $user['id']);
                 $insert_a->setString(16, $user['name']);
                 $insert_a->setInt(17, $user['id'] == $request['user']->get('id') ? 1 : 0);
                 $insert_a->setString(18, $tracker_id);
                 $insert_a->setString(19, $sending_id);
                 $insert_a->setString(20, $parent_id);
                 $insert_a->setString(21, $message_id);
                 $insert_a->executeUpdate();
                 $pm_id = $request['dba']->getInsertId(K4PRIVMESSAGES, 'pm_id');
                 // update the number of new pm's for that user
                 if ($user['id'] != $request['user']->get('id')) {
                     $request['dba']->executeUpdate("UPDATE " . K4USERS . " SET new_pms=new_pms+1 WHERE id = " . intval($user['id']));
                 }
             } else {
                 break;
             }
             $i++;
         }
         /**
          * If this PM was a draft, it was sent back to us, now we need to create
          * a record of who to send it to for if we choose to send it again
          */
         if (!$draft_loaded && (isset($_REQUEST['submit_type']) && $_REQUEST['submit_type'] == 'draft') || isset($_REQUEST['draft'])) {
             /* Split who this message is to into 'to' and 'carbon copy' */
             $count = count($draft_users);
             $to = array_slice($draft_users, 0, ceil($count / 2));
             $cc = $count > 1 ? array_slice($draft_users, ceil($count / 2), $count) : array();
             $insert = $request['dba']->prepareStatement("INSERT INTO " . K4PRIVMSGDRAFTS . " (pm_id,pm_to,pm_cc) VALUES (?,?,?)");
             $insert->setInt(1, $pm_id);
             $insert->setString(2, implode(',', $to));
             $insert->setString(3, implode(',', $cc));
             /* Add the draft information */
             $insert->executeUpdate();
         }
         /**
          * If we loaded a draft, deal with it
          */
         if ($draft_loaded) {
             $request['dba']->executeUpdate("DELETE FROM " . K4PRIVMESSAGES . " WHERE pm_id = " . intval($draft['pm_id']));
             $request['dba']->executeUpdate("DELETE FROM " . K4PRIVMSGDRAFTS . " WHERE pm_id = " . intval($draft['pm_id']));
         }
         /**
          * If this was a reply, update its parent and top-message
          */
         if ($message_id > 0) {
             $request['dba']->executeUpdate("UPDATE " . K4PRIVMESSAGES . " SET num_replies=num_replies+1 WHERE pm_id = " . intval($message_id));
             if ($message_id != $parent_id) {
                 $request['dba']->executeUpdate("UPDATE " . K4PRIVMESSAGES . " SET num_replies=num_replies+1 WHERE pm_id = " . intval($parent_id));
             }
         }
         /* Finish everything off by commiting the SQL transaction */
         $request['dba']->commitTransaction();
         /**
          * Now we're done!
          */
         if ($is_draft == 0) {
             $action = new K4InformationAction(new K4LanguageElement('L_SENTPRIVATEMSG', k4_htmlentities(html_entity_decode($_REQUEST['name']), ENT_QUOTES)), 'usercp_content', FALSE, 'member.php?act=usercp', 3);
             return $action->execute($request);
         } else {
             $action = new K4InformationAction(new K4LanguageElement('L_SAVEDPRIVATEMSG', k4_htmlentities(html_entity_decode($_REQUEST['name']), ENT_QUOTES)), 'usercp_content', FALSE, 'member.php?act=usercp', 3);
             return $action->execute($request);
         }
     } else {
         /**
          * Message Previewing
          */
         if (!USE_XMLHTTP) {
             $request['template']->setVar('L_PMSUBJECTTOOSHORT', sprintf($request['template']->getVar('L_TITLETOOSHORT'), $request['template']->getVar('topicminchars'), $request['template']->getVar('topicmaxchars')));
             /* Create the bbcode/wysiwyg editor */
             create_editor($request, '', 'pm');
             $request['template']->setFile('usercp_content', 'pm_newmessage.html');
             $request['template']->setVisibility('post_pm', TRUE);
             $request['template']->setVar('newpm_action', 'member.php?act=pm_savemessage');
             /* 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);
             /* Add the emoticons and the post icons to the template */
             $request['template']->setList('emoticons', $emoticons);
             $request['template']->setList('posticons', $posticons);
             /* Set some emoticon information */
             $request['template']->setVar('emoticons_per_row', $request['template']->getVar('smcolumns'));
             $request['template']->setVar('emoticons_per_row_remainder', $request['template']->getVar('smcolumns') - 1);
         }
         $msg_preview = array('pm_id' => 0, 'name' => k4_htmlentities(html_entity_decode($_REQUEST['name']), ENT_QUOTES), 'posticon' => isset($_REQUEST['posticon']) ? $_REQUEST['posticon'] : 'clear.gif', 'body_text' => $body_text, 'poster_name' => $request['user']->get('name'), 'poster_id' => $request['user']->get('id'), 'disable_html' => iif(isset($_REQUEST['disable_html']) && $_REQUEST['disable_html'], 1, 0), 'disable_sig' => iif(isset($_REQUEST['enable_sig']) && $_REQUEST['enable_sig'], 0, 1), 'disable_bbcode' => iif(isset($_REQUEST['disable_bbcode']) && $_REQUEST['disable_bbcode'], 1, 0), 'disable_emoticons' => iif(isset($_REQUEST['disable_emoticons']) && $_REQUEST['disable_emoticons'], 1, 0), 'disable_areply' => iif(isset($_REQUEST['disable_areply']) && $_REQUEST['disable_areply'], 1, 0), 'disable_aurls' => iif(isset($_REQUEST['disable_aurls']) && $_REQUEST['disable_aurls'], 1, 0));
         /* Add the message information to the template */
         $pm_iterator =& new K4PrivMsgIterator($request['dba'], $request['user'], $msg_preview, FALSE);
         $request['template']->setList('message', $pm_iterator);
         /* Assign the message preview values to the template */
         $msg_preview['body_text'] = $_REQUEST['message'];
         foreach ($msg_preview as $key => $val) {
             $request['template']->setVar('pm_' . $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);
             $request['template']->setVisibility('post_pm', TRUE);
             /* Create the bbcode/wysiwyg editor */
             create_editor($request, $body_text, 'pm');
             $request['template']->setVar('L_PMSUBJECTTOOSHORT', sprintf($request['template']->getVar('L_TITLETOOSHORT'), $request['template']->getVar('topicminchars'), $request['template']->getVar('topicmaxchars')));
             $request['template']->setVar('newpm_action', 'member.php?act=pm_savemessage');
             if ($draft_loaded) {
                 $request['template']->setVar('edit_type', 'draft');
                 $request['template']->setVisibility('edit_message', TRUE);
                 $request['template']->setVisibility('save_draft', FALSE);
             }
             if ($parent_id > 0) {
                 $request['template']->setVar('edit_type', 'reply');
             }
             /* Set the post topic form */
             $request['template']->setFile('preview', 'pm_preview.html');
             $request['template']->setFile('content', 'usercp.html');
             $request['template']->setFile('usercp_content', 'pm_newmessage.html');
         } else {
             xmlhttp_header();
             echo $request['template']->run(BB_BASE_DIR . '/templates/' . $request['user']->get('templateset') . '/pm_preview.html');
             xmlhttp_footer();
         }
     }
 }
Esempio n. 12
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;
 }
Esempio n. 13
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;
 }