first commit

This commit is contained in:
2024-10-28 22:14:22 +01:00
commit b65352c452
40581 changed files with 5712079 additions and 0 deletions

View File

@@ -0,0 +1,63 @@
<?php
/**
* 2012-2018 Areama
*
* 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@areama.net so we can send you a copy immediately.
*
* @author Areama <contact@areama.net>
* @copyright 2018 Areama
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of Areama
*/
include_once dirname(__FILE__).'/AdminArSeoControllerAbstract.php';
class AdminArSeoController extends AdminArSeoControllerAbstract
{
public function initContent()
{
$url = Context::getContext()->link->getAdminLink('AdminModules') . '&configure=' . $this->module->name;
Tools::redirectAdmin($url);
}
public function ajaxProcessReinstallOverrides()
{
$return = true;
$this->module->getLogger()->log('Re-install overrides');
$res = $this->module->uninstallOverrides();
$this->module->getLogger()->log('Uninstall overrides: ' . (int)$res);
$return = $return && $res;
$res = $this->module->getInstaller()->prepareOverrides();
$this->module->getLogger()->log('Preparing overrides: ' . (int)$res);
$return = $return && $res;
$res = $this->module->installOverrides();
$this->module->getLogger()->log('Install overrides: ' . (int)$res);
$return = $return && $res;
$this->module->getLogger()->log('Re-install overrides complete' . PHP_EOL);
die(Tools::jsonEncode(array(
'success' => (int)$return
)));
}
public function ajaxProcessGetOverridesVersion()
{
die(Tools::jsonEncode(array(
'success' => 1,
'versions' => $this->module->getOverridesVersion(),
'moduleVersion' => $this->module->version
)));
}
}

View File

@@ -0,0 +1,151 @@
<?php
/**
* 2012-2018 Areama
*
* 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@areama.net so we can send you a copy immediately.
*
* @author Areama <contact@areama.net>
* @copyright 2018 Areama
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of Areama
*/
/**
* @property ArSeoPro $module
*/
abstract class AdminArSeoControllerAbstract extends ModuleAdminController
{
public static $shopCache = null;
public function __construct()
{
header("Cache-Control: no-store, no-cache, must-revalidate, max-age=0");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
$this->bootstrap = true;
$this->display = 'view';
parent::__construct();
$this->meta_title = $this->l('SeoPro');
}
public function renderTable()
{
return null;
}
public function getListId()
{
return null;
}
public function yesNoList()
{
return array(
'0' => $this->l('No'),
'1' => $this->l('Yes')
);
}
public function ajaxProcessReload()
{
$params = $this->getParams($this->getListId());
die(Tools::jsonEncode(array(
'content' => $this->renderTable($params)
)));
}
public function getParams($listId)
{
$data = Tools::getValue('data');
if (empty($data)) {
return array();
}
$params = array(
'resetFilter' => 0
);
foreach ($data as $param) {
$name = str_replace($listId, '', $param['name']);
if (strpos($name, 'Filter') === 0) {
$name = str_replace('Filter_', '', $name);
$params['filter'][$name] = $param['value'];
} elseif ($name == 'submit') {
if (strpos($param['value'], 'submitReset') !== false) {
$params['resetFilter'] = 1;
return array();
}
} else {
$params[$name] = $param['value'];
}
}
return $params;
}
protected function filterIdList($ids)
{
$res = array();
foreach ($ids as $id) {
$res[] = (int)$id;
}
return $res;
}
public function getShopList()
{
if (empty(self::$shopCache)) {
$shops = Shop::getShops();
foreach ($shops as $shop) {
self::$shopCache[$shop['id_shop']] = $shop['name'];
}
}
$shops = self::$shopCache;
$shops[0] = $this->l('[all shops]');
ksort($shops);
return $shops;
}
public function shopTableValue($cellValue, $row)
{
if (empty(self::$shopCache)) {
$shops = Shop::getShops();
foreach ($shops as $shop) {
self::$shopCache[$shop['id_shop']] = $shop['name'];
}
}
if ($row['id_shop'] == 0) {
return $this->l('[all shops]');
}
return isset(self::$shopCache[$row['id_shop']])? self::$shopCache[$row['id_shop']] : $this->l('[deleted]');
}
public function ajaxProcessHelp()
{
$lang = Language::getIsoById(Context::getContext()->language->id);
$defLang = 'en';
$path = $this->module->getPath(true) . 'docs/' . $lang . '/';
$file = 'docs/' . $lang . '/index.tpl';
if (!file_exists($path)) {
$lang = $defLang;
$path = $this->module->getPath(true) . 'docs/' . $defLang . '/';
$file = 'docs/' . $defLang . '/index.tpl';
}
die(Tools::jsonEncode(array(
'success' => 1,
'lang' => $lang,
'content' => $this->module->render($file, array(
'path' => $this->module->getPath(),
'lang' => $lang,
'moduleUrl' => $this->module->getModuleBaseUrl(),
'serverUrl' => Tools::getShopDomainSsl(true),
'schemeUrl' => Context::getContext()->link->getAdminLink('AdminMeta'),
))
)));
}
}

View File

