code:
CREATE TABLE {$prefix}posts (
  id INT UNSIGNED NOT NULL AUTO_INCREMENT,
  slug VARCHAR(255) NOT NULL,
  content_type SMALLINT UNSIGNED NOT NULL,
  title VARCHAR(255) NOT NULL,
  guid VARCHAR(255) NOT NULL,
  content LONGTEXT NOT NULL,
  cached_content LONGTEXT NOT NULL,
  user_id SMALLINT UNSIGNED NOT NULL,
  status SMALLINT UNSIGNED NOT NULL,
  pubdate INT UNSIGNED NOT NULL,
  updated INT UNSIGNED NOT NULL,
  modified INT UNSIGNED NOT NULL,
  PRIMARY KEY (id),
  UNIQUE KEY slug (slug(80))
) DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;

CREATE TABLE  {$prefix}postinfo  (
  post_id INT UNSIGNED NOT NULL,
  name VARCHAR(255) NOT NULL,
  type SMALLINT UNSIGNED NOT NULL DEFAULT 0,
  value TEXT,
  PRIMARY KEY (post_id,name)
) DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;

CREATE TABLE  {$prefix}posttype (
  id INT UNSIGNED NOT NULL AUTO_INCREMENT,
  name VARCHAR(255) NOT NULL,
  active TINYINT(1) DEFAULT 1,
  PRIMARY KEY (id)
) DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;

CREATE TABLE  {$prefix}poststatus (
  id SMALLINT UNSIGNED NOT NULL AUTO_INCREMENT,
  name VARCHAR(255) NOT NULL,
  internal TINYINT(1),
  PRIMARY KEY (id)
) DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;

CREATE TABLE  {$prefix}options (
  name VARCHAR(255) NOT NULL,
  type SMALLINT UNSIGNED NOT NULL DEFAULT 0,
  value TEXT,
  PRIMARY KEY (name)
) DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;

CREATE TABLE  {$prefix}users (
  id SMALLINT UNSIGNED NOT NULL AUTO_INCREMENT,
  username VARCHAR(255) NOT NULL,
  email VARCHAR(255) NOT NULL,
  password VARCHAR(255) NOT NULL,
  PRIMARY KEY (id),
  UNIQUE KEY username (username)
) DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;

CREATE TABLE  {$prefix}userinfo (
  user_id SMALLINT UNSIGNED NOT NULL,
  name VARCHAR(255) NOT NULL,
  type SMALLINT UNSIGNED NOT NULL DEFAULT 0,
  value TEXT,
  PRIMARY KEY (user_id,name)
) DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;

CREATE TABLE  {$prefix}comments (
  id INT UNSIGNED NOT NULL AUTO_INCREMENT,
  post_id INT UNSIGNED NOT NULL,
  name VARCHAR(255) NOT NULL,
  email VARCHAR(255) NOT NULL,
  url VARCHAR(255) NULL,
  ip VARCHAR(45) NOT NULL,
  content TEXT,
  status SMALLINT UNSIGNED NOT NULL,
  date INT UNSIGNED NOT NULL,
  type SMALLINT UNSIGNED NOT NULL,
  PRIMARY KEY (id),
  KEY post_id (post_id)
) DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;

CREATE TABLE  {$prefix}commenttype (
  id INT UNSIGNED NOT NULL AUTO_INCREMENT,
  name VARCHAR(255) NOT NULL,
  active TINYINT(1) DEFAULT 1,
  PRIMARY KEY (id)
) DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;

CREATE TABLE  {$prefix}commentstatus (
  id SMALLINT UNSIGNED NOT NULL AUTO_INCREMENT,
  name VARCHAR(255) NOT NULL,
  internal TINYINT(1),
  PRIMARY KEY (id)
) DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;

CREATE TABLE  {$prefix}commentinfo (
  comment_id INT UNSIGNED NOT NULL,
  name VARCHAR(255) NOT NULL,
  type SMALLINT UNSIGNED NOT NULL DEFAULT 0,
  value TEXT NULL,
  PRIMARY KEY (comment_id,name)
) DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;

CREATE TABLE {$prefix}rewrite_rules (
  rule_id INT UNSIGNED NOT NULL AUTO_INCREMENT,
  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 SMALLINT UNSIGNED NOT NULL,
  is_active SMALLINT UNSIGNED NOT NULL DEFAULT 0,
  rule_class SMALLINT UNSIGNED NOT NULL DEFAULT 0,
  description TEXT NULL,
  parameters TEXT NULL,
  PRIMARY KEY (rule_id)
) DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;

CREATE TABLE {$prefix}crontab (
  cron_id INT unsigned NOT NULL auto_increment,
  name VARCHAR(255) NOT NULL,
  callback VARCHAR(255) NOT NULL,
  last_run INT UNSIGNED,
  next_run INT UNSIGNED NOT NULL,
  increment INT UNSIGNED NOT NULL,
  start_time INT UNSIGNED NOT NULL,
  end_time INT UNSIGNED,
  result VARCHAR(255) NOT NULL,
  notify VARCHAR(255) NOT NULL,
  cron_class TINYINT unsigned NOT NULL DEFAULT 0,
  description TEXT NULL,
  PRIMARY KEY (cron_id)
) DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;

CREATE TABLE {$prefix}log (
  id INT NOT NULL AUTO_INCREMENT,
  user_id INT NULL DEFAULT NULL,
  type_id INT NOT NULL,
  severity_id TINYINT NOT NULL,
  message VARCHAR(255) NOT NULL,
  data BLOB NULL,
  timestamp INT UNSIGNED NOT NULL,
  ip VARCHAR(45) NOT NULL,
  PRIMARY KEY (id)
) DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;

CREATE TABLE {$prefix}log_types (
  id INT NOT NULL AUTO_INCREMENT,
  module VARCHAR(100) NOT NULL,
  type VARCHAR(100) NOT NULL,
  PRIMARY KEY (id),
  UNIQUE KEY module_type (module,type)
) DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;

CREATE TABLE {$prefix}groups (
  id INT unsigned not null auto_increment,
  name VARCHAR(255) NOT NULL,
  PRIMARY KEY (id),
  UNIQUE KEY name (name)
) DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;

CREATE TABLE {$prefix}users_groups (
  id INT unsigned not null auto_increment,
  user_id INT unsigned not null,
  group_id INT unsigned not null,
  PRIMARY KEY (id),
  UNIQUE KEY user_group (user_id,group_id)
) DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;

CREATE TABLE {$prefix}sessions  (
  token varchar(255) NOT NULL,
  ip VARCHAR(45) NOT NULL,
  expires INT UNSIGNED NOT NULL DEFAULT 0,
  ua VARCHAR(255) NOT NULL,
  data MEDIUMTEXT,
  user_id SMALLINT UNSIGNED,
  PRIMARY KEY (token)
) DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;

