first commit

This commit is contained in:
sujan
2024-08-06 18:06:00 +05:45
commit a2fa49071a
2745 changed files with 391199 additions and 0 deletions

View File

@ -0,0 +1,344 @@
<?php
namespace Opencart\Admin\Controller\Design;
/**
* Class Banner
*
* @package Opencart\Admin\Controller\Design
*/
class Banner extends \Opencart\System\Engine\Controller {
/**
* @return void
*/
public function index(): void {
$this->load->language('design/banner');
$this->document->setTitle($this->language->get('heading_title'));
$url = '';
if (isset($this->request->get['sort'])) {
$url .= '&sort=' . $this->request->get['sort'];
}
if (isset($this->request->get['order'])) {
$url .= '&order=' . $this->request->get['order'];
}
if (isset($this->request->get['page'])) {
$url .= '&page=' . $this->request->get['page'];
}
$data['breadcrumbs'] = [];
$data['breadcrumbs'][] = [
'text' => $this->language->get('text_home'),
'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'])
];
$data['breadcrumbs'][] = [
'text' => $this->language->get('heading_title'),
'href' => $this->url->link('design/banner', 'user_token=' . $this->session->data['user_token'] . $url)
];
$data['add'] = $this->url->link('design/banner.form', 'user_token=' . $this->session->data['user_token'] . $url);
$data['delete'] = $this->url->link('design/banner.delete', 'user_token=' . $this->session->data['user_token']);
$data['list'] = $this->getList();
$data['user_token'] = $this->session->data['user_token'];
$data['header'] = $this->load->controller('common/header');
$data['column_left'] = $this->load->controller('common/column_left');
$data['footer'] = $this->load->controller('common/footer');
$this->response->setOutput($this->load->view('design/banner', $data));
}
/**
* @return void
*/
public function list(): void {
$this->load->language('design/banner');
$this->response->setOutput($this->getList());
}
/**
* @return string
*/
protected function getList(): string {
if (isset($this->request->get['sort'])) {
$sort = (string)$this->request->get['sort'];
} else {
$sort = 'name';
}
if (isset($this->request->get['order'])) {
$order = (string)$this->request->get['order'];
} else {
$order = 'ASC';
}
if (isset($this->request->get['page'])) {
$page = (int)$this->request->get['page'];
} else {
$page = 1;
}
$url = '';
if (isset($this->request->get['sort'])) {
$url .= '&sort=' . $this->request->get['sort'];
}
if (isset($this->request->get['order'])) {
$url .= '&order=' . $this->request->get['order'];
}
if (isset($this->request->get['page'])) {
$url .= '&page=' . $this->request->get['page'];
}
$data['action'] = $this->url->link('design/banner.list', 'user_token=' . $this->session->data['user_token'] . $url);
$data['banners'] = [];
$filter_data = [
'sort' => $sort,
'order' => $order,
'start' => ($page - 1) * $this->config->get('config_pagination_admin'),
'limit' => $this->config->get('config_pagination_admin')
];
$this->load->model('design/banner');
$banner_total = $this->model_design_banner->getTotalBanners();
$results = $this->model_design_banner->getBanners($filter_data);
foreach ($results as $result) {
$data['banners'][] = [
'banner_id' => $result['banner_id'],
'name' => $result['name'],
'status' => $result['status'],
'edit' => $this->url->link('design/banner.form', 'user_token=' . $this->session->data['user_token'] . '&banner_id=' . $result['banner_id'] . $url)
];
}
$url = '';
if ($order == 'ASC') {
$url .= '&order=DESC';
} else {
$url .= '&order=ASC';
}
$data['sort_name'] = $this->url->link('design/banner.list', 'user_token=' . $this->session->data['user_token'] . '&sort=name' . $url);
$url = '';
if (isset($this->request->get['sort'])) {
$url .= '&sort=' . $this->request->get['sort'];
}
if (isset($this->request->get['order'])) {
$url .= '&order=' . $this->request->get['order'];
}
$data['pagination'] = $this->load->controller('common/pagination', [
'total' => $banner_total,
'page' => $page,
'limit' => $this->config->get('config_pagination_admin'),
'url' => $this->url->link('design/banner.list', 'user_token=' . $this->session->data['user_token'] . $url . '&page={page}')
]);
$data['results'] = sprintf($this->language->get('text_pagination'), ($banner_total) ? (($page - 1) * $this->config->get('config_pagination_admin')) + 1 : 0, ((($page - 1) * $this->config->get('config_pagination_admin')) > ($banner_total - $this->config->get('config_pagination_admin'))) ? $banner_total : ((($page - 1) * $this->config->get('config_pagination_admin')) + $this->config->get('config_pagination_admin')), $banner_total, ceil($banner_total / $this->config->get('config_pagination_admin')));
$data['sort'] = $sort;
$data['order'] = $order;
return $this->load->view('design/banner_list', $data);
}
/**
* @return void
*/
public function form(): void {
$this->load->language('design/banner');
$this->document->setTitle($this->language->get('heading_title'));
$data['text_form'] = !isset($this->request->get['banner_id']) ? $this->language->get('text_add') : $this->language->get('text_edit');
$url = '';
if (isset($this->request->get['sort'])) {
$url .= '&sort=' . $this->request->get['sort'];
}
if (isset($this->request->get['order'])) {
$url .= '&order=' . $this->request->get['order'];
}
if (isset($this->request->get['page'])) {
$url .= '&page=' . $this->request->get['page'];
}
$data['breadcrumbs'] = [];
$data['breadcrumbs'][] = [
'text' => $this->language->get('text_home'),
'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'])
];
$data['breadcrumbs'][] = [
'text' => $this->language->get('heading_title'),
'href' => $this->url->link('design/banner', 'user_token=' . $this->session->data['user_token'] . $url)
];
$data['save'] = $this->url->link('design/banner.save', 'user_token=' . $this->session->data['user_token']);
$data['back'] = $this->url->link('design/banner', 'user_token=' . $this->session->data['user_token'] . $url);
if (isset($this->request->get['banner_id'])) {
$this->load->model('design/banner');
$banner_info = $this->model_design_banner->getBanner($this->request->get['banner_id']);
}
if (isset($this->request->get['banner_id'])) {
$data['banner_id'] = (int)$this->request->get['banner_id'];
} else {
$data['banner_id'] = 0;
}
if (!empty($banner_info)) {
$data['name'] = $banner_info['name'];
} else {
$data['name'] = '';
}
if (!empty($banner_info)) {
$data['status'] = $banner_info['status'];
} else {
$data['status'] = true;
}
$this->load->model('localisation/language');
$data['languages'] = $this->model_localisation_language->getLanguages();
$this->load->model('tool/image');
if (!empty($banner_info)) {
$banner_images = $this->model_design_banner->getImages($this->request->get['banner_id']);
} else {
$banner_images = [];
}
$data['banner_images'] = [];
foreach ($banner_images as $language_id => $banner_image) {
foreach ($banner_image as $value) {
if (is_file(DIR_IMAGE . html_entity_decode($value['image'], ENT_QUOTES, 'UTF-8'))) {
$image = $value['image'];
$thumb = $value['image'];
} else {
$image = '';
$thumb = 'no_image.png';
}
$data['banner_images'][$language_id][] = [
'title' => $value['title'],
'link' => $value['link'],
'image' => $image,
'thumb' => $this->model_tool_image->resize(html_entity_decode($thumb, ENT_QUOTES, 'UTF-8'), 100, 100),
'sort_order' => $value['sort_order']
];
}
}
$data['placeholder'] = $this->model_tool_image->resize('no_image.png', 100, 100);
$data['user_token'] = $this->session->data['user_token'];
$data['header'] = $this->load->controller('common/header');
$data['column_left'] = $this->load->controller('common/column_left');
$data['footer'] = $this->load->controller('common/footer');
$this->response->setOutput($this->load->view('design/banner_form', $data));
}
/**
* @return void
*/
public function save(): void {
$this->load->language('design/banner');
$json = [];
if (!$this->user->hasPermission('modify', 'design/banner')) {
$json['error']['warning'] = $this->language->get('error_permission');
}
if ((oc_strlen($this->request->post['name']) < 3) || (oc_strlen($this->request->post['name']) > 64)) {
$json['error']['name'] = $this->language->get('error_name');
}
if (isset($this->request->post['banner_image'])) {
foreach ($this->request->post['banner_image'] as $language_id => $banner_image) {
foreach ($banner_image as $key => $value) {
if ((oc_strlen(trim($value['title'])) < 2) || (oc_strlen($value['title']) > 64)) {
$json['error']['image_' . $language_id . '_' . $key . '_title'] = $this->language->get('error_title');
}
}
}
}
if (!$json) {
$this->load->model('design/banner');
if (!$this->request->post['banner_id']) {
$json['banner_id'] = $this->model_design_banner->addBanner($this->request->post);
} else {
$this->model_design_banner->editBanner($this->request->post['banner_id'], $this->request->post);
}
$json['success'] = $this->language->get('text_success');
}
$this->response->addHeader('Content-Type: application/json');
$this->response->setOutput(json_encode($json));
}
/**
* @return void
*/
public function delete(): void {
$this->load->language('design/banner');
$json = [];
if (isset($this->request->post['selected'])) {
$selected = $this->request->post['selected'];
} else {
$selected = [];
}
if (!$this->user->hasPermission('modify', 'design/banner')) {
$json['error'] = $this->language->get('error_permission');
}
if (!$json) {
$this->load->model('design/banner');
foreach ($selected as $banner_id) {
$this->model_design_banner->deleteBanner($banner_id);
}
$json['success'] = $this->language->get('text_success');
}
$this->response->addHeader('Content-Type: application/json');
$this->response->setOutput(json_encode($json));
}
}

