Table of Contents

WRAP_SHOW_CONTENTX

Forum: http://forum.phpwcms.org/viewtopic.php?p=112725#p112725

Enhanced version of {WRAP_SHOW_CONTENT:…..} to display unvisible CPs {WRAP_SHOW_CONTENTX:…:class}. The same like {SHOW_CONTENT: … but with a enclosed div container

If there is/are a unfilled CP/CPs no output is generated (and no div wrapper)

Download: http://phpwcms.planmatrix.de/download/reptag/rt_wrap_show_contentX.zip

E.g.: {WRAP_SHOW_CONTENTX:CP, 19: my_class}
   or {WRAP_SHOW_CONTENTX:CP, 19}  -> fallback to the default class

Default class: WRAP_SHOW_CONTENTX

Update:

- 04.04.2010 KH: Improvement over the original: If you are running SHOW_CONTENT from [PHP]… now [PHP-Code] in articles/CPs can be addressed a second time with this tag.
- 05.03.2010 KH: Parses all system RTs and mailto: conversion for JS-eMail address.
- 19.01.2011 KH: Parsing of SHOW_CONTENT when in embedded CPs this RT appears a second time.

Example:

[PHP]
  if ( $GLOBALS['LEVEL_ID'][2] == 13 ) echo '<div>{WRAP_SHOW_CONTENTX:CP,104}</div>';
[/PHP]

PHP code in the CP 104 would not be processed using the built in SHOW_CONTENT.


Code:

File: template/inc_script/frontend_render/rt_wrap_show_contentx.php

WRAP_SHOW_CONTENTX:....:class

<?php
// ==================================================================
// Enhanced version of {WRAP_SHOW_CONTENTX:.....} to display unvisible CPs
// {WRAP_SHOW_CONTENTX:...:class}. The same like {SHOW_CONTENT: ...
// but with a enclosed div container
// If there is/are a unfilled or unvisible CP/CPs no output is generated
// (and no div wrapper)
//
// E.g.: {WRAP_SHOW_CONTENTX:CP, 19: my_class}
//    or {WRAP_SHOW_CONTENTX:CP, 19}  -> fallback to the default class
//
// Default class: WRAP_SHOW_CONTENTX
//
// file name: /template/inc_script/frontend_render/rt_WRAP_SHOW_CONTENTX.php
// forum: http://forum.phpwcms.org/viewtopic.php?p=112725#p112725
//
// (c) 07.11.08 Knut Heermann (flip-flop) http://planmatrix.de
//      08.11.08 Updated for a better handling
//      16.01.09 Enhanced WRAP_SHOW_CONTENT:  to display unvisible CPs
//      11.01.11 Update parse SHOW_CONTENT a second time
// ==================================================================
// ------------------------------------------------------------------
// obligate check for phpwcms constants
if (!defined('PHPWCMS_ROOT')) {
   die("You Cannot Access This Script Directly, Have a Nice Day."); }
// ------------------------------------------------------------------
 
if( strpos($content['all'], '{WRAP_SHOW_CONTENTX:') !== FALSE ) {
 
 
/*
 * {SHOW_CONTENT}
 * thanks to Jens Zetterström who has initiated this in 2005
 * Shows the content of the article content part with the specified id.
 * use it {SHOW_CONTENT:MODE,id[,id[,...]]}
 * where MODE is what should returned
 * and id is the corresponding ID
 * MODE options:
 *   CP   - list of Content Parts | id = id of the content part, one or more possible, comma seperated.
 *   CPA  - ascending list of Content Parts but based on selected article  | id = id of article, comma seperated
 *   CPAD - same as CPA, but descending
 *   AS   - list of Article Summaries | id = id of articles, comma separated
 *
 */
function showSelectedContentX($param='') {
 
    global $template_default;
    global $db;
    global $content;
    global $block;
    global $phpwcms;
    global $aktion;
 
    $topcount = 999999;
    $template = '';
 
    if($cp = explode(',', $param)) {
        $mode    = strtoupper(trim($cp[0]));
        if(substr($mode, 0, 2) == 'AS') {
            $mode = explode('|', $cp[0]);
            if(isset($mode[1])) {
                $mode[1] = trim($mode[1]);
                if(is_numeric($mode[1])) {
                    $topcount = intval($mode[1]);
                } elseif(empty($mode[2]) && strlen($mode[1]) > 4 && ($mode[1] == 'default' || is_file(PHPWCMS_TEMPLATE.'inc_cntpart/articlesummary/list/'.$mode[1]))) {
                    $template = $mode[1];
                }
            }
            if(isset($mode[2])) {
                $mode[2] = trim($mode[2]);
                if(is_numeric($mode[2])) {
                    $topcount = intval($mode[2]);
                } elseif(strlen($mode[2]) > 4 && ($mode[2] == 'default' || is_file(PHPWCMS_TEMPLATE.'inc_cntpart/articlesummary/list/'.$mode[2]))) {
                    $template = $mode[2];
                }
            }
            $mode = strtoupper(trim($mode[0]));
            if(isset($cp[1])) { // now check if
                $cp[1] = trim($cp[1]);
                if(!is_numeric($cp[1])) {
                    switch($cp[1]) {
                        case 'new':        $cp = array('new'        => 1);    break;
                        case 'random':    $cp = array('random'    => 1);    break;
                        case 'related':    if(isset($cp[2])) {
                                            unset($cp[0], $cp[1]);
                                            $related = array();
                                            foreach($cp as $value) {
                                                $related[] = "article_keyword LIKE '%".aporeplace(strtoupper(trim($value)))."%'";
                                            }
                                            $cp = array('related' => 1); break;
                                        }
 
                        default:        $cp = array('new'        => 1);
                    }
                }
            }
        }
        unset($cp[0]);
        foreach($cp as $key => $value) {
            $value    = intval($value);
            if(!$value) {
                unset($cp[$key]);
            } else {
                $cp[$key] = $value;
            }
        }
        if(!is_array($cp) || !count($cp)) {
            return '';
        }
    } else {
        // oh no ID given, end function
        return '';
    }
 
    $CNT_TMP = '';
 
    if(substr($mode, 0, 2) == 'AS') {
 
        if(substr($mode, -1) == 'P') {
            $mode = substr($mode, 0, -1);
            $priorize = 'article_priorize DESC, ';
        } else {
            $priorize = '';
        }
 
        switch($mode) {
 
            case 'ASL':        $sort = $priorize.'article_begin ASC';        break; // sorted by livedate ascending
            case 'ASLD':    $sort = $priorize.'article_begin DESC';        break; // sorted by livedate descending
            case 'ASK':        $sort = $priorize.'article_end ASC';        break; // sorted by killdate ascending
            case 'ASKD':    $sort = $priorize.'article_end DESC';        break; // sorted by killdate descending
            case 'ASC':        $sort = $priorize.'article_tstamp ASC';        break; // sorted by change date ascending
            case 'ASCD':    $sort = $priorize.'article_tspamp DESC';    break; // sorted by change date descending
            case 'ASR':        $sort = 'RAND()';                            break; // random sort
            default:        $sort = '';
 
        }
 
        $CNT_TMP = list_articles_summary( get_article_data( $cp, $topcount, $sort ) , $topcount, $template);
 
 
    } elseif($mode == 'CP' || $mode == 'CPA' || $mode == 'CPAD') {
 
        $sort = ($mode=='CPAD') ? ' DESC' : ''; //means ASCENDING
 
        foreach($cp as $value) {
 
            if($mode == 'CP') {
                // content part listing
                $sql  = "SELECT * FROM " . DB_PREPEND . "phpwcms_articlecontent ";
                $sql .= "INNER JOIN " . DB_PREPEND . "phpwcms_article ON ";
                $sql .= DB_PREPEND . "phpwcms_article.article_id = " . DB_PREPEND . "phpwcms_articlecontent.acontent_aid ";
//                $sql .= "WHERE acontent_id = " . $value . " AND acontent_visible = 1 "; -kh
                $sql .= "WHERE acontent_id = " . $value . " ";
 
                if( !FEUSER_LOGIN_STATUS ) {
                    $sql .= 'AND acontent_granted=0 ';
                }
 
                $sql .= "AND acontent_trash = 0 AND " . DB_PREPEND . "phpwcms_article.article_deleted=0 AND ";
                $sql .= DB_PREPEND."phpwcms_article.article_begin < NOW() AND " . DB_PREPEND . "phpwcms_article.article_end > NOW() ";
                $sql .= "LIMIT 1";
 
            } else {
                // content parts based on article ID
                $sql  = "SELECT * FROM ".DB_PREPEND."phpwcms_articlecontent ";
//                $sql .= "WHERE acontent_aid=". $value." AND acontent_visible=1 AND acontent_trash=0 "; // -kh
                $sql .= "WHERE acontent_aid=". $value." AND acontent_trash=0 ";
 
                if( !FEUSER_LOGIN_STATUS ) {
                    $sql .= 'AND acontent_granted=0 ';
                }
 
                $sql .= "ORDER BY acontent_sorting".$sort.", acontent_id";
 
            }
 
            if($cresult = mysql_query($sql, $db)) {
                while($crow = mysql_fetch_assoc($cresult))    {
 
                    if($crow["acontent_type"] == 30 && !isset($phpwcms['modules'][$crow["acontent_module"]])) {
                        continue;
                    }
 
                    if($crow["acontent_type"] == 24) {
                        // first retrieve alias ID information and settings
                        $crow = getContentPartAlias($crow);
                    }
 
                    $space = getContentPartSpacer($crow["acontent_before"], $crow["acontent_after"]);
 
                    // Space before
                    $CNT_TMP .= $space['before'];
 
                    // set frontend edit link
                    $CNT_TMP .= getFrontendEditLink('CP', $crow['acontent_aid'], $crow['acontent_id']);
 
                    // include content part code section
                    if($crow["acontent_type"] != 30) {
 
                        include(PHPWCMS_ROOT.'/include/inc_front/content/cnt' . $crow["acontent_type"] . '.article.inc.php');
 
                    } elseif($crow["acontent_type"] == 30 && file_exists($phpwcms['modules'][$crow["acontent_module"]]['path'].'inc/cnt.article.php')) {
 
                        $CNT_TMP .= getFrontendEditLink('module', $phpwcms['modules'][$crow["acontent_module"]]['name']);
 
                        // now try to include module content part code
                        include($phpwcms['modules'][$crow["acontent_module"]]['path'].'inc/cnt.article.php');
 
                    }
 
                    //check if top link should be shown
                    $CNT_TMP .= getContentPartTopLink($crow["acontent_top"]);
 
                    //Maybe content part ID should b used inside templates or for something different
                    $CNT_TMP  = str_replace( array('[%CPID%]', '{CPID}'), $crow["acontent_id"], $CNT_TMP );
 
                    // trigger content part functions
                    $CNT_TMP = trigger_cp($CNT_TMP, $crow);
 
                    // Space after
                    $CNT_TMP .= $space['after'];
 
                }
                mysql_free_result($cresult);
            }
        }
    }
 
    if(empty($phpwcms["allow_cntPHP_rt"])) {
        $CNT_TMP = remove_unsecure_rptags($CNT_TMP);
 
    //+KH: 05.04.2010
    } else
        // include external PHP script (also normal HTML snippets) or return PHP var value +KH: 04.04.2010
        $CNT_TMP = render_PHPcode($CNT_TMP);
 
    // parses all system RTs
    $CNT_TMP = html_parser($CNT_TMP);
 
    // Special for eMail mailto:....
    if ( ($phpwcms["allow_ext_render"]) AND (strpos($CNT_TMP, 'mailto:') != false) ) {
 
        // try to include custom functions and replacement tags or what you want to do at this point of the script
        // default dir: "phpwcms_template/inc_script/frontend_render"; only *.php files are allowed there
        if ( is_file(PHPWCMS_TEMPLATE.'inc_script/frontend_render/makeEmailSpamSave.php') ) {
 
            include_once(PHPWCMS_TEMPLATE.'inc_script/frontend_render/makeEmailSpamSave.php');
            $CNT_TMP = replaceEmailAddress($CNT_TMP);
        }
    }
 
    return $CNT_TMP;
}
 
 
   function func_WRAP_SHOW_CONTENTX($my_param) {
 
      $my_param = str_replace(' ','',$my_param); // kill all spaces
 
      // explode parameter for SHOW_CONTENT and the optional class name
      // $my_arr[0] = SHOW_CONTENT parameter
      // $my_arr[1] = optional own class name
      $my_arr = explode(":",$my_param);
 
      if (!empty($my_arr[1])) { $my_class = $my_arr[1]; }    // custom class name = yes
      else {$my_class = 'WRAP_SHOW_CONTENTX'; }            // custom class name = no -> default name
 
      // set the wrapper code
      $div_before = '<div class="'.$my_class.'">'.LF;
      $div_behind = LF.'</div>';
 
      $string = '';
      $string = showSelectedContentX($my_arr[0]);    // same as SHOW_CONTENT
 
      // +KH 19.01.11 parse SHOW_CONTENT a second time
      while (strpos($string, '{SHOW_CONTENT:') != false)
         $string = preg_replace('/\{SHOW_CONTENT:(.*?)\}/e', 'showSelectedContent("$1");', $string);
 
 
      // Set the wrapper around
      if (!$string == '') { $my_replace  = $div_before.$string.$div_behind; }
      else { $my_replace = ''; }
 
   return $my_replace;
}
 
// And do it ======
$content["all"] = preg_replace('/{WRAP_SHOW_CONTENTX:(.*?)}/e', 'func_WRAP_SHOW_CONTENTX("$1")', $content["all"]);
 
}
?>
english/phpwcms_replacer_rts/frontend_render/wrap_show_contentx.txt · Last modified: 2018/06/03 18:09 (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