895 lines
35 KiB
PHP
895 lines
35 KiB
PHP
<?php
|
||
/**
|
||
* 2007-2018 PrestaShop
|
||
*
|
||
* NOTICE OF LICENSE
|
||
*
|
||
* This source file is subject to the Academic Free License (AFL 3.0)
|
||
* that is bundled with this package in the file LICENSE.txt.
|
||
* It is also available through the world-wide-web at this URL:
|
||
* http://opensource.org/licenses/afl-3.0.php
|
||
* If you did not receive a copy of the license and are unable to
|
||
* obtain it through the world-wide-web, please send an email
|
||
* to license@prestashop.com so we can send you a copy immediately.
|
||
*
|
||
* DISCLAIMER
|
||
*
|
||
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
|
||
* versions in the future. If you wish to customize PrestaShop for your
|
||
* needs please refer to http://www.prestashop.com for more information.
|
||
*
|
||
* @author PrestaShop SA <contact@prestashop.com>
|
||
* @copyright 2007-2018 PrestaShop SA
|
||
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
|
||
* International Registered Trademark & Property of PrestaShop SA
|
||
*/
|
||
|
||
if (!defined('_PS_VERSION_')) {
|
||
exit;
|
||
}
|
||
|
||
require_once(dirname(__FILE__) . '/classes/pssitemapDataClass.php');
|
||
|
||
class Pssitemap extends Module
|
||
{
|
||
protected $front_controller = null;
|
||
private $google_font = array(
|
||
'https://fonts.googleapis.com/css?family=Roboto',
|
||
'https://fonts.googleapis.com/css?family=Hind',
|
||
'https://fonts.googleapis.com/css?family=Maven+Pro',
|
||
'https://fonts.googleapis.com/css?family=Noto+Serif',
|
||
'https://fonts.googleapis.com/css?family=Bitter',
|
||
'https://fonts.googleapis.com/css?family=Forum',
|
||
);
|
||
|
||
private $font_text = array(1 => 'Roboto', 2 => 'Hind', 3 => 'Maven Pro', 4 => 'Noto Serif', 5 => 'Bitter', 6 => 'Forum');
|
||
|
||
public function __construct()
|
||
{
|
||
// Settings
|
||
$this->name = 'pssitemap';
|
||
$this->tab = 'seo';
|
||
$this->version = '1.1.2';
|
||
$this->author = 'PrestaShop';
|
||
$this->need_instance = 0;
|
||
|
||
$this->module_key = '938b96386d4d79aa7cb891439cb0ef11';
|
||
$this->author_address = '0x64aa3c1e4034d07015f639b0e171b0d7b27d01aa';
|
||
|
||
// Controllers
|
||
$this->controller_name = 'AdminAjaxPsSiteMap';
|
||
|
||
// bootstrap -> always set to true
|
||
$this->bootstrap = true;
|
||
|
||
parent::__construct();
|
||
|
||
$this->output = '';
|
||
|
||
$this->displayName = $this->l('Sitemap Generator for SEO (XML AND HTML)');
|
||
$this->description = $this->l('This module allows you to optimize the SEO of your site on all search engines by automatically generating your store’s sitemaps.');
|
||
|
||
// Settings paths
|
||
$this->js_path = $this->_path.'views/js/';
|
||
$this->css_path = $this->_path.'views/css/';
|
||
$this->img_path = $this->_path.'views/img/';
|
||
$this->docs_path = $this->_path.'docs/';
|
||
$this->logo_path = $this->_path.'logo.png';
|
||
$this->module_path = $this->_path;
|
||
|
||
// Confirm uninstall
|
||
$this->confirmUninstall = $this->l('Are you sure you want to uninstall this module?');
|
||
$this->ps_versions_compliancy = array('min' => '1.6', 'max' => _PS_VERSION_);
|
||
}
|
||
|
||
/**
|
||
* install()
|
||
*
|
||
* @param none
|
||
* @return bool
|
||
*/
|
||
public function install()
|
||
{
|
||
$id_lang = $this->context->language->id;
|
||
$token = Tools::encrypt(microtime());
|
||
|
||
Configuration::updateValue('PSM_CRON_TOKEN', $token);
|
||
Configuration::updateValue('LANGUAGE_CONF', $id_lang);
|
||
Configuration::updateValue('IMG_LINKS_SITEMAP', 1);
|
||
Configuration::updateValue('HOMEPAGE_BUTTON', 1);
|
||
Configuration::updateValue('SITEMAP_CATEGORY', 1);
|
||
Configuration::updateValue('SITEMAP_PRODUCT', 1);
|
||
Configuration::updateValue('SITEMAP_CMS', 1);
|
||
Configuration::updateValue('SITEMAP_OTHER_PAGES', 1);
|
||
//Configuration::updateValue('CMS_PAGE', 0);
|
||
Configuration::updateValue('SITEMAP_HTML', 1);
|
||
|
||
Configuration::updateValue('FONT_TEXT', 'roboto');
|
||
Configuration::updateValue('PAGE_TITLE_COLOR', '#ffcb9b');
|
||
Configuration::updateValue('PAGE_CATEGORY_COLOR', '#7fff80');
|
||
Configuration::updateValue('PAGE_LINK_COLOR', '#2f89ff');
|
||
Configuration::updateValue('LAYOUT-CHOICE', 1);
|
||
|
||
Configuration::updateValue('PRODUCT_PRIORITY', '0.5');
|
||
Configuration::updateValue('PRODUCT_FREQUENCY', 'always');
|
||
|
||
Configuration::updateValue('CATEGORY_PRIORITY', '0.5');
|
||
Configuration::updateValue('CATEGORY_FREQUENCY', 'always');
|
||
|
||
Configuration::updateValue('HOMEPAGE_PRIORITY', '0.5');
|
||
Configuration::updateValue('HOMEPAGE_FREQUENCY', 'always');
|
||
|
||
Configuration::updateValue('CMS_PRIORITY', '0.5');
|
||
Configuration::updateValue('CMS_FREQUENCY', 'always');
|
||
|
||
Configuration::updateValue('OTHER_PAGE_PRIORITY', '0.5');
|
||
Configuration::updateValue('OTHER_PAGE_FREQUENCY', 'always');
|
||
|
||
configuration::updateValue('CMS_PAGE', 1);
|
||
|
||
include(dirname(__FILE__).'/sql/install.php'); // sql querries
|
||
|
||
// register hook used by the module
|
||
if (parent::install() &&
|
||
$this->installTab() &&
|
||
$this->registerHook('header') &&
|
||
$this->registerHook('actionProductSave') &&
|
||
$this->registerHook('actionCategoryAdd') &&
|
||
$this->registerHook('actionObjectCmsAddAfter') &&
|
||
$this->registerHook('actionProductUpdate') &&
|
||
$this->registerHook('displayFooter') == false) {
|
||
$this->_errors[] = $this->l('There was an error during the installation. Please contact us through Addons website');
|
||
return false;
|
||
}
|
||
|
||
if (version_compare(_PS_VERSION_, '1.7', '>=')) {
|
||
$this->registerHook('ActionFrontControllerSetMedia');
|
||
}
|
||
|
||
$id_lang = explode(",", configuration::get('LANGUAGE_CONF'));
|
||
|
||
foreach ($id_lang as $value) {
|
||
$aProducts = Product::getProducts($value, 0, 0, 'id_product', 'ASC', false, true);
|
||
$nbproducts = count($aProducts);
|
||
for ($i=0; $i < $nbproducts; $i++) {
|
||
PssitemapData::updateExportElement($aProducts[$i]['id_product'], 'product', 1);
|
||
}
|
||
|
||
$aCategories = Category::getSimpleCategories($value);
|
||
$nbCategories = count($aCategories);
|
||
for ($i=0; $i < $nbCategories; $i++) {
|
||
PssitemapData::updateExportElement($aCategories[$i]['id_category'], 'category', 1);
|
||
}
|
||
|
||
$aCMS = CMS::listCms($value, false, false);
|
||
$nbCms = count($aCMS);
|
||
for ($i=0; $i < $nbCms; $i++) {
|
||
PssitemapData::updateExportElement($aCMS[$i]['id_cms'], 'cms', 1);
|
||
}
|
||
}
|
||
|
||
return true;
|
||
}
|
||
|
||
/**
|
||
* uninstall()
|
||
*
|
||
* @param none
|
||
* @return bool
|
||
*/
|
||
public function uninstall()
|
||
{
|
||
// some stuff
|
||
Configuration::deleteByName('PSM_CRON_TOKEN');
|
||
Configuration::deleteByName('LANGUAGE_CONF');
|
||
Configuration::deleteByName('IMG_LINKS_SITEMAP');
|
||
Configuration::deleteByName('HOMEPAGE_BUTTON');
|
||
Configuration::deleteByName('SITEMAP_CATEGORY');
|
||
Configuration::deleteByName('SITEMAP_PRODUCT');
|
||
Configuration::deleteByName('SITEMAP_CMS');
|
||
Configuration::deleteByName('SITEMAP_OTHER_PAGES');
|
||
Configuration::deleteByName('CMS_PAGE');
|
||
|
||
Configuration::deleteByName('SITEMAP_HTML');
|
||
Configuration::deleteByName('FONT_TEXT');
|
||
Configuration::deleteByName('PAGE_TITLE_COLOR');
|
||
Configuration::deleteByName('PAGE_CATEGORY_COLOR');
|
||
Configuration::deleteByName('PAGE_LINK_COLOR');
|
||
Configuration::deleteByName('LAYOUT-CHOICE');
|
||
|
||
Configuration::deleteByName('PRODUCT_PRIORITY');
|
||
Configuration::deleteByName('PRODUCT_FREQUENCY');
|
||
Configuration::deleteByName('CATEGORY_PRIORITY');
|
||
Configuration::deleteByName('CATEGORY_FREQUENCY');
|
||
Configuration::deleteByName('HOMEPAGE_PRIORITY');
|
||
Configuration::deleteByName('HOMEPAGE_FREQUENCY');
|
||
Configuration::deleteByName('CMS_PRIORITY');
|
||
Configuration::deleteByName('CMS_FREQUENCY');
|
||
Configuration::deleteByName('OTHER_PAGE_PRIORITY');
|
||
Configuration::deleteByName('OTHER_PAGE_FREQUENCY');
|
||
|
||
include(dirname(__FILE__).'/sql/uninstall.php');
|
||
// unregister hook
|
||
if (parent::uninstall() &&
|
||
$this->uninstallTab() &&
|
||
$this->unregisterHook('header') &&
|
||
$this->unregisterHook('actionProductSave') &&
|
||
$this->unregisterHook('actionCategoryAdd') &&
|
||
$this->unregisterHook('actionObjectCmsAddAfter') &&
|
||
$this->unregisterHook('displayFooter')) {
|
||
return true;
|
||
} else {
|
||
$this->_errors[] = $this->l('There was an error during the desinstallation. Please contact us through Addons website');
|
||
return false;
|
||
}
|
||
|
||
if (version_compare(_PS_VERSION_, '1.7', '>=')) {
|
||
$this->unregisterHook('ActionFrontControllerSetMedia');
|
||
}
|
||
|
||
|
||
include(dirname(__FILE__).'/sql/uninstall.php');
|
||
|
||
return parent::uninstall();
|
||
}
|
||
|
||
/**
|
||
* This method is often use to create an ajax controller
|
||
*
|
||
* @param none
|
||
* @return bool
|
||
*/
|
||
public function installTab()
|
||
{
|
||
$tab = new Tab();
|
||
$tab->active = 1;
|
||
$tab->class_name = $this->controller_name;
|
||
$tab->name = array();
|
||
foreach (Language::getLanguages(true) as $lang) {
|
||
$tab->name[$lang['id_lang']] = $this->name;
|
||
}
|
||
$tab->id_parent = -1;
|
||
$tab->module = $this->name;
|
||
$result = $tab->add();
|
||
|
||
return ($result);
|
||
}
|
||
|
||
/**
|
||
* uninstall tab
|
||
*
|
||
* @param none
|
||
* @return bool
|
||
*/
|
||
public function uninstallTab()
|
||
{
|
||
$id_tab = (int)Tab::getIdFromClassName($this->controller_name);
|
||
if ($id_tab) {
|
||
$tab = new Tab($id_tab);
|
||
if (Validate::isLoadedObject($tab)) {
|
||
return ($tab->delete());
|
||
} else {
|
||
$return = false;
|
||
}
|
||
} else {
|
||
$return = true;
|
||
}
|
||
|
||
return ($return);
|
||
}
|
||
|
||
/**
|
||
* load dependencies
|
||
*/
|
||
public function loadAsset()
|
||
{
|
||
$controller = Context::getContext()->controller;
|
||
// Load CSS
|
||
$css = array(
|
||
$this->css_path.'font-awesome.min.css',
|
||
$this->css_path.'faq.css',
|
||
$this->css_path.'back.css',
|
||
$this->css_path.'menu.css',
|
||
$this->css_path.'bitter.css',
|
||
$this->css_path.'forum.css',
|
||
$this->css_path.'hind.css',
|
||
$this->css_path.'mavenPro.css',
|
||
$this->css_path.'notoSerif.css',
|
||
$this->css_path.'roboto.css',
|
||
$this->css_path.'bootstrap-datatables.css',
|
||
);
|
||
|
||
$this->context->controller->addCSS($css, 'all');
|
||
$this->context->controller->addCSS($this->google_font);
|
||
|
||
// Load JS
|
||
$jss = array(
|
||
$this->js_path.'faq.js',
|
||
$this->js_path.'menu.js',
|
||
$this->js_path.'back.js',
|
||
$this->js_path.'vue.js',
|
||
$this->js_path.'bootstrap-datatables.js',
|
||
);
|
||
|
||
// prestashop plugin
|
||
$controller->addJqueryPlugin('colorpicker');
|
||
$controller->addJqueryUI('ui.sortable');
|
||
|
||
$this->context->controller->addJS($jss);
|
||
|
||
// Clean memory
|
||
unset($jss, $css);
|
||
}
|
||
|
||
/**
|
||
* FAQ API
|
||
*/
|
||
public function loadFaq()
|
||
{
|
||
include_once('classes/APIFAQClass.php');
|
||
$api = new APIFAQ();
|
||
$faq = $api->getData($this->module_key, $this->version);
|
||
|
||
return $faq;
|
||
}
|
||
|
||
/**
|
||
* Load the configuration form
|
||
*/
|
||
public function getContent()
|
||
{
|
||
$id_lang = $this->context->language->id;
|
||
$iso_lang = Language::getIsoById($id_lang);
|
||
$id_shop = (int)Context::getContext()->shop->id;
|
||
$active_language = explode(",", configuration::get('LANGUAGE_CONF'));
|
||
$doc = $this->docs_path.'readme_'.$iso_lang.'.pdf';
|
||
//cron URL
|
||
$cron_url = Tools::getShopDomain(true, true).__PS_BASE_URI__."modules/pssitemap/cron.php?token=".configuration::get('PSM_CRON_TOKEN');
|
||
|
||
$this->loadFaq();
|
||
$this->loadAsset();
|
||
$this->postProcess();
|
||
|
||
$params = array('configure' => $this->name);
|
||
$moduleAdminLink = Context::getContext()->link->getAdminLink('AdminModules', true, false, $params);
|
||
|
||
// get current page
|
||
$currentPage = 'XMLconf';
|
||
if (Tools::getValue('page') != '') {
|
||
$currentPage = Tools::getValue('page');
|
||
}
|
||
$getCatToExp = PssitemapData::getCategoryToExport($id_shop);
|
||
if (empty($getCatToExp)) {
|
||
$getCatToExp = true;
|
||
} else {
|
||
$getCatToExp = false;
|
||
}
|
||
|
||
$getProdToExp = PssitemapData::getProductToExport($id_shop);
|
||
if (empty($getProdToExp)) {
|
||
$getProdToExp = true;
|
||
} else {
|
||
$getProdToExp = false;
|
||
}
|
||
|
||
$getCmsToExp = PssitemapData::getCmsToExport($id_shop);
|
||
if (empty($getCmsToExp)) {
|
||
$getCmsToExp = true;
|
||
} else {
|
||
$getCmsToExp = false;
|
||
}
|
||
|
||
$getOpToExp = PssitemapData::getOtherPageToExport($id_shop);
|
||
if (empty($getOpToExp)) {
|
||
$getOpToExp = true;
|
||
} else {
|
||
$getOpToExp = false;
|
||
}
|
||
// controller ajax url
|
||
$link = new Link();
|
||
$controller_url = $link->getAdminLink($this->controller_name);
|
||
|
||
// assign var to smarty
|
||
$this->context->smarty->assign(array(
|
||
'module_name' => $this->name,
|
||
'module_version' => $this->version,
|
||
'moduleAdminLink' => $moduleAdminLink,
|
||
'id_lang' => $id_lang,
|
||
'apifaq' => $this->loadFaq(),
|
||
'module_display' => $this->displayName,
|
||
'module_path' => $this->module_path,
|
||
'logo_path' => $this->logo_path,
|
||
'img_path' => $this->img_path,
|
||
'languages' => $this->context->controller->getLanguages(),
|
||
'defaultFormLanguage' => (int) $this->context->employee->id_lang,
|
||
'currentPage' => $currentPage,
|
||
'ps_version' => (bool)version_compare(_PS_VERSION_, '1.6', '>'),
|
||
'img_link_sitemap' => configuration::get('IMG_LINKS_SITEMAP'),
|
||
'homepage_button' => configuration::get('HOMEPAGE_BUTTON'),
|
||
'sitemap_category' => configuration::get('SITEMAP_CATEGORY'),
|
||
'sitemap_product' => configuration::get('SITEMAP_PRODUCT'),
|
||
'sitemap_cms' => configuration::get('SITEMAP_CMS'),
|
||
'sitemap_other_pages' => configuration::get('SITEMAP_OTHER_PAGES'),
|
||
'language_conf' => $active_language,
|
||
'categories' => PssitemapData::getCategoriesShop($id_shop, $id_lang),
|
||
'product' => PssitemapData::getProductsShop($id_shop, $id_lang),
|
||
'cms_page' => PssitemapData::getCMSPage($id_shop, $id_lang),
|
||
'other_pages' => PssitemapData::getOtherPages($id_shop, $id_lang),
|
||
'html_listCMS' => CMS::listCms(),
|
||
'sitemap_page_html' => configuration::get('CMS_PAGE'),
|
||
'active_html' => configuration::get('SITEMAP_HTML'),
|
||
'page_title_color' => configuration::get('PAGE_TITLE_COLOR'),
|
||
'page_category_color' => configuration::get('PAGE_CATEGORY_COLOR'),
|
||
'page_link_color' => configuration::get('PAGE_LINK_COLOR'),
|
||
'product_priority' => configuration::get('PRODUCT_PRIORITY'),
|
||
'product_frequency' => configuration::get('PRODUCT_FREQUENCY'),
|
||
'product_to_export' => PssitemapData::getProductToExport($id_shop),
|
||
'bget_prod_to_exp' => $getProdToExp,
|
||
'cms_to_export' => PssitemapData::getCmsToExport($id_shop),
|
||
'bget_cms_to_exp' => $getCmsToExp,
|
||
'other_to_export' => PssitemapData::getOtherPageToExport($id_shop),
|
||
'bget_othpage_to_exp' => $getOpToExp,
|
||
'category_to_export' => PssitemapData::getCategoryToExport($id_shop),
|
||
'bget_cat_to_exp' => $getCatToExp,
|
||
'fontText' => $this->font_text,
|
||
'active_FontText' => configuration::get('FONT_TEXT'),
|
||
'active_layout' => Configuration::get('LAYOUT-CHOICE'),
|
||
'category_priority' => configuration::get('CATEGORY_PRIORITY'),
|
||
'category_frequency' => configuration::get('CATEGORY_FREQUENCY'),
|
||
'homepage_priority' => configuration::get('HOMEPAGE_PRIORITY'),
|
||
'homepage_frequency' => configuration::get('HOMEPAGE_FREQUENCY'),
|
||
'cms_priority' => configuration::get('CMS_PRIORITY'),
|
||
'cms_frequency' => configuration::get('CMS_FREQUENCY'),
|
||
'other_pages_priority' => configuration::get('OTHER_PAGE_PRIORITY'),
|
||
'other_pages_frequency' => configuration::get('OTHER_PAGE_FREQUENCY'),
|
||
'sitemap_created' => $this->getIndexSitemap(),
|
||
'cron_url' => $cron_url,
|
||
'adminCMS' => $this->context->link->getAdminLink('AdminCmsContent', true),
|
||
'ps17' => (bool)version_compare(_PS_VERSION_, '1.7', '>='),
|
||
'doc' => $doc
|
||
));
|
||
|
||
$this->output .= $this->context->smarty->fetch($this->local_path.'views/templates/admin/menu.tpl');
|
||
|
||
Media::addJsDef(array(
|
||
'admin_module_ajax_url' => $controller_url,
|
||
'admin_module_controller' => $this->controller_name));
|
||
|
||
return $this->output;
|
||
}
|
||
|
||
public function postProcess()
|
||
{
|
||
$id_shop = (int)Context::getContext()->shop->id;
|
||
$new = new PssitemapData();
|
||
$id_lang = explode(",", configuration::get('LANGUAGE_CONF'));
|
||
$errors = array();
|
||
|
||
// GET GENERAL CONFIGURATION SUBMIT
|
||
if (Tools::isSubmit('submitGeneralConf')) {
|
||
$languageConf = Tools::getValue('lgConf');
|
||
if ($languageConf == false) {
|
||
$errors[] = $this->l('Please select a language for the sitemap');
|
||
} else {
|
||
$data = implode(",", $languageConf); // Gather the elements of the array into a string
|
||
$img_link_sitemap = (int)Tools::getValue('img_link_sitemap'); //include links for images in sitemap or not
|
||
Configuration::updateValue('LANGUAGE_CONF', $data);
|
||
Configuration::updateValue('IMG_LINKS_SITEMAP', $img_link_sitemap);
|
||
$this->output .= $this->displayConfirmation($this->l('Successful update !'));
|
||
}
|
||
}
|
||
|
||
/** HTML CONFIGURATION **/
|
||
if (Tools::isSubmit('submitConfHtml')) {
|
||
Configuration::updateValue('SITEMAP_HTML', Tools::getValue('html_sitemap'));
|
||
$this->output .= $this->displayConfirmation($this->l('Successful update !'));
|
||
}
|
||
|
||
// GET CATEGORY CONFIGURATION SUBMIT
|
||
if (Tools::isSubmit('submitCategoryConf')) {
|
||
Configuration::updateValue('SITEMAP_CATEGORY', Tools::getValue('categoty_sitemap'));
|
||
$this->output .= $this->displayConfirmation($this->l('Successful update !'));
|
||
}
|
||
|
||
// GET PRODUCT CONFIGURATION SUBMIT
|
||
if (Tools::isSubmit('submitproductConf')) {
|
||
Configuration::updateValue('SITEMAP_PRODUCT', Tools::getValue('product_sitemap'));
|
||
$this->output .= $this->displayConfirmation($this->l('Successful update !'));
|
||
}
|
||
|
||
// GET CMS PAGE CONFIGURATION SUBMIT
|
||
if (Tools::isSubmit('submit_cms_conf')) {
|
||
Configuration::updateValue('SITEMAP_CMS', Tools::getValue('cms_sitemap'));
|
||
$this->output .= $this->displayConfirmation($this->l('Successful update !'));
|
||
}
|
||
|
||
// GET OTHER PAGE CONFIGURATION SUBMIT
|
||
if (Tools::isSubmit('submitOtherConf')) {
|
||
Configuration::updateValue('SITEMAP_OTHER_PAGES', Tools::getValue('other_sitemap'));
|
||
$this->output .= $this->displayConfirmation($this->l('Successful update !'));
|
||
}
|
||
|
||
/** GENERATE HTML SITEMAP **/
|
||
if ((Tools::isSubmit('gen_html_sitemap') && Tools::getValue('cms_page_html') == 0)) {
|
||
$errors[] = $this->l('Please select a cms page');
|
||
} elseif (Tools::isSubmit('gen_html_sitemap') && Tools::getValue('cms_page_html') != 0) {
|
||
// SAVE HTML CONF
|
||
Configuration::updateValue('SITEMAP_HTML', Tools::getValue('html_sitemap'));
|
||
Configuration::updateValue('CMS_PAGE', Tools::getValue('cms_page_html'));
|
||
Configuration::updateValue('PAGE_TITLE_COLOR', Tools::getValue('page_title_color'));
|
||
Configuration::updateValue('PAGE_CATEGORY_COLOR', Tools::getValue('page_category_color'));
|
||
Configuration::updateValue('PAGE_LINK_COLOR', Tools::getValue('page_link_color'));
|
||
Configuration::updateValue('FONT_TEXT', Tools::getValue('font_text_name'));
|
||
Configuration::updateValue('LAYOUT-CHOICE', Tools::getValue('LAYOUT-CHOICE'));
|
||
|
||
$this->updateCMS(configuration::get('CMS_PAGE'));
|
||
$this->output .= $this->displayConfirmation($this->l('Successful update !'));
|
||
}
|
||
|
||
/*** GENERATE AND SAVE PRODUCT ***/
|
||
if (Tools::isSubmit('gen_product_sitemap') && PssitemapData::getProductToExport($id_shop) == NULL) {
|
||
$errors[] = $this->l('Please select a product to export');
|
||
} elseif (Tools::isSubmit('gen_product_sitemap') && PssitemapData::getProductToExport($id_shop) !== NULL) {
|
||
// Save product configuration
|
||
Configuration::updateValue('SITEMAP_PRODUCT', Tools::getValue('product_sitemap'));
|
||
Configuration::updateValue('PRODUCT_PRIORITY', Tools::getValue('product_priority'));
|
||
Configuration::updateValue('PRODUCT_FREQUENCY', Tools::getValue('product_frequency'));
|
||
|
||
//then Generate sitemap product
|
||
$frequency = configuration::get('PRODUCT_FREQUENCY');
|
||
$priority = configuration::get('PRODUCT_PRIORITY');
|
||
|
||
foreach ($id_lang as $value) {
|
||
$new->getActiveURLProduct($frequency, $priority, $id_shop, $value);
|
||
}
|
||
$this->output .= $this->displayConfirmation($this->l('Successful update !'));
|
||
}
|
||
|
||
/*** GENERATE AND SAVE CMS ***/
|
||
if (Tools::isSubmit('gen_cms_sitemap') && PssitemapData::getCmsToExport($id_shop) == NULL) {
|
||
$errors[] = $this->l('Please select a CMS page to export');
|
||
} elseif (Tools::isSubmit('gen_cms_sitemap') && PssitemapData::getCmsToExport($id_shop) !== NULL) {
|
||
//Save cms configuration
|
||
Configuration::updateValue('SITEMAP_CMS', Tools::getValue('cms_sitemap'));
|
||
Configuration::updateValue('CMS_PRIORITY', Tools::getValue('cms_priority'));
|
||
Configuration::updateValue('CMS_FREQUENCY', Tools::getValue('cms_frequency'));
|
||
|
||
//then Generate sitemap cms
|
||
$frequency = configuration::get('CMS_FREQUENCY');
|
||
$priority = configuration::get('CMS_PRIORITY');
|
||
|
||
foreach ($id_lang as $value) {
|
||
$new->getActiveURLCMS($frequency, $priority, $id_shop, $value);
|
||
}
|
||
$this->output .= $this->displayConfirmation($this->l('Successful update !'));
|
||
}
|
||
|
||
/*** GENERATE AND SAVE CATEGORY ***/
|
||
if (Tools::isSubmit('gen_category_sitemap') && PssitemapData::getCategoryToExport($id_shop) == NULL) {
|
||
$errors[] = $this->l('Please select a Category page to export');
|
||
} elseif (Tools::isSubmit('gen_category_sitemap') && PssitemapData::getCategoryToExport($id_shop) !== NULL) {
|
||
//Save category configuration
|
||
Configuration::updateValue('SITEMAP_CATEGORY', Tools::getValue('categoty_sitemap'));
|
||
Configuration::updateValue('HOMEPAGE_BUTTON', Tools::getValue('dissociate_homepage'));
|
||
Configuration::updateValue('CATEGORY_PRIORITY', Tools::getValue('category_priority'));
|
||
Configuration::updateValue('CATEGORY_FREQUENCY', Tools::getValue('category_frequency'));
|
||
Configuration::updateValue('HOMEPAGE_PRIORITY', Tools::getValue('homepage_priority'));
|
||
Configuration::updateValue('HOMEPAGE_FREQUENCY', Tools::getValue('homepage_frequency'));
|
||
|
||
//then Generate sitemap category
|
||
$frequency = configuration::get('CATEGORY_FREQUENCY');
|
||
$priority = configuration::get('CATEGORY_PRIORITY');
|
||
foreach ($id_lang as $value) {
|
||
$new->getActiveURLCategory($frequency, $priority, $id_shop, $value);
|
||
}
|
||
$this->output .= $this->displayConfirmation($this->l('Successful update !'));
|
||
}
|
||
|
||
/*** GENERATE AND SAVE OTHERS PAGE ***/
|
||
if (Tools::isSubmit('gen_otherConf_sitemap') && PssitemapData::getOtherPageToExport($id_shop) == NULL) {
|
||
$errors[] = $this->l('Please select other page to export');
|
||
} elseif (Tools::isSubmit('gen_otherConf_sitemap') && PssitemapData::getOtherPageToExport($id_shop) !== NULL) {
|
||
//Save other pages configuration
|
||
Configuration::updateValue('SITEMAP_OTHER_PAGES', Tools::getValue('other_sitemap'));
|
||
Configuration::updateValue('OTHER_PAGE_PRIORITY', Tools::getValue('other_pages_priority'));
|
||
Configuration::updateValue('OTHER_PAGE_FREQUENCY', Tools::getValue('other_pages_frequency'));
|
||
|
||
//then Generate sitemap other pages
|
||
$frequency = configuration::get('OTHER_PAGE_FREQUENCY');
|
||
$priority = configuration::get('OTHER_PAGE_PRIORITY');
|
||
|
||
foreach ($id_lang as $value) {
|
||
$new->getActiveURLOtherPage($frequency, $priority, $id_shop, $value);
|
||
}
|
||
$this->output .= $this->displayConfirmation($this->l('Successful update !'));
|
||
}
|
||
|
||
$this->context->smarty->assign(array(
|
||
'errors' => $errors,
|
||
));
|
||
}
|
||
|
||
/**
|
||
* @param id_element [Product, CMS, Category & other page]
|
||
* @param type to save the type in his table
|
||
* @param export (0 or 1)
|
||
*/
|
||
public function saveExportElement($id_element, $type, $export)
|
||
{
|
||
return PssitemapData::updateExportElement($id_element, $type, $export);
|
||
}
|
||
|
||
/**
|
||
* hook use on 1.7 to load css and js on front
|
||
*/
|
||
public function hookActionFrontControllerSetMedia()
|
||
{
|
||
// load css
|
||
$this->context->controller->registerStylesheet(
|
||
'pssitemap-css-front',
|
||
'modules/'.$this->name.'/views/css/forum.css'
|
||
);
|
||
|
||
$this->context->controller->registerStylesheet(
|
||
'pssitemap-css-front',
|
||
'modules/'.$this->name.'/views/css/hind.css'
|
||
);
|
||
|
||
// load js
|
||
$this->context->controller->registerJavascript(
|
||
'pssitemap-js',
|
||
'modules/'.$this->name.'/views/pssitemap.js'
|
||
);
|
||
|
||
$this->context->controller->registerStylesheet(
|
||
'pssitemap-roboto',
|
||
'modules/'.$this->name.'/views/css/roboto.css.'
|
||
);
|
||
|
||
$this->context->controller->registerStylesheet(
|
||
'pssitemap-mavenpro',
|
||
'modules/'.$this->name.'/views/css/mavenPro.css'
|
||
);
|
||
|
||
$this->context->controller->registerStylesheet(
|
||
'pssitemap-notoserif',
|
||
'modules/'.$this->name.'/views/css/notoSerif.css'
|
||
);
|
||
|
||
$this->context->controller->registerStylesheet(
|
||
'pssitemap-bitter',
|
||
'modules/'.$this->name.'/views/css/bitter.css'
|
||
);
|
||
}
|
||
|
||
public function hookActionProductSave($params)
|
||
{
|
||
$sitemap = new PssitemapData();
|
||
$id_lang = explode(",", configuration::get('LANGUAGE_CONF'));
|
||
$id_shop = (int)Context::getContext()->shop->id;
|
||
|
||
$product_frequency = configuration::get('PRODUCT_FREQUENCY');
|
||
$product_priority = configuration::get('PRODUCT_PRIORITY');
|
||
|
||
if ($params['product']->active) {
|
||
foreach ($id_lang as $value) {
|
||
PssitemapData::updateExportElement($params['id_product'], 'product', 1);
|
||
$sitemap->getActiveURLProduct($product_frequency, $product_priority, $id_shop, $value);
|
||
}
|
||
}
|
||
$this->updateCMS(configuration::get('CMS_PAGE'));
|
||
}
|
||
|
||
public function hookActionProductUpdate($params)
|
||
{
|
||
$sitemap = new PssitemapData();
|
||
$id_lang = explode(",", configuration::get('LANGUAGE_CONF'));
|
||
$id_shop = (int)Context::getContext()->shop->id;
|
||
|
||
$product_frequency = configuration::get('PRODUCT_FREQUENCY');
|
||
$product_priority = configuration::get('PRODUCT_PRIORITY');
|
||
|
||
if($params['product']->active) {
|
||
foreach ($id_lang as $value) {
|
||
PssitemapData::updateExportElement($params['id_product'], 'product', 1);
|
||
$sitemap->getActiveURLProduct($product_frequency, $product_priority, $id_shop, $value);
|
||
}
|
||
} else {
|
||
foreach ($id_lang as $value) {
|
||
PssitemapData::updateExportElement($params['id_product'], 'product', 0);
|
||
$sitemap->getActiveURLProduct($product_frequency, $product_priority, $id_shop, $value);
|
||
}
|
||
}
|
||
$this->updateCMS(configuration::get('CMS_PAGE'));
|
||
}
|
||
|
||
public function hookActionCategoryAdd($params)
|
||
{
|
||
$sitemap = new PssitemapData();
|
||
$id_lang = explode(",", configuration::get('LANGUAGE_CONF'));
|
||
$id_shop = (int)Context::getContext()->shop->id;
|
||
|
||
$category_frequency = configuration::get('CATEGORY_FREQUENCY');
|
||
$category_priority = configuration::get('CATEGORY_PRIORITY');
|
||
|
||
foreach ($id_lang as $value) {
|
||
PssitemapData::updateExportElement($params['category']->id, 'category', 1);
|
||
$sitemap->getActiveURLCategory($category_frequency, $category_priority, $id_shop, $value);
|
||
}
|
||
$this->updateCMS(configuration::get('CMS_PAGE'));
|
||
}
|
||
|
||
public function hookActionObjectCmsAddAfter($params)
|
||
{
|
||
$sitemap = new PssitemapData();
|
||
$id_lang = explode(",", configuration::get('LANGUAGE_CONF'));
|
||
$id_shop = (int)Context::getContext()->shop->id;
|
||
|
||
$cms_frequency = configuration::get('CMS_FREQUENCY');
|
||
$cms_priority = configuration::get('CMS_PRIORITY');
|
||
|
||
foreach ($id_lang as $value) {
|
||
PssitemapData::updateExportElement($params['object']->id, 'cms', 1);
|
||
$sitemap->getActiveURLCMS($cms_frequency, $cms_priority, $id_shop, $value);
|
||
}
|
||
$this->updateCMS(configuration::get('CMS_PAGE'));
|
||
}
|
||
|
||
public function hookDisplayFooter()
|
||
{
|
||
$this->output .= $this->context->smarty->fetch($this->local_path.'views/templates/hook/html.tpl');
|
||
}
|
||
|
||
/** GET SITEMAP FILES **/
|
||
public function getIndexSitemap()
|
||
{
|
||
$id_shop = (int)Context::getContext()->shop->id;
|
||
$indexSitemap = glob(_PS_ROOT_DIR_."/sitemapIndex_Shop_".$id_shop.".xml");
|
||
$indexSitemap = str_replace(_PS_ROOT_DIR_."/", _PS_BASE_URL_.__PS_BASE_URI__, $indexSitemap);
|
||
|
||
if (Tools::usingSecureMode()) {
|
||
$indexSitemap = str_replace('http', 'https', $indexSitemap);
|
||
}
|
||
|
||
//Add Index sitemap in robots.txt file
|
||
$string = Tools::file_get_contents("../robots.txt");
|
||
$string = explode("\n", $string);
|
||
if (in_array("Sitemap: ".implode(",", $indexSitemap), $string)) {
|
||
return $indexSitemap;
|
||
} else {
|
||
file_put_contents("../robots.txt", "Sitemap: ".implode(",", $indexSitemap)."\n", FILE_APPEND);
|
||
return $indexSitemap;
|
||
}
|
||
}
|
||
|
||
/*
|
||
** Get all sitemap generated by id shop
|
||
*/
|
||
public function getAllSitemap($id_shop)
|
||
{
|
||
$files = array();
|
||
|
||
foreach (glob(_PS_ROOT_DIR_."/sitemap_*".$id_shop.".xml") as $file) {
|
||
$files[] = $file;
|
||
}
|
||
$files = str_replace(_PS_ROOT_DIR_."/", _PS_BASE_URL_.__PS_BASE_URI__, $files);
|
||
|
||
if (Tools::usingSecureMode()) {
|
||
$files = str_replace('http', 'https', $files);
|
||
}
|
||
|
||
return $files;
|
||
}
|
||
|
||
/***
|
||
* return url for generate HTML sitemap
|
||
**/
|
||
public function getUrlProduct()
|
||
{
|
||
$link = new Link();
|
||
$id_shop = (int)Context::getContext()->shop->id;
|
||
$lang = $this->context->language->id;
|
||
$products_export = PssitemapData::getProductToExport($id_shop);
|
||
$all_urls = array();
|
||
|
||
foreach ($products_export as $products_id) {
|
||
$product = new Product((int)$products_id['id_element'], false, (int)$lang, $id_shop);
|
||
$url_products = $link->getProductLink($product, null, null, null, $lang, $id_shop, 0, false, false, false, array());
|
||
$product_name = $product->name;
|
||
$all_urls[] = array($product_name => $url_products);
|
||
}
|
||
return $all_urls;
|
||
}
|
||
|
||
/***
|
||
* return url to generate HTML sitemap
|
||
**/
|
||
public function getUrlCategory()
|
||
{
|
||
$link = new Link();
|
||
$id_shop = (int)Context::getContext()->shop->id;
|
||
$lang = $this->context->language->id;
|
||
$category_export = PssitemapData::getCategoryToExport($id_shop);
|
||
$all_urls = array();
|
||
|
||
foreach ($category_export as $id) {
|
||
$category = new Category($id['id_element'], $lang);
|
||
$category_url = $link->getCategoryLink($category, null, $lang, null, $id_shop, false);
|
||
$category_name = $category->name;
|
||
$all_urls[] = array($category_name => $category_url);
|
||
}
|
||
return $all_urls;
|
||
}
|
||
|
||
/***
|
||
* return url to generate HTML sitemap
|
||
**/
|
||
public function getUrlCMS()
|
||
{
|
||
$link = new Link();
|
||
$id_shop = (int)Context::getContext()->shop->id;
|
||
$lang = $this->context->language->id;
|
||
$cms_export = PssitemapData::getCmsToExport($id_shop);
|
||
$all_urls = array();
|
||
|
||
foreach ($cms_export as $cms_id) {
|
||
$cms = new CMS($cms_id['id_element'], $lang);
|
||
$url_cms = $link->getCMSLink($cms, null, null, $lang, $id_shop);
|
||
$cms_name = $cms->meta_title;
|
||
$all_urls[] = array($cms_name => $url_cms);
|
||
}
|
||
return $all_urls;
|
||
}
|
||
|
||
public function getUrlOtherPage()
|
||
{
|
||
$link = new Link();
|
||
$id_shop = (int)Context::getContext()->shop->id;
|
||
$lang = $this->context->language->id;
|
||
$all_urls = array();
|
||
|
||
$other_page_export = PssitemapData::getOtherPageToExport($id_shop);
|
||
|
||
foreach ($other_page_export as $id) {
|
||
$otherPage = Db::getInstance()->ExecuteS('SELECT cat.id_meta, cat.page, cats.title FROM `'._DB_PREFIX_.'meta` as cat INNER JOIN `'._DB_PREFIX_.'meta_lang` as cats ON(cat.id_meta = cats.id_meta) WHERE id_shop = '.(int)$id_shop.' AND id_lang ='.(int)$lang.' AND cat.id_meta= '.(int)$id['id_element']);
|
||
|
||
foreach ($otherPage as $value) {
|
||
$otherPage_url = $link->getPageLink($value["page"], null, $lang, null, false, $id_shop, false);
|
||
$other_page_name = $value["title"];
|
||
}
|
||
$all_urls[] = array($other_page_name => $otherPage_url);
|
||
}
|
||
|
||
return $all_urls;
|
||
}
|
||
|
||
public function updateCMS($id_cms)
|
||
{
|
||
$product_name = $this->getUrlProduct();
|
||
$category_url = $this->getUrlCategory();
|
||
$cms_url = $this->getUrlCMS();
|
||
|
||
$this->context->smarty->assign(array(
|
||
'product_name' => $product_name,
|
||
'category_url' => $category_url,
|
||
'cms_url' => $cms_url,
|
||
'otherPage' => $this->getUrlOtherPage(),
|
||
'page_title_color' => configuration::get('PAGE_TITLE_COLOR'),
|
||
'page_category_color' => configuration::get('PAGE_CATEGORY_COLOR'),
|
||
'page_link_color' => configuration::get('PAGE_LINK_COLOR'),
|
||
'font_text' => configuration::get('FONT_TEXT'),
|
||
'layout' => Configuration::get('LAYOUT-CHOICE'),
|
||
));
|
||
|
||
$html = $this->context->smarty->fetch(
|
||
$this->local_path.'views/templates/hook/html.tpl'
|
||
);
|
||
|
||
$cms = new CMS($id_cms);
|
||
$cms->content = $html;
|
||
$save = $cms->save();
|
||
|
||
return $save;
|
||
}
|
||
}
|