Removed redundant lib2/cookie.inc.php, changed all uses to new Cookie service. Except lib1 - should be phased out anyway.
This commit is contained in:
@ -90,11 +90,8 @@ class Cookie
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function set($name, $value, $default=null)
|
private function setSession($name, $value, $default = null)
|
||||||
{
|
{
|
||||||
global $opt;
|
|
||||||
|
|
||||||
if ($opt['session']['mode'] == SAVE_SESSION) {
|
|
||||||
if (!isset($_SESSION[$name]) || $_SESSION[$name] != $value) {
|
if (!isset($_SESSION[$name]) || $_SESSION[$name] != $value) {
|
||||||
if ($value == $default) {
|
if ($value == $default) {
|
||||||
if (isset($_SESSION[$name])) {
|
if (isset($_SESSION[$name])) {
|
||||||
@ -107,7 +104,10 @@ class Cookie
|
|||||||
$this->changed = true;
|
$this->changed = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
|
|
||||||
|
private function setCookie($name, $value, $default = null)
|
||||||
|
{
|
||||||
// Store cookie value in internal array. OcSmarty will call this->header()
|
// Store cookie value in internal array. OcSmarty will call this->header()
|
||||||
// to actually set the cookie.
|
// to actually set the cookie.
|
||||||
|
|
||||||
@ -123,9 +123,19 @@ class Cookie
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function set($name, $value, $default = null)
|
||||||
|
{
|
||||||
|
global $opt;
|
||||||
|
|
||||||
|
if ($opt['session']['mode'] == SAVE_SESSION) {
|
||||||
|
$this->setSession($name, $value, $default);
|
||||||
|
} else {
|
||||||
|
$this->setCookie($name, $value, $default);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function get($name, $default='')
|
public function get($name, $default = '')
|
||||||
{
|
{
|
||||||
global $opt;
|
global $opt;
|
||||||
|
|
||||||
@ -147,7 +157,7 @@ class Cookie
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function un_set($name)
|
public function un_set($name)
|
||||||
{
|
{
|
||||||
global $opt;
|
global $opt;
|
||||||
|
|
||||||
|
@ -192,16 +192,12 @@ function set_domain()
|
|||||||
|
|
||||||
function set_language()
|
function set_language()
|
||||||
{
|
{
|
||||||
global $opt, $cookie;
|
global $opt;
|
||||||
|
|
||||||
if ($cookie === null) {
|
|
||||||
$cookie = new cookie2();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isset($_REQUEST['locale']))
|
if (isset($_REQUEST['locale']))
|
||||||
$opt['template']['locale'] = strtoupper($_REQUEST['locale']);
|
$opt['template']['locale'] = strtoupper($_REQUEST['locale']);
|
||||||
else
|
else
|
||||||
$opt['template']['locale'] = strtoupper($cookie->get('locale', $opt['template']['default']['locale']));
|
$opt['template']['locale'] = strtoupper($GLOBALS['container']->get('ocde.cookie')->get('locale', $opt['template']['default']['locale']));
|
||||||
|
|
||||||
if (isset($opt['template']['locale']) && $opt['template']['locale'] != '')
|
if (isset($opt['template']['locale']) && $opt['template']['locale'] != '')
|
||||||
{
|
{
|
||||||
@ -215,7 +211,7 @@ function set_language()
|
|||||||
else
|
else
|
||||||
$opt['template']['locale'] = $opt['template']['default']['locale'];
|
$opt['template']['locale'] = $opt['template']['default']['locale'];
|
||||||
|
|
||||||
$cookie->set('locale', $opt['template']['locale'], $opt['template']['default']['locale']);
|
$GLOBALS['container']->get('ocde.cookie')->set('locale', $opt['template']['locale'], $opt['template']['default']['locale']);
|
||||||
|
|
||||||
bindtextdomain('messages', $GLOBALS['container']->get('ocde.config')->getBaseDir() . '/cache2/translate');
|
bindtextdomain('messages', $GLOBALS['container']->get('ocde.config')->getBaseDir() . '/cache2/translate');
|
||||||
|
|
||||||
@ -235,10 +231,9 @@ function set_language()
|
|||||||
|
|
||||||
function set_usercountry()
|
function set_usercountry()
|
||||||
{
|
{
|
||||||
global $cookie;
|
if (isset($_REQUEST['usercountry'])) {
|
||||||
|
$GLOBALS['container']->get('ocde.cookie')->set('usercountry', $_REQUEST['usercountry']);
|
||||||
if (isset($_REQUEST['usercountry']))
|
}
|
||||||
$cookie->set('usercountry', $_REQUEST['usercountry']);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function set_timezone()
|
function set_timezone()
|
||||||
|
@ -1,241 +0,0 @@
|
|||||||
<?php
|
|
||||||
/***************************************************************************
|
|
||||||
* For license information see doc/license.txt
|
|
||||||
*
|
|
||||||
* Unicode Reminder メモ
|
|
||||||
*
|
|
||||||
* Cookie handling
|
|
||||||
* See doc/cookies.txt for more information in cookies.
|
|
||||||
***************************************************************************/
|
|
||||||
|
|
||||||
class cookie2
|
|
||||||
{
|
|
||||||
var $changed = false;
|
|
||||||
var $values = array();
|
|
||||||
var $session_initalized = false;
|
|
||||||
|
|
||||||
function __construct()
|
|
||||||
{
|
|
||||||
global $opt;
|
|
||||||
|
|
||||||
if ($opt['session']['mode'] == SAVE_SESSION)
|
|
||||||
{
|
|
||||||
if (isset($_REQUEST['SESSION']) && $_REQUEST['SESSION'] != '')
|
|
||||||
{
|
|
||||||
$this->init_session();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (isset($_COOKIE[$opt['session']['cookiename'] . 'data']))
|
|
||||||
{
|
|
||||||
//get the cookievars-array
|
|
||||||
$decoded = base64_decode($_COOKIE[$opt['session']['cookiename'] . 'data']);
|
|
||||||
|
|
||||||
if ($decoded !== false)
|
|
||||||
{
|
|
||||||
$this->values = @unserialize($decoded);
|
|
||||||
if (!is_array($this->values))
|
|
||||||
$this->values = array();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
$this->values = array();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function init_session()
|
|
||||||
{
|
|
||||||
global $opt;
|
|
||||||
|
|
||||||
if ($this->session_initalized != true)
|
|
||||||
{
|
|
||||||
session_name('SESSION');
|
|
||||||
session_set_cookie_params($opt['session']['expire']['cookie'], $opt['session']['path'], $opt['session']['domain']);
|
|
||||||
session_start();
|
|
||||||
|
|
||||||
if ($opt['session']['check_referer'])
|
|
||||||
if (isset($_SERVER['REFERER']))
|
|
||||||
if (strtolower(substr($_SERVER['REFERER'], 0, strlen($opt['page']['absolute_url']))) != strtolower($opt['page']['absolute_url']))
|
|
||||||
$this->createNewSession();
|
|
||||||
|
|
||||||
if ((isset($_GET['SESSION']) || isset($_POST['SESSION'])) && count($_SESSION) > 0)
|
|
||||||
{
|
|
||||||
// comapre and set timestamp
|
|
||||||
if (isset($_SESSION['lastcall']))
|
|
||||||
{
|
|
||||||
if (abs(time() - $_SESSION['lastcall']) > $opt['session']['expire']['url'])
|
|
||||||
{
|
|
||||||
$this->createNewSession();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$_SESSION['lastcall'] = time();
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->session_initalized = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function createNewSession()
|
|
||||||
{
|
|
||||||
session_regenerate_id();
|
|
||||||
$locale = isset($_SESSION['locale']) ? $_SESSION['locale'] : '';
|
|
||||||
foreach ($_SESSION AS $k => $v)
|
|
||||||
{
|
|
||||||
unset($_SESSION[$k]);
|
|
||||||
}
|
|
||||||
if ($locale != '')
|
|
||||||
$_SESSION['locale'] = $locale;
|
|
||||||
}
|
|
||||||
|
|
||||||
function set($name, $value, $default=null)
|
|
||||||
{
|
|
||||||
global $opt;
|
|
||||||
|
|
||||||
if ($opt['session']['mode'] == SAVE_SESSION)
|
|
||||||
{
|
|
||||||
if (!isset($_SESSION[$name]) || $_SESSION[$name] != $value)
|
|
||||||
{
|
|
||||||
if ($value == $default)
|
|
||||||
{
|
|
||||||
if (isset($_SESSION[$name]))
|
|
||||||
{
|
|
||||||
unset($_SESSION[$name]);
|
|
||||||
$this->changed = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
$this->init_session();
|
|
||||||
$_SESSION[$name] = $value;
|
|
||||||
$this->changed = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// Store cookie value in internal array. OcSmarty will call this->header()
|
|
||||||
// to actually set the cookie.
|
|
||||||
|
|
||||||
if (!isset($this->values[$name]) || $this->values[$name] != $value)
|
|
||||||
{
|
|
||||||
if ($value == $default)
|
|
||||||
{
|
|
||||||
if (isset($this->values[$name]))
|
|
||||||
{
|
|
||||||
unset($this->values[$name]);
|
|
||||||
$this->changed = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
$this->values[$name] = $value;
|
|
||||||
$this->changed = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function get($name, $default='')
|
|
||||||
{
|
|
||||||
global $opt;
|
|
||||||
|
|
||||||
if ($opt['session']['mode'] == SAVE_SESSION)
|
|
||||||
{
|
|
||||||
return isset($_SESSION[$name]) ? $_SESSION[$name] : $default;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return isset($this->values[$name]) ? $this->values[$name] : $default;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function is_set($name)
|
|
||||||
{
|
|
||||||
global $opt;
|
|
||||||
|
|
||||||
if ($opt['session']['mode'] == SAVE_SESSION)
|
|
||||||
{
|
|
||||||
return isset($_SESSION[$name]);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return isset($this->values[$name]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function un_set($name)
|
|
||||||
{
|
|
||||||
global $opt;
|
|
||||||
|
|
||||||
if ($opt['session']['mode'] == SAVE_SESSION)
|
|
||||||
{
|
|
||||||
if (isset($_SESSION[$name]))
|
|
||||||
{
|
|
||||||
unset($_SESSION[$name]);
|
|
||||||
$this->changed = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (isset($this->values[$name]))
|
|
||||||
{
|
|
||||||
unset($this->values[$name]);
|
|
||||||
$this->changed = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function header()
|
|
||||||
{
|
|
||||||
global $opt;
|
|
||||||
|
|
||||||
if ($opt['session']['mode'] == SAVE_SESSION)
|
|
||||||
{
|
|
||||||
// is autmatically sent
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if ($this->changed == true)
|
|
||||||
{
|
|
||||||
if (count($this->values) == 0)
|
|
||||||
setcookie($opt['session']['cookiename'] . 'data', false, time() + 31536000, $opt['session']['path'], $opt['session']['domain'], 0);
|
|
||||||
else
|
|
||||||
setcookie($opt['session']['cookiename'] . 'data', base64_encode(serialize($this->values)), time() + 31536000, $opt['session']['path'], $opt['session']['domain'], 0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function debug()
|
|
||||||
{
|
|
||||||
global $opt;
|
|
||||||
if ($opt['session']['mode'] == SAVE_SESSION)
|
|
||||||
{
|
|
||||||
print_r($_SESSION);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
print_r($this->values);
|
|
||||||
}
|
|
||||||
exit;
|
|
||||||
}
|
|
||||||
|
|
||||||
function close()
|
|
||||||
{
|
|
||||||
global $opt;
|
|
||||||
if ($opt['session']['mode'] == SAVE_SESSION)
|
|
||||||
{
|
|
||||||
if ($this->session_initalized == true)
|
|
||||||
{
|
|
||||||
if (count($_SESSION) == 0)
|
|
||||||
@session_destroy();
|
|
||||||
else
|
|
||||||
session_write_close();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -9,15 +9,13 @@ function createTranslate($backtrace_level = 0)
|
|||||||
{
|
{
|
||||||
$access = new translateAccess();
|
$access = new translateAccess();
|
||||||
|
|
||||||
if ($access->hasAccess())
|
if ($access->hasAccess()) {
|
||||||
{
|
$translateMode = $GLOBALS['container']->get('ocde.cookie')->get('translate_mode');
|
||||||
global $cookie;
|
|
||||||
|
|
||||||
$translateMode = $cookie->get('translate_mode');
|
if ($translateMode) {
|
||||||
|
|
||||||
if ($translateMode)
|
|
||||||
return new translateEdit($translateMode == 'all', $backtrace_level);
|
return new translateEdit($translateMode == 'all', $backtrace_level);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return new translate();
|
return new translate();
|
||||||
}
|
}
|
||||||
|
@ -100,7 +100,7 @@ use \OpencachingDE\Conversions\Coordinates;
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
$bCookieQueryid = true;
|
$bCookieQueryid = true;
|
||||||
$queryid = $cookie->get('lastqueryid',false);
|
$queryid = $GLOBALS['container']->get('ocde.cookie')->get('lastqueryid',false);
|
||||||
if ($queryid === false ||
|
if ($queryid === false ||
|
||||||
sql_value("SELECT COUNT(*) FROM `queries` WHERE id='&1'", 0, $queryid) == 0)
|
sql_value("SELECT COUNT(*) FROM `queries` WHERE id='&1'", 0, $queryid) == 0)
|
||||||
{
|
{
|
||||||
@ -455,7 +455,7 @@ use \OpencachingDE\Conversions\Coordinates;
|
|||||||
sql("INSERT INTO `queries` (`user_id`, `options`, `last_queried`) VALUES (0, '&1', NOW())", serialize($options));
|
sql("INSERT INTO `queries` (`user_id`, `options`, `last_queried`) VALUES (0, '&1', NOW())", serialize($options));
|
||||||
$options['queryid'] = sql_insert_id();
|
$options['queryid'] = sql_insert_id();
|
||||||
}
|
}
|
||||||
$cookie->set('lastqueryid', $options['queryid']);
|
$GLOBALS['container']->get('ocde.cookie')->set('lastqueryid', $options['queryid']);
|
||||||
}
|
}
|
||||||
|
|
||||||
// remove old queries (after 1 hour without use);
|
// remove old queries (after 1 hour without use);
|
||||||
|
@ -124,11 +124,11 @@
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
if ($action == 'quicknone')
|
if ($action == 'quicknone')
|
||||||
$cookie->un_set('translate_mode');
|
$GLOBALS['container']->get('ocde.cookie')->un_set('translate_mode');
|
||||||
else if ($action == 'quicknew')
|
else if ($action == 'quicknew')
|
||||||
$cookie->set('translate_mode', 'new');
|
$GLOBALS['container']->get('ocde.cookie')->set('translate_mode', 'new');
|
||||||
else if ($action == 'quickall')
|
else if ($action == 'quickall')
|
||||||
$cookie->set('translate_mode', 'all');
|
$GLOBALS['container']->get('ocde.cookie')->set('translate_mode', 'all');
|
||||||
|
|
||||||
$action = 'listnew';
|
$action = 'listnew';
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user