diff --git a/plugins/TajianStats.php b/plugins/TajianStats.php new file mode 100644 index 0000000..1888b10 --- /dev/null +++ b/plugins/TajianStats.php @@ -0,0 +1,104 @@ + self::$total_user, + 'video' => self::$total_video, + 'tag' => self::$total_tag, + 'cache_time' => self::$cache_save_time, + ); + } + + public static function increase($data_type) { + $total = 0; + + switch($data_type) { + case 'user': + self::$total_user ++; + $total = self::$total_user; + break; + + case 'video': + self::$total_video ++; + $total = self::$total_video; + break; + + case 'tag': + self::$total_tag ++; + $total = self::$total_tag; + break; + } + + return $total; + } + + public static function decrease($data_type) { + $total = 0; + + switch($data_type) { + case 'video': + self::$total_video --; + $total = self::$total_video; + break; + + case 'tag': + self::$total_tag --; + $total = self::$total_tag; + break; + } + + return $total; + } +} \ No newline at end of file diff --git a/themes/tajian/controller/FrontapiController.php b/themes/tajian/controller/FrontapiController.php index d2fc2e6..ca5e26e 100644 --- a/themes/tajian/controller/FrontapiController.php +++ b/themes/tajian/controller/FrontapiController.php @@ -6,6 +6,7 @@ require_once __DIR__ . '/../../../lib/DirScanner.php'; require_once __DIR__ . '/../../../plugins/Parsedown.php'; require_once __DIR__ . '/../../../plugins/Html.php'; require_once __DIR__ . '/../../../plugins/Common.php'; +require_once __DIR__ . '/../../../plugins/TajianStats.php'; require_once __DIR__ . '/SiteController.php'; Class FrontApiController extends SiteController { @@ -128,7 +129,15 @@ Class FrontApiController extends SiteController { } if ($code == 1) { //保存视频 - $msg = $this->saveShareVideo($content, $title, $tagName) ? '视频保存完成,系统开始自动处理,1 - 3 分钟后刷新就能看到新添加的视频了。' : '视频保存失败,请稍后重试!'; + $done = $this->saveShareVideo($content, $title, $tagName); + $msg = $done ? '视频保存完成,系统开始自动处理,1 - 3 分钟后刷新就能看到新添加的视频了。' : '视频保存失败,请稍后重试!'; + + //更新统计数据 + if ($done) { + $stats = TajianStats::init(); + TajianStats::increase('video'); + $saved = TajianStats::save(); + } } return $this->renderJson(compact('code', 'msg', 'err')); @@ -661,6 +670,11 @@ eof; Common::saveFriendsCode($cellphone); Common::initUserData($cellphone, $friends_code); + //更新统计数据 + $stats = TajianStats::init(); + TajianStats::increase('user'); + $saved = TajianStats::save(); + $shareUrl = "/{$newUser['username']}/"; $msg = "注册完成,开始收藏你喜欢的视频吧,正在为你跳转到专属网址..."; $code = 1; @@ -924,6 +938,11 @@ eof; //保存 $saved = $this->deleteTag($tag_to_delete); if (!empty($saved)) { + //更新统计数据 + $stats = TajianStats::init(); + TajianStats::decrease('tag'); + $saved = TajianStats::save(); + $msg = "分类已删除"; $code = 1; }else { @@ -998,6 +1017,11 @@ eof; //保存 $saved = $this->addTag(ucfirst($tag_to_add)); if (!empty($saved)) { + //更新统计数据 + $stats = TajianStats::init(); + TajianStats::increase('tag'); + $saved = TajianStats::save(); + $msg = "分类已添加"; $code = 1; }else { @@ -1070,6 +1094,12 @@ eof; //删除此视频的所有文件 $saved = $this->deleteVideoFiles($video_filename); if (!empty($saved)) { + //更新统计数据 + $stats = TajianStats::init(); + TajianStats::decrease('video'); + $saved = TajianStats::save(); + + $msg = "视频已删除"; $code = 1; }else { diff --git a/themes/tajian/controller/SiteController.php b/themes/tajian/controller/SiteController.php index 0b0364f..7330bc0 100644 --- a/themes/tajian/controller/SiteController.php +++ b/themes/tajian/controller/SiteController.php @@ -5,6 +5,7 @@ require_once __DIR__ . '/../../../lib/DirScanner.php'; require_once __DIR__ . '/../../../plugins/Parsedown.php'; require_once __DIR__ . '/../../../plugins/Common.php'; +require_once __DIR__ . '/../../../plugins/TajianStats.php'; Class SiteController extends Controller { @@ -207,6 +208,11 @@ Class SiteController extends Controller { rename($tagFile, $newTagFile); }else { unlink($tagFile); + + //更新统计数据 + $stats = TajianStats::init(); + TajianStats::decrease('tag'); + $saved = TajianStats::save(); } } }