Page Menu
Home
In-Portal Phabricator
Search
Configure Global Search
Log In
Files
F773367
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:45 AM
Size
42 KB
Mime Type
text/x-diff
Expires
Tue, Feb 4, 9:45 AM (1 h, 59 m)
Engine
blob
Format
Raw Data
Handle
556597
Attached To
rINP In-Portal
in-portal
View Options
Index: trunk/core/kernel/event_manager.php
===================================================================
--- trunk/core/kernel/event_manager.php (revision 936)
+++ trunk/core/kernel/event_manager.php (revision 937)
@@ -1,192 +1,211 @@
<?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 $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();
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;
}
- function ProcessRequest()
+ /**
+ * 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
- // 1. process QueryString
$env_var =& $this->Application->GetVar(ENV_VAR_NAME);
- $query_maps=Array();
-
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);
- $query_maps[$prefix_special]=$this->Application->getUnitOption($prefix,'QueryString');
- foreach($query_maps[$prefix_special] as $index => $var_name)
+ $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($query_maps && !$events)
+ if($this->queryMaps && !$events)
{
// if we got $_GET type submit (links, not javascript)
- foreach($query_maps as $prefix_special => $query_map)
+ 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');
+ //$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.1
\ No newline at end of property
+1.2
\ No newline at end of property
Index: trunk/core/kernel/session/session.php
===================================================================
--- trunk/core/kernel/session/session.php (revision 936)
+++ trunk/core/kernel/session/session.php (revision 937)
@@ -1,486 +1,490 @@
<?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 laod it from the Storage (default is database)
+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;
-
- function SessionStorage()
- {
- parent::kDBBase();
- $this->OriginalData = Array();
- }
+ 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 * FROM %sSessions WHERE %s = %s",
+ $query = sprintf( "SELECT expire FROM %sSessions WHERE %s = %s",
TABLE_PREFIX,
'sid',
$sid);
- $result = $this->Conn->GetRow($query);
- if ($result === false || $result == NULL) {
- return false;
- }
- $this->Expiration = $result['expire'];
+ $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 (array_key_exists($key, $this->OriginalData) && $this->OriginalData[$key] == $value)
+ foreach ($ses_data as $key => $value)
+ {
+ if ( isset($this->OriginalData[$key]) && $this->OriginalData[$key] == $value)
+ {
continue; //skip unchanged session data
- else {
+ }
+ 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)
+ 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'];
+ $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');
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);
}
break;
case smCOOKIES_ONLY:
$sid = $http_query->Cookie[$this->CookieName];
break;
case smGET_ONLY:
$sid = $http_query->Get($this->GETName);
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 = '';
break;
}
$this->CachedSID = $sid;
return $this->CachedSID;
}
function GetID()
{
return $this->SID;
}
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->SID = $sid_part_1.$sid_part_2.$sid_part_3;
+ $this->setSID($sid_part_1.$sid_part_2.$sid_part_3);
return $this->SID;
}
+ 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
);
}
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)
+ function RecallVar($name,$default=false)
{
- return $this->Data->Get($name);
+ $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.1
\ No newline at end of property
+1.2
\ No newline at end of property
Index: trunk/core/kernel/application.php
===================================================================
--- trunk/core/kernel/application.php (revision 936)
+++ trunk/core/kernel/application.php (revision 937)
@@ -1,778 +1,784 @@
<?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();
- // to read configs before doing any recallObject
+ // 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->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('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('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.2
\ No newline at end of property
+1.3
\ No newline at end of property
Event Timeline
Log In to Comment