Пример #1
0
 /**
  * check that is current loading site is enabled.
  * 
  * @param boolean $site_not_found set return result for site that could not found in sites table db.
  * @return boolean
  */
 public function isSiteEnabled($site_not_found = false)
 {
     if (!is_bool($site_not_found)) {
         $site_not_found = false;
     }
     $cache = new \System\Libraries\Cache();
     $cache->setSubFolder('system/Core/Models/SitesDb.php');
     $server_http_host = isset($_SERVER['HTTP_HOST']) ? strtolower($_SERVER['HTTP_HOST']) : '';
     if ($cache->contains('SitesDb-isSiteEnabled-' . $server_http_host)) {
         $result = $cache->fetch('SitesDb-isSiteEnabled-' . $server_http_host);
     } else {
         $qb = $this->Db->Conn->createQueryBuilder();
         $stmt = $qb->select('site_id', 'site_domain', 'site_status')->from('`' . $this->Db->getTableName('sites') . '`')->where('LOWER(`site_domain`) = :site_domain')->setParameter('site_domain', $server_http_host)->execute();
         $row = $stmt->fetch();
         if ($row !== false) {
             if ($row->site_status == '1') {
                 $result = true;
             } else {
                 $result = false;
             }
         } else {
             $result = $site_not_found;
         }
         unset($qb, $row, $stmt);
         $cache->save('SitesDb-isSiteEnabled-' . $server_http_host, $result, 60 * 60 * 24 * 30);
     }
     unset($cache, $server_http_host);
     if (isset($result)) {
         return $result;
     } else {
         return false;
     }
 }
Пример #2
0
 /**
  * load functions file.
  * 
  * @param mixed $file path to file name start from inside module. this can be file name (string) or multiple file names (array).
  * @param string $module module name.
  * @param boolean $load_again set to false to require_once, set to true to require. use false to prevent function/class exists.
  * @return boolean return true on success loading, return false on failed loading.
  */
 public function loadFunctions($file, $module = '', $load_again = false)
 {
     if (is_array($file)) {
         $last = false;
         foreach ($file as $a_file) {
             $last = $this->loadFunctions($a_file, $module, $load_again);
         }
         return $last;
     }
     $this->Db = $this->Silexapp['Db'];
     if ($module != null) {
         // load function on specified module. check that module is enabled.
         $cache = new \System\Libraries\Cache();
         $cache->setSubFolder('system/Libraries/Modules.php');
         if ($cache->contains('Modules-registerAutoload-' . $this->Db->getCurrentSiteId())) {
             $modules_list = $cache->fetch('Modules-registerAutoload-' . $this->Db->getCurrentSiteId());
         } else {
             $moduledb = new \System\Core\Models\ModulesDb($this->Db);
             $options['module_enable'] = 1;
             $options['site_id'] = intval($this->Db->getCurrentSiteId());
             $options['unlimited'] = true;
             $modules_list = $moduledb->listModulesQb($options);
             $cache->save('Modules-registerAutoload-' . $this->Db->getCurrentSiteId(), $modules_list, 60 * 60 * 24 * 30);
             unset($moduledb, $options);
         }
         if (is_array($modules_list) && array_key_exists('items', $modules_list) && is_array($modules_list['items'])) {
             foreach ($modules_list['items'] as $row) {
                 if ($module == $row->module_system_name) {
                     // found in module enabled.
                     $module_found = true;
                     break;
                 }
             }
             // endforeach;
             unset($row);
         }
         unset($cache, $modules_list);
         if (!isset($module_found) || isset($module_found) && $module_found == false) {
             return false;
         }
     }
     if ($module == null) {
         $file = SYSTEM_PATH . DS . 'Functions' . DS . $file;
     } else {
         $file = MODULE_PATH . DS . $module . DS . 'Functions' . DS . $file;
     }
     return $this->loadFile($file, $load_again);
 }
