/** * Load definition values from XML * @param string $filename * @param string $directory * @param string $mode * @return array|null */ protected function _load_from_xml($filename, $directory, $mode) { if (!$filename) { return null; } $definitions = array(); ADebug::checkpoint('ALanguage ' . $this->language_details['name'] . ' ' . $filename . ' prepare loading language from XML'); //get default extension language file $default_language_info = $this->getDefaultLanguage(); if ($filename == $directory) { // for common language file (english.xml. russian.xml, etc) $file_name = $default_language_info['filename']; $mode = 'silent'; } else { $file_name = $filename; } $default_file_path = $this->_detect_language_xml_file($file_name, $default_language_info['directory']); // if default language file path wrong - takes english if (!file_exists($default_file_path)) { $file_name = $filename == $directory ? 'english' : $file_name; $default_file_path = $this->_detect_language_xml_file($file_name, 'english'); } // get path to actual language $file_path = $this->_detect_language_xml_file($filename, $this->language_details['directory']); if (file_exists($file_path)) { ADebug::checkpoint('ALanguage ' . $this->language_details['name'] . ' loading XML file ' . $file_path); $definitions = $this->ReadXmlFile($file_path); } else { if (file_exists($default_file_path)) { ADebug::checkpoint('ALanguage ' . $this->language_details['name'] . ' loading XML file ' . $default_file_path); $definitions = $this->ReadXmlFile($default_file_path); } else { if ($mode != 'silent') { $error = new AError('Missing default English definition XML file for ' . $filename . ' !'); $error->toLog()->toDebug(); } } } //skip if not required and language file does not exist for silent mode. if (empty($definitions) && $mode != 'silent') { $error = new AError('Could not load language ' . $filename . ' from file "' . $file_path . '"!'); $error->toLog()->toDebug(); } return $definitions; }
/** * @param $file string - full path of file * @return string */ public function _fetch($file) { if (!file_exists($file)) { return ''; } ADebug::checkpoint('_fetch ' . $file . ' start'); extract($this->data); ob_start(); /** @noinspection PhpIncludeInspection */ require $file; $content = ob_get_contents(); ob_end_clean(); ADebug::checkpoint('_fetch ' . $file . ' end'); return $content; }
/** * Process each table level recursively * @param string $table_name * @param array $table_cfg * @param array $data_arr * @param array $parent_vals * @param bool $action_delete * @return array */ private function _process_import_table($table_name, $table_cfg, $data_arr, $parent_vals = array(), $action_delete = false) { ADebug::checkpoint('AData::importData processing table ' . $table_name); if (!isset($data_arr['rows'])) { $this->_status2array('error', 'Incorrect structure of ' . $table_name . ' node. Row node is expected'); } $new_vals = array(); foreach ($data_arr['rows'] as $rnode) { $action = ''; //Set action for the row if (!$action_delete) { $action = $this->_get_action($table_name, $table_cfg, $rnode); } else { $action = 'delete'; } //set current scope values $new_vals = $parent_vals; if (isset($table_cfg['id']) && isset($rnode[$table_cfg['id']])) { $new_vals[$table_cfg['id']] = $rnode[$table_cfg['id']]; } if (isset($table_cfg['special_relation'])) { foreach ($table_cfg['special_relation'] as $sp_field => $sp_value) { //check if this is relation id to be used for special relation if (in_array($sp_field, $table_cfg['relation_ids'])) { $new_vals[$sp_field] = $new_vals[$sp_value]; } } } else { if ($table_cfg['relation_ids']) { foreach ($table_cfg['relation_ids'] as $relation_id) { if (isset($rnode[$relation_id])) { $new_vals[$relation_id] = $rnode[$relation_id]; } } } } //Validate required keys if wrong donot bother with children exit. if (!$this->_validate_action($action, $table_name, $table_cfg, $new_vals)) { continue; } //Unique case: If this is a resource_map and resource_id is missing we need to create resource library first and get resource_id if ($table_name == 'resource_map' && isset($rnode['tables']) && is_array($rnode['tables'])) { //only one resource can be mapped at the time. $new_table = $rnode['tables'][0]; $sub_table_cfg = $this->model_tool_table_relationships->find_table_cfg($new_table['name'], $table_cfg); if ($sub_table_cfg) { if ($action == 'delete') { $set_action_delete = true; } else { $set_action_delete = false; } $resource_data = $this->_process_import_table($new_table['name'], $sub_table_cfg, $new_table, $new_vals, $set_action_delete); $new_vals['resource_id'] = $resource_data['resource_id']; //Now do the action for the row if any data provided besides keys $new_vals = array_merge($new_vals, $this->_do_fromArray($action, $table_name, $table_cfg, $rnode, $new_vals)); } else { $this->_status2array('error', 'Unknown table: "' . $new_table['name'] . '" requested in relation to table ' . $table_name . '. Exit this node'); } } else { // all other tables //Now do the action for the row if any data provided besides keys $new_vals = array_merge($new_vals, $this->_do_fromArray($action, $table_name, $table_cfg, $rnode, $new_vals)); //locate inner table nodes for recursion if ($table_name != 'resource_map' && isset($rnode['tables']) && is_array($rnode['tables'])) { foreach ($rnode['tables'] as $new_table) { if ($action == 'delete') { $set_action_delete = true; } else { $set_action_delete = false; } $sub_table_cfg = $this->model_tool_table_relationships->find_table_cfg($new_table['name'], $table_cfg); if ($sub_table_cfg) { $this->_process_import_table($new_table['name'], $sub_table_cfg, $new_table, $new_vals, $set_action_delete); } else { $this->_status2array('error', 'Unknown table: "' . $new_table['name'] . '" requested in relation to table ' . $table_name . '. Exit this node'); continue; } } } } } //return last row new (updated) values return $new_vals; }
} // if task details needed for ajax step-by-step run if ($get['mode'] == 'query') { $get['task_name'] = $_GET['task_name']; } $_GET = $get; unset($get); $_GET['s'] = ADMIN_PATH; // sign of admin side for controllers run from dispatcher // Load all initial set up require_once DIR_ROOT . '/core/init.php'; unset($_GET['s']); // not needed anymore ADebug::checkpoint('init end'); // Currency $registry->set('currency', new ACurrency($registry)); //ok... let's start tasks $tm = new ATaskManager(); if ($_GET['mode'] == 'query') { //$output = array(); $tm->getTask(); //TODO: in the future need to add ability json response for task result } elseif ($_GET['mode'] == 'run') { //try to remove execution time limitation (can not work on some hosts!) ini_set("max_execution_time", "0"); //start do tasks one by one $tm->runTasks(); } ADebug::checkpoint('app end'); //display debug info ADebug::display();
/** * Translate provided text to requested language * Configured method is used (default translation is a COPY) * * @param string $source_lang_code - two-letters language code (ISO 639-1) * @param string $src_text * @param string $dest_lang_code - two-letters language code (ISO 639-1) * @param string $translate_method (optional) * @return null * @throws AException */ public function translate($source_lang_code, $src_text, $dest_lang_code, $translate_method = '') { $this->registry->get('extensions')->hk_InitData($this, __FUNCTION__); if (empty($source_lang_code) || empty($src_text) || empty($dest_lang_code)) { return null; } //check what method is selected for translation if (empty($translate_method)) { $translate_method = $this->registry->get('config')->get('translate_method'); } $extensions = $this->registry->get('extensions')->getEnabledExtensions(); if (in_array($translate_method, $extensions)) { $ex_class = DIR_EXT . $translate_method . '/core/translator.php'; if (file_exists($ex_class)) { /** @noinspection PhpIncludeInspection */ require_once $ex_class; } else { throw new AException(AC_ERR_LOAD, 'Error: Could not load translations class ' . $ex_class . '!'); } /** @noinspection PhpUndefinedClassInspection */ $translate_driver = new translator($this->registry->get('config')); /** @noinspection PhpUndefinedMethodInspection */ $result_txt = $translate_driver->translate($source_lang_code, $src_text, $dest_lang_code); if (!$result_txt) { $result_txt = $src_text; } ADebug::checkpoint("AlangugeManager: Translated text: {$src_text} from {$source_lang_code} to {$dest_lang_code}"); } else { //fail over to default 'copy_source_text' method $result_txt = $src_text; } $this->registry->get('extensions')->hk_UpdateData($this, __FUNCTION__); return $result_txt; }
public function callback() { //init controller data $this->extensions->hk_InitData($this, __FUNCTION__); $order_id = $this->session->data['order_id']; $post = $this->request->post; if ($order_id) { $this->loadModel('checkout/order'); $this->loadModel('extension/default_realex'); $this->loadLanguage('default_realex/default_realex'); $pd = unserialize($this->encryption->decrypt($post['MD'])); $signature_result = $this->model_extension_default_realex->verify3DSignature($pd, $post['PaRes']); ADebug::checkpoint('Realex 3D processing'); ADebug::variable('Signature result:' . $signature_result); $v3d = array(); if ($signature_result->result == '00' && (strtoupper($signature_result->threedsecure->status) == 'Y' || strtoupper($signature_result->threedsecure->status) == 'A')) { if (strtoupper($signature_result->threedsecure->status) == 'Y') { $v3d['eci_ref'] = 5; } else { $v3d['eci_ref'] = 6; } $v3d['eci'] = (string) $signature_result->threedsecure->eci; $v3d['cavv'] = (string) $signature_result->threedsecure->cavv; $v3d['xid'] = (string) $signature_result->threedsecure->xid; } else { if ($pd['cc_type'] == 'mc') { $v3d['eci'] = 0; } else { $v3d['eci'] = 7; } // Enrolled but invalid response from ACS. No shift in liability. ECI = 7 if ($signature_result->result == '110' && strtoupper($signature_result->threedsecure->status) == 'Y') { $v3d['eci_ref'] = 4; $v3d['cavv'] = (string) $signature_result->threedsecure->cavv; $v3d['xid'] = (string) $signature_result->threedsecure->xid; } // Incorrect password entered. No shift in liability. ECI = 7 if ($signature_result->result == '00' && strtoupper($signature_result->threedsecure->status) == 'N') { $v3d['eci_ref'] = 7; $v3d['xid'] = (string) $signature_result->threedsecure->xid; } // Authentication Unavailable. No shift in liability. ECI = 7 if ($signature_result->result == '00' && strtoupper($signature_result->threedsecure->status) == 'U') { $v3d['eci_ref'] = 8; $v3d['xid'] = (string) $signature_result->threedsecure->xid; } // Invalid response from ACS. No shift in liability. ECI = 7 if (isset($signature_result->result) && $signature_result->result >= 500 && $signature_result->result < 600) { $v3d['eci_ref'] = 9; } if (!$this->config->get('default_realex_liability_shift')) { // this is the check for liability shift // Merchant does not want to accept, redirect to checkout with message $error = '3D secure authorization failed'; $message = $error; $message .= 'ECI (3D secure) result: (' . $v3d['eci'] . ')'; $message .= 'Timestamp: ' . (string) strftime("%Y%m%d%H%M%S"); $message .= 'Order Reference: ' . (string) $pd['order_ref']; $this->model_checkout_order->update($order_id, $this->config->get('default_realex_status_decline'), $message, FALSE); $this->session->data['error'] = $error; $this->redirect($this->html->getSecureURL('checkout/checkout')); } } $capture_result = $this->model_extension_default_realex->processPayment($pd, $v3d); ADebug::variable('Capture result:' . $capture_result); if ($capture_result->result != '00') { $this->session->data['error'] = (string) $capture_result->message . ' (' . (int) $capture_result->result . ')'; $this->redirect($this->html->getSecureURL('checkout/checkout')); } else { $this->redirect($this->html->getSecureURL('checkout/success')); } } else { $this->redirect($this->html->getSecureURL('account/login')); } }
/** * @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; }
public function send() { //init controller data $this->extensions->hk_InitData($this, __FUNCTION__); $this->loadLanguage('default_stripe/default_stripe'); //validate input $post = $this->request->post; //check if saved cc mode is used if (!$post['use_saved_cc']) { if (empty($post['cc_number'])) { $json['error'] = $this->language->get('error_incorrect_number'); } if (empty($post['cc_owner'])) { $json['error'] = $this->language->get('error_incorrect_name'); } if (empty($post['cc_expire_date_month']) || empty($post['cc_expire_date_year'])) { $json['error'] = $this->language->get('error_incorrect_expiration'); } if (strlen($post['cc_cvv2']) != 3 && strlen($post['cc_cvv2']) != 4) { $json['error'] = $this->language->get('error_incorrect_cvv'); } } if (isset($json['error'])) { $this->load->library('json'); $this->response->setOutput(AJson::encode($json)); return null; } $this->loadModel('checkout/order'); $this->loadModel('extension/default_stripe'); $this->loadLanguage('default_stripe/default_stripe'); $order_id = $this->session->data['order_id']; $order_info = $this->model_checkout_order->getOrder($order_id); // currency code $currency = $this->currency->getCode(); // order amount without decimal delimiter $amount = round($this->currency->convert($this->cart->getFinalTotal(), $this->config->get('config_currency'), $currency), 2) * 100; $cardnumber = preg_replace('/[^0-9]/', '', $post['cc_number']); $cvv2 = preg_replace('/[^0-9]/', '', $post['cc_cvv2']); // Card owner name $cardname = html_entity_decode($post['cc_owner'], ENT_QUOTES, 'UTF-8'); $cardtype = $post['cc_type']; // card expire date mmyy $cardissue = $post['cc_issue']; ADebug::checkpoint('Stripe Payment: Order ID ' . $order_id); $pd = array('amount' => $amount, 'currency' => $currency, 'order_id' => $order_id, 'cc_number' => $cardnumber, 'cc_expire_month' => $post['cc_expire_date_month'], 'cc_expire_year' => $post['cc_expire_date_year'], 'cc_owner' => $cardname, 'cc_cvv2' => $cvv2, 'cc_issue' => $cardissue); $p_result = $this->model_extension_default_stripe->processPayment($pd, $customer_stripe_id); ADebug::variable('Processing payment result: ', $p_result); if ($p_result['error']) { // transaction failed $json['error'] = (string) $p_result['error']; if ($p_result['code']) { $json['error'] .= ' (' . $p_result['code'] . ')'; } } else { if ($p_result['paid']) { $json['success'] = $this->html->getSecureURL('checkout/success'); } else { //Unexpected result $json['error'] = $this->language->get('error_system'); } } //init controller data $this->extensions->hk_UpdateData($this, __FUNCTION__); $this->load->library('json'); $this->response->setOutput(AJson::encode($json)); }