[ Index ]
 

Code source de XOOPS 2.0.17.1

Accédez au Source d'autres logiciels libres

title

Body

[fermer]

/htdocs/include/ -> functions.php (source)

   1  <?php
   2  // $Id: functions.php 1032 2007-09-09 13:01:16Z dugris $

   3  //  ------------------------------------------------------------------------ //

   4  //                XOOPS - PHP Content Management System                      //

   5  //                    Copyright (c) 2000 XOOPS.org                           //

   6  //                       <http://www.xoops.org/>                             //

   7  //  ------------------------------------------------------------------------ //

   8  //  This program is free software; you can redistribute it and/or modify     //

   9  //  it under the terms of the GNU General Public License as published by     //

  10  //  the Free Software Foundation; either version 2 of the License, or        //

  11  //  (at your option) any later version.                                      //

  12  //                                                                           //

  13  //  You may not change or alter any portion of this comment or credits       //

  14  //  of supporting developers from this source code or any supporting         //

  15  //  source code which is considered copyrighted (c) material of the          //

  16  //  original comment or credit authors.                                      //

  17  //                                                                           //

  18  //  This program is distributed in the hope that it will be useful,          //

  19  //  but WITHOUT ANY WARRANTY; without even the implied warranty of           //

  20  //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            //

  21  //  GNU General Public License for more details.                             //

  22  //                                                                           //

  23  //  You should have received a copy of the GNU General Public License        //

  24  //  along with this program; if not, write to the Free Software              //

  25  //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA //

  26  //  ------------------------------------------------------------------------ //

  27  
  28  // ################## Various functions from here ################

  29  
  30  function xoops_header($closehead=true)
  31  {
  32      global $xoopsConfig, $xoopsTheme, $xoopsConfigMetaFooter;
  33      $myts =& MyTextSanitizer::getInstance();
  34  
  35      if (!headers_sent()) {
  36          header('Content-Type:text/html; charset='._CHARSET);
  37          header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
  38          header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
  39          header('Cache-Control: no-store, no-cache, max-age=1, s-maxage=1, must-revalidate, post-check=0, pre-check=0');
  40          header("Pragma: no-cache");
  41      }
  42      echo "<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'>";
  43      echo '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="'._LANGCODE.'" lang="'._LANGCODE.'">
  44      <head>
  45      <meta http-equiv="content-type" content="text/html; charset='._CHARSET.'" />
  46      <meta http-equiv="content-language" content="'._LANGCODE.'" />
  47      <meta name="robots" content="'.htmlspecialchars($xoopsConfigMetaFooter['meta_robots']).'" />
  48      <meta name="keywords" content="'.htmlspecialchars($xoopsConfigMetaFooter['meta_keywords']).'" />
  49      <meta name="description" content="'.htmlspecialchars($xoopsConfigMetaFooter['meta_desc']).'" />
  50      <meta name="rating" content="'.htmlspecialchars($xoopsConfigMetaFooter['meta_rating']).'" />
  51      <meta name="author" content="'.htmlspecialchars($xoopsConfigMetaFooter['meta_author']).'" />
  52      <meta name="copyright" content="'.htmlspecialchars($xoopsConfigMetaFooter['meta_copyright']).'" />
  53      <meta name="generator" content="XOOPS" />
  54      <title>'.htmlspecialchars($xoopsConfig['sitename']).'</title>
  55      <script type="text/javascript" src="'.XOOPS_URL.'/include/xoops.js"></script>
  56      ';
  57      $themecss = getcss($xoopsConfig['theme_set']);
  58      echo '<link rel="stylesheet" type="text/css" media="all" href="'.XOOPS_URL.'/xoops.css" />';
  59      if ($themecss) {
  60          echo '<link rel="stylesheet" type="text/css" media="all" href="'.$themecss.'" />';
  61          //echo '<style type="text/css" media="all"><!-- @import url('.$themecss.'); --></style>';

  62      }
  63      if ($closehead) {
  64          echo '</head><body>';
  65      }
  66  }
  67  
  68  function xoops_footer()
  69  {
  70      echo '</body></html>';
  71      ob_end_flush();
  72  }
  73  
  74  function xoops_error($msg, $title='')
  75  {
  76      echo '
  77      <div class="errorMsg">';
  78      if ($title != '') {
  79          echo '<h4>'.$title.'</h4>';
  80      }
  81      if (is_array($msg)) {
  82          foreach ($msg as $m) {
  83              echo $m.'<br />';
  84          }
  85      } else {
  86          echo $msg;
  87      }
  88      echo '</div>';
  89  }
  90  
  91  function xoops_result($msg, $title='')
  92  {
  93      echo '
  94      <div class="resultMsg">';
  95      if ($title != '') {
  96          echo '<h4>'.$title.'</h4>';
  97      }
  98      if (is_array($msg)) {
  99          foreach ($msg as $m) {
 100              echo $m.'<br />';
 101          }
 102      } else {
 103          echo $msg;
 104      }
 105      echo '</div>';
 106  }
 107  
 108  function xoops_confirm($hiddens, $action, $msg, $submit='', $addtoken = true)
 109  {
 110      $submit = ($submit != '') ? trim($submit) : _SUBMIT;
 111      echo '
 112      <div class="confirmMsg">
 113        <h4>'.$msg.'</h4>
 114        <form method="post" action="'.$action.'">
 115      ';
 116      foreach ($hiddens as $name => $value) {
 117          if (is_array($value)) {
 118              foreach ($value as $caption => $newvalue) {
 119                  echo '<input type="radio" name="'.$name.'" value="'.htmlspecialchars($newvalue).'" /> '.$caption;
 120              }
 121              echo '<br />';
 122          } else {
 123              echo '<input type="hidden" name="'.$name.'" value="'.htmlspecialchars($value).'" />';
 124          }
 125      }
 126      if ($addtoken != false) {
 127          echo $GLOBALS['xoopsSecurity']->getTokenHTML();
 128      }
 129      echo '
 130          <input type="submit" name="confirm_submit" value="'.$submit.'" /> <input type="button" name="confirm_back" value="'._CANCEL.'" onclick="javascript:history.go(-1);" />
 131        </form>
 132      </div>
 133      ';
 134  }
 135  
 136  /**

 137  * Deprecated, use {@link XoopsSecurity} class instead

 138  **/
 139  function xoops_refcheck($docheck=1)
 140  {
 141      return $GLOBALS['xoopsSecurity']->checkReferer($docheck);
 142  }
 143  
 144  function xoops_getUserTimestamp($time, $timeoffset="")
 145  {
 146      global $xoopsConfig, $xoopsUser;
 147      if ($timeoffset == '') {
 148          if ($xoopsUser) {
 149              $timeoffset = $xoopsUser->getVar("timezone_offset");
 150          } else {
 151              $timeoffset = $xoopsConfig['default_TZ'];
 152          }
 153      }
 154      $usertimestamp = intval($time) + (floatval($timeoffset) - $xoopsConfig['server_TZ'])*3600;
 155      return $usertimestamp;
 156  }
 157  
 158  
 159  
 160  /*

 161   * Function to display formatted times in user timezone

 162   */
 163  function formatTimestamp($time, $format="l", $timeoffset="")
 164  {
 165      global $xoopsConfig, $xoopsUser;
 166      $usertimestamp = xoops_getUserTimestamp($time, $timeoffset);
 167      switch (strtolower($format)) {
 168      case 's':
 169          $datestring = _SHORTDATESTRING;
 170          break;
 171      case 'm':
 172          $datestring = _MEDIUMDATESTRING;
 173          break;
 174      case 'mysql':
 175          $datestring = "Y-m-d H:i:s";
 176          break;
 177      case 'rss':
 178          $datestring = "r";
 179          break;
 180      case 'l':
 181          $datestring = _DATESTRING;
 182          break;
 183      default:
 184          if ($format != '') {
 185              $datestring = $format;
 186          } else {
 187              $datestring = _DATESTRING;
 188          }
 189          break;
 190      }
 191      return ucfirst(date($datestring, $usertimestamp));
 192  }
 193  
 194  /*

 195   * Function to calculate server timestamp from user entered time (timestamp)

 196   */
 197  function userTimeToServerTime($timestamp, $userTZ=null)
 198  {
 199      global $xoopsConfig;
 200      if (!isset($userTZ)) {
 201          $userTZ = $xoopsConfig['default_TZ'];
 202      }
 203      $timestamp = $timestamp - (($userTZ - $xoopsConfig['server_TZ']) * 3600);
 204      return $timestamp;
 205  }
 206  
 207  function xoops_makepass() {
 208      $makepass = '';
 209      $syllables = array("er","in","tia","wol","fe","pre","vet","jo","nes","al","len","son","cha","ir","ler","bo","ok","tio","nar","sim","ple","bla","ten","toe","cho","co","lat","spe","ak","er","po","co","lor","pen","cil","li","ght","wh","at","the","he","ck","is","mam","bo","no","fi","ve","any","way","pol","iti","cs","ra","dio","sou","rce","sea","rch","pa","per","com","bo","sp","eak","st","fi","rst","gr","oup","boy","ea","gle","tr","ail","bi","ble","brb","pri","dee","kay","en","be","se");
 210      srand((double)microtime()*1000000);
 211      for ($count = 1; $count <= 4; $count++) {
 212          if (rand()%10 == 1) {
 213              $makepass .= sprintf("%0.0f",(rand()%50)+1);
 214          } else {
 215              $makepass .= sprintf("%s",$syllables[rand()%62]);
 216          }
 217      }
 218      return $makepass;
 219  }
 220  
 221  /*

 222   * Functions to display dhtml loading image box

 223   */
 224  function OpenWaitBox()
 225  {
 226      echo "<div id='waitDiv' style='position:absolute;left:40%;top:50%;visibility:hidden;text-align: center;'>
 227      <table cellpadding='6' border='2' class='bg2'>
 228        <tr>
 229          <td align='center'><b><big>" ._FETCHING."</big></b><br /><img src='".XOOPS_URL."/images/await.gif' alt='' /><br />" ._PLEASEWAIT."</td>
 230        </tr>
 231      </table>
 232      </div>
 233      <script type='text/javascript'>
 234      <!--//
 235      var DHTML = (document.getElementById || document.all || document.layers);
 236      function ap_getObj(name) {
 237          if (document.getElementById) {
 238              return document.getElementById(name).style;
 239          } else if (document.all) {
 240              return document.all[name].style;
 241          } else if (document.layers) {
 242              return document.layers[name];
 243          }
 244      }
 245      function ap_showWaitMessage(div,flag)  {
 246          if (!DHTML) {
 247              return;
 248          }
 249          var x = ap_getObj(div);
 250          x.visibility = (flag) ? 'visible' : 'hidden';
 251          if (!document.getElementById) {
 252              if (document.layers) {
 253                  x.left=280/2;
 254              }
 255          }
 256          return true;
 257      }
 258      ap_showWaitMessage('waitDiv', 1);
 259      //-->

 260      </script>";
 261  }
 262  
 263  function CloseWaitBox()
 264  {
 265      echo "<script type='text/javascript'>
 266      <!--//
 267      ap_showWaitMessage('waitDiv', 0);
 268      //-->

 269      </script>
 270      ";
 271  }
 272  
 273  function checkEmail($email,$antispam = false)
 274  {
 275      if (!$email || !preg_match("/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+([\.][a-z0-9-]+)+$/i",$email)){
 276          return false;
 277      }
 278      if ($antispam) {
 279          $email = str_replace("@", " at ", $email);
 280          $email = str_replace(".", " dot ", $email);
 281      }
 282      return $email;
 283  }
 284  
 285  function formatURL($url)
 286  {
 287      $url = trim($url);
 288      if ($url != '') {
 289          if ((!preg_match("/^http[s]*:\/\//i", $url)) && (!preg_match("/^ftp*:\/\//i", $url)) && (!preg_match("/^ed2k*:\/\//i", $url)) ) {
 290              $url = 'http://'.$url;
 291          }
 292      }
 293      return $url;
 294  }
 295  
 296  /*

 297   * Function to display banners in all pages

 298   */
 299  function showbanner()
 300  {
 301      echo xoops_getbanner();
 302  }
 303  
 304  /*

 305   * Function to get banner html tags for use in templates

 306   */
 307  function xoops_getbanner()
 308  {
 309      global $xoopsConfig;
 310      $db =& Database::getInstance();
 311      $bresult = $db->query("SELECT COUNT(*) FROM ".$db->prefix("banner"));
 312      list ($numrows) = $db->fetchRow($bresult);
 313      if ( $numrows > 1 ) {
 314          $numrows = $numrows-1;
 315          mt_srand((double)microtime()*1000000);
 316          $bannum = mt_rand(0, $numrows);
 317      } else {
 318          $bannum = 0;
 319      }
 320      if ( $numrows > 0 ) {
 321          $bresult = $db->query("SELECT * FROM ".$db->prefix("banner"), 1, $bannum);
 322          list ($bid, $cid, $imptotal, $impmade, $clicks, $imageurl, $clickurl, $date, $htmlbanner, $htmlcode) = $db->fetchRow($bresult);
 323          if ($xoopsConfig['my_ip'] == xoops_getenv('REMOTE_ADDR')) {
 324              // EMPTY

 325          } else {
 326              $db->queryF(sprintf("UPDATE %s SET impmade = impmade+1 WHERE bid = %u", $db->prefix("banner"), $bid));
 327          }
 328          /* Check if this impression is the last one and print the banner */

 329          if ( $imptotal == $impmade ) {
 330              $newid = $db->genId($db->prefix("bannerfinish")."_bid_seq");
 331              $sql = sprintf("INSERT INTO %s (bid, cid, impressions, clicks, datestart, dateend) VALUES (%u, %u, %u, %u, %u, %u)", $db->prefix("bannerfinish"), $newid, $cid, $impmade, $clicks, $date, time());
 332              $db->queryF($sql);
 333              $db->queryF(sprintf("DELETE FROM %s WHERE bid = %u", $db->prefix("banner"), $bid));
 334          }
 335          if ($htmlbanner){
 336              $bannerobject = $htmlcode;
 337          }else{
 338              $bannerobject = '<div><a href="'.XOOPS_URL.'/banners.php?op=click&amp;bid='.$bid.'" target="_blank">';
 339              if (stristr($imageurl, '.swf')) {
 340                  $bannerobject = $bannerobject
 341                      .'<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0" width="468" height="60">'
 342                      .'<param name="movie" value="'.$imageurl.'"></param>'
 343                      .'<param name="quality" value="high"></param>'
 344                      .'<embed src="'.$imageurl.'" quality="high" pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="468" height="60">'
 345                      .'</embed>'
 346                      .'</object>';
 347              } else {
 348                  $bannerobject = $bannerobject.'<img src="'.$imageurl.'" alt="" />';
 349              }
 350  
 351              $bannerobject = $bannerobject.'</a></div>';
 352          }
 353          return $bannerobject;
 354      }
 355  }
 356  
 357  /*

 358  * Function to redirect a user to certain pages

 359  */
 360  function redirect_header($url, $time = 3, $message = '', $addredirect = true)
 361  {
 362      global $xoopsConfig, $xoopsRequestUri, $xoopsLogger, $xoopsUserIsAdmin;
 363      if ( preg_match( "/[\\0-\\31]|about:|script:/i", $url) ) {
 364          if (!preg_match('/^\b(java)?script:([\s]*)history\.go\(-[0-9]*\)([\s]*[;]*[\s]*)$/si', $url) ) {
 365              $url = XOOPS_URL;
 366          }
 367      }
 368      if (defined('XOOPS_CPFUNC_LOADED')) {
 369          $theme = 'default';
 370      } else {
 371          $theme = $xoopsConfig['theme_set'];
 372      }
 373  
 374      require_once  XOOPS_ROOT_PATH . '/class/template.php';
 375      require_once  XOOPS_ROOT_PATH . '/class/theme.php';
 376  
 377      $xoopsThemeFactory =& new xos_opal_ThemeFactory();
 378      $xoopsThemeFactory->allowedThemes = $xoopsConfig['theme_set_allowed'];
 379      $xoopsThemeFactory->defaultTheme = $theme;
 380      $xoTheme =& $xoopsThemeFactory->createInstance(array("plugins" => array()));
 381      $xoopsTpl =& $xoTheme->template;
 382  
 383      $xoopsTpl->assign( array(
 384          'xoops_theme' => $theme,
 385          'xoops_imageurl' => XOOPS_THEME_URL.'/'.$theme.'/',
 386          'xoops_themecss'=> xoops_getcss($theme),
 387          'xoops_requesturi' => htmlspecialchars( $_SERVER['REQUEST_URI'], ENT_QUOTES),
 388          'xoops_sitename' => htmlspecialchars($xoopsConfig['sitename'], ENT_QUOTES),
 389          'xoops_slogan' => htmlspecialchars($xoopsConfig['slogan'], ENT_QUOTES),
 390          'xoops_dirname' => @$xoopsModule ? $xoopsModule->getVar( 'dirname' ) : 'system',
 391          'xoops_banner' => $xoopsConfig['banners'] ? xoops_getbanner() : '&nbsp;',
 392          'xoops_pagetitle' => isset($xoopsModule) && is_object($xoopsModule) ? $xoopsModule->getVar('name') : htmlspecialchars( $xoopsConfig['slogan'], ENT_QUOTES ),
 393      ) );
 394  
 395      if ($xoopsConfig['debug_mode'] == 2 && $xoopsUserIsAdmin) {
 396          $xoopsTpl->assign('time', 300);
 397          $xoopsTpl->assign('xoops_logdump', $xoopsLogger->dump());
 398      } else {
 399          $xoopsTpl->assign('time', intval($time));
 400      }
 401      if ($xoopsRequestUri && $addredirect && strstr($url, 'user.php')) {
 402          if (!strstr($url, '?')) {
 403              $url .= '?xoops_redirect='.urlencode($xoopsRequestUri);
 404          } else {
 405              $url .= '&amp;xoops_redirect='.urlencode($xoopsRequestUri);
 406          }
 407      }
 408      if (defined('SID') && SID && (! isset($_COOKIE[session_name()]) || ($xoopsConfig['use_mysession'] && $xoopsConfig['session_name'] != '' && !isset($_COOKIE[$xoopsConfig['session_name']])))) {
 409          if (!strstr($url, '?')) {
 410              $url .= '?' . SID;
 411          } else {
 412              $url .= '&amp;'.SID;
 413          }
 414      }
 415      $url = preg_replace("/&amp;/i", '&', htmlspecialchars($url, ENT_QUOTES));
 416      $xoopsTpl->assign('url', $url);
 417      $message = trim($message) != '' ? $message : _TAKINGBACK;
 418      $xoopsTpl->assign('message', $message);
 419      $xoopsTpl->assign('lang_ifnotreload', sprintf(_IFNOTRELOAD, $url));
 420      $xoopsTpl->display('db:system_redirect.html');
 421      exit();
 422  }
 423  
 424  function xoops_getenv($key)
 425  {
 426      $ret = '';
 427      //$phpv = explode(".", PHP_VERSION);

 428      //if ($phpv[0] > 3 && $phpv[1] > 0) {

 429      //  $ret = isset($_SERVER[$key]) ? $_SERVER[$key] : $_ENV[$key];

 430      //} else {

 431          $ret = isset($_SERVER[$key]) ? $_SERVER[$key] : $_ENV[$key];
 432      //}

 433      return $ret;
 434  }
 435  
 436  /*

 437   * This function is deprecated. Do not use!

 438   */
 439  function getTheme()
 440  {
 441      return $GLOBALS['xoopsConfig']['theme_set'];
 442  }
 443  
 444  /*

 445   * Function to get css file for a certain theme

 446   * This function will be deprecated.

 447   */
 448  function getcss($theme = '')
 449  {
 450      return xoops_getcss($theme);
 451  }
 452  
 453  /*

 454   * Function to get css file for a certain themeset

 455   */
 456  function xoops_getcss($theme = '')
 457  {
 458      if ($theme == '') {
 459          $theme = $GLOBALS['xoopsConfig']['theme_set'];
 460      }
 461      $uagent = xoops_getenv('HTTP_USER_AGENT');
 462      if (stristr($uagent, 'mac')) {
 463          $str_css = 'styleMAC.css';
 464      } elseif (preg_match("/MSIE ([0-9]\.[0-9]{1,2})/i", $uagent)) {
 465          $str_css = 'style.css';
 466      } else {
 467          $str_css = 'styleNN.css';
 468      }
 469      if (is_dir(XOOPS_THEME_PATH.'/'.$theme)) {
 470          if (file_exists(XOOPS_THEME_PATH.'/'.$theme.'/'.$str_css)) {
 471              return XOOPS_THEME_URL.'/'.$theme.'/'.$str_css;
 472          } elseif (file_exists(XOOPS_THEME_PATH.'/'.$theme.'/style.css')) {
 473              return XOOPS_THEME_URL.'/'.$theme.'/style.css';
 474          }
 475      }
 476      if (is_dir(XOOPS_THEME_PATH.'/'.$theme . '/css')) {
 477          if (file_exists(XOOPS_THEME_PATH.'/'.$theme.'/css/'.$str_css)) {
 478              return XOOPS_THEME_URL.'/'.$theme.'/css/'.$str_css;
 479          } elseif (file_exists(XOOPS_THEME_PATH.'/'.$theme.'/css/style.css')) {
 480              return XOOPS_THEME_URL.'/'.$theme.'/css/style.css';
 481          }
 482      }
 483      return '';
 484  }
 485  
 486  function &getMailer()
 487  {
 488      global $xoopsConfig;
 489      $inst = false;
 490      include_once XOOPS_ROOT_PATH."/class/xoopsmailer.php";
 491      if ( file_exists(XOOPS_ROOT_PATH."/language/".$xoopsConfig['language']."/xoopsmailerlocal.php") ) {
 492          include_once XOOPS_ROOT_PATH."/language/".$xoopsConfig['language']."/xoopsmailerlocal.php";
 493          if ( class_exists("XoopsMailerLocal") ) {
 494              $inst =& new XoopsMailerLocal();
 495          }
 496      }
 497      if ( !$inst ) {
 498          $inst =& new XoopsMailer();
 499      }
 500      return $inst;
 501  }
 502  
 503  function &xoops_gethandler($name, $optional = false )
 504  {
 505      static $handlers;
 506      $name = strtolower(trim($name));
 507      if (!isset($handlers[$name])) {
 508          if ( file_exists( $hnd_file = XOOPS_ROOT_PATH.'/kernel/'.$name.'.php' ) ) {
 509              require_once $hnd_file;
 510          }
 511          $class = 'Xoops'.ucfirst($name).'Handler';
 512          if (class_exists($class)) {
 513              $handlers[$name] =& new $class($GLOBALS['xoopsDB']);
 514          }
 515      }
 516      if (!isset($handlers[$name]) && !$optional ) {
 517          trigger_error('Class <b>'.$class.'</b> does not exist<br />Handler Name: '.$name, E_USER_ERROR);
 518      }
 519      if ( isset($handlers[$name]) ) {
 520          return $handlers[$name];
 521      }
 522      $inst = false;
 523      return $inst;
 524  }
 525  
 526  function &xoops_getmodulehandler($name = null, $module_dir = null, $optional = false)
 527  {
 528      static $handlers;
 529      // if $module_dir is not specified

 530      if (!isset($module_dir)) {
 531          //if a module is loaded

 532          if (isset($GLOBALS['xoopsModule']) && is_object($GLOBALS['xoopsModule'])) {
 533              $module_dir = $GLOBALS['xoopsModule']->getVar('dirname');
 534          } else {
 535              trigger_error('No Module is loaded', E_USER_ERROR);
 536          }
 537      } else {
 538          $module_dir = trim($module_dir);
 539      }
 540      $name = (!isset($name)) ? $module_dir : trim($name);
 541      if (!isset($handlers[$module_dir][$name])) {
 542          if ( file_exists( $hnd_file = XOOPS_ROOT_PATH . "/modules/{$module_dir}/class/{$name}.php" ) ) {
 543              include_once $hnd_file;
 544          }
 545          $class = ucfirst(strtolower($module_dir)).ucfirst($name).'Handler';
 546          if (class_exists($class)) {
 547              $handlers[$module_dir][$name] =& new $class($GLOBALS['xoopsDB']);
 548          }
 549      }
 550      if (!isset($handlers[$module_dir][$name]) && !$optional) {
 551          trigger_error('Handler does not exist<br />Module: '.$module_dir.'<br />Name: '.$name, E_USER_ERROR);
 552      }
 553      if ( isset($handlers[$module_dir][$name]) ) {
 554          return $handlers[$module_dir][$name];
 555      }
 556      $inst = false;
 557      return $inst;
 558  
 559  }
 560  
 561  function xoops_getrank($rank_id =0, $posts = 0)
 562  {
 563      $db =& Database::getInstance();
 564      $myts =& MyTextSanitizer::getInstance();
 565      $rank_id = intval($rank_id);
 566      if ($rank_id != 0) {
 567          $sql = "SELECT rank_title AS title, rank_image AS image FROM ".$db->prefix('ranks')." WHERE rank_id = ".$rank_id;
 568      } else {
 569          $sql = "SELECT rank_title AS title, rank_image AS image FROM ".$db->prefix('ranks')." WHERE rank_min <= ".$posts." AND rank_max >= ".$posts." AND rank_special = 0";
 570      }
 571      $rank = $db->fetchArray($db->query($sql));
 572      $rank['title'] = $myts->makeTboxData4Show($rank['title']);
 573      $rank['id'] = $rank_id;
 574      return $rank;
 575  }
 576  
 577  
 578  /**

 579  * Returns the portion of string specified by the start and length parameters. If $trimmarker is supplied, it is appended to the return string. This function works fine with multi-byte characters if mb_* functions exist on the server.

 580  *

 581  * @param    string    $str

 582  * @param    int       $start

 583  * @param    int       $length

 584  * @param    string    $trimmarker

 585  *

 586  * @return   string

 587  */
 588  function xoops_substr($str, $start, $length, $trimmarker = '...')
 589  {
 590      if ( !XOOPS_USE_MULTIBYTES ) {
 591          return ( strlen($str) - $start <= $length ) ? substr( $str, $start, $length ) : substr( $str, $start, $length - strlen($trimmarker) ) . $trimmarker;
 592      }
 593      if (function_exists('mb_internal_encoding') && @mb_internal_encoding(_CHARSET)) {
 594          $str2 = mb_strcut( $str , $start , $length - strlen( $trimmarker ) );
 595          return $str2 . ( mb_strlen($str)!=mb_strlen($str2) ? $trimmarker : '' );
 596      }
 597      // phppp patch

 598      $DEP_CHAR=127;
 599      $pos_st=0;
 600      $action = false;
 601      for ( $pos_i = 0; $pos_i < strlen($str); $pos_i++ ) {
 602          if ( ord( substr( $str, $pos_i, 1) ) > 127 ) {
 603              $pos_i++;
 604          }
 605          if ($pos_i<=$start) {
 606              $pos_st=$pos_i;
 607          }
 608          if ($pos_i>=$pos_st+$length) {
 609              $action = true;
 610              break;
 611          }
 612      }
 613      return ($action) ? substr( $str, $pos_st, $pos_i - $pos_st - strlen($trimmarker) ) . $trimmarker : $str;
 614  }
 615  
 616  // RMV-NOTIFY

 617  // ################ Notification Helper Functions ##################

 618  
 619  // We want to be able to delete by module, by user, or by item.

 620  // How do we specify this??

 621  
 622  function xoops_notification_deletebymodule ($module_id)
 623  {
 624      $notification_handler =& xoops_gethandler('notification');
 625      return $notification_handler->unsubscribeByModule ($module_id);
 626  }
 627  
 628  function xoops_notification_deletebyuser ($user_id)
 629  {
 630      $notification_handler =& xoops_gethandler('notification');
 631      return $notification_handler->unsubscribeByUser ($user_id);
 632  }
 633  
 634  function xoops_notification_deletebyitem ($module_id, $category, $item_id)
 635  {
 636      $notification_handler =& xoops_gethandler('notification');
 637      return $notification_handler->unsubscribeByItem ($module_id, $category, $item_id);
 638  }
 639  
 640  // ################### Comment helper functions ####################

 641  
 642  function xoops_comment_count($module_id, $item_id = null)
 643  {
 644      $comment_handler =& xoops_gethandler('comment');
 645      $criteria = new CriteriaCompo(new Criteria('com_modid', intval($module_id)));
 646      if (isset($item_id)) {
 647          $criteria->add(new Criteria('com_itemid', intval($item_id)));
 648      }
 649      return $comment_handler->getCount($criteria);
 650  }
 651  
 652  function xoops_comment_delete($module_id, $item_id)
 653  {
 654      if (intval($module_id) > 0 && intval($item_id) > 0) {
 655          $comment_handler =& xoops_gethandler('comment');
 656          $comments =& $comment_handler->getByItemId($module_id, $item_id);
 657          if (is_array($comments)) {
 658              $count = count($comments);
 659              $deleted_num = array();
 660              for ($i = 0; $i < $count; $i++) {
 661                  if (false != $comment_handler->delete($comments[$i])) {
 662                      // store poster ID and deleted post number into array for later use

 663                      $poster_id = $comments[$i]->getVar('com_uid');
 664                      if ($poster_id != 0) {
 665                          $deleted_num[$poster_id] = !isset($deleted_num[$poster_id]) ? 1 : ($deleted_num[$poster_id] + 1);
 666                      }
 667                  }
 668              }
 669              $member_handler =& xoops_gethandler('member');
 670              foreach ($deleted_num as $user_id => $post_num) {
 671                  // update user posts

 672                  $com_poster = $member_handler->getUser($user_id);
 673                  if (is_object($com_poster)) {
 674                      $member_handler->updateUserByField($com_poster, 'posts', $com_poster->getVar('posts') - $post_num);
 675                  }
 676              }
 677              return true;
 678          }
 679      }
 680      return false;
 681  }
 682  
 683  // ################ Group Permission Helper Functions ##################

 684  
 685  function xoops_groupperm_deletebymoditem($module_id, $perm_name, $item_id = null)
 686  {
 687      // do not allow system permissions to be deleted

 688      if (intval($module_id) <= 1) {
 689          return false;
 690      }
 691      $gperm_handler =& xoops_gethandler('groupperm');
 692      return $gperm_handler->deleteByModule($module_id, $perm_name, $item_id);
 693  }
 694  
 695  function xoops_utf8_encode(&$text)
 696  {
 697      if (XOOPS_USE_MULTIBYTES == 1) {
 698          if (function_exists('mb_convert_encoding')) {
 699              return mb_convert_encoding($text, 'UTF-8', 'auto');
 700          }
 701          return $text;
 702      }
 703      return utf8_encode($text);
 704  }
 705  
 706  function xoops_convert_encoding(&$text)
 707  {
 708      return xoops_utf8_encode($text);
 709  }
 710  
 711  function xoops_getLinkedUnameFromId($userid)
 712  {
 713      $userid = intval($userid);
 714      if ($userid > 0) {
 715          $member_handler =& xoops_gethandler('member');
 716          $user =& $member_handler->getUser($userid);
 717          if (is_object($user)) {
 718              $linkeduser = '<a href="'.XOOPS_URL.'/userinfo.php?uid='.$userid.'">'. $user->getVar('uname').'</a>';
 719              return $linkeduser;
 720          }
 721      }
 722      return $GLOBALS['xoopsConfig']['anonymous'];
 723  }
 724  
 725  function xoops_trim($text)
 726  {
 727      if (function_exists('xoops_language_trim')) {
 728          return xoops_language_trim($text);
 729      }
 730      return trim($text);
 731  }
 732  ?>


Généré le : Sun Nov 25 11:44:32 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics