aboutsummaryrefslogtreecommitdiff
path: root/class
diff options
context:
space:
mode:
authorroot2014-10-19 03:54:53 +0200
committerroot2014-10-19 03:54:53 +0200
commit2330bb06ececee220d854883a2870a3adf17c277 (patch)
treee49f6b561faf5b39a81d57d54fa57a1550074c0f /class
parenta3009bf57d50fbc25a707b32fb3c5c170d011680 (diff)
downloadjungegemeinde-2330bb06ececee220d854883a2870a3adf17c277.tar.gz
Version 4.1. Support for photo galleries and advanced caching.
Diffstat (limited to 'class')
-rw-r--r--class/cache.php74
-rw-r--r--class/moar.php58
-rw-r--r--class/mysql.php17
3 files changed, 147 insertions, 2 deletions
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 @@
+<?php
+
+class Moar {
+
+ private $header = array();
+ private $footer = array();
+
+ public function __construct(){
+ return true;
+ }
+
+ public function addHeader($string){
+ $this->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("<p>There was a problem during bootstrapping the database schema. " . $this->db->error . "</p>", '500 Server Failure', false, "<h1>CREATE TABLE FAILED</h1>");
}