Skip to content

Commit

Permalink
Merge pull request #41 from dcz/ticket/17
Browse files Browse the repository at this point in the history
[ticket/17] rewrite without forum cache
  • Loading branch information
dcz committed Sep 11, 2014
2 parents 08a7b50 + b1e27d8 commit 54f7e14
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 18 deletions.
23 changes: 21 additions & 2 deletions core.php
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,7 @@ public function __construct(\phpbb\config\config $config, \phpbb\request\request
// $1 parent : string/
// $2 title / url : topic-title / forum-url-fxx
// $3 id
$this->sftpl = array_merge(
$this->sftpl = array_replace(
array(
'topic' => ($this->seo_opt['virtual_folder'] ? '%1$s/' : '') . '%2$s' . $this->seo_delim['topic'] . '%3$s',
'topic_smpl' => ($this->seo_opt['virtual_folder'] ? '%1$s/' : '') . $this->seo_static['topic'] . '%3$s',
Expand Down Expand Up @@ -608,12 +608,31 @@ public function set_url($url, $id = 0, $type = 'forum', $parent = '')
{
if (empty($this->seo_url[$type][$id]))
{
return ($this->seo_url[$type][$id] = !empty($this->cache_config[$type . '_urls'][$id]) ? $this->cache_config[$type . '_urls'][$id] : sprintf($this->sftpl[$type], $parent, $this->format_url($url, $this->seo_static[$type]) . $this->seo_delim[$type] . $id, $id));
return ($this->seo_url[$type][$id] = !empty($this->cache_config[$type . '_urls'][$id]) ? $this->cache_config[$type . '_urls'][$id] : sprintf($this->sftpl[$type], $this->format_url($url, $this->seo_static[$type]) . $this->seo_delim[$type] . $id, $id));
}

return $this->seo_url[$type][$id];
}

/**
* set_parent_urls(array & $forum_data)
* set/check urls of current forum's parent(s)
*/
public function set_parent_urls(&$forum_data)
{
if (!empty($forum_data['forum_parents']))
{
$forum_parents = @unserialize($forum_data['forum_parents']);
if (!empty($forum_parents))
{
foreach ($forum_parents as $fid => $data)
{
$this->set_url($data[0], $fid, 'forum');
}
}
}
}

/**
* prepare_url($type, $title, $id, $parent = '', $smpl = false)
* Prepare url first part
Expand Down
41 changes: 25 additions & 16 deletions event/listener.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,19 +93,19 @@ public function __construct(\phpbbseo\usu\core $core, \phpbb\config\config $conf
public static function getSubscribedEvents()
{
return array(
'core.common' => 'core_common',
'core.page_header_after' => 'core_page_header_after',
'core.page_footer' => 'core_page_footer',
'core.user_setup' => 'core_user_setup',
'core.viewforum_modify_topicrow' => 'core_viewforum_modify_topicrow',
'core.viewtopic_modify_page_title' => 'core_viewtopic_modify_page_title',
'core.viewtopic_modify_post_row' => 'core_viewtopic_modify_post_row',
'core.memberlist_view_profile' => 'core_memberlist_view_profile',
'core.modify_username_string' => 'core_modify_username_string',
'core.append_sid' => 'core_append_sid',
'core.submit_post_end' => 'core_submit_post_end',
'core.posting_modify_template_vars' => 'core_posting_modify_template_vars',
'core.display_user_activity_modify_actives' => 'core_display_user_activity_modify_actives',
'core.common' => 'core_common',
'core.page_header_after' => 'core_page_header_after',
'core.page_footer' => 'core_page_footer',
'core.user_setup' => 'core_user_setup',
'core.viewforum_modify_topicrow' => 'core_viewforum_modify_topicrow',
'core.viewtopic_modify_page_title' => 'core_viewtopic_modify_page_title',
'core.viewtopic_modify_post_row' => 'core_viewtopic_modify_post_row',
'core.memberlist_view_profile' => 'core_memberlist_view_profile',
'core.modify_username_string' => 'core_modify_username_string',
'core.append_sid' => 'core_append_sid',
'core.submit_post_end' => 'core_submit_post_end',
'core.posting_modify_template_vars' => 'core_posting_modify_template_vars',
'core.display_user_activity_modify_actives' => 'core_display_user_activity_modify_actives',
);
}

Expand Down Expand Up @@ -138,8 +138,12 @@ public function core_user_setup($event)
$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}&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';
Expand All @@ -152,7 +156,7 @@ public function core_user_setup($event)

$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),
'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),
Expand All @@ -176,6 +180,7 @@ public function core_user_setup($event)
}

break;

case 'viewtopic':
global $topic_data, $topic_replies, $forum_id, $post_id, $view; // god save the hax

Expand All @@ -195,6 +200,8 @@ public function core_user_setup($event)
$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)
Expand All @@ -206,8 +213,8 @@ public function core_user_setup($event)
}
else
{
$this->core->set_url($topic_data['forum_name'], $forum_id, 'forum');
$_parent = $this->core->seo_url['forum'][$topic_data['forum_id']];
$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))
Expand Down Expand Up @@ -323,6 +330,7 @@ public function core_user_setup($event)
}

break;

case 'memberlist':
if ($this->request->is_set('un'))
{
Expand Down Expand Up @@ -376,6 +384,7 @@ public function core_common($event)
}

break;

case 'viewtopic':
$this->forum_id = max(0, $this->request->variable('f', 0));
$this->topic_id = max(0, $this->request->variable('t', 0));
Expand Down

0 comments on commit 54f7e14

Please sign in to comment.