Actinic – Bypass the CGI-Bin numeric links and get SEO Friendly Links

Include this code at the end of your actinic_main.php then restart actinic.

***************************************************************
* GetSectFileName - A support function for Ref2File
***************************************************************/ 
function GetSectFileName($sectref)
    {
        $connect = odbc_connect("ActinicCatalog8","","");
        $query = "SELECT [sPageName] FROM [Catalog Section] WHERE [nSectionID]=".$sectref."";
        $result = odbc_exec($connect, $query);
        while(odbc_fetch_row($result)){
            //$name = odbc_result($result, 2);
            $url = odbc_result($result, 1);
        }
        odbc_close($connect);
            return $url;
    } 
/***************************************************************
* GetProdParent - A support function for Ref2File
***************************************************************/
function GetProdParent($prodrefs)
    {
    $prodrefs = str_replace("{","",$prodrefs);
    $prodrefs = str_replace("}","",$prodrefs);
        $connect = odbc_connect("ActinicCatalog8","","");
        $query = "SELECT [nParentSectionID] FROM [product] WHERE [Product Reference]='".$prodrefs."'";
        $result = odbc_exec($connect, $query);
        while(odbc_fetch_row($result)){
            $parentid = odbc_result($result, 1);
        }
        odbc_close($connect);
            return $parentid; 
        } 
/***************************************************************
* GetSectParent- A support function for Ref2File
***************************************************************/
function GetSectParent($sectrefs)
    {
    $prodrefs = str_replace("{","",$sectrefs);
    $prodrefs = str_replace("}","",$sectrefs);
        $connect = odbc_connect("ActinicCatalog8","","");
        $query = "SELECT [nParentSectionID] FROM [Catalog section] WHERE [nSectionID]=".$sectrefs."";
        $result = odbc_exec($connect, $query);
        while(odbc_fetch_row($result)){
            $parentid = odbc_result($result, 1);
        }
        odbc_close($connect);
            return $parentid;
        } 
/***************************************************************
* Ref2file - Use Actinic's pwn database, to convert a prod ref, to a filename
* @param int $ref the product reference.
* @author Gabriel Crowe + NormanRouxel 08 September 2007
*
* usage example:
<a href="<actinic:variable name="CatalogURL" /><actinic:block php=">true< span class="phpString">">echo Ref2file("<actinic:variable Name="ProductReference" />");</actinic:block>">Link Text</a>
***************************************************************/ 
function Ref2File($ref) {

return GetSectFileName(GetProdParent($ref));
}
function Ref2ParentFile($ref) {

return GetSectFileName(GetSectParent(GetProdParent($ref)));
}

To use this in your Actinic template:

<a href="<actinic:variable name="CatalogURL" /><actinic:block php="true">echo Ref2file("<actinic:variable Name="ProductReference" />");</actinic:block>">Link Text</a>

To get the parent of the section your item is in (for single product per page lists) then make a link like this:

<a href="<actinic:variable name="CatalogURL" /><actinic:block php="true">echo Ref2ParentFile("<actinic:variable Name="ProductReference" />");</actinic:block>">Link Text</a>

This will traverse up another level.

what does the code do? basically, it uses actinics own database to find the name of the section that pertains to a product. by using the product reference. The code may cause some slowdown on larger shops, but really, all it does is convert the prodref, to the filename online.

Originally posted here:
http://community.actinic.com/showthread.php?t=34301