Table of Contents

NEWX

{NEWX: Listenzähler : Kategorie-IDs : Schlüsselwörter : Modus [:versteckte Kategorien]}

Original-TAG {NEW:Anzahl_angezeigter_Links:ID} erweitert um die Möglichkeit in mehreren Kategorien nach Artikelschlüsselwörtern zu suchen.



Erweitert von KH (flip-flop) 10.03.2011

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

Forum: Replacement Tag NEW mit Filterung

TAG: {NEWX: Listenzähler : Kategorie-IDs : Schlüsselwörter : Modus [:versteckte Kategorien]} ist ein “ausgeschnittener Programmteil aus dem System frontend” erweitert um die Möglichkeit ab oder unterhalb vorgegebenen Ebenen mit der Suche zu beginnen. Dies ist sehr vorteilhaft z.B. für mehrsprachige Seiten.

Dateiname: rt_newx.php

Ort: /template/inc_script/frontend_render/rt_newx.php

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




Beschreibung:

Bitte immer alle Felder ausfüllen: Z.B.


Z.B.:

Gegebene Struktur:

------------------------------------
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.
------------------------------------

{NEWX:5:1,2,4:tip,top,flip,flop:1} → Ausgabe: Der Titellink der ersten fünf sichtbaren Artikel, in und unterhalb category_01 (ID=1),category_02 (ID=2) und category_04 (ID=4), in denen die Artikelschlüsselwörter vorkommen.


Beispiele:

Backend/Frontendausgabe


Script V 0.9

Datei: template/inc_script/frontend_render/rt_newx.php

{NEWX:count:category-IDs:key words:mode}

<?php
/*******************************************************************************************
   Copyright notice
 
   (c) 2002-2011 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!
  -------------------------------------------------------------------------------------------
  V 0.9
  10.03.11 KH (flip-flop) RT NEW cut out (frontend snippet)
  RT NEW erweitert um Schluesselwoerter, Kategorienliste (IDs) und Modus
   {NEWX:count:category-IDs:key word´s:category-ID:Mode}
...Please always fill out all fields: e.g.
   {NEWX:5::tip,top,flip,flop:0}  -> Output first 5 entries, search only in cad-ID=0 = home
   {NEWX:8:12,23,56:tip,top,flip,flop:1}  -> Output first 8 entries, search beginning in cad-ID=12,23,56 downstares in sub cats
   {NEWX:8:12,23,56::2}  -> Output first 8 entries, search beginning behind cad-ID=12,23,56 downstares in sub cats, no keywords
 
*********************************************************************************************/
// -------------------------------------------------------------------------------------------
// obligate check for phpwcms constants
  if (!defined('PHPWCMS_ROOT')) {die("You Cannot Access This Script Directly, Have a Nice Day.");}
// -------------------------------------------------------------------------------------------
 
 
 
if(strpos($content["all"],'{NEWX:') !== false) {
 
 
    function my_newX_keywords ($keywords = "")  {
 
        $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)."%'";
            }
        }
 
    return $where;
    }
// -------------------------------------------------
 
    // Parse cat id string
 
    function my_newX_cat_id ($cat_id = "")  {
 
        // replace unwanted chars and convert to wanted
        $cat_id = str_replace(";", ",", $cat_id);
        $cat_id = str_replace("'", "", $cat_id);
        $cat_id = str_replace(" ", ",", $cat_id);
        $cat_id = str_replace(",,", ",", $cat_id);
 
        // choose comma separated keywords
        $cat_id_array = explode (",", $cat_id);
        $cat_id_array = array_map('trim', $cat_id_array);
        $cat_id_array = array_diff($cat_id_array, array(''));
        $cat_id_array = array_unique($cat_id_array);
        $cat_id_array = array_map('strtoupper', $cat_id_array);
 
        // check for empty cat_ids or cat_ids smaller than 1 chars
        if(is_array($cat_id_array) && count($cat_id_array)) {
            foreach($cat_id_array as $key => $value) {
 
                if(substr($cat_id_array[$key], 0, 1) == '-') {
                    $doNotUse = substr($cat_id_array[$key], 1);
                    foreach($cat_id_array as $key2 => $value2) {
                        if($doNotUse == $value2) {
                            unset($cat_id_array[$key2]);
                            unset($cat_id_array[$key]);
                        }
                    }
                }
 
                if(isset($cat_id_array[$key]) && (strlen($cat_id_array[$key]) < 1 )) {
                    unset($cat_id_array[$key]);
                }
            }
        }
 
//    return $where;
    return $cat_id_array;
    }