@@ -0,0 +1,739 @@
<?php
/**
* 2012-2018 Areama
*
* 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@areama.net so we can send you a copy immediately.
*
* @author Areama <contact@areama.net>
* @copyright 2018 Areama
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of Areama
*/
include_once dirname(__FILE__).'/AdminArSeoControllerAbstract.php';
include_once dirname(__FILE__).'/../../classes/ArSeoProUrls.php';
include_once dirname(__FILE__).'/../../classes/meta/models/ArSeoProMetaTable.php';
include_once dirname(__FILE__).'/../../classes/ArSeoProListHelper.php';
class AdminArSeoMetaController extends AdminArSeoControllerAbstract
{
public $max_image_size;
protected $mimeTypes = array(
'jpg' => array(
'image/jpeg'
),
'jpeg' => array(
'image/jpeg'
),
'gif' => array(
'image/gif'
),
'png' => array(
'image/png'
)
);
public function __construct()
{
parent::__construct();
$this->max_image_size = (int)Configuration::get('PS_PRODUCT_PICTURE_MAX_SIZE');
}
protected function isMimeTypeValid($mime, $ext)
{
if (isset($this->mimeTypes[$ext])) {
if (in_array($mime, $this->mimeTypes[$ext])) {
return true;
}
}
return false;
}
public function getListId()
{
return 'meta-list';
}
protected function uploadImageFile($id, $storeKey)
{
self::$currentIndex = 'index.php?tab=AdminArSeoMeta';
$fileTypes = array('jpeg', 'gif', 'png', 'jpg');
$uploader = $id;
$isImage = true;
if ($isImage) {
$image_uploader = new HelperImageUploader($uploader);
} else {
$image_uploader = new HelperUploader($uploader);
}
$image_uploader->setAcceptTypes($fileTypes);
if ($isImage) {
$image_uploader->setMaxSize($this->max_image_size);
} else {
$image_uploader->setMaxSize($this->module->fileUploadMaxSize());
}
$files = $image_uploader->process();
$errors = array();
foreach ($files as &$file) {
if (isset($file['error']) && $file['error']) {
$errors[] = $file['error'];
continue;
}
$ext = pathinfo($file['name'], PATHINFO_EXTENSION);
$finfo = finfo_open(FILEINFO_MIME_TYPE);
$mime = finfo_file($finfo, $file['save_path']);
finfo_close($finfo);
if ($this->isMimeTypeValid($mime, $ext)) {
$filename = uniqid() . '.' . $ext;
$file['filename'] = $filename;
$file['real_path'] = $this->module->getUploadPath() . $filename;
copy($file['save_path'], $this->module->getUploadPath() . $filename);
$file['url'] = $this->module->getUploadsUrl() . $filename;
} else {
$file['error'] = $this->module->l('File type does not match its extension');
$errors[] = $file['error'];
}
}
if ($errors) {
return array(
$uploader => $files
);
} else {
if ($storeKey) {
Configuration::updateValue($storeKey, $file['url']);
}
return array(
$image_uploader->getName() => $files
);
}
return false;
}
public function ajaxProcessUploadFbCustomImage()
{
die(Tools::jsonEncode($this->uploadImageFile('arseopro_fb_upload_image', null)));
}
public function ajaxProcessUploadTwCustomImage()
{
die(Tools::jsonEncode($this->uploadImageFile('arseopro_tw_upload_image', null)));
}
public function fetchFilters()
{
return array(
array(
array(
'name',
'rule_type',
'meta_title',
'meta_description',
'meta_keywords',
'fb_admins',
'fb_app',
'fb_title',
'fb_description',
'fb_type',
'fb_custom_image',
'tw_type',
'tw_account',
'tw_title',
'tw_description',
'tw_ch1',
'tw_ch2',
'tw_custom_image',
), 'pSQL'
),
array(
array(
'id_lang',
'id_category',
'fb_image',
'tw_image',
), 'int'
)
);
}
public function getFilterType($attribute)
{
foreach ($this->fetchFilters() as $filter) {
if (in_array($attribute, $filter[0])) {
return $filter[1];
}
}
return false;
}
public function fetchData($data)
{
$result = array();
foreach ($data as $param) {
if (isset($param['name']) && $param['name']) {
$attribute = trim($param['name']);
if ($filter = $this->getFilterType($attribute)) {
if ($filter == 'pSQL') {
$result[$attribute] = trim(pSQL($param['value']));
} elseif ($filter == 'int') {
$result[$attribute] = (int)$param['value'];
}
}
}
}
return $result;
}
public function assignData($model, $data)
{
foreach ($data as $k => $v) {
if (property_exists($model, $k)) {
$model->$k = $v;
}
}
}
public function ajaxProcessSave()
{
$data = Tools::getValue('data');
$id = Tools::getValue('id');
$errors = array();
if (!$id) {
$model = new ArSeoProMetaTable();
$model->status = 1;
} else {
$model = new ArSeoProMetaTable($id);
}
$id_category = 0;
$categories = array();
$metaPages = array();
foreach ($data as $param) {
if ((isset($param['name'])) && $param['name'] == 'categoryBox[]') {
if ((int)$param['value'] > 0) {
$categories[] = (int)$param['value'];
}
}
if ((isset($param['name'])) && $param['name'] == 'meta[]') {
if ((int)$param['value'] > 0) {
$metaPages[] = (int)$param['value'];
}
}
}
$data = $this->fetchData($data);
$this->assignData($model, $data);
if ($data['id_category'] == 1 && empty($categories) && $model->rule_type != 'metapage') {
$errors['id_category'] = $this->l('Please select categories');
}
if ($model->rule_type == 'metapage' && empty($metaPages)) {
$errors['id_meta'] = $this->l('Please select meta pages');
}
$model->name = $data['name']? $data['name'] : ArSeoProMetaTable::generateRuleName();
$model->status = 1;
$model->id_shop = (int)Context::getContext()->shop->id;
$modelErrors = $model->validateFields(false, true);
if ($modelErrors !== true) {
$errors = array_merge($errors, $modelErrors);
}
if ($errors) {
die(Tools::jsonEncode(array(
'success' => 0,
'errors' => $errors
)));
}
$model->created_at = date('Y-m-d H:i:s');
if ($model->save()) {
$model->clearRelations();
if (in_array($model->rule_type, array('category', 'product', 'brand'))) {
if ($categories && ($data['id_category'] == 1)) {
foreach ($categories as $id_category) {
$model->addRelation($id_category);
}
} else {
$model->addRelation(0);
}
} else {
foreach ($metaPages as $id_meta) {
$model->addRelation($id_meta);
}
}
}
die(Tools::jsonEncode(array(
'success' => 1,
'errors' => $errors,
'model' => $model,
'categories' => $categories
)));
}
public function ajaxProcessRemoveBulk()
{
$ids = $this->filterIdList(Tools::getValue('ids'));
$sql = 'DELETE FROM `' . ArSeoProMetaTable::getTableName() . '` WHERE id_rule IN (' . implode(', ', $ids) . ')';
$sql2 = 'DELETE FROM `' . ArSeoProMetaTable::getTableName(true) . '` WHERE id_rule IN (' . implode(', ', $ids) . ')';
die(Tools::jsonEncode(array(
'success' => Db::getInstance()->execute($sql2) && Db::getInstance()->execute($sql),
)));
}
public function ajaxProcessActivate()
{
$ids = $this->filterIdList(Tools::getValue('ids'));
$sql = 'UPDATE `' . ArSeoProMetaTable::getTableName() . '` SET `status` = 1 WHERE id_rule IN (' . implode(', ', $ids) . ')';
die(Tools::jsonEncode(array(
'success' => Db::getInstance()->execute($sql)
)));
}
public function ajaxProcessDeactivate()
{
$ids = $this->filterIdList(Tools::getValue('ids'));
$sql = 'UPDATE `' . ArSeoProMetaTable::getTableName() . '` SET `status` = 0 WHERE id_rule IN (' . implode(', ', $ids) . ')';
die(Tools::jsonEncode(array(
'success' => Db::getInstance()->execute($sql),
)));
}
public function displayEditLink($token, $id, $name)
{
return $this->module->render('_partials/_button.tpl', array(
'href' => '#',
'onclick' => 'arSEO.meta.edit(' . $id . '); return false;',
'class' => '',
'target' => '',
'title' => $this->l('Edit'),
'icon' => 'icon-pencil'
));
}
public function displayDeleteLink($token, $id, $name)
{
return $this->module->render('_partials/_button.tpl', array(
'href' => '#',
'onclick' => 'arSEO.meta.remove(' . $id . '); return false;',
'class' => '',
'target' => '',
'title' => $this->l('Delete'),
'icon' => 'icon-trash'
));
}
public function displayApplyLink($token, $id, $name)
{
return $this->module->render('_partials/_button.tpl', array(
'href' => '#',
'onclick' => 'arSEO.meta.applyRule(' . $id . ', 0, 0, 0); return false;',
'class' => 'edit btn btn-default',
'target' => '',
'title' => $this->l('Apply'),
'icon' => 'icon-check'
));
}
public function langTableValue($cellValue, $row)
{
if (!$cellValue) {
return $this->l('All languages');
}
if ($lang = Language::getLanguage($cellValue)) {
return $lang['name'];
}
return null;
}
public function getLanguages()
{
$return = array(
0 => $this->l('All languages')
);
$langs = Language::getLanguages();
foreach ($langs as $lang) {
$return[$lang['id_lang']] = $lang['name'];
}
return $return;
}
public function renderTable($params = array())
{
$pageSize = isset($params['selected_pagination'])? $params['selected_pagination'] : 20;
$helper = new ArSeoProListHelper();
$helper->title = $this->l('URL Rewrite Rules for products');
$helper->actions = array(
'apply', 'edit', 'delete'
);
$helper->list_id = $this->getListId();
$helper->identifier = 'id_rule';
$helper->currentIndex = AdminController::$currentIndex.'&configure='.$this->module->name;
$helper->setPagination(array(20, 50, 100));
$totalCount = ArSeoProMetaTable::getCount($params);
if (isset($params['page'])) {
$totalPages = ceil($totalCount / $pageSize);
if ($params['page'] > $totalPages) {
$params['page'] = $totalPages;
}
}
$helper->listTotal = $totalCount;
$helper->currentPage = isset($params['page'])? $params['page'] : 1;
$helper->module = $this->module;
$helper->no_link = true;
$helper->setDefaultPagination($pageSize);
$helper->filters = isset($params['filter'])? $params['filter'] : array();
$helper->token = Tools::getAdminTokenLite('AdminArSeoMeta');
$helper->bulk_actions = array(
'delete' => array(
'text' => $this->l('Delete selected'),
'icon' => 'icon-trash',
'confirm' => $this->l('Delete selected items?'),
'js_action' => 'arSEO.meta.bulk.remove(); return false'
),
'activate' => array(
'text' => $this->l('Activate selected'),
'icon' => 'icon-check',
'confirm' => $this->l('Activate selected items?'),
'js_action' => 'arSEO.meta.bulk.activate(); return false'
),
'deactivate' => array(
'text' => $this->l('Deactivate selected'),
'icon' => 'icon-remove',
'confirm' => $this->l('Deactivate selected items?'),
'js_action' => 'arSEO.meta.bulk.deactivate(); return false'
)
);
$list = ArSeoProMetaTable::getAll($params);
$columns = array(
'id_rule' => array(
'title' => $this->l('#'),
'filter_key' => 'id',
'orderby' => false,
),
'rule_type' => array(
'title' => $this->l('Rule type'),
'filter_key' => 'rule_type',
'orderby' => false,
'type' => 'select',
'list' => array(
'product' => $this->l('Product'),
'category' => $this->l('Category'),
'metapage' => $this->l('Meta page')
)
),
'id_lang' => array(
'title' => $this->l('Language'),
'filter_key' => 'id_lang',
'orderby' => false,
'callback' => 'langTableValue',
'type' => 'select',
'list' => $this->getLanguages()
),
'name' => array(
'title' => $this->l('Name'),
'filter_key' => 'name',
'orderby' => false,
),
);
if (Shop::isFeatureActive()) {
$columns['id_shop'] = array(
'title' => $this->l('Shop'),
'filter_key' => 'id_shop',
'callback' => 'shopTableValue',
'type' => 'select',
'orderby' => false,
'list' => $this->getShopList(),
);
}
$columns['status'] = array(
'title' => $this->l('Status'),
'filter_key' => 'status',
'type' => 'bool',
'active' => 'enabled',
'ajax' => true,
'orderby' => false,
);
$columns['created_at'] = array(
'search' => false,
'title' => $this->l('Create date'),
'orderby' => false,
);
$columns['last_applied_at'] = array(
'search' => false,
'title' => $this->l('Last apply time'),
'orderby' => false,
);
return $helper->generateList($list, $columns);
}
public function ajaxProcessDelete()
{
$id = Tools::getValue('id');
$model = new ArSeoProMetaTable($id);
$model->clearRelations();
die(Tools::jsonEncode(array(
'success' => $model->delete()
)));
}
public function ajaxProcessClear()
{
ArSeoProMetaTable::truncate();
die(Tools::jsonEncode(array(
'success' => 1
)));
}
public function ajaxProcessEnabledconfiguration()
{
$id = Tools::getValue('id_rule');
$model = new ArSeoProMetaTable($id);
$model->status = $model->status? 0 : 1;
die(Tools::jsonEncode(array(
'success' => $model->save(false),
'text' => $this->l('Status updated')
)));
}
public function ajaxProcessEdit()
{
$id = Tools::getValue('id');
$model = new ArSeoProMetaTable($id);
$categories = $model->getRelations(true);
$model->id_category = $categories? 1 : 0;
$model->categories = $categories;
if ($model->fb_custom_image) {
$model->fb_custom_image_url = $this->module->getModuleBaseUrl() . 'uploads/' . $model->fb_custom_image;
}
if ($model->tw_custom_image) {
$model->tw_custom_image_url = $this->module->getModuleBaseUrl() . 'uploads/' . $model->tw_custom_image;
}
die(Tools::jsonEncode($model));
}
protected function generateKeywordLists($fields, $keywords)
{
$return = array();
foreach ($fields as $field) {
$return[] = $this->module->render('_partials/url/_keywords.tpl', array(
'target' => $field,
'keywords' => $keywords
));
}
return $return;
}
public function ajaxProcessGetKeywords()
{
$type = Tools::getValue('type');
switch ($type) {
case 'product':
$keywords = ArSeoPro::getProductKeywords();
break;
case 'metapage':
$keywords = ArSeoPro::getMetaKeywords();
break;
case 'brand':
$keywords = ArSeoPro::getBrandKeywords();
break;
default:
$keywords = ArSeoPro::getCategoryKeywords();
}
die(Tools::jsonEncode(array(
'meta' => $this->generateKeywordLists(array(
'arseo-meta-rule-form_meta_title',
'arseo-meta-rule-form_meta_description',
'arseo-meta-rule-form_meta_keywords',
), $keywords),
'fb' => $this->generateKeywordLists(array(
'arseo-meta-rule-form_fb_title',
'arseo-meta-rule-form_fb_description'
), $keywords),
'tw' => $this->generateKeywordLists(array(
'arseo-meta-rule-form_tw_title',
'arseo-meta-rule-form_tw_description'
), $keywords)
)));
}
public function ajaxProcessApplyRule()
{
$id = Tools::getValue('id');
$all = Tools::getValue('all');
$offset = (int)Tools::getValue('offset');
$total = (int)Tools::getValue('total');
$count = (int)Tools::getValue('count');
$pageSize = 50;
if ($all && $id == 0) {
$query = new DbQuery();
$query->from(ArSeoProMetaTable::TABLE_NAME);
$query->where('status = 1');
$query->orderBy('id_rule ASC');
if ($row = Db::getInstance()->getRow($query)) {
$id = $row['id_rule'];
} else {
die(Tools::jsonEncode(array(
'success' => 0,
'error' => $this->l('No rules to apply')
)));
}
}
$rule = new ArSeoProMetaTable($id);
if ($rule->rule_type == 'product') {
if (!$total) {
$total = $rule->getRelatedProductsCount();
}
$models = $rule->getRelatedProductIds($pageSize, $offset);
$meta = array();
foreach ($models as $id_product) {
$meta[$id_product] = $this->module->generateProductMeta($rule, $id_product);
}
} elseif ($rule->rule_type == 'category') {
if (!$total) {
$total = $rule->getRelatedCategoriesCount();
}
$models = $rule->getRelatedCategories($pageSize, $offset);
$meta = array();
foreach ($models as $id_category) {
$meta[$id_category] = $this->module->generateCategoryMeta($rule, $id_category);
}
} elseif ($rule->rule_type == 'metapage') {
if (!$total) {
$total = $rule->getRelatedMetaPagesCount();
}
$models = $rule->getRelatedMetaPages($pageSize, $offset);
$meta = array();
foreach ($models as $id_meta) {
$meta[$id_meta] = $this->module->generateMetaPageMeta($rule, $id_meta);
}
} elseif ($rule->rule_type == 'brand') {
if (!$total) {
$total = $rule->getRelatedBrandPagesCount();
}
$models = $rule->getRelatedBrandPages($pageSize, $offset);
$meta = array();
foreach ($models as $id_meta) {
$meta[$id_meta] = $this->module->generateBrandMeta($rule, $id_meta);
}
}
$processed = $count + count($models);
if ($processed == $total) {
$rule->last_applied_at = date('Y-m-d H:i:s');
$rule->save(false);
}
$continue = $processed < $total? 1 : 0;
$nextRule = 0;
if ($all) {
$query = new DbQuery();
$query->from(ArSeoProMetaTable::TABLE_NAME);
$query->where('id_rule > ' . (int)$id . ' AND status = 1');
$query->orderBy('id_rule ASC');
if ($row = Db::getInstance()->getRow($query)) {
$nextRule = $row['id_rule'];
}
}
die(Tools::jsonEncode(array(
'success' => 1,
'id' => $id,
'rule' => $rule,
'total' => $total,
'count' => count($models),
'processed' => $processed,
'offset' => $offset + count($models),
'continue' => $continue,
'percent' => round($processed / $total * 100),
'meta' => $meta,
'models' => $models,
'nextRule' => $nextRule
)));
}
public function ajaxProcessCheckOgTags()
{
$id_lang = Context::getContext()->language->id;
$products = Product::getProducts($id_lang, 0, 1, 'id_product', 'asc');
$link = Context::getContext()->link->getProductLink($products[0], null, null, null, $id_lang);
$tpl = _PS_THEME_DIR_ . 'templates/catalog/product.tpl';
$fileExists = file_exists($tpl);
$fileReadable = is_readable($tpl);
$fileWritable = is_writable($tpl);
if (!$fileExists || !$fileReadable) {
die(Tools::jsonEncode(array(
'link' => $link,
'tpl' => $tpl,
'fileExists' => $fileExists,
'fileReadable' => $fileReadable,
'fileWritable' => $fileWritable,
'content' => '',
)));
}
$tplContent = Tools::file_get_contents($tpl);
$contentArray = explode("\n", $tplContent);
$lines = array();
$ogTagsExists = false;
$ogTypeProduct = false;
if (preg_match('/og:type/is', $tplContent)) {
$ogTagsExists = true;
if (preg_match('/property="og:type"\s+content="product"/is', $tplContent)) {
$ogTypeProduct = true;
}
}
foreach ($contentArray as $k => $string) {
if (preg_match('/property="og:.*?"\s+content/is', $string)) {
$string = trim($string);
if (!preg_match('/^{\*.*?\*}$/is', $string)) {
$lines[$k + 1] = trim($string);
}
}
}
if (empty($lines)) {
$ogTagsExists = false;
$ogTypeProduct = false;
}
$content = '';
$relativePath = str_replace(_PS_ROOT_DIR_, '', $tpl);
if ($ogTagsExists) {
$content = $this->module->render('_partials/meta/_og_notice.tpl', array(
'ogTypeProduct' => $ogTypeProduct,
'fileExists' => $fileExists,
'fileReadable' => $fileReadable,
'fileWritable' => $fileWritable,
'relativePath' => $relativePath,
'lines' => $lines,
));
}
die(Tools::jsonEncode(array(
'link' => $link,
'tpl' => $tpl,
'contentArray' => $contentArray,
'fileExists' => $fileExists,
'fileReadable' => $fileReadable,
'fileWritable' => $fileWritable,
'tplContent' => $tplContent,
'lines' => $lines,
'content' => $content,
'ogTagsExists' => (int)$ogTagsExists,
'ogTypeProduct' => (int)$ogTypeProduct,
'relativePath' => $relativePath
)));
}
}

