[3884] trunk/htdocs/system/classes: Add some doc comments, fix whitespace for coding standard and consistency.

0 views
Skip to first unread message

svn-N...@habariproject.org

unread,
Dec 13, 2009, 8:05:15 PM12/13/09
to habar...@googlegroups.com

Diff

Modified: trunk/htdocs/system/classes/config.php (3883 => 3884)


--- trunk/htdocs/system/classes/config.php	2009-12-14 00:11:08 UTC (rev 3883)
+++ trunk/htdocs/system/classes/config.php	2009-12-14 01:05:15 UTC (rev 3884)
@@ -17,17 +17,17 @@
 	 * Registry of configuration data
 	 */
 	protected static $registry = array();
-	
+
 	/**
 	 * Static; private constructor
 	 */
 	private function __construct()
 	{
 	}
-	
+
 	/**
 	 * See if a key exists
-	 * 
+	 *
 	 * @param string $key key name
 	 * @return bool
 	 */
@@ -35,10 +35,10 @@
 	{
 		return isset( self::$registry[ $key ] );
 	}
-	
+
 	/**
 	 * Fetch data from registry
-	 * 
+	 *
 	 * @param string $key key name
 	 * @return mixed (empty object on invalid key)
 	 */
@@ -49,7 +49,7 @@
 		}
 		return self::$registry[ $key ];
 	}
-	
+
 	/**
 	 * Set data in registry
 	 *
@@ -64,12 +64,13 @@
 		$new = !self::exists( $key );
 		if ( is_scalar( $val ) ) {
 			self::$registry[ $key ] = $val;
-		} else {
+		}
+		else {
 			self::$registry[ $key ] = (object)$val;
 		}
 		return $new;
 	}
-	
+
 	/**
 	 * Unset data
 	 *
@@ -82,4 +83,4 @@
 			unset( self::$registry[ $key ] );
 		}
 	}
-}
\ No newline at end of file
+}

Modified: trunk/htdocs/system/classes/habaridatetime.php (3883 => 3884)


--- trunk/htdocs/system/classes/habaridatetime.php	2009-12-14 00:11:08 UTC (rev 3883)
+++ trunk/htdocs/system/classes/habaridatetime.php	2009-12-14 01:05:15 UTC (rev 3884)
@@ -17,7 +17,7 @@
 	private static $default_datetime_format = 'c';
 	private static $default_date_format;
 	private static $default_time_format;
-	
+
 	/**
 	 * Set default timezone to system default on init.
 	 *
@@ -25,13 +25,13 @@
 	 */
 	public static function __static()
 	{
-		
+
 		if ( Options::get( 'timezone' ) ) {
 			self::set_default_timezone( Options::get( 'timezone' ) );
 		}
-				
+
 		self::$default_timezone = date_default_timezone_get();
-		
+
 		self::$default_date_format = Options::get('dateformat');
 		self::$default_time_format = Options::get('timeformat');
 
@@ -39,7 +39,7 @@
 			self::set_default_datetime_format( self::$default_date_format . ' ' . self::$default_time_format );
 		}
 	}
-	
+
 	/**
 	 * Set default date/time format. The format is the same as the
 	 * internal php {@link http://ca.php.net/date date() function}.
@@ -51,7 +51,7 @@
 	{
 		self::$default_datetime_format = $format;
 	}
-	
+
 	/**
 	 * Get the default date/time format set.
 	 *
@@ -63,10 +63,10 @@
 	{
 		return self::$default_datetime_format;
 	}
-	
+
 	/**
 	 * Sets the timezone for Habari and PHP.
-	 * 
+	 *
 	 * @static
 	 * @param string $timezone A timezone name, not an abbreviation, for example 'America/New York'
 	 */
@@ -75,11 +75,11 @@
 		self::$default_timezone = $timezone;
 		date_default_timezone_set( self::$default_timezone );
 	}
-	
+
 	/**
 	 * Get the timezone for Habari and PHP.
 	 * Defaults to system timezone if not set.
-	 * 
+	 *
 	 * @static
 	 * @see set_default_timezone()
 	 * @param string The deafult timezone.
@@ -88,7 +88,7 @@
 	{
 		return self::$default_timezone;
 	}
-	
+
 	/**
 	 * Helper function to create a HabariDateTime object for the given
 	 * time and timezone. If no time is given, defaults to 'now'. If no
@@ -118,13 +118,13 @@
 		if ( $timezone === null ) {
 			$timezone = self::$default_timezone;
 		}
-		
+
 		// passing the timezone to construct doesn't seem to do anything.
 		$datetime = new HabariDateTime($time);
 		$datetime->set_timezone($timezone);
 		return $datetime;
 	}
-	
+
 	/**
 	 * Set the date of this object
 	 *
@@ -138,7 +138,7 @@
 		parent::setDate($year, $month, $day);
 		return $this;
 	}
-	
+
 	/**
 	 * Sets the ISO date
 	 *
@@ -152,7 +152,7 @@
 		parent::setISODate($year, $week, $day);
 		return $this;
 	}
-	
+
 	/**
 	 * Set the time of this object
 	 *
@@ -166,11 +166,11 @@
 		parent::setTime($hour, $minute, $second);
 		return $this;
 	}
-	
+
 	/**
 	 * Set the timezone for this datetime object. Can be either string
 	 * timezone identifier, or DateTimeZone object.
-	 * 
+	 *
 	 * @see DateTime::setTimezone()
 	 * @param mixed The timezone to use.
 	 * @return HabariDateTime $this object.
@@ -183,20 +183,20 @@
 		parent::setTimezone($timezone);
 		return $this;
 	}
-	
+
 	/**
 	 * Get the timezone identifier that is set for this datetime object.
-	 * 
+	 *
 	 * @return DateTimeZone The timezone object.
 	 */
 	public function get_timezone()
 	{
 		return parent::getTimezone();
 	}
-	
+
 	/**
 	 * Returns date formatted according to given format.
-	 * 
+	 *
 	 * @see DateTime::format()
 	 * @param string $format Format accepted by {@link http://php.net/date date()}.
 	 * @return string The formatted date, false on failure.
@@ -209,16 +209,16 @@
 		return parent::format($format);
 	}
 
-	public function text_format($format) 
-	{ 
-		return preg_replace_callback('%\{(\w)\}%i', array($this, 'text_format_callback'), $format); 
-	} 
-	
-	private function text_format_callback($matches) 
-	{ 
-		return $this->format($matches[1]); 
+	public function text_format($format)
+	{
+		return preg_replace_callback('%\{(\w)\}%i', array($this, 'text_format_callback'), $format);
 	}
-	
+
+	private function text_format_callback($matches)
+	{
+		return $this->format($matches[1]);
+	}
+
 	/**
 	 * Alters the timestamp
 	 *
@@ -230,7 +230,7 @@
 		parent::modify( $args );
 		return $this;
 	}
-	
+
 	/**
 	 * @see format()
 	 */
@@ -238,10 +238,10 @@
 	{
 		return $this->format($format);
 	}
-	
+
 	/**
 	 * Echos date formatted according to given format.
-	 * 
+	 *
 	 * @see format()
 	 * @param string $format Format accepted by {@link http://php.net/date date()}.
 	 */
@@ -249,18 +249,18 @@
 	{
 		echo $this->format($format);
 	}
-	
+
 	/**
 	 * Magic method called when this object is cast to string. Returns the
 	 * unix timestamp of this object.
-	 * 
+	 *
 	 * @return string The unix timestamp
 	 */
 	public function __toString()
 	{
 		return $this->format('U');
 	}
