Exemple #1
0
 /**
  * @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;
         }
     }
 }
Exemple #2
0
 /**
  * @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;
             }
         }
     }
 }
 public function test()
 {
     $this->loadLanguage('default_pp_pro/default_pp_pro');
     $this->loadModel('setting/setting');
     $cfg = $this->model_setting_setting->getSetting('default_pp_pro', (int) $this->session->data['current_store_id']);
     if (!$cfg['default_pp_pro_test']) {
         $api_endpoint = 'https://api-3t.paypal.com/nvp';
     } else {
         $api_endpoint = 'https://api-3t.sandbox.paypal.com/nvp';
     }
     $payment_data = array('METHOD' => 'SetExpressCheckout', 'VERSION' => '98.0', 'USER' => html_entity_decode($cfg['default_pp_pro_username'], ENT_QUOTES, 'UTF-8'), 'PWD' => html_entity_decode($cfg['default_pp_pro_password'], ENT_QUOTES, 'UTF-8'), 'SIGNATURE' => html_entity_decode($cfg['default_pp_pro_signature'], ENT_QUOTES, 'UTF-8'), 'PAYMENTREQUEST_0_PAYMENTACTION' => 'Sale', 'PAYMENTREQUEST_0_AMT' => '10.00', 'PAYMENTREQUEST_0_CURRENCYCODE' => 'USD', 'RETURNURL' => $this->html->getCatalogURL('r/extension/default_pp_pro/callback'), 'CANCELURL' => $this->html->getSecureURL('extension/extensions/edit', '&extension=default_pp_pro'));
     $curl = curl_init($api_endpoint);
     curl_setopt($curl, CURLOPT_PORT, 443);
     curl_setopt($curl, CURLOPT_HEADER, 0);
     curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
     curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
     curl_setopt($curl, CURLOPT_FORBID_REUSE, 1);
     curl_setopt($curl, CURLOPT_FRESH_CONNECT, 1);
     curl_setopt($curl, CURLOPT_POST, 1);
     curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($payment_data));
     $response = curl_exec($curl);
     $curl_error = curl_error($curl);
     curl_close($curl);
     $ec_settings = $this->_parse_http_query($response);
     $json = array();
     if (empty($response)) {
         $warning = new AWarning('CURL Error: ' . $curl_error . '. Test mode = ' . $cfg['default_pp_pro_test'] . '.');
         $warning->toLog()->toDebug();
         $json['message'] = "Connection to PayPal server can not be established.\n" . $curl_error . ".\nCheck your server configuration or contact your hosting provider.";
         $json['error'] = true;
     } elseif (isset($ec_settings['TOKEN'])) {
         $json['message'] = $this->language->get('text_connection_success');
         $json['error'] = false;
     } else {
         $warning = new AWarning('PayPal Error: ' . $ec_settings['L_LONGMESSAGE0'] . '. Test mode = ' . $cfg['default_pp_pro_test'] . '.');
         $warning->toLog()->toDebug();
         $test_mode = $cfg['default_pp_pro_test'] ? 'ON' : 'OFF';
         $json['message'] = 'PayPal Error: ' . $ec_settings['L_LONGMESSAGE0'] . ".\n" . 'Please check your API Credentials and try again.' . "\n" . 'Also please note that Test mode is ' . $test_mode . '!';
         $json['error'] = true;
     }
     $this->load->library('json');
     $this->response->setOutput(AJson::encode($json));
 }
 public function onControllerPagesCheckoutGuestStep2_ProcessData()
 {
     $that = $this->baseObject;
     if ($that->session->data['payment_method']['id'] == 'default_pp_express' && !has_value($that->session->data['pp_express_checkout']['token'])) {
         $that->loadModel('checkout/order');
         if (has_value($that->session->data['order_id'])) {
             $order_info = $that->model_checkout_order->getOrder($that->session->data['order_id']);
         } else {
             if ($that->cart->hasProducts() && $that->cart->hasStock() && ($amount = $that->cart->getFinalTotal())) {
                 $order_info = array('total' => $amount, 'currency' => $that->session->data['currency'], 'value' => '');
             } else {
                 header('Location:' . $that->html->getSecureURL('checkout/cart'));
                 die;
             }
         }
         if (!$that->config->get('default_pp_express_test')) {
             $api_endpoint = 'https://api-3t.paypal.com/nvp';
         } else {
             $api_endpoint = 'https://api-3t.sandbox.paypal.com/nvp';
         }
         if (!$that->config->get('default_pp_express_transaction')) {
             $paymentaction = 'authorization';
         } else {
             $paymentaction = 'sale';
         }
         $order_total = $that->currency->format($order_info['total'], $order_info['currency'], $order_info['value'], FALSE);
         $payment_data = array('METHOD' => 'SetExpressCheckout', 'VERSION' => '98.0', 'USER' => html_entity_decode($that->config->get('default_pp_express_username'), ENT_QUOTES, 'UTF-8'), 'PWD' => html_entity_decode($that->config->get('default_pp_express_password'), ENT_QUOTES, 'UTF-8'), 'SIGNATURE' => html_entity_decode($that->config->get('default_pp_express_signature'), ENT_QUOTES, 'UTF-8'), 'PAYMENTREQUEST_0_PAYMENTACTION' => $paymentaction, 'PAYMENTREQUEST_0_AMT' => $order_total, 'PAYMENTREQUEST_0_CURRENCYCODE' => $order_info['currency'], 'RETURNURL' => $that->html->getSecureURL('r/extension/default_pp_express/callback'), 'CANCELURL' => $that->request->server['HTTP_REFERER']);
         $that->loadLanguage('default_pp_express/default_pp_express');
         $products_data = $this->_get_products_data(array('currency' => $order_info['currency'], 'value' => $order_info['value']));
         if ($this->data['items_total'] - $order_total !== 0.0) {
             $payment_data['L_PAYMENTREQUEST_0_ITEMAMT'] = $order_total;
             $skip_item_list = true;
         }
         if (!$skip_item_list) {
             foreach ($products_data as $key => $product) {
                 //$payment_data['L_PAYMENTREQUEST_0_ITEMAMT'] += $this->data['items_total'];
                 $payment_data['L_PAYMENTREQUEST_0_NAME' . $key] = $product['name'];
                 $payment_data['L_PAYMENTREQUEST_0_AMT' . $key] = (double) $product['price'];
                 $payment_data['L_PAYMENTREQUEST_0_NUMBER' . $key] = $product['model'];
                 $payment_data['L_PAYMENTREQUEST_0_QTY' . $key] = $product['quantity'];
                 $payment_data['L_PAYMENTREQUEST_0_ITEMWEIGHTVALUE' . $key] = $product['weight'];
                 $payment_data['L_PAYMENTREQUEST_0_ITEMWEGHTUNIT' . $key] = $product['weight_type'];
             }
         } else {
             $payment_data['L_PAYMENTREQUEST_0_NAME0'] = $that->language->get('text_order_total_amount');
             $payment_data['L_PAYMENTREQUEST_0_AMT0'] = $order_total;
             $payment_data['L_PAYMENTREQUEST_0_NUMBER0'] = '';
             $payment_data['L_PAYMENTREQUEST_0_QTY0'] = 1;
             $payment_data['L_PAYMENTREQUEST_0_ITEMWEIGHTVALUE0'] = '';
             $payment_data['L_PAYMENTREQUEST_0_ITEMWEGHTUNIT0'] = '';
         }
         if (has_value($order_info['shipping_method'])) {
             $payment_data['PAYMENTREQUEST_0_SHIPTONAME'] = $order_info['shipping_firstname'] . ' ' . $order_info['shipping_lastname'];
             $payment_data['PAYMENTREQUEST_0_SHIPTOSTREET'] = $order_info['shipping_address_1'];
             $payment_data['PAYMENTREQUEST_0_SHIPTOSTREET2'] = $order_info['shipping_address_2'];
             $payment_data['PAYMENTREQUEST_0_SHIPTOCITY'] = $order_info['shipping_city'];
             $payment_data['PAYMENTREQUEST_0_SHIPTOSTATE'] = $order_info['shipping_zone'];
             $payment_data['PAYMENTREQUEST_0_SHIPTOZIP'] = $order_info['shipping_postcode'];
             $payment_data['PAYMENTREQUEST_0_SHIPTOCOUNTRYCODE'] = $order_info['shipping_iso_code_2'];
             $payment_data['PAYMENTREQUEST_0_SHIPTOPHONENUM'] = $order_info['telephone'];
         }
         if ($that->config->get('default_pp_express_credit_cards')) {
             $payment_data['SOLUTIONTYPE'] = 'Sole';
             $payment_data['LANDINGPAGE'] = 'Billing';
         }
         if ($that->config->get('default_pp_express_billmelater') && has_value($that->request->get['fundsource']) && strtolower($that->request->get['fundsource']) == 'bml') {
             $payment_data['SOLUTIONTYPE'] = 'Sole';
             $payment_data['LANDINGPAGE'] = 'Billing';
             $payment_data['USERSELECTEDFUNDINGSOURCE'] = 'BML';
         }
         if (has_value($that->config->get('default_pp_express_custom_logo'))) {
             if (strpos($that->config->get('default_pp_express_custom_logo'), 'http') === 0) {
                 $custom_logo = $that->config->get('default_pp_express_custom_logo');
             } else {
                 $custom_logo = HTTPS_SERVER . $that->config->get('default_pp_express_custom_logo');
             }
             $payment_data['LOGOIMG'] = $custom_logo;
         }
         if (has_value($that->config->get('default_pp_express_custom_bg_color'))) {
             $payment_data['CARTBORDERCOLOR'] = $that->config->get('default_pp_express_custom_bg_color');
         }
         $curl = curl_init($api_endpoint);
         curl_setopt($curl, CURLOPT_PORT, 443);
         curl_setopt($curl, CURLOPT_HEADER, 0);
         curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
         curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
         curl_setopt($curl, CURLOPT_FORBID_REUSE, 1);
         curl_setopt($curl, CURLOPT_FRESH_CONNECT, 1);
         curl_setopt($curl, CURLOPT_POST, 1);
         curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($payment_data));
         $response = curl_exec($curl);
         curl_close($curl);
         $ec_settings = $this->_parse_http_query($response);
         if (isset($ec_settings['TOKEN'])) {
             if (!$that->config->get('default_pp_express_test')) {
                 header('Location: https://www.paypal.com/webscr?cmd=_express-checkout&token=' . urlencode($ec_settings['TOKEN']) . '&useraction=commit');
                 die;
             } else {
                 header('Location: https://www.sandbox.paypal.com/webscr?cmd=_express-checkout&token=' . urlencode($ec_settings['TOKEN']) . '&useraction=commit');
                 die;
             }
         } else {
             $warning = new AWarning('PayPal Express Checkout Error: ' . $ec_settings['L_LONGMESSAGE0'] . '. Test mode = ' . $that->config->get('default_pp_express_test') . '.');
             $warning->toLog()->toDebug()->toMessages();
             $that->loadLanguage('default_pp_express/default_pp_express');
             $that->session->data['pp_express_checkout_error'] = $that->language->get('service_error');
             header('Location: ' . $that->html->getSecureURL('extension/default_pp_express/error'));
             die;
         }
     }
 }
 public function set_pp()
 {
     $this->loadLanguage('default_pp_express/default_pp_express');
     if ($this->cart->hasProducts() && $this->cart->hasStock() && ($amount = $this->cart->getFinalTotal())) {
         //do not allow redirecting to paypal side for nonlogged users when guest-checkout is disabled
         if (!$this->config->get('config_guest_checkout') && !$this->customer->isLogged()) {
             $this->session->data['redirect'] = $this->html->getCatalogURL('r/extension/default_pp_express/set_pp');
             $this->redirect($this->html->getSecureURL('account/login'));
             return null;
         }
         if (!$this->config->get('default_pp_express_test')) {
             $api_endpoint = 'https://api-3t.paypal.com/nvp';
         } else {
             $api_endpoint = 'https://api-3t.sandbox.paypal.com/nvp';
         }
         if (!$this->config->get('default_pp_express_transaction')) {
             $paymentaction = 'authorization';
         } else {
             $paymentaction = 'sale';
         }
         $products_data = $this->_get_products_data(array('currency' => $this->session->data['currency'], 'value' => ''));
         $language = $this->language->getCurrentLanguage();
         $locale = explode(',', $language['locale']);
         $order_total = (double) $this->currency->format_number($amount, $this->session->data['currency']);
         $payment_data = array('METHOD' => 'SetExpressCheckout', 'VERSION' => '98.0', 'USER' => html_entity_decode($this->config->get('default_pp_express_username'), ENT_QUOTES, 'UTF-8'), 'PWD' => html_entity_decode($this->config->get('default_pp_express_password'), ENT_QUOTES, 'UTF-8'), 'SIGNATURE' => html_entity_decode($this->config->get('default_pp_express_signature'), ENT_QUOTES, 'UTF-8'), 'PAYMENTREQUEST_0_PAYMENTACTION' => $paymentaction, 'PAYMENTREQUEST_0_AMT' => $order_total, 'PAYMENTREQUEST_0_CURRENCYCODE' => $this->session->data['currency'], 'RETURNURL' => $this->html->getSecureURL('r/extension/default_pp_express/callback', $this->request->get['to_confirm'] ? '&to_confirm=1' : ''), 'CANCELURL' => has_value($this->request->get['redirect_to']) ? $this->request->get['redirect_to'] : $this->request->server['HTTP_REFERER'], 'LOCALECODE' => $locale[1]);
         if ($this->data['items_total'] - $order_total !== 0.0) {
             $payment_data['L_PAYMENTREQUEST_0_ITEMAMT'] = $order_total;
             $skip_item_list = true;
         }
         if (!$skip_item_list) {
             foreach ($products_data as $key => $product) {
                 $payment_data['L_PAYMENTREQUEST_0_NAME' . $key] = $product['name'];
                 $payment_data['L_PAYMENTREQUEST_0_AMT' . $key] = (double) $product['price'];
                 $payment_data['L_PAYMENTREQUEST_0_NUMBER' . $key] = $product['model'];
                 $payment_data['L_PAYMENTREQUEST_0_QTY' . $key] = $product['quantity'];
                 $payment_data['L_PAYMENTREQUEST_0_ITEMWEIGHTVALUE' . $key] = $product['weight'];
                 $payment_data['L_PAYMENTREQUEST_0_ITEMWEGHTUNIT' . $key] = $product['weight_type'];
             }
         } else {
             $payment_data['L_PAYMENTREQUEST_0_NAME0'] = $this->language->get('text_order_total_amount');
             $payment_data['L_PAYMENTREQUEST_0_AMT0'] = $order_total;
             $payment_data['L_PAYMENTREQUEST_0_NUMBER0'] = '';
             $payment_data['L_PAYMENTREQUEST_0_QTY0'] = 1;
             $payment_data['L_PAYMENTREQUEST_0_ITEMWEIGHTVALUE0'] = '';
             $payment_data['L_PAYMENTREQUEST_0_ITEMWEGHTUNIT0'] = '';
         }
         if ($this->config->get('default_pp_express_credit_cards')) {
             $payment_data['SOLUTIONTYPE'] = 'Sole';
             $payment_data['LANDINGPAGE'] = 'Billing';
         }
         if ($this->config->get('default_pp_express_billmelater') && has_value($this->request->get['fundsource']) && strtolower($this->request->get['fundsource']) == 'bml') {
             $payment_data['SOLUTIONTYPE'] = 'Sole';
             $payment_data['LANDINGPAGE'] = 'Billing';
             $payment_data['USERSELECTEDFUNDINGSOURCE'] = 'BML';
         }
         if (has_value($this->config->get('default_pp_express_custom_logo'))) {
             $payment_data['LOGOIMG'] = HTTPS_SERVER . 'resources/' . $this->config->get('default_pp_express_custom_logo');
         }
         if (has_value($this->config->get('default_pp_express_custom_bg_color'))) {
             $payment_data['CARTBORDERCOLOR'] = ltrim($this->config->get('default_pp_express_custom_bg_color'), '#');
         }
         ADebug::variable('Paypal Express Debug Log Sent setpp:', var_export($payment_data, true));
         $curl = curl_init($api_endpoint);
         curl_setopt($curl, CURLOPT_PORT, 443);
         curl_setopt($curl, CURLOPT_HEADER, 0);
         curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
         curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
         curl_setopt($curl, CURLOPT_FORBID_REUSE, 1);
         curl_setopt($curl, CURLOPT_FRESH_CONNECT, 1);
         curl_setopt($curl, CURLOPT_POST, 1);
         curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($payment_data));
         $response = curl_exec($curl);
         curl_close($curl);
         $ec_settings = $this->_parse_http_query($response);
         ADebug::variable('Paypal Express Debug Log Received setpp:', var_export($ec_settings, true));
         if (isset($ec_settings['TOKEN'])) {
             if (!$this->config->get('default_pp_express_test')) {
                 $this->redirect('https://www.paypal.com/webscr?cmd=_express-checkout&token=' . urlencode($ec_settings['TOKEN']));
                 // . '&useraction=commit');
             } else {
                 $this->redirect('https://www.sandbox.paypal.com/webscr?cmd=_express-checkout&token=' . urlencode($ec_settings['TOKEN']));
                 // . '&useraction=commit');
             }
         } else {
             $warning = new AWarning('PayPal Express Checkout Error: ' . $ec_settings['L_LONGMESSAGE0'] . '. Test mode = ' . $this->config->get('default_pp_express_test') . '.');
             $warning->toLog()->toDebug();
             $this->session->data['pp_express_checkout_error'] = $this->language->get('service_error');
             $this->redirect($this->html->getSecureURL('extension/default_pp_express/error'));
         }
     } else {
         $this->redirect($this->html->getSecureURL('checkout/cart'));
     }
 }
 public function __construct()
 {
     $this->extensions_dir = array();
     $this->db_extensions = array();
     $this->missing_extensions = array();
     $extensions = glob(DIR_EXT . '*', GLOB_ONLYDIR);
     if ($extensions) {
         foreach ($extensions as $ext) {
             //skip other directory not containing extensions
             if (is_file($ext . '/config.xml')) {
                 $this->extensions_dir[] = str_replace(DIR_EXT, '', $ext);
             }
         }
     }
     $registry = Registry::getInstance();
     if ($registry->has('db')) {
         $this->db = $registry->get('db');
         //get extensions from db
         $query = $this->getExtensionsList();
         foreach ($query->rows as $result) {
             $this->db_extensions[] = $result['key'];
         }
         //check if we have extensions that has record in db, but missing files
         // if so, disable them
         $this->missing_extensions = array_diff($this->db_extensions, $this->extensions_dir);
         if (!empty($this->missing_extensions)) {
             foreach ($this->missing_extensions as $ext) {
                 $warning = new AWarning($ext . ' directory is missing');
                 $warning->toMessages();
             }
         }
         //check if we have extensions in dir that has no record in db
         $diff = array_diff($this->extensions_dir, $this->db_extensions);
         if (!empty($diff)) {
             foreach ($diff as $ext) {
                 $data['key'] = $ext;
                 $data['status'] = 0;
                 $misext = new ExtensionUtils($ext);
                 $data['type'] = $misext->getConfig('type');
                 $data['version'] = $misext->getConfig('version');
                 $data['priority'] = $misext->getConfig('priority');
                 $data['category'] = $misext->getConfig('category');
                 $data['license_key'] = $registry->get('session')->data['package_info']['extension_key'];
                 if ($registry->has('extension_manager')) {
                     $registry->get('extension_manager')->add($data);
                 }
             }
         }
     }
 }
 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();
     }
 }
Exemple #8
0
 /**
  * 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 '';
 }
Exemple #9
0
 /**
  * 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;
 }
Exemple #10
0
 /**
  * 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 '';
 }
 /**
  * @param object $layout
  * @param object $block
  * @param int $parent_instance_id
  * @return bool
  */
 private function _processBlock($layout, $block, $parent_instance_id = 0)
 {
     $instance_id = null;
     $layout_id = (int) $layout->layout_id;
     $layout_name = $layout->name;
     if ((string) $block->type) {
         $this->_processCustomBlock($layout_id, $block, $parent_instance_id);
         return true;
     } elseif ((string) $block->kind == 'custom') {
         $this->_processCustomBlock($layout_id, $block, $parent_instance_id);
         return true;
     }
     $restricted = true;
     if (!in_array($block->block_txt_id, $this->main_placeholders)) {
         $restricted = false;
     }
     //NOTE $restricted blocks can only be linked to layout. Can not be deleted or updated
     //try to get block_id to see if it exists
     $sql = "SELECT block_id\n\t\t\t\tFROM " . $this->db->table("blocks") . " \n\t\t\t\tWHERE block_txt_id = '" . $this->db->escape($block->block_txt_id) . "'";
     $result = $this->db->query($sql);
     $block_id = (int) $result->row['block_id'];
     $action = (string) $block->action;
     if (!$block_id && in_array($action, array("", null, "update"))) {
         //if block does not exist, we need to insert new one
         $action = 'insert';
     }
     if (has_value($block_id) && $action == 'delete') {
         //try to delete the block if exists
         $this->_deleteBlock($block, $layout_id);
     } else {
         if ($action == 'insert') {
             //If block exists with same block_txt_id, log error and continue
             if ($block_id) {
                 $error_text = 'Layout (' . $layout_name . ') XML error: Cannot insert block (block_txt_id: "' . $block->block_txt_id . '"). Block already exists!';
                 $error = new AError($error_text);
                 $error->toLog()->toDebug();
                 $this->errors = 1;
             } else {
                 //if block does not exists - insert and get a new block_id
                 $sql = "INSERT INTO " . $this->db->table("blocks") . " (block_txt_id, controller, date_added) \n\t\t\t\t\t\tVALUES ('" . $this->db->escape($block->block_txt_id) . "', '" . $this->db->escape($block->controller) . "',NOW())";
                 if (!$block->controller) {
                     $error_text = 'Layout (' . $layout_name . ') XML error: Missing controller for new block (block_txt_id: "' . $block->block_txt_id . '"). This block might not function properly!';
                     $error = new AError($error_text);
                     $error->toLog()->toDebug();
                     $this->errors = 1;
                 }
                 $this->db->query($sql);
                 $block_id = $this->db->getLastId();
                 $position = (int) $block->position;
                 //if parent block exists add positioning
                 if ($parent_instance_id && !$position) {
                     $sql = "SELECT MAX(position) as maxpos\n\t\t\t\t\t\t\tFROM " . $this->db->table("block_layouts") . " \n\t\t\t\t\t\t\tWHERE  parent_instance_id = " . (int) $parent_instance_id;
                     $result = $this->db->query($sql);
                     $position = $result->row['maxpos'] + 10;
                 }
                 $position = !$position ? 10 : $position;
                 $sql = "INSERT INTO " . $this->db->table("block_layouts") . " (layout_id,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tblock_id,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tparent_instance_id,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tposition,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tstatus,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tdate_added)\n\t\t\t\t\t\tVALUES ('" . (int) $layout_id . "',\n\t\t\t\t\t\t\t\t'" . (int) $block_id . "',\n\t\t\t\t\t\t\t\t'" . (int) $parent_instance_id . "',\n\t\t\t\t\t\t\t\t'" . (int) $position . "',\n\t\t\t\t\t\t\t\t'" . 1 . "',\n\t\t\t\t\t\t\t\tNOW())";
                 $this->db->query($sql);
                 $instance_id = $this->db->getLastId();
                 $sql = array();
                 //insert new block details
                 if ($block->block_descriptions->block_description) {
                     foreach ($block->block_descriptions->block_description as $block_description) {
                         $language_id = $this->_getLanguageIdByName(mb_strtolower((string) $block_description->language, 'UTF-8'));
                         //if loading language does not exists or installed, skip
                         if ($language_id) {
                             $this->language->replaceDescriptions('block_descriptions', array('instance_id' => (int) $instance_id, 'block_id' => (int) $block_id), array((int) $language_id => array('name' => (string) $block_description->name, 'title' => (string) $block_description->title, 'description' => (string) $block_description->description, 'content' => (string) $block_description->content)));
                         }
                     }
                 }
                 //insert new block tempalte
                 //Idealy, block needs to have a template set, but template can be set in the controller for the block.
                 if ($block->templates->template) {
                     foreach ($block->templates->template as $block_template) {
                         // parent block_id by parent_name
                         $query = "SELECT block_id\n\t\t\t\t\t\t\t\t  FROM " . $this->db->table("blocks") . " \n\t\t\t\t\t\t\t\t  WHERE block_txt_id = '" . $this->db->escape($block_template->parent_block) . "'";
                         $result = $this->db->query($query);
                         $parent_block_id = $result->row['block_id'];
                         $sql[] = "INSERT INTO " . $this->db->table("block_templates") . " (block_id,parent_block_id,template,date_added)\n\t\t\t\t\t\t\t\t   VALUES ('" . (int) $block_id . "',\n\t\t\t\t\t\t\t\t\t\t\t'" . (int) $parent_block_id . "',\n\t\t\t\t\t\t\t\t\t\t\t'" . $this->db->escape($block_template->template_name) . "',NOW())";
                     }
                 }
                 foreach ($sql as $query) {
                     $this->db->query($query);
                 }
             }
         } else {
             //other update action
             if ($block_id) {
                 //update non restricted blocks and blocks for current template only.
                 //this will update blocks that present only in this template
                 $query = "SELECT count(*) as total\n\t\t\t\t\t  FROM " . $this->db->table("block_layouts") . " bl\n\t\t\t\t\t  INNER JOIN " . $this->db->table("layouts") . " l on l.layout_id = bl.layout_id\t\t\t\t\t  \n\t\t\t\t\t  WHERE bl.block_id='" . $block_id . "' AND l.template_id <> '" . $layout->template_id . "'";
                 $result = $this->db->query($query);
                 if ($result->row['total'] == 0 && !$restricted) {
                     $sql = "UPDATE " . $this->db->table("blocks") . " \n\t\t\t\t\t\t\tSET controller = '" . $this->db->escape($block->controller) . "' \n\t\t\t\t\t\t\tWHERE block_id='" . $block_id . "'";
                     $this->db->query($sql);
                     $sql = array();
                     // insert block's info
                     if ($block->block_descriptions->block_description) {
                         foreach ($block->block_descriptions->block_description as $block_description) {
                             $language_id = $this->_getLanguageIdByName(mb_strtolower((string) $block_description->language, 'UTF-8'));
                             //if loading language does not exists or installed, log error on update
                             if (!$language_id) {
                                 $error = "ALayout_manager Error. Unknown language for block descriptions.'." . "(Block_id=" . $block_id . ", name=" . (string) $block_description->name . ", " . "title=" . (string) $block_description->title . ", " . "description=" . (string) $block_description->description . ", " . "content=" . (string) $block_description->content . ", " . ")";
                                 $this->log->write($error);
                                 $this->message->saveError('layout import error', $error);
                                 continue;
                             }
                             $this->language->replaceDescriptions('block_descriptions', array('block_id' => (int) $block_id), array((int) $language_id => array('name' => (string) $block_description->name, 'title' => (string) $block_description->title, 'description' => (string) $block_description->description, 'content' => (string) $block_description->content)));
                         }
                     }
                     if ($block->templates->template) {
                         foreach ($block->templates->template as $block_template) {
                             // parent block_id by parent_name
                             $query = "SELECT block_id\n\t\t\t\t\t\t\t\t\t  FROM " . $this->db->table("blocks") . " \n\t\t\t\t\t\t\t\t\t  WHERE block_txt_id = '" . $this->db->escape($block_template->parent_block) . "'";
                             $result = $this->db->query($query);
                             $parent_block_id = $result->row ? $result->row['block_id'] : 0;
                             $query = "SELECT block_id\n\t\t\t\t\t\t\t\t\t  FROM " . $this->db->table("block_templates") . " \n\t\t\t\t\t\t\t\t\t  WHERE block_id = '" . $block_id . "'\n\t\t\t\t\t\t\t\t\t\t  AND parent_block_id = '" . $parent_block_id . "'";
                             $result = $this->db->query($query);
                             $exists = $result->row ? $result->row['block_id'] : 0;
                             if (!$parent_block_id) {
                                 $error_text = 'Layout (' . $layout_name . ') XML error: block template "' . $block_template->template_name . '" (block_txt_id: "' . $block->block_txt_id . '") have not parent block!';
                                 $error = new AError($error_text);
                                 $error->toLog()->toDebug();
                                 $this->errors = 1;
                             }
                             if ($exists) {
                                 $sql[] = "UPDATE " . $this->db->table("block_templates") . " \n\t\t\t\t\t\t\t\t\t\t   SET parent_block_id = '" . (int) $parent_block_id . "',\n\t\t\t\t\t\t\t\t\t\t\t   template = '" . $this->db->escape($block_template->template_name) . "'\n\t\t\t\t\t\t\t\t\t\t   WHERE block_id='" . $block_id . "' AND parent_block_id='" . $parent_block_id . "'";
                             } else {
                                 $sql[] = "INSERT INTO " . $this->db->table("block_templates") . " (block_id,parent_block_id,template,date_added)\n\t\t\t\t\t\t\t\t\t\t\tVALUES ('" . (int) $block_id . "',\n\t\t\t\t\t\t\t\t\t\t\t\t\t'" . (int) $parent_block_id . "',\n\t\t\t\t\t\t\t\t\t\t\t\t\t'" . $this->db->escape($block_template->template_name) . "',NOW())";
                             }
                         }
                     }
                     foreach ($sql as $query) {
                         $this->db->query($query);
                     }
                 } else {
                     if (!$restricted) {
                         //log warning if try to update exsting block with new controller or template
                         if ($block->templates || $block->controller) {
                             $error_text = 'Layout (' . $layout_name . ') XML warning: Block (block_txt_id: "' . $block->block_txt_id . '") cannot be updated. This block is used by another template(s)! Will be linked to existing block';
                             $error = new AWarning($error_text);
                             $error->toLog()->toDebug();
                         }
                     }
                 }
                 // end of check for use
                 //Finally relate block with current layout
                 $query = "SELECT *\n\t\t\t\t\t\t\tFROM " . $this->db->table("block_layouts") . " \n\t\t\t\t\t\t\tWHERE layout_id = '" . (int) $layout_id . "'\n\t\t\t\t\t\t\t\t\tAND block_id = '" . (int) $block_id . "'\n\t\t\t\t\t\t\t\t\tAND parent_instance_id = '" . (int) $parent_instance_id . "'";
                 $result = $this->db->query($query);
                 $exists = $result->row['instance_id'];
                 $status = $block->status ? (int) $block->status : 1;
                 if (!$exists && $layout->action != "delete") {
                     $position = (int) $block->position;
                     // if parent block exists add positioning
                     if ($parent_instance_id && !$position) {
                         $sql = "SELECT MAX(position) as maxpos\n\t\t\t\t\t\t\t\tFROM " . $this->db->table("block_layouts") . " \n\t\t\t\t\t\t\t\tWHERE  parent_instance_id = " . (int) $parent_instance_id;
                         $result = $this->db->query($sql);
                         $position = $result->row['maxpos'] + 10;
                     }
                     $position = !$position ? 10 : $position;
                     $query = "INSERT INTO " . $this->db->table("block_layouts") . " \n\t\t\t\t\t\t\t\t\t(layout_id,\n\t\t\t\t\t\t\t\t\tblock_id,\n\t\t\t\t\t\t\t\t\tparent_instance_id,\n\t\t\t\t\t\t\t\t\tposition,\n\t\t\t\t\t\t\t\t\tstatus,\n\t\t\t\t\t\t\t\t\tdate_added)\n\t\t\t\t\t\t\t  VALUES (  '" . (int) $layout_id . "',\n\t\t\t\t\t\t\t  \t\t\t'" . (int) $block_id . "',\n\t\t\t\t\t\t\t  \t\t\t'" . (int) $parent_instance_id . "',\n\t\t\t\t\t\t\t\t\t    '" . (int) $position . "',\n\t\t\t\t\t\t\t\t\t    '" . $status . "',\n\t\t\t\t\t\t\t\t\t    NOW())";
                     $this->db->query($query);
                     $instance_id = (int) $this->db->getLastId();
                 }
             }
             // end if block_id
         }
     }
     // end of update block
     // start recursion for all included blocks
     if ($block->block) {
         foreach ($block->block as $childblock) {
             $this->_processBlock($layout, $childblock, $instance_id);
         }
     }
     return true;
 }
 private function _load_settings()
 {
     /**
      * @var ACache
      */
     $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);
     }
     // Load default store settings
     $settings = $cache->force_get('settings', '', 0);
     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\tLEFT JOIN " . $db->table("extensions") . " e ON TRIM(se.`group`) = TRIM(e.`key`)\n\t\t\t\t\tWHERE se.store_id='0' AND e.extension_id IS NULL";
         $query = $db->query($sql);
         $settings = $query->rows;
         foreach ($settings as &$setting) {
             if ($setting['key'] == 'config_url') {
                 $parsed_url = parse_url($setting['value']);
                 $setting['value'] = 'http://' . $parsed_url['host'] . $parsed_url['path'];
             }
             if ($setting['key'] == 'config_ssl_url') {
                 $parsed_url = parse_url($setting['value']);
                 $setting['value'] = 'https://' . $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)) {
             $cache->force_set('settings', $settings, '', 0);
         }
     } else {
         foreach ($settings as $setting) {
             $this->cnfg[$setting['key']] = $setting['value'];
         }
     }
     // 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_name = 'settings.store.' . md5('http://' . $url);
         $store_settings = $cache->force_get($cache_name);
         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  LEFT JOIN " . $db->table('extensions') . " e ON TRIM(se.`group`) = TRIM(e.`key`)\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 AND e.extension_id IS NULL";
             $query = $db->query($sql);
             $store_settings = $query->rows;
             //fix for rare issue on a database and creation of empty cache
             if (!empty($store_settings)) {
                 $cache->force_set($cache_name, $store_settings);
             }
         }
         if ($store_settings) {
             //store found by URL, load settings
             foreach ($store_settings as $row) {
                 $value = $row['value'];
                 $this->cnfg[$row['key']] = $value;
             }
             $this->cnfg['config_store_id'] = $store_settings[0]['store_id'];
         } else {
             $warning = new AWarning('Warning: Accessing store with unconfigured 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']);
         }
     }
     //still no store? load default store or session based
     if (is_null($this->cnfg['config_store_id'])) {
         $this->cnfg['config_store_id'] = 0;
         if (IS_ADMIN) {
             //if admin and specific store 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'] = $this->cnfg['config_store_id'] = (int) $store_id;
             } else {
                 if (has_value($session->data['current_store_id'])) {
                     $this->cnfg['config_store_id'] = $session->data['current_store_id'];
                 }
             }
         }
         $this->_reload_settings($this->cnfg['config_store_id']);
     } else {
         $this->cnfg['current_store_id'] = $this->cnfg['config_store_id'];
     }
     //get template for storefront
     $tmpl_id = $this->cnfg['config_storefront_template'];
     // load extension settings
     $cache_suffix = IS_ADMIN ? 'admin' : $this->cnfg['config_store_id'];
     $settings = $cache->force_get('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 (TRIM(se.`group`) = TRIM(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->force_set('settings.extension.' . $cache_suffix, $settings);
         }
     }
     //add encryption key to settings, overwise use from database (backwards compatability)
     if (defined('ENCRYPTION_KEY')) {
         $setting['encryption_key'] = ENCRYPTION_KEY;
     }
     foreach ($settings as $setting) {
         $this->cnfg[$setting['key']] = $setting['value'];
     }
 }