// -------------------------------------------------
 
 
 
    function newX_buildStruct_TopDown($start=0, &$my_cat_id='') {  // KH: V1.1 25.01.2011
 
        $struct = getStructureChildData($start);
 
        foreach($struct as $value) {
            $my_cat_id .= ($my_cat_id != '') ? ','.$value['acat_id'] : $value['acat_id'];
            newX_buildStruct_TopDown($value['acat_id'],$my_cat_id);
        }
 
    return $my_cat_id;
    }
 
// -------------------------------------------------
 
 
    function my_get_newX_articles(&$template_default, $max_cnt_links=0, $cat, $keywords='', $sub_cat=0, $dbcon) {
        // find all new articles
 
 
        $cat         = (empty($cat)) ? '0': trim($cat);
        $save_cat     = $cat;
 
        //+KH:read cCategories from string
        $cat_id_array = my_newX_cat_id($cat);
 
        //+KH: Search sub-categories required??
        if (isset($sub_cat) AND $sub_cat) {
 
            $temp = '';
 
            foreach ($cat_id_array as $value) {
                $temp = newX_buildStruct_TopDown($value);    // find all permitted IDs behind $cat_id
                if (!empty($temp)) $temp .= ',';
            }
 
            $temp = substr ($temp, 0, -1); // Delete the last comma
 
            if (!empty($temp)) {
                $cat = $temp;
                if ($sub_cat == 1) $cat .= ','.$save_cat;    // +KH: 20.01.11 add start category
            }
        }
        else $sub_cat = false;
 
        $max_cnt_links = intval($max_cnt_links);
 
        $limit = (empty($max_cnt_links)) ?  '' : ' LIMIT '.$max_cnt_links;
 
 
 
        $cat =    "article_cid IN (".$cat.") AND ";
 
        $sql = 'SELECT article_id, article_title, article_cid, article_alias, article_redirect, article_morelink, ';
 
        switch( (empty($template_default["sort_by"]) ? '' : strtolower($template_default["sort_by"])) ) {
 
            case 'cdate':     //use real creation date
                            $sql .=    "article_created AS article_date ";
                            $sorting = 'article_created';
                            break;
 
            case 'ldate':     //use live/start date
                            $sql .=    "UNIX_TIMESTAMP(article_begin) AS article_date ";
                            $sorting = 'article_begin';
                            break;
 
            case 'kdate':     //use kill/end date
                            $sql .=    "UNIX_TIMESTAMP(article_end) AS article_date ";
                            $sorting = 'article_end';
                            break;
 
            default:        $sql .=    "UNIX_TIMESTAMP(article_tstamp) AS article_date ";
                            $sorting = 'article_tstamp';
        }
 
        $sql .=    "FROM ".DB_PREPEND."phpwcms_article WHERE ".$cat;
        // 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
        }
 
        // +KH: Keyword added
        $where = my_newX_keywords($keywords);
 
        if (!empty($where))
            $where = ' AND ('.$where.')';
        else $where = '';
 
        $sql .= "article_deleted=0 AND article_begin < NOW() AND article_end > NOW() ".$where." ";
        $sql .= "ORDER BY ".$sorting." DESC".$limit;
 
        // new articles list
        $new_links = "";
        $target = ($template_default["link_target"]) ? ' target="'.$template_default["link_target"].'"' : '';
 
        $result = _dbQuery($sql);
        $count  = 0;
 
        foreach($result as $row) {
 
                if(empty($row['article_redirect'])) {
                    if(empty($row['article_morelink'])) {
                        continue;
                    }
                    $article_link = 'index.php?'.setGetArticleAid($row).'"'.$target;
                } else {
                    $redirect = get_redirect_link($row['article_redirect'], ' ', '');
                    $article_link = $redirect['link'].'"'.$redirect['target'];
                }
 
                $count++;
                if($template_default["link_length"] && strlen($row['article_title']) > $template_default["link_length"]) {
                    $article_title = substr($row['article_title'], 0, $template_default["link_length"]).$template_default["cut_title_add"];
                } else {
                    $article_title = $row['article_title'];
                }
                $article_title = html_specialchars($article_title);
                if(trim($template_default["date_format"])) {
                    $article_date =     $template_default["date_before"] .
                                        html_specialchars(
                                            international_date_format(
                                                $template_default["date_language"],
                                                $template_default["date_format"],
                                                $row['article_date']
                                            )
                                        ) .
                                        $template_default["date_after"];
//                                        $article_title;
                }
                $new_links .= $template_default["link_before"];
                $new_links .= $template_default["link_symbol"];
                // --------------------------------------------------------
                // +KH: if you need an other order of date and article, please change the next line: $article_title.$article_date
                // --------------------------------------------------------
                $new_links .= '<a href="' . $article_link . '>' . $article_date.$article_title . '</a>';
                $new_links .= $template_default["link_after"];
        }
 
        //enclose whole
        if($new_links) $new_links = $template_default["before"].$new_links.$template_default["after"];
 
        // parses all system RTs  +KH 25.01.2011
        $new_links = html_parser($new_links);
 
        return $new_links;
    }
