| [ Index ] |
PHP Cross Reference of Unnamed Project |
[Summary view] [Print] [Text view]
1 <?php 2 3 // --------------------------------------------------- 4 // System callback functions, registered automaticly 5 // or in application/application.php 6 // --------------------------------------------------- 7 8 /** 9 * Gets called, when an undefined class is being instanciated 10 *d 11 * @param_string $load_class_name 12 */ 13 function __autoload($load_class_name) { 14 static $loader = null; 15 $class_name = strtoupper($load_class_name); 16 17 // Try to get this data from index... 18 if(isset($GLOBALS[AutoLoader::GLOBAL_VAR])) { 19 if(isset($GLOBALS[AutoLoader::GLOBAL_VAR][$class_name])) { 20 return include $GLOBALS[AutoLoader::GLOBAL_VAR][$class_name]; 21 } // if 22 } // if 23 24 if(!$loader) { 25 $loader = new AutoLoader(); 26 $loader->addDir(ROOT . '/application'); 27 $loader->addDir(ROOT . '/environment'); 28 $loader->addDir(ROOT . '/library'); 29 $loader->setIndexFilename(ROOT . '/cache/autoloader.php'); 30 } // if 31 32 try { 33 $loader->loadClass($class_name); 34 } catch(Exception $e) { 35 die('Caught Exception in AutoLoader: ' . $e->__toString()); 36 } // try 37 } // __autoload 38 39 /** 40 * ProjectPier shutdown function 41 * 42 * @param void 43 * @return null 44 */ 45 function __shutdown() { 46 $logger_session = Logger::getSession(); 47 if(($logger_session instanceof Logger_Session) && !$logger_session->isEmpty()) { 48 Logger::saveSession(); 49 } // if 50 } // __shutdown 51 52 /** 53 * This function will be used as error handler for production 54 * 55 * @param integer $code 56 * @param string $message 57 * @param string $file 58 * @param integer $line 59 * @return null 60 */ 61 function __production_error_handler($code, $message, $file, $line) { 62 // Skip non-static method called staticly type of error... 63 if($code == 2048) { 64 return; 65 } // if 66 67 Logger::log("Error: $message in '$file' on line $line (error code: $code)", Logger::ERROR); 68 } // __production_error_handler 69 70 /** 71 * This function will be used as exception handler in production environment 72 * 73 * @param Exception $exception 74 * @return null 75 */ 76 function __production_exception_handler($exception) { 77 Logger::log($exception, Logger::FATAL); 78 } // __production_exception_handler 79 80 // --------------------------------------------------- 81 // Get URL 82 // --------------------------------------------------- 83 84 /** 85 * Return an application URL 86 * 87 * If $include_project_id variable is presend active_project variable will be added to the list of params if we have a 88 * project selected (active_project() function returns valid project instance) 89 * 90 * @param string $controller_name 91 * @param string $action_name 92 * @param array $params 93 * @param string $anchor 94 * @param boolean $include_project_id 95 * @return string 96 */ 97 function get_url($controller_name = null, $action_name = null, $params = null, $anchor = null, $include_project_id = true) { 98 $controller = trim($controller_name) ? $controller_name : DEFAULT_CONTROLLER; 99 $action = trim($action_name) ? $action_name : DEFAULT_ACTION; 100 if(!is_array($params) && !is_null($params)) { 101 $params = array('id' => $params); 102 } // if 103 104 $url_params = array('c=' . $controller, 'a=' . $action); 105 106 if($include_project_id) { 107 if(function_exists('active_project') && (active_project() instanceof Project)) { 108 if(!(is_array($params) && isset($params['active_project']))) { 109 $url_params[] = 'active_project=' . active_project()->getId(); 110 } // if 111 } // if 112 } // if 113 114 if(is_array($params)) { 115 foreach($params as $param_name => $param_value) { 116 if(is_bool($param_value)) { 117 $url_params[] = $param_name . '=1'; 118 } else { 119 $url_params[] = $param_name . '=' . urlencode($param_value); 120 } // if 121 } // foreach 122 } // if 123 124 if(trim($anchor) <> '') { 125 $anchor = '#' . $anchor; 126 } // if 127 128 return with_slash(ROOT_URL) . 'index.php?' . implode('&', $url_params) . $anchor; 129 } // get_url 130 131 // --------------------------------------------------- 132 // Product 133 // --------------------------------------------------- 134 135 /** 136 * Return product name. This is a wrapper function that abstracts the product name 137 * 138 * @param void 139 * @return string 140 */ 141 function product_name() { 142 return PRODUCT_NAME; 143 } // product_name 144 145 /** 146 * Return product version, wrapper function. 147 * 148 * @param void 149 * @return string 150 */ 151 function product_version() { 152 // 0.6 is the last version that comes without PRODUCT_VERSION constant that is set up 153 return defined('PRODUCT_VERSION') ? PRODUCT_VERSION : '0.8.0'; 154 } // product_version 155 156 /** 157 * Returns product signature (name and version). If user is not logged in and 158 * is not member of owner company he will see only product name 159 * 160 * @param void 161 * @return string 162 */ 163 function product_signature() { 164 if(function_exists('logged_user') && (logged_user() instanceof User) && logged_user()->isMemberOfOwnerCompany()) { 165 $result = lang('footer powered', 'http://www.projectpier.org/', clean(product_name()) . ' ' . product_version()); 166 if(Env::isDebugging()) { 167 ob_start(); 168 benchmark_timer_display(false); 169 $result .= '. ' . ob_get_clean(); 170 if(function_exists('memory_get_usage')) { 171 $result .= '. ' . format_filesize(memory_get_usage()); 172 } // if 173 } // if 174 return $result; 175 } else { 176 return lang('footer powered', 'http://www.ProjectPier.org/', clean(product_name())); 177 } // if 178 } // product_signature 179 180 // --------------------------------------------------- 181 // Request, routes replacement methods 182 // --------------------------------------------------- 183 184 /** 185 * Return matched requst controller 186 * 187 * @access public 188 * @param void 189 * @return string 190 */ 191 function request_controller() { 192 $controller = trim(array_var($_GET, 'c', DEFAULT_CONTROLLER)); 193 return $controller && is_valid_function_name($controller) ? $controller : DEFAULT_CONTROLLER; 194 } // request_controller 195 196 /** 197 * Return matched request action 198 * 199 * @access public 200 * @param void 201 * @return string 202 */ 203 function request_action() { 204 $action = trim(array_var($_GET, 'a', DEFAULT_ACTION)); 205 return $action && is_valid_function_name($action) ? $action : DEFAULT_ACTION; 206 } // request_action 207 208 // --------------------------------------------------- 209 // Controllers and stuff 210 // --------------------------------------------------- 211 212 /** 213 * Set internals of specific company website controller 214 * 215 * @access public 216 * @param PageController $controller 217 * @param string $layout Project or company website layout. Or any other... 218 * @return null 219 */ 220 function prepare_company_website_controller(PageController $controller, $layout = 'dashboard') { 221 222 // If we don't have logged user prepare referer params and redirect user to login page 223 if(!(logged_user() instanceof User)) { 224 $ref_params = array(); 225 foreach($_GET as $k => $v) $ref_params['ref_' . $k] = $v; 226 $controller->redirectTo('access', 'login', $ref_params); 227 } // if 228 229 $controller->setLayout($layout); 230 $controller->addHelper('form', 'breadcrumbs', 'pageactions', 'tabbednavigation', 'company_website', 'project_website'); 231 } // prepare_company_website_controller 232 233 // --------------------------------------------------- 234 // Company website interface 235 // --------------------------------------------------- 236 237 /** 238 * Return owner company object if we are on company website and it is loaded 239 * 240 * @access public 241 * @param void 242 * @return Company 243 */ 244 function owner_company() { 245 return CompanyWebsite::instance()->getCompany(); 246 } // owner_company 247 248 /** 249 * Return logged user if we are on company website 250 * 251 * @access public 252 * @param void 253 * @return User 254 */ 255 function logged_user() { 256 return CompanyWebsite::instance()->getLoggedUser(); 257 } // logged_user 258 259 /** 260 * Return active project if we are on company website 261 * 262 * @access public 263 * @param void 264 * @return Project 265 */ 266 function active_project() { 267 return CompanyWebsite::instance()->getProject(); 268 } // active_project 269 270 // --------------------------------------------------- 271 // Config interface 272 // --------------------------------------------------- 273 274 /** 275 * Return config option value 276 * 277 * @access public 278 * @param string $name Option name 279 * @param mixed $default Default value that is returned in case of any error 280 * @return mixed 281 */ 282 function config_option($option, $default = null) { 283 return ConfigOptions::getOptionValue($option, $default); 284 } // config_option 285 286 /** 287 * Set value of specific configuration option 288 * 289 * @param string $option_name 290 * @param mixed $value 291 * @return boolean 292 */ 293 function set_config_option($option_name, $value) { 294 $config_option = ConfigOptions::getByName($option_name); 295 if(!($config_option instanceof ConfigOption)) { 296 return false; 297 } // if 298 299 $config_option->setValue($value); 300 return $config_option->save(); 301 } // set_config_option 302 303 /** 304 * This function will return object by the manager class and object ID 305 * 306 * @param integer $object_id 307 * @param string $manager_class 308 * @return ApplicationDataObject 309 */ 310 function get_object_by_manager_and_id($object_id, $manager_class) { 311 $object_id = (integer) $object_id; 312 $manager_class = trim($manager_class); 313 314 if(!is_valid_function_name($manager_class) || !class_exists($manager_class, true)) { 315 throw new Error("Class '$manager_class' does not exist"); 316 } // if 317 318 $code = "return $manager_class::findById($object_id);"; 319 $object = eval($code); 320 321 return $object instanceof DataObject ? $object : null; 322 } // get_object_by_manager_and_id 323 324 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Tue Sep 25 23:40:09 2007 | Cross-referenced by PHPXref 0.7 |