ocs  2.3.6
About: OCS (Open Conference System) is a Web publishing tool that will create a complete Web presence for your scholarly conference.
  Fossies Dox: ocs-2.3.6.tar.gz  ("inofficial" and yet experimental doxygen-generated source code documentation)  

functions.inc.php
Go to the documentation of this file.
1 <?php
2 
15 //$Id$
16 
17 
23 if (!function_exists('import')) {
24  function import($class) {
25  require_once(str_replace('.', '/', $class) . '.inc.php');
26  }
27 }
28 
29 if (!function_exists('file_get_contents')) {
30  // For PHP < 4.3.0
31  function file_get_contents($file) {
32  return join('', file($file));
33  }
34 }
35 
39 function fatalError($reason) {
40  // Because this method may be called when checking the value of the show_stacktrace
41  // configuration string, we need to ensure that we don't get stuck in an infinite loop.
42  static $isErrorCondition = null;
43  static $showStackTrace = false;
44 
45  if ($isErrorCondition === null) {
46  $isErrorCondition = true;
47  $showStackTrace = Config::getVar('debug', 'show_stacktrace');
48  $isErrorCondition = false;
49  }
50 
51  echo "<h1>$reason</h1>";
52 
53  if ($showStackTrace && checkPhpVersion('4.3.0')) {
54  echo "<h4>Stack Trace:</h4>\n";
55  $trace = debug_backtrace();
56 
57  // Remove the call to fatalError from the call trace.
58  array_shift($trace);
59 
60  // Back-trace pretty-printer adapted from the following URL:
61  // http://ca3.php.net/manual/en/function.debug-backtrace.php
62  // Thanks to diz at ysagoon dot com
63 
64  // FIXME: Is there any way to localize this when the localization
65  // functions may have caused the failure in the first place?
66  foreach ($trace as $bt) {
67  $args = '';
68  if (isset($bt['args'])) foreach ($bt['args'] as $a) {
69  if (!empty($args)) {
70  $args .= ', ';
71  }
72  switch (gettype($a)) {
73  case 'integer':
74  case 'double':
75  $args .= $a;
76  break;
77  case 'string':
78  $a = htmlspecialchars(substr($a, 0, 64)).((strlen($a) > 64) ? '...' : '');
79  $args .= "\"$a\"";
80  break;
81  case 'array':
82  $args .= 'Array('.count($a).')';
83  break;
84  case 'object':
85  $args .= 'Object('.get_class($a).')';
86  break;
87  case 'resource':
88  $args .= 'Resource('.strstr($a, '#').')';
89  break;
90  case 'boolean':
91  $args .= $a ? 'True' : 'False';
92  break;
93  case 'NULL':
94  $args .= 'Null';
95  break;
96  default:
97  $args .= 'Unknown';
98  }
99  }
100  $class = isset($bt['class'])?$bt['class']:'';
101  $type = isset($bt['type'])?$bt['type']:'';
102  $function = isset($bt['function'])?$bt['function']:'';
103  $file = isset($bt['file'])?$bt['file']:'(unknown)';
104  $line = isset($bt['line'])?$bt['line']:'(unknown)';
105 
106  echo "<strong>File:</strong> {$file} line {$line}<br />\n";
107  echo "<strong>Function:</strong> {$class}{$type}{$function}($args)<br />\n";
108  echo "<br/>\n";
109  }
110  }
111 
112  // Determine the application name. Use defensive code so that we
113  // can handle errors during early application initialization.
114  $application = null;
115  if (class_exists('Registry')) {
116  $application = Registry::get('application', true, null);
117  }
118  $applicationName = '';
119  if (!is_null($application)) {
120  $applicationName = $application->getName().': ';
121  }
122 
123  error_log($applicationName.$reason);
124 
125  if (defined('DONT_DIE_ON_ERROR') && DONT_DIE_ON_ERROR == true) {
126  // trigger an error to be catched outside the application
127  trigger_error($reason);
128  return;
129  }
130 
131  die();
132 }
133 
139 function checkPhpVersion($version) {
140  return (version_compare(PHP_VERSION, $version) !== -1);
141 }
142 
149 function &cloneObject(&$object) {
150  if (checkPhpVersion('5.0.0')) {
151  // We use the PHP5 clone() syntax so that PHP4 doesn't
152  // raise a parse error.
153  $clonedObject = clone($object);
154  } else {
155  // PHP4 always clones objects on assignment
156  $clonedObject = $object;
157  }
158  return $clonedObject;
159 }
160 
166 function arrayClean(&$array) {
167  if (!is_array($array)) return null;
168  return array_filter($array, create_function('$o', 'return !empty($o);'));
169 }
170 ?>
config TEMPLATE inc php
Definition: config.inc.php:4
checkPhpVersion($version)
$application
Definition: index.php:64
$class
& cloneObject(&$object)
getVar($section, $key, $default=null)
Definition: Config.inc.php:35
arrayClean(&$array)
if(!function_exists('import')) if(!function_exists('file_get_contents')) fatalError($reason)
& get($key, $createIfEmpty=false, $createWithDefault=null)