Page MenuHomeIn-Portal Phabricator

in-portal
No OneTemporary

File Metadata

Created
Sat, Jun 21, 1:57 AM

in-portal

Index: branches/unlabeled/unlabeled-1.6.2/kernel/units/languages/languages_item.php
===================================================================
--- branches/unlabeled/unlabeled-1.6.2/kernel/units/languages/languages_item.php (nonexistent)
+++ branches/unlabeled/unlabeled-1.6.2/kernel/units/languages/languages_item.php (revision 6449)
@@ -0,0 +1,64 @@
+<?php
+
+ class LanguagesItem extends kDBItem
+ {
+ function generateID()
+ {
+ $sql = 'SELECT MAX('.$this->IDField.') FROM '.$this->Application->GetLiveName($this->TableName);
+ return $this->Conn->GetOne($sql) + 1;
+ }
+
+ function setPrimary($reset_primary = true)
+ {
+ if ($reset_primary) {
+ $sql = 'UPDATE '.$this->TableName.'
+ SET PrimaryLang = 0';
+ $this->Conn->Query($sql);
+ }
+
+ $sql = 'UPDATE '.$this->TableName.'
+ SET PrimaryLang = 1, Enabled = 1
+ WHERE '.$this->IDField.' = '.$this->GetID();
+ $this->Conn->Query($sql);
+ }
+
+ /**
+ * Allows to format number according to regional settings
+ *
+ * @param float $number
+ * @param int $precision
+ * @return float
+ */
+ function formatNumber($number, $precision = null)
+ {
+ return number_format($number, $precision, $this->GetDBField('DecimalPoint'), $this->GetDBField('ThousandSep'));
+ }
+
+ function Load($id, $id_field_name=null)
+ {
+ $default = false;
+ if ($id == 'default') {
+ $id = 1;
+ $id_field_name = 'PrimaryLang';
+ $default = true;
+ }
+
+ $res = parent::Load($id, $id_field_name);
+
+ if ($default) {
+ if (!$res) {
+ if ($this->Application->IsAdmin()) {
+ $res = parent::Load(1);
+ }
+ else {
+ $this->Application->ApplicationDie('No Primary Language Selected');
+ }
+ }
+ $this->Application->SetVar('lang.current_id', $this->GetID() );
+ $this->Application->SetVar('m_lang', $this->GetID() );
+ }
+ return $res;
+ }
+ }
+
+?>
\ No newline at end of file
Property changes on: branches/unlabeled/unlabeled-1.6.2/kernel/units/languages/languages_item.php
___________________________________________________________________
Added: cvs2svn:cvs-rev
## -0,0 +1 ##
+1.6
\ No newline at end of property
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property
Index: branches/unlabeled/unlabeled-1.6.2/kernel/units/general/helpers/mod_rewrite_helper.php
===================================================================
--- branches/unlabeled/unlabeled-1.6.2/kernel/units/general/helpers/mod_rewrite_helper.php (nonexistent)
+++ branches/unlabeled/unlabeled-1.6.2/kernel/units/general/helpers/mod_rewrite_helper.php (revision 6449)
@@ -0,0 +1,485 @@
+<?php
+
+ class kModRewriteHelper extends kHelper {
+
+ function kModRewriteHelper()
+ {
+ parent::kHelper();
+ $this->HTTPQuery =& $this->Application->recallObject('HTTPQuery');
+ }
+
+ function SetDefaultValues(&$vars)
+ {
+ $defaults = Array('m_cat_id' => 0, 'm_cat_page' => 1, 'm_opener' => 's');
+ foreach ($defaults as $default_key => $default_value)
+ {
+ if ($this->HTTPQuery->Get($default_key) == null) {
+ $vars[$default_key] = $default_value;
+ }
+ }
+ }
+
+ function ProcessLanguage(&$url_parts, &$vars)
+ {
+ if (!isset($url_parts[0])) return false;
+ $res = false;
+ $url_part = array_shift($url_parts);
+
+ $sql = 'SELECT LanguageId FROM '.TABLE_PREFIX.'Language WHERE LOWER(PackName) = '.$this->Conn->qstr($url_part).' AND Enabled = 1';
+ $language_id = $this->Conn->GetOne($sql);
+ $this->Application->Phrases = new PhrasesCache();
+ if($language_id)
+ {
+ $vars['m_lang'] = $language_id;
+ $res = true;
+ }
+
+// $this->Application->VerifyLanguageId();
+ if (!$res) {
+ array_unshift($url_parts, $url_part);
+ }
+ return $res;
+ }
+
+ function ProcessTheme(&$url_parts, &$vars)
+ {
+ if (!isset($url_parts[0])) return false;
+ $res = false;
+ $url_part = array_shift($url_parts);
+
+ $sql = 'SELECT ThemeId FROM '.TABLE_PREFIX.'Theme WHERE LOWER(Name) = '.$this->Conn->qstr($url_part).' AND Enabled = 1';
+ $theme_id = $this->Conn->GetOne($sql);
+ if($theme_id)
+ {
+ $vars['m_theme'] = $theme_id;
+ $res = true;
+ }
+// $this->Application->VerifyThemeId(); // verify anyway - will set default if not found!!!
+ if (!$res) {
+ array_unshift($url_parts, $url_part);
+ }
+ return $res;
+ }
+
+ function ProcessCategory(&$url_parts, &$vars)
+ {
+ if (!isset($url_parts[0])) return false;
+ $res = false;
+ $url_part = array_shift($url_parts);
+
+ $category_id = 0;
+ $last_category_id = 0;
+ $category_path = '';
+ do
+ {
+ $category_path = trim($category_path.'/'.$url_part, '/');
+
+ if( preg_match('/(.*)_([\d]+)$/', $category_path, $rets) )
+ {
+ $category_path = $rets[1];
+ $vars['m_cat_page'] = $rets[2];
+ }
+
+ $category_id = $this->Conn->GetOne(
+ 'SELECT CategoryId
+ FROM '.TABLE_PREFIX.'Category
+ WHERE Status = 1 AND NamedParentPath = '.$this->Conn->qstr($category_path));
+ if ($category_id !== false) {
+ $last_category_id = $category_id;
+ $url_part = array_shift($url_parts);
+ $res = true;
+ }
+ } while ($category_id !== false && $url_part);
+ $vars['m_cat_id'] = $last_category_id;
+
+ if ($url_part) {
+ array_unshift($url_parts, $url_part);
+ }
+ return $res;
+ }
+
+ function ProcessPage(&$url_parts, &$vars)
+ {
+ if (!is_numeric($url_parts[0]) || count($url_parts) > 1) return false;
+
+ // set module pages for all modules, since we don't know which module will need it
+ foreach ($this->Application->ModuleInfo as $module_name => $module_data)
+ {
+ $vars[ $module_data['Var'].'_id'] = 0;
+ $vars[ $module_data['Var'].'_Page'] = $url_parts[0];
+ $vars[ $module_data['Var'].'_Reviews_Page'] = 0;
+ }
+ return true;
+ }
+
+ function ProcessModuleIndex(&$url_parts, &$vars)
+ {
+ if ( count($url_parts) > 1) return false; // if no more parts or only 1 part left
+ if ( $url_parts && $url_parts[0] == 'index') { // treat index same as no parts
+ array_shift($url_parts);
+ }
+
+ if( $url_parts ) { // if parts are left, it can only be module page
+ if (!is_numeric($url_parts[0])) return false;
+ $this->ProcessPage($url_parts, $vars);
+ }
+
+ // try to find CMS index page of the category
+ if ($this->Application->isModuleEnabled('In-CMS')) {
+ $sql = 'SELECT p.Path, ci.CategoryId FROM '.TABLE_PREFIX.'Pages AS p
+ LEFT JOIN '.TABLE_PREFIX.'CategoryItems AS ci
+ ON ci.ItemResourceId = p.ResourceId
+ WHERE
+ p.IsIndex = 1
+ AND
+ p.Status = 1
+ AND
+ CategoryId = '.$vars['m_cat_id'].'
+ AND
+ ci.PrimaryCat = 1';
+ $template_found = $this->Conn->GetRow($sql);
+ if ($template_found !== false) {
+ $vars['t'] = $template_found['Path'];
+ return true;
+ }
+ }
+
+ $sql = 'SELECT CachedCategoryTemplate
+ FROM '.TABLE_PREFIX.'Category
+ WHERE CategoryId = '.$vars['m_cat_id'];
+ $vars['t'] = $this->Conn->GetOne($sql);
+ if (!$vars['t']) $vars['t'] = 'index';
+ return true;
+ }
+
+ function ProcessModuleItem(&$url_parts, &$vars, $set_t=true)
+ {
+ if (preg_match('/^bb_.*/', $url_parts[0])) {
+ $cat_item = $this->Conn->GetRow('
+ SELECT c.ParentPath, c.CategoryId FROM '.TABLE_PREFIX.'Category AS c
+ WHERE
+ c.CategoryId = '.$vars['m_cat_id']);
+
+ if ($set_t) {
+ $item_template = $this->GetItemTemplate($cat_item, 'bb');
+ $vars['t'] = $item_template;
+ }
+
+ $this->Application->HandleEvent($bb_event, 'bb:ParseEnv', Array('url_parts' => $url_parts, 'vars' => $vars));
+ $vars = $bb_event->getEventParam('vars');
+ return 'bb';
+ }
+
+ if (!isset($url_parts[0])) return false;
+ if ( count($url_parts) != 1 ) return false;
+ $url_part = array_shift($url_parts);
+
+ // match module reviews page
+ $page = 1;
+ if( preg_match('/(.*)_([\d]+)$/', $url_part, $rets) )
+ {
+ $url_part = $rets[1];
+ $page = $rets[2];
+ }
+
+ // locating the item in CategoryItems by filename to detect its ItemPrefix and its category ParentPath
+ $cat_item = $this->Conn->GetRow('
+ SELECT ci.ItemResourceId, ci.ItemPrefix, c.ParentPath, ci.CategoryId FROM '.TABLE_PREFIX.'CategoryItems AS ci
+ LEFT JOIN '.TABLE_PREFIX.'Category AS c
+ ON c.CategoryId = ci.CategoryId
+ WHERE
+ ci.CategoryId = '.$vars['m_cat_id'].'
+ AND
+ ci.Filename = '.$this->Conn->qstr($url_part));
+
+ if ($cat_item !== false) { // item found
+ $module_prefix = $cat_item['ItemPrefix'];
+ $item_template = $this->GetItemTemplate($cat_item, $module_prefix);
+
+ // converting ResourceId to correpsonding Item id
+ $module_config = $this->Application->getUnitOptions($module_prefix);
+ $item_id = $this->Conn->GetOne(
+ 'SELECT '.$module_config['IDField'].' FROM '.$module_config['TableName'].'
+ WHERE ResourceId = '.$cat_item['ItemResourceId']
+ );
+
+ if ((!$set_t || $item_template) && $item_id) {
+ if ($set_t) {
+ $vars['t'] = $item_template;
+ }
+ $vars[ $module_prefix.'_id' ] = $item_id;
+ $vars[ $module_prefix.'_Reviews_Page' ] = $page;
+ return $module_prefix;
+ }
+ }
+ array_unshift($url_parts, $url_part);
+ return false;
+ }
+
+ function GetItemTemplate($category, $module_prefix)
+ {
+ if (!is_array($category)) {
+ $category = $this->Conn->GetRow('
+ SELECT c.ParentPath, c.CategoryId FROM '.TABLE_PREFIX.'Category AS c
+ WHERE
+ c.CategoryId = '.$category);
+ }
+ $parent_path = implode(',',explode('|', substr($category['ParentPath'], 1, -1)));
+
+ // item template is stored in module' system custom field - need to get that field Id
+ $item_template_field_id = $this->Conn->GetOne(
+ 'SELECT CustomFieldId
+ FROM '.TABLE_PREFIX.'CustomField
+ WHERE FieldName = '.$this->Conn->qstr($module_prefix.'_ItemTemplate'));
+
+ // looking for item template through cats hierarchy sorted by parent path
+ $query = 'SELECT ccd.l1_cust_'.$item_template_field_id.',
+ FIND_IN_SET(c.CategoryId, '.$this->Conn->qstr($parent_path).') AS Ord1,
+ c.CategoryId, c.Name, ccd.l1_cust_'.$item_template_field_id.'
+ FROM '.TABLE_PREFIX.'Category AS c
+ LEFT JOIN '.TABLE_PREFIX.'CategoryCustomData AS ccd
+ ON ccd.ResourceId = c.ResourceId
+ WHERE c.CategoryId IN ('.$parent_path.') AND ccd.l1_cust_'.$item_template_field_id.' != \'\'
+ ORDER BY FIND_IN_SET(c.CategoryId, '.$this->Conn->qstr($parent_path).') DESC';
+ $item_template = $this->Conn->GetOne($query);
+ return $item_template;
+ }
+
+ function ProcessPhisycalTemplate(&$url_parts, &$vars)
+ {
+ if (!isset($url_parts[0])) return false;
+
+ $remaining = array();
+ do
+ {
+ $template_path = implode('/', $url_parts);
+
+ $t_parts['path'] = dirname($template_path) == '.' ? '' : '/'.dirname($template_path);
+ $t_parts['file'] = basename($template_path);
+
+ $sql = 'SELECT FileId
+ FROM '.TABLE_PREFIX.'ThemeFiles
+ WHERE (FilePath = '.$this->Conn->qstr($t_parts['path']).') AND (FileName = '.$this->Conn->qstr($t_parts['file'].'.tpl').')';
+
+// $sql = 'SELECT FileId FROM '.TABLE_PREFIX.'ThemeFiles WHERE CONCAT(FilePath, "/", FileName) = '.$this->Conn->qstr('/'.$template_path.'.tpl');
+ $template_found = $this->Conn->GetOne($sql);
+ if(!$template_found)
+ {
+ array_unshift($remaining, array_pop($url_parts));
+ }
+ } while (!$template_found && $url_parts);
+
+ $url_parts = $remaining;
+
+ if ($template_found) {
+ $vars['t'] = $template_path;
+ return true;
+ }
+ return false;
+ }
+
+ /**
+ * Checks if whole url_parts matches a whole In-CMS page
+ *
+ * @param array $url_parts
+ * @return boolean
+ */
+ function ProcessVirtualTemplate(&$url_parts, &$vars)
+ {
+ if (!isset($url_parts[0]) || !$this->Application->isModuleEnabled('In-Edit')) return false;
+
+ $template_path = implode('/', $url_parts);
+ $sql = 'SELECT p.PageId, ci.CategoryId FROM '.TABLE_PREFIX.'Pages AS p
+ LEFT JOIN '.TABLE_PREFIX.'CategoryItems AS ci
+ ON ci.ItemResourceId = p.ResourceId
+ WHERE
+ Path = '.$this->Conn->qstr($template_path).'
+ AND
+ ci.PrimaryCat = 1
+ AND
+ p.Status = 1';
+ $template_found = $this->Conn->GetRow($sql);
+
+ if ($template_found) {
+ $vars['m_cat_id'] = $template_found['CategoryId'];
+ $vars['t'] = $template_path;
+ return true;
+ }
+
+ return false;
+ }
+
+ function processRewriteURL()
+ {
+ $passed = array();
+ $url = $this->HTTPQuery->Get('_mod_rw_url_');
+ if( substr($url, -5) == '.html' ) $url = substr($url, 0, strlen($url) - 5 );
+
+ $restored = false;
+ $cache = $this->Conn->GetRow('SELECT Data, Cached FROM '.TABLE_PREFIX.'Cache WHERE VarName = "mod_rw_'.md5($url).'"');
+ if (false && $cache && $cache['Cached'] > 0) {
+ $cache = unserialize($cache['Data']);
+ $vars = $cache['vars'];
+ $passed = $cache['passed'];
+ $restored = true;
+ }
+ else {
+ $passed = array();
+ $vars = $this->parseRewriteURL($url,$passed);
+ $cache = array('vars'=>$vars,'passed'=>$passed);
+ $this->Conn->Query('REPLACE '.TABLE_PREFIX.'Cache (VarName, Data, Cached) VALUES ("mod_rw_'.md5($url).'", '.$this->Conn->qstr(serialize($cache)).', '.adodb_mktime().')');
+ }
+ foreach ($vars as $name => $value)
+ {
+ $this->HTTPQuery->Set($name,$value);
+ }
+// if ($restored) {
+ $this->InitAll();
+// }
+ $this->HTTPQuery->finalizeParsing($passed);
+ }
+
+ function InitAll()
+ {
+// $this->Application->Phrases = new PhrasesCache();
+ $this->Application->VerifyLanguageId();
+ $this->Application->Phrases->Init('phrases');
+ $this->Application->VerifyThemeId();
+ }
+
+ function parseRewriteURL($url, &$passed)
+ {
+ $vars = $this->Conn->GetRow('SELECT Data, Cached FROM '.TABLE_PREFIX.'Cache WHERE VarName = "mod_rw_'.md5($url).'"');
+ if (false && $vars && $vars['Cached'] > 0) {
+ $vars = unserialize($menu['Data']);
+ return $vars;
+ }
+
+ $vars = array();
+ $url_parts = $url ? explode('/', $url) : Array();
+
+ $process_module = true;
+ if($this->HTTPQuery->Get('rewrite') == 'on' || !$url_parts)
+ {
+ $this->SetDefaultValues($vars);
+ }
+
+ if(!$url_parts)
+ {
+ $this->InitAll();
+
+ $vars['t'] = $this->HTTPQuery->getDefaultTemplate('');
+ $passed[] = 'm';
+ return $vars;
+ }
+ else
+ {
+ $vars['t'] = '';
+ }
+
+ $passed = Array('m');
+ $this->ProcessLanguage($url_parts, $vars);
+ $this->ProcessTheme($url_parts, $vars);
+
+ if ( $this->ProcessVirtualTemplate($url_parts, $vars) ) {
+ return $vars;
+ }
+
+ $this->ProcessCategory($url_parts, $vars);
+
+ if ( $this->ProcessModuleIndex($url_parts, $vars) ) {
+ foreach ($this->Application->ModuleInfo as $module_name => $info) {
+ $passed[] = $info['Var'];
+ }
+ return $vars;
+ }
+ if ( $module_prefix = $this->ProcessModuleItem($url_parts, $vars) ) {
+ $passed[] = $module_prefix;
+ return $vars;
+ }
+
+ /*// match module
+ $next_template = $this->HTTPQuery->Get('next_template');
+ if($url_part || $next_template)
+ {
+ if($next_template)
+ {
+ $next_template_parts = explode('/', $next_template);
+ $module_folder = array_shift($next_template_parts);
+ }
+ else
+ {
+ $module_folder = $url_part;
+ }
+
+ foreach ($this->Application->ModuleInfo as $module_name => $module_data)
+ {
+ if( trim($module_data['TemplatePath'], '/') == $module_folder )
+ {
+ $module_prefix = $module_data['Var'];
+ break;
+ }
+ }
+ }*/
+
+ if ( $this->ProcessPhisycalTemplate($url_parts, $vars) ) {
+ if (!$url_parts) {
+ return $vars;
+ }
+ }
+
+ if ( $this->ProcessPage($url_parts, $vars) ) {
+ return $vars;
+ }
+
+ if ( $module_prefix = $this->ProcessModuleItem($url_parts, $vars, false) ) {
+ $passed[] = $module_prefix;
+ return $vars;
+ }
+
+ if ( $this->Application->isModuleEnabled('In-Edit') && $this->Application->GetVar('admin') == 1) {
+ $adm_ses =& $this->Application->recallObject('Session.admin');
+ $user = $adm_ses->RecallVar('user_id');
+ $perm_helper =& $this->Application->recallObject('PermissionsHelper');
+ if ($perm_helper->CheckUserPermission($user, 'PAGE.ADD', 0)) {
+ $vars['t'] = implode('/', $url_parts);
+ return $vars;
+ }
+ }
+
+ $not_found = $this->Application->ConfigValue('ErrorTemplate');
+ $vars['t'] = $not_found ? $not_found : 'error_notfound';
+
+ header('HTTP/1.0 404 Not Found');
+
+ return $vars;
+
+// $this->HTTPQuery->finalizeParsing($passed, $module_params);
+
+ // pass params left to module
+
+ /*$this->Application->Phrases->Init('phrases');
+ $passed = Array('m');
+ $module_params = Array();
+ if ( isset($module_prefix) ) {
+ $passed[] = $module_prefix;
+ $module_event = new kEvent($module_prefix.':ParseEnv', Array('url_parts' => $url_parts) );
+ if ($process_module) {
+ $this->Application->HandleEvent($module_event);
+ }
+ $item_id = $this->HTTPQuery->Get($module_prefix.'_id');
+ $module_params = Array($module_prefix.'_id' => $item_id ? $item_id : '0' );
+
+ if ($module_event->status == erFAIL) {
+ $not_found = $this->Application->ConfigValue('ErrorTemplate');
+ $this->HTTPQuery->Set('t', $not_found ? $not_found : 'error_notfound' );
+ }
+ }
+
+ $this->HTTPQuery->finalizeParsing($passed, $module_params);*/
+ }
+
+
+ }
+
+?>
\ No newline at end of file
Property changes on: branches/unlabeled/unlabeled-1.6.2/kernel/units/general/helpers/mod_rewrite_helper.php
___________________________________________________________________
Added: cvs2svn:cvs-rev
## -0,0 +1 ##
+1.6
\ No newline at end of property
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property
Index: branches/unlabeled/unlabeled-1.6.2/core/units/languages/languages_item.php
===================================================================
--- branches/unlabeled/unlabeled-1.6.2/core/units/languages/languages_item.php (nonexistent)
+++ branches/unlabeled/unlabeled-1.6.2/core/units/languages/languages_item.php (revision 6449)
@@ -0,0 +1,64 @@
+<?php
+
+ class LanguagesItem extends kDBItem
+ {
+ function generateID()
+ {
+ $sql = 'SELECT MAX('.$this->IDField.') FROM '.$this->Application->GetLiveName($this->TableName);
+ return $this->Conn->GetOne($sql) + 1;
+ }
+
+ function setPrimary($reset_primary = true)
+ {
+ if ($reset_primary) {
+ $sql = 'UPDATE '.$this->TableName.'
+ SET PrimaryLang = 0';
+ $this->Conn->Query($sql);
+ }
+
+ $sql = 'UPDATE '.$this->TableName.'
+ SET PrimaryLang = 1, Enabled = 1
+ WHERE '.$this->IDField.' = '.$this->GetID();
+ $this->Conn->Query($sql);
+ }
+
+ /**
+ * Allows to format number according to regional settings
+ *
+ * @param float $number
+ * @param int $precision
+ * @return float
+ */
+ function formatNumber($number, $precision = null)
+ {
+ return number_format($number, $precision, $this->GetDBField('DecimalPoint'), $this->GetDBField('ThousandSep'));
+ }
+
+ function Load($id, $id_field_name=null)
+ {
+ $default = false;
+ if ($id == 'default') {
+ $id = 1;
+ $id_field_name = 'PrimaryLang';
+ $default = true;
+ }
+
+ $res = parent::Load($id, $id_field_name);
+
+ if ($default) {
+ if (!$res) {
+ if ($this->Application->IsAdmin()) {
+ $res = parent::Load(1);
+ }
+ else {
+ $this->Application->ApplicationDie('No Primary Language Selected');
+ }
+ }
+ $this->Application->SetVar('lang.current_id', $this->GetID() );
+ $this->Application->SetVar('m_lang', $this->GetID() );
+ }
+ return $res;
+ }
+ }
+
+?>
\ No newline at end of file
Property changes on: branches/unlabeled/unlabeled-1.6.2/core/units/languages/languages_item.php
___________________________________________________________________
Added: cvs2svn:cvs-rev
## -0,0 +1 ##
+1.6
\ No newline at end of property
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property
Index: branches/unlabeled/unlabeled-1.6.2/core/units/general/xml_helper.php
===================================================================
--- branches/unlabeled/unlabeled-1.6.2/core/units/general/xml_helper.php (nonexistent)
+++ branches/unlabeled/unlabeled-1.6.2/core/units/general/xml_helper.php (revision 6449)
@@ -0,0 +1,202 @@
+<?php
+
+class kXMLHelper extends kHelper {
+ var $RootElement = null;
+
+ /**
+ * Enter description here...
+ *
+ * @var kXMLNode
+ */
+ var $CurrentElement = null;
+
+ /**
+ * Parses XML data specified and returns root node
+ *
+ * @param string $xml
+ * @return kXMLNode
+ */
+ function &Parse($xml = null)
+ {
+ $this->Clear(); // in case if Parse method is called more then one time
+ $xml_parser = xml_parser_create();
+ xml_set_element_handler( $xml_parser, Array(&$this, 'startElement'), Array(&$this, 'endElement') );
+ xml_set_character_data_handler( $xml_parser, Array(&$this, 'characterData') );
+ if (!xml_parse($xml_parser, $xml, 1)) {
+ $this->RootElement =& new kXMLNode('ERROR', array('code'=>xml_get_error_code($xml_parser),'message'=>xml_error_string(xml_get_error_code($xml_parser))));
+ trigger_error(sprintf('XML error: %s at line %d'),
+ xml_error_string(xml_get_error_code($xml_parser)),
+ xml_get_current_line_number($xml_parser), E_USER_WARNING);
+ }
+ xml_parser_free($xml_parser);
+ return $this->RootElement;
+ }
+
+ function startElement(&$Parser, &$Elem, $Attrs)
+ {
+ $parent =& $this->CurrentElement;
+ $this->CurrentElement =& new kXMLNode($Elem, $Attrs);
+ if (is_null($this->RootElement)) {
+ $this->RootElement =& $this->CurrentElement;
+ }
+ if (!is_null($parent)) {
+ $parent->AddChild($this->CurrentElement);
+ }
+ }
+
+ function characterData($Parser, $Line)
+ {
+ $this->CurrentElement->AppendData($Line);
+ }
+
+ function endElement($Parser, $Elem)
+ {
+ if ($this->CurrentElement->Parent != null) {
+ $this->CurrentElement =& $this->CurrentElement->Parent;
+ }
+ }
+
+ function Clear()
+ {
+ $this->RootElement = null;
+ $this->CurrentElement = null;
+ }
+}
+
+class kXMLNode {
+ var $Name = null;
+ var $Attributes = array();
+ var $Children = array();
+ var $Data = null;
+
+ var $firstChild = null;
+ var $lastChild = null;
+ /**
+ * Parent node
+ *
+ * @var kXMLNode
+ */
+ var $Parent = null;
+ /**
+ * Node position relative to other nodes of it's parent
+ *
+ * @var int
+ */
+ var $Position = 0;
+
+ function kXMLNode($name, $attrs = array())
+ {
+ $this->Name = $name;
+ $this->Attributes = $attrs;
+ }
+
+ function SetParent(&$elem)
+ {
+ $this->Parent =& $elem;
+ }
+
+ /**
+ * Adds new child to current node
+ *
+ * @param kXMLNode $a_child
+ */
+ function AddChild(&$a_child)
+ {
+ $node_count = count($this->Children);
+ $a_child->Position = $node_count;
+
+ if ($node_count == 0) {
+ $this->firstChild =& $a_child;
+ $this->lastChild =& $a_child;
+ }
+ else {
+ $this->lastChild =& $a_child;
+ }
+
+ $this->Children[] =& $a_child;
+ $a_child->SetParent($this);
+ }
+
+ function AppendData($data)
+ {
+ $this->Data .= $data;
+ }
+
+ function &GetChild($path)
+ {
+ $entries = explode('/', strtoupper($path));
+ $cur = array_shift($entries);
+ if ($cur == $this->Name) $cur = array_shift($entries);
+ if (!$cur) return $this;
+ if (!isset($this->Children[$cur])) return false;
+ $left = implode('/', $entries);
+ if (!$left) return $this->Children[$cur];
+ return $this->Children[$cur]->GetChild($left);
+ }
+
+ function GetChildValue($path)
+ {
+ $child =& $this->GetChild($path);
+ if ($child !== false) {
+ return $child->Data;
+ }
+ }
+
+ function &GetChildByPosition($position)
+ {
+ if ($position < count($this->Children) ) {
+ return $this->Children[$position];
+ }
+ else {
+ $false = false;
+ return $false;
+ }
+ }
+
+ function &FindChild($name)
+ {
+ $name = strtoupper($name);
+ if ($this->Name == $name) return $this;
+// if (isset($this->Children[$name])) return $this->Children[$name];
+// $children = array_keys($this->Children);
+ foreach ($this->Children as $elem)
+ {
+ $child =& $elem->FindChild($name);
+ if ($child !== false)
+ {
+ return $child;
+ }
+ }
+ return false;
+ }
+
+ function FindChildValue($name, $attr=null)
+ {
+ $child =& $this->FindChild($name);
+ if ($child !== false) {
+ if (isset($attr)) {
+ return $child->Attributes[strtoupper($attr)];
+ }
+ return $child->Data;
+ }
+ }
+
+ /**
+ * Returns next node to this, false in case of end list
+ *
+ * @return kXMLNode
+ */
+ function &NextSibling()
+ {
+ if (!is_null($this->Parent)) {
+ $ret =& $this->Parent->GetChildByPosition($this->Position + 1);
+ return $ret;
+ }
+ else {
+ $false = false;
+ return $false;
+ }
+ }
+}
+
+?>
\ No newline at end of file
Property changes on: branches/unlabeled/unlabeled-1.6.2/core/units/general/xml_helper.php
___________________________________________________________________
Added: cvs2svn:cvs-rev
## -0,0 +1 ##
+1.6
\ No newline at end of property
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property

Event Timeline