Index: branches/RC/core/units/admin/admin_config.php =================================================================== diff -u -N -r10912 -r11067 --- branches/RC/core/units/admin/admin_config.php (.../admin_config.php) (revision 10912) +++ branches/RC/core/units/admin/admin_config.php (.../admin_config.php) (revision 11067) @@ -61,6 +61,10 @@ ), ), + 'ListSQLs' => Array ( + '' => '', // to prevent warning + ), + 'Fields' => Array (), // we need empty array because kernel doesn't use virtual fields else 'VirtualFields' => Array ( 'ImportFile' => Array ( @@ -75,5 +79,7 @@ 'multiple' => false, 'direct_links' => false, 'default' => null, ), + + 'Content' => Array ('type' => 'string', 'default' => ''), ), ); Index: branches/RC/core/kernel/nparser/ntags.php =================================================================== diff -u -N -r10740 -r11067 --- branches/RC/core/kernel/nparser/ntags.php (.../ntags.php) (revision 10740) +++ branches/RC/core/kernel/nparser/ntags.php (.../ntags.php) (revision 11067) @@ -159,6 +159,7 @@ $o = parent::Open($tag); $f_name = $tag['NP']['name'].'_'.abs(crc32($tag['file'])).'_'.$tag['line']; + $this->Tag['function_name'] = $f_name; // for later use in closing tag $code[] = "\$_parser->Elements['{$tag['NP']['name']}'] = '$f_name';"; @@ -168,6 +169,7 @@ $code[] = "function $f_name(&\$_parser, \$params) {"; $code[] = "global \$application;"; + $tag['NP'] = $this->_extractParams($tag['NP']); $defaults = $this->Parser->CompileParamsArray($tag['NP']); $code[] = "\$params = array_merge($defaults, \$params);"; @@ -179,13 +181,32 @@ return $o; } + /** + * Converts $param_name to $params['param_name'] + * + * @param Array $params + * @return Array + */ + function _extractParams($params) + { + foreach ($params as $param_name => $param_value) { + $params[$param_name] = preg_replace('/[\{]{0,1}([\$])(.*?[^\$\s\{\}]*)[\}]{0,1}/', '{$params[\'\\2\']}', $param_value); + } + + return $params; + } + function Close($tag) { $o = $this->Parser->Buffers[$this->Parser->Level]; $code[] = '$_output = ob_get_contents();'; $code[] = 'ob_end_clean();'; $code[] = 'return $_output;'; $code[] = '}}'; + + $end_pos = $this->Tag['pos'] + $tag['pos'] + strlen($tag['opening']) + strlen($tag['tag']) + strlen($tag['closing']) + TAG_NAMESPACE_LENGTH; + $code[] = "\$_parser->ElementLocations['{$this->Tag['function_name']}'] = Array('file' => '{$this->Tag['file']}', 'start_pos' => {$this->Tag['pos']}, 'end_pos' => {$end_pos});"; + $this->AppendCode($o, $code); return $o; } @@ -260,13 +281,14 @@ $this->Single = false; $this->OriginalTag = $tag; $tag['NP']['name'] = '__lambda'; + return parent::Open($tag); } function RenderDesignCode(&$o, $params) { $to_pass = $this->Parser->CompileParamsArray($params); - $code[] = "echo (\$_parser->ParseBlock(array_merge($to_pass, array('name'=>'{$params['design']}','content'=>\$_parser->ParseBlock($to_pass), 'keep_data_exists'=>1))));"; + $code[] = "echo (\$_parser->ParseBlock(array_merge($to_pass, array('name'=>\"{$params['design']}\",'content'=>\$_parser->ParseBlock($to_pass), 'keep_data_exists'=>1))));"; $this->AppendCode($o, $code); } @@ -277,6 +299,7 @@ } $o = parent::Close($tag); $this->OriginalTag['NP']['name'] = '__lambda'; + $this->RenderDesignCode($o, $this->OriginalTag['NP']); return $o; } Index: branches/RC/core/admin_templates/popups/translator.tpl =================================================================== diff -u -N -r9716 -r11067 --- branches/RC/core/admin_templates/popups/translator.tpl (.../translator.tpl) (revision 9716) +++ branches/RC/core/admin_templates/popups/translator.tpl (.../translator.tpl) (revision 11067) @@ -1,49 +1,6 @@ - - - -In-Portal :: Administration Panel + -"> - - - - - - - - - - - - - - - - - - - - - - - - - - Index: branches/RC/core/kernel/nparser/nparser.php =================================================================== diff -u -N -r10669 -r11067 --- branches/RC/core/kernel/nparser/nparser.php (.../nparser.php) (revision 10669) +++ branches/RC/core/kernel/nparser/nparser.php (.../nparser.php) (revision 11067) @@ -2,6 +2,9 @@ include_once(KERNEL_PATH.'/nparser/ntags.php'); +define('TAG_NAMESPACE', 'inp2:'); +define('TAG_NAMESPACE_LENGTH', 5); + class NParser extends kBase { var $Stack = array(); @@ -13,31 +16,40 @@ var $Params = array(); var $ParamsStack = array(); var $ParamsLevel = 0; - + var $Definitions = ''; var $Elements = array(); // holds dynamic elements to function names mapping during execution + + /** + * Holds location of element definitions inside templates. + * key - element function name, value - array of 2 keys: {from_pos, to_pos} + * + * @var Array + */ + var $ElementLocations = Array (); + var $DataExists = false; - + var $TemplateName = null; var $TempalteFullPath = null; - + var $CachePointers = array(); var $Cachable = array(); - - + + function NParser() { parent::kBase(); } - function Compile($pre_parsed) + function Compile($pre_parsed, $template_name = 'unknown') { $data = file_get_contents($pre_parsed['tname']); - $this->CompileRaw($data, $pre_parsed['tname']); + $this->CompileRaw($data, $pre_parsed['tname'], $template_name); // saving compiled version $compiled = fopen($pre_parsed['fname'], 'w'); @@ -58,19 +70,20 @@ return ob_get_clean(); } - function CompileRaw($data, $t_name) + function CompileRaw($data, $t_name, $template_name = 'unknown') { $code = "extract (\$_parser->Params);\n"; - + $code .= "\$_parser->ElementLocations['{$template_name}'] = Array('file' => '{$t_name}', 'start_pos' => 0, 'end_pos' => " . strlen($data) . ");\n"; + // $code .= "__@@__DefinitionsMarker__@@__\n"; - + // $code .= "if (!\$this->CacheStart('".abs(crc32($t_name))."_0')) {\n"; $this->Buffers[0] = '\n"; $this->Cacheable[0] = true; $this->Definitions = ''; // finding all the tags - $reg = '(.*?)(<[\\/]?)inp2:([^>]*?)([\\/]?>)(\r\n){0,1}'; + $reg = '(.*?)(<[\\/]?)' . TAG_NAMESPACE . '([^>]*?)([\\/]?>)(\r\n){0,1}'; preg_match_all('/'.$reg.'/s', $data, $results, PREG_SET_ORDER + PREG_OFFSET_CAPTURE); $this->InsideComment = false; @@ -80,6 +93,7 @@ 'tag' => $tag_data[3][0], 'closing' => $tag_data[4][0], 'line' => substr_count(substr($data, 0, $tag_data[2][1]), "\n")+1, + 'pos' => $tag_data[2][1], 'file' => $t_name, ); @@ -187,6 +201,7 @@ opened at line '.$opening_tag['line'].')', $tag['file'], $tag['line']); return false; } + $o .= $this->Stack[$this->Level]->Close($tag); // DO NOT use $this->Level-- here because it's used inside Close $this->Level--; } @@ -213,12 +228,12 @@ $this->Buffers[$this->Level] .= $o; return true; } - + function GetPointer($tag) { return abs(crc32($tag['file'])).'_'.$tag['line']; } - + function BreakCache($code, $pointer, $condition='') { return "\$_parser->CacheEnd();\n}\n" . $code."\nif ( !\$_parser->CacheStart('{$pointer}'" . ($condition ? ", {$condition}" : '') . ") ) {\n"; @@ -280,7 +295,7 @@ } if (!$pre_parsed || !$pre_parsed['active'] || defined('DBG_NPARSER_FORCE_COMPILE') && DBG_NPARSER_FORCE_COMPILE) { $inc_parser = new NParser(); - if (!$inc_parser->Compile($pre_parsed)) return false; + if (!$inc_parser->Compile($pre_parsed, $t)) return false; } return $pre_parsed; } @@ -307,7 +322,7 @@ $this->TemplateName = $backup_template; $this->TempalteFullPath = $backup_fullpath; - + return $output; } @@ -373,9 +388,9 @@ unset($params['default_element']); return $this->ParseBlock($params, $pass_params); } - + $original_params = $params; - + if ($pass_params || isset($params['pass_params'])) $params = array_merge($this->Params, $params); $this->PushParams($params); $data_exists_bak = $this->DataExists; @@ -390,7 +405,14 @@ if (!array_key_exists($params['name'], $this->Elements)) { $pre_parsed = $this->Application->TemplatesCache->GetPreParsed($params['name']); if ($pre_parsed) { - return $this->IncludeTemplate($params); + $ret = $this->IncludeTemplate($params); + + if (array_key_exists('no_editing', $params) && $params['no_editing']) { + // when individual render element don't want to be edited + return $ret; + } + + return defined('DBG_DECORATE_BLOCKS') && DBG_DECORATE_BLOCKS ? $this->DecorateBlock($ret, $params, true) : $ret; } if ($this->Application->isDebugMode()) { @@ -411,32 +433,61 @@ $this->CheckNoData($ret, $params); $this->DataExists = $data_exists_bak || $this->DataExists; - + if (isset($original_params['cache_timeout'])) { $this->CacheSet($this->FormCacheKey('element_'.$original_params['name']), $ret, $original_params['cache_timeout']); } - + + if (array_key_exists('no_editing', $params) && $params['no_editing']) { + // when individual render element don't want to be edited + return $ret; + } + return defined('DBG_DECORATE_BLOCKS') && DBG_DECORATE_BLOCKS ? $this->DecorateBlock($ret, $params) : $ret; } - - function DecorateBlock($block_content, $block_params) + + function DecorateBlock($block_content, $block_params, $is_template = false) { - if (preg_match('/^(\s*)(.*)<\/td>(.*)$/is', $block_content, $regs)) { - // block with td -> put div inside td - return $regs[1].'
'.$regs[3].'
'.$regs[4]; + static $used_ids = Array (); + + $block_name = $block_params['name']; + $function_name = $is_template ? $block_name : $this->Elements[$block_name]; + $element_location = $this->ElementLocations[$function_name]; + + // ensure unique id for every div (used from print lists) + $container_num = 1; + $container_id = 'parser_block[' . $function_name . ']'; + while (in_array($container_id . '_' . $container_num, $used_ids)) { + $container_num++; } - return '
'.$block_content.'
'; + $container_id .= '_' . $container_num; + $used_ids[] = $container_id; + + // prepare parameter string + $param_string = "$block_name:$function_name:{$element_location['file']}:{$element_location['start_pos']}:{$element_location['end_pos']}"; + $block_editor = '
+ edit
+ %s +
'; + + // 1 - text before, 2 - open tag, 3 - open tag attributes, 4 - content inside tag, 5 - closing tag, 6 - text after closing tag + if (preg_match('/^(\s*)<(td|span)(.*?)>(.*)<\/(td|span)>(.*)$/is', $block_content, $regs)) { + // div inside span -> put div outside span + return $regs[1] . '<' . $regs[2] . ' ' . $regs[3] . '>' . str_replace('%s', $regs[4], $block_editor) . '' . $regs[6]; + } + + return str_replace('%s', $block_content, $block_editor); } function IncludeTemplate($params, $silent=null) { $t = is_array($params) ? $this->SelectParam($params, 't,template,block,name') : $params; - + if (isset($params['cache_timeout']) && ($ret = $this->CacheGet('template:'.$t))) { return $ret; } - + $t = eregi_replace("\.tpl$", '', $t); $data_exists_bak = $this->DataExists; $this->DataExists = false; @@ -451,11 +502,11 @@ $this->CheckNoData($ret, $params); $this->DataExists = $data_exists_bak || $this->DataExists; - + if (isset($params['cache_timeout'])) { $this->CacheSet('template:'.$t, $ret, $params['cache_timeout']); } - + return $ret; } @@ -471,27 +522,27 @@ } } } - + function CacheGet($name) { if (!$this->Application->ConfigValue('SystemTagCache')) return false; return $this->Application->CacheGet($name); } - + function CacheSet($name, $value, $expiration=0) { if (!$this->Application->ConfigValue('SystemTagCache')) return false; return $this->Application->CacheSet($name, $value, $expiration); } - + function FormCacheKey($element, $file=null, $add_prefixes=null) { if (!isset($file)) { $file = str_replace(FULL_PATH, '', $this->TempalteFullPath).':'.$this->Application->GetVar('t'); } $parts = array( 'file_'.$file.'('.filemtime($this->TempalteFullPath).')' => 'serials:file_ts', // theme + template timestamp - 'm_lang_'.$this->Application->GetVar('m_lang') => 'serials:lang_ts', + 'm_lang_'.$this->Application->GetVar('m_lang') => 'serials:lang_ts', 'm_cat_id_'.$this->Application->GetVar('m_cat_id') => 'serials:cat_'.$this->Application->GetVar('m_cat_id').'_ts', 'm_cat_page'.$this->Application->GetVar('m_cat_page') => false, ); @@ -512,21 +563,21 @@ } } $key .= $element; - + return crc32($key); } - + function PushPointer($pointer) { $this->CachePointers[++$this->CacheLevel] = $this->FormCacheKey('pointer:'.$pointer); return $this->CachePointers[$this->CacheLevel]; } - + function PopPointer() { return $this->CachePointers[$this->CacheLevel--]; } - + function CacheStart($pointer=null) { if ($ret = $this->CacheGet($this->PushPointer($pointer)) ) { @@ -537,7 +588,7 @@ ob_start(); return false; } - + function CacheEnd($elem=null) { $ret = ob_get_clean(); Index: branches/RC/core/kernel/db/db_tag_processor.php =================================================================== diff -u -N -r10975 -r11067 --- branches/RC/core/kernel/db/db_tag_processor.php (.../db_tag_processor.php) (revision 10975) +++ branches/RC/core/kernel/db/db_tag_processor.php (.../db_tag_processor.php) (revision 11067) @@ -2039,51 +2039,64 @@ if (file_exists(FULL_PATH.EDITOR_PATH.'/editor/lang/'.$lang_file)) { return $lang_prefix; - } + } $aLangPrefix = explode("-",$lang_prefix); if (file_exists(FULL_PATH.EDITOR_PATH.'/editor/lang/'.$aLangPrefix[0].'.js')) { return $aLangPrefix[0]; - } + } return 'en'; } - - - function FCKEditor($params) { + + + function FCKEditor($params) + { $params['no_special'] = 1; $value = $this->Field($params); - $name = isset($params['name']) ? $params['name'] : $this->InputName($params); + $name = array_key_exists('name', $params) ? $params['name'] : $this->InputName($params); - $theme_path = substr($this->Application->GetFrontThemePath(), 1).'/inc/'; - if (!file_exists(FULL_PATH.'/'.$theme_path.'style.css')) { + $theme_path = substr($this->Application->GetFrontThemePath(), 1) . '/inc/'; + if (!file_exists(FULL_PATH . '/' . $theme_path . 'style.css')) { $theme_path = EDITOR_PATH; } - $styles_xml = $this->Application->BaseURL().$theme_path.'styles.xml'; - $styles_css = $this->Application->BaseURL().$theme_path.'style.css'; - $bgcolor = isset($params['bgcolor']) ? $params['bgcolor'] : $this->Application->GetVar('bgcolor'); - if (!$bgcolor) $bgcolor = '#ffffff'; + $styles_xml = $this->Application->BaseURL() . $theme_path . 'styles.xml'; + $styles_css = $this->Application->BaseURL() . $theme_path . 'style.css'; + + $bgcolor = array_key_exists('bgcolor', $params) ? $params['bgcolor'] : $this->Application->GetVar('bgcolor'); + if (!$bgcolor) { + $bgcolor = '#ffffff'; + } + + $url = ''; $st_id = $this->Application->GetVar('st_id'); if ($st_id) { - $tpl = $this->Conn->GetRow('SELECT NamedParentPath, CategoryId FROM '.TABLE_PREFIX.'Category WHERE CategoryId = '.$st_id); - $url = $this->Application->HREF($tpl['NamedParentPath'], '_FRONT_END_', array('pass'=>'m', 'm_cat_id' => $st_id, 'index_file' => 'index.php')); + $sql = 'SELECT NamedParentPath + FROM ' . $this->Application->getUnitOption('st', 'TableName') . ' + WHERE ' . $this->Application->getUnitOption('st', 'IDField') . ' = ' . $st_id; + $tpl = $this->Conn->GetOne($sql); + + $url_params = Array ('pass' => 'm', 'm_cat_id' => $st_id, 'index_file' => 'index.php'); + $url = $this->Application->HREF($tpl, '_FRONT_END_', $url_params); } - include_once(FULL_PATH.EDITOR_PATH.'fckeditor.php'); + + include_once(FULL_PATH . EDITOR_PATH . 'fckeditor.php'); + $oFCKeditor = new FCKeditor($name); $oFCKeditor->FullUrl = $this->Application->BaseURL(); - $oFCKeditor->BaseUrl = BASE_PATH.'/'; - $oFCKeditor->BasePath = BASE_PATH.EDITOR_PATH; + $oFCKeditor->BaseUrl = BASE_PATH . '/'; + $oFCKeditor->BasePath = BASE_PATH . EDITOR_PATH; $oFCKeditor->Width = $params['width'] ; $oFCKeditor->Height = $params['height'] ; - $oFCKeditor->ToolbarSet = $st_id ? 'Advanced' : 'Default' ; + $oFCKeditor->ToolbarSet = $st_id ? 'Advanced' : 'Default'; $oFCKeditor->Value = $value; $oFCKeditor->PreviewUrl = $url; $oFCKeditor->DefaultLanguage = $this->SetFCKDefaultLanguage(); - $oFCKeditor->LateLoad = isset($params['late_load']) && $params['late_load']; - $oFCKeditor->Config = Array( + $oFCKeditor->LateLoad = array_key_exists('late_load', $params) && $params['late_load']; + $oFCKeditor->Config = Array ( //'UserFilesPath' => $pathtoroot.'kernel/user_files', - 'ProjectPath' => BASE_PATH.'/', - 'CustomConfigurationsPath' => $this->Application->BaseURL().'core/admin_templates/js/inp_fckconfig.js', + 'ProjectPath' => BASE_PATH . '/', + 'CustomConfigurationsPath' => $this->Application->BaseURL() . 'core/admin_templates/js/inp_fckconfig.js', 'StylesXmlPath' => $styles_xml, 'EditorAreaCSS' => $styles_css, 'DefaultStyleLabel' => $this->Application->Phrase('la_editor_default_style'), @@ -2092,9 +2105,10 @@ 'K4' => 1, 'newBgColor' => $bgcolor, 'PreviewUrl' => $url, - 'BaseUrl' => BASE_PATH.'/', + 'BaseUrl' => BASE_PATH . '/', 'DefaultLanguage' => $this->SetFCKDefaultLanguage(), ); + return $oFCKeditor->CreateHtml(); }