Elxis CMS Forum

Support => Elxis 2008 developers guide => Topic started by: datahell on October 04, 2007, 11:50:29

Title: SEO PRO and third party extensions optimization
Post by: datahell on October 04, 2007, 11:50:29
Elxis 2008.x has an advanced build-in SEO (Search Engine Optimization) mechanism, we call SEO PRO.

SEO PRO generates URLs free of any variable. The SEO PRO URLs are consisted from SEO Titles. A SEO Title is an alternative name for an item (content item, section, category etc) valid to be placed in the URL. More on SEO Titles on Elxis 2008.x administration, help and upcoming Elxis's books. To active SEO PRO you must set $mosConfig_sef = 2 (0: no sef, 1: standard sef)

Here are some SEO PRO URL examples for content (SEO titles are marked with green color):

Section table page
section_seotitle/
Category table page
section_seotitle/category_seotitle/
Content item page
section_seotitle/category_seotitle/item_seotitle.html

Suppose we have enable SEO PRO. By doing so, we know the final urls (see above). We don't have to calculate itemids because we don't need them! When we retrieve rows from the database we should also retrieve relative seotitles. I will give you more info and examples bellow but let's look the sef urls generation function (sefRelToAbs) at first.

Elxis 2006.x:
function sefRelToAbs($link)
Elxis 2008.x:
function sefRelToAbs($link, $seolink='')

In Elxis 2008.x if we feed the function's second parameter(seolink) with an already formatted seo link then the function returns the input immediately as output  without having to calculate anything! This leads to great speed improvement! Of course seolinks can also be calculated automatically if we don't feed the second parameter but in this case we lose in performance. So, this is why it is important the SEO PRO optimization we are speaking about.

Definition: SEO PRO optimization is the feed of the sefRelToAbs function with ready to use SEO links.

Lets say we wish to get autonomous pages (typed content items). An autonomous page does not belong to any section or category. Elxis generates links to autonomous pages like this:

www.mysite.com/item_seotitle.html
So we only need to also get the seotitle for the autonomous page and we have ready our SEF link.

$query = "SELECT a.id, a.title, a.seotitle FROM #__content AS a"
. "\n WHERE a.state = '1' AND a.sectionid = '0'"
..........
";
$database->setQuery( $query, '#__', $limit, $limitstart );
$rows = $database->loadObjectList();

manipulate rows and make links to each autonomous page:

foreach ($rows as $row) {
$seolink = $row->seotitle.'.html';
$link = sefRelToAbs("index.php?option=com_content&task=view&id=$row->id&Itemid=$Itemid", $seolink);
echo '<a href="'.$link.'">'.$row->title.'</a><br />';
}


The above will produce a list like this (notice the SEO link):
www.mysite.com/elxis-license.html
www.mysite.com/test.html
www.mysite.com/developing-modules.html
.....

If we needed to work with normal content items we should also get seo titles for sections and categories:
$query = "SELECT a.id, a.title, a.seotitle, a.sectionid, a.catid, cc.seotitle AS seocat, s.seotitle AS seosec"
."\n FROM #__content AS a"
."\n LEFT JOIN #__content_frontpage AS f ON f.content_id = a.id"
."\n INNER JOIN #__categories AS cc ON cc.id = a.catid"
."\n INNER JOIN #__sections AS s ON s.id = a.sectionid"
."\n WHERE a.state = '1' AND a.sectionid > '0'"
.........

and create links like this:
$seolink = $row->seosec.'/'.$row->seocat.'/'.$row->seotitle.'.html';

For other components we use a similar technic. Every SEO PRO link exists in Elxis 2008.x SEO class file. SEO PRO also accepts extensions for third party software.

Some other features of SEO PRO
1. Ajax based SEO title suggestion feature
2. Ajax based SEO title validation feature
3. SEO titles validation upon saving.
4. Automatic SEO title alternation (adds a numeric suffix, e.g. seotitle-2) upon copy or move (if needed - because system does not allow e.g. 2 items to have same seotitles inside the same category ).
5. Available for ALL Elxis core components
6. Very easy to administer, you don't have special configuration pages etc. Just enable/disable, nothing more! Elxis does all the hard work automatically.
7. You don't need to update htaccess file.
8. Free GNU/GPL buildin in Elxis 2008.x!
9. Backwards compatible. You can use standard SEF (mosConfig_sef=1) if you wish to use a third party sef solution or you like more the old way ( why? ).
10. Search engine friendly URLs.
11. Human friendly URLs (provides tree structured URLs)
12. Created by Elxis Team/GO UP Inc. Available only for Elxis CMS.
13. IIS (windows) compatible with Ionic Isapi Rewrite.
Title: Re: SEO PRO and third party extensions optimization
Post by: datahell on October 04, 2007, 12:32:52
Here is a short guide for SEO PRO extensions creation.

We create a php file having the same name as ours component (e.g. com_xxxxxx).
When finish we will place this file inside /includes/seopro/ folder.
Each SEO PRO extension file must contain at least two functions, one for SEO links generation and another one for original links restoration.
The names of these function should follow our component name.

function seogen_com_xxxxxx($link) {
// seo link generation, must output the final seo link
}

function seores_com_xxxxxx($seolink='') {
// original link restoration, must find and load needed variables as the original non-sef url would do
}

You are free to write anything inside these functions and create any SEF links you wish (make attention not to conflict with core links).

Here is an example of SEO link generation from component wrapper:

Code: (php) [Select]
<?php 
/*********************/
/* GENERATE SEO LINK */
/*********************/
function seogen_com_wrapper($link) {
global $mosConfig_live_site$database;

if (trim($link) == &#39;&#39;) { return &#39;&#39;; }
//index.php?option=com_wrapper&Itemid=xx
$vars = array();
$half preg_split(&#39;/[\?]/&#39;, $link);
if (isset($half[1])) {
$half2 preg_split(&#39;/[\#]/&#39;, $half[1]);
$parts preg_split(&#39;/[\&]/&#39;, $half2[0], -1, PREG_SPLIT_NO_EMPTY);
if (count($parts) >0) {
foreach ($parts as $part) {
list($x$y) = preg_split(&#39;/[\=]/&#39;, $part, 2);
$x strtolower($x);
$vars[$x] = $y;
}
}
}

if (isset($vars[&#39;itemid&#39;])) {
        
$_Itemid intval($vars[&#39;itemid&#39;]);
        
if ($_Itemid) {
            
$database->setQuery("SELECT seotitle FROM #__menu WHERE id=&#39;$_Itemid&#39; AND published=&#39;1&#39;", &#39;#__&#39;, 1, 0);
            
$seotitle $database->loadResult();
            if (
$seotitle && ($seotitle != &#39;&#39;)) {
                
return $mosConfig_live_site.&#39;/ext/&#39;.$seotitle.&#39;.html&#39;; 
            
}
        }
    }
    return 
sefstdRelToAbs($link);
}
?>


See the standard (core) extensions as examples to create your own SEO PRO extensions.