码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2016-04-13 20:17:13      阅读:617      评论:0      收藏:0      [点我收藏+]

标签:

首页面包括的文件源码如下:

文件实现了:

1.打开所有的错误输出.

2.包括了两个文件.

3.定义了一个404页面.

 1 <?php
 2 ini_set("display_errors", "On"); error_reporting(E_ALL);//ini_set — 为一个配置选项设置值
 3 /*error_reporting() 函数规定报告哪个错误[1]  。
 4 该函数设置当前脚本的错误报告级别。
 5 该函数返回旧的错误报告级别。*/
 6 require_once ‘tags.php‘;
 7 require_once ‘conf.php‘;
 8 function mc_404()
 9 {
10   header(‘HTTP/1.0 404 Not Found‘);
11   echo "<h1>404 Not Found</h1>";
12   echo "The page that you have requested could not be found.";
13   exit();
14 }
15 ?>

tag.php源码如下:

文件实现了:

1.实现对全局变量转换成HTML实体并返回的函数.

2.定义了主题URL地址.

3.一些内容类型确定函数.

4.各种内容跳转链接地址生成函数.(首页文件中用正则表达式来匹配这些链接地址)

 

  1 <?php
  2 function mc_site_name($print = true) {
  3   global $mc_config;
  4   $site_name = htmlspecialchars($mc_config[‘site_name‘]);//把预定义的字符 "<" (小于)和 ">" (大于)转换为 HTML 实体:
  5   if ($print) {
  6     echo $site_name;
  7     return;
  8   }
  9   return $site_name;
 10 }
 11 
 12 function mc_site_desc($print = true) {
 13   global $mc_config;
 14   $site_desc = htmlspecialchars($mc_config[‘site_desc‘]);
 15   if ($print) {
 16     echo $site_desc;
 17     return;
 18   }
 19   return $site_desc;
 20 }
 21 
 22 function mc_site_link($print = true) {
 23   global $mc_config;
 24   $site_link = $mc_config[‘site_link‘];
 25   if ($print) {
 26     echo $site_link;
 27     return;
 28   }
 29   return $site_link;
 30 }
 31 
 32 function mc_nick_name($print = true) {
 33   global $mc_config;
 34   $nick_name = htmlspecialchars($mc_config[‘user_nick‘]);
 35   if ($print) {
 36     echo $nick_name;
 37     return;
 38   }
 39   return $nick_name;
 40 }
 41 
 42 function mc_theme_url($path, $print = true) {
 43   global $mc_config;
 44   $url = $mc_config[‘site_link‘].‘/files/theme/v/‘.$path;
 45   if ($print) {
 46     echo $url;
 47     return;
 48   }
 49   return $url;
 50 }
 51 
 52 function mc_is_post() {
 53   global $mc_get_type;
 54   return $mc_get_type == ‘post‘;
 55 }
 56 
 57 function mc_is_page() {
 58   global $mc_get_type;
 59   return $mc_get_type == ‘page‘;
 60 }
 61 
 62 function mc_is_tag() {
 63   global $mc_get_type;
 64   return $mc_get_type == ‘tag‘;
 65 }
 66 
 67 function mc_is_date() {
 68   global $mc_get_type;
 69   return $mc_get_type == ‘date‘;
 70 }
 71 
 72 function mc_is_archive() {
 73   global $mc_get_type;
 74   return $mc_get_type == ‘archive‘;
 75 }
 76 
 77 function mc_tag_name($print=true) {
 78   global $mc_get_name;
 79   if ($print) {
 80     echo htmlspecialchars($mc_get_name);
 81     return;
 82   }
 83   return $mc_get_name;
 84 }
 85 
 86 function mc_date_name($print=true) {
 87   global $mc_get_name;
 88   if ($print) {
 89     echo htmlspecialchars($mc_get_name);
 90     return;
 91   }
 92   return $mc_get_name;
 93 }
 94 
 95 function mc_has_new() {
 96   global $mc_page_num;
 97   return $mc_page_num != 1;
 98 }
 99 
