Initial commit

This commit is contained in:
2019-11-20 07:44:43 +01:00
commit 5bf49c4a81
41188 changed files with 5459177 additions and 0 deletions

View File

@@ -0,0 +1,55 @@
<?php
/**
* 2007-2018 PrestaShop.
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 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:
* https://opensource.org/licenses/OSL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2018 PrestaShop SA
* @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
interface ITreeToolbarCore
{
public function __toString();
public function setActions($value);
public function getActions();
public function setContext($value);
public function getContext();
public function setData($value);
public function getData();
public function setTemplate($value);
public function getTemplate();
public function setTemplateDirectory($value);
public function getTemplateDirectory();
public function addAction($action);
public function removeActions();
public function render();
}

View File

@@ -0,0 +1,69 @@
<?php
/**
* 2007-2018 PrestaShop.
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 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:
* https://opensource.org/licenses/OSL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2018 PrestaShop SA
* @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
interface ITreeToolbarButtonCore
{
public function __toString();
public function setAttribute($name, $value);
public function getAttribute($name);
public function setAttributes($value);
public function getAttributes();
public function setClass($value);
public function getClass();
public function setContext($value);
public function getContext();
public function setId($value);
public function getId();
public function setLabel($value);
public function getLabel();
public function setName($value);
public function getName();
public function setTemplate($value);
public function getTemplate();
public function setTemplateDirectory($value);
public function getTemplateDirectory();
public function hasAttribute($name);
public function render();
}

511
web/classes/tree/Tree.php Normal file
View File

@@ -0,0 +1,511 @@
<?php
/**
* 2007-2018 PrestaShop.
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 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:
* https://opensource.org/licenses/OSL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2018 PrestaShop SA
* @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
class TreeCore
{
const DEFAULT_TEMPLATE_DIRECTORY = 'helpers/tree';
const DEFAULT_TEMPLATE = 'tree.tpl';
const DEFAULT_HEADER_TEMPLATE = 'tree_header.tpl';
const DEFAULT_NODE_FOLDER_TEMPLATE = 'tree_node_folder.tpl';
const DEFAULT_NODE_ITEM_TEMPLATE = 'tree_node_item.tpl';
protected $_attributes;
private $_context;
protected $_data;
protected $_data_search;
protected $_headerTemplate;
protected $_id_tree;
private $_id;
protected $_node_folder_template;
protected $_node_item_template;
protected $_template;
/** @var string */
private $_template_directory;
private $_title;
private $_no_js;
/** @var TreeToolbar|ITreeToolbar */
private $_toolbar;
public function __construct($id, $data = null)
{
$this->setId($id);
if (isset($data)) {
$this->setData($data);
}
}
public function __toString()
{
return $this->render();
}
public function setActions($value)
{
if (!isset($this->_toolbar)) {
$this->setToolbar(new TreeToolbarCore());
}
$this->getToolbar()->setTemplateDirectory($this->getTemplateDirectory())->setActions($value);
return $this;
}
public function getActions()
{
if (!isset($this->_toolbar)) {
$this->setToolbar(new TreeToolbarCore());
}
return $this->getToolbar()->setTemplateDirectory($this->getTemplateDirectory())->getActions();
}
public function setAttribute($name, $value)
{
if (!isset($this->_attributes)) {
$this->_attributes = array();
}
$this->_attributes[$name] = $value;
return $this;
}
public function getAttribute($name)
{
return $this->hasAttribute($name) ? $this->_attributes[$name] : null;
}
public function setAttributes($value)
{
if (!is_array($value) && !$value instanceof Traversable) {
throw new PrestaShopException('Data value must be an traversable array');
}
$this->_attributes = $value;
return $this;
}
public function setIdTree($id_tree)
{
$this->_id_tree = $id_tree;
return $this;
}
public function getIdTree()
{
return $this->_id_tree;
}
public function getAttributes()
{
if (!isset($this->_attributes)) {
$this->_attributes = array();
}
return $this->_attributes;
}
public function setContext($value)
{
$this->_context = $value;
return $this;
}
public function getContext()
{
if (!isset($this->_context)) {
$this->_context = Context::getContext();
}
return $this->_context;
}
public function setDataSearch($value)
{
if (!is_array($value) && !$value instanceof Traversable) {
throw new PrestaShopException('Data value must be an traversable array');
}
$this->_data_search = $value;
return $this;
}
public function getDataSearch()
{
if (!isset($this->_data_search)) {
$this->_data_search = array();
}
return $this->_data_search;
}
public function setData($value)
{
if (!is_array($value) && !$value instanceof Traversable) {
throw new PrestaShopException('Data value must be an traversable array');
}
$this->_data = $value;
return $this;
}
public function getData()
{
if (!isset($this->_data)) {
$this->_data = array();
}
return $this->_data;
}
public function setHeaderTemplate($value)
{
$this->_headerTemplate = $value;
return $this;
}
public function getHeaderTemplate()
{
if (!isset($this->_headerTemplate)) {
$this->setHeaderTemplate(self::DEFAULT_HEADER_TEMPLATE);
}
return $this->_headerTemplate;
}
public function setId($value)
{
$this->_id = $value;
return $this;
}
public function getId()
{
return $this->_id;
}
public function setNodeFolderTemplate($value)
{
$this->_node_folder_template = $value;
return $this;
}
public function getNodeFolderTemplate()
{
if (!isset($this->_node_folder_template)) {
$this->setNodeFolderTemplate(self::DEFAULT_NODE_FOLDER_TEMPLATE);
}
return $this->_node_folder_template;
}
public function setNodeItemTemplate($value)
{
$this->_node_item_template = $value;
return $this;
}
public function getNodeItemTemplate()
{
if (!isset($this->_node_item_template)) {
$this->setNodeItemTemplate(self::DEFAULT_NODE_ITEM_TEMPLATE);
}
return $this->_node_item_template;
}
public function setTemplate($value)
{
$this->_template = $value;
return $this;
}
public function getTemplate()
{
if (!isset($this->_template)) {
$this->setTemplate(self::DEFAULT_TEMPLATE);
}
return $this->_template;
}
/**
* @param $value
*
* @return Tree
*/
public function setTemplateDirectory($value)
{
$this->_template_directory = $this->_normalizeDirectory($value);
return $this;
}
/**
* @return string
*/
public function getTemplateDirectory()
{
if (!isset($this->_template_directory)) {
$this->_template_directory = $this->_normalizeDirectory(
self::DEFAULT_TEMPLATE_DIRECTORY);
}
return $this->_template_directory;
}
public function getTemplateFile($template)
{
if (preg_match_all('/((?:^|[A-Z])[a-z]+)/', get_class($this->getContext()->controller), $matches) !== false) {
$controller_name = strtolower($matches[0][1]);
}
if ($this->getContext()->controller instanceof ModuleAdminController && isset($controller_name) && file_exists($this->_normalizeDirectory(
$this->getContext()->controller->getTemplatePath()) . $controller_name . DIRECTORY_SEPARATOR . $this->getTemplateDirectory() . $template)) {
return $this->_normalizeDirectory($this->getContext()->controller->getTemplatePath()) .
$controller_name . DIRECTORY_SEPARATOR . $this->getTemplateDirectory() . $template;
} elseif ($this->getContext()->controller instanceof ModuleAdminController && file_exists($this->_normalizeDirectory(
$this->getContext()->controller->getTemplatePath()) . $this->getTemplateDirectory() . $template)) {
return $this->_normalizeDirectory($this->getContext()->controller->getTemplatePath())
. $this->getTemplateDirectory() . $template;
} elseif ($this->getContext()->controller instanceof AdminController && isset($controller_name)
&& file_exists($this->_normalizeDirectory($this->getContext()->smarty->getTemplateDir(0)) . 'controllers'
. DIRECTORY_SEPARATOR . $controller_name . DIRECTORY_SEPARATOR . $this->getTemplateDirectory() . $template)) {
return $this->_normalizeDirectory($this->getContext()->smarty->getTemplateDir(0)) . 'controllers'
. DIRECTORY_SEPARATOR . $controller_name . DIRECTORY_SEPARATOR . $this->getTemplateDirectory() . $template;
} elseif (file_exists($this->_normalizeDirectory($this->getContext()->smarty->getTemplateDir(1))
. $this->getTemplateDirectory() . $template)) {
return $this->_normalizeDirectory($this->getContext()->smarty->getTemplateDir(1))
. $this->getTemplateDirectory() . $template;
} elseif (file_exists($this->_normalizeDirectory($this->getContext()->smarty->getTemplateDir(0))
. $this->getTemplateDirectory() . $template)) {
return $this->_normalizeDirectory($this->getContext()->smarty->getTemplateDir(0))
. $this->getTemplateDirectory() . $template;
} else {
return $this->getTemplateDirectory() . $template;
}
}
public function setNoJS($value)
{
$this->_no_js = $value;
return $this;
}
public function setTitle($value)
{
$this->_title = $value;
return $this;
}
public function getTitle()
{
return $this->_title;
}
public function setToolbar($value)
{
if (!is_object($value)) {
throw new PrestaShopException('Toolbar must be a class object');
}
$reflection = new ReflectionClass($value);
if (!$reflection->implementsInterface('ITreeToolbarCore')) {
throw new PrestaShopException('Toolbar class must implements ITreeToolbarCore interface');
}
$this->_toolbar = $value;
return $this;
}
public function getToolbar()
{
if (isset($this->_toolbar)) {
if ($this->getDataSearch()) {
$this->_toolbar->setData($this->getDataSearch());
} else {
$this->_toolbar->setData($this->getData());
}
}
return $this->_toolbar;
}
public function addAction($action)
{
if (!isset($this->_toolbar)) {
$this->setToolbar(new TreeToolbarCore());
}
$this->getToolbar()->setTemplateDirectory($this->getTemplateDirectory())->addAction($action);
return $this;
}
public function removeActions()
{
if (!isset($this->_toolbar)) {
$this->setToolbar(new TreeToolbarCore());
}
$this->getToolbar()->setTemplateDirectory($this->getTemplateDirectory())->removeActions();
return $this;
}
public function render($data = null)
{
//Adding tree.js
$admin_webpath = str_ireplace(_PS_CORE_DIR_, '', _PS_ADMIN_DIR_);
$admin_webpath = preg_replace('/^' . preg_quote(DIRECTORY_SEPARATOR, '/') . '/', '', $admin_webpath);
$bo_theme = ((Validate::isLoadedObject($this->getContext()->employee)
&& $this->getContext()->employee->bo_theme) ? $this->getContext()->employee->bo_theme : 'default');
if (!file_exists(_PS_BO_ALL_THEMES_DIR_ . $bo_theme . DIRECTORY_SEPARATOR . 'template')) {
$bo_theme = 'default';
}
$js_path = __PS_BASE_URI__ . $admin_webpath . '/themes/' . $bo_theme . '/js/tree.js';
if ($this->getContext()->controller->ajax) {
if (!$this->_no_js) {
$html = '<script type="text/javascript" src="' . $js_path . '"></script>';
}
} else {
$this->getContext()->controller->addJs($js_path);
}
//Create Tree Template
$template = $this->getContext()->smarty->createTemplate(
$this->getTemplateFile($this->getTemplate()),
$this->getContext()->smarty
);
if (trim($this->getTitle()) != '' || $this->useToolbar()) {
//Create Tree Header Template
$headerTemplate = $this->getContext()->smarty->createTemplate(
$this->getTemplateFile($this->getHeaderTemplate()),
$this->getContext()->smarty
);
$headerTemplate->assign($this->getAttributes())
->assign(array(
'title' => $this->getTitle(),
'toolbar' => $this->useToolbar() ? $this->renderToolbar() : null,
)
);
$template->assign('header', $headerTemplate->fetch());
}
//Assign Tree nodes
$template->assign($this->getAttributes())->assign(array(
'id' => $this->getId(),
'nodes' => $this->renderNodes($data),
'id_tree' => $this->getIdTree(),
));
return (isset($html) ? $html : '') . $template->fetch();
}
public function renderNodes($data = null)
{
if (!isset($data)) {
$data = $this->getData();
}
if (!is_array($data) && !$data instanceof Traversable) {
throw new PrestaShopException('Data value must be an traversable array');
}
$html = '';
foreach ($data as $item) {
if (array_key_exists('children', $item)
&& !empty($item['children'])) {
$html .= $this->getContext()->smarty->createTemplate(
$this->getTemplateFile($this->getNodeFolderTemplate()),
$this->getContext()->smarty
)->assign(array(
'children' => $this->renderNodes($item['children']),
'node' => $item,
))->fetch();
} else {
$html .= $this->getContext()->smarty->createTemplate(
$this->getTemplateFile($this->getNodeItemTemplate()),
$this->getContext()->smarty
)->assign(array(
'node' => $item,
))->fetch();
}
}
return $html;
}
public function renderToolbar()
{
return $this->getToolbar()->render();
}
public function useInput()
{
return isset($this->_input_type);
}
public function useToolbar()
{
return isset($this->_toolbar);
}
private function _normalizeDirectory($directory)
{
$last = $directory[strlen($directory) - 1];
if (in_array($last, array('/', '\\'))) {
$directory[strlen($directory) - 1] = DIRECTORY_SEPARATOR;
return $directory;
}
$directory .= DIRECTORY_SEPARATOR;
return $directory;
}
}

