コード例 #1
4
ファイル: listener.php プロジェクト: edipdincer/QuickReply
 /**
  * Show bbcodes and smilies in the quickreply
  * Template data for Ajax submit
  *
  * @param object $event The event object
  * @return null
  * @access public
  */
 public function viewtopic_modify_data($event)
 {
     $forum_id = $event['forum_id'];
     $topic_data = $event['topic_data'];
     $post_list = $event['post_list'];
     $topic_id = $topic_data['topic_id'];
     $s_quick_reply = false;
     if (($this->user->data['is_registered'] || $this->config['qr_allow_for_guests']) && $this->config['allow_quick_reply'] && $topic_data['forum_flags'] & FORUM_FLAG_QUICK_REPLY && $this->auth->acl_get('f_reply', $forum_id)) {
         // Quick reply enabled forum
         $s_quick_reply = $topic_data['forum_status'] == ITEM_UNLOCKED && $topic_data['topic_status'] == ITEM_UNLOCKED || $this->auth->acl_get('m_edit', $forum_id) ? true : false;
     }
     if (!$this->user->data['is_registered'] && $s_quick_reply) {
         add_form_key('posting');
         $s_attach_sig = $this->config['allow_sig'] && $this->user->optionget('attachsig') && $this->auth->acl_get('f_sigs', $forum_id) && $this->auth->acl_get('u_sig');
         $s_smilies = $this->config['allow_smilies'] && $this->user->optionget('smilies') && $this->auth->acl_get('f_smilies', $forum_id);
         $s_bbcode = $this->config['allow_bbcode'] && $this->user->optionget('bbcode') && $this->auth->acl_get('f_bbcode', $forum_id);
         $s_notify = false;
         $qr_hidden_fields = array('topic_cur_post_id' => (int) $topic_data['topic_last_post_id'], 'lastclick' => (int) time(), 'topic_id' => (int) $topic_data['topic_id'], 'forum_id' => (int) $forum_id);
         // Originally we use checkboxes and check with isset(), so we only provide them if they would be checked
         !$s_bbcode ? $qr_hidden_fields['disable_bbcode'] = 1 : true;
         !$s_smilies ? $qr_hidden_fields['disable_smilies'] = 1 : true;
         !$this->config['allow_post_links'] ? $qr_hidden_fields['disable_magic_url'] = 1 : true;
         $s_attach_sig ? $qr_hidden_fields['attach_sig'] = 1 : true;
         $s_notify ? $qr_hidden_fields['notify'] = 1 : true;
         $topic_data['topic_status'] == ITEM_LOCKED ? $qr_hidden_fields['lock_topic'] = 1 : true;
         $this->template->assign_vars(array('S_QUICK_REPLY' => true, 'U_QR_ACTION' => append_sid("{$this->phpbb_root_path}posting.{$this->php_ext}", "mode=reply&f={$forum_id}&t={$topic_id}"), 'QR_HIDDEN_FIELDS' => build_hidden_fields($qr_hidden_fields), 'USERNAME' => $this->request->variable('username', '', true)));
         if ($this->config['enable_post_confirm']) {
             $captcha = $this->captcha->get_instance($this->config['captcha_plugin']);
             $captcha->init(CONFIRM_POST);
         }
         if ($this->config['enable_post_confirm'] && (isset($captcha) && $captcha->is_solved() === false)) {
             $this->template->assign_vars(array('S_CONFIRM_CODE' => true, 'CAPTCHA_TEMPLATE' => $captcha->get_template()));
         }
         // Add the confirm id/code pair to the hidden fields, else an error is displayed on next submit/preview
         if (isset($captcha) && $captcha->is_solved() !== false) {
             $this->template->append_var('QR_HIDDEN_FIELDS', build_hidden_fields($captcha->get_hidden_fields()));
         }
     }
     // Ajaxify viewtopic data
     if ($this->request->is_ajax() && $this->request->is_set('qr_request')) {
         if (!$this->user->data['is_registered'] && $this->config['enable_post_confirm']) {
             $captcha = $this->captcha->get_instance($this->config['captcha_plugin']);
             $captcha->init(CONFIRM_POST);
             // Add the confirm id/code pair to the hidden fields, else an error is displayed on next submit/preview
             if (isset($captcha) && $captcha->is_solved() !== false) {
                 $this->template->append_var('QR_HIDDEN_FIELDS', build_hidden_fields($captcha->get_hidden_fields()));
             }
         }
         // Fix issues if the inserted post is not the first.
         if ($this->qr_insert && !$this->qr_first) {
             $this->template->alter_block_array('postrow', array('S_FIRST_ROW' => false), false, 'change');
         }
         $page_title = $event['page_title'];
         $this->template->assign_vars(array('S_QUICKREPLY_REQUEST' => true, 'S_QR_NO_FIRST_POST' => $this->qr_insert, 'S_QR_FULL_QUOTE' => $this->config['qr_full_quote']));
         $this->template->append_var('QR_HIDDEN_FIELDS', build_hidden_fields(array('qr' => 1, 'qr_cur_post_id' => (int) max($post_list))));
         // Output the page
         page_header($page_title, false, $forum_id);
         page_footer(false, false, false);
         $json_response = new \phpbb\json_response();
         $json_response->send(array('success' => true, 'result' => $this->template->assign_display('@tatiana5_quickreply/quickreply_template.html', '', true), 'insert' => $this->qr_insert));
     }
     if ($s_quick_reply) {
         include_once $this->phpbb_root_path . 'includes/functions_posting.' . $this->php_ext;
         // HTML, BBCode, Smilies, Images and Flash status
         $bbcode_status = $this->config['allow_bbcode'] && $this->config['qr_bbcode'] && $this->auth->acl_get('f_bbcode', $forum_id) ? true : false;
         $smilies_status = $this->config['allow_smilies'] && $this->config['qr_smilies'] && $this->auth->acl_get('f_smilies', $forum_id) ? true : false;
         $img_status = $bbcode_status && $this->auth->acl_get('f_img', $forum_id) ? true : false;
         $url_status = $this->config['allow_post_links'] ? true : false;
         $flash_status = $bbcode_status && $this->auth->acl_get('f_flash', $forum_id) && $this->config['allow_post_flash'] ? true : false;
         $quote_status = true;
         // Build custom bbcodes array
         if ($bbcode_status) {
             display_custom_bbcodes();
         }
         // Generate smiley listing
         if ($smilies_status) {
             generate_smilies('inline', $forum_id);
         }
         // Show attachment box for adding attachments if true
         $form_enctype = @ini_get('file_uploads') == '0' || strtolower(@ini_get('file_uploads')) == 'off' || !$this->config['allow_attachments'] || !$this->auth->acl_get('u_attach') || !$this->auth->acl_get('f_attach', $forum_id) ? '' : '" enctype="multipart/form-data';
         $allowed = $this->auth->acl_get('f_attach', $forum_id) && $this->auth->acl_get('u_attach') && $this->config['allow_attachments'] && $form_enctype;
         $attachment_data = false;
         if ($bbcode_status || $smilies_status || $this->config['qr_attach'] && $allowed) {
             $this->user->add_lang('posting');
         }
         if ($this->config['qr_attach'] && $allowed) {
             $this->template->assign_vars(array('U_QR_ACTION' => append_sid("{$this->phpbb_root_path}posting.{$this->php_ext}", "mode=reply&f={$forum_id}&t={$topic_id}") . $form_enctype));
             include_once $this->phpbb_root_path . 'includes/message_parser.' . $this->php_ext;
             $message_parser = new \parse_message();
             $message_parser->set_plupload($this->plupload);
             $message_parser->set_mimetype_guesser($this->mimetype_guesser);
             $message_parser->get_submitted_attachment_data($this->user->data['user_id']);
             $attachment_data = $message_parser->attachment_data;
             $filename_data = $message_parser->filename_data;
             posting_gen_inline_attachments($attachment_data);
             $max_files = $this->auth->acl_get('a_') || $this->auth->acl_get('m_', $forum_id) ? 0 : (int) $this->config['max_attachments'];
             $topic_id = $topic_data['topic_id'];
             $s_action = append_sid("{$this->phpbb_root_path}posting.{$this->php_ext}", "mode=reply&f={$forum_id}&t={$topic_id}");
             $this->plupload->configure($this->cache, $this->template, $s_action, $forum_id, $max_files);
             posting_gen_attachment_entry($attachment_data, $filename_data, $allowed);
         }
         $this->template->append_var('QR_HIDDEN_FIELDS', build_hidden_fields(array('qr' => 1, 'qr_cur_post_id' => (int) max($post_list))));
         if ($this->phpbb_extension_manager->is_enabled('rxu/PostsMerging') && $this->user->data['is_registered'] && $this->config['merge_interval']) {
             // Always show the checkbox if PostsMerging extension is installed.
             $this->user->add_lang_ext('rxu/PostsMerging', 'posts_merging');
             $this->template->assign_var('POSTS_MERGING_OPTION', true);
         }
         $this->template->assign_vars(array('S_QR_COLOUR_NICKNAME' => $this->config['qr_color_nickname'], 'S_QR_NOT_CHANGE_SUBJECT' => $this->auth->acl_get('f_qr_change_subject', $forum_id) ? false : true, 'S_QR_COMMA_ENABLE' => $this->config['qr_comma'], 'S_QR_QUICKNICK_ENABLE' => $this->config['qr_quicknick'], 'S_QR_QUICKNICK_REF' => $this->config['qr_quicknick_ref'], 'S_QR_QUICKNICK_PM' => $this->config['qr_quicknick_pm'], 'S_QR_QUICKQUOTE_ENABLE' => $this->config['qr_quickquote'], 'S_QR_QUICKQUOTE_LINK' => $this->config['qr_quickquote_link'], 'S_QR_FULL_QUOTE' => $this->config['qr_full_quote'], 'S_QR_CE_ENABLE' => $this->config['qr_ctrlenter'], 'QR_SOURCE_POST' => $this->config['qr_source_post'], 'S_DISPLAY_USERNAME' => !$this->user->data['is_registered'], 'S_BBCODE_ALLOWED' => $bbcode_status ? 1 : 0, 'S_SMILIES_ALLOWED' => $smilies_status, 'S_BBCODE_IMG' => $img_status, 'S_LINKS_ALLOWED' => $url_status, 'S_BBCODE_FLASH' => $flash_status, 'S_BBCODE_QUOTE' => $quote_status, 'MESSAGE' => $this->request->variable('message', '', true), 'READ_POST_IMG' => $this->user->img('icon_post_target', 'POST'), 'S_QR_CAPS_ENABLE' => $this->config['qr_capslock_transfer'], 'S_QR_SHOW_BUTTON_TRANSLIT' => $this->config['qr_show_button_translit'], 'L_FULL_EDITOR' => $this->config['qr_ajax_submit'] ? $this->user->lang['PREVIEW'] : $this->user->lang['FULL_EDITOR'], 'S_QR_AJAX_SUBMIT' => $this->config['qr_ajax_submit'], 'S_QR_AJAX_PAGINATION' => $this->config['qr_ajax_pagination'] && $this->user->data['ajax_pagination'], 'S_QR_ENABLE_SCROLL' => $this->user->data['qr_enable_scroll'], 'S_QR_SCROLL_INTERVAL' => $this->config['qr_scroll_time'], 'S_QR_SOFT_SCROLL' => $this->config['qr_scroll_time'] && $this->user->data['qr_soft_scroll'], 'S_QR_ALLOWED_GUEST' => $this->config['qr_allow_for_guests'] && $this->user->data['user_id'] == ANONYMOUS, 'S_ABBC3_INSTALLED' => $this->phpbb_extension_manager->is_enabled('vse/abbc3'), 'S_QR_SHOW_ATTACH_BOX' => $this->config['qr_attach'] && $allowed, 'S_ATTACH_DATA' => $attachment_data ? json_encode($attachment_data) : '[]'));
         $add_re = $this->config['qr_enable_re'] ? 'Re: ' : '';
         $this->template->assign_var('SUBJECT', $this->request->variable('subject', $add_re . censor_text($topic_data['topic_title']), true));
     }
     $this->template->assign_vars(array('QR_HIDE_POSTS_SUBJECT' => $this->config['qr_show_subjects'] ? false : true));
 }
