/** * @param string $list_name whitelist or blacklist * @param string $u_action phpbb acp-u_action */ private function manage_list($u_action, $list_name) { $list_name_upper = strtoupper($list_name); // Define the name of the form for use as a form key $form_name = 'topictags'; add_form_key($form_name); $errors = array(); if ($this->request->is_set_post('submit')) { if (!check_form_key($form_name)) { trigger_error('FORM_INVALID'); } $this->config->set(prefixes::CONFIG . '_' . $list_name . '_enabled', $this->request->variable(prefixes::CONFIG . '_' . $list_name . '_enabled', 0)); $list = rawurldecode(base64_decode($this->request->variable(prefixes::CONFIG . '_' . $list_name, ''))); if (!empty($list)) { $list = json_decode($list, true); $tags = array(); for ($i = 0, $size = sizeof($list); $i < $size; $i++) { $tags[] = $list[$i]['text']; } $list = json_encode($tags); } // store the list $this->config_text->set(prefixes::CONFIG . '_' . $list_name, $list); trigger_error($this->user->lang('TOPICTAGS_' . $list_name_upper . '_SAVED') . adm_back_link($u_action)); } // display $list = $this->config_text->get(prefixes::CONFIG . '_' . $list_name); $list = base64_encode(rawurlencode($list)); $this->template->assign_vars(array('TOPICTAGS_VERSION' => $this->user->lang('TOPICTAGS_INSTALLED', $this->config[prefixes::CONFIG . '_version']), 'TOPICTAGS_' . $list_name_upper . '_ENABLED' => $this->config[prefixes::CONFIG . '_' . $list_name . '_enabled'], 'TOPICTAGS_' . $list_name_upper => $list, 'S_RH_TOPICTAGS_INCLUDE_NG_TAGS_INPUT' => true, 'S_RH_TOPICTAGS_INCLUDE_CSS' => true, 'TOPICTAGS_CONVERT_SPACE_TO_MINUS' => $this->config[prefixes::CONFIG . '_convert_space_to_minus'] ? 'true' : 'false', 'S_ERROR' => sizeof($errors) ? true : false, 'ERROR_MSG' => implode('<br />', $errors), 'U_ACTION' => $u_action)); }
/** * Remove an existing config_text setting. * * @param string $config_name The name of the config_text setting you would * like to remove * @return null */ public function remove($config_name) { if (is_null($this->config_text->get($config_name))) { return; } $this->config_text->delete($config_name); }
/** * Loads resume data from the database * * @param string $name Name of the reparser to which the resume data belongs * * @return array */ public function get_resume_data($name) { if ($this->resume_data === null) { $resume_data = $this->config_text->get('reparser_resume'); $this->resume_data = !empty($resume_data) ? unserialize($resume_data) : array(); } return isset($this->resume_data[$name]) ? $this->resume_data[$name] : array(); }
/** * Set a cookie to keep an announcement closed * * @return bool True * @access protected */ protected function set_board_announcement_cookie() { // Get board announcement data from the DB text object $announcement_timestamp = $this->config_text->get('announcement_timestamp'); // Store the announcement timestamp/id in a cookie with a 1 year expiration $this->user->set_cookie('baid', $announcement_timestamp, strtotime('+1 year')); return true; }
public function test_update_resume_data() { $resume_data = array('test_reparser' => array('range-min' => 0, 'range-max' => 100, 'range-size' => 50)); $this->config_text->set('reparser_resume', serialize($resume_data)); $this->reparser_manager->update_resume_data('another_reparser', 5, 20, 10, false); $this->assert_array_content_equals($resume_data, unserialize($this->config_text->get('reparser_resume'))); $this->reparser_manager->update_resume_data('test_reparser', 0, 50, 50); $resume_data = array('test_reparser' => array('range-min' => 0, 'range-max' => 50, 'range-size' => 50), 'another_reparser' => array('range-min' => 5, 'range-max' => 20, 'range-size' => 10)); $this->assert_array_content_equals($resume_data, unserialize($this->config_text->get('reparser_resume'))); }
public function test_delete_array_get_remaining() { $this->config_text->delete_array(array('foo', 'bar')); $this->assertNull($this->config_text->get('bar')); $this->assertNull($this->config_text->get('foo')); $this->assertSame('string-de-ding', $this->config_text->get('meh')); }
/** * {inheritDoc} */ public function render(\phpbb\template\template $template) { $l_admin_info = $this->config_text->get('contact_admin_info'); if ($l_admin_info) { $contact_admin_data = $this->config_text->get_array(array('contact_admin_info', 'contact_admin_info_uid', 'contact_admin_info_bitfield', 'contact_admin_info_flags')); $l_admin_info = generate_text_for_display($contact_admin_data['contact_admin_info'], $contact_admin_data['contact_admin_info_uid'], $contact_admin_data['contact_admin_info_bitfield'], $contact_admin_data['contact_admin_info_flags']); } $template->assign_vars(array('S_CONTACT_ADMIN' => true, 'S_CONTACT_FORM' => $this->config['contact_admin_form_enable'], 'S_IS_REGISTERED' => $this->user->data['is_registered'], 'S_POST_ACTION' => append_sid($this->phpbb_root_path . 'memberlist.' . $this->phpEx, 'mode=contactadmin'), 'CONTACT_INFO' => $l_admin_info, 'MESSAGE' => $this->body, 'SUBJECT' => $this->subject, 'NAME' => $this->sender_name, 'EMAIL' => $this->sender_address)); parent::render($template); }
public function core_posting_modify_template_vars($event) { $page_data = $event['page_data']; $post_data = $event['post_data']; $mode = $event['mode']; $submit = $event['submit']; $preview = $event['preview']; $load = $event['load']; $save = $event['save']; $refresh = $event['refresh']; $forum_id = $event['forum_id']; if ($mode == 'post' && !$submit && !$preview && !$load && !$save && !$refresh && empty($post_data['post_text']) && empty($post_data['post_subject']) && $this->config_text->get('marttiphpbb_postingtemplate_forum[' . $forum_id . ']')) { $page_data['MESSAGE'] = $this->config_text->get('marttiphpbb_postingtemplate_forum[' . $forum_id . ']'); } $event['page_data'] = $page_data; }
public function edit_subject($event) { $mode = $event['mode']; $post_data = $event['post_data']; $topic_first_post_id = isset($event['post_data']['topic_first_post_id']) ? $event['post_data']['topic_first_post_id'] : 0; $post_id = isset($event['post_data']['post_id']) ? $event['post_data']['post_id'] : 0; $forums = explode(',', $this->config['sub_prfx_forums']); if (in_array($event['forum_id'], $forums) && ($mode == 'post' || $mode == 'edit') && ($post_id == $topic_first_post_id || !$topic_first_post_id)) { if ($mode == 'edit') { $subject_data = $event['post_data']['post_subject']; $subject_data = explode(']', $subject_data); $subject = array_pop($subject_data); $subject_prfixes = array_diff($subject_data, array($subject)); foreach ($subject_prfixes as $key => $pfx) { $subject_prfixes[$key] = str_replace('[', '', $pfx); } } $options = $options_second = array(0 => $this->user->lang['SELECT']); $options = array_merge($options, explode(',', (string) $this->config_text->get('sub_prfx'))); $options_second = array_merge($options_second, explode(',', (string) $this->config_text->get('sub_prfx_second'))); $key = isset($subject_prfixes[0]) ? array_search($subject_prfixes[0], $options) : 0; $second_key = isset($subject_prfixes[1]) ? array_search($subject_prfixes[1], $options_second) : 0; $prefix = $this->request->variable('subprfx', $key); $subprfx_second = $this->request->variable('subprfx_second', $second_key); $select = ''; if ($options[1]) { foreach ($options as $key => $value) { $select .= '<option value="' . $key . '"' . ($key == $prefix ? ' selected="selected"' : '') . '>' . $value . '</option>'; } } $select_second = ''; if ($options_second[1]) { foreach ($options_second as $key => $value) { $select_second .= '<option value="' . $key . '"' . ($key == $subprfx_second ? ' selected="selected"' : '') . '>' . $value . '</option>'; } } $this->template->assign_vars(array('S_SELECT' => $select, 'S_SELECT_SECOND' => $select_second)); } }
private function get_settings() { $settings = $this->config_text->get('sfs_settings'); $settings = unserialize($settings); return $settings; }
public function posts_merging($event) { $mode = $event['mode']; $subject = $event['subject']; $username = $event['username']; $topic_type = $event['topic_type']; $poll = $event['poll']; $data = $event['data']; $update_message = $event['update_message']; $update_search_index = $event['update_search_index']; $current_time = time(); $do_not_merge_with_previous = $this->request->variable('posts_merging_option', false); if (!$do_not_merge_with_previous && !$this->helper->post_needs_approval($data) && in_array($mode, array('reply', 'quote')) && $this->merge_interval && !$this->helper->excluded_from_merge($data)) { $merge_post_data = $this->helper->get_last_post_data($data); // Do not merge if there's no last post data, the post is locked or allowed merge period has left if (!$merge_post_data || $merge_post_data['post_edit_locked'] || $current_time - (int) $merge_post_data['topic_last_post_time'] > $this->merge_interval || !$this->user->data['is_registered']) { return; } // Also, don't let user to violate attachments limit by posts merging // In this case, also don't merge posts and return // Exceptions are administrators and forum moderators $num_old_attachments = $this->helper->count_post_attachments((int) $merge_post_data['post_id']); $num_new_attachments = sizeof($data['attachment_data']); $total_attachments_count = $num_old_attachments + $num_new_attachments; if ($total_attachments_count > $this->config['max_attachments'] && !$this->auth->acl_get('a_') && !$this->auth->acl_get('m_', (int) $data['forum_id'])) { return; } $data['post_id'] = (int) $merge_post_data['post_id']; $merge_post_data['post_attachment'] = $total_attachments_count ? 1 : 0; // Decode old message and addon $merge_post_data['post_text'] = $this->helper->prepare_text_for_merge($merge_post_data); $data['message'] = $this->helper->prepare_text_for_merge($data); // Handle inline attachments BBCode in old message if ($num_new_attachments) { $merge_post_data['post_text'] = preg_replace('#\\[attachment=([0-9]+)\\](.*?)\\[\\/attachment\\]#e', "'[attachment='.(\\1 + {$num_new_attachments}).']\\2[/attachment]'", $merge_post_data['post_text']); } // Prepare message separator $separator = (string) $this->config_text->get('posts_merging_separator_text'); $this->user->add_lang_ext('rxu/PostsMerging', 'posts_merging'); // Calculate the time interval $interval = $this->helper->get_time_interval($current_time, $merge_post_data['post_time']); $time = array(); $time[] = $interval->h ? $this->user->lang('D_HOURS', $interval->h) : null; $time[] = $interval->i ? $this->user->lang('D_MINUTES', $interval->i) : null; $time[] = $interval->s ? $this->user->lang('D_SECONDS', $interval->s) : null; // Allow using language variables like {L_LANG_VAR} $separator = preg_replace_callback('/{L_([A-Z0-9_]+)}/', function ($matches) { return $this->user->lang($matches[1]); }, $separator); // Eval linefeeds and generate the separator, time interval included $separator = sprintf(str_replace('\\n', "\n", $separator), implode(' ', $time)); // Merge subject if (!empty($subject) && $subject != $merge_post_data['post_subject'] && $merge_post_data['post_id'] != $merge_post_data['topic_first_post_id']) { $separator .= sprintf($this->user->lang['MERGE_SUBJECT'], $subject); } // Merge posts $merge_post_data['post_text'] = $merge_post_data['post_text'] . $separator . $data['message']; // Make sure the message is safe $this->type_cast_helper->recursive_set_var($merge_post_data['post_text'], '', true); //Prepare post for submit $options = ''; $warn_msg = generate_text_for_storage($merge_post_data['post_text'], $merge_post_data['bbcode_uid'], $merge_post_data['bbcode_bitfield'], $options, $merge_post_data['enable_bbcode'], $merge_post_data['enable_magic_url'], $merge_post_data['enable_smilies']); // If $warn_msg is not empty, the merged message does not conform some restrictions // In this case we simply don't merge and return back to the function submit_post() if (!empty($warn_msg)) { return; } // If this is the first merging for current post, save original post time within the post_created field // Update post time with the current time and submit post to the database $merge_post_data['post_created'] = $merge_post_data['post_created'] ?: $merge_post_data['post_time']; $merge_post_data['post_time'] = $data['post_time'] = $current_time; $this->helper->submit_post_to_database($merge_post_data); // Submit attachments $this->helper->submit_attachments($data); // Update read tracking $this->helper->update_read_tracking($data); // If a username was supplied or the poster is a guest, we will use the supplied username. // Doing it this way we can use "...post by guest-username..." in notifications when // "guest-username" is supplied or ommit the username if it is not. $username = $username !== '' || !$this->user->data['is_registered'] ? $username : $this->user->data['username']; // Send Notifications // Despite the post_id is the same and users who've been already notified // won't be notified again about the same post_id, we send notifications // for new users possibly subscribed to it $notification_data = array_merge($data, array('topic_title' => isset($data['topic_title']) ? $data['topic_title'] : $subject, 'post_username' => $username, 'poster_id' => (int) $data['poster_id'], 'post_text' => $data['message'], 'post_time' => $merge_post_data['post_time'], 'post_subject' => $subject)); $this->notification_manager->add_notifications(array('notification.type.quote', 'notification.type.bookmark', 'notification.type.post'), $notification_data); // Update search index $this->helper->update_search_index($merge_post_data); //Generate redirection URL and redirecting $params = $add_anchor = ''; $params .= '&t=' . $data['topic_id']; $params .= '&p=' . $data['post_id']; $add_anchor = '#p' . $data['post_id']; $url = "{$this->phpbb_root_path}viewtopic.{$this->php_ext}"; $url = append_sid($url, 'f=' . (int) $data['forum_id'] . $params) . $add_anchor; /** * Modify the data for post submitting * * @event rxu.postsmerging.posts_merging_end * @var string mode Variable containing posting mode value * @var string subject Variable containing post subject value * @var string username Variable containing post author name * @var int topic_type Variable containing topic type value * @var array poll Array with the poll data for the post * @var array data Array with the data for the post * @var bool update_message Flag indicating if the post will be updated * @var bool update_search_index Flag indicating if the search index will be updated * @var string url The "Return to topic" URL * @since 2.0.0 */ $vars = array('mode', 'subject', 'username', 'topic_type', 'poll', 'data', 'update_message', 'update_search_index', 'url'); extract($this->phpbb_dispatcher->trigger_event('rxu.postsmerging.posts_merging_end', compact($vars))); redirect($url); } }
/** * Load the resume data from the database */ protected function load_resume_data() { $resume_data = $this->config_text->get('reparser_resume'); $this->resume_data = empty($resume_data) ? array() : unserialize($resume_data); }
/** * Gets all tags from the whitelist */ public function get_whitelist_tags() { return json_decode($this->config_text->get(prefixes::CONFIG . '_whitelist'), true); }