PageRenderTime 56ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 1ms

/catalog/controller/common/simple_connector.php

https://bitbucket.org/angell2438/bsr
PHP | 240 lines | 177 code | 61 blank | 2 comment | 43 complexity | a3bf3b961a4c583e5d453a2c913bc44a MD5 | raw file
Possible License(s): LGPL-2.1, MPL-2.0-no-copyleft-exception
  1. <?php
  2. class ControllerCommonSimpleConnector extends Controller {
  3. public function index() {
  4. $custom = isset($this->request->get['custom']) ? true : false;
  5. $method = isset($this->request->get['method']) ? trim($this->request->get['method']) : '';
  6. $filter = isset($this->request->get['filter']) ? trim($this->request->get['filter']) : '';
  7. if (!$method) {
  8. exit;
  9. }
  10. if (!$custom) {
  11. $this->load->model('tool/simpleapimain');
  12. if (method_exists($this->model_tool_simpleapimain, $method) || property_exists($this->model_tool_simpleapimain, $method)) {
  13. $this->response->setOutput(json_encode($this->model_tool_simpleapimain->{$method}($filter)));
  14. }
  15. } else {
  16. $this->load->model('tool/simpleapicustom');
  17. if (method_exists($this->model_tool_simpleapicustom, $method) || property_exists($this->model_tool_simpleapicustom, $method)) {
  18. $this->response->setOutput(json_encode($this->model_tool_simpleapicustom->{$method}($filter)));
  19. }
  20. }
  21. }
  22. public function validate() {
  23. $custom = isset($this->request->get['custom']) ? true : false;
  24. $method = isset($this->request->get['method']) ? trim($this->request->get['method']) : '';
  25. $filter = isset($this->request->get['filter']) ? trim($this->request->get['filter']) : '';
  26. $value = isset($this->request->get['value']) ? trim($this->request->get['value']) : '';
  27. if (!$method) {
  28. exit;
  29. }
  30. if (!$custom) {
  31. $this->load->model('tool/simpleapimain');
  32. if (method_exists($this->model_tool_simpleapimain, $method) || property_exists($this->model_tool_simpleapimain, $method)) {
  33. $this->response->setOutput($this->model_tool_simpleapimain->{$method}($value, $filter) ? 'valid' : 'invalid');
  34. }
  35. } else {
  36. $this->load->model('tool/simpleapicustom');
  37. if (method_exists($this->model_tool_simpleapicustom, $method) || property_exists($this->model_tool_simpleapicustom, $method)) {
  38. $this->response->setOutput($this->model_tool_simpleapicustom->{$method}($value, $filter) ? 'valid' : 'invalid');
  39. }
  40. }
  41. }
  42. public function zone() {
  43. $output = '<option value="">' . $this->language->get('text_select') . '</option>';
  44. $this->load->model('localisation/zone');
  45. $results = $this->model_localisation_zone->getZonesByCountryId($this->request->get['country_id']);
  46. foreach ($results as $result) {
  47. $output .= '<option value="' . $result['zone_id'] . '"';
  48. if (isset($this->request->get['zone_id']) && ($this->request->get['zone_id'] == $result['zone_id'])) {
  49. $output .= ' selected="selected"';
  50. }
  51. $output .= '>' . $result['name'] . '</option>';
  52. }
  53. if (!$results) {
  54. $output .= '<option value="0">' . $this->language->get('text_none') . '</option>';
  55. }
  56. $this->response->setOutput($output);
  57. }
  58. public function geo() {
  59. $this->load->model('tool/simplegeo');
  60. $term = $this->request->get['term'];
  61. if (utf8_strlen($term) < 2) {
  62. exit;
  63. }
  64. $this->response->setOutput(json_encode($this->model_tool_simplegeo->getGeoList($term)));
  65. }
  66. public function upload() {
  67. $this->language->load('checkout/simplecheckout');
  68. $json = array();
  69. if ($this->request->server['REQUEST_METHOD'] == 'POST') {
  70. if (!empty($this->request->files['file']['name'])) {
  71. $filename = html_entity_decode($this->request->files['file']['name'], ENT_QUOTES, 'UTF-8');
  72. $filename = str_replace(' ', '_', $filename);
  73. if ((utf8_strlen($filename) < 3) || (utf8_strlen($filename) > 128)) {
  74. $json['error'] = $this->language->get('error_filename');
  75. }
  76. // Allowed file extension types
  77. $allowed = array();
  78. $config_extensions = $this->config->get('config_file_extension_allowed');
  79. if (empty($config_extensions)) {
  80. $config_extensions = $this->config->get('config_file_ext_allowed');
  81. }
  82. if (empty($config_extensions)) {
  83. $config_extensions = $this->config->get('config_upload_allowed');
  84. $filetypes = explode(",", $config_extensions);
  85. } else {
  86. $filetypes = explode("\n", $config_extensions);
  87. }
  88. foreach ($filetypes as $filetype) {
  89. $allowed[] = trim($filetype);
  90. }
  91. if (!in_array(substr(strrchr($filename, '.'), 1), $allowed)) {
  92. $json['error'] = $this->language->get('error_filetype');
  93. }
  94. // Allowed file mime types
  95. $allowed = array();
  96. $config_filetypes = $this->config->get('config_file_mime_allowed');
  97. if (!empty($config_filetypes)) {
  98. $filetypes = explode("\n", $config_filetypes);
  99. foreach ($filetypes as $filetype) {
  100. $allowed[] = trim($filetype);
  101. }
  102. if (!in_array($this->request->files['file']['type'], $allowed)) {
  103. $json['error'] = $this->language->get('error_filetype');
  104. }
  105. }
  106. if ($this->request->files['file']['error'] != UPLOAD_ERR_OK) {
  107. $json['error'] = $this->language->get('error_upload_' . $this->request->files['file']['error']);
  108. }
  109. } else {
  110. $json['error'] = $this->language->get('error_upload');
  111. }
  112. if (!isset($json['error'])) {
  113. if (is_uploaded_file($this->request->files['file']['tmp_name']) && file_exists($this->request->files['file']['tmp_name'])) {
  114. $file = basename($filename) . '.' . md5(mt_rand());
  115. $json['filename'] = $filename;
  116. $opencartVersion = explode('.', VERSION);
  117. $opencartVersion = floatval($opencartVersion[0].$opencartVersion[1].$opencartVersion[2].'.'.(isset($opencartVersion[3]) ? $opencartVersion[3] : 0));
  118. if ($opencartVersion < 200) {
  119. $encryption = new Encryption($this->config->get('config_encryption'));
  120. $json['file'] = $encryption->encrypt($file);
  121. } else {
  122. $this->load->model('tool/upload');
  123. $json['file'] = $this->model_tool_upload->addUpload($filename, $file);
  124. }
  125. move_uploaded_file($this->request->files['file']['tmp_name'], DIR_DOWNLOAD . $file);
  126. }
  127. }
  128. }
  129. $this->response->setOutput(json_encode($json));
  130. }
  131. public function captcha() {
  132. $this->session->data['captcha'] = substr(sha1(mt_rand()), 17, 6);
  133. $image = imagecreatetruecolor(150, 35);
  134. $width = imagesx($image);
  135. $height = imagesy($image);
  136. $black = imagecolorallocate($image, 0, 0, 0);
  137. $white = imagecolorallocate($image, 255, 255, 255);
  138. $red = imagecolorallocatealpha($image, 255, 0, 0, 75);
  139. $green = imagecolorallocatealpha($image, 0, 255, 0, 75);
  140. $blue = imagecolorallocatealpha($image, 0, 0, 255, 75);
  141. imagefilledrectangle($image, 0, 0, $width, $height, $white);
  142. imagefilledellipse($image, ceil(rand(5, 145)), ceil(rand(0, 35)), 30, 30, $red);
  143. imagefilledellipse($image, ceil(rand(5, 145)), ceil(rand(0, 35)), 30, 30, $green);
  144. imagefilledellipse($image, ceil(rand(5, 145)), ceil(rand(0, 35)), 30, 30, $blue);
  145. imagefilledrectangle($image, 0, 0, $width, 0, $black);
  146. imagefilledrectangle($image, $width - 1, 0, $width - 1, $height - 1, $black);
  147. imagefilledrectangle($image, 0, 0, 0, $height - 1, $black);
  148. imagefilledrectangle($image, 0, $height - 1, $width, $height - 1, $black);
  149. imagestring($image, 10, intval(($width - (strlen($this->session->data['captcha']) * 9)) / 2), intval(($height - 15) / 2), $this->session->data['captcha'], $black);
  150. header('Content-type: image/jpeg');
  151. imagejpeg($image);
  152. imagedestroy($image);
  153. }
  154. public function human() {
  155. if (isset($this->session->data['get_used'])) {
  156. $this->session->data['human'] = true;
  157. }
  158. }
  159. public function header() {
  160. $opencartVersion = explode('.', VERSION);
  161. $opencartVersion = floatval($opencartVersion[0].$opencartVersion[1].$opencartVersion[2].'.'.(isset($opencartVersion[3]) ? $opencartVersion[3] : 0));
  162. if ($opencartVersion < 200) {
  163. if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/common/maintenance.tpl')) {
  164. $this->template = $this->config->get('config_template') . '/template/common/maintenance.tpl';
  165. } else {
  166. $this->template = 'default/template/common/maintenance.tpl';
  167. }
  168. $this->data['message'] = '';
  169. $this->children = array(
  170. 'common/header',
  171. 'common/footer'
  172. );
  173. $this->response->setOutput($this->render());
  174. } else {
  175. $this->response->setOutput($this->load->controller('common/header'));
  176. }
  177. }
  178. }
  179. ?>