/** * 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)); }
/** * Validate config vars and update config table if needed * * @return null */ public function process() { $submit = $this->request->is_set_post('submit') ? true : false; $this->new_config = $this->config; $cfg_array = $this->request->is_set('config') ? $this->request->variable('config', array('' => ''), true) : $this->new_config; $error = array(); // We validate the complete config if whished validate_config_vars($this->display_vars['vars'], $cfg_array, $error); // Do not write values if there is an error if (sizeof($error)) { $submit = false; } // We go through the display_vars to make sure no one is trying to set variables he/she is not allowed to... foreach ($this->display_vars['vars'] as $config_name => $null) { if (!isset($cfg_array[$config_name]) || strpos($config_name, 'legend') !== false) { continue; } $this->new_config[$config_name] = $config_value = $cfg_array[$config_name]; if ($submit) { $this->config->set($config_name, $config_value); } } if ($submit) { $this->log->add('admin', $this->user->data['user_id'], $this->user->ip, 'DIR_CONFIG_SETTINGS'); trigger_error($this->user->lang['CONFIG_UPDATED'] . adm_back_link($this->u_action)); } $this->template->assign_vars(array('L_TITLE' => $this->user->lang[$this->display_vars['title']], 'L_TITLE_EXPLAIN' => $this->user->lang[$this->display_vars['title'] . '_EXPLAIN'], 'S_ERROR' => sizeof($error) ? true : false, 'ERROR_MSG' => implode('<br />', $error), 'U_ACTION' => $this->u_action)); }
/** * {@inheritDoc} */ public function prepare_hidden_fields($step, $key, $action, &$field_data) { if ($key == 'l_lang_options' && $this->request->is_set('l_lang_options')) { return $this->request->variable($key, array(array('')), true); } else if ($key == 'field_default_value') { return $this->request->variable($key, $field_data[$key]); } else { if (!$this->request->is_set($key)) { return false; } else if ($key == 'field_ident' && isset($field_data[$key])) { return $field_data[$key]; } else { return ($key == 'lang_options') ? $this->request->variable($key, array(''), true) : $this->request->variable($key, '', true); } } }
/** * Abstracted method to generate acp configuration pages out of a list of display vars, using * the function build_cfg_template(). * Build configuration template for acp configuration pages * * @param array $display_vars The display vars for this acp site */ protected function generate_stuff_for_cfg_template($display_vars) { $this->new_config = $this->config; $cfg_array = $this->request->is_set('config') ? $this->request->variable('config', ['' => ''], true) : $this->new_config; $error = isset($error) ? $error : []; validate_config_vars($display_vars['vars'], $cfg_array, $error); foreach ($display_vars['vars'] as $config_key => $vars) { if (!is_array($vars) && strpos($config_key, 'legend') === false) { continue; } if (strpos($config_key, 'legend') !== false) { $this->template->assign_block_vars('options', ['S_LEGEND' => true, 'LEGEND' => isset($this->user->lang[$vars]) ? $this->user->lang[$vars] : $vars]); continue; } $type = explode(':', $vars['type']); $l_explain = ''; if ($vars['explain'] && isset($vars['lang_explain'])) { $l_explain = isset($this->user->lang[$vars['lang_explain']]) ? $this->user->lang[$vars['lang_explain']] : $vars['lang_explain']; } else { if ($vars['explain']) { $l_explain = isset($this->user->lang[$vars['lang'] . '_EXPLAIN']) ? $this->user->lang[$vars['lang'] . '_EXPLAIN'] : ''; } } $content = build_cfg_template($type, $config_key, $this->new_config, $config_key, $vars); if (empty($content)) { continue; } $this->template->assign_block_vars('options', ['KEY' => $config_key, 'TITLE' => isset($this->user->lang[$vars['lang']]) ? $this->user->lang[$vars['lang']] : $vars['lang'], 'S_EXPLAIN' => $vars['explain'], 'TITLE_EXPLAIN' => $l_explain, 'CONTENT' => $content]); //unset($display_vars['vars'][$config_key]); } $this->template->assign_vars(['S_ERROR' => sizeof($error) ? true : false, 'ERROR_MSG' => implode('<br />', $error), 'U_ACTION' => $this->u_action]); }
/** * {@inheritDoc} */ public function generate_field($profile_row, $preview_options = false) { $profile_row['field_ident'] = isset($profile_row['var_name']) ? $profile_row['var_name'] : 'pf_' . $profile_row['field_ident']; $field_ident = $profile_row['field_ident']; $default_value = $profile_row['lang_default_value']; $profile_row['field_value'] = $this->request->is_set($field_ident) ? $this->request->variable($field_ident, $default_value, true) : (!isset($this->user->profile_fields[$field_ident]) || $preview_options !== false ? $default_value : $this->user->profile_fields[$field_ident]); $this->template->assign_block_vars($this->get_name_short(), array_change_key_case($profile_row, CASE_UPPER)); }
/** * {@inheritDoc} */ public function prepare_hidden_fields($step, $key, $action, &$field_data) { if ($key == 'field_length' && $this->request->is_set('rows')) { $field_data['rows'] = $this->request->variable('rows', 0); $field_data['columns'] = $this->request->variable('columns', 0); return $field_data['rows'] . '|' . $field_data['columns']; } return parent::prepare_hidden_fields($step, $key, $action, $field_data); }
/** * Enable quick edit * * @param object $event The event object * @return null * @access public */ public function enable_quick_edit($event) { $cfg_array = $this->request->is_set('config') ? $this->request->variable('config', array('' => '')) : ''; if (isset($cfg_array['allow_quick_edit'])) { $this->config->set('allow_quick_edit', (bool) $cfg_array['allow_quick_edit']); \enable_bitfield_column_flag(FORUMS_TABLE, 'forum_flags', log(self::QUICKEDIT_FLAG, 2)); } $event->offsetSet('submit', true); }
/** * 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) { $this->helper->enable_qr_for_guests($forum_id, $topic_data); } // Ajaxify viewtopic data if ($this->request->is_ajax() && $this->request->is_set('qr_request')) { $this->helper->ajax_response($event['page_title'], max($post_list), $forum_id); } if ($s_quick_reply) { if (!function_exists('generate_smilies')) { include $this->phpbb_root_path . 'includes/functions_posting.' . $this->php_ext; } // HTML, BBCode, Smilies, Images, Url, Flash and Quote 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); } $this->template->assign_vars(array('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)); // Show attachment box for adding attachments $show_attach_box = @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); if ($bbcode_status || $smilies_status || $this->config['qr_attach'] && $show_attach_box) { $this->user->add_lang('posting'); } if ($this->config['qr_attach'] && $show_attach_box) { $this->helper->handle_attachments($forum_id, $topic_id, $show_attach_box); } $this->template->append_var('QR_HIDDEN_FIELDS', build_hidden_fields(array('qr' => 1, 'qr_cur_post_id' => (int) max($post_list)))); $this->helper->assign_template_variables_for_qr($forum_id); $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'])); }
/** * {@inheritDoc} */ public function prepare_hidden_fields($step, $key, $action, &$field_data) { if ($key == 'field_default_value') { $field_length = $this->request->variable('field_length', 0); // Do a simple is set check if using checkbox. if ($field_length == 2) { return $this->request->is_set($key); } return $this->request->variable($key, $field_data[$key], true); } $default_lang_options = array('l_lang_options' => array(0 => array('')), 'lang_options' => array(0 => '')); if (isset($default_lang_options[$key]) && $this->request->is_set($key)) { return $this->request->variable($key, $default_lang_options[$key], true); } return parent::prepare_hidden_fields($step, $key, $action, $field_data); }
public function profile_side_switcher($event) { $topic_data = $event['topic_data']; $forum_id = $event['forum_id']; if ($this->request->is_set('pss')) { $pss_left = $this->request->variable('pss', 0); $sql = 'UPDATE ' . USERS_TABLE . ' SET allow_pss_left = ' . (int) $pss_left . ' WHERE user_id = ' . (int) $this->user->data['user_id']; $result = $this->db->sql_query($sql); if ($this->request->is_ajax()) { $json_response = new \phpbb\json_response(); $json_response->send(array('success' => $result ? true : false)); } $this->db->sql_freeresult($result); } $this->template->assign_vars(array('PSS_URL_LEFT' => append_sid("{$this->phpbb_root_path}viewtopic.{$this->php_ext}", 'f=' . $forum_id . '&t=' . $topic_data['topic_id'] . '&pss=1'), 'PSS_URL_RIGHT' => append_sid("{$this->phpbb_root_path}viewtopic.{$this->php_ext}", 'f=' . $forum_id . '&t=' . $topic_data['topic_id'] . '&pss=0'))); }
/** * {@inheritDoc} */ public function prepare_hidden_fields($step, $key, $action, &$field_data) { if ($key == 'field_default_value') { $always_now = $this->request->variable('always_now', 0); if ($always_now) { return 'now'; } else { if ($this->request->is_set('field_default_value_day')) { $field_data['field_default_value_day'] = $this->request->variable('field_default_value_day', 0); $field_data['field_default_value_month'] = $this->request->variable('field_default_value_month', 0); $field_data['field_default_value_year'] = $this->request->variable('field_default_value_year', 0); return sprintf('%2d-%2d-%4d', $field_data['field_default_value_day'], $field_data['field_default_value_month'], $field_data['field_default_value_year']); } } } return parent::prepare_hidden_fields($step, $key, $action, $field_data); }
/** * {@inheritDoc} */ public function prepare_hidden_fields($step, $key, $action, &$field_data) { if (!$this->request->is_set($key)) { // Do not set this variable, we will use the default value return null; } else { if ($key == 'field_ident' && isset($field_data[$key])) { return $field_data[$key]; } else { $default_value = ''; $lang_fields = array('l_lang_name', 'l_lang_explain', 'l_lang_default_value', 'l_lang_options'); if (in_array($key, $lang_fields)) { $default_value = array(0 => ''); } return $this->request->variable($key, $default_value, true); } } }
/** * Create the options to show the cookie acceptance box * * @param object $event The event object * @return null * @access public */ public function page_header($event) { $cookie_enabled = $this->config['cookie_policy_enabled']; // If we have already set the cookie on this device then there is no need to process $cookie_set = $this->request->is_set($this->config['cookie_name'] . '_ca', \phpbb\request\request_interface::COOKIE) ? true : false; if ($this->config['cookie_policy_enabled'] && !$cookie_set && !$this->user->data['is_bot']) { // Only need to do this if we are trying to detect if cookie required if ($this->config['cookie_eu_detect']) { // Setting this to true here means that if there is a problem with the IP lookup then the cookie will be enabled - just in case we have got it wrong! $cookie_enabled = true; // Check if cURL is available on the server if (function_exists('curl_version')) { $curl_handle = curl_init(); curl_setopt($curl_handle, CURLOPT_CONNECTTIMEOUT, 2); curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, 1); curl_setopt($curl_handle, CURLOPT_URL, 'http://ip-api.com/json/' . $this->user->ip . '?fields=status,countryCode'); $ip_query = curl_exec($curl_handle); curl_close($curl_handle); if (!empty($ip_query)) { $ip_array = json_decode($ip_query, true); $eu_array = array('AT', 'BE', 'BG', 'CY', 'CZ', 'DE', 'DK', 'EE', 'ES', 'EU', 'FI', 'FR', 'FX', 'GB', 'GR', 'HR', 'HU', 'IE', 'IM', 'IT', 'LT', 'LU', 'LV', 'MT', 'NL', 'PL', 'PT', 'RO', 'SE', 'SI', 'SK', 'UK'); if ($ip_array['status'] == 'success' && !in_array($ip_array['countryCode'], $eu_array)) { // IP not in an EU country therefore we do not need to invoke the Cookie Policy $cookie_enabled = false; } else { if ($ip_array['status'] != 'success' && $this->config['cookie_log_errors']) { $this->log->add('critical', $this->user->data['user_id'], $this->user->ip, 'LOG_COOKIE_ERROR'); } } } else { if ($this->config['cookie_log_errors']) { $this->log->add('critical', $this->user->data['user_id'], $this->user->ip, 'LOG_SERVER_ERROR'); } } } else { if ($this->config['cookie_log_errors']) { $this->log->add('critical', $this->user->data['user_id'], $this->user->ip, 'LOG_CURL_ERROR'); } } } $this->template->assign_vars(array('COOKIE_BOX_BG_COLOUR' => addslashes($this->config['cookie_box_bg_colour']), 'COOKIE_BOX_HREF_COLOUR' => addslashes($this->config['cookie_box_href_colour']), 'COOKIE_BOX_TXT_COLOUR' => addslashes($this->config['cookie_box_txt_colour']), 'COOKIE_CLASS' => $this->config['cookie_box_position'] ? addslashes('cookie-box rightside') : addslashes('cookie-box leftside'), 'COOKIE_EXPIRES' => addslashes($this->config['cookie_expire']), 'COOKIE_NAME' => addslashes($this->config['cookie_name']), 'S_COOKIE_CUSTOM_BOX' => $this->config['cookie_custom_box'])); } $this->template->assign_vars(array('S_SHOW_COOKIE_ACCEPT' => $cookie_set, 'S_COOKIE_ENABLED' => $cookie_enabled)); }
/** * {@inheritDoc} */ public function generate_field($profile_row, $preview_options = false) { $profile_row['field_ident'] = isset($profile_row['var_name']) ? $profile_row['var_name'] : 'pf_' . $profile_row['field_ident']; $field_ident = $profile_row['field_ident']; $default_value = $profile_row['field_default_value']; $value = $this->request->is_set($field_ident) ? $this->request->variable($field_ident, $default_value) : (!isset($this->user->profile_fields[$field_ident]) || $preview_options !== false ? $default_value : $this->user->profile_fields[$field_ident]); if (!$this->lang_helper->is_set($profile_row['field_id'], $profile_row['lang_id'], 1)) { if ($preview_options) { $this->lang_helper->load_preview_options($profile_row['field_id'], $profile_row['lang_id'], $preview_options); } else { $this->lang_helper->load_option_lang($profile_row['lang_id']); } } $profile_row['field_value'] = (int) $value; $this->template->assign_block_vars('dropdown', array_change_key_case($profile_row, CASE_UPPER)); $options = $this->lang_helper->get($profile_row['field_id'], $profile_row['lang_id']); foreach ($options as $option_id => $option_value) { $this->template->assign_block_vars('dropdown.options', array('OPTION_ID' => $option_id, 'SELECTED' => $value == $option_id ? ' selected="selected"' : '', 'VALUE' => $option_value)); } }
/** * {@inheritDoc} */ public function generate_field($profile_row, $preview_options = false) { $profile_row['field_ident'] = isset($profile_row['var_name']) ? $profile_row['var_name'] : 'pf_' . $profile_row['field_ident']; $field_ident = $profile_row['field_ident']; $default_value = $profile_row['field_default_value']; if ($this->request->is_set($field_ident)) { $value = $this->request->variable($field_ident, '') === '' ? null : $this->request->variable($field_ident, $default_value); } else { if ($preview_options === false && array_key_exists($field_ident, $this->user->profile_fields) && is_null($this->user->profile_fields[$field_ident])) { $value = null; } else { if (!isset($this->user->profile_fields[$field_ident]) || $preview_options !== false) { $value = $default_value; } else { $value = $this->user->profile_fields[$field_ident]; } } } $profile_row['field_value'] = is_null($value) || $value === '' ? '' : (int) $value; $this->template->assign_block_vars('int', array_change_key_case($profile_row, CASE_UPPER)); }
/** * Display message to the user if there where failed login trys * * @param object $event The event object * @return null * @access public */ public function page_footer($event) { // clear failed_logins_count_last on user action if ($this->request->is_set('failedlogins_remove')) { if (check_form_key('failedlogins_remove')) { $sql = 'UPDATE ' . USERS_TABLE . ' SET failed_logins_count_last = 0 WHERE user_id = ' . (int) $this->user->data['user_id']; $this->db->sql_query($sql); if ($this->request->is_ajax()) { trigger_error('REMOVED_FAILED_LOGINS'); } } else { if ($this->request->is_ajax()) { trigger_error('FORM_INVALID', E_USER_WARNING); } } } // Display failed logins if ($this->user->data['failed_logins_count_last'] > 0) { add_form_key('failedlogins_remove'); $this->template->assign_vars(array('U_REMOVE_MESSAGE' => generate_board_url() . '/' . $this->user->page['page'], 'FAILED_LOGINS' => $this->user->data['failed_logins_count_last'] == 1 ? $this->user->lang['ONE_FAILED_LOGIN'] : sprintf($this->user->lang['FAILED_LOGINS_COUNT'], $this->user->data['failed_logins_count_last']))); } }
/** * Allow justification to display * * @param object $event The event object * @return null * @access public */ public function user_justification_display($event) { if (!$this->auth->acl_get('a_user')) { return; } $this->data = $event['member']; $this->user_id = (int) $this->data['user_id']; $this->user->add_lang_ext('rmcgirr83/activationjustification', 'common'); if ($this->data['user_type'] != USER_INACTIVE && $this->data['user_inactive_reason'] != INACTIVE_REGISTER) { $aj_result = $this->request->variable('aj_res', ''); if (!empty($aj_result)) { if ($aj_result == 'success') { $aj_message = $this->user->lang('ACTIVATED_SUCCESS'); $this->template->assign_vars(array('AJ_MESSAGE' => $aj_message)); } } return; } if (!$this->request->is_set('aj') || $this->request->is_set('aj') && $this->request->is_set('confirm_key') && !confirm_box(true)) { $params = array('mode' => 'viewprofile', 'u' => $this->user_id, 'aj' => 1); $this->template->assign_vars(array('JUSTIFICATION' => empty($this->data['user_justification']) ? $this->user->lang('NO_JUSTIFICATION') : $this->data['user_justification'], 'U_ACTIVATE' => append_sid($this->root_path . 'memberlist.' . $this->php_ext, $params), 'S_JUSTIFY' => true)); return; } // Time to activate a user. But are you sure? if (!confirm_box(true)) { $hidden_fields = array('mode' => 'viewprofile'); $message = $this->user->lang('SURE_ACTIVATE', $this->data['username']); confirm_box(false, $message, build_hidden_fields($hidden_fields)); } $this->user_justification_activate(); // The page needs to be reloaded to show the new status. $args = array('mode' => 'viewprofile', 'u' => $this->user_id, 'aj_res' => 'success'); $url = generate_board_url(); $url .= (substr($url, -1) == '/' ? '' : '/') . 'memberlist.' . $this->php_ext; $url = append_sid($url, $args); redirect($url); }
function main($id, $mode) { global $config, $db, $user, $template, $request; global $phpbb_root_path, $phpbb_admin_path, $phpEx; global $phpbb_container; $this->config = $config; $this->core = $phpbb_container->get('phpbbseo.usu.core'); $this->db = $db; $this->request = $request; $this->template = $template; $this->user = $user; $this->phpbb_root_path = $phpbb_root_path; $this->php_ext = $phpEx; $this->user->add_lang_ext('phpbbseo/usu', 'acp_usu'); $action = $this->request->variable('action', ''); $submit = $this->request->is_set_post('submit'); $cancel = $this->request->variable('cancel', ''); $form_key = 'acp_seo_usu'; add_form_key($form_key); $display_vars = array(); // --> Zero Dupe if (@isset($this->core->seo_opt['zero_dupe'])) { $this->multiple_options['zero_dupe']['post_redir_values'] = array('off' => 'off', 'post' => 'post', 'guest' => 'guest', 'all' => 'all'); // do not change $this->multiple_options['zero_dupe']['post_redir_lang'] = array('off' => $this->user->lang['ACP_ZERO_DUPE_OFF'], 'post' => $this->user->lang['ACP_ZERO_DUPE_MSG'], 'guest' => $this->user->lang['ACP_ZERO_DUPE_GUEST'], 'all' => $this->user->lang['ACP_ZERO_DUPE_ALL']); } // <-- Mod rewrite selector if ($this->core->modrtype == 1) { $this->seo_unset_opts = array('cache_layer', 'rem_ids'); } else { if (!$this->core->seo_opt['cache_layer']) { $this->seo_unset_opts = array('rem_ids'); } } $this->modrtype_lang = $this->set_phpbb_seo_links(); $this->multiple_options['modrtype_lang'] = $this->modrtype_lang['titles']; if (@isset($this->core->seo_opt['modrtype'])) { $this->multiple_options['modrtype_values'] = array(1 => 1, 2 => 2, 3 => 3); // do not change; } // <-- Mod rewrite selector foreach ($this->seo_unset_opts as $opt) { if ($optkey = array_search($opt, $this->core->cache_config['dynamic_options'])) { unset($this->core->cache_config['dynamic_options'][$optkey]); } } // We need shorter URLs with Virtual Folder Trick if ($this->core->seo_opt['virtual_folder']) { $this->lengh_limit = 20; $this->word_limit = 3; } else { $this->lengh_limit = 30; $this->word_limit = 5; } $related_installed = false; switch ($mode) { case 'settings': $display_vars['title'] = 'ACP_PHPBB_SEO_CLASS'; $this->user->lang['ACP_PHPBB_SEO_CLASS_EXPLAIN'] = sprintf($this->user->lang['ACP_PHPBB_SEO_CLASS_EXPLAIN'], $this->modrtype_lang['ulink'], $this->modrtype_lang['uforumlink'], '</p><hr/><p><b>' . $this->user->lang['ACP_PHPBB_SEO_MODE'] . ' : ' . $this->modrtype_lang['link'] . ' - ( ' . $this->modrtype_lang['forumlink'] . ' )</b></p><hr/><p>'); $display_vars['vars'] = array(); $i = 2; $display_vars['vars']['legend1'] = 'ACP_PHPBB_SEO_CLASS'; foreach ($this->core->cache_config['dynamic_options'] as $optionname => $optionvalue) { if (@is_bool($this->core->seo_opt[$optionvalue])) { if ($optionvalue == 'virtual_root') { if (!$this->core->seo_path['phpbb_script']) { continue; } if (empty($this->config['force_server_vars'])) { // we assume that the force server var will not break everything // since this is in use in all cases in USU set_config('force_server_vars', 1); } } $display_vars['vars'][$optionvalue] = array('lang' => $optionvalue, 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true, 'lang_explain' => $optionvalue . '_explain'); $this->new_config[$optionvalue] = $this->core->seo_opt[$optionvalue]; } else { if (@isset($this->multiple_options[$optionvalue . '_values'])) { $this->dyn_select[$optionvalue] = $this->multiple_options[$optionvalue . '_values']; $display_vars['vars'][$optionvalue] = array('lang' => $optionvalue, 'validate' => 'string', 'type' => 'select', 'method' => 'select_string', 'explain' => true, 'lang_explain' => $optionvalue . '_explain'); $this->new_config[$optionvalue] = $this->core->seo_opt[$optionvalue]; } else { if (is_array($optionvalue)) { $display_vars['vars']['legend' . $i] = $optionname; $i++; foreach ($optionvalue as $key => $value) { $this->array_type_cfg[$optionname . '_' . $key] = array('main' => $optionname, 'sub' => $key); if (is_bool($value)) { $display_vars['vars'][$optionname . '_' . $key] = array('lang' => $optionname . '_' . $key, 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true, 'lang_explain' => $optionname . '_' . $key . '_explain'); $this->new_config[$optionname . '_' . $key] = $this->core->seo_opt[$optionname][$key]; } else { if (@isset($this->multiple_options[$optionname][$key . '_values'])) { $this->dyn_select[$optionname . '_' . $key] = $this->multiple_options[$optionname][$key . '_values']; $display_vars['vars'][$optionname . '_' . $key] = array('lang' => $optionname . '_' . $key, 'validate' => 'string', 'type' => 'select', 'method' => 'select_string', 'explain' => true, 'lang_explain' => $optionname . '_' . $key . '_explain'); $this->new_config[$optionname . '_' . $key] = $this->core->seo_opt[$optionname][$key]; } else { $display_vars['vars'][$optionname . '_' . $key] = array('lang' => $optionname . '_' . $key, 'validate' => 'string:0:50', 'type' => 'text:50:50', 'explain' => true, 'lang_explain' => $optionname . '_' . $key . '_explain'); $this->new_config[$optionname . '_' . $key] = $this->core->seo_opt[$optionname][$key]; } } } } } } } break; case 'forum_url': $forbidden = array($this->core->seo_static['forum'], $this->core->seo_static['global_announce'], $this->core->seo_static['user'], $this->core->seo_static['topic'], $this->core->seo_static['atopic'], $this->core->seo_static['utopic'], $this->core->seo_static['leaders'], $this->core->seo_static['post'], $this->core->seo_static['group'], $this->core->seo_static['npost'], $this->core->seo_static['index']); if ($this->core->modrtype == 1 || !$this->core->seo_opt['cache_layer']) { trigger_error($this->user->lang['ACP_NO_FORUM_URL'] . preg_replace('`(&|&|\\?)mode=forum_url`i', '', adm_back_link($this->u_action))); break; } $display_vars['title'] = 'ACP_FORUM_URL'; $this->user->lang['ACP_FORUM_URL_EXPLAIN'] .= '</p><hr/><p><b>' . $this->user->lang['ACP_PHPBB_SEO_VERSION'] . ' : ' . $this->modrtype_lang['link'] . ' - ( ' . $this->modrtype_lang['forumlink'] . ' )</b></p><hr/><p>'; $display_vars['vars'] = array(); $display_vars['vars']['legend1'] = 'ACP_FORUM_URL'; $sql = "SELECT forum_id, forum_name\n\t\t\t\t\tFROM " . FORUMS_TABLE . "\n\t\t\t\t\tORDER BY left_id ASC"; $result = $this->db->sql_query($sql); $forum_url_title = $error_cust = ''; while ($row = $this->db->sql_fetchrow($result)) { $this->forum_ids[$row['forum_id']] = $row['forum_name']; } $this->db->sql_freeresult($result); // take care of deleted forums foreach ($this->core->cache_config['forum_urls'] as $fid => $null) { if (!isset($this->forum_ids[$fid])) { unset($this->core->cache_config['forum_urls'][$fid]); } } foreach ($this->forum_ids as $forum_id => $forum_name) { $error_cust = ''; // Is the URL cached already ? if (empty($this->core->cache_config['forum_urls'][$forum_id])) { // Suggest the one from the title $forum_url_title = $this->core->format_url($forum_name, $this->core->seo_static['forum']); if (!in_array($forum_url_title, $forbidden)) { if (array_search($forum_url_title, $this->core->cache_config['forum_urls'])) { $this->new_config['forum_url' . $forum_id] = $forum_url_title . $this->core->seo_delim['forum'] . $forum_id; $error_cust = '<li> ' . sprintf($this->user->lang['SEO_ADVICE_DUPE'], $forum_url_title) . '</li>'; } else { $this->new_config['forum_url' . $forum_id] = $forum_url_title . (@$this->core->cache_config['settings']['rem_ids'] ? '' : $this->core->seo_delim['forum'] . $forum_id); } } else { $this->new_config['forum_url' . $forum_id] = $forum_url_title . $this->core->seo_delim['forum'] . $forum_id; $error_cust = '<li> ' . sprintf($this->user->lang['SEO_ADVICE_RESERVED'], $forum_url_title) . '</li>'; } $title = '<b style="color:red">' . $forum_name . ' - ID ' . $forum_id . '</b>'; $status_msg = '<b style="color:red">' . $this->user->lang['SEO_CACHE_URL_NOT_OK'] . '</b>'; $status_msg .= '<br/><span style="color:red">' . $this->user->lang['SEO_CACHE_URL'] . ' :</span> ' . $this->new_config['forum_url' . $forum_id] . $this->core->seo_ext['forum']; $display_vars['vars']['forum_url' . $forum_id] = array('lang' => $title, 'validate' => 'string', 'type' => 'custom', 'method' => 'forum_url_input', 'explain' => true, 'lang_explain_custom' => $status_msg, 'append' => $this->seo_advices($this->new_config['forum_url' . $forum_id], $forum_id, false, $error_cust)); } else { // Cached $this->new_config['forum_url' . $forum_id] = $this->core->cache_config['forum_urls'][$forum_id]; $title = '<b style="color:green">' . $forum_name . ' - ID ' . $forum_id . '</b>'; $status_msg = '<span style="color:green">' . $this->user->lang['SEO_CACHE_URL_OK'] . ' :</span> <b style="color:green">' . $this->new_config['forum_url' . $forum_id] . '</b>'; $status_msg .= '<br/><span style="color:green">' . $this->user->lang['SEO_CACHE_URL'] . ' :</span> ' . $this->new_config['forum_url' . $forum_id] . $this->core->seo_ext['forum']; $display_vars['vars']['forum_url' . $forum_id] = array('lang' => $title, 'validate' => 'string:0:100', 'type' => 'custom', 'method' => 'forum_url_input', 'explain' => true, 'lang_explain_custom' => $status_msg, 'append' => $this->seo_advices($this->new_config['forum_url' . $forum_id], $forum_id, true)); } } break; case 'server': $display_vars['title'] = 'ACP_REWRITE_CONF'; $this->user->lang['ACP_REWRITE_CONF_EXPLAIN'] .= '</p><hr/><p><b>' . $this->user->lang['ACP_PHPBB_SEO_VERSION'] . ' : ' . $this->modrtype_lang['link'] . ' - ( ' . $this->modrtype_lang['forumlink'] . ' )</b></p><p>'; $display_vars['vars'] = array(); $display_vars['vars']['legend1'] = 'ACP_REWRITE_CONF'; if ($this->core->seo_path['phpbb_script'] && !$this->core->seo_opt['virtual_root']) { $display_vars['vars']['rbase'] = array('lang' => 'SEO_SERVER_CONF_RBASE', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true); } $display_vars['vars']['save'] = array('lang' => 'SEO_SERVER_CONF_SAVE', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true); $display_vars['vars']['more_options'] = array('lang' => 'SEO_MORE_OPTION', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true); $this->new_config['save'] = false; $cfg_array = $this->request->is_set('config') ? utf8_normalize_nfc($this->request->variable('config', array('' => ''), true)) : $this->new_config; $this->new_config['more_options'] = isset($cfg_array['more_options']) ? $cfg_array['more_options'] : false; $this->new_config['slash'] = isset($cfg_array['slash']) ? $cfg_array['slash'] : false; $this->new_config['wslash'] = isset($cfg_array['wslash']) ? $cfg_array['wslash'] : false; $this->new_config['rbase'] = isset($cfg_array['rbase']) ? $cfg_array['rbase'] : false; if ($this->new_config['more_options']) { $display_vars['vars']['slash'] = array('lang' => 'SEO_SERVER_CONF_SLASH', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true); $display_vars['vars']['wslash'] = array('lang' => 'SEO_SERVER_CONF_WSLASH', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true); } // Dirty yet simple templating $this->user->lang['ACP_REWRITE_CONF_EXPLAIN'] .= $this->seo_server_conf(); $this->template->assign_vars(array('S_SEO_HTACCESS' => 1)); break; case 'extended': $display_vars = array('title' => 'ACP_SEO_EXTENDED', 'vars' => array('legend1' => 'SEO_EXTERNAL_LINKS', 'seo_ext_links' => array('lang' => 'SEO_EXTERNAL_LINKS', 'validate' => 'bool', 'type' => 'radio:enabled_disabled', 'explain' => true, 'default' => 1), 'seo_ext_subdomain' => array('lang' => 'SEO_EXTERNAL_SUBDOMAIN', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true, 'default' => 0), 'seo_ext_classes' => array('lang' => 'SEO_EXTERNAL_CLASSES', 'validate' => 'string', 'type' => 'text:40:250', 'explain' => true, 'default' => ''))); // Related topics if (!empty($this->config['seo_related_on'])) { $related_installed = true; $this->user->add_lang_ext('phpbbseo/usu', 'acp_usu_install'); $display_vars['vars'] += array('legend2' => 'SEO_RELATED_TOPICS', 'seo_related' => array('lang' => 'SEO_RELATED', 'validate' => 'bool', 'type' => 'radio:enabled_disabled', 'explain' => true, 'append' => !empty($this->config['seo_related']) ? '<br/>' . (!empty($this->config['seo_related_fulltext']) ? $this->user->lang['FULLTEXT_INSTALLED'] : $this->user->lang['FULLTEXT_NOT_INSTALLED']) : '', 'default' => 0), 'seo_related_check_ignore' => array('lang' => 'SEO_RELATED_CHECK_IGNORE', 'validate' => 'bool', 'type' => 'radio:enabled_disabled', 'explain' => true, 'default' => 0), 'seo_related_limit' => array('lang' => 'SEO_RELATED_LIMIT', 'validate' => 'int:2:25', 'type' => 'text:3:4', 'explain' => true, 'default' => 5), 'seo_related_allforums' => array('lang' => 'SEO_RELATED_ALLFORUMS', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true, 'default' => 0)); } // dynamic meta tag mod if (!empty($this->config['seo_meta_on'])) { $display_vars['vars'] += array('legend3' => 'SEO_META', 'seo_meta_title' => array('lang' => 'SEO_META_TITLE', 'validate' => 'string:0:225', 'type' => 'text:40:250', 'explain' => true, 'default' => $this->config['sitename']), 'seo_meta_desc' => array('lang' => 'SEO_META_DESC', 'validate' => 'string:0:225', 'type' => 'text:40:250', 'explain' => true, 'default' => $this->config['site_desc']), 'seo_meta_desc_limit' => array('lang' => 'SEO_META_DESC_LIMIT', 'validate' => 'int:5:40', 'type' => 'text:3:4', 'explain' => true, 'default' => 25), 'seo_meta_bbcode_filter' => array('lang' => 'SEO_META_BBCODE_FILTER', 'validate' => 'string:0:225', 'type' => 'text:40:250', 'explain' => true, 'default' => 'img|url|flash|code'), 'seo_meta_keywords' => array('lang' => 'SEO_META_KEYWORDS', 'validate' => 'string:0:225', 'type' => 'text:40:250', 'explain' => true, 'default' => $this->config['site_desc']), 'seo_meta_keywords_limit' => array('lang' => 'SEO_META_KEYWORDS_LIMIT', 'validate' => 'int:5:40', 'type' => 'text:3:4', 'explain' => true, 'default' => 15), 'seo_meta_min_len' => array('lang' => 'SEO_META_MIN_LEN', 'validate' => 'int:0:10', 'type' => 'text:3:4', 'explain' => true, 'default' => 2), 'seo_meta_check_ignore' => array('lang' => 'SEO_META_CHECK_IGNORE', 'validate' => 'bool', 'type' => 'radio:enabled_disabled', 'explain' => true, 'default' => 0), 'seo_meta_lang' => array('lang' => 'SEO_META_LANG', 'validate' => 'lang', 'type' => 'select', 'method' => 'language_select', 'params' => array('{CONFIG_VALUE}'), 'explain' => true, 'default' => $this->config['default_lang']), 'seo_meta_copy' => array('lang' => 'SEO_META_COPY', 'validate' => 'string:0:225', 'type' => 'text:40:250', 'explain' => true, 'default' => $this->config['sitename']), 'seo_meta_file_filter' => array('lang' => 'SEO_META_FILE_FILTER', 'validate' => 'string:0:225', 'type' => 'text:40:250', 'explain' => true, 'default' => 'ucp'), 'seo_meta_get_filter' => array('lang' => 'SEO_META_GET_FILTER', 'validate' => 'string:0:225', 'type' => 'text:40:250', 'explain' => true, 'default' => 'style,hilit,sid'), 'seo_meta_robots' => array('lang' => 'SEO_META_ROBOTS', 'validate' => 'string:0:225', 'type' => 'text:25:150', 'explain' => true, 'default' => 'index,follow'), 'seo_meta_noarchive' => array('lang' => 'SEO_META_NOARCHIVE', 'validate' => 'string:0:225', 'multiple_validate' => 'int', 'type' => 'custom', 'method' => 'select_multiple', 'params' => array('{CONFIG_VALUE}', '{KEY}', $this->forum_select()), 'explain' => true, 'default' => ''), 'seo_meta_og' => array('lang' => 'SEO_META_OG', 'validate' => 'bool', 'type' => 'radio:enabled_disabled', 'explain' => true, 'default' => 0)); // Open Graph if (!empty($this->config['seo_meta_og'])) { $display_vars['vars'] += array('fb_app_id' => array('lang' => 'SEO_META_FB_APP_ID', 'validate' => 'string:0:225', 'type' => 'text:40:250', 'explain' => true, 'default' => '')); } } // Optimal title if (!empty($this->config['seo_optimal_title_on'])) { $display_vars['vars'] += array('legend' => 'SEO_PAGE_TITLES', 'seo_append_sitename' => array('lang' => 'SEO_APPEND_SITENAME', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true, 'default' => 0)); } // install if necessary foreach ($display_vars['vars'] as $config_name => $config_setup) { if (strpos($config_name, 'legend') !== false) { continue; } if (!isset($this->config[$config_name])) { set_config($config_name, $config_setup['default']); unset($display_vars['vars'][$config_name]['default']); } } $this->new_config = $this->config; break; case 'sync_url': $sync_url = $this->request->variable('sync', ''); $redirect_url = "{$phpbb_admin_path}index.{$phpEx}?i=-phpbbseo-usu-acp-usu&mode=sync_url"; $go = max(0, $this->request->variable('go', 0)); if ($cancel || !$go) { trigger_error($this->user->lang['SYNC_WARN'] . '<br/><br/><b> • <a href="' . append_sid($redirect_url, "go=1&sync=sync") . '">' . $this->user->lang['SYNC_TOPIC_URLS'] . '</a><br/><br/> • <a href="' . append_sid($redirect_url, "go=1&sync=reset") . '" >' . $this->user->lang['SYNC_RESET_TOPIC_URLS'] . '</a></b>'); } $starttime = microtime(true); $start = max(0, $this->request->variable('start', 0)); $limit = max(100, $this->request->variable('limit', 0)); // Do not go over 1000 topic in a row $limit = min(1000, $limit); $poll_processed = 0; $forum_data = array(); $url_updated = 0; if ($sync_url === 'sync') { // get all forum info $sql = 'SELECT forum_id, forum_name FROM ' . FORUMS_TABLE; $result = $db->sql_query($sql); while ($row = $db->sql_fetchrow($result)) { $forum_data[$row['forum_id']] = $row['forum_name']; $this->core->set_url($row['forum_name'], $row['forum_id'], $this->core->seo_static['forum']); } $db->sql_freeresult($result); // let's work $sql = 'SELECT * FROM ' . TOPICS_TABLE . ' ORDER BY topic_id ASC'; $result = $db->sql_query_limit($sql, $limit, $start); while ($row = $db->sql_fetchrow($result)) { $forum_id = (int) $row['forum_id']; $topic_id = (int) $row['topic_id']; $_parent = $row['topic_type'] == POST_GLOBAL ? $this->core->seo_static['global_announce'] : $this->core->seo_url['forum'][$forum_id]; if (!$this->core->check_url('topic', $row['topic_url'], $_parent)) { if (!empty($row['topic_url'])) { // Here we get rid of the seo delim (-t) and put it back even in simple mod // to be able to handle all cases at once $_url = preg_replace('`' . $this->core->seo_delim['topic'] . '$`i', '', $row['topic_url']); $_title = $this->core->get_url_info('topic', $_url . $this->core->seo_delim['topic'] . $topic_id, 'title'); } else { $_title = $this->core->modrtype > 2 ? censor_text($row['topic_title']) : ''; } unset($this->core->seo_url['topic'][$topic_id]); $row['topic_url'] = $this->core->get_url_info('topic', $this->core->prepare_url('topic', $_title, $topic_id, $_parent, empty($_title) || $_title == $this->core->seo_static['topic'] ? true : false), 'url'); unset($this->core->seo_url['topic'][$topic_id]); if ($row['topic_url']) { // Update the topic_url field for later re-use $sql = "UPDATE " . TOPICS_TABLE . " SET topic_url = '" . $db->sql_escape($row['topic_url']) . "'\n\t\t\t\t\t\t\t\t\tWHERE topic_id = {$topic_id}"; $db->sql_query($sql); $url_updated++; } } } $db->sql_freeresult($result); $sql = 'SELECT count(topic_id) as topic_cnt FROM ' . TOPICS_TABLE; $result = $db->sql_query($sql); $cnt = $db->sql_fetchrow($result); $db->sql_freeresult($result); if ($cnt['topic_cnt'] > $start + $limit) { $endtime = microtime(true); $duration = $endtime - $starttime; $speed = round($limit / $duration, 2); $percent = round(($start + $limit) / $cnt['topic_cnt'] * 100, 2); $message = sprintf($user->lang['SYNC_PROCESSING'], $percent, $start + $limit, $cnt['topic_cnt'], $limit, $speed, round($duration, 2), round(($cnt['topic_cnt'] - $start) / $speed / 60, 2)); if ($url_updated) { $message .= sprintf($user->lang['SYNC_ITEM_UPDATED'], '<br/>' . $url_updated); } $new_limit = $duration < 10 ? $limit + 50 : $limit - 10; meta_refresh(1, append_sid($redirect_url, 'go=1&start=' . ($start + $limit) . "&limit={$new_limit}&sync=sync")); trigger_error("{$message}<br/>"); } else { trigger_error($user->lang['SYNC_COMPLETE'] . sprintf($user->lang['RETURN_INDEX'], '<br/><br/><a href="' . append_sid($redirect_url) . '" >', '</a>')); } } else { if ($sync_url === 'reset') { if (confirm_box(true)) { $sql = "UPDATE " . TOPICS_TABLE . " SET topic_url = ''"; $db->sql_query($sql); trigger_error($user->lang['SYNC_RESET_COMPLETE'] . '<br/><br/><b> • <a href="' . append_sid($redirect_url, "go=1&sync=sync") . '">' . $user->lang['SYNC_TOPIC_URLS'] . '</a><br/><br/> • ' . sprintf($user->lang['RETURN_INDEX'], '<a href="' . append_sid($redirect_url) . '" >', '</a></b>')); } else { confirm_box(false, $user->lang['CONFIRM_OPERATION'], build_hidden_fields(array('go' => '1', 'sync' => 'reset')), 'confirm_body.html'); } } else { trigger_error($user->lang['SYNC_WARN'] . '<br/><br/><b> • <a href="' . append_sid($redirect_url, "go=1&sync=sync") . '">' . $user->lang['SYNC_TOPIC_URLS'] . '</a><br/><br/> • <a href="' . append_sid($redirect_url, "go=1&sync=reset") . '" >' . $user->lang['SYNC_RESET_TOPIC_URLS'] . '</a></b>'); } } break; default: trigger_error('NO_MODE', E_USER_ERROR); break; } $error = array(); $seo_msg = array(); $cfg_array = $this->request->is_set('config') ? utf8_normalize_nfc($this->request->variable('config', array('' => ''), true)) : $this->new_config; if ($submit && !check_form_key($form_key)) { $error[] = $this->user->lang['FORM_INVALID']; } // We validate the complete config if whished validate_config_vars($display_vars['vars'], $cfg_array, $error); // Do not write values if there is an error if (!empty($error)) { $submit = false; } $additional_notes = ''; // We go through the display_vars to make sure no one is trying to set variables he/she is not allowed to... foreach ($display_vars['vars'] as $config_name => $cfg_setup) { if (!isset($cfg_array[$config_name]) && @$cfg_setup['method'] != 'select_multiple' || strpos($config_name, 'legend') !== false) { continue; } // Handle multiple select options if (!empty($cfg_setup['method']) && $cfg_setup['method'] == 'select_multiple') { if (isset($_POST['multiple_' . $config_name])) { $m_values = utf8_normalize_nfc($this->request->variable('multiple_' . $config_name, array('' => ''))); $validate_int = !empty($cfg_setup['multiple_validate']) && $cfg_setup['multiple_validate'] == 'int' ? true : false; foreach ($m_values as $k => $v) { if ($validate_int) { $v = max(0, (int) $v); } if (empty($v)) { unset($m_values[$k]); } else { $m_values[$k] = $v; } } sort($m_values); $this->new_config[$config_name] = $m_values; $config_value = implode(',', $m_values); if (strlen($config_value) > 255) { $error[] = sprintf($this->user->lang['SETTING_TOO_LONG'], $this->user->lang[$cfg_setup['lang']], 255); } $submit = empty($error); } else { if ($submit) { $this->new_config[$config_name] = array(); $config_value = ''; } else { $config_value = $this->new_config[$config_name]; $this->new_config[$config_name] = !empty($config_value) ? explode(',', $config_value) : array(); } } } else { $this->new_config[$config_name] = $config_value = $cfg_array[$config_name]; } if ($submit) { // In case we deal with forum URLs if ($mode == 'forum_url' && preg_match('`^forum_url([0-9]+)$`', $config_name, $matches)) { // Check if this is an actual forum_id if (isset($this->forum_ids[$matches[1]])) { $forum_id = intval($matches[1]); $config_value = $this->core->format_url($config_value, $this->core->seo_static['forum']); // Remove delim if required while (preg_match('`^[a-z0-9_-]+' . $this->core->seo_delim['forum'] . '[0-9]+$`i', $config_value)) { $config_value = preg_replace('`^([a-z0-9_-]+)' . $this->core->seo_delim['forum'] . '[0-9]+$`i', '\\1', $config_value); if (@$this->core->cache_config['settings']['rem_ids']) { $seo_msg['SEO_ADVICE_DELIM_REM'] = '<li> ' . $this->user->lang['SEO_ADVICE_DELIM_REM'] . '</li>'; } } // Forums cannot end with the pagination param while (preg_match('`^[a-z0-9_-]+' . $this->core->seo_delim['start'] . '[0-9]+$`i', $config_value)) { $config_value = preg_replace('`^([a-z0-9_-]+)' . $this->core->seo_delim['start'] . '[0-9]+$`i', "\\1", $config_value); $seo_msg['SEO_ADVICE_START'] = '<li> ' . $this->user->lang['SEO_ADVICE_START'] . '</li>'; } // Only update if the value is not a static one for forums if (!in_array($config_value, $forbidden)) { // and updated (sic) if ($config_value != @$this->core->cache_config['forum_urls'][$forum_id]) { // and if not already set if (!array_search($config_value, $this->core->cache_config['forum_urls'])) { $this->core->cache_config['forum_urls'][$forum_id] = $config_value . (@$this->core->cache_config['settings']['rem_ids'] ? '' : $this->core->seo_delim['forum'] . $forum_id); } else { $seo_msg['SEO_ADVICE_DUPE_' . $forum_id] = '<li> ' . sprintf($this->user->lang['SEO_ADVICE_DUPE'], $config_value) . '</li>'; } } } else { $seo_msg['SEO_ADVICE_RESERVED_' . $forum_id] = '<li> ' . sprintf($this->user->lang['SEO_ADVICE_RESERVED'], $config_value) . '</li>'; } } } else { if ($mode == 'settings') { if (isset($this->array_type_cfg[$config_name]) && isset($this->core->seo_opt[$this->array_type_cfg[$config_name]['main']][$this->array_type_cfg[$config_name]['sub']])) { if (is_bool($this->core->seo_opt[$this->array_type_cfg[$config_name]['main']][$this->array_type_cfg[$config_name]['sub']])) { $this->core->cache_config['settings'][$this->array_type_cfg[$config_name]['main']][$this->array_type_cfg[$config_name]['sub']] = $config_value == 1 ? true : false; } else { if (is_numeric($this->core->seo_opt[$this->array_type_cfg[$config_name]['main']][$this->array_type_cfg[$config_name]['sub']])) { $this->core->cache_config['settings'][$this->array_type_cfg[$config_name]['main']][$this->array_type_cfg[$config_name]['sub']] = intval($config_value); } else { if (is_string($this->core->seo_opt[$this->array_type_cfg[$config_name]['main']][$this->array_type_cfg[$config_name]['sub']])) { $this->core->cache_config['settings'][$this->array_type_cfg[$config_name]['main']][$this->array_type_cfg[$config_name]['sub']] = $config_value; } } } } else { if (isset($this->core->seo_opt[$config_name])) { if (is_bool($this->core->seo_opt[$config_name])) { $this->core->cache_config['settings'][$config_name] = $config_value == 1 ? true : false; } else { if (is_numeric($this->core->seo_opt[$config_name])) { $this->core->cache_config['settings'][$config_name] = intval($config_value); } else { if (is_string($this->core->seo_opt[$config_name])) { $this->core->cache_config['settings'][$config_name] = $config_value; } } } } } // Let's make sure that the proper field was added to the topic table if ($config_name === 'sql_rewrite' && $config_value == 1 && !$this->core->seo_opt['sql_rewrite']) { $db_tools = new \phpbb\db\tools($this->db); $db_tools->db->sql_return_on_error(true); if (!$db_tools->sql_column_exists(TOPICS_TABLE, 'topic_url')) { $db_tools->sql_column_add(TOPICS_TABLE, 'topic_url', array('VCHAR:255', '')); } $additional_notes = sprintf($this->user->lang['SYNC_TOPIC_URL_NOTE'], '<a href="' . append_sid("{$phpbb_admin_path}index.{$phpEx}", 'i=-phpbbseo-usu-acp-usu&mode=sync_url') . '">', '</a>'); if ($db_tools->db->get_sql_error_triggered()) { $error[] = '<b>' . $this->user->lang['sql_rewrite'] . '</b> : ' . $this->user->lang['SEO_SQL_ERROR'] . ' [ ' . $db_tools->db->get_sql_layer() . ' ] : ' . $db_tools->db->sql_error_returned['message'] . ' [' . $db_tools->db->sql_error_returned['code'] . ']' . '<br/>' . $this->user->lang['SEO_SQL_TRY_MANUALLY'] . '<br/>' . $db_tools->db->sql_error_sql; $submit = false; } $db_tools->db->sql_return_on_error(false); } } else { if ($mode == 'extended') { set_config($config_name, $config_value); } } } } } if (sizeof($error)) { $submit = false; } if ($submit) { if ($mode == 'server') { if ($this->new_config['save']) { $this->seo_server_conf(false); add_log('admin', 'SEO_LOG_CONFIG_' . strtoupper($mode)); } } else { if ($mode == 'extended') { add_log('admin', 'SEO_LOG_CONFIG_' . strtoupper($mode)); trigger_error($this->user->lang['CONFIG_UPDATED'] . adm_back_link($this->u_action)); } else { // config $file = $this->core->cache_config['file']; ksort($this->core->cache_config['forum_urls']); $update = '<' . '?php' . "\n" . '/**' . "\n" . '* phpBB SEO' . "\n" . '* www.phpBB-SEO.com' . "\n" . '* @package phpBB SEO USU' . "\n" . '*/' . "\n" . 'if (!defined(\'IN_PHPBB\')) {' . "\n\t" . 'exit;' . "\n" . '}' . "\n"; $update .= '$settings = ' . preg_replace('`[\\s]+`', ' ', var_export($this->core->cache_config['settings'], true)) . ';' . "\n"; $update .= '$forum_urls = ' . preg_replace('`[\\s]+`', ' ', var_export($this->core->cache_config['forum_urls'], true)) . ';'; if ($this->write_cache($file, $update)) { global $msg_long_text; add_log('admin', 'SEO_LOG_CONFIG_' . strtoupper($mode)); $msg = !empty($seo_msg) ? '<br /><h1 style="color:red;text-align:left;">' . $this->user->lang['SEO_VALIDATE_INFO'] . '</h1><ul style="text-align:left;">' . implode(' ', $seo_msg) . '</ul><br />' : ''; $msg_long_text = $this->user->lang['SEO_CACHE_MSG_OK'] . $msg . adm_back_link($this->u_action); if ($additional_notes) { $msg_long_text .= "<br/><br/>{$additional_notes}"; } trigger_error(false); } else { trigger_error($this->user->lang['SEO_CACHE_MSG_FAIL'] . adm_back_link($this->u_action)); } } } } $this->tpl_name = 'acp_board'; $this->page_title = $display_vars['title']; $l_title_explain = $this->user->lang[$display_vars['title'] . '_EXPLAIN']; if ($mode != 'extended') { $l_title_explain .= $mode == 'server' ? '' : $this->check_cache_folder($this->core->seo_opt['cache_folder']); } $this->template->assign_vars(array('L_TITLE' => $this->user->lang[$display_vars['title']], 'L_TITLE_EXPLAIN' => $l_title_explain, 'S_ERROR' => sizeof($error) ? true : false, 'ERROR_MSG' => implode('<br />', $error), 'U_ACTION' => $this->u_action)); // Output relevant page foreach ($display_vars['vars'] as $config_key => $vars) { if (!is_array($vars) && strpos($config_key, 'legend') === false) { continue; } if (strpos($config_key, 'legend') !== false) { $this->template->assign_block_vars('options', array('S_LEGEND' => true, 'LEGEND' => isset($this->user->lang[$vars]) ? $this->user->lang[$vars] : $vars)); continue; } $type = explode(':', $vars['type']); $l_explain = ''; if ($vars['explain'] && isset($vars['lang_explain'])) { $l_explain = isset($this->user->lang[$vars['lang_explain']]) ? $this->user->lang[$vars['lang_explain']] : $vars['lang_explain']; } else { if ($vars['explain'] && isset($vars['lang_explain_custom'])) { $l_explain = $vars['lang_explain_custom']; } else { if ($vars['explain']) { $l_explain = isset($this->user->lang[$vars['lang'] . '_EXPLAIN']) ? $this->user->lang[$vars['lang'] . '_EXPLAIN'] : ''; } } } $this->template->assign_block_vars('options', array('KEY' => $config_key, 'TITLE' => isset($this->user->lang[$vars['lang']]) ? $this->user->lang[$vars['lang']] : $vars['lang'], 'S_EXPLAIN' => $vars['explain'], 'TITLE_EXPLAIN' => $l_explain, 'CONTENT' => build_cfg_template($type, $config_key, $this->new_config, $config_key, $vars))); unset($display_vars['vars'][$config_key]); } }
/** * Perform all poll related modifications * * @param array $topic_data The array of topic data * @param array $vote_counts Array with the vote counts for every poll option, updated here * @param array $cur_voted_id Array of current votes, stored in the database, updated here * @param array $voted_id Array of votes, submitted in the form, updated here * @param array $poll_info Array with poll options and details, updated here * @param bool $s_can_vote May the user vote in this poll? May be modified here * @param string $viewtopic_url URL with the return topic * @return void */ public function do_poll_voting_modifications($topic_data, &$vote_counts, &$cur_voted_id, &$voted_id, &$poll_info, &$s_can_vote, $viewtopic_url) { $options = $this->get_possible_options(true); $options = array_keys($options); $poll_options = array_keys($vote_counts); $poll_options_count = count($poll_options); // Get votes data $sql = 'SELECT * FROM ' . POLL_VOTES_TABLE . ' WHERE poll_option_id > 0 AND topic_id = ' . $topic_data['topic_id']; $result = $this->db->sql_query($sql); $option_voters = array_fill_keys($poll_options, array()); $cur_voted_val = array(); $cur_total_val = 0; while ($row = $this->db->sql_fetchrow($result)) { $option_voters[$row['poll_option_id']][(int) $row['vote_user_id']] = (int) $row['wolfsblvt_poll_option_value']; if ($this->user->data['is_registered'] && $this->user->data['user_id'] == $row['vote_user_id']) { $cur_voted_val[(int) $row['poll_option_id']] = (int) $row['wolfsblvt_poll_option_value']; $cur_total_val += (int) $row['wolfsblvt_poll_option_value']; } } $this->db->sql_freeresult($result); for ($i = 0; $i < $poll_options_count; $i++) { $poll_info[$i]['option_voters'] = $option_voters[$poll_info[$i]['poll_option_id']]; } if (!$this->user->data['is_registered']) { // Cookie based guest tracking ... I don't like this but hum ho // it's oft requested. This relies on "nice" users who don't feel // the need to delete cookies to mess with results. if ($this->request->is_set($this->config['cookie_name'] . '_poll_votes_' . $topic_data['topic_id'], \phpbb\request\request_interface::COOKIE)) { $cur_voted_votes = explode(',', $this->request->variable($this->config['cookie_name'] . '_poll_votes_' . $topic_data['topic_id'], '', true, \phpbb\request\request_interface::COOKIE)); $cur_voted_votes = array_map('intval', $cur_voted_votes); $cur_voted_val = array_combine($cur_voted_id, $cur_voted_votes); $cur_total_val = array_sum($cur_voted_votes); } } $voted_val = array(); $scoring = $this->request->variable('scoring', false); $update = $this->request->variable('update', false); if ($scoring) { $voted_val = $this->request->variable('vote_id', array(0 => 0)); $voted_val = array_diff($voted_val, array(0)); $voted_id = array_keys($voted_val); $voted_id = sizeof($voted_id) > 1 ? array_unique($voted_id) : $voted_id; } if (!in_array('wolfsblvt_no_vote', $options) && in_array(0, $cur_voted_id)) { $sql = 'DELETE FROM ' . POLL_VOTES_TABLE . ' WHERE topic_id = ' . (int) $topic_data['topic_id'] . ' AND poll_option_id = ' . 0 . ' AND vote_user_id = ' . (int) $this->user->data['user_id']; $this->db->sql_query($sql); $cur_voted_id = array_keys($cur_voted_val); } $s_incremental = in_array('wolfsblvt_incremental_votes', $options); $s_is_scoring = in_array('wolfsblvt_poll_max_value', $options) && $topic_data['wolfsblvt_poll_max_value'] > 1 ? true : false; $s_vote_incomplete = $s_incremental ? $s_is_scoring ? $cur_total_val < $topic_data['wolfsblvt_poll_total_value'] : sizeof($cur_voted_id) < $topic_data['poll_max_options'] : !sizeof($cur_voted_id); $s_can_change_vote = $this->auth->acl_get('f_votechg', $topic_data['forum_id']) && $topic_data['poll_vote_change'] ? true : false; $s_can_vote = $s_can_vote || $this->auth->acl_get('f_vote', $topic_data['forum_id']) && ($topic_data['poll_length'] != 0 && $topic_data['poll_start'] + $topic_data['poll_length'] > time() || $topic_data['poll_length'] == 0) && ($topic_data['topic_status'] != ITEM_LOCKED || in_array('wolfsblvt_closed_voting', $options)) && $topic_data['forum_status'] != ITEM_LOCKED && ($s_vote_incomplete || $s_can_change_vote) ? true : false; if ($update && $s_can_vote) { if (!sizeof($voted_id) || sizeof($voted_id) > $topic_data['poll_max_options'] || $scoring !== $s_is_scoring || !$s_can_change_vote && sizeof(array_diff($cur_voted_id, $voted_id)) || !check_form_key('posting')) { meta_refresh(5, $viewtopic_url); if (!sizeof($voted_id)) { $message = 'NO_VOTE_OPTION'; } else { if (sizeof($voted_id) > $topic_data['poll_max_options']) { $message = 'TOO_MANY_VOTE_OPTIONS'; } else { if ($scoring !== $s_is_scoring) { $message = 'AP_POLL_TYPE_MISMATCH'; } else { if (!$s_can_change_vote && sizeof(array_diff($cur_voted_id, $voted_id))) { $message = 'AP_VOTE_CHANGED'; } else { $message = 'FORM_INVALID'; } } } } $message = $this->user->lang[$message] . '<br /><br />' . sprintf($this->user->lang['RETURN_TOPIC'], '<a href="' . $viewtopic_url . '">', '</a>'); trigger_error($message); } if ($this->user->data['is_registered'] && in_array(0, $cur_voted_id)) { $sql = 'DELETE FROM ' . POLL_VOTES_TABLE . ' WHERE topic_id = ' . (int) $topic_data['topic_id'] . ' AND poll_option_id = ' . 0 . ' AND vote_user_id = ' . (int) $this->user->data['user_id']; $this->db->sql_query($sql); $cur_voted_id = array_keys($cur_voted_val); } } if ($update && $s_can_vote && $s_is_scoring) { $voted_total_val = 0; $vote_changed = false; foreach ($voted_id as $option) { $voted_total_val += $voted_val[$option]; if (isset($cur_voted_val[$option]) && $cur_voted_val[$option] > $voted_val[$option]) { $vote_changed = true; } } if ($voted_total_val > $topic_data['wolfsblvt_poll_total_value'] || !$s_can_change_vote && $vote_changed) { meta_refresh(5, $viewtopic_url); $message = ''; if (!$s_can_change_vote && $vote_changed) { $message = 'AP_VOTE_CHANGED'; } else { if ($voted_total_val > $topic_data['wolfsblvt_poll_total_value']) { $message = 'AP_TOO_MANY_VOTES'; } } $message = $this->user->lang[$message] . '<br /><br />' . sprintf($this->user->lang['RETURN_TOPIC'], '<a href="' . $viewtopic_url . '">', '</a>'); trigger_error($message); } foreach ($cur_voted_id as $option) { if (!in_array($option, $voted_id) || $cur_voted_val[$option] != $voted_val[$option]) { $sql = 'UPDATE ' . POLL_OPTIONS_TABLE . ' SET poll_option_total = poll_option_total - ' . (int) $cur_voted_val[$option] . ' WHERE poll_option_id = ' . (int) $option . ' AND topic_id = ' . (int) $topic_data['topic_id']; $this->db->sql_query($sql); $vote_counts[$option] -= (int) $cur_voted_val[$option]; if ($this->user->data['is_registered']) { $sql = 'DELETE FROM ' . POLL_VOTES_TABLE . ' WHERE topic_id = ' . (int) $topic_data['topic_id'] . ' AND poll_option_id = ' . (int) $option . ' AND vote_user_id = ' . (int) $this->user->data['user_id']; $this->db->sql_query($sql); } } } foreach ($voted_id as $option) { if (in_array($option, $cur_voted_id) && $cur_voted_val[$option] == $voted_val[$option]) { continue; } $sql = 'UPDATE ' . POLL_OPTIONS_TABLE . ' SET poll_option_total = poll_option_total + ' . (int) $voted_val[$option] . ' WHERE poll_option_id = ' . (int) $option . ' AND topic_id = ' . (int) $topic_data['topic_id']; $this->db->sql_query($sql); $vote_counts[$option] += (int) $voted_val[$option]; if ($this->user->data['is_registered']) { $sql_ary = array('topic_id' => (int) $topic_data['topic_id'], 'poll_option_id' => (int) $option, 'wolfsblvt_poll_option_value' => (int) $voted_val[$option], 'vote_user_id' => (int) $this->user->data['user_id'], 'vote_user_ip' => (string) $this->user->ip); $sql = 'INSERT INTO ' . POLL_VOTES_TABLE . ' ' . $this->db->sql_build_array('INSERT', $sql_ary); $this->db->sql_query($sql); } } if ($this->user->data['user_id'] == ANONYMOUS && !$this->user->data['is_bot']) { $this->user->set_cookie('poll_' . $topic_data['topic_id'], implode(',', array_keys($voted_val)), time() + 31536000); $this->user->set_cookie('poll_votes_' . $topic_data['topic_id'], implode(',', array_values($voted_val)), time() + 31536000); } $sql = 'UPDATE ' . TOPICS_TABLE . ' SET poll_last_vote = ' . time() . ' WHERE topic_id = ' . $topic_data['topic_id']; $this->db->sql_query($sql); $message = $this->user->lang['VOTE_SUBMITTED'] . '<br /><br />' . sprintf($this->user->lang['RETURN_TOPIC'], '<a href="' . $viewtopic_url . '">', '</a>'); if ($this->request->is_ajax()) { // Filter out invalid options $valid_user_votes = array_intersect(array_keys($vote_counts), $voted_id); $s_vote_incomplete = $s_incremental ? $s_is_scoring ? $voted_total_val < $topic_data['wolfsblvt_poll_total_value'] : sizeof($valid_user_votes) < $topic_data['poll_max_options'] : !sizeof($valid_user_votes); $data = array('NO_VOTES' => $this->user->lang['NO_VOTES'], 'success' => true, 'scoring' => true, 'user_votes' => array_flip($valid_user_votes), 'user_vote_counts' => $voted_val, 'vote_counts' => $vote_counts, 'total_votes' => array_sum($vote_counts), 'can_vote' => $s_vote_incomplete || $s_can_change_vote); $json_response = new \phpbb\json_response(); $json_response->send($data); } meta_refresh(5, $viewtopic_url); trigger_error($message); } // If we have ajax call here with no_vote, we exit save it here and return json_response if (in_array('wolfsblvt_no_vote', $options) && $this->request->is_ajax() && $this->request->is_set('no_vote')) { if ($this->user->data['is_registered']) { $sql_ary = array('topic_id' => (int) $topic_data['topic_id'], 'poll_option_id' => (int) 0, 'wolfsblvt_poll_option_value' => (int) 0, 'vote_user_id' => (int) $this->user->data['user_id'], 'vote_user_ip' => (string) $this->user->ip); $sql = 'INSERT INTO ' . POLL_VOTES_TABLE . ' ' . $this->db->sql_build_array('INSERT', $sql_ary); $this->db->sql_query($sql); $json_response = new \phpbb\json_response(); $json_response->send(array('success' => true)); } } $this->cur_voted_val = $cur_voted_val; return; }
/** * Parse template variables for module * * @param int $module_id Module ID * @param string $type Module type (center or side) * * @return string HTML filename */ protected function parse_template($module_id, $type = '') { $this->user->add_lang('viewtopic'); // check if we need to include the bbcode class if (!class_exists('bbcode')) { include $this->phpbb_root_path . 'includes/bbcode.' . $this->php_ext; } $view = $this->request->variable('view', ''); $update = $this->request->variable('update', false); $poll_view = $this->request->variable('polls', ''); $poll_view_ar = strpos($poll_view, ',') !== false ? explode(',', $poll_view) : ($poll_view != '' ? array($poll_view) : array()); if ($update && $this->config['board3_poll_allow_vote_' . $module_id]) { $up_topic_id = $this->request->variable('t', 0); $up_forum_id = $this->request->variable('f', 0); $voted_id = $this->request->variable('vote_id', array('' => 0)); $cur_voted_id = array(); if ($this->user->data['is_registered']) { $sql = 'SELECT poll_option_id FROM ' . POLL_VOTES_TABLE . ' WHERE topic_id = ' . (int) $up_topic_id . ' AND vote_user_id = ' . (int) $this->user->data['user_id']; $result = $this->db->sql_query($sql); while ($row = $this->db->sql_fetchrow($result)) { $cur_voted_id[] = $row['poll_option_id']; } $this->db->sql_freeresult($result); } else { // Cookie based guest tracking ... I don't like this but hum ho // it's oft requested. This relies on "nice" users who don't feel // the need to delete cookies to mess with results. if ($this->request->is_set($this->config['cookie_name'] . '_poll_' . $up_topic_id, \phpbb\request\request_interface::COOKIE)) { $cur_voted_id = explode(',', $this->request->variable($this->config['cookie_name'] . '_poll_' . $up_topic_id, '', true, \phpbb\request\request_interface::COOKIE)); $cur_voted_id = array_map('intval', $cur_voted_id); } } $sql = 'SELECT t.poll_length, t.poll_start, t.poll_vote_change, t.topic_status, f.forum_status, t.poll_max_options FROM ' . TOPICS_TABLE . ' t, ' . FORUMS_TABLE . " f\n\t\t\t\tWHERE t.forum_id = f.forum_id\n\t\t\t\t\tAND t.topic_id = " . (int) $up_topic_id . "\n\t\t\t\t\tAND t.forum_id = " . (int) $up_forum_id; $result = $this->db->sql_query_limit($sql, 1); $topic_data = $this->db->sql_fetchrow($result); $this->db->sql_freeresult($result); $s_can_up_vote = (!sizeof($cur_voted_id) && $this->auth->acl_get('f_vote', $up_forum_id) || $this->auth->acl_get('f_votechg', $up_forum_id) && $topic_data['poll_vote_change']) && ($topic_data['poll_length'] != 0 && $topic_data['poll_start'] + $topic_data['poll_length'] > time() || $topic_data['poll_length'] == 0) && $topic_data['topic_status'] != ITEM_LOCKED && $topic_data['forum_status'] != ITEM_LOCKED ? true : false; if ($s_can_up_vote) { $redirect_url = $this->modules_helper->route('board3_portal_controller'); if (!sizeof($voted_id) || sizeof($voted_id) > $topic_data['poll_max_options'] || in_array(VOTE_CONVERTED, $cur_voted_id)) { meta_refresh(5, $redirect_url); if (!sizeof($voted_id)) { $message = 'NO_VOTE_OPTION'; } else { if (sizeof($voted_id) > $topic_data['poll_max_options']) { $message = 'TOO_MANY_VOTE_OPTIONS'; } else { $message = 'VOTE_CONVERTED'; } } $message = $this->user->lang[$message] . '<br /><br />' . sprintf($this->user->lang['RETURN_PORTAL'], '<a href="' . $redirect_url . '">', '</a>'); trigger_error($message); } foreach ($voted_id as $option) { if (in_array($option, $cur_voted_id)) { continue; } $sql = 'UPDATE ' . POLL_OPTIONS_TABLE . ' SET poll_option_total = poll_option_total + 1 WHERE poll_option_id = ' . (int) $option . ' AND topic_id = ' . (int) $up_topic_id; $this->db->sql_query($sql); if ($this->user->data['is_registered']) { $sql_ary = array('topic_id' => (int) $up_topic_id, 'poll_option_id' => (int) $option, 'vote_user_id' => (int) $this->user->data['user_id'], 'vote_user_ip' => (string) $this->user->ip); $sql = 'INSERT INTO ' . POLL_VOTES_TABLE . ' ' . $this->db->sql_build_array('INSERT', $sql_ary); $this->db->sql_query($sql); } } foreach ($cur_voted_id as $option) { if (!in_array($option, $voted_id)) { $sql = 'UPDATE ' . POLL_OPTIONS_TABLE . ' SET poll_option_total = poll_option_total - 1 WHERE poll_option_id = ' . (int) $option . ' AND topic_id = ' . (int) $up_topic_id; $this->db->sql_query($sql); if ($this->user->data['is_registered']) { $sql = 'DELETE FROM ' . POLL_VOTES_TABLE . ' WHERE topic_id = ' . (int) $up_topic_id . ' AND poll_option_id = ' . (int) $option . ' AND vote_user_id = ' . (int) $this->user->data['user_id']; $this->db->sql_query($sql); } } } if ($this->user->data['user_id'] == ANONYMOUS && !$this->user->data['is_bot']) { $this->user->set_cookie('poll_' . $up_topic_id, implode(',', $voted_id), time() + 31536000); } $sql = 'UPDATE ' . TOPICS_TABLE . ' SET poll_last_vote = ' . time() . ' WHERE topic_id = ' . (int) $up_topic_id; //, topic_last_post_time = ' . time() . " -- for bumping topics with new votes, ignore for now $this->db->sql_query($sql); meta_refresh(5, $redirect_url); trigger_error($this->user->lang['VOTE_SUBMITTED'] . '<br /><br />' . sprintf($this->user->lang['RETURN_PORTAL'], '<a href="' . $redirect_url . '">', '</a>')); } } $poll_forums = false; // Get readable forums $forum_list = array_unique(array_keys($this->auth->acl_getf('f_read', true))); if ($this->config['board3_poll_topic_id_' . $module_id] !== '') { $poll_forums_config = explode(',', $this->config['board3_poll_topic_id_' . $module_id]); if ($this->config['board3_poll_exclude_id_' . $module_id]) { $forum_list = array_unique(array_diff($forum_list, $poll_forums_config)); } else { $forum_list = array_unique(array_intersect($poll_forums_config, $forum_list)); } } $where = ''; if (sizeof($forum_list)) { $poll_forums = true; $where = 'AND ' . $this->db->sql_in_set('t.forum_id', $forum_list); } if ($this->config['board3_poll_hide_' . $module_id]) { $portal_poll_hide = 'AND (t.poll_start + t.poll_length > ' . time() . ' OR t.poll_length = 0)'; } else { $portal_poll_hide = ''; } if ($poll_forums === true) { $sql = 'SELECT t.poll_title, t.poll_start, t.topic_id, t.topic_first_post_id, t.forum_id, t.poll_length, t.poll_vote_change, t.poll_max_options, t.topic_status, f.forum_status, p.bbcode_bitfield, p.bbcode_uid FROM ' . TOPICS_TABLE . ' t, ' . POSTS_TABLE . ' p, ' . FORUMS_TABLE . " f\n\t\t\t\tWHERE t.forum_id = f.forum_id\n\t\t\t\t\tAND t.topic_visibility = 1\n\t\t\t\t\tAND t.poll_start > 0\n\t\t\t\t\t{$where}\n\t\t\t\t\tAND t.topic_moved_id = 0\n\t\t\t\t\tAND p.post_id = t.topic_first_post_id\n\t\t\t\t\t{$portal_poll_hide}\n\t\t\t\tORDER BY t.poll_start DESC"; $limit = isset($this->config['board3_poll_limit_' . $module_id]) ? $this->config['board3_poll_limit_' . $module_id] : 3; $result = $this->db->sql_query_limit($sql, $limit); $has_poll = false; if ($result) { while ($data = $this->db->sql_fetchrow($result)) { $has_poll = true; $poll_has_options = false; $topic_id = (int) $data['topic_id']; $forum_id = (int) $data['forum_id']; $cur_voted_id = array(); if ($this->config['board3_poll_allow_vote_' . $module_id]) { if ($this->user->data['is_registered']) { $vote_sql = 'SELECT poll_option_id FROM ' . POLL_VOTES_TABLE . ' WHERE topic_id = ' . (int) $topic_id . ' AND vote_user_id = ' . (int) $this->user->data['user_id']; $vote_result = $this->db->sql_query($vote_sql); while ($row = $this->db->sql_fetchrow($vote_result)) { $cur_voted_id[] = $row['poll_option_id']; } $this->db->sql_freeresult($vote_result); } else { // Cookie based guest tracking ... I don't like this but hum ho // it's oft requested. This relies on "nice" users who don't feel // the need to delete cookies to mess with results. if ($this->request->is_set($this->config['cookie_name'] . '_poll_' . $topic_id, \phpbb\request\request_interface::COOKIE)) { $cur_voted_id = explode(',', $this->request->variable($this->config['cookie_name'] . '_poll_' . $topic_id, 0, false, true)); $cur_voted_id = array_map('intval', $cur_voted_id); } } $s_can_vote = (!sizeof($cur_voted_id) && $this->auth->acl_get('f_vote', $forum_id) || $this->auth->acl_get('f_votechg', $forum_id) && $data['poll_vote_change']) && ($data['poll_length'] != 0 && $data['poll_start'] + $data['poll_length'] > time() || $data['poll_length'] == 0) && $data['topic_status'] != ITEM_LOCKED && $data['forum_status'] != ITEM_LOCKED ? true : false; } else { $s_can_vote = false; } $s_display_results = !$s_can_vote || $s_can_vote && sizeof($cur_voted_id) || $view == 'viewpoll' && in_array($topic_id, $poll_view_ar) ? true : false; $poll_sql = 'SELECT po.poll_option_id, po.poll_option_text, po.poll_option_total FROM ' . POLL_OPTIONS_TABLE . ' po WHERE po.topic_id = ' . (int) $topic_id . ' ORDER BY po.poll_option_id'; $poll_result = $this->db->sql_query($poll_sql); $poll_total_votes = 0; $poll_data = array(); if ($poll_result) { while ($polls_data = $this->db->sql_fetchrow($poll_result)) { $poll_has_options = true; $poll_data[] = $polls_data; $poll_total_votes += $polls_data['poll_option_total']; } } $this->db->sql_freeresult($poll_result); $make_poll_view = array(); if (in_array($topic_id, $poll_view_ar) === false) { $make_poll_view[] = $topic_id; $make_poll_view = array_merge($poll_view_ar, $make_poll_view); } $poll_view_str = urlencode(implode(',', $make_poll_view)); $portalpoll_url = $this->modules_helper->route('board3_portal_controller') . "?polls={$poll_view_str}"; $portalvote_url = $this->modules_helper->route('board3_portal_controller') . "?f={$forum_id}&t={$topic_id}"; $viewtopic_url = append_sid("{$this->phpbb_root_path}viewtopic.{$this->php_ext}", "f={$forum_id}&t={$topic_id}"); $poll_end = $data['poll_length'] + $data['poll_start']; // Parse BBCode title if ($data['bbcode_bitfield']) { $poll_bbcode = new \bbcode(); } else { $poll_bbcode = false; } $data['poll_title'] = censor_text($data['poll_title']); if ($poll_bbcode !== false) { $poll_bbcode->bbcode_second_pass($data['poll_title'], $data['bbcode_uid'], $data['bbcode_bitfield']); } $data['poll_title'] = bbcode_nl2br($data['poll_title']); $data['poll_title'] = smiley_text($data['poll_title']); unset($poll_bbcode); $this->template->assign_block_vars($type !== '' ? 'poll_' . $type : 'poll', array('S_POLL_HAS_OPTIONS' => $poll_has_options, 'POLL_QUESTION' => $data['poll_title'], 'U_POLL_TOPIC' => append_sid($this->phpbb_root_path . 'viewtopic.' . $this->php_ext, 't=' . $topic_id . '&f=' . $forum_id), 'POLL_LENGTH' => $data['poll_length'], 'TOPIC_ID' => $topic_id, 'TOTAL_VOTES' => $poll_total_votes, 'L_MAX_VOTES' => $this->user->lang('MAX_OPTIONS_SELECT', $data['poll_max_options']), 'L_POLL_LENGTH' => $data['poll_length'] ? sprintf($this->user->lang[$poll_end > time() ? 'POLL_RUN_TILL' : 'POLL_ENDED_AT'], $this->user->format_date($poll_end)) : '', 'S_CAN_VOTE' => $s_can_vote, 'S_DISPLAY_RESULTS' => $s_display_results, 'S_IS_MULTI_CHOICE' => $data['poll_max_options'] > 1 ? true : false, 'S_POLL_ACTION' => $portalvote_url, 'U_VIEW_RESULTS' => $portalpoll_url . '&view=viewpoll#viewpoll', 'U_VIEW_TOPIC' => $viewtopic_url)); foreach ($poll_data as $pd) { $option_pct = $poll_total_votes > 0 ? $pd['poll_option_total'] / $poll_total_votes : 0; $option_pct_txt = sprintf("%.1d%%", round($option_pct * 100)); // Parse BBCode option text if ($data['bbcode_bitfield']) { $poll_bbcode = new \bbcode(); } else { $poll_bbcode = false; } $pd['poll_option_text'] = censor_text($pd['poll_option_text']); if ($poll_bbcode !== false) { $poll_bbcode->bbcode_second_pass($pd['poll_option_text'], $data['bbcode_uid'], $data['bbcode_bitfield']); } $pd['poll_option_text'] = bbcode_nl2br($pd['poll_option_text']); $pd['poll_option_text'] = smiley_text($pd['poll_option_text']); unset($poll_bbcode); $this->template->assign_block_vars(($type !== '' ? 'poll_' . $type : 'poll') . '.poll_option', array('POLL_OPTION_ID' => $pd['poll_option_id'], 'POLL_OPTION_CAPTION' => $pd['poll_option_text'], 'POLL_OPTION_RESULT' => $pd['poll_option_total'], 'POLL_OPTION_PERCENT' => $option_pct_txt, 'POLL_OPTION_PCT' => round($option_pct * 100), 'POLL_OPTION_IMG' => $this->user->img('poll_center', $option_pct_txt, round($option_pct * 35) . 'px'), 'POLL_OPTION_VOTED' => in_array($pd['poll_option_id'], $cur_voted_id) ? true : false)); } } } $this->db->sql_freeresult($result); $this->template->assign_vars(array('S_HAS_POLL' => $has_poll, 'POLL_LEFT_CAP_IMG' => $this->user->img('poll_left'), 'POLL_RIGHT_CAP_IMG' => $this->user->img('poll_right'))); } return ($type !== '' ? 'poll_' . $type : 'poll_center') . '.html'; }
/** * {@inheritdoc} */ public function get_template_center($module_id) { $news = $this->request->variable('news_' . $module_id, -1); $news = $news > $this->config['board3_number_of_news_' . $module_id] - 1 ? -1 : $news; $this->user->add_lang('viewforum'); $start = $this->request->variable('np_' . $module_id, 0); $start = $start < 0 ? 0 : $start; $total_news = 1; // Fetch news from portal functions.php with check if "read full" is requested. $portal_news_length = $news < 0 && !$this->config['board3_news_style_' . $module_id] ? $this->config['board3_news_length_' . $module_id] : 0; $this->fetch_posts->set_module_id($module_id); $fetch_news = $this->fetch_posts->get_posts($this->config['board3_news_forum_' . $module_id], $this->config['board3_news_permissions_' . $module_id], $this->config['board3_number_of_news_' . $module_id], $portal_news_length, 0, $this->config['board3_show_all_news_' . $module_id] ? 'news_all' : 'news', $start, (bool) $this->config['board3_news_exclude_' . $module_id]); $topic_icons = false; if (!empty($fetch_news['topic_icons'])) { $topic_icons = true; } // Standard news row $news_row = array('S_NEWEST_OR_FIRST' => $this->config['board3_news_show_last_' . $module_id] ? $this->user->lang['JUMP_NEWEST'] : $this->user->lang['JUMP_FIRST'], 'POSTED_BY_TEXT' => $this->config['board3_news_show_last_' . $module_id] ? $this->user->lang['LAST_POST'] : $this->user->lang['POSTED'], 'S_DISPLAY_NEWS_RVS' => $this->config['board3_show_news_replies_views_' . $module_id] ? true : false, 'S_TOPIC_ICONS' => $topic_icons, 'MODULE_ID' => $module_id); // Any news present? If not terminate it here. if (sizeof($fetch_news) == 0) { // Create standard news row $this->template->assign_block_vars('news', $news_row); $this->template->assign_block_vars('news.news_row', array('S_NO_TOPICS' => true, 'S_NOT_LAST' => false)); } else { // Count number of posts for news archive, considering if permission check is dis- or enabled. if ($this->config['board3_news_archive_' . $module_id]) { $permissions = $this->config['board3_news_permissions_' . $module_id]; $forum_from = $this->config['board3_news_forum_' . $module_id]; $forum_from = strpos($forum_from, ',') !== false ? explode(',', $forum_from) : ($forum_from != '' ? array($forum_from) : array()); $str_where = ''; // Get disallowed forums $disallow_access = $this->modules_helper->get_disallowed_forums($permissions); if ($this->config['board3_news_exclude_' . $module_id] == true) { $disallow_access = array_merge($disallow_access, $forum_from); $forum_from = array(); } if (sizeof($forum_from)) { $disallow_access = array_diff($forum_from, $disallow_access); if (!sizeof($disallow_access)) { return array(); } foreach ($disallow_access as $acc_id) { $acc_id = (int) $acc_id; $str_where .= "forum_id = {$acc_id} OR "; } } else { foreach ($disallow_access as $acc_id) { $acc_id = (int) $acc_id; $str_where .= "forum_id <> {$acc_id} AND "; } } $str_where = strlen($str_where) > 0 ? 'AND (' . trim(substr($str_where, 0, -4)) . ')' : ''; $topic_type = $this->config['board3_show_all_news_' . $module_id] ? '(topic_type <> ' . POST_ANNOUNCE . ') AND (topic_type <> ' . POST_GLOBAL . ')' : 'topic_type = ' . POST_NORMAL; $sql = 'SELECT COUNT(topic_id) AS num_topics FROM ' . TOPICS_TABLE . ' WHERE ' . $topic_type . ' AND topic_visibility = ' . ITEM_APPROVED . ' AND topic_moved_id = 0 ' . $str_where; $result = $this->db->sql_query($sql, 300); $total_news = (int) $this->db->sql_fetchfield('num_topics'); $this->db->sql_freeresult($result); } $topic_tracking_info = get_portal_tracking_info($fetch_news); // Create pagination if necessary if ($this->config['board3_news_archive_' . $module_id]) { $pagination = generate_portal_pagination($this->modules_helper->route('board3_portal_controller'), $total_news, $this->config['board3_number_of_news_' . $module_id], $start, $this->config['board3_show_all_news_' . $module_id] ? 'news_all' : 'news', $module_id); } if ($this->config['board3_number_of_news_' . $module_id] != 0 && $this->config['board3_news_archive_' . $module_id]) { $news_row = array_merge($news_row, array('NP_PAGINATION' => !empty($pagination) ? $pagination : '', 'TOTAL_NEWS' => $total_news == 1 ? sprintf($this->user->lang['VIEW_FORUM_TOPICS'][1], $total_news) : sprintf($this->user->lang['VIEW_FORUM_TOPICS'][2], $total_news), 'NP_PAGE_NUMBER' => $this->pagination->on_page($total_news, $this->config['board3_number_of_news_' . $module_id], $start))); } // Create standard news row $this->template->assign_block_vars('news', $news_row); // Show the news overview if ($news < 0) { $count = $fetch_news['topic_count']; for ($i = 0; $i < $count; $i++) { if (isset($fetch_news[$i]['striped']) && $fetch_news[$i]['striped'] == true) { $open_bracket = '[ '; $close_bracket = ' ]'; $read_full = $this->user->lang['READ_FULL']; } else { $open_bracket = ''; $close_bracket = ''; $read_full = ''; } // unread? $forum_id = $fetch_news[$i]['forum_id']; $topic_id = $fetch_news[$i]['topic_id']; $unread_topic = isset($topic_tracking_info[$topic_id]) && $fetch_news[$i]['topic_last_post_time'] > $topic_tracking_info[$topic_id] ? true : false; $read_full_url = $this->request->is_set('np_' . $module_id) ? "np_{$module_id}={$start}&news_{$module_id}={$i}#n_{$module_id}_{$i}" : "news_{$module_id}={$i}#n_{$module_id}_{$i}"; $view_topic_url = append_sid("{$this->phpbb_root_path}viewtopic.{$this->php_ext}", 'f=' . ($fetch_news[$i]['forum_id'] ? $fetch_news[$i]['forum_id'] : $forum_id) . '&t=' . $topic_id); $replies = $this->auth->acl_get('m_approve', $forum_id) ? $fetch_news[$i]['topic_replies_real'] : $fetch_news[$i]['topic_replies']; switch ($fetch_news[$i]['topic_type']) { case POST_STICKY: $folder = 'sticky_read'; $folder_new = 'sticky_unread'; break; case POST_ANNOUNCE: $folder = 'announce_read'; $folder_new = 'announce_unread'; break; default: $folder = 'topic_read'; $folder_new = 'topic_unread'; if ($this->config['hot_threshold'] && $replies >= $this->config['hot_threshold'] && $fetch_news[$i]['topic_status'] != ITEM_LOCKED) { $folder .= '_hot'; $folder_new .= '_hot'; } break; } if ($fetch_news[$i]['topic_status'] == ITEM_LOCKED) { $folder .= '_locked'; $folder_new .= '_locked'; } if ($fetch_news[$i]['topic_posted']) { $folder .= '_mine'; $folder_new .= '_mine'; } $folder_img = $unread_topic ? $folder_new : $folder; $folder_alt = $unread_topic ? 'NEW_POSTS' : ($fetch_news[$i]['topic_status'] == ITEM_LOCKED ? 'TOPIC_LOCKED' : 'NO_NEW_POSTS'); // Grab icons $icons = $this->cache->obtain_icons(); $this->template->assign_block_vars('news.news_row', array('ATTACH_ICON_IMG' => $fetch_news[$i]['attachment'] && $this->config['allow_attachments'] ? $this->user->img('icon_topic_attach', $this->user->lang['TOTAL_ATTACHMENTS']) : '', 'FORUM_NAME' => $forum_id ? $fetch_news[$i]['forum_name'] : '', 'TITLE' => $fetch_news[$i]['topic_title'], 'POSTER' => $fetch_news[$i]['username'], 'POSTER_FULL' => $fetch_news[$i]['username_full'], 'USERNAME_FULL_LAST' => $fetch_news[$i]['username_full_last'], 'U_USER_PROFILE' => ($fetch_news[$i]['user_type'] == USER_NORMAL || $fetch_news[$i]['user_type'] == USER_FOUNDER) && $fetch_news[$i]['user_id'] != ANONYMOUS ? append_sid("{$this->phpbb_root_path}memberlist.{$this->php_ext}", 'mode=viewprofile&u=' . $fetch_news[$i]['user_id']) : '', 'TIME' => $fetch_news[$i]['topic_time'], 'LAST_POST_TIME' => $this->user->format_date($fetch_news[$i]['topic_last_post_time']), 'TEXT' => $fetch_news[$i]['post_text'], 'REPLIES' => $fetch_news[$i]['topic_replies'], 'TOPIC_VIEWS' => $fetch_news[$i]['topic_views'], 'N_ID' => $i, 'TOPIC_FOLDER_IMG' => $this->user->img($folder_img, $folder_alt), 'TOPIC_IMG_STYLE' => $folder_img, 'TOPIC_FOLDER_IMG_SRC' => $this->user->img($folder_img, $folder_alt, false, '', 'src'), 'TOPIC_FOLDER_IMG_ALT' => $this->user->lang[$folder_alt], 'TOPIC_ICON_IMG' => !empty($icons[$fetch_news[$i]['icon_id']]) ? $icons[$fetch_news[$i]['icon_id']]['img'] : '', 'TOPIC_ICON_IMG_WIDTH' => !empty($icons[$fetch_news[$i]['icon_id']]) ? $icons[$fetch_news[$i]['icon_id']]['width'] : '', 'TOPIC_ICON_IMG_HEIGHT' => !empty($icons[$fetch_news[$i]['icon_id']]) ? $icons[$fetch_news[$i]['icon_id']]['height'] : '', 'FOLDER_IMG' => $this->user->img('topic_read', 'NO_NEW_POSTS'), 'U_VIEWFORUM' => append_sid("{$this->phpbb_root_path}viewforum.{$this->php_ext}", 'f=' . $fetch_news[$i]['forum_id']), 'U_LAST_COMMENTS' => append_sid("{$this->phpbb_root_path}viewtopic.{$this->php_ext}", 'f=' . $fetch_news[$i]['forum_id'] . '&t=' . $fetch_news[$i]['topic_id'] . '&p=' . $fetch_news[$i]['topic_last_post_id'] . '#p' . $fetch_news[$i]['topic_last_post_id']), 'U_VIEW_COMMENTS' => append_sid("{$this->phpbb_root_path}viewtopic.{$this->php_ext}", 'f=' . $fetch_news[$i]['forum_id'] . '&t=' . $fetch_news[$i]['topic_id']), 'U_VIEW_UNREAD' => append_sid("{$this->phpbb_root_path}viewtopic.{$this->php_ext}", 'f=' . $fetch_news[$i]['forum_id'] . '&t=' . $fetch_news[$i]['topic_id'] . '&view=unread#unread'), 'U_POST_COMMENT' => append_sid("{$this->phpbb_root_path}posting.{$this->php_ext}", 'mode=reply&f=' . $fetch_news[$i]['forum_id'] . '&t=' . $fetch_news[$i]['topic_id']), 'U_READ_FULL' => $this->modules_helper->route('board3_portal_controller') . '?' . $read_full_url, 'L_READ_FULL' => $read_full, 'OPEN' => $open_bracket, 'CLOSE' => $close_bracket, 'S_NOT_LAST' => $i < sizeof($fetch_news) - 1 ? true : false, 'S_POLL' => $fetch_news[$i]['poll'], 'S_UNREAD_INFO' => $unread_topic, 'S_HAS_ATTACHMENTS' => !empty($fetch_news[$i]['attachments']) ? true : false)); // Assign pagination $this->pagination->generate_template_pagination($view_topic_url, 'news.news_row.pagination', 'start', $fetch_news[$i]['topic_replies'] + 1, $this->config['posts_per_page'], 1); if (!empty($fetch_news[$i]['attachments'])) { foreach ($fetch_news[$i]['attachments'] as $attachment) { $this->template->assign_block_vars('news.news_row.attachment', array('DISPLAY_ATTACHMENT' => $attachment)); } } } } else { $i = $news; $forum_id = $fetch_news[$i]['forum_id']; $topic_id = $fetch_news[$i]['topic_id']; $unread_topic = isset($topic_tracking_info[$topic_id]) && $fetch_news[$i]['topic_last_post_time'] > $topic_tracking_info[$topic_id] ? true : false; $open_bracket = '[ '; $close_bracket = ' ]'; $read_full = $this->user->lang['BACK']; $read_full_url = $this->request->is_set('np_' . $module_id) ? $this->modules_helper->route('board3_portal_controller') . "?np_{$module_id}={$start}#n_{$module_id}_{$i}" : $this->modules_helper->route('board3_portal_controller') . "#n_{$module_id}_{$i}"; $view_topic_url = append_sid("{$this->phpbb_root_path}viewtopic.{$this->php_ext}", 'f=' . ($fetch_news[$i]['forum_id'] ? $fetch_news[$i]['forum_id'] : $forum_id) . '&t=' . $topic_id); $this->template->assign_block_vars('news.news_row', array('ATTACH_ICON_IMG' => $fetch_news[$i]['attachment'] && $this->config['allow_attachments'] ? $this->user->img('icon_topic_attach', $this->user->lang['TOTAL_ATTACHMENTS']) : '', 'FORUM_NAME' => $forum_id ? $fetch_news[$i]['forum_name'] : '', 'TITLE' => $fetch_news[$i]['topic_title'], 'POSTER' => $fetch_news[$i]['username'], 'POSTER_FULL' => $fetch_news[$i]['username_full'], 'TIME' => $fetch_news[$i]['topic_time'], 'TEXT' => $fetch_news[$i]['post_text'], 'REPLIES' => $fetch_news[$i]['topic_replies'], 'TOPIC_VIEWS' => $fetch_news[$i]['topic_views'], 'N_ID' => $i, 'U_VIEWFORUM' => append_sid("{$this->phpbb_root_path}viewforum.{$this->php_ext}", 'f=' . $fetch_news[$i]['forum_id']), 'U_LAST_COMMENTS' => append_sid("{$this->phpbb_root_path}viewtopic.{$this->php_ext}", 'p=' . $fetch_news[$i]['topic_last_post_id'] . '#p' . $fetch_news[$i]['topic_last_post_id']), 'U_VIEW_COMMENTS' => append_sid("{$this->phpbb_root_path}viewtopic.{$this->php_ext}", 'f=' . $fetch_news[$i]['forum_id'] . '&t=' . $fetch_news[$i]['topic_id']), 'U_POST_COMMENT' => append_sid("{$this->phpbb_root_path}posting.{$this->php_ext}", 'mode=reply&f=' . $fetch_news[$i]['forum_id'] . '&t=' . $fetch_news[$i]['topic_id']), 'S_POLL' => $fetch_news[$i]['poll'], 'S_UNREAD_INFO' => $unread_topic, 'U_READ_FULL' => $read_full_url, 'L_READ_FULL' => $read_full, 'OPEN' => $open_bracket, 'CLOSE' => $close_bracket, 'S_HAS_ATTACHMENTS' => !empty($fetch_news[$i]['attachments']) ? true : false)); $this->pagination->generate_template_pagination($view_topic_url, 'news.news_row.pagination', 'start', $fetch_news[$i]['topic_replies'] + 1, $this->config['posts_per_page'], 1); if (!empty($fetch_news[$i]['attachments'])) { foreach ($fetch_news[$i]['attachments'] as $attachment) { $this->template->assign_block_vars('news.news_row.attachment', array('DISPLAY_ATTACHMENT' => $attachment)); } } } } $this->template->assign_vars(array('NEWEST_POST_IMG' => $this->user->img('icon_topic_newest', 'VIEW_NEWEST_POST'), 'READ_POST_IMG' => $this->user->img('icon_topic_latest', 'VIEW_LATEST_POST'), 'GOTO_PAGE_IMG' => $this->user->img('icon_post_target', 'GOTO_PAGE'))); if ($this->config['board3_news_style_' . $module_id]) { return 'news_compact_center.html'; } else { return 'news_center.html'; } }
/** * Main ACP module * * @param int $id * @param string $mode * @access public */ public function main($id, $mode) { // Define the name of the form for use as a form key $form_name = 'acp_phpbb_ideas_settings'; add_form_key($form_name); // Set an empty errors array $errors = array(); $display_vars = array('legend1' => 'ACP_PHPBB_IDEAS_SETTINGS', 'ideas_forum_id' => array('lang' => 'ACP_IDEAS_FORUM_ID', 'validate' => 'string', 'type' => 'custom', 'method' => 'select_ideas_forum', 'explain' => true), 'ideas_poster_id' => array('lang' => 'ACP_IDEAS_POSTER_ID', 'validate' => 'string', 'type' => 'custom', 'method' => 'select_ideas_topics_poster', 'explain' => true), 'ideas_base_url' => array('lang' => 'ACP_IDEAS_BASE_URL', 'validate' => 'string', 'type' => 'text:45:255', 'explain' => true)); // Display forum setup utility button only if the forum is set if (!empty($this->config['ideas_forum_id'])) { $display_vars = array_merge($display_vars, array('legend2' => 'ACP_IDEAS_UTILITIES', 'ideas_forum_setup' => array('lang' => 'ACP_IDEAS_FORUM_SETUP', 'validate' => 'bool', 'type' => 'custom', 'method' => 'set_ideas_forum_permissions', 'explain' => true))); } $this->new_config = $this->config; $cfg_array = $this->request->is_set('config') ? $this->request->variable('config', array('' => ''), true) : $this->new_config; $submit = $this->request->is_set_post('submit'); $submit_forum_setup = $this->request->is_set_post('ideas_forum_setup'); // We validate the complete config if wished validate_config_vars($display_vars, $cfg_array, $errors); if ($submit || $submit_forum_setup) { if (!check_form_key($form_name)) { $errors[] = $this->language->lang('FORM_INVALID'); } } // Check if selected user exists if ($submit) { $sql = 'SELECT user_id FROM ' . USERS_TABLE . "\n\t\t\t\tWHERE username_clean = '" . $this->db->sql_escape(utf8_clean_string($cfg_array['ideas_poster_id'])) . "'"; $result = $this->db->sql_query($sql); $user_id = (int) $this->db->sql_fetchfield('user_id'); $this->db->sql_freeresult($result); if (!$user_id) { $errors[] = $this->language->lang('NO_USER'); } else { // If selected user does exist, reassign the config value to its ID $cfg_array['ideas_poster_id'] = $user_id; } } // Check if Ideas forum is selected and apply relevant settings if it is if ($submit_forum_setup) { if (empty($this->config['ideas_forum_id'])) { trigger_error($this->language->lang('ACP_IDEAS_NO_FORUM') . '.' . adm_back_link($this->u_action)); } else { if (!class_exists('auth_admin')) { include $this->phpbb_root_path . 'includes/acp/auth.' . $this->php_ext; } $auth_admin = new \auth_admin(); $forum_id = (int) $this->config['ideas_forum_id']; // Get the REGISTERED usergroup ID $sql = 'SELECT group_id FROM ' . GROUPS_TABLE . "\n\t\t\t\t\tWHERE group_name = '" . $this->db->sql_escape('REGISTERED') . "'"; $this->db->sql_query($sql); $group_id = (int) $this->db->sql_fetchfield('group_id'); // Get 'f_' local REGISTERED users group permissions array for the ideas forum // Default undefined permissions to ACL_NO $hold_ary = $auth_admin->get_mask('set', false, $group_id, $forum_id, 'f_', 'local', ACL_NO); $auth_settings = $hold_ary[$group_id][$forum_id]; // Set 'Can start new topics' permissions to 'Never' for the ideas forum $auth_settings['f_post'] = ACL_NEVER; // Update the registered usergroup permissions for selected Ideas forum... $auth_admin->acl_set('group', $forum_id, $group_id, $auth_settings); // Disable auto-pruning for ideas forum $sql = 'UPDATE ' . FORUMS_TABLE . ' SET ' . $this->db->sql_build_array('UPDATE', array('enable_prune' => false)) . ' WHERE forum_id = ' . $forum_id; $this->db->sql_query($sql); } } // Do not write values if there are errors if (sizeof($errors)) { $submit = $submit_forum_setup = false; } // We go through the display_vars to make sure no one is trying to set variables he/she is not allowed to foreach ($display_vars as $config_name => $null) { if (!isset($cfg_array[$config_name]) || strpos($config_name, 'legend') !== false) { continue; } $this->new_config[$config_name] = $config_value = $cfg_array[$config_name]; if ($submit) { $this->config->set($config_name, $config_value); } } // Submit relevant log entries and output success message if ($submit || $submit_forum_setup) { $message = $submit_forum_setup ? 'FORUM_SETUP' : 'SETTINGS'; $this->log->add('admin', $this->user->data['user_id'], $this->user->ip, "ACP_PHPBB_IDEAS_{$message}_LOG"); trigger_error($this->language->lang("ACP_IDEAS_{$message}_UPDATED") . adm_back_link($this->u_action)); } // Output relevant page foreach ($display_vars as $config_key => $vars) { if (!is_array($vars) && strpos($config_key, 'legend') === false) { continue; } if (strpos($config_key, 'legend') !== false) { $this->template->assign_block_vars('options', array('S_LEGEND' => true, 'LEGEND' => $this->language->lang($vars))); continue; } $type = explode(':', $vars['type']); $content = build_cfg_template($type, $config_key, $this->new_config, $config_key, $vars); if (empty($content)) { continue; } $this->template->assign_block_vars('options', array('KEY' => $config_key, 'TITLE' => $this->language->lang($vars['lang']), 'S_EXPLAIN' => $vars['explain'], 'TITLE_EXPLAIN' => $vars['explain'] ? $this->language->lang($vars['lang'] . '_EXPLAIN') : '', 'CONTENT' => $content)); } $this->template->assign_vars(array('S_ERROR' => (bool) sizeof($errors), 'ERROR_MSG' => sizeof($errors) ? implode('<br />', $errors) : '', 'U_ACTION' => $this->u_action, 'U_FIND_USERNAME' => append_sid("{$this->phpbb_root_path}memberlist.{$this->php_ext}", 'mode=searchuser&form=acp_phpbb_ideas_settings&field=ideas_poster_id&select_single=true'))); }