Ejemplo n.º 1
0
		FROM ' . POSTS_TABLE . "\n\t\tWHERE topic_id = {$topic_id}\n\t\t\tAND post_time >= {$min_post_time}\n\t\t\t\tAND " . $phpbb_content_visibility->get_visibility_sql('post', $forum_id);
    $result = $db->sql_query($sql);
    $total_posts = (int) $db->sql_fetchfield('num_posts');
    $db->sql_freeresult($result);
    $limit_posts_time = "AND p.post_time >= {$min_post_time} ";
    if (isset($_POST['sort'])) {
        $start = 0;
    }
} else {
    $total_posts = $topic_replies + 1;
    $limit_posts_time = '';
}
// Was a highlight request part of the URI?
$highlight_match = $highlight = '';
if ($hilit_words) {
    $highlight_match = phpbb_clean_search_string($hilit_words);
    $highlight = urlencode($highlight_match);
    $highlight_match = str_replace('\\*', '\\w+?', preg_quote($highlight_match, '#'));
    $highlight_match = preg_replace('#(?<=^|\\s)\\\\w\\*\\?(?=\\s|$)#', '\\w+?', $highlight_match);
    $highlight_match = str_replace(' ', '|', $highlight_match);
}
// Make sure $start is set to the last page if it exceeds the amount
$start = $pagination->validate_start($start, $config['posts_per_page'], $total_posts);
// General Viewtopic URL for return links
$viewtopic_url = append_sid("{$phpbb_root_path}viewtopic.{$phpEx}", "f={$forum_id}&amp;t={$topic_id}" . ($start == 0 ? '' : "&amp;start={$start}") . (strlen($u_sort_param) ? "&amp;{$u_sort_param}" : '') . ($highlight_match ? "&amp;hilit={$highlight}" : ''));
// Are we watching this topic?
$s_watching_topic = array('link' => '', 'link_toggle' => '', 'title' => '', 'title_toggle' => '', 'is_watching' => false);
if ($config['allow_topic_notify']) {
    $notify_status = isset($topic_data['notify_status']) ? $topic_data['notify_status'] : null;
    watch_topic_forum('topic', $s_watching_topic, $user->data['user_id'], $forum_id, $topic_id, $notify_status, $start, $topic_data['topic_title']);
    // Reset forum notification if forum notify is set
Ejemplo n.º 2
0
 /**
  * @dataProvider phpbb_clean_search_string_data
  */
 public function test_phpbb_clean_search_string($search_string, $expected)
 {
     $this->assertEquals($expected, phpbb_clean_search_string($search_string));
 }
Ejemplo n.º 3
0
				while ($row = $db->sql_fetchrow($result))
				{
					$attachments[$row['post_msg_id']][] = $row;
				}
				$db->sql_freeresult($result);
			}
		}

		if ($hilit)
		{
			// Remove bad highlights
			$hilit_array = array_filter(explode('|', $hilit), 'strlen');
			foreach ($hilit_array as $key => $value)
			{
				$hilit_array[$key] = phpbb_clean_search_string($value);
				$hilit_array[$key] = str_replace('\*', '\w*?', preg_quote($hilit_array[$key], '#'));
				$hilit_array[$key] = preg_replace('#(^|\s)\\\\w\*\?(\s|$)#', '$1\w+?$2', $hilit_array[$key]);
			}
			$hilit = implode('|', $hilit_array);
		}

		/**
		* Modify the rowset data
		*
		* @event core.search_modify_rowset
		* @var	array	attachments				Array with posts attachments data
		* @var	string	hilit					String to highlight
		* @var	array	rowset					Array with the search results data
		* @var	string	show_results			String indicating the show results mode
		* @var	array	topic_tracking_info		Array with the topics tracking data
Ejemplo n.º 4
0
 public function core_user_setup($event)
 {
     if (empty($this->core->seo_opt['url_rewrite'])) {
         return;
     }
     $user_data = $event['user_data'];
     switch ($this->core->seo_opt['req_file']) {
         case 'viewforum':
             global $forum_data;
             // god save the hax
             if ($forum_data) {
                 if ($forum_data['forum_topics_per_page']) {
                     $this->config['topics_per_page'] = $forum_data['forum_topics_per_page'];
                 }
                 $start = $this->core->seo_chk_start($this->start, $this->config['topics_per_page']);
                 if ($this->start != $start) {
                     $this->start = (int) $start;
                     $this->request->overwrite('start', $this->start);
                 }
                 $this->forum_id = max(0, (int) $forum_data['forum_id']);
                 $this->core->prepare_forum_url($forum_data);
                 $this->core->seo_path['canonical'] = $this->core->drop_sid(append_sid("{$this->phpbb_root_path}viewforum.{$this->php_ext}", "f={$this->forum_id}&amp;start={$this->start}"));
                 $this->core->set_parent_urls($forum_data);
                 $default_sort_days = !empty($user_data['user_topic_show_days']) ? $user_data['user_topic_show_days'] : 0;
                 $default_sort_key = !empty($user_data['user_topic_sortby_type']) ? $user_data['user_topic_sortby_type'] : 't';
                 $default_sort_dir = !empty($user_data['user_topic_sortby_dir']) ? $user_data['user_topic_sortby_dir'] : 'd';
                 $mark_read = $this->request->variable('mark', '');
                 $sort_days = $this->request->variable('st', $default_sort_days);
                 $sort_key = $this->request->variable('sk', $default_sort_key);
                 $sort_dir = $this->request->variable('sd', $default_sort_dir);
                 $keep_mark = in_array($mark_read, array('topics', 'topic', 'forums', 'all')) ? (bool) ($user_data['is_registered'] || $config['load_anon_lastread']) : false;
                 $this->core->seo_opt['zero_dupe']['redir_def'] = array('hash' => array('val' => $this->request->variable('hash', ''), 'keep' => $keep_mark), 'f' => array('val' => $this->forum_id, 'keep' => true, 'force' => true), 'st' => array('val' => $sort_days, 'keep' => true), 'sk' => array('val' => $sort_key, 'keep' => true), 'sd' => array('val' => $sort_dir, 'keep' => true), 'mark' => array('val' => $mark_read, 'keep' => $keep_mark), 'mark_time' => array('val' => $this->request->variable('mark_time', 0), 'keep' => $keep_mark), 'start' => array('val' => $this->start, 'keep' => true));
                 $this->core->zero_dupe();
             } else {
                 if ($this->core->seo_opt['redirect_404_forum']) {
                     $this->core->seo_redirect($this->core->seo_path['phpbb_url']);
                 } else {
                     send_status_line(404, 'Not Found');
                 }
             }
             break;
         case 'viewtopic':
             global $topic_data, $topic_replies, $forum_id, $post_id, $view;
             // god save the hax
             if (empty($topic_data)) {
                 if ($this->core->seo_opt['redirect_404_topic']) {
                     $this->core->seo_redirect($this->core->seo_path['phpbb_url']);
                 } else {
                     send_status_line(404, 'Not Found');
                 }
                 return;
             }
             $this->topic_id = $topic_id = (int) $topic_data['topic_id'];
             $this->forum_id = $forum_id;
             $this->core->set_parent_urls($topic_data);
             if (!empty($topic_data['topic_url']) || isset($topic_data['topic_url']) && !empty($this->core->seo_opt['sql_rewrite'])) {
                 if ($topic_data['topic_type'] == POST_GLOBAL) {
                     // Let's make sure user will see global annoucements
                     // $this->auth->cache[$forum_id]['f_read'] = 1;
                     $_parent = $this->core->seo_static['global_announce'];
                 } else {
                     $this->core->prepare_forum_url($topic_data);
                     $_parent = $this->core->seo_url['forum'][$forum_id];
                 }
                 if (!$this->core->check_url('topic', $topic_data['topic_url'], $_parent)) {
                     if (!empty($topic_data['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', '', $topic_data['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($topic_data['topic_title']) : '';
                     }
                     unset($this->core->seo_url['topic'][$topic_id]);
                     $topic_data['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 ($topic_data['topic_url']) {
                         // Update the topic_url field for later re-use
                         $sql = "UPDATE " . TOPICS_TABLE . " SET topic_url = '" . $this->db->sql_escape($topic_data['topic_url']) . "'\n\t\t\t\t\t\t\t\tWHERE topic_id = {$topic_id}";
                         $this->db->sql_query($sql);
                     }
                 }
             } else {
                 $topic_data['topic_url'] = '';
             }
             $this->core->prepare_topic_url($topic_data, $this->forum_id);
             if (!$this->request->is_set('start')) {
                 if (!empty($post_id)) {
                     $this->start = floor($topic_data['prev_posts'] / $this->config['posts_per_page']) * $this->config['posts_per_page'];
                 }
             }
             $start = $this->core->seo_chk_start($this->start, $this->config['posts_per_page']);
             if ($this->start != $start) {
                 $this->start = (int) $start;
                 if (empty($post_id)) {
                     $this->request->overwrite('start', $this->start);
                 }
             }
             $this->core->seo_path['canonical'] = $this->core->drop_sid(append_sid("{$this->phpbb_root_path}viewtopic.{$this->php_ext}", "f={$this->forum_id}&amp;t={$topic_id}&amp;start={$this->start}"));
             if ($this->core->seo_opt['zero_dupe']['on']) {
                 $highlight_match = $highlight = '';
                 if ($this->hilit_words) {
                     $highlight_match = phpbb_clean_search_string($this->hilit_words);
                     $highlight = urlencode($highlight_match);
                     $highlight_match = str_replace('\\*', '\\w+?', preg_quote($highlight_match, '#'));
                     $highlight_match = preg_replace('#(?<=^|\\s)\\\\w\\*\\?(?=\\s|$)#', '\\w+?', $highlight_match);
                     $highlight_match = str_replace(' ', '|', $highlight_match);
                 }
                 if ($post_id && !$view && !$this->core->set_do_redir_post()) {
                     $this->core->seo_opt['zero_dupe']['redir_def'] = array('p' => array('val' => $post_id, 'keep' => true, 'force' => true, 'hash' => "p{$post_id}"), 'hilit' => array('val' => $highlight_match ? $highlight : '', 'keep' => !empty($highlight_match)));
                 } else {
                     $default_sort_days = !empty($user_data['user_topic_show_days']) ? $user_data['user_topic_show_days'] : 0;
                     $default_sort_key = !empty($user_data['user_topic_sortby_type']) ? $user_data['user_topic_sortby_type'] : 't';
                     $default_sort_dir = !empty($user_data['user_topic_sortby_dir']) ? $user_data['user_topic_sortby_dir'] : 'd';
                     $sort_days = $this->request->variable('st', $default_sort_days);
                     $sort_key = $this->request->variable('sk', $default_sort_key);
                     $sort_dir = $this->request->variable('sd', $default_sort_dir);
                     $seo_watch = $this->request->variable('watch', '');
                     $seo_unwatch = $this->request->variable('unwatch', '');
                     $seo_bookmark = $this->request->variable('bookmark', 0);
                     $keep_watch = (bool) ($seo_watch == 'topic' && $user_data['is_registered']);
                     $keep_unwatch = (bool) ($seo_unwatch == 'topic' && $user_data['is_registered']);
                     $keep_hash = (bool) ($keep_watch || $keep_unwatch || $seo_bookmark);
                     $seo_uid = max(0, $this->request->variable('uid', 0));
                     $this->core->seo_opt['zero_dupe']['redir_def'] = array('uid' => array('val' => $seo_uid, 'keep' => (bool) ($keep_hash && $seo_uid)), 'f' => array('val' => $forum_id, 'keep' => true, 'force' => true), 't' => array('val' => $topic_id, 'keep' => true, 'force' => true, 'hash' => $post_id ? "p{$post_id}" : ''), 'p' => array('val' => $post_id, 'keep' => $post_id && $view == 'show' ? true : false, 'hash' => "p{$post_id}"), 'watch' => array('val' => $seo_watch, 'keep' => $keep_watch), 'unwatch' => array('val' => $seo_unwatch, 'keep' => $keep_unwatch), 'bookmark' => array('val' => $seo_bookmark, 'keep' => (bool) ($user_data['is_registered'] && $this->config['allow_bookmarks'] && $seo_bookmark)), 'start' => array('val' => $this->start, 'keep' => true, 'force' => true), 'hash' => array('val' => $this->request->variable('hash', ''), 'keep' => $keep_hash), 'st' => array('val' => $sort_days, 'keep' => true), 'sk' => array('val' => $sort_key, 'keep' => true), 'sd' => array('val' => $sort_dir, 'keep' => true), 'view' => array('val' => $view, 'keep' => $view == 'print' ? (bool) $this->auth->acl_get('f_print', $forum_id) : ($view == 'viewpoll' || $view == 'show' ? true : false)), 'hilit' => array('val' => $highlight_match ? $highlight : '', 'keep' => (bool) (!(!$user_data['is_registered'] && $this->core->seo_opt['rem_hilit']))));
                     if ($this->core->seo_opt['zero_dupe']['redir_def']['bookmark']['keep']) {
                         // Prevent unessecary redirections
                         // Note : bookmark, watch and unwatch cases could just not be handled by the zero dupe (no redirect at all when used),
                         // but the handling as well acts as a security shield so, it's worth it ;)
                         unset($this->core->seo_opt['zero_dupe']['redir_def']['start']);
                     }
                 }
                 $this->core->zero_dupe();
             }
             break;
         case 'memberlist':
             if ($this->request->is_set('un')) {
                 $un = rawurldecode($this->request->variable('un', '', true));
                 if (!$this->core->is_utf8($un)) {
                     $un = utf8_normalize_nfc(utf8_recode($un, 'ISO-8859-1'));
                 }
                 $this->request->overwrite('un', $un);
             }
             break;
     }
 }