Page Menu
Home
In-Portal Phabricator
Search
Configure Global Search
Log In
Files
F773386
in-portal
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Sun, Feb 2, 9:53 AM
Size
63 KB
Mime Type
text/x-diff
Expires
Tue, Feb 4, 9:53 AM (2 h, 5 m)
Engine
blob
Format
Raw Data
Handle
556616
Attached To
rINP In-Portal
in-portal
View Options
Index: trunk/core/kernel/event_manager.php
===================================================================
--- trunk/core/kernel/event_manager.php (revision 938)
+++ trunk/core/kernel/event_manager.php (revision 939)
@@ -1,211 +1,164 @@
<?php
define('hBEFORE',1);
define('hAFTER',2);
class kEventManager extends kDBBase {
/**
* Cache of QueryString parameters
* from config, that are represented
* in enviroment variable
*
- * @var unknown_type
+ * @var Array
*/
var $queryMaps=Array();
/**
* Build events registred for
* pseudo classes. key - pseudo class
* value - event name
*
* @var Array
* @access private
*/
var $buildEvents=Array();
/**
* Holds before hooks
* key - prefix.event (to link to)
* value - hooked event info
*
* @var Array
* @access private
*/
var $beforeHooks=Array();
/**
* Holds after hooks
* key - prefix.event (to link to)
* value - hooked event info
*
* @var Array
* @access private
*/
var $afterHooks=Array();
+ /**
+ * Set's new enviroment parameter mappings
+ * between their names as application vars
+ *
+ * @param Array $new_query_maps
+ * @access public
+ */
+ function setQueryMaps($new_query_maps)
+ {
+ $this->queryMaps=$new_query_maps;
+ }
+
function registerBuildEvent($pseudo_class,$build_event_name)
{
$this->buildEvents[$pseudo_class]=$build_event_name;
}
/**
* Returns build event by pseudo class
* name if any defined in config
*
* @param string $pseudo_class
* @return kEvent
* @access public
*/
function &getBuildEvent($pseudo_class)
{
if( !isset($this->buildEvents[$pseudo_class]) ) return false;
$event = new kEvent();
$event->Name=$this->buildEvents[$pseudo_class];
$event->MasterEvent=null;
return $event;
}
/**
* Allows to process any type of event
*
* @param kEvent $event
* @access public
*/
function HandleEvent(&$event)
{
$event_handler =& $this->Application->recallObject($event->Prefix.'_EventHandler');
$event_handler->processEvent(&$event);
}
- function getTemplateName($querystring_template)
- {
- $t_from_post=$this->Application->GetVar('t');
- $t=$t_from_post?$t_from_post:$querystring_template;
- return $t;
- }
-
- /**
- * Process QueryString only, create
- * events, ids, based on config
- * set template name and sid in
- * desired application variables.
- *
- * @access public
- */
- function processQueryString()
- {
- // env=SID:TEMPLATE:m-1-1-1-1:l0-0-0:n-0-0-0:bb-0-0-1-1-1-0
-
- $env_var =& $this->Application->GetVar(ENV_VAR_NAME);
- if($env_var)
- {
- $parts=explode(':',$env_var);
-
- // Save Session ID
- $sid=array_shift($parts);
- if($sid) $this->Application->SetVar('sid',$sid);
-
- // Save Template Name
- $t=$this->getTemplateName( array_shift($parts) );
- if(!$t) $t='index';
- $this->Application->SetVar('t',$t);
-
- if($parts)
- {
- foreach($parts as $mixed_part)
- {
- $mixed_part=explode('-',$mixed_part);
- $prefix_special=array_shift($mixed_part); // l.pick, l
- list($prefix)=explode('.',$prefix_special);
-
- $this->queryMaps[$prefix_special]=$this->Application->getUnitOption($prefix,'QueryString');
- foreach($this->queryMaps[$prefix_special] as $index => $var_name)
- {
- // l_id, l_page, l_bla-bla-bla
- $this->Application->SetVar($prefix_special.'_'.$var_name,$mixed_part[$index-1]);
- }
- }
- }
- }
- else
- {
- $t=$this->getTemplateName('index');
- $this->Application->SetVar('t',$t);
- }
- }
-
-
function ProcessRequest()
{
// 1. get events from $_POST
$events=$this->Application->GetVar('events');
if($events===false) $events=Array();
// 2. if nothing there, then try to find them in $_GET
if($this->queryMaps && !$events)
{
// if we got $_GET type submit (links, not javascript)
foreach($this->queryMaps as $prefix_special => $query_map)
{
$query_map=array_flip($query_map);
if(isset($query_map['event']))
{
$events[$prefix_special]=$this->Application->GetVar($prefix_special.'_event');
}
}
}
//print_pre($events);
- //$t=$this->Application->GetVar('t');
foreach($events as $prefix_special => $event_name)
{
if(!$event_name) continue;
$event = new kEvent();
$event->Name=$event_name;
$event->Prefix_Special=$prefix_special;
$prefix_special=explode('.',$prefix_special);
$event->Prefix=$prefix_special[0];
$event->Special=isset($prefix_special[1])?$prefix_special[1]:'';
$event->redirect=$this->Application->RecallVar('redirect_to');
$this->HandleEvent(&$event);
}
}
function registerHook($hookto_unit, $hookto_event_name, $mode, $do_unit, $do_event_name)
{
}
function processHooks(&$event, $mode)
{
}
/**
* Set's new event for $prefix_special
* passed
*
* @param string $prefix_special
* @param string $event_name
* @access public
*/
function setEvent($prefix_special,$event_name)
{
$actions =& $this->Application->recallObject('kActions');
$actions->Set('events['.$prefix_special.']',$event_name);
}
}
?>
\ No newline at end of file
Property changes on: trunk/core/kernel/event_manager.php
___________________________________________________________________
Modified: cvs2svn:cvs-rev
## -1 +1 ##
-1.2
\ No newline at end of property
+1.3
\ No newline at end of property
Index: trunk/core/kernel/session/session.php
===================================================================
--- trunk/core/kernel/session/session.php (revision 938)
+++ trunk/core/kernel/session/session.php (revision 939)
@@ -1,490 +1,513 @@
<?php
/*
The session works the following way:
1. When a visitor loads a page from the site the script checks if cookies_on varibale has been passed to it as a cookie.
2. If it has been passed, the script tries to get Session ID (SID) from the request:
3. Depending on session mode the script is getting SID differently.
The following modes are available:
smAUTO - Automatic mode: if cookies are on at the client side, the script relays only on cookies and
ignore all other methods of passing SID.
If cookies are off at the client side, the script relays on SID passed through query string
and referal passed by the client. THIS METHOD IS NOT 100% SECURE, as long as attacker may
get SID and substitude referal to gain access to user' session. One of the faults of this method
is that the session is only created when the visitor clicks the first link on the site, so
there is NO session at the first load of the page. (Actually there is a session, but it gets lost
after the first click because we do not use SID in query string while we are not sure if we need it)
smCOOKIES_ONLY - Cookies only: in this mode the script relays solely on cookies passed from the browser
and ignores all other methods. In this mode there is no way to use sessions for clients
without cookies support or cookies support disabled. The cookies are stored with the
full domain name and path to base-directory of script installation.
smGET_ONLY - GET only: the script will not set any cookies and will use only SID passed in
query string using GET, it will also check referal. The script will set SID at the
first load of the page
smCOOKIES_AND_GET - Combined mode: the script will use both cookies and GET right from the start. If client has
cookies enabled, the script will check SID stored in cookie and passed in query string, and will
use this SID only if both cookie and query string matches. However if cookies are disabled on the
client side, the script will work the same way as in GET_ONLY mode.
4. After the script has the SID it tries to load it from the Storage (default is database)
5. If such SID is found in the database, the script checks its expiration time. If session is not expired, it updates
its expiration, and resend the cookie (if applicable to session mode)
6. Then the script loads all the data (session variables) pertaining to the SID.
Usage:
$session =& new Session(smAUTO); //smAUTO is default, you could just leave the brackets empty, or provide another mode
$session->SetCookieDomain('my.domain.com');
$session->SetCookiePath('/myscript');
$session->SetCookieName('my_sid_cookie');
$session->SetGETName('sid');
$session->InitSession();
...
//link output:
echo "<a href='index.php?'". ( $session->NeedQueryString() ? 'sid='.$session->SID : '' ) .">My Link</a>";
*/
//Implements session storage in the database
class SessionStorage extends kDBBase {
var $Expiration;
var $OriginalData=Array();
function StoreSession(&$session)
{
$query = sprintf( "INSERT INTO %sSessions (sid, expire) VALUES (%s, %s)",
TABLE_PREFIX,
$session->SID,
$session->Expiration);
$this->Conn->Query($query);
}
function DeleteSession(&$session)
{
$query = sprintf( "DELETE FROM %sSessions WHERE %s = %s",
TABLE_PREFIX,
'sid',
$session->SID);
$this->Conn->Query($query);
$query = sprintf( "DELETE FROM %sSessionData WHERE %s = %s",
TABLE_PREFIX,
'sid',
$session->SID);
$this->Conn->Query($query);
$this->OriginalData = Array();
}
function UpdateSession(&$session)
{
$query = sprintf( "UPDATE %sSessions SET expire = %s WHERE %s = %s",
TABLE_PREFIX,
$session->Expiration,
'sid',
$session->SID);
$this->Conn->Query($query);
}
function LocateSession($sid)
{
$query = sprintf( "SELECT expire FROM %sSessions WHERE %s = %s",
TABLE_PREFIX,
'sid',
$sid);
$result = $this->Conn->GetOne($query);
if($result===false) return false;
$this->Expiration = $result;
return true;
}
function GetExpiration()
{
return $this->Expiration;
}
function LoadData(&$session)
{
$query = sprintf( "SELECT value,name FROM %sSessionData WHERE %s = %s",
TABLE_PREFIX,
'sid',
$session->SID);
$this->OriginalData = $this->Conn->GetCol($query,'name');
return $this->OriginalData;
}
function SaveData(&$session)
{
$ses_data = $session->Data->GetParams();
$replace = '';
foreach ($ses_data as $key => $value)
{
if ( isset($this->OriginalData[$key]) && $this->OriginalData[$key] == $value)
{
continue; //skip unchanged session data
}
else
{
$replace .= sprintf("(%s, %s, %s),",
$session->SID,
$this->Conn->qstr($key),
$this->Conn->qstr($value));
}
}
$replace = rtrim($replace, ',');
if ($replace != '') {
$query = sprintf( 'REPLACE INTO %sSessionData (sid, name, value) VALUES %s',
TABLE_PREFIX,
$replace);
$this->Conn->Query($query);
}
}
function RemoveFromData(&$session, $var)
{
$query = sprintf( "DELETE FROM %sSessionData WHERE %s = %s AND %s = %s",
TABLE_PREFIX,
'sid',
$session->SID,
'name',
$this->Conn->qstr($var));
$this->Conn->Query($query);
unset($this->OriginalData[$var]);
}
}
define('smAUTO', 1);
define('smCOOKIES_ONLY', 2);
define('smGET_ONLY', 3);
define('smCOOKIES_AND_GET', 4);
class Session extends kBase {
var $Checkers;
var $Mode;
var $GETName = 'sid';
var $CookiesEnabled = true;
var $CookieName = 'sid';
var $CookieDomain;
var $CookiePath;
var $CookieSecure = 0;
var $SessionTimeout = 3600;
var $Expiration;
var $SID;
var $Storage;
var $CachedNeedQueryString = null;
var $Data;
function Session($mode=smAUTO)
{
parent::kBase();
$this->SetMode($mode);
}
function SetMode($mode)
{
$this->Mode = $mode;
}
function SetCookiePath($path)
{
$this->CookiePath = $path;
}
function SetCookieDomain($domain)
{
$this->CookieDomain = $domain;
}
function SetGETName($get_name)
{
$this->GETName = $get_name;
}
function SetCookieName($cookie_name)
{
$this->CookieName = $cookie_name;
}
function InitStorage()
{
$this->Storage =& new SessionStorage();
}
function Init($prefix,$special)
{
parent::Init($prefix,$special);
$this->CheckIfCookiesAreOn();
$this->Checkers = Array();
$this->InitStorage();
$this->Data =& new Params();
if ($this->Check()) {
$this->SID = $this->GetPassedSIDValue();
$this->Refresh();
$this->LoadData();
}
else {
$this->SetSession();
}
}
function CheckReferer()
{
$reg = '#^'.preg_quote(PROTOCOL.$this->CookieDomain.$this->CookiePath).'#';
return preg_match($reg, $_SERVER['HTTP_REFERER']);
}
function CheckIfCookiesAreOn()
{
if ($this->Mode == smGET_ONLY) {
//we don't need to bother checking if we would not use it
$this->CookiesEnabled = false;
return;
}
$http_query =& $this->Application->recallObject('HTTPQuery');
$cookies_on = $http_query->Cookie['cookies_on']; // not good here
if (!$cookies_on) {
//If referer is our server, but we don't have our cookies_on, it's definetly off
if ($this->CheckReferer()) {
$this->CookiesEnabled = false;
}
else {
//Otherwise we still suppose cookies are on, because may be it's the first time user visits the site
//So we send cookies on to get it next time (when referal will tell us if they are realy off
setcookie(
'cookies_on',
1,
time()+31104000, //one year should be enough
$this->CookiePath,
$this->CookieDomain,
$this->CookieSecure
);
}
}
else
$this->CookiesEnabled = true;
return $this->CookiesEnabled;
}
function Check()
{
// we should check referer if cookies are disabled, and in combined mode
// auto mode would detect cookies, get only mode would turn it off - so we would get here
// and we don't care about referal in cookies only mode
if ( $this->Mode != smCOOKIES_ONLY && (!$this->CookiesEnabled || $this->Mode == smCOOKIES_AND_GET) ) {
if (!$this->CheckReferer())
return false;
}
$sid = $this->GetPassedSIDValue();
if (empty($sid)) return false;
//try to load session by sid, if everything is fine
$result = $this->LoadSession($sid);
return $result;
}
function LoadSession($sid)
{
if ($this->Storage->LocateSession($sid)) {
//if we have session with such SID - get its expiration
$this->Expiration = $this->Storage->GetExpiration();
//If session has expired
if ($this->Expiration < time()) return false;
//Otherwise it's ok
return true;
}
else //fake or deleted due to expiration SID
return false;
}
function GetPassedSIDValue($use_cache = 1)
{
if (!empty($this->CachedSID) && $use_cache) return $this->CachedSID;
$http_query =& $this->Application->recallObject('HTTPQuery');
+ $get_sid=$this->Application->GetVar($this->GETName);
switch ($this->Mode) {
case smAUTO:
- if ($this->CookiesEnabled) { //Cookies has the priority - we ignore everything else
- $sid = $http_query->Cookie[$this->CookieName];
- }
- else {
- $sid = $http_query->Get($this->GETName);
- }
+ //Cookies has the priority - we ignore everything else
+ $sid=$this->CookiesEnabled?$http_query->Cookie[$this->CookieName]:$get_sid;
break;
case smCOOKIES_ONLY:
- $sid = $http_query->Cookie[$this->CookieName];
+ $sid = $http_query->Cookie[$this->CookieName];
break;
case smGET_ONLY:
- $sid = $http_query->Get($this->GETName);
+ $sid = $get_sid;
break;
case smCOOKIES_AND_GET:
- $cookie_sid = $http_query->Cookie[$this->CookieName];
- $get_sid = $http_query->Get($this->GETName);
- //both sids should match if cookies are enabled
- if (!$this->CookiesEnabled || ($cookie_sid == $get_sid))
- $sid = $get_sid; //we use get here just in case cookies are disabled
- else
- $sid = '';
+ $cookie_sid = $http_query->Cookie[$this->CookieName];
+ //both sids should match if cookies are enabled
+ if (!$this->CookiesEnabled || ($cookie_sid == $get_sid))
+ {
+ $sid = $get_sid; //we use get here just in case cookies are disabled
+ }
+ else
+ {
+ $sid = '';
+ }
break;
}
$this->CachedSID = $sid;
return $this->CachedSID;
}
+ /**
+ * Returns session id
+ *
+ * @return int
+ * @access public
+ */
function GetID()
{
return $this->SID;
}
+ /**
+ * Generates new session id
+ *
+ * @return int
+ * @access private
+ */
function GenerateSID()
{
list($usec, $sec) = explode(" ",microtime());
$sid_part_1 = substr($usec, 4, 4);
$sid_part_2 = mt_rand(1,9);
$sid_part_3 = substr($sec, 6, 4);
$digit_one = substr($sid_part_1, 0, 1);
if ($digit_one == 0) {
$digit_one = mt_rand(1,9);
$sid_part_1 = ereg_replace("^0","",$sid_part_1);
$sid_part_1=$digit_one.$sid_part_1;
}
$this->setSID($sid_part_1.$sid_part_2.$sid_part_3);
return $this->SID;
}
+ /**
+ * Set's new session id
+ *
+ * @param int $new_sid
+ * @access private
+ */
function setSID($new_sid)
{
$this->SID=$new_sid;
$this->Application->SetVar($this->GETName,$new_sid);
}
function SetSession()
{
$this->GenerateSID();
$this->Expiration = time() + $this->SessionTimeout;
switch ($this->Mode) {
case smAUTO:
if ($this->CookiesEnabled) {
$this->SetSessionCookie();
}
break;
case smGET_ONLY:
break;
case smCOOKIES_ONLY:
case smCOOKIES_AND_GET:
$this->SetSessionCookie();
break;
}
$this->Storage->StoreSession($this);
}
function SetSessionCookie()
{
setcookie(
$this->CookieName,
$this->SID,
$this->Expiration,
$this->CookiePath,
$this->CookieDomain,
$this->CookieSecure
);
}
+ /**
+ * Refreshes session expiration time
+ *
+ * @access private
+ */
function Refresh()
{
if ($this->CookiesEnabled) $this->SetSessionCookie(); //we need to refresh the cookie
$this->Storage->UpdateSession($this);
}
function Destroy()
{
$this->Storage->DeleteSession($this);
$this->Data =& new Params();
$this->SID = '';
if ($this->CookiesEnabled) $this->SetSessionCookie(); //will remove the cookie due to value (sid) is empty
$this->SetSession(); //will create a new session
}
function NeedQueryString($use_cache = 1)
{
if ($this->CachedNeedQueryString != null && $use_cache) return $this->CachedNeedQueryString;
switch ($this->Mode) {
case smAUTO:
if ($this->CookiesEnabled) {
$res = 0;
}
else {
$res = 1;
}
break;
case smCOOKIES_ONLY:
break;
case smGET_ONLY:
case smCOOKIES_AND_GET:
$res = 1;
break;
}
$this->CachedNeedQueryString = $res;
return $res;
}
function LoadData()
{
$this->Data->AddParams($this->Storage->LoadData($this));
}
function SaveData()
{
$this->Storage->SaveData($this);
}
function StoreVar($name, $value)
{
$this->Data->Set($name, $value);
}
function RecallVar($name,$default=false)
{
$ret=$this->Data->Get($name);
return ($ret===false)?$default:$ret;
}
function RemoveVar($name)
{
$this->Storage->RemoveFromData($this, $name);
$this->Data->Remove($name);
}
}
?>
\ No newline at end of file
Property changes on: trunk/core/kernel/session/session.php
___________________________________________________________________
Modified: cvs2svn:cvs-rev
## -1 +1 ##
-1.2
\ No newline at end of property
+1.3
\ No newline at end of property
Index: trunk/core/kernel/utility/params.php
===================================================================
--- trunk/core/kernel/utility/params.php (revision 938)
+++ trunk/core/kernel/utility/params.php (revision 939)
@@ -1,170 +1,171 @@
<?php
define ('FALSE_ON_NULL', 1);
define ('EMPTY_ON_NULL', 2);
class Params extends kBase {
var $_Params = Array();
function Params($params_str=null)
{
- if ($params_str != '') $this->SplitParamsStr($params_str);
+ parent::kBase();
+ if($params_str != '') $this->SplitParamsStr($params_str);
}
/**
* Splits tag params into associative array
*
* @param string $params_str
* @access private
*/
function SplitParamsStr($params_str)
{
preg_match_all("/([a-zA-Z0-9_.]+)=([\"']{1,1})(.*?)(?<!\\\)\\2/", $params_str, $rets, PREG_SET_ORDER);
$values = Array();
foreach ($rets AS $key => $val){
$values[$val[1]] = str_replace('\\' . $val[2], $val[2], $val[3]);
}
$this->AddParams($values);
}
/**
* Sets new parameter value
*
* @param string $name
* @param string $val
* @access public
*/
function Set($name, $val)
{
//echo "sessing params: [$name] = [$val] (class: <b>".get_class($this)."</b>)<br>";
$this->_Params[strtolower($name)] = $val;
}
/**
* Removes parameter
*
* @param string $name
* @access public
*/
function Remove($name)
{
unset($this->_Params[$name]);
}
/**
* Gets parameter value by parameter name
*
* @param string $name
* @param int $mode
* @return string
* @access public
*/
function Get($name, $mode=FALSE_ON_NULL)
{
// echo " name : '$name' || mode : $mode <br> ";
$name = strtolower($name);
if (array_key_exists($name, $this->_Params))
return $this->_Params[$name];
else
return $mode == FALSE_ON_NULL ? false : '';
}
/**
* Mass parameter setting from hash
*
* @param Array $params
* @access public
*/
function AddParams($params)
{
if (!is_array($params)) return;
/*if (count($this->_Params) == 0) {
$this->_Params = $params;
}
else {*/
foreach ($params as $name => $val)
$this->Set(strtolower($name), $val);
//}
}
/**
* Return all paramters as hash
*
* @return Array
* @access public
*/
function GetParams()
{
return $this->_Params;
}
}
/*class RefParams extends Params {
function Set($name, &$val)
{
$this->_Params[$name] =& $val;
}
function &Get($name)
{
if (isset($this->_Params[$name]))
return $this->_Params[$name];
else
return false;
}
}*/
// ################### TESTS ############################
global $suite;
if (isset($suite)) {
class TestParams extends TestCase {
function testParamsOperations()
{
$params =& new Params();
$params->Set('test_var', 24);
$this->AssertEquals(24, $params->Get('test_var'));
$this->AssertFalse($params->Get('none_existant_param'));
$res = $params->GetParams();
$this->AssertEquals(24, $res['test_var']);
}
function testSplitParams()
{
$params =& new Params('test_param="abc" another_param="7"');
$this->AssertEquals('abc', $params->Get('test_param'));
$this->AssertEquals('7', $params->Get('another_param'));
}
}
$suite->addTest(new TestSuite("TestParams"));
}
/*
function getmicrotime(){
list($usec, $sec) = explode(" ",microtime());
//echo "Usec: $usec, sec: $sec<br>";
return ((float)$usec + (float)$sec);
}
$total = 0;
$params =& new MyParams();
$param_str = "param1=\"1\" param2='atessafa \'sdf'
params3=\"asd ' \\\"f\"";
$param_str = "m:test escape1='-\"-' \t\t \n \t\n escape2=\"+\\\"+\" \n escape3='*\'*' escape4='=\='";
//3852
for ($i=0; $i<1; $i++)
{
$start = getmicrotime();
$params->SplitParamsStr($param_str);
$end = getmicrotime();
$total += $end-$start;
}
printf ("total: %.8f; average: %.8f <br>", $total, $total/100);
*/
?>
\ No newline at end of file
Property changes on: trunk/core/kernel/utility/params.php
___________________________________________________________________
Modified: cvs2svn:cvs-rev
## -1 +1 ##
-1.1
\ No newline at end of property
+1.2
\ No newline at end of property
Index: trunk/core/kernel/utility/http_query.php
===================================================================
--- trunk/core/kernel/utility/http_query.php (revision 938)
+++ trunk/core/kernel/utility/http_query.php (revision 939)
@@ -1,225 +1,296 @@
<?php
class HTTPQuery extends Params {
/**
* $_POST vars
*
* @var Array
* @access private
*/
var $Post;
/**
* $_GET vars
*
* @var Array
* @access private
*/
var $Get;
/**
* $_COOKIE vars
*
* @var Array
* @access private
*/
var $Cookie;
/**
* $_SERVER vars
*
* @var Array
* @access private
*/
var $Server;
/**
* $_ENV vars
*
* @var Array
* @access private
*/
var $Env;
/**
* Order in what write
* all vars together in
* the same array
*
* @var string
*/
var $Order;
/**
* Uploaded files info
*
* @var Array
* @access private
*/
var $Files;
/**
* Loads info from $_POST, $_GET and
* related arrays into common place
*
* @param string $order
* @return HTTPQuery
* @access public
*/
function HTTPQuery($order='CGPF')
{
+ parent::Params();
$this->Order = $order;
$this->AddAllVars();
+ $this->processQueryString();
ini_set("magic_quotes_gpc", 0);
}
/**
* All all requested vars to
* common storage place
*
* @access private
*/
function AddAllVars()
{
for ($i=0; $i < strlen($this->Order); $i++)
{
$current = $this->Order[$i];
switch ($current) {
case 'G':
$this->Get =$this->AddVars($_GET);
break;
case 'P':
$my_post = $this->post_convert($_POST); // needed ?
$this->Post = $this->AddVars($_POST);
break;
case 'C':
$this->Cookie = $this->AddVars($_COOKIE);
break;
case 'E';
$this->Env = $this->AddVars($_ENV);
break;
case 'S';
$this->Server = $this->AddVars($_SERVER);
break;
case 'F';
$this->Files = $this->AddVars($_FILES);
break;
}
}
}
+ /**
+ * Process QueryString only, create
+ * events, ids, based on config
+ * set template name and sid in
+ * desired application variables.
+ *
+ * @access private
+ */
+ function processQueryString()
+ {
+ // env=SID:TEMPLATE:m-1-1-1-1:l0-0-0:n-0-0-0:bb-0-0-1-1-1-0
+
+ $env_var =& $this->Get(ENV_VAR_NAME);
+ if($env_var)
+ {
+ $parts=explode(':',$env_var);
+
+ // Save Session ID
+ $sid=array_shift($parts);
+ if($sid) $this->Set('sid',$sid);
+
+ // Save Template Name
+ $t=$this->getTemplateName( array_shift($parts) );
+ if(!$t) $t='index';
+ $this->Set('t',$t);
+
+ if($parts)
+ {
+ $query_maps=Array();
+ $event_manger =& $this->Application->recallObject('EventManager');
+
+ foreach($parts as $mixed_part)
+ {
+ $mixed_part=explode('-',$mixed_part);
+ $prefix_special=array_shift($mixed_part); // l.pick, l
+ list($prefix)=explode('.',$prefix_special);
+
+ $query_maps[$prefix_special]=$this->Application->getUnitOption($prefix,'QueryString');
+ foreach($query_maps[$prefix_special] as $index => $var_name)
+ {
+ // l_id, l_page, l_bla-bla-bla
+ $this->Set($prefix_special.'_'.$var_name,$mixed_part[$index-1]);
+ }
+ }
+ $event_manger->setQueryMaps($query_maps);
+ }
+ }
+ else
+ {
+ $t=$this->getTemplateName('index');
+ $this->Set('t',$t);
+ }
+ }
+
+ /**
+ * Decides what template name to
+ * use from $_GET or from $_POST
+ *
+ * @param string $querystring_template
+ * @return string
+ * @access private
+ */
+ function getTemplateName($querystring_template)
+ {
+ $t_from_post=$this->Get('t');
+ $t=$t_from_post?$t_from_post:$querystring_template;
+ return $t;
+ }
+
function post_convert($array)
{
$out = Array();
foreach ($array as $key => $val) {
if ( ereg("\|\|",$key)) {
$key = str_replace("||",".",$key);
}
else
$out[$key] = $val;
}
}
/**
* Saves variables from array specified
* into common variable storage place
*
* @param Array $array
* @return Array
* @access private
*/
function AddVars($array)
{
foreach ($array as $key => $val) {
if (get_magic_quotes_gpc())
{
if ( is_array($val) )
{
foreach ($val as $key_array => $val_array)
{
if( is_array($val_array) )
{
$array[$key][$key_array] = $this->AddVars($val_array);
}
else
{
$array[$key][$key_array] = stripslashes($val_array);
}
}
$this->Set($key, $array[$key]);
}
else {
$array[$key] = stripslashes($val);
$this->Set($key, $array[$key]);
}
}
else {
$this->Set($key, $val);
}
}
return $array;
}
/**
* Returns the hash of http params
* matching the mask with values
*
* @param string $mask
* @return Array
* @access public
*/
function GetSelectedValues($mask)
{
return $this->Application->ExtractByMask($this->Vars, $mask);
}
/**
* Returns the sprintf'ed by format list of
* http params matching the mask and set to on
*
* @param string $mask
* @param string $format
* @return string
* @access public
*/
function GetSelectedIDs($mask, $format)
{
if ($mask == '') return;
$result = '';
foreach ($this->GetParams() as $name => $val)
{
if (eregi($mask, $name, $regs) && $val == 'on') {
$result.= sprintf($format, $regs[1]);
}
}
return $result;
}
/**
* Returns the sprintf'ed by format list of
* http params matching the mask and set to on
*
* @param string $mask
* @param string $value_mask
* @return Array
* @access public
*/
function GetSelectedIDsArray($mask, $value_mask="%s,")
{
$str = $this->GetSelectedIDs($mask, $value_mask);
$str = rtrim($str, ',');
if (!empty($str)) {
$ids = split(',', $str);
if ($ids !== false)
return $ids;
else return Array();
}
else return Array();
}
}
?>
\ No newline at end of file
Property changes on: trunk/core/kernel/utility/http_query.php
___________________________________________________________________
Modified: cvs2svn:cvs-rev
## -1 +1 ##
-1.1
\ No newline at end of property
+1.2
\ No newline at end of property
Index: trunk/core/kernel/db/db_event_handler.php
===================================================================
--- trunk/core/kernel/db/db_event_handler.php (revision 938)
+++ trunk/core/kernel/db/db_event_handler.php (revision 939)
@@ -1,382 +1,380 @@
<?php
/**
* Note:
* 1. When adressing variables from submit containing
* Prefix_Special as part of their name use
* $event->getPrefixSpecial(true) instead of
* $event->Prefix_Special as usual. This is due PHP
* is converting "." symbols in variable names during
* submit info "_". $event->getPrefixSpecial optional
* 1st parameter returns correct corrent Prefix_Special
* for variables beeing submitted such way (e.g. variable
* name that will be converted by PHP: "users.read_only_id"
* will be submitted as "users_read_only_id".
*
* 2. When using $this->Application-LinkVar on variables submitted
* from form which contain $Prefix_Special then note 1st item. Example:
* LinkVar($event->getPrefixSpecial(true).'_varname',$event->Prefix_Special.'_varname')
*
*/
/**
* EventHandler that is used to process
* any database related events
*
*/
class kDBEventHandler extends kEventHandler {
/**
* Get's ID of item to be edited.
* Returns 1st id in case if many
* items were selected.
*
* @param kEvent $event
* @return int
*/
function getPassedID(&$event)
{
$ret=$this->Application->GetVar($event->getPrefixSpecial().'_id');
if($ret===false)
{
$ids=$this->Application->GetVar($event->getPrefixSpecial().'_selected_ids');
$ids=explode(',',$ids);
if($ids) $ret=array_shift($ids);
}
return $ret;
}
/**
* Builds item (loads if needed)
*
* @param kEvent $event
* @access protected
*/
function OnItemBuild(&$event)
{
$object =& $this->createObject(&$event);
$this->dbBuild(&$object,&$event);
$sql=$this->getSelectSQL($event,'OnItemPrepareQuery');
$object->setSelectSQL($sql);
// 1. set from config what needed
$fields = $this->Application->getUnitOption($event->Prefix,'Fields');
$object->setConfigFields( array_keys($fields) );
// 2. loads if allowed
$auto_load = $this->Application->getUnitOption($event->Prefix,'AutoLoad');
if($auto_load)
{
$id = $this->getPassedID(&$event);
$object->Load($id);
}
}
/**
* Builds list
*
* @param kEvent $event
* @access protected
*/
function OnListBuild(&$event)
{
$event->setPseudoClass('_List');
$object =& $this->createObject(&$event);
$this->dbBuild(&$object,&$event);
$sql=$this->getSelectSQL($event,'OnListPrepareQuery');
$object->setSelectSQL($sql);
$t=$this->Application->GetVar('t');
$this->Application->StoreVar('redirect_to',$t);
$this->SetPagination(&$event);
$this->SetSorting(&$event);
}
/**
* Set's correct page for list
* based on data provided with event
*
* @param kEvent $event
* @access private
* @see OnListBuild
*/
function SetPagination(&$event)
{
$per_page = $event->getEventParam('per_page');
if(!$per_page)
{
$per_page=$this->Application->RecallVar($event->Prefix_Special.'_PerPage');
if(!$per_page)
{
$per_page=10;
}
}
$event->setPseudoClass('_List');
$object =& $this->createObject(&$event);
$object->SetPerPage($per_page);
$object->CountRecs();
$object->SetPage( $this->Application->GetLinkedVar( $event->Prefix_Special.'_Page' ) );
}
/**
* Set's correct sorting for list
* based on data provided with event
*
* @param kEvent $event
* @access private
* @see OnListBuild
*/
function SetSorting(&$event)
{
$event->setPseudoClass('_List');
$object =& $this->createObject(&$event);
$cur_sort1 = $this->Application->RecallVar($event->Prefix_Special.'_Sort1');
$cur_sort1_dir = $this->Application->RecallVar($event->Prefix_Special.'_Sort1_Dir');
$cur_sort2 = $this->Application->RecallVar($event->Prefix_Special.'_Sort2');
$cur_sort2_dir = $this->Application->RecallVar($event->Prefix_Special.'_Sort2_Dir');
//Use default if not specified
/*if ( $cur_sort1 === false || $cur_sort1_dir == false ) {
$cur_sort1 = $this->Application->ConfigOption($event->Prefix_Special.'_Sort1');
$cur_sort1_dir = $this->Application->ConfigOption($event->Prefix_Special.'_Sort1_Dir');
$cur_sort2 = $this->Application->ConfigOption($event->Prefix_Special.'_Sort2');
$cur_sort2_dir = $this->Application->ConfigOption($event->Prefix_Special.'_Sort2_Dir');
}*/
if($cur_sort1 != '' && $cur_sort1_dir != '')
{
$object->AddOrderField($cur_sort1, $cur_sort1_dir);
}
if($cur_sort2 != '' && $cur_sort2_dir != '')
{
$object->AddOrderField($cur_sort2, $cur_sort2_dir);
}
}
/**
* Some kind of filter processing stuff.
* Not in use by now
*
*/
function AddFilters()
{
}
/**
* Set's new sorting for list
*
* @param kEvent $event
* @access protected
*/
function OnSetSorting(&$event)
{
$this->Application->LinkVar($event->getPrefixSpecial(true).'_Sort1',$event->Prefix_Special.'_Sort1');
$this->Application->LinkVar($event->getPrefixSpecial(true).'_Sort1_Dir',$event->Prefix_Special.'_Sort1_Dir');
//$event->setPseudoClass('_List');
//$object =& $this->createObject(&$event);
}
/**
* Common builder part for Item & List
*
* @param Object $object
* @access private
*/
function dbBuild(&$object,&$event)
{
// set Item & List common parameters from config
$table = $this->Application->getUnitOption($event->Prefix,'TableName');
$object->setTableName($table);
$id_field = $this->Application->getUnitOption($event->Prefix,'IDField');
$object->setIDField($id_field);
// get selected ids from post & save them to session
$items_info = $this->Application->GetVar( $event->getPrefixSpecial(true) );
if($items_info)
{
$ids=array_keys($items_info);
$this->Application->SetVar($event->getPrefixSpecial().'_selected_ids',implode(',',$ids));
}
$this->Application->LinkVar($event->getPrefixSpecial().'_selected_ids');
// set's any possible hidden fields needed for both Item & List
$current_event = $this->Application->GetVar($event->Prefix_Special.'_event');
$this->Application->setEvent($event->Prefix_Special,$current_event);
}
/**
* Returns select query for loading item/list
*
* @param kEvent $event
* @param string $event_name
* @return string
* @access protected
*/
function getSelectSQL(&$event,$event_name)
{
$new_event =& $this->inheritEvent(&$event);
$new_event->Name=$event_name;
$this->Application->HandleEvent(&$new_event);
return $event->getEventParam('SQLQuery');
}
/**
* Creates needed sql query to load item,
* if no query is defined in config for
* special requested, then use default
* query
*
* @param kEvent $event
* @access protected
*/
function OnItemPrepareQuery(&$event)
{
$sqls = $this->Application->getUnitOption($event->Prefix,'ItemSQLs');
$sql = isset($sqls[$event->Special])?$sqls[$event->Special]:$sqls[''];
$event->MasterEvent->setEventParam('SQLQuery',$sql);
}
/**
* Creates needed sql query to load list,
* if no query is defined in config for
* special requested, then use default
* query
*
* @param kEvent $event
* @access protected
*/
function OnListPrepareQuery(&$event)
{
$sqls = $this->Application->getUnitOption($event->Prefix,'ListSQLs');
$sql = isset($sqls[$event->Special])?$sqls[$event->Special]:$sqls[''];
$event->MasterEvent->setEventParam('SQLQuery',$sql);
}
/**
* Creates new kDBItem
*
* @param kEvent $event
* @access protected
*/
function OnCreate(&$event)
{
$this->Application->setUnitOption($this->getPrefixSpecial(),'AutoLoad',false);
$object =& $this->createObject(&$event);
$this->prepareObject(&$object,&$event);
$items_info = $this->Application->GetVar( $event->getPrefixSpecial(true) );
if($items_info) $field_values = array_shift($items_info);
$object->SetFieldsFromHash($field_values);
if( $object->Create() )
{
$event->status=erSUCCESS;
}
else
{
$event->status=erFATAL;
$event->redirect=false;
}
}
/**
* Updates kDBItem
*
* @param kEvent $event
* @access protected
*/
function OnUpdate(&$event)
{
$this->Application->setUnitOption($this->getPrefixSpecial(),'AutoLoad',false);
$object =& $this->createObject(&$event);
$this->prepareObject(&$object,&$event);
$items_info = $this->Application->GetVar( $event->getPrefixSpecial(true) );
if($items_info)
{
foreach($items_info as $id => $field_values)
{
//$object->Load($id);
$object->SetFieldsFromHash($field_values);
if( $object->Update($id) )
{
$event->status=erSUCCESS;
}
else
{
$event->status=erFATAL;
$event->redirect=false;
break;
}
}
}
}
/**
* Delete's kDBItem object
*
* @param kEvent $event
* @access protected
*/
function OnDelete(&$event)
{
$this->Application->setUnitOption($this->getPrefixSpecial(),'AutoLoad',false);
$object =& $this->createObject(&$event);
$object->ID=$this->Application->GetVar($event->Prefix_Special.'_id');
if( $object->Delete() )
{
$event->status=erSUCCESS;
}
else
{
$event->status=erFATAL;
$event->redirect=false;
break;
}
}
/**
* Prepares new kDBItem object
*
* @param kEvent $event
* @access protected
*/
function OnNew(&$event)
{
$this->Application->setUnitOption($this->getPrefixSpecial(),'AutoLoad',false);
$object =& $this->createObject(&$event);
$this->prepareObject(&$object,&$event);
$object->setID(0);
$this->Application->SetVar($event->Prefix_Special.'_SaveEvent','OnCreate');
-
-
$event->redirect=false;
}
/**
* Cancel's kDBItem Editing/Creation
*
* @param kEvent $event
* @access protected
*/
function OnCancel(&$event)
{
}
}
?>
\ No newline at end of file
Property changes on: trunk/core/kernel/db/db_event_handler.php
___________________________________________________________________
Modified: cvs2svn:cvs-rev
## -1 +1 ##
-1.3
\ No newline at end of property
+1.4
\ No newline at end of property
Index: trunk/core/kernel/application.php
===================================================================
--- trunk/core/kernel/application.php (revision 938)
+++ trunk/core/kernel/application.php (revision 939)
@@ -1,784 +1,778 @@
<?php
//include_once(KERNEL_PATH."/base.php");
//include_once(KERNEL_PATH."/mvc/models/dbitem.php");
//include_once(KERNEL_PATH."/mvc/models/dblist.php");
include_once(KERNEL_PATH."/kbase.php");
include_once(KERNEL_PATH.'/processors/tag_processor.php');
include_once(KERNEL_PATH."/event_handler.php");
include_once(KERNEL_PATH."/utility/factory.php");
include_once(KERNEL_PATH."/utility/iterator.php");
include_once(KERNEL_PATH."/languages/phrases_cache.php");
include_once(KERNEL_PATH."/db/dblist.php");
include_once(KERNEL_PATH."/db/dbitem.php");
include_once(KERNEL_PATH."/db/db_tag_processor.php");
include_once(KERNEL_PATH."/utility/event.php");
$profiler = null;
/**
* Basic class for Kernel3-based Application
*
* This class is a Facade for any other class which needs to deal with Kernel3 framework.<br>
* The class incapsulates the main run-cycle of the script, provide access to all other objects in the framework.<br>
* <br>
* The class is a singleton, which means that there could be only one instance of KernelApplication in the script.<br>
* This could be guranteed by NOT calling the class constuctor directly, but rather calling KernelApplication::Instance() method,
* which returns an instance of the application. The method gurantees that it will return exactly the same instance for any call.<br>
* See singleton pattern by GOF.
* @package kernel4
*/
class kApplication {
/**
* Holds internal TemplateParser object
* @access private
* @var TemplateParser
*/
var $Parser;
var $Profiler;
/**
* Holds parser output buffer
* @access private
* @var string
*/
var $HTML;
var $DocRoot;
var $BasePath;
var $KernelPath;
var $Server;
/**
* The main Factory used to create
* almost any class of kernel and
* modules
*
* @access private
* @var kFactory
*/
var $Factory;
var $XMLFactory; // in use?
/**
* Holds all phrases used
* in code and template
*
* @var PhrasesCache
*/
var $Phrases;
/**
* Holds connection to database
*
* @var DBConnection
*/
var $DB;
/**
* Constucts KernelApplication - constructor is PRIVATE
*
* The constuructor of KernelApplication should NOT be called directly
* To create KernelApplication, call its Instance() method
* @see KerenelApplication::Instance
* @access private
*/
function kApplication()
{
global $doc_root, $base_path, $kernel_path, $protocol, $server;
$this->DocRoot = $doc_root;
$this->BasePath = $base_path;
$this->KernelPath = $kernel_path;
$this->Protocol = $protocol;
$this->Server = $server;
}
/**
* Returns kApplication instance anywhere in the script.
*
* This method should be used to get single kApplication object instance anywhere in the
* Kernel-based application. The method is guranteed to return the SAME instance of kApplication.
* Anywhere in the script you could write:
* <code>
* $application =& kApplication::Instance();
* </code>
* or in an object:
* <code>
* $this->Application =& kApplication::Instance();
* </code>
* to get the instance of kApplication. Note that we call the Instance method as STATIC - directly from the class.
* To use descendand of standard kApplication class in your project you would need to define APPLICATION_CLASS constant
* BEFORE calling kApplication::Instance() for the first time. If APPLICATION_CLASS is not defined the method would
* create and return default KernelApplication instance.
* @static
* @access public
* @return kApplication
*/
function &Instance()
{
static $instance = false;
if (!$instance) {
if (!defined('APPLICATION_CLASS')) define('APPLICATION_CLASS', 'kApplication');
$class = APPLICATION_CLASS;
$instance = new $class();
}
return $instance;
}
/**
* Initializes the Application
*
* Creates Utilites instance, HTTPQuery, Session, Profiler, TemplatesCache, Parser
* @access public
* @see HTTPQuery
* @see Session
* @see TemplatesCache
* @return void
*/
function Init()
{
$this->DB = new DBConnection(SQL_TYPE);
$this->DB->Connect(SQL_SERVER, SQL_USER, SQL_PASS, SQL_DB);
$this->DB->debugMode = $this->isDebugMode();
$this->SetDefaultConstants();
setcookie('CookiesOn', 1, time()+600);
$this->Factory = new kFactory();
$this->registerDefaultClasses();
// 1. to read configs before doing any recallObject
$config_reader =& $this->recallObject('kUnitConfigReader');
-
- // 2. to virtually create SID and T application vars just
- // in case if they are needed before ProcessRequest method call
- $event_manager =& $this->recallObject('EventManager');
- $event_manager->processQueryString();
-
- $this->Phrases =& new PhrasesCache($this->RecallVar('LanguageId', DEFAULT_LANGUAGE_ID));
+ $this->Phrases = new PhrasesCache( $this->RecallVar('LanguageId', DEFAULT_LANGUAGE_ID) );
$this->ValidateLogin(); // TODO: write that method
}
/**
* Registers default classes such as ItemController, GridController and LoginController
*
* Called automatically while initializing Application
* @access private
* @return void
*/
function RegisterDefaultClasses()
{
- $this->registerClass('Utilites',KERNEL_PATH.'/utility/utilities.php');
+ //$this->registerClass('Utilites',KERNEL_PATH.'/utility/utilities.php');
$this->registerClass('HTTPQuery',KERNEL_PATH.'/utility/http_query.php');
$this->registerClass('Session',KERNEL_PATH.'/session/session.php');
$this->registerClass('kEventManager',KERNEL_PATH.'/event_manager.php','EventManager');
$this->registerClass('kUnitConfigReader',KERNEL_PATH.'/utility/unit_config_reader.php');
$this->registerClass('Params',KERNEL_PATH.'/utility/params.php','kActions');
- $this->registerClass('Configuration',KERNEL_PATH.'/utility/configuration.php');
+ //$this->registerClass('Configuration',KERNEL_PATH.'/utility/configuration.php');
$this->registerClass('TemplatesCache',KERNEL_PATH.'/parser/template.php');
$this->registerClass('TemplateParser',KERNEL_PATH.'/parser/template_parser.php');
$this->registerClass('MainProcessor', KERNEL_PATH.'/processors/main_processor.php','m_TagProcessor');
$this->registerClass('kDBList', KERNEL_PATH.'/db/dblist.php');
$this->registerClass('kDBItem', KERNEL_PATH.'/db/dbitem.php');
$this->registerClass('kDBEventHandler', KERNEL_PATH.'/db/db_event_handler.php');
$this->registerClass('kDBTagProcessor', KERNEL_PATH.'/db/db_tag_processor.php');
$this->registerClass('kTagProcessor', KERNEL_PATH.'/processors/tag_processor.php');
/*$this->RegisterClass('LoginController', KERNEL_PATH.'/users/login_controller.php');*/
}
/**
* Defines default constants if it's not defined before - in config.php
*
* Called automatically while initializing Application and defines:
* LOGIN_CONTROLLER, XML_FACTORY etc.
* @access private
* @return void
*/
function SetDefaultConstants()
{
if (!defined('SERVER_NAME')) define('SERVER_NAME', $_SERVER['SERVER_NAME']);
if (!defined('LOGIN_CONTROLLER')) define('LOGIN_CONTROLLER', 'LoginController');
if (!defined('XML_FACTORY')) define('XML_FACTORY', 'XMLFactory');
if (!defined('ADMINS_LIST')) define('ADMINS_LIST', '/users/users.php');
if (!defined('USER_MODEL')) define('USER_MODEL', 'Users');
if (!defined('DEFAULT_LANGUAGE_ID')) define('DEFAULT_LANGUAGE_ID', 1);
}
/**
* Actually runs the parser against current template and stores parsing result
*
* This method gets t variable passed to the script, loads the template given in t variable and
* parses it. The result is store in {@link $this->HTML} property.
* @access public
* @return void
*/
function Run()
{
$event_manager =& $this->recallObject('EventManager');
$event_manager->ProcessRequest();
$this->Parser =& $this->recallObject('TemplateParser');
$template_cache =& $this->recallObject('TemplatesCache');
$t = $this->GetVar('t');
$this->HTML = $this->Parser->Parse( $template_cache->GetTemplateBody($t) );
}
/**
* Send the parser results to browser
*
* Actually send everything stored in {@link $this->HTML}, to the browser by echoing it.
* @access public
* @return void
*/
function Done()
{
//eval("?".">".$this->HTML);
echo $this->HTML;
$this->Phrases->UpdateCache();
$session =& $this->recallObject('Session');
$session->SaveData();
}
// Facade
/**
* Returns current session id (SID)
* @access public
* @return longint
*/
function GetSID()
{
$session =& $this->recallObject('Session');
return $session->GetID();
}
function DestroySession()
{
$session =& $this->recallObject('Session');
$session->DestroySession();
}
/**
* Returns variable passed to the script as GET/POST/COOKIE
*
* @access public
* @param string $var Variable name
* @return mixed
*/
function GetVar($var,$mode=FALSE_ON_NULL)
{
$http_query =& $this->recallObject('HTTPQuery');
return $http_query->Get($var,$mode);
}
/**
* Returns ALL variables passed to the script as GET/POST/COOKIE
*
* @access public
* @return array
*/
function GetVars()
{
$http_query =& $this->recallObject('HTTPQuery');
return $http_query->GetParams();
}
/**
* Set the variable 'as it was passed to the script through GET/POST/COOKIE'
*
* This could be useful to set the variable when you know that
* other objects would relay on variable passed from GET/POST/COOKIE
* or you could use SetVar() / GetVar() pairs to pass the values between different objects.<br>
*
* This method is formerly known as $this->Session->SetProperty.
* @param string $var Variable name to set
* @param mixed $val Variable value
* @access public
* @return void
*/
function SetVar($var,$val)
{
$http_query =& $this->recallObject('HTTPQuery');
$http_query->Set($var,$val);
}
function RemoveVar($var)
{
$session =& $this->recallObject('Session');
return $session->RemoveVar($var);
}
/**
* Returns session variable value
*
* Return value of $var variable stored in Session. An optional default value could be passed as second parameter.
*
* @see SimpleSession
* @access public
* @param string $var Variable name
* @param mixed $default Default value to return if no $var variable found in session
* @return mixed
*/
function RecallVar($var,$default='')
{
$session =& $this->recallObject('Session');
return $session->RecallVar($var,$default);
}
/**
* Stores variable $val in session under name $var
*
* Use this method to store variable in session. Later this variable could be recalled.
* @see RecallVar
* @access public
* @param string $var Variable name
* @param mixed $val Variable value
*/
function StoreVar($var, $val)
{
$session =& $this->recallObject('Session');
$session->StoreVar($var, $val);
}
function StoreVarDefault($var, $val)
{
$session =& $this->recallObject('Session');
$session->StoreVarDefault($var, $val);
}
/**
* Links HTTP Query variable with session variable
*
* If variable $var is passed in HTTP Query it is stored in session for later use. If it's not passed it's recalled from session.
* This method could be used for making sure that GetVar will return query or session value for given
* variable, when query variable should overwrite session (and be stored there for later use).<br>
* This could be used for passing item's ID into popup with multiple tab -
* in popup script you just need to call LinkVar('id', 'current_id') before first use of GetVar('id').
* After that you can be sure that GetVar('id') will return passed id or id passed earlier and stored in session
* @access public
* @param string $var HTTP Query (GPC) variable name
* @param mixed $ses_var Session variable name
* @param mixed $default Default variable value
*/
function LinkVar($var, $ses_var=null, $default='')
{
if (!isset($ses_var)) $ses_var = $var;
if ($this->GetVar($var) !== false) {
$this->StoreVar($ses_var, $this->GetVar($var));
}
else
$this->SetVar($var, $this->RecallVar($ses_var, $default));
}
/**
* Returns variable from HTTP Query, or from session if not passed in HTTP Query
*
* The same as LinkVar, but also returns the variable value taken from HTTP Query if passed, or from session if not passed.
* Returns the default value if variable does not exist in session and was not passed in HTTP Query
*
* @see LinkVar
* @access public
* @param string $var HTTP Query (GPC) variable name
* @param mixed $ses_var Session variable name
* @param mixed $default Default variable value
* @return mixed
*/
function GetLinkedVar($var, $ses_var=null, $default='')
{
if (!isset($ses_var)) $ses_var = $var;
$this->LinkVar($var, $ses_var, $default);
return $this->GetVar($var);
}
/*function ExtractByMask($array, $mask, $key_id=1, $ret_mode=1)
{
$utils =& $this->recallObject('Utilities');
return $utils->ExtractByMask($array, $mask, $key_id, $ret_mode);
}
function GetSelectedIDs($mask, $format)
{
$http_query =& $this->recallObject('HTTPQuery');
return $http_query->GetSelectedIDs($mask, $format);
}
function GetSelectedIDsArray($mask, $value_mask="%s,")
{
$http_query =& $this->recallObject('HTTPQuery');
return $http_query->GetSelectedIDsArray($mask, $value_mask);
}*/
/**
* Returns configurtion option
*
* @param string $option
* @return string
* @access public
*/
/*function ConfigOption($option)
{
$config =& $this->recallObject('Configuration');
return $config->Get($option);
}*/
/**
* Sets configuration option
*
* @param string $option
* @param string $value
* @return bool
* @access public
*/
/*function SetConfigOption($option,$value)
{
$config =& $this->recallObject('Configuration');
return $config->Set($option, $value);
}*/
function AddBlock($name, $tpl)
{
$this->cache[$name] = $tpl;
}
function SetTemplateBody($title,$body)
{
$templates_cache =& $this->recallObject('TemplatesCache');
$templates_cache->SetTemplateBody($title,$body);
}
function ProcessTag($tag_data)
{
$a_tag = new Tag($tag_data,$this->Parser);
return $a_tag->DoProcessTag();
}
/*function &GetProcessor($prefix)
{
$this->KernelDie('GetProcessor is DEPRICATED, use recallObject');
// return $this->Processors->GetProcessor($prefix, new Tag('empty', $this->Parser));
}*/
/* DEFINETLY NEEDS TO BE MOVED AWAY!!!!! */
/*var $email_body;
function Email($params)
{
$this->email_body = $this->ParseBlock($params);
$from = $this->GetVar('email_from');
$to = $this->GetVar('email_to');
$replay = $this->GetVar('email_replay');
if ( $replay == "" ) $replay = $from;
$subject = $this->GetVar('email_subject');
$charset = $this->GetVar('email_charset');
// $display = $this->GetVar('email_display');
$display = 0;
if (!isset($charset) || $charset == '') $charset = 'US-ASCII';
$mime = $this->GetVar('email_mime');
if ($mime == 'yes') {
$mime_mail = new MIMEMail($to, $from, $subject, $charset);
$mime_mail->mailbody($this->email_body);
if ($f_name = $this->GetVar('email_attach')) {
$full_path = DOC_ROOT.BASE_PATH.'/'.$f_name;
$data = '';
if(file_exists($full_path)) {
$fd = fopen($full_path, "r");
$data = fread($fd, filesize($full_path));
fclose($fd);
}
else exit;
$filename = $this->GetVar('email_attach_filename');
$type = $this->GetVar('email_attach_type');
$mime_mail->attachfile_raw($data, $filename, $type);
$mime_mail->send();
}
}
else {
$headers.="From: $from\n";
$headers.="Reply-To: $replay\n";
$headers.="Content-Type: text/html; charset=\"$charset\"\n";
if ( $display == 1 ) {
echo "<pre>";
echo " from : $from <br>";
echo " to : $to <br>";
echo " replay : $replay <br>";
echo " subject : $subject <br>";
echo " this->email_body : $this->email_body <br>";
echo " headers : $headers <br>";
echo "</pre>";
}
mail($to, $subject, $this->email_body, $headers);
}
}*/
/**
* Return ADODB Connection object
*
* Returns ADODB Connection object already connected to the project database, configurable in config.php
* @access public
* @return ADODBConnection
*/
function &GetADODBConnection()
{
return $this->DB;
}
function ParseBlock($params,$pass_params=0)
{
return $this->Parser->ParseBlock($params,$pass_params);
}
function &GetXMLFactory()
{
return $this->XMLFactory;
}
/**
* Return href for template
*
* @access public
* @param string $t Template path
* @var string $prefix index.php prefix - could be blank, 'admin'
*/
function HREF($t, $prefix='')
{
global $HTTP_SERVER_VARS;
if (defined('ADMIN') && $prefix == '') $prefix='/admin';
if (defined('ADMIN') && $prefix == '_FRONT_END_') $prefix = '';
$index_file = defined('INDEX_FILE') ? INDEX_FILE : 'index.php';
$t_path = !empty($t) ? 't='.$t : '';
$session =& $this->recallObject('Session');
$sid = $session->NeedQueryString()?$this->GetSID():'';
$ret = $this->BaseURL($prefix).$index_file.'?'.ENV_VAR_NAME.'='.$sid.':'.$t;
$t_pass=$this->GetVar('t_pass');
if($t_pass)
{
$ret.=':';
$pass_info=explode(',',$t_pass); // array( prefix[.special], prefix[.special] ...
foreach($pass_info as $pass_element)
{
list($prefix)=explode('.',$pass_element);
$query_vars = $this->getUnitOption($prefix,'QueryString');
if($query_vars)
{
$tmp_string=Array(0=>$pass_element);
foreach($query_vars as $index => $var_name)
{
$tmp_string[$index]=$this->GetVar($pass_element.'_'.$var_name);
}
$ret.=implode('-',$tmp_string);
}
}
}
return $ret;
}
function BaseURL($prefix='')
{
return PROTOCOL.SERVER_NAME.(defined('PORT')?':'.PORT : '').BASE_PATH.$prefix.'/';
}
function Redirect($t='', $params='', $prefix='')
{
if ($t == '') $t = $this->GetVar('t');
$location = $this->HREF($t, $prefix);
$a_location = $location;
$location = sprintf("Location: %s".($params ? "&" : '')."%s",$location, $params);
//echo " location : $location <br>";
if (headers_sent() != '') {
echo "<b>Debug output above!!!</b> Proceed to redirect: <a href=\"$a_location\">$a_location</a><br>";
}
else
header("$location");
$session =& $this->recallObject('Session');
$session->SaveData();
exit;
}
/*function UserError($msg)
{
error_reporting(E_ALL);
trigger_error($msg, E_USER_WARNING );
}*/
function Phrase($label)
{
if (ereg("^!.+!$", $label) > 0) {
$label = substr($label, 1, -1); //cut exclamation marks
}
return $this->Phrases->GetPhrase($label);
}
/**
* Validtates user in session if required
*
*/
function ValidateLogin()
{
if (defined('LOGIN_REQUIRED'))
{
// Original Kostja call
//$login_controller =& $this->Factory->MakeClass(LOGIN_CONTROLLER, Array('model' => USER_MODEL, 'prefix' => 'login'));
// Call proposed by Alex
//$login_controller =& $this->RecallObject(LOGIN_CONTROLLER, Array('model' => USER_MODEL, 'prefix' => 'login'));
//$login_controller->CheckLogin();
}
}
function KernelDie($message) {
echo "<b>KernelApplication died</b>: $message<br>Debug backtrace follows:<br>";
print_pre(debug_backtrace());
echo "</pre>";
}
function trigerError($message,$error_type=E_USER_WARNING)
{
trigger_error($message,$error_type);
}
/**
* Allows to process any type of event
*
* @param kEvent $event
* @access public
*/
function HandleEvent(&$event)
{
$event_manager =& $this->recallObject('EventManager');
$event_manager->HandleEvent(&$event);
}
/**
* Registers new class in the factory
*
* @param string $real_class
* @param string $file
* @param string $pseudo_class
* @access public
*/
function registerClass($real_class,$file,$pseudo_class=null)
{
$this->Factory->registerClass($real_class,$file,$pseudo_class);
}
/**
* Returns object using params specified,
* creates it if is required
*
* @param string $name
* @param string $pseudo_class
* @param Array $event_params
* @return Object
*/
function &recallObject($name,$pseudo_class=null,$event_params=Array())
{
return $this->Factory->getObject($name,$pseudo_class,$event_params);
}
/**
* Checks if application is in debug mode
*
* @return bool
* @access public
*/
function isDebugMode()
{
return defined('DEBUG_MODE')&&DEBUG_MODE;
}
/**
* Reads unit (specified by $prefix)
* option specified by $option
*
* @param string $prefix
* @param string $option
* @return string
* @access public
*/
function getUnitOption($prefix,$option)
{
$unit_config_reader =& $this->recallObject('kUnitConfigReader');
return $unit_config_reader->getUnitOption($prefix,$option);
}
/**
* Set's new unit option value
*
* @param string $prefix
* @param string $name
* @param string $value
* @access public
*/
function setUnitOption($prefix,$option,$value)
{
$unit_config_reader =& $this->recallObject('kUnitConfigReader');
return $unit_config_reader->setUnitOption($prefix,$option,$value);
}
/**
* Splits any mixing of prefix and
* special into correct ones
*
* @param string $prefix_special
* @return Array
* @access public
*/
function processPrefix($prefix_special)
{
return $this->Factory->processPrefix($prefix_special);
}
/**
* Set's new event for $prefix_special
* passed
*
* @param string $prefix_special
* @param string $event_name
* @access public
*/
function setEvent($prefix_special,$event_name)
{
$event_manager =& $this->recallObject('EventManager');
$event_manager->setEvent($prefix_special,$event_name);
}
}
?>
\ No newline at end of file
Property changes on: trunk/core/kernel/application.php
___________________________________________________________________
Modified: cvs2svn:cvs-rev
## -1 +1 ##
-1.3
\ No newline at end of property
+1.4
\ No newline at end of property
Event Timeline
Log In to Comment