예제 #1
0
 public function actionGene_pwd()
 {
     if (!Yii::$app->request->isPost) {
         return $this->renderJSON([], "系统繁忙,请稍后重试", -1);
     }
     return $this->renderJSON(['pwd' => UtilHelper::gene_password([1, 2])]);
 }
예제 #2
0
 private function search($params = [])
 {
     $p = isset($params['p']) ? $params['p'] : 1;
     $type = isset($params['type']) ? $params['type'] : 1;
     $offset = ($p - 1) * $this->page_size;
     $query = Posts::find()->where(['status' => 1]);
     switch ($type) {
         case 2:
             $query->orderBy(['view_count' => SORT_DESC]);
             break;
         case 3:
             $query->andWhere(['original' => 1]);
             $query->orderBy(['id' => SORT_DESC]);
             break;
         default:
             $query->orderBy(['id' => SORT_DESC]);
             break;
     }
     $posts_info = $query->offset($offset)->limit($this->page_size)->all();
     $data = [];
     if ($posts_info) {
         foreach ($posts_info as $_post) {
             $tmp_tags = explode(",", $_post['tags']);
             $data[] = ['title' => DataHelper::encode($_post['title']), 'content' => nl2br(UtilHelper::blog_short($_post['content'], 200)), "tags" => $tmp_tags, 'image_url' => $_post['image_url'], 'view_url' => UrlService::buildWapUrl("/default/info", ["id" => $_post['id']])];
         }
     }
     return $data;
 }
예제 #3
0
 public function beforeAction($action)
 {
     $this->setTitle();
     $this->setSubTitle();
     $this->setDescription();
     $this->setKeywords();
     \Yii::$app->response->getHeaders()->set("Content-Security-Policy", UtilHelper::getCspHeader(YII_ENV));
     //微信被封了
     //        $login_status = $this->checkLoginStatus();
     //
     //        if (!$login_status && !in_array($action->getUniqueId(), $this->allowAllAction)) {
     //            if( UtilHelper::isWechat() ){
     //                if(\Yii::$app->request->isAjax){
     //                    $this->renderJSON([],"未登录,请返回用户中心",-302);
     //                }else{
     //                    $redirect_url = UrlService::buildUrl("/weixin/oauth/login",['referer' =>  $this->getLoginUrl() ]);
     //                    $this->redirect( $redirect_url );
     //                }
     //                return false;
     //            }
     //
     //
     //        }
     if (!$this->getUUID()) {
         $this->setUUID();
     }
     return true;
 }
예제 #4
0
 public static function addCspReport($content)
 {
     $json_content = @json_decode($content, true);
     $target = new AdCspReport();
     $target->url = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '';
     $target->ip = UtilHelper::getClientIP();
     $target->report_content = $content;
     if ($json_content && isset($json_content['csp-report'])) {
         if (isset($json_content['csp-report']['blocked-uri'])) {
             $blocked_uri = parse_url($json_content['csp-report']['blocked-uri']);
             $tmp_port = isset($blocked_uri['port']) ? $blocked_uri['port'] : '';
             $blocked_uri = $blocked_uri['host'];
             if ($tmp_port) {
                 $blocked_uri .= ":{$tmp_port}";
             }
             $target->blocked_uri = $blocked_uri;
         }
         if (isset($json_content['csp-report']['source-file'])) {
             $target->source_file = $json_content['csp-report']['source-file'];
         }
     }
     $target->ua = isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : '';
     $target->updated_time = date("Y-m-d H:i:s");
     $target->created_time = date("Y-m-d H:i:s");
     $target->save(0);
 }