Пример #3
0
 /**
  * execute command
  * 
  * @param InputInterface $input
  * @param OutputInterface $output
  */
 public function execute(InputInterface $input, OutputInterface $output)
 {
     $subfolder = $input->getOption('subfolder');
     if ($subfolder == null) {
         $output->writeln('<error>Sorry, you did not enter cache sub folder name.</error>');
         unset($subfolder);
         return false;
     }
     if ($subfolder != null) {
         $Cache = new \System\Libraries\Cache();
         $cache_config = $Cache->getCacheConfig();
         $style = new \Symfony\Component\Console\Formatter\OutputFormatterStyle('white', 'green');
         $output->getFormatter()->setStyle('success', $style);
         unset($style);
         if ($subfolder == '*') {
             // entered command to delete all cache.
             $Cache->deleteAllFile();
             $output->writeln('<success>All cache was deleted successfully.</success>');
         } else {
             if (is_array($cache_config) && array_key_exists('driver', $cache_config) && $cache_config['driver'] == 'Filesystem' && array_key_exists('cache_path', $cache_config)) {
                 $adapter = new \League\Flysystem\Adapter\Local($cache_config['cache_path']);
                 $Filesystem = new \League\Flysystem\Filesystem($adapter);
                 $Filesystem->addPlugin(new \League\Flysystem\Plugin\ListPaths());
                 try {
                     $Filesystem->getMetadata($subfolder);
                     // selected sub folder exists.
                     $Cache->setSubFolder($subfolder);
                     $Cache->deleteAllFile();
                     unset($Filesystem);
                     $output->writeln('<success>The cache inside "' . $subfolder . '" folder was deleted successfully.</success>');
                 } catch (\Exception $e) {
                     $output->writeln('<error>The "' . $subfolder . '" cache folder is not found.</error>');
                 }
                 unset($adapter, $Filesystem);
             }
         }
         unset($Cache, $cache_config);
     }
     unset($subfolder);
 }
Пример #4
0
 /**
  * get current site id from HTTP_HOST in $_SERVER.
  * 
  * @param integer $default number of default site_id referrer from sites table. this will be use in case that current host name not found in sites table.
  * @return integer return site_id of current host name.
  */
 public function getCurrentSiteId($default = 1)
 {
     $cache = new \System\Libraries\Cache();
     $cache->setSubFolder('system/Libraries/Db/Db.php');
     if (is_array($_SERVER) && array_key_exists('HTTP_HOST', $_SERVER)) {
         $server_httphost = strtolower($_SERVER['HTTP_HOST']);
     } else {
         $server_httphost = 'console';
     }
     if ($cache->contains('Db-getCurrentSiteId-' . $server_httphost)) {
         \System\Libraries\Log::write('db_connection', 'debug', 'Getting site id using cache name "Db-getCurrentSiteId-' . $server_httphost . '"', [$cache->fetch('Db-getCurrentSiteId-' . $server_httphost)]);
         return $cache->fetch('Db-getCurrentSiteId-' . $server_httphost);
     } else {
         $stmt = $this->prepare('SELECT `site_id`, `site_domain`, `site_status`, `site_settings` FROM `' . $this->getTableName('sites') . '` WHERE LOWER(`site_domain`) = :site_domain AND `site_status` = 1');
         $stmt->bindValue('site_domain', isset($_SERVER['HTTP_HOST']) ? $server_httphost : '');
         $stmt->execute();
         $site = $stmt->fetch();
         unset($stmt);
         if ($site != null) {
             $cache->save('Db-getCurrentSiteId-' . $server_httphost, $site->site_id, 60 * 60 * 24 * 30);
             $cache->save('Db-getCurrentSiteData-' . $site->site_id, $site, 60 * 60 * 24 * 30);
             return $site->site_id;
         } else {
             $cache->save('Db-getCurrentSiteId-' . $server_httphost, $default, 60 * 60 * 24 * 30);
             return $default;
         }
     }
 }
