summaryrefslogtreecommitdiffstats
path: root/functions.php
diff options
context:
space:
mode:
Diffstat (limited to 'functions.php')
-rw-r--r--functions.php31
1 files changed, 31 insertions, 0 deletions
diff --git a/functions.php b/functions.php
index cc26636..9490c0d 100644
--- a/functions.php
+++ b/functions.php
@@ -44,3 +44,34 @@ function themeVersion() {
$info = Typecho_Plugin::parseInfo(__DIR__ . '/index.php');
return $info['version'];
}
+
+/**
+ * 统计文章浏览数
+ * from:http://docs.qqdie.com/
+ */
+function get_post_view($archive) {
+ $cid = $archive->cid;
+ $db = Typecho_Db::get();
+ $prefix = $db->getPrefix();
+ if (!array_key_exists('views', $db->fetchRow($db->select()->from('table.contents')))) {
+ $db->query('ALTER TABLE `' . $prefix . 'contents` ADD `views` INT(10) DEFAULT 0;');
+ echo 0;
+ return;
+ }
+ $row = $db->fetchRow($db->select('views')->from('table.contents')->where('cid = ?', $cid));
+ if ($archive->is('single')) {
+ $views = Typecho_Cookie::get('extend_contents_views');
+ if(empty($views)){
+ $views = array();
+ }else{
+ $views = explode(',', $views);
+ }
+if(!in_array($cid,$views)){
+ $db->query($db->update('table.contents')->rows(array('views' => (int) $row['views'] + 1))->where('cid = ?', $cid));
+array_push($views, $cid);
+ $views = implode(',', $views);
+ Typecho_Cookie::set('extend_contents_views', $views); //记录查看cookie
+ }
+ }
+ echo $row['views'];
+}