[ Index ]

PHP Cross Reference of Mambo 4.6.5

[ Variables ]     [ Functions ]     [ Classes ]     [ Constants ]     [ Statistics ]

title

Body

[close]

/includes/ -> core.helpers.php (source)

   1  <?php
   2  /**
   3  * @package Mambo
   4  * @author Mambo Foundation Inc see README.php
   5  * @copyright (C) 2000 - 2009 Mambo Foundation Inc.
   6  * See COPYRIGHT.php for copyright notices and details.
   7  * @license GNU/GPL Version 2, see LICENSE.php
   8  *
   9  * Redistributions of files must retain the above copyright notice.
  10  *
  11  * Mambo is free software; you can redistribute it and/or
  12  * modify it under the terms of the GNU General Public License
  13  * as published by the Free Software Foundation; version 2 of the License.
  14  */
  15  
  16  class mosHtmlHelper {
  17      var $doctype = 'XHTML 1.0 Transitional';
  18      var $charset = 'utf-8';
  19      var $useXmlPrologue = false;
  20      var $_tags = array(
  21              'title' => '<title>%s</title>',
  22              'meta' => '<meta name="%s" content="%s" />',
  23              'metalink' => '<link href="%s" title="%s"%s />',
  24              'metalinkrel' => '<link rel="%s" href="%s" />',
  25              'charset' => '<meta http-equiv="Content-Type" content="text/html; charset=%s" />',
  26              'css' => '<link href="%s" rel="stylesheet" type="text/css"%s />',
  27              'javascript' => '<script type="text/javascript"%s>%s</script>',
  28              'xmlprologue' => '<?xml version="1.0" encoding="%s"?>',
  29              'base' => '<base href="%s/" />'
  30          );
  31      var $_docTypes = array(
  32          'XHTML 1.0 Strict' => '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">',
  33          'XHTML 1.0 Transitional' => '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">',
  34          'XHTML 1.0 Frameset' => '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">',
  35          'XHTML 1.1' => '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">',
  36          'XHTML Mobile 1.0' => '<!DOCTYPE html PUBLIC "-//WAPFORUM//DTD XHTML Mobile 1.0//EN" "http://www.wapforum.org/DTD/xhtml-mobile10.dtd">',
  37          'XHTML Mobile 1.1' => '<!DOCTYPE html PUBLIC "-//WAPFORUM//DTD XHTML Mobile 1.1//EN" "http://www.openmobilealliance.org/tech/DTD/xh tml-mobile11.dtd">',
  38          'XHTML Mobile 1.2' => '<!DOCTYPE html PUBLIC "-//WAPFORUM//DTD XHTML Mobile 1.2//EN" "http://www.openmobilealliance.org/tech/DTD/xh tml-mobile11.dtd">',
  39          'XHTML Basic 1.0' => '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML Basic 1.0//EN" "http://www.w3.org/TR/xhtml-basic/xhtml-basic10.dtd">',
  40          'XHTML Basic 1.1' => '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML Basic 1.1//EN" "http://www.w3.org/TR/xhtml-basic/xhtml-basic11.dtd">'
  41      );
  42      var $_docTypesMobile = array(
  43          'XHTML Mobile 1.0',
  44          'XHTML Mobile 1.1',
  45          'XHTML Mobile 1.2',
  46          'XHTML Basic 1.0',
  47          'XHTML Basic 1.1'
  48      );
  49      var $_headTags = array();
  50  
  51      /**
  52      * Singleton accessor
  53      */
  54      function &getInstance () {
  55          static $instance;
  56          if ( !is_object($instance) ) {
  57              $instance = new mosHtmlHelper();
  58              $lang = mamboCore::get('current_language');
  59              $instance->charset = $lang->charset;
  60              if ( mamboCore::is_set('mosConfig_doctype') ) {
  61                  $instance->doctype = mamboCore::get('mosConfig_doctype');
  62              }
  63              $instance->loadHeadTags();
  64          }
  65          return $instance;
  66      }
  67      /**
  68       * Get method
  69       *
  70       * @param unknown_type $var
  71       * @return unknown
  72       */
  73  	function doctypeIsMobile($key='') {
  74          static $obj;
  75          if ( !is_object($obj) ) $obj =& mosHtmlHelper::getInstance();
  76          if ( trim($key) == '' ) $key = $obj->doctype;
  77          if ( in_array($key, $obj->_docTypesMobile) ) return true;
  78  
  79          return false;
  80      }
  81      /**
  82       * Get method
  83       *
  84       * @param unknown_type $var
  85       * @return unknown
  86       */
  87  	function get($var) {
  88          $var = trim($var);
  89          if ( !$var ) return null;
  90  
  91          static $obj;
  92          if ( !is_object($obj) ) $obj =& mosHtmlHelper::getInstance();
  93          
  94          if( isset($obj->$var) ) return $obj->$var;
  95          return null;
  96      }
  97      /**
  98       * Set method - set public properties. Does not set a property that does not already exist
  99       *
 100       * @param unknown_type $property - the property to set
 101       * @param unknown_type $value - the value to set the property to
 102       */
 103  	function set($property, $value) {
 104          $property = trim($property);
 105          if ( !$property ) return;
 106          if( $property{0} == '_' ) return; // dont set private properties
 107  
 108          static $obj;
 109          if ( !is_object($obj) ) $obj =& mosHtmlHelper::getInstance();
 110  
 111          if ( isset($obj->$property) ) $obj->$property = $value;
 112      }
 113      /**
 114       * Set method - set public properties. Does not set a property that does not already exist
 115       *
 116       * @param unknown_type $property - the property to set
 117       * @param unknown_type $value - the value to set the property to
 118       */
 119  	function useXmlPrologue($flag=null) {
 120          static $obj;
 121          if ( !is_object($obj) ) $obj =& mosHtmlHelper::getInstance();
 122  
 123          if ( $flag === true && $flag === false ) $obj->useXmlProlugue = $flag;
 124          return $obj->useXmlPrologue;
 125      }
 126      /**
 127       * Generic tag construction
 128       *
 129       * @param string $key - should be a key in the _tags property list
 130       * @param unknown $vars - a string or array of strings
 131       * @return formatted html
 132       */
 133  	function tag($key, $vars=array()) {
 134          $key = trim($key);
 135          if ( !$key ) return null;
 136          if ( is_array($vars) )
 137              if ( !count($vars) ) return null;
 138          if ( !is_array($vars) && trim($vars) == '' ) return null;
 139  
 140          static $obj;
 141          if ( !is_object($obj) ) $obj =& mosHtmlHelper::getInstance();
 142  
 143          if ( !isset($obj->_tags[$key]) ) return null;
 144          if ( !is_array($vars) ) $vars = array($vars);
 145          
 146          $countVars = count($vars);
 147          $countTagVars = substr_count($obj->_tags[$key], '%s');
 148          // make sure we pass at least n vars
 149          for ($i=$countVars; $i<$countTagVars; $i++) {
 150              $vars[] = '';
 151          }
 152          // make sure we pass no more than n vars
 153          for ($i=$countVars; $i>$countTagVars-1; $i--) {
 154              unset($vars[$i]);
 155          }
 156          return vsprintf($obj->_tags[$key], $vars);
 157      }
 158      /**
 159       * Render output
 160       *   Default is to render output wrapped by $prepend/$postpend. Default value of postpend is \n.
 161       *   A case statement calls various public rendering functions
 162       *
 163       * @param string $string
 164       * @param string $postpend
 165       * @param string $prepend
 166       */
 167  	function render($string, $prepend=null, $postpend="\n") {
 168          switch($string) {
 169              case 'head':
 170                  mosHtmlHelper::showHead();
 171                  break;
 172              case 'doctype':
 173                  mosHtmlHelper::renderDoctype();
 174                  break;
 175              case 'title':
 176                  mosHtmlHelper::renderTitle();
 177                  break;
 178              case 'charset':
 179                  mosHtmlHelper::renderCharset();
 180                  break;
 181              case 'css':
 182                  mosHtmlHelper::renderCss();
 183                  break;
 184              case 'javascript':
 185                  mosHtmlHelper::renderJavascript();
 186                  break;
 187              case 'meta':
 188                  mosHtmlHelper::showMeta();
 189                  break;
 190              case 'xmlprologue':
 191                  mosHtmlHelper::renderXmlPrologue();
 192                  break;
 193              case 'base':
 194                  mosHtmlHelper::renderBase();
 195                  break;
 196              default:
 197                  echo $prepend.$string.$postpend;
 198                  break;
 199          }
 200      }
 201      /**
 202       * Render DTD
 203       *
 204       * @param string $type - doctype
 205       */
 206  	function renderDocType($type='') {
 207          static $obj;
 208          if ( !is_object($obj) ) $obj =& mosHtmlHelper::getInstance();
 209          
 210          $type = trim($type);
 211          if ( $type && array_key_exists($type, $obj->_docTypes) )
 212              $obj->render($obj->_docTypes[$type]);
 213          else
 214              $obj->render($obj->_docTypes[$obj->doctype]);
 215      }
 216      /**
 217       * Render xml prologue
 218       *
 219       * @param string $charset - the character set for the prologue
 220       * @param string $force - render prologue even if class property userXmlPrologue is false
 221       */
 222  	function renderXmlPrologue($charset='', $force=false) {
 223          static $obj;
 224          if ( !is_object($obj) ) $obj =& mosHtmlHelper::getInstance();
 225          if ( $obj->doctypeIsMobile() ) $obj->set('useXmlPrologue', true);
 226          
 227          $charset = trim($charset);
 228          $charset = $charset !== '' ? $charset : $obj->charset;
 229          if ( $obj->useXmlPrologue !== false || ($force === true) )
 230              $obj->render($obj->tag('xmlprologue', $charset));
 231      }
 232      /**
 233       * Render title tag
 234       *
 235       * @param string $title - page title
 236       */
 237  	function renderTitle($title='') {
 238          static $obj;
 239          if ( !is_object($obj) ) $obj =& mosHtmlHelper::getInstance();
 240          
 241          static $mainframe;
 242          if ( !is_object($mainframe) ) $mainframe =& mosMainFrame::getInstance();
 243          
 244          $title = trim($title);
 245          $title = $title !== '' ? $title : $mainframe->_head['title'];
 246          $obj->render($obj->tag('title', $title));
 247      }
 248      /**
 249       * Render meta tag
 250       */
 251  	function renderMeta($name='', $content='') {
 252          $name = trim($name);
 253          $content = trim($content);
 254          if ( !$name || !$content ) return;
 255  
 256          static $obj;
 257          if ( !is_object($obj) ) $obj =& mosHtmlHelper::getInstance();
 258  
 259          $obj->render($obj->tag('meta', array($name, $content)));
 260      }
 261      /**
 262       * Render meta link href tag
 263       */
 264  	function renderMetaLink($href='', $title='', $extra='') {
 265          $href = trim($href);
 266          $title = trim($title);
 267          if ( !$href || !$title ) return;
 268          
 269          static $obj;
 270          if ( !is_object($obj) ) $obj =& mosHtmlHelper::getInstance();
 271  
 272          $extra = (trim($extra) !== '') ? " $extra" : '';
 273          $obj->render($obj->tag('metalink', array($href, $title, $extra)));
 274      }
 275      /**
 276       * Render meta link rel tag
 277       */
 278  	function renderMetaLinkRel($rel='', $href='') {
 279          $rel = trim($rel);
 280          $href = trim($href);
 281          if ( !$rel || !$href ) return;
 282          
 283          static $obj;
 284          if ( !is_object($obj) ) $obj =& mosHtmlHelper::getInstance();
 285  
 286          $obj->render($obj->tag('metalinkrel', array($rel, $href)));
 287      }
 288      /**
 289       * Render character set meta tag
 290       *
 291       * @param string $charset - character set
 292       */
 293  	function renderCharset($charset='') {
 294          static $obj;
 295          if ( !is_object($obj) ) $obj =& mosHtmlHelper::getInstance();
 296          
 297          $charset = trim($charset);
 298          $charset = $charset !== '' ? $charset : $obj->get('charset');
 299          $obj->render($obj->tag('charset', $charset));
 300      }
 301      /**
 302       * Render css link tag
 303       *
 304       * @param string $path - css file path. Default is template_css.css in the current template folder
 305       */
 306  	function renderCss($filepath='', $media='') {
 307          static $obj;
 308          if ( !is_object($obj) ) $obj =& mosHtmlHelper::getInstance();
 309          
 310          $filepath = trim($filepath);
 311          $media = trim($media);
 312          $media = $media !== '' ? " media=\"$media\"" : '';
 313          $mainframe =& mosMainframe::getInstance();
 314  
 315          if ( $filepath == '' && $media == '' ) {
 316              $file = mosPath(mamboCore::get('mosConfig_absolute_path').'/templates/'.$mainframe->getTemplate().'/css/template_css.css');
 317              if ( file_exists($file) ) {
 318                  $filepath = mamboCore::get('mosConfig_live_site').'/templates/'.$mainframe->getTemplate().'/css/template_css.css';
 319                  $obj->render($obj->tag('css', array($filepath)));
 320              }
 321              $file = mosPath(mamboCore::get('mosConfig_absolute_path').'/templates/'.$mainframe->getTemplate().'/css/print.css');
 322              if ( file_exists($file) ) {
 323                  $filepath = mamboCore::get('mosConfig_live_site').'/templates/'.$mainframe->getTemplate().'/css/print.css';
 324                  $obj->render($obj->tag('css', array($filepath, ' media="print"')));
 325              }
 326              return;
 327          }
 328          if ( $filepath == '' ) {
 329              $filepath = mamboCore::get('mosConfig_live_site').'/templates/'.$mainframe->getTemplate().'/css/template_css.css';
 330          }
 331          $obj->render($obj->tag('css', array($filepath, $media)));
 332      }
 333      /**
 334       * Render Javascript tags
 335       */
 336  	function renderJavascript($link='', $code='') {
 337          static $obj;
 338          if ( !is_object($obj) ) $obj =& mosHtmlHelper::getInstance();
 339          
 340          if ( strlen(trim($code)) !== 0 ) {
 341              $obj->render($obj->tag('javascript', array('', "\n$code\n")));
 342          } else {
 343              $link = trim($link);
 344              if ( $link ) {
 345                  $obj->render($obj->tag('javascript', " src=\"$link\""));
 346              } else {
 347                  $my = mamboCore::get('currentUser');
 348                  $obj->_headTags['mambojavascript'] = $my->id ? $obj->tag('javascript', ' src="'. mamboCore::get('mosConfig_live_site')."/includes/js/mambojavascript.js\"") : '';
 349                  if ( $obj->_headTags['mambojavascript'] !== '' )
 350                      $obj->render($obj->_headTags['mambojavascript']);
 351              }
 352          }
 353      }
 354      /**
 355       * Render base tag
 356       *
 357       * @param string $url - base url
 358       */
 359  	function renderBase($url='') {
 360          static $obj;
 361          if ( !is_object($obj) ) $obj =& mosHtmlHelper::getInstance();
 362          
 363          $obj->render($obj->tag('base', mamboCore::get('mosConfig_live_site')));
 364      }
 365      /**
 366       * Load Mambo generated head tags into an array
 367       */
 368  	function loadHeadTags() {
 369          static $obj;
 370          if ( !is_object($obj) ) $obj =& mosHtmlHelper::getInstance();
 371  
 372          $mainframe =& mosMainFrame::getInstance();
 373          $obj->_headTags = array();
 374          $mainframe->appendMetaTag( 'description', mamboCore::get('mosConfig_MetaDesc'), true );
 375          $mainframe->appendMetaTag( 'keywords', mamboCore::get('mosConfig_MetaKeys'), true );
 376  
 377          $title = $mainframe->_head['title'];
 378          $obj->_headTags['title'] = $obj->tag('title', $title);
 379  
 380          $obj->_headTags['meta'] = array();
 381          foreach ($mainframe->_head['meta'] as $name=>$meta) {
 382              if ( $meta[1] ) $obj->_headTags['meta'][] = $meta[1];
 383              $obj->_headTags['meta'][$name] = $obj->tag('meta', array($name, $meta[0]));
 384              if ( $meta[2] ) $obj->_headTags['meta'][] = $meta[2];
 385          }
 386  
 387          $my =& mamboCore::get('currentUser');
 388          $obj->_headTags['mambojavascript'] = $my->id ? $obj->tag('javascript', ' src="'.mamboCore::get('mosConfig_live_site')."/includes/js/mambojavascript.js\"") : '';
 389          $obj->_headTags['base'] = mamboCore::get('mosConfig_sef') ? $obj->tag('base', mamboCore::get('mosConfig_live_site')) : '';
 390          $obj->_headTags['custom'] = array();
 391          foreach ($mainframe->_head['custom'] as $html)
 392              if ( trim($html) !== '' )
 393                  $obj->_headTags['custom'][] = $html;
 394  
 395          ob_start();
 396             $mainframe->liveBookMark();
 397          $obj->_headTags['livebookmark'] = trim(ob_get_contents());
 398          ob_end_clean();
 399  
 400          $configuration =& mamboCore::getMamboCore();
 401          $obj->_headTags['favicon'] = $obj->tag('metalinkrel', array("shortcut icon", $configuration->getFavIcon()));
 402      }
 403  
 404      /**
 405       * Render Mambo generated head tags.
 406       *
 407       * @param string $keys - a key or array of keys in the head tag array to render
 408       * @param string $exclue - a key or array of keys in the head tag array to exclude
 409       */
 410      function showHead($keys='', $exclude='') {
 411          if ( !is_array($keys) )
 412              if ( $keys !== '' && !is_null($keys) )
 413                  $keys = array($keys);
 414              else $keys = array();
 415          if ( !is_array($exclude) )
 416              if ( $exclude !== '' )
 417                  $exclude = array($exclude);
 418              else $exclude = array();
 419  
 420          static $obj;
 421          if ( !is_object($obj) ) $obj =& mosHtmlHelper::getInstance();
 422          if ( count($obj->_headTags) == 0 ) $obj->loadHeadTags();
 423          
 424          if ( count($keys) == 0 ) {
 425              foreach($obj->_headTags as $key=>$value) {
 426                  if ( !in_array($key, $exclude) ) {
 427                      if ( is_array($value) ) {
 428                          foreach ($value as $key2=>$value2)
 429                              if (isset($value2))
 430                                  if ( $value2 !== '' ) $obj->render($value2);
 431                      } else {
 432                          if (isset($value))
 433                              if ( $value !== '' ) $obj->render($value);
 434                      }
 435                  }
 436              }
 437          } else {
 438              foreach($keys as $key) {
 439                  if ( isset($obj->_headTags[$key]) ) {
 440                      if ( is_array($obj->_headTags[$key]) ) {
 441                          foreach ($obj->_headTags[$key] as $key2=>$value2)
 442                              if ( $value2 !== '' ) $obj->render($value2);
 443                      } else {
 444                          if ( $obj->_headTags[$key] !== '' ) $obj->render($obj->_headTags[$key]);
 445                      }
 446                  }
 447              }
 448          }
 449      }
 450      /**
 451       * Render Mambo generated meta tags.
 452       *
 453       * @param string $keys - a key or array of keys in the meta tag array to render
 454       * @param string $exclue - a key or array of keys in the meta tag array to exclude
 455       */
 456  	function showMeta($keys='', $exclude='') {
 457          if ( !is_array($keys) )
 458              if ( $keys !== '' && !is_null($keys) )
 459                  $keys = array($keys);
 460              else $keys = array();
 461          if ( !is_array($exclude) )
 462              if ( $exclude !== '' )
 463                  $exclude = array($exclude);
 464              else $exclude = array();
 465          
 466          static $obj;
 467          if ( !is_object($obj) ) $obj =& mosHtmlHelper::getInstance();
 468          if ( count($obj->_headTags) == 0 ) $obj->loadHeadTags();
 469          if ( count($keys) == 0 ) {
 470              foreach($obj->_headTags['meta'] as $key=>$value) {
 471                  if ( !in_array($key, $exclude) ) {
 472                      if (is_array($value)) {
 473                          foreach ($value as $key2=>$value2)
 474                              if ( $value2 !== '' ) $obj->render($value2);
 475                      } else {
 476                          if ( $value2 !== '' ) $obj->render($value);
 477                      }
 478                  }
 479              }
 480          } else {
 481              foreach($keys as $key) {
 482                  if ( isset($obj->_headTags['meta'][$key]) ) {
 483                      if ( is_array($obj->_headTags['meta'][$key]) ) {
 484                          foreach ($obj->_headTags['meta'][$key] as $key2=>$value2)
 485                              if ( $value2 !== '' ) $obj->render($value2);
 486                      } else {
 487                          if ( $obj->_headTags['meta'][$key] !== '' ) $obj->render($obj->_headTags['meta'][$key]);
 488                      }
 489                  }
 490              }
 491          }
 492      }
 493  } // end class mosHtmlHelper
 494  
 495  /**
 496   * mosUriHelper class
 497   *
 498   * original copyright (c) 2003, binarycloud-dev
 499   * original license - LGPL (http://www.gnu.org/copyleft/lesser.html)
 500   * original author - jason hines, jason@greenhell.com
 501   *
 502   * Changelog:
 503   * 12-01-2007 Al Warren (alwarren)
 504   *     - changed class name to mosUri
 505   *  - removed includes
 506   *  - removed references to authorizer class
 507   *     - cleaned up comments
 508  */
 509  
 510  /**
 511   * mosUriHelper is a single instance class used for altering and receiving the Uri
 512   * from different apps.  By default, it looks to current Uri, and provides
 513   * methods for retrieving the various parts of the given Uri.
 514   *
 515   * Usage:
 516   * $Uri =& mosUriHelper::getInstance();
 517   * $Uri->setUri('http://domain.com/path/to/script.php?param1=value1');
 518   * $Uri->pushParam('foo','bar');
 519   * $Uri->popParam('param1');
 520   * print $Uri->getUri();
 521   *
 522   * Outputs: http://domain.com/path/to/script.php?foo=bar
 523   *
 524   */
 525  class mosUriHelper {
 526      /**
 527       * @var string Full uri
 528       */
 529      var $uri;
 530      /**
 531       * @var string Protocol
 532       */
 533      var $scheme;
 534      /**
 535       * @var string Username
 536       */
 537      var $user;
 538      /**
 539       * @var string Password
 540       */
 541      var $pass;
 542      /**
 543       * @var string Host
 544       */
 545      var $host;
 546      /**
 547       * @var integer Port
 548       */
 549      var $port;
 550      /**
 551       * @var string Path
 552       */
 553      var $path;
 554      /**
 555       * @var array Query hash
 556       */
 557      var $query;
 558      /**
 559       * @var string Anchor
 560       */
 561      var $anchor;
 562      /**
 563       * Constructor set Uri on class instantiation.
 564       *
 565       * @param     string
 566       * @access  public
 567       */
 568      function mosUriHelper() {
 569          $this->setUri();
 570      }
 571      /**
 572       * Singleton accessor
 573       *
 574       * @access public
 575       */
 576      function &getInstance() {
 577          static $instance;
 578          if(!isset($instance)) {
 579              $instance = new mosUriHelper();
 580          }
 581          return $instance;
 582      }
 583      /**
 584       * Looks to _SERVER vars, and sets Uri property accordingly if Uri not passed.
 585       *
 586       * @access  public
 587       */
 588      function setUri($uri = null) {
 589          if ($uri == null) {
 590              $this->scheme = 'http' . (@$_SERVER['HTTPS'] == 'on' ? 's' : '');
 591              $this->user   = '';
 592              $this->pass   = '';
 593              $this->host   = !empty($host) ? $host : (isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : 'localhost');
 594              $this->port   = !empty($port) ? $port : (isset($_SERVER['SERVER_PORT']) ? $_SERVER['SERVER_PORT'] : 80);
 595              $this->path   = !empty($_SERVER['PHP_SELF']) ? $_SERVER['PHP_SELF'] : '/';
 596              $this->query  = isset($_SERVER['QUERY_STRING']) ? $this->_parseRawQuery($_SERVER['QUERY_STRING']) : null;
 597              $this->anchor = '';
 598          } else {
 599              $_parts = parse_url($uri);
 600              $this->scheme = isset($_parts['scheme']) ? $_parts['scheme'] : 'http';
 601              $this->user   = isset($_parts['user']) ? $_parts['user'] : '';
 602              $this->pass   = isset($_parts['pass']) ? $_parts['pass'] : '';
 603              $this->host   = isset($_parts['host']) ? $_parts['host'] : '';
 604              $this->port   = isset($_parts['port']) ? $_parts['port'] : 80;
 605              $this->path   = isset($_parts['path']) ? $_parts['path'] : '';
 606              $this->query  = isset($_parts['query']) ? $this->_parseRawQuery($_parts['query']) : array();
 607              $this->anchor = isset($_parts['fragment']) ? $_parts['fragment'] : '';
 608          }
 609      }
 610      /**
 611       * Returns full uri string
 612       *
 613       * @return string Full uri
 614       * @access public
 615       */
 616      function toString() {
 617          $query = $this->getQuery();
 618          $this->uri = $this->scheme . '://'
 619                       . $this->user . (!empty($this->pass) ? ':' : '')
 620                       . $this->pass . (!empty($this->user) ? '@' : '')
 621                       . $this->host . ($this->port == '80' ? '' : ':' . $this->port)
 622                       . $this->path
 623                       . (!empty($query) ? '?' . $query : '')
 624                       . (!empty($this->anchor) ? '#' . $this->anchor : '');
 625          return $this->uri;
 626      }
 627      /**
 628       * Alias for toString()
 629       *
 630       * @access  public
 631       */
 632      function getUri() {
 633          return $this->toString();
 634      }
 635      /**
 636       * Adds a query item
 637       *
 638       * @param  string $name       Name of item
 639       * @param  string $value      Value of item
 640       * @access public
 641       */
 642      function pushParam($name, $value) {
 643          $this->query[$name] = is_array($value)? array_map('urlencode', $value): urlencode($value);
 644      }
 645      /**
 646       * Get a query item
 647       *
 648       * @param  string $key Name of item
 649       * @return mixed
 650       * @access public
 651       */
 652  	function get($key, $default='') {
 653          if (isset($this->query[$key])) return $this->query[$key];
 654              else return $default;
 655      }
 656      /**
 657       * Removes a query item
 658       *
 659       * @param  string $name Name of item
 660       * @access public
 661       */
 662      function popParam($name) {
 663          if (isset($this->query[$name])) {
 664              unset($this->query[$name]);
 665          }
 666      }
 667      /**
 668       * Sets the query to literally what you supply
 669       *
 670       * @param  string $query The query data. Should be of the format foo=bar&x=y etc
 671       * @access public
 672       */
 673      function setRawQuery($query) {
 674          $this->query = $this->_parseRawQuery($query);
 675      }
 676      /**
 677       * Returns flat query
 678       *
 679       * @return string Query
 680       * @access public
 681       */
 682      function getQuery() {
 683          if (!empty($this->query)) {
 684              $query = array();
 685              foreach ($this->query as $name => $value) {
 686                  if (is_array($value)) {
 687                      foreach ($value as $k => $v) {
 688                          $query[] = $name . '=' . $v;
 689                      }
 690                  }
 691                  elseif (!is_null($value)) {
 692                      $query[] = $name . '=' . $value;
 693                  }
 694                  else {
 695                      $query[] = $name;
 696                  }
 697              }
 698              $query = implode('&', $query);
 699          } else {
 700              $query = '';
 701          }
 702          return $query;
 703      }
 704      /**
 705       * Parses raw query and returns an array of it
 706       *
 707       * @param  string  $query   The querystring to parse
 708       * @return array            An array of the query data
 709       * @access private
 710       */
 711      function _parseRawQuery($query) {
 712          $query = rawurldecode($query);
 713          // replace ampersand entities
 714          $query = str_replace('&amp;', '&', $query);
 715          $parts = preg_split('/&/', $query, -1, PREG_SPLIT_NO_EMPTY);
 716          $return = array();
 717          foreach ($parts as $part) {
 718              if (strpos($part, '=') !== false) {
 719                  $value = rawurlencode(substr($part, strpos($part, '=') + 1));
 720                  $key   = substr($part, 0, strpos($part, '='));
 721              } else {
 722                  $value = null;
 723                  $key   = $part;
 724              }
 725              if (substr($key, -2) == '[]') {
 726                  $key = substr($key, 0, -2);
 727                  if (@!is_array($return[$key])) {
 728                      $return[$key]   = array();
 729                      $return[$key][] = $value;
 730                  } else {
 731                      $return[$key][] = $value;
 732                  }
 733              } elseif (!empty($return[$key])) {
 734                  $return[$key]   = (array) $return[$key];
 735                  $return[$key][] = $value;
 736              }
 737              else {
 738                  $return[$key] = $value;
 739              }
 740          }
 741          return $return;
 742      }
 743      /**
 744       * Resolves //, ../ and ./ from a path and returns
 745       * the result. Eg:
 746       *
 747       * /foo/bar/../boo.php    => /foo/boo.php
 748       * /foo/bar/../../boo.php => /boo.php
 749       * /foo/bar/.././/boo.php => /foo/boo.php
 750       *
 751       * This method can also be called statically.
 752       *
 753       * @param  string $uri Uri path to resolve
 754       * @return string      The result
 755       */
 756      function resolvePath($path) {
 757          $path = explode('/', str_replace('//', '/', $path));
 758          for ($i=0; $i<count($path); $i++) {
 759              if ($path[$i] == '.') {
 760                  unset($path[$i]);
 761                  $path = array_values($path);
 762                  $i--;
 763              }
 764              elseif ($path[$i] == '..' AND ($i > 1 OR ($i == 1 AND $path[0] != '') ) ) {
 765                  unset($path[$i]);
 766                  unset($path[$i-1]);
 767                  $path = array_values($path);
 768                  $i -= 2;
 769              }
 770              elseif ($path[$i] == '..' AND $i == 1 AND $path[0] == '') {
 771                  unset($path[$i]);
 772                  $path = array_values($path);
 773                  $i--;
 774              }
 775              else {
 776                  continue;
 777              }
 778          }
 779          return implode('/', $path);
 780      }
 781      /**
 782       * Get scheme - returns the scheme
 783       *
 784       * @access public
 785       * @return string
 786       */
 787      function getScheme() {
 788          return $this->scheme;
 789      }
 790      /**
 791       * Set scheme - sets the scheme (protocol)
 792       *
 793       * @param  string  scheme
 794       * @access public
 795       */
 796      function setScheme($scheme) {
 797          $this->scheme = $scheme;
 798      }
 799      /**
 800       * Get username - returns the username, or null if no username was specified
 801       *
 802       * @access public
 803       * @return string
 804       */
 805      function getUser() {
 806          return $this->user;
 807      }
 808      /**
 809       * Set username - sets the username
 810       *
 811       * @param  string  username
 812       * @access public
 813       */
 814      function setUser($user) {
 815          $this->user = $user;
 816      }
 817      /**
 818       * Get password - returns the password
 819       *
 820       * @access public
 821       * @return string
 822       */
 823      function getPass() {
 824          return $this->pass;
 825      }
 826      /**
 827       * Set password - sets the password
 828       *
 829       * @param  string  password
 830       * @access public
 831       */
 832      function setPass($pass) {
 833          $this->pass = $pass;
 834      }
 835      /**
 836       * Get host - returns the hostname/ip, or null if no hostname/ip was specifi
 837       *
 838       * @access public
 839       * @return string
 840       */
 841      function getHost() {
 842          return $this->host;
 843      }
 844      /**
 845       * Set host - sets the hostname/ip
 846       *
 847       * @param  string  hostname
 848       * @access public
 849       */
 850      function setHost($host) {
 851          $this->host = $host;
 852      }
 853      /**
 854       * Get port - returns the port number, or null if no port was specified
 855       *
 856       * @access public
 857       * @return int
 858       */
 859      function getPort() {
 860          return (isset($this->port)) ? $this->port : null;
 861      }
 862      /**
 863       * Set port - sets the port number
 864       *
 865       * @param  int   port number
 866       * @access public
 867       */
 868      function setPort($port) {
 869          $this->port = $port;
 870      }
 871      /**
 872       * Gets the path string
 873       *
 874       * @access public
 875       * @return string
 876       */
 877      function getPath() {
 878          return $this->path;
 879      }
 880      /**
 881       * Set path
 882       *
 883       * @param  string  fragment for page anchors
 884       * @access public
 885       */
 886      function setPath($path) {
 887          $this->path = $path;
 888      }
 889      /**
 890       * Gets the archor string
 891       *
 892       * @access public
 893       * @return string
 894       */
 895      function getAnchor() {
 896          return $this->anchor;
 897      }
 898      /**
 899       * Set anchor - sets everything after the "#"
 900       *
 901       * @param  string  fragment for page anchors
 902       * @access public
 903       */
 904      function setAnchor($anchor) {
 905          $this->anchor = $anchor;
 906      }
 907      /**
 908       * Checks whether the current URI is using HTTPS
 909       *
 910       * @access  public
 911       * @return  boolean
 912       */
 913      function checkSSL() {
 914          return $this->getScheme() == 'https' ? TRUE : FALSE;
 915      }
 916  } // end class mosUri
 917  
 918  require_once(mamboCore::get('rootPath').'/includes/tm_encrypt/std.encryption.class.inc');
 919  class mosCrypto extends encryption_class {
 920      var $key;
 921      function &getInstance() {
 922          static $instance;
 923          if (!is_object($instance)) {
 924              $instance = new mosCrypto;
 925              $instance->key = mosCreateGUID();
 926          }
 927          return $instance;
 928      }
 929  	function get($property, $default=null) {
 930          if(isset($this->$property)) {
 931              return $this->$property;
 932          } else {
 933              return $default;
 934          }
 935      }
 936  	function encrypt($plain_text, $key='') {
 937          $this->key = $key !== '' ? $key : mosCreateGUID();
 938          $mainframe =& mosMainframe::getInstance();
 939          $enc_text = parent::encrypt($this->key, $plain_text, strlen($plain_text));
 940          return $enc_text;
 941      }
 942  	function decrypt($enc_text, $key='') {
 943          $this->key = $key !== '' ? $key : mosCreateGUID();
 944          $plain_text = parent::decrypt($this->key, $enc_text);
 945          return $plain_text;
 946      }
 947  	function encryptQuery($query, $key='') {
 948          $this->key = $key !== '' ? $key : mosCreateGUID();
 949          return base64_encode(urlencode($this->encrypt($query, $key)));
 950      }
 951  	function decryptQuery($query, $key='') {
 952          $this->key = $key !== '' ? $key : mosCreateGUID();
 953          return $this->decrypt(urldecode(base64_decode($query)), $key);
 954      }
 955  }
 956  ?>