Topic: Link details pages

I did a mod to the link details extension to give sef urls as below.

<hook id="link_row_footer">
- <![CDATA[ 
                echo '<br /><a href="' .$settings['domain']. '/details/' .$links['id']. "/". $links['title'].'">Details</a>';
            

  ]]> 
  </hook>

Also needs this in the htaccess file

RewriteRule ^details/([0-9]+)/(.+)$ index.php?details=$1&category=$2

Maybe someone could include this properly in the releases so users can turn it on/off

Re: Link details pages

Cool -- I give it a shot if anders hasn't approved it yet or put it in the latest branch.

http://www.optimseo.com - Directory Owners Forum

Re: Link details pages

oh -- the .htaccess gets automatically generated, when you edit options -- you should add it to the  sef layers ... path is something like: ./include/sef/defaut.php or something. There is an array of what basically equate to rewrite rules (as you have).

http://www.optimseo.com - Directory Owners Forum

Re: Link details pages

There's currently no simple way to generate own rewrite-rules&links from an extension.

Maybe some htaccess_build(array()) function could be useful.

Re: Link details pages

The current seflayers might look more like this in OpenLD 1.3, just a suggestion.

class RewriteLayer
{
    var $htaccess_text = null;
    var $rules = array();
    var $openld_urls = array();


    //constructor
    function RewriteLayer()
    {
        
    }


    //private methods
    function set_rule($item, $rule, $url)
    {
        $this->rules[$item] = $rule;
        $this->openld_url[$item] = $url;
    }


    //public methods
    function add_rule($item, $rule, $url)
    {
        if(!isset($this->rules[$item]) && !isset($this->openld_url[$item]))
            $this->set_rule($item, $rule, $url);
        else
            error('Rule item and/or openld_url is already set Method: add_rule(' .$item. ', ' .$rule. ', ' .$url.')', __FILE__, __LINE__);
    }


    function change_rule($item, $rule, $url)
    {
        if(isset($this->rules[$item]) && isset($this->openld_url[$item]))
            $this->set_rule($item, $rule, $url);
        else
            error('Rule item and/or openld_url is not set Method: change_rule(' .$item. ', ' .$rule. ', ' .$url.')', __FILE__, __LINE__);
    }


    function remove_rule($item)
    {
        if(!isset($this->rules[$item]) || !isset($this->openld_url[$item])
        {
            unset($this->rules[$item]);
            unset($this->openld_url[$item]);
        }
        else
            error("one or two of the items is not set", __FILE__, __LINE__);
    }
//half-way

    //function htaccess_build(array $rules)
    function set_htaccess_text($text)
    {
        $this->htaccess_text = $text;
    }


    function output_htaccess()
    {
        $fh = @fopen(OPENLD_ROOT.'.htaccess', 'wb');
        if (!$fh)
            error("Couldn't edit .htaccess.. ensure that permissions are set to 755 for the root directory");
        if($this->htaccess_text != null)
        {
            fwrite($fh, $this->htaccess_text);
            fclose($fh);
        }
        else
            error("htaccess must be set", __FiLE__, _LINE__);
    }
    
//old
    function se_suggest($arg_array)
    {
        if(isset($arg_array['id']) && isset($arg_array['category']))
            return array($arg_array['id'], str_replace(' ', '-', $arg_array['category']));

        $this->openld_url['suggest'] = 'suggest_category.php';
        return null;
    }


    function se_submit($arg_array)
    {
        if(isset($arg_array['id']) && isset($arg_array['category']))
            return array($arg_array['id'], str_replace(' ', '-', $arg_array['category']));

        $this->openld_url['submit'] = 'submit.php';
        return null;
    }


    function se_index_cat($arg_array)
    {
        if(isset($arg_array['id']) && isset($arg_array['title']))
            return array($arg_array['id'], str_replace(' ', '-', $arg_array['title']));

        $this->openld_url['index_cat'] = 'index.php';
        return null;
    }


    function se_search($arg_array)
    {
        //escape before function in parameter
        //global $db;
        //$arg_array = $db->escape_array($arg_array);

        if(isset($arg_array['term']) && isset($arg_array['search_in']) && isset($arg_array['sort_by']) && isset($arg_array['search_type']))
            return array($arg_array['term'], $arg_array['search_in'], $arg_array['sort_by'], $arg_array['search_type']);

        $this->openld_url['search'] = 'search.php';
        return null;
    }
}

$urls = new RewriteLayer();
$urls->add_rule(
    'index_cat',
    '^(.+)-([0-9]+)$ index.php?id=$2&category=$1',
    '#2-#1');
$urls->add_rule(
    'index_cat_page',
    '^(.+)-([0-9]+)/([0-9]+)$ index.php?id=$2&category=$1&page=$3',
    '#2-#1/#p');
$urls->add_rule(
    'search',
    '^(.+)/(.+)/(.+)/(.+)-search$ search.php?term=$1&search_in=$2&sort_by=$3&search_type=$4',
    '#1/#2/#3/#4-search'
);
$urls->add_rule(
    'search_page',
    '^(.+)/(.+)/(.+)/(.+)-search/([0-9]+)$ search.php?term=$1&search_in=$2&sort_by=$3&search_type=$4&page=$5',
    '#1/#2/#3/#4-search/#p'
);
$urls->add_rule(
    'suggest',
    '^(.+)-([0-9]+)-suggest$ suggest_category.php?id=$2&category=$1',
    '#2-#1-suggest'
);
$urls->add_rule(
    'submit',
    '^(.+)-([0-9]+)-submit$ submit.php?cat_id=$2&category=$1',
    '#2-#1-submit'
);
$urls->set_htaccess_text('Options +FollowSymlinks\nRewriteEngine On\n\n'.implode('\nRewriteRule ',$urls->rules));
$urls->output_htaccess();