[ Index ]

PHP Cross Reference of phpwcms V1.5.0 _r431 (28.01.12)

title

Body

[close]

/include/inc_front/ -> content.func.inc.php (source)

   1  <?php
   2  /*************************************************************************************
   3     Copyright notice
   4     
   5     (c) 2002-2012 Oliver Georgi <oliver@phpwcms.de> // All rights reserved.
   6   
   7     This script is part of PHPWCMS. The PHPWCMS web content management system is
   8     free software; you can redistribute it and/or modify it under the terms of
   9     the GNU General Public License as published by the Free Software Foundation;
  10     either version 2 of the License, or (at your option) any later version.
  11    
  12     The GNU General Public License can be found at http://www.gnu.org/copyleft/gpl.html
  13     A copy is found in the textfile GPL.txt and important notices to the license 
  14     from the author is found in LICENSE.txt distributed with these scripts.
  15    
  16     This script is distributed in the hope that it will be useful, but WITHOUT ANY 
  17     WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
  18     PARTICULAR PURPOSE.  See the GNU General Public License for more details.
  19   
  20     This copyright notice MUST APPEAR in all copies of the script!
  21  *************************************************************************************/
  22  
  23  // ----------------------------------------------------------------
  24  // obligate check for phpwcms constants
  25  if (!defined('PHPWCMS_ROOT')) {
  26     die("You Cannot Access This Script Directly, Have a Nice Day.");
  27  }
  28  // ----------------------------------------------------------------
  29  
  30  //predefine values
  31  
  32  $content['cat']                    = '';
  33  $content['metakey']                = '';
  34  $content['struct']                = get_struct_data(); //reads the complete structure as array
  35  $content['article_date']        = time();
  36  $content['redirect']            = array('code' => '');
  37  $content['all_keywords']        = '';
  38  $content['globalRT']            = array();
  39  $content['aId_CpPage']            = 0; // set default content part pagination page (0 and 1) are the same
  40  $content['CpTrigger']            = array(); // array to hold content part trigger functions
  41  $content['404error']            = false;
  42  $content['set_canonical']        = false;
  43  $content['cptab']                = array(); // array to hold content part based tabs
  44  $pagelayout                        = array();
  45  $no_content_for_this_page        = 0;
  46  $alias                            = '';
  47  $PERMIT_ACCESS                    = true; // by default set all content without permissions
  48  $CUSTOM                            = array(); // var that holds result of content part "php var"
  49  
  50  //method to get the right action values
  51  //if there is only the ?alias try to find the right category
  52  if(isset($_GET["id"])) {
  53  
  54      $aktion = explode(',', $_GET["id"], 6);
  55      $aktion[0] = intval($aktion[0]); //$aktion[0] will be always available
  56      $aktion[1] = isset($aktion[1]) ? intval($aktion[1]) : 0;
  57      $aktion[2] = isset($aktion[2]) ? intval($aktion[2]) : 0;
  58      $aktion[3] = isset($aktion[3]) ? intval($aktion[3]) : 1;
  59      $aktion[4] = isset($aktion[4]) ? intval($aktion[4]) : 0;
  60      $aktion[5] = isset($aktion[5]) ? intval($aktion[5]) : 0;
  61      
  62      // check if article category is given and available
  63      if(!isset($content['struct'][ $aktion[0] ])) {
  64          $aktion[0] = 0;
  65          // OK in case not we should check if given article ID is correct
  66          if($aktion[1]) {
  67              $sql  =    'SELECT article_id, article_cid FROM '.DB_PREPEND.'phpwcms_article WHERE ';
  68              $sql .= 'article_deleted=0 AND article_aktiv=1 AND article_id='.$aktion[1].' LIMIT 1';
  69              $aktion[1] = 0; //reset
  70              if($result = mysql_query($sql, $db)) {
  71                  if($row = mysql_fetch_row($result)) {
  72                      $aktion[0] = $row[1];
  73                      $aktion[1] = $row[0];
  74                  }
  75                  mysql_free_result($result);
  76              }
  77          }
  78          $GLOBALS['_getVar']['id'] = implode(',', $aktion);
  79          headerRedirect(PHPWCMS_URL.'index.php'.returnGlobalGET_QueryString(), 404);
  80      }
  81  
  82  } elseif(isset($_GET['aid'])) {
  83      // try to find correct structure
  84      $aktion = array(0,0,0,0,1,0);
  85  
  86      $_GET['aid']            = explode('-', $_GET['aid'], 2);    // now check for cp pagination
  87      $content['aId_CpPage']    = isset($_GET['aid'][1]) ? intval($_GET['aid'][1]) : 0; // set cp paginate page
  88      $_GET['aid']            = intval($_GET['aid'][0]);
  89      if($_GET['aid']) {
  90          $sql  =    'SELECT article_cid FROM '.DB_PREPEND.'phpwcms_article WHERE ';
  91          $sql .= 'article_deleted=0 ';
  92          if(VISIBLE_MODE !== 2) {
  93              $sql .= 'AND article_aktiv=1 AND article_public=1 ';
  94          } elseif(VISIBLE_MODE === 1) {
  95              $sql .= 'AND article_uid='.intval($_SESSION["wcs_user_id"]).' ';
  96          }
  97          $sql .= 'AND article_id='.$_GET['aid'].' LIMIT 1';
  98          if($result = mysql_query($sql, $db)) {
  99              if($row = mysql_fetch_row($result)) {
 100                  $aktion[0] = $row[0];
 101                  $aktion[1] = $_GET['aid'];
 102              } else {
 103                  $content['404error'] = true;
 104              }
 105              mysql_free_result($result);
 106          } else {
 107              $content['404error'] = true;
 108          }
 109      }
 110      if(!$aktion[1]) {
 111          $content['aId_CpPage']    = 0;    // no article = no pagination
 112      }
 113  
 114  } else {
 115      // check the alias
 116      $aktion = array(0,0,0,1,0,0);
 117  
 118      if(count($GLOBALS['_getVar'])) {
 119          reset($GLOBALS['_getVar']);
 120          $alias = trim(key($GLOBALS['_getVar']));
 121          if($alias && $GLOBALS['_getVar'][$alias] === '') { // alias must be empty ""
 122          
 123              $where_alias = aporeplace($alias);
 124              
 125              // we have to check against MySQL < 4.0 -> UNION unknown
 126              // so use a workaround
 127              
 128              if(PHPWCMS_DB_VERSION < 40000) {
 129              
 130                  $sql  = "SELECT acat_id, (0) AS article_id, 1 AS aktion3, 0 AS aktion4 FROM " . DB_PREPEND . "phpwcms_articlecat ";
 131                  $sql .= "WHERE acat_trash=0 AND acat_aktiv=1 AND acat_alias='" . $where_alias . "' LIMIT 1";
 132                  
 133                  $row = _dbQuery($sql);
 134                  
 135                  if(!isset($row[0]['acat_id'])) {
 136                      
 137                      $sql  = "SELECT article_cid AS acat_id, article_id, 0 AS aktion3, 1 AS aktion4 FROM " . DB_PREPEND . "phpwcms_article ";
 138                      $sql .= "WHERE article_deleted=0 AND article_aktiv=1 AND article_alias='" . $where_alias . "' LIMIT 1";
 139                  
 140                      $row = _dbQuery($sql);
 141                  
 142                  }
 143              
 144              } else {
 145          
 146                  $sql  = "(SELECT acat_id, (0) AS article_id, 1 AS aktion3, 0 AS aktion4 FROM " . DB_PREPEND . "phpwcms_articlecat ";
 147                  $sql .= "WHERE acat_trash=0 AND acat_aktiv=1 AND acat_alias='" . $where_alias . "')";             
 148                  $sql .= " UNION ";
 149                  $sql .= "(SELECT article_cid AS acat_id, article_id, 0 AS aktion3, 1 AS aktion4 FROM " . DB_PREPEND . "phpwcms_article ";
 150                  $sql .= "WHERE article_deleted=0 AND article_aktiv=1 AND article_alias='" . $where_alias . "') ";
 151                  $sql .= "LIMIT 1";
 152              
 153                  $row = _dbQuery($sql);
 154                      
 155              }
 156              
 157              if(isset($row[0]['acat_id'])) {
 158              
 159                  $aktion[0] = $row[0]['acat_id'];
 160                  $aktion[1] = $row[0]['article_id'];
 161                  $aktion[3] = $row[0]['aktion3'];
 162                  $aktion[4] = $row[0]['aktion4'];
 163                          
 164                  define('PHPWCMS_ALIAS', $alias);
 165              
 166              } elseif($alias == $indexpage['acat_alias']) {
 167              
 168                  define('PHPWCMS_ALIAS', $alias);
 169              
 170              } else {
 171              
 172                  $content['404error'] = true;
 173              
 174              }
 175              
 176          }
 177      }
 178      
 179  }
 180  if(isset($_GET['print'])) {
 181  
 182      $aktion[2] = 1;
 183      define('PRINT_PDF', intval($_GET['print']) == 2 ? true : false);
 184      unset($_getVar['print'], $_GET['print']);
 185  
 186  }
 187  
 188  // define special OUTPUT format/action
 189  $phpwcms['output_action'] = false;
 190  if(!empty($_GET['phpwcms_output_action']) || !empty($_POST['phpwcms_output_action'])) {
 191  
 192      // split by function - value: F-function1|function2|function3--S-SECT1|SECT2|SECT3
 193      $phpwcms['output_action']    = explode('--', clean_slweg( empty($_GET['phpwcms_output_action']) ? $_POST['phpwcms_output_action'] : $_GET['phpwcms_output_action'] ));
 194      unset(
 195          $_GET['phpwcms_output_action'],
 196          $_POST['phpwcms_output_action'],
 197          $_getVar['phpwcms_output_action']
 198      );
 199      
 200      if(is_array($phpwcms['output_action'])) {
 201          
 202          $phpwcms['output_function']    = array();
 203          $phpwcms['output_section']    = array();
 204          
 205          foreach($phpwcms['output_action'] as $value) {
 206              
 207              $value = trim($value);
 208              if($value{0} == 'F') {
 209                  $value = explode('|', substr($value, 2));
 210                  $output_key = 'output_function';
 211              } elseif($value{0} == 'S') {
 212                  $value = explode('|', substr($value, 2));
 213                  $output_key = 'output_section';
 214              } else {
 215                  continue;
 216              }
 217  
 218              if(is_array($value)) {
 219              
 220                  foreach($value as $_value) {
 221                      
 222                      $_value = trim($_value);
 223                      
 224                      if($_value != '') {
 225                          $phpwcms[$output_key][$_value] = $_value;
 226                      }
 227                  }
 228              }
 229          }
 230          
 231          $phpwcms['output_action'] = count($phpwcms['output_function']) || count($phpwcms['output_section']) ? true : false;
 232  
 233      } else {
 234          $phpwcms['output_action'] = false;
 235      }
 236  }
 237  
 238  
 239  //define the current article category ID
 240  $content["cat_id"]    = $aktion[0];
 241  $content['body_id']    = $content["cat_id"];
 242  
 243  // check if current level is a redirect level
 244  if(!empty($content['struct'][ $content["cat_id"] ]['acat_redirect'])) {
 245      $redirect = get_redirect_link( $content['struct'][ $content["cat_id"] ]['acat_redirect'] );
 246      headerRedirect($redirect['link'], 301);
 247  }
 248  
 249  //try to find current tree depth
 250  $LEVEL_ID          = array();
 251  $LEVEL_KEY         = array();
 252  $LEVEL_STRUCT    = array();
 253  $level_ID_array    = get_breadcrumb($content["cat_id"], $content['struct']);
 254  $level_count    = 0;
 255  foreach($level_ID_array as $key => $value) {
 256      $LEVEL_ID[$level_count]        = $key;
 257      $LEVEL_KEY[$key]             = $level_count;
 258      $LEVEL_STRUCT[$level_count]    = $content['struct'][$key]['acat_name'];
 259      if($PERMIT_ACCESS && $content['struct'][$key]['acat_regonly']) {
 260          $PERMIT_ACCESS            = false; // only users have been logged in get access
 261      } 
 262      $level_count++;
 263  }
 264  
 265  define('PERMIT_ACCESS', $PERMIT_ACCESS);
 266  // frontend login check
 267  _checkFrontendUserAutoLogin();
 268  
 269  // -------------------------------------------------------------
 270  
 271  // read the template information for page based on structure
 272  if($content["struct"][ $content["cat_id"] ]["acat_template"]) {
 273      //if there is a template defined for this structure level
 274      //then choose the template information based on this ID
 275      $sql  = "SELECT template_var FROM ".DB_PREPEND."phpwcms_template WHERE template_trash=0 AND ";
 276      $sql .= "template_id=".$content["struct"][ $content["cat_id"] ]["acat_template"]." LIMIT 1;";
 277      if($result = mysql_query($sql, $db)) {
 278          if($row = mysql_fetch_row($result)) {
 279              $block = unserialize($row[0]);
 280          }
 281          mysql_free_result($result);
 282      }
 283  }
 284  if(!isset($block)) {
 285      // if template ID is not defined or the were a problem with level's template ID then
 286      // choose the default template or if no default template defined choose the next one
 287      $sql  = "SELECT template_var FROM ".DB_PREPEND."phpwcms_template ";
 288      $sql .= "WHERE template_trash=0 ORDER BY template_default DESC LIMIT 1;";
 289      if($result = mysql_query($sql, $db)) {
 290          if($row = mysql_fetch_row($result)) {
 291              $block = unserialize($row[0]);
 292          }
 293          mysql_free_result($result);
 294      }
 295  }
 296  
 297  // compatibility for older releases where only 
 298  // 1 css file could be stored per template
 299  if(is_string($block['css'])) {
 300      $block['css'] = array($block['css']);
 301  }
 302  // check if template_defaults should be overwritten
 303  if(!empty($block['overwrite'])) {
 304      $block['overwrite'] = str_replace('/', '', $block['overwrite']);
 305      @include(PHPWCMS_TEMPLATE.'inc_settings/template_default/'.$block['overwrite']);
 306  }
 307  if(!empty($content['struct'][ $content['cat_id'] ]['acat_overwrite'])) {
 308      $block['overwrite'] = str_replace('/', '', $content['struct'][ $content['cat_id'] ]['acat_overwrite']);
 309      @include(PHPWCMS_TEMPLATE.'inc_settings/template_default/'.$block['overwrite']);
 310  }
 311  
 312  // load frontend JavaScript lib file
 313  require  PHPWCMS_ROOT.'/include/inc_front/js.inc.php';
 314  
 315  // -------------------------------------------------------------
 316  
 317  // retrieve pagelayout info
 318  // check how the content should be rendered based on pagelayout render value
 319  $block["layout"] = intval($block["layout"]);
 320  $sql  = "SELECT pagelayout_var FROM ".DB_PREPEND."phpwcms_pagelayout WHERE pagelayout_trash=0 ";
 321  $sql .= $block["layout"] ? "AND pagelayout_id=".$block["layout"] : "ORDER BY pagelayout_default DESC";
 322  $sql .= " LIMIT 1";
 323  $result = _dbQuery($sql);
 324  if(isset($result[0]['pagelayout_var'])) {
 325      $pagelayout = @unserialize($result[0]['pagelayout_var']);
 326      // if print action
 327      if($aktion[2] === 1) {
 328          $pagelayout = array('layout_title' => $pagelayout['layout_title'], 'layout_customblocks' => $pagelayout['layout_customblocks']);
 329      }
 330  }
 331  if(empty($pagelayout)) {
 332      // if no pagelayout could be found
 333      die('There is no pagelayout available. Please <a href="'.
 334          PHPWCMS_URL.get_login_file().'">login</a> to the admin section and <a href="'.
 335          PHPWCMS_URL.'phpwcms.php?do=admin&p=8">create one here</a>!');
 336  }
 337  // Pagetitle
 338  $content["pagetitle"] = empty($pagelayout["layout_title"]) ? '' : $pagelayout["layout_title"];
 339  
 340  //generate the colspan attribute
 341  $colspan = get_colspan($pagelayout);
 342  
 343  // -------------------------------------------------------------
 344  
 345  // now initialize content blocks like CONTENT, HEADER, LEFT, RIGHT, FOOTER
 346  $content['main']            = ''; // {CONTENT}
 347  $content['CB']['LEFT']        = ''; // {LEFT}
 348  $content['CB']['RIGHT']        = ''; // {RIGHT}
 349  $content['CB']['HEADER']    = ''; // {HEADER}
 350  $content['CB']['FOOTER']    = ''; // {FOOTER}
 351  // and try to add and initialize custom blocks
 352  if(!empty($pagelayout['layout_customblocks'])) {
 353      $custom_blocks = explode(', ', $pagelayout['layout_customblocks']);
 354      foreach($custom_blocks as $value) {
 355          if($value != '') $content['CB'][$value] = '';
 356      }
 357      unset($custom_blocks);
 358  }
 359  
 360  // -------------------------------------------------------------
 361  
 362  // try to include custom functions or what ever you want to do at this point of the script
 363  // default dir: "phpwcms_template/inc_script/frontend_init"; only *.php files are allowed there
 364  if($phpwcms["allow_ext_init"]) {
 365      if(count($custom_includes = get_tmpl_files(PHPWCMS_TEMPLATE.'inc_script/frontend_init', 'php'))) {
 366          foreach($custom_includes as $value) {
 367              include_once(PHPWCMS_TEMPLATE.'inc_script/frontend_init/'.$value);
 368          }
 369      }
 370  }
 371  // include custom frontend init scripts based on module definitions
 372  if(count($phpwcms['modules_fe_init'])) {
 373      foreach($phpwcms['modules_fe_init'] as $value) {
 374          include_once($value);
 375      }
 376  }
 377  
 378  // redirect to login form if user is not logged in and has no permission to access level
 379  if(!PERMIT_ACCESS && !_getFeUserLoginStatus()) {
 380  
 381      if(!empty($block['feloginurl'])) {
 382          $template_default['login_form_url'] = str_replace('{SITE}', PHPWCMS_URL, $block['feloginurl']);
 383      } elseif(empty($template_default['login_form_url'])) {
 384          $template_default['login_form_url'] = PHPWCMS_URL;
 385      }
 386      
 387      // store current URL
 388      $_SESSION['LOGIN_REDIRECT'] = decode_entities(FE_CURRENT_URL);
 389      
 390      // redirect to login form
 391      headerRedirect($template_default['login_form_url'], 401);
 392  }
 393  
 394  // -------------------------------------------------------------
 395  
 396  //reads all articles for active cat into array
 397  $content["articles"]            = get_actcat_articles_data($content["cat_id"]);
 398  $content["article_list_count"]    = count($content["articles"]);
 399  
 400  // -------------------------------------------------------------
 401  
 402  // generating a list of articles inside the current article category
 403  if(!$aktion[4]) {
 404      
 405      if(!$content['404error'] && ($content["article_list_count"] || $content['struct'][ $content['cat_id'] ]['acat_topcount'] == -1)) {
 406          
 407          if($content["article_list_count"] == 1 || $content['struct'][ $content['cat_id'] ]['acat_topcount'] == -1) {
 408              // if($temp_counter == 1) {
 409              // if only 1 article for this category available
 410              // then show this article directly
 411              // sets article ID to this only 1 article
 412              foreach($content["articles"] as $key => $value) {
 413                  $aktion[1] = intval($key);
 414                  break;
 415              }
 416              $aktion[4] = 1; // this needs to be set to 1 for showing the article
 417              
 418              // enable canonical <link> tag
 419              $content['set_canonical'] = true;
 420  
 421          } else {
 422              // there is more than 1 article inside this category
 423              // -> list all - the 1st will be shown with summary and such stuff
 424              $content["main"] .= list_articles_summary();
 425  
 426          }
 427      
 428      } else {
 429  
 430          $no_content_for_this_page = 1;
 431  
 432      }
 433  
 434  } elseif($content["article_list_count"] === 1) {
 435  
 436      // enable canonical <link> tag
 437      $content['set_canonical'] = true;
 438  
 439  }
 440  
 441  // -------------------------------------------------------------
 442  
 443  // check if current category should be cached
 444  if($content['struct'][$content['cat_id']]['acat_timeout'] != '') {
 445      $phpwcms['cache_timeout'] = $content['struct'][$content['cat_id']]['acat_timeout'];
 446  }
 447  // set search status for current category
 448  $cache_searchable = $content['struct'][$content['cat_id']]['acat_nosearch'];
 449  
 450  // -------------------------------------------------------------
 451  
 452  $content['list_mode'] = true;
 453  
 454  if($aktion[1]) {
 455  
 456      // render page based on article
 457      include_once (PHPWCMS_ROOT."/include/inc_front/content.article.inc.php");
 458      $content['list_mode'] = false;
 459  
 460  } elseif(!empty($content['struct'][$content['cat_id']]['acat_pagetitle'])) {
 461  
 462      // a custom pagetitle for structure level exists
 463      $content["pagetitle"] = $content['struct'][$content['cat_id']]['acat_pagetitle'];
 464  
 465  } else {
 466  
 467      $content["pagetitle"] = setPageTitle($content["pagetitle"], $content['struct'][$content['cat_id']]['acat_name'], '');
 468  
 469  }
 470  
 471  // -------------------------------------------------------------
 472  
 473  //check for no content error
 474  $content["main"] = trim($content["main"]);
 475  if($content['404error'] || $no_content_for_this_page || $content["main"] == '') {
 476      header('HTTP/1.0 404 Not Found');
 477      $content["main"] .= $block["errortext"];
 478  }
 479  
 480  // -------------------------------------------------------------
 481  
 482  //check if one of needed block texts and values are empty and if then fill with content
 483  if(!$block["maintext"]) {
 484      $block["maintext"] = $content["main"];
 485  }
 486  
 487  // -------------------------------------------------------------
 488  
 489  //normal page operation
 490  if($aktion[2] == 0) {
 491      
 492      switch($pagelayout["layout_render"]) {
 493      
 494          case 0:    //create the page layout table (header, left, content, right, footer)
 495                  $content["all"]  = "<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\"";    //start main table
 496                  $content["all"] .= td_attributes($pagelayout, "all", 0);
 497                  $content["all"] .= align_base_layout($pagelayout["layout_align"])." summary=\"\">".LF;        // align table
 498  
 499                  //header
 500                  $content["all"] .= colspan_table_row($pagelayout, "header", $colspan, $block["headertext"]); //header row
 501                  if($pagelayout["layout_topspace_height"]) { //header space
 502                      $content["all"] .= colspan_table_row($pagelayout, "topspace", $colspan, spacer(1, $pagelayout["layout_topspace_height"]));
 503                  }
 504  
 505                  //returns the main blocks: left column, content column, right column
 506                  $content["all"] .= get_table_block($pagelayout, $block["maintext"], $block["lefttext"], $block["righttext"]);
 507  
 508                  //footer
 509                  if($pagelayout["layout_bottomspace_height"]) { //bottom space
 510                      $content["all"] .= colspan_table_row($pagelayout, "bottomspace", $colspan, spacer(1, $pagelayout["layout_bottomspace_height"]));
 511                  }
 512                  $content["all"] .= colspan_table_row($pagelayout, "footer", $colspan, $block["footertext"]); //footer row
 513                  $content["all"] .= '</table>'.LF; //end main table
 514                  
 515                  break;
 516          
 517                  
 518          case 1:    //create the page layout based on DIV (layer)
 519          
 520                  //contentContainer DIV start
 521                  $content["all"] = '';
 522                  $pagelayout['additional_wrap_div'] = false;
 523                  switch($pagelayout["layout_align"]) {
 524                      case 1:        $content["all"] .= '<div align="center" style="margin:0;padding:0;">';
 525                                  $pagelayout['additional_wrap_div'] = true;
 526                                  break;
 527                      case 2:        $content["all"] .= '<div align="right" style="margin:0;padding:0;">';
 528                                  $pagelayout['additional_wrap_div'] = true;
 529                                  break;
 530                  }
 531                  $content["all"] .= '<div id="container">'.LF;
 532          
 533                  //header DIV
 534                  if($block["headertext"] || $pagelayout['layout_header_height']) {
 535                      $content["all"] .= '    <div id="headerBlock">'.$block["headertext"]."</div>\n";
 536                  }
 537                  //left DIV if 3column or 2column (with left block)
 538                  if($pagelayout["layout_type"] == 0 || $pagelayout["layout_type"] == 1) {
 539                      $content["all"] .= '    <div id="leftBlock">'.$block["lefttext"]."</div>\n";
 540                  }
 541                  //right DIV if 3column or 2column (with right block)
 542                  if($pagelayout["layout_type"] == 0 || $pagelayout["layout_type"] == 2) {
 543                      $content["all"] .= '    <div id="rightBlock">'.$block["righttext"]."</div>\n";
 544                  }
 545                  //main block
 546                  $content["all"] .= '<div id="mainBlock">'.$block["maintext"]."</div>\n";
 547                  //footer DIV
 548                  if($block["footertext"] || $pagelayout['layout_footer_height']) {
 549                      $content["all"] .= '    <div id="footerBlock">'.$block["footertext"]."</div>\n";
 550                  }
 551                  //contentContainer DIV end
 552                  if($pagelayout['additional_wrap_div']) {
 553                      $content["all"] .= "</div>";
 554                  }
 555                  $content["all"] .= "</div>\n";
 556          
 557                  break;
 558          
 559          
 560          case 2: //create the page layout based only on the content of main block
 561                  $content["all"]    = $block["maintext"];
 562                  
 563                  break;
 564      
 565      }
 566  
 567  } elseif ($aktion[2] == 1) {
 568  
 569      //if print layout should be shown
 570      $_print_tmpl = PRINT_PDF ? 'pdf' : 'print';
 571      $content['all'] = is_file(PHPWCMS_TEMPLATE.'inc_default/'.$_print_tmpl.'.tmpl') ? @file_get_contents(PHPWCMS_TEMPLATE.'inc_default/'.$_print_tmpl.'.tmpl') : '{CONTENT}<hr />{CURRENT_URL}';
 572      if(PRINT_PDF) {
 573          $_print_settings    = get_tmpl_section('PDF_SETTINGS', $content['all']);
 574          $content['all']        = replace_tmpl_section('PDF_SETTINGS', $content['all']);
 575          $_print_settings    = parse_ini_str($_print_settings, false);
 576      }
 577      
 578      if($content['all']) {
 579          $content["all"]    = str_replace('{CURRENT_URL}', abs_url(), $content["all"]);
 580          $content["all"]    = str_replace('{CONTENT}', $block["maintext"], $content["all"]);
 581      } else {
 582          $content['all']    = $block["maintext"];
 583      }
 584      
 585  }
 586  
 587  // -------------------------------------------------------------
 588  
 589  // Render possible PHP Values in category or article keyword field
 590  $content["struct"][$aktion[0]]["acat_info"] = render_PHPcode($content["struct"][$aktion[0]]["acat_info"]);
 591  if(!empty($content["articles"][$aktion[1]]["article_keyword"]) && strpos($content["articles"][$aktion[1]]["article_keyword"], 'PHP') !== FALSE) {
 592      $content["articles"][$aktion[1]]["article_keyword"]    = render_PHPcode($content["articles"][$aktion[1]]["article_keyword"]);
 593  }
 594  
 595  // -------------------------------------------------------------
 596  
 597  // put in the complete rendered content
 598  $content["all"] = str_replace('{CONTENT}', $content["main"], $content["all"]);
 599  // put in custom rendered content
 600  foreach($content['CB'] as $key => $value) {
 601      //first check content of custom block in current template
 602      if(isset($block['customblock_'.$key]) && $block['customblock_'.$key] !== '' && $value !== '') {
 603          $value = str_replace('{'.$key.'}', $value, $block['customblock_'.$key]);
 604      }
 605      $content["all"] = str_replace('{'.$key.'}', $value, $content["all"]);
 606  }
 607  
 608  // render Tab replacement code
 609  if(count($content['cptab'])) {
 610      foreach($content['cptab'] as $CNT_TAB => $trow) {
 611          $content['all'] = str_replace('<!-- ' . $CNT_TAB . ' -->', $trow, $content['all']);
 612      }
 613  }
 614  
 615  // check layout for list mode sections or detail view
 616  if(strpos($content['all'], '_LIST_MODE')) {
 617      $content['all'] = replace_tmpl_section( ($content['list_mode'] ? 'ELSE_LIST_MODE' : 'IF_LIST_MODE') , $content['all']);
 618      $content['all'] = str_replace(array('<!--ELSE_LIST_MODE_START//-->', '<!--ELSE_LIST_MODE_END//-->', '<!--IF_LIST_MODE_START//-->', '<!--IF_LIST_MODE_END//-->'), '', $content['all']);
 619  }
 620  
 621  // Initial Render Device
 622  $content['all'] = render_device($content['all']);
 623  
 624  // search for specific article ID and or category ID and replace it
 625  $content['all'] = str_replace('{CURRENT_ARTICLEID}', $aktion[1], $content['all']);
 626  $content['all'] = str_replace('{CURRENT_CATEGORYID}', $aktion[0], $content['all']);
 627  
 628  // search for level related replacement tags and replace it, sample: {LEVEL2_ID}
 629  $content['all'] = preg_replace_callback('/\{LEVEL(\d+)_ID\}/', 'replace_level_id', $content['all']);
 630  
 631  // {SHOW_CONTENT:MODE,id[,id[,...]]}
 632  if( ! ( strpos($content["all"],'{SHOW_CONTENT:')===false ) ) {
 633      $content["all"] = preg_replace('/\{SHOW_CONTENT:(.*?)\}/e', 'showSelectedContent("$1");', $content["all"]);
 634  }
 635  
 636  // -------------------------------------------------------------
 637  
 638  // include external PHP script (also normal HTML snippets) or return PHP var value
 639  if(strpos($content["all"],'PHP') !== false) {
 640      $content["all"] = render_PHPcode($content["all"]);
 641  }
 642  
 643  // -------------------------------------------------------------
 644  
 645  //breadcrumb replacement
 646  if(strpos($content["all"],'{BREADCRUMB') !== false) {
 647      $content["all"] = str_replace('{BREADCRUMB}', '{BREADCRUMB:0}', $content["all"]);
 648      $replace = 'breadcrumb($content["cat_id"], $content["struct"], $1, $template_default["breadcrumb_spacer"]);';
 649      $content["all"] = preg_replace('/\{BREADCRUMB:(\d+)\}/e', $replace, $content["all"]);
 650  }
 651  
 652  // -------------------------------------------------------------
 653  
 654  // Simple row based navigation
 655  if(strpos($content["all"],'{NAV_ROW') !== false) {
 656      $content["all"] = str_replace('{NAV_ROW}', nav_level_row(0), $content["all"]);
 657      $content["all"] = preg_replace('/\{NAV_ROW:(\w+|\d+):(0|1)\}/e',"nav_level_row('$1',$2);",$content["all"]);
 658  }
 659  
 660  // -------------------------------------------------------------
 661  
 662  // Simple Navigation table
 663  if(strpos($content["all"],'{NAV_TABLE_SIMPLE}') !== false) {
 664      $replace = nav_table_simple_struct($content["struct"], $content["cat_id"]);
 665      $content["all"] = str_replace('{NAV_TABLE_SIMPLE}', $replace, $content["all"]);
 666  }
 667  
 668  // -------------------------------------------------------------
 669  
 670  // Left table based rollover navigation
 671  if(strpos($content["all"],'{NAV_TABLE_COLUMN') !== false) {
 672      $content["all"] = str_replace('{NAV_TABLE_COLUMN}', '{NAV_TABLE_COLUMN:0}', $content["all"]);
 673      $replace = 'nav_table_struct($content["struct"], $content["cat_id"], "$1", $template_default["nav_table_struct"]);';
 674      $content["all"] = preg_replace('/\{NAV_TABLE_COLUMN:(\d+)\}/e', $replace, $content["all"]);
 675  }
 676  
 677  // -------------------------------------------------------------
 678  
 679  // some list based navigations
 680  if(strpos($content["all"],'{NAV_LIST') !== false) {
 681  
 682      //reads all active category IDs beginning with the current cat ID - without HOME
 683      $content["cat_path"] = get_active_categories($content["struct"], $content["cat_id"]);
 684  
 685      // some general list replacements first
 686      $content["all"] = str_replace('{NAV_LIST}', '{NAV_LIST:0}', $content["all"]);
 687      $content["all"] = str_replace('{NAV_LIST_TOP}', css_level_list($content["struct"], $content["cat_path"], 0, '', 1), $content["all"]);
 688      $content["all"] = str_replace('{NAV_LIST_CURRENT}', css_level_list($content["struct"],$content["cat_path"],$content["cat_id"]), $content["all"]);
 689      
 690      // build complete menu structure starting at a specific ID
 691      // {NAV_LIST_UL:Parameter} Parameter: "menu_type, start_id, class_path, class_active, ul_id_name"
 692      $content["all"] = preg_replace('/\{NAV_LIST_UL:(.*?)\}/e', 'buildCascadingMenu("$1");', $content["all"]);
 693  
 694      // list based navigation starting at given level
 695      $replace = 'nav_list_struct($content["struct"],$content["cat_id"],"$1", "$2");';
 696      $content["all"] = preg_replace('/\{NAV_LIST:(\d+):{0,1}(.*){0,1}\}/e', $replace, $content["all"]);
 697      
 698      // List based navigation with Top Level - default settings
 699      // creates a list styled top nav menu, + optional Home | {NAV_LIST_TOP:home_name:class_name} | default class name = list_top
 700      $content["all"] = preg_replace('/\{NAV_LIST_TOP:(.*?):(.*?)\}/e', 'css_level_list($content["struct"], $content["cat_path"], 0, "$1", 1, "$2")', $content["all"]);
 701      
 702      // List based navigation with Top Level - default settings
 703      // creates a list styled nav menu of current level {NAV_LIST_CURRENT:1:back_name:class_name} | default class name = list_top
 704      $content["all"] = preg_replace('/\{NAV_LIST_CURRENT:(\d+):(.*?):(.*?)\}/e', 'css_level_list($content["struct"],$content["cat_path"],$content["cat_id"],"$2","$1","$3")', $content["all"]);
 705  }
 706  
 707  // -------------------------------------------------------------
 708  
 709  // date replacement
 710  if(strpos($content["all"],'{DATE_') !== false) {
 711      $content["all"] = str_replace('{DATE_LONG}',    international_date_format($template_default["date"]["language"], $template_default["date"]["long"]),   $content["all"]);
 712      $content["all"] = str_replace('{DATE_MEDIUM}',  international_date_format($template_default["date"]["language"], $template_default["date"]["medium"]), $content["all"]);
 713      $content["all"] = str_replace('{DATE_SHORT}',   international_date_format($template_default["date"]["language"], $template_default["date"]["short"]),  $content["all"]);
 714      $content["all"] = str_replace('{DATE_ARTICLE}', international_date_format($template_default["date"]["language"], $template_default["date"]["article"],   $content["article_date"]),  $content["all"]);
 715  }
 716  
 717  // -------------------------------------------------------------
 718  
 719  // time replacement
 720  if(strpos($content["all"],'{TIME_') !== false) {
 721      $content["all"] = str_replace('{TIME_LONG}',    date($template_default["time"]["long"]) ,                            $content["all"] );
 722      $content["all"] = str_replace('{TIME_SHORT}',   date($template_default["time"]["short"]),                            $content["all"] );
 723      $content["all"] = str_replace('{TIME_ARTICLE}', date($template_default["time"]["short"] , $content["article_date"]), $content["all"] );
 724  }
 725  
 726  // -------------------------------------------------------------
 727  
 728  // replace custom search form input field and action with right target
 729  if(strpos($content["all"],'###search_input_action') !== false) {
 730      $content["all"] = str_replace('###search_input_field###', 'search_input_field', $content["all"]);
 731      $content["all"] = str_replace('###search_input_value###', (empty($content["search_word"]) ? '' : $content["search_word"]), $content["all"]);
 732      // create serahc form action
 733      if(strpos($content["all"],'###search_input_action:') !== false) {
 734          $content["all"] = preg_replace('/###search_input_action:(\d+)###/e','get_search_action("$1", $db);', $content["all"]);
 735      }
 736  }
 737  
 738  // -------------------------------------------------------------
 739  
 740  // related articles based on keywords, inspired by Magnar Stav Johanssen
 741  if(strpos($content["all"],'{RELATED:') !== false) {
 742      if (!$no_content_for_this_page && !empty($content["articles"][$aktion[1]]["article_keyword"])) {
 743          $related_keywords = $content["articles"][$aktion[1]]["article_keyword"];
 744      } else {
 745          $related_keywords = '';
 746      }
 747      $content["all"] = preg_replace('/\{RELATED:(\d+)\}/e','get_related_articles($related_keywords,$aktion[1],$template_default["related"],"$1",$db);',$content["all"]);
 748      $content["all"] = preg_replace('/\{RELATED:(\d+):(.*?)\}/e','get_related_articles("$2",$aktion[1],$template_default["related"],"$1",$db);',$content["all"]);
 749  }
 750  
 751  // -------------------------------------------------------------
 752  
 753  // all new article list sorted by date
 754  if(strpos($content["all"],'{NEW:') !== false) {
 755      $content["all"] = preg_replace('/\{NEW:(\d+):{0,1}(\d+){0,1}\}/e','get_new_articles($template_default["news"],"$1","$2",$db);',$content["all"]);
 756  }
 757  
 758  // -------------------------------------------------------------
 759  
 760  // some more general parsing 
 761  $content["all"]    = str_replace('{SITE}', PHPWCMS_URL, $content["all"]);
 762  $content["all"] = str_replace('{RSSIMG}', $template_default["rss"]["image"], $content["all"]);
 763  
 764  $content["all"] = html_parser($content["all"]);
 765  
 766  $content["all"] = preg_replace_callback('/\[img=(\d+)(.*?){0,1}\](.*?)\[\/img\]/i', 'parse_images', $content["all"]);
 767  $content["all"] = preg_replace_callback('/\[img=(\d+)(.*?){0,1}\]/i', 'parse_images', $content["all"]);
 768  $content["all"] = preg_replace_callback('/\[download=(.*?)\/\]/i', 'parse_downloads', $content["all"]);
 769  $content["all"] = preg_replace_callback('/\[download=(.*?)\](.*?)\[\/download\]/is', 'parse_downloads', $content["all"]);
 770  
 771  // -------------------------------------------------------------
 772  
 773  // create link to articles for found keywords
 774  $content["all"] = preg_replace('/\{KEYWORD:(.*?)\}/e', 'get_keyword_link("$1", $db);', $content["all"]);
 775  //}
 776  
 777  // -------------------------------------------------------------
 778  
 779  // include external HTML page but only part between <body></body>
 780  $content["all"] = preg_replace_callback('/\{URL:(.*?)\}/i', 'include_url', $content["all"]);
 781  
 782  // -------------------------------------------------------------
 783  
 784  // special browse the content links: UP, NEXT, PREVIOUS
 785  // echo get_index_link_up('UP')." | ".get_index_link_prev('PREV',1).' | '.get_index_link_next('NEXT',1);
 786  if(strpos($content["all"],'{BROWSE:') !== false) {
 787      $content["all"] = preg_replace('/\{BROWSE:UP:(.*?)\}/e','get_index_link_up("$1");',$content["all"]);
 788      $content["all"] = preg_replace('/\{BROWSE:NEXT:(.*?):(0|1)\}/e','get_index_link_next("$1",$2);',$content["all"]);
 789      $content["all"] = preg_replace('/\{BROWSE:PREV:(.*?):(0|1)\}/e','get_index_link_prev("$1",$2);',$content["all"]);
 790  }
 791  
 792  // -------------------------------------------------------------
 793  
 794  // replace all "hardcoded" global replacement tags
 795  if(count($content['globalRT'])) {
 796      foreach($content['globalRT'] as $key => $value) {
 797          if($key != '') {
 798              $content["all"] = str_replace($key, $value, $content["all"]);
 799          }
 800      }
 801  }
 802  
 803  // -------------------------------------------------------------
 804  
 805  // add possible redirection code (article summary) to $block["htmlhead"];
 806  $block["htmlhead"] = $content["redirect"]["code"] . render_PHPcode($block["htmlhead"]) . LF;
 807  
 808  // -------------------------------------------------------------
 809  
 810  
 811  if(!defined('PHPWCMS_ALIAS')) {
 812      define('PHPWCMS_ALIAS', empty($content['struct'][ $content["cat_id"] ]['acat_alias']) ? '' : $content['struct'][ $content["cat_id"] ]['acat_alias'] );
 813  }
 814  
 815  // try to include custom functions and replacement tags or what you want to do at this point of the script
 816  // default dir: "phpwcms_template/inc_script/frontend_render"; only *.php files are allowed there
 817  if($phpwcms["allow_ext_render"]) {
 818      if(count($custom_includes = get_tmpl_files(PHPWCMS_TEMPLATE.'inc_script/frontend_render', 'php'))) {
 819          foreach($custom_includes as $value) {
 820              include_once(PHPWCMS_TEMPLATE.'inc_script/frontend_render/'.$value);
 821          }
 822      }
 823  }
 824  if(count($phpwcms['modules_fe_render'])) {
 825      foreach($phpwcms['modules_fe_render'] as $value) {
 826          include_once($value);
 827      }
 828  }
 829  
 830  // Final Render Device
 831  $content['all'] = render_device($content['all']);
 832  
 833  // render frontend edit related content and JavaScript
 834  if(FE_EDIT_LINK) {
 835  
 836      init_frontend_edit_js();
 837      $content['all'] .= LF . '<div id="fe-link" class="disabled"></div>' . LF;
 838  
 839  }
 840  
 841  // insert description meta tag if not definied
 842  if(empty($block['custom_htmlhead']['meta.description']) && !empty($content["struct"][$aktion[0]]["acat_info"]) && !stristr($block["htmlhead"], '"description"')) {
 843      set_meta('description', $content["struct"][$aktion[0]]["acat_info"]);
 844  }
 845  // add structure level keywords
 846  if(!empty($content['struct'][ $content["cat_id"] ]['acat_keywords'])) {
 847      $content['all_keywords'] .= ', ' . $content['struct'][ $content["cat_id"] ]['acat_keywords'];
 848  }
 849  // insert keywords meta tag if not yet definied
 850  if(empty($block['custom_htmlhead']['meta.keywords']) && !empty($content['all_keywords']) && !stristr($block["htmlhead"], '"keywords"')) {
 851      $content['all_keywords'] = convertStringToArray($content['all_keywords']);
 852      if(count($content['all_keywords'])) {
 853          set_meta('keywords', implode(', ', $content['all_keywords']));
 854      }
 855  }
 856  $phpwcms["generator"] = PHPWCMS_VERSION . ' (r'.PHPWCMS_REVISION.')';
 857  set_meta('generator', 'phpwcms '.$phpwcms["generator"]);
 858  
 859  
 860  // replace Print URL
 861  if(strpos($content["all"], '[PRINT]') !== false) {
 862      $content["all"] = str_replace('[PRINT]', '<a href="'.rel_url(array('print'=>1),array(), PHPWCMS_ALIAS).'" target="_blank" rel="nofollow">', $content["all"]);
 863      $content["all"] = str_replace('[/PRINT]', '</a>', $content["all"]);
 864  }
 865  if(strpos($content["all"], '[PRINT_PDF]') !== false) {
 866      $content["all"] = str_replace('[PRINT_PDF]', '<a href="'.rel_url(array('print'=>2),array(), PHPWCMS_ALIAS).'" target="_blank" rel="nofollow">', $content["all"]);
 867      $content["all"] = str_replace('[/PRINT_PDF]', '</a>', $content["all"]);
 868  }
 869  
 870  // some article related "global" replacement tags
 871  if(isset($content['article_livedate'])) {
 872  
 873      $content['all'] = render_cnt_template($content['all'], 'AUTHOR', html_specialchars($content['article_username']));
 874      $content['all'] = render_cnt_date($content['all'], $content["article_date"], $content['article_livedate'], $content['article_killdate']);
 875      $content['all'] = render_cnt_template($content['all'], 'CATEGORY', $content['cat']);
 876  
 877  } else {
 878  
 879      $content['all'] = render_cnt_template($content['all'], 'AUTHOR', '');
 880      $content['all'] = render_cnt_date($content['all'], now(), now(), now());
 881      $content['all'] = render_cnt_template($content['all'], 'CATEGORY', html_specialchars($content['struct'][ $content['cat_id'] ]['acat_name']));
 882  
 883  }
 884  
 885  // -------------------------------------------------------------
 886  
 887  // render JavaScript Plugins and/or JavaScript scripts that should be loaded in <head>
 888  $content['all'] = preg_replace_callback('/<!--\s+JS:\s+(.*?)\s+-->/s', 'renderHeadJS', $content['all']);
 889  $content['all'] = preg_replace_callback('/<!--\s+CSS:\s+(.*?)\s+-->/s', 'renderHeadCSS', $content['all']);
 890  
 891  // test for frontend.js
 892  if(!isset($GLOBALS['block']['custom_htmlhead']['frontend.js']) && preg_match('/MM_swapImage|BookMark_Page|clickZoom|mailtoLink/', $content['all'])) {
 893      initFrontendJS();
 894  }
 895  
 896  //check for additional template based onLoad JavaScript Code
 897  if($block["jsonload"]) {
 898      if(empty($pagelayout["layout_jsonload"])) {
 899          $pagelayout["layout_jsonload"]  = '';
 900      } else {
 901          $pagelayout["layout_jsonload"] .= ';';
 902      }
 903      $pagelayout["layout_jsonload"]    = convertStringToArray($pagelayout["layout_jsonload"] . $block["jsonload"], ';');
 904      $block['js_ondomready'][]        = '        ' . implode(';'.LF.'    ', $pagelayout["layout_jsonload"]) . ';';
 905      $pagelayout["layout_jsonload"]    = '';
 906  }
 907  
 908  // set OnLoad (DomReady) JavaScript
 909  if(count($block['js_ondomready'])) {
 910      jsOnDomReady(implode(LF, $block['js_ondomready']));
 911  }
 912  // set OnUnLoad JavaScript
 913  if(count($block['js_onunload'])) {
 914      jsOnUnLoad(implode(LF, $block['js_onunload']));
 915  }
 916  // set Inline JS
 917  if(count($block['js_inline'])) {
 918      $block['custom_htmlhead']['inline']  = '  <script type="text/javascript">'.LF.SCRIPT_CDATA_START.LF;
 919      $block['custom_htmlhead']['inline'] .= implode(LF, $block['js_inline']);
 920      $block['custom_htmlhead']['inline'] .= LF.SCRIPT_CDATA_END.LF.'  </script>';
 921  }
 922  
 923  if(!empty($_GET['highlight'])) {
 924      $highlight_words = clean_slweg(rawurldecode($_GET['highlight']));
 925      $highlight_words = explode(' ', $highlight_words);
 926      $content['all'] = preg_replace_callback("/<!--SEARCH_HIGHLIGHT_START\/\/-->(.*?)<!--SEARCH_HIGHLIGHT_END\/\/-->/si", "pregReplaceHighlightWrapper", $content['all']);
 927  }
 928  $content['all'] = str_replace(array('<!--SEARCH_HIGHLIGHT_START//-->', '<!--SEARCH_HIGHLIGHT_END//-->'), '', $content['all']);
 929  
 930  // render content part pagination
 931  if(!empty($_CpPaginate)) {
 932  
 933      $content['all'] = str_replace(array('<!--CP_PAGINATE_START//-->', '<!--CP_PAGINATE_END//-->'), '', $content['all']);
 934      
 935      unset($_getVar['aid'], $_getVar['id']);
 936      $content['CpPaginateNaviGET']    = returnGlobalGET_QueryString('htmlentities', array(), defined('PHPWCMS_ALIAS') ? array(PHPWCMS_ALIAS) : array());
 937      if(!empty($content['CpPaginateNaviGET']) && $content['CpPaginateNaviGET']{0} == '?') {
 938          $content['CpPaginateNaviGET'] = '&amp;'.substr($content['CpPaginateNaviGET'], 1);
 939      }
 940  
 941      // first build [1][2][3] paginate pages    
 942      if(strpos($content['all'], '{CP_PAGINATE}')) {
 943          $content['CpPaginateNavi'] = array();
 944          foreach($content['CpPages'] as $key => $value) {
 945              
 946              $content['CpPaginateNavi'][ $key ]  = '    <a href="index.php?aid='.$aktion[1];
 947              if($key) {
 948                  $content['CpPaginateNavi'][ $key ] .= '-'.$key;
 949              }
 950              $content['CpPaginateNavi'][ $key ] .= $content['CpPaginateNaviGET'].'" class="';
 951              $content['CpPaginateNavi'][ $key ] .= ($key == $content['aId_CpPage']) ? 'cpPaginateActive' : 'cpPaginate';
 952              $content['CpPaginateNavi'][ $key ] .= '">'.$value.'</a>';
 953          
 954          }    
 955          $content['all'] = render_cnt_template($content['all'], 'CP_PAGINATE', implode(LF, $content['CpPaginateNavi']));
 956      }
 957      
 958      // is there PREV
 959      if(in_array($content['CpPages'][ $content['aId_CpPage'] ] - 1, $content['CpPages'])) {
 960          
 961          $key = array_search($content['CpPages'][ $content['aId_CpPage'] ] - 1, $content['CpPages']);
 962          $value = 'index.php?aid='.$aktion[1];
 963          if($key) { $value .= '-'.$key; }
 964          $content['all'] = render_cnt_template($content['all'], 'CP_PAGINATE_PREV', $value);
 965  
 966      } else {
 967          $content['all'] = render_cnt_template($content['all'], 'CP_PAGINATE_PREV');
 968      }
 969      
 970      // is there NEXT
 971      if(in_array($content['CpPages'][ $content['aId_CpPage'] ] + 1, $content['CpPages'])) {
 972          
 973          $key = array_search($content['CpPages'][ $content['aId_CpPage'] ] + 1, $content['CpPages']);
 974          $value = 'index.php?aid='.$aktion[1];
 975          if($key) { $value .= '-'.$key; }
 976          $content['all'] = render_cnt_template($content['all'], 'CP_PAGINATE_NEXT', $value);
 977  
 978      } else {
 979          $content['all'] = render_cnt_template($content['all'], 'CP_PAGINATE_NEXT');
 980      }
 981      
 982      // search for content part pagination title menu
 983      if(strpos($content['all'], '[CP_PAGINATE_MENU')) {
 984      
 985          /**
 986           * search for custom cp menu parameters
 987           *
 988           * [0] => item_prefix
 989           * [1] => item_suffix
 990           * [2] => active_class
 991           * [3] => hide_active
 992           * [4] => menu_prefix
 993           * [5] => menu_suffix
 994           */
 995          if( preg_match('/\[CP_PAGINATE_MENU:(.*?)\]/', $content['all'], $match) ) {
 996          
 997              $content['all']                    = str_replace($match[0], '[CP_PAGINATE_MENU]', $content['all']);
 998              $content['CpTitleParams']        = explode('|', $match[1]);
 999              if(!isset($content['CpTitleParams'][1])) {
1000                  $content['CpTitleParams'][1] = '';
1001              }
1002              $content['CpTitleParams'][2] = empty($content['CpTitleParams'][2]) ? '' : trim($content['CpTitleParams'][2]);
1003              $content['CpTitleParams'][3] = empty($content['CpTitleParams'][3]) ? 0 : 1 ;
1004              $content['CpTitleParams'][4]    = '';
1005              $content['CpTitleParams'][5]    = '';
1006          
1007          } else {
1008          
1009              $content['CpTitleParams'][0]    = '<li>';
1010              $content['CpTitleParams'][1]    = '</li>';
1011              $content['CpTitleParams'][2]    = 'active';
1012              $content['CpTitleParams'][3]    = 0;
1013              $content['CpTitleParams'][4]    = '<ul class="cpmenu">';
1014              $content['CpTitleParams'][5]    = '</ul>';            
1015          
1016          }
1017          
1018          $content['CpTitleMenu'] = array();
1019  
1020          // cp menu items
1021          foreach($content['CpPageTitles'] as $key => $value) {
1022              
1023              $content['CpItem']  = '<a href="index.php?aid='.$aktion[1];
1024              
1025              if($key) {
1026                  $content['CpItem'] .= '-'.$key;
1027              }
1028              
1029              $content['CpItem'] .= $content['CpPaginateNaviGET'].'"';
1030              
1031              if($key == $content['aId_CpPage']) {
1032                  
1033                  if(!empty($content['CpTitleParams'][3])) {
1034                      continue;
1035                  }
1036                  
1037                  if(!empty($content['CpTitleParams'][2])) {
1038                      $content['CpItem'] .= ' class="'.$content['CpTitleParams'][2].'"';
1039                  }
1040                  
1041              }
1042  
1043              $content['CpItem'] .= '>'.html_specialchars($value).'</a>';
1044              $content['CpTitleMenu'][] = $content['CpTitleParams'][0] . $content['CpItem'] . $content['CpTitleParams'][1];
1045          }
1046          
1047          // cp menu prefix/suffix
1048          if(count($content['CpTitleMenu'])) {
1049              $content['CpTitleMenu'][] = $content['CpTitleParams'][5];
1050              array_unshift($content['CpTitleMenu'], $content['CpTitleParams'][4]);
1051          }
1052  
1053          $content['all'] = render_cnt_template($content['all'], 'CP_PAGINATE_MENU', implode(LF, $content['CpTitleMenu']));
1054      }
1055      
1056      
1057  } elseif(strpos($content['all'], 'CP_PAGINATE')) {
1058  
1059      // remove CP_paginate block
1060      $content['all'] = replace_tmpl_section('CP_PAGINATE', $content['all']);
1061      
1062  }
1063  
1064  // check if print mode - then try to replace "no-print" sections from source
1065  if(strpos($content['all'], '--NO_PRINT')) {
1066      if($aktion[2] == 1) {
1067  
1068          $content['all'] = replace_tmpl_section('NO_PRINT', $content['all']);
1069          $block['css']    = array('print_layout.css');
1070  
1071      } else {
1072  
1073          $content['all'] = str_replace(array('<!--NO_PRINT_START//-->', '<!--NO_PRINT_END//-->'), '', $content['all']);
1074  
1075      }
1076  }
1077  
1078  // now clean up special sections in case user is logged in OR not
1079  if(strpos($content['all'], '--LOGGED_')) {
1080  
1081      if( _getFeUserLoginStatus() ) {
1082          // if user IS logged in
1083          $content['all'] = str_replace(array('<!--LOGGED_IN_START//-->', '<!--LOGGED_IN_END//-->'), '', $content['all']);
1084          $content['all'] = replace_tmpl_section('LOGGED_OUT', $content['all']);    
1085      } else {
1086          // user is NOT logged
1087          $content['all'] = str_replace(array('<!--LOGGED_OUT_START//-->', '<!--LOGGED_OUT_END//-->'), '', $content['all']);
1088          $content['all'] = replace_tmpl_section('LOGGED_IN', $content['all']);
1089      }
1090  
1091  }
1092  
1093  $content['all'] = preg_replace_callback('/\[HTML\](.*?)\[\/HTML\]/s', 'convert2html', $content['all'] );
1094  $content['all'] = preg_replace_callback('/\[HTML_SPECIAL\](.*?)\[\/HTML_SPECIAL\]/s', 'convert2htmlspecialchars' , $content['all'] );
1095  
1096  parse_CKEDitor_resized_images();
1097  
1098  // cleanup document to enhance XHTML Strict compatibility
1099  switch($phpwcms['mode_XHTML']) {
1100      case 2:
1101          $content['all'] = preg_replace(array('/ border="[0-9]+?"/', '/ target=".+?"/'), '', $content['all'] );
1102          break;
1103      case 3:
1104          // put it as first item
1105          if(empty($phpwcms['html5shiv_disabled'])) {
1106              $block['custom_htmlhead'] = array('html5shiv' => '  <!--[if lt IE 9]><script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script><![endif]-->') + $block['custom_htmlhead'];
1107          }
1108          break;
1109  }
1110  
1111  // new $block['custom_htmlhead'] var (array) for usage in own rendering stuff.
1112  // you will be able to use $GLOBALS['block']['custom_htmlhead']['myheadname']
1113  // always check if you want to use same head code only once
1114  if(count($block['custom_htmlhead'])) {
1115      $block["htmlhead"] .= implode(LF, $block['custom_htmlhead']).LF;
1116  }
1117  
1118  // remove all useless replacement tags
1119  $content["pagetitle"] = sanitize_replacement_tags($content["pagetitle"]);
1120  
1121  // now we should search all ?aid=123 and/or ?id=123 and replace'em by the real alias if available
1122  $match = array();
1123  preg_match_all('/index.php\?(aid|id)=([\d\,]+)(["|&])/', $content['all'], $match);
1124  
1125  if( isset($match[1]) && isset($match[2]) ) {
1126  
1127      $all_id        = array();
1128      $sql_id        = '';
1129      
1130      $all_aid    = array();
1131      $sql_aid    = '';
1132      
1133      $old_style    = false;
1134  
1135      foreach($match[2] as $key => $value) {
1136      
1137          if($match[1][$key] == 'id') {
1138              
1139              if(strpos($match[2][$key], ',')) {
1140              
1141                  $old_style    = true;
1142                  
1143                  $this_id    = 0;
1144                  $this_aid    = 0;
1145                  
1146                  list($this_id, $this_aid) = explode(',', $match[2][$key]);
1147                  
1148                  if( $this_aid = intval($this_aid) ) {
1149                  
1150                      $all_aid[ $this_aid ]    = $this_aid;
1151                      
1152                  } elseif( $this_id = intval($this_id) ) {
1153                  
1154                      $all_id[ $this_id ]        = $this_id;
1155                  
1156                  }
1157              
1158              } else {
1159      
1160                  $all_id[ $match[2][$key] ]    = $match[2][$key];
1161      
1162              }            
1163                  
1164          } else {
1165          
1166              $all_aid[ $match[2][$key] ]    = $match[2][$key];
1167          
1168          }
1169      }
1170      
1171      if(count($all_id)) {
1172          $sql_id   = "SELECT 'id' AS alias_type, acat_id AS id, 0 AS aid, acat_alias AS alias FROM ".DB_PREPEND.'phpwcms_articlecat ';
1173          $sql_id  .= 'WHERE acat_id IN (' . implode(',', $all_id) . ") AND acat_alias != ''";
1174      }    
1175      
1176      if(count($all_aid)) {
1177          $sql_aid  = "SELECT 'aid' AS alias_type, article_cid AS id, article_id AS aid, article_alias AS alias FROM ".DB_PREPEND.'phpwcms_article ';
1178          $sql_aid .= 'WHERE article_id IN (' . implode(',', $all_aid) . ") AND article_alias != ''";
1179      }
1180  
1181      if($sql_id && $sql_aid) {
1182      
1183          $sql = '(' . $sql_id . ') UNION (' . $sql_aid . ')';
1184      
1185      } else {
1186      
1187          $sql = $sql_id . $sql_aid ;
1188      
1189      }
1190      
1191      $match = _dbQuery($sql);
1192  
1193      if(isset($match[0])) {
1194      
1195          foreach($match as $value) {
1196      
1197              $value['alias'] = html_specialchars($value['alias']);
1198  
1199              if($value['alias_type'] == 'id') { 
1200              
1201                  $content['all'] = str_replace('index.php?id=' . $value['id'] . '"', 'index.php?' . $value['alias'] . '"', $content['all']);
1202                  $content['all'] = str_replace('index.php?id=' . $value['id'] . '&', 'index.php?' . $value['alias'] . '&', $content['all']);
1203              
1204              } else {
1205              
1206                  $content['all'] = str_replace('index.php?aid=' . $value['aid'] . '"', 'index.php?' . $value['alias'] . '"', $content['all']);
1207                  $content['all'] = str_replace('index.php?aid=' . $value['aid'] . '&', 'index.php?' . $value['alias'] . '&', $content['all']);
1208              
1209              }
1210              
1211              // search also for id=0,0,...
1212              if( $old_style == true ) {
1213              
1214                  $value['id'] = $value['id'] . ',' . $value['aid'] . ',0,1,0,0';
1215              
1216                  $content['all'] = str_replace('index.php?id=' . $value['id'] . '"', 'index.php?' . $value['alias'] . '"', $content['all']);
1217                  $content['all'] = str_replace('index.php?id=' . $value['id'] . '&', 'index.php?' . $value['alias'] . '&', $content['all']);
1218  
1219              }
1220              
1221          }
1222      
1223      }
1224      
1225  }
1226  
1227  // Global parsing for i18 @@Text@@ replacements
1228  if(!empty($phpwcms['i18n_parse'])) {
1229      $content['all']            = i18n_substitute_text($content['all']);
1230      $content["pagetitle"]    = i18n_substitute_text($content['pagetitle']);
1231  }
1232  
1233  // Replace all deprecated GT Mod tags
1234  if(!empty($phpwcms['gt_mod']) && strpos($content["all"], '{GT') !== false) {
1235      
1236  	function deprecated_get_gt_by_style($matches) {
1237          return '<span class="gt-'.trim($matches[1]).'">' . $matches[2] . '</span>';
1238      }
1239      
1240      $content["all"] = preg_replace_callback('/\{GT:(.+?)\}(.*?)\{\/GT\}/is', 'deprecated_get_gt_by_style', $content["all"]);
1241  }
1242  
1243  ?>


Generated: Sun Jan 29 16:31:14 2012 Cross-referenced by PHPXref 0.7.1