CREATE TABLE {$prefix}terms (
  id INT UNSIGNED NOT NULL AUTO_INCREMENT,
  term VARCHAR(255) NOT NULL,
  term_display VARCHAR(255) NOT NULL,
  vocabulary_id INT UNSIGNED NOT NULL,
  mptt_left INT SIGNED NOT NULL,
  mptt_right INT SIGNED NOT NULL,
  PRIMARY KEY (id),
  UNIQUE KEY ix_mptt (vocabulary_id, mptt_right, mptt_left),
  UNIQUE KEY ix_term (vocabulary_id, term)
) DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;

CREATE TABLE  {$prefix}terminfo (
  term_id INT UNSIGNED NOT NULL,
  name VARCHAR(255) NOT NULL,
  type SMALLINT UNSIGNED NOT NULL DEFAULT 0,
  value TEXT NULL,
  PRIMARY KEY (term_id,name)
) DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;

CREATE TABLE {$prefix}vocabularies (
  id INT UNSIGNED NOT NULL AUTO_INCREMENT,
  name VARCHAR(255) NOT NULL,
  description TEXT,
  features TEXT,
  PRIMARY KEY (id)
) DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;

CREATE TABLE {$prefix}object_terms (
  object_id INT UNSIGNED NOT NULL,
  term_id INT UNSIGNED NOT NULL,
  object_type_id INT NOT NULL,
  PRIMARY KEY (object_id,term_id)
) DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;

CREATE TABLE {$prefix}object_types (
  id INT UNSIGNED NOT NULL AUTO_INCREMENT,
  name VARCHAR(50),
  PRIMARY KEY (id)
) DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;

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

CREATE TABLE {$prefix}tokens (
  id INT UNSIGNED NOT NULL AUTO_INCREMENT,
  name VARCHAR(255) NOT NULL,
  description VARCHAR(255) NULL,
  token_type INT UNSIGNED NOT NULL DEFAULT 0,
  token_group VARCHAR(255) NULL,
  PRIMARY KEY (id),
  UNIQUE INDEX name (name)
) DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;

CREATE TABLE {$prefix}post_tokens (
  post_id INT UNSIGNED NOT NULL,
  token_id INT UNSIGNED NOT NULL,
  PRIMARY KEY (post_id, token_id)
) DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;

CREATE TABLE {$prefix}group_token_permissions (
  group_id INT UNSIGNED NOT NULL,
  token_id INT UNSIGNED NOT NULL,
  access_mask TINYINT UNSIGNED NOT NULL,
  PRIMARY KEY (group_id, token_id)
) DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;

CREATE TABLE {$prefix}user_token_permissions (
  user_id INT UNSIGNED NOT NULL,
  token_id INT UNSIGNED NOT NULL,
  access_mask TINYINT UNSIGNED NOT NULL,
  PRIMARY KEY (user_id, token_id)
) DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;

CREATE TABLE {$prefix}scopes (
  id INT UNSIGNED NOT NULL AUTO_INCREMENT,
  name VARCHAR(255) NOT NULL,
  criteria TEXT NOT NULL,
	description TEXT NULL,
	priority TINYINT UNSIGNED NOT NULL,
  PRIMARY KEY (id)
) DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;

CREATE TABLE {$prefix}blocks (
  id INT UNSIGNED NOT NULL AUTO_INCREMENT,
  title VARCHAR(255) NOT NULL,
  type VARCHAR(255) NOT NULL,
  data TEXT NULL,
  PRIMARY KEY (id)
) DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;

CREATE TABLE {$prefix}blocks_areas (
  id INT UNSIGNED NOT NULL AUTO_INCREMENT,
  block_id INT UNSIGNED NOT NULL,
  area VARCHAR(255) NOT NULL,
  scope_id INT UNSIGNED NOT NULL,
	display_order INT UNSIGNED NOT NULL DEFAULT 0,
  PRIMARY KEY (id)
) DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;


code:
ALTER TABLE {$prefix}posts CONVERT TO CHARACTER SET binary;
ALTER TABLE {$prefix}postinfo CONVERT TO CHARACTER SET binary;
ALTER TABLE {$prefix}posttype CONVERT TO CHARACTER SET binary;
ALTER TABLE {$prefix}poststatus CONVERT TO CHARACTER SET binary;
ALTER TABLE {$prefix}options CONVERT TO CHARACTER SET binary;
ALTER TABLE {$prefix}users CONVERT TO CHARACTER SET binary;
ALTER TABLE {$prefix}userinfo CONVERT TO CHARACTER SET binary;
ALTER TABLE {$prefix}tags CONVERT TO CHARACTER SET binary;
ALTER TABLE {$prefix}tag2post CONVERT TO CHARACTER SET binary;
ALTER TABLE {$prefix}comments CONVERT TO CHARACTER SET binary;
ALTER TABLE {$prefix}commentinfo CONVERT TO CHARACTER SET binary;
ALTER TABLE {$prefix}rewrite_rules CONVERT TO CHARACTER SET binary;
ALTER TABLE {$prefix}crontab CONVERT TO CHARACTER SET binary;
ALTER TABLE {$prefix}log CONVERT TO CHARACTER SET binary;
ALTER TABLE {$prefix}log_types CONVERT TO CHARACTER SET binary;
ALTER TABLE {$prefix}groups CONVERT TO CHARACTER SET binary;
ALTER TABLE {$prefix}users_groups CONVERT TO CHARACTER SET binary;
ALTER TABLE {$prefix}groups_permissions CONVERT TO CHARACTER SET binary;
ALTER TABLE {$prefix}sessions CONVERT TO CHARACTER SET binary;
ALTER TABLE {$prefix}posts CONVERT TO CHARACTER SET binary;
ALTER TABLE {$prefix}postinfo CONVERT TO CHARACTER SET binary;
ALTER TABLE {$prefix}posttype CONVERT TO CHARACTER SET binary;
ALTER TABLE {$prefix}poststatus CONVERT TO CHARACTER SET binary;
ALTER TABLE {$prefix}options CONVERT TO CHARACTER SET binary;
ALTER TABLE {$prefix}users CONVERT TO CHARACTER SET binary;
ALTER TABLE {$prefix}userinfo CONVERT TO CHARACTER SET binary;
ALTER TABLE {$prefix}tags CONVERT TO CHARACTER SET binary;
ALTER TABLE {$prefix}tag2post CONVERT TO CHARACTER SET binary;
ALTER TABLE {$prefix}comments CONVERT TO CHARACTER SET binary;
ALTER TABLE {$prefix}commentinfo CONVERT TO CHARACTER SET binary;
ALTER TABLE {$prefix}rewrite_rules CONVERT TO CHARACTER SET binary;
ALTER TABLE {$prefix}crontab CONVERT TO CHARACTER SET binary;
ALTER TABLE {$prefix}log CONVERT TO CHARACTER SET binary;
ALTER TABLE {$prefix}log_types CONVERT TO CHARACTER SET binary;
ALTER TABLE {$prefix}groups CONVERT TO CHARACTER SET binary;
ALTER TABLE {$prefix}users_groups CONVERT TO CHARACTER SET binary;
ALTER TABLE {$prefix}groups_permissions CONVERT TO CHARACTER SET binary;
ALTER TABLE {$prefix}sessions CONVERT TO CHARACTER SET binary;