コード例 #2
0
ファイル: display.php プロジェクト: 3D-I/phpBB-ext-sitemaker
 protected function find_parents(array $data, $parent_id)
 {
     if (isset($data[$parent_id]) && $data[$parent_id]['item_url'] !== 'index.php') {
         $row = $data[$parent_id];
         $this->template->alter_block_array('navlinks', array('FORUM_NAME' => $row['item_title'], 'U_VIEW_FORUM' => $row['full_url']));
         $this->find_parents($data, $row['parent_id']);
     }
 }
コード例 #3
0
ファイル: listener.php プロジェクト: 3D-I/phpBB-ext-sitemaker
 /**
  * - Add "Forum" to navbar when we are not on the forum page (viewforum/viewtopic)
  * - Add "Forum" to the breadcrump when viewing forum page (viewforum/viewtopic)
  */
 public function prepend_breadcrump()
 {
     $u_viewforum = $this->phpbb_container->get('controller.helper')->route('blitze_sitemaker_forum');
     // Add "Forum" to breadcrump menu when viewing forum pages (viewforum/viewtopic/posting)
     if ($this->request->is_set('f')) {
         $this->template->alter_block_array('navlinks', array('FORUM_NAME' => $this->user->lang('FORUM'), 'U_VIEW_FORUM' => $u_viewforum));
     } else {
         if ($this->user->page['page'] !== 'app.' . $this->php_ext . '/forum') {
             $this->template->assign_vars(array('S_PT_SHOW_FORUM_NAV' => true, 'U_PT_VIEWFORUM' => $u_viewforum));
         }
     }
 }
