Subversion-Projekte lars-tiefland.ci

Revision

Revision 2049 | Revision 2242 | Zur aktuellen Revision | Ganze Datei anzeigen | Leerzeichen ignorieren | Details | Blame | Letzte Änderung | Log anzeigen | RSS feed

Revision 2049 Revision 2107
Zeile 121... Zeile 121...
121
	 * @var	bool
121
	 * @var	bool
122
	 */
122
	 */
123
	public $parse_exec_vars = TRUE;
123
	public $parse_exec_vars = TRUE;
Zeile 124... Zeile 124...
124
 
124
 
125
	/**
125
	/**
126
	 * mbstring.func_override flag
126
	 * mbstring.func_overload flag
127
	 *
127
	 *
128
	 * @var	bool
128
	 * @var	bool
129
	 */
129
	 */
Zeile 130... Zeile 130...
130
	protected static $func_override;
130
	protected static $func_overload;
131
 
131
 
132
	/**
132
	/**
133
	 * Class constructor
133
	 * Class constructor
Zeile 143... Zeile 143...
143
			$this->_zlib_oc === FALSE
143
			$this->_zlib_oc === FALSE
144
			&& config_item('compress_output') === TRUE
144
			&& config_item('compress_output') === TRUE
145
			&& extension_loaded('zlib')
145
			&& extension_loaded('zlib')
146
		);
146
		);
Zeile 147... Zeile 147...
147
 
147
 
Zeile 148... Zeile 148...
148
		isset(self::$func_override) OR self::$func_override = (extension_loaded('mbstring') && ini_get('mbstring.func_override'));
148
		isset(self::$func_overload) OR self::$func_overload = (extension_loaded('mbstring') && ini_get('mbstring.func_overload'));
149
 
149
 
Zeile 150... Zeile 150...
150
		// Get mime types for later
150
		// Get mime types for later
Zeile 584... Zeile 584...
584
		{
584
		{
585
			log_message('error', 'Unable to write cache file: '.$cache_path);
585
			log_message('error', 'Unable to write cache file: '.$cache_path);
586
			return;
586
			return;
587
		}
587
		}
Zeile 588... Zeile 588...
588
 
588
 
589
		if (flock($fp, LOCK_EX))
589
		if ( ! flock($fp, LOCK_EX))
590
		{
-
 
591
			// If output compression is enabled, compress the cache
590
		{
592
			// itself, so that we don't have to do that each time
591
			log_message('error', 'Unable to secure a file lock for file at: '.$cache_path);
593
			// we're serving it
592
			fclose($fp);
594
			if ($this->_compress_output === TRUE)
593
			return;
595
			{
-
 
Zeile -... Zeile 594...
-
 
594
		}
-
 
595
 
-
 
596
		// If output compression is enabled, compress the cache
-
 
597
		// itself, so that we don't have to do that each time
-
 
598
		// we're serving it
-
 
599
		if ($this->_compress_output === TRUE)
-
 
600
		{
596
				$output = gzencode($output);
601
			$output = gzencode($output);
597
 
602
 
598
				if ($this->get_header('content-type') === NULL)
603
			if ($this->get_header('content-type') === NULL)
599
				{
-
 
600
					$this->set_content_type($this->mime_type);
604
			{
-
 
605
				$this->set_content_type($this->mime_type);
Zeile 601... Zeile 606...
601
				}
606
			}
Zeile 602... Zeile 607...
602
			}
607
		}
603
 
608
 
604
			$expire = time() + ($this->cache_expiration * 60);
609
		$expire = time() + ($this->cache_expiration * 60);
605
 
610
 
606
			// Put together our serialized info.
611
		// Put together our serialized info.
Zeile 607... Zeile 612...
607
			$cache_info = serialize(array(
612
		$cache_info = serialize(array(
Zeile 608... Zeile 613...
608
				'expire'	=> $expire,
613
			'expire'	=> $expire,
-
 
614
			'headers'	=> $this->headers
-
 
615
		));
609
				'headers'	=> $this->headers
616
 
610
			));
-
 
611
 
-
 
612
			$output = $cache_info.'ENDCI--->'.$output;
617
		$output = $cache_info.'ENDCI--->'.$output;
613
 
-
 
614
			for ($written = 0, $length = self::strlen($output); $written < $length; $written += $result)
618
 
615
			{
-
 
616
				if (($result = fwrite($fp, self::substr($output, $written))) === FALSE)
-
 
617
				{
-
 
618
					break;
-
 
619
				}
-
 
620
			}
-
 
621
 
-
 
622
			flock($fp, LOCK_UN);
619
		for ($written = 0, $length = self::strlen($output); $written < $length; $written += $result)
Zeile -... Zeile 620...
-
 
620
		{
623
		}
621
			if (($result = fwrite($fp, self::substr($output, $written))) === FALSE)
Zeile 624... Zeile 622...
624
		else
622
			{
625
		{
-
 
626
			log_message('error', 'Unable to secure a file lock for file at: '.$cache_path);
-
 
627
			return;
-
 
628
		}
-
 
629
 
-
 
630
		fclose($fp);
-
 
631
 
-
 
632
		if (is_int($result))
-
 
633
		{
623
				break;
634
			chmod($cache_path, 0640);
624
			}
635
			log_message('debug', 'Cache file written: '.$cache_path);
625
		}
-
 
626
 
636
 
627
		flock($fp, LOCK_UN);
-
 
628
		fclose($fp);
-
 
629
 
-
 
630
		if ( ! is_int($result))
-
 
631
		{
-
 
632
			@unlink($cache_path);
-
 
633
			log_message('error', 'Unable to write the complete cache content at: '.$cache_path);
637
			// Send HTTP cache-control headers to browser to match file cache settings.
634
			return;
Zeile 638... Zeile 635...
638
			$this->set_cache_header($_SERVER['REQUEST_TIME'], $expire);
635
		}
Zeile 639... Zeile 636...
639
		}
636
 
Zeile 706... Zeile 703...
706
			// If so we'll delete it.
703
			// If so we'll delete it.
707
			@unlink($filepath);
704
			@unlink($filepath);
708
			log_message('debug', 'Cache file has expired. File deleted.');
705
			log_message('debug', 'Cache file has expired. File deleted.');
709
			return FALSE;
706
			return FALSE;
710
		}
707
		}
711
		else
-
 
712
		{
708
 
713
			// Or else send the HTTP cache control headers.
709
		// Send the HTTP cache control headers
714
			$this->set_cache_header($last_modified, $expire);
710
		$this->set_cache_header($last_modified, $expire);
715
		}
-
 
Zeile 716... Zeile 711...
716
 
711
 
717
		// Add headers from cache file.
712
		// Add headers from cache file.
718
		foreach ($cache_info['headers'] as $header)
713
		foreach ($cache_info['headers'] as $header)
719
		{
714
		{
Zeile 796... Zeile 791...
796
		if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) && $last_modified <= strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE']))
791
		if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) && $last_modified <= strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE']))
797
		{
792
		{
798
			$this->set_status_header(304);
793
			$this->set_status_header(304);
799
			exit;
794
			exit;
800
		}
795
		}
801
		else
-
 
802
		{
796
 
803
			header('Pragma: public');
797
		header('Pragma: public');
804
			header('Cache-Control: max-age='.$max_age.', public');
798
		header('Cache-Control: max-age='.$max_age.', public');
805
			header('Expires: '.gmdate('D, d M Y H:i:s', $expiration).' GMT');
799
		header('Expires: '.gmdate('D, d M Y H:i:s', $expiration).' GMT');
806
			header('Last-modified: '.gmdate('D, d M Y H:i:s', $last_modified).' GMT');
800
		header('Last-modified: '.gmdate('D, d M Y H:i:s', $last_modified).' GMT');
807
		}
-
 
808
	}
801
	}
Zeile 809... Zeile 802...
809
 
802
 
Zeile 810... Zeile 803...
810
	// --------------------------------------------------------------------
803
	// --------------------------------------------------------------------
Zeile 815... Zeile 808...
815
	 * @param	string	$str
808
	 * @param	string	$str
816
	 * @return	int
809
	 * @return	int
817
	 */
