code:
CREATE SEQUENCE {$prefix}posts_pkey_seq;
CREATE TABLE {$prefix}posts (
  id BIGINT NOT NULL DEFAULT nextval('{$prefix}posts_pkey_seq'),
  slug VARCHAR(255) NOT NULL,
  content_type INTEGER NOT NULL,
  title VARCHAR(255) NOT NULL,
  guid VARCHAR(255) NOT NULL,
  content TEXT NOT NULL,
  cached_content TEXT NOT NULL,
  user_id INTEGER NOT NULL,
  status INTEGER NOT NULL,
  pubdate INTEGER NOT NULL,
  updated INTEGER NOT NULL,
  modified INTEGER NOT NULL,
  PRIMARY KEY (id),
  UNIQUE (slug)
);

CREATE TABLE {$prefix}postinfo (
  post_id BIGINT NOT NULL,
  name VARCHAR(255) NOT NULL,
  type INTEGER NOT NULL DEFAULT 0,
  value TEXT,
  PRIMARY KEY (post_id,name)
);

CREATE SEQUENCE {$prefix}posttype_pkey_seq;
CREATE TABLE {$prefix}posttype (
  id INTEGER NOT NULL DEFAULT nextval('{$prefix}posttype_pkey_seq'),
  name VARCHAR(255) NOT NULL,
  active SMALLINT DEFAULT 1,
  PRIMARY KEY (id)
);

CREATE SEQUENCE {$prefix}poststatus_pkey_seq;
CREATE TABLE {$prefix}poststatus (
  id INTEGER NOT NULL DEFAULT nextval('{$prefix}poststatus_pkey_seq'),
  name VARCHAR(255) NOT NULL,
  internal SMALLINT,
  PRIMARY KEY (id)
);

CREATE TABLE {$prefix}options (
  name VARCHAR(255) NOT NULL,
  type INTEGER NOT NULL DEFAULT 0,
  value TEXT,
  PRIMARY KEY (name)
);

CREATE SEQUENCE {$prefix}users_pkey_seq;
CREATE TABLE {$prefix}users (
  id INTEGER NOT NULL DEFAULT nextval('{$prefix}users_pkey_seq'),
  username VARCHAR(255) NOT NULL,
  email VARCHAR(255) NOT NULL,
  password VARCHAR(255) NOT NULL,
  PRIMARY KEY (id),
  UNIQUE (username)
);

CREATE TABLE {$prefix}userinfo (
  user_id SMALLINT NOT NULL,
  name VARCHAR(255) NOT NULL,
  type INTEGER NOT NULL DEFAULT 0,
  value TEXT,
  PRIMARY KEY (user_id,name)
);

CREATE SEQUENCE {$prefix}tags_pkey_seq;
CREATE TABLE {$prefix}tags (
  id BIGINT NOT NULL DEFAULT nextval('{$prefix}tags_pkey_seq'),
  tag_text VARCHAR(255) NOT NULL,
  tag_slug VARCHAR(255) NOT NULL,
  PRIMARY KEY (id),
  UNIQUE (tag_slug)
);

CREATE TABLE {$prefix}tag2post (
  tag_id BIGINT NOT NULL,
  post_id BIGINT NOT NULL,
  PRIMARY KEY (tag_id,post_id)
);

CREATE INDEX {$prefix}tag2post_post_id_key ON {$prefix}tag2post (
  post_id
);

CREATE SEQUENCE {$prefix}comments_pkey_seq;
CREATE TABLE {$prefix}comments (
  id BIGINT NOT NULL DEFAULT nextval('{$prefix}comments_pkey_seq'),
  post_id BIGINT NOT NULL,
  name VARCHAR(255) NOT NULL,
  email VARCHAR(255) NOT NULL,
  url VARCHAR(255) NULL,
  ip BIGINT NOT NULL,
  content TEXT,
  status INTEGER NOT NULL,
  date INT NOT NULL,
  type INTEGER NOT NULL,
  PRIMARY KEY (id)
);

CREATE INDEX {$prefix}comments_post_id_key ON {$prefix}comments (
  post_id
);

CREATE TABLE {$prefix}commentinfo (
  comment_id BIGINT NOT NULL,
  name VARCHAR(255) NOT NULL,
  type INTEGER NOT NULL DEFAULT 0,
  value TEXT NULL,
  PRIMARY KEY (comment_id,name)
);

CREATE SEQUENCE {$prefix}rewrite_rules_pkey_seq;
CREATE TABLE {$prefix}rewrite_rules (
  rule_id INTEGER NOT NULL DEFAULT nextval('{$prefix}rewrite_rules_pkey_seq'),
  name VARCHAR(255) NOT NULL,
  parse_regex VARCHAR(255) NOT NULL,
  build_str VARCHAR(255) NOT NULL,
  handler VARCHAR(255) NOT NULL,
  action VARCHAR(255) NOT NULL,
  priority INTEGER NOT NULL,
  is_active INTEGER NOT NULL DEFAULT 0,
  rule_class INTEGER NOT NULL DEFAULT 0,
  description TEXT NULL,
  parameters TEXT NULL,
  PRIMARY KEY (rule_id)
);

CREATE SEQUENCE {$prefix}crontab_pkey_seq;
CREATE TABLE {$prefix}crontab (
  cron_id INTEGER NOT NULL DEFAULT nextval('{$prefix}crontab_pkey_seq'),
  name VARCHAR(255) NOT NULL,
  callback VARCHAR(255) NOT NULL,
  last_run INTEGER,
  next_run INTEGER NOT NULL,
  increment INTEGER NOT NULL,
  start_time INTEGER NOT NULL,
  end_time INTEGER,
  result VARCHAR(255) NOT NULL,
  notify VARCHAR(255) NOT NULL,
  cron_class SMALLINT NOT NULL DEFAULT 0,
  description TEXT NULL,
  PRIMARY KEY (cron_id)
);

CREATE SEQUENCE {$prefix}log_pkey_seq;
CREATE TABLE {$prefix}log (
  id BIGINT NOT NULL DEFAULT nextval('{$prefix}log_pkey_seq'),
  user_id INTEGER NULL DEFAULT NULL,
  type_id INTEGER NOT NULL,
  severity_id SMALLINT NOT NULL,
  message VARCHAR(255) NOT NULL,
  data BYTEA NULL,
  timestamp INT NOT NULL,
  ip BIGINT NOT NULL DEFAULT 0,
  PRIMARY KEY (id)
);

CREATE SEQUENCE {$prefix}log_types_pkey_seq;
CREATE TABLE {$prefix}log_types (
  id INTEGER NOT NULL DEFAULT nextval('{$prefix}log_types_pkey_seq'),
  module VARCHAR(100) NOT NULL,
  type VARCHAR(100) NOT NULL,
  PRIMARY KEY (id),
  UNIQUE (module,type)
);

CREATE SEQUENCE {$prefix}groups_pkey_seq;
CREATE TABLE {$prefix}groups (
  id INTEGER NOT NULL DEFAULT nextval('{$prefix}groups_pkey_seq'),
  name VARCHAR(255) NOT NULL,
  PRIMARY KEY (id),
  UNIQUE (name)
);

CREATE SEQUENCE {$prefix}users_groups_pkey_seq;
CREATE TABLE {$prefix}users_groups (
  id INTEGER NOT NULL DEFAULT nextval('{$prefix}users_groups_pkey_seq'),
  user_id INTEGER NOT NULL,
  group_id INTEGER NOT NULL,
  PRIMARY KEY (id),
  UNIQUE (user_id,group_id)
);

CREATE TABLE {$prefix}sessions (
  token varchar(255) NOT NULL,
  subnet INTEGER NOT NULL DEFAULT 0,
  expires BIGINT NOT NULL DEFAULT 0,
  ua VARCHAR(255) NOT NULL,
  data TEXT,
  user_id INTEGER,
  PRIMARY KEY (token)
);

CREATE SEQUENCE {$prefix}terms_pkey_seq;
CREATE TABLE {$prefix}terms (
  id INTEGER NOT NULL DEFAULT nextval('{$prefix}terms_pkey_seq'),
  term VARCHAR(255) NOT NULL,
  term_display VARCHAR(255) NOT NULL,
  vocabulary_id INTEGER NOT NULL,
  mptt_left INTEGER NOT NULL,
  mptt_right INTEGER NOT NULL,
  PRIMARY KEY (id),
  UNIQUE (vocabulary_id,mptt_right,mptt_left),
  UNIQUE (vocabulary_id,term)
);

CREATE SEQUENCE {$prefix}vocabularies_pkey_seq;
CREATE TABLE {$prefix}vocabularies (
  id INTEGER NOT NULL DEFAULT nextval('{$prefix}vocabularies_pkey_seq'),
  name VARCHAR(255) NOT NULL,
  description TEXT,
	features TEXT,
  PRIMARY KEY (id)
);

CREATE TABLE {$prefix}object_terms (
  object_id INTEGER NOT NULL,
  term_id INTEGER NOT NULL,
  object_type_id INTEGER NOT NULL,
  PRIMARY KEY (object_id, term_id)
);

CREATE SEQUENCE {$prefix}object_types_pkey_seq;
CREATE TABLE {$prefix}object_types (
  id INTEGER NOT NULL DEFAULT nextval('{$prefix}object_types_pkey_seq'),
  name VARCHAR(50),
  PRIMARY KEY (id)
);

INSERT INTO {$prefix}object_types (name) VALUES ('post');

CREATE SEQUENCE {$prefix}tokens_pkey_seq;
CREATE TABLE {$prefix}tokens (
  id INTEGER NOT NULL DEFAULT nextval('{$prefix}tokens_pkey_seq'),
  name VARCHAR(255) NOT NULL,
  description VARCHAR(255) NULL,
  token_type INT NOT NULL DEFAULT 0,
  token_group VARCHAR(255) NULL,
  PRIMARY KEY (id),
  UNIQUE (name)
);

CREATE TABLE {$prefix}post_tokens (
  post_id INTEGER NOT NULL,
  token_id INTEGER NOT NULL,
  PRIMARY KEY (post_id, token_id)
);

CREATE TABLE {$prefix}group_token_permissions (
  group_id INTEGER NOT NULL,
  token_id INTEGER NOT NULL,
  access_mask SMALLINT NOT NULL,
  PRIMARY KEY (group_id, token_id)
);

CREATE TABLE {$prefix}user_token_permissions (
  user_id INTEGER NOT NULL,
  token_id INTEGER NOT NULL,
  access_mask SMALLINT NOT NULL,
  PRIMARY KEY (user_id, token_id)
);

CREATE SEQUENCE {$prefix}scopes_pkey_seq;
CREATE TABLE {$prefix}scopes (
  id INTEGER NOT NULL DEFAULT nextval('{$prefix}scopes_pkey_seq'),
  name VARCHAR(255) NOT NULL,
  criteria TEXT NOT NULL,
  description TEXT NULL,
  priority SMALLINT NOT NULL,
  PRIMARY KEY (id)
);

CREATE SEQUENCE {$prefix}blocks_pkey_seq;
CREATE TABLE {$prefix}blocks (
  id INTEGER NOT NULL DEFAULT nextval('{$prefix}blocks_pkey_seq'),
  title VARCHAR(255) NOT NULL,
  type VARCHAR(255) NOT NULL,
  data TEXT NULL,
  PRIMARY KEY (id)
);

CREATE SEQUENCE {$prefix}blocks_areas_pkey_seq;
CREATE TABLE {$prefix}blocks_areas (
  id INTEGER NOT NULL DEFAULT nextval('{$prefix}blocks_areas_pkey_seq'),
  block_id INTEGER NOT NULL,
  area VARCHAR(255) NOT NULL,
  scope_id INTEGER NOT NULL,
  PRIMARY KEY (id),
  display_order INTEGER NOT NULL DEFAULT 0
);


code:
ALTER TABLE {$prefix}posts ALTER COLUMN pubdate TYPE INT USING EXTRACT (EPOCH FROM pubdate);
ALTER TABLE {$prefix}posts ALTER COLUMN updated TYPE INT USING EXTRACT (EPOCH FROM updated);

ALTER TABLE {$prefix}posts ADD COLUMN modified INT;
UPDATE {$prefix}posts SET modified = updated;
ALTER TABLE {$prefix}posts ALTER COLUMN modified SET NOT NULL;

ALTER TABLE {$prefix}comments ALTER COLUMN date TYPE INT USING EXTRACT (EPOCH FROM date);
ALTER TABLE {$prefix}log ALTER COLUMN timestamp TYPE INT USING EXTRACT (EPOCH FROM timestamp);

ALTER TABLE {$prefix}crontab ALTER COLUMN last_run DROP NOT NULL;
ALTER TABLE {$prefix}crontab ALTER COLUMN end_time DROP NOT NULL;

-- I have no idea why these explicit casts should be necessary, but they seem to be.
ALTER TABLE {$prefix}crontab ALTER COLUMN last_run TYPE INT USING CASE WHEN last_run = '' THEN NULL
                                                                       ELSE last_run::int
                                                                  END;
ALTER TABLE {$prefix}crontab ALTER COLUMN next_run TYPE INT USING next_run::int;
ALTER TABLE {$prefix}crontab ALTER COLUMN increment TYPE INT USING increment::int;
ALTER TABLE {$prefix}crontab ALTER COLUMN start_time TYPE INT USING start_time::int;
ALTER TABLE {$prefix}crontab ALTER COLUMN end_time TYPE INT USING CASE WHEN end_time = '' THEN NULL
                                                                       ELSE end_time::int
                                                                  END;

UPDATE {$prefix}crontab SET last_run = NULL WHERE last_run = 0;
UPDATE {$prefix}crontab SET end_time = NULL WHERE end_time = 0;

DROP TABLE {$prefix}groups_permissions;

repo_name: DaSourcerer/habari


code:
<?php
Config::set( 'db_connection', array(
	'connection_string'=>'sqlite:{$db_file}',
	'username'=>'',
	'password'=>'',
	'prefix'=>'{$table_prefix}'
));

//$locale = '{$locale}';
?>


code:
<?php
/**
 * Habari database specific connection class
 *
 * @package Habari
 */

