links_to_marketplaces.php 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. <?php
  2. class ControllerExtensionModuleLinksToMarketplaces extends Controller {
  3. private $error = array();
  4. public function install() {
  5. $this->load->model('extension/module/links_to_marketplaces');
  6. $this->model_extension_module_links_to_marketplaces->addColumnsToTable();
  7. }
  8. public function index() {
  9. $this->load->language('extension/module/links_to_marketplaces');
  10. $this->document->setTitle($this->language->get('heading_title'));
  11. $this->load->model('setting/setting');
  12. if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) {
  13. $this->model_setting_setting->editSetting('module_links_to_marketplaces', $this->request->post);
  14. $this->session->data['success'] = $this->language->get('text_success');
  15. $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=module', true));
  16. }
  17. if (isset($this->error['warning'])) {
  18. $data['error_warning'] = $this->error['warning'];
  19. } else {
  20. $data['error_warning'] = '';
  21. }
  22. if (isset($this->error['icon_width'])) {
  23. $data['error_icon_width'] = $this->error['icon_width'];
  24. } else {
  25. $data['error_icon_width'] = '';
  26. }
  27. if (isset($this->error['icon_height'])) {
  28. $data['error_icon_height'] = $this->error['icon_height'];
  29. } else {
  30. $data['error_icon_height'] = '';
  31. }
  32. $data['breadcrumbs'] = array();
  33. $data['breadcrumbs'][] = array(
  34. 'text' => $this->language->get('text_home'),
  35. 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true)
  36. );
  37. $data['breadcrumbs'][] = array(
  38. 'text' => $this->language->get('text_extension'),
  39. 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=module', true)
  40. );
  41. $data['breadcrumbs'][] = array(
  42. 'text' => $this->language->get('heading_title'),
  43. 'href' => $this->url->link('extension/module/links_to_marketplaces', 'user_token=' . $this->session->data['user_token'], true)
  44. );
  45. $data['action'] = $this->url->link('extension/module/links_to_marketplaces', 'user_token=' . $this->session->data['user_token'], true);
  46. $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=module', true);
  47. if (isset($this->request->post['module_links_to_marketplaces_status'])) {
  48. $data['module_links_to_marketplaces_status'] = $this->request->post['module_links_to_marketplaces_status'];
  49. } else {
  50. $data['module_links_to_marketplaces_status'] = $this->config->get('module_links_to_marketplaces_status');
  51. }
  52. if (isset($this->request->post['module_links_to_marketplaces'])) {
  53. $data['module_links_to_marketplaces'] = $this->request->post['module_links_to_marketplaces'];
  54. } else {
  55. $data['module_links_to_marketplaces'] = $this->config->get('module_links_to_marketplaces');
  56. }
  57. $this->load->model('tool/image');
  58. $data['placeholder'] = $this->model_tool_image->resize('no_image.png', 100, 100);
  59. if (!empty($data['module_links_to_marketplaces']) && count($data['module_links_to_marketplaces'])) {
  60. foreach($data['module_links_to_marketplaces'] as $key => $linkData) {
  61. if (!empty($data['module_links_to_marketplaces'][$key]['image'])) {
  62. $data['module_links_to_marketplaces'][$key]['thumb'] = $this->model_tool_image->resize($data['module_links_to_marketplaces'][$key]['image'], 100, 100);
  63. } else {
  64. $data['module_links_to_marketplaces'][$key]['thumb'] = $data['placeholder'];
  65. }
  66. }
  67. }
  68. $data['header'] = $this->load->controller('common/header');
  69. $data['column_left'] = $this->load->controller('common/column_left');
  70. $data['footer'] = $this->load->controller('common/footer');
  71. $this->response->setOutput($this->load->view('extension/module/links_to_marketplaces', $data));
  72. }
  73. protected function validate() {
  74. if (!$this->user->hasPermission('modify', 'extension/module/links_to_marketplaces')) {
  75. $this->error['warning'] = $this->language->get('error_permission');
  76. }
  77. if (empty($this->request->post['module_links_to_marketplaces']['icon']['width']) || (int)$this->request->post['module_links_to_marketplaces']['icon']['width'] <= 0) {
  78. $this->error['icon_width'] = $this->language->get('error_icon_width');
  79. }
  80. if (empty($this->request->post['module_links_to_marketplaces']['icon']['height']) || (int)$this->request->post['module_links_to_marketplaces']['icon']['height'] <= 0) {
  81. $this->error['icon_height'] = $this->language->get('error_icon_height');
  82. }
  83. return !$this->error;
  84. }
  85. }