-	
+
 	/**
 	 * Magic method to get magic ponies... properties, I mean.
 	 */
@@ -277,11 +277,11 @@
 			case 'int':
 				return intval( $this->format('U') );
 				break;
-				
+
 			case 'time':
 				return $this->format( self::get_default_time_format() );
 				break;
-				
+
 			case 'date':
 				return $this->format( self::get_default_date_format() );
 				break;
@@ -290,25 +290,35 @@
 				$info = getdate($this->format('U'));
 				$info['mon0'] = substr('0' . $info['mon'], -2, 2);
 				$info['mday0'] = substr('0' . $info['mday'], -2, 2);
-				if(isset($info[$property])) {
+				if ( isset($info[$property]) ) {
 					return $info[$property];
 				}
 				return $this->$property;
 		}
 	}
-	
+
+	/**
+	 * Return the default date format, as set in the Options table
+	 *
+	 * @return The default date format
+	 **/
 	public static function get_default_date_format ( ) {
-		
+
 		return self::$default_date_format;
-		
+
 	}
-	
+
+	/**
+	 * Return the default time format, as set in the Options table
+	 *
+	 * @return The default time format
+	 **/
 	public static function get_default_time_format ( ) {
-		
+
 		return self::$default_time_format;
-		
+
 	}
-	
+
 	/**
 	 * Returns an associative array containing the date information for
 	 * this HabariDateTime object, as per {@link http://php.net/getdate getdate()}

Modified: trunk/htdocs/system/classes/habarilocale.php (3883 => 3884)


--- trunk/htdocs/system/classes/habarilocale.php	2009-12-14 00:11:08 UTC (rev 3883)
+++ trunk/htdocs/system/classes/habarilocale.php	2009-12-14 01:05:15 UTC (rev 3884)
@@ -150,7 +150,7 @@
 		// determine endianness
 		$little_endian = TRUE;
 
-		list(,$magic)= unpack( 'V1', substr( $data, 0, 4 ) );
+		list(,$magic) = unpack( 'V1', substr( $data, 0, 4 ) );
 		switch ( $magic & 0xFFFFFFFF ) {
 			case (int)0x950412de:
 				$little_endian = TRUE;
@@ -223,18 +223,18 @@
 				$ch = $body[$i];
 				switch ($ch) {
 					case '?':
-						$res.= ' ? (';
+						$res .= ' ? (';
 						$p++;
 						break;
 					case ':':
-						$res.= ') : (';
+						$res .= ') : (';
 						break;
 					case ';':
-						$res.= str_repeat( ')', $p) . ';';
+						$res .= str_repeat( ')', $p) . ';';
 						$p = 0;
 						break;
 					default:
-						$res.= $ch;
+						$res .= $ch;
 				}
 			}
 
@@ -264,7 +264,7 @@
 		$fn = self::get_plural_function( $header );
 		$res = '';
 		for ( $n = 0; $n < 200; $n++ ) {
-			$res.= $fn($n);
+			$res .= $fn($n);
 		}
 
 		return $res;
@@ -284,7 +284,7 @@
 	 * @param string $text The text to echo translated
 	 * @param string $domain (optional) The domain to search for the message
 	 **/