View File

@@ -0,0 +1,521 @@
<?php
/**
* 2012-2018 Areama
*
* 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@areama.net so we can send you a copy immediately.
*
* @author Areama <contact@areama.net>
* @copyright 2018 Areama
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of Areama
*/
include_once dirname(__FILE__).'/AdminArSeoControllerAbstract.php';
include_once dirname(__FILE__).'/../../classes/redirects/models/ArSeoProRedirectTable.php';
include_once dirname(__FILE__).'/../../classes/ArSeoProListHelper.php';
class AdminArSeoRedirectsController extends AdminArSeoControllerAbstract
{
public function getListId()
{
return 'redirect-list';
}
public function processImportcsv()
{
$file = $_FILES['file'];
$dest = $this->module->getPath(true) . 'csv/import-' . date('Y-m-d_h-i-s') . '.csv';
if (move_uploaded_file($file['tmp_name'], $dest)) {
$data = file($dest);
foreach ($data as $line) {
$row = explode(';', $line);
$model = new ArSeoProRedirectTable();
$model->from = pSQL($row[0]);
$model->to = pSQL($row[1]);
$model->type = (int)$row[2];
$model->id_shop = (int)$row[3];
$model->status = isset($row[4])? (int)$row[4] : 1;
$model->created_at = date('Y-m-d H:i:s');
$model->save(false);
}
}
Tools::redirectAdmin($this->context->link->getAdminLink('AdminModules') . '&configure=' . $this->module->name . '&activeTab=redirects');
}
public function ajaxProcessRemoveBulk()
{
$ids = $this->filterIdList(Tools::getValue('ids'));
$sql = 'DELETE FROM `' . _DB_PREFIX_ . ArSeoProRedirectTable::TABLE_NAME . '` WHERE id_redirect IN (' . implode(', ', $ids) . ')';
die(Tools::jsonEncode(array(
'success' => Db::getInstance()->execute($sql),
)));
}
public function ajaxProcessActivate()
{
$ids = $this->filterIdList(Tools::getValue('ids'));
$sql = 'UPDATE `' . _DB_PREFIX_ . ArSeoProRedirectTable::TABLE_NAME . '` SET `status` = 1 WHERE id_redirect IN (' . implode(', ', $ids) . ')';
die(Tools::jsonEncode(array(
'success' => Db::getInstance()->execute($sql)
)));
}
public function ajaxProcessDeactivate()
{
$ids = $this->filterIdList(Tools::getValue('ids'));
$sql = 'UPDATE `' . _DB_PREFIX_ . ArSeoProRedirectTable::TABLE_NAME . '` SET `status` = 0 WHERE id_redirect IN (' . implode(', ', $ids) . ')';
die(Tools::jsonEncode(array(
'success' => Db::getInstance()->execute($sql),
)));
}
public function displayEditLink($token, $id, $name)
{
return $this->module->render('_partials/_button.tpl', array(
'href' => '#',
'onclick' => 'arSEO.redirect.edit(' . $id . '); return false;',
'class' => 'edit btn btn-default',
'target' => '',
'title' => $this->l('Edit'),
'icon' => 'icon-pencil'
));
}
public function displayDeleteLink($token, $id, $name)
{
return $this->module->render('_partials/_button.tpl', array(
'href' => '#',
'onclick' => 'arSEO.redirect.remove(' . $id . '); return false;',
'class' => '',
'target' => '',
'title' => $this->l('Delete'),
'icon' => 'icon-trash'
));
}
public function displayTestLink($token, $id, $name)
{
$redirect = new ArSeoProRedirectTable($id);
return $this->module->render('_partials/_button.tpl', array(
'href' => $redirect->from,
'onclick' => '',
'class' => '',
'target' => '_blank',
'title' => $this->l('Test'),
'icon' => 'icon-link'
));
}
public static function redirectTypeLabels()
{
return array(
301 => '301',
302 => '302',
303 => '303'
);
}
public static function getRedirectTypeLabel($type)
{
$types = self::redirectTypeLabels();
return $types[$type];
}
public function redirectTypeTableValue($cellValue, $row)
{
return self::getRedirectTypeLabel($row['type']);
}
public function renderTable($params = array())
{
$pageSize = isset($params['selected_pagination'])? $params['selected_pagination'] : 100;
$helper = new ArSeoProListHelper();
$helper->title = $this->l('List of redirects');
$helper->actions = array(
'edit', 'test', 'delete'
);
$helper->list_id = $this->getListId();
$helper->identifier = 'id_redirect';
$helper->currentIndex = AdminController::$currentIndex.'&configure='.$this->module->name;
$helper->setPagination(array(20, 50, 100));
$totalCount = ArSeoProRedirectTable::getCount($params);
if (isset($params['page'])) {
$totalPages = ceil($totalCount / $pageSize);
if ($params['page'] > $totalPages) {
$params['page'] = $totalPages;
}
}
$helper->listTotal = $totalCount;
$helper->currentPage = isset($params['page'])? $params['page'] : 1;
$helper->module = $this->module;
$helper->no_link = true;
$helper->setDefaultPagination($pageSize);
$helper->filters = isset($params['filter'])? $params['filter'] : array();
$helper->token = Tools::getAdminTokenLite('AdminArSeoRedirects');
$helper->bulk_actions = array(
'delete' => array(
'text' => $this->l('Delete selected'),
'icon' => 'icon-trash',
'confirm' => $this->l('Delete selected items?'),
'js_action' => 'arSEO.redirect.bulk.remove()'
),
'activate' => array(
'text' => $this->l('Activate selected'),
'icon' => 'icon-check',
'confirm' => $this->l('Activate selected items?'),
'js_action' => 'arSEO.redirect.bulk.activate()'
),
'deactivate' => array(
'text' => $this->l('Deactivate selected'),
'icon' => 'icon-remove',
'confirm' => $this->l('Deactivate selected items?'),
'js_action' => 'arSEO.redirect.bulk.deactivate()'
)
);
$list = ArSeoProRedirectTable::getAll($params);
$columns = array(
'id_redirect' => array(
'title' => $this->l('#'),
'filter_key' => 'id',
'orderby' => false,
),
'from' => array(
'title' => $this->l('Redirect from URL'),
'filter_key' => 'from',
'orderby' => false,
),
'to' => array(
'title' => $this->l('Redirect to URL'),
'filter_key' => 'to',
'orderby' => false,
),
'type' => array(
'title' => $this->l('Redirect type'),
'filter_key' => 'type',
'callback' => 'redirectTypeTableValue',
'type' => 'select',
'orderby' => false,
'list' => array(
'301' => '301',
'302' => '302',
'303' => '303',
)
)
);
if (Shop::isFeatureActive()) {
$columns['id_shop'] = array(
'title' => $this->l('Shop'),
'filter_key' => 'id_shop',
'callback' => 'shopTableValue',
'type' => 'select',
'orderby' => false,
'list' => $this->getShopList(),
);
}
$columns['status'] = array(
'title' => $this->l('Status'),
'filter_key' => 'status',
'type' => 'bool',
'active' => 'enabled',
'ajax' => true,
'orderby' => false,
);
$columns['created_at'] = array(
'search' => false,
'title' => $this->l('Create date'),
'orderby' => false,
);
$columns['last_used_at'] = array(
'search' => false,
'title' => $this->l('Last use date'),
'orderby' => false,
);
$columns['use_times'] = array(
'search' => false,
'title' => $this->l('Use times'),
'orderby' => false,
);
return $helper->generateList($list, $columns);
}
public function ajaxProcessSave()
{
$data = Tools::getValue('data');
$id = Tools::getValue('id');
$errors = array();
if (!$id) {
$model = new ArSeoProRedirectTable();
$model->status = 1;
} else {
$model = new ArSeoProRedirectTable($id);
}
$from = null;
$to = null;
$type = null;
$id_shop = 0;
foreach ($data as $param) {
if ($param['name'] == 'from') {
$from = trim($param['value']);
}
if ($param['name'] == 'to') {
$to = trim($param['value']);
}
if ($param['name'] == 'type') {
$type = $param['value'];
}
if ($param['name'] == 'id_shop') {
$id_shop = $param['value'];
}
}
$model->from = pSQL($from);
$model->to = pSQL($to);
$model->type = (int)$type;
$model->id_shop = (int)$id_shop;
$modelErrors = $model->validateFields(false, true);
if ($modelErrors !== true) {
$errors = array_merge($errors, $modelErrors);
}
if ($errors) {
die(Tools::jsonEncode(array(
'success' => 0,
'errors' => $errors
)));
}
$model->created_at = date('Y-m-d H:i:s');
$model->save();
die(Tools::jsonEncode(array(
'success' => 1,
'errors' => $errors,
'model' => $model
)));
}
public function ajaxProcessExport()
{
$pageSize = 100;
$page = (int)Tools::getValue('page');
$count = (int)Tools::getValue('count');
$sql = 'SELECT COUNT(1) as c FROM `' . _DB_PREFIX_ . 'arseopro_redirect`';
$res = Db::getInstance()->getRow($sql);
$totalCount = (int)$res['c'];
if ($totalCount == 0) {
die(Tools::jsonEncode(array(
'percent' => 0,
'count' => 0,
'continue' => 0,
'page' => $page,
'success' => 0,
'error' => $this->l('Your redirect list is empty. Nothing to export.')
)));
}
$totalPages = ceil($totalCount / $pageSize);
$sql = 'SELECT * FROM `' . _DB_PREFIX_ . 'arseopro_redirect` LIMIT ' . (int)($page * $pageSize) . ', ' . (int)$pageSize;
$result = Db::getInstance()->executeS($sql);
$filename = $this->module->getPath(true) . 'csv/export.csv';
$f = null;
if (!is_dir($this->module->getPath(true) . 'csv')) {
if (!@mkdir($this->module->getPath(true) . 'csv', 0777, true)) {
die(Tools::jsonEncode(array(
'percent' => 0,
'count' => 0,
'continue' => 0,
'page' => $page,
'success' => 0,
'error' => sprintf($this->l('Cant create directory %s. Please create this directory manualy.'), $this->module->getPath(true) . 'csv/')
)));
}
} elseif (!is_writable($this->module->getPath(true) . 'csv')) {
die(Tools::jsonEncode(array(
'percent' => 0,
'count' => 0,
'continue' => 0,
'page' => $page,
'success' => 0,
'error' => sprintf($this->l('Directory %s is not writable. Please change permission for this directory.'), $this->module->getPath(true) . 'csv/')
)));
}
if ($page == 0) {
if (file_exists($filename)) {
unlink($filename);
}
$f = fopen($filename, 'w');
} elseif ($page > 0) {
$f = fopen($filename, 'a');
}
foreach ($result as $k => $row) {
$line = array();
$line[] = $row['from'];
$line[] = $row['to'];
$line[] = $row['type'];
$line[] = $row['id_shop'];
$line[] = $row['status'];
fwrite($f, implode(';', $line) . PHP_EOL);
}
fclose($f);
die(Tools::jsonEncode(array(
'percent' => ceil(($page + 1) / $totalPages * 100),
'count' => count($result),
'totalCount' => $totalCount,
'processed' => $count + count($result),
'continue' => (($page + 1) == $totalPages)? 0 : 1,
'success' => 1,
'time' => date('Y-m-d H:i:s', Configuration::get('ARSEO_NFL_TIME')),
'page' => $page + 1
)));
}
public function ajaxProcessPageNotFound()
{
$pageSize = 100;
$page = (int)Tools::getValue('page');
$count = (int)Tools::getValue('count');
$to = Tools::getValue('to');
$type = Tools::getValue('type');
$sql = 'SELECT COUNT(DISTINCT(t.request_uri), t.id_shop) as c
FROM `' . _DB_PREFIX_ . 'pagenotfound` as t
LEFT JOIN `' . _DB_PREFIX_ . 'arseopro_redirect` as r ON t.request_uri = r.`from`
WHERE r.`from` IS NULL';
$res = Db::getInstance()->getRow($sql);
$totalCount = (int)$res['c'];
if ($totalCount == 0) {
die(Tools::jsonEncode(array(
'percent' => 0,
'count' => 0,
'continue' => 0,
'page' => $page,
'success' => 0,
'error' => $this->l('Page-not-found table is empty. Nothing to export.')
)));
}
$totalPages = ceil($totalCount / $pageSize);
$sql = 'SELECT DISTINCT(t.request_uri), t.id_shop
FROM `' . _DB_PREFIX_ . 'pagenotfound` as t
LEFT JOIN `' . _DB_PREFIX_ . 'arseopro_redirect` as r ON t.request_uri = r.`from`
WHERE r.`from` IS NULL LIMIT ' . (int)($page * $pageSize) . ', ' . (int)$pageSize;
$result = Db::getInstance()->executeS($sql);
$filename = $this->module->getPath(true) . 'csv/not-found-list.csv';
$f = null;
if (!is_dir($this->module->getPath(true) . 'csv')) {
if (!@mkdir($this->module->getPath(true) . 'csv', 0777, true)) {
die(Tools::jsonEncode(array(
'percent' => 0,
'count' => 0,
'continue' => 0,
'page' => $page,
'success' => 0,
'error' => sprintf($this->l('Cant create directory %s. Please create this directory manualy.'), $this->module->getPath(true) . 'csv/')
)));
}
} elseif (!is_writable($this->module->getPath(true) . 'csv')) {
die(Tools::jsonEncode(array(
'percent' => 0,
'count' => 0,
'continue' => 0,
'page' => $page,
'success' => 0,
'error' => sprintf($this->l('Directory %s is not writable. Please change permission for this directory.'), $this->module->getPath(true) . 'csv/')
)));
}
if ($page == 0) {
if (file_exists($filename)) {
unlink($filename);
}
Configuration::updateValue('ARSEO_NFL_TIME', time());
$f = fopen($filename, 'w');
} elseif ($page > 0) {
$f = fopen($filename, 'a');
}
foreach ($result as $k => $row) {
$line = array();
$line[] = $row['request_uri'];
$line[] = $to;
$line[] = $type;
$line[] = $row['id_shop'];
fwrite($f, implode(';', $line) . PHP_EOL);
}
fclose($f);
die(Tools::jsonEncode(array(
'percent' => ceil(($page + 1) / $totalPages * 100),
'count' => count($result),
'totalCount' => $totalCount,
'processed' => $count + count($result),
'continue' => (($page + 1) == $totalPages)? 0 : 1,
'success' => 1,
'time' => date('Y-m-d H:i:s', Configuration::get('ARSEO_NFL_TIME')),
'page' => $page + 1
)));
}
public function ajaxProcessEdit()
{
$id = Tools::getValue('id');
$model = new ArSeoProRedirectTable($id);
die(Tools::jsonEncode($model));
}
public function ajaxProcessClear()
{
ArSeoProRedirectTable::truncate();
die(Tools::jsonEncode(array(
'success' => 1
)));
}
public function ajaxProcessDelete()
{
$id = Tools::getValue('id');
$model = new ArSeoProRedirectTable($id);
die(Tools::jsonEncode(array(
'success' => $model->delete()
)));
}
public function ajaxProcessEnabledconfiguration()
{
$id = Tools::getValue('id_redirect');
$model = new ArSeoProRedirectTable($id);
$model->status = $model->status? 0 : 1;
die(Tools::jsonEncode(array(
'success' => $model->save(false),
'text' => $this->l('Status updated')
)));
}
}

