initial import

This commit is contained in:
Alchemy
2011-02-16 16:09:48 +01:00
parent 399a584b6f
commit 339d23c06d
5539 changed files with 2028637 additions and 1 deletions

70
lib/classes/cache/appbox.class.php vendored Normal file
View File

@@ -0,0 +1,70 @@
<?php
class cache_appbox
{
private static $_instance = false;
var $_c_obj = false;
function __construct()
{
$this->_c_obj = cache::getInstance();
}
/**
* @return cache_appbox
*/
public static function getInstance()
{
if (!(self::$_instance instanceof self))
self::$_instance = new self();
return self::$_instance;
}
public function get($id)
{
return $this->_c_obj->get(GV_ServerName.'_appbox_'.$id);
}
public function set($id,$value)
{
return $this->_c_obj->set(GV_ServerName.'_appbox_'.$id,$value);
}
public function delete($id)
{
// if(in_array($id, array('sbas_names','bas_names')))
// {
// $this->delete('list_bases');
// }
if($id == 'list_bases')
{
$this->delete('bas_names');
$this->delete('sbas_names');
$this->delete('sbas_from_bas');
$avLanguages = user::detectlanguage();
foreach($avLanguages as $lng=>$languages)
{
foreach($languages as $locale=>$language)
{
$this->delete('bases_settings_'.$locale);
}
}
}
return $this->_c_obj->delete(GV_ServerName.'_appbox_'.$id);
}
public function is_ok()
{
return $this->_c_obj->is_ok();
}
}

113
lib/classes/cache/basket.class.php vendored Normal file
View File

@@ -0,0 +1,113 @@
<?php
class cache_basket
{
private static $_instance = false;
var $_c_obj = false;
function __construct()
{
$this->_c_obj = cache::getInstance();
}
/**
* @return cache_basket
*/
public static function getInstance()
{
if (!(self::$_instance instanceof self))
self::$_instance = new self();
return self::$_instance;
}
public function get($usr_id, $ssel_id)
{
return $this->_c_obj->get(GV_ServerName.'_basket_'.$usr_id.'_'.$ssel_id);
}
public function set($usr_id, $ssel_id,$value)
{
return $this->_c_obj->set(GV_ServerName.'_basket_'.$usr_id.'_'.$ssel_id,$value);
}
public function delete($usr_id, $ssel_id)
{
try
{
$basket = basket::getInstance($ssel_id, $usr_id);
if($basket->valid)
{
foreach($basket->validating_users as $user_data)
{
$this->_c_obj->delete(GV_ServerName.'_basket_'.$user_data['usr_id'].'_'.$ssel_id);
}
}
return $this->_c_obj->delete(GV_ServerName.'_basket_'.$usr_id.'_'.$ssel_id);
}
catch(Exception $e)
{
}
}
/**
* Revoke cache when user rights have been modified - do not cache datas which are now forbidden
* @param $usr_id
* @return boolean
*/
public function revoke_baskets_usr($usr_id)
{
$conn = connection::getInstance();
$ssel_ids = array();
if($conn)
{
$sql = 'SELECT ssel_id FROM ssel WHERE deleted="0"';
if($rs = $conn->query($sql))
{
while($row = $conn->fetch_assoc($rs))
{
$ssel_ids[] = GV_ServerName.'_basket_'.$usr_id.'_'.$row['ssel_id'];
}
$conn->free_result($rs);
}
}
return $this->_c_obj->deleteMulti($ssel_ids);
}
/**
* Revoke cache when user documents have their collection changed or status - do not cache datas which are now forbidden
* @param $usr_id
* @return boolean
*/
public function revoke_baskets_record($records_array)
{
$conn = connection::getInstance();
$keys = array();
if($conn)
{
$sql = 'SELECT s.ssel_id, s.usr_id FROM ssel s, sselcont c WHERE (c.record_id="'.implode('" OR c.record_id="',$records_array).'") AND c.ssel_id = s.ssel_id';
if($rs = $conn->query($sql))
{
while($row = $conn->fetch_assoc($rs))
{
$keys[] = GV_ServerName.'_basket_'.$row['usr_id'].'_'.$row['ssel_id'];
}
$conn->free_result($rs);
}
}
return $this->_c_obj->deleteMulti($keys);
}
}

