protected function getLoginUrl() { $refer = \Yii::$app->request->getPathInfo(); if (isset($_SERVER['QUERY_STRING']) && $_SERVER['QUERY_STRING']) { $refer .= "@|@" . str_replace("&", "@@", $_SERVER['QUERY_STRING']); } return UrlService::buildUrl("/" . urlencode($refer)); }
public function actionError() { AppLogService::addLog(); $reback_url = UrlService::buildUrl("/"); if (preg_match("/^wap/", Yii::$app->request->getPathInfo())) { $reback_url = UrlService::buildWapUrl("/"); } $this->layout = false; return $this->render("index", ["title" => "Page Not Found", "msg" => "404警告! 很不幸,您探索了一个未知领域!", "reback_url" => $reback_url]); }
public function actionStep() { $type = $this->get("type", "daily"); $total_step = 0; $data_step = []; $x_cat = []; if ($type == "monthly") { $avg = 6000; $step = 3; $total_days = 0; $date_to = date("Ymd"); $date_from = date("Ymd", strtotime(' -30 day')); $step_list = HealthDay::find()->where([">=", "date", $date_from])->andWhere(["<=", "date", $date_to])->orderBy("id asc")->all(); if ($step_list) { foreach ($step_list as $_one_step) { $data_step[] = $_one_step["quantity"]; $x_cat[] = (strtotime($_one_step['date']) + 8 * 3600) * 1000; $total_days++; $total_step += $_one_step["quantity"]; } } $title = '<span class="sub_title">步数<br/><span>日平均值:' . ceil($total_step / $total_days) . '</span></span>'; $sub_title = '<span class="sub_title">' . number_format($total_step) . ' 步<br/><span>' . "{$date_from} ~ {$date_to}</span></span>"; } else { $avg = 40; $step = 3; $date_to = ""; $date_from = ""; $step_list = HealthLog::find()->where(["date" => date("Ymd")])->orderBy("id asc")->all(); if ($step_list) { $date_from = date("H:i", strtotime($step_list[0]['time_from'])); foreach ($step_list as $_one_step) { $data_step[] = $_one_step["quantity"]; $total_step += $_one_step["quantity"]; $x_cat[] = (strtotime($_one_step['time_from']) + 8 * 3600) * 1000; $date_to = date("H:i", strtotime($_one_step['time_from'])); } } $title = '<span class="sub_title">步数<br/><span>小时平均值:' . ceil($total_step / date("H")) . '</span></span>'; $sub_title = '<span class="sub_title">' . number_format($total_step) . ' 步<br/><span>' . "{$date_from} ~ {$date_to}</span></span>"; } $data = ['data' => $data_step, 'x_cat' => $x_cat, 'avg' => $avg, 'step' => $step, 'title' => $title, 'sub_title' => $sub_title]; return $this->render("step", ['data' => json_encode($data), 'type' => $type, 'urls' => ["daily" => UrlService::buildUrl("/run/step", ["type" => "daily"]), "monthly" => UrlService::buildUrl("/run/step", ["type" => "monthly"])]]); }
public function beforeAction($action) { $this->setTitle(); $this->setSubTitle(); $this->setDescription(); $this->setKeywords(); if (!in_array($action->getUniqueId(), $this->allowAllAction)) { if (!$this->checkLoginStatus()) { if (\Yii::$app->request->isAjax) { $this->renderJSON([], "未登录,请返回用户中心", -302); } else { $redirect_url = UrlService::buildUrl("/weixin/oauth/login", ['source' => "mate"]); $this->redirect($redirect_url); } return false; } } return true; }
public function actionInfo($id) { $id = intval($id); if (!$id) { return $this->goHome(); } $post_info = Posts::findOne(['id' => $id, 'status' => 1]); if (!$post_info) { return $this->goHome(); } $author = Yii::$app->params['author']; $tags = explode(",", $post_info['tags']); $content = preg_replace("/brush:(\\w+);toolbar:false/", "prettyprint linenums", $post_info['content']); $content = str_replace("<pre>", "<pre class='prettyprint linenums'>", $content); $data = ["id" => $post_info['id'], "title" => $post_info['title'], "content" => $content, "original" => $post_info['original'], 'view_count' => $post_info['view_count'], "tags" => $tags, 'date' => date("Y.m.d", strtotime($post_info['updated_time'])), 'author' => $author, "url" => UrlService::buildUrl("/default/info", ["id" => $post_info['id']])]; $prev_info = Posts::find()->where(["<", "id", $id])->andWhere(['status' => 1])->orderBy("id desc")->one(); $next_info = Posts::find()->where([">", "id", $id])->andWhere(['status' => 1])->orderBy("id asc")->one(); $this->setTitle($post_info['title']); return $this->render("detail", ["info" => $data, "prev_info" => $prev_info, "next_info" => $next_info, "recommend_blogs" => RecommendService::getRecommendBlog($id)]); }
public static function buildFront($refresh = false) { $cache = new FileCache(); $cache_key = "tag_post"; $root_path = UtilHelper::getRootPath(); $cache->cachePath = $root_path . '/common/logs/cache'; $data = $cache[$cache_key]; if (!$data || $refresh) { $data = ["tag" => [], "post_hot" => [], "post_origin" => [], "post_latest" => []]; $tags = PostsTags::find()->select("tag,count(*) as num ")->groupBy("tag")->orderBy("num desc")->limit(20)->all(); if ($tags) { foreach ($tags as $_tag) { $data['tag'][] = $_tag['tag']; } } $post_hot = Posts::find()->where(['status' => 1])->orderBy(['view_count' => SORT_DESC])->limit(10)->all(); if ($post_hot) { foreach ($post_hot as $_post_info) { $data['post_hot'][] = ["id" => $_post_info['id'], "title" => DataHelper::encode($_post_info["title"]), "detail_url" => UrlService::buildUrl("/default/info", ["id" => $_post_info['id']])]; } } $post_origin = Posts::find()->where(['status' => 1, 'original' => 1])->orderBy(['id' => SORT_DESC])->limit(10)->all(); if ($post_origin) { foreach ($post_origin as $_post_info) { $data['post_origin'][] = ["id" => $_post_info['id'], "title" => DataHelper::encode($_post_info["title"]), "detail_url" => UrlService::buildUrl("/default/info", ["id" => $_post_info['id']])]; } } $post_latest = Posts::find()->where(['status' => 1])->orderBy(['id' => SORT_DESC])->limit(10)->all(); if ($post_latest) { foreach ($post_latest as $_post_info) { $data['post_latest'][] = ["id" => $_post_info['id'], "title" => DataHelper::encode($_post_info["title"]), "detail_url" => UrlService::buildUrl("/default/info", ["id" => $_post_info['id']])]; } } $data = json_encode($data); $cache[$cache_key] = $data; } return $data; }
</div> <div class="widget hidden content_index_wrap"> <h4 class="title">目录</h4> <div class="content"> </div> </div> <div class="widget"> <h4 class="title">智能推荐</h4> <div class="content recommend_posts"> <?php foreach ($recommend_blogs as $_recommend_blog_info) { ?> <p> <a href="<?php echo UrlService::buildUrl("/default/info", ["id" => $_recommend_blog_info["id"], "flag" => "recommend", "source_id" => $_recommend_blog_info['source_id']]); ?> "><?php echo $_recommend_blog_info["title"]; ?> </a> </p> <?php } ?> </div> </div> <div class="widget hide"> <h4 class="title">阅读目录</h4> <div class="content" id="content">
public function actionSitemap() { $data = []; $tags = []; $type = $this->get("type", "blog"); switch ($type) { case "m": $domain_host = Yii::$app->params['domains']['m']; $sitemap_filename = "m_sitemap.xml"; break; default: $domain_host = Yii::$app->params['domains']['blog']; $sitemap_filename = "sitemap.xml"; break; } $index_urls = ['m' => ["/default/index?type=1", "/default/index?type=2", "/default/index?type=3", "/library/index", "/richmedia/index", "/my/about", "http://www.vincentguo.cn"], 'blog' => ["/default/index?type=1", "/default/index?type=2", "/default/index?type=3", "/library/index", "/richmedia/index", "/default/donation", "/default/about", "http://m.vincentguo.cn"]]; if (isset($index_urls[$type])) { foreach ($index_urls[$type] as $_index_url) { if (preg_match("/^http/", $_index_url)) { $tmp_url = $_index_url; } else { if ($type == "m") { $tmp_url = UrlService::buildWapUrl($_index_url); } else { $tmp_url = UrlService::buildUrl($_index_url); } } $data[] = ["loc" => $tmp_url, "priority" => 1.0, "lastmod" => date("Y-m-d"), "changefreq" => "daily"]; } } $post_list = Posts::find()->where(["status" => 1])->orderBy("id desc")->all(); if ($post_list) { foreach ($post_list as $_post_info) { if ($type == "m") { $tmp_url = UrlService::buildWapUrl("/default/info", ["id" => $_post_info['id']]); } else { $tmp_url = UrlService::buildUrl("/default/info", ["id" => $_post_info['id']]); } $data[] = ["loc" => $tmp_url, "priority" => 1.0, "lastmod" => date("Y-m-d", strtotime($_post_info['updated_time'])), "changefreq" => "daily"]; $tmp_tags = explode(",", $_post_info['tags']); $tags = array_merge($tags, $tmp_tags); } } $book_list = Book::find()->where(['status' => 1])->orderBy("id desc")->all(); if ($book_list) { foreach ($book_list as $_book_info) { if ($type == "m") { $tmp_url = UrlService::buildWapUrl("/library/info", ["id" => $_book_info['id']]); } else { $tmp_url = UrlService::buildUrl("/library/info", ["id" => $_book_info['id']]); } $data[] = ["loc" => $tmp_url, "priority" => 1.0, "lastmod" => date("Y-m-d", strtotime($_book_info['updated_time'])), "changefreq" => "daily"]; $tmp_tags = explode(",", $_book_info['tags']); $tags = array_merge($tags, $tmp_tags); } } $tags = array_unique($tags); if ($tags) { foreach ($tags as $_tag) { if ($type == "m") { $tmp_url = UrlService::buildWapUrl("/search/do", ["kw" => $_tag]); } else { $tmp_url = UrlService::buildUrl("/search/do", ["kw" => $_tag]); } $data[] = ["loc" => $tmp_url, "priority" => 1.0, "lastmod" => date("Y-m-d", time()), "changefreq" => "daily"]; } } $xml_content = $this->renderPartial("sitemap", ["data" => $data]); $app_root = Yii::$app->getBasePath(); $file_path = $app_root . "/web/{$sitemap_filename}"; file_put_contents($file_path, $xml_content); $this->layout = false; return "ok"; }
<?php } ?> <span class="page-number">第 <?php echo $page_info['current']; ?> 页 ⁄ 共 <?php echo $page_info['total_page']; ?> 页</span> <?php if ($page_info['next']) { ?> <a class="older-posts" href="<?php echo UrlService::buildUrl("/default/index", ["type" => $type, "p" => $page_info['current'] + 1]); ?> " title="下一页"><i class="fa fa-angle-right"></i></a> <?php } ?> </nav> <?php } ?> </main> <?php echo Yii::$app->controller->renderPartial("/public/side"); ?>
<article class="post"> <table class="table table-bordered text-center"> <thead> <tr> <td>赞助人</td> <td>赞助金额</td> <td width="200">赞助原因</td> </tr> </thead> <tbody> <tr> <td>唐萪衷</td> <td>88.00</td> <td class="text-left"> 做档案录入需要拍照上传保存,参考博文:<a target="_blank" href="<?php echo UrlService::buildUrl('/default/info', ['id' => 150]); ?> ">HTML5 拍照上传</a> </td> </tr> </tbody> </table> </article> </div> <div class="col-md-4 sidebar"> <div class="widget"> <h4 class="title">感谢您的支持</h4> <div class="content m_qrcode"> <img title="扫一扫手机阅读" src="<?php echo GlobalUrlService::buildStaticUrl("/images/pay/pay_wechat.jpg"); ?>
?> "><i class="fa fa-angle-left fa-fw"></i> <?php echo DataHelper::encode($prev_info['title']); ?> </a> <?php } ?> <?php if ($next_info) { ?> <a class="btn btn-default" href="<?php echo UrlService::buildUrl("/default/info", ["id" => $next_info['id'], "flag" => "next"]); ?> "><?php echo DataHelper::encode($next_info['title']); ?> <i class="fa fa-angle-right fa-fw"></i></a> <?php } ?> </div> </main> <?php echo Yii::$app->controller->renderPartial("/public/blog_side", ["recommend_blogs" => $recommend_blogs, "qr_text" => GlobalUrlService::buildWapUrl("/default/info", ['id' => $info['id']])]); ?>
public static function blogMenu() { $menu = ['blog' => ['title' => '文章', 'url' => GlobalUrlService::buildBlogUrl("/")], 'library' => ['title' => '图书馆', 'url' => GlobalUrlService::buildBlogUrl("/library/index")], 'donation' => ['title' => '赞助', 'url' => GlobalUrlService::buildBlogUrl("/default/donation")], 'project' => ['title' => '项目', 'sub_menu' => [['title' => '二维码登录', 'url' => UrlService::buildUrl("/default/info", ['id' => 21])], ['title' => '微信墙', 'url' => UrlService::buildUrl("/default/info", ['id' => 132])], ['title' => '私人github', 'url' => UrlService::buildUrl("/default/info", ['id' => 96])], ['title' => 'QQ音乐', 'url' => UrlService::buildUrl("/default/info", ['id' => 80])], ['title' => 'metaweblog', 'url' => UrlService::buildUrl("/default/info", ['id' => 91])], ['title' => 'H5拍照上传', 'url' => UrlService::buildUrl("/default/info", ['id' => 150])], ['title' => '条形码和二维码', 'url' => UrlService::buildUrl("/default/info", ['id' => 152])], ['title' => '【运维工具】Git代码发布系统', 'url' => UrlService::buildUrl("/default/info", ['id' => 151])]]], 'tools' => ['title' => '小工具', 'sub_menu' => [['title' => '密码生成器', 'url' => GlobalUrlService::buildGameUrl("/tools/index")], ['title' => '字符长度统计', 'url' => GlobalUrlService::buildGameUrl("/tools/strlen")], ['title' => 'JSON格式化', 'url' => GlobalUrlService::buildGameUrl("/tools/json_format")], ['title' => '点歌台', 'url' => GlobalUrlService::buildGameUrl("/music/index")], ['title' => 'Code Preview', 'url' => GlobalUrlService::buildBlogUrl("/code/run")]]], 'business' => ['title' => '商业合作', 'tip' => '定制开发程序,数据库维护,服务器运维', 'url' => GlobalUrlService::buildBlogUrl("/business/index"), 'status' => 0], 'about' => ['title' => '关于', 'sub_menu' => [['title' => '编程浪子', 'url' => GlobalUrlService::buildBlogUrl("/default/about")], ['title' => '富媒体', 'url' => GlobalUrlService::buildBlogUrl("/richmedia/index")], ['title' => '更新日志', 'url' => GlobalUrlService::buildBlogUrl("/default/change-log")]]]]; return $menu; }