RELATEDX

{RELATEDX:list_count_:keywords:cat-ID}

Enhanced by KH (flip-flop)

Docu: http://www.phpwcms-docu.de/link_tags.phtml

Forum: –

Tag: {RELATEDX:list_count_:keywords:category-ID} is an “cut out frontend snippet” enhanced for a search behind a given level. You can use it e.g. for multilingual sites.

Filename: rt_relatedx.php

Location: /template/inc_script/frontend_render/rt_relatedx.php

Condition: $phpwcms['allow_ext_render'] = 1;/config/phpwcms/conf.inc.php




Please always fill out all fields: e.g.

  • {RELATEDX:0:tip,top,flip,flop:0}Search beginning behind cad-ID=0 = home
  • {RELATEDX:5:tip,top,flip,flop:2}Output first 5 entries, search beginning behind cad-ID=2

E.g.:

Given structure

------------------------------------
L  E  V  E  L
.:  :  :  :
.0  1  2  3   <- LEVEL-Nr.
.:  :  :  :
-+ home   :                    ID=0
-+--+ category_01              ID=01
-+--+ category_02              ID=02
-+--+--+ category_02_01        ID=04
-+--+--+--+ category_02_01_01  ID=06
-+--+--+--+ category_02_01_02  ID=07
-+--+--+ category_02_01        ID=05
-+--+--+ category_02_02        ID=08
-+--+ category_03              ID=03
-+--+ category_04              ID=09
.:  :  :  :
.0  1  2  3   <- LEVEL Nr.
------------------------------------

{RELATEDX:5:tip,top,flip,flop:2} → Output: The title link of the first five visible keyword matched articles, behind category_02 (ID=2).


{RELATEDX:count:key words:category-ID}

<?php
/*************************************************************************************
   Copyright notice
 
   (c) 2002-2008 Oliver Georgi (oliver@phpwcms.de) // All rights reserved.
 
   This script is part of PHPWCMS. The PHPWCMS web content management system is
   free software; you can redistribute it and/or modify it under the terms of
   the GNU General Public License as published by the Free Software Foundation;
   either version 2 of the License, or (at your option) any later version.
 
   The GNU General Public License can be found at http://www.gnu.org/copyleft/gpl.html
   A copy is found in the textfile GPL.txt and important notices to the license
   from the author is found in LICENSE.txt distributed with these scripts.
 
   This script is distributed in the hope that it will be useful, but WITHOUT ANY
   WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
   PARTICULAR PURPOSE.  See the GNU General Public License for more details.
 
   This copyright notice MUST APPEAR in all copies of the script!
 
-------------------------------------------------------------------------------------
15.03.09 KH (flip-flop) RT RELATED cut out (frontend snippet)
   {RELATEDX:count:key word´s:category-ID}
...Please always fill out all fields: e.g.
   {RELATEDX:0:tip,top,flip,flop:0}  -> Search beginning behind cad-ID=0 = home
   {RELATEDX:5:tip,top,flip,flop:2}  -> Output first 5 entries, search beginning behind cad-ID=2
 
*************************************************************************************/
// ----------------------------------------------------------------------------------
// obligate check for phpwcms constants
if (!defined('PHPWCMS_ROOT')) {die("You Cannot Access This Script Directly, Have a Nice Day.");}
// ----------------------------------------------------------------------------------
 
 
 
