issue 2662 trash, widget, session, trackback, spamfilter, tag

git-svn-id: http://xe-core.googlecode.com/svn/branches/maserati@12260 201d5d3c-b55e-5fd7-737f-ddc643e51545
This commit is contained in:
ovclas 2012-11-20 03:01:32 +00:00
parent e1a22ca6f0
commit 5219a360c6
31 changed files with 3465 additions and 3173 deletions

View file

@ -1,26 +1,28 @@
<?php
/**
* @class sessionAdminController
* @author NHN (developers@xpressengine.com)
* @brief The admin controller class of the session module
**/
/**
* @class sessionAdminController
* @author NHN (developers@xpressengine.com)
* @brief The admin controller class of the session module
*/
class sessionAdminController extends session
{
/**
* @brief Initialization
*/
function init()
{
}
class sessionAdminController extends session {
/**
* @brief The action to clean up the Derby session
*/
function procSessionAdminClear()
{
$oSessionController = &getController('session');
$oSessionController->gc(0);
/**
* @brief Initialization
**/
function init() {
}
/**
* @brief The action to clean up the Derby session
**/
function procSessionAdminClear() {
$oSessionController = &getController('session');
$oSessionController->gc(0);
$this->add('result',Context::getLang('session_cleared'));
}
}
?>
$this->add('result',Context::getLang('session_cleared'));
}
}
/* End of file session.admin.controller.php */
/* Location: ./modules/session/session.admin.controller.php */

View file

@ -1,26 +1,27 @@
<?php
/**
* @class sessionAdminView
* @author NHN (developers@xpressengine.com)
* @brief The admin view class of the session module
**/
/**
* @class sessionAdminView
* @author NHN (developers@xpressengine.com)
* @brief The admin view class of the session module
*/
class sessionAdminView extends session
{
/**
* @brief Initialization
*/
function init()
{
}
class sessionAdminView extends session {
/**
* @brief Initialization
**/
function init() {
}
/**
* @brief Configure
**/
function dispSessionAdminIndex() {
// Set the template file
$this->setTemplatePath($this->module_path.'tpl');
$this->setTemplateFile('index');
}
}
?>
/**
* @brief Configure
*/
function dispSessionAdminIndex()
{
// Set the template file
$this->setTemplatePath($this->module_path.'tpl');
$this->setTemplateFile('index');
}
}
/* End of file session.admin.view.php */
/* Location: ./modules/session/session.admin.view.php */

View file

