From 2330bb06ececee220d854883a2870a3adf17c277 Mon Sep 17 00:00:00 2001 From: root Date: Sun, 19 Oct 2014 03:54:53 +0200 Subject: Version 4.1. Support for photo galleries and advanced caching. --- class/cache.php | 74 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++- class/moar.php | 58 ++++++++++++++++++++++++++++++++++++++++++++ class/mysql.php | 17 ++++++++++++- 3 files changed, 147 insertions(+), 2 deletions(-) create mode 100644 class/moar.php (limited to 'class') diff --git a/class/cache.php b/class/cache.php index 8005484..b64ab9d 100644 --- a/class/cache.php +++ b/class/cache.php @@ -2,11 +2,17 @@ class cache { public $token = ""; + public $bypassCache; private $db; + private $dbnmr; + private $dbpagecache; + private $db2nd; + public function __construct($rconnect, $rdb){ $this->db = new Redis(); + $this->bypassCache=false; try { $this->db->connect($rconnect); @@ -23,6 +29,9 @@ class cache { } catch (Exception $e) { return $e->getMessage(); } + $this->dbnmr = $rdb; + $this->dbpagecache = PAGECACHE_DB; + $this->db2nd = SECOND_CACHE; } public function check(){ @@ -58,12 +67,75 @@ class cache { return $this->db->delete($key); } + public function setPageCache($key, $value, $ttl = 3600){ + $this->db->select( $this->dbpagecache ); + $this->db->set( $key, $value, $ttl ); + $this->db->select( $this->dbnmr ); + } + + public function getPageCache($key){ + $this->db->select( $this->dbpagecache ); + $data = $this->db->get( $key ); + $this->db->select( $this->dbnmr ); + return $data; + } + + public function existsPageCache($key){ + $this->db->select( $this->dbpagecache ); + $data = $this->exists( $key ); + $this->db->select( $this->dbnmr ); + return $data; + } + + public function flushPageCache(){ + $this->db->select( $this->dbpagecache ); + $this->db->flushDB(); + $this->db->select( $this->dbnmr ); + } + public function flush($token = null){ + $this->flushPageCache(); if ( is_null($token) ) return $this->db->flushDB(); else return $this->db->delete($token); } -} + public function flushAll(){ + $this->db->flushDB(); + $this->flushPageCache(); + $this->flush2(); + } + public function set2($key, $value, $ttl = null){ + $this->db->select( $this->db2nd ); + $this->db->set($key, $value, $ttl); + $this->db->select( $this->dbnmr ); + } + + public function get2($key){ + $this->db->select( $this->db2nd ); + $data = $this->db->get($key); + $this->db->select( $this->dbnmr ); + return $data; + } + + public function exists2($key){ + $this->db->select( $this->db2nd ); + $data = $this->db->exists($key); + $this->db->select( $this->dbnmr ); + return $data; + } + + public function flush2($token = null){ + $this->db->select( $this->db2nd ); + if ( is_null($token) ) + $data = $this->db->flushDB(); + else + $data = $this->db->delete($token); + + $this->db->select( $this->dbnmr ); + $this->flushPageCache(); + return $data; + } +} diff --git a/class/moar.php b/class/moar.php new file mode 100644 index 0000000..822640f --- /dev/null +++ b/class/moar.php @@ -0,0 +1,58 @@ +header[] = $string; + } + + public function addFooter($string){ + $this->footer[] = $string; + } + + public function playHeader(){ + if ( ! empty( $this->header ) ){ + foreach( $this->header as $value ){ + echo $value; + } + } + $this->deleteHeader(); + } + + public function playFooter(){ + if ( ! empty( $this->footer ) ){ + foreach( $this->footer as $value ){ + echo $value; + } + } + $this->deleteFooter(); + } + + public function deleteHeader(){ + unset( $this->header ); + } + + public function deleteFooter(){ + unset( $this->footer ); + + } + + public function magicHeader($html){ + ob_start(); + $this->playHeader(); + $header = ob_get_contents(); + ob_end_clean(); + return preg_replace("/\<\!\-\-%%placeholder\-head%%\-\-\>/", $header, $html); + } + + public function __destruct(){ + return true; + } +} diff --git a/class/mysql.php b/class/mysql.php index 8d75538..eea5f95 100644 --- a/class/mysql.php +++ b/class/mysql.php @@ -72,6 +72,10 @@ class db { return true; } + public function affectedRows(){ + return $this->db->affected_rows; + } + # code by WordPress. See @link https://core.trac.wordpress.org/browser/branches/4.0/src/wp-includes/wp-db.php#L1154 # syntax like sprintf() public function prepare( $query, $args ) { @@ -143,7 +147,18 @@ class db { ) ENGINE=InnoDB;'; - if ( ! $this->execMultipleQueries('BEGIN; '. $user_table . ' ' . $banned_user_table . ' ' . $jg_table . ' COMMIT;') ) + $gallery_table = + 'CREATE TABLE IF NOT EXISTS ' . DBPREFIX . 'gallery + ( id INTEGER AUTO_INCREMENT NOT NULL, PRIMARY KEY(id), + name varchar(70), UNIQUE(name), + description varchar(500), + owner INTEGER, FOREIGN KEY(owner) REFERENCES ' . DBPREFIX . 'user(id), + restricted INTEGER, + time INTEGER + ) + ENGINE=InnoDB;'; + + if ( ! $this->execMultipleQueries('BEGIN; '. $user_table . ' ' . $banned_user_table . ' ' . $jg_table . ' ' . $gallery_table . ' COMMIT;') ) failure("
There was a problem during bootstrapping the database schema. " . $this->db->error . "
", '500 Server Failure', false, "