diff options
author | Jesús <heckyel@hyperbola.info> | 2019-08-18 21:14:58 -0500 |
---|---|---|
committer | Jesús <heckyel@hyperbola.info> | 2019-08-18 21:14:58 -0500 |
commit | 2eed7b082f83630301e51f57ca8394de228a8605 (patch) | |
tree | 1d19962d22d30f99317d9276e4bae7744fc93fc2 /public/admin/controller/design | |
download | librecart-2eed7b082f83630301e51f57ca8394de228a8605.tar.lz librecart-2eed7b082f83630301e51f57ca8394de228a8605.tar.xz librecart-2eed7b082f83630301e51f57ca8394de228a8605.zip |
first commit
Diffstat (limited to 'public/admin/controller/design')
-rw-r--r-- | public/admin/controller/design/banner.php | 399 | ||||
-rw-r--r-- | public/admin/controller/design/layout.php | 455 | ||||
-rw-r--r-- | public/admin/controller/design/seo_url.php | 544 | ||||
-rw-r--r-- | public/admin/controller/design/theme.php | 311 | ||||
-rw-r--r-- | public/admin/controller/design/translation.php | 509 |
5 files changed, 2218 insertions, 0 deletions
diff --git a/public/admin/controller/design/banner.php b/public/admin/controller/design/banner.php new file mode 100644 index 0000000..624a419 --- /dev/null +++ b/public/admin/controller/design/banner.php @@ -0,0 +1,399 @@ +<?php +class ControllerDesignBanner extends Controller { + private $error = array(); + + public function index() { + $this->load->language('design/banner'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('design/banner'); + + $this->getList(); + } + + public function add() { + $this->load->language('design/banner'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('design/banner'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validateForm()) { + $this->model_design_banner->addBanner($this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $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']; + } + + $this->response->redirect($this->url->link('design/banner', 'user_token=' . $this->session->data['user_token'] . $url, true)); + } + + $this->getForm(); + } + + public function edit() { + $this->load->language('design/banner'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('design/banner'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validateForm()) { + $this->model_design_banner->editBanner($this->request->get['banner_id'], $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $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']; + } + + $this->response->redirect($this->url->link('design/banner', 'user_token=' . $this->session->data['user_token'] . $url, true)); + } + + $this->getForm(); + } + + public function delete() { + $this->load->language('design/banner'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('design/banner'); + + if (isset($this->request->post['selected']) && $this->validateDelete()) { + foreach ($this->request->post['selected'] as $banner_id) { + $this->model_design_banner->deleteBanner($banner_id); + } + + $this->session->data['success'] = $this->language->get('text_success'); + + $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']; + } + + $this->response->redirect($this->url->link('design/banner', 'user_token=' . $this->session->data['user_token'] . $url, true)); + } + + $this->getList(); + } + + protected function getList() { + if (isset($this->request->get['sort'])) { + $sort = $this->request->get['sort']; + } else { + $sort = 'name'; + } + + if (isset($this->request->get['order'])) { + $order = $this->request->get['order']; + } else { + $order = 'ASC'; + } + + if (isset($this->request->get['page'])) { + $page = $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['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('design/banner', 'user_token=' . $this->session->data['user_token'] . $url, true) + ); + + $data['add'] = $this->url->link('design/banner/add', 'user_token=' . $this->session->data['user_token'] . $url, true); + $data['delete'] = $this->url->link('design/banner/delete', 'user_token=' . $this->session->data['user_token'] . $url, true); + + $data['banners'] = array(); + + $filter_data = array( + 'sort' => $sort, + 'order' => $order, + 'start' => ($page - 1) * $this->config->get('config_limit_admin'), + 'limit' => $this->config->get('config_limit_admin') + ); + + $banner_total = $this->model_design_banner->getTotalBanners(); + + $results = $this->model_design_banner->getBanners($filter_data); + + foreach ($results as $result) { + $data['banners'][] = array( + 'banner_id' => $result['banner_id'], + 'name' => $result['name'], + 'status' => ($result['status'] ? $this->language->get('text_enabled') : $this->language->get('text_disabled')), + 'edit' => $this->url->link('design/banner/edit', 'user_token=' . $this->session->data['user_token'] . '&banner_id=' . $result['banner_id'] . $url, true) + ); + } + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + if (isset($this->session->data['success'])) { + $data['success'] = $this->session->data['success']; + + unset($this->session->data['success']); + } else { + $data['success'] = ''; + } + + if (isset($this->request->post['selected'])) { + $data['selected'] = (array)$this->request->post['selected']; + } else { + $data['selected'] = array(); + } + + $url = ''; + + if ($order == 'ASC') { + $url .= '&order=DESC'; + } else { + $url .= '&order=ASC'; + } + + if (isset($this->request->get['page'])) { + $url .= '&page=' . $this->request->get['page']; + } + + $data['sort_name'] = $this->url->link('design/banner', 'user_token=' . $this->session->data['user_token'] . '&sort=name' . $url, true); + $data['sort_status'] = $this->url->link('design/banner', 'user_token=' . $this->session->data['user_token'] . '&sort=status' . $url, true); + + $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']; + } + + $pagination = new Pagination(); + $pagination->total = $banner_total; + $pagination->page = $page; + $pagination->limit = $this->config->get('config_limit_admin'); + $pagination->url = $this->url->link('design/banner', 'user_token=' . $this->session->data['user_token'] . $url . '&page={page}', true); + + $data['pagination'] = $pagination->render(); + + $data['results'] = sprintf($this->language->get('text_pagination'), ($banner_total) ? (($page - 1) * $this->config->get('config_limit_admin')) + 1 : 0, ((($page - 1) * $this->config->get('config_limit_admin')) > ($banner_total - $this->config->get('config_limit_admin'))) ? $banner_total : ((($page - 1) * $this->config->get('config_limit_admin')) + $this->config->get('config_limit_admin')), $banner_total, ceil($banner_total / $this->config->get('config_limit_admin'))); + + $data['sort'] = $sort; + $data['order'] = $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/banner_list', $data)); + } + + protected function getForm() { + $data['text_form'] = !isset($this->request->get['banner_id']) ? $this->language->get('text_add') : $this->language->get('text_edit'); + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + if (isset($this->error['name'])) { + $data['error_name'] = $this->error['name']; + } else { + $data['error_name'] = ''; + } + + if (isset($this->error['banner_image'])) { + $data['error_banner_image'] = $this->error['banner_image']; + } else { + $data['error_banner_image'] = array(); + } + + $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'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('design/banner', 'user_token=' . $this->session->data['user_token'] . $url, true) + ); + + if (!isset($this->request->get['banner_id'])) { + $data['action'] = $this->url->link('design/banner/add', 'user_token=' . $this->session->data['user_token'] . $url, true); + } else { + $data['action'] = $this->url->link('design/banner/edit', 'user_token=' . $this->session->data['user_token'] . '&banner_id=' . $this->request->get['banner_id'] . $url, true); + } + + $data['cancel'] = $this->url->link('design/banner', 'user_token=' . $this->session->data['user_token'] . $url, true); + + if (isset($this->request->get['banner_id']) && ($this->request->server['REQUEST_METHOD'] != 'POST')) { + $banner_info = $this->model_design_banner->getBanner($this->request->get['banner_id']); + } + + $data['user_token'] = $this->session->data['user_token']; + + if (isset($this->request->post['name'])) { + $data['name'] = $this->request->post['name']; + } elseif (!empty($banner_info)) { + $data['name'] = $banner_info['name']; + } else { + $data['name'] = ''; + } + + if (isset($this->request->post['status'])) { + $data['status'] = $this->request->post['status']; + } elseif (!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 (isset($this->request->post['banner_image'])) { + $banner_images = $this->request->post['banner_image']; + } elseif (isset($this->request->get['banner_id'])) { + $banner_images = $this->model_design_banner->getBannerImages($this->request->get['banner_id']); + } else { + $banner_images = array(); + } + + $data['banner_images'] = array(); + + foreach ($banner_images as $key => $value) { + foreach ($value as $banner_image) { + if (is_file(DIR_IMAGE . $banner_image['image'])) { + $image = $banner_image['image']; + $thumb = $banner_image['image']; + } else { + $image = ''; + $thumb = 'no_image.png'; + } + + $data['banner_images'][$key][] = array( + 'title' => $banner_image['title'], + 'link' => $banner_image['link'], + 'image' => $image, + 'thumb' => $this->model_tool_image->resize($thumb, 100, 100), + 'sort_order' => $banner_image['sort_order'] + ); + } + } + + $data['placeholder'] = $this->model_tool_image->resize('no_image.png', 100, 100); + + $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)); + } + + protected function validateForm() { + if (!$this->user->hasPermission('modify', 'design/banner')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + if ((utf8_strlen($this->request->post['name']) < 3) || (utf8_strlen($this->request->post['name']) > 64)) { + $this->error['name'] = $this->language->get('error_name'); + } + + if (isset($this->request->post['banner_image'])) { + foreach ($this->request->post['banner_image'] as $language_id => $value) { + foreach ($value as $banner_image_id => $banner_image) { + if ((utf8_strlen($banner_image['title']) < 2) || (utf8_strlen($banner_image['title']) > 64)) { + $this->error['banner_image'][$language_id][$banner_image_id] = $this->language->get('error_title'); + } + } + } + } + + return !$this->error; + } + + protected function validateDelete() { + if (!$this->user->hasPermission('modify', 'design/banner')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + return !$this->error; + } +}
\ No newline at end of file diff --git a/public/admin/controller/design/layout.php b/public/admin/controller/design/layout.php new file mode 100644 index 0000000..90acbb3 --- /dev/null +++ b/public/admin/controller/design/layout.php @@ -0,0 +1,455 @@ +<?php +class ControllerDesignLayout extends Controller { + private $error = array(); + + public function index() { + $this->load->language('design/layout'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('design/layout'); + + $this->getList(); + } + + public function add() { + $this->load->language('design/layout'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('design/layout'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validateForm()) { + $this->model_design_layout->addLayout($this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $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']; + } + + $this->response->redirect($this->url->link('design/layout', 'user_token=' . $this->session->data['user_token'] . $url, true)); + } + + $this->getForm(); + } + + public function edit() { + $this->load->language('design/layout'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('design/layout'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validateForm()) { + $this->model_design_layout->editLayout($this->request->get['layout_id'], $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $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']; + } + + $this->response->redirect($this->url->link('design/layout', 'user_token=' . $this->session->data['user_token'] . $url, true)); + } + + $this->getForm(); + } + + public function delete() { + $this->load->language('design/layout'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('design/layout'); + + if (isset($this->request->post['selected']) && $this->validateDelete()) { + foreach ($this->request->post['selected'] as $layout_id) { + $this->model_design_layout->deleteLayout($layout_id); + } + + $this->session->data['success'] = $this->language->get('text_success'); + + $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']; + } + + $this->response->redirect($this->url->link('design/layout', 'user_token=' . $this->session->data['user_token'] . $url, true)); + } + + $this->getList(); + } + + protected function getList() { + if (isset($this->request->get['sort'])) { + $sort = $this->request->get['sort']; + } else { + $sort = 'name'; + } + + if (isset($this->request->get['order'])) { + $order = $this->request->get['order']; + } else { + $order = 'ASC'; + } + + if (isset($this->request->get['page'])) { + $page = $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['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('design/layout', 'user_token=' . $this->session->data['user_token'] . $url, true) + ); + + $data['add'] = $this->url->link('design/layout/add', 'user_token=' . $this->session->data['user_token'] . $url, true); + $data['delete'] = $this->url->link('design/layout/delete', 'user_token=' . $this->session->data['user_token'] . $url, true); + + $data['layouts'] = array(); + + $filter_data = array( + 'sort' => $sort, + 'order' => $order, + 'start' => ($page - 1) * $this->config->get('config_limit_admin'), + 'limit' => $this->config->get('config_limit_admin') + ); + + $layout_total = $this->model_design_layout->getTotalLayouts(); + + $results = $this->model_design_layout->getLayouts($filter_data); + + foreach ($results as $result) { + $data['layouts'][] = array( + 'layout_id' => $result['layout_id'], + 'name' => $result['name'], + 'edit' => $this->url->link('design/layout/edit', 'user_token=' . $this->session->data['user_token'] . '&layout_id=' . $result['layout_id'] . $url, true) + ); + } + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + if (isset($this->session->data['success'])) { + $data['success'] = $this->session->data['success']; + + unset($this->session->data['success']); + } else { + $data['success'] = ''; + } + + if (isset($this->request->post['selected'])) { + $data['selected'] = (array)$this->request->post['selected']; + } else { + $data['selected'] = array(); + } + + $url = ''; + + if ($order == 'ASC') { + $url .= '&order=DESC'; + } else { + $url .= '&order=ASC'; + } + + if (isset($this->request->get['page'])) { + $url .= '&page=' . $this->request->get['page']; + } + + $data['sort_name'] = $this->url->link('design/layout', 'user_token=' . $this->session->data['user_token'] . '&sort=name' . $url, true); + + $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']; + } + + $pagination = new Pagination(); + $pagination->total = $layout_total; + $pagination->page = $page; + $pagination->limit = $this->config->get('config_limit_admin'); + $pagination->url = $this->url->link('design/layout', 'user_token=' . $this->session->data['user_token'] . $url . '&page={page}', true); + + $data['pagination'] = $pagination->render(); + + $data['results'] = sprintf($this->language->get('text_pagination'), ($layout_total) ? (($page - 1) * $this->config->get('config_limit_admin')) + 1 : 0, ((($page - 1) * $this->config->get('config_limit_admin')) > ($layout_total - $this->config->get('config_limit_admin'))) ? $layout_total : ((($page - 1) * $this->config->get('config_limit_admin')) + $this->config->get('config_limit_admin')), $layout_total, ceil($layout_total / $this->config->get('config_limit_admin'))); + + $data['sort'] = $sort; + $data['order'] = $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/layout_list', $data)); + } + + protected function getForm() { + $data['text_form'] = !isset($this->request->get['layout_id']) ? $this->language->get('text_add') : $this->language->get('text_edit'); + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + if (isset($this->error['name'])) { + $data['error_name'] = $this->error['name']; + } else { + $data['error_name'] = ''; + } + + $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'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('design/layout', 'user_token=' . $this->session->data['user_token'] . $url, true) + ); + + if (!isset($this->request->get['layout_id'])) { + $data['action'] = $this->url->link('design/layout/add', 'user_token=' . $this->session->data['user_token'] . $url, true); + } else { + $data['action'] = $this->url->link('design/layout/edit', 'user_token=' . $this->session->data['user_token'] . '&layout_id=' . $this->request->get['layout_id'] . $url, true); + } + + $data['cancel'] = $this->url->link('design/layout', 'user_token=' . $this->session->data['user_token'] . $url, true); + + $data['user_token'] = $this->session->data['user_token']; + + if (isset($this->request->get['layout_id']) && ($this->request->server['REQUEST_METHOD'] != 'POST')) { + $layout_info = $this->model_design_layout->getLayout($this->request->get['layout_id']); + } + + if (isset($this->request->post['name'])) { + $data['name'] = $this->request->post['name']; + } elseif (!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->post['layout_route'])) { + $data['layout_routes'] = $this->request->post['layout_route']; + } elseif (isset($this->request->get['layout_id'])) { + $data['layout_routes'] = $this->model_design_layout->getLayoutRoutes($this->request->get['layout_id']); + } else { + $data['layout_routes'] = array(); + } + + $this->load->model('setting/extension'); + + $this->load->model('setting/module'); + + $data['extensions'] = array(); + + // Get a list of installed modules + $extensions = $this->model_setting_extension->getInstalled('module'); + + // Add all the modules which have multiple settings for each module + foreach ($extensions as $code) { + $this->load->language('extension/module/' . $code, 'extension'); + + $module_data = array(); + + $modules = $this->model_setting_module->getModulesByCode($code); + + foreach ($modules as $module) { + $module_data[] = array( + 'name' => strip_tags($module['name']), + 'code' => $code . '.' . $module['module_id'] + ); + } + + if ($this->config->has('module_' . $code . '_status') || $module_data) { + $data['extensions'][] = array( + 'name' => strip_tags($this->language->get('extension')->get('heading_title')), + 'code' => $code, + 'module' => $module_data + ); + } + } + + // Modules layout + if (isset($this->request->post['layout_module'])) { + $layout_modules = $this->request->post['layout_module']; + } elseif (isset($this->request->get['layout_id'])) { + $layout_modules = $this->model_design_layout->getLayoutModules($this->request->get['layout_id']); + } else { + $layout_modules = array(); + } + + $data['layout_modules'] = array(); + + // Add all the modules which have multiple settings for each module + foreach ($layout_modules as $layout_module) { + $part = explode('.', $layout_module['code']); + + $this->load->language('extension/module/' . $part[0]); + + if (!isset($part[1])) { + $data['layout_modules'][] = array( + 'name' => strip_tags($this->language->get('heading_title')), + 'code' => $layout_module['code'], + 'edit' => $this->url->link('extension/module/' . $part[0], 'user_token=' . $this->session->data['user_token'], true), + 'position' => $layout_module['position'], + 'sort_order' => $layout_module['sort_order'] + ); + } else { + $module_info = $this->model_setting_module->getModule($part[1]); + + if ($module_info) { + $data['layout_modules'][] = array( + 'name' => strip_tags($module_info['name']), + 'code' => $layout_module['code'], + 'edit' => $this->url->link('extension/module/' . $part[0], 'user_token=' . $this->session->data['user_token'] . '&module_id=' . $part[1], true), + 'position' => $layout_module['position'], + 'sort_order' => $layout_module['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/layout_form', $data)); + } + + protected function validateForm() { + if (!$this->user->hasPermission('modify', 'design/layout')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + if ((utf8_strlen($this->request->post['name']) < 3) || (utf8_strlen($this->request->post['name']) > 64)) { + $this->error['name'] = $this->language->get('error_name'); + } + + return !$this->error; + } + + protected function validateDelete() { + if (!$this->user->hasPermission('modify', 'design/layout')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + $this->load->model('setting/store'); + $this->load->model('catalog/product'); + $this->load->model('catalog/category'); + $this->load->model('catalog/information'); + + foreach ($this->request->post['selected'] as $layout_id) { + if ($this->config->get('config_layout_id') == $layout_id) { + $this->error['warning'] = $this->language->get('error_default'); + } + + $store_total = $this->model_setting_store->getTotalStoresByLayoutId($layout_id); + + if ($store_total) { + $this->error['warning'] = sprintf($this->language->get('error_store'), $store_total); + } + + $product_total = $this->model_catalog_product->getTotalProductsByLayoutId($layout_id); + + if ($product_total) { + $this->error['warning'] = sprintf($this->language->get('error_product'), $product_total); + } + + $category_total = $this->model_catalog_category->getTotalCategoriesByLayoutId($layout_id); + + if ($category_total) { + $this->error['warning'] = sprintf($this->language->get('error_category'), $category_total); + } + + $information_total = $this->model_catalog_information->getTotalInformationsByLayoutId($layout_id); + + if ($information_total) { + $this->error['warning'] = sprintf($this->language->get('error_information'), $information_total); + } + } + + return !$this->error; + } +} diff --git a/public/admin/controller/design/seo_url.php b/public/admin/controller/design/seo_url.php new file mode 100644 index 0000000..a00e566 --- /dev/null +++ b/public/admin/controller/design/seo_url.php @@ -0,0 +1,544 @@ +<?php +class ControllerDesignSeoUrl extends Controller { + private $error = array(); + + public function index() { + $this->load->language('design/seo_url'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('design/seo_url'); + + $this->getList(); + } + + public function add() { + $this->load->language('design/seo_url'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('design/seo_url'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validateForm()) { + $this->model_design_seo_url->addSeoUrl($this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $url = ''; + + if (isset($this->request->get['filter_query'])) { + $url .= '&filter_query=' . urlencode(html_entity_decode($this->request->get['filter_query'], ENT_QUOTES, 'UTF-8')); + } + + if (isset($this->request->get['filter_keyword'])) { + $url .= '&filter_keyword=' . urlencode(html_entity_decode($this->request->get['filter_keyword'], ENT_QUOTES, 'UTF-8')); + } + + if (isset($this->request->get['filter_store_id'])) { + $url .= '&filter_store_id=' . $this->request->get['filter_store_id']; + } + + if (isset($this->request->get['filter_language_id'])) { + $url .= '&filter_language_id=' . $this->request->get['filter_language_id']; + } + + 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']; + } + + $this->response->redirect($this->url->link('design/seo_url', 'user_token=' . $this->session->data['user_token'] . $url, true)); + } + + $this->getForm(); + } + + public function edit() { + $this->load->language('design/seo_url'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('design/seo_url'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validateForm()) { + $this->model_design_seo_url->editSeoUrl($this->request->get['seo_url_id'], $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $url = ''; + + if (isset($this->request->get['filter_query'])) { + $url .= '&filter_query=' . urlencode(html_entity_decode($this->request->get['filter_query'], ENT_QUOTES, 'UTF-8')); + } + + if (isset($this->request->get['filter_keyword'])) { + $url .= '&filter_keyword=' . urlencode(html_entity_decode($this->request->get['filter_keyword'], ENT_QUOTES, 'UTF-8')); + } + + if (isset($this->request->get['filter_store_id'])) { + $url .= '&filter_store_id=' . $this->request->get['filter_store_id']; + } + + if (isset($this->request->get['filter_language_id'])) { + $url .= '&filter_language_id=' . $this->request->get['filter_language_id']; + } + + 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']; + } + + $this->response->redirect($this->url->link('design/seo_url', 'user_token=' . $this->session->data['user_token'] . $url, true)); + } + + $this->getForm(); + } + + public function delete() { + $this->load->language('design/seo_url'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('design/seo_url'); + + if (isset($this->request->post['selected']) && $this->validateDelete()) { + foreach ($this->request->post['selected'] as $seo_url_id) { + $this->model_design_seo_url->deleteSeoUrl($seo_url_id); + } + + $this->session->data['success'] = $this->language->get('text_success'); + + $url = ''; + + if (isset($this->request->get['filter_query'])) { + $url .= '&filter_query=' . urlencode(html_entity_decode($this->request->get['filter_query'], ENT_QUOTES, 'UTF-8')); + } + + if (isset($this->request->get['filter_keyword'])) { + $url .= '&filter_keyword=' . urlencode(html_entity_decode($this->request->get['filter_keyword'], ENT_QUOTES, 'UTF-8')); + } + + if (isset($this->request->get['filter_store_id'])) { + $url .= '&filter_store_id=' . $this->request->get['filter_store_id']; + } + + if (isset($this->request->get['filter_language_id'])) { + $url .= '&filter_language_id=' . $this->request->get['filter_language_id']; + } + + 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']; + } + + $this->response->redirect($this->url->link('design/seo_url', 'user_token=' . $this->session->data['user_token'] . $url, true)); + } + + $this->getList(); + } + + protected function getList() { + if (isset($this->request->get['filter_query'])) { + $filter_query = $this->request->get['filter_query']; + } else { + $filter_query = ''; + } + + if (isset($this->request->get['filter_keyword'])) { + $filter_keyword = $this->request->get['filter_keyword']; + } else { + $filter_keyword = ''; + } + + if (isset($this->request->get['filter_store_id'])) { + $filter_store_id = $this->request->get['filter_store_id']; + } else { + $filter_store_id = ''; + } + + if (isset($this->request->get['filter_language_id'])) { + $filter_language_id = $this->request->get['filter_language_id']; + } else { + $filter_language_id = ''; + } + + if (isset($this->request->get['sort'])) { + $sort = $this->request->get['sort']; + } else { + $sort = 'keyword'; + } + + if (isset($this->request->get['order'])) { + $order = $this->request->get['order']; + } else { + $order = 'ASC'; + } + + if (isset($this->request->get['page'])) { + $page = $this->request->get['page']; + } else { + $page = 1; + } + + $url = ''; + + if (isset($this->request->get['filter_query'])) { + $url .= '&filter_query=' . urlencode(html_entity_decode($this->request->get['filter_query'], ENT_QUOTES, 'UTF-8')); + } + + if (isset($this->request->get['filter_keyword'])) { + $url .= '&filter_keyword=' . urlencode(html_entity_decode($this->request->get['filter_keyword'], ENT_QUOTES, 'UTF-8')); + } + + if (isset($this->request->get['filter_store_id'])) { + $url .= '&filter_store_id=' . $this->request->get['filter_store_id']; + } + + if (isset($this->request->get['filter_language_id'])) { + $url .= '&filter_language_id=' . $this->request->get['filter_language_id']; + } + + 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'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('design/seo_url', 'user_token=' . $this->session->data['user_token'] . $url, true) + ); + + $data['add'] = $this->url->link('design/seo_url/add', 'user_token=' . $this->session->data['user_token'] . $url, true); + $data['delete'] = $this->url->link('design/seo_url/delete', 'user_token=' . $this->session->data['user_token'] . $url, true); + + $data['seo_urls'] = array(); + + $filter_data = array( + 'filter_query' => $filter_query, + 'filter_keyword' => $filter_keyword, + 'filter_store_id' => $filter_store_id, + 'filter_language_id' => $filter_language_id, + 'sort' => $sort, + 'order' => $order, + 'start' => ($page - 1) * $this->config->get('config_limit_admin'), + 'limit' => $this->config->get('config_limit_admin') + ); + + $seo_url_total = $this->model_design_seo_url->getTotalSeoUrls($filter_data); + + $results = $this->model_design_seo_url->getSeoUrls($filter_data); + + foreach ($results as $result) { + $data['seo_urls'][] = array( + 'seo_url_id' => $result['seo_url_id'], + 'query' => $result['query'], + 'keyword' => $result['keyword'], + 'store' => $result['store_id'] ? $result['store'] : $this->language->get('text_default'), + 'language' => $result['language'], + 'edit' => $this->url->link('design/seo_url/edit', 'user_token=' . $this->session->data['user_token'] . '&seo_url_id=' . $result['seo_url_id'] . $url, true) + ); + } + + $data['user_token'] = $this->session->data['user_token']; + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + if (isset($this->session->data['success'])) { + $data['success'] = $this->session->data['success']; + + unset($this->session->data['success']); + } else { + $data['success'] = ''; + } + + if (isset($this->request->post['selected'])) { + $data['selected'] = (array)$this->request->post['selected']; + } else { + $data['selected'] = array(); + } + + $url = ''; + + if (isset($this->request->get['filter_query'])) { + $url .= '&filter_query=' . urlencode(html_entity_decode($this->request->get['filter_query'], ENT_QUOTES, 'UTF-8')); + } + + if (isset($this->request->get['filter_keyword'])) { + $url .= '&filter_keyword=' . urlencode(html_entity_decode($this->request->get['filter_keyword'], ENT_QUOTES, 'UTF-8')); + } + + if (isset($this->request->get['filter_store_id'])) { + $url .= '&filter_store_id=' . $this->request->get['filter_store_id']; + } + + if (isset($this->request->get['filter_language_id'])) { + $url .= '&filter_language_id=' . $this->request->get['filter_language_id']; + } + + if ($order == 'ASC') { + $url .= '&order=DESC'; + } else { + $url .= '&order=ASC'; + } + + if (isset($this->request->get['page'])) { + $url .= '&page=' . $this->request->get['page']; + } + + $data['sort_query'] = $this->url->link('design/seo_url', 'user_token=' . $this->session->data['user_token'] . '&sort=query' . $url, true); + $data['sort_keyword'] = $this->url->link('design/seo_url', 'user_token=' . $this->session->data['user_token'] . '&sort=keyword' . $url, true); + $data['sort_store'] = $this->url->link('design/seo_url', 'user_token=' . $this->session->data['user_token'] . '&sort=store' . $url, true); + $data['sort_language'] = $this->url->link('design/seo_url', 'user_token=' . $this->session->data['user_token'] . '&sort=language' . $url, true); + + $url = ''; + + if (isset($this->request->get['filter_query'])) { + $url .= '&filter_query=' . urlencode(html_entity_decode($this->request->get['filter_query'], ENT_QUOTES, 'UTF-8')); + } + + if (isset($this->request->get['filter_keyword'])) { + $url .= '&filter_keyword=' . urlencode(html_entity_decode($this->request->get['filter_keyword'], ENT_QUOTES, 'UTF-8')); + } + + if (isset($this->request->get['filter_store_id'])) { + $url .= '&filter_store_id=' . $this->request->get['filter_store_id']; + } + + if (isset($this->request->get['filter_language_id'])) { + $url .= '&filter_language_id=' . $this->request->get['filter_language_id']; + } + + if (isset($this->request->get['sort'])) { + $url .= '&sort=' . $this->request->get['sort']; + } + + if (isset($this->request->get['order'])) { + $url .= '&order=' . $this->request->get['order']; + } + + $pagination = new Pagination(); + $pagination->total = $seo_url_total; + $pagination->page = $page; + $pagination->limit = $this->config->get('config_limit_admin'); + $pagination->url = $this->url->link('design/seo_url', 'user_token=' . $this->session->data['user_token'] . $url . '&page={page}', true); + + $data['pagination'] = $pagination->render(); + + $data['results'] = sprintf($this->language->get('text_pagination'), ($seo_url_total) ? (($page - 1) * $this->config->get('config_limit_admin')) + 1 : 0, ((($page - 1) * $this->config->get('config_limit_admin')) > ($seo_url_total - $this->config->get('config_limit_admin'))) ? $seo_url_total : ((($page - 1) * $this->config->get('config_limit_admin')) + $this->config->get('config_limit_admin')), $seo_url_total, ceil($seo_url_total / $this->config->get('config_limit_admin'))); + + $data['filter_query'] = $filter_query; + $data['filter_keyword'] = $filter_keyword; + $data['filter_store_id'] = $filter_store_id; + $data['filter_language_id'] = $filter_language_id; + + $data['sort'] = $sort; + $data['order'] = $order; + + $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['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_list', $data)); + } + + protected function getForm() { + $data['text_form'] = !isset($this->request->get['seo_url_id']) ? $this->language->get('text_add') : $this->language->get('text_edit'); + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + if (isset($this->error['query'])) { + $data['error_query'] = $this->error['query']; + } else { + $data['error_query'] = ''; + } + + if (isset($this->error['keyword'])) { + $data['error_keyword'] = $this->error['keyword']; + } else { + $data['error_keyword'] = ''; + } + + $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'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('design/seo_url', 'user_token=' . $this->session->data['user_token'] . $url, true) + ); + + if (!isset($this->request->get['seo_url_id'])) { + $data['action'] = $this->url->link('design/seo_url/add', 'user_token=' . $this->session->data['user_token'] . $url, true); + } else { + $data['action'] = $this->url->link('design/seo_url/edit', 'user_token=' . $this->session->data['user_token'] . '&seo_url_id=' . $this->request->get['seo_url_id'] . $url, true); + } + + $data['cancel'] = $this->url->link('design/seo_url', 'user_token=' . $this->session->data['user_token'] . $url, true); + + if (isset($this->request->get['seo_url_id']) && ($this->request->server['REQUEST_METHOD'] != 'POST')) { + $seo_url_info = $this->model_design_seo_url->getSeoUrl($this->request->get['seo_url_id']); + } + + if (isset($this->request->post['query'])) { + $data['query'] = $this->request->post['query']; + } elseif (!empty($seo_url_info)) { + $data['query'] = $seo_url_info['query']; + } else { + $data['query'] = ''; + } + + if (isset($this->request->post['keyword'])) { + $data['keyword'] = $this->request->post['keyword']; + } elseif (!empty($seo_url_info)) { + $data['keyword'] = $seo_url_info['keyword']; + } else { + $data['keyword'] = ''; + } + + $this->load->model('setting/store'); + + $data['stores'] = array(); + + $data['stores'][] = array( + 'store_id' => 0, + 'name' => $this->language->get('text_default') + ); + + $stores = $this->model_setting_store->getStores(); + + foreach ($stores as $store) { + $data['stores'][] = array( + 'store_id' => $store['store_id'], + 'name' => $store['name'] + ); + } + + if (isset($this->request->post['store_id'])) { + $data['store_id'] = $this->request->post['store_id']; + } elseif (!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 (isset($this->request->post['language_id'])) { + $data['language_id'] = $this->request->post['language_id']; + } elseif (!empty($seo_url_info)) { + $data['language_id'] = $seo_url_info['language_id']; + } else { + $data['language_id'] = ''; + } + + $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)); + } + + protected function validateForm() { + if (!$this->user->hasPermission('modify', 'design/seo_url')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + if (!$this->request->post['query']) { + $this->error['query'] = $this->language->get('error_query'); + } + + $seo_urls = $this->model_design_seo_url->getSeoUrlsByKeyword($this->request->post['keyword']); + + foreach ($seo_urls as $seo_url) { + if ($seo_url['store_id'] == $this->request->post['store_id'] && $seo_url['query'] != $this->request->post['query']) { + $this->error['keyword'] = $this->language->get('error_exists'); + + break; + } + } + + if (!$this->request->post['keyword']) { + $this->error['keyword'] = $this->language->get('error_keyword'); + } + + return !$this->error; + } + + protected function validateDelete() { + if (!$this->user->hasPermission('modify', 'design/seo_url')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + return !$this->error; + } +}
\ No newline at end of file diff --git a/public/admin/controller/design/theme.php b/public/admin/controller/design/theme.php new file mode 100644 index 0000000..839d03f --- /dev/null +++ b/public/admin/controller/design/theme.php @@ -0,0 +1,311 @@ +<?php +class ControllerDesignTheme extends Controller { + public function index() { + $this->load->language('design/theme'); + + $this->document->setTitle($this->language->get('heading_title')); + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('design/theme', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['user_token'] = $this->session->data['user_token']; + + $data['stores'] = array(); + + $this->load->model('setting/store'); + + $results = $this->model_setting_store->getStores(); + + foreach ($results as $result) { + $data['stores'][] = array( + 'store_id' => $result['store_id'], + 'name' => $result['name'] + ); + } + + $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)); + } + + public function history() { + $this->load->language('design/theme'); + + if (isset($this->request->get['page'])) { + $page = $this->request->get['page']; + } else { + $page = 1; + } + + $data['histories'] = array(); + + $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) * 10, 10); + + 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'][] = array( + 'store_id' => $result['store_id'], + 'store' => ($result['store_id'] ? $store : $this->language->get('text_default')), + 'route' => $result['route'], + 'theme' => $result['theme'], + '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'], true), + 'delete' => $this->url->link('design/theme/delete', 'user_token=' . $this->session->data['user_token'] . '&theme_id=' . $result['theme_id'], true) + ); + } + + $pagination = new Pagination(); + $pagination->total = $history_total; + $pagination->page = $page; + $pagination->limit = 10; + $pagination->url = $this->url->link('design/theme/history', 'user_token=' . $this->session->data['user_token'] . '&page={page}', true); + + $data['pagination'] = $pagination->render(); + + $data['results'] = sprintf($this->language->get('text_pagination'), ($history_total) ? (($page - 1) * 10) + 1 : 0, ((($page - 1) * 10) > ($history_total - 10)) ? $history_total : ((($page - 1) * 10) + 10), $history_total, ceil($history_total / 10)); + + $this->response->setOutput($this->load->view('design/theme_history', $data)); + } + + public function path() { + $this->load->language('design/theme'); + + $json = array(); + + if (isset($this->request->get['store_id'])) { + $store_id = $this->request->get['store_id']; + } else { + $store_id = 0; + } + + $this->load->model('setting/setting'); + + $theme = $this->model_setting_setting->getSettingValue('config_theme', $store_id); + + // This is only here for compatibility with old themes. + if ($theme == 'theme_default') { + $theme = $this->model_setting_setting->getSettingValue('theme_default_directory', $store_id); + } + + if (isset($this->request->get['path'])) { + $path = $this->request->get['path']; + } else { + $path = ''; + } + + if (substr(str_replace('\\', '/', realpath(DIR_CATALOG . 'view/theme/default/template/' . $path)), 0, strlen(DIR_CATALOG . 'view')) == DIR_CATALOG . 'view') { + $path_data = array(); + + // We grab the files from the default theme directory first as the custom themes drops back to the default theme if selected theme files can not be found. + $files = glob(rtrim(DIR_CATALOG . 'view/theme/{default,' . $theme . '}/template/' . $path, '/') . '/*', GLOB_BRACE); + + if ($files) { + foreach($files as $file) { + if (!in_array(basename($file), $path_data)) { + if (is_dir($file)) { + $json['directory'][] = array( + 'name' => basename($file), + 'path' => trim($path . '/' . basename($file), '/') + ); + } + + if (is_file($file)) { + $json['file'][] = array( + 'name' => basename($file), + 'path' => trim($path . '/' . basename($file), '/') + ); + } + + $path_data[] = basename($file); + } + } + } + } + + if (!empty($this->request->get['path'])) { + $json['back'] = array( + '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)); + } + + public function template() { + $this->load->language('design/theme'); + + $json = array(); + + if (isset($this->request->get['store_id'])) { + $store_id = $this->request->get['store_id']; + } else { + $store_id = 0; + } + + $this->load->model('setting/setting'); + + $theme = $this->model_setting_setting->getSettingValue('config_theme', $store_id); + + // This is only here for compatibility with old themes. + if ($theme == 'theme_default') { + $theme = $this->model_setting_setting->getSettingValue('theme_default_directory', $store_id); + } + + if (isset($this->request->get['path'])) { + $path = $this->request->get['path']; + } else { + $path = ''; + } + + $this->load->model('design/theme'); + + $theme_info = $this->model_design_theme->getTheme($store_id, $theme, $path); + + if ($theme_info) { + $json['code'] = html_entity_decode($theme_info['code']); + } elseif (is_file(DIR_CATALOG . 'view/theme/' . $theme . '/template/' . $path) && (substr(str_replace('\\', '/', realpath(DIR_CATALOG . 'view/theme/' . $theme . '/template/' . $path)), 0, strlen(DIR_CATALOG . 'view')) == DIR_CATALOG . 'view')) { + $json['code'] = file_get_contents(DIR_CATALOG . 'view/theme/' . $theme . '/template/' . $path); + } elseif (is_file(DIR_CATALOG . 'view/theme/default/template/' . $path) && (substr(str_replace('\\', '/', realpath(DIR_CATALOG . 'view/theme/default/template/' . $path)), 0, strlen(DIR_CATALOG . 'view')) == DIR_CATALOG . 'view')) { + $json['code'] = file_get_contents(DIR_CATALOG . 'view/theme/default/template/' . $path); + } + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } + + public function save() { + $this->load->language('design/theme'); + + $json = array(); + + if (isset($this->request->get['store_id'])) { + $store_id = $this->request->get['store_id']; + } else { + $store_id = 0; + } + + $this->load->model('setting/setting'); + + $theme = $this->model_setting_setting->getSettingValue('config_theme', $store_id); + + // This is only here for compatibility with old themes. + if ($theme == 'theme_default') { + $theme = $this->model_setting_setting->getSettingValue('theme_default_directory', $store_id); + } + + 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, $theme, ($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)); + } + + public function reset() { + $this->load->language('design/theme'); + + $json = array(); + + if (isset($this->request->get['store_id'])) { + $store_id = $this->request->get['store_id']; + } else { + $store_id = 0; + } + + $this->load->model('setting/setting'); + + $theme = $this->model_setting_setting->getSettingValue('config_theme', $store_id); + + // This is only here for compatibility with old themes. + if ($theme == 'theme_default') { + $theme = $this->model_setting_setting->getSettingValue('theme_default_directory', $store_id); + } + + if (isset($this->request->get['path'])) { + $path = $this->request->get['path']; + } else { + $path = ''; + } + + if (is_file(DIR_CATALOG . 'view/theme/' . $theme . '/template/' . $path) && (substr(str_replace('\\', '/', realpath(DIR_CATALOG . 'view/theme/' . $theme . '/template/' . $path)), 0, strlen(DIR_CATALOG . 'view')) == DIR_CATALOG . 'view')) { + $json['code'] = file_get_contents(DIR_CATALOG . 'view/theme/' . $theme . '/template/' . $path); + } + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } + + public function delete() { + $this->load->language('design/theme'); + + $json = array(); + + if (isset($this->request->get['theme_id'])) { + $theme_id = $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)); + } +} diff --git a/public/admin/controller/design/translation.php b/public/admin/controller/design/translation.php new file mode 100644 index 0000000..0740ec1 --- /dev/null +++ b/public/admin/controller/design/translation.php @@ -0,0 +1,509 @@ +<?php +class ControllerDesignTranslation extends Controller { + private $error = array(); + + public function index() { + $this->load->language('design/translation'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('design/translation'); + + $this->getList(); + } + + public function add() { + $this->load->language('design/translation'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('design/translation'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validateForm()) { + $this->model_design_translation->addTranslation($this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $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']; + } + + $this->response->redirect($this->url->link('design/translation', 'user_token=' . $this->session->data['user_token'] . $url, true)); + } + + $this->getForm(); + } + + public function edit() { + $this->load->language('design/translation'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('design/translation'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validateForm()) { + $this->model_design_translation->editTranslation($this->request->get['translation_id'], $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $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']; + } + + $this->response->redirect($this->url->link('design/translation', 'user_token=' . $this->session->data['user_token'] . $url, true)); + } + + $this->getForm(); + } + + public function delete() { + $this->load->language('design/translation'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('design/translation'); + + if (isset($this->request->post['selected']) && $this->validateDelete()) { + foreach ($this->request->post['selected'] as $translation_id) { + $this->model_design_translation->deleteTranslation($translation_id); + } + + $this->session->data['success'] = $this->language->get('text_success'); + + $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']; + } + + $this->response->redirect($this->url->link('design/translation', 'user_token=' . $this->session->data['user_token'] . $url, true)); + } + + $this->getList(); + } + + protected function getList() { + if (isset($this->request->get['sort'])) { + $sort = $this->request->get['sort']; + } else { + $sort = 'store'; + } + + if (isset($this->request->get['order'])) { + $order = $this->request->get['order']; + } else { + $order = 'ASC'; + } + + if (isset($this->request->get['page'])) { + $page = $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['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('design/translation', 'user_token=' . $this->session->data['user_token'], true) + ); + + $this->load->model('localisation/language'); + + $data['add'] = $this->url->link('design/translation/add', 'user_token=' . $this->session->data['user_token'] . $url, true); + $data['delete'] = $this->url->link('design/translation/delete', 'user_token=' . $this->session->data['user_token'] . $url, true); + + $data['translations'] = array(); + + $filter_data = array( + 'sort' => $sort, + 'order' => $order, + 'start' => ($page - 1) * $this->config->get('config_limit_admin'), + 'limit' => $this->config->get('config_limit_admin') + ); + + $translation_total = $this->model_design_translation->getTotalTranslations(); + + $results = $this->model_design_translation->getTranslations($filter_data); + + foreach ($results as $result) { + $data['translations'][] = array( + 'translation_id' => $result['translation_id'], + 'store' => ($result['store_id'] ? $result['store'] : $this->language->get('text_default')), + 'route' => $result['route'], + 'language' => $result['language'], + 'key' => $result['key'], + 'value' => $result['value'], + 'edit' => $this->url->link('design/translation/edit', 'user_token=' . $this->session->data['user_token'] . '&translation_id=' . $result['translation_id'], true), + ); + } + + $data['user_token'] = $this->session->data['user_token']; + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + if (isset($this->session->data['success'])) { + $data['success'] = $this->session->data['success']; + + unset($this->session->data['success']); + } else { + $data['success'] = ''; + } + + if (isset($this->request->post['selected'])) { + $data['selected'] = (array)$this->request->post['selected']; + } else { + $data['selected'] = array(); + } + + $url = ''; + + if ($order == 'ASC') { + $url .= '&order=DESC'; + } else { + $url .= '&order=ASC'; + } + + if (isset($this->request->get['page'])) { + $url .= '&page=' . $this->request->get['page']; + } + + $data['sort_store'] = $this->url->link('design/translation', 'user_token=' . $this->session->data['user_token'] . '&sort=store' . $url, true); + $data['sort_language'] = $this->url->link('design/translation', 'user_token=' . $this->session->data['user_token'] . '&sort=language' . $url, true); + $data['sort_route'] = $this->url->link('design/translation', 'user_token=' . $this->session->data['user_token'] . '&sort=route' . $url, true); + $data['sort_key'] = $this->url->link('design/translation', 'user_token=' . $this->session->data['user_token'] . '&sort=key' . $url, true); + $data['sort_value'] = $this->url->link('design/translation', 'user_token=' . $this->session->data['user_token'] . '&sort=value' . $url, true); + + $pagination = new Pagination(); + $pagination->total = $translation_total; + $pagination->page = $page; + $pagination->limit = 10; + $pagination->url = $this->url->link('design/translation/history', 'user_token=' . $this->session->data['user_token'] . '&page={page}', true); + + $data['pagination'] = $pagination->render(); + + $data['results'] = sprintf($this->language->get('text_pagination'), ($translation_total) ? (($page - 1) * $this->config->get('config_limit_admin')) + 1 : 0, ((($page - 1) * $this->config->get('config_limit_admin')) > ($translation_total - $this->config->get('config_limit_admin'))) ? $translation_total : ((($page - 1) * $this->config->get('config_limit_admin')) + $this->config->get('config_limit_admin')), $translation_total, ceil($translation_total / $this->config->get('config_limit_admin'))); + + $data['sort'] = $sort; + $data['order'] = $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/translation_list', $data)); + } + + protected function getForm() { + $data['text_form'] = !isset($this->request->get['translation_id']) ? $this->language->get('text_add') : $this->language->get('text_edit'); + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + if (isset($this->error['key'])) { + $data['error_key'] = $this->error['key']; + } else { + $data['error_key'] = ''; + } + + $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'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('design/translation', 'user_token=' . $this->session->data['user_token'] . $url, true) + ); + + if (!isset($this->request->get['translation_id'])) { + $data['action'] = $this->url->link('design/translation/add', 'user_token=' . $this->session->data['user_token'] . $url, true); + } else { + $data['action'] = $this->url->link('design/translation/edit', 'user_token=' . $this->session->data['user_token'] . '&translation_id=' . $this->request->get['translation_id'] . $url, true); + } + + $data['cancel'] = $this->url->link('design/translation', 'user_token=' . $this->session->data['user_token'] . $url, true); + + $data['user_token'] = $this->session->data['user_token']; + + if (isset($this->request->get['translation_id']) && ($this->request->server['REQUEST_METHOD'] != 'POST')) { + $translation_info = $this->model_design_translation->getTranslation($this->request->get['translation_id']); + } + + $this->load->model('setting/store'); + + $data['stores'] = $this->model_setting_store->getStores(); + + if (isset($this->request->post['store_id'])) { + $data['store_id'] = $this->request->post['store_id']; + } elseif (!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)) { + $language = $this->model_localisation_language->getLanguage($translation_info['language_id']); + $code = $language['code']; + } else { + $code = $this->config->get('config_language'); + $language = $this->model_localisation_language->getLanguageByCode($code); + } + + if (isset($this->request->post['language_id'])) { + $data['language_id'] = $this->request->post['language_id']; + } elseif (!empty($translation_info)) { + $data['language_id'] = $translation_info['language_id']; + } else { + $data['language_id'] = $language['language_id']; + } + + if (empty($translation_info)) { + // Get a list of files ready to upload + $data['paths'] = array(); + + $path = glob(DIR_CATALOG . 'language/'.$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') { + $data['paths'][] = substr(substr($file, strlen(DIR_CATALOG . 'language/'.$code.'/')), 0, -4); + } + } + } + } + + if (isset($this->request->post['route'])) { + $data['route'] = $this->request->post['route']; + } elseif (!empty($translation_info)) { + $data['route'] = $translation_info['route']; + } else { + $data['route'] = ''; + } + + if (isset($this->request->post['key'])) { + $data['key'] = $this->request->post['key']; + } elseif (!empty($translation_info)) { + $data['key'] = $translation_info['key']; + } else { + $data['key'] = ''; + } + + if (!empty($translation_info)) { + $directory = DIR_CATALOG . 'language/'; + + if (is_file($directory . $code . '/' . $translation_info['route'] . '.php') && substr(str_replace('\\', '/', realpath($directory . $code . '/' . $translation_info['route'] . '.php')), 0, strlen($directory)) == str_replace('\\', '/', $directory)) { + $_ = array(); + + include($directory . $code . '/' . $translation_info['route'] . '.php'); + + foreach ($_ as $key => $value) { + if ($translation_info['key'] == $key) { + $data['default'] = $value; + } + } + + if (empty($data['default'])) { + $data['default'] = $translation_info['value']; + } + } + } + + if (isset($this->request->post['value'])) { + $data['value'] = $this->request->post['value']; + } elseif (!empty($translation_info)) { + $data['value'] = $translation_info['value']; + } else { + $data['value'] = ''; + } + + $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)); + } + + protected function validateForm() { + if (!$this->user->hasPermission('modify', 'design/translation')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + if ((utf8_strlen($this->request->post['key']) < 3) || (utf8_strlen($this->request->post['key']) > 64)) { + $this->error['key'] = $this->language->get('error_key'); + } + + return !$this->error; + } + + protected function validateDelete() { + if (!$this->user->hasPermission('modify', 'design/translation')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + return !$this->error; + } + + public function path() { + $this->load->language('design/translation'); + + $json = array(); + + if (isset($this->request->get['language_id'])) { + $language_id = $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); + } + } + } + } + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } + + public function translation() { + $this->load->language('design/translation'); + + $json = array(); + + if (isset($this->request->get['store_id'])) { + $store_id = $this->request->get['store_id']; + } else { + $store_id = 0; + } + + if (isset($this->request->get['language_id'])) { + $language_id = $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); + + $directory = DIR_CATALOG . 'language/'; + + 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)) { + $_ = array(); + + include($directory . $language_info['code'] . '/' . $route . '.php'); + + foreach ($_ as $key => $value) { + $json[] = array( + 'key' => $key, + 'value' => $value + ); + } + } + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } +} |