'Index'); // automatically search for admin page and create a default link if(is_dir($basepath . '_admin_' . __DS__)) $info['admin_path'] = $basepath . '_admin_' . __DS__; $info['title'] = 'Untitled module'; $info['verion'] = 'Unversioned module'; if(file_exists($basepath . '_info_.php')) { include ($basepath . '_info_.php'); } else { $info = array(); } $info['path'] = $basepath; return $info; } } } } /** * loads a module * * @param string $classpath * component name * @return string the class name of the component * @throws MMPageNotFoundException if component isn't found * @throws MFIllegalStateException if component class isn't found */ function loadModule($classpath) { static $loaded; if(!(defined('_MODPATH_') || defined('_MODPATHX_'))) throw new \Mammut\Exception\IllegalStateException('neigher _MODPATH_ nor _MODPATHX_ defined'); if(!isset($loaded)) $loaded = array(); $path = ''; $parts = explode('.', $classpath); for($i = 0; $i < count($parts) - 1; $i++) $path .= $parts[$i] . __DS__; $class = $parts[count($parts) - 1]; $classname = 'MMMod' . ucfirst($class); if(array_search($classpath, $loaded)) return $classname; foreach(array('_MODPATHX_','_MODPATH_') as $const) { if(defined($const)) { $basepath = constant($const) . __DS__ . $path . __DS__ . strtolower($class) . __DS__; if(is_dir($basepath)) { // if (file_exists($basepath.'_info_.php')) { // $info = array(); // include($basepath.'_info_.php'); // } if(file_exists($basepath . 'mod.' . strtolower($class) . '.php')) { require_once ($basepath . 'mod.' . strtolower($class) . '.php'); if(!class_exists($classname)) throw new \Mammut\Exception\IllegalStateException('module class file found, but class is missing: ' . $classname); else { $loaded[] = $classpath; return $classname; } } } } } throw new \Mammut\Exception\ImplementationException('class not found: ' . $classname); } /** * loads a plugin * * @param string $category * plugin category * @param string $classpath * plugin classpath * @return string the class name of the component * @throws MMPageNotFoundException if component isn't found * @throws MFIllegalStateException if component class isn't found */ function loadPlugin($category, $classpath) { static $loaded; $classpath = $category . '.' . $classpath; // simple but it works for now if(!(defined('_PLUGINPATH_') || defined('_PLUGINPATHX_'))) throw new \Mammut\Exception\IllegalStateException('neigher _PLUGINPATH_ nor _PLUGINPATHX_ defined'); if(!isset($loaded)) $loaded = array(); $path = ''; $parts = explode('.', $classpath); for($i = 0; $i < count($parts) - 1; $i++) $path .= $parts[$i] . __DS__; $class = $parts[count($parts) - 1]; $classname = 'PlugIn' . ucfirst($class); if(array_search($classpath, $loaded)) return $classname; foreach(array('_PLUGINPATHX_','_PLUGINPATH_') as $const) { if(defined($const)) { $basepath = constant($const) . __DS__ . $path . strtolower($class) . __DS__; if(is_dir($basepath)) { if(file_exists($basepath . '_info_.php')) { $info = array(); include ($basepath . '_info_.php'); if(isset($info['needs']) && (count($info['needs']) > 0)) { foreach($info['needs'] as $need) loadPlugin($category, $need); } } if(file_exists($basepath . 'pin.' . strtolower($class) . '.php')) { require_once ($basepath . 'pin.' . strtolower($class) . '.php'); if(!class_exists($classname)) throw new \Mammut\Exception\IllegalStateException('class file found, but class is missing: ' . $classname); else { $loaded[] = $classpath; return $classname; } } } } } throw new \Mammut\Exception\ImplementationException('class not found: ' . $classname); } /** * loads a plugin admin class * * @param string $category * plugin category * @param string $classpath * plugin classpath * @param string $name * the admin class name part * @return string the class name of the component * @return string the class name of the component * @throws MFIllegalStateException if component class isn't found */ function loadPluginAdmin($category, $classpath, $name) { static $loaded; $classpath = $category . '.' . $classpath; // simple but it works for now if(!(defined('_PLUGINPATH_') || defined('_PLUGINPATHX_'))) throw new \Mammut\Exception\IllegalStateException('neigher _PLUGINPATH_ nor _PLUGINPATHX_ defined'); if(!isset($loaded)) $loaded = array(); $path = ''; $parts = explode('.', $classpath); for($i = 0; $i < count($parts) - 1; $i++) $path .= $parts[$i] . __DS__; $class = $parts[count($parts) - 1]; $classname = 'PIA' . ucfirst($class) . ucfirst($name); if(array_search($classpath, $loaded)) return $classname; foreach(array('_PLUGINPATHX_','_PLUGINPATH_') as $const) { if(defined($const)) { $basepath = constant($const) . __DS__ . $path . strtolower($class) . __DS__; if(is_dir($basepath)) { if(file_exists($basepath . '_info_.php')) { $info = array(); include ($basepath . '_info_.php'); if(isset($info['needs']) && (count($info['needs']) > 0)) { foreach($info['needs'] as $need) loadPlugin($category, $need); } } $file = $basepath . '_admin_' . __DS__ . 'pia.' . strtolower($name) . '.php'; if(file_exists($file)) { require_once ($file); if(!class_exists($classname)) throw new \Mammut\Exception\IllegalStateException('class file found, but class is missing: ' . $classname); else { $loaded[] = $classpath; return $classname; } } } } } throw new \Mammut\Exception\ImplementationException('class not found: ' . $classname); } // create a better default errror handler (using html) function mcms_exception_handler($ex) { echo ($ex instanceof ErrorException) ? '
Critical error!
' : 'Error!
'; echo 'Uncaught exception: ' . get_class($ex) . '
';
echo 'Code: ' . $ex->getCode() . '
';
echo 'Message: ' . $ex->getMessage() . '
Stack trace:'; } die(); } // we want all errors to be exceptions function mcms_error_handler($severity, $errString, $filename, $lineno, $errContext) { switch($severity) { case E_USER_NOTICE: case E_NOTICE: if(defined('DEBUG')) if(defined('_CLI_')) echo 'Notice: ' . $errString . ' | ' . $filename . ':' . $lineno . "\n"; else echo '
'; echo $ex->getTraceAsString() . '