PageRenderTime 94ms CodeModel.GetById 26ms RepoModel.GetById 1ms app.codeStats 1ms

/controller/admin.php

http://web-optimizator.googlecode.com/
PHP | 6972 lines | 6693 code | 20 blank | 259 comment | 247 complexity | 53807590d2640c136dbb828ed06c5aa3 MD5 | raw file

Large files files are truncated, but you can click here to view the full 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. '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' .
  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…

Large files files are truncated, but you can click here to view the full file