[ Index ]

PHP Cross Reference of phpwcms V1.4.7 _r403 (01.11.10)

title

Body

[close]

/include/inc_lib/ -> backend.functions.inc.php (source)

   1  <?php
   2  /*************************************************************************************
   3     Copyright notice
   4     
   5     (c) 2002-2010 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  // general functions used in backend only
  24  
  25  function update_cache() {
  26      // used to update cache setting all current cache entries 
  27      // will be forced to update cache but will not be deleted
  28      //$sql = "UPDATE ".DB_PREPEND."phpwcms_cache SET cache_timeout='0'";
  29      //mysql_query($sql, $GLOBALS['db']) or die("error while updating cache");
  30  }
  31  
  32  function set_chat_focus($do, $p) { //set_chat_focus("chat", 1)
  33      if($do == "chat" && $p == 1) {
  34          echo "<script type=\"text/javascript\">\n";
  35          echo "document.sendchatmessage.chatmsg.focus();\ndocument.sendchatmessage.chatmsg.value=get_cookie('chatstring');\n";
  36          echo "timer = chat_reload(20000);\nfunction chat_reload(zeit) {\n";
  37          echo "timer=setTimeout(\"write_cookie(1);self.location.href='phpwcms.php?do=chat&p=1&l=".$chatlist."'\", zeit);\n";
  38          echo "return timer;\n}\nfunction restart_reload(timer) {\n";
  39          echo "if(timer != null) { clearTimeout(timer); timer=null; timer = chat_reload(20000); }\nreturn timer;\n}\n</script>\n";
  40      }
  41  }
  42  
  43  function forward_to($to, $link, $time=2500) { //Javascript forwarding
  44      if($to) echo "<script type=\"text/javascript\">\n setTimeout(\"document.location.href='".$link."'\", ".(intval($time))."); \n</script>\n";
  45  }
  46  
  47  function subnavtext($text, $link, $is, $should, $getback=1, $js='') {
  48      //generate subnavigation based on text
  49      $id = "subnavid".randpassword(5);
  50      $sn = '';
  51      if($is == $should) {
  52          $sn .= '<tr><td><img src="img/subnav/subnav_B.gif" width="15" height="13" border="0" alt="" /></td>';    
  53          $sn .= '<td class="subnavactive"><a href="'.$link.'">'.$text.'</a></td></tr>';
  54      } else {
  55          $sn .= "<tr><td><img name=\"".$id."\" src=\"img/subnav/subnav_A.gif\" width=\"15\" height=\"13\" border=\"0\" alt=\"\" /></td>";
  56          $sn .= "<td class=\"subnavinactive\"><a href=\"".$link."\" ".$js;
  57          $sn .= "onMouseOver=\"".$id.".src='img/subnav/subnav_B.gif'\" onMouseOut=\"".$id;
  58          $sn .= ".src='img/subnav/subnav_A.gif'\">".$text."</a></td></tr>";
  59      }
  60      $sn .= "\n";
  61      if(!$getback) { 
  62          return $sn; 
  63      } else {
  64          echo $sn;
  65      }
  66  }
  67  
  68  function subnavtextext($text, $link, $target='_blank', $getback=1) {
  69      //generate subnavigation based on text and links to new page
  70      $id  = 'subnavid'.randpassword(5);
  71      $sn  = '<tr><td><img src="img/subnav/subnav_A.gif" width="15" height="13" border="0" name="'.$id.'" alt="" /></td>';    
  72      $sn .= '<td class="subnavinactive"><a href="'.$link.'" target="'.$target.'" ';
  73      $sn .= "onMouseOver=\"".$id.".src='img/subnav/subnav_B.gif'\" onMouseOut=\"".$id.".src='img/subnav/subnav_A.gif'\"";
  74      $sn .= '>'.$text.'</a></td></tr>';
  75      $sn .= "\n";
  76      if(!$getback) { return $sn; } else { echo $sn; }
  77  }
  78  
  79  function subnavback($text, $link, $h_before=0, $h_after=0) {
  80      $id = "subbackid".randpassword(5);
  81      $sn  = "<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n";
  82      $sn .= (intval($h_before)) ? "<tr><td colspan=\"2\"><img src=\"img/leer.gif\" width=\"1\" height=\"".intval($h_before)."\" alt=\"\" /></td></tr>\n" : "";
  83      $sn .= "<tr>";
  84      $sn .= "<td><img name=\"".$id."\" src=\"img/subnav/subnav_back_0.gif\" width=\"9\" height=\"9\" border=\"0\" alt=\"\" /></td>";
  85      $sn .= "<td class=\"subnavinactive\">&nbsp;<a href=\"".$link."\" onMouseOver=\"".$id.".src='img/subnav/subnav_back_1.gif'\" ";
  86      $sn .= "onMouseOut=\"".$id.".src='img/subnav/subnav_back_0.gif'\"><strong>".$text."</strong></a></td>";
  87      $sn .= "</tr>\n";
  88      $sn .= (intval($h_after)) ? "<tr><td colspan=\"2\"><img src=\"img/leer.gif\" width=\"1\" height=\"".intval($h_after)."\" alt=\"\" /></td></tr>\n" : "";
  89      $sn .= "</table>\n";
  90      echo $sn;
  91  }
  92  
  93  function clearfilename($formvar) {
  94      //Filename anpassen und säubern
  95      $formvar = trim($formvar);
  96      if( get_magic_quotes_gpc() ) $formvar = stripslashes ($formvar);
  97      $formvar = str_replace(array("'", ':', '/', '\\', '"'), '_', $formvar);
  98      return $formvar;
  99  }
 100  
 101  function check_image_extension($file, $filename='') {
 102      // only checks against correct image extension
 103      $image_info    = getimagesize($file);    
 104      $result        = false;
 105      if(false != $image_info) {
 106          switch($image_info[2]) {
 107              case  1: $result = 'gif';    break;
 108              case  2: $result = 'jpg';    break;
 109              case  3: $result = 'png';    break;
 110              case  4: $result = 'swf';    break;
 111              case  5: $result = 'psd';    break;
 112              case  6: $result = 'bmp';    break;
 113              case  7: $result = 'tif';    break; //(intel byte order), 
 114              case  8: $result = 'tif';    break; //(motorola byte order), 
 115              case  9: $result = 'jpc';    break;
 116              case 10: $result = 'jp2';    break;
 117              case 11: $result = 'jpx';    break;
 118              case 12: $result = 'jb2';    break;
 119              
 120              case 13: // there is a problem in some cases swf -> swc ? why ever!
 121                       // do an additional extension check and compare against swf
 122                       $result = (strtolower(which_ext($file)) == 'swf') ? 'swf' : 'swc';
 123                       break;
 124              
 125              case 14: $result = 'iff';    break;
 126  
 127              case 15: // there seems to be a problem with getimagesize and Quicktime VR
 128                       // mov -> wmbf ? why ever!
 129                       // do an additional extension check and compare against mov
 130                       $result = (strtolower(which_ext( empty($filename) ? $file : $filename )) == 'mov') ? 'mov' : 'wbmp';
 131                       break;
 132  
 133              case 16: $result = 'xbm';    break;
 134          }
 135      }    
 136      return $result;
 137  }
 138  
 139  function getParentStructArray($structID) {
 140      $structID    = intval($structID);
 141      $sql = "SELECT * FROM ".DB_PREPEND."phpwcms_articlecat WHERE acat_id=".$structID." LIMIT 1";
 142      if($result = mysql_query($sql, $GLOBALS['db'])) {
 143          if($row = mysql_fetch_assoc($result)) {
 144              return $row;
 145          }
 146          mysql_free_result($result);
 147      }
 148      return $GLOBALS['indexpage'];
 149  }
 150  
 151  /*
 152   * Get sort value for an article based on category
 153   */
 154  function getArticleSortValue($cat_id=0) {
 155      
 156      // default sort value
 157      $sort        = 0;
 158      $cat_id        = intval($cat_id);
 159      $count        = 0;
 160      $max_sort    = 0;
 161      // Count all articles within the given structure ID
 162      $sql  = "SELECT article_id, article_sort FROM ".DB_PREPEND."phpwcms_article ";
 163      $sql .= "WHERE article_cid=".$cat_id." ";
 164      $sql .= "ORDER BY article_sort DESC";
 165      if($result = mysql_query($sql, $GLOBALS['db'])) {
 166          // this is the max articles in structure
 167          $count = mysql_num_rows($result);
 168          // but neccessary trying to get the highest article sort value
 169          if($row = mysql_fetch_assoc($result)) {
 170              $max_sort = $row['article_sort'];
 171          }
 172          mysql_free_result($result);
 173      }
 174      $count = ($count + 1) * 10;
 175      $count = ($max_sort < $count) ? $count : $max_sort + 10;
 176      return $count;
 177  }
 178  
 179  /*
 180   * Make a re-sort for given structure ID and 
 181   * return new sorted articles as array
 182   */
 183  function getArticleReSorted(& $cat_id, & $ordered_by) {
 184      
 185      // get all articles including deleted and update sorting
 186      // in correct sort order by adding sort + 10
 187      $sort                = 10;
 188      $sort_multiply_by    = 1;
 189      $count_article        = 0;
 190      $ao                 = get_order_sort($ordered_by);
 191      
 192      $sql  = "SELECT article_id, article_cid, article_title, article_public, article_aktiv, article_uid, ";
 193      $sql .= "date_format(article_tstamp, '%Y-%m-%d %H:%i:%s') AS article_date, article_sort, article_deleted, article_tstamp ";
 194      $sql .= "FROM ".DB_PREPEND."phpwcms_article ";
 195      $sql .= "WHERE article_cid='".$cat_id."' ORDER BY ".$ao[2];
 196      
 197      if($result = mysql_query($sql, $GLOBALS['db'])) {
 198      
 199          // now check if it's sorted manually and DESC
 200          // then sort has to be lowerd by -10
 201          if($ao[0] == 0 && $ao[1] == 1) {
 202              $max_article_count    = mysql_num_rows($result);
 203              $sort                 = ($max_article_count + 1) * 10;
 204              $sort_multiply_by    = -1;
 205          }
 206      
 207          // take all entries and build new array with it
 208          while($row = mysql_fetch_assoc($result)) {
 209  
 210              // SQL update query with new sort value
 211              $update_sql  = "UPDATE ".DB_PREPEND."phpwcms_article SET ";
 212              $update_sql .= "article_sort=".$sort.", ";
 213              $update_sql .= "article_tstamp='".$row['article_tstamp']."' ";
 214              $update_sql .= "WHERE article_id=".$row['article_id']." LIMIT 1";
 215              @mysql_query($update_sql, $GLOBALS['db']);
 216  
 217              // add entry to the returning array only for article_deleted=0
 218              // drops all deleted articles or articles having another status
 219              if($row['article_deleted'] == 0) {
 220              
 221                  $article[$count_article]                    = $row;
 222                  $article[$count_article]['article_sort']    = $sort;
 223                          
 224                  // count up for article array index
 225                  $count_article++;
 226                  
 227              }
 228  
 229              // count sort up by 10
 230              $sort = $sort + (10 * $sort_multiply_by);
 231  
 232          }
 233          mysql_free_result($result);
 234      }
 235  
 236      return $article;    
 237  
 238  }
 239  
 240  function phpwcmsversionCheck() {
 241  
 242      // Check for new version
 243      
 244      global $phpwcms;
 245      global $BL;
 246      
 247      if(empty($phpwcms['version_check'])) return '';
 248  
 249      $errno                         = 0;
 250      $errstr                     = '';
 251      $version_info                = '';
 252  
 253      if ($fsock = @fsockopen('www.phpwcms.de', 80, $errno, $errstr, 10))    {
 254  
 255          $identify = '?version='.rawurlencode($phpwcms["release"].'-'.str_replace('/', '', $phpwcms["release_date"])).'&hash='.md5($_SERVER['REQUEST_URI']);
 256      
 257          @fputs($fsock, "GET /versioncheck/phpwcms_releaseinfo.txt".$identify." HTTP/1.1\r\n");
 258          @fputs($fsock, "HOST: www.phpwcms.de\r\n");
 259          @fputs($fsock, "Connection: close\r\n\r\n");
 260  
 261          $get_info = false;
 262          while (!@feof($fsock)) {
 263              if ($get_info) {
 264                  $version_info .= @fread($fsock, 1024);
 265              } else {
 266                  if (@fgets($fsock, 1024) == "\r\n") {
 267                      $get_info = true;
 268                  }
 269              }
 270          }
 271          @fclose($fsock);
 272  
 273          $version_info        = explode("\n", $version_info);
 274          
 275          $latest_version        = trim($version_info[0]);
 276          $latest_revdate        = trim($version_info[1]);
 277          $latest_revision    = intval(trim($version_info[2]));
 278  
 279          // do version check
 280          $check = $latest_revision > $phpwcms['revision'] ? false : true;
 281          
 282          
 283          if ($check)    {
 284              $version_info  = '<p class="valid">' . $BL['Version_up_to_date'] . '</p>';
 285              $version_info .= '<p class="valid">'.sprintf($BL['Latest_version_info'], $latest_version.' ('.$latest_revdate.', r'.$latest_revision.')'). ' ';
 286              $version_info .= sprintf($BL['Current_version_info'], $phpwcms["release"].' ('.$phpwcms["release_date"].', r'.$phpwcms["revision"].')') . '</p>';
 287          
 288          } else {
 289              $version_info  = '<p class="error">' . $BL['Version_not_up_to_date'] . '</p>';
 290              $version_info .= '<p class="error">'.sprintf($BL['Latest_version_info'], ' ' . $latest_version . ' ('.$latest_revdate.', r'.$latest_revision.')'). ' ';
 291              $version_info .= sprintf($BL['Current_version_info'], $phpwcms["release"].' ('.$phpwcms["release_date"].', r'.$phpwcms["revision"].')') . '</p>';
 292  
 293          }
 294          
 295  
 296      } else {
 297      
 298          if ($errstr) {
 299              $version_info = '<p class="error">' . sprintf($BL['Connect_socket_error'], $errstr) . '</p>';
 300          } else {
 301              $version_info = '<p>' . $BL['Socket_functions_disabled'] . '</p>';
 302          }
 303      }
 304      
 305      //$version_info .= '<p>' . $BL['Mailing_list_subscribe_reminder'] . '</p>';
 306  
 307      return '<div class="versioncheck"><h1>'.$BL['Version_information'].'</h1> '.$version_info.'</div>';
 308  
 309  }
 310  
 311  
 312  function createOptionTransferSelectList($id='', $leftData, $rightData, $option = array()) {
 313      // used to create
 314      
 315      global $BL;
 316  
 317      $id_left                = $id.'_left';
 318      $id_right                = $id.'_right';
 319      $id_left_box            = $id_left.'list';
 320      $id_right_box            = $id_right.'list';
 321      $option_object            = generic_string(4, 4);
 322      
 323      $table                    = '';
 324      
 325      $option['rows']            = empty($option['rows']) || !intval($option['rows']) ? 5 : $option['rows'];
 326      $option['delimeter']    = empty($option['delimeter']) ? ',' : $option['delimeter'];
 327      $option['encode']        = (isset($option['encode']) && $option['encode'] === false) ? false : true;
 328      $option['style']        = empty($option['style']) ? '' : ' style="'.$option['style'].'"';
 329      $option['class']        = empty($option['class']) ? ' class="#SIDE#"' : ' class="#SIDE# '.$option['class'].'"';
 330      $option['formname']        = empty($option['formname']) ? 'document.forms[0]' : 'document.getElementById(\''.$option['formname'].'\')';
 331      
 332      
 333      $GLOBALS['BE']['HEADER']['optionselect.js'] = getJavaScriptSourceLink('include/inc_js/optionselect.js');
 334      
 335      $table .= '<table border="0" cellspacing="0" cellpadding="0">'.LF.'<tr>'.LF;
 336      
 337      // left select list
 338      $table .= '<td valign><select name="'.$id_left_box.'" id="'.$id_left_box.'" size="'.$option['rows'].'" multiple="multiple"';
 339      $table .= $option['style'].str_replace('#SIDE#', 'leftSide', $option['class']).' ondblclick="'.$option_object.'.transferRight()">'.LF;
 340      if(!empty($leftData) && is_array($leftData)) {
 341          foreach($leftData as $key => $value) {
 342              $table .= '        <option value="'.$key.'">'.$value.'</option>'.LF;
 343          }
 344      }    $table .= '</select></td>'.LF;
 345      
 346      // left <-> right buttons
 347      $table .= '<td'.$option['style'].$option['class'].'>';
 348      $table .= '<img src="img/leer.gif" alt="" width="1" height="1" />'.LF;
 349      $table .= '</td>'.LF;
 350      
 351      // right select list
 352      $table .= '<td><select name="'.$id_right_box.'" id="'.$id_right_box.'" size="'.$option['rows'].'" multiple="multiple"';
 353      $table .= $option['style'].str_replace('#SIDE#', 'rightSide', $option['class']).' ondblclick="'.$option_object.'.transferLeft()">'.LF;
 354      if(!empty($rightData) && is_array($rightData)) {
 355          foreach($rightData as $key => $value) {
 356              $table .= '        <option value="'.$key.'">'.$value.'</option>'.LF;
 357          }
 358      }
 359      $table .= '</select></td>'.LF;
 360      $table .= '</tr>'.LF;
 361      
 362      $table .= '<tr>'.LF.'<td>';
 363      $table .= '<img src="img/button/list_pos_up.gif" alt="" border="0" onclick="moveOptionUp('.$option['formname'].'.'.$id_left_box.');'.$option_object.'.update();">';
 364      $table .= '<img src="img/leer.gif" width="2" height="2" alt="" />';
 365      $table .= '<img src="img/button/list_pos_down.gif" alt="" border="0" onclick="moveOptionDown('.$option['formname'].'.'.$id_left_box.');'.$option_object.'.update();">';
 366      $table .= '<img src="img/leer.gif" width="4" height="4" alt="" />';
 367      $table .= '<img src="img/button/put_right_a.gif" alt="Move selected to right" border="0" onclick="'.$option_object.'.transferRight();" />';
 368      $table .= '<img src="img/leer.gif" width="2" height="2" alt="" />';
 369      $table .= '<img src="img/button/put_right.gif" alt="Move all to right" border="0" onclick="'.$option_object.'.transferAllRight();"/>';
 370      $table .= '</td>'.LF;
 371      
 372      $table .= '<td><img src="img/leer.gif" alt="" width="1" height="1" /></td>'.LF;
 373      
 374      $table .= '<td>';
 375      $table .= '<img src="img/button/put_left_a.gif" alt="Move selected to left" border="0" onclick="'.$option_object.'.transferLeft();" />';
 376      $table .= '<img src="img/leer.gif" width="2" height="2" alt="" />';
 377      $table .= '<img src="img/button/put_left.gif" alt="Move all to left" border="0" onclick="'.$option_object.'.transferAllLeft();" />';
 378      $table .= '</td>'.LF;
 379      
 380      $table .= '</tr>'.LF.'</table>'.LF;
 381      
 382      $table .= '<input type="hidden" name="'.$id_left.'" id="'.$id_left.'" value="" />';
 383      $table .= '<input type="hidden" name="'.$id_right.'" id="'.$id_right.'" value="" />';
 384      
 385      $table .= '<script language="javascript">'.LF;
 386      $table .= SCRIPT_CDATA_START.LF;
 387      $table .= '    var '.$option_object.' = new OptionTransfer("'.$id_left_box.'","'.$id_right_box.'");'.LF;
 388      $table .= '    '.$option_object.'.setAutoSort(false);'.LF;
 389      $table .= '    '.$option_object.'.setDelimiter("'.$option['delimeter'].'");'.LF;
 390      $table .= '    '.$option_object.'.saveNewLeftOptions("'.$id_left.'");'.LF;
 391      $table .= '    '.$option_object.'.saveNewRightOptions("'.$id_right.'");'.LF;
 392      $table .= '    '.$option_object.'.init('.$option['formname'].');'.LF;
 393      
 394      $table .= LF.SCRIPT_CDATA_END.LF;
 395      $table .= '</script>'.LF;
 396  
 397      return $table;
 398  }
 399  
 400  function countNewsletterRecipients($target) {
 401      // try to count all recipients for special newsletter
 402      $recipients    = _dbQuery('SELECT * FROM '.DB_PREPEND.'phpwcms_address WHERE address_verified=1');
 403      $counter    = 0;
 404      $check        = (empty($target) || !is_array($target) || !count($target)) ? false : true;
 405      foreach($recipients as $value) {
 406          if(empty($value['address_subscription'])) {
 407              $counter++;
 408              continue;
 409          } elseif($check) {
 410              $value['address_subscription'] = unserialize($value['address_subscription']);
 411              if(is_array($value['address_subscription'])) {
 412                  foreach($value['address_subscription'] as $subscr) {
 413                      if(in_array(intval($subscr), $target)) {
 414                          $counter++;
 415                          break;
 416                      }
 417                  }
 418              }
 419          }
 420      }
 421      return $counter;
 422  }
 423  
 424  function getContentPartOptionTag($value='', $text='', $selected='', $module='') {
 425  
 426      $result = '';
 427      
 428  
 429      // neccessary plugin check
 430      if($value == 30) {
 431      
 432          if(!isset($GLOBALS['temp_count'])) {
 433              $GLOBALS['temp_count'] = 0;
 434          }
 435      
 436          foreach($GLOBALS['phpwcms']['modules'] as $module_value) {
 437          
 438              if($module_value['cntp'] && file_exists($module_value['path'].'inc/cnt.list.php')) {
 439                  $result .= '<option value="'.$value.':'.$module_value['name'].'"';
 440                  if($value == $selected && $module_value['name'] == $module) {
 441                      $result .= ' selected="selected"';
 442                      $GLOBALS['contentpart_temp_selected'] = $GLOBALS['temp_count'];
 443                  }
 444                  $result .= '>'.$text;
 445                  $result .= ': '.$GLOBALS['BL']['modules'][ $module_value['name'] ]['listing_title'];
 446                  $result .= '</option>'.LF;
 447                  $GLOBALS['temp_count']++;
 448              }
 449          
 450          }
 451      
 452      } else {
 453      
 454          $result .= '<option value="'.$value.'"';
 455          if($value == $selected) {
 456              $result .= ' selected="selected"';
 457              $GLOBALS['contentpart_temp_selected'] = $GLOBALS['temp_count'];
 458          }
 459          $result .= '>'.$text.'</option>'.LF;
 460      
 461      }
 462      
 463      return $result;
 464  
 465  }
 466  
 467  function isContentPartSet($value='') {
 468      
 469      $value = explode(':', $value);
 470      $value[0] = intval($value[0]);
 471      
 472      // check for set module
 473      if(empty($value[1])) {
 474  
 475          $value[1] = 1;
 476          
 477      } elseif(        isset($GLOBALS['phpwcms']['modules'][$value[1]]) 
 478                  &&    $GLOBALS['phpwcms']['modules'][$value[1]]['cntp']
 479                  &&    file_exists($GLOBALS['phpwcms']['modules'][$value[1]]['path'].'inc/cnt.list.php')) {
 480          
 481          $value[1] = 1;
 482      
 483      } else {
 484      
 485          $value[1] = 0;
 486      
 487      }
 488      
 489      // check if content part ID exists
 490      if(isset($GLOBALS['wcs_content_type'][ $value[0] ]) && $value[1]) {
 491      
 492          return true;
 493      
 494      } else {
 495      
 496          return false;
 497      
 498      }
 499  
 500  }
 501  
 502  /*
 503   *    Show System Status Message
 504   */
 505  function show_status_message($return_status=false) {
 506      if(empty($_SESSION['system_status']['msg'])) {
 507          $status = '';
 508      } else {
 509          $status  = '<div class="status_message_' . $_SESSION['system_status']['type'] .'">';
 510          $status .= nl2br( trim( html_specialchars($_SESSION['system_status']['msg']) ) ) . '</div>';
 511          $_SESSION['system_status']['msg'] = '';
 512      }
 513      if($return_status) {
 514          return $status;
 515      } else {
 516          echo $status;
 517          return NULL;
 518      }
 519  }
 520  /*
 521   *    Set System Status Message
 522   */
 523  function set_status_message($msg='', $type='info', $replace=array()) {
 524      if(is_array($replace) && count($replace)) {
 525          foreach($replace as $key => $item) {
 526              $msg = str_replace('{'.strtoupper($key).'}', $item, $msg);
 527          }
 528      }
 529      $_SESSION['system_status']['msg']  = $msg;
 530      switch($type) {
 531          case 'success':
 532          case 'info':
 533          case 'help':
 534          case 'error':
 535          case 'warning':    break;
 536          default: $type = 'info';
 537      }
 538      $_SESSION['system_status']['type'] = $type;
 539      return NULL;
 540  }
 541  
 542  function set_language_cookie() {
 543      setcookie('phpwcmsBELang', $_SESSION["wcs_user_lang"], time()+(3600*24*365), '/', getCookieDomain() );
 544  }
 545  
 546  // checks for alias and sets unique value
 547  function proof_alias($current_id, $alias='', $mode='CATEGORY') {
 548  
 549      $current_id    = intval($current_id);
 550      $alias = clean_slweg(strtolower($alias), 150);
 551      $alias = uri_sanitize($alias);
 552      /*
 553      $alias = pre_remove_accents($alias);
 554      $alias = get_alnum_dashes($alias, true);
 555      $alias = trim($alias);
 556      if($alias != '') {
 557          $alias = trim( preg_replace('/\-\-+/', '-', $alias), '-' );
 558          $alias = trim( preg_replace('/__+/', '_', $alias), '_' );
 559      }
 560      */
 561      
 562      $reserved    = array(
 563          'print',
 564          'newsdetail',
 565          'newspage',
 566          'id',
 567          'aid',
 568          'subgallery',
 569          'listpage',
 570          'page',
 571          'subscribe',
 572          'unsubscribe',
 573          'email',
 574          'u',
 575          's',
 576          'q'
 577          );
 578  
 579      if($mode == 'CATEGORY' && $alias == '' && isset($_POST["acat_name"])) {
 580          $alias = $_POST["acat_name"];
 581          $set = true;
 582      } elseif($mode == 'ARTICLE' && $alias == '' && isset($_POST["article_title"])) {
 583          $alias = $_POST["article_title"];
 584          $set = true;
 585      } elseif($mode == 'CONTENT' && $alias == '' && ( isset($_POST["cnt_title"]) || isset($_POST["cnt_name"]) )) {
 586          $alias = trim($_POST["cnt_title"]) == '' ? $_POST["cnt_name"] : $_POST["cnt_title"];
 587          $set = true;
 588      } else {
 589          $set = false;
 590      }
 591      
 592      if($set) {
 593          $alias = clean_slweg(strtolower($alias), 150);
 594          $alias = pre_remove_accents($alias);
 595          $alias = get_alnum_dashes($alias, true);
 596          if($alias != '') {
 597              $alias        = trim( preg_replace('/\-\-+/', '-', $alias), '-' );
 598              $alias        = trim( preg_replace('/__+/', '_', $alias), '_' );
 599          }
 600      }
 601      
 602      // new reserved alias can be defined in $phpwcms['reserved_alias']
 603      if( isset($phpwcms['reserved_alias']) && is_array($phpwcms['reserved_alias']) && count($phpwcms['reserved_alias']) ) {
 604          $reserved = array_merge($reserved, $phpwcms['reserved_alias']);
 605      }
 606      
 607      if( $alias == '' || in_array($alias, $reserved) || ($alias == 'index' && $current_id != 'index') ) {
 608      
 609          if($mode == 'CONTENT') {
 610              $alias .= date('-Y-n-j');
 611          } else {
 612              $alias .= '-view';
 613          }
 614      }
 615      
 616      $alias = trim( $alias, '-' );
 617      
 618      /*
 619      $where_acat        = 'acat_id != '.$current_id.' AND ';
 620      $where_article    = 'article_id != '.$current_id.' AND ';
 621      $where_content    = 'cnt_id != '.$current_id.' AND ';
 622  
 623      switch($mode) {
 624          case 'CATEGORY':    $where_article    = '';    break;
 625          case 'ARTICLE':        $where_acat        = '';    break;
 626          case 'CONTENT':        $where_content    = '';    break;
 627      }
 628      */
 629      $where_acat        = '';
 630      $where_article    = '';
 631      $where_content    = '';
 632  
 633      switch($mode) {
 634          case 'CATEGORY':    $where_acat        = 'acat_id != '.$current_id.' AND ';    break;
 635          case 'ARTICLE':        $where_article    = 'article_id != '.$current_id.' AND ';    break;
 636          case 'CONTENT':        $where_content    = 'cnt_id != '.$current_id.' AND ';        break;
 637      }
 638      
 639      // check alias against all structure alias
 640      $sql  = "SELECT COUNT(acat_id) FROM ".DB_PREPEND."phpwcms_articlecat WHERE ";
 641      $sql .= $where_acat;
 642      $sql .= "acat_alias='".aporeplace($alias)."'";
 643      $acat_count = _dbQuery($sql, 'COUNT');
 644      
 645      // check alias against all articles
 646      $sql  = "SELECT COUNT(article_id) FROM ".DB_PREPEND."phpwcms_article WHERE ";
 647      $sql .= $where_article;
 648      $sql .= "article_alias='".aporeplace($alias)."'";
 649      $article_count = _dbQuery($sql, 'COUNT');
 650      
 651      // check alias against all "sub" contents like news
 652      $sql  = "SELECT COUNT(cnt_id) FROM ".DB_PREPEND."phpwcms_content WHERE ";
 653      $sql .= $where_content;
 654      $sql .= "cnt_alias='".aporeplace($alias)."'";
 655      $content_count = _dbQuery($sql, 'COUNT');
 656  
 657      if( $acat_count > 0 || $article_count > 0 || $content_count > 0 ) {
 658      
 659          $sql  = "SELECT acat_alias FROM ".DB_PREPEND."phpwcms_articlecat WHERE ";
 660          $sql .= $where_acat;
 661          $sql .= "acat_alias LIKE '".aporeplace($alias)."%'";
 662          $all_acat_alias = _dbQuery($sql);
 663          
 664          $sql  = "SELECT article_alias FROM ".DB_PREPEND."phpwcms_article WHERE ";
 665          $sql .= $where_article;
 666          $sql .= "article_alias LIKE '".aporeplace($alias)."%'";
 667          $all_article_alias = _dbQuery($sql);
 668          
 669          $sql  = "SELECT cnt_alias FROM ".DB_PREPEND."phpwcms_content WHERE ";
 670          $sql .= $where_content;
 671          $sql .= "cnt_alias LIKE '".aporeplace($alias)."%'";
 672          $all_content_alias = _dbQuery($sql);
 673  
 674          $all_alias = array();
 675          foreach($all_acat_alias as $item) {
 676              $item = $item['acat_alias'];
 677              $all_alias[$item] = $item;
 678          }
 679          foreach($all_article_alias as $item) {
 680              $item = $item['article_alias'];
 681              $all_alias[$item] = $item;
 682          }
 683          foreach($all_content_alias as $item) {
 684              $item = $item['cnt_alias'];
 685              $all_alias[$item] = $item;
 686          }
 687          $all_alias_count = count($all_alias);
 688          while( isset( $all_alias[ $alias.'-'.$all_alias_count ] ) ) {
 689              $all_alias_count++;
 690          }
 691                  
 692          if(preg_match('/\-(\d+)$/', $alias)) {
 693              $alias .= $all_alias_count;
 694          } else {
 695              $alias .= '-'.$all_alias_count;
 696          }
 697      }
 698      
 699      return $alias;
 700  }
 701  
 702  function _getTime($time='', $delimeter=':', $default_time='H:i:s') {
 703  
 704      $timeformat        = explode($delimeter, trim($default_time));
 705      $time            = explode($delimeter, trim($time));
 706      
 707      $hour            = 0;
 708      $minute            = 0;
 709      $second            = 0;
 710      
 711      for($x=0; $x<=2; $x++) {
 712      
 713          if(isset($timeformat[$x])) {
 714          
 715              $value = trim($timeformat[$x]);
 716              switch( $value{0} ) {
 717              
 718                  case 'H':     if(isset($time[$x])) {
 719                                  $hour = intval($time[$x]);
 720                                  if($hour < 0 || $hour > 23) $hour = 0;
 721                              }
 722                              break;
 723                              
 724                  case 'i':     if(isset($time[$x])) {
 725                                  $minute = intval($time[$x]);
 726                                  if($minute < 0 || $minute > 59) $minute = 0;
 727                              }
 728                              break;
 729                              
 730                  case 's':     if(isset($time[$x])) {
 731                                  $second = intval($time[$x]);
 732                                  if($second < 0 || $second > 59) $second = 0;
 733                              }
 734                              break;
 735              }
 736          
 737          }
 738      
 739      }
 740      
 741      $time = str_replace($delimeter, ':', $default_time);
 742      $time = str_replace('H', $hour, $time);
 743      $time = str_replace('i', $minute, $time);
 744      $time = str_replace('s', $second, $time);
 745  
 746      return $time;
 747  }
 748  
 749  function _getDate($date='', $delimeter='', $default_date='') {
 750  
 751      global $BL;
 752      
 753      $delimeter        = $delimeter == '' ? $BL['default_date_delimiter'] : $delimeter;
 754      $default_date    = $default_date == '' ? $BL['default_date'] : $default_date;
 755      
 756      $dateformat        = explode($delimeter, trim($default_date));
 757      $date            = explode($delimeter, trim($date));
 758      
 759      $day            = '';
 760      $month            = '';
 761      $year            = '';
 762      
 763      for($x=0; $x<=2; $x++) {
 764      
 765          if(isset($dateformat[$x])) {
 766          
 767              $value = trim($dateformat[$x]);
 768              $value = strtolower($value);
 769              switch( $value{0} ) {
 770              
 771                  case 'y':     if(isset($date[$x])) {
 772                                  $year = intval($date[$x]);
 773                                  if($year < 0) $year = '';
 774                              }
 775                              break;
 776                              
 777                  case 'd':     if(isset($date[$x])) {
 778                                  $day = intval($date[$x]);
 779                                  if($day < 1 || $day > 31) $day = '';
 780                              }
 781                              break;
 782                              
 783                  case 'm':     if(isset($date[$x])) {
 784                                  $month = intval($date[$x]);
 785                                  if($month < 1 || $month > 12) $month = '';
 786                              }
 787                              break;
 788              
 789              }
 790          
 791          }
 792      
 793      }
 794      
 795      if($year && $month && $day) {
 796      
 797          return $year.'-'.$month.'-'.$day;
 798      
 799      } else {
 800      
 801          return '0000-00-00';
 802      
 803      }
 804      
 805  }
 806  
 807  function _dbSaveCategories($categories=array(), $type='', $pid=0, $seperator=',') {
 808  
 809      $pid    = intval($pid);
 810      $type    = trim($type);
 811      
 812      if(is_string($categories)) {
 813          $categories = convertStringToArray($categories, $seperator);
 814      }
 815      
 816      // delete all related categories first
 817      if($type && $pid) {
 818          
 819          $sql = 'DELETE FROM '.DB_PREPEND.'phpwcms_categories WHERE cat_pid='.$pid." AND cat_type='".aporeplace( $type )."'";
 820          _dbQuery($sql, 'DELETE');
 821      
 822      }
 823  
 824      if(is_array($categories) && count($categories) && $type && $pid) {
 825      
 826          $data = array(    'cat_type'            => $type,
 827                          'cat_pid'             => $pid,
 828                          'cat_status'        => 1,
 829                          'cat_createdate'    => date('Y-m-d H:i:s'),
 830                          'cat_changedate'    => date('Y-m-d H:i:s'),
 831                          'cat_name'            => '',
 832                          'cat_info'            => ''
 833                          );
 834      
 835          foreach($categories as $value) {
 836              $value = trim($value);
 837              if($value != '') {
 838                  
 839                  $data['cat_name'] = $value;
 840                  _dbInsert('phpwcms_categories', $data);
 841                  
 842              }
 843          }
 844      }
 845  }
 846  
 847  function setItemsPerPage($default=25) {
 848      if( isset($_GET['showipp']) ) {
 849          $ipp = intval( is_numeric($_GET['showipp']) ? $_GET['showipp'] : $default );
 850          setcookie('phpwcmsBEItemsPerPage', $ipp, time()+157680000, '/', getCookieDomain() );
 851      } elseif(isset($_SESSION['PAGE_FILTER'])) {
 852          $ipp = $_SESSION['PAGE_FILTER']['IPP'];
 853      } elseif( isset($_COOKIE['phpwcmsBEItemsPerPage']) ) {
 854          $ipp = intval( $_COOKIE['phpwcmsBEItemsPerPage'] );
 855      } else {
 856          $ipp = $default;
 857      }
 858      
 859      if(!isset($_SESSION['PAGE_FILTER'])) {
 860          $_SESSION['PAGE_FILTER'] = array();
 861      }
 862      
 863      $_SESSION['PAGE_FILTER']['IPP'] = $ipp;
 864      
 865      return $ipp;
 866  }
 867  
 868  function getItemsPerPageMenu($base_url='', $steps=array(10,25,50,100,250,0), $separator=' ') {
 869  
 870      $ipp = isset($_SESSION['PAGE_FILTER']['IPP']) ? $_SESSION['PAGE_FILTER']['IPP'] : setItemsPerPage();
 871      
 872      if(!in_array($ipp, $steps)) {
 873          array_unshift($steps, $ipp);
 874      }
 875      
 876      $menu = array();
 877      $x = 0;
 878      foreach($steps as $item) {
 879      
 880          $menu[$x]  = '<a href="'.$base_url.'&amp;showipp='.$item.'"';
 881          if($ipp == $item) {
 882              $menu[$x] .= ' class="active"';
 883          }
 884          $menu[$x] .= '>';
 885          $menu[$x] .= $item == 0 ? $GLOBALS['BL']['be_ftptakeover_all'] : $item;
 886          $menu[$x] .= '</a>';
 887      
 888          $x++;
 889      }
 890      
 891      return implode($separator, $menu);
 892  }
 893  
 894  function initJsCalendar() {
 895      $GLOBALS['BE']['HEADER']['date.js']            = getJavaScriptSourceLink('include/inc_js/date.js');
 896      $GLOBALS['BE']['HEADER']['dynCalendar.js']    = getJavaScriptSourceLink('include/inc_js/dynCalendar.js');
 897  }
 898  function initMootools($mode='1.1', $more=array()) {
 899      switch($mode) {
 900          // MooTools 1.1
 901          case '1.1':
 902              $GLOBALS['BE']['HEADER']['mootools.js'] = getJavaScriptSourceLink(TEMPLATE_PATH.'lib/mootools/mootools-1.1-yc.js');
 903              break;
 904              
 905          // MooTools 1.2 + More
 906          default:
 907              unset($GLOBALS['BE']['HEADER']['mootools.js']);
 908              $GLOBALS['BE']['HEADER']['mootools-1.2-core.js'] = getJavaScriptSourceLink(TEMPLATE_PATH.'lib/mootools/mootools-1.2-core-yc.js');
 909              
 910              if(is_array($more) && count($more)) {
 911                  array_unshift($more, 'Core/More');
 912                  foreach($more as $item) {
 913                      $name = 'mootools-more-'.$item;
 914                      if(empty($GLOBALS['BE']['HEADER'][$name]) && is_file(PHPWCMS_TEMPLATE.'lib/mootools/more/'.$item.'.js')) {
 915                          $GLOBALS['BE']['HEADER'][$name] = getJavaScriptSourceLink(TEMPLATE_PATH.'lib/mootools/more/'.$item.'.js');
 916                      }
 917                  }
 918              }
 919      }
 920      $GLOBALS['phpwcms']['mootools_mode'] = $mode;
 921  }
 922  function initMootoolsAutocompleter($mode='1.1') {
 923      initMootools($mode);
 924      $GLOBALS['BE']['HEADER']['Autocompleter.js']        = getJavaScriptSourceLink('include/inc_js/mootools/cnet/Autocompleter.js');
 925      $GLOBALS['BE']['HEADER']['Autocompleter.Remote.js']    = getJavaScriptSourceLink('include/inc_js/mootools/cnet/Autocompleter.Remote.js');
 926      $GLOBALS['BE']['HEADER']['Observer.js']                = getJavaScriptSourceLink('include/inc_js/mootools/cnet/Observer.js');
 927  }
 928  function initJsOptionSelect() {
 929      $GLOBALS['BE']['HEADER']['optionselect.js']    = getJavaScriptSourceLink('include/inc_js/optionselect.js');
 930  }
 931  function initMultipleUpload($mode='1.2') {
 932      switch($mode) {
 933          case '1.1':
 934              initMootools('1.1');
 935              $GLOBALS['BE']['HEADER']['Swiff.Base.js']        = getJavaScriptSourceLink('include/inc_js/mootools/FancyUpload/v1/Swiff.Base.js');
 936              $GLOBALS['BE']['HEADER']['Swiff.Uploader.js']    = getJavaScriptSourceLink('include/inc_js/mootools/FancyUpload/v1/Swiff.Uploader.js');
 937              $GLOBALS['BE']['HEADER']['FancyUpload.js']        = getJavaScriptSourceLink('include/inc_js/mootools/FancyUpload/v1/FancyUpload.js');
 938              break;
 939  
 940          default:
 941              initMootools('1.2');
 942              $GLOBALS['BE']['HEADER']['Swiff.Uploader.js']    = getJavaScriptSourceLink('include/inc_js/mootools/FancyUpload/Swiff.Uploader.js');
 943              $GLOBALS['BE']['HEADER']['FX.ProgressBar.js']    = getJavaScriptSourceLink('include/inc_js/mootools/FancyUpload/Fx.ProgressBar.js');
 944              $GLOBALS['BE']['HEADER']['FancyUpload2.js']        = getJavaScriptSourceLink('include/inc_js/mootools/FancyUpload/FancyUpload2.js');
 945      }
 946  }
 947  
 948  // make phpwcms compatibility and upgrade check
 949  function phpwcms_revision_check(&$revision) {
 950      $revision_temp = phpwcms_revision_check_temp($revision);
 951      if($revision_temp === NULL) {
 952          return false;
 953      } elseif($revision_temp) {
 954          return true;
 955      }
 956      $revision_file = PHPWCMS_ROOT.'/include/inc_lib/revision/r'.$revision.'.php';
 957      if(!is_file($revision_file)) {
 958          return false;
 959      }
 960      include_once($revision_file);
 961      $revision_function = 'phpwcms_revision_r'.$revision;
 962      if(function_exists($revision_function) && empty($GLOBALS['phpwcms']['check_r'.$revision])) {
 963          if( call_user_func($revision_function) !== false ) {
 964              $GLOBALS['phpwcms']['check_r'.$revision] = true;
 965              @write_textfile(PHPWCMS_TEMP.'r'.$revision.'.checked.tmp', date('Y-d-m H:i:s'));
 966              return true;
 967          }
 968      }
 969      return true;
 970  }
 971  
 972  // check upgrade temp file for current revision
 973  function phpwcms_revision_check_temp(&$revision) {
 974      if(empty($revision) || !preg_match('/^\d+$/', $revision)) {
 975          return NULL;
 976      }
 977      return is_file(PHPWCMS_TEMP.'r'.$revision.'.checked.tmp');
 978  }
 979  
 980  /*
 981   * Parse backend for language related BBCode [EN][/EN] or {EN}{/EN} unsing JavaScript
 982   * 
 983   * To enable backend language parser set config in conf.inc.php
 984   * $phpwcms['be_lang_parse'] = 'BBCode'; // to enable parsing for [EN][/EN]
 985   * $phpwcms['be_lang_parse'] = 'BraceCode'; // to enable parsing for {EN}{/EN}
 986   * $phpwcms['be_lang_parse'] = 'i18n'; // ToDo: to enable parsing for @@Default@@
 987   * $phpwcms['be_lang_parse'] = false; // to disable backend language parsing
 988   */ 
 989  function backend_language_parser() {
 990      
 991      global $phpwcms, $BE, $BL;
 992          
 993      
 994      if(!$phpwcms['be_parse_lang_process'] || empty($phpwcms['be_lang_parse'])) {
 995          
 996          return backend_language_replace('');
 997          
 998      } elseif(empty($phpwcms['allowed_lang']) || !is_array($phpwcms['allowed_lang']) || count($phpwcms['allowed_lang']) < 2) {
 999          
1000          return backend_language_replace('');
1001      
1002      } else {
1003          
1004          $parse_mode = strtoupper($phpwcms['be_lang_parse']);
1005          
1006          if(!in_array($parse_mode, array('BBCODE', 'BRACECODE'))) { // i18n later
1007              
1008              return backend_language_replace('');
1009      
1010          }
1011  
1012      }
1013      
1014      // cut main backend content innerHTML
1015      $html_pos1    = strpos($BE['HTML'], '<!--BE_MAIN_CONTENT_START//-->');
1016      $html_pos2    = strpos($BE['HTML'], '<!--BE_MAIN_CONTENT_END//-->');
1017      
1018      if($html_pos1 !== false && $html_pos2 !== false) {
1019      
1020          $html_pos1 += strlen('<!--BE_MAIN_CONTENT_START//-->');
1021          $html_pos2 -= 1;
1022          
1023      }
1024      
1025      $html        = trim( preg_replace('/\s+/', ' ', substr($BE['HTML'], $html_pos1, $html_pos2-$html_pos1) ) );
1026      $BE['HTML']    = substr($BE['HTML'], 0, $html_pos1) . substr($BE['HTML'], $html_pos2);
1027      
1028      // load MooTools too
1029      if(empty($phpwcms['mootools_mode'])) {
1030          initMootools();
1031      }
1032      
1033      // init language replacements
1034      $regexp     = array( 'search' => array(), 'replace' => array() );
1035      $bracket    = array('BBCODE_OPEN' => '[', 'BRACECODE_OPEN' => '{', 'BBCODE_CLOSE' => ']', 'BRACECODE_CLOSE' => '}');
1036      $cookie        = (empty($_COOKIE['phpwcms_be_parse_lang']) || !in_array($_COOKIE['phpwcms_be_parse_lang'], $phpwcms['allowed_lang'])) ? false : $_COOKIE['phpwcms_be_parse_lang'];
1037      
1038      // init menu
1039      $menu        = array(
1040          '<ul id="be_lang">',
1041          '<li class="be-lang-label chatlist">'.$BL['be_profile_label_lang'].':</li>',
1042          '<li><a href="#" class="be-disabled'.
1043              ($cookie === false ? ' be-active' : '').
1044              '" rel="disabled" title="'.
1045              $BL['be_profile_label_lang'].': '.$BL['be_off'].'">'.$BL['be_off'].'</a></li>'
1046      );
1047      
1048      // Header CSS section
1049      $BE['HEADER']['be_parse_lang']  = '    <style type="text/css">' . LF;
1050      
1051      // JavaScript section
1052      $BE['BODY_CLOSE']['hidden_main_content']  = '    <script type="text/javascript">' . LF;
1053      $BE['BODY_CLOSE']['hidden_main_content'] .= "        var be_lang_html = [];" . LF;
1054      $BE['BODY_CLOSE']['hidden_main_content'] .= "        var cur_be_lang = 'disabled';" . LF;
1055      $BE['BODY_CLOSE']['hidden_main_content'] .= "        be_lang_html['disabled'] = '" . trim(str_replace(array("\\", "'"), array("\\\\", "\\'"), $html)) . "';" . LF . LF;
1056      
1057      // build regular expression at first
1058      foreach($phpwcms['allowed_lang'] as $lang) {
1059          $regexp['search'][$lang]    = '/\\'.$bracket[$parse_mode.'_OPEN'].$lang.'\\'.$bracket[$parse_mode.'_CLOSE'].'(.*?)\\'.$bracket[$parse_mode.'_OPEN'].'\/'.$lang.'\\'.$bracket[$parse_mode.'_CLOSE'].'/is';
1060          $regexp['replace'][$lang]    = '';
1061      }
1062      // parse each language at second
1063      foreach($phpwcms['allowed_lang'] as $lang) {
1064          $replace        = $regexp['replace'];
1065          $replace[$lang]    = '$1';
1066          $lang_html        = preg_replace($regexp['search'], $replace, $html);
1067          
1068          $BE['HEADER']['be_parse_lang'] .= '    #be_lang a.be-lang-'.$lang.' {background-image:url(img/famfamfam/lang/'.$lang.'.png);}'.LF;
1069          
1070          
1071          $menu_item        = '<li><a href="#" class="be-lang be-lang-'.$lang;
1072          
1073          // check which is current default
1074          if($lang == $cookie) {
1075              $new_html = $lang_html;    // phpwcms should use the curent lang html
1076              $BE['BODY_CLOSE']['hidden_main_content'] .= "        cur_be_lang = '" . $lang . "';" . LF;
1077              $menu_item .= ' be-active';
1078          }
1079          
1080          $menu[] = $menu_item . '" rel="'.$lang.'" title="'.$BL['be_profile_label_lang'].': '.strtoupper($lang).'">'.$lang.'</a></li>';
1081  
1082          $BE['BODY_CLOSE']['hidden_main_content'] .= "        be_lang_html['".$lang."'] = '" . trim(str_replace(array("\\", "'"), array("\\\\", "\\'"), $lang_html)) . "';" . LF . LF;
1083      }
1084      
1085      $BE['HEADER']['be_parse_lang']             .= '    </style>';
1086      
1087      $BE['BODY_CLOSE']['hidden_main_content'] .= '    window.addEvent("domready", function() {' . LF;
1088      $BE['BODY_CLOSE']['hidden_main_content'] .= '        var be_lang = $("be_lang");' . LF;
1089      $BE['BODY_CLOSE']['hidden_main_content'] .= '        var be_lang_cnt = $("be_lang_cnt");' . LF;
1090      $BE['BODY_CLOSE']['hidden_main_content'] .= '        if(be_lang && be_lang_cnt) {' . LF;
1091      $BE['BODY_CLOSE']['hidden_main_content'] .= '            var be_lang_items = be_lang.getElements("a");' . LF;
1092      $BE['BODY_CLOSE']['hidden_main_content'] .= '            be_lang_items.each(function(l) {' . LF;
1093  
1094      $BE['BODY_CLOSE']['hidden_main_content'] .= '                l.addEvent("click", function(){' . LF;
1095      
1096      $BE['BODY_CLOSE']['hidden_main_content'] .= "                    if(cur_be_lang == l.rel) {return;}" . LF;
1097      
1098      $BE['BODY_CLOSE']['hidden_main_content'] .= "                    cur_be_lang = l.rel;" . LF;
1099      $BE['BODY_CLOSE']['hidden_main_content'] .= '                    be_lang_items.each(function(el){el.removeClass("be-active");});' . LF;
1100      $BE['BODY_CLOSE']['hidden_main_content'] .= '                    l.addClass("be-active");' . LF;
1101      $BE['BODY_CLOSE']['hidden_main_content'] .= '                    be_lang_cnt.setHTML(be_lang_html[l.rel]);' . LF;
1102      $BE['BODY_CLOSE']['hidden_main_content'] .= '                    Cookie.set("phpwcms_be_parse_lang", cur_be_lang);' . LF;
1103      
1104      $BE['BODY_CLOSE']['hidden_main_content'] .= '                });' . LF;
1105      $BE['BODY_CLOSE']['hidden_main_content'] .= '            });' . LF;
1106      $BE['BODY_CLOSE']['hidden_main_content'] .= '        }' . LF;
1107      $BE['BODY_CLOSE']['hidden_main_content'] .= '    });' . LF;
1108      $BE['BODY_CLOSE']['hidden_main_content'] .= '    </script>';
1109      
1110      $menu[] = '</ul>';
1111      
1112      // wrap current lang/html with <div>
1113      $BE['HTML']    = replace_tmpl_section('BE_MAIN_CONTENT', $BE['HTML'], '<div id="be_lang_cnt">' . (empty($new_html) ? $html : $new_html) . '</div>');
1114      
1115      backend_language_replace( implode(LF, $menu) );
1116      
1117  }
1118  
1119  function backend_language_replace($result) {
1120      
1121      $GLOBALS['BE']['HTML'] = str_replace('{BE_PARSE_LANG}', $result, $GLOBALS['BE']['HTML']);
1122      return NULL;
1123      
1124  }
1125  
1126  ?>


Generated: Tue Nov 16 22:51:00 2010 Cross-referenced by PHPXref 0.7