Index: branches/5.1.x/core/units/general/custom_fields.php =================================================================== diff -u -N --- branches/5.1.x/core/units/general/custom_fields.php (revision 12127) +++ branches/5.1.x/core/units/general/custom_fields.php (revision 0) @@ -1,157 +0,0 @@ -ParseConfigSQL($values_list, $separator, $parse), $separator); - - if (!$values_list) { - // no options, then return empty array - return Array(); - } - - $optionValuesTmp = explode($separator, $values_list); - $optionValues = Array(); - - if (substr_count($values_list, '=') != count($optionValuesTmp)) { - if ($this->Application->isDebugMode()) { - $this->Application->Debugger->appendTrace(); - } - - trigger_error('Invalid symbol in ValueList field [' . substr($values_list, 0, 100) . ' ...]' , E_USER_NOTICE); - return Array (); - } - - if ($parse) { - // normal way - foreach ($optionValuesTmp as $optionValue) { - list ($key, $val) = explode('=', $optionValue); - - $val = substr($val, 0, 1) == '+' ? substr($val, 1) : $this->Application->Phrase($val); - - $optionValues[$key] = $val; - } - } - else { - // during custom field editing - foreach ($optionValuesTmp as $optionValue) { - list ($key, $val) = explode('=', $optionValue); - - if (substr($key, 0, 3) == 'SQL') { - $val = base64_decode( str_replace('_', '=', substr($val, 1)) ); - } - - $optionValues[$key] = $val; - } - } - - return $optionValues; - } - - /** - * Replace SQL's in valueList with appropriate queried values - * - * @param string $valueString - * @param string $separator - * @return string - * @todo Apply refactoring to embedded vars stuff - */ - function ParseConfigSQL($valueString, $separator = VALUE_LIST_SEPARATOR, $parse_sqls = true) - { - $string = trim( str_replace(Array('', '%3$s'), Array (TABLE_PREFIX, $this->Application->GetVar('m_lang')), $valueString) ); - - preg_match_all("|\{(.*)\}|U", $string, $embedded_vars, PREG_SET_ORDER); - - /* - in ValueList now can use globally available variables. - Usage: {$_POST['variable']|what to output if $_POST['variable'] is set} - e.g. $_POST['variable']='Hello' - Will output: what to output if Hello is set - */ - - if ($embedded_vars) { - for ($i = 0; $i < count($embedded_vars); $i++) { - $embedded_var = $embedded_vars[$i][1]; - $embedded_var_src = $embedded_vars[$i][0]; - - list($var_name, $pattern) = explode('|', $embedded_var); - eval('$var_value = (isset('.$var_name.')?'.$var_name.':false);'); - - if ($var_value !== false) { - $pattern = str_replace($var_name, $var_value, $pattern); - $string = str_replace($embedded_var_src, $pattern, $string); - } - else { - $string = str_replace($embedded_var_src, '', $string); - } - } - } - - if (preg_match_all('/(.*?)<\/SQL>/', $string, $regs)) { - $i = 0; - $sql_count = count($regs[0]); - while ($i < $sql_count) { - if ($parse_sqls) { - $replacement = $this->_queryConfigSQL($regs[2][$i], $regs[1][$i], $separator); - } - else { - $sql = base64_encode(''.$regs[2][$i].''); - $replacement = 'SQL' . $i . '=+' . str_replace('=', '_', $sql); - } - - $string = str_replace(''.$regs[2][$i].'', $replacement, $string); - $i++; - } - - $string = preg_replace('/[' . preg_quote($separator, '/') . ']+/', $separator, $string); // trim trailing separators inside string - } - - return $string; - } - - /** - * Transforms given sql into value list string - * - * @param string $sql - * @param string $plus - * @param string $separator - * @return string - */ - function _queryConfigSQL($sql, $plus = '', $separator = VALUE_LIST_SEPARATOR) - { - $values = $this->Conn->Query($sql); - foreach ($values as $index => $value) { - $values[$index] = $value['OptionValue'] . '=' . $plus . $value['OptionName']; - } - - return implode($separator, $values); - } -} - -?> \ No newline at end of file