コード例 #1
0
 public function main()
 {
     //Load input arguments for gid settings
     $this->data = func_get_arg(0);
     //init controller data
     $this->extensions->hk_InitData($this, __FUNCTION__);
     $this->loadLanguage('extension/extensions');
     $extension = $this->request->get['extension'];
     if ($extension && !$this->data['extension_info']) {
         $this->data['extension_info'] = $this->extensions->getExtensionInfo($extension);
     }
     $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';
     $this->data['extension_info']['icon'] = $icon;
     $this->data['extension_info']['name'] = $this->language->get($extension . '_name');
     $datetime_format = $this->language->get('date_format_short') . ' ' . $this->language->get('time_format');
     if ($this->data['extension_info']['date_installed']) {
         $this->data['extension_info']['installed'] = dateISO2Display($this->data['extension_info']['date_installed'], $datetime_format);
     }
     if ($this->data['extension_info']['date_added']) {
         $this->data['extension_info']['date_added'] = dateISO2Display($this->data['extension_info']['date_added'], $datetime_format);
     }
     if (isset($this->session->data['extension_updates'][$extension])) {
         $this->data['upgrade_button'] = $this->html->buildElement(array('type' => 'button', 'name' => 'btn_upgrade', 'id' => 'upgradenow', 'href' => AEncryption::addEncoded_stid($this->session->data['extension_updates'][$extension]['url']), 'text' => $this->language->get('button_upgrade')));
     }
     $this->data['extension_info']['license'] = $this->data['extension_info']['license_key'];
     $this->view->batchAssign($this->data);
     $this->processTemplate('pages/extension/extension_summary.tpl');
     //update controller data
     $this->extensions->hk_UpdateData($this, __FUNCTION__);
 }
コード例 #2
0
 public function main()
 {
     $href = '/mp_api2';
     $GET = $this->request->get;
     // if set subfolder for request(seo requests) - concatenate it to url
     if (isset($GET['path'])) {
         $href .= $GET['path'];
         unset($GET['path']);
     }
     $unset = array('s', 'rt', 'token', 'path', 'store_id', 'store_ip', 'store_url', 'store_version', 'language_code');
     foreach ($unset as $key) {
         unset($GET[$key]);
     }
     $GET['store_id'] = UNIQUE_ID;
     $GET['store_ip'] = $_SERVER['SERVER_ADDR'];
     $GET['store_url'] = HTTP_SERVER;
     $GET['store_version'] = VERSION;
     $GET['language_code'] = $this->request->cookie['language'];
     // place your affiliate id here
     define('MP_AFFILIATE_ID', '');
     if (MP_AFFILIATE_ID) {
         $GET['aff_id'] = MP_AFFILIATE_ID;
     }
     $href .= '?' . http_build_query($GET);
     $connect = new AConnect();
     $html = $connect->getResponse($href);
     if (!$html) {
         $this->loadLanguage('extension/extensions_store', 'silent');
         $error = is_array($connect->error) ? $connect->error : array($connect->error);
         foreach ($error as $err) {
             $this->log->write($err);
         }
         $html = '<div style="padding: 10px 10px 10px 20px;	margin-bottom: 15px; background: #FFDFE0 !important;	border: 1px solid #FF9999;	font-size: 12px;">' . $this->language->get('error_connect') . '</div>';
     } else {
         //then parse response
         // get base href and remove it from response
         preg_match('/\\<base.*?href=(\\")(.*?)(\\")/is', $html, $basehref);
         $basehref = $basehref[2];
         $html = str_replace('<base href="' . $basehref . '" />', '', $html);
         // then replace relative url by absolute (css, js, img)
         $html = str_replace('<link href="/', '<link href="' . $basehref, $html);
         $html = str_replace(' src="/', ' src="' . $basehref, $html);
         // then need to replace url of http-links except anchors and absolute urls
         preg_match_all('/href=(\\")(.*?)(\\")/i', $html, $orig_hrefs);
         for ($i = 0; $i < count($orig_hrefs[0]); $i++) {
             $replace = $orig_hrefs[0][$i];
             $ohref = $orig_hrefs[2][$i];
             $link1 = 'href="' . AEncryption::addEncoded_stid($ohref) . (MP_AFFILIATE_ID ? '&aff_id=' . MP_AFFILIATE_ID : '') . '"';
             $link2 = 'href="' . $this->html->getSecureUrl('tool/extensions_store', '&path=' . $ohref . (MP_AFFILIATE_ID ? '&aff_id=' . MP_AFFILIATE_ID : '')) . '"';
             if (substr($ohref, 0, 4) == 'http' || substr($ohref, 0, 1) == '#') {
                 $html = str_replace($replace, $link1, $html);
             } else {
                 $html = str_replace($replace, $link2, $html);
             }
         }
         // construct action for search form
         $action = $this->html->getSecureUrl('tool/extensions_store', MP_AFFILIATE_ID ? '&aff_id=' . MP_AFFILIATE_ID : '');
         $html = str_replace(' action="/', ' action="' . $action, $html);
         $hidden = '<input type="hidden" name="search_performed" value="Y">';
         $hidden .= '<input type="hidden" name="rt" value="tool/extensions_store">';
         $hidden .= '<input type="hidden" name="s" value="' . ADMIN_PATH . '">';
         $hidden .= '<input type="hidden" name="token" value="' . $this->request->get['token'] . '">';
         $hidden .= '<input type="hidden" name="aff_id" value="' . MP_AFFILIATE_ID . '">';
         $html = preg_replace('/<input.*name="search_performed".*>/', $hidden, $html);
         $html = $this->html->convertLinks($html);
         $html = str_replace('<span>Store ID</span>', '<span><font size="1"> ' . UNIQUE_ID . '</font></span>', $html);
     }
     $this->response->setOutput($html);
 }
