Index: branches/5.1.x/core/kernel/db/db_tag_processor.php =================================================================== diff -u -N -r12127 -r12657 --- branches/5.1.x/core/kernel/db/db_tag_processor.php (.../db_tag_processor.php) (revision 12127) +++ branches/5.1.x/core/kernel/db/db_tag_processor.php (.../db_tag_processor.php) (revision 12657) @@ -1,6 +1,6 @@ SelectParam($params, 'types'); - $except = $this->SelectParam($params, 'except'); - $list_name = $this->SelectParam($params, 'list_name'); + $types = array_key_exists('types', $params) ? $params['types'] : ''; + $except = array_key_exists('except', $params) ? $params['except'] : ''; + $list_name = array_key_exists('list_name', $params) ? $params['list_name'] : ''; + if (!$list_name) { $list_name = $this->Application->Parser->GetParam('list_name'); } - return $types.$except.$list_name; + return $types . $except . $list_name; } /** @@ -384,38 +387,39 @@ } $requery = isset($params['requery']) && $params['requery']; - if ($list_name && !$requery){ + if ($list_name && !$requery) { $names_mapping = $this->Application->GetVar('NamesToSpecialMapping'); $special = is_array($names_mapping) && isset($names_mapping[$this->Prefix]) && isset($names_mapping[$this->Prefix][$list_name]) ? $names_mapping[$this->Prefix][$list_name] : false; // $special = getArrayValue($names_mapping, $this->Prefix, $list_name); - if(!$special) - { + if (!$special) { $special = $this->BuildListSpecial($params); } } - else - { + else { $special = $this->BuildListSpecial($params); } $prefix_special = rtrim($this->Prefix.'.'.$special, '.'); $params['skip_counting'] = true; + $list =& $this->Application->recallObject( $prefix_special, $this->Prefix.'_List', $params); /* @var $list kDBList */ - if ($requery) { - $this->Application->HandleEvent($an_event, $prefix_special.':OnListBuild', $params); - } + if (!array_key_exists('skip_quering', $params) || !$params['skip_quering']) { + if ($requery) { + $this->Application->HandleEvent($an_event, $prefix_special.':OnListBuild', $params); + } - if (array_key_exists('offset', $params)) { - $list->Offset += $params['offset']; // apply custom offset - } + if (array_key_exists('offset', $params)) { + $list->Offset += $params['offset']; // apply custom offset + } - $list->Query($requery); + $list->Query($requery); - if (array_key_exists('offset', $params)) { - $list->Offset -= $params['offset']; // remove custom offset + if (array_key_exists('offset', $params)) { + $list->Offset -= $params['offset']; // remove custom offset + } } $this->Special = $special; @@ -432,7 +436,11 @@ { $list =& $this->GetList($params); $ret = $list->getPrefixSpecial(); - if( getArrayValue($params, 'as_preg') ) $ret = preg_quote($ret, '/'); + + if (array_key_exists('as_preg', $params) && $params['as_preg']) { + $ret = preg_quote($ret, '/'); + } + return $ret; } @@ -647,6 +655,7 @@ function ColumnWidth($params) { $columns = $this->Application->Parser->GetParam('columns'); + return round(100/$columns).'%'; } @@ -726,68 +735,72 @@ $object =& $this->getObject($params); - if ( $this->HasParam($params, 'db') ) - { + if (array_key_exists('db', $params) && $params['db']) { $value = $object->GetDBField($field); } - else - { - if( $this->HasParam($params, 'currency') ) - { + else { + if (array_key_exists('currency', $params) && $params['currency']) { $iso = $this->GetISO($params['currency']); $original = $object->GetDBField($field); $value = $this->ConvertCurrency($original, $iso); $object->SetDBField($field, $value); $object->Fields[$field]['converted'] = true; } - $format = getArrayValue($params, 'format'); + $format = array_key_exists('format', $params) ? $params['format'] : false; if (!$format || $format == '$format') { $format = null; } $value = $object->GetField($field, $format); - if( $this->SelectParam($params, 'negative') ) - { - if(strpos($value, '-') === 0) - { + if (array_key_exists('negative', $params) && $params['negative']) { + if (strpos($value, '-') === 0) { $value = substr($value, 1); } - else - { - $value = '-'.$value; + else { + $value = '-' . $value; } } - if( $this->HasParam($params, 'currency') ) - { + if (array_key_exists('currency', $params) && $params['currency']) { $value = $this->AddCurrencySymbol($value, $iso); $params['no_special'] = 1; } } - if( !$this->HasParam($params, 'no_special') ) $value = htmlspecialchars($value); - if( getArrayValue($params,'checked' ) ) $value = ($value == ( isset($params['value']) ? $params['value'] : 1)) ? 'checked' : ''; - if( isset($params['plus_or_as_label']) ) { + if (!array_key_exists('no_special', $params) || !$params['no_special']) { + $value = htmlspecialchars($value); + } + + if (array_key_exists('checked', $params) && $params['checked']) { + $value = ($value == ( isset($params['value']) ? $params['value'] : 1)) ? 'checked' : ''; + } + + if (array_key_exists('plus_or_as_label', $params) && $params['plus_or_as_label']) { $value = substr($value, 0,1) == '+' ? substr($value, 1) : $this->Application->Phrase($value); } - elseif( isset($params['as_label']) && $params['as_label'] ) $value = $this->Application->Phrase($value); + elseif (array_key_exists('as_label', $params) && $params['as_label']) { + $value = $this->Application->Phrase($value); + } $first_chars = $this->SelectParam($params,'first_chars,cut_first'); - if($first_chars) - { + if ($first_chars) { $needs_cut = mb_strlen($value) > $first_chars; $value = mb_substr($value, 0, $first_chars); if ($needs_cut) $value .= ' ...'; } - if( getArrayValue($params,'nl2br' ) ) $value = nl2br($value); - if ($value != '') $this->Application->Parser->DataExists = true; + if (array_key_exists('nl2br', $params) && $params['nl2br']) { + $value = nl2br($value); + } - if( $this->HasParam($params, 'currency') ) - { - //restoring value in original currency, for other Field tags to work properly + if ($value != '') { + $this->Application->Parser->DataExists = true; + } + + if (array_key_exists('currency', $params) && $params['currency']) { + // restoring value in original currency, for other Field tags to work properly $object->SetDBField($field, $original); } @@ -806,25 +819,6 @@ $object->SetDBField($dst_field, $src_object->GetDBField($src_field)); } - /** - * Checks if parameter is passed - * Note: works like Tag and line simple method too - * - * @param Array $params - * @param string $param_name - * @return bool - */ - function HasParam($params, $param_name = null) - { - if( !isset($param_name) ) - { - $param_name = $this->SelectParam($params, 'name'); - $params = $this->Application->Parser->Params; - } - $value = isset($params[$param_name]) ? $params[$param_name] : false; - return $value && ($value != '$'.$param_name); - } - function PhraseField($params) { $field_label = $this->Field($params); @@ -846,7 +840,7 @@ { $object =& $this->getObject($params); - $skip_fields = getArrayValue($params, 'except'); + $skip_fields = array_key_exists('except', $params) ? $params['except'] : false; $skip_fields = $skip_fields ? explode(',', $skip_fields) : Array(); return $object->HasErrors($skip_fields); @@ -889,7 +883,8 @@ } $options = $object->GetFieldOptions($field); - return getArrayValue($options,'required'); + + return array_key_exists('required', $options) ? $options['required'] : false; } function FieldOption($params) @@ -915,7 +910,7 @@ $options = $field_options['options']; - if ($this->HasParam($params, 'has_empty')) { + if (array_key_exists('has_empty', $params) && $params['has_empty']) { $empty_value = array_key_exists('empty_value', $params) ? $params['empty_value'] : ''; $options = array_merge_recursive2(Array ($empty_value => ''), $options); // don't use other array merge function, because they will reset keys !!! } @@ -931,14 +926,14 @@ $block_params['field_name'] = $this->InputName($params); // depricated (produces warning when used as grid filter), but used in Front-End (submission create), admin (submission view) } - $selected_param_name = getArrayValue($params, 'selected_param'); + $selected_param_name = array_key_exists('selected_param', $params) ? $params['selected_param'] : false; if (!$selected_param_name) { $selected_param_name = $params['selected']; } $selected = $params['selected']; $o = ''; - if ($this->HasParam($params, 'no_empty') && !getArrayValue($options, '')) { + if (array_key_exists('no_empty', $params) && $params['no_empty'] && !getArrayValue($options, '')) { // removes empty option, when present (needed?) array_shift($options); } @@ -967,7 +962,7 @@ function PredefinedSearchOptions($params) { - $object =& $this->getObject($params); + $object =& $this->GetList($params); /* @var $object kDBList */ $params['value'] = $this->SearchField($params); @@ -984,18 +979,17 @@ $format = $options[ $this->SelectParam($params, 'input_format') ? 'input_format' : 'format' ]; - $formatter_class = getArrayValue($options,'formatter'); + $formatter_class = array_key_exists('formatter', $options) ? $options['formatter'] : false; + if ($formatter_class) { $formatter =& $this->Application->recallObject($formatter_class); - $human_format = getArrayValue($params,'human'); - $edit_size = getArrayValue($params,'edit_size'); - $sample = getArrayValue($params,'sample'); - if($sample) - { + $human_format = array_key_exists('human', $params) ? $params['human'] : false; + $edit_size = array_key_exists('edit_size', $params) ? $params['edit_size'] : false; + $sample = array_key_exists('sample', $params) ? $params['sample'] : false; + if ($sample) { return $formatter->GetSample($field, $options, $object); } - elseif($human_format || $edit_size) - { + elseif ($human_format || $edit_size) { $format = $formatter->HumanFormat($format); return $edit_size ? strlen($format) : $format; } @@ -1204,7 +1198,7 @@ $id = $params['force_id']; } else { - $id_field = getArrayValue($params, 'IdField'); + $id_field = array_key_exists('IdField', $params) ? $params['IdField'] : false; $id = $id_field ? $object->GetDBField($id_field) : $object->GetID(); } @@ -1226,7 +1220,11 @@ list($id, $field) = $this->prepareInputName($params); $ret = $this->getPrefixSpecial().'['.$id.']['.$field.']'; - if( getArrayValue($params, 'as_preg') ) $ret = preg_quote($ret, '/'); + + if (array_key_exists('as_preg', $params) && $params['as_preg']) { + $ret = preg_quote($ret, '/'); + } + return $ret; } @@ -1243,8 +1241,11 @@ list($id, $field) = $this->prepareInputName($params); $ret = 'field_modifiers['.$this->getPrefixSpecial().']['.$field.']['.$params['type'].']'; - if( getArrayValue($params, 'as_preg') ) $ret = preg_quote($ret, '/'); + if (array_key_exists('as_preg', $params) && $params['as_preg']) { + $ret = preg_quote($ret, '/'); + } + if (isset($params['value'])) { $object =& $this->getObject($params); $field_modifiers[$field][$params['type']] = $params['value']; @@ -1480,9 +1481,8 @@ function FieldEquals($params) { $object =& $this->getObject($params); - $ret = $object->GetDBField($this->SelectParam($params, 'name,field')) == $params['value']; -// if( getArrayValue($params,'inverse') ) $ret = !$ret; - return $ret; + + return $object->GetDBField( $this->SelectParam($params, 'name,field') ) == $params['value']; } /** @@ -1532,23 +1532,38 @@ function ItemIcon($params) { - $object =& $this->getObject($params); + $grids = $this->Application->getUnitOption($this->Prefix, 'Grids'); + $grid = $grids[ $params['grid'] ]; - $grids = $this->Application->getUnitOption($this->Prefix,'Grids'); - $icons =& $grids[ $params['grid'] ]['Icons']; + if (!array_key_exists('Icons', $grid)) { + return ''; + } - $key = ''; - $status_fields = $this->Application->getUnitOption($this->Prefix,'StatusField'); - if(!$status_fields) return $icons['default']; + $icons = $grid['Icons']; - foreach($status_fields as $status_field) - { - $key .= $object->GetDBField($status_field).'_'; + if (array_key_exists('name', $params)) { + $icon_name = $params['name']; + return array_key_exists($icon_name, $icons) ? $icons[$icon_name] : ''; } - $key = rtrim($key,'_'); - $value = ($key !== false) ? $key : 'default'; - return isset($icons[$value]) ? $icons[$value] : $icons['default']; + $status_fields = $this->Application->getUnitOption($this->Prefix, 'StatusField'); + + if (!$status_fields) { + return $icons['default']; + } + + $object =& $this->getObject($params); + /* @var $object kDBList */ + + $icon = ''; + + foreach ($status_fields as $status_field) { + $icon .= $object->GetDBField($status_field) . '_'; + } + + $icon = rtrim($icon, '_'); + + return array_key_exists($icon, $icons) ? $icons[$icon] : $icons['default']; } /** @@ -1561,7 +1576,8 @@ { $preset_name = replaceModuleSection($params['title_preset']); $title_presets = $this->Application->getUnitOption($this->Prefix,'TitlePresets'); - $title_info = getArrayValue($title_presets, $preset_name); + $title_info = array_key_exists($preset_name, $title_presets) ? $title_presets[$preset_name] : false; + if ($title_info === false) { $title = str_replace('#preset_name#', $preset_name, $params['title']); if ($this->Application->ConfigValue('UseSmallHeader') && isset($params['group_title']) && $params['group_title']) { @@ -1570,7 +1586,7 @@ return $title; } - if (getArrayValue($title_presets,'default')) { + if (array_key_exists('default', $title_presets) && $title_presets['default']) { // use default labels + custom labels specified in preset used $title_info = array_merge_recursive2($title_presets['default'], $title_info); } @@ -1582,8 +1598,9 @@ $object_status = Array(); $status_labels = Array(); - $prefixes = getArrayValue($title_info,'prefixes'); - $all_tag_params = getArrayValue($title_info,'tag_params'); + $prefixes = array_key_exists('prefixes', $title_info) ? $title_info['prefixes'] : false; + $all_tag_params = array_key_exists('tag_params', $title_info) ? $title_info['tag_params'] : false; + if ($prefixes) { // extract tag_perams passed directly to SectionTitle tag for specific prefix foreach ($params as $tp_name => $tp_value) { @@ -1600,7 +1617,9 @@ if ($all_tag_params) { $tag_params = getArrayValue($all_tag_params, $prefix_data['prefix_special']); - if (!$tag_params) $tag_params = Array(); + if (!$tag_params) { + $tag_params = Array(); + } } $tag_params = array_merge_recursive2($params, $tag_params); @@ -1654,7 +1673,8 @@ $title .= ' - '.$params['group_title']; } - $cut_first = getArrayValue($params, 'cut_first'); + $cut_first = array_key_exists('cut_first', $params) && $params['cut_first']; + if ($cut_first && mb_strlen($title) > $cut_first) { if (!preg_match('/(.*)<\/a>/',$title)) { $title = mb_substr($title, 0, $cut_first).' ...'; @@ -1824,8 +1844,8 @@ */ function SaveWarning($params) { - $main_prefix = getArrayValue($params, 'main_prefix'); - if ($main_prefix && $main_prefix != '$main_prefix') { + $main_prefix = array_key_exists('main_prefix', $params) ? $params['main_prefix'] : false; + if ($main_prefix) { $top_prefix = $main_prefix; } else { @@ -1897,35 +1917,55 @@ $ret = $ret[ $params['type'] ]; } - if( !$this->HasParam($params, 'no_special') ) $ret = htmlspecialchars($ret); + if (!array_key_exists('no_special', $params) || !$params['no_special']) { + $ret = htmlspecialchars($ret); + } + return $ret; } return ''; } + /** + * Tells, that at least one of search filters is used by now + * + * @param Array $params + * @return bool + */ + function SearchActive($params) + { + if ($this->Application->RecallVar($this->getPrefixSpecial() . '_search_keyword')) { + // simple search filter is used + return true; + } + + $view_name = $this->Application->RecallVar($this->getPrefixSpecial().'_current_view'); + $custom_filter = $this->Application->RecallPersistentVar($this->getPrefixSpecial().'_custom_filter.'.$view_name/*, ALLOW_DEFAULT_SETTINGS*/); + $custom_filter = $custom_filter ? unserialize($custom_filter) : Array(); + + return array_key_exists($params['grid'], $custom_filter); + } + function SearchFormat($params) { $field = $params['field']; $object =& $this->GetList($params); $options = $object->GetFieldOptions($field); - $format = $options[ $this->SelectParam($params, 'input_format') ? 'input_format' : 'format' ]; + $formatter_class = array_key_exists('formatter', $options) ? $options['formatter'] : false; - $formatter_class = getArrayValue($options,'formatter'); - if($formatter_class) - { + if ($formatter_class) { $formatter =& $this->Application->recallObject($formatter_class); - $human_format = getArrayValue($params,'human'); - $edit_size = getArrayValue($params,'edit_size'); - $sample = getArrayValue($params,'sample'); - if($sample) - { + $human_format = array_key_exists('human', $params) ? $params['human'] : false; + $edit_size = array_key_exists('edit_size', $params) ? $params['edit_size'] : false; + $sample = array_key_exists('sample', $params) ? $params['sample'] : false; + + if ($sample) { return $formatter->GetSample($field, $options, $object); } - elseif($human_format || $edit_size) - { + elseif ($human_format || $edit_size) { $format = $formatter->HumanFormat($format); return $edit_size ? strlen($format) : $format; } @@ -1958,38 +1998,6 @@ } /** - * Returns templates path for module, which is gathered from prefix module - * - * @param Array $params - * @return string - * @author Alex - */ - function ModulePath($params) - { - $force_module = getArrayValue($params, 'module'); - if ($force_module) { - if ($force_module == '#session#') { - $force_module = preg_replace('/([^:]*):.*/', '\1', $this->Application->RecallVar('module')); - if (!$force_module) $force_module = 'core'; - } - else { - $force_module = mb_strtolower($force_module); - } - - if ($force_module == 'core') { - $module_folder = 'core'; - } - else { - $module_folder = trim( $this->Application->findModule('Name', $force_module, 'Path'), '/'); - } - } - else { - $module_folder = $this->Application->getUnitOption($this->Prefix, 'ModuleFolder'); - } - return '../../'.$module_folder.'/admin_templates/'; - } - - /** * Returns object used in tag processor * * @access public @@ -2043,7 +2051,7 @@ return false; } - function MultipleEditing($params) + /*function MultipleEditing($params) { $wid = $this->Application->GetTopmostWid($this->Prefix); $session_name = rtrim($this->getPrefixSpecial().'_selected_ids_'.$wid, '_'); @@ -2061,7 +2069,7 @@ } return $ret; - } + }*/ /** * Returns import/export process percent @@ -2108,8 +2116,7 @@ { $ret = EXPORT_PATH.'/'; - if( getArrayValue($params, 'as_url') ) - { + if (array_key_exists('as_url', $params) && $params['as_url']) { $ret = str_replace( FULL_PATH.'/', $this->Application->BaseURL(), $ret); } @@ -2187,10 +2194,10 @@ // editing content block from Front-End, not category in admin $sql = 'SELECT NamedParentPath FROM ' . $this->Application->getUnitOption('c', 'TableName') . ' - WHERE ' . $this->Application->getUnitOption('c', 'IDField') . ' = ' . $page_id; + WHERE ' . $this->Application->getUnitOption('c', 'IDField') . ' = ' . (int)$page_id; $template = strtolower( $this->Conn->GetOne($sql) ); - $url_params = Array ('m_cat_id' => $page_id, 'no_amp' => 1, 'editing_mode' => EDITING_MODE_CMS, 'pass' => 'm'); + $url_params = Array ('m_cat_id' => $page_id, 'no_amp' => 1, 'editing_mode' => EDITING_MODE_CONTENT, 'pass' => 'm'); $preview_url = $this->Application->HREF($template, '_FRONT_END_', $url_params, 'index.php'); $preview_url = preg_replace('/&(admin|editing_mode)=[\d]/', '', $preview_url); } @@ -2538,6 +2545,4 @@ return false; } -} - -?> \ No newline at end of file +} \ No newline at end of file