View File

@@ -0,0 +1,75 @@
<?php
/**
* 2012-2018 Areama
*
* 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@areama.net so we can send you a copy immediately.
*
* @author Areama <contact@areama.net>
* @copyright 2018 Areama
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of Areama
*/
include_once dirname(__FILE__).'/AdminArSeoControllerAbstract.php';
include_once dirname(__FILE__).'/../../classes/ArSeoProRobots.php';
class AdminArSeoRobotsController extends AdminArSeoControllerAbstract
{
public function ajaxProcessReload()
{
$robots = new ArSeoProRobots($this->module);
$content = $robots->getContent();
if ($content === false) {
die(Tools::jsonEncode(array(
'success' => 0,
'error' => $robots->getError()
)));
} else {
die(Tools::jsonEncode(array(
'success' => 1,
'content' => $content
)));
}
}
public function ajaxProcessSave()
{
$robots = new ArSeoProRobots($this->module);
$content = Tools::getValue('robots');
if ($robots->save($content)) {
die(Tools::jsonEncode(array(
'success' => 1,
'content' => $robots->getContent()
)));
} else {
die(Tools::jsonEncode(array(
'success' => 0,
'error' => $robots->getError()
)));
}
}
public function ajaxProcessDefaults()
{
$robots = new ArSeoProRobots($this->module);
if ($robots->loadDefaults()) {
die(Tools::jsonEncode(array(
'success' => 1,
'content' => $robots->getContent()
)));
} else {
die(Tools::jsonEncode(array(
'success' => 0,
'error' => $robots->getError()
)));
}
}
}

View File

@@ -0,0 +1,81 @@
<?php
/**
* 2012-2018 Areama
*
* 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@areama.net so we can send you a copy immediately.
*
* @author Areama <contact@areama.net>
* @copyright 2018 Areama
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of Areama
*/
include_once dirname(__FILE__).'/AdminArSeoSitemapController.php';
include_once dirname(__FILE__).'/../../classes/sitemap/models/ArSeoProSitemapCategory.php';
class AdminArSeoSitemapCategoryController extends AdminArSeoSitemapController
{
public function ajaxProcessSwitch()
{
$id = Tools::getValue('id');
$id_shop = Context::getContext()->shop->id;
$sql = 'SELECT * FROM `' . ArSeoProSitemapCategory::getTableName() . '` WHERE id_shop=' . (int)$id_shop . ' AND id_category=' . (int)$id;
if ($row = Db::getInstance()->getRow($sql)) {
$model = new ArSeoProSitemapCategory($row['id_sitemap']);
} else {
$model = new ArSeoProSitemapCategory();
$model->id_category = (int)$id;
$model->id_shop = (int)$id_shop;
}
$model->updated_at = date('Y-m-d H:i:s');
$model->export = $model->export? 0 : 1;
die(Tools::jsonEncode(array(
'success' => $model->save(false),
'status' => $model->export,
'text' => $this->l('Status updated')
)));
}
public function ajaxProcessCheckAll()
{
$ids = $this->filterIdList(Tools::getValue('ids'));
foreach ($ids as $id) {
$id_shop = Context::getContext()->shop->id;
$date = date('Y-m-d H:i:s');
$sql = 'SELECT * FROM `' . ArSeoProSitemapCategory::getTableName() . '` WHERE id_category=' . (int)$id . ' AND id_shop=' . (int)$id_shop;
if ($row = Db::getInstance()->getRow($sql)) {
$model = new ArSeoProSitemapCategory($row['id_sitemap']);
} else {
$model = new ArSeoProSitemapCategory();
}
$model->id_category = (int)$id;
$model->id_shop = (int)$id_shop;
$model->export = 1;
$model->updated_at = $date;
$model->save();
}
die(Tools::jsonEncode(array(
'success' => 1,
'text' => $this->l('Status updated')
)));
}
public function ajaxProcessUncheckAll()
{
ArSeoProSitemapCategory::truncate();
die(Tools::jsonEncode(array(
'success' => 1,
'text' => $this->l('Status updated')
)));
}
}

View File

@@ -0,0 +1,174 @@
<?php
/**
* 2012-2018 Areama
*
* 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@areama.net so we can send you a copy immediately.
*
* @author Areama <contact@areama.net>
* @copyright 2018 Areama
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of Areama
*/
include_once dirname(__FILE__).'/AdminArSeoSitemapController.php';
include_once dirname(__FILE__).'/../../classes/sitemap/models/ArSeoProSitemapCms.php';
class AdminArSeoSitemapCmsController extends AdminArSeoSitemapController
{
public function displayViewLink($token, $id, $name)
{
$link = Context::getContext()->link->getCMSLink($id);
return $this->module->render('_partials/_button.tpl', array(
'href' => $link,
'onclick' => '',
'class' => 'btn btn-default',
'target' => '_blank',
'title' => $this->l('View'),
'icon' => 'icon-search-plus'
));
}
public function getListId()
{
return 'sitemap-cms';
}
public function renderTable($params = array())
{
$pageSize = isset($params['selected_pagination'])? $params['selected_pagination'] : 20;
$helper = new ArSeoProListHelper();
$helper->title = $this->l('URL Rewrite Rules for products');
$helper->actions = array(
'view'
);
$helper->list_id = $this->getListId();
$helper->identifier = 'id_cms';
$helper->currentIndex = AdminController::$currentIndex.'&configure='.$this->module->name.'&id_shop='.Context::getContext()->shop->id;
$helper->setPagination(array(20, 50, 100));
$totalCount = ArSeoProSitemapCms::getCount($params);
if (isset($params['page'])) {
$totalPages = ceil($totalCount / $pageSize);
if ($params['page'] > $totalPages) {
$params['page'] = $totalPages;
}
}
$helper->listTotal = $totalCount;
$helper->currentPage = isset($params['page'])? $params['page'] : 1;
$helper->module = $this->module;
$helper->no_link = true;
$helper->setDefaultPagination($pageSize);
$helper->filters = isset($params['filter'])? $params['filter'] : array();
$helper->token = Tools::getAdminTokenLite('AdminArSeoSitemap');
$helper->bulk_actions = array(
'activate' => array(
'text' => $this->l('Activate selected'),
'icon' => 'icon-check',
'confirm' => $this->l('Activate selected items?'),
'js_action' => 'arSEO.sitemap.cms.bulk.activate(); return false'
),
'deactivate' => array(
'text' => $this->l('Deactivate selected'),
'icon' => 'icon-remove',
'confirm' => $this->l('Deactivate selected items?'),
'js_action' => 'arSEO.sitemap.cms.bulk.deactivate(); return false'
)
);
$list = ArSeoProSitemapCms::getAll($params);
$columns = array(
'id_cms' => array(
'title' => $this->l('#'),
'filter_key' => 'id',
'orderby' => false,
),
'meta_title' => array(
'title' => $this->l('Name'),
'filter_key' => 'meta_title',
'orderby' => false,
)
);
if (Shop::isFeatureActive()) {
$columns['id_shop'] = array(
'title' => $this->l('Shop'),
'filter_key' => 'id_shop',
'callback' => 'shopTableValue',
'type' => 'select',
'orderby' => false,
'search' => false,
'list' => $this->getShopList(),
);
}
$columns['export'] = array(
'title' => $this->l('Export'),
'filter_key' => 'export',
'ajax' => true,
'orderby' => false,
'type' => 'select',
'list' => $this->yesNoList(),
'callback' => 'renderSupplierCheckbox'
);
return $helper->generateList($list, $columns);
}
public function ajaxProcessSwitch()
{
$id = Tools::getValue('id_sitemap');
$id_cms = Tools::getValue('id_cms');
$id_shop = Context::getContext()->shop->id;
$sql = 'SELECT * FROM `' . ArSeoProSitemapCms::getTableName() . '` WHERE id_shop=' . (int)$id_shop . ' AND id_cms=' . (int)$id_cms;
if ($row = Db::getInstance()->getRow($sql)) {
$model = new ArSeoProSitemapCms($row['id_sitemap']);
} else {
$model = new ArSeoProSitemapCms();
$model->id_cms = (int)$id_cms;
$model->id_shop = (int)$id_shop;
}
$model->updated_at = date('Y-m-d H:i:s');
$model->export = $model->export? 0 : 1;
die(Tools::jsonEncode(array(
'success' => $model->save(false),
'status' => $model->export,
'text' => $this->l('Status updated')
)));
}
public function renderSupplierCheckbox($cellValue, $row)
{
$link = Context::getContext()->link->getAdminLink('AdminArSeoSitemapCms').'&ajax=1&action=switch&id_sitemap='.$row['id_sitemap'].'&id_cms='.$row['id_cms'];
return $this->renderCheckbox($link, $cellValue, $row);
}
protected function toggle($export = 1)
{
$ids = $this->filterIdList(Tools::getValue('ids'));
$id_shop = Context::getContext()->shop->id;
$date = date('Y-m-d H:i:s');
foreach ($ids as $id) {
$sql = 'SELECT * FROM `' . ArSeoProSitemapCms::getTableName() . '` WHERE id_cms=' . (int)$id . ' AND id_shop=' . (int)$id_shop;
if ($row = Db::getInstance()->getRow($sql)) {
$model = new ArSeoProSitemapCms($row['id_sitemap']);
} else {
$model = new ArSeoProSitemapCms();
}
$model->id_cms = (int)$id;
$model->id_shop = (int)$id_shop;
$model->export = (int)$export;
$model->updated_at = $date;
$model->save();
}
}
}