class SQLiteConnection extends DatabaseConnection
{
	 /**
	 * database specific SQL translation function, loosely modelled on the
	 * internationalization _t()  function
	 * Call with a database independent SQL string and it will be translated
	 * to a SQLite specific SQL string
	 *
	 * @param sql database independent SQL
	 * @return  string	translated SQL string
	 */
	function sql_t( $sql )
	{
		$sql = preg_replace_callback( '%concat\(([^)]+?)\)%i', array( &$this, 'replace_concat' ), $sql );
		$sql = preg_replace( '%DATE_SUB\s*\(\s*NOW\(\s*\)\s*,\s*INTERVAL\s+([0-9]+)\s+DAY\s*\)%ims', 'date(\'now\', \'-${1} days\')', $sql );
		$sql = preg_replace( '%OPTIMIZE TABLE ([^ ]*)%i', 'VACUUM;', $sql );
		//$sql= preg_replace( '%YEAR\s*\(\s*([^ ]*)\s*\)%ims', 'strftime(\'%Y\', ${1})', $sql );
		//$sql= preg_replace( '%MONTH\s*\(\s*([^ ]*)\s*\)%ims', 'strftime(\'%m\', ${1})', $sql );
		//$sql= preg_replace( '%DAY\s*\(\s*([^ ]*)\s*\)%ims', 'strftime(\'%d\', ${1})', $sql );
		$sql = preg_replace( '%YEAR\s*\(\s*FROM_UNIXTIME\s*\(\s*([^ ]*)\s*\)\s*\)%ims', 'strftime(\'%Y\', ${1}, \'unixepoch\')', $sql );
		$sql = preg_replace( '%MONTH\s*\(\s*FROM_UNIXTIME\s*\(\s*([^ ]*)\s*\)\s*\)%ims', 'strftime(\'%m\', ${1}, \'unixepoch\')', $sql );
		$sql = preg_replace( '%DAY\s*\(\s*FROM_UNIXTIME\s*\(\s*([^ ]*)\s*\)\s*\)%ims', 'strftime(\'%d\', ${1}, \'unixepoch\')', $sql );
		$sql = preg_replace( '%TRUNCATE \s*([^ ]*)%i', 'DELETE FROM ${1}', $sql );
		$sql = preg_replace( '%RAND\s*\(\s*\)%i', 'RANDOM()', $sql );
		return $sql;
	}

	/**
	 * Replaces the MySQL CONCAT function with SQLite-compatible statements
	 * @todo needs work, kind of sucky conversion
	 * @param array $matches Matches from the regex in sql_t()
	 * @return string The replacement for the MySQL SQL
	 * @see SQLiteConnection::sql_t()
	 */
	function replace_concat( $matches )
	{
		$innards = explode( ',', $matches[1] );
		return implode( ' || ', $innards );
	}

	/**
	 * Connect to SQLite
	 * Overrides the DatabaseConnection to return false if the SQLite file doesn't exist.
	 *
	 * @param connection_string string a PDO connection string
	 * @param db_user string the database user name
	 * @param db_pass string the database user password
	 * @return boolean True if connection succeeded, false if not.
	 */
	public function connect( $connect_string, $db_user, $db_pass )
	{
		list( $type, $file )= explode( ':', $connect_string, 2 );
		if ( $file == basename( $file ) ) {
			if ( file_exists( HABARI_PATH . '/' . $file ) ) {
				$file = HABARI_PATH . '/' . $file;
			}
			else {
				$file = HABARI_PATH . '/' . Site::get_path( 'user', TRUE ) . $file;
			}
			$connect_string = implode( ':', array( $type, $file ) );
		}
		if ( file_exists( $file ) && !is_writable( $file ) ) {
			die( _t( 'Database file "%s" must be writable.', array($file) ) );
		}
		$conn = parent::connect( $connect_string, $db_user, $db_pass );
		$this->exec( 'PRAGMA synchronous = OFF' );
		return $conn;
	}

		/**
	 * automatic diffing function - used for determining required database upgrades
	 * based on Owen Winkler's microwiki upgrade function
	 *
	 * @param queries array of create table and insert statements which constitute a fresh install
	 * @param (optional)  execute should the queries be executed against the database or just simulated. default = true
	 * @param (optional) silent silent running with no messages printed? default = true
	 * @return  string			translated SQL string
	 */
	function dbdelta( $queries, $execute = true, $silent = true, $doinserts = false )
	{
		if ( !is_array( $queries ) ) {
			$queries = explode( ';', $queries );
			if ( '' == $queries[count( $queries ) - 1] ) {
				array_pop( $queries );
			}
		}

		$cqueries = array();
		$indexqueries = array();
		$iqueries = array();
		$pqueries = array();
		$for_update = array();
		$allqueries = array();

		foreach ( $queries as $qry ) {
			if ( preg_match( "|CREATE TABLE ([^ ]*)|", $qry, $matches ) ) {
				$cqueries[strtolower( $matches[1] )] = $qry;
				$for_update[$matches[1]] = 'Created table '.$matches[1];
			}
			else if ( preg_match( "|CREATE (UNIQUE )?INDEX ([^ ]*)|", $qry, $matches ) ) {
				$indexqueries[] = $qry;
			}
			else if ( preg_match( "|INSERT INTO ([^ ]*)|", $qry, $matches ) ) {
				$iqueries[] = $qry;
			}
			else if ( preg_match( "|UPDATE ([^ ]*)|", $qry, $matches ) ) {
				$iqueries[] = $qry;
			}
			else if ( preg_match ( "|PRAGMA ([^ ]*)|", $qry, $matches ) ) {
				$pqueries[] = $qry;
			}
			else {
				// Unrecognized query type
			}
		}

		// Merge the queries into allqueries; pragmas MUST go first
		$allqueries = array_merge($pqueries);

		$tables = $this->get_column( "SELECT name FROM sqlite_master WHERE type = 'table';" );

		foreach ( $cqueries as $tablename => $query ) {
			if ( in_array( $tablename, $tables ) ) {
				$sql = $this->get_value( "SELECT sql FROM sqlite_master WHERE type = 'table' AND name='" . $tablename . "';" );
				$sql = preg_replace( '%\s+%', ' ', $sql ) . ';';
				$query = preg_replace( '%\s+%', ' ', $query );
				if ( $sql != $query ) {
					$this->query("ALTER TABLE {$tablename} RENAME TO {$tablename}__temp;");
					$this->query($query);

					$new_fields_temp = $this->get_results( "pragma table_info({$tablename});" );
					$new_fields = array();
					foreach ( $new_fields_temp as $field ) {
						$new_fields[$field->name] = $field;
					}
					$old_fields = $this->get_results( "pragma table_info({$tablename}__temp);" );
					$new_field_names = array_map(array($this, 'filter_fieldnames'), $new_fields);
					$old_field_names = array_map(array($this, 'filter_fieldnames'), $old_fields);
					$used_field_names = array_intersect($new_field_names, $old_field_names);
					$used_field_names = implode(',', $used_field_names);
					$needed_fields = array_diff($new_field_names, $old_field_names);
					foreach ( $needed_fields as $needed_field_name ) {
						$used_field_names .= ",'" . $new_fields[$needed_field_name]->dflt_value . "' as " . $needed_field_name;
					}

					$this->query("INSERT INTO {$tablename} SELECT {$used_field_names} FROM {$tablename}__temp;");
					$this->query("DROP TABLE {$tablename}__temp;");
				}
			}
			else {
				$allqueries[] = $query;
			}
		}

		// Drop all indices that we created, they'll get recreated by indexqueries below.
		// The other option would be to loop through the indices, comparing with indexqueries, and only drop the ones that have changed.
		$indices = DB::get_column( "SELECT name FROM sqlite_master WHERE type='index' AND name NOT LIKE 'sqlite_autoindex_%'" );
		foreach ( $indices as $name ) {
			DB::exec( 'DROP INDEX ' . $name );
		}

		$allqueries = array_merge( $allqueries, $indexqueries );
		if ( $doinserts ) {
			$allqueries = array_merge( $allqueries, $iqueries );
		}

		if ( $execute ) {
			DB::exec( 'PRAGMA cache_size=4000' );
			foreach ( $allqueries as $query ) {
				if ( !$this->query( $query ) ) {
					$this->get_errors();
					return false;
				}
			}
		}

		return $allqueries;
	}

	/**
	 * Execute a stored procedure
	 *
	 * @param   procedure   name of the stored procedure
	 * @param   args        arguments for the procedure
	 * @return  mixed       whatever the procedure returns...
	 * Not supported with SQLite
	 */
	public function execute_procedure( $procedure, $args = array() )
	{
		die( _t( 'not yet supported on SQLite' ) );
	}

	/**
	 * Run all of the upgrades slated for pre-dbdelta since the last database revision.
	 *
	 * @param integer $old_version The current version of the database that is being upgraded
	 * @return boolean True on success
	 */
	public function upgrade_pre( $old_version, $upgrade_path = '' )
	{
		return parent::upgrade( $old_version, dirname(__FILE__) . '/upgrades/pre');
	}

	/**
	 * Run all of the upgrades slated for post-dbdelta since the last database revision.
	 *
	 * @param integer $old_version The current version of the database that is being upgraded
	 * @return boolean True on success
	 */
	public function upgrade_post( $old_version, $upgrade_path = '' )
	{
		return parent::upgrade( $old_version, dirname(__FILE__) . '/upgrades/post');
	}

	/**
	 * Filter out the fieldnames from whole pragma rows
	 *
	 * @param StdClass $row A row result from a SQLite PRAGMA table_info query
	 * @return string The name of the associated field
	 */
	protected function filter_fieldnames($row)
	{
		return $row->name;
	}

}
?>


code:
PRAGMA auto_vacuum = 1;

CREATE TABLE {$prefix}posts (
  id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
  slug VARCHAR(255) NOT NULL,
  content_type SMALLINTEGER NOT NULL,
  title VARCHAR(255) NOT NULL,
  guid VARCHAR(255) NOT NULL,
  content TEXT NOT NULL,
  cached_content LONGTEXT NOT NULL,
  user_id SMALLINTEGER NOT NULL,
  status SMALLINTEGER NOT NULL,
  pubdate INTEGER NOT NULL,
  updated INTEGER NOT NULL,
  modified INTEGER NOT NULL
);
CREATE UNIQUE INDEX IF NOT EXISTS slug ON {$prefix}posts(slug);

CREATE TABLE {$prefix}postinfo  (
  post_id INTEGER NOT NULL,
  name VARCHAR(255) NOT NULL,
  type SMALLINTEGER NOT NULL DEFAULT 0,
  value TEXT,
  PRIMARY KEY (post_id, name)
);

CREATE TABLE {$prefix}posttype (
  id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
  name VARCHAR(255) NOT NULL,
  active TINYINT(1) DEFAULT 1
);

CREATE TABLE {$prefix}poststatus (
  id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
  name VARCHAR(255) NOT NULL,
  internal TINYINT(1)
);

CREATE TABLE {$prefix}options (
  name VARCHAR(255) NOT NULL,
  type SMALLINTEGER NOT NULL DEFAULT 0,
  value TEXT,
  PRIMARY KEY (name)
);

CREATE TABLE {$prefix}users (
  id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
  username VARCHAR(255) NOT NULL,
  email VARCHAR(255) NOT NULL,
  password VARCHAR(255) NOT NULL
);
CREATE UNIQUE INDEX IF NOT EXISTS username ON {$prefix}users(username);

CREATE TABLE {$prefix}userinfo (
  user_id SMALLINTEGER NOT NULL,
  name VARCHAR(255) NOT NULL,
  type SMALLINTEGER NOT NULL DEFAULT 0,
  value TEXT,
  PRIMARY KEY (user_id, name)
);

CREATE TABLE {$prefix}tags (
  id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
  tag_text VARCHAR(255) NOT NULL,
  tag_slug VARCHAR(255) NOT NULL
);
CREATE UNIQUE INDEX IF NOT EXISTS tag_slug ON {$prefix}tags(tag_slug);

CREATE TABLE {$prefix}tag2post (
  tag_id INTEGER NOT NULL,
  post_id INTEGER NOT NULL,
  PRIMARY KEY (tag_id, post_id)
);
CREATE INDEX IF NOT EXISTS tag2post_post_id ON {$prefix}tag2post(post_id);

CREATE TABLE {$prefix}comments (
  id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
  post_id INTEGER NOT NULL,
  name VARCHAR(255) NOT NULL,
  email VARCHAR(255) NOT NULL,
  url VARCHAR(255) NULL,
  ip INTEGER NOT NULL,
  content TEXT,
  status SMALLINTEGER NOT NULL,
  date INTEGER NOT NULL,
  type SMALLINTEGER NOT NULL
);
CREATE INDEX IF NOT EXISTS comments_post_id ON {$prefix}comments(post_id);

CREATE TABLE {$prefix}commentinfo (
  comment_id INTEGER NOT NULL,
  name VARCHAR(255) NOT NULL,
  type SMALLINTEGER NOT NULL DEFAULT 0,
  value TEXT NULL,
  PRIMARY KEY (comment_id, name)
);

CREATE TABLE {$prefix}rewrite_rules (
  rule_id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
  name VARCHAR(255) NOT NULL,
  parse_regex VARCHAR(255) NOT NULL,
  build_str VARCHAR(255) NOT NULL,
  handler VARCHAR(255) NOT NULL,
  action VARCHAR(255) NOT NULL,
  priority SMALLINTEGER NOT NULL,
  is_active SMALLINTEGER NOT NULL DEFAULT 0,
  rule_class SMALLINTEGER NOT NULL DEFAULT 0,
  description TEXT NULL,
  parameters TEXT NULL
);

CREATE TABLE {$prefix}crontab (
  cron_id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
  name VARCHAR(255) NOT NULL,
  callback VARCHAR(255) NOT NULL,
  last_run INTEGER,
  next_run INTEGER NOT NULL,
  increment INTEGER NOT NULL,
  start_time INTEGER NOT NULL,
  end_time INTEGER,
  result VARCHAR(255) NOT NULL,
  notify VARCHAR(255) NOT NULL,
  cron_class TINYINTEGER NOT NULL DEFAULT 0,
  description TEXT NULL
);

CREATE TABLE {$prefix}log (
  id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
  user_id INTEGER NULL DEFAULT NULL,
  type_id INTEGER NOT NULL,
  severity_id TINYINT NOT NULL,
  message VARCHAR(255) NOT NULL,
  data BLOB NULL,
  timestamp INTEGER NOT NULL,
  ip INTEGER NOT NULL
);

CREATE TABLE {$prefix}log_types (
  id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
  module VARCHAR(100) NOT NULL,
  type VARCHAR(100) NOT NULL
);
CREATE UNIQUE INDEX IF NOT EXISTS module_type ON {$prefix}log_types(module, type);

CREATE TABLE {$prefix}groups (
  id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
  name VARCHAR(255) NOT NULL
);
CREATE UNIQUE INDEX IF NOT EXISTS group_name ON {$prefix}groups(name);

CREATE TABLE {$prefix}users_groups (
  id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
  user_id INTEGER NOT NULL,
  group_id INTEGER NOT NULL
);
CREATE UNIQUE INDEX IF NOT EXISTS user_group ON {$prefix}users_groups(user_id,group_id);

CREATE TABLE {$prefix}sessions  (
  token VARCHAR(255) NOT NULL,
  subnet INTEGER NOT NULL,
  expires INTEGER NOT NULL,
  ua VARCHAR(255) NOT NULL,
  user_id INTEGER,
  data TEXT
);
CREATE UNIQUE INDEX IF NOT EXISTS token_key ON {$prefix}sessions(token);