예제 #5
0
 public static function recordAccess_log($params)
 {
     $target_type = isset($params['target_type']) ? $params['target_type'] : 0;
     $target_id = isset($params['target_id']) ? $params['target_id'] : 0;
     $act_type = isset($params['act_type']) ? $params['act_type'] : 0;
     $note = isset($params['note']) ? $params['note'] : [];
     $status = isset($params['status']) ? $params['status'] : 1;
     $login_name = isset($params['login_name']) ? $params['login_name'] : '';
     $get_params = \Yii::$app->request->get();
     $post_params = \Yii::$app->request->post();
     if (isset($get_params['passwd'])) {
         unset($get_params['passwd']);
     }
     if (isset($post_params['passwd'])) {
         unset($post_params['passwd']);
     }
     $access_log = new AdminAccessLog();
     $access_log->target_type = $target_type;
     $access_log->act_type = $act_type;
     $access_log->login_name = $login_name;
     $access_log->target_id = $target_id;
     $access_log->refer_url = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '';
     $access_log->target_url = isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : '';
     $access_log->query_params = json_encode(array_merge($get_params, $post_params));
     $access_log->ua = isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : '';
     $access_log->ip = UtilHelper::getClientIP();
     $access_log->note = json_encode($note);
     $access_log->status = $status;
     $access_log->created_time = date("Y-m-d H:i:s");
     $access_log->save(0);
 }
예제 #6
0
 public static function getFrontCache($attr_key = '')
 {
     $cache = new FileCache();
     $cache_key = "tag_post";
     $root_path = UtilHelper::getRootPath();
     $cache->cachePath = $root_path . '/common/logs/cache';
     $data = $cache[$cache_key];
     $data = $data ? $data : self::buildFront(true);
     $data_attr = json_decode($data, true);
     return $attr_key ? $data_attr[$attr_key] : $data_attr;
 }
예제 #7
0
 public function actionInfo()
 {
     $id = intval($this->post("id", 0));
     if (!$id) {
         return $this->renderJSON([], "指定博文不存在", -1);
     }
     $post_info = Posts::find()->where(['status' => 1, 'id' => $id])->one();
     if (!$post_info) {
         return $this->renderJSON([], "指定博文不存在", -1);
     }
     $tmp_tags = explode(",", $post_info['tags']);
     $content = preg_replace("/brush:(\\w+);toolbar:false/", "prettyprint linenums", $post_info['content']);
     $info = ['author' => ['name' => DataHelper::getAuthorName()], 'title' => $post_info['title'], 'content' => $content, "tags" => $tmp_tags, 'updated_time' => date("Y-m-d H:i", strtotime($post_info['updated_time']))];
     $share_info = ['title' => $post_info['title'], 'content' => UtilHelper::blog_short($post_info['content'], 200), 'url' => GlobalUrlService::buildWapUrl("/default/info", ['id' => $post_info['id']])];
     return $this->renderJSON(['info' => $info, 'share_info' => $share_info]);
 }
예제 #8
0
 public function beforeAction($action)
 {
     $this->setTitle();
     $this->setDescription();
     $this->setKeywords();
     Yii::$app->response->getHeaders()->set("Content-Security-Policy", UtilHelper::getCspHeader(YII_ENV));
     if (!UtilHelper::isPC() && !in_array($action->getUniqueId(), $this->ignoreRedirectAction)) {
         $url = UrlService::buildWapUrl("/" . $action->getUniqueId(), $_GET);
         $this->redirect($url);
         return false;
     }
     if (!in_array($action->getUniqueId(), $this->allowAllAction)) {
     }
     if (!$this->getUUID()) {
         $this->setUUID();
     }
     return true;
 }
예제 #9
0
 public function actionDo()
 {
     $kw = trim($this->get("kw", ""));
     $p = intval($this->get("p", 1));
     if (!$p) {
         $p = 1;
     }
     $data = [];
     if (!$kw) {
         return $this->redirect("/");
     }
     $this->setTitle($kw);
     $pagesize = 10;
     $offset = ($p - 1) * $pagesize;
     $search_key = ['LIKE', 'search_key', '%' . strtr($kw, ['%' => '\\%', '_' => '\\_', '\\' => '\\\\']) . '%', false];
     $query = IndexSearch::find()->where($search_key);
     $total_count = $query->count();
     $list = $query->orderBy("id desc")->limit($pagesize)->offset($offset)->all();
     if ($list) {
         $book_mapping = DataHelper::getDicByRelateID($list, Book::className(), "book_id", "id", ["subtitle", "summary", "origin_image_url", "tags"]);
         $post_mapping = DataHelper::getDicByRelateID($list, Posts::className(), "post_id", "id", ["title", "content", "tags"]);
         foreach ($list as $_item) {
             if ($_item['book_id']) {
                 $tmp_target = $book_mapping[$_item['book_id']];
                 $tmp_content = mb_substr($tmp_target['summary'], 0, 105, "utf-8");
                 $tmp_title = DataHelper::encode($tmp_target['subtitle']);
                 $tmp_view_url = Url::toRoute("/library/detail/{$_item['book_id']}");
             } else {
                 $tmp_target = $post_mapping[$_item['post_id']];
                 $tmp_content = UtilHelper::blog_summary($tmp_target['content'], 105);
                 $tmp_title = DataHelper::encode($tmp_target['title']);
                 $tmp_view_url = Url::toRoute("/default/{$_item['post_id']}");
             }
             $tags = explode(",", $tmp_target['tags']);
             $data[] = ['title' => $tmp_title, 'content' => nl2br($tmp_content), 'tags' => $tags, 'date' => date("Y年m月d日"), 'view_url' => $tmp_view_url];
         }
     }
     $page_info = DataHelper::ipagination(["total_count" => $total_count, "page_size" => $pagesize, "page" => $p, "display" => 5]);
     return $this->render("result", ["data" => $data, "page_info" => $page_info, "urls" => ["page_base" => Url::toRoute(["/search/do", "kw" => $kw])]]);
 }
