* @version 1.1.0.0 */ /* $Id$ */ (defined('USE_MCMS') && (basename(__FILE__) != basename($_SERVER['SCRIPT_NAME']))) or die('ACCESS DENIED'); if(!defined('USE_MAMMUT')) /** @ignore */ define('USE_MAMMUT', true); // import mammut framework require_once ('Mammut' . DIRECTORY_SEPARATOR . 'lib.mammut.php'); if(!(defined('MAMMUT') && function_exists('importlib'))) die('CRITICAL ERROR: mammut framework not found (missing function: importlib())'); use Mammut\Exception\IllegalStateException; if (!defined('__DS__')) /** @ignore */ define('__DS__',DIRECTORY_SEPARATOR); /** * Current MCMS script version */ define('MCMS', '1.1.0.0'); /** * Current MCMS schema version required by the script */ define('MCMS_DB', '1.1.0.0'); /** * Searches the path of a module */ function getModulePath($namespace) { foreach(array('_MODPATHX_','_MODPATH_') as $const) { if(defined($const)) { $base = constant($const); $st = $base . __DS__ . str_replace('.', __DS__, $namespace); if(file_exists($st)) return $st; } } return false; } /** * Searches the path of a plugin */ function getPluginPath($namespace) { foreach(array('_PLUGINPATHX_','_PLUGINPATH_') as $const) { if(defined($const)) { $base = constant($const); $st = $base . __DS__ . str_replace('.', __DS__, $namespace); if(file_exists($st)) return $st; } } return false; } /** * Checks if an component is installed on the file system * * @param string $cat * component category * @param string $classpath * component name * @return boolean trhe if the component is found */ function isComponentInstalled($cat, $classpath) { if(!(defined('_COMPATH_') || defined('_COMPATHX_'))) throw new IllegalStateException('neigher _COMPATH_ nor _COMPATHX_ defined'); $path = strtolower($cat) . __DS__; $parts = explode('.', $classpath); for($i = 0; $i < count($parts) - 1; $i++) $path .= strtolower($parts[$i]) . __DS__; $class = $parts[count($parts) - 1]; $classname = ucfirst($class); foreach(array('_COMPATHX_','_COMPATH_') as $const) { if(defined($const)) { $basepath = constant($const) . __DS__ . strtolower($path); if(is_dir($basepath)) { if(file_exists($basepath . 'com.' . strtolower($class) . '.php')) { return true; } } } } return false; } /** * Fetches the module info array * * @param string $modPath * @throws IllegalStateException * @return array|boolean The info array or false */ function getModuleInfo($modPath) { $path = ''; $parts = explode('\\', $modPath); $info = array(); $info['modname'] = $parts[count($parts) - 1]; $info['entries'] = ['index' => 'Index']; $info['extended']= strtoupper($parts[3]) == 'MODX'; $info['layout_pathx'] = false; if ($info['extended'] && !defined('_MODPATHX_')) throw new IllegalStateException('Extended module selected, but _MODPATHX_ is undefined'); $moddir = $info['extended'] ? _MODPATHX_ : _MODPATH_; unset($parts[count($parts) - 1]); unset($parts[3], $parts[2], $parts[1], $parts[0]); $moddir .= __DS__; $layoutpathx = _LAYOUTPATHX_ . __DS__ . '_module_' . __DS__; foreach ($parts as $p) { $p = strtolower($p); $moddir .= $p.__DS__; $layoutpathx .= $p.__DS__; } $layoutpathx .= '_layout_' . __DS__; if(is_dir($moddir)) { $info['layout_path'] = $moddir . '_layout_' . __DS__; $info['layout_pathx'] = $layoutpathx; $info['title'] = 'Untitled module'; $info['version'] = 'N/A'; $info['setup'] = false; $info['setupi'] = false; if(file_exists($moddir . '_info_.php')) include ($moddir . '_info_.php'); $info['path'] = $moddir; } return $info; } /** * Default exception handler * * @param \Exception $ex * The exception that will be handled */ 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() . '

'; if(defined('DEBUG')) { if ($ex instanceof \Mammut\DB\SQLException) echo '
Query:
'.$ex->getQuery().'

'; echo '
Stack trace:
'; echo $ex->getTraceAsString() . '
'; } die(); } /** * Error to exception converter function. * * @param mixed $severity * @param string $errString * @param string $filename * @param integer $lineno * @param mixed $errContext * @throws ErrorException The converted error */ function mcms_error_handler($severity, $errString, $filename, $lineno) { switch($severity) { case E_USER_NOTICE: case E_NOTICE: if(defined('DEBUG')) if(defined('_CLI_')) echo 'Notice: ' . $errString . ' | ' . $filename . ':' . $lineno . "\n"; else echo '
Notice: ' . $errString . ' | ' . $filename . ':' . $lineno . '
'; break; case E_USER_DEPRECATED: case E_DEPRECATED: if(defined('DEBUG')) if(defined('_CLI_')) echo 'Deprecated: ' . $errString . ' | ' . $filename . ':' . $lineno . "\n"; else echo '
Deprecated: ' . $errString . ' | ' . $filename . ':' . $lineno . '
'; break; case E_WARNING: if(defined('_CLI_')) echo 'Warning: ' . $errString . ' | ' . $filename . ':' . $lineno . "\n"; else { echo '
Warning'; if(defined('DEBUG')) echo ': ' . $errString . ' | ' . $filename . ':' . $lineno; else echo ' (Enable debug mode for details)'; echo '
'; } break; default: throw new \ErrorException($errString, 0, $severity, $filename, $lineno); break; } } importlib('vendor.composer'); // Pseudo-Libloader for composer fragments // this method should not exist, but if you want to write your own, do it importlib('vendor.composer'); // Pseudo-Libloader for composer fragments if(!function_exists('__autoload')) { require_once ('Mammut' . __DS__ . 'AutoLoader' . __DS__ . 'cls.iautoloader.php'); require_once (__DIR__ . __DS__ . 'AutoLoader' . __DS__ . 'cls.mmautoloader.php'); spl_autoload_register(array(\MCMS\AutoLoader\MMAutoLoader::clazz(),'loadClass')); } set_exception_handler('mcms_exception_handler'); set_error_handler('mcms_error_handler'); // import base libaries try { importlib('Mammut.Math'); if (lib_exists('vendor.composerx')) // Additional composer fragments importlib('vendor.composerx'); } catch(Exception $e) { die("INIT-ERROR: " . $e->getMessage()); }