Back to Opencart

File admin\controller\common\developer.php

docs/api/source-admin.controller.common.developer.html

4.1.0.315.8 KB
Original Source

Namespaces

Classes

| 1: | <?php | | 2: | namespace Opencart\Admin\Controller\Common; | | 3: | /** | | 4: | * Class Developer | | 5: | * | | 6: | * @package Opencart\Admin\Controller\Common | | 7: | */ | | 8: | class Developer extends \Opencart\System\Engine\Controller { | | 9: | /** | | 10: | * Index | | 11: | * | | 12: | * @return void | | 13: | */ | | 14: | public function index(): void { | | 15: | $this->load->language('common/developer'); | | 16: | | | 17: | $data['developer_sass'] = $this->config->get('developer_sass'); | | 18: | | | 19: | $data['user_token'] = $this->session->data['user_token']; | | 20: | | | 21: | $this->response->setOutput($this->load->view('common/developer', $data)); | | 22: | } | | 23: | | | 24: | /** | | 25: | * Edit | | 26: | * | | 27: | * @return void | | 28: | */ | | 29: | public function edit(): void { | | 30: | $this->load->language('common/developer'); | | 31: | | | 32: | $json = []; | | 33: | | | 34: | if (!$this->user->hasPermission('modify', 'common/developer')) { | | 35: | $json['error'] = $this->language->get('error_permission'); | | 36: | } | | 37: | | | 38: | if (!$json) { | | 39: | $this->load->model('setting/setting'); | | 40: | | | 41: | $this->model_setting_setting->editSetting('developer', $this->request->post, 0); | | 42: | | | 43: | $json['success'] = $this->language->get('text_developer_success'); | | 44: | } | | 45: | | | 46: | $this->response->addHeader('Content-Type: application/json'); | | 47: | $this->response->setOutput(json_encode($json)); | | 48: | } | | 49: | | | 50: | /** | | 51: | * Cache | | 52: | * | | 53: | * @return void | | 54: | */ | | 55: | public function cache(): void { | | 56: | $this->load->language('common/developer'); | | 57: | | | 58: | $json = []; | | 59: | | | 60: | if (!$this->user->hasPermission('modify', 'common/developer')) { | | 61: | $json['error'] = $this->language->get('error_permission'); | | 62: | } | | 63: | | | 64: | if (!$json) { | | 65: | $files = glob(DIR_CACHE . 'cache.*'); | | 66: | | | 67: | if ($files) { | | 68: | foreach ($files as $file) { | | 69: | if (is_file($file)) { | | 70: | unlink($file); | | 71: | } | | 72: | } | | 73: | } | | 74: | | | 75: | $json['success'] = $this->language->get('text_cache_success'); | | 76: | } | | 77: | | | 78: | $this->response->addHeader('Content-Type: application/json'); | | 79: | $this->response->setOutput(json_encode($json)); | | 80: | } | | 81: | | | 82: | /** | | 83: | * Theme | | 84: | * | | 85: | * @return void | | 86: | */ | | 87: | public function theme(): void { | | 88: | $this->load->language('common/developer'); | | 89: | | | 90: | $json = []; | | 91: | | | 92: | if (!$this->user->hasPermission('modify', 'common/developer')) { | | 93: | $json['error'] = $this->language->get('error_permission'); | | 94: | } | | 95: | | | 96: | if (!$json) { | | 97: | $directories = glob(DIR_CACHE . 'template/*', GLOB_ONLYDIR); | | 98: | | | 99: | if ($directories) { | | 100: | foreach ($directories as $directory) { | | 101: | $files = glob($directory . '/*'); | | 102: | | | 103: | foreach ($files as $file) { | | 104: | if (is_file($file)) { | | 105: | unlink($file); | | 106: | } | | 107: | } | | 108: | | | 109: | if (is_dir($directory)) { | | 110: | rmdir($directory); | | 111: | } | | 112: | } | | 113: | } | | 114: | | | 115: | $json['success'] = $this->language->get('text_theme_success'); | | 116: | } | | 117: | | | 118: | $this->response->addHeader('Content-Type: application/json'); | | 119: | $this->response->setOutput(json_encode($json)); | | 120: | } | | 121: | | | 122: | /** | | 123: | * Sass | | 124: | * | | 125: | * @return void | | 126: | */ | | 127: | public function sass(): void { | | 128: | $this->load->language('common/developer'); | | 129: | | | 130: | $json = []; | | 131: | | | 132: | if (!$this->user->hasPermission('modify', 'common/developer')) { | | 133: | $json['error'] = $this->language->get('error_permission'); | | 134: | } | | 135: | | | 136: | if (!$json) { | | 137: | // Before we delete we need to make sure there is a sass file to regenerate the css | | 138: | $file = DIR_APPLICATION . 'view/stylesheet/bootstrap.css'; | | 139: | | | 140: | if (is_file($file) && is_file(DIR_APPLICATION . 'view/stylesheet/scss/bootstrap.scss')) { | | 141: | unlink($file); | | 142: | } | | 143: | | | 144: | $files = glob(DIR_CATALOG . 'view/theme/*/stylesheet/scss/bootstrap.scss'); | | 145: | | | 146: | foreach ($files as $file) { | | 147: | $file = substr($file, 0, -20) . '/bootstrap.css'; | | 148: | | | 149: | if (is_file($file)) { | | 150: | unlink($file); | | 151: | } | | 152: | } | | 153: | | | 154: | $files = glob(DIR_CATALOG . 'view/theme/*/stylesheet/stylesheet.scss'); | | 155: | | | 156: | foreach ($files as $file) { | | 157: | $file = substr($file, 0, -16) . '/stylesheet.css'; | | 158: | | | 159: | if (is_file($file)) { | | 160: | unlink($file); | | 161: | } | | 162: | } | | 163: | | | 164: | $json['success'] = $this->language->get('text_sass_success'); | | 165: | } | | 166: | | | 167: | $this->response->addHeader('Content-Type: application/json'); | | 168: | $this->response->setOutput(json_encode($json)); | | 169: | } | | 170: | | | 171: | /** | | 172: | * Vendor | | 173: | * | | 174: | * Generate new autoloader file | | 175: | * | | 176: | * @return void | | 177: | */ | | 178: | public function vendor(): void { | | 179: | $this->load->language('common/developer'); | | 180: | | | 181: | $json = []; | | 182: | | | 183: | if (!$this->user->hasPermission('modify', 'common/developer')) { | | 184: | $json['error'] = $this->language->get('error_permission'); | | 185: | } | | 186: | | | 187: | if (!$json) { | | 188: | // Generate php autoload file | | 189: | $code = '<?php' . "\n"; | | 190: | | | 191: | $files = glob(DIR_STORAGE . 'vendor/*/*/composer.json'); | | 192: | | | 193: | foreach ($files as $file) { | | 194: | $output = json_decode(file_get_contents($file), true); | | 195: | | | 196: | $code .= '// ' . $output['name'] . "\n"; | | 197: | | | 198: | if (isset($output['autoload'])) { | | 199: | $directory = substr(dirname($file), strlen(DIR_STORAGE . 'vendor/')); | | 200: | | | 201: | // Autoload psr-4 files | | 202: | if (isset($output['autoload']['psr-4'])) { | | 203: | $autoload = $output['autoload']['psr-4']; | | 204: | | | 205: | foreach ($autoload as $namespace => $path) { | | 206: | if (!is_array($path)) { | | 207: | $code .= '$autoloader->register('' . rtrim($namespace, '\') . '', DIR_STORAGE . 'vendor/' . $directory . '/' . rtrim($path, '/') . '/' . '', true);' . "\n"; | | 208: | } else { | | 209: | foreach ($path as $value) { | | 210: | $code .= '$autoloader->register('' . rtrim($namespace, '\') . '', DIR_STORAGE . 'vendor/' . $directory . '/' . rtrim($value, '/') . '/' . '', true);' . "\n"; | | 211: | } | | 212: | } | | 213: | } | | 214: | } | | 215: | | | 216: | // Autoload psr-0 files | | 217: | if (isset($output['autoload']['psr-0'])) { | | 218: | $autoload = $output['autoload']['psr-0']; | | 219: | | | 220: | foreach ($autoload as $namespace => $path) { | | 221: | if (!is_array($path)) { | | 222: | $code .= '$autoloader->register('' . rtrim($namespace, '\') . '', DIR_STORAGE . 'vendor/' . $directory . '/' . rtrim($path, '/') . '/' . '', true);' . "\n"; | | 223: | } else { | | 224: | foreach ($path as $value) { | | 225: | $code .= '$autoloader->register('' . rtrim($namespace, '\') . '', DIR_STORAGE . 'vendor/' . $directory . '/' . rtrim($value, '/') . '/' . '', true);' . "\n"; | | 226: | } | | 227: | } | | 228: | } | | 229: | } | | 230: | | | 231: | // Autoload classmap | | 232: | if (isset($output['autoload']['classmap'])) { | | 233: | $autoload = []; | | 234: | | | 235: | $classmaps = $output['autoload']['classmap']; | | 236: | | | 237: | foreach ($classmaps as $classmap) { | | 238: | $directories = [dirname($file) . '/' . $classmap]; | | 239: | | | 240: | while (count($directories) != 0) { | | 241: | $next = array_shift($directories); | | 242: | | | 243: | if (is_dir($next)) { | | 244: | foreach (glob(trim($next, '/') . '/{*,.[!.]*,..?*}', GLOB_BRACE) as $file) { | | 245: | if (is_dir($file)) { | | 246: | $directories[] = $file . '/'; | | 247: | } | | 248: | | | 249: | if (is_file($file)) { | | 250: | $namespace = substr(dirname($file), strlen(DIR_STORAGE . 'vendor/' . $directory . $classmap) + 1); | | 251: | | | 252: | if ($namespace) { | | 253: | $autoload[$namespace] = substr(dirname($file), strlen(DIR_STORAGE . 'vendor/')); | | 254: | } | | 255: | } | | 256: | } | | 257: | } | | 258: | } | | 259: | } | | 260: | | | 261: | foreach ($autoload as $namespace => $path) { | | 262: | $code .= '$autoloader->register('' . rtrim($namespace, '\') . '', DIR_STORAGE . 'vendor/' . rtrim($path, '/') . '/' . '', true);' . "\n"; | | 263: | } | | 264: | } | | 265: | | | 266: | // Autoload files | | 267: | if (isset($output['autoload']['files'])) { | | 268: | $files = $output['autoload']['files']; | | 269: | | | 270: | foreach ($files as $file) { | | 271: | $code .= 'if (is_file(DIR_STORAGE . 'vendor/' . $directory . '/' . $file . '')) {' . "\n"; | | 272: | $code .= ' require_once(DIR_STORAGE . 'vendor/' . $directory . '/' . $file . '');' . "\n"; | | 273: | $code .= '}' . "\n"; | | 274: | } | | 275: | } | | 276: | } | | 277: | | | 278: | $code .= "\n"; | | 279: | } | | 280: | | | 281: | file_put_contents(DIR_SYSTEM . 'vendor.php', trim($code)); | | 282: | | | 283: | $json['success'] = $this->language->get('text_vendor_success'); | | 284: | } | | 285: | | | 286: | $this->response->addHeader('Content-Type: application/json'); | | 287: | $this->response->setOutput(json_encode($json)); | | 288: | } | | 289: | } | | 290: | |

OpenCart API API documentation generated by ApiGen dev-master