function upgrade_module_1_3_2_11($object) { $themes = Theme::getThemes(); $theme_meta_value = array(); foreach ($object->controllers as $controller) { $page = 'module-' . $object->name . '-' . $controller; $result = Db::getInstance()->getValue('SELECT * FROM ' . _DB_PREFIX_ . 'meta WHERE page="' . pSQL($page) . '"'); if ((int) $result > 0) { continue; } $meta = new Meta(); $meta->page = $page; $meta->configurable = 0; $meta->save(); if ((int) $meta->id > 0) { foreach ($themes as $theme) { $theme_meta_value[] = array('id_theme' => $theme->id, 'id_meta' => $meta->id, 'left_column' => (int) $theme->default_left_column, 'right_column' => (int) $theme->default_right_column); } } else { $object->_errors[] = sprintf(Tools::displayError('Unable to install controller: %s'), $controller); } } if (count($theme_meta_value) > 0) { return Db::getInstance()->insert('theme_meta', $theme_meta_value); } return true; }
/** * return an array of all available theme (installed or not) * * @param boolean $installed_only * @return array string (directory) */ public static function getAvailable($installed_only = true) { static $dirlist = array(); $available_theme = array(); if (empty($dirlist)) { $themes = scandir(_PS_ALL_THEMES_DIR_); foreach ($themes as $theme) { if (is_dir(_PS_ALL_THEMES_DIR_ . DIRECTORY_SEPARATOR . $theme) && $theme[0] != '.') { $dirlist[] = $theme; } } } if ($installed_only) { $themes = Theme::getThemes(); foreach ($themes as $theme_obj) { $themes_dir[] = $theme_obj->directory; } foreach ($dirlist as $theme) { if (false !== array_search($theme, $themes_dir)) { $available_theme[] = $theme; } } } else { $available_theme = $dirlist; } return $available_theme; }
function getSubThemes($theme_id) { $query= <<< EOF select a.*, b.layer_count from (SELECT * FROM "Theme" where parent_id = %d AND theme_id <> parent_id and status = 1 order by theme_name) as a left join (select theme_id, count(*) as layer_count from "Theme_Layer_Mapping", "Meta_Layer" where "Theme_Layer_Mapping".layer_id = "Meta_Layer".layer_id and "Meta_Layer".status = 1 group by theme_id) as b on a.theme_id = b.theme_id EOF; return Theme::getThemes($query, $theme_id); }
public function renderForm() { $getAvailableThemes = Theme::getAvailable(false); $available_theme_dir = array(); $selected_theme_dir = null; if ($this->object) { $selected_theme_dir = $this->object->directory; } foreach ($getAvailableThemes as $k => $dirname) { $available_theme_dir[$k]['value'] = $dirname; $available_theme_dir[$k]['label'] = $dirname; $available_theme_dir[$k]['id'] = $dirname; } $this->fields_form = array('tinymce' => false, 'legend' => array('title' => $this->l('Theme'), 'image' => '../img/admin/themes.gif'), 'input' => array(array('type' => 'text', 'label' => $this->l('Name of the theme:'), 'name' => 'name', 'size' => 48, 'required' => true, 'hint' => $this->l('Invalid characters:') . ' <>;=#{}')), 'submit' => array('title' => $this->l('Save'), 'class' => 'button')); // adding a new theme, you can create a directory, and copy from an existing theme if ($this->display == 'add' || !$this->object->id) { $this->fields_form['input'][] = array('type' => 'text', 'label' => $this->l('Name of the theme\'s directory:'), 'name' => 'directory', 'required' => true, 'desc' => $this->l('If the directory does not exists, it will be created.')); $theme_query = Theme::getThemes(); $this->fields_form['input'][] = array('type' => 'select', 'name' => 'based_on', 'label' => $this->l('Copy missing files from existing theme:'), 'desc' => $this->l('If you create a new theme, it\'s recommended to use default theme files.'), 'options' => array('id' => 'id', 'name' => 'name', 'default' => array('value' => 0, 'label' => ' - '), 'query' => $theme_query)); } else { $this->fields_form['input'][] = array('type' => 'radio', 'label' => $this->l('Directory:'), 'name' => 'directory', 'required' => true, 'br' => true, 'class' => 't', 'values' => $available_theme_dir, 'selected' => $selected_theme_dir, 'desc' => $this->l('Please select a valid theme directory.')); } return parent::renderForm(); }
public function postProcess() { /* PrestaShop demo mode */ if (_PS_MODE_DEMO_ && Tools::isSubmit('submitOptionsmeta') && (Tools::getValue('domain') != Configuration::get('PS_SHOP_DOMAIN') || Tools::getValue('domain_ssl') != Configuration::get('PS_SHOP_DOMAIN_SSL'))) { $this->errors[] = Tools::displayError('This functionality has been disabled.'); return; } if (Tools::isSubmit('submitAddmeta')) { $default_language = Configuration::get('PS_LANG_DEFAULT'); if (Tools::getValue('page') != 'index') { $defaultLangIsValidated = Validate::isLinkRewrite(Tools::getValue('url_rewrite_' . $default_language)); $englishLangIsValidated = Validate::isLinkRewrite(Tools::getValue('url_rewrite_1')); } else { // index.php can have empty rewrite rule $defaultLangIsValidated = !Tools::getValue('url_rewrite_' . $default_language) || Validate::isLinkRewrite(Tools::getValue('url_rewrite_' . $default_language)); $englishLangIsValidated = !Tools::getValue('url_rewrite_1') || Validate::isLinkRewrite(Tools::getValue('url_rewrite_1')); } if (!$defaultLangIsValidated && !$englishLangIsValidated) { $this->errors[] = Tools::displayError('The URL rewrite field must be filled in either the default or English language.'); return false; } foreach (Language::getIDs(false) as $id_lang) { $current = Tools::getValue('url_rewrite_' . $id_lang); if (strlen($current) == 0) { // Prioritize default language first if ($defaultLangIsValidated) { $_POST['url_rewrite_' . $id_lang] = Tools::getValue('url_rewrite_' . $default_language); } else { $_POST['url_rewrite_' . $id_lang] = Tools::getValue('url_rewrite_1'); } } } Hook::exec('actionAdminMetaSave'); } elseif (Tools::isSubmit('submitRobots')) { $this->generateRobotsFile(); } if (Tools::isSubmit('PS_ROUTE_product_rule')) { Tools::clearCache($this->context->smarty); } if (Tools::isSubmit('deletemeta') && (int) Tools::getValue('id_meta') > 0) { Db::getInstance()->delete('theme_meta', 'id_meta=' . (int) Tools::getValue('id_meta')); } $ret = parent::postProcess(); if (Tools::isSubmit('submitAddmeta') && Validate::isLoadedObject($ret)) { /** @var Theme $ret */ $themes = Theme::getThemes(); $theme_meta_value = array(); foreach ($themes as $theme) { /** @var Theme $theme */ $theme_meta_value[] = array('id_theme' => (int) $theme->id, 'id_meta' => (int) $ret->id, 'left_column' => (int) $theme->default_left_column, 'right_column' => (int) $theme->default_right_column); } if (count($theme_meta_value) > 0) { Db::getInstance()->insert('theme_meta', $theme_meta_value, false, true, DB::INSERT_IGNORE); } } return $ret; }
/** * Clear XML cache folder */ public static function clearXMLCache() { $themes = array(); foreach (Theme::getThemes() as $theme) { $themes[] = $theme->directory; } foreach (scandir(_PS_ROOT_DIR_ . '/config/xml') as $file) { $path_info = pathinfo($file, PATHINFO_EXTENSION); if ($path_info == 'xml' && $file != 'default.xml' && !in_array(basename($file, '.' . $path_info), $themes)) { self::deleteFile(_PS_ROOT_DIR_ . '/config/xml/' . $file); } } }
public function initContent() { if ($this->display == 'list') { $this->display = ''; } if (isset($this->display) && method_exists($this, 'render' . $this->display)) { $this->content .= $this->initPageHeaderToolbar(); $this->content .= $this->{'render' . $this->display}(); $this->context->smarty->assign(array('content' => $this->content, 'show_page_header_toolbar' => $this->show_page_header_toolbar, 'page_header_toolbar_title' => $this->page_header_toolbar_title, 'page_header_toolbar_btn' => $this->page_header_toolbar_btn)); } else { $themes = array(); foreach (Theme::getThemes() as $theme) { $themes[] = $theme->directory; } foreach (scandir(_PS_ALL_THEMES_DIR_) as $theme_dir) { if ($theme_dir[0] != '.' && Validate::isDirName($theme_dir) && is_dir(_PS_ALL_THEMES_DIR_ . $theme_dir) && file_exists(_PS_ALL_THEMES_DIR_ . $theme_dir . '/preview.jpg') && !in_array($theme_dir, $themes)) { $config_file = false; $default_config = _PS_ROOT_DIR_ . '/config/xml/themes/default.xml'; $theme_config = _PS_ROOT_DIR_ . '/config/xml/themes/' . $theme_dir . '.xml'; if (file_exists($theme_config)) { $config_file = $theme_config; } elseif (file_exists($default_config)) { $config_file = $default_config; } if ($config_file) { $this->importThemeXmlConfig(simplexml_load_file($config_file), $theme_dir); } } } $content = ''; if (Configuration::hasKey('PS_LOGO') && trim(Configuration::get('PS_LOGO')) != '' && file_exists(_PS_IMG_DIR_ . Configuration::get('PS_LOGO'))) { list($width, $height, $type, $attr) = getimagesize(_PS_IMG_DIR_ . Configuration::get('PS_LOGO')); Configuration::updateValue('SHOP_LOGO_HEIGHT', (int) round($height)); Configuration::updateValue('SHOP_LOGO_WIDTH', (int) round($width)); } if (file_exists(_PS_IMG_DIR_ . 'logo_mobile.jpg') && Configuration::get('PS_LOGO_MOBILE') && trim(Configuration::get('PS_LOGO_MOBILE')) != '') { list($width, $height, $type, $attr) = getimagesize(_PS_IMG_DIR_ . Configuration::get('PS_LOGO_MOBILE')); Configuration::updateValue('SHOP_LOGO_MOBILE_HEIGHT', (int) round($height)); Configuration::updateValue('SHOP_LOGO_MOBILE_WIDTH', (int) round($width)); } $this->content .= $content; return parent::initContent(); } }
public function displayAjaxGetKpi() { $currency = new Currency(Configuration::get('PS_CURRENCY_DEFAULT')); switch (Tools::getValue('kpi')) { case 'conversion_rate': $visitors = AdminStatsController::getVisits(true, date('Y-m-d', strtotime('-31 day')), date('Y-m-d', strtotime('-1 day')), false); $orders = AdminStatsController::getOrders(date('Y-m-d', strtotime('-31 day')), date('Y-m-d', strtotime('-1 day')), false); // $data = array(); // $from = strtotime(date('Y-m-d 00:00:00', strtotime('-31 day'))); // $to = strtotime(date('Y-m-d 23:59:59', strtotime('-1 day'))); // for ($date = $from; $date <= $to; $date = strtotime('+1 day', $date)) // if (isset($visitors[$date]) && $visitors[$date]) // $data[$date] = round(100 * ((isset($orders[$date]) && $orders[$date]) ? $orders[$date] : 0) / $visitors[$date], 2); // else // $data[$date] = 0; $visits_sum = $visitors; //array_sum($visitors); $orders_sum = $orders; //array_sum($orders); if ($visits_sum) { $value = round(100 * $orders_sum / $visits_sum, 2); } elseif ($orders_sum) { $value = '∞'; } else { $value = 0; } $value .= '%'; // ConfigurationKPI::updateValue('CONVERSION_RATE_CHART', Tools::jsonEncode($data)); ConfigurationKPI::updateValue('CONVERSION_RATE', $value); ConfigurationKPI::updateValue('CONVERSION_RATE_EXPIRE', strtotime(date('Y-m-d 00:00:00', strtotime('+1 day')))); break; case 'abandoned_cart': $value = AdminStatsController::getAbandonedCarts(date('Y-m-d H:i:s', strtotime('-2 day')), date('Y-m-d H:i:s', strtotime('-1 day'))); ConfigurationKPI::updateValue('ABANDONED_CARTS', $value); ConfigurationKPI::updateValue('ABANDONED_CARTS_EXPIRE', strtotime('+1 hour')); break; case 'installed_modules': $value = AdminStatsController::getInstalledModules(); ConfigurationKPI::updateValue('INSTALLED_MODULES', $value); ConfigurationKPI::updateValue('INSTALLED_MODULES_EXPIRE', strtotime('+2 min')); break; case 'disabled_modules': $value = AdminStatsController::getDisabledModules(); ConfigurationKPI::updateValue('DISABLED_MODULES', $value); ConfigurationKPI::updateValue('DISABLED_MODULES_EXPIRE', strtotime('+2 min')); break; case 'update_modules': $value = AdminStatsController::getModulesToUpdate(); ConfigurationKPI::updateValue('UPDATE_MODULES', $value); ConfigurationKPI::updateValue('UPDATE_MODULES_EXPIRE', strtotime('+2 min')); break; case 'percent_product_stock': $value = AdminStatsController::getPercentProductStock(); ConfigurationKPI::updateValue('PERCENT_PRODUCT_STOCK', $value); ConfigurationKPI::updateValue('PERCENT_PRODUCT_STOCK_EXPIRE', strtotime('+4 hour')); break; case 'product_avg_gross_margin': $value = AdminStatsController::getProductAverageGrossMargin(); ConfigurationKPI::updateValue('PRODUCT_AVG_GROSS_MARGIN', $value); ConfigurationKPI::updateValue('PRODUCT_AVG_GROSS_MARGIN_EXPIRE', strtotime('+6 hour')); break; case 'disabled_categories': $value = AdminStatsController::getDisabledCategories(); ConfigurationKPI::updateValue('DISABLED_CATEGORIES', $value); ConfigurationKPI::updateValue('DISABLED_CATEGORIES_EXPIRE', strtotime('+2 hour')); break; case 'disabled_products': $value = AdminStatsController::getDisabledProducts(); ConfigurationKPI::updateValue('DISABLED_PRODUCTS', $value); ConfigurationKPI::updateValue('DISABLED_PRODUCTS_EXPIRE', strtotime('+2 hour')); break; case '8020_sales_catalog': $value = AdminStatsController::get8020SalesCatalog(date('Y-m-d', strtotime('-1 month')), date('Y-m-d')); $value = sprintf($this->l('%d%% of your Catalog'), $value); ConfigurationKPI::updateValue('8020_SALES_CATALOG', $value); ConfigurationKPI::updateValue('8020_SALES_CATALOG_EXPIRE', strtotime('+12 hour')); break; case 'empty_categories': $value = AdminStatsController::getEmptyCategories(); ConfigurationKPI::updateValue('EMPTY_CATEGORIES', $value); ConfigurationKPI::updateValue('EMPTY_CATEGORIES_EXPIRE', strtotime('+2 hour')); break; case 'customer_main_gender': $value = AdminStatsController::getCustomerMainGender(); if ($value === false) { $value = $this->l('No customers', null, null, false); } elseif ($value['type'] == 'female') { $value = sprintf($this->l('%d%% Women Customers', null, null, false), $value['value']); } elseif ($value['type'] == 'male') { $value = sprintf($this->l('%d%% Men Customers', null, null, false), $value['value']); } else { $value = sprintf($this->l('%d%% Neutral Customers', null, null, false), $value['value']); } ConfigurationKPI::updateValue('CUSTOMER_MAIN_GENDER', array($this->context->language->id => $value)); ConfigurationKPI::updateValue('CUSTOMER_MAIN_GENDER_EXPIRE', array($this->context->language->id => strtotime('+1 day'))); break; case 'avg_customer_age': $value = sprintf($this->l('%d years', null, null, false), AdminStatsController::getAverageCustomerAge(), 1); ConfigurationKPI::updateValue('AVG_CUSTOMER_AGE', $value); ConfigurationKPI::updateValue('AVG_CUSTOMER_AGE_EXPIRE', strtotime('+1 day')); break; case 'pending_messages': $value = (int) AdminStatsController::getPendingMessages(); ConfigurationKPI::updateValue('PENDING_MESSAGES', $value); ConfigurationKPI::updateValue('PENDING_MESSAGES_EXPIRE', strtotime('+5 min')); break; case 'avg_msg_response_time': $value = sprintf($this->l('%.1f hours', null, null, false), AdminStatsController::getAverageMessageResponseTime(date('Y-m-d', strtotime('-31 day')), date('Y-m-d', strtotime('-1 day')))); ConfigurationKPI::updateValue('AVG_MSG_RESPONSE_TIME', $value); ConfigurationKPI::updateValue('AVG_MSG_RESPONSE_TIME_EXPIRE', strtotime('+4 hour')); break; case 'messages_per_thread': $value = round(AdminStatsController::getMessagesPerThread(date('Y-m-d', strtotime('-31 day')), date('Y-m-d', strtotime('-1 day'))), 1); ConfigurationKPI::updateValue('MESSAGES_PER_THREAD', $value); ConfigurationKPI::updateValue('MESSAGES_PER_THREAD_EXPIRE', strtotime('+12 hour')); break; case 'newsletter_registrations': $value = Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue(' SELECT COUNT(*) FROM `' . _DB_PREFIX_ . 'customer` WHERE newsletter = 1 ' . Shop::addSqlRestriction(Shop::SHARE_ORDER)); if (Module::isInstalled('blocknewsletter')) { $value += Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue(' SELECT COUNT(*) FROM `' . _DB_PREFIX_ . 'newsletter` WHERE active = 1 ' . Shop::addSqlRestriction(Shop::SHARE_ORDER)); } ConfigurationKPI::updateValue('NEWSLETTER_REGISTRATIONS', $value); ConfigurationKPI::updateValue('NEWSLETTER_REGISTRATIONS_EXPIRE', strtotime('+6 hour')); break; case 'enabled_languages': $value = Language::countActiveLanguages(); ConfigurationKPI::updateValue('ENABLED_LANGUAGES', $value); ConfigurationKPI::updateValue('ENABLED_LANGUAGES_EXPIRE', strtotime('+1 min')); break; case 'frontoffice_translations': $themes = Theme::getThemes(); $languages = Language::getLanguages(); $total = $translated = 0; foreach ($themes as $theme) { foreach ($languages as $language) { $kpi_key = substr(strtoupper($theme->name . '_' . $language['iso_code']), 0, 16); $total += ConfigurationKPI::get('TRANSLATE_TOTAL_' . $kpi_key); $translated += ConfigurationKPI::get('TRANSLATE_DONE_' . $kpi_key); } } $value = 0; if ($translated) { $value = round(100 * $translated / $total, 1); } $value .= '%'; ConfigurationKPI::updateValue('FRONTOFFICE_TRANSLATIONS', $value); ConfigurationKPI::updateValue('FRONTOFFICE_TRANSLATIONS_EXPIRE', strtotime('+2 min')); break; case 'main_country': if (!($row = AdminStatsController::getMainCountry(date('Y-m-d', strtotime('-30 day')), date('Y-m-d')))) { $value = $this->l('No orders', null, null, false); } else { $country = new Country($row['id_country'], $this->context->language->id); $value = sprintf($this->l('%d%% %s', null, null, false), $row['orders'], $country->name); } ConfigurationKPI::updateValue('MAIN_COUNTRY', array($this->context->language->id => $value)); ConfigurationKPI::updateValue('MAIN_COUNTRY_EXPIRE', array($this->context->language->id => strtotime('+1 day'))); break; case 'orders_per_customer': $value = Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue(' SELECT COUNT(*) FROM `' . _DB_PREFIX_ . 'customer` c WHERE active = 1 ' . Shop::addSqlRestriction()); if ($value) { $orders = Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue(' SELECT COUNT(*) FROM `' . _DB_PREFIX_ . 'orders` o WHERE valid = 1 ' . Shop::addSqlRestriction()); $value = round($orders / $value, 2); } ConfigurationKPI::updateValue('ORDERS_PER_CUSTOMER', $value); ConfigurationKPI::updateValue('ORDERS_PER_CUSTOMER_EXPIRE', strtotime('+1 day')); break; case 'average_order_value': $row = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow(' SELECT COUNT(`id_order`) as orders, SUM(`total_paid_tax_excl` / `conversion_rate`) as total_paid_tax_excl FROM `' . _DB_PREFIX_ . 'orders` WHERE `invoice_date` BETWEEN "' . pSQL(date('Y-m-d', strtotime('-31 day'))) . ' 00:00:00" AND "' . pSQL(date('Y-m-d', strtotime('-1 day'))) . ' 23:59:59" ' . Shop::addSqlRestriction()); $value = Tools::displayPrice($row['orders'] ? $row['total_paid_tax_excl'] / $row['orders'] : 0, $currency); ConfigurationKPI::updateValue('AVG_ORDER_VALUE', $value); ConfigurationKPI::updateValue('AVG_ORDER_VALUE_EXPIRE', strtotime(date('Y-m-d 00:00:00', strtotime('+1 day')))); break; case 'netprofit_visitor': $date_from = date('Y-m-d', strtotime('-31 day')); $date_to = date('Y-m-d', strtotime('-1 day')); $total_visitors = AdminStatsController::getVisits(true, $date_from, $date_to); $net_profits = AdminStatsController::getTotalSales($date_from, $date_to); $net_profits -= AdminStatsController::getExpenses($date_from, $date_to); $net_profits -= AdminStatsController::getPurchases($date_from, $date_to); if ($total_visitors) { $value = Tools::displayPrice($net_profits / $total_visitors, $currency); } elseif ($net_profits) { $value = '∞'; } else { $value = Tools::displayPrice(0, $currency); } ConfigurationKPI::updateValue('NETPROFIT_VISITOR', $value); ConfigurationKPI::updateValue('NETPROFIT_VISITOR_EXPIRE', strtotime(date('Y-m-d 00:00:00', strtotime('+1 day')))); break; case 'products_per_category': $products = AdminStatsController::getTotalProducts(); $categories = AdminStatsController::getTotalCategories(); $value = round($products / $categories); ConfigurationKPI::updateValue('PRODUCTS_PER_CATEGORY', $value); ConfigurationKPI::updateValue('PRODUCTS_PER_CATEGORY_EXPIRE', strtotime('+1 hour')); break; case 'top_category': if (!($id_category = AdminStatsController::getBestCategory(date('Y-m-d', strtotime('-1 month')), date('Y-m-d')))) { $value = $this->l('No category', null, null, false); } else { $category = new Category($id_category, $this->context->language->id); $value = $category->name; } ConfigurationKPI::updateValue('TOP_CATEGORY', array($this->context->language->id => $value)); ConfigurationKPI::updateValue('TOP_CATEGORY_EXPIRE', array($this->context->language->id => strtotime('+1 day'))); break; default: $value = false; } if ($value !== false) { $array = array('value' => $value); if (isset($data)) { $array['data'] = $data; } die(Tools::jsonEncode($array)); } die(Tools::jsonEncode(array('has_errors' => true))); }
public function initContent() { $this->checkMobileNeeds(); $themes = array(); foreach (Theme::getThemes() as $theme) { $themes[] = $theme->directory; } foreach (scandir(_PS_ALL_THEMES_DIR_) as $theme_dir) { if ($theme_dir[0] != '.' && Validate::isDirName($theme_dir) && is_dir(_PS_ALL_THEMES_DIR_ . $theme_dir) && file_exists(_PS_ALL_THEMES_DIR_ . $theme_dir . '/preview.jpg') && !in_array($theme_dir, $themes)) { $theme = new Theme(); $theme->name = $theme->directory = $theme_dir; $theme->add(); } } $content = ''; if (file_exists(_PS_IMG_DIR_ . 'logo.jpg')) { list($width, $height, $type, $attr) = getimagesize(_PS_IMG_DIR_ . Configuration::get('PS_LOGO')); Configuration::updateValue('SHOP_LOGO_HEIGHT', (int) round($height)); Configuration::updateValue('SHOP_LOGO_WIDTH', (int) round($width)); } $this->content .= $content; return parent::initContent(); }
public function renderForm() { if (!($obj = $this->loadObject(true))) { return; } $this->fields_form = array('legend' => array('title' => $this->l('Shop'), 'icon' => 'icon-shopping-cart'), 'input' => array(array('type' => 'text', 'label' => $this->l('Shop name'), 'desc' => array($this->l('This field does not refer to the shop name visible in the front office.'), sprintf($this->l('Follow %sthis link%s to edit the shop name used on the Front Office.'), '<a href="' . $this->context->link->getAdminLink('AdminStores') . '#store_fieldset_general">', '</a>')), 'name' => 'name', 'required' => true))); $display_group_list = true; if ($this->display == 'edit') { $group = new ShopGroup($obj->id_shop_group); if ($group->share_customer || $group->share_order || $group->share_stock) { $display_group_list = false; } } if ($display_group_list) { $options = array(); foreach (ShopGroup::getShopGroups() as $group) { if ($this->display == 'edit' && ($group->share_customer || $group->share_order || $group->share_stock) && ShopGroup::hasDependency($group->id)) { continue; } $options[] = array('id_shop_group' => $group->id, 'name' => $group->name); } if ($this->display == 'add') { $group_desc = $this->l('Warning: You won\'t be able to change the group of this shop if this shop belongs to a group with one of these options activated: Share Customers, Share Quantities or Share Orders.'); } else { $group_desc = $this->l('You can only move your shop to a shop group with all "share" options disabled -- or to a shop group with no customers/orders.'); } $this->fields_form['input'][] = array('type' => 'select', 'label' => $this->l('Shop group'), 'desc' => $group_desc, 'name' => 'id_shop_group', 'options' => array('query' => $options, 'id' => 'id_shop_group', 'name' => 'name')); } else { $this->fields_form['input'][] = array('type' => 'hidden', 'name' => 'id_shop_group', 'default' => $group->name); $this->fields_form['input'][] = array('type' => 'textShopGroup', 'label' => $this->l('Shop group'), 'desc' => $this->l('You can\'t edit the shop group because the current shop belongs to a group with the "share" option enabled.'), 'name' => 'id_shop_group', 'value' => $group->name); } $categories = Category::getRootCategories($this->context->language->id); $this->fields_form['input'][] = array('type' => 'select', 'label' => $this->l('Category root'), 'desc' => $this->l('This is the root category of the store that you\'ve created. To define a new root category for your store,') . ' <a href="' . $this->context->link->getAdminLink('AdminCategories') . '&addcategoryroot" target="_blank">' . $this->l('Please click here') . '</a>', 'name' => 'id_category', 'options' => array('query' => $categories, 'id' => 'id_category', 'name' => 'name')); if (Tools::isSubmit('id_shop')) { $shop = new Shop((int) Tools::getValue('id_shop')); $id_root = $shop->id_category; } else { $id_root = $categories[0]['id_category']; } $id_shop = (int) Tools::getValue('id_shop'); self::$currentIndex = self::$currentIndex . '&id_shop_group=' . (int) (Tools::getValue('id_shop_group') ? Tools::getValue('id_shop_group') : (isset($obj->id_shop_group) ? $obj->id_shop_group : Shop::getContextShopGroupID())); $shop = new Shop($id_shop); $selected_cat = Shop::getCategories($id_shop); if (empty($selected_cat)) { // get first category root and preselect all these children $root_categories = Category::getRootCategories(); $root_category = new Category($root_categories[0]['id_category']); $children = $root_category->getAllChildren($this->context->language->id); $selected_cat[] = $root_categories[0]['id_category']; foreach ($children as $child) { $selected_cat[] = $child->id; } } if (Shop::getContext() == Shop::CONTEXT_SHOP && Tools::isSubmit('id_shop')) { $root_category = new Category($shop->id_category); } else { $root_category = new Category($id_root); } $this->fields_form['input'][] = array('type' => 'categories', 'name' => 'categoryBox', 'label' => $this->l('Associated categories'), 'tree' => array('id' => 'categories-tree', 'selected_categories' => $selected_cat, 'root_category' => $root_category->id, 'use_search' => true, 'use_checkbox' => true), 'desc' => $this->l('By selecting associated categories, you are choosing to share the categories between shops. Once associated between shops, any alteration of this category will impact every shop.')); /*$this->fields_form['input'][] = array( 'type' => 'switch', 'label' => $this->l('Enabled'), 'name' => 'active', 'required' => true, 'is_bool' => true, 'values' => array( array( 'id' => 'active_on', 'value' => 1 ), array( 'id' => 'active_off', 'value' => 0 ) ), 'desc' => $this->l('Enable or disable your store?') );*/ $themes = Theme::getThemes(); if (!isset($obj->id_theme)) { foreach ($themes as $theme) { if (isset($theme->id)) { $id_theme = $theme->id; break; } } } $this->fields_form['input'][] = array('type' => 'theme', 'label' => $this->l('Theme'), 'name' => 'theme', 'values' => $themes); $this->fields_form['submit'] = array('title' => $this->l('Save')); if (Shop::getTotalShops() > 1 && $obj->id) { $disabled = array('active' => false); } else { $disabled = false; } $import_data = array('carrier' => $this->l('Carriers'), 'cms' => $this->l('CMS pages'), 'contact' => $this->l('Contact information'), 'country' => $this->l('Countries'), 'currency' => $this->l('Currencies'), 'discount' => $this->l('Discount prices'), 'employee' => $this->l('Employees'), 'image' => $this->l('Images'), 'lang' => $this->l('Languages'), 'manufacturer' => $this->l('Manufacturers'), 'module' => $this->l('Modules'), 'hook_module' => $this->l('Module hooks'), 'meta_lang' => $this->l('Meta'), 'product' => $this->l('Products'), 'product_attribute' => $this->l('Combinations'), 'scene' => $this->l('Scenes'), 'stock_available' => $this->l('Available quantities for sale'), 'store' => $this->l('Stores'), 'warehouse' => $this->l('Warehouses'), 'webservice_account' => $this->l('Webservice accounts'), 'attribute_group' => $this->l('Attribute groups'), 'feature' => $this->l('Features'), 'group' => $this->l('Customer groups'), 'tax_rules_group' => $this->l('Tax rules groups'), 'supplier' => $this->l('Suppliers'), 'referrer' => $this->l('Referrers/affiliates'), 'zone' => $this->l('Zones'), 'cart_rule' => $this->l('Cart rules')); // Hook for duplication of shop data $modules_list = Hook::getHookModuleExecList('actionShopDataDuplication'); if (is_array($modules_list) && count($modules_list) > 0) { foreach ($modules_list as $m) { $import_data['Module' . ucfirst($m['module'])] = Module::getModuleName($m['module']); } } asort($import_data); if (!$this->object->id) { $this->fields_import_form = array('radio' => array('type' => 'radio', 'label' => $this->l('Import data'), 'name' => 'useImportData', 'value' => 1), 'select' => array('type' => 'select', 'name' => 'importFromShop', 'label' => $this->l('Choose the shop (source)'), 'options' => array('query' => Shop::getShops(false), 'name' => 'name')), 'allcheckbox' => array('type' => 'checkbox', 'label' => $this->l('Choose data to import'), 'values' => $import_data), 'desc' => $this->l('Use this option to associate data (products, modules, etc.) the same way for each selected shop.')); } $this->fields_value = array('id_shop_group' => Tools::getValue('id_shop_group') ? Tools::getValue('id_shop_group') : isset($obj->id_shop_group) ? $obj->id_shop_group : Shop::getContextShopGroupID(), 'id_category' => Tools::getValue('id_category') ? Tools::getValue('id_category') : isset($obj->id_category) ? $obj->id_category : (int) Configuration::get('PS_HOME_CATEGORY'), 'id_theme_checked' => isset($obj->id_theme) ? $obj->id_theme : $id_theme); $ids_category = array(); $shops = Shop::getShops(false); foreach ($shops as $shop) { $ids_category[$shop['id_shop']] = $shop['id_category']; } $this->tpl_form_vars = array('disabled' => $disabled, 'checked' => Tools::getValue('addshop') !== false ? true : false, 'defaultShop' => (int) Configuration::get('PS_SHOP_DEFAULT'), 'ids_category' => $ids_category); if (isset($this->fields_import_form)) { $this->tpl_form_vars = array_merge($this->tpl_form_vars, array('form_import' => $this->fields_import_form)); } return parent::renderForm(); }
/** * Return an array of theme * * @return array([theme dir] => array('name' => [theme name])) * @deprecated 1.5.5.0 */ protected function _getThemesList() { Tools::displayAsDeprecated(); static $themes = array(); if (empty($themes)) { $installed_themes = Theme::getThemes(); foreach ($installed_themes as $theme) { /** @var Theme $theme */ $themes[$theme->directory] = array('name' => $theme->name); } } return $themes; }
private function displayForm1() { $installed_themes = '<option value="" >' . $this->l('select a theme to export') . '</option>'; if (_PS_VERSION_ < '1.5') { $theme_list = $this->getThemes14(); foreach ($theme_list as $row) { $installed_themes .= '<option value="' . $row . '" ' . ($row == _THEME_NAME_ ? 'selected="selected"' : '') . '>' . $row . '</option>'; } } else { $theme_list = Theme::getThemes(); foreach ($theme_list as $theme) { $installed_themes .= '<option value="' . $theme->id . '" >' . $theme->name . '</option>'; } } if (count($theme_list) > 0) { $this->_html .= ' <fieldset> <legend>' . $this->l('Export a theme') . '</legend> <label>' . $this->l('Select a theme') . '</label>'; $this->_html .= '<form action="' . $this->action_form . '" method="post" enctype="multipart/form-data">'; $this->_html .= '<div class="margin-form"> <select style="width:350px" name="id_theme">' . $installed_themes . '</select> </div> <input type="submit" class="button" name="exportTheme" value="' . $this->l('Export this theme') . '" onclick="if (!$(\'select[name=\\\'id_theme\\\']\').val().length) { alert(\'' . htmlentities($this->l('Please select a theme'), ENT_QUOTES, 'utf-8') . '\'); return false; } "/>'; $this->_html .= '</form>'; $this->_html .= '</fieldset> <div class="clear"> </div>'; } $this->_html .= ' <fieldset> <legend>' . $this->l('Import from your computer') . '</legend> <form action="' . $this->action_form . '" method="post" enctype="multipart/form-data"> <input type="hidden" name="MAX_FILE_SIZE" value="100000000" /> <label for="themearchive">' . $this->l('Archive File') . '</label> <div class="margin-form"> <input type="file" id="themearchive" name="themearchive" /> <p class="clear">' . $this->l('Where is your zip file?') . '</p> </div> <input type="submit" class="button" name="submitImport1" value="' . $this->l('Next') . '" /> </form> </fieldset> <div class="clear"> </div> '; $link_url = Tools::getValue('linkurl') ? Tools::safeOutput(Tools::getValue('linkurl')) : 'http://'; $this->_html .= ' <fieldset> <legend>' . $this->l('Import from the web') . '</legend> <form action="' . $this->action_form . '" method="post" enctype="multipart/form-data"> <label for="linkurl">' . $this->l('Archive URL') . '</label> <div class="margin-form"> <input type="text" id="linkurl" name="linkurl" value="' . $link_url . '"/> </div> <input type="submit" class="button" name="submitImport2" value="' . $this->l('Next') . '" /> </form> </fieldset> <div class="clear"> </div>'; // Import folder is located in the module directory $import_dir = scandir(_IMPORT_FOLDER_); $list = array(); foreach ($import_dir as $row) { if (substr(_IMPORT_FOLDER_ . $row, -4) == '.zip') { $list[] = $row; } } $import_dir = ''; foreach ($list as $row) { $import_dir .= '<option value="' . $row . '">' . $row . '</option>'; } $this->_html .= ' <fieldset> <legend>' . $this->l('Import from FTP') . '</legend> <form action="' . $this->action_form . '" method="post" enctype="multipart/form-data"> <label for="linkurl">' . $this->l('Select archive') . '</label> <div class="margin-form"> <select name="ArchiveName" style="width:350px"> ' . $import_dir . ' </select> <p>' . sprintf($this->l('Select the ZIP file you want to use (it should have been uploaded to your %s directory).'), '<b>modules/themeinstallator/import/</b>') . '</p> </div> <input type="submit" class="button" name="submitImport3" value="' . $this->l('Next') . '" /> </form> </fieldset> <div class="clear"> </div>'; }
protected function isThemeInstalled($theme_name) { $themes = Theme::getThemes(); foreach ($themes as $theme_object) { /** @var Theme $theme_object */ if ($theme_object->name == $theme_name) { return true; } } return false; }
private function searchHooksInThemes() { $themes = Theme::getThemes(); $not_found_hooks = array(); foreach ($themes as $theme) { if (!$theme->isUsed()) { continue; } $this->searchHooksInTheme($theme->directory, $not_found_hooks); } return $not_found_hooks; }
public function isThemeInstalled($theme_name) { $themes = Theme::getThemes(); foreach ($themes as $theme_object) { if ($theme_object->name == $theme_name) { return true; } } return false; }
/** * Get all informations on : languages, theme and the translation type. */ public function getInformations() { // Get all Languages $this->languages = Language::getLanguages(false); // Get all iso_code of languages foreach ($this->languages as $language) { $this->all_iso_lang[] = $language['iso_code']; } // Get all themes $this->themes = Theme::getThemes(); // Get folder name of theme if (($theme = Tools::getValue('theme')) && !is_array($theme)) { $this->theme_selected = Tools::safeOutput($theme); } else { $this->theme_selected = self::DEFAULT_THEME_NAME; } // Set the path of selected theme define('_PS_THEME_SELECTED_DIR_', _PS_ROOT_DIR_ . '/themes/' . $this->theme_selected . '/'); // Get type of translation if (($type = Tools::getValue('type')) && !is_array($type)) { $this->type_selected = strtolower(Tools::safeOutput($type)); } // Get selected language if (Tools::getValue('lang') || Tools::getValue('iso_code')) { $iso_code = Tools::getValue('lang') ? Tools::getValue('lang') : Tools::getValue('iso_code'); if (!Validate::isLangIsoCode($iso_code) || !in_array($iso_code, $this->all_iso_lang)) { throw new PrestaShopException(sprintf(Tools::displayError('Invalid iso code "%s"'), $iso_code)); } $this->lang_selected = new Language((int) Language::getIdByIso($iso_code)); } else { $this->lang_selected = new Language((int) Language::getIdByIso('en')); } // Get all information for translations $this->getTranslationsInformations(); }
protected function theme_exists($theme) { if (!is_array($this->themes)) { $this->themes = Theme::getThemes(); } $theme_exists = false; foreach ($this->themes as $existing_theme) { if ($existing_theme->directory == $theme) { return true; } } return false; }