Page MenuHomeIn-Portal Phabricator

in-portal
No OneTemporary

File Metadata

Created
Sun, Feb 2, 2:23 AM

in-portal

Index: trunk/kernel/units/modules/modules_config.php
===================================================================
--- trunk/kernel/units/modules/modules_config.php (revision 2059)
+++ trunk/kernel/units/modules/modules_config.php (revision 2060)
@@ -1,41 +1,41 @@
<?php
$config = Array(
'Prefix' => 'mod',
'ItemClass' => Array('class'=>'kDBItem','file'=>'','build_event'=>'OnItemBuild'),
'ListClass' => Array('class'=>'kDBList','file'=>'','build_event'=>'OnListBuild'),
'EventHandlerClass' => Array('class'=>'ModulesEventHandler','file'=>'modules_event_handler.php','build_event'=>'OnBuild'),
- 'TagProcessorClass' => Array('class'=>'kDBTagProcessor','file'=>'','build_event'=>'OnBuild'),
+ 'TagProcessorClass' => Array('class'=>'ModulesTagProcessor','file'=>'modules_tag_processor.php','build_event'=>'OnBuild'),
'AutoLoad' => true,
'hooks' => Array(),
'QueryString' => Array(
1 => 'id',
2 => 'page',
3 => 'event',
),
'IDField' => 'Name',
'TitleField' => 'Name', // field, used in bluebar when editing existing item
'TableName' => TABLE_PREFIX.'Modules',
'ListSQLs' => Array( ''=>'SELECT * FROM %s',
), // key - special, value - list select sql
'ItemSQLs' => Array( ''=>'SELECT * FROM %s',
),
'ListSortings' => Array(),
'Fields' => Array(
'Name' => Array('type' => 'string','not_null' => '1','default' => ''),
'Path' => Array('type' => 'string','not_null' => '1','default' => ''),
'Var' => Array('type' => 'string','not_null' => '1','default' => ''),
'Version' => Array('type' => 'string','not_null' => '1','default' => ''),
'Loaded' => Array('type' => 'int','not_null' => '1','default' => '1'),
'LoadOrder' => Array('type' => 'int','not_null' => '1','default' => '0'),
'TemplatePath' => Array('type' => 'string','not_null' => '1','default' => ''),
'RootCat' => Array('type' => 'int','not_null' => '1','default' => '0'),
'BuildDate' => Array('type' => 'double','not_null' => '1','default' => '0'),
),
'VirtualFields' => Array(),
'Grids' => Array(),
);
?>
\ No newline at end of file
Property changes on: trunk/kernel/units/modules/modules_config.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/kernel/units/modules/modules_tag_processor.php
===================================================================
--- trunk/kernel/units/modules/modules_tag_processor.php (nonexistent)
+++ trunk/kernel/units/modules/modules_tag_processor.php (revision 2060)
@@ -0,0 +1,15 @@
+<?php
+
+class ModulesTagProcessor extends kDBTagProcessor {
+
+ function ModuleInstalled($params)
+ {
+ $module = $this->SelectParam($params, 'name,module');
+ $sql = 'SELECT Loaded FROM '.$this->Application->getUnitOption('mod', 'TableName').'
+ WHERE Name = "'.$module.'"';
+ return $this->Conn->GetOne($sql) ? 1 : 0;
+ }
+
+}
+
+?>
\ No newline at end of file
Property changes on: trunk/kernel/units/modules/modules_tag_processor.php
___________________________________________________________________
Added: cvs2svn:cvs-rev
## -0,0 +1 ##
+1.1
\ No newline at end of property
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property
Index: trunk/core/kernel/event_manager.php
===================================================================
--- trunk/core/kernel/event_manager.php (revision 2059)
+++ trunk/core/kernel/event_manager.php (revision 2060)
@@ -1,260 +1,268 @@
<?php
define('hBEFORE',1);
define('hAFTER',2);
class kEventManager extends kDBBase {
/**
* Cache of QueryString parameters
* from config, that are represented
* in enviroment variable
*
* @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)
{
if (!$event->SkipBeforeHooks) {
$this->processHooks($event, hBEFORE);
if ($event->status == erFATAL) return;
}
$event_handler =& $this->Application->recallObject($event->Prefix.'_EventHandler');
$event_handler->processEvent($event);
if ($event->status == erFATAL) return;
if (!$event->SkipAfterHooks) {
$this->processHooks($event, hAFTER);
}
}
function ProcessRequest()
{
$this->processOpener();
// 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');
}
}
$actions = $this->Application->GetVar('do');
if ($actions) {
list($prefix, $event_name) = explode('_', $actions);
$events[$prefix] = $event_name;
}
}
$passed = explode(',', $this->Application->GetVar('passed'));
foreach($events as $prefix_special => $event_name)
{
if(!$event_name) continue;
if( is_array($event_name) )
{
$event_name = key($event_name);
$events[$prefix_special] = $event_name;
$this->Application->SetVar($prefix_special.'_event', $event_name);
}
$event = new kEvent();
$event->Name=$event_name;
$event->Prefix_Special=$prefix_special;
$prefix_special=explode('.',$prefix_special);
$event->Prefix=$prefix_special[0];
array_push($passed, $prefix_special[0]);
$event->Special=isset($prefix_special[1])?$prefix_special[1]:'';
$event->redirect_params = Array('opener'=>'s', 'pass'=>'all');
$event->redirect = true;
$this->HandleEvent($event);
if($event->status==erSUCCESS && ($event->redirect === true || strlen($event->redirect) > 0) )
{
$this->Application->Redirect($event->redirect, $event->redirect_params, null, $event->redirect_script);
}
}
$this->Application->SetVar('events', $events);
$this->Application->SetVar('passed', implode(',', $passed));
}
function processOpener()
{
$opener_action=$this->Application->GetVar('m_opener');
$opener_stack=$this->Application->RecallVar('opener_stack');
$opener_stack=$opener_stack?unserialize($opener_stack):Array();
switch($opener_action)
{
case 'r': // "reset" opener stack
$opener_stack=Array();
break;
case 'd': // "down/push" new template to opener stack, deeplevel++
if ($this->Application->GetVar('front')) {
array_push($opener_stack, '../'.$this->Application->RecallVar('last_template') );
}
else {
array_push($opener_stack, $this->Application->RecallVar('last_template') );
}
break;
case 'u': // "up/pop" last template from opener stack, deeplevel--
array_pop($opener_stack);
break;
default: // "s/0," stay on same deep level
break;
}
$this->Application->SetVar('m_opener','s');
$this->Application->StoreVar('opener_stack',serialize($opener_stack));
}
function registerHook($hookto_prefix, $hookto_special, $hookto_event, $mode, $do_prefix, $do_special, $do_event, $conditional)
{
+ if( !$this->Application->getUnitOptions($hookto_prefix) )
+ {
+ if($this->Application->isDebugMode())
+ {
+ trigger_error('Prefix <b>'.$hookto_prefix.'</b> doesn\'t exist when trying to hook from <b>'.$do_prefix.':'.$do_event.'</b>', E_USER_WARNING);
+ }
+ return;
+ }
$hookto_prefix_special = rtrim($hookto_prefix.'.'.$hookto_special, '.');
if ($mode == hBEFORE) {
$this->beforeHooks[strtolower($hookto_prefix_special.'.'.$hookto_event)][] = Array(
'DoPrefix' => $do_prefix,
'DoSpecial' => $do_special,
'DoEvent' => $do_event,
'Conditional' => $conditional,
);
}
elseif ($mode == hAFTER) {
$this->afterHooks[strtolower($hookto_prefix_special.'.'.$hookto_event)][] = Array(
'DoPrefix' => $do_prefix,
'DoSpecial' => $do_special,
'DoEvent' => $do_event,
'Conditional' => $conditional,
);
}
}
/**
* Enter description here...
*
* @param kEvent $event
* @param int $mode hBEFORE or hAFTER
*/
function processHooks(&$event, $mode)
{
if ($mode == hBEFORE) {
$mode_hooks =& $this->beforeHooks;
}
else {
$mode_hooks =& $this->afterHooks;
}
if ( $hooks = getArrayValue($mode_hooks, strtolower($event->Prefix_Special.'.'.$event->Name)) ) {
foreach($hooks as $hook)
{
$prefix_special = rtrim($hook['DoPrefix'].'_'.$hook['DoSpecial'],'_');
if( $hook['Conditional'] && !$this->Application->GetVar($prefix_special) ) continue;
$hook_event = new kEvent( Array('name'=>$hook['DoEvent'],'prefix'=>$hook['DoPrefix'],'special'=>$hook['DoSpecial']) );
$hook_event->MasterEvent =& $event;
$this->HandleEvent($hook_event);
}
}
}
/**
* 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.6
\ No newline at end of property
+1.7
\ No newline at end of property
Index: trunk/core/kernel/processors/main_processor.php
===================================================================
--- trunk/core/kernel/processors/main_processor.php (revision 2059)
+++ trunk/core/kernel/processors/main_processor.php (revision 2060)
@@ -1,754 +1,754 @@
<?php
class MainProcessor extends TagProcessor {
function Init($prefix,$special)
{
parent::Init($prefix,$special);
$actions =& $this->Application->recallObject('kActions');
$actions->Set('t', $this->Application->GetVar('t'));
$actions->Set('sid', $this->Application->GetSID());
$actions->Set('m_opener', $this->Application->GetVar('m_opener') );
}
/**
* Used to handle calls where tag name
* match with existing php function name
*
* @param Tag $tag
* @return string
*/
function ProcessTag(&$tag)
{
if ($tag->Tag=='include') $tag->Tag='MyInclude';
return parent::ProcessTag($tag);
}
/**
* Creates <base href ..> HTML tag for all templates
* affects future css, js files and href params of links
*
* @return string
* @access public
*/
function Base_Ref()
{
$url = $this->Application->BaseURL().substr(THEMES_PATH,1).'/';
return '<base href="'.$url.'" />';
}
/**
* Returns base url for web-site
*
* @return string
* @access public
*/
function BaseURL()
{
return $this->Application->BaseURL();
}
function TemplatesBase($params)
{
return $this->Application->BaseURL().THEMES_PATH;
}
function ProjectBase($params)
{
return $this->Application->BaseURL();
}
/*function Base($params)
{
return $this->Application->BaseURL().$params['add'];
}*/
/**
* Used to create link to any template.
* use "pass" paramter if "t" tag to specify
* prefix & special of object to be represented
* in resulting url
*
* @param Array $params
* @return string
* @access public
*/
function T($params)
{
//by default link to current template
$t = $this->SelectParam($params, 't,template');
if ($t === false) {
$t = $this->Application->GetVar('t');
}
unset($params['t']);
unset($params['template']);
$prefix=isset($params['prefix']) ? $params['prefix'] : ''; unset($params['prefix']);
$index_file = isset($params['index_file']) ? $params['index_file'] : null; unset($params['index_file']);
/*$pass=isset($params['pass']) ? $params['pass'] : $this->Application->GetVar('t_pass'); unset($params['pass']);
$this->Application->SetVar('t_pass', $pass);
$pass_events = isset($params['pass_events']) && $params['pass_events'] ? 1 : 0; unset($params['pass_events']);
$this->Application->SetVar('t_pass_events', $pass_events);*/
//Use only implicit params passing, do not set into APP
// $this->Set($params); // set other params as application vars
return str_replace('&', '&amp;', $this->Application->HREF($t,$prefix,$params,$index_file));
}
function Link($params)
{
if (isset($params['template'])) {
$params['t'] = $params['template'];
unset($params['template']);
}
if (!isset($params['pass']) && !isset($params['no_pass'])) $params['pass'] = 'm';
if (isset($params['no_pass'])) unset($params['no_pass']);
return $this->T($params);
}
function Env($params)
{
$t = $params['template'];
unset($params['template']);
return $this->Application->BuildEnv($t, $params, 'm', null, false);
}
function FormAction($params)
{
return $this->Application->ProcessParsedTag('m', 't', Array( 'pass'=>'all,m' ) );
}
/*// NEEDS TEST
function Config($params)
{
return $this->Application->ConfigOption($params['var']);
}
function Object($params)
{
$name = $params['name'];
$method = $params['method'];
$tmp =& $this->Application->recallObject($name);
if ($tmp != null) {
if (method_exists($tmp, $method))
return $tmp->$method($params);
else
echo "Method $method does not exist in object ".get_class($tmp)." named $name<br>";
}
else
echo "Object $name does not exist in the appliaction<br>";
}*/
/**
* Tag, that always returns true.
* For parser testing purposes
*
* @param Array $params
* @return bool
* @access public
*/
function True($params)
{
return true;
}
/**
* Tag, that always returns false.
* For parser testing purposes
*
* @param Array $params
* @return bool
* @access public
*/
function False($params)
{
return false;
}
/**
* Returns block parameter by name
*
* @param Array $params
* @return stirng
* @access public
*/
function Param($params)
{
//$parser =& $this->Application->recallObject('TemplateParser');
$res = $this->Application->Parser->GetParam($params['name']);
if ($res === false) $res = '';
if (isset($params['plus']))
$res += $params['plus'];
return $res;
}
/**
* Compares block parameter with value specified
*
* @param Array $params
* @return bool
* @access public
*/
function ParamEquals($params)
{
//$parser =& $this->Application->recallObject('TemplateParser');
$name = $this->SelectParam($params, 'name,var,param');
$value = $params['value'];
return ($this->Application->Parser->GetParam($name) == $value);
}
/*function PHP_Self($params)
{
return $HTTP_SERVER_VARS['PHP_SELF'];
}
*/
/**
* Returns session variable value by name
*
* @param Array $params
* @return string
* @access public
*/
function Recall($params)
{
$ret = $this->Application->RecallVar( $this->SelectParam($params,'name,var,param') );
$ret = ($ret === false && isset($params['no_null'])) ? '' : $ret;
if( getArrayValue($params,'special') || getArrayValue($params,'htmlchars')) $ret = htmlspecialchars($ret);
return $ret;
}
// bad style to store something from template to session !!! (by Alex)
// Used here only to test how session works, nothing more
function Store($params)
{
//echo"Store $params[name]<br>";
$name = $params['name'];
$value = $params['value'];
$this->Application->StoreVar($name,$value);
}
/**
* Sets application variable value(-s)
*
* @param Array $params
* @access public
*/
function Set($params)
{
foreach ($params as $param => $value) {
$this->Application->SetVar($param, $value);
}
}
/**
* Increment application variable
* specified by number specified
*
* @param Array $params
* @access public
*/
function Inc($params)
{
$this->Application->SetVar($params['param'], $this->Application->GetVar($params['param']) + $params['by']);
}
/**
* Retrieves application variable
* value by name
*
* @param Array $params
* @return string
* @access public
*/
function Get($params)
{
$ret = $this->Application->GetVar($this->SelectParam($params, 'name,var,param'), EMPTY_ON_NULL);
return getArrayValue($params, 'htmlchars') ? htmlspecialchars($ret) : $ret;
}
/**
* Retrieves application constant
* value by name
*
* @param Array $params
* @return string
* @access public
*/
function GetConst($params)
{
return defined($this->SelectParam($params, 'name,const')) ? constant($this->SelectParam($params, 'name,const,param')) : '';
}
/*function Config_Equals($params)
{
foreach ($params as $name => $val) {
if (in_array($name, Array( 'prefix', 'function'))) continue;
return $this->Application->ConfigOption($name) == $val;
}
return false;
}*/
/**
* Creates all hidden fields
* needed for kernel_form
*
* @param Array $params
* @return string
* @access public
*/
function DumpSystemInfo($params)
{
$actions =& $this->Application->recallObject('kActions');
$actions->Set('t', $this->Application->GetVar('t') );
$params = $actions->GetParams();
$o='';
foreach ($params AS $name => $val)
{
$o .= "<input type='hidden' name='$name' id='$name' value='$val'>\n";
}
return $o;
}
function GetFormHiddens($params)
{
$sid = $this->Application->GetSID();
$t = $this->SelectParam($params, 'template,t');
unset($params['template']);
$env = $this->Application->BuildEnv($t, $params, 'm', null, false);
$o = '';
if (defined('MOD_REWRITE') && MOD_REWRITE) {
$session =& $this->Application->recallObject('Session');
if ($session->NeedQueryString()) {
$o .= "<input type='hidden' name='sid' id='sid' value='$sid'>\n";
}
}
else {
$o .= "<input type='hidden' name='env' id='env' value='$env'>\n";
}
return $o;
}
function Odd_Even($params)
{
$odd = $params['odd'];
$even = $params['even'];
if (!isset($params['var'])) {
$var = 'odd_even';
}
else {
$var = $params['var'];
}
if ($this->Application->GetVar($var) == 'even') {
$this->Application->SetVar($var, 'odd');
return $even;
}
else {
$this->Application->SetVar($var, 'even');
return $odd;
}
}
/**
* Returns phrase translation by name
*
* @param Array $params
* @return string
* @access public
*/
function Phrase($params)
{
// m:phrase name="phrase_name" default="Tr-alala" updated="2004-01-29 12:49"
if (array_key_exists('default', $params)) return $params['default']; //backward compatibility
return $this->Application->Phrase($this->SelectParam($params, 'label,name,title'));
}
// for tabs
function is_active($params)
{
$test_templ = $this->SelectParam($params, 'templ,template,t');
if ( !getArrayValue($params,'allow_empty') )
{
$if_true=getArrayValue($params,'true') ? $params['true'] : 1;
$if_false=getArrayValue($params,'false') ? $params['false'] : 0;
}
else
{
$if_true=$params['true'];
$if_false=$params['false'];
}
if ( preg_match("/^".str_replace('/', '\/', $test_templ)."/", $this->Application->GetVar('t'))) {
return $if_true;
}
else {
return $if_false;
}
}
function IsNotActive($params)
{
return !$this->is_active($params);
}
function IsActive($params)
{
return $this->is_active($params);
}
function is_t_active($params)
{
return $this->is_active($params);
}
function CurrentTemplate($params)
{
return $this->is_active($params);
}
/**
* Checks if session variable
* specified by name value match
* value passed as parameter
*
* @param Array $params
* @return string
* @access public
*/
function RecallEquals($params)
{
$name = $params['var'];
$value = $params['value'];
return ($this->Application->RecallVar($name) == $value);
}
/**
* Checks if application variable
* specified by name value match
* value passed as parameter
*
* @param Array $params
* @return bool
* @access public
*/
function GetEquals($params)
{
$name = $this->SelectParam($params, 'var,name,param');
$value = $params['value'];
if ($this->Application->GetVar($name) == $value) {
return 1;
}
}
/**
* Includes template
* and returns it's
* parsed version
*
* @param Array $params
* @return string
* @access public
*/
function MyInclude($params)
{
$BlockParser =& $this->Application->makeClass('TemplateParser');
$BlockParser->SetParams($params);
$parser =& $this->Application->Parser;
$this->Application->Parser =& $BlockParser;
$t = $this->SelectParam($params, 't,template,block,name');
$t = eregi_replace("\.tpl$", '', $t);
$templates_cache =& $this->Application->recallObject('TemplatesCache');
$res = $BlockParser->Parse( $templates_cache->GetTemplateBody($t), $t );
if ( !$BlockParser->DataExists && (isset($params['data_exists']) || isset($params['block_no_data'])) ) {
if ($block_no_data = getArrayValue($params, 'block_no_data')) {
$res = $BlockParser->Parse(
$templates_cache->GetTemplateBody($block_no_data, $silent),
$t
);
}
else {
$res = '';
}
}
$this->Application->Parser =& $parser;
$this->Application->Parser->DataExists = $this->Application->Parser->DataExists || $BlockParser->DataExists;
return $res;
}
/*function Kernel_Scripts($params)
{
return '<script type="text/javascript" src="'.PROTOCOL.SERVER_NAME.BASE_PATH.'/kernel3/js/grid.js"></script>';
}*/
/*function GetUserPermission($params)
{
// echo"GetUserPermission $params[name]";
if ($this->Application->RecallVar('user_type') == 1)
return 1;
else {
$perm_name = $params[name];
$aPermissions = unserialize($this->Application->RecallVar('user_permissions'));
if ($aPermissions)
return $aPermissions[$perm_name];
}
}*/
/**
* Set's parser block param value
*
* @param Array $params
* @access public
*/
function AddParam($params)
{
$parser =& $this->Application->Parser; // recallObject('TemplateParser');
foreach ($params as $param => $value) {
$this->Application->SetVar($param, $value);
$parser->SetParam($param, $value);
$parser->AddParam('/\$'.$param.'/', $value);
}
}
/*function ParseToVar($params)
{
$var = $params['var'];
$tagdata = $params['tag'];
$parser =& $this->Application->Parser; //recallObject('TemplateParser');
$res = $this->Application->ProcessTag($tagdata);
$parser->SetParam($var, $res);
$parser->AddParam('/\$'.$var.'/', $res);
return '';
}*/
/*function TagNotEmpty($params)
{
$tagdata = $params['tag'];
$res = $this->Application->ProcessTag($tagdata);
return $res != '';
}*/
/*function TagEmpty($params)
{
return !$this->TagNotEmpty($params);
}*/
/**
* Parses block and returns result
*
* @param Array $params
* @return string
* @access public
*/
function ParseBlock($params)
{
$parser =& $this->Application->Parser; // recallObject('TemplateParser');
return $parser->ParseBlock($params);
}
function RenderElement($params)
{
return $this->ParseBlock($params);
}
/**
* Checks if debug mode is on
*
* @return bool
* @access public
*/
function IsDebugMode()
{
return $this->Application->isDebugMode();
}
function MassParse($params)
{
$qty = $params['qty'];
$block = $params['block'];
$mode = $params['mode'];
$o = '';
if ($mode == 'func') {
$func = create_function('$params', '
$o = \'<tr>\';
$o.= \'<td>a\'.$params[\'param1\'].\'</td>\';
$o.= \'<td>a\'.$params[\'param2\'].\'</td>\';
$o.= \'<td>a\'.$params[\'param3\'].\'</td>\';
$o.= \'<td>a\'.$params[\'param4\'].\'</td>\';
$o.= \'</tr>\';
return $o;
');
for ($i=1; $i<$qty; $i++) {
$block_params['param1'] = rand(1, 10000);
$block_params['param2'] = rand(1, 10000);
$block_params['param3'] = rand(1, 10000);
$block_params['param4'] = rand(1, 10000);
$o .= $func($block_params);
}
return $o;
}
$block_params['name'] = $block;
for ($i=0; $i<$qty; $i++) {
$block_params['param1'] = rand(1, 10000);
$block_params['param2'] = rand(1, 10000);
$block_params['param3'] = rand(1, 10000);
$block_params['param4'] = rand(1, 10000);
$block_params['passed'] = $params['passed'];
$block_params['prefix'] = 'm';
$o.= $this->Application->ParseBlock($block_params, 1);
}
return $o;
}
function AfterScript($params)
{
$after_script = $this->Application->GetVar('after_script');
if ( $after_script ) {
return '<script type="text/javascript">'.$after_script.'</script>';
}
return '';
}
function LoggedIn($params)
{
return $this->Application->LoggedIn();
}
/**
* Checks if user is logged in and if not redirects it to template passed
*
* @param Array $params
*/
function RequireLogin($params)
{
if($permission_groups = getArrayValue($params, 'permissions'))
{
$permission_groups = explode('|', $permission_groups);
$group_has_permission = false;
foreach($permission_groups as $permission_group)
{
$permissions = explode(',', $permission_group);
$has_permission = true;
foreach($permissions as $permission)
{
$has_permission = $has_permission && $this->Application->CheckPermission($permission);
}
$group_has_permission = $group_has_permission || $has_permission;
if($group_has_permission)
{
return;
}
}
if( !$this->Application->LoggedIn() )
{
$t = $this->Application->GetVar('t');
$this->Application->Redirect( $params['login_template'], Array('next_template'=>$t) );
}
else
{
$this->Application->Redirect( $params['no_permissions_template'] );
}
}
$condition = getArrayValue($params,'condition');
if(!$condition)
{
$condition = true;
}
else
{
if( substr($condition,0,1) == '!' )
{
$condition = !$this->Application->ConfigValue( substr($condition,1) );
}
else
{
$condition = $this->Application->ConfigValue($condition);
}
}
if( !$this->Application->LoggedIn() && $condition )
{
$t = $this->Application->GetVar('t');
$this->Application->Redirect( $params['login_template'], Array('next_template'=>$t) );
}
}
function SaveReturnScript($params)
{
// admin/save_redirect.php?do=
$url = str_replace($this->Application->BaseURL(), '', $this->T($params) );
$url = explode('?', $url, 2);
$url = 'save_redirect.php?'.$url[1].'&do='.$url[0];
$this->Application->StoreVar('ReturnScript', $url);
}
function ConstOn($params)
{
$name = $this->SelectParam($params,'name,const');
return $this->Application->isDebugMode() && dbg_ConstOn($name);
}
function SetDefaultCategory($params)
{
$module_name = $params['module'];
$module =& $this->Application->recallObject('mod.'.$module_name);
$this->Application->SetVar('m_cat_id', $module->GetDBField('RootCat') );
}
-
+
/*
function Login($params)
{
$user_prefix = 'users';
$this->parser->registerprefix($user_prefix);
$user_class = $this->parser->processors[$user_prefix]->item_class;
$candidate = new $user_class(NULL, $this->parser->processors[$user_prefix]);
//print_pre($this->Session->Property);
$special = array_shift($params);
//echo"$special<br>";
$candidate_id = $candidate->Login($this->Session->GetProperty('username'), $this->Session->GetProperty('password'), $special);
if ($candidate_id !== false) {
$this->Session->SetField('user_id', $candidate_id);
$this->Session->Update();
$this->Session->AfterLogin();
$this->parser->register_prefix('m');
$template = array_shift($params);
if ($template == '') $template = 'index';
$location = $this->parser->do_process_tag('m', 't', Array($template));
header("Location: $location");
exit;
}
elseif ($this->Session->GetProperty('username') != '') {
$this->Session->SetProperty('login_error', 'Incorrect username or password');
}
}
*/
}
?>
\ No newline at end of file
Property changes on: trunk/core/kernel/processors/main_processor.php
___________________________________________________________________
Modified: cvs2svn:cvs-rev
## -1 +1 ##
-1.11
\ No newline at end of property
+1.12
\ No newline at end of property
Index: trunk/core/kernel/utility/unit_config_reader.php
===================================================================
--- trunk/core/kernel/utility/unit_config_reader.php (revision 2059)
+++ trunk/core/kernel/utility/unit_config_reader.php (revision 2060)
@@ -1,412 +1,412 @@
<?php
class kUnitConfigReader extends kBase {
/**
* Configs readed
*
* @var Array
* @access private
*/
var $configData=Array();
var $configFiles=Array();
var $CacheExpired = false;
/**
* Module names found during
* config reading
*
* @var Array
*/
var $modules_installed = Array();
/**
* Scan kernel and user classes
* for available configs
*
* @access protected
*/
function Init($prefix,$special)
{
parent::Init($prefix,$special);
$db =& $this->Application->GetADODBConnection();
- $this->modules_installed = $db->GetCol('SELECT CONCAT(\'/\',Path) AS Path, Name FROM '.TABLE_PREFIX.'Modules','Name');
+ $this->modules_installed = $db->GetCol('SELECT CONCAT(\'/\',Path) AS Path, Name FROM '.TABLE_PREFIX.'Modules WHERE Loaded = 1','Name');
$this->scanModules(MODULES_PATH);
}
/**
* Checks if config file is allowed for includion (if module of config is installed)
*
* @param string $config_path relative path from in-portal directory
*/
function configAllowed($config_path)
{
$module_found = false;
foreach($this->modules_installed as $module_path)
{
if( substr($config_path, 0, strlen($module_path)) == $module_path )
{
$module_found = true;
break;
}
}
return $module_found;
}
/**
* Read configs from all directories
* on path specified
*
* @param string $folderPath
* @access public
*/
function processFolder($folderPath, $cached)
{
$fh=opendir($folderPath);
while(($sub_folder=readdir($fh)))
{
$full_path=$folderPath.'/'.$sub_folder;
if( $this->isDir($full_path) && file_exists($this->getConfigName($full_path)) )
{
if (filemtime($full_path) > $cached) {
$this->CacheExpired = true;
$file = $this->getConfigName($full_path);
if ( defined('DEBUG_MODE') && dbg_ConstOn('DBG_PROFILE_INCLUDES')) {
if ( in_array($file, get_required_files()) ) return;
global $debugger;
$debugger->IncludeLevel++;
$before_time = getmicrotime();
$before_mem = memory_get_usage();
include_once(DOC_ROOT.BASE_PATH.$file);
$used_time = getmicrotime() - $before_time;
$used_mem = memory_get_usage() - $before_mem;
$debugger->IncludeLevel--;
$debugger->IncludesData['file'][] = str_replace(DOC_ROOT.BASE_PATH, '', $file);
$debugger->IncludesData['mem'][] = $used_mem;
$debugger->IncludesData['time'][] = $used_time;
$debugger->IncludesData['level'][] = -1;
}
else {
include_once($file);
}
$prefix=$config['Prefix'];
$config['BasePath']=$full_path;
$this->configData[$prefix] = $config;
}
}
}
}
function ParseConfigs()
{
foreach ($this->configData as $prefix => $config)
{
$this->parseConfig($prefix);
}
}
function findConfigFiles($folderPath)
{
$folderPath = str_replace(DOC_ROOT.BASE_PATH, '', $folderPath);
$fh=opendir(DOC_ROOT.BASE_PATH.$folderPath);
while(($sub_folder=readdir($fh)))
{
$full_path=DOC_ROOT.BASE_PATH.$folderPath.'/'.$sub_folder;
if( $this->isDir($full_path))
{
if ( file_exists(DOC_ROOT.BASE_PATH.$this->getConfigName($folderPath.'/'.$sub_folder)) ) {
$this->configFiles[] = $this->getConfigName($folderPath.'/'.$sub_folder);
}
$this->findConfigFiles($full_path);
// if (filemtime($full_path) > $cached) { }
}
}
}
function includeConfigFiles()
{
$db =& $this->Application->GetADODBConnection();
foreach ($this->configFiles as $filename)
{
$config_found = file_exists(DOC_ROOT.BASE_PATH.$filename) && $this->configAllowed($filename);
if( defined('DEBUG_MODE') && DEBUG_MODE && dbg_ConstOn('DBG_PROFILE_INCLUDES'))
{
if ( in_array($filename, get_required_files()) ) return;
global $debugger;
$debugger->IncludeLevel++;
$before_time = getmicrotime();
$before_mem = memory_get_usage();
if($config_found) include_once(DOC_ROOT.BASE_PATH.$filename);
$used_time = getmicrotime() - $before_time;
$used_mem = memory_get_usage() - $before_mem;
$debugger->IncludeLevel--;
$debugger->IncludesData['file'][] = str_replace(DOC_ROOT.BASE_PATH, '', $filename);
$debugger->IncludesData['mem'][] = $used_mem;
$debugger->IncludesData['time'][] = $used_time;
$debugger->IncludesData['level'][] = -1;
}
else
{
if($config_found) include_once(DOC_ROOT.BASE_PATH.$filename);
}
if($config_found)
{
$prefix = $config['Prefix'];
$config['BasePath'] = dirname(DOC_ROOT.BASE_PATH.$filename);
$this->configData[$prefix] = $config;
}
}
}
function scanModules($folderPath)
{
global $debugger;
if (defined('CACHE_CONFIGS_FILES')) {
$conn =& $this->Application->GetADODBConnection();
$data = $conn->GetRow('SELECT Data, Cached FROM '.TABLE_PREFIX.'Cache WHERE VarName = "config_files"');
if ($data && $data['Cached'] > (time() - 3600) ) {
$this->configFiles = unserialize($data['Data']);
$files_cached = $data['Cached'];
}
else {
$files_cached = 0;
}
}
else {
$files_cached = 0;
}
if (defined('CACHE_CONFIGS_DATA')) {
$conn =& $this->Application->GetADODBConnection();
$data = $conn->GetRow('SELECT Data, Cached FROM '.TABLE_PREFIX.'Cache WHERE VarName = "config_data"');
if ($data && $data['Cached'] > (time() - 3600) ) {
$this->configData = unserialize($data['Data']);
$data_cached = $data['Cached'];
}
else {
$data_cached = 0;
}
}
else {
$data_cached = 0;
}
if ( !defined('CACHE_CONFIGS_FILES') || $files_cached == 0 ) {
$this->findConfigFiles($folderPath);
}
if ( !defined('CACHE_CONFIGS_DATA') || $data_cached == 0) {
$this->includeConfigFiles();
}
/*// && (time() - $cached) > 600) - to skip checking files modified dates
if ( !defined('CACHE_CONFIGS') ) {
$fh=opendir($folderPath);
while(($sub_folder=readdir($fh)))
{
$full_path=$folderPath.'/'.$sub_folder.'/units';
if( $this->isDir($full_path) )
{
$this->processFolder($full_path, $cached);
}
}
}*/
$this->ParseConfigs();
if (defined('CACHE_CONFIGS_FILES') && $files_cached == 0) {
$conn->Query('REPLACE '.TABLE_PREFIX.'Cache (VarName, Data, Cached) VALUES ("config_files", '.$conn->qstr(serialize($this->configFiles)).', '.time().')');
}
if (defined('CACHE_CONFIGS_DATA') && $data_cached == 0) {
$conn->Query('REPLACE '.TABLE_PREFIX.'Cache (VarName, Data, Cached) VALUES ("config_data", '.$conn->qstr(serialize($this->configData)).', '.time().')');
}
unset($this->configFiles);
// unset($this->configData);
}
/**
* Register nessasary classes
*
* @param string $prefix
* @access private
*/
function parseConfig($prefix)
{
$config =& $this->configData[$prefix];
$event_manager =& $this->Application->recallObject('EventManager');
$class_params=Array('ItemClass','ListClass','EventHandlerClass','TagProcessorClass');
foreach($class_params as $param_name)
{
if ( !(isset($config[$param_name]) ) ) continue;
$class_info =& $config[$param_name];
$pseudo_class = $this->getPrefixByParamName($param_name,$prefix);
$this->Application->registerClass( $class_info['class'],
$config['BasePath'].'/'.$class_info['file'],
$pseudo_class);
$event_manager->registerBuildEvent($pseudo_class,$class_info['build_event']);
}
$register_classes = getArrayValue($config,'RegisterClasses');
if($register_classes)
{
foreach($register_classes as $class_info)
{
$this->Application->registerClass( $class_info['class'],
$config['BasePath'].'/'.$class_info['file'],
$class_info['pseudo']);
//$event_manager->registerBuildEvent($class_info['pseudo'],$class_info['build_event']);
}
}
if ( is_array(getArrayValue($config, 'Hooks')) ) {
foreach ($config['Hooks'] as $hook) {
$do_prefix = $hook['DoPrefix'] == '' ? $config['Prefix'] : $hook['DoPrefix'];
if ( !is_array($hook['HookToEvent']) ) {
$hook_events = Array( $hook['HookToEvent'] );
}
else {
$hook_events = $hook['HookToEvent'];
}
foreach ($hook_events as $hook_event) {
$this->Application->registerHook($hook['HookToPrefix'], $hook['HookToSpecial'], $hook_event, $hook['Mode'], $do_prefix, $hook['DoSpecial'], $hook['DoEvent'], $hook['Conditional']);
}
}
}
if ( is_array(getArrayValue($config, 'AggregateTags')) ) {
foreach ($config['AggregateTags'] as $aggregate_tag) {
$aggregate_tag['LocalPrefix'] = $config['Prefix'];
$this->Application->registerAggregateTag($aggregate_tag);
}
}
if ( $this->Application->isDebugMode() && dbg_ConstOn('DBG_VALIDATE_CONFIGS') && isset($config['TableName']) )
{
global $debugger;
$tablename = $config['TableName'];
$conn =& $this->Application->GetADODBConnection();
$res = $conn->Query("DESCRIBE $tablename");
foreach ($res as $field) {
$f_name = $field['Field'];
if (getArrayValue($config, 'Fields')) {
if ( !array_key_exists ($f_name, $config['Fields']) ) {
$debugger->appendHTML("<b class='debug_error'>Config Warning: </b>Field $f_name exists in the database, but is not defined in config file for prefix <b>".$config['Prefix']."</b>!");
safeDefine('DBG_RAISE_ON_WARNINGS', 1);
}
else {
$options = $config['Fields'][$f_name];
if ($field['Null'] == '') {
if ( $f_name != $config['IDField'] && !isset($options['not_null']) && !isset($options['required']) ) {
$debugger->appendHTML("<b class='debug_error'>Config Error: </b>Field $f_name in config for prefix <b>".$config['Prefix']."</b> is NOT NULL in the database, but is not configured as not_null or required!");
safeDefine('DBG_RAISE_ON_WARNINGS', 1);
}
if ( isset($options['not_null']) && !isset($options['default']) ) {
$debugger->appendHTML("<b class='debug_error'>Config Error: </b>Field $f_name in config for prefix <b>".$config['Prefix']."</b> is described as NOT NULL, but does not have DEFAULT value!");
safeDefine('DBG_RAISE_ON_WARNINGS', 1);
}
}
}
}
}
}
}
/**
* Reads unit (specified by $prefix)
* option specified by $option
*
* @param string $prefix
* @param string $option
* @return string
* @access public
*/
function getUnitOption($prefix,$name)
{
return isset($this->configData[$prefix][$name])?$this->configData[$prefix][$name]:false;
}
/**
* Read all unit with $prefix options
*
* @param string $prefix
* @return Array
* @access public
*/
function getUnitOptions($prefix)
{
return isset($this->configData[$prefix])?$this->configData[$prefix]:false;
}
/**
* Set's new unit option value
*
* @param string $prefix
* @param string $name
* @param string $value
* @access public
*/
function setUnitOption($prefix,$name,$value)
{
$this->configData[$prefix][$name]=$value;
}
function getPrefixByParamName($paramName,$prefix)
{
$pseudo_class_map=Array(
'ItemClass'=>'%s',
'ListClass'=>'%s_List',
'EventHandlerClass'=>'%s_EventHandler',
'TagProcessorClass'=>'%s_TagProcessor'
);
return sprintf($pseudo_class_map[$paramName],$prefix);
}
/**
* Get's config file name based
* on folder name supplied
*
* @param string $folderPath
* @return string
* @access private
*/
function getConfigName($folderPath)
{
return $folderPath.'/'.basename($folderPath).'_config.php';
}
/**
* is_dir ajustment to work with
* directory listings too
*
* @param string $folderPath
* @return bool
* @access private
*/
function isDir($folderPath)
{
$base_name=basename($folderPath);
$ret=!($base_name=='.'||$base_name=='..');
return $ret&&is_dir($folderPath);
}
}
?>
\ No newline at end of file
Property changes on: trunk/core/kernel/utility/unit_config_reader.php
___________________________________________________________________
Modified: cvs2svn:cvs-rev
## -1 +1 ##
-1.6
\ No newline at end of property
+1.7
\ No newline at end of property
Index: trunk/core/units/modules/modules_config.php
===================================================================
--- trunk/core/units/modules/modules_config.php (revision 2059)
+++ trunk/core/units/modules/modules_config.php (revision 2060)
@@ -1,41 +1,41 @@
<?php
$config = Array(
'Prefix' => 'mod',
'ItemClass' => Array('class'=>'kDBItem','file'=>'','build_event'=>'OnItemBuild'),
'ListClass' => Array('class'=>'kDBList','file'=>'','build_event'=>'OnListBuild'),
'EventHandlerClass' => Array('class'=>'ModulesEventHandler','file'=>'modules_event_handler.php','build_event'=>'OnBuild'),
- 'TagProcessorClass' => Array('class'=>'kDBTagProcessor','file'=>'','build_event'=>'OnBuild'),
+ 'TagProcessorClass' => Array('class'=>'ModulesTagProcessor','file'=>'modules_tag_processor.php','build_event'=>'OnBuild'),
'AutoLoad' => true,
'hooks' => Array(),
'QueryString' => Array(
1 => 'id',
2 => 'page',
3 => 'event',
),
'IDField' => 'Name',
'TitleField' => 'Name', // field, used in bluebar when editing existing item
'TableName' => TABLE_PREFIX.'Modules',
'ListSQLs' => Array( ''=>'SELECT * FROM %s',
), // key - special, value - list select sql
'ItemSQLs' => Array( ''=>'SELECT * FROM %s',
),
'ListSortings' => Array(),
'Fields' => Array(
'Name' => Array('type' => 'string','not_null' => '1','default' => ''),
'Path' => Array('type' => 'string','not_null' => '1','default' => ''),
'Var' => Array('type' => 'string','not_null' => '1','default' => ''),
'Version' => Array('type' => 'string','not_null' => '1','default' => ''),
'Loaded' => Array('type' => 'int','not_null' => '1','default' => '1'),
'LoadOrder' => Array('type' => 'int','not_null' => '1','default' => '0'),
'TemplatePath' => Array('type' => 'string','not_null' => '1','default' => ''),
'RootCat' => Array('type' => 'int','not_null' => '1','default' => '0'),
'BuildDate' => Array('type' => 'double','not_null' => '1','default' => '0'),
),
'VirtualFields' => Array(),
'Grids' => Array(),
);
?>
\ No newline at end of file
Property changes on: trunk/core/units/modules/modules_config.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/units/modules/modules_tag_processor.php
===================================================================
--- trunk/core/units/modules/modules_tag_processor.php (nonexistent)
+++ trunk/core/units/modules/modules_tag_processor.php (revision 2060)
@@ -0,0 +1,15 @@
+<?php
+
+class ModulesTagProcessor extends kDBTagProcessor {
+
+ function ModuleInstalled($params)
+ {
+ $module = $this->SelectParam($params, 'name,module');
+ $sql = 'SELECT Loaded FROM '.$this->Application->getUnitOption('mod', 'TableName').'
+ WHERE Name = "'.$module.'"';
+ return $this->Conn->GetOne($sql) ? 1 : 0;
+ }
+
+}
+
+?>
\ No newline at end of file
Property changes on: trunk/core/units/modules/modules_tag_processor.php
___________________________________________________________________
Added: cvs2svn:cvs-rev
## -0,0 +1 ##
+1.1
\ No newline at end of property
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property

Event Timeline