ALTER TABLE {$prefix}posts CONVERT TO CHARACTER SET utf8 COLLATE utf8_unicode_ci;
ALTER TABLE {$prefix}postinfo CONVERT TO CHARACTER SET utf8 COLLATE utf8_unicode_ci;
ALTER TABLE {$prefix}posttype CONVERT TO CHARACTER SET utf8 COLLATE utf8_unicode_ci;
ALTER TABLE {$prefix}poststatus CONVERT TO CHARACTER SET utf8 COLLATE utf8_unicode_ci;
ALTER TABLE {$prefix}options CONVERT TO CHARACTER SET utf8 COLLATE utf8_unicode_ci;
ALTER TABLE {$prefix}users CONVERT TO CHARACTER SET utf8 COLLATE utf8_unicode_ci;
ALTER TABLE {$prefix}userinfo CONVERT TO CHARACTER SET utf8 COLLATE utf8_unicode_ci;
ALTER TABLE {$prefix}tags CONVERT TO CHARACTER SET utf8 COLLATE utf8_unicode_ci;
ALTER TABLE {$prefix}tag2post CONVERT TO CHARACTER SET utf8 COLLATE utf8_unicode_ci;
ALTER TABLE {$prefix}comments CONVERT TO CHARACTER SET utf8 COLLATE utf8_unicode_ci;
ALTER TABLE {$prefix}commentinfo CONVERT TO CHARACTER SET utf8 COLLATE utf8_unicode_ci;
ALTER TABLE {$prefix}rewrite_rules CONVERT TO CHARACTER SET utf8 COLLATE utf8_unicode_ci;
ALTER TABLE {$prefix}crontab CONVERT TO CHARACTER SET utf8 COLLATE utf8_unicode_ci;
ALTER TABLE {$prefix}log CONVERT TO CHARACTER SET utf8 COLLATE utf8_unicode_ci;
ALTER TABLE {$prefix}log_types CONVERT TO CHARACTER SET utf8 COLLATE utf8_unicode_ci;
ALTER TABLE {$prefix}groups CONVERT TO CHARACTER SET utf8 COLLATE utf8_unicode_ci;
ALTER TABLE {$prefix}users_groups CONVERT TO CHARACTER SET utf8 COLLATE utf8_unicode_ci;
ALTER TABLE {$prefix}groups_permissions CONVERT TO CHARACTER SET utf8 COLLATE utf8_unicode_ci;
ALTER TABLE {$prefix}sessions CONVERT TO CHARACTER SET utf8 COLLATE utf8_unicode_ci;
ALTER TABLE {$prefix}posts CONVERT TO CHARACTER SET utf8 COLLATE utf8_unicode_ci;
ALTER TABLE {$prefix}postinfo CONVERT TO CHARACTER SET utf8 COLLATE utf8_unicode_ci;
ALTER TABLE {$prefix}posttype CONVERT TO CHARACTER SET utf8 COLLATE utf8_unicode_ci;
ALTER TABLE {$prefix}poststatus CONVERT TO CHARACTER SET utf8 COLLATE utf8_unicode_ci;
ALTER TABLE {$prefix}options CONVERT TO CHARACTER SET utf8 COLLATE utf8_unicode_ci;
ALTER TABLE {$prefix}users CONVERT TO CHARACTER SET utf8 COLLATE utf8_unicode_ci;
ALTER TABLE {$prefix}userinfo CONVERT TO CHARACTER SET utf8 COLLATE utf8_unicode_ci;
ALTER TABLE {$prefix}tags CONVERT TO CHARACTER SET utf8 COLLATE utf8_unicode_ci;
ALTER TABLE {$prefix}tag2post CONVERT TO CHARACTER SET utf8 COLLATE utf8_unicode_ci;
ALTER TABLE {$prefix}comments CONVERT TO CHARACTER SET utf8 COLLATE utf8_unicode_ci;
ALTER TABLE {$prefix}commentinfo CONVERT TO CHARACTER SET utf8 COLLATE utf8_unicode_ci;
ALTER TABLE {$prefix}rewrite_rules CONVERT TO CHARACTER SET utf8 COLLATE utf8_unicode_ci;
ALTER TABLE {$prefix}crontab CONVERT TO CHARACTER SET utf8 COLLATE utf8_unicode_ci;
ALTER TABLE {$prefix}log CONVERT TO CHARACTER SET utf8 COLLATE utf8_unicode_ci;
ALTER TABLE {$prefix}log_types CONVERT TO CHARACTER SET utf8 COLLATE utf8_unicode_ci;
ALTER TABLE {$prefix}groups CONVERT TO CHARACTER SET utf8 COLLATE utf8_unicode_ci;
ALTER TABLE {$prefix}users_groups CONVERT TO CHARACTER SET utf8 COLLATE utf8_unicode_ci;
ALTER TABLE {$prefix}groups_permissions CONVERT TO CHARACTER SET utf8 COLLATE utf8_unicode_ci;
ALTER TABLE {$prefix}sessions CONVERT TO CHARACTER SET utf8 COLLATE utf8_unicode_ci;

ALTER TABLE {$prefix}posts DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;
ALTER TABLE {$prefix}postinfo DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;
ALTER TABLE {$prefix}posttype DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;
ALTER TABLE {$prefix}poststatus DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;
ALTER TABLE {$prefix}options DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;
ALTER TABLE {$prefix}users DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;
ALTER TABLE {$prefix}userinfo DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;
ALTER TABLE {$prefix}tags DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;
ALTER TABLE {$prefix}tag2post DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;
ALTER TABLE {$prefix}comments DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;
ALTER TABLE {$prefix}commentinfo DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;
ALTER TABLE {$prefix}rewrite_rules DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;
ALTER TABLE {$prefix}crontab DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;
ALTER TABLE {$prefix}log DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;
ALTER TABLE {$prefix}log_types DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;
ALTER TABLE {$prefix}groups DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;
ALTER TABLE {$prefix}users_groups DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;
ALTER TABLE {$prefix}groups_permissions DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;
ALTER TABLE {$prefix}sessions DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;
ALTER TABLE {$prefix}posts DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;
ALTER TABLE {$prefix}postinfo DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;
ALTER TABLE {$prefix}posttype DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;
ALTER TABLE {$prefix}poststatus DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;
ALTER TABLE {$prefix}options DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;
ALTER TABLE {$prefix}users DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;
ALTER TABLE {$prefix}userinfo DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;
ALTER TABLE {$prefix}tags DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;
ALTER TABLE {$prefix}tag2post DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;
ALTER TABLE {$prefix}comments DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;
ALTER TABLE {$prefix}commentinfo DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;
ALTER TABLE {$prefix}rewrite_rules DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;
ALTER TABLE {$prefix}crontab DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;
ALTER TABLE {$prefix}log DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;
ALTER TABLE {$prefix}log_types DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;
ALTER TABLE {$prefix}groups DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;
ALTER TABLE {$prefix}users_groups DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;
ALTER TABLE {$prefix}groups_permissions DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;
ALTER TABLE {$prefix}sessions DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;