Пример #5
0
 /**
  * list themes up to conditions provided by options.
  * 
  * @param array $options available options: theme_enable, theme_default, theme_default_admin, site_id, search, sort, orders, offset, limit, list_for, unlimited
  * @return array return array with total and items in keys.
  */
 public function listThemes(array $options = [])
 {
     $output = [];
     $cache = new \System\Libraries\Cache();
     $cache->setSubFolder('system/Core/Models/ThemesDb.php');
     $cache_name = 'ThemesDb-listThemes-' . $this->Db->getCurrentSiteId() . '_options_' . md5(serialize($options));
     if ($cache->contains($cache_name)) {
         $output = $cache->fetch($cache_name);
     } else {
         // create query and prepare. first step is for count total.-----------------------------------------
         $sql = 'SELECT * FROM `' . $this->Db->getTableName('themes') . '` AS `t`';
         $sql .= ' LEFT JOIN `' . $this->Db->getTableName('theme_sites') . '` AS `ts` ON t.theme_id = ts.theme_id';
         $sql .= ' WHERE 1';
         if ((!isset($options['list_for']) || isset($options['list_for']) && $options['list_for'] == 'front') && !isset($options['theme_enable'])) {
             $options['theme_enable'] = '1';
         }
         if (isset($options['theme_enable'])) {
             $sql .= ' AND `ts`.`theme_enable` = :theme_enable';
         }
         if (isset($options['theme_default'])) {
             $sql .= ' AND `ts`.`theme_default` = :theme_default';
         }
         if (isset($options['theme_default_admin'])) {
             $sql .= ' AND `ts`.`theme_default_admin` = :theme_default_admin';
         }
         if (isset($options['site_id'])) {
             $sql .= ' AND `ts`.`site_id` = :site_id';
         }
         if (isset($options['search'])) {
             $sql .= ' AND (';
             $sql .= 't.theme_system_name LIKE :search';
             $sql .= ' OR t.theme_version LIKE :search';
             $sql .= ')';
         }
         $sql .= ' GROUP BY `t`.`theme_id`';
         // sort and order
         if (isset($options['sort']) && $options['sort'] == 'theme_id') {
             $options['sort'] = '`t`.`theme_id`';
         }
         if (!isset($options['sort']) || isset($options['sort']) && !in_array($options['sort'], ['theme_id', 't.theme_id', 'theme_system_name', 'theme_version', 'site_id', 'theme_enable', 'theme_default', 'theme_default_admin'])) {
             $options['sort'] = '`t`.`theme_id`';
         }
         if (!isset($options['orders']) || isset($options['orders']) && !in_array($options['orders'], $this->allowed_orders)) {
             $options['orders'] = 'ASC';
         }
         $sql .= ' ORDER BY ' . $options['sort'] . ' ' . $options['orders'];
         $stmt = $this->Conn->prepare($sql);
         // bind values
         $this->bindValues($stmt, $options);
         $stmt->execute();
         $result = $stmt->fetchAll();
         $output['total'] = count($result);
         unset($stmt);
         // re-create query and prepare. second step is for set limit and fetch all items.------------------
         if (!isset($options['unlimited']) || isset($options['unlimited']) && $options['unlimited'] == false) {
             if (!isset($options['offset']) || isset($options['offset']) && !is_numeric($options['offset'])) {
                 $options['offset'] = 0;
             }
             if (!isset($options['limit']) || isset($options['limit']) && !is_numeric($options['limit'])) {
                 $configdb = new \System\Core\Models\ConfigDb($this->Db);
                 if (isset($options['list_for']) && $options['list_for'] == 'admin') {
                     $options['limit'] = $configdb->getConfigValue('content_admin_items_perpage', 10);
                 } else {
                     $options['limit'] = $configdb->getConfigValue('content_items_perpage', 10);
                 }
                 unset($configdb);
             }
             $sql .= ' LIMIT ' . $options['offset'] . ', ' . $options['limit'];
             $stmt = $this->Conn->prepare($sql);
             // bind values
             $this->bindValues($stmt, $options);
             $stmt->execute();
             $result = $stmt->fetchAll();
         }
         // get all related theme_sites to theme_sites property.
         if ($output['total'] > '0' && is_array($result)) {
             $new_result = [];
             $i = 0;
             unset($sql);
             foreach ($result as $row) {
                 $new_row = $row;
                 $sql = 'SELECT * FROM ' . $this->Db->getTableName('theme_sites') . ' WHERE theme_id = :theme_id';
                 $stmt = $this->Conn->prepare($sql);
                 $this->bindValues($stmt, ['theme_id' => $row->theme_id]);
                 $stmt->execute();
                 $result_ts = $stmt->fetchAll();
                 $new_row->theme_sites = $result_ts;
                 $new_result[$i] = $new_row;
                 $i++;
                 unset($new_row, $result_ts, $sql);
             }
             $result = $new_result;
             unset($i, $new_result);
         }
         $output['items'] = $result;
         unset($result, $sql, $stmt);
         $cache->save($cache_name, $output, 60 * 60 * 24 * 30);
     }
     unset($cache, $cache_name);
     return $output;
 }
Пример #6
0
 /**
  * get all available modules.
  * 
  * @return array return array with total and items in key. items key contain list of all modules available.
  */
 public function getAllAvailableModules()
 {
     $this->Db = $this->Silexapp['Db'];
     $cache = new \System\Libraries\Cache();
     $cache->setSubFolder('system/Libraries/Modules.php');
     if ($cache->contains('Modules-registerAutoload-' . $this->Db->getCurrentSiteId())) {
         $modules_list = $cache->fetch('Modules-registerAutoload-' . $this->Db->getCurrentSiteId());
     } else {
         $moduledb = new \System\Core\Models\ModulesDb($this->Db);
         $options['module_enable'] = 1;
         $options['site_id'] = intval($this->Db->getCurrentSiteId());
         $options['unlimited'] = true;
         $modules_list = $moduledb->listModulesQb($options);
         $cache->save('Modules-registerAutoload-' . $this->Db->getCurrentSiteId(), $modules_list, 60 * 60 * 24 * 30);
         unset($moduledb, $options);
     }
     unset($cache, $this->Db);
     return $modules_list;
 }