Пример #1
0
 public static function getOptions($name, $scope = '', $default = null)
 {
     $cache = ZCache::getInstance(ZCMS_APPLICATION);
     $optionsCache = $cache->get(self::ZCMS_CACHE_MODEL_CORE_OPTIONS);
     if ($optionsCache === null) {
         $optionsCache = self::initOrUpdateCacheOptions(true);
     }
     if (isset($optionsCache[$name . '_' . $scope])) {
         return $optionsCache[$name . '_' . $scope];
     }
     return $default;
 }
Пример #2
0
 /**
  * Instance construct
  */
 public function __construct()
 {
     $this->language = PhalconDI::getDefault()->get('config')->website->language;
     global $APP_LOCATION;
     if ($APP_LOCATION) {
         $cache = ZCache::getInstance();
         $translation = $cache->get('ZCMS_Core_ZTranslate' . $APP_LOCATION);
         if ($translation === null) {
             $modules = get_child_folder(ROOT_PATH . "/app/{$APP_LOCATION}/");
             $this->addLang(ROOT_PATH . '/app/languages/en-GB/en-GB.php');
             $this->addLang(ROOT_PATH . '/app/languages/' . $this->language . '/' . $this->language . '.php');
             $this->addModuleLang($modules, $APP_LOCATION);
             $cache->save('ZCMS_Core_ZTranslate', $this->translation);
         } else {
             $this->setTranslate($translation);
         }
     }
 }
Пример #3
0
 /**
  * Set default template
  */
 protected final function _setTemplateDefault()
 {
     $config = PDI::getDefault()->get('config');
     $cache = ZCache::getInstance('ZCMS_APPLICATION');
     $templateDefault = $cache->get('DEFAULT_TEMPLATE');
     if ($templateDefault === null) {
         /**
          * @var CoreTemplates $templateDefault
          */
         $templateDefault = CoreTemplates::findFirst('published = 1 AND location = \'frontend\'');
         $templateDefault = $templateDefault->base_name;
         $cache->save('DEFAULT_TEMPLATE', $templateDefault);
     }
     if ($templateDefault) {
         $config->frontendTemplate->defaultTemplate = $templateDefault;
         PDI::getDefault()->set('config', $config);
     }
 }
Пример #4
0
 /**
  * @return mixed|string
  */
 public function widget()
 {
     $html = '';
     if (isset($this->options->slide_show_id)) {
         $cache = ZCache::getInstance();
         $html = $cache->get(self::SLIDE_SHOW_WIDGET_CACHE . $this->options->slide_show_id);
         if ($html === null) {
             /**
              * @var SlideShowItems[] $slideShowItems
              */
             $slideShowItems = SlideShowItems::find(['conditions' => 'id_slide_show = ?0 AND published = 1', 'bind' => [$this->options->slide_show_id], 'order' => 'ordering ASC']);
             if (count($slideShowItems)) {
                 $html .= '<div class="flexslider"><ul class="slides">';
                 foreach ($slideShowItems as $item) {
                     $html .= '<li><a target="' . $item->target . '" href="' . $item->link . '"><img src="' . $item->image . '"/></a></li>';
                 }
                 $html .= ' </ul></div>';
                 $cache->save(self::SLIDE_SHOW_WIDGET_CACHE . $this->options->slide_show_id, $html);
             }
         }
     }
     return $html;
 }
Пример #5
0
 /**
  * Auto load module from database
  */
 public function _initModule()
 {
     //Create new cache
     $cache = ZCache::getInstance(ZCMS_APPLICATION);
     CoreOptions::initOrUpdateCacheOptions();
     //Load module
     $registerModules = $cache->get(self::ZCMS_APPLICATION_CACHE_MODULES);
     if ($registerModules === null) {
         /**
          * @var \Phalcon\Db\Adapter\Pdo\Postgresql $db
          */
         $db = $this->getDI()->get('db');
         $query = 'SELECT base_name, class_name, path FROM core_modules WHERE published = 1';
         $modules = $db->fetchAll($query);
         $registerModules = [];
         foreach ($modules as $module) {
             $registerModules[$module['base_name']] = ['className' => $module['class_name'], 'path' => APP_DIR . $module['path']];
         }
         $cache->save(self::ZCMS_APPLICATION_CACHE_MODULES, $registerModules);
     }
     $this->registerModules($registerModules);
 }