// -------------------------------------------------------------------------------------------
 
 
    // +KH: all new article list sorted by date
    if(strpos($content["all"],'{NEWX:') !== false) {
        $content["all"] = preg_replace('/\{NEWX\}/e','my_get_newX_articles($template_default["news"],"10","0","","1",$db);',$content["all"]);
        $content["all"] = preg_replace('/\{NEWX:(\d+):([0-9,]*):(.*?):(\d?)\}/e','my_get_newX_articles($template_default["news"],"$1","$2","$3","$4",$db);',$content["all"]);
    }
 
}
 
?>


Script V 1.0

Update V1.0 08.02.2012: Erweitert um auch Artikel in Versteckten Kategorien anzeigen zu können [:0|:1]

Update 08.02.2012


Datei: template/inc_script/frontend_render/rt_newx.php

{NEWX:count:category-IDs:key words:mode:hidden}

<?php
/*******************************************************************************************
   Copyright notice
 
   (c) 2002-2012 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!
  -------------------------------------------------------------------------------------------
  V 1.0
  10.03.11 KH (flip-flop) RT NEW cut out (frontend snippet)
  08.02.12 KH (flip-flop) Update: New var @hidden. Custom switch for show article without [more] is set.
  RT NEW erweitert um Schluesselwoerter, Kategorienliste (IDs) und Modus
   {NEWX:count:category-IDs:key word´s:category-ID:Mode}
...Please always fill out all fields: e.g.
   {NEWX:5::tip,top,flip,flop:0}          -> Output first 5 entries, search only in cad-ID=0 = home
   {NEWX:7:12,23,56:tip,top,flip,flop:1}  -> Output first 7 entries, search beginning in cad-ID=12,23,56 downstares in sub cats
   {NEWX:9:12,23,56::2}                   -> Output first 9 entries, search beginning behind cad-ID=12,23,56 downstares in sub cats, no keywords
 
   Update 08.02.12 :
   {NEWX:count:category-IDs:key word´s:Mode:show_hidden_categories}
   Show articles in hidden categories if set to 1
   {NEWX:9:12,23,56::2:1}                 -> Output first 9 entries, search beginning behind cad-ID=12,23,56 downstares in sub cats, no keywords, show article in hidden categories
   {NEWX:9:12,23,56::2:0}  or {NEWX:9:12,23,56::2}  -> The same as above, but don´t show article in hidden categories
 
   Custom switch @more:
   - 0 = Show article only if @more is [x]
   - 1 = Show article if @more is [x] or [_]
*********************************************************************************************/
// -------------------------------------------------------------------------------------------
// obligate check for phpwcms constants
  if (!defined('PHPWCMS_ROOT')) {die("You Cannot Access This Script Directly, Have a Nice Day.");}
// -------------------------------------------------------------------------------------------
 
 
 
if(strpos($content["all"],'{NEWX:') !== false) {
 
// CUSTOM ------------------------------------------------------------------------------------
 
    $more = 1;  // +KH 08.02.12: [0|1]  0 = Show article only if @more is [x] | 1 = if @more is [x] or [_]
 
// -------------------------------------------------------------------------------------------
 
    // +KH 08.02.12: include/inc_front/front.func.inc.php
    function my_getStructureLevelDisplayStatus(&$level_ID, &$current_ID, $hidden=0) {
 
 
        // Datensatz einer Unterkategorie der aktuellen Kategorie und nicht Kategorie 0 (home))
        if($GLOBALS['content']['struct'][$level_ID]['acat_struct'] == $current_ID && $level_ID) {
 
            // Kategorie fuer registrierte Benutzer und nicht eingeloggt
            if($GLOBALS['content']['struct'][$level_ID]['acat_regonly'] && !FEUSER_LOGIN_STATUS) {
                return false;
            }
            if(empty($GLOBALS['content']['struct'][$level_ID]['acat_hidden'])) {
                return true;
            } elseif($GLOBALS['content']['struct'][$level_ID]["acat_hidden"] == 2 && isset($GLOBALS['LEVEL_KEY'][$level_ID])) {
                return true;
            } elseif ($hidden) {  // +KH: IF hidden flag is set: All categories, including the hidden.
                return true;
            }
            return false;
        }
        return false;
    }
 
    // +KH 08.02.12: include/inc_front/front.func.inc.php
    function my_getStructureChildData($level_id=0, $hidden=0) {
        if( !isset($GLOBALS['content']['struct'][$level_id]) ) return array();
        $struct_data = array();
        foreach($GLOBALS['content']['struct'] as $key => $value) {
            if( my_getStructureLevelDisplayStatus($key, $level_id, $hidden) ) {
                $struct_data[$key]    = $value;
            }
        }
        return $struct_data;
    }
 
 
    function my_newX_keywords ($keywords = "")  {
 
        $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)."%'";
            }
        }
 
    return $where;
    }