CREATE TABLE {$prefix}terms (
  id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
  term VARCHAR(255) NOT NULL,
  term_display VARCHAR(255) NOT NULL,
  vocabulary_id INTEGER NOT NULL,
  mptt_left INTEGER NOT NULL,
  mptt_right INTEGER NOT NULL
);
CREATE UNIQUE INDEX IF NOT EXISTS ix_mptt ON {$prefix}terms(vocabulary_id, mptt_right, mptt_left);
CREATE UNIQUE INDEX IF NOT EXISTS ix_term ON {$prefix}terms(vocabulary_id, term);

CREATE TABLE {$prefix}vocabularies (
  id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
  name VARCHAR(255) NOT NULL,
  description TEXT,
	features TEXT
);

CREATE TABLE {$prefix}object_terms (
  object_id INTEGER NOT NULL,
  term_id INTEGER NOT NULL,
  object_type_id INTEGER NOT NULL,
  PRIMARY KEY (object_id,term_id)
);

CREATE TABLE {$prefix}object_types (
  id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
  name VARCHAR(50)
);

INSERT INTO {$prefix}object_types (name) VALUES
  ('post');

CREATE TABLE {$prefix}tokens (
  id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
  name VARCHAR(255) NOT NULL,
  description VARCHAR(255) NULL,
  token_type INT UNSIGNED NOT NULL DEFAULT 0,
  token_group VARCHAR(255) NULL
);
CREATE UNIQUE INDEX IF NOT EXISTS name ON {$prefix}tokens(name);

CREATE TABLE {$prefix}post_tokens (
  post_id INTEGER NOT NULL,
  token_id INTEGER NOT NULL,
  PRIMARY KEY (post_id, token_id)
);

CREATE TABLE {$prefix}group_token_permissions (
  group_id INTEGER NOT NULL,
  token_id INTEGER NOT NULL,
  access_mask TINYINT UNSIGNED NOT NULL,
  PRIMARY KEY (group_id, token_id)
);
CREATE UNIQUE INDEX IF NOT EXISTS group_permission ON {$prefix}group_token_permissions(group_id,token_id);

CREATE TABLE {$prefix}user_token_permissions (
  user_id INTEGER NOT NULL,
  token_id INTEGER NOT NULL,
  access_mask TINYINT UNSIGNED NOT NULL,
  PRIMARY KEY (user_id, token_id)
);

CREATE TABLE {$prefix}scopes (
  id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
  name VARCHAR(255) NOT NULL,
  criteria TEXT NOT NULL,
	description TEXT NULL,
	priority TINYINT UNSIGNED NOT NULL
);
CREATE UNIQUE INDEX IF NOT EXISTS id ON {$prefix}group_token_permissions(group_id,token_id);

CREATE TABLE {$prefix}blocks (
  id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
  title VARCHAR(255) NOT NULL,
  type VARCHAR(255) NOT NULL,
  data TEXT NULL
);

CREATE TABLE {$prefix}blocks_areas (
  id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
  block_id INTEGER NOT NULL,
  area VARCHAR(255) NOT NULL,
  scope_id INTEGER NOT NULL,
	display_order INTEGER NOT NULL DEFAULT 0
);


code:
ALTER TABLE {$prefix}posts ADD modified INT UNSIGNED NOT NULL DEFAULT (0);
UPDATE {$prefix}posts SET pubdate = strftime( '%s', pubdate );
UPDATE {$prefix}posts SET updated = strftime( '%s', updated );
UPDATE {$prefix}posts SET modified = updated;

UPDATE {$prefix}comments SET date = strftime( '%s', date );
UPDATE {$prefix}crontab SET last_run = NULL WHERE last_run = 0;
UPDATE {$prefix}crontab SET end_time = NULL WHERE end_time = 0;
ALTER TABLE {$prefix}rewrite_rules ADD parameters TEXT NULL;
DROP TABLE {$prefix}groups_permissions;


code:
<?php include 'header.php'; ?>

<?php _e( "Whoops! 404" ); ?>

<?php _e( "The page you were trying to access is not really there. Please try again." ); ?>

			<?php include'sidebar.php' ?>

			<?php $theme->display_archives() ;?>

<?php include 'footer.php'; ?>


code:
<?php if ( !$post->info->comments_disabled ) : ?>

<?php 	if ( Session::has_messages() ) Session::messages_out(); ?>
<?php 	$post->comment_form()->out(); ?>

<?php	else: ?>

<?php _e( "Comments are closed for this post" ); ?>

<?php 	endif; ?>


code:
<?php if ( !$post->info->comments_disabled || $post->comments->moderated->count ) :?>

			<?php if ( $post->comments->moderated->count ) : ?>
				<?php foreach ( $post->comments->moderated as $comment ) : ?>

				<div id="comment-<?php echo $comment->id; ?>" class="post-comment">

							<a href="<?php echo $comment->url; ?>" rel="external"><?php echo $comment->name; ?>

						<?php echo $comment->content_out; ?>

<a href="#comment-<?php echo $comment->id; ?>" title="<?php _e( 'Time of this comment - Click for comment permalink' ); ?>"><?php $comment->date->out(); ?>

						<?php if ( $comment->status == Comment::STATUS_UNAPPROVED ) : ?>

<?php _e( 'Your comment is awaiting moderation' ) ;?>

						<?php endif; ?>

				<?php endforeach; ?>
			<?php else : ?>

<?php _e( 'Be the first to write a comment!' ); ?>

			<?php endif; ?>

		<?php endif; ?>


code:
<?php include 'header.php'; ?>

			<?php if ($show_post_nav) : ?>

				<?php if ( $previous = $post->descend() ): ?>

 « <a href="<?php echo $previous->permalink ?>" title="<?php echo $previous->slug ?>"><?php echo $previous->title ?>

				<?php endif; ?>
				<?php if ( $next = $post->ascend() ): ?>

<a href="<?php echo $next->permalink ?>" title="<?php echo $next->slug ?>"><?php echo $next->title ?> »

				<?php endif; ?>

			<?php endif; ?>
				<div class="<?php echo $post_class?>">
				<?php if ( is_array($post->tags) ) : ?>

						<?php echo $post->tags_out;?>

				<?php endif; ?>

							<a href="<?php echo $post->permalink; ?>" title="<?php echo $post->title; ?>"><?php echo $post->title_out; ?>

						<?php $post->pubdate->out(); ?>

							<a href="<?php echo $post->permalink.'#comment-form'; ?>" title="<?php _e( "Comments on this post" ); ?>"><?php $theme->post_comments_link( $post, _t('No Comments'), _t('Comment'), _t('Comments') ); ?>

						<?php echo $post->content_out; ?>

					<?php if ( $loggedin ) : ?>

							<a href="<?php echo $post->editlink; ?>" title="<?php _e( "Edit post" ); ?>"><?php _e( "Edit" ); ?>

					<?php endif; ?>

			<?php include'sidebar.php' ?>

		<?php include 'comments.php'; ?>

		<?php include 'commentform.php'; ?>

<?php include 'footer.php'; ?>


code:
<?php if (Plugins::is_loaded('tagcloud')) $theme->tag_cloud(); else $theme->show_tags();?>

			<?php printf( _t('%1$s is powered by %2$s'), Options::get('title'),' Habari ' . Version::HABARI_VERSION  . '' ); ?> -
			<a href="<?php URL::out( 'atom_feed', array( 'index' => '1' ) ); ?>"><?php _e( 'Atom Entries' ); ?><?php _e( ' and ' ); ?>
			<a href="<?php URL::out( 'atom_feed_comments' ); ?>"><?php _e( 'Atom Comments' ); ?>

<?php $theme->footer(); ?>


code:
<div<?php echo isset( $class ) ? " class=\"$class\"" : ''; ?><?php echo isset( $id ) ? " id=\"$id\"" : ''; ?>>
	<input<?php if ( isset( $control_title ) ) { ?> title="<?php echo $control_title; ?>"<?php } else { echo ( isset( $title ) ? " title=\"$title\"" : '' ); } if ( isset( $tabindex ) ) { ?> tabindex="<?php echo $tabindex; ?>"<?php } ?> size="30" type="text" id="<?php echo $field; ?>" name="<?php echo $field; ?>" value="<?php echo Utils::htmlspecialchars( $value ); ?>">
	<label<?php if ( isset( $label_title ) ) { ?> title="<?php echo $label_title; ?>"<?php } else { echo ( isset( $title ) ? " title=\"$title\"" : '' ); } ?> for="<?php echo $field; ?>"><?php echo $this->caption; ?>
	<?php $control->errors_out( '
%s
', '
%s
' ); ?>


code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

	<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
	<title><?php Options::out( 'title' ) ?><?php if($request->display_entry && isset($post)) { echo " :: {$post->title}"; } ?></title>
	<meta name="generator" content="Habari">
	<link rel="alternate" type="application/atom+xml" title="Atom 1.0" href="<?php $theme->feed_alternate(); ?>">
	<link rel="edit" type="application/atom+xml" title="Atom Publishing Protocol" href="<?php URL::out( 'atompub_servicedocument' ); ?>">
	<link rel="EditURI" type="application/rsd+xml" title="RSD" href="<?php URL::out( 'rsd' ); ?>">
	<link rel="stylesheet" type="text/css" media="screen" href="<?php Site::out_url( 'theme' ); ?>/style.css">
	<?php if ($localized_css): ?>
	<link rel="stylesheet" type="text/css" media="screen" href="<?php echo Site::get_url( 'theme', true ) . $localized_css; ?>">
	<?php endif; ?>

	<?php $theme->header(); ?>

<body class="<?php $theme->body_class(); ?>">

					<?php if ( $show_title_image ) : ?>

<a href="<?php Site::out_url( 'habari' ); ?>"><img src="<?php Site::out_url( 'theme' ); ?>/images/sample-title.png" alt="<?php Options::out( 'title' ); ?>" ><?php Options::out( 'title' ); ?>

					<?php else : ?>

<a href="<?php Site::out_url( 'habari' ); ?>"><?php Options::out( 'title' ); ?>

					<?php endif; ?>

<?php Options::out( 'tagline' ); ?>

							<li<?php if ($post_id == 0) echo ' class="current-page"'; ?>>
								<a href="<?php Site::out_url( 'habari' ); ?>"><?php echo $home_label; ?>

						<?php foreach ( $pages as $pagelink ) : ?>
							<li<?php if ($pagelink->id == $post_id) echo ' class="current-page"'; ?>>
								<a href="<?php echo $pagelink->permalink; ?>" title="<?php echo $pagelink->title; ?>"><?php echo $pagelink->title; ?>

						<?php endforeach; ?>
						<?php if ($display_login): ?>

							<?php if ( $loggedin ) : ?>
								<a href="<?php Site::out_url( 'admin' ); ?>" title="<?php _e( "Admin area" ); ?>"><?php _e( "Admin" ); ?>
							<?php else: ?>
								<a href="<?php Site::out_url( 'login' ); ?>" title="<?php _e( "Login" ); ?>"><?php _e( "Login" ); ?>

							<?php endif; ?>
						<?php endif; ?>


code:
<?php include 'header.php'; ?>

            <?php $posts = (array) $posts; ?>
			<?php if ( sizeof( $posts ) ): ?>
				<?php $post =reset($posts); ?>
				<div class="<?php echo $post_class?>">
				<?php if ( is_array( $post->tags ) ) : ?>

						<?php echo $post->tags_out;?>

				<?php endif; ?>

							<a href="<?php echo $post->permalink; ?>"title="<?php echo $post->title; ?>"><?php echo $post->title_out; ?>

							<?php $post->pubdate->out(); ?>

							<a href="<?php echo $post->permalink.'#comment-form'; ?>" title="<?php _e( "Comments on this post" ); ?>"><?php $theme->post_comments_link( $post, _t('No Comments'), _t('Comment'), _t('Comments') ); ?>

						<?php echo $post->content_out; ?>

						<?php if ( $loggedin ) : ?>

								<a href="<?php echo $post->editlink; ?>" title="<?php _e( "Edit post" ); ?>"><?php _e( "Edit" ); ?>

						<?php endif; ?>

			<?php else: ?>

<?php _e( "No posts published, yet." ); ?>

			<?php endif; ?>

			<?php include'sidebar.php' ?>

			<?php while($post =next($posts)) : ?>

							<a href="<?php echo $post->permalink; ?>" title="<?php echo $post->title; ?>"><?php echo $post->title_out; ?>

							<?php echo $post->content_excerpt; ?>
							<a href="<?php echo $post->permalink; ?>" title="<?php printf( _t("Continue reading %s"), $post->title ); ?>"><img src="<?php Site::out_url( 'theme' ); ?>/images/arrow.png" alt="<?php _e( "more" ); ?>">

			<?php endwhile; ?>

				<?php $theme->prev_page_link( _t('Newer Posts') ); ?>
				<?php $theme->next_page_link( _t('Older Posts') ); ?>

			<?php //$theme->prevnext($page, Utils::archive_pages($posts->count_all())); ?>
			<?php $theme->display_archives() ;?>

<?php include 'footer.php'; ?>


code:
.post {
	height: 153px;
}

#top-primary {
	margin-right: -300px;
	clear: right;
}

#top-secondary {
	height: 266px;
	clear: left;
}

#sidebar {
	height: 300px;
}

.post-sup {
	height: 30px
}

.post-comments-link a {
	margin-top: 0;
	padding-top: 0;
}

#prev-posts {
	height: 233px;
}

.prev-post-excerpt p a img {
	display: none;
}

#prev-posts-footer .nav-prev {
	background: none;
}

#prev-posts-footer .nav-prev a {
	margin: 0;
}

#prev-posts-footer img {
	display: inline;
}

#prev-posts-footer .nav-next {
	background: none;
}

#prev-posts-footer .nav-next a {
	margin: 0;
}

#archives {
	height: 147px;
}

#post-comments {
	height: 180px;
}

#comment-form {
	height: 180px;
	padding-right: 0px;
}

#tags {
	height: 160px;
}

#bottom-secondary {
	position: relative;
	right: 0px;
	height: 250px;
	overflow: auto;
}

.post-comments-link {
	padding-top: 3px;
}

#feeds {
	border: none;
	cursor: pointer;
}

.feedlink {
	border: none;
}

.feedlink a {
	border: none;
	width: 156px;
}

#feeds a:hover {
	padding-bottom: 0px;
	cursor: pointer;
}

#habari-link {
	margin-top: 0;
}

#navbar {
	width: 930px;
	margin-top: 20px;
}

.archlist-left {
	margin: 0;
}

.archlist-right {
	margin: 0;
}

#title {
	margin-bottom: 10px;
}

#footer {
	margin-left: 65px;
}