@ -1,81 +1,88 @@
<?php
/**
* @class session
* @author NHN (developers@xpressengine.com)
* @brief session module's high class
* @version 0.1
*
* The session management class
**/
/**
* @class session
* @author NHN (developers@xpressengine.com)
* @brief session module's high class
* @version 0.1
*
* The session management class
*/
class session extends ModuleObject
{
var $lifetime = 18000;
var $session_started = false;
class session extends ModuleObject {
function session()
{
if(Context::isInstalled()) $this->session_started= true;
}
var $lifetime = 18000;
var $session_started = false;
/**
* @brief Additional tasks required to accomplish during the installation
*/
function moduleInstall()
{
$oDB = &DB::getInstance();
$oDB->addIndex("session","idx_session_update_mid", array("member_srl","last_update","cur_mid"));
function session() {
if(Context::isInstalled()) $this->session_started= true;
}
return new Object();
}
/**
* @brief Additional tasks required to accomplish during the installation
**/
function moduleInstall() {
$oDB = &DB::getInstance();
$oDB->addIndex("session","idx_session_update_mid", array("member_srl","last_update","cur_mid"));
/**
* @brief A method to check if the installation has been successful
*/
function checkUpdate()
{
$oDB = &DB::getInstance();
if(!$oDB->isTableExists('session')) return true;
if(!$oDB->isColumnExists("session","cur_mid")) return true;
if(!$oDB->isIndexExists("session","idx_session_update_mid")) return true;
return false;
}
return new Object();
}
/**
* @brief Execute update
*/
function moduleUpdate()
{
$oDB = &DB::getInstance();
$oModuleModel = &getModel('module');
/**
* @brief A method to check if the installation has been successful
**/
function checkUpdate() {
$oDB = &DB::getInstance();
if(!$oDB->isTableExists('session')) return true;
if(!$oDB->isColumnExists("session","cur_mid")) return true;
if(!$oDB->isIndexExists("session","idx_session_update_mid")) return true;
return false;
}
if(!$oDB->isTableExists('session')) $oDB->createTableByXmlFile($this->module_path.'schemas/session.xml');
/**
* @brief Execute update
**/
function moduleUpdate() {
$oDB = &DB::getInstance();
$oModuleModel = &getModel('module');
if(!$oDB->isTableExists('session')) $oDB->createTableByXmlFile($this->module_path.'schemas/session.xml');
if(!$oDB->isColumnExists("session","cur_mid")) $oDB->addColumn('session',"cur_mid","varchar",128);
if(!$oDB->isColumnExists("session","cur_mid")) $oDB->addColumn('session',"cur_mid","varchar",128);
if(!$oDB->isIndexExists("session","idx_session_update_mid")) $oDB->addIndex("session","idx_session_update_mid", array("member_srl","last_update","cur_mid"));
}
if(!$oDB->isIndexExists("session","idx_session_update_mid")) $oDB->addIndex("session","idx_session_update_mid", array("member_srl","last_update","cur_mid"));
}
/**
* @brief session string decode
*/
function unSerializeSession($val)
{
$vars = preg_split('/([a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff^|]*)\|/', $val,-1,PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE);
for($i=0; $vars[$i]; $i++) $result[$vars[$i++]] = unserialize($vars[$i]);
return $result;
}
/**
* @brief session string decode
**/
function unSerializeSession($val) {
$vars = preg_split('/([a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff^|]*)\|/', $val,-1,PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE);
for($i=0; $vars[$i]; $i++) $result[$vars[$i++]] = unserialize($vars[$i]);
return $result;
}
/**
* @brief session string encode
*/
function serializeSession($data)
{
if(!count($data)) return;
/**
* @brief session string encode
**/
function serializeSession($data) {
if(!count($data)) return;
$str = '';
foreach($data as $key => $val) $str .= $key.'|'.serialize($val);
return substr($str, 0, strlen($str)-1).'}';
}
$str = '';
foreach($data as $key => $val) $str .= $key.'|'.serialize($val);
return substr($str, 0, strlen($str)-1).'}';
}
/**
* @brief Re-generate the cache file
**/
function recompileCache() {
}
}
?>
/**
* @brief Re-generate the cache file
*/
function recompileCache()
{
}
}
/* End of file session.class.php */
/* Location: ./modules/session/session.class.php */

View file