// -------------------------------------------------
 
    // Parse cat id string
 
    function my_newX_cat_id ($cat_id = "")  {
 
        // replace unwanted chars and convert to wanted
        $cat_id = str_replace(";", ",", $cat_id);
        $cat_id = str_replace("'", "", $cat_id);
        $cat_id = str_replace(" ", ",", $cat_id);
        $cat_id = str_replace(",,", ",", $cat_id);
 
        // choose comma separated keywords
        $cat_id_array = explode (",", $cat_id);
        $cat_id_array = array_map('trim', $cat_id_array);
        $cat_id_array = array_diff($cat_id_array, array(''));
        $cat_id_array = array_unique($cat_id_array);
        $cat_id_array = array_map('strtoupper', $cat_id_array);
 
        // check for empty cat_ids or cat_ids smaller than 1 chars
        if(is_array($cat_id_array) && count($cat_id_array)) {
            foreach($cat_id_array as $key => $value) {
 
                if(substr($cat_id_array[$key], 0, 1) == '-') {
                    $doNotUse = substr($cat_id_array[$key], 1);
                    foreach($cat_id_array as $key2 => $value2) {
                        if($doNotUse == $value2) {
                            unset($cat_id_array[$key2]);
                            unset($cat_id_array[$key]);
                        }
                    }
                }
 
                if(isset($cat_id_array[$key]) && (strlen($cat_id_array[$key]) < 1 )) {
                    unset($cat_id_array[$key]);
                }
            }
        }
 
//    return $where;
    return $cat_id_array;
    }
// -------------------------------------------------
 
 
 
    function newX_buildStruct_TopDown($start=0, $hidden=0, &$my_cat_id='') {  // KH: V1.1 25.01.2011
 
        $struct = my_getStructureChildData($start, $hidden);
 
        foreach($struct as $value) {
            $my_cat_id .= ($my_cat_id != '') ? ','.$value['acat_id'] : $value['acat_id'];
            newX_buildStruct_TopDown($value['acat_id'], $hidden, $my_cat_id);
        }
 
    return $my_cat_id;
    }
 