예제 #10
0
 public function actionIndex()
 {
     $type = intval($this->get("type", 1));
     $type = in_array($type, [1, 2, 3]) ? $type : 1;
     $p = intval($this->get("p", 1));
     if (!$p) {
         $p = 1;
     }
     $data = [];
     $pagesize = 10;
     $offset = ($p - 1) * $pagesize;
     $query = Posts::find()->where(['status' => 1]);
     switch ($type) {
         case 2:
             $query->orderBy(['view_count' => SORT_DESC]);
             break;
         case 3:
             $query->andWhere(['original' => 1]);
             $query->orderBy(['id' => SORT_DESC]);
             break;
         default:
             $query->orderBy(['id' => SORT_DESC]);
             break;
     }
     $total_count = $query->count();
     $posts_info = $query->offset($offset)->limit($pagesize)->all();
     if ($posts_info) {
         $idx = 1;
         $author = Yii::$app->params['author'];
         foreach ($posts_info as $_post) {
             $tmp_content = UtilHelper::blog_summary($_post['content'], 105);
             $tags = explode(",", $_post['tags']);
             $data[] = ['idx' => $idx, 'id' => $_post['id'], 'title' => DataHelper::encode($_post['title']), 'content' => nl2br($tmp_content), 'original' => $_post['original'], 'view_count' => $_post['view_count'], 'author' => $author, 'tags' => $tags, 'date' => date("Y.m.d", strtotime($_post['updated_time'])), 'view_url' => UrlService::buildUrl("/default/info", ["id" => $_post['id']])];
         }
     }
     $page_info = DataHelper::ipagination(["total_count" => $total_count, "page_size" => $pagesize, "page" => $p, "display" => 5]);
     $tags = CacheHelperService::getFrontCache("tag");
     return $this->render("index", ["data" => $data, "page_info" => $page_info, "type" => $type, "hot_kws" => array_slice($tags, 0, 5)]);
 }
예제 #11
0
 public function actionDo()
 {
     $data = [];
     $kw = $this->get("kw", "");
     if ($kw) {
         $this->setTitle($kw);
         $search_key = ['LIKE', 'search_key', '%' . strtr($kw, ['%' => '\\%', '_' => '\\_', '\\' => '\\\\']) . '%', false];
         $query = IndexSearch::find()->where($search_key);
         $list = $query->orderBy("id desc")->all();
         if ($list) {
             foreach ($list as $_item) {
                 if ($_item['book_id']) {
                     $tmp_title = DataHelper::encode($_item['title']);
                     $tmp_view_url = UrlService::buildWapUrl("/library/info", ['id' => $_item['book_id']]);
                 } else {
                     $tmp_title = DataHelper::encode($_item['title']);
                     $tmp_view_url = UrlService::buildWapUrl("/default/info", ['id' => $_item['post_id']]);
                 }
                 $data[] = ['title' => $tmp_title, 'content' => nl2br(UtilHelper::blog_short($_item['description'], 200)), 'image_url' => $_item['image'], 'view_url' => $tmp_view_url];
             }
         }
     }
     return $this->render("do", ["post_list" => $data, 'kw' => $kw]);
 }
