[ Index ]

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

title

Body

[close]

/include/inc_front/ -> front.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  //specific functions for the frontend
  31  
  32  function spacer($width=1, $height=1) {
  33      //creates a placeholder image (transparent gif)
  34      return '<img src="img/leer.gif" width="'.intval($width).'" height="'.intval($height).'" border="0" alt="" />';
  35  }
  36  
  37  function headline(& $head, & $subhead, & $layout) {
  38      $c = '';
  39      if($head) {
  40          $c .= $layout["content_head_before"];
  41          $c .= html_specialchars($head);
  42          $c .= $layout["content_head_after"];
  43      }
  44      if($subhead) {
  45          $c .= $layout["content_subhead_before"];
  46          $c .= html_specialchars($subhead);
  47          $c .= $layout["content_subhead_after"];
  48      }
  49      return $c;
  50  }
  51  
  52  //defines multimedia plugin specific values for width or height
  53  function plugin_size($mediatype, $player, $width, $height) {
  54  
  55      switch($mediatype) {
  56          case 0: //Video
  57                  switch($player) {
  58                      case 0:    //Quicktime
  59                              $width = ($width) ? $width : "";
  60                              $height = ($height) ? $height+16 : "";
  61                              break;
  62  
  63                      case 1:    //RealPlayer
  64                              $width = ($width) ? $width : "";
  65                              $width = ($height) ? $height+36 : "";
  66                              break;
  67  
  68                      case 2:    //MediaPlayer
  69                              $width = ($width) ? $width : "";
  70                              $width = ($height) ? $height : "";
  71                              break;
  72  
  73                      case 3:    //Flash
  74                              $width = ($width) ? $width : "";
  75                              $width = ($height) ? $height : "";
  76                              break;
  77                  }
  78                  break;
  79  
  80          case 1:    //Audio
  81                  break;
  82  
  83          case 2:    //Flash
  84                  break;
  85  
  86      }
  87  }
  88  
  89  function must_filled($c) {
  90      //spaceholder for form fields that have to be filled
  91      //with some content or has to be marked or like that
  92      return intval($c) ? '<img src="img/article/fill_in_here.gif" border="0" alt="" />' : '';
  93  }
  94  
  95  function add_attribute($baseval, $attribute, $val, $space=" ") {
  96      //to add all relevant attributes that contains
  97      //values to a string maybe a html tag
  98      $attribute = isEmpty(strval($val)) ? '' : $attribute.'="'.$val.'"';
  99      $attribute = ($baseval && !isEmpty($val)) ? $space.$attribute : $attribute;
 100      return $attribute;
 101  }
 102  
 103  function add_style_attribute($attribute='', $val='') {
 104      //to add all relevant attributes that contains
 105      //values to a string maybe a html tag
 106      $attribute = isEmpty(strval($val)) ? '' : $attribute.': '.$val.';';
 107      return $attribute;
 108  }
 109  
 110  function html_attribute($attribute='', $val='') {
 111      //to return only 1 well formatted attributes and values
 112      return isEmpty(strval($val)) ? '' : $attribute.'="'.$val.'"';
 113  }
 114  
 115  function html_height_attribute($val=0) {
 116      //to return only 1 well formatted attributes and values
 117      return (intval($val)) ? ' style="height:'.$val.'px;" ' : '';
 118  }
 119  
 120  function get_body_attributes(& $values) {
 121      //return a standard list of standard html body attributes
 122      //based on the pagelayout definitions
 123      $body_class    = '';
 124      $link_class    = '';
 125      if(is_array($values)) {
 126          if(empty($values["layout_noborder"])) {
 127              $body_class .= add_style_attribute('        margin', '0').LF;
 128              $body_class .= add_style_attribute('        padding-top',        empty($values["layout_border_top"])        ? '0' : intval($values["layout_border_top"])   .'px').LF;
 129              $body_class .= add_style_attribute('        padding-bottom',    empty($values["layout_border_bottom"])    ? '0' : intval($values["layout_border_bottom"]).'px').LF;
 130              $body_class .= add_style_attribute('        padding-left',    empty($values["layout_border_left"])     ? '0' : intval($values["layout_border_left"])  .'px').LF;
 131              $body_class .= add_style_attribute('        padding-right',     empty($values["layout_border_right"])     ? '0' : intval($values["layout_border_right"]) .'px').LF;
 132              $body_class .= LF;
 133          }
 134          if(!empty($values["layout_bgcolor"])) {
 135              $body_class .= add_style_attribute('        background-color', $values["layout_bgcolor"]);
 136              $body_class .= LF;
 137          }
 138          if(!empty($values["layout_bgimage"])) {
 139              $body_class .= add_style_attribute('        background-image', 'url('.$values["layout_bgimage"].')');
 140              $body_class .= LF;
 141          }
 142          if(!empty($values["layout_textcolor"])) {
 143              $body_class .= add_style_attribute('        color', $values["layout_textcolor"]);
 144              $body_class .= LF;
 145          }
 146          if(!empty($body_class)) {
 147              $body_class  = '    body {'.LF.$body_class.'    }'.LF;
 148          }
 149          if(!empty($values["layout_linkcolor"])) {
 150              $link_class .= '    a, a:link, a:active, a:visited, a:hover { color: '.$values["layout_linkcolor"].'; }';
 151              $link_class .= LF;
 152          }
 153          if(!empty($values["layout_vcolor"])) {
 154              $link_class .= '    a:visited { color: '.$values["layout_vcolor"].'; }';
 155              $link_class .= LF;
 156          }
 157          if(!empty($values["layout_acolor"])) {
 158              $link_class .= '    a:active { color: '.$values["layout_acolor"].'; }';
 159              $link_class .= LF;
 160          }
 161          if(!empty($body_class) || !empty($link_class)) {
 162              $body_class  = '  <style type="text/css">'.LF. $body_class;
 163              $body_class .= $link_class . '  </style>'.LF;
 164          }
 165          return $body_class;
 166      }
 167      return '';
 168  }
 169  
 170  function align_base_layout($value) {
 171      //to get the alignment of the base layout table
 172      switch($value) {
 173          case  1: $align = "center"; break;
 174          case  2: $align = "right"; break;
 175          default: $align = 0;
 176      }
 177      return ($align) ? ' align="'.$align.'"' : '';
 178  }
 179  
 180  function get_colspan($value) {
 181      //returns colspan value back to table row
 182      if(!isset($value["layout_type"]))                $value["layout_type"] = 0;
 183      switch($value["layout_type"]) {
 184          case  0:    $col=3; break;
 185          case  1:    $col=2; break;
 186          case  2:    $col=2; break;
 187          case  3:    $col=0; break;
 188          default:    $col=3;
 189      }
 190      if(!empty($value["layout_leftspace_width"]))  $col++;
 191      if(!empty($value["layout_rightspace_width"])) $col++;
 192      return ($col) ? (' colspan="'.$col.'"') : '';
 193  }
 194  
 195  function colspan_table_row($val, $block, $colspan="", $rowcontent="&nbsp;") {
 196      //creates a new table row for header or footer or such rows
 197      return ($rowcontent) ? "<tr>\n<td".$colspan.td_attributes($val, $block, 0).">".$rowcontent."</td>\n</tr>\n" : '';
 198  }
 199  
 200  function get_table_block($val, $content="", $leftblock="", $rightblock="") {
 201      //creates the string with all relevant main block data
 202      //$val = $pagelayout array values
 203      $mainblock  = "<tr>\n"; //start row
 204  
 205      //if 3column or 2column (with left block)
 206      if($val["layout_type"]==0 || $val["layout_type"]==1) {
 207          $mainblock .= "<td".td_attributes($val, "left").">".$leftblock."</td>\n";
 208      }
 209  
 210      //if there is a spacer column between left and main block
 211      if($val["layout_leftspace_width"]) {
 212          $mainblock .= "<td".td_attributes($val, "leftspace").">";
 213          $mainblock .= spacer($val["layout_leftspace_width"]);
 214          $mainblock .= "</td>\n";
 215      }
 216  
 217      $mainblock .= "<td".td_attributes($val, "content").">".$content."</td>\n";
 218  
 219      //if there is a spacer column between main block and right column
 220      if($val["layout_rightspace_width"]) {
 221          $mainblock .= "<td".td_attributes($val, "rightspace").">";
 222          $mainblock .= spacer($val["layout_rightspace_width"]);
 223          $mainblock .= "</td>\n";
 224      }
 225  
 226      //if 3column or 2column (with right block)
 227      if($val["layout_type"]==0 || $val["layout_type"]==2) {
 228          $mainblock .= "<td".td_attributes($val, "right").">".$rightblock."</td>\n";
 229      }
 230  
 231      $mainblock .= "</tr>\n"; //end row
 232      return $mainblock;
 233  }
 234  
 235  function td_attributes($val, $block, $top=1) {
 236      //creates a string with all relevant cell attributes like nackground color/image, class
 237      $td_attrib  = ($top) ? ' valign="top"' : "";
 238      if(!empty($val["layout_".$block."_height"])) {
 239          $td_attrib .= html_height_attribute($val["layout_".$block."_height"]);
 240      }
 241      if(!empty($val["layout_".$block."_width"])) {
 242          $td_attrib .= html_attribute(" width", $val["layout_".$block."_width"]);
 243      }
 244      if(!empty($val["layout_".$block."_bgcolor"])) {
 245          $td_attrib .= html_attribute(" bgcolor", $val["layout_".$block."_bgcolor"]);
 246      }
 247      if(!empty($val["layout_".$block."_bgimage"])) {
 248          $td_attrib .= html_attribute(" style", 'background-image:url('.$val["layout_".$block."_bgimage"].')');
 249      }
 250      if(!empty($val["layout_".$block."_class"])) {
 251          $td_attrib .= html_attribute(" class", $val["layout_".$block."_class"]);
 252      }
 253      return $td_attrib;
 254  }
 255  
 256  function table_attributes($val, $var_part, $top=1, $tr=false) {
 257      //creates a string with all relevant cell attributes like background color/image, class
 258      //P.S. it is nearly the same as td_attributes - but it was boring to rewrite code ;-)
 259      $td_attrib = '';
 260      if($top) {
 261          $td_attrib = ' valign="top"';
 262      }
 263  
 264      if(!$tr) {
 265          $td_attrib .= html_attribute(" border", (!empty($val[$var_part."_border"])) ? $val[$var_part."_border"] : '0');
 266          $td_attrib .= html_attribute(" cellspacing", (!empty($val[$var_part."_cspace"])) ? $val[$var_part."_cspace"] : '0');
 267          $td_attrib .= html_attribute(" cellpadding", (!empty($val[$var_part."_cpad"])) ? $val[$var_part."_cpad"] : '0');
 268      }
 269  
 270      if(!empty($val[$var_part."_height"])) {
 271          $td_attrib .= html_height_attribute($val[$var_part."_height"]);
 272      }
 273      if(!empty($val[$var_part."_width"])) {
 274          $td_attrib .= html_attribute(" width", $val[$var_part."_width"]);
 275      }
 276      if(!empty($val[$var_part."_bgcolor"])) {
 277          $td_attrib .= html_attribute(" bgcolor", $val[$var_part."_bgcolor"]);
 278      }
 279      if(!empty($val[$var_part."_bgimage"])) {
 280          $td_attrib .= html_attribute(" background", $val[$var_part."_bgimage"]);
 281      }
 282      if(!empty($val[$var_part."_class"])) {
 283          $td_attrib .= html_attribute(" class", $val[$var_part."_class"]);
 284      }
 285  
 286      return $td_attrib;
 287  }
 288  
 289  function get_breadcrumb ($start_id, &$struct_array, $key="acat_name") {
 290      //returns the breadcrumb path starting with given start_id
 291  
 292      $data = array();
 293      while ($start_id && isset($struct_array[$start_id])) {
 294          $data[$start_id] = $struct_array[$start_id][$key];
 295          $start_id         = $struct_array[$start_id]["acat_struct"];
 296      }
 297      if(!empty($struct_array[$start_id][$key])) {
 298          $data[$start_id] = $struct_array[$start_id][$key];
 299      }
 300      return array_reverse($data, 1);
 301  }
 302  
 303  function breadcrumb ($start_id, &$struct_array, $end_id, $spacer=' &gt; ') {
 304      //builds the breadcrumb menu based on given values
 305      //$link_to = the page on which the breadcrum part links
 306      //$root_name = name of the breadcrumb part if empty/false/0 $start_id
 307      //$spacer = how should breadcrumb parts be divided
 308  
 309      $start_id     = intval($start_id);
 310      $end_id     = intval($end_id);
 311      $act_id     = $start_id; //store actual ID for later comparing
 312      $breadcrumb = '';
 313      global $template_default;
 314  
 315      while ($start_id) { //get the breadcrumb path starting with given start_id
 316          if($end_id && $start_id == $end_id) break;
 317          $data[$start_id] = $struct_array[$start_id]["acat_name"];
 318          $start_id         = $struct_array[$start_id]["acat_struct"];
 319      }
 320      $data[$start_id] = $struct_array[$start_id]["acat_name"];
 321      $crumbs_part = array_reverse($data, 1);
 322      if(is_array($crumbs_part) && count($crumbs_part)) {
 323          foreach($crumbs_part as $key => $value) {
 324  
 325              $alias = '';
 326  
 327              if($struct_array[$key]["acat_hidden"] != 1) { // check if the structure should be unvisible when active
 328  
 329                  if($breadcrumb) {
 330                      $breadcrumb .= $spacer;
 331                  }
 332  
 333                  if ($act_id != $key) {
 334  
 335                      if(!$struct_array[$key]["acat_redirect"]) {
 336                          $breadcrumb .= '<a href="index.php?';
 337                          $alias          = $struct_array[$key]["acat_alias"];
 338                          $breadcrumb .= ($alias) ? html_specialchars($alias) : 'id='.$key;
 339                          $breadcrumb .= '">';
 340                      } else {
 341                          $redirect = get_redirect_link($struct_array[$key]["acat_redirect"], ' ', '');
 342                          $breadcrumb .= '<a href="'.$redirect['link'].'"'.$redirect['target'].'>';
 343                      }
 344  
 345                      $breadcrumb .= html_specialchars($crumbs_part[$key]).'</a>';
 346  
 347                  } else {
 348                  
 349                      if(!$struct_array[$key]["acat_redirect"]) {
 350                          $breadcrumb .= '<a href="index.php?';
 351                          $alias          = $struct_array[$key]["acat_alias"];
 352                          $breadcrumb .= ($alias) ? html_specialchars($alias) : 'id='.$key;
 353                          $breadcrumb .= '" class="active">';
 354                      } else {
 355                          $redirect = get_redirect_link($struct_array[$key]["acat_redirect"], ' ', '');
 356                          $breadcrumb .= '<a href="'.$redirect['link'].'"'.$redirect['target'].' class="active">';
 357                      }
 358  
 359                      if(!empty($template_default['breadcrumb_active_prefix'])) {
 360                          $breadcrumb .= $template_default['breadcrumb_active_prefix'];
 361                      }
 362                      
 363                      $breadcrumb .= html_specialchars($crumbs_part[$key]);
 364                      
 365                      if(!empty($template_default['breadcrumb_active_suffix'])) {
 366                          $breadcrumb .= $template_default['breadcrumb_active_suffix'];
 367                      }
 368                      
 369                      $breadcrumb .= '</a>';
 370                  }
 371              }
 372          }
 373      }
 374      return $breadcrumb;
 375  }
 376  
 377  function get_redirect_link($link='#', $pre='', $after=' ') {
 378      // returns the link var and target var if available
 379      $link             = explode(' ', $link);
 380      $l['link']        = empty($link[0]) ? '#' : $link[0];
 381      $l['target']    = empty($link[1]) ? ''  : $pre.'target="'.$link[1].'"'.$after;
 382      return $l;
 383  }
 384  
 385  function get_struct_data($root_name='', $root_info='') {
 386      //returns the complete active and public struct data as array
 387      //so it is reusable by many menu functions -> lower db access
 388      
 389      // first check pre-rendered structure for current user mode
 390      $sysvalue_key    = 'structure_array_vmode_'.get_user_vmode();
 391      $data            = _getConfig($sysvalue_key);
 392      
 393      if(is_array($data)) {
 394          return $data;    
 395      }
 396  
 397      global $db;
 398      global $indexpage;
 399      $data = array();
 400  
 401      $data[0] = array(    "acat_id"        => 0,
 402                      "acat_name"        => $indexpage['acat_name'],
 403                      "acat_info"        => $indexpage['acat_info'],
 404                      "acat_struct"    => 0,
 405                      "acat_sort"        => 0,
 406                      "acat_hidden"    => intval($indexpage['acat_hidden']),
 407                      "acat_regonly"    => intval($indexpage['acat_regonly']),
 408                      "acat_ssl"        => intval($indexpage['acat_ssl']),
 409                      "acat_template"    => intval($indexpage['acat_template']),
 410                      "acat_alias"    => $indexpage['acat_alias'],
 411                      "acat_topcount"    => intval($indexpage['acat_topcount']),
 412                      "acat_maxlist"    => intval($indexpage['acat_maxlist']),
 413                      "acat_redirect"    => $indexpage['acat_redirect'],
 414                      "acat_order"    => intval($indexpage['acat_order']),
 415                      "acat_timeout"    => $indexpage['acat_timeout'],
 416                      "acat_nosearch"    => $indexpage['acat_nosearch'],
 417                      "acat_nositemap"=> $indexpage['acat_nositemap'],
 418                      "acat_permit"    => !empty($indexpage['acat_permit']) && is_array($indexpage['acat_permit']) ? $indexpage['acat_permit'] : array(),
 419                      "acat_pagetitle"=> empty($indexpage['acat_pagetitle']) ? '' : $indexpage['acat_pagetitle'],
 420                      "acat_paginate"    => empty($indexpage['acat_paginate']) ? 0 : 1,
 421                      "acat_overwrite"=> empty($indexpage['acat_overwrite']) ? '' : $indexpage['acat_overwrite'],
 422                      "acat_archive"    => empty($indexpage['acat_archive']) ? 0 : 1,
 423                      "acat_class"    => empty($indexpage['acat_class']) ? '' : $indexpage['acat_class'],
 424                      "acat_keywords"    => empty($indexpage['acat_keywords']) ? '' : $indexpage['acat_keywords']
 425                  );
 426      $sql  = "SELECT * FROM ".DB_PREPEND."phpwcms_articlecat WHERE ";
 427      // VISIBLE_MODE: 0 = frontend (all) mode, 1 = article user mode, 2 = admin user mode
 428      if(VISIBLE_MODE != 2) {
 429          // for 0 AND 1
 430          $sql .= "acat_aktiv=1 AND acat_public=1 AND ";
 431      }
 432      $sql .= "acat_trash=0 ORDER BY acat_struct, acat_sort";
 433  
 434      if($result = mysql_query($sql, $db)) {
 435          while($row = mysql_fetch_assoc($result)) {
 436              $data[$row["acat_id"]] = array(    "acat_id"        => $row["acat_id"],
 437                                          "acat_name"        => $row["acat_name"],
 438                                          "acat_info"        => $row["acat_info"],
 439                                          "acat_struct"    => $row["acat_struct"],
 440                                          "acat_sort"        => $row["acat_sort"],
 441                                          "acat_hidden"    => $row["acat_hidden"],
 442                                          "acat_regonly"    => $row["acat_regonly"],
 443                                          "acat_ssl"        => $row["acat_ssl"],
 444                                          "acat_template"    => $row["acat_template"],
 445                                          "acat_alias"    => $row["acat_alias"],
 446                                          "acat_topcount"    => $row["acat_topcount"],
 447                                          "acat_maxlist"    => $row["acat_maxlist"],
 448                                          "acat_redirect"    => $row["acat_redirect"],
 449                                          "acat_order"    => $row["acat_order"],
 450                                          "acat_timeout"    => $row["acat_cache"],
 451                                          "acat_nosearch"    => $row["acat_nosearch"],
 452                                          "acat_nositemap"=> $row["acat_nositemap"],
 453                                          "acat_permit"    => empty($row["acat_permit"]) ? array() : explode(',', $row["acat_permit"]),
 454                                          "acat_pagetitle"=> $row["acat_pagetitle"],
 455                                          "acat_paginate"    => $row["acat_paginate"],
 456                                          "acat_overwrite"=> $row["acat_overwrite"],
 457                                          "acat_archive"    => $row["acat_archive"],
 458                                          "acat_class"    => $row["acat_class"],
 459                                          "acat_keywords"    => $row["acat_keywords"]
 460                                        );
 461          }
 462          mysql_free_result($result);
 463      }
 464      
 465      // set max_allowed_package to bigger value
 466      _dbSetVar('max_allowed_packet', 16*1024*1024, '<');
 467  
 468      // store pre-rendered serialized array in database
 469      _setConfig($sysvalue_key, $data, 'frontend_render', 1);
 470      
 471      return $data;
 472  }
 473  
 474  function get_actcat_articles_data($act_cat_id) {
 475      //returns the complete active and public article data as array (basic infos only)
 476      //so it is reusable by many functions -> lower db access
 477  
 478      global $content;
 479      global $db;
 480  
 481      $data                 = array();
 482      if(isset($content['struct'][ $act_cat_id ])) {
 483          $ao = get_order_sort($content['struct'][ $act_cat_id ]['acat_order']);
 484      } else {
 485          return $data;
 486      }
 487      $as                    = $content['struct'][ $act_cat_id ];
 488      $as['acat_maxlist']    = intval($as['acat_maxlist']);
 489  
 490      $sql  = "SELECT *, UNIX_TIMESTAMP(article_tstamp) AS article_date, ";
 491      $sql .= "UNIX_TIMESTAMP(article_begin) AS article_livedate, ";
 492      $sql .= "UNIX_TIMESTAMP(article_end) AS article_killdate ";
 493      $sql .= "FROM ".DB_PREPEND."phpwcms_article ";
 494      $sql .= "WHERE article_cid=".$act_cat_id;
 495      // VISIBLE_MODE: 0 = frontend (all) mode, 1 = article user mode, 2 = admin user mode
 496      switch(VISIBLE_MODE) {
 497          case 0: $sql .= " AND article_public=1 AND article_aktiv=1";
 498                  break;
 499          case 1: $sql .= " AND article_uid=".$_SESSION["wcs_user_id"];
 500                  break;
 501          //case 2: admin mode no additional neccessary
 502      }
 503      $sql .= ' AND article_deleted=0 AND article_begin < NOW() ';
 504      
 505      if($content['struct'][ $act_cat_id ]['acat_archive'] == 0) {
 506          $sql .= 'AND article_end > NOW() ';
 507      } else {
 508          $sql .= 'AND IF( article_archive_status=1 , 1 , article_end > NOW() ) ';    
 509      }
 510      
 511      $sql .= "ORDER BY ".$ao[2];
 512  
 513      if(empty($as['acat_paginate']) && $as['acat_maxlist'] && $as['acat_topcount'] >= $as['acat_maxlist']) {
 514          $sql .= ' LIMIT '.$as['acat_maxlist'];
 515      }
 516  
 517      if($result = mysql_query($sql, $db)) {
 518          while($row = mysql_fetch_assoc($result)) {
 519              $data[$row["article_id"]] = array(
 520                                      "article_id"        => $row["article_id"],
 521                                      "article_cid"        => $row["article_cid"],
 522                                      "article_title"        => $row["article_title"],
 523                                      "article_subtitle"    => $row["article_subtitle"],
 524                                      "article_menutitle"    => $row["article_menutitle"],
 525                                      "article_keyword"    => $row["article_keyword"],
 526                                      "article_summary"    => $row["article_summary"],
 527                                      "article_redirect"    => $row["article_redirect"],
 528                                      "article_date"        => $row["article_date"],
 529                                      "article_username"    => $row["article_username"],
 530                                      "article_sort"        => $row["article_sort"],
 531                                      "article_notitle"    => $row["article_notitle"],
 532                                      "article_created"    => $row["article_created"],
 533                                      "article_image"        => @unserialize($row["article_image"]),
 534                                      "article_timeout"    => $row["article_cache"],
 535                                      "article_nosearch"    => $row["article_nosearch"],
 536                                      "article_nositemap"    => $row["article_nositemap"],
 537                                      "article_aliasid"    => $row["article_aliasid"],
 538                                      "article_headerdata"=> $row["article_headerdata"],
 539                                      "article_morelink"    => $row["article_morelink"],
 540                                      "article_begin"        => $row["article_begin"],
 541                                      "article_end"        => $row["article_end"],
 542                                      "article_alias"        => $row["article_alias"],
 543                                      'article_livedate'    => $row["article_livedate"],
 544                                      'article_killdate'    => $row["article_killdate"]
 545                                              );
 546              // now check for article alias ID
 547              if($row["article_aliasid"]) {
 548                  $aid = $row["article_id"];
 549                  $alias_sql  = "SELECT *, UNIX_TIMESTAMP(article_tstamp) AS article_date, ";
 550                  $alias_sql .= "UNIX_TIMESTAMP(article_begin) AS article_livedate, ";
 551                  $alias_sql .= "UNIX_TIMESTAMP(article_end) AS article_killdate "; 
 552                  $alias_sql .= "FROM ".DB_PREPEND."phpwcms_article ";
 553                  $alias_sql .= "WHERE article_deleted=0 AND article_id=".intval($row["article_aliasid"]);
 554                  if(!$row["article_headerdata"]) {
 555                      switch(VISIBLE_MODE) {
 556                          case 0: $alias_sql .= " AND article_public=1 AND article_aktiv=1";
 557                                  break;
 558                          case 1: $alias_sql .= " AND article_uid=".$_SESSION["wcs_user_id"];
 559                                  break;
 560                      }
 561                      $alias_sql .= " AND article_begin < NOW() AND article_end > NOW()";
 562                  }
 563                  $alias_sql .= " AND article_deleted=0 LIMIT 1";
 564                  if($alias_result = mysql_query($alias_sql, $db)) {
 565                      if($alias_row = mysql_fetch_assoc($alias_result)) {
 566                          $data[$aid]["article_id"] = $alias_row["article_id"];
 567                          $data[$aid]["article_alias"] = $alias_row["article_alias"];
 568                          // use alias article header data
 569                          if(!$row["article_headerdata"]) {
 570                              $data[$aid]["article_title"]        = $alias_row["article_title"];
 571                              $data[$aid]["article_subtitle"]        = $alias_row["article_subtitle"];
 572                              $data[$aid]["article_keyword"]        = $alias_row["article_keyword"];
 573                              $data[$aid]["article_summary"]        = $alias_row["article_summary"];
 574                              $data[$aid]["article_redirect"]        = $alias_row["article_redirect"];
 575                              $data[$aid]["article_date"]            = $alias_row["article_date"];
 576                              $data[$aid]["article_image"]        = @unserialize($alias_row["article_image"]);
 577                              $data[$aid]["article_begin"]        = $alias_row["article_begin"];
 578                              $data[$aid]["article_end"]            = $alias_row["article_end"];
 579                              $data[$aid]['article_livedate']        = $alias_row["article_livedate"];
 580                              $data[$aid]['article_killdate']        = $alias_row["article_killdate"];
 581                              $data[$aid]['article_menutitle']    = $alias_row["article_menutitle"];
 582                          }
 583                      }
 584                      mysql_free_result($alias_result);
 585                  }
 586              }
 587          }
 588          mysql_free_result($result);
 589      }
 590      return $data;
 591  }
 592  
 593  function setArticleSummaryImageData($img) {
 594      // used to set correct list image values based on given data
 595  
 596      //first check if lis_image data is set - will not for all old articles
 597      if(!isset($img['list_usesummary'])) {
 598          $img['list_usesummary'] = 1;
 599      }
 600      if($img['list_usesummary'] && !empty($img['hash'])) {
 601          $img['list_name']        = $img['name'];
 602          $img['list_hash']        = $img['hash'];
 603          $img['list_ext']        = $img['ext'];
 604          $img['list_id']            = $img['id'];
 605          $img['list_caption']    = $img['caption'];
 606          $img['list_zoom']        = empty($img['list_zoom']) ? $img['zoom'] : $img['list_zoom'];
 607          $img['list_width']        = empty($img['list_width']) ? $img['width'] : $img['list_width'];
 608          $img['list_height']        = empty($img['list_height']) ? $img['height'] : $img['list_height'];
 609      }
 610      return $img;
 611  }
 612  
 613  //menu creating
 614  function nav_table_simple_struct(&$struct, $act_cat_id, $link_to="index.php") {
 615      //returns a simple table based navigation menu of possible
 616      //structure levels based on current structure level
 617      $nav_table  = "<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\" width=\"100%\" summary=\"\">\n<tr>\n";
 618      $nav_table .= "<td width=\"10\"><img src=\"img/leer.gif\" width=\"10\" height=\"1\" alt=\"\" /></td>\n";
 619      $nav_table .= '<td width="100%"'.(empty($struct[$act_cat_id]["acat_class"]) ? '' : ' class="'.$struct[$act_cat_id]["acat_class"].'"').'><strong>';
 620      $nav_table .= html_specialchars($struct[$act_cat_id]["acat_name"]);
 621      $nav_table .= "</strong></td>\n<tr>";
 622      foreach($struct as $key => $value) {
 623  
 624          if($key != $act_cat_id && _getStructureLevelDisplayStatus($key, $act_cat_id) ) {
 625              
 626              $nav_table .= "<tr>\n";
 627              $nav_table .= "<td width=\"10\"><img src=\"img/leer.gif\" width=\"10\" height=\"1\" alt=\"\" /></td>\n";
 628              $nav_table .= '<td width="100%"'.(empty($struct[$key]["acat_class"]) ? '' : ' class="'.$struct[$key]["acat_class"].'"').'>';
 629  
 630              if(!$struct[$key]["acat_redirect"]) {
 631                  $nav_table .= '<a href="index.php?';
 632                  if($struct[$key]["acat_alias"]) {
 633                      $nav_table .= html_specialchars($struct[$key]["acat_alias"]);
 634                  } else {
 635                      $nav_table .= 'id='.$key; //',0,0,1,0,0';
 636                  }
 637                  $nav_table .= '">';
 638              } else {
 639                  $redirect = get_redirect_link($struct[$key]["acat_redirect"], ' ', '');
 640                  $nav_table .= '<a href="'.$redirect['link'].'"'.$redirect['target'].'>';
 641              }
 642  
 643              $nav_table .= html_specialchars($struct[$key]["acat_name"])."</a></td>\n<tr>";
 644          }
 645      }
 646      $nav_table .= '</table>';
 647      return $nav_table;
 648  }
 649  
 650  function nav_level_row($show_id, $show_home=1) {
 651      //returns a simple row based navigation
 652  
 653      if(strtoupper($show_id) == 'CURRENT') {
 654          $act_cat_id = $GLOBALS['content']["cat_id"];
 655      } else {
 656          $act_cat_id = intval($show_id);
 657      }
 658  
 659      $nav = '';
 660  
 661      if($show_home && $GLOBALS['content']['struct'][$act_cat_id]['acat_hidden'] != 1) {
 662          if($GLOBALS['content']["cat_id"] == $act_cat_id) {
 663              $before = $GLOBALS['template_default']["nav_row"]["link_before_active"];
 664              $after  = $GLOBALS['template_default']["nav_row"]["link_after_active"];
 665              $direct_before    = $GLOBALS['template_default']["nav_row"]["link_direct_before_active"];
 666              $direct_after    = $GLOBALS['template_default']["nav_row"]["link_direct_after_active"];
 667          } else {
 668              $before = $GLOBALS['template_default']["nav_row"]["link_before"];
 669              $after  = $GLOBALS['template_default']["nav_row"]["link_after"];
 670              $direct_before    = $GLOBALS['template_default']["nav_row"]["link_direct_before"];
 671              $direct_after    = $GLOBALS['template_default']["nav_row"]["link_direct_after"];
 672          }
 673          $nav .= $before;
 674          $nav .= '<a href="index.php?';
 675          $nav .= ($GLOBALS['content']['struct'][$act_cat_id]['acat_alias']) ? html_specialchars($GLOBALS['content']['struct'][$act_cat_id]['acat_alias']) : 'id='.$act_cat_id; //',0,0,1,0,0';
 676          $nav .= '"'.(empty($GLOBALS['content']['struct'][$act_cat_id]["acat_class"]) ? '' : ' class="'.$GLOBALS['content']['struct'][$act_cat_id]["acat_class"].'"').'>'.$direct_before;
 677          $nav .= html_specialchars($GLOBALS['content']['struct'][$act_cat_id]['acat_name']);
 678          $nav .= $direct_after.'</a>'.$after;
 679      }
 680  
 681      // check against breadcrumb - active site tree
 682      if($GLOBALS['content']['struct'][$GLOBALS['content']["cat_id"]]['acat_struct'] != 0) {
 683          $breadcrumb = get_breadcrumb($GLOBALS['content']["cat_id"], $GLOBALS['content']['struct']);
 684      }
 685  
 686      foreach($GLOBALS['content']['struct'] as $key => $value) {
 687      
 688          if($key != $act_cat_id && _getStructureLevelDisplayStatus($key, $act_cat_id) ) {
 689              
 690              $class = empty($GLOBALS['content']['struct'][$key]["acat_class"]) ? '' : ' class="'.$GLOBALS['content']['struct'][$key]["acat_class"].'"';
 691  
 692              if($nav) {
 693                  $nav .= $GLOBALS['template_default']["nav_row"]["between"];
 694              }
 695  
 696              if($GLOBALS['content']["cat_id"] == $key || isset($breadcrumb[$key])) {
 697                  $before = $GLOBALS['template_default']["nav_row"]["link_before_active"];
 698                  $after  = $GLOBALS['template_default']["nav_row"]["link_after_active"];
 699                  $direct_before    = $GLOBALS['template_default']["nav_row"]["link_direct_before_active"];
 700                  $direct_after    = $GLOBALS['template_default']["nav_row"]["link_direct_after_active"];
 701              } else {
 702                  $before = $GLOBALS['template_default']["nav_row"]["link_before"];
 703                  $after  = $GLOBALS['template_default']["nav_row"]["link_after"];
 704                  $direct_before    = $GLOBALS['template_default']["nav_row"]["link_direct_before"];
 705                  $direct_after    = $GLOBALS['template_default']["nav_row"]["link_direct_after"];
 706              }
 707  
 708              $nav .= $before;
 709  
 710              if(!$GLOBALS['content']['struct'][$key]["acat_redirect"]) {
 711                  $nav .= '<a href="index.php?';
 712                  if($GLOBALS['content']['struct'][$key]["acat_alias"]) {
 713                      $nav .= html_specialchars($GLOBALS['content']['struct'][$key]["acat_alias"]);
 714                  } else {
 715                      $nav .= 'id='.$key; //',0,0,1,0,0';
 716                  }
 717                  $nav .= '"'.$class.'>';
 718              } else {
 719                  $redirect = get_redirect_link($GLOBALS['content']['struct'][$key]["acat_redirect"], ' ', '');
 720                  $nav .= '<a href="'.$redirect['link'].'"'.$redirect['target'].$class.'>';
 721              }
 722              $nav .= $direct_before;
 723              $nav .= html_specialchars($GLOBALS['content']['struct'][$key]['acat_name']);;
 724              $nav .= $direct_after.'</a>'.$after;
 725          }
 726      }
 727      if($nav) {
 728          $nav  = $GLOBALS['template_default']["nav_row"]["before"].$nav;
 729          $nav .= $GLOBALS['template_default']["nav_row"]["after"];
 730      }
 731      return $nav;
 732  }
 733  
 734  function nav_table_struct (&$struct, $act_cat_id, $level, $nav_table_struct, $link_to="index.php") {
 735      // start with home directory for the listing = top nav structure
 736      // 1. Build the recursive tree for given actual article category ID
 737  
 738      // return the tree starting with given start_id (like breadcrumb)
 739      // if the $start_id = 0 then this stops because 0 = top level
 740  
 741      $level             = intval($level);
 742      $start_id         = $act_cat_id;
 743      $data             = array();
 744      $c                 = 0;
 745      $total_levels     = 0;
 746      $level_depth     = 0;
 747      //$start_level     = $level;
 748      while ($start_id) {
 749          $data[$start_id]    = 1;
 750          $start_id            = $struct[$start_id]["acat_struct"];
 751          $total_levels++;
 752      }
 753  
 754      if(is_array($data) && count($data)) {
 755          $temp_tree = array_reverse($data, 1);
 756      } else {
 757          $temp_tree = false;
 758      }
 759  
 760      foreach($struct as $key => $value) {
 761          if($struct[$key]["acat_struct"] == $act_cat_id && $key && (!$struct[$key]["acat_hidden"] || isset($GLOBALS['LEVEL_KEY'][$key]))) {
 762              $c++;
 763          }
 764      }
 765      $c = (!$c) ? 1 : 0;
 766  
 767      //build image src path and real image tag
 768      $nav_table_struct["linkimage_over_js"]  = get_real_imgsrc($nav_table_struct["linkimage_over"]);
 769  
 770      $nav_table_struct["linkimage_norm"]        = add_linkid($nav_table_struct["linkimage_norm"],   '#');
 771      $nav_table_struct["linkimage_over"]        = add_linkid($nav_table_struct["linkimage_over"],   '#');
 772      $nav_table_struct["linkimage_active"]    = add_linkid($nav_table_struct["linkimage_active"], '#');
 773  
 774      $lc = count($temp_tree);
 775      $ld = false;
 776      for($l = 0; $l <= $lc; $l++) {
 777  
 778          if(isset($GLOBALS['LEVEL_ID'][$l])) {
 779  
 780              $curStructID = $GLOBALS['LEVEL_ID'][$l];
 781              // now all deeper levels can be deleted
 782              if($ld) {
 783                  unset($temp_tree[$curStructID]);
 784              }
 785  
 786              if(!isset($nav_table_struct['array_struct'][$l])) {
 787  
 788                  $nav_table_struct['array_struct'][$l]["linkimage_over_js"]    = $nav_table_struct["linkimage_over_js"];
 789                  $nav_table_struct['array_struct'][$l]["linkimage_norm"]        = $nav_table_struct["linkimage_norm"];
 790                  $nav_table_struct['array_struct'][$l]["linkimage_over"]        = $nav_table_struct["linkimage_over"];
 791                  $nav_table_struct['array_struct'][$l]["linkimage_active"]    = $nav_table_struct["linkimage_active"];
 792  
 793                  $nav_table_struct['array_struct'][$l]["link_before"]        = $nav_table_struct["link_before"];
 794                  $nav_table_struct['array_struct'][$l]["link_after"]            = $nav_table_struct["link_after"];
 795                  $nav_table_struct['array_struct'][$l]["link_active_before"]    = $nav_table_struct["link_active_before"];
 796                  $nav_table_struct['array_struct'][$l]["link_active_after"]    = $nav_table_struct["link_active_after"];
 797  
 798                  $nav_table_struct['array_struct'][$l]["row_norm_bgcolor"]    = $nav_table_struct["row_norm_bgcolor"];
 799                  $nav_table_struct['array_struct'][$l]["row_norm_class"]        = $nav_table_struct["row_norm_class"];
 800                  $nav_table_struct['array_struct'][$l]["row_over_bgcolor"]    = $nav_table_struct["row_over_bgcolor"];
 801                  $nav_table_struct['array_struct'][$l]["row_active_bgcolor"]    = $nav_table_struct["row_active_bgcolor"];
 802                  $nav_table_struct['array_struct'][$l]["row_active_class"]    = $nav_table_struct["row_active_class"];
 803  
 804                  $nav_table_struct['array_struct'][$l]["space_celltop"]        = $nav_table_struct["space_celltop"];
 805                  $nav_table_struct['array_struct'][$l]["space_cellbottom"]    = $nav_table_struct["space_cellbottom"];
 806  
 807                  $nav_table_struct['array_struct'][$l]["cell_height"]        = $nav_table_struct["cell_height"];
 808                  $nav_table_struct['array_struct'][$l]["cell_class"]            = $nav_table_struct["cell_class"];
 809                  $nav_table_struct['array_struct'][$l]["cell_active_height"]    = $nav_table_struct["cell_active_height"];
 810                  $nav_table_struct['array_struct'][$l]["cell_active_class"]    = $nav_table_struct["cell_active_class"];
 811  
 812              } else {
 813  
 814                  $nav_table_struct['array_struct'][$l]["linkimage_over_js"]    = get_real_imgsrc($nav_table_struct['array_struct'][$l]["linkimage_over"]);
 815                  $nav_table_struct['array_struct'][$l]["linkimage_norm"]        = add_linkid($nav_table_struct['array_struct'][$l]["linkimage_norm"],   '#');
 816                  $nav_table_struct['array_struct'][$l]["linkimage_over"]        = add_linkid($nav_table_struct['array_struct'][$l]["linkimage_over"],   '#');
 817                  $nav_table_struct['array_struct'][$l]["linkimage_active"]    = add_linkid($nav_table_struct['array_struct'][$l]["linkimage_active"], '#');
 818  
 819              }
 820  
 821              if($struct[$curStructID]['acat_hidden'] == 1) {
 822                  unset($temp_tree[$curStructID]);
 823                  $ld = true;
 824              }
 825  
 826          }
 827  
 828      }
 829  
 830      $temp_menu = build_levels ($struct, $level, $temp_tree, $act_cat_id, $nav_table_struct, $level_depth, $c, $link_to); //starts at root level
 831      if($temp_menu) {
 832          initFrontendJS();
 833          return "<table".table_attributes($nav_table_struct, "table", 0)." summary=\"\">\n".$temp_menu."</table>";
 834      }
 835      return '';
 836  }
 837  
 838  function get_real_imgsrc($img='') {
 839      // strips real src attribute from image tag
 840      if($img) {
 841          $img = preg_replace('/.*src=["|\'](.*?)["|\'].*/i', "$1", $img);
 842      }
 843      return $img;
 844  }
 845  
 846  function add_linkid($img='', $linkid='') {
 847      //used to add the link ID for js over functions
 848      $img = preg_replace('/( \/>|>)$/', $linkid."$1", $img);
 849      return $img;
 850  }
 851  
 852  function build_levels ($struct, $level, $temp_tree, $act_cat_id, $nav_table_struct, $count, $div, $link_to) {
 853  
 854      // this returns the level structure based on given arrays
 855      // it is special for browsing from root levels
 856  
 857      $nav_table_struct["linkimage_over_js"]    = $nav_table_struct['array_struct'][$count]["linkimage_over_js"];
 858      $nav_table_struct["linkimage_norm"]        = $nav_table_struct['array_struct'][$count]["linkimage_norm"];
 859      $nav_table_struct["linkimage_over"]        = $nav_table_struct['array_struct'][$count]["linkimage_over"];
 860      $nav_table_struct["linkimage_active"]    = $nav_table_struct['array_struct'][$count]["linkimage_active"];
 861      $nav_table_struct["row_norm_bgcolor"]    = $nav_table_struct['array_struct'][$count]["row_norm_bgcolor"];
 862      $nav_table_struct["row_norm_class"]        = $nav_table_struct['array_struct'][$count]["row_norm_class"];
 863      $nav_table_struct["row_over_bgcolor"]    = $nav_table_struct['array_struct'][$count]["row_over_bgcolor"];
 864      $nav_table_struct["row_active_bgcolor"]    = $nav_table_struct['array_struct'][$count]["row_active_bgcolor"];
 865      $nav_table_struct["row_active_class"]    = $nav_table_struct['array_struct'][$count]["row_active_class"];
 866      $nav_table_struct["space_celltop"]        = $nav_table_struct['array_struct'][$count]["space_celltop"];
 867      $nav_table_struct["space_cellbottom"]    = $nav_table_struct['array_struct'][$count]["space_cellbottom"];
 868      $nav_table_struct["cell_height"]        = $nav_table_struct['array_struct'][$count]["cell_height"];
 869      $nav_table_struct["cell_class"]            = $nav_table_struct['array_struct'][$count]["cell_class"];
 870      $nav_table_struct["cell_active_height"]    = $nav_table_struct['array_struct'][$count]["cell_active_height"];
 871      $nav_table_struct["cell_active_class"]    = $nav_table_struct['array_struct'][$count]["cell_active_class"];
 872      $nav_table_struct["link_before"]        = $nav_table_struct['array_struct'][$count]["link_before"];
 873      $nav_table_struct["link_after"]            = $nav_table_struct['array_struct'][$count]["link_after"];
 874      $nav_table_struct["link_active_before"]    = $nav_table_struct['array_struct'][$count]["link_active_before"];
 875      $nav_table_struct["link_active_after"]    = $nav_table_struct['array_struct'][$count]["link_active_after"];
 876  
 877      $temp_menu        = '';
 878      $js             = '';
 879      $depth             = count($temp_tree)-$div;
 880      $current_level    = $count;
 881      $count++;
 882      $depth2         = $depth-$count+2;
 883      $right_cell     = '';
 884      $left_cell         = '';
 885      $cell_top         = '';
 886      $cell_bottom     = '';
 887      $space_right    = '';
 888      $space_cell     = '';
 889      $space_row         = '';
 890      $cell_height     = $nav_table_struct["cell_height"] ? $nav_table_struct["cell_height"] : 1;
 891  
 892      if($nav_table_struct["space_right"]) {
 893          $right_cell  = "<td width=\"".$nav_table_struct["space_left"]."\">";
 894          $right_cell .= spacer($nav_table_struct["space_right"], $cell_height)."</td>\n";
 895          $space_right = "<td>".spacer(1, 1)."</td>";
 896      }
 897      if($nav_table_struct["space_left"]) {
 898          $colspan    = ($count > 1) ? " colspan=\"".$count."\"" : "";
 899          $left_cell    = "<td width=\"".$nav_table_struct["space_left"]."\"".$colspan.">";
 900          $left_cell .= spacer($nav_table_struct["space_left"], $cell_height)."</td>\n";
 901          $space_cell = "<td".$colspan.">".spacer(1, 1)."</td><td>".spacer(1, 1)."</td>";
 902      } else {
 903          if($count > 1) {
 904              $colspan    = ($count > 2) ? " colspan=\"".($count-1)."\"" : "";
 905              $left_cell    = "<td ".$colspan.">".spacer(1, 1)."</td>\n";
 906              $space_cell = "<td".$colspan.">".spacer(1, 1)."</td><td>".spacer(1, 1)."</td>";
 907          }
 908      }
 909      if($nav_table_struct["space_celltop"]) $cell_top = spacer(1, $nav_table_struct["space_celltop"])."<br />";
 910      if($nav_table_struct["space_cellbottom"]) $cell_bottom = "<br />".spacer(1, $nav_table_struct["space_cellbottom"]);
 911  
 912      $colspan    = ($depth2 > 1) ? ' colspan="'.($depth2).'"' : '';
 913  
 914      foreach($struct as $key => $value) {
 915  
 916          if( _getStructureLevelDisplayStatus($key, $level) ) {
 917              
 918              $link_image_id    = "linkid".randpassword(6);
 919              $link_name_id     = ' name="'.$link_image_id.'" id="'.$link_image_id.'"';
 920  
 921              if(!$struct[$key]["acat_redirect"]) {
 922                  $link = 'index.php?';
 923                  if($struct[$key]["acat_alias"]) {
 924                      $link .= html_specialchars($struct[$key]["acat_alias"]);
 925                  } else {
 926                      $link .= 'id='.$key; //',0,0,1,0,0';
 927                  }
 928                  $redirect['target'] = '';
 929              } else {
 930                  $redirect = get_redirect_link($struct[$key]["acat_redirect"], ' ', '');
 931                  $link = $redirect['link'];
 932              }
 933  
 934              $js        = ' style="cursor:pointer;cursor:hand;"'; //display:block;
 935              $js_act = $js;
 936              if($nav_table_struct["js_over_effects"]) {
 937  
 938                  if($redirect['target'] != ' target="_blank"') {
 939                      $js .= " onclick=\"location.href='".js_singlequote($link)."';return false;\"";
 940                  } else {
 941                      $js .= " onclick=\"window.open('".js_singlequote($link)."', 'phpwcmnewwin');return false;\"";
 942                  }
 943  
 944                  $js_act = $js;
 945                  $js .= ' onmouseover="';
 946                  if($nav_table_struct["linkimage_over_js"]) {
 947                      $js .= "MM_swapImage('".$link_image_id."','','".$nav_table_struct["linkimage_over_js"]."',1);";
 948                  }
 949                  if($nav_table_struct["row_over_bgcolor"]) $js .= "this.bgColor='".$nav_table_struct["row_over_bgcolor"]."';";
 950                  $js .= '" onmouseout="';
 951                  if($nav_table_struct["linkimage_over_js"]) $js .= "MM_swapImgRestore();";
 952                  if($nav_table_struct["row_norm_bgcolor"]) $js .= "this.bgColor='".$nav_table_struct["row_norm_bgcolor"]."';";
 953                  $js .= '"';
 954              } else {
 955                  $js = '';
 956              }
 957              
 958              // add structure level based classes
 959              if(!empty($struct[$key]["acat_class"])) {
 960                  $nav_table_struct_temp = $nav_table_struct;
 961                  $nav_table_struct["row_norm_class"]        = trim($nav_table_struct["row_norm_class"].' '.$struct[$key]["acat_class"]);
 962                  $nav_table_struct["row_active_class"]    = trim($nav_table_struct["row_active_class"].' '.$struct[$key]["acat_class"]);
 963                  $nav_table_struct["row_space_class"]    = 'row_space '.$struct[$key]["acat_class"];
 964              } else {
 965                  $nav_table_struct_temp = NULL;
 966              }
 967  
 968              //spacer row
 969              if($nav_table_struct["row_space"]) {
 970                  $space_row  = "<tr".table_attributes($nav_table_struct, "row_space", 0, true).">\n".$space_cell;
 971                  $space_row .= "<td".$colspan.">".spacer(1, $nav_table_struct["row_space"])."</td>";
 972                  $space_row .= $space_right."\n</tr>\n";
 973                  $temp_menu .= $space_row;
 974              }
 975  
 976              if(!empty($temp_tree[$key])) {
 977                  //if($act_cat_id == $key) {
 978                  //check if inside active tree structure
 979                  if($act_cat_id == $key || (!empty($nav_table_struct["all_nodes_active"]) && isset($GLOBALS['LEVEL_KEY'][$key]))) {
 980                      $temp_menu .= "<tr".table_attributes($nav_table_struct, "row_active", 0, true).$js_act.">\n".$left_cell;
 981                      $temp_menu .= "<td valign=\"top\">".str_replace('#', $link_name_id, $nav_table_struct["linkimage_active"])."</td>\n";
 982                      $temp_menu .= "<td".table_attributes($nav_table_struct, "cell_active", 1, true).$colspan.">".$cell_top;
 983                      $temp_menu .= '<a href="'.$link.'"'.$redirect['target'].'>';
 984                      $temp_menu .= $nav_table_struct["link_active_before"];
 985                      $temp_menu .= html_specialchars($struct[$key]["acat_name"]);
 986                      $temp_menu .= $nav_table_struct["link_active_after"].'</a>';
 987                  } else {
 988                      $temp_menu .= "<tr".table_attributes($nav_table_struct, "row_norm", 0, true).$js.">\n".$left_cell;
 989                      $temp_menu .= "<td valign=\"top\">".str_replace('#', $link_name_id, $nav_table_struct["linkimage_norm"])."</td>\n";
 990                      $temp_menu .= "<td".table_attributes($nav_table_struct, "cell", 1, true).$colspan.">".$cell_top;
 991                      $temp_menu .= '<a href="'.$link.'"'.$redirect['target'].'>';
 992                      $temp_menu .= $nav_table_struct["link_before"];
 993                      $temp_menu .= html_specialchars($struct[$key]["acat_name"]);
 994                      $temp_menu .= $nav_table_struct["link_after"].'</a>';
 995                  }
 996  
 997                  $temp_menu .= $cell_bottom."</td>\n".$right_cell."</tr>\n";
 998                  $temp_menu .= build_levels ($struct, $key, $temp_tree, $act_cat_id, $nav_table_struct, $count, $div, $link_to);
 999              } else {
1000                  $temp_menu .= "<tr".table_attributes($nav_table_struct, "row_norm", 0, true).$js.">\n".$left_cell;
1001                  $temp_menu .= "<td valign=\"top\">".str_replace('#', $link_name_id, $nav_table_struct["linkimage_norm"])."</td>\n";
1002                  $temp_menu .= "<td".table_attributes($nav_table_struct, "cell", 1, true).$colspan.">".$cell_top;
1003                  $temp_menu .= '<a href="'.$link.'"'.$redirect['target'].'>';
1004                  $temp_menu .= $nav_table_struct["link_before"];
1005                  $temp_menu .= html_specialchars($struct[$key]["acat_name"]);
1006                  $temp_menu .= $nav_table_struct["link_after"].'</a>';
1007                  $temp_menu .= $cell_bottom."</td>\n".$right_cell."</tr>\n";
1008              }
1009              
1010              // reset table structure attributes
1011              if($nav_table_struct_temp !== NULL) {
1012                  $nav_table_struct = $nav_table_struct_temp;
1013              }
1014          }
1015      }
1016  
1017      if($nav_table_struct["row_space"] && $count == 1) {
1018          $temp_menu .= $space_row;
1019      }
1020  
1021      return $temp_menu;
1022  }
1023  
1024  function list_articles_summary($alt=NULL, $topcount=99999, $template='') {
1025      // returns an article listing only with headline and summary text
1026      // and with an listing of all other available articles of this category
1027  
1028      global $content;
1029      global $template_default;
1030      global $_getVar;
1031  
1032      // alternative way to send article listings
1033      if(is_array($alt)) {
1034          // first save default value of $content["articles"]
1035          $_old_articles            = $content["articles"];
1036          $content["articles"]    = $alt;
1037          $temp_topcount            = intval($topcount);
1038          if($temp_topcount == 0) {
1039              $temp_topcount        = $content['struct'][ $content['cat_id'] ]['acat_topcount'];
1040          }
1041          $template                = trim($template);
1042      } else {
1043          $temp_topcount = $content['struct'][ $content['cat_id'] ]['acat_topcount'];
1044      }
1045  
1046      $max_articles = count($content["articles"]);
1047  
1048      if(empty($template_default['article_paginate_show'])) {
1049          $paginate_show = array('bottom'=>1);
1050      } else {
1051          $paginate_show = array();
1052          foreach((explode(' ', $template_default['article_paginate_show'])) as $value) {
1053              if($value == 'top') {
1054                  $paginate_show['top'] = 1;
1055              } elseif($value == 'bottom') {
1056                  $paginate_show['bottom'] = 1;
1057              } elseif(strpos($value, 'rt') !== false) {
1058                  $paginate_show['rt'] = str_replace('rt', '', $value);
1059              }
1060          }
1061          if(!count($paginate_show)) {
1062              $paginate_show = array('bottom'=>1);
1063          }
1064      }
1065  
1066      if($content['struct'][ $content['cat_id'] ]['acat_paginate'] && $content['struct'][ $content['cat_id'] ]['acat_maxlist'] && $max_articles > $content['struct'][ $content['cat_id'] ]['acat_maxlist']) {
1067  
1068          $paginate         = true;
1069          $paginate_navi    = empty($template_default['article_paginate_navi']) ? '<div class="phpwcmsArticleListNavi">{PREV:&laquo;} {NEXT:&raquo;}</div>' : $template_default['article_paginate_navi'];
1070          $max_pages        = ceil($max_articles / $content['struct'][ $content['cat_id'] ]['acat_maxlist']);
1071  
1072          // always do full top article listing because of paginating
1073          $temp_topcount    = $max_articles+1;
1074  
1075          if(isset($_getVar['listpage'])) {
1076              $page_current = intval($_getVar['listpage']);
1077              if($page_current < 1) {
1078                  $page_current = 1;
1079              } elseif($page_current > $max_pages) {
1080                  $page_current = $max_pages;
1081              }
1082          } else {
1083              $page_current = 1;
1084          }
1085  
1086          $page_next = $page_current;
1087          $page_prev = $page_current;
1088          if($page_current < $max_pages) {
1089              $page_next = $page_current + 1;
1090          }
1091          if($page_current > 1) {
1092              $page_prev = $page_current - 1;
1093          }
1094  
1095          // setting pagination navi
1096  
1097          $page_article_max = $content['struct'][ $content['cat_id'] ]['acat_maxlist'] * $page_current;
1098          $page_article_at  = $content['struct'][ $content['cat_id'] ]['acat_maxlist'] * ($page_current - 1);
1099          $page_article_at  = $page_article_at + 1;
1100          if($page_article_max > $max_articles) $page_article_max = $max_articles;
1101  
1102          $paginate_navi = str_replace('#####',    $max_articles,             $paginate_navi);
1103          $paginate_navi = str_replace('####',    $page_article_max,         $paginate_navi);
1104          $paginate_navi = str_replace('###',     $page_article_at,        $paginate_navi);
1105          $paginate_navi = str_replace('##',         $max_pages,             $paginate_navi);
1106          $paginate_navi = str_replace('#',         $page_current,             $paginate_navi);
1107  
1108          $GLOBALS['paginate_temp'] = array('next' => '', 'prev' => '', 'navi' => '');
1109  
1110          $paginate_navi = preg_replace_callback('/\{NEXT:(.*?)\}/', create_function('$matches', '$GLOBALS["paginate_temp"]["next"]=$matches[1]; return "{NEXT}";'), $paginate_navi);
1111          $paginate_navi = preg_replace_callback('/\{PREV:(.*?)\}/', create_function('$matches', '$GLOBALS["paginate_temp"]["prev"]=$matches[1]; return "{PREV}";'), $paginate_navi);
1112          $paginate_navi = preg_replace_callback('/\{NAVI:(.*?)\}/', create_function('$matches', '$GLOBALS["paginate_temp"]["navi"]=$matches[1]; return "{NAVI}";'), $paginate_navi);
1113  
1114          // next page link
1115          if($GLOBALS['paginate_temp']['next'] && $page_current < $max_pages) {
1116              $_getVar['listpage'] = $page_next;
1117              $page_next_link = '<a href="index.php' . returnGlobalGET_QueryString('htmlentities') . '">' . $GLOBALS['paginate_temp']['next'] . '</a>';
1118          } else {
1119              $page_next_link = $GLOBALS['paginate_temp']['next'];
1120          }
1121  
1122          // previous page link
1123          if($GLOBALS['paginate_temp']['prev'] && $page_current > 1) {
1124              $_getVar['listpage'] = $page_prev;
1125              $page_prev_link = '<a href="index.php' . returnGlobalGET_QueryString('htmlentities') . '">' . $GLOBALS['paginate_temp']['prev'] . '</a>';
1126          } else {
1127              $page_prev_link = $GLOBALS['paginate_temp']['prev'];
1128          }
1129  
1130          // set listpage value to current page
1131  
1132          $paginate_navi = str_replace('{NEXT}', $page_next_link, $paginate_navi);
1133          $paginate_navi = str_replace('{PREV}', $page_prev_link, $paginate_navi);
1134  
1135          // temporary unset GET listpage setting
1136          unset($_getVar['listpage']);
1137  
1138          if($GLOBALS['paginate_temp']['navi']) {
1139  
1140              $navi = explode(',', $GLOBALS['paginate_temp']['navi'], 2);
1141              $navi[0] = trim($navi[0]);
1142  
1143              $navi[1]         = empty($navi[1])    ? array(0 => ' ') : explode('|', $navi[1]);
1144              $navi['spacer']    = empty($navi[1][0]) ? ' ' : $navi[1][0]; //spacer
1145              $navi['prefix']    = empty($navi[1][1]) ? ''  : $navi[1][1]; //prefix
1146              $navi['suffix']    = empty($navi[1][2]) ? ''  : $navi[1][2]; //suffix
1147  
1148              $navi['navi']     = $navi['prefix'];
1149  
1150              if($navi[0] == '123') {
1151  
1152                  for($i = 1; $i <= $max_pages; $i++) {
1153  
1154                      if($i > 1) $navi['navi'] .= $navi['spacer'];
1155                      $navi['navi'] .= ($i == $page_current) ? $i : '<a href="' . rel_url( array('listpage'=>$i) ) . '">'.$i.'</a>';
1156  
1157                  }
1158  
1159              } elseif($navi[0] == '1-3') {
1160  
1161                  for($i = 0; $i < $max_pages; $i++) {
1162  
1163                      $i_start    = $i * $content['struct'][ $content['cat_id'] ]['acat_maxlist'] + 1;
1164                      $i_end        = $i_start - 1 + $content['struct'][ $content['cat_id'] ]['acat_maxlist'];
1165                      if($i_end > $max_articles) $i_end = $max_articles;
1166  
1167                      if($i > 0) $navi['navi'] .= $navi['spacer'];
1168                      $i_entry     = $i_start.'&ndash;'.$i_end;
1169                      $i_page     = $i+1;
1170                      $navi['navi'] .= ($i_page == $page_current) ? $i_entry : '<a href="' . rel_url( array('listpage'=>$i_page) ) . '">'.$i_entry.'</a>';
1171  
1172                  }
1173  
1174              }
1175  
1176              $navi['navi'] .= $navi['suffix'];
1177  
1178              // replace navi
1179              $paginate_navi = str_replace('{NAVI}', $navi['navi'], $paginate_navi);
1180  
1181          }
1182  
1183          // reset GET listpage setting
1184          $_getVar['listpage'] = $page_current;
1185  
1186          unset($GLOBALS['paginate_temp']);
1187  
1188      } else {
1189          $paginate         = false;
1190          $paginate_navi    = '';
1191      }
1192  
1193  
1194      $tmpllist         = array(); //temporary array for storing templates to minimize load
1195      $temp_counter     = 0;
1196      $space_counter    = 0;
1197  
1198      $listing         = $template_default["space_top"]; //start with space at top
1199  
1200      if(isset($paginate_show['top'])) {
1201          $listing        .= str_replace('{POS}', 'top', $paginate_navi);
1202      }
1203  
1204      foreach($content["articles"] as $article) {
1205  
1206          if($paginate && $content['struct'][ $content['cat_id'] ]['acat_maxlist']) {
1207              // get page number based on current article counter
1208              $page_article = ceil( ($temp_counter + 1) / $content['struct'][ $content['cat_id'] ]['acat_maxlist']);
1209              if($page_article > $page_current) {
1210                  //stop listing
1211                  break;
1212              } elseif($page_article != $page_current) {
1213                  //no listing - goto next article
1214                  $temp_counter++;
1215                  continue;
1216              }
1217          }
1218  
1219          $link_data        = get_article_morelink($article);
1220          $article_link     = $link_data[0];
1221  
1222          //add available keywords to page wide keyword field
1223          $content['all_keywords'] .= $article["article_keyword"].',';
1224  
1225          if($temp_counter < $temp_topcount) {
1226              // as long as the counter is lower than the default "top_count" value
1227              // show the complete article summary listing
1228  
1229              $article["article_image"] = setArticleSummaryImageData($article["article_image"]);
1230              
1231              if($template) {
1232                  $article["article_image"]['tmpllist'] = $template;
1233              }
1234  
1235              // build image/image link
1236              $article["article_image"]["poplink"]    = '';
1237              $thumb_image                             = false;
1238              $thumb_img                                 = '';
1239              
1240              $img_thumb_name        = '';
1241              $img_thumb_rel        = '';
1242              $img_thumb_abs        = '';
1243              $img_thumb_width    = 0;
1244              $img_thumb_height    = 0;
1245              $img_thumb_ext        = 'jpg';
1246              
1247              $img_zoom_name        = '';
1248              $img_zoom_rel        = '';
1249              $img_zoom_abs        = '';
1250              $img_zoom_width        = 0;
1251              $img_zoom_height    = 0;
1252              
1253              if(empty($article["article_image"]["list_caption"])) {
1254                  $article["article_image"]["list_caption"] = '';
1255              }
1256              $caption = getImageCaption($article["article_image"]["list_caption"]);
1257  
1258              $article["article_image"]["list_caption"]    = $caption[0]; // caption text
1259              $article["article_image"]["copyright"]        = $caption[4]; // copyright information
1260              $article["article_image"]["list_alt"]        = $caption[1]; // alt text
1261              $article["article_image"]["list_title"]        = $caption[3]; // title text
1262              
1263              if(!empty($article["article_image"]["list_hash"])) {
1264  
1265                  $thumb_image = get_cached_image(
1266                                      array(    "target_ext"    =>    $article["article_image"]['list_ext'],
1267                                              "image_name"    =>    $article["article_image"]['list_hash'] . '.' . $article["article_image"]['list_ext'],
1268                                              "max_width"        =>    $article["article_image"]['list_width'],
1269                                              "max_height"    =>    $article["article_image"]['list_height'],
1270                                              "thumb_name"    =>    md5($article["article_image"]['list_hash'].$article["article_image"]['list_width'].$article["article_image"]['list_height'].$GLOBALS['phpwcms']["sharpen_level"])
1271                                        ));
1272  
1273                  if($thumb_image != false) {
1274                  
1275                      $img_thumb_name        = $thumb_image[0];
1276                      $img_thumb_rel        = PHPWCMS_IMAGES.$thumb_image[0];
1277                      $img_thumb_abs        = PHPWCMS_URL.PHPWCMS_IMAGES.$thumb_image[0];
1278                      $img_thumb_width    = $thumb_image[1];
1279                      $img_thumb_height    = $thumb_image[2];
1280                      $img_thumb_ext        = $article["article_image"]['list_ext'];
1281  
1282                      $caption[3] = empty($caption[3]) ? '' : ' title="'.html_specialchars($caption[3]).'"';
1283                      $caption[1] = html_specialchars($caption[1]);
1284  
1285                      $thumb_img = '<img src="'.PHPWCMS_IMAGES . $thumb_image[0] .'" border="0" '.$thumb_image[3].' alt="'.$caption[1].'"'.$caption[3].' />';
1286  
1287                      if($article["article_image"]["list_zoom"]) {
1288  
1289                          $zoominfo = get_cached_image(
1290                                              array(    "target_ext"    =>    $article["article_image"]['list_ext'],
1291                                                      "image_name"    =>    $article["article_image"]['list_hash'] . '.' . $article["article_image"]['list_ext'],
1292                                                      "max_width"        =>    $GLOBALS['phpwcms']["img_prev_width"],
1293                                                      "max_height"    =>    $GLOBALS['phpwcms']["img_prev_height"],
1294                                                      "thumb_name"    =>    md5($article["article_image"]['list_hash'].$GLOBALS['phpwcms']["img_prev_width"].$GLOBALS['phpwcms']["img_prev_height"].$GLOBALS['phpwcms']["sharpen_level"])
1295                                                        )
1296                                                  );
1297  
1298                          if($zoominfo != false) {
1299                          
1300                              $img_zoom_name        = $zoominfo[0];
1301                              $img_zoom_rel        = PHPWCMS_IMAGES.$zoominfo[0];
1302                              $img_zoom_abs        = PHPWCMS_URL.PHPWCMS_IMAGES.$zoominfo[0];
1303                              $img_zoom_width        = $zoominfo[1];
1304                              $img_zoom_height    = $zoominfo[2];
1305  
1306                              $article["article_image"]["poplink"] = 'image_zoom.php?'.getClickZoomImageParameter($zoominfo[0].'?'.$zoominfo[3]);
1307  
1308                              if(!empty($caption[2][0])) {
1309                                  $open_link = $caption[2][0];
1310                                  $return_false = '';
1311                              } else {
1312                                  $open_link = $article["article_image"]["poplink"];
1313                                  $return_false = 'return false;';
1314                              }
1315  
1316                              if(empty($article["article_image"]["list_lightbox"]) && !empty($caption[2][0])) {
1317                                  
1318                                  initFrontendJS();
1319                                  
1320                                  $article["article_image"]["poplink"]  = '<a href="'.$article["article_image"]["poplink"].'" ';
1321                                  $article["article_image"]["poplink"] .= 'onclick="checkClickZoom();clickZoom(\''.$open_link;
1322                                  $article["article_image"]["poplink"] .= "','previewpic','width=".$zoominfo[1];
1323                                  $article["article_image"]["poplink"] .= ",height=".$zoominfo[2]."');".$return_false;
1324                                  $article["article_image"]["poplink"] .= '"'.$caption[2][1].'>';
1325                              } else {
1326                                  // lightbox
1327                                  initSlimbox();
1328                                  
1329                                  $article["article_image"]["poplink"]  = '<a href="'.PHPWCMS_IMAGES.$zoominfo[0].'" rel="lightbox" ';
1330                                  if($article["article_image"]["list_caption"]) {
1331                                      $article["article_image"]["poplink"] .= 'title="'.parseLightboxCaption($article["article_image"]["list_caption"]).'" ';
1332                                  }
1333                                  $article["article_image"]["poplink"] .= 'target="_blank">';
1334                              }
1335                                                                     
1336                              $article["article_image"]["poplink"] .= $thumb_img.'</a>';
1337                          }
1338                      }
1339  
1340                      unset($caption);
1341                  }
1342              } else {
1343              
1344                  $article["article_image"]["list_id"]    = 0;
1345                  $article["article_image"]["list_hash"]    = '';
1346      
1347              }
1348  
1349  
1350              // set default template
1351              if(empty($article["article_image"]['tmpllist']) || $article["article_image"]['tmpllist'] == 'default') {
1352  
1353                  $article["article_image"]['tmpllist'] = 'default';
1354  
1355                  if(empty($tmpllist['default'])) {
1356  
1357                      $tmpllist['default'] = file_get_contents(PHPWCMS_TEMPLATE.'inc_default/article_summary_list.tmpl');
1358  
1359                  }
1360  
1361              }
1362  
1363              // try to read the template files
1364              // 1. try to check if template was read
1365              if(!isset($tmpllist[ $article["article_image"]['tmpllist'] ])) {
1366                  $tmpllist[ $article["article_image"]['tmpllist'] ] = @file_get_contents(PHPWCMS_TEMPLATE.'inc_cntpart/articlesummary/list/'.$article["article_image"]['tmpllist']);
1367              }
1368              if($tmpllist[ $article["article_image"]['tmpllist'] ]) {
1369              
1370                  // set frontend edit link
1371                  $tmpl  = getFrontendEditLink('summary', $article['article_id']);
1372              
1373                  //rendering
1374                  $tmpl .= $tmpllist[ $article["article_image"]['tmpllist'] ];
1375                  
1376                  $tmpl = render_cnt_template($tmpl, 'TITLE', empty($article['article_notitle']) ? html_specialchars($article["article_title"]) : '' );
1377                  $tmpl = render_cnt_template($tmpl, 'SUB', html_specialchars($article["article_subtitle"]));
1378                  
1379                  // replace thumbnail and zoom image information
1380                  $tmpl = str_replace( array(    '{THUMB_NAME}', '{THUMB_REL}', '{THUMB_ABS}', '{THUMB_WIDTH}', '{THUMB_HEIGHT}',
1381                                              '{IMAGE_NAME}', '{IMAGE_REL}', '{IMAGE_ABS}', '{IMAGE_WIDTH}', '{IMAGE_HEIGHT}',
1382                                              '{IMAGE_ID}',     '{IMAGE_HASH}', '{IMAGE_EXT}' ),
1383                                       array(    $img_thumb_name, $img_thumb_rel, $img_thumb_abs, $img_thumb_width, $img_thumb_height,
1384                                              $img_zoom_name, $img_zoom_rel, $img_zoom_abs, $img_zoom_width, $img_zoom_height,
1385                                              $article["article_image"]["list_id"], $article["article_image"]["list_hash"], $img_thumb_ext ),
1386                                       $tmpl );
1387                  
1388                  if( preg_match('/\{SUMMARY:(\d+)\}/', $tmpl, $matches) ) {
1389                      if(empty($article['article_image']['list_maxwords'])) {
1390                          $article['article_image']['list_maxwords'] = intval($matches[1]);
1391                      }                    
1392                      $tmpl = preg_replace('/\{SUMMARY:\d+\}/', '{SUMMARY}', $tmpl);
1393                  }
1394                  
1395                  if(strpos($article["article_summary"], '-//-')) {
1396                      $article["article_summary"] = explode('-//-', $article["article_summary"]);
1397                      $article['article_image']['list_maxwords_temp'] = count(preg_split("/[\s,]+/", $article["article_summary"][0], -1, PREG_SPLIT_NO_EMPTY));
1398                      if(empty($article['article_image']['list_maxwords']) || $article['article_image']['list_maxwords_temp'] < $article['article_image']['list_maxwords']) {
1399                          $article['article_image']['list_maxwords'] = $article['article_image']['list_maxwords_temp'];
1400                          $article["article_summary"] = trim($article["article_summary"][0]);
1401                      } else {
1402                          $article["article_summary"] = implode(' ', $article["article_summary"]);
1403                      }
1404                  }
1405                  
1406                  $tmpl = render_cnt_template($tmpl, 'SUMMARY', empty($article['article_image']['list_maxwords']) ? $article["article_summary"] : getCleanSubString($article["article_summary"], $article['article_image']['list_maxwords'], $template_default['ellipse_sign'], 'word', true));
1407                  $tmpl = render_cnt_template($tmpl, 'IMAGE', $thumb_img);
1408                  $tmpl = render_cnt_template($tmpl, 'ZOOMIMAGE', $article["article_image"]["poplink"]);
1409                  $tmpl = render_cnt_template($tmpl, 'CAPTION', nl2br(html_specialchars($article["article_image"]["list_caption"])));
1410                  $tmpl = render_cnt_template($tmpl, 'ALT', html_specialchars($article["article_image"]["list_alt"]));
1411                  $tmpl = render_cnt_template($tmpl, 'IMAGE_TITLE', html_specialchars($article["article_image"]["list_title"]));
1412                  $tmpl = render_cnt_template($tmpl, 'COPYRIGHT', html_specialchars($article["article_image"]["copyright"]));
1413                  $tmpl = render_cnt_template($tmpl, 'ARTICLELINK', $article["article_morelink"] ? $article_link : '');
1414                  $tmpl = render_cnt_template($tmpl, 'EDITOR', html_specialchars($article["article_username"]));
1415                  $tmpl = render_cnt_template($tmpl, 'ARTICLEID', $article["article_id"]);
1416                  $tmpl = render_cnt_template($tmpl, 'MORE', $article["article_morelink"] ? $template_default["top_readmore_link"] : '');
1417                  $tmpl = render_cnt_template($tmpl, 'TARGET', ($article["article_morelink"] && $link_data[1]) ? ' target="'.$link_data[1].'"' : '');
1418                  $tmpl = render_cnt_template($tmpl, 'BEFORE', '<!--before//-->');
1419                  $tmpl = render_cnt_template($tmpl, 'AFTER', '<!--after//-->');
1420                  $tmpl = render_cnt_date($tmpl, $article["article_date"], $article["article_livedate"], $article["article_killdate"] );
1421                  if($space_counter) {
1422                      $tmpl = render_cnt_template($tmpl, 'SPACE', '<!--space//-->');
1423                  } else {
1424                      $tmpl = render_cnt_template($tmpl, 'SPACE', '');
1425                  }
1426                  $listing .= $tmpl;
1427                  $article["article_image"]['tmpllist'] = 1;
1428              } else {
1429                  $article["article_image"]['tmpllist'] = 0;
1430              }
1431  
1432          } else {
1433              // if "top_count" value is equal or larger
1434              // show only the article headline listing
1435              if($temp_counter && $temp_counter == $temp_topcount) {
1436                  $listing .= $template_default["space_aftertop_text"];
1437              } elseif ($temp_counter) {
1438                  $listing .= $template_default["space_between_list"];
1439              }
1440              
1441              $listing .= $template_default["list_headline_before"];
1442              
1443              // set frontend edit link
1444              $listing .= getFrontendEditLink('article', $article['article_id']);
1445              $listing .= getFrontendEditLink('summary', $article['article_id']);            
1446              
1447              $listing .= '<a href="'.$article_link.'">';
1448              $listing .= $template_default["list_startimage"];
1449              $listing .= html_specialchars($article["article_title"]);
1450              $listing .= '</a>'.$template_default["list_headline_after"];
1451  
1452          }
1453          $temp_counter++;
1454          $space_counter++;
1455      }
1456  
1457      if(isset($paginate_show['bottom'])) {
1458          $listing .= str_replace('{POS}', 'bottom', $paginate_navi);
1459      }
1460      if(!empty($paginate_show['rt'])) {
1461          $content['globalRT'][ $paginate_show['rt'] ] = $paginate_navi;
1462      }
1463  
1464      // restore original articles
1465      if(isset($_old_articles)) {
1466          $content["articles"]    = $_old_articles;
1467      }
1468  
1469      $listing .= $template_default["space_bottom"]; //ends with space at bottom
1470      return $listing;
1471  }
1472  
1473  function get_html_part($value, $class="", $link="", $span_or_div=1) {
1474      // returns a content part for html output like
1475      // <span class="xxx">html</span>
1476      if($value) {
1477          $html_tag  = ($span_or_div) ? 'span' : 'div';
1478          $html_part = ($link) ? '<a href="'.$link.'">'.html_specialchars($value).'</a>' : html_specialchars($value);
1479          if($class) {
1480              $html_part = '<'.$html_tag.' class="'.$class.'">'.$html_part;
1481          } else {
1482              $html_part = '<'.$html_tag.'>'.$html_part;
1483          }
1484          return $html_part.'</'.$html_tag.'>';
1485      } else {
1486          return '';
1487      }
1488  }
1489  
1490  function span_class($value, $class) {
1491      return !empty($class) ? '<span class="'.$class.'">'.$value.'</span>' : $value;
1492  }
1493  
1494  function div_class($value, $class, $tag='div') {
1495      return !empty($class) ? '<'.$tag.' class="'.$class.'">'.$value.'</'.$tag.'>' : $value;
1496  }
1497  
1498  function get_class_attrib($class) {
1499      return !empty($class) ? ' class="'.$class.'"' : '';
1500  }
1501  
1502  function html_parser($string) {
1503      // parse the $string and replace all possible
1504      // values with $replace
1505      
1506      if(trim($string) == '') {
1507          return $string;    
1508      }
1509      
1510      $string = render_bbcode_basics($string, '');
1511  
1512      // page TOP link
1513      $search[0]        = '/\[TOP\](.*?)\[\/TOP\]/is';
1514      $replace[0]        = '<a href="#top" class="phpwcmsTopLink">$1</a>';
1515  
1516      // internal Link to article ID
1517      $search[1]        = '/\[ID (\d+)\](.*?)\[\/ID\]/s';
1518      $replace[1]        = '<a href="index.php?aid=$1" class="phpwcmsIntLink">$2</a>';
1519  
1520      // external Link (string)
1521      $search[2]        = '/\[EXT (.*?)\](.*?)\[\/EXT\]/s';
1522      $replace[2]        = '<a href="$1" target="_blank" class="phpwcmsExtLink">$2</a>';
1523  
1524      // internal Link (string)
1525      $search[3]        = '/\[INT (.*?)\](.*?)\[\/INT\]/s';
1526      $replace[3]        = '<a href="$1" class="phpwcmsIntLink">$2</a>';
1527  
1528      // random GIF Image
1529      $search[4]        = '/\{RANDOM_GIF:(.*?)\}/';
1530      $replace[4]        = '<img src="img/random_image.php?type=0&imgdir=$1" border="0" alt="" />';
1531  
1532      // random JPEG Image
1533      $search[5]        = '/\{RANDOM_JPEG:(.*?)\}/';
1534      $replace[5]        = '<img src="img/random_image.php?type=1&amp;imgdir=$1" border="0" alt="" />';
1535  
1536      // random PNG Image
1537      $search[6]        = '/\{RANDOM_PNG:(.*?)\}/';
1538      $replace[6]        = '<img src="img/random_image.php?type=2&amp;imgdir=$1" border="0" alt="" />';
1539  
1540      // insert non db image standard
1541      $search[7]        = '/\{IMAGE:(.*?)\}/';
1542      $replace[7]        = '<img src="picture/$1" border="0" alt="" />';
1543  
1544      // insert non db image left
1545      $search[8]        = '/\{IMAGE_LEFT:(.*?)\}/';
1546      $replace[8]        = '<img src="picture/$1" border="0" align="left" alt="" />';
1547  
1548      // insert non db image right
1549      $search[9]        = '/\{IMAGE_RIGHT:(.*?)\}/';
1550      $replace[9]        = '<img src="picture/$1" border="0" align="right" alt="" />';
1551  
1552      // insert non db image center
1553      $search[10]        = '/\{IMAGE_CENTER:(.*?)\}/';
1554      $replace[10]        = '<div align="center"><img src="picture/$1" border="0" alt="" /></div>';
1555  
1556      // insert non db image right
1557      $search[11]         = '/\{SPACER:(\d+)x(\d+)\}/';
1558      $replace[11]     = '<img src="img/leer.gif" border="0" width="$1" height="$2" alt="" />';
1559  
1560      // RSS feed link 
1561      $search[13]        = '/\[RSS (.*?)\](.*?)\[\/RSS\]/s';
1562      $replace[13]    = '<a href="feeds.php?feed=$1" target="_blank" class="phpwcmsRSSLink">$2</a>';
1563  
1564      // back Link (string)
1565      $search[14]        = '/\[BACK\](.*?)\[\/BACK\]/i';
1566      $replace[14]     = '<a href="#" target="_top" title="go back" onclick="history.back();return false;" class="phpwcmsBackLink">$1</a>';
1567  
1568      // random Image Tag
1569      $search[15]        = '/\{RANDOM:(.*?)\}/e';
1570      $replace[15]    = 'get_random_image_tag("$1");';
1571  
1572      // span or div style
1573      $search[16]        = '/\[(span|div)_style:(.*?)\](.*?)\[\/style\]/s';
1574      $replace[16]    = '<$1 style="$2">$3</$1>';
1575  
1576      // span or div class
1577      $search[17]        = '/\[(span|div)_class:(.*?)\](.*?)\[\/class\]/s';
1578      $replace[17]    = '<$1 class="$2">$3</$1>';
1579  
1580      // anchor link
1581      $search[22]        = '/\{A:(.*?)\}/is';
1582      $replace[22]    = '<a name="$1" class="phpwcmsAnchorLink"></a>';
1583  
1584      // this parses an E-Mail Link without subject (by Florian, 21-11-2003)
1585      $search[23]     = '/\[E{0,1}MAIL (.*?)\](.*?)\[\/E{0,1}MAIL\]/is';
1586      $replace[23]    = '<a href="mailto:$1" class="phpwcmsMailtoLink">$2</a>';
1587  
1588      // this tags out a Mailaddress with an predifined subject (by Florian, 21-11-2003)
1589      $search[24]     = '/\[MAILSUB (.*?) (.*?)\](.*?)\[\/MAILSUB\]/is';
1590      $replace[24]    = '<a href="mailto:$1?subject=$2" class="phpwcmsMailtoLink">$3</a>';
1591  
1592      $search[26]     = '/\<br>/i';
1593      $replace[26]    = '<br />';
1594  
1595      // create "make bookmark" javascript code
1596      $search[27]     = '/\[BOOKMARK\s{0,}(.*)\](.*?)\[\/BOOKMARK\]/is';
1597      $replace[27]    = '<a href="#" onclick="return BookMark_Page(\'$1\');" title="$1" class="phpwcmsBookmarkLink">$2</a>';
1598  
1599      // ABBreviation
1600      $search[28]        = '/\[abbr (.*?)\](.*?)\[\/abbr\]/is';
1601      $replace[28]    = '<abbr title="$1">$2</abbr>';
1602  
1603      $search[29]        = '/\[dfn (.*?)\](.*?)\[\/dfn\]/is';
1604      $replace[29]    = '<dfn title="$1">$2</dfn>';
1605  
1606      $search[34]        = '/\[blockquote (.*?)\](.*?)\[\/blockquote\]/is';
1607      $replace[34]    = '<blockquote cite="$1">$2</blockquote>';
1608  
1609      $search[35]        = '/\[acronym (.*?)\](.*?)\[\/acronym\]/is';
1610      $replace[35]    = '<acronym title="$1">$2</acronym>';
1611  
1612      $search[36]        = '/\[ID (.*?)\](.*?)\[\/ID\]/s';
1613      $replace[36]    = '<a href="index.php?$1" class="phpwcmsIntLink">$2</a>';
1614  
1615      $search[49]     = '/\[E{0,1}MAIL\](.*?)\[\/E{0,1}MAIL\]/is';
1616      $replace[49]    = '<a href="mailto:$1" class="phpwcmsMailtoLink">$1</a>';
1617      
1618      $string = preg_replace($search, $replace, $string);
1619      $string = str_replace(
1620          array(
1621              '&#92;&#039;',
1622              '&amp;quot;',
1623              '-//-'
1624          ), 
1625          array(
1626              '&#039;',
1627              '&quot;',
1628              ' '
1629          ),
1630          $string
1631      );
1632      return $string;
1633  }
1634  
1635  function include_ext_php($inc_file, $t=0) {
1636      // includes an external PHP script file and returns
1637      // the result as string from buffered include content
1638  
1639      //check if this is a local file
1640      if(!$t && is_file($inc_file)) {
1641  
1642          $this_path = str_replace("\\", '/', dirname(realpath($inc_file)));
1643          $this_path = preg_replace('/\/$/', '', $this_path);
1644  
1645          $root_path = str_replace("\\", '/', realpath(PHPWCMS_ROOT));
1646          $root_path = preg_replace('/\/$/', '', $root_path);
1647  
1648          if(strpos($this_path, $root_path) === 0) $t = 1;
1649  
1650      } elseif(!$t && !empty($GLOBALS['phpwcms']['allow_remote_URL'])) {
1651          //if remote URL is allowed in conf.inc.php
1652          $t = 1;
1653      }
1654  
1655      if(!$t) {
1656          return '';
1657      }
1658  
1659      ob_start();
1660      @include($inc_file);
1661      return ob_get_clean();;
1662  }
1663  
1664  function international_date_format($language="EN", $format="Y/m/d", $date_now=0) {
1665      // formats the given date
1666      // for the specific language
1667      // use the normal date format options
1668  
1669      if(!$format) {
1670          $format = "Y/m/d";
1671      }
1672      if(!intval($date_now)) {
1673          $date_now = time();
1674      }
1675      if($language == "EN" || !$language) {
1676          return date($format, $date_now);
1677      } else {
1678          $lang_include = PHPWCMS_ROOT.'/include/inc_lang/date/'.substr(strtolower($language), 0, 2).'.date.lang.php';
1679          if(is_file($lang_include)) {
1680  
1681              include($lang_include);
1682              $date_format_function = array (    "a" => 1, "A" => 1, "B" => 1, "d" => 1, "g" => 1, "G" => 1,
1683                                      "h" => 1, "H" => 1, "i" => 1, "I" => 1, "j" => 1, "m" => 1,
1684                                      "n" => 1, "s" => 1, "t" => 1, "T" => 1, "U" => 1, "w" => 1,
1685                                      "Y" => 1, "y" => 1, "z" => 1, "Z" => 1,
1686                                      "D" => 0, "F" => 0, "l" => 0, "M" => 0, "S" => 0
1687                                     );
1688  
1689              $str_length = strlen($format); $date = "";
1690              for($i = 0; $i < $str_length; $i++) $date_format[$i] = substr($format, $i, 1);
1691              foreach($date_format as $key => $value) {
1692                  if(isset($date_format_function[$value])) {
1693                      if($date_format_function[$value]) {
1694                          $date .= date($value, $date_now);
1695                      } else{
1696                          switch($value) {
1697                              case "D":    $date .= $weekday_short[ intval(date("w", $date_now)) ]; break; //short weekday name
1698                              case "l":    $date .= $weekday_long[ intval(date("w", $date_now)) ]; break; //long weekday name
1699                              case "F":    $date .= $month_long[ intval(date("n", $date_now)) ]; break; //long month name
1700                              case "M":    $date .= $month_short[ intval(date("n", $date_now)) ]; break; //long month name
1701                              case "S":    $date .= ""; break;
1702                          }
1703                      }
1704                  } else {
1705                      $date .= $value;
1706                  }
1707              }
1708  
1709          } else {
1710              $date = date($format, $date_now);
1711          }
1712      }
1713      return $date;
1714  }
1715  
1716  function get_random_image_tag($path) {
1717      // returns an random image from the give path
1718      // it looks for image of following type: gif, jpg, jpeg, png
1719      // {RANDOM:path} willl return <img src="path/rand_image" />
1720      // {RANDOM:SRC:path} willl return absolute URI PHPWCMS_URL/path/rand_image
1721  
1722      $imgArray    = array();
1723      $path        = trim($path);
1724      if(strtoupper(substr($path, 0, 4)) == 'SRC:') {
1725          $tag    = false;
1726          $path    = trim(substr($path, 4));
1727      } else {
1728          $tag    = true;
1729      }
1730      
1731      $path        = trim($path, '/');
1732      $imgpath    = PHPWCMS_ROOT . '/' . $path . '/';
1733      $imageinfo    = false;
1734  
1735      if(is_dir($imgpath)) {
1736          $handle = opendir( $imgpath );
1737          while($file = readdir( $handle )) {
1738                 if( $file{0} != '.' && preg_match('/(\.jpg|\.jpeg|\.gif|\.png)$/i', $file)) {
1739                  $imgArray[] = $file;
1740              }
1741          }
1742          closedir( $handle );
1743      }
1744  
1745      if(count($imgArray) && ($imageinfo = is_random_image($imgArray, $imgpath))) {
1746          if($tag) {
1747              return '<img src="'.$path.'/'.urlencode($imageinfo['imagename']).'" '.$imageinfo[3].' border="0" alt="'.html_specialchars($imageinfo["imagename"]).'"'.HTML_TAG_CLOSE;
1748          } else {
1749              return PHPWCMS_URL . $path . '/' . urlencode($imageinfo['imagename']);
1750          }
1751      }
1752  
1753      return '';
1754  }
1755  
1756  function is_random_image($imgArray, $imagepath, $count=0) {
1757      // tests if the random choosed image is really an image
1758      $count++;
1759      $randval = mt_rand( 0, count( $imgArray ) - 1 );
1760      $file = $imagepath.$imgArray[ $randval ];
1761      $imageinfo = @getimagesize($file);
1762      //if $imageinfo is not true repeat function and count smaller count all images
1763      if(!$imageinfo && $count < count($imgArray)) {
1764          $imageinfo = is_random_image($imgArray, $imagepath, $count);
1765      } else {
1766          $imageinfo["imagename"] = $imgArray[ $randval ];
1767      }
1768      return $imageinfo;
1769  }
1770  
1771  function return_struct_level(&$struct, $struct_id) {
1772      // walk through the given struct level and returns an array with available levels
1773      $level_entry = array();
1774      if(is_array($struct)) {
1775          foreach($struct as $key => $value) {
1776              if( _getStructureLevelDisplayStatus($key, $struct_id) ) {
1777                  $level_entry[$key] = $value;
1778              }
1779          }
1780      }
1781      return $level_entry;
1782  }
1783  
1784  function get_active_categories($struct, $act_struct_id) {
1785      // returns an array with all active categories/structure levels
1786  
1787      $which_cat_array = array();
1788      $which_category = $act_struct_id;
1789      while($which_category) {
1790          $which_cat_array[$which_category] = 1;
1791          $which_category = $GLOBALS['content']["struct"][$which_category]["acat_struct"];
1792      }
1793      return $which_cat_array;
1794  }
1795  
1796  function css_level_list(&$struct, $struct_path, $level, $parent_level_name='', $parent_level=1, $class='') {
1797      // returns list <div><ul><li></li></ul></div> of the current structure level
1798      // if $parent_level=1 the first list entry will be the parent level
1799      // $parent_level=0 - only the list of all levels in this structure
1800      // if $parent_leve_name != "" then it uses the given string
1801      // predefined class for this menu is "list_level"
1802      if(!trim($class)) {
1803          $class = 'list_level';
1804      }
1805      $parent_level_name    = trim($parent_level_name);
1806      $level                 = intval($level);
1807      $parent_level         = intval($parent_level);
1808      $activated            = 0;
1809      $css_list            = '';
1810  
1811      //returns the complete level of NON hidden categories
1812      $level_struct         = return_struct_level($struct, $level);
1813      $breadcrumb         = get_breadcrumb(key($struct_path), $struct);
1814  
1815      foreach($level_struct as $key => $value) {
1816  
1817          if(!$level_struct[$key]["acat_redirect"]) {
1818              $link = 'index.php?';
1819              if($level_struct[$key]["acat_alias"]) {
1820                  $link .= html_specialchars($level_struct[$key]["acat_alias"]);
1821              } else {
1822                  $link .= 'id='.$key;
1823              }
1824              $redirect['target'] = '';
1825          } else {
1826              $redirect = get_redirect_link($level_struct[$key]["acat_redirect"], ' ', '');
1827              $link = $redirect['link'];
1828          }
1829          $css_list .= '    <li';
1830          $liclass   = trim( (empty($breadcrumb[$key]) ? '' : 'active ') . $level_struct[$key]["acat_class"] );
1831          $css_list .= empty($liclass) ? '' : ' class="'.$liclass.'"';
1832          $css_list .= '><a href="'.$link.'"'.$redirect['target'].'>';
1833          $css_list .= html_specialchars($level_struct[$key]["acat_name"]);
1834          $css_list .= '</a></li>'.LF;
1835  
1836      }
1837  
1838      if($parent_level) {
1839          if(!$struct[$level]["acat_redirect"]) {
1840              $link = 'index.php?';
1841              if($struct[$level]["acat_alias"]) {
1842                  $link .= html_specialchars($struct[$level]["acat_alias"]);
1843              } else {
1844                  $link .= 'id='.$level;
1845              }
1846              $redirect['target'] = '';
1847          } else {
1848              $redirect = get_redirect_link($struct[$level]["acat_redirect"], ' ', '');
1849              $link = $redirect['link'];
1850          }
1851  
1852          $css_list_home  = '    <li class="' . trim( ($GLOBALS['aktion'][0] == $level ? 'active' : 'parent') . ' ' . $struct[$level]["acat_class"] ) .'">';
1853          $css_list_home .= '<a href="'.$link.'"'.$redirect['target'].'>';
1854          $css_list_home .= html_specialchars((!$parent_level_name) ? $struct[$level]["acat_name"] : $parent_level_name);
1855          $css_list_home .= '</a></li>'.LF;
1856          $css_list = $css_list_home . $css_list;
1857      }
1858      if($css_list) {
1859          $css_list = LF.'<ul class="'.$class.'">'.LF . $css_list .'</ul>'.LF;
1860      }
1861      return $css_list;
1862  }
1863  
1864  // REWRITE - PATCHED FOR 04/04 // jan212
1865  function url_search($query) {
1866      if ( substr($query,0,4) == '?id=') {
1867          $noid = substr($query, 4);
1868          $file = str_replace(',', '.', $noid).PHPWCMS_REWRITE_EXT;
1869      } else {
1870          $noid = substr($query,1);
1871          $file = str_replace(',', '.', $noid).PHPWCMS_REWRITE_EXT;
1872          $file = str_replace('aid=', 'aid'.rawurlencode('='), $file);
1873      }
1874      $link = ' href="'.str_replace('aid=', 'aid'.rawurlencode('='), $file).'"';
1875      return($link);
1876  }
1877  
1878  function js_url_search($query) {
1879      if ( substr($query,0,4) == '?id=') {
1880          $noid = substr($query, 4);
1881          $file = str_replace(',', '.', $noid).PHPWCMS_REWRITE_EXT;
1882      } else {
1883          $noid = substr($query,1);
1884          $file = str_replace(',', '.', $noid).PHPWCMS_REWRITE_EXT;
1885          $file = str_replace('aid=', 'aid'.rawurlencode('='), $file);
1886      }
1887      $link = "onclick=\"location.href='".$file."'";
1888      return($link);
1889  }
1890  
1891  function get_related_articles($keywords, $current_article_id, $template_default, $max_cnt_links=0, $dbcon) {
1892      // find keyword for current article used for RELATED replacementtag
1893      // prepared and inspired by Magnar Stav Johanssen
1894  
1895      $keyword_links = '';
1896      $max_cnt_links = intval($max_cnt_links);
1897      
1898      // replace unwanted chars and convert to wanted
1899      $keywords = str_replace(
1900          array("ALLKEYWORDS",";", "'", ' ', ',,'),
1901          array($GLOBALS['content']['all_keywords'].',', ",", '', ',', ','),
1902          strtoupper($keywords)
1903      );
1904  
1905      // choose comma separated keywords
1906      $keywordarray = convertStringToArray($keywords);
1907      
1908      // check for empty keywords or keywords smaller than 3 chars
1909      if(is_array($keywordarray) && count($keywordarray)) {
1910          foreach($keywordarray as $key => $value) {
1911  
1912              if(substr($keywordarray[$key], 0, 1) == '-') {
1913                  $doNotUse = substr($keywordarray[$key], 1);
1914                  foreach($keywordarray as $key2 => $value2) {
1915                      if($doNotUse == $value2) {
1916                          unset($keywordarray[$key2]);
1917                          unset($keywordarray[$key]);
1918                      }
1919                  }
1920              }
1921  
1922              if(isset($keywordarray[$key]) && (strlen($keywordarray[$key]) < 3 || empty($keywordarray[$key]))) {
1923                  unset($keywordarray[$key]);
1924              }
1925          }
1926      }
1927  
1928      if(is_array($keywordarray) && count($keywordarray)) {
1929          $where = "";
1930          foreach($keywordarray as $value) {
1931                  //build where keyword = blabla
1932                  $where .= ($where) ? " OR " : "";
1933                  //replace every "'" to "''" for security reasons with aporeplace()
1934                  $where .= "article_keyword LIKE '%".aporeplace($value)."%'";
1935          }
1936          $limit = ($max_cnt_links) ? " LIMIT ".$max_cnt_links : "";
1937          $sql  =    "SELECT article_id, article_title, article_cid, article_subtitle, article_summary, article_alias, article_redirect, article_morelink ";
1938          $sql .=    "FROM ".DB_PREPEND."phpwcms_article WHERE article_deleted=0 AND ";
1939          $sql .=    "article_id<>".intval($current_article_id)." AND ";
1940          // VISIBLE_MODE: 0 = frontend (all) mode, 1 = article user mode, 2 = admin user mode
1941          switch(VISIBLE_MODE) {
1942              case 0: $sql .=    "article_public=1 AND article_aktiv=1 AND ";
1943                      break;
1944              case 1: $sql .= "article_uid=".$_SESSION["wcs_user_id"]." AND ";
1945                      break;
1946              //case 2: admin mode no additional neccessary
1947          }
1948          $sql .=    "article_begin < NOW() AND article_end > NOW() AND (".$where.") ";
1949          
1950          if(empty($template_default['sort_by'])) $template_default['sort_by'] = '';
1951          
1952          switch($template_default['sort_by']) {
1953          
1954              case 'title_asc': 
1955                          $sql .=    "ORDER BY article_title";
1956                          break;
1957                          
1958              case 'title_desc': 
1959                          $sql .=    "ORDER BY article_title DESC";
1960                          break;
1961                          
1962              case 'ldate_asc': 
1963                          $sql .=    "ORDER BY article_begin";
1964                          break;
1965                          
1966              case 'ldate_desc': 
1967                          $sql .=    "ORDER BY article_begin DESC";
1968                          break;
1969                          
1970              case 'kdate_asc': 
1971                          $sql .=    "ORDER BY article_end";
1972                          break;
1973                          
1974              case 'kdate_desc': 
1975                          $sql .=    "ORDER BY article_end DESC";
1976                          break;
1977                          
1978              case 'cdate_asc': 
1979                          $sql .=    "ORDER BY article_created";
1980                          break;
1981                          
1982              case 'cdate_desc': 
1983                          $sql .=    "ORDER BY article_created DESC";
1984                          break;
1985          
1986              default:
1987                          $sql .=    "ORDER BY article_tstamp DESC";
1988          }
1989          
1990          $sql .= $limit;
1991  
1992          // related things
1993          $target = $template_default["link_target"] ? ' target="'.$template_default["link_target"].'"' : '';
1994          $result = _dbQuery($sql);
1995          if(isset($result[0])) {
1996              foreach($result as $row) {
1997                  
1998                  if(empty($row['article_redirect'])) {
1999                      if(empty($row['article_morelink'])) {
2000                          continue;
2001                      }
2002                      $article_link = 'index.php?'.setGetArticleAid($row).'"'.$target;
2003                  } else {
2004                      $redirect = get_redirect_link($row['article_redirect'], ' ', '');
2005                      $article_link = $redirect['link'].'"'.$redirect['target'];
2006                  }
2007                  
2008                  if($template_default["link_length"] && strlen($row['article_title']) > $template_default["link_length"]) {
2009                      $article_title = substr($row['article_title'], 0, $template_default["link_length"]).$template_default["cut_title_add"];
2010                  } else {
2011                      $article_title = $row['article_title'];
2012                  }
2013                  $keyword_links .= $template_default["link_before"];
2014                  $keyword_links .= $template_default["link_symbol"];
2015                  $keyword_links .= '<a href="' . $article_link . '>';
2016                  $keyword_links .= html_specialchars($article_title);
2017                  $keyword_links .= '</a>' . $template_default["link_after"];
2018              }
2019          }
2020      }
2021  
2022      //enclose whole
2023      return empty($keyword_links) ? '' : $template_default["before"].$keyword_links.$template_default["after"];
2024  }
2025  
2026  function get_new_articles(&$template_default, $max_cnt_links=0, $cat, $dbcon) {
2027      // find all new articles
2028  
2029      $max_cnt_links = intval($max_cnt_links);
2030      $limit = empty($max_cnt_links) ?  '' : ' LIMIT '.$max_cnt_links;
2031      $cat = trim($cat);
2032      $cat = (intval($cat) || $cat == '0') ? 'article_cid='.intval($cat).' AND ' : '';
2033      
2034      $sql = 'SELECT article_id, article_title, article_cid, article_alias, article_redirect, article_morelink, ';
2035  
2036      switch( (empty($template_default["sort_by"]) ? '' : strtolower($template_default["sort_by"])) ) {
2037  
2038          case 'cdate':     //use real creation date
2039                          $sql .=    "article_created AS article_date ";
2040                          $sorting = 'article_created';
2041                          break;
2042  
2043          case 'ldate':     //use live/start date
2044                          $sql .=    "UNIX_TIMESTAMP(article_begin) AS article_date ";
2045                          $sorting = 'article_begin';
2046                          break;
2047  
2048          case 'kdate':     //use kill/end date
2049                          $sql .=    "UNIX_TIMESTAMP(article_end) AS article_date ";
2050                          $sorting = 'article_end';
2051                          break;
2052  
2053          default:        $sql .=    "UNIX_TIMESTAMP(article_tstamp) AS article_date ";
2054                          $sorting = 'article_tstamp';
2055      }
2056  
2057      $sql .=    "FROM ".DB_PREPEND."phpwcms_article WHERE ".$cat;
2058      // VISIBLE_MODE: 0 = frontend (all) mode, 1 = article user mode, 2 = admin user mode
2059      switch(VISIBLE_MODE) {
2060          case 0: $sql .=    "article_public=1 AND article_aktiv=1 AND ";
2061                  break;
2062          case 1: $sql .= "article_uid=".$_SESSION["wcs_user_id"]." AND ";
2063                  break;
2064          //case 2: admin mode no additional neccessary
2065      }
2066      $sql .= "article_deleted=0 AND article_begin < NOW() AND article_end > NOW() ";
2067      $sql .= "ORDER BY ".$sorting." DESC".$limit;
2068  
2069      // new articles list
2070      $new_links = "";
2071      $target = ($template_default["link_target"]) ? ' target="'.$template_default["link_target"].'"' : '';
2072      
2073      $result = _dbQuery($sql);
2074      $count  = 0;
2075      
2076      foreach($result as $row) {
2077          
2078              if(empty($row['article_redirect'])) {
2079                  if(empty($row['article_morelink'])) {
2080                      continue;
2081                  }
2082                  $article_link = 'index.php?'.setGetArticleAid($row).'"'.$target;
2083              } else {
2084                  $redirect = get_redirect_link($row['article_redirect'], ' ', '');
2085                  $article_link = $redirect['link'].'"'.$redirect['target'];
2086              }
2087          
2088              $count++;
2089              if($template_default["link_length"] && strlen($row['article_title']) > $template_default["link_length"]) {
2090                  $article_title = substr($row['article_title'], 0, $template_default["link_length"]).$template_default["cut_title_add"];
2091              } else {
2092                  $article_title = $row['article_title'];
2093              }
2094              $article_title = html_specialchars($article_title);
2095              if(trim($template_default["date_format"])) {
2096                  $article_title =     $template_default["date_before"] .
2097                                      html_specialchars(international_date_format(
2098                                      $template_default["date_language"],
2099                                      $template_default["date_format"],
2100                                      $row['article_date'])) .
2101                                      $template_default["date_after"] .
2102                                      $article_title;
2103              }
2104              $new_links .= $template_default["link_before"];
2105              $new_links .= $template_default["link_symbol"];
2106              $new_links .= '<a href="' . $article_link . '>' . $article_title . '</a>';
2107              $new_links .= $template_default["link_after"];
2108      }
2109  
2110      //enclose whole
2111      if($new_links) $new_links = $template_default["before"].$new_links.$template_default["after"];
2112  
2113      return $new_links;
2114  }
2115  
2116  function get_article_idlink($article_id=0, $link_text="", $db) {
2117      // returns the internal article link to given article ID/category
2118      $article_id        = intval($article_id);
2119      $article_cid    = 0;
2120      $link_text        = decode_entities($link_text);
2121      $link_text        = html_specialchars($link_text);
2122      $article_title    = $link_text;
2123  
2124      if($article_id) {
2125          $sql =    "SELECT article_id, article_title, article_cid, article_alias ".
2126                  "FROM ".DB_PREPEND."phpwcms_article ".
2127                  "WHERE article_id=".$article_id." AND ".
2128                  "article_public=1 AND article_aktiv=1 AND article_deleted=0 AND ".
2129                  "article_begin < NOW() AND article_end > NOW() LIMIT 1";
2130          $data = _dbQuery($sql);
2131          
2132          if(isset($data[0])) {
2133              return '<a href="index.php?'.setGetArticleAid($data[0]).'" title="'.$article_title.'">'.$link_text.'</a>';
2134          }
2135      }
2136      return '<a href="index.php?aid='.$article_id.'" title="'.$article_title.'">'.$link_text.'</a>';
2137  }
2138  
2139  function get_keyword_link($keywords="", $db) {
2140      // returns a link or linklist for special article keywords
2141      // used for replacement tag {KEYWORD:Charlie}
2142  
2143      $keywords = explode(",", $keywords);
2144      $where = "";
2145      $keyword_list = "";
2146      $link = "";
2147  
2148      if(count($keywords)) {
2149          foreach($keywords as $value) {
2150              $value = trim($value);
2151              if($value) {
2152                  if($where) {
2153                      $where .= " AND ";
2154                      $keyword_list .= ", ";
2155                  }
2156                  $where .= "article_keyword LIKE '%*".aporeplace($value)."*%'";
2157                  $keyword_list .= html_specialchars($value);
2158              }
2159          }
2160      } else {
2161          $keyword_list = $keywords;
2162      }
2163  
2164      if($where) {
2165  
2166          $x = 0;
2167          $sql  = "SELECT article_id, article_cid, article_title, article_alias FROM ".DB_PREPEND."phpwcms_article WHERE ";
2168          // VISIBLE_MODE: 0 = frontend (all) mode, 1 = article user mode, 2 = admin user mode
2169          switch(VISIBLE_MODE) {
2170              case 0: $sql .=    "article_public=1 AND article_aktiv=1 AND ";
2171                      break;
2172              case 1: $sql .= "article_uid=".$_SESSION["wcs_user_id"]." AND ";
2173                      break;
2174              //case 2: admin mode no additional neccessary
2175          }
2176          $sql .= "article_deleted=0 AND article_begin < NOW() ";
2177          $sql .=    "AND article_end > NOW() AND (".$where.")";
2178  
2179          if($result = mysql_query($sql, $db)) {
2180              $article_list = array();
2181              while($row = mysql_fetch_row($result)) {
2182                  $article_list[$x][0] = $row[0]; //article ID
2183                  $article_list[$x][1] = $row[1]; //article catID
2184                  $article_list[$x][2] = html_specialchars($row[2]); //article title
2185                  $article_list[$x]['article_alias'] = $row[3];
2186                  $article_list[$x]['article_id'] = $row[0];
2187                  $x++;
2188              }
2189              mysql_free_result($result);
2190          }
2191  
2192          if($x) {
2193              // if keyword(s) found
2194              if($x == 1) {
2195                  // if only 1 article found
2196                  $link .= '<a href="index.php?'.setGetArticleAid($article_list[0]).'" title="'.$article_list[0][2].'">'.$keyword_list.'</a>';
2197              } else {
2198                  // if more than one article found
2199                  foreach($article_list as $key => $value) {
2200                      if($link) $link .= '|';
2201                      $link .= '<a href="index.php?'.setGetArticleAid($value).'" title="'.$article_list[$key][2].'">'.($key+1).'</a>';
2202                  }
2203                  $link = $keyword_list.' ['.$link.']';
2204              }
2205          }
2206      }
2207      if(!$link) $link = $keyword_list;
2208      $link  = $GLOBALS['template_default']["article"]["keyword_before"] . $link;
2209      $link .= $GLOBALS['template_default']["article"]["keyword_after"];
2210      return $link;
2211  
2212  }
2213  
2214  function clean_replacement_tags($text = '', $allowed_tags='<a><b><i><strong>') {
2215      // strip out special replacement tags
2216      $text = render_PHPcode($text);
2217      $text = str_replace('<td>', '<td> ', $text);
2218      $text = strip_tags($text, $allowed_tags);
2219      $text = str_replace('|', ' ', $text);
2220      
2221      $search = array(
2222                  '/\{.*?\}/si',
2223                  '/\[ID.*?\/ID\]/si',
2224                  '/(\s+)/i',
2225                  '/\[img=(\d+)(.*?){0,1}\](.*?)\[\/img\]/i',
2226                  '/\[img=(\d+)(.*?){0,1}\]/i',
2227                  '/\[download=(.*?)\/\]/i',
2228                  '/\[download=(.*?)\](.*?)\[\/download\]/is'
2229                      );
2230                      
2231      $replace = array(
2232                  '',
2233                  '',
2234                  ' ',
2235                  '$3',
2236                  '',
2237                  '',
2238                  '$2'
2239                      );
2240      
2241      $text = preg_replace($search, $replace, $text);
2242  
2243      return trim($text);
2244  }
2245  
2246  function get_search_action($id, $dbcon) {
2247      // return the search form action
2248      $id = intval($id); $cid = 0;
2249      if($id) {
2250          $sql  = "SELECT article_cid, article_alias FROM ".DB_PREPEND."phpwcms_article WHERE ";
2251          $sql .=    "article_public=1 AND article_aktiv=1 AND article_deleted=0 AND article_begin < NOW() ";
2252          $sql .=    "AND article_end > NOW() AND article_id=".$id." LIMIT 1";
2253          if($result = mysql_query($sql, $dbcon)) {
2254              if($row = mysql_fetch_row($result)) {
2255                  $cid = $row[0];
2256                  $data = array('article_id'=>$id, 'article_alias'=>$row[1]);
2257              }
2258              mysql_free_result($result);
2259          }
2260      }
2261      return ($cid) ? 'index.php?'.setGetArticleAid($data) : '';
2262  }
2263  
2264  function get_index_link_up($linktext) {
2265      // return the link to parent category of current category
2266      $cat_id = $GLOBALS['content']['cat_id'];
2267      $linktext = trim($linktext);
2268      $link = '';
2269      if(!$linktext) $linktext = 'UP';
2270      if($cat_id && !$GLOBALS['content']['struct'][$cat_id]['acat_hidden']) {
2271          $upid = $GLOBALS['content']['struct'][$cat_id]['acat_struct'];
2272          $link = '<a href="index.php?' . ( empty($GLOBALS['content']['struct'][$upid]['acat_alias']) ? 'id='.$upid : $GLOBALS['content']['struct'][$upid]['acat_alias'] ) .'">';
2273      }
2274      return ($link) ? $link.$linktext.'</a>' : $linktext;
2275  }
2276  
2277  function get_index_link_next($linktext, $cat_down=0) {
2278  
2279      global $content;
2280  
2281      // return the link to next article in current ctageory
2282      $a_id = isset($content['article_id']) ? $content['article_id'] : $GLOBALS['aktion'][1];
2283      $linktext = trim($linktext);
2284      if(!$linktext) $linktext = 'NEXT';
2285      $link = '';
2286  
2287      if(count($content['articles']) > 1) {
2288  
2289          $c = 0; //temp counter
2290          foreach($content['articles'] as $key => $value) {
2291              if($c || !$a_id) {
2292                  $link  = '<a href="index.php?aid='.$key.'">';
2293                  break;
2294              }
2295              if($key == $a_id) $c++;
2296          }
2297      }
2298  
2299      if($cat_down && !$link) {
2300          // go cat down or to next cat above
2301  
2302          if($content['cat_id']) {
2303              foreach($content['struct'] as $key => $value) {
2304                  if($content['struct'][$key]['acat_struct'] == $content['cat_id']) {
2305                      $link  = '<a href="index.php?';
2306                      $link .= empty($content['struct'][$key]['acat_alias']) ? 'id='.$key : html_specialchars($content['struct'][$key]['acat_alias']);
2307                      $link .= '">';
2308                      break;
2309                  }
2310              }
2311          } else {
2312              $c = 0;
2313              foreach($content['struct'] as $key => $value) {
2314                  if($c) {
2315                      $link  = '<a href="index.php?';
2316                      $link .= empty($content['struct'][$key]['acat_alias']) ? 'id='.$key : html_specialchars($content['struct'][$key]['acat_alias']);
2317                      $link .= '">';
2318                      break;
2319                  }
2320                  $c++;
2321              }
2322          }
2323  
2324          if(!$link && $content['cat_id']) {
2325              $c=0;
2326              $temp_key = array();
2327              foreach($content['struct'] as $key => $value) {
2328                  if($content['struct'][$key]['acat_struct'] == $content['struct'][ $content['cat_id'] ]['acat_struct']) {
2329                      $temp_key[] = $key;
2330                  }
2331              }
2332              $count_temp = count($temp_key);
2333              if($count_temp) {
2334                  $c=0;
2335                  foreach($temp_key as $value) {
2336                      if($value == $content['cat_id'] && $c+1 < $count_temp) {
2337                          //$link = '<a href="index.php?id='.$temp_key[$c+1].',0,0,1,0,0">';
2338                          
2339                          $key = $temp_key[$c+1];
2340                          
2341                          $link  = '<a href="index.php?';
2342                          $link .= empty($content['struct'][$key]['acat_alias']) ? 'id='.$key : html_specialchars($content['struct'][$key]['acat_alias']);
2343                          $link .= '">';
2344                          break;
2345                      }
2346                      $c++;
2347                  }
2348                  if($c == $count_temp && !$link) {
2349                      // back reverese to higher next structure level
2350                      $current_id = $content['cat_id'];
2351  
2352                      while($c=1) {
2353                          $parent_id = $content['struct'][ $current_id ]['acat_struct'];
2354                          $parent_struct_id = $content['struct'][ $parent_id ]['acat_struct'];
2355  
2356                          $c=0;
2357                          foreach($content['struct'] as $key => $value) {
2358                              if($content['struct'][$key]['acat_struct'] == $parent_struct_id) {
2359                                  if($c) {
2360                                      $link  = '<a href="index.php?';
2361                                      $link .= empty($content['struct'][$key]['acat_alias']) ? 'id='.$key : html_specialchars($content['struct'][$key]['acat_alias']);
2362                                      $link .= '">';
2363                                      break;
2364                                  }
2365                                  if($key == $parent_id) $c=1;
2366                              }
2367                          }
2368  
2369                          if(!$parent_struct_id) {
2370                              if(!$parent_id) $link = '';
2371                              break;
2372                          } else {
2373                              $current_id = $parent_id;
2374                          }
2375  
2376                      }
2377  
2378  
2379                  }
2380              }
2381          }
2382  
2383      }
2384  
2385      return ($link) ? $link.$linktext.'</a>' : $linktext;
2386  }
2387  
2388  function get_index_link_prev($linktext, $cat_up=0) {
2389      // return the link to next article in current ctageory
2390      $a_id = isset($GLOBALS['content']['article_id']) ? $GLOBALS['content']['article_id'] : $GLOBALS['aktion'][1];
2391      $linktext = trim($linktext);
2392      if(!$linktext) $linktext = 'PREV';
2393      $link = '';
2394      $c = 0; //temp counter
2395  
2396      if(count($GLOBALS['content']['articles']) > 1 && $a_id) {
2397  
2398          foreach($GLOBALS['content']['articles'] as $key => $value) {
2399              if($key == $a_id && $c) {
2400                  $link  = '<a href="index.php?aid='.$prev_art_id.'">';
2401                  break;
2402              }
2403              $c++;
2404              $prev_cat_id = $GLOBALS['content']['articles'][$key]['article_cid'];
2405              $prev_art_id = $key;
2406          }
2407      }
2408      if($cat_up && $a_id && $c && !$link) {
2409          $link = '<a href="index.php?id='.$GLOBALS['content']['cat_id'].',0,0,1,0,0">';
2410      }
2411  
2412      if($cat_up && !$link) {
2413          // go cat down or to next cat above
2414          $temp_key = array();
2415          foreach($GLOBALS['content']['struct'] as $key => $value) {
2416              if($GLOBALS['content']['struct'][$key]['acat_struct'] == $GLOBALS['content']['struct'][ $GLOBALS['content']['cat_id'] ]['acat_struct']) {
2417                  $temp_key[] = $key;
2418              }
2419          }
2420          if(count($temp_key) && $GLOBALS['content']['cat_id']) {
2421              $c = 0;
2422              foreach($temp_key as $value) {
2423                  if($value == $GLOBALS['content']['cat_id']) {
2424                      $prev_cat_id = (!$c) ? $GLOBALS['content']['struct'][$value]['acat_struct'] : $temp_key[$c-1];
2425                      $link = '<a href="index.php?id='.$prev_cat_id.',0,0,1,0,0">';
2426                      break;
2427                  }
2428                  $c++;
2429              }
2430          }
2431      }
2432  
2433      return ($link) ? $link.$linktext.'</a>' : $linktext;
2434  }
2435  
2436  function include_int_php($string) {
2437      // return the PHP var value
2438      $s = html_despecialchars($string[1]);
2439      if((strpos($s,'$GLOBALS') || strpos($s,'$_'))===false) {
2440          $s = preg_replace('/^\$(.*?)\[(.*?)/si', '$GLOBALS["$1"][$2', $s);
2441          if(substr($s,strlen($s)-1) != ']') {
2442              $s = str_replace('$', '', $s);
2443              $s = '$GLOBALS["'.$s.'"]';
2444          }
2445      }
2446      $s = str_replace('$phpwcms', '$notavailable', $s);
2447      $s = str_replace('["phpwcms"]', '["notavailable"]', $s);
2448      $s = str_replace("['phpwcms']", '["notavailable"]', $s);
2449      ob_start();
2450      eval('echo '.$s.';');
2451      return ob_get_clean();
2452  }
2453  
2454  function include_int_phpcode($string) {
2455      // return the PHP code
2456      $s = html_despecialchars($string[1]);
2457      $s = str_replace('<br>', "\n", $s);
2458      $s = str_replace('<br />', "\n", $s);
2459      ob_start();
2460      eval($s.";");
2461      return ob_get_clean();
2462  }
2463  
2464  function build_sitemap($start=0, $counter=0) {
2465      // create sitemap
2466  
2467      $s = '';
2468      $c = '';
2469      $counter++;
2470  
2471  
2472      if($GLOBALS['sitemap']['classcount']) {
2473          if($GLOBALS['sitemap']['catclass']) $c = ' class="'.$GLOBALS['sitemap']['catclass'].$counter.'"';
2474      } else {
2475          if($GLOBALS['sitemap']['catclass']) $c = ' class="'.$GLOBALS['sitemap']['catclass'].'"';
2476      }
2477  
2478      foreach($GLOBALS['content']['struct'] as $key => $value) {
2479  
2480          //if ($key && $GLOBALS['content']['struct'][$key]['acat_nositemap'] && $start == $GLOBALS['content']['struct'][$key]['acat_struct'])
2481          if( $GLOBALS['content']['struct'][$key]['acat_nositemap'] && _getStructureLevelDisplayStatus($key, $start) ) {
2482  
2483              $s .= '<li'.$GLOBALS['sitemap']['cat_style'].'>';    //$c.
2484  
2485              if(!$GLOBALS['content']['struct'][$key]["acat_redirect"]) {
2486                  $s .= '<a href="index.php?';
2487                  if($GLOBALS['content']['struct'][$key]['acat_alias']) {
2488                      $s .= $GLOBALS['content']['struct'][$key]['acat_alias'];
2489                  } else {
2490                      $s .= 'id='.$key;
2491                  }
2492                  $s .= '"';
2493              } else {
2494                  $redirect = get_redirect_link($GLOBALS['content']['struct'][$key]["acat_redirect"], ' ', '');
2495                  $s .= '<a href="'.$redirect['link'].'"'.$redirect['target'];
2496              }
2497  
2498              $s .= '>';
2499              $s .= html_specialchars($GLOBALS['content']['struct'][$key]['acat_name']);
2500              $s .= '</a>';
2501              if($GLOBALS['sitemap']["display"]) $s .= build_sitemap_articlelist($key, $counter);
2502  
2503              $s .= build_sitemap($key, $counter);
2504  
2505              $s .= "</li>\n";
2506          }
2507      }
2508  
2509  
2510      if($s) $s = "\n<ul".$c.">\n".$s.'</ul>';
2511  
2512      return $s;
2513  }
2514  
2515  function build_sitemap_articlelist($cat, $counter=0) {
2516      // create list of articles for given category
2517  
2518      $ao = get_order_sort($GLOBALS['content']['struct'][ $cat ]['acat_order']);
2519  
2520      $sql  = "SELECT article_id, article_title FROM ".DB_PREPEND."phpwcms_article ";
2521      $sql .= "WHERE article_cid=".intval($cat)." AND article_nositemap=1 AND ";
2522      // VISIBLE_MODE: 0 = frontend (all) mode, 1 = article user mode, 2 = admin user mode
2523      switch(VISIBLE_MODE) {
2524          case 0: $sql .=    "article_public=1 AND article_aktiv=1 AND ";
2525                  break;
2526          case 1: $sql .= "article_uid=".$_SESSION["wcs_user_id"]." AND ";
2527                  break;
2528          //case 2: admin mode no additional neccessary
2529      }
2530      $sql .= "article_deleted=0 AND article_begin<NOW() AND article_end>NOW() ";
2531      $sql .= "ORDER BY ".$ao[2];
2532  
2533      $s = '';
2534      $c = '';
2535      if($GLOBALS['sitemap']['classcount']) {
2536          if($GLOBALS['sitemap']['articleclass']) $c = ' class="'.$GLOBALS['sitemap']['articleclass'].$counter.'"';
2537      } else {
2538          if($GLOBALS['sitemap']['articleclass']) $c = ' class="'.$GLOBALS['sitemap']['articleclass'].'"';
2539      }
2540  
2541      if($result = mysql_query($sql, $GLOBALS['db'])) {
2542          while($row = mysql_fetch_row($result)) {
2543  
2544              $s .= '<li'.$GLOBALS['sitemap']['article_style'].'>';    //.$c
2545              $s .= '<a href="index.php?aid='.$row[0].'">';
2546              $s .= html_specialchars($row[1]);
2547              $s .= "</a></li>\n";
2548  
2549          }
2550          mysql_free_result($result);
2551      }
2552  
2553      if($s) $s = "\n<ul".$c.">\n".$s.'</ul>';
2554  
2555      return $s;
2556  
2557  }
2558  
2559  function render_cnt_template($text='', $tag='', $value='') {
2560      // render content part by replacing placeholder tags by value
2561      $value = strval($value);
2562      if($value) {
2563          $text = preg_replace('/\['.$tag.'\](.*?)\[\/'.$tag.'\]/is', '$1', $text);
2564          $text = preg_replace('/\['.$tag.'_ELSE\](.*?)\[\/'.$tag.'_ELSE\]/is', '', $text);
2565      } else {
2566          $text = preg_replace('/\['.$tag.'_ELSE\](.*?)\[\/'.$tag.'_ELSE\]/is', '$1', $text);
2567          $text = preg_replace('/\['.$tag.'\](.*?)\[\/'.$tag.'\]/is', '', $text);
2568      }
2569      return str_replace('{'.$tag.'}', $value, $text);
2570  }
2571  
2572  function replace_cnt_template($text='', $tag='', $value='') {
2573      // replace tag by value
2574      return preg_replace('/\['.$tag.'\].*?\[\/'.$tag.'\]/is', strval($value), $text);
2575  }
2576  
2577  function parse_cnt_urlencode($value) {
2578      // replace tag by value
2579      return preg_replace_callback('/\[URLENCODE\](.*?)\[\/URLENCODE\]/s', 'render_urlencode', $value);
2580  }
2581  
2582  function render_urlencode($match) {
2583      if(is_array($match) && isset($match[1])) {
2584          $match = $match[1]; 
2585      }
2586      return rawurlencode(decode_entities($match));
2587  }
2588  
2589  function render_cnt_date($text='', $date, $livedate=NULL, $killdate=NULL) {
2590      // render date by replacing placeholder tags by value
2591      $date = is_numeric($date) ? intval($date) : now();
2592      $text = preg_replace('/\{DATE:(.*?) lang=(..)\}/e', 'international_date_format("$2","$1","'.$date.'")', $text);
2593      $text = preg_replace('/\{DATE:(.*?)\}/e', 'date("$1",'.$date.')', $text);
2594      if(intval($livedate)) {
2595          $text = preg_replace('/\{LIVEDATE:(.*?) lang=(..)\}/e', 'international_date_format("$2","$1","'.$livedate.'")', $text);
2596          $text = preg_replace('/\{LIVEDATE:(.*?)\}/e', 'date("$1",'.$livedate.')', $text);
2597      }
2598      if(intval($killdate)) {
2599          $text = preg_replace('/\{KILLDATE:(.*?) lang=(..)\}/e', 'international_date_format("$2","$1","'.$killdate.'")', $text);
2600          $text = preg_replace('/\{KILLDATE:(.*?)\}/e', 'date("$1",'.$killdate.')', $text);
2601      }
2602      return preg_replace('/\{NOW:(.*?) lang=(..)\}/e', 'international_date_format("$2","$1","'.now().'")', $text);
2603  }
2604  
2605  function render_date($text='', $date, $rt='DATE') {
2606      // render date by replacing placeholder tags by value
2607      $rt = preg_quote($rt);
2608      $text = preg_replace('/\{'.$rt.':(.*?) lang=(..)\}/e', 'international_date_format("$2","$1","'.$date.'")', $text);
2609      return preg_replace('/\{'.$rt.':(.*?)\}/e', 'date("$1",'.$date.')', $text);
2610  }
2611  
2612  function returnTagContent($string='', $tag='', $findall=false, $tagOpen='[', $tagClose=']') {
2613      // used to exclude a special string sequence from string
2614      // enclosed by [tag][/tag] or also <tag></tag>
2615      $data                 = array();
2616      $data['original']    = $string;
2617      $tag_open            = preg_quote($tagOpen.$tag.$tagClose, '/');
2618      $tag_close            = preg_quote($tagOpen.'/'.$tag.$tagClose, '/');
2619      $data['new']        = trim(preg_replace('/'.$tag_open.'(.*?)'.$tag_close.'/is', '', $string));
2620      if($findall) {
2621          preg_match_all('/'.$tag_open.'(.*?)'.$tag_close.'/is', $string, $matches);
2622      } else {
2623          preg_match('/'.$tag_open.'(.*?)'.$tag_close.'/is', $string, $matches);
2624      }
2625      $data['tag']        = isset($matches[1]) ? $matches[1] : '';
2626      return $data;
2627  }
2628  
2629  function include_url($url) {
2630      // include given URL but only take content between <body></body>
2631  
2632      global $include_urlparts;
2633      
2634      if( is_string($url) ) {
2635          $url = array( 1 => $url );
2636      } elseif( ! isset($url[1]) ) {
2637          return '';
2638      }
2639      
2640      $k                = '';
2641      $url            = trim($url[1]);
2642      $url            = explode(' ', $url);
2643      $cache            = isset($url[1]) ? intval(str_replace('CACHE=', '', strtoupper($url[1]))) : 0;
2644      $url            = $url[0];
2645      $cache_status    = 'MISSING';
2646      
2647      if($url && $cache) {
2648      
2649          $cache_filename    = md5($url).'-url';    // set cache file name
2650          $cache_file        = PHPWCMS_CONTENT.'tmp/'.$cache_filename;    // set caching file
2651          $cache_status    = check_cache($cache_file, $cache);    // ceck existence
2652          
2653          if($cache_status == 'VALID') {    // read cache
2654              
2655              $k    = read_textfile($cache_file);
2656              $k    = trim($k);
2657          
2658              if(empty($k)) {
2659                  $cache_status == 'EXPIRED';    // check if cache content is available
2660              }
2661          
2662          }
2663  
2664      }
2665      
2666      if($cache_status != 'VALID' && $url) {    // cache file is missing or outdated
2667  
2668          $include_urlparts = parse_url($url);
2669          if(!empty($include_urlparts['path'])) {
2670              $include_urlparts['path'] = dirname($include_urlparts['path']);
2671              $include_urlparts['path'] = str_replace('\\', '/', $include_urlparts['path']);
2672          }
2673          $k = @file_get_contents($url);
2674  
2675          if($k) {
2676              // now check against charset
2677              if(preg_match('/charset=(.*?)"/i', $k, $match)) {
2678                  $charset = $match[1];
2679                  $charset = str_replace(array('"', "'", '/'), '', $charset);
2680                  $charset = strtolower(trim($charset));
2681              } elseif(preg_match('/http-equiv="{0,1}Content-Type"{0,1}\s{1,}(content="{0,1}.*?"{0,1}.{0,3}>)/i', $k, $match)) {
2682                  $charset = '';
2683                  if(!empty($match[1])) {
2684                      $charset = strtolower($match[1]);
2685                      $charset = trim(str_replace(array('"', "'", '/', 'content=', ' ', '>'), '', $charset));
2686                  }
2687              } else {
2688                  $charset = false;
2689              }
2690  
2691              if(preg_match('/<body[^>]*?'.'>(.*)<\/body>/is', $k, $match)) {
2692                  $k = $match[1];
2693              }
2694              $k = str_replace(array('<?', '?>', '<%', '%>'), array('&lt;?', '?&gt;', '&lt;&#37;', '&#37;&gt;'), $k);
2695              $k = preg_replace_callback('/(href|src|action)=[\'|"]{0,1}(.*?)[\'|"]{0,1}( .*?){0,1}>/i', 'make_absoluteURL', $k);
2696              $k = htmlfilter_sanitize( trim($k) , array(false, 'link', 'meta'), array(), array('img', 'br', 'hr', 'input'), true);
2697  
2698              if($charset != false) {
2699                  $k = makeCharsetConversion($k, $charset, PHPWCMS_CHARSET, 1);
2700              }
2701              
2702              // now write or update cache file in case there is timeout or content
2703              if($cache && $k) {
2704                  @write_textfile($cache_file, $k);
2705              }
2706  
2707          }
2708          $include_urlparts = '';
2709  
2710      }
2711      return $k;
2712  }
2713  
2714  function make_absoluteURL($matches) {
2715      // replaces all relative URLs in href=/src= to absolute paths based on called URI
2716      $parts = $GLOBALS['include_urlparts'];
2717      $path  = $matches[2];
2718      $k = '';
2719      if(preg_match('/^(http|mailto|ftp|https|skype|itms)/i', $path)) {
2720          $k = $path;
2721      } else {
2722          if(empty($parts['path'])) $parts['path'] = '';
2723          $k = $parts['host'].$parts['path'].'/'.$path;
2724          $k = str_replace('///', '/', $k);
2725          $k = str_replace('//', '/', $k);
2726          $k = $parts['scheme'].'://'.$k;
2727      }
2728      if(empty($matches[3])) $matches[3] = '';
2729      return $matches[1].'="'.$k.'"'.$matches[3].'>';
2730  
2731  }
2732  
2733  function render_PHPcode($string='') {
2734      // combined PHP replace renderer
2735      // includes external PHP script and returns the content
2736      $string = preg_replace('/\{PHP:(.*?)\}/e', 'include_ext_php("$1");', $string);
2737      // do complete PHP code
2738      $string = preg_replace_callback("/\[PHP\](.*?)\[\/PHP\]/s", 'include_int_phpcode', $string);
2739      // includes external PHP script and returns the content
2740      $string = preg_replace_callback("/\{PHPVAR:(.*?)\}/s", 'include_int_php', $string);
2741      return $string;
2742  }
2743  
2744  function nav_list_struct (&$struct, $act_cat_id, $level, $class='') {
2745      // start with home directory for the listing = top nav structure
2746      // 1. Build the recursive tree for given actual article category ID
2747  
2748      // return the tree starting with given start_id (like breadcrumb)
2749      // if the $start_id = 0 then this stops because 0 = top level
2750  
2751      $level        = intval($level);
2752      $data        = array();
2753      $start_id     = $act_cat_id;
2754      $class         = trim($class);
2755      $depth        = 0;
2756  
2757      while ($start_id) {
2758          $data[$start_id] = 1;
2759          $start_id         = $struct[$start_id]["acat_struct"];
2760      }
2761      $temp_tree = sizeof($data) ? array_reverse($data, 1) : false;
2762  
2763      $temp_menu = build_list ($struct, $level, $temp_tree, $act_cat_id, $class, $depth);
2764      $temp_menu = str_replace("\n\n", LF, $temp_menu);
2765      return $temp_menu ? $temp_menu : '';
2766  }
2767  
2768  function build_list ($struct, $level, $temp_tree, $act_cat_id, $class='', $depth=0) {
2769      // this returns the level structure based on given arrays
2770      // it is special for browsing from root levels
2771  
2772      if($class != '') {
2773          $curClass = ' class="'.$class.$depth.'"';
2774          $curClassNext = ' class="'.$class.($depth+1).'"';
2775          $curClassActive = ' class="'.$class.'Active'.$depth.'"';
2776      } else {
2777          $curClass = '';
2778          $curClassNext = '';
2779          $curClassActive = ' class="listActive"';
2780      }
2781  
2782      $depth++;
2783  
2784      $temp_menu = "\n<ul".$curClass.">\n";
2785      foreach($struct as $key => $value) {
2786  
2787          if( _getStructureLevelDisplayStatus($key, $level) ) {
2788  
2789              if(!$struct[$key]["acat_redirect"]) {
2790                  $link = 'index.php?';
2791                  if($struct[$key]["acat_alias"]) {
2792                      $link .= html_specialchars($struct[$key]["acat_alias"]);
2793                  } else {
2794                      $link .= 'id='.$key; //',0,0,1,0,0';
2795                  }
2796                  $redirect['target'] = '';
2797              } else {
2798                  $redirect = get_redirect_link($struct[$key]["acat_redirect"], ' ', '');
2799                  $link = $redirect['link'];
2800              }
2801  
2802              if(!empty($temp_tree[$key])) {
2803  
2804                  if($act_cat_id == $key) {
2805                      $temp_menu .= "\n<li".$curClassActive.">";
2806                  } else {
2807                      $temp_menu .= "\n<li>";
2808                  }
2809  
2810                  $temp_menu .= '<a href="'.$link.'">'.html_specialchars($struct[$key]["acat_name"]).'</a>';
2811  
2812                  $temp_menu .= build_list ($struct, $key, $temp_tree, $act_cat_id, $class, $depth);
2813                  $temp_menu .= '</li>';
2814  
2815              } else {
2816                  $temp_menu .= "\n<li>".'<a href="'.$link.'"'.$redirect['target'].'>';
2817                  $temp_menu .= html_specialchars($struct[$key]["acat_name"])."</a></li>\n";
2818              }
2819          }
2820      }
2821  
2822      $temp_menu = trim($temp_menu);
2823      return $temp_menu != "<ul".$curClassNext.">" ? $temp_menu."\n</ul>" : '';
2824  }
2825  
2826  function combined_POST_cleaning($val) {
2827      $val = clean_slweg($val);
2828      $val = remove_unsecure_rptags($val);
2829      return $val;
2830  }
2831  
2832  function get_fe_userinfo($forum_userID) {
2833      // get frontend userinformation
2834      $forum_userID = intval($forum_userID);
2835      $got_the_info = false;
2836      if($forum_userID != 0 && (!isset($GLOBALS['FE_USER']) || !isset($GLOBALS['FE_USER'][$forum_userID]))) {
2837          //connect to user db and get information
2838          $sql = "SELECT * FROM ".DB_PREPEND."phpwcms_user WHERE usr_id=".$forum_userID." LIMIT 1";
2839          if($result = mysql_query($sql, $GLOBALS['db'])) {
2840              if($row = mysql_fetch_assoc($result)) {
2841                  $GLOBALS['FE_USER'][$forum_userID] = array(
2842                      'FE_ID'        => $forum_userID,        'login'    => $row['usr_login'],
2843                      'pass'        => $row['usr_pass'],    'email'    => $row['usr_email'],
2844                      'admin'        => $row['usr_admin'],    'fe'    => $row['usr_fe'],
2845                      'aktiv'        => $row['usr_aktiv'],    'name'    => $row['usr_name'],
2846                      'lang'        => empty($row['usr_lang']) ? $GLOBALS['phpwcms']['default_lang'] : $row['usr_lang'],
2847                      'wysiwyg'    => $row['usr_wysiwyg']
2848                  );
2849                  $got_the_info = true;
2850              }
2851              mysql_free_result($result);
2852          }
2853      } else {
2854          $got_the_info = true;
2855      }
2856      if(($forum_userID === 0 && !isset($GLOBALS['FE_USER'][$forum_userID])) || !$got_the_info) {
2857          $forum_userID = 0;
2858          $GLOBALS['FE_USER'][$forum_userID] = array(
2859                      'FE_ID'        => $forum_userID,        'login'    => 'guest',
2860                      'pass'        => '',                    'email'    => 'noreply@localhost',
2861                      'admin'        => 0,                    'fe'    => 0,
2862                      'aktiv'        => 1,                    'name'    => 'Guest',
2863                      'lang'        => $GLOBALS['phpwcms']['default_lang'],
2864                      'wysiwyg'    => $GLOBALS['phpwcms']['wysiwyg_editor']
2865                  );
2866      }
2867  }
2868  
2869  function highlightSearchResult($string='', $search, $wrap='<em class="highlight">|</em>') {
2870      // string will be highlighted by $search - can be string or array
2871      if(!empty($string) && !empty($search)) {
2872  
2873          // make $wrap[0] prefix and $wrap[1] suffix
2874          $wrap = explode('|', $wrap);
2875          if(empty($wrap[1])) $wrap[1] = '';
2876          $highlight_match = '';
2877  
2878          // make all search values array fields
2879          if(is_array($search)) {
2880              // make unique
2881              $search = array_unique($search);
2882          } else {
2883              $search = array(strval($search));
2884          }
2885          foreach($search as $key => $value) {
2886              if($highlight_match != '') $highlight_match .= '|';
2887              $highlight_match .= preg_quote($value, '/');
2888          }
2889          $highlight_match = str_replace("\\?", '.?', $highlight_match);
2890          $highlight_match = str_replace("\\*", '.*', $highlight_match);
2891          $highlight_match = trim($highlight_match);
2892  
2893          if(false == preg_match('/<.+>/', $string)) {
2894              $string = preg_replace('/('.$highlight_match.')/i', $wrap[0].'$1'.$wrap[1], $string);
2895          } else {
2896              $string = preg_replace('/(?<=>)([^<]+)?('.$highlight_match.')/i', '$1'.$wrap[0].'$2'.$wrap[1], $string);
2897          }
2898      }
2899      return $string;
2900  }
2901  function pregReplaceHighlightWrapper($matches) {
2902      // just a wrapper for frontend sectional highlighting
2903      global $highlight_words;
2904      return highlightSearchResult($matches[1], $highlight_words, '<em class="highlight">|</em>');
2905  }
2906  
2907  function buildCascadingMenu($parameter='', $counter=0, $param='string') {
2908  
2909      // @string $parameter = "menu_type, start_id, max_level_depth, class_path, class_active_li|class_active_a,
2910      // ul_id_name, wrap_ul_div(0 = off, 1 = <div>, 2 = <div id="">, 3 = <div class="navLevel-0">),
2911      // wrap_link_text(<em>|</em>, articlemenu_start_level)"
2912  
2913      if($param == 'string') {
2914  
2915          $parameter         = explode(',', $parameter);
2916          $menu_type        = empty($parameter[0]) ? '' : strtoupper(trim($parameter[0]));
2917  
2918          $unfold         = 'all';
2919          $ie_patch        = false; // unused at the moment
2920          $create_css     = false;
2921          $parent            = false; // do not show parent link
2922          $articlemenu    = false; // do not show category's article titles as menu entry
2923  
2924          switch($menu_type) {
2925              
2926              case 'A':        $articlemenu    = true;
2927                              break;
2928  
2929                              // show parent level too
2930              case 'PA':        $articlemenu    = true;
2931              case 'P':        $parent            = true;
2932                              break;
2933  
2934                              // vertical, active path unfolded
2935              case 'FPA':        $articlemenu    = true;
2936              case 'FP':        $parent            = true;
2937              case 'F':        $unfold            = 'active_path';
2938                              break;
2939                              
2940              case 'FA':        $articlemenu    = true;
2941                              $unfold            = 'active_path';
2942                              break;
2943                              
2944                              // horizontal, all levels unfolded, add special code for horizontal flyout menu
2945              case 'HCSSP':    $parent        = true;
2946              case 'HCSS':    $create_css    = true;
2947                              break;
2948  
2949                              // horizontal, all levels unfolded, add special code for vertical flyout menu
2950              case 'VCSSP':    $parent        = true;
2951              case 'VCSS':    $create_css = true;
2952                              break;
2953  
2954          }
2955  
2956          $start_id        = empty($parameter[1]) ? 0  : intval($parameter[1]);
2957          $max_depth        = empty($parameter[2]) ? 0  : intval($parameter[2]);
2958          $path_class     = empty($parameter[3]) ? '' : trim($parameter[3]);
2959          $active_class    = empty($parameter[4]) ? '' : trim($parameter[4]);
2960          $level_id_name    = empty($parameter[5]) ? '' : trim($parameter[5]);
2961          $wrap_ul_div    = empty($parameter[6]) ? 0  : intval($parameter[6]);
2962          if($active_class) {
2963              $active_class        = explode('|', $active_class, 2);
2964              $active_class[0]    = trim($active_class[0]);
2965              $active_class[1]    = empty($active_class[1]) ? '' : trim($active_class[1]);
2966          } else {
2967              $active_class        = array(0 => '', 1 => '');
2968          }
2969          if($wrap_ul_div > 3) {
2970              $wrap_ul_div = 2;
2971          } elseif($wrap_ul_div < 0) {
2972              $wrap_ul_div = 0;
2973          }
2974          $wrap_link_text    = empty($parameter[7]) ? array(0 => '', 1 => '') : explode('|', trim($parameter[7]), 2);
2975          if(empty($wrap_link_text[1])) {
2976              $wrap_link_text[1] = '';
2977          }
2978          $amenu_level    = empty($parameter[8]) ? 0 : intval($parameter[8]);
2979  
2980          $parameter        = array(     0 => $menu_type,          1 => $start_id,          2 => $max_depth,
2981                                       3 => $path_class,         4 => $active_class,      5 => $level_id_name,
2982                                       6 => $wrap_ul_div,         7 => $wrap_link_text,     8 => $unfold,
2983                                       9 => $ie_patch,        10 => $create_css,        11 => $amenu_level,
2984                                      12 => array('articlemenu' => $articlemenu, 'level_id' => $start_id)
2985                              );
2986          
2987          if($articlemenu) {
2988              $parameter[12]['class_active']            = $active_class;
2989              $parameter[12]['wrap_title_prefix']        = $wrap_link_text[0];
2990              $parameter[12]['wrap_title_suffix']        = $wrap_link_text[1];
2991              $parameter[12]['item_prefix']            = "\t";
2992              $parameter[12]['item_suffix']            = '';
2993              $parameter[12]['sort']                    = 'level';
2994              $parameter[12]['item_tag']                = 'li';
2995              $parameter[12]['wrap_tag']                = '';
2996              $parameter[12]['attribute_wrap_tag']    = '';
2997              $parameter[12]['class_item_tag']        = 'asub_no';
2998              $parameter[12]['class_first_item_tag']    = 'asub_first';
2999              $parameter[12]['class_last_item_tag']    = 'asub_last';
3000              $parameter[12]['return_format']            = 'array';
3001          }
3002      
3003      } else {
3004  
3005          $menu_type        = $parameter[0];
3006          $start_id        = $parameter[1];
3007          $max_depth        = $parameter[2];
3008          $path_class     = $parameter[3];
3009          $active_class    = $parameter[4];
3010          $level_id_name    = $parameter[5];
3011          $wrap_ul_div    = $parameter[6];
3012          $wrap_link_text    = $parameter[7];
3013          $unfold            = $parameter[8];
3014          $ie_patch        = $parameter[9];
3015          $create_css     = $parameter[10];
3016          $amenu_level    = $parameter[11];
3017          
3018          $parent            = false;        // do not show parent link
3019  
3020      }
3021  
3022      $li                = '';
3023      $ali            = '';
3024      $ul                = '';
3025      $TAB            = str_repeat('    ', $counter);
3026      $_menu_type        = strtolower($menu_type);
3027      $max_depth        = ($max_depth == 0 || $max_depth-1 > $counter) ? true : false;
3028      $x                = 0;
3029  
3030      foreach($GLOBALS['content']['struct'] as $key => $value) {
3031  
3032          if( _getStructureLevelDisplayStatus($key, $start_id) ) {
3033  
3034              $li_ul         = '';
3035              $li_ie        = '';
3036              $li_a_title    = html_specialchars($GLOBALS['content']['struct'][$key]['acat_name']);
3037              $li_a_class    = ($active_class[1] && $key == $GLOBALS['aktion'][0]) ? ' class="'.$active_class[1].'"' : ''; // set active link class
3038              
3039              $li_a  = get_level_ahref($key, $li_a_class.' title="'.$li_a_title.'"');
3040              $li_a .= $wrap_link_text[0] . $li_a_title . $wrap_link_text[1];
3041  
3042              if($max_depth && ($unfold == 'all' || ($unfold == 'active_path' && isset($GLOBALS['LEVEL_KEY'][$key]))) ) {
3043                  $parameter[1]    = $key;
3044                  $li_ul            = buildCascadingMenu($parameter, $counter+1, 'param_is_array');
3045              }
3046  
3047              $li .= $TAB.'    <li';
3048  
3049              if($level_id_name) {
3050                  $li .= ' id="li_'.$level_id_name.'_'.$key.'"';
3051              }
3052              $li_class = ($li_ul) ? 'sub_ul' : (getHasSubStructureStatus($key) ? 'sub_no sub_ul_true' : 'sub_no');
3053              if($path_class != '' && isset($GLOBALS['LEVEL_KEY'][$key])) {
3054                  $li_class = trim($li_class.' '.$path_class);
3055              }
3056              if($active_class[0] != '' && $key == $GLOBALS['aktion'][0]) {
3057                  $li_class = trim($li_class.' '.$active_class[0]);
3058              }
3059              if($x==0) {
3060                  $li_class .= ' sub_first';
3061              }
3062  
3063              $li .= ' class="' . trim($li_class . ' ' . $GLOBALS['content']['struct'][$key]['acat_class']) .'"';
3064  
3065              $li .= '>' . $li_a . '</a>';
3066  
3067              $li .= $li_ul.'</li>'.LF; // remove $li_ul from this line of code if $ie_patch is used
3068              
3069              $x++;
3070          }
3071      }
3072      
3073      // show article menu
3074      if($parameter[12]['articlemenu'] && $amenu_level <= $counter) {
3075          
3076          $parameter[12]['level_id']        = $start_id;
3077          $parameter[12]['item_prefix']    = $TAB.$TAB.$TAB;
3078  
3079          $ali = getArticleMenu( $parameter[12] );
3080          
3081          if(count($ali) > 1) {
3082          
3083              $li .= implode(LF, $ali) . LF;
3084              $ali = $TAB;
3085              
3086          } else {
3087          
3088              $ali = '';
3089              
3090          }
3091          
3092      }    
3093      
3094      // also check if $parent
3095      if($li || ($parent && isset($GLOBALS['content']['struct'][$start_id]))) {
3096  
3097          switch($wrap_ul_div) {
3098              case 1:        $ul = LF.$TAB.'<div>';
3099                          $close_wrap_ul = '</div>'.LF.$TAB;
3100                          break;
3101              case 2:        $ul = LF.$TAB.'<div id="ul_div_'.$start_id.'">';
3102                          $close_wrap_ul = '</div>'.LF.$TAB;
3103                          break;
3104              case 3:        $ul = LF.$TAB.'<div class="navLevel-'.$counter.'">';
3105                          $close_wrap_ul = '</div>'.LF.$TAB;
3106                          break;
3107              default:    $ul = '';
3108                          $close_wrap_ul = '';
3109          }
3110          $ul .= LF . $TAB . $ali . '<ul';
3111          if($level_id_name) {
3112              $ul .= ' id="'.$level_id_name.'_'.$start_id.'"';
3113          }
3114          if(isset($GLOBALS['LEVEL_KEY'][$start_id]) && $path_class) {
3115              $ul .= ' class="'.$path_class.'"';
3116          }
3117          $ul .= '>'.LF;
3118          
3119          if($parent && isset($GLOBALS['content']['struct'][$start_id])) {
3120          
3121              $ul .= LF;
3122              $ul .= $TAB.'    <li';
3123              if($level_id_name) {
3124                  $ul .= ' id="li_'.$level_id_name.'_'.$start_id.'"';
3125              }
3126              $li_class = 'sub_parent';
3127              if($active_class[0] != '' && $start_id == $GLOBALS['aktion'][0]) {
3128                  $li_class = trim($li_class.' '.$active_class[0]);
3129              }
3130              $ul .= ' class="'.trim($li_class.' '.$GLOBALS['content']['struct'][$start_id]['acat_class']).'">';
3131              
3132              $link_text    = html_specialchars($GLOBALS['content']['struct'][$start_id]['acat_name']);
3133              $link_class    = ($active_class[1] && $start_id == $GLOBALS['aktion'][0]) ? ' class="'.$active_class[1].'"' : ''; // set active link class
3134              
3135              $ul .= get_level_ahref($start_id, $link_class.' title="'.$link_text.'"');
3136              $ul .= $wrap_link_text[0] . $link_text . $wrap_link_text[1];
3137              $ul .= '</a></li>'.LF;
3138                      
3139          }
3140          
3141          $ul .= $li;
3142          $ul .= $TAB . $ali . '</ul>' . LF . $TAB . $close_wrap_ul;
3143  
3144          if($create_css && empty($GLOBALS['block']['custom_htmlhead'][$menu_type][$counter])) {
3145  
3146              if($counter) {
3147  
3148                  $tmp_css  = '    .'.$_menu_type.'_menu ul li:hover '.str_repeat('ul ', $counter) .'ul { display: none; }'.LF;
3149                  $tmp_css .= '    .'.$_menu_type.'_menu ul '.str_repeat('ul ', $counter) .'li:hover ul { display: block; }';
3150                  $GLOBALS['block']['custom_htmlhead'][$menu_type][$counter] = $tmp_css;
3151  
3152              } else {  //if($counter == 0) {
3153  
3154                  $GLOBALS['block']['custom_htmlhead'][$menu_type][-9]  = LF.'  <style type="text/css">'.LF.SCRIPT_CDATA_START;
3155                  $GLOBALS['block']['custom_htmlhead'][$menu_type][-8]  = '    @import url("'.TEMPLATE_PATH.'inc_css/specific/nav_list_ul_'.$_menu_type.'.css");';
3156  
3157                  $GLOBALS['block']['custom_htmlhead'][$menu_type][-5]  = '    .'.$_menu_type.'_menu ul ul { display: none; }';
3158                  $GLOBALS['block']['custom_htmlhead'][$menu_type][-4]  = '    .'.$_menu_type.'_menu ul li:hover ul { display: block; }';
3159  
3160                  ksort($GLOBALS['block']['custom_htmlhead'][$menu_type]);
3161                  $GLOBALS['block']['custom_htmlhead'][$menu_type][]   = SCRIPT_CDATA_END.LF.'  </style>';
3162                  $GLOBALS['block']['custom_htmlhead'][$menu_type]   = implode(LF, $GLOBALS['block']['custom_htmlhead'][$menu_type]);
3163  
3164                  $ul = '<div class="'.$_menu_type.'_menu">'.$ul.'</div>';
3165  
3166              }
3167  
3168          }
3169  
3170      }
3171  
3172      return $ul;
3173  }
3174  
3175  function get_level_ahref($key=0, $custom_link_add='') {
3176      $link = '<a href="';
3177      if(!$GLOBALS['content']['struct'][$key]["acat_redirect"]) {
3178          $link .= 'index.php?';
3179          if($GLOBALS['content']['struct'][$key]['acat_alias']) {
3180              $link .= $GLOBALS['content']['struct'][$key]['acat_alias'];
3181          } else {
3182              $link .= 'id='.$key.',0,0,1,0,0';
3183          }
3184          $link .= '"';
3185      } else {
3186          $redirect = get_redirect_link($GLOBALS['content']['struct'][$key]["acat_redirect"], ' ', '');
3187          $link .= html_specialchars($redirect['link']).'"'.$redirect['target'];
3188      }
3189      return $link.$custom_link_add.'>';
3190  }
3191  
3192  function getHasSubStructureStatus($level_id=0) {
3193      if( !isset($GLOBALS['content']['struct'][$level_id]) ) {
3194          return false;
3195      }
3196      foreach($GLOBALS['content']['struct'] as $key => $value) {
3197          if( _getStructureLevelDisplayStatus($key, $level_id) ) {
3198              return true;
3199          }
3200      }
3201      return false;
3202  }
3203  
3204  function getStructureChildData($level_id=0) {
3205      if( !isset($GLOBALS['content']['struct'][$level_id]) ) return array();
3206      $struct_data = array();
3207      foreach($GLOBALS['content']['struct'] as $key => $value) {
3208          if( _getStructureLevelDisplayStatus($key, $level_id) ) {
3209              $struct_data[$key]    = $value;
3210          }
3211      }
3212      return $struct_data;
3213  }
3214  
3215  function getStructureChildEntryHref($childData) {
3216  
3217      $a = array('link'=>'', 'target'=>'');
3218      if(!$childData["acat_redirect"]) {
3219          $a['link'] .= 'index.php?';
3220          $a['link'] .= $childData['acat_alias'] ? $childData['acat_alias'] : 'id='.$childData['acat_id'].',0,0,1,0,0';
3221      } else {
3222          $redirect = get_redirect_link($childData["acat_redirect"], ' ', '');
3223          $a['link']   .= $redirect['link'];
3224          $a['target'] .= $redirect['target'];
3225      }
3226      return $a;
3227  
3228  }
3229  
3230  function getImageCaption($caption='', $array_index='NUM', $short=false) {
3231      // splits given image caption and returns an array
3232      $caption    = explode('|', $caption);
3233  
3234      // following is default for the exploded $caption
3235      // [0] caption text
3236      // [1] alt text for image
3237      // [2] link -> array(0 => link, 1 => target)
3238      // [3] title text -> if empty alt text will be used
3239      // [4] copyright information
3240      $caption[0]            = trim($caption[0]);
3241      $caption[1]            = isset($caption[1]) ? trim($caption[1]) : '';
3242      $caption[3]            = isset($caption[3]) ? trim($caption[3]) : $caption[1];
3243      
3244      // cut here Ð just return caption and alt text
3245      if($short) {
3246          return array('caption' => $caption[0], 'alt' => $caption[1], 'title' => $caption[3]);
3247      }
3248      
3249      $caption[2]            = isset($caption[2]) ? explode(' ', trim($caption[2])) : array(0 => '', 1 => '');
3250      $caption[2][0]        = trim($caption[2][0]);
3251      if(empty($caption[2][0]) || empty($caption[2][1])) {
3252          $caption[2][1]    = '';
3253      } else {
3254          $caption[2][1]    = trim($caption[2][1]);
3255          $caption[2][1]    = empty($caption[2][1]) ? '' : ' target="'.$caption[2][1].'"';
3256      }
3257      $caption[4]            = isset($caption[4]) ? trim($caption[4]) : '';
3258      
3259      if($caption[4] == '') {
3260          $copyright        = returnTagContent($caption[3], 'copyright');
3261          $caption[3]        = $copyright['new'];
3262          $caption[4]        = $copyright['tag'];
3263      } else {
3264          $caption[3]        = replace_cnt_template($caption[3], 'copyright', '');
3265      }
3266      
3267      if($array_index == 'NUM') {
3268          return $caption;
3269      } else {
3270          return array(    'caption_text'        => $caption[0],        'caption_alt'        => $caption[1],
3271                          'caption_link'        => $caption[2][0],    'caption_target'    => $caption[2][1],
3272                          'caption_title'        => $caption[3]        );
3273      }
3274  
3275  }
3276  
3277  function getClickZoomImageParameter($string='', $getvar='show') {
3278      $string = base64_encode($string);
3279      $string = rawurlencode($string);
3280      return $getvar.'='.$string;
3281  }
3282  
3283  function getPageInfoGetValue($type='string') {
3284      // type can be
3285      // 'string' -> 'pageinfo=/...';
3286      // 'array' -> array('pageinfo'=>'/...')
3287      return ($type == 'string') ? 'pageinfo=' : array('pageinfo'=>'');
3288  }
3289  
3290  function _getFeUserLoginStatus() {
3291      $login_key = session_id();
3292      if(empty($login_key)) {
3293          return false;    // user is not logged in
3294      } elseif(empty($_SESSION[$login_key])) {
3295          return false;    // this is the false session and/or false user
3296      } elseif(isset($_GET[$login_key])) {
3297          return false;    // hm, somebody is trying to inject by GET in case register_globals ON
3298      } elseif(isset($_POST[$login_key])) {
3299          return false;    // hm, somebody is trying to inject by POST in case register_globals ON
3300      }
3301      return true;
3302  }
3303  
3304  function _checkFrontendUserLogin($user='', $pass='', $validate_db=array('userdetail'=>1, 'backenduser'=>1)) {
3305      if(empty($user) || empty($pass)) return false;
3306      // check against database
3307      if(!empty($validate_db['userdetail'])) {
3308          $sql  = 'SELECT * FROM '.DB_PREPEND.'phpwcms_userdetail WHERE ';
3309          $sql .= "detail_login='".aporeplace($user)."' AND ";
3310          $sql .= "detail_password='".aporeplace($pass)."' AND ";
3311          $sql .= "detail_aktiv=1 LIMIT 1";
3312          $result = _dbQuery($sql);
3313      }
3314      // hm, seems no user found - OK test against cms users
3315      if(!empty($validate_db['backenduser']) && !isset($result[0])) {
3316          $sql  = 'SELECT * FROM '.DB_PREPEND.'phpwcms_user ';
3317          $sql .= 'LEFT JOIN '.DB_PREPEND.'phpwcms_userdetail ON ';
3318          $sql .= 'usr_id = detail_pid WHERE ';
3319          $sql .= "usr_login='".aporeplace($user)."' AND ";
3320          $sql .= "usr_pass='".aporeplace($pass)."' AND ";
3321          $sql .= "usr_aktiv=1 AND usr_fe IN (0,2) LIMIT 1";
3322          $result = _dbQuery($sql);
3323      }
3324      return (isset($result[0]) && is_array($result)) ? $result[0] : false;
3325  }
3326  
3327  function _getFrontendUserBaseData(& $data) {
3328      // use vaid user data to set some base fe user data
3329      // like name, login, email
3330      $userdata = array('login'=>'', 'name'=>'', 'email'=>'', 'url'=>'', 'source'=>'', 'id'=>0);
3331  
3332      if(isset($data['usr_login'])) {
3333          $userdata['login']    = $data['usr_login'];
3334          $userdata['name']    = $data['usr_name'];
3335          $userdata['email']    = $data['usr_email'];
3336          $userdata['source']    = 'BACKEND';
3337          $userdata['id']        = $data['usr_id'];
3338          if(trim($data['detail_firstname'].$data['detail_lastname'].$data['detail_company'])) {
3339              $t                            = trim($data['detail_firstname'].' '.$data['detail_lastname']);
3340              if(empty($t))    $t            = trim($data['detail_company']);
3341              if($t) $userdata['name']    = $t;
3342              $userdata['url']            = trim($data['detail_website']);
3343          }        
3344      } elseif($data['detail_login']) {
3345          $t                    = trim($data['detail_firstname'].' '.$data['detail_lastname']);
3346          if(empty($t)) $t    = $data['detail_company'];
3347          $userdata['login']    = $data['detail_login'];
3348          $userdata['name']    = $t;
3349          $userdata['email']    = $data['detail_email'];
3350          $userdata['url']    = $data['detail_website'];
3351          $userdata['source']    = 'PROFILE';
3352          $userdata['id']        = $data['detail_id'];
3353      }
3354      return $userdata;
3355  }
3356  
3357  function _checkFrontendUserAutoLogin() {
3358      if(!_getFeUserLoginStatus() && session_id() && !empty($_COOKIE['phpwcmsFeLoginRemember']) && !isset($_POST['phpwcmsFeLoginRemember']) && !isset($_GET['phpwcmsFeLoginRemember'])) {
3359          $_loginData = explode('##-|-##', $_COOKIE['phpwcmsFeLoginRemember']);
3360          if(!empty($_loginData[0]) && !empty($_loginData[1])) {
3361              $_loginData['validate_db']['userdetail']    = empty($_loginData[2]) ? 0 : 1;
3362              $_loginData['validate_db']['backenduser']    = empty($_loginData[3]) ? 0 : 1;
3363              $_loginData['query_result'] = _checkFrontendUserLogin($_loginData[0], $_loginData[1], $_loginData['validate_db']);
3364              if($_loginData['query_result'] !== false && is_array($_loginData['query_result']) && count($_loginData['query_result'])) {
3365                  if(isset($_loginData['query_result']['usr_login'])) {
3366                      $_SESSION[ session_id() ] = $_loginData['query_result']['usr_login'];
3367                  } elseif($_loginData['query_result']['detail_login']) {
3368                      $_SESSION[ session_id() ] = $_loginData['query_result']['detail_login'];
3369                  }
3370                  $_SESSION[ session_id().'_userdata'] = _getFrontendUserBaseData($_loginData['query_result']);
3371              } else {
3372                  unset($_COOKIE['phpwcmsFeLoginRemember']);
3373              }
3374          }
3375      }
3376      // logout
3377      if(session_id() && (isset($_POST['feLogout']) || isset($_GET['feLogout']))) {
3378          unset($_SESSION[ session_id() ]); 
3379          setcookie('phpwcmsFeLoginRemember', '', time()-3600, '/',  getCookieDomain() );
3380      }
3381      define('FEUSER_LOGIN_STATUS', _getFeUserLoginStatus() );
3382  }
3383  
3384  function _getStructureLevelDisplayStatus(&$level_ID, &$current_ID) {
3385      if($GLOBALS['content']['struct'][$level_ID]['acat_struct'] == $current_ID && $level_ID) {
3386          if($GLOBALS['content']['struct'][$level_ID]['acat_regonly'] && !FEUSER_LOGIN_STATUS) {
3387              return false;
3388          }
3389          if(empty($GLOBALS['content']['struct'][$level_ID]['acat_hidden'])) {
3390              return true;
3391          } elseif($GLOBALS['content']['struct'][$level_ID]["acat_hidden"] == 2 && isset($GLOBALS['LEVEL_KEY'][$level_ID])) {
3392              return true;
3393          }
3394          return false;
3395      }
3396      return false;
3397  }
3398  
3399  function setPageTitle($pagetitle, $cattitle, $articletitle, $title_order=NULL) {
3400      // get default pagetitle order value;
3401      if($title_order === NULL) {
3402          $title_order = empty($GLOBALS['pagelayout']['layout_title_order']) ? 0 : intval($GLOBALS['pagelayout']['layout_title_order']);
3403      }    
3404      if(empty($GLOBALS['pagelayout']['layout_title_spacer'])) {
3405          $title_spacer = ' | ';
3406          $GLOBALS['pagelayout']['layout_title_spacer'] = $title_spacer;
3407      } else {
3408          $title_spacer = $GLOBALS['pagelayout']['layout_title_spacer'];
3409      }
3410      switch($title_order) {
3411      
3412          case 1:        $title = array($pagetitle, $articletitle, $cattitle); break;
3413          case 2:        $title = array($cattitle, $articletitle, $pagetitle); break;
3414          case 3:        $title = array($cattitle, $pagetitle, $articletitle); break;
3415          case 4:        $title = array($articletitle, $cattitle, $pagetitle); break;
3416          case 5:        $title = array($articletitle, $pagetitle, $cattitle); break;
3417  
3418          case 6:        $title = array($pagetitle, $cattitle);         break;
3419          case 7:        $title = array($pagetitle, $articletitle);     break;
3420          case 8:        $title = array($cattitle, $articletitle);     break;
3421          case 9:        $title = array($cattitle, $pagetitle);         break;
3422          case 10:    $title = array($articletitle, $cattitle);     break;
3423          case 11:    $title = array($articletitle, $pagetitle);     break;
3424  
3425          case 12:    $title = array($pagetitle);     break;
3426          case 13:    $title = array($cattitle);         break;
3427          case 14:    $title = array($articletitle);     break;
3428          
3429          default:    $title = array($pagetitle, $cattitle, $articletitle);
3430      
3431      }
3432      $title = array_diff($title, array('', NULL, false));
3433      $title = array_unique($title);
3434      $title = trim(implode($title_spacer, $title));
3435      return ($title === '') ? $pagetitle : $title;
3436  }
3437  
3438  function sanitize_replacement_tags( $string, $rt='', $bracket=array('{}', '[]') ) {
3439      if( $string === '' ) return '';
3440      if( is_string($bracket) ) {
3441          $bracket = array($bracket);
3442      }
3443      $tag = array();
3444      if($rt === '') {
3445          $tag[] = array('.*?', '.*?');
3446      } elseif( is_array($rt) ) {
3447          foreach($rt as $value) {
3448              $value = trim($value);
3449              if($value === '') continue;
3450              $tag[] = array($value . '.*?', $value);
3451          }
3452      } elseif( is_string($rt) ) {
3453          $rt = trim($rt);
3454          if($rt) {
3455              $tag[] = array($rt . '.*?', $rt);
3456          }
3457      }
3458      if( is_array($bracket) && count($bracket) && count($tag) ) {
3459          foreach($bracket as $value) {
3460              if(strlen($value) < 2) continue;
3461              $prefix = preg_quote($value{0});
3462              $suffix = preg_quote($value{1});
3463              foreach($tag as $row) {
3464                  $string = preg_replace('/' . $prefix . $row[0] . $suffix . '(.*?)' . $prefix . '\/' . $row[1] . $suffix . '/si', '$1', $string);
3465              }
3466          }
3467      }
3468      return $string;
3469  }
3470  
3471  function parseLightboxCaption($caption='') {
3472      if(empty($caption)) return '';
3473      $caption = html_parser($caption);
3474      return html_specialchars($caption);
3475  }
3476  
3477  function get_article_morelink(& $article) {
3478      if($article['article_redirect'] && strpos($article['article_redirect'], ' ')) {
3479          $link = explode(' ', $article['article_redirect']);
3480          if($link[0]) {
3481              $link[0] = str_replace('{SITE}', PHPWCMS_URL, $link[0]);
3482          }
3483          if(empty($link[1])) $link[1] = '';
3484      } else {
3485          $link[0] = 'index.php?'.setGetArticleAid($article);
3486          $link[1] = '';
3487      }
3488      return $link;
3489  }
3490  
3491  function set_css_link($css='', $add_template_path=true) {
3492      $css_var = basename($css);
3493      $GLOBALS['block']['custom_htmlhead'][$css_var] = '  <link href="';
3494      if($add_template_path) {
3495          $GLOBALS['block']['custom_htmlhead'][$css_var] .= TEMPLATE_PATH;
3496      }
3497      $GLOBALS['block']['custom_htmlhead'][$css_var] .= $css.'" rel="stylesheet" type="text/css" />';
3498  }
3499  
3500  function getFrontendEditLink($type='', $id_1=0, $id_2=0) {
3501  
3502      // check if frontend edit link allowed
3503      if(!FE_EDIT_LINK) return '';
3504      
3505      // init Mootools
3506      initJSLib();
3507      
3508      // set specific frontend editing link
3509      set_css_link('inc_css/specific/frontend_edit.css');
3510      
3511      $link  = '';
3512      $href  = '';
3513      $title = '';
3514      
3515      switch($type) {
3516  
3517          case 'article':        $href  = 'do=articles&amp;p=2&amp;s=1&amp;id='.$id_1;
3518                              $title = 'backend: goto Article';
3519                              break;
3520                              
3521          case 'summary':        $href = 'do=articles&amp;p=2&amp;s=1&amp;aktion=1&amp;id='.$id_1;
3522                              $title = 'backend: edit Article Summary';
3523                              break;
3524  
3525          case 'structure':    break;
3526                              
3527          case 'CP':            $href = 'do=articles&amp;p=2&amp;s=1&amp;aktion=2&amp;id='.$id_1.'&amp;acid='.$id_2;
3528                              $title = 'backend: edit Content Part';
3529                              break;
3530                              
3531          case 'module':        $href = 'do=modules&amp;module='.$id_1;
3532                              $title = 'backend: goto Module';
3533                              break;
3534      }
3535      
3536      if($href) {
3537      
3538          $link  = '<a href="'.PHPWCMS_URL.'phpwcms.php?'.$href.'" target="_blank" ';
3539          $link .= 'class="fe-link fe-'.$type.'" title="'.$title.'">';
3540          $link .= '<span>'.$title.'</span></a> ';
3541      
3542      }
3543      
3544      return $link;
3545  }
3546  
3547  function setGetArticleAid(&$data) {
3548  
3549      if(!empty($data['article_alias'])) {
3550          return $data['article_alias'];
3551      } elseif(isset($data['article_id'])) {
3552          return 'aid='.$data['article_id'];
3553      }
3554      return '';
3555  }
3556  
3557  /**
3558   * Return Link based on given structure level data
3559   *
3560   * @param mixed - structure level [integer] ID or Array(acat_redirect,acat_alias,acat_id,acat_name) 
3561   * @param string - additional link attributes
3562   * @param string - link prefix
3563   * @param string - link suffix
3564   */
3565  function getStructureLevelLink($acat, $attributes='', $prefix='', $suffix='') {
3566      
3567      if( !is_array($acat) ) {
3568          
3569          $id = is_int($acat) ? intval($acat) : -1;
3570          
3571          if($id >= 0 && isset($GLOBALS['content']['struct'][$id])) {
3572          
3573              $acat =& $GLOBALS['content']['struct'][$id];
3574          
3575          } else {
3576              
3577              $acat = trim($acat);
3578              
3579              if(empty($acat)) {
3580                  return '';
3581              }
3582              
3583              return $prefix . html_specialchars( $acat ) . $suffix;
3584          
3585          }
3586          
3587      }
3588      
3589      if($acat['acat_redirect'] == false) {
3590          
3591          $target        = '';
3592          $link        = rel_url( array(), array('newsdetail'), empty($acat['acat_alias']) ? 'id='.$acat['acat_id'] : $acat['acat_alias'] );
3593          
3594      } else {
3595          
3596          $redirect    = get_redirect_link($acat['acat_redirect'], ' ', '');
3597          $target        = $redirect['target'];
3598          $link        = $redirect['link'];
3599          
3600      }
3601      
3602      return trim( '<a href="' . $link . '"' . $target . ' ' . $attributes ) . '>' . $prefix . html_specialchars( $acat['acat_name'] ) . $suffix . '</a>';
3603      
3604  }
3605  
3606  /**
3607   * Return menu or menu elements based on article menu title information 
3608   * starting at given structure level ID, limited to single level (non-nested)
3609   *
3610   * @return mixed (array/string)
3611   * @param array
3612   **/
3613  function getArticleMenu($data=array()) {
3614      
3615      global $content;
3616      global $aktion;
3617      
3618      $defaults = array(
3619          
3620          'level_id'                => 0,
3621          'class_active'            => array(0 => 'active', 1 => ''),
3622          'wrap_title_prefix'        => '',
3623          'wrap_title_suffix'        => '',
3624          'item_prefix'            => "\t",
3625          'item_suffix'            => '',
3626          'sort'                    => 'level',
3627          'item_tag'                => 'li',
3628          'wrap_tag'                => 'ul',
3629          'attribute_wrap_tag'    => '',
3630          'class_item_tag'        => '',
3631          'class_first_item_tag'    => '',
3632          'class_last_item_tag'    => '',
3633          'return_format'            => 'string' // string or array
3634  
3635                        );    
3636      
3637      $data        = is_array($data) && count($data) ? array_merge($defaults, $data) : $defaults;
3638      $li            = array();
3639      
3640      $articles = get_actcat_articles_data( $data['level_id'] );
3641      
3642      $key    = 0;
3643      $total    = count($articles) - 1;
3644      foreach($articles as $item) {
3645          
3646          $class        = '';
3647          $class_a    = '';
3648          if($data['class_item_tag']) {
3649              $class .= $data['class_item_tag'].' ';
3650          }
3651          if($key === 0 && $data['class_first_item_tag']) {
3652              $class .= $data['class_first_item_tag'].' ';
3653          } elseif($key === $total && $data['class_last_item_tag']) {
3654              $class .= $data['class_last_item_tag'].' ';
3655          }
3656          if($item['article_id'] == $aktion[1]) {
3657              if(!empty($data['class_active'][0])) {
3658                  $class .= $data['class_active'][0].' ';
3659              }
3660              if(!empty($data['class_active'][1])) {
3661                  $class_a = ' class="'.$data['class_active'][1].'"'; // set active link class
3662              }
3663          }
3664          $class = trim($class);
3665          
3666          $li[$key]  = $data['item_prefix'] . '<'. $data['item_tag'] . ($class != '' ? ' class="' . $class . '"' : '' ) . '>';
3667  
3668          $li[$key] .= '<a href="'.rel_url( array(), array('newsdetail'), setGetArticleAid($item) ).'"'.$class_a.'>';
3669          
3670          $li[$key] .= $data['wrap_title_prefix'];
3671          $li[$key] .= html_entities( getArticleMenuTitle($item) );
3672          $li[$key] .= $data['wrap_title_suffix'];
3673          
3674          $li[$key] .= '</a>';
3675  
3676          $li[$key] .= '</'.$data['item_tag'].'>' . $data['item_suffix'];
3677      
3678          $key++;
3679      
3680      }
3681      
3682      if($data['wrap_tag'] && count($li)) {
3683          
3684          array_unshift($li, '<'.trim($data['wrap_tag'].' '.trim($data['attribute_wrap_tag'])).'>');
3685          array_push($li, '</'.$data['wrap_tag'].'>');
3686          
3687      }
3688      
3689      return $data['return_format'] == 'string' ? implode(LF, $li) : $li;
3690  
3691  }
3692  
3693  /**
3694   * Return article menu title text
3695   *
3696   * @return string
3697   * @param array article data
3698   **/
3699  function getArticleMenuTitle(& $data) {
3700      return empty($data['article_menutitle']) ? $data['article_title'] : $data['article_menutitle'];
3701  }
3702  
3703  /**
3704   * Add HTML Head meta tag
3705   */
3706  function set_meta($name='', $content='', $http_equiv=FALSE) {
3707      if(empty($name) || empty($content)) {
3708          return NULL;
3709      }
3710      $GLOBALS['block']['custom_htmlhead']['meta.'.$name]  = '  <meta ';
3711      if($http_equiv == 'prop' || $http_equiv == 'property') {
3712          $GLOBALS['block']['custom_htmlhead']['meta.'.$name] .= 'property';
3713      } elseif($http_equiv === TRUE) {
3714          $GLOBALS['block']['custom_htmlhead']['meta.'.$name] .= 'http-equiv'; break;
3715      } else {
3716          $GLOBALS['block']['custom_htmlhead']['meta.'.$name] .= 'name';
3717      }
3718      $GLOBALS['block']['custom_htmlhead']['meta.'.$name] .= '="' . $name . '" content="'.html_specialchars($content).'" />';
3719  }
3720  
3721  /**
3722   * Search for replacement tag {LEVELX_ID} while X is integer like {LEVEL3_ID}
3723   * and return ID of the level or 0 if level is not set
3724   */
3725  function replace_level_id($match) {
3726      $level = intval($match[1]);
3727      if(isset($GLOBALS['LEVEL_ID'][ $level ])) {
3728          return $GLOBALS['LEVEL_ID'][ $level ];
3729      }
3730      return 0;
3731  }
3732  
3733  /**
3734   * Render CSS related template code
3735   *
3736   * relative or absolute external css file
3737   * <!-- CSS: file.css -->
3738   *
3739   * put as inline CSS in separate <style> section in head
3740   * <!-- CSS: img {} -->
3741   */
3742  function renderHeadCSS($css) {
3743      
3744      if(empty($css[1])) {
3745          return '';
3746      }
3747      
3748      $css = trim($css[1]);
3749      
3750      // test for .css as file extension
3751      $ext = which_ext($css);
3752      $key = md5($css);
3753      
3754      // if it is a css file register it as external css file
3755      if($ext == 'css') {
3756  
3757          $css = str_replace(' ', '%20', str_replace('{TEMPLATE}', TEMPLATE_PATH, html_specialchars($css)));
3758          
3759          if(strpos($css, '/') !== false) {
3760              $GLOBALS['block']['custom_htmlhead'][$key] = '  <link rel="stylesheet" type="text/css" href="' . $css . '"'.HTML_TAG_CLOSE;
3761          } else {
3762              $GLOBALS['block']['css'][$css] = $css;
3763          }
3764      
3765      // otherwise create a CSS <style> section
3766      } else {
3767          
3768          // add the same section only once
3769          if(isset($GLOBALS['block']['custom_htmlhead'][$key])) {
3770              return '';
3771          }
3772          
3773          $GLOBALS['block']['custom_htmlhead'][$key]  = '  <style type="text/css">' . LF . SCRIPT_CDATA_START . LF . '    ';
3774          $GLOBALS['block']['custom_htmlhead'][$key] .= str_replace('{TEMPLATE}', TEMPLATE_PATH, $css);
3775          $GLOBALS['block']['custom_htmlhead'][$key] .= LF . SCRIPT_CDATA_END . LF . '  </style>';
3776  
3777      }
3778      
3779      return '';
3780      
3781  }
3782  
3783  function parse_CKEDitor_resized_images() {
3784      
3785      $GLOBALS['content']['all'] = preg_replace_callback('/<img.*? src="(image_resized\.php\?format=.*?)".*? style="(.*?)px;"/', 'render_CKEDitor_resized_images', $GLOBALS['content']['all']);
3786      
3787  }
3788  
3789  function render_CKEDitor_resized_images($match) {
3790  
3791      $src = explode(PHPWCMS_FILES, $match[1]);
3792      if(empty($src[1])) {
3793          return $match[0];
3794      }
3795      
3796      $sizes    = explode(';', str_replace('px', '', $match[2]));
3797      $height    = 0;
3798      $width    = 0;
3799      foreach($sizes as $size) {
3800          
3801          $size = trim($size);
3802          
3803          if(substr($size, 0, 6) == 'width:') {
3804              $width    = intval(trim(substr($size, 6)));
3805          } elseif(substr($size, 0, 7) == 'height:') {
3806              $height    = intval(trim(substr($size, 7)));
3807          }
3808          
3809      }
3810      
3811      if(!$width || !$height) {
3812          return $match[0];
3813      }
3814      
3815      $src = 'img/cmsimage.php/'.$width.'x'.$height.'/'.$src[1];
3816      if(strpos($match[0], 'alt="')) {
3817          preg_match('/alt="(.*?)"/', $match[0], $alt);
3818          $alt = empty($alt[1]) ? '' : ' alt="'.$alt[1].'"';
3819      } else {
3820          $alt = '';
3821      }
3822      
3823      return '<img src="'.$src.'"'.$alt;
3824  }
3825  
3826  function get_structurelevel_single_article_alias($article_cid=0) {
3827      
3828      if(!is_intval($article_cid)) {
3829          return '';
3830      }
3831      
3832      global $content;
3833      
3834      if(empty($content['struct'][ $article_cid ]['acat_articlecount'])) {
3835          $sql  = 'SELECT COUNT(article_id) FROM '.DB_PREPEND.'phpwcms_article ';
3836          $sql .= 'WHERE article_cid='.$article_cid.' AND ';
3837          $sql .= 'article_public=1 AND article_aktiv=1 AND article_deleted=0 AND ';
3838          $sql .= 'article_begin < NOW() AND article_end > NOW()';
3839          $content['struct'][ $article_cid ]['acat_articlecount'] = _dbCount($sql);
3840      }
3841  
3842      // reset article alias/ID
3843      if($content['struct'][ $article_cid ]['acat_articlecount'] === 1) {
3844          return empty($content['struct'][ $article_cid ]['acat_alias']) ? 'id='.$article_cid : $content['struct'][ $article_cid ]['acat_alias'];
3845      }
3846      
3847      return '';
3848  }
3849  
3850  /**
3851   * Parse and render text for device specific replacement tags
3852   *
3853   *
3854   * @param    string
3855   * @return    string
3856   */
3857  function render_device($string) {
3858  
3859      if(empty($string)) {
3860          return '';
3861      }
3862  
3863      if(empty($GLOBALS['phpwcms']['render_device']) || strpos($string, '<!--if:') === false) {
3864          return $string;
3865      }
3866      
3867      preg_match_all('/<!--if:(.+?)-->(.*?)<!--\/if-->/s', $string, $matches);
3868  
3869      if(!isset($matches[0][0])) {
3870          return $string;        
3871      }
3872      
3873      // get agent information
3874      $user_agent = phpwcms_getUserAgent();
3875      
3876      // Test against
3877  
3878      foreach($matches[1] as $match) {
3879          
3880          $validity    = array();
3881          $values        = explode(';', strtolower($match));
3882          
3883          // parameters (AND)
3884          foreach($values as $check) {
3885              
3886              // values (OR)
3887              $check    = explode(':', trim($check));
3888              $param    = trim($check[0]);
3889              $value    = isset($check[1]) ? explode(',', trim($check[1])) : array();
3890                          
3891              // mobile
3892              if($param == 'mobile') {
3893              
3894                  $validity[] = $user_agent['mobile'] ? 1 : 0;
3895              
3896              } elseif($param == 'desktop') {
3897              
3898                  $validity[] = $user_agent['mobile'] ? 0 : 1;
3899              
3900              } elseif($param == 'platform') {
3901              
3902                  // WinPhone, WinCE, Win, iOS, Mac, GoogleTV, Android, 
3903                  // BlackBerry, WebOS, Linux, Unix, Symbian, Other
3904                  $validity[] = in_array(strtolower($user_agent['platform']), $value) ? 1 : 0;
3905              
3906              } elseif($param == 'device') {
3907              
3908                  // Default, Other, Smartphone, Tablet, Desktop, TV
3909                  $validity[] = in_array(strtolower($user_agent['device']), $value) ? 1 : 0;
3910              
3911              } elseif($param == 'browser') {
3912                  
3913                  // Other, Firefox, Chrome, Safari, IE, IEMobile, Opera, Mozilla
3914                  $validity[] = in_array(strtolower($user_agent['agent']), $value) ? 1 : 0;
3915                  
3916              } elseif($param == 'engine') {
3917                  
3918                  // Gecko, Other, WebKit, Opera, KHTML, 
3919                  $validity[] = in_array(strtolower($user_agent['engine']), $value) ? 1 : 0;
3920                  
3921              } elseif($param == 'version') {
3922                  
3923                  // Only first value will be used for comparison
3924                  // >Version, <Version, =Version, <=Version, >=Version
3925                  if(preg_match('/^([<>=]+)(\d+)$/', current($value), $value)) {
3926                      
3927                      $compare    = $value[1];
3928                      $value        = intval($value[2]);                
3929                      if($compare == '=' && $user_agent['version'] == $value) {
3930                          $validity[] = 1;
3931                      } elseif($compare == '<' && $user_agent['version'] < $value) {
3932                          $validity[] = 1;
3933                      } elseif($compare == '>' && $user_agent['version'] > $value) {
3934                              $validity[] = 1;
3935                      } elseif($compare == '<=' && $user_agent['version'] <= $value) {
3936                          $validity[] = 1;
3937                      } elseif($compare == '>=' && $user_agent['version'] >= $value) {
3938                          $validity[] = 1;
3939                      } else {
3940                          $validity[] = 0;            
3941                      }
3942                      
3943                  } else {
3944                      $validity[] = 0;                    
3945                  }
3946                  
3947              }
3948              
3949          }
3950          
3951          $match = preg_quote($match);
3952          if(array_sum($validity) == count($values)) {
3953              // Valid – delete the !if and !if:default
3954              $string    = preg_replace(
3955                  array('/<!--if:'.$match.'-->(.*?)<!--\/if-->/s', '/<!--!if:'.$match.'-->.*?<!--\/!if-->/s', '/<!--!if:default-->.*?<!--\/!if-->/s'),
3956                  array('$1', '', ''),
3957                  $string
3958              );
3959          } else {
3960              // Invalid – keep the !if and !if:default
3961              $string    = preg_replace(
3962                  array('/<!--if:'.$match.'-->.*?<!--\/if-->/s', '/<!--!if:'.$match.'-->(.*?)<!--\/!if-->/s', '/<!--!if:default-->(.*?)<!--\/!if-->/s'),
3963                  array('', '$1', '$1'),
3964                  $string
3965              );
3966          }
3967          
3968      }
3969  
3970      return $string;
3971  }
3972  
3973  ?>


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