View File

@ -0,0 +1,410 @@
<?php
namespace Opencart\Admin\Controller\Design;
/**
* Class Layout
*
* @package Opencart\Admin\Controller\Design
*/
class Layout extends \Opencart\System\Engine\Controller {
/**
* @return void
*/
public function index(): void {
$this->load->language('design/layout');
$this->document->setTitle($this->language->get('heading_title'));
$url = '';
if (isset($this->request->get['sort'])) {
$url .= '&sort=' . $this->request->get['sort'];
}
if (isset($this->request->get['order'])) {
$url .= '&order=' . $this->request->get['order'];
}
if (isset($this->request->get['page'])) {
$url .= '&page=' . $this->request->get['page'];
}
$data['breadcrumbs'] = [];
$data['breadcrumbs'][] = [
'text' => $this->language->get('text_home'),
'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'])
];
$data['breadcrumbs'][] = [
'text' => $this->language->get('heading_title'),
'href' => $this->url->link('design/layout', 'user_token=' . $this->session->data['user_token'] . $url)
];
$data['add'] = $this->url->link('design/layout.form', 'user_token=' . $this->session->data['user_token'] . $url);
$data['delete'] = $this->url->link('design/layout.delete', 'user_token=' . $this->session->data['user_token']);
$data['list'] = $this->getList();
$data['user_token'] = $this->session->data['user_token'];
$data['header'] = $this->load->controller('common/header');
$data['column_left'] = $this->load->controller('common/column_left');
$data['footer'] = $this->load->controller('common/footer');
$this->response->setOutput($this->load->view('design/layout', $data));
}
/**
* @return void
*/
public function list(): void {
$this->load->language('design/layout');
$this->response->setOutput($this->getList());
}
/**
* @return string
*/
protected function getList(): string {
if (isset($this->request->get['sort'])) {
$sort = (string)$this->request->get['sort'];
} else {
$sort = 'name';
}
if (isset($this->request->get['order'])) {
$order = (string)$this->request->get['order'];
} else {
$order = 'ASC';
}
if (isset($this->request->get['page'])) {
$page = (int)$this->request->get['page'];
} else {
$page = 1;
}
$url = '';
if (isset($this->request->get['sort'])) {
$url .= '&sort=' . $this->request->get['sort'];
}
if (isset($this->request->get['order'])) {
$url .= '&order=' . $this->request->get['order'];
}
if (isset($this->request->get['page'])) {
$url .= '&page=' . $this->request->get['page'];
}
$data['action'] = $this->url->link('design/layout.list', 'user_token=' . $this->session->data['user_token'] . $url);
$data['layouts'] = [];
$filter_data = [
'sort' => $sort,
'order' => $order,
'start' => ($page - 1) * $this->config->get('config_pagination_admin'),
'limit' => $this->config->get('config_pagination_admin')
];
$this->load->model('design/layout');
$layout_total = $this->model_design_layout->getTotalLayouts();
$results = $this->model_design_layout->getLayouts($filter_data);
foreach ($results as $result) {
$data['layouts'][] = [
'layout_id' => $result['layout_id'],
'name' => $result['name'],
'edit' => $this->url->link('design/layout.form', 'user_token=' . $this->session->data['user_token'] . '&layout_id=' . $result['layout_id'] . $url)
];
}
$url = '';
if ($order == 'ASC') {
$url .= '&order=DESC';
} else {
$url .= '&order=ASC';
}
$data['sort_name'] = $this->url->link('design/layout.list', 'user_token=' . $this->session->data['user_token'] . '&sort=name' . $url);
$url = '';
if (isset($this->request->get['sort'])) {
$url .= '&sort=' . $this->request->get['sort'];
}
if (isset($this->request->get['order'])) {
$url .= '&order=' . $this->request->get['order'];
}
$data['pagination'] = $this->load->controller('common/pagination', [
'total' => $layout_total,
'page' => $page,
'limit' => $this->config->get('config_pagination_admin'),
'url' => $this->url->link('design/layout.list', 'user_token=' . $this->session->data['user_token'] . $url . '&page={page}')
]);
$data['results'] = sprintf($this->language->get('text_pagination'), ($layout_total) ? (($page - 1) * $this->config->get('config_pagination_admin')) + 1 : 0, ((($page - 1) * $this->config->get('config_pagination_admin')) > ($layout_total - $this->config->get('config_pagination_admin'))) ? $layout_total : ((($page - 1) * $this->config->get('config_pagination_admin')) + $this->config->get('config_pagination_admin')), $layout_total, ceil($layout_total / $this->config->get('config_pagination_admin')));
$data['sort'] = $sort;
$data['order'] = $order;
return $this->load->view('design/layout_list', $data);
}
/**
* @return void
*/
public function form(): void {
$this->load->language('design/layout');
$this->document->setTitle($this->language->get('heading_title'));
$data['text_form'] = !isset($this->request->get['layout_id']) ? $this->language->get('text_add') : $this->language->get('text_edit');
$url = '';
if (isset($this->request->get['sort'])) {
$url .= '&sort=' . $this->request->get['sort'];
}
if (isset($this->request->get['order'])) {
$url .= '&order=' . $this->request->get['order'];
}
if (isset($this->request->get['page'])) {
$url .= '&page=' . $this->request->get['page'];
}
$data['breadcrumbs'] = [];
$data['breadcrumbs'][] = [
'text' => $this->language->get('text_home'),
'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'])
];
$data['breadcrumbs'][] = [
'text' => $this->language->get('heading_title'),
'href' => $this->url->link('design/layout', 'user_token=' . $this->session->data['user_token'] . $url)
];
$data['save'] = $this->url->link('design/layout.save', 'user_token=' . $this->session->data['user_token']);
$data['back'] = $this->url->link('design/layout', 'user_token=' . $this->session->data['user_token'] . $url);
if (isset($this->request->get['layout_id'])) {
$this->load->model('design/layout');
$layout_info = $this->model_design_layout->getLayout($this->request->get['layout_id']);
}
if (isset($this->request->get['layout_id'])) {
$data['layout_id'] = (int)$this->request->get['layout_id'];
} else {
$data['layout_id'] = 0;
}
if (!empty($layout_info)) {
$data['name'] = $layout_info['name'];
} else {
$data['name'] = '';
}
$this->load->model('setting/store');
$data['stores'] = $this->model_setting_store->getStores();
if (isset($this->request->get['layout_id'])) {
$data['layout_routes'] = $this->model_design_layout->getRoutes($this->request->get['layout_id']);
} else {
$data['layout_routes'] = [];
}
$this->load->model('setting/extension');
$this->load->model('setting/module');
$data['extensions'] = [];
// Get a list of installed modules
$extensions = $this->model_setting_extension->getExtensionsByType('module');
// Add all the modules which have multiple settings for each module
foreach ($extensions as $extension) {
$this->load->language('extension/' . $extension['extension'] . '/module/' . $extension['code'], $extension['code']);
$module_data = [];
$modules = $this->model_setting_module->getModulesByCode($extension['extension'] .'.' . $extension['code']);
foreach ($modules as $module) {
$module_data[] = [
'name' => strip_tags($module['name']),
'code' => $extension['extension'] . '.' . $extension['code'] . '.' . $module['module_id']
];
}
if ($this->config->has('module_' . $extension['code'] . '_status') || $module_data) {
$data['extensions'][] = [
'name' => strip_tags($this->language->get($extension['code'] . '_heading_title')),
'code' => $extension['extension'] . '.' . $extension['code'],
'module' => $module_data
];
}
}
// Modules layout
if (!empty($layout_info)) {
$layout_modules = $this->model_design_layout->getModules($this->request->get['layout_id']);
} else {
$layout_modules = [];
}
$data['layout_modules'] = [];
// Add all the modules which have multiple settings for each module
foreach ($layout_modules as $layout_module) {
$part = explode('.', $layout_module['code']);
if (!isset($part[2])) {
$data['layout_modules'][] = [
'code' => $layout_module['code'],
'position' => $layout_module['position'],
'sort_order' => $layout_module['sort_order'],
'edit' => $this->url->link('extension/' . $part[0] . '/module/' . $part[1], 'user_token=' . $this->session->data['user_token'])
];
} else {
$module_info = $this->model_setting_module->getModule($part[2]);
if ($module_info) {
$data['layout_modules'][] = [
'code' => $layout_module['code'],
'position' => $layout_module['position'],
'sort_order' => $layout_module['sort_order'],
'edit' => $this->url->link('extension/' . $part[0] . '/module/' . $part[1], 'user_token=' . $this->session->data['user_token'] . '&module_id=' . $part[2])
];
}
}
}
$data['user_token'] = $this->session->data['user_token'];
$data['header'] = $this->load->controller('common/header');
$data['column_left'] = $this->load->controller('common/column_left');
$data['footer'] = $this->load->controller('common/footer');
$this->response->setOutput($this->load->view('design/layout_form', $data));
}
/**
* @return void
*/
public function save(): void {
$this->load->language('design/layout');
$json = [];
if (!$this->user->hasPermission('modify', 'design/layout')) {
$json['error']['warning'] = $this->language->get('error_permission');
}
if ((oc_strlen($this->request->post['name']) < 3) || (oc_strlen($this->request->post['name']) > 64)) {
$json['error']['name'] = $this->language->get('error_name');
}
if (!$json) {
$this->load->model('design/layout');
if (!$this->request->post['layout_id']) {
$json['layout_id'] = $this->model_design_layout->addLayout($this->request->post);
} else {
$this->model_design_layout->editLayout($this->request->post['layout_id'], $this->request->post);
}
$json['success'] = $this->language->get('text_success');
}
$this->response->addHeader('Content-Type: application/json');
$this->response->setOutput(json_encode($json));
}
/**
* @return void
*/
public function delete(): void {
$this->load->language('design/layout');
$json = [];
if (isset($this->request->post['selected'])) {
$selected = $this->request->post['selected'];
} else {
$selected = [];
}
if (!$this->user->hasPermission('modify', 'design/layout')) {
$json['error'] = $this->language->get('error_permission');
}
$this->load->model('setting/store');
$this->load->model('catalog/product');
$this->load->model('catalog/category');
$this->load->model('catalog/manufacturer');
$this->load->model('catalog/information');
foreach ($selected as $layout_id) {
if ($this->config->get('config_layout_id') == $layout_id) {
$json['error'] = $this->language->get('error_default');
}
$store_total = $this->model_setting_store->getTotalStoresByLayoutId($layout_id);
if ($store_total) {
$json['error'] = sprintf($this->language->get('error_store'), $store_total);
}
$product_total = $this->model_catalog_product->getTotalProductsByLayoutId($layout_id);
if ($product_total) {
$json['error'] = sprintf($this->language->get('error_product'), $product_total);
}
$category_total = $this->model_catalog_category->getTotalCategoriesByLayoutId($layout_id);
if ($category_total) {
$json['error'] = sprintf($this->language->get('error_category'), $category_total);
}
$manufacturer_total = $this->model_catalog_manufacturer->getTotalManufacturersByLayoutId($layout_id);
if ($manufacturer_total) {
$json['error'] = sprintf($this->language->get('error_manufacturer'), $manufacturer_total);
}
$information_total = $this->model_catalog_information->getTotalInformationsByLayoutId($layout_id);
if ($information_total) {
$json['error'] = sprintf($this->language->get('error_information'), $information_total);
}
}
if (!$json) {
$this->load->model('design/layout');
foreach ($selected as $layout_id) {
$this->model_design_layout->deleteLayout($layout_id);
}
$json['success'] = $this->language->get('text_success');
}
$this->response->addHeader('Content-Type: application/json');
$this->response->setOutput(json_encode($json));
}
}

