/** * @param string $model * @param string $mode * @return bool * @throws AException */ public function model($model, $mode = '') { //force mode alows to load models for ALL extensions to bypass extension enabled only status $force = ''; if ($mode == 'force') { $force = 'all'; } $file = DIR_APP_SECTION . 'model/' . $model . '.php'; if ($this->registry->has('extensions') && ($result = $this->extensions->isExtensionResource('M', $model, $force))) { if (is_file($file)) { $warning = new AWarning("Extension <b>{$result['extension']}</b> override model <b>{$model}</b>"); $warning->toDebug(); } $file = $result['file']; } $class = 'Model' . preg_replace('/[^a-zA-Z0-9]/', '', $model); if (file_exists($file)) { include_once $file; $this->registry->set('model_' . str_replace('/', '_', $model), new $class($this->registry)); } else { if ($mode != 'silent') { throw new AException(AC_ERR_LOAD, 'Error: Could not load model ' . $model . ' from ' . $file); } else { return false; } } }
/** * @param string $model * @param string $mode * @return bool * @throws AException */ public function model($model, $mode = '') { //force mode alows to load models for ALL extensions to bypass extension enabled only status //This might be helpful in storefront. In admin all installed extenions are available $force = ''; if ($mode == 'force') { $force = 'all'; } //mode to force load storefront model $section = DIR_APP_SECTION; if ($mode == 'storefront') { $section = DIR_ROOT . '/storefront/'; } $file = $section . 'model/' . $model . '.php'; if ($this->registry->has('extensions') && ($result = $this->extensions->isExtensionResource('M', $model, $force, $mode))) { if (is_file($file)) { $warning = new AWarning("Extension <b>{$result['extension']}</b> override model <b>{$model}</b>"); $warning->toDebug(); } $file = $result['file']; } $class = 'Model' . preg_replace('/[^a-zA-Z0-9]/', '', $model); $obj_name = 'model_' . str_replace('/', '_', $model); //if modal is loaded return it back if (is_object($this->registry->get($obj_name))) { return $this->registry->get($obj_name); } else { if (file_exists($file)) { include_once $file; $this->registry->set($obj_name, new $class($this->registry)); return $this->registry->get($obj_name); } else { if ($mode != 'silent') { $backtrace = debug_backtrace(); $file_info = $backtrace[0]['file'] . ' on line ' . $backtrace[0]['line']; throw new AException(AC_ERR_LOAD, 'Error: Could not load model ' . $model . ' from ' . $file_info); return false; } else { return false; } } } }
/** * Detect file for default or extension language * @param string $filename * @param string $language_dir_name * @return null|string */ protected function _detect_language_xml_file($filename, $language_dir_name = 'english') { if (empty($filename)) { return null; } $file_path = $this->language_path . $language_dir_name . '/' . $filename . '.xml'; if ($this->registry->has('extensions') && ($result = $this->registry->get('extensions')->isExtensionLanguageFile($filename, $language_dir_name, $this->is_admin))) { if (is_file($file_path)) { $warning = new AWarning("Extension <b>{$result['extension']}</b> overrides language file <b>{$filename}</b>"); $warning->toDebug(); } $file_path = $result['file']; } return $file_path; }
public function addToParent($variable, $value) { if (!empty($this->parent_controller)) { $this->parent_controller->view->append($variable, $value); } else { $wrn = new AWarning('Parent controller called does not exist in ' . get_class($this)); $wrn->toDebug(); } }
/** * Process the template * @param $filename * @return string */ public function fetch($filename) { ADebug::checkpoint('fetch ' . $filename . ' start'); //#PR First see if we have full path to template file. Nothing to do. Higher precedence! if (is_file($filename)) { //#PR set full path $file = $filename; } else { //#PR Build the path to the template file $path = DIR_TEMPLATE; if (!defined('INSTALL')) { $file = $this->_get_template_path($path, '/template/' . $filename, 'full'); } else { $file = $path . $filename; } if ($this->has_extensions && ($result = $this->extensions->isExtensionResource('T', $filename))) { if (is_file($file)) { $warning = new AWarning("Extension <b>" . $result['extension'] . "</b> overrides core template with <b>" . $filename . "</b>"); $warning->toDebug(); } $file = $result['file']; } } if (is_file($file)) { $content = ''; $file_pre = str_replace('.tpl', POSTFIX_PRE . '.tpl', $filename); if ($result = $this->extensions->isExtensionResource('T', $file_pre)) { $content .= $this->_fetch($result['file']); } $content .= $this->_fetch($file); $file_post = str_replace('.tpl', POSTFIX_POST . '.tpl', $filename); if ($result = $this->extensions->isExtensionResource('T', $file_post)) { $content .= $this->_fetch($result['file']); } ADebug::checkpoint('fetch ' . $filename . ' end'); return $content; } else { $error = new AError('Error: Could not load template ' . $filename . '!', AC_ERR_LOAD); $error->toDebug()->toLog(); } return ''; }
/** * @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; }
/** * funtion create table from dataset values and returns multiarray * @param array $dataset_values * @param array $column_names * @param array $order_by * @return array|bool */ private function _createTable($dataset_values = array(), $column_names = array(), $order_by = array()) { if (!$dataset_values || !$this->columnset) { return false; } if ($order_by) { list($order_name, $order_direction, $limit, $offset) = $order_by; } $output = array(); if (is_array($dataset_values)) { foreach ($dataset_values as $row) { // then build order for resorting if ($order_name && $row['dataset_column_name'] == $order_name) { $index[$row['row_id']] = $row["value_" . $this->columnset[$row['dataset_column_id']]['dataset_column_type']]; } if (in_array($row['dataset_column_name'], $column_names) || !$column_names) { if (!isset($row["value_" . $this->columnset[$row['dataset_column_id']]['dataset_column_type']])) { $warning = new AWarning('Dataset inconsistency data issue detected. Dataset ID: ' . $this->dataset_id . '. Column_name: ' . $row['dataset_column_name'] . ' Column data type: ' . $this->columnset[$row['dataset_column_id']]['dataset_column_type']); $warning->toDebug(); } $output[$row['row_id']][$row['dataset_column_name']] = $row["value_" . $this->columnset[$row['dataset_column_id']]['dataset_column_type']]; } } // resort index (row_id) if ($order_name) { $order = $order_direction == 'DESC' ? SORT_DESC : SORT_ASC; array_multisort($index, $order, $output); } // limit-offset if ((int) $limit) { $offset = (int) $offset; $offset = $offset < 0 ? 0 : $offset; $num_rows = sizeof($output); $limit = $limit > $num_rows ? $num_rows : $limit; if ($offset >= $num_rows) { return array(); } $output = array_slice($output, $offset, $limit); } } return $output; }
/** * Process the template * @param $filename * @return string */ public function fetch($filename) { ADebug::checkpoint('fetch ' . $filename . ' start'); //#PR First see if we have full path to template file. Nothing to do. Higher precedence! if (is_file($filename)) { //#PR set full path $file = $filename; } else { //#PR Build the path to the template file $path = DIR_TEMPLATE; if (!defined('INSTALL')) { $file = $this->_get_template_path($path, '/template/' . $filename, 'full'); } else { $file = $path . $filename; } if ($this->has_extensions && ($result = $this->extensions->isExtensionResource('T', $filename))) { if (is_file($file)) { $warning = new AWarning("Extension <b>" . $result['extension'] . "</b> overrides core template with <b>" . $filename . "</b>"); $warning->toDebug(); } $file = $result['file']; } } if (empty($file)) { $error = new AError('Error: Unable to identify file path to template ' . $filename . '! Check blocks in the layout or enable debug mode to get more details. ' . AC_ERR_LOAD); $error->toDebug()->toLog(); return ''; } if (is_file($file)) { $content = ''; $file_pre = str_replace('.tpl', POSTFIX_PRE . '.tpl', $filename); if ($result = $this->extensions->getAllPrePostTemplates($file_pre)) { foreach ($result as $item) { $content .= $this->_fetch($item['file']); } } $content .= $this->_fetch($file); $file_post = str_replace('.tpl', POSTFIX_POST . '.tpl', $filename); if ($result = $this->extensions->getAllPrePostTemplates($file_post)) { foreach ($result as $item) { $content .= $this->_fetch($item['file']); } } ADebug::checkpoint('fetch ' . $filename . ' end'); //Write HTML Cache if we need and can write if ($this->config && $this->config->get('config_html_cache') && $this->html_cache_key) { if ($this->cache->save_html_cache($this->html_cache_key, $content) === false) { $error = new AError('Error: Cannot create HTML cache for file ' . $this->html_cache_key . '! Directory to write cache is not writable', AC_ERR_LOAD); $error->toDebug()->toLog(); } } return $content; } else { $error = new AError('Error: Cannot load template ' . $filename . '! File ' . $file . ' is missing or incorrect. Check blocks in the layout or enable debug mode to get more details. ', AC_ERR_LOAD); $error->toDebug()->toLog(); } return ''; }