コード例 #4
0
 /**
  * Output the page for QuickReply
  *
  * @param string $page_title      The title of the page
  * @param int    $current_post_id ID of the current last post
  * @param int    $forum_id        Forum ID
  */
 public function ajax_response($page_title, $current_post_id, $forum_id)
 {
     // Fix issues if the inserted post is not the first.
     if ($this->qr_insert && !$this->qr_first) {
         $this->template->alter_block_array('postrow', array('S_FIRST_ROW' => false), false, 'change');
     }
     $this->template->assign_vars(array('S_QUICKREPLY_REQUEST' => true, 'S_QR_FULL_QUOTE' => $this->config['qr_full_quote']));
     $this->template->append_var('QR_HIDDEN_FIELDS', build_hidden_fields(array('qr' => 1, 'qr_cur_post_id' => (int) $current_post_id)));
     // Output the page
     page_header($page_title, false, $forum_id);
     page_footer(false, false, false);
     $json_response = new \phpbb\json_response();
     $json_response->send(array('success' => true, 'result' => $this->template->assign_display('@boardtools_quickreply/quickreply_template.html', '', true), 'insert' => $this->qr_insert));
 }
コード例 #5
0
 /**
  * Adds the enabled poll options to the posting template
  *
  * @param array	$post_data		The array of post data
  * @param array	$page_data		The array of template data, will be modified here
  * @param bool	$preview		Whether or not the post is being previewed
  * @return void
  */
 public function config_for_polls_to_template($post_data, &$page_data, $preview = false)
 {
     // Check stuff for official poll setting "can change vote
     if (empty($post_data['poll_title']) || !isset($post_data['poll_vote_change']) && !$this->request->is_set('poll_vote_change')) {
         $page_data['VOTE_CHANGE_CHECKED'] = $this->config['wolfsblvt.advancedpolls.default_poll_votes_change'] ? ' checked="checked"' : '';
     }
     if (isset($page_data['S_POLL_VOTE_CHANGE']) && $page_data['S_POLL_VOTE_CHANGE']) {
         $page_data['S_POLL_VOTE_CHANGE'] = false;
         $page_data['S_AP_POLL_VOTE_CHANGE'] = true;
     }
     $options = $this->get_possible_options();
     if ($post_data['poll_length']) {
         $poll_end = $post_data['poll_start'] + $post_data['poll_length'] * 86400;
         $poll_end_ary = getdate($poll_end);
         $opts = array('year', 'mon', 'mday', 'hours', 'minutes');
         foreach ($opts as $opt) {
             if (isset($options['wolfsblvt_poll_end_' . $opt])) {
                 $options['wolfsblvt_poll_end_' . $opt] = $poll_end_ary[$opt];
             }
         }
     }
     foreach ($options as $option => $default_val) {
         if ($preview || $this->request->is_set($option)) {
             $value_to_take = $this->request->variable($option, $default_val);
         } else {
             if (!empty($post_data['poll_title']) && isset($post_data[$option])) {
                 $value_to_take = is_bool($default_val) ? $post_data[$option] == 1 ? true : false : (int) $post_data[$option];
             } else {
                 $value_to_take = is_bool($default_val) ? $this->config[str_replace('wolfsblvt_', 'wolfsblvt.advancedpolls.default_', $option)] == 1 ? true : false : $default_val;
             }
         }
         if ($option == 'wolfsblvt_poll_max_value') {
             $page_data['WOLFSBLVT_POLL_SCORING'] = true;
         }
         if ($option == 'wolfsblvt_poll_end_year') {
             $page_data['WOLFSBLVT_POLL_END'] = true;
         }
         if (is_bool($value_to_take)) {
             $page_data[strtoupper($option)] = true;
             $page_data[strtoupper($option) . '_CHECKED'] = $value_to_take ? ' checked="checked"' : '';
         } else {
             if ($value_to_take < 0) {
                 $page_data[strtoupper($option)] = '';
             } else {
                 $page_data[strtoupper($option)] = $value_to_take;
             }
         }
         if ($preview && $option == 'wolfsblvt_poll_max_value' && $value_to_take > 1) {
             $page_data['AP_IS_SCORING'] = true;
             $option_eval_opts_txt = '<option value="0"></option>';
             for ($i = 1; $i <= $value_to_take; $i++) {
                 $option_eval_opts_txt .= '<option value="' . $i . '">' . $i . '</option>';
             }
             $block_vars = array('AP_POLL_OPTION_VALUE' => 0, 'AP_POLL_OPTION_OPTS' => $option_eval_opts_txt);
             for ($i = 0, $count = count($post_data['poll_options']); $i < $count; $i++) {
                 $this->template->alter_block_array('poll_option', $block_vars, $i, 'change');
             }
         }
     }
     return;
 }
