<?php 


/** 
***************************************************
*欢迎使用免费版SiteTeam企业建站软件！
*这是一个专业为搜索引擎营销而设计的，极稳定、极易维护的建站软件！
*官方客服：help@php.net.cn
*官方下载网址：http://www.SiteTeam.cn 
***************************************************
**/




if(!defined('IN_SITETEAM')) { exit('Access Denied'); } function dynamic_form($array) { global $site_url; $formstr = ''; if (is_array($array) && count($array) > 0) foreach ($array as $k => $v) { if (!array_key_exists('type', $v)) continue; $style_name = (!empty($v['name'])) ? "<div class='style1'>{$v['name']}：</div>" : ''; $style_length = (!empty($v['length'])) ? $v['length'] : 255; $style_class = (!empty($v['class'])) ? "class='{$v['class']}'" : ''; $style_value = (!empty($v['value'])) ? str_replace(array("'", '"'), array("&#039;", "&quot;") , ($v['value'])) : ''; $style_description = (!empty($v['description'])) ? "<span class='style2'>{$v['description']}</span>" : ''; $style_editor = array_key_exists("editor", $v) ? $v['editor'] : ''; if ($v['type'] == "varchar" || $v['type'] == "char" || $v['type'] == "int") { if ($style_length > 255) { if ($style_editor) { } $formstr .= "\n<li id='form_{$k}'>{$style_name}<label><textarea name='data[{$k}]' {$style_class} id='{$k}'/>{$style_value}</textarea></label>{$style_description}</li>"; } else { $formstr .= "\n<li id='form_{$k}'>{$style_name}<label><input name='data[{$k}]' {$style_class} type='text' id='{$k}' value='{$style_value}' /></label>{$style_description}</li>"; } } if ($v['type'] == "images" || $v['type'] == "file") { $formstr .= "\n<li id='form_{$k}'>{$style_name}<label><input name='{$k}' {$style_class} type='file' id='{$k}' value='' /></label><input name='data[{$k}]' id='hidden_{$k}' type='hidden' value='{$style_value}' />" . ((!empty($style_value)) ? "<span><b><a target='_blank' href='http://{$site_url}" . SITE_PATH . "/{$style_value}'>查看旧文件</a></b></span>" : '') . "{$style_description}</li>"; } } return $formstr; } function update_article_index($category) { global $site_id, $user_article_dir; $category_dir = $user_article_dir . "/{$category}"; if (!file_exists($category_dir)) { return false; } $db = new txtSQL('./data/siteteam'); $db->connect('root', 'siteteam'); $article_list = array(); if ($handle = opendir($category_dir)) { while (false !== ($file = readdir($handle))) { if ($file != "." && $file != "..") { $key = substr($file, 0, -4); if (file_exists("{$category_dir}/{$file}")) { $article_list[$key] = read_array_file("{$category_dir}/{$file}"); $article_list[$key]['key'] = $key; } } } closedir($handle); if (is_array($article_list) && count($article_list)) { ksort($article_list); foreach ($article_list as $key => $v) { $article_info = $v; $row = $db->execute('select', array('db' => dbname($site_id), 'select' => array('key'), 'table' => 'sm_article', 'where' => array("key = {$key}", 'and', "category = {$category}"), 'limit' => array(0))); $data = array(); if (count($row)) { $data['category'] = $category; $data['body_name'] = (!empty($article_info['body_name']) ? $article_info['body_name'] : ''); $data['body_title'] = (!empty($article_info['body_title']) ? $article_info['body_title'] : ''); $data['status'] = (!empty($article_info['status']) ? $article_info['status'] : '1'); $data['is_first'] = (!empty($article_info['is_first']) ? $article_info['is_first'] : '1'); $db->update(array('db' => dbname($site_id), 'table' => 'sm_article', 'values' => $data, 'where' => array("key = {$key}", 'and', "category = {$category}"), 'limit' => array(0))); } else { $data['key'] = $key; $data['category'] = $category; $data['body_name'] = (!empty($article_info['body_name']) ? $article_info['body_name'] : ''); $data['body_title'] = (!empty($article_info['body_title']) ? $article_info['body_title'] : ''); $data['status'] = (!empty($article_info['status']) ? $article_info['status'] : '1'); $data['is_first'] = (!empty($article_info['is_first']) ? $article_info['is_first'] : '1'); $db->insert(array('db' => dbname($site_id), 'table' => 'sm_article', 'values' => $data)); } } } $list = $db->execute('select', array('db' => dbname($site_id), 'select' => array('key'), 'table' => 'sm_article', 'where' => array("category = {$category}"))); if (is_array($list) && count($list)) { foreach ($list as $k => $v) { if (array_key_exists($v['key'], $article_list)) { continue; } if (!file_exists("{$category_dir}/{$v['key']}.txt")) { $db->execute("delete", array('db' => dbname($site_id), 'table' => 'sm_article', 'where' => array("key = {$v['key']}", 'and', "category = {$category}"), 'limit' => array(1))); } } } $db->disconnect(); return true; } else { $db->disconnect(); return false; } } function delete_article_index($category) { global $site_id, $user_article_dir; $db = new txtSQL('./data/siteteam'); $db->connect('root', 'siteteam'); $list = $db->execute('select', array('db' => dbname($site_id), 'select' => array('key'), 'table' => 'sm_article', 'where' => array("category = {$category}"))); if (is_array($list) && count($list)) { foreach ($list as $k => $v) { if (!file_exists("{$user_article_dir}/{$category}/{$v['key']}.txt")) { $db->execute("delete", array('db' => dbname($site_id), 'table' => 'sm_article', 'where' => array("key = {$v['key']}", 'and', "category = {$category}"), 'limit' => array(1))); } } } $db->disconnect(); return true; } function update_article_all_index() { return true; } function update_product_index($category) { global $site_id,$user_product_dir; $category_dir = $user_product_dir . "/{$category}"; if (!file_exists($category_dir)) { return false; } $db = new txtSQL('./data/siteteam'); $db->connect('root', 'siteteam'); $product_list = array(); if ($handle = opendir($category_dir)) { while (false !== ($file = readdir($handle))) { if ($file != "." && $file != "..") { $key = substr($file, 0, -4); if (file_exists("{$category_dir}/{$file}")) { $product_list[$key] = read_array_file("{$category_dir}/{$file}"); } } } closedir($handle); if (is_array($product_list) && count($product_list)) { ksort($product_list); foreach ($product_list as $key => $v) { $product_info = $v; $row = $db->execute('select', array('db' => dbname($site_id), 'select' => array('key'), 'table' => 'sm_product', 'where' => array("key = {$key}", 'and', "category = {$category}"), 'limit' => array(0))); $data = array(); if (count($row)) { $data['category'] = $category; $data['name'] = (!empty($product_info['name']) ? $product_info['name'] : ''); $data['ptitle'] = (!empty($product_info['ptitle']) ? $product_info['ptitle'] : ''); $data['pname'] = (!empty($product_info['pname']) ? $product_info['pname'] : ''); $data['pass'] = (!empty($product_info['pass']) ? $product_info['pass'] : '4'); $data['status'] = (!empty($product_info['status']) ? $product_info['status'] : '1'); $db->update(array('db' => dbname($site_id), 'table' => 'sm_product', 'values' => $data, 'where' => array("key = {$key}", 'and', "category = {$category}"), 'limit' => array(0))); } else { $data['key'] = $key; $data['category'] = $category; $data['name'] = (!empty($product_info['name']) ? $product_info['name'] : ''); $data['ptitle'] = (!empty($product_info['ptitle']) ? $product_info['ptitle'] : ''); $data['pname'] = (!empty($product_info['pname']) ? $product_info['pname'] : ''); $data['pass'] = (!empty($product_info['pass']) ? $product_info['pass'] : '4'); $data['status'] = (!empty($product_info['status']) ? $product_info['status'] : '1'); $db->insert(array('db' => dbname($site_id), 'table' => 'sm_product', 'values' => $data)); } } } $list = $db->execute('select', array('db' => dbname($site_id), 'select' => array('key'), 'table' => 'sm_product', 'where' => array("category = {$category}"))); if (is_array($list) && count($list)) { foreach ($list as $k => $v) { if (array_key_exists($v['key'], $product_list)) { continue; } if (!file_exists("{$category_dir}/{$v['key']}.txt")) { $db->execute("delete", array('db' => dbname($site_id), 'table' => 'sm_product', 'where' => array("key = {$v['key']}", 'and', "category = {$category}"), 'limit' => array(1))); } } } $db->disconnect(); return true; } else { $db->disconnect(); return false; } } function delete_product_index($category) { global $site_id,$user_product_dir; $db = new txtSQL('./data/siteteam'); $db->connect('root', 'siteteam'); $list = $db->execute('select', array('db' => dbname($site_id), 'select' => array('key'), 'table' => 'sm_product', 'where' => array("category = {$category}"))); if (is_array($list) && count($list)) { foreach ($list as $k => $v) { if (!file_exists("{$category_dir}/{$v['key']}.txt")) { $db->execute("delete", array('db' => dbname($site_id), 'table' => 'sm_product', 'where' => array("key = {$v['key']}", 'and', "category = {$category}"), 'limit' => array(1))); } } } $db->disconnect(); return true; } function update_product_all_index() { return true; } function check_db_structure($site_id) { $site_id = dbname($site_id); if (empty($site_id)) { return false; } $db = new txtSQL('./data/siteteam'); if ($db->connect('root', 'siteteam')){ if (!$db->db_exists(dbname($site_id))) { $db->createdb(array("db" => dbname($site_id))); } if (!$db->table_exists('sm_article', dbname($site_id))) { $columns = array('key' => array('type' => 'int', 'permanent' => 1), 'category' => array('type' => 'string', 'max' => 32), 'body_name' => array('type' => 'string', 'max' => 100), 'body_title' => array('type' => 'string', 'max' => 100), 'status' => array('type' => 'int', 'max' => 9), 'is_first' => array('type' => 'int', 'max' => 9)); $db->createtable(array('db' => dbname($site_id), 'table' => 'sm_article', 'columns' => $columns)); } if (!$db->table_exists('sm_product', dbname($site_id))) { $columns = array('key' => array('type' => 'int', 'permanent' => 1), 'category' => array('type' => 'string', 'max' => 32), 'name' => array('type' => 'string', 'max' => 100), 'ptitle' => array('type' => 'string', 'max' => 100), 'pname' => array('type' => 'string', 'max' => 100), 'pass' => array('type' => 'int', 'max' => 9), 'status' => array('type' => 'int', 'max' => 9)); $db->createtable(array('db' => dbname($site_id), 'table' => 'sm_product', 'columns' => $columns)); } $db->disconnect(); return true; } else { return false; } } function keywords_internal_parse() { global $site_id, $user_product_index_file, $user_article_index_file, $site_url, $site_title, $site_keywords,$site_product_url; $separator = array(",", "，", ".", "。", "?", "？", ":", "：", ";", "；", '、', "!", "！", "|", " ", "-", "_", "/", "\\", "【", "】"); $words_internal_data = array(); $settingfile = SITE_ROOT . "/data/setting/{$site_url}/keywords.setting.txt"; if (file_exists($settingfile)) { $keywords_setting = read_array_file($settingfile); $temp = $keywords_setting['base_words']; if (strlen($keywords_setting['words_data']) >= 4) { $tmp = explode(",", str_replace($separator, "," , $keywords_setting['words_data'])); foreach ($tmp as $k => $v) { if (!empty($tmp[$k])) { $words_internal_data[trim($tmp[$k])][] = "/"; } } } } else { $temp = "{$site_title},{$site_keywords}"; } $base_keywords = explode(",", str_replace($separator, "," , $temp)); foreach ($base_keywords as $k => $v) { if (empty($base_keywords[$k])) { unset($base_keywords[$k]); } } $db = new txtSQL('./data/siteteam'); $db->connect("root", "siteteam"); $product_list = $db->execute("select", array('db' => dbname($site_id), 'select' => array('key', 'category'), 'table' => 'sm_product')); if (is_array($product_list) && count($product_list)) { foreach ($product_list as $k => $v) { $product_info_file = SITE_ROOT . "/data/setting/{$site_url}/product/{$v['category']}/{$v['key']}.txt"; if (file_exists($product_info_file)) { $product_info = read_array_file($product_info_file); if (!empty($product_info['seo_keywords']) || !empty($product_info['keywords'])) { $temp = explode(",", str_replace($separator, "," , strtolower("{$product_info['seo_keywords']},{$product_info['keywords']}"))); $temp = array_unique($temp); if (is_array($temp) && count($temp)) { foreach ($temp as $words) { if (strlen($words) > 20 || empty($words)) { continue; } foreach ($base_keywords as $filter) { if (preg_match("/" . preg_quote($filter, "/") . "/i", $words)) { $url = "/?{$site_product_url}/{$v['category']}/{$v['key']}.html"; $words_internal_data[$words][] = url_rewrite($url, $type = ''); break; } } } } } } } } $article_list = $db->execute("select", array('db' => dbname($site_id), 'select' => array('key', 'category'), 'table' => 'sm_article')); if (is_array($article_list) && count($article_list)) { foreach ($article_list as $k => $v) { $article_info_file = SITE_ROOT . "/data/setting/{$site_url}/article/{$v['category']}/{$v['key']}.txt"; if (file_exists($article_info_file)) { $article_info = read_array_file($article_info_file); if (!empty($article_info['seo_keywords'])) { $temp = explode(",", str_replace($separator, "," , strtolower($article_info['seo_keywords']))); $temp = array_unique($temp); if (is_array($temp) && count($temp)) { foreach ($temp as $words) { if (strlen($words) > 20 || empty($words)) { continue; } foreach ($base_keywords as $filter) { if (preg_match("/" . preg_quote($filter, "/") . "/i", $words)) { $url = "/?{$v['category']}/{$v['key']}.html"; $words_internal_data[$words][] = url_rewrite($url, $type = ''); break; } } } } } } } } $db->disconnect(); if (is_array($words_internal_data) && count($words_internal_data)) { foreach ($words_internal_data as $k => $v) { if (count($v) < 1) { unset($words_internal_data[$k]); continue; } $words_internal_data[$k] = array_unique($v); } } return $words_internal_data; } function keywords_update_internal_link($content) { global $words_internal_data; $content = preg_replace('/\<a rel="INTERNAL_LINK"[^>]+\>([^<]+)\<\/a\>/is', '$1', $content); global $_TEMP_replace, $_TEMP_index; $_TEMP_replace = array(); $_TEMP_index = 0; $a = create_function('$match', 'global $_TEMP_replace, $_TEMP_index; 
									$_TEMP_index++; 
									$key=str_num2char(sprintf("%08d", $_TEMP_index)); 
									$_TEMP_replace[$key]=$match[0];
									return "<--{$key}-->"; '); $content = preg_replace_callback('/\<a[^>]+\>(.*)\<\/a\>/Uis', $a, $content); if (is_array($words_internal_data) && count($words_internal_data)) { foreach ($words_internal_data as $k => $v) { if (count($words_internal_data[$k]) < 1) { unset($GLOBALS['words_internal_data'][$k]); } } if (count($words_internal_data) > 0) { $content = preg_replace_callback('/\>([^<>]+)\</Uis', 'keywords_text_internal_parse', $content); } } if (is_array($_TEMP_replace) && count($_TEMP_replace)) { foreach ($_TEMP_replace as $key => $v) { $content = str_replace("<--{$key}-->", $v, $content); } } unset($GLOBALS['_TEMP_replace']); unset($GLOBALS['_TEMP_index']); return $content; } function keywords_text_internal_parse($match) { global $words_internal_data; $match = $match[0]; if (!is_array($words_internal_data) || count($words_internal_data) < 1) { return $match; } $replace = array(); $index = 0; foreach ($words_internal_data as $k => $v) { $index++; $key = str_num2char(sprintf("%08d", $index)); if (preg_match("/" . preg_quote($k, "/") . "/i", $match)) { if ($url = @array_pop($words_internal_data[$k])) { $temp = $match; $match = preg_replace("/{$k}/Uis", "<--{$key}-->", $match, 1); if ($temp != $match) { $replace[$key] = "<a rel=\"INTERNAL_LINK\" target=\"_blank\" href=\"{$url}\">{$k}</a>"; } } else { unset($GLOBALS['words_internal_data'][$k]); } } } if (is_array($replace) && count($replace)) { foreach ($replace as $key => $v) { $match = str_replace("<--{$key}-->", $v, $match); } } return $match; } function keywords_external_parse() { global $user_product_index_file, $user_article_index_file, $site_url, $site_title, $site_keywords; $separator = array(",", "，", ".", "。", "?", "？", ":", "：", ";", "；", "!", "！", "|", " ", "-", "_", "/", "\\", "【", "】"); $words_external_data = array(); $settingfile = SITE_ROOT . "/data/setting/{$site_url}/keywords.setting.txt"; if (file_exists($settingfile)) { $keywords_setting = read_array_file($settingfile); $temp = $keywords_setting['base_words']; if (strlen($keywords_setting['words_data']) >= 4) { $tmp = explode(",", str_replace($separator, "," , $keywords_setting['words_data'])); foreach ($tmp as $k => $v) { if (!empty($tmp[$k])) { $words_external_data[trim($tmp[$k])] = array(); } } } } else { $temp = "{$site_title},{$site_keywords}"; } $base_keywords = explode(",", str_replace($separator, "," , $temp)); foreach ($base_keywords as $k => $v) { if (empty($base_keywords[$k])) { unset($base_keywords[$k]); } } if (is_array($words_external_data) && count($words_external_data)) { foreach ($words_external_data as $k => $v) { $temp = baidu_related_words($k); if (is_array($temp) && count($temp)) { foreach ($temp as $words) { if (empty($words)) { continue; } foreach ($base_keywords as $filter) { if (preg_match("/" . preg_quote($filter, "/") . "/i", $words)) { $words_external_data[$words] = array(); break; } } } } } } return $words_external_data; } function keywords_update_external_link($content) { global $words_external_data; $content = preg_replace('/\<a rel="EXTERNAL_LINK"[^>]+\>([^<]+)\<\/a\>/is', '$1', $content); global $_TEMP_replace, $_TEMP_index; $_TEMP_replace = array(); $_TEMP_index = 0; $a = create_function('$match', 'global $_TEMP_replace, $_TEMP_index; 
									$_TEMP_index++; 
									$key=str_num2char(sprintf("%08d", $_TEMP_index)); 
									$_TEMP_replace[$key]=$match[0];
									return "<--{$key}-->"; '); $content = preg_replace_callback('/\<a[^>]+\>(.*)\<\/a\>/Uis', $a, $content); if (is_array($words_external_data) && count($words_external_data)) { if (count($words_external_data) > 0) { $content = preg_replace_callback('/\>([^<>]+)\</Uis', 'keywords_text_external_parse', $content); } } if (is_array($_TEMP_replace) && count($_TEMP_replace)) { foreach ($_TEMP_replace as $key => $v) { $content = str_replace("<--{$key}-->", $v, $content); } } unset($GLOBALS['_TEMP_replace']); unset($GLOBALS['_TEMP_index']); return $content; } function keywords_text_external_parse($match) { global $words_external_data, $external_link_type; $match = $match[0]; if (!is_array($words_external_data) || count($words_external_data) < 1) { return $match; } $replace = array(); $index = 0; foreach ($words_external_data as $k => $v) { $index++; $key = str_num2char(sprintf("%08d", $index)); if (preg_match("/" . preg_quote($k, "/") . "/i", $match)) { if (count($words_external_data[$k]) < 1) { $temp = $match; $match = preg_replace("/{$k}/Uis", "<--{$key}-->", $match, 2); if ($temp != $match) { $replace[$key] = "<a rel=\"EXTERNAL_LINK\" target=\"_blank\" href=\"http://www.baidu.com/s?wd=" . rawurlencode($k) . "&tn=siteteam_pg\">{$k}</a>"; } unset($GLOBALS['words_external_data'][$k]); continue; } if ($url = @array_pop($words_external_data[$k])) { $temp = $match; $match = preg_replace("/{$k}/Uis", "<--{$key}-->", $match, 1); if ($temp != $match) { if ($external_link_type == 1) { $replace[$key] = "<a rel=\"EXTERNAL_LINK\" target=\"_blank\" href=\"http://www.baidu.com/s?wd=" . rawurlencode($k) . "&tn=siteteam_pg\">{$k}</a>"; } else { $replace[$key] = "<a rel=\"EXTERNAL_LINK\" target=\"_blank\" href=\"{$url}\">{$k}</a>"; } } if ($external_link_type == 1) { continue; } } else { unset($GLOBALS['words_external_data'][$k]); } } } if (is_array($replace) && count($replace)) { foreach ($replace as $key => $v) { $match = str_replace("<--{$key}-->", $v, $match); } } return $match; } function str_num2char($number) { $n = array('1', '2', '3', '4', '5', '6', '7', '8', '9', '0'); $c = array('!', '@', '#', '$', '%', '^', '&', '*', '(', ')'); return str_replace($n, $c, "{$number}"); } function save_array_to_file($array, $arrayfile, $arrayname) { if (!is_array($array) || empty($arrayfile) || empty($arrayname)) { return false; } $fp = fopen($arrayfile, "w"); $cachetext = "\n<?php\n"; $cachetext .= "if(!defined('IN_SITETEAM')) {exit('Access Denied');}\n"; $cachetext .= "\${$arrayname}= \n" . var_export($array, true) . ";\n"; $cachetext .= "?>\n"; fwrite($fp, $cachetext); fclose($fp); return true; } function file_del_dir($dir) { if (!file_exists("{$dir}")) { return false; } if ($handle = opendir($dir)) { while (false !== ($file = readdir($handle))) { if ($file != "." && $file != "..") { if (is_dir("{$dir}/{$file}")) { if (!@rmdir("{$dir}/{$file}")) { file_del_dir("{$dir}/{$file}"); } else { ; } } else { @unlink("{$dir}/{$file}"); } } } closedir($handle); } @rmdir($dir); } ?>