public static function getPages($exclude_filled = false, $add_page = false) { $selected_pages = array(); if (!($files = Tools::scandir(_PS_ROOT_DIR_ . '/controllers/front/', 'php', '', true))) { die(Tools::displayError('Cannot scan root directory')); } // Exclude pages forbidden $exlude_pages = array('category', 'changecurrency', 'cms', 'footer', 'header', 'pagination', 'product', 'product-sort', 'statistics'); foreach ($files as $file) { if ($file != 'index.php' && !in_array(strtolower(str_replace('Controller.php', '', $file)), $exlude_pages)) { $class_name = str_replace('.php', '', $file); if (class_exists($class_name)) { $reflection = new ReflectionClass(str_replace('.php', '', $file)); } if (isset($reflection) && $reflection) { $properties = $reflection->getDefaultProperties(); } if (isset($properties['php_self'])) { $selected_pages[$properties['php_self']] = $properties['php_self']; } else { if (preg_match('/^[a-z0-9_.-]*\\.php$/i', $file)) { $selected_pages[strtolower(str_replace('Controller.php', '', $file))] = strtolower(str_replace('Controller.php', '', $file)); } else { if (preg_match('/^([a-z0-9_.-]*\\/)?[a-z0-9_.-]*\\.php$/i', $file)) { $selected_pages[strtolower(sprintf(Tools::displayError('%2$s (in %1$s)'), dirname($file), str_replace('Controller.php', '', basename($file))))] = strtolower(str_replace('Controller.php', '', basename($file))); } } } } } // Add modules controllers to list (this function is cool !) foreach (glob(_PS_MODULE_DIR_ . '*/controllers/front/*.php') as $file) { $filename = Tools::strtolower(basename($file, '.php')); if ($filename == 'index') { continue; } $module = Tools::strtolower(basename(dirname(dirname(dirname($file))))); $selected_pages[$module . ' - ' . $filename] = 'module-' . $module . '-' . $filename; } // Exclude page already filled if ($exclude_filled) { $metas = Meta::getMetas(); foreach ($metas as $meta) { if (in_array($meta['page'], $selected_pages)) { unset($selected_pages[array_search($meta['page'], $selected_pages)]); } } } // Add selected page if ($add_page) { $name = $add_page; if (preg_match('#module-([a-z0-9_-]+)-([a-z0-9]+)$#i', $add_page, $m)) { $add_page = $m[1] . ' - ' . $m[2]; } $selected_pages[$add_page] = $name; asort($selected_pages); } return $selected_pages; }
function __construct() { $exculde = array('pagenotfound', 'index'); foreach (Meta::getMetas() as $meta) { if (!in_array($meta['page'], $exculde)) { $this->_config['controller']['fields']['PST_CONTROLLER_' . strtoupper(str_replace('-', '_', $meta['page']))] = array('type' => 'bool', 'label' => ucfirst(str_replace('-', ' ', $meta['page'])), 'default_value' => true); } } $this->name = 'pst'; $this->tab = version_compare(_PS_VERSION_, '1.4.0.0', '<') ? 'Tools' : 'administration'; $this->version = '0.1.4'; parent::__construct(); $this->dependencies = array(); $this->_hook_list = array('header', 'controllerConstruct', 'backOfficeHome', 'displayBackOfficeFooter'); /* The parent construct is required for translations */ $this->page = basename(__FILE__, '.php'); $this->displayName = $this->l('Tools'); $this->description = $this->l('A set of tools by PrestaSuperTool'); $this->_html = ''; }
public function processAdd() { if (($new_dir = Tools::getValue('directory')) != '') { if (!Validate::isDirName($new_dir)) { $this->display = 'add'; return !($this->errors[] = sprintf(Tools::displayError('"%s" is not a valid directory name'), $new_dir)); } if (Theme::getByDirectory($new_dir)) { $this->display = 'add'; return !($this->errors[] = Tools::displayError('A directory with this name already exist')); } if (mkdir(_PS_ALL_THEMES_DIR_ . $new_dir, Theme::$access_rights)) { $this->confirmations[] = $this->l('The directory was successfully created.'); } if (0 !== ($id_based = (int) Tools::getValue('based_on'))) { $base_theme = new Theme($id_based); $this->copyTheme($base_theme->directory, $new_dir); $base_theme = new Theme((int) Tools::getValue('based_on')); } if (isset($_FILES['image_preview']) && $_FILES['image_preview']['error'] == 0) { if (@getimagesize($_FILES['image_preview']['tmp_name']) && !ImageManager::validateUpload($_FILES['image_preview'], Tools::getMaxUploadSize())) { move_uploaded_file($_FILES['image_preview']['tmp_name'], _PS_ALL_THEMES_DIR_ . $new_dir . '/preview.jpg'); } else { $this->errors[] = $this->l('Image not valid'); $this->display = 'form'; return false; } } } $theme = parent::processAdd(); if ((int) $theme->product_per_page == 0) { $theme->product_per_page = 1; $theme->save(); } if (is_object($theme) && (int) $theme->id > 0) { $metas = Meta::getMetas(); foreach ($metas as &$meta) { $meta['left'] = $theme->default_left_column; $meta['right'] = $theme->default_right_column; } $theme->updateMetas($metas, true); } return $theme; }
public function hookactionModuleRegisterHookAfter($params) { $module = $params['object']; $current_theme = Theme::getThemeInfo($this->context->shop->id_theme); if (!$this->IsOvicThemes($current_theme['theme_name'])) { return; } if ($module->name != $this->name) { $hook_name = $params['hook_name']; if ($hook_name && Validate::isHookName($hook_name)) { $id_hook = Hook::getIdByName($hook_name); $hook_name = Hook::getNameById($id_hook); // get full hookname //order possition hook $id_hook_header = Hook::getIdByName('Header'); if ($id_hook && $id_hook === $id_hook_header) { $this->changeHeaderPosition(); } if (in_array($hook_name, self::$OptionHookAssign)) { $this->backupModuleHook($id_hook, 'hook_module', 'ovic_backup_hook_module', true); } elseif (in_array($hook_name, self::getHookexecuteList())) { $this->backupModuleHook($id_hook, 'hook_module', 'ovic_backup_hook_module', false); } else { return; } $id_shop = (int) $this->context->shop->id; $current_id_option = Configuration::get('OVIC_CURRENT_OPTION', null, null, $id_shop); $current_option = new Options($current_id_option); $moduleHook = array(); $moduleHook[] = $module->name; $moduleHook[] = $hook_name; if ($current_option && Validate::isLoadedObject($current_option)) { //insert module to current option $HookedModulesArr = self::getModulesHook($current_option->theme, $current_option->alias, $hook_name); $HookedModulesArr = Tools::jsonDecode($HookedModulesArr['modules'], true); if (!is_array($HookedModulesArr)) { $HookedModulesArr = array(); } $key = array_search($moduleHook, $HookedModulesArr); if ($key && !array_key_exists($key, $HookedModulesArr)) { $HookedModulesArr[] = $moduleHook; self::registerHookModule($current_option, $hook_name, Tools::jsonEncode($HookedModulesArr), $id_shop); } } $pagelist = Meta::getMetas(); $sidebarPages = array(); $theme = new Theme((int) $this->context->shop->id_theme); if ($hook_name == 'displayLeftColumn' || $hook_name == 'displayRightColumn') { foreach ($pagelist as $page) { if ($hook_name == 'displayLeftColumn' && $theme->hasLeftColumn($page['page'])) { $HookedModulesArr = self::getSideBarModulesByPage($page['page'], 'left', false); if (!is_array($HookedModulesArr)) { $HookedModulesArr = array(); } $key = array_search($moduleHook, $HookedModulesArr); if ($key && !array_key_exists($key, $HookedModulesArr)) { $HookedModulesArr[] = $moduleHook; self::registerSidebarModule($page['page'], 'left', Tools::jsonEncode($HookedModulesArr), $id_shop); } } if ($hook_name == 'displayRightColumn' && $theme->hasRightColumn($page['page'])) { $HookedModulesArr = self::getSideBarModulesByPage($page['page'], 'right', false); if (!is_array($HookedModulesArr)) { $HookedModulesArr = array(); } $key = array_search($moduleHook, $HookedModulesArr); if ($key && !array_key_exists($key, $HookedModulesArr)) { $HookedModulesArr[] = $moduleHook; self::registerSidebarModule($page['page'], 'right', Tools::jsonEncode($HookedModulesArr), $id_shop); } } } } } } }
public function renderList() { $view = Tools::getValue('view', 'default'); $id_lang = $this->context->language->id; $id_shop = $this->context->shop->id; if ($view == 'default') { $languages = Language::getLanguages(false); $id_lang_default = (int) Configuration::get('PS_LANG_DEFAULT'); $tpl = $this->createTemplate('oviclayout.tpl'); $id_tab = (int) Tools::getValue('id_tab', 0); $current_id_option = Configuration::get('OVIC_CURRENT_OPTION', null, null, $id_shop); $check_option = new Options($current_id_option); $current_theme = Theme::getThemeInfo($this->context->shop->id_theme); if (strtolower($check_option->theme) != strtolower($current_theme['theme_name'])) { Configuration::deleteByName('OVIC_CURRENT_OPTION'); Configuration::deleteByName('OVIC_LAYOUT_COLUMN'); Configuration::deleteByName('OVIC_CURRENT_DIR'); $current_id_option = null; } $emptyOption = false; $sql = 'SELECT * FROM `' . _DB_PREFIX_ . 'ovic_options` o WHERE LCASE(o.`theme`) =\'' . strtolower($current_theme['theme_name']) . '\''; $options = Db::getInstance()->executeS($sql); if ($options && is_array($options) && sizeof($options) > 0) { if (!$current_id_option || !Validate::isUnsignedId($current_id_option) || !OvicLayoutControl::isAvailablebyId($current_id_option)) { foreach ($options as $option) { $current_option = new Options($option['id_option']); Configuration::updateValue('OVIC_CURRENT_OPTION', $option['id_option'], false, null, $id_shop); Configuration::updateValue('OVIC_CURRENT_DIR', str_replace(' ', '_', $current_option->alias), false, null, $id_shop); $current_id_option = $option['id_option']; break; } } } else { $emptyOption = true; } if ($options && is_array($options) && sizeof($options) > 0) { $current_option = new Options($current_id_option); } if (!$emptyOption) { $selected_layout = Configuration::get('OVIC_LAYOUT_COLUMN', null, null, $id_shop); if (!$selected_layout || substr_count($current_option->column, $selected_layout) < 1) { if (strlen($current_option->column) > 0) { $selected_layout = (int) substr($current_option->column, 0, 1); Configuration::updateValue('OVIC_LAYOUT_COLUMN', $selected_layout, false, null, $id_shop); $this->ProcessLayoutColumn(); } } } else { $tpl->assign(array('emptyOption' => Tools::displayError('There is no Option, please add new Option from Layout Builder menu.'))); } //get sidebar infomation $pagelist = Meta::getMetas(); $sidebarPages = array(); if ($pagelist && is_array($pagelist) && sizeof($pagelist) > 0) { $theme = new Theme((int) $this->context->shop->id_theme); foreach ($pagelist as $page) { $sidebarPage = array(); $meta_object = new Meta($page['id_meta']); $title = $page['page']; if (isset($meta_object->title[(int) $id_lang]) && $meta_object->title[(int) $id_lang] != '') { $title = $meta_object->title[(int) $id_lang]; } $sidebarPage['id_meta'] = $page['id_meta']; $sidebarPage['title'] = $title; $sidebarPage['page_name'] = $page['page']; $sidebarPage['displayLeft'] = $theme->hasLeftColumn($page['page']) ? 1 : 0; $sidebarPage['displayRight'] = $theme->hasRightColumn($page['page']) ? 1 : 0; $sidebarPages[] = $sidebarPage; } } $tpl->assign(array('postUrl' => self::$currentIndex . '&token=' . Tools::getAdminTokenLite('AdminLayoutSetting'), 'absoluteUrl' => __PS_BASE_URI__ . 'modules/' . $this->module->name, 'id_tab' => $id_tab, 'options' => $options, 'current_option' => isset($current_option) ? $current_option : null, 'selected_layout' => isset($selected_layout) ? $selected_layout : null, 'sidebarPages' => $sidebarPages)); } elseif ($view == 'detail') { $tpl = $this->createTemplate('sidebarmodule.tpl'); $pagemeta = Tools::getValue('pagemeta'); $meta = Meta::getMetaByPage($pagemeta, $id_lang); $theme = new Theme((int) $this->context->shop->id_theme); $LeftModules = array(); $RightModules = array(); if ($theme->hasLeftColumn($pagemeta)) { $LeftModules = OvicLayoutControl::getSideBarModulesByPage($pagemeta, 'left'); } if ($theme->hasRightColumn($pagemeta)) { $RightModules = OvicLayoutControl::getSideBarModulesByPage($pagemeta, 'right'); } $tpl->assign(array('postUrl' => self::$currentIndex . '&token=' . Tools::getAdminTokenLite('AdminLayoutSetting'), 'leftModule' => $LeftModules, 'rightModule' => $RightModules, 'pagemeta' => $pagemeta, 'pagename' => $meta['title'], 'displayLeft' => $theme->hasLeftColumn($pagemeta), 'displayRight' => $theme->hasRightColumn($pagemeta), 'templatePath' => $this->getTemplatePath(), 'moduleDir' => _MODULE_DIR_)); } return $tpl->fetch(); }
public function hookactionModuleRegisterHookAfter($params) { $module = $params['object']; if ($module->name != $this->name) { $hook_name = $params['hook_name']; if ($hook_name && Validate::isHookName($hook_name)) { $id_hook = Hook::getIdByName($hook_name); $hook_name = Hook::getNameById($id_hook); if (in_array($hook_name, self::$OptionHookAssign)) { $this->backupModuleHook($id_hook, 'hook_module', 'ovic_backup_hook_module', true); } elseif (in_array($hook_name, self::getHookexecuteList())) { $this->backupModuleHook($id_hook, 'hook_module', 'ovic_backup_hook_module', false); } $id_shop = $this->context->shop->id; $current_id_option = Configuration::get('OVIC_CURRENT_OPTION'); $moduleHook = array(); $moduleHook[] = $module->name; $moduleHook[] = $hook_name; if ($current_id_option && Validate::isUnsignedId($current_id_option)) { //insert module to current option $HookedModulesArr = self::getModulesHook($current_id_option, $hook_name); $HookedModulesArr = Tools::jsonDecode($HookedModulesArr['modules'], true); if (!is_array($HookedModulesArr)) { $HookedModulesArr = array(); } $key = array_search($moduleHook, $HookedModulesArr); if (!array_key_exists($key, $HookedModulesArr)) { $HookedModulesArr[] = $moduleHook; self::registerHookModule($current_id_option, $hook_name, Tools::jsonEncode($HookedModulesArr), $this->context->shop->id); } } $pagelist = Meta::getMetas(); $sidebarPages = array(); $theme = new Theme((int) $this->context->shop->id_theme); if ($hook_name == 'displayLeftColumn' || $hook_name == 'displayRightColumn') { foreach ($pagelist as $page) { if ($hook_name == 'displayLeftColumn' && $theme->hasLeftColumn($page['page'])) { $HookedModulesArr = self::getSideBarModulesByPage($page['page'], 'left', false); $HookedModulesArr[] = $moduleHook; self::registerSidebarModule($page['page'], 'left', Tools::jsonEncode($HookedModulesArr), $this->context->shop->id); } if ($hook_name == 'displayRightColumn' && $theme->hasRightColumn($page['page'])) { $HookedModulesArr = self::getSideBarModulesByPage($page['page'], 'right', false); $HookedModulesArr[] = $moduleHook; self::registerSidebarModule($page['page'], 'right', Tools::jsonEncode($HookedModulesArr), $this->context->shop->id); } } } } } }
public function getContent() { if (Tools::isSubmit('SubmitGsitemap')) { Configuration::updateValue('GSITEMAP_FREQUENCY', pSQL(Tools::getValue('gsitemap_frequency'))); if (Tools::getValue('gsitemap_meta')) { $meta = ''; foreach (Tools::getValue('gsitemap_meta') as $val) { $meta .= (int) $val . ','; } Configuration::updateValue('GSITEMAP_DISABLE_LINKS', $meta); } $this->removeSitemap(); $this->createSitemap(); } elseif (Tools::getValue('continue')) { $this->createSitemap(); } /* Backward compatibility */ if (_PS_VERSION_ < 1.5) { require _PS_MODULE_DIR_ . 'gsitemap/backward_compatibility/backward.php'; } $this->context->smarty->assign(array('gsitemap_form' => './index.php?tab=AdminModules&configure=gsitemap&token=' . Tools::getAdminTokenLite('AdminModules') . '&tab_module=' . $this->tab . '&module_name=gsitemap', 'gsitemap_cron' => _PS_BASE_URL_ . _MODULE_DIR_ . 'gsitemap/gsitemap-cron.php?token=' . substr(Tools::encrypt('gsitemap/cron'), 0, 10), 'gsitemap_feed_exists' => file_exists(dirname(__FILE__) . '/../../index_sitemap.xml'), 'gsitemap_last_export' => Configuration::get('GSITEMAP_LAST_EXPORT'), 'gsitemap_frequency' => Configuration::get('GSITEMAP_FREQUENCY'), 'gsitemap_store_url' => 'http' . (Configuration::get('PS_SSL_ENABLED') ? 's' : '') . '://' . Tools::getShopDomain(false, true) . __PS_BASE_URI__, 'gsitemap_links' => Db::getInstance()->ExecuteS('SELECT * FROM `' . _DB_PREFIX_ . 'gsitemap_sitemap`'), 'store_metas' => Meta::getMetas(), 'gsitemap_disable_metas' => explode(',', Configuration::get('GSITEMAP_DISABLE_LINKS')), 'gsitemap_customer_limit' => array('max_exec_time' => (int) ini_get('max_execution_time'), 'memory_limit' => intval(ini_get('memory_limit'))), 'prestashop_version' => _PS_VERSION_ >= 1.5 ? '1.5' : '1.4', 'prestashop_ssl' => Configuration::get('PS_SSL_ENABLED'))); return $this->display(__FILE__, 'tpl/configuration.tpl'); }