code:
<?php include 'header.php'; ?>

			<?php foreach ($posts as $post): ?>

				<?php if ( is_array( $post->tags ) && ($tags_in_multiple) ) : ?>

						<?php echo $post->tags_out;?>

				<?php endif; ?>

							<a href="<?php echo $post->permalink; ?>" title="<?php echo $post->title; ?>"><?php echo $post->title_out; ?>

						<?php $post->pubdate->out(); ?>

							<a href="<?php echo $post->permalink.'#comment-form'; ?>" title="<?php _e( "Comments on this post" ); ?>"><?php $theme->post_comments_link( $post, _t('No Comments'), _t('Comment'), _t('Comments') ); ?>

						<?php echo $post->content_excerpt; ?>

		<?php endforeach; ?>

		<?php include'sidebar.php' ?>

				<?php $theme->prev_page_link( _t('Newer Posts') ); ?><img class="hidden" src="<?php Site::out_url('theme'); ?>/images/nav-right.png" alt="">
				<img class="hidden" src="<?php Site::out_url('theme'); ?>/images/nav-left.png" alt=""><?php $theme->next_page_link( _t('Older Posts') ); ?>

			<?php $theme->display_archives() ;?>

<?php include 'footer.php'; ?>


code:
<?php include 'header.php'; ?>

				<div class="<?php echo $page_class?>">
				<?php if ( is_array( $post->tags ) && !empty($post->tags) ) : ?>

						<?php echo $post->tags_out;?>

				<?php endif ?>

							<a href="<?php echo $post->permalink; ?>" title="<?php echo $post->title; ?>"><?php echo $post->title_out; ?>

						<?php echo $post->content_out; ?>

					<?php if ( $loggedin ) : ?>

						<a href="<?php echo $post->editlink; ?>" title="<?php _e( "Edit post" ); ?>"><?php _e( "Edit" ); ?>

					<?php endif;?>

			<?php include'sidebar.php' ?>

		<?php include 'comments.php'; ?>

		<?php include 'commentform.php'; ?>

<?php include 'footer.php'; ?>


code:
$(document).ready(function() {
	$(".post, blockquote, .post-tags, #prev-posts, #archives, #tags, .post-date, .post-comments-link a, #prev-posts-footer img, #search-btn, .feedlink a, #post-comments, #comment-form, img[@src$=pwrd_habari.png]").pngfix({sizingMethod: "crop"});
});


code:
/**
 * jQuery (PNG Fix) v1.2
 * Microsoft Internet Explorer 24bit PNG Fix
 *
 * The MIT License
 *
 * Copyright (c) 2007 Paul Campbell (pauljamescampbell.co.uk)
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 *
 * @param		Object
 * @return		Array
 */
(function($) {

	$.fn.pngfix = function(options) {

		// Review the Microsoft IE developer library for AlphaImageLoader reference
		// http://msdn2.microsoft.com/en-us/library/ms532969(VS.85).aspx

		// ECMA scope fix
		var elements 	= this;
		var settings 	= $.extend({
			imageFixSrc: 	false,
			sizingMethod: 	false
		}, options);

		if(!$.browser.msie || ($.browser.msie &&  $.browser.version >= 7)) {
			return(elements);
		}

		function setFilter(el, path, mode) {
			var fs = el.attr("filters");
			var alpha = "DXImageTransform.Microsoft.AlphaImageLoader";
			if (fs[alpha]) {
				fs[alpha].enabled = true;
				fs[alpha].src = path;
				fs[alpha].sizingMethod = mode;
			} else {
				el.css("filter", 'progid:' + alpha + '(enabled="true", sizingMethod="' + mode + '", src="' + path + '")');
			}
		}

		function setDOMElementWidth(el) {
			if(el.css("width") == "auto" & el.css("height") == "auto") {
				el.css("width", el.attr("offsetWidth") + "px");
			}
		}

		return(
			elements.each(function() {

				// Scope
				var el = $(this);

				if(el.attr("tagName").toUpperCase() == "IMG" && (/\.png/i).test(el.attr("src"))) {
					if(!settings.imageFixSrc) {

						// Wrap the  in a  then apply style/filters,
						// removing the  tag from the final render
						el.wrap("");
						var par = el.parent();
						par.css({
							height: 	el.height(),
							width: 		el.width(),
							display: 	"inline-block"
						});
						setFilter(par, el.attr("src"), "scale");
						el.remove();
					} else if((/\.gif/i).test(settings.imageFixSrc)) {

						// Replace the current image with a transparent GIF
						// and apply the filter to the background of the
						//  tag (not the preferred route)
						setDOMElementWidth(el);
						setFilter(el, el.attr("src"), "image");
						el.attr("src", settings.imageFixSrc);
					}

				} else {
					var bg = new String(el.css("backgroundImage"));
					var matches = bg.match(/^url\("(.*)"\)$/);
					if(matches && matches.length) {

						// Elements with a PNG as a backgroundImage have the
						// filter applied with a sizing method relevant to the
						// background repeat type
						setDOMElementWidth(el);
						el.css("backgroundImage", "none");

						// Restrict scaling methods to valid MSDN defintions (or one custom)
						var sc = "crop";
						if(settings.sizingMethod) {
							sc = settings.sizingMethod;
						}
						setFilter(el, matches[1], sc);

						// Fix IE peek-a-boo bug for internal links
						// within that DOM element
						el.find("a").each(function() {
							$(this).css("position", "relative");
						});
					}
				}

			})
		);
	}

})(jQuery)


code:
<?php include 'header.php'; ?>

		<?php if (isset($post)) : ?>

<?php $theme->search_prompt( Utils::htmlspecialchars( $criteria ), true ); ?>

			<?php foreach ($posts as $post): ?>

				<?php if ( is_array( $post->tags ) && ($tags_in_multiple) ) : ?>

						<?php echo $post->tags_out;?>

				<?php endif; ?>

							<a href="<?php echo $post->permalink; ?>" title="<?php echo $post->title; ?>"><?php echo $post->title_out; ?>

						<?php $post->pubdate->out(); ?>

							<a href="<?php echo $post->permalink.'#comment-form'; ?>" title="<?php _e( "Comments on this post" ); ?>"><?php $theme->post_comments_link( $post, _t('No Comments'), _t('Comment'), _t('Comments') ); ?>

						<?php echo $post->content_excerpt; ?>

			<?php endforeach; ?>

		<?php else: ?>

<?php $theme->search_prompt( Utils::htmlspecialchars( $criteria ), false ); ?>

		<?php endif; ?>

			<?php include'sidebar.php' ?>

				<?php $theme->prev_page_link( _t('Newer Posts') ); ?>
				<?php $theme->next_page_link( _t('Older Posts') ); ?>

			<?php $theme->display_archives() ;?>

<?php include 'footer.php'; ?>


code:
<form method="get" id="search-form" action="<?php URL::out('display_search'); ?>">
	<input type="text" name="criteria" id="search-box" value="<?php if ( isset( $criteria ) ) { echo htmlentities($criteria, ENT_COMPAT, 'UTF-8');} else { printf( _t("Search %s"), Options::get("title")) ;}  ?>" onfocus="if (this.value == '<?php printf( _t("Search %s"), str_replace("'", "\'", Options::get("title")) ); ?>') {this.value = '';}" onblur="if (this.value == '') {this.value = '<?php printf( _t("Search %s"), str_replace("'", "\'", Options::get("title")) ); ?>';}" >
	<input type="submit" id="search-btn" value="" title="<?php _e( "Go" ); ?>">
</form>


code:
	<?php $theme->search_form() ?>

<a href="<?php URL::out( 'atom_feed', array( 'index' => '1' ) ); ?>"><?php _e( "{blog entries}" ); ?>

<a href="<?php URL::out( 'atom_feed_comments' ); ?>"><?php _e( "{comments}" ); ?>

<?php if ($show_powered) : ?>
	<a href="http://habariproject.org/" title="<?php _e( "Powered by Habari" ); ?>"><img src="<?php Site::out_url('theme'); ?>/images/pwrd_habari.png" alt="<?php _e( "Powered by Habari" ); ?>">
<?php  endif; ?>

<?php $theme->area('sidebar'); ?>


code:
/* Default Elements */
body {
	margin: 0;
	font-family: 'myriad pro', helvetica, arial, sans-serif;
	font-weight: normal;
	color: #333333;
	font-size: 14px;
	background-color: #ffffff;
}

a {
	color: #535353;
	text-decoration: none;
	border-bottom: #535353 1px dotted;
}

a:hover {
	background-color: #dadada;
}

h1 {
	font-weight: bold;
	font-size: 3.8em;
	color: #e5e5e5;
	margin: 0;
	line-height: 120%;
	color: #f9f9f9;
}

h1 a {
	color: #f9f9f9;
	border: none;
}

h1 a:hover {
	color: #f9f9f9;
	border: none;
	background: none;
}

h3 {
	font-weight: bold;
	font-size: 2.4em;
	color: #3f3f3e;
	margin: 0;
	line-height: 120%;
}

h3 a {
	color: #3f3f3e;
	margin: 0;
	border: none;
}

h3 a:hover {
	background: none;
	color: #5f5f5f
}

h2 {
	font-weight: bold;
	font-size: 1.7em;
	color: #f9f9f9;
	margin: 0;
	line-height: 120%
}

h2 a {
	color: #f9f9f9;
	margin: 0;
	line-height: 120%;
	border: none;
}

h2 a:hover {
	background: none;
	color: #dadadb;
}

h4 {
	margin-bottom: 5px;
}

p {
	margin: 0 0 10px;
	line-height: 130%;
}

/* The upper part of the page */
#page-top {
	position: relative;
	background: url("images/main_bg.png") top repeat-x;
}

#wrapper-top {
	position: relative;
	width: 972px;
	margin: 0 auto;
	padding-bottom: 30px;
}

#top-primary {
	width: 657px;
	float: left;
}

#header {
	width: 930px;
	min-height: 160px;
}

#title {
	width: 610px;
	height: 100px;
	margin-top: 35px;
	margin-left: 50px;
	margin-bottom: 25px;
	position: relative;
}

#title img {
	border: none;
}

#title a,#title a:hover {
	text-decoration: none;
	border: none;
	background: none;
}

.tagline,.tagline p {
	margin-left: 50px;
	font-size: 1.4em;
	margin-top: 0;
	color: #f9f9f9;
}

#navbar {
	min-width: 650px;
	overflow: visible;
	display: block;
	margin-left: 50px;
	z-index: 0;
}

#navbar ul {
	font-size: 0.9em;
	list-style: none;
	padding: 0;
	height: 48px;
	display: block;
	margin-bottom:5px;
}

#navbar ul li {
	float: left;
	display: block;
	margin-left: 1px;
	margin-right: 3px;
	overflow: hidden;
}

#navbar ul li a {
	padding: 7px 13px 20px 12px;
	text-decoration: none;
	color: #e9e9e9;
	display: block;
	font-size: 1.25em;
	font-weight: normal;
	border: none;
	display: block;
}

#navbar ul li a:hover {
	background: none;
	color: #3f3f3e;
}

#navbar ul li:hover {
	border: none;
	background: url("images/select_bg.png") top left repeat-x;
	color: #3f3f3e;
}

.current-page {
	background: url("images/select_bg.png") top left repeat-x;
}

#navbar ul li.current-page a {
	color: #3f3f3e;
	font-weight: bold;
}

#navbar ul li.login {
	margin-left: 5px;
}

li.login a {
	border: none;
}

li.login a:hover {
	Background: none !important;
}

#main-posts {
	margin:0;
	padding:0;
}
.post-nav{
	margin-top:10px;
	height:15px;
	padding-left: 57px;
}
.post-nav a{
	font-size:90%;
	border:none;
}

.post {
	min-height: 153px;
	padding-left: 100px;
	padding-top: 60px;
	background: url("images/paperclip.png") top left no-repeat;
}

.post.alt {
	background: none;
}

.post.multi {
	padding-top: 35px;
	background: none;
}

.post.multi .post-entry {
	padding-top: 5px;
	text-indent: 0;
}

.post-tags {
	display: block;
	margin-left: 2px;
	background: url("images/tags.png") left no-repeat;
	padding-left: 40px;
	word-spacing: 10px;
	font-size: 0.9em;
	color: #5a5a5a;
}

.post-tags a {
	border: none;
}

.post-tags a:hover {
	color: #5a5a5a;
}

.post-title {

}

.post-sup {
	height: 23px
}

.post-date {
	margin-left: 2px;
	font-weight: 400;
	background: url("images/dots.png") left no-repeat;
	padding-left: 17px;
	color: #5a5a5a;
	font-size: 1.03em;
	float: left;
}

.post-comments-link a {
	text-align: right;
	font-size: 1.03em;
	background: url("images/comments.png") left no-repeat;
	float: right;
	padding-left: 32px;
	margin-top: -3px;
	height: 23px;
	line-height: 150%;
	color: #5a5a5a;
	border: none;
}

.post-comments-link a:hover {
	background-color: #dadada;
}

.post-entry {
	font-size: 1.1em;
	padding-top: 15px;
	text-align: justify;
	text-indent: 2em;
}

.post-entry img {
	border: #909090 1px dashed;
	margin: 10px;
	padding: 5px;
	background-color: #f0f0f0;
}

.post-entry pre {
	overflow: auto;
	width: 100%;
	background-color: #f7f7f7;
}

.post-footer {
	height: 30px;
	text-align: right;
}

#top-secondary {
	min-height: 266px;
	width: 315px;
	background: url("images/sidebar_top.png") top center no-repeat;
	float: right;
	z-index: 1;
}

#search {
	height: 30px;
	margin: 20px 35px 15px 35px;
}

#search-form {
	margin: 0;
	padding: 0;
}

#search #search-box {
	font-size: 1.1em;
	color: #999999;
	width: 200px;
	height: 20px;
	text-align: center;
	float: left;
	margin-top: 2px;
}

#search #search-btn {
	background: url("images/search_button.png") bottom left no-repeat;
	height: 30px;
	width: 31px;
	border: none;
	margin-top: 0;
	float: right;
	display: inline;
	cursor: pointer;
}

#feeds {
	height: 92px;
	width: 203px;
	margin-left: 35px;
	margin-bottom: 5px;
}

.feedlink {
	margin-bottom: 12px;

}

.feedlink a {
	background: url("images/feed.png") center left no-repeat;
	font-size: 1.6em;
	display: block;
	padding-left: 50px;
	color: #ffffff;
	line-height: 34px;
	border: none;
}

.feedlink a:hover {
	background: url("images/feed_hover_1.png") center left no-repeat;
	color: #aaaaaa;
}

#habari-link {
	margin-top: -10px;
	margin-right: 0;
	height: 58px;
	text-align: right;
}

#habari-link a {
	border: none;
}

#habari-link a img {
	text-decoration: none;
	border: none;
}

#habari-link a:hover {
	background: none;
}

#sidebar {
	padding-left: 45px;
	padding-right: 10px;
	padding-top: 30px;
}

#sidebar div {
	margin-bottom: 25px;
}

#sidebar div h2 {
	color: #3f3f3d;
}

#sidebar div ul {
	list-style: none;
	margin-top: 10px;
	margin-left: 5px;
	padding-left: 0;
}

