Knowledge Base

e_url.php [part n.1]

How I try to use e_url.php on maybe most complicated old plugin
on Sunday 15 July 2018
comments: 0

Official documentation:

It provides a simple way to add mod-rewrite redirects to your plugin's page, without having to edit the .htaccess file. To create search-engine-friendly URLs which utilize this add-on, please see the e107::url() method.

class myplugin_url  
	function config() 
		$config = array();
		$config[] = array(
			'regex'			=> '^myplugref-(.*)/?$',
			'redirect'		=> 'e107_plugins/myplugin/ref.php?ref=$1',
		return $config;

Using: e107::url('other',$row);
where $row is array of values needed to generate correct SEF-URL. If they are missing, SEF-URL is not used.

Content plugin

Why I use content plugin? Because it is written old way where everything is set by urls parameters.

What simple rewriting means with old plugin?
1. To set correct rewrite rules in meaning that if you use them manually, correct content will be displayed
2. To fix problems before actual changing used urls (changing related path to absolute)
3. To solve how value of SEF-URL will be managed (generated, new field etc)
4. To solve problem of double content (in case that both version are working together)
5. Replace old ulrs with e107::url();

1. To set correct rewrite rules

It means to analyze how legacy urls work. In fact old urls were created with more logic and they had more understandable rules than new plugins have now.

e_PAGE is filled
e_QUERY is filled
as soon as you add e_url.php, e_LEGACY _URL is filled too
: now if you use SEF-URL, e_PAGE is not defined. There is no rule for this.

e_LEGACY_URL is in fact value you have set in 'redirect' field.

Now, what values can e_PAGE to have in content plugin? Only content.php and content_manager.php

All others urls are set by e_QUERY (categories, authors, comments etc), so everything can be done by simple settings:

After you know (or you still quess) how it should work, create content_url class in e_url.php file
(you need to run Plugin scan after adding it)

class content_url
	function config()
		$config = array();
    $config['content_manager'] = array(
		'regex'    => '^content_manager/(.*)',
		'sef'      => 'content_manager/{content_query}',
		'redirect' => 'e107_plugins/content/content_manager.php$1'
    $config['content'] = array(
    'alias'         => '{alias}',
		'regex'    => '^{alias}/(.*)/(.*)',
		'sef'      => '{alias}/{content_sef}/{content_query}',
		'redirect' => 'e107_plugins/content/content.php$2'
    $config['content-temp'] = array(
    'alias'         => '{alias}',
		'regex'    => '^{alias}/(.*)',
		'sef'      => '{alias}/{content_query}',
		'redirect' => 'e107_plugins/content/content.php$1'
    $config['index'] = array(
    'alias'         => '{alias}',
		'regex'    => '^{alias}\/?$',
		'sef'      => '{alias}',
		'redirect' => 'e107_plugins/content/content.php'
  return $config;

- in fact you don't need pretty urls for content manager, because it's accessible only for manager classes. But it's easier this way (to do everything, not just part of content)
- because the same reason content manager uses simplier version - no alias, no sef version
- content-temp version is temporalily solution before adding SEF-URL field
- {alias} is used for posibility to used different word than content in url root (f.e. knowledge_base). On multilang site it can be different for each language.

Where to set aliases:

2. To fix problems before actual changing used urls

* replace

* replace e_PLUGIN with e_PLUGIN_ABS for all images and inserted urls. Do this one by one, where you notice wrong url. Replace in bulk could cause more issues that fix.

<a href='".e_PLUGIN  -  to <a href='".e_PLUGIN_ABS

* replace e_SELF with e_HTTP

* check all using of e_PAGE - with SEF-URL is not filled anymore.

This could be fixed very easy in e_meta.php and now e_PAGE is filled as should be:

if(defined("e_URL_LEGACY")) { 
   if (strpos(e_URL_LEGACY, 'content.php') !== false)     {
    define("e_PAGE", 'content.php');
   elseif (strpos(e_URL_LEGACY, 'content_manager.php') !== false)     {
     define("e_PAGE", 'content_manager.php');

you can now manually check your future urls:


So in this point rewriting works, now it's needed to solve the rest.