ALTER TABLE {$prefix}posts modify column content longtext;
ALTER TABLE {$prefix}posts modify column cached_content longtext;
ALTER TABLE {$prefix}postinfo modify column value text;
ALTER TABLE {$prefix}postinfo modify column value text;
ALTER TABLE {$prefix}options modify column value text;
ALTER TABLE {$prefix}userinfo modify column value text;
ALTER TABLE {$prefix}comments modify column content text;
ALTER TABLE {$prefix}commentinfo modify column value text;
ALTER TABLE {$prefix}rewrite_rules modify column description text;
ALTER TABLE {$prefix}crontab modify column description text;
ALTER TABLE {$prefix}sessions modify column data mediumtext;

repo_name: DaSourcerer/habari


code:
ALTER TABLE {$prefix}commentinfo CONVERT TO CHARACTER SET utf8 COLLATE utf8_unicode_ci;
ALTER TABLE {$prefix}comments CONVERT TO CHARACTER SET utf8 COLLATE utf8_unicode_ci;
ALTER TABLE {$prefix}crontab CONVERT TO CHARACTER SET utf8 COLLATE utf8_unicode_ci;
ALTER TABLE {$prefix}group_token_permissions CONVERT TO CHARACTER SET utf8 COLLATE utf8_unicode_ci;
ALTER TABLE {$prefix}groups CONVERT TO CHARACTER SET utf8 COLLATE utf8_unicode_ci;
ALTER TABLE {$prefix}log CONVERT TO CHARACTER SET utf8 COLLATE utf8_unicode_ci;
ALTER TABLE {$prefix}log_types CONVERT TO CHARACTER SET utf8 COLLATE utf8_unicode_ci;
ALTER TABLE {$prefix}object_terms CONVERT TO CHARACTER SET utf8 COLLATE utf8_unicode_ci;
ALTER TABLE {$prefix}object_types CONVERT TO CHARACTER SET utf8 COLLATE utf8_unicode_ci;
ALTER TABLE {$prefix}options CONVERT TO CHARACTER SET utf8 COLLATE utf8_unicode_ci;
ALTER TABLE {$prefix}post_tokens CONVERT TO CHARACTER SET utf8 COLLATE utf8_unicode_ci;
ALTER TABLE {$prefix}postinfo CONVERT TO CHARACTER SET utf8 COLLATE utf8_unicode_ci;
ALTER TABLE {$prefix}posts CONVERT TO CHARACTER SET utf8 COLLATE utf8_unicode_ci;
ALTER TABLE {$prefix}poststatus CONVERT TO CHARACTER SET utf8 COLLATE utf8_unicode_ci;
ALTER TABLE {$prefix}posttype CONVERT TO CHARACTER SET utf8 COLLATE utf8_unicode_ci;
ALTER TABLE {$prefix}rewrite_rules CONVERT TO CHARACTER SET utf8 COLLATE utf8_unicode_ci;
ALTER TABLE {$prefix}sessions CONVERT TO CHARACTER SET utf8 COLLATE utf8_unicode_ci;
ALTER TABLE {$prefix}tag2post CONVERT TO CHARACTER SET utf8 COLLATE utf8_unicode_ci;
ALTER TABLE {$prefix}tags CONVERT TO CHARACTER SET utf8 COLLATE utf8_unicode_ci;
ALTER TABLE {$prefix}terms CONVERT TO CHARACTER SET utf8 COLLATE utf8_unicode_ci;
ALTER TABLE {$prefix}tokens CONVERT TO CHARACTER SET utf8 COLLATE utf8_unicode_ci;
ALTER TABLE {$prefix}user_token_permissions CONVERT TO CHARACTER SET utf8 COLLATE utf8_unicode_ci;
ALTER TABLE {$prefix}userinfo CONVERT TO CHARACTER SET utf8 COLLATE utf8_unicode_ci;
ALTER TABLE {$prefix}users CONVERT TO CHARACTER SET utf8 COLLATE utf8_unicode_ci;
ALTER TABLE {$prefix}users_groups CONVERT TO CHARACTER SET utf8 COLLATE utf8_unicode_ci;
ALTER TABLE {$prefix}vocabularies CONVERT TO CHARACTER SET utf8 COLLATE utf8_unicode_ci;


code:
ALTER TABLE {$prefix}crontab CONVERT TO CHARACTER SET utf8 COLLATE utf8_unicode_ci;
ALTER TABLE {$prefix}groups CONVERT TO CHARACTER SET utf8 COLLATE utf8_unicode_ci;
ALTER TABLE {$prefix}group_token_permissions CONVERT TO CHARACTER SET utf8 COLLATE utf8_unicode_ci;
ALTER TABLE {$prefix}log CONVERT TO CHARACTER SET utf8 COLLATE utf8_unicode_ci;
ALTER TABLE {$prefix}log_types CONVERT TO CHARACTER SET utf8 COLLATE utf8_unicode_ci;
ALTER TABLE {$prefix}object_terms CONVERT TO CHARACTER SET utf8 COLLATE utf8_unicode_ci;
ALTER TABLE {$prefix}object_types CONVERT TO CHARACTER SET utf8 COLLATE utf8_unicode_ci;
ALTER TABLE {$prefix}post_tokens CONVERT TO CHARACTER SET utf8 COLLATE utf8_unicode_ci;
ALTER TABLE {$prefix}rewrite_rules CONVERT TO CHARACTER SET utf8 COLLATE utf8_unicode_ci;
ALTER TABLE {$prefix}sessions CONVERT TO CHARACTER SET utf8 COLLATE utf8_unicode_ci;
ALTER TABLE {$prefix}tags CONVERT TO CHARACTER SET utf8 COLLATE utf8_unicode_ci;
ALTER TABLE {$prefix}terms CONVERT TO CHARACTER SET utf8 COLLATE utf8_unicode_ci;
ALTER TABLE {$prefix}tokens CONVERT TO CHARACTER SET utf8 COLLATE utf8_unicode_ci;
ALTER TABLE {$prefix}users_groups CONVERT TO CHARACTER SET utf8 COLLATE utf8_unicode_ci;
ALTER TABLE {$prefix}user_token_permissions CONVERT TO CHARACTER SET utf8 COLLATE utf8_unicode_ci;
ALTER TABLE {$prefix}vocabularies CONVERT TO CHARACTER SET utf8 COLLATE utf8_unicode_ci;