-	public static function _e( )
+	public static function _e()
 	{
 		$args = func_get_args();
 		echo call_user_func_array(array('HabariLocale', '_t'), $args);
@@ -328,8 +328,8 @@
 	public static function _u($text, $domain = 'habari')
 	{
 		$t = $text;
-		foreach( self::$messages[$domain] as $msg ) {
-			if( $text == $msg[1][0] ) {
+		foreach ( self::$messages[$domain] as $msg ) {
+			if ( $text == $msg[1][0] ) {
 				$t = $msg[0][0];
 				break;
 			}

Modified: trunk/htdocs/system/classes/hiengine.php (3883 => 3884)


--- trunk/htdocs/system/classes/hiengine.php	2009-12-14 00:11:08 UTC (rev 3883)
+++ trunk/htdocs/system/classes/hiengine.php	2009-12-14 01:05:15 UTC (rev 3884)
@@ -28,7 +28,7 @@
 	public function __construct()
 	{
 		$streams = stream_get_wrappers();
-		if( ! in_array( 'hi' , $streams ) ) {
+		if ( ! in_array( 'hi' , $streams ) ) {
 			stream_wrapper_register("hi", "HiEngineParser")
 			or die(_t("Failed to register HiEngine stream protocol"));
 		}
@@ -43,7 +43,7 @@
 	public function display($template)
 	{
 		extract($this->engine_vars);
-		if ($this->template_exists($template)) {
+		if ( $this->template_exists($template) ) {
 			$template_file = isset($this->template_map[$template]) ? $this->template_map[$template] : null;
 			$template_file = Plugins::filter('include_template_file', $template_file, $template, __CLASS__);
 			$template_file = 'hi://' . $template_file;
@@ -95,7 +95,7 @@
 	 */
 	function stream_read($count)
 	{
-		if($this->stream_eof()) {
+		if ( $this->stream_eof() ) {
 			return false;
 		}
 		$ret = substr($this->file, $this->position, $count);
@@ -144,30 +144,33 @@
 	 */
 	function stream_seek($offset, $whence)
 	{
-		switch ($whence) {
+		switch ( $whence ) {
 			case SEEK_SET:
-				if ($offset < strlen($this->file) && $offset >= 0) {
+				if ( $offset < strlen($this->file) && $offset >= 0 ) {
 					$this->position = $offset;
 					return true;
-				} else {
+				}
+				else {
 					return false;
 				}
 				break;
 
 			case SEEK_CUR:
-				if ($offset >= 0) {
+				if ( $offset >= 0 ) {
 					$this->position += $offset;
 					return true;
-				} else {
+				}
+				else {
 					return false;
 				}
 				break;
 
 			case SEEK_END:
-				if (strlen($this->file) + $offset >= 0) {
+				if ( strlen($this->file) + $offset >= 0 ) {
 					$this->position = strlen($this->file) + $offset;
 					return true;
-				} else {
+				}
+				else {
 					return false;
 				}
 				break;
@@ -213,19 +216,19 @@
 		$cmd = trim($matches[1]);
 
 		// Straight variable or property output, ala {hi:variable_name} or {hi:post.title}
-		if(preg_match('%^[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff.]*$%i', $cmd)) {
+		if ( preg_match('%^[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff.]*$%i', $cmd) ) {
 			$cmd = str_replace('.', '->', $cmd);
-			if(count($this->contexts)) {
+			if ( count($this->contexts) ) {
 				// Build a conditional that checks for the most specific, then the least
 				// eg.- $a->b->c->d->x, then $a->b->c->x, down to just $x
 				$ctx = $this->contexts;
 				$prefixes = array();
-				foreach($ctx as $void) {
+				foreach ( $ctx as $void ) {
 					$prefixes[] = implode('->', $this->contexts);
 					array_pop($ctx);
 				}
 				$output = '<?php echo ';
-				foreach($prefixes as $prefix) {
+				foreach ( $prefixes as $prefix ) {
 					$output .= '(is_object($' . $prefix . ') && !'.'is_null($' . $prefix . '->' . $cmd . ')) ? $' . $prefix . '->' . $cmd . ' : ';
 				}
 				$output .= '$' . $cmd . '; ?>';
@@ -237,8 +240,8 @@
 		}
 
 		// Catch tags in the format {hi:command:parameter}
-		if(preg_match('%^(\w+):(.+)$%', $cmd, $cmd_matches)) {
-			switch(strtolower($cmd_matches[1])) {
+		if ( preg_match('%^(\w+):(.+)$%', $cmd, $cmd_matches) ) {
+			switch ( strtolower($cmd_matches[1]) ) {
 				case 'display':
 					return '<?php $theme->display(\'' . $cmd_matches[2] . '\'); ?>';
 				case 'option':
@@ -264,7 +267,7 @@
 		}
 
 		// Use tags in the format {hi:@foo} as theme functions, ala $theme->foo();
-		if($cmd[0] == '@') {
+		if ( $cmd[0] == '@' ) {
 			return '<?php $theme->' . substr($cmd, 1) . '(); ?>';
 		}
 
@@ -300,10 +303,10 @@
 	{
 		$var = $matches[1];
 
-		if(is_callable($var)) {
+		if ( is_callable($var) ) {
 			return $var;
 		}
-		if(preg_match('/true|false|null|isset|empty/i', $var)) {
+		if ( preg_match('/true|false|null|isset|empty/i', $var) ) {
 			return $var;
 		}
 
@@ -315,17 +318,17 @@
 	function hi_to_var($hisyntax)
 	{
 		$var = str_replace('.', '->', $hisyntax);
-		if(count($this->contexts)) {
+		if ( count($this->contexts) ) {
 			// Build a conditional that checks for the most specific, then the least
 			// eg.- $a->b->c->d->x, then $a->b->c->x, down to just $x
 			$ctx = $this->contexts;
 			$prefixes = array();
-			foreach($ctx as $void) {
+			foreach ( $ctx as $void ) {
 				$prefixes[] = implode('->', $this->contexts);
 				array_pop($ctx);
 			}
 			$output = '';
-			foreach($prefixes as $prefix) {
+			foreach ( $prefixes as $prefix ) {
 				$output .= '(!is_null($' . $prefix . '->' . $var . ') ? $' . $prefix . '->' . $var . ' : ';
 			}
 			$output .= '$' . $var . ')';
@@ -383,19 +386,19 @@
 		preg_match_all('/"(.+?)(?<!\\\\)"/', $matches[1], $quotes);
 		$count = 0;
 		$all_vars = array();
-		foreach($quotes[1] as $index => $quote) {
+		foreach ( $quotes[1] as $index => $quote ) {
 			preg_match_all('%{hi:([a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff.]*)}%', $quote, $vars, PREG_SET_ORDER);
-			foreach($vars as $var) {
+			foreach ( $vars as $var ) {
 				$count++;
 				$quote = str_replace($var[0], '%'.$count.'\$s', $quote);
 				$all_vars[] = '{hi:context:' . $var[1] . '}';  //$this->hi_to_var($var[1]);
 			}
 			$quotes[1][$index] = $quote;
 		}
-		if(count($quotes[1]) > 1) {
+		if ( count($quotes[1]) > 1 ) {
 			$output = '<?php printf(_n("'.$quotes[1][0].'", "'.$quotes[1][1].'", {hi:context:'.$args[0].'})';
 			// Add vars
-			if(count($all_vars) > 0) {
+			if ( count($all_vars) > 0 ) {
 				$output .= ', ' . implode(', ', $all_vars);
 			}
 			array_shift($args);
@@ -403,13 +406,13 @@
 		else {
 			$output = '<?php _e("'.$quotes[1][0].'"';
 			// Add vars
-			if(count($all_vars) > 0) {
+			if ( count($all_vars) > 0 ) {
 				$output .= ', array(' . implode(', ', $all_vars) . ')';
 			}
 		}
 
 		// Add the domain, if any
-		if(isset($args[0])) {
+		if ( isset($args[0]) ) {
 			$output .= ', "'.$args[0].'"';
 		}
 

Modified: trunk/htdocs/system/classes/htmltokenizer.php (3883 => 3884)


--- trunk/htdocs/system/classes/htmltokenizer.php	2009-12-14 00:11:08 UTC (rev 3883)
+++ trunk/htdocs/system/classes/htmltokenizer.php	2009-12-14 01:05:15 UTC (rev 3884)
@@ -18,28 +18,28 @@
 	const NODE_TYPE_CDATA_SECTION = 6;
 	const NODE_TYPE_STATEMENT = 7;
 
-	/* States of the Machine ;p */	
-	private static $STATE_FINISHED = -1; 
+	/* States of the Machine ;p */
+	private static $STATE_FINISHED = -1;
 	private static $STATE_START = 0;
 	private static $STATE_TAG = 1;
 	private static $STATE_ELEMENT_OPEN = 2;
 	private static $STATE_ELEMENT_CLOSE = 3;
 	private static $STATE_STATEMENT = 4;
 	private static $STATE_PI = 5;
-	
+
 	/* Character Ranges */
 	private static $CHR_TAG_BEGIN = '<';
 	private static $CHR_TAG_END = '>';
 	private static $CHR_TAG_END_TRIM = '/';
 	private static $CHR_ATTRNAME_END = '=';
 	private static $CHR_WHITESPACE = " \t\r\n"; // SP, TAB, CR, LF
-	
+
 	private $html;
 	private $pos;
 	private $len;
-	
+
 	private $state;
-	
+
 	private $nodes;
 
 	public function __construct( $html, $escape = true )
@@ -81,15 +81,15 @@
 					break;
 			}
 		}
-		
+
 		return $this->nodes;
 	}
-	
+
 	public function has_more()
 	{
 		return ( $this->pos < $this->len );
 	}
-	
+
 	private function node( $type, $name, $value, $attrs )
 	{
 		$this->nodes[] = array(
@@ -99,15 +99,15 @@
 			'attrs' => $attrs,
 		);
 	}
-	
+
 	private function dec( $n = 1 )
 	{
-		$this->pos-= $n;
+		$this->pos -= $n;
 	}
 
 	private function inc( $n = 1 )
 	{
-		$this->pos+= $n;
+		$this->pos += $n;
 	}
 
 	private function get()
@@ -115,14 +115,14 @@
 		if ( $this->has_more() ) {
 			return $this->html{ $this->pos++ };
 		}
-		
+
 		return NULL;
 	}
-	
+
 	private function peek()
 	{
 		return $this->html{ $this->pos };
-	}	
+	}
 
 	private function up_to_str( $str )
 	{
@@ -132,7 +132,7 @@
 			// finish
 			$this->pos = $this->len;
 		}
-		
+
 		return substr( $this->html, $pos, $this->pos - $pos );
 	}
 
@@ -140,17 +140,16 @@
 	{
 		$pos = $this->pos;
 		$seg_len = strcspn( $this->html, $chr, $pos );
-		$this->pos+= $seg_len;
-		
+		$this->pos += $seg_len;
+
 		return substr( $this->html, $pos, $seg_len );
 	}
 
 	private function skip_whitespace()
 	{
-		$this->pos+= strspn( $this->html, self::$CHR_WHITESPACE, $this->pos );
+		$this->pos += strspn( $this->html, self::$CHR_WHITESPACE, $this->pos );
 	}
 
-	//
 	private function parse_start()
 	{
 		$data = $this->up_to_str( self::$CHR_TAG_BEGIN );
@@ -158,17 +157,17 @@
 		if ( $data != '' ) {
 			$this->node( self::NODE_TYPE_TEXT, '#text', $data, NULL );
 		}
-		
+
 		return self::$STATE_TAG;
 	}
-	
+
 	private function parse_attributes()
 	{
 		$attr = array();
 		$name = '';
-		
+
 		$this->skip_whitespace();
-	
+
 		// read attribute name
 		while ( $name = $this->up_to_chr( self::$CHR_ATTRNAME_END . self::$CHR_TAG_END . self::$CHR_WHITESPACE ) ) {
 			$name = strtolower( rtrim( $name, self::$CHR_TAG_END_TRIM ) );
@@ -176,16 +175,16 @@
 			$this->skip_whitespace();
 			// first non-ws char
 			$char = $this->get();
-			if ($char == '=') {
+			if ( $char == '=' ) {
 				// attribute value follows
 				$this->skip_whitespace();
 				$char = $this->get();
-				if ($char == '"') {
+				if ( $char == '"' ) {
 					// double-quoted
 					$value = $this->up_to_str( '"' );
 					$this->inc();
 				}
-				elseif ($char == '\'') {
+				elseif ( $char == '\'' ) {
 					// single-quoted
 					$value = $this->up_to_str( '\'' );
 					$this->inc();
@@ -200,17 +199,18 @@
 				// TODO HTMLParser should handle #IMPLIED attrs
 				$value = NULL;
 				$this->dec();
-			} else {
+			}
+			else {
 				// default
 				$value = NULL;
 			}
 			// store that attribute only if it's not empty
-			if ($name) {
+			if ( $name ) {
 				$attr[$name] = $value;
 			}
 			$this->skip_whitespace();
 		}
-		
+
 		return $attr;
 	}
 
@@ -244,45 +244,46 @@
 				$this->inc(); // skip peeked '>'
 				// empty tag in collapsed form (<br />)
 				// XXX mark this somehow?
-				$this->node( self::NODE_TYPE_ELEMENT_OPEN, $tag, NULL, $attr ); 
+				$this->node( self::NODE_TYPE_ELEMENT_OPEN, $tag, NULL, $attr );
 				$this->node( self::NODE_TYPE_ELEMENT_CLOSE, $tag, NULL, NULL );
-			} else {
-				$this->node( self::NODE_TYPE_ELEMENT_OPEN, $tag, NULL, $attr ); 
 			}
+			else {
+				$this->node( self::NODE_TYPE_ELEMENT_OPEN, $tag, NULL, $attr );
+			}
 		}
-			
+
 		return self::$STATE_START;
 	}
 
 	private function parse_element_close()
 	{
 		$tag = $this->up_to_chr( self::$CHR_TAG_END );
-		
+
 		if ( $tag != '' ) {
 			$char = $this->get();
 			if ( $char == '/' && $this->peek() == '>' ) {
 				$this->inc();
 			}
-			
-			$this->node( self::NODE_TYPE_ELEMENT_CLOSE, $tag, NULL, NULL ); 
+
+			$this->node( self::NODE_TYPE_ELEMENT_CLOSE, $tag, NULL, NULL );
 		}
-		
+
 		return self::$STATE_START;
 	}
-	
+
 	private function parse_statement()
 	{
 		// everything starting with <!
 		$nodeName = '#statement';
 		$nodeType = self::NODE_TYPE_STATEMENT;
-		
+
 		$char = $this->get();
 		if ( $char == '[' ) {
 			// CDATA
 			// <http://www.w3.org/TR/DOM-Level-2-Core/core.html>
 			$nodeName = '#cdata-section';
 			$nodeType = self::NODE_TYPE_CDATA_SECTION;
-			
+
 			$this->inc( 6 ); // strlen( 'CDATA[' )
 			$data = $this->up_to_str( ']]>' );
 			$this->inc( 2 ); // strlen( ']]' )
@@ -291,7 +292,7 @@
 			// comment
 			$nodeName = '#comment';
 			$nodeType = self::NODE_TYPE_COMMENT;
-			
+
 			// skip peeked -
 			$this->inc();
 			// consume text
@@ -304,42 +305,42 @@
 			// some other kind of statement
 			$this->dec();
 		}
-		
+
 		if ( $nodeType == self::NODE_TYPE_STATEMENT ) {
 			$data = '';
 			$nodeName = $this->up_to_chr( self::$CHR_TAG_END . self::$CHR_TAG_END_TRIM . self::$CHR_WHITESPACE );
 			if ( $this->peek() != '>' ) {
 				// there be data or something
 				$this->skip_whitespace();
-				$data.= $this->up_to_chr( '[>' );
+				$data .= $this->up_to_chr( '[>' );
 				if ( $this->peek() == '[' ) {
 					// internal subset
-					$data.= $this->get() . $this->up_to_str( ']' ) . $this->get();
+					$data .= $this->get() . $this->up_to_str( ']' ) . $this->get();
 				}
 			}
-			$data.= $this->up_to_str( '>' );
+			$data .= $this->up_to_str( '>' );
 			// not like anyone uses them, eh?
 		}
 
 		// skip over final '>'
 		$this->inc();
-		
+
 		if ( $data != '' ) {
 			$this->node( $nodeType, $nodeName, $data, NULL );
 		}
-		
+
 		return self::$STATE_START;
 	}
 
-	private function parse_pi() 
+	private function parse_pi()
 	{
 		$target = $this->up_to_chr( self::$CHR_TAG_END . self::$CHR_WHITESPACE );
 		$data = $this->up_to_chr( self::$CHR_TAG_END );
 		// skip over closing tag
 		$this->inc( 1 );
-		
-		$this->node( self::NODE_TYPE_PI, $target, $data, array() ); 
-		
+
+		$this->node( self::NODE_TYPE_PI, $target, $data, array() );
+
 		return self::$STATE_START;
 	}
 

Modified: trunk/htdocs/system/classes/htmltokenset.php (3883 => 3884)


--- trunk/htdocs/system/classes/htmltokenset.php	2009-12-14 00:11:08 UTC (rev 3883)
+++ trunk/htdocs/system/classes/htmltokenset.php	2009-12-14 01:05:15 UTC (rev 3884)
@@ -32,7 +32,7 @@
 
 	public static function token_to_string( array $token, $escape = true )
 	{
-		switch ($token['type']) {
+		switch ( $token['type'] ) {
 			case HTMLTokenizer::NODE_TYPE_TEXT:
 				return $escape ? htmlspecialchars($token['value']) : $token['value'];
 				break;
@@ -42,9 +42,10 @@
 				if ( isset( $token['attrs'] ) && is_array( $token['attrs'] ) ) {
 					foreach ( $token['attrs'] as $attr => $attrval ) {
 						$out .= " {$attr}=\"";
-						if ($escape) {
+						if ( $escape ) {
 							$out .= htmlspecialchars( html_entity_decode( $attrval, ENT_QUOTES, 'utf-8' ), ENT_COMPAT, 'utf-8' );
-						} else {
+						}
+						else {
 							$out .= html_entity_decode( $attrval, ENT_QUOTES, 'utf-8' );
 						}
 						$out .= '"';
@@ -71,7 +72,7 @@
 
 			case HTMLTokenizer::NODE_TYPE_STATEMENT:
 				$out = "<!{$token['name']}";
-				if (!empty($token['value'])) {
+				if ( !empty($token['value']) ) {
 					$out .= " {$token['value']}";
 				}
 				$out .= ">";
@@ -92,7 +93,7 @@
 	{
 		$names = (array)$names;
 		$ret = array();
-		foreach ($names as $name) {
+		foreach ( $names as $name ) {
 			$offset = 0;
 			$slices = array();
 			while ( $slice = $this->find_slice( $offset, $name, $attr ) ) {
@@ -248,7 +249,8 @@
 	{
 		if ( $offset === null) {
 			$this->tokens[] = $value;
-		} else {
+		}
+		else {
 			$this->tokens[ $offset ] = $value;
 		}
 	}
@@ -258,4 +260,4 @@
 		unset( $this->tokens[ $offset ] );
 	}
 }
-?>
\ No newline at end of file
+?>

Modified: trunk/htdocs/system/classes/installhandler.php (3883 => 3884)


--- trunk/htdocs/system/classes/installhandler.php	2009-12-14 00:11:08 UTC (rev 3883)
+++ trunk/htdocs/system/classes/installhandler.php	2009-12-14 01:05:15 UTC (rev 3884)
@@ -65,7 +65,7 @@
 		// set the default values now, which will be overriden as we go
 		$this->form_defaults();
 
-		if (! $this->meets_all_requirements()) {
+		if ( ! $this->meets_all_requirements() ) {
 			$this->display('requirements');
 		}
 
@@ -86,24 +86,24 @@
 		// try to load any values that might be defined in config.php
 		if ( file_exists( Site::get_dir('config_file') ) ) {
 			include( Site::get_dir('config_file') );
-			
+
 			// check for old style config (global variable, pre-dates registry based config
 			if ( !Config::exists( 'db_connection' ) && isset( $db_connection ) ) {
 				// found old style config...
-				
+
 				// set up registry:
 				Config::set( 'db_connection', $db_connection );
-				
+
 				// assign handler vars (for config file write)
 				$this->set_handler_vars_from_db_connection();
-				
+
 				// write new config file
 				if ( $this->write_config_file( true ) ) {
 					// successful, so redirect:
 					Utils::redirect(Site::get_url( 'habari' ) );
 				}
 			}
-			
+
 			if ( Config::exists( 'db_connection' ) ) {
 				$this->set_handler_vars_from_db_connection();
 			}
@@ -155,18 +155,18 @@
 		}
 
 		// Make sure we still have a valid connection
-		if( ! call_user_func(array( $this, "check_{$db_type}" ) ) ) {
+		if ( ! call_user_func(array( $this, "check_{$db_type}" ) ) ) {
 			$this->display( 'db_setup' );
 		}
 
 		// try to write the config file
-		if (! $this->write_config_file()) {
+		if ( ! $this->write_config_file() ) {
 			$this->theme->assign('form_errors', array('write_file'=>_t('Could not write config.php file...')));
 			$this->display('db_setup');
 		}
 
 		// try to install the database
-		if (! $this->install_db()) {
+		if ( ! $this->install_db() ) {
 			// the installation failed for some reason.
 			// re-display the form
 			$this->display('db_setup');
@@ -249,7 +249,7 @@
 		$this->theme->assign('plugins', $this->get_plugins());
 
 		$this->theme->display($template_name);
-		
+
 		exit;
 	}
 
@@ -271,7 +271,7 @@
 		$formdefaults['blog_title'] = 'My Habari';
 		$formdefaults['admin_email'] = '';
 
-		foreach( $formdefaults as $key => $value ) {
+		foreach ( $formdefaults as $key => $value ) {
 			if ( !isset( $this->handler_vars[$key] ) ) {
 				$this->handler_vars[$key] = $value;
 			}
@@ -308,7 +308,7 @@
 		$this->theme->assign('php_version_ok', $php_version_ok);
 		$this->theme->assign('PHP_OS', PHP_OS);;
 		$this->theme->assign('PHP_VERSION',  phpversion());
-		if (! $php_version_ok) {
+		if ( ! $php_version_ok ) {
 			$requirements_met = false;
 		}
 		/* Check for mod_rewrite on Apache */
@@ -319,7 +319,7 @@
 		/* Check for required extensions */
 		$missing_extensions = array();
 		foreach ($required_extensions as $ext_name => $ext_url) {
-			if (!extension_loaded($ext_name)) {
+			if ( !extension_loaded($ext_name) ) {
 				$missing_extensions[$ext_name] = $ext_url;
 				$requirements_met = false;
 			}
@@ -388,20 +388,20 @@
 		$db_schema = $this->handler_vars['db_schema'];
 		$db_user = $this->handler_vars['db_user'];
 		$db_pass = $this->handler_vars['db_pass'];
-		
+
 		switch($db_type) {
 		case 'mysql':
 		case 'pgsql':
 			// MySQL & PostgreSQL requires specific connection information
-			if (empty($db_user)) {
+			if ( empty($db_user) ) {
 				$this->theme->assign('form_errors', array("{$db_type}_db_user"=>_t('User is required.')));
 				return false;
 			}
-			if (empty($db_schema)) {
+			if ( empty($db_schema) ) {
 				$this->theme->assign('form_errors', array("{$db_type}_db_schema"=>_t('Name for database is required.')));
 				return false;
 			}
-			if (empty($db_host)) {
+			if ( empty($db_host) ) {
 				$this->theme->assign('form_errors', array("{$db_type}_db_host"=>_t('Host is required.')));
 				return false;
 			}
@@ -414,13 +414,13 @@
 			}
 			break;
 		}
-		
+
 		if ( isset( $this->handler_vars['table_prefix'] ) ) {
 			// store prefix in the Config singleton so DatabaseConnection can access it
 			Config::set( 'db_connection', array( 'prefix' => $this->handler_vars['table_prefix'], ) );
 		}
 
-		if (! $this->connect_to_existing_db()) {
+		if ( ! $this->connect_to_existing_db() ) {
 			$this->theme->assign('form_errors', array("{$db_type}_db_user"=>_t('Problem connecting to supplied database credentials')));
 			return false;
 		}
@@ -435,7 +435,7 @@
 		DB::clear_errors();
 		DB::dbdelta($create_table_queries, true, true, true);
 
-		if(DB::has_errors()) {
+		if ( DB::has_errors() ) {
 			$error = DB::get_last_error();
 			$this->theme->assign('form_errors', array('db_host'=>sprintf(_t('Could not create schema tables... %s'), $error['message'])));
 			DB::rollback();
@@ -445,22 +445,22 @@
 		// Cool.  DB installed. Create the default options
 		// but check first, to make sure
 		if ( ! Options::get('installed') ) {
-			if (! $this->create_default_options()) {
+			if ( ! $this->create_default_options() ) {
 				$this->theme->assign('form_errors', array('options'=>_t('Problem creating default options')));
 				DB::rollback();
 				return false;
 			}
 		}
-		
+
 		// Create the Tags vocabulary
-		if(! $this->create_tags_vocabulary()) {
+		if ( ! $this->create_tags_vocabulary() ) {
 			$this->theme->assign('form_errors', array('options'=>_t('Problem creating tags vocabulary')));
 			DB::rollback();
 			return false;
 		}
 
 		// Create the standard post types and statuses
-		if(! $this->create_base_post_types()) {
+		if ( ! $this->create_base_post_types() ) {
 			$this->theme->assign('form_errors', array('options'=>_t('Problem creating base post types')));
 			DB::rollback();
 			return false;
@@ -471,13 +471,13 @@
 		$all_users = Users::get_all();
 		if ( count( $all_users ) < 1 ) {
 			$user = $this->create_admin_user();
-			if (! $user ) {
+			if ( ! $user ) {
 				$this->theme->assign('form_errors', array('admin_user'=>_t('Problem creating admin user.')));
 				DB::rollback();
 				return false;
 			}
 			$admin_group = $this->create_admin_group( $user );
-			if( ! $admin_group ) {
+			if ( ! $admin_group ) {
 				$this->theme->assign('form_errors', array('admin_user'=>_t('Problem creating admin group.')));
 				DB::rollback();
 				return false;
@@ -496,7 +496,7 @@
 		}
 
 		/* Post::save_tags() closes transaction, until we fix that, check and reconnect if needed */
-		if (!DB::in_transaction()) {
+		if ( !DB::in_transaction() ) {
 			DB::begin_transaction();
 		}
 
@@ -581,7 +581,7 @@
 	private function check_sqlite()
 	{
 		$db_file = $this->handler_vars['db_file'];
-		if($db_file == basename($db_file)) { // The filename was given without a path
+		if ( $db_file == basename($db_file) ) { // The filename was given without a path
 			$db_file = Site::get_path( 'user', TRUE ) . $db_file;
 		}
 		if ( file_exists( $db_file ) && is_writable( $db_file ) && is_writable( dirname( $db_file ) ) ) {
@@ -621,7 +621,7 @@
 	 */
 	private function connect_to_existing_db()
 	{
-		if($config = $this->get_config_file()) {
+		if ( $config = $this->get_config_file() ) {
 			$config = preg_replace('/<\\?php(.*)\\?'.'>/ims', '$1', $config);
 			// Update the db_connection from the config that is about to be written:
 			eval($config);
@@ -652,7 +652,7 @@
 		$admin_email = $this->handler_vars['admin_email'];
 		$admin_pass = $this->handler_vars['admin_pass1'];
 
-		if ($admin_pass{0} == '{') {
+		if ( $admin_pass{0} == '{' ) {
 			// looks like we might have a crypted password
 			$password = $admin_pass;
 
@@ -688,7 +688,7 @@
 	{
 		// Create the admin group
 		$group = UserGroup::create( array( 'name' => _t('admin') ) );
-		if( ! $group ) {
+		if ( ! $group ) {
 			return false;
 		}
 		$group->add( $user->id );
@@ -699,7 +699,7 @@
 	{
 		// Create the anonymous group
 		$group = UserGroup::create( array( 'name' => _t('anonymous') ) );
-		if( ! $group ) {
+		if ( ! $group ) {
 			return false;
 		}
 		$group->grant('post_entry', 'read');
@@ -767,15 +767,15 @@
 
 		return true;
 	}
-	
+
 	/**
 	 * Add the tags vocabulary
-	 */	 	
+	 */
 	private function create_tags_vocabulary()
 	{
 		$vocabulary = new Vocabulary( array( 'name' => 'tags', 'description' => 'Habari\'s tags implementation', 'features' => array( 'multiple', 'free' ) ) );
 		$vocabulary->insert();
-		
+
 		return true;
 	}
 
@@ -861,16 +861,16 @@
 	*/
 	private function get_config_file()
 	{
-		if (! ($file_contents = file_get_contents(HABARI_PATH . "/system/schema/" . $this->handler_vars['db_type'] . "/config.php"))) {
+		if ( ! ($file_contents = file_get_contents(HABARI_PATH . "/system/schema/" . $this->handler_vars['db_type'] . "/config.php")) ) {
 			return false;
 		}
 
 		$vars = array();
-		foreach ($this->handler_vars as $k => $v) {
+		foreach ( $this->handler_vars as $k => $v ) {
 			$vars[$k] = addslashes($v);
 		}
 		$keys = array();
-		foreach (array_keys($vars) as $v) {
+		foreach ( array_keys($vars) as $v ) {
 			$keys[] = Utils::map_array($v);
 		}
 
@@ -931,12 +931,12 @@
 				return true;
 			}
 		}
-		if (! ($file_contents = file_get_contents(HABARI_PATH . "/system/schema/" . $this->handler_vars['db_type'] . "/config.php"))) {
+		if ( ! ($file_contents = file_get_contents(HABARI_PATH . "/system/schema/" . $this->handler_vars['db_type'] . "/config.php")) ) {
 			return false;
 		}
-		if($file_contents = $this->get_config_file()) {
-			if ($file = @fopen(Site::get_dir('config_file'), 'w')) {
-				if (fwrite($file, $file_contents, strlen($file_contents))) {
+		if ( $file_contents = $this->get_config_file() ) {
+			if ( $file = @fopen(Site::get_dir('config_file'), 'w') ) {
+				if ( fwrite($file, $file_contents, strlen($file_contents)) ) {
 					fclose($file);
 					return true;
 				}
@@ -1012,9 +1012,9 @@
 	{
 		// default is assume we have mod_rewrite
 		$this->handler_vars['no_mod_rewrite'] = false;
-		
+
 		// If this is the mod_rewrite check request, then bounce it as a success.
-		if( strpos( $_SERVER['REQUEST_URI'], 'check_mod_rewrite' ) !== false ) {
+		if ( strpos( $_SERVER['REQUEST_URI'], 'check_mod_rewrite' ) !== false ) {
 			echo 'ok';
 			exit;
 		}
@@ -1032,7 +1032,8 @@
 				// the Habari block does not exist in this file
 				// so try to create it
 				$result = $this->write_htaccess( true );
-			} else {
+			}
+			else {
 				// the Habari block exists
 				$result = true;
 			}
@@ -1065,7 +1066,7 @@
 	public function write_htaccess( $exists = FALSE, $update = FALSE, $rewritebase = TRUE )
 	{
 		$htaccess = $this->htaccess();
-		if($rewritebase) {
+		if ( $rewritebase ) {
 			$rewrite_base = trim( dirname( $_SERVER['SCRIPT_NAME'] ), '/\\' );
 			$htaccess['rewrite_base'] = 'RewriteBase /' . $rewrite_base;
 		}
@@ -1337,7 +1338,7 @@
 
 		// Apply data changes to the database based on version, call the db-specific upgrades, too.
 		$this->upgrade_db_post( $version );
-		
+
 		// run schema-specific upgrade scripts for after dbdelta
 		DB::upgrade_post( $version );
 
@@ -1371,8 +1372,8 @@
 		// Strip the base path off active plugins
 		$base_path = array_map( create_function( '$s', 'return str_replace(\'\\\\\', \'/\', $s);' ), array( HABARI_PATH ) );
 		$activated = Options::get( 'active_plugins' );
-		if( is_array( $activated ) ) {
-			foreach( $activated as $plugin ) {
+		if ( is_array( $activated ) ) {
+			foreach ( $activated as $plugin ) {
 				$index = array_search( $plugin, $activated );
 				$plugin = str_replace( $base_path, '', $plugin );
 				$activated[$index] = $plugin;
@@ -1440,7 +1441,7 @@
 	{
 		// Create the admin group
 		$group = UserGroup::create( array( 'name' => 'admin' ) );
-		if( ! $group ) {
+		if ( ! $group ) {
 			return false;
 		}
 
@@ -1471,7 +1472,7 @@
 		foreach ( Post::list_active_post_types() as $name => $posttype ) {
 				ACL::destroy_token( 'own_post_' . Utils::slugify($name) );
 		}
-		
+
 		ACL::destroy_token( 'own_posts_any' );
 		ACL::create_token( 'own_posts', _t('Permissions on one\'s own posts'), 'Content', true );
 	}
@@ -1480,7 +1481,7 @@
 	{
 		// Add a default to the number of posts of a feed
 		$atom_entries = Options::get( 'atom_entries' );
-		if( empty( $atom_entries ) ) {
+		if ( empty( $atom_entries ) ) {
 			Options::set( 'atom_entries', '5' );
 		}
 		// Create the default authenticated group
@@ -1493,22 +1494,22 @@
 		$authenticated_group->grant( 'comment' );
 
 	}
-	
+
 	private function upgrade_db_post_3484()
 	{
 		$new_plugins = array();
 		$plugins = Options::get( 'active_plugins' );
-		if( is_array($plugins) ) {
-			foreach( $plugins as $filename ) {
-				if(!file_exists($filename)) {
+		if ( is_array($plugins) ) {
+			foreach ( $plugins as $filename ) {
+				if ( !file_exists($filename) ) {
 					// try adding base path to stored path
 					$filename = HABARI_PATH . $filename;
 				}
-				if(file_exists($filename)) {
+				if ( file_exists($filename) ) {
 					require_once $filename;
 					$class = Plugins::class_from_filename($filename);
 					$short_file = substr( $filename, strlen( HABARI_PATH ) );
-					if( $class ) {
+					if ( $class ) {
 						$new_plugins[$class] = $short_file;
 					}
 				}
@@ -1517,38 +1518,38 @@
 
 		Options::set('active_plugins', $new_plugins);
 	}
-	
+
 	private function upgrade_db_post_3539()
 	{
-		
+
 		// get the global option
 		$hide = Options::get( 'dashboard__hide_spam_count' );
-		
+
 		// if it was set to hide, get all our available users and set their info values instead
 		if ( $hide == true ) {
-			
+
 			$users = Users::get();
-			
+
 			foreach ( $users as $user ) {
-				
+
 				$user->info->dashboard_hide_spam_count = 1;
 				$user->update();
-				
+
 			}
-			
+
 		}
-		
+
 		Options::delete( 'dashboard__hide_spam_count' );
-		
+
 		return true;
-		
+
 	}
-	
+
 	private function upgrade_db_post_3698()
 	{
 		ACL::create_token( 'manage_self', _t('Edit own profile'), 'Administration' );
 	}
-	
+
 	private function upgrade_db_post_3701()
 	{
 		ACL::create_token( 'manage_dash_modules', _t('Manage dashboard modules'), 'Administration' );
@@ -1560,17 +1561,17 @@
 
 		$vocabulary = new Vocabulary( array( 'name' => 'tags', 'description' => 'Habari\'s tags implementation', 'features' => array( 'multiple', 'free' ) ) );
 		$vocabulary->insert();
-		
+
 		$new_tag = NULL;
 		$post_ids = array();
 		$prefix = Config::get( 'db_connection' )->prefix;
 
 		$results = DB::get_results( "SELECT id, tag_text, tag_slug from {$prefix}tags" );
 
-		foreach( $results as $tag ) {
+		foreach ( $results as $tag ) {
 			$new_tag = $vocabulary->add_term( $tag->tag_text );
 			$post_ids = DB::get_column( "SELECT post_id FROM {$prefix}tag2post WHERE tag_id = ?", array( $tag->id ) );
-			foreach( $post_ids as $id ) {
+			foreach ( $post_ids as $id ) {
 				DB::insert( "{object_terms}", array( 'term_id' => $new_tag->id, 'object_id' => $id, 'object_type_id' => $type_id ) );
 			}
 		}
@@ -1734,7 +1735,7 @@
 			$xml_error->addChild( 'message', _t('The database file was left empty.') );
 		}
 		if ( !isset( $xml_error ) ) {
-			if($db_file == basename($db_file)) { // The filename was given without a path
+			if ( $db_file == basename($db_file) ) { // The filename was given without a path
 				$db_file = Site::get_path( 'user', TRUE ) . $db_file;
 			}
 			if ( ! is_writable( dirname( $db_file ) ) ) {
@@ -1742,13 +1743,15 @@
 				$xml_error = $xml->addChild( 'error' );
 				$xml_error->addChild( 'id', '#databasefile' );
 				$xml_error->addChild( 'message', _t('Cannot write to %s directory. SQLite requires that the directory that holds the DB file be writable by the web server.', array(dirname($db_file)) ) );
-			} elseif ( file_exists ( Site::get_path( 'user', TRUE ) . $db_file ) && ( ! is_writable( Site::get_path( 'user', TRUE ) . $db_file ) ) ) {
+			}
+			elseif ( file_exists ( Site::get_path( 'user', TRUE ) . $db_file ) && ( ! is_writable( Site::get_path( 'user', TRUE ) . $db_file ) ) ) {
 				$xml->addChild( 'status', 0 );
 				$xml_error = $xml->addChild( 'error' );
 				$xml_error->addChild( 'id', '#databasefile' );
 
 				$xml_error->addChild( 'message', _t('Cannot write to %s. The SQLite data file is not writable by the web server.', array($db_file) ) );
-			} else {
+			}
+			else {
 				// Can we connect to the DB?
 				$pdo = 'sqlite:' . $db_file;
 				$connect = DB::connect( $pdo, null, null );
@@ -1759,7 +1762,7 @@
 					unlink($db_file);
 				}
 
-				switch ($connect) {
+				switch ( $connect ) {
 					case true:
 						// We were able to connect to an existing database file.
 						$xml->addChild( 'status', 1 );
@@ -1780,7 +1783,7 @@
 		header("Cache-Control: no-cache");
 		print $xml;
 	}
-	
+
 	/**
 	 * Sets up install handler variables from an existing DB connection (registry)
 	 *
@@ -1789,7 +1792,7 @@
 	private function set_handler_vars_from_db_connection()
 	{
 		list( $this->handler_vars['db_type'], $remainder )= explode( ':', Config::get( 'db_connection' )->connection_string );
-		switch( $this->handler_vars['db_type'] ) {
+		switch ( $this->handler_vars['db_type'] ) {
 		case 'sqlite':
 			// SQLite uses less info.
 			// we stick the path in db_host

Modified: trunk/htdocs/system/classes/posts.php (3883 => 3884)


--- trunk/htdocs/system/classes/posts.php	2009-12-14 00:11:08 UTC (rev 3883)
+++ trunk/htdocs/system/classes/posts.php	2009-12-14 01:05:15 UTC (rev 3884)
@@ -36,7 +36,7 @@
 	 **/
 	public function __get( $name )
 	{
-		switch( $name ) {
+		switch ( $name ) {
 			case 'onepost':
 				return ( count( $this ) == 1 );
 		}
@@ -240,7 +240,7 @@
 
 					if ( is_array( $infos ) ) {
 						$pi_count = 0;
-						foreach($infos as $info_key => $info_value) {
+						foreach ( $infos as $info_key => $info_value ) {
 							$pi_count++;
 							$joins['info_' . $info_key] = " LEFT JOIN {postinfo} ipi{$pi_count} ON {posts}.id = ipi{$pi_count}.post_id AND ipi{$pi_count}.name = ? AND ipi{$pi_count}.value = ?";
 							$join_params[] = $info_key;
@@ -257,7 +257,7 @@
 					if ( is_array( $paramset['any:info'] ) ) {
 						$pi_count = 0;
 						$pi_where = array();
-						foreach($paramset['any:info'] as $info_key => $info_value) {
+						foreach ( $paramset['any:info'] as $info_key => $info_value ) {
 							$pi_count++;
 							$joins['any_info_' . $info_key] = " LEFT JOIN {postinfo} aipi{$pi_count} ON {posts}.id = aipi{$pi_count}.post_id AND aipi{$pi_count}.name = ? AND aipi{$pi_count}.value = ?";
 							$join_params[] = $info_key;
@@ -275,7 +275,7 @@
 					$has_info = Utils::single_array( $paramset['has:info'] );
 					$pi_count = 0;
 					$pi_where = array();
-					foreach( $has_info as $info_name ) {
+					foreach ( $has_info as $info_name ) {
 						$pi_count++;
 						$joins['has_info_' . $info_name] = " LEFT JOIN {postinfo} hipi{$pi_count} ON {posts}.id = hipi{$pi_count}.post_id AND hipi{$pi_count}.name = ?";
 						$join_params[] = $info_name;
@@ -412,7 +412,7 @@
 			}
 
 			// If a user can read any post type, let him
-			if( User::identify()->can( 'post_any', 'read' ) ) {
+			if ( User::identify()->can( 'post_any', 'read' ) ) {
 				$perm_where = array('post_any' => '(1=1)');
 				$params_where = array();
 			}
@@ -437,7 +437,7 @@
 			}
 
 			// If a user is denied access to all posts, do so
-			if( User::identify()->cannot( 'post_any' ) ) {
+			if ( User::identify()->cannot( 'post_any' ) ) {
 				$perm_where_denied = array('(1=0)');
 			}
 			else {
@@ -484,7 +484,7 @@
 		// For example: page number, fetch function, limit
 		$paramarray = new SuperGlobal($paramarray);
 		$extract = $paramarray->filter_keys('page', 'limit', 'fetch_fn', 'count', 'orderby', 'groupby', 'limit', 'offset', 'nolimit', 'having');
-		foreach($extract as $key => $value) {
+		foreach ( $extract as $key => $value ) {
 			$$key = $value;
 		}
 
@@ -527,7 +527,7 @@
 		}
 
 		// If the month counts are requested, replaced the select clause
-		if( isset( $paramset['month_cts'] ) ) {
+		if ( isset( $paramset['month_cts'] ) ) {
 			if ( isset( $paramset['tag'] ) || isset( $paramset['tag_slug'] ))
 				$select = 'MONTH(FROM_UNIXTIME(pubdate)) AS month, YEAR(FROM_UNIXTIME(pubdate)) AS year, COUNT(DISTINCT {posts}.id) AS ct';
 			else
@@ -563,12 +563,12 @@
 			$query .= ' WHERE (' . implode( " \nOR\n ", $wheres ) . ')';
 			$query .= ($master_perm_where == '') ? '' : ' AND (' . $master_perm_where . ')';
 		}
-		elseif($master_perm_where != '') {
+		elseif ( $master_perm_where != '' ) {
 			$query .= ' WHERE (' . $master_perm_where . ')';
 		}
-		$query.= ( ! isset($groupby) || $groupby == '' ) ? '' : ' GROUP BY ' . $groupby;
-		$query.= ( ! isset($having) || $having == '' ) ? '' : ' HAVING ' . $having;
-		$query.= ( ( $orderby == '' ) ? '' : ' ORDER BY ' . $orderby ) . $limit;
+		$query .= ( ! isset($groupby) || $groupby == '' ) ? '' : ' GROUP BY ' . $groupby;
+		$query .= ( ! isset($having) || $having == '' ) ? '' : ' HAVING ' . $having;
+		$query .= ( ( $orderby == '' ) ? '' : ' ORDER BY ' . $orderby ) . $limit;
 
 		/**
 		 * DEBUG: Uncomment the following line to display everything that happens in this function
@@ -635,7 +635,7 @@
 	public static function count_total( $status = FALSE )
 	{
 		$params = array( 'count' => 1 );
-		if( $status !== FALSE ) {
+		if ( $status !== FALSE ) {
 			$params['status'] = $status;
 		}
 		return self::get( $params );
@@ -706,7 +706,7 @@
 		if ( ( $user == 0 ) || empty( $posts ) ) {
 			return false;
 		}
-		switch( true ) {
+		switch ( true ) {
 			case is_integer( reset( $posts ) ):
 				break;
 			case reset( $posts ) instanceof Post:
@@ -735,7 +735,7 @@
 	public static function publish_scheduled_posts( $params )
 	{
 		$posts = DB::get_results('SELECT * FROM {posts} WHERE status = ? AND pubdate <= ? ORDER BY pubdate DESC', array( Post::status( 'scheduled' ), HabariDateTime::date_create() ), 'Post' );
-		foreach( $posts as $post ) {
+		foreach ( $posts as $post ) {
 			$post->publish();
 		}
 	}
@@ -753,7 +753,7 @@
 		$min_time = DB::get_value( 'SELECT MIN(pubdate) FROM {posts} WHERE status = ?', array( Post::status( 'scheduled' ) ) );
 
 		CronTab::delete_cronjob( 'publish_scheduled_posts' );
-		if( $min_time ) {
+		if ( $min_time ) {
 			CronTab::add_single_cron( 'publish_scheduled_posts', array( 'Posts', 'publish_scheduled_posts'),  $min_time, 'Next run: ' . HabariDateTime::date_create( $min_time )->get( 'c' ) );
 		}
 	}
@@ -859,12 +859,12 @@
 
 		$tokens = explode( ' ', $search_string );
 
-		foreach( $tokens as $token ) {
+		foreach ( $tokens as $token ) {
 			//check for triple combination
 			if ( preg_match( '/^\w+:[^:\s]*:\S+$/', $token ) ){
 				list( $keyword, $infokey, $infovalue )= explode( ':', $token );
 				$keyword = strtolower( $keyword );
-				switch($keyword){
+				switch ( $keyword ){
 					case 'info':
 						$arguments['info'][]= array($infokey=>$infovalue);
 					break;
@@ -920,7 +920,12 @@
 
 		return $arguments;
 	}
-	
+
+	/**
+	 * Check if the requested post is of the type specified, to see if a rewrite rule matches.
+	 *
+	 * @return Boolean Whether the requested post matches the content type of the rule.
+	 */
 	public static function rewrite_match_type($rule, $slug, $parameters)
 	{
 		$args = $rule->named_arg_values;
@@ -937,10 +942,10 @@
 	 */
 	function content_type ()
 	{
-		if(isset($this->preset)) {
+		if ( isset($this->preset) ) {
 			return 'posts.' . $this->preset;
 		}
 		return 'posts';
 	}
 }
-?>
\ No newline at end of file
+?>

Modified: trunk/htdocs/system/classes/tag.php (3883 => 3884)


--- trunk/htdocs/system/classes/tag.php	2009-12-14 00:11:08 UTC (rev 3883)
+++ trunk/htdocs/system/classes/tag.php	2009-12-14 01:05:15 UTC (rev 3884)
@@ -36,7 +36,7 @@
 	{
 		$term = Term::get( Tags::vocabulary()->id, $this->id );
 
-		switch ($name) {
+		switch ( $name ) {
 			case 'tag':
 			case 'tag_text':
 				$out = $term->term_display;
@@ -74,7 +74,7 @@
 	/**
 	 * Check if a tag exists, to see if we should match this rewrite rule
 	 *
-	 * @return Boolean
+	 * @return Boolean Whether the tag exists.
 	 **/
 	public static function rewrite_tag_exists($rule, $slug, $parameters)
 	{
@@ -192,7 +192,7 @@
 		$result = $term->update();
 
 		$term = Tags::vocabulary()->get_term( $this->id );
-		if( $result ) {
+		if ( $result ) {
 			$this->tag_text = $term->term_display;
 			$this->tag_slug = $term->term;
 		}
Reply all
Reply to author
Forward
0 new messages