public function actionInfo($id) { $id = intval($id); if (!$id) { return $this->goLibraryHome(); } $book_info = Book::find()->where(['id' => $id, 'status' => 1])->one(); if (!$book_info) { return $this->goLibraryHome(); } $data = []; $author = json_decode($book_info['creator'], true); $data['name'] = DataHelper::encode($book_info['name']); $data['title'] = DataHelper::encode($book_info['subtitle']); $data['summary'] = nl2br(DataHelper::encode($book_info['summary'])); $data['publish_date'] = $book_info['publish_date']; $data['author'] = implode(" ~ ", $author); $data['tags'] = explode(",", $book_info['tags']); $data['read_status_info'] = Constant::$read_desc[$book_info['read_status']]; $data['image_url'] = GlobalUrlService::buildPic1Static($book_info['image_url'], ['w' => 500]); $data['isbn'] = $book_info['isbn']; $prev_info = Book::find()->where(["<", "id", $id])->andWhere(['status' => 1])->orderBy("id desc")->one(); $next_info = Book::find()->where([">", "id", $id])->andWhere(['status' => 1])->orderBy("id asc")->one(); $this->setTitle($book_info['subtitle']); return $this->render("detail", ["info" => $data, "prev_info" => $prev_info, "next_info" => $next_info]); }
public function actionBuild() { $batch_data = []; $date_now = date("Y-m-d H:i:s"); $this->echoLog("=========start build({$date_now})=========="); /*build blog*/ $post_list = Posts::find()->where(['status' => 1])->orderBy("id asc")->all(); if ($post_list) { foreach ($post_list as $_post_info) { $tmp_search_key = $_post_info['title'] . "#@#" . $_post_info['tags']; $batch_data[] = ["title" => $_post_info['title'], "description" => strip_tags($_post_info['content']), "book_id" => 0, "post_id" => $_post_info['id'], "search_key" => $tmp_search_key, "image" => $_post_info['image_url']]; } } $book_list = Book::find()->where(['status' => 1])->orderBy("id asc")->all(); if ($book_list) { foreach ($book_list as $_book_info) { $tmp_search_key = $_book_info['subtitle'] . "#@#" . $_book_info['tags']; $batch_data[] = ["title" => $_book_info['subtitle'], "description" => $_book_info['summary'], "book_id" => $_book_info['id'], "post_id" => 0, "search_key" => $tmp_search_key, "image" => GlobalUrlService::buildPic1Static($_book_info['image_url'], ['w' => 600])]; } } if ($batch_data && count($batch_data) > 0) { //批量插入速度快 foreach ($batch_data as $_item) { if (!$_item['post_id'] && !$_item['book_id']) { $this->echoLog("skip"); continue; } $query = IndexSearch::find(); if ($_item['post_id']) { $query->where(['post_id' => $_item['post_id']]); } else { $query->where(['book_id' => $_item['book_id']]); } $tmp_info = $query->one(); if ($tmp_info) { $model_index_search = $tmp_info; } else { $model_index_search = new IndexSearch(); $model_index_search->created_time = $date_now; } $tmp_description = str_replace(" ", " ", $_item['description']); $model_index_search->title = $_item['title']; $model_index_search->description = $tmp_description; $model_index_search->book_id = $_item['book_id']; $model_index_search->post_id = $_item['post_id']; $model_index_search->search_key = $_item['search_key']; $model_index_search->image = $_item['image']; $model_index_search->updated_time = $date_now; $model_index_search->save(0); } } }
public function actionInfo($id) { $id = intval($id); if (!$id) { return $this->goHome(); } $book_info = Book::find()->where(['id' => $id])->one(); if (!$book_info) { return $this->goHome(); } $data = []; $author = json_decode($book_info['creator'], true); $data['name'] = DataHelper::encode($book_info['name']); $data['title'] = DataHelper::encode($book_info['subtitle']); $data['summary'] = nl2br(DataHelper::encode($book_info['summary'])); $data['publish_date'] = $book_info['publish_date']; $data['author'] = implode(" ~ ", $author); $data['tags'] = explode(",", $book_info['tags']); $data['image_url'] = $book_info['origin_image_url']; return $this->render("info", ["info" => $data]); }
private function search($params = []) { $p = isset($params['p']) ? $params['p'] : 1; $offset = ($p - 1) * $this->page_size; $query = Book::find()->where(['status' => 1]); $books = $query->orderBy("id desc")->offset($offset)->limit($this->page_size)->all(); $data = []; if ($books) { foreach ($books as $_book) { $tmp_author = @json_decode($_book['creator'], true); $tmp_author = $tmp_author ? $tmp_author[0] : ' '; if (stripos($tmp_author, "(") !== false) { $tmp_author = substr($tmp_author, 0, stripos($tmp_author, "(")); } if (stripos($tmp_author, "(") !== false) { $tmp_author = substr($tmp_author, 0, stripos($tmp_author, "(")); } $data[] = ["title" => DataHelper::encode($_book['subtitle']), 'author' => $tmp_author ? $tmp_author : " ", 'imager_url' => GlobalUrlService::buildPic1Static($_book['image_url']), 'view_url' => UrlService::buildWapUrl("/library/info", ["id" => $_book["id"]])]; } } return $data; }
public function actionScan() { $type = trim($this->post("type", "EAN_13")); $code = trim($this->post("isbn")); $date_now = date("Y-m-d H:i:s"); //$this->recode("test"); if (!$type || !$code) { return $this->renderJSON([], "请输入参数type 和 isbn", -1); } $book_info = Book::find()->where(['isbn' => $code])->one(); if ($book_info) { return $this->renderJSON(["name" => $book_info['subtitle'], "origin_image_url" => $book_info['origin_image_url'], "isbn" => $book_info['isbn']]); } $ret = $this->doubanApi($code, $type); if (!$ret) { return $this->render([], "无法从豆瓣获取数据信息", -1); } $ret_upload = UploadService::uploadByUrl($ret['origin_image_url']); $model_book = new Book(); $model_book->isbn = $ret['isbn']; $model_book->bartype = $ret['bartype']; $model_book->name = $ret['name']; $model_book->subtitle = $ret['subtitle']; $model_book->creator = json_encode($ret['creator']); $model_book->binding = $ret['binding']; $model_book->pages = $ret['pages']; $model_book->publish_date = date("Y-m-d", strtotime($ret['publish_date'])); $model_book->publishing_house = $ret['publishing_house']; $model_book->tags = $ret['tags']; $model_book->summary = $ret['summary']; $model_book->image_url = $ret_upload ? $ret_upload['uri'] : ''; $model_book->origin_image_url = $ret['origin_image_url']; $model_book->status = 0; $model_book->updated_time = $date_now; $model_book->created_time = $date_now; $model_book->save(0); return $this->renderJSON(["name" => $ret['subtitle'], "origin_image_url" => $ret['origin_image_url'], "isbn" => $code]); }
public function actionIndex() { $data = ["posts" => [], "library" => [], 'summary' => []]; $total_posts = Posts::find()->count(); $total_valid_posts = Posts::find()->where(['status' => 1])->count(); $data['posts'] = ["total" => $total_posts, "total_valid" => $total_valid_posts]; $total_book = Book::find()->count(); $total_valid_book = Book::find()->where(['status' => 1])->count(); $data['library'] = ["total" => $total_book, "total_valid" => $total_valid_book]; /*画图*/ $date_from = date("Y-m-d", strtotime("-30 day")); $date_to = date("Y-m-d"); $stat_access_list = StatAccess::find()->where(['>=', "date", $date_from])->andWhere(['<=', "date", $date_to])->orderBy("date asc")->asArray()->all(); $data_access = ["categories" => [], "series" => [['name' => 'PV', 'data' => []], ['name' => 'UV', 'data' => []], ['name' => 'IP', 'data' => []]]]; if ($stat_access_list) { foreach ($stat_access_list as $_item) { $data_access['categories'][] = $_item['date']; $data_access['series'][0]['data'][] = intval($_item['total_number']); $data_access['series'][1]['data'][] = intval($_item['total_uv_number']); $data_access['series'][2]['data'][] = intval($_item['total_ip_number']); if ($_item['date'] >= date("Y-m-d", strtotime("-7 days"))) { $data['summary'][] = ['date' => $_item['date'], 'total_number' => $_item['total_number'], 'total_ip_number' => $_item['total_ip_number'], 'total_uv_number' => $_item['total_uv_number'], 'total_new_user_number' => $_item['total_new_user_number'], 'total_returned_user_number' => $_item['total_returned_user_number'], 'avg_pv_per_uv' => $_item['avg_pv_per_uv']]; } } $data['summary'] = array_reverse($data['summary']); } $stat_blog_list = StatBlog::find()->where(['>=', "date", $date_from])->andWhere(['<=', "date", $date_to])->orderBy("date asc")->asArray()->all(); $data_blog = ["categories" => [], "series" => [['name' => '已发布', 'data' => []], ['name' => '待发布', 'data' => []]]]; if ($stat_blog_list) { foreach ($stat_blog_list as $_item) { $data_blog['categories'][] = $_item['date']; $data_blog['series'][0]['data'][] = intval($_item['total_post_number']); $data_blog['series'][1]['data'][] = intval($_item['total_unpost_number']); } } $date_int = date("Ymd"); /*今日来源域名*/ $ignore_source = ["direct", "www.vincentguo.cn", "m.vincentguo.cn"]; $data_source = ['series' => [['data' => []]]]; $source_list = StatDailyAccessSource::find()->where(['date' => $date_int])->andWhere(['not in', 'source', $ignore_source])->orderBy(['total_number' => SORT_DESC])->asArray()->all(); if ($source_list) { $total_number = array_sum(array_column($source_list, "total_number")); foreach ($source_list as $_item) { $data_source['series'][0]['data'][] = ['name' => $_item['source'], 'y' => floatval(sprintf("%.2f", $_item['total_number'] / $total_number * 100)), 'total_number' => $_item['total_number']]; } } /*操作系统*/ $data_client_os = ['series' => [['data' => []]]]; $os_list = StatDailyOs::find()->where(['date' => $date_int])->orderBy(['total_number' => SORT_DESC])->asArray()->all(); if ($os_list) { $total_number = array_sum(array_column($os_list, "total_number")); foreach ($os_list as $_item) { $data_client_os['series'][0]['data'][] = ['name' => $_item['client_os'], 'y' => floatval(sprintf("%.2f", $_item['total_number'] / $total_number * 100)), 'total_number' => $_item['total_number']]; } } /*浏览器统计*/ $data_client_browser = ['series' => [['data' => []]]]; $client_browser_list = StatDailyBrowser::find()->where(['date' => $date_int])->orderBy(['total_number' => SORT_DESC])->asArray()->all(); if ($client_browser_list) { $total_number = array_sum(array_column($client_browser_list, "total_number")); foreach ($client_browser_list as $_item) { $data_client_browser['series'][0]['data'][] = ['name' => $_item['client_browser'], 'y' => floatval(sprintf("%.2f", $_item['total_number'] / $total_number * 100)), 'total_number' => $_item['total_number']]; } } /*设备统计*/ $data_client_device = ['series' => [['data' => []]]]; $client_device_list = StatDailyDevice::find()->where(['date' => $date_int])->orderBy(['total_number' => SORT_DESC])->asArray()->all(); if ($client_device_list) { $total_number = array_sum(array_column($client_device_list, "total_number")); foreach ($client_device_list as $_item) { $data_client_device['series'][0]['data'][] = ['name' => $_item['client_device'], 'y' => floatval(sprintf("%.2f", $_item['total_number'] / $total_number * 100)), 'total_number' => $_item['total_number']]; } } //环境变量 // $db_target = Yii::$app->get("blog"); // $db_target->createCommand("SELECT version() as version,user() as user")->queryOne(); $env = ['sys' => ['服务器' => $_SERVER["SERVER_SOFTWARE"], 'PHP版本' => PHP_VERSION, '操作系统' => php_uname(), '端口' => $_SERVER['SERVER_PORT'], '上传限制' => ini_get("file_uploads") ? ini_get("upload_max_filesize") : "Disabled"]]; return $this->render("index", ["stat" => $data, "data_access" => $data_access, "data_blog" => $data_blog, "data_client_os" => $data_client_os, 'data_source' => $data_source, 'data_client_browser' => $data_client_browser, 'data_client_device' => $data_client_device, 'env' => $env]); }
public function actionBook() { $p = intval($this->get("p", 1)); $offset = ($p - 1) * $this->page_size; $query = Book::find()->where(['status' => 1]); $books = $query->orderBy("id desc")->offset($offset)->limit($this->page_size)->all(); $data = []; if ($books) { foreach ($books as $_book) { $data[] = ['id' => $_book['id'], 'image_url' => GlobalUrlService::buildPic1Static($_book['image_url']), 'title' => $_book['subtitle']]; } } return $this->renderJSON(['list' => $data]); }
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"; }