// -------------------------------------------------
 
 
    function my_get_newX_articles(&$template_default, $max_cnt_links=10, $cat=0, $keywords='', $sub_cat=0, $hidden=0, $more=0, $dbcon) {
        // find all new articles
 
 
        $cat         = (empty($cat)) ? '0': trim($cat);
        $save_cat     = $cat;
 
        //+KH:read cCategories from string
        $cat_id_array = my_newX_cat_id($cat);
 
        //+KH: Search sub-categories required??
        if (isset($sub_cat) AND $sub_cat) {
 
            $temp = '';
 
            foreach ($cat_id_array as $value) {
                $temp = newX_buildStruct_TopDown($value, $hidden);    // find all permitted IDs behind $cat_id
                if (!empty($temp)) $temp .= ',';
            }
 
            $temp = substr ($temp, 0, -1); // Delete the last comma
 
            if (!empty($temp)) {
                $cat = $temp;
                if ($sub_cat == 1) {
 
                    if(empty($GLOBALS['content']['struct'][$save_cat]['acat_hidden']) OR $hidden) // +KH: 08.02.12
                        $cat .= ','.$save_cat;    // +KH: 20.01.11 add start category
                }
            }
        }
        else $sub_cat = false;
 
        $max_cnt_links = intval($max_cnt_links);
 
        $limit = (empty($max_cnt_links)) ?  '' : ' LIMIT '.$max_cnt_links;
 
 
 
        $cat =    "article_cid IN (".$cat.") AND ";
 
        $sql = 'SELECT article_id, article_title, article_cid, article_alias, article_redirect, article_morelink, ';
 
        switch( (empty($template_default["sort_by"]) ? '' : strtolower($template_default["sort_by"])) ) {
 
            case 'cdate':     //use real creation date
                            $sql .=    "article_created AS article_date ";
                            $sorting = 'article_created';
                            break;
 
            case 'ldate':     //use live/start date
                            $sql .=    "UNIX_TIMESTAMP(article_begin) AS article_date ";
                            $sorting = 'article_begin';
                            break;
 
            case 'kdate':     //use kill/end date
                            $sql .=    "UNIX_TIMESTAMP(article_end) AS article_date ";
                            $sorting = 'article_end';
                            break;
 
            default:        $sql .=    "UNIX_TIMESTAMP(article_tstamp) AS article_date ";
                            $sorting = 'article_tstamp';
        }
 
        $sql .=    "FROM ".DB_PREPEND."phpwcms_article WHERE ".$cat;
        // 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
        }
 
        // +KH: Keyword added
        $where = my_newX_keywords($keywords);
 
        if (!empty($where))
            $where = ' AND ('.$where.')';
        else $where = '';
 
        $sql .= "article_deleted=0 AND article_begin < NOW() AND article_end > NOW() ".$where." ";
        $sql .= "ORDER BY ".$sorting." DESC".$limit;
 
        // new articles list
        $new_links = "";
        $target = ($template_default["link_target"]) ? ' target="'.$template_default["link_target"].'"' : '';
 
        $result = _dbQuery($sql);
        $count  = 0;
 
        foreach($result as $row) {
 
                if(empty($row['article_redirect'])) {
                    // Feld more im Artikel nicht gesetzt und Schalter @more nicht aktiv  // +KH 08.02.12
                    if(empty($row['article_morelink']) AND !$more) {
                        continue;
                    }
                    $article_link = 'index.php?'.setGetArticleAid($row).'"'.$target;
                } else {
                    $redirect = get_redirect_link($row['article_redirect'], ' ', '');
                    $article_link = $redirect['link'].'"'.$redirect['target'];
                }
 
                $count++;
                if($template_default["link_length"] && strlen($row['article_title']) > $template_default["link_length"]) {
                    $article_title = substr($row['article_title'], 0, $template_default["link_length"]).$template_default["cut_title_add"];
                } else {
                    $article_title = $row['article_title'];
                }
                $article_title = html_specialchars($article_title);
                if(trim($template_default["date_format"])) {
                    $article_date =     $template_default["date_before"] .
                                        html_specialchars(
                                            international_date_format(
                                                $template_default["date_language"],
                                                $template_default["date_format"],
                                                $row['article_date']
                                            )
                                        ) .
                                        $template_default["date_after"];
//                                        $article_title;
                }
                $new_links .= $template_default["link_before"];
                $new_links .= $template_default["link_symbol"];
                // --------------------------------------------------------
                // +KH: if you need an other order of date and article, please change the next line: $article_title.$article_date
                // --------------------------------------------------------
                $new_links .= '<a href="' . $article_link . '>' . $article_date.$article_title . '</a>';
                $new_links .= $template_default["link_after"];
        }
 
        //enclose whole
        if($new_links) $new_links = $template_default["before"].$new_links.$template_default["after"];
 
        // parses all system RTs  +KH 25.01.2011
        $new_links = html_parser($new_links);
 
        return $new_links;
    }
// -------------------------------------------------------------------------------------------
 
 
    // +KH: all new article list sorted by date
    if(strpos($content["all"],'{NEWX:') !== false) {
        $content["all"] = preg_replace('/\{NEWX\}/e','my_get_newX_articles($template_default["news"],"10","0","","1","0",$db);',$content["all"]);
        // NEWX: Count : catID,catID,catID : keyword,keyword,keyword : mode : hidden}
        $content["all"] = preg_replace('/\{NEWX:(\d+):([0-9,]*):(.*?):(\d?):?([0|1]?)\}/e','my_get_newX_articles($template_default["news"],"$1","$2","$3","$4","$5",$more,$db);',$content["all"]);
    }
 
}
 
?>


Script V 1.1

Update V1.1 14.02.2012: Wie V1.0, zusätzlich


Datei: template/inc_script/frontend_render/rt_newx.php

{NEWX:count:category-IDs:key words:mode:hidden}