@ -1,128 +1,151 @@
<?php
/**
* @class sessionController
* @author NHN (developers@xpressengine.com)
* @brief The controller class of the session module
**/
/**
* @class sessionController
* @author NHN (developers@xpressengine.com)
* @brief The controller class of the session module
*/
class sessionController extends session
{
/**
* @brief Initialization
*/
function init()
{
}
class sessionController extends session {
function open()
{
return true;
}
/**
* @brief Initialization
**/
function init() {
}
function close()
{
return true;
}
function open() {
return true;
}
function write($session_key, $val)
{
if(!$session_key || !$this->session_started) return;
$oCacheHandler = &CacheHandler::getInstance('object');
if($oCacheHandler->isSupport())
{
$cache_key = 'object:'.$session_key;
$cache_vars = $oCacheHandler->get($cache_key);
}
function close() {
return true;
}
$args->session_key = $session_key;
if($cache_vars) $session_info = $cache_vars;
else
{
$output = executeQuery('session.getSession', $args);
$session_info = $output->data;
}
//if ip has changed delete the session from cache and db
if($session_info->session_key == $session_key && $session_info->ipaddress != $_SERVER['REMOTE_ADDR'])
{
if($oCacheHandler->isSupport()) $oCacheHandler->delete($cache_key);
executeQuery('session.deleteSession', $args);
return true;
}
function write($session_key, $val) {
if(!$session_key || !$this->session_started) return;
$oCacheHandler = &CacheHandler::getInstance('object');
if($oCacheHandler->isSupport()) {
$cache_key = 'object:'.$session_key;
$cache_vars = $oCacheHandler->get($cache_key);
}
$args->session_key = $session_key;
if($cache_vars) $session_info = $cache_vars;
else {
$output = executeQuery('session.getSession', $args);
$session_info = $output->data;
}
//if ip has changed delete the session from cache and db
if($session_info->session_key == $session_key && $session_info->ipaddress != $_SERVER['REMOTE_ADDR']) {
if($oCacheHandler->isSupport()) $oCacheHandler->delete($cache_key);
executeQuery('session.deleteSession', $args);
return true;
}
$args->expired = date("YmdHis", time()+$this->lifetime);
$args->val = $val;
$args->cur_mid = Context::get('mid');
if(!$args->cur_mid)
{
$module_info = Context::get('current_module_info');
$args->cur_mid = $module_info->mid;
}
$args->expired = date("YmdHis", time()+$this->lifetime);
$args->val = $val;
$args->cur_mid = Context::get('mid');
if(!$args->cur_mid) {
$module_info = Context::get('current_module_info');
$args->cur_mid = $module_info->mid;
}
if(Context::get('is_logged'))
{
$logged_info = Context::get('logged_info');
$args->member_srl = $logged_info->member_srl;
}
else
{
$args->member_srl = 0;
}
$args->ipaddress = $_SERVER['REMOTE_ADDR'];
$args->last_update = date("YmdHis", time());
$diff = $args->last_update - $cache_vars->last_update;
//verify if session values have changed
if($val == $cache_vars->val)
{
// if more than 5 minutes passed than modify the db session also
if($diff > 300)
{
//put session into cache
if($oCacheHandler->isSupport())
{
$cache_key = 'object:'.$session_key;
$oCacheHandler->put($cache_key,$args);
}
//put session into db
if($session_info->session_key) $output = executeQuery('session.updateSession', $args);
}
else
{
//put session into cache
if($oCacheHandler->isSupport())
{
$cache_key = 'object:'.$session_key;
$oCacheHandler->put($cache_key,$args);
}
}
}
else
{
//put session into cache
if($oCacheHandler->isSupport())
{
$cache_key = 'object:'.$session_key;
$oCacheHandler->put($cache_key,$args);
}
//put session into db
if($session_info->session_key) $output = executeQuery('session.updateSession', $args);
else $output = executeQuery('session.insertSession', $args);
}
if(Context::get('is_logged')) {
$logged_info = Context::get('logged_info');
$args->member_srl = $logged_info->member_srl;
} else {
$args->member_srl = 0;
}
$args->ipaddress = $_SERVER['REMOTE_ADDR'];
$args->last_update = date("YmdHis", time());
$diff = $args->last_update - $cache_vars->last_update;
//verify if session values have changed
if($val == $cache_vars->val){
// if more than 5 minutes passed than modify the db session also
if($diff > 300){
//put session into cache
if($oCacheHandler->isSupport()) {
$cache_key = 'object:'.$session_key;
$oCacheHandler->put($cache_key,$args);
}
//put session into db
if($session_info->session_key) $output = executeQuery('session.updateSession', $args);
}
else {
//put session into cache
if($oCacheHandler->isSupport()) {
$cache_key = 'object:'.$session_key;
$oCacheHandler->put($cache_key,$args);
}
}
}
else {
//put session into cache
if($oCacheHandler->isSupport()) {
$cache_key = 'object:'.$session_key;
$oCacheHandler->put($cache_key,$args);
}
//put session into db
if($session_info->session_key) $output = executeQuery('session.updateSession', $args);
else $output = executeQuery('session.insertSession', $args);
}
return true;
}
return true;
}
function destroy($session_key) {
if(!$session_key || !$this->session_started) return;
//remove session from cache
$oCacheHandler = &CacheHandler::getInstance('object');
if($oCacheHandler->isSupport()) {
$cache_key = 'object:'.$session_key;
$oCacheHandler->delete($cache_key);
}
//remove session from db
$args->session_key = $session_key;
executeQuery('session.deleteSession', $args);
return true;
}
function destroy($session_key)
{
if(!$session_key || !$this->session_started) return;
//remove session from cache
$oCacheHandler = &CacheHandler::getInstance('object');
if($oCacheHandler->isSupport())
{
$cache_key = 'object:'.$session_key;
$oCacheHandler->delete($cache_key);
}
//remove session from db
$args->session_key = $session_key;
executeQuery('session.deleteSession', $args);
return true;
}
function gc($maxlifetime) {
if(!$this->session_started) return;
$expired_sessions = executeQueryArray('session.getExpiredSessions');
if($expired_session){
foreach ($expired_sessions as $session_key){
//remove session from cache
$oCacheHandler = &CacheHandler::getInstance('object');
if($oCacheHandler->isSupport()) {
$cache_key = 'object:'.$session_key;
$oCacheHandler->delete($cache_key);
}
}
}
executeQuery('session.gcSession');
return true;
}
}
?>
function gc($maxlifetime)
{
if(!$this->session_started) return;
$expired_sessions = executeQueryArray('session.getExpiredSessions');
if($expired_session)
{
foreach ($expired_sessions as $session_key)
{
//remove session from cache
$oCacheHandler = &CacheHandler::getInstance('object');
if($oCacheHandler->isSupport())
{
$cache_key = 'object:'.$session_key;
$oCacheHandler->delete($cache_key);
}
}
}
executeQuery('session.gcSession');
return true;
}
}
/* End of file session.controller.php */
/* Location: ./modules/session/session.controller.php */