810
	 */
818
	protected static function strlen($str)
811
	protected static function strlen($str)
819
	{
812
	{
820
		return (self::$func_override)
813
		return (self::$func_overload)
821
			? mb_strlen($str, '8bit')
814
			? mb_strlen($str, '8bit')
822
			: strlen($str);
815
			: strlen($str);
823
	}
816
	}
Zeile 824... Zeile 817...
824
 
817
 
Zeile 832... Zeile 825...
832
	 * @param	int	$length
825
	 * @param	int	$length
833
	 * @return	string
826
	 * @return	string
834
	 */
827
	 */
835
	protected static function substr($str, $start, $length = NULL)
828
	protected static function substr($str, $start, $length = NULL)
836
	{
829
	{
837
		if (self::$func_override)
830
		if (self::$func_overload)
838
		{
831
		{
839
			// mb_substr($str, $start, null, '8bit') returns an empty
832
			// mb_substr($str, $start, null, '8bit') returns an empty
840
			// string on PHP 5.3
833
			// string on PHP 5.3
841
			isset($length) OR $length = ($start >= 0 ? self::strlen($str) - $start : -$start);
834
			isset($length) OR $length = ($start >= 0 ? self::strlen($str) - $start : -$start);
842
			return mb_substr($str, $start, $length, '8bit');
835
			return mb_substr($str, $start, $length, '8bit');