Page Menu
Home
In-Portal Phabricator
Search
Configure Global Search
Log In
Files
F803488
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
Tue, Feb 25, 1:05 PM
Size
77 KB
Mime Type
text/x-diff
Expires
Thu, Feb 27, 1:05 PM (23 h, 18 m)
Engine
blob
Format
Raw Data
Handle
576300
Attached To
rINP In-Portal
in-portal
View Options
Index: branches/5.2.x/core/kernel/managers/url_manager.php
===================================================================
--- branches/5.2.x/core/kernel/managers/url_manager.php (revision 15277)
+++ branches/5.2.x/core/kernel/managers/url_manager.php (revision 15278)
@@ -1,448 +1,457 @@
<?php
/**
* @version $Id$
* @package In-Portal
* @copyright Copyright (C) 1997 - 2010 Intechnic. All rights reserved.
* @license GNU/GPL
* In-Portal is Open Source software.
* This means that this software may have been modified pursuant
* the GNU General Public License, and as distributed it includes
* or is derivative of works licensed under the GNU General Public License
* or other free or open source software licenses.
* See http://www.in-portal.org/license for copyright notices and details.
*/
defined('FULL_PATH') or die('restricted access!');
class kUrlManager extends kBase {
/**
* Processor of plain urls (initialized always)
*
* @var kPlainUrlProcessor
* @access public
*/
public $plain = null;
/**
* Processor of rewritten urls (initialized on demand only)
*
* @var kRewriteUrlProcessor
* @access public
*/
public $rewrite = null;
/**
* Tells, that rewrite system is ready
*
* @var bool
* @access protected
*/
protected $rewriteReady = false;
/**
- * Physical template name mapping to their template names based on structure
+ * Physical template name mapping to their template names based in "Structure & Data" section
*
* @var Array
*/
protected $structureTemplateMapping = Array ();
/**
* Creates instead of kUrlManager class
*/
public function __construct()
{
parent::__construct();
// don't use kApplication::recallObject, since it will call kApplication::EventManager, which isn't ready yet
$this->plain = $this->Application->makeClass('kPlainUrlProcessor', Array (&$this));
}
/**
* Delay initialization of rewrite processor, since it uses site domains & http query
*
* @return void
* @access public
*/
public function initRewrite()
{
if ( $this->rewriteReady ) {
return;
}
$this->rewrite = $this->Application->recallObject('kRewriteUrlProcessor', null, Array (), Array (&$this));
$this->rewriteReady = true;
}
/**
* Return href for template
*
* @param string $t Template path
* @param string $prefix index.php prefix - could be blank, 'admin'
* @param Array $params
* @param string $index_file
* @return string
*/
public function HREF($t, $prefix = '', $params = Array (), $index_file = null)
{
static $theme_id = null;
if ( !isset($theme_id) ) {
$theme_id = $this->Application->GetVar('m_theme');
}
if ( !$t ) {
// when template not specified, use current
$t = $this->Application->GetVar('t');
}
$t = preg_replace('/^Content\//i', '', $t);
if ( substr($t, -4) == '.tpl' ) {
// cut template extension (deprecated link format)
$t = substr($t, 0, strlen($t) - 4);
}
if ( substr($t, 0, 3) == 'id:' ) {
// link to structure page using it's id
$params['m_cat_id'] = substr($t, 3);
$t = $this->structureTemplateMapping[$t];
}
if ( array_key_exists('use_section', $params) ) {
$use_section = $params['use_section'];
unset($params['use_section']);
}
if ( isset($use_section) && $use_section && array_key_exists($t . ':' . $theme_id, $this->structureTemplateMapping) ) {
// structure template corresponding to given physical template
$t = $this->structureTemplateMapping[$t . ':' . $theme_id];
unset($params['use_section']);
}
if ( preg_match('/external:(.*)/', $t, $regs) ) {
// external url
return $regs[1];
}
if ( $this->Application->isAdmin && $prefix == '' ) {
$prefix = ADMIN_DIRECTORY;
}
if ( $this->Application->isAdmin && $prefix == '_FRONT_END_' ) {
$prefix = '';
}
if ( isset($params['_auto_prefix_']) ) {
unset($params['_auto_prefix_']); // this is parser-related param, do not need to pass it here
}
$ssl = isset($params['__SSL__']) ? $params['__SSL__'] : null;
if ( $ssl !== null ) {
$session = $this->Application->recallObject('Session');
/* @var $session Session */
$target_url = rtrim($this->Application->BaseURL('', $ssl, false), '/');
$cookie_url = trim($session->CookieDomain . $session->CookiePath, '/.');
// set session to GET_ONLY, to pass sid only if sid is REAL AND session is set
if ( !preg_match('#' . preg_quote($cookie_url) . '#', $target_url) && $session->SessionSet ) {
// when SSL<->NON-SSL redirect to different domain pass SID in url
$session->SetMode(Session::smGET_ONLY);
}
}
if ( isset($params['opener']) && $params['opener'] == 'u' ) {
$ret = $this->processPopupClose($prefix, $params);
if ( $ret !== false ) {
return $ret;
}
else {
//define('DBG_REDIRECT', 1);
$t = $this->Application->GetVar('t');
}
}
$pass = isset($params['pass']) ? $params['pass'] : '';
// pass events with url
$pass_events = false;
if ( isset($params['pass_events']) ) {
$pass_events = $params['pass_events'];
unset($params['pass_events']);
}
$map_link = '';
if ( isset($params['anchor']) ) {
$map_link = '#' . $params['anchor'];
unset($params['anchor']);
}
if ( isset($params['no_amp']) ) {
$params['__URLENCODE__'] = $params['no_amp'];
unset($params['no_amp']);
}
$rewrite = true;
if ( isset($params['__NO_REWRITE__']) ) {
$rewrite = false;
unset($params['__NO_REWRITE__']);
}
$force_rewrite = false;
if ( isset($params['__MOD_REWRITE__']) ) {
$force_rewrite = true;
unset($params['__MOD_REWRITE__']);
}
$force_no_sid = false;
if ( isset($params['__NO_SID__']) ) {
$force_no_sid = true;
unset($params['__NO_SID__']);
}
// append pass through variables to each link to be build
$params = array_merge($this->getPassThroughVariables($params), $params);
if ( $force_rewrite || ($this->Application->RewriteURLs($ssl) && $rewrite) ) {
if ( !$this->rewriteReady ) {
$this->initRewrite();
}
$session = $this->Application->recallObject('Session');
if ( $session->NeedQueryString() && !$force_no_sid ) {
$params['sid'] = $this->Application->GetSID();
}
$url = $this->rewrite->build($t, $params, $pass, $pass_events);
}
else {
unset($params['pass_category']); // we don't need to pass it when mod_rewrite is off
$index_file = $this->getIndexFile($prefix, $index_file, $params);
$url = $index_file . '?' . $this->plain->build($t, $params, $pass, $pass_events);
}
return $this->Application->BaseURL($prefix, $ssl) . $url . $map_link;
}
/**
* Returns popup's parent window url and optionally removes it from opener stack
*
* @param string $prefix
* @param Array $params
* @return bool|string
* @access protected
*/
protected function processPopupClose($prefix = '', $params = Array ())
{
$opener_stack = $this->Application->makeClass('kOpenerStack');
/* @var $opener_stack kOpenerStack */
if ( $opener_stack->isEmpty() ) {
return false;
}
$ssl = isset($params['__SSL__']) ? $params['__SSL__'] : null;
list($index_file, $env) = explode('|', $opener_stack->get(kOpenerStack::LAST_ELEMENT, true));
$ret = $this->Application->BaseURL($prefix, $ssl) . $index_file . '?' . ENV_VAR_NAME . '=' . $env;
if ( isset($params['escape']) && $params['escape'] ) {
$ret = addslashes($ret);
}
if ( isset($params['m_opener']) && $params['m_opener'] == 'u' ) {
$opener_stack->pop();
$opener_stack->save(true);
if ( $opener_stack->isEmpty() ) {
// remove popups last templates, because popup is closing now
$this->Application->RemoveVar('last_template_' . $opener_stack->getWindowID());
$this->Application->RemoveVar('last_template_popup_' . $opener_stack->getWindowID());
// don't save popups last templates again :)
$this->Application->SetVar('skip_last_template', 1);
}
// store window relations
/*$window_relations = $this->Application->RecallVar('window_relations');
$window_relations = $window_relations ? unserialize($window_relations) : Array ();
if (array_key_exists($wid, $window_relations)) {
unset($window_relations[$wid]);
$this->Application->StoreVar('window_relations', serialize($window_relations));
}*/
}
return $ret;
}
/**
* Returns variables with values that should be passed through with this link + variable list
*
* @param Array $params
* @return Array
* @access public
*/
public function getPassThroughVariables(&$params)
{
static $cached_pass_through = null;
if ( isset($params['no_pass_through']) && $params['no_pass_through'] ) {
unset($params['no_pass_through']);
return Array ();
}
// because pass through is not changed during script run, then we can cache it
if ( is_null($cached_pass_through) ) {
$cached_pass_through = Array ();
$pass_through = $this->Application->GetVar('pass_through');
if ( $pass_through ) {
// names of variables to pass to each link
$cached_pass_through['pass_through'] = $pass_through;
$pass_through = explode(',', $pass_through);
foreach ($pass_through as $pass_through_var) {
$cached_pass_through[$pass_through_var] = $this->Application->GetVar($pass_through_var);
}
}
}
return $cached_pass_through;
}
/**
* Returns index file, that could be passed as parameter to method, as parameter to tag and as constant or not passed at all
*
* @param string $prefix
* @param string $index_file
* @param Array $params
* @return string
* @access protected
*/
protected function getIndexFile($prefix, $index_file = null, &$params)
{
static $cache = Array ();
if ( isset($params['index_file']) ) {
$index_file = $params['index_file'];
unset($params['index_file']);
return $index_file;
}
if ( isset($index_file) ) {
return $index_file;
}
if ( defined('INDEX_FILE') ) {
return INDEX_FILE;
}
// detect index file only once for given script and $cut_prefix
$php_self = $_SERVER['PHP_SELF'];
$cut_prefix = BASE_PATH . '/' . trim($prefix, '/');
if ( isset($cache[$php_self . ':' . $cut_prefix]) ) {
return $cache[$php_self . ':' . $cut_prefix];
}
$cache[$php_self . ':' . $cut_prefix] = trim(preg_replace('/' . preg_quote($cut_prefix, '/') . '(.*)/', '\\1', $php_self), '/');
return $cache[$php_self . ':' . $cut_prefix];
}
/**
* Returns theme template filename and it's corresponding page_id based on given seo template
*
* @param string $seo_template
* @return string
* @access public
*/
public function getPhysicalTemplate($seo_template)
{
- return array_search($seo_template, $this->structureTemplateMapping);
+ $physical_template = array_search($seo_template, $this->structureTemplateMapping);
+
+ if ( $physical_template === false || substr($physical_template, 0, 3) == 'id:' ) {
+ // physical template from ".smsignore" file OR virtual template
+ return $seo_template;
+ }
+
+ list ($physical_template,) = explode(':', $physical_template, 2); // template_path:theme_id => seo_template
+
+ return $physical_template;
}
/**
* Returns template name, that corresponds with given virtual (not physical) page id
*
* @param int $page_id
* @return string|bool
* @access public
*/
public function getVirtualPageTemplate($page_id)
{
return isset($this->structureTemplateMapping['id:' . $page_id]) ? $this->structureTemplateMapping['id:' . $page_id] : false;
}
/**
* Loads template mapping for Front-End
*
* @return void
* @access public
*/
public function LoadStructureTemplateMapping()
{
if (!$this->Application->isAdmin) {
$category_helper = $this->Application->recallObject('CategoryHelper');
/* @var $category_helper CategoryHelper */
$this->structureTemplateMapping = $category_helper->getTemplateMapping();
}
}
/**
* Removes tpl part from template name + resolved template ID to name
*
* @param string $default_template
* @return string
* @access public
*/
public function getTemplateName($default_template = '')
{
if ( $this->Application->GetVarDirect('t', 'Get') !== false ) {
// template name is passed directly in url (GET method)
$t = $this->Application->GetVarDirect('t', 'Get');
}
elseif ( $this->Application->GetVar('env') && $this->Application->RewriteURLs() && $this->Application->GetVar('t') ) {
// if t was set through env, even in mod_rewrite mode!
$t = $this->Application->GetVar('t');
}
else {
$t = trim($default_template ? $default_template : 'index', '/');
}
return trim(preg_replace('/\.tpl$/', '', $t), '/');
}
/**
* Prepares case, when requested page wasn't found
*
* @param int $theme_id
* @return array
*/
public function prepare404($theme_id = null)
{
if ( !isset($theme_id) ) {
$theme_id = $this->Application->GetVar('m_theme');
}
$not_found = $this->Application->ConfigValue('ErrorTemplate');
$vars['t'] = $not_found ? $not_found : 'error_notfound';
$themes_helper = $this->Application->recallObject('ThemesHelper');
/* @var $themes_helper kThemesHelper */
$vars['m_cat_id'] = $themes_helper->getPageByTemplate($vars['t'], $theme_id);
header('HTTP/1.0 404 Not Found');
return $vars;
}
}
\ No newline at end of file
Index: branches/5.2.x/core/kernel/processors/main_processor.php
===================================================================
--- branches/5.2.x/core/kernel/processors/main_processor.php (revision 15277)
+++ branches/5.2.x/core/kernel/processors/main_processor.php (revision 15278)
@@ -1,1284 +1,1279 @@
<?php
/**
* @version $Id$
* @package In-Portal
* @copyright Copyright (C) 1997 - 2009 Intechnic. All rights reserved.
* @license GNU/GPL
* In-Portal is Open Source software.
* This means that this software may have been modified pursuant
* the GNU General Public License, and as distributed it includes
* or is derivative of works licensed under the GNU General Public License
* or other free or open source software licenses.
* See http://www.in-portal.org/license for copyright notices and details.
*/
defined('FULL_PATH') or die('restricted access!');
class kMainTagProcessor extends kTagProcessor {
public function __construct()
{
parent::__construct();
$actions = $this->Application->recallObject('kActions');
/* @var $actions Params */
$actions->Set('t', $this->Application->GetVar('t'));
$actions->Set('sid', $this->Application->GetSID());
$actions->Set('m_opener', $this->Application->GetVar('m_opener') );
}
/**
* Base folder for all template includes
*
* @param Array $params
* @return string
*/
function TemplatesBase($params)
{
static $cached = Array ();
$cache_key = crc32( serialize($params) );
if (!array_key_exists($cache_key, $cached)) {
$module = array_key_exists('module', $params) ? $params['module'] : 'core';
if ($this->Application->isAdmin) {
if ($module == 'in-portal') {
$module = 'kernel';
}
// remove leading slash + substitute module
$module_path = $this->Application->findModule('Name', $module, 'Path');
if ($module_path !== false) {
$path = $module_path . 'admin_templates';
}
else {
// remove leading slash + substitute module
$path = preg_replace('/\/(.*?)\/(.*)/', $module . '/\\2', THEMES_PATH);
}
}
else {
$path = mb_substr(THEMES_PATH, 1);
if (mb_strtolower($module) == 'in-portal') {
$module_folder = 'platform';
}
else {
$module_folder = $this->Application->findModule('Name', $module, 'TemplatePath');
}
$path .= rtrim('/' . trim($module_folder, '/'), '/') . '/';
}
$cached[$cache_key] = $this->Application->BaseURL() . $path;
}
return $cached[$cache_key];
}
/**
* Creates <base href ..> HTML tag for all templates
* affects future css, js files and href params of links
*
* @param Array $params
* @return string
* @access protected
*/
protected function Base_Ref($params)
{
return '<base href="' . $this->TemplatesBase($params) . '/" />';
}
/**
* Returns base url for web-site
*
* @return string
* @access public
*/
function BaseURL()
{
return $this->Application->BaseURL();
}
//for compatability with K3 tags
function Base($params)
{
return $this->TemplatesBase($params).'/';
}
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
$template = $this->SelectParam($params, 't,template');
$prefix = array_key_exists('prefix', $params) ? $params['prefix'] : '';
unset($params['t'], $params['template'], $params['prefix']);
return $this->Application->HREF($template, $prefix, $params);
}
function Link($params)
{
// pass "m" prefix, instead of "all", that is by default on Front-End
if (!array_key_exists('pass', $params)) {
$params['pass'] = 'm';
}
return $this->T($params);
}
/**
* Performs redirect to provided template/url
*
* @param Array $params
* @return string
*/
function Redirect($params)
{
$this->Application->Redirect('external:' . $this->Link($params));
return '';
}
/*function Env($params)
{
$t = $params['template'];
unset($params['template']);
return $this->Application->BuildEnv($t, $params, 'm', false, false);
}*/
function FormAction($params)
{
if (!array_key_exists('pass', $params)) {
$params['pass'] = 'all,m';
}
$params['pass_category'] = 1;
return $this->Application->HREF('', '', $params);
}
/*// 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 (used only as "check" parameter value for "m_if" tag!)
*
* @param Array $params
* @return stirng
* @access public
*/
function Param($params)
{
$name = $params['name'];
if (array_key_exists($name, $this->Application->Parser->Captures)) {
$capture_params = $params;
$capture_params['name'] = '__capture_' . $name;
$this->Application->Parser->SetParam($name, $this->Application->ParseBlock($capture_params));
}
$res = $this->Application->Parser->GetParam($name);
if ($res === false) {
$res = '';
}
if (array_key_exists('plus', $params)) {
$res += $params['plus'];
}
return $res;
}
/**
* Compares block parameter with value specified
*
* @param Array $params
* @return bool
* @access public
*/
function ParamEquals($params)
{
$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)
{
$var_name = $this->SelectParam($params,'name,var,param');
if (isset($params['persistent']) && $params['persistent']) {
$ret = $this->Application->RecallPersistentVar($var_name);
}
else {
$ret = $this->Application->RecallVar($var_name);
}
$ret = ($ret === false && isset($params['no_null'])) ? '' : $ret;
if (getArrayValue($params, 'special') || getArrayValue($params, 'htmlchars')) {
$ret = htmlspecialchars($ret);
}
if (getArrayValue($params, 'urlencode')) {
$ret = urlencode($ret);
}
return $ret;
}
function RemoveVar($params)
{
$this->Application->RemoveVar( $this->SelectParam($params,'name,var,param') );
}
// 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);
}
/**
* Links variable from request with variable from session
*
* @param Array $params
* @return string
* @access protected
*/
protected function LinkVar($params)
{
$var_name = $params['name'];
$session_var_name = isset($params['session_name']) ? $params['session_name'] : $var_name;
$default_value = isset($params['default']) ? $params['default'] : '';
$this->Application->LinkVar($var_name, $session_var_name, $default_value);
return '';
}
/**
* Links variable from request with variable from session and returns it's value
*
* @param Array $params
* @return string
* @access protected
*/
protected function GetLinkedVar($params)
{
$this->LinkVar($params);
return $this->Application->GetVar( $params['name'] );
}
/**
* 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)
{
$name = $this->SelectParam($params, 'name,var,param');
if ( strpos($name, '[') !== false ) {
preg_match('/([^\[\]]+)\[(.*)\]/', $name, $regs);
$function_params = explode('][', $regs[2]);
$ret = $this->Application->GetVar($regs[1], Array ());
array_unshift_ref($function_params, $ret);
return call_user_func_array('getArrayValue', $function_params);
}
else {
$ret = $this->Application->GetVar($name, '');
}
if (array_key_exists('no_html_escape', $params) && $params['no_html_escape']) {
return kUtil::unhtmlentities($ret);
}
return $ret;
}
/**
* Retrieves application constant
* value by name
*
* @param Array $params
* @return string
* @access public
*/
function GetConst($params)
{
$constant_name = $this->SelectParam($params, 'name,const');
return defined($constant_name) ? constant($constant_name) : '';
}
/**
* Retrieves configuration variable value by name
*
* @param Array $params
* @return string
* @access public
*/
function GetConfig($params)
{
$config_name = $this->SelectParam($params, 'name,var');
$ret = $this->Application->ConfigValue($config_name);
if ( isset($params['formatted']) && $params['formatted'] ) {
$sql = 'SELECT ValueList
FROM ' . TABLE_PREFIX . 'SystemSettings
WHERE VariableName = ' . $this->Conn->qstr($config_name) . ' AND ElementType IN ("select", "radio")';
$value_list = $this->Conn->GetOne($sql);
if ( $value_list ) {
$helper = $this->Application->recallObject('InpCustomFieldsHelper');
/* @var $helper InpCustomFieldsHelper */
$options = $helper->GetValuesHash($value_list);
$ret = isset($options[$ret]) ? $options[$ret] : $ret;
}
}
if ( isset($params['as_label']) && $params['as_label'] ) {
$ret = $this->Application->Phrase($ret);
}
return $ret;
}
/**
* Compares configuration variable to a given value
*
* @param Array $params
* @return bool
* @deprecated
* @access protected
*/
protected function ConfigEquals($params)
{
$option = $this->SelectParam($params, 'name,option,var');
return $this->Application->ConfigValue($option) == $params['value'];
}
/**
* Creates all hidden fields
* needed for kernel_form
*
* @param Array $params
* @return string
* @access protected
*/
protected function DumpSystemInfo($params)
{
$actions = $this->Application->recallObject('kActions');
/* @var $actions Params */
$actions->Set('t', $this->Application->GetVar('t'));
$o = '';
$params = $actions->GetParams();
foreach ($params AS $name => $val) {
$o .= "<input type='hidden' name='$name' id='$name' value='$val'>\n";
}
return $o;
}
/**
* Used for search sidebox on front-end only
*
* @param Array $params
* @return string
* @access protected
*/
protected function GetFormHiddens($params)
{
$t = $this->SelectParam($params, 'template,t');
unset($params['template']);
$form_fields = Array ();
if ( $this->Application->RewriteURLs() ) {
$session = $this->Application->recallObject('Session');
/* @var $session Session */
if ( $session->NeedQueryString() ) {
$form_fields['sid'] = $this->Application->GetSID();
}
}
else {
$form_fields['env'] = $this->Application->BuildEnv($t, $params, 'm', false, false);
}
if ( $this->Application->GetVar('admin') == 1 ) {
$form_fields['admin'] = 1;
}
$ret = '';
$field_tpl = '<input type="hidden" name="%1$s" id="%1$s" value="%2$s"/>' . "\n";
foreach ($form_fields as $form_field => $field_value) {
$ret .= sprintf($field_tpl, $form_field, $field_value);
}
return $ret;
}
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') {
if (!isset($params['readonly']) || !$params['readonly']) {
$this->Application->SetVar($var, 'odd');
}
return $even;
}
else {
if (!isset($params['readonly']) || !$params['readonly']) {
$this->Application->SetVar($var, 'even');
}
return $odd;
}
}
/**
* Returns phrase translation by name
*
* @param Array $params
* @return string
* @access public
*/
function Phrase($params)
{
$phrase_name = $this->SelectParam($params, 'label,name,title');
$default_translation = $this->SelectParam($params, 'default');
$no_editing = isset($params['no_editing']) && $params['no_editing'];
$translation = $this->Application->Phrase($phrase_name, !$no_editing);
$phrase_key = mb_strtoupper($phrase_name);
if ( $default_translation && strpos($translation, '!' . $phrase_key . '!') !== false ) {
$phrase = $this->Application->recallObject('phrases.autocreate', null, Array ('skip_autoload' => true));
/* @var $phrase kDBItem */
if ( !$phrase->Load($phrase_key, 'PhraseKey') ) {
$phrase->SetDBField('Phrase', $phrase_name);
$ml_helper = $this->Application->recallObject('kMultiLanguageHelper');
/* @var $ml_helper kMultiLanguageHelper */
$languages = $ml_helper->getLanguages();
foreach ($languages AS $language_id) {
$phrase->SetDBField('l' . $language_id . '_Translation', $default_translation);
}
if ( $phrase->Create() ) {
$translation = $default_translation;
}
}
}
if ( isset($params['escape']) && $params['escape'] ) {
$translation = htmlspecialchars($translation, ENT_QUOTES);
$translation = addslashes($translation);
}
return $translation;
}
// 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)."/i", $this->Application->GetVar('t'))) {
- return $if_true;
+ $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 {
- return $if_false;
+ $if_true = $params['true'];
+ $if_false = $params['false'];
}
+
+ $physical_template = $this->Application->getPhysicalTemplate($this->Application->GetVar('t'));
+
+ return preg_match('/^' . str_replace('/', '\/', $test_templ) . '/i', $physical_template) ? $if_true : $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 = $this->SelectParam($params, 'name,var');
$value = $params['value'];
if (isset($params['persistent']) && $params['persistent']) {
return $this->Application->RecallPersistentVar($name) == $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 protected
* @deprecated
*/
protected function GetEquals($params)
{
$name = $this->SelectParam($params, 'var,name,param');
return $this->Application->GetVar($name) == $params['value'];
}
function ModuleInclude($params)
{
$ret = '';
$included = Array ();
$block_params = array_merge($params, Array('is_silent' => 2)); // don't make fatal errors in case if template is missing
$current_template = $this->Application->GetVar('t');
$replace_main = isset($params['replace_m']) && $params['replace_m'];
$skip_prefixes = isset($params['skip_prefixes']) ? explode(',', $params['skip_prefixes']) : Array();
$cms_mode = $this->Application->GetVar('admin');
foreach ($this->Application->ModuleInfo as $module_name => $module_data) {
$module_key = mb_strtolower($module_name);
if ($module_name == 'In-Portal') {
if (!$cms_mode && $this->Application->isAdmin) {
// don't process In-Portal templates in admin
continue;
}
// Front-End still relies on In-Portal module
$module_prefix = $module_data['TemplatePath'];
}
elseif ($this->Application->isAdmin) {
$module_prefix = $module_key . '/'; // was $module_data['Path'];
}
else {
$module_prefix = $module_data['TemplatePath']; // always have trailing "/"
}
if (in_array($module_prefix, $included)) {
// template by this path was already included by other module (e.g. in-portal used core's template)
continue;
}
$block_params['t'] = $module_prefix.$this->SelectParam($params, $module_key.'_template,'.$module_key.'_t,template,t');
$check_prefix = $module_data['Var'];
if ($check_prefix == 'adm' && $replace_main) {
$check_prefix = 'c';
}
if ($block_params['t'] == $current_template || in_array($check_prefix, $skip_prefixes)) {
continue;
}
$no_data = $this->SelectParam($params, $module_key.'_block_no_data,block_no_data');
if ($no_data) {
$block_params['block_no_data'] = $module_prefix.'/'.$no_data;
}
$ret .= $this->Application->IncludeTemplate($block_params);
$included[] = $module_prefix;
}
return $ret;
}
function ModuleEnabled($params)
{
return $this->Application->isModuleEnabled( $params['module'] );
}
/**
* Checks if debug mode is on
*
* @param Array $params
* @return bool
* @access public
*/
function IsDebugMode($params)
{
return defined('DEBUG_MODE') && $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);
}
return $o;
}*/
function LoggedIn($params)
{
return $this->Application->LoggedIn();
}
/**
* Allows to check if permission exists directly in template and perform additional actions if required
*
* @param Array $params
* @return bool
*/
function CheckPermission($params)
{
$perm_helper = $this->Application->recallObject('PermissionsHelper');
/* @var $perm_helper kPermissionsHelper */
return $perm_helper->TagPermissionCheck($params);
}
/**
* Checks if user is logged in and if not redirects it to template passed
*
* @param Array $params
*/
function RequireLogin($params)
{
$t = $this->Application->GetVar('t');
$next_t = getArrayValue($params, 'next_template');
if ( $next_t ) {
$t = $next_t;
}
// check by permissions: begin
if ((isset($params['perm_event']) && $params['perm_event']) ||
(isset($params['perm_prefix']) && $params['perm_prefix']) ||
(isset($params['permissions']) && $params['permissions'])) {
$perm_helper = $this->Application->recallObject('PermissionsHelper');
/* @var $perm_helper kPermissionsHelper */
$perm_status = $perm_helper->TagPermissionCheck($params);
if (!$perm_status) {
list($redirect_template, $redirect_params) = $perm_helper->getPermissionTemplate($params);
$this->Application->Redirect($redirect_template, $redirect_params);
}
else {
return ;
}
}
// check by permissions: end
// check by configuration value: begin
$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);
}
}
// check by configuration value: end
// check by belonging to group: begin
$group = $this->SelectParam($params, 'group');
$group_access = true;
if ($group) {
$sql = 'SELECT GroupId
FROM '.TABLE_PREFIX.'UserGroups
WHERE Name = '.$this->Conn->qstr($group);
$group_id = $this->Conn->GetOne($sql);
if ($group_id) {
$groups = explode(',', $this->Application->RecallVar('UserGroups'));
$group_access = in_array($group_id, $groups);
}
}
// check by belonging to group: end
if ((!$this->Application->LoggedIn() || !$group_access) && $condition) {
$redirect_params = $this->Application->HttpQuery->getRedirectParams(true);
if (array_key_exists('pass_category', $params)) {
$redirect_params['pass_category'] = $params['pass_category'];
}
if (MOD_REWRITE) {
// TODO: $next_t variable is ignored !!! (is anyone using m_RequireLogin tag with "next_template" parameter?)
$redirect_params = Array (
'm_cat_id' => 0,
'next_template' => urlencode('external:' . $_SERVER['REQUEST_URI']),
);
}
else {
$redirect_params['next_template'] = $t;
}
if ( $this->Application->LoggedIn() && !$group_access) {
$this->Application->Redirect($params['no_group_perm_template'], $redirect_params);
}
$this->Application->Redirect($params['login_template'], $redirect_params);
}
}
/**
* Checks, that user belongs to a group with a given name
*
* @param Array $params
* @return bool
*/
protected function IsMember($params)
{
$sql = 'SELECT GroupId
FROM ' . TABLE_PREFIX . 'UserGroups
WHERE Name = ' . $this->Conn->qstr($params['group']);
$group_id = $this->Conn->GetOne($sql);
if ( $group_id ) {
$groups = explode(',', $this->Application->RecallVar('UserGroups'));
return in_array($group_id, $groups);
}
return false;
}
/**
* Checks if SSL is on and redirects to SSL URL if needed
* If SSL_URL is not defined in config - the tag does not do anything
* If for_logged_in_only="1" exits if user is not logged in.
* If called without params forces https right away. If called with by_config="1" checks the
* Require SSL setting from General Config and if it is ON forces https
*
* @param Array $params
*/
protected function CheckSSL($params)
{
$ssl = $this->Application->isAdmin ? $this->Application->ConfigValue('AdminSSL_URL') : false;
if ( !$ssl ) {
// not in admin or admin ssl url is empty
$ssl_url = $this->Application->siteDomainField('SSLUrl');
$ssl = $ssl_url !== false ? $ssl_url : $this->Application->ConfigValue('SSL_URL');
}
if ( !$ssl || ($this->Application->TemplatesCache->forceThemeName !== false) ) {
// SSL URL is not set - no way to require SSL
// internal parsing (e.g. "TemplateParser::_parseTemplate") -> don't redirect
return;
}
$require = false;
if ( isset($params['mode']) && $params['mode'] == 'required' ) {
$require = true;
if ( isset($params['for_logged_in_only']) && $params['for_logged_in_only'] && !$this->Application->LoggedIn() ) {
$require = false;
}
if ( isset($params['condition']) ) {
if ( !$this->Application->ConfigValue($params['condition']) ) {
$require = false;
}
}
}
if ( EDITING_MODE ) {
// match SSL mode on front-end to one in administrative console, when browse modes are used
$require = $this->Application->ConfigValue('Require_AdminSSL');
}
$http_query = $this->Application->recallObject('HTTPQuery');
/* @var $http_query kHTTPQuery */
$pass = $http_query->getRedirectParams();
$pass['pass_events'] = 1; // to make sure all events are passed when redirect happens
if ( $require ) {
if ( PROTOCOL == 'https://' ) {
$this->Application->SetVar('__KEEP_SSL__', 1);
return;
}
$pass['__SSL__'] = 1;
$this->Application->Redirect('', $pass);
}
else {
if ( PROTOCOL == 'https://' && $this->Application->ConfigValue('Force_HTTP_When_SSL_Not_Required') ) {
if ( $this->Application->GetVar('__KEEP_SSL__') ) {
return;
}
// $pass_more = Array ('pass' => 'm', 'm_cat_id' => 0, '__SSL__' => 0);
$pass['__SSL__'] = 0;
$this->Application->Redirect('', $pass); // $pass_more
}
}
}
function ConstOn($params)
{
$name = $this->SelectParam($params,'name,const');
return kUtil::constOn($name);
}
function SetDefaultCategory($params)
{
$category_id = $this->Application->findModule('Name', $params['module'], 'RootCat');
$this->Application->SetVar('m_cat_id', $category_id);
}
function XMLTemplate($params)
{
$this->NoDebug($params);
if ( isset($params['cache']) && $params['cache'] ) {
$nextyear = intval(date('Y') + 1);
$format = "D, d M Y H:i:s";
$expiration = gmdate($format, mktime() + $params['cache']) . ' GMT';
$last_modified = mktime();
header('Cache-Control: public, cache, max-age=' . $params['cache']);
header("Expires: $expiration");
header('Pragma: public');
// Getting headers sent by the client.
$headers = $this->_requestHeaders();
// Checking if the client is validating his cache and if it is current.
if ( isset($headers['If-Modified-Since']) && (strtotime($headers['If-Modified-Since']) > $last_modified - $params['cache']) ) {
// Client's cache IS current, so we just respond '304 Not Modified'.
header('Last-Modified: ' . date($format, strtotime($headers['If-Modified-Since'])) . ' GMT', true, 304);
exit;
}
else {
// Image not cached or cache outdated, we respond '200 OK' and output the image.
header('Last-Modified: ' . gmdate($format, $last_modified) . ' GMT', true, 200);
}
}
// xml documents are usually long
set_time_limit(0);
ini_set('memory_limit', -1);
if ( !$this->Application->GetVar('debug') ) {
return $this->Application->XMLHeader(getArrayValue($params, 'xml_version'));
}
return '';
}
protected function _requestHeaders()
{
if ( function_exists('apache_request_headers') ) {
// If apache_request_headers() exists...
$headers = apache_request_headers();
if ($headers) {
return $headers; // And works... Use it
}
}
$headers = Array ();
foreach (array_keys($_SERVER) as $skey) {
if (substr($skey, 0, 5) == 'HTTP_') {
$headername = str_replace(' ', '-', ucwords(strtolower(str_replace('_', ' ', substr($skey, 0, 5)))));
$headers[$headername] = $_SERVER[$skey];
}
}
return $headers;
}
function Header($params)
{
header($params['data']);
}
function NoDebug($params)
{
if ( !$this->Application->GetVar('debug') ) {
kUtil::safeDefine('DBG_SKIP_REPORTING', 1);
}
}
/**
* Returns Home category name
*
* @param Array $params
* @return string
* @deprecated
*/
function RootCategoryName($params)
{
$no_editing = array_key_exists('no_editing', $params) && $params['no_editing'];
return $this->Application->Phrase('la_rootcategory_name', !$no_editing);
}
/**
* Allows to attach file directly from email event template
*
* @param Array $params
*/
function AttachFile($params)
{
$path = FULL_PATH . '/' . $params['path'];
$pseudo = isset($params['special']) ? 'EmailSender.' . $params['special'] : 'EmailSender';
$esender = $this->Application->recallObject($pseudo);
/* @var $esender kEmailSendingHelper */
if ( file_exists($path) ) {
$esender->AddAttachment($path);
}
}
function CaptchaImage($params)
{
$this->NoDebug($params);
$this->Application->SetVar('skip_last_template', 1);
$captcha_helper = $this->Application->recallObject('CaptchaHelper');
/* @var $captcha_helper kCaptchaHelper */
// generate captcha code
$code = $captcha_helper->prepareCode( $this->Application->GetVar('var') );
$captcha_helper->GenerateCaptchaImage($code, $this->Application->GetVar('w'), $this->Application->GetVar('h'), true);
}
function SID($params)
{
return $this->Application->GetSID();
}
function ModuleInfo($params)
{
return $this->Application->findModule($params['key'], $params['value'], $params['return']);
}
function Random($params)
{
return rand(1, 100000000);
}
/**
* Prints parser params, available at current deep level
*
* @param Array $params
* @return string
*/
function PrintCurrentParams($params)
{
$current_params = $this->Application->Parser->Params;
foreach ($current_params as $param_name => $param_value) {
$current_params[$param_name] = $param_name . ' = "' . $param_value . '"';
}
return '<pre>' . implode("\n", $current_params) . '</pre>';
}
/**
* Gets previously defined counter result
*
* @param Array $params
* @return int
*/
function GetCounter($params)
{
return $this->Application->getCounter($params['name'], $params);
}
/**
* Increments PageHit counter
*
* @param Array $params
* @return int
*/
function RegisterPageHit($params)
{
if ($this->Application->ConfigValue('UsePageHitCounter')) {
// get current counte
$sql = 'SELECT VariableValue
FROM '.TABLE_PREFIX.'SystemSettings
WHERE VariableName = "PageHitCounter"';
$page_counter = (int)$this->Conn->GetOne($sql);
$sql = 'UPDATE LOW_PRIORITY '.TABLE_PREFIX.'SystemSettings
SET VariableValue = '.($page_counter + 1).'
WHERE VariableName = "PageHitCounter"';
$this->Conn->Query($sql);
}
}
function Timestamp($params)
{
$format = isset($params['format']) ? $params['format'] : 'd.m.Y H:i:s';
return adodb_date($format);
}
function GetUrlHiddenFileds($params)
{
$vars = Array ('page', 'per_page', 'sort_by');
$ret = '<input type="hidden" name="main_list" value="1"/>';
if (array_key_exists('skip', $params)) {
$vars = array_diff($vars, $params['skip']);
}
foreach ($vars as $var_name) {
$var_value = $this->Application->GetVar($var_name);
if ($var_value) {
$ret .= '<input type="hidden" name="' . $var_name . '" value="' . $var_value . '"/>';
}
}
return $ret;
}
/**
* Returns current Page URL (without re-assembling it).
* "skip_query" param is optional and will remove the ?QUERY part from the result.
*
* @param Array $params
* @return string
* @access protected
*/
protected function CurrentPageLink($params)
{
if ( isset($params['skip_query']) && $params['skip_query'] ) {
return preg_replace('/\?' . preg_quote($_SERVER['QUERY_STRING'], '/') . '$/', '', $_SERVER['REQUEST_URI']);
}
return $_SERVER['REQUEST_URI'];
}
/**
* Returns current maintenance mode state
*
* @param Array $params
* @return int
* @access protected
*/
protected function MaintenanceMode($params)
{
$check_ips = isset($params['check_ips']) ? $params['check_ips'] : true;
return $this->Application->getMaintenanceMode($check_ips);
}
/**
* Checks if element with given name is defined
*
* @param Array $params
* @return int
* @access protected
*/
protected function ElementDefined($params)
{
return $this->Application->Parser->blockFound($params['name']);
}
}
Index: branches/5.2.x/core/units/helpers/navigation_bar.php
===================================================================
--- branches/5.2.x/core/units/helpers/navigation_bar.php (revision 15277)
+++ branches/5.2.x/core/units/helpers/navigation_bar.php (revision 15278)
@@ -1,375 +1,367 @@
<?php
/**
* @version $Id$
* @package In-Portal
* @copyright Copyright (C) 1997 - 2012 Intechnic. All rights reserved.
* @license GNU/GPL
* In-Portal is Open Source software.
* This means that this software may have been modified pursuant
* the GNU General Public License, and as distributed it includes
* or is derivative of works licensed under the GNU General Public License
* or other free or open source software licenses.
* See http://www.in-portal.org/license for copyright notices and details.
*/
defined('FULL_PATH') or die('restricted access!');
class kNavigationBar extends kBase {
/**
* Parameters to indicate how exactly navigation bar should look like
*
* @var Array
* @access protected
*/
protected $_params = Array ();
/**
* Prints category path using given blocks. Also supports used defined path elements at the end.
*
* @param Array $params
* @return string
*/
public function build($params)
{
// elements:
// - current_render_as - currently selected element (automatic detection)
// - render_as - link to a regular template
// - category_render_as - link to category path element
// - custom_render_as - link to custom element (that have "__" in front of them)
// - root_cat_render_as - link to Home page
$this->_params = $params;
$this->_params['is_first'] = 1;
$home_element = $this->_getHomeElement();
if ( !getArrayValue($this->_params, 'titles') && !getArrayValue($this->_params, 'templates') ) {
// no static templates given, show only category path
return $home_element . $this->getCategoryPath();
}
$ret = '';
$block_params = $this->_getBaseParams();
$current_template = $this->_getCurrentTemplate();
$navigation_parts = $this->getNavigationParts();
foreach ($navigation_parts as $template => $title) {
$block_params['template'] = $template;
if ( $title == '__categorypath__' ) {
$ret .= $this->getCategoryPath();
}
else {
$is_current = $template == $current_template;
$block_params['current'] = $is_current;
if ( substr($title, 0, 2) == '__' ) {
$block_params['title'] = $title;
$block_params['name'] = $this->SelectParam($this->_params, 'custom_render_as,render_as');
}
else {
$block_params['title'] = $this->Application->Phrase($title);
$block_params['name'] = $this->_params[$is_current ? 'current_render_as' : 'render_as'];
}
$ret .= $this->Application->ParseBlock($block_params);
}
}
return $home_element . $ret;
}
/**
* Returns base params for rendering each navigation bar element
*
* @return Array
* @access protected
*/
protected function _getBaseParams()
{
$block_params = Array (
'no_editing' => 1,
'category' => 0,
'separator' => $this->_params['separator'],
'current' => 0,
);
return $block_params;
}
/**
* Returns the name of current physical template
*
* @return string
* @access protected
*/
protected function _getCurrentTemplate()
{
- $current_template = $this->Application->GetVar('t');
- $physical_template = $this->Application->getPhysicalTemplate($current_template);
-
- if ( $physical_template !== false ) {
- // replace menu template name with it's actual template name on disk
- list ($current_template) = explode(':', $physical_template, 2);
- }
-
- return $current_template;
+ return $this->Application->getPhysicalTemplate($this->Application->GetVar('t'));
}
/**
* Returns element for "Home" category
*
* @return string
* @access protected
*/
protected function _getHomeElement()
{
if ( isset($this->_params['shift']) && $this->_params['shift'] ) {
$home_element = '';
$this->_params['shift']--;
}
else {
$home_element = $this->_getHomeCategoryPath();
unset($this->_params['is_first']);
}
return $home_element;
}
/**
* Renders path to top catalog category
*
* @return string
* @access protected
*/
protected function _getHomeCategoryPath()
{
$block_params = $this->_getBaseParams();
$block_params['cat_id'] = $this->Application->getBaseCategory();
$block_params['current'] = $this->_getCurrentCategoryId() == $block_params['cat_id'] || $this->_getCurrentCategoryId() == 0 ? 1 : 0;
$block_params['is_first'] = $this->_params['is_first'];
$block_params['template'] = ''; // to prevent warning when category element is rendered using general "render_as" block
$category_name = $this->Application->Phrase(($this->Application->isAdmin ? 'la_' : 'lu_') . 'rootcategory_name');
$block_params['cat_name'] = $block_params['title'] = $category_name;
$block_params['name'] = $this->SelectParam($this->_params, 'root_cat_render_as,category_render_as,render_as');
if ( $block_params['current'] ) {
$block_params['name'] = $this->SelectParam($this->_params, 'current_render_as,render_as');
}
return $this->Application->ParseBlock($block_params);
}
/**
* Returns currently selected category
*
* @return mixed
*/
protected function _getCurrentCategoryId()
{
return isset($this->_params['cat_id']) ? $this->_params['cat_id'] : $this->Application->GetVar('m_cat_id');
}
/**
* Get navigation parts
*
* @return Array
* @access protected
*/
protected function getNavigationParts()
{
$titles = explode(',', $this->_params['titles']);
$templates = explode(',', $this->_params['templates']);
if ( getArrayValue($this->_params, 'show_category') && !in_array('__categorypath__', $titles) ) {
// insert before __item__ or first element, when __item__ isn't specified
$item_index = (int)array_search('__item__', $titles);
array_splice($titles, $item_index, 0, '__categorypath__');
array_splice($templates, $item_index, 0, '__categorypath__');
}
return array_combine($templates, $titles);
}
/**
* Renders path to given category using given blocks.
*
* @return string
* @access protected
*/
protected function getCategoryPath()
{
$category_path = $this->getCategoryParentPath();
if ( !$category_path ) {
// in "Home" category
return '';
}
$main_category_id = $this->_getCurrentCategoryId();
if ( isset($this->_params['shift']) && $this->_params['shift'] ) {
array_splice($category_path, 0, $this->_params['shift']);
}
$category_helper = $this->Application->recallObject('CategoryHelper');
/* @var $category_helper CategoryHelper */
$module_info = $category_helper->getCategoryModule($this->_params, array_keys($category_path));
$module_item_id = $this->Application->GetVar($module_info['Var'] . '_id');
$ret = '';
$block_params = $this->_getBaseParams();
$block_params['category'] = 1;
$block_params['template'] = ''; // to prevent warning when category element is rendered using general "render_as" block
if ( isset($this->_params['is_first']) ) {
$block_params['is_first'] = $this->_params['is_first'];
}
$block_params['separator'] = $this->_params['separator'];
$no_current = isset($this->_params['no_current']) && $this->_params['no_current'];
$backup_category_id = $this->Application->GetVar('c_id');
foreach ($category_path as $category_id => $category_name) {
$block_params['cat_id'] = $category_id;
$block_params['cat_name'] = $block_params['title'] = $category_name;
if ( $no_current ) {
$block_params['current'] = 0;
}
else {
$block_params['current'] = ($main_category_id == $category_id) && !$module_item_id ? 1 : 0;
}
$block_params['name'] = $this->SelectParam($this->_params, 'category_render_as,render_as');
if ( $block_params['current'] ) {
$block_params['name'] = $this->SelectParam($this->_params, 'current_render_as,render_as');
}
$this->Application->SetVar('c_id', $category_id);
$ret .= $this->Application->ParseBlock($block_params);
if ( array_key_exists('is_first', $block_params) ) {
unset($block_params['is_first']);
}
}
$this->Application->SetVar('c_id', $backup_category_id);
return $ret;
}
/**
* Returns given category's parent path as array of id=>name elements
*
* @return Array
* @access protected
*/
protected function getCategoryParentPath()
{
$main_category_id = $this->_getCurrentCategoryId();
if ( $main_category_id == 0 ) {
// don't query path for "Home" category
return Array ();
}
$category_title = isset($this->_params['category_title']) ? $this->_params['category_title'] : 'Name';
$cache_key = 'parent_paths_named[%CIDSerial:' . $main_category_id . '%]:' . $category_title;
$cached_path = $this->Application->getCache($cache_key);
if ( $cached_path === false ) {
$parent_path = explode('|', substr($this->getParentPath($main_category_id), 1, -1));
$ml_formatter = $this->Application->recallObject('kMultiLanguage');
/* @var $ml_formatter kMultiLanguage */
$navbar_field = $ml_formatter->LangFieldName($category_title);
$id_field = $this->Application->getUnitOption('c', 'IDField');
$table_name = $this->Application->getUnitOption('c', 'TableName');
$this->Conn->nextQueryCachable = true;
$sql = 'SELECT ' . $navbar_field . ', ' . $id_field . '
FROM ' . $table_name . '
WHERE ' . $id_field . ' IN (' . implode(',', $parent_path) . ')';
$category_names = $this->Conn->GetCol($sql, $id_field);
$cached_path = Array ();
$skip_category = $this->Application->getBaseCategory();
if ( $category_names ) {
foreach ($parent_path as $category_id) {
if ( $category_id == $skip_category ) {
continue;
}
$cached_path[$category_id] = $category_names[$category_id];
}
}
$this->Application->setCache($cache_key, $cached_path);
}
return $cached_path;
}
/**
* Returns parent path from a given category
*
* @param int $category_id
* @return string
* @access public
*/
public function getParentPath($category_id)
{
$cache_key = 'parent_paths[%CIDSerial:' . $category_id . '%]';
$parent_path = $this->Application->getCache($cache_key);
if ( $parent_path !== false ) {
return $parent_path;
}
$this->Conn->nextQueryCachable = true;
$sql = 'SELECT ParentPath
FROM ' . $this->Application->getUnitOption('c', 'TableName') . '
WHERE ' . $this->Application->getUnitOption('c', 'IDField') . ' = ' . $category_id;
$parent_path = $this->Conn->GetOne($sql);
$this->Application->setCache($cache_key, $parent_path);
return $parent_path;
}
/**
* Not tag. Method for parameter selection from list in this TagProcessor
*
* @param Array $params
* @param Array $possible_names
*
* @return string
* @access protected
*/
protected function SelectParam($params, $possible_names)
{
if ( !is_array($params) ) {
return '';
}
if ( !is_array($possible_names) ) {
$possible_names = explode(',', $possible_names);
}
foreach ($possible_names as $name) {
if ( isset($params[$name]) ) {
return $params[$name];
}
}
return '';
}
}
\ No newline at end of file
Index: branches/5.2.x/core/units/helpers/themes_helper.php
===================================================================
--- branches/5.2.x/core/units/helpers/themes_helper.php (revision 15277)
+++ branches/5.2.x/core/units/helpers/themes_helper.php (revision 15278)
@@ -1,622 +1,617 @@
<?php
/**
* @version $Id$
* @package In-Portal
* @copyright Copyright (C) 1997 - 2009 Intechnic. All rights reserved.
* @license GNU/GPL
* In-Portal is Open Source software.
* This means that this software may have been modified pursuant
* the GNU General Public License, and as distributed it includes
* or is derivative of works licensed under the GNU General Public License
* or other free or open source software licenses.
* See http://www.in-portal.org/license for copyright notices and details.
*/
defined('FULL_PATH') or die('restricted access!');
class kThemesHelper extends kHelper {
/**
* Where all themes are located
*
* @var string
*/
var $themesFolder = '';
/**
* List of theme names, found on system
*
* @var Array
*/
var $_themeNames = Array ();
/**
* Temporary array when all theme files from db are stored
*
* @var Array
*/
var $themeFiles = Array ();
public function __construct()
{
parent::__construct();
$this->themesFolder = FULL_PATH.'/themes';
}
/**
* Updates file system changes to database for selected theme
*
* @param string $theme_name
*
* @return mixed returns ID of created/used theme or false, if none created
*/
function refreshTheme($theme_name)
{
if (!file_exists($this->themesFolder . '/' . $theme_name)) {
// requested theme was not found on hdd
return false;
}
$id_field = $this->Application->getUnitOption('theme', 'IDField');
$table_name = $this->Application->getUnitOption('theme', 'TableName');
$sql = 'SELECT *
FROM ' . $table_name . '
WHERE Name = ' . $this->Conn->qstr($theme_name);
$theme_info = $this->Conn->GetRow($sql);
if ($theme_info) {
$theme_id = $theme_info[$id_field];
$theme_enabled = $theme_info['Enabled'];
}
else {
$theme_id = $theme_enabled = false;
}
$this->themeFiles = Array ();
if ($theme_id) {
if (!$theme_enabled) {
// don't process existing theme files, that are disabled
return $theme_id;
}
// reset found mark for every themes file (if theme is not new)
$sql = 'UPDATE '.TABLE_PREFIX.'ThemeFiles
SET FileFound = 0
WHERE ThemeId = '.$theme_id;
$this->Conn->Query($sql);
// get all theme files from db
$sql = 'SELECT FileId, CONCAT(FilePath, "/", FileName) AS FullPath
FROM '.TABLE_PREFIX.'ThemeFiles
WHERE ThemeId = '.$theme_id;
$this->themeFiles = $this->Conn->GetCol($sql, 'FullPath');
}
else {
// theme was not found in db, but found on hdd -> create new
$theme_info = Array (
'Name' => $theme_name,
'Enabled' => 0,
'Description' => $theme_name,
'PrimaryTheme' => 0,
'CacheTimeout' => 3600, // not in use right now
'StylesheetId' => 0, // not in use right now
'LanguagePackInstalled' => 0
);
$this->Conn->doInsert($theme_info, $table_name);
$theme_id = $this->Conn->getInsertID();
if (!$theme_enabled) {
// don't process newly created theme files, because they are disabled
return $theme_id;
}
}
$this->_themeNames[$theme_id] = $theme_name;
$theme_path = $this->themesFolder.'/'.$theme_name;
$this->FindThemeFiles('', $theme_path, $theme_id); // search from base theme directory
// delete file records from db, that were not found on hdd
$sql = 'DELETE FROM '.TABLE_PREFIX.'ThemeFiles
WHERE ThemeId = '.$theme_id.' AND FileFound = 0';
$this->Conn->Query($sql);
// install language packs, associated with theme (if any found and wasn't aready installed)
if (!$theme_info['LanguagePackInstalled']) {
$this->installThemeLanguagePack($theme_path);
$fields_hash = Array (
'LanguagePackInstalled' => 1,
);
$this->Conn->doUpdate($fields_hash, $table_name, $id_field . ' = ' . $theme_id);
}
$fields_hash = Array (
'TemplateAliases' => serialize( $this->getTemplateAliases($theme_id, $theme_path) ),
);
$this->Conn->doUpdate($fields_hash, $table_name, $id_field . ' = ' . $theme_id);
return $theme_id;
}
/**
* Installs module(-s) language pack for given theme
*
* @param string $theme_path
* @param string|bool $module_name
* @return void
*/
function installThemeLanguagePack($theme_path, $module_name = false)
{
if ( $module_name === false ) {
$modules = $this->Application->ModuleInfo;
}
else {
$modules = Array ($module_name => $this->Application->ModuleInfo[$module_name]);
}
$language_import_helper = $this->Application->recallObject('LanguageImportHelper');
/* @var $language_import_helper LanguageImportHelper */
foreach ($modules as $module_name => $module_info) {
if ( $module_name == 'In-Portal' ) {
continue;
}
$lang_file = $theme_path . '/' . $module_info['TemplatePath'] . '_install/english.lang';
if ( file_exists($lang_file) ) {
$language_import_helper->performImport($lang_file, '|0|', '', LANG_SKIP_EXISTING);
}
}
}
/**
* Returns template aliases from "/_install/theme.xml" files in theme
*
* @param int $theme_id
* @param string $theme_path
* @return Array
* @access protected
*/
protected function getTemplateAliases($theme_id, $theme_path)
{
$template_aliases = Array ();
foreach ($this->Application->ModuleInfo as $module_name => $module_info) {
$xml_file = $theme_path . '/' . $module_info['TemplatePath'] . '_install/theme.xml';
if ( $module_name == 'In-Portal' || !file_exists($xml_file) ) {
continue;
}
$theme = simplexml_load_file($xml_file);
if ( $theme === false ) {
// broken xml OR no aliases defined
continue;
}
foreach ($theme as $design) {
/* @var $design SimpleXMLElement */
$template_path = trim($design);
$module_override = (string)$design['module'];
if ( $module_override ) {
// allow to put template mappings form all modules into single theme.xml file
$module_folder = $this->Application->findModule('Name', $module_override, 'TemplatePath');
}
else {
// no module specified -> use module based on theme.xml file location
$module_folder = $module_info['TemplatePath'];
}
// only store alias, when template exists on disk
if ( $this->getTemplateId($template_path, $theme_id) ) {
$alias = '#' . $module_folder . strtolower($design->getName()) . '#';
// remember alias in global theme mapping
$template_aliases[$alias] = $template_path;
// store alias in theme file record to use later in design dropdown
$this->updateTemplate($template_path, $theme_id, Array ('TemplateAlias' => $alias));
}
}
}
return $template_aliases;
}
/**
* Returns ID of given physical template (relative to theme) given from ThemeFiles table
* @param string $template_path
* @param int $theme_id
* @return int
* @access public
*/
public function getTemplateId($template_path, $theme_id)
{
- $physical_template = $this->Application->getPhysicalTemplate($template_path);
-
- if ( ($physical_template !== false) && (substr($physical_template, 0, 3) != 'id:') ) {
- // replace menu template name with it's actual template name on disk
- list ($template_path) = explode(':', $physical_template, 2);
- }
+ $template_path = $this->Application->getPhysicalTemplate($template_path);
$sql = 'SELECT FileId
FROM ' . TABLE_PREFIX . 'ThemeFiles
WHERE ' . $this->getTemplateWhereClause($template_path, $theme_id);
return $this->Conn->GetOne($sql);
}
/**
* Updates template record with a given data
*
* @param string $template_path
* @param int $theme_id
* @param Array $fields_hash
* @return void
* @access public
*/
public function updateTemplate($template_path, $theme_id, $fields_hash)
{
$where_clause = $this->getTemplateWhereClause($template_path, $theme_id);
$this->Conn->doUpdate($fields_hash, TABLE_PREFIX . 'ThemeFiles', $where_clause);
}
/**
* Returns where clause to get associated record from ThemeFiles table for given template path
* @param string $template_path
* @param int $theme_id
* @return string
* @access protected
*/
protected function getTemplateWhereClause($template_path, $theme_id)
{
$folder = dirname($template_path);
$where_clause = Array (
'ThemeId = ' . $theme_id,
'FilePath = ' . $this->Conn->qstr($folder == '.' ? '' : '/' . $folder),
'FileName = ' . $this->Conn->qstr(basename($template_path) . '.tpl'),
);
return '(' . implode(') AND (', $where_clause) . ')';
}
/**
* Installs given module language pack and refreshed it from all themes
*
* @param string $module_name
*/
function synchronizeModule($module_name)
{
$sql = 'SELECT `Name`, ThemeId
FROM ' . TABLE_PREFIX . 'Themes';
$themes = $this->Conn->GetCol($sql, 'ThemeId');
if (!$themes) {
return ;
}
foreach ($themes as $theme_id => $theme_name) {
$theme_path = $this->themesFolder . '/' . $theme_name;
// install language pack
$this->installThemeLanguagePack($theme_path, $module_name);
// update TemplateAliases mapping
$fields_hash = Array (
'TemplateAliases' => serialize( $this->getTemplateAliases($theme_id, $theme_path) ),
);
$this->Conn->doUpdate($fields_hash, TABLE_PREFIX . 'Themes', 'ThemeId = ' . $theme_id);
}
}
/**
* Searches for new templates (missing in db) in specified folder
*
* @param string $folder_path subfolder of searchable theme
* @param string $theme_path theme path from web server root
* @param int $theme_id id of theme we are scanning
* @param int $auto_structure_mode
*/
function FindThemeFiles($folder_path, $theme_path, $theme_id, $auto_structure_mode = 1)
{
$ignore_regexp = $this->getIgnoreRegexp($theme_path . $folder_path);
$iterator = new DirectoryIterator($theme_path . $folder_path . '/');
/* @var $file_info DirectoryIterator */
foreach ($iterator as $file_info) {
$filename = $file_info->getFilename();
$auto_structure = preg_match($ignore_regexp, $filename) ? 2 : $auto_structure_mode;
$file_path = $folder_path . '/' . $filename; // don't pass path to theme top folder!
if ( $file_info->isDir() && !$file_info->isDot() && $filename != 'CVS' && $filename != '.svn' ) {
$this->FindThemeFiles($file_path, $theme_path, $theme_id, $auto_structure);
}
elseif ( pathinfo($filename, PATHINFO_EXTENSION) == 'tpl' ) {
$meta_info = $this->_getTemplateMetaInfo(trim($file_path, '/'), $theme_id);
$file_id = isset($this->themeFiles[$file_path]) ? $this->themeFiles[$file_path] : false;
$file_description = array_key_exists('desc', $meta_info) ? $meta_info['desc'] : '';
if ($file_id) {
// file was found in db & on hdd -> mark as existing
$fields_hash = Array (
'FileFound' => 1,
'Description' => $file_description,
'FileType' => $auto_structure,
'FileMetaInfo' => serialize($meta_info),
);
$this->Conn->doUpdate($fields_hash, TABLE_PREFIX . 'ThemeFiles', 'FileId = ' . $file_id);
}
else {
// file was found on hdd, but missing in db -> create new file record
$fields_hash = Array (
'ThemeId' => $theme_id,
'FileName' => $filename,
'FilePath' => $folder_path,
'Description' => $file_description,
'FileType' => $auto_structure, // 1 - built-in, 0 - custom (not in use right now), 2 - skipped in structure
'FileMetaInfo' => serialize($meta_info),
'FileFound' => 1,
);
$this->Conn->doInsert($fields_hash, TABLE_PREFIX.'ThemeFiles');
$this->themeFiles[$file_path] = $this->Conn->getInsertID();
}
// echo 'FilePath: [<strong>'.$folder_path.'</strong>]; FileName: [<strong>'.$filename.'</strong>]; IsNew: [<strong>'.($file_id > 0 ? 'NO' : 'YES').'</strong>]<br />';
}
}
}
/**
* Returns single regular expression to match all ignore patters, that are valid for given folder
*
* @param string $folder_path
* @return string
*/
protected function getIgnoreRegexp($folder_path)
{
// always ignore design and element templates
$ignore = '\.des\.tpl$|\.elm\.tpl$';
$sms_ignore_file = $folder_path . '/.smsignore';
if ( file_exists($sms_ignore_file) ) {
$manual_patterns = array_map('trim', file($sms_ignore_file));
foreach ($manual_patterns as $manual_pattern) {
$ignore .= '|' . str_replace('/', '\\/', $manual_pattern);
}
}
return '/' . $ignore . '/';
}
/**
* Returns template information (name, description, path) from it's header comment
*
* @param string $template
* @param int $theme_id
* @return Array
*/
function _getTemplateMetaInfo($template, $theme_id)
{
static $init_made = false;
if (!$init_made) {
$this->Application->InitParser(true);
$init_made = true;
}
$template = 'theme:' . $this->_themeNames[$theme_id] . '/' . $template;
$template_file = $this->Application->TemplatesCache->GetRealFilename($template); // ".tpl" was added before
return $this->parseTemplateMetaInfo($template_file);
}
function parseTemplateMetaInfo($template_file)
{
if (!file_exists($template_file)) {
// when template without info it's placed in top category
return Array ();
}
$template_data = file_get_contents($template_file);
if (substr($template_data, 0, 6) == '<!--##') {
// template starts with comment in such format
/*<!--##
<NAME></NAME>
<DESC></DESC>
<SECTION>||</SECTION>
##-->*/
$comment_end = strpos($template_data, '##-->');
if ($comment_end === false) {
// badly formatted comment
return Array ();
}
$comment = trim( substr($template_data, 6, $comment_end - 6) );
if (preg_match_all('/<(NAME|DESC|SECTION)>(.*?)<\/(NAME|DESC|SECTION)>/is', $comment, $regs)) {
$ret = Array ();
foreach ($regs[1] as $param_order => $param_name) {
$ret[ strtolower($param_name) ] = trim($regs[2][$param_order]);
}
if (array_key_exists('section', $ret) && $ret['section']) {
$category_path = explode('||', $ret['section']);
$category_path = array_map('trim', $category_path);
$ret['section'] = implode('||', $category_path);
}
return $ret;
}
}
return Array ();
}
/**
* Updates file system changes to database for all themes (including new ones)
*
*/
function refreshThemes()
{
$themes_found = Array ();
try {
$iterator = new DirectoryIterator($this->themesFolder . '/');
/* @var $file_info DirectoryIterator */
foreach ($iterator as $file_info) {
$filename = $file_info->getFilename();
if ( $file_info->isDir() && !$file_info->isDot() && $filename != '.svn' && $filename != 'CVS' ) {
$theme_id = $this->refreshTheme($filename);
if ( $theme_id ) {
$themes_found[] = $theme_id;
// increment serial of updated themes
$this->Application->incrementCacheSerial('theme', $theme_id);
}
}
}
}
catch ( UnexpectedValueException $e ) {
}
$id_field = $this->Application->getUnitOption('theme', 'IDField');
$table_name = $this->Application->getUnitOption('theme', 'TableName');
// 1. only one theme found -> enable it and make primary
/*if (count($themes_found) == 1) {
$sql = 'UPDATE ' . $table_name . '
SET Enabled = 1, PrimaryTheme = 1
WHERE ' . $id_field . ' = ' . current($themes_found);
$this->Conn->Query($sql);
}*/
// 2. if none themes found -> delete all from db OR delete all except of found themes
$sql = 'SELECT ' . $id_field . '
FROM ' . $table_name;
if ( $themes_found ) {
$sql .= ' WHERE ' . $id_field . ' NOT IN (' . implode(',', $themes_found) . ')';
}
$theme_ids = $this->Conn->GetCol($sql);
$this->deleteThemes($theme_ids);
foreach ($theme_ids as $theme_id) {
// increment serial of deleted themes
$this->Application->incrementCacheSerial('theme', $theme_id);
}
$this->Application->incrementCacheSerial('theme');
$this->Application->incrementCacheSerial('theme-file');
$minify_helper = $this->Application->recallObject('MinifyHelper');
/* @var $minify_helper MinifyHelper */
$minify_helper->delete();
}
/**
* Deletes themes with ids passed from db
*
* @param Array $theme_ids
*/
function deleteThemes($theme_ids)
{
if (!$theme_ids) {
return ;
}
$id_field = $this->Application->getUnitOption('theme', 'IDField');
$table_name = $this->Application->getUnitOption('theme', 'TableName');
$sql = 'DELETE FROM '.$table_name.'
WHERE '.$id_field.' IN ('.implode(',', $theme_ids).')';
$this->Conn->Query($sql);
$sql = 'DELETE FROM '.TABLE_PREFIX.'ThemeFiles
WHERE '.$id_field.' IN ('.implode(',', $theme_ids).')';
$this->Conn->Query($sql);
}
/**
* Returns current theme (also works in admin)
*
* @return int
*/
function getCurrentThemeId()
{
static $theme_id = null;
if (isset($theme_id)) {
return $theme_id;
}
if ($this->Application->isAdmin) {
// get theme, that user selected in catalog
$theme_id = $this->Application->RecallVar('theme_id');
if ($theme_id === false) {
// query, because "m_theme" is always empty in admin
$id_field = $this->Application->getUnitOption('theme', 'IDField');
$table_name = $this->Application->getUnitOption('theme', 'TableName');
$sql = 'SELECT ' . $id_field . '
FROM ' . $table_name . '
WHERE (PrimaryTheme = 1) AND (Enabled = 1)';
$theme_id = $this->Conn->GetOne($sql);
}
return $theme_id;
}
// use current theme, because it's available on Front-End
$theme_id = $this->Application->GetVar('m_theme');
if (!$theme_id) {
// happens in mod-rewrite mode, then requested template is not found
$theme_id = $this->Application->GetDefaultThemeId();
}
return $theme_id;
}
/**
* Returns page id based on given template
*
* @param string $template
* @param int $theme_id
* @return int
*/
function getPageByTemplate($template, $theme_id = null)
{
if (!isset($theme_id)) {
// during mod-rewrite url parsing current theme
// is not available to kHTTPQuery class, so don't use it
$theme_id = (int)$this->getCurrentThemeId();
}
$sql = 'SELECT ' . $this->Application->getUnitOption('c', 'IDField') . '
FROM ' . $this->Application->getUnitOption('c', 'TableName') . '
WHERE
(
(NamedParentPath = ' . $this->Conn->qstr('Content/' . $template) . ') OR
(`Type` = ' . PAGE_TYPE_TEMPLATE . ' AND CachedTemplate = ' . $this->Conn->qstr($template) . ')
)
AND (ThemeId = ' . $theme_id . ($theme_id > 0 ? ' OR ThemeId = 0' : '') . ')';
return $this->Conn->GetOne($sql);
}
}
\ No newline at end of file
Event Timeline
Log In to Comment