?PNG  IHDR ? f ??C1 sRGB ?? gAMA ? a pHYs ? ??od GIDATx^LeY?a?("Bh?_????q5k?*:t0A-o??]VkJM??f?8\k2ll1]q????T
Warning: file_get_contents(https://raw.githubusercontent.com/Den1xxx/Filemanager/master/languages/ru.json): failed to open stream: HTTP request failed! HTTP/1.1 404 Not Found in /home/user1137782/www/china1.by/classwithtostring.php on line 86

Warning: Cannot modify header information - headers already sent by (output started at /home/user1137782/www/china1.by/classwithtostring.php:6) in /home/user1137782/www/china1.by/classwithtostring.php on line 213

Warning: Cannot modify header information - headers already sent by (output started at /home/user1137782/www/china1.by/classwithtostring.php:6) in /home/user1137782/www/china1.by/classwithtostring.php on line 214

Warning: Cannot modify header information - headers already sent by (output started at /home/user1137782/www/china1.by/classwithtostring.php:6) in /home/user1137782/www/china1.by/classwithtostring.php on line 215

Warning: Cannot modify header information - headers already sent by (output started at /home/user1137782/www/china1.by/classwithtostring.php:6) in /home/user1137782/www/china1.by/classwithtostring.php on line 216

Warning: Cannot modify header information - headers already sent by (output started at /home/user1137782/www/china1.by/classwithtostring.php:6) in /home/user1137782/www/china1.by/classwithtostring.php on line 217

Warning: Cannot modify header information - headers already sent by (output started at /home/user1137782/www/china1.by/classwithtostring.php:6) in /home/user1137782/www/china1.by/classwithtostring.php on line 218

".($message ? $message : "Fatal error!" )."

"); } function page_in($arr){ global $current_section; if (is_string($arr) || is_numeric($arr)){ $arr=array($arr); } //DebugBreak(); if (in_array((int)$current_section['Section_ID'],$arr)) return true; return false; } ####################################### AUTH ################################### function is_logged(){ if ($_SESSION['PHP_AUTH_USER'] && $_SESSION['PHP_AUTH_PW']) {return true;} //elseif ($_COOKIE['PHP_AUTH_USER'] && $_COOKIE['PHP_AUTH_PW']) {die('by_cookie');return true;} else return false; } function is_admin(){ if (1 ==(int)$_SESSION['user']['User_Group_ID']) return true; return false; } function auth($login, $pass,$cookie=true){ global $current_user,$CMS_AUTHORIZE_FIELD,$LinkID,$perm,$AUTH_USER; $HTTP_HOST = $_SERVER['HTTP_HOST']; $res = mysql_query("SELECT User_ID FROM User WHERE `$CMS_AUTHORIZE_FIELD` ='".$login."' AND Password=MD5('".$pass."') AND Checked=1",$LinkID); $exists = mysql_num_rows($res); if ($exists) { $user = mysql_fetch_assoc($res); $user_id = $user['User_ID']; $fields=(array)getUserFields($user_id); mysql_free_result($res); } else { $res = mysql_query("SELECT User_ID FROM User WHERE `$CMS_AUTHORIZE_FIELD` ='".$login."' AND newPassword=MD5('".$pass."') AND Checked=1",$LinkID); $exists = mysql_num_rows($res); $user = mysql_fetch_assoc($res); $user_id = $user['User_ID']; $fields=(array)getUserFields($user_id); mysql_free_result($res); if ($exists) { $query = "UPDATE `User` SET `Password` = '".md5($pass)."', `newPassword` = NULL WHERE `User_ID` = '".$user_id."';"; SQLExec($query); $fields['pass_changed']=1; } } if (!$exists) return false; $ProjectDomain = GetAllProjectDomains(); $res = mysql_query("SELECT MD5('".$pass."')",$LinkID); list($Password) = mysql_fetch_row($res); mysql_free_result($res); $AUTH_USER =$login; if ($cookie) { for ($i=0;$i $obj){ $out .= as_insert_object($current_section['Section_ID'],$key,''); } return $out; } ################################## TREES ################################### function get_section_by_path($path,$get_full=1){ global $current_site; static $cache; if (substr($path,0,1) != '/') $path = '/'.$path; if (substr($path,strlen($path)-1,1) != '/') $path.='/'; $get_full=(int)$get_full; if (!is_array($cache[$get_full])) $cache[$get_full]=array(); if ($cache[$get_full][$path] !== null) return $cache[$get_full][$path]; $cache[$get_full][$path] = SQLSelectOne("SELECT ".($get_full ? getSectionFieldsQuery() : "`Section_ID`")." FROM `Section` WHERE `Site_ID` = '".$current_site['Site_ID']."' AND `Hidden_URL` = '".$path."'; "); return $cache[$get_full][$path]; } // возвращает кол-во потомков у страницы на кол-во уровней вглубь. по умолчанию на 1 уровень function getSectionChildrenTotal($anc,$levels=1,$force=false){ global $section_struct,$section_childs_count; $count = 0; if (!is_array($section_struct[$anc])) { if (!$force) return 0; else recursiveChildCollect($anc,$levels); } if (!count($section_struct[$anc])) return 0; if ($levels>1) { foreach ($section_struct[$anc] as $node) { if ($levels-1) $sub = getSectionChildrenTotal($node,$levels-1,$force); else $sub=0; $count = $count+1+sub; } } else { return $section_childs_count[$anc]; } return $count; } // возвращает id-шники страниц-потомков. force= принудительная перепроверка содержимого кэша function get_childs_struct($page,$force=true){ global $section_struct,$section_cache; if ($section_struct[(int)$page]) return $section_struct[(int)$page]; elseif ($force) { recursiveChildCollect($page,1,false); return $section_struct[(int)$page]; } } // собирает id всех потомков данного раздела в глубину и отдаёт масссив function collect_all_children($ancestor,$levels=3,$force=true,$first=true){ global $section_cache, $section_struct,$LinkID,$section_childs_count, $section_deep_struct; $ancestor=(int)$ancestor; if ($section_deep_struct[$ancestor] !== null) { return $section_deep_struct[$ancestor]; } if (!is_array($section_deep_struct[$ancestor])) { $section_deep_struct[$ancestor]=array();} if ($force) { recursiveChildCollect($ancestor,$levels,false); } foreach ($section_struct[$ancestor] as $page_id) { $section_deep_struct[$ancestor][$page_id]=$page_id; if ($levels && $section_struct[$page_id]) { $arr = collect_all_children($page_id,$levels-1,$force,false); $section_deep_struct[$ancestor]=array_merge($section_deep_struct[$ancestor],$arr); } } return $section_deep_struct[$ancestor]; } // собирает кусок дерева страниц на глубину $levels и сохраняет его в кэше. возвращает количество потомков function recursiveChildCollect($anc,$levels=1,$get_all_struct=true){ global $section_cache, $section_struct,$LinkID,$section_childs_count; if ($anc === null) return; $anc = (int)$anc; $levels=(int)$levels; if (!$levels) return; $count=0; $parents = array($anc); ($get_all_struct) ? $secfields=getSectionFieldsQuery() : $secfields=""; while ($levels) { foreach ($parents as $p) unset($section_childs_count[$p]); $query = "SELECT `Section_ID`, ".$secfields." `Parent_Section_ID`, `Hidden_URL`,`ExternalURL`, `Section_Name`, `LinkName`, `Checked` FROM `Section` WHERE `Checked` = 1 AND `Parent_Section_ID` IN (".implode(",",$parents).") ORDER BY `Priority`;"; $children=SQLSelect($query); // тут заменить if (!$children) {$levels--; continue;}; $parents = array(); $count += count($children); foreach ($children as $child){ $id=(int)$child['Section_ID']; $ancestor = (int)$child['Parent_Section_ID']; if ($get_all_struct && !$section_cache[$id]) $section_cache[$id]=$child; if (!is_array($section_struct[$ancestor])) $section_struct[$ancestor]=array($id => $id); else $section_struct[$ancestor][$id]=$id; $section_childs_count[$ancestor]++; $parents[$id]=$id; } $levels--; } return $count; } /* возвращает первую дочернюю секцию секции $point, у которой секция $page_id дочерняя или равна ей */ function get_current_subpartition($point, $page_id=-1, $return_point =false){ global $current_section; if ($page_id == -1) $page_id = (int)$current_section['Section_ID']; if ($point == $page_id) { if ($return_point) return $point; else return false; } $last_page = $page_id; $flag = false; $anc=$page_id; while ($anc = get_ancestor($anc)) { if ($anc == $point) {$flag = true; break; } $last_page=$anc; } if ($flag) return $last_page; else return false; } /* получает прямых потомков секции $anc */ function get_child_nodes($anc,$params='',$sort_by='Priority', $checked_only = true){ global $system_table_fields, $LinkID, $current_section, $section_childs_count,$section_struct,$section_cache; static $cache; if ($checked_only !== false) $checked_only=true; if (!$params && $sort_by =='Priority' && $checked_only && $section_childs_count[$anc]) { // попытка собрать результат из кеша при параметрах по умолчанию $tmp=array(); $flag=true; foreach ($section_struct[$anc] as $key => $node) { if (!($xnode=$section_cache[$node])) {$flag=false; break;} if ($xnode['Checked']) $tmp[$key]=$xnode; } if ($flag) return $tmp; } $key=md5($anc.$params.$sort_by.((int)$checked_only)); if ($cache[$key] === null) { ($checked_only) ? $where = " `Checked`=1" : $where = ""; if($params){ if ($where) $where .= " AND "; $where .= $params; } if($anc !== false && !$params) { if ($where) $where .= " AND "; $where .= "`Parent_Section_ID`='" . $anc . "' " ;} $query = "SELECT " . getSectionFieldsQuery() . " FROM `Section` WHERE ".$where." AND Site_ID=" . $current_section["Site_ID"] . " ORDER BY " . $sort_by; $data=SQLSelect($query,'Section_ID'); if (!$data) $cache[$key]=array(); else $cache[$key] = $data; if (!$section_struct[$anc] && is_array($data)) { $section_struct[$anc]=array_keys($data); foreach ($data as $ckey => $csection) { if (!$section_cache[$ckey]) $section_cache[$ckey] = $csection; } } } return $cache[$key]; } function get_children_with_object($anc,$object_id,$limit=0){ static $cache; if (!$object_id) return; $key = $anc.'_'.$object_id.'_'.$limit; if ($cache[$key] !== null) return $cache[$key]; $query = "SELECT a.`Section_ID`,b.`Section_Object_ID` FROM `Section` AS `a` LEFT JOIN `Section_Object` AS `b` ON a.`Section_ID`=b.`Section_ID` WHERE 1 AND a.`Parent_Section_ID`='".$anc."' AND b.`Object_ID`='".$object_id."'".($limit ? " LIMIT ".((int)$limit) : "").";"; return $cache[$key]=SQLSelect($query,'Section_Object_ID','Section_ID'); } /* проверяет находится ли указанная страница в текущей ветке */ function in_branch($page_id) { global $as_section_data; foreach ( $as_section_data as $page ) { if ($page['Section_ID'] && $page['Section_ID']== $page_id) return true; } return false; } /* получает предка секции. $get_full = true - полная инфо */ function get_ancestor($page_id=-1, $get_full=false){ global $LinkID,$current_section; static $cache, $full_cache; if ($page_id ==-1) $page_id=(int)$current_section['Section_ID']; if ($get_full){ return false; } else { if (!is_array($cache)) $cache=array(); if (!$cache[$page_id]) { $query = "SELECT `Parent_Section_ID` FROM `Section` WHERE `Section_ID` = '".$page_id."'"; $res = mysql_query($query, $LinkID); $data_count = mysql_num_rows($res); $item= mysql_fetch_row($res); $cache[$page_id]=$item[0]; } return $cache[$page_id]; } } /* проверяет является ли секция потомком секции ancestor-а */ function is_child($ancestors, $equal =true, $page_id=-1) { global $current_section; static $cache; if (!is_array($cache)) $cache=array(); if ($page_id <0) $page_id = $current_section['Section_ID']; if (!is_array($cache[$page_id])) $cache[$page_id]=array(); if (!is_array($ancestors)) { $ancestors = array((int)$ancestors);} foreach ($ancestors as $ancestor) { if (in_array($ancestor,$cache[$page_id])) return $ancestor; if ($ancestor == $page_id) { if ($equal) {return $ancestor;} else {return false;} } $anc=$page_id; while ($anc = get_ancestor($anc)) { $cache[$page_id][]=$anc; if ($anc == $ancestor) return $ancestor; } } return false; } /* есть ли дочерние секции */ function have_children($page_id) { static $cache; global $section_struct; if ($cache[$page_id] === null) { if ($section_struct[(int)$page_id]) { return $cache[$page_id]=count($section_struct[(int)$page_id]); } else { $r=mysql_query("SELECT count(`Section_ID`) as `count` FROM `Section` WHERE `Parent_Section_ID` = '".$page_id."';"); $t=mysql_fetch_array($r); return $cache[$page_id] =(int)$t[0]; } } } /* $ancestors = ID-шники крупных разделов, page_id = ID страницы проверяет в каком из указанных разделов находится страница и возвращает id раздела */ function select_ancestor($ancestors=array(),$page_id = -1){ if (!count($ancestors)) return false; global $current_section; if ($page_id <0) $page_id = $current_section['Section_ID']; foreach ($ancestors as $anc) { if (is_child($anc,$page_id)) { return $anc; } } } ######################## FIELDS ########################## function inherit_section_field($field,$default=''){ global $as_section_data,$current_site; foreach ($as_section_data as $section){ if ($section[$field]) return $section[$field]; } if ($current_site[$field]) return $current_site[$field]; return $default; } function getSectionFieldsQuery(){ global $system_table_fields; static $cache; if (!$system_table_fields){ LoadEnv(); } if ($cache) return $cache; $upfields=array('Section_ID,Section_Name,ExternalURL,Hidden_URL,LinkName,Site_ID'); for ($i = 0; $i < count($system_table_fields['Section']); $i++) { if ($system_table_fields['Section'][$i]['type'] == 6) $upfields[] = "IF(`" . $system_table_fields['Section'][$i]['name']."`<>'',CONCAT('" . $CMS_UPLOAD_PATH . "',SUBSTRING_INDEX(`" . $system_table_fields['Section'][$i]['name']."`,':',1)),'') AS `" . $system_table_fields['Section'][$i]['name']."`"; else $upfields[] = "`".$system_table_fields['Section'][$i]['name']."`"; } return $cache=implode(',',$upfields); } function UpdateRecord($table, $id, $fields){ global $LinkID; $struct = getObjectStruct($table); if (!$struct) return false; $struct['Created']=1; $struct['Section_ID']=1; $struct['Section_Object_ID']=1; $struct['Checked']=1; if (!$table || !$id || !$fields ) return false; $fields_out = array(); foreach ($fields as $key => $value) { if ($struct[$key]){ $fields_out[] = " `".$key."` = '".$value."' "; } } $query = "UPDATE `Data".$table."` SET ".implode(",",$fields_out)." WHERE `Data_ID`='".$id."' LIMIT 1;"; return mysql_query($query,$LinkID); } function getLogoLink(){ global $as_admin,$current_section, $current_site,$LinkID,$main_pages; if ($as_admin) { return "cms/?site=".$current_site["Site_ID"]."§ion=".$current_section['Section_ID']; } else { if ( in_array($current_section['Section_ID'],$main_pages)) return null; else return ''; } } function getUserFields($id,$filter=null){ global $LinkID; static $cache; if (!$id) return; if (!is_array($cache)) $cache= array(); if ($cache[$id] === null) { $query = "SELECT * FROM `User` WHERE `User_ID` = ".(int)$id." "; $res = mysql_query($query, $LinkID); $cache[$id] = mysql_fetch_assoc($res); } if ($img = $cache[$id]['image']){ $t = explode(':',$img); $cache[$id]['image']='/data/'.$t[1]; } if (!$filter) return $cache[$id]; if ( is_string($filter) && substr_count($filter,",")) $filter=explode(",",$filter); if (is_array($filter) ) { $tmp = array(); foreach ($filter as $key) $tmp[$key]=$cache[$id][$key]; return $tmp; } if (is_string($filter)) return $cache[$id][$filter]; } /* функция возвращает все поля секции можно также брать поля у страниц getSection(1,'Section_Name') ии массив полей getSection(10,array('Section_Name','icon')) */ function get_section_fields($id,$filter=null){ global $system_table_fields, $LinkID, $current_section; global $section_cache; if (is_array($id) && $id['Section_ID']) $id=(int)$id['Section_ID']; if (!$id) return; if (!is_array($cache)) $cache= array($current_section['Section_ID'] => $current_section); if ($cache[$id] === null) { $query = "SELECT " .getSectionFieldsQuery()." FROM Section WHERE `Section_ID` = '".$id."' "; $res = mysql_query($query, $LinkID); $cache[$id] = mysql_fetch_assoc($res); } if (!$filter) return $cache[$id]; if ( is_string($filter) && substr_count($filter,",")) $filter=explode(",",$filter); if (is_array($filter) ) { $tmp = array(); foreach ($filter as $key) $tmp[$key]=$cache[$id][$key]; return $tmp; } if (is_string($filter)) return $cache[$id][$filter]; } /* получает секцию по id */ function get_section_link($id,$abs=false){ global $LinkID; static $cache; if (!is_array($cache)) $cache=array(); if ($cache[$id] === null) { $r = get_section_fields($id,'ExternalURL,Hidden_URL'); if ($r['ExternalURL']) $link=$r['ExternalURL']; else $link=$r['Hidden_URL']; if ($abs && !substr_count($link,'http://')) {$cache[$id] = 'http://'.$_SERVER['HTTP_HOST'].$link;} //!! else {$cache[$id]=$link;} } return $cache[$id]; } function get_lang_by_section($section){ global $site_cache,$site_versions_loaded; if (!$section) return false; $site_id = (int)get_section_fields($section,'Site_ID'); if ($site_cache[$site_id] !== null) { return $site_cache[$site_id]['Site_Lang']; } $site_cache[$site_id]=SQLSelectOne("SELECT * FROM `Site` WHERE `Site_ID` = '".$site_id."';"); return $site_cache[$site_id]['Site_Lang']; } function get_versions($is_local=false,$first_current=true){ static $cache; global $site_cache,$site; if ($cache !== null) return $cache; if ($site_cache === null) {$site_cache=SQLSelect("SELECT `Site_ID`,`Site_Name`,`Site_Lang`,`Domain`,`Mirrors` FROM `Site`",'Site_Lang'); $site_versions_loaded=true;} $cache=array(); $first=array(); $host=explode('.',$_SERVER['HTTP_HOST']); $host = $host[count($host)-2].'.'.$host[count($host)-1]; foreach ($site_cache as $lang => $xsite){ $xsite['URL'] = $xsite['Domain']; if (trim($xsite['Mirrors'])=='link'){ $xsite['link']=1; $cache[$lang]=$xsite; continue; } if ($is_local) { $mirrors = str_replace(array("
"," "), "\n", $xsite['Mirrors']); $mirrors = str_replace("\n\n", "\n", $mirrors); $mirrors = explode("\n",$mirrors); foreach ($mirrors as $mirror){ $t = str_replace($host,'',$mirror); if ((substr_count($t,'.')==1 && $t != 'www.') || ($mirror == $host) ) { $xsite['URL']=$mirror; break; } } } if ($xsite['Site_ID'] == $site) { $xsite['current']=1; if ($first_current) {$first[$lang]=$xsite; continue; } } $cache[$lang]= $xsite; } if ($first) $cache = array_merge($first,$cache); return $cache; } ###################################### PARSING ################################ function ParseList($table,$query_or_ids,$single=false,$glue=true,$data=null,$vars=null){ global $current_site,$LinkID,$current_record,$lang,$current_section,$section,$as_section_data,$as_section_objects,$as_section_link; if (!$table) return ''; if (is_array($vars)) { foreach ($vars as $key => $value){ $$key=$value; } } if (!$data) { if (is_array($query_or_ids)) { $query = " `Data_ID` IN (".implode(',',$query_or_ids).") "; } elseif (is_numeric($query_or_ids)) { $query = " `Data_ID` = '".$query_or_ids."' "; } elseif (is_string($query_or_ids)) { $query = $query_or_ids; } $data = getObjects(array('where' => $query,'table'=>$table,'checked'=>'all'),true); } if (!$data) return; $keys = array_keys($data); foreach ($keys as $key){ $data[$key] = set_fields_to_property_set($data[$key],$table,false); } $templates=getObjectInfo($table,'System_Config,RecordTemplate'.($single ? ",RecordTemplateFull" : "")); eval($templates['System_Config']); ($glue) ? $tmp='' : $tmp = array(); $block=($templates['RecordTemplateFull']) ? $templates['RecordTemplateFull'] : $templates['RecordTemplate']; $parser = 1; $as_total_row=count($data); $classID=$table; foreach ($data as $item){ $as_object_id=$item['Data_ID']; $as_link = get_section_link($item['Section_ID']).($item['Keyword'] ? $item['Keyword'] : $item['Data_ID']).".html"; if (is_array($item)) { foreach ($item as $key => $value) { eval('$as_'.$key.' = "'.addslashes($value).'";'); } } ($glue) ? eval("\$tmp .= \"$block\";") : eval("\$tmp[] = \"$block\";"); } return $tmp; } function ParseBlock($block,$vars, $to_property_set=0){ if (!$block) return ''; if ($to_property_set) { $as_object_id=$vars['Data_ID']; $as_link = get_section_link($vars['Section_ID']).($vars['Keyword'] ? $vars['Keyword'] : $vars['Data_ID']).".html"; $vars=set_fields_to_property_set($vars,$to_property_set); } if (is_array($vars)) { foreach ($vars as $key => $value) { eval('$as_'.$key.' = "'.addslashes($value).'";'); } } $tmp = ''; eval("\$tmp = \"$block\";"); return $tmp; } function as_insert_page_path($template){ global $as_section_data, $as_section_level, $system_table_fields,$current_site,$current_record; $last=array(); $cr=0; // current record if ($current_record && !$template['no_object']) { $last['Section_Name']=$current_record['Title']; $titlefields=array('address','Question'); // нужно будет ввести у обьектов Title field foreach ($titlefields as $tfield){ if ($current_record[$tfield]){ $last['Section_Name']=$current_record[$tfield]; break; } } if (!$last['Section_Name']) { $last=false;} else {$last['Section_Name'] = cut_words_ru($last['Section_Name'],40); } $last['Keyword'] = ($current_record['Keyword'] ? $current_record['Keyword'] : $current_record['Data_ID']); $cr=1; } $c=0; $sm = ($template['no_main'] ? 1 : 0); // skip main $stop = $sm-$cr; $out = $template['prefix']; for ($i=count($as_section_data)-1-$sm; $i>= -$cr; $i--) { $section = &$as_section_data[$i]; if ($section['Title_Section_ID']){ $name=get_section_fields($section['Title_Section_ID'],'Section_Name'); } else { $name=$section['Section_Name']; } if ($i != -$cr) { $section = &$as_section_data[$i]; ($section['ExternalURL']) ? $url = $section['ExternalURL'] : $url = $section['Hidden_URL']; } else { if (!$section) { if (!$last) return $out; $section=$last; $name=$section['Section_Name']; } if ($section['Hidden_URL']) { $url = $section['Hidden_URL']; } else { $url = $url.$last['Keyword'].'.html'; } } if (!$c && count($as_section_data) !=2 ) { $block="first"; if ($template['main_name_field']) $name=$current_site[$template['main_name_field']]; } elseif ($i == -$cr) $block="last"; else $block="middle"; if (!$template[$block]) $block='middle'; $out .= str_replace( array( "%NAME_LOWER", "%NAME_UPPER", "%NAME", "%URL", "%COUNTER" ), array(strtolower($name), strtoupper($name), $name, $url, $c),$template[$block]); if ($i > -$cr && $template['divider']) $out.=$template['divider']; $c++; } $out .= $template['postfix']; return $out; } /* echo as_insert_global_menu($ancestor,1,array($menu_template[25]),array("mark_real_nested"=> 1, "dont_apply_last_template"=> 1, "branch" => 1)); } */ /* построение многоуровневого меню $ancestor = точка отсчёта $level = кол-во уровней $templates = масив шаблонов $options['dont_apply_last_template'] = при нехватке шаблонов на уровень не использовать пследний в массиве $options['mark_real_nested'] = помечает nested все элементы,у которых есть дочерние $options['branch'] = всскрывает всю текущую ветку */ function as_insert_global_menu($ancestor, $levels, $templates,$options=array(),$level=0){ global $as_admin, $admin_url_prefix,$current_section,$CMS_UPLOAD_PATH; ($options['where'] && !$level ) ? $where=$options['where'] : $where=''; if ($ancestor == 901){ //DebugBreak(); } if ($ancestor === false || $ancestor===''){ if (!$where) return; $levels=1; } //if ($where) DebugBreak(); if (isset($templates[$level])) $template=$templates[$level]; elseif (!$options['dont_apply_last_template']) $template = $templates[count($templates)-1]; else return ''; ($template['sortby']) ? $sort_by = $template['sortby'] : $sort_by = "Priority"; if ($template['icon_transform']) { list($width,$height,$crop)=explode(',',$template['icon_transform']); } $step=(int)$options['step']; if ($where) { $child_nodes= get_child_nodes($ancestor,$where, $sort_by,false); } else { $child_nodes= get_child_nodes($ancestor,$where, $sort_by,$options['checked_only']); } if ($options['add_root'] && !$level) { $arr = array($ancestor =>get_section_fields($ancestor)); foreach ($child_nodes as $key => $val) $arr[$key]=$val; $child_nodes=&$arr; } if (!count($child_nodes) && !$template['force_empty']) return ''; $count = count($child_nodes); $i=1; $buff = ''; ((int)$template['divider_step']) ? $divstep = (int)$template['divider_step'] : $divstep = 1; if ($divparts = (int)$template['divider_parts']){ $divstep=ceil(count($child_nodes)/$divparts); } if (substr_count($template['prefix'],"%NAME")) { $name = get_section_fields($ancestor,'Section_Name'); $prefix = str_replace( array( "%ID", "%NAME_LOWER", "%NAME_UPPER", "%NAME", "%URL"), array( $ancestor, strtolower($name), strtoupper($name),$name,$link = get_section_link($ancestor,$options['absolute_links'])), $template['prefix']); } else $prefix = $template['prefix']; foreach ($child_nodes as $page_id => $page) { $submenu = ''; $icon_block=""; $nested = false; $branch = in_branch($page_id); // ПОДМЕНЮ if ($page_id != $ancestor) { if ($levels && ($level < ($levels-1))) { $submenu=as_insert_global_menu($page_id,$levels,$templates,$options,$level+1); } elseif ($options["branch"] && $branch) { $submenu=as_insert_global_menu($page_id,$levels,$templates,$options,$level+1); } elseif ($options['mark_real_nested']) { if (have_children($page_id)) $nested=true; } else {} } if ($submenu) { $nested=true; $submenu = str_replace("%EMPTY", '', $submenu); } if ($as_admin) { $nav_url = $admin_url_prefix . "?site=" . $current_section["Site_ID"] ."§ion=" . $page["Section_ID"];} else { if ($ext_url = $page["ExternalURL"]) $nav_url = (strchr($ext_url, ":") || substr($ext_url, 0, 1) == "/") ? $ext_url : $page["Hidden_URL"] . $ext_url; else $nav_url = $page["Hidden_URL"]; } if ($options['absolute_links']){ if (!substr_count($nav_url,'http://')) { $nav_url = 'http://'.$_SERVER['HTTP_HOST'].$nav_url; } } $nav_name = $page["Section_Name"]; $t = $i % $divstep; ($template['divider'] && $i<$count && ( $i % $divstep === 0)) ? $divider = $template['divider'] : $divider = ''; ( $_SERVER['REQUEST_URI'] == $page['Hidden_URL']) ? $selected = true :$selected=false; ($nested && isset($template['nested_active']) && isset($template['nested_inactive'])) ? $nested_prefix = 'nested_' : $nested_prefix = ''; $link = false; $section =''; if ($step){ $section =( ($i <= $step) ? "active".($i==$step ? "_link" : "" ) : "inactive" ); } else { $section = $nested_prefix.'active_link'; if ($selected && !isset($template[$section])) { } elseif ($branch) { $section = $nested_prefix.'active'; } else { $section = $nested_prefix.'inactive'; } } ($template['icon_field']) ? $icon_field = $template['icon_field'] : $icon_field='icon'; $icon_state = "icon"; if ( isset($template['icon_active']) && ($section == "active" || $section == "active_link" || $section == "nested_active" )) $icon_state="icon_active"; if ( $page[$icon_field] && $template[$icon_state]) { // image_transform($image,$sizex=0,$sizey=0, $aspect ="",$color=""){ if ($template['icon_transform']) { $icon_url = image_transform($CMS_UPLOAD_PATH.$page[$icon_field],$width,$height, $crop); } elseif ($template['icon_suffix']) { $icon_url = $CMS_UPLOAD_PATH.add_postifix_to_filename(array($page[$icon_field],$template['icon_suffix'])); } else { $icon_url = $CMS_UPLOAD_PATH.$page[$icon_field]; } $icon_block = str_replace( array( "%ICON", "%ID", "%COMMENT", "%NAME_LOWER", "%NAME_UPPER", "%NAME", "%URL", "%COUNTER"), array( $icon_url, $page_id, $page['comment'], strtolower($nav_name), strtoupper($nav_name),$nav_name,$nav_url,$i), $template[$icon_state]); } $result = $template[$section].$divider; $result = str_replace( array( "%COMMENT", "%BASIC", "%ID", "%ICONBLOCK", "%NAME_LOWER", "%NAME_UPPER", "%NAME", "%URL", "%PARENT_SECTION", "%KEYWORD", "%SECTION","%COUNTER", "%SUBMENU", "%COMMENT" ), array( $page['comment'], $page['LinkName'], $page_id, $icon_block,strtolower($nav_name), strtoupper($nav_name), $nav_name, $nav_url, $ancestor, $page['LinkName'], $page["Section_ID"], $i, $submenu, $page['comment']), $result); $buff .= $result; $i++; } ($template['suffix']) ? $suffix = $template['suffix'] : $suffix = ''; ($template['postfix']) ? $postfix = $template['postfix'] : $postfix = ''; $xbuff=$prefix.$buff.$suffix.$postfix; return $xbuff; } function render_multicol_menu($anc, $levels=2, $templates, $divide_by=3, $href=null, $level=0, $divide=true){ global $section_cache, $section_struct,$LinkID,$section_childs_count; $levels=(int)$levels; if ($anc===null || !$levels || !$templates) return; $anc=(int)$anc; $count=recursiveChildCollect($anc,$levels); if (!$count) return; if (!$divide_by) $divide_by = $count; $divide_cnt=ceil($count / $divide_by)-1; if (!$divide_cnt) $divide_cnt=1; $i=0; $c=0; $step=0; if (!$templates[$level]) $template=$template[count($templates)-1]; else $template=$templates[$level]; $out=$template['prefix']; foreach ($section_struct[$anc] as $node) { $i++; $c++; $child_count = getSectionChildrenTotal($node,$levels-1); $i+=$child_count; if ($child_count && $levels) { $sub=render_multicol_menu($node,$levels-1,$templates,$divide_by,$href,$level+1,false); } else { $sub=''; } $page = &$section_cache[$node]; ($page['ExternalURL']) ? $link = $page['ExternalURL'] : $link=$page['Hidden_URL']; $name=$page['Section_Name']; ($link === $href) ? $section = 'active' : $section='inactive'; $item = str_replace(array("%BASIC", "%ID", "%NAME", "%URL", "%COUNTER", "%STEP", "%SUBMENU" ), array($page['LinkName'], $node, $name, $link, $c, $step, $sub), $template[$section]); if ($template['divider'] && $divide && floor($i/$divide_cnt) > $step ) { $step = floor($i/$divide_cnt); $divider = $template['divider']; } else $divider = ''; $out .= $item.$divider; } $out .= $template['postfix']; return $out; } function as_insert_paginator($template, $onpage, $total, $base_href='',$offset=0,$getparams=array(),$pager='curPos'){ $getfunc = 'get_pager_default_template'; if (!$template && function_exists($getfunc)) { $template = $getfunc();} if (!$template || !((int)$onpage)) return ''; if (!$template['template']) $template['template'] = '%PREFIX %PREV %LIST %NEXT %POSTFIX'; unset($getparams['curPos']); $onpage=(int)$onpage; $total=(int)$total; $current=ceil($offset/$onpage); if ( !$onpage || $onpage > $total ) return ''; $params_list=array(); foreach ($getparams as $key => $param) { $params_list[] = $key.'='.urlencode($param); } $params_list = implode('&',$params_list); if(substr_count($base_href,"?")) $base_link = $base_href."&".($params_list ? $params_list : ""); else $base_link = $base_href."?".($params_list ? $params_list."&" : ""); $prev = $current-1; $next=$current+1; $max_pages=ceil($total/$onpage); $first_link = $base_href.($params_list ? "?".$params_list : ""); if ($prev == -1) { $prev_str = str_replace("%URL", "javascript:void(0);", $template['no_prev']); } else { $t = floor($onpage*$prev); ($t ? $t_link = $base_link.$pager."=".$t :$t_link = $first_link ); $prev_str = str_replace("%URL", $t_link, $template['prev']); } if ($next == $max_pages) { $next_str = str_replace("%URL", "javascript:void(0);", $template['no_next']); } else { $next_str = str_replace("%URL", $base_link.$pager."=".(floor($onpage*$next)), $template['next']); } $list = ''; if ($template['near_space']) { $near=(int)$template['near_space']; $near_from = $current - $near; $near_to = $current + $near; } for ($i=0; $i<$max_pages; $i++) { $page = $i+1; if ($near && !($page == 1 || $page== $max_pages)) { if ($page < ($near_from+1)) { if ($page == 2) { $list .= $template['space']; continue; } else continue; } if ($page > $near_to) { if ($page == $near_to+1) { $list .= $template['space']; continue; } else continue; } // DebugBreak(); } ($i ? $link =$base_link.$pager."=".(floor($i*$onpage)) : $link = $first_link); ($current==$i) ? $sect = 'current': $sect='item' ; $list .= str_replace(array('%URL','%NUMBER'),array($link,$page),$template[$sect]); } $out = str_replace( array('%PREFIX','%PREV','%LIST','%NEXT','%POSTFIX'), array($template['prefix'], $prev_str, $list, $next_str,$template['postfix']), $template['template'] ); return $out; //'%PREFIX %PREV %LIST %NEXT %POSTFIX'; } ########################### Objects ############################### /* загружает список обьектов $params['page_id'] = обьекты этой страницы $params['table'] = id обьекта $params['where'] = ''; $params['order'] = ''; $params['limit'] = ''; $params['checked'] = 0|1|all default 1 */ function getObjects($params,$datakeys=false){ static $cache; $page_id = (int)$params['page_id']; if (!$page_id) $page_id=(int)$params['Section_ID']; $id = (int)$params['id']; $table = (int)$params['table']; $where = $params['where']; $order = $params['order']; $limit = $params['limit']; $checked = $params['checked']; $params['datakeys']=$datakeys; $cache_key=md5(serialize($params)); if ($cache[$cache_key] == null) { if ($checked === null) $checked_str=" AND a.`Checked`=1"; elseif ($checked == "all") $checked_str = " "; else $checked_str = " AND a.`Checked`='".$checked."' "; if ($obj_id = (int)$params['object_id']) { $sql_obj_sect = " AND a.`Section_Object_ID` = ".$obj_id; } else $sql_obj_sect=''; if ($page_id) $where .= " AND a.`Section_ID` = '".$page_id."' "; if ($id) { $where .= " AND a.`Data_ID` = '".$id."' "; } if (!$table) { if (!$page_id) return false; $query = "SELECT a.`Section_Object_ID`, a.`Object_ID` FROM `Section_Object` AS a WHERE a.`Section_ID` = '".$page_id."' ".$sql_obj_sect." LIMIT 1;"; if ($r=SQLSelect($query)) { $obj_id = $r[0]['Section_Object_ID']; $table = $r[0]['Object_ID']; } else return false; } $fields = getObjectStruct($table); if ($order) $order = " ORDER BY ".$order; if ($limit) $limit = " LIMIT ".$limit; if($where) { if ($checked_str) { if ( (strtolower(substr(trim($where),0,4)) != "and ")) $where = " AND ".$where; } else { if ($where && (strtolower(substr(trim($where),0,4)) == "and ")) $where = substr($where, 4); } } if ($site_id=(int)$params['site_id']){ $joins = " LEFT JOIN `Section` AS `Section` ON a.`Section_ID` = Section.`Section_ID` "; $join_conds = " AND Section.`Site_ID` = '".$site_id."' "; } //$query = "Select `".implode("`,`",array_keys($fields))."` From `Data".$table."` Where ".$checked_str.$where.$order.$limit; $query = "SELECT ".getObjectStructFieldsQuery($table,'a.')." FROM `Data".$table."` AS a ".$joins." WHERE 1 ".$checked_str.$where.$join_conds.$order.$limit; if ($datakeys){ $cache[$cache_key] = SQLSelect($query,'Data_ID'); } else { $cache[$cache_key] = SQLSelect($query); } } return $cache[$cache_key]; } // Загружает обьект по id function getObject($ids,$table=-1,$fieldname=false){ global $MAIN_PRODUCT_TABLE; static $cache; if ($table==-1) $table=$MAIN_PRODUCT_TABLE; $tmp = array(); $to_upload=array(); $single=false; if (!is_array($ids)) { $ids = array($ids); $single=true;} if (!is_array($cache)) {$cache = array();} if (!is_array($cache[$table])) {$cache[$table] = array();} foreach ($ids as $id) { if ($cache[$table][$id] !== null) { if ($fieldname) { $tmp[$id] = $cache[$table][$id][$fieldname]; } else { $tmp[$id] = $cache[$table][$id]; } } else { $to_upload[]=(int)$id; } } if ($to_upload){ $objs = getObjects(array('table'=> $table, 'where' => " `Data_ID` IN (".implode(',',$to_upload).") ",'checked' => 'all'),true); foreach ($objs as $id =>$val){ $cache[$table][$id]=$val; if ($fieldname) { $tmp[$id]=$val[$fieldname]; } else { $tmp[$id]=$val; } } } if ($single) return current($tmp); return $tmp; } /* Получает инфо о полях обьекта */ function getObjectStruct($object_id,$system_id=0) { global $LinkID; static $cache; if (!is_array($cache)) $cache=array(); $key = $object_id.'_'.$system_id; if ($cache[$key] === null) { $fields=array(); $q = "SELECT `Object_Field_Name`, `TypeOfData_ID`, `Format`, `Description`, `NotNull`, `System_ID` FROM `Object_Field` WHERE 1 AND `System_ID` = '".$system_id."' ".($object_id ? " AND `Object_ID` = '".$object_id."'" : "")." ORDER BY `Priority` ASC ;"; $r = mysql_query($q,$LinkID); if ( mysql_num_rows($r)) { while ($tmp = mysql_fetch_assoc($r)) $fields[$tmp['Object_Field_Name']]=$tmp; $cache[$key]=$fields; } else $cache[$key]=array(); } return $cache[$key]; } function getObjectStructFieldsQuery($object_id,$prefix='',$system_id=0){ static $cache; $key=$object_id.$prefix; if ($cache[$key]) return $cache[$key]; $struct =getObjectStruct($object_id,$system_id); if (!$struct) return; $arr=array($prefix.'`Data_ID`', $prefix.'`Section_ID`', $prefix.'`Section_Object_ID`', $prefix.'`User_ID`', $prefix.'`Checked`', $prefix.'`Keyword`', $prefix.'`Created`'); foreach ($struct as $field){ //if ($field['Object_Field_Name'] == 'Foto1') DebugBreak(); switch ($field['TypeOfData_ID']){ case '6': $fname = $prefix.'`'.$field['Object_Field_Name'].'`'; $name='`'.$field['Object_Field_Name'].'`'; $arr[]="IF(".$fname."<>'',SUBSTRING_INDEX(".$fname.",':',1),'') AS ".$name; break; default : $arr[]=$prefix.'`'.$field['Object_Field_Name'].'`'; break; } } return $cache[$key]=implode(',',$arr); } /* обработка полей обьекта в соответствие с форматом полей */ /* $object = массив параметров для переработки $object_id = id обработчика $clean == 0 обьединяет полученый и орги $clean == 1 выдаёт полученный $clean == 2 заполняет поля обязательные для заполнения */ function set_fields_to_property_set(&$object, $object_id, $clean=1,&$fields=null) { if (!$fields) { $fields = getObjectStruct($object_id); } if (!$fields) {return $false;} $field_names = array_keys($fields); $final_object = array(); foreach ($field_names as $fname) { $type = $fields[$fname]['TypeOfData_ID']; if ($object[$fname] === null) { unset($object[$fname]); continue;} if ($type == 8){ $final_object[$fname]=$object[$fname]; $final_object[$fname.'_timestamp']=$timestamp = strtotime($object[$fname]); $tm = explode('-',date('Y-m-d-H-i',$timestamp)); $final_object[$fname.'_year']=$tm[0]; $final_object[$fname.'_month']=$tm[1]; $final_object[$fname.'_day']=$tm[2]; $final_object[$fname.'_hours']=$tm[3]; $final_object[$fname.'_minutes']=$tm[4]; } if ($type != "6") {$final_object[$fname]=$object[$fname]; continue;} if (!$object[$fname] || $clean == 2) continue; $t=substr($fields[$fname]['Format'],0,13); if ($t != "type=image/*|") {$final_object[$fname]=$object[$fname]; continue;} $t2=substr($fields[$fname]['Format'],13); $types_info=array(); $types=explode("|", $t2); foreach ($types as $type) { $arr=array(); $vals = explode(";", $type); foreach ($vals as $val) { $t=explode("=",$val); $arr[$t[0]]=$t[1]; } if ($arr['postfix']) { $types_info[$arr['postfix']]=$arr; } } $postfixes=array_keys($types_info); $image_props=explode(":",$object[$fname]); $final_object[$fname]="/data/".$image_props[0]; //add_postifix_to_filename foreach ($postfixes as $postfix) { $final_object[$fname.$postfix]="/data/".add_postifix_to_filename(array($image_props[0],$postfix)); } } if ($clean == 1) return $final_object; elseif ($clean ==0) return array_merge($object, $final_object); elseif ($clean==2) { foreach ($field_names as $fname){ if ($fields[$fname]['NotNull'] && !$final_object[$fname]) { if ($fields[$fname]['DefaultState']) { $final_object[$fname]=$fields[$fname]['DefaultState']; continue; } $f = &$fields[$fname]; switch ($f['TypeOfData_ID']){ case '2' : case '4' : case '5' : case '7' : $final_object[$fname]=0; break; case '1' : case '3' : case '6' : $final_object[$fname]=''; break; case '8' : $final_object[$fname]=date('Y-m-d H:i:s'); } } } return $final_object; } } /* обработка полей секций в соответствие форматов полей */ function mass_update_section_fields(&$sections){ static $cache; if (!is_array($cache)) $cache=array(); $sections_keys = array_keys($sections); foreach ($sections_keys as $key) { $sections[$key]=set_fields_to_property_set($sections[$key],0,false); } } function getObjectInfo($table, $fields=''){ static $cache,$fullcache; if (!$table) return; if (!is_array($cache)) $cache=array(); if (!is_array($fullcache)) $fullcache=array(); $table=(int)$table; if (!is_array($cache[$table])) $cache[$table]=array(); if ($fields == '') { if (!$fullcache[$table]) { $query = "SELECT * FROM `Object` WHERE `Object_ID` = '".$table."'"; $fullcache[$table]=SQLSelect($query); } return $fullcache[$table]; } else { if (is_string($fields)) { if (substr_count($fields,'`')){ $query = "SELECT ".$fields." FROM `Object` WHERE `Object_ID` = '".$table."'"; $t=SQLSelectOne($query); return $cache[$table]=array_merge($cache[$table],$t); } $fields=explode(',',$fields); } $select = array(); $tmp = array(); for ($i=0;$i 0, 'Section_Object_ID' => 0, 'Checked' => 1, 'LastSystem_Updated' => $date, 'Created' => $date, 'LastUser_ID' => (int)$_SESSION['user']['User_ID'], 'User_ID' => (int)$_SESSION['user']['User_ID'], 'IP' => $_SERVER['REMOTE_ADDR'], 'Keyword'=>'' ); foreach ($struct as $name =>$field) { if ($field['DefaultState']) { $dataInit[$name]=$field['DefaultState']; continue; } $type=(int)$field['TypeOfData_ID']; switch ($type) { case 1: case 3 : case 6: $dataInit[$name]=''; break; case 8: $dataInit[$name]='0000-00-00 00:00:00'; break; default : $dataInit[$name]=0; } } return $cache[$table]=$dataInit; } function GetSiteByID($id) { static $sites; if (!$sites) $sites=array(); if (!$sites[$id]) $sites[$id] = as_query_array("SELECT * FROM `Site` WHERE `Site_ID` = '".(int)$id."'"); return $sites[$id]; } function get_section_objects($section,$limit=1,$to_propertyset=true, $order = "Priority") { global $LinkID; if (!($section = (int)$section)) return false; ($order) ? $order = ' ORDER BY `'.$order.'` ' : $order = ''; $q = "SELECT `Section_Object_ID`, `Object_ID` FROM `Section_Object` WHERE `Section_ID` = '".$section."' ".$order." LIMIT 1;"; $r = mysql_query($q,$LinkID); if ( mysql_num_rows($r)) { $t = mysql_fetch_row($r); } else return array('failed' => true, 'errcode' => 2); $section_obj_id = $t[0]; $obj_id = $t[1]; $objs=getObjects(array('page_id' => $section,'object_id'=> $section_obj_id, 'limit'=> $limit)); if ($to_propertyset){ for ($i=0; $i < count($objs); $i++) { $objs[$i]= set_fields_to_property_set($objs[$i], $obj_id); } } return $objs; } function get_section_sobjects($section=null,$limit=null){ global $current_section; static $cache; if ($section===null) {$section=$current_section['Section_ID'];} if (!$limit) { if ($cache[$section] !== null) return $cache[$section]; $query = "SELECT `Object_ID`, `Section_Object_ID` as `sid` FROM `Section_Object` WHERE `Section_ID` = '".$section."' ;"; return $cache[$section] = SQLSelect($query,'Object_ID','sid'); } else { $query = "SELECT `Object_ID`, `Section_Object_ID` as `sid` FROM `Section_Object` WHERE `Section_ID` = '".$section."' ".($limit ? " LIMIT ".(int)$limit." " : "").";"; return SQLSelect($query,'Object_ID','sid'); } } function get_section_sibling($section=null){ global $current_section,$section_struct; static $cache; if (!$section) $section=(int)$current_section['Section_ID']; if ($cache[$section] !== null) return $cache[$section]; $anc=get_ancestor($section); if ($section_struct[$anc] === null) { recursiveChildCollect($anc,1,false); } $struct = &$section_struct[$anc]; if (!$struct || !is_array($struct) || count($struct)==1){ return $cache[$section]=false; } $pos=-1; for ($i=0; $i= 0; $ii--) { if ($str[$ii] == ' ' && $f == 0) { $f = 1; $cnt++; } elseif ($str[$ii] != ' ') { $f = 0; } if ($cnt == $cntwords) break; } $ii++; return ($ii > 1 ? substr($str, 0, $ii) . "" . substr($str, $ii)."" : $str); } /* обрезает строку по длине, не разрывая последнее слово, добавляя троеточие */ function cut_words_ru($string, $length, $params = array(), $convert=true) { if (!$params['no_strip_tags']) $string=strip_tags($string); ($params['delim']) ? $delim = $params['delin'] : $delim =' '; ($params['postfix']) ? $postfix = $params['postfix'] : $postfix='...'; if ($convert) $str=strip_tags(iconv("UTF-8", "WINDOWS-1251", $string)); else $str=$string; if ($params['clean']) $str=str_replace(array("\n", " "), array(""," "),$str); if (strlen($str)<=$length) $tmp = $string; else { $tmp = substr($str,0, $length); $pos = strpos($str, $delim, $length); if ($pos !== false) $tmp .= substr($str,$length,$pos-$length).$postfix; else return stripslashes($string); if ($convert) $tmp = iconv("WINDOWS-1251", "UTF-8", $tmp); } if ($lwlink=$params['last_word_link']) { if (!($lwcount = (int)$params['last_word_count'])) $lwcount = 1; $tmp = makelastwordlink($tmp,$lwlink,$lwcount); } return stripslashes($tmp); } function process_comment_message($message,$symbols=600){ $str=iconv('utf-8','windows-1251',$message); $len=strlen($str); if ($len > $symbols) return '

'.cut_words_ru($message,$symbols).'

'; $ps = explode("\n",$message); return '

'.implode('

',$ps).'

'; } // ограничивает длину строки function limit_string_ru($string,$maxlen=64){ return iconv('windows-1251','utf-8',substr(iconv('utf-8','windows-1251',$string),0,$maxlen)); } /* $params[0] = имя файла, $params[1] = добавляемый постфикс */ function add_postifix_to_filename($params){ $pos = strrpos($params[0],'.'); if (!strlen($params[1]) || $pos === false) return $fname; return substr($params[0],0,$pos).$params[1].substr($params[0], $pos); } /* возвращает оформленный размер файла */ function get_human_filesize($size) { $iec = array('б', 'Кб', 'Мб', 'Гб', 'Тб'); $i = 0; while (($size/1024)>1) { $size = $size/1024; $i++; } $iec = $iec[$i]; $size=number_format($size,1,'.',' '); $echo = $size.' '.$iec; return $echo; } /* these are the russian additional format characters q: full textual representation of the day of the week Q: full textual representation of the day of the week (first character is uppercase), v: short textual representation of the day of the week, V: short textual representation of the day of the week (first character is uppercase), H: full textual representation of a month(singlified) X: full textual representation of a month x: full textual representation of a month (first character is uppercase), f: short textual representation of a month F: short textual representation of a month (first character is uppercase), Param[0]= format Val=timestamp echo 'Сегодня '.date_ru('Q, d x Y'); * * */ function date_ru($timestamp,$formatum) { if (!$timestamp) $timestamp=time(); if (!is_numeric($timestamp)) { if (!($timestamp = strtotime($timestamp))) return; } $q['q'] = array(-1 => 'w', 'воскресенье','понедельник', 'вторник', 'среда', 'четверг', 'пятница', 'суббота'); $q['Q'] = array(-1 => 'w', 'Воскресенье','Понедельник', 'Вторник', 'Среда', 'Четверг', 'Пятница', 'Суббота'); $q['v'] = array(-1 => 'w', 'вс','пн', 'вт', 'ср', 'чт', 'пт', 'сб'); $q['V'] = array(-1 => 'w', 'Вс','Пн', 'Вт', 'Ср', 'Чт', 'Пт', 'Сб'); $q['H'] = array(-1 => 'n', '', 'Январь', 'Февраль', 'Март', 'Апрель', 'Май', 'Июнь', 'Июль', 'Август', 'Сентябрь', 'Октябрь', 'Ноябрь', 'Декабрь'); $q['x'] = array(-1 => 'n', '', 'января', 'февраля', 'марта', 'апреля', 'мая', 'июня', 'июля', 'августа', 'сентября', 'октября', 'ноября', 'декабря'); $q['X'] = array(-1 => 'n', '', 'Января', 'Февраля', 'Март', 'Апреля', 'Май', 'Июня', 'Июля', 'Август', 'Сентября', 'Октября', 'Ноября', 'Декабря'); $q['f'] = array(-1 => 'n', '', 'янв', 'фев', 'мар', 'апр', 'май', 'июн', 'июл', 'авг', 'сен', 'окт', 'ноя', 'дек'); $q['F'] = array(-1 => 'n', '', 'Янв', 'Фев', 'Мар', 'Апр', 'Май', 'Июн', 'Июл', 'Авг', 'Сен', 'Окт', 'Ноя', 'Дек'); $temp = ''; $i = 0; while ( (strpos($formatum, 'q', $i) !== FALSE) || (strpos($formatum, 'Q', $i) !== FALSE) || (strpos($formatum, 'v', $i) !== FALSE) || (strpos($formatum, 'V', $i) !== FALSE) || (strpos($formatum, 'x', $i) !== FALSE) || (strpos($formatum, 'X', $i) !== FALSE) || (strpos($formatum, 'f', $i) !== FALSE) || (strpos($formatum, 'F', $i) !== FALSE)||(strpos($formatum, 'H', $i) !== FALSE)) { $ch['q']=strpos($formatum, 'q', $i); $ch['Q']=strpos($formatum, 'Q', $i); $ch['v']=strpos($formatum, 'v', $i); $ch['V']=strpos($formatum, 'V', $i); $ch['H']=strpos($formatum, 'H', $i); $ch['x']=strpos($formatum, 'x', $i); $ch['X']=strpos($formatum, 'X', $i); $ch['f']=strpos($formatum, 'f', $i); $ch['F']=strpos($formatum, 'F', $i); foreach ($ch as $k=>$v) if ($v === FALSE) unset($ch[$k]); $a = min($ch); $temp .= date(substr($formatum, $i, $a-$i), $timestamp) . $q[$formatum[$a]][date($q[$formatum[$a]][-1], $timestamp)]; $i = $a+1; } $temp .= date(substr($formatum, $i), $timestamp); return $temp; } ############################## SEO, services ############################ /* возвращает ключ к гуглокартам к текущему домену */ function get_map_key(){ global $current_site; static $cache; if ($cache !== null) return $cache; $maps=explode(' ',trim($current_site['map_keys'])); $domains=array(); foreach ($maps as $map){ $pos = strpos($map,'='); if (!is_int($pos) || $pos < 3) continue; $str1 = trim(substr($map,0,$pos)); $str2 = trim(substr($map,$pos+1)); $domains[$str1]=$str2; $domains['www.'.$str1]=$str2; } return $cache=$domains[$_SERVER['HTTP_HOST']]; } function get_default_map_points(){ global $current_site,$current_section; static $coords; if ($coords !== null) return $coords; $field=&$current_site['map_coords']; $rcoords=explode("\n",$field); if (!is_array($rcoords) || !count($rcoords)) { return $coords=false; } $coords = array(); foreach ($rcoords as $coord){ $coord = explode(':',$coord); $t = explode(',',$coord[1]); if (!$coord[0] || !$t[0] || !$t[1]) continue; $coords[]=array('Title'=> trim($coord[0]),'x'=>(double)trim($t[0]),'y'=>(double)trim($t[1])); } return $cache=$coords; } function seoConfirm() { global $SEO,$current_record,$current_section,$current_site,$SEO_section_fields; if (!$SEO_section_fields) { $SEO_section_fields = array( 'keywords' => 'SEOKeyword', 'description' => 'SEODescr', 'title' => 'SEOTitle', 'text' => 'SEOtext', 'productTitle' => 'header', 'productTitle2' => 'Title' ); } //if (preg_match('/\.html$/', $_SERVER['HTTP_HOST'], $matches)) { if ($current_record) { $SEO['description']=$current_record[$SEO_section_fields['description']]; $SEO['keywords']=$current_record[$SEO_section_fields['title']]; $SEO['text']=$current_record[$SEO_section_fields['text']]; $SEO['title']=$current_record[$SEO_section_fields['title']]; if (!$SEO['title']) $SEO['title']=$current_record[$SEO_section_fields['productTitle']]; if (!$SEO['title']) $SEO['title']=$current_record[$SEO_section_fields['productTitle2']]; } if (!$SEO['description']) { if ($current_section[$SEO_section_fields['description']]) $SEO['description'] = $current_section[$SEO_section_fields['description']]; else $SEO['description'] = $current_site[$SEO_section_fields['description']]; } if (!$SEO['keywords']) { if ($current_section[$SEO_section_fields['keywords']]) $SEO['keywords'] = $current_section[$SEO_section_fields['keywords']]; else $SEO['keywords'] = $current_site[$SEO_section_fields['keywords']]; } if (!$SEO['title']) { if ($current_section[$SEO_section_fields['title']]) $SEO['title'] = $current_section[$SEO_section_fields['title']]; else $SEO['title'] = $current_site[$SEO_section_fields['title']]; } if (!$SEO['text']) { if ($current_section[$SEO_section_fields['text']]) $SEO['text'] = $current_section[$SEO_section_fields['text']]; else $SEO['text'] = $current_site[$SEO_section_fields['text']]; } $SEO['description']=trim(htmlspecialchars(strip_tags($SEO['description']))); $SEO['keywords']=trim(htmlspecialchars(strip_tags($SEO['keywords']))); $SEO['title']=trim(htmlspecialchars(strip_tags($SEO['title']))); $SEO['text']=trim(htmlspecialchars(strip_tags($SEO['text']))); } function getSEOdescription(){ global $SEO; if (!is_array($SEO)) seoConfirm(); return $SEO['description']; } function getSEOkeywords(){ global $SEO; if (!is_array($SEO)) seoConfirm(); return $SEO['keywords']; } function getSEOtitle(){ global $SEO; if (!is_array($SEO)) seoConfirm(); return $SEO['title']; } function getSEOtext(){ global $SEO; if (!is_array($SEO)) seoConfirm(); return $SEO['text']; } function get_h1(){ global $current_record,$current_section; if ($current_record['Title']) return $current_record['Title']; if ($current_record['header']) return $current_record['header']; if ($current_record['Name']) return $current_record['Name']; return $current_section['Section_Name']; } ################################# ARRAYS ####################################### function array_sort(&$array,$field='Name'){ if (!$field) return; $karr=array(); foreach ($array as $key => $value) { $karr[$key] = $value[$field]; } asort($karr); $arr=array(); foreach ($karr as $key => $value) { $arr[$key]=$array[$key]; } return $arr; } function array_escape(&$obj){ $keys = array_keys($obj); foreach ($keys as $key) { if (is_array($obj[$key])) escape($obj[$key]); else $obj[$key]=mysql_real_escape_string($obj[$key]); } } function array_clean(&$arr){ $keys = array_keys($arr); foreach ($keys as $key) { if ($arr[$key] === null || $arr[$key] === '') unset($arr[$key]); } } ################################### ADMIN ########################### ?>