#sidebar div ul li {
	color: #5a5a5a;
	font-weight: 400;
	background: url("images/bullet.png") center left no-repeat;
	padding-left: 20px;
	margin-left: 0;
	margin-top: 4px;
}

/* The lower part of the page */
#page-bottom {
	margin: 0;
	padding-top: 17px;
	position: relative;
	background: #3f3f3f url("images/page_bottom_bg.png") top repeat-x;
	color: #ffffff;
}

#wrapper-bottom {
	position: relative;
	width: 972px;
	padding: 0;
	margin: 0 auto;
	background: url("images/secondary_bg.png") left repeat-y;
}

#bottom-primary {
	width: 645px;
	float: left;
}

#prev-posts {
	min-height: 233px;
	margin: 6px 0 0 auto;
	background: url("images/prevposts_text.png") top left no-repeat;
	padding-left: 120px;
	padding-right: 20px;
}

.prev-post-excerpt {
	padding-bottom: 20px;
	text-align: justify;
}

.prev-post-excerpt p {
	color: #e4e4e4
}

.prev-post-excerpt a:hover {
	background: none;
}

.prev-post-excerpt p a,.prev-post-excerpt a,.prev-post-excerpt p a img,.prev-post-excerpt a img
	{
	border: none;
}

#prev-posts-footer {
	height: 25px;
	bottom: 0;
	padding-left: 120px;
	padding-right: 20px;
	margin-bottom: 35px;
}

#prev-posts-footer a {
	color: #dad7d7;
	border-color: #dad7d7;
}

#prev-posts-footer .nav-prev {
	background: url("images/nav-left.png") top left no-repeat;
	float: left;
	height: 25px;
}

#prev-posts-footer .nav-prev a {
	text-align: left;
	margin-left: 30px;
	border: none;
}

#prev-posts-footer .nav-next {
	background: url("images/nav-right.png") top right no-repeat;
	float: right;
	height: 25px;
}

#prev-posts-footer .nav-next a {
	text-align: right;
	margin-right: 30px;
	border: none;
}

#prev-posts-footer .nav-prev a:hover,#prev-posts-footer .nav-next a:hover
	{
	color: #888888;
	border-color: #888888;
}

/* Comments section */
#post-comments {
	min-height: 180px;
	margin: 6px 0 35px auto;
	background: url("images/comments_text.png") top left no-repeat;
	padding-left: 120px;
	padding-right: 20px;
}

div.post-comments-title {
	text-align: left;
	margin-bottom: 20px;
}

.comment-message {
	font-size: .9em;
	font-weight: bold;
}

.post-comment  h2,.post-comment-u h2 {
	font-size: 1.5em;
}

.post-comment-body {
	padding-bottom: 20px;
	text-align: justify;
}

.post-comment-body p {
	color: #e4e4e4;
}

.post-comment-body p a {
	color: #e4e4e4;
	border-color: #e4e4e4;
}

#post-comments-footer {
	height: 25px;
}

#post-comments-footer a {
	color: #dad7d7;
	border-color: #dad7d7;
}

p.post-comment-link a {
	color: #dad7d7;
}

p.post-comment-link a:hover {
	background-color: #dadada;
	color: #aaa7a7
}

/* Comments form */
#comment-form {
	min-height: 177px;
	margin: 0 0 auto;
	background: url("images/postcomment_text.png") top left no-repeat;
	padding-left: 120px;
	padding-right: 20px;
}

#comment-form #comment-public input,
#comment-form #comment-public textarea {
	margin-bottom: 5px;
}

#comment-form #comment-public input {
	color: #666666;
}

#comment-form #comment-public textarea {
	color: #666666;
}

#comment-form #comment-public #submit {
	color: #111111;
}

#comments-closed {
	padding-left: 120px;
	padding-bottom: 50px;
	background:none;
}

#comments-closed p{
	text-align:center;
	font-size:1.2em;
}
/* Others */
#archives {
	min-height: 147px;
	background: url("images/archives_text.png") top left no-repeat;
	padding-left: 150px;
	padding-right: 40px;
	margin-bottom: 40px;
}

ul.archlist-left {
	float: left;
	padding: 0;
	margin: 0 -50px 0 0; /*fixing an IE7 Bug */
}

ul.archlist-right {
	float: right;
	padding: 0;
	margin: 0 0 0 -50px; /*fixing an IE7 Bug */
}

ul.archlist-left li {
	text-align: right;
	display: block;
	list-style-type: none;
}

ul.archlist-right li {
	text-align: left;
	display: block;
	list-style-type: none;
}

ul.archlist-left li a,ul.archlist-right li a {
	color: #f9f9f9;
	margin: 0;
	line-height: 140%;
	border: none;
	font-size: 1.6em;
}

ul.archlist-left li a:hover,ul.archlist-right li a:hover {
	background: none;
	color: #dadadb;
}

#bottom-secondary {
	width: 315px;
	margin-top: -17px;
	padding-top: 17px;
	background: url("images/secodary_top.png") top center no-repeat;
	float: right;
}

#tags {
	min-height: 160px;
	background: url("images/tagcloud_text.png") top left no-repeat;
	margin: 6px 0 30px 15px;
	padding-left: 40px;
	padding-right: 40px;
	padding-top: 0;
	font-size: 100%;
}

#tags ul {
	margin: 0;
	padding: 0;
	text-align: justify;
	word-spacing: 2px;

}

#tags ul li {
	display: inline;
	list-style-type: none;
	font-weight: bold;

}

#tags ul li a {
	color: #8d8d8d;
	border: none;
}

#tags ul li a:hover {
	border: none;
}

#footer {
	float: left;
	width: 520px;
	margin-left: 145px;
}

#footer a {
	color: #8d8d8d;
}

.clear {
	clear: both;
}

.hidden {
	display: none
}

.prompt {
	padding-left: 50px;
	font-size: 1.6em;
	padding-top: 20px;
	font-weight: bold;
	margin: 0;
}

.noposts{
	margin-bottom:120px;
}

input {
	border: 2px solid;
}

textarea {
	border: 2px solid;
	width: 100%;
}

blockquote {
background: url(images/blockquote.png) top left no-repeat;
margin: 10px 20px 20px 10px;
padding: 15px 0 0 70px;
text-indent: 0;
font-style: italic;
}

.left{
	float:left;
}

.right{
	float:right;
}


code:
<?php include 'header.php'; ?>

<?php printf( _t("Displaying posts tagged: %s"), $tag ); ?>

			<?php foreach ($posts as $post): ?>

				<?php if ( is_array( $post->tags ) && ($tags_in_multiple) ) : ?>

						<?php echo $post->tags_out;?>

				<?php endif; ?>

							<a href="<?php echo $post->permalink; ?>" title="<?php echo $post->title; ?>"><?php echo $post->title_out; ?>

						<?php $post->pubdate->out(); ?>

							<a href="<?php echo $post->permalink.'#comment-form'; ?>" title="<?php _e( "Comments on this post" ); ?>"><?php $theme->post_comments_link( $post, _t('No Comments'), _t('Comment'), _t('Comments') ); ?>

						<?php echo $post->content_excerpt; ?>

			<?php endforeach; ?>

<?php include'sidebar.php' ?>

				<?php $theme->prev_page_link( _t('Newer Posts') ); ?>
				<?php $theme->next_page_link( _t('Older Posts') ); ?>

			<?php $theme->display_archives() ;?>

<?php include 'footer.php'; ?>


code:
<?php foreach($taglist as $tag): ?>

<a href="<?php echo $tag->url; ?>" title="<?php echo $tag->text; ?>" rel="tag" style="font-size: 125%;"><?php echo $tag->text; ?>

<?php endforeach; ?>


code:
<?php

define( 'THEME_CLASS', 'charcoal' );

class charcoal extends Theme
{
	//Set to true to show the title image, false to display the title text.
	const SHOW_TITLE_IMAGE = false;

	//Set to whatever you want your first tab text to be.
	const HOME_LABEL = 'Blog';

	//Set to true to show the paperclip graphic in posts, false to hide it.
	const SHOW_ENTRY_PAPERCLIP = true;

	//Set to true to show the paperclip graphic in pages, false to hide it.
	const SHOW_PAGE_PAPERCLIP = false;

	//Set to true to show the "powered by Habari" graphic in the sidebar, false to hide it.
	const SHOW_POWERED = true;

	//Set to true to show the Login/Logout link in the navigation bar, false to hide it.
	const DISPLAY_LOGIN = true;

	//Set to true to show the post tags in the multiple posts pages (search, tags, archives), false to hide them.
	const TAGS_IN_MULTIPLE = false;

	//Set to true to show single post navigation links, false to hide them.
	const SHOW_POST_NAV = true;

	//Set to the number of tags to display on the default "cloud"
	const TAGS_COUNT = 40;
	/**
	 * Execute on theme init to apply these filters to output
	 */
	public function action_init_theme()
	{
		// Apply Format::autop() to comment content...
		Format::apply( 'autop', 'comment_content_out' );
		// Truncate content excerpt at "more" or 56 characters...
		Format::apply( 'autop', 'post_content_excerpt' );
		Format::apply_with_hook_params( 'more', 'post_content_excerpt', '', 56, 1 );
	}

	/**
	 * Add some variables to the template output
	 */
	public function add_template_vars()
	{
		// Use theme options to set values that can be used directly in the templates
		// Don't check for constant values in the template code itself
		$this->assign('show_title_image', self::SHOW_TITLE_IMAGE);
		$this->assign('home_label', self::HOME_LABEL);
		$this->assign('show_powered', self::SHOW_POWERED);
		$this->assign('display_login', self::DISPLAY_LOGIN);
		$this->assign('tags_in_multiple', self::TAGS_IN_MULTIPLE);
		$this->assign('post_class', 'post' . ( ! self::SHOW_ENTRY_PAPERCLIP ? ' alt' : '' ) );
		$this->assign('page_class', 'post' . ( ! self::SHOW_PAGE_PAPERCLIP ? ' alt' : '' ) );
		$this->assign('show_post_nav', self::SHOW_POST_NAV);

		$locale =Options::get( 'locale' );
		if ( file_exists( Site::get_dir( 'theme', true ). $locale . '.css' ) ){
			$this->assign( 'localized_css',  $locale . '.css' );
		}
		else {
			$this->assign( 'localized_css', false );
		}

		if( !$this->template_engine->assigned( 'pages' ) ) {
			$this->assign('pages', Posts::get( array( 'content_type' => 'page', 'status' => Post::status('published'), 'nolimit' => 1 ) ) );
		}
		$this->assign( 'post_id', ( isset($this->post) && $this->post->content_type == Post::type('page') ) ? $this->post->id : 0 );

		// Add FormUI template placing the input before the label
		$this->add_template( 'charcoal_text', dirname(__FILE__) . '/formcontrol_text.php' );

		parent::add_template_vars();
	}

	/**
	 * Convert a post's tags array into a usable list of links
	 *
	 * @param array $array The tags array from a Post object
	 * @return string The HTML of the linked tags
	 */
	public function filter_post_tags_out($array)
	{
		if ( ! is_array( $array ) ) {
			$array = array ( $array );
		}
		$fn = create_function('$a,$b', 'return " $b) ) . "\\" rel=\\"tag\\">" . $a . "";');
		$array = array_map($fn, $array, array_keys($array));
		$out = implode(' ', $array);
		return $out;
	}

	public function theme_post_comments_link($theme, $post, $zero, $one, $more)
	{
		$c = $post->comments->approved->count;
		return 0 == $c ? $zero : sprintf( '%1$d %2$s', $c, _n( $one, $more, $c ) );
	}

	public function filter_post_content_excerpt($return)
	{
		return strip_tags($return);
	}

	public function theme_search_prompt( $theme, $criteria, $has_results )
	{
		$out =array();
		$keywords =explode(' ',trim($criteria));
		foreach ($keywords as $keyword) {
			$out[]= '' . $keyword . '';
		}

		if ( sizeof( $keywords ) > 1 ) {
			if ( $has_results ) {
				return sprintf( _t( 'Search results for \'%s\'' ), implode(' ',$out) );
				exit;
			}
			return sprintf( _t('No results found for your search \'%1$s\'') . '
'. _t('You can try searching for \'%2$s\''), $criteria, implode('\' or \'',$out) );
		}
		else {
			return sprintf( _t( 'Search results for \'%s\'' ), $criteria );
			exit;
		}
		return sprintf( _t( 'No results found for your search \'%s\'' ), $criteria );

	}

	public function theme_search_form( $theme )
	{
		return $theme->fetch('searchform');
	}

	/**
	 * Returns an unordered list of all used Tags
	 */
	public function theme_show_tags ( $theme )
	{
		$limit = self::TAGS_COUNT;
		$sql ="
			SELECT t.term AS slug, t.term_display AS text, count(tp.object_id) as ttl
			FROM {terms} t
			INNER JOIN {object_terms} tp
			ON t.id=tp.term_id
			INNER JOIN {posts} p
			ON p.id=tp.object_id AND p.status = ?
			WHERE t.vocabulary_id = ? AND tp.object_type_id = ?
			GROUP BY t.term, t.term_display
			ORDER BY t.term_display
			LIMIT {$limit}
		";
		$tags = DB::get_results( $sql, array(Post::status('published'), Tags::vocabulary()->id, Vocabulary::object_type_id( 'post' ) ) );
		foreach ($tags as $index => $tag) {
			$tags[$index]->url = URL::get( 'display_entries_by_tag', array( 'tag' => $tag->slug ) );
		}
		$theme->taglist = $tags;

		return $theme->fetch( 'taglist' );
	}

	/**
	 * Customize comment form layout. Needs thorough commenting.
	 */
	public function action_form_comment( $form ) {
		$form->cf_commenter->caption = '' . _t('Name') . ' ' . ( Options::get('comments_require_id') == 1 ? _t('(Required)') : '' ) . '';
		$form->cf_commenter->template = 'charcoal_text';
		$form->cf_email->caption = '' . _t('Mail') . ' ' . _t( '(will not be published' ) .' ' . ( Options::get('comments_require_id') == 1 ? _t('- Required)') : ')' ) . '';
		$form->cf_email->template = 'charcoal_text';
		$form->cf_url->caption = '' . _t('Website') . '';
		$form->cf_url->template = 'charcoal_text';
	        $form->cf_content->caption = '';
		$form->cf_submit->caption = _t( 'Submit' );
	}

}
?>


code:
<?xml version="1.0" encoding="utf-8" ?>
<pluggable type="theme">
	<name>Charcoal</name>
	<license url="http://www.apache.org/licenses/LICENSE-2.0.html">Apache Software License 2.0</license>

	<author url="http://habariproject.org/">Habari Community</author>

	<version>0.5</version>
	<url>http://habariproject.org/</url>
	<description><![CDATA[Charcoal is a Habari signature release, demonstrating the craft and style of the Habari platform.]]></description>

	<copyright>2009</copyright>

	<template_engine>rawphpengine</template_engine>

	<areas>
		<area name="sidebar">
			<description><![CDATA[The sidebar area]]></description>
		</area>
		<area name="nav">
			<description><![CDATA[The sidebar area]]></description>
		</area>
	</areas>

