Page MenuHomeIn-Portal Phabricator

in-portal
No OneTemporary

File Metadata

Created
Sat, Feb 22, 12:06 AM

in-portal

Index: branches/5.2.x/core/kernel/utility/factory.php
===================================================================
--- branches/5.2.x/core/kernel/utility/factory.php (revision 15419)
+++ branches/5.2.x/core/kernel/utility/factory.php (revision 15420)
@@ -1,290 +1,296 @@
<?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 kFactory extends kBase implements kiCacheable {
/**
* Where all created objects are stored
*
* @var Array
* @access protected
*/
protected $Storage = Array ();
/**
* Mapping between class name and file name
* where class definition can be found.
* File path absolute!
*
* @var Array
* @access protected
*/
protected $Files = Array ();
/**
* Map class names to their pseudo
* class names, e.g. key=pseudo_class,
* value=real_class_name
*
* @var Array
* @access protected
*/
protected $realClasses = Array ();
public function __construct()
{
parent::__construct();
spl_autoload_register(Array (&$this, 'autoload'));
}
/**
* Sets data from cache to object
*
* @param Array $data
* @return void
* @access public
*/
public function setFromCache(&$data)
{
$this->Files = $data['Factory.Files'];
$this->realClasses = $data['Factory.realClasses'];
}
/**
* Performs automatic loading of classes registered with the factory
*
* @param string $class_name
* @return void
- * @throws Exception
+ * @throws kFactoryException
* @access public
*/
public function autoload($class_name)
{
if ( !isset($this->Files[$class_name]) ) {
// class not from our factory -> let other autoloaders handle it
return;
}
if ( !file_exists(FULL_PATH . $this->Files[$class_name]) ) {
- throw new Exception('File <strong>' . FULL_PATH . $this->Files[$class_name] . '</strong> containing class <strong>' . $class_name . '</strong> definition not found');
+ throw new kFactoryException('File <strong>' . FULL_PATH . $this->Files[$class_name] . '</strong> containing class <strong>' . $class_name . '</strong> definition not found');
}
kUtil::includeOnce(FULL_PATH . $this->Files[$class_name]);
}
/**
* Gets object data for caching
*
* @return Array
* @access public
*/
public function getToCache()
{
return Array (
'Factory.Files' => $this->Files,
'Factory.realClasses' => $this->realClasses,
);
}
/**
* Splits any mixing of prefix and
* special into correct ones
*
* @param string $prefix_special
* @return Array
* @access public
*/
public function processPrefix($prefix_special)
{
// l.pick, l, m.test_TagProcessor
//preg_match("/(.*)\.*(.*)(_*)(.*)/", $prefix_special, $regs);
//return Array('prefix'=>$regs[1].$regs[3].$regs[4], 'special'=>$regs[2]);
$tmp = explode('_', $prefix_special, 2);
$tmp[0] = explode('.', $tmp[0]);
$prefix = $tmp[0][0];
$prefix_special = $prefix; // new1
if ( isset($tmp[1]) ) {
$prefix .= '_' . $tmp[1];
}
$special = isset($tmp[0][1]) ? $tmp[0][1] : '';
$prefix_special .= '.' . $special; // new2
return Array ('prefix' => $prefix, 'special' => $special, 'prefix_special' => $prefix_special);
}
/**
* Returns object using params specified, creates it if is required
*
* @param string $name
* @param string $pseudo_class
* @param Array $event_params
* @param Array $arguments
* @return kBase
* @access public
+ * @throws kFactoryException
*/
public function getObject($name, $pseudo_class = '', $event_params = Array (), $arguments = Array ())
{
$name = rtrim($name, '.');
if ( isset($this->Storage[$name]) ) {
return $this->Storage[$name];
}
$ret = $this->processPrefix($name);
if ( !$pseudo_class ) {
$pseudo_class = $ret['prefix'];
}
if ( !isset($this->realClasses[$pseudo_class]) ) {
$error_msg = 'RealClass not defined for pseudo_class <strong>' . $pseudo_class . '</strong>';
if ( $this->Application->isInstalled() ) {
- throw new Exception($error_msg);
+ throw new kFactoryException($error_msg);
}
else {
if ( $this->Application->isDebugMode() ) {
$this->Application->Debugger->appendTrace();
}
trigger_error($error_msg, E_USER_WARNING);
}
return false;
}
if ( defined('DEBUG_MODE') && defined('DBG_FACTORY') && DBG_FACTORY && $this->Application->isDebugMode() ) {
$this->Application->Debugger->appendHTML('<b>Creating object:</b> Pseudo class: ' . $pseudo_class . ' Prefix: ' . $name);
$this->Application->Debugger->appendTrace();
}
$this->Storage[$name] = $this->makeClass($pseudo_class, $arguments);
$this->Storage[$name]->Init($ret['prefix'], $ret['special']);
$this->Application->EventManager->runBuildEvent($ret['prefix_special'], $pseudo_class, $event_params);
return $this->Storage[$name];
}
/**
* Removes object from storage, so next time it could be created from scratch
*
* @param string $name Object's name in the Storage
* @return void
* @access public
*/
public function DestroyObject($name)
{
unset($this->Storage[$name]);
}
/**
* Checks if object with prefix passes was already created in factory
*
* @param string $name object pseudo_class, prefix
* @return bool
* @access public
*/
public function hasObject($name)
{
return isset($this->Storage[$name]);
}
/**
* Get's real class name for pseudo class,
* includes class file and creates class
* instance.
* All parameters except first one are passed to object constuctor
* through mediator method makeClass that creates instance of class
*
* Pattern: Factory Method
*
* @param string $pseudo_class
* @param Array $arguments
* @return kBase
* @access public
*/
public function makeClass($pseudo_class, $arguments = Array ())
{
$real_class = $this->realClasses[$pseudo_class];
$mem_before = memory_get_usage();
$time_before = microtime(true);
$arguments = (array)$arguments;
if ( !$arguments ) {
$class = new $real_class();
}
else {
$reflection = new ReflectionClass($real_class);
$class = $reflection->newInstanceArgs($arguments);
}
if ( defined('DEBUG_MODE') && DEBUG_MODE && defined('DBG_PROFILE_MEMORY') && DBG_PROFILE_MEMORY && $this->Application->isDebugMode() ) {
$mem_after = memory_get_usage();
$time_after = microtime(true);
$mem_used = $mem_after - $mem_before;
$time_used = $time_after - $time_before;
$this->Application->Debugger->appendHTML('Factroy created <b>' . $real_class . '</b> - used ' . round($mem_used / 1024, 3) . 'Kb time: ' . round($time_used, 5));
$this->Application->Debugger->profilerAddTotal('objects', null, $mem_used);
}
return $class;
}
/**
* Registers new class in the factory
*
* @param string $real_class Real name of class as in class declaration
* @param string $file Filename in what $real_class is declared
* @param string $pseudo_class Name under this class object will be accessed using getObject method
* @return void
* @access public
*/
public function registerClass($real_class, $file, $pseudo_class = null)
{
if ( !isset($pseudo_class) ) {
$pseudo_class = $real_class;
}
if ( !isset($this->Files[$real_class]) ) {
$this->Files[$real_class] = preg_replace('/^' . preg_quote(FULL_PATH, '/') . '/', '', $file, 1);
}
$this->realClasses[$pseudo_class] = $real_class;
}
/**
* Unregisters existing class from factory
*
* @param string $real_class Real name of class as in class declaration
* @param string $pseudo_class Name under this class object is accessed using getObject method
* @return void
* @access public
*/
public function unregisterClass($real_class, $pseudo_class = null)
{
unset($this->Files[$real_class]);
}
+}
+
+
+class kFactoryException extends Exception {
+
}
\ No newline at end of file
Index: branches/5.2.x/core/kernel/nparser/compiler.php
===================================================================
--- branches/5.2.x/core/kernel/nparser/compiler.php (revision 15419)
+++ branches/5.2.x/core/kernel/nparser/compiler.php (revision 15420)
@@ -1,142 +1,142 @@
<?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 NParserCompiler extends kHelper {
var $Errors = array();
var $Templates = array();
function CompileTemplatesStep()
{
$templates = $this->Application->RecallVar('templates_to_compile');
if ( !$templates ) {
// build $templates
$templates = $this->FindTemplates();
}
else {
$templates = unserialize($templates);
}
$total = count($templates);
$current = $this->Application->RecallVar('current_template_to_compile');
if ( !$current ) {
$current = 0;
}
$errors = $this->Application->RecallVar('compile_errors');
if ( $errors ) {
$this->Errors = unserialize($errors);
}
kUtil::safeDefine('DBG_NPARSER_FORCE_COMPILE', 1);
$i = $current;
$this->Application->InitParser(true);
while ( $i < $total && $i < ($current + 20) ) {
$a_template = $templates[$i];
try {
$this->Application->Parser->CheckTemplate($a_template['module'] . '/' . $a_template['path']);
- } catch ( ParserException $e ) {
- $this->Errors[] = Array ('msg' => $e->getMessage(), 'file' => $e->getFile(), 'line' => $e->getLine());
+ } catch ( Exception $e ) {
+ $this->Errors[] = Array ('message' => $e->getMessage(), 'exception_class' => get_class($e), 'file' => $e->getFile(), 'line' => $e->getLine());
}
$i++;
}
$this->Application->StoreVar('current_template_to_compile', $i);
$this->Application->StoreVar('templates_to_compile', serialize($templates));
$this->Application->StoreVar('compile_errors', serialize($this->Errors));
$res = floor(($current / $total) * 100);
if ( $res == 100 || $current >= $total ) {
$this->Application->RemoveVar('templates_to_compile');
$this->Application->RemoveVar('current_template_to_compile');
$this->Application->Redirect($this->Application->GetVar('finish_template'));
}
echo $res;
}
function FindTemplates()
{
$this->Templates = Array ();
// find admin templates
foreach ($this->Application->ModuleInfo as $module => $options) {
if ($module == 'In-Portal') {
// don't check In-Portal admin templates, because it doesn't have them
continue;
}
$template_path = '/' . $options['Path'] . 'admin_templates';
$options['Path'] = $template_path;
$this->FindTemplateFiles($template_path, $options);
}
// find Front-End templates (from enabled themes only)
$sql = 'SELECT Name
FROM ' . $this->Application->getUnitOption('theme', 'TableName') . '
WHERE Enabled = 1';
$themes = $this->Conn->GetCol($sql);
$options = Array ();
foreach ($themes as $theme_name) {
$template_path = '/themes/' . $theme_name;
$options['Name'] = 'theme:' . $theme_name;
$options['Path'] = $template_path;
$this->FindTemplateFiles($template_path, $options);
}
return $this->Templates;
}
/**
* Recursively collects all TPL file across whole installation
*
* @param string $folder_path
* @param Array $options
* @return void
*/
function FindTemplateFiles($folder_path, $options)
{
// if FULL_PATH = "/" ensure, that all "/" in $folderPath are not deleted
$reg_exp = '/^' . preg_quote(FULL_PATH, '/') . '/';
$folder_path = preg_replace($reg_exp, '', $folder_path, 1); // this make sense, since $folderPath may NOT contain FULL_PATH
$iterator = new DirectoryIterator(FULL_PATH . $folder_path);
/* @var $file_info DirectoryIterator */
foreach ($iterator as $file_info) {
$filename = $file_info->getFilename();
$full_path = $file_info->getPathname();
if ( $file_info->isDir() && !$file_info->isDot() && $filename != '.svn' && $filename != 'CVS' ) {
$this->FindTemplateFiles($full_path, $options);
}
elseif ( pathinfo($full_path, PATHINFO_EXTENSION) == 'tpl' ) {
$this->Templates[] = Array (
'module' => mb_strtolower( $options['Name'] ),
'path' => str_replace(FULL_PATH . $options['Path'] . '/', '', preg_replace('/\.tpl$/', '', $full_path))
);
}
}
}
}
\ No newline at end of file
Index: branches/5.2.x/core/units/admin/admin_tag_processor.php
===================================================================
--- branches/5.2.x/core/units/admin/admin_tag_processor.php (revision 15419)
+++ branches/5.2.x/core/units/admin/admin_tag_processor.php (revision 15420)
@@ -1,1127 +1,1139 @@
<?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 AdminTagProcessor extends kDBTagProcessor {
/**
* Allows to execute js script after the page is fully loaded
*
* @param Array $params
* @return string
*/
function AfterScript($params)
{
$after_script = $this->Application->GetVar('after_script');
if ($after_script) {
return '<script type="text/javascript">'.$after_script.'</script>';
}
return '';
}
/**
* Returns section title with #section# keyword replaced with current section
*
* @param Array $params
* @return string
*/
function GetSectionTitle($params)
{
if (array_key_exists('default', $params)) {
return $params['default'];
}
return $this->Application->Phrase( kUtil::replaceModuleSection($params['phrase']) );
}
/**
* Returns section icon with #section# keyword replaced with current section
*
* @param Array $params
* @return string
*/
function GetSectionIcon($params)
{
return kUtil::replaceModuleSection($params['icon']);
}
/**
* Returns version of module by name
*
* @param Array $params
* @return string
*/
function ModuleVersion($params)
{
return $this->Application->findModule('Name', $params['module'], 'Version');
}
/**
* Used in table form section drawing
*
* @param Array $params
* @return string
*/
function DrawTree($params)
{
static $deep_level = 0;
// when processings, then sort children by priority (key of children array)
$ret = '';
$section_name = $params['section_name'];
$params['name'] = $this->SelectParam($params, 'name,render_as,block');
$sections_helper = $this->Application->recallObject('SectionsHelper');
/* @var $sections_helper kSectionsHelper */
$section_data =& $sections_helper->getSectionData($section_name);
$params['children_count'] = isset($section_data['children']) ? count($section_data['children']) : 0;
$params['deep_level'] = $deep_level++;
$template = $section_data['url']['t'];
unset($section_data['url']['t']);
$section_data['section_url'] = $this->Application->HREF($template, '', $section_data['url']);
$ret .= $this->Application->ParseBlock( array_merge($params, $section_data) );
if (!isset($section_data['children'])) {
return $ret;
}
ksort($section_data['children'], SORT_NUMERIC);
foreach ($section_data['children'] as $section_name) {
if (!$sections_helper->sectionVisible($section_name)) {
continue;
}
$params['section_name'] = $section_name;
$ret .= $this->DrawTree($params);
$deep_level--;
}
return $ret;
}
function SectionInfo($params)
{
$section = $params['section'];
if ($section == '#session#') {
$section = $this->Application->RecallVar('section');
}
$sections_helper = $this->Application->recallObject('SectionsHelper');
/* @var $sections_helper kSectionsHelper */
$section_data =& $sections_helper->getSectionData($section);
if (!$section_data) {
throw new Exception('Use of undefined section "<strong>' . $section . '</strong>" in "<strong>' . __METHOD__ . '</strong>"');
return '';
}
if (array_key_exists('parent', $params) && $params['parent']) {
do {
$section = $section_data['parent'];
$section_data =& $sections_helper->getSectionData($section);
} while (array_key_exists('use_parent_header', $section_data) && $section_data['use_parent_header']);
}
$info = $params['info'];
switch ($info) {
case 'module_path':
if (isset($params['module']) && $params['module']) {
$module = $params['module'];
}
elseif (isset($section_data['icon_module'])) {
$module = $section_data['icon_module'];
}
else {
$module = '#session#';
}
$res = $this->ModulePath(array('module' => $module));
break;
case 'perm_section':
$res = $sections_helper->getPermSection($section);
break;
case 'label':
$res = '';
if ( $section ) {
if ( $section == 'in-portal:root' ) {
// don't translate label for top section, because it's already translated
$res = $section_data['label'];
}
else {
$no_editing = array_key_exists('no_editing', $params) ? $params['no_editing'] : false;
$res = $this->Application->Phrase($section_data['label'], !$no_editing);
}
}
break;
default:
$res = $section_data[$info];
break;
}
if (array_key_exists('as_label', $params) && $params['as_label']) {
$res = $this->Application->Phrase($res);
}
return $res;
}
function PrintSection($params)
{
$section_name = $params['section_name'];
if ($section_name == '#session#') {
$section_name = $this->Application->RecallVar('section');
}
$sections_helper = $this->Application->recallObject('SectionsHelper');
/* @var $sections_helper kSectionsHelper */
if (isset($params['use_first_child']) && $params['use_first_child']) {
$section_name = $sections_helper->getFirstChild($section_name, true);
}
$section_data =& $sections_helper->getSectionData($section_name);
$params['name'] = $this->SelectParam($params, 'name,render_as,block');
$params['section_name'] = $section_name;
$template = $section_data['url']['t'];
unset($section_data['url']['t']);
$section_data['section_url'] = $this->Application->HREF($template, '', $section_data['url']);
$ret = $this->Application->ParseBlock( array_merge($params, $section_data) );
return $ret;
}
/**
* Used in XML drawing for tree
*
* @param Array $params
* @return string
*/
function PrintSections($params)
{
// when processings, then sort children by priority (key of children array)
$ret = '';
$section_name = $params['section_name'];
if ($section_name == '#session#') {
$section_name = $this->Application->RecallVar('section');
}
$sections_helper = $this->Application->recallObject('SectionsHelper');
/* @var $sections_helper kSectionsHelper */
$section_data =& $sections_helper->getSectionData($section_name);
$params['name'] = $this->SelectParam($params, 'name,render_as,block');
if (!isset($section_data['children'])) {
return '';
}
ksort($section_data['children'], SORT_NUMERIC);
foreach ($section_data['children'] as $section_name) {
$params['section_name'] = $section_name;
$section_data =& $sections_helper->getSectionData($section_name);
if (!$sections_helper->sectionVisible($section_name)) {
continue;
}
else {
$show_mode = isset($section_data['show_mode']) ? $section_data['show_mode'] : smNORMAL;
$section_data['debug_only'] = ($show_mode == smDEBUG) || ($show_mode == smSUPER_ADMIN) ? 1 : 0;
}
if (isset($section_data['tabs_only']) && $section_data['tabs_only']) {
$perm_status = false;
$folder_label = $section_data['label'];
ksort($section_data['children'], SORT_NUMERIC);
foreach ($section_data['children'] as $priority => $section_name) {
// if only tabs in this section & none of them have permission, then skip section too
$section_name = $sections_helper->getPermSection($section_name);
$perm_status = $this->Application->CheckPermission($section_name.'.view', 1);
if ($perm_status) {
break;
}
}
if (!$perm_status) {
// no permission for all tabs -> don't display tree node either
continue;
}
$params['section_name'] = $section_name;
$section_data =& $sections_helper->getSectionData($section_name);
$section_data['label'] = $folder_label; // use folder label in tree
$section_data['is_tab'] = 1;
}
else {
$section_name = $sections_helper->getPermSection($section_name);
if (!$this->Application->CheckPermission($section_name.'.view', 1)) continue;
}
$params['children_count'] = isset($section_data['children']) ? count($section_data['children']) : 0;
// remove template, so it doesn't appear as additional parameter in url
$template = $section_data['url']['t'];
unset($section_data['url']['t']);
$section_data['section_url'] = $this->Application->HREF($template, '', $section_data['url']);
$late_load = getArrayValue($section_data, 'late_load');
if ($late_load) {
$t = $late_load['t'];
unset($late_load['t']);
$section_data['late_load'] = $this->Application->HREF($t, '', $late_load);
$params['children_count'] = 99;
}
else {
$section_data['late_load'] = '';
}
// restore template
$section_data['url']['t'] = $template;
$ret .= $this->Application->ParseBlock( array_merge($params, $section_data) );
$params['section_name'] = $section_name;
}
return preg_replace("/\r\n|\n/", '', $ret);
}
function ListSectionPermissions($params)
{
$section_name = isset($params['section_name']) ? $params['section_name'] : $this->Application->GetVar('section_name');
$sections_helper = $this->Application->recallObject('SectionsHelper');
/* @var $sections_helper kSectionsHelper */
$section_data =& $sections_helper->getSectionData($section_name);
$block_params = array_merge($section_data, Array('name' => $params['render_as'], 'section_name' => $section_name));
$ret = '';
foreach ($section_data['permissions'] as $perm_name) {
if (preg_match('/^advanced:(.*)/', $perm_name) != $params['type']) continue;
$block_params['perm_name'] = $perm_name;
$ret .= $this->Application->ParseBlock($block_params);
}
return $ret;
}
function ModuleInclude($params)
{
foreach ($params as $param_name => $param_value) {
$params[$param_name] = kUtil::replaceModuleSection($param_value);
}
return $this->Application->ProcessParsedTag('m', 'ModuleInclude', $params);
}
function TodayDate($params)
{
return date($params['format']);
}
function TreeEditWarrning($params)
{
$ret = $this->Application->Phrase($params['label']);
$ret = str_replace(Array('&lt;', '&gt;', 'br/', 'br /', "\n", "\r"), Array('<', '>', 'br', 'br', '', ''), $ret);
if (getArrayValue($params, 'escape')) {
$ret = addslashes($ret);
}
$ret = str_replace('<br>', '\n', $ret);
return $ret;
}
/**
* Draws section tabs using block name passed
*
* @param Array $params
*/
function ListTabs($params)
{
$sections_helper = $this->Application->recallObject('SectionsHelper');
/* @var $sections_helper kSectionsHelper */
$section_data =& $sections_helper->getSectionData($params['section_name']);
$ret = '';
$block_params = Array('name' => $params['render_as']);
ksort($section_data['children'], SORT_NUMERIC);
foreach ($section_data['children'] as $priority => $section_name) {
$perm_section = $sections_helper->getPermSection($section_name);
if ( !$this->Application->CheckPermission($perm_section.'.view') ) {
continue;
}
$tab_data =& $sections_helper->getSectionData($section_name);
$block_params['t'] = $tab_data['url']['t'];
$block_params['pass'] = $tab_data['url']['pass'];
$block_params['title'] = $tab_data['label'];
$block_params['main_prefix'] = $section_data['SectionPrefix'];
$ret .= $this->Application->ParseBlock($block_params);
}
return $ret;
}
/**
* Returns list of module item tabs that have view permission in current category
*
* @param Array $params
*/
function ListCatalogTabs($params)
{
$ret = '';
$special = isset($params['special']) ? $params['special'] : '';
$replace_main = isset($params['replace_m']) && $params['replace_m'];
$skip_prefixes = isset($params['skip_prefixes']) ? explode(',', $params['skip_prefixes']) : Array();
$block_params = $this->prepareTagParams($params);
$block_params['name'] = $params['render_as'];
foreach ($this->Application->ModuleInfo as $module_name => $module_info) {
$prefix = $module_info['Var'];
if ($prefix == 'm' && $replace_main) {
$prefix = 'c';
}
if (in_array($prefix, $skip_prefixes) || !$this->Application->prefixRegistred($prefix) || !$this->Application->getUnitOption($prefix, 'CatalogItem')) {
continue;
}
$icon = $this->Application->getUnitOption($prefix, 'CatalogTabIcon');
if (strpos($icon, ':') !== false) {
list ($icon_module, $icon) = explode(':', $icon, 2);
}
else {
$icon_module = 'core';
}
$label = $this->Application->getUnitOption($prefix, $params['title_property']);
$block_params['title'] = $label;
$block_params['prefix'] = $prefix;
$block_params['icon_module'] = $icon_module;
$block_params['icon'] = $icon;
$ret .= $this->Application->ParseBlock($block_params);
}
return $ret;
}
/**
* Renders inividual catalog tab based on prefix and title_property given
*
* @param Array $params
* @return string
*/
function CatalogTab($params)
{
$icon = $this->Application->getUnitOption($params['prefix'], 'CatalogTabIcon');
if (strpos($icon, ':') !== false) {
list ($icon_module, $icon) = explode(':', $icon, 2);
}
else {
$icon_module = 'core';
}
$block_params = $this->prepareTagParams($params);
$block_params['name'] = $params['render_as'];
$block_params['icon_module'] = $icon_module;
$block_params['icon'] = $icon;
$block_params['title'] = $this->Application->getUnitOption($params['prefix'], $params['title_property']);
return $this->Application->ParseBlock($block_params);
}
/**
* Allows to construct link for opening any type of catalog item selector
*
* @param Array $params
* @return string
*/
function SelectorLink($params)
{
$mode = 'catalog';
if (isset($params['mode'])) { // {catalog, advanced_view}
$mode = $params['mode'];
unset($params['mode']);
}
$params['t'] = 'catalog/item_selector/item_selector_'.$mode;
$params['m_cat_id'] = $this->Application->getBaseCategory();
$default_params = Array('no_amp' => 1, 'pass' => 'all,'.$params['prefix']);
unset($params['prefix']);
$pass_through = Array();
if (isset($params['tabs_dependant'])) { // {yes, no}
$pass_through['td'] = $params['tabs_dependant'];
unset($params['tabs_dependant']);
}
if (isset($params['selection_mode'])) { // {single, multi}
$pass_through['tm'] = $params['selection_mode'];
unset($params['selection_mode']);
}
if (isset($params['tab_prefixes'])) { // {all, none, <comma separated prefix list>}
$pass_through['tp'] = $params['tab_prefixes'];
unset($params['tab_prefixes']);
}
if ($pass_through) {
// add pass_through to selector url if any
$params['pass_through'] = implode(',', array_keys($pass_through));
$params = array_merge($params, $pass_through);
}
// user can override default parameters (except pass_through of course)
$params = array_merge($default_params, $params);
return $this->Application->ProcessParsedTag('m', 'T', $params);
}
function TimeFrame($params)
{
$w = adodb_date('w');
$m = adodb_date('m');
$y = adodb_date('Y');
//FirstDayOfWeek is 0 for Sunday and 1 for Monday
$fdow = $this->Application->ConfigValue('FirstDayOfWeek');
if ( $fdow && $w == 0 ) {
$w = 7;
}
$today_start = adodb_mktime(0, 0, 0, adodb_date('m'), adodb_date('d'), $y);
$first_day_of_this_week = $today_start - ($w - $fdow) * 86400;
$first_day_of_this_month = adodb_mktime(0, 0, 0, $m, 1, $y);
$this_quater = ceil($m / 3);
$this_quater_start = adodb_mktime(0, 0, 0, $this_quater * 3 - 2, 1, $y);
switch ( $params['type'] ) {
case 'last_week_start':
$timestamp = $first_day_of_this_week - 86400 * 7;
break;
case 'last_week_end':
$timestamp = $first_day_of_this_week - 1;
break;
case 'last_month_start':
$timestamp = $m == 1 ? adodb_mktime(0, 0, 0, 12, 1, $y - 1) : adodb_mktime(0, 0, 0, $m - 1, 1, $y);
break;
case 'last_month_end':
$timestamp = $first_day_of_this_month = adodb_mktime(0, 0, 0, $m, 1, $y) - 1;
break;
case 'last_quater_start':
$timestamp = $this_quater == 1 ? adodb_mktime(0, 0, 0, 10, 1, $y - 1) : adodb_mktime(0, 0, 0, ($this_quater - 1) * 3 - 2, 1, $y);
break;
case 'last_quater_end':
$timestamp = $this_quater_start - 1;
break;
case 'last_6_months_start':
$timestamp = $m <= 6 ? adodb_mktime(0, 0, 0, $m + 6, 1, $y - 1) : adodb_mktime(0, 0, 0, $m - 6, 1, $y);
break;
case 'last_year_start':
$timestamp = adodb_mktime(0, 0, 0, 1, 1, $y - 1);
break;
case 'last_year_end':
$timestamp = adodb_mktime(23, 59, 59, 12, 31, $y - 1);
break;
default:
$timestamp = 0;
break;
}
if ( isset($params['format']) ) {
$format = $params['format'];
if ( preg_match("/_regional_(.*)/", $format, $regs) ) {
$lang = $this->Application->recallObject('lang.current');
/* @var $lang LanguagesItem */
$format = $lang->GetDBField($regs[1]);
}
return adodb_date($format, $timestamp);
}
return $timestamp;
}
/**
* Redirect to cache rebuild template, when required by installator
*
* @param Array $params
*/
function CheckPermCache($params)
{
// we have separate session between install wizard and admin console, so store in cache
$global_mark = $this->Application->getDBCache('ForcePermCacheUpdate');
$local_mark = $this->Application->RecallVar('PermCache_UpdateRequired');
if ($global_mark || $local_mark) {
$this->Application->RemoveVar('PermCache_UpdateRequired');
if ($this->Application->ConfigValue('QuickCategoryPermissionRebuild')) {
$updater = $this->Application->makeClass('kPermCacheUpdater');
/* @var $updater kPermCacheUpdater */
$updater->OneStepRun();
$this->Application->HandleEvent(new kEvent('c:OnResetCMSMenuCache'));
}
else {
// update with progress bar
return true;
}
}
return false;
}
/**
* Checks if current protocol is SSL
*
* @param Array $params
* @return int
*/
function IsSSL($params)
{
return (PROTOCOL == 'https://')? 1 : 0;
}
function PrintColumns($params)
{
$picker_helper = $this->Application->recallObject('ColumnPickerHelper');
$picker_helper->SetGridName($this->Application->GetLinkedVar('grid_name'));
/* @var $picker_helper kColumnPickerHelper */
$main_prefix = $this->Application->RecallVar('main_prefix');
$cols = $picker_helper->LoadColumns($main_prefix);
$this->Application->Phrases->AddCachedPhrase('__FREEZER__', '-------------');
$o = '';
if (isset($params['hidden']) && $params['hidden']) {
foreach ($cols['hidden_fields'] as $col) {
$title = $this->Application->Phrase($cols['titles'][$col]);
$o .= "<option value='$col'>".$title;
}
}
else {
foreach ($cols['order'] as $col) {
if (in_array($col, $cols['hidden_fields'])) continue;
$title = $this->Application->Phrase($cols['titles'][$col]);
$o .= "<option value='$col'>".$title;
}
}
return $o;
}
/**
* Allows to set popup size (key - current template name)
*
* @param Array $params
*/
function SetPopupSize($params)
{
$width = $params['width'];
$height = $params['height'];
if ($this->Application->GetVar('ajax') == 'yes') {
// during AJAX request just output size
die($width.'x'.$height);
}
if (!$this->UsePopups($params)) {
return ;
}
$t = $this->Application->GetVar('t');
$sql = 'SELECT *
FROM '.TABLE_PREFIX.'PopupSizes
WHERE TemplateName = '.$this->Conn->qstr($t);
$popup_info = $this->Conn->GetRow($sql);
if (!$popup_info) {
// create new popup size record
$fields_hash = Array (
'TemplateName' => $t,
'PopupWidth' => $width,
'PopupHeight' => $height,
);
$this->Conn->doInsert($fields_hash, TABLE_PREFIX.'PopupSizes');
}
elseif ($popup_info['PopupWidth'] != $width || $popup_info['PopupHeight'] != $height) {
// popup found and size in tag differs from one in db -> update in db
$fields_hash = Array (
'PopupWidth' => $width,
'PopupHeight' => $height,
);
$this->Conn->doUpdate($fields_hash, TABLE_PREFIX.'PopupSizes', 'PopupId = '.$popup_info['PopupId']);
}
}
/**
* Returns popup size (by template), if not cached, then parse template to get value
*
* @param Array $params
* @return string
*/
function GetPopupSize($params)
{
$t = $this->Application->GetVar('template_name');
$sql = 'SELECT *
FROM '.TABLE_PREFIX.'PopupSizes
WHERE TemplateName = '.$this->Conn->qstr($t);
$popup_info = $this->Conn->GetRow($sql);
if (!$popup_info) {
$this->Application->InitParser();
$this->Application->ParseBlock(array('name' => $t)); // dies when SetPopupSize tag found & in ajax requrest
return '750x400'; // tag SetPopupSize not found in template -> use default size
}
return $popup_info['PopupWidth'].'x'.$popup_info['PopupHeight'];
}
/**
* Allows to check if popups are generally enabled OR to check for "popup" or "modal" mode is enabled
*
* @param Array $params
* @return bool
*/
function UsePopups($params)
{
if ($this->Application->GetVar('_force_popup')) {
return true;
}
$use_popups = (int)$this->Application->ConfigValue('UsePopups');
if (array_key_exists('mode', $params)) {
$mode_mapping = Array ('popup' => 1, 'modal' => 2);
return $use_popups == $mode_mapping[ $params['mode'] ];
}
return $use_popups;
}
function UseToolbarLabels($params)
{
return (int)$this->Application->ConfigValue('UseToolbarLabels');
}
/**
* Checks if debug mode enabled (optionally) and specified constant is on
*
* @param Array $params
* @return bool
* @todo Could be a duplicate of kMainTagProcessor::ConstOn
*/
function ConstOn($params)
{
$constant_name = $this->SelectParam($params, 'name,const');
$debug_mode = isset($params['debug_mode']) && $params['debug_mode'] ? $this->Application->isDebugMode() : true;
return $debug_mode && kUtil::constOn($constant_name);
}
/**
* Builds link to last template in main frame of admin
*
* @param Array $params
* @return string
*/
function MainFrameLink($params)
{
$persistent = isset($params['persistent']) && $params['persistent'];
if ($persistent && $this->Application->ConfigValue('RememberLastAdminTemplate')) {
// check last_template in persistent session
$last_template = $this->Application->RecallPersistentVar('last_template_popup');
}
else {
// check last_template in session
$last_template = $this->Application->RecallVar('last_template_popup'); // because of m_opener=s there
}
if (!$last_template) {
$params['persistent'] = 1;
return $persistent ? false : $this->MainFrameLink($params);
}
list($index_file, $env) = explode('|', $last_template);
$vars = $this->Application->processQueryString($env, 'pass');
$recursion_templates = Array ('login', 'index', 'no_permission');
if (isset($vars['admin']) && $vars['admin'] == 1) {
// index template doesn't begin recursion on front-end (in admin frame)
$vars['m_theme'] = '';
if (isset($params['m_opener']) && $params['m_opener'] == 'r') {
// front-end link for highlighting purposes
$vars['t'] = 'index';
$vars['m_cat_id'] = $this->Application->getBaseCategory();
}
unset($recursion_templates[ array_search('index', $recursion_templates)]);
}
if (in_array($vars['t'], $recursion_templates)) {
// prevents redirect recursion OR old in-portal pages
$params['persistent'] = 1;
return $persistent ? false : $this->MainFrameLink($params);
}
$vars = array_merge($vars, $params);
$t = $vars['t'];
unset($vars['t'], $vars['persistent']);
// substitute language in link to current (link will work, even when language will be changed)
$vars['m_lang'] = $this->Application->GetVar('m_lang');
return $this->Application->HREF($t, '', $vars, $index_file);
}
/**
* Returns menu frame width or 200 in case, when invalid width specified in config
*
* @param Array $params
* @return string
*/
function MenuFrameWidth($params)
{
$width = (int)$this->Application->ConfigValue('MenuFrameWidth');
return $width > 0 ? $width : 200;
}
function AdminSkin($params)
{
$skin_helper = $this->Application->recallObject('SkinHelper');
/* @var $skin_helper SkinHelper */
return $skin_helper->AdminSkinTag($params);
}
/**
* Prints errors, discovered during mass template compilation
*
* @param $params
* @return string
* @access protected
*/
protected function PrintCompileErrors($params)
{
$block_params = $this->prepareTagParams($params);
$block_params['name'] = $params['render_as'];
$errors = $this->Application->RecallVar('compile_errors');
if ( !$errors ) {
return '';
}
$ret = '';
$errors = unserialize($errors);
+ $path_regexp = '/^' . preg_quote(FULL_PATH, '/') . '/';
foreach ($errors as $an_error) {
- $block_params['file'] = str_replace(FULL_PATH, '', $an_error['file']);
- $block_params['line'] = $an_error['line'];
- $block_params['message'] = $an_error['msg'];
+ $block_params = array_merge($block_params, $an_error);
+ $block_params['file'] = preg_replace($path_regexp, '', $an_error['file'], 1);
$ret .= $this->Application->ParseBlock($block_params);
}
$this->Application->RemoveVar('compile_errors');
return $ret;
}
function CompileErrorCount($params)
{
$errors = $this->Application->RecallVar('compile_errors');
if (!$errors) {
return 0;
}
return count( unserialize($errors) );
}
+ /**
+ * Detects if given exception isn't one caused by tag error
+ *
+ * @param Array $params
+ * @return string
+ * @access protected
+ */
+ protected function IsParserException($params)
+ {
+ return mb_strtolower($params['class']) == 'parserexception';
+ }
+
function ExportData($params)
{
$export_helper = $this->Application->recallObject('CSVHelper');
/* @var $export_helper kCSVHelper */
$result = $export_helper->ExportData( $this->SelectParam($params, 'var,name,field') );
return ($result === false) ? '' : $result;
}
function ImportData($params)
{
$import_helper = $this->Application->recallObject('CSVHelper');
/* @var $import_helper kCSVHelper */
$result = $import_helper->ImportData( $this->SelectParam($params, 'var,name,field') );
return ($result === false) ? '' : $result;
}
function PrintCSVNotImportedLines($params)
{
$import_helper = $this->Application->recallObject('CSVHelper');
/* @var $import_helper kCSVHelper */
return $import_helper->GetNotImportedLines();
}
/**
* Returns input field name to
* be placed on form (for correct
* event processing)
*
* @param Array $params
* @return string
* @access public
*/
function InputName($params)
{
list($id, $field) = $this->prepareInputName($params);
$ret = $this->getPrefixSpecial().'[0]['.$field.']'; // 0 always, as has no idfield
if( getArrayValue($params, 'as_preg') ) $ret = preg_quote($ret, '/');
return $ret;
}
/**
* Returns list of all backup file dates formatted
* in passed block
*
* @param Array $params
* @return string
* @access public
*/
function PrintBackupDates($params)
{
$backup_helper = $this->Application->recallObject('BackupHelper');
/* @var $backup_helper BackupHelper */
$ret = '';
$dates = $backup_helper->getBackupFiles();
foreach ($dates as $date) {
$params['backuptimestamp'] = $date['filedate'];
$params['backuptime'] = date('F j, Y, g:i a', $date['filedate']);
$params['backupsize'] = round($date['filesize'] / 1024 / 1024, 2); // MBytes
$ret .= $this->Application->ParseBlock($params);
}
return $ret;
}
/**
* Returns phpinfo() output
*
* @param Array $params
* @return string
*/
function PrintPHPinfo($params)
{
ob_start();
phpinfo();
return ob_get_clean();
}
function PrintSqlCols($params)
{
$a_data = unserialize($this->Application->GetVar('sql_rows'));
$ret = '';
$block = $params['render_as'];
foreach ($a_data AS $a_row)
{
foreach ($a_row AS $col => $value)
{
$ret .= $this->Application->ParseBlock(Array('name'=>$block, 'value'=>$col));
}
break;
}
return $ret;
}
function PrintSqlRows($params)
{
$a_data = unserialize($this->Application->GetVar('sql_rows'));
$ret = '';
$block = $params['render_as'];
foreach ($a_data AS $a_row)
{
$cells = '';
foreach ($a_row AS $col => $value)
{
$cells .= '<td>'.$value.'</td>';
}
$ret .= $this->Application->ParseBlock(Array('name'=>$block, 'cells'=>$cells));
}
return $ret;
}
/**
* Prints available and enabled import sources using given block
*
* @param Array $params
* @return string
*/
function PrintImportSources($params)
{
$sql = 'SELECT *
FROM ' . TABLE_PREFIX . 'ImportScripts
WHERE (Status = ' . STATUS_ACTIVE . ') AND (Type = "CSV")';
$import_sources = $this->Conn->Query($sql);
$block_params = $this->prepareTagParams($params);
$block_params['name'] = $params['render_as'];
$ret = '';
foreach ($import_sources as $import_source) {
$block_params['script_id'] = $import_source['ImportId'];
$block_params['script_module'] = mb_strtolower($import_source['Module']);
$block_params['script_name'] = $import_source['Name'];
$block_params['script_prefix'] = $import_source['Prefix'];
$block_params['module_path'] = $this->Application->findModule('Name', $import_source['Module'], 'Path');
$ret .= $this->Application->ParseBlock($block_params);
}
return $ret;
}
/**
* Checks, that new window should be opened in "incs/close_popup" template instead of refreshing parent window
*
* @param Array $params
* @return bool
*/
function OpenNewWindow($params)
{
if (!$this->UsePopups($params)) {
return false;
}
$diff = array_key_exists('diff', $params) ? $params['diff'] : 0;
$wid = $this->Application->GetVar('m_wid');
$stack_name = rtrim('opener_stack_' . $wid, '_');
$opener_stack = $this->Application->RecallVar($stack_name);
$opener_stack = $opener_stack ? unserialize($opener_stack) : Array ();
return count($opener_stack) >= 2 - $diff;
}
/**
* Allows to dynamically change current language in template
*
* @param Array $params
*/
function SetLanguage($params)
{
$this->Application->SetVar('m_lang', $params['language_id']);
$this->Application->Phrases->Init('phrases', '', $params['language_id']);
}
/**
* Performs HTTP Authentification for administrative console
*
* @param Array $params
*/
function HTTPAuth($params)
{
if (!$this->Application->ConfigValue('UseHTTPAuth')) {
// http authentification not required
return true;
}
$super_admin_ips = defined('SA_IP') ? SA_IP : false;
$auth_bypass_ips = $this->Application->ConfigValue('HTTPAuthBypassIPs');
if (($auth_bypass_ips && kUtil::ipMatch($auth_bypass_ips)) || ($super_admin_ips && kUtil::ipMatch($super_admin_ips))) {
// user ip is in ip bypass list
return true;
}
if (!array_key_exists('PHP_AUTH_USER', $_SERVER)) {
// ask user to authentificate, when not authentificated before
return $this->_httpAuthentificate();
}
else {
// validate user credentials (browsers remembers user/password
// and sends them each time page is visited, so no need to save
// authentification result in session)
if ($this->Application->ConfigValue('HTTPAuthUsername') != $_SERVER['PHP_AUTH_USER']) {
// incorrect username
return $this->_httpAuthentificate();
}
$password_formatter = $this->Application->recallObject('kPasswordFormatter');
/* @var $password_formatter kPasswordFormatter */
$password = $password_formatter->EncryptPassword($_SERVER['PHP_AUTH_PW'], 'b38');
if ($this->Application->ConfigValue('HTTPAuthPassword') != $password) {
// incorrect password
return $this->_httpAuthentificate();
}
}
return true;
}
/**
* Ask user to authentificate
*
* @return false
*/
function _httpAuthentificate()
{
$realm = strip_tags( $this->Application->ConfigValue('Site_Name') );
header('WWW-Authenticate: Basic realm="' . $realm . '"');
header('HTTP/1.0 401 Unauthorized');
return false;
}
/**
* Checks, that we are using memory cache
*
* @param Array $params
* @return bool
*/
function MemoryCacheEnabled($params)
{
return $this->Application->isCachingType(CACHING_TYPE_MEMORY);
}
}
\ No newline at end of file
Index: branches/5.2.x/core/admin_templates/tools/compile_complete.tpl
===================================================================
--- branches/5.2.x/core/admin_templates/tools/compile_complete.tpl (revision 15419)
+++ branches/5.2.x/core/admin_templates/tools/compile_complete.tpl (revision 15420)
@@ -1,52 +1,58 @@
<inp2:m_include t="incs/header"/>
<inp2:m_RenderElement name="combined_header" prefix="adm" section="in-portal:service" title_preset="system_tools"/>
<!-- ToolBar -->
<table class="toolbar" height="30" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td>
<script type="text/javascript">
var a_toolbar = new ToolBar();
a_toolbar.AddButton(
new ToolBarButton(
'cancel',
'<inp2:m_phrase label="la_ToolTip_Close" escape="1"/>',
function() {
window_close();
}
)
);
a_toolbar.Render();
</script>
</td>
</tr>
</tbody>
</table>
<div id="scroll_container">
<table class="edit-form" border="1">
<tr class="subsectiontitle">
<td colspan="3">Errors (<inp2:adm_CompileErrorCount/>):</td>
</tr>
<tr class="subsectiontitle">
<td><strong>File</strong></td>
<td><strong>Line</strong></td>
<td><strong>Message</strong></td>
</tr>
<inp2:m_DefineElement name="compile_error_element">
<tr class="<inp2:m_odd_even odd='table-color1' even='table-color2'/>">
<td><inp2:m_Param name="file"/></td>
<td><inp2:m_Param name="line"/></td>
- <td><inp2:m_Param name="message"/></td>
+ <td>
+ <inp2:m_ifnot check="adm_IsParserException" class="$exception_class">
+ <strong><inp2:m_Param name="exception_class"/></strong>:
+ </inp2:m_ifnot>
+
+ <inp2:m_Param name="message" html_escape="1"/>
+ </td>
</tr>
</inp2:m_DefineElement>
<inp2:adm_PrintCompileErrors render_as="compile_error_element"/>
</table>
</div>
<inp2:m_include t="incs/footer"/>
\ No newline at end of file

Event Timeline