예제 #1
0
 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]);
 }
예제 #2
0
 public function actionIndex()
 {
     $p = intval($this->get("p", 1));
     if (!$p) {
         $p = 1;
     }
     $data = [];
     $pagesize = 20;
     $query = RichMedia::find()->where(['status' => [0, 1]]);
     $total_count = $query->count();
     $offset = ($p - 1) * $pagesize;
     $rich_list = $query->orderBy("id desc")->offset($offset)->limit($pagesize)->all();
     $page_info = DataHelper::ipagination(["total_count" => $total_count, "page_size" => $pagesize, "page" => $p, "display" => 10]);
     if ($rich_list) {
         $idx = 1;
         $domains = Yii::$app->params['domains'];
         foreach ($rich_list as $_rich_info) {
             $tmp_small_pic_url = GlobalUrlService::buildPic1Static($_rich_info['src_url'], ['h' => 100]);
             $tmp_big_pic_url = GlobalUrlService::buildPic1Static($_rich_info['src_url'], ['w' => 600]);
             $data[] = ['idx' => $idx, 'id' => $_rich_info['id'], 'small_src_url' => $tmp_small_pic_url, 'big_src_url' => $tmp_big_pic_url, 'src_url' => $tmp_small_pic_url, 'thumb_url' => $_rich_info['thumb_url'] ? $_rich_info['thumb_url'] : $domains['static'] . "/wx/video_cover.jpg", 'type' => $_rich_info['type'], 'address' => $_rich_info['address'], 'status' => $_rich_info['status'], 'status_info' => $this->status_desc[$_rich_info['status']], 'created' => $_rich_info['created_time']];
             $idx++;
         }
     }
     return $this->render("index", ["data" => $data, "page_info" => $page_info]);
 }
예제 #3
0
 private function parseText($dataObj)
 {
     $keyword = trim($dataObj->Content);
     if (filter_var($keyword, FILTER_VALIDATE_URL) !== FALSE) {
         return ['type' => "text", 'data' => $this->urlTips()];
     }
     $cmd_tip = substr($keyword, 0, 1);
     switch ($cmd_tip) {
         case "@":
             //搜歌曲
             return $this->searchMusicByKw($keyword);
             break;
         case "#":
             //微信墙
             $bind_info = UserOpenidUnionid::findOne(['other_openid' => trim($dataObj->FromUserName)]);
             if ($bind_info) {
                 return 'success';
             }
             $keyword = "上墙";
             break;
     }
     switch ($keyword) {
         case "上墙":
             $data = [['title' => '点击授权签到', 'description' => \Yii::$app->params['author']['nickname'] . "微信墙,授权后方可上墙留言", 'picurl' => GlobalUrlService::buildPic1Static("/20160531/7ba8f923c344a5af480cd76dd358e196.jpg", ['w' => 800]), 'url' => GlobalUrlService::buildWapUrl("/wechat_wall/sign", ['woid' => trim($dataObj->FromUserName)])]];
             return ['type' => "rich", "data" => $this->getRichXml($data)];
             break;
     }
     return $this->getDataByKeyword($keyword, trim($dataObj->FromUserName));
 }
예제 #4
0
 public function actionReplace()
 {
     $post_list = Posts::find()->where(['status' => 1])->orderBy("id desc")->all();
     if ($post_list) {
         $domain_pic1 = \Yii::$app->params['domains']['pic1'];
         foreach ($post_list as $_post_info) {
             $this->echoLog("post_id:{$_post_info['id']}");
             $tmp_content = $_post_info['content'];
             preg_match_all('/<\\s*img\\s+[^>]*?src\\s*=\\s*(\'|\\")(.*?)\\1[^>]*?\\/?\\s*>/i', $tmp_content, $match_img);
             if ($match_img && count($match_img) == 3) {
                 foreach ($match_img[2] as $_img_src) {
                     if (stripos($_img_src, $domain_pic1) === false) {
                         continue;
                     }
                     $tmp_parse = parse_url($_img_src);
                     if ($tmp_parse && isset($tmp_parse['path'])) {
                         $tmp_url = GlobalUrlService::buildPic1Static($tmp_parse['path'], ['w' => 600]);
                         $tmp_content = str_replace($_img_src, $tmp_url, $tmp_content);
                     }
                 }
                 $_post_info->content = $tmp_content;
                 $_post_info->update(0);
             }
         }
     }
 }
예제 #5
0
 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("&nbsp;", " ", $_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);
         }
     }
 }
예제 #6
0
 private function search($params = [])
 {
     $p = isset($params['p']) ? $params['p'] : 1;
     $offset = ($p - 1) * $this->page_size;
     $query = RichMedia::find()->where(['status' => 1, 'type' => 'image']);
     $rich_media_list = $query->orderBy("id desc")->offset($offset)->limit($this->page_size)->all();
     $data = [];
     if ($rich_media_list) {
         foreach ($rich_media_list as $_rich_info) {
             $data[] = ['id' => $_rich_info['id'], 'type' => $_rich_info['type'], 'src_url' => GlobalUrlService::buildPic1Static($_rich_info['src_url']), 'address' => $_rich_info['address'], 'switch' => \Yii::$app->params['switch']['cdn']['pic1']];
         }
     }
     return $data;
 }
예제 #7
0
 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] : '&nbsp;';
             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 : "&nbsp;", 'imager_url' => GlobalUrlService::buildPic1Static($_book['image_url']), 'view_url' => UrlService::buildWapUrl("/library/info", ["id" => $_book["id"]])];
         }
     }
     return $data;
 }
예제 #8
0
 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]);
 }
예제 #9
0
 private function listUeditorImage()
 {
     $start = intval($this->get("start", 0));
     $page_size = intval($this->get("size", 20));
     $query = Images::find()->where(['bucket' => "pic1"]);
     if ($start) {
         $query->andWhere(['<', "id", $start]);
     }
     $list = $query->orderBy("id desc")->limit($page_size)->all();
     $images = [];
     $last_id = 0;
     if ($list) {
         foreach ($list as $_item) {
             $images[] = ['url' => GlobalUrlService::buildPic1Static($_item['filepath'], ['w' => 600]), 'mtime' => strtotime($_item['created_time']), 'width' => 300];
             $last_id = $_item['id'];
         }
     }
     header('Content-type: application/json');
     $data = ["state" => count($images) > 0 ? 'SUCCESS' : 'no match file', "list" => $images, "start" => $last_id, "total" => count($images)];
     echo json_encode($data);
     exit;
 }