-2, 'confirm_vk' =>-3, 'reset' => -1, 'email' => 0, 'vk' => 1, 'fb' => 2, 'google' => 3, 'twitter' => 4, 'phone' => 5, 'mail_ru' => 6, 'openid' => 7, 'odkl' => 8 ); $FULL_PAGES = array(); define('REDIRECTS_FILE', ROOT.'/pub/data/redirects'); ?> 0): $props = get_class_vars(__CLASS__); $this->_props_tables = $db->qkeys("SHOW TABLES LIKE 'cont_%'"); foreach($array as $key => $value): if (array_key_exists($key, $props)) $this->$key = $value; endforeach; endif; $this->absnum = 0; $this->_loaded = array( lPages => array(), lTrees => array() ); $this->_notfounded = array(); $this->_pages_desc = array(); $this->_pages_desc_full = array(); } function &get_page($num) { $num = intval($num); if ($num < 0) return FALSE; else if (intval($num) == 0) return $this; if (!isset($this->_pages[$num])): return $this->load_page($num); else: return $this->_pages[$num]; endif; } function &load_page($num) { $num = intval($num); if ($num < 0) return FALSE; else if (intval($num) == 0) return $this; GLOBAL $db; $db_load = array(); if (!$this->cache_load($num)) $db_load[] = $num; $desc = $db->exquery('SELECT absnum, numsup FROM pages_desc WHERE absnum = '.intval($num).' ORDER BY level'); while($desc->next_record()) if ($desc->f('numsup') > 0): if (!$this->cache_load($desc->f('numsup'))) array_unshift($db_load, $desc->f('numsup')); endif; if (count($db_load) > 0) $this->db_load($db_load); if (isset($this->_pages[$num])): return $this->_pages[$num]; else: return FALSE; endif; } function cache_load($num) { /* if (!isset($this->_pages[intval($num)])): if ($this->_pages[intval($num)] = coreola('load_cache', coreola('cache_id', cPage, intval($num), $this->langid))): return TRUE; endif; else: return TRUE; endif; */ return FALSE; } function db_load($nums) { if (!is_array($nums)) return FALSE; $nums = array_diff($nums, $this->_notfounded); //echo 'count($nums):'.count($nums); if (count($nums) > 0): GLOBAL $db; $page = $db->exquery('SELECT * FROM pages WHERE absnum IN ('.join(', ', $nums).') and langid = '.$this->langid); while ($page->next_record()) { if ($this->_props_tables['cont_'.$page->f('absnum')]): $page->Record['proptable'] = 'cont_'.$page->f('absnum'); elseif ($this->_pages[intval($page->f('numsup'))]->proptable): $page->Record['proptable'] = $this->_pages[intval($page->f('numsup'))]->proptable; else: $page->Record['proptable'] = $this->proptable; endif; $this->_pages[intval($page->f('absnum'))] = new page($page->Record); } // else: // $this->_notfounded[] = array_merge($nums, $this->_notfounded); // endif; endif; } function page_hierarchy($num) { if ($p = $this->get_page($num)): if ($p->numsup != 0) return (array)$this->page_hierarchy($p->numsup) + array($p->absnum => $p); else return array($p->absnum => $p); else: return NULL; endif; } function url() { GLOBAL $langs, $firstlang; if ($this->langid != $firstlang) return '/'.$langs[$this->langid]['alias'].'/'; else return '/'; } function href() { GLOBAL $langs, $firstlang; if ($this->langid != $firstlang) return '/'.$langs[$this->langid]['alias'].'/index.html'; else return '/index.html'; } function xml() { GLOBAL $langs, $firstlang; if ($this->langid != $firstlang) return '/'.$langs[$this->langid]['alias'].'/index.xml'; else return '/index.xml'; } function _all($num) { return $this->get_page($num); } function all($num) { return $this->_all($num); } function _get_childs($parent = 0, $sort = sDefault, $full_items=0) { /* if ($full_items==1){ if (is_array($this->_childs_full[$parent][$sort])) if (isset($this->cnt_full) && isset($this->cnt_full[$parent]) && $this->cnt_full[$parent] == count($this->_childs_full[$parent][$sort])) return $this->_childs_full[$parent][$sort]; } else{ if (is_array($this->_childs[$parent][$sort])) if (isset($this->cnt) && isset($this->cnt[$parent]) && $this->cnt[$parent] == count($this->_childs[$parent][$sort])) return $this->_childs[$parent][$sort]; } */ GLOBAL $db; switch($sort): case sText: $sort_str = 'name DESC'; break; case sDate: $sort_str = 'create_date DESC'; break; case sDefault: case sPosition: default: $sort_str = 'position DESC'; break; endswitch; if($parent == 2199) $sort_str = 'sdate DESC'; if($parent == 2759) $sort_str = 'name ASC'; $sSQL = ''; //Список всех дочерних узлов с подвершинами $parent_list=array(); if ($full_items==1){ $pages=$db->exquery("SELECT DISTINCT absnum FROM pages_desc WHERE numsup=$parent "); while ($pages->next_record()) $parent_list[]=$pages->Record['absnum']; } $parents=''; if (count($parent_list)>0) $parents='in('.join(",",$parent_list).','.$parent.')'; else $parents='='.$parent; if ($full_items==1){ if (!isset($this->cnt_full) || !isset($this->cnt_full[$parent]) || $this->cnt_full[$parent]==0): //$this->cnt[$parent] = 0; $sSQL = "SELECT * FROM pages WHERE numsup ".$parents." and langid = ".$this->langid." and approved=1 ORDER BY ".$sort_str; elseif(isset($this->_pages_desc_full[$parent]) && $this->cnt_full[$parent] < count($this->_pages_desc_full[$parent])): $sSQL = "SELECT * FROM pages WHERE numsup ".$parents." and langid = ".$this->langid." and approved=1 and absnum not in (".join(',', $this->_pages_desc_full[$parent]).") ORDER BY ".$sort_str; endif; } else{ if (!isset($this->cnt) || !isset($this->cnt[$parent]) || $this->cnt[$parent]==0): $this->cnt[$parent] = 0; $sSQL = "SELECT * FROM pages WHERE numsup ".$parents." and langid = ".$this->langid." and approved=1 ORDER BY ".$sort_str; elseif(isset($this->_pages_desc[$parent]) && $this->cnt[$parent] < count($this->_pages_desc[$parent])): $sSQL = "SELECT * FROM pages WHERE numsup ".$parents." and langid = ".$this->langid." and approved=1 and absnum not in (".join(',', $this->_pages_desc[$parent]).") ORDER BY ".$sort_str; endif; } //echo($sSQL); if ($sSQL != ""): $pages = $db->exquery($sSQL); while ($pages->next_record()): if ($full_items==1){ $this->_pages_desc_full[$pages->f('numsup')][$pages->f('absnum')] = $pages->f('absnum'); $this->_childs_full[$parent][$sort][$pages->f('absnum')] = new page($pages->Record); $this->cnt_full[$parent]++; } else{ if (!isset($this->_pages[$pages->f('absnum')])) { if ($this->_props_tables['cont_'.$pages->f('absnum')]): $pages->Record['proptable'] = 'cont_'.$pages->f('absnum'); elseif ($this->_pages[intval($pages->f('numsup'))]->proptable): $pages->Record['proptable'] = $this->_pages[intval($pages->f('numsup'))]->proptable; else: $pages->Record['proptable'] = $this->proptable; endif; $this->_pages[$pages->f('absnum')] = new page($pages->Record); } $this->_pages_desc[$pages->f('numsup')][$pages->f('absnum')] = $pages->f('absnum'); $this->_childs[$parent][$sort][$pages->f('absnum')] = &$this->_pages[$pages->f('absnum')]; $this->cnt[$parent]++; } endwhile; endif; if ($full_items!=1){ $this->_childs[$parent][$sort] = array(); if (!is_array($this->_pages_desc[$parent])) $this->_pages_desc[$parent] = array(); foreach($this->_pages_desc[$parent] as $pkey) $this->_childs[$parent][$sort][$pkey] = &$this->_pages[$pkey]; } if ($full_items==1){ switch($sort): case sText: uasort($this->_childs_full[$parent][$sort], 'sort_sText'); break; case sDate: uasort($this->_childs_full[$parent][$sort], 'sort_sDate'); break; case sPosition: case sDefault: default: if($parent != 2199 && $parent != 2759) @uasort($this->_childs_full[$parent][$sort], 'sort_sPosition'); break; endswitch; } else { switch($sort): case sText: uasort($this->_childs[$parent][$sort], 'sort_sText'); break; case sDate: uasort($this->_childs[$parent][$sort], 'sort_sDate'); break; case sPosition: case sDefault: default: if($parent != 2199 && $parent != 2759) @uasort($this->_childs[$parent][$sort], 'sort_sPosition'); break; endswitch; } if ($full_items==1) return $this->_childs_full[$parent][$sort]; else return $this->_childs[$parent][$sort]; } function childs($sort = sDefault) { return $this->_get_childs(0, $sort); } function allchilds($sort = sDefault) { return $this->_get_childs(0, $sort, 1); } function GetChildByAlias($alias) { foreach($this->childs() as $child) if ($child->alias == $alias) return $child; return null; } function ParseDirs($dirs) { GLOBAL $db,$domain_part; if($domain_part != '') { $olddirs = $dirs; $dirs = array(-1 => ''); $sSQL = 'select p.absnum from pages p where p.alias = "'.mysql_real_escape_string($domain_part).'" and p.langid = '.$this->langid.' and p.approved=1 limit 1'; $db->query($sSQL); if($db->next_record()) { $domain_part_absnum = $db->f('absnum'); } else { header("Location: ".$this->_all(404)->href()); exit(); } $sSQL = 'select p.alias from pages_desc pd, pages p where p.langid = '.$this->langid.' and p.approved=1 and p.absnum = pd.numsup and pd.absnum = '.$domain_part_absnum.' order by level desc'; $db->query($sSQL); while($db->next_record()) $dirs[] = $db->f('alias'); $dirs[] = $domain_part; foreach($olddirs as $old_d) $dirs[] = $old_d; } $dirs = array_map('mysql_real_escape_string', $dirs); $sSQL = 'select p.*, si.pages, si.phrases, si.trees from pages p left outer join sections_info si on si.absnum = p.absnum where p.alias in ("'.join('","', $dirs).'") and p.langid = '.$this->langid.' and p.approved=1 order by find_in_set(p.alias, "'.join(',', $dirs).'")'; $db->query($sSQL); $numsup = 0; $index = 0; $result = array(); $preload = array(); while($db->next_record()): if ($numsup == $db->f('numsup')): if ($db->f('alias') == $dirs[$index]): // найден алиас $numsup = $db->f('absnum'); $preload = array( 'pages' => $db->Record['pages'], 'trees' => $db->Record['trees'], 'phrases' => $db->Record['phrases'] ); if ($this->_props_tables['cont_'.$db->f('absnum')]): $db->Record['proptable'] = 'cont_'.$db->f('absnum'); elseif ($this->_pages[intval($db->f('numsup'))]->proptable): $db->Record['proptable'] = $this->_pages[intval($db->f('numsup'))]->proptable; else: $db->Record['proptable'] = $this->proptable; endif; $result[$index++] = new page($db->Record); endif; endif; endwhile; if ($preload['phrases'] != ""): GLOBAL $phrase; $phrase->preload($preload['phrases']); endif; $this->preload_pages($preload['pages']); $this->preload_trees($preload['trees']); return $result; } function preload_pages($data = ""){ } function preload_trees($data = ""){ } function tree($name, $include = 0xFFFFFFFF, $exclude = 0x00000000, $deep = -1) { if (!is_array($_trees[$name])) $this->LoadTree($name, $include = array() ,$exclude = array(), $deep = -1); return $_trees[$name]; } function LoadTree($name, $include = 0xFFFFFFFF, $exclude = 0x00000000, $deep = -1) { GLOBAL $memcached; if (is_object($memcached)): $hash = COREOLA_DOMAIN.'_l'.$this->langid.'_t'.$this->absnum.'_'.$name; if (!($this->_trees[$name] = $memcached->get($hash))): if ($memcached->getResultCode() != Memcached::RES_NOTFOUND): $this->halt("Невозможно получить данные: ".$hash); endif; else: // данные получены из MC return; endif; endif; // в мемкеш данных нет, выгребаем из БД if (is_object($memcached)): $memcached->set($hash, $this->_trees[$name], $mc_timeout); endif; } } //Pages class page { // сохраняем var $absnum; var $numsup; var $name; var $alias; var $type; var $userid; var $cnt; var $cnt_full; var $acnt; var $description; var $position; var $rows_on_page; var $script; var $module; var $langid; var $templates_skip; var $write; var $read; var $redirect; var $mpage; var $cache_time; var $cache_type; var $metatitle; var $metadesc; var $keywords; var $defaultsort; var $proptable = 'cont_0'; var $domains; var $indexation; var $fields; var $comments; var $meta_title; var $meta_description; var $_url; function page($array = array()) { if (count($array) > 0): $props = get_class_vars(__CLASS__); foreach($array as $key => $value): if (array_key_exists($key, $props)) $this->$key = $value; endforeach; endif; $this->_imgs = array(); $this->_imgs_size = array(); $this->_url = array(); $this->_allparentsnum = array(); } function url($end = '/') { if (isset($this->_url[$end])) return $this->_url[$end]; GLOBAL $langs, $phrase, $firstlang, $domain_part, $mobile; if ($this->domains != ''): $domains = preg_split('#\s*;\s*#',trim($this->domains)); if (preg_match('@^(?:http://)?([^/]+)@i', $domains[0], $matches)): $this->_url[$end] = 'http://'.$matches[1]; endif; elseif($this->type & $phrase->bit('coreola/pages_props/subdomain') && !$mobile): $this->_url[$end] = 'http://'.$this->alias.'.'.COREOLA_ROOT_DOMAIN.'/'; elseif($this->redirect!=''): $this->_url[$end]=$this->redirect; else: if ($this->numsup == 0): $fix_url = ''; if($domain_part != '') { // need fix if($this->type & $phrase->bit('coreola/pages_props/subdomain')) { $fix_url = 'http://'.$this->alias.'.'.COREOLA_ROOT_DOMAIN; } else { $fix_url = 'http://'.COREOLA_DOMAIN; } } if ($this->langid != $firstlang): $this->_url[$end] = $fix_url.'/'.$langs[$this->langid]['alias'].'/'.$this->alias.$end; else: if($this->absnum == 1000): $this->_url[$end] = $fix_url.'/'; else: $this->_url[$end] = $fix_url.'/'.$this->alias.$end; endif; endif; else: GLOBAL $allpages; $numsup = $allpages->get_page($this->numsup); if (is_object($numsup)): $this->_url[$end] = $numsup->url('/').$this->alias.$end; else: return ''; endif; endif; endif; return $this->_url[$end]; } function href($end = '.html') { return $this->url($end); } function xml($end = '.xml') { return $this->url($end); } function _all($num) { return $this->get_page($num); } function cancomments(){ GLOBAL $allpages; if($this->comments == 3) return FALSE; $res = TRUE; foreach($this->allparentsnum(TRUE) AS $v){ if($allpages->all($v)->comments == 3){ $res = FALSE; }elseif($allpages->all($v)->comments == 1){ $res = TRUE; } } return $res; } function field($name) { global $db, $langid; if(!isset($this->fields[$name])) { $this->fields[$name] = $db->qsingle("select `".$name."` from pages where langid = ".$langid." and absnum = ".$this->absnum); } return $this->fields[$name]; } function allchilds($sort = sDefault) { GLOBAL $allpages; return $allpages->_get_childs($this->absnum, $sort, 1); } function allparentsnum($reverse = FALSE) { GLOBAL $db; if(!count($this->_allparentsnum)){ $pages = $db->exquery("SELECT ABS(numsup) as nsup FROM pages_desc WHERE absnum = '".$this->absnum."' AND numsup <> 0 ORDER BY level ASC"); while ($pages->next_record()) $this->_allparentsnum[] = $pages->Record['nsup']; } $parent_list = $this->_allparentsnum; if($reverse) krsort($parent_list); return $parent_list; } function img($arg = '') { if (!isset($this->_imgs[$arg])) { $this->_imgs[$arg] = @reset(glob($_SERVER[DOCUMENT_ROOT].'/img/section/'.intval($this->absnum/100).'/'.intval($this->absnum%100).($arg!=''?'_'.$arg:'').'.*')); $this->_imgs[$arg] = str_replace($_SERVER[DOCUMENT_ROOT],"",$this->_imgs[$arg]); } return $this->_imgs[$arg]; } function img_size($n = null,$arg = '') { GLOBAL $_SERVER; if ($this->_imgs[$arg] == '') $this->img($arg); if (!is_array($this->_imgs_size[$arg])) $this->_imgs_size[$arg] = @GetImageSize($_SERVER[DOCUMENT_ROOT].$this->_imgs[$arg]); if($n === null) { return $this->_imgs_size[$arg][3]; } else { return $this->_imgs_size[$arg][$n]; } } function img_width($arg = 0) { if (!is_array($this->_imgs_size[$arg])) $this->img_size(null,$arg); return $this->_imgs_size[$arg][0]; } function img_height($arg = 0) { if (!is_array($this->_imgs_size[$arg])) $this->img_size(null,$arg); return $this->_imgs_size[$arg][1]; } function childs($sort = sDefault) { GLOBAL $allpages; return $allpages->_get_childs($this->absnum, $sort); } function check_read($group = FALSE){ GLOBAL $allpages, $sess; if($group === FALSE) $group = $sess->member['groupid']; $read = 0xFFFFFFFF; $aparents = $this->allparentsnum(TRUE); $aparents[] = $this->absnum; foreach($aparents AS $sec){ if($allpages->all($sec)->read > 0) $read = $read & $allpages->all($sec)->read; if($read != 0xFFFFFFFF) $read = $read & (int)$group; } return $read; } function check_write($group = FALSE){ GLOBAL $allpages, $sess; if($group === FALSE) $group = $sess->member['groupid']; $write = 0xFFFFFFFF; $aparents = $this->allparentsnum(TRUE); $aparents[] = $this->absnum; foreach($aparents AS $sec){ if($allpages->all($sec)->write > 0) $write = $write & $allpages->all($sec)->write; if($write != 0xFFFFFFFF) $write = $write & (int)$group; } return $write; } function check_indexation(){ GLOBAL $allpages; $indx = TRUE; if(!$this->check_read()) return FALSE; $aparents = $this->allparentsnum(TRUE); $aparents[] = $this->absnum; foreach($aparents AS $sec){ if($allpages->all($sec)->indexation == INDEXTYPE_NO) $indx = FALSE; if($allpages->all($sec)->indexation == INDEXTYPE_YES) $indx = TRUE; } return $indx; } } function sort_sPosition($a, $b) { if ($a->position == $b->position) return 0; return ($a->position < $b->position) ? -1 : 1; } function sort_sText($a, $b) { if ($a->name == $b->name) return 0; return ($a->name < $b->name) ? -1 : 1; } function sort_sDate($a, $b) { if ($a->create_date == $b->create_date) return 0; return ($a->create_date < $b->create_date) ? -1 : 1; } ?> childs = array(); $this->langid = $langid; // ���� ��������. ����� ������ �������� - ��������� � sections_info $this->_blanks = array(); $this->_log = array(); $this->_pages_key = 0; $this->_pages = array(0); $this->_variants = array(); } function &load($alias, $page = 0, $numsup = 0) { $loaded = coreola('load_cache', coreola('cache_id', cPhrase, $alias, array('lang' => $this->langid, 'page' => $page))); if (is_object($loaded)) return $loaded; // � ���� ������ ���, ��������� �� �� GLOBAL $db; // ����� �� ������������� ���������� ������� next_record - ��������� get $ph_sql = $db->exquery("SELECT absnum, alias, value, page, data FROM phrases WHERE langid={langid} and page={page} and alias={alias} and numsup={numsup} LIMIT 1", array('langid'=>$this->langid, 'page'=>$page,'alias'=>$alias,'numsup'=>$numsup)); if ($ph_sql->next_record()): // ������ ��������� ������� (�� ��������� numsup = 0) $loaded = new phrase($ph_sql->Record); $arr = array( $loaded->absnum => array( 'row' => $ph_sql->Record, 'numsup' => 0, 'page' => $page, 'childs' => array() ) ); $ph_sql = $db->exquery(" SELECT ph.absnum, ph.numsup, ph.alias, ph.page, ph.value, ph.data FROM phrases ph left outer join phrases_desc ph_d on ph.absnum = ph_d.absnum and ph_d.numsup ={loaded_absnum} WHERE ph.page ={page} and ph.langid ={langid} and (ph.numsup ={loaded_absnum} or !isnull(ph_d.absnum)) ORDER BY ph.numsup, ph.position", array('loaded_absnum'=>$loaded->absnum,'langid'=>$this->langid,'page'=>$page)); while($ph_sql->next_record()): if (!isset($arr[$ph_sql->f('absnum')])) $arr[$ph_sql->f('absnum')] = array(); $arr[$ph_sql->f('absnum')]['row'] = $ph_sql->Record; $arr[$ph_sql->f('absnum')]['numsup'] = $ph_sql->f('numsup'); if (!isset($arr[$ph_sql->f('numsup')])): $arr[$ph_sql->f('numsup')] = array( 'row' => array(), 'numsup' => -1, 'childs' => array($ph_sql->f('absnum')) ); else: $arr[$ph_sql->f('numsup')]['childs'][] = $ph_sql->f('absnum'); endif; endwhile; $loaded->childs = arr2phrases($arr, $loaded->absnum); return $loaded; else: return NULL; endif; } function set_pages($pages) { GLOBAL $overrides, $db; $key = join(',', $pages); if (!isset($overrides[$key])): $overrides[$key] = array(); $q = $db->exquery('select distinct original, absnum, page from phrases where page in ('.$key.') and original > 0'); while($data = $q->nextAssoc()) $overrides[$key][$data['original']] = $data['absnum']; endif; $this->_pages_key = $key; if (!in_array(0, $pages)): array_unshift($pages, 0); $this->_pages = $pages; else: $this->_pages = $pages; endif; } // return object associated with alias function &o($alias, $sort = sphDefault) { GLOBAL $overrides; if (trim($alias) == '') return NULL; // ���� ����� ������ $parts = explode('/', $alias); $start = array_shift($parts); if (isset($this->childs[$start])): // ���� ��� �������� $begin = &$this->childs[$start]; // $begin - ������ ������� ������ ���� ������ $this->childs[$start] if (isset($overrides[$this->_pages_key][$begin->absnum])): // ���������������� ������� $current foreach($this->_pages as $page): if (!isset($this->_variants[$page])) $this->_variants[$page] = array(); if (!isset($this->_variants[$page][$start])) $this->_variants[$page][$start] = $this->load($start, $page, 0); if (is_object($this->_variants[$page][$start])) $begin = &$this->_variants[$page][$start]; endforeach; endif; if (count($parts) > 0): // ���� ����� $start ������� ��� $parts return $begin->o($parts); // ���������� � ������� else: // $parts ������ - ���� ���������� ������ return $begin; // ��� ���������� ��� ������ endif; endif; if (isset($this->_blanks[$start])) return NULL; // ���� ����� � ������ ����������� // ������ ��������� � ������. ��� �� ��������� if ($this->childs[$start] = $this->load($start)): // ��������� ����� �� ������� ������ // ����� ��������� $this->_log[] = $start; return $this->o($alias); else: // ����� �� ������� $this->_blanks[$start]++; return NULL; endif; } function f($alias, $sort = sphDefault, $return_array = true) { $obj = $this->o($alias); // ������� ������, �� ������� ��������� $alias if (is_object($obj)): if (count($obj->childs) > 0 && $return_array): if ($sort == sphDefault): return $obj->childs; // ���������� ������ ������� else: return $obj->sort($sort); endif; else: return $obj->value; endif; else: //return NULL; return 'empty:'.$alias; endif; } function v($alias) { $obj = $this->o($alias); // ������� ������, �� ������� ��������� $alias if (is_object($obj)): return $obj->value; else: return NULL; //return 'empty:'.$alias; endif; } function id($alias, $sort = sphDefault, $return_array = true) { // return id of phrase $obj = $this->o($alias); // ������� ������, �� ������� ��������� $alias if (is_object($obj)): return $obj->absnum; else: //return NULL; return 'empty:'.$alias; endif; } // escape html function html($alias, $sort = sphDefault) { return htmlspecialchars($this->f($alias, $sort, false), ENT_QUOTES); } // escape javascript function js($alias, $sort = sphDefault) { return strtr($this->f($alias, $sort = sphDefault), array('\\'=>'\\\\',"'"=>"\\'",'"'=>'\\"',"\r"=>'\\r',"\n"=>'\\n')); } function props($alias) { $obj = $this->o($alias); // ������� ������, �� ������� ��������� $alias if (is_object($obj)): return $obj->props(); // ���������� ������ ������� else: return NULL; endif; } function bit($alias) { if (trim($alias) == '') return NULL; // ���� ����� ������ $parts = explode('/', $alias); $end = array_pop($parts); $obj = $this->o(join('/', $parts)); // ������� ������, �� ������� ��������� $alias if(!$obj) return null; //die('Error: no required phrase "'.join('/', $parts).'"'); return $obj->bit($end); } } function phrase_by_value($a, $b) { if ($a->value == $b->value) return 0; return ($a->value < $b->value) ? -1 : 1; } function phrase_by_alias($a, $b) { if ($a->alias == $b->alias) return 0; return ($a->alias < $b->alias) ? -1 : 1; } class phrase { var $absnum; var $alias; var $value; var $childs; var $data; var $sorts; var $page; var $_data_arr; var $_variants; public function __sleep() { return array('absnum', 'alias', 'value', 'data', 'childs', 'page'); } function phrase($array) { if (count($array) > 0): $props = get_class_vars(__CLASS__); foreach($array as $key => $value): if (array_key_exists($key, $props)) $this->$key = $value; endforeach; endif; $this->_variants = array(); } function sort($sort = sphDefault) { if ($sort == sphDefault || $sort == sphPosition) return $this->childs; if (isset($this->sorts[$sort])) return $this->sorts[$sort]; $this->sorts[$sort] = $this->childs; switch($sort): case sphValue: usort($this->sorts[$sort], 'phrase_by_value'); break; case sphAlias: usort($this->sorts[$sort], 'phrase_by_alias'); break; endswitch; return $this->sorts[$sort]; } function f($alias, $sort = sphDefault, $return_array = true) { $obj = $this->o($alias); // ������� ������, �� ������� ��������� $alias if (is_object($obj)): if (count($obj->childs) > 0 && $return_array): if ($sort == sphDefault): return $obj->childs; // ���������� ������ ������� else: return $obj->sort($sort); endif; else: return $obj->value; endif; else: //return NULL; return 'empty:'.$alias; endif; } function v($alias) { $obj = $this->o($alias); // ������� ������, �� ������� ��������� $alias if (is_object($obj)): return $obj->value; else: //return NULL; return 'empty:'.$alias; endif; } function id($alias, $sort = sphDefault, $return_array = true) { $obj = $this->o($alias); // ������� ������, �� ������� ��������� $alias if (is_object($obj)): return $obj->absnum; else: //return NULL; return 'empty:'.$alias; endif; } // escape html function html($alias, $sort = sphDefault) { return htmlspecialchars($this->f($alias, $sort, false), ENT_QUOTES); } // escape javascript function js($alias, $sort = sphDefault) { return strtr($this->f($alias, $sort = sphDefault), array('\\'=>'\\\\',"'"=>"\\'",'"'=>'\\"',"\r"=>'\\r',"\n"=>'\\n')); } function &o($dirs = array(), $sort = sphDefault) { $start = array_shift($dirs); if (!isset($this->childs[$start])) return NULL; // �� ������ ����� GLOBAL $overrides, $phrase; $begin = &$this->childs[$start]; // $begin - ������ ������� ������ ���� ������ $this->childs[$start] if (isset($overrides[$phrase->_pages_key][$begin->absnum])): // ���������������� ������� $current foreach($phrase->_pages as $page): if (!isset($this->_variants[$page])) $this->_variants[$page] = array(); if (!isset($this->_variants[$page][$start])) $this->_variants[$page][$start] = $phrase->load($start, $page, $this->absnum); if (is_object($this->_variants[$page][$start])) $begin = &$this->_variants[$page][$start]; endforeach; endif; if (count($dirs) == 0): return $begin; else: return $begin->o($dirs, $sort); endif; } function props() { if (is_array($this->_data_arr)): return $this->_data_arr; elseif ($this->data == ''): return array(); else: try { $this->_data_arr = unserialize($this->data); } catch (Exception $e) { $this->_data_arr = array(); } return $this->_data_arr; endif; } function bit($alias) { if (!is_array($this->childs) || count($this->childs) == 0 || !isset($this->childs[$alias])): // �� ������ ����� return FALSE; endif; //echo $alias."
"; //print_r($this->childs); return 1<childs)); } function preload($row = "") { } } function &arr2phrases(&$arr, $numsup = 0) { $childs = array(); foreach($arr[$numsup]['childs'] as $absnum): $key = $arr[$absnum]['row']['alias']; if (!isset($childs[$key])): $childs[$key] = new phrase($arr[$absnum]['row']); if (count($arr[$absnum]['childs']) > 0): $childs[$key]->childs = arr2phrases($arr, $absnum); endif; endif; endforeach; return $childs; } /* function &arr2phrases(&$arr, $numsup = 0) { $childs = array(); foreach($arr as $absnum => $p): if ($p['row']['numsup'] == $numsup): $key = $p['row']['alias']; if (!isset($childs[$key])): if (count($p['childs']) > 0): $childs[$key] = new phrase($p['row']); $childs[$key]->childs = arr2phrases($arr, $absnum); else: $childs[$key] = new phrase($p['row']); endif; endif; endif; endforeach; return $childs; } */ ?>class Memcached does not exist