<?php
/*******************************************************************************************
   Copyright notice
 
   (c) 2002-2012 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!
  -------------------------------------------------------------------------------------------
  V 1.1
  10.03.11 KH (flip-flop) RT NEW cut out (frontend snippet)
  08.02.12 KH (flip-flop) Update V1.0: New var @hidden. Custom switch for show article without [more] is set.
  14.02.12 KH (flip-flop) Update V1.1: If in BE the keyword is set to "hidden" or "versteckt", the articles of the category are not displayed. (Don´t need [x] hidden).
 
  RT NEW erweitert um Schluesselwoerter, Kategorienliste (IDs) und Modus
   {NEWX:count:category-IDs:key word´s:category-ID:Mode}
...Please always fill out all fields: e.g.
   {NEWX:5::tip,top,flip,flop:0}          -> Output first 5 entries, search only in cad-ID=0 = home
   {NEWX:7:12,23,56:tip,top,flip,flop:1}  -> Output first 7 entries, search beginning in cad-ID=12,23,56 downstares in sub cats
   {NEWX:9:12,23,56::2}                   -> Output first 9 entries, search beginning behind cad-ID=12,23,56 downstares in sub cats, no keywords
 
   Update 08.02.12 :
   {NEWX:count:category-IDs:key word´s:Mode:show_hidden_categories}
   Show articles in hidden categories if set to 1
   {NEWX:9:12,23,56::2:1}                 -> Output first 9 entries, search beginning behind cad-ID=12,23,56 downstares in sub cats, no keywords, show article in hidden categories
   {NEWX:9:12,23,56::2:0}  or {NEWX:9:12,23,56::2}  -> The same as above, but don´t show article in hidden categories
 
   Custom switch @more:
   - 0 = Show article only if @more is [x]
   - 1 = Show article if @more is [x] or [_]
*********************************************************************************************/
// -------------------------------------------------------------------------------------------
// obligate check for phpwcms constants
  if (!defined('PHPWCMS_ROOT')) {die("You Cannot Access This Script Directly, Have a Nice Day.");}
// -------------------------------------------------------------------------------------------
 
 
 
if(strpos($content["all"],'{NEWX:') !== false) {
 
// CUSTOM ------------------------------------------------------------------------------------
 
    $more = 1;  // +KH 08.02.12: [0|1]  0 = Show article only if @more is [x] | 1 = if @more is [x] or [_]
 
// -------------------------------------------------------------------------------------------
 
    // +KH 08.02.12: include/inc_front/front.func.inc.php
    function my_getStructureLevelDisplayStatus(&$level_ID, &$current_ID, $hidden=0) {
 
 
        // Datensatz einer Unterkategorie der aktuellen Kategorie und nicht Kategorie 0 (home))
        if($GLOBALS['content']['struct'][$level_ID]['acat_struct'] == $current_ID && $level_ID) {
 
            // Kategorie fuer registrierte Benutzer und nicht eingeloggt
            if($GLOBALS['content']['struct'][$level_ID]['acat_regonly'] && !FEUSER_LOGIN_STATUS) {
                return false;
            }
            // Update V1.1: Wenn die Schluesselwoerter "hidden" oder "versteckt" gesetzt sind, dann verbergen
            if (!empty($GLOBALS['content']['struct'][$level_ID]['acat_keywords'])) {
 
                if( (stripos($GLOBALS['content']['struct'][$level_ID]['acat_keywords'], 'hidden'   ) !== FALSE) OR
                    (stripos($GLOBALS['content']['struct'][$level_ID]['acat_keywords'], 'versteckt') !== FALSE)    ) {
                    return false;
                }
            }
 
            if(empty($GLOBALS['content']['struct'][$level_ID]['acat_hidden'])) {
                return true;
            } elseif($GLOBALS['content']['struct'][$level_ID]["acat_hidden"] == 2 && isset($GLOBALS['LEVEL_KEY'][$level_ID])) {
                return true;
            } elseif ($hidden) {  // +KH: IF hidden flag is set: All categories, including the hidden.
                return true;
            }
            return false;
        }
        return false;
    }
 
    // +KH 08.02.12: include/inc_front/front.func.inc.php
    function my_getStructureChildData($level_id=0, $hidden=0) {
        if( !isset($GLOBALS['content']['struct'][$level_id]) ) return array();
        $struct_data = array();
        foreach($GLOBALS['content']['struct'] as $key => $value) {
            if( my_getStructureLevelDisplayStatus($key, $level_id, $hidden) ) {
                $struct_data[$key]    = $value;
            }
        }
        return $struct_data;
    }
 
 
    function my_newX_keywords ($keywords = "")  {
 
        $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)."%'";
            }
        }
 
    return $where;
    }
