/** * Return plugin class for $name * * @param string $name * * @return object; */ public static function getInstance($name = null) { if (!$name) { $name = get_called_class(); } return Clockwork::getInstance()->loadedPlugins[strtolower($name)]; }
/** * Constructor * */ public function __construct() { if (!Clockwork::getInstance()->isModuleLoaded('Cache')) { Clockwork::throwError('Login module depends on Cache module, which is not loaded', Clockwork::ERROR_FATAL, 1); } if (!Clockwork::getInstance()->isModuleLoaded('Hash')) { Clockwork::throwError('Login module depends on Hash module, which is not loaded', Clockwork::ERROR_FATAL, 1); } }
/** * Return a setting. * * @param string $key Setting to return. * @param boolean $error Throw an error if setting does not exists. * @param boolean $default Default value to return if setting does not exists. * * @return mixed */ public static function getSetting($key, $error = true, $default = null) { $config = self::getInstance(); if (!isset($config->settings[$key])) { if (defined(strtoupper($key))) { return constant(strtoupper($key)); } if ($error) { Clockwork::getInstance()->throwError('Config (' . $key . ') not found', Clockwork::ERROR_WARNING, 1); } return $default; } else { return $config->settings[$key]; } }
<?php // define('CW_CRON', true); include_once 'index.php'; extract($_GET); // if (preg_match('/(css|js|image)/', $type)) { if (Clockwork::getInstance()->isPluginLoaded($plugin)) { if ($type != 'image' || preg_match('/jpg|jpeg|gif|png/i', $ext)) { $file = Plugin::getInstance($plugin)->dir() . 'asset/' . $type . '/' . $file . '.' . $ext; if (file_exists($file)) { if ($type == 'image') { header('Content-Type: image/' . str_replace('jpg', 'jpeg', $ext)); } else { if ($type == 'css') { header('Content-Type: text/css'); } else { if ($type == 'js') { header('Content-Type: application/javascript'); } } } readfile($file); exit; } } } } // --- 404 new Template(['view' => '404']);
/** * Extend $this with ActiveRecord. * * @param string $object Object to extend. * * @return self */ public function find($object) { if (Clockwork::getInstance()->isModuleLoaded('Data/ActiveRecord')) { if (!$this->ActiveRecord || $this->ActiveRecord != $object) { $this->ActiveRecord = new ActiveRecord($object, $this); } } return $this; }
/** * Register a plugin * * @param string $name * * @return void */ public static function registerPlugin($name, $plugin) { Clockwork::getInstance()->loadedPlugins[strtolower($name)] = $plugin; }
/** * Setup Twig template engine * * @return void */ public function setupTwig() { Twig_Autoloader::register(true); if (!is_dir($this->basedir . 'template/')) { Clockwork::throwError('Template directory (' . $this->basedir . 'template/) does not exists'); } $paths = [$this->basedir . 'template/', APP_DIR . 'template/']; $plugins = Clockwork::getInstance()->loadedPlugins; foreach ($plugins as $plugin) { if (is_dir($plugin->dir() . 'template/')) { $paths[] = $plugin->dir() . 'template/'; } } $loader = new Twig_Loader_Filesystem($paths); $this->twig = new Twig_Environment($loader, array('cache' => Config::getSetting('twig_cache') ? appdir('template/cache/') : false)); $functions = get_defined_functions(); foreach ($functions['user'] as $function) { if (strpos(strtolower($function), 'twig') === false) { $this->twig->addFunction(new Twig_SimpleFunction($function, $function)); } } $this->twig->addFunction(new Twig_SimpleFunction('PluginLoader', [Clockwork::getInstance(), 'pluginLoader'])); }