PageRenderTime 100ms CodeModel.GetById 6ms app.highlight 73ms RepoModel.GetById 0ms app.codeStats 2ms

/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 **/
   7class 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
  43/* try to restore options backup */
  44		if (@is_file($this->basepath . '.config.webo.php') && !strpos($this->file_get_contents($this->basepath . $this->options_file), '$compress_options[\'license\']')) {
  45			@copy($this->basepath . '.config.webo.php', $this->basepath . $this->options_file);
  46			$this->error = array(-1 => 1);
  47		}
  48		require($this->basepath . $this->options_file);
  49		$this->compress_options = empty($compress_options) ? '' : $compress_options;
  50		$this->start_cache_engine();
  51
  52/* to check and download new Web Optimizer version */
  53		$this->svn_generic = 'http://web-optimizator.googlecode.com/svn/';
  54		$this->svn = $this->svn_generic . 'trunk-stable/';
  55		$this->svn_beta = $this->svn_generic . 'trunk/';
  56		$this->version = str_replace(array("\r", "\n"), "", $this->file_get_contents($this->basepath . 'version'));
  57		$this->version_stable = preg_replace("[^0-9\.]", "", empty($this->input['wss_version_stable']) ? '' : $this->input['wss_version_stable']);
  58/* get the latest version */
  59		$version_new_file = $this->compress_options['html_cachedir'] . 'version.new';
  60		$this->input['wss_page'] = empty($this->input['wss_page']) ? '' : $this->input['wss_page'];
  61		if (in_array($this->input['wss_page'],
  62			array('install_dashboard',
  63				'install_set_password',
  64				'install_enter_password',
  65				'install_system',
  66				'install_update',
  67				'install_beta',
  68				'install_stable',
  69				'install_rollback'))) {
  70			$this->view->download($this->svn . 'version', $version_new_file, 5);
  71		}
  72		$this->version_new = $this->version . '+';
  73		if (@is_file($version_new_file)) {
  74			$this->version_new = str_replace(array("\r", "\n"), "", $this->file_get_contents($version_new_file));
  75			@unlink($version_new_file);
  76		}
  77		$this->version_beta = $this->version;
  78/* check for beta version */
  79		if (in_array($this->input['wss_page'],
  80			array('install_system',
  81				'install_beta',
  82				'install_stable',
  83				'install_rollback'))) {
  84			$this->view->download($this->svn_beta . 'version', $version_new_file, 5);
  85			if (@is_file($version_new_file)) {
  86				$this->version_beta = str_replace(array("\r", "\n"), "", $this->file_get_contents($version_new_file));
  87				@unlink($version_new_file);
  88			}
  89		}
  90/* validate license */
  91		if (!empty($compress_options)) {
  92/* reset license check */
  93			if (!empty($this->input['wss_license']) && $this->input['wss_license'] != $this->compress_options['license']) {
  94				@unlink($this->compress_options['html_cachedir'] . 'wo');
  95			}
  96			$this->compress_options['license'] =
  97				empty($this->input['wss_license']) ?
  98					$this->compress_options['license'] :
  99						$this->input['wss_license'];
 100			$this->premium = $this->view->validate_license($this->compress_options['license'],
 101				$this->compress_options['html_cachedir'], $this->compress_options['host']);
 102			$this->need_access = in_array($this->input['wss_page'],
 103				array('install_enter_password', 'install_set_password'));
 104/* Make sure password valid */
 105			$this->check_password();
 106			if (!$this->access) {
 107				$this->input['wss_page'] = 'install_set_password';
 108			} elseif ($this->need_access) {
 109				$this->input['wss_page'] = 'install_dashboard';
 110			}
 111/* default multiple hosts */
 112			$this->default_hosts = array('img', 'img1', 'img2', 'img3', 'img4', 'i', 'i1', 'i2', 'i3', 'i4', 'image', 'images', 'assets', 'static', 'css', 'js');
 113/* Set page functions for the installation and admin, makes sure nothing else can be run */
 114			$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');
 115/* inializa stage for chained optimization */
 116			$this->web_optimizer_stage =
 117				round(empty($this->input['web_optimizer_stage']) ? 0 :
 118					$this->input['web_optimizer_stage']);
 119/* grade URL from webo.name */
 120			$this->webo_grade = 'https://www.googleapis.com/pagespeedonline/v1/runPagespeed?key=AIzaSyD1VD8YlfdF1RZpPrhOZ1awzuMs4t143Fo&url=http://' .
 121				$this->compress_options['host'] .
 122				str_replace($this->compress_options['document_root'], '/',
 123					$this->compress_options['website_root']);
 124/* download counter */
 125			if (!is_file($this->basepath . 'web-optimizer-counter')) {
 126				$this->view->download('http://web-optimizator.googlecode.com/files/web-optimizer-counter',
 127					$this->basepath . 'web-optimizer-counter', 10);
 128			}
 129/* download WPT evaluation */
 130			if (!is_file($this->basepath . 'web-optimizer-wpt') && !empty($this->compress_options['host'])) {
 131				$this->view->download('http://webo.name/check/wpt.php?url=http://' .
 132					$this->compress_options['host'] .
 133					str_replace($this->compress_options['document_root'], '/',
 134						$this->compress_options['website_root']) .
 135					'&email=' . $this->compress_options['email'], $this->basepath . 'web-optimizer-wpt');
 136			}
 137		}
 138/* define constants for stats */
 139		$this->index_check = 'index.check';
 140		$this->index_before = 'index.before';
 141		$this->index_after = 'index.after';
 142/* initialize info about cache types */
 143		$this->cache_types = array(
 144			'js' => array('*.js', '*.js.gz'),
 145			'js_php' => array('*script.php', '*script.php.gz', '*script.php.df'),
 146			'css' => array('*.css', '*.css.gz'),
 147			'css_php' => array('*link.php', '*link.php.gz', '*link.php.df'),
 148			'res' => array('*.css.css', '*.css.css.gz', '*.php.php', '*.php.php.gz'),
 149			'sprites' => array('webo.*.png', 'webo.*.jpg'),
 150			'imgs' => array('*.png', '*.jpg', '*.gif', '*.bmp'),
 151			'html' => array('*.html','*.html.gz', '*.html.df'),
 152			'scripts' => array('*.php', '*.php.gz', '*.php.df')
 153		);
 154/* define if we can skip some info */
 155		$this->internal = preg_match("@wp-content|components|modules|administrator|addons|app|engine@",
 156			str_replace($this->compress_options['document_root'], '/', $this->basepath));
 157/* detect CS-Cart to */
 158		$this->cscart = strpos($this->basepath, 'addons/webositespeedup');
 159/* check for database driver , WordPress */
 160		$this->internal_sql = strpos($this->basepath, "wp-content") !== false ||
 161/* Joomla! 1.5x */
 162			(strpos($this->basepath, "components") !== false && @is_file($this->compress_options['website_root'] . 'libraries/joomla/database/database/WeboMySql.php'));
 163/* fix for not supported languages */
 164		$this->language = empty($this->language) ? '' : $this->language;
 165		$this->language = in_array($this->language, array('en', 'de', 'es', 'ru', 'ua', 'fr', 'ur', 'it', 'da', 'bg')) ? $this->language : 'en';
 166/* calculate configuration files for Extended and Corporate Editions */
 167		$this->find_configs($this->premium > 1 && $this->premium < 10);
 168		if ($this->compress_options['active']) {
 169			$this->validate();
 170		}
 171		$this->iis = !empty($_SERVER['SERVER_SOFTWARE']) && strpos($_SERVER['SERVER_SOFTWARE'], 'IIS') !== false;
 172
 173/* show page */
 174		if (!empty($this->input) &&
 175			in_array($this->input['wss_page'], $this->page_functions) &&
 176			method_exists($this, $this->input['wss_page']) &&
 177			($this->input['wss_page'] != 'install_set_password' ||
 178			empty($this->internal))) {
 179				$func = $this->input['wss_page'];
 180				$this->$func();
 181		}
 182	}
 183
 184	/*
 185	* Return status of synced file
 186	*
 187	**/
 188	function compress_cdn () {
 189		$file = realpath($this->input['wss_file']);
 190		$size = @filesize($file);
 191		$error = 0;
 192		$success = 1;
 193		if (strpos($file, $this->view->paths['full']['document_root']) !== false &&
 194			!empty($this->compress_options['parallel']['ftp']) &&
 195			@function_exists('curl_init')) {
 196				$mime = '';
 197/* calculate MIME type */
 198				switch (strtolower(preg_replace("!.*\.!is", "", $file))) {
 199					case 'js':
 200						$mime = 'application/x-javascript';
 201						break;
 202					case 'css':
 203						$mime = 'text/css';
 204						break;
 205					case 'jpg':
 206						$mime = 'jpeg';
 207					case 'jpeg':
 208					case 'bmp':
 209					case 'gif':
 210					case 'png':
 211						$mime = 'image/' . $mime;
 212						break;
 213					case 'cur':
 214						$mime = 'image/vnd.microsoft.icon';
 215						break;
 216					case 'ico':
 217						$mime = 'image/x-icon';
 218						break;
 219					case 'otf':
 220						$mime = 'application/x-font-opentype';
 221						break;
 222					case 'ttf':
 223						$mime = 'application/x-font-truetype';
 224						break;
 225					case 'svg':
 226						$mime = 'image/svg+xml';
 227						break;
 228					case 'eot':
 229						$mime = 'application/vnd.ms-fontobject';
 230						break;
 231					case 'woff':
 232						$mime = 'font/woff';
 233						break;
 234				}
 235				$error = $this->view->upload_cdn($file,
 236					$this->compress_options['html_cachedir'],
 237					$this->compress_options['parallel']['ftp'],
 238					$mime,
 239					$this->compress_options['host']);
 240				if (strpos($error, 'Error:') !== false) {
 241					$success = 0;
 242				}
 243		}
 244		$page_variables = array(
 245			"file" => $file,
 246			"size" => $size,
 247			"compressed" => $size,
 248			"success" => $success,
 249			"error" => $error,
 250			"skip_render" => $this->skip_render
 251		);
 252		$this->view->render("compress_gzip", $page_variables);
 253	}
 254
 255	/*
 256	* Return size of specific (optimized images) files
 257	*
 258	**/
 259	function compress_image () {
 260		$file = str_replace('\\', '/', realpath($this->input['wss_file']));
 261		$service = empty($this->input['wss_service']) ? 0 : round($this->input['wss_service']);
 262		$mtime = @filemtime($file);
 263		$size = @filesize($file);
 264		$backup = empty($this->input['wss_backup']) ? '' : $file . '.backup';
 265		$compressed_size = $size;
 266		$error = 0;
 267		if (strpos($file, $this->view->paths['full']['document_root']) !== false) {
 268			if (!$backup || !@is_file($backup) || $mtime != @filemtime($backup)) {
 269				require(dirname(__FILE__) . '/../libs/php/css.sprites.optimize.php');
 270				$optimizer = new css_sprites_optimize();
 271/* CSS Sprites uses .backup itself, so just prepare another backup */
 272				if ($backup && @is_file($backup)) {
 273					@copy($backup, $file . '.bkp');
 274				} else {
 275					@copy($file, $file . '.bkp');
 276				}
 277				$optimizer->website_root = $this->view->paths['full']['document_root'];
 278				switch ($service) {
 279					case 2:
 280						$optimizer->punypng($file);
 281						break;
 282					case 1:
 283						$optimizer->webolk($file);
 284						break;
 285					default:
 286						$optimizer->smushit($file);
 287						break;
 288				}
 289/* copy backup back */
 290				if ($backup) {
 291					@copy($file . '.bkp', $backup);
 292				}
 293				@unlink($file . '.bkp');
 294				$mtime2 = @filemtime($file);
 295/* Has file been changed? */
 296				$success = $mtime2 > $mtime ? 1 : 0;
 297				if ($success) {
 298					$compressed_size = @filesize($file);
 299					@touch($backup, $mtime2);
 300/* can't overwrite targeted file */
 301				} else {
 302					$error = 1;
 303				}
 304			} else {
 305				$success = 1;
 306			}
 307		}
 308		$page_variables = array(
 309			"file" => $file,
 310			"size" => $size,
 311			"compressed" => $compressed_size,
 312			"success" => $success,
 313			"error" => $error,
 314			"skip_render" => $this->skip_render
 315		);
 316		$this->view->render("compress_gzip", $page_variables);
 317	}
 318
 319	/*
 320	* Return size of specific (minified) files
 321	*
 322	**/
 323	function compress_minify () {
 324		$file = realpath($this->input['wss_file']);
 325		$size = @filesize($file);
 326		$chunks = explode(".", $file);
 327		$extension = array_pop($chunks);
 328		$gzipped = $file;
 329		$gzipped_size = $size;
 330		$success = 0;
 331		$error = 0;
 332		if (strpos($file, $this->view->paths['full']['document_root']) !== false) {
 333			$content = '';
 334			$c = $this->file_get_contents($file);
 335			$not_buffered = 1;
 336			require(dirname(__FILE__) . '/../web.optimizer.php');
 337			$not_buffered = 1;
 338			switch (strtolower($extension)) {
 339				case 'css':
 340					switch ($this->compress_options['minify']['css_min']) {
 341						case 1:
 342							$content = $web_optimizer->minify_text($c);
 343							break;
 344						case 2:
 345							$c = preg_replace("!/\*.*?\*/!is", "", $c);
 346							require(dirname(__FILE__) . '/../libs/php/class.csstidy.php');
 347							$csstidy = new csstidy();
 348							$csstidy->load_template(dirname(__FILE__) . '/../libs/php/css.template.tpl');
 349							$csstidy->parse($c);
 350							$content = $csstidy->print->plain();
 351							break;
 352					}
 353					break;
 354				case 'js':
 355					foreach ($web_optimizer->libraries as $klass => $library) {
 356						if (!class_exists($klass, false)) {
 357							require($web_optimizer->options['css']['installdir'] . 'libs/php/' . $library);
 358						}
 359					}
 360					$content = $web_optimizer->minify_javascript($c, $web_optimizer->options['javascript']);
 361					break;
 362			}
 363			if (strlen($content)) {
 364				@copy($file, $file . '.backup');
 365				$success = $this->write_file($gzipped, $content);
 366/* can't overwrite targeted file */
 367				if (!$success) {
 368					$error = 1;
 369				}
 370			} else {
 371				$success = 0;
 372/* cam't gzip file */
 373				$error = 2;
 374			}
 375			if ($success) {
 376				@touch($gzipped, @filemtime($file));
 377				$gzipped_size = @filesize($gzipped);
 378			}
 379		}
 380		$page_variables = array(
 381			"file" => $file,
 382			"size" => $size,
 383			"compressed" => $gzipped_size,
 384			"success" => $success,
 385			"error" => $error,
 386			"skip_render" => $this->skip_render
 387		);
 388		$this->view->render("compress_gzip", $page_variables);
 389	}
 390
 391	/*
 392	* Return size of specific (compressed) files
 393	*
 394	**/
 395	function compress_gzip () {
 396		$file = realpath($this->input['wss_file']);
 397		$size = @filesize($file);
 398		$gzipped = $file . '.gz';
 399		$gzipped_size = $size;
 400		$success = 0;
 401		$error = 0;
 402		if (strpos($file, $this->view->paths['full']['document_root']) !== false) {
 403			if (!@is_file($gzipped) || !@filesize($gzipped)) {
 404				$raw = !function_exists('shell_exec');
 405				$success = 1;
 406				if (!$raw) {
 407					@shell_exec('gzip -c -n -9 ' . $file . ' > ' . $gzipped);
 408					if (!@is_file($gzipped) || !@filesize($gzipped)) {
 409						$raw = 1;
 410					}
 411				}
 412				if ($raw) {
 413					$content = @gzencode($this->file_get_contents($file), 9, FORCE_GZIP);
 414					if (strlen($content)) {
 415						$success = $this->write_file($gzipped, $content);
 416/* can't overwrite targeted file */
 417						if (!$success) {
 418							$error = 1;
 419						}
 420					} else {
 421						$success = 0;
 422/* cam't gzip file */
 423						$error = 2;
 424					}
 425				}
 426				if ($success) {
 427					@touch($gzipped, @filemtime($file));
 428					$gzipped_size = @filesize($gzipped);
 429				}
 430			} else {
 431				$success = 1;
 432				$gzipped_size = @filesize($gzipped);
 433			}
 434		}
 435		$page_variables = array(
 436			"file" => $file,
 437			"size" => $size,
 438			"compressed" => $gzipped_size,
 439			"success" => $success,
 440			"error" => $error,
 441			"skip_render" => $this->skip_render
 442		);
 443		$this->view->render("compress_gzip", $page_variables);
 444	}
 445
 446	/*
 447	* Returns all info about current award + retrieves them from server
 448	*
 449	**/
 450	function calculate_awards () {
 451		$evaluation1 = $this->file_get_contents($this->basepath . $this->index_before);
 452		$evaluation1 = strpos($evaluation1, 'responseCode": 200') === false ? '' : $evaluation1;
 453		$evaluation2 = $this->file_get_contents($this->basepath . $this->index_after);
 454		$evaluation2 = strpos($evaluation1, 'responseCode": 200') === false ? '' : $evaluation2;
 455/* first level - WEBO grade (YSlow + Page Speed + WEBO) */
 456		$grade = round(preg_replace("!.*score\":\s*([0-9]+),.*!s", "$1", $evaluation2));
 457		$level1 = $grade > 50 ? $grade > 70 ? $grade > 90 ? 3 : 2 : 1 : 0;
 458/* second level - website home page size savings */
 459		$size11 = round(preg_replace("!.*htmlResponseBytes\":\s*([0-9]+),.*!", "$1", $evaluation1));
 460		$size12 = round(preg_replace("!.*cssResponseBytes\":\s*([0-9]+),.*!", "$1", $evaluation1));
 461		$size13 = round(preg_replace("!.*imageResponseBytes\":\s*([0-9]+),.*!", "$1", $evaluation1));
 462		$size14 = round(preg_replace("!.*javascriptResponseBytes\":\s*([0-9]+),.*!", "$1", $evaluation1));
 463		$size1 = $size11 + $size12 + $size13 + $size14;
 464		$size21 = round(preg_replace("!.*htmlResponseBytes\":\s*([0-9]+),.*!", "$1", $evaluation2));
 465		$size22 = round(preg_replace("!.*cssResponseBytes\":\s*([0-9]+),.*!", "$1", $evaluation2));
 466		$size23 = round(preg_replace("!.*imageResponseBytes\":\s*([0-9]+),.*!", "$1", $evaluation2));
 467		$size24 = round(preg_replace("!.*javascriptResponseBytes\":\s*([0-9]+),.*!", "$1", $evaluation2));
 468		$size2 = $size21 + $size22 + $size23 + $size24;
 469		$delta = ($size1 - $size2) / ($size1 + 0.01);
 470		$level2 = $size1 && $size2 && $delta > 0.25 ? $delta > 0.5 ? $delta > 0.75 ? 3 : 2 : 1 : 0;
 471/* fourth level - number of files on home page */
 472		$files1 = round(preg_replace("!.*numberResources\":\s*([0-9]+),.*!", "$1", $evaluation1));
 473		$files = round(preg_replace("!.*numberResources\":\s*([0-9]+),.*!", "$1", $evaluation2));
 474		$level4 = $files ? !$files || $files < 35 ? $files < 20 ? $files < 10 ? 3 : 2 : 1 : 0 : 0;
 475/* third level - gained acceleration */
 476		$time1 = round(preg_replace("!.*numberHosts\":\s*([0-9]+),.*!", "$1", $evaluation1));
 477		$time2 = round(preg_replace("!.*numberHosts\":\s*([0-9]+),.*!", "$1", $evaluation2));
 478		$time1 *= $size1 * $files1;
 479		$time2 *= $size2 * $files;
 480		$speedup = ($time1 - $time2) / ($time1 + 0.01);
 481		$speedup = $speedup < 0 || $speedup > 0.9998 ? 0 : $speedup;
 482		$level3 = $speedup > 0.5 ? $speedup > 0.65 ? $speedup > 0.8 ? 3 : 2 : 1 : 0;
 483/* fifth level - WEBO Site SpeedUp options */
 484		$errors = $this->options_count();
 485/* count delta */
 486		$deltas = array(28, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
 487		$options = $deltas[round($this->premium)];
 488		foreach ($errors as $key => $value) {
 489			$options += $value;
 490		}
 491		$level5 = $options < 50 ? $options < 25 ? $options < 5 ? 3 : 2 : 1 : 0;
 492		$awards = $level1 . $level2 . $level3 . $level4 . $level5;
 493		$host = $this->compress_options['host'];
 494/* check for images existence */
 495		if (!@is_file($this->compress_options['css_cachedir'] . 'webo-site-speedup.back.jpg')) {
 496			@copy($this->basepath . 'libs/css/webo-site-speedup.back.jpg',
 497				$this->compress_options['css_cachedir'] . 'webo-site-speedup.back.jpg');
 498		}
 499		if (!@is_file($this->compress_options['css_cachedir'] . 'webo-site-speedup.rocket.png')) {
 500			@copy($this->basepath . 'libs/css/rocket.main.png',
 501				$this->compress_options['css_cachedir'] . 'webo-site-speedup.rocket.png');
 502		}
 503		if ($this->compress_options['awards'] != $awards ||
 504			!@is_file($this->compress_options['css_cachedir'] . 'webo-site-speedup88.png')) {
 505			$sizes = array('88', '125', '161', '250');
 506			foreach ($sizes as $size) {
 507				$this->view->download("http://webo.in/rocket/?size=$size&top=$level1&middle=$level2&bottom=$level3&tail=$level4&circle=$level5",
 508					$this->compress_options['css_cachedir'] . 'webo-site-speedup' . $size . '.png');
 509				$this->view->download("http://webo.in/webonautes/?url=$host&options=" . (100 - $options),
 510						$this->compress_options['css_cachedir'] . 'webonautes.png');
 511				for ($i=1; $i<6; $i++) {
 512					$this->view->download("http://webo.in/webonautes/?size=$size&type=$i&url=$host&options=" . (100 - $options),
 513						$this->compress_options['css_cachedir'] . 'webonaut' . $i . '-' . $size . '.png');
 514				}
 515			}
 516			$local = @is_file($this->compress_options['css_cachedir'] . 'webo-site-speedup250.png');
 517			$this->save_option("['awards']", $awards);
 518/* save final page with awards */
 519			@ob_start();
 520			include($this->basepath . 'view/external_awards.php');
 521			$content = @ob_get_contents();
 522			@ob_end_clean();
 523/* add gzip / charset envelope */
 524			$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;
 525			$this->write_file($this->compress_options['css_cachedir'] . 'webo-site-speedup.php', $content);
 526			$url = 'mhtml:http://' . $host .
 527				str_replace($this->compress_options['document_root'], "/",
 528				$this->compress_options['css_cachedir']) .
 529				'webo-site-speedup.css!';
 530			$content = '.wg-teeth{background-image:url(' .
 531				$url .
 532				'1)}.wg-footer-logo{background-image:url(' .
 533				$url .
 534				"2);display:inline;zoom:1}/*\nContent-Type:multipart/related;boundary=\"_\"" .
 535				"\n\n--_\nContent-Location:1\nContent-Transfer-Encoding:base64\n\n" .
 536				'iVBORw0KGgoAAAANSUhEUgAAAAoAAAAJCAYAAAALpr0TAAAATklEQVQYGY3BTRFAUAAGwG8EEEGNF0YVI4wwasjg7LDGifG/m5ygRZs3aDBjRpM7qDDajahyhs5VnyMULK4WlGxQY/JsQh0Mvg3xU/y0AgXf++/+7UXZAAAAAElFTkSuQmCC' .
 537				"\n\n--_\nContent-Location:2\nContent-Transfer-Encoding:base64\n\n" .
 538				'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' .
 539				"\n\n--_--\n*/";
 540			$this->write_file($this->compress_options['css_cachedir'] . 'webo-site-speedup.css', $content);
 541		}
 542/* download shorten link for twitter */
 543		$this->view->download('http://api.bit.ly/v3/shorten?login=wboptimizer&apiKey=R_c4fd5b38fe32971ae146abbf85aee568&uri='.
 544			urlencode('http://' . $this->compress_options['host'] .
 545				str_replace($this->compress_options['document_root'], "/",
 546				$this->compress_options['css_cachedir']) .
 547				'webo-site-speedup.php') .
 548			'&format=txt', $this->compress_options['css_cachedir'] . 'url');
 549		$short_link = $this->file_get_contents($this->compress_options['css_cachedir'] . 'url');
 550		@unlink($this->compress_options['css_cachedir'] . 'url');
 551		return array($level1, $level2, $level3, $level4, $level5,
 552			100 - $options, $grade, $files, round($size2 / 1024),
 553			round(100*((1 / (0.9999 - $speedup)) - 1)), $short_link);
 554	}
 555	
 556	/*
 557	* Calculate the best options for website.
 558	* Shows wizard page
 559	*
 560	**/	
 561	function install_wizard () {
 562		$wizard = round(isset($_GET['web_optimizer_wizard']) ? $_GET['web_optimizer_wizard'] : 0);
 563/* calculate options */
 564		if ($wizard) {
 565			$wizard_options = isset($_GET['web_optimizer_wizard_options']) ? $_GET['web_optimizer_wizard_options'] : '';
 566/*	1 - disable application, calculate .htaccess, enable client&server side caching
 567	2 - enable combine CSS
 568	3 - disable combine inline CSS
 569	4 - disable combine external CSS
 570	5 - enable minify CSS
 571	6 - disable minify CSS
 572	7 - disable combine CSS
 573	8 - enable gzip CSS
 574	9 - disable gzip CSS
 575	10 - enable combine JS
 576	11 - disable combine inline JS
 577	12 - move JS to head
 578	13 - move JS to /head, disable combine external JS
 579	14 - exclude JS from combine
 580	15 - enable minify JS with JSMin
 581	16 - enable minify JS with YUI Compressor
 582	17 - enable minify JS with Packer
 583	18 - disable minify JS
 584	19 - enable duplicates removal
 585	20 - disable duplicates removal
 586	21 - disable combine JS
 587	22 - enable gzip JS
 588	23 - disable gzip JS
 589	24 - enable minify HTML
 590	25 - disable minify HTML
 591	26 - enable remove HTML comments
 592	27 - disable remove HTML comments
 593	28 - enable gzip HTML
 594	29 - disable gzip HTML
 595	30 - enable plain string + no mtime
 596	31 - disable plain string
 597	32 - enable data:URI + mhtml + separation
 598	33 - disable separation data:URI
 599	34 - disable data:URI + mhtml
 600	35 - set JS host
 601	36 - set CSS host
 602	37 - set IMG host
 603	38 - enable CDN
 604	39 - disable CDN
 605	40 - enable HTML Sprites
 606	41 - enable HTML Sprites restriction
 607	42 - disable HTML Sprites
 608	43 - move JS to /body
 609	44 - move JS to /head
 610	45 - enable unobtrusive JavaScript
 611	46 - disable unobtrusive JavaScript
 612	47 - show selection screen (step2/step3)
 613	48 - show server side screen
 614	49 - enable or disable server side caching
 615	50 - show step3 screen
 616	51 - save settings
 617	100 - final check
 618	*/
 619			switch ($wizard) {
 620/* check htaccess, disable all options */
 621				case 1:
 622/* disable application for future tests */
 623					$this->save_option("['active']", 0);
 624/* disable all the other options */
 625					foreach ($this->compress_options as $group => $options) {
 626						if (is_array($options)) {
 627							foreach ($options as $key => $option) {
 628								if ($option === '1') {
 629									$this->save_option("['". $group ."']['" . $key . "']", 0);
 630								}
 631							}
 632						}
 633					}
 634/* detect .htaccess */
 635					$this->get_modules();
 636					$ht = count($this->apache_modules) ? 1 : 0;
 637/* enable .htaccess */
 638					$this->save_option("['htaccess']['enabled']", $ht);
 639					$this->save_option("['htaccess']['local']", $ht);
 640					$modules = array(
 641						'mod_deflate',
 642						'mod_gzip',
 643						'mod_expires',
 644						'mod_mime',
 645						'mod_headers',
 646						'mod_setenvif',
 647						'mod_rewrite');
 648					foreach ($modules as $module) {
 649						if ($ht && in_array($module, $this->apache_modules)) {
 650							$this->save_option("['htaccess']['" . $module . "']", 1);
 651							$this->input['wss_htaccess_' . $module] = 1;
 652						}
 653					}
 654					if ($ht) {
 655						$this->compress_options['active'] = 1;
 656						$this->input['wss_htaccess_enabled'] = 1;
 657						$this->input['wss_htaccess_local'] = 1;
 658						$this->input['wss_gzip_fonts'] = 1;
 659						$this->input['wss_far_future_expires_css'] = 1;
 660						$this->input['wss_far_future_expires_images'] = 1;
 661						$this->input['wss_far_future_expires_javascript'] = 1;
 662						$this->input['wss_far_future_expires_fonts'] = 1;
 663						$this->input['wss_far_future_expires_video'] = 1;
 664						$this->input['wss_far_future_expires_static'] = 1;
 665/* write complete test set of rules */
 666						$this->write_htaccess();
 667					}
 668					$test_file = $this->compress_options['html_cachedir'] . 'index.test';
 669					$t = time() + microtime();
 670					$this->view->download("http://" . $_SERVER['HTTP_HOST'] .
 671						str_replace($this->compress_options['document_root'], "/", $this->compress_options['website_root']),
 672						$test_file, 20);
 673/* enable HTML caching if server side expenses are more than 500ms + we have known engine */
 674					if (time() + microtime() - $t > 0.5 && $this->internal) {
 675						$this->save_option("['html_cache']['enabled']", 1);
 676						$this->save_option("['html_cache']['timeout']", 3600);
 677						$this->save_option("['sql_cache']['enabled']", 1);
 678						$this->save_option("['sql_cache']['timeout']", 600);
 679/* check for caching extensions */
 680						if (function_exists('xcache_set')) {
 681							$this->save_option("['performance']['cache_engine']", 3);
 682						} elseif (function_exists('apc_store')) {
 683							$this->save_option("['performance']['cache_engine']", 2);
 684						} elseif (@class_exists('Memcached') || @class_exists('Memcache')) {
 685							$this->save_option("['performance']['cache_engine']", 1);
 686						}
 687					}
 688/* some errors with .htaccess, disable all options */
 689					if ($ht && !$this->file_get_contents($test_file)) {
 690						foreach ($modules as $module) {
 691							$this->save_option("['htaccess']['" . $module . "']", 0);
 692							$this->input['wss_htaccess_' . $module] = 0;
 693						}
 694						$this->save_option("['htaccess']['enabled']", 0);
 695						$this->write_htaccess();
 696					}
 697					@unlink($test_file);
 698					$this->save_option("['footer']['spot']", 1);
 699/* enable client side caching */
 700					$this->save_option("['far_future_expires']['css']", 1);
 701					$this->save_option("['far_future_expires']['javascript']", 1);
 702					$this->save_option("['far_future_expires']['fonts']", 1);
 703					$this->save_option("['far_future_expires']['images']", 1);
 704					$this->save_option("['far_future_expires']['video']", 1);
 705					$this->save_option("['far_future_expires']['static']", 1);
 706					break;
 707/* enable combine CSS */
 708				case 2:
 709					if ($wizard_options) {
 710						$this->save_option("['minify']['css_body']", 1);
 711					}
 712					$this->save_option("['minify']['css']", 1);
 713					$this->save_option("['external_scripts']['css']", 1);
 714					$this->save_option("['external_scripts']['css_inline']", 1);
 715					break;
 716/* disable inline CSS */
 717				case 3:
 718					$this->save_option("['external_scripts']['css_inline']", 0);
 719					break;
 720/* disable external CSS */
 721				case 4:
 722					$this->save_option("['external_scripts']['css']", 0);
 723					break;
 724/* enable minify CSS */
 725				case 5:
 726					$this->save_option("['minify']['css_min']", 1);
 727					break;
 728/* disable minify CSS */
 729				case 6:
 730					$this->save_option("['minify']['css_min']", 0);
 731					break;
 732/* disable combine CSS */
 733				case 7:
 734					$this->save_option("['minify']['css']", 0);
 735					$this->save_option("['minify']['css_body']", 0);
 736					break;
 737/* enable gzip CSS */
 738				case 8:
 739					$this->save_option("['gzip']['css']", 1);
 740					$this->save_option("['htaccess']['enabled']", 1);
 741					$this->compress_options['active'] = 1;
 742					$this->compress_options['htaccess']['enabled'] = 1;
 743					$this->compress_options['gzip']['css'] = 1;
 744					foreach ($this->compress_options as $group => $options) {
 745						if (is_array($options)) {
 746							foreach ($options as $key => $option) {
 747								$this->input['wss_'. $group . '_' . $key] = $option;
 748							}
 749						}
 750					}
 751					$this->write_htaccess();
 752					break;
 753/* disable gzip CSS */
 754				case 9:
 755					$this->save_option("['gzip']['css']", 0);
 756					$this->save_option("['htaccess']['enabled']", 0);
 757					$this->input['wss_htaccess_enabled'] = 0;
 758					$this->write_htaccess();
 759					break;
 760/* enable combine JS */
 761				case 10:
 762					$this->save_option("['minify']['javascript']", 1);
 763					$this->save_option("['external_scripts']['on']", 1);
 764					$this->save_option("['external_scripts']['inline']", 1);
 765					$this->save_option("['external_scripts']['head_end']", 1);
 766					break;
 767/* disable combine inline JS */
 768				case 11:
 769					$this->save_option("['external_scripts']['inline']", 0);
 770					break;
 771/* move JS to head */
 772				case 12:
 773					$this->save_option("['external_scripts']['head_end']", 0);
 774					break;
 775/* move JS to /head, disable combine external JS */
 776				case 13:
 777					$this->save_option("['external_scripts']['head_end']", 1);
 778					$this->save_option("['external_scripts']['on']", 0);
 779					break;
 780/* exclude JS from combine */
 781				case 14:
 782					$this->save_option("['external_scripts']['ignore_list']", htmlspecialchars($wizard_options));
 783					break;
 784/* enable minify JS with JSMin */
 785				case 15:
 786					$this->save_option("['minify']['with_jsmin']", 1);
 787					break;
 788/* enable minify JS with YUI Compressor */
 789				case 16:
 790					$this->save_option("['minify']['with_jsmin']", 0);
 791					$this->save_option("['minify']['with_yui']", 1);
 792					break;
 793/* enable minify JS with Packer */
 794				case 17:
 795					$this->save_option("['minify']['with_jsmin']", 0);
 796					$this->save_option("['minify']['with_yui']", 0);
 797					$this->save_option("['minify']['with_packer']", 1);
 798					break;
 799/* disable minify JS */
 800				case 18:
 801					$this->save_option("['minify']['with_jsmin']", 0);
 802					$this->save_option("['minify']['with_yui']", 0);
 803					$this->save_option("['minify']['with_packer']", 0);
 804					break;
 805/* enable duplicates removal */
 806				case 19:
 807					$this->save_option("['external_scripts']['duplicates']", 1);
 808					break;
 809/* disable duplicates removal */
 810				case 20:
 811					$this->save_option("['external_scripts']['duplicates']", 0);
 812					break;
 813/* disable combine JS */
 814				case 21:
 815					$this->save_option("['minify']['javascript']", 0);
 816					break;
 817/* enable gzip JS */
 818				case 22:
 819					$this->save_option("['gzip']['javascript']", 1);
 820					$this->save_option("['htaccess']['enabled']", 1);
 821					$this->compress_options['active'] = 1;
 822					$this->compress_options['htaccess']['enabled'] = 1;
 823					$this->compress_options['gzip']['javascript'] = 1;
 824					foreach ($this->compress_options as $group => $options) {
 825						if (is_array($options)) {
 826							foreach ($options as $key => $option) {
 827								$this->input['wss_'. $group . '_' . $key] = $option;
 828							}
 829						}
 830					}
 831					$this->write_htaccess();
 832					break;
 833/* disable gzip JS */
 834				case 23:
 835					$this->save_option("['gzip']['javascript']", 0);
 836					$this->save_option("['htaccess']['enabled']", 0);
 837					$this->input['wss_htaccess_enabled'] = 0;
 838					$this->write_htaccess();
 839					break;
 840/* enable minify HTML */
 841				case 24:
 842					$this->save_option("['minify']['page']", 1);
 843					break;
 844/* disable minify HTML */
 845				case 25:
 846					$this->save_option("['minify']['page']", 0);
 847					break;
 848/* enable remove HTML comments */
 849				case 26:
 850					$this->save_option("['minify']['html_comments']", 1);
 851					break;
 852/* disable remove HTML comments */
 853				case 27:
 854					$this->save_option("['minify']['html_comments']", 0);
 855					break;
 856/* enable plain string + no mtime */
 857				case 28:
 858					$this->save_option("['performance']['mtime']", 1);
 859					$this->save_option("['performance']['plain_string']", 1);
 860					break;
 861/* disable plain string */
 862				case 29:
 863					$this->save_option("['performance']['plain_string']", 0);
 864					break;
 865/* enable gzip HTML */
 866				case 30:
 867					$this->save_option("['gzip']['page']", 1);
 868					$this->save_option("['gzip']['fonts']", 1);
 869					$this->save_option("['gzip']['cookie']", 1);
 870					$this->save_option("['gzip']['noie']", 1);
 871					$this->save_option("['htaccess']['enabled']", 1);
 872					$this->compress_options['active'] = 1;
 873					$this->compress_options['htaccess']['enabled'] = 1;
 874					$this->compress_options['gzip']['page'] = 1;
 875					foreach ($this->compress_options as $group => $options) {
 876						if (is_array($options)) {
 877							foreach ($options as $key => $option) {
 878								$this->input['wss_'. $group . '_' . $key] = $option;
 879							}
 880						}
 881					}
 882					$this->write_htaccess();
 883					break;
 884/* disable gzip HTML */
 885				case 31:
 886					$this->save_option("['gzip']['page']", 0);
 887					$this->save_option("['gzip']['fonts']", 0);
 888					$this->save_option("['gzip']['cookie']", 0);
 889					$this->save_option("['gzip']['noie']", 0);
 890					$this->save_option("['htaccess']['enabled']", 0);
 891					foreach ($this->compress_options as $group => $options) {
 892						if (is_array($options)) {
 893							foreach ($options as $key => $option) {
 894								$this->input['wss_'. $group . '_' . $key] = $option;
 895							}
 896						}
 897					}
 898					$this->input['wss_htaccess_enabled'] = 0;
 899					$this->write_htaccess();
 900					break;
 901/* enable data:URI + mhtml + separation */
 902				case 32:
 903					$this->save_option("['data_uris']['on']", 1);
 904					$this->save_option("['data_uris']['separate']", 1);
 905					$this->save_option("['unobtrusive']['background']", 1);
 906					break;
 907/* disable separation data:URI */
 908				case 33:
 909					$this->save_option("['data_uris']['separate']", 0);
 910					$this->save_option("['unobtrusive']['background']", 0);
 911					break;
 912/* disable data:URI + mhtml */
 913				case 34:
 914					$this->save_option("['data_uris']['on']", 0);
 915					$this->save_option("['data_uris']['separate']", 0);
 916					$this->save_option("['unobtrusive']['background']", 0);
 917					break;
 918/* set JS host */
 919				case 35:
 920					$this->save_option("['minify']['javascript_host']", htmlspecialchars($wizard_options));
 921					break;
 922/* set CSS host */
 923				case 36:
 924					$this->save_option("['minify']['css_host']", htmlspecialchars($wizard_options));
 925					break;
 926/* set IMG host */
 927				case 37:
 928					$this->save_option("['parallel']['allowed_list']", htmlspecialchars($wizard_options));
 929					break;
 930/* enable CDN */
 931				case 38:
 932					$this->save_option("['parallel']['custom']", 0);
 933					$this->save_option("['parallel']['css']", $this->compress_options['minify']['css_host'] ? 1 : 0);
 934					$this->save_option("['parallel']['javascript']", $this->compress_options['minify']['javascript_host'] ? 1 : 0);
 935					$this->save_option("['parallel']['enabled']", $this->compress_options['parallel']['allowed_list'] ? 1 : 0);
 936					break;
 937/* disable CDN */
 938				case 39:
 939					$this->save_option("['parallel']['custom']", 0);
 940					$this->save_option("['parallel']['css']", 0);
 941					$this->save_option("['parallel']['javascript']", 0);
 942					$this->save_option("['parallel']['enabled']", 0);
 943					$this->save_option("['minify']['css_host']", '');
 944					$this->save_option("['minify']['javascript_host']", '');
 945					$this->save_option("['parallel']['allowed_list']", '');
 946					break;
 947/* enable HTML Sprites */
 948				case 40:
 949					$this->save_option("['css_sprites']['html_sprites']", 1);
 950					$this->save_option("['css_sprites']['html_limit']", 16);
 951					$this->save_option("['css_sprites']['html_page']", 1);
 952					break;
 953/* disable HTML Sprites */
 954				case 41:
 955					$this->save_option("['css_sprites']['html_sprites']", 0);
 956					break;
 957/* enable HTML images scaling */
 958				case 42:
 959					$this->save_option("['performance']['scale']", 1);
 960					break;
 961/* disable HTML images scaling */
 962				case 43:
 963					$this->save_option("['performance']['scale']", 0);
 964					break;
 965/* move JS to /body */
 966				case 44:
 967					$this->save_option("['unobtrusive']['body']", 1);
 968					break;
 969/* move JS to /head */
 970				case 45:
 971					$this->save_option("['unobtrusive']['body']", 0);
 972					break;
 973/* enable unobtrusive JavaScript  */
 974				case 46:
 975					$wizard_options = round($wizard_options);
 976					$this->save_option("['unobtrusive']['informers']", ($wizard_options & 1) ? 1 : 0);
 977					$this->save_option("['unobtrusive']['counters']", ($wizard_options & 2) ? 1 : 0);
 978					$this->save_option("['unobtrusive']['ads']", ($wizard_options & 4) ? 1 : 0);
 979					$this->save_option("['unobtrusive']['iframes']", ($wizard_options & 8) ? 1 : 0);
 980					break;
 981/* disable unobtrusive JavaScript */
 982				case 47:
 983					$this->save_option("['unobtrusive']['informers']", 0);
 984					$this->save_option("['unobtrusive']['counters']", 0);
 985					$this->save_option("['unobtrusive']['ads']", 0);
 986					$this->save_option("['unobtrusive']['iframes']", 0);
 987					break;
 988/* switch to manual mode */
 989				case 48:
 990					break;
 991				case 49:
 992/* enable or disable server side caching */
 993					$wizard_options = round($wizard_options);
 994					switch ($wizard_options) {
 995						case 1:
 996							$this->save_option("['html_cache']['enabled']", 0);
 997							$this->save_option("['sql_cache']['enabled']", 0);
 998							break;
 999						case 2:
1000							$this->save_option("['html_cache']['enabled']", 1);
1001							$this->save_option("['sql_cache']['enabled']", 1);
1002							break;
1003					}
1004					$this->install_clean_cache(0, 1);
1005					break;
1006/* save config */
1007				case 51:
1008					$this->save_option("['active']", 1);
1009					$this->compress_options['active'] = 1;
1010					foreach ($this->compress_options as $group => $options) {
1011						if (is_array($options)) {
1012							foreach ($options as $key => $option) {
1013								$this->input['wss_'. $group . '_' . $key] = $option;
1014							}
1015						}
1016					}
1017/* detect .htaccess */
1018					$this->get_modules();
1019					if (count($this->apache_modules)) {
1020						$this->save_option("['htaccess']['enabled']", 1);
1021						$this->input['wss_htaccess_enabled'] = 1;
1022						$this->compress_options['htaccess']['enabled'] = 1;
1023						$this->write_htaccess();
1024					}
1025/* create fake options */
1026					$this->input['wss_combine_css'] = $this->input['wss_minify_css'] * 2 + $this->input['wss_minify_css_body'];
1027					$this->input['wss_minify_javascript'] = $this->input['wss_minify_javascript'] * 2 + $this->input['wss_minify_javascript_body'];
1028					$this->input['wss_minify_js'] = $this->input['wss_minify_with_google'] ? 5 :
1029						($this->input['wss_minify_with_packer'] ? 4 :
1030						($this->input['wss_minify_with_yui'] ? 3 :
1031						($this->input['wss_minify_with_jsmin'] ? 2 : 1)));
1032/* define configuration file */
1033					if (@is_file($this->basepath . 'config.auto.php')) {
1034						$i = 1;
1035						while (@is_file($this->basepath . 'config.auto'. ($i++) .'.php')) {}
1036						$this->input['wss_config'] = 'auto' . ($i - 1);
1037					} else {
1038						$this->input['wss_config'] = 'auto';
1039					}
1040					$this->save_option("['config']", $this->input['wss_config']);
1041					$this->input['wss_title'] = 'Auto Config';
1042					$this->input['wss_description'] = 'Created by WEBO Wizard on ' . @date("Y-m-d");
1043					$this->input['wss_page'] = 'install_options';
1044					$this->set_options();
1045					break;
1046			}
1047		} else {
1048/* show generic page */
1049		}
1050		$page_variables = array(
1051			"version" => $this->version,
1052			"premium" => $this->premium,
1053			"skip_render" => $this->skip_render,
1054			"wizard_mode" => $wizard,
1055			"website_root" => str_replace($this->compress_options['document_root'], "/", $this->compress_options['website_root'])
1056		);
1057		$this->view->render("install_wizard", $page_variables);
1058	}
1059
1060	/*
1061	* Renders awards page
1062	*
1063	**/
1064	function install_awards () {
1065		$info = $this->calculate_awards();
1066		$level_options = array(
1067			array(
1068				array('gzip', 'clientside', 'combinecss'),
1069				array('minify', 'combine_js', 'data_uri', 'css_sprites'),
1070				array('unobtrusive', 'multiple_hosts', 'performance')),
1071			array(
1072				array('gzip', 'minify', 'htaccess'),
1073				array('combinecss', 'combine_js'),
1074				array('data_uri', 'css_sprites', 'performance')),
1075			array(
1076				array('gzip', 'clientside', 'htaccess', 'combinecss'),
1077				array('minify', 'combine_js', 'data_uri', 'css_sprites', 'serverside'),
1078				array('unobtrusive', 'multiple_hosts', 'performance')),
1079			array(
1080				array('combinecss', 'combine_js'),
1081				array('data_uri', 'css_sprites'),
1082				array('multiple_hosts', 'css_sprites')),
1083			array(
1084				array('htaccess', 'gzip', 'performance', 'unobtrusive'),
1085				array('minify', 'clientside', 'combinecss', 'combine_js'),
1086				array('css_sprites', 'data_uri', 'multiple_hosts'))
1087		);
1088		$page_variables = array(
1089			"version" => $this->version,
1090			"premium" => $this->premium,
1091			"skip_render" => $this->skip_render,
1092			"level1" => $info[0],
1093			"level2" => $info[1],
1094			"level3" => $info[2],
1095			"level4" => $info[3],
1096			"level5" => $info[4],
1097			"local" => @is_file($this->compress_options['css_cachedir'] . 'webo-site-speedup250.png'),
1098			"cachedir" => str_replace($this->compress_options['document_root'], "/",
1099				$this->compress_options['css_cachedir']),
1100			"short_link" => $info[10],
1101			"level_options" => $level_options,
1102			"host" => $this->compress_options['host'],
1103			"options" => $info[5]
1104		);
1105		$this->view->render("install_awards", $page_variables);
1106	}
1107
1108	/*
1109	* Renders account page
1110	*
1111	**/
1112	function install_account () {
1113		$allow = $this->compress_options['optimization'];
1114		$email = $this->compress_options['email'];
1115		$name = $this->compress_options['name'];
1116		$license = $this->compress_options['license'];
1117		$submit = empty($this->input['wss_Submit']) ? '' : $this->input['wss_Submit'];
1118		$error = array();
1119		if (!empty($submit)) {
1120			$email = $this->input['wss_email'];
1121			$allow = empty($this->input['wss_allow']) ? 0 : 1;
1122			$license = trim($this->input['wss_license']);
1123			$name = $this->input['wss_name'];
1124			if (!$this->internal && (empty($this->input['wss_password']) ||
1125				md5($this->input['wss_password']) !=
1126				$this->input['wss__password'])) {
1127				$error[1] = 1;
1128			}
1129			if (empty($this->input['wss_email']) ||
1130				!preg_match("/.+@.+\..+/", $this->input['wss_email'])) {
1131				$error[2] = 1;
1132			}
1133			if (!empty($this->input['wss_new']) &&
1134				(empty($this->input['wss_confirm']) ||
1135					$this->input['wss_confirm'] !=
1136						$this->input['wss_new']) && !$this->internal) {
1137				$error[3] = 1;
1138			}
1139			$this->premium = $this->view->validate_license($license);
1140/* save new options */
1141			if (!count($error)) {
1142				$this->save_option("['email']", htmlspecialchars($email));
1143				$this->save_option("['optimization']", $allow);
1144				$this->save_option("['license']", htmlspecialchars($license));
1145				$this->save_option("['name']", htmlspecialchars($name));
1146				if (!empty($this->input['wss_new'])) {
1147					$this->save_option("['password']", md5($this->input['wss_new']));
1148				}
1149			}
1150		}
1151		$expires = -1;
1152		if (empty($this->premium) && !empty($license)) {
1153			$error[4] = 1;
1154		} elseif (@is_file($this->basepath . 'cache/wo')) {
1155			$expires = $this->file_get_contents($this->basepath . 'cache/wo');
1156		}
1157/* check for additional libraries */
1158		if ($this->premium > 1) {
1159			$jars_to_download = array(
1160				'yuicompressor/yuicompressor.jar',
1161				'googlecompiler/googlecompiler.jar'
1162			);
1163			foreach ($jars_to_download as $jar) {
1164				$jar = 'libs/' . $jar;
1165				if (!@is_file($this->basepath . $jar)) {
1166					$this->view->download($this->svn . $jar, $this->basepath . $jar);
1167/* make lib executable */
1168					@chmod($this->basepath . $jar, octdec("0755"));
1169				}
1170			}
1171		}
1172		$page_variables = array(
1173			"version" => $this->version,
1174			"premium" => $this->premium,
1175			"submit" => $submit,
1176			"expires" => $expires,
1177			"allow" => $allow,
1178			"email" => $email,
1179			"name" => $name,
1180			"license" => $license,
1181			"error" => $error,
1182			"skip_render" => $this->skip_render,
1183			"internal" => $this->internal,
1184			"language" => $this->language,
1185			"root" => str_replace($this->compress_options['document_root'], '/', $this->basepath)
1186		);
1187		$this->view->render("install_account", $page_variables);
1188	}
1189	
1190	/*
1191	* Renders about page
1192	*
1193	**/
1194	function install_about () {
1195		$email = empty($this->input['wss_email']) ? '' : $this->input['wss_email'];
1196		$message = empty($this->input['wss_message']) ? '' : $this->input['wss_message'];
1197		$submit = empty($this->input['wss_Submit']) ? 0 : 1;
1198		$error = array();
1199		if ($submit) {
1200			if (empty($email) ||
1201				!preg_match("/.+@.+\..+/", $email)) {
1202				$error[1] = 1;
1203			}
1204			if (empty($message)) {
1205				$error[2] = 1;
1206			}
1207/* send a email to info@webo.name */
1208			if (!count($error)) {
1209				$this->send_message($email, $message);
1210			}
1211		}
1212		$page_variables = array(
1213			"version" => $this->version,
1214			"premium" => $this->premium,
1215			"email" => $email,
1216			"message" => $message,
1217			"error" => $error,
1218			"submit" => $submit,
1219			"skip_render" => $this->skip_render,
1220			"ready" => @is_file($this->basepath . 'ready')
1221		);
1222		$this->view->render("install_about", $page_variables);
1223	}
1224
1225	/*
1226	* Sends a message from given e-mail
1227	*
1228	**/
1229	function send_message ($email, $message, $uninstall = false) {
1230		$headers = 'From: ' . $email . "\r\n" . 'Reply-To: ' . $email . "\r\n";
1231		$headers .= 'Content-Type: text/plain; charset=utf-8'."\r\n";
1232		$headers .= 'Content-Transfer-Encoding: base64';
1233/* general info */
1234		$message = "On " . @date("Y-m-d") . " at " . @date("H:i:s") . " " .
1235			$this->compress_options['name'] .
1236			" (" . $this->compress_options['email'] . ") send a message: " .
1237			($uninstall ? "(after uninstalltion) " : "") . "\r\n" . $message;
1238/* application info */
1239		$this->cms_version = $this->system_info($this->compress_options['document_root']);
1240		$message .= "\r\n\r\nWEBO Site SpeedUp " . $this->version . " was " .
1241			($this->compress_options['active'] ? "enabled" : "disabled") .
1242			" on " . $this->cms_version . ($this->internal ? " (plugin…

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