</pluggable>


code:
<?php $theme->display ( 'header' ); ?>

<?php _e('Error!'); ?>

<?php _e('The requested post was not found.'); ?>

<?php $theme->display ( 'sidebar' ); ?>

<?php $theme->display ('footer'); ?>


code:
<?php echo $post->comments->moderated->count; ?> <?php _e('Responses to'); ?> <?php echo $post->title; ?>

			<a href="<?php echo $post->comment_feed_link; ?>"><?php _e('Feed for this Entry'); ?>

<?php
if ( $post->comments->moderated->count ) {
	foreach ( $post->comments->moderated as $comment ) {

		if ( $comment->url_out == '' ) {
			$comment_url = $comment->name_out;
		}
		else {
			$comment_url = 'url_out . '" rel="external">' . $comment->name_out . '';
		}

?>
			<li id="comment-<?php echo $comment->id; ?>" <?php echo $theme->k2_comment_class( $comment, $post ); ?>>
			<a href="#comment-<?php echo $comment->id; ?>" class="counter" title="<?php _e('Permanent Link to this Comment'); ?>"><?php echo $comment->id; ?>
			<?php echo $comment_url; ?>
			<a href="#comment-<?php echo $comment->id; ?>" title="<?php _e('Time of this Comment'); ?>"><?php $comment->date->out(); ?><?php if ( $comment->status == Comment::STATUS_UNAPPROVED ) : ?> <?php _e('In moderation'); ?><?php endif; ?>

				<?php echo $comment->content_out; ?>

<?php
	}
}
else { ?>

<?php _e('There are currently no comments.'); ?>

<?php } ?>

<?php 	if ( ! $post->info->comments_disabled ) { ?>

<?php _e('Leave a Reply'); ?>

<?php	if ( Session::has_messages() ) {
		Session::messages_out();
	}

	$post->comment_form()->out();
} ?>


code:
<?php _e('DB Profiling'); ?>

	<?php
	$profiles = DB::get_profiles();
	$total_time_querying = 0;
	foreach ( $profiles as $profile ) {
	?>

			<?php echo $profile->query_text; ?>

<?php _e('Time to Execute:'); ?> <?php echo $profile->total_time; ?>

		<?php if ( !empty( $profile->backtrace ) ) { ?>

			BACKTRACE:

			<?php print_r($profile->backtrace); ?>

		<?php } ?>

	<?php
			$total_time_querying+= $profile->total_time;
	}
	?>

<?php _e('Total Time Executing Queries:'); ?> <?php echo $total_time_querying; ?>


code:
<?php $theme->display ('header'); ?>

<?php foreach ( $posts as $post ) { ?>
		<div id="post-<?php echo $post->id; ?>" class="<?php echo $post->statusname; ?> hentry">

<a href="<?php echo $post->permalink; ?>" title="<?php echo $post->title; ?>"><?php echo $post->title_out; ?>

				<?php $post->pubdate->out(); ?> <?php if ( $show_author ) { _e( 'by %s', array( $post->author->displayname ) ); } ?>
			<?php $theme->comments_link($post); ?>
<?php if ( $loggedin ) { ?>
				<a href="<?php echo $post->editlink; ?>" title="<?php _e('Edit post'); ?>"><?php _e('Edit'); ?>
<?php } ?>
<?php if ( count( $post->tags ) > 0 ) { ?>
				<?php echo $post->tags_out; ?>
<?php } ?>

			<?php echo $post->content_out; ?>

<?php } ?>

		<?php $theme->prev_page_link(); ?> <?php $theme->page_selector( null, array( 'leftSide' => 2, 'rightSide' => 2 ) ); ?> <?php $theme->next_page_link(); ?>

<?php $theme->display ('sidebar'); ?>

<?php $theme->display ( 'footer'); ?>


code:
<?php $theme->display ( 'header'); ?>

		<?php if ( $previous = $post->descend() ): ?>

 « <a href="<?php echo $previous->permalink ?>" title="<?php echo $previous->slug ?>"><?php echo $previous->title ?>

		<?php endif; ?>
		<?php if ( $next = $post->ascend() ): ?>

<a href="<?php echo $next->permalink ?>" title="<?php echo $next->slug ?>"><?php echo $next->title ?> »

		<?php endif; ?>

		<div id="post-<?php echo $post->id; ?>" class="<?php echo $post->statusname; ?>">

<a href="<?php echo $post->permalink; ?>" title="<?php echo $post->title; ?>"><?php echo $post->title_out; ?>

			<?php $post->pubdate->out(); ?> <?php if ( $show_author ) { _e( 'by %s', array( $post->author->displayname ) );  } ?>
			<?php $theme->comments_link($post); ?>
<?php if ( $loggedin ) { ?>
			<a href="<?php echo $post->editlink; ?>" title="<?php _e('Edit post'); ?>"><?php _e('Edit'); ?>
<?php } ?>
<?php if ( count( $post->tags ) > 0 ) { ?>
			<?php echo $post->tags_out; ?>
<?php } ?>

			<?php echo $post->content_out; ?>

<?php $theme->display ('comments'); ?>

<?php $theme->display ( 'sidebar' ); ?>

<?php $theme->display ( 'footer' ); ?>


code:
<?php Options::out('title'); _e(' is powered by'); ?> Habari <?php _e('and a huge amount of '); ?>
<a href="http://en.wikipedia.org/wiki/Caffeine" title="<?php _e('Caffeine'); ?>" rel="nofollow">C8H10N4O2

<a href="<?php URL::out( 'atom_feed', array( 'index' => '1' ) ); ?>"><?php _e('Atom Entries'); ?> <?php _e('and'); ?> <a href="<?php URL::out( 'atom_feed_comments' ); ?>"><?php _e('Atom Comments'); ?>

<?php $theme->footer(); ?>

<?php
/* In order to see DB profiling information:
1. Insert this line in your config file: define( 'DEBUG', TRUE );
2.Uncomment the followng line
*/
// include 'db_profiling.php';
?>


code:
<div<?php echo isset( $class ) ? " class=\"$class\"" : ''; ?><?php echo isset( $id ) ? " id=\"$id\"" : ''; ?>>
	<input<?php if ( isset( $control_title ) ) { ?> title="<?php echo $control_title; ?>"<?php } else { echo ( isset( $title ) ? " title=\"$title\"" : '' ); } if ( isset( $tabindex ) ) { ?> tabindex="<?php echo $tabindex; ?>"<?php } if ( isset( $size ) ) { ?> size="<?php echo $size; ?>"<?php } ?> type="text" id="<?php echo $field; ?>" name="<?php echo $field; ?>" value="<?php echo Utils::htmlspecialchars( $value ); ?>">
	<label<?php if ( isset( $label_title ) ) { ?> title="<?php echo $label_title; ?>"<?php } else { echo ( isset( $title ) ? " title=\"$title\"" : '' ); } ?> for="<?php echo $field; ?>"><?php echo $this->caption; ?>
	<?php $control->errors_out( '
%s
', '
%s
' ); ?>


code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<meta http-equiv="Content-Type" content="text/html">
<title><?php if($request->display_entry && isset($post)) { echo "{$post->title} - "; } ?><?php Options::out( 'title' ) ?></title>
<meta name="generator" content="Habari">

<link rel="alternate" type="application/atom+xml" title="Atom 1.0" href="<?php $theme->feed_alternate(); ?>">
<link rel="edit" type="application/atom+xml" title="Atom Publishing Protocol" href="<?php URL::out( 'atompub_servicedocument' ); ?>">
<link rel="EditURI" type="application/rsd+xml" title="RSD" href="<?php URL::out( 'rsd' ); ?>">

<link rel="stylesheet" type="text/css" media="screen" href="<?php Site::out_url( 'theme' ); ?>/style.css">

<?php $theme->header(); ?>

<body class="<?php $theme->body_class(); ?>">

<a href="<?php Site::out_url( 'habari' ); ?>"><?php Options::out( 'title' ); ?>

<?php Options::out( 'tagline' ); ?>

		<li <?php if($request->display_home) { ?>
	class="current_page_item"<?php } ?>><a href="<?php Site::out_url( 'habari' ); ?>" title="<?php Options::out( 'title' ); ?>"><?php echo $home_tab; ?>

<?php
// Menu tabs
$theme->menu('mainmenu');
if ( $user instanceof User ) { ?>

<a href="<?php Site::out_url( 'admin' ); ?>" title="<?php _e('Admin area'); ?>"><?php _e('Admin'); ?>

<?php } ?>


code:
<?php $theme->display( 'header'); ?>

<?php foreach ( $posts as $post ) { ?>
		<div id="post-<?php echo $post->id; ?>" class="<?php echo $post->statusname; ?>">

<a href="<?php echo $post->permalink; ?>" title="<?php echo $post->title; ?>"><?php echo $post->title_out; ?>

				<?php echo $post->pubdate->text_format('{M} {d}, {Y}'); ?> <?php if ( $show_author ) { _e( 'by %s', array( $post->author->displayname ) ); } ?>
			<?php $theme->comments_link($post); ?>
<?php if ( $loggedin ) { ?>
				<a href="<?php echo $post->editlink; ?>" title="<?php _e('Edit post'); ?>"><?php _e('Edit'); ?>
<?php } ?>
<?php if ( count( $post->tags ) > 0 ) { ?>
				<?php echo $post->tags_out; ?>
<?php } ?>

			<?php echo $post->content_out; ?>

<?php } ?>

		<?php $theme->prev_page_link(); ?> <?php $theme->page_selector( null, array( 'leftSide' => 2, 'rightSide' => 2 ) ); ?> <?php $theme->next_page_link(); ?>

<?php $theme->display ( 'sidebar' ); ?>

<?php $theme->display ('footer'); ?>


code:
<?php $theme->display( 'header'); ?>

<?php $theme->display( 'loginform'); ?>
<?php Plugins::act( 'theme_login' ); ?>

<?php $theme->display( 'sidebar'); ?>

<?php $theme->display( 'footer'); ?>


code:
<?php
if ( isset( $error ) && ( $error == 'Bad credentials' ) ) {
?>

<?php _e('That login is incorrect.'); ?>

<?php
}
if ( $loggedin ) {
?>

<?php _e('You are logged in as'); ?> <a href="<?php URL::out( 'admin', 'page=user&user=' . $user->username ) ?>" title="<?php _e('Edit Your Profile'); ?>"><?php echo $user->username; ?>.

<?php _e('Want to'); ?> <a href="<?php Site::out_url( 'habari' ); ?>/auth/logout"><?php _e('log out'); ?>?

<?php
}
else {
?>
	<?php Plugins::act( 'theme_loginform_before' ); ?>
		<form method="post" action="<?php URL::out( 'auth', array( 'page' => 'login' ) ); ?>" id="loginform">

			<?php _e('Name:'); ?>
			<input type="text" size="25" name="habari_username" id="habari_username">

			<?php _e('Password:'); ?>
			<input type="password" size="25" name="habari_password" id="habari_password">

			<?php Plugins::act( 'theme_loginform_controls' ); ?>

			<input type="submit" value="<?php _e('Sign in'); ?>">

		</form>
		<?php Plugins::act( 'theme_loginform_after' ); ?>
<?php
}
?>


code:
<?php $theme->display ('header'); ?>

		<div id="post-<?php echo $post->id; ?>" class="<?php echo $post->statusname; ?>">

<?php _e('Page:'); ?> <a href="<?php echo $post->permalink; ?>" title="<?php echo $post->title; ?>"><?php echo $post->title_out; ?>

			<?php $post->pubdate->out(); ?> <?php if ( $show_author ) { _e('by %s', array( $post->author->displayname ) ); } ?>
			<?php $theme->comments_link($post); ?>
<?php if ( $loggedin ) { ?>
			<a href="<?php echo $post->editlink; ?>" title="<?php _e('Edit post'); ?>"><?php _e('Edit'); ?>
<?php } ?>
<?php if ( count( $post->tags ) > 0 ) { ?>
			<?php echo $post->tags_out; ?>
<?php } ?>

			<?php echo $post->content_out; ?>

<?php $theme->display ( 'comments' ); ?>

<?php $theme->display ('sidebar'); ?>

<?php $theme->display ( 'footer' ); ?>


code:
<?php $theme->display ( 'header' ); ?>

<?php _e('Search results for %s', array( Utils::htmlspecialchars( $criteria ) ) ); ?>

<?php foreach ( $posts as $post ) { ?>
		<div id="post-<?php echo $post->id; ?>" class="<?php echo $post->statusname; ?>">

<a href="<?php echo $post->permalink; ?>" title="<?php echo $post->title; ?>"><?php echo $post->title_out; ?>

				<?php $post->pubdate->out(); ?> <?php if ( $show_author ) { _e( 'by %s', array( $post->author->displayname ) ); } ?>
			<?php $theme->comments_link($post); ?>
<?php if ( $loggedin ) { ?>
				<a href="<?php echo $post->editlink; ?>" title="<?php _e('Edit post'); ?>"><?php _e('Edit'); ?>
<?php } ?>
<?php if ( count( $post->tags ) > 0 ) { ?>
				<?php echo $post->tags_out; ?>
<?php } ?>

			<?php echo $post->content_out; ?>

<?php } ?>

		<?php $theme->prev_page_link(); ?> <?php $theme->page_selector( null, array( 'leftSide' => 2, 'rightSide' => 2 ) ); ?> <?php $theme->next_page_link(); ?>

<?php $theme->display ( 'sidebar' ); ?>

<?php $theme->display ( 'footer' ); ?>


code:
<?php Plugins::act( 'theme_searchform_before' ); ?>
		<form method="get" id="searchform" action="<?php URL::out('display_search'); ?>">

<input type="text" id="s" name="criteria" value="<?php if ( isset( $criteria ) ) { echo htmlentities($criteria, ENT_COMPAT, 'UTF-8'); } ?>"> <input type="submit" id="searchsubmit" value="<?php _e('Go!'); ?>">

		</form>
<?php Plugins::act( 'theme_searchform_after' ); ?>


code:
<?php Plugins::act( 'theme_sidebar_top' ); ?>

<?php _e('Search'); ?>

<?php $theme->display ('searchform' ); ?>

<?php _e('About'); ?>

<?php Options::out('about'); ?>

<?php $theme->area( 'sidebar' ); ?>

<?php _e('User'); ?>

<?php $theme->display ( 'loginform' ); ?>

<?php Plugins::act( 'theme_sidebar_bottom' ); ?>


code:
/*
Theme Name: K2 for Habari
Theme URI: http://getk2.com
Version: 0.9.1
Author: Various Artists
Author URI: http://binarybonsai.com

License: Apache Software License
	http://groups.google.com/group/habari-dev/msg/9b98a01189093e7e

CSS Documentation: http://k2.stikipad.com/docs/show/CSS+Overview
*/

/*- Page Structure */

html { /* Force Vertical Scrollbar */
	/* IE */
	overflow-y: scroll;
	/* Moz */
	height: 100%;
	margin-bottom: 0.1em;
}

* {
	padding: 0;
	margin: 0;
	}

img {
	border: 0;
	}

body {
	font: 62.5% 'Lucida Grande', Verdana, Arial, Sans-Serif; /* Resets 1em to 10px */
	color: #444;
	background: #EDEDED;
	text-align: center;
	margin: 0 0 30px;
	}

#page {
	background: white;
	text-align: left;
	margin: 0 auto;
	padding: 20px 0 10px;
	position: relative;
	width: 780px;
	border: 1px solid #ddd;
	border-top: none;
	}

