/** * registerListeners * * @param Dispatcher $dispatcher * * @return void */ public function registerListeners(Dispatcher $dispatcher) { $config = Ioc::getConfig(); $plugins = $config->get('plugins', array()); foreach ($plugins as $plugin) { if (class_exists($plugin) && is_subclass_of($plugin, 'Vaseman\\Plugin\\AbstractPlugin') && $plugin::$isEnabled) { $dispatcher->addListener(new $plugin()); } } }
/** * checkLogin * * @return boolean */ public static function checkLogin() { if (User::get()->notNull()) { return true; } $session = Ioc::getSession(); $current = Ioc::getConfig()->get('uri.current'); $current = base64_encode($current); $session->set('login.redirect.url', $current); Ioc::getApplication()->redirect(Router::buildHttp('user:login')); return true; }
/** * onViewBeforeRender * * @param Event $event * * @return void */ public function onViewBeforeRender(Event $event) { $data = $event['data']; $data->user = $data->user ?: User::get(); $articleMapper = new ArticleMapper(); $data->articles = $data->articles ?: $articleMapper->find(['state' => 1], 'ordering'); foreach ($data->articles as $article) { $article->link = $article->url ?: Router::html('forum@article', ['id' => $article->id, 'alias' => $article->alias]); } // Template $config = Ioc::getConfig(); if ($config['natika.theme']) { $event['view']->getRenderer()->addPath(WINDWALKER_TEMPLATES . '/theme/' . $config['natika.theme'] . '/' . $event['view']->getName(), Priority::HIGH); } }
/** * loadAllFromPath * * @param string $path * @param string $format * @param string $package */ public static function loadAllFromPath($path, $format, $package = null) { $config = Ioc::getConfig(); $locale = $config['language.locale'] ?: 'en-GB'; $default = $config['language.default'] ?: 'en-GB'; $locale = LanguageNormalize::toLanguageTag($locale); $default = LanguageNormalize::toLanguageTag($default); $localePath = $path . '/' . $locale; $files = array(); if (is_dir($localePath)) { $files = array_merge($files, (array) Folder::files($localePath, false, Folder::PATH_BASENAME)); } $defaultPath = $path . '/' . $default; if (is_dir($defaultPath)) { $files = array_merge($files, (array) Folder::files($defaultPath, false, Folder::PATH_BASENAME)); } foreach ($files as $file) { $ext = File::getExtension($file); if (strcasecmp($ext, $format) !== 0) { continue; } Translator::loadFile(File::stripExtension($file), strtolower($format), $package); } }
/** * getPackages * * @return array */ public static function loadPackages() { /* * Get Global Packages * ----------------------------------------- * If you want a package can be used in every applications (for example: Web and Console), * set it in Windwalker\Windwalker object. */ $packages = array_merge(parent::loadPackages(), Windwalker::loadPackages()); $packages = array_merge($packages, (array) Ioc::getConfig()->get('packages')); /* * Get Packages for This Application * ----------------------------------------- * If you want a package only use in this application or want to override a global package, * set it here. Example: $packages[] = new Flower\FlowerPackage; */ // Your packages here... return $packages; }
/** * keepAlive * * @param string $url * @param integer $time * * @return void */ public static function keepAlive($url = './', $time = null) { if (!static::inited(__METHOD__)) { static::core(); if ($time === null) { $config = Ioc::getConfig(); $time = $config->get('session.life_time', 3); $time = $time * 60000; } $js = <<<JS jQuery(document).ready(function(\$) { Phoenix.keepAlive('{$url}', {$time}); }); JS; static::getAsset()->internalScript($js); } }
/** * onAfterWriteFiles * * @return void */ public function onAfterWriteFiles() { include_once __DIR__ . '/../../vendor/autoload.php'; $base = realpath(__DIR__ . '/../../..'); $items = Folder::files($base, true); $sitemap = new Sitemap(); $root = Ioc::getConfig()->get('site.root'); $sitemap->addItem($root, 1.0); foreach ($items as $item) { if (File::getExtension($item) != 'html') { continue; } $loc = str_replace('\\', '/', substr($item, strlen($base) + 1)); $sitemap->addItem($root . '/' . $loc, 0.8, ChangeFreq::WEEKLY, new \DateTime()); } $xml = $sitemap->toString(); file_put_contents($base . '/sitemap.xml', $xml); }
/** * extractConfig * * @param string $template * * @return string */ public function prepareData($template) { $template = explode('---', $template, 3); if (!trim($template[0])) { array_shift($template); $template = implode('---', $template); $template = explode('---', $template, 2); } try { $config = Yaml::parse($template[0]); if ($config) { array_shift($template); } $this->config->loadArray($config); $this->config->merge(Ioc::getConfig()); $this->getData()->bind(array('config' => $this->config->toArray())); // Target permalink if ($this->config['permalink']) { $this->target = rtrim($this->config['permalink'], '/'); if (substr($this->target, -5) != '.html') { $this->target .= '/index.html'; } $this->data->uri['base'] = ProcessorHelper::getBackwards($this->target) ?: './'; $this->data->uri['media'] = ProcessorHelper::getBackwards($this->target) . 'media/'; } else { $this->target = $this->getTarget(); } $template = implode('---', $template); } catch (ParseException $e) { $template = implode('---', $template); } $event = new Event('loadProvider'); $event['data'] = $this->data; $event['processor'] = $this; $dispatcher = Ioc::getDispatcher(); $dispatcher->triggerEvent($event); return $template; }
/** * getToken * * @param string $data * @param string $secret * * @return string */ public static function getToken($data = null, $secret = null) { $secret = $secret ?: Ioc::getConfig()->get('system.secret'); $data = json_encode($data); return md5($secret . $data . uniqid() . CryptHelper::genRandomBytes()); }