100 function mc_has_old() {
101   global $mc_page_num, $mc_post_count, $mc_post_per_page;
102   return $mc_page_num < ($mc_post_count / $mc_post_per_page);
103 }
104 
105 function mc_goto_old($text) {
106   global $mc_get_type, $mc_get_name, $mc_page_num, $mc_config;
107   if ($mc_get_type == ‘tag‘) {
108     echo ‘<a href="‘;
109     echo $mc_config[‘site_link‘];
110     echo ‘/?tag/‘;
111     echo $mc_get_name;
112     echo ‘/?page=‘;
113     echo ($mc_page_num + 1);
114     echo ‘" class="nextpage">‘;
115     echo $text;
116     echo ‘</a>‘;
117   } 
118   elseif ($mc_get_type == ‘date‘) {
119     echo ‘<a href="‘;
120     echo $mc_config[‘site_link‘];
121     echo ‘/?date/‘;
122     echo $mc_get_name;
123     echo ‘/?page=‘;
124     echo ($mc_page_num + 1);
125     echo ‘" class="nextpage">‘;
126     echo $text;
127     echo ‘</a>‘;
128   } else {
129     echo ‘<a href="‘;
130     echo $mc_config[‘site_link‘];
131     echo ‘/?page=‘;
132     echo ($mc_page_num + 1);
133     echo ‘" class="nextpage">‘;
134     echo $text;
135     echo ‘</a>‘;
136   }
137 }
138 
139 function mc_goto_new($text) {
140   global $mc_get_type, $mc_get_name, $mc_page_num, $mc_config;
141   if ($mc_get_type == ‘tag‘) {
142     echo ‘<a href="‘;
143     echo $mc_config[‘site_link‘];
144     echo ‘/?tag/‘;
145     echo $mc_get_name;
146     echo ‘/?page=‘;
147     echo ($mc_page_num - 1);
148     echo ‘" class="prevpage">‘;
149     echo $text;
150     echo ‘</a>‘;
151   }
152   elseif ($mc_get_type == ‘date‘) {
153     echo ‘<a href="‘;
154     echo $mc_config[‘site_link‘];
155     echo ‘/?date/‘;
156     echo $mc_get_name;
157     echo ‘/?page=‘;
158     echo ($mc_page_num - 1);
159     echo ‘" class="prevpage">‘;
160     echo $text;
161     echo ‘</a>‘;
162   } else {
163     echo ‘<a href="‘;
164     echo $mc_config[‘site_link‘];
165     echo ‘/?page=‘;
166     echo ($mc_page_num - 1);
167     echo ‘" class="prevpage">‘;
168     echo $text;
169     echo ‘</a>‘;
170   }
171 }
172 
173 function mc_date_list($item_begin=‘<li>‘, $item_gap=‘‘, $item_end=‘</li>‘) {
174   global $mc_dates, $mc_config;
175   if (isset($mc_dates)) {
176     $date_count = count($mc_dates);
177     for ($i = 0; $i < $date_count; $i ++) {
178       $date = $mc_dates[$i];
179       echo $item_begin;
180       echo ‘<a href="‘;
181       echo $mc_config[‘site_link‘];
182       echo ‘/?date/‘;
183       echo $date;
184       echo ‘/">‘;
185       echo $date;
186       echo ‘</a>‘;
187       echo $item_end;
188       if ($i < $date_count - 1)
189         echo $item_gap;
190     }
191   }
192 }
193 
194 function mc_tag_list($item_begin=‘<li>‘, $item_gap=‘‘, $item_end=‘</li>‘) {
195   global $mc_tags, $mc_config;
196   if (isset($mc_tags)) {
197     $tag_count = count($mc_tags);
198     for ($i = 0; $i < $tag_count; $i ++) {
199       $tag = $mc_tags[$i];
200       echo $item_begin;
201       echo ‘<a href="‘;
202       echo $mc_config[‘site_link‘];
203       echo ‘/?tag/‘;
204       echo urlencode($tag);
205       echo ‘/">‘;
206       echo $tag;
207       echo ‘</a>‘;
208       echo $item_end;
209       if ($i < $tag_count - 1)
210         echo $item_gap;
211     }
212   }
213 }
214 
215 function mc_next_post() {
216   global $mc_posts, $mc_post_ids, $mc_post_count, $mc_post_i, $mc_post_i_end, $mc_post_id, $mc_post, $mc_page_num, $mc_post_per_page;
217   if (!isset($mc_posts))
218     return false;
219   if (!isset($mc_post_i)) {
220     $mc_post_i = 0 + ($mc_page_num - 1) * $mc_post_per_page;
221     $mc_post_i_end = $mc_post_i + $mc_post_per_page;
222     if ($mc_post_count < $mc_post_i_end)
223       $mc_post_i_end = $mc_post_count;
224   }
225   if ($mc_post_i == $mc_post_i_end)
226     return false;
227   $mc_post_id = $mc_post_ids[$mc_post_i];
228   $mc_post = $mc_posts[$mc_post_id];
229   $mc_post_i += 1;
230   return true;
231 }
232 
233 function mc_the_title($print = true) {
234   global $mc_post;
235   if ($print) {
236     echo htmlspecialchars($mc_post[‘title‘]);
237     return;
238   }
239   return htmlspecialchars($mc_post[‘title‘]);
240 }
241 
242 function mc_the_date($print = true) {
243   global $mc_post;
244   if ($print) {
245     echo $mc_post[‘date‘];
246     return;
247   }
248   return $mc_post[‘date‘];
249 }
250 
251 function mc_the_time($print = true) {
252   global $mc_post;
253   if ($print) {
254     echo $mc_post[‘time‘];
255     return;
256   }
257   return $mc_post[‘time‘];
258 }
259 
260 function mc_the_tags($item_begin=‘‘, $item_gap=‘, ‘, $item_end=‘‘) {
261   global $mc_post, $mc_config;
262   $tags = $mc_post[‘tags‘];
263   $count = count($tags);
264   for ($i = 0; $i < $count; $i ++) {
265     $tag = htmlspecialchars($tags[$i]);
266     echo $item_begin;
267     echo ‘<a href="‘;
268     echo $mc_config[‘site_link‘];
269     echo ‘/?tag/‘;
270     echo urlencode($tag);
271     echo ‘/">‘;
272     echo $tag;
273     echo ‘</a>‘;
274     echo $item_end;
275     if ($i < $count - 1)
276       echo $item_gap;
277   }
278 }
279 
280 function mc_the_content($print = true) {
281   global $mc_data;
282   if (!isset($mc_data)) {
283     global $mc_post_id;
284     $data = unserialize(file_get_contents(‘files/posts/data/‘.$mc_post_id.‘.dat‘)); 
285     $html = $data[‘content‘]; 
286   }
287   else {
288     $html = $mc_data[‘content‘];
289   }
290   if ($print) {
291     echo $html;
292     return;
293   }
294   return $html;
295 }
296 
297 function mc_the_link() {
298   global $mc_post_id, $mc_post, $mc_config;
299   echo ‘<a href="‘;
300   echo $mc_config[‘site_link‘];
301   echo ‘/?post/‘;
302   echo $mc_post_id;
303   echo ‘">‘;
304   echo htmlspecialchars($mc_post[‘title‘]);
305   echo ‘</a>‘;
306 }
307 
308 function mc_post_link() {
309   global $mc_post_id, $mc_post, $mc_config;
310   echo $mc_config[‘site_link‘];
311   echo ‘/?post/‘;
312   echo $mc_post_id;
313 }
314 
315 function mc_page_title() {
316   global $mc_post_id, $mc_post, $mc_config;
317   echo htmlspecialchars($mc_post[‘title‘]);
318 }
319 
320 function mc_can_comment() {
321   global $mc_post_id, $mc_post;
322   return isset($mc_post[‘can_comment‘]) ? $mc_post[‘can_comment‘] == ‘1‘ : true;
323 }
324 
325 function mc_comment_code() {
326   global $mc_config;
327   echo isset($mc_config[‘comment_code‘]) ? $mc_config[‘comment_code‘] : ‘‘;
328 }
329 ?>