* html #page { width: 770px } /* IE hack */

#header {
	padding: 0;
	margin: 0;
	position: relative;
	height: 200px;
	background: #3371A3;
	}

#primary {
	width: 500px;
	float: left;
	padding: 20px 0 10px;
	margin: 0 10px 0 30px;
	display: inline;
	}

.secondary {
	font-size: 1em;
	line-height: 1.5em;
	padding: 10px 0;
	margin: 0 0 20px 71%;
	width: 26%;
	color: #666;
	position: relative;
	}

.comments {
	text-align: left;
	padding: 30px 0 0;
	position: relative;
	}

/*- Main Menu in Header */

ul.menu {
	margin: 0;
	padding: 0;
	position: absolute;
	bottom: 0;
	left: 20px;
	width: 90%;
	}

ul.menu li {
	display: inline;
	margin: 0;
	}

ul.menu,
ul.menu li a {
	padding: 5px 15px 6px;
	}

ul.menu li a {
	font-size: 1em;
	color: white;
	margin: 0;
	}

ul.menu li a:hover {
	background: #333;
	color: #eee !important;
	text-decoration: none;
	}

ul.menu li.current_page_item a,
ul.menu li.current_page_item a:hover {
	color: #333 !important;
	background: white;
	text-decoration: none;
	}

.admintab {
	position: absolute;
	right: 0px;
	}

* html .admintab { padding: 5px 15px 6px }	/* IE hack */

a img,:link img,:visited img { border:none }

/*- Sidebar Subpages Menu */

.sb-pagemenu ul {
	margin-left: 10px;
	}

.sb-pagemenu ul ul {
	margin-top: 2px;
	}

.sb-pagemenu ul ul .page_item {
	margin-left: 10px;
	padding: 0;
	}

.sb-pagemenu .current_page_item {
	}

/*- Headings */

h1, h2, h3, h4 {
	font-family: 'Trebuchet MS', Verdana, Sans-Serif;
	}

h1 { /* H1 is the title in the header */
	font-size: 3em;
	font-weight: bold;
	letter-spacing: -1px;
	margin: 0;
	padding: 75px 40px 0;
	}

h1, h1 a, h1 a:hover, h1 a:visited,
#header .description {
	text-decoration: none;
	color: white;
	}

h1 a:hover {
	text-decoration: underline;
	}

#header .description { /* Description in header */
	font-size: 1em;
	margin: 0 40px;
	}

h2 { /* H2 is what kind of page you are on. Eg. 'Monthly Archive'. */
	text-align: center;
	font-size: 2.4em;
	font-weight: bold;
	letter-spacing: -1px;
	}

.secondary h2 { /* Secondary H2 is sidebar headlines */
	font-size: 1.5em !important;
	font-weight: normal !important;
	padding: 0 !important;
	display: inline;
	}

#primary h3, #primary h4, .single #primary .k2-asides h3 { /* H3 is entry headlines. H4 is comments and replyform headlines */
	font-size: 2.4em;
	font-weight: normal;
	letter-spacing: -1px;
	}

#primary .entry-content h3 {
	font-size: 1.8em;
	font-weight: normal;
	margin-top: 25px;
	}

#primary .entry-content h4 {
	font-size: 1.5em;
	font-weight: normal;
	margin-top: 25px;
	}

#primary .k2-asides h3 {
	font-size: 1.6em;
	font-weight: normal;
	}

.entry-head {
	margin-top: 10px;
	}

body.page .entry-content h3 {
	font-size: 1.7em;
	display: block;
	padding: 15px 0 0;
	}

body.page .entry-content h4 {
	font-size: 1.5em;
	display: block;
	padding: 15px 0 0;
	}

.secondary div {
	margin: 20px 0 0;
	padding: 0;
	position: relative;
	}

#primary .metalink a, #primary .metalink a:visited, /* The Metalink class takes care of the comments, edit, rss and trackback links next to the titles */
.secondary .metalink a, .secondary .metalink a:visited,
.secondary span a, .secondary span a:visited {
	color: #999;
	font-weight: normal;
	}

#primary .hentry .entry-head .metalink {
	font-size: 1.8em;
	letter-spacing: -1px;
	text-transform: lowercase;
	margin-left: 15px;
	}

#primary .k2-asides .entry-head .metalink {
	font-size: 1.4em;
	}

.single #primary .k2-asides .entry-content {
	font-size: 1.5em;
	color: #999;
	}

.comment-meta {
	margin: 0 15px 0 0;
	float: none;
	}

.comment-login, .comment-welcomeback {
	margin-top: 15px;
	color: #777;
}

#comment-personaldetails {
	margin-top: 10px;
}

.feedicon { /* Next to Comment Section Headline */
	border: 0 !important;
	padding: 0 !important;
	}

.feedlink img { /* On the sidebar */
	height: 16px;
	width: 16px;
	border: none;
	position: absolute;
	right: 0;
	}

.secondary .k2-asides {
	margin: 0;
	padding: 0 0 10px;
	word-spacing: -1px;
	}

.secondary .k2-asides p {
	display: inline;
	}

.secondary .k2-asides .metalink {
	padding-left: 0px;
	}

.secondary span a {
	margin-left: 10px;
	}

body.page .entry-edit {
	position: absolute;
	right: 0;
	margin-top: -15px;
	}

.entry-edit a {
	border: none;
	padding: 2px;
	padding-left: 23px;
	margin-left: 10px;
	background: url('images/pencil.png') left center no-repeat;
	height: 16px;
	}

.comment-edit a {
	border: none;
	padding: 2px;
	padding-left: 23px;
	margin-left: 10px;
	background: url('images/comment_edit.png') left center no-repeat;
	height: 16px;
	}

h2, h2 a, h2 a:visited,
h3, h3 a, h3 a:visited,
h4, h4 a, h4 a:visited {
	color: #444;
	}

h2, h2 a, h2 a:hover, h2 a:visited,
h3, h3 a, h3 a:hover, h3 a:visited,
h4, h4 a, h4 a:hover, h4 a:visited {
	text-decoration: none;
	}

.entry-meta { /* Time and category for blog entries */
	font-size: 1em;
	display: block;
	margin-top: 1px;
	color: #bbb;
	}

.entry-meta a, .comment-meta a {
	color: #777;
	}

.chronodata {
	padding: 2px 0 2px 20px ;
	background: url('images/time.png') left center no-repeat;
	}

.commentslink {
	padding: 2px 0 2px 20px;
	background: url('images/comment.png') left center no-repeat;
	margin-left: 10px;
	}

.quoter_comment {
	padding: 2px 0 2px 20px;
	background: url('images/comment.png') left center no-repeat;
	margin-left: 5px;
	}

.entry-tags {
	display: block;
	padding: 2px 0 2px 20px;
	background: url('images/tag_blue.png') left center no-repeat;
	}

/*- Primary Contents */

.hentry {
	margin: 0;
	padding: 5px 0 15px;
	position: relative;
	}

.entry-content {
	font-size: 1.2em;
	line-height: 1.8em;
	text-align: justify;
	color: #444;
	}

.entry-content p,
.entry-content ul,
.entry-content ol,
.entry-content div,
.entry-content blockquote {
	margin: 13px 0;
	}

.k2-asides .entry-content p,
.k2-asides .entry-content ul,
.k2-asides .entry-content ol,
.k2-asides .entry-content div,
.k2-asides .entry-content blockquote {
	margin: 5px 0;
	}

.single .k2-asides .entry-content p,
.single .k2-asides .entry-content ul,
.single .k2-asides .entry-content ol,
.single .k2-asides .entry-content div,
.single .k2-asides .entry-content blockquote {
	margin: 13px 0;
	}

.metalinks {
	margin-top: 3px;
	}

.commentsrsslink {
	background: url('images/feed.png') left top no-repeat;
	padding: 2px 0 2px 20px;
	margin-right: 10px;
	height: 16px;
	}

.trackbacklink {
	background: url('images/arrow_refresh.png') left top no-repeat;
	padding: 2px 0 2px 20px;
	height: 16px;
	}

.commentsrsslink a, .trackbacklink a {
	color: #999;
	padding: 2px;
	}

.nopassword {
	text-align: center;
	}

#commentlist {
	margin: 0;
	padding: 10px 0 20px;
	position: relative;
	}

#commentlist li {
	margin: 10px 0 0;
	padding: 10px 10px 5px;
	list-style: none;
	}

#commentlist li.comment-unapproved {
	border: #3371A3 solid 2px;
}

#commentlist li .comment-content {
	padding: 10px 0;
	font-size: 1.2em;
	line-height: 1.8em;
	}

.comment-content p,
.comment-content ul,
.comment-content ol,
.comment-content div,
.comment-content blockquote {
	margin: 13px 0;
	}

#commentlist li .comment-meta {
	padding: 2px 0 2px 20px;
	background: url('images/time.png') left center no-repeat;
	display: block;
	}

#commentlist li img {
	padding: 0;
	border: none;
	}

#commentlist li img.gravatar {
	float: right;
	margin: -5px 0 0;
	}

#commentlist li .commentauthor {
	font-size: 1.5em;
	font-weight: bold;
	letter-spacing: -1px;
	}

#commentlist li .counter {
	display: none;
	font: normal 1.5em 'Century Gothic', 'Lucida Grande', Arial, Helvetica, Sans-Serif;
	color: #999;
	float: left;
	width: 35px;
	}

li.byuser {
	background: #f6f7f8;
	}

li.bypostauthor {
	background: #eee;
	}

li.bypostauthor blockquote {
	color: #333;
	background: #eee url('images/quote.png') no-repeat 10px 0;
	}

#pinglist {
	font-size: 1.2em;
	padding: 0;
	margin: 10px 0 10px;
	background: #f6f7f8;
	}

#pinglist li {
	margin-left: 40px;
	padding: 7px 0;
	list-style: none;
	}

#pinglist li small {
	font-size: 0.8em;
	display: block;
	}

#pinglist li .counter {
	display: none;
	}

#pinglist li span.favatar img {
	margin-left: -25px;
	border: none;
	padding: 0;
	float: left;
	}

#pinglist li img {
	padding: 0;
	border: none;
	}

.comments form {
	clear: both;
	padding: 1px 0 10px;
	margin: 0;
	}

.comments input[type=text], .comments textarea {
	font: 1.2em 'Courier New', Courier, Monospace;
	padding: 3px;
	color: #777;
	}

input[type=text]:focus, textarea:focus {
	background: #fff;
	color: #333;
	border-color: #666;
	}

.comments form input[type=text] {
	width: 45%;
	margin: 5px 5px 1px 0;
	}

.comments textarea {
	height: 250px;
	width: 100%;
	margin: 10px 0;
	}

.comments form #submit {
	margin: 0;
	float: right;
	}

.comments .required {
	color: #FF0000;
}

#footer {
	margin-top: 20px;
	text-align: center;
	}

#footer a {
	color: #888;
	border-bottom: 1px solid #ccc;
	font-weight: bold;
	}

#footer a:hover {
	border: none;
	text-decoration: none;
	color: black;
	}

/*- Links */

#primary a:hover, #primary a:visited:hover,
.secondary a:hover, .secondary a:visited:hover {
	text-decoration: underline;
	}

h2 a:hover, h2 span a:hover {
	color: #27d !important;
	}

a {
	color: #27d;
	text-decoration: none;
	}

.entry-content a:visited {
	color: #b41;
	}

/*- Navigation */
.navigation {
	margin-bottom:10pt;
}

.navigation a {
	color: #999;
}

.navigation .left {
	float: left;
	text-align: left;
	width: 50%;
}

.navigation .right {
	float: right;
	text-align: right;
	width: 50%;
}

/*- Various Tags and Classes */

.clear {
	clear: both;
	margin: 0;
	padding: 0;
	}

#primary .entry-content img {
	margin: 0 5px;
	padding: 4px;
	border: 1px solid #ccc;
	max-width: 100%;
	}

.center {
	text-align: center;
	}

.alignright {
	float: right;
	}

.alignleft {
	float: left
	}

img.center, img[align="center"] {
	display: block;
	margin-left: auto;
	margin-right: auto;
	}

img.alignright, img[align="right"] {
	padding: 4px;
	margin: 0 0 2px 7px;
	display: inline;
	}

img.alignleft, img[align="left"] {
	padding: 4px;
	margin: 0 7px 2px 0;
	display: inline;
	}

img.noborder {
	border: none !important;
	}

small {
	font-size: 0.9em;
	line-height: 1.5em;
	}

small, strike {
	color: #777;
	}

code {
	font: 1.1em 'Courier New', Courier, Monospace;
	}

acronym, abbr {
	font-size: 0.9em;
	letter-spacing: .07em;
	border-bottom: 1px dashed #999;
	cursor: help;
	}

.chronodata abbr { border: 0; }

blockquote {
	margin: 20px 0;
	padding: 0 20px 0 50px;
	color: #333;
	background: #fff url('images/quote.png') no-repeat 10px 0;
	border: none;
	}

hr {
	display: none;
	}
	.comments .navigation {
		margin: 10px 0;
		}

/*Sample Page Selector Code - active page gets .current-page class */

#page-selector {
	text-align: center;
	margin: 10px 0;
	padding: 0;
	font-size: 1.2em;
	width: 100%;
	color: #999;
	}

#page-selector a {
	color: #27d;
	}

#page-selector a.current-page {
	padding: 2px;
	border: 1px solid #999;
	color: #999;
}

.draft { background: #FFFFCC; }

.alert {
	background: #FFF6BF;
	border-top: 2px solid #FFD324;
	border-bottom: 2px solid #FFD324;
	text-align: center;
	margin: 10px auto;
	padding: 5px 20px;
	}

/*- Begin Lists */
.entry-content ol, .entry-content ul {
	padding: 0 0 0 35px;
	margin: 0;
	}

.entry-content ol li, .entry-content ul li {
	margin: 0 0 3px;
	padding: 0;
	}

.secondary div p {
	margin-top: 0.5em;
	}

.secondary ul, .secondary ol, .secondary div div {
	margin: 5px 0 0;
	padding-left: 0;
	}

.secondary ol {
	margin-left: 15px;
	}

.secondary ul li, .secondary ol li {
	margin: 0;
	padding: 1px 0;
	}

.secondary ul li {
	list-style-type: none;
	list-style-image: none;
	}

ol li {
	list-style: decimal outside;
	}

.sb-links ul li {
	margin-top: 20px;
	}

.sb-links ul ul li {
	margin-top: 0;
	}

/*- Search Form and Livesearch */

#s {
	width: 12em;
	}
