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

/controller/admin.php

http://web-optimizator.googlecode.com/
PHP | 6972 lines | 6693 code | 20 blank | 259 comment | 247 complexity | 53807590d2640c136dbb828ed06c5aa3 MD5 | raw file
  1. <?php
  2. /**
  3. * File from WEBO Site SpeedUp, WEBO Software (http://www.webogroup.com/)
  4. * Provides admin interface.
  5. *
  6. **/
  7. class admin {
  8. /**
  9. * Constructor
  10. * Sets the options and defines the gzip headers
  11. **/
  12. function admin ($options = null) {
  13. if (!empty($options['skip_startup'])) {
  14. return;
  15. }
  16. foreach ($options as $key => $value) {
  17. $this->$key = $value;
  18. }
  19. $this->skip_render = empty($this->skip_render) ? 0 : $this->skip_render;
  20. $this->time = time();
  21. if (!$this->skip_render) {
  22. /* Fixes time zone for future usage */
  23. if (function_exists('date_default_timezone_set')) {
  24. @date_default_timezone_set('Europe/Moscow');
  25. }
  26. /* Ensure no caching */
  27. header('Expires: ' . @date("r"));
  28. header("Cache-Control: no-store, no-cache, must-revalidate, private");
  29. header("Pragma: no-cache");
  30. }
  31. /* define website host */
  32. $host = empty($_SERVER['HTTP_HOST']) ? '' : strtolower($_SERVER['HTTP_HOST']);
  33. if (strpos($host, "www.") === 0) {
  34. $host = substr($host, 4);
  35. }
  36. /* Set name of options file, multi-configs supported */
  37. if ($host && @file_exists($this->basepath . $host . ".config.webo.php")) {
  38. $this->options_file = $host . ".config.webo.php";
  39. } else {
  40. $this->options_file = "config.webo.php";
  41. }
  42. /* try to restore options backup */
  43. if (@is_file($this->basepath . '.config.webo.php') && !strpos($this->file_get_contents($this->basepath . $this->options_file), '$compress_options[\'license\']')) {
  44. @copy($this->basepath . '.config.webo.php', $this->basepath . $this->options_file);
  45. $this->error = array(-1 => 1);
  46. }
  47. require($this->basepath . $this->options_file);
  48. $this->compress_options = empty($compress_options) ? '' : $compress_options;
  49. $this->start_cache_engine();
  50. /* to check and download new Web Optimizer version */
  51. $this->svn_generic = 'http://web-optimizator.googlecode.com/svn/';
  52. $this->svn = $this->svn_generic . 'trunk-stable/';
  53. $this->svn_beta = $this->svn_generic . 'trunk/';
  54. $this->version = str_replace(array("\r", "\n"), "", $this->file_get_contents($this->basepath . 'version'));
  55. $this->version_stable = preg_replace("[^0-9\.]", "", empty($this->input['wss_version_stable']) ? '' : $this->input['wss_version_stable']);
  56. /* get the latest version */
  57. $version_new_file = $this->compress_options['html_cachedir'] . 'version.new';
  58. $this->input['wss_page'] = empty($this->input['wss_page']) ? '' : $this->input['wss_page'];
  59. if (in_array($this->input['wss_page'],
  60. array('install_dashboard',
  61. 'install_set_password',
  62. 'install_enter_password',
  63. 'install_system',
  64. 'install_update',
  65. 'install_beta',
  66. 'install_stable',
  67. 'install_rollback'))) {
  68. $this->view->download($this->svn . 'version', $version_new_file, 5);
  69. }
  70. $this->version_new = $this->version . '+';
  71. if (@is_file($version_new_file)) {
  72. $this->version_new = str_replace(array("\r", "\n"), "", $this->file_get_contents($version_new_file));
  73. @unlink($version_new_file);
  74. }
  75. $this->version_beta = $this->version;
  76. /* check for beta version */
  77. if (in_array($this->input['wss_page'],
  78. array('install_system',
  79. 'install_beta',
  80. 'install_stable',
  81. 'install_rollback'))) {
  82. $this->view->download($this->svn_beta . 'version', $version_new_file, 5);
  83. if (@is_file($version_new_file)) {
  84. $this->version_beta = str_replace(array("\r", "\n"), "", $this->file_get_contents($version_new_file));
  85. @unlink($version_new_file);
  86. }
  87. }
  88. /* validate license */
  89. if (!empty($compress_options)) {
  90. /* reset license check */
  91. if (!empty($this->input['wss_license']) && $this->input['wss_license'] != $this->compress_options['license']) {
  92. @unlink($this->compress_options['html_cachedir'] . 'wo');
  93. }
  94. $this->compress_options['license'] =
  95. empty($this->input['wss_license']) ?
  96. $this->compress_options['license'] :
  97. $this->input['wss_license'];
  98. $this->premium = $this->view->validate_license($this->compress_options['license'],
  99. $this->compress_options['html_cachedir'], $this->compress_options['host']);
  100. $this->need_access = in_array($this->input['wss_page'],
  101. array('install_enter_password', 'install_set_password'));
  102. /* Make sure password valid */
  103. $this->check_password();
  104. if (!$this->access) {
  105. $this->input['wss_page'] = 'install_set_password';
  106. } elseif ($this->need_access) {
  107. $this->input['wss_page'] = 'install_dashboard';
  108. }
  109. /* default multiple hosts */
  110. $this->default_hosts = array('img', 'img1', 'img2', 'img3', 'img4', 'i', 'i1', 'i2', 'i3', 'i4', 'image', 'images', 'assets', 'static', 'css', 'js');
  111. /* Set page functions for the installation and admin, makes sure nothing else can be run */
  112. $this->page_functions = array('install_set_password', 'install_enter_password', 'install_dashboard', 'install_install', 'install_uninstall', 'install_promo', 'install_about', 'install_minify', 'install_gzip', 'install_image', 'install_cdn', 'install_status', 'install_account', 'install_refresh', 'install_renew', 'install_options', 'install_system', 'install_update', 'install_stable', 'install_rollback', 'install_beta', 'install_awards', 'install_balance', 'install_wizard', 'dashboard_cache', 'dashboard_system', 'dashboard_options', 'dashboard_speed', 'dashboard_awards', 'compress_gzip', 'compress_image', 'compress_cdn', 'compress_minify', 'options_configuration', 'options_delete');
  113. /* inializa stage for chained optimization */
  114. $this->web_optimizer_stage =
  115. round(empty($this->input['web_optimizer_stage']) ? 0 :
  116. $this->input['web_optimizer_stage']);
  117. /* grade URL from webo.name */
  118. $this->webo_grade = 'https://www.googleapis.com/pagespeedonline/v1/runPagespeed?key=AIzaSyD1VD8YlfdF1RZpPrhOZ1awzuMs4t143Fo&url=http://' .
  119. $this->compress_options['host'] .
  120. str_replace($this->compress_options['document_root'], '/',
  121. $this->compress_options['website_root']);
  122. /* download counter */
  123. if (!is_file($this->basepath . 'web-optimizer-counter')) {
  124. $this->view->download('http://web-optimizator.googlecode.com/files/web-optimizer-counter',
  125. $this->basepath . 'web-optimizer-counter', 10);
  126. }
  127. /* download WPT evaluation */
  128. if (!is_file($this->basepath . 'web-optimizer-wpt') && !empty($this->compress_options['host'])) {
  129. $this->view->download('http://webo.name/check/wpt.php?url=http://' .
  130. $this->compress_options['host'] .
  131. str_replace($this->compress_options['document_root'], '/',
  132. $this->compress_options['website_root']) .
  133. '&email=' . $this->compress_options['email'], $this->basepath . 'web-optimizer-wpt');
  134. }
  135. }
  136. /* define constants for stats */
  137. $this->index_check = 'index.check';
  138. $this->index_before = 'index.before';
  139. $this->index_after = 'index.after';
  140. /* initialize info about cache types */
  141. $this->cache_types = array(
  142. 'js' => array('*.js', '*.js.gz'),
  143. 'js_php' => array('*script.php', '*script.php.gz', '*script.php.df'),
  144. 'css' => array('*.css', '*.css.gz'),
  145. 'css_php' => array('*link.php', '*link.php.gz', '*link.php.df'),
  146. 'res' => array('*.css.css', '*.css.css.gz', '*.php.php', '*.php.php.gz'),
  147. 'sprites' => array('webo.*.png', 'webo.*.jpg'),
  148. 'imgs' => array('*.png', '*.jpg', '*.gif', '*.bmp'),
  149. 'html' => array('*.html','*.html.gz', '*.html.df'),
  150. 'scripts' => array('*.php', '*.php.gz', '*.php.df')
  151. );
  152. /* define if we can skip some info */
  153. $this->internal = preg_match("@wp-content|components|modules|administrator|addons|app|engine@",
  154. str_replace($this->compress_options['document_root'], '/', $this->basepath));
  155. /* detect CS-Cart to */
  156. $this->cscart = strpos($this->basepath, 'addons/webositespeedup');
  157. /* check for database driver , WordPress */
  158. $this->internal_sql = strpos($this->basepath, "wp-content") !== false ||
  159. /* Joomla! 1.5x */
  160. (strpos($this->basepath, "components") !== false && @is_file($this->compress_options['website_root'] . 'libraries/joomla/database/database/WeboMySql.php'));
  161. /* fix for not supported languages */
  162. $this->language = empty($this->language) ? '' : $this->language;
  163. $this->language = in_array($this->language, array('en', 'de', 'es', 'ru', 'ua', 'fr', 'ur', 'it', 'da', 'bg')) ? $this->language : 'en';
  164. /* calculate configuration files for Extended and Corporate Editions */
  165. $this->find_configs($this->premium > 1 && $this->premium < 10);
  166. if ($this->compress_options['active']) {
  167. $this->validate();
  168. }
  169. $this->iis = !empty($_SERVER['SERVER_SOFTWARE']) && strpos($_SERVER['SERVER_SOFTWARE'], 'IIS') !== false;
  170. /* show page */
  171. if (!empty($this->input) &&
  172. in_array($this->input['wss_page'], $this->page_functions) &&
  173. method_exists($this, $this->input['wss_page']) &&
  174. ($this->input['wss_page'] != 'install_set_password' ||
  175. empty($this->internal))) {
  176. $func = $this->input['wss_page'];
  177. $this->$func();
  178. }
  179. }
  180. /*
  181. * Return status of synced file
  182. *
  183. **/
  184. function compress_cdn () {
  185. $file = realpath($this->input['wss_file']);
  186. $size = @filesize($file);
  187. $error = 0;
  188. $success = 1;
  189. if (strpos($file, $this->view->paths['full']['document_root']) !== false &&
  190. !empty($this->compress_options['parallel']['ftp']) &&
  191. @function_exists('curl_init')) {
  192. $mime = '';
  193. /* calculate MIME type */
  194. switch (strtolower(preg_replace("!.*\.!is", "", $file))) {
  195. case 'js':
  196. $mime = 'application/x-javascript';
  197. break;
  198. case 'css':
  199. $mime = 'text/css';
  200. break;
  201. case 'jpg':
  202. $mime = 'jpeg';
  203. case 'jpeg':
  204. case 'bmp':
  205. case 'gif':
  206. case 'png':
  207. $mime = 'image/' . $mime;
  208. break;
  209. case 'cur':
  210. $mime = 'image/vnd.microsoft.icon';
  211. break;
  212. case 'ico':
  213. $mime = 'image/x-icon';
  214. break;
  215. case 'otf':
  216. $mime = 'application/x-font-opentype';
  217. break;
  218. case 'ttf':
  219. $mime = 'application/x-font-truetype';
  220. break;
  221. case 'svg':
  222. $mime = 'image/svg+xml';
  223. break;
  224. case 'eot':
  225. $mime = 'application/vnd.ms-fontobject';
  226. break;
  227. case 'woff':
  228. $mime = 'font/woff';
  229. break;
  230. }
  231. $error = $this->view->upload_cdn($file,
  232. $this->compress_options['html_cachedir'],
  233. $this->compress_options['parallel']['ftp'],
  234. $mime,
  235. $this->compress_options['host']);
  236. if (strpos($error, 'Error:') !== false) {
  237. $success = 0;
  238. }
  239. }
  240. $page_variables = array(
  241. "file" => $file,
  242. "size" => $size,
  243. "compressed" => $size,
  244. "success" => $success,
  245. "error" => $error,
  246. "skip_render" => $this->skip_render
  247. );
  248. $this->view->render("compress_gzip", $page_variables);
  249. }
  250. /*
  251. * Return size of specific (optimized images) files
  252. *
  253. **/
  254. function compress_image () {
  255. $file = str_replace('\\', '/', realpath($this->input['wss_file']));
  256. $service = empty($this->input['wss_service']) ? 0 : round($this->input['wss_service']);
  257. $mtime = @filemtime($file);
  258. $size = @filesize($file);
  259. $backup = empty($this->input['wss_backup']) ? '' : $file . '.backup';
  260. $compressed_size = $size;
  261. $error = 0;
  262. if (strpos($file, $this->view->paths['full']['document_root']) !== false) {
  263. if (!$backup || !@is_file($backup) || $mtime != @filemtime($backup)) {
  264. require(dirname(__FILE__) . '/../libs/php/css.sprites.optimize.php');
  265. $optimizer = new css_sprites_optimize();
  266. /* CSS Sprites uses .backup itself, so just prepare another backup */
  267. if ($backup && @is_file($backup)) {
  268. @copy($backup, $file . '.bkp');
  269. } else {
  270. @copy($file, $file . '.bkp');
  271. }
  272. $optimizer->website_root = $this->view->paths['full']['document_root'];
  273. switch ($service) {
  274. case 2:
  275. $optimizer->punypng($file);
  276. break;
  277. case 1:
  278. $optimizer->webolk($file);
  279. break;
  280. default:
  281. $optimizer->smushit($file);
  282. break;
  283. }
  284. /* copy backup back */
  285. if ($backup) {
  286. @copy($file . '.bkp', $backup);
  287. }
  288. @unlink($file . '.bkp');
  289. $mtime2 = @filemtime($file);
  290. /* Has file been changed? */
  291. $success = $mtime2 > $mtime ? 1 : 0;
  292. if ($success) {
  293. $compressed_size = @filesize($file);
  294. @touch($backup, $mtime2);
  295. /* can't overwrite targeted file */
  296. } else {
  297. $error = 1;
  298. }
  299. } else {
  300. $success = 1;
  301. }
  302. }
  303. $page_variables = array(
  304. "file" => $file,
  305. "size" => $size,
  306. "compressed" => $compressed_size,
  307. "success" => $success,
  308. "error" => $error,
  309. "skip_render" => $this->skip_render
  310. );
  311. $this->view->render("compress_gzip", $page_variables);
  312. }
  313. /*
  314. * Return size of specific (minified) files
  315. *
  316. **/
  317. function compress_minify () {
  318. $file = realpath($this->input['wss_file']);
  319. $size = @filesize($file);
  320. $chunks = explode(".", $file);
  321. $extension = array_pop($chunks);
  322. $gzipped = $file;
  323. $gzipped_size = $size;
  324. $success = 0;
  325. $error = 0;
  326. if (strpos($file, $this->view->paths['full']['document_root']) !== false) {
  327. $content = '';
  328. $c = $this->file_get_contents($file);
  329. $not_buffered = 1;
  330. require(dirname(__FILE__) . '/../web.optimizer.php');
  331. $not_buffered = 1;
  332. switch (strtolower($extension)) {
  333. case 'css':
  334. switch ($this->compress_options['minify']['css_min']) {
  335. case 1:
  336. $content = $web_optimizer->minify_text($c);
  337. break;
  338. case 2:
  339. $c = preg_replace("!/\*.*?\*/!is", "", $c);
  340. require(dirname(__FILE__) . '/../libs/php/class.csstidy.php');
  341. $csstidy = new csstidy();
  342. $csstidy->load_template(dirname(__FILE__) . '/../libs/php/css.template.tpl');
  343. $csstidy->parse($c);
  344. $content = $csstidy->print->plain();
  345. break;
  346. }
  347. break;
  348. case 'js':
  349. foreach ($web_optimizer->libraries as $klass => $library) {
  350. if (!class_exists($klass, false)) {
  351. require($web_optimizer->options['css']['installdir'] . 'libs/php/' . $library);
  352. }
  353. }
  354. $content = $web_optimizer->minify_javascript($c, $web_optimizer->options['javascript']);
  355. break;
  356. }
  357. if (strlen($content)) {
  358. @copy($file, $file . '.backup');
  359. $success = $this->write_file($gzipped, $content);
  360. /* can't overwrite targeted file */
  361. if (!$success) {
  362. $error = 1;
  363. }
  364. } else {
  365. $success = 0;
  366. /* cam't gzip file */
  367. $error = 2;
  368. }
  369. if ($success) {
  370. @touch($gzipped, @filemtime($file));
  371. $gzipped_size = @filesize($gzipped);
  372. }
  373. }
  374. $page_variables = array(
  375. "file" => $file,
  376. "size" => $size,
  377. "compressed" => $gzipped_size,
  378. "success" => $success,
  379. "error" => $error,
  380. "skip_render" => $this->skip_render
  381. );
  382. $this->view->render("compress_gzip", $page_variables);
  383. }
  384. /*
  385. * Return size of specific (compressed) files
  386. *
  387. **/
  388. function compress_gzip () {
  389. $file = realpath($this->input['wss_file']);
  390. $size = @filesize($file);
  391. $gzipped = $file . '.gz';
  392. $gzipped_size = $size;
  393. $success = 0;
  394. $error = 0;
  395. if (strpos($file, $this->view->paths['full']['document_root']) !== false) {
  396. if (!@is_file($gzipped) || !@filesize($gzipped)) {
  397. $raw = !function_exists('shell_exec');
  398. $success = 1;
  399. if (!$raw) {
  400. @shell_exec('gzip -c -n -9 ' . $file . ' > ' . $gzipped);
  401. if (!@is_file($gzipped) || !@filesize($gzipped)) {
  402. $raw = 1;
  403. }
  404. }
  405. if ($raw) {
  406. $content = @gzencode($this->file_get_contents($file), 9, FORCE_GZIP);
  407. if (strlen($content)) {
  408. $success = $this->write_file($gzipped, $content);
  409. /* can't overwrite targeted file */
  410. if (!$success) {
  411. $error = 1;
  412. }
  413. } else {
  414. $success = 0;
  415. /* cam't gzip file */
  416. $error = 2;
  417. }
  418. }
  419. if ($success) {
  420. @touch($gzipped, @filemtime($file));
  421. $gzipped_size = @filesize($gzipped);
  422. }
  423. } else {
  424. $success = 1;
  425. $gzipped_size = @filesize($gzipped);
  426. }
  427. }
  428. $page_variables = array(
  429. "file" => $file,
  430. "size" => $size,
  431. "compressed" => $gzipped_size,
  432. "success" => $success,
  433. "error" => $error,
  434. "skip_render" => $this->skip_render
  435. );
  436. $this->view->render("compress_gzip", $page_variables);
  437. }
  438. /*
  439. * Returns all info about current award + retrieves them from server
  440. *
  441. **/
  442. function calculate_awards () {
  443. $evaluation1 = $this->file_get_contents($this->basepath . $this->index_before);
  444. $evaluation1 = strpos($evaluation1, 'responseCode": 200') === false ? '' : $evaluation1;
  445. $evaluation2 = $this->file_get_contents($this->basepath . $this->index_after);
  446. $evaluation2 = strpos($evaluation1, 'responseCode": 200') === false ? '' : $evaluation2;
  447. /* first level - WEBO grade (YSlow + Page Speed + WEBO) */
  448. $grade = round(preg_replace("!.*score\":\s*([0-9]+),.*!s", "$1", $evaluation2));
  449. $level1 = $grade > 50 ? $grade > 70 ? $grade > 90 ? 3 : 2 : 1 : 0;
  450. /* second level - website home page size savings */
  451. $size11 = round(preg_replace("!.*htmlResponseBytes\":\s*([0-9]+),.*!", "$1", $evaluation1));
  452. $size12 = round(preg_replace("!.*cssResponseBytes\":\s*([0-9]+),.*!", "$1", $evaluation1));
  453. $size13 = round(preg_replace("!.*imageResponseBytes\":\s*([0-9]+),.*!", "$1", $evaluation1));
  454. $size14 = round(preg_replace("!.*javascriptResponseBytes\":\s*([0-9]+),.*!", "$1", $evaluation1));
  455. $size1 = $size11 + $size12 + $size13 + $size14;
  456. $size21 = round(preg_replace("!.*htmlResponseBytes\":\s*([0-9]+),.*!", "$1", $evaluation2));
  457. $size22 = round(preg_replace("!.*cssResponseBytes\":\s*([0-9]+),.*!", "$1", $evaluation2));
  458. $size23 = round(preg_replace("!.*imageResponseBytes\":\s*([0-9]+),.*!", "$1", $evaluation2));
  459. $size24 = round(preg_replace("!.*javascriptResponseBytes\":\s*([0-9]+),.*!", "$1", $evaluation2));
  460. $size2 = $size21 + $size22 + $size23 + $size24;
  461. $delta = ($size1 - $size2) / ($size1 + 0.01);
  462. $level2 = $size1 && $size2 && $delta > 0.25 ? $delta > 0.5 ? $delta > 0.75 ? 3 : 2 : 1 : 0;
  463. /* fourth level - number of files on home page */
  464. $files1 = round(preg_replace("!.*numberResources\":\s*([0-9]+),.*!", "$1", $evaluation1));
  465. $files = round(preg_replace("!.*numberResources\":\s*([0-9]+),.*!", "$1", $evaluation2));
  466. $level4 = $files ? !$files || $files < 35 ? $files < 20 ? $files < 10 ? 3 : 2 : 1 : 0 : 0;
  467. /* third level - gained acceleration */
  468. $time1 = round(preg_replace("!.*numberHosts\":\s*([0-9]+),.*!", "$1", $evaluation1));
  469. $time2 = round(preg_replace("!.*numberHosts\":\s*([0-9]+),.*!", "$1", $evaluation2));
  470. $time1 *= $size1 * $files1;
  471. $time2 *= $size2 * $files;
  472. $speedup = ($time1 - $time2) / ($time1 + 0.01);
  473. $speedup = $speedup < 0 || $speedup > 0.9998 ? 0 : $speedup;
  474. $level3 = $speedup > 0.5 ? $speedup > 0.65 ? $speedup > 0.8 ? 3 : 2 : 1 : 0;
  475. /* fifth level - WEBO Site SpeedUp options */
  476. $errors = $this->options_count();
  477. /* count delta */
  478. $deltas = array(28, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
  479. $options = $deltas[round($this->premium)];
  480. foreach ($errors as $key => $value) {
  481. $options += $value;
  482. }
  483. $level5 = $options < 50 ? $options < 25 ? $options < 5 ? 3 : 2 : 1 : 0;
  484. $awards = $level1 . $level2 . $level3 . $level4 . $level5;
  485. $host = $this->compress_options['host'];
  486. /* check for images existence */
  487. if (!@is_file($this->compress_options['css_cachedir'] . 'webo-site-speedup.back.jpg')) {
  488. @copy($this->basepath . 'libs/css/webo-site-speedup.back.jpg',
  489. $this->compress_options['css_cachedir'] . 'webo-site-speedup.back.jpg');
  490. }
  491. if (!@is_file($this->compress_options['css_cachedir'] . 'webo-site-speedup.rocket.png')) {
  492. @copy($this->basepath . 'libs/css/rocket.main.png',
  493. $this->compress_options['css_cachedir'] . 'webo-site-speedup.rocket.png');
  494. }
  495. if ($this->compress_options['awards'] != $awards ||
  496. !@is_file($this->compress_options['css_cachedir'] . 'webo-site-speedup88.png')) {
  497. $sizes = array('88', '125', '161', '250');
  498. foreach ($sizes as $size) {
  499. $this->view->download("http://webo.in/rocket/?size=$size&top=$level1&middle=$level2&bottom=$level3&tail=$level4&circle=$level5",
  500. $this->compress_options['css_cachedir'] . 'webo-site-speedup' . $size . '.png');
  501. $this->view->download("http://webo.in/webonautes/?url=$host&options=" . (100 - $options),
  502. $this->compress_options['css_cachedir'] . 'webonautes.png');
  503. for ($i=1; $i<6; $i++) {
  504. $this->view->download("http://webo.in/webonautes/?size=$size&type=$i&url=$host&options=" . (100 - $options),
  505. $this->compress_options['css_cachedir'] . 'webonaut' . $i . '-' . $size . '.png');
  506. }
  507. }
  508. $local = @is_file($this->compress_options['css_cachedir'] . 'webo-site-speedup250.png');
  509. $this->save_option("['awards']", $awards);
  510. /* save final page with awards */
  511. @ob_start();
  512. include($this->basepath . 'view/external_awards.php');
  513. $content = @ob_get_contents();
  514. @ob_end_clean();
  515. /* add gzip / charset envelope */
  516. $content = '<?php header("Content-type:text/html;charset=utf-8");ob_start(\'a\');function a($b){$c=empty($_SERVER[\'HTTP_ACCEPT_ENCODING\'])?\'\':$_SERVER[\'HTTP_ACCEPT_ENCODING\'];$d=empty($_SERVER["HTTP_USER_AGENT"])?\'\':$_SERVER["HTTP_USER_AGENT"];if(!empty($b)&&(strpos($c,\'gzip\')!==\'false\'||strpos($c,\'deflate\')!==\'false\')){if(!strstr($d,"Opera")&&preg_match("/compatible; MSIE ([0-9]\.[0-9])/i",$d,$matches)){$e=floatval($matches[1]);if($e<7){$b=str_repeat(" ", 2048)."\r\n".$b;}}$g=@gzencode($b,7,strpos($c,\'gzip\')!==\'false\'?FORCE_GZIP:FORCE_DEFLATE);if(!empty($g)){header(\'Content-Encoding: gzip\');header(\'Vary: Accept-Encoding,User-Agent\');return $g;}}return $b;}?>' . $content;
  517. $this->write_file($this->compress_options['css_cachedir'] . 'webo-site-speedup.php', $content);
  518. $url = 'mhtml:http://' . $host .
  519. str_replace($this->compress_options['document_root'], "/",
  520. $this->compress_options['css_cachedir']) .
  521. 'webo-site-speedup.css!';
  522. $content = '.wg-teeth{background-image:url(' .
  523. $url .
  524. '1)}.wg-footer-logo{background-image:url(' .
  525. $url .
  526. "2);display:inline;zoom:1}/*\nContent-Type:multipart/related;boundary=\"_\"" .
  527. "\n\n--_\nContent-Location:1\nContent-Transfer-Encoding:base64\n\n" .
  528. 'iVBORw0KGgoAAAANSUhEUgAAAAoAAAAJCAYAAAALpr0TAAAATklEQVQYGY3BTRFAUAAGwG8EEEGNF0YVI4wwasjg7LDGifG/m5ygRZs3aDBjRpM7qDDajahyhs5VnyMULK4WlGxQY/JsQh0Mvg3xU/y0AgXf++/+7UXZAAAAAElFTkSuQmCC' .
  529. "\n\n--_\nContent-Location:2\nContent-Transfer-Encoding:base64\n\n" .
  530. 'iVBORw0KGgoAAAANSUhEUgAAAFgAAAAiCAYAAADbLB6TAAAH80lEQVRo3u1aaWxVRRR+McQY4hZDVIx7lGBVQnAJIlEWURCFKCIaJQEVNFaIuCAimCo2Fdmk2uV11ecCFDAKSAlVARGUNLU2lShxqWwiKjYEm6YhDZ6v+aYcjnPve7dK+fF6k5N339yZuTPfnG2+ubGY5yotLT0vHo/PFakV+UvkiMiewsLCdUVFRY/n5eWdGgu4pF5PqTdL5HPV9jf+nyHSPZbuF4E9EiJ/CNBjdJusrKyTCGBzWFsBuqgL4Hh8XxKAHVivo35FRcXJ8n9TKm1EKrsAjsdHioZuk98KaKXcT5LfbJF6D2BZAvQHHvDhEmaiLVyG3K8V+UzuM2JdV/AlgI0XoA6FaOhuqTMgXfCAaywuLj5H5n1GLCSg1TAQ3Zmihg8UafGAuw/9pdjHs1yoNXAxAXXKRH6UBbvOLPIkBt3nTHlf1Jfyd5XrWoW5eWSXiyNs9715/qvIRulrdMDYeossFWlS898hMr28vPwUXfE1VaE6gibP8biFuyO4ofYFkr7u8zzvofpeqcq7ixxkeZPOSuR+iWtDxRmYJB68x3bzw+rJ+O4yYxsboGDtOGL8rnKdbyLJLk5Ad7o3op/fqSZQkqROo5hiN5RhEc2ijlNZzAHnplAmpjtE1d0uklBSmJ+ffynfs1jVW8Xna1RZjRpTPwPuLlgMY8xhNacNrsEBVXl6RJAaOrI4tIDlCqRPA/pf6OoIWP0J8GpfViLl16qyNy3A8r4FIfNoB7igoOAqVb6d5TtVmc6W4todyPv6YHHVO0fFzGAfiQjSBtV2fsS2bydzTcbEs2UyZyrt+Zu/0Joe0t+LCqRBHg2uRICGyGLcn5ube7oPYHn+PAP5DKWRS1BP+j1b9VfnrEpf0vdQpTjL0Ple1SgnCkicAIJBjTO3CNpfpSb1cVCEluf7nZlCAdRYJ6v7TKaVuD/gJm4AtlLsA9gjTQLsxZ4FzwqZWyPr1B8zUZhEZ6Q2RhMB8Kshgy1lvVaVhzfw2Q6nTXyO+4RRAB9ozdpakwAM+RqLZi0qRClcEK5F55kmYo7vhFx6gZlAv6C6Yma3e6L6HD6b5Xl2hw/gqD4YQEmbAtX3rcxs3EL+cEw6dnRuo1SbRAzEDbgFVYjcdODxAldAediAsiWsPnPZQwbEXngGt2TNWadt/0OQe1r508dYprOLFbBGNbdhyqW1LYpDfYwZaAvz3J5hk0egkE4nIlXyOXxPYp7wmGrvFPz1Sl/KxGfVCoTVnhjh2u2UOa1X8qGUXe1xEVvxHNt6nXZJ3zcRxAyz4HAHGy1Bhv6taucG+J+fySEMteCaNK0KZmX6fEjafclAaPttTTVrwUZEtZtmAM5Uk3rAANw/CVm1jH3MTeKDE8YKhyk/69uYrPdSujrV8che85IHPR33dc/lBecqf2XlsKU7k+z3u5F4WmP5ZPhBauMKu+VmwCljELRSAw1HvZKSksuY39o62CpPtIrjeG9q/i/OGkFwIYb56rf5Oh8rpqTeLMa9tg4GajKFppD+stOGIeNK+/jcPdAMAX6erPYlVqtwwmG5YX1JwLhenr3B7afPpOanBcDYIltWzBIcIVRdH625Scx8qjnxaG2PtCFZhIzlZnDU4nYuSFVhwIJJm0fDjrc65aKv1JPenSrl2MEceIB5X4PXZx0NpIjO9dLuC4wtqK4N2KiPPBkLi9RL/t92QgC2yboM5sZOeOcUExxvCQBqgjz/zoEqC39aihbZ7La3/P9OWB58vN3DFjXZzR1o3zOQzQ93F43qvYsC+gb30OAj5OkCanlQgOB8oWHAtmNXJ8+G813YTNXBgqQsT+6fUO/Jdnk8Lboa2Yn8zmZ/yBQSblOBPpHiITYhBYU7ZRybCYXgFj6nbadnJvpCB3Zl8KNNoAsjttW0Y1UAwD3ICWMzMdKVM61qpl/GThTXRgbWQY5RAyBM45Zj24ujHfp0WEadYshaXNoI63LkEzZQmBd2jlLnK8eZMC/HvDNlLBdxMXKQKEj9y5EQMGnIsXTl5Ij+dJtqWxhR80uVi9gWtlvkgeshaCrTyZc0AycTOp9p4lmOUsRvkItgny1wI9S6b531cjHHGvrxSZ6WVCqAGzwM2jRsQrgRadP+mN47gwv9D8f7lRHbfhSlLVwAUj0Z/D2gGrFAxuUgVcxIBWD1fpwLNiAIgrwhsYRtcHeaPDY3W5GNiLzlDgYIcK1ZMLy/HG7DCbgM64OrIph4htH+gz52KQSw/VHzYWg6viwiMFUq3wZArXAXPoBJ7i8248fRU6MDjVvuP92BKU8n2skj7FyDAHYnQ76zRZsDb4oAUMKzt58Sof1BdRw0JIQgKoMvlN+XMWH4QwaiRhLtSPs2Q8P0qYMGWNo/JWU/iQyW+xv04amjN+nL4YaGK4tpIk05WOQbBC/SmP8CWMqeAZ2A0xLm7QvbTk3wIhw64tBOfq/sIOXYzo6l+k2E1Bsh9T+BPw2p04sLuVnu38fOUB8+ogzECvpwmQbNNaGPhEh5LuTOc7oGXufV8LWaFeTCroVWixJcg35huSSRXvHgMo4ZDQ5AZ0fe5CAqe8jywx4Kcmoy+jKtL/q4FuZ/S2mm6zzfArQivfF9I4EvK8lyFXNVf6dJjugCOPzTKO0OJijzmBdCTx5JdkSfVpfn2wMrW8QPXeFpN4wEfdhXMnPSHmAm83Dw+Tw+qSblmJ1sx8YoiwC2iG6lmgF0wQkjXE7g9Q+Jw0W5TeZ2uwAAAABJRU5ErkJggg==' .
  531. "\n\n--_--\n*/";
  532. $this->write_file($this->compress_options['css_cachedir'] . 'webo-site-speedup.css', $content);
  533. }
  534. /* download shorten link for twitter */
  535. $this->view->download('http://api.bit.ly/v3/shorten?login=wboptimizer&apiKey=R_c4fd5b38fe32971ae146abbf85aee568&uri='.
  536. urlencode('http://' . $this->compress_options['host'] .
  537. str_replace($this->compress_options['document_root'], "/",
  538. $this->compress_options['css_cachedir']) .
  539. 'webo-site-speedup.php') .
  540. '&format=txt', $this->compress_options['css_cachedir'] . 'url');
  541. $short_link = $this->file_get_contents($this->compress_options['css_cachedir'] . 'url');
  542. @unlink($this->compress_options['css_cachedir'] . 'url');
  543. return array($level1, $level2, $level3, $level4, $level5,
  544. 100 - $options, $grade, $files, round($size2 / 1024),
  545. round(100*((1 / (0.9999 - $speedup)) - 1)), $short_link);
  546. }
  547. /*
  548. * Calculate the best options for website.
  549. * Shows wizard page
  550. *
  551. **/
  552. function install_wizard () {
  553. $wizard = round(isset($_GET['web_optimizer_wizard']) ? $_GET['web_optimizer_wizard'] : 0);
  554. /* calculate options */
  555. if ($wizard) {
  556. $wizard_options = isset($_GET['web_optimizer_wizard_options']) ? $_GET['web_optimizer_wizard_options'] : '';
  557. /* 1 - disable application, calculate .htaccess, enable client&server side caching
  558. 2 - enable combine CSS
  559. 3 - disable combine inline CSS
  560. 4 - disable combine external CSS
  561. 5 - enable minify CSS
  562. 6 - disable minify CSS
  563. 7 - disable combine CSS
  564. 8 - enable gzip CSS
  565. 9 - disable gzip CSS
  566. 10 - enable combine JS
  567. 11 - disable combine inline JS
  568. 12 - move JS to head
  569. 13 - move JS to /head, disable combine external JS
  570. 14 - exclude JS from combine
  571. 15 - enable minify JS with JSMin
  572. 16 - enable minify JS with YUI Compressor
  573. 17 - enable minify JS with Packer
  574. 18 - disable minify JS
  575. 19 - enable duplicates removal
  576. 20 - disable duplicates removal
  577. 21 - disable combine JS
  578. 22 - enable gzip JS
  579. 23 - disable gzip JS
  580. 24 - enable minify HTML
  581. 25 - disable minify HTML
  582. 26 - enable remove HTML comments
  583. 27 - disable remove HTML comments
  584. 28 - enable gzip HTML
  585. 29 - disable gzip HTML
  586. 30 - enable plain string + no mtime
  587. 31 - disable plain string
  588. 32 - enable data:URI + mhtml + separation
  589. 33 - disable separation data:URI
  590. 34 - disable data:URI + mhtml
  591. 35 - set JS host
  592. 36 - set CSS host
  593. 37 - set IMG host
  594. 38 - enable CDN
  595. 39 - disable CDN
  596. 40 - enable HTML Sprites
  597. 41 - enable HTML Sprites restriction
  598. 42 - disable HTML Sprites
  599. 43 - move JS to /body
  600. 44 - move JS to /head
  601. 45 - enable unobtrusive JavaScript
  602. 46 - disable unobtrusive JavaScript
  603. 47 - show selection screen (step2/step3)
  604. 48 - show server side screen
  605. 49 - enable or disable server side caching
  606. 50 - show step3 screen
  607. 51 - save settings
  608. 100 - final check
  609. */
  610. switch ($wizard) {
  611. /* check htaccess, disable all options */
  612. case 1:
  613. /* disable application for future tests */
  614. $this->save_option("['active']", 0);
  615. /* disable all the other options */
  616. foreach ($this->compress_options as $group => $options) {
  617. if (is_array($options)) {
  618. foreach ($options as $key => $option) {
  619. if ($option === '1') {
  620. $this->save_option("['". $group ."']['" . $key . "']", 0);
  621. }
  622. }
  623. }
  624. }
  625. /* detect .htaccess */
  626. $this->get_modules();
  627. $ht = count($this->apache_modules) ? 1 : 0;
  628. /* enable .htaccess */
  629. $this->save_option("['htaccess']['enabled']", $ht);
  630. $this->save_option("['htaccess']['local']", $ht);
  631. $modules = array(
  632. 'mod_deflate',
  633. 'mod_gzip',
  634. 'mod_expires',
  635. 'mod_mime',
  636. 'mod_headers',
  637. 'mod_setenvif',
  638. 'mod_rewrite');
  639. foreach ($modules as $module) {
  640. if ($ht && in_array($module, $this->apache_modules)) {
  641. $this->save_option("['htaccess']['" . $module . "']", 1);
  642. $this->input['wss_htaccess_' . $module] = 1;
  643. }
  644. }
  645. if ($ht) {
  646. $this->compress_options['active'] = 1;
  647. $this->input['wss_htaccess_enabled'] = 1;
  648. $this->input['wss_htaccess_local'] = 1;
  649. $this->input['wss_gzip_fonts'] = 1;
  650. $this->input['wss_far_future_expires_css'] = 1;
  651. $this->input['wss_far_future_expires_images'] = 1;
  652. $this->input['wss_far_future_expires_javascript'] = 1;
  653. $this->input['wss_far_future_expires_fonts'] = 1;
  654. $this->input['wss_far_future_expires_video'] = 1;
  655. $this->input['wss_far_future_expires_static'] = 1;
  656. /* write complete test set of rules */
  657. $this->write_htaccess();
  658. }
  659. $test_file = $this->compress_options['html_cachedir'] . 'index.test';
  660. $t = time() + microtime();
  661. $this->view->download("http://" . $_SERVER['HTTP_HOST'] .
  662. str_replace($this->compress_options['document_root'], "/", $this->compress_options['website_root']),
  663. $test_file, 20);
  664. /* enable HTML caching if server side expenses are more than 500ms + we have known engine */
  665. if (time() + microtime() - $t > 0.5 && $this->internal) {
  666. $this->save_option("['html_cache']['enabled']", 1);
  667. $this->save_option("['html_cache']['timeout']", 3600);
  668. $this->save_option("['sql_cache']['enabled']", 1);
  669. $this->save_option("['sql_cache']['timeout']", 600);
  670. /* check for caching extensions */
  671. if (function_exists('xcache_set')) {
  672. $this->save_option("['performance']['cache_engine']", 3);
  673. } elseif (function_exists('apc_store')) {
  674. $this->save_option("['performance']['cache_engine']", 2);
  675. } elseif (@class_exists('Memcached') || @class_exists('Memcache')) {
  676. $this->save_option("['performance']['cache_engine']", 1);
  677. }
  678. }
  679. /* some errors with .htaccess, disable all options */
  680. if ($ht && !$this->file_get_contents($test_file)) {
  681. foreach ($modules as $module) {
  682. $this->save_option("['htaccess']['" . $module . "']", 0);
  683. $this->input['wss_htaccess_' . $module] = 0;
  684. }
  685. $this->save_option("['htaccess']['enabled']", 0);
  686. $this->write_htaccess();
  687. }
  688. @unlink($test_file);
  689. $this->save_option("['footer']['spot']", 1);
  690. /* enable client side caching */
  691. $this->save_option("['far_future_expires']['css']", 1);
  692. $this->save_option("['far_future_expires']['javascript']", 1);
  693. $this->save_option("['far_future_expires']['fonts']", 1);
  694. $this->save_option("['far_future_expires']['images']", 1);
  695. $this->save_option("['far_future_expires']['video']", 1);
  696. $this->save_option("['far_future_expires']['static']", 1);
  697. break;
  698. /* enable combine CSS */
  699. case 2:
  700. if ($wizard_options) {
  701. $this->save_option("['minify']['css_body']", 1);
  702. }
  703. $this->save_option("['minify']['css']", 1);
  704. $this->save_option("['external_scripts']['css']", 1);
  705. $this->save_option("['external_scripts']['css_inline']", 1);
  706. break;
  707. /* disable inline CSS */
  708. case 3:
  709. $this->save_option("['external_scripts']['css_inline']", 0);
  710. break;
  711. /* disable external CSS */
  712. case 4:
  713. $this->save_option("['external_scripts']['css']", 0);
  714. break;
  715. /* enable minify CSS */
  716. case 5:
  717. $this->save_option("['minify']['css_min']", 1);
  718. break;
  719. /* disable minify CSS */
  720. case 6:
  721. $this->save_option("['minify']['css_min']", 0);
  722. break;
  723. /* disable combine CSS */
  724. case 7:
  725. $this->save_option("['minify']['css']", 0);
  726. $this->save_option("['minify']['css_body']", 0);
  727. break;
  728. /* enable gzip CSS */
  729. case 8:
  730. $this->save_option("['gzip']['css']", 1);
  731. $this->save_option("['htaccess']['enabled']", 1);
  732. $this->compress_options['active'] = 1;
  733. $this->compress_options['htaccess']['enabled'] = 1;
  734. $this->compress_options['gzip']['css'] = 1;
  735. foreach ($this->compress_options as $group => $options) {
  736. if (is_array($options)) {
  737. foreach ($options as $key => $option) {
  738. $this->input['wss_'. $group . '_' . $key] = $option;
  739. }
  740. }
  741. }
  742. $this->write_htaccess();
  743. break;
  744. /* disable gzip CSS */
  745. case 9:
  746. $this->save_option("['gzip']['css']", 0);
  747. $this->save_option("['htaccess']['enabled']", 0);
  748. $this->input['wss_htaccess_enabled'] = 0;
  749. $this->write_htaccess();
  750. break;
  751. /* enable combine JS */
  752. case 10:
  753. $this->save_option("['minify']['javascript']", 1);
  754. $this->save_option("['external_scripts']['on']", 1);
  755. $this->save_option("['external_scripts']['inline']", 1);
  756. $this->save_option("['external_scripts']['head_end']", 1);
  757. break;
  758. /* disable combine inline JS */
  759. case 11:
  760. $this->save_option("['external_scripts']['inline']", 0);
  761. break;
  762. /* move JS to head */
  763. case 12:
  764. $this->save_option("['external_scripts']['head_end']", 0);
  765. break;
  766. /* move JS to /head, disable combine external JS */
  767. case 13:
  768. $this->save_option("['external_scripts']['head_end']", 1);
  769. $this->save_option("['external_scripts']['on']", 0);
  770. break;
  771. /* exclude JS from combine */
  772. case 14:
  773. $this->save_option("['external_scripts']['ignore_list']", htmlspecialchars($wizard_options));
  774. break;
  775. /* enable minify JS with JSMin */
  776. case 15:
  777. $this->save_option("['minify']['with_jsmin']", 1);
  778. break;
  779. /* enable minify JS with YUI Compressor */
  780. case 16:
  781. $this->save_option("['minify']['with_jsmin']", 0);
  782. $this->save_option("['minify']['with_yui']", 1);
  783. break;
  784. /* enable minify JS with Packer */
  785. case 17:
  786. $this->save_option("['minify']['with_jsmin']", 0);
  787. $this->save_option("['minify']['with_yui']", 0);
  788. $this->save_option("['minify']['with_packer']", 1);
  789. break;
  790. /* disable minify JS */
  791. case 18:
  792. $this->save_option("['minify']['with_jsmin']", 0);
  793. $this->save_option("['minify']['with_yui']", 0);
  794. $this->save_option("['minify']['with_packer']", 0);
  795. break;
  796. /* enable duplicates removal */
  797. case 19:
  798. $this->save_option("['external_scripts']['duplicates']", 1);
  799. break;
  800. /* disable duplicates removal */
  801. case 20:
  802. $this->save_option("['external_scripts']['duplicates']", 0);
  803. break;
  804. /* disable combine JS */
  805. case 21:
  806. $this->save_option("['minify']['javascript']", 0);
  807. break;
  808. /* enable gzip JS */
  809. case 22:
  810. $this->save_option("['gzip']['javascript']", 1);
  811. $this->save_option("['htaccess']['enabled']", 1);
  812. $this->compress_options['active'] = 1;
  813. $this->compress_options['htaccess']['enabled'] = 1;
  814. $this->compress_options['gzip']['javascript'] = 1;
  815. foreach ($this->compress_options as $group => $options) {
  816. if (is_array($options)) {
  817. foreach ($options as $key => $option) {
  818. $this->input['wss_'. $group . '_' . $key] = $option;
  819. }
  820. }
  821. }
  822. $this->write_htaccess();
  823. break;
  824. /* disable gzip JS */
  825. case 23:
  826. $this->save_option("['gzip']['javascript']", 0);
  827. $this->save_option("['htaccess']['enabled']", 0);
  828. $this->input['wss_htaccess_enabled'] = 0;
  829. $this->write_htaccess();
  830. break;
  831. /* enable minify HTML */
  832. case 24:
  833. $this->save_option("['minify']['page']", 1);
  834. break;
  835. /* disable minify HTML */
  836. case 25:
  837. $this->save_option("['minify']['page']", 0);
  838. break;
  839. /* enable remove HTML comments */
  840. case 26:
  841. $this->save_option("['minify']['html_comments']", 1);
  842. break;
  843. /* disable remove HTML comments */
  844. case 27:
  845. $this->save_option("['minify']['html_comments']", 0);
  846. break;
  847. /* enable plain string + no mtime */
  848. case 28:
  849. $this->save_option("['performance']['mtime']", 1);
  850. $this->save_option("['performance']['plain_string']", 1);
  851. break;
  852. /* disable plain string */
  853. case 29:
  854. $this->save_option("['performance']['plain_string']", 0);
  855. break;
  856. /* enable gzip HTML */
  857. case 30:
  858. $this->save_option("['gzip']['page']", 1);
  859. $this->save_option("['gzip']['fonts']", 1);
  860. $this->save_option("['gzip']['cookie']", 1);
  861. $this->save_option("['gzip']['noie']", 1);
  862. $this->save_option("['htaccess']['enabled']", 1);
  863. $this->compress_options['active'] = 1;
  864. $this->compress_options['htaccess']['enabled'] = 1;
  865. $this->compress_options['gzip']['page'] = 1;
  866. foreach ($this->compress_options as $group => $options) {
  867. if (is_array($options)) {
  868. foreach ($options as $key => $option) {
  869. $this->input['wss_'. $group . '_' . $key] = $option;
  870. }
  871. }
  872. }
  873. $this->write_htaccess();
  874. break;
  875. /* disable gzip HTML */
  876. case 31:
  877. $this->save_option("['gzip']['page']", 0);
  878. $this->save_option("['gzip']['fonts']", 0);
  879. $this->save_option("['gzip']['cookie']", 0);
  880. $this->save_option("['gzip']['noie']", 0);
  881. $this->save_option("['htaccess']['enabled']", 0);
  882. foreach ($this->compress_options as $group => $options) {
  883. if (is_array($options)) {
  884. foreach ($options as $key => $option) {
  885. $this->input['wss_'. $group . '_' . $key] = $option;
  886. }
  887. }
  888. }
  889. $this->input['wss_htaccess_enabled'] = 0;
  890. $this->write_htaccess();
  891. break;
  892. /* enable data:URI + mhtml + separation */
  893. case 32:
  894. $this->save_option("['data_uris']['on']", 1);
  895. $this->save_option("['data_uris']['separate']", 1);
  896. $this->save_option("['unobtrusive']['background']", 1);
  897. break;
  898. /* disable separation data:URI */
  899. case 33:
  900. $this->save_option("['data_uris']['separate']", 0);
  901. $this->save_option("['unobtrusive']['background']", 0);
  902. break;
  903. /* disable data:URI + mhtml */
  904. case 34:
  905. $this->save_option("['data_uris']['on']", 0);
  906. $this->save_option("['data_uris']['separate']", 0);
  907. $this->save_option("['unobtrusive']['background']", 0);
  908. break;
  909. /* set JS host */
  910. case 35:
  911. $this->save_option("['minify']['javascript_host']", htmlspecialchars($wizard_options));
  912. break;
  913. /* set CSS host */
  914. case 36:
  915. $this->save_option("['minify']['css_host']", htmlspecialchars($wizard_options));
  916. break;
  917. /* set IMG host */
  918. case 37:
  919. $this->save_option("['parallel']['allowed_list']", htmlspecialchars($wizard_options));
  920. break;
  921. /* enable CDN */
  922. case 38:
  923. $this->save_option("['parallel']['custom']", 0);
  924. $this->save_option("['parallel']['css']", $this->compress_options['minify']['css_host'] ? 1 : 0);
  925. $this->save_option("['parallel']['javascript']", $this->compress_options['minify']['javascript_host'] ? 1 : 0);
  926. $this->save_option("['parallel']['enabled']", $this->compress_options['parallel']['allowed_list'] ? 1 : 0);
  927. break;
  928. /* disable CDN */
  929. case 39:
  930. $this->save_option("['parallel']['custom']", 0);
  931. $this->save_option("['parallel']['css']", 0);
  932. $this->save_option("['parallel']['javascript']", 0);
  933. $this->save_option("['parallel']['enabled']", 0);
  934. $this->save_option("['minify']['css_host']", '');
  935. $this->save_option("['minify']['javascript_host']", '');
  936. $this->save_option("['parallel']['allowed_list']", '');
  937. break;
  938. /* enable HTML Sprites */
  939. case 40:
  940. $this->save_option("['css_sprites']['html_sprites']", 1);
  941. $this->save_option("['css_sprites']['html_limit']", 16);
  942. $this->save_option("['css_sprites']['html_page']", 1);
  943. break;
  944. /* disable HTML Sprites */
  945. case 41:
  946. $this->save_option("['css_sprites']['html_sprites']", 0);
  947. break;
  948. /* enable HTML images scaling */
  949. case 42:
  950. $this->save_option("['performance']['scale']", 1);
  951. break;
  952. /* disable HTML images scaling */
  953. case 43:
  954. $this->save_option("['performance']['scale']", 0);
  955. break;
  956. /* move JS to /body */
  957. case 44:
  958. $this->save_option("['unobtrusive']['body']", 1);
  959. break;
  960. /* move JS to /head */
  961. case 45:
  962. $this->save_option("['unobtrusive']['body']", 0);
  963. break;
  964. /* enable unobtrusive JavaScript */
  965. case 46:
  966. $wizard_options = round($wizard_options);
  967. $this->save_option("['unobtrusive']['informers']", ($wizard_options & 1) ? 1 : 0);
  968. $this->save_option("['unobtrusive']['counters']", ($wizard_options & 2) ? 1 : 0);
  969. $this->save_option("['unobtrusive']['ads']", ($wizard_options & 4) ? 1 : 0);
  970. $this->save_option("['unobtrusive']['iframes']", ($wizard_options & 8) ? 1 : 0);
  971. break;
  972. /* disable unobtrusive JavaScript */
  973. case 47:
  974. $this->save_option("['unobtrusive']['informers']", 0);
  975. $this->save_option("['unobtrusive']['counters']", 0);
  976. $this->save_option("['unobtrusive']['ads']", 0);
  977. $this->save_option("['unobtrusive']['iframes']", 0);
  978. break;
  979. /* switch to manual mode */
  980. case 48:
  981. break;
  982. case 49:
  983. /* enable or disable server side caching */
  984. $wizard_options = round($wizard_options);
  985. switch ($wizard_options) {
  986. case 1:
  987. $this->save_option("['html_cache']['enabled']", 0);
  988. $this->save_option("['sql_cache']['enabled']", 0);
  989. break;
  990. case 2:
  991. $this->save_option("['html_cache']['enabled']", 1);
  992. $this->save_option("['sql_cache']['enabled']", 1);
  993. break;
  994. }
  995. $this->install_clean_cache(0, 1);
  996. break;
  997. /* save config */
  998. case 51:
  999. $this->save_option("['active']", 1);
  1000. $this->compress_options['active'] = 1;
  1001. foreach ($this->compress_options as $group => $options) {
  1002. if (is_array($options)) {
  1003. foreach ($options as $key => $option) {
  1004. $this->input['wss_'. $group . '_' . $key] = $option;
  1005. }
  1006. }
  1007. }
  1008. /* detect .htaccess */
  1009. $this->get_modules();
  1010. if (count($this->apache_modules)) {
  1011. $this->save_option("['htaccess']['enabled']", 1);
  1012. $this->input['wss_htaccess_enabled'] = 1;
  1013. $this->compress_options['htaccess']['enabled'] = 1;
  1014. $this->write_htaccess();
  1015. }
  1016. /* create fake options */
  1017. $this->input['wss_combine_css'] = $this->input['wss_minify_css'] * 2 + $this->input['wss_minify_css_body'];
  1018. $this->input['wss_minify_javascript'] = $this->input['wss_minify_javascript'] * 2 + $this->input['wss_minify_javascript_body'];
  1019. $this->input['wss_minify_js'] = $this->input['wss_minify_with_google'] ? 5 :
  1020. ($this->input['wss_minify_with_packer'] ? 4 :
  1021. ($this->input['wss_minify_with_yui'] ? 3 :
  1022. ($this->input['wss_minify_with_jsmin'] ? 2 : 1)));
  1023. /* define configuration file */
  1024. if (@is_file($this->basepath . 'config.auto.php')) {
  1025. $i = 1;
  1026. while (@is_file($this->basepath . 'config.auto'. ($i++) .'.php')) {}
  1027. $this->input['wss_config'] = 'auto' . ($i - 1);
  1028. } else {
  1029. $this->input['wss_config'] = 'auto';
  1030. }
  1031. $this->save_option("['config']", $this->input['wss_config']);
  1032. $this->input['wss_title'] = 'Auto Config';
  1033. $this->input['wss_description'] = 'Created by WEBO Wizard on ' . @date("Y-m-d");
  1034. $this->input['wss_page'] = 'install_options';
  1035. $this->set_options();
  1036. break;
  1037. }
  1038. } else {
  1039. /* show generic page */
  1040. }
  1041. $page_variables = array(
  1042. "version" => $this->version,
  1043. "premium" => $this->premium,
  1044. "skip_render" => $this->skip_render,
  1045. "wizard_mode" => $wizard,
  1046. "website_root" => str_replace($this->compress_options['document_root'], "/", $this->compress_options['website_root'])
  1047. );
  1048. $this->view->render("install_wizard", $page_variables);
  1049. }
  1050. /*
  1051. * Renders awards page
  1052. *
  1053. **/
  1054. function install_awards () {
  1055. $info = $this->calculate_awards();
  1056. $level_options = array(
  1057. array(
  1058. array('gzip', 'clientside', 'combinecss'),
  1059. array('minify', 'combine_js', 'data_uri', 'css_sprites'),
  1060. array('unobtrusive', 'multiple_hosts', 'performance')),
  1061. array(
  1062. array('gzip', 'minify', 'htaccess'),
  1063. array('combinecss', 'combine_js'),
  1064. array('data_uri', 'css_sprites', 'performance')),
  1065. array(
  1066. array('gzip', 'clientside', 'htaccess', 'combinecss'),
  1067. array('minify', 'combine_js', 'data_uri', 'css_sprites', 'serverside'),
  1068. array('unobtrusive', 'multiple_hosts', 'performance')),
  1069. array(
  1070. array('combinecss', 'combine_js'),
  1071. array('data_uri', 'css_sprites'),
  1072. array('multiple_hosts', 'css_sprites')),
  1073. array(
  1074. array('htaccess', 'gzip', 'performance', 'unobtrusive'),
  1075. array('minify', 'clientside', 'combinecss', 'combine_js'),
  1076. array('css_sprites', 'data_uri', 'multiple_hosts'))
  1077. );
  1078. $page_variables = array(
  1079. "version" => $this->version,
  1080. "premium" => $this->premium,
  1081. "skip_render" => $this->skip_render,
  1082. "level1" => $info[0],
  1083. "level2" => $info[1],
  1084. "level3" => $info[2],
  1085. "level4" => $info[3],
  1086. "level5" => $info[4],
  1087. "local" => @is_file($this->compress_options['css_cachedir'] . 'webo-site-speedup250.png'),
  1088. "cachedir" => str_replace($this->compress_options['document_root'], "/",
  1089. $this->compress_options['css_cachedir']),
  1090. "short_link" => $info[10],
  1091. "level_options" => $level_options,
  1092. "host" => $this->compress_options['host'],
  1093. "options" => $info[5]
  1094. );
  1095. $this->view->render("install_awards", $page_variables);
  1096. }
  1097. /*
  1098. * Renders account page
  1099. *
  1100. **/
  1101. function install_account () {
  1102. $allow = $this->compress_options['optimization'];
  1103. $email = $this->compress_options['email'];
  1104. $name = $this->compress_options['name'];
  1105. $license = $this->compress_options['license'];
  1106. $submit = empty($this->input['wss_Submit']) ? '' : $this->input['wss_Submit'];
  1107. $error = array();
  1108. if (!empty($submit)) {
  1109. $email = $this->input['wss_email'];
  1110. $allow = empty($this->input['wss_allow']) ? 0 : 1;
  1111. $license = trim($this->input['wss_license']);
  1112. $name = $this->input['wss_name'];
  1113. if (!$this->internal && (empty($this->input['wss_password']) ||
  1114. md5($this->input['wss_password']) !=
  1115. $this->input['wss__password'])) {
  1116. $error[1] = 1;
  1117. }
  1118. if (empty($this->input['wss_email']) ||
  1119. !preg_match("/.+@.+\..+/", $this->input['wss_email'])) {
  1120. $error[2] = 1;
  1121. }
  1122. if (!empty($this->input['wss_new']) &&
  1123. (empty($this->input['wss_confirm']) ||
  1124. $this->input['wss_confirm'] !=
  1125. $this->input['wss_new']) && !$this->internal) {
  1126. $error[3] = 1;
  1127. }
  1128. $this->premium = $this->view->validate_license($license);
  1129. /* save new options */
  1130. if (!count($error)) {
  1131. $this->save_option("['email']", htmlspecialchars($email));
  1132. $this->save_option("['optimization']", $allow);
  1133. $this->save_option("['license']", htmlspecialchars($license));
  1134. $this->save_option("['name']", htmlspecialchars($name));
  1135. if (!empty($this->input['wss_new'])) {
  1136. $this->save_option("['password']", md5($this->input['wss_new']));
  1137. }
  1138. }
  1139. }
  1140. $expires = -1;
  1141. if (empty($this->premium) && !empty($license)) {
  1142. $error[4] = 1;
  1143. } elseif (@is_file($this->basepath . 'cache/wo')) {
  1144. $expires = $this->file_get_contents($this->basepath . 'cache/wo');
  1145. }
  1146. /* check for additional libraries */
  1147. if ($this->premium > 1) {
  1148. $jars_to_download = array(
  1149. 'yuicompressor/yuicompressor.jar',
  1150. 'googlecompiler/googlecompiler.jar'
  1151. );
  1152. foreach ($jars_to_download as $jar) {
  1153. $jar = 'libs/' . $jar;
  1154. if (!@is_file($this->basepath . $jar)) {
  1155. $this->view->download($this->svn . $jar, $this->basepath . $jar);
  1156. /* make lib executable */
  1157. @chmod($this->basepath . $jar, octdec("0755"));
  1158. }
  1159. }
  1160. }
  1161. $page_variables = array(
  1162. "version" => $this->version,
  1163. "premium" => $this->premium,
  1164. "submit" => $submit,
  1165. "expires" => $expires,
  1166. "allow" => $allow,
  1167. "email" => $email,
  1168. "name" => $name,
  1169. "license" => $license,
  1170. "error" => $error,
  1171. "skip_render" => $this->skip_render,
  1172. "internal" => $this->internal,
  1173. "language" => $this->language,
  1174. "root" => str_replace($this->compress_options['document_root'], '/', $this->basepath)
  1175. );
  1176. $this->view->render("install_account", $page_variables);
  1177. }
  1178. /*
  1179. * Renders about page
  1180. *
  1181. **/
  1182. function install_about () {
  1183. $email = empty($this->input['wss_email']) ? '' : $this->input['wss_email'];
  1184. $message = empty($this->input['wss_message']) ? '' : $this->input['wss_message'];
  1185. $submit = empty($this->input['wss_Submit']) ? 0 : 1;
  1186. $error = array();
  1187. if ($submit) {
  1188. if (empty($email) ||
  1189. !preg_match("/.+@.+\..+/", $email)) {
  1190. $error[1] = 1;
  1191. }
  1192. if (empty($message)) {
  1193. $error[2] = 1;
  1194. }
  1195. /* send a email to info@webo.name */
  1196. if (!count($error)) {
  1197. $this->send_message($email, $message);
  1198. }
  1199. }
  1200. $page_variables = array(
  1201. "version" => $this->version,
  1202. "premium" => $this->premium,
  1203. "email" => $email,
  1204. "message" => $message,
  1205. "error" => $error,
  1206. "submit" => $submit,
  1207. "skip_render" => $this->skip_render,
  1208. "ready" => @is_file($this->basepath . 'ready')
  1209. );
  1210. $this->view->render("install_about", $page_variables);
  1211. }
  1212. /*
  1213. * Sends a message from given e-mail
  1214. *
  1215. **/
  1216. function send_message ($email, $message, $uninstall = false) {
  1217. $headers = 'From: ' . $email . "\r\n" . 'Reply-To: ' . $email . "\r\n";
  1218. $headers .= 'Content-Type: text/plain; charset=utf-8'."\r\n";
  1219. $headers .= 'Content-Transfer-Encoding: base64';
  1220. /* general info */
  1221. $message = "On " . @date("Y-m-d") . " at " . @date("H:i:s") . " " .
  1222. $this->compress_options['name'] .
  1223. " (" . $this->compress_options['email'] . ") send a message: " .
  1224. ($uninstall ? "(after uninstalltion) " : "") . "\r\n" . $message;
  1225. /* application info */
  1226. $this->cms_version = $this->system_info($this->compress_options['document_root']);
  1227. $message .= "\r\n\r\nWEBO Site SpeedUp " . $this->version . " was " .
  1228. ($this->compress_options['active'] ? "enabled" : "disabled") .
  1229. " on " . $this->cms_version . ($this->internal ? " (plugin)" : "") .
  1230. " and has the following warnings / errors:\r\n";
  1231. /* get basic errors / warnings */
  1232. $page_variables = $this->dashboard_system(1);
  1233. if (count($page_variables['errors'])) {
  1234. foreach ($page_variables['errors'] as $key => $value) {
  1235. if (empty($value)) {
  1236. $message .= "* " . $key . "\r\n";
  1237. }
  1238. }
  1239. }
  1240. if (count($page_variables['warnings'])) {
  1241. foreach ($page_variables['warnings'] as $key => $value) {
  1242. if (empty($value)) {
  1243. $message .= "* " . $key . "\r\n";
  1244. }
  1245. }
  1246. }
  1247. $message .= "\r\n\r\nActive configuration (" .
  1248. $this->compress_options['config'] .
  1249. ") parameters:\r\n" .
  1250. "License: " . $this->compress_options['license'] . "\r\n" .
  1251. "HTTP_HOST: " . $_SERVER['HTTP_HOST'] . "\r\n" .
  1252. "DOCUMENT_ROOT: " . $_SERVER['DOCUMENT_ROOT'] . "\r\n" .
  1253. "Configuration options:\r\n" .
  1254. "document_root => " . $this->compress_options['document_root'] . "\r\n" .
  1255. "website_root => " . $this->compress_options['website_root'] . "\r\n" .
  1256. "javascript_cachedir => " . $this->compress_options['javascript_cachedir'] . "\r\n" .
  1257. "css_cachedir => " . $this->compress_options['css_cachedir'] . "\r\n" .
  1258. "html_cachedir => " . $this->compress_options['html_cachedir'] . "\r\n" .
  1259. "restricted => " . $this->compress_options['restricted'] . "\r\n" .
  1260. "plugins => " . $this->compress_options['plugins'] . "\r\n" .
  1261. "host => " . $this->compress_options['host'] . "\r\n";
  1262. foreach ($this->compress_options as $ko => $opts) {
  1263. if (is_array($opts)) {
  1264. foreach ($opts as $k => $v) {
  1265. $message .= $ko . " " . $k . " => " . $v . "\r\n";
  1266. }
  1267. }
  1268. }
  1269. @mail('info@webo.name', "=?latin-1?B?" .
  1270. base64_encode('New message from WEBO Site SpeedUp') . "?=",
  1271. base64_encode($message), $headers);
  1272. }
  1273. /*
  1274. * Renders cache refresh (from cache page)
  1275. *
  1276. **/
  1277. function install_renew () {
  1278. $this->write_progress(1);
  1279. $this->install_clean_cache(0, 1);
  1280. $this->save_option("['performance']['cache_version']", 0);
  1281. /* need to make these async requests safe somehow
  1282. $this->save_option("['active']", 0); */
  1283. $this->chained_load(str_replace(
  1284. $this->compress_options['document_root'], "/",
  1285. $this->compress_options['website_root']));
  1286. $this->save_option("['active']", $this->compress_options['active']);
  1287. $this->validate();
  1288. $this->save_option("['performance']['cache_version']",
  1289. $this->compress_options['performance']['cache_version']);
  1290. $this->install_system();
  1291. }
  1292. /*
  1293. * Renders cache refresh (from dashboard)
  1294. *
  1295. **/
  1296. function install_refresh () {
  1297. $this->write_progress(1);
  1298. $this->install_clean_cache(0, 1);
  1299. $this->save_option("['performance']['cache_version']", 0);
  1300. /* need to make these async requests safe somehow
  1301. $this->save_option("['active']", 0); */
  1302. $this->chained_load(str_replace(
  1303. $this->compress_options['document_root'], "/" ,
  1304. $this->compress_options['website_root']));
  1305. $this->save_option("['active']", $this->compress_options['active']);
  1306. $this->validate();
  1307. $this->save_option("['performance']['cache_version']",
  1308. $this->compress_options['performance']['cache_version']);
  1309. $this->install_dashboard();
  1310. }
  1311. /*
  1312. * Renders change of application status
  1313. *
  1314. **/
  1315. function install_status () {
  1316. if (empty($this->compress_options['active']) && round($this->premium)) {
  1317. $this->chained_load(str_replace(
  1318. $this->compress_options['document_root'], "/" ,
  1319. $this->compress_options['website_root']));
  1320. $this->compress_options['active'] = 1;
  1321. $this->save_option("['active']", 1);
  1322. $options = $this->get_options();
  1323. $this->input = array();
  1324. foreach ($options as $group) {
  1325. if (is_array($group)) {
  1326. foreach ($group as $key => $option) {
  1327. if (is_array($option)) {
  1328. $this->input['wss_' . $key] = $option['value'];
  1329. }
  1330. }
  1331. }
  1332. }
  1333. $this->set_options();
  1334. $this->write_htaccess();
  1335. if (!@is_file($this->basepath . $this->index_after) && $this->premium > 1 && !empty($this->compress_options['host'])) {
  1336. $this->view->download($this->webo_grade,
  1337. $this->basepath . $this->index_after, 2);
  1338. }
  1339. $this->validate();
  1340. } else {
  1341. $this->input = array(
  1342. 'wss_htaccess_enabled' => $this->compress_options['htaccess']['enabled'],
  1343. 'wss_htaccess_mod_rewrite' => $this->compress_options['htaccess']['mod_rewrite'],
  1344. 'wss_far_future_expires_css' => $this->compress_options['far_future_expires']['css'],
  1345. 'wss_far_future_expires_images' => $this->compress_options['far_future_expires']['images'],
  1346. 'wss_far_future_expires_javascript' => $this->compress_options['far_future_expires']['javascript']
  1347. );
  1348. $this->compress_options['active'] = 0;
  1349. $this->write_htaccess();
  1350. $this->save_option("['active']", 0);
  1351. }
  1352. $this->install_dashboard();
  1353. }
  1354. /*
  1355. * Return info about current optimization awards
  1356. *
  1357. **/
  1358. function dashboard_awards () {
  1359. $info = $this->calculate_awards();
  1360. $page_variables = array(
  1361. "version" => $this->version,
  1362. "premium" => $this->premium,
  1363. "skip_render" => $this->skip_render,
  1364. "level1" => $info[0],
  1365. "level2" => $info[1],
  1366. "level3" => $info[2],
  1367. "level4" => $info[3],
  1368. "level5" => $info[4],
  1369. "options" => $info[5],
  1370. "grade" => $info[6],
  1371. "files" => $info[7],
  1372. "size" => $info[8],
  1373. "speedup" => $info[9],
  1374. "short_link" => $info[10],
  1375. "local" => @is_file($this->compress_options['css_cachedir'] . 'webo-site-speedup250.png'),
  1376. "cachedir" => str_replace($this->compress_options['document_root'], "/",
  1377. $this->compress_options['css_cachedir'])
  1378. );
  1379. $this->view->render("dashboard_awards", $page_variables);
  1380. }
  1381. /*
  1382. * Return size and number of specific files
  1383. *
  1384. **/
  1385. function dashboard_cache_size ($mask, $number = false) {
  1386. $return = 0;
  1387. $files = glob($mask);
  1388. if (is_array($files)) {
  1389. foreach ($files as $filename) {
  1390. $return += @filesize($filename);
  1391. if ($number) {
  1392. $number++;
  1393. }
  1394. }
  1395. }
  1396. return $number ? array($return, $number - 1) : $return;
  1397. }
  1398. /*
  1399. * Renders block with cache information for dashboard
  1400. *
  1401. **/
  1402. function dashboard_cache () {
  1403. $res = $css = $php = $css_php = $js = $js_php = $html = $sprites = $imgs = 0;
  1404. /* get size of JS files */
  1405. if (!empty($this->compress_options['javascript_cachedir'])) {
  1406. @chdir($this->compress_options['javascript_cachedir']);
  1407. foreach ($this->cache_types['js'] as $mask) {
  1408. $js += $this->dashboard_cache_size($mask);
  1409. }
  1410. foreach ($this->cache_types['js_php'] as $mask) {
  1411. $js_php += $this->dashboard_cache_size($mask);
  1412. }
  1413. foreach ($this->cache_types['scripts'] as $mask) {
  1414. $php += $this->dashboard_cache_size($mask);
  1415. }
  1416. }
  1417. /* get size of CSS files */
  1418. if (!empty($this->compress_options['css_cachedir'])) {
  1419. @chdir($this->compress_options['css_cachedir']);
  1420. foreach ($this->cache_types['css'] as $mask) {
  1421. $css += $this->dashboard_cache_size($mask);
  1422. }
  1423. foreach ($this->cache_types['css_php'] as $mask) {
  1424. $css_php += $this->dashboard_cache_size($mask);
  1425. }
  1426. foreach ($this->cache_types['res'] as $mask) {
  1427. $res += $this->dashboard_cache_size($mask);
  1428. }
  1429. /* exclude from CSS resource files */
  1430. $css -= $res;
  1431. /* get CSS Sprites size */
  1432. foreach ($this->cache_types['sprites'] as $mask) {
  1433. $sprites += $this->dashboard_cache_size($mask);
  1434. }
  1435. /* get size of images */
  1436. foreach ($this->cache_types['imgs'] as $mask) {
  1437. $imgs += $this->dashboard_cache_size($mask);
  1438. }
  1439. /* Exclude Sprites from images */
  1440. $imgs -= $sprites;
  1441. if ($this->compress_options['css_cachedir'] !=
  1442. $this->compress_options['javascript_cachedir']) {
  1443. foreach ($this->cache_types['scripts'] as $mask) {
  1444. $php += $this->dashboard_cache_size($mask);
  1445. }
  1446. }
  1447. /* get HTML Sprites size */
  1448. @chdir($this->compress_options['html_cachedir'] . 'img/scale');
  1449. foreach ($this->cache_types['sprites'] as $mask) {
  1450. $sprites += $this->dashboard_cache_size($mask);
  1451. }
  1452. }
  1453. /* get size of HTML files */
  1454. if (!empty($this->compress_options['html_cachedir'])) {
  1455. @chdir($this->compress_options['html_cachedir']);
  1456. foreach ($this->cache_types['html'] as $mask) {
  1457. $html += $this->cache_engine->get_cache_size($mask);
  1458. }
  1459. /* get size of HTML Sprites cache */
  1460. @chdir($this->compress_options['html_cachedir'] . 'img/cache');
  1461. foreach ($this->cache_types['scripts'] as $mask) {
  1462. $css_php += $this->dashboard_cache_size($mask);
  1463. }
  1464. }
  1465. /* distribute general PHP files between CSS and JS */
  1466. if (!empty($this->compress_options['css_cachedir']) &&
  1467. !empty($this->compress_options['javascript_cachedir']) &&
  1468. $this->compress_options['javascript_cachedir'] ==
  1469. $this->compress_options['css_cachedir']) {
  1470. $css_php += $php / 3;
  1471. $js_php += $php * 2 / 3;
  1472. }
  1473. $css += $css_php;
  1474. $js += $js_php;
  1475. foreach ($this->cache_types as $key => $val) {
  1476. if (!empty($$key)) {
  1477. $$key = round($$key / 1024);
  1478. }
  1479. }
  1480. $page_variables = array(
  1481. 'css' => $css,
  1482. 'js' => $js,
  1483. 'res' => $res,
  1484. 'html' => $html,
  1485. 'sprites' => $sprites,
  1486. 'imgs' => $imgs,
  1487. 'total' => $css + $js + $res + $html + $sprites + $imgs,
  1488. "skip_render" => $this->skip_render
  1489. );
  1490. $this->view->render("dashboard_cache", $page_variables);
  1491. }
  1492. /*
  1493. * Check Web Optimizer acceleration
  1494. *
  1495. **/
  1496. function dashboard_speed () {
  1497. $this->check_acceleration();
  1498. $grade_after = $grade_before = $saved_kb = $saved_s = $s_after = $s_before = $kb_after = $kb_before = 0;
  1499. $before = $this->file_get_contents($this->basepath . $this->index_before);
  1500. $before = strpos($before, 'responseCode": 200') === false ? '' : $before;
  1501. $after = $this->file_get_contents($this->basepath . $this->index_after);
  1502. $after = strpos($after, 'responseCode": 200') === false ? '' : $after;
  1503. /* parse files' content for calculated load speed */
  1504. if (!empty($before) && !empty($after)) {
  1505. $grade_before = round(preg_replace("!.*score\":\s*([0-9]+),.*!s", "$1", $before));
  1506. $grade_after = round(preg_replace("!.*score\":\s*([0-9]+),.*!s", "$1", $after));
  1507. $grade_after = $grade_after < $grade_before ? $grade_before : $grade_after;
  1508. $size11 = round(preg_replace("!.*htmlResponseBytes\":\s*([0-9]+),.*!", "$1", $before));
  1509. $size12 = round(preg_replace("!.*cssResponseBytes\":\s*([0-9]+),.*!", "$1", $before));
  1510. $size13 = round(preg_replace("!.*imageResponseBytes\":\s*([0-9]+),.*!", "$1", $before));
  1511. $size14 = round(preg_replace("!.*javascriptResponseBytes\":\s*([0-9]+),.*!", "$1", $before));
  1512. $size21 = round(preg_replace("!.*htmlResponseBytes\":\s*([0-9]+),.*!", "$1", $after));
  1513. $size22 = round(preg_replace("!.*cssResponseBytes\":\s*([0-9]+),.*!", "$1", $after));
  1514. $size23 = round(preg_replace("!.*imageResponseBytes\":\s*([0-9]+),.*!", "$1", $after));
  1515. $size24 = round(preg_replace("!.*javascriptResponseBytes\":\s*([0-9]+),.*!", "$1", $after));
  1516. $kb_before = $size11 + $size12 + $size13 + $size14;
  1517. $kb_after = $size21 + $size22 + $size23 + $size24;
  1518. if (!empty($kb_before) && !empty($kb_after)) {
  1519. $saved_kb = $kb_before - $kb_after;
  1520. /* do not show negative numbers */
  1521. if ($grade_after <= $grade_before) {
  1522. $grade_after = 0;
  1523. }
  1524. if ($saved_kb <= 0) {
  1525. $kb_after = 0;
  1526. }
  1527. }
  1528. }
  1529. /* set variables */
  1530. $page_variables = array(
  1531. 'grade_after' => $grade_after,
  1532. 'grade_before' => $grade_before,
  1533. 'kb_after' => $kb_after,
  1534. 'kb_before' => $kb_before,
  1535. 'premium' => $this->premium,
  1536. "skip_render" => $this->skip_render
  1537. );
  1538. /* Output data */
  1539. $this->view->render("dashboard_speed", $page_variables);
  1540. }
  1541. /*
  1542. * Check WEBO Site SpeedUp options
  1543. *
  1544. **/
  1545. function options_count () {
  1546. /* get available Apache modules */
  1547. $this->get_modules();
  1548. /* check if .htaccess is avaiable */
  1549. $htaccess_available = count($this->apache_modules) ? 1 : 0;
  1550. $apache2 = 0;
  1551. /* Apache/1 indicates (for sure) Apache 1.3.0-1.3.11. Apache 1.3.12+ has
  1552. Prod in ServerTokens support, so can be false detected as Apache2 */
  1553. if (function_exists('apache_get_version')) {
  1554. $apache2 = strpos(apache_get_version(), "/1") ? 0 : 1;
  1555. }
  1556. /* fill array with errors */
  1557. $errors = array();
  1558. $value = 5;
  1559. /* first priority issues */
  1560. if (empty($this->compress_options['performance']['plain_string']) &&
  1561. $this->premium) {
  1562. $errors['performance_plain_string'] = $value;
  1563. }
  1564. if (empty($this->compress_options['gzip']['cookie']) &&
  1565. $this->premium) {
  1566. $errors['gzip_cookie'] = $value;
  1567. }
  1568. if (empty($this->compress_options['gzip']['noie']) &&
  1569. $this->premium) {
  1570. $errors['gzip_noie'] = $value;
  1571. }
  1572. if (empty($this->compress_options['performance']['restore_properties']) &&
  1573. $this->premium) {
  1574. $errors['performance_restore_properties'] = $value;
  1575. }
  1576. if (empty($this->compress_options['minify']['html_comments']) &&
  1577. $this->premium) {
  1578. $errors['minify_html_comments'] = $value;
  1579. }
  1580. /* second priority issues */
  1581. $value = 4;
  1582. if (empty($this->compress_options['css_sprites']['enabled'])) {
  1583. $errors['css_sprites_enabled'] = $value;
  1584. }
  1585. if (empty($this->compress_options['parallel']['enabled'])) {
  1586. $errors['parallel_enabled'] = $value;
  1587. }
  1588. if (empty($this->compress_options['performance']['mtime'])) {
  1589. $errors['performance_mtime'] = $value;
  1590. }
  1591. if (empty($this->compress_options['htaccess']['enabled']) ||
  1592. !$htaccess_available) {
  1593. $errors['htaccess_enabled'] = $value;
  1594. }
  1595. if (empty($this->compress_options['unobtrusive']['body'])) {
  1596. $errors['unobtrusive_body'] = $value;
  1597. }
  1598. if (empty($this->compress_options['minify']['html_one_string']) &&
  1599. $this->premium) {
  1600. $errors['minify_html_one_string'] = $value;
  1601. }
  1602. /* third priority issues */
  1603. $value = 3;
  1604. if ((empty($this->compress_options['htaccess']['mod_deflate']) ||
  1605. !in_array('mod_deflate', $this->apache_modules))) {
  1606. $errors['htaccess_mod_deflate'] = $value;
  1607. } elseif (!in_array('mod_deflate', $this->apache_modules) &&
  1608. (empty($this->compress_options['htaccess']['mod_gzip']) ||
  1609. !in_array('mod_gzip', $this->apache_modules)) &&
  1610. !$apache) {
  1611. $errors['htaccess_mod_gzip'] = $value;
  1612. }
  1613. if (empty($this->compress_options['data_uris']['on'])) {
  1614. $errors['data_uris_on'] = $value;
  1615. }
  1616. if (empty($this->compress_options['gzip']['page'])) {
  1617. $errors['gzip_page'] = $value;
  1618. }
  1619. if (empty($this->compress_options['minify']['javascript'])) {
  1620. $errors['minify_javascript'] = $value;
  1621. }
  1622. if (empty($this->compress_options['data_uris']['mhtml'])) {
  1623. $errors['data_uris_mhtml'] = $value;
  1624. }
  1625. if (empty($this->compress_options['css_sprites']['html_sprites'])) {
  1626. $errors['css_sprites_html_sprites'] = $value;
  1627. }
  1628. if (empty($this->compress_options['minify']['css'])) {
  1629. $errors['combine_css'] = $value;
  1630. }
  1631. /* fourth priority issues */
  1632. $value = 2;
  1633. if (empty($this->compress_options['htaccess']['mod_expires']) ||
  1634. !in_array('mod_expires', $this->apache_modules)) {
  1635. $errors['htaccess_mod_expires'] = $value;
  1636. }
  1637. if (empty($this->compress_options['gzip']['css'])) {
  1638. $errors['gzip_css'] = $value;
  1639. }
  1640. if (empty($this->compress_options['gzip']['javascript'])) {
  1641. $errors['gzip_javascript'] = $value;
  1642. }
  1643. if (empty($this->compress_options['htaccess']['mod_rewrite']) ||
  1644. !in_array('mod_rewrite', $this->apache_modules)) {
  1645. $errors['htaccess_mod_rewrite'] = $value;
  1646. }
  1647. if (empty($this->compress_options['far_future_expires']['css'])) {
  1648. $errors['far_future_expires_css'] = $value;
  1649. }
  1650. if (empty($this->compress_options['far_future_expires']['javascript'])) {
  1651. $errors['far_future_expires_javascript'] = $value;
  1652. }
  1653. if (empty($this->compress_options['far_future_expires']['images'])) {
  1654. $errors['far_future_expires_images'] = $value;
  1655. }
  1656. if (empty($this->compress_options['external_scripts']['on'])) {
  1657. $errors['external_scripts_on'] = $value;
  1658. }
  1659. if (empty($this->compress_options['htaccess']['mod_headers']) ||
  1660. !in_array('mod_headers', $this->apache_modules)) {
  1661. $errors['htaccess_mod_headers'] = $value;
  1662. }
  1663. if (empty($this->compress_options['minify']['javascript'])) {
  1664. $errors['minify_javascript'] = $value;
  1665. }
  1666. /* fifth priority issues */
  1667. $value = 1;
  1668. if (empty($this->compress_options['external_scripts']['css'])) {
  1669. $errors['external_scripts_css'] = $value;
  1670. }
  1671. if (empty($this->compress_options['external_scripts']['inline'])) {
  1672. $errors['external_scripts_inline'] = $value;
  1673. }
  1674. if (empty($this->compress_options['external_scripts']['css_inline'])) {
  1675. $errors['external_scripts_css_inline'] = $value;
  1676. }
  1677. if (empty($this->compress_options['gzip']['fonts'])) {
  1678. $errors['gzip_fonts'] = $value;
  1679. }
  1680. if (empty($this->compress_options['htaccess']['mod_setenvif']) ||
  1681. !in_array('mod_setenvif', $this->apache_modules)) {
  1682. $errors['htaccess_mod_setenvif'] = $value;
  1683. }
  1684. if (empty($this->compress_options['htaccess']['mod_mime']) ||
  1685. !in_array('mod_mime', $this->apache_modules)) {
  1686. $errors['htaccess_mod_mime'] = $value;
  1687. }
  1688. if (empty($this->compress_options['far_future_expires']['fonts'])) {
  1689. $errors['far_future_expires_fonts'] = $value;
  1690. }
  1691. if (empty($this->compress_options['far_future_expires']['video'])) {
  1692. $errors['far_future_expires_video'] = $value;
  1693. }
  1694. if (empty($this->compress_options['far_future_expires']['static'])) {
  1695. $errors['far_future_expires_static'] = $value;
  1696. }
  1697. if (empty($this->compress_options['minify']['with_jsmin']) &&
  1698. empty($this->compress_options['minify']['with_yui']) &&
  1699. empty($this->compress_options['minify']['with_packer']) &&
  1700. empty($this->compress_options['minify']['with_google'])) {
  1701. $errors['minify_js'] = $value;
  1702. }
  1703. return $errors;
  1704. }
  1705. /*
  1706. * Check Web Optimizer options
  1707. *
  1708. **/
  1709. function dashboard_options () {
  1710. $errors = $this->options_count();
  1711. /* count delta */
  1712. $deltas = array(28, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
  1713. $delta = $deltas[round($this->premium)];
  1714. foreach ($errors as $key => $value) {
  1715. $delta += $value;
  1716. }
  1717. /* overwrite delta */
  1718. if (!empty($this->compress_options['points'])) {
  1719. $delta = 100 - round($this->compress_options['points']);
  1720. }
  1721. $delta = $delta < 0 ? 0 : ($delta > 100 ? 100 : $delta);
  1722. /* set variables */
  1723. $page_variables = array(
  1724. 'errors' => $errors,
  1725. 'delta' => $delta,
  1726. 'premium' => $this->premium,
  1727. "skip_render" => $this->skip_render
  1728. );
  1729. /* Output data */
  1730. $this->view->render("dashboard_options", $page_variables);
  1731. }
  1732. /*
  1733. * Check server requirements for Web Optimizer
  1734. *
  1735. **/
  1736. function dashboard_system ($return = false) {
  1737. /* get available Apache modules */
  1738. $this->check_options();
  1739. /* get PHP extensions */
  1740. $extensions = $this->loaded_modules;
  1741. /* get GDlib info */
  1742. $gd = function_exists('gd_info') ? gd_info() : array();
  1743. /* set default paths */
  1744. $this->view->set_paths();
  1745. /* calculate directories */
  1746. $javascript_cachedir = empty($this->compress_options['javascript_cachedir']) ? $this->view->paths['full']['current_directory'] . 'cache/' : $this->compress_options['javascript_cachedir'];
  1747. $css_cachedir = empty($this->compress_options['css_cachedir']) ? $this->view->paths['full']['current_directory'] . 'cache/' : $this->compress_options['css_cachedir'];
  1748. $html_cachedir = empty($this->compress_options['html_cachedir']) ? $this->view->paths['full']['current_directory'] . 'cache/' : $this->compress_options['html_cachedir'];
  1749. $website_root = empty($this->compress_options['website_root']) ? $this->view->paths['absolute']['document_root'] : $this->compress_options['website_root'];
  1750. $document_root = empty($this->compress_options['document_root']) ? $this->view->paths['full']['document_root'] : $this->compress_options['document_root'];
  1751. /* check if .htaccess is avaiable */
  1752. $htaccess_available = count($this->apache_modules) ? 1 : 0;
  1753. /* check for multiple hosts */
  1754. $hosts = empty($this->compress_options['parallel']['allowed_list']) ? $this->default_hosts : explode(" ", $this->compress_options['parallel']['allowed_list']);
  1755. if (!empty($this->compress_options['parallel']['check'])) {
  1756. $hosts = $this->check_hosts($hosts);
  1757. }
  1758. /* try to get and increase memory limit */
  1759. $memory_limit = @ini_get('memory_limit');
  1760. /* 64M must enough for any operations with images */
  1761. if (round(str_replace("M", "000000", str_replace("K", "000", $memory_limit))) < 64000000) {
  1762. @ini_set('memory_limit', '64M');
  1763. $memory_limit = @ini_get('memory_limit');
  1764. }
  1765. $apache2 = $nginx = $iss = 0;
  1766. if (function_exists('apache_get_version')) {
  1767. $apache2 = strpos(apache_get_version(), "/1") ? 0 : 1;
  1768. }
  1769. if (!empty($_SERVER['SERVER_SOFTWARE'])) {
  1770. $nginx = strpos($_SERVER['SERVER_SOFTWARE'], 'nginx/') !== false;
  1771. }
  1772. /* define caching for WordPress */
  1773. if (!empty($this->compress_options['html_cache']['enabled']) && (strpos($this->basepath, "wp-content") !== false)) {
  1774. $content = $this->file_get_contents($this->compress_options['website_root'] . 'wp-config.php');
  1775. if(preg_match('/define\s*\(\s*[\'"]WP_CACHE[\'"]\s*,\s*true\s*\)\s*;/i', $content)) {
  1776. $wp_cache_enabled = true;
  1777. } else {
  1778. $wp_cache_enabled = false;
  1779. }
  1780. } else {
  1781. $wp_cache_enabled = true;
  1782. }
  1783. /* remember current number of files in cache */
  1784. $cache_files = count(@scandir($css_cachedir)) + count(@scandir($javascript_cachedir));
  1785. /* check CPU usage for the website */
  1786. $tmp_file = $this->compress_options['html_cachedir'] . 'index.tmp';
  1787. $time = time() + microtime();
  1788. $results = $this->view->download("http://" .
  1789. $this->compress_options['host'] .
  1790. str_replace($this->compress_options['document_root'], "/", $this->compress_options['website_root']) .
  1791. '?web_optimizer_disabled=1', $tmp_file, 60, $_SERVER['HTTP_HOST'], $this->compress_options['external_scripts']['user'], $this->compress_options['external_scripts']['pass']);
  1792. $standard_delay = time() + microtime() - $time;
  1793. $time = time() + microtime();
  1794. $this->view->download("http://" .
  1795. $this->compress_options['host'] .
  1796. str_replace($this->compress_options['document_root'], "/", $this->compress_options['website_root']) .
  1797. '?web_optimizer_debug=' . rand(), $tmp_file, 60, $_SERVER['HTTP_HOST'], $this->compress_options['external_scripts']['user'], $this->compress_options['external_scripts']['pass']);
  1798. $wss_delay = time() + microtime() - $time;
  1799. /* save default encoding */
  1800. if (empty($this->compress_options['charset']) && !empty($results[2])) {
  1801. $headers = strtolower($results[2]);
  1802. if (strpos($headers, 'content-type') && ($charset = trim(preg_replace("!;.*!is", "", preg_replace("@.*content-type:[^;]*;*(\s*charset=(.*?))?\r?\n.*@is", "$2", $headers))))) {
  1803. $this->save_option("['charset']", $charset);
  1804. $this->compress_options['charset'] = $charset;
  1805. }
  1806. }
  1807. /* check activity for the website */
  1808. $spot = strpos($this->file_get_contents($tmp_file), '<!--WSS-->') || !@filesize($tmp_file);
  1809. @unlink($tmp_file);
  1810. /* get new number of files in cache */
  1811. $cache_files_new = count(@scandir($css_cachedir)) + count(@scandir($javascript_cachedir));
  1812. $errors = array(
  1813. 'javascript_writable' => @is_writable($javascript_cachedir),
  1814. 'css_writable' => @is_writable($css_cachedir),
  1815. 'html_writable' => @is_writable($html_cachedir),
  1816. 'config_writable' => @is_writable($this->basepath . $this->options_file),
  1817. 'memory_limit' => round($memory_limit) > 16,
  1818. 'not_active' => $spot || !$this->compress_options['footer']['spot'] || $this->compress_options['footer']['ab']
  1819. );
  1820. $warnings = array(
  1821. 'index_writable' => @is_writable($website_root . 'index.php') ||
  1822. $this->internal,
  1823. 'curl_possibility' => in_array('curl', $extensions) &&
  1824. function_exists('curl_init'),
  1825. 'gzip_possibility' => in_array('zlib', $extensions) &&
  1826. function_exists('gzencode') &&
  1827. function_exists('gzcompress') &&
  1828. function_exists('gzdeflate'),
  1829. 'gd_possibility' => in_array('gd', $extensions) &&
  1830. function_exists('imagecreatetruecolor'),
  1831. 'gd_full_support' => !(in_array('gd', $extensions) &&
  1832. function_exists('imagecreatetruecolor')) ||
  1833. (!empty($gd['GIF Read Support']) &&
  1834. !empty($gd['GIF Create Support']) &&
  1835. (!empty($gd['JPEG Support']) || !empty($gd['JPG Support'])) &&
  1836. !empty($gd['PNG Support']) &&
  1837. !empty($gd['WBMP Support'])),
  1838. 'memory_limit' => round($memory_limit) > 32 || round($memory_limit) < 15,
  1839. 'wordpress_cache_enabled' => $wp_cache_enabled,
  1840. 'too_many_files' => $cache_files >= $cache_files_new
  1841. );
  1842. $infos = array(
  1843. 'htaccess_writable' => !$htaccess_available ||
  1844. @is_writable($website_root) ||
  1845. @is_writable($website_root . '.htaccess'),
  1846. 'webconfig_writable' => !$this->iis || @is_file($this->compress_options['website_root']) . 'web.config',
  1847. 'mod_deflate' => in_array('mod_deflate', $this->apache_modules) ||
  1848. $nginx || $this->iis ||
  1849. in_array('mod_gzip', $this->apache_modules),
  1850. 'mod_gzip' => in_array('mod_gzip', $this->apache_modules) ||
  1851. $apache2 || $nginx || $this->iis ||
  1852. in_array('mod_deflate', $this->apache_modules),
  1853. 'mod_headers' => in_array('mod_headers', $this->apache_modules) || $nginx || $this->iis,
  1854. 'mod_expires' => in_array('mod_expires', $this->apache_modules) || $nginx || $this->iis,
  1855. 'mod_mime' => in_array('mod_mime', $this->apache_modules) || $nginx || $this->iis,
  1856. 'mod_setenvif' => in_array('mod_setenvif', $this->apache_modules) || $nginx || $this->iis,
  1857. 'mod_rewrite' => in_array('mod_rewrite', $this->apache_modules) || $nginx || $this->iis,
  1858. 'mod_symlinks' => in_array('mod_symlinks', $this->apache_modules) || $nginx || $this->iis,
  1859. 'yui_possibility' => empty($this->restrictions['wss_minify_js2']),
  1860. 'google_possibility' => empty($this->restrictions['wss_minify_js4']),
  1861. 'hosts_possibility' => count($hosts) > 0 && !empty($hosts[0]),
  1862. 'protected_mode' => (isset($_SERVER['PHP_AUTH_USER']) &&
  1863. $this->compress_options['htaccess']['access']) ||
  1864. $this->internal,
  1865. 'cms' => $this->system_info($website_root),
  1866. 'heavy_optimization' => !$this->compress_options['active'] ||
  1867. ($this->compress_options['performance']['mtime'] &&
  1868. !$this->compress_options['minify']['javascript_body'] &&
  1869. !$this->compress_options['minify']['css_body'] &&
  1870. !$this->compress_options['minify']['with_yui'] &&
  1871. !$this->compress_options['minify']['with_google'] &&
  1872. !$this->compress_options['minify']['html_one_string']),
  1873. 'heavy_optimization2' => !$this->compress_options['active'] ||
  1874. !$this->compress_options['performance']['mtime'] ||
  1875. $this->compress_options['minify']['javascript_body'] ||
  1876. $this->compress_options['minify']['css_body'] ||
  1877. $this->compress_options['minify']['with_yui'] ||
  1878. $this->compress_options['minify']['with_google'] ||
  1879. $this->compress_options['minify']['html_one_string'] ||
  1880. (!$this->compress_options['unobtrusive']['all'] &&
  1881. !$this->compress_options['unobtrusive']['informers'] &&
  1882. !$this->compress_options['unobtrusive']['ads'] &&
  1883. !$this->compress_options['unobtrusive']['counters'] &&
  1884. !$this->compress_options['unobtrusive']['iframes'] &&
  1885. !$this->compress_options['css_sprites']['enabled'] &&
  1886. !$this->compress_options['css_sprites']['html_sprites']),
  1887. 'large_delay' => $standard_delay < 1,
  1888. 'large_wss_delay' => $wss_delay / $standard_delay < 2 || $wss_delay < 0.3,
  1889. 'apc_enabled' => !@function_exists('apc_store') || strpos(@ini_get('apc.filters'), 'config') !== false
  1890. );
  1891. $e = $w = $i = 0;
  1892. /* count acturl troubles / warnings */
  1893. foreach ($errors as $key => $value) {
  1894. if (empty($value)) {
  1895. $e++;
  1896. }
  1897. }
  1898. foreach ($warnings as $key => $value) {
  1899. if (empty($value)) {
  1900. $w++;
  1901. }
  1902. }
  1903. foreach ($infos as $key => $value) {
  1904. if (empty($value)) {
  1905. $i++;
  1906. }
  1907. }
  1908. /* set variables */
  1909. $page_variables = array(
  1910. 'errors' => $errors,
  1911. 'warnings' => $warnings,
  1912. 'infos' => $infos,
  1913. 'e' => $e,
  1914. 'w' => $w,
  1915. 'i' => $i,
  1916. "skip_render" => $this->skip_render
  1917. );
  1918. if (!$return) {
  1919. /* Output data */
  1920. $this->view->render("dashboard_system", $page_variables);
  1921. } else {
  1922. return $page_variables;
  1923. }
  1924. }
  1925. /**
  1926. * Outputs page with general info about system / common actions
  1927. *
  1928. **/
  1929. function install_system ($success = 0) {
  1930. $this->cms_version = $this->system_info($this->view->paths['absolute']['document_root']);
  1931. $submit = empty($this->input['wss_Submit']) ? '' : $this->input['wss_Submit'];
  1932. $this->error = array();
  1933. if (!empty($submit)) {
  1934. $this->compress_options['host'] = empty($this->input['wss_host']) ?
  1935. $this->compress_options['host'] : $this->input['wss_host'];
  1936. $this->compress_options['charset'] = empty($this->input['wss_encoding']) ?
  1937. $this->compress_options['charset'] : $this->input['wss_encoding'];
  1938. $this->compress_options['currency'] = empty($this->input['wss_currency']) ?
  1939. $this->compress_options['currency'] : $this->input['wss_currency'];
  1940. $this->compress_options['website_root'] = empty($this->input['wss_website_root']) ?
  1941. $this->compress_options['website_root'] : $this->input['wss_website_root'];
  1942. $this->compress_options['document_root'] = empty($this->input['wss_document_root']) ?
  1943. $this->compress_options['document_root'] : $this->input['wss_document_root'];
  1944. $this->compress_options['css_cachedir'] = empty($this->input['wss_css_cachedir']) ?
  1945. $this->compress_options['css_cachedir'] : $this->input['wss_css_cachedir'];
  1946. $this->compress_options['javascript_cachedir'] = empty($this->input['wss_javascript_cachedir']) ?
  1947. $this->compress_options['javascript_cachedir'] : $this->input['wss_javascript_cachedir'];
  1948. $this->compress_options['html_cachedir'] = empty($this->input['wss_html_cachedir']) ?
  1949. $this->compress_options['html_cachedir'] : $this->input['wss_html_cachedir'];
  1950. $this->compress_options['htaccess']['access'] = empty($this->input['wss_htaccess_access']) ?
  1951. 0 : 1;
  1952. $this->compress_options['username'] = empty($this->input['wss_username']) ?
  1953. '' : $this->input['wss_username'];
  1954. $this->compress_options['external_scripts']['user'] = empty($this->input['wss_external_scripts_user']) ?
  1955. '' : $this->input['wss_external_scripts_user'];
  1956. $this->compress_options['external_scripts']['pass'] = empty($this->input['wss_external_scripts_pass']) ?
  1957. '' : $this->input['wss_external_scripts_pass'];
  1958. $this->compress_options['restricted'] = trim(empty($this->input['wss_restricted']) ?
  1959. '' : str_replace(array("\r\n", "\n"), array(' ', ' '), $this->input['wss_restricted']));
  1960. if (!@is_dir($this->compress_options['website_root'])) {
  1961. $this->error[1] = 1;
  1962. }
  1963. if (!@is_dir($this->compress_options['document_root'])) {
  1964. $this->error[2] = 1;
  1965. }
  1966. @mkdir($this->compress_options['css_cachedir']);
  1967. @chmod($this->compress_options['css_cachedir'], octdec("0755"));
  1968. if (!@is_writable($this->compress_options['css_cachedir'])) {
  1969. $this->error[3] = 1;
  1970. }
  1971. @mkdir($this->compress_options['javascript_cachedir']);
  1972. @chmod($this->compress_options['javascript_cachedir'], octdec("0755"));
  1973. if (!@is_writable($this->compress_options['javascript_cachedir'])) {
  1974. $this->error[4] = 1;
  1975. }
  1976. @mkdir($this->compress_options['html_cachedir']);
  1977. @chmod($this->compress_options['html_cachedir'], octdec("0755"));
  1978. if (!@is_writable($this->compress_options['html_cachedir'])) {
  1979. $this->error[5] = 1;
  1980. }
  1981. if (!empty($this->compress_options['htaccess']['access']) &&
  1982. empty($this->compress_options['username'])) {
  1983. $this->error[6] = 1;
  1984. } else {
  1985. $this->protect_installation();
  1986. }
  1987. if ((!empty($this->compress_options['external_scripts']['user']) &&
  1988. empty($this->compress_options['external_scripts']['pass'])) ||
  1989. (!empty($this->compress_options['external_scripts']['pass']) &&
  1990. empty($this->compress_options['external_scripts']['user']))) {
  1991. $this->error[7] = 1;
  1992. }
  1993. if (!count($this->error)) {
  1994. /* copy some files */
  1995. $image = $this->compress_options['footer']['image'];
  1996. if (!empty($image)) {
  1997. @copy($this->basepath . 'images/' . $image,
  1998. $this->compress_options['css_cachedir'] . $image);
  1999. }
  2000. @copy($this->basepath . 'libs/js/index.php',
  2001. $this->compress_options['javascript_cachedir'] . 'index.php');
  2002. @copy($this->basepath . 'libs/js/yass.loader.js',
  2003. $this->compress_options['javascript_cachedir'] . 'yass.loader.js');
  2004. @copy($this->basepath . 'libs/php/wo.static.php',
  2005. $this->compress_options['css_cachedir'] . 'wo.static.php');
  2006. @chmod($this->compress_options['css_cachedir'] . 'wo.static.php', octdec("0755"));
  2007. @copy($this->basepath . 'libs/php/wo.gzip.php',
  2008. $this->compress_options['css_cachedir'] . 'wo.gzip.php');
  2009. @chmod($this->compress_options['css_cachedir'] . 'wo.gzip.php', octdec("0755"));
  2010. @copy($this->basepath . 'libs/php/wo.merge.php',
  2011. $this->compress_options['css_cachedir'] . 'wo.merge.php');
  2012. @chmod($this->compress_options['css_cachedir'] . 'wo.merge.php', octdec("0755"));
  2013. @copy($this->basepath . 'libs/php/0.gif',
  2014. $this->compress_options['css_cachedir'] . '0.gif');
  2015. $this->save_option("['host']", $this->compress_options['host']);
  2016. $this->save_option("['charset']", $this->compress_options['charset']);
  2017. $this->save_option("['currency']", $this->compress_options['currency']);
  2018. $this->save_option("['website_root']", $this->compress_options['website_root']);
  2019. $this->save_option("['document_root']", $this->compress_options['document_root']);
  2020. $this->save_option("['css_cachedir']", $this->compress_options['css_cachedir']);
  2021. $this->save_option("['javascript_cachedir']", $this->compress_options['javascript_cachedir']);
  2022. $this->save_option("['html_cachedir']", $this->compress_options['html_cachedir']);
  2023. $this->save_option("['htaccess']['access']", $this->compress_options['htaccess']['access']);
  2024. $this->save_option("['username']", $this->compress_options['username']);
  2025. $this->save_option("['external_scripts']['user']", $this->compress_options['external_scripts']['user']);
  2026. $this->save_option("['external_scripts']['pass']", $this->compress_options['external_scripts']['pass']);
  2027. $this->save_option("['restricted']", $this->compress_options['restricted']);
  2028. $success = 3;
  2029. } else {
  2030. $success = 4;
  2031. }
  2032. }
  2033. $files = array(
  2034. 'CSS' => array(),
  2035. 'JS' => array(),
  2036. 'HTML' => array(),
  2037. 'SPRITES' => array(),
  2038. 'IMAGES' => array(),
  2039. 'RESOURCES' => array(),
  2040. 'SCRIPTS' => array());
  2041. if (!empty($this->compress_options['css_cachedir'])) {
  2042. @chdir($this->compress_options['css_cachedir']);
  2043. foreach ($this->cache_types['css'] as $mask) {
  2044. $files['CSS'][$mask] = $this->dashboard_cache_size($mask, 1);
  2045. }
  2046. foreach ($this->cache_types['res'] as $mask) {
  2047. $files['RESOURCES'][$mask] = $this->dashboard_cache_size($mask, 1);
  2048. }
  2049. foreach ($this->cache_types['imgs'] as $mask) {
  2050. $files['IMAGES'][$mask] = $this->dashboard_cache_size($mask, 1);
  2051. }
  2052. foreach ($this->cache_types['sprites'] as $mask) {
  2053. $files['SPRITES'][$mask] = $this->dashboard_cache_size($mask, 1);
  2054. }
  2055. foreach ($this->cache_types['scripts'] as $mask) {
  2056. $files['SCRIPTS'][$mask] = $this->dashboard_cache_size($mask, 1);
  2057. }
  2058. }
  2059. if (!empty($this->compress_options['javascript_cachedir'])) {
  2060. @chdir($this->compress_options['javascript_cachedir']);
  2061. foreach ($this->cache_types['js'] as $mask) {
  2062. $files['JS'][$mask] = $this->dashboard_cache_size($mask, 1);
  2063. }
  2064. if ($this->compress_options['javascript_cachedir'] !=
  2065. $this->compress_options['css_cachedir']) {
  2066. foreach ($this->cache_types['scripts'] as $mask) {
  2067. if (is_array($files['SCRIPTS'][$mask])) {
  2068. $files['SCRIPTS'][$mask] = array_merge($files['SCRIPTS'][$mask], $this->dashboard_cache_size($mask, 1));
  2069. } else {
  2070. $files['SCRIPTS'][$mask] = $this->dashboard_cache_size($mask, 1);
  2071. }
  2072. }
  2073. }
  2074. }
  2075. if (!empty($this->compress_options['html_cachedir'])) {
  2076. @chdir($this->compress_options['html_cachedir']);
  2077. foreach ($this->cache_types['html'] as $mask) {
  2078. $files['HTML'][$mask] = $this->cache_engine->get_cache_size($mask, 1);
  2079. }
  2080. foreach ($this->cache_types['sprites'] as $mask) {
  2081. if (is_array($files['SPRITES'][$mask])) {
  2082. $files['SPRITES'][$mask] = array_merge($files['SPRITES'][$mask], $this->dashboard_cache_size($mask, 1));
  2083. } else {
  2084. $files['SPRITES'][$mask] = $this->dashboard_cache_size($mask, 1);
  2085. }
  2086. }
  2087. if ($this->compress_options['html_cachedir'] !=
  2088. $this->compress_options['css_cachedir'] &&
  2089. $this->compress_options['html_cachedir'] !=
  2090. $this->compress_options['javascript_cachedir']) {
  2091. foreach ($this->cache_types['scripts'] as $mask) {
  2092. if (is_array($files['SCRIPTS'][$mask])) {
  2093. $files['SCRIPTS'][$mask] = array_merge($files['SCRIPTS'][$mask], $this->dashboard_cache_size($mask, 1));
  2094. } else {
  2095. $files['SCRIPTS'][$mask] = $this->dashboard_cache_size($mask, 1);
  2096. }
  2097. }
  2098. }
  2099. }
  2100. if (@function_exists('apc_cache_info')) {
  2101. $cache = @apc_cache_info('user');
  2102. if (!empty($cache['num_entries'])) {
  2103. $files['APC'] = array('.php' => array($cache['mem_size'], $cache['num_entries']));
  2104. }
  2105. } elseif ($this->compress_options['performance']['cache_engine']) {
  2106. $files[$this->compress_options['performance']['cache_engine'] == 1 ? 'Memcached' : 'XCache'] =
  2107. array('.php' => array($this->cache_engine->get_cache_size('.html'), count($this->cache_engine->get_entry('webo_files_list'))));
  2108. }
  2109. $total = $size = 0;
  2110. foreach ($files as $group) {
  2111. foreach ($group as $file) {
  2112. if (count($file)) {
  2113. $size += $file[0];
  2114. $total += $file[1];
  2115. }
  2116. }
  2117. }
  2118. /* get basic errors / warnings */
  2119. $page_variables = $this->dashboard_system(1);
  2120. /* get stable versions */
  2121. $this->view->download('http://web-optimizator.googlecode.com/svn/versions/versions', $this->basepath . 'versions');
  2122. /* sey all other variables */
  2123. $page_variables['version'] = $this->version;
  2124. $page_variables['version_new'] = $this->version_new;
  2125. $page_variables['language'] = $this->language;
  2126. $page_variables['premium'] = $this->premium;
  2127. $page_variables['password'] = $this->compress_options['password'];
  2128. $page_variables['active'] = $this->compress_options['active'];
  2129. $page_variables['website'] = $_SERVER['HTTP_HOST'];
  2130. $page_variables['cache_folder'] = str_replace($this->compress_options['document_root'],
  2131. "/", $this->compress_options['javascript_cachedir']);
  2132. $page_variables['host'] = $this->compress_options['host'];
  2133. $page_variables['charset'] = $this->compress_options['charset'];
  2134. $page_variables['currency'] = $this->compress_options['currency'];
  2135. $page_variables['website_root'] = $this->compress_options['website_root'];
  2136. $page_variables['document_root'] = $this->compress_options['document_root'];
  2137. $page_variables['css_cachedir'] = $this->compress_options['css_cachedir'];
  2138. $page_variables['javascript_cachedir'] = $this->compress_options['javascript_cachedir'];
  2139. $page_variables['html_cachedir'] = $this->compress_options['html_cachedir'];
  2140. $page_variables['current_directory'] = $this->basepath;
  2141. $page_variables['htpasswd'] = $this->compress_options['htaccess']['access'];
  2142. $page_variables['username'] = $this->compress_options['username'];
  2143. $page_variables['external_scripts_user'] = $this->compress_options['external_scripts']['user'];
  2144. $page_variables['external_scripts_pass'] = $this->compress_options['external_scripts']['pass'];
  2145. $page_variables['restricted'] = $this->compress_options['restricted'];
  2146. $page_variables['showbeta'] = $this->compress_options['showbeta'] || strpos($this->version, 'b');
  2147. $page_variables['files_to_change'] = $this->system_files($this->cms_version);
  2148. $page_variables['cms_version'] = $this->cms_version;
  2149. $page_variables['success'] = $success;
  2150. $page_variables['error'] = $this->error;
  2151. $page_variables['version'] = $this->version;
  2152. $page_variables['version_new'] = $this->version_new;
  2153. $page_variables['version_beta'] = $this->version_beta;
  2154. $page_variables['versions'] = explode("\n", $this->file_get_contents($this->basepath . 'versions'));
  2155. $page_variables['skip_render'] = $this->skip_render;
  2156. $page_variables['internal'] = $this->internal;
  2157. $page_variables['total'] = $total;
  2158. $page_variables['size'] = $size;
  2159. $page_variables['files'] = $files;
  2160. $page_variables['custom'] = !@function_exists('curl_init') || @is_file($this->basepath . 'custom');
  2161. ob_start();
  2162. phpinfo();
  2163. $c = ob_get_contents();
  2164. ob_end_clean();
  2165. $page_variables['phpinfo'] = base64_encode($c);
  2166. $this->view->paths['full']['view'] = $this->basepath . 'view/';
  2167. /* Output data */
  2168. $this->view->render("install_system", $page_variables);
  2169. }
  2170. /**
  2171. * Write installation progress to JavaScript file
  2172. *
  2173. **/
  2174. function write_progress ($progress) {
  2175. $file = (empty($this->compress_options['javascript_cachedir']) ?
  2176. ($this->view->paths['full']['current_directory'] . 'cache/') :
  2177. $this->compress_options['javascript_cachedir']) .
  2178. 'progress.php';
  2179. return $this->write_file($file, $progress, 1);
  2180. }
  2181. /**
  2182. * Refresh results about acceleration
  2183. *
  2184. **/
  2185. function check_acceleration () {
  2186. $before = @filesize($this->basepath . $this->index_before);
  2187. $before = strpos($this->file_get_contents($this->basepath . $this->index_before), 'responseCode": 200') === false ? 0 : $before;
  2188. $a = $this->file_get_contents($this->basepath . $this->index_after);
  2189. $a = strpos($a, 'responseCode": 200') === false ? '' : $a;
  2190. $after = strlen($a);
  2191. if ($this->premium > 1 && !empty($this->compress_options['website_root'])) {
  2192. /* re-check if there was 503 error */
  2193. if (!empty($this->compress_options['active']) &&
  2194. strpos($a, 'code": 503')) {
  2195. $this->view->download($this->webo_grade, $this->basepath . $this->index_after, 1);
  2196. } elseif (!empty($this->compress_options['active']) &&
  2197. $before && (empty($after) || $after < 250)) {
  2198. /* Request to re-check should be done on options save */
  2199. $this->view->download($this->webo_grade, $this->basepath . $this->index_after, 1);
  2200. } elseif (empty($before) || $before < 250) {
  2201. $this->view->download($this->webo_grade, $this->basepath . $this->index_before, 1);
  2202. }
  2203. }
  2204. }
  2205. /**
  2206. * The login page -- to define password
  2207. *
  2208. **/
  2209. function install_enter_password () {
  2210. $this->check_acceleration();
  2211. $page_variables = array(
  2212. "title" => _WEBO_LOGIN_TITLE,
  2213. "page" => 'install_enter_password',
  2214. "version" => $this->version,
  2215. "premium" => true,
  2216. "language" => $this->language,
  2217. "skip_render" => $this->skip_render
  2218. );
  2219. $this->view->render("admin_container", $page_variables);
  2220. }
  2221. /**
  2222. * Page with version comparison
  2223. *
  2224. **/
  2225. function install_promo() {
  2226. $page_variables = array(
  2227. "title" => _WEBO_SPLASH2_COMPARISON,
  2228. "version" => $this->version,
  2229. "promo" => true,
  2230. "premium" => true,
  2231. "password" => $this->compress_options['password'],
  2232. "language" => $this->language,
  2233. "skip_render" => $this->skip_render,
  2234. "ready" => @is_file($this->basepath . 'ready'),
  2235. "email" => $this->compress_options['email']
  2236. );
  2237. $this->view->render("install_promo", $page_variables);
  2238. }
  2239. /**
  2240. * Home page (dashboard), control panel
  2241. *
  2242. **/
  2243. function install_dashboard() {
  2244. @unlink($this->compress_options['javascript_cachedir'] . 'progress.php');
  2245. $page_variables = array(
  2246. "title" => _WEBO_SPLASH2_CONTROLPANEL,
  2247. "page" => 'install_dashboard',
  2248. "version" => $this->version,
  2249. "version_new" => $this->version_new,
  2250. "language" => $this->language,
  2251. "premium" => $this->premium,
  2252. "password" => $this->compress_options['password'],
  2253. "active" => $this->compress_options['active'],
  2254. "website" => $_SERVER['HTTP_HOST'] .
  2255. str_replace($this->compress_options['document_root'],
  2256. "/", $this->compress_options['website_root']),
  2257. "cache_folder" => str_replace($this->compress_options['document_root'],
  2258. "/", $this->compress_options['javascript_cachedir']),
  2259. "cookie" => empty($_COOKIE['wss_blocks']) ? '' : $_COOKIE['wss_blocks'],
  2260. "welcome" => empty($_COOKIE['wss_welcome']) ? '' : $_COOKIE['wss_welcome'],
  2261. "skip_render" => $this->skip_render,
  2262. "license" => $this->compress_options['license'],
  2263. "fee" => $this->compress_options['fee'],
  2264. "custom" => !@function_exists('curl_init') || @is_file($this->basepath . 'custom'),
  2265. "ready" => @is_file($this->basepath . 'ready'),
  2266. "limited" => @is_file($this->basepath . 'limited')
  2267. );
  2268. $this->view->render("admin_container", $page_variables);
  2269. }
  2270. /**
  2271. * The very first page -- to define e-mail and password
  2272. *
  2273. **/
  2274. function install_set_password() {
  2275. $username = empty($this->input['wss_username']) ? '' : $this->input['wss_username'];
  2276. $password = empty($this->input['wss_password']) ? '' : $this->input['wss_password'];
  2277. $confirm = empty($this->input['wss_confirm']) ? '' : $this->input['wss_confirm'];
  2278. $license = empty($this->input['wss_license']) ? '' : $this->input['wss_license'];
  2279. $email = empty($this->input['wss_email']) ? '' : $this->input['wss_email'];
  2280. $confirmagreement = empty($this->input['wss_confirmagreement']) ? '' : $this->input['wss_confirmagreement'];
  2281. $submit = empty($this->input['wss_Submit']) ? '' : $this->input['wss_Submit'];
  2282. /* try to get preliminary optimization grade for the website */
  2283. $this->check_acceleration();
  2284. if (!empty($this->compress_options['password'])) {
  2285. $this->install_enter_password();
  2286. } else {
  2287. $this->error = array();
  2288. if (!empty($submit)) {
  2289. if (empty($password)) {
  2290. $this->error[1] = 1;
  2291. }
  2292. if (empty($password) || empty($confirm) || $password != $confirm) {
  2293. $this->error[2] = 1;
  2294. }
  2295. if (empty($email) ||
  2296. !preg_match("/.+@.+\..+/", $email)) {
  2297. $this->error[3] = 1;
  2298. }
  2299. if (empty($confirmagreement)) {
  2300. $this->error[4] = 1;
  2301. }
  2302. }
  2303. if (!count($this->error) && !empty($submit)) {
  2304. $this->install_install(1);
  2305. }
  2306. if (count($this->error) || empty($submit)) {
  2307. $page_variables = array(
  2308. "title" => _WEBO_NEW_ENTER,
  2309. "page" => 'install_set_password',
  2310. "version" => $this->version,
  2311. "error" => $this->error,
  2312. "username" => $username,
  2313. "password" => $password,
  2314. "confirm" => $confirm,
  2315. "license" => $license,
  2316. "email" => $email,
  2317. "confirmagreement" => $confirmagreement,
  2318. "submit" => $submit,
  2319. "premium" => true,
  2320. "javascript_relative_cachedir" => str_replace($this->compress_options['document_root'],
  2321. "/", $this->compress_options['javascript_cachedir']),
  2322. "language" => $this->language,
  2323. "skip_render" => $this->skip_render
  2324. );
  2325. /* Show the install page */
  2326. $this->view->render("admin_container", $page_variables);
  2327. } else {
  2328. $this->save_option("['htpasswd']",
  2329. ":" . $this->encrypt_password($password));
  2330. $this->compress_options['password'] = md5($password);
  2331. $this->save_option("['password']", $this->compress_options['password']);
  2332. $this->save_option("['email']", htmlspecialchars($email));
  2333. $this->save_option("['username']", htmlspecialchars($username));
  2334. $this->save_option("['name']", htmlspecialchars($username));
  2335. $this->save_option("['license']", htmlspecialchars($license));
  2336. $this->premium = $this->view->validate_license($license);
  2337. $this->install_favicon();
  2338. $this->install_dashboard();
  2339. }
  2340. }
  2341. }
  2342. /**
  2343. * Detect and put favicon.ico to the website root, get SaaS license key for the website
  2344. *
  2345. **/
  2346. function install_favicon () {
  2347. $file = $this->compress_options['document_root'] . 'favicon.ico';
  2348. if (@!is_file($file)) {
  2349. /* download website index */
  2350. $this->view->download('http://' . $_SERVER['HTTP_HOST'] .
  2351. str_replace($this->compress_options['document_root'], '/',
  2352. $this->compress_options['website_root']),
  2353. $this->basepath . $this->index_check, 2);
  2354. /* calculate favicon */
  2355. $favicon = preg_replace("@.*(<link.*rel=['\"\s](shortcut\s)?icon[^>]*>).*@is", "$1",
  2356. $this->file_get_contents($this->basepath . $this->index_check));
  2357. if (!empty($favicon) && strlen($favicon) < 1000) {
  2358. $favicon = preg_replace("@.*href\s*=[\s'\"](.*?)[\s'\"].*@is", "$1",
  2359. $favicon);
  2360. /* clear external favicon from current website host */
  2361. $favicon = preg_replace("@https?://(www.)" .
  2362. preg_replace("@www.@i", "", $_SERVER['HTTP_HOST']) . "@", "",
  2363. $favicon);
  2364. }
  2365. $favicon = empty($favicon) ? $this->svn . 'favicon.ico' : $favicon;
  2366. /* absolute paths */
  2367. if ($favicon{0} == '/') {
  2368. /* external resource */
  2369. if ($favicon{1} == '/') {
  2370. $this->view->download('http:' . $favicon, $file, 2);
  2371. } else {
  2372. @copy($this->compress_options['document_root'] . $favicon, $file);
  2373. }
  2374. /* relative paths */
  2375. } else {
  2376. /* external file */
  2377. if ((substr($favicon, 0, 5) == 'http:' ||
  2378. substr($favicon, 0, 6) == 'https:')) {
  2379. $this->view->download($favicon, $file, 2);
  2380. } else {
  2381. @copy($this->compress_options['website_root'] . $favicon, $file);
  2382. }
  2383. }
  2384. }
  2385. /* get SaaS license - by website host */
  2386. if (empty($this->compress_options['license'])) {
  2387. $license_file = $this->compress_options['document_root'] . 'wss.license';
  2388. $this->view->download('http://webo.name/license/trial/?name=' . $this->compress_options['name'] .
  2389. '&email=' . $this->compress_options['email'], $license_file, 2);
  2390. $this->save_option("['license']", preg_replace("!.*'([A-Z0-9\-]+)'.*!is", "$1", @file_get_contents($license_file)));
  2391. @unlink($license_file);
  2392. }
  2393. }
  2394. /**
  2395. * Sends welcome letter to user
  2396. *
  2397. **/
  2398. function send_welcome_letter ($compress_options) {
  2399. $headers = 'From: ' . $compress_options['email'] . "\r\n" . 'Reply-To: support@webo.name' . "\r\n";
  2400. $headers .= 'Content-Type: text/plain; charset=utf-8';
  2401. @mail($compress_options['email'],
  2402. "=?latin-1?B?" . base64_encode('WEBO Site SpeedUp welcome letter for ' . $compress_options['host']) . "?=",
  2403. str_replace('###FOLDER###', str_replace($compress_options['document_root'], "/", $this->basepath), str_replace('###WEBSITE###', $compress_options['host'], _WEBO_WELCOME_LETTER)),
  2404. $headers);
  2405. }
  2406. /**
  2407. * Clean up cache
  2408. *
  2409. **/
  2410. function install_clean_cache ($redirect = true, $ajax = false) {
  2411. /* if all directories haven't been set yet -- just success */
  2412. $success = false || (empty($this->compress_options['css_cachedir']) &&
  2413. empty($this->compress_options['javascript_cachedir']) &&
  2414. empty($this->compress_options['html_cachedir']));
  2415. $deleted_css = true;
  2416. $deleted_js = true;
  2417. $deleted_html = true;
  2418. $deleted_sql = true;
  2419. $restricted = array('.', '..', 'last.chain', 'yass.loader.js', 'progress.php', '.svn', 'index.php', 'web.optimizer.stamp.png', 'wo.static.php', 'wo.gzip.php', 'wo.merge.php', 'wo', '0.gif', 'webo-site-speedup.php', 'webo-site-speedup88.png', 'webo-site-speedup125.png', 'webo-site-speedup161.png', 'webo-site-speedup250.png', 'webo-site-speedup.css', 'webo-site-speedup.rocket.png', 'webo-site-speedup.back.jpg', 'webonautes.png', 'webonaut1-88.png', 'webonaut1-125.png', 'webonaut1-161.png', 'webonaut1-250.png', 'webonaut2-88.png', 'webonaut2-125.png', 'webonaut2-161.png', 'webonaut2-250.png', 'webonaut3-88.png', 'webonaut3-125.png', 'webonaut3-161.png', 'webonaut3-250.png', 'webonaut4-88.png', 'webonaut4-125.png', 'webonaut4-161.png', 'webonaut4-250.png', 'webonaut5-88.png', 'webonaut5-125.png', 'webonaut5-161.png', 'webonaut5-250.png');
  2420. /* css cache */
  2421. if ($dir = @opendir($this->compress_options['css_cachedir'])) {
  2422. while (($file = @readdir($dir)) !== false) {
  2423. if (!in_array($file, $restricted) &&
  2424. @is_file($this->compress_options['css_cachedir'] . $file)) {
  2425. if (!@unlink($this->compress_options['css_cachedir'] . $file)) {
  2426. $deleted_css = false;
  2427. }
  2428. }
  2429. }
  2430. $success = true;
  2431. }
  2432. /* javascript cache */
  2433. if ($dir = @opendir($this->compress_options['javascript_cachedir'])) {
  2434. while (($file = @readdir($dir)) !== false) {
  2435. if (!in_array($file, $restricted) &&
  2436. @is_file($this->compress_options['javascript_cachedir'] . $file)) {
  2437. if (!@unlink($this->compress_options['javascript_cachedir'] . $file)) {
  2438. $deleted_js = false;
  2439. }
  2440. }
  2441. }
  2442. $success = true;
  2443. }
  2444. /* html cache */
  2445. /* if cache stored on filesystem we need to preserve several files */
  2446. if (($dir = @opendir($this->compress_options['html_cachedir'])) && (@$this->compress_options['performance']['cache_engine'] == 0)) {
  2447. while (($file = @readdir($dir)) !== false) {
  2448. if (!in_array($file, $restricted)) {
  2449. if(@is_file($this->compress_options['html_cachedir'] . $file)) {
  2450. if (!@unlink($this->compress_options['html_cachedir'] . $file)) {
  2451. $deleted_html = false;
  2452. }
  2453. }
  2454. }
  2455. }
  2456. $success = true;
  2457. }
  2458. /* clean-up Joomla! cache */
  2459. if (str_replace(realpath(dirname(__FILE__) . '/../../../') . '/', '', realpath(dirname(__FILE__) . '/../../')) == 'com_webositespeedup') {
  2460. $dir = $this->compress_options['html_cachedir'] . '../page/';
  2461. if ($d = opendir($dir)) {
  2462. while (($file = @readdir($d)) !== false) {
  2463. @unlink($dir . $file);
  2464. }
  2465. }
  2466. $dir = $this->compress_options['html_cachedir'] . '../content/';
  2467. if ($d = opendir($dir)) {
  2468. while (($file = @readdir($d)) !== false) {
  2469. @unlink($dir . $file);
  2470. }
  2471. }
  2472. }
  2473. $this->__rmdir($this->compress_options['html_cachedir'] . 'img');
  2474. $this->cache_engine->delete_entries('*');
  2475. if (!$this->cache_engine->clear_sql_cache()) {
  2476. $deleted_sql = false;
  2477. }
  2478. if ($auth = $this->compress_options['parallel']['ftp']) {
  2479. /* Rack Space Cloud */
  2480. if ($last = strpos($auth, '@RSC')) {
  2481. $first = strpos($auth, ':');
  2482. $user = substr($auth, 0, $first);
  2483. $key = substr($auth, $first + 1, $last - $first - 1);
  2484. /* perform authorization */
  2485. $headers = $this->view->upload('https://auth.api.rackspacecloud.com/v1.0',
  2486. '', $this->options['html_cachedir'],
  2487. array('X-Auth-User: ' . $user, 'X-Auth-Key: ' . $key));
  2488. if (strpos($headers, 'Error: ') === false && strpos($headers, 'HTTP/1.1 401') === false) {
  2489. $token = preg_replace("@.*X-Auth-Token: (.*?)\r?\n.*@is", "$1", $headers);
  2490. /* remove wo container */
  2491. $headers = $this->view->upload(preg_replace("@.*X-CDN-Management-Url: (.*?)\r?\n.*@is", "$1", $headers) . '/wo',
  2492. '', $this->options['html_cachedir'],
  2493. array('X-Auth-Token: ' . $token, 'X-CDN-Enabled: False'), 'HEAD');
  2494. /* create container once more */
  2495. $this->view->upload(preg_replace("@.*X-Storage-Url: (.*?)\r?\n.*@is", "$1", $headers) . '/wo',
  2496. '', $this->options['html_cachedir'],
  2497. array('X-Auth-Token: ' . $token, 'X-Referrer-ACL: 259200'), 'PUT');
  2498. }
  2499. }
  2500. }
  2501. }
  2502. /**
  2503. * Recursive function for files' fetching
  2504. *
  2505. **/
  2506. function get_directory_files ($directory, $mask, $recursive = true, $backup = 'gz', $return = array(), $limit = 0) {
  2507. if (@is_dir($directory) && ($dh = @opendir($directory))) {
  2508. while (($file = @readdir($dh)) !== false) {
  2509. if ($file !== '.' && $file !== '..') {
  2510. $absolute_file =
  2511. $this->view->ensure_trailing_slash($directory) . $file;
  2512. /* deeper recursion */
  2513. if (@is_dir($absolute_file) && $recursive) {
  2514. /* prevent PHP timeout on folders parsing */
  2515. if (!$limit || time() > $this->time + $limit) {
  2516. $return = $this->get_directory_files($absolute_file,
  2517. $mask, $recursive, $backup, $return, $limit);
  2518. }
  2519. /* check for mask */
  2520. } elseif (preg_match("@" . $mask . "@is", $absolute_file)) {
  2521. /* get info about synced file from FTP */
  2522. if ($backup == 'FTP' &&
  2523. !empty($this->compress_options['parallel']['ftp']) &&
  2524. @function_exists('curl_init')) {
  2525. $dir = preg_replace("@[^/]+$@", "", $absolute_file);
  2526. /* check if we already have mtime for files inside this directory */
  2527. if (!isset($this->synced_files[$dir . '.'])) {
  2528. $file = $this->compress_options['html_cachedir'] . 'ftp.tmp';
  2529. $ch = @curl_init('ftp://' .
  2530. preg_replace("!^([^@]+)@([^:]+):([^@]+)@!", "$1:$3@", $this->compress_options['parallel']['ftp']) .
  2531. str_replace($this->compress_options['document_root'], "/", $dir));
  2532. $fp = @fopen($file, 'w');
  2533. @curl_setopt($ch, CURLOPT_USERPWD, preg_replace("!(.*)@.*!", "$1", $this->compress_options['parallel']['ftp']));
  2534. @curl_setopt($ch, CURLOPT_FILE, $fp);
  2535. @curl_exec($ch);
  2536. @curl_close($ch);
  2537. @fclose($fp);
  2538. $fp = @fopen($file, 'r');
  2539. while ($f = @fgets($fp)) {
  2540. $f = preg_replace("@\s+@", " ", $f);
  2541. $metas = explode(" ", $f);
  2542. $this->synced_files[$dir . $metas[8]] = strtotime($metas[5] . " " . $metas[6] . " " . $metas[7]);
  2543. }
  2544. @unlink($file);
  2545. }
  2546. $synced = empty($this->synced_files[$absolute_file]) ? 0 : $this->synced_files[$absolute_file];
  2547. /* or directly from file system */
  2548. } else {
  2549. $synced = @filemtime($absolute_file . '.' . $backup);
  2550. }
  2551. $return[] = array(
  2552. $absolute_file,
  2553. @filemtime($absolute_file),
  2554. $synced,
  2555. @filesize($absolute_file)
  2556. );
  2557. }
  2558. }
  2559. }
  2560. }
  2561. return $return;
  2562. }
  2563. /**
  2564. * CDN sync page
  2565. *
  2566. **/
  2567. function install_cdn() {
  2568. $directory = empty($this->input['wss_directory']) ?
  2569. (empty($this->compress_options['website_root']) ?
  2570. $this->view->paths['absolute']['document_root'] :
  2571. $this->compress_options['website_root']) :
  2572. $this->input['wss_directory'];
  2573. $recursive = empty($this->input['wss_recursive']) ? 0 : 1;
  2574. $submit = empty($this->input['wss_Submit']) ? 0 : 1;
  2575. $results = array();
  2576. if ($submit) {
  2577. /* prevent PHP timeout on folders parsing */
  2578. $limit = @ini_get("max_execution_time");
  2579. @set_time_limit($limit * 10);
  2580. $results = $this->get_directory_files($directory,
  2581. '\\.(jpe?g|png|gif|tiff|bmp|flv|wmv|asf|asx|wma|wax|wmx|wm|swf|pdf|doc|rtf|xls|ppt|txt|xml|css|js|ico|cur|ttf|otf|eot|svg)$',
  2582. $recursive, 'FTP', array(),
  2583. @ini_get("max_execution_time") == $limit ? $limit - 5 : 0);
  2584. }
  2585. $this->page_variables = array(
  2586. "cdn_disabled" => empty($this->compress_options['parallel']['ftp']),
  2587. "results" => $results,
  2588. "directory" => $directory,
  2589. "premium" => $this->premium,
  2590. "recursive" => $recursive,
  2591. "submit" => $submit,
  2592. "skip_render" => $this->skip_render
  2593. );
  2594. $this->view->render("install_cdn", $this->page_variables);
  2595. }
  2596. /**
  2597. * Image optimization page
  2598. *
  2599. **/
  2600. function install_image() {
  2601. $directory = empty($this->input['wss_directory']) ?
  2602. (empty($this->compress_options['website_root']) ?
  2603. $this->view->paths['absolute']['document_root'] :
  2604. $this->compress_options['website_root']) :
  2605. $this->input['wss_directory'];
  2606. $recursive = empty($this->input['wss_recursive']) ? 0 : 1;
  2607. $backup = empty($this->input['wss_backup']) ? 0 : 1;
  2608. $submit = empty($this->input['wss_Submit']) ? 0 : 1;
  2609. $results = array();
  2610. if ($submit) {
  2611. /* prevent PHP timeout on folders parsing */
  2612. $limit = @ini_get("max_execution_time");
  2613. @set_time_limit($limit * 10);
  2614. $this->time = time();
  2615. $results = $this->get_directory_files($directory,
  2616. '\\.(png|gif|jpe?g|bmp)$',
  2617. $recursive, 'backup', array(),
  2618. @ini_get("max_execution_time") == $limit ? $limit - 5 : 0);
  2619. }
  2620. $this->page_variables = array(
  2621. "results" => $results,
  2622. "directory" => $directory,
  2623. "premium" => $this->premium,
  2624. "recursive" => $recursive,
  2625. "backup" => $backup,
  2626. "submit" => $submit,
  2627. "skip_render" => $this->skip_render
  2628. );
  2629. $this->view->render("install_image", $this->page_variables);
  2630. }
  2631. /**
  2632. * Minify page
  2633. *
  2634. **/
  2635. function install_minify() {
  2636. $directory = empty($this->input['wss_directory']) ?
  2637. (empty($this->compress_options['website_root']) ?
  2638. $this->view->paths['absolute']['document_root'] :
  2639. $this->compress_options['website_root']) :
  2640. $this->input['wss_directory'];
  2641. $recursive = empty($this->input['wss_recursive']) ? 0 : 1;
  2642. $submit = empty($this->input['wss_Submit']) ? 0 : 1;
  2643. $results = array();
  2644. if ($submit) {
  2645. /* prevent PHP timeout on folders parsing */
  2646. $limit = @ini_get("max_execution_time");
  2647. @set_time_limit($limit * 10);
  2648. $this->time = time();
  2649. $results = $this->get_directory_files($directory,
  2650. '\\.(css|js)$',
  2651. $recursive, 'backup', array(),
  2652. @ini_get("max_execution_time") == $limit ? $limit - 5 : 0);
  2653. }
  2654. $this->page_variables = array(
  2655. "results" => $results,
  2656. "directory" => $directory,
  2657. "premium" => $this->premium,
  2658. "recursive" => $recursive,
  2659. "submit" => $submit,
  2660. "skip_render" => $this->skip_render
  2661. );
  2662. $this->view->render("install_minify", $this->page_variables);
  2663. }
  2664. /**
  2665. * Static gzip page
  2666. *
  2667. **/
  2668. function install_gzip() {
  2669. $directory = empty($this->input['wss_directory']) ?
  2670. (empty($this->compress_options['website_root']) ?
  2671. $this->view->paths['absolute']['document_root'] :
  2672. $this->compress_options['website_root']) :
  2673. $this->input['wss_directory'];
  2674. $recursive = empty($this->input['wss_recursive']) ? 0 : 1;
  2675. $submit = empty($this->input['wss_Submit']) ? 0 : 1;
  2676. $results = array();
  2677. if ($submit) {
  2678. /* prevent PHP timeout on folders parsing */
  2679. $limit = @ini_get("max_execution_time");
  2680. @set_time_limit($limit * 10);
  2681. $this->time = time();
  2682. $results = $this->get_directory_files($directory,
  2683. '\\.(txt|xml|css|js|ico|cur|ttf|otf|eot|svg)$',
  2684. $recursive, 'gz', array(),
  2685. @ini_get("max_execution_time") == $limit ? $limit - 5 : 0);
  2686. }
  2687. $this->page_variables = array(
  2688. "results" => $results,
  2689. "directory" => $directory,
  2690. "premium" => $this->premium,
  2691. "recursive" => $recursive,
  2692. "submit" => $submit,
  2693. "skip_render" => $this->skip_render
  2694. );
  2695. $this->view->render("install_gzip", $this->page_variables);
  2696. }
  2697. /**
  2698. * Update from System Status (beta)
  2699. *
  2700. **/
  2701. function install_beta () {
  2702. $this->install_update_generic(0);
  2703. $this->install_system();
  2704. }
  2705. /**
  2706. * Update from System Status (rollback)
  2707. *
  2708. **/
  2709. function install_rollback () {
  2710. $this->install_update_generic();
  2711. $this->install_system();
  2712. }
  2713. /**
  2714. * Update from System Status (stable)
  2715. *
  2716. **/
  2717. function install_stable () {
  2718. $this->install_update_generic();
  2719. $this->install_system();
  2720. }
  2721. /**
  2722. * Update from dashboard
  2723. *
  2724. **/
  2725. function install_update () {
  2726. $this->install_update_generic();
  2727. $this->install_dashboard();
  2728. }
  2729. /**
  2730. * Generic update function
  2731. *
  2732. **/
  2733. function install_update_generic($stable = 1) {
  2734. @chdir($this->basepath);
  2735. $file = 'files';
  2736. $svn = $stable ? $this->version_stable ? $this->svn_generic . 'versions/' . $this->version_stable . '/' : $this->svn : $this->svn_beta;
  2737. $this->view->download($svn . $file, $file);
  2738. $i = 1;
  2739. if (@is_file($file)) {
  2740. $files = preg_split("!\r?\n!", $this->file_get_contents($file));
  2741. $total = count($files);
  2742. foreach ($files as $file) {
  2743. $this->write_progress(round(100 * $i / $total) . "," . $i . "," . $total, 1);
  2744. if (!empty($file)) {
  2745. $file = explode(":", $file);
  2746. $tmp = $file[0] . '.tmp';
  2747. if (!empty($file[1])) {
  2748. $recursion = 0;
  2749. while (@filesize($tmp) != $file[1] && $recursion < 10) {
  2750. $this->view->download($svn . $file[0], $tmp);
  2751. $recursion++;
  2752. }
  2753. if (@filesize($tmp) != $file[1]) {
  2754. $this->error[6] = 1;
  2755. }
  2756. } else {
  2757. $this->view->download($svn . $file[0], $tmp);
  2758. }
  2759. @rename($tmp, $file[0]);
  2760. /* remove old gzipped version */
  2761. @unlink($file[0] . '.gz');
  2762. if ($file[0] == 'config.webo.php') {
  2763. $this->options_file = 'config.webo.php';
  2764. $this->save_options();
  2765. }
  2766. }
  2767. $i++;
  2768. }
  2769. }
  2770. $config_file = 'config.' . $this->compress_options['config'] . '.php';
  2771. @include($this->basepath . $config_file);
  2772. $compress_options_backup = $this->compress_options;
  2773. /* rewrite user/auto configs */
  2774. @chdir($this->basepath);
  2775. $configs = glob("config.*.php");
  2776. if (is_array($configs)) {
  2777. foreach ($configs as $file) {
  2778. if (@is_file($this->basepath . $file) && !in_array($file, array('config.safe.php', 'config.basic.php', 'config.optimal.php', 'config.extreme.php', 'config.webo.php'))) {
  2779. include($this->basepath . $file);
  2780. $this->compress_options = $compress_options;
  2781. $this->options_file_backup = $this->options_file;
  2782. $this->options_file = $file;
  2783. @copy($this->basepath . 'config.safe.php', $this->basepath . $file);
  2784. $this->save_options();
  2785. $this->options_file = $this->options_file_backup;
  2786. }
  2787. }
  2788. }
  2789. if (@is_file($this->basepath . $config_file) && !in_array($this->compress_options['config'], array('safe', 'basic', 'optimal', 'extreme'))) {
  2790. $this->save_option("['config']", $this->compress_options['config']);
  2791. $this->options_file_backup = $this->options_file;
  2792. $this->options_file = $config_file;
  2793. $this->save_option("['title']", $compress_options['title']);
  2794. $this->save_option("['description']", $compress_options['description']);
  2795. $this->save_options();
  2796. $this->options_file = $this->options_file_backup;
  2797. $this->save_option("['config']", $this->compress_options['config']);
  2798. }
  2799. /* rewrite current hosts'/URLs configs with new options */
  2800. $configs = glob("*.config.webo.php");
  2801. if (is_array($configs)) {
  2802. foreach ($configs as $file) {
  2803. include($this->basepath . $file);
  2804. $this->compress_options = $compress_options;
  2805. $this->options_file_backup = $this->options_file;
  2806. $this->options_file = $file;
  2807. @copy($this->basepath . 'config.webo.php', $this->basepath . $file);
  2808. $this->save_options();
  2809. $this->options_file = $this->options_file_backup;
  2810. }
  2811. }
  2812. $this->compress_options = $compress_options_backup;
  2813. @unlink($this->compress_options['javascript_cachedir'] . 'progress.php');
  2814. }
  2815. /**
  2816. * Uninstall page
  2817. *
  2818. **/
  2819. function install_uninstall ($skip = false) {
  2820. $return = !$skip;
  2821. $this->cms_version = $this->system_info($this->view->paths['absolute']['document_root']);
  2822. /* PHP-Nuke, Bitrix, Open Slaed deletion */
  2823. if (in_array($this->cms_version, array('PHP-Nuke', 'Bitrix', '4images', 'VaM Shop', 'osCommerce')) ||
  2824. substr($this->cms_version, 0, 10) == 'Open Slaed' ||
  2825. substr($this->cms_version, 0, 13) == 'Social Engine') {
  2826. if ($this->cms_version == 'Bitrix') {
  2827. $mainfile = $this->view->paths['absolute']['document_root'] . 'bitrix/header.php';
  2828. $footer = $this->view->paths['absolute']['document_root'] . 'bitrix/modules/main/include/epilog_after.php';
  2829. } elseif ($this->cms_version == 'PHP-Nuke') {
  2830. $mainfile = $this->view->paths['absolute']['document_root'] . 'mainfile.php';
  2831. $footer = $this->view->paths['absolute']['document_root'] . 'footer.php';
  2832. } elseif ($this->cms_version == '4images') {
  2833. $mainfile = $this->view->paths['absolute']['document_root'] . 'includes/page_header.php';
  2834. $footer = $this->view->paths['absolute']['document_root'] . 'includes/page_footer.php';
  2835. } elseif ($this->cms_version == 'VaM Shop' || $this->cms_version == 'osCommerce') {
  2836. $mainfile = $this->view->paths['absolute']['document_root'] . 'includes/application_top.php';
  2837. $footer = $this->view->paths['absolute']['document_root'] . 'includes/application_bottom.php';
  2838. } elseif (substr($this->cms_version, 0, 13) == 'Social Engine') {
  2839. $mainfile = $this->view->paths['absolute']['document_root'] . 'header.php';
  2840. $footer = $this->view->paths['absolute']['document_root'] . 'footer.php';
  2841. } else {
  2842. $mainfile = $this->view->paths['absolute']['document_root'] . 'index.php';
  2843. $footer = $this->view->paths['absolute']['document_root'] . 'function/function.php';
  2844. }
  2845. $this->cleanup_file($mainfile, $return);
  2846. $this->cleanup_file($footer, $return);
  2847. } else {
  2848. /* remove instances of Web Optimizer from index.php */
  2849. $index = $this->view->paths['absolute']['document_root'] . 'index.php';
  2850. /* fix for phpBB and vBulletin */
  2851. if ($this->cms_version == 'phpBB' || substr($this->cms_version, 0, 9) == 'vBulletin') {
  2852. $index = $this->view->paths['absolute']['document_root'] . 'includes/functions.php';
  2853. /* fix for IPB */
  2854. } elseif ($this->cms_version == 'Invision Power Board') {
  2855. $index = $this->view->paths['absolute']['document_root'] . 'sources/classes/class_display.php';
  2856. /* fix for NetCat */
  2857. } elseif ($this->cms_version == 'NetCat') {
  2858. $index = $this->view->paths['absolute']['document_root'] . 'netcat/require/e404.php';
  2859. /* fix for PHP Fusion */
  2860. } elseif ($this->cms_version == 'PHP Fusion') {
  2861. $index = $this->view->paths['absolute']['document_root'] . 'themes/templates/footer.php';
  2862. /* fix for PHP Fusion */
  2863. } elseif ($this->cms_version == 'X-Cart') {
  2864. $index = $this->view->paths['absolute']['document_root'] . 'include/func/func.core.php';
  2865. /* fix for Shop-Script */
  2866. } elseif (substr($this->cms_version, 0, 11) == 'Shop-Script') {
  2867. $index = $this->view->paths['absolute']['document_root'] . 'published/SC/html/scripts/index.php';
  2868. }
  2869. $this->cleanup_file($index, $return);
  2870. /* additional change of cache plugins */
  2871. if (substr($this->cms_version, 0, 7) == "Joomla!" || substr($this->cms_version, 0, 5) == "XOOPS") {
  2872. /* Joomla! 1.5 System-Cache plugin */
  2873. if (preg_match("/Joomla! 1\.[56789]/", $this->cms_version)) {
  2874. $cache_file = $this->view->paths['absolute']['document_root'] . 'plugins/system/cache.php';
  2875. /* Joomla! 1.0 PageCache component */
  2876. } elseif (substr($this->cms_version, 0, 7) == "Joomla!") {
  2877. $cache_file = $this->view->paths['absolute']['document_root'] . 'components/com_pagecache/pagecache.class.php';
  2878. /* XOOPS internal caching */
  2879. } else {
  2880. $cache_file = $this->view->paths['absolute']['document_root'] . 'class/theme.php';
  2881. }
  2882. $this->cleanup_file($cache_file, $return);
  2883. }
  2884. /* Joomla! 1.0 System-Cache mambot, Joomla! 1.5 JRE change */
  2885. if (substr($this->cms_version, 0, 7) == "Joomla!") {
  2886. /* System-Cache*/
  2887. $cache_file = $this->view->paths['absolute']['document_root'] . 'mambots/system/cache.php';
  2888. $this->cleanup_file($cache_file, $return);
  2889. /* JRE */
  2890. $cache_file = $this->view->paths['absolute']['document_root'] . 'administrator/components/com_jrecache/includes/cache_handler.php';
  2891. $this->cleanup_file($cache_file, $return);
  2892. }
  2893. }
  2894. /* execute plugin-specific logic */
  2895. $plugins = explode(" ", $this->compress_options['plugins']);
  2896. if (is_array($plugins)) {
  2897. foreach ($plugins as $plugin) {
  2898. $plugin_file = $this->basepath . 'plugins/' . $plugin . '.php';
  2899. if (@is_file($plugin_file)) {
  2900. include($plugin_file);
  2901. $web_optimizer_plugin->onUninstall($this->view->paths['absolute']['document_root']);
  2902. }
  2903. }
  2904. }
  2905. /* clean up all WEBO Site SpeedUp rules from .htaccess */
  2906. $this->htaccess = $this->detect_htaccess();
  2907. if (empty($this->error)) {
  2908. if (!@is_file($this->htaccess . '.backup')) {
  2909. $content_saved = $this->clean_htaccess();
  2910. $this->write_file($this->htaccess, $content_saved, $return);
  2911. } else {
  2912. @copy($this->htaccess . '.backup', $this->htaccess);
  2913. }
  2914. }
  2915. $submit = empty($this->input['wss_Submit']) ? 0 : 1;
  2916. $message = empty($this->input['wss_message']) ? '' : $this->input['wss_message'];
  2917. $email = empty($this->input['wss_email']) ? '' : $this->input['wss_email'];
  2918. /* remove all optimization results */
  2919. @unlink($this->basepath . $this->index_before);
  2920. @unlink($this->basepath . $this->index_after);
  2921. $error = array();
  2922. if (!$skip) {
  2923. if ($submit) {
  2924. if (empty($email) ||
  2925. !preg_match("/.+@.+\..+/", $email)) {
  2926. $error[1] = 1;
  2927. }
  2928. if (empty($message)) {
  2929. $error[2] = 1;
  2930. }
  2931. /* send a email to info@webo.name */
  2932. if (!count($error)) {
  2933. $this->send_message($email, $message, 1);
  2934. }
  2935. }
  2936. $this->page_variables = array(
  2937. "title" => _WEBO_SPLASH1_UNINSTALL,
  2938. "page" => 'install_uninstall',
  2939. "document_root" => $this->view->paths['full']['document_root'],
  2940. "website_root" => $this->view->paths['absolute']['document_root'],
  2941. "message" => $message,
  2942. "email" => $email,
  2943. "submit" => $submit,
  2944. "error" => $error,
  2945. "basepath" => $this->basepath,
  2946. "version" => $this->version,
  2947. "premium" => $this->premium,
  2948. "language" => $this->language,
  2949. "skip_render" => $this->skip_render
  2950. );
  2951. $this->view->render("install_uninstall", $this->page_variables);
  2952. }
  2953. }
  2954. /**
  2955. * Writes content to file
  2956. **/
  2957. function write_file ($file, $content, $return = false) {
  2958. if (function_exists('file_put_contents')) {
  2959. @chmod($file, octdec("0666"));
  2960. $return = @file_put_contents($file, $content);
  2961. @chmod($file, octdec("0644"));
  2962. } else {
  2963. @chmod($file, octdec("0666"));
  2964. $fp = @fopen($file, "w");
  2965. if ($fp) {
  2966. @fwrite($fp, $content);
  2967. @fclose($fp);
  2968. $return = 1;
  2969. } elseif ($return) {
  2970. $return = 0;
  2971. }
  2972. @chmod($file, octdec("0644"));
  2973. }
  2974. if (!empty($return)) {
  2975. return $return;
  2976. }
  2977. }
  2978. /**
  2979. * Delets Web Optimizer calls from a single file
  2980. **/
  2981. function cleanup_file ($file, $return = false) {
  2982. if (@is_file($file)) {
  2983. $content = $this->file_get_contents($file);
  2984. /* clean content from Web Optimizer calls */
  2985. $content = preg_replace("!<\?php /\* WEBO Site SpeedUp.*?\?>!is", "", $content);
  2986. $content = preg_replace("/(global \\\$web_optimizer|\\\$web_optimizer,|\\\$[^\s]+\s*=\s*\\\$web_optimizer->finish\([^\)]+\);|\\\$web_optimizer->finish\(\)|require\('[^\']+\/web.optimizer.php'\));?\r?\n?/is", "", $content);
  2987. $content = preg_replace("!\\\$not_buffered\s*=\s*.*?ob_start\('weboptimizer_shutdown'\);!is", "", $content);
  2988. $this->write_file($file, $content, $return);
  2989. }
  2990. }
  2991. /**
  2992. * Simple function to check multiple hosts possibility
  2993. * Returns lists of allowed hosts from given array
  2994. **/
  2995. function check_hosts ($hosts) {
  2996. $main_host = preg_replace("/^www\./", "", $_SERVER['HTTP_HOST']);
  2997. $allowed_hosts = "";
  2998. /* exclude local host case */
  2999. if (strpos($main_host, ".")) {
  3000. $etalon = @filesize("libs/css/progress.png");
  3001. $etalon2 = @filesize("libs/css/stamps.png");
  3002. if (is_array($hosts)) {
  3003. foreach ($hosts as $host) {
  3004. if (!strpos($host, ".")) {
  3005. $host = $host . "." . $main_host;
  3006. }
  3007. $webo_image = "http://" . $host . preg_replace("/[^\/]+$/", "", $_SERVER['SCRIPT_NAME']) . "libs/css/a.png";
  3008. $tmp_image = "image.tmp.png";
  3009. /* try to get webo image from this host */
  3010. $this->view->download($webo_image, $tmp_image);
  3011. if (@filesize($tmp_image) == $etalon) {
  3012. /* prevent 404 page with the same size */
  3013. $webo_image2 = "http://" . $host . preg_replace("/[^\/]+$/", "", $_SERVER['SCRIPT_NAME']) . "libs/css/c.png";
  3014. $tmp_image2 = "image.tmp2.png";
  3015. $this->view->download($webo_image2, $tmp_image2);
  3016. if (@filesize($tmp_image2) == $etalon2) {
  3017. $allowed_hosts .= $host . " ";
  3018. }
  3019. @unlink($tmp_image2);
  3020. }
  3021. @unlink($tmp_image);
  3022. }
  3023. }
  3024. }
  3025. return trim($allowed_hosts);
  3026. }
  3027. /**
  3028. * Get current balance / paid options
  3029. *
  3030. **/
  3031. function install_balance () {
  3032. $this->page_variables = array(
  3033. "options" => $this->get_options(),
  3034. "premium" => $this->premium,
  3035. "basepath" => $this->basepath,
  3036. "skip_render" => $this->skip_render
  3037. );
  3038. $this->view->render("install_balance", $this->page_variables);
  3039. }
  3040. /**
  3041. * Delete given configuration
  3042. **/
  3043. function options_delete () {
  3044. $config = $this->input['wss_config'];
  3045. $config_file = $this->basepath . 'config.' .
  3046. preg_replace("/[^a-z0-9]/","", $config) . '.php';
  3047. @unlink($config_file);
  3048. $this->error = array();
  3049. if (@is_file($config_file)) {
  3050. $this->error[5] = 1;
  3051. /* switch to safe config is we deleting current one */
  3052. } else {
  3053. if ($config == $this->compress_options['config']) {
  3054. $this->save_option("['config']", "safe");
  3055. }
  3056. }
  3057. $this->page_variables = array(
  3058. "page" => 'options_delete',
  3059. "submit" => 1,
  3060. "error" => $this->error,
  3061. "config" => $config_file
  3062. );
  3063. $this->view->render("install_options", $this->page_variables);
  3064. }
  3065. /**
  3066. * Return all configuration as JSON-array
  3067. **/
  3068. function options_configuration () {
  3069. /* get all available configurations */
  3070. $options = array();
  3071. @chdir($this->basepath);
  3072. foreach (glob("config.*.php") as $file) {
  3073. if ($file != 'config.webo.php') {
  3074. $saved = $this->compress_options;
  3075. $key = str_replace(array("config.", ".php"), '', $file);
  3076. $ext = strpos($key, 'user') === false ? $key : 'user';
  3077. include($this->basepath . $file);
  3078. $this->compress_options = $compress_options;
  3079. $this->compress_options['external_scripts']['user'] =
  3080. $saved['external_scripts']['user'];
  3081. $this->compress_options['external_scripts']['pass'] =
  3082. $saved['external_scripts']['pass'];
  3083. $this->compress_options['javascript_cachedir'] =
  3084. $saved['javascript_cachedir'];
  3085. $options[$key] = $this->get_options($ext);
  3086. $this->compress_options = $saved;
  3087. }
  3088. }
  3089. $this->page_variables = array(
  3090. "options" => $options,
  3091. "skip_render" => $this->skip_render
  3092. );
  3093. $this->view->render("options_configuration", $this->page_variables);
  3094. }
  3095. /**
  3096. * Get options to render them
  3097. *
  3098. **/
  3099. function install_options () {
  3100. $options = $this->get_options();
  3101. $submit = empty($this->input['wss_Submit']) ? 0 : 1;
  3102. $this->error = array();
  3103. if ($submit) {
  3104. $this->set_options();
  3105. $this->write_htaccess();
  3106. }
  3107. /* get list of users configs */
  3108. $configs = array();
  3109. @chdir($this->basepath);
  3110. foreach (glob("config.*.php") as $file) {
  3111. if (!in_array($file, array( 'config.webo.php', 'config.basic.php', 'config.safe.php', 'config.optimal.php', 'config.extreme.php'))) {
  3112. $configs[] = str_replace(array("config.", ".php"), '', $file);
  3113. }
  3114. }
  3115. $this->page_variables = array(
  3116. "options" => $options,
  3117. "premium" => $this->premium,
  3118. "submit" => $submit,
  3119. "error" => $this->error,
  3120. "basepath" => $this->basepath,
  3121. "configs" => $configs,
  3122. "config" => $this->compress_options['config'],
  3123. "skip_render" => $this->skip_render,
  3124. "iis" => $this->iis
  3125. );
  3126. $this->view->render("install_options", $this->page_variables);
  3127. }
  3128. /**
  3129. * Set options according to internal logic
  3130. *
  3131. **/
  3132. function get_options ($config = 'safe') {
  3133. /* calculate current environment restrictions */
  3134. $this->check_options();
  3135. $options = array(
  3136. 'title' => empty($this->compress_options['title']) ?
  3137. '' : $this->compress_options['title'],
  3138. 'description' => empty($this->compress_options['description']) ?
  3139. '' : $this->compress_options['description'],
  3140. 'combinecss' => array(
  3141. 'combine_css' => array(
  3142. 'value' => $this->compress_options['minify']['css'] ?
  3143. $this->compress_options['minify']['css_body'] ? 2 : 1 : 0,
  3144. 'type' => 'radio',
  3145. 'count' => 3
  3146. ),
  3147. 'external_scripts_css_inline' => array(
  3148. 'value' => $this->compress_options['external_scripts']['css_inline'],
  3149. 'type' => 'checkbox'
  3150. ),
  3151. 'external_scripts_css' => array(
  3152. 'value' => $this->compress_options['external_scripts']['css'],
  3153. 'type' => 'checkbox',
  3154. 'disabled' => !empty($this->restrictions['wss_external_scripts_css'])
  3155. ),
  3156. 'minify_css_file' => array(
  3157. 'value' => $this->compress_options['minify']['css_file'],
  3158. 'type' => 'text',
  3159. 'price' => 1,
  3160. 'hidden' => $this->premium < 2 ? 1 : 0
  3161. ),
  3162. 'minify_css_host' => array(
  3163. 'value' => $this->compress_options['minify']['css_host'],
  3164. 'type' => 'text',
  3165. 'price' => 2,
  3166. 'hidden' => $this->premium < 1 ? 1 : 0
  3167. ),
  3168. 'external_scripts_additional_list' => array(
  3169. 'value' => $this->compress_options['external_scripts']['additional_list'],
  3170. 'type' => 'textarea'
  3171. ),
  3172. 'external_scripts_include_code' => array(
  3173. 'value' => $this->compress_options['external_scripts']['include_code'],
  3174. 'type' => 'textarea',
  3175. 'price' => 1,
  3176. 'hidden' => $this->premium < 1 ? 1 : 0
  3177. ),
  3178. 'config' => array(
  3179. 'value' => $this->compress_options['config'],
  3180. 'type' => 'text',
  3181. 'hidden' => 1
  3182. ),
  3183. 'external_scripts_remove_list_css' => array(
  3184. 'value' => empty($this->compress_options['external_scripts']['remove_list_css']) ? '' : $this->compress_options['external_scripts']['remove_list_css'],
  3185. 'type' => 'text',
  3186. 'hidden' => $this->premium < 2 ? 1 : 0,
  3187. 'price' => 3
  3188. ),
  3189. ),
  3190. 'combine_js' => array(
  3191. 'minify_javascript' => array(
  3192. 'value' => $this->compress_options['minify']['javascript'],
  3193. 'type' => 'checkbox'
  3194. ),
  3195. 'minify_javascript_body' => array(
  3196. 'value' => $this->compress_options['minify']['javascript_body'],
  3197. 'type' => 'checkbox'
  3198. ),
  3199. 'external_scripts_inline' => array(
  3200. 'value' => $this->compress_options['external_scripts']['inline'],
  3201. 'type' => 'checkbox'
  3202. ),
  3203. 'external_scripts_inline_body' => array(
  3204. 'value' => empty($this->compress_options['external_scripts']['inline_body']) ? 0 : 1,
  3205. 'type' => 'checkbox'
  3206. ),
  3207. 'external_scripts_on' => array(
  3208. 'value' => $this->compress_options['external_scripts']['on'],
  3209. 'type' => 'checkbox',
  3210. 'disabled' => !empty($this->restrictions['wss_external_scripts_on'])
  3211. ),
  3212. 'minify_javascript_file' => array(
  3213. 'value' => $this->compress_options['minify']['javascript_file'],
  3214. 'type' => 'text',
  3215. 'price' => 1,
  3216. 'hidden' => $this->premium < 2 ? 1 : 0
  3217. ),
  3218. 'minify_javascript_host' => array(
  3219. 'value' => $this->compress_options['minify']['javascript_host'],
  3220. 'type' => 'text',
  3221. 'price' => 2,
  3222. 'hidden' => $this->premium < 1 ? 1 : 0
  3223. ),
  3224. 'external_scripts_ignore_list' => array(
  3225. 'value' => $this->compress_options['external_scripts']['ignore_list'],
  3226. 'type' => 'textarea'
  3227. ),
  3228. 'external_scripts_head_end' => array(
  3229. 'value' => $this->compress_options['external_scripts']['head_end'],
  3230. 'type' => 'checkbox'
  3231. ),
  3232. 'external_scripts_include_try' => array(
  3233. 'value' => $this->compress_options['external_scripts']['include_try'],
  3234. 'type' => 'checkbox',
  3235. 'hidden' => $this->premium < 1 ? 1 : 0
  3236. ),
  3237. 'external_scripts_duplicates' => array(
  3238. 'value' => $this->compress_options['external_scripts']['duplicates'],
  3239. 'type' => 'checkbox',
  3240. 'hidden' => $this->premium < 1 ? 1 : 0
  3241. ),
  3242. 'external_scripts_include_mask' => array(
  3243. 'value' => empty($this->compress_options['external_scripts']['include_mask']) ? '' : $this->compress_options['external_scripts']['include_mask'],
  3244. 'type' => 'text',
  3245. 'hidden' => $this->premium < 2 ? 1 : 0
  3246. ),
  3247. 'external_scripts_remove_list' => array(
  3248. 'value' => empty($this->compress_options['external_scripts']['remove_list']) ? '' : $this->compress_options['external_scripts']['remove_list'],
  3249. 'type' => 'text',
  3250. 'hidden' => $this->premium < 2 ? 1 : 0,
  3251. 'price' => 3
  3252. ),
  3253. ),
  3254. 'minify' => array(
  3255. 'minify_css_min' => array(
  3256. 'value' => $this->compress_options['minify']['css_min'],
  3257. 'type' => 'radio',
  3258. 'count' => $this->premium < 2 ? 2 : 4,
  3259. ),
  3260. 'minify_js' => array(
  3261. 'value' => $this->compress_options['minify']['with_jsmin'] ? 1 :
  3262. ($this->compress_options['minify']['with_yui'] ? 2 :
  3263. ($this->compress_options['minify']['with_packer'] ? 3 :
  3264. (!empty($this->compress_options['minify']['with_google']) ? 4 : 0))),
  3265. 'type' => 'radio',
  3266. 'count' => $this->premium < 2 ? 2 : 5,
  3267. 'disabled' => array(
  3268. 0,
  3269. !empty($this->restrictions['wss_minify_js1']),
  3270. !empty($this->restrictions['wss_minify_js2']),
  3271. !empty($this->restrictions['wss_minify_js3']),
  3272. !empty($this->restrictions['wss_minify_js4']),
  3273. !empty($this->restrictions['wss_minify_js5'])
  3274. )
  3275. ),
  3276. 'external_scripts_minify_exclude' => array(
  3277. 'value' => $this->compress_options['external_scripts']['minify_exclude'],
  3278. 'type' => 'textarea',
  3279. 'price' => 1
  3280. ),
  3281. 'minify_page' => array(
  3282. 'value' => $this->compress_options['minify']['page'],
  3283. 'type' => 'checkbox'
  3284. ),
  3285. 'minify_html_one_string' => array(
  3286. 'hidden' => $this->premium < 1 ? 1 : 0,
  3287. 'value' => $this->compress_options['minify']['html_one_string'],
  3288. 'type' => 'checkbox',
  3289. 'price' => 2
  3290. ),
  3291. 'minify_html_comments' => array(
  3292. 'hidden' => $this->premium < 1 ? 1 : 0,
  3293. 'value' => $this->compress_options['minify']['html_comments'],
  3294. 'type' => 'checkbox',
  3295. 'price' => 2
  3296. )
  3297. ),
  3298. 'gzip' => array(
  3299. 'gzip_css' => array(
  3300. 'value' => $this->compress_options['gzip']['css'],
  3301. 'type' => 'checkbox'
  3302. ),
  3303. 'gzip_javascript' => array(
  3304. 'value' => $this->compress_options['gzip']['javascript'],
  3305. 'type' => 'checkbox'
  3306. ),
  3307. 'gzip_fonts' => array(
  3308. 'value' => $this->compress_options['gzip']['fonts'],
  3309. 'type' => 'checkbox'
  3310. ),
  3311. 'gzip_page' => array(
  3312. 'value' => $this->compress_options['gzip']['page'],
  3313. 'type' => 'checkbox',
  3314. 'disabled' => !empty($this->restrictions['wss_gzip_page'])
  3315. ),
  3316. 'gzip_zlib' => array(
  3317. 'hidden' => $this->premium < 2 ? 1 : 0,
  3318. 'value' => empty($this->compress_options['gzip']['zlib']) ? '' : $this->compress_options['gzip']['zlib'],
  3319. 'type' => 'checkbox',
  3320. 'disabled' => !empty($this->restrictions['wss_gzip_zlib'])
  3321. ),
  3322. 'gzip_cookie' => array(
  3323. 'hidden' => $this->premium < 1 ? 1 : 0,
  3324. 'value' => $this->compress_options['gzip']['cookie'],
  3325. 'type' => 'checkbox',
  3326. 'price' => 3
  3327. ),
  3328. 'gzip_noie' => array(
  3329. 'hidden' => $this->premium < 1 ? 1 : 0,
  3330. 'value' => $this->compress_options['gzip']['noie'],
  3331. 'type' => 'checkbox',
  3332. 'price' => 1
  3333. )
  3334. ),
  3335. 'clientside' => array(
  3336. 'far_future_expires_css' => array(
  3337. 'value' => $this->compress_options['far_future_expires']['css'],
  3338. 'type' => 'checkbox'
  3339. ),
  3340. 'far_future_expires_javascript' => array(
  3341. 'value' => $this->compress_options['far_future_expires']['javascript'],
  3342. 'type' => 'checkbox'
  3343. ),
  3344. 'far_future_expires_images' => array(
  3345. 'value' => $this->compress_options['far_future_expires']['images'],
  3346. 'type' => 'checkbox'
  3347. ),
  3348. 'far_future_expires_fonts' => array(
  3349. 'value' => $this->compress_options['far_future_expires']['fonts'],
  3350. 'type' => 'checkbox',
  3351. 'disabled' => !empty($this->restrictions['wss_htaccess_mod_expires']) &&
  3352. !empty($this->restrictions['wss_htaccess_mod_rewrite'])
  3353. ),
  3354. 'far_future_expires_video' => array(
  3355. 'value' => $this->compress_options['far_future_expires']['video'],
  3356. 'type' => 'checkbox',
  3357. 'disabled' => !empty($this->restrictions['wss_htaccess_mod_expires']) &&
  3358. !empty($this->restrictions['wss_htaccess_mod_rewrite'])
  3359. ),
  3360. 'far_future_expires_static' => array(
  3361. 'value' => $this->compress_options['far_future_expires']['static'],
  3362. 'type' => 'checkbox',
  3363. 'disabled' => !empty($this->restrictions['wss_htaccess_mod_expires']) &&
  3364. !empty($this->restrictions['wss_htaccess_mod_rewrite'])
  3365. ),
  3366. 'far_future_expires_html' => array(
  3367. 'value' => $this->compress_options['far_future_expires']['html'],
  3368. 'type' => 'checkbox',
  3369. 'price' => 2,
  3370. 'hidden' => $this->premium < 1 ? 1 : 0
  3371. ),
  3372. 'far_future_expires_html_timeout' => array(
  3373. 'value' => $this->compress_options['far_future_expires']['html_timeout'],
  3374. 'type' => 'smalltext',
  3375. 'hidden' => $this->premium < 1 ? 1 : 0
  3376. ),
  3377. 'far_future_expires_external' => array(
  3378. 'value' => $this->compress_options['far_future_expires']['external'],
  3379. 'type' => 'checkbox',
  3380. 'price' => 3,
  3381. 'hidden' => $this->premium < 1 ? 1 : 0
  3382. )
  3383. ),
  3384. 'htaccess' => array(
  3385. 'htaccess_enabled' => array(
  3386. 'value' => $this->compress_options['htaccess']['enabled'],
  3387. 'type' => 'checkbox',
  3388. 'disabled' => !empty($this->restrictions['wss_htaccess_enabled'])
  3389. ),
  3390. 'htaccess_local' => array(
  3391. 'value' => $this->compress_options['htaccess']['local'],
  3392. 'type' => 'checkbox',
  3393. 'disabled' => !empty($this->restrictions['wss_htaccess_enabled'])
  3394. ),
  3395. 'htaccess_mod_deflate' => array(
  3396. 'value' => $this->compress_options['htaccess']['mod_deflate'],
  3397. 'type' => 'checkbox',
  3398. 'disabled' => !empty($this->restrictions['wss_htaccess_mod_deflate']) ||
  3399. empty($this->restrictions['wss_htaccess_mod_gzip'])
  3400. ),
  3401. 'htaccess_mod_gzip' => array(
  3402. 'value' => $this->compress_options['htaccess']['mod_gzip'],
  3403. 'type' => 'checkbox',
  3404. 'disabled' => !empty($this->restrictions['wss_htaccess_mod_gzip']) ||
  3405. empty($this->restrictions['wss_htaccess_mod_deflate'])
  3406. ),
  3407. 'htaccess_mod_expires' => array(
  3408. 'value' => $this->compress_options['htaccess']['mod_expires'],
  3409. 'type' => 'checkbox',
  3410. 'disabled' => !empty($this->restrictions['wss_htaccess_mod_expires'])
  3411. ),
  3412. 'htaccess_mod_headers' => array(
  3413. 'value' => $this->compress_options['htaccess']['mod_headers'],
  3414. 'type' => 'checkbox',
  3415. 'disabled' => !empty($this->restrictions['wss_htaccess_mod_headers'])
  3416. ),
  3417. 'htaccess_mod_setenvif' => array(
  3418. 'value' => $this->compress_options['htaccess']['mod_setenvif'],
  3419. 'type' => 'checkbox',
  3420. 'disabled' => !empty($this->restrictions['wss_htaccess_mod_setenvif'])
  3421. ),
  3422. 'htaccess_mod_rewrite' => array(
  3423. 'value' => $this->compress_options['htaccess']['mod_rewrite'],
  3424. 'type' => 'checkbox',
  3425. 'disabled' => !empty($this->restrictions['wss_htaccess_mod_rewrite'])
  3426. ),
  3427. 'htaccess_mod_mime' => array(
  3428. 'value' => $this->compress_options['htaccess']['mod_mime'],
  3429. 'type' => 'checkbox',
  3430. 'disabled' => !empty($this->restrictions['wss_htaccess_mod_mime'])
  3431. )
  3432. ),
  3433. 'backlink' => array(
  3434. 'footer_text' => array(
  3435. 'value' => $this->compress_options['footer']['text'],
  3436. 'type' => 'checkbox'
  3437. ),
  3438. 'footer_image' => array(
  3439. 'value' => $this->compress_options['footer']['image'],
  3440. 'type' => 'textarea'
  3441. ),
  3442. 'footer_link' => array(
  3443. 'value' => $this->compress_options['footer']['link'],
  3444. 'type' => 'textarea'
  3445. ),
  3446. 'footer_css_code' => array(
  3447. 'value' => $this->compress_options['footer']['css_code'],
  3448. 'type' => 'textarea'
  3449. ),
  3450. 'footer_spot' => array(
  3451. 'hidden' => $this->premium < 1 ? 1 : 0,
  3452. 'value' => $this->compress_options['footer']['spot'],
  3453. 'type' => 'checkbox'
  3454. ),
  3455. 'footer_counter' => array(
  3456. 'hidden' => $this->premium < 2 ? 1 : 0,
  3457. 'value' => empty($this->compress_options['footer']['counter']) ? '' : $this->compress_options['footer']['counter'],
  3458. 'type' => 'smalltext'
  3459. ),
  3460. 'footer_ab' => array(
  3461. 'hidden' => $this->premium < 2 ? 1 : 0,
  3462. 'type' => 'smalltext',
  3463. 'value' => empty($this->compress_options['footer']['ab']) ? '' : $this->compress_options['footer']['ab'],
  3464. 'price' => 5
  3465. )
  3466. ),
  3467. 'performance' => array(
  3468. 'performance_mtime' => array(
  3469. 'value' => $this->compress_options['performance']['mtime'],
  3470. 'type' => 'checkbox',
  3471. 'price' => 12
  3472. ),
  3473. 'performance_check_files' => array(
  3474. 'hidden' => $this->premium < 2 ? 1 : 0,
  3475. 'value' => empty($this->compress_options['performance']['cache_version']) ? 0 : 1,
  3476. 'type' => 'checkbox',
  3477. 'price' => 1
  3478. ),
  3479. 'performance_cache_version' => array(
  3480. 'hidden' => $this->premium < 2 ? 1 : 0,
  3481. 'value' => $this->compress_options['performance']['cache_version'],
  3482. 'type' => 'smalltext',
  3483. 'price' => 2
  3484. ),
  3485. 'performance_plain_string' => array(
  3486. 'hidden' => $this->premium < 1 ? 1 : 0,
  3487. 'value' => $this->compress_options['performance']['plain_string'],
  3488. 'type' => 'checkbox',
  3489. 'price' => 2
  3490. ),
  3491. 'performance_uniform_cache' => array(
  3492. 'hidden' => $this->premium < 2 ? 1 : 0,
  3493. 'value' => $this->compress_options['performance']['uniform_cache'],
  3494. 'type' => 'checkbox',
  3495. 'price' => 3
  3496. ),
  3497. 'performance_restore_properties' => array(
  3498. 'value' => $this->compress_options['performance']['restore_properties'],
  3499. 'type' => 'checkbox',
  3500. 'hidden' => $this->premium < 2 ? 1 : 0,
  3501. 'price' => 1
  3502. ),
  3503. 'performance_delete_old' => array(
  3504. 'hidden' => $this->premium < 2 ? 1 : 0,
  3505. 'value' => $this->compress_options['performance']['delete_old'],
  3506. 'type' => 'smalltext',
  3507. 'price' => 2
  3508. ),
  3509. 'performance_https' => array(
  3510. 'value' => empty($this->compress_options['performance']['https']) ? 0 : 1,
  3511. 'type' => 'checkbox',
  3512. 'hidden' => $this->premium < 2 ? 1 : 0,
  3513. 'price' => 1
  3514. ),
  3515. 'performance_cache_engine' => array(
  3516. 'hidden' => $this->premium < 2 ? 1 : 0,
  3517. 'value' => $this->compress_options['performance']['cache_engine'],
  3518. 'type' => 'radio',
  3519. 'count' => 4,
  3520. 'price' => array(0, 5, 5, 5, 5, 5, 5),
  3521. 'disabled' => array(
  3522. 0,
  3523. !empty($this->restrictions['wss_performance_cache_engine1']),
  3524. !empty($this->restrictions['wss_performance_cache_engine2']),
  3525. !empty($this->restrictions['wss_performance_cache_engine3']),
  3526. !empty($this->restrictions['wss_performance_cache_engine4']),
  3527. !empty($this->restrictions['wss_performance_cache_engine5']),
  3528. )
  3529. ),
  3530. 'performance_cache_engine_options' => array(
  3531. 'hidden' => $this->premium < 2 ? 1 : 0,
  3532. 'value' => empty($this->compress_options['performance']['cache_engine_options']) ? '' : $this->compress_options['performance']['cache_engine_options'],
  3533. 'type' => 'text',
  3534. 'hidden' => 1
  3535. ),
  3536. 'performance_scale' => array(
  3537. 'value' => empty($this->compress_options['performance']['scale']) ? 0 : 1,
  3538. 'type' => 'checkbox',
  3539. 'hidden' => $this->premium < 2 ? 1 : 0,
  3540. 'price' => 3,
  3541. 'disabled' => !empty($this->restrictions['wss_css_sprites_enabled'])
  3542. ),
  3543. 'performance_scale_restriction' => array(
  3544. 'value' => empty($this->compress_options['performance']['scale_restriction']) ? '' : $this->compress_options['performance']['scale_restriction'],
  3545. 'type' => 'text',
  3546. 'hidden' => $this->premium < 2 ? 1 : 0,
  3547. 'price' => 5,
  3548. 'disabled' => !empty($this->restrictions['wss_css_sprites_enabled'])
  3549. ),
  3550. ),
  3551. 'data_uri' => array(
  3552. 'data_uris_on' => array(
  3553. 'value' => $this->compress_options['data_uris']['on'],
  3554. 'type' => 'checkbox',
  3555. 'disabled' => !empty($this->restrictions['wss_css_minify']),
  3556. 'price' => 5
  3557. ),
  3558. 'data_uris_mhtml' => array(
  3559. 'value' => $this->compress_options['data_uris']['mhtml'],
  3560. 'type' => 'checkbox',
  3561. 'disabled' => !empty($this->compress_options['performance']['uniform_cache']) || !empty($this->restrictions['wss_css_minify']),
  3562. 'price' => 5
  3563. ),
  3564. 'data_uris_size' => array(
  3565. 'value' => $this->compress_options['data_uris']['size'],
  3566. 'type' => 'smalltext',
  3567. ),
  3568. 'data_uris_mhtml_size' => array(
  3569. 'value' => $this->compress_options['data_uris']['mhtml_size'],
  3570. 'type' => 'smalltext',
  3571. 'disabled' => !empty($this->compress_options['performance']['uniform_cache']) || !empty($this->restrictions['wss_css_minify'])
  3572. ),
  3573. 'data_uris_ignore_list' => array(
  3574. 'value' => $this->compress_options['data_uris']['ignore_list'],
  3575. 'type' => 'textarea'
  3576. ),
  3577. 'data_uris_additional_list' => array(
  3578. 'value' => $this->compress_options['data_uris']['additional_list'],
  3579. 'type' => 'textarea',
  3580. 'disabled' => !empty($this->compress_options['performance']['uniform_cache']) || !empty($this->restrictions['wss_css_minify'])
  3581. ),
  3582. 'data_uris_separate' => array(
  3583. 'hidden' => $this->premium < 2 ? 1 : 0,
  3584. 'value' => $this->compress_options['data_uris']['separate'],
  3585. 'type' => 'checkbox',
  3586. 'price' => 2,
  3587. 'disabled' => !empty($this->compress_options['performance']['uniform_cache']) || !empty($this->restrictions['wss_css_minify'])
  3588. )
  3589. ),
  3590. 'css_sprites' => array(
  3591. 'premium' => $this->premium < 1 ? 1 : 0,
  3592. 'css_sprites_enabled' => array(
  3593. 'hidden' => $this->premium < 2 ? 1 : 0,
  3594. 'value' => $this->compress_options['css_sprites']['enabled'],
  3595. 'type' => 'checkbox',
  3596. 'disabled' => !empty($this->restrictions['wss_css_sprites_enabled']) || !empty($this->restrictions['wss_css_sprites_tidy']) || !empty($this->restrictions['wss_css_minify']),
  3597. 'price' => 5,
  3598. ),
  3599. 'css_sprites_aggressive' => array(
  3600. 'hidden' => $this->premium < 2 ? 1 : 0,
  3601. 'value' => $this->compress_options['css_sprites']['aggressive'],
  3602. 'type' => 'checkbox',
  3603. 'disabled' => !empty($this->restrictions['wss_css_sprites_enabled']) || !empty($this->restrictions['wss_css_sprites_tidy']) || !empty($this->restrictions['wss_css_minify']),
  3604. 'price' => 2
  3605. ),
  3606. 'css_sprites_no_ie6' => array(
  3607. 'hidden' => $this->premium < 2 ? 1 : 0,
  3608. 'value' => $this->compress_options['css_sprites']['no_ie6'],
  3609. 'type' => 'checkbox',
  3610. 'disabled' => !empty($this->restrictions['wss_css_sprites_enabled']) || !empty($this->restrictions['wss_css_sprites_tidy']) || !empty($this->restrictions['wss_css_minify']),
  3611. 'price' => 2
  3612. ),
  3613. 'css_sprites_dimensions_limited' => array(
  3614. 'hidden' => $this->premium < 2 ? 1 : 0,
  3615. 'value' => $this->compress_options['css_sprites']['dimensions_limited'],
  3616. 'type' => 'smalltext',
  3617. 'disabled' => !empty($this->restrictions['wss_css_sprites_enabled']) || !empty($this->restrictions['wss_css_sprites_tidy']) || !empty($this->restrictions['wss_css_minify'])
  3618. ),
  3619. 'css_sprites_sprites_limited' => array(
  3620. 'hidden' => $this->premium < 2 ? 1 : 0,
  3621. 'value' => empty($this->compress_options['css_sprites']['sprites_limited']) ? '' : $this->compress_options['css_sprites']['sprites_limited'],
  3622. 'type' => 'smalltext',
  3623. 'disabled' => !empty($this->restrictions['wss_css_sprites_enabled'])
  3624. ),
  3625. 'css_sprites_html_sprites' => array(
  3626. 'hidden' => $this->premium < 1 ? 1 : 0,
  3627. 'value' => $this->compress_options['css_sprites']['html_sprites'],
  3628. 'type' => 'checkbox',
  3629. 'disabled' => !empty($this->restrictions['wss_css_sprites_enabled']),
  3630. 'price' => 4
  3631. ),
  3632. 'css_sprites_html_limit' => array(
  3633. 'hidden' => $this->premium < 1 ? 1 : 0,
  3634. 'value' => $this->compress_options['css_sprites']['html_limit'],
  3635. 'type' => 'smalltext',
  3636. 'disabled' => !empty($this->restrictions['wss_css_sprites_enabled'])
  3637. ),
  3638. 'css_sprites_html_page' => array(
  3639. 'hidden' => $this->premium < 1 ? 1 : 0,
  3640. 'value' => $this->compress_options['css_sprites']['html_page'],
  3641. 'type' => 'checkbox',
  3642. 'disabled' => !empty($this->restrictions['wss_css_sprites_enabled']),
  3643. 'price' => 2
  3644. ),
  3645. 'css_sprites_ignore' => array(
  3646. 'hidden' => $this->premium < 1 ? 1 : 0,
  3647. 'value' => empty($this->compress_options['css_sprites']['ignore']) ? 0 : $this->compress_options['css_sprites']['ignore'],
  3648. 'type' => 'radio',
  3649. 'count' => 2,
  3650. 'disabled' => !empty($this->restrictions['wss_css_sprites_enabled'])
  3651. ),
  3652. 'css_sprites_ignore_list' => array(
  3653. 'hidden' => $this->premium < 1 ? 1 : 0,
  3654. 'value' => $this->compress_options['css_sprites']['ignore_list'],
  3655. 'type' => 'textarea',
  3656. 'disabled' => !empty($this->restrictions['wss_css_sprites_enabled'])
  3657. ),
  3658. 'css_sprites_extra_space' => array(
  3659. 'hidden' => $this->premium < 2 ? 1 : 0,
  3660. 'value' => $this->compress_options['css_sprites']['extra_space'],
  3661. 'type' => 'checkbox',
  3662. 'disabled' => !empty($this->restrictions['wss_css_sprites_enabled']) || !empty($this->restrictions['wss_css_sprites_tidy']) || !empty($this->restrictions['wss_css_minify']),
  3663. 'price' => 1
  3664. ),
  3665. 'css_sprites_truecolor_in_jpeg' => array(
  3666. 'hidden' => $this->premium < 2 ? 1 : 0,
  3667. 'value' => $this->compress_options['css_sprites']['truecolor_in_jpeg'],
  3668. 'type' => 'radio',
  3669. 'count' => 2,
  3670. 'disabled' => !empty($this->restrictions['wss_css_sprites_enabled']) || !empty($this->restrictions['wss_css_sprites_tidy']) || !empty($this->restrictions['wss_css_minify']) ? 100 : 0,
  3671. 'price' => array(0, 1)
  3672. ),
  3673. ),
  3674. 'serverside' => array(
  3675. 'premium' => $this->premium < 1 ? 1 : 0,
  3676. 'html_cache_enabled' => array(
  3677. 'hidden' => $this->premium < 1 ? 1 : 0,
  3678. 'value' => $this->compress_options['html_cache']['enabled'],
  3679. 'type' => 'checkbox',
  3680. 'price' => 25
  3681. ),
  3682. 'html_cache_timeout' => array(
  3683. 'hidden' => $this->premium < 1 ? 1 : 0,
  3684. 'value' => $this->compress_options['html_cache']['timeout'],
  3685. 'type' => 'smalltext'
  3686. ),
  3687. 'html_cache_timeout_cart' => array(
  3688. 'hidden' => $this->premium < 2 ? 1 : 0,
  3689. 'value' => empty($this->compress_options['html_cache']['timeout_cart']) ? 0 : $this->compress_options['html_cache']['timeout_cart'],
  3690. 'type' => 'smalltext',
  3691. 'price' => 2
  3692. ),
  3693. 'html_cache_timeout_ajax' => array(
  3694. 'hidden' => $this->premium < 2 ? 1 : 0,
  3695. 'value' => empty($this->compress_options['html_cache']['timeout_ajax']) ? 0 : $this->compress_options['html_cache']['timeout_ajax'],
  3696. 'type' => 'smalltext',
  3697. 'price' => 2
  3698. ),
  3699. 'html_cache_flush_only' => array(
  3700. 'hidden' => $this->premium < 2 ? 1 : 0,
  3701. 'value' => $this->compress_options['html_cache']['flush_only'],
  3702. 'type' => 'checkbox',
  3703. 'price' => 3
  3704. ),
  3705. 'html_cache_flush_size' => array(
  3706. 'hidden' => $this->premium < 2 ? 1 : 0,
  3707. 'value' => $this->compress_options['html_cache']['flush_size'],
  3708. 'type' => 'smalltext'
  3709. ),
  3710. 'html_cache_ignore' => array(
  3711. 'hidden' => $this->premium < 1 ? 1 : 0,
  3712. 'value' => empty($this->compress_options['html_cache']['ignore']) ? 0 : $this->compress_options['html_cache']['ignore'],
  3713. 'type' => 'radio',
  3714. 'count' => 2
  3715. ),
  3716. 'html_cache_ignore_list' => array(
  3717. 'hidden' => $this->premium < 1 ? 1 : 0,
  3718. 'value' => $this->compress_options['html_cache']['ignore_list'],
  3719. 'type' => 'textarea',
  3720. 'price' => 2
  3721. ),
  3722. 'html_cache_allowed_list' => array(
  3723. 'hidden' => $this->premium < 2 ? 1 : 0,
  3724. 'value' => $this->compress_options['html_cache']['allowed_list'],
  3725. 'type' => 'text'
  3726. ),
  3727. 'html_cache_additional_list' => array(
  3728. 'hidden' => $this->premium < 2 ? 1 : 0,
  3729. 'value' => $this->compress_options['html_cache']['additional_list'],
  3730. 'type' => 'text',
  3731. 'price' => 3
  3732. ),
  3733. 'html_cache_params' => array(
  3734. 'hidden' => $this->premium < 2 ? 1 : 0,
  3735. 'value' => empty($this->compress_options['html_cache']['params']) ? '' : $this->compress_options['html_cache']['params'],
  3736. 'type' => 'text',
  3737. 'price' => 2
  3738. ),
  3739. 'html_cache_enhanced' => array(
  3740. 'hidden' => $this->premium < 2 ? 1 : 0,
  3741. 'value' => $this->compress_options['html_cache']['enhanced'],
  3742. 'type' => 'checkbox',
  3743. 'price' => 3,
  3744. 'disabled' => !empty($this->restrictions['wss_htaccess_mod_rewrite'])
  3745. ),
  3746. 'html_cache_cleanup' => array(
  3747. 'hidden' => $this->premium < 2 ? 1 : 0,
  3748. 'value' => empty($this->compress_options['html_cache']['cleanup']) ? 0 : 1,
  3749. 'type' => 'checkbox',
  3750. 'price' => 2
  3751. )
  3752. ),
  3753. 'sqlcache' => array(
  3754. 'premium' => $this->premium < 2 ? 1 : 0,
  3755. 'sql_cache_enabled' => array(
  3756. 'hidden' => $this->premium < 2 ? 1 : 0,
  3757. 'value' => empty($this->compress_options['sql_cache']['enabled']) ? 0 : 1,
  3758. 'type' => 'checkbox',
  3759. 'price' => 12,
  3760. 'disabled' => empty($this->internal_sql)
  3761. ),
  3762. 'sql_cache_time' => array(
  3763. 'hidden' => $this->premium < 2 ? 1 : 0,
  3764. 'value' => empty($this->compress_options['sql_cache']['time']) ? 0 : $this->compress_options['sql_cache']['time'],
  3765. 'type' => 'smalltext',
  3766. 'disabled' => empty($this->internal_sql)
  3767. ),
  3768. 'sql_cache_timeout' => array(
  3769. 'hidden' => $this->premium < 2 ? 1 : 0,
  3770. 'value' => empty($this->compress_options['sql_cache']['timeout']) ? 0 : $this->compress_options['sql_cache']['timeout'],
  3771. 'type' => 'smalltext',
  3772. 'disabled' => empty($this->internal_sql)
  3773. ),
  3774. 'sql_cache_tables_exclude' => array(
  3775. 'hidden' => $this->premium < 2 ? 1 : 0,
  3776. 'value' => empty($this->compress_options['sql_cache']['tables_exclude']) ? '' : $this->compress_options['sql_cache']['tables_exclude'],
  3777. 'type' => 'textarea',
  3778. 'disabled' => empty($this->internal_sql)
  3779. )
  3780. ),
  3781. 'unobtrusive' => array(
  3782. 'premium' => $this->premium < 1 ? 1 : 0,
  3783. 'unobtrusive_on' => array(
  3784. 'hidden' => $this->premium < 2 ? 1 : 0,
  3785. 'value' => $this->compress_options['unobtrusive']['on'],
  3786. 'type' => 'radio',
  3787. 'count' => 3,
  3788. 'price' => array(0,5,5)
  3789. ),
  3790. 'unobtrusive_body' => array(
  3791. 'hidden' => $this->premium < 1 ? 1 : 0,
  3792. 'value' => $this->compress_options['unobtrusive']['body'],
  3793. 'type' => 'checkbox',
  3794. 'price' => 2
  3795. ),
  3796. 'unobtrusive_all' => array(
  3797. 'hidden' => $this->premium < 1 ? 1 : 0,
  3798. 'value' => $this->compress_options['unobtrusive']['all'],
  3799. 'type' => 'checkbox',
  3800. 'price' => 2
  3801. ),
  3802. 'unobtrusive_informers' => array(
  3803. 'value' => $this->compress_options['unobtrusive']['informers'],
  3804. 'type' => 'checkbox',
  3805. 'hidden' => $this->premium < 2 ? 1 : 0,
  3806. 'price' => 3
  3807. ),
  3808. 'unobtrusive_counters' => array(
  3809. 'value' => $this->compress_options['unobtrusive']['counters'],
  3810. 'type' => 'checkbox',
  3811. 'hidden' => $this->premium < 2 ? 1 : 0,
  3812. 'price' => 2
  3813. ),
  3814. 'unobtrusive_ads' => array(
  3815. 'value' => $this->compress_options['unobtrusive']['ads'],
  3816. 'type' => 'checkbox',
  3817. 'hidden' => $this->premium < 2 ? 1 : 0,
  3818. 'price' => 3
  3819. ),
  3820. 'unobtrusive_iframes' => array(
  3821. 'value' => $this->compress_options['unobtrusive']['iframes'],
  3822. 'type' => 'checkbox',
  3823. 'hidden' => $this->premium < 2 ? 1 : 0,
  3824. 'price' => 3
  3825. ),
  3826. 'unobtrusive_background' => array(
  3827. 'value' => empty($this->compress_options['unobtrusive']['background']) ? 0 : 1,
  3828. 'type' => 'checkbox',
  3829. 'hidden' => $this->premium < 2 ? 1 : 0,
  3830. 'price' => 2
  3831. ),
  3832. 'unobtrusive_configuration' => array(
  3833. 'value' => empty($this->compress_options['unobtrusive']['configuration']) ? '' : $this->compress_options['unobtrusive']['configuration'],
  3834. 'type' => 'text',
  3835. 'hidden' => $this->premium < 2 ? 1 : 0,
  3836. 'price' => 5
  3837. ),
  3838. 'unobtrusive_postload' => array(
  3839. 'value' => empty($this->compress_options['unobtrusive']['postload']) ? '' : $this->compress_options['unobtrusive']['postload'],
  3840. 'type' => 'textarea',
  3841. 'hidden' => $this->premium < 2 ? 1 : 0,
  3842. 'price' => 5
  3843. ),
  3844. 'unobtrusive_frames' => array(
  3845. 'value' => empty($this->compress_options['unobtrusive']['frames']) ? '' : $this->compress_options['unobtrusive']['frames'],
  3846. 'type' => 'textarea',
  3847. 'hidden' => $this->premium < 2 ? 1 : 0,
  3848. 'price' => 5
  3849. ),
  3850. ),
  3851. 'multiple_hosts' => array(
  3852. 'parallel_enabled' => array(
  3853. 'value' => $this->compress_options['parallel']['enabled'],
  3854. 'type' => 'checkbox',
  3855. 'price' => 3
  3856. ),
  3857. 'parallel_regexp' => array(
  3858. 'value' => empty($this->compress_options['parallel']['regexp']) ? '' : $this->compress_options['parallel']['regexp'],
  3859. 'type' => 'text',
  3860. 'hidden' => $this->premium < 2 ? 1 : 0,
  3861. 'price' => 5
  3862. ),
  3863. 'parallel_check' => array(
  3864. 'hidden' => $this->premium < 1 ? 1 : 0,
  3865. 'value' => $this->compress_options['parallel']['check'],
  3866. 'type' => 'checkbox'
  3867. ),
  3868. 'parallel_allowed_list' => array(
  3869. 'value' => $this->compress_options['parallel']['allowed_list'],
  3870. 'type' => 'text'
  3871. ),
  3872. 'parallel_css' => array(
  3873. 'value' => $this->compress_options['parallel']['css'],
  3874. 'type' => 'checkbox',
  3875. 'price' => 2
  3876. ),
  3877. 'parallel_javascript' => array(
  3878. 'value' => $this->compress_options['parallel']['javascript'],
  3879. 'type' => 'checkbox',
  3880. 'price' => 2,
  3881. 'onclick' => '_.u(this)',
  3882. ),
  3883. 'parallel_additional' => array(
  3884. 'value' => $this->compress_options['parallel']['additional'],
  3885. 'type' => 'textarea',
  3886. 'hidden' => 1
  3887. ),
  3888. 'parallel_additional_list' => array(
  3889. 'value' => $this->compress_options['parallel']['additional_list'],
  3890. 'type' => 'textarea',
  3891. 'hidden' => 1
  3892. ),
  3893. 'parallel_ignore_list' => array(
  3894. 'value' => $this->compress_options['parallel']['ignore_list'],
  3895. 'type' => 'textarea',
  3896. 'price' => 1
  3897. ),
  3898. 'parallel_custom' => array(
  3899. 'value' => $this->compress_options['parallel']['custom'],
  3900. 'type' => 'radio',
  3901. 'count' => 3,
  3902. 'price' => 1
  3903. ),
  3904. 'parallel_ftp' => array(
  3905. 'hidden' => $this->premium < 1 ? 1 : 0,
  3906. 'value' => $this->compress_options['parallel']['ftp'],
  3907. 'type' => 'text',
  3908. 'price' => 2
  3909. ),
  3910. 'parallel_https' => array(
  3911. 'hidden' => $this->premium < 2 ? 1 : 0,
  3912. 'value' => $this->compress_options['parallel']['https'],
  3913. 'type' => 'text',
  3914. 'price' => 5
  3915. ),
  3916. ),
  3917. 'rocket' => array(
  3918. 'rocket_css' => array(
  3919. 'value' => empty($this->compress_options['rocket']['css']) ? 0 : 1,
  3920. 'type' => 'checkbox'
  3921. ),
  3922. 'rocket_javascript' => array(
  3923. 'value' => empty($this->compress_options['rocket']['javascript']) ? 0 : 1,
  3924. 'type' => 'checkbox'
  3925. ),
  3926. 'rocket_reorder' => array(
  3927. 'value' => empty($this->compress_options['rocket']['reorder']) ? 0 : 1,
  3928. 'type' => 'checkbox'
  3929. ),
  3930. )
  3931. );
  3932. if (empty($options['title'])) {
  3933. $options['title'] = constant('_WEBO_OPTIONS_TITLES_' . $config);
  3934. }
  3935. if (empty($options['description'])) {
  3936. $options['description'] = constant('_WEBO_OPTIONS_DESCRIPTIONS_' . $config);
  3937. }
  3938. $fee = 0;
  3939. /* calculate current options' fee */
  3940. foreach ($options as $key => $group) {
  3941. if (is_array($group)) {
  3942. foreach ($group as $option) {
  3943. if (!empty($option['price']) && $option['value']) {
  3944. $fee += is_array($option['price']) ?
  3945. $option['price'][$option['value']] : $option['price'];
  3946. }
  3947. }
  3948. }
  3949. }
  3950. $options['fee'] = $fee;
  3951. return $options;
  3952. }
  3953. /**
  3954. * Check for possible restrictions for options
  3955. *
  3956. **/
  3957. function check_options() {
  3958. if (!empty($this->restrictions)) {
  3959. return $this->restrictions;
  3960. }
  3961. $this->restrictions = array();
  3962. /* normalize all the other options */
  3963. $this->get_modules();
  3964. /* disable .htaccess if not Apache */
  3965. if (empty($this->apache_modules)) {
  3966. $this->restrictions['wss_htaccess_enabled'] = 1;
  3967. $this->restrictions['wss_htaccess_mod_deflate'] = 1;
  3968. $this->restrictions['wss_htaccess_mod_gzip'] = 1;
  3969. $this->restrictions['wss_htaccess_mod_expires'] = 1;
  3970. $this->restrictions['wss_htaccess_mod_mime'] = 1;
  3971. $this->restrictions['wss_htaccess_mod_headers'] = 1;
  3972. $this->restrictions['wss_htaccess_mod_setenvif'] = 1;
  3973. $this->restrictions['wss_htaccess_mod_rewrite'] = 1;
  3974. } else {
  3975. foreach (array(
  3976. 'mod_deflate',
  3977. 'mod_gzip',
  3978. 'mod_expires',
  3979. 'mod_mime',
  3980. 'mod_headers',
  3981. 'mod_setenvif',
  3982. 'mod_rewrite') as $module) {
  3983. if (!in_array($module, $this->apache_modules)) {
  3984. $this->restrictions['wss_htaccess_' . $module] = 1;
  3985. }
  3986. }
  3987. }
  3988. /* for IIS we can use web.config */
  3989. if ($this->iis) {
  3990. unset($this->restrictions['wss_htaccess_enabled']);
  3991. unset($this->restrictions['wss_htaccess_mod_gzip']);
  3992. unset($this->restrictions['wss_htaccess_mod_expires']);
  3993. unset($this->restrictions['wss_htaccess_mod_rewrite']);
  3994. }
  3995. $this->loaded_modules = @get_loaded_extensions();
  3996. /* fix CSS Sprites options in case of GD lib failure */
  3997. $gd = function_exists('gd_info') ? gd_info() : array();
  3998. if (!(in_array('gd', $this->loaded_modules) &&
  3999. function_exists('imagecreatetruecolor') ||
  4000. (!empty($gd['GIF Read Support']) &&
  4001. !empty($gd['GIF Create Support']) &&
  4002. (!empty($gd['JPEG Support']) || !empty($gd['JPG Support'])) &&
  4003. !empty($gd['PNG Support']) &&
  4004. !empty($gd['WBMP Support'])))) {
  4005. $this->restrictions['wss_css_sprites_enabled'] = 1;
  4006. }
  4007. /* Disable CSS Sprites if no CSS Tidy is used */
  4008. if (isset($this->compress_options['minify']['css_min']) &&
  4009. $this->compress_options['minify']['css_min'] != 2 &&
  4010. (!isset($this->input['wss_minify_css_min']) ||
  4011. $this->input['wss_minify_css_min'] != 2)) {
  4012. $this->restrictions['wss_css_sprites_tidy'] = 1;
  4013. }
  4014. /* Disable CSS Sprites and data:URI if no CSS minify is used */
  4015. $this->restrictions['wss_css_minify'] = (empty($this->compress_options['minify']['css']) && !isset($this->input['wss_minify_css'])) ||
  4016. (isset($this->input['wss_minify_css']) && empty($this->input['wss_minify_css']));
  4017. /* check for YUI&Google availability */
  4018. $YUI_checked = 0;
  4019. $Google_checked = 0;
  4020. if (!$this->iis) {
  4021. if (@is_file($this->basepath . 'libs/php/class.yuicompressor.php')) {
  4022. require_once($this->basepath . 'libs/php/class.yuicompressor.php');
  4023. $YUI = new YuiCompressor($this->compress_options['javascript_cachedir'], $this->basepath);
  4024. $YUI_checked = $YUI->check();
  4025. }
  4026. if (@is_file($this->basepath . 'libs/php/class.googlecompiler.php')) {
  4027. require_once($this->basepath . 'libs/php/class.googlecompiler.php');
  4028. $Google = new GoogleCompiler($this->compress_options['javascript_cachedir'], $this->basepath);
  4029. $Google_checked = $Google->check();
  4030. }
  4031. }
  4032. if (!$YUI_checked) {
  4033. $this->restrictions['wss_minify_js2'] = 1;
  4034. }
  4035. if (!$Google_checked) {
  4036. $this->restrictions['wss_minify_js4'] = 1;
  4037. }
  4038. /* check for curl existence */
  4039. if (empty($this->loaded_modules) ||
  4040. !in_array('curl', $this->loaded_modules) ||
  4041. !function_exists('curl_init')) {
  4042. $this->restrictions['wss_external_scripts_on'] = 1;
  4043. $this->restrictions['wss_external_scripts_css'] = 1;
  4044. }
  4045. /* check for gzip for HTML possibility */
  4046. if ((!function_exists('gzencode') ||
  4047. !function_exists('gzcompress') ||
  4048. !function_exists('gzdeflate')) &&
  4049. !(!empty($this->input['wss_htaccess_enabled']) &&
  4050. (!empty($this->input['wss_htaccess_mod_deflate']) ||
  4051. !empty($this->input['wss_htaccess_mod_gzip'])))) {
  4052. $this->restrictions['wss_gzip_page'] = 1;
  4053. }
  4054. /* check for gzip for fonts possibility */
  4055. if (!(!empty($this->input['wss_htaccess_enabled']) &&
  4056. (!empty($this->input['wss_htaccess_mod_deflate']) ||
  4057. !empty($this->input['wss_htaccess_mod_gzip']) ||
  4058. !empty($this->input['wss_htaccess_mod_rewrite'])))) {
  4059. $this->restrictions['wss_gzip_fonts'] = 1;
  4060. }
  4061. /* check for zlib possibility */
  4062. if (!strlen(@ini_get("zlib.output_compression_level"))) {
  4063. $this->restrictions['wss_gzip_zlib'] = 1;
  4064. }
  4065. /* check for caching extensions */
  4066. if (!@class_exists('Memcached') && !@class_exists('Memcache')) {
  4067. $this->restrictions['wss_performance_cache_engine1'] = 1;
  4068. }
  4069. if (!@function_exists('apc_store')) {
  4070. $this->restrictions['wss_performance_cache_engine2'] = 1;
  4071. }
  4072. if (!@function_exists('xcache_set')) {
  4073. $this->restrictions['wss_performance_cache_engine3'] = 1;
  4074. }
  4075. if (!@function_exists('zend_shm_cache_store')) {
  4076. $this->restrictions['wss_performance_cache_engine4'] = 1;
  4077. }
  4078. if (!@function_exists('sem_get')) {
  4079. $this->restrictions['wss_performance_cache_engine5'] = 1;
  4080. }
  4081. }
  4082. /**
  4083. * Save / sanitize all options
  4084. *
  4085. **/
  4086. function set_options() {
  4087. /* fix multiple lines in textarea */
  4088. foreach (array(
  4089. 'wss_unobtrusive_postload',
  4090. 'wss_unobtrusive_frames',
  4091. 'wss_unobtrusive_configuration',
  4092. 'wss_minify_css_file',
  4093. 'wss_minify_css_host',
  4094. 'wss_minify_javascript_file',
  4095. 'wss_minify_javascript_host',
  4096. 'wss_external_scripts_include_code',
  4097. 'wss_external_scripts_ignore_list',
  4098. 'wss_external_scripts_additional_list',
  4099. 'wss_external_scripts_minify_exclude',
  4100. 'wss_external_scripts_include_mask',
  4101. 'wss_performance_cache_engine_options',
  4102. 'wss_footer_image',
  4103. 'wss_footer_link',
  4104. 'wss_footer_css_code',
  4105. 'wss_footer_counter',
  4106. 'wss_data_uris_ignore_list',
  4107. 'wss_data_uris_additional_list',
  4108. 'wss_css_sprites_ignore_list',
  4109. 'wss_html_cache_ignore_list',
  4110. 'wss_html_cache_allowed_list',
  4111. 'wss_html_cache_additional_list',
  4112. 'wss_html_cache_params',
  4113. 'wss_sql_cache_tables_exclude',
  4114. 'wss_parallel_regexp',
  4115. 'wss_parallel_allowed_list',
  4116. 'wss_parallel_additional',
  4117. 'wss_parallel_additional_list',
  4118. 'wss_parallel_ignore_list',
  4119. 'wss_parallel_ftp',
  4120. 'wss_parallel_https',
  4121. 'wss_description',
  4122. 'wss_title',
  4123. 'wss_config') as $val) {
  4124. $this->input[$val] = trim(str_replace(array("\r\n", "\n", '/"', '"'), array(" ", " ", "&quot;", "&quot;"),
  4125. !isset($this->input[$val]) ? '' : $this->input[$val]));
  4126. }
  4127. /* leave only 1 value (before space) */
  4128. foreach (array(
  4129. 'wss_minify_css_file',
  4130. 'wss_minify_css_host',
  4131. 'wss_minify_javascript_file',
  4132. 'wss_minify_javascript_host',
  4133. 'wss_external_scripts_remove_list',
  4134. 'wss_external_scripts_remove_list_css',
  4135. 'wss_performance_scale_restriction',
  4136. 'wss_footer_counter',
  4137. 'wss_parallel_ftp',
  4138. 'wss_parallel_https',
  4139. 'wss_config') as $val) {
  4140. if ($this->input[$val]) {
  4141. $this->input[$val] = preg_replace("![\s\t\r\n].*!is", "", trim($this->input[$val]));
  4142. }
  4143. }
  4144. /* make numeric options save */
  4145. foreach (array(
  4146. 'wss_combine_css',
  4147. 'wss_minify_css_min',
  4148. 'wss_minify_js',
  4149. 'wss_unobtrusive_on',
  4150. 'wss_performance_cache_version',
  4151. 'wss_performance_delete_old',
  4152. 'wss_performance_cache_engine',
  4153. 'wss_far_future_expires_html_timeout',
  4154. 'wss_html_cache_timeout',
  4155. 'wss_html_cache_timeout_cart',
  4156. 'wss_html_cache_timeout_ajax',
  4157. 'wss_html_cache_flush_size',
  4158. 'wss_html_cache_ignore',
  4159. 'wss_sql_cache_time',
  4160. 'wss_sql_cache_timeout',
  4161. 'wss_footer_ab',
  4162. 'wss_data_uris_size',
  4163. 'wss_data_uris_mhtml_size',
  4164. 'wss_css_sprites_dimensions_limited',
  4165. 'wss_css_sprites_sprites_limited',
  4166. 'wss_css_sprites_truecolor_in_jpeg',
  4167. 'wss_css_sprites_html_limit',
  4168. 'wss_parallel_custom',
  4169. 'wss_fee') as $val) {
  4170. $this->input[$val] = empty($this->input[$val]) ? 0 : round($this->input[$val]);
  4171. }
  4172. /* normalize values for radio buttons */
  4173. foreach (array(
  4174. 'wss_performance_cache_engine',
  4175. 'wss_css_sprites_truecolor_in_jpeg',
  4176. 'wss_html_cache_ignore',
  4177. 'wss_css_sprites_ignore',
  4178. 'wss_parallel_custom',
  4179. 'wss_unobtrusive_on',
  4180. 'wss_minify_css_min') as $val) {
  4181. if ($this->input[$val]) {
  4182. $this->input[$val]--;
  4183. }
  4184. }
  4185. /* disable don't check files in cache */
  4186. $this->input['wss_performance_cache_version'] =
  4187. empty($this->input['wss_performance_check_files']) ? 0 :
  4188. $this->input['wss_performance_cache_version'];
  4189. foreach (array(
  4190. 'wss_unobtrusive_body',
  4191. 'wss_unobtrusive_all',
  4192. 'wss_unobtrusive_informers',
  4193. 'wss_unobtrusive_ads',
  4194. 'wss_unobtrusive_counters',
  4195. 'wss_unobtrusive_iframes',
  4196. 'wss_unobtrusive_background',
  4197. 'wss_external_scripts_on',
  4198. 'wss_external_scripts_inline',
  4199. 'wss_external_scripts_inline_body',
  4200. 'wss_external_scripts_head_end',
  4201. 'wss_external_scripts_css',
  4202. 'wss_external_scripts_css_inline',
  4203. 'wss_external_scripts_include_try',
  4204. 'wss_external_scripts_duplicates',
  4205. 'wss_minify_javascript',
  4206. 'wss_minify_javascript_body',
  4207. 'wss_performance_mtime',
  4208. 'wss_performance_plain_string',
  4209. 'wss_performance_cache_version',
  4210. 'wss_performance_uniform_cache',
  4211. 'wss_performance_restore_properties',
  4212. 'wss_performance_https',
  4213. 'wss_performance_scale',
  4214. 'wss_minify_page',
  4215. 'wss_minify_html_comments',
  4216. 'wss_minify_html_one_string',
  4217. 'wss_gzip_javascript',
  4218. 'wss_gzip_page',
  4219. 'wss_gzip_css',
  4220. 'wss_gzip_fonts',
  4221. 'wss_gzip_zlib',
  4222. 'wss_gzip_cookie',
  4223. 'wss_gzip_noie',
  4224. 'wss_far_future_expires_javascript',
  4225. 'wss_far_future_expires_css',
  4226. 'wss_far_future_expires_images',
  4227. 'wss_far_future_expires_fonts',
  4228. 'wss_far_future_expires_video',
  4229. 'wss_far_future_expires_static',
  4230. 'wss_far_future_expires_html',
  4231. 'wss_far_future_expires_external',
  4232. 'wss_html_cache_enabled',
  4233. 'wss_html_cache_flush_only',
  4234. 'wss_html_cache_enhanced',
  4235. 'wss_html_cache_cleanup',
  4236. 'wss_sql_cache_enabled',
  4237. 'wss_footer_text',
  4238. 'wss_footer_spot',
  4239. 'wss_data_uris_on',
  4240. 'wss_data_uris_separate',
  4241. 'wss_data_uris_mhtml',
  4242. 'wss_css_sprites_enabled',
  4243. 'wss_css_sprites_aggressive',
  4244. 'wss_css_sprites_extra_space',
  4245. 'wss_css_sprites_ignore',
  4246. 'wss_css_sprites_no_ie6',
  4247. 'wss_css_sprites_html_sprites',
  4248. 'wss_css_sprites_html_page',
  4249. 'wss_parallel_enabled',
  4250. 'wss_parallel_check',
  4251. 'wss_parallel_css',
  4252. 'wss_parallel_javascript',
  4253. 'wss_htaccess_enabled',
  4254. 'wss_htaccess_mod_deflate',
  4255. 'wss_htaccess_mod_gzip',
  4256. 'wss_htaccess_mod_expires',
  4257. 'wss_htaccess_mod_headers',
  4258. 'wss_htaccess_mod_setenvif',
  4259. 'wss_htaccess_mod_rewrite',
  4260. 'wss_htaccess_mod_mime',
  4261. 'wss_htaccess_local',
  4262. 'wss_rocket_css',
  4263. 'wss_rocket_javascript',
  4264. 'wss_rocket_reorder') as $val) {
  4265. $this->input[$val] = empty($this->input[$val]) ? 0 : 1;
  4266. }
  4267. $this->check_options();
  4268. foreach ($this->restrictions as $key => $restriction) {
  4269. $this->input[$key] = 0;
  4270. }
  4271. /* make specific fake option for Apache envs. */
  4272. $this->input['wss_htaccess_mod_symlinks'] = in_array('mod_symlinks', $this->apache_modules);
  4273. /* correct multiple hosts list */
  4274. if (!empty($this->input['wss_parallel_check'])) {
  4275. $hosts = explode(" ", $this->input['wss_parallel_allowed_list']);
  4276. $this->input['wss_parallel_allowed_list'] = $this->check_hosts($hosts);
  4277. }
  4278. /* exclude original host from distribution */
  4279. if (!empty($this->input['wss_parallel_allowed_list'])) {
  4280. $arr = explode(" ", $this->input['wss_parallel_allowed_list']);
  4281. foreach ($arr as $k => $a) {
  4282. if (empty($a) || $a == $this->compress_options['host']) {
  4283. unset($arr[$k]);
  4284. }
  4285. }
  4286. $this->input['wss_parallel_allowed_list'] = implode(" ", $arr);
  4287. if (empty($this->input['wss_parallel_allowed_list'])) {
  4288. $this->input['wss_parallel_enabled'] = 0;
  4289. }
  4290. }
  4291. /* map CSS merge options to real one */
  4292. switch ($this->input['wss_combine_css']) {
  4293. case 3:
  4294. $this->input['wss_minify_css'] = 1;
  4295. $this->input['wss_minify_css_body'] = 1;
  4296. break;
  4297. case 2:
  4298. $this->input['wss_minify_css'] = 1;
  4299. $this->input['wss_minify_css_body'] = 0;
  4300. break;
  4301. default:
  4302. $this->input['wss_minify_css'] = 0;
  4303. $this->input['wss_minify_css_body'] = 0;
  4304. break;
  4305. }
  4306. /* map JavaScript minify options to real one */
  4307. switch ($this->input['wss_minify_js']) {
  4308. case 5:
  4309. $this->input['wss_minify_with_google'] = 1;
  4310. $this->input['wss_minify_with_jsmin'] = 0;
  4311. $this->input['wss_minify_with_yui'] = 0;
  4312. $this->input['wss_minify_with_packer'] = 0;
  4313. break;
  4314. case 4:
  4315. $this->input['wss_minify_with_google'] = 0;
  4316. $this->input['wss_minify_with_jsmin'] = 0;
  4317. $this->input['wss_minify_with_yui'] = 0;
  4318. $this->input['wss_minify_with_packer'] = 1;
  4319. break;
  4320. case 3:
  4321. $this->input['wss_minify_with_google'] = 0;
  4322. $this->input['wss_minify_with_jsmin'] = 0;
  4323. $this->input['wss_minify_with_yui'] = 1;
  4324. $this->input['wss_minify_with_packer'] = 0;
  4325. break;
  4326. case 2:
  4327. $this->input['wss_minify_with_google'] = 0;
  4328. $this->input['wss_minify_with_jsmin'] = 1;
  4329. $this->input['wss_minify_with_yui'] = 0;
  4330. $this->input['wss_minify_with_packer'] = 0;
  4331. break;
  4332. default:
  4333. $this->input['wss_minify_with_google'] = 0;
  4334. $this->input['wss_minify_with_jsmin'] = 0;
  4335. $this->input['wss_minify_with_yui'] = 0;
  4336. $this->input['wss_minify_with_packer'] = 0;
  4337. break;
  4338. }
  4339. $image = $this->input['wss_footer_image'];
  4340. if (!empty($image)) {
  4341. @copy($this->basepath . 'images/' . $image,
  4342. $this->compress_options['css_cachedir'] . $image);
  4343. }
  4344. if (!empty($this->input['wss_parallel_ftp'])) {
  4345. $this->check_cdn();
  4346. }
  4347. if (!empty($this->input['wss_page']) && $this->input['wss_page'] == 'install_options') {
  4348. /* Try to re-define configuration name from predefined set */
  4349. if (empty($this->input['wss_apply'])) {
  4350. if (in_array($this->input['wss_config'], array('safe', 'optimal', 'extreme', 'basic'))) {
  4351. if (@is_file($this->basepath . 'config.user.php')) {
  4352. $i = 1;
  4353. while (@is_file($this->basepath . 'config.user'. ($i++) .'.php')) {}
  4354. $this->input['wss_config'] = 'user' . ($i - 1);
  4355. } else {
  4356. $this->input['wss_config'] = 'user';
  4357. }
  4358. }
  4359. }
  4360. /* Apply options or just save them? */
  4361. if (!empty($this->input['wss_apply']) ||
  4362. ($this->input['wss_config'] == $this->compress_options['config'])) {
  4363. /* Save the options to work config */
  4364. $this->save_options(1);
  4365. /* re-check grade if application is active */
  4366. if (!empty($this->compress_options['active']) && $this->premium > 1 && !empty($this->compress_options['website_root'])) {
  4367. @unlink($this->basepath . $this->index_after);
  4368. $this->view->download($this->webo_grade, $this->basepath . $this->index_after, 1);
  4369. }
  4370. }
  4371. /* Save the options to backup config */
  4372. if (!empty($this->input['wss_config']) &&
  4373. (strpos($this->input['wss_config'], 'user') !== false ||
  4374. strpos($this->input['wss_config'], 'auto') !== false)) {
  4375. $this->options_file_backup = $this->options_file;
  4376. $this->options_file = 'config.' .
  4377. preg_replace("/[^a-zA-Z0-9]*/", "",
  4378. $this->input['wss_config']) . '.php';
  4379. if (!@is_file($this->basepath . $this->options_file)) {
  4380. @copy($this->basepath . 'config.safe.php',
  4381. $this->basepath . $this->options_file);
  4382. @chmod($this->basepath . $this->options_file,
  4383. octdec("0644"));
  4384. }
  4385. $this->save_option("['title']",
  4386. $this->input['wss_title']);
  4387. $this->save_option("['description']",
  4388. $this->input['wss_description']);
  4389. $this->save_options(1);
  4390. $this->options_file = $this->options_file_backup;
  4391. /* can't create new config file */
  4392. if (!empty($this->error[0])) {
  4393. $this->save_option("['config']", 'safe');
  4394. }
  4395. }
  4396. }
  4397. }
  4398. /**
  4399. * Checks FTP / API access to remote CDN host
  4400. **/
  4401. function check_cdn () {
  4402. $this->error = $this->error ? $this->error : array();
  4403. $auth = $this->input['wss_parallel_ftp'];
  4404. /* Rack Space Cloud */
  4405. if ($last = strpos($auth, '@RSC')) {
  4406. $first = strpos($auth, ':');
  4407. $user = substr($auth, 0, $first);
  4408. $key = substr($auth, $first + 1, $last - $first - 1);
  4409. /* perform authorization */
  4410. $headers = $this->view->upload('https://auth.api.rackspacecloud.com/v1.0',
  4411. '', $this->options['html_cachedir'],
  4412. array('X-Auth-User: ' . $user, 'X-Auth-Key: ' . $key));
  4413. if (strpos($headers, 'Error: ') === false && strpos($headers, 'HTTP/1.1 401') === false) {
  4414. $token = preg_replace("@.*X-Auth-Token: (.*?)\r?\n.*@is", "$1", $headers);
  4415. /* create wo container */
  4416. $this->view->upload(preg_replace("@.*X-Storage-Url: (.*?)\r?\n.*@is", "$1", $headers) . '/wo',
  4417. '', $this->options['html_cachedir'],
  4418. array('X-Auth-Token: ' . $token, 'X-Referrer-ACL: 259200'), 'PUT');
  4419. /* remember current CDN URL */
  4420. $headers = $this->view->upload(preg_replace("@.*X-CDN-Management-Url: (.*?)\r?\n.*@is", "$1", $headers) . '/wo',
  4421. '', $this->options['html_cachedir'],
  4422. array('X-Auth-Token: ' . $token, 'X-Referrer-ACL: 259200'), 'HEAD');
  4423. if (strpos($headers, 'Error: ') === false) {
  4424. $cdn = preg_replace("@.*X-CDN-URI: https?://(.*?)\r?\n.*@is", "$1", $headers);
  4425. if (!$this->input['wss_minify_css_host']) {
  4426. $this->input['wss_minify_css_host'] = $cdn;
  4427. }
  4428. if (!$this->input['wss_minify_javascript_host']) {
  4429. $this->input['wss_minify_javascript_host'] = $cdn;
  4430. }
  4431. } else {
  4432. $this->error[11] = 1;
  4433. }
  4434. } else {
  4435. $this->error[11] = 1;
  4436. }
  4437. /* common FTP */
  4438. } else {
  4439. $file = @is_file($this->options['document_root'] . 'favicon.ico') ?
  4440. $this->options['document_root'] . 'favicon.ico' :
  4441. $this->basepath . 'favicon.ico';
  4442. $headers = $this->view->upload('ftp://' .
  4443. preg_replace("!^([^@]+)@([^:]+):([^@]+)@!", "$1:$3@", $auth) .
  4444. str_replace($this->options['document_root'], "/", $file),
  4445. $file, $this->options['html_cachedir'], array(), 'PUT',
  4446. preg_replace("!(.*)@.*!", "$1", $auth));
  4447. if (strpos($headers, 'Error: ') !== false) {
  4448. $this->error[11] = 1;
  4449. }
  4450. }
  4451. }
  4452. /**
  4453. * Checks and writes all optimized rules to web.config file
  4454. **/
  4455. function write_webconfig ($base = '/', $content_saved) {
  4456. $content = "<!-- Web Optimizer options -->";
  4457. /* rules for gzip */
  4458. if (!empty($this->input['wss_htaccess_mod_gzip']) && empty($this->input['wss_footer_ab'])) {
  4459. $types = '';
  4460. if (!empty($this->input['wss_gzip_page'])) {
  4461. $types .="
  4462. <add mimeType=\"text/html\" enabled=\"true\" />
  4463. <add mimeType=\"text/xml\" enabled=\"true\" />
  4464. <add mimeType=\"text/plain\" enabled=\"true\" />
  4465. <add mimeType=\"text/richtext\" enabled=\"true\" />
  4466. <add mimeType=\"text/xsd\" enabled=\"true\" />
  4467. <add mimeType=\"text/xsl\" enabled=\"true\" />
  4468. <add mimeType=\"message/*\" enabled=\"true\" />
  4469. <add mimeType=\"application/json\" enabled=\"true\" />
  4470. <add mimeType=\"application/xhtml+xml\" enabled=\"true\" />
  4471. <add mimeType=\"text/x-component\" enabled=\"true\" />
  4472. <add mimeType=\"image/x-icon\" enabled=\"true\" />";
  4473. }
  4474. if (!empty($this->input['wss_gzip_css'])) {
  4475. $types .="
  4476. <add mimeType=\"text/css\" enabled=\"true\" />";
  4477. }
  4478. if (!empty($this->input['wss_gzip_javascript'])) {
  4479. $types .="
  4480. <add mimeType=\"text/javascript\" enabled=\"true\" />
  4481. <add mimeType=\"text/x-js\" enabled=\"true\" />
  4482. <add mimeType=\"text/ecmascript\" enabled=\"true\" />
  4483. <add mimeType=\"text/vbscript\" enabled=\"true\" />
  4484. <add mimeType=\"text/fluffscript\" enabled=\"true\" />
  4485. <add mimeType=\"application/x-javascript\" enabled=\"true\" />
  4486. <add mimeType=\"application/javascript\" enabled=\"true\" />
  4487. <add mimeType=\"application/ecmascript\" enabled=\"true\" />
  4488. <add mimeType=\"application/json\" enabled=\"true\" />";
  4489. }
  4490. if (!empty($this->input['wss_gzip_font'])) {
  4491. $types .="
  4492. <add mimeType=\"font/*\" enabled=\"true\" />
  4493. <add mimeType=\"image/svg+xml\" enabled=\"true\" />
  4494. <add mimeType=\"application/x-font-ttf\" enabled=\"true\" />
  4495. <add mimeType=\"application/x-font\" enabled=\"true\" />
  4496. <add mimeType=\"application/x-font-truetype\" enabled=\"true\" />
  4497. <add mimeType=\"application/x-font-opentype\" enabled=\"true\" />
  4498. <add mimeType=\"application/vnd.ms-fontobject\" enabled=\"true\" />
  4499. <add mimeType=\"application/vnd.oasis.opendocument.formula-template\" enabled=\"true\" />";
  4500. }
  4501. $content .= "
  4502. <httpCompression directory=\"%SystemDrive%\inetpub\temp\IIS Temporary Compressed Files\">
  4503. <scheme name=\"gzip\" dll=\"%Windir%\system32\inetsrv\gzip.dll\" staticCompressionLevel=\"9\" />
  4504. <dynamicTypes>" . $types . "
  4505. <add mimeType=\"*/*\" enabled=\"false\" />
  4506. </dynamicTypes>
  4507. <staticTypes>" . $types . "
  4508. <add mimeType=\"*/*\" enabled=\"false\" />
  4509. </staticTypes>
  4510. </httpCompression>
  4511. <urlCompression doStaticCompression=\"true\" doDynamicCompression=\"true\" />";
  4512. }
  4513. /* rules for expires */
  4514. if (!empty($this->input['wss_htaccess_mod_expires']) && empty($this->input['wss_footer_ab'])) {
  4515. $content .= "
  4516. <staticContent>
  4517. <clientCache cacheControlMaxAge=\"3650:00:00\" cacheControlMode=\"UseMaxAge\" />
  4518. </staticContent>";
  4519. }
  4520. $content .= "
  4521. <!-- Web Optimizer end -->
  4522. </system.webServer>";
  4523. if ($content_saved) {
  4524. $this->write_file($this->htaccess, str_replace("</system.webServer>", $content, $content_saved), 1);
  4525. }
  4526. }
  4527. /**
  4528. * Returns actual .htaccess file name
  4529. **/
  4530. function detect_htaccess () {
  4531. $htaccess = $this->iis ? 'web.config' : '.htaccess';
  4532. if (empty($this->input['wss_htaccess_local'])) {
  4533. $htaccess = $this->compress_options['document_root'] . $htaccess;
  4534. } else {
  4535. $htaccess = $this->compress_options['website_root'] . $htaccess;
  4536. }
  4537. return $htaccess;
  4538. }
  4539. /**
  4540. * Cleans all previous rules from .htaccess file content
  4541. **/
  4542. function clean_htaccess ($content_saved = '') {
  4543. if (empty($content_saved)) {
  4544. $content_saved = $this->file_get_contents($this->htaccess);
  4545. }
  4546. $content_saved = $this->iis ?
  4547. preg_replace("@\r?\n?\t*<!-- Web Optimizer options.*?Web Optimizer end -->\r?\n?@is", "", $content_saved) :
  4548. preg_replace("@\r?\n?# Web Optimizer (options|path).*?# Web Optimizer (path )?end\r?\n?@is", "", $content_saved);
  4549. return $content_saved;
  4550. }
  4551. /**
  4552. * Checks and writes all optimized rules to .htaccess file
  4553. **/
  4554. function write_htaccess ($base = '/') {
  4555. $this->view->set_paths($this->compress_options['document_root']);
  4556. /* re-check base */
  4557. if ($base == '/' && !empty($this->compress_options['htaccess']['local'])) {
  4558. $base = str_replace($this->compress_options['document_root'], '/',
  4559. $this->compress_options['website_root']);
  4560. }
  4561. /* delete previous Web Optimizer rules */
  4562. $this->htaccess = $this->detect_htaccess();
  4563. $content_saved = $this->clean_htaccess();
  4564. /* create backup */
  4565. if (!@is_file($this->htaccess . '.backup')) {
  4566. @copy($this->htaccess, $this->htaccess . '.backup');
  4567. }
  4568. if ($this->iis) {
  4569. return $this->write_webconfig($base, $content_saved);
  4570. }
  4571. if (!@is_writable($this->htaccess) && @is_file($this->htaccess)) {
  4572. $this->error = $this->error ? $this->error : array();
  4573. $this->error[10] = 1;
  4574. }
  4575. $content = '# Web Optimizer options';
  4576. $content2 = '';
  4577. if (!empty($this->input['wss_htaccess_enabled']) && $this->compress_options['active']) {
  4578. $content_enhanced = '';
  4579. if (!empty($this->input['wss_html_cache_enabled']) && !empty($this->input['wss_html_cache_enhanced']) && empty($this->input['wss_footer_ab'])) {
  4580. /* create rules for enhanced HTML caching mode */
  4581. $content_enhanced = "
  4582. " . (empty($this->compress_options['charset']) ? '' : 'AddDefaultCharset ' . $this->compress_options['charset']);
  4583. $cookie = array();
  4584. /* WordPress-related cookie to skip server side extreme caching */
  4585. if (strstr($this->basepath, 'wp-content')) {
  4586. $cookie[] = 'wordpress';
  4587. $cookie[] = 'wp-postpass_';
  4588. }
  4589. /* Bitrix-related cookie to skip server side extreme caching */
  4590. if (strstr($this->basepath, 'bitrix')) {
  4591. $cookie[] = '_SM_LOGIN';
  4592. }
  4593. /* generic cookies to skip server side caching */
  4594. if (!empty($this->input['wss_html_cache_additional_list'])) {
  4595. $cookies = explode(' ', $this->input['wss_html_cache_additional_list']);
  4596. foreach ($cookies as $c) {
  4597. if (!empty($c)) {
  4598. $cookie[] = $c;
  4599. }
  4600. }
  4601. }
  4602. if (count($cookie)) {
  4603. $cookie = '!^.*(' . implode($cookie, '|') . ').*$';
  4604. }
  4605. if (!empty($this->input['wss_htaccess_mod_setenvif'])) {
  4606. if ($cookie) {
  4607. $content_enhanced .= "
  4608. RewriteCond %{HTTP:Cookie} " . $cookie;
  4609. }
  4610. $content_enhanced .= "
  4611. RewriteCond %{REQUEST_METHOD} !=POST
  4612. RewriteCond \"" . $this->compress_options['html_cachedir'] . "%{HTTP_HOST}/%{REQUEST_URI}%{QUERY_STRING}/index%{ENV:WSSBR}.html%{ENV:WSSENC}\" -f
  4613. RewriteRule (.*) " . str_replace($this->compress_options['document_root'], "/", $this->compress_options['html_cachedir']) . "%{HTTP_HOST}" . str_replace($this->compress_options['document_root'], "/", $this->compress_options['website_root']) . "$1/index%{ENV:WSSBR}.html%{ENV:WSSENC} [L]";
  4614. } else {
  4615. $browsers = empty($this->input['wss_performance_uniform_cache']) ?
  4616. array(
  4617. 'MSIE 6' => '.ie6',
  4618. 'MSIE 7' => '.ie7',
  4619. 'MSIE 8' => '.ie8',
  4620. 'MSIE 9' => '.ie9',
  4621. 'MSIE 10' => '.ie10',
  4622. 'Android|BlackBerry|HTC|iPhone|iPod|LG|MOT|Mobile|NetFront|Nokia|Opera Mini|Palm|PPC|SAMSUNG|Smartphone|SonyEricsson|Symbian|UP.Browser|webOS' => '.ma') : array();
  4623. $browsers[] = '';
  4624. $encodings = (empty($this->input['wss_gzip_page']) ||
  4625. !empty($this->input['wss_htaccess_mod_gzip']) ||
  4626. !empty($this->input['wss_htaccess_mod_deflate'])) &&
  4627. !empty($this->input['wss_htaccess_mod_mime']) ?
  4628. array() : array('gzip' => '.gz', 'deflate' => '.df');
  4629. $encodings[] = '';
  4630. foreach ($encodings as $enc => $encoding) {
  4631. foreach ($browsers as $br => $browser) {
  4632. $content_enhanced .= "
  4633. RewriteCond %{REQUEST_METHOD} !=POST";
  4634. if ($br) {
  4635. $content_enhanced .= "
  4636. RewriteCond %{HTTP_USER_AGENT} \"" . $br . "\"";
  4637. }
  4638. if ($enc) {
  4639. $content_enhanced .= "
  4640. RewriteCond %{HTTP:Accept-Encoding} ". $enc;
  4641. }
  4642. if ($cookie) {
  4643. $content_enhanced .= "
  4644. RewriteCond %{HTTP:Cookie} " . $cookie;
  4645. }
  4646. $content_enhanced .= "
  4647. RewriteCond \"" . $this->compress_options['html_cachedir'] . "%{HTTP_HOST}/%{REQUEST_URI}%{QUERY_STRING}/index". $browser .".html". $encoding ."\" -f
  4648. RewriteRule (.*) " . str_replace($this->compress_options['document_root'], "/", $this->compress_options['html_cachedir']) . "%{HTTP_HOST}" . str_replace($this->compress_options['document_root'], "/", $this->compress_options['website_root']) . "$1/index". $browser .".html". $encoding ." [L]";
  4649. }
  4650. }
  4651. }
  4652. }
  4653. /* rules for gzip via mod_gzip */
  4654. if (!empty($this->input['wss_htaccess_mod_gzip']) && empty($this->input['wss_footer_ab'])) {
  4655. $content .= "
  4656. <IfModule mod_gzip.c>
  4657. mod_gzip_on Yes
  4658. mod_gzip_can_negotiate Yes
  4659. mod_gzip_static_suffix .gz
  4660. mod_gzip_update_static No
  4661. mod_gzip_keep_workfiles No
  4662. mod_gzip_minimum_file_size 500
  4663. mod_gzip_maximum_file_size 5000000
  4664. mod_gzip_maximum_inmem_size 60000
  4665. mod_gzip_min_http 1000
  4666. mod_gzip_handle_methods GET POST
  4667. mod_gzip_item_exclude reqheader \"User-agent: Mozilla/4.0[678]\"
  4668. mod_gzip_dechunk No";
  4669. if (!empty($this->input['wss_gzip_page'])) {
  4670. $content .= "
  4671. mod_gzip_item_include mime ^text/plain$
  4672. mod_gzip_item_include mime ^text/html$
  4673. mod_gzip_item_include mime ^text/xml$
  4674. mod_gzip_item_include mime ^application/xhtml+xml$
  4675. mod_gzip_item_include mime ^application/json$
  4676. mod_gzip_item_include mime ^image/x-icon$
  4677. mod_gzip_item_include mime ^image/vnd.microsoft.icon$
  4678. mod_gzip_item_include mime ^text/richtext$
  4679. mod_gzip_item_include mime ^text/xsd$
  4680. mod_gzip_item_include mime ^text/xsl$
  4681. mod_gzip_item_include mime ^text/x-component$
  4682. mod_gzip_item_include mime ^httpd/unix-directory$";
  4683. }
  4684. if (!empty($this->input['wss_gzip_css'])) {
  4685. $content .= "
  4686. mod_gzip_item_include mime ^text/css$";
  4687. }
  4688. if (!empty($this->input['wss_gzip_javascript'])) {
  4689. $content .= "
  4690. mod_gzip_item_include mime ^text/javascript$
  4691. mod_gzip_item_include mime ^application/javascript$
  4692. mod_gzip_item_include mime ^application/x-javascript$
  4693. mod_gzip_item_include mime ^text/x-js$
  4694. mod_gzip_item_include mime ^text/ecmascript$
  4695. mod_gzip_item_include mime ^application/ecmascript$
  4696. mod_gzip_item_include mime ^text/vbscript$
  4697. mod_gzip_item_include mime ^text/fluffscript$";
  4698. }
  4699. if (!empty($this->input['wss_gzip_fonts'])) {
  4700. $content .= "
  4701. mod_gzip_item_include mime ^image/svg+xml$
  4702. mod_gzip_item_include mime ^application/x-font$
  4703. mod_gzip_item_include mime ^application/x-font-ttf$
  4704. mod_gzip_item_include mime ^font/opentype$
  4705. mod_gzip_item_include mime ^font/otf$
  4706. mod_gzip_item_include mime ^font/ttf$
  4707. mod_gzip_item_include mime ^application/x-font-opentype$
  4708. mod_gzip_item_include mime ^application/x-font-truetype$
  4709. mod_gzip_item_include mime ^application/vnd.ms-fontobject
  4710. mod_gzip_item_include mime ^application/vnd.oasis.opendocument.formula-template$";
  4711. }
  4712. $content .= "
  4713. </IfModule>";
  4714. }
  4715. if (!empty($this->input['wss_htaccess_mod_setenvif']) && empty($this->input['wss_footer_ab'])) {
  4716. $content .= "
  4717. <IfModule mod_setenvif.c>
  4718. BrowserMatch ^Mozilla/4 gzip-only-text/html
  4719. BrowserMatch ^Mozilla/4\.0[678] no-gzip
  4720. BrowserMatch SV1; !no_gzip
  4721. BrowserMatch \bMSIE !no-gzip !gzip-only-text/html";
  4722. if (!empty($this->input['wss_html_cache_enabled']) &&
  4723. !empty($this->input['wss_html_cache_enhanced']) &&
  4724. !empty($this->input['wss_gzip_page']) &&
  4725. empty($this->input['wss_htaccess_mod_gzip']) &&
  4726. empty($this->input['wss_htaccess_mod_deflate'])) {
  4727. $content .= "
  4728. SetEnvIfNoCase accept-encoding deflate WSSENC=.df
  4729. SetEnvIfNoCase accept-encoding gzip WSSENC=.gz";
  4730. }
  4731. if (empty($this->input['wss_performance_uniform_cache']) &&
  4732. !empty($this->input['wss_html_cache_enabled']) &&
  4733. !empty($this->input['wss_html_cache_enhanced'])) {
  4734. $content .="
  4735. BrowserMatch \"MSIE 6\" WSSBR=.ie6
  4736. BrowserMatch \"MSIE 7\" WSSBR=.ie7
  4737. BrowserMatch \"MSIE 8\" WSSBR=.ie8
  4738. BrowserMatch \"Android|BlackBerry|HTC|iPhone|iPod|LG|MOT|Mobile|NetFront|Nokia|Opera Mini|Palm|PPC|SAMSUNG|Smartphone|SonyEricsson|Symbian|UP.Browser|webOS\" WSSBR=.ma";
  4739. }
  4740. $content .= "
  4741. </IfModule>";
  4742. }
  4743. if (!empty($this->input['wss_htaccess_mod_deflate']) && empty($this->input['wss_footer_ab'])) {
  4744. $content .= "
  4745. <IfModule mod_deflate.c>";
  4746. if (!empty($this->input['wss_gzip_page'])) {
  4747. $content .= "
  4748. AddOutputFilterByType DEFLATE text/plain text/html text/xml application/xhtml+xml image/x-icon image/vnd.microsoft.icon text/richtext text/xsd text/xsl text/xml application/json text/x-component";
  4749. }
  4750. if (!empty($this->input['wss_gzip_css'])) {
  4751. $content .= "
  4752. AddOutputFilterByType DEFLATE text/css";
  4753. }
  4754. if (!empty($this->input['wss_gzip_javascript'])) {
  4755. $content .= "
  4756. AddOutputFilterByType DEFLATE text/javascript application/javascript application/x-javascript text/x-js text/ecmascript application/ecmascript text/vbscript text/fluffscript";
  4757. }
  4758. /* add gzip for fonts
  4759. http://www.phpied.com/gzip-your-font-face-files/ */
  4760. if (!empty($this->input['wss_gzip_fonts'])) {
  4761. $content .= "
  4762. AddOutputFilterByType DEFLATE image/svg+xml application/x-font-ttf application/x-font font/opentype font/otf font/ttf application/x-font-truetype application/x-font-opentype application/vnd.ms-fontobject application/vnd.oasis.opendocument.formula-template";
  4763. }
  4764. $content .= "
  4765. </IfModule>";
  4766. }
  4767. /* prevent 403 error due to no FollowSymLinks
  4768. http://www.elharo.com/blog/software-development/web-development/2006/01/02/two-tips-for-fixing-apache-problems/
  4769. http://code.google.com/p/web-optimizator/issues/detail?id=156 */
  4770. if (!empty($this->input['wss_htaccess_mod_symlinks']) && empty($this->input['wss_footer_ab'])) {
  4771. $content .= "
  4772. Options +FollowSymLinks";
  4773. }
  4774. /* try to add static gzip */
  4775. if (!empty($this->input['wss_htaccess_mod_mime']) && empty($this->input['wss_footer_ab'])) {
  4776. $content .= "
  4777. <IfModule mod_mime.c>
  4778. AddEncoding gzip .gz
  4779. AddEncoding deflate .df
  4780. <FilesMatch \.html\.(gz|df)$>
  4781. ForceType text/html
  4782. </FilesMatch>
  4783. <FilesMatch \.xml\.gz$>
  4784. ForceType text/xml
  4785. </FilesMatch>
  4786. <FilesMatch \.txt\.gz$>
  4787. ForceType text/plain
  4788. </FilesMatch>
  4789. <FilesMatch \.ico\.gz$>
  4790. ForceType image/x-icon
  4791. </FilesMatch>
  4792. <FilesMatch \.cur\.gz$>
  4793. ForceType image/vnd.microsoft.icon
  4794. </FilesMatch>
  4795. <FilesMatch \.css\.gz$>
  4796. ForceType text/css
  4797. </FilesMatch>
  4798. <FilesMatch \.js\.gz$>
  4799. ForceType application/x-javascript
  4800. </FilesMatch>
  4801. <FilesMatch \.svg\.gz$>
  4802. ForceType image/svg+xml
  4803. </FilesMatch>
  4804. <FilesMatch \.ttf\.gz$>
  4805. ForceType font/ttf
  4806. </FilesMatch>
  4807. <FilesMatch \.otf\.gz$>
  4808. ForceType font/otf
  4809. </FilesMatch>
  4810. <FilesMatch \.eot\.gz$>
  4811. ForceType application/vnd.ms-fontobject
  4812. </FilesMatch>
  4813. <FilesMatch \.(rtf|rtx)\.gz$>
  4814. ForceType text/richtext
  4815. </FilesMatch>
  4816. <FilesMatch \.xsd\.gz$>
  4817. ForceType text/xsd
  4818. </FilesMatch>
  4819. <FilesMatch \.xsl\.gz$>
  4820. ForceType text/xsl
  4821. </FilesMatch>
  4822. <FilesMatch \.htc\.gz$>
  4823. ForceType text/x-component
  4824. </FilesMatch>
  4825. AddType text/css css
  4826. AddType application/x-javascript js
  4827. AddType text/html html htm
  4828. AddType text/richtext rtf rtx
  4829. AddType text/plain txt
  4830. AddType text/xsd xsd
  4831. AddType text/xsl xsl
  4832. AddType text/xml xml
  4833. AddType text/cache-manifest manifest
  4834. AddType text/x-component htc
  4835. AddType video/asf asf asx wax wmv wmx
  4836. AddType video/avi avi
  4837. AddType video/ogg ogg ogv
  4838. AddType video/mp4 mp4 m4v
  4839. AddType video/webm webm
  4840. AddType video/divx divx
  4841. AddType video/quicktime mov qt
  4842. AddType video/mpeg mpeg mpg mpe
  4843. AddType audio/midi mid midi
  4844. AddType audio/mpeg mp3 m4a
  4845. AddType audio/ogg ogg
  4846. AddType audio/x-realaudio ra ram
  4847. AddType audio/wav wav
  4848. AddType audio/wma wma
  4849. AddType image/svg+xml svg svgz
  4850. AddType image/bmp bmp
  4851. AddType image/gif gif
  4852. AddType image/x-icon ico
  4853. AddType image/vnd.microsoft.icon ico
  4854. AddType image/jpeg jpg jpeg jpe
  4855. AddType image/png png
  4856. AddType image/tiff tif tiff
  4857. AddType font/ttf ttf
  4858. AddType font/otf otf
  4859. AddType font/x-woff woff
  4860. AddType application/vnd.ms-fontobject eot
  4861. AddType application/msword doc docx
  4862. AddType application/x-msdownload exe
  4863. AddType application/vnd.ms-access mdb
  4864. AddType application/vnd.ms-project mpp
  4865. AddType application/vnd.ms-powerpoint pot pps ppt pptx
  4866. AddType application/vnd.ms-write wri
  4867. AddType application/vnd.ms-excel xla xls xlsx xlt xlw
  4868. AddType application/vnd.oasis.opendocument.database odb
  4869. AddType application/vnd.oasis.opendocument.chart odc
  4870. AddType application/vnd.oasis.opendocument.formula odf
  4871. AddType application/vnd.oasis.opendocument.graphics odg
  4872. AddType application/vnd.oasis.opendocument.presentation odp
  4873. AddType application/vnd.oasis.opendocument.spreadsheet ods
  4874. AddType application/vnd.oasis.opendocument.text odt
  4875. AddType application/java class
  4876. AddType application/x-gzip gzip
  4877. AddType application/pdf pdf
  4878. AddType application/x-shockwave-flash swf
  4879. AddType application/x-tar tar
  4880. AddType application/zip zip
  4881. </IfModule>";
  4882. if (!empty($this->input['wss_htaccess_mod_rewrite'])) {
  4883. $content .= "
  4884. <IfModule mod_rewrite.c>
  4885. RewriteEngine On
  4886. RewriteBase $base";
  4887. /* Redirects for multiple domains */
  4888. if (!empty($this->input['wss_parallel_allowed_list'])) {
  4889. $hosts = str_replace(" ", " [OR]\n\tRewriteCond %{HTTP_HOST} ^", $this->input['wss_parallel_allowed_list']);
  4890. $content .= "
  4891. RewriteCond %{HTTP_HOST} ^" . $hosts . "
  4892. RewriteCond %{REQUEST_URI} !\.(jpe?g|png|gif|bmp)$
  4893. RewriteRule (.*) http://" . $this->compress_options['host'] . $base . "$1 [R=301,L]";
  4894. }
  4895. if (!empty($this->input['wss_far_future_expires_css'])) {
  4896. $content .= "
  4897. RewriteRule ^(.*)\.wo[0-9]+\.(css|php)$ $1.$2";
  4898. }
  4899. if (!empty($this->input['wss_far_future_expires_javascript'])) {
  4900. $content .= "
  4901. RewriteRule ^(.*)\.wo[0-9]+\.(js|php)$ $1.$2";
  4902. }
  4903. if (!empty($this->input['wss_far_future_expires_images'])) {
  4904. $content .= "
  4905. RewriteRule ^(.*)\.wo[0-9]+\.(jpe?g|png)$ $1.$2";
  4906. }
  4907. if (!empty($this->input['wss_gzip_page'])) {
  4908. $content .= "
  4909. RewriteCond %{HTTP:Accept-encoding} gzip
  4910. RewriteCond %{HTTP_USER_AGENT} !Konqueror
  4911. RewriteCond %{REQUEST_FILENAME}.gz -f
  4912. RewriteRule ^(.*)\.cur$ $1.cur.gz [QSA,L]
  4913. RewriteCond %{HTTP:Accept-encoding} gzip
  4914. RewriteCond %{HTTP_USER_AGENT} !Konqueror
  4915. RewriteCond %{REQUEST_FILENAME}.gz -f
  4916. RewriteRule ^(.*)\.ico$ $1.ico.gz [QSA,L]
  4917. RewriteCond %{HTTP:Accept-encoding} gzip
  4918. RewriteCond %{HTTP_USER_AGENT} !Konqueror
  4919. RewriteCond %{REQUEST_FILENAME}.gz -f
  4920. RewriteRule ^(.*)\.xml$ $1.xml.gz [QSA,L]
  4921. RewriteCond %{HTTP:Accept-encoding} gzip
  4922. RewriteCond %{HTTP_USER_AGENT} !Konqueror
  4923. RewriteCond %{REQUEST_FILENAME}.gz -f
  4924. RewriteRule ^(.*)\.txt$ $1.txt.gz [QSA,L]
  4925. RewriteCond %{HTTP:Accept-encoding} gzip
  4926. RewriteCond %{HTTP_USER_AGENT} !Konqueror
  4927. RewriteCond %{REQUEST_FILENAME}.gz -f
  4928. RewriteRule ^(.*)\.htc$ $1.htc.gz [QSA,L]";
  4929. }
  4930. if (!empty($this->input['wss_gzip_css'])) {
  4931. $content .= "
  4932. RewriteCond %{HTTP:Accept-encoding} gzip
  4933. RewriteCond %{HTTP_USER_AGENT} !Konqueror
  4934. RewriteCond %{REQUEST_FILENAME}.gz -f
  4935. RewriteRule ^(.*)\.css$ $1.css.gz [QSA,L]";
  4936. }
  4937. if (!empty($this->input['wss_gzip_javascript'])) {
  4938. $content .= "
  4939. RewriteCond %{HTTP:Accept-encoding} gzip
  4940. RewriteCond %{HTTP_USER_AGENT} !Konqueror
  4941. RewriteCond %{REQUEST_FILENAME}.gz -f
  4942. RewriteRule ^(.*)\.js$ $1.js.gz [QSA,L]";
  4943. }
  4944. if (!empty($this->input['wss_gzip_fonts'])) {
  4945. $content .= "
  4946. RewriteCond %{HTTP:Accept-encoding} gzip
  4947. RewriteCond %{HTTP_USER_AGENT} !Konqueror
  4948. RewriteCond %{REQUEST_FILENAME}.gz -f
  4949. RewriteRule ^(.*)\.(ttf|otf|eot|svg)$ $1.$2.gz [QSA,L]";
  4950. }
  4951. $content .= $content_enhanced;
  4952. /* there is gzip enabled, mod_expires exists, but no mod_deflate/mod_gzip */
  4953. if (!empty($this->input['wss_htaccess_mod_expires']) &&
  4954. empty($this->input['wss_htaccess_mod_gzip']) &&
  4955. empty($this->input['wss_htaccess_mod_deflate']) &&
  4956. @is_file($this->compress_options['css_cachedir'] . 'wo.gzip.php') &&
  4957. !empty($this->premium)) {
  4958. @chmod($this->compress_options['css_cachedir'] . 'wo.gzip.php', octdec("0755"));
  4959. $cachedir = str_replace($this->compress_options['document_root'],
  4960. "/", $this->compress_options['css_cachedir']);
  4961. if (!empty($this->input['wss_gzip_css'])) {
  4962. $content .= "
  4963. RewriteCond %{REQUEST_FILENAME} -f
  4964. RewriteRule ^(.*)\.css$ " . $cachedir . "wo.gzip.php?" . $base . "$1.css [L]";
  4965. }
  4966. if (!empty($this->input['wss_gzip_javascript'])) {
  4967. $content .= "
  4968. RewriteCond %{REQUEST_FILENAME} -f
  4969. RewriteRule ^(.*)\.js$ " . $cachedir . "wo.gzip.php?" . $base . "$1.js [L]";
  4970. }
  4971. if (!empty($this->input['wss_gzip_fonts'])) {
  4972. $content .= "
  4973. RewriteCond %{REQUEST_FILENAME} -f
  4974. RewriteRule ^(.*)\.ttf$ " . $cachedir . "wo.gzip.php?" . $base . "$1.ttf [L]
  4975. RewriteCond %{REQUEST_FILENAME} -f
  4976. RewriteRule ^(.*)\.otf$ " . $cachedir . "wo.gzip.php?" . $base . "$1.otf [L]
  4977. RewriteCond %{REQUEST_FILENAME} -f
  4978. RewriteRule ^(.*)\.eot$ " . $cachedir . "wo.gzip.php?" . $base . "$1.eot [L]";
  4979. }
  4980. }
  4981. $content .= "
  4982. </IfModule>";
  4983. }
  4984. } elseif (!empty($this->input['wss_htaccess_mod_rewrite'])) {
  4985. $content .= "
  4986. <IfModule mod_rewrite.c>
  4987. RewriteEngine On
  4988. RewriteBase $base";
  4989. if (!empty($this->input['wss_far_future_expires_css'])) {
  4990. $content .= "
  4991. RewriteRule ^(.*)\.wo[0-9]+\.(css|php)$ $1.$2";
  4992. }
  4993. if (!empty($this->input['wss_far_future_expires_javascript'])) {
  4994. $content .= "
  4995. RewriteRule ^(.*)\.wo[0-9]+\.(js|php)$ $1.$2";
  4996. }
  4997. if (!empty($this->input['wss_far_future_expires_images'])) {
  4998. $content .= "
  4999. RewriteRule ^(.*)\.wo[0-9]+\.(jpe?g|png)$ $1.$2";
  5000. }
  5001. $content .= $content_enhanced;
  5002. $content .= "
  5003. </IfModule>";
  5004. }
  5005. if (!empty($this->input['wss_htaccess_mod_expires']) && !empty($this->premium) && empty($this->input['wss_footer_ab'])) {
  5006. $content2 .= "
  5007. # Web Optimizer options
  5008. <IfModule mod_expires.c>
  5009. ExpiresActive On
  5010. <FilesMatch \.manifest$>
  5011. ExpiresDefault A0
  5012. </FilesMatch>
  5013. ExpiresByType text/cache-manifest A0";
  5014. if (!empty($this->input['wss_far_future_expires_html'])) {
  5015. $content2 .= "
  5016. <FilesMatch \.(html|xhtml|xml|shtml|phtml|php|xsl|xsd|rtf|rtx)$>
  5017. ExpiresDefault \"access plus " . $this->input['wss_far_future_expires_html_timeout'] . " seconds\"
  5018. </FilesMatch>
  5019. ExpiresByType text/html A" . $this->input['wss_far_future_expires_html_timeout'] . "
  5020. ExpiresByType text/xml A" . $this->input['wss_far_future_expires_html_timeout'] . "
  5021. ExpiresByType application/xhtml+xml A" . $this->input['wss_far_future_expires_html_timeout'] . "
  5022. ExpiresByType text/plain A" . $this->input['wss_far_future_expires_html_timeout'] . "
  5023. ExpiresByType text/richtext A" . $this->input['wss_far_future_expires_html_timeout'] . "
  5024. ExpiresByType text/xsd A" . $this->input['wss_far_future_expires_html_timeout'] . "
  5025. ExpiresByType text/xsl A" . $this->input['wss_far_future_expires_html_timeout'] . "
  5026. ExpiresByType text/htc A" . $this->input['wss_far_future_expires_html_timeout'] . "
  5027. ExpiresByType application/rss+xml A" . $this->input['wss_far_future_expires_html_timeout'];
  5028. }
  5029. if (!empty($this->input['wss_far_future_expires_css'])) {
  5030. $content2 .= "
  5031. <FilesMatch \.css$>
  5032. ExpiresDefault \"access plus 10 years\"
  5033. </FilesMatch>
  5034. ExpiresByType text/css A315360000";
  5035. }
  5036. if (!empty($this->input['wss_far_future_expires_javascript'])) {
  5037. $content2 .= "
  5038. <FilesMatch \.js$>
  5039. ExpiresDefault \"access plus 10 years\"
  5040. </FilesMatch>
  5041. ExpiresByType text/javascript A315360000
  5042. ExpiresByType application/javascript A315360000
  5043. ExpiresByType application/x-javascript A315360000
  5044. ExpiresByType text/x-js A315360000
  5045. ExpiresByType text/ecmascript A315360000
  5046. ExpiresByType application/ecmascript A315360000
  5047. ExpiresByType text/vbscript A315360000
  5048. ExpiresByType text/fluffscript A315360000";
  5049. }
  5050. if (!empty($this->input['wss_far_future_expires_images'])) {
  5051. $content2 .= "
  5052. <FilesMatch \.(bmp|png|gif|jpe?g|ico|cur)$>
  5053. ExpiresDefault \"access plus 10 years\"
  5054. </FilesMatch>
  5055. ExpiresByType image/gif A315360000
  5056. ExpiresByType image/png A315360000
  5057. ExpiresByType image/jpg A315360000
  5058. ExpiresByType image/jpeg A315360000
  5059. ExpiresByType image/x-icon A315360000
  5060. ExpiresByType image/vnd.microsoft.icon A315360000
  5061. ExpiresByType image/bmp A315360000";
  5062. }
  5063. if (!empty($this->input['wss_far_future_expires_fonts'])) {
  5064. $content2 .= "
  5065. <FilesMatch \.(eot|ttf|otf|svg|woff)$>
  5066. ExpiresDefault \"access plus 10 years\"
  5067. </FilesMatch>
  5068. ExpiresByType image/svg+xml A315360000
  5069. ExpiresByType application/x-font-opentype A315360000
  5070. ExpiresByType application/x-font-truetype A315360000
  5071. ExpiresByType application/x-font-ttf A315360000
  5072. ExpiresByType application/x-font A315360000
  5073. ExpiresByType application/vnd.oasis.opendocument.formula-template A315360000
  5074. ExpiresByType application/vnd.ms-fontobject A315360000
  5075. ExpiresByType font/ttf A315360000
  5076. ExpiresByType font/opentype A315360000
  5077. ExpiresByType font/otf A315360000
  5078. ExpiresByType font/woff A315360000";
  5079. }
  5080. if (!empty($this->input['wss_far_future_expires_video'])) {
  5081. $content2 .= "
  5082. <FilesMatch \.(flv|wmv|asf|asx|wma|wax|wmx|wm|ogg|mp4|mp3|midi?|wav|m4v|webm|divx|mov|qt|mpe?g|mpe|m4a|ra|ram)$>
  5083. ExpiresDefault \"access plus 10 years\"
  5084. </FilesMatch>
  5085. ExpiresByType audio/mpeg A315360000
  5086. ExpiresByType audio/ogg A315360000
  5087. ExpiresByType audio/mid A315360000
  5088. ExpiresByType audio/midi A315360000
  5089. ExpiresByType audio/wav A31536000
  5090. ExpiresByType audio/x-wav A315360000
  5091. ExpiresByType audio/x-realaudio A31536000
  5092. ExpiresByType audio/wma A31536000
  5093. ExpiresByType video/asf A315360000
  5094. ExpiresByType video/avi A315360000
  5095. ExpiresByType video/divx A315360000
  5096. ExpiresByType video/x-flv A315360000
  5097. ExpiresByType video/x-ms-wmv A315360000
  5098. ExpiresByType video/x-ms-asf A315360000
  5099. ExpiresByType video/x-ms-asx A315360000
  5100. ExpiresByType video/x-ms-wma A315360000
  5101. ExpiresByType video/x-ms-wax A315360000
  5102. ExpiresByType video/x-ms-wmx A315360000
  5103. ExpiresByType video/x-ms-wm A315360000
  5104. ExpiresByType video/ogg A315360000
  5105. ExpiresByType video/quicktime A31536000
  5106. ExpiresByType video/mp4 A315360000
  5107. ExpiresByType video/mpeg A31536000";
  5108. }
  5109. if (!empty($this->input['wss_far_future_expires_static'])) {
  5110. $content2 .= "
  5111. <FilesMatch \.(swf|pdf|docx?|rtf|xls|ppt|class|exe|g?zip|tar|mdb|mpp|pot|pps|ppt|pptx|wri|xla|xlsx?|xlt|xlw|odb|odc|odf|odg|odp|ods|odt)$>
  5112. ExpiresDefault \"access plus 10 years\"
  5113. </FilesMatch>
  5114. ExpiresByType application/x-shockwave-flash A315360000
  5115. ExpiresByType application/pdf A315360000
  5116. ExpiresByType application/msword A315360000
  5117. ExpiresByType application/rtf A315360000
  5118. ExpiresByType application/java A315360000
  5119. ExpiresByType application/vnd.ms-excel A315360000
  5120. ExpiresByType application/vnd.ms-powerpoint A315360000
  5121. ExpiresByType application/x-msdownload A31536000
  5122. ExpiresByType application/x-gzip A31536000
  5123. ExpiresByType application/x-tar A31536000
  5124. ExpiresByType application/zip A31536000
  5125. ExpiresByType application/vnd.ms-access A31536000
  5126. ExpiresByType application/vnd.ms-write A31536000
  5127. ExpiresByType application/vnd.oasis.opendocument.text A31536000
  5128. ExpiresByType application/vnd.ms-project A31536000
  5129. ExpiresByType application/vnd.oasis.opendocument.database A31536000
  5130. ExpiresByType application/vnd.oasis.opendocument.chart A31536000
  5131. ExpiresByType application/vnd.oasis.opendocument.formula A31536000
  5132. ExpiresByType application/vnd.oasis.opendocument.graphics A31536000
  5133. ExpiresByType application/vnd.oasis.opendocument.presentation A31536000
  5134. ExpiresByType application/vnd.oasis.opendocument.spreadsheet A31536000
  5135. ExpiresByType application/vnd.oasis.opendocument.text A31536000";
  5136. }
  5137. /* Caching for AJAX requests, CS-Cart */
  5138. if (!empty($this->input['wss_html_cache_enabled']) && $this->cscart) {
  5139. $content2 .= "
  5140. </IfModule>
  5141. <IfModule mod_rewrite.c>
  5142. RewriteCond %{QUERY_STRING} dispatch=load_menu\.get_items&tree_id=([0-9_]+)&dir=&result_ids=sub_menu_content_([0-9_]+)
  5143. RewriteCond ". $this->compress_options['html_cachedir'] ."menu.%1.%2.html -f
  5144. RewriteRule ^(.*)$ /addons/webositespeedup/web-optimizer/cache/menu.%1.%2.html?";
  5145. }
  5146. $content2 .= "
  5147. </IfModule>
  5148. # Web Optimizer end";
  5149. /* add Expires headers via PHP script if we don't have mod_expires */
  5150. } elseif (!empty($this->input['wss_htaccess_mod_rewrite']) &&
  5151. @is_file($this->compress_options['css_cachedir'] . 'wo.static.php') &&
  5152. @is_file($this->compress_options['css_cachedir'] . 'wo.gzip.php')) {
  5153. @chmod($this->compress_options['css_cachedir'] . 'wo.static.php', octdec("0755"));
  5154. @chmod($this->compress_options['css_cachedir'] . 'wo.gzip.php', octdec("0755"));
  5155. $cachedir = str_replace($this->compress_options['document_root'],
  5156. "/", $this->compress_options['css_cachedir']);
  5157. $content2 .= "
  5158. # Web Optimizer options
  5159. <IfModule mod_rewrite.c>";
  5160. /* Caching for AJAX requests, CS-Cart */
  5161. if (!empty($this->input['wss_html_cache_enabled']) && $this->cscart) {
  5162. $content2 .= "
  5163. RewriteCond %{QUERY_STRING} dispatch=load_menu\.get_items&tree_id=([0-9_]+)&dir=&result_ids=sub_menu_content_([0-9_]+)
  5164. RewriteCond ". $this->compress_options['html_cachedir'] ."menu.%1.%2.html -f
  5165. RewriteRule ^(.*)$ /addons/webositespeedup/web-optimizer/cache/menu.%1.%2.html?";
  5166. }
  5167. if (!empty($this->input['wss_far_future_expires_css'])) {
  5168. $content2 .= "
  5169. RewriteCond %{REQUEST_FILENAME} -f";
  5170. if (!empty($this->input['wss_footer_ab'])) {
  5171. $content2 .= "
  5172. RewriteCond %{HTTP:Cookie} !^WSS_DISABLED";
  5173. }
  5174. $content2 .= "
  5175. RewriteRule ^(.*)\.css$ " . $cachedir . (empty($this->input['wss_gzip_css']) ? "wo.static.php" : "wo.gzip.php") . "?" . $base . "$1.css [L]";
  5176. }
  5177. if (!empty($this->input['wss_far_future_expires_javascript'])) {
  5178. $content2 .= "
  5179. RewriteCond %{REQUEST_FILENAME} -f";
  5180. if (!empty($this->input['wss_footer_ab'])) {
  5181. $content2 .= "
  5182. RewriteCond %{HTTP:Cookie} !^WSS_DISABLED";
  5183. }
  5184. $content2 .= "
  5185. RewriteRule ^(.*)\.js$ " . $cachedir . (empty($this->input['wss_gzip_javascript']) ? "wo.static.php" : "wo.gzip.php") . "?" . $base . "$1.js [L]";
  5186. }
  5187. if (!empty($this->input['wss_far_future_expires_images'])) {
  5188. $content2 .= "
  5189. RewriteCond %{REQUEST_FILENAME} -f";
  5190. if (!empty($this->input['wss_footer_ab'])) {
  5191. $content2 .= "
  5192. RewriteCond %{HTTP:Cookie} !^WSS_DISABLED";
  5193. }
  5194. $content2 .= "
  5195. RewriteRule ^(.*)\.(bmp|gif|png|jpe?g|ico|cur)$ " . $cachedir . (empty($this->input['wss_gzip_page']) ? "wo.static.php" : "wo.gzip.php") . "?" . $base . "$1.$2 [L]";
  5196. }
  5197. if (!empty($this->input['wss_far_future_expires_fonts'])) {
  5198. $content2 .= "
  5199. RewriteCond %{REQUEST_FILENAME} -f";
  5200. if (!empty($this->input['wss_footer_ab'])) {
  5201. $content2 .= "
  5202. RewriteCond %{HTTP:Cookie} !^WSS_DISABLED";
  5203. }
  5204. $content2 .= "
  5205. RewriteRule ^(.*)\.(eot|ttf|otf|svg)$ " . $cachedir . "wo.static.php?" . $base . "$1.$2 [L]";
  5206. }
  5207. $content2 .= "
  5208. </IfModule>
  5209. # Web Optimizer end";
  5210. }
  5211. if (!empty($this->input['wss_htaccess_mod_headers']) && !empty($this->premium) && empty($this->input['wss_footer_ab'])) {
  5212. $content .= "
  5213. <IfModule mod_headers.c>";
  5214. if (!empty($this->input['wss_htaccess_mod_deflate']) ||
  5215. !empty($this->input['wss_htaccess_mod_gzip'])) {
  5216. $content .= "
  5217. <FilesMatch \.(css|js)$>
  5218. Header append Vary User-Agent
  5219. Header append Vary Accept-Encoding
  5220. Header append Cache-Control private
  5221. </FilesMatch>";
  5222. }
  5223. if (!empty($this->input['wss_htaccess_mod_expires'])) {
  5224. $content .= "
  5225. <FilesMatch \.(bmp|png|gif|jpe?g|ico|flv|wmv|asf|asx|wma|wax|wmx|wm|ogg|mp4|mp3|wav|mid|swf|pdf|doc|rtf|xls|ppt|eot|ttf|otf|svg|woff)$>
  5226. Header append Cache-Control public
  5227. </FilesMatch>
  5228. <FilesMatch \.(js|css|bmp|png|gif|jpe?g|ico|flv|wmv|asf|asx|wma|wax|wmx|wm|ogg|mp4|mp3|wav|mid|swf|pdf|doc|rtf|xls|ppt|woff)$>
  5229. Header unset Last-Modified
  5230. FileETag MTime
  5231. </FilesMatch>";
  5232. }
  5233. $content .= "
  5234. </IfModule>";
  5235. }
  5236. } elseif (!empty($this->input['wss_htaccess_mod_rewrite']) && !empty($this->input['wss_htaccess_enabled'])) {
  5237. $content .= "
  5238. <IfModule mod_rewrite.c>
  5239. RewriteEngine On
  5240. RewriteBase $base";
  5241. if (!empty($this->input['wss_far_future_expires_css'])) {
  5242. $content .= "
  5243. RewriteRule ^(.*)\.wo[0-9]+\.(css|php)$ $1.$2";
  5244. }
  5245. if (!empty($this->input['wss_far_future_expires_javascript'])) {
  5246. $content .= "
  5247. RewriteRule ^(.*)\.wo[0-9]+\.(js|php)$ $1.$2";
  5248. }
  5249. if (!empty($this->input['wss_far_future_expires_images'])) {
  5250. $content .= "
  5251. RewriteRule ^(.*)\.wo[0-9]+\.(jpe?g|png)$ $1.$2";
  5252. }
  5253. $content .= "
  5254. </IfModule>";
  5255. }
  5256. $content .= "\n# Web Optimizer end";
  5257. /* define CMS */
  5258. $this->cms_version = $this->system_info($this->view->paths['absolute']['document_root']);
  5259. $cms_frameworks = array('Zend Framework', 'Symfony', 'CodeIgniter', 'Kohana', 'Yii', 'CakePHP');
  5260. /* prevent rewrite to admin access on frameworks */
  5261. if (in_array($this->cms_version, $cms_frameworks)) {
  5262. $content_saved = preg_replace("/((#\s*)?RewriteRule \.\* index.php\r?\n)/",
  5263. "# Web Optimizer path\nRewriteCond %{REQUEST_FILENAME} ^(".
  5264. $this->view->paths['relative']['current_directory'] .
  5265. ")\n# Web Optimizer path end\n$1", $content_saved);
  5266. }
  5267. /* try to remove current .htaccess with a new one */
  5268. if (!@is_writable($this->htaccess)) {
  5269. @unlink($this->htaccess);
  5270. }
  5271. /* check if .htaccess isn't required */
  5272. $not_apache = 0;
  5273. if (!empty($_SERVER['SERVER_SOFTWARE'])) {
  5274. $not_apache = strpos($_SERVER['SERVER_SOFTWARE'], 'nginx');
  5275. }
  5276. if (!$not_apache) {
  5277. $this->write_file($this->htaccess, $content . "\n" . $content_saved . $content2, 1);
  5278. $test_file = $this->compress_options['html_cachedir'] . 'htaccess.test';
  5279. /* load home page, text .htaccess possibility */
  5280. $this->view->download('http://' . $_SERVER['HTTP_HOST'] . '/', $test_file);
  5281. if (!@is_file($test_file)) {
  5282. $this->write_file($this->htaccess, $content_saved, 1);
  5283. }
  5284. @unlink($test_file);
  5285. }
  5286. }
  5287. /**
  5288. * Final stage
  5289. *
  5290. **/
  5291. function install_install ($skip = false) {
  5292. $auto_rewrite = 0;
  5293. /* sve initial options */
  5294. $this->compress_options['document_root'] = empty($this->compress_options['document_root']) ?
  5295. $this->view->paths['full']['document_root'] : $this->compress_options['document_root'];
  5296. $this->compress_options['website_root'] = empty($this->compress_options['website_root']) ?
  5297. $this->view->paths['absolute']['document_root'] : $this->compress_options['website_root'];
  5298. $this->compress_options['css_cachedir'] = empty($this->compress_options['css_cachedir']) ?
  5299. $this->basepath . 'cache/' : $this->compress_options['css_cachedir'];
  5300. $this->compress_options['javascript_cachedir'] = empty($this->compress_options['javascript_cachedir']) ?
  5301. $this->basepath . 'cache/' : $this->compress_options['javascript_cachedir'];
  5302. $this->compress_options['html_cachedir'] = empty($this->compress_options['html_cachedir']) ?
  5303. $this->basepath . 'cache/' : $this->compress_options['html_cachedir'];
  5304. $this->compress_options['host'] = empty($this->compress_options['host']) ?
  5305. (empty($_SERVER['HTTP_HOST']) ? '' : $_SERVER['HTTP_HOST']) :
  5306. $this->compress_options['host'];
  5307. $this->compress_options['minify']['css_host'] = empty($this->compress_options['minify']['css_host']) ?
  5308. (empty($_SERVER['HTTP_HOST']) ? '' : $_SERVER['HTTP_HOST']) :
  5309. $this->compress_options['minify']['css_host'];
  5310. $this->compress_options['minify']['javascript_host'] = empty($this->compress_options['minify']['javascript_host']) ?
  5311. (empty($_SERVER['HTTP_HOST']) ? '' : $_SERVER['HTTP_HOST']) :
  5312. $this->compress_options['minify']['javascript_host'];
  5313. foreach (array(
  5314. 'document_root',
  5315. 'website_root',
  5316. 'css_cachedir',
  5317. 'javascript_cachedir',
  5318. 'html_cachedir',
  5319. 'host') as $val) {
  5320. $this->save_option("['" . $val . "']",
  5321. $this->compress_options[$val]);
  5322. }
  5323. foreach (array(
  5324. 'css_host',
  5325. 'javascript_host') as $val) {
  5326. $this->save_option("['minify']['" . $val . "']",
  5327. $this->compress_options['minify'][$val]);
  5328. }
  5329. /* create backup for options file */
  5330. if (!@is_file($this->basepath . '.config.webo.php')) {
  5331. @copy($this->basepath . $this->options_file, $this->basepath . '.config.webo.php');
  5332. }
  5333. /* clean previous changes */
  5334. $this->install_uninstall(1);
  5335. /* define CMS */
  5336. $this->cms_version = $this->system_info($this->compress_options['website_root']);
  5337. /* copy some files */
  5338. @copy($this->basepath . 'images/web.optimizer.stamp.png',
  5339. $this->compress_options['css_cachedir'] . 'web.optimizer.stamp.png');
  5340. @copy($this->basepath . 'libs/js/index.php',
  5341. $this->compress_options['javascript_cachedir'] . 'index.php');
  5342. @copy($this->basepath . 'libs/js/yass.loader.js',
  5343. $this->compress_options['javascript_cachedir'] . 'yass.loader.js');
  5344. @copy($this->basepath . 'libs/php/wo.static.php',
  5345. $this->compress_options['css_cachedir'] . 'wo.static.php');
  5346. @chmod($this->compress_options['css_cachedir'] . 'wo.static.php', octdec("0755"));
  5347. @copy($this->basepath . 'libs/php/wo.gzip.php',
  5348. $this->compress_options['css_cachedir'] . 'wo.gzip.php');
  5349. @chmod($this->compress_options['css_cachedir'] . 'wo.gzip.php', octdec("0755"));
  5350. @copy($this->basepath . 'libs/php/wo.merge.php',
  5351. $this->compress_options['css_cachedir'] . 'wo.merge.php');
  5352. @chmod($this->compress_options['css_cachedir'] . 'wo.merge.php', octdec("0755"));
  5353. @copy($this->basepath . 'libs/php/0.gif',
  5354. $this->compress_options['css_cachedir'] . '0.gif');
  5355. /* dirty hack for PHP-Nuke */
  5356. if ($this->cms_version == 'PHP-Nuke') {
  5357. $mainfile = $this->view->paths['absolute']['document_root'] . 'mainfile.php';
  5358. $footer = $this->view->paths['absolute']['document_root'] . 'footer.php';
  5359. $mainfile_content = $this->file_get_contents($mainfile);
  5360. $footer_content = $this->file_get_contents($footer);
  5361. if (!empty($mainfile_content) && !empty($footer_content)) {
  5362. /* create backup */
  5363. @copy($mainfile, $mainfile . '.backup');
  5364. /* update main PHP-Nuke file */
  5365. $return1 = $this->write_file($mainfile,
  5366. preg_replace("/(if\s+\(!ini_get\('register_globals)/",
  5367. 'require(\'' . $this->basepath .
  5368. 'web.optimizer.php\');' . "\n$1",
  5369. preg_replace("/require\('[^\']+\/web.optimizer.php'\);\r?\n?/", "", $mainfile_content)), 1);
  5370. /* create backup */
  5371. @copy($footer, $footer . '.backup');
  5372. /* update footer */
  5373. $return2 = $this->write_file($footer, preg_replace("/global /", 'global \$web_optimizer,', preg_replace("/(\s*ob_end_flush\(\);)/", '\$web_optimizer->finish();' . "\n$1", preg_replace("/(\\\$web_optimizer,|\\\$web_optimizer->finish\(\);\r?\n?)/", "", $footer_content))), 1);
  5374. if (!empty($return1) && !empty($return2)) {
  5375. $auto_rewrite = 1;
  5376. }
  5377. }
  5378. /* another dirty hack for phpBB */
  5379. } elseif ($this->cms_version == 'phpBB') {
  5380. $mainfile = $this->view->paths['absolute']['document_root'] .
  5381. 'includes/functions.php';
  5382. $mainfile_content = $this->file_get_contents($mainfile);
  5383. if (!empty($mainfile_content)) {
  5384. /* create backup */
  5385. @copy($mainfile, $mainfile . '.backup');
  5386. /* remove any old strings regarding Web Optimizer */
  5387. $mainfile_content =
  5388. preg_replace("/\\\$web_optimizer->finish\(\);\r?\n?/", "",
  5389. preg_replace("/require\('[^\']+\/web.optimizer.php'\);\r?\n?/", "",
  5390. $mainfile_content));
  5391. /* add class declaration */
  5392. $mainfile_content =
  5393. preg_replace("/(function\s*page_footer\s*\([^\)]+\)[\r\n\s]*\{)/",
  5394. "$1\n" . 'require(\'' . $this->basepath . 'web.optimizer.php\');',
  5395. $mainfile_content);
  5396. /* add finish */
  5397. $mainfile_content =
  5398. preg_replace("/(\\\$template->display\(['\"]body['\"]\);\r?\n?)/",
  5399. "$1" . '\$web_optimizer->finish();' . "\n",
  5400. $mainfile_content);
  5401. $return = $this->write_file($mainfile, $mainfile_content, 1);
  5402. if (!empty($return)) {
  5403. $auto_rewrite = 1;
  5404. }
  5405. }
  5406. /* one more dirty hack for ipb */
  5407. } elseif ($this->cms_version == 'Invision Power Board') {
  5408. $mainfile = $this->view->paths['absolute']['document_root'] .
  5409. 'sources/classes/class_display.php';
  5410. $mainfile_content = $this->file_get_contents($mainfile);
  5411. if (!empty($mainfile_content)) {
  5412. /* create backup */
  5413. @copy($mainfile, $mainfile . '.backup');
  5414. /* add class declaration */
  5415. $mainfile_content =
  5416. preg_replace("/(print \\\$this->ipsclass->skin\['_wrapper'\];\r?\n?)/",
  5417. 'require(\'' . $this->basepath . 'web.optimizer.php\');' . "\n$1",
  5418. $mainfile_content);
  5419. /* add finish */
  5420. $mainfile_content =
  5421. preg_replace("/(print \\\$this->ipsclass->skin\['_wrapper'\];\r?\n?)/", "$1" . '\$web_optimizer->finish();' . "\n", $mainfile_content);
  5422. $return = $this->write_file($mainfile, $mainfile_content, 1);
  5423. if (!empty($return)) {
  5424. $auto_rewrite = 1;
  5425. }
  5426. }
  5427. /* and for Bitrix */
  5428. } elseif ($this->cms_version == 'Bitrix') {
  5429. $mainfile = $this->view->paths['absolute']['document_root'] . 'bitrix/header.php';
  5430. $footer = $this->view->paths['absolute']['document_root'] . 'bitrix/modules/main/include/epilog_after.php';
  5431. $mainfile_content = $this->file_get_contents($mainfile);
  5432. $footer_content = $this->file_get_contents($footer);
  5433. if (!empty($mainfile_content) && !empty($footer_content)) {
  5434. /* create backup */
  5435. @copy($mainfile, $mainfile . '.backup');
  5436. /* update header */
  5437. $return1 = $this->write_file($mainfile, preg_replace("/<\?/", '<? require(\'' . $this->basepath . 'web.optimizer.php\');' . "\n", $mainfile_content), 1);
  5438. /* create backup */
  5439. @copy($footer, $footer . '.backup');
  5440. /* update footer */
  5441. $return2 = $this->write_file($footer, preg_replace("/(echo\s*\\\$r;\r?\n?)/", "$1\n" . '\$web_optimizer->finish();' . "\n", preg_replace("/\\\$web_optimizer->finish\(\);\r?\n?/", "", $footer_content)), 1);
  5442. if (!empty($return1) && !empty($return2)) {
  5443. $auto_rewrite = 1;
  5444. }
  5445. }
  5446. /* and for Open Slaed */
  5447. } elseif (substr($this->cms_version, 0, 10) == 'Open Slaed') {
  5448. $mainfile = $this->view->paths['absolute']['document_root'] . 'index.php';
  5449. $footer = $this->view->paths['absolute']['document_root'] . 'function/function.php';
  5450. $mainfile_content = $this->file_get_contents($mainfile);
  5451. $footer_content = $this->file_get_contents($footer);
  5452. if (!empty($mainfile_content) && !empty($footer_content)) {
  5453. /* create backup */
  5454. @copy($mainfile, $mainfile . '.backup');
  5455. /* update mainfile */
  5456. $return1 = $this->write_file($mainfile, preg_replace("/(<\?(php)?)/", "$1" . ' require(\'' . $this->basepath . 'web.optimizer.php\');' . "\n", $mainfile_content), 1);
  5457. /* create backup */
  5458. @copy($footer, $footer . '.backup');
  5459. $footer_content = preg_replace('!(readfile\(\$cacheurl\);)!', "$1\n" . 'global $web_optimizer;$web_optimizer->finish();', $footer_content);
  5460. $footer_content = preg_replace('!(ob_end_flush\(\);)!', 'global $web_optimizer;$web_optimizer->finish();' . "\n$1", $footer_content);
  5461. /* update footer */
  5462. $return2 = $this->write_file($footer, $footer_content, 1);
  5463. if (!empty($return1) && !empty($return2)) {
  5464. $auto_rewrite = 1;
  5465. }
  5466. }
  5467. /* and for 4images */
  5468. } elseif ($this->cms_version == '4images') {
  5469. $mainfile = $this->view->paths['absolute']['document_root'] . 'includes/page_header.php';
  5470. $footer = $this->view->paths['absolute']['document_root'] . 'includes/page_footer.php';
  5471. $mainfile_content = $this->file_get_contents($mainfile);
  5472. $footer_content = $this->file_get_contents($footer);
  5473. if (!empty($mainfile_content) && !empty($footer_content)) {
  5474. /* create backup */
  5475. @copy($mainfile, $mainfile . '.backup');
  5476. /* update mainfile */
  5477. $return1 = $this->write_file($mainfile, preg_replace("/(<\?(php)?)/", "$1" . ' require(\'' . $this->basepath . 'web.optimizer.php\');' . "\n", $mainfile_content), 1);
  5478. /* create backup */
  5479. @copy($footer, $footer . '.backup');
  5480. $footer_content = preg_replace('!(exit;)!', 'global $web_optimizer;$web_optimizer->finish();' . "$1", $footer_content);
  5481. /* update footer */
  5482. $return2 = $this->write_file($footer, $footer_content, 1);
  5483. if (!empty($return1) && !empty($return2)) {
  5484. $auto_rewrite = 1;
  5485. }
  5486. }
  5487. /* and for VaM Shop, osCommerce */
  5488. } elseif ($this->cms_version == 'VaM Shop' || $this->cms_version == 'osCommerce') {
  5489. $mainfile = $this->view->paths['absolute']['document_root'] . 'includes/application_top.php';
  5490. $footer = $this->view->paths['absolute']['document_root'] . 'includes/application_bottom.php';
  5491. $mainfile_content = $this->file_get_contents($mainfile);
  5492. $footer_content = $this->file_get_contents($footer);
  5493. if (!empty($mainfile_content) && !empty($footer_content)) {
  5494. /* create backup */
  5495. @copy($mainfile, $mainfile . '.backup');
  5496. /* update mainfile */
  5497. $return1 = $this->write_file($mainfile, preg_replace("/(<\?(php)?)/", "$1" . ' require(\'' . $this->basepath . 'web.optimizer.php\');' . "\n", $mainfile_content), 1);
  5498. /* create backup */
  5499. @copy($footer, $footer . '.backup');
  5500. $footer_content = preg_replace('!(\?>)!s', '$web_optimizer->finish();' . "$1", $footer_content);
  5501. /* update footer */
  5502. $return2 = $this->write_file($footer, $footer_content, 1);
  5503. if (!empty($return1) && !empty($return2)) {
  5504. $auto_rewrite = 1;
  5505. }
  5506. }
  5507. /* and for Social Engine */
  5508. } elseif (substr($this->cms_version, 0, 13) == 'Social Engine') {
  5509. $mainfile = $this->view->paths['absolute']['document_root'] . 'header.php';
  5510. $footer = $this->view->paths['absolute']['document_root'] . 'footer.php';
  5511. $mainfile_content = $this->file_get_contents($mainfile);
  5512. $footer_content = $this->file_get_contents($footer);
  5513. if (!empty($mainfile_content) && !empty($footer_content)) {
  5514. /* create backup */
  5515. @copy($mainfile, $mainfile . '.backup');
  5516. /* update mainfile */
  5517. $return1 = $this->write_file($mainfile, preg_replace("/(<\?(php)?)/", "$1" . ' require(\'' . $this->basepath . 'web.optimizer.php\');' . "\n", $mainfile_content), 1);
  5518. /* create backup */
  5519. @copy($footer, $footer . '.backup');
  5520. $footer_content = preg_replace('!(exit\(\);\r?\n\?>)!s', '$web_optimizer->finish();' . "$1", $footer_content);
  5521. /* update footer */
  5522. $return2 = $this->write_file($footer, $footer_content, 1);
  5523. if (!empty($return1) && !empty($return2)) {
  5524. $auto_rewrite = 1;
  5525. }
  5526. }
  5527. /* and for X-Cart */
  5528. } elseif ($this->cms_version == 'X-Cart') {
  5529. $mainfile = $this->view->paths['absolute']['document_root'] . 'include/func/func.core.php';
  5530. $mainfile_content = $this->file_get_contents($mainfile);
  5531. if (!empty($mainfile_content)) {
  5532. /* create backup */
  5533. @copy($mainfile, $mainfile . '.backup');
  5534. $mainfile_content = preg_replace("!(\\\$templater->assign\(\"is_https_zone\",\s\\\$HTTPS\);\r?\n?)!", "$1" . ' require(\'' . $this->basepath . 'web.optimizer.php\');' . "\n", $mainfile_content);
  5535. $mainfile_content = preg_replace("!(\\\$templater->display\(\\\$tpl\);\r?\n?)!s", "$1" . '$web_optimizer->finish();' . "\n", $mainfile_content);
  5536. /* update mainfile */
  5537. $return = $this->write_file($mainfile, $mainfile_content, 1);
  5538. if (!empty($return)) {
  5539. $auto_rewrite = 1;
  5540. }
  5541. }
  5542. /* and for Koobi */
  5543. } elseif ($this->cms_version == 'Koobi CMS') {
  5544. $mainfile = $this->view->paths['absolute']['document_root'] . 'index.php';
  5545. $c = $this->file_get_contents($mainfile);
  5546. if (!empty($c)) {
  5547. /* create backup */
  5548. @copy($mainfile, $mainfile . '.backup');
  5549. $c = preg_replace("!(define\(\"BASEDIR\",\s*dirname\(__FILE__\)\);\r?\n?)!s", "$1" . ' require(\'' . $this->basepath . 'web.optimizer.php\');' . "\n", $c);
  5550. $c = preg_replace("!(\\\$gz_content\s*=\s*ob_get_clean\(\);\r?\n?)!s", "$1" . '$gz_content = $web_optimizer->finish($gz_content);' . "\n", $c);
  5551. $c = preg_replace("!(\\\$content\s*=\s*ob_get_clean\(\);\r?\n?)!s", "$1" . '$content = $web_optimizer->finish($content);' . "\n", $c);
  5552. /* update mainfile */
  5553. $return = $this->write_file($mainfile, $c, 1);
  5554. if (!empty($return)) {
  5555. $auto_rewrite = 1;
  5556. }
  5557. }
  5558. } else {
  5559. $index = $this->view->paths['absolute']['document_root'] . 'index.php';
  5560. if (substr($this->cms_version, 0, 9) == 'vBulletin') {
  5561. $index = $this->view->paths['absolute']['document_root'] . 'includes/functions.php';
  5562. } elseif ($this->cms_version == 'NetCat') {
  5563. $index = $this->view->paths['absolute']['document_root'] . 'netcat/require/e404.php';
  5564. } elseif ($this->cms_version == 'PHP Fusion') {
  5565. $index = $this->view->paths['absolute']['document_root'] . 'themes/templates/footer.php';
  5566. } elseif (substr($this->cms_version, 0, 11) == 'Shop-Script') {
  5567. $index = $this->view->paths['absolute']['document_root'] . 'published/SC/html/scripts/index.php';
  5568. }
  5569. $fp = @fopen($index, "r");
  5570. if ($fp) {
  5571. $content_saved = '';
  5572. /* generic code to include */
  5573. $web_optimizer_handler = '$not_buffered=1;require(\'' .
  5574. $this->basepath .
  5575. 'web.optimizer.php\');function weboptimizer_shutdown($content){if(!empty($content)){global $webo_uri;$not_buffered=1;require(\'' .
  5576. $this->basepath .
  5577. 'web.optimizer.php\');if(!empty($web_optimizer)){$weboptimizer_content=$web_optimizer->finish($content);}if(!empty($weboptimizer_content)){$content=$weboptimizer_content;}return $content;}}ob_start(\'weboptimizer_shutdown\');';
  5578. while ($index_string = fgets($fp)) {
  5579. $content_saved .= preg_replace("/(require\('[^\']+\/web.optimizer.php'\)|\\\$web_optimizer->finish\(\));\r?\n?/i", "", $index_string);
  5580. }
  5581. @fclose($fp);
  5582. /* fix for Joomla 1.0 */
  5583. if (preg_match("/Joomla! 1\.0/", $this->cms_version)) {
  5584. $content_saved = preg_replace("/(initGzip\(\);\r?\n)/i", 'require(\'' . $this->basepath . 'web.optimizer.php\');' . "\n$1", $content_saved);
  5585. /* fix for Joomla 1.5+ */
  5586. } elseif (preg_match("/Joomla! 1\.[56789]/", $this->cms_version)) {
  5587. $content_saved = preg_replace("/(\\\$mainframe\s*=&\s*JFactory::getApplication\(['\"]site['\"]\);\r?\n)/i", "$1" . 'require(\'' . $this->basepath . 'web.optimizer.php\');' . "\n", $content_saved);
  5588. /* fix for Joostina */
  5589. } elseif (preg_match("/Joostina/", $this->cms_version)) {
  5590. $content_saved = preg_replace("/(require_once\s*\([^\)]+frontend\.php)/i", 'require(\'' . $this->basepath . 'web.optimizer.php\');' . "\n$1", $content_saved);
  5591. /* fix for vBulletin */
  5592. } elseif (substr($this->cms_version, 0, 9) == 'vBulletin') {
  5593. $content_saved = preg_replace("/(\(\\\$hook\s*=\s*vBulletinHook::fetch_hook\('global_complete'\)\))/i", 'require(\'' . $this->basepath . 'web.optimizer.php\');' . "\n$1", $content_saved);
  5594. /* fix for CMS Made Simple */
  5595. } elseif (substr($this->cms_version, 0, 15) == 'CMS Made Simple') {
  5596. $content_saved = preg_replace("/(echo\s*\\\$html;)/", 'require(\'' . $this->basepath . 'web.optimizer.php\');' . "\n$1", $content_saved);
  5597. /* fix for UMI.CMS */
  5598. } elseif (substr($this->cms_version, 0, 7) == 'UMI.CMS') {
  5599. $content_saved = preg_replace("/(sha1.*)\r?\n([\s\t]*echo\s*\\\$res;)/", "$1\n" . 'require(\'' . $this->basepath . 'web.optimizer.php\');' . "\n$2", $content_saved);
  5600. /* fix for PHP Fusion */
  5601. } elseif ($this->cms_version == 'PHP Fusion') {
  5602. $content_saved = preg_replace("/(require_once INCLUDES.\"footer_includes.php\";\r?\n)/", "$1" . 'require(\'' . $this->basepath . 'web.optimizer.php\');' . "\n", $content_saved);
  5603. /* fix for Shop-Script */
  5604. } elseif (substr($this->cms_version, 0, 11) == 'Shop-Script') {
  5605. $content_saved = preg_replace("!(include_once\(DIR_CFG\s*.\s*'/connect.inc.wa.php'\);\r?\n)!is", "$1" . $web_optimizer_handler, $content_saved);
  5606. } elseif (substr($content_saved, 0, 2) == '<?') {
  5607. /* add require block */
  5608. $content_saved = preg_replace("/^<\?(php)?(\s|\r?\n)/i", '<?php /* WEBO Site SpeedUp */' . $web_optimizer_handler . '?><?php' . "\n", $content_saved);
  5609. } else {
  5610. $content_saved = '<?php /* WEBO Site SpeedUp */' . $web_optimizer_handler . '?>' . $content_saved;
  5611. }
  5612. /* fix for DataLife Engine */
  5613. if (substr($this->cms_version, 0, 15) == 'DataLife Engine') {
  5614. $content_saved = preg_replace("/(GzipOut\s*\(\);)/", '$web_optimizer->finish();' . "\n$1", $content_saved);
  5615. /* fix for vBulletin */
  5616. } elseif (substr($this->cms_version, 0, 9) == 'vBulletin') {
  5617. $content_saved = preg_replace("/(flush\s*\(\);[\r\n\s\t]*\})/", "$1\n" . '$web_optimizer->finish();', $content_saved);
  5618. /* fix for Joomla! 1.0 */
  5619. } elseif (preg_match("/Joomla! 1\.0/", $this->cms_version)) {
  5620. $content_saved = preg_replace("/(doGzip\(\);\r?\n)/i", '$web_optimizer->finish();' . "\n$1" , $content_saved);
  5621. /* fix for CMS Made Simple */
  5622. } elseif (substr($this->cms_version, 0, 15) == 'CMS Made Simple') {
  5623. $content_saved = preg_replace("/(echo\s*\\\$html;)/", "$1\n" . '$web_optimizer->finish();', $content_saved);
  5624. /* fix for UMI.CMS */
  5625. } elseif (substr($this->cms_version, 0, 7) == 'UMI.CMS') {
  5626. $content_saved = preg_replace("/(web\.optimizer.*\r?\n[\s\t]*echo\s*\\\$res;)/", "$1\n" . '$web_optimizer->finish();', $content_saved);
  5627. /* fix for MaxDev */
  5628. } elseif (substr($this->cms_version, 0, 6) == 'MaxDev') {
  5629. $content_saved = preg_replace("/(\\\$output->PrintPage\(\);)/", "$1" . '$web_optimizer->finish();', $content_saved);
  5630. $content_saved = preg_replace("/(\}[\r\n\t\s]+)(exit;)/", "$1" . '$web_optimizer->finish();' . "$2", $content_saved);
  5631. /* fix for PHP Fusion */
  5632. } elseif ($this->cms_version == 'PHP Fusion') {
  5633. $content_saved = preg_replace("/(echo handle_output\(\\\$output\);\r?\n)/", "$1" . '$web_optimizer->finish();', $content_saved);
  5634. /* fix for Contao */
  5635. } elseif (substr($this->cms_version, 0, 6) == 'Contao') {
  5636. $content_saved = preg_replace("/echo \\\$strBuffer/", "global \\\$web_optimizer;echo \\\$web_optimizer->finish(\\\$strBuffer)", $content_saved);
  5637. $content_saved = preg_replace("/(\\\$objIndex->run\(\);\r?\n)/", "$1" . '$web_optimizer->finish();' . "\r\n", $content_saved);
  5638. } elseif (preg_match("/\?>[\r\n\s]*$/", $content_saved) && substr($this->cms_version, 0, 11) != 'Shop-Script') {
  5639. /* small fix for Joostina */
  5640. if (substr($this->cms_version, 0, 8) == 'Joostina') {
  5641. $content_saved = preg_replace("/(exit\s*\(\);\r?\n\?>)[\r\n\s]*$/", '$web_optimizer->finish();' . "\n$1", $content_saved);
  5642. }
  5643. } elseif (substr($this->cms_version, 0, 11) != 'Shop-Script') {
  5644. /* fix for Drupal / Joomla / others on not-closed ?> */
  5645. $content_saved .= '$web_optimizer->finish();';
  5646. }
  5647. /* restrict changes in binary files, i.e. Zend Optimized ones */
  5648. if (substr($content_saved, 0, 12) != '<?php @Zend;') {
  5649. /* create backup */
  5650. @copy($index, $index . '.backup');
  5651. $return = $this->write_file($index, $content_saved, 1);
  5652. if (!empty($return)) {
  5653. $auto_rewrite = 1;
  5654. }
  5655. } else {
  5656. $auto_rewrite = 3;
  5657. }
  5658. /* additional change of cache plugins */
  5659. if (preg_match("/Joomla! 1\.[56789]/", $this->cms_version)) {
  5660. /* System-Cache plugin */
  5661. $cache_file = $this->view->paths['absolute']['document_root'] . 'plugins/system/cache.php';
  5662. if (@is_file($cache_file)) {
  5663. @copy($cache_file, $cache_file . '.backup');
  5664. $content = preg_replace("/(\\\$mainframe->close)/", 'global \$web_optimizer;\$web_optimizer->finish();' . "$1", $this->file_get_contents($cache_file));
  5665. $this->write_file($cache_file, $content);
  5666. }
  5667. /* JRE component */
  5668. $cache_file = $this->view->paths['absolute']['document_root'] . 'administrator/components/com_jrecache/includes/cache_handler.php';
  5669. if (@is_file($cache_file)) {
  5670. @copy($cache_file, $cache_file . '.backup');
  5671. $content = preg_replace("/(echo \\\$output;)/", 'require(\'' . $this->basepath . 'web.optimizer.php\');' . "$1" . '\$web_optimizer->finish();', $this->file_get_contents($cache_file));
  5672. $this->write_file($cache_file, $content);
  5673. }
  5674. }
  5675. if (preg_match("/Joomla! 1\.0/", $this->cms_version)) {
  5676. /* PageCache component */
  5677. $cache_file = $this->view->paths['absolute']['document_root'] . 'components/com_pagecache/pagecache.class.php';
  5678. if (@is_file($cache_file)) {
  5679. @copy($cache_file, $cache_file . '.backup');
  5680. $content = preg_replace("/(echo \\\$data;)/", "$1" . 'global \$web_optimizer;\$web_optimizer->finish();', $this->file_get_contents($cache_file));
  5681. $this->write_file($cache_file, $content);
  5682. }
  5683. /* System-Cache mambot */
  5684. $cache_file = $this->view->paths['absolute']['document_root'] . 'mambots/system/cache.php';
  5685. if (@is_file($cache_file)) {
  5686. @copy($cache_file, $cache_file . '.backup');
  5687. $content = preg_replace("/(echo \\\$content;)/", 'require(\'' . $this->basepath . 'web.optimizer.php\');' . "$1" . '\$web_optimizer->finish();', $this->file_get_contents($cache_file));
  5688. $this->write_file($cache_file, $content);
  5689. }
  5690. }
  5691. if (substr($this->cms_version, 0, 5) == 'XOOPS') {
  5692. $cache_file = $this->view->paths['absolute']['document_root'] . 'class/theme.php';
  5693. if (@is_file($cache_file)) {
  5694. @copy($cache_file, $cache_file . '.backup');
  5695. $content = preg_replace("/(\\\$this->render\([^\(]+\);)/", "$1" . 'global \$web_optimizer;\$web_optimizer->finish();', $this->file_get_contents($cache_file));
  5696. $this->write_file($cache_file, $content);
  5697. }
  5698. }
  5699. }
  5700. }
  5701. /* execute plugin-specific logic */
  5702. $plugins = explode(" ", $this->compress_options['plugins']);
  5703. if (is_array($plugins)) {
  5704. foreach ($plugins as $plugin) {
  5705. $plugin_file = $this->basepath . 'plugins/' . $plugin . '.php';
  5706. if (@is_file($plugin_file)) {
  5707. include($plugin_file);
  5708. $web_optimizer_plugin->onInstall($this->view->paths['absolute']['document_root']);
  5709. }
  5710. }
  5711. }
  5712. /* write .htaccess */
  5713. $options = $this->get_options();
  5714. $this->input = array();
  5715. foreach ($options as $group) {
  5716. if (is_array($group)) {
  5717. foreach ($group as $key => $option) {
  5718. if (is_array($option)) {
  5719. $this->input['wss_' . $key] = $option['value'];
  5720. }
  5721. }
  5722. }
  5723. }
  5724. $this->set_options();
  5725. $this->write_htaccess();
  5726. if (!$skip) {
  5727. $this->install_system(2 - $auto_rewrite);
  5728. }
  5729. }
  5730. /**
  5731. * Get all loaded Apache modules and do some magic
  5732. *
  5733. **/
  5734. function get_modules () {
  5735. /* check for Apache installation, only if curl is disabled */
  5736. if (function_exists('apache_get_modules')) {
  5737. $amodules = apache_get_modules();
  5738. } else {
  5739. /* if PHP installed as CGI module -- we don't need .htaccess */
  5740. $amodules = array();
  5741. }
  5742. $this->apache_modules = array();
  5743. $apache_modules = array();
  5744. if (in_array('mod_expires', $amodules)) {
  5745. $apache_modules[] = 'mod_expires';
  5746. }
  5747. if (in_array('mod_gzip', $amodules)) {
  5748. $apache_modules[] = 'mod_gzip';
  5749. }
  5750. if (in_array('mod_deflate', $amodules) && (in_array('mod_filter', $amodules) || in_array('mod_ext_filter', $amodules))) {
  5751. $apache_modules[] = 'mod_deflate';
  5752. }
  5753. if (in_array('mod_headers', $amodules)) {
  5754. $apache_modules[] = 'mod_headers';
  5755. }
  5756. if (in_array('mod_setenvif', $amodules)) {
  5757. $apache_modules[] = 'mod_setenvif';
  5758. }
  5759. if (in_array('mod_mime', $amodules)) {
  5760. $apache_modules[] = 'mod_mime';
  5761. }
  5762. if (in_array('mod_rewrite', $amodules)) {
  5763. $apache_modules[] = 'mod_rewrite';
  5764. }
  5765. $cachedir = empty($this->compress_options['javascript_cachedir']) ?
  5766. $this->view->paths['full']['current_directory'] . 'cache/' :
  5767. $this->compress_options['javascript_cachedir'];
  5768. $root = empty($this->compress_options['document_root']) ?
  5769. $this->view->paths['full']['document_root'] :
  5770. $this->compress_options['document_root'];
  5771. /* don't check modules more than 9 seconds */
  5772. $timer = time();
  5773. $check_modules_curl = @function_exists('curl_init') && strpos($_SERVER['SERVER_SOFTWARE'], 'Win') === false;
  5774. /* detect if hosting is compatible with SynLinks rule (included in core) */
  5775. if (($check_modules_curl && $this->check_apache_module('Options +FollowSymLinks', $root, $cachedir, 'mod_symlinks')) || strpos($_SERVER['SERVER_SOFTWARE'], 'Win') === false) {
  5776. $this->apache_modules[] = 'mod_symlinks';
  5777. }
  5778. /* download restricted file, if sizes are equal =? file isn't restricted => htaccess won't work */
  5779. /* can't get this code (htaccess detection) on both Denwer with curl, non-curl,
  5780. CGI with curl and Apache with curl environments. See
  5781. http://code.google.com/p/web-optimizator/issues/detail?id=369
  5782. $this->view->download(str_replace($root, "http://" . $_SERVER['HTTP_HOST'] . "/", $this->basepath) . 'libs/php/css.sprites.php', $cachedir . 'htaccess.test');
  5783. if (@is_file($cachedir . 'htaccess.test') && !@filesize($cachedir . 'htaccess.test')) {
  5784. $this->apache_modules = array(); */
  5785. $modules = array(
  5786. 'mod_gzip' => 'mod_gzip_on Yes
  5787. mod_gzip_can_negotiate Yes
  5788. mod_gzip_keep_workfiles No
  5789. mod_gzip_minimum_file_size 500
  5790. mod_gzip_maximum_file_size 5000000
  5791. mod_gzip_maximum_inmem_size 60000
  5792. mod_gzip_min_http 1000
  5793. mod_gzip_handle_methods GET POST
  5794. mod_gzip_item_exclude reqheader \"User-agent: Mozilla/4.0[678]\"
  5795. mod_gzip_dechunk No',
  5796. 'mod_deflate' => 'AddOutputFilterByType DEFLATE text/javascript application/javascript application/x-javascript text/x-js text/ecmascript application/ecmascript text/vbscript text/fluffscript',
  5797. 'mod_headers' => 'Header append Cache-Control public',
  5798. 'mod_expires' => 'ExpiresActive On',
  5799. 'mod_setenvif' => 'BrowserMatch SV1; !no_gzip',
  5800. 'mod_mime' => '<FilesMatch \.otf\.gz$>
  5801. ForceType font/otf
  5802. </FilesMatch>',
  5803. 'mod_rewrite' => "RewriteEngine On
  5804. RewriteRule index\.php$ " .
  5805. str_replace($root, "/", str_replace("\\", "/", dirname(__FILE__))) .
  5806. "/../libs/js/yass.loader.js"
  5807. );
  5808. /* test only existent modules or all if Apache doens't exist */
  5809. $test_all = count($apache_modules) ? 0 : 1;
  5810. /* exclude Windows servers from testing */
  5811. if ($check_modules_curl) {
  5812. /* detect modules one by one, it can be CGI environment */
  5813. foreach ($modules as $key => $value) {
  5814. if ((!in_array('mod_deflate', $apache_modules) || $key != 'mod_gzip') && ($test_all || in_array($key, $apache_modules))) {
  5815. if ($this->check_apache_module($value, $root, $cachedir, $key)) {
  5816. $this->apache_modules[] = $key;
  5817. }
  5818. }
  5819. }
  5820. } else {
  5821. $this->apache_modules = $apache_modules;
  5822. }
  5823. @unlink($cachedir . 'htaccess.test');
  5824. }
  5825. /**
  5826. * Checks exitence of current Apache module
  5827. *
  5828. **/
  5829. function check_apache_module ($rule, $root, $cachedir, $module) {
  5830. $gzip = strpos($rule, 'DEFLATE') !== false || strpos($rule, 'mod_gzip') !== false;
  5831. if ($module == 'mod_symlinks' || $module == 'mod_gzip') {
  5832. $testfile = 'libs/js/index.php';
  5833. $curlfile = 'libs/js/index.php';
  5834. $size = 131;
  5835. } else {
  5836. $testfile = $curlfile = 'libs/js/yass.loader.js';
  5837. $size = @filesize($this->basepath . $testfile);
  5838. if ($module == 'mod_rewrite') {
  5839. $curlfile = 'libs/js/index.php';
  5840. }
  5841. }
  5842. $return = false;
  5843. $this->write_file($this->basepath . 'libs/js/.htaccess', $rule);
  5844. $recursive = 0;
  5845. while (!($filesize = @filesize($cachedir . 'module.test')) &&
  5846. $recursive++ < 10) {
  5847. $curl = $this->view->download(str_replace(realpath($root),
  5848. 'http' . (empty($_SERVER['HTTPS']) ? '' : 's') . '://' . $_SERVER['HTTP_HOST'],
  5849. realpath($this->basepath)) . '/' .
  5850. $curlfile . '?' . rand(), $cachedir . 'module.test', 1, 0,
  5851. $this->compress_options['external_scripts']['user'],
  5852. $this->compress_options['external_scripts']['pass']);
  5853. if (round($curl[1]) == 301) {
  5854. /* switch from PHP for JS, if recursion w/o result */
  5855. if ($module == 'mod_symlinks') {
  5856. $testfile = $curlfile = 'libs/js/yass.loader.js';
  5857. /* or just disable module */
  5858. } else {
  5859. $recursive = 10;
  5860. }
  5861. }
  5862. }
  5863. /* it it's possible to get file => module works, also fix for normal return on internal empty requests */
  5864. if ($filesize == $size || ($curl[1] == 200 && !$filesize)) {
  5865. $return = true;
  5866. /* fix for LiteSpeed bug on .htaccess rights + mod_rewrite
  5867. + one more LiteSpeed bug with delay with .htaccess application
  5868. */
  5869. } elseif (($curl[1] == 400 || $filesize == 131) &&
  5870. $module == 'mod_rewrite' &&
  5871. !empty($_SERVER["SERVER_SOFTWARE"]) &&
  5872. $_SERVER["SERVER_SOFTWARE"] == 'LiteSpeed') {
  5873. $return = true;
  5874. }
  5875. /* check for gzip / deflate support */
  5876. if ($gzip && !$curl[0]) {
  5877. $return = false;
  5878. }
  5879. @unlink($cachedir . 'module.test');
  5880. @unlink($this->basepath . 'libs/js/.htaccess');
  5881. return $return;
  5882. }
  5883. /**
  5884. * Consequenty emulate different stages of optimization process
  5885. * To prevent initial delay for optimized website and PHP timeout
  5886. *
  5887. **/
  5888. function chained_load ($index = false) {
  5889. /* force cache reload via index.php */
  5890. if ($index) {
  5891. $this->write_progress(8);
  5892. $test_file = $this->compress_options['html_cachedir'] . 'optimizing.php';
  5893. $chain_file = $this->compress_options['html_cachedir'] . 'last.chain';
  5894. /* load home page */
  5895. $this->view->download('http://' . $_SERVER['HTTP_HOST'] . $index . '?web_optimizer_disabled=1', $test_file);
  5896. $contents = $this->file_get_contents($test_file);
  5897. $this->write_file($test_file, "<?php require('" .
  5898. $this->basepath . "web.optimizer.php'); ?>" .
  5899. preg_replace("/<\?xml[^>]+\?>/", "", $contents) .
  5900. '<?php $web_optimizer->finish(); ?>', 1);
  5901. $this->write_progress(9);
  5902. /* then iterate through its local copy, prevent DDoS */
  5903. if (time() - @filemtime($chain_file) > 60) {
  5904. $this->view->download('http://' . $_SERVER['HTTP_HOST'] . '/' .
  5905. str_replace($this->compress_options['document_root'], '',
  5906. $this->compress_options['html_cachedir']) .
  5907. 'optimizing.php?web_optimizer_stage=10&web_optimizer_debug=' . rand() . '&password=' . $this->compress_options['password'],
  5908. $this->compress_options['html_cachedir'] . 'chained.load', 60);
  5909. }
  5910. @unlink($this->compress_options['javascript_cachedir'] . 'progress.php');
  5911. @unlink($this->compress_options['html_cachedir'] . 'chained.load');
  5912. @unlink($test_file);
  5913. @touch($chain_file);
  5914. /* or via cached HTML */
  5915. } else {
  5916. $test_file = $this->basepath . 'cache/optimizing.php';
  5917. $this->write_progress(8);
  5918. /* try to download main file */
  5919. $this->view->download('http://' . $_SERVER['HTTP_HOST'] . '/?web_optimizer_disabled=1', $test_file);
  5920. $this->write_progress(9);
  5921. $contents = $this->file_get_contents($test_file);
  5922. if (!empty($contents)) {
  5923. $return = $this->write_file($test_file, "<?php require('" .
  5924. $this->basepath .
  5925. "web.optimizer.php'); ?>" .
  5926. preg_replace("/<\?xml[^>]+\?>/", "", $contents) .
  5927. '<?php $web_optimizer->finish(); ?>', 1);
  5928. if (!empty($return)) {
  5929. $this->write_progress(10);
  5930. $this->input['user']['auto_rewrite'] =
  5931. empty($this->input['user']['auto_rewrite']) ? array() :
  5932. $this->input['user']['auto_rewrite'];
  5933. $this->input['user']['auto_rewrite']['enabled'] =
  5934. empty($this->input['user']['auto_rewrite']['enabled']) ? 0 : 1;
  5935. header('Location: ' .
  5936. str_replace($this->compress_options['document_root'], '',
  5937. $this->compress_options['html_cachedir']) .
  5938. 'optimizing.php?web_optimizer_stage=10&password=' .
  5939. $this->input['user']['password'] .
  5940. '&username=' .
  5941. $this->input['user']['username'] .
  5942. '&auto_rewrite=' .
  5943. $this->input['user']['auto_rewrite']['enabled'] .
  5944. '&cache_version=' .
  5945. $this->cache_version .
  5946. '&web_optimizer_debug=' . rand());
  5947. die();
  5948. }
  5949. }
  5950. }
  5951. }
  5952. /**
  5953. * Saves all admin options
  5954. *
  5955. **/
  5956. function save_options ($mode = 0) {
  5957. $options = array();
  5958. switch ($mode) {
  5959. case 1:
  5960. foreach($this->compress_options as $key => $option) {
  5961. if (is_array($option)) {
  5962. foreach($option as $option_name => $option_value) {
  5963. if (isset($this->input['wss_' . strtolower($key) . '_' . strtolower($option_name)])) {
  5964. $options["['" .
  5965. strtolower($key) . "']['" .
  5966. strtolower($option_name) . "']"] = $this->input['wss_' .
  5967. strtolower($key) . '_' .
  5968. strtolower($option_name)];
  5969. }
  5970. }
  5971. } else {
  5972. if (isset($this->input['wss_' . strtolower($key)])) {
  5973. $options["['" . strtolower($key)
  5974. . "']"] = $this->input['wss_' . strtolower($key)];
  5975. }
  5976. }
  5977. }
  5978. break;
  5979. default:
  5980. foreach($this->compress_options as $key => $option) {
  5981. if (is_array($option)) {
  5982. foreach($option as $option_name => $option_value) {
  5983. $options["['" . strtolower($key) . "']['" . strtolower($option_name) . "']"] = $option_value;
  5984. }
  5985. } else {
  5986. $options["['" . strtolower($key) . "']"] = $option;
  5987. }
  5988. }
  5989. break;
  5990. }
  5991. $this->save_option('', '', $options);
  5992. }
  5993. /**
  5994. * Saves an admin option
  5995. *
  5996. **/
  5997. function save_option ($option_name, $option_value, $options = array()) {
  5998. /* See if file exists */
  5999. $option_file = $this->basepath . $this->options_file;
  6000. if (!@is_file($option_file)) {
  6001. @copy($this->basepath . 'config.safe.php', $option_file);
  6002. @chmod($option_file, octdec("0644"));
  6003. }
  6004. $content = $this->file_get_contents($option_file);
  6005. if ($content) {
  6006. if (!count($options)) {
  6007. $options = array($option_name => $option_value);
  6008. }
  6009. if (is_array($options)) {
  6010. /* bunch save for options */
  6011. foreach ($options as $option_name => $option_value) {
  6012. /* make password salt safe */
  6013. if ($option_name == "['htpasswd']") {
  6014. $option_value = str_replace('$', '#', $option_value);
  6015. /* make paths uniform (Windows-Linux). Thx to dmiFedorenko */
  6016. } else {
  6017. $option_value = str_replace('$', '\\\$', preg_replace("!(https?|ftp):/!", "$1://", str_replace('\\\\\\', '', str_replace('//', '/', str_replace('\\', '/', $option_value)))));
  6018. }
  6019. $content = preg_replace("@(" . preg_quote($option_name) . ")\s*=\s*\"(.*?)\"@is","$1 = \"" . $option_value . "\"", $content);
  6020. }
  6021. if (!$this->write_file($option_file, $content, 1)) {
  6022. $this->error[0] = 1;
  6023. } else {
  6024. /* re-new values in current options' array */
  6025. $options = explode("']", $option_name);
  6026. if (count($options) == 2) {
  6027. $this->compress_options[str_replace("['", '', $options[0])] = $option_value;
  6028. } else {
  6029. $this->compress_options[str_replace("['", '', $options[0])][str_replace("['", '', $options[1])] = $option_value;
  6030. }
  6031. }
  6032. }
  6033. } else {
  6034. $this->error[0] = 1;
  6035. }
  6036. }
  6037. /**
  6038. * Check password
  6039. *
  6040. **/
  6041. function check_password ($rewrite = 0) {
  6042. /* If passing a username and pass, don't md5 encode */
  6043. if ((!empty($this->input['wss_password']) &&
  6044. ($this->compress_options['password'] ==
  6045. md5($this->input['wss_password'])) ||
  6046. (!empty($this->input['wss__password']) &&
  6047. $this->compress_options['password'] ==
  6048. $this->input['wss__password'])) ||
  6049. /* if we use .htaccess */
  6050. (isset($_SERVER['PHP_AUTH_USER']) &&
  6051. $this->compress_options['username'] ==
  6052. $_SERVER['PHP_AUTH_USER'] &&
  6053. $this->compress_options['htaccess']['access'])) {
  6054. $this->access = 1;
  6055. } else {
  6056. $this->access = 0;
  6057. }
  6058. }
  6059. /**
  6060. * Protects Web Optimizer folder via htpasswd
  6061. *
  6062. **/
  6063. function protect_installation() {
  6064. $htaccess = $this->basepath . '.htaccess';
  6065. $htaccess_content = $this->file_get_contents($htaccess);
  6066. /* clean current content */
  6067. $htaccess_content = preg_replace("!\r?\n# Web Optimizer protection(\r?\n.*)*Web Optimizer protection end!", "", $htaccess_content);
  6068. $htaccess_content .= '
  6069. # Web Optimizer protection';
  6070. $this->error = $this->error ? $this->error : array();
  6071. if (!empty($this->compress_options['htaccess']['access'])) {
  6072. $htpasswd = $this->basepath . '.htpasswd';
  6073. $this->write_file($htpasswd,
  6074. $this->compress_options['username'] .
  6075. str_replace("#", "$", $this->compress_options['htpasswd']));
  6076. if (@is_file($htpasswd)) {
  6077. /* add secure protection via htpasswd */
  6078. $htaccess_content .= '
  6079. AuthType Basic
  6080. AuthName "WEBO Site SpeedUp Installation"
  6081. AuthUserFile ' . $htpasswd . '
  6082. require valid-user';
  6083. } else {
  6084. $this->error[8] = 1;
  6085. }
  6086. }
  6087. $htaccess_content .= '
  6088. <Files .htpasswd>
  6089. Deny from all
  6090. </Files>
  6091. # Web Optimizer protection end';
  6092. /* create backup */
  6093. @copy($htaccess, $htaccess . '.backup');
  6094. if (!$this->write_file($htaccess, $htaccess_content) &&
  6095. !empty($this->compress_options['htaccess']['access'])) {
  6096. $this->error[9] = 1;
  6097. }
  6098. }
  6099. /**
  6100. * Creates password hash for htpasswd file
  6101. * thx to mikey_nich (at) hotmail . com
  6102. *
  6103. **/
  6104. function encrypt_password($plainpasswd) {
  6105. $salt = substr(str_shuffle("abcdefghijklmnopqrstuvwxyz0123456789"), 0, 8);
  6106. $len = strlen($plainpasswd);
  6107. $text = $plainpasswd . '$apr1$' . $salt;
  6108. $bin = pack("H32", md5($plainpasswd . $salt . $plainpasswd));
  6109. $tmp = '';
  6110. for($i = $len; $i > 0; $i -= 16) {
  6111. $text .= substr($bin, 0, min(16, $i));
  6112. }
  6113. for($i = $len; $i > 0; $i >>= 1) {
  6114. $text .= ($i & 1) ? chr(0) : $plainpasswd{0};
  6115. }
  6116. $bin = pack("H32", md5($text));
  6117. for($i = 0; $i < 1000; $i++) {
  6118. $new = ($i & 1) ? $plainpasswd : $bin;
  6119. if ($i % 3) {
  6120. $new .= $salt;
  6121. }
  6122. if ($i % 7) {
  6123. $new .= $plainpasswd;
  6124. }
  6125. $new .= ($i & 1) ? $bin : $plainpasswd;
  6126. $bin = pack("H32", md5($new));
  6127. }
  6128. for ($i = 0; $i < 5; $i++) {
  6129. $k = $i + 6;
  6130. $j = $i + 12;
  6131. if ($j == 16) {
  6132. $j = 5;
  6133. }
  6134. $tmp = $bin[$i].$bin[$k].$bin[$j].$tmp;
  6135. }
  6136. $tmp = chr(0).chr(0).$bin[11].$tmp;
  6137. $tmp = strtr(strrev(substr(base64_encode($tmp), 2)),
  6138. "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",
  6139. "./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz");
  6140. return "$" . "apr1" . "$" . $salt . "$" . $tmp;
  6141. }
  6142. /**
  6143. * Get current PHP system info
  6144. *
  6145. **/
  6146. function system_info($root) {
  6147. if (!empty($this->cms_version)) {
  6148. return $this->cms_version;
  6149. }
  6150. /* Wordpress */
  6151. if (@is_file($root . 'wp-includes/version.php')) {
  6152. $wp_version = '1.0.0';
  6153. require($root . 'wp-includes/version.php');
  6154. return 'Wordpress ' . $wp_version;
  6155. } elseif (@is_file($root . 'modules/system/system.info')) {
  6156. /* Drupal */
  6157. $drupal_version = '1.0.0';
  6158. $fp = @fopen($root . 'modules/system/system.info', "r");
  6159. if ($fp) {
  6160. while ($str = fgets($fp)) {
  6161. if (strstr($str, 'version = "')) {
  6162. $drupal_version = preg_replace('/version\s+=\s+"([0-9.]*?)"/', "$1", $str);
  6163. }
  6164. }
  6165. }
  6166. return 'Drupal ' . trim($drupal_version);
  6167. /* Joomla 1.5 */
  6168. } elseif (@is_file($root . 'libraries/joomla/version.php')) {
  6169. return 'Joomla! 1.5';
  6170. } elseif (@is_dir($root . 'includes')) {
  6171. /* for PHP-Nuke 8.0 */
  6172. if (@is_file($root . 'modules/Journal/copyright.php') && @is_file($root . 'footer.php') && @is_file($root . 'mainfile.php')) {
  6173. return 'PHP-Nuke';
  6174. /* vBulletin */
  6175. } elseif (@is_file($root . 'includes/class_core.php')) {
  6176. require($root . 'includes/class_core.php');
  6177. $vbulletin_version = '';
  6178. if (defined('FILE_VERSION')) {
  6179. $vbulletin_version = ' ' . FILE_VERSION;
  6180. }
  6181. return 'vBulletin' . $vbulletin_version;
  6182. /* phpBB (3.0) */
  6183. } elseif (@is_file($root . 'includes/functions_privmsgs.php')) {
  6184. return 'phpBB';
  6185. /* osCommerce (2.2) */
  6186. } elseif (@is_file($root . 'includes/tld.txt')) {
  6187. return 'osCommerce';
  6188. /* Joomla 1.0, Joostina */
  6189. } elseif (@is_file($root . 'includes/version.php')) {
  6190. define('_VALID_MOS', 1);
  6191. $joomla_version = '1.0';
  6192. $joomla_title = 'Joomla!';
  6193. if (substr(phpversion(), 0, 1) == 4) {
  6194. if (!class_exists('joomlaVersion')) {
  6195. require($root . 'includes/version.php');
  6196. } else {
  6197. $_VERSION = new joomlaVersion();
  6198. }
  6199. } else {
  6200. if (!class_exists('joomlaVersion', false)) {
  6201. require($root . 'includes/version.php');
  6202. } else {
  6203. $_VERSION = new joomlaVersion();
  6204. }
  6205. }
  6206. $joomla_version = empty($_VERSION->CMS_ver) ? ($_VERSION->RELEASE . '.' . $_VERSION->DEV_LEVEL) : $_VERSION->CMS_ver;
  6207. $joomla_title = empty($_VERSION->CMS) ? $_VERSION->PRODUCT : $_VERSION->CMS;
  6208. return $joomla_title . ' ' . $joomla_version;
  6209. /* 4images */
  6210. } elseif (@is_file($root . 'postcards.php')) {
  6211. return '4images';
  6212. /* VaM Shop */
  6213. } elseif (@is_file($root . 'includes/application_top.php')) {
  6214. return 'VaM Shop';
  6215. /* MaxDev Pro */
  6216. } elseif (@is_file($root . 'includes/mdHTML.php')) {
  6217. return 'MaxDev Pro';
  6218. /* PHP Fusion */
  6219. } elseif (@is_dir($root . 'infusions')) {
  6220. return 'PHP Fusion';
  6221. /* Magento */
  6222. } elseif (@is_file($root . '/app/Mage.php')) {
  6223. return 'Magento';
  6224. /* Shop-Script */
  6225. } elseif (@is_file($root . 'published/SC/updates/versions.php')) {
  6226. @require($root . 'published/SC/updates/versions.php');
  6227. $version = array_pop(array_keys($_VERSIONS));
  6228. return 'Shop-Script ' . floor($version/100) . '.' . ($version%100);
  6229. }
  6230. /* Typo 3 */
  6231. } elseif (@is_dir($root . 'typo3conf')) {
  6232. $TYPO3_CONF_VARS = array('SYS' => array('compat_version' => '4.2'));
  6233. if (@is_file($root . 'typo3conf/localconf.php')) {
  6234. require($root . 'typo3conf/localconf.php');
  6235. }
  6236. return 'Typo3 ' . $TYPO3_CONF_VARS['SYS']['compat_version'];
  6237. /* Simpla */
  6238. } elseif (@is_file($root . 'Storefront.class.php')) {
  6239. return 'Simpla';
  6240. /* Etomate 1.0, MODx */
  6241. } elseif (@is_file($root . 'manager/includes/version.inc.php')) {
  6242. require($root . 'manager/includes/version.inc.php');
  6243. if (empty($full_appname)) {
  6244. return 'Etomite ' . $release;
  6245. } else {
  6246. /* MODx case */
  6247. return $full_appname;
  6248. }
  6249. /* LiveStreet */
  6250. } elseif (@is_file($root . 'classes/engine/Router.class.php') || @is_file($root . 'classes/actions/ActionPage.class.php') || @is_dir($root . 'engine/lib/internal/')) {
  6251. return 'LiveStreet';
  6252. /* Santafox */
  6253. } elseif (@is_file($root . 'ini.php')) {
  6254. require($root . 'ini.php');
  6255. if (defined('SANTAFOX_VERSION')) {
  6256. return 'Santafox ' . SANTAFOX_VERSION;
  6257. } else {
  6258. return 'Santafox';
  6259. }
  6260. /* Zend Framework */
  6261. } elseif (@is_file($root . '../application/configs/config.ini')) {
  6262. return 'Zend Framework';
  6263. /* DataLife Engine */
  6264. } elseif (@is_file($root . 'engine/data/config.php')) {
  6265. $config = array(
  6266. 'version_id' => '8.0'
  6267. );
  6268. require($root . 'engine/data/config.php');
  6269. return 'DataLife Engine ' . $config['version_id'];
  6270. /* CodeIgniter */
  6271. } elseif (@is_file($root . 'system/codeigniter/CodeIgniter.php')) {
  6272. return 'CodeIgniter';
  6273. /* Symfony */
  6274. } elseif (@is_file($root . '../lib/symfony/config/config/settings.yml')) {
  6275. return 'Symfony';
  6276. /* Textpattern */
  6277. } elseif (@is_file($root . 'textpattern/index.php')) {
  6278. $version = preg_replace("/['\"].*/", "", preg_replace("/.*\\\$thisversion\s*=\s*['\"]/", "", preg_replace("/\r?\n/", "", $this->file_get_contents($root . 'textpattern/index.php'))));
  6279. return 'Textpattern ' . $version;
  6280. /* Kohana */
  6281. } elseif (@is_file($root . 'system/core/Kohana.php')) {
  6282. return 'Kohana';
  6283. /* Yii */
  6284. } elseif (@is_file($root . '../framework/YiiBase.php') || @is_file($root . 'framework/YiiBase.php')) {
  6285. return 'Yii';
  6286. /* Invision Power Board */
  6287. } elseif (@is_file($root . 'sources/classes/class_display.php')) {
  6288. return 'Invision Power Board';
  6289. /* Simple Machines Forum */
  6290. } elseif (@is_file($root . 'Sources/LogInOut.php')) {
  6291. $version = preg_replace("/['\"].*/", "", preg_replace("/.*\\\$forum_version\s*=\s*['\"]/", "", preg_replace("/\r?\n/", "", $this->file_get_contents($root . 'index.php'))));
  6292. return 'Simple Machines Forum' . (empty($version) ? '' : ' ' . $version);
  6293. /* Bitrix */
  6294. } elseif (@is_dir($root . 'bitrix/')) {
  6295. return 'Bitrix';
  6296. /* cogear */
  6297. } elseif (@is_file($root . 'gears/global/global.info')) {
  6298. $version = preg_replace("/group.*/", "", preg_replace("/.*version\s*=\s*/", "", preg_replace("/\r?\n/", "", $this->file_get_contents($root . 'gears/global/global.info'))));
  6299. return 'cogear' . (empty($version) ? '' : ' ' . $version);
  6300. /* NetCat */
  6301. } elseif (@is_dir($root . 'netcat/')) {
  6302. return 'NetCat';
  6303. /* CakePHP, global root */
  6304. } elseif (@is_file($root . 'cake/VERSION.txt')) {
  6305. /* change document root to inner directory */
  6306. $this->view->paths['absolute']['document_root'] = $this->view->ensure_trailing_slash($this->view->unify_dir_separator(substr(getenv("SCRIPT_FILENAME"), 0, strpos(getenv("SCRIPT_FILENAME"), getenv("SCRIPT_NAME")))));
  6307. $this->save_option("['website_root']", $this->view->paths['absolute']['document_root']);
  6308. return 'CakePHP';
  6309. /* CakePHP, local root */
  6310. } elseif (@is_file($root . '../../cake/VERSION.txt')) {
  6311. $this->save_option("['document_root']", $root);
  6312. return 'CakePHP';
  6313. /* CMS Made Simple */
  6314. } elseif (@is_file($root . 'version.php')) {
  6315. if (@is_file($root . 'plugins/function.cms_version.php')) {
  6316. require_once($root . 'version.php');
  6317. }
  6318. return 'CMS Made Simple ' . $CMS_VERSION;
  6319. /* UMI.CMS */
  6320. } elseif (@is_file($root . 'gw.php')) {
  6321. return 'UMI.CMS';
  6322. } elseif (@is_file($root . 'path.php')) {
  6323. require_once($root . 'path.php');
  6324. define('EXT', '1');
  6325. /* ExpressionEngine */
  6326. if (!empty($system_path)) {
  6327. require_once($root . $system_path . 'config.php');
  6328. $version = !empty($conf) && !empty($conf['app_version']) ? ' ' . preg_replace("!([0-9])([0-9])([0-9])$!", "$1.$2.$3", $conf['app_version']) : '';
  6329. return 'ExpressionEngine' . $version;
  6330. }
  6331. /* Xaraya 1.1.5 */
  6332. } elseif (@is_file($root . 'var/config.system.php')) {
  6333. return 'Xaraya';
  6334. /* X-Cart */
  6335. } elseif (@is_file($root . 'include/func/func.core.php')) {
  6336. return 'X-Cart';
  6337. /* XOOPS 2.3.3 */
  6338. } elseif (@is_file($root . 'include/version.php')) {
  6339. @require($root . 'include/version.php');
  6340. /* SocialEngine 3.19 */
  6341. if (@is_file($root . 'include/database_config.php')) {
  6342. return 'Social Engine' . (empty($version) ? '' : ' ' . $version);
  6343. } else {
  6344. return defined(XOOPS_VERSION) ? XOOPS_VERSION : 'XOOPS';
  6345. }
  6346. /* Website Baker 2.8 */
  6347. } elseif (@is_file($root . 'account/preferences.php')) {
  6348. return 'Website Baker';
  6349. /* Open Slaed 1.2 */
  6350. } elseif (@is_file($root . 'config/config_global.php')) {
  6351. define('FUNC_FILE', 1);
  6352. require($root . 'config/config_global.php');
  6353. return 'Open Slaed' . (empty($conf['version']) ? '' : ' ' . $conf['version']);
  6354. /* Geeklog 1.6.1 */
  6355. } elseif (@is_file($root . 'images/icons/geeklog.gif')) {
  6356. return 'Geeklog';
  6357. /* PrestaShop 1.2.5 */
  6358. } elseif (@is_file($root . 'modules/paypal/prestashop_paypal.png')) {
  6359. return 'PrestaShop';
  6360. /* Koobi CMS */
  6361. } elseif (@is_file($root . 'class/tpl/Koobi.class.php')) {
  6362. return 'Koobi CMS';
  6363. /* Contao */
  6364. } elseif (@is_dir($root . 'contao/')) {
  6365. return 'Contao';
  6366. }
  6367. return 'CMS 42';
  6368. }
  6369. function validate() {
  6370. $a = $this->file_get_contents(dirname(__FILE__) . '/../libs/php/view.php');
  6371. $a = preg_replace("!.*(function validate_.*/\*\*).*!is", "$1", $a);
  6372. if (!empty($a) && strlen($a) < 1000) {
  6373. $this->premium = 0;
  6374. }
  6375. $image = $this->compress_options['footer']['image'];
  6376. /* check cache integrity */
  6377. if (!empty($image) &&
  6378. @filemtime($this->basepath . 'images/' . $image) >
  6379. @filemtime($this->compress_options['css_cachedir'] . $image)) {
  6380. @copy($this->basepath . 'images/' . $image,
  6381. $this->compress_options['css_cachedir'] . $image);
  6382. }
  6383. if (@filemtime($this->basepath . 'libs/js/index.php') >
  6384. @filemtime($this->compress_options['javascript_cachedir'] . 'index.php')) {
  6385. @copy($this->basepath . 'libs/js/index.php',
  6386. $this->compress_options['javascript_cachedir'] . 'index.php');
  6387. }
  6388. if (@filemtime($this->basepath . 'libs/js/yass.loader.js') >
  6389. @filemtime($this->compress_options['javascript_cachedir'] . 'yass.loader.js')) {
  6390. @copy($this->basepath . 'libs/js/yass.loader.js',
  6391. $this->compress_options['javascript_cachedir'] . 'yass.loader.js');
  6392. }
  6393. if (@filemtime($this->basepath . 'libs/php/wo.static.php') >
  6394. @filemtime($this->compress_options['css_cachedir'] . 'wo.static.php')) {
  6395. @copy($this->basepath . 'libs/php/wo.static.php',
  6396. $this->compress_options['css_cachedir'] . 'wo.static.php');
  6397. @chmod($this->compress_options['css_cachedir'] . 'wo.static.php', octdec("0755"));
  6398. }
  6399. if (@filemtime($this->basepath . 'libs/php/wo.gzip.php') >
  6400. @filemtime($this->compress_options['css_cachedir'] . 'wo.gzip.php')) {
  6401. @copy($this->basepath . 'libs/php/wo.gzip.php',
  6402. $this->compress_options['css_cachedir'] . 'wo.gzip.php');
  6403. @chmod($this->compress_options['css_cachedir'] . 'wo.gzip.php', octdec("0755"));
  6404. }
  6405. if (@filemtime($this->basepath . 'libs/php/wo.merge.php') >
  6406. @filemtime($this->compress_options['css_cachedir'] . 'wo.merge.php')) {
  6407. @copy($this->basepath . 'libs/php/wo.merge.php',
  6408. $this->compress_options['css_cachedir'] . 'wo.merge.php');
  6409. @chmod($this->compress_options['css_cachedir'] . 'wo.merge.php', octdec("0755"));
  6410. }
  6411. if (@filemtime($this->basepath . 'libs/php/0.gif') >
  6412. @filemtime($this->compress_options['css_cachedir'] . '0.gif')) {
  6413. @copy($this->basepath . 'libs/php/0.gif',
  6414. $this->compress_options['css_cachedir'] . '0.gif');
  6415. }
  6416. }
  6417. /**
  6418. * Get files & strings to change manually
  6419. *
  6420. **/
  6421. function system_files ($cms_version = 'CMS 42') {
  6422. $cms_version = explode(" ", $cms_version);
  6423. $files = array();
  6424. switch ($cms_version[0]) {
  6425. case 'Joomla!':
  6426. /* Joomla 1.5.1+ */
  6427. if (preg_match("/1\.[56789]/", $cms_version[1])) {
  6428. $files = array(
  6429. array(
  6430. 'file' => 'index.php',
  6431. 'mode' => 'start',
  6432. 'location' => '$mainframe =& JFactory::getApplication(\'site\');'
  6433. ),
  6434. array(
  6435. 'file' => 'index.php',
  6436. 'mode' => 'finish',
  6437. 'location' => 'end'
  6438. ),
  6439. array(
  6440. 'file' => 'plugins/system/cache.php',
  6441. 'mode' => 'finish',
  6442. 'location' => 'echo JResponse::toString($mainframe->getCfg(\'gzip\'));',
  6443. 'global' => 1
  6444. ),
  6445. array(
  6446. 'file' => 'administrator/components/com_jrecache/includes/cache_handler.php',
  6447. 'mode' => 'start',
  6448. 'location' => 'fclose($handle);'
  6449. ),
  6450. array(
  6451. 'file' => 'administrator/components/com_jrecache/includes/cache_handler.php',
  6452. 'mode' => 'finish',
  6453. 'location' => 'echo $output;'
  6454. )
  6455. );
  6456. /* Joomla 1.0 */
  6457. } else {
  6458. $files = array(
  6459. array(
  6460. 'file' => 'index.php',
  6461. 'mode' => 'start',
  6462. 'location' => 'ob_end_clean();'
  6463. ),
  6464. array(
  6465. 'file' => 'index.php',
  6466. 'mode' => 'finish',
  6467. 'location' => 'echo \'</pre>\';}'
  6468. ),
  6469. array(
  6470. 'file' => 'components/com_pagecache/pagecache.class.php',
  6471. 'mode' => 'finish',
  6472. 'location' => 'echo $data;',
  6473. 'global' => 1
  6474. ),
  6475. array(
  6476. 'file' => 'mambots/system/cache.php',
  6477. 'mode' => 'start',
  6478. 'location' => 'initGzip();'
  6479. ),
  6480. array(
  6481. 'file' => 'mambots/system/cache.php',
  6482. 'mode' => 'finish',
  6483. 'location' => 'echo $content;'
  6484. ),
  6485. array(
  6486. 'file' => 'administrator/components/com_jrecache/includes/cache_handler.php',
  6487. 'mode' => 'start',
  6488. 'location' => 'fclose($handle);'
  6489. ),
  6490. array(
  6491. 'file' => 'administrator/components/com_jrecache/includes/cache_handler.php',
  6492. 'mode' => 'finish',
  6493. 'location' => 'echo $output;'
  6494. )
  6495. );
  6496. }
  6497. break;
  6498. /* Joostina */
  6499. case 'Joostina':
  6500. $files = array(
  6501. array(
  6502. 'file' => 'index.php',
  6503. 'mode' => 'start',
  6504. 'location' => 'joostina_api::check_host();'
  6505. ),
  6506. array(
  6507. 'file' => 'index.php',
  6508. 'mode' => 'finish',
  6509. 'location' => 'if($mosConfig_clearCache == 1 && $mosConfig_caching == 1) joostina_api::clearCache();'
  6510. )
  6511. );
  6512. break;
  6513. /* vBulletin */
  6514. case 'vBulletin':
  6515. $files = array(
  6516. array(
  6517. 'file' => 'includes/functions.php',
  6518. 'mode' => 'start',
  6519. 'location' => '$output = process_replacement_vars($vartext);',
  6520. 'global' => 1
  6521. ),
  6522. array(
  6523. 'file' => 'includes/functions.php',
  6524. 'mode' => 'finish',
  6525. 'location' => 'flush(); }',
  6526. )
  6527. );
  6528. break;
  6529. /* DataLife Engine */
  6530. case 'DataLife':
  6531. $files = array(
  6532. array(
  6533. 'file' => 'index.php',
  6534. 'mode' => 'start'
  6535. ),
  6536. array(
  6537. 'file' => 'index.php',
  6538. 'mode' => 'finish',
  6539. 'location' => 'db->close ();'
  6540. )
  6541. );
  6542. break;
  6543. /* Bitrix */
  6544. case 'Bitrix':
  6545. $files = array(
  6546. array(
  6547. 'file' => 'bitrix/header.php',
  6548. 'mode' => 'start'
  6549. ),
  6550. array(
  6551. 'file' => 'bitrix/modules/main/include/epilog_after.php',
  6552. 'mode' => 'finish',
  6553. 'location' => 'echo $r;'
  6554. )
  6555. );
  6556. break;
  6557. /* Invision Power Board */
  6558. case 'Invision':
  6559. $files = array(
  6560. array(
  6561. 'file' => 'sources/classes/class_display.php',
  6562. 'mode' => 'start',
  6563. 'location' => '$this->ipsclass->skin[\'_wrapper\'] = preg_replace( "#htmldocument\.prototype#is", "HTMLDocument_prototype", $this->ipsclass->skin[\'_wrapper\'] );'
  6564. ),
  6565. array(
  6566. 'file' => 'sources/classes/class_display.php',
  6567. 'mode' => 'finish',
  6568. 'location' => 'print $this->ipsclass->skin[\'_wrapper\'];'
  6569. )
  6570. );
  6571. break;
  6572. /* phpBB */
  6573. case 'phpBB':
  6574. $files = array(
  6575. array(
  6576. 'file' => 'includes/functions.php',
  6577. 'mode' => 'start',
  6578. 'location' => 'function page_footer($run_cron = true) {'
  6579. ),
  6580. array(
  6581. 'file' => 'includes/functions.php',
  6582. 'mode' => 'finish',
  6583. 'location' => '$template->display(\'body\');'
  6584. )
  6585. );
  6586. break;
  6587. /* PHP-Nuke */
  6588. case 'PHP-Nuke':
  6589. $files = array(
  6590. array(
  6591. 'file' => 'mainfile.php',
  6592. 'mode' => 'start',
  6593. 'location' => 'unset($matches);',
  6594. ),
  6595. array(
  6596. 'file' => 'footer.php',
  6597. 'mode' => 'finish',
  6598. 'location' => 'echo "</body>\n</html>";',
  6599. 'global' => 1
  6600. )
  6601. );
  6602. break;
  6603. /* NetCat */
  6604. case 'NetCat':
  6605. $files = array(
  6606. array(
  6607. 'file' => 'netcat/require/e404.php',
  6608. 'mode' => 'start',
  6609. ),
  6610. array(
  6611. 'file' => 'netcat/require/e404.php',
  6612. 'mode' => 'finish',
  6613. 'location' => 'end'
  6614. )
  6615. );
  6616. break;
  6617. /* UMI.CMS */
  6618. case 'UMI.CMS':
  6619. $files = array(
  6620. array(
  6621. 'file' => 'index.php',
  6622. 'mode' => 'start',
  6623. 'location' => 'header("ETag: \"" . sha1($res) . "\");',
  6624. ),
  6625. array(
  6626. 'file' => 'index.php',
  6627. 'mode' => 'finish',
  6628. 'location' => 'echo $res;'
  6629. )
  6630. );
  6631. break;
  6632. /* XOOPS 2.3.3 */
  6633. case 'XOOPS':
  6634. $files = array(
  6635. array(
  6636. 'file' => 'index.php',
  6637. 'mode' => 'start',
  6638. ),
  6639. array(
  6640. 'file' => 'index.php',
  6641. 'mode' => 'finish',
  6642. 'location' => 'end'
  6643. ),
  6644. array(
  6645. 'file' => 'class/theme.php',
  6646. 'mode' => 'finish',
  6647. 'location' => '$this->render( null, null, $template );',
  6648. 'global' => 1
  6649. )
  6650. );
  6651. break;
  6652. /* Open Slaed 1.2 */
  6653. case 'Open':
  6654. $files = array(
  6655. array(
  6656. 'file' => 'function/function.php',
  6657. 'mode' => 'start',
  6658. 'location' => 'unset($_SESSION[$conf[\'user_c\']]);',
  6659. 'global' => 1
  6660. ),
  6661. array(
  6662. 'file' => 'function/function.php',
  6663. 'mode' => 'finish',
  6664. 'location' => 'readfile($cacheurl);'
  6665. ),
  6666. array(
  6667. 'file' => 'function/function.php',
  6668. 'mode' => 'finish',
  6669. 'location' => 'echo pack(\'V\', $gzip_size);}}',
  6670. 'global' => 1
  6671. )
  6672. );
  6673. break;
  6674. /* MaxDev Pro */
  6675. case 'MaxDev':
  6676. $files = array(
  6677. array(
  6678. 'file' => 'index.php',
  6679. 'mode' => 'start_shutdown'
  6680. )
  6681. );
  6682. break;
  6683. /* 4images */
  6684. case '4images':
  6685. $files = array(
  6686. array(
  6687. 'file' => 'includes/page_header.php',
  6688. 'mode' => 'start'
  6689. ),
  6690. array(
  6691. 'file' => 'includes/page_footer.php',
  6692. 'mode' => 'finish',
  6693. 'location' => 'echo pack("V", $gzip_size);}'
  6694. ),
  6695. );
  6696. break;
  6697. /* CMS Made Simple */
  6698. case 'CMS':
  6699. if ($cms_version[1] == 'Made') {
  6700. $files = array(
  6701. array(
  6702. 'file' => 'index.php',
  6703. 'mode' => 'start',
  6704. 'location' => 'header("Content-Type: " . $gCms->variables[\'content-type\'] . "; charset=" . (isset($pageinfo->template_encoding) && $pageinfo->template_encoding != \'\'?$pageinfo->template_encoding:get_encoding()));',
  6705. ),
  6706. array(
  6707. 'file' => 'index.php',
  6708. 'mode' => 'finish',
  6709. 'location' => 'echo $html;'
  6710. )
  6711. );
  6712. } else {
  6713. $files = array(
  6714. array(
  6715. 'file' => 'index.php',
  6716. 'mode' => 'start_shutdown'
  6717. )
  6718. );
  6719. }
  6720. break;
  6721. /* VaM Shop */
  6722. case 'VaM':
  6723. case 'osCommerce':
  6724. $files = array(
  6725. array(
  6726. 'file' => 'includes/application_top.php',
  6727. 'mode' => 'start_shutdown'
  6728. )
  6729. );
  6730. break;
  6731. /* PHP Fusion */
  6732. case 'PHP':
  6733. $files = array(
  6734. array(
  6735. 'file' => 'themes/templates/footer.php',
  6736. 'mode' => 'start',
  6737. 'location' => 'require_once INCLUDES."footer_includes.php";'
  6738. ),
  6739. array(
  6740. 'file' => 'themes/templates/footer.php',
  6741. 'mode' => 'finish',
  6742. 'location' => 'echo handle_output($output);'
  6743. )
  6744. );
  6745. break;
  6746. /* Social Engine */
  6747. case 'Social':
  6748. $files = array(
  6749. array(
  6750. 'file' => 'header.php',
  6751. 'mode' => 'start_shutdown'
  6752. )
  6753. );
  6754. break;
  6755. /* X-Cart */
  6756. case 'X-Cart':
  6757. $files = array(
  6758. array(
  6759. 'file' => 'include/func/func.core.php',
  6760. 'mode' => 'start_shutdown'
  6761. )
  6762. );
  6763. break;
  6764. /* Koobi CMS */
  6765. case 'Koobi':
  6766. $files = array(
  6767. array(
  6768. 'file' => 'index.php',
  6769. 'mode' => 'start_shutdown'
  6770. )
  6771. );
  6772. break;
  6773. /* Contao */
  6774. case 'Contao':
  6775. $files = array(
  6776. array(
  6777. 'file' => 'index.php',
  6778. 'mode' => 'start_shutdown'
  6779. )
  6780. );
  6781. break;
  6782. /* Contao */
  6783. case 'Shop-Script':
  6784. $files = array(
  6785. array(
  6786. 'file' => 'published/SC/html/scripts/index.php',
  6787. 'mode' => 'start_shutdown',
  6788. 'location' => 'include_once(DIR_CFG.\'/connect.inc.wa.php\');'
  6789. )
  6790. );
  6791. break;
  6792. /* all other systems */
  6793. default:
  6794. $files = array(
  6795. array(
  6796. 'file' => 'index.php',
  6797. 'mode' => 'start_shutdown'
  6798. )
  6799. );
  6800. break;
  6801. }
  6802. /* return default value */
  6803. return $files;
  6804. }
  6805. /**
  6806. * Determines cache engine and create instance of it
  6807. *
  6808. **/
  6809. function start_cache_engine () {
  6810. $cache_engines = array('0' => 'files',
  6811. '1' => 'memcached',
  6812. '2' => 'apc',
  6813. '3' => 'xcache'
  6814. );
  6815. $cache_engines_options = array('0' => array('cache_dir' => $this->compress_options['html_cachedir'], 'host' => $this->compress_options['host']),
  6816. '1' => array('server' => @$this->compress_options['performance']['cache_engine_options']),
  6817. '2' => '',
  6818. '3' => ''
  6819. );
  6820. $engine_num = round($this->compress_options['performance']['cache_engine']);
  6821. /* check for caching extensions */
  6822. if ((!@class_exists('Memcached') && !@class_exists('Memcache') && $engine_num == 1) ||
  6823. (!@function_exists('apc_store') && $engine_num == 2) ||
  6824. (!@function_exists('xcache_set') && $engine_num == 3) ||
  6825. empty($cache_engines[$engine_num])) {
  6826. $engine_num = 0;
  6827. }
  6828. $engine_name = 'webo_cache_' . $cache_engines[$engine_num];
  6829. include_once($this->basepath . 'libs/php/cache_engine.php');
  6830. $this->cache_engine = new $engine_name ($cache_engines_options[$engine_num]);
  6831. }
  6832. /**
  6833. * Deletes cached HTML files determined by patterns. Just an interface for cache_engine delete_entries method.
  6834. *
  6835. **/
  6836. function clear_html_cache ($patterns) {
  6837. if (!empty($patterns)) {
  6838. $this->cache_engine->delete_entries($patterns);
  6839. }
  6840. }
  6841. /**
  6842. * Envelopes standard file_get_contents in case of Magic Quotes
  6843. *
  6844. **/
  6845. function file_get_contents ($file) {
  6846. if (get_magic_quotes_runtime()) {
  6847. return stripslashes(@file_get_contents($file));
  6848. } else {
  6849. return @file_get_contents($file);
  6850. }
  6851. }
  6852. /**
  6853. * Finds all active configuration and writes info about them to web.optimizer.php
  6854. *
  6855. **/
  6856. function find_configs ($licensed) {
  6857. @chdir($this->basepath);
  6858. $str = '';
  6859. if ($licensed) {
  6860. $files = array();
  6861. foreach (glob('*config.webo.php') as $file) {
  6862. if ($file != 'config.webo.php') {
  6863. $files[] = substr($file, 0, strlen($file) - 16);
  6864. }
  6865. }
  6866. $str = '<?php $wss_configs = array(\'' . implode($files, "','") . '\'); ?>';
  6867. }
  6868. $this->write_file($this->basepath . 'web.optimizer.configs.php', $str);
  6869. }
  6870. /**
  6871. * Removes directory recursively
  6872. *
  6873. **/
  6874. function __rmdir ($dir) {
  6875. if (is_dir($dir)) {
  6876. $objects = @scandir($dir);
  6877. foreach ($objects as $object) {
  6878. if ($object != "." && $object != "..") {
  6879. if (@is_dir($dir . "/" . $object)) {
  6880. $this->__rmdir($dir . "/" . $object);
  6881. } else {
  6882. @unlink($dir . "/" . $object);
  6883. }
  6884. }
  6885. }
  6886. @reset($objects);
  6887. @rmdir($dir);
  6888. }
  6889. }
  6890. }
  6891. ?>