コード例 #3
0
ファイル: extensions.php プロジェクト: harshzalavadiya/fatak
    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__);
    }
コード例 #4
0
ファイル: updater.php プロジェクト: harshzalavadiya/fatak
 /**
  * this method checks for updates on remote server
  * common/ant controller calls it every page load
  * @param bool $mode
  * @internal param array $extension_list
  * @return array|boolean
  */
 public function check4Updates($mode = false)
 {
     $need_to_download = true;
     $extension_list = $this->loadExtensionsList();
     $this->updates_path = is_writable(DIR_APP_SECTION . "system/") ? DIR_APP_SECTION . "system/" : sys_get_temp_dir() . "/";
     $coreversion = MASTER_VERSION . '.' . MINOR_VERSION;
     // checks for downloaded xml-file and download it when it needs (one per day)
     if (file_exists($this->updates_path . 'updates.xml')) {
         $mtime = date("m/d/Y", filemtime($this->updates_path . "updates.xml"));
         $need_to_download = date("m/d/Y", time()) != $mtime ? true : false;
         $need_to_download = !filesize($this->updates_path . "updates.xml") ? true : $need_to_download;
     }
     if ($need_to_download) {
         $success = $this->getUpdateInfo();
         if ($success === false) {
             file_put_contents($this->updates_path . "updates.xml", '<updates></updates>');
             return false;
         }
     } else {
         // if file exists locally and session not expired - do nothing
         if (isset($this->session->data['extension_updates'])) {
             //return true;
         }
     }
     $this->session->data['extension_updates'] = array();
     $updates_info = '';
     if (file_exists($this->updates_path . "updates.xml") && filesize($this->updates_path . "updates.xml") > 20) {
         $updates_info = @simplexml_load_file($this->updates_path . "updates.xml");
     }
     if ($updates_info) {
         $updates_info = $updates_info->extensions->extension;
         foreach ($updates_info as $ext) {
             $extension_id = strtolower((string) $ext->id);
             if (!$extension_list[$extension_id]) {
                 continue;
                 // check next extension in xml tree
             }
             $versions = array();
             foreach ($ext->coreversions->item as $version) {
                 $version = (string) $version;
                 $version = explode('.', $version);
                 $version = (int) $version[0] . '.' . (int) $version[1];
                 $versions[] = $version;
             }
             asort($versions, SORT_DESC);
             $versions = array_unique($versions);
             $result = true;
             if (!in_array($coreversion, $versions)) {
                 foreach ($versions as $version) {
                     $result = versionCompare($version, $coreversion, '<');
                     if ($result) {
                         break;
                     }
                 }
             }
             if (!$result) {
                 continue;
                 //  check next extension in xml tree
             }
             if (versionCompare($extension_list[$extension_id]['version'], (string) $ext->version, '<')) {
                 $action = array('text' => $this->html->buildButton(array('name' => 'btn_upgrade', 'text' => $this->language->get('button_upgrade'), 'style' => 'button1')), 'link' => AEncryption::addEncoded_stid((string) $ext->url));
                 $this->session->data['extension_updates'][$extension_id] = array('id' => $extension_id, 'url' => (string) $ext->url, 'new_version' => (string) $ext->version, 'action' => $action);
                 $this->session->data['extension_updates'][$extension_id] = array_merge($this->session->data['extension_updates'][$extension_id], $extension_list[$extension_id]);
             }
         }
     }
     // save notice in messages if we got new update data
     if (sizeof($this->session->data['extension_updates']) && $need_to_download) {
         $this->load->language('tool/updater');
         foreach ($this->session->data['extension_updates'] as $extension_info) {
             $message_text = str_replace('%EXTENSION%', $extension_info['name'], $this->language->get('text_notice_text'));
             $url = AEncryption::addEncoded_stid($extension_info['url']);
             $message_text = str_replace('%LINK%', '<a onclick="window.open(\'' . $url . '\',\'marketplace\',\'width=700,height=700,resizable=yes,scrollbars=yes\');">' . $extension_info['url'] . '</a>', $message_text);
             $this->messages->saveNotice(str_replace('%EXTENSION%', $extension_info['name'], $this->language->get('text_notice_title')), $message_text);
         }
     }
     return true;
 }