47
lib/classes/cache/baskets.class.php vendored Normal file
View File

@@ -0,0 +1,47 @@
<?php
class cache_baskets
{
private static $_instance = false;
var $_c_obj = false;
function __construct()
{
$this->_c_obj = cache::getInstance();
}
/**
* @return cache_baskets
*/
public static function getInstance()
{
if (!(self::$_instance instanceof self))
self::$_instance = new self();
return self::$_instance;
}
public function get($usr_id)
{
return $this->_c_obj->get(GV_ServerName.'_baskets_'.$usr_id);
}
public function set($usr_id,$value)
{
return $this->_c_obj->set(GV_ServerName.'_baskets_'.$usr_id,$value);
}
public function delete($usr_id)
{
return $this->_c_obj->delete(GV_ServerName.'_baskets_'.$usr_id);
}
}

47
lib/classes/cache/collection.class.php vendored Normal file
View File

@@ -0,0 +1,47 @@
<?php
class cache_collection
{
private static $_instance = false;
var $_c_obj = false;
function __construct()
{
$this->_c_obj = cache::getInstance();
}
/**
* @return cache_collection
*/
public static function getInstance()
{
if (!(self::$_instance instanceof self))
self::$_instance = new self();
return self::$_instance;
}
public function get($base_id,$what)
{
return $this->_c_obj->get(GV_ServerName.'_collection_'.$base_id.'_'.$what);
}
public function set($base_id,$what,$bin)
{
return $this->_c_obj->set(GV_ServerName.'_collection_'.$base_id.'_'.$what,$bin);
}
public function delete($base_id,$what)
{
return $this->_c_obj->delete(GV_ServerName.'_collection_'.$base_id.'_'.$what);
}
}

120
lib/classes/cache/databox.class.php vendored Normal file
View File

@@ -0,0 +1,120 @@
<?php
class cache_databox
{
private static $_instance = false;
var $_c_obj = false;
function __construct()
{
$this->_c_obj = cache::getInstance();
}
/**
* @return cache_databox
*/
public static function getInstance()
{
if (!(self::$_instance instanceof self))
self::$_instance = new self();
return self::$_instance;
}
public function get($type,$what)
{
return $this->_c_obj->get(GV_ServerName.'_databox_'.$type.'_'.$what);
}
public function set($type,$what,$bin)
{
return $this->_c_obj->set(GV_ServerName.'_databox_'.$type.'_'.$what,$bin);
}
public function delete($type,$what)
{
return $this->_c_obj->delete(GV_ServerName.'_databox_'.$type.'_'.$what);
}
function refresh($sbas_id)
{
$date = new DateTime('-30 seconds');
$cache_appbox = cache_appbox::getInstance();
$last_update = $cache_appbox->get('memcached_update');
if($last_update)
$last_update = new DateTime($last_update);
else
$last_update = new DateTime('-10 years');
if($date > $last_update && $cache_appbox->is_ok())
{
$connsbas = connection::getInstance($sbas_id);
if($connsbas)
{
$sql = 'SELECT type, value FROM memcached WHERE site_id="'.$connsbas->escape_string(GV_ServerName).'"';
if($rs = $connsbas->query($sql))
{
$cache_record = cache_record::getInstance();
$cache_thumbnail = cache_thumbnail::getInstance();
$cache_preview = cache_preview::getInstance();
while($row = $connsbas->fetch_assoc($rs))
{
switch($row['type'])
{
case 'record':
$cache_record->delete($sbas_id,$row['value'],false);
$cache_thumbnail->delete($sbas_id,$row['value'],false);
$cache_preview->delete($sbas_id,$row['value'],false);
$sql = 'DELETE FROM memcached WHERE site_id="'.$connsbas->escape_string(GV_ServerName).'" AND type="record" AND value="'.$row['value'].'"';
$connsbas->query($sql);
break;
case 'structure':
$cache_appbox->delete('list_bases');
$sql = 'DELETE FROM memcached WHERE site_id="'.$connsbas->escape_string(GV_ServerName).'" AND type="structure" AND value="'.$row['value'].'"';
$connsbas->query($sql);
break;
}
}
}
}
$date = new DateTime();
$now = phraseadate::format_mysql($date);
$cache_appbox->set('memcached_update',$now);
$conn = connection::getInstance();
$sql = 'UPDATE sitepreff SET memcached_update="'.$conn->escape_string($now).'"';
$conn->query($sql);
}
}
function update($sbas_id, $type, $value='')
{
$connbas = connection::getInstance($sbas_id);
if($connbas)
{
$sql = 'SELECT distinct site_id as site_id FROM clients WHERE site_id != "'.$connbas->escape_string(GV_ServerName).'"';
if($rs = $connbas->query($sql))
{
while($row = $connbas->fetch_assoc($rs))
{
$sql = 'REPLACE INTO memcached (site_id, type, value) VALUES ("'.$connbas->escape_string($row['site_id']).'","'.$connbas->escape_string($type).'","'.$connbas->escape_string($value).'")';
$connbas->query($sql);
}
$connbas->free_result($rs);
}
}
return true;
}
}