// -------------------------------------------------
 
    // Parse cat id string
 
    function my_newX_cat_id ($cat_id = "")  {
 
        // replace unwanted chars and convert to wanted
        $cat_id = str_replace(";", ",", $cat_id);
        $cat_id = str_replace("'", "", $cat_id);
        $cat_id = str_replace(" ", ",", $cat_id);
        $cat_id = str_replace(",,", ",", $cat_id);
 
        // choose comma separated keywords
        $cat_id_array = explode (",", $cat_id);
        $cat_id_array = array_map('trim', $cat_id_array);
        $cat_id_array = array_diff($cat_id_array, array(''));
        $cat_id_array = array_unique($cat_id_array);
        $cat_id_array = array_map('strtoupper', $cat_id_array);
 
        // check for empty cat_ids or cat_ids smaller than 1 chars
        if(is_array($cat_id_array) && count($cat_id_array)) {
            foreach($cat_id_array as $key => $value) {
 
                if(substr($cat_id_array[$key], 0, 1) == '-') {
                    $doNotUse = substr($cat_id_array[$key], 1);
                    foreach($cat_id_array as $key2 => $value2) {
                        if($doNotUse == $value2) {
                            unset($cat_id_array[$key2]);
                            unset($cat_id_array[$key]);
                        }
                    }
                }
 
                if(isset($cat_id_array[$key]) && (strlen($cat_id_array[$key]) < 1 )) {
                    unset($cat_id_array[$key]);
                }
            }
        }
 
//    return $where;
    return $cat_id_array;
    }
// -------------------------------------------------
 
 
 
    function newX_buildStruct_TopDown($start=0, $hidden=0, &$my_cat_id='') {  // KH: V1.1 25.01.2011
 
        $struct = my_getStructureChildData($start, $hidden);
 
        foreach($struct as $value) {
            $my_cat_id .= ($my_cat_id != '') ? ','.$value['acat_id'] : $value['acat_id'];
            newX_buildStruct_TopDown($value['acat_id'], $hidden, $my_cat_id);
        }
 
    return $my_cat_id;
    }
 
// -------------------------------------------------
 
 
    function my_get_newX_articles(&$template_default, $max_cnt_links=10, $cat=0, $keywords='', $sub_cat=0, $hidden=0, $more=0, $dbcon) {
        // find all new articles
 
        $cat         = (empty($cat)) ? '0': trim($cat);
        $save_cat     = $cat;
 
        //+KH:read cCategories from string
        $cat_id_array = my_newX_cat_id($cat);
 
        //+KH: Search sub-categories required??
        if (isset($sub_cat) AND $sub_cat) {
 
            $temp = '';
 
            foreach ($cat_id_array as $value) {
                $temp = newX_buildStruct_TopDown($value, $hidden);    // find all permitted IDs behind $cat_id
                if (!empty($temp)) $temp .= ',';
            }
 
            $temp = substr ($temp, 0, -1); // Delete the last comma
 
            if (!empty($temp)) {
                $cat = $temp;
                if ($sub_cat == 1) {
 
                    if(empty($GLOBALS['content']['struct'][$save_cat]['acat_hidden']) OR $hidden) // +KH: 08.02.12
                        $cat .= ','.$save_cat;    // +KH: 20.01.11 add start category
                }
            }
        }
        else $sub_cat = false;
 
        $max_cnt_links = intval($max_cnt_links);
 
        $limit = (empty($max_cnt_links)) ?  '' : ' LIMIT '.$max_cnt_links;
 
 
 
        $cat =    "article_cid IN (".$cat.") AND ";
 
        $sql = 'SELECT article_id, article_title, article_cid, article_alias, article_redirect, article_morelink, ';
 
        switch( (empty($template_default["sort_by"]) ? '' : strtolower($template_default["sort_by"])) ) {
 
            case 'cdate':     //use real creation date
                            $sql .=    "article_created AS article_date ";
                            $sorting = 'article_created';
                            break;
 
            case 'ldate':     //use live/start date
                            $sql .=    "UNIX_TIMESTAMP(article_begin) AS article_date ";
                            $sorting = 'article_begin';
                            break;
 
            case 'kdate':     //use kill/end date
                            $sql .=    "UNIX_TIMESTAMP(article_end) AS article_date ";
                            $sorting = 'article_end';
                            break;
 
            default:        $sql .=    "UNIX_TIMESTAMP(article_tstamp) AS article_date ";
                            $sorting = 'article_tstamp';
        }
 
        $sql .=    "FROM ".DB_PREPEND."phpwcms_article WHERE ".$cat;
        // 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
        }
 
        // +KH: Keyword added
        $where = my_newX_keywords($keywords);
 
        if (!empty($where))
            $where = ' AND ('.$where.')';
        else $where = '';
 
        $sql .= "article_deleted=0 AND article_begin < NOW() AND article_end > NOW() ".$where." ";
        $sql .= "ORDER BY ".$sorting." DESC".$limit;
 
        // new articles list
        $new_links = "";
        $target = ($template_default["link_target"]) ? ' target="'.$template_default["link_target"].'"' : '';
 
        $result = _dbQuery($sql);
        $count  = 0;
 
        foreach($result as $row) {
 
                if(empty($row['article_redirect'])) {
                    // Feld more im Artikel nicht gesetzt und Schalter @more nicht aktiv  // +KH 08.02.12
                    if(empty($row['article_morelink']) AND !$more) {
                        continue;
                    }
                    $article_link = 'index.php?'.setGetArticleAid($row).'"'.$target;
                } else {
                    $redirect = get_redirect_link($row['article_redirect'], ' ', '');
                    $article_link = $redirect['link'].'"'.$redirect['target'];
                }
 
                $count++;
                if($template_default["link_length"] && strlen($row['article_title']) > $template_default["link_length"]) {
                    $article_title = substr($row['article_title'], 0, $template_default["link_length"]).$template_default["cut_title_add"];
                } else {
                    $article_title = $row['article_title'];
                }
                $article_title = html_specialchars($article_title);
                if(trim($template_default["date_format"])) {
                    $article_date =     $template_default["date_before"] .
                                        html_specialchars(
                                            international_date_format(
                                                $template_default["date_language"],
                                                $template_default["date_format"],
                                                $row['article_date']
                                            )
                                        ) .
                                        $template_default["date_after"];
//                                        $article_title;
                }
                $new_links .= $template_default["link_before"];
                $new_links .= $template_default["link_symbol"];
                // --------------------------------------------------------
                // +KH: if you need an other order of date and article, please change the next line: $article_title.$article_date
                // --------------------------------------------------------
                $new_links .= '<a href="' . $article_link . '>' . $article_date.$article_title . '</a>';
                $new_links .= $template_default["link_after"];
        }
 
        //enclose whole
        if($new_links) $new_links = $template_default["before"].$new_links.$template_default["after"];
 
        // parses all system RTs  +KH 25.01.2011
        $new_links = html_parser($new_links);
 
        return $new_links;
    }