code:
ALTER TABLE {$prefix}blocks CONVERT TO CHARACTER SET utf8 COLLATE utf8_bin;
ALTER TABLE {$prefix}blocks_areas CONVERT TO CHARACTER SET utf8 COLLATE utf8_bin;
ALTER TABLE {$prefix}commentinfo CONVERT TO CHARACTER SET utf8 COLLATE utf8_bin;
ALTER TABLE {$prefix}comments CONVERT TO CHARACTER SET utf8 COLLATE utf8_bin;
ALTER TABLE {$prefix}commentstatus CONVERT TO CHARACTER SET utf8 COLLATE utf8_bin;
ALTER TABLE {$prefix}commenttype CONVERT TO CHARACTER SET utf8 COLLATE utf8_bin;
ALTER TABLE {$prefix}crontab CONVERT TO CHARACTER SET utf8 COLLATE utf8_bin;
ALTER TABLE {$prefix}group_token_permissions CONVERT TO CHARACTER SET utf8 COLLATE utf8_bin;
ALTER TABLE {$prefix}groups CONVERT TO CHARACTER SET utf8 COLLATE utf8_bin;
ALTER TABLE {$prefix}log CONVERT TO CHARACTER SET utf8 COLLATE utf8_bin;
ALTER TABLE {$prefix}log_types CONVERT TO CHARACTER SET utf8 COLLATE utf8_bin;
ALTER TABLE {$prefix}object_terms CONVERT TO CHARACTER SET utf8 COLLATE utf8_bin;
ALTER TABLE {$prefix}object_types CONVERT TO CHARACTER SET utf8 COLLATE utf8_bin;
ALTER TABLE {$prefix}options CONVERT TO CHARACTER SET utf8 COLLATE utf8_bin;
ALTER TABLE {$prefix}post_tokens CONVERT TO CHARACTER SET utf8 COLLATE utf8_bin;
ALTER TABLE {$prefix}postinfo CONVERT TO CHARACTER SET utf8 COLLATE utf8_bin;
ALTER TABLE {$prefix}posts CONVERT TO CHARACTER SET utf8 COLLATE utf8_bin;
ALTER TABLE {$prefix}poststatus CONVERT TO CHARACTER SET utf8 COLLATE utf8_bin;
ALTER TABLE {$prefix}posttype CONVERT TO CHARACTER SET utf8 COLLATE utf8_bin;
ALTER TABLE {$prefix}rewrite_rules CONVERT TO CHARACTER SET utf8 COLLATE utf8_bin;
ALTER TABLE {$prefix}scopes CONVERT TO CHARACTER SET utf8 COLLATE utf8_bin;
ALTER TABLE {$prefix}sessions CONVERT TO CHARACTER SET utf8 COLLATE utf8_bin;
ALTER TABLE {$prefix}tag2post CONVERT TO CHARACTER SET utf8 COLLATE utf8_bin;
ALTER TABLE {$prefix}tags CONVERT TO CHARACTER SET utf8 COLLATE utf8_bin;
ALTER TABLE {$prefix}terms CONVERT TO CHARACTER SET utf8 COLLATE utf8_bin;
ALTER TABLE {$prefix}tokens CONVERT TO CHARACTER SET utf8 COLLATE utf8_bin;
ALTER TABLE {$prefix}user_token_permissions CONVERT TO CHARACTER SET utf8 COLLATE utf8_bin;
ALTER TABLE {$prefix}userinfo CONVERT TO CHARACTER SET utf8 COLLATE utf8_bin;
ALTER TABLE {$prefix}users CONVERT TO CHARACTER SET utf8 COLLATE utf8_bin;
ALTER TABLE {$prefix}users_groups CONVERT TO CHARACTER SET utf8 COLLATE utf8_bin;
ALTER TABLE {$prefix}vocabularies CONVERT TO CHARACTER SET utf8 COLLATE utf8_bin;


code:
ALTER TABLE {$prefix}posts MODIFY pubdate VARCHAR(25) NOT NULL;
ALTER TABLE {$prefix}posts MODIFY updated VARCHAR(25) NOT NULL;
ALTER TABLE {$prefix}posts ADD COLUMN modified INT UNSIGNED NOT NULL;
ALTER TABLE {$prefix}comments MODIFY date VARCHAR(25) NOT NULL;
ALTER TABLE {$prefix}log MODIFY timestamp VARCHAR(25) NOT NULL;

UPDATE {$prefix}posts SET pubdate = UNIX_TIMESTAMP(pubdate);
UPDATE {$prefix}posts SET updated = UNIX_TIMESTAMP(updated);
UPDATE {$prefix}posts SET modified = updated;
UPDATE {$prefix}comments SET date = UNIX_TIMESTAMP(date);
UPDATE {$prefix}log SET timestamp = UNIX_TIMESTAMP(timestamp);

ALTER TABLE {$prefix}posts MODIFY pubdate INT UNSIGNED NOT NULL;
ALTER TABLE {$prefix}posts MODIFY updated INT UNSIGNED NOT NULL;
ALTER TABLE {$prefix}comments MODIFY date INT UNSIGNED NOT NULL;
ALTER TABLE {$prefix}log MODIFY timestamp INT UNSIGNED NOT NULL;

ALTER TABLE {$prefix}crontab MODIFY COLUMN last_run INT UNSIGNED;
ALTER TABLE {$prefix}crontab MODIFY COLUMN next_run INT UNSIGNED NOT NULL;
ALTER TABLE {$prefix}crontab MODIFY COLUMN increment INT UNSIGNED NOT NULL;
ALTER TABLE {$prefix}crontab MODIFY COLUMN start_time INT UNSIGNED NOT NULL;
ALTER TABLE {$prefix}crontab MODIFY COLUMN end_time INT UNSIGNED;

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;


code:
<?php if ( !defined( 'HABARI_PATH' ) ) { die( 'No direct access' ); }
Config::set( 'db_connection', array(
	'connection_string'=>'pgsql:host={$db_host} dbname={$db_schema}',
	'username'=>'{$db_user}',
	'password'=>'{$db_pass}',
	'prefix'=>'{$table_prefix}'
));

// Config::set('locale', '{$locale}');
?>


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