47
lib/classes/cache/feed.class.php vendored Normal file
View File

@@ -0,0 +1,47 @@
<?php
class cache_feed
{
private static $_instance = false;
var $_c_obj = false;
function __construct()
{
$this->_c_obj = cache::getInstance();
}
/**
* @return cache_feed
*/
public static function getInstance()
{
if (!(self::$_instance instanceof self))
self::$_instance = new self();
return self::$_instance;
}
public function get($feed_id)
{
return $this->_c_obj->get(GV_ServerName.'_feed_'.$feed_id);
}
public function set($feed_id,$datas)
{
return $this->_c_obj->set(GV_ServerName.'_feed_'.$feed_id,$datas, 1800);
}
public function delete($feed_id)
{
return $this->_c_obj->delete(GV_ServerName.'_feed_'.$feed_id);
}
}

54
lib/classes/cache/preview.class.php vendored Normal file
View File

@@ -0,0 +1,54 @@
<?php
class cache_preview
{
private static $_instance = false;
var $_c_obj = false;
function __construct()
{
$this->_c_obj = cache::getInstance();
}
/**
* @return cache_preview
*/
public static function getInstance()
{
if (!(self::$_instance instanceof self))
self::$_instance = new self();
return self::$_instance;
}
public function get($sbas_id,$record_id, $canPrev)
{
cache_databox::refresh($sbas_id);
return $this->_c_obj->get(GV_ServerName.'_preview_'.$sbas_id.'_'.$record_id.'_'.($canPrev ? '1':'0'));
}
public function set($sbas_id,$record_id, $canPrev, $value)
{
return $this->_c_obj->set(GV_ServerName.'_preview_'.$sbas_id.'_'.$record_id.'_'.($canPrev ? '1':'0'),$value);
}
public function delete($sbas_id,$record_id,$update_distant_boxes = true)
{
$this->_c_obj->delete(GV_ServerName.'_preview_'.$sbas_id.'_'.$record_id.'_0');
$this->_c_obj->delete(GV_ServerName.'_preview_'.$sbas_id.'_'.$record_id.'_1');
if($update_distant_boxes)
cache_databox::update($sbas_id,'record',$record_id);
return true;
}
}

56
lib/classes/cache/record.class.php vendored Normal file
View File

