Differences

This shows you the differences between two versions of the page.

english:phpwcms_replacer_rts:frontend_render:newx [2012/02/10 20:25]
Knut Heermann (flip-flop)
english:phpwcms_replacer_rts:frontend_render:newx [2018/06/03 18:09] (current)
Line 6: Line 6:
===== {NEWX: Counter : category-IDs : Keywords : Mode [hidden categories]} ===== ===== {NEWX: Counter : category-IDs : Keywords : Mode [hidden categories]} =====
-FIXME Beta -> TRANSLATE  please test+FIXME TRANSLATE  please test
Original TAG [[http://www.phpwcms-docu.de/link_tags_.phtml|{NEW:Amount_of_shown_links:ID}]] enhanced to allow a search for articles keywords in different categories.. \\ Original TAG [[http://www.phpwcms-docu.de/link_tags_.phtml|{NEW:Amount_of_shown_links:ID}]] enhanced to allow a search for articles keywords in different categories.. \\
Line 61: Line 61:
    * **{NEWX: list counter : Category-IDs : keywords : mode : hidden categories}** \\ **{NEWX:5:3::1:1}**  -> //Search without keywords within category-ID=3 and below even if they are hidden //     * **{NEWX: list counter : Category-IDs : keywords : mode : hidden categories}** \\ **{NEWX:5:3::1:1}**  -> //Search without keywords within category-ID=3 and below even if they are hidden //
-e.g.: + 
 + 
 +  * **Update** V1.1 14.02.2012: If one of the keywords %%"hidden" or "versteckt"%% is entered in the category field %%"keywords"%%, the articles of this category are not displayed. The category switch %%"[x] hidden"%% does not have to be set. 
 + 
 +\\ 
 +E.g.:
Given structure: Given structure:
Line 98: Line 103:
-\\+~~UP~~
-==== Script V 0.9 ====+===== Script V 0.9 =====
File: template/inc_script/frontend_render/rt_newx.php File: template/inc_script/frontend_render/rt_newx.php
Line 405: Line 410:
\\ \\
- 
-==== Settings: ==== 
- 
-**In the file:** config/phpwcms/conf.template_default.inc.php 
- 
-**Example:** 
-<code php> 
-// 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 
- 
-</code> 
- 
- 
-\\ 
-=== CSS: === 
- 
-File: e.g. in template/inc_css/frontend.css 
- 
-**Example:** 
-<code css> 
-/* 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; 
-} 
-</code> 
- 
-\\ 
- 
- 
- 
===== Script V 1.0 ===== ===== Script V 1.0 =====
-  * Update V1.0 08.02.2012: Enhanced by the possibility to show articles in hidden categories too [:0|:1]+**Update V1.0 08.02.2012**: Enhanced by the possibility to show articles in hidden categories too [:0|:1]
    * {NEWX: counter : category-IDs : keywords : mode : hidden category}     * {NEWX: counter : category-IDs : keywords : mode : hidden category}
Line 836: Line 788:
\\ \\
 +===== Script V 1.1 =====
 +**Update V1.1 14.02.2012**: As V1.0, in addition
 +  * If one of the keywords "hidden" or "versteckt" is entered in the category field %%"keywords"%%, the articles of this category are not displayed. The category switch %%"[x] hidden"%% is not necessary for this.
 +\\
 +**File:** template/inc_script/frontend_render/rt_newx.php
 +<code php|h {NEWX:count:category-IDs:key words:mode:hidden category} |h>
 +<?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;
 + }
-==== Adjustments: ==== 
-**In file:** config/phpwcms/conf.template_default.inc.php+ 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; 
 +
 +// -------------------------------------------------
-**Example:** + // Parse cat id string 
-&lt;code php&gt+  
-// new articles + function my_newX_cat_id ($cat_id = &quot;&quot;)  { 
-$template_default['news']['before'] = '&lt;div class="new-tag"&gt;'+  
-$template_default['news']['after'] = '&lt;/div&gt;'+ // replace unwanted chars and convert to wanted 
-$template_default['news']['link_before'] = '&lt;p&gt;'; + $cat_id = str_replace(&quot;;", ",&quot;, $cat_id)
-$template_default['news']['link_after'] = '&lt;/p&gt;'+ $cat_id = str_replace("'&quot;, &quot;", $cat_id)
-$template_default['news']['link_symbol'] = '&amp;raquo; '+ $cat_id = str_replace(&quot; &quot;, ";,", $cat_id); 
-$template_default['news']['link_target'] = ''; + $cat_id = str_replace(&quot;,,&quot;, ",", $cat_id)
-$template_default['news']['link_length'] = 0; //if 0 no limit +  
-$template_default['news']['cut_title_add'] = '&#8230;'+ // choose comma separated keywords 
-$template_default['news']['date_language'] = 'DE'; // DE=German, IT=Italian, FR=French, ES = Spanish, DA = Danish, NO = Norwegian + $cat_id_array = explode (&quot;,";, $cat_id)
-$template_default['news']['date_format'] = 'd.m.Y'; //if empty -> no Date + $cat_id_array = array_map('trim', $cat_id_array); 
-$template_default['news']['date_before'] = '&lt;span class=&quot;datelink"> '; + $cat_id_array = array_diff($cat_id_array, array(''))
-$template_default['news']['date_after'] = ' - </span>'; + $cat_id_array = array_unique($cat_id_array); 
-$template_default['news']['sort_by'] = 'udate'; // 'cdate' = Creation date, or 'udate' = update date, ldate = start date, kdate = end date+ $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]) &amp;&amp; (strlen($cat_id_array[$key]) < 1 )) { 
 + unset($cat_id_array[$key]); 
 +
 +
 +
 +  
 +// return $where; 
 + return $cat_id_array; 
 +
 +// -------------------------------------------------
-</code> 
 +
 + 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"]);
 + }
 +
 +}
 +
 +?>
 +</code>
\\ \\
Line 880: Line 1169:
 +\\
Line 894: Line 1184:
 +==== Settings: ====
 +**In the file:** config/phpwcms/conf.template_default.inc.php
 +**Example:**
 +<code php>
 +// 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
 +</code>
 +
 +
 +\\
==== CSS: ==== ==== CSS: ====
Line 921: Line 1233:
\\ \\
 +
 +
english/phpwcms_replacer_rts/frontend_render/newx.1328901951.txt.gz · Last modified: 2018/06/03 18:08 (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