Logo Search packages:      
Sourcecode: bamboo version File versions

common.php

<?php

##
## common functions which all code needs access to.
##

##################################################################
## GLOBAL URL FUNCTIONS

function deurlize($name) {
      if (preg_match('#^index\.\w{2,3}$#',$name))
            $title = basename(dirname($name));
      else
            $title = basename($name);

      # remove query string, underscore with space,
      # dash with space, Erase tilde
      
      $title = preg_replace(
            array("/(\?.*)/", "/_/", "/--/", "/-/", "/~/"),
            array("",         " ",   "&ndash;",    " ",   ""),
            $title
      );
      $title = preg_replace("/&ndash;/", "-",$title);
      
      # remove leading or trailing space
      $title = trim($title);
      
      # Capitalize All Words 
      $title = ucwords($title);
      
      return $title;
}

function urlize($title) {
      $name = strtolower($title);
      $name = preg_replace(
            array('/&.{2,4};/','/-/','/\s+/','/[^a-z0-9-]/'),
            array('','--','-',''),
            $name
      );
      return $name;
}

function alink($path,$label,$tags='') {
      global $root;
      if ($path == '' || $path{0}=='?')
            return "<a href=\"" . preg_replace('/\?.*$/','',$_SERVER['REQUEST_URI']) . "$path\" $tags>$label</a>";
      elseif ($path{0} == '/')
            return "<a href=\"$root$path\" $tags>$label</a>";
      else
            return "<a href=\"$path\" $tags>$label</a>";
}

/**
 * magic quotes are stupid, and there is no easy way to turn them off.
 * (set_magic_quotes_runtime doesn't always work).
 **/

function &get($prop, $default='', $raw=false) {
      if (!isset($_REQUEST[$prop])) 
            return $default;
            
      $prop = $_REQUEST[$prop];
      if (!is_array($prop)) {
            if(get_magic_quotes_gpc() || ini_get('magic_quotes_gpc')) {
                  $prop = stripslashes($prop);
            }
            if (!$raw)
                  $prop = htmlspecialchars($prop,ENT_QUOTES);
      }
      else {
            if(get_magic_quotes_gpc()) {
                  $prop = array_map("stripslashes", $prop);
            }
            if (!$raw)
                  $prop = array_map("htmlspecialchars", $prop);
      }
      return $prop;
}

function &getraw($prop, $default='') {
      return get($prop, $default, true);
}

##################################################################
## GLOBAL ERROR FUNCTIONS

#error_reporting (E_USER_ERROR | E_USER_WARNING | E_USER_NOTICE);
function errors($errno='', $errstr='', $errfile='', $errline='') {
      static $_errors = array();
      
      if ($errno == '') {
            return join('',$_errors);
      }
      else {
            switch ($errno) {
                  case E_USER_ERROR:
                  case E_ERROR:
                        $etype = 'ERROR'; break;
                  case E_USER_WARNING:
                  case E_WARNING:
                        $etype = 'WARNING'; break;
                  case E_USER_NOTICE:
                  case E_NOTICE:
                        #if ( ! (ini_get('error_reporting')&E_NOTICE) ) return;
                        $etype = 'NOTICE'; break;
                  case E_STRICT:
                        #if ( ! (ini_get('error_reporting')&E_STRICT) ) return;
                        $etype = 'STRICT'; break;

            }
            $_errors[] = "<p><b>$etype</b>: $errstr <br /><i>$errfile: $errline</i></p>";
      }
}
set_error_handler("errors");


/**
 * return a copy of $path which safe to pass to a shell command.
 **/
function safepath($path) {
      global $docroot;
      if (strpos($path,$docroot) != 0)
            die("path must be absolute and under site's docroot: $path");
      if (strpos($path,'..') !== false)
            die("path cannot have .. in it");
      return escapeshellarg($path);
}

return;
?>

Generated by  Doxygen 1.6.0   Back to index