@@ -0,0 +1,56 @@
<?php
class cache_record
{
private static $_instance = false;
var $_c_obj = false;
function __construct()
{
$this->_c_obj = cache::getInstance();
}
/**
* @return cache_record
*/
public static function getInstance()
{
if (!(self::$_instance instanceof self))
self::$_instance = new self();
return self::$_instance;
}
public function get($sbas_id,$record_id,$type)
{
cache_databox::refresh($sbas_id);
return $this->_c_obj->get(GV_ServerName.'_'.$sbas_id.'_'.$type.'_'.$record_id);
}
public function set($sbas_id,$record_id,$type,$value)
{
return $this->_c_obj->set(GV_ServerName.'_'.$sbas_id.'_'.$type.'_'.$record_id,$value,14400);
}
/**
* Update Delayed Cache on distant databoxes for other clients
* @param1 $sbas_id : sbas_id of databox
* @param2 $record_id : record_id updated
*/
public function delete($sbas_id,$record_id,$update_distant_boxes = true)
{
$this->_c_obj->delete(GV_ServerName.'_'.$sbas_id.'_caption_'.$record_id);
$this->_c_obj->delete(GV_ServerName.'_'.$sbas_id.'_caption_bounce_'.$record_id);
$this->_c_obj->delete(GV_ServerName.'_'.$sbas_id.'_title_'.$record_id);
if($update_distant_boxes)
cache_databox::update($sbas_id,'record',$record_id);
return true;
}
}

54
lib/classes/cache/status.class.php vendored Normal file
View File

@@ -0,0 +1,54 @@
<?php
class cache_status
{
private static $_instance = false;
var $_c_obj = false;
function __construct()
{
$this->_c_obj = cache::getInstance();
}
/**
* @return cache_status
*/
public static function getInstance()
{
if (!(self::$_instance instanceof self))
self::$_instance = new self();
return self::$_instance;
}
public function get($usr_id)
{
return $this->_c_obj->get(GV_ServerName.'_status_'.$usr_id);
}
public function set($usr_id,$value)
{
$statuspool = array();
if(($tmp = $this->_c_obj->get(GV_ServerName.'_statuspool_')) != false)
$statuspool = array();
$statuspool[] = $usr_id;
if($this->_c_obj->set(GV_ServerName.'_statuspool_',$statuspool))
return $this->_c_obj->set(GV_ServerName.'_status_'.$usr_id,$value);
return false;
}
public function delete($usr_id)
{
return $this->_c_obj->delete(GV_ServerName.'_status_'.$usr_id);
}
}

54
lib/classes/cache/thumbnail.class.php vendored Normal file
View File

@@ -0,0 +1,54 @@
<?php
class cache_thumbnail
{
private static $_instance = false;
private $_c_obj = false;
function __construct()
{
$this->_c_obj = cache::getInstance();
}
/**
* @return cache_thumbnail
*/
public static function getInstance()
{
if (!(self::$_instance instanceof self))
self::$_instance = new self();
return self::$_instance;
}
public function get($sbas_id, $rid, $getPrev)
{
cache_databox::refresh($sbas_id);
return $this->_c_obj->get(GV_ServerName.'_thumbnail_'.$sbas_id.'_'.$rid.'_'.($getPrev ? '1':'0'));
}
public function set($sbas_id, $rid, $getPrev,$value)
{
return $this->_c_obj->set(GV_ServerName.'_thumbnail_'.$sbas_id.'_'.$rid.'_'.($getPrev ? '1':'0'),$value);
}
public function delete($sbas_id, $rid,$update_distant_boxes = true)
{
$this->_c_obj->delete(GV_ServerName.'_thumbnail_'.$sbas_id.'_'.$rid.'_1');
$this->_c_obj->delete(GV_ServerName.'_thumbnail_'.$sbas_id.'_'.$rid.'_0');
if($update_distant_boxes)
cache_databox::update($sbas_id,'record',$rid);
return true;
}
}

49
lib/classes/cache/user.class.php vendored Normal file
View File

@@ -0,0 +1,49 @@
<?php
class cache_user
{
private static $_instance = false;
var $_c_obj = false;
function __construct()
{
$this->_c_obj = cache::getInstance();
}
/**
* @return cache_user
*/
public static function getInstance()
{
if (!(self::$_instance instanceof self))
self::$_instance = new self();
return self::$_instance;
}
public function get($id)
{
return $this->_c_obj->get(GV_ServerName.'_user_'.$id);
}
public function set($id,$value)
{
return $this->_c_obj->set(GV_ServerName.'_user_'.$id,$value);
}
public function delete($id)
{
$cache_basket = cache_basket::getInstance();
$cache_basket->revoke_baskets_usr($id);
return $this->_c_obj->delete(GV_ServerName.'_user_'.$id);
}
}