<commit_before><?php

	Class extension_LESS_Compiler extends Extension{

		public function about(){
			return array(
				'name' => 'LESS Compiler',
				'version' => '1.0',
				'release-date' => '2011-09-04',
				'author' => array(
					array(
						'name' => '<NAME>',
						'website' => 'http://www.obssessive-media.de/',
						'email' => '<EMAIL>'
					)
				)
			);
		}

		public function getSubscribedDelegates(){
			return array();
		}

		public function install(){
			$htaccess = @file_get_contents(DOCROOT . '/.htaccess');

			if($htaccess === false) return false;

			## Cannot use $1 in a preg_replace replacement string, so using a token instead
			$token = md5(time());

			$rule = "
	### LESS RULES
	RewriteRule ^less\/(.+\.less)\$ extensions/less_compiler/lib/less.php?param={$token} [L,NC]\n\n";

			## Remove existing the rules
			$htaccess = self::__removeLessRules($htaccess);

			if(preg_match('/### LESS RULES/', $htaccess)){
				$htaccess = preg_replace('/### LESS RULES/', $rule, $htaccess);
			}
			else{
				$htaccess = preg_replace('/RewriteRule .\* - \[S=14\]\s*/i', "RewriteRule .* - [S=14]\n{$rule}\t", $htaccess);
			}

			## Replace the token with the real value
			$htaccess = str_replace($token, '$1', $htaccess);

			return @file_put_contents(DOCROOT . '/.htaccess', $htaccess);
		}

		public function uninstall(){
			$htaccess = @file_get_contents(DOCROOT . '/.htaccess');

			if($htaccess === false) return false;

			$htaccess = self::__removeLessRules($htaccess);
			$htaccess = preg_replace('/### LESS RULES/', NULL, $htaccess);

			return @file_put_contents(DOCROOT . '/.htaccess', $htaccess);
		}

		public function enable(){
			return $this->install();
		}

		public function disable(){
			$htaccess = @file_get_contents(DOCROOT . '/.htaccess');

			if($htaccess === false) return false;

			$htaccess = self::__removeLessRules($htaccess);
			$htaccess = preg_replace('/### LESS RULES/', NULL, $htaccess);

			return @file_put_contents(DOCROOT . '/.htaccess', $htaccess);
		}

	/*-------------------------------------------------------------------------
		Utilities:
	-------------------------------------------------------------------------*/

		private static function __removeLessRules($string){
			return preg_replace('/RewriteRule \^less[^\r\n]+[\r\n]?/i', NULL, $string);
		}

	}
<commit_msg>Create less_compiler dir in CACHE on installation<commit_after><?php

	Class extension_LESS_Compiler extends Extension{

		public function about(){
			return array(
				'name' => 'LESS Compiler',
				'version' => '1.0',
				'release-date' => '2011-09-04',
				'author' => array(
					array(
						'name' => '<NAME>',
						'website' => 'http://www.obssessive-media.de/',
						'email' => '<EMAIL>'
					)
				)
			);
		}

		public function getSubscribedDelegates(){
			return array();
		}

		public function install(){
			General::realiseDirectory(CACHE . '/less_compiler/', Symphony::Configuration()->get('write_mode', 'directory'));
			
			$htaccess = @file_get_contents(DOCROOT . '/.htaccess');

			if($htaccess === false) return false;

			## Cannot use $1 in a preg_replace replacement string, so using a token instead
			$token = md5(time());

			$rule = "
	### LESS RULES
	RewriteRule ^less\/(.+\.less)\$ extensions/less_compiler/lib/less.php?param={$token} [L,NC]\n\n";

			## Remove existing the rules
			$htaccess = self::__removeLessRules($htaccess);

			if(preg_match('/### LESS RULES/', $htaccess)){
				$htaccess = preg_replace('/### LESS RULES/', $rule, $htaccess);
			}
			else{
				$htaccess = preg_replace('/RewriteRule .\* - \[S=14\]\s*/i', "RewriteRule .* - [S=14]\n{$rule}\t", $htaccess);
			}

			## Replace the token with the real value
			$htaccess = str_replace($token, '$1', $htaccess);

			return @file_put_contents(DOCROOT . '/.htaccess', $htaccess);
		}

		public function uninstall(){
			$htaccess = @file_get_contents(DOCROOT . '/.htaccess');

			if($htaccess === false) return false;

			$htaccess = self::__removeLessRules($htaccess);
			$htaccess = preg_replace('/### LESS RULES/', NULL, $htaccess);

			return @file_put_contents(DOCROOT . '/.htaccess', $htaccess);
		}

		public function enable(){
			return $this->install();
		}

		public function disable(){
			$htaccess = @file_get_contents(DOCROOT . '/.htaccess');

			if($htaccess === false) return false;

			$htaccess = self::__removeLessRules($htaccess);
			$htaccess = preg_replace('/### LESS RULES/', NULL, $htaccess);

			return @file_put_contents(DOCROOT . '/.htaccess', $htaccess);
		}

	/*-------------------------------------------------------------------------
		Utilities:
	-------------------------------------------------------------------------*/

		private static function __removeLessRules($string){
			return preg_replace('/RewriteRule \^less[^\r\n]+[\r\n]?/i', NULL, $string);
		}

	}

{'fraction_non_alphanumeric': 0.23509933774834438, 'fraction_numerical': 0.007036423841059603, 'mean_word_length': 2.761089494163424, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 24, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7108836', 'n_tokens_mistral': 1864, 'n_tokens_neox': 1545, 'n_words': 332}