protected function _build_menu($values) { // need to resort by sort_order property $offset = 0; // it needs for process repeating sort numbers $tmp = $this->item_ids = array(); if (is_array($values)) { $rm = new AResourceManager(); $rm->setType('image'); $language_id = $this->registry->get('language')->getContentLanguageID(); foreach ($values as &$item) { if ($item['item_icon_rl_id']) { $r = $rm->getResource($item['item_icon_rl_id'], $language_id); $item['item_icon_code'] = $r['resource_code']; } if (isset($tmp[$item['parent_id']][$item['sort_order']])) { $offset++; } $tmp[$item['parent_id']][$item['sort_order'] + $offset] = $item; $this->item_ids[] = $item['item_id']; } } unset($item); $this->dataset_rows = $values; $menu = array(); foreach ($tmp as $key => $item) { ksort($item); $menu[$key] = $item; } return $menu; }
private function _getBlockForm() { if (isset($this->session->data['warning'])) { $this->data['error_warning'] = $this->session->data['warning']; $this->session->data['warning'] = ''; } else { $this->data['error_warning'] = ''; } $this->load->library('json'); $this->view->assign('success', $this->session->data['success']); if (isset($this->session->data['success'])) { unset($this->session->data['success']); } $this->document->initBreadcrumb(array('href' => $this->html->getSecureURL('index/home'), 'text' => $this->language->get('text_home'), 'separator' => FALSE)); $this->document->addBreadcrumb(array('href' => $this->html->getSecureURL('design/blocks'), 'text' => $this->language->get('heading_title'), 'separator' => ' :: ')); $this->data['cancel'] = $this->html->getSecureURL('design/blocks'); $custom_block_id = (int) $this->request->get['custom_block_id']; // need to get data of custom listing $options_list = array(); if ($custom_block_id) { $lm = new ALayoutManager(); $block_info = $lm->getBlockDescriptions($custom_block_id); $language_id = $this->session->data['content_language_id']; if (!isset($block_info[$language_id])) { $language_id = key($block_info); } foreach ($block_info[$language_id] as $k => $v) { $this->data[$k] = $v; } $content = $block_info[$this->language->getContentLanguageID()]['content']; if ($content) { $content = unserialize($content); } else { $content = current($block_info); $content = unserialize($content['content']); } $this->data['banner_group_name'] = $content['banner_group_name']; $lm = new AListingManager($this->request->get['custom_block_id']); $list = $lm->getCustomList(); $options_list = array(); if ($list) { foreach ($list as $row) { $options_list[(int) $row['id']] = array(); } $ids = array_keys($options_list); $assigned_banners = $this->model_extension_banner_manager->getBanners(array('subsql_filter' => 'b.banner_id IN (' . implode(', ', $ids) . ')')); $rm = new AResourceManager(); $rm->setType('image'); foreach ($assigned_banners as $banner) { $id = $banner['banner_id']; if (in_array($id, $ids)) { $thumbnail = $rm->getMainThumb('banners', $banner['banner_id'], (int) $this->config->get('config_image_grid_width'), (int) $this->config->get('config_image_grid_height'), false); $icon = $thumbnail['thumb_html'] ? $thumbnail['thumb_html'] : '<i class="fa fa-code fa-4x"></i> '; $options_list[$id] = array('image' => $icon, 'id' => $id, 'name' => $banner['name'], 'sort_order' => (int) $banner['sort_order']); } } } } if (!$custom_block_id) { $this->data['action'] = $this->html->getSecureURL('extension/banner_manager/insert_block'); $this->data['form_title'] = $this->language->get('text_create_block'); $this->data['update'] = ''; $form = new AForm('ST'); } else { $this->data['action'] = $this->html->getSecureURL('extension/banner_manager/edit_block', '&custom_block_id=' . $custom_block_id); $this->data['form_title'] = $this->language->get('text_edit') . ' ' . $this->data['name']; $this->data['update'] = $this->html->getSecureURL('listing_grid/blocks_grid/update_field', '&custom_block_id=' . $custom_block_id); $form = new AForm('HS'); } $this->document->addBreadcrumb(array('href' => $this->data['action'], 'text' => $this->data['form_title'], 'separator' => ' :: ', 'current' => true)); $form->setForm(array('form_name' => 'BannerBlockFrm', 'update' => $this->data['update'])); $this->data['form']['form_open'] = $form->getFieldHtml(array('type' => 'form', 'name' => 'BannerBlockFrm', 'action' => $this->data['action'], 'attr' => 'data-confirm-exit="true" class="aform form-horizontal"')); $this->data['form']['submit'] = $form->getFieldHtml(array('type' => 'button', 'name' => 'submit', 'text' => $this->language->get('button_save'), 'style' => 'button1')); $this->data['form']['cancel'] = $form->getFieldHtml(array('type' => 'button', 'name' => 'cancel', 'text' => $this->language->get('button_cancel'), 'style' => 'button2')); if ($custom_block_id) { $this->data['form']['fields']['block_status'] = $form->getFieldHtml(array('type' => 'checkbox', 'name' => 'block_status', 'value' => $this->data['status'], 'style' => 'btn_switch')); $this->data['form']['text']['block_status'] = $this->html->convertLinks($this->language->get('entry_block_status')); $this->data['form']['fields']['block_status_note'] = ''; $this->data['form']['text']['block_status_note'] = $this->html->convertLinks($this->language->get('entry_block_status_note')); } $this->data['form']['fields']['block_name'] = $form->getFieldHtml(array('type' => 'hidden', 'name' => 'block_id', 'value' => $this->data['block_id'])); $this->data['form']['fields']['block_name'] .= $form->getFieldHtml(array('type' => 'input', 'name' => 'block_name', 'value' => $this->data['name'], 'required' => true)); $this->data['form']['text']['block_name'] = $this->language->get('entry_block_name'); $this->data['form']['fields']['block_title'] = $form->getFieldHtml(array('type' => 'input', 'name' => 'block_title', 'required' => true, 'value' => $this->data['title'])); $this->data['form']['text']['block_title'] = $this->language->get('entry_block_title'); // list of templates for block $tmpl_ids = $this->extensions->getInstalled('template'); $tmpl_ids[] = 'default'; $this->data['block_wrappers'] = array(); foreach ($tmpl_ids as $tmpl_id) { // for tpls of block that stores in db $layout_manager = new ALayoutManager($tmpl_id); $block = $layout_manager->getBlockByTxtId('banner_block'); $block_templates = (array) $layout_manager->getBlockTemplates($block['block_id']); foreach ($block_templates as $item) { if ($item['template']) { $this->data['block_wrappers'][$item['template']] = $item['template']; } } //Automatic block template selection mode based on parent is limited to 1 template per location //To extend, allow custom block's template to be selected to suppress automatic selection //for tpls that stores in main.php (other extensions templates) $ext_tpls = $this->extensions->getExtensionTemplates(); foreach ($ext_tpls as $section) { foreach ($section as $s => $tpls) { if ($s != 'storefront') { continue; } foreach ($tpls as $tpl) { if (isset($this->data['block_wrappers'][$tpl]) || strpos($tpl, 'blocks/banner_block/') === false) { continue; } $this->data['block_wrappers'][$tpl] = $tpl; } } } $tpls = glob(DIR_STOREFRONT . 'view/*/template/blocks/banner_block/*.tpl'); foreach ($tpls as $tpl) { $pos = strpos($tpl, 'blocks/banner_block/'); $tpl = substr($tpl, $pos); if (!isset($this->data['block_wrappers'][$tpl])) { $this->data['block_wrappers'][$tpl] = $tpl; } } } ksort($this->data['block_wrappers']); array_unshift($this->data['block_wrappers'], $this->language->get('text_automatic')); if ($this->data['block_wrapper'] && !isset($this->data['block_wrappers'][$this->data['block_wrapper']])) { $this->data['block_wrappers'] = array_merge(array($this->data['block_wrapper'] => $this->data['block_wrapper']), $this->data['block_wrappers']); } $this->data['form']['fields']['block_wrapper'] = $form->getFieldHtml(array('type' => 'selectbox', 'name' => 'block_wrapper', 'options' => $this->data['block_wrappers'], 'value' => $this->data['block_wrapper'], 'help_url' => $this->gen_help_url('block_wrapper'))); $this->data['form']['text']['block_wrapper'] = $this->language->get('entry_block_wrapper'); $this->data['form']['fields']['block_framed'] = $form->getFieldHtml(array('type' => 'checkbox', 'name' => 'block_framed', 'value' => $this->data['block_framed'], 'style' => 'btn_switch', 'help_url' => $this->gen_help_url('block_framed'))); $this->data['form']['text']['block_framed'] = $this->language->get('entry_block_framed'); $this->data['form']['fields']['block_description'] = $form->getFieldHtml(array('type' => 'textarea', 'name' => 'block_description', 'value' => $this->data['description'], 'attr' => ' style="height: 50px;"')); $this->data['form']['text']['block_description'] = $this->language->get('entry_block_description'); // groups of banners $this->loadModel('extension/banner_manager'); $result = $this->model_extension_banner_manager->getBannerGroups(); $groups = array('0' => $this->language->get('text_select')); if ($result) { foreach ($result as $row) { $groups[$row['banner_group_name']] = $row['banner_group_name']; } } $this->data['form']['fields']['banner_group_name'] = $form->getFieldHtml(array('type' => 'selectbox', 'name' => 'banner_group_name', 'options' => $groups, 'value' => $this->data['banner_group_name'], 'style' => 'no-save')); $this->data['form']['text']['banner_group_name'] = $this->language->get('entry_banner_group_name'); $this->data['form']['text']['listed_banners'] = $this->language->get('entry_banners_selected'); //load only prior saved products $this->data['banners'] = array(); $this->data['form']['fields']['listed_banners'] = $form->getFieldHtml(array('type' => 'multiselectbox', 'name' => 'block_banners[]', 'value' => $ids, 'options' => $options_list, 'style' => 'no-save chosen', 'ajax_url' => $this->html->getSecureURL('listing_grid/banner_manager/banners'), 'placeholder' => $this->language->get('text_select_from_lookup'))); $this->view->batchAssign($this->language->getASet()); $this->view->batchAssign($this->data); $this->view->assign('form_language_switch', $this->html->getContentLanguageSwitcher()); $this->view->assign('language_code', $this->session->data['language']); $this->view->assign('help_url', $this->gen_help_url('banner_edit')); $this->view->assign('rl', $this->html->getSecureURL('common/resource_library', '&object_name=banners&type=image&mode=url')); $this->processTemplate('pages/extension/banner_manager_block_form.tpl'); }
public function get_resource_details() { if (!$this->user->canModify('common/resource_library')) { $error = new AError(''); return $error->toJSONResponse('NO_PERMISSIONS_402', array('error_text' => sprintf($this->language->get('error_permission_modify'), 'common/resource_library'), 'reset_value' => true)); } //init controller data $this->extensions->hk_InitData($this, __FUNCTION__); $resource_id = (int) $this->request->get['resource_id']; $language_id = $this->language->getContentLanguageID(); $rm = new AResourceManager(); $info = $rm->getResource($resource_id, $language_id); if (!$info) { $info = null; } else { $rm->setType($info['type_name']); $info['thumbnail_url'] = $rm->getResourceThumb($resource_id, $this->thumb_sizes['width'], $this->thumb_sizes['height'], $language_id); } $this->load->library('json'); $this->response->addJSONHeader(); $this->response->setOutput(AJson::encode($info)); }
This source file is subject to Open Software License (OSL 3.0) License details is bundled with this package in the file LICENSE.txt. It is also available at this URL: <http://www.opensource.org/licenses/OSL-3.0> UPGRADE NOTE: Do not edit or add to this file if you wish to upgrade AbanteCart to newer versions in the future. If you wish to customize AbanteCart for your needs please refer to http://www.AbanteCart.com for more information. ------------------------------------------------------------------------------*/ if (!defined('DIR_CORE')) { header('Location: static_pages/'); } // add new menu item $rm = new AResourceManager(); $rm->setType('image'); $language_id = $this->language->getContentLanguageID(); $data = array(); $data['resource_code'] = '<i class="fa fa-picture-o"></i> '; $data['name'] = array($language_id => 'Menu Icon Banner Manager'); $data['title'] = array($language_id => ''); $data['description'] = array($language_id => ''); $resource_id = $rm->addResource($data); $menu = new AMenu("admin"); $menu->insertMenuItem(array("item_id" => "banner_manager", "parent_id" => "design", "item_text" => "banner_manager_name", "item_url" => "extension/banner_manager", "item_icon_rl_id" => $resource_id, "item_type" => "extension", "sort_order" => "6")); $data = array(); $data['resource_code'] = '<i class="fa fa-reply-all"></i> '; $data['name'] = array($language_id => 'Menu Icon Banner Manager Stat'); $data['title'] = array($language_id => ''); $data['description'] = array($language_id => ''); $resource_id = $rm->addResource($data);
public function banners() { //$products = array(); $banners_data = array(); //init controller data $this->extensions->hk_InitData($this, __FUNCTION__); $this->loadModel('extension/banner_manager'); if (isset($this->request->post['term'])) { $rm = new AResourceManager(); $rm->setType('image'); $filter = array('subsql_filter' => "b.target_url LIKE '%" . $this->db->escape($this->request->post['term']) . "%'\n\t\t\t\t\t\t\t\t\t\t\t\tOR bd.name LIKE '%" . $this->db->escape($this->request->post['term']) . "%'\n\t\t\t\t\t\t\t\t\t\t\t\tOR bd.description LIKE '%" . $this->db->escape($this->request->post['term']) . "%'\n\t\t\t\t\t\t\t\t\t\t\t\tOR bd.meta LIKE '%" . $this->db->escape($this->request->post['term']) . "%'", 'limit' => 20); $banners = $this->model_extension_banner_manager->getBanners($filter); $ids = array(); foreach ($banners as $result) { $ids[] = (int) $result['banner_id']; } $resource = new AResource('image'); $thumbnails = $resource->getMainThumbList('banners', $ids, $this->config->get('config_image_grid_width'), $this->config->get('config_image_grid_height'), false); foreach ($banners as $banner) { $thumbnail = $thumbnails[$banner['banner_id']]; $icon = $thumbnail['thumb_html'] ? $thumbnail['thumb_html'] : '<i class="fa fa-code fa-4x"></i> '; $banners_data[] = array('image' => $icon, 'id' => $banner['banner_id'], 'name' => $banner['name'], 'sort_order' => (int) $banner['sort_order']); } } //update controller data $this->extensions->hk_UpdateData($this, __FUNCTION__); $this->load->library('json'); $this->response->addJSONHeader(); $this->response->setOutput(AJson::encode($banners_data)); }
/** * @param int $download_id * @return null */ public function deleteDownload($download_id) { $download_id = (int) $download_id; if (!$download_id) { return null; } $download = $this->getDownload($download_id); if (!$download) { return null; } $rm = new AResourceManager(); $rm->setType('download'); $path = ltrim($download['filename'], 'download/'); $rl_id = $rm->getIdFromHexPath($path); if ($rl_id && !$rm->isMapped($rl_id)) { $rm->deleteResource($rl_id); } $this->db->query("DELETE FROM " . $this->db->table("downloads") . " WHERE download_id = '" . (int) $download_id . "'"); $this->db->query("DELETE FROM " . $this->db->table("download_descriptions") . " WHERE download_id = '" . (int) $download_id . "'"); $this->db->query("DELETE FROM " . $this->db->table("download_attribute_values") . " WHERE download_id = '" . (int) $download_id . "'"); $this->db->query("DELETE FROM " . $this->db->table("products_to_downloads") . " WHERE download_id = '" . (int) $download_id . "'"); }
public function getCustomListingSubForm() { //init controller data $this->extensions->hk_InitData($this, __FUNCTION__); $this->load->library('json'); $lm = new ALayoutManager(); $form_name = has_value($this->request->get['form_name']) ? $this->request->get['form_name'] : 'BlockFrm'; $custom_block_id = (int) $this->request->get['custom_block_id']; $listing_datasource = $this->request->post_or_get('listing_datasource'); // need to get data of custom listing if ($custom_block_id) { $content = $lm->getBlockDescriptions($custom_block_id); $content = $content[$this->language->getContentLanguageID()]['content']; $content = unserialize($content); if ($content['listing_datasource'] == $listing_datasource) { $lm = new AListingManager($custom_block_id); $list = $lm->getCustomList(); $options_list = array(); if ($list) { foreach ($list as $row) { $options_list[(int) $row['id']] = array(); } $ids = array_keys($options_list); switch ($listing_datasource) { case 'custom_products': $this->loadModel('catalog/product'); $filter = array('subsql_filter' => 'p.product_id in (' . implode(',', $ids) . ')'); $results = $this->model_catalog_product->getProducts($filter); $id_name = 'product_id'; $rl_object_name = 'products'; break; case 'custom_categories': $this->loadModel('catalog/category'); $filter = array('subsql_filter' => 'c.category_id in (' . implode(',', $ids) . ')'); $results = $this->model_catalog_category->getCategoriesData($filter); $id_name = 'category_id'; $rl_object_name = 'categories'; break; case 'custom_manufacturers': $this->loadModel('catalog/manufacturer'); $filter = array('subsql_filter' => 'm.manufacturer_id in (' . implode(',', $ids) . ')'); $results = $this->model_catalog_manufacturer->getManufacturers($filter); $id_name = 'manufacturer_id'; $rl_object_name = 'manufacturers'; break; } $rm = new AResourceManager(); $rm->setType('image'); foreach ($results as $item) { $id = $item[$id_name]; if (in_array($id, $ids)) { $thumbnail = $rm->getMainThumb($rl_object_name, $id, (int) $this->config->get('config_image_grid_width'), (int) $this->config->get('config_image_grid_height'), false); $icon = $thumbnail['thumb_html'] ? $thumbnail['thumb_html'] : '<i class="fa fa-code fa-4x"></i> '; $options_list[$id] = array('image' => $icon, 'id' => $id, 'name' => $item['name'], 'meta' => $item['model'], 'sort_order' => (int) $item['sort_order']); } } } } } switch ($listing_datasource) { case 'custom_products': $ajax_url = $this->html->getSecureURL('r/product/product/products'); break; case 'custom_categories': $ajax_url = $this->html->getSecureURL('r/listing_grid/category/categories'); break; case 'custom_manufacturers': $ajax_url = $this->html->getSecureURL('r/listing_grid/manufacturer/manufacturers'); break; } $form = new AForm('ST'); $form->setForm(array('form_name' => $form_name)); $multivalue_html = $form->getFieldHtml(array('type' => 'multiselectbox', 'name' => 'selected[]', 'value' => $ids, 'options' => $options_list, 'style' => 'chosen', 'ajax_url' => $ajax_url, 'placeholder' => $this->language->get('text_select_from_lookup'))); $this->view->assign('multivalue_html', $multivalue_html); $this->view->assign('form_name', $form_name); //update controller data $this->extensions->hk_UpdateData($this, __FUNCTION__); $this->processTemplate('responses/design/block_custom_listing_subform.tpl'); }
public function main() { //use to init controller data $this->extensions->hk_InitData($this, __FUNCTION__); $this->load->helper('html'); $this->view->assign('breadcrumbs', $this->document->getBreadcrumbs()); if ($this->request->is_POST() && isset($this->request->post['language_code'])) { unset($this->session->data['content_language']); $this->session->data['language'] = $this->request->post['language_code']; $this->cache->delete('admin_menu'); if (!empty($this->request->post['redirect'])) { $this->redirect($this->request->post['redirect']); } else { $this->redirect($this->html->getURL('index/home')); } } $this->view->assign('language_code', $this->session->data['language']); $this->view->assign('languages', array()); $this->view->assign('languages', $this->language->getActiveLanguages()); $this->view->assign('content_language_id', $this->language->getContentLanguageID()); $this->view->assign('language_settings', $this->html->getSecureURL('localisation/language')); $this->view->assign('new_messages', $this->messages->getShortList()); $this->view->assign('messages_link', $this->html->getSecureURL('tool/message_manager')); $this->view->assign('action', $this->html->getSecureURL('index/home')); $this->view->assign('search_action', $this->html->getSecureURL('tool/global_search')); //redirect after language change if (!$this->request->get['rt'] || $this->request->get['rt'] == 'index/home') { $this->view->assign('redirect', $this->html->getSecureURL('index/home')); $this->view->assign('home_page', true); } else { $this->view->assign('home_page', false); $this->view->assign('redirect', HTTPS_SERVER . '?' . $_SERVER['QUERY_STRING']); } if (!$this->user->isLogged() || !isset($this->request->get['token']) || !isset($this->session->data['token']) || $this->request->get['token'] != $this->session->data['token']) { $this->view->assign('logged', ''); $this->view->assign('home', $this->html->getSecureURL('index/login', '', true)); } else { $this->view->assign('home', $this->html->getSecureURL('index/home', '', true)); $this->view->assign('logged', sprintf($this->language->get('text_logged'), $this->user->getUserName())); $this->view->assign('avatar', $this->user->getAvatar()); $this->view->assign('username', $this->user->getUserName()); $this->view->assign('last_login', sprintf($this->language->get('text_last_login'), $this->user->getLastLogin())); $this->view->assign('account_edit', $this->html->getSecureURL('index/edit_details', '', true)); $stores = array(); $this->loadModel('setting/store'); $results = $this->model_setting_store->getStores(); foreach ($results as $result) { $stores[] = array('name' => $result['name'], 'href' => $result['config_url']); } $this->view->assign('stores', $stores); $this->view->assign('logout', $this->html->getSecureURL('index/logout')); $this->view->assign('store', HTTP_CATALOG); // add dynamic menu based on dataset scheme $this->addChild('common/menu', 'menu', 'common/menu.tpl'); //Get surrent menu item $menu = new AMenu('admin'); $current_menu = $menu->getMenuByRT($this->request->get['rt']); if ($current_menu['item_icon_rl_id']) { $rm = new AResourceManager(); $rm->setType('image'); $resource = $rm->getResource($current_menu['item_icon_rl_id']); $current_menu['icon'] = $resource['resource_code']; } unset($current_menu['item_icon_rl_id']); $this->view->assign('current_menu', $current_menu); } if ($this->user->isLogged()) { $ant_message = $this->messages->getANTMessage(); $this->view->assign('ant', $ant_message['html']); $this->view->assign('mark_read_url', $this->html->getSecureURL('common/common/antMessageRead', '&message_id=' . $ant_message['id'])); $this->view->assign('ant_viewed', $ant_message['viewed']); } $this->view->assign('config_voicecontrol', $this->config->get('config_voicecontrol')); $this->view->assign('voicecontrol_setting_url', $this->html->getSecureURL('setting/setting/system')); $this->view->assign('command_lookup_url', $this->html->getSecureURL('common/action_commands')); $this->view->assign('search_suggest_url', $this->html->getSecureURL('listing_grid/global_search_result/suggest')); $this->view->assign('search_everywhere', $this->language->get('search_everywhere')); $this->view->assign('text_all_matches', $this->language->get('text_all_matches')); $this->view->assign('dialog_title', $this->language->get('text_quick_edit_form')); $this->view->assign('button_go', $this->html->buildButton(array('name' => 'searchform_go', 'text' => $this->language->get('button_go'), 'style' => 'button5'))); //check if install dir existing. warn if (file_exists(DIR_ROOT . '/install')) { $this->messages->saveWarning($this->language->get('text_install_warning_subject'), $this->language->get('text_install_warning')); } //backwards compatability from 1.2.1. Can remove this check in the future. if (!defined('ENCRYPTION_KEY')) { $cmbody = "To be compatible with v" . VERSION . " add below line to configuration file: <br>\n" . DIR_ROOT . '/system/config.php'; $cmbody .= "<br>\n" . "define('ENCRYPTION_KEY', '" . $this->config->get('encryption_key') . "');\n"; $this->messages->saveWarning('Compatibility warning for v' . VERSION, $cmbody); } //prepare quick stats $this->loadModel('tool/online_now'); $online_new = $this->model_tool_online_now->getTotalTodayOnline('new'); $online_registered = $this->model_tool_online_now->getTotalTodayOnline('registered'); $this->view->assign('online_new', $online_new); $this->view->assign('online_registered', $online_registered); $this->loadModel('report/sale'); $data = array('filter' => array('date_start' => dateISO2Display(date('Y-m-d', time()), $this->language->get('date_format_short')), 'date_end' => dateISO2Display(date('Y-m-d', time()), $this->language->get('date_format_short')))); $today_orders = $this->model_report_sale->getSaleReportSummary($data); $today_order_count = $today_orders['orders']; $today_sales_amount = $this->currency->format($today_orders['total_amount'], $this->config->get('config_currency')); $this->view->assign('today_order_count', $today_order_count); $this->view->assign('today_sales_amount', $today_sales_amount); $this->loadModel('sale/customer'); $filter = array('date_added' => date('Y-m-d', time())); $today_customer_count = $this->model_sale_customer->getTotalCustomers(array('filter' => $filter)); $this->view->assign('today_customer_count', $today_customer_count); $this->loadModel('catalog/review'); $today_review_count = $this->model_catalog_review->getTotalToday(); $this->view->assign('today_review_count', $today_review_count); $this->processTemplate('common/header.tpl'); //use to update data before render $this->extensions->hk_UpdateData($this, __FUNCTION__); }
private function _migrateImages($data = array(), $object_txt_id = '', $object_id = 0) { $objects = array('products' => 'Product', 'categories' => 'Category', 'manufacturers' => 'Brand'); if (!in_array($object_txt_id, array_keys($objects)) || !$data || !is_array($data)) { $this->addLog('Error: data array for object "' . $object_txt_id . '" wrong.'); return false; } $language_list = $this->language->getAvailableLanguages(); $rm = new AResourceManager(); $rm->setType('image'); //IMAGE PROCESSING $success_db = false; // sign of imported image from database query result(not generated additional) $data['image'] = (array) $data['image']; foreach ($data['image'] as $k => $source) { $src_exists = @getimagesize($source); // check is image exists if ($src_exists) { $image_basename = basename($source); $target = DIR_RESOURCE . 'image/' . $image_basename; if (($file = $this->downloadFile($source)) === false) { $this->is_error = true; if ($k == 'db') { $this->addLog($objects[$object_txt_id] . " " . $data['name'] . " File " . $source . " couldn't be uploaded."); } continue; } if (!$this->is_error) { if (!is_dir(DIR_RESOURCE . 'image/')) { mkdir(DIR_RESOURCE . 'image/', 0777); } if (!$this->writeToFile($file, $target)) { $this->is_error = true; if ($k == 'db') { $this->addLog("Cannot create " . $objects[$object_txt_id] . " " . $data['name'] . " ( " . $source . " ) file " . $target . " in resource/image folder "); } continue; } $resource = array('language_id' => $this->config->get('storefront_language_id'), 'name' => array(), 'title' => '', 'description' => '', 'resource_path' => $image_basename, 'resource_code' => ''); foreach ($language_list as $lang) { $resource['name'][$lang['language_id']] = str_replace('%20', ' ', $image_basename); } $resource_id = $rm->addResource($resource); if ($resource_id) { $rm->mapResource($object_txt_id, $object_id, $resource_id); $this->pic_count++; $success_db = $k == 'db' ? true : $success_db; } else { $this->addLog($this->db->error); continue; } } } } // end of processing images return true; }
/** * Process resource library insert * @param array $table_cfg * @param array $data_row * @param array $parent_vals * @return array */ private function _do_all_resources($table_cfg, $data, $parent_vals) { $records = array(); foreach ($data['rows'] as $row) { if ($row['type']) { if ($row['source_url']) { $records[$row['type']]['source_url'][] = $row['source_url']; } else { if ($row['source_path']) { $records[$row['type']]['source_path'][] = $row['source_path']; } else { if ($row['html_code']) { $records[$row['type']]['html_code'][] = $row['html_code']; } } } } } foreach ($records as $type => $sources) { $rm = new AResourceManager(); $rm->setType($type); //delete all resource of the type from library $object_name = $table_cfg['special_relation']['object_name']; $object_id = $parent_vals[$table_cfg['special_relation']['object_id']]; $resources = $rm->unmapAndDeleteResources($object_name, $object_id, $type); //ad new media sources if ($sources['source_url']) { $fl = new AFile(); foreach ($sources['source_url'] as $source) { $image_basename = basename($source); $target = DIR_RESOURCE . $rm->getTypeDir() . '/' . $image_basename; if (!is_dir(DIR_RESOURCE . $rm->getTypeDir())) { @mkdir(DIR_RESOURCE . $rm->getTypeDir(), 0777); } if (($file = $fl->downloadFile($source)) === false) { $this->_status2array('error', "Unable to download file from {$source}"); continue; } if (!$fl->writeDownloadToFile($file, $target)) { $this->_status2array('error', "Unable to save download to {$target}"); continue; } if (!$this->_create_resource($rm, $object_name, $object_id, $image_basename)) { $this->_status2array('error', "Unable to create new media resource type {$type} for {$image_basename}"); continue; } } } if ($sources['source_path']) { foreach ($sources['source_path'] as $source) { $image_basename = basename($source); $target = DIR_RESOURCE . $rm->getTypeDir() . '/' . $image_basename; if (!is_dir(DIR_RESOURCE . $rm->getTypeDir())) { @mkdir(DIR_RESOURCE . $rm->getTypeDir(), 0777); } if (!copy($source, $target)) { $this->_status2array('error', "Unable to copy {$source} to {$target}"); continue; } if (!$this->_create_resource($rm, $object_name, $object_id, $image_basename)) { $this->_status2array('error', "Unable to create new media resource for {$image_basename}"); continue; } } } if ($sources['html_code']) { foreach ($sources['html_code'] as $code) { if (!$this->_create_resource($rm, $object_name, $object_id, '', $code)) { $this->_status2array('error', "Unable to create new HTML code media resource type {$type}"); continue; } } } } return array(); }
private function _getChildItems($item_id, $menu_items) { $rm = new AResourceManager(); $rm->setType('image'); $result = array(); foreach ($menu_items as $item) { if ($item['parent_id'] == $item_id && isset($item['item_id'])) { if (isset($item['language'])) { $this->loadLanguage($item['language'], 'silent'); } $childen = $this->_getChildItems($item['item_id'], $menu_items); $rt = ''; $menu_link = ''; if (preg_match("/(http|https):/", $item['item_url'])) { $menu_link = $item['item_url']; } else { if ($item['item_url']) { //rt based link, need to save rt $menu_link = $this->html->getSecureURL($item['item_url'], '', true); $rt = $item['item_url']; } } $link_keyname = strpos($item['item_url'], "http") ? "onclick" : "href"; $icon = $rm->getResource($item['item_icon_rl_id']); $icon = $icon['resource_code'] ? $icon['resource_code'] : ''; $temp = array('id' => $item['item_id'], $link_keyname => $menu_link, 'text' => $this->language->get($item['item_text']), 'icon' => $icon); if ($rt) { $temp['rt'] = $rt; } if ($childen) { $temp['children'] = $childen; } $result[$item['item_id']] = $temp; } } return $result; }
public function get_resource_preview() { $rm = new AResourceManager(); $result = $rm->getResource($this->request->get['resource_id'], $this->config->get('storefront_language_id')); if (!empty($result)) { $rm->setType($result['type_name']); if (!empty($result['resource_code'])) { if (strpos($result['resource_code'], "http") === 0) { $this->redirect($result['resource_code']); } else { $this->response->setOutput($result['resource_code']); } } else { $file_path = DIR_RESOURCE . $rm->getTypeDir() . $result['resource_path']; $result['name'] = pathinfo($result['name'], PATHINFO_FILENAME); if (file_exists($file_path) && ($fd = fopen($file_path, "r"))) { $fsize = filesize($file_path); $path_parts = pathinfo($file_path); $this->response->addHeader('Content-type: ' . mime_content_type($path_parts["basename"])); $this->response->addHeader("Content-Disposition: filename=\"" . $result['name'] . '.' . $path_parts["extension"] . "\""); $this->response->addHeader("Content-length: {$fsize}"); $this->response->addHeader("Cache-control: private"); //use this to open files directly $buffer = ''; while (!feof($fd)) { $buffer .= fread($fd, 32768); } $this->response->setOutput($buffer); } else { $this->response->setOutput($this->language->get('text_no_resources')); } fclose($fd); } } else { $this->response->setOutput($this->language->get('text_no_resources')); } }