PageRenderTime 68ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 1ms

/controller/compressor.php

http://web-optimizator.googlecode.com/
PHP | 4401 lines | 3986 code | 31 blank | 384 comment | 620 complexity | 93e1035a585d931b99fe8efa4fe67a25 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. * Gzips and minifies the JavaScript and CSS within the head tags of a page.
  5. * Can also gzip and minify the page itself
  6. * and 100+ other cool web performance optimization techniques
  7. * Based on Web Optimizer, which was based on PHP Speedy
  8. *
  9. **/
  10. class web_optimizer {
  11. /**
  12. * Constructor
  13. * Sets the options and defines the gzip headers
  14. **/
  15. function web_optimizer ($options = false) {
  16. $currency = empty($_COOKIE['WSS_CURRENCY']) ? $options['options']['currency'] : $_COOKIE['WSS_CURRENCY'];
  17. $rurl = empty($options['uri']) ? empty($_SERVER['REQUEST_URI']) ? '' : $_SERVER['REQUEST_URI'] : $options['uri'];
  18. $homepage = empty($options['options']['html_cache']['ignore_list']) && empty($options['options']['restricted']) ? '' :
  19. in_array($rurl, array('/', '/index.php', '/index.html', '/#' . $currency));
  20. /* skip processing if disabled or restricted */
  21. if (!empty($_GET['web_optimizer_disabled']) || (!empty($options['options']['restricted']) &&
  22. (preg_match("@" . preg_replace("/ /", "|", preg_replace("/([\?!\^\$\|\(\)\[\]\{\}])/", "\\\\$1", $options['options']['restricted'])) . "@", $rurl))) ||
  23. (strpos($options['options']['restricted'], '#') !== false && $homepage)) {
  24. $this->options['active'] = 0;
  25. return;
  26. }
  27. /* A/B testing, */
  28. if (!empty($options['options']['footer']['ab'])) {
  29. if (empty($_COOKIE['WSS_DISABLED']) && empty($_COOKIE['WSS_ENABLED'])) {
  30. $ab = (microtime()*100)%100 < round($options['options']['footer']['ab']);
  31. setcookie($ab ? "WSS_ENABLED" : "WSS_DISABLED", 1, time() + 60*60, '/', $_SERVER['HTTP_HOST'], false, true);
  32. if (!$ab) {
  33. $_COOKIE['WSS_DISABLED'] = 1;
  34. }
  35. }
  36. }
  37. /* initialize chained optimization */
  38. $this->web_optimizer_stage = round(empty($_GET['web_optimizer_stage']) ? 0 : $_GET['web_optimizer_stage']);
  39. $this->debug_mode = empty($_GET['web_optimizer_debug']) && empty($_COOKIE['web_optimizer_debug']) ? 0 : 1;
  40. /* allow merging of other classes with this one */
  41. foreach ($options as $key => $value) {
  42. $this->$key = $value;
  43. }
  44. /* get chained optimization params */
  45. if (!empty($this->web_optimizer_stage)) {
  46. $this->username = htmlspecialchars(empty($_GET['username']) ? '' :
  47. $_GET['username']);
  48. $this->password = htmlspecialchars(empty($_GET['password']) ? '' :
  49. $_GET['password']);
  50. $this->auto_rewrite = round(empty($_GET['auto_rewrite']) ? '' :
  51. $_GET['auto_rewrite']);
  52. $this->chained_redirect = 'http://' .
  53. $this->options['host'] .
  54. str_replace($this->options['document_root'], '/', $this->options['html_cachedir']) .
  55. 'optimizing.php';
  56. $this->cache_version = round(empty($_GET['cache_version']) ? '' :
  57. $_GET['cache_version']);
  58. /* get major stage number, all stages:
  59. -1 - system, envelope all <script> to try-catch-document.write
  60. 0-9 - inilialization, starts in administrative interface
  61. 10-13 - JS file generation, 1st major stage (common browsers)
  62. 14-19 - CSS Sprites / data:URI generation, 1st major stage
  63. 20-24 - CSS file generation + page parsing, 1st major stage
  64. 25-28 - JS file generation, 2nd major stage (IE 6.0)
  65. 29-34 - CSS Sprites / mhtml generation, 2nd major stage
  66. 35-39 - CSS file generation + page parsing, 2nd major stage
  67. 40-43 - JS file generation, 3rd major stage (IE 7.0)
  68. 44-49 - CSS Sprites / mhtml generation, 2nd major stage
  69. 50-54 - CSS file generation + page parsing, 2nd major stage
  70. 55-58 - JS file generation, 4th major stage (IE 8.0)
  71. 59-64 - CSS Sprites / data:URI generation, 4th major stage
  72. 65-69 - CSS file generation + page parsing, 4th major stage
  73. 70-73 - JS file generation, 5th major stage (IE 7.0 @ Vista)
  74. 74-79 - CSS Sprites generation, 5th major stage
  75. 80-84 - CSS file generation + page parsing, 5th major stage
  76. */
  77. $this->cache_stage = floor(($this->web_optimizer_stage - 10) / 15);
  78. }
  79. $this->options['active'] = $this->debug_mode ? 1 : $this->options['active'];
  80. /* disable any actions if not active */
  81. if (empty($this->options['active'])) {
  82. return;
  83. }
  84. /* define head of the webpage for scripts / styles */
  85. $this->head = '';
  86. /* remember current time */
  87. $this->time = empty($_SERVER['REQUEST_TIME']) ? time() : $_SERVER['REQUEST_TIME'];
  88. /* skip buffering (need for integration as plugin) */
  89. $this->buffered = $this->options['buffered'];
  90. /* Sets User Agent to differ IE from non-IE */
  91. $this->ua = empty($_SERVER['HTTP_USER_AGENT']) ? '' : $_SERVER['HTTP_USER_AGENT'];
  92. /* HTTPS or not ? */
  93. $this->https = empty($_SERVER['HTTPS']) ? '' : 's';
  94. /* Set list of outdated IE */
  95. $this->ies = array('.ie4', '.ie5', '.ie6', '.ie7');
  96. /* Set options */
  97. $this->set_options();
  98. /* Include base plugin class */
  99. if (is_array($this->options['plugins'])) {
  100. include_once($this->options['css']['installdir'] . 'libs/php/class.plugin.php');
  101. }
  102. /* Remember current page encoding */
  103. $this->encoding = '';
  104. /* Define the gzip headers */
  105. $this->set_gzip_headers();
  106. /* Deal with flushed content or not? */
  107. $this->flushed = false;
  108. $excluded_html_pages = '';
  109. $included_user_agents = '';
  110. $restricted_cookie = 0;
  111. if (!empty($this->options['page']['cache'])) {
  112. $this->start_cache_engine();
  113. if (!empty($this->clear_cache_key)) {
  114. $this->clear_html_cache($this->clear_cache_key);
  115. }
  116. /* HTML cache ? */
  117. if (!empty($this->options['page']['cache_ignore'])) {
  118. $excluded_html_pages = preg_replace("/ /", "|", preg_replace("/([\?!\^\$\|\(\)\[\]\{\}])/", "\\\\$1", str_replace(array('# ', '#'), '', $this->options['page']['cache_ignore'])));
  119. }
  120. if (!empty($this->options['page']['allowed_user_agents'])) {
  121. $included_user_agents = preg_replace("/ /", "|", preg_replace("/([\?!\^\$\|\(\)\[\]\{\}])/", "\\\\$1", $this->options['page']['allowed_user_agents']));
  122. }
  123. if (!empty($this->options['page']['exclude_cookies'])) {
  124. $cookies = explode(" ", $this->options['page']['exclude_cookies']);
  125. foreach ($cookies as $cookie) {
  126. if ($e = strpos($cookie, '=')) {
  127. $c = substr($cookie, 0, $e);
  128. $e = substr($cookie, $e+1);
  129. if (isset($_COOKIE[$c]) && $_COOKIE[$c] == $e) {
  130. $restricted_cookie = 1;
  131. }
  132. } else {
  133. if (isset($_COOKIE[$cookie])) {
  134. $restricted_cookie = 1;
  135. }
  136. }
  137. }
  138. }
  139. }
  140. /* cache if
  141. - option is enabled,
  142. - don't parse excluded pages (including home page),
  143. - or parse included USER AGENTS,
  144. - don't parse pages with excluded coockies,
  145. - flush or gzip for HTML are disabled,
  146. - headers have not been sent,
  147. - page is requested by GET,
  148. - no chained optimization,
  149. - no debug mode,
  150. - external cache restriction,
  151. - exclude domains except the activated one for non-corporate licenses,
  152. - disable cache in case of negative A/B test.
  153. */
  154. $this->cache_me = !empty($this->options['page']['cache']) &&
  155. ((empty($this->options['page']['cache_ignore']) && !$this->options['page']['ignore_include']) ||
  156. (!$this->options['page']['ignore_include'] &&
  157. (!$excluded_html_pages || !preg_match("!" . $excluded_html_pages . "!is", $this->uri)) &&
  158. (strpos($this->options['page']['cache_ignore'], '#') === false || !$homepage)) ||
  159. ($this->options['page']['ignore_include'] &&
  160. (($excluded_html_pages && preg_match("!" . $excluded_html_pages . "!is", $this->uri)) ||
  161. (strpos($this->options['page']['cache_ignore'], '#') !== false && $homepage))) ||
  162. !$this->ua ||
  163. ($included_user_agents && preg_match("!" . $included_user_agents . "!is", $this->ua))) &&
  164. !$restricted_cookie &&
  165. (empty($this->options['page']['gzip']) ||
  166. empty($this->options['page']['flush'])) &&
  167. !headers_sent() &&
  168. (getenv('REQUEST_METHOD') == 'GET') &&
  169. empty($this->web_optimizer_stage) &&
  170. !$this->debug_mode &&
  171. empty($this->no_cache) &&
  172. ($this->premium == 3 || strpos($this->options['host'], $this->host) !== false) &&
  173. (empty($this->options['page']['ab']) || empty($_COOKIE['WSS_DISABLED']));
  174. /* check if we can get out cached page */
  175. if (!empty($this->cache_me)) {
  176. $this->uri = $this->convert_request_uri(empty($this->uri) ? '' : $this->uri);
  177. $jutility = class_exists('JUtility', false);
  178. $jsession = class_exists('JSession', false);
  179. /* gzip cached content before output? (plugins have onCache), JUtility must parse content */
  180. $gzip_me = is_array($this->options['plugins']) || $jutility || $jsession;
  181. $cache_plain_key = $this->view->ensure_trailing_slash($this->uri) .
  182. 'index' .
  183. $this->ua_mod .
  184. '.html' .
  185. ($this->options['page']['https_separate'] ? $this->https : '');
  186. $cache_key = $cache_plain_key .
  187. ($this->options['page']['flush'] ||
  188. empty($this->encoding_ext) ||
  189. $gzip_me ? '' : $this->encoding_ext);
  190. $timestamp_ajax = 0;
  191. $cache_key_ajax = $cache_plain_key . '.ajax';
  192. if (defined('WSS_CACHE_MISS')) {
  193. $timestamp = 0;
  194. } else {
  195. $timestamp = $this->cache_engine->get_mtime($cache_key);
  196. if ($this->options['page']['ajax_timeout']) {
  197. $timestamp_ajax = $this->cache_engine->get_mtime($cache_key_ajax);
  198. }
  199. }
  200. /* try to get from cache non-gzipped page if gzipped one doesn't exist */
  201. if (!$timestamp && !$this->options['page']['flush'] && !empty($this->encoding_ext) && !$gzip_me) {
  202. $timestamp = $this->cache_engine->get_mtime($cache_plain_key);
  203. $gzip_me = 1;
  204. }
  205. if (!$timestamp && !$timestamp_ajax && !defined('WSS_CACHE_MISS')) {
  206. define('WSS_CACHE_MISS', 1);
  207. }
  208. if (($timestamp &&
  209. $this->time - $timestamp < $this->options['page']['cache_timeout'] &&
  210. ($content = $this->cache_engine->get_entry($gzip_me ? $cache_plain_key : $cache_key))) ||
  211. ($timestamp_ajax &&
  212. $this->time - $timestamp_ajax < $this->options['page']['ajax_timeout'] &&
  213. ($content = $this->cache_engine->get_entry($cache_key_ajax)))) {
  214. if ($jutility) {
  215. $token = JUtility::getToken();
  216. }
  217. elseif ($jsession) {
  218. $token = JSession::getFormToken();
  219. }
  220. if (!empty($token)) {
  221. $content = str_replace('##WSS_JTOKEN_WSS##', $token, $content);
  222. }
  223. /* execute plugin-specific logic */
  224. if (is_array($this->options['plugins'])) {
  225. foreach ($this->options['plugins'] as $plugin) {
  226. $plugin_file = $this->options['css']['installdir'] . 'plugins/' . $plugin . '.php';
  227. if (@is_file($plugin_file)) {
  228. include_once($plugin_file);
  229. $web_optimizer_plugin = new $plugin;
  230. $content = $web_optimizer_plugin->onAfterOptimization($content);
  231. }
  232. }
  233. }
  234. $hash = crc32($content) . (empty($this->encoding) ? '' : '-' . str_replace("x-", "", $this->encoding));
  235. /* check for return visits */
  236. if ((isset($_SERVER['HTTP_IF_NONE_MATCH']) &&
  237. stripslashes($_SERVER['HTTP_IF_NONE_MATCH']) == '"' . $hash . '"') ||
  238. (isset($_SERVER['HTTP_IF_MATCH']) &&
  239. stripslashes($_SERVER['HTTP_IF_MATCH']) == '"' . $hash . '"')) {
  240. /* return visit and no modifications, so do not send anything */
  241. @header ("HTTP/1.0 304 Not Modified");
  242. @header ("Content-Length: 0");
  243. $this->di();
  244. }
  245. /* define gzip headers */
  246. $this->set_gzip_header();
  247. if ($gzip_me && $this->encoding) {
  248. $cnt = $this->create_gz_compress($content, in_array($this->encoding, array('gzip', 'x-gzip')));
  249. if (!empty($cnt)) {
  250. $content = $cnt;
  251. /* skip gzip if we can't compress content */
  252. } else {
  253. $this->options['page']['gzip'] = 0;
  254. $this->encoding = '';
  255. }
  256. }
  257. /* set ETag, thx to merzmarkus */
  258. @header("ETag: \"" . $hash . "\"");
  259. if ($gzip_me && ($this->encoding || empty($this->gzip_set)) && (empty($_SERVER['SERVER_PROTOCOL']) || $_SERVER['SERVER_PROTOCOL'] == 'HTTP/1.0')) {
  260. @header("Content-Length: " . strlen($content));
  261. }
  262. /* set content-type */
  263. if (!empty($this->options['charset'])) {
  264. @header("Content-Type: text/html; charset=" . $this->options['charset']);
  265. }
  266. if (empty($this->web_optimizer_stage) &&
  267. $this->options['page']['clientside_cache']) {
  268. /* not really GMT but is valid locally */
  269. $ExpStr = date("D, d M Y H:i:s",
  270. $this->time + $this->options['page']['clientside_timeout']) . " GMT";
  271. @header("Cache-Control: " .
  272. ($this->options['page']['gzip'] ? 'private' : 'public') .
  273. ", max-age=" .
  274. $this->options['page']['clientside_timeout']);
  275. @header("Expires: " . $ExpStr);
  276. }
  277. while (@ob_end_clean());
  278. @header('WEBO: cache hit');
  279. echo $content;
  280. /* content is a head part, flush it after */
  281. if ($this->options['page']['flush']) {
  282. flush();
  283. $this->flushed = true;
  284. } else {
  285. $this->di(1);
  286. }
  287. } else {
  288. @header('WEBO: cache miss');
  289. }
  290. } elseif (!empty($this->options['page']['cache'])) {
  291. @header('WEBO: cache miss');
  292. }
  293. /* remember Joomla! caching (VirtueMart) */
  294. $this->joomla_cache = $this->options['page']['cache'] && (class_exists('JUtility', false) || class_exists('JSession', false));
  295. /* remember WordPress caching (WP Digi Cart) */
  296. $this->wp_cache = defined('WP_CACHE') && @is_dir($this->options['document_root'] . 'wp-content/plugins/wp-cart-for-digital-products/');
  297. /* remember Generic caching for other carts */
  298. $this->generic_cache = !$this->joomla_cache && !$this->wp_cache && $this->options['page']['cache'];
  299. /* change some hosts if HTTPS is used */
  300. if ($this->https && !empty($this->options['page']['parallel_https'])) {
  301. $this->options['javascript']['host'] =
  302. $this->options['css']['host'] =
  303. $this->options['page']['parallel_hosts'] =
  304. $this->options['page']['parallel_https'];
  305. }
  306. /* number of external files calls to process */
  307. $this->initial_files = array();
  308. /* set internal encoding */
  309. $this->charset = empty($wss_encoding) ? 'utf8' : $wss_encoding;
  310. /* prepare escaped host */
  311. $this->host_escaped = str_replace('.', '\.', $this->host);
  312. /* activate application */
  313. $this->options['active'] = 1;
  314. if ($this->buffered) {
  315. /* Start things off */
  316. $this->start();
  317. }
  318. }
  319. /**
  320. * Write installation progress to JavaScript file
  321. *
  322. **/
  323. function write_progress ($progress) {
  324. $this->write_file($this->options['javascript']['cachedir'] . 'progress.php', $progress);
  325. }
  326. /**
  327. * Options are read from config.webo.php
  328. **/
  329. function set_options () {
  330. /* Set paths with new options */
  331. $this->options['document_root'] = empty($this->options['document_root']) ? '' : $this->options['document_root'];
  332. $this->view->set_paths($this->options['document_root']);
  333. /* Set local root if chained optimization */
  334. if (!empty($this->web_optimizer_stage)) {
  335. $this->view->paths['full']['current_directory'] = $this->view->paths['full']['document_root'];
  336. $this->view->paths['relative']['current_directory'] = $this->view->paths['relative']['document_root'];
  337. $_SERVER['REQUEST_URI'] = '/';
  338. /* force User Agent on chained optimization */
  339. $mods = array(
  340. /* all common browsers except IE */
  341. '',
  342. /* IE 6.0, when will it die? */
  343. '.ie6',
  344. /* IE 7.0 */
  345. '.ie7',
  346. /* IE 8.0 */
  347. '.ie8',
  348. /* Mobile Agents */
  349. '.ma',
  350. /* dummy UA, thx to peterbowey */
  351. '.end'
  352. );
  353. $this->ua_mod = $mods[$this->cache_stage];
  354. }
  355. $this->premium = $this->view->validate_license($this->options['license'], $this->options['html_cachedir'], $this->options['host']);
  356. $this->set_user_agent();
  357. $webo_cachedir = $this->view->unify_dir_separator(realpath(dirname(__FILE__) . '/../') . '/');
  358. /* ensure trailing slashes */
  359. $this->options['html_cachedir'] = $this->view->ensure_trailing_slash($this->options['html_cachedir']);
  360. $this->options['css_cachedir'] = $this->view->ensure_trailing_slash($this->options['css_cachedir']);
  361. $this->options['javascript_cachedir'] = $this->view->ensure_trailing_slash($this->options['javascript_cachedir']);
  362. /* normalize host */
  363. if (!empty($this->options['host'])) {
  364. $this->options['host'] = preg_replace("!^https?://!", "", $this->options['host']);
  365. }
  366. /* Read in options */
  367. $full_options = array(
  368. "javascript" => array(
  369. "cachedir" => $this->options['javascript_cachedir'],
  370. "cachedir_relative" => str_replace($this->options['document_root'], "/", $this->options['javascript_cachedir']),
  371. "installdir" => $webo_cachedir,
  372. "gzip" => $this->options['gzip']['javascript'] &&
  373. ((!$this->options['htaccess']['mod_gzip'] &&
  374. !$this->options['htaccess']['mod_deflate'] &&
  375. (!$this->options['htaccess']['mod_rewrite'] ||
  376. !$this->options['htaccess']['mod_mime'] ||
  377. !$this->options['htaccess']['mod_expires'])) ||
  378. !$this->options['htaccess']['enabled']),
  379. "gzip_level" => round($this->options['gzip']['javascript_level']),
  380. "minify" => $this->options['minify']['javascript'],
  381. "minify_body" => $this->options['minify']['javascript_body'],
  382. "minify_with" => $this->options['minify']['with_jsmin'] ?
  383. 'jsmin' : ($this->options['minify']['with_yui'] && $this->premium > 1 ?
  384. 'yui' : ($this->options['minify']['with_packer'] && $this->premium ?
  385. 'packer' : ($this->options['minify']['with_google'] && $this->premium > 1 ?
  386. 'google' : ''))),
  387. "minify_try" => $this->options['external_scripts']['include_try'] &&
  388. $this->premium,
  389. "minify_exclude" => $this->options['external_scripts']['minify_exclude'],
  390. "remove_duplicates" => $this->options['external_scripts']['duplicates'] &&
  391. $this->premium,
  392. "far_future_expires" => $this->options['far_future_expires']['javascript'] &&
  393. !$this->options['htaccess']['mod_expires'],
  394. "far_future_expires_php" => $this->options['far_future_expires']['javascript'],
  395. "far_future_expires_rewrite" => $this->options['htaccess']['mod_rewrite'] &&
  396. $this->options['htaccess']['enabled'] &&
  397. $this->options['far_future_expires']['javascript'],
  398. "far_future_expires_static" => ((!($this->options['htaccess']['mod_rewrite'] ||
  399. $this->options['htaccess']['mod_expires']) ||
  400. !$this->options['htaccess']['enabled']) &&
  401. $this->options['far_future_expires']['javascript']) ||
  402. ((!($this->options['htaccess']['mod_rewrite'] ||
  403. $this->options['htaccess']['mod_deflate'] ||
  404. $this->options['htaccess']['mod_gzip']) ||
  405. !$this->options['htaccess']['enabled']) &&
  406. $this->options['gzip']['javascript']),
  407. "unobtrusive_body" => $this->premium && $this->options['unobtrusive']['body'] &&
  408. !$this->options['unobtrusive']['all'],
  409. "external_scripts" => $this->options['external_scripts']['on'],
  410. "inline_scripts" => $this->options['external_scripts']['inline'] &&
  411. ($this->options['minify']['javascript'] || $this->options['rocket']['reorder']),
  412. "inline_scripts_body" => $this->options['external_scripts']['inline_body'] &&
  413. ($this->options['minify']['javascript'] || $this->options['rocket']['reorder']),
  414. "external_scripts_head_end" => $this->options['external_scripts']['head_end'],
  415. "external_scripts_exclude" => $this->options['external_scripts']['ignore_list'],
  416. "external_scripts_mask" => $this->premium > 1 ? $this->options['external_scripts']['include_mask'] : '',
  417. "remove_list" => $this->premium > 1 ? $this->options['external_scripts']['remove_list'] : '',
  418. "dont_check_file_mtime" => $this->options['performance']['mtime'],
  419. "file" => $this->premium > 1 ? $this->options['minify']['javascript_file'] : '',
  420. "host" => $this->premium ? $this->options['minify']['javascript_host'] : '',
  421. "https" => $this->premium > 1 ? $this->options['parallel']['https'] : '',
  422. "rocket" => $this->options['rocket']['javascript'] && !$this->options['minify']['javascript'],
  423. "rocket_external" => $this->options['rocket']['javascript_external'] && !$this->options['minify']['javascript'],
  424. "reorder" => $this->options['rocket']['reorder']
  425. ),
  426. "css" => array(
  427. "cachedir" => $this->options['css_cachedir'],
  428. "cachedir_relative" => str_replace($this->options['document_root'], "/", $this->options['css_cachedir']),
  429. "installdir" => $webo_cachedir,
  430. "gzip" => $this->options['gzip']['css'] &&
  431. ((!$this->options['htaccess']['mod_gzip'] &&
  432. !$this->options['htaccess']['mod_deflate'] &&
  433. (!$this->options['htaccess']['mod_rewrite'] ||
  434. !$this->options['htaccess']['mod_mime'] ||
  435. !$this->options['htaccess']['mod_expires'])) ||
  436. !$this->options['htaccess']['enabled']),
  437. "gzip_level" => round($this->options['gzip']['css_level']),
  438. "minify" => $this->options['minify']['css'],
  439. "minify_body" => $this->options['minify']['css_body'],
  440. "minify_with" => $this->premium > 1 && $this->options['minify']['css_min'] == 2 ?
  441. 'tidy' :
  442. ($this->premium > 1 && $this->options['minify']['css_min'] == 3 ? 'cssmin' :
  443. ($this->options['minify']['css_min'] ? 'basic' : '')),
  444. "far_future_expires" => $this->options['far_future_expires']['css'] &&
  445. !$this->options['htaccess']['mod_expires'],
  446. "far_future_expires_php" => $this->options['far_future_expires']['css'],
  447. "far_future_expires_rewrite" => $this->options['htaccess']['mod_rewrite'] &&
  448. $this->options['htaccess']['enabled'] &&
  449. $this->options['far_future_expires']['css'],
  450. "far_future_expires_static" => ((!($this->options['htaccess']['mod_rewrite'] ||
  451. $this->options['htaccess']['mod_expires']) ||
  452. !$this->options['htaccess']['enabled']) &&
  453. $this->options['far_future_expires']['css']) ||
  454. ((!($this->options['htaccess']['mod_rewrite'] ||
  455. $this->options['htaccess']['mod_deflate'] ||
  456. $this->options['htaccess']['mod_gzip']) ||
  457. !$this->options['htaccess']['enabled']) &&
  458. $this->options['gzip']['css']),
  459. "data_uris" => $this->options['data_uris']['on'],
  460. /* disable mhtml for IE7- under HTTPS */
  461. "data_uris_mhtml" => $this->options['data_uris']['mhtml'] && !$this->https,
  462. "data_uris_separate" => $this->premium > 1 && $this->options['data_uris']['separate'] &&
  463. ((in_array($this->ua_mod, $this->ies) &&
  464. $this->options['data_uris']['mhtml']) ||
  465. (!in_array($this->ua_mod, $this->ies) &&
  466. $this->options['data_uris']['on'])),
  467. "data_uris_domloaded" => $this->options['unobtrusive']['background'] &&
  468. $this->premium > 1,
  469. "data_uris_size" => round($this->options['data_uris']['size']),
  470. "data_uris_mhtml_size" => round($this->options['data_uris']['mhtml_size']),
  471. "data_uris_exclude" => $this->options['data_uris']['ignore_list'],
  472. "data_uris_exclude_mhtml" => $this->options['data_uris']['additional_list'],
  473. "css_sprites" => $this->premium && $this->options['css_sprites']['enabled'],
  474. "css_sprites_expires_rewrite" => (!($this->options['htaccess']['mod_rewrite'] &&
  475. $this->options['htaccess']['mod_expires']) ||
  476. !$this->options['htaccess']['enabled']) &&
  477. $this->options['far_future_expires']['images'],
  478. "css_sprites_ignore" => $this->options['css_sprites']['ignore'],
  479. "css_sprites_exclude" => $this->options['css_sprites']['ignore_list'],
  480. "truecolor_in_jpeg" => $this->premium > 1 && $this->options['css_sprites']['truecolor_in_jpeg'],
  481. "aggressive" => $this->premium > 1 && $this->options['css_sprites']['aggressive'],
  482. "no_ie6" => $this->premium > 1 && $this->options['css_sprites']['no_ie6'],
  483. "dimensions_limited" => $this->premium ? round($this->options['css_sprites']['dimensions_limited']) : 0,
  484. "css_sprites_extra_space" => $this->premium && $this->options['css_sprites']['extra_space'],
  485. "punypng" => $this->premium > 1 ? $this->options['punypng'] : '',
  486. "css_restore_properties" => $this->options['performance']['restore_properties'] &&
  487. $this->premium > 1,
  488. "unobtrusive_body" => false,
  489. "parallel" => $this->options['parallel']['enabled'],
  490. "parallel_hosts" => $this->options['parallel']['allowed_list'],
  491. "external_scripts" => $this->options['external_scripts']['css'],
  492. "inline_scripts" => $this->options['external_scripts']['css_inline'],
  493. "external_scripts_exclude" => $this->options['external_scripts']['additional_list'],
  494. "include_code" => $this->options['external_scripts']['include_code'],
  495. "remove_list" => $this->premium > 1 ? $this->options['external_scripts']['remove_list_css'] : '',
  496. "dont_check_file_mtime" => $this->options['performance']['mtime'],
  497. "file" => $this->premium > 1 ? $this->options['minify']['css_file'] : '',
  498. "host" => $this->premium ? $this->options['minify']['css_host'] : '',
  499. "https" => $this->premium > 1 ? $this->options['parallel']['https'] : '',
  500. "rocket" => $this->options['rocket']['css'] && !$this->options['minify']['css'],
  501. "reorder" => $this->options['rocket']['reorder']
  502. ),
  503. "page" => array(
  504. "cachedir" => $this->options['html_cachedir'],
  505. "cache_engine" => $this->premium ? $this->options['performance']['cache_engine'] : 0,
  506. "cache_engine_options" => $this->premium ? $this->options['performance']['cache_engine_options'] : '',
  507. "cachedir_relative" => str_replace($this->options['document_root'], "/", $this->options['html_cachedir']),
  508. "installdir" => $webo_cachedir,
  509. "host" => $this->options['host'],
  510. "gzip" => $this->options['gzip']['page'] &&
  511. ((!$this->options['htaccess']['mod_gzip'] &&
  512. !$this->options['htaccess']['mod_deflate']) ||
  513. !$this->options['htaccess']['enabled']),
  514. "zlib" => $this->options['gzip']['zlib'],
  515. "gzip_noie" => $this->options['gzip']['noie'] &&
  516. $this->premium > 1,
  517. "gzip_level" => round($this->options['gzip']['page_level']),
  518. "gzip_cookie" => $this->options['gzip']['cookie'] &&
  519. $this->premium > 1,
  520. "minify" => $this->options['minify']['page'],
  521. "minify_aggressive" => $this->options['minify']['html_one_string'] &&
  522. $this->premium,
  523. "remove_comments" => $this->options['minify']['html_comments'] &&
  524. $this->premium,
  525. "dont_check_file_mtime" => $this->options['performance']['mtime'],
  526. "cache_images" => $this->options['far_future_expires']['images'],
  527. "far_future_expires_rewrite" => (!($this->options['htaccess']['mod_rewrite'] ||
  528. $this->options['htaccess']['mod_expires']) ||
  529. !$this->options['htaccess']['enabled']) &&
  530. $this->options['far_future_expires']['images'],
  531. "far_future_expires_external" => $this->options['far_future_expires']['external'],
  532. "clientside_cache" => $this->premium > 1 && $this->options['far_future_expires']['html'],
  533. "clientside_timeout" => $this->options['far_future_expires']['html_timeout'],
  534. "cache" => $this->options['html_cache']['enabled'] &&
  535. $this->premium,
  536. "cache_timeout" => $this->options['html_cache']['timeout'],
  537. "cart_timeout" => $this->premium > 1 ? $this->options['html_cache']['timeout_cart'] : $this->options['html_cache']['timeout'],
  538. "ajax_timeout" => $this->premium > 1 ? $this->options['html_cache']['timeout_ajax'] : $this->options['html_cache']['timeout'],
  539. "flush" => $this->options['html_cache']['flush_only'] &&
  540. $this->premium > 1,
  541. "flush_size" => $this->options['html_cache']['flush_size'],
  542. "cache_ignore" => $this->premium ? $this->options['html_cache']['ignore_list'] : '',
  543. "ignore_include" => $this->premium ? $this->options['html_cache']['ignore'] : '',
  544. "cache_params" => $this->premium > 1 ? $this->options['html_cache']['params'] : '',
  545. "allowed_user_agents" => $this->premium > 1 ? $this->options['html_cache']['allowed_list'] : '',
  546. "exclude_cookies" => $this->premium > 1 ? $this->options['html_cache']['additional_list'] : '',
  547. "parallel" => $this->options['parallel']['enabled'] && !empty($this->options['parallel']['allowed_list']),
  548. "parallel_regexp" => $this->premium > 1 ? $this->options['parallel']['regexp'] : '',
  549. "parallel_hosts" => $this->options['parallel']['allowed_list'],
  550. "parallel_satellites" => $this->options['parallel']['additional'],
  551. "parallel_satellites_hosts" => $this->options['parallel']['additional_list'],
  552. "parallel_ignore" => $this->options['parallel']['ignore_list'],
  553. "parallel_css" => $this->options['parallel']['css'] && !empty($this->options['parallel']['allowed_list']),
  554. "parallel_javascript" => $this->options['parallel']['javascript'] && !empty($this->options['parallel']['allowed_list']),
  555. "parallel_ftp" => $this->premium ? $this->options['parallel']['ftp'] : '',
  556. "parallel_https" => $this->premium > 1 ? $this->options['parallel']['https'] : '',
  557. "unobtrusive_informers" => $this->options['unobtrusive']['informers'] &&
  558. ($this->premium > 1),
  559. "unobtrusive_counters" => $this->options['unobtrusive']['counters'] &&
  560. ($this->premium > 1),
  561. "unobtrusive_ads" => $this->options['unobtrusive']['ads'] &&
  562. ($this->premium > 1),
  563. "unobtrusive_all" => $this->options['unobtrusive']['all'] &&
  564. $this->premium,
  565. "unobtrusive_iframes" => $this->options['unobtrusive']['iframes'] &&
  566. ($this->premium > 1),
  567. "unobtrusive_onload" => $this->options['unobtrusive']['on'] &&
  568. ($this->premium > 1),
  569. "unobtrusive_inline" => $this->options['unobtrusive']['on'] == 2 &&
  570. ($this->premium > 1),
  571. "unobtrusive_configuration" => $this->premium > 1 ? explode(" ", $this->options['unobtrusive']['configuration']) : array(),
  572. "postload" => $this->premium > 1 ? $this->options['unobtrusive']['postload'] : '',
  573. "postload_frames" => $this->premium > 1 ? $this->options['unobtrusive']['frames'] : '',
  574. "footer" => $this->options['footer']['text'],
  575. "footer_image" => $this->options['footer']['image'],
  576. "footer_text" => $this->options['footer']['link'],
  577. "footer_style" => $this->options['footer']['css_code'],
  578. "spot" => $this->premium ? $this->options['footer']['spot'] : 1,
  579. "counter" => $this->premium > 1 ? $this->options['footer']['counter'] : '',
  580. "ab" => $this->options['footer']['ab'] &&
  581. $this->premium > 1,
  582. "htaccess_username" => $this->premium > 1 ? $this->options['external_scripts']['user'] : '',
  583. "htaccess_password" => $this->premium > 1 ? $this->options['external_scripts']['pass'] : '',
  584. "html_tidy" => $this->options['performance']['plain_string'] &&
  585. $this->premium,
  586. "sprites" => $this->premium && $this->options['css_sprites']['html_sprites'],
  587. "sprites_domloaded" => $this->options['unobtrusive']['background'] &&
  588. $this->premium > 1,
  589. "dimensions_limited" => $this->premium ? round($this->options['css_sprites']['html_limit']) : 0,
  590. "per_page" => $this->premium && $this->options['css_sprites']['html_page'],
  591. "https_separate" => $this->premium > 1 ? $this->options['performance']['https'] : 0,
  592. "scale_images" => $this->premium > 1 ? $this->options['performance']['scale'] : 0,
  593. "scale_restriction" => $this->premium > 1 ? $this->options['performance']['scale_restriction'] : 0,
  594. ),
  595. "document_root" => $this->options['document_root'],
  596. "document_root_relative" => str_replace("//", "/", str_replace($this->options['document_root'], "/", $this->options['website_root'])),
  597. "website_root" => $this->options['website_root'],
  598. "cache_version" => round($this->options['performance']['cache_version']) &&
  599. $this->premium > 1,
  600. "uniform_cache" => $this->options['performance']['uniform_cache'] &&
  601. $this->premium > 1,
  602. "plugins" => !empty($this->options['plugins']) &&
  603. $this->premium > 1 ? explode(" ", $this->options['plugins']) : '',
  604. "days_to_delete" => $this->premium > 1 ? round($this->options['performance']['delete_old']) : 0,
  605. "charset" => $this->options['charset'],
  606. "currency" => $this->premium > 1 ? $this->options['currency'] : '',
  607. 'host' => $this->options['host'],
  608. "clean_html_cache" => $this->options['html_cache']['cleanup'] &&
  609. $this->premium > 1 ? $this->options['html_cache']['timeout'] : 0
  610. );
  611. $this->lc = $this->options['license'];
  612. /* overwrite other options array that we passed in */
  613. $this->options = $full_options;
  614. /* some additional checks */
  615. if ($this->options['page']['parallel_css'] && empty($this->options['css']['host'])) {
  616. if ($this->options['page']['parallel_hosts']) {
  617. $hosts = explode(" ", $this->options['page']['parallel_hosts']);
  618. $this->options['css']['host'] = $hosts[0];
  619. } else {
  620. $this->options['page']['parallel_css'] = 0;
  621. }
  622. }
  623. if ($this->options['page']['parallel_javascript'] && empty($this->options['javascript']['host'])) {
  624. if ($this->options['page']['parallel_hosts']) {
  625. $hosts = explode(" ", $this->options['page']['parallel_hosts']);
  626. $this->options['javascript']['host'] = $hosts[0];
  627. } else {
  628. $this->options['page']['parallel_javascript'] = 0;
  629. }
  630. }
  631. }
  632. /**
  633. * Start saving the output buffer
  634. *
  635. **/
  636. function start () {
  637. ob_start();
  638. ob_start();
  639. ob_implicit_flush(0);
  640. }
  641. /**
  642. * Compress passes content directly
  643. *
  644. **/
  645. function compress ($content) {
  646. $this->finish($content);
  647. }
  648. /**
  649. * Do work and return output buffer
  650. *
  651. **/
  652. function finish ($content = false) {
  653. /* disable any actions if not active */
  654. if (empty($this->options['active'])) {
  655. return $content;
  656. }
  657. @ini_set("max_execution_time", 600);
  658. if ($content === false) {
  659. $this->content = @ob_get_clean();
  660. /* clear all other buffers */
  661. while (@ob_end_clean());
  662. } else {
  663. $this->content = $content;
  664. }
  665. /* execute plugin-specific logic, BeforeOptimization event */
  666. if (is_array($this->options['plugins'])) {
  667. foreach ($this->options['plugins'] as $plugin) {
  668. $plugin_file =
  669. $this->options['css']['installdir'] .
  670. 'plugins/' . $plugin . '.php';
  671. if (@is_file($plugin_file)) {
  672. include_once($plugin_file);
  673. $web_optimizer_plugin = new $plugin;
  674. $this->content =
  675. $web_optimizer_plugin->onBeforeOptimization($this->content);
  676. }
  677. }
  678. }
  679. $skip = 0;
  680. $ajax = 0;
  681. if (function_exists('headers_list')) {
  682. $headers = headers_list();
  683. /* define if Content-Type is text/html and allow it */
  684. foreach ($headers as $head) {
  685. $header = strtolower($head);
  686. if (strpos($header, 'content-type:') !== false || (strpos($header, 'location:') !== false && strpos($header, '-location:') === false)) {
  687. $skip++;
  688. }
  689. if (strpos($header, 'text/html') || strpos($header, 'application/xhtml+xml')) {
  690. $skip--;
  691. }
  692. if (strpos($header, 'application/json')) {
  693. $skip++;
  694. $ajax = 1;
  695. }
  696. if (strpos($header, 'content-base') !== false) {
  697. $this->basehref = substr($head, 14);
  698. }
  699. if ($this->ua_mod && strpos($header, 'x-ua-compatible') !== false) {
  700. $this->ua_mod = '.ie' . substr($head, 20);
  701. }
  702. }
  703. }
  704. /* also skip AJAX requests with X-Requested-With: XMLHttpRequest */
  705. if (!$skip &&
  706. !empty($_SERVER['HTTP_X_REQUESTED_WITH']) &&
  707. $_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest') {
  708. $skip = 1;
  709. $ajax = 1;
  710. }
  711. /* also skip some CMS-related parameters */
  712. if (!$skip && !empty($_GET['no_html'])) {
  713. $skip = 1;
  714. $ajax = 1;
  715. }
  716. /* skip some extensions */
  717. if (!$skip && !empty($_SERVER['QUERY_STRING'])) {
  718. $query = explode('.', $_SERVER['QUERY_STRING']);
  719. $ext = strtolower($query[count($query) - 1]);
  720. if (in_array($ext, array('pdf', 'doc', 'xls', 'docx', 'xlsx'))) {
  721. $skip = 1;
  722. }
  723. }
  724. /* skip some known cases of non-HTML content */
  725. if (!$skip) {
  726. /* reduce amount of viewing content, accelerate 'fast check' by 1% */
  727. $spot = substr($this->content, 0, 200);
  728. if (strpos($spot, '<methodResponse') !== false ||
  729. strpos($spot, '<rss') !== false ||
  730. strpos($spot, '<feed') !== false ||
  731. strpos($spot, '<urlset') !== false ||
  732. strpos($spot, '<smf') !== false ||
  733. strlen($spot) < 200) {
  734. $skip = 1;
  735. /* mark AJAX requests */
  736. } elseif (strpos($spot, '{') === 0 || !preg_match("!<h(tml|ead)!is", $spot)) {
  737. $skip = 1;
  738. $ajax = 1;
  739. }
  740. }
  741. /* enable A/B testing */
  742. if (!$skip && !empty($this->options['page']['ab']) && !empty($_COOKIE['WSS_DISABLED'])) {
  743. $this->content = preg_replace("!(<head[^>]*>)!i", "$1" . '<script type="text/javascript">//<![CDATA[' .
  744. "\n" . 'var _gaq=_gaq||[];_gaq.push(["_setCustomVar",1,"WEBOSiteSpeedUp","0"])' . "\n//]]></script>", $this->content);
  745. $skip = 1;
  746. }
  747. /* skip RSS, SMF xml format */
  748. if (!$skip) {
  749. /* define gzip headers at the end */
  750. $this->set_gzip_header();
  751. /* Add UA-Compatible support */
  752. if ($this->ua_mod && strpos($this->content, 'X-UA-Compatible') && !strpos($this->content, 'IE=edge')) {
  753. $this->ua_mod = '.ie' . preg_replace("!.*<meta[^>]+content=['\"]?IE=([0-9]+).*!is", "$1", $this->content);
  754. }
  755. /* create DOMready chunk of JavaScript code, is required for different tasks */
  756. $this->domready_include = $this->domready_include2 = $this->domready_include3 = '';
  757. if ($this->options['css']['data_uris_separate'] || $this->options['page']['sprites_domloaded'] || $this->joomla_cache || $this->wp_cache || $this->generic_cache) {
  758. $this->domready_include = '__WSSLOADED=0;function _weboptimizer_load(){if(__WSSLOADED){return}';
  759. if ($this->options['page']['sprites_domloaded']) {
  760. $this->domready_include .= '_webo_hsprites();';
  761. }
  762. $cart_class = $this->generic_cache ? 'wss_cart' : ($this->joomla_cache ? 'vmCartModule' : 'widget_wp_digi_cart');
  763. if ($this->options['page']['cache'] && $this->cache_me) {
  764. $this->domready_include .= 'var g,x=document,f,h,j;if(typeof x.getElementsByClassName!="undefined"){g=x.getElementsByClassName("' .
  765. $cart_class .
  766. '")[0];f=x.getElementsByClassName("wss_cart_qty")[0];h=x.getElementsByClassName("wss_cart2")[0];j=x.getElementsByClassName("wss_cart2_qty")[0]}else{var b=x.getElementsByTagName("*"),c,d=0;while(c=b[d++]){if(c.className){if(/(^|\s)' .
  767. $cart_class .
  768. '(\s|$)/.test(c.className)){g=c}if(/(^|\s)wss_cart_qty(\s|$)/.test(c.className)){f=c}if(/(^|\s)wss_cart2(\s|$)/.test(c.className)){h=c}if(/(^|\s)wss_cart2_qty(\s|$)/.test(c.className)){j=c}}}}if(g&&!(f&&(parseInt(f.innerHTML)))&&!(j&&(parseInt(j.innerHTML)))){var a,a1;if(typeof window.localStorage!="undefined"){a=window.localStorage.wss_cart||"";a1=window.localStorage.wss_cart2||"";if(x.cookie.indexOf("WSS_CART=0")!==-1){delete window.localStorage["wss_cart"];delete window.localStorage["wss_cart2"]}}else{var b=x.cookie.split(";"),c,d=0,e;while(c=b[d++]){e=c.indexOf("wss_cart=");if(!e||e==1){a=c.substr(e+11).replace(/@#/g,";")}e=c.indexOf("wss_cart2=");if(!e||e==1){a1=c.substr(e+11).replace(/@#/g,";")}}}if(x.cookie.indexOf("WSS_CART=1")!==-1'.
  769. ($this->wp_cache ? '&&x.location.pathname!="/cart/"' : '') .
  770. '){if(a&&a!="undefined"){WSS_CART=g.innerHTML=a}if(a1&&a1!="undefined"){WSS_CART2=h.innerHTML=a1}}}';
  771. }
  772. $this->domready_include .= '__WSSLOADED=1}(function(){var d=document;if(d.addEventListener){d.addEventListener("DOMContentLoaded",_weboptimizer_load,false)}';
  773. if (!empty($this->ua_mod) && substr($this->ua_mod, 3, 1) < 8) {
  774. $this->domready_include .= 'd.write("\x3cscript id=\"_weboptimizer\" defer=\"defer\" src=\"\">\x3c\/script>");(d.getElementById("_weboptimizer")).onreadystatechange=function(){if(this.readyState=="complete"){setTimeout(function(){if(typeof _weboptimizer_load!=="undefined"){_weboptimizer_load()}},0)}};';
  775. } else {
  776. $this->domready_include .= 'if(/WebK/i.test(navigator.userAgent)){var wssload=setInterval(function(){if(/loaded|complete/.test(document.readyState)){clearInterval(wssload);if(typeof _weboptimizer_load!=="undefined"){_weboptimizer_load()}}},10)}';
  777. }
  778. $this->domready_include .= 'window[/*@cc_on !@*/0?"attachEvent":"addEventListener"](/*@cc_on "on"+@*/"load",_weboptimizer_load,false)}());';
  779. if ($this->options['page']['cache']) {
  780. /* clean-up all localStorage values */
  781. if ($this->logged) {
  782. $this->domready_include2 .= 'if(typeof window.localStorage!="undefined"){window.localStorage.wss_cart="";window.localStorage.wss_cart2=""}else{document.cookie="wss_cart=;path=/;expires="+(new Date(new Date().getTime()+' .
  783. ($this->options['page']['cart_timeout'] * 1000) .
  784. ').toGMTString());document.cookie="wss_cart2=;path=/;expires="+(new Date(new Date().getTime()+' .
  785. ($this->options['page']['cart_timeout'] * 1000) .
  786. ').toGMTString())}';
  787. /* store user-specific values into localStorage */
  788. } else {
  789. $this->domready_include2 .= '(function(){var a=window;if(a.parent===a)a[/*@cc_on !@*/0?"attachEvent":"addEventListener"](/*@cc_on "on"+@*/"unload",function(){var a,x=document,y,z,r;if(typeof x.getElementsByClassName!="undefined"){a=x.getElementsByClassName("' .
  790. $cart_class .
  791. '")[0]||0;y=x.getElementsByClassName("wss_cart_qty")[0]||0;z=x.getElementsByClassName("wss_cart2")[0]||0;r=x.getElementsByClassName("wss_cart2_qty")[0]||0}else{var b=x.getElementsByTagName("*"),c,d=0;while(c=b[d++]){if(c.className){if(/(^|\s)' .
  792. $cart_class .
  793. '(\s|$)/.test(c.className)){a=c}if(/(^|\s)wss_cart_qty(\s|$)/.test(c.className)){y=c}if(/(^|\s)wss_cart2(\s|$)/.test(c.className)){z=c}if(/(^|\s)wss_cart2_qty(\s|$)/.test(c.className)){r=c}}}}y=y||a.getElementsByTagName("b")[0];if(a||z){if(a){a=a.innerHTML.replace(/[\r\n]/g," ").replace(/\s+/g," ").replace(/;">/g,"\">").replace(/&amp;/,"&")}if(z){z=z.innerHTML.replace(/[\r\n]/g," ").replace(/\s+/g," ").replace(/;">/g,"\">").replace(/&amp;/,"&")}if(typeof window.localStorage!="undefined"){window.localStorage.wss_cart=a;window.localStorage.wss_cart2=z}else{document.cookie="wss_cart="+a.replace(/;/g,"@#")+";path=/;expires="+(new Date(new Date().getTime()+' .
  794. ($this->options['page']['cart_timeout'] * 1000) .
  795. ').toGMTString());document.cookie="wss_cart2="+z.replace(/;/g,"@#")+";path=/;expires="+(new Date(new Date().getTime()+' .
  796. ($this->options['page']['cart_timeout'] * 1000) .
  797. ').toGMTString())}document.cookie="WSS_CART="+(((a&&y&&parseInt(y.innerHTML))||(z&&r&&parseInt(r.innerHTML)))?1:0)+";path=/;expires="+(new Date(new Date().getTime()+' .
  798. ($this->options['page']['cart_timeout'] * 1000) .
  799. ').toGMTString())}},false)})();';
  800. $this->domready_include3 = '(function(){var a=window;if(a.parent===a)a[/*@cc_on !@*/0?"attachEvent":"addEventListener"](/*@cc_on "on"+@*/"unload",function(){var a,x=document,y,z,r;document.cookie="WSS_CART=0;path=/;expires="+(new Date(new Date().getTime()+' .
  801. ($this->options['page']['cart_timeout'] * 1000) .
  802. ').toGMTString())},false)})();';
  803. }
  804. }
  805. }
  806. /* find all files in head to process */
  807. $this->get_script_array();
  808. /* Run the functions specified in options */
  809. if (is_array($this->options)) {
  810. foreach ($this->options as $func => $option) {
  811. if (method_exists($this, $func)) {
  812. if (!empty($option['gzip']) ||
  813. !empty($option['minify']) ||
  814. !empty($option['far_future_expires']) ||
  815. !empty($option['parallel']) ||
  816. !empty($option['unobtrusive_onload']) ||
  817. !empty($option['unobtrusive_all']) ||
  818. !empty($option['unobtrusive_ads']) ||
  819. !empty($option['unobtrusive_counters']) ||
  820. !empty($option['unobtrusive_informers']) ||
  821. !empty($option['unobtrusive_iframes']) ||
  822. !empty($option['postload']) ||
  823. !empty($option['postload_frames']) ||
  824. !empty($option['cache']) ||
  825. !empty($option['sprites']) ||
  826. !empty($option['counter']) ||
  827. !empty($option['scale_images']) ||
  828. !empty($option['ab']) ||
  829. !empty($this->domready_include)) {
  830. if (!empty($this->web_optimizer_stage)) {
  831. $this->write_progress($this->web_optimizer_stage++);
  832. }
  833. $this->$func($option, $func);
  834. }
  835. }
  836. if ($func == 'page') {
  837. $this->clear_trash();
  838. }
  839. }
  840. }
  841. if (!empty($this->web_optimizer_stage)) {
  842. $this->write_progress($this->web_optimizer_stage);
  843. /* redirect to installation page if chained optimization if finished */
  844. if ($this->web_optimizer_stage > 85) {
  845. $this->write_progress(97);
  846. @header('Location: http://' .
  847. $this->host .
  848. str_replace($this->options['document_root'], '/', realpath(dirname(__FILE__) . '/../')) .
  849. '/index.php?page=install_stage_3&Submit=1&web_optimizer_stage=97&wss__password=' .
  850. $this->password);
  851. /* else redirect to the next stage */
  852. } else {
  853. @header('Location: ' . $this->chained_redirect . '?web_optimizer_stage=' .
  854. $this->web_optimizer_stage .
  855. '&password=' .
  856. $this->password .
  857. '&web_optimizer_debug=1');
  858. }
  859. $this->di();
  860. }
  861. }
  862. if ($ajax && $this->options['page']['ajax_timeout']) {
  863. $this->options['page']['cache_timeout'] = $this->options['page']['ajax_timeout'];
  864. $this->cache_generic(1);
  865. }
  866. /* Return content to requestor */
  867. if ($content) {
  868. return $this->content;
  869. /* or echo content to the browser */
  870. } else {
  871. /* HTTP/1.0 needs Content-Length */
  872. if (($this->encoding || empty($this->gzip_set)) && (empty($_SERVER['SERVER_PROTOCOL']) || $_SERVER['SERVER_PROTOCOL'] == 'HTTP/1.0')) {
  873. @header('Content-Length: ' . strlen($this->content));
  874. }
  875. echo $this->content;
  876. /* It's obvious to send anything right after gzipped content */
  877. if (!empty($this->encoding)) {
  878. $this->di();
  879. }
  880. }
  881. }
  882. /**
  883. * GZIP and minify the javascript as required
  884. *
  885. **/
  886. function javascript ($options,$type) {
  887. /* prepare list of files to process */
  888. $script_files = array();
  889. foreach ($this->initial_files as $file) {
  890. if (!empty($file['tag']) && $file['tag'] == 'script') {
  891. $script_files[] = $file;
  892. }
  893. }
  894. if (!empty($options['minify']) && !empty($script_files)) {
  895. $this->content = $this->do_compress(
  896. array(
  897. 'cachedir' => $options['cachedir'],
  898. 'cachedir_relative' => $options['cachedir_relative'],
  899. 'installdir' => $options['installdir'],
  900. 'host' => $options['host'],
  901. 'tag' => 'script',
  902. 'type' => 'text/javascript',
  903. 'ext' => 'js',
  904. 'src' => 'src',
  905. 'self_close' => 0,
  906. 'gzip' => $options['gzip'],
  907. 'gzip_level' => $options['gzip_level'],
  908. 'minify' => $options['minify'],
  909. 'minify_body' => $options['minify_body'],
  910. 'minify_with' => $options['minify_with'],
  911. 'minify_try' => $options['minify_try'],
  912. 'minify_exclude' => $options['minify_exclude'],
  913. 'remove_duplicates' => $options['remove_duplicates'],
  914. 'far_future_expires' => $options['far_future_expires'],
  915. 'far_future_expires_php' => $options['far_future_expires_php'],
  916. 'far_future_expires_rewrite' => $options['far_future_expires_rewrite'],
  917. 'header' => $type,
  918. 'css_sprites' => 0,
  919. 'css_sprites_exclude' => 0,
  920. 'parallel' => 0,
  921. 'aggressive' => 0,
  922. 'no_ie6' => 0,
  923. 'dimensions_limited' => 0,
  924. 'css_sprites_extra_space' => 0,
  925. 'data_uris' => 0,
  926. 'mhtml' => 0,
  927. 'unobtrusive_body' => $options['unobtrusive_body'],
  928. 'external_scripts' => $options['external_scripts'],
  929. 'inline_scripts' => $options['inline_scripts'],
  930. 'inline_scripts_body' => $options['inline_scripts_body'],
  931. 'external_scripts_head_end' => $options['external_scripts_head_end'],
  932. 'external_scripts_exclude' => $options['external_scripts_exclude'],
  933. 'remove_list' => $options['remove_list'],
  934. 'dont_check_file_mtime' => $options['dont_check_file_mtime'],
  935. 'file' => $options['file'],
  936. 'https' => $options['https'],
  937. 'rocket' => $options['rocket'],
  938. 'rocket_external' => $options['rocket_external'],
  939. 'reorder' => $options['reorder']
  940. ),
  941. $this->content,
  942. $script_files
  943. );
  944. }
  945. }
  946. /**
  947. * GZIP and minify the CSS as required
  948. *
  949. **/
  950. function css ($options, $type) {
  951. /* prepare list of files to process */
  952. $link_files = array();
  953. foreach ($this->initial_files as $file) {
  954. if (!empty($file['tag']) && $file['tag'] == 'link') {
  955. $link_files[] = $file;
  956. }
  957. }
  958. if (!empty($options['minify']) && !empty($link_files)) {
  959. /* Compress separately for each media type*/
  960. $this->content = $this->do_compress(
  961. array(
  962. 'cachedir' => $options['cachedir'],
  963. 'cachedir_relative' => $options['cachedir_relative'],
  964. 'installdir' => $options['installdir'],
  965. 'host' => $options['host'],
  966. 'tag' => 'link',
  967. 'type' => 'text/css',
  968. 'ext' => 'css',
  969. 'src' => 'href',
  970. 'rel' => 'stylesheet',
  971. 'data_uris' => $options['data_uris'],
  972. 'mhtml' => $options['data_uris_mhtml'],
  973. 'data_uris_separate' => $options['data_uris_separate'],
  974. 'data_uris_domloaded' => $options['data_uris_domloaded'],
  975. 'data_uris_size' => $options['data_uris_size'],
  976. 'data_uris_exclude' => $options['data_uris_exclude'],
  977. 'mhtml' => $options['data_uris_mhtml'],
  978. 'mhtml_size' => $options['data_uris_mhtml_size'],
  979. 'mhtml_exclude' => $options['data_uris_exclude_mhtml'],
  980. 'css_sprites' => $options['css_sprites'],
  981. 'css_sprites_ignore' => $options['css_sprites_ignore'],
  982. 'css_sprites_exclude' => $options['css_sprites_exclude'],
  983. 'truecolor_in_jpeg' => $options['truecolor_in_jpeg'],
  984. 'aggressive' => $options['aggressive'],
  985. 'no_ie6' => $options['no_ie6'],
  986. 'dimensions_limited' => $options['dimensions_limited'],
  987. 'css_sprites_extra_space' => $options['css_sprites_extra_space'],
  988. 'css_sprites_expires_rewrite' => $options['css_sprites_expires_rewrite'],
  989. 'punypng' => $options['punypng'],
  990. 'css_restore_properties' => $options['css_restore_properties'],
  991. 'self_close' => 1,
  992. 'gzip' => $options['gzip'],
  993. 'gzip_level' => $options['gzip_level'],
  994. 'minify' => $options['minify'],
  995. 'minify_body' => $options['minify_body'],
  996. 'minify_with' => $options['minify_with'],
  997. 'far_future_expires' => $options['far_future_expires'],
  998. 'far_future_expires_php' => $options['far_future_expires_php'],
  999. 'far_future_expires_rewrite' => $options['far_future_expires_rewrite'],
  1000. 'header' => $type,
  1001. 'unobtrusive_body' => $options['unobtrusive_body'],
  1002. 'parallel' => $options['parallel'],
  1003. 'parallel_hosts' => $options['parallel_hosts'],
  1004. 'external_scripts' => $options['external_scripts'],
  1005. 'inline_scripts' => $options['inline_scripts'],
  1006. 'external_scripts_exclude' => $options['external_scripts_exclude'],
  1007. 'include_code' => $options['include_code'],
  1008. 'remove_list' => $options['remove_list'],
  1009. 'dont_check_file_mtime' => $options['dont_check_file_mtime'],
  1010. 'file' => $options['file'],
  1011. 'https' => $options['https'],
  1012. 'rocket' => $options['rocket'],
  1013. 'rocket_external' => $options['rocket'],
  1014. 'reorder' => $options['reorder']
  1015. ),
  1016. $this->content,
  1017. $link_files
  1018. );
  1019. }
  1020. }
  1021. /**
  1022. * GZIP and minify the page itself as required
  1023. *…

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