Exemple #13
0
    public function edit()
    {
        //init controller data
        $this->extensions->hk_InitData($this, __FUNCTION__);
        $this->document->addScript($this->view->templateResource('/javascript/jquery/thickbox/thickbox-compressed.js'));
        $this->document->addStyle(array('href' => $this->view->templateResource('/javascript/jquery/thickbox/thickbox.css'), 'rel' => 'stylesheet', 'media' => 'screen'));
        $this->document->resetBreadcrumbs();
        $this->document->addBreadcrumb(array('href' => $this->html->getSecureURL('index/home'), 'text' => $this->language->get('text_home'), 'separator' => FALSE));
        $this->document->addBreadcrumb(array('href' => $this->html->getSecureURL('extension/extensions/' . $this->session->data['extension_filter']), 'text' => $this->language->get('heading_title'), 'separator' => ' :: '));
        $extension = $this->request->get['extension'];
        $this->loadLanguage('extension/extensions');
        $this->loadLanguage($extension . '/' . $extension);
        $store_id = (int) $this->config->get('config_store_id');
        if ($this->request->get_or_post('store_id')) {
            $store_id = $this->request->get_or_post('store_id');
        }
        $ext = new ExtensionUtils($extension, $store_id);
        $settings = $ext->getSettings();
        $extension_info = $this->extensions->getExtensionInfo($extension);
        if (!$extension_info) {
            // if extension is not installed yet - redirect to list
            $this->redirect($this->html->getSecureURL('extension/extensions'));
        }
        /** build aform with settings**/
        $result = array('resource_field_list' => array());
        // store switcher for default store Cntrol Panel only
        if (!$this->config->get('config_store_id')) {
            $stores = array();
            $stores[0] = $this->language->get('text_default');
            $this->loadModel('setting/store');
            $stores_arr = $this->model_setting_store->getStores();
            if (count($stores_arr) > 1) {
                foreach ($stores_arr as $res) {
                    $stores[$res['store_id']] = $res['alias'];
                }
                $switcher = array('name' => 'store_id', 'type' => 'selectbox', 'options' => $stores, 'value' => $store_id, 'note' => $this->language->get('tab_store'), 'style' => 'no-save');
            } else {
                $switcher = array('type' => 'hidden', 'name' => 'store_id', 'note' => ' ', 'value' => 0);
            }
        } else {
            $switcher = array('type' => 'hidden', 'name' => 'store_id', 'note' => ' ', 'value' => $store_id);
        }
        array_unshift($settings, $switcher);
        foreach ($settings as $item) {
            $data = array();
            if ($item['name'] == $extension . '_status') {
                $status = $item['value'];
            }
            $data['name'] = $item['name'];
            $data['type'] = $item['type'];
            $data['value'] = $item['value'];
            $data['required'] = (bool) $item['required'];
            if ($item['note']) {
                $data['note'] = $item['note'];
            } else {
                $note_text = $this->language->get($data['name']);
                // if text definition not found - seek it in default settings definitions
                if ($note_text == $data['name']) {
                    $new_text_key = str_replace($extension . '_', 'text_', $data['name']);
                    $note_text = $this->language->get($new_text_key);
                    if ($note_text == $new_text_key) {
                        $note_text = $this->language->get($new_text_key . '_' . $extension_info['type']);
                    }
                }
                $data['note'] = $note_text;
            }
            if ($item['style']) {
                $data['style'] = $item['style'];
            }
            if ($item['attr']) {
                $data['attr'] = $item['attr'];
            }
            if ($item['readonly']) {
                $data['readonly'] = $item['readonly'];
            }
            switch ($data['type']) {
                case 'selectbox':
                case 'multiselectbox':
                case 'checkboxgroup':
                    // if options need to extract from db
                    $data['options'] = $item['options'];
                    if ($item['model_rt'] != '') {
                        //force to load models even before extension is enabled
                        $this->loadModel($item['model_rt'], 'force');
                        $model = $this->{'model_' . str_replace("/", "_", $item['model_rt'])};
                        $method_name = $item['method'];
                        if (method_exists($model, $method_name)) {
                            $res = call_user_func(array($model, $method_name));
                            if ($res) {
                                $field1 = $item['field1'];
                                $field2 = $item['field2'];
                                foreach ($res as $opt) {
                                    $data['options'][$opt[$field1]] = $opt[$field2];
                                }
                            }
                        }
                    }
                    if ($data['type'] == 'checkboxgroup' || $data['type'] == 'multiselectbox') {
                        #custom settings for multivalue
                        $data['scrollbox'] = 'true';
                        if (substr($item['name'], -2) != '[]') {
                            $data['name'] = $item['name'] . "[]";
                        }
                    }
                    break;
                case 'resource':
                    $item['resource_type'] = (string) $item['resource_type'];
                    if (!$result['rl_scripts']) {
                        $scripts = $this->dispatch('responses/common/resource_library/get_resources_scripts', array('object_name' => '', 'object_id' => '', 'types' => $item['resource_type'], 'mode' => 'url'));
                        $result['rl_scripts'] = $scripts->dispatchGetOutput();
                        unset($scripts);
                    }
                    //preview of resource
                    $resource = new AResource($item['resource_type']);
                    $resource_id = $resource->getIdFromHexPath(str_replace($item['resource_type'] . '/', '', $item['value']));
                    $preview = $this->dispatch('responses/common/resource_library/get_resource_html_single', array('type' => 'image', 'wrapper_id' => $item['name'], 'resource_id' => $resource_id, 'field' => $item['name']));
                    $item['value'] = $preview->dispatchGetOutput();
                    if ($data['value']) {
                        $data = array('note' => $data['note'], 'name' => $item['name'], 'type' => 'hidden');
                        if ($resource_id) {
                            $resource_info = $resource->getResource($resource_id);
                            $data['value'] = $item['resource_type'] . '/' . $resource_info['resource_path'];
                        }
                    }
                    $result['resource_field_list'][$item['name']]['value'] = $item['value'];
                    $result['resource_field_list'][$item['name']]['resource_type'] = $item['resource_type'];
                    $result['resource_field_list'][$item['name']]['resource_id'] = $resource_id;
                    break;
                default:
            }
            $item = HtmlElementFactory::create($data);
            $result['html'][$data['name']] = array('note' => $data['note'], 'value' => $item->getHtml());
        }
        // end building aform
        $this->data['settings'] = $result['html'];
        $this->data['resource_field_list'] = $result['resource_field_list'];
        $this->data['resource_edit_link'] = $this->data['resources_scripts'] = $result['rl_scripts'];
        $this->data['target_url'] = $this->html->getSecureURL('extension/extensions/edit', '&extension=' . $extension . '&store_id=' . $store_id);
        if (isset($this->request->get['restore']) && $this->request->get['restore']) {
            $this->extension_manager->editSetting($extension, $ext->getDefaultSettings());
            $this->cache->delete('settings.extension');
            $this->session->data['success'] = $this->language->get('text_restore_success');
            $this->redirect($this->data['target_url']);
        }
        if ($this->request->server['REQUEST_METHOD'] == 'POST' && $this->_validateSettings($extension, $store_id)) {
            foreach ($settings as $item) {
                if (!isset($this->request->post[$item['name']])) {
                    $this->request->post[$item['name']] = 0;
                }
            }
            $this->extension_manager->editSetting($extension, $this->request->post);
            $this->cache->delete('settings.extension');
            $this->session->data['success'] = $this->language->get('text_success');
            $this->redirect($this->data['target_url']);
        }
        $conflict_resources = $ext->validateResources();
        if (!empty($conflict_resources)) {
            ob_start();
            print_r($conflict_resources);
            $err = ob_get_clean();
            ADebug::warning('resources conflict', AC_ERR_USER_WARNING, $extension . ' Extension resources conflict detected.<br/><pre>' . $err . '</pre>');
        }
        $this->document->setTitle($this->language->get($extension . '_name'));
        $this->document->addBreadcrumb(array('href' => $this->data['target_url'], 'text' => $this->language->get($extension . '_name'), 'separator' => ' :: '));
        $this->data['heading_title'] = $this->language->get($extension . '_name');
        $this->data['text_version'] = $this->language->get('text_version');
        $this->data['text_installed_on'] = $this->language->get('text_installed_on');
        $this->data['text_date_added'] = $this->language->get('text_date_added');
        $this->data['text_license'] = $this->language->get('text_license');
        $this->data['text_dependency'] = $this->language->get('text_dependency');
        $this->data['text_configuration_settings'] = $this->language->get('text_configuration_settings');
        $this->data['button_back'] = $this->html->buildButton(array('name' => 'btn_back', 'text' => $this->language->get('text_back'), 'style' => 'button2'));
        $this->data['button_reload'] = $this->html->buildButton(array('name' => 'btn_reload', 'text' => $this->language->get('text_reload'), 'style' => 'button2'));
        $this->data['button_restore_defaults'] = $this->html->buildButton(array('name' => 'button_restore_defaults', 'text' => $this->language->get('button_restore_defaults'), 'style' => 'button2'));
        $this->data['button_save'] = $this->html->buildButton(array('name' => 'btn_save', 'text' => $this->language->get('button_save'), 'style' => 'button1'));
        $this->data['button_save_green'] = $this->html->buildButton(array('name' => 'btn_save', 'text' => $this->language->get('button_save'), 'style' => 'button3'));
        $this->data['button_reset'] = $this->html->buildButton(array('name' => 'btn_reset', 'text' => $this->language->get('text_reset'), 'style' => 'button2'));
        $this->data['reload'] = $this->html->getSecureURL('extension/extensions/edit/', '&extension=' . $extension);
        $this->data['back'] = $this->html->getSecureURL('extension/extensions/' . $this->session->data['extension_filter']);
        $this->data['update'] = $this->html->getSecureURL('listing_grid/extension/update', '&id=' . $extension . '&store_id=' . $store_id);
        $this->data['dependants_url'] = $this->html->getSecureURL('listing_grid/extension/dependants');
        $form = new AForm();
        $form->setForm(array('form_name' => 'editSettings'));
        $this->data['form']['form_open'] = $form->getFieldHtml(array('type' => 'form', 'name' => 'editSettings', 'attr' => 'confirm-exit="true"', 'action' => $this->html->getSecureURL('extension/extensions/edit/', '&action=save&extension=' . $extension . '&store_id=' . $store_id)));
        if (!$this->extension_manager->validateDependencies($extension, getExtensionConfigXml($extension))) {
            $this->error['warning'] = 'This extension cannot be enabled because required dependency missing or not enabled.';
        }
        if (isset($this->error['warning'])) {
            $this->data['error_warning'] = $this->error['warning'];
        } else {
            $this->data['error_warning'] = '';
        }
        if (isset($this->session->data['success'])) {
            $this->data['success'] = $this->session->data['success'];
            unset($this->session->data['success']);
        } else {
            $this->data['success'] = '';
        }
        if (isset($this->session->data['error'])) {
            $this->data['error_warning'] = $this->session->data['error'];
            unset($this->session->data['error']);
        } else {
            $this->data['error'] = '';
        }
        $icon_ext_img_url = HTTP_CATALOG . 'extensions/' . $extension . '/image/icon.png';
        $icon_ext_dir = DIR_EXT . $extension . '/image/icon.png';
        $icon = is_file($icon_ext_dir) ? $icon_ext_img_url : RDIR_TEMPLATE . 'image/default_extension.png';
        $extension_data = array('id' => $extension);
        $missing_extensions = $this->extensions->getMissingExtensions();
        if (!in_array($extension, $missing_extensions)) {
            $extension_data['icon'] = $icon;
            $extension_data['name'] = $this->language->get($extension . '_name');
            $extension_data['version'] = $extension_info['version'];
            $long_datetime_format = $this->language->get('date_format_long') . ' ' . $this->language->get('time_format');
            if ($extension_info['date_installed']) {
                $extension_data['installed'] = dateISO2Display($extension_info['date_installed'], $long_datetime_format);
            }
            if ($extension_info['create_date']) {
                $extension_data['create_date'] = dateISO2Display($extension_info['create_date'], $long_datetime_format);
            }
            $extension_data['license'] = $extension_info['license_key'];
            $extension_data['note'] = $ext->getConfig('note') ? $this->html->convertLinks($this->language->get($extension . '_note')) : '';
            $config = $ext->getConfig();
            if (!empty($config->preview->item)) {
                foreach ($config->preview->item as $item) {
                    if (!is_file(DIR_EXT . $extension . DIR_EXT_IMAGE . (string) $item)) {
                        continue;
                    }
                    $extension_data['preview'][] = HTTPS_EXT . $extension . DIR_EXT_IMAGE . (string) $item;
                }
            }
            if (isset($this->session->data['extension_updates'][$extension])) {
                $extension_data['upgrade'] = array('text' => $this->html->buildButton(array('id' => 'upgradenow', 'name' => 'btn_upgrade', 'text' => $this->language->get('button_upgrade'), 'style' => 'button1')), 'link' => AEncryption::addEncoded_stid($this->session->data['extension_updates'][$extension]['url']));
            }
            $extension_data['help'] = array('text' => $this->html->buildButton(array('name' => 'btn_help', 'text' => $this->language->get('text_help'), 'style' => 'button2')), 'ext_link' => $ext->getConfig('help_link'));
            if ($ext->getConfig('help_file')) {
                $extension_data['help']['file'] = true;
                $extension_data['help']['file_link'] = $this->html->getSecureURL('extension/extension/help', '&extension=' . $this->request->get['extension']);
                $this->data['text_more_help'] = $this->language->get('text_more_help');
            }
            $extension_data['dependencies'] = array();
            $extension_data['extensions'] = $this->extensions->getEnabledExtensions();
            $missing_extensions = $this->extensions->getMissingExtensions();
            $db_extensions = $this->extensions->getDbExtensions();
            if (isset($config->dependencies->item)) {
                foreach ($config->dependencies->item as $item) {
                    $id = (string) $item;
                    if (in_array($id, $db_extensions)) {
                        if (in_array($id, $missing_extensions)) {
                            $class = 'warning';
                            $action = str_replace('%EXT%', $id, $this->language->get('text_missing_extension')) . '<a class="btn_action" target="_blank" href="' . $this->html->getSecureURL('extension/extensions/delete', '&extension=' . $id) . '"
										onclick="return confirm(\'' . $this->language->get('text_delete_confirm') . '\')" title="' . $this->language->get('text_delete') . '">' . '<img src="' . RDIR_TEMPLATE . 'image/icons/icon_grid_delete.png" alt="' . $this->language->get('text_delete') . '" />' . '</a>';
                        } else {
                            if (!$this->config->has($id . '_status')) {
                                $class = 'attention';
                                $action = '<a class="btn_action" target="_blank" href="' . $this->html->getSecureURL('extension/extensions/install', '&extension=' . $id) . '"
								title="' . $this->language->get('text_install') . '">' . '<img src="' . RDIR_TEMPLATE . 'image/icons/icon_grid_install.png" alt="' . $this->language->get('text_install') . '" />' . '</a>' . '<a class="btn_action" target="_blank" href="' . $this->html->getSecureURL('extension/extensions/delete', '&extension=' . $id) . '"
									  onclick="return confirm(\'' . $this->language->get('text_delete_confirm') . '\')" title="' . $this->language->get('text_delete') . '">' . '<img src="' . RDIR_TEMPLATE . 'image/icons/icon_grid_delete.png" alt="' . $this->language->get('text_delete') . '" />' . '</a>';
                            } else {
                                $action = '<a id="action_edit_' . $id . '" target="_blank" class="btn_action"
												href="' . $this->html->getSecureURL('extension/extensions/edit', '&extension=' . $id) . '"
												title="' . $this->language->get('text_edit') . '">' . '<img src="' . RDIR_TEMPLATE . 'image/icons/icon_grid_edit.png" alt="' . $this->language->get('text_edit') . '" /></a>';
                                if (!(bool) $item['required']) {
                                    $action .= '<a class="btn_action" target="_blank" href="' . $this->html->getSecureURL('extension/extensions/uninstall', '&extension=' . $id) . '"
									  onclick="return confirm(\'' . str_replace('%extension%', $id, $this->language->get('text_uninstall_confirm')) . '\')"
									  title="' . $this->language->get('text_uninstall') . '">' . '<img src="' . RDIR_TEMPLATE . 'image/icons/icon_grid_uninstall.png" alt="' . $this->language->get('text_uninstall') . '" />' . '</a>';
                                }
                            }
                        }
                    } else {
                        $action = '<a href="' . $this->html->getSecureURL('extension/extensions_store', '&extension=' . $id) . '" target="_blank">';
                        $action = str_replace('%extensions_store%', $action, $this->language->get('text_visit_repository'));
                    }
                    $extension_data['dependencies'][] = array('required' => (bool) $item['required'], 'id' => $id, 'status' => ($this->config->has($id . '_status') ? $this->language->get('text_installed') : $this->language->get('text_not_installed')) . ' (' . ($this->config->get($id . '_status') ? $this->language->get('text_enabled') : $this->language->get('text_disabled')) . ' )', 'action' => $action, 'class' => $class);
                    unset($class);
                }
            }
        } else {
            // if extension missing
            $extension_data['icon'] = $icon;
            $extension_data['name'] = str_replace('%EXT%', $extension, $this->language->get('text_missing_extension'));
        }
        // additional settings page
        if ($ext->getConfig('additional_settings') && $status) {
            $btn_param = array('name' => 'btn_addsett', 'text' => $this->language->get('text_additional_settings'), 'style' => 'button1');
            $this->data['add_sett']['link'] = $this->html->getSecureURL($ext->getConfig('additional_settings'));
            if ($store_id) {
                $this->loadModel('setting/store');
                $store_info = $this->model_setting_store->getStore($store_id);
                $this->data['add_sett']['link'] = $store_info['config_url'] . '?s=' . ADMIN_PATH . '&rt=' . $ext->getConfig('additional_settings');
                $this->data['add_sett']['onclick'] = 'onclick="return confirm(\'' . $this->language->get('additional_settings_confirm') . '\');"';
            }
            $this->data['add_sett']['text'] = $this->html->buildButton($btn_param);
        }
        $this->data['extension'] = $extension_data;
        $this->data['target_url'] = $this->html->getSecureURL('extension/extensions/edit', '&extension=' . $extension);
        $this->view->assign('help_url', $this->gen_help_url('extension_edit'));
        $template = 'pages/extension/extensions_edit.tpl';
        //#PR set custom templates for extension settings page.
        if (has_value((string) $config->custom_settings_template)) {
            //build path to template directory.
            $dir_template = DIR_EXT . $extension . DIR_EXT_ADMIN . DIR_EXT_TEMPLATE . $this->config->get('admin_template') . "/template/";
            $dir_template .= (string) $config->custom_settings_template;
            //validate template and report issue
            if (!file_exists($dir_template)) {
                $warning = new AWarning("Cannot load override template {$dir_template} in extension {$extension}!");
                $warning->toLog()->toDebug();
            } else {
                $template = $dir_template;
            }
        }
        $this->view->batchAssign($this->data);
        $this->processTemplate($template);
        //update controller data
        $this->extensions->hk_UpdateData($this, __FUNCTION__);
    }