コード例 #6
0
 /**
  * Generate template rendered pagination
  * Allows full control of rendering of pagination with the template
  *
  * @param string $base_url is url prepended to all links generated within the function
  *							If you use page numbers inside your controller route, base_url should contains a placeholder (%d)
  *							for the page. Also be sure to specify the pagination path information into the start_name argument
  * @param string $block_var_name is the name assigned to the pagination data block within the template (example: <!-- BEGIN pagination -->)
  * @param string $start_name is the name of the parameter containing the first item of the given page (example: start=20)
  *							If you use page numbers inside your controller route, start name should be the string
  *							that should be removed for the first page (example: /page/%d)
  * @param int $num_items the total number of items, posts, etc., used to determine the number of pages to produce
  * @param int $per_page the number of items, posts, etc. to display per page, used to determine the number of pages to produce
  * @param int $start the item which should be considered currently active, used to determine the page we're on
  * @param bool $reverse_count determines whether we weight display of the list towards the start (false) or end (true) of the list
  * @param bool $ignore_on_page decides whether we enable an active (unlinked) item, used primarily for embedded lists
  * @return null
  */
 public function generate_template_pagination($base_url, $block_var_name, $start_name, $num_items, $per_page, $start = 1, $reverse_count = false, $ignore_on_page = false)
 {
     $total_pages = ceil($num_items / $per_page);
     $on_page = $this->get_on_page($per_page, $start);
     $u_previous_page = $u_next_page = '';
     if ($total_pages > 1) {
         if ($reverse_count) {
             $start_page = $total_pages > 5 ? $total_pages - 4 : 1;
             $end_page = $total_pages;
         } else {
             // What we're doing here is calculating what the "start" and "end" pages should be. We
             // do this by assuming pagination is "centered" around the currently active page with
             // the three previous and three next page links displayed. Anything more than that and
             // we display the ellipsis, likewise anything less.
             //
             // $start_page is the page at which we start creating the list. When we have five or less
             // pages we start at page 1 since there will be no ellipsis displayed. Anymore than that
             // and we calculate the start based on the active page. This is the min/max calculation.
             // First (max) would we end up starting on a page less than 1? Next (min) would we end
             // up starting so close to the end that we'd not display our minimum number of pages.
             //
             // $end_page is the last page in the list to display. Like $start_page we use a min/max to
             // determine this number. Again at most five pages? Then just display them all. More than
             // five and we first (min) determine whether we'd end up listing more pages than exist.
             // We then (max) ensure we're displaying the minimum number of pages.
             $start_page = $total_pages > 5 ? min(max(1, $on_page - 2), $total_pages - 4) : 1;
             $end_page = $total_pages > 5 ? max(min($total_pages, $on_page + 2), 5) : $total_pages;
         }
         if ($on_page != 1) {
             $u_previous_page = $this->generate_page_link($base_url, $on_page - 1, $start_name, $per_page);
             $this->template->assign_block_vars($block_var_name, array('PAGE_NUMBER' => '', 'PAGE_URL' => $u_previous_page, 'S_IS_CURRENT' => false, 'S_IS_PREV' => true, 'S_IS_NEXT' => false, 'S_IS_ELLIPSIS' => false));
         }
         // This do...while exists purely to negate the need for start and end assign_block_vars, i.e.
         // to display the first and last page in the list plus any ellipsis. We use this loop to jump
         // around a little within the list depending on where we're starting (and ending).
         $at_page = 1;
         do {
             // We decide whether to display the ellipsis during the loop. The ellipsis is always
             // displayed as either the second or penultimate item in the list. So are we at either
             // of those points and of course do we even need to display it, i.e. is the list starting
             // on at least page 3 and ending three pages before the final item.
             $this->template->assign_block_vars($block_var_name, array('PAGE_NUMBER' => $at_page, 'PAGE_URL' => $this->generate_page_link($base_url, $at_page, $start_name, $per_page), 'S_IS_CURRENT' => !$ignore_on_page && $at_page == $on_page, 'S_IS_NEXT' => false, 'S_IS_PREV' => false, 'S_IS_ELLIPSIS' => $at_page == 2 && $start_page > 2 || $at_page == $total_pages - 1 && $end_page < $total_pages - 1));
             // We may need to jump around in the list depending on whether we have or need to display
             // the ellipsis. Are we on page 2 and are we more than one page away from the start
             // of the list? Yes? Then we jump to the start of the list. Likewise are we at the end of
             // the list and are there more than two pages left in total? Yes? Then jump to the penultimate
             // page (so we can display the ellipsis next pass). Else, increment the counter and keep
             // going
             if ($at_page == 2 && $at_page < $start_page - 1) {
                 $at_page = $start_page;
             } else {
                 if ($at_page == $end_page && $end_page < $total_pages - 1) {
                     $at_page = $total_pages - 1;
                 } else {
                     $at_page++;
                 }
             }
         } while ($at_page <= $total_pages);
         if ($on_page != $total_pages) {
             $u_next_page = $this->generate_page_link($base_url, $on_page + 1, $start_name, $per_page);
             $this->template->assign_block_vars($block_var_name, array('PAGE_NUMBER' => '', 'PAGE_URL' => $u_next_page, 'S_IS_CURRENT' => false, 'S_IS_PREV' => false, 'S_IS_NEXT' => true, 'S_IS_ELLIPSIS' => false));
         }
     }
     // If the block_var_name is a nested block, we will use the last (most
     // inner) block as a prefix for the template variables. If the last block
     // name is pagination, the prefix is empty. If the rest of the
     // block_var_name is not empty, we will modify the last row of that block
     // and add our pagination items.
     $tpl_block_name = $tpl_prefix = '';
     if (strrpos($block_var_name, '.') !== false) {
         $tpl_block_name = substr($block_var_name, 0, strrpos($block_var_name, '.'));
         $tpl_prefix = strtoupper(substr($block_var_name, strrpos($block_var_name, '.') + 1));
     } else {
         $tpl_prefix = strtoupper($block_var_name);
     }
     $tpl_prefix = $tpl_prefix == 'PAGINATION' ? '' : $tpl_prefix . '_';
     $template_array = array($tpl_prefix . 'BASE_URL' => is_string($base_url) ? $base_url : '', $tpl_prefix . 'START_NAME' => $start_name, $tpl_prefix . 'PER_PAGE' => $per_page, 'U_' . $tpl_prefix . 'PREVIOUS_PAGE' => $on_page != 1 ? $u_previous_page : '', 'U_' . $tpl_prefix . 'NEXT_PAGE' => $on_page != $total_pages ? $u_next_page : '', $tpl_prefix . 'TOTAL_PAGES' => $total_pages, $tpl_prefix . 'CURRENT_PAGE' => $on_page, $tpl_prefix . 'PAGE_NUMBER' => $this->on_page($num_items, $per_page, $start));
     if ($tpl_block_name) {
         $this->template->alter_block_array($tpl_block_name, $template_array, true, 'change');
     } else {
         $this->template->assign_vars($template_array);
     }
 }