View File

@ -0,0 +1,573 @@
<?php
namespace Opencart\Admin\Controller\Design;
/**
* Class SEO URL
*
* @package Opencart\Admin\Controller\Design
*/
class SeoUrl extends \Opencart\System\Engine\Controller {
/**
* @return void
*/
public function index(): void {
$this->load->language('design/seo_url');
$this->document->setTitle($this->language->get('heading_title'));
if (isset($this->request->get['filter_keyword'])) {
$filter_keyword = (string)$this->request->get['filter_keyword'];
} else {
$filter_keyword = '';
}
if (isset($this->request->get['filter_key'])) {
$filter_key = (string)$this->request->get['filter_key'];
} else {
$filter_key = '';
}
if (isset($this->request->get['filter_value'])) {
$filter_value = (string)$this->request->get['filter_value'];
} else {
$filter_value = '';
}
if (isset($this->request->get['filter_store_id'])) {
$filter_store_id = (int)$this->request->get['filter_store_id'];
} else {
$filter_store_id = '';
}
if (isset($this->request->get['filter_language_id'])) {
$filter_language_id = (int)$this->request->get['filter_language_id'];
} else {
$filter_language_id = 0;
}
$url = '';
if (isset($this->request->get['filter_keyword'])) {
$url .= '&filter_keyword=' . urlencode(html_entity_decode((string)$this->request->get['filter_keyword'], ENT_QUOTES, 'UTF-8'));
}
if (isset($this->request->get['filter_key'])) {
$url .= '&filter_key=' . urlencode(html_entity_decode((string)$this->request->get['filter_key'], ENT_QUOTES, 'UTF-8'));
}
if (isset($this->request->get['filter_value'])) {
$url .= '&filter_value=' . urlencode(html_entity_decode((string)$this->request->get['filter_value'], ENT_QUOTES, 'UTF-8'));
}
if (isset($this->request->get['filter_store_id'])) {
$url .= '&filter_store_id=' . (int)$this->request->get['filter_store_id'];
}
if (isset($this->request->get['filter_language_id'])) {
$url .= '&filter_language_id=' . (int)$this->request->get['filter_language_id'];
}
if (isset($this->request->get['sort'])) {
$url .= '&sort=' . (string)$this->request->get['sort'];
}
if (isset($this->request->get['order'])) {
$url .= '&order=' . (string)$this->request->get['order'];
}
if (isset($this->request->get['page'])) {
$url .= '&page=' . (int)$this->request->get['page'];
}
$data['breadcrumbs'] = [];
$data['breadcrumbs'][] = [
'text' => $this->language->get('text_home'),
'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'])
];
$data['breadcrumbs'][] = [
'text' => $this->language->get('heading_title'),
'href' => $this->url->link('design/seo_url', 'user_token=' . $this->session->data['user_token'] . $url)
];
$data['add'] = $this->url->link('design/seo_url.form', 'user_token=' . $this->session->data['user_token'] . $url);
$data['delete'] = $this->url->link('design/seo_url.delete', 'user_token=' . $this->session->data['user_token']);
$data['list'] = $this->getList();
$this->load->model('setting/store');
$data['stores'] = $this->model_setting_store->getStores();
$this->load->model('localisation/language');
$data['languages'] = $this->model_localisation_language->getLanguages();
$data['filter_keyword'] = $filter_keyword;
$data['filter_key'] = $filter_key;
$data['filter_value'] = $filter_value;
$data['filter_store_id'] = $filter_store_id;
$data['filter_language_id'] = $filter_language_id;
$data['user_token'] = $this->session->data['user_token'];
$data['header'] = $this->load->controller('common/header');
$data['column_left'] = $this->load->controller('common/column_left');
$data['footer'] = $this->load->controller('common/footer');
$this->response->setOutput($this->load->view('design/seo_url', $data));
}
/**
* @return void
*/
public function list(): void {
$this->load->language('design/seo_url');
$this->response->setOutput($this->getList());
}
/**
* @return string
*/
protected function getList(): string {
if (isset($this->request->get['filter_keyword'])) {
$filter_keyword = (string)$this->request->get['filter_keyword'];
} else {
$filter_keyword = '';
}
if (isset($this->request->get['filter_key'])) {
$filter_key = (string)$this->request->get['filter_key'];
} else {
$filter_key = '';
}
if (isset($this->request->get['filter_value'])) {
$filter_value = (string)$this->request->get['filter_value'];
} else {
$filter_value = '';
}
if (isset($this->request->get['filter_store_id'])) {
$filter_store_id = (int)$this->request->get['filter_store_id'];
} else {
$filter_store_id = '';
}
if (isset($this->request->get['filter_language_id'])) {
$filter_language_id = (int)$this->request->get['filter_language_id'];
} else {
$filter_language_id = 0;
}
if (isset($this->request->get['sort'])) {
$sort = (string)$this->request->get['sort'];
} else {
$sort = 'key';
}
if (isset($this->request->get['order'])) {
$order = (string)$this->request->get['order'];
} else {
$order = 'ASC';
}
if (isset($this->request->get['page'])) {
$page = (int)$this->request->get['page'];
} else {
$page = 1;
}
$url = '';
if (isset($this->request->get['filter_keyword'])) {
$url .= '&filter_keyword=' . urlencode(html_entity_decode((string)$this->request->get['filter_keyword'], ENT_QUOTES, 'UTF-8'));
}
if (isset($this->request->get['filter_key'])) {
$url .= '&filter_key=' . urlencode(html_entity_decode((string)$this->request->get['filter_key'], ENT_QUOTES, 'UTF-8'));
}
if (isset($this->request->get['filter_value'])) {
$url .= '&filter_value=' . urlencode(html_entity_decode((string)$this->request->get['filter_value'], ENT_QUOTES, 'UTF-8'));
}
if (isset($this->request->get['filter_store_id'])) {
$url .= '&filter_store_id=' . (int)$this->request->get['filter_store_id'];
}
if (isset($this->request->get['filter_language_id'])) {
$url .= '&filter_language_id=' . (int)$this->request->get['filter_language_id'];
}
if (isset($this->request->get['sort'])) {
$url .= '&sort=' . (string)$this->request->get['sort'];
}
if (isset($this->request->get['order'])) {
$url .= '&order=' . (string)$this->request->get['order'];
}
if (isset($this->request->get['page'])) {
$url .= '&page=' . (int)$this->request->get['page'];
}
$data['action'] = $this->url->link('design/seo_url.list', 'user_token=' . $this->session->data['user_token'] . $url);
$data['seo_urls'] = [];
$filter_data = [
'filter_keyword' => $filter_keyword,
'filter_key' => $filter_key,
'filter_value' => $filter_value,
'filter_store_id' => $filter_store_id,
'filter_language_id' => $filter_language_id,
'sort' => $sort,
'order' => $order,
'start' => ($page - 1) * $this->config->get('config_pagination_admin'),
'limit' => $this->config->get('config_pagination_admin')
];
$this->load->model('design/seo_url');
$this->load->model('localisation/language');
$seo_url_total = $this->model_design_seo_url->getTotalSeoUrls($filter_data);
$results = $this->model_design_seo_url->getSeoUrls($filter_data);
foreach ($results as $result) {
$language_info = $this->model_localisation_language->getLanguage($result['language_id']);
if ($language_info) {
$code = $language_info['code'];
$image = $language_info['image'];
} else {
$code = '';
$image = '';
}
$data['seo_urls'][] = [
'seo_url_id' => $result['seo_url_id'],
'keyword' => $result['keyword'],
'image' => $image,
'language' => $code,
'key' => $result['key'],
'value' => $result['value'],
'sort_order' => $result['sort_order'],
'store' => $result['store_id'] ? $result['store'] : $this->language->get('text_default'),
'edit' => $this->url->link('design/seo_url.form', 'user_token=' . $this->session->data['user_token'] . '&seo_url_id=' . $result['seo_url_id'] . $url)
];
}
$url = '';
if (isset($this->request->get['filter_keyword'])) {
$url .= '&filter_keyword=' . urlencode(html_entity_decode((string)$this->request->get['filter_keyword'], ENT_QUOTES, 'UTF-8'));
}
if (isset($this->request->get['filter_key'])) {
$url .= '&filter_key=' . urlencode(html_entity_decode((string)$this->request->get['filter_key'], ENT_QUOTES, 'UTF-8'));
}
if (isset($this->request->get['filter_value'])) {
$url .= '&filter_value=' . urlencode(html_entity_decode((string)$this->request->get['filter_value'], ENT_QUOTES, 'UTF-8'));
}
if (isset($this->request->get['filter_store_id'])) {
$url .= '&filter_store_id=' . (int)$this->request->get['filter_store_id'];
}
if (isset($this->request->get['filter_language_id'])) {
$url .= '&filter_language_id=' . (int)$this->request->get['filter_language_id'];
}
if ($order == 'ASC') {
$url .= '&order=DESC';
} else {
$url .= '&order=ASC';
}
$data['sort_keyword'] = $this->url->link('design/seo_url.list', 'user_token=' . $this->session->data['user_token'] . '&sort=keyword' . $url);
$data['sort_key'] = $this->url->link('design/seo_url.list', 'user_token=' . $this->session->data['user_token'] . '&sort=key' . $url);
$data['sort_value'] = $this->url->link('design/seo_url.list', 'user_token=' . $this->session->data['user_token'] . '&sort=value' . $url);
$data['sort_sort_order'] = $this->url->link('design/seo_url.list', 'user_token=' . $this->session->data['user_token'] . '&sort=sort_order' . $url);
$data['sort_store'] = $this->url->link('design/seo_url.list', 'user_token=' . $this->session->data['user_token'] . '&sort=store' . $url);
$data['sort_language'] = $this->url->link('design/seo_url.list', 'user_token=' . $this->session->data['user_token'] . '&sort=language' . $url);
$url = '';
if (isset($this->request->get['filter_keyword'])) {
$url .= '&filter_keyword=' . urlencode(html_entity_decode((string)$this->request->get['filter_keyword'], ENT_QUOTES, 'UTF-8'));
}
if (isset($this->request->get['filter_key'])) {
$url .= '&filter_key=' . urlencode(html_entity_decode((string)$this->request->get['filter_key'], ENT_QUOTES, 'UTF-8'));
}
if (isset($this->request->get['filter_value'])) {
$url .= '&filter_value=' . urlencode(html_entity_decode((string)$this->request->get['filter_value'], ENT_QUOTES, 'UTF-8'));
}
if (isset($this->request->get['filter_store_id'])) {
$url .= '&filter_store_id=' . (int)$this->request->get['filter_store_id'];
}
if (isset($this->request->get['filter_language_id'])) {
$url .= '&filter_language_id=' . (int)$this->request->get['filter_language_id'];
}
if (isset($this->request->get['sort'])) {
$url .= '&sort=' . (string)$this->request->get['sort'];
}
if (isset($this->request->get['order'])) {
$url .= '&order=' . (string)$this->request->get['order'];
}
$data['pagination'] = $this->load->controller('common/pagination', [
'total' => $seo_url_total,
'page' => $page,
'limit' => $this->config->get('config_pagination_admin'),
'url' => $this->url->link('design/seo_url.list', 'user_token=' . $this->session->data['user_token'] . $url . '&page={page}')
]);
$data['results'] = sprintf($this->language->get('text_pagination'), ($seo_url_total) ? (($page - 1) * $this->config->get('config_pagination_admin')) + 1 : 0, ((($page - 1) * $this->config->get('config_pagination_admin')) > ($seo_url_total - $this->config->get('config_pagination_admin'))) ? $seo_url_total : ((($page - 1) * $this->config->get('config_pagination_admin')) + $this->config->get('config_pagination_admin')), $seo_url_total, ceil($seo_url_total / $this->config->get('config_pagination_admin')));
$data['sort'] = $sort;
$data['order'] = $order;
return $this->load->view('design/seo_url_list', $data);
}
/**
* @return void
*/
public function form(): void {
$this->load->language('design/seo_url');
$this->document->setTitle($this->language->get('heading_title'));
$data['text_form'] = !isset($this->request->get['seo_url_id']) ? $this->language->get('text_add') : $this->language->get('text_edit');
$url = '';
if (isset($this->request->get['filter_keyword'])) {
$url .= '&filter_keyword=' . urlencode(html_entity_decode((string)$this->request->get['filter_keyword'], ENT_QUOTES, 'UTF-8'));
}
if (isset($this->request->get['filter_key'])) {
$url .= '&filter_key=' . urlencode(html_entity_decode((string)$this->request->get['filter_key'], ENT_QUOTES, 'UTF-8'));
}
if (isset($this->request->get['filter_value'])) {
$url .= '&filter_value=' . urlencode(html_entity_decode((string)$this->request->get['filter_value'], ENT_QUOTES, 'UTF-8'));
}
if (isset($this->request->get['filter_store_id'])) {
$url .= '&filter_store_id=' . (int)$this->request->get['filter_store_id'];
}
if (isset($this->request->get['filter_language_id'])) {
$url .= '&filter_language_id=' . (int)$this->request->get['filter_language_id'];
}
if (isset($this->request->get['sort'])) {
$url .= '&sort=' . (string)$this->request->get['sort'];
}
if (isset($this->request->get['order'])) {
$url .= '&order=' . (string)$this->request->get['order'];
}
if (isset($this->request->get['page'])) {
$url .= '&page=' . (int)$this->request->get['page'];
}
$data['breadcrumbs'] = [];
$data['breadcrumbs'][] = [
'text' => $this->language->get('text_home'),
'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'])
];
$data['breadcrumbs'][] = [
'text' => $this->language->get('heading_title'),
'href' => $this->url->link('design/seo_url', 'user_token=' . $this->session->data['user_token'] . $url)
];
$data['save'] = $this->url->link('design/seo_url.save', 'user_token=' . $this->session->data['user_token']);
$data['back'] = $this->url->link('design/seo_url', 'user_token=' . $this->session->data['user_token'] . $url);
if (isset($this->request->get['seo_url_id'])) {
$this->load->model('design/seo_url');
$seo_url_info = $this->model_design_seo_url->getSeoUrl($this->request->get['seo_url_id']);
}
if (isset($this->request->get['seo_url_id'])) {
$data['seo_url_id'] = (int)$this->request->get['seo_url_id'];
} else {
$data['seo_url_id'] = 0;
}
$data['stores'] = [];
$data['stores'][] = [
'store_id' => 0,
'name' => $this->language->get('text_default')
];
$this->load->model('setting/store');
$stores = $this->model_setting_store->getStores();
foreach ($stores as $store) {
$data['stores'][] = [
'store_id' => $store['store_id'],
'name' => $store['name']
];
}
if (!empty($seo_url_info)) {
$data['store_id'] = $seo_url_info['store_id'];
} else {
$data['store_id'] = '';
}
$this->load->model('localisation/language');
$data['languages'] = $this->model_localisation_language->getLanguages();
if (!empty($seo_url_info)) {
$data['language_id'] = $seo_url_info['language_id'];
} else {
$data['language_id'] = '';
}
if (!empty($seo_url_info)) {
$data['key'] = $seo_url_info['key'];
} else {
$data['key'] = '';
}
if (!empty($seo_url_info)) {
$data['value'] = $seo_url_info['value'];
} else {
$data['value'] = '';
}
if (!empty($seo_url_info)) {
$data['keyword'] = $seo_url_info['keyword'];
} else {
$data['keyword'] = '';
}
if (!empty($seo_url_info)) {
$data['sort_order'] = $seo_url_info['sort_order'];
} else {
$data['sort_order'] = '';
}
$data['header'] = $this->load->controller('common/header');
$data['column_left'] = $this->load->controller('common/column_left');
$data['footer'] = $this->load->controller('common/footer');
$this->response->setOutput($this->load->view('design/seo_url_form', $data));
}
/**
* @return void
*/
public function save(): void {
$this->load->language('design/seo_url');
$json = [];
if (!$this->user->hasPermission('modify', 'design/seo_url')) {
$json['error']['warning'] = $this->language->get('error_permission');
}
if ((oc_strlen($this->request->post['key']) < 1) || (oc_strlen($this->request->post['key']) > 64)) {
$json['error']['key'] = $this->language->get('error_key');
}
if ((oc_strlen($this->request->post['value']) < 1) || (oc_strlen($this->request->post['value']) > 255)) {
$json['error']['value'] = $this->language->get('error_value');
}
$this->load->model('design/seo_url');
// Check if there is already a key value pair on the same store using the same language
$seo_url_info = $this->model_design_seo_url->getSeoUrlByKeyValue($this->request->post['key'], $this->request->post['value'], $this->request->post['store_id'], $this->request->post['language_id']);
if ($seo_url_info && (!isset($this->request->post['seo_url_id']) || $seo_url_info['seo_url_id'] != (int)$this->request->post['seo_url_id'])) {
$json['error']['value'] = $this->language->get('error_value_exists');
}
// Split keywords by / so we can validate each keyword
$keywords = explode('/', $this->request->post['keyword']);
foreach ($keywords as $keyword) {
if ((oc_strlen(trim($keyword)) < 1) || (oc_strlen($keyword) > 64)) {
$json['error']['keyword'] = $this->language->get('error_keyword');
}
if (preg_match('/[^a-zA-Z0-9\/_-]|[\p{Cyrillic}]+/u', $keyword)) {
$json['error']['keyword'] = $this->language->get('error_keyword_character');
}
}
// Check if keyword already exists and on the same store as long as the keyword matches the key / value pair
$seo_url_info = $this->model_design_seo_url->getSeoUrlByKeyword($this->request->post['keyword'], $this->request->post['store_id']);
if ($seo_url_info && (($seo_url_info['key'] != $this->request->post['key']) || ($seo_url_info['value'] != $this->request->post['value']))) {
$json['error']['keyword'] = $this->language->get('error_keyword_exists');
}
if (!$json) {
if (!$this->request->post['seo_url_id']) {
$json['seo_url_id'] = $this->model_design_seo_url->addSeoUrl($this->request->post);
} else {
$this->model_design_seo_url->editSeoUrl($this->request->post['seo_url_id'], $this->request->post);
}
$json['success'] = $this->language->get('text_success');
}
$this->response->addHeader('Content-Type: application/json');
$this->response->setOutput(json_encode($json));
}
/**
* @return void
*/
public function delete(): void {
$this->load->language('design/seo_url');
$json = [];
if (isset($this->request->post['selected'])) {
$selected = $this->request->post['selected'];
} else {
$selected = [];
}
if (!$this->user->hasPermission('modify', 'design/seo_url')) {
$json['error'] = $this->language->get('error_permission');
}
if (!$json) {
$this->load->model('design/seo_url');
foreach ($selected as $seo_url_id) {
$this->model_design_seo_url->deleteSeoUrl($seo_url_id);
}
$json['success'] = $this->language->get('text_success');
}
$this->response->addHeader('Content-Type: application/json');
$this->response->setOutput(json_encode($json));
}
}