View File

@@ -0,0 +1,221 @@
<?php
/**
* 2007-2018 PrestaShop.
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 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:
* https://opensource.org/licenses/OSL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2018 PrestaShop SA
* @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
class TreeToolbarCore implements ITreeToolbarCore
{
const DEFAULT_TEMPLATE_DIRECTORY = 'helpers/tree';
const DEFAULT_TEMPLATE = 'tree_toolbar.tpl';
private $_actions;
private $_context;
private $_data;
private $_template;
private $_template_directory;
public function __toString()
{
return $this->render();
}
public function setActions($actions)
{
if (!is_array($actions) && !$actions instanceof Traversable) {
throw new PrestaShopException('Action value must be an traversable array');
}
foreach ($actions as $action) {
$this->addAction($action);
}
}
public function getActions()
{
if (!isset($this->_actions)) {
$this->_actions = array();
}
return $this->_actions;
}
public function setContext($value)
{
$this->_context = $value;
return $this;
}
public function getContext()
{
if (!isset($this->_context)) {
$this->_context = Context::getContext();
}
return $this->_context;
}
public function setData($value)
{
if (!is_array($value) && !$value instanceof Traversable) {
throw new PrestaShopException('Data value must be an traversable array');
}
$this->_data = $value;
return $this;
}
public function getData()
{
return $this->_data;
}
public function setTemplate($value)
{
$this->_template = $value;
return $this;
}
public function getTemplate()
{
if (!isset($this->_template)) {
$this->setTemplate(self::DEFAULT_TEMPLATE);
}
return $this->_template;
}
public function setTemplateDirectory($value)
{
$this->_template_directory = $this->_normalizeDirectory($value);
return $this;
}
public function getTemplateDirectory()
{
if (!isset($this->_template_directory)) {
$this->_template_directory = $this->_normalizeDirectory(
self::DEFAULT_TEMPLATE_DIRECTORY);
}
return $this->_template_directory;
}
public function getTemplateFile($template)
{
if (preg_match_all('/((?:^|[A-Z])[a-z]+)/', get_class($this->getContext()->controller), $matches) !== false) {
$controllerName = strtolower($matches[0][1]);
}
if ($this->getContext()->controller instanceof ModuleAdminController && file_exists($this->_normalizeDirectory(
$this->getContext()->controller->getTemplatePath()) . $this->getTemplateDirectory() . $template)) {
return $this->_normalizeDirectory($this->getContext()->controller->getTemplatePath())
. $this->getTemplateDirectory() . $template;
} elseif ($this->getContext()->controller instanceof AdminController && isset($controllerName)
&& file_exists($this->_normalizeDirectory($this->getContext()->smarty->getTemplateDir(0)) . 'controllers'
. DIRECTORY_SEPARATOR . $controllerName . DIRECTORY_SEPARATOR . $this->getTemplateDirectory() . $template)) {
return $this->_normalizeDirectory($this->getContext()->smarty->getTemplateDir(0)) . 'controllers'
. DIRECTORY_SEPARATOR . $controllerName . DIRECTORY_SEPARATOR . $this->getTemplateDirectory() . $template;
} elseif (file_exists($this->_normalizeDirectory($this->getContext()->smarty->getTemplateDir(1))
. $this->getTemplateDirectory() . $template)) {
return $this->_normalizeDirectory($this->getContext()->smarty->getTemplateDir(1))
. $this->getTemplateDirectory() . $template;
} elseif (file_exists($this->_normalizeDirectory($this->getContext()->smarty->getTemplateDir(0))
. $this->getTemplateDirectory() . $template)) {
return $this->_normalizeDirectory($this->getContext()->smarty->getTemplateDir(0))
. $this->getTemplateDirectory() . $template;
} else {
return $this->getTemplateDirectory() . $template;
}
}
/**
* @param ITreeToolbarButton $action
*
* @return TreeToolbar
*
* @throws PrestaShopException
*/
public function addAction($action)
{
if (!is_object($action)) {
throw new PrestaShopException('Action must be a class object');
}
$reflection = new ReflectionClass($action);
if (!$reflection->implementsInterface('ITreeToolbarButtonCore')) {
throw new PrestaShopException('Action class must implements ITreeToolbarButtonCore interface');
}
if (!isset($this->_actions)) {
$this->_actions = array();
}
if (isset($this->_template_directory)) {
$action->setTemplateDirectory($this->getTemplateDirectory());
}
$this->_actions[] = $action;
return $this;
}
public function removeActions()
{
$this->_actions = null;
return $this;
}
public function render()
{
foreach ($this->getActions() as $action) {
/* @var ITreeToolbarButton $action */
$action->setAttribute('data', $this->getData());
}
return $this->getContext()->smarty->createTemplate(
$this->getTemplateFile($this->getTemplate()),
$this->getContext()->smarty
)->assign('actions', $this->getActions())->fetch();
}
private function _normalizeDirectory($directory)
{
$last = $directory[strlen($directory) - 1];
if (in_array($last, array('/', '\\'))) {
$directory[strlen($directory) - 1] = DIRECTORY_SEPARATOR;
return $directory;
}
$directory .= DIRECTORY_SEPARATOR;
return $directory;
}
}