// related articles based on keywords, inspired by Magnar Stav Johanssen
if(strpos($content["all"],'{RELATEDX:') !== false) {
 
    if (!$no_content_for_this_page && !empty($content["articles"][$aktion[1]]["article_keyword"])) {
        $related_keywords = $content["articles"][$aktion[1]]["article_keyword"];
    } else {
        $related_keywords = '';
    }
    $content["all"] = preg_replace('/\{RELATEDX:(\d+)\}/e','my_get_related_articles($related_keywords,$aktion[1],$template_default["related"],"$1",$db);',$content["all"]);
    $content["all"] = preg_replace('/\{RELATEDX:(\d+):(.*?):(\d+)\}/e','get_related_articles("$2",$aktion[1],$template_default["related"],"$1",$db, "$3");',$content["all"]);
 
 
// -------------------------------------------------------------
 
 
// $content["all"] = preg_replace('/\{RELATEDX:(\d+):(.*?):(\d+)\}/e','my_get_related_articles("$2",$GLOBALS["aktion"][1],$GLOBALS["template_default"]["related"],"$1",$GLOBALS["db"], "$3");',$content["all"]);
 
 
 
function buildStruct_TopDown($start=0) {
 
    static $my_cat_id = '';
 
    $struct = getStructureChildData($start);
 
    foreach($struct as $value) {
 
        buildStruct_TopDown($value['acat_id']);
        $my_cat_id .= $my_cat_id != '' ? ','.$value['acat_id'] : $value['acat_id'];
 
//        echo  '||'.$value['acat_id'].' ,';
 
    }
 
return $my_cat_id;
 
}
 
// =================================================================
 
function my_get_related_articles($keywords, $current_article_id, $template_default, $max_cnt_links=0, $dbcon ,$cat_id) {
    // find keyword for current article used for RELATED replacementtag
    // prepared and inspired by Magnar Stav Johanssen
 
    $cat_id = buildStruct_TopDown($cat_id);  // find all permitted IDs behind $cat_id
 
 
    $keyword_links = "";
    $max_cnt_links = intval($max_cnt_links);
 
    $keywords = str_replace("ALLKEYWORDS", $GLOBALS['content']['all_keywords'].',', $keywords);
 
    // replace unwanted chars and convert to wanted
    $keywords = str_replace(";", ",", $keywords);
    $keywords = str_replace("'", "", $keywords);
    $keywords = str_replace(" ", ",", $keywords);
    $keywords = str_replace(",,", ",", $keywords);
 
    // choose comma separated keywords
    $keywordarray = explode (",", $keywords);
    $keywordarray = array_map('trim', $keywordarray);
    $keywordarray = array_diff($keywordarray, array(''));
    $keywordarray = array_unique($keywordarray);
    $keywordarray = array_map('strtoupper', $keywordarray);
    // check for empty keywords or keywords smaller than 3 chars
    if(is_array($keywordarray) && count($keywordarray)) {
        foreach($keywordarray as $key => $value) {
 
            if(substr($keywordarray[$key], 0, 1) == '-') {
                $doNotUse = substr($keywordarray[$key], 1);
                foreach($keywordarray as $key2 => $value2) {
                    if($doNotUse == $value2) {
                        unset($keywordarray[$key2]);
                        unset($keywordarray[$key]);
                    }
                }
            }
 
            if(isset($keywordarray[$key]) && (strlen($keywordarray[$key]) < 3 || empty($keywordarray[$key]))) {
                unset($keywordarray[$key]);
            }
        }
    }
 
    if(is_array($keywordarray) && count($keywordarray)) {
        $where = "";
        foreach($keywordarray as $value) {
                //build where keyword = blabla
                $where .= ($where) ? " OR " : "";
                //replace every "'" to "''" for security reasons with aporeplace()
                $where .= "article_keyword LIKE '%".aporeplace($value)."%'";
        }
        $limit = ($max_cnt_links) ? " LIMIT ".$max_cnt_links : "";
        $sql  =    "SELECT article_id, article_title, article_cid, article_subtitle, article_summary, article_alias ";
        $sql .=    "FROM ".DB_PREPEND."phpwcms_article WHERE article_deleted=0 AND ";
        $sql .=    "article_id<>".intval($current_article_id)." AND ";
        $sql .=    "article_cid IN (".$cat_id.") AND ";
        // VISIBLE_MODE: 0 = frontend (all) mode, 1 = article user mode, 2 = admin user mode
        switch(VISIBLE_MODE) {
            case 0: $sql .=    "article_public=1 AND article_aktiv=1 AND ";
                    break;
            case 1: $sql .= "article_uid=".$_SESSION["wcs_user_id"]." AND ";
                    break;
            //case 2: admin mode no additional neccessary
        }
        $sql .=    "article_begin < NOW() AND article_end > NOW() AND (".$where.") ";
 
        if(empty($template_default['sort_by'])) $template_default['sort_by'] = '';
 
        switch($template_default['sort_by']) {
 
            case 'title_asc':
                        $sql .=    "ORDER BY article_title";
                        break;
 
            case 'title_desc':
                        $sql .=    "ORDER BY article_title DESC";
                        break;
 
            case 'ldate_asc':
                        $sql .=    "ORDER BY article_begin";
                        break;
 
            case 'ldate_desc':
                        $sql .=    "ORDER BY article_begin DESC";
                        break;
 
            case 'kdate_asc':
                        $sql .=    "ORDER BY article_end";
                        break;
 
            case 'kdate_desc':
                        $sql .=    "ORDER BY article_end DESC";
                        break;
 
            case 'cdate_asc':
                        $sql .=    "ORDER BY article_created";
                        break;
 
            case 'cdate_desc':
                        $sql .=    "ORDER BY article_created DESC";
                        break;
 
            default:
                        $sql .=    "ORDER BY article_tstamp DESC";
        }
 
        $sql .= $limit;
 
        // related things
        $target = ($template_default["link_target"]) ? ' target="'.$template_default["link_target"].'"' : "";
        if($result = _dbQuery($sql)) {
            $count_results = count($result);
            $count = 0;
 
 
            foreach($result as $value) {
                $count++;
                if($template_default["link_length"] && strlen($value['article_title']) > $template_default["link_length"]) {
                    $article_title = substr($value['article_title'], 0, $template_default["link_length"]).$template_default["cut_title_add"];
                } else {
                    $article_title = $value['article_title'];
                }
 
                $keyword_links .= $template_default["link_before"].$template_default["link_symbol"];
                $keyword_links .= '<a href="index.php?id='.$value['article_cid'].','.$value['article_id'].',0,0,1,0"';
                $keyword_links .= $target.">".html_specialchars($article_title)."</a>";
 
                //try to remove possible unwanted after - if not enclosed before.link.after
                if($keyword_links && !$template_default["link_before"] && $count < $count_results) {
                    $keyword_links .= $template_default["link_after"];
                }
            }
        }
    }
 
    //enclose whole
    if($keyword_links) $keyword_links = $template_default["before"].$keyword_links.$template_default["after"];
 
    return $keyword_links;
}
 
}
 
 
 
?>
english/phpwcms_replacer_rts/frontend_render/relatedx.txt · Last modified: 2009/04/25 08:06 (external edit)
www.planmatrix.de www.chimeric.de Creative Commons License Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0