Contact : [tel]'; $page_data = array(); } else { $page = db_get_row('SELECT * FROM network_pages WHERE subdomain_id=?i AND seo_name=?s LIMIT 1', $subdomain['subdomain_id'], str_replace('.html', '', PATH)); if(!$page) default_page(); } $site_data = json_decode($subdomain['data'], true); if(!$site_data) $site_data = array(); $page = array_merge($site_data, $page); if(PATH != 'terms') { $page_content = get_page_content($page['page_id']); if(!$page_content) { if(PATH) redirect(SCHEME.HOST, 301); } $page_data = $page_content['page_data'] ? $page_content['page_data'] : array(); if($page_content['page_content']) $page_data = array_merge($page_data, $page_content['page_content']); unset($page_content); } $page = array_merge($page, $page_data, db_get_row('SELECT lang FROM networks WHERE network_id=?i', $subdomain['network_id'])); unset($page_data); if(PATH != 'terms') { if(isset($page['merge_with_parent']) AND $page['parent_id']) { $page = array_merge(get_page_content($page['parent_id'], 'page_data'), $page); unset($page['merge_with_parent']); } if($page['parent_id']) { $page['breadcrumb'] = array(); $page['breadcrumb'][] = array('anchor' => $page['anchor'], 'href' => '/'.PATH, 'last' => 1); if(PATH) { $parent = db_get_row('SELECT parent_id, seo_name, anchor FROM network_pages WHERE page_id=?i', $page['parent_id']); while($parent) { $page['breadcrumb'][] = array('anchor' => ($parent['anchor'] ? $parent['anchor'] : ($parent['seo_name'] ? $parent['seo_name'] : ($page['site_brand'] ? $page['site_brand'] : HOST))), 'href' => '/'.$parent['seo_name']); $_parent_id = $parent['parent_id']; $parent = db_get_row('SELECT parent_id, seo_name, anchor FROM network_pages WHERE page_id=?i', $parent['parent_id']); if($parent['parent_id'] == $_parent_id) break;//dani bug } } $page['breadcrumb'] = array_reverse($page['breadcrumb']); } $text_links = $list_links = $table_links = array(); $links = ''; $links = $subdomain['is_banned'] ? '' : db_get_field('SELECT links FROM network_pages_add WHERE page_id=?i LIMIT 1', $page['page_id']); if($links) { $links = json_decode($links, true); foreach($links as $v) { $to_page = db_get_row('SELECT a.seo_name, b.subdomain, b.network_id, b.has_ssl FROM network_pages a JOIN subdomains b ON b.subdomain_id=a.subdomain_id AND b.is_banned=0 WHERE a.page_id=?i', $v['to_id']); $link_params = $v['link_params'] ? $v['link_params'] : array(); $link = array( 'href' => ($to_page['has_ssl'] == 'Y' ? 'https' : 'http').'://'.$to_page['subdomain'].'/'.$to_page['seo_name'], 'anchor' => $v['anchor'], 'anchor_wrap' => array_filter(explode(',', $v['anchor_wrap'])), 'link_params' => $link_params, 'link_type' => $v['link_type'], ); if($v['link_type'] == 'L') { $list_links[] = $link; } elseif($v['link_type'] == 'A') { $table_links[] = $link; } elseif(!empty($link_params['placeholder'])) $text_links[$link_params['placeholder']][] = $link; else $text_links['T'][] = $link; } } unset($links); } $placeholders = holderize($page); $template = db_get_field('SELECT template FROM templates WHERE template_id=?i', $subdomain['template_id']); //$template = file_get_contents('file.html');//temp $articles_per_page = 9;$has_more_articles = 0;$total_pages = 0; $template = preg_replace_callback('#(\{\*.+?\*\})|\{((?:\w|\$|/)[^}]+)\}#s', function($_m) use($page) { static $in_function; if($_m[1]) return '';//comments if(preg_match('#^(\$?\w+)\s+(.+)$#', $_m[2], $m)) { if($m[1] == 'elseif') $m[1] = '} '.$m[1]; switch($m[1]) { case 'use': $params = explode(' ', preg_replace('#\s+#', ' ', $m[2])); return ''; break; case 'block': $params = explode(' ', preg_replace('#\s+#', ' ', $m[2])); $in_function = true; return ''; break; case 'foreach': $m[2] = explode(' ', preg_replace('#\s+#', ' ', $m[2])); $m[2][0] = replace_template_var($m[2][0], $in_function); $m[1] = 'if(!empty('.$m[2][0].')) '.$m[1]; $m[2] = $m[2][0].' as $'.$m[2][1].(isset($m[2][2]) ? ' => $'.$m[2][2] : ''); break; case '} elseif': case 'if': case 'while': $m[2] = replace_template_var($m[2], $in_function); break; default: if(substr($m[1], 0, 1) == '$') return ''; //debug('Regex: '.$m[1].' not implemented'); //debug($m); return '{'.$_m[2].'}'; } return ''; } else { if($_m[2] == 'else') return ''; $first_char = substr($_m[2], 0, 1); if($first_char == '/') { $ob = substr($_m[2], 1); if(!in_array($ob, array('foreach', 'if', 'while', 'block'))) return '{'.$_m[2].'}'; if($ob == 'block') $in_function = false; return ''; } if(strpos($_m[2], '$') !== false OR strpos($_m[2], '(') !== false) { return ''; } if(defined($_m[2])) return ''; return '{'.$_m[2].'}'; } }, $template); //debug($template);exit;//temp ob_start(); @eval('?>'.$template); $content = ob_get_clean(); if($content) { fixit($content); if(!SEONID) http_response_code(200); to_html($content); } exit; function to_html($content) { $path = PATH ? PATH : 'index.html'; $dir = ''; $dirs = explode('/', $path); array_pop($dirs); foreach($dirs as $_dir) { $dir .= ($dir ? '/' : '').$_dir; if(!is_dir($dir)) mkdir($dir); } file_put_contents($path, $content); echo $content; exit; } function default_page() { global $photoho_hosts; if(0 AND in_array(HOST, $photoho_hosts)) {//temp photogo, temp 0 $path = PATH ? PATH : 'index.html'; if(file_exists('websites/'.HOST.'/'.$path) AND $c = file_get_contents('websites/'.HOST.'/'.$path)) { } elseif($c = @file_get_contents(MASTER_HOST.'websites/'.HOST.'/'.$path)) { $dir = ''; $dirs = explode('/', 'websites/'.HOST.'/'.$path); array_pop($dirs); foreach($dirs as $_dir) { $dir .= ($dir ? '/' : '').$_dir; if(!is_dir($dir)) mkdir($dir); } file_put_contents('websites/'.HOST.'/'.$path, $c); } if($c) { if(!SEONID) http_response_code(200); header('Content-Type: text/html'); exit($c); } } if(PATH) redirect(SCHEME.HOST, 301); if(!SEONID) http_response_code(200); exit(@file_get_contents('index.html_default')); } //function get_county_name($county_id) { // return db_get_field('SELECT county FROM geo_counties WHERE county_id=?i', $county_id); //} function count_level($branch, $level, $g = array()) { global $subdomain; $condition = db_quote('subdomain_id=?i AND branch=?s AND level=?i', $subdomain['subdomain_id'], $branch, $level); if($level > 1) { foreach($g as $k => $v) { if($v) $condition .= db_quote(' AND ?p=?i', 'g'.($k+1), $v); } } $condition .= db_quote(' AND ?p<>0', 'g'.$level); //debug($condition); return db_get_field('SELECT COUNT(*) FROM network_pages WHERE ?p', $condition); } /*function get_branches() { global $subdomain; return db_get_array('SELECT * FROM network_pages WHERE subdomain_id=?i AND branch<>?s AND level=1 AND g1=0 ORDER BY gravity DESC', $subdomain['subdomain_id'], ''); }*/ function get_index($branch, $level = 0, $g = array()) { global $subdomain; $condition = db_quote('subdomain_id=?i AND branch=?s AND level=?i', $subdomain['subdomain_id'], $branch, $level); if($level > 0 AND $g) { foreach($g as $k => $v) { if($v) $condition .= db_quote(' AND ?p=?i', 'g'.($k+1), $v); } } $condition .= db_quote(' AND ?p=0', 'g'.($level+1)); return db_get_row('SELECT * FROM network_pages WHERE ?p LIMIT 1', $condition); } function get_branch_pages($branch, $level, $g = array(), $limit = 20, $exclude = false, $check_next_level = false) { global $subdomain, $pagination, $total_pages; //$level = count($g)+1; $condition = db_quote('subdomain_id=?i AND branch=?s AND level=?i', $subdomain['subdomain_id'], $branch, $level); if($level > 0 AND $g) { foreach($g as $k => $v) { if($v) { if(is_array($v)) { $ag = explode(',', current($v)); $v = key($v); if($v) { $condition .= db_quote(' AND (?p=?i', 'g'.($k+1), $v); foreach($ag as $i) $condition .= db_quote(' OR ?p=?i', 'g'.$i, $v); $condition .= ')'; //debug($condition); //exit; } } else $condition .= db_quote(' AND ?p=?i', 'g'.($k+1), $v); } } } $condition .= db_quote(' AND ?p<>0', 'g'.$level); if($exclude) { $condition .= db_quote(' AND ?p<>?i', 'g'.$level, $exclude); //todo: order by ... } //debug($condition); $pages = db_get_array('SELECT SQL_CALC_FOUND_ROWS * FROM network_pages WHERE ?p ORDER BY gravity DESC, modified DESC ?p', $condition, $limit ? 'LIMIT '.(($pagination-1)*$limit).','.$limit : ''); if($limit) { $total = db_get_field('SELECT FOUND_ROWS()'); $total_pages = ceil($total/$limit); } if($check_next_level) { foreach($pages as &$v) { $_condition = str_replace(array(' level='.$level.' ', ' g'.$level.'<>0'), array(' level='.($level+1).' ', ' g'.($level+1).'='.$v['g'.($level+1)].' AND g'.($level+2).'<>0'), $condition); $next_level = db_get_row('SELECT SQL_CALC_FOUND_ROWS * FROM network_pages WHERE ?p LIMIT 1', $_condition); $total = db_get_field('SELECT FOUND_ROWS()'); if($total == 1) $v = $next_level; } unset($v); } foreach($pages as &$v) { $v = array_merge($v, get_page_content($v['page_id'], 'page_data')); } unset($v); return $pages; } function get_submenu($page_id, $limit = 50, $get_subpages = true) {//temp old global $subdomain; if($subdomain['is_banned']) return array(); if($limit < 1) $limit = 50; $subpages = db_get_array('SELECT page_id, seo_name, anchor, level FROM network_pages WHERE parent_id=?i ORDER BY gravity DESC, RAND() LIMIT ?i', $page_id, $limit); if(!$get_subpages) return $subpages; $c = count($subpages); if($c < $limit) { $limit -= $c; $limit = ceil($limit/$c); $_subpages = $subpages; $subpages = array(); foreach($_subpages as $v) { $subpages[] = $v; $subpages = array_merge($subpages, get_submenu($v['page_id'], $limit, false)); } } return $subpages; } function get_articles($page_id, $key, $page = 1) {//temp old global $articles_per_page, $has_more_articles, $subdomain; if($subdomain['is_banned']) return array(); if($page < 1) $page = 1; $childs = db_get_array('SELECT SQL_CALC_FOUND_ROWS seo_name, anchor, page_id FROM network_pages WHERE parent_id=?i ORDER BY gravity DESC, page_id LIMIT '.(($page-1)*$articles_per_page).','.$articles_per_page, $page_id); $total_articles = db_get_field('SELECT FOUND_ROWS()'); $has_more_articles = ($total_articles > $page*$articles_per_page); $articles = array(); foreach($childs as $v) { $_data = get_page_content($v['page_id'], 'page_content'); if(isset($_data[0])) {//temp dani fucked $article = $_data[array_rand($_data)]; $article['seo_name'] = $v['seo_name']; $article['anchor'] = $v['anchor']; $articles[] = $article; } else if(!empty($_data[$key])) { $article = $_data[$key][array_rand($_data[$key])]; if(isset($article[0])) $article = $article[array_rand($article)]; $article['seo_name'] = $v['seo_name']; $article['anchor'] = $v['anchor']; $articles[] = $article; } } return $articles; } function get_page_content($page_id, $only_field = '') { static $ips; if(!$page_id) return array(); $droplet_id = db_get_field('SELECT droplet_id FROM network_pages WHERE page_id=?i', $page_id); if(!$droplet_id) return array(); if(!$ips) $ips = array(); if(!isset($ips[$droplet_id])) $ips[$droplet_id] = db_get_field('SELECT ip_address FROM droplets WHERE droplet_id=?i LIMIT 1', $droplet_id); $ip = $ips[$droplet_id]; if(!$ip) return array(); db_select_db('network_pages', $ip); if($only_field) $page_data = db_get_field('SELECT '.$only_field.' FROM `pages` WHERE page_id=?i LIMIT 1', $page_id); else $page_data = db_get_row('SELECT page_data, page_content FROM `pages` WHERE page_id=?i LIMIT 1', $page_id); db_select_db(); if(!$page_data) return array(); if($only_field) { fixit($page_data); return ($page_data ? json_decode($page_data, true) : array()); } $page_data['page_data'] = $page_data['page_data'] ? json_decode($page_data['page_data'], true) : array(); $page_data['page_content'] = $page_data['page_content'] ? json_decode($page_data['page_content'], true) : array(); if(!is_array($page_data['page_content'])) $page_data['page_content'] = array(); fixit($page_data); return $page_data; } function fixit(&$v) {//todo: fix and remove this if(!$v) return; if(is_array($v)) { foreach($v as &$s) fixit($s); } else { $fuckedup = array('À' => 'À', 'Ã' => 'Á', 'Â' => 'Â', 'Ã' => 'Ã', 'Ä' => 'Ä', 'Ã…' => 'Å', 'Æ' => 'Æ', 'Ç' => 'Ç', 'È' => 'È', 'É' => 'É', 'Ê' => 'Ê', 'Ë' => 'Ë', 'ÃŒ' => 'Ì', 'Ã' => 'Í', 'ÃŽ' => 'Î', 'Ã' => 'Ï', 'Ã' => 'Ð', 'Ñ' => 'Ñ', 'Ã’' => 'Ò', 'Ó' => 'Ó', 'Ô' => 'Ô', 'Õ' => 'Õ', 'Ö' => 'Ö', '×' => '×', 'Ø' => 'Ø', 'Ù' => 'Ù', 'Ú' => 'Ú', 'Û' => 'Û', 'Ãœ' => 'Ü', 'Ã' => 'Ý', 'Þ' => 'Þ', 'ß' => 'ß', 'Ã' => 'à', 'á' => 'á', 'â' => 'â', 'ã' => 'ã', 'ä' => 'ä', 'Ã¥' => 'å', 'æ' => 'æ', 'ç' => 'ç', 'è' => 'è', 'é' => 'é', 'ê' => 'ê', 'ë' => 'ë', 'ì' => 'ì', 'í' => 'í', 'î' => 'î', 'ï' => 'ï', 'ð' => 'ð', 'ñ' => 'ñ', 'ò' => 'ò', 'ó' => 'ó', 'ô' => 'ô', 'õ' => 'õ', 'ö' => 'ö', '÷' => '÷', 'ø' => 'ø', 'ù' => 'ù', 'ú' => 'ú', 'û' => 'û', 'ü' => 'ü', 'ý' => 'ý', 'þ' => 'þ', 'ÿ' => 'ÿ', '€' => '€ ', '‚' => '‚ ', 'Æ’' => 'ƒ ', '„' => '„ ', '…' => '… ', 'â€' => '† ', '‡' => '‡ ', 'ˆ' => 'ˆ ', '‰' => '‰ ', 'Å' => 'Š ', '‹' => '‹ ', 'Å’' => 'Œ ', 'Ž' => 'Ž ', '‘' => '‘ ', '’' => '’ ', '“' => '“ ', 'â€' => '” ', '•' => '• ', '–' => '– ', '—' => '— ', 'Ëœ' => '˜ ', 'â„¢' => '™ ', 'Å¡' => 'š ', '›' => '› ', 'Å“' => 'œ ', 'ž' => 'ž ', 'Ÿ' => 'Ÿ ', 'Â' => ' ', '¡' => '¡ ', '¢' => '¢ ', '£' => '£ ', '¤' => '¤ ', 'Â¥' => '¥ ', '¦' => '¦ ', '§' => '§ ', '¨' => '¨ ', '©' => '© ', 'ª' => 'ª ', '«' => '« ', '¬' => '¬ ', '­' => ' ', '®' => '® ', '¯' => '¯ ', '°' => '° ', '±' => '± ', '²' => '² ', '³' => '³ ', '´' => '´ ', 'µ' => 'µ ', '¶' => '¶ ', '·' => '· ', '¸' => '¸ ', '¹' => '¹ ', 'º' => 'º ', '»' => '» ', '¼' => '¼ ', '½' => '½ ', '¾' => '¾ ', '¿' => '¿' ); if(preg_match('/'.implode('|', array_keys($fuckedup)).'/', $v)) $v = strtr($v, $fuckedup); } } function translit($str) { return strtr($str, array( 'Š'=>'S', 'š'=>'s', 'Ð'=>'Dj','Ž'=>'Z', 'ž'=>'z', 'À'=>'A', 'Á'=>'A', 'Â'=>'A', 'Ã'=>'A', 'Ä'=>'A', 'Å'=>'A', 'Æ'=>'A', 'Ç'=>'C', 'È'=>'E', 'É'=>'E', 'Ê'=>'E', 'Ë'=>'E', 'Ì'=>'I', 'Í'=>'I', 'Î'=>'I', 'Ï'=>'I', 'Ñ'=>'N', 'Ń'=>'N', 'Ò'=>'O', 'Ó'=>'O', 'Ô'=>'O', 'Õ'=>'O', 'Ö'=>'O', 'Ø'=>'O', 'Ù'=>'U', 'Ú'=>'U', 'Û'=>'U', 'Ü'=>'U', 'Ý'=>'Y', 'Þ'=>'B', 'ß'=>'Ss','à'=>'a', 'á'=>'a', 'â'=>'a', 'ã'=>'a', 'ä'=>'a', 'å'=>'a', 'æ'=>'a', 'ç'=>'c', 'è'=>'e', 'é'=>'e', 'ê'=>'e', 'ë'=>'e', 'ì'=>'i', 'í'=>'i', 'î'=>'i', 'ï'=>'i', 'ð'=>'o', 'ñ'=>'n', 'ń'=>'n', 'ò'=>'o', 'ó'=>'o', 'ô'=>'o', 'õ'=>'o', 'ö'=>'o', 'ø'=>'o', 'ù'=>'u', 'ú'=>'u', 'û'=>'u', 'ü'=>'u', 'ý'=>'y', 'ý'=>'y', 'þ'=>'b', 'ÿ'=>'y', 'ƒ'=>'f', 'ă'=>'a', 'î'=>'i', 'â'=>'a', 'ş'=>'s', 'ș'=>'s', 'ţ'=>'t', 'ț'=>'t', 'Ă'=>'A', 'Î'=>'I', 'Â'=>'A', 'Ş'=>'S', 'Ș'=>'S', 'Ţ'=>'T', 'Ț'=>'T', )); } function seo_name($str, $delimiter = '-') { $str = strtolower(translit($str)); $str = preg_replace('/[^a-z\p{L}0-9]+/ui', $delimiter, $str); $str = preg_replace('#('.$delimiter.'){2,}#', $delimiter, $str); return trim($str, '-'); } //function get_rand($arr) { // if(!$arr) return false; // return $arr[array_rand($arr)]; //} function express() { static $express; if(!$express) $express = db_get_fields('SELECT express FROM express'); return $express[array_rand($express)]; } function inject_link($description, $placeholder = 'T', $loop_key = false) { global $text_links, $subdomain; if($loop_key !== false) $placeholder .= ':'.$loop_key; if(!$text_links) return $description; if($placeholder != 'T' AND empty($text_links[$placeholder])) $placeholder = 'T'; if(empty($text_links[$placeholder])) return $description; $link = array_pop($text_links[$placeholder]); if($link['link_type'] == 'I') $link['anchor'] = ''.$link['anchor'].''; foreach($link['anchor_wrap'] as $tag) $link['anchor'] = '<'.$tag.'>'.$link['anchor'].''; $link = (empty($link['link_params']['prefix']) ? '' : $link['link_params']['prefix'].' ').''.$link['anchor'].''.(empty($link['link_params']['suffix']) ? '' : ' '.$link['link_params']['suffix']); $desc = explode(' ', $description); $rand = array_rand($desc); if($rand == 0) $rand = array_rand($desc); $desc = array_merge(array_slice($desc, 0, $rand), array($link), array_slice($desc, $rand)); return implode(' ', $desc); } function parse_var($content, $echo = true, $in_function = false) { $content = replace_template_var($content, $in_function); if(strpos($content, ' ') !== false) { $_content = explode(' ', $content); if($f = array_pop($_content) AND function_exists($f)) {//todo: while? return ' echo '.$f.'('.implode(' ', $_content).')'; } } //debug($content); return (($echo AND strpos($content, '=') === false) ? 'echo ' : '').$content; } function replace_template_var($content, $in_function = false) { global $page; return preg_replace_callback('#\$(\w+)(?:\.(\w+))?(?:\.(\w+))?#', function($n) use($page, $in_function) { $var = ($in_function ? '' : '@').'$'.$n[1]; if(!$in_function AND isset($page[$n[1]])) $var = '@$page[\''.$n[1].'\']'; if(isset($n[2])) $var .= '[\''.$n[2].'\']'; if(isset($n[3])) $var .= '[\''.$n[3].'\']'; return $var; }, $content); } function apply_holders($var) { global $placeholders; if($placeholders) $var = strtr($var, $placeholders); $var = preg_replace('#\[.+?\]#', '', $var); return $var; } function holderize($arr) { if(!is_array($arr)) return $arr; $holders = array(); foreach($arr as $k => $v) { if(is_array($v)) foreach($v as $_k => $_v) { if(is_array($_v)) { foreach($_v as $__k => $__v) { if(is_array($__v)) continue; $holders['['.$k.'.'.$_k.'.'.$__k.']'] = ucfirst($__v); } } else $holders['['.$k.'.'.$_k.']'] = ucfirst($_v); } else $holders['['.$k.']'] = ucfirst($v); } return $holders; } function debug($var, $skip_entities = false) { if(!SEONID) return; if($skip_entities) echo '
'.print_r($var, true).'
'; else echo '
'.htmlentities(print_r($var, true)).'
'; } function redirect($url, $code = 302) { if(headers_sent()) { echo ''; debug('Redirecting to '.$url.'', true); } else { http_response_code($code); if($code == 301) header('HTTP/1.1 301 Moved Permanently'); header('Location: '.$url, $code); } exit; } function not_found() { http_response_code(404); echo @file_get_contents('error/404.html');exit; }