class PGSQLConnection extends DatabaseConnection
{
	/**
	 * Extends default connection method. It will be useful in order to
	 * allow accents and other DB-centric global commands.
	 *
	 * @param string $connect_string a PDO connection string
	 * @param string $db_user the database user name
	 * @param string $db_pass the database user password
	 * @return boolean true on success, false on error
	 */
	public function connect( $connect_string, $db_user, $db_pass )
	{
		// If something went wrong, we don't need to exec the specific commands.
		if ( !parent::connect( $connect_string, $db_user, $db_pass ) ) {
			return false;
		}

		return true;
	}

	/**
	 * 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 PostgreSQL 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', 'NOW() - INTERVAL \'${1} DAYS\'', $sql );
		$sql = preg_replace( '%OPTIMIZE TABLE ([^ ]*)%i', 'VACUUM ${1};', $sql );
		//$sql= preg_replace( '%YEAR\s*\(\s*([^ ]*)\s*\)%ims', 'date_part(\'year\', ${1})', $sql );
		//$sql= preg_replace( '%MONTH\s*\(\s*([^ ]*)\s*\)%ims', 'date_part(\'month\', ${1})', $sql );
		//$sql= preg_replace( '%DAY\s*\(\s*([^ ]*)\s*\)%ims', 'date_part(\'day\', ${1})', $sql );
		$sql = preg_replace( '%YEAR\s*\(\s*FROM_UNIXTIME\s*\(\s*([^ ]*)\s*\)\s*\)%ims', 'date_part(\'year\', \'epoch\'::timestamptz + ${1} * \'1 second\'::interval)', $sql );
		$sql = preg_replace( '%MONTH\s*\(\s*FROM_UNIXTIME\s*\(\s*([^ ]*)\s*\)\s*\)%ims', 'date_part(\'month\',  \'epoch\'::timestamptz + ${1} * \'1 second\'::interval)', $sql );
		$sql = preg_replace( '%DAY\s*\(\s*FROM_UNIXTIME\s*\(\s*([^ ]*)\s*\)\s*\)%ims', 'date_part(\'day\',  \'epoch\'::timestamptz + ${1} * \'1 second\'::interval)', $sql );
		$sql = preg_replace('%LIKE\s+((\'|").*\2)%iUms', 'ILIKE \1', $sql);
		$sql = preg_replace( '%RAND\s*\(\s*\)%i', 'RANDOM()', $sql );
		return $sql;
	}

	/**
	 * Replaces the MySQL CONCAT function with PostgreSQL-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 PGSQLConnection::sql_t()
	 */
	function replace_concat( $matches )
	{
		$innards = explode( ',', $matches[1] );
		return implode( ' || ', $innards );
	}