View File

@ -0,0 +1,432 @@
<?php
namespace Opencart\Admin\Controller\Design;
/**
* Class Theme
*
* @package Opencart\Admin\Controller\Design
*/
class Theme extends \Opencart\System\Engine\Controller {
/**
* @return void
*/
public function index(): void {
$this->load->language('design/theme');
$this->document->setTitle($this->language->get('heading_title'));
$data['breadcrumbs'] = [];
$data['breadcrumbs'][] = [
'text' => $this->language->get('text_home'),
'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'])
];
$data['breadcrumbs'][] = [
'text' => $this->language->get('heading_title'),
'href' => $this->url->link('design/theme', 'user_token=' . $this->session->data['user_token'])
];
$data['stores'] = [];
$this->load->model('setting/store');
$results = $this->model_setting_store->getStores();
foreach ($results as $result) {
$data['stores'][] = [
'store_id' => $result['store_id'],
'name' => $result['name']
];
}
$data['user_token'] = $this->session->data['user_token'];
$data['header'] = $this->load->controller('common/header');
$data['column_left'] = $this->load->controller('common/column_left');
$data['footer'] = $this->load->controller('common/footer');
$this->response->setOutput($this->load->view('design/theme', $data));
}
/**
* @return void
*/
public function history(): void {
$this->load->language('design/theme');
if (isset($this->request->get['page'])) {
$page = (int)$this->request->get['page'];
} else {
$page = 1;
}
$limit = 10;
$data['histories'] = [];
$this->load->model('design/theme');
$this->load->model('setting/store');
$history_total = $this->model_design_theme->getTotalThemes();
$results = $this->model_design_theme->getThemes(($page - 1) * $limit, $limit);
foreach ($results as $result) {
$store_info = $this->model_setting_store->getStore($result['store_id']);
if ($store_info) {
$store = $store_info['name'];
} else {
$store = '';
}
$data['histories'][] = [
'store_id' => $result['store_id'],
'store' => ($result['store_id'] ? $store : $this->language->get('text_default')),
'route' => $result['route'],
'date_added' => date($this->language->get('date_format_short'), strtotime($result['date_added'])),
'edit' => $this->url->link('design/theme.template', 'user_token=' . $this->session->data['user_token']),
'delete' => $this->url->link('design/theme.delete', 'user_token=' . $this->session->data['user_token'] . '&theme_id=' . $result['theme_id'])
];
}
$data['pagination'] = $this->load->controller('common/pagination', [
'total' => $history_total,
'page' => $page,
'limit' => $limit,
'url' => $this->url->link('design/theme.history', 'user_token=' . $this->session->data['user_token'] . '&page={page}')
]);
$data['results'] = sprintf($this->language->get('text_pagination'), ($history_total) ? (($page - 1) * $limit) + 1 : 0, ((($page - 1) * $limit) > ($history_total - $limit)) ? $history_total : ((($page - 1) * $limit) + $limit), $history_total, ceil($history_total / $limit));
$this->response->setOutput($this->load->view('design/theme_history', $data));
}
/**
* @return void
*/
public function path(): void {
$this->load->language('design/theme');
$json = [];
if (isset($this->request->get['store_id'])) {
$store_id = (int)$this->request->get['store_id'];
} else {
$store_id = 0;
}
if (isset($this->request->get['path'])) {
$path = $this->request->get['path'];
} else {
$path = '';
}
// Default templates
$json['directory'] = [];
$json['file'] = [];
$directory = DIR_CATALOG . 'view/template';
if (substr(str_replace('\\', '/', realpath($directory . '/' . $path)), 0, strlen($directory)) == $directory) {
// We grab the files from the default template directory
$files = glob(rtrim(DIR_CATALOG . 'view/template/' . $path, '/') . '/*');
foreach ($files as $file) {
if (is_dir($file)) {
$json['directory'][] = [
'name' => basename($file),
'path' => trim($path . '/' . basename($file), '/')
];
}
if (is_file($file)) {
$json['file'][] = [
'name' => basename($file),
'path' => trim($path . '/' . basename($file), '/')
];
}
}
}
if (!$path) {
$json['directory'][] = [
'name' => $this->language->get('text_extension'),
'path' => 'extension',
];
}
// Extension templates
$json['extension'] = [];
// List all the extensions
if ($path == 'extension') {
$directories = glob(DIR_EXTENSION . '*', GLOB_ONLYDIR);
foreach ($directories as $directory) {
$json['extension']['directory'][] = [
'name' => basename($directory),
'path' => 'extension/' . basename($directory)
];
}
}
// List extension sub directories directories
if (substr($path, 0, 10) == 'extension/') {
$route = '';
$part = explode('/', $path);
$extension = $part[1];
unset($part[0]);
unset($part[1]);
if (isset($part[2])) {
$route = implode('/', $part);
}
$safe = true;
if (substr(str_replace('\\', '/', realpath(DIR_EXTENSION . $extension)), 0, strlen(DIR_EXTENSION)) != DIR_EXTENSION) {
$safe = false;
}
$directory = DIR_EXTENSION . $extension . '/catalog/view/template';
if (substr(str_replace('\\', '/', realpath($directory . '/' . $route)), 0, strlen($directory)) != $directory) {
$safe = false;
}
if ($safe) {
$files = glob(rtrim(DIR_EXTENSION . $extension . '/catalog/view/template/' . $route, '/') . '/*');
sort($files);
foreach ($files as $file) {
if (is_dir($file)) {
$json['extension']['directory'][] = [
'name' => basename($file),
'path' => $path . '/' . basename($file)
];
}
if (is_file($file)) {
$json['extension']['file'][] = [
'name' => basename($file),
'path' => $path . '/' . basename($file)
];
}
}
}
}
if ($path) {
$json['back'] = [
'name' => $this->language->get('button_back'),
'path' => urlencode(substr($path, 0, strrpos($path, '/'))),
];
}
$this->response->addHeader('Content-Type: application/json');
$this->response->setOutput(json_encode($json));
}
/**
* @return void
*/
public function template(): void {
$this->load->language('design/theme');
$json = [];
if (isset($this->request->get['store_id'])) {
$store_id = (int)$this->request->get['store_id'];
} else {
$store_id = 0;
}
if (isset($this->request->get['path'])) {
$path = $this->request->get['path'];
} else {
$path = '';
}
// Default template load
$directory = DIR_CATALOG . 'view/template';
if (is_file($directory . '/' . $path) && (substr(str_replace('\\', '/', realpath($directory . '/' . $path)), 0, strlen($directory)) == $directory)) {
$json['code'] = file_get_contents(DIR_CATALOG . 'view/template/' . $path);
}
// Extension template load
if (substr($path, 0, 10) == 'extension/') {
$part = explode('/', $path);
$extension = $part[1];
unset($part[0]);
unset($part[1]);
$route = implode('/', $part);
$safe = true;
if (substr(str_replace('\\', '/', realpath(DIR_EXTENSION . $extension)), 0, strlen(DIR_EXTENSION)) != DIR_EXTENSION) {
$safe = false;
}
$directory = DIR_EXTENSION . $extension . '/catalog/view/template';
if (substr(str_replace('\\', '/', realpath($directory . '/' . $route)), 0, strlen($directory)) != $directory) {
$safe = false;
}
if ($safe && is_file($directory . '/' . $route)) {
$json['code'] = file_get_contents($directory . '/' . $route);
}
}
// Custom template load
$this->load->model('design/theme');
$theme_info = $this->model_design_theme->getTheme($store_id, $path);
if ($theme_info) {
$json['code'] = html_entity_decode($theme_info['code']);
}
$this->response->addHeader('Content-Type: application/json');
$this->response->setOutput(json_encode($json));
}
/**
* @return void
*/
public function save(): void {
$this->load->language('design/theme');
$json = [];
if (isset($this->request->get['store_id'])) {
$store_id = (int)$this->request->get['store_id'];
} else {
$store_id = 0;
}
if (isset($this->request->get['path'])) {
$path = $this->request->get['path'];
} else {
$path = '';
}
// Check user has permission
if (!$this->user->hasPermission('modify', 'design/theme')) {
$json['error'] = $this->language->get('error_permission');
}
if (substr($path, -5) != '.twig') {
$json['error'] = $this->language->get('error_twig');
}
if (!$json) {
$this->load->model('design/theme');
$pos = strpos($path, '.');
$this->model_design_theme->editTheme($store_id, ($pos !== false) ? substr($path, 0, $pos) : $path, $this->request->post['code']);
$json['success'] = $this->language->get('text_success');
}
$this->response->addHeader('Content-Type: application/json');
$this->response->setOutput(json_encode($json));
}
/**
* @return void
*/
public function reset(): void {
$json = [];
if (isset($this->request->get['store_id'])) {
$store_id = (int)$this->request->get['store_id'];
} else {
$store_id = 0;
}
if (isset($this->request->get['path'])) {
$path = $this->request->get['path'];
} else {
$path = '';
}
$directory = DIR_CATALOG . 'view/template';
if (is_file($directory . '/' . $path) && (substr(str_replace('\\', '/', realpath($directory . '/' . $path)), 0, strlen($directory)) == $directory)) {
$json['code'] = file_get_contents(DIR_CATALOG . 'view/template/' . $path);
}
// Extension template load
if (substr($path, 0, 10) == 'extension/') {
$part = explode('/', $path);
$extension = $part[1];
unset($part[0]);
unset($part[1]);
$route = implode('/', $part);
$safe = true;
if (substr(str_replace('\\', '/', realpath(DIR_EXTENSION . $extension)), 0, strlen(DIR_EXTENSION)) != DIR_EXTENSION) {
$safe = false;
}
$directory = DIR_EXTENSION . $extension . '/catalog/view/template';
if (substr(str_replace('\\', '/', realpath($directory . '/' . $route)), 0, strlen($directory)) != $directory) {
$safe = false;
}
if ($safe && is_file($directory . '/' . $route)) {
$json['code'] = file_get_contents($directory . '/' . $route);
}
}
$this->response->addHeader('Content-Type: application/json');
$this->response->setOutput(json_encode($json));
}
/**
* @return void
*/
public function delete(): void {
$this->load->language('design/theme');
$json = [];
if (isset($this->request->get['theme_id'])) {
$theme_id = (int)$this->request->get['theme_id'];
} else {
$theme_id = 0;
}
// Check user has permission
if (!$this->user->hasPermission('modify', 'design/theme')) {
$json['error'] = $this->language->get('error_permission');
}
if (!$json) {
$this->load->model('design/theme');
$this->model_design_theme->deleteTheme($theme_id);
$json['success'] = $this->language->get('text_success');
}
$this->response->addHeader('Content-Type: application/json');
$this->response->setOutput(json_encode($json));
}
}