View File

@@ -0,0 +1,52 @@
<?php
/**
* 2012-2018 Areama
*
* 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@areama.net so we can send you a copy immediately.
*
* @author Areama <contact@areama.net>
* @copyright 2018 Areama
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of Areama
*/
include_once dirname(__FILE__).'/../../classes/ArSeoProListHelper.php';
include_once dirname(__FILE__).'/AdminArSeoControllerAbstract.php';
class AdminArSeoSitemapController extends AdminArSeoControllerAbstract
{
protected function renderCheckbox($link, $cellValue, $row)
{
return $this->module->render('_partials/_checkbox.tpl', array(
'href' => $link,
'onclick' => 'arSEO.sitemap.toggleItem(this); return false;',
'class' => ($row['export']? 'list-action-enable action-enabled' : 'list-action-enable action-disabled'),
'export' => $row['export'],
'title' => ($row['export']? $this->l('Enabled') : $this->l('Disabled')),
));
}
public function ajaxProcessActivate()
{
$this->toggle();
die(Tools::jsonEncode(array(
'success' => 1
)));
}
public function ajaxProcessDeactivate()
{
$this->toggle(0);
die(Tools::jsonEncode(array(
'success' => 1
)));
}
}

View File

@@ -0,0 +1,174 @@
<?php
/**
* 2012-2018 Areama
*
* 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@areama.net so we can send you a copy immediately.
*
* @author Areama <contact@areama.net>
* @copyright 2018 Areama
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of Areama
*/
include_once dirname(__FILE__).'/AdminArSeoSitemapController.php';
include_once dirname(__FILE__).'/../../classes/sitemap/models/ArSeoProSitemapManufacturer.php';
class AdminArSeoSitemapManufacturerController extends AdminArSeoSitemapController
{
public function displayViewLink($token, $id, $name)
{
$link = Context::getContext()->link->getManufacturerLink($id);
return $this->module->render('_partials/_button.tpl', array(
'href' => $link,
'onclick' => '',
'class' => 'btn btn-default',
'target' => '_blank',
'title' => $this->l('View'),
'icon' => 'icon-search-plus'
));
}
public function getListId()
{
return 'sitemap-manufacturers';
}
public function renderTable($params = array())
{
$pageSize = isset($params['selected_pagination'])? $params['selected_pagination'] : 20;
$helper = new ArSeoProListHelper();
$helper->title = $this->l('URL Rewrite Rules for products');
$helper->actions = array(
'view'
);
$helper->list_id = $this->getListId();
$helper->identifier = 'id_manufacturer';
$helper->currentIndex = AdminController::$currentIndex.'&configure='.$this->module->name.'&id_shop='.Context::getContext()->shop->id.'&id_manufacturer=';
$helper->setPagination(array(20, 50, 100));
$totalCount = ArSeoProSitemapManufacturer::getCount($params);
if (isset($params['page'])) {
$totalPages = ceil($totalCount / $pageSize);
if ($params['page'] > $totalPages) {
$params['page'] = $totalPages;
}
}
$helper->listTotal = $totalCount;
$helper->currentPage = isset($params['page'])? $params['page'] : 1;
$helper->module = $this->module;
$helper->no_link = true;
$helper->setDefaultPagination($pageSize);
$helper->filters = isset($params['filter'])? $params['filter'] : array();
$helper->token = Tools::getAdminTokenLite('AdminArSeoSitemap');
$helper->bulk_actions = array(
'activate' => array(
'text' => $this->l('Activate selected'),
'icon' => 'icon-check',
'confirm' => $this->l('Activate selected items?'),
'js_action' => 'arSEO.sitemap.manufacturer.bulk.activate(); return false'
),
'deactivate' => array(
'text' => $this->l('Deactivate selected'),
'icon' => 'icon-remove',
'confirm' => $this->l('Deactivate selected items?'),
'js_action' => 'arSEO.sitemap.manufacturer.bulk.deactivate(); return false'
)
);
$list = ArSeoProSitemapManufacturer::getAll($params);
$columns = array(
'id_manufacturer' => array(
'title' => $this->l('#'),
'filter_key' => 'id',
'orderby' => false,
),
'name' => array(
'title' => $this->l('Name'),
'filter_key' => 'name',
'orderby' => false,
)
);
if (Shop::isFeatureActive()) {
$columns['id_shop'] = array(
'title' => $this->l('Shop'),
'filter_key' => 'id_shop',
'callback' => 'shopTableValue',
'type' => 'select',
'orderby' => false,
'search' => false,
'list' => $this->getShopList(),
);
}
$columns['export'] = array(
'title' => $this->l('Export'),
'filter_key' => 'export',
'ajax' => true,
'orderby' => false,
'type' => 'select',
'list' => $this->yesNoList(),
'callback' => 'renderSupplierCheckbox'
);
return $helper->generateList($list, $columns);
}
public function ajaxProcessSwitch()
{
$id = Tools::getValue('id_sitemap');
$id_manufacturer = Tools::getValue('id_manufacturer');
$id_shop = Context::getContext()->shop->id;
$sql = 'SELECT * FROM `' . ArSeoProSitemapManufacturer::getTableName() . '` WHERE id_shop=' . (int)$id_shop . ' AND id_manufacturer=' . (int)$id_manufacturer;
if ($row = Db::getInstance()->getRow($sql)) {
$model = new ArSeoProSitemapManufacturer($row['id_sitemap']);
} else {
$model = new ArSeoProSitemapManufacturer();
$model->id_manufacturer = (int)$id_manufacturer;
$model->id_shop = (int)$id_shop;
}
$model->updated_at = date('Y-m-d H:i:s');
$model->export = $model->export? 0 : 1;
die(Tools::jsonEncode(array(
'success' => $model->save(false),
'status' => $model->export,
'text' => $this->l('Status updated')
)));
}
public function renderSupplierCheckbox($cellValue, $row)
{
$link = Context::getContext()->link->getAdminLink('AdminArSeoSitemapManufacturer').'&ajax=1&action=switch&id_sitemap='.$row['id_sitemap'].'&id_manufacturer='.$row['id_manufacturer'];
return $this->renderCheckbox($link, $cellValue, $row);
}
protected function toggle($export = 1)
{
$ids = $this->filterIdList(Tools::getValue('ids'));
$id_shop = Context::getContext()->shop->id;
$date = date('Y-m-d H:i:s');
foreach ($ids as $id) {
$sql = 'SELECT * FROM `' . ArSeoProSitemapManufacturer::getTableName() . '` WHERE id_manufacturer=' . (int)$id . ' AND id_shop=' . (int)$id_shop;
if ($row = Db::getInstance()->getRow($sql)) {
$model = new ArSeoProSitemapManufacturer($row['id_sitemap']);
} else {
$model = new ArSeoProSitemapManufacturer();
}
$model->id_manufacturer = (int)$id;
$model->id_shop = (int)$id_shop;
$model->export = (int)$export;
$model->updated_at = $date;
$model->save();
}
}
}

View File

@@ -0,0 +1,180 @@
<?php
/**
* 2012-2018 Areama
*
* 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@areama.net so we can send you a copy immediately.
*
* @author Areama <contact@areama.net>
* @copyright 2018 Areama
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of Areama
*/
include_once dirname(__FILE__).'/AdminArSeoSitemapController.php';
include_once dirname(__FILE__).'/../../classes/sitemap/models/ArSeoProSitemapMetaPages.php';
class AdminArSeoSitemapMetaController extends AdminArSeoSitemapController
{
public function displayViewLink($token, $id, $name)
{
$meta = new Meta($id, Context::getContext()->language->id);
$link = Context::getContext()->link->getPageLink($meta->page);
return $this->module->render('_partials/_button.tpl', array(
'href' => $link,
'onclick' => '',
'class' => 'btn btn-default',
'target' => '_blank',
'title' => $this->l('View'),
'icon' => 'icon-search-plus'
));
}
public function getListId()
{
return 'sitemap-meta';
}
public function renderTable($params = array())
{
$pageSize = isset($params['selected_pagination'])? $params['selected_pagination'] : 20;
$helper = new ArSeoProListHelper();
$helper->title = $this->l('URL Rewrite Rules for products');
$helper->actions = array(
'view'
);
$helper->list_id = $this->getListId();
$helper->identifier = 'id_meta';
$helper->currentIndex = AdminController::$currentIndex.'&configure='.$this->module->name.'&id_shop='.Context::getContext()->shop->id;
$helper->setPagination(array(20, 50, 100));
$totalCount = ArSeoProSitemapMetaPages::getCount($params);
if (isset($params['page'])) {
$totalPages = ceil($totalCount / $pageSize);
if ($params['page'] > $totalPages) {
$params['page'] = $totalPages;
}
}
$helper->listTotal = $totalCount;
$helper->currentPage = isset($params['page'])? $params['page'] : 1;
$helper->module = $this->module;
$helper->no_link = true;
$helper->setDefaultPagination($pageSize);
$helper->filters = isset($params['filter'])? $params['filter'] : array();
$helper->token = Tools::getAdminTokenLite('AdminArSeoSitemap');
$helper->bulk_actions = array(
'activate' => array(
'text' => $this->l('Activate selected'),
'icon' => 'icon-check',
'confirm' => $this->l('Activate selected items?'),
'js_action' => 'arSEO.sitemap.meta.bulk.activate(); return false'
),
'deactivate' => array(
'text' => $this->l('Deactivate selected'),
'icon' => 'icon-remove',
'confirm' => $this->l('Deactivate selected items?'),
'js_action' => 'arSEO.sitemap.meta.bulk.deactivate(); return false'
)
);
$list = ArSeoProSitemapMetaPages::getAll($params);
$columns = array(
'id_meta' => array(
'title' => $this->l('#'),
'filter_key' => 'id',
'orderby' => false,
),
'title' => array(
'title' => $this->l('Title'),
'filter_key' => 'title',
'orderby' => false,
),
'page' => array(
'title' => $this->l('Page'),
'filter_key' => 'page',
'orderby' => false,
)
);
if (Shop::isFeatureActive()) {
$columns['id_shop'] = array(
'title' => $this->l('Shop'),
'filter_key' => 'id_shop',
'callback' => 'shopTableValue',
'type' => 'select',
'orderby' => false,
'search' => false,
'list' => $this->getShopList(),
);
}
$columns['export'] = array(
'title' => $this->l('Export'),
'filter_key' => 'export',
'ajax' => true,
'orderby' => false,
'type' => 'select',
'list' => $this->yesNoList(),
'callback' => 'renderSupplierCheckbox'
);
return $helper->generateList($list, $columns);
}
public function ajaxProcessSwitch()
{
$id = Tools::getValue('id_sitemap');
$id_meta = Tools::getValue('id_meta');
$id_shop = Context::getContext()->shop->id;
$sql = 'SELECT * FROM `' . ArSeoProSitemapMetaPages::getTableName() . '` WHERE id_shop=' . (int)$id_shop . ' AND id_meta=' . (int)$id_meta;
if ($row = Db::getInstance()->getRow($sql)) {
$model = new ArSeoProSitemapMetaPages($row['id_sitemap']);
} else {
$model = new ArSeoProSitemapMetaPages();
$model->id_meta = (int)$id_meta;
$model->id_shop = (int)$id_shop;
}
$model->updated_at = date('Y-m-d H:i:s');
$model->export = $model->export? 0 : 1;
die(Tools::jsonEncode(array(
'success' => $model->save(false),
'status' => $model->export,
'text' => $this->l('Status updated')
)));
}
public function renderSupplierCheckbox($cellValue, $row)
{
$link = Context::getContext()->link->getAdminLink('AdminArSeoSitemapMeta').'&ajax=1&action=switch&id_sitemap='.$row['id_sitemap'].'&id_meta='.$row['id_meta'];
return $this->renderCheckbox($link, $cellValue, $row);
}
protected function toggle($export = 1)
{
$ids = $this->filterIdList(Tools::getValue('ids'));
$id_shop = Context::getContext()->shop->id;
$date = date('Y-m-d H:i:s');
foreach ($ids as $id) {
$sql = 'SELECT * FROM `' . ArSeoProSitemapMetaPages::getTableName() . '` WHERE id_meta=' . (int)$id . ' AND id_shop=' . (int)$id_shop;
if ($row = Db::getInstance()->getRow($sql)) {
$model = new ArSeoProSitemapMetaPages($row['id_sitemap']);
} else {
$model = new ArSeoProSitemapMetaPages();
}
$model->id_meta = (int)$id;
$model->id_shop = (int)$id_shop;
$model->export = (int)$export;
$model->updated_at = $date;
$model->save();
}
}
}