View File

@@ -0,0 +1,224 @@
<?php
/**
* 2007-2018 PrestaShop.
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 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:
* https://opensource.org/licenses/OSL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2018 PrestaShop SA
* @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
abstract class TreeToolbarButtonCore
{
const DEFAULT_TEMPLATE_DIRECTORY = 'helpers/tree';
protected $_attributes;
private $_context;
protected $_template;
protected $_template_directory;
public function __construct($label, $id = null, $name = null, $class = null)
{
$this->setLabel($label);
$this->setId($id);
$this->setName($name);
$this->setClass($class);
}
public function __toString()
{
return $this->render();
}
public function setAttribute($name, $value)
{
if (!isset($this->_attributes)) {
$this->_attributes = array();
}
$this->_attributes[$name] = $value;
return $this;
}
public function getAttribute($name)
{
return $this->hasAttribute($name) ? $this->_attributes[$name] : null;
}
public function setAttributes($value)
{
if (!is_array($value) && !$value instanceof Traversable) {
throw new PrestaShopException('Data value must be an traversable array');
}
$this->_attributes = $value;
return $this;
}
public function getAttributes()
{
if (!isset($this->_attributes)) {
$this->_attributes = array();
}
return $this->_attributes;
}
public function setClass($value)
{
return $this->setAttribute('class', $value);
}
public function getClass()
{
return $this->getAttribute('class');
}
public function setContext($value)
{
$this->_context = $value;
return $this;
}
public function getContext()
{
if (!isset($this->_context)) {
$this->_context = Context::getContext();
}
return $this->_context;
}
public function setId($value)
{
return $this->setAttribute('id', $value);
}
public function getId()
{
return $this->getAttribute('id');
}
public function setLabel($value)
{
return $this->setAttribute('label', $value);
}
public function getLabel()
{
return $this->getAttribute('label');
}
public function setName($value)
{
return $this->setAttribute('name', $value);
}
public function getName()
{
return $this->getAttribute('name');
}
public function setTemplate($value)
{
$this->_template = $value;
return $this;
}
public function getTemplate()
{
return $this->_template;
}
public function setTemplateDirectory($value)
{
$this->_template_directory = $this->_normalizeDirectory($value);
return $this;
}
public function getTemplateDirectory()
{
if (!isset($this->_template_directory)) {
$this->_template_directory = $this->_normalizeDirectory(self::DEFAULT_TEMPLATE_DIRECTORY);
}
return $this->_template_directory;
}
public function getTemplateFile($template)
{
if (preg_match_all('/((?:^|[A-Z])[a-z]+)/', get_class($this->getContext()->controller), $matches) !== false) {
$controllerName = strtolower($matches[0][1]);
}
if ($this->getContext()->controller instanceof ModuleAdminController && file_exists($this->_normalizeDirectory(
$this->getContext()->controller->getTemplatePath()) . $this->getTemplateDirectory() . $template)) {
return $this->_normalizeDirectory($this->getContext()->controller->getTemplatePath())
. $this->getTemplateDirectory() . $template;
} elseif ($this->getContext()->controller instanceof AdminController && isset($controllerName)
&& file_exists($this->_normalizeDirectory($this->getContext()->smarty->getTemplateDir(0)) . 'controllers'
. DIRECTORY_SEPARATOR . $controllerName . DIRECTORY_SEPARATOR . $this->getTemplateDirectory() . $template)) {
return $this->_normalizeDirectory($this->getContext()->smarty->getTemplateDir(0)) . 'controllers'
. DIRECTORY_SEPARATOR . $controllerName . DIRECTORY_SEPARATOR . $this->getTemplateDirectory() . $template;
} elseif (file_exists($this->_normalizeDirectory($this->getContext()->smarty->getTemplateDir(1))
. $this->getTemplateDirectory() . $template)) {
return $this->_normalizeDirectory($this->getContext()->smarty->getTemplateDir(1))
. $this->getTemplateDirectory() . $template;
} elseif (file_exists($this->_normalizeDirectory($this->getContext()->smarty->getTemplateDir(0))
. $this->getTemplateDirectory() . $template)) {
return $this->_normalizeDirectory($this->getContext()->smarty->getTemplateDir(0))
. $this->getTemplateDirectory() . $template;
} else {
return $this->getTemplateDirectory() . $template;
}
}
public function hasAttribute($name)
{
return isset($this->_attributes)
&& array_key_exists($name, $this->_attributes);
}
public function render()
{
return $this->getContext()->smarty->createTemplate(
$this->getTemplateFile($this->getTemplate()),
$this->getContext()->smarty
)->assign($this->getAttributes())->fetch();
}
private function _normalizeDirectory($directory)
{
$last = $directory[strlen($directory) - 1];
if (in_array($last, array('/', '\\'))) {
$directory[strlen($directory) - 1] = DIRECTORY_SEPARATOR;
return $directory;
}
$directory .= DIRECTORY_SEPARATOR;
return $directory;
}
}

View File

@@ -0,0 +1,68 @@
<?php
/**
* 2007-2018 PrestaShop.
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 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:
* https://opensource.org/licenses/OSL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2018 PrestaShop SA
* @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
class TreeToolbarLinkCore extends TreeToolbarButtonCore implements ITreeToolbarButtonCore
{
protected $_template = 'tree_toolbar_link.tpl';
public function __construct($label, $link, $action = null, $iconClass = null)
{
parent::__construct($label);
$this->setLink($link);
$this->setAction($action);
$this->setIconClass($iconClass);
}
public function setAction($value)
{
return $this->setAttribute('action', $value);
}
public function getAction()
{
return $this->getAttribute('action');
}
public function setIconClass($value)
{
return $this->setAttribute('icon_class', $value);
}
public function getIconClass()
{
return $this->getAttribute('icon_class');
}
public function setLink($value)
{
return $this->setAttribute('link', $value);
}
public function getLink()
{
return $this->getAttribute('link');
}
}

View File

@@ -0,0 +1,84 @@
<?php
/**
* 2007-2018 PrestaShop.
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 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:
* https://opensource.org/licenses/OSL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2018 PrestaShop SA
* @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
class TreeToolbarSearchCore extends TreeToolbarButtonCore implements ITreeToolbarButtonCore
{
protected $_template = 'tree_toolbar_search.tpl';
public function __construct($label, $id, $name = null, $class = null)
{
parent::__construct($label);
$this->setId($id);
$this->setName($name);
$this->setClass($class);
}
public function render()
{
if ($this->hasAttribute('data_search')) {
$this->setAttribute('typeahead_source',
$this->_renderData($this->getAttribute('data_search')));
} elseif ($this->hasAttribute('data')) {
$this->setAttribute('typeahead_source',
$this->_renderData($this->getAttribute('data')));
}
$admin_webpath = str_ireplace(_PS_CORE_DIR_, '', _PS_ADMIN_DIR_);
$admin_webpath = preg_replace('/^' . preg_quote(DIRECTORY_SEPARATOR, '/') . '/', '', $admin_webpath);
$bo_theme = ((Validate::isLoadedObject($this->getContext()->employee)
&& $this->getContext()->employee->bo_theme) ? $this->getContext()->employee->bo_theme : 'default');
if (!file_exists(_PS_BO_ALL_THEMES_DIR_ . $bo_theme . DIRECTORY_SEPARATOR . 'template')) {
$bo_theme = 'default';
}
if ($this->getContext()->controller->ajax) {
$html = '<script type="text/javascript" src="' . __PS_BASE_URI__ . $admin_webpath . '/themes/' . $bo_theme . '/js/vendor/typeahead.min.js"></script>';
} else {
$this->getContext()->controller->addJs(__PS_BASE_URI__ . $admin_webpath . '/themes/' . $bo_theme . '/js/vendor/typeahead.min.js');
}
return (isset($html) ? $html : '') . parent::render();
}
private function _renderData($data)
{
if (!is_array($data) && !$data instanceof Traversable) {
throw new PrestaShopException('Data value must be a traversable array');
}
$html = '';
foreach ($data as $item) {
$html .= json_encode($item) . ',';
if (array_key_exists('children', $item) && !empty($item['children'])) {
$html .= $this->_renderData($item['children']);
}
}
return $html;
}
}

View File

@@ -0,0 +1,81 @@
<?php
/**
* 2007-2018 PrestaShop.
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 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:
* https://opensource.org/licenses/OSL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2018 PrestaShop SA
* @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
class TreeToolbarSearchCategoriesCore extends TreeToolbarButtonCore implements ITreeToolbarButtonCore
{
protected $_template = 'tree_toolbar_search.tpl';
public function __construct($label, $id, $name = null, $class = null)
{
parent::__construct($label);
$this->setId($id);
$this->setName($name);
$this->setClass($class);
}
public function render()
{
if ($this->hasAttribute('data')) {
$this->setAttribute('typeahead_source',
$this->_renderData($this->getAttribute('data')));
}
$admin_webpath = str_ireplace(_PS_CORE_DIR_, '', _PS_ADMIN_DIR_);
$admin_webpath = preg_replace('/^' . preg_quote(DIRECTORY_SEPARATOR, '/') . '/', '', $admin_webpath);
$bo_theme = ((Validate::isLoadedObject($this->getContext()->employee)
&& $this->getContext()->employee->bo_theme) ? $this->getContext()->employee->bo_theme : 'default');
if (!file_exists(_PS_BO_ALL_THEMES_DIR_ . $bo_theme . DIRECTORY_SEPARATOR . 'template')) {
$bo_theme = 'default';
}
if ($this->getContext()->controller->ajax) {
$html = '<script type="text/javascript" src="' . __PS_BASE_URI__ . $admin_webpath . '/themes/' . $bo_theme . '/js/vendor/typeahead.min.js"></script>';
} else {
$this->getContext()->controller->addJs(__PS_BASE_URI__ . $admin_webpath . '/themes/' . $bo_theme . '/js/vendor/typeahead.min.js');
}
return (isset($html) ? $html : '') . parent::render();
}
private function _renderData($data)
{
if (!is_array($data) && !$data instanceof Traversable) {
throw new PrestaShopException('Data value must be a traversable array');
}
$html = '';
foreach ($data as $item) {
$html .= json_encode($item) . ',';
if (array_key_exists('children', $item) && !empty($item['children'])) {
$html .= $this->_renderData($item['children']);
}
}
return $html;
}
}

View File

@@ -0,0 +1,34 @@
<?php
/**
* 2007-2018 PrestaShop.
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 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:
* https://opensource.org/licenses/OSL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2018 PrestaShop SA
* @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
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;