View File

@ -0,0 +1,459 @@
<?php
namespace Opencart\Admin\Controller\Design;
/**
* Class Translation
*
* @package Opencart\Admin\Controller\Design
*/
class Translation extends \Opencart\System\Engine\Controller {
/**
* @return void
*/
public function index(): void {
$this->load->language('design/translation');
$this->document->setTitle($this->language->get('heading_title'));
$url = '';
if (isset($this->request->get['sort'])) {
$url .= '&sort=' . $this->request->get['sort'];
}
if (isset($this->request->get['order'])) {
$url .= '&order=' . $this->request->get['order'];
}
if (isset($this->request->get['page'])) {
$url .= '&page=' . $this->request->get['page'];
}
$data['breadcrumbs'] = [];
$data['breadcrumbs'][] = [
'text' => $this->language->get('text_home'),
'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'])
];
$data['breadcrumbs'][] = [
'text' => $this->language->get('heading_title'),
'href' => $this->url->link('design/translation', 'user_token=' . $this->session->data['user_token'] . $url)
];
$data['add'] = $this->url->link('design/translation.form', 'user_token=' . $this->session->data['user_token'] . $url);
$data['delete'] = $this->url->link('design/translation.delete', 'user_token=' . $this->session->data['user_token']);
$data['list'] = $this->getList();
$data['user_token'] = $this->session->data['user_token'];
$data['header'] = $this->load->controller('common/header');
$data['column_left'] = $this->load->controller('common/column_left');
$data['footer'] = $this->load->controller('common/footer');
$this->response->setOutput($this->load->view('design/translation', $data));
}
/**
* @return void
*/
public function list(): void {
$this->load->language('design/translation');
$this->response->setOutput($this->getList());
}
/**
* @return string
*/
protected function getList(): string {
if (isset($this->request->get['sort'])) {
$sort = (string)$this->request->get['sort'];
} else {
$sort = 'store';
}
if (isset($this->request->get['order'])) {
$order = (string)$this->request->get['order'];
} else {
$order = 'ASC';
}
if (isset($this->request->get['page'])) {
$page = (int)$this->request->get['page'];
} else {
$page = 1;
}
$url = '';
if (isset($this->request->get['sort'])) {
$url .= '&sort=' . $this->request->get['sort'];
}
if (isset($this->request->get['order'])) {
$url .= '&order=' . $this->request->get['order'];
}
if (isset($this->request->get['page'])) {
$url .= '&page=' . $this->request->get['page'];
}
$data['action'] = $this->url->link('design/translation.list', 'user_token=' . $this->session->data['user_token'] . $url);
$this->load->model('localisation/language');
$data['translations'] = [];
$filter_data = [
'sort' => $sort,
'order' => $order,
'start' => ($page - 1) * $this->config->get('config_pagination_admin'),
'limit' => $this->config->get('config_pagination_admin')
];
$this->load->model('design/translation');
$translation_total = $this->model_design_translation->getTotalTranslations();
$results = $this->model_design_translation->getTranslations($filter_data);
foreach ($results as $result) {
$language_info = $this->model_localisation_language->getLanguage($result['language_id']);
if ($language_info) {
$code = $language_info['code'];
$image = $language_info['image'];
} else {
$code = '';
$image = '';
}
$data['translations'][] = [
'translation_id' => $result['translation_id'],
'store' => ($result['store_id'] ? $result['store'] : $this->language->get('text_default')),
'route' => $result['route'],
'image' => $image,
'language' => $code,
'key' => $result['key'],
'value' => $result['value'],
'edit' => $this->url->link('design/translation.form', 'user_token=' . $this->session->data['user_token'] . '&translation_id=' . $result['translation_id'])
];
}
$url = '';
if ($order == 'ASC') {
$url .= '&order=DESC';
} else {
$url .= '&order=ASC';
}
$data['sort_store'] = $this->url->link('design/translation.list', 'user_token=' . $this->session->data['user_token'] . '&sort=store' . $url);
$data['sort_language'] = $this->url->link('design/translation.list', 'user_token=' . $this->session->data['user_token'] . '&sort=language' . $url);
$data['sort_route'] = $this->url->link('design/translation.list', 'user_token=' . $this->session->data['user_token'] . '&sort=route' . $url);
$data['sort_key'] = $this->url->link('design/translation.list', 'user_token=' . $this->session->data['user_token'] . '&sort=key' . $url);
$data['sort_value'] = $this->url->link('design/translation.list', 'user_token=' . $this->session->data['user_token'] . '&sort=value' . $url);
$data['pagination'] = $this->load->controller('common/pagination', [
'total' => $translation_total,
'page' => $page,
'limit' => $this->config->get('config_pagination_admin'),
'url' => $this->url->link('design/translation.list', 'user_token=' . $this->session->data['user_token'] . $url . '&page={page}')
]);
$data['results'] = sprintf($this->language->get('text_pagination'), ($translation_total) ? (($page - 1) * $this->config->get('config_pagination_admin')) + 1 : 0, ((($page - 1) * $this->config->get('config_pagination_admin')) > ($translation_total - $this->config->get('config_pagination_admin'))) ? $translation_total : ((($page - 1) * $this->config->get('config_pagination_admin')) + $this->config->get('config_pagination_admin')), $translation_total, ceil($translation_total / $this->config->get('config_pagination_admin')));
$data['sort'] = $sort;
$data['order'] = $order;
return $this->load->view('design/translation_list', $data);
}
/**
* @return void
*/
public function form(): void {
$this->load->language('design/translation');
$this->document->setTitle($this->language->get('heading_title'));
$data['text_form'] = !isset($this->request->get['translation_id']) ? $this->language->get('text_add') : $this->language->get('text_edit');
$url = '';
if (isset($this->request->get['sort'])) {
$url .= '&sort=' . $this->request->get['sort'];
}
if (isset($this->request->get['order'])) {
$url .= '&order=' . $this->request->get['order'];
}
if (isset($this->request->get['page'])) {
$url .= '&page=' . $this->request->get['page'];
}
$data['breadcrumbs'] = [];
$data['breadcrumbs'][] = [
'text' => $this->language->get('text_home'),
'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'])
];
$data['breadcrumbs'][] = [
'text' => $this->language->get('heading_title'),
'href' => $this->url->link('design/translation', 'user_token=' . $this->session->data['user_token'] . $url)
];
$data['save'] = $this->url->link('design/translation.save', 'user_token=' . $this->session->data['user_token']);
$data['back'] = $this->url->link('design/translation', 'user_token=' . $this->session->data['user_token'] . $url);
if (isset($this->request->get['translation_id'])) {
$this->load->model('design/translation');
$translation_info = $this->model_design_translation->getTranslation($this->request->get['translation_id']);
}
if (isset($this->request->get['translation_id'])) {
$data['translation_id'] = (int)$this->request->get['translation_id'];
} else {
$data['translation_id'] = 0;
}
$this->load->model('setting/store');
$data['stores'] = $this->model_setting_store->getStores();
if (!empty($translation_info)) {
$data['store_id'] = $translation_info['store_id'];
} else {
$data['store_id'] = '';
}
$this->load->model('localisation/language');
$data['languages'] = $this->model_localisation_language->getLanguages();
if (!empty($translation_info)) {
$data['language_id'] = $translation_info['language_id'];
} else {
$data['language_id'] = '';
}
if (!empty($translation_info)) {
$data['route'] = $translation_info['route'];
} else {
$data['route'] = '';
}
if (!empty($translation_info)) {
$data['key'] = $translation_info['key'];
} else {
$data['key'] = '';
}
if (!empty($translation_info)) {
$data['value'] = $translation_info['value'];
} else {
$data['value'] = '';
}
$data['user_token'] = $this->session->data['user_token'];
$data['header'] = $this->load->controller('common/header');
$data['column_left'] = $this->load->controller('common/column_left');
$data['footer'] = $this->load->controller('common/footer');
$this->response->setOutput($this->load->view('design/translation_form', $data));
}
/**
* @return void
*/
public function save(): void {
$this->load->language('design/translation');
$json = [];
if (!$this->user->hasPermission('modify', 'design/translation')) {
$json['error']['warning'] = $this->language->get('error_permission');
}
if ((oc_strlen($this->request->post['key']) < 3) || (oc_strlen($this->request->post['key']) > 64)) {
$json['error']['key'] = $this->language->get('error_key');
}
if (!$json) {
$this->load->model('design/translation');
if (!$this->request->post['translation_id']) {
$json['translation_id'] = $this->model_design_translation->addTranslation($this->request->post);
} else {
$this->model_design_translation->editTranslation($this->request->post['translation_id'], $this->request->post);
}
$json['success'] = $this->language->get('text_success');
}
$this->response->addHeader('Content-Type: application/json');
$this->response->setOutput(json_encode($json));
}
/**
* @return void
*/
public function delete(): void {
$this->load->language('design/translation');
$json = [];
if (isset($this->request->post['selected'])) {
$selected = $this->request->post['selected'];
} else {
$selected = [];
}
if (!$this->user->hasPermission('modify', 'design/translation')) {
$json['error'] = $this->language->get('error_permission');
}
if (!$json) {
$this->load->model('design/translation');
foreach ($selected as $translation_id) {
$this->model_design_translation->deleteTranslation($translation_id);
}
$json['success'] = $this->language->get('text_success');
}
$this->response->addHeader('Content-Type: application/json');
$this->response->setOutput(json_encode($json));
}
/**
* @return void
*/
public function path(): void {
$this->load->language('design/translation');
$json = [];
if (isset($this->request->get['language_id'])) {
$language_id = (int)$this->request->get['language_id'];
} else {
$language_id = 0;
}
$this->load->model('localisation/language');
$language_info = $this->model_localisation_language->getLanguage($language_id);
if (!empty($language_info)) {
$path = glob(DIR_CATALOG . 'language/' . $language_info['code'] . '/*');
while (count($path) != 0) {
$next = array_shift($path);
foreach ((array)glob($next . '/*') as $file) {
if (is_dir($file)) {
$path[] = $file;
}
if (substr($file, -4) == '.php') {
$json[] = substr(substr($file, strlen(DIR_CATALOG . 'language/' . $language_info['code'] . '/')), 0, -4);
}
}
}
$path = glob(DIR_EXTENSION . '*/catalog/language/' . $language_info['code'] . '/*');
while (count($path) != 0) {
$next = array_shift($path);
foreach ((array)glob($next . '/*') as $file) {
if (is_dir($file)) {
$path[] = $file;
}
if (substr($file, -4) == '.php') {
$new_path = substr($file, strlen(DIR_EXTENSION));
$code = substr($new_path, 0, strpos($new_path, '/'));
$length = strlen(DIR_EXTENSION . $code . '/catalog/language/' . $language_info['code'] . '/');
$route = substr(substr($file, $length), 0, -4);
$json[] = 'extension/' . $code . '/' . $route;
}
}
}
}
$this->response->addHeader('Content-Type: application/json');
$this->response->setOutput(json_encode($json));
}
/**
* @return void
*/
public function translation(): void {
$this->load->language('design/translation');
$json = [];
if (isset($this->request->get['store_id'])) {
$store_id = (int)$this->request->get['store_id'];
} else {
$store_id = 0;
}
if (isset($this->request->get['language_id'])) {
$language_id = (int)$this->request->get['language_id'];
} else {
$language_id = 0;
}
if (isset($this->request->get['path'])) {
$route = $this->request->get['path'];
} else {
$route = '';
}
$this->load->model('localisation/language');
$language_info = $this->model_localisation_language->getLanguage($language_id);
$part = explode('/', $route);
if ($part[0] != 'extension') {
$directory = DIR_CATALOG . 'language/';
} else {
$directory = DIR_EXTENSION . $part[1] . '/catalog/language/';
array_shift($part);
// Don't remove. Required for extension route.
array_shift($part);
$route = implode('/', $part);
}
if ($language_info && is_file($directory . $language_info['code'] . '/' . $route . '.php') && substr(str_replace('\\', '/', realpath($directory . $language_info['code'] . '/' . $route . '.php')), 0, strlen($directory)) == str_replace('\\', '/', $directory)) {
$_ = [];
include($directory . $language_info['code'] . '/' . $route . '.php');
foreach ($_ as $key => $value) {
$json[] = [
'key' => $key,
'value' => $value
];
}
}
$this->response->addHeader('Content-Type: application/json');
$this->response->setOutput(json_encode($json));
}
}