View File

@@ -0,0 +1,179 @@
<?php
/**
* 2012-2018 Areama
*
* 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@areama.net so we can send you a copy immediately.
*
* @author Areama <contact@areama.net>
* @copyright 2018 Areama
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of Areama
*/
include_once dirname(__FILE__).'/AdminArSeoSitemapController.php';
include_once dirname(__FILE__).'/../../classes/sitemap/models/ArSeoProSitemapProduct.php';
class AdminArSeoSitemapProductController extends AdminArSeoSitemapController
{
public function displayViewLink($token, $id, $name)
{
$link = Context::getContext()->link->getProductLink($id);
return $this->module->render('_partials/_button.tpl', array(
'href' => $link,
'onclick' => '',
'class' => 'btn btn-default',
'target' => '_blank',
'title' => $this->l('View'),
'icon' => 'icon-search-plus'
));
}
public function getListId()
{
return 'sitemap-products';
}
public function renderTable($params = array())
{
$pageSize = isset($params['selected_pagination'])? $params['selected_pagination'] : 20;
$helper = new ArSeoProListHelper();
$helper->title = $this->l('URL Rewrite Rules for products');
$helper->actions = array(
'view'
);
$helper->list_id = $this->getListId();
$helper->identifier = 'id_product';
$helper->currentIndex = AdminController::$currentIndex.'&configure='.$this->module->name.'&id_shop='.Context::getContext()->shop->id.'&id_product=';
$helper->setPagination(array(20, 50, 100));
$totalCount = ArSeoProSitemapProduct::getCount($params);
if (isset($params['page'])) {
$totalPages = ceil($totalCount / $pageSize);
if ($params['page'] > $totalPages) {
$params['page'] = $totalPages;
}
}
$helper->listTotal = $totalCount;
$helper->currentPage = isset($params['page'])? $params['page'] : 1;
$helper->module = $this->module;
$helper->no_link = true;
$helper->setDefaultPagination($pageSize);
$helper->filters = isset($params['filter'])? $params['filter'] : array();
$helper->token = Tools::getAdminTokenLite('AdminArSeoSitemap');
$helper->bulk_actions = array(
'activate' => array(
'text' => $this->l('Activate selected'),
'icon' => 'icon-check',
'confirm' => $this->l('Activate selected items?'),
'js_action' => 'arSEO.sitemap.product.bulk.activate(); return false'
),
'deactivate' => array(
'text' => $this->l('Deactivate selected'),
'icon' => 'icon-remove',
'confirm' => $this->l('Deactivate selected items?'),
'js_action' => 'arSEO.sitemap.product.bulk.deactivate(); return false'
)
);
$list = ArSeoProSitemapProduct::getAll($params);
$columns = array(
'id_product' => array(
'title' => $this->l('#'),
'filter_key' => 'id',
'orderby' => false,
),
'reference' => array(
'title' => $this->l('Reference'),
'filter_key' => 'reference',
'orderby' => false,
),
'name' => array(
'title' => $this->l('Name'),
'filter_key' => 'name',
'orderby' => false,
)
);
if (Shop::isFeatureActive()) {
$columns['id_shop'] = array(
'title' => $this->l('Shop'),
'filter_key' => 'id_shop',
'callback' => 'shopTableValue',
'type' => 'select',
'orderby' => false,
'search' => false,
'list' => $this->getShopList(),
);
}
$columns['export'] = array(
'title' => $this->l('Export'),
'filter_key' => 'export',
'type' => 'select',
'list' => $this->yesNoList(),
'ajax' => true,
'orderby' => false,
'callback' => 'renderProductCheckbox'
);
return $helper->generateList($list, $columns);
}
public function renderProductCheckbox($cellValue, $row)
{
$link = Context::getContext()->link->getAdminLink('AdminArSeoSitemapProduct').'&ajax=1&action=switch&id_sitemap='.$row['id_sitemap'].'&id_product='.$row['id_product'];
return $this->renderCheckbox($link, $cellValue, $row);
}
protected function toggle($export = 1)
{
$ids = $this->filterIdList(Tools::getValue('ids'));
$id_shop = Context::getContext()->shop->id;
$date = date('Y-m-d H:i:s');
foreach ($ids as $id) {
$sql = 'SELECT * FROM `' . ArSeoProSitemapProduct::getTableName() . '` WHERE id_product=' . (int)$id . ' AND id_shop=' . (int)$id_shop;
if ($row = Db::getInstance()->getRow($sql)) {
$model = new ArSeoProSitemapProduct($row['id_sitemap']);
} else {
$model = new ArSeoProSitemapProduct();
}
$model->id_product = (int)$id;
$model->id_shop = (int)$id_shop;
$model->export = (int)$export;
$model->updated_at = $date;
$model->save();
}
}
public function ajaxProcessSwitch()
{
$id = Tools::getValue('id_sitemap');
$id_product = Tools::getValue('id_product');
$id_shop = Context::getContext()->shop->id;
$sql = 'SELECT * FROM `' . ArSeoProSitemapProduct::getTableName() . '` WHERE id_shop=' . (int)$id_shop . ' AND id_product=' . (int)$id_product;
if ($row = Db::getInstance()->getRow($sql)) {
$model = new ArSeoProSitemapProduct($row['id_sitemap']);
} else {
$model = new ArSeoProSitemapProduct();
$model->id_product = (int)$id_product;
$model->id_shop = (int)$id_shop;
}
$model->updated_at = date('Y-m-d H:i:s');
$model->export = $model->export? 0 : 1;
die(Tools::jsonEncode(array(
'success' => $model->save(false),
'status' => $model->export,
'text' => $this->l('Status updated')
)));
}
}

View File

@@ -0,0 +1,174 @@
<?php
/**
* 2012-2018 Areama
*
* 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@areama.net so we can send you a copy immediately.
*
* @author Areama <contact@areama.net>
* @copyright 2018 Areama
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of Areama
*/
include_once dirname(__FILE__).'/AdminArSeoSitemapController.php';
include_once dirname(__FILE__).'/../../classes/sitemap/models/ArSeoProSitemapSupplier.php';
class AdminArSeoSitemapSupplierController extends AdminArSeoSitemapController
{
public function displayViewLink($token, $id, $name)
{
$link = Context::getContext()->link->getSupplierLink($id);
return $this->module->render('_partials/_button.tpl', array(
'href' => $link,
'onclick' => '',
'class' => 'btn btn-default',
'target' => '_blank',
'title' => $this->l('View'),
'icon' => 'icon-search-plus'
));
}
public function getListId()
{
return 'sitemap-suppliers';
}
public function renderTable($params = array())
{
$pageSize = isset($params['selected_pagination'])? $params['selected_pagination'] : 20;
$helper = new ArSeoProListHelper();
$helper->title = $this->l('URL Rewrite Rules for products');
$helper->actions = array(
'view'
);
$helper->list_id = $this->getListId();
$helper->identifier = 'id_supplier';
$helper->currentIndex = AdminController::$currentIndex.'&configure='.$this->module->name.'&id_shop='.Context::getContext()->shop->id.'&id_supplier=';
$helper->setPagination(array(20, 50, 100));
$totalCount = ArSeoProSitemapSupplier::getCount($params);
if (isset($params['page'])) {
$totalPages = ceil($totalCount / $pageSize);
if ($params['page'] > $totalPages) {
$params['page'] = $totalPages;
}
}
$helper->listTotal = $totalCount;
$helper->currentPage = isset($params['page'])? $params['page'] : 1;
$helper->module = $this->module;
$helper->no_link = true;
$helper->setDefaultPagination($pageSize);
$helper->filters = isset($params['filter'])? $params['filter'] : array();
$helper->token = Tools::getAdminTokenLite('AdminArSeoSitemap');
$helper->bulk_actions = array(
'activate' => array(
'text' => $this->l('Activate selected'),
'icon' => 'icon-check',
'confirm' => $this->l('Activate selected items?'),
'js_action' => 'arSEO.sitemap.supplier.bulk.activate(); return false'
),
'deactivate' => array(
'text' => $this->l('Deactivate selected'),
'icon' => 'icon-remove',
'confirm' => $this->l('Deactivate selected items?'),
'js_action' => 'arSEO.sitemap.supplier.bulk.deactivate(); return false'
)
);
$list = ArSeoProSitemapSupplier::getAll($params);
$columns = array(
'id_supplier' => array(
'title' => $this->l('#'),
'filter_key' => 'id',
'orderby' => false,
),
'name' => array(
'title' => $this->l('Name'),
'filter_key' => 'name',
'orderby' => false,
)
);
if (Shop::isFeatureActive()) {
$columns['id_shop'] = array(
'title' => $this->l('Shop'),
'filter_key' => 'id_shop',
'callback' => 'shopTableValue',
'type' => 'select',
'orderby' => false,
'search' => false,
'list' => $this->getShopList(),
);
}
$columns['export'] = array(
'title' => $this->l('Export'),
'filter_key' => 'export',
'ajax' => true,
'orderby' => false,
'type' => 'select',
'list' => $this->yesNoList(),
'callback' => 'renderSupplierCheckbox'
);
return $helper->generateList($list, $columns);
}
public function ajaxProcessSwitch()
{
$id = Tools::getValue('id_sitemap');
$id_supplier = Tools::getValue('id_supplier');
$id_shop = Context::getContext()->shop->id;
$sql = 'SELECT * FROM `' . ArSeoProSitemapSupplier::getTableName() . '` WHERE id_shop=' . (int)$id_shop . ' AND id_supplier=' . (int)$id_supplier;
if ($row = Db::getInstance()->getRow($sql)) {
$model = new ArSeoProSitemapSupplier($row['id_sitemap']);
} else {
$model = new ArSeoProSitemapSupplier();
$model->id_supplier = (int)$id_supplier;
$model->id_shop = (int)$id_shop;
}
$model->updated_at = date('Y-m-d H:i:s');
$model->export = $model->export? 0 : 1;
die(Tools::jsonEncode(array(
'success' => $model->save(false),
'status' => $model->export,
'text' => $this->l('Status updated')
)));
}
public function renderSupplierCheckbox($cellValue, $row)
{
$link = Context::getContext()->link->getAdminLink('AdminArSeoSitemapSupplier').'&ajax=1&action=switch&id_sitemap='.$row['id_sitemap'].'&id_supplier='.$row['id_supplier'];
return $this->renderCheckbox($link, $cellValue, $row);
}
protected function toggle($export = 1)
{
$ids = $this->filterIdList(Tools::getValue('ids'));
$id_shop = Context::getContext()->shop->id;
$date = date('Y-m-d H:i:s');
foreach ($ids as $id) {
$sql = 'SELECT * FROM `' . ArSeoProSitemapSupplier::getTableName() . '` WHERE id_supplier=' . (int)$id . ' AND id_shop=' . (int)$id_shop;
if ($row = Db::getInstance()->getRow($sql)) {
$model = new ArSeoProSitemapSupplier($row['id_sitemap']);
} else {
$model = new ArSeoProSitemapSupplier();
}
$model->id_supplier = (int)$id;
$model->id_shop = (int)$id_shop;
$model->export = (int)$export;
$model->updated_at = $date;
$model->save();
}
}
}

View File

