PageRenderTime 50ms CodeModel.GetById 19ms RepoModel.GetById 1ms app.codeStats 0ms

/admin/controller/module/vqmod_manager.php

https://bitbucket.org/valdeir2000/opencart-pack
PHP | 691 lines | 507 code | 125 blank | 59 comment | 120 complexity | ce01f9e7df68581b61236d3639afbf4a MD5 | raw file
Possible License(s): LGPL-2.1
  1. <?php
  2. class ControllerModuleVQModManager extends Controller {
  3. /**
  4. * @todo VQMod 2.3.0
  5. * @todo Use VQMod vars for paths instead of hardcoding
  6. * @todo VQMod installation check
  7. * @todo Invalid XML handling
  8. * @todo Check for unused language text
  9. * @todo VQMod script rename
  10. * @todo Better handling of VQMod logs
  11. * @todo Break VQMod installation errors into more generic parts
  12. * -Missing Files (re-upload)
  13. * -Permissions (chmod)
  14. * -Version (upgrade)
  15. */
  16. private $error = array();
  17. public function __construct($registry) {
  18. parent::__construct($registry);
  19. // Paths and Files
  20. $this->base_dir = substr_replace(DIR_SYSTEM, '/', -8);
  21. $this->vqmod_dir = substr_replace(DIR_SYSTEM, '/vqmod/', -8);
  22. $this->vqmod_script_dir = substr_replace(DIR_SYSTEM, '/vqmod/xml/', -8);
  23. $this->vqcache_dir = substr_replace(DIR_SYSTEM, '/vqmod/vqcache/', -8);
  24. $this->vqcache_files = substr_replace(DIR_SYSTEM, '/vqmod/vqcache/vq*', -8);
  25. $this->vqmod_log = substr_replace(DIR_SYSTEM, '/vqmod/vqmod.log', -8); // Depricated VQMod 2.2.0
  26. $this->vqmod_logs_dir = substr_replace(DIR_SYSTEM, '/vqmod/logs/', -8);
  27. $this->vqmod_logs = substr_replace(DIR_SYSTEM, '/vqmod/logs/*.log', -8);
  28. $this->vqmod_modcache = substr_replace(DIR_SYSTEM, '/vqmod/mods.cache', -8); // VQMod 2.2.0
  29. $this->vqmod_opencart_script = substr_replace(DIR_SYSTEM, '/vqmod/xml/vqmod_opencart.xml', -8);
  30. $this->vqmod_path_replaces = substr_replace(DIR_SYSTEM, '/vqmod/pathReplaces.php', -8); // VQMod 2.3.0
  31. clearstatcache();
  32. }
  33. public function index() {
  34. $this->language->load('module/vqmod_manager');
  35. $this->document->setTitle($this->language->get('heading_title'));
  36. $this->load->model('setting/setting');
  37. if ($this->request->server['REQUEST_METHOD'] == 'POST' && isset($this->request->post['upload'])) {
  38. // Upload VQMod
  39. $this->vqmod_upload();
  40. }
  41. // Language
  42. $this->data = array_merge($this->data, $this->language->load('module/vqmod_manager'));
  43. // Check that VQMod is properly installed in store
  44. if ($this->vqmod_installation_check()) {
  45. $this->data['vqmod_is_installed'] = true;
  46. } else {
  47. $this->data['vqmod_is_installed'] = false;
  48. }
  49. // VQMod installation errors
  50. if (isset($this->session->data['vqmod_installation_error'])) {
  51. $this->data['vqmod_installation_error'] = $this->session->data['vqmod_installation_error'];
  52. unset($this->session->data['vqmod_installation_error']);
  53. } else {
  54. $this->data['vqmod_installation_error'] = '';
  55. }
  56. // Warning
  57. if (isset($this->session->data['error'])) {
  58. $this->data['error_warning'] = $this->session->data['error'];
  59. unset($this->session->data['error']);
  60. } else {
  61. $this->data['error_warning'] = '';
  62. }
  63. // Success
  64. if (isset($this->session->data['success'])) {
  65. $this->data['success'] = $this->session->data['success'];
  66. unset($this->session->data['success']);
  67. } else {
  68. $this->data['success'] = '';
  69. }
  70. // Breadcrumbs
  71. $this->data['breadcrumbs'] = array();
  72. $this->data['breadcrumbs'][] = array(
  73. 'href' => $this->url->link('common/home', 'token=' . $this->session->data['token'], 'SSL'),
  74. 'text' => $this->language->get('text_home'),
  75. 'separator' => false
  76. );
  77. $this->data['breadcrumbs'][] = array(
  78. 'href' => $this->url->link('extension/module', 'token=' . $this->session->data['token'], 'SSL'),
  79. 'text' => $this->language->get('text_module'),
  80. 'separator' => ' :: '
  81. );
  82. $this->data['breadcrumbs'][] = array(
  83. 'href' => $this->url->link('module/vqmod_manager', 'token=' . $this->session->data['token'], 'SSL'),
  84. 'text' => $this->language->get('heading_title'),
  85. 'separator' => ' :: '
  86. );
  87. // Action Buttons
  88. $this->data['action'] = $this->url->link('module/vqmod_manager', 'token=' . $this->session->data['token'], 'SSL');
  89. $this->data['cancel'] = $this->url->link('extension/module', 'token=' . $this->session->data['token'], 'SSL');
  90. $this->data['clear_log'] = $this->url->link('module/vqmod_manager/clear_log', 'token=' . $this->session->data['token'], 'SSL');
  91. $this->data['clear_vqcache'] = $this->url->link('module/vqmod_manager/clear_vqcache', 'token=' . $this->session->data['token'], 'SSL');
  92. $this->data['download_log'] = $this->url->link('module/vqmod_manager/download_log', 'token=' . $this->session->data['token'], 'SSL');
  93. $this->data['download_scripts'] = $this->url->link('module/vqmod_manager/download_vqmod_scripts', 'token=' . $this->session->data['token'], 'SSL');
  94. $this->data['download_vqcache'] = $this->url->link('module/vqmod_manager/download_vqcache', 'token=' . $this->session->data['token'], 'SSL');
  95. // Check ZipArchive for use with downloads
  96. if (class_exists('ZipArchive')) {
  97. $this->data['ziparchive'] = true;
  98. } else {
  99. $this->data['ziparchive'] = false;
  100. }
  101. // Detect scripts
  102. $vqmod_scripts = $this->list_vqmod_scripts();
  103. $this->data['vqmods'] = array();
  104. if (!empty($vqmod_scripts)) {
  105. foreach ($vqmod_scripts as $vqmod_script) {
  106. $extension = pathinfo($vqmod_script, PATHINFO_EXTENSION);
  107. if ($extension == 'xml_') {
  108. $file = basename($vqmod_script, '.xml_');
  109. } else {
  110. $file = basename($vqmod_script, '.xml');
  111. }
  112. $action = array();
  113. if ($extension == 'xml_') {
  114. $action[] = array(
  115. 'text' => $this->language->get('text_install'),
  116. 'href' => $this->url->link('module/vqmod_manager/vqmod_install', 'token=' . $this->session->data['token'] . '&vqmod=' . $file, 'SSL')
  117. );
  118. } else {
  119. $action[] = array(
  120. 'text' => $this->language->get('text_uninstall'),
  121. 'href' => $this->url->link('module/vqmod_manager/vqmod_uninstall', 'token=' . $this->session->data['token'] . '&vqmod=' . $file, 'SSL')
  122. );
  123. }
  124. libxml_use_internal_errors(true);
  125. $xml = simplexml_load_file($vqmod_script);
  126. if (libxml_get_errors()) {
  127. $invalid_xml = sprintf($this->language->get('highlight'), $this->language->get('error_invalid_xml'));
  128. libxml_clear_errors();
  129. } else {
  130. $invalid_xml = '';
  131. }
  132. $this->data['vqmods'][] = array(
  133. 'file_name' => basename($vqmod_script, ''),
  134. 'id' => isset($xml->id) ? $xml->id : $this->language->get('text_unavailable'),
  135. 'version' => isset($xml->version) ? $xml->version : $this->language->get('text_unavailable'),
  136. 'vqmver' => isset($xml->vqmver) ? $xml->vqmver : $this->language->get('text_unavailable'),
  137. 'author' => isset($xml->author) ? $xml->author : $this->language->get('text_unavailable'),
  138. 'status' => $extension == 'xml_' ? sprintf($this->language->get('highlight'), $this->language->get('text_disabled')) : $this->language->get('text_enabled'),
  139. 'delete' => $this->url->link('module/vqmod_manager/vqmod_delete', 'token=' . $this->session->data['token'] . '&vqmod=' . basename($vqmod_script), 'SSL'),
  140. 'action' => $action,
  141. 'invalid_xml' => $invalid_xml
  142. );
  143. }
  144. }
  145. // VQCache files
  146. $this->data['vqcache'] = array();
  147. if (is_dir($this->vqcache_dir)) {
  148. $this->data['vqcache'] = array_diff(scandir($this->vqcache_dir), array('.', '..'));
  149. }
  150. // VQMod Error Log
  151. $this->data['log'] = '';
  152. if (is_dir($this->vqmod_logs_dir) && is_readable($this->vqmod_logs_dir)) {
  153. // VQMod 2.2.0 and later logs
  154. $vqmod_logs = glob($this->vqmod_logs);
  155. $vqmod_logs_size = 0;
  156. if (!empty($vqmod_logs)) {
  157. foreach ($vqmod_logs as $vqmod_log) {
  158. $vqmod_logs_size += filesize($vqmod_log);
  159. }
  160. // Error if log files are larger than 6MB combined
  161. if ($vqmod_logs_size > 6291456) {
  162. $this->data['error_warning'] = sprintf($this->language->get('error_log_size'), round(($vqmod_logs_size / 1048576), 2));
  163. $this->data['log'] = sprintf($this->language->get('error_log_size'), round(($vqmod_logs_size / 1048576), 2));
  164. } else {
  165. foreach ($vqmod_logs as $vqmod_log) {
  166. $this->data['log'] .= str_pad(basename($vqmod_log), 70, '*', STR_PAD_BOTH) . "\n";
  167. $this->data['log'] .= file_get_contents($vqmod_log, FILE_USE_INCLUDE_PATH, null);
  168. }
  169. }
  170. }
  171. } elseif (is_file($this->vqmod_log) && filesize($this->vqmod_log) > 0) {
  172. // VQMod 2.1.7 and earlier log
  173. if (filesize($this->vqmod_log) > 6291456) {
  174. // Error if log file is larger than 6MB
  175. $this->data['error_warning'] = sprintf($this->language->get('error_log_size'), round((filesize($this->vqmod_log) / 1048576), 2));
  176. $this->data['log'] = sprintf($this->language->get('error_log_size'), round((filesize($this->vqmod_log) / 1048576), 2));
  177. } else {
  178. // Regular log
  179. $this->data['log'] = file_get_contents($this->vqmod_log, FILE_USE_INCLUDE_PATH, null);
  180. }
  181. }
  182. if ($this->data['log']) {
  183. // Highlight Error Log tab
  184. $this->data['tab_error_log'] = sprintf($this->language->get('highlight'), $this->language->get('tab_error_log'));
  185. }
  186. // VQMod Path
  187. if (is_dir($this->vqmod_dir)) {
  188. $this->data['vqmod_path'] = $this->vqmod_dir;
  189. } else {
  190. $this->data['vqmod_path'] = '';
  191. }
  192. // VQMod class variables
  193. $vqmod_vars = get_class_vars('VQMod');
  194. $this->data['vqmod_vars'] = array();
  195. if ($vqmod_vars) {
  196. foreach ($vqmod_vars as $setting => $value) {
  197. // Deprecated VQMod 2.1.7
  198. if ($setting == 'useCache') {
  199. $this->data['vqmod_vars'][] = array(
  200. 'setting' => $this->language->get('setting_usecache'),
  201. 'value' => ($value === true ? $this->language->get('text_enabled') : $this->language->get('text_disabled')),
  202. );
  203. }
  204. if ($setting == 'logging') {
  205. $this->data['vqmod_vars'][] = array(
  206. 'setting' => $this->language->get('setting_logging'),
  207. 'value' => ($value === true ? $this->language->get('text_enabled') : $this->language->get('text_disabled'))
  208. );
  209. }
  210. // Deprecated VQMod 2.2.0
  211. if ($setting == 'cacheTime') {
  212. $this->data['vqmod_vars'][] = array(
  213. 'setting' => $this->language->get('setting_cachetime'),
  214. 'value' => sprintf($this->language->get('text_cachetime'), $value)
  215. );
  216. }
  217. if ($setting == 'protectedFilelist' && is_file($this->base_dir . $value)) {
  218. $protected_files = file_get_contents($this->base_dir . $value);
  219. if (!empty($protected_files)) {
  220. $protected_files = preg_replace('~\r?\n~', "\n", $protected_files);
  221. $paths = explode("\n", $protected_files);
  222. $this->data['vqmod_vars'][] = array(
  223. 'setting' => $this->language->get('setting_protected_files'),
  224. 'value' => implode('<br />', $paths)
  225. );
  226. }
  227. }
  228. if ($setting == 'directorySeparator' && !empty($value)) {
  229. $this->data['vqmod_vars'][] = array(
  230. 'setting' => $this->language->get('setting_dir_separator'),
  231. 'value' => htmlentities($value, ENT_QUOTES, 'UTF-8')
  232. );
  233. }
  234. }
  235. }
  236. // Path Replacements - VQMod 2.3.0
  237. if (is_file($this->vqmod_path_replaces)) {
  238. if (!in_array('pathReplaces.php', get_included_files())) {
  239. include_once($this->vqmod_path_replaces);
  240. }
  241. if (!empty($replaces)) {
  242. $replacement_values = array();
  243. foreach ($replaces as $key => $value) {
  244. $replacement_values[] = $value[0] . $this->language->get('text_separator') . $value[1];
  245. }
  246. $this->data['vqmod_vars'][] = array(
  247. 'setting' => $this->language->get('setting_path_replaces'),
  248. 'value' => implode('<br />', $replacement_values)
  249. );
  250. }
  251. }
  252. // Stylesheet
  253. $this->document->addStyle('view/stylesheet/vqmod_manager.css');
  254. // Template
  255. $this->template = 'module/vqmod_manager.tpl';
  256. $this->children = array(
  257. 'common/header',
  258. 'common/footer'
  259. );
  260. $this->response->setOutput($this->render());
  261. }
  262. public function vqmod_install() {
  263. if ($this->userPermission()) {
  264. $vqmod_script = $this->request->get['vqmod'];
  265. if (is_file($this->vqmod_script_dir . $vqmod_script . '.xml_')) {
  266. rename($this->vqmod_script_dir . $vqmod_script . '.xml_', $this->vqmod_script_dir . $vqmod_script . '.xml');
  267. $this->clear_vqcache(true);
  268. $this->session->data['success'] = $this->language->get('success_install');
  269. } else {
  270. $this->session->data['error'] = $this->language->get('error_install');
  271. }
  272. }
  273. $this->redirect($this->url->link('module/vqmod_manager', 'token=' . $this->session->data['token'], 'SSL'));
  274. }
  275. public function vqmod_uninstall() {
  276. if ($this->userPermission()) {
  277. $vqmod_script = $this->request->get['vqmod'];
  278. if (is_file($this->vqmod_script_dir . $vqmod_script . '.xml')) {
  279. rename($this->vqmod_script_dir . $vqmod_script . '.xml', $this->vqmod_script_dir . $vqmod_script . '.xml_');
  280. $this->clear_vqcache(true);
  281. $this->session->data['success'] = $this->language->get('success_uninstall');
  282. } else {
  283. $this->session->data['error'] = $this->language->get('error_uninstall');
  284. }
  285. }
  286. $this->redirect($this->url->link('module/vqmod_manager', 'token=' . $this->session->data['token'], 'SSL'));
  287. }
  288. public function vqmod_upload() {
  289. $this->language->load('module/vqmod_manager');
  290. if ($this->userPermission()) {
  291. $file = $this->request->files['vqmod_file']['tmp_name'];
  292. $file_name = $this->request->files['vqmod_file']['name'];
  293. if ($this->request->files['vqmod_file']['error'] > 0) {
  294. switch($this->request->files['vqmod_file']['error']) {
  295. case 1:
  296. $this->session->data['error'] = $this->language->get('error_ini_max_file_size');
  297. break;
  298. case 2:
  299. $this->session->data['error'] = $this->language->get('error_form_max_file_size');
  300. break;
  301. case 3:
  302. $this->session->data['error'] = $this->language->get('error_partial_upload');
  303. break;
  304. case 4:
  305. $this->session->data['error'] = $this->language->get('error_no_upload');
  306. break;
  307. case 6:
  308. $this->session->data['error'] = $this->language->get('error_no_temp_dir');
  309. break;
  310. case 7:
  311. $this->session->data['error'] = $this->language->get('error_write_fail');
  312. break;
  313. case 8:
  314. $this->session->data['error'] = $this->language->get('error_php_conflict');
  315. break;
  316. default:
  317. $this->session->data['error'] = $this->language->get('error_unknown');
  318. }
  319. } else {
  320. if ($this->request->files['vqmod_file']['type'] != 'text/xml') {
  321. $this->session->data['error'] = $this->language->get('error_filetype');
  322. } else {
  323. libxml_use_internal_errors(true);
  324. simplexml_load_file($file);
  325. if (libxml_get_errors()) {
  326. $this->session->data['error'] = $this->language->get('error_invalid_xml');
  327. libxml_clear_errors();
  328. } elseif (move_uploaded_file($file, $this->vqmod_script_dir . $file_name) === false) {
  329. $this->session->data['error'] = $this->language->get('error_move');
  330. } else {
  331. $this->clear_vqcache(true);
  332. $this->session->data['success'] = $this->language->get('success_upload');
  333. }
  334. }
  335. }
  336. }
  337. $this->redirect($this->url->link('module/vqmod_manager', 'token=' . $this->session->data['token'], 'SSL'));
  338. }
  339. public function vqmod_delete() {
  340. if ($this->userPermission()) {
  341. $vqmod_script = $this->request->get['vqmod'];
  342. if (is_file($this->vqmod_script_dir . $vqmod_script)) {
  343. if (unlink($this->vqmod_script_dir . $vqmod_script)) {
  344. $this->clear_vqcache(true);
  345. $this->session->data['success'] = $this->language->get('success_delete');
  346. } else {
  347. $this->session->data['error'] = $this->language->get('error_delete');
  348. }
  349. }
  350. }
  351. $this->redirect($this->url->link('module/vqmod_manager', 'token=' . $this->session->data['token'], 'SSL'));
  352. }
  353. public function clear_vqcache($return = false) {
  354. if ($this->userPermission()) {
  355. $files = glob($this->vqcache_files);
  356. if ($files) {
  357. foreach ($files as $file) {
  358. if (is_file($file)) {
  359. unlink($file);
  360. }
  361. }
  362. }
  363. if (is_file($this->vqmod_modcache)) {
  364. unlink($this->vqmod_modcache);
  365. }
  366. if ($return) {
  367. return;
  368. }
  369. $this->session->data['success'] = $this->language->get('success_clear_vqcache');
  370. }
  371. $this->redirect($this->url->link('module/vqmod_manager', 'token=' . $this->session->data['token'], 'SSL'));
  372. }
  373. public function clear_log() {
  374. if ($this->userPermission()) {
  375. if (is_dir($this->vqmod_logs_dir)) {
  376. // VQMod 2.2.0 and later
  377. $files = glob($this->vqmod_logs);
  378. foreach ($files as $file) {
  379. unlink($file);
  380. }
  381. } else {
  382. // VQMod 2.1.7 and earlier
  383. $file = $this->vqmod_log;
  384. $handle = fopen($file, 'w+');
  385. fclose($handle);
  386. $this->session->data['success'] = $this->language->get('success_clear_log');
  387. }
  388. }
  389. $this->redirect($this->url->link('module/vqmod_manager', 'token=' . $this->session->data['token'], 'SSL'));
  390. }
  391. private function list_vqmod_scripts() {
  392. $vqmod_scripts = array();
  393. if ($this->userPermission('access')) {
  394. $enabled_vqmod_scripts = glob($this->vqmod_script_dir . '*.xml');
  395. $disabled_vqmod_scripts = glob($this->vqmod_script_dir . '*.xml_');
  396. if (!empty($enabled_vqmod_scripts)) {
  397. $vqmod_scripts = array_merge($vqmod_scripts, $enabled_vqmod_scripts);
  398. }
  399. if (!empty($disabled_vqmod_scripts)) {
  400. $vqmod_scripts = array_merge($vqmod_scripts, $disabled_vqmod_scripts);
  401. }
  402. }
  403. return $vqmod_scripts;
  404. }
  405. public function download_vqmod_scripts() {
  406. if ($this->userPermission()) {
  407. $targets = $this->list_vqmod_scripts();
  408. $this->zip_send($targets, 'vqmod_scripts_backup');
  409. } else {
  410. $this->redirect($this->url->link('module/vqmod_manager', 'token=' . $this->session->data['token'], 'SSL'));
  411. }
  412. }
  413. public function download_vqcache() {
  414. if ($this->userPermission()) {
  415. $targets = glob($this->vqcache_files);
  416. if (is_file($this->vqmod_modcache)) {
  417. $targets[] = $this->vqmod_modcache;
  418. }
  419. $this->zip_send($targets, 'vqcache_dump');
  420. } else {
  421. $this->redirect($this->url->link('module/vqmod_manager', 'token=' . $this->session->data['token'], 'SSL'));
  422. }
  423. }
  424. public function download_log() {
  425. if ($this->userPermission()) {
  426. if (is_dir($this->vqmod_logs_dir) && count(array_diff(scandir($this->vqmod_logs_dir), array('.', '..'))) > 0) {
  427. // VQMod 2.2.0 and later
  428. $targets = glob($this->vqmod_logs);
  429. $this->zip_send($targets, 'vqmod_logs');
  430. } elseif (is_file($this->vqmod_log)) {
  431. // VQMod 2.1.7 and earlier
  432. $targets = array($this->vqmod_log);
  433. $this->zip_send($targets, 'vqmod_log');
  434. } else {
  435. // No log available for download error
  436. $this->language->load('module/vqmod_manager');
  437. $this->session->data['error'] = $this->language->get('error_log_download');
  438. $this->redirect($this->url->link('module/vqmod_manager', 'token=' . $this->session->data['token'], 'SSL'));
  439. }
  440. } else {
  441. $this->redirect($this->url->link('module/vqmod_manager', 'token=' . $this->session->data['token'], 'SSL'));
  442. }
  443. }
  444. private function zip_send($targets, $filename = 'download') {
  445. $temp = tempnam('tmp', 'zip');
  446. $zip = new ZipArchive();
  447. $zip->open($temp, ZipArchive::OVERWRITE);
  448. foreach ($targets as $target) {
  449. if (is_file($target)) {
  450. $zip->addFile($target, basename($target));
  451. }
  452. }
  453. $zip->close();
  454. header('Pragma: public');
  455. header('Expires: 0');
  456. header('Content-Description: File Transfer');
  457. header('Content-Type: application/zip');
  458. header('Content-Disposition: attachment; filename=' . $filename . '_' . date('Y-m-d_H-i') . '.zip');
  459. header('Content-Transfer-Encoding: binary');
  460. readfile($temp);
  461. unlink($temp);
  462. }
  463. private function vqmod_installation_check() {
  464. // Check SimpleXML for VQMod Manager use
  465. if (!function_exists('simplexml_load_file')) {
  466. $this->session->data['vqmod_installation_error'] = $this->language->get('error_simplexml');
  467. return false;
  468. }
  469. // Check if /vqmod directory exists
  470. if (!is_dir($this->vqmod_dir)) {
  471. $this->session->data['vqmod_installation_error'] = $this->language->get('error_vqmod_dir');
  472. return false;
  473. }
  474. // Check if vqmod.php exists
  475. if (!is_file($this->vqmod_dir . 'vqmod.php')) {
  476. $this->session->data['vqmod_installation_error'] = $this->language->get('error_vqmod_core');
  477. return false;
  478. }
  479. // Check if /vqmod/xml directory exists
  480. if (!is_dir($this->vqmod_script_dir)) {
  481. $this->session->data['vqmod_installation_error'] = $this->language->get('error_vqmod_script_dir');
  482. return false;
  483. }
  484. // Check if /vqmod/vqcache directory exists
  485. if (!is_dir($this->vqcache_dir)) {
  486. $this->session->data['vqmod_installation_error'] = $this->language->get('error_vqcache_dir');
  487. return false;
  488. }
  489. // Check that vqmod_opencart.xml exists
  490. if (!is_file($this->vqmod_opencart_script)) {
  491. if (is_file($this->vqmod_opencart_script . '_')) {
  492. $this->session->data['error'] = $this->language->get('error_opencart_xml_disabled');
  493. } else {
  494. $this->session->data['vqmod_installation_error'] = $this->language->get('error_opencart_xml');
  495. return false;
  496. }
  497. }
  498. // Check that OpenCart 1.5.x is being used - other errors will appear on the page if they're using 1.4.x but at least the user will be told what the issue is
  499. if (!defined('VERSION') || version_compare(VERSION, '1.5.0', '<')) {
  500. $this->session->data['vqmod_installation_error'] = $this->language->get('error_opencart_version');
  501. return false;
  502. }
  503. // If OpenCart 1.5.4+ check that vqmod_opencart.xml 2.1.7 or later is being used
  504. if (version_compare(VERSION, '1.5.4', '>=')) {
  505. libxml_use_internal_errors(true);
  506. $xml = simplexml_load_file($this->vqmod_opencart_script);
  507. libxml_clear_errors();
  508. // In VQMod 2.3.0 'vqmver' is set as '2.X'
  509. if ((isset($xml->vqmver)) && (strtolower($xml->vqmver) != '2.x') && (version_compare($xml->vqmver, '2.1.7', '<'))) {
  510. $this->session->data['vqmod_installation_error'] = $this->language->get('error_opencart_xml_version');
  511. return false;
  512. }
  513. }
  514. // Check if VQMod class is added to OpenCart
  515. if (!class_exists('VQMod')) {
  516. if (is_file($this->vqmod_dir . 'install/index.php') && is_file($this->vqmod_dir . 'install/ugrsr.class.php')) {
  517. $this->session->data['vqmod_installation_error'] = sprintf($this->language->get('error_vqmod_install_link'), HTTP_CATALOG . 'vqmod/install');
  518. } else {
  519. $this->session->data['vqmod_installation_error'] = $this->language->get('error_vqmod_opencart_integration');
  520. }
  521. return false;
  522. }
  523. // Check VQMod Error Log Writing
  524. if ((is_dir($this->vqmod_logs_dir) && !is_writable($this->vqmod_logs_dir)) || (!is_writable($this->vqmod_dir))) {
  525. $this->session->data['vqmod_installation_error'] = $this->language->get('error_error_log_write');
  526. return false;
  527. }
  528. // Check VQMod Script Writing
  529. if (!is_writable($this->vqmod_script_dir)) {
  530. $this->session->data['vqmod_installation_error'] = $this->language->get('error_vqmod_script_write');
  531. return false;
  532. }
  533. // Check VQCache Writing
  534. if (!is_writable($this->vqcache_dir)) {
  535. $this->session->data['vqmod_installation_error'] = $this->language->get('error_vqcache_write');
  536. return false;
  537. }
  538. // Check if vqcache files from vqmod_opencart.xml have been generated
  539. $vqcache_files = array(
  540. 'vq2-system_engine_controller.php',
  541. 'vq2-system_engine_front.php',
  542. 'vq2-system_engine_loader.php',
  543. 'vq2-system_library_language.php',
  544. 'vq2-system_library_template.php',
  545. 'vq2-system_startup.php'
  546. );
  547. foreach ($vqcache_files as $vqcache_file) {
  548. // Only return false if vqmod_opencart.xml_ isn't present (in case the user has disabled it) so they aren't locked out of VQMM
  549. if (!is_file($this->vqcache_dir . $vqcache_file) && !is_file($this->vqmod_opencart_script . '_')) {
  550. $this->session->data['vqmod_installation_error'] = $this->language->get('error_vqcache_files_missing');
  551. return false;
  552. }
  553. }
  554. return true;
  555. }
  556. private function userPermission($permission = 'modify') {
  557. $this->language->load('module/vqmod_manager');
  558. if (!$this->user->hasPermission($permission, 'module/vqmod_manager')) {
  559. $this->session->data['error'] = $this->language->get('error_permission');
  560. return false;
  561. } else {
  562. return true;
  563. }
  564. }
  565. }
  566. ?>