贝邦网站采集系统详解
目录
navicat for sqlite – db3软件
系统下载
newsystem
一、文件结构
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
- .htaccess - admin_tools.php - config.php - index.php - /data/ -- .htaccess -- 数据库.db3 - /inc/ -- conn.php -- function.php -- function_get.php -- function_post.php -- robots.php -- sitemap.php - /themes/ -- 模板文件夹 - /pages/ --主题模板下page.php调取the_content()。 |
二、文件说明
1、htaccess文件
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
//windows环境 Options -Indexes <IfModule mod_rewrite.c> RewriteEngine On RewriteBase / RewriteRule ^index\.php$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L] </IfModule> //nginx环境 if (!-f $request_filename){ set $rule_0 1$rule_0; } if (!-d $request_filename){ set $rule_0 2$rule_0; } if ($rule_0 = "21"){ rewrite /. /list.php last; } |
2、Themes文件夹
和wordpress一样,category对应列表、single对应内容页、functions.php可写函数功能。
functions.php只支持独立的功能,不支持add_函数。同时模板里也不支持很多wordpress的功能。
(1)page.php
page.php页面如果存在,期内the_content()直接调取根目录下Page文件夹内更新内容。
(2)支持的标签
1 2 3 4 |
the_ID() //文章id function the_title() //文章标题 the_content() //文章内容 the_permalink() //文章链接 |
配置信息标签
注意:配置信息需要再config.php里设置。
1 2 3 |
bloginfo('template_directory'); bloginfo('site_name'); bloginfo('index_name'); //在首页时,the_title();和此相等。 |
3、data文件夹
(1)数据库文件
存放数据库的地方,只支持.db3数据库。(火车头采集出来的数据库结构就行)
(2).htaccess文件
和kiss的文件相同。上传需要转换为nginx。
4、admin_tools.php文件
数据库管理,访问地址为 域名/admin_tools.php
,只支持查询、编辑和删除。不支持sql语句。
5、config.php
网站配置文件,比较重要,主要设置如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
//管理员工具的登录密码 define('admin_tools_password', '1986'); //基本设置 define('site_name', 'Bottle Packager'); /** 网站名称 */ define('index_name', 'Bottle Packager,Bottle Packing - UKE Packaging machinery'); /** 首页名称 */ define('theme_name', 'packing'); //模板选择。模板请放置在themes目录下 //URL伪静态设置 define('static_format', '%postname%-%post_id%/'); //静态网址格式,可用%post_id%、%postname% %postzuozhe% %postchuchu%(建议优先使用%post_id%) /** 目录设置 文件夹名须与sqlite文件名一致 格式:文件夹名称 => array(分类名称, [起始发布时间, 每天发布篇数,] [发布延时秒数]) */ $category=array( // 'packager' => array('Bottle Packager,Bottle Packing', '2017-11-13', 10000), 'coffeepackager' => array('Coffee Packager,Packing Machine', '2017-11-13', 10000), 'packermachine' => array('Packing Machine,Packer Machine', '2017-11-13', 10000), '1' => array('Packing Machine,Packer Machine', '2017-11-13', 10000), ); /** 目录列表数 */ define('category_perpagenum', 20); /** 站点地图列表数*/ define('sitemap_perpagenum', 2000); |
6、根目录下的index.php
一般情况不要动
7、inc文件夹
(1)robots.txt文件可根据需要改动
1 2 3 4 5 6 7 |
<?php //Ver1.1 $http_host='http://' . $_SERVER ['HTTP_HOST']; header('Content-Type: text/plain'); //纯文本格式 echo "User-agent: *\r\n"; echo "Sitemap: {$http_host}/sitemap.xml"; die; ?> |
(2)conn.php
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
<?php //数据库封装 function ConnectDatebase($the_db, $admin=''){ global $conn; $conn=new PDO("sqlite:data/{$the_db}.db3"); global $where_publish, $category; $publish_date=isset($category[$the_db][1])?$category[$the_db][1]:''; $publish_pernum=isset($category[$the_db][2])?$category[$the_db][2]:0; $publish_delay=isset($category[$the_db][3])?$category[$the_db][3]:1000; if($admin=='admin' or $publish_date=='' or $publish_pernum==0){ $where_publish='1'; }else{ date_default_timezone_set('Asia/Shanghai'); $now_id=floor( (floor(time()/$publish_delay)*$publish_delay-strtotime($publish_date) )/86400*$publish_pernum ); if($now_id>99999){$where_publish='1';}else{$where_publish="`Id`<={$now_id}";} } } function CloseDatebase(){ global $conn; unset($conn); } /** * 获取第一条记录 * @param string $sql * @return array */ function FetchOne($the_where){ global $conn, $where_publish; $resultArr = array(); $sql="select * from `Content` where `已采`=1 and {$where_publish} and {$the_where} limit 1"; $result = $conn->query($sql); $row = $result->fetch(); !empty($row) && $resultArr = $row; return $resultArr; } function FetchCount($the_where='1'){ global $conn, $where_publish; $sql="select count(*) as `sum` from `Content` where `已采`=1 and {$where_publish} and {$the_where}"; $result = $conn->query($sql); $sum = $result->fetchColumn(); return $sum; } /** * 获取多条记录 * @param string * @return array */ function FetchAll($the_sql_args){ global $conn, $where_publish; $the_sql_args=str_replace('rand()', 'random()', $the_sql_args); //替换 $sql="select * from `Content` where `已采`=1 and {$where_publish} {$the_sql_args}"; $result = $conn->query($sql); $resultArr = $result->fetchAll(); return $resultArr; } /** * 更新一条记录 * @param string $sql * @return array */ function UpdateOne($the_where, $set_arr){ global $conn, $where_publish; $set_arr1=array(); foreach ($set_arr as $the_k => $the_v){ $the_v_sql=format($the_v, 'sql'); $set_arr1[]="`{$the_k}`='{$the_v_sql}'"; } $set_temp=implode(', ', $set_arr1); $sql="update `Content` set {$set_temp} where `已采`=1 and {$where_publish} and {$the_where}"; $result = $conn->query($sql); } /** * 删除一条记录 * @param string $sql * @return array */ function DeleteOne($the_where){ global $conn, $where_publish; $sql="delete from `Content` where `已采`=1 and {$where_publish} and {$the_where}"; $result = $conn->query($sql); } ?> |
(3)function.php
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
<?php //filter Ver1.0.1 function filter($name, $type='', $default=''){ if(isset($_GET[$name])){ $temp=trim($_GET[$name]); }elseif(isset($_POST[$name])){ $temp=trim($_POST[$name]); }else{ $temp=$default; } switch($type){ case 'int': $temp=(int)$temp; break; } return $temp; } ////GetIntroVer1.0 function GetIntro($the_text, $length=36){ if (strlen($the_text)>$length){ for($i=0; $i<$length; $i++){ if(ord($the_text[$i])>128) $i+=2;} $the_text = substr($the_text,0,$i) .'..'; } return $the_text; } ////GetSpace Ver1.0.0 function GetSpace($the_inquiry){ if (strlen($the_inquiry)==0) $the_inquiry=' '; return $the_inquiry; } //format 格式化字符串 function format($str, $type=''){ $temp=$str; switch($type){ case 'sql': $temp=str_replace('\\', '\\\\', $temp); $temp=str_replace('\'', '\\\'', $temp); break; case 'sqlike': $temp=str_replace('\\', '\\\\', $temp); $temp=str_replace('\'', '\\\'', $temp); $temp=str_replace('%', '\\%', $temp); $temp=str_replace('_', '\\_', $temp); break; case 'reg': $temp=str_replace('.', '\.', $temp); $temp=str_replace('/', '\/', $temp); break; case 'pre': $temp=str_replace("\r\n", "<br>\r\n", $temp); break; } return $temp; } /////////////////////////////////////////// //debug调试 ///////////////////////////////////////// function debug($string){ echo '<p><textarea style="width:800px; height:200px">'; print_r($string); echo "</textarea></p>\r\n"; //ob_flush();flush(); } ?> |
(4)function_get.php
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
<?php //function_get.php Ver1.0 by jkj //////////////////////////////////////////////////////////////////////////// //网站配置 //////////////////////////////////////////////////////////////////////////// //加载配置信息 function bloginfo($the_show='name'){echo get_bloginfo($the_show);} function get_bloginfo($the_show='name'){ switch ($the_show) { case 'name': return constant('site_name'); break; case 'site': return constant('site_name'); break; case 'site_name': return constant('site_name'); break; case 'index': return constant('index_name'); break; case 'index_name': return constant('index_name'); break; case 'template_url': return $GLOBALS['template_path']; break; case 'template_directory': return $GLOBALS['template_path']; break; default: break; } } //////////////////////////////////////////////////////////////////////////// //网站模板 //////////////////////////////////////////////////////////////////////////// $theme_name=constant('theme_name'); $theme_path="themes/{$theme_name}/"; $template_path='/themes/' . $theme_name; function get_theme_url($the_file){$the_file=substr($the_file, 0, 1)=='/'?$the_file:"/{$the_file}"; return $GLOBALS['theme_path'] . $the_file;} //获取模板文件路径 function get_template_url($the_file){$the_file=substr($the_file, 0, 1)=='/'?$the_file:"/{$the_file}"; return $GLOBALS['template_path'] . $the_file;} //模板引用部分 function get_template(){return $GLOBALS['theme_name'];} //获得模板目录的名车 function get_template_directory(){return $GLOBALS['template_path'];} //获得模板目录的url //加载模板文件 function get_header() {require_file(get_theme_url('header.php')); } function get_footer() {require_file(get_theme_url('footer.php')); } function get_nav() {require_file(get_theme_url('nav.php')); } function get_right() {require_file(get_theme_url('right.php')); } function get_message() {require_file(get_theme_url('message.php')); } //加载文档 function require_file($the_file_url){ global $post, $posts, $template_path; require_once($the_file_url); } //获取链接 function GetPermalink($the_post_id='', $the_post_name='', $the_post_chuchu='', $the_post_zuozhe=''){ $the_permalink=constant('static_format'); $the_permalink=str_replace('%post_id%', $the_post_id, $the_permalink); if($the_post_name) $the_post_name=str_replace(' ', '-', $the_post_name); $the_permalink=str_replace('%postname%', urlencode($the_post_name), $the_permalink); if($the_post_chuchu) $the_post_chuchu=str_replace(' ', '-', $the_post_chuchu); $the_permalink=str_replace('%postchuchu%', urlencode($the_post_chuchu), $the_permalink); if($the_post_zuozhe) $the_post_zuozhe=str_replace(' ', '-', $the_post_zuozhe); $the_permalink=str_replace('%postzuozhe%', urlencode($the_post_zuozhe), $the_permalink); $the_permalink='/' . $GLOBALS['dir'] . '/' . $the_permalink; return $the_permalink; } ?> |
(5)function_post.php
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 |
<?php //function_post.php V1.1 by jkj $post=array(); $posts=array(); //文档初始化 //测试posts是否存在 function have_posts(){ global $posts; $result = empty($posts); return !$result; } function the_post(){ global $post, $posts; $post=array_shift($posts); } //加载模板文件 function the_ID() {echo get_ID();} function the_title() {echo get_title();} function the_content() {echo get_content();} function the_chuchu() {echo get_chuchu();} //新增加字段 function the_zuozhe() {echo get_zuozhe();} //新增加字段 function the_permalink() {echo get_permalink();} function get_ID() {global $post; return array_key_exists('the_ID', $post)?$post['the_ID']:'';} function get_title() {global $post; return array_key_exists('the_title', $post)?$post['the_title']:'';} function get_content() {global $post; return array_key_exists('the_content', $post)?$post['the_content']:'';} function get_chuchu() {global $post; return array_key_exists('the_chuchu', $post)?$post['the_chuchu']:'';}//新增加字段 function get_zuozhe() {global $post; return array_key_exists('the_zuozhe', $post)?$post['the_zuozhe']:'';}//新增加字段 function get_permalink() {global $post; return array_key_exists('the_permalink', $post)?$post['the_permalink']:'';} //get_single function get_single(){ global $dir, $matches; $static_format=constant('static_format'); $static_format_reg=format(static_format, 'reg'); $static_format_reg=str_replace('%post_id%', '(%post_id%)', $static_format_reg); $static_format_reg=str_replace('%postname%', '(%postname%)', $static_format_reg); $static_format_reg=str_replace('%postchuchu%', '(%postchuchu%)', $static_format_reg); $static_format_reg=str_replace('%postzuozhe%', '(%postzuozhe%)', $static_format_reg); preg_match("/^{$static_format_reg}$/i", $static_format, $name_matches); $where_arr=array(); for ($i=1; $i<count($name_matches); $i++){ switch($name_matches[$i]){ case '%post_id%': $where_arr[]='`Id`=' . $matches[$i]; break; case '%postname%': $text_sql=format(urldecode($matches[$i]), 'sql'); $where_arr[]="REPLACE(`标题`, ' ', '-')='{$text_sql}'"; break; case '%postchuchu%': $text_sql=format(urldecode($matches[$i]), 'sql'); $where_arr[]="REPLACE(`出处`, ' ', '-')='{$text_sql}'"; break; case '%postzuozhe%': $text_sql=format(urldecode($matches[$i]), 'sql'); $where_arr[]="REPLACE(`作者`, ' ', '-')='{$text_sql}'"; break; } } if(empty($where_arr)){$where='0';}else{$where=implode(' and ', $where_arr);} ConnectDatebase($dir); $row=FetchOne($where); CloseDatebase(); if(empty($row)) return; $temp=array(); $temp['the_ID']=$row['Id']; $temp['the_title']=$row['标题']; $temp['the_content']=$row['内容']; //$temp['the_chuchu']=$row['出处']; //新增加字段 //$temp['the_zuozhe']=$row['作者']; //新增加字段 $temp['the_permalink']=GetPermalink($temp['the_ID'], $temp['the_title']); global $post, $posts; $post=$temp; $posts=array($post); } //get_category function get_category(){ global $dir, $text; global $page_current, $page_num; $category_perpagenum=constant('category_perpagenum'); ConnectDatebase($dir); $page_current=$text==''?1:$text; //获取index的id if(!is_numeric($page_current) or $page_current<=0) return; $page_begin=$category_perpagenum*($page_current-1); $sum=FetchCount(); $page_num=ceil($sum/$category_perpagenum); $sql_args="limit {$page_begin}, {$category_perpagenum}"; $rs=FetchAll($sql_args); CloseDatebase(); if(empty($rs)) return; global $posts; $posts=array(); foreach($rs as $row){ $temp=array(); $temp['the_ID']=$row['Id']; $temp['the_title']=$row['标题']; $temp['the_content']=$row['内容']; //$temp['the_zuozhe']=$row['作者']; //列表新增加字段 //$temp['the_chuchu']=$row['出处']; //列表新增加字段 $temp['the_permalink']=GetPermalink($temp['the_ID'], $temp['the_title']); $posts[]=$temp; } global $post, $category; $post['the_title']=$category[$dir][0] . ' ' . $page_current; $post['the_title']=ucwords($post['the_title']); } //get_page function get_page(){ global $text; $the_filename=trim($text); if($the_filename=='') $the_filename='index.html'; $file_path='pages/' . $the_filename; if(!file_exists($file_path)) return; //如果不存在则返回空 $the_content = file_get_contents($file_path); global $post; $post['the_ID']=0; $post['the_title']=substr($the_filename, 0, -5); $post['the_content']=$the_content; $post['the_permalink']='/' . $the_filename; $post['the_title']=ucwords($post['the_title']); global $posts; $posts=array($post); } //get_page function get_index(){ global $post; $post['the_title']=get_bloginfo('index_name'); $post['the_title']=ucwords($post['the_title']); global $posts; $posts=array($post); } ///////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////// //get_posts function get_posts($the_args=''){ //get_posts('numberposts=30&orderby=rand'); global $dir; if($dir==''){global $category; $key_arr=array_keys($category); $dir=$key_arr[0];} $args = array( 'numberposts' => 10, //需要提取的文章数 'offset' => 0, //以第几篇文章为起始位置 'orderby' => 'rand()', //排序规则(注1) 'order' => 'DESC', //升序、降序 'ASC' —— 升序 (低到高) 'DESC' —— 降序 (高到底) 'post_status' => 'publish' //文章状态 ); if(is_array($the_args)){ } if(is_string($the_args) and $the_args<>''){ $arg1=explode('&', $the_args); foreach($arg1 as $arg2){ $temp=explode('=', $arg2); $args[$temp[0]]=$temp[1]; } } if($args['orderby']=='rand') $args['orderby'].='()'; $sql_args=' order by ' . $args['orderby'] . ' ' . $args['order'] . ' limit ' . $args['offset'] . ',' . $args['numberposts']; ConnectDatebase($dir); $rs=FetchAll($sql_args); CloseDatebase(); $posts=array(); foreach($rs as $row){ $temp=array(); $temp['the_ID']=$row['Id']; $temp['the_title']=$row['标题']; $temp['the_content']=$row['内容']; //$temp['the_chuchu']=$row['出处']; //新增加字段 //$temp['the_zuozhe']=$row['作者']; //新增加字段 $temp['the_permalink']=GetPermalink($temp['the_ID'], $temp['the_title']); $posts[]=$temp; } return $posts; } ?> |
(6)sitemap.php
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
<?php //Ver1.1 $http_host='http://' . $_SERVER ['HTTP_HOST']; $sitemap_perpagenum=constant('sitemap_perpagenum'); if($text==''){ //显示主xml $flag=false; if(count($category)<=1){ $key_arr=array_keys($category); $key0=$key_arr[0]; ConnectDatebase($key0); $sum=FetchCount(); CloseDatebase(); if($sum<=$sitemap_perpagenum) $flag=true; } //判断是否直接显示sitemap if($flag){ShowMap($key0, 1);}else{ShowIndex(); die;} }else{ //分xml list($temp, $dir, $page)=explode('_', $text); if(!is_numeric($page) or $page<=0) R404(); if(!array_key_exists($dir, $category)) R404(); ShowMap($page); die; } //地图索引 function ShowIndex(){ global $category, $http_host, $sitemap_perpagenum; //初始化 header("Content-type: application/xml"); echo '<?xml version="1.0" encoding="utf-8"?>'; echo "\r\n"; echo '<sitemapindex xmlns="http://www.google.com/schemas/sitemap/0.84">'; echo "\r\n"; foreach($category as $dir=>$dir_name){ ConnectDatebase($dir); $sum=FetchCount(); CloseDatebase(); $page_num=ceil($sum/$sitemap_perpagenum); for($i=1;$i<=$page_num; $i++){ echo '<sitemap>'; echo "\r\n"; echo "<loc>{$http_host}/sitemap_{$dir}_{$i}.xml</loc>\r\n"; echo '</sitemap>'; echo "\r\n"; } } echo '</sitemapindex>'; } //地图文档 function ShowMap($the_page){ global $http_host, $sitemap_perpagenum, $dir; $page_begin=$sitemap_perpagenum*($the_page-1); $sql_args="limit {$page_begin}, {$sitemap_perpagenum}"; ConnectDatebase($dir); $rs=FetchAll($sql_args); CloseDatebase(); if(empty($rs)) R404(); global $posts; foreach($rs as $row){ $temp=array(); $temp['the_ID']=$row['Id']; $temp['the_title']=$row['标题']; //$temp['the_content']=$row['内容']; $temp['the_permalink']=GetPermalink($temp['the_ID'], $temp['the_title']); $posts[]=$temp; } //初始化 header("Content-type: application/xml"); echo '<?xml version="1.0" encoding="utf-8"?>'; echo "\r\n"; echo '<urlset xmlns="http://www.google.com/schemas/sitemap/0.84">'; echo "\r\n"; foreach($posts as $post){ echo '<url>'; echo "\r\n"; echo '<loc>' . $http_host . $post['the_permalink'] . '</loc>'; echo "\r\n"; echo '</url>'; echo "\r\n"; } echo '</urlset>'; } ?> |
上一篇: 外贸营销留言板程序inquiry教程
下一篇: ps -aux命令详解
总计 0 评论