	/**
	 * 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
	 * @param boolean $doinserts (optional) Execute all insert queries found, default=false
	 * @return  array list of updates made
	 */
	function dbdelta( $queries, $execute = true, $silent = true, $doinserts = false )
	{
		if ( !is_array( $queries ) ) {
			$queries = explode( ';', $queries );
			if ( '' == $queries[count( $queries ) - 1] ) {
				array_pop( $queries );
			}
		}

		$cseqqueries = array();
		$cqueries = array();
		$alterseqqueries = array();
		$indexqueries = array();
		$iqueries = array();
		$for_update = array();
		$indices = array();

		foreach ( $queries as $qry ) {
			if ( preg_match( "|CREATE TABLE\s+(\w*)|", $qry, $matches ) ) {
				$cqueries[strtolower( $matches[1] )] = $qry;
				$for_update[$matches[1]] = 'Created table ' . $matches[1];
			}
			else if ( preg_match( "|CREATE (UNIQUE )?INDEX ([^ ]*) ON ([^ ]*)|", $qry, $matches ) ) {
				$indexqueries[strtolower( $matches[3] )] = $qry;
			}
			else if ( preg_match( "|CREATE DATABASE ([^ ]*)|", $qry, $matches ) ) {
				array_unshift( $cqueries, $qry );
			}
			else if ( preg_match( "|CREATE SEQUENCE ([^ ]*)|", $qry, $matches ) ) {
				$cseqqueries[strtolower( $matches[1] )] = $qry;
			}
			else if ( preg_match( "|ALTER SEQUENCE ([^ ]*)|", $qry, $matches ) ) {
				$alterseqqueries[] = $qry;
			}
			else if ( preg_match( "|INSERT INTO ([^ ]*)|", $qry, $matches ) ) {
				$iqueries[] = $qry;
			}
			else if ( preg_match( "|UPDATE ([^ ]*)|", $qry, $matches ) ) {
				$iqueries[] = $qry;
			}
			else {
				// Unrecognized query type
			}
		}

		// Checking sequence
		if ( $seqnames = $this->get_results(
			"SELECT c.relname as name,
				CASE c.relkind WHEN 'r' THEN 'table' WHEN 'v' THEN 'view' WHEN 'i' THEN 'index' WHEN 'S' THEN 'sequence' WHEN 's' THEN 'special' END AS type
			   FROM pg_catalog.pg_class c
			   JOIN pg_catalog.pg_roles r ON r.oid = c.relowner
				LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace
				WHERE c.relkind IN ('S','')
				AND n.nspname NOT IN ('pg_catalog', 'pg_toast')
				AND pg_catalog.pg_table_is_visible(c.oid)
				ORDER BY 1,2;" ) ) {
			foreach ( ( array ) $seqnames as $seqname ) {
				if ( array_key_exists( strtolower( $seqname->name ), $cseqqueries ) ) {
					unset( $cseqqueries[$seqname->name] );
				}
			}
		}

		if ( $tables = $this->get_column(
			"SELECT table_name
				 FROM information_schema.tables
				 WHERE table_type = 'BASE TABLE'
				 AND table_schema NOT IN ('pg_catalog', 'information_schema');" ) ) {
			foreach ( $tables as $table ) {
				if ( array_key_exists( strtolower( $table ), $cqueries ) ) {
					unset( $cfields );
					$cfields = array();
					unset( $indices );
					$indices = array();
					preg_match( "|\((.*)\)|ms", $cqueries[strtolower( $table )], $match2 );
					$qryline = trim( $match2[1] );

					$flds = explode( "\n", $qryline );
					foreach ( $flds as $fld ) {
						preg_match( "|^([^ ]*)|", trim( $fld ), $fvals );
						$fieldname = $fvals[1];
						$validfield = true;
						switch ( strtolower( $fieldname ) ) {
							case '':
							case 'primary':
							case 'index':
							case 'fulltext':
							case 'unique':
							case 'key':
								$validfield = false;
								$indices[] = trim( trim( $fld ), ", \n" );
								break;
						}
						$fld = trim( $fld );
						if ( $validfield ) {
							$cfields[strtolower( $fieldname )] = trim( $fld, ", \n" );
						}
					}
					if ( isset( $indexqueries[$table] ) ) {
						preg_match( "|CREATE (UNIQUE )?INDEX ([^ ]*) ON ([^ ]*) \((.*)\)|ms", $indexqueries[$table], $matches );
						if ( $matches ) {
							$indices[] = ' (' . preg_replace( '/\s/ms', '', $matches[4] ) . ')';
						}
					}
					$tablefields = $this->get_results(
						"SELECT column_name AS field,
								  data_type AS type,
								  column_default AS default,
								  is_nullable AS null,
								  character_maximum_length AS length,
								  numeric_precision
						   FROM information_schema.columns
						   WHERE table_name = '{$table}'
						   ORDER BY ordinal_position;" );

					foreach ( ( array ) $tablefields as $tablefield ) {
						if ( array_key_exists( strtolower( $tablefield->field ), $cfields ) ) {
							preg_match( '/^(.*) (.*)( |$)/U', $cfields[strtolower( $tablefield->field )], $matches );
							$cfieldname = $matches[1];
							$cfieldtype = $matches[2];
							$fieldtype = $tablefield->type;

							if ( stripos( $fieldtype, 'character' ) === false ) {
								// do nothing
							}
							else {
								if ( stripos( $fieldtype, 'varying' ) > 0 ) {
									$fieldtype = 'varchar(' . $tablefield->length . ')';
								}
								else {
									$fieldtype = 'char(' . $tablefield->length . ')';
								}
							}
							if ( stripos( $fieldtype, 'timestamp' ) === false ) {
								// do nothing
							}
							else {
								$fieldtype = 'timestamp';
							}
							if ( strtolower( $fieldtype ) != strtolower( $cfieldtype ) ) {
								$cqueries[] = "ALTER TABLE {$table} ALTER COLUMN " . $cfieldname . " TYPE " . $cfieldtype;
								$for_update[$table.'.'.$tablefield->field] = "Changed type of {$table}.{$tablefield->field} from {$tablefield->type} to {$fieldtype}";
							}
							if ( preg_match( "| DEFAULT ([^ ]*)|i", $cfields[strtolower( $tablefield->field )], $matches ) ) {
								$default_value = $matches[1];
								if ( strpos( '::', $tablefield->default) === false ) {
									$tablefield_default = $tablefield->default;
								}
								else {
									preg_match( '|(.*)::|', $tablefield->default, $matches );
									$tablefield_default = $matches[1] . ( preg_match( '|^nextval|i', $matches[1] ) > 0 ? ')' : '' );
								}
								if ( $tablefield_default != $default_value ) {
									$cqueries[] = "ALTER TABLE {$table} ALTER COLUMN {$tablefield->field} SET DEFAULT {$default_value}";
									$for_update[$table.'.'.$tablefield->field] = "Changed default value of {$table}.{$tablefield->field} from {$tablefield->default} to {$default_value}";
								}
							}
							elseif ( strlen( $tablefield->default) > 0 ) {
								$cqueries[] = "ALTER TABLE {$table} ALTER COLUMN {$tablefield->field} DROP DEFAULT";
								$for_update[$table.'.'.$tablefield->field] = "Dropped default value of {$table}.{$tablefield->field}";
							}
							unset( $cfields[strtolower( $tablefield->field )] );
						}
						else {
							// This field exists in the table, but not in the creation queries?
						}
					}
					foreach ( $cfields as $fieldname => $fielddef ) {
						$cqueries[] = "ALTER TABLE {$table} ADD COLUMN $fielddef";
						$for_update[$table.'.'.$fieldname] = 'Added column '.$table.'.'.$fieldname;
					}
					$tableindices = $this->get_results(
						"SELECT c2.relname AS key_name,
									i.indisprimary AS is_primary,
									i.indisunique AS is_unique,
									i.indisclustered AS is_clustered,
									i.indisvalid AS is_valid,
									pg_catalog.pg_get_indexdef(i.indexrelid, 0, true) AS index_def,
									c2.reltablespace
							 FROM pg_catalog.pg_class c, pg_catalog.pg_class c2,
									pg_catalog.pg_index i
							 WHERE c.oid = (
								SELECT c.oid
									FROM pg_catalog.pg_class c
									LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace
									WHERE c.relname = '{$table}'
									AND pg_catalog.pg_table_is_visible(c.oid)
								)
								AND c.oid = i.indrelid AND i.indexrelid = c2.oid
								ORDER BY i.indisprimary DESC, i.indisunique DESC,
									c2.relname;" );

					if ( $tableindices ) {
						unset( $index_ary );
						$index_ary = array();
						foreach ( ( array ) $tableindices as $tableindex ) {
							$keyname = $tableindex->key_name;
							preg_match( '/\((.*)\)/', $tableindex->index_def, $matches );
							$fieldnames = str_replace( '"', '', str_replace( ' ', '', $matches[1] ) );
							$index_ary[$keyname]['fieldnames'] = $fieldnames;
							$index_ary[$keyname]['unique'] = ( $tableindex->is_unique == true ) ? true : false;
							$index_ary[$keyname]['primary'] = ( $tableindex->is_primary == true ) ? true : false;
						}

						foreach ( $index_ary as $index_name => $index_data ) {
							$index_string = '';
							if ( $index_data['primary'] ) {
								$index_string .= 'PRIMARY KEY ';
							}
							else if ( $index_data['unique'] ) {
								$index_string .= 'UNIQUE ';
							}
							$index_columns = $index_data['fieldnames'];

							$index_string = rtrim( $index_string, ' ' );
							$index_string .= ' (' . $index_columns . ')';
							if ( !( ( $aindex = array_search( $index_string, $indices ) ) === false ) ) {
								unset( $indices[$aindex] );
								unset( $indexqueries[$table] );
							}
							else {
								if ( $index_data['unique'] ) {
									$cqueries[] = "ALTER TABLE {$table} DROP CONSTRAINT {$index_name}";
								}
								else {
									$cqueries[] = "DROP INDEX {$index_name}";
								}
							}
						}
					}
					foreach ( $indices as $index ) {
						$cqueries[] = "ALTER TABLE {$table} ADD $index";
						$for_update[$table . '.' . $fieldname] = 'Added index ' . $table . ' ' . $index;
					}
					unset( $cqueries[strtolower( $table )] );
					unset( $for_update[strtolower( $table )] );
				}
				else {
				}
			}
		}

		$allqueries = array_merge( $cseqqueries, $cqueries, $alterseqqueries );
		if ( $doinserts ) {
			$allqueries = array_merge( $allqueries, $iqueries );
		}
		foreach ( $indexqueries as $tablename => $indexquery ) {
			$allqueries = array_merge( $allqueries, ( array ) $indexquery );
		}

		if ( $execute ) {
			foreach ( $allqueries as $query ) {
				if ( !$this->exec( $query ) ) {
					$this->get_errors();
					return false;
				}
			}
		}

		if ( !$silent ) {
			if ( count( $for_update ) > 0 ) {
				echo "
\n";
				foreach ( $for_update as $upgrade ) {
					echo "
{$upgrade}
\n";
				}
				echo "
\n";
			}
			else {
				echo "

" . _t('No Upgrades') . "

";
			}
		}
		return $for_update;
	}

	/**
	 * 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');
	}
}
?>


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}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 VARCHAR(45) 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 VARCHAR(45) NOT NULL,
  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,
  ip VARCHAR(45) NOT NULL,
  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 TABLE {$prefix}terminfo (
  term_id BIGINT NOT NULL,
  name VARCHAR(255) NOT NULL,
  type INTEGER NOT NULL DEFAULT 0,
  value TEXT NULL,
  PRIMARY KEY (term_id,name)
);

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;


code:
<?php if ( !defined( 'HABARI_PATH' ) ) { die( 'No direct access' ); }
Config::set( 'db_connection', array(
	'connection_string'=>'sqlite:{$db_file}',
	'username'=>'',
	'password'=>'',
	'prefix'=>'{$table_prefix}'
));

// Config::set('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}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 VARCHAR(45) 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 VARCHAR(45) 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,
  ip VARCHAR(45) 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}terminfo (
  term_id INTEGER NOT NULL,
  name VARCHAR(255) NOT NULL,
  type SMALLINTEGER NOT NULL DEFAULT 0,
  value TEXT NULL,
  PRIMARY KEY (term_id, name)
);

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 if ( !defined( 'HABARI_PATH' ) ) { die('No direct access'); } ?>
<?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 ( !defined( 'HABARI_PATH' ) ) { die( 'No direct access' ); } ?>
<?php foreach($content->menus as $menu) : ?>
<li class="<?php echo $menu['cssclass']; ?> block-<?php echo Utils::slugify($menu['caption']); ?>"><a href="<?php echo $menu['link']; ?>"><?php echo $menu['caption']; ?>

<?php endforeach; ?>


code:
<?php if ( !defined( 'HABARI_PATH' ) ) { die('No direct access'); } ?>
<?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 ( !defined( 'HABARI_PATH' ) ) { die('No direct access'); } ?>
		<?php if ( !$post->info->comments_disabled || $post->comments->moderated->count ) :?>

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

				<?php

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

				?>

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

							<?php echo $comment_url; ?>

						<?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 if ( !defined( 'HABARI_PATH' ) ) { die('No direct access'); } ?>
<?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 ( count($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 echo $theme->post_comments_link( $post ); ?>

						<?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 ( !defined( 'HABARI_PATH' ) ) { die('No direct access'); } ?>

<?php echo (Plugins::is_loaded('tagcloud')) ? $theme->tag_cloud() : $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 echo $theme->footer(); ?>


code:
<?php if ( !defined( 'HABARI_PATH' ) ) { die('No direct access'); } ?>
<div<?php
	echo $control->parameter_map(
		array(
			'class', 'id' => 'name'
		)
	); ?>>
	<input <?php
		echo $control->parameter_map(
			array(
				'title' => array('control_title', 'title'),
				'tabindex', 'size', 'maxlength', 'type', 'placeholder',
				'id' => 'field',
				'name' => 'field',
			),
			array(
				'value' => Utils::htmlspecialchars( $value ),
			)
		);
		?>>
	<label <?php
		echo $control->parameter_map(
			array(
				'title' => array('label_title', 'title'),
				'for' => 'field',
			)
		); ?>><?php echo $this->caption; ?>
	<?php $control->errors_out( '
%s
', '
%s
' ); ?>


code:
<?php if ( !defined( 'HABARI_PATH' ) ) { die('No direct access'); } ?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html lang="<?php echo $locale; ?>">

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

<body class="<?php echo $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' ); ?>

						<?php echo $theme->area( 'nav' ); ?>
						<?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 if ( !defined( 'HABARI_PATH' ) ) { die('No direct access'); } ?>
<?php include 'header.php'; ?>

            <?php $posts = (array) $posts; ?>
			<?php if ( count( $posts ) ): ?>
				<?php $post =reset($posts); ?>
				<div class="<?php echo $post_class?>">
				<?php if ( count( $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 echo $theme->post_comments_link( $post ); ?>

						<?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 echo $theme->prev_page_link( _t('Newer Posts') ); ?>
				<?php echo $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 if ( !defined( 'HABARI_PATH' ) ) { die('No direct access'); } ?>
<?php include 'header.php'; ?>

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

				<?php if ( count( $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 echo $theme->post_comments_link( $post ); ?>

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

		<?php endforeach; ?>

		<?php include'sidebar.php' ?>

				<?php echo $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 echo $theme->next_page_link( _t('Older Posts') ); ?>

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

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


code:
<?php if ( !defined( 'HABARI_PATH' ) ) { die('No direct access'); } ?>
<?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 if ( !defined( 'HABARI_PATH' ) ) { die('No direct access'); } ?>
<?php include 'header.php'; ?>

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

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

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

				<?php if ( count( $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 echo $theme->post_comments_link( $post ); ?>

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

			<?php endforeach; ?>

		<?php else: ?>

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

		<?php endif; ?>

			<?php include'sidebar.php' ?>

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

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

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


code:
<?php if ( !defined( 'HABARI_PATH' ) ) { die('No direct access'); } ?>
<form method="get" id="search-form" action="<?php URL::out('display_search'); ?>" onsubmit="if ( document.getElementById('search-box').value == '<?php printf( _t("Search %s"), str_replace("'", "\'", Options::get("title")) ); ?>' ) { return false; }">
	<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 if ( !defined( 'HABARI_PATH' ) ) { die( 'No direct access' ); } ?>
<div class="block<?php if( $block->_first ): ?> first<?php endif; if( $block->_last ):?> last<?php endif; echo ' index_' . $block->_area_index; ?>">
<?php if ( $block->_show_title ) :?>

<?php echo $block->title; ?>

<?php endif; ?>
<?php echo $content; ?>


code:
<?php if ( !defined( 'HABARI_PATH' ) ) { die('No direct access'); } ?>

	<?php echo $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 echo $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;
}
body.display_home #main-posts {
	padding:20px 0 0 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-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 if ( !defined( 'HABARI_PATH' ) ) { die('No direct access'); } ?>
<?php include 'header.php'; ?>

<?php echo $tags_msg; ?>

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

				<?php if ( count( $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 echo $theme->post_comments_link( $post ); ?>

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

			<?php endforeach; ?>

<?php include'sidebar.php' ?>

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

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

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


code:
<?php if ( !defined( 'HABARI_PATH' ) ) { die('No direct access'); } ?>

<?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; ?>