@@ -0,0 +1,720 @@
<?php
/**
* 2012-2018 Areama
*
* 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@areama.net so we can send you a copy immediately.
*
* @author Areama <contact@areama.net>
* @copyright 2018 Areama
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of Areama
*/
include_once dirname(__FILE__).'/AdminArSeoControllerAbstract.php';
include_once dirname(__FILE__).'/../../classes/ArSeoProUrls.php';
include_once dirname(__FILE__).'/../../classes/url/models/ArSeoProRuleTable.php';
include_once dirname(__FILE__).'/../../classes/ArSeoProListHelper.php';
include_once dirname(__FILE__).'/../../classes/ArSeoProInstaller.php';
class AdminArSeoUrlsController extends AdminArSeoControllerAbstract
{
public function ajaxProcessResetOldRoutes()
{
$reflectionClass = new ReflectionClass('Dispatcher');
$defaultProps = $reflectionClass->getDefaultProperties();
$defaultRoutes = $defaultProps['default_routes'];
$this->module->getInstaller()->clearDefaultRoutes($defaultRoutes);
die(Tools::jsonEncode(array(
'success' => 1,
'defaultRoutes' => $defaultRoutes
)));
}
public function ajaxProcessResetRoutes()
{
$routesToDelete = array(
'PS_ROUTE_index_rule',
'PS_ROUTE_category_rule',
'PS_ROUTE_supplier_rule',
'PS_ROUTE_manufacturer_rule',
'PS_ROUTE_cms_rule',
'PS_ROUTE_cms_category_rule',
'PS_ROUTE_module',
'PS_ROUTE_product_rule',
'PS_ROUTE_layered_rule'
);
$deletedRoutes = array();
foreach ($routesToDelete as $route) {
if (Configuration::deleteByName($route)) {
$deletedRoutes[] = $route;
}
}
die(Tools::jsonEncode(array(
'success' => 1,
'deletedRoutes' => $deletedRoutes
)));
}
public function ajaxProcessReloadRoutes()
{
$urls = new ArSeoProUrls($this->module);
$urls->loadAllFromConfig();
$routes = array(
$urls->product->getRuleId() => $urls->product->getRouteRule(),
$urls->category->getRuleId() => $urls->category->getRouteRule(),
$urls->cms->getRuleId() => $urls->cms->getRouteRule(),
$urls->cmsCategory->getRuleId() => $urls->cmsCategory->getRouteRule(),
$urls->manufacturer->getRuleId() => $urls->manufacturer->getRouteRule(),
$urls->supplier->getRuleId() => $urls->supplier->getRouteRule(),
);
die(Tools::jsonEncode($routes));
}
public function ajaxProcessSave()
{
$data = Tools::getValue('data');
$id = Tools::getValue('id');
$errors = array();
if (!$id) {
$model = new ArSeoProRuleTable();
$model->status = 1;
} else {
$model = new ArSeoProRuleTable($id);
}
$name = null;
$rule = null;
$id_lang = null;
$id_category = 0;
$categories = array();
foreach ($data as $param) {
if ((isset($param['name'])) && $param['name'] == 'name') {
$name = trim($param['value']);
}
if ((isset($param['name'])) && $param['name'] == 'rule') {
$rule = trim($param['value']);
}
if ((isset($param['name'])) && $param['name'] == 'id_lang') {
$id_lang = $param['value'];
}
if ((isset($param['name'])) && $param['name'] == 'id_category') {
$id_category = $param['value'];
}
if ((isset($param['name'])) && $param['name'] == 'categoryBox[]') {
if ((int)$param['value'] > 0) {
$categories[] = $param['value'];
}
}
}
if ($id_category == 1 && empty($categories)) {
$errors['id_category'] = $this->l('Please select categories');
}
$model->name = $name? pSQL($name) : ArSeoProRuleTable::generateRuleName();
$model->rule = pSQL($rule);
$model->id_lang = (int)$id_lang;
$model->status = 1;
$model->id_shop = (int)Context::getContext()->shop->id;
$modelErrors = $model->validateFields(false, true);
if ($modelErrors !== true) {
$errors = array_merge($errors, $modelErrors);
}
if ($errors) {
die(Tools::jsonEncode(array(
'success' => 0,
'errors' => $errors
)));
}
$model->created_at = date('Y-m-d H:i:s');
if ($model->save()) {
$model->clearCategories();
if ($categories && ($id_category == 1)) {
foreach ($categories as $id_category) {
$model->addCategory((int)$id_category);
}
} else {
$model->addCategory(0);
}
}
die(Tools::jsonEncode(array(
'success' => 1,
'errors' => $errors,
'model' => $model,
'categories' => $categories
)));
}
public function ajaxProcessEdit()
{
$id = Tools::getValue('id');
$model = new ArSeoProRuleTable($id);
$categories = $model->getCategories(true);
$model->id_category = $categories? 1 : 0;
$model->categories = $categories;
die(Tools::jsonEncode($model));
}
public function ajaxProcessRemoveBulk()
{
$ids = $this->filterIdList(Tools::getValue('ids'));
$sql = 'DELETE FROM `' . ArSeoProRuleTable::getTableName() . '` WHERE id_rule IN (' . implode(', ', $ids) . ')';
$sql2 = 'DELETE FROM `' . ArSeoProRuleTable::getTableName(true) . '` WHERE id_rule IN (' . implode(', ', $ids) . ')';
die(Tools::jsonEncode(array(
'success' => Db::getInstance()->execute($sql2) && Db::getInstance()->execute($sql),
)));
}
public function ajaxProcessActivate()
{
$ids = $this->filterIdList(Tools::getValue('ids'));
$sql = 'UPDATE `' . ArSeoProRuleTable::getTableName() . '` SET `status` = 1 WHERE id_rule IN (' . implode(', ', $ids) . ')';
die(Tools::jsonEncode(array(
'success' => Db::getInstance()->execute($sql)
)));
}
public function ajaxProcessDeactivate()
{
$ids = $this->filterIdList(Tools::getValue('ids'));
$sql = 'UPDATE `' . ArSeoProRuleTable::getTableName() . '` SET `status` = 0 WHERE id_rule IN (' . implode(', ', $ids) . ')';
die(Tools::jsonEncode(array(
'success' => Db::getInstance()->execute($sql),
)));
}
public function displayEditLink($token, $id, $name)
{
return $this->module->render('_partials/_button.tpl', array(
'href' => '#',
'onclick' => 'arSEO.url.edit(' . $id . '); return false;',
'class' => '',
'target' => '',
'title' => $this->l('Edit'),
'icon' => 'icon-pencil'
));
}
public function displayEditItemLink($token, $id, $name)
{
return $this->module->render('_partials/_button.tpl', array(
'href' => '#',
'onclick' => 'arSEO.url.duplication.edit(\'' . $id . '\'); return false;',
'class' => '',
'target' => '',
'title' => $this->l('Edit'),
'icon' => 'icon-pencil'
));
}
public function displayDeleteLink($token, $id, $name)
{
return $this->module->render('_partials/_button.tpl', array(
'href' => '#',
'onclick' => 'arSEO.url.remove(' . $id . '); return false;',
'class' => '',
'target' => '',
'title' => $this->l('Delete'),
'icon' => 'icon-trash'
));
}
public function displayApplyLink($token, $id, $name)
{
return $this->module->render('_partials/_button.tpl', array(
'href' => '#',
'onclick' => 'arSEO.url.applyRule(' . $id . ', 0, 0, 0); return false;',
'class' => 'edit btn btn-default',
'target' => '',
'title' => $this->l('Apply'),
'icon' => 'icon-check'
));
}
public function langTableValue($cellValue, $row)
{
if (!$cellValue) {
return $this->l('All languages');
}
if ($lang = Language::getLanguage($cellValue)) {
return $lang['name'];
}
return null;
}
public function getLanguages()
{
$return = array(
0 => $this->l('All languages')
);
$langs = Language::getLanguages();
foreach ($langs as $lang) {
$return[$lang['id_lang']] = $lang['name'];
}
return $return;
}
public function renderDuplicates()
{
$context = Context::getContext();
$columns = array();
if (Shop::isFeatureActive()) {
$columns['shop'] = array(
'title' => $this->l('Shop'),
);
}
$columns['type'] = array(
'title' => $this->l('URL type'),
);
$columns['id_object'] = array(
'title' => $this->l('ID'),
);
$columns['name'] = array(
'title' => $this->l('Name'),
);
$columns['lang'] = array(
'title' => $this->l('Language'),
);
$columns['link_rewrite'] = array(
'title' => $this->l('Friendly URL'),
);
$helper = new ArSeoProListHelper();
$helper->list_id = 'url-duplication-list';
$helper->shopLinkType = '';
$helper->simple_header = true;
$helper->no_link = true;
$helper->identifier = 'id_arseopro';
$helper->actions = array('edititem');
$helper->show_toolbar = false;
$helper->imageType = 'jpg';
$helper->title[] = $this->l('Duplicate URLs');
$helper->table = 'arseopro';
$helper->module = $this;
$helper->token = Tools::getAdminTokenLite('AdminArSeoUrls');
$helper->currentIndex = AdminController::$currentIndex.'&configure='.$this->module->name;
$duplicates = array();
$urlConfig = $this->module->getUrlConfig();
$urlConfig->loadAllFromConfig();
if ($urlConfig->product->enable) {
$duplicates = array_merge($duplicates, $urlConfig->product->getDuplicates());
}
if ($urlConfig->category->enable) {
$duplicates = array_merge($duplicates, $urlConfig->category->getDuplicates());
}
if ($urlConfig->manufacturer->enable) {
$duplicates = array_merge($duplicates, $urlConfig->manufacturer->getDuplicates());
}
if ($urlConfig->supplier->enable) {
$duplicates = array_merge($duplicates, $urlConfig->supplier->getDuplicates());
}
if ($urlConfig->cms->enable) {
$duplicates = array_merge($duplicates, $urlConfig->cms->getDuplicates());
}
if ($urlConfig->cmsCategory->enable) {
$duplicates = array_merge($duplicates, $urlConfig->cmsCategory->getDuplicates());
}
return $helper->generateList($duplicates, $columns);
}
public function renderTable($params = array())
{
$pageSize = isset($params['selected_pagination'])? $params['selected_pagination'] : 20;
$helper = new ArSeoProListHelper();
$helper->title = $this->l('URL Rewrite Rules for products');
$helper->actions = array(
'apply', 'edit', 'delete'
);
$helper->list_id = 'url-list';
$helper->identifier = 'id_rule';
$helper->currentIndex = AdminController::$currentIndex.'&configure='.$this->module->name;
$helper->setPagination(array(20, 50, 100));
$totalCount = ArSeoProRuleTable::getCount($params);
if (isset($params['page'])) {
$totalPages = ceil($totalCount / $pageSize);
if ($params['page'] > $totalPages) {
$params['page'] = $totalPages;
}
}
$helper->listTotal = $totalCount;
$helper->currentPage = isset($params['page'])? $params['page'] : 1;
$helper->module = $this->module;
$helper->no_link = true;
$helper->setDefaultPagination($pageSize);
$helper->filters = isset($params['filter'])? $params['filter'] : array();
$helper->token = Tools::getAdminTokenLite('AdminArSeoUrls');
$helper->bulk_actions = array(
'delete' => array(
'text' => $this->l('Delete selected'),
'icon' => 'icon-trash',
'confirm' => $this->l('Delete selected items?'),
'js_action' => 'arSEO.url.bulk.remove(); return false'
),
'activate' => array(
'text' => $this->l('Activate selected'),
'icon' => 'icon-check',
'confirm' => $this->l('Activate selected items?'),
'js_action' => 'arSEO.url.bulk.activate(); return false'
),
'deactivate' => array(
'text' => $this->l('Deactivate selected'),
'icon' => 'icon-remove',
'confirm' => $this->l('Deactivate selected items?'),
'js_action' => 'arSEO.url.bulk.deactivate(); return false'
)
);
$list = ArSeoProRuleTable::getAll($params);
$columns = array(
'id_rule' => array(
'title' => $this->l('#'),
'filter_key' => 'id',
'orderby' => false,
),
'id_lang' => array(
'title' => $this->l('Language'),
'filter_key' => 'id_lang',
'orderby' => false,
'callback' => 'langTableValue',
'type' => 'select',
'list' => $this->getLanguages()
),
'name' => array(
'title' => $this->l('Name'),
'filter_key' => 'name',
'orderby' => false,
),
'rule' => array(
'title' => $this->l('Rewrite rule'),
'filter_key' => 'rule',
'orderby' => false
)
);
if (Shop::isFeatureActive()) {
$columns['id_shop'] = array(
'title' => $this->l('Shop'),
'filter_key' => 'id_shop',
'callback' => 'shopTableValue',
'type' => 'select',
'orderby' => false,
'list' => $this->getShopList(),
);
}
$columns['status'] = array(
'title' => $this->l('Status'),
'filter_key' => 'status',
'type' => 'bool',
'active' => 'enabled',
'ajax' => true,
'orderby' => false,
);
$columns['created_at'] = array(
'search' => false,
'title' => $this->l('Create date'),
'orderby' => false,
);
$columns['last_applied_at'] = array(
'search' => false,
'title' => $this->l('Last apply time'),
'orderby' => false,
);
return $helper->generateList($list, $columns);
}
public function ajaxProcessDuplicatesReload()
{
$params = $this->getParams('url-list');
die(Tools::jsonEncode(array(
'success' => 1,
'content' => $this->renderDuplicates($params)
)));
}
public function ajaxProcessReload()
{
$params = $this->getParams('url-list');
die(Tools::jsonEncode(array(
'success' => 1,
'content' => $this->renderTable($params)
)));
}
public function ajaxProcessDelete()
{
$id = Tools::getValue('id');
$model = new ArSeoProRuleTable($id);
$model->clearCategories();
die(Tools::jsonEncode(array(
'success' => $model->delete()
)));
}
public function ajaxProcessClear()
{
ArSeoProRuleTable::truncate();
die(Tools::jsonEncode(array(
'success' => 1
)));
}
public function ajaxProcessEnabledconfiguration()
{
$id = Tools::getValue('id_rule');
$model = new ArSeoProRuleTable($id);
$model->status = $model->status? 0 : 1;
die(Tools::jsonEncode(array(
'success' => $model->save(false),
'text' => $this->l('Status updated')
)));
}
public function ajaxProcessApplyRule()
{
$id = Tools::getValue('id');
$all = Tools::getValue('all');
$offset = (int)Tools::getValue('offset');
$total = (int)Tools::getValue('total');
$count = (int)Tools::getValue('count');
$pageSize = 50;
if ($all && $id == 0) {
$query = new DbQuery();
$query->from(ArSeoProRuleTable::TABLE_NAME);
$query->where('status = 1');
$query->orderBy('id_rule ASC');
if ($row = Db::getInstance()->getRow($query)) {
$id = $row['id_rule'];
} else {
die(Tools::jsonEncode(array(
'success' => 0,
'error' => $this->l('No rules to apply')
)));
}
}
$rule = new ArSeoProRuleTable($id);
if (!$total) {
$total = $rule->getRelatedProductsCount();
}
$products = $rule->getRelatedProductIds($pageSize, $offset);
$meta = array();
foreach ($products as $id_product) {
$meta[$id_product] = $this->module->generateProductRewrite($rule, $id_product);
}
$processed = $count + count($products);
if ($processed == $total) {
$rule->last_applied_at = date('Y-m-d H:i:s');
$rule->save(false);
}
$continue = $processed < $total? 1 : 0;
$nextRule = 0;
if ($all) {
$query = new DbQuery();
$query->from(ArSeoProRuleTable::TABLE_NAME);
$query->where('id_rule > ' . (int)$id . ' AND status = 1');
$query->orderBy('id_rule ASC');
if ($row = Db::getInstance()->getRow($query)) {
$nextRule = $row['id_rule'];
}
}
die(Tools::jsonEncode(array(
'success' => 1,
'id' => $id,
'total' => $total,
'count' => count($products),
'processed' => $processed,
'offset' => $offset + count($products),
'continue' => $continue,
'rule' => $rule,
'percent' => round($processed / $total * 100),
'meta' => $meta,
'products' => $products,
'nextRule' => $nextRule
)));
}
public function ajaxProcessApplyProductRules()
{
$id = Tools::getValue('id');
$params = array(
'object' => new Product($id, false, Context::getContext()->language->id)
);
$res = $this->module->hookActionObjectProductUpdateAfter($params);
die(Tools::jsonEncode(array(
'res' => $res
)));
}
public function ajaxProcessDuplicateSave()
{
$id = Tools::getValue('id');
$type = Tools::getValue('type');
$data = Tools::getValue('data');
$id_shop = 0;
$link_rewrite = array();
$name = null;
foreach ($data as $param) {
if (isset($param['name'])) {
if (Tools::strpos($param['name'], 'link_rewrite') !== false) {
$lang = str_replace('link_rewrite_', '', $param['name']);
$link_rewrite[$lang] = bqSQL($this->module->toLinkRewrite($param['value']));
}
if (Tools::strpos($param['name'], 'id_shop') !== false) {
$id_shop = (int)$param['value'];
}
if ($param['name'] == 'name') {
$name = pSQL($param['value']);
}
}
}
switch ($type) {
case 'product':
foreach ($link_rewrite as $id_lang => $value) {
$sql = 'UPDATE `' . _DB_PREFIX_ . "product_lang` SET `link_rewrite` = '" . pSQL($value) . "' WHERE id_lang = " . (int)$id_lang .
' AND id_product = ' . (int)$id;
if ($id_shop) {
$sql .= ' AND id_shop = ' . (int)$id_shop;
}
Db::getInstance()->execute($sql);
}
break;
case 'category':
foreach ($link_rewrite as $id_lang => $value) {
$sql = 'UPDATE `' . _DB_PREFIX_ . "category_lang` SET `link_rewrite` = '" . pSQL($value) . "' WHERE id_lang = " . (int)$id_lang .
' AND id_category = ' . (int)$id;
if ($id_shop) {
$sql .= ' AND id_shop = ' . (int)$id_shop;
}
Db::getInstance()->execute($sql);
}
break;
case 'cms':
foreach ($link_rewrite as $id_lang => $value) {
$sql = 'UPDATE `' . _DB_PREFIX_ . "cms_lang` SET `link_rewrite` = '" . pSQL($value) . "' WHERE id_lang = " . (int)$id_lang .
' AND id_cms = ' . (int)$id;
if ($id_shop) {
$sql .= ' AND id_shop = ' . (int)$id_shop;
}
Db::getInstance()->execute($sql);
}
break;
case 'cmscategory':
foreach ($link_rewrite as $id_lang => $value) {
$sql = 'UPDATE `' . _DB_PREFIX_ . "cms_category_lang` SET `link_rewrite` = '" . pSQL($value) . "' WHERE id_lang = " . (int)$id_lang .
' AND id_cms_category = ' . (int)$id;
if ($id_shop) {
$sql .= ' AND id_shop = ' . (int)$id_shop;
}
Db::getInstance()->execute($sql);
}
break;
case 'manufacturer':
$sql = 'UPDATE `' . _DB_PREFIX_ . "manufacturer` SET `name` = '" . pSQL($name) . "' WHERE id_manufacturer = " . (int)$id;
Db::getInstance()->execute($sql);
break;
case 'supplier':
$sql = 'UPDATE `' . _DB_PREFIX_ . "supplier` SET `name` = '" . pSQL($name) . "' WHERE id_supplier = " . (int)$id;
Db::getInstance()->execute($sql);
break;
}
die(Tools::jsonEncode(array(
'success' => 1,
'name' => $name,
'link_rewrite' => $link_rewrite
)));
}
public function ajaxProcessDuplicateEdit()
{
$id = Tools::getValue('id');
$data = explode('_', $id);
$type = $data[0];
$id = $data[1];
$field = 'link_rewrite';
switch ($type) {
case 'product':
$model = new Product($id);
break;
case 'category':
$model = new Category($id);
break;
case 'cms':
$model = new CMS($id);
break;
case 'cmscategory':
$model = new CMSCategory($id);
break;
case 'manufacturer':
$model = new Manufacturer($id);
$field = 'name';
break;
case 'supplier':
$model = new Supplier($id);
$field = 'name';
break;
}
die(Tools::jsonEncode(array(
$field => $model->$field,
'field' => $field,
'id' => $id,
'type' => $type,
)));
}
public function ajaxProcessDuplicateLinkRewrite()
{
$data = Tools::getValue('data');
$idLang = Tools::getValue('id_lang');
$link_rewrite = array();
foreach ($data as $param) {
if (isset($param['name'])) {
if (Tools::strpos($param['name'], 'link_rewrite') !== false) {
$lang = str_replace('link_rewrite_', '', $param['name']);
$link_rewrite[$lang] = bqSQL($this->module->toLinkRewrite($param['value']));
}
}
}
if (isset($link_rewrite[0]) && $link_rewrite[0] && $idLang == 0) {
foreach ($link_rewrite as $id_lang => $v) {
if ($id_lang != $idLang) {
$link_rewrite[$id_lang] = $link_rewrite[0];
}
}
}
die(Tools::jsonEncode(array(
'link_rewrite' => $link_rewrite
)));
}
}