Exemple #14
0
 public function edit()
 {
     //init controller data
     $this->extensions->hk_InitData($this, __FUNCTION__);
     $extension = $this->request->get['extension'];
     if (!$extension) {
         $this->redirect($this->html->getSecureURL('extension/extensions'));
     }
     $this->document->resetBreadcrumbs();
     $this->document->addBreadcrumb(array('href' => $this->html->getSecureURL('index/home'), 'text' => $this->language->get('text_home'), 'separator' => FALSE));
     $this->document->addBreadcrumb(array('href' => $this->html->getSecureURL('extension/extensions/' . $this->session->data['extension_filter']), 'text' => $this->language->get('heading_title'), 'separator' => ' :: '));
     $this->loadLanguage('extension/extensions');
     $this->loadLanguage($extension . '/' . $extension);
     $store_id = (int) $this->session->data['current_store_id'];
     if ($this->request->get_or_post('store_id')) {
         $store_id = $this->request->get_or_post('store_id');
     }
     $ext = new ExtensionUtils($extension, $store_id);
     $settings = $ext->getSettings();
     $this->data['extension_info'] = $this->extensions->getExtensionInfo($extension);
     if (!$this->data['extension_info']) {
         // if extension is not installed yet - redirect to list
         $this->redirect($this->html->getSecureURL('extension/extensions'));
     }
     $this->data['extension_info']['id'] = $extension;
     $this->data['form_store_switch'] = $this->html->getStoreSwitcher();
     /** build aform with settings**/
     $form = new AForm('HS');
     $form->setForm(array('form_name' => 'editSettings', 'update' => $this->html->getSecureURL('listing_grid/extension/update', '&id=' . $extension . '&store_id=' . $store_id)));
     $this->data['form']['form_open'] = $form->getFieldHtml(array('type' => 'form', 'name' => 'editSettings', 'attr' => 'data-confirm-exit="true" class="aform form-horizontal"', 'action' => $this->html->getSecureURL('extension/extensions/edit/', '&action=save&extension=' . $extension . '&store_id=' . $store_id)));
     $result = array('resource_field_list' => array());
     foreach ($settings as $item) {
         $data = array();
         if ($item['name'] == $extension . '_status') {
             $data['attr'] = ' reload_on_save="true"';
             $status = $item['value'];
             //set sign for confirmation modal about dependendants for disable action
             if ($item['value'] == 1) {
                 $children = $this->extension_manager->getChildrenExtensions($extension);
                 if ($children) {
                     foreach ($children as $child) {
                         if ($this->config->get($child['key'] . '_status')) {
                             $this->data['has_dependants'] = true;
                             break;
                         }
                     }
                 }
             }
         }
         $data['name'] = $item['name'];
         $data['type'] = $item['type'];
         $data['value'] = $item['value'];
         $data['required'] = (bool) $item['required'];
         if ($item['note']) {
             $data['note'] = $item['note'];
         } else {
             $note_text = $this->language->get($data['name']);
             // if text definition not found - seek it in default settings definitions
             if ($note_text == $data['name']) {
                 $new_text_key = str_replace($extension . '_', 'text_', $data['name']);
                 $note_text = $this->language->get($new_text_key);
                 if ($note_text == $new_text_key) {
                     $note_text = $this->language->get($new_text_key . '_' . $this->data['extension_info']['type']);
                 }
             }
             $data['note'] = $note_text;
         }
         if ($item['style']) {
             $data['style'] = $item['style'];
         }
         if ($item['attr']) {
             $data['attr'] = $item['attr'];
         }
         if ($item['readonly']) {
             $data['readonly'] = $item['readonly'];
         }
         switch ($data['type']) {
             case 'selectbox':
             case 'multiselectbox':
             case 'checkboxgroup':
                 // if options need to extract from db
                 $data['options'] = $item['options'];
                 if ($item['model_rt'] != '') {
                     //force to load models even before extension is enabled
                     $this->loadModel($item['model_rt'], 'force');
                     $model = $this->{'model_' . str_replace("/", "_", $item['model_rt'])};
                     $method_name = $item['method'];
                     if (method_exists($model, $method_name)) {
                         $res = call_user_func(array($model, $method_name));
                         if ($res) {
                             $field1 = $item['field1'];
                             $field2 = $item['field2'];
                             foreach ($res as $opt) {
                                 $data['options'][$opt[$field1]] = $opt[$field2];
                             }
                         }
                     }
                 }
                 if ($data['type'] == 'checkboxgroup' || $data['type'] == 'multiselectbox') {
                     #custom settings for multivalue
                     $data['scrollbox'] = 'true';
                     if (substr($item['name'], -2) != '[]') {
                         $data['name'] = $item['name'] . "[]";
                     }
                     $data['style'] = "chosen";
                 }
                 break;
             case 'html_template':
                 // if options need to extract from db
                 $data['template'] = $item['template'];
                 $data['options'] = $item['options'];
                 if ($item['model_rt'] != '') {
                     //force to load models even before extension is enabled
                     $this->loadModel($item['model_rt'], 'force');
                     $model = $this->{'model_' . str_replace("/", "_", $item['model_rt'])};
                     $method_name = $item['method'];
                     if (method_exists($model, $method_name)) {
                         $data['options'][$method_name] = call_user_func(array($model, $method_name));
                     }
                 }
                 break;
             case 'checkbox':
                 $data['style'] = "btn_switch";
                 if ($item['name'] == $extension . '_status') {
                     $data['style'] .= " status_switch";
                 }
                 break;
             case 'resource':
                 $item['resource_type'] = (string) $item['resource_type'];
                 $data['rl_types'] = array($item['resource_type']);
                 $data['rl_type'] = $item['resource_type'];
                 //check if ID for resource is provided or path
                 if (is_numeric($item['value'])) {
                     $data['resource_id'] = $item['value'];
                 } else {
                     $data['resource_path'] = $item['value'];
                 }
                 if (!$result['rl_scripts']) {
                     $scripts = $this->dispatch('responses/common/resource_library/get_resources_scripts', array('object_name' => '', 'object_id' => '', 'types' => array($item['resource_type']), 'onload' => true, 'mode' => 'single'));
                     $result['rl_scripts'] = $scripts->dispatchGetOutput();
                     unset($scripts);
                 }
                 break;
             default:
         }
         $html = '';
         //if template process diffrently
         if (has_value((string) $data['template'])) {
             //build path to template directory.
             $dir_template = DIR_EXT . $extension . DIR_EXT_ADMIN . DIR_EXT_TEMPLATE . $this->config->get('admin_template') . "/template/" . $data['template'];
             //validate template and report issue
             if (!file_exists($dir_template)) {
                 $warning = new AWarning(sprintf($this->language->get('error_could_not_load_override'), $dir_template, $extension));
                 $warning->toLog()->toDebug();
             } else {
                 $this->view->batchAssign($data);
                 $html = $this->view->fetch($dir_template);
             }
         } else {
             $html = $form->getFieldHtml($data);
         }
         $result['html'][$data['name']] = array('note' => $data['note'], 'value' => $html);
     }
     // end building aform
     $this->data['settings'] = $result['html'];
     $this->data['resources_scripts'] = $result['rl_scripts'];
     $this->data['target_url'] = $this->html->getSecureURL('extension/extensions/edit', '&extension=' . $extension . '&store_id=' . $store_id);
     //check if we restore settings to default values
     if (isset($this->request->get['restore']) && $this->request->get['restore']) {
         $this->extension_manager->editSetting($extension, $ext->getDefaultSettings());
         $this->cache->delete('settings.extension');
         $this->session->data['success'] = $this->language->get('text_restore_success');
         $this->redirect($this->data['target_url']);
     }
     //check if we save settings with the post
     if ($this->request->is_POST() && $this->_validateSettings($extension, $store_id)) {
         $save_data = $this->request->post;
         foreach ($settings as $item) {
             if (!isset($this->request->post[$item['name']])) {
                 $save_data[$item['name']] = 0;
             }
         }
         $save_data['store_id'] = $store_id;
         $this->extension_manager->editSetting($extension, $save_data);
         $this->cache->delete('settings.extension');
         $this->session->data['success'] = $this->language->get('text_save_success');
         $this->redirect($this->data['target_url']);
     }
     $conflict_resources = $ext->validateResources();
     if (!empty($conflict_resources)) {
         ob_start();
         print_r($conflict_resources);
         $err = ob_get_clean();
         ADebug::warning('resources conflict', AC_ERR_USER_WARNING, $extension . ' Extension resources conflict detected.<br/><pre>' . $err . '</pre>');
     }
     $this->document->setTitle($this->language->get($extension . '_name'));
     $this->document->addBreadcrumb(array('href' => $this->data['target_url'], 'text' => $this->language->get($extension . '_name'), 'separator' => ' :: ', 'current' => true));
     $this->data['heading_title'] = $this->language->get($extension . '_name');
     $this->data['text_version'] = $this->language->get('text_version');
     $this->data['text_installed_on'] = $this->language->get('text_installed_on');
     $this->data['text_date_added'] = $this->language->get('text_date_added');
     $this->data['text_license'] = $this->language->get('text_license');
     $this->data['text_dependency'] = $this->language->get('text_dependency');
     $this->data['text_configuration_settings'] = $this->language->get('text_configuration_settings');
     $this->data['button_back'] = $this->html->buildElement(array('type' => 'button', 'name' => 'btn_back', 'text' => $this->language->get('text_back')));
     $this->data['button_reload'] = $this->html->buildElement(array('type' => 'button', 'name' => 'btn_reload', 'text' => $this->language->get('text_reload')));
     $this->data['button_restore_defaults'] = $this->html->buildElement(array('type' => 'button', 'name' => 'button_restore_defaults', 'text' => $this->language->get('button_restore_defaults'), 'href' => $this->html->getSecureURL('extension/extensions/edit', '&extension=' . $extension . '&reload=1')));
     $this->data['button_save'] = $this->html->buildElement(array('type' => 'button', 'name' => 'btn_save', 'text' => $this->language->get('button_save')));
     $this->data['button_save_green'] = $this->html->buildElement(array('type' => 'button', 'name' => 'btn_save', 'text' => $this->language->get('button_save')));
     $this->data['button_reset'] = $this->html->buildElement(array('type' => 'button', 'name' => 'btn_reset', 'text' => $this->language->get('text_reset')));
     $this->data['reload'] = $this->html->getSecureURL('extension/extensions/edit', '&extension=' . $extension);
     $this->data['back'] = $this->html->getSecureURL('extension/extensions/' . $this->session->data['extension_filter']);
     $this->data['update'] = $this->html->getSecureURL('listing_grid/extension/update', '&id=' . $extension . '&store_id=' . $store_id);
     $this->data['dependants_url'] = $this->html->getSecureURL('listing_grid/extension/dependants', '&extension=' . $extension);
     if (!$this->extension_manager->validateDependencies($extension, getExtensionConfigXml($extension))) {
         $this->error['warning'] = $this->language->get('error_dependencies');
     }
     if (isset($this->error['warning'])) {
         $this->data['error_warning'] = $this->error['warning'];
     } else {
         $this->data['error_warning'] = '';
     }
     if (isset($this->session->data['success'])) {
         $this->data['success'] = $this->session->data['success'];
         unset($this->session->data['success']);
     } else {
         $this->data['success'] = '';
     }
     if (isset($this->session->data['error'])) {
         $this->data['error_warning'] = $this->session->data['error'];
         unset($this->session->data['error']);
     } else {
         $this->data['error'] = '';
     }
     //info about available updates
     $upd = $this->cache->get('extensions.updates');
     if (is_array($upd) && in_array($extension, array_keys($upd))) {
         $this->data['info'] = sprintf($this->language->get('text_update_available'), $upd[$extension]['version'], $this->html->getSecureURL('tool/package_installer', '&extension_key=' . $upd[$extension]['installation_key']));
     }
     $missing_extensions = $this->extensions->getMissingExtensions();
     //if extension is missing - do redirect on extensions list with alert!
     if (in_array($extension, $missing_extensions)) {
         $this->session->data['error'] = sprintf($this->language->get('text_missing_extension'), $extension);
         $this->redirect($this->html->getSecureURL('extension/extensions'));
     }
     $this->data['extension_info']['note'] = $ext->getConfig('note') ? $this->html->convertLinks($this->language->get($extension . '_note')) : '';
     $config = $ext->getConfig();
     if (!empty($config->preview->item)) {
         foreach ($config->preview->item as $item) {
             if (!is_file(DIR_EXT . $extension . DIR_EXT_IMAGE . (string) $item)) {
                 continue;
             }
             $this->data['extension_info']['preview'][] = HTTPS_EXT . $extension . DIR_EXT_IMAGE . (string) $item;
         }
         //image gallery scripts and css for previews
         $this->document->addStyle(array('href' => RDIR_TEMPLATE . 'javascript/blueimp-gallery/css/bootstrap-image-gallery.css', 'rel' => 'stylesheet'));
         $this->document->addStyle(array('href' => RDIR_TEMPLATE . 'javascript/blueimp-gallery/css/blueimp-gallery.min.css', 'rel' => 'stylesheet'));
         $this->document->addScript(RDIR_TEMPLATE . 'javascript/blueimp-gallery/jquery.blueimp-gallery.min.js');
         $this->document->addScript(RDIR_TEMPLATE . 'javascript/blueimp-gallery/bootstrap-image-gallery.js');
     }
     if ($ext->getConfig('help_link')) {
         $this->data['extension_info']['help'] = array('ext_link' => array('text' => $this->language->get('text_developer_site'), 'link' => $ext->getConfig('help_link')));
     }
     if ($ext->getConfig('help_file')) {
         $this->data['extension_info']['help']['file'] = array('link' => $this->html->getSecureURL('extension/extension/help', '&extension=' . $this->request->get['extension']), 'text' => $this->language->get('button_howto'));
     }
     $this->data['extension_info']['dependencies'] = array();
     $this->data['extension_info']['extensions'] = $this->extensions->getEnabledExtensions();
     $missing_extensions = $this->extensions->getMissingExtensions();
     $db_extensions = $this->extensions->getDbExtensions();
     if (isset($config->dependencies->item)) {
         foreach ($config->dependencies->item as $item) {
             $id = (string) $item;
             $actions = array();
             if ($this->config->has($id . '_status')) {
                 $status = $this->language->get('text_installed') . ' (' . $this->language->get('text_enabled') . ')';
             } else {
                 $status = $this->language->get('text_not_installed') . ' (' . $this->language->get('text_disabled') . ')';
             }
             if (in_array($id, $db_extensions)) {
                 if (in_array($id, $missing_extensions)) {
                     $class = 'warning';
                     $status = sprintf($this->language->get('text_missing_extension'), $id);
                     $actions['delete'] = $this->html->buildElement(array('type' => 'button', 'href' => $this->html->getSecureURL('extension/extensions/delete', '&extension=' . $id), 'target' => '_blank', 'style' => 'btn_delete', 'icon' => 'fa fa-trash-o', 'title' => $this->language->get('text_delete')));
                 } else {
                     if (!$this->config->has($id . '_status')) {
                         $actions['install'] = $this->html->buildElement(array('type' => 'button', 'href' => $this->html->getSecureURL('extension/extensions/install', '&extension=' . $id), 'target' => '_blank', 'style' => 'btn_install', 'icon' => 'fa fa-play', 'title' => $this->language->get('text_install')));
                         $actions['delete'] = $this->html->buildElement(array('type' => 'button', 'href' => $this->html->getSecureURL('extension/extensions/delete', '&extension=' . $id), 'target' => '_blank', 'style' => 'btn_delete', 'icon' => 'fa fa-trash-o', 'title' => $this->language->get('text_delete')));
                     } else {
                         $actions['edit'] = $this->html->buildElement(array('type' => 'button', 'href' => $this->html->getSecureURL('extension/extensions/edit', '&extension=' . $id), 'target' => '_blank', 'style' => 'btn_edit', 'icon' => 'fa fa-edit', 'title' => $this->language->get('text_edit')));
                         if (!(bool) $item['required']) {
                             $actions['uninstall'] = $this->html->buildElement(array('type' => 'button', 'href' => $this->html->getSecureURL('extension/extensions/uninstall', '&extension=' . $id), 'target' => '_blank', 'style' => 'btn_uninstall', 'icon' => 'fa fa-times', 'title' => $this->language->get('text_uninstall')));
                         }
                     }
                 }
             } else {
                 $actions['mp'] = $this->html->buildElement(array('type' => 'button', 'href' => $this->html->getSecureURL('extension/extensions_store', '&extension=' . $id), 'target' => '_blank', 'style' => 'btn_mp', 'icon' => 'fa fa-play', 'title' => $this->language->get('text_visit_repository')));
             }
             $this->data['extension_info']['dependencies'][] = array('required' => (bool) $item['required'], 'id' => $id, 'status' => $status, 'actions' => $actions, 'class' => $class);
             unset($class);
         }
     }
     // additional settings page
     if ($ext->getConfig('additional_settings')) {
         $btn_param = array('type' => 'button', 'name' => 'btn_addsett', 'href' => $this->html->getSecureURL($ext->getConfig('additional_settings')), 'text' => $this->language->get('text_additional_settings'), 'style' => 'button1');
         if ($store_id) {
             $this->loadModel('setting/store');
             $store_info = $this->model_setting_store->getStore($store_id);
             $btn_param['link'] = $store_info['config_url'] . '?s=' . ADMIN_PATH . '&rt=' . $ext->getConfig('additional_settings');
             $btn_param['target'] = '_blank';
             $btn_param['onclick'] = 'onclick="return confirm(\'' . $this->language->get('additional_settings_confirm') . '\');"';
         }
         $this->data['add_sett'] = $this->html->buildElement($btn_param);
     }
     $this->data['target_url'] = $this->html->getSecureURL('extension/extensions/edit', '&extension=' . $extension);
     $this->view->assign('help_url', $this->gen_help_url('extension_edit'));
     $template = 'pages/extension/extensions_edit.tpl';
     //#PR set custom templates for extension settings page.
     if (has_value((string) $config->custom_settings_template)) {
         //build path to template directory.
         $dir_template = DIR_EXT . $extension . DIR_EXT_ADMIN . DIR_EXT_TEMPLATE . $this->config->get('admin_template') . "/template/";
         $dir_template .= (string) $config->custom_settings_template;
         //validate template and report issue
         if (!file_exists($dir_template)) {
             $warning = new AWarning(sprintf($this->language->get('error_could_not_load_override'), $dir_template, $extension));
             $warning->toLog()->toDebug();
         } else {
             $template = $dir_template;
         }
     }
     //load tabs controller for addtional settings
     if ($this->data['add_sett']) {
         $this->data['groups'][] = 'additional_settings';
         $this->data['link_additional_settings'] = $this->data['add_sett']->href . '&extension=' . $extension;
     }
     $tabs_obj = $this->dispatch('pages/extension/extension_tabs', array($this->data));
     $this->data['tabs'] = $tabs_obj->dispatchGetOutput();
     unset($tabs_obj);
     $obj = $this->dispatch('pages/extension/extension_summary', array($this->data));
     $this->data['extension_summary'] = $obj->dispatchGetOutput();
     unset($obj);
     $this->view->batchAssign($this->data);
     $this->processTemplate($template);
     //update controller data
     $this->extensions->hk_UpdateData($this, __FUNCTION__);
 }
 /**
  * @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;
 }
 /**
  * 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;
 }
Exemple #17
0
 private function _load_settings()
 {
     /**
      * @var ACache
      */
     $cache = $this->registry->get('cache');
     /**
      * @var ADB
      */
     $db = $this->registry->get('db');
     //detect URL for the store
     $url = str_replace('www.', '', $_SERVER['HTTP_HOST']) . rtrim(dirname($_SERVER['PHP_SELF']), '/.\\') . '/';
     if (defined('INSTALL')) {
         $url = str_replace('install/', '', $url);
     }
     // Load default store settings
     $settings = $cache->force_get('settings', '', 0);
     if (empty($settings)) {
         // set global settings (without extensions settings)
         $sql = "SELECT se.*\n\t\t\t\t\tFROM " . DB_PREFIX . "settings se\n\t\t\t\t\tLEFT JOIN " . DB_PREFIX . "extensions e ON TRIM(se.`group`) = TRIM(e.`key`)\n\t\t\t\t\tWHERE se.store_id='0' AND e.extension_id IS NULL";
         $query = $db->query($sql);
         $settings = $query->rows;
         foreach ($settings as &$setting) {
             if ($setting['key'] == 'config_url') {
                 $parsed_url = parse_url($setting['value']);
                 $setting['value'] = 'http://' . $parsed_url['host'] . $parsed_url['path'];
             }
             if ($setting['key'] == 'config_ssl_url') {
                 $parsed_url = parse_url($setting['value']);
                 $setting['value'] = 'https://' . $parsed_url['host'] . $parsed_url['path'];
             }
             $this->cnfg[$setting['key']] = $setting['value'];
         }
         unset($setting);
         // unset reference
         $cache->force_set('settings', $settings, '', 0);
     } else {
         foreach ($settings as $setting) {
             $this->cnfg[$setting['key']] = $setting['value'];
         }
     }
     // if storefront and not default store try to load setting for given url
     if (!is_int(strpos($this->cnfg['config_url'], $url))) {
         // if requested url not equal of default store url - do check other ctore urls.
         $cache_name = 'settings.store.' . md5('http://' . $url);
         $store_settings = $cache->force_get($cache_name);
         if (empty($store_settings)) {
             $sql = "SELECT se.`key`, se.`value`, st.store_id\n\t\t   \t\t\t  FROM " . DB_PREFIX . "settings se\n\t\t   \t\t\t  RIGHT JOIN " . DB_PREFIX . "stores st ON se.store_id=st.store_id\n\t\t   \t\t\t  LEFT JOIN " . DB_PREFIX . "extensions e ON TRIM(se.`group`) = TRIM(e.`key`)\n\t\t   \t\t\t  WHERE se.store_id = (SELECT DISTINCT store_id FROM " . DB_PREFIX . "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 AND e.extension_id IS NULL";
             $query = $db->query($sql);
             $store_settings = $query->rows;
             $cache->force_set($cache_name, $store_settings);
         }
         if ($store_settings) {
             foreach ($store_settings as $row) {
                 $value = $row['value'];
                 $this->cnfg[$row['key']] = $value;
             }
             $this->cnfg['config_store_id'] = $store_settings[0]['store_id'];
         } else {
             $warning = new AWarning('Warning: Accessing store with unconfigured 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 . rtrim(dirname($_SERVER['PHP_SELF']), '/.\\') . '/';
         }
         if (!$this->cnfg['config_url']) {
             $this->cnfg['config_url'] = 'http://' . REAL_HOST . rtrim(dirname($_SERVER['PHP_SELF']), '/.\\') . '/';
         }
     }
     if (is_null($this->cnfg['config_store_id'])) {
         $this->cnfg['config_store_id'] = 0;
         $this->_set_default_settings();
     }
     // load extension settings
     $cache_suffix = IS_ADMIN ? 'admin' : $this->cnfg['config_store_id'];
     $settings = $cache->force_get('settings.extension.' . $cache_suffix);
     if (empty($settings)) {
         // all settings of default store without extensions settings
         $sql = "SELECT se.*\n\t\t\t\t\tFROM " . DB_PREFIX . "settings se\n\t\t\t\t\tLEFT JOIN " . DB_PREFIX . "extensions e ON TRIM(se.`group`) = TRIM(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);
         $settings = $query->rows;
         $cache->force_set('settings.extension.' . $cache_suffix, $settings);
     }
     foreach ($settings as $setting) {
         $this->cnfg[$setting['key']] = $setting['value'];
     }
 }