// -------------------------------------------------------------------------------------------
 
 
    // +KH: all new article list sorted by date
    if(strpos($content["all"],'{NEWX:') !== false) {
        $content["all"] = preg_replace('/\{NEWX\}/e','my_get_newX_articles($template_default["news"],"10","0","","1","0",$db);',$content["all"]);
        // NEWX: Count : catID,catID,catID : keyword,keyword,keyword : mode : hidden}
        $content["all"] = preg_replace('/\{NEWX:(\d+):([0-9,]*):(.*?):(\d?):?([0|1]?)\}/e','my_get_newX_articles($template_default["news"],"$1","$2","$3","$4","$5",$more,$db);',$content["all"]);
    }
 
}
 
?>


Einstellungen:

In der Datei: config/phpwcms/conf.template_default.inc.php

Beispiel:

// new articles
$template_default['news']['before']            = '<div class="new-tag">';
$template_default['news']['after']            = '</div>';
$template_default['news']['link_before']    = '<p>';
$template_default['news']['link_after']        = '</p>';
$template_default['news']['link_symbol']    = '&raquo; ';
$template_default['news']['link_target']    = '';
$template_default['news']['link_length']    = 0; //if 0 no limit
$template_default['news']['cut_title_add']    = '&#8230;';
$template_default['news']['date_language']    = 'DE'; // DE=German, IT=Italian, FR=French, ES = Spanish, DA = Danish, NO = Norwegian
$template_default['news']['date_format']    = 'd.m.Y'; //if empty -> no Date
$template_default['news']['date_before']    = '<span class="datelink"> ';
$template_default['news']['date_after']        = ' - </span>';
$template_default['news']['sort_by']        = 'udate'; // 'cdate' = Creation date, or 'udate' = update date, ldate = start date, kdate = end date


CSS:

Datei: Z.B. in template/inc_css/frontend.css

Beispiel:

/* NEW TAG --------------------------------- */
 
.new-tag {
    font-family: verdana; /* "Courier New", monospace; */
    font-size:90%;
}
 
.new-tag a {
    color: red;
}
 
.new-tag .datelink {
    font-size:80%;
    color: darkred;
}