#s:focus {
	border-color: #666;
}

#searchsubmit {
	width: 3em;
}

/*- Login Form */

#loginform label {
	display:block;
	font-size: 0.9em;
	font-weight: bold;
	line-height: 1.5em;
	color: #777;
}
#habari_username, #habari_password {
	width: 15em;
}
#habari_username:focus, #habari_password:focus {
	border-color: #666;
}

/* CSS Beyond this point is for various supported plugins and not the 'core' K2 template */

/*-
	Latest Comments
*/
.sb-comments-lc ul li span a, .sb-comments ul li small a {
	color: #999;
	font-weight: normal;
	word-spacing: -1px;
	}

.sb-comments-lc ul li {
	margin-bottom: 6px;
}

.sb-comments-lc li > a[title="Go to the comments of this entry"] {
	position: absolute;
	right:0;
	color: #999;
}

.activityentry {
	font-size: 1.1em;
	}

div#latest-comments small {
	display: block;
	margin: 0;
	font-weight: normal;
	line-height: 1em;
	}

/*-
	FlickrRSS
*/

.sb-flickr div img {
	border: 0px;
	padding: 5px;
}

.sb-flickr div a img {
	border: 1px solid #ccc;
	padding: 3px;
	margin: 5px 3px 0;
}

.sb-flickr div a:hover img {
	border: 1px solid #999;
}

/* Peace and forgiveness */
/* Learn more about the other K2: http://en.wikipedia.org/wiki/K2 */


code:
<?php $theme->display ( 'header' ); ?>

<?php foreach ( $posts as $post ) { ?>
		<div id="post-<?php echo $post->id; ?>" class="<?php echo $post->statusname; ?>">

<a href="<?php echo $post->permalink; ?>" title="<?php echo $post->title; ?>"><?php echo $post->title_out; ?>

				<?php $post->pubdate->out(); ?> <?php if ( $show_author ) { ?> <?php _e( 'by %s', array( $post->author->displayname ) ); } ?>
			<?php $theme->comments_link($post); ?>
<?php if ( $loggedin ) { ?>
				<a href="<?php echo $post->editlink; ?>" title="<?php _e('Edit post'); ?>"><?php _e('Edit'); ?>
<?php } ?>
<?php if ( count( $post->tags ) > 0 ) { ?>
				<?php echo $post->tags_out; ?>
<?php } ?>

			<?php echo $post->content_out; ?>

<?php } ?>

		<?php $theme->prev_page_link(); ?> <?php $theme->page_selector( null, array( 'leftSide' => 2, 'rightSide' => 2 ) ); ?> <?php $theme->next_page_link(); ?>

<?php $theme->display ('sidebar' ); ?>

<?php $theme->display ( 'footer' ); ?>


code:
<?php

/**
 * MyTheme is a custom Theme class for the K2 theme.
 *
 * @package Habari
 */

// We must tell Habari to use MyTheme as the custom theme class:
define( 'THEME_CLASS', 'MyTheme' );

/**
 * A custom theme for K2 output
 */
class MyTheme extends Theme
{
	/**
	 * Execute on theme init to apply these filters to output
	 */
	public function action_init_theme()
	{
// Apply Format::autop() to comment content...
Format::apply( 'autop', 'comment_content_out' );
// Apply Format::tag_and_list() to post tags...
Format::apply( 'tag_and_list', 'post_tags_out' );

// Remove the comment on the following line to limit post length on the home page to 1 paragraph or 100 characters
//Format::apply_with_hook_params( 'more', 'post_content_out', _t('more'), 100, 1 );
	}

/**
	 * Add additional template variables to the template output.
	 *
	 *  You can assign additional output values in the template here, instead of
	 *  having the PHP execute directly in the template.  The advantage is that
	 *  you would easily be able to switch between template types (RawPHP/Smarty)
	 *  without having to port code from one to the other.
	 *
	 *  You could use this area to provide "recent comments" data to the template,
	 *  for instance.
	 *
	 *  Note that the variables added here should possibly *always* be added,
	 *  especially 'user'.
	 *
	 *  Also, this function gets executed *after* regular data is assigned to the
	 *  template.  So the values here, unless checked, will overwrite any existing
	 *  values.
	 */
	public function add_template_vars()
	{
		//Theme Options
		$this->assign('home_tab','Blog'); //Set to whatever you want your first tab text to be.
		$this->assign( 'show_author' , false ); //Display author in posts

		//Add formcontrol template with input before label
		$this->add_template( 'k2_text', dirname(__FILE__) . '/formcontrol_text.php' );

		if( !$this->template_engine->assigned( 'pages' ) ) {
			$this->assign('pages', Posts::get( array( 'content_type' => 'page', 'status' => Post::status('published'), 'nolimit' => 1 ) ) );
		}
		if( !$this->template_engine->assigned( 'page' ) ) {
			$page = Controller::get_var( 'page' );
			$this->assign('page', isset( $page ) ? $page : 1 );
		}
		parent::add_template_vars();

		if ( User::identify()->loggedin ) {
			Stack::add( 'template_header_javascript', Site::get_url('scripts') . '/jquery.js', 'jquery' );
		}
	}

	public function k2_comment_class( $comment, $post )
	{
		$class = 'class="comment';
		if ( $comment->status == Comment::STATUS_UNAPPROVED ) {
			$class.= '-unapproved';
		}
		// check to see if the comment is by a registered user
		if ( $u = User::get( $comment->email ) ) {
			$class.= ' byuser comment-author-' . Utils::slugify( $u->displayname );
		}
		if( $comment->email == $post->author->email ) {
			$class.= ' bypostauthor';
		}

		$class.= '"';
		return $class;
	}

/**
 * If comments are enabled, or there are comments on the post already, output a link to the comments.
 *
 */
	public function comments_link( $post )
	{
		if ( !$post->info->comments_disabled || $post->comments->approved->count > 0 ) {
			$comment_count = $post->comments->approved->count;
			echo "permalink}#comments\" title=\"" . _t('Comments on this post') . "\">{$comment_count} " . _n( 'Comment', 'Comments', $comment_count ) . "";
		}

	}

	public function theme_menu_empty($theme, $menu)
	{
		// Should pass menu name on to Posts::get(array('preset'=>$menu))
		if($menu == 'mainmenu') {
			$pages = Posts::get(array('content_type' => 'page', 'status' => Post::status('published')));
			$out = '';
			foreach( $pages as $page ) {
				$out .= '
permalink . '" title="' . $page->title . '">' . $page->title . '
' . "\n";
			}
			return $out;
		}
	}

	/**
	 * Customize comment form layout. Needs thorough commenting.
	 */
	public function action_form_comment( $form ) {
		$form->cf_commenter->caption = '' . _t('Name') . '' . ( Options::get('comments_require_id') == 1 ? ' *' . _t('Required') : '' ) . '';
		$form->cf_commenter->template = 'k2_text';
		$form->cf_email->caption = '' . _t('Mail') . ' ' . _t( '(will not be published)' ) .'' . ( Options::get('comments_require_id') == 1 ? ' *' . _t('Required') : '' ) . '';
		$form->cf_email->template = 'k2_text';
		$form->cf_url->caption = '' . _t('Website') . '';
		$form->cf_url->template = 'k2_text';
	        $form->cf_content->caption = '';
		$form->cf_submit->caption = _t( 'Submit' );
	}

}

?>


code:
<?xml version="1.0" encoding="utf-8" ?>
<pluggable type="theme">
	<name>K2</name>
	<license url="http://www.apache.org/licenses/LICENSE-2.0.html">Apache Software License 2.0</license>

	<author url="http://getk2.com/">K2 Team</author>

	<version>1.0</version>
	<url>http://habariproject.org/</url>
	<description><![CDATA[A port of the popular design K2 and first Habari "theme"]]></description>

	<template_engine>rawphpengine</template_engine>

	<copyright>2009</copyright>
	<areas>
		<area name="sidebar">
			<description><![CDATA[Sidebar]]></description>
		</area>
	</areas>
</pluggable>


code:
<?php $theme->display ( 'header' ); ?>

<?php _e("It seems you couldn't find what you are looking for."); ?>

<?php _e('Perhaps you can try searching.'); ?>

						<?php $theme->display ( 'searchform' ); ?>

		<?php $theme->display ( 'sidebar' ); ?>

	<?php $theme->display ( 'footer' ); ?>


code:
<?php if ( Session::has_messages() ) {
		Session::messages_out();
	}
?>

<?php $theme->comments_count($post,'%d Responses','%d Response','%d Responses'); ?> <?php _e('to'); ?> <?php echo $post->title; ?>

<a href="<?php echo $post->comment_feed_link; ?>"><?php _e('Feed for this Entry'); ?>
	<?php if( $post->comments->pingbacks->count ) : ?>

<?php $theme->pingback_count($post); ?>

					<?php foreach ( $post->comments->pingbacks->approved as $pingback ) : ?>
						<li id="ping-<?php echo $pingback->id; ?>">

								<?php echo $pingback->content; ?>

<a href="<?php echo $pingback->url; ?>" title=""><?php echo $pingback->name; ?>

					<?php endforeach; ?>

		<?php endif; ?>

<?php echo $post->comments->comments->approved->count; ?> <?php echo _n( 'Comment', 'Comments', $post->comments->comments->approved->count ); ?>

		<?php
		if ( $post->comments->moderated->count ) {
			foreach ( $post->comments->comments->moderated as $comment ) {
			$class = 'class="comment';
			if ( $comment->status == Comment::STATUS_UNAPPROVED ) {
				$class.= '-unapproved';
			}
			$class.= '"';
		?>

			<li id="comment-<?php echo $comment->id; ?>" <?php echo $class; ?>>

		        <?php echo $comment->content_out; ?>

#<a href="#comment-<?php echo $comment->id; ?>" class="counter" title="<?php _e('Permanent Link to this Comment'); ?>"><?php echo $comment->id; ?> |
		       <?php _e('Comment by'); ?> <?php $theme->comment_author_link($comment); ?>
		        <?php _e('on'); ?> <a href="#comment-<?php echo $comment->id; ?>" title="<?php _e('Time of this comment'); ?>"><?php $comment->date->out('M j, Y h:ia'); ?>
<?php if ( $comment->status == Comment::STATUS_UNAPPROVED ) : ?> <?php _e('In moderation'); ?><?php endif; ?>

		<?php
			}
		}
		else {
			_e('There are currently no comments.');
		}
		?>

<?php $post->comment_form()->out(); ?>


code:
<?php $theme->display ( 'header' ); ?>

			<?php foreach ( $posts as $post ) { ?>
				<div id="post-<?php echo $post->id; ?>" class="<?php echo $post->statusname; ?>">

<a href="<?php echo $post->permalink; ?>" title="<?php echo $post->title; ?>"><?php echo $post->title_out; ?>

<?php echo $post->pubdate_out; ?>

						<?php echo $post->content_out; ?>

						<?php if ( is_array( $post->tags ) ) { ?>

<?php _e('Tagged:'); ?> <?php echo $post->tags_out; ?>

						<?php } ?>

<?php $theme->comments_link($post,'%d Comments','%d Comment','%d Comments'); ?>

					<?php if ( $loggedin ) { ?>
					<a href="<?php echo $post->editlink; ?>" title="<?php _e('Edit post'); ?>"><?php _e('Edit'); ?>
					<?php } ?>

			<?php } ?>

				<?php $theme->prev_page_link('« ' . _t('Newer Posts')); ?> <?php $theme->page_selector( null, array( 'leftSide' => 2, 'rightSide' => 2 ) ); ?> <?php $theme->next_page_link('» ' . _t('Older Posts')); ?>

		<?php $theme->display ( 'sidebar' ); ?>

	<?php $theme->display ( 'footer' ); ?>


code:
<?php $theme->display ( 'header' ); ?>

				<?php if ( $previous = $post->ascend() ): ?>
				 « <a href="<?php echo $previous->permalink ?>" title="<?php echo $previous->slug ?>"><?php echo $previous->title ?>
				<?php endif; ?>
				<?php if ( $next = $post->descend() ): ?>
				<a href="<?php echo $next->permalink ?>" title="<?php echo $next->slug ?>"><?php echo $next->title ?> »
				<?php endif; ?>

				<div id="post-<?php echo $post->id; ?>" class="<?php echo $post->statusname; ?>">

<a href="<?php echo $post->permalink; ?>" title="<?php echo $post->title; ?>"><?php echo $post->title_out; ?>

<?php echo $post->pubdate_out; ?>

						<?php echo $post->content_out; ?>

						<?php if ( is_array( $post->tags ) ) { ?>

<?php _e('Tagged:'); ?> <?php echo $post->tags_out; ?>

						<?php } ?>

						<?php if ( $loggedin ) { ?>
						<a href="<?php echo $post->editlink; ?>" title="<?php _e('Edit post'); ?>"><?php _e('Edit'); ?>
						<?php } ?>

			<?php include 'commentform.php'; ?>

		<?php $theme->display ( 'sidebar' ); ?>

	<?php $theme->display ( 'footer' ); ?>


code:
<?php Options::out('title'); ?> <?php _e('is powered by'); ?> Habari

	<?php $theme->footer(); ?>


code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">

	<meta http-equiv="Content-Type" content="text/html">
	<title><?php if($request->display_entry && isset($post)) { echo "{$post->title} - "; } ?><?php Options::out( 'title' ) ?></title>
	<meta name="generator" content="Habari">

	<link rel="edit" type="application/atom+xml" title="Atom Publishing Protocol" href="<?php URL::out( 'atompub_servicedocument' ); ?>">
	<link rel="alternate" type="application/atom+xml" title="Atom" href="<?php $theme->feed_alternate(); ?>">
	<link rel="EditURI" type="application/rsd+xml" title="RSD" href="<?php URL::out( 'rsd' ); ?>">
	<link rel="stylesheet" type="text/css"  media="print" href="<?php Site::out_url( 'habari'); ?>/3rdparty/blueprint/print.css">
	<link rel="stylesheet" type="text/css" media ="screen" href="<?php Site::out_url( 'habari'); ?>/3rdparty/blueprint/screen.css">
	<link rel="stylesheet" type="text/css" media="screen" href="<?php Site::out_url( 'theme' ); ?>/style.css">
	<link rel="Shortcut Icon" href="<?php Site::out_url( 'theme' ); ?>/favicon.ico">
	<?php $theme->header(); ?>

<body class="<?php $theme->body_class(); ?>">

<a href="<?php Site::out_url( 'habari'); ?>" title="<?php Options::out( 'title' ); ?>"> <?php Options::out( 'title' ); ?>

<?php Options::out( 'tagline' ); ?>