“博客迷”(BlogMi)源码阅读[1]

最近在学习PHP语言,想做一个博客程序.于是下载了一个博客程序的源码来研究.这个程序比较小巧,通过阅读可以快速掌握编写一个博客的方法.

阅读顺序是从第一个文件index.php开始.源码如下:

本文件的思路是:

1.包含核心文件: 

require_once dirname(__FILE__).'/files/core.php';

核心文件包含了自定义的函数和全局变量.还有一个404页面函数.

2.通过正则表达式来确定请求类型.

3.根据请求的正文类型来进行查询.

require 'files/posts/index/publish.php';

4.查询完毕后通过模板进行输出.

if ($mc_get_type != 'rss') require 'files/theme/v/index.php';
else require 'files/rss.php';

  1 <?php
  2 require_once dirname(__FILE__).'/files/core.php';
  3 $mc_post_per_page = 2;
  4 $qs = $_SERVER['QUERY_STRING'];
  5 if (preg_match('|^post/([a-z0-5]{6})$|', $qs, $matches)) {
  6   $mc_get_type = 'post';
  7   $mc_get_name = $matches[1];
  8 }
  9 else if (preg_match('|^tag/([^/]+)/(\?page=([0-9]+)){0,1}$|', $qs, $matches)) {
 10   $mc_get_type = 'tag';
 11   $mc_get_name = urldecode($matches[1]);
 12   $mc_page_num = isset($matches[2]) ? $matches[3] : 1;
 13 }
 14 else if (preg_match('|^date/([0-9]{4}-[0-9]{2})/(\?page=([0-9]+)){0,1}$|', $qs, $matches)) {
 15   $mc_get_type = 'date';
 16   $mc_get_name = urldecode($matches[1]);
 17   $mc_page_num = isset($matches[2]) ? $matches[3] : 1;
 18 }
 19 else if (preg_match('|^archive/$|', $qs, $matches)) {
 20   $mc_get_type = 'archive';
 21 }
 22 else if ($qs == 'rss/') {
 23   $mc_get_type = 'rss';
 24   $mc_get_name = '';
 25   $mc_page_num = isset($_GET['page']) ? $_GET['page'] : 1;
 26 }
 27 else if (preg_match('|^(([-a-zA-Z0-5]+/)+)$|', $qs, $matches)) {
 28   $mc_get_type = 'page';
 29   $mc_get_name = substr($matches[1], 0, -1);
 30 } else {
 31   $mc_get_type = 'index';
 32   $mc_get_name = '';
 33   $mc_page_num = isset($_GET['page']) ? $_GET['page'] : 1;
 34 }
 35 if ($mc_get_type == 'post') {
 36   require 'files/posts/index/publish.php';
 37   if (array_key_exists($mc_get_name, $mc_posts)) {
 38     $mc_post_id = $mc_get_name;
 39     $mc_post = $mc_posts[$mc_post_id];
 40     $mc_data = unserialize(file_get_contents('files/posts/data/'.$mc_post_id.'.dat'));
 41   }
 42   else {
 43     mc_404();
 44   }
 45 }
 46 else if ($mc_get_type == 'tag') {
 47   require 'files/posts/index/publish.php';
 48   $mc_post_ids = array_keys($mc_posts);
 49   $mc_post_count = count($mc_post_ids);
 50   $mc_tag_posts = array();
 51   for ($i = 0; $i < $mc_post_count; $i ++) {
 52     $id = $mc_post_ids[$i];
 53     $post = $mc_posts[$id];
 54     if (in_array($mc_get_name, $post['tags'])) {
 55       $mc_tag_posts[$id] = $post;
 56     }
 57   }
 58   $mc_posts = $mc_tag_posts;
 59   $mc_post_ids = array_keys($mc_posts);
 60   $mc_post_count = count($mc_post_ids);
 61 }
 62 else if ($mc_get_type == 'date') {
 63   require 'files/posts/index/publish.php';
 64   $mc_post_ids = array_keys($mc_posts);
 65   $mc_post_count = count($mc_post_ids);
 66   $mc_date_posts = array();
 67   for ($i = 0; $i < $mc_post_count; $i ++) {
 68     $id = $mc_post_ids[$i];
 69     $post = $mc_posts[$id];
 70     if (strpos($post['date'], $mc_get_name) === 0) {
 71       $mc_date_posts[$id] = $post;
 72     }
 73   }
 74   $mc_posts = $mc_date_posts;
 75   $mc_post_ids = array_keys($mc_posts);
 76   $mc_post_count = count($mc_post_ids);
 77 }
 78 else if ($mc_get_type == 'archive') {
 79   require 'files/posts/index/publish.php';
 80   $mc_post_ids = array_keys($mc_posts);
 81   $mc_post_count = count($mc_post_ids);
 82   $tags_array = array();
 83   $date_array = array();
 84   for ($i = 0; $i < $mc_post_count; $i ++) {
 85     $post_id = $mc_post_ids[$i];
 86     $post = $mc_posts[$post_id];
 87     $date_array[] = substr($post['date'], 0, 7);
 88     $tags_array = array_merge($tags_array, $post['tags']);
 89   }
 90   $mc_tags  = array_values(array_unique($tags_array));
 91   $mc_dates = array_values(array_unique($date_array));
 92 }
 93 else if ($mc_get_type == 'page') {
 94   require 'files/pages/index/publish.php';
 95   if (array_key_exists($mc_get_name, $mc_pages)) {
 96     $mc_post_id = $mc_get_name;
 97     $mc_post = $mc_pages[$mc_post_id];
 98     $mc_data = unserialize(file_get_contents('files/pages/data/'.$mc_post['file'].'.dat'));
 99   }
100   else {
101     mc_404();
102   }
103 }
104 else {
105   require 'files/posts/index/publish.php';
106   $mc_post_ids = array_keys($mc_posts);
107   $mc_post_count = count($mc_post_ids);
108 }
109 if ($mc_get_type != 'rss')
110   require 'files/theme/v/index.php';
111 else
112   require 'files/rss.php';
113 ?>

 

转载于:https://www.cnblogs.com/OneL1fe/p/5388194.html

特点:轻巧、方便 “博客”(BlogMi)是一套基于PHP语言的开源、简洁、高效的博客程序,它满足个人博客必要的建站需求,剔除了常见博客程序复杂臃肿的功能。因此,“”取令人着你之意。 “博客”不需要数据库的支持,采用的是类似TXT文本数据库的存储形式。上传本程序到支持PHP的主机或虚拟空间,立即就可使用。博客内容的备份和还原非常方便,只需下载和上传程序目录下的全部文件即可,所有的文章、配置等均可完整保留和再现。 功能:文章、页面 从功能上来说,“博客”分为“文章”和“页面”。 “文章”功能让你能够发布文章,仅保留基本的标题、标签、正文、发布时间等功能。发布文章时可以选择是否允许评论,这样在你添加了第三方的评论代码之后,可以针对每一篇文章设置评论权限。另外,还有发布状态的选项,允许你暂时把文章保存在草稿箱中。 “页面”功能让你可以自由创建一些独立页面,并且可以自定义链接,同时也像“文章”一样可设置评论权限、发布状态。 安装:上传、配置 安装“博客”只需两步: 1、将本程序解压上传到你的网站目录(不要求必须是根目录); 2、进入程序管理后台修改密码和网址,http://网站目录/admin/,默认帐号:admin,默认密码:2046。 然后开始使用吧!
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值