コード例 #7
0
ファイル: advancedpolls.php プロジェクト: ezpz-cz/web-plugins
    /**
     * Add the possible options to the template
     * 
     * @param array	$post_data		The array of post data
     * @return void
     */
    public function do_poll_modification($topic_data)
    {
        $options = $this->get_possible_options();
        $javascript_vars = array('wolfsblvt_poll_votes_hide_topic' => false, 'wolfsblvt_poll_voters_show_topic' => false, 'wolfsblvt_poll_voters_limit_topic' => false, 'username_clean' => $this->user->data['username_clean'], 'username_string' => get_username_string('full', $this->user->data['user_id'], $this->user->data['username'], $this->user->data['user_colour']), 'l_seperator' => $this->user->lang['COMMA_SEPARATOR'], 'l_none' => $this->user->lang['AP_NONE']);
        // Check how many options
        $sql = 'SELECT poll_option_id
				FROM ' . POLL_OPTIONS_TABLE . '
				WHERE topic_id = ' . $topic_data['topic_id'] . '
				ORDER BY poll_option_id ASC';
        $result = $this->db->sql_query($sql);
        $poll_options = array();
        while ($row = $this->db->sql_fetchrow($result)) {
            $poll_options[] = $row['poll_option_id'];
        }
        $poll_options_count = count($poll_options);
        $this->db->sql_freeresult($result);
        $poll_votes_hidden = false;
        if ($topic_data['wolfsblvt_poll_votes_hide'] == 1 && in_array('wolfsblvt_poll_votes_hide', $options) && $topic_data['poll_length'] > 0 && $topic_data['poll_start'] + $topic_data['poll_length'] > time()) {
            $javascript_vars['wolfsblvt_poll_votes_hide_topic'] = true;
            // Overwrite options to hide values
            for ($i = 0; $i < $poll_options_count; $i++) {
                $this->template->alter_block_array('poll_option', array('POLL_OPTION_RESULT' => '??', 'POLL_OPTION_PERCENT' => '??%', 'POLL_OPTION_PERCENT_REL' => sprintf("%.1d%%", round(100 * (1 / $poll_options_count))), 'POLL_OPTION_PCT' => round(100 * (1 / $poll_options_count)), 'POLL_OPTION_WIDTH' => round(250 * (1 / $poll_options_count)), 'POLL_OPTION_MOST_VOTES' => false), $i, 'change');
            }
            // Overwrite language vars to explain the hide
            $this->template->assign_vars(array('L_NO_VOTES' => $this->user->lang['AP_VOTES_HIDDEN'], 'AP_POLL_HIDE_VOTES' => true));
            $this->template->append_var('L_POLL_LENGTH', $this->user->lang['AP_POLL_RUN_TILL_APPEND']);
            $poll_votes_hidden = true;
        }
        if ($topic_data['wolfsblvt_poll_voters_show'] == 1 && in_array('wolfsblvt_poll_voters_show', $options) && !$poll_votes_hidden && $this->auth->acl_get('u_see_voters')) {
            $javascript_vars['wolfsblvt_poll_voters_show_topic'] = true;
            $sql = 'SELECT poll_option_id, vote_user_id
					FROM ' . POLL_VOTES_TABLE . '
					WHERE topic_id = ' . $topic_data['topic_id'];
            $result = $this->db->sql_query($sql);
            $option_voters = array_fill_keys($poll_options, array());
            $user_cache = array();
            while ($row = $this->db->sql_fetchrow($result)) {
                $option_voters[$row['poll_option_id']][] = $row['vote_user_id'];
                $user_cache[$row['vote_user_id']] = null;
            }
            $this->db->sql_freeresult($result);
            // We need to get the user data so that we can print out their username
            if (!empty($user_cache)) {
                $sql = 'SELECT user_id, username, username_clean, user_colour
						FROM ' . USERS_TABLE . '
						WHERE ' . $this->db->sql_in_set('user_id', array_keys($user_cache));
                $result = $this->db->sql_query($sql);
                while ($row = $this->db->sql_fetchrow($result)) {
                    $user_cache[$row['user_id']] = $row;
                }
                $this->db->sql_freeresult($result);
            }
            foreach ($option_voters as $option_id => $voter_ids) {
                $voter_list = array();
                $last_voter_id = end($voter_ids);
                foreach ($voter_ids as $voter_id) {
                    $username = get_username_string('full', $voter_id, $user_cache[$voter_id]['username'], $user_cache[$voter_id]['user_colour']);
                    $separator = $voter_id != $last_voter_id ? $this->user->lang['COMMA_SEPARATOR'] : '';
                    $html_surrounded = '<span name="' . $user_cache[$voter_id]['username_clean'] . '">' . $username . $separator . '</span>';
                    $voter_list[] = $html_surrounded;
                }
                $block_vars = array('VOTER_LIST' => !empty($voter_list) ? implode($voter_list) : false);
                $this->template->alter_block_array('poll_option', $block_vars, $option_id - 1, 'change');
            }
            $message = $this->user->lang['AP_POLL_VOTES_ARE_VISIBLE'];
            $this->template->assign_vars(array('AP_POLL_SHOW_VOTERS' => true));
            $this->template->append_var('L_POLL_LENGTH', '<span class="poll_vote_notice">' . $message . '</span>');
        }
        if ($topic_data['wolfsblvt_poll_voters_limit'] == 1 && in_array('wolfsblvt_poll_voters_limit', $options)) {
            $javascript_vars['wolfsblvt_poll_voters_limit_topic'] = true;
            $not_be_able_to_vote = false;
            $reason = "";
            // Check if user has posted in this thread
            $sql = 'SELECT post_id
					FROM ' . POSTS_TABLE . '
					WHERE poster_id = ' . $this->user->data['user_id'] . '
						AND topic_id = ' . $topic_data['topic_id'];
            $result = $this->db->sql_query_limit($sql, 1);
            $has_posted = $this->db->sql_fetchrow($result) ? true : false;
            $this->db->sql_freeresult($result);
            if (!$has_posted) {
                $not_be_able_to_vote = true;
                $reason = $this->user->lang['AP_POLL_REASON_NOT_POSTED'];
                $this->template->assign_vars(array('AP_POLL_REASON_NOT_POSTED' => true));
            }
            /**
             * Event to modify the limit poll modification
             *
             * @event wolfsblvt.advancedpolls.modify_poll_limit
             * @var	bool	not_be_able_to_vote			Bool if the user should be able to vote.
             * @var bool	has_posted					Bool if the user already has posted in this topic
             * @var string	reason						The reason why the user can't vote. Should be translated already.
             * @var	array	$topic_data					The topic data array
             * @since 1.0.0
             */
            $vars = array('not_be_able_to_vote', 'has_posted', 'reason', 'topic_row');
            extract($this->dispatcher->trigger_event('wolfsblvt.advancedpolls.modify_poll_limit', compact($vars)));
            if ($not_be_able_to_vote) {
                $this->template->assign_vars(array('S_CAN_VOTE' => false));
                $vote_error = $this->user->lang['AP_POLL_CANT_VOTE'] . $this->user->lang['COLON'] . ' ' . $reason;
                $this->template->assign_vars(array('L_POLL_LENGTH' => '<span class="poll_vote_notice">' . $vote_error . '</span>'));
            }
            $this->template->assign_vars(array('AP_POLL_LIMIT_VOTES' => true));
        }
        // Okay, lets push some of this information to the template
        $this->template->assign_vars(array('AP_JSON_DATA' => 'var wolfsblvt_ap_json_data = ' . json_encode($javascript_vars) . ';'));
    }