/** * @param string $filename * @throws AException */ public function __construct($filename) { if (file_exists($filename) && ($info = getimagesize($filename))) { $this->file = $filename; $this->info = array('width' => $info[0], 'height' => $info[1], 'bits' => $info['bits'], 'mime' => $info['mime'], 'channels' => $info['channels']); $this->registry = Registry::getInstance(); $this->image = $this->get_gd_resource($filename); } else { $error = new AError('Error: Cannot load image ' . $filename); $error->toMessages()->toDebug()->toLog(); return false; } return true; }
$template = $config->get('config_storefront_template'); $dir = $template . DIR_EXT_STORE . DIR_EXT_TEMPLATE . $template; } if (in_array($template, $enabled_extensions) && is_dir(DIR_EXT . $dir)) { $is_valid = true; } else { $is_valid = false; } //check if this is default template if (!$is_valid && is_dir(DIR_TEMPLATE . $template)) { $is_valid = true; } } if (!$is_valid) { $error = new AError('Template ' . $template . ' is not found - roll back to default'); $error->toMessages()->toLog()->toDebug(); $template = 'default'; } if (IS_ADMIN) { $config->set('original_admin_template', $config->get('admin_template')); $config->set('admin_template', $template); // Load language $lang_obj = new ALanguageManager($registry); } else { $config->set('original_config_storefront_template', $config->get('config_storefront_template')); $config->set('config_storefront_template', $template); // Load language $lang_obj = new ALanguage($registry); } // Create Global Layout Instance $registry->set('layout', new ALayout($registry, $template));
/** * @param string $parent_controller * @return null|string */ public function dispatch($parent_controller = '') { ADebug::checkpoint('' . $this->class . '/' . $this->method . ' dispatch START'); //Process the controller, layout and children //check if we have missing class or everithing if (empty($this->class) && has_value($this->file)) { #Build back trace of calling functions to provide more details $backtrace = debug_backtrace(); $function_stack = ''; if (is_object($parent_controller) && strlen($parent_controller->rt()) > 1) { $function_stack = 'Parent Controller: ' . $parent_controller->rt() . ' | '; } for ($i = 1; $i < count($backtrace); $i++) { $function_stack .= ' < ' . $backtrace[$i]['function']; } $url = $this->request->server['REQUEST_URI']; $error = new AError('Error: URL: ' . $url . ' Could not load controller ' . $this->controller . '! Call stack: ' . $function_stack . '', AC_ERR_CLASS_CLASS_NOT_EXIST); $error->toLog()->toDebug(); $error->toMessages(); return null; } else { if (empty($this->file) && empty($this->class) || empty($this->method)) { $warning_txt = 'ADispatch: skipping unavailable controller …'; $warning = new AWarning($warning_txt); $warning->toDebug(); return null; } } //check for controller.pre $output_pre = $this->dispatchPrePost($this->controller . POSTFIX_PRE); /** @noinspection PhpIncludeInspection */ require_once $this->file; /** * @var $controller AController */ $controller = null; if (class_exists($this->class)) { $controller = new $this->class($this->registry, $this->args["instance_id"], $this->controller, $parent_controller); $controller->dispatcher = $this; } else { $error = new AError('Error: controller class not exist ' . $this->class . '!', AC_ERR_CLASS_CLASS_NOT_EXIST); $error->toLog()->toDebug(); } if (is_callable(array($controller, $this->method))) { /** * @var $dispatch ADispatcher */ $dispatch = call_user_func_array(array($controller, $this->method), $this->args); //Check if return is a dispatch and need to call new page if ($dispatch && is_object($dispatch)) { if ($this->args["instance_id"] == 0) { //If main controller come back for new dispatch return $dispatch->getController() . '/' . $dispatch->getMethod(); } else { // Call new dispatch for new controller and exit //???? need to put limit for recursion to prevent overflow $dispatch->dispatch(); return null; } } /** * Load layout and process children controllers * @method AController getChildren() */ $children = $controller->getChildren(); ADebug::variable('Processing children of ' . $this->controller, $children); $block_uids = array(); //Process each child controller foreach ($children as $child) { //???? Add highest Debug level here with backtrace to review this ADebug::checkpoint($child['controller'] . ' ( child of ' . $this->controller . ', instance_id: ' . $child['instance_id'] . ' ) dispatch START'); //Process each child and create dispatch to call recurcive $dispatch = new ADispatcher($child['controller'], array("instance_id" => $child['instance_id'])); $dispatch->dispatch($controller); // Append output of child controller to current controller if ($child['position']) { // maden for recognizing few custom_blocks in the same placeholder $controller->view->assign($child['block_txt_id'] . '_' . $child['instance_id'], $this->response->getOutput()); } else { $controller->view->assign($child['block_txt_id'], $this->response->getOutput()); } //clean up and remove output $this->response->setOutput(''); ADebug::checkpoint($child['controller'] . ' ( child of ' . $this->controller . ' ) dispatch END'); } //Request controller to generate output $controller->finalize(); //check for controller.pre $output_post = $this->dispatchPrePost($this->controller . POSTFIX_POST); //add pre and post controllers output $this->response->setOutput($output_pre . $this->response->getOutput() . $output_post); //clean up and destroy the object unset($controller); unset($dispatch); } else { $err = new AError('Error: controller method not exist ' . $this->class . '::' . $this->method . '!', AC_ERR_CLASS_METHOD_NOT_EXIST); $err->toLog()->toDebug(); } ADebug::checkpoint('' . $this->class . '/' . $this->method . ' dispatch END'); return null; }
private function _load_settings() { /** * @var ACache $cache */ $cache = $this->registry->get('cache'); /** * @var ADB */ $db = $this->registry->get('db'); //detect URL for the store $url = str_replace('www.', '', $_SERVER['HTTP_HOST']) . get_url_path($_SERVER['PHP_SELF']); if (defined('INSTALL')) { $url = str_replace('install/', '', $url); } //enable cache storage based on configuration $cache->enableCache(); //set configured driver. $cache_driver = 'file'; if (defined('CACHE_DRIVER')) { $cache_driver = CACHE_DRIVER; } if (!$cache->setCacheStorageDriver($cache_driver)) { $error = new AError('Cache storage driver ' . $cache_driver . ' can not be loaded!'); $error->toMessages()->toLog()->toDebug(); } // Load default store settings $settings = $cache->pull('settings'); if (empty($settings)) { // set global settings (without extensions settings) $sql = "SELECT se.*\n\t\t\t\t\tFROM " . $db->table("settings") . " se\n\t\t\t\t\tWHERE se.store_id = '0'\n\t\t\t\t\t\tAND se.`group` NOT IN (SELECT `key` FROM " . $db->table("extensions") . ")"; $query = $db->query($sql); $settings = $query->rows; foreach ($settings as &$setting) { if ($setting['key'] == 'config_url') { $parsed_url = parse_url($setting['value']); if (empty($parsed_url['scheme'])) { $parsed_url['scheme'] = "http"; } $setting['value'] = $parsed_url['scheme'] . '://' . $parsed_url['host'] . $parsed_url['path']; } if ($setting['key'] == 'config_ssl_url') { $parsed_url = parse_url($setting['value']); if (empty($parsed_url['scheme'])) { $parsed_url['scheme'] = "https"; } $setting['value'] = $parsed_url['scheme'] . '://' . $parsed_url['host'] . $parsed_url['path']; } $this->cnfg[$setting['key']] = $setting['value']; } unset($setting); //unset temp reference //fix for rare issue on a database and creation of empty cache if (!empty($settings) && $this->cnfg['config_cache_enable']) { $cache->push('settings', $settings); } } else { foreach ($settings as $setting) { $this->cnfg[$setting['key']] = $setting['value']; } } //set current store id as default 0 for now. It will be reset if other store detected below $this->cnfg['config_store_id'] = 0; // if storefront and not default store try to load setting for given URL /* Example: Specific store config -> http://localhost/abantecart123 Generic config -> http://localhost */ $config_url = preg_replace("(^https?://)", "", $this->cnfg['config_url']); $config_url = preg_replace("(^://)", "", $config_url); if (!is_int(strpos($config_url, $url)) && !is_int(strpos($url, $config_url))) { // if requested url not a default store URL - do check other stores. $cache_key = 'settings.store.' . md5('http://' . $url); $store_settings = $cache->pull($cache_key); if (empty($store_settings)) { $sql = "SELECT se.`key`, se.`value`, st.store_id\n\t\t \t\t\t FROM " . $db->table('settings') . " se\n\t\t \t\t\t RIGHT JOIN " . $db->table('stores') . " st ON se.store_id = st.store_id\n\t\t \t\t\t WHERE se.store_id = (SELECT DISTINCT store_id FROM " . $db->table('settings') . "\n\t\t \t\t\t WHERE `group`='details'\n\t\t \t\t\t AND\n\t\t \t\t\t ( (`key` = 'config_url' AND (`value` LIKE '%" . $db->escape($url) . "'))\n\t\t \t\t\t XOR\n\t\t \t\t\t (`key` = 'config_ssl_url' AND (`value` LIKE '%" . $db->escape($url) . "')) )\n\t\t LIMIT 0,1)\n\t\t \t\t\t\t\tAND st.status = 1\n\t\t \t\t\t\t\tAND TRIM(se.`group`) NOT IN\n\t (SELECT TRIM(`key`) as `key`\n\t FROM " . $db->table("extensions") . ")"; $query = $db->query($sql); $store_settings = $query->rows; } if ($store_settings) { //store found by URL, load settings foreach ($store_settings as $row) { $value = $row['value']; $this->cnfg[$row['key']] = $value; } //fix for rare issue on a database and creation of empty cache if ($this->cnfg['config_cache_enable']) { $cache->push($cache_key, $store_settings); } $this->cnfg['config_store_id'] = $store_settings[0]['store_id']; } else { $warning = new AWarning('Warning: Accessing store with non-configured or unknown domain ( ' . $url . ' ).' . "\n" . ' Check setting of your store domain URL in System Settings . Loading default store configuration for now.'); $warning->toLog()->toMessages(); //set config url to current domain $this->cnfg['config_url'] = 'http://' . REAL_HOST . get_url_path($_SERVER['PHP_SELF']); } if (!$this->cnfg['config_url']) { $this->cnfg['config_url'] = 'http://' . REAL_HOST . get_url_path($_SERVER['PHP_SELF']); } } //load specific store if admin and set current_store_id for admin operation on store if (IS_ADMIN) { //Check if admin has specific store in session or selected $session = $this->registry->get('session'); $store_id = $this->registry->get('request')->get['store_id']; if (has_value($store_id)) { $this->cnfg['current_store_id'] = (int) $store_id; } else { if (has_value($session->data['current_store_id'])) { $this->cnfg['current_store_id'] = $session->data['current_store_id']; } else { //nothing to do $this->cnfg['current_store_id'] = $session->data['config_store_id']; } } //reload store settings if not what is loaded now if ($this->cnfg['current_store_id'] != $this->cnfg['config_store_id']) { $this->_reload_settings($this->cnfg['current_store_id']); $this->cnfg['config_store_id'] = $this->cnfg['current_store_id']; } } //get template for storefront $tmpl_id = $this->cnfg['config_storefront_template']; //disable cache when it disabled in settings if (!$this->cnfg['config_cache_enable']) { $cache->disableCache(); } // load extension settings $cache_suffix = IS_ADMIN ? 'admin' : $this->cnfg['config_store_id']; $settings = $cache->pull('settings.extension.' . $cache_suffix); if (empty($settings)) { // all extensions settings of store $sql = "SELECT se.*, e.type as extension_type, e.key as extension_txt_id\n\t\t\t\t\tFROM " . $db->table('settings') . " se\n\t\t\t\t\tLEFT JOIN " . $db->table('extensions') . " e ON se.`group` = e.`key`\n\t\t\t\t\tWHERE se.store_id='" . (int) $this->cnfg['config_store_id'] . "' AND e.extension_id IS NOT NULL\n\t\t\t\t\tORDER BY se.store_id ASC, se.group ASC"; $query = $db->query($sql); foreach ($query->rows as $row) { //skip settings for non-active template except status (needed for extensions list in admin) if ($row['extension_type'] == 'template' && $tmpl_id != $row['group'] && $row['key'] != $row['extension_txt_id'] . '_status') { continue; } $settings[] = $row; } //fix for rare issue on a database and creation of empty cache if (!empty($settings)) { $cache->push('settings.extension.' . $cache_suffix, $settings); } } //add encryption key to settings, otherwise use from database (backwards compatibility) if (defined('ENCRYPTION_KEY')) { $setting['encryption_key'] = ENCRYPTION_KEY; } foreach ($settings as $setting) { $this->cnfg[$setting['key']] = $setting['value']; } }