View File

@@ -0,0 +1,31 @@
<?php
/*
* 2018 Areama
*
* 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@areama.net so we can send you a copy immediately.
*
*
* @author Areama <contact@areama.net>
* @copyright 2018 Areama
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of Areama
*/
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');
header('Cache-Control: no-store, no-cache, must-revalidate');
header('Cache-Control: post-check=0, pre-check=0', false);
header('Pragma: no-cache');
header('Location: ../../../');
exit;

View File

@@ -0,0 +1,121 @@
<?php
/**
* 2012-2018 Areama
*
* 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@areama.net so we can send you a copy immediately.
*
* @author Areama <contact@areama.net>
* @copyright 2018 Areama
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of Areama
*/
include_once dirname(__FILE__).'/../../classes/sitemap/ArSeoProSitemapGenerator.php';
/**
* @property ArSeoPro $module
*/
class ArSeoProAjaxModuleFrontController extends ModuleFrontController
{
public $ssl = true;
/**
* @see FrontController::initContent()
*/
public function initContent()
{
$time = microtime(true);
$id_shop = (int)Tools::getValue('id_shop');
$token = Tools::getValue('token');
if ($token != Configuration::get('ARSEO_SITEMAP_TOKEN', null, null, $id_shop)) {
die(Tools::jsonEncode(array(
'success' => 0,
'error' => $this->module->l('Wrong security token')
)));
}
$step = (int)Tools::getValue('step');
$totalCount = (int)Tools::getValue('totalCount');
$redirect = (int)Tools::getValue('redirect', 1);
$page = (int)Tools::getValue('page');
$generator = new ArSeoProSitemapGenerator($this->module, $id_shop);
$path = $this->module->getSitemapPath($id_shop);
if (!is_dir($path)) {
mkdir($path, 0777, true);
}
$generator->setPath($this->module->getSitemapPath($id_shop, false))->setIndexPath($this->module->getIndexSitemapPath(false));
if ($step == 0) {
$generator->clearSitemapDir();
$generator->generateAll();
} elseif ($step == 1) {
$generator->generateProducts($page);
}
$end = microtime(true);
$realCount = $generator->getRealCount();
$count = $generator->getCount();
$continue = ($step == 1 && $realCount['product'] != 0) || $step == 0;
$linkParams = http_build_query(array(
'page' => $step == 0? 0 : $page + 1,
'step' => 1,
'redirect' => $redirect? 1 : 0
));
if ($redirect) {
if ($continue) {
Tools::redirect($this->module->getSitemapCronUrl($id_shop) . '&' . $linkParams);
}
}
if (!$continue) {
$lastgen = time();
$generator->generateIndexSitemap();
Configuration::updateValue('ARSEO_SITEMAP_GEN', $time, false, null, $id_shop);
$config = new ArSeoProSitemapGeneral($this->module);
$config->loadFromConfig();
$ping = array();
if ($config->ping_google) {
$ping['google'] = 'https://www.google.com/webmasters/sitemaps/ping?sitemap=';
}
if ($config->ping_bing) {
$ping['bing'] = 'https://www.bing.com/webmaster/ping.aspx?siteMap=';
}
if ($config->ping_yandex) {
$ping['yandex'] = 'https://ping.blogs.yandex.ru/ping?sitemap=';
}
$pingRes = array();
if ($ping) {
$sitemapUrl = $generator->getIndexFileUrl($generator->getIndexFileName());
foreach ($ping as $k => $url) {
$url .= urlencode($sitemapUrl);
$pingRes[$k] = Tools::file_get_contents($url);
}
}
}
die(Tools::jsonEncode(array(
'success' => 1,
'id_shop' => $id_shop,
'time' => round($end - $time, 2),
'memory' => round(memory_get_peak_usage() / 1024 / 1024, 2),
'step' => 1,
'page' => $step == 0? 0 : $page + 1,
'nextUrl' => $continue? ($this->module->getSitemapCronUrl($id_shop) . '&' . $linkParams) : null,
'continue' => $continue? 1 : 0,
'count' => $count,
'realCount' => $realCount,
'lastgen' => isset($lastgen)? date('Y-m-d H:i:s', $lastgen) : null,
'totalCount' => $step == 0? $generator->getTotalCount() : $totalCount,
'ping' => isset($pingRes)? $pingRes : null,
'token' => $token
)));
}
}

View File

@@ -0,0 +1,31 @@
<?php
/*
* 2018 Areama
*
* 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@areama.net so we can send you a copy immediately.
*
*
* @author Areama <contact@areama.net>
* @copyright 2018 Areama
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of Areama
*/
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');
header('Cache-Control: no-store, no-cache, must-revalidate');
header('Cache-Control: post-check=0, pre-check=0', false);
header('Pragma: no-cache');
header('Location: ../../../');
exit;

View File

@@ -0,0 +1,31 @@
<?php
/*
* 2018 Areama
*
* 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@areama.net so we can send you a copy immediately.
*
*
* @author Areama <contact@areama.net>
* @copyright 2018 Areama
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of Areama
*/
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');
header('Cache-Control: no-store, no-cache, must-revalidate');
header('Cache-Control: post-check=0, pre-check=0', false);
header('Pragma: no-cache');
header('Location: ../../../');
exit;