View file

@ -1,100 +1,113 @@
<?php
/**
* @class sessionModel
* @author NHN (developers@xpressengine.com)
* @brief The Model class of the session module
**/
/**
* @class sessionModel
* @author NHN (developers@xpressengine.com)
* @brief The Model class of the session module
*/
class sessionModel extends session
{
/**
* @brief Initialization
*/
function init()
{
}
class sessionModel extends session {
function getLifeTime()
{
return $this->lifetime;
}
/**
* @brief Initialization
**/
function init() {
}
function read($session_key)
{
if(!$session_key || !$this->session_started) return;
function getLifeTime() {
return $this->lifetime;
}
function read($session_key) {
if(!$session_key || !$this->session_started) return;
$oCacheHandler = &CacheHandler::getInstance('object');
if($oCacheHandler->isSupport()){
$cache_key = 'object:'.$session_key;
$output->data = $oCacheHandler->get($cache_key);
$oCacheHandler = &CacheHandler::getInstance('object');
if($oCacheHandler->isSupport())
{
$cache_key = 'object:'.$session_key;
$output->data = $oCacheHandler->get($cache_key);
}
if(!$output->data)
{
$args->session_key = $session_key;
$columnList = array('session_key', 'cur_mid', 'val');
$output = executeQuery('session.getSession', $args, $columnList);
// Confirm there is a table created if read error occurs
if(!$output->toBool())
{
$oDB = &DB::getInstance();
if(!$oDB->isTableExists('session')) $oDB->createTableByXmlFile($this->module_path.'schemas/session.xml');
if(!$oDB->isColumnExists("session","cur_mid")) $oDB->addColumn('session',"cur_mid","varchar",128);
$output = executeQuery('session.getSession', $args);
}
if(!$output->data) {
$args->session_key = $session_key;
$columnList = array('session_key', 'cur_mid', 'val');
$output = executeQuery('session.getSession', $args, $columnList);
// Confirm there is a table created if read error occurs
if(!$output->toBool()) {
$oDB = &DB::getInstance();
if(!$oDB->isTableExists('session')) $oDB->createTableByXmlFile($this->module_path.'schemas/session.xml');
if(!$oDB->isColumnExists("session","cur_mid")) $oDB->addColumn('session',"cur_mid","varchar",128);
$output = executeQuery('session.getSession', $args);
}
// Check if there is a table created in case there is no "cur_mid" value in the sessions information
if(!isset($output->data->cur_mid)) {
$oDB = &DB::getInstance();
if(!$oDB->isColumnExists("session","cur_mid")) $oDB->addColumn('session',"cur_mid","varchar",128);
}
// Check if there is a table created in case there is no "cur_mid" value in the sessions information
if(!isset($output->data->cur_mid))
{
$oDB = &DB::getInstance();
if(!$oDB->isColumnExists("session","cur_mid")) $oDB->addColumn('session',"cur_mid","varchar",128);
}
return $output->data->val;
}
}
return $output->data->val;
}
/**
* @brief Get a list of currently connected users
* Requires "object" argument because multiple arguments are expected
* limit_count : the number of objects
* page : the page number
* period_time: "n" specifies the time range in minutes since the last update
* mid: a user who belong to a specified mid
**/
function getLoggedMembers($args) {
if(!$args->site_srl) {
$site_module_info = Context::get('site_module_info');
$args->site_srl = (int)$site_module_info->site_srl;
}
if(!$args->list_count) $args->list_count = 20;
if(!$args->page) $args->page = 1;
if(!$args->period_time) $args->period_time = 3;
$args->last_update = date("YmdHis", time() - $args->period_time*60);
/**
* @brief Get a list of currently connected users
* Requires "object" argument because multiple arguments are expected
* limit_count : the number of objects
* page : the page number
* period_time: "n" specifies the time range in minutes since the last update
* mid: a user who belong to a specified mid
*/
function getLoggedMembers($args)
{
if(!$args->site_srl)
{
$site_module_info = Context::get('site_module_info');
$args->site_srl = (int)$site_module_info->site_srl;
}
if(!$args->list_count) $args->list_count = 20;
if(!$args->page) $args->page = 1;
if(!$args->period_time) $args->period_time = 3;
$args->last_update = date("YmdHis", time() - $args->period_time*60);
$output = executeQueryArray('session.getLoggedMembers', $args);
if(!$output->toBool()) return $output;
$output = executeQueryArray('session.getLoggedMembers', $args);
if(!$output->toBool()) return $output;
$member_srls = array();
if(count($output->data)) {
foreach($output->data as $key => $val) {
$member_srls[$key] = $val->member_srl;
$member_keys[$val->member_srl] = $key;
}
}
$member_srls = array();
if(count($output->data))
{
foreach($output->data as $key => $val)
{
$member_srls[$key] = $val->member_srl;
$member_keys[$val->member_srl] = $key;
}
}
if(Context::get('is_logged')) {
$logged_info = Context::get('logged_info');
if(!in_array($logged_info->member_srl, $member_srls)) {
$member_srls[0] = $logged_info->member_srl;
$member_keys[$logged_info->member_srl] = 0;
}
}
if(Context::get('is_logged'))
{
$logged_info = Context::get('logged_info');
if(!in_array($logged_info->member_srl, $member_srls))
{
$member_srls[0] = $logged_info->member_srl;
$member_keys[$logged_info->member_srl] = 0;
}
}
if(!count($member_srls)) return $output;
if(!count($member_srls)) return $output;
$member_args->member_srl = implode(',',$member_srls);
$member_output = executeQueryArray('member.getMembers', $member_args);
if($member_output->data) {
foreach($member_output->data as $key => $val) {
$output->data[$member_keys[$val->member_srl]] = $val;
}
}
$member_args->member_srl = implode(',',$member_srls);
$member_output = executeQueryArray('member.getMembers', $member_args);
if($member_output->data)
{
foreach($member_output->data as $key => $val)
{
$output->data[$member_keys[$val->member_srl]] = $val;
}
}
return $output;
}
}
?>
return $output;
}
}
/* End of file session.model.php */
/* Location: ./modules/session/session.model.php */