conf.php源码如下:

1.定义全局配置.该配置文件可以通过后台登录修改.管理员帐户密码全是明文的.

 1 <?php
 2 $mc_config = array (
 3   ‘site_link‘ => ‘http://127.0.0.1:8080‘,
 4   ‘site_name‘ => ‘博客迷‘,
 5   ‘site_desc‘ => ‘不需要数据库的迷你博客程序‘,
 6   ‘user_name‘ => ‘admin‘,
 7   ‘user_pass‘ => ‘2046‘,
 8   ‘user_nick‘ => ‘BlogMi‘,
 9   ‘comment_code‘ => ‘‘,
10 )
11 ?>

publish.php源码如下:

1.该文件是用来存放文章信息的.

包含博客的id,标题,标签等.每发表一篇博文就会添加一条信息.

 1 <?php
 2 $mc_posts=array (
 3   ‘pxvczn‘ => 
 4   array (
 5     ‘id‘ => ‘pxvczn‘,
 6     ‘state‘ => ‘publish‘,
 7     ‘title‘ => ‘Hello,World!‘,
 8     ‘tags‘ => 
 9     array (
10       0 => ‘妙语‘,
11       1 => ‘男人‘,
12       2 => ‘女人‘,
13     ),
14     ‘date‘ => ‘2012-04-05‘,
15     ‘time‘ => ‘10:10:10‘,
16     ‘can_comment‘ => ‘1‘,
17   ),
18 )
19 ?>

 

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

标签:

原文地址:http://www.cnblogs.com/OneL1fe/p/5388332.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!