예제 #12
0
 public static function buildMateUrl($uri, $params = [])
 {
     $path = Url::toRoute(array_merge(["/mate" . $uri], $params));
     $domain_blog = \Yii::$app->params['domains']['blog'];
     if (UtilHelper::is_SSL()) {
         $domain_blog = str_replace("http://", "https://", $domain_blog);
     }
     return $domain_blog . $path;
 }
예제 #13
0
 public function setUUID()
 {
     $this->setCookie(Constant::$uuid_cookie_name, UtilHelper::gene_guid(), 60 * 60 * 24 * 30);
 }
예제 #14
0
 public function actionUeditor()
 {
     $action = $this->get("action");
     $config_path = UtilHelper::getRootPath() . "/admin/web/ueditor/upload_config.json";
     $config = json_decode(preg_replace("/\\/\\*[\\s\\S]+?\\*\\//", "", file_get_contents($config_path)), true);
     switch ($action) {
         case 'config':
             echo json_encode($config);
             break;
             /* 上传图片 */
         /* 上传图片 */
         case 'uploadimage':
             /* 上传涂鸦 */
         /* 上传涂鸦 */
         case 'uploadscrawl':
             /* 上传视频 */
         /* 上传视频 */
         case 'uploadvideo':
             /* 上传文件 */
         /* 上传文件 */
         case 'uploadfile':
             $this->uploadUeditorImage();
             break;
         case 'listimage':
             $this->listUeditorImage();
             break;
     }
 }
예제 #15
0
 public function actionAdd()
 {
     $referer = trim($this->get("referer", ""));
     $screen = trim($this->get("screen", ""));
     $target_url = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : "";
     if ($target_url) {
         $blog_id = 0;
         preg_match("/\\/default\\/(\\d+)(.html)?/", $target_url, $matches);
         if ($matches && count($matches) >= 2) {
             $blog_id = $matches[1];
         }
         $tmp_source = 'direct';
         if ($referer) {
             $tmp_source = parse_url($referer, PHP_URL_HOST);
             if (stripos($tmp_source, "www.google.") !== false) {
                 $tmp_source = "www.google.com";
             }
         }
         $uuid = $this->getUUID();
         $uuid = ltrim($uuid, "{");
         $uuid = rtrim($uuid, "}");
         $model_ac_log = new AccessLogs();
         $model_ac_log->referer = $referer;
         $model_ac_log->target_url = $target_url;
         $model_ac_log->blog_id = $blog_id;
         $model_ac_log->source = $tmp_source ? $tmp_source : '';
         $model_ac_log->user_agent = isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : "";
         if ($model_ac_log->user_agent) {
             $tmp_browser = new Browser($model_ac_log->user_agent);
             $tmp_os = new Os($model_ac_log->user_agent);
             $tmp_device = new Device($model_ac_log->user_agent);
             $model_ac_log->client_browser = $tmp_browser->getName() ? $tmp_browser->getName() : '';
             $model_ac_log->client_browser_version = $tmp_browser->getVersion() ? $tmp_browser->getVersion() : '';
             $model_ac_log->client_os = $tmp_os->getName() ? $tmp_os->getName() : '';
             $model_ac_log->client_os_version = $tmp_os->getVersion() ? $tmp_os->getVersion() : '';
             $model_ac_log->client_device = $tmp_device->getName() ? $tmp_device->getName() : '';
             if ($model_ac_log->client_device == "unknown" && UtilHelper::isPC()) {
                 $model_ac_log->client_device = "pc";
             }
         }
         $model_ac_log->ip = UtilHelper::getClientIP();
         $model_ac_log->uuid = $uuid;
         if ($screen) {
             list($client_width, $client_height) = explode("/", $screen);
             if ($client_width) {
                 $model_ac_log->client_width = $client_width;
             }
             if ($client_height) {
                 $model_ac_log->client_height = $client_height;
             }
         }
         $model_ac_log->created_time_min = date("Y-m-d H:i");
         $model_ac_log->created_time = date("Y-m-d H:i:s");
         $model_ac_log->save();
         /*更新文章阅读量*/
         if ($blog_id) {
             $blog_info = Posts::findOne(['id' => $blog_id]);
             if ($blog_info) {
                 $blog_info->view_count += 1;
                 $blog_info->update(0);
             }
         }
     }
 }