Пример #6
0
 /**
  * Init Services
  *
  * @param mixed $config
  * @param \Phalcon\DiInterface $di
  */
 public function _initServices($di, $config)
 {
     /**
      * The URL component is used to generate all kind of urls in the application
      */
     $di->set('url', function () use($config) {
         $url = new UrlResolver();
         $url->setBaseUri($config->website->baseUri);
         return $url;
     }, true);
     /**
      * Start the session the first time some component request the session service
      */
     $di->set('session', function () use($config) {
         $session = new ZSession(['uniqueId' => $config->auth->salt]);
         $session->start();
         return $session;
     }, true);
     /**
      * Set view cache
      */
     $di->set('viewCache', function () use($config) {
         //Cache data for one day by default
         $frontCache = new FrontendOutput(['lifetime' => $config->viewCache->lifetime]);
         //File backend settings
         $cache = new CacheFile($frontCache, ['cacheDir' => ROOT_PATH . $config->viewCache->dir]);
         return $cache;
     });
     if ($config->modelMetadataCache->status) {
         /**
          * Set models metadata
          */
         $di->set('modelsMetadata', function () use($config) {
             if ($config->modelMetadataCache->type == 'apc') {
                 return new MetaDataApc(['lifetime' => $config->modelMetadataCache->lifetime, 'prefix' => $config->modelMetadataCache->prefix]);
             } else {
                 return new MetadataFiles(['metaDataDir' => ROOT_PATH . '/cache/metadata/', 'lifetime' => $config->modelMetadataCache->lifetime]);
             }
         });
     }
     /**
      * Crypt service
      */
     $di->set('crypt', function () use($config) {
         $crypt = ZCrypt::getInstance();
         $crypt->setKey($config->crypt->key);
         return $crypt;
     });
     /**
      * Set security
      */
     $di->set('security', function () {
         $security = new Security();
         $security->setWorkFactor(8);
         return $security;
     });
     /**
      * Set up database connection
      */
     $di->set('db', function () use($config) {
         $adapter = 'Phalcon\\Db\\Adapter\\Pdo\\' . $config->database->adapter;
         /**
          * @var \Phalcon\Db\Adapter\Pdo\Postgresql $db
          */
         if ($config->database->adapter == 'Mysql') {
             $db = new $adapter($config->database->toArray());
         } else {
             $db = new $adapter(array('host' => $config->database->host, 'username' => $config->database->username, 'password' => $config->database->password, 'dbname' => $config->database->dbname));
         }
         if ($config->database->log) {
             $eventsManager = new EventsManager();
             if (!file_exists(ROOT_PATH . '/cache/logs/db.log')) {
                 file_put_contents(ROOT_PATH . '/cache/logs/db.log', '');
             }
             $logger = new FileLogger(ROOT_PATH . '/cache/logs/db.log');
             //Listen all the database events
             $eventsManager->attach('db', function ($event, $db) use($logger) {
                 /**
                  * @var \Phalcon\Events\Event $event
                  */
                 if ($event->getType() == 'beforeQuery') {
                     /**
                      * @var \Phalcon\Db\Adapter\Pdo\Postgresql $db
                      */
                     $logger->log($db->getSQLStatement(), Logger::INFO);
                 }
             });
             //Assign the eventsManager to the db adapter instance
             $db->setEventsManager($eventsManager);
         }
         return $db;
     });
     /**
      * Set a models manager
      */
     $di->set('modelsManager', new ModelsManager());
     /**
      * Set up model cache for Phalcon model
      */
     $di->set('modelsCache', function () {
         return ZCache::getInstance('_ZCMS_MODEL');
     });
     /**
      * Set up asset add css, js
      */
     $di->set('assets', new ZAssets());
     /**
      * Loading routes from the routes.php file
      */
     $di->set('router', function () {
         return require APP_DIR . '/config/router.php';
     });
     $di->set('acl', ZAcl::getInstance());
     /**
      * Set up the flash service (custom with bootstrap)
      */
     $di->set('flashSession', function () {
         $flashSession = new FlashSession(['warning' => 'alert alert-warning', 'notice' => 'alert alert-info', 'success' => 'alert alert-success', 'error' => 'alert alert-danger']);
         return $flashSession;
     });
     /**
      * Set up cache
      */
     $di->set('cache', ZCache::getInstance('_ZCMS_GLOBAL'));
 }