Rewriting empty topic-urls - working suggestion

phpBB3 SEO Mixed mod Rewrite support forum. This mods performs URL rewriting for phpBB3, injecting forums in their URLs and keeping a static rewriting for topics.

Moderator: Moderators

Rewriting empty topic-urls - working suggestion

Postby Versus » Wed Feb 17, 2010 11:04 am

Hi guys,

I have faced a problem that when I set up the phpBB SEO in mixed mode, all my topics do not have any URL, obviously.
Thus, all of them are shown as /forum-URL/topic#####.html
which is good, but not good enough for me.

Question1:
Can I make phpBB SEO rewrite all topic-URL accoding to Subjects of topics translating and modifying them as necessary (as set up in setup_phpbb_seo.php)?
Only if the topic URL is not set manually.
SQL rewrite is ON.

----

Temporarily I did the following:

1) Hide URL field from non-moderators
It is said in the phpBb SEO ACP that SQL rewiting is available to moderators and admins only, but it is not as I can see from the template. My patch hides the URL field from non-moderators.
in template subsilver2 posting_body.html I show URL field only to moderators. So, users can't set or edit topic URL - it shoudl be generated automatically. While moderators can do it manually.
Code: Select all
<!-- IF S_URL and U_MCP -->
<tr>
   <td class="f" colspan="3">
      <b class="genmed">URL:</b>
      <input class="post" style="width:450px" type="text" name="url" size="45" maxlength="250" tabindex="2" value="{TOPIC_URL}" />
   </td>
</tr>
<!-- ENDIF -->

I had to modify posting.php to pass U_MCP to the template:
Code: Select all
$template->assign_vars(array(
   'U_MCP'       => ($auth->acl_get('m_', $forum_id)) ? append_sid("{$phpbb_root_path}mcp.$phpEx", "i=main&amp;mode=topic_view&amp;f=$forum_id&amp;t=$topic_id&amp;start=$start" . ((strlen($u_sort_param)) ? "&amp;$u_sort_param" : ''), true, $user->session_id) : '',


2) Setting good default URL for new topics
If the topic URL remains empty after editing, it is generated automatically from the Subject. Since my forum is in Russian, all national symbols are translated into latin characters.

Code: Select all
   // www.phpBB-SEO.com SEO TOOLKIT BEGIN
   if (!empty($phpbb_seo->seo_opt['sql_rewrite'])) {
      if ($mode == 'post' || ($mode == 'edit' && $post_data['topic_first_post_id'] == $post_id)) {
         $phpbb_seo->set_url($post_data['forum_name'], $forum_id, $phpbb_seo->seo_static['forum']);
         $_parent = $post_data['topic_type'] == POST_GLOBAL ? $phpbb_seo->seo_static['global_announce'] : $phpbb_seo->seo_url['forum'][$forum_id];
         $_t = !empty($post_data['topic_id']) ? max(0, (int) $post_data['topic_id'] ) : 0;      
         
         //Added by Versus - start
         // Overriding empty URL fields
         if ($_REQUEST['url']==''){$_REQUEST['url']=$_REQUEST['subject'];}
         //Added by Versus - end
         
// next line is amended by Versus
         $_url = $phpbb_seo->url_can_edit($forum_id) ? utf8_normalize_nfc(request_var('url', '', true)) : ( isset($post_data['topic_url']) ? $post_data['topic_url'] : utf8_normalize_nfc(request_var('url', '', true)) );
         if (!$phpbb_seo->check_url('topic', $_url, $_parent)) {
            if (!empty($_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('`' . $phpbb_seo->seo_delim['topic'] . '$`i', '', $_url);
               $_title = $phpbb_seo->get_url_info('topic', $_url . $phpbb_seo->seo_delim['topic'] . $_t);
            } else {
               $_title = $phpbb_seo->modrtype > 2 ? censor_text($post_data['post_subject']) : '';
            }
            unset($phpbb_seo->seo_url['topic'][$_t]);
            $_url = $phpbb_seo->get_url_info('topic', $phpbb_seo->prepare_url( 'topic', $_title, $_t, $_parent ,  (( empty($_title) || ($_title == $phpbb_seo->seo_static['topic']) ) ? true : false)), 'url');
            unset($phpbb_seo->seo_url['topic'][$_t]);
         }
         $post_data['topic_url'] = $_url;
      }
   }
   // www.phpBB-SEO.com SEO TOOLKIT END




What do you say?
Is it good?
Any other good solution for that?
Versus
 
Posts: 2
Joined: Wed Feb 17, 2010 10:34 am

Advertisement

Re: Rewriting empty topic-urls - working suggestion

Postby dcz » Fri Mar 12, 2010 4:05 pm

Well, if you always want to inject topic title, use the advanced mode (and if you do so, you will have to re sync all topic urls with sql rewriting, but they will be redirected without further effort with the zero dupe).

And, he topic url field is only shown (and usable) by admins and moderator (of the forum where the topic is posted) by default, it's dealt with in phpbb_seo::url_can_edit :
Code: Select all
   /**
   * Returns true if the user can edit urls
   * @access public
   */
   function url_can_edit($forum_id = 0) {
      global $user, $auth;
      if (empty($this->seo_opt['sql_rewrite']) || empty($user->data['is_registered'])) {
         return false;
      }
      if ($auth->acl_get('a_')) {
         return true;
      }
      // un comment to grant url edit perm to moderators in at least a forums
      /*if ($auth->acl_getf_global('m_')) {
         return true;
      }*/
      $forum_id = max(0, (int) $forum_id);
      if ($forum_id && $auth->acl_get('m_', $forum_id)) {
         return true;
      }
      return false;
   }


++
Useful links :
SEO Forum || SEO Directory || SEO phpBB || Search
____________________

Liens Utiles :
Forum référencement || Annuaire référencement || Référencement phpBB || Recherche
dcz
Admin
Admin
 
Posts: 21219
Joined: Fri Apr 28, 2006 9:03 pm


Return to Mixed SEO URL

 


  • Related topics
    Replies
    Views
    Last post

Who is online

Users browsing this forum: No registered users and 5 guests