public function run() { $tags = Tag::model()->findAll(); if ($tags) { foreach ($tags as $tag) { $post = Post::model()->findAll("FIND_IN_SET(:tag, tags)", array(':tag' => $tag->tag_name)); $image = Image::model()->findAll("FIND_IN_SET(:tag, tags)", array(':tag' => $tag->tag_name)); $soft = Soft::model()->findAll("FIND_IN_SET(:tag, seo_keywords)", array(':tag' => $tag->tag_name)); $video = Video::model()->findAll("FIND_IN_SET(:tag, seo_keywords)", array(':tag' => $tag->tag_name)); if (!$post && !$image && !$soft && !$video) { $tag->delete(); } else { $tag->data_count = count($post) + count($image) + count($soft); $tag->save(); } } } $tagdatas = TagData::model()->findAll(); if ($tagdatas) { foreach ($tagdatas as $value) { $modelType = ModelType::model()->findByPk($value->type); $model = $modelType->model; $data = $model::model()->findByPk($value->content_id); if (!$data) { $value->delete(); } } } $this->controller->message('success', Yii::t('admin', 'Reset Tags Success'), $this->controller->createUrl('index')); }
public function run() { $ids = Yii::app()->request->getParam('id'); $command = Yii::app()->request->getParam('command'); empty($ids) && $this->controller->message('error', Yii::t('admin', 'No Select')); if (!is_array($ids)) { $ids = array($ids); } $criteria = new CDbCriteria(); $criteria->addInCondition('id', $ids); switch ($command) { case 'delete': //删除 foreach ((array) $ids as $id) { $softModel = Soft::model()->findByPk($id); if ($softModel) { Uploader::deleteFile(ROOT_PATH . $softModel->soft_icon); Uploader::deleteFile(ROOT_PATH . $softModel->soft_file); } } Soft::model()->deleteAll($criteria); break; case 'show': //显示 Soft::model()->updateAll(['status' => 'Y'], $criteria); break; case 'hidden': //隐藏 Soft::model()->updateAll(['status' => 'N'], $criteria); break; default: throw new CHttpException(404, Yii::t('admin', 'Error Operation')); } $this->controller->message('success', Yii::t('admin', 'Batch Operate Success')); }
public function run() { //SEO $this->controller->_seoTitle = $this->controller->_setting['seo_title']; $this->controller->_seoKeywords = $this->controller->_setting['seo_keywords']; $this->controller->_seoDescription = $this->controller->_setting['seo_description']; //头部banner $index_top_banner = Ad::model()->getAdOne(4); //中部banner $index_mid_banner = Ad::model()->getAdOne(3); //底部banner $index_bottom_banner = Ad::model()->getAdOne(5); //最新资讯 $news_new = Post::model()->getList(array('limit' => 20)); //热门资讯 $news_hot = Post::model()->getList(array('order' => 't.view_count DESC, t.id DESC', 'limit' => 20)); //最新图集 $image_new = Image::model()->getList(array('limit' => 10)); //热门图集 $image_hot = Image::model()->getList(array('limit' => 10, 'order' => 'view_count DESC, t.id DESC')); //最新软件 $soft_new = Soft::model()->getList(array('limit' => 20)); //热门软件 $soft_hot = Soft::model()->getList(array('limit' => 10, 'order' => 'down_count DESC, t.id DESC')); //最新视频 $video_new = Video::model()->findAll("status=:status AND catalog_id = 13 ORDER BY id DESC Limit 20", array(':status' => 'Y')); //热门视频 $video_hot = Video::model()->findAll("status=:status AND catalog_id = 13 ORDER BY view_count DESC, video_score DESC, id DESC Limit 20", array(':status' => 'Y')); //友情链接 $link_logos = Link::model()->findAll("logo !='' AND status='Y'", array('order' => 'sortorder ASC, id DESC')); $link_texts = Link::model()->findAll("logo ='' AND status='Y'", array('order' => 'sortorder ASC, id DESC')); $this->controller->render('index', array('index_top_banner' => $index_top_banner, 'index_mid_banner' => $index_mid_banner, 'index_bottom_banner' => $index_bottom_banner, 'link_logos' => $link_logos, 'link_texts' => $link_texts, 'news_new' => $news_new, 'news_hot' => $news_hot, 'image_new' => $image_new, 'image_hot' => $image_hot, 'soft_new' => $soft_new, 'soft_hot' => $soft_hot, 'video_new' => $video_new, 'video_hot' => $video_hot)); }
public function run() { //限制下载频率 $cookie = Yii::app()->request->getCookies(); $id = Yii::app()->request->getParam('id'); $cookie_key = 'DL' . $id . 'TIMES'; if (isset($cookie[$cookie_key]) && $cookie[$cookie_key]->value) { throw new CHttpException(404, Yii::t('common', 'Access frequency too fast')); } $soft = Soft::model()->findByPk($id); if ($soft) { $file = Helper::convertChineseName(ROOT_PATH . '/' . $soft->soft_file); if ($soft->soft_file && file_exists($file)) { $filename = pathinfo($file, PATHINFO_BASENAME); //更新下载次数 $soft->updateCounters(array('down_count' => 1), 'id=:id', array('id' => $id)); //存储下载cookie次数 unset($cookie[$cookie_key]); $down = 1; $cookie = new CHttpCookie($cookie_key, $down); $cookie->expire = time() + 20; //20秒之后可以再次下载 Yii::app()->request->cookies[$cookie_key] = $cookie; //开始下载 Yii::app()->request->sendFile($filename, file_get_contents($file)); exit; } else { throw new CHttpException(404, Yii::t('common', 'Source Is Not Found')); } } else { throw new CHttpException(404, Yii::t('common', 'Source Is Not Found')); } }
/** * 判断数据是否存在 * * return \$this->model */ public function loadModel() { if ($this->model === null) { if (isset($_GET['id'])) { $this->model = Soft::model()->findbyPk($_GET['id']); } if ($this->model === null) { throw new CHttpException(404, Yii::t('common', 'The requested page does not exist.')); } } return $this->model; }
public function run() { $catalog_id = trim(Yii::app()->request->getParam('catalog_id')); $order = trim(Yii::app()->request->getParam('order')); if (!$order) { $order = 'id'; } switch ($order) { case 'id': $order_by = 't.id DESC'; break; case 'view_count': $order_by = 'view_count DESC'; break; default: $order = 'id'; $order_by = 't.id DESC'; break; } //SEO $navs = array(); $search_cats = '所有'; if ($catalog_id) { $condition = ' AND catalog_id = ' . $catalog_id; $catalog = Catalog::model()->findByPk($catalog_id); if ($catalog) { $this->controller->_seoTitle = $catalog->seo_title ? $catalog->seo_title : $catalog->catalog_name . ' - ' . $this->controller->_setting['site_name']; $this->controller->_seoKeywords = $catalog->seo_keywords; $this->controller->_seoDescription = $catalog->seo_description; $navs[] = array('url' => $this->controller->createUrl('soft/index', array('catalog_id' => $catalog->id)), 'name' => $catalog->catalog_name); //已搜索的分类 $cat_parents = Catalog::getParantsCatalog($catalog_id); $search_cats = $cat_parents ? implode('>', $cat_parents) . '>' . $catalog->catalog_name : $catalog->catalog_name; } } if (!$navs) { $condition = ''; $catalog = array(); $seo = ModelType::getSEO('soft'); $this->controller->_seoTitle = $seo['seo_title'] . ' - ' . $this->controller->_setting['site_name']; $this->controller->_seoKeywords = $seo['seo_keywords']; $this->controller->_seoDescription = $seo['seo_description']; $navs[] = array('url' => Yii::app()->request->getUrl(), 'name' => $this->controller->_seoTitle); } //获取所有符合条件的软件 $pages = array(); $datalist = Soft::model()->getList(array('condition' => $condition, 'limit' => 15, 'order' => $order_by, 'page' => true), $pages); //该栏目下最新的软件 $last_softs = Soft::model()->getList(array('condition' => $condition, 'limit' => 10)); $this->controller->render('index', array('navs' => $navs, 'catalog' => $catalog, 'softs' => $datalist, 'pagebar' => $pages, 'last_softs' => $last_softs, 'order' => $order, 'search_cats' => $search_cats)); }
/** * * 重新统计标签,删除不匹配的标签 * */ public function actionReset() { $tags = Tag::model()->findAll(); foreach ((array) $tags as $tag) { $post = Post::model()->findAll("FIND_IN_SET(:tag, tags)", array(':tag' => $tag->tag_name)); $image = Image::model()->findAll("FIND_IN_SET(:tag, tags)", array(':tag' => $tag->tag_name)); $soft = Soft::model()->findAll("FIND_IN_SET(:tag, seo_keywords)", array(':tag' => $tag->tag_name)); if (!$post && !$image && !$soft) { $tag->delete(); } else { $tag->data_count = count($post) + count($image) + count($soft); $tag->save(); } } $this->message('success', Yii::t('admin', 'Reset Tags Success'), $this->createUrl('index')); }
/** * This is the default 'index' action that is invoked * when an action is not explicitly requested by users. */ public function actionIndex() { //首页banner幻灯片 $banner = Ad::model()->findAll('position_id=:pid', array(':pid' => 1)); //SEO $this->_seoTitle = $this->_setting['seo_title']; $this->_seoKeywords = $this->_setting['seo_keywords']; $this->_seoDescription = $this->_setting['seo_description']; //加载css,js Yii::app()->clientScript->registerCssFile($this->_stylePath . "/css/index.css"); Yii::app()->clientScript->registerScriptFile($this->_static_public . "/js/jquery/jquery.js"); Yii::app()->clientScript->registerScriptFile($this->_static_public . "/js/jquery/jquery.easytabs.min.js"); //头部banner $index_top_banner = Ad::model()->getAdOne(4); //中部banner $index_mid_banner = Ad::model()->getAdOne(3); //底部banner $index_bottom_banner = Ad::model()->getAdOne(5); //最新资讯 Yii::app()->cache && ($news_new = Yii::app()->cache->get('news_new')); if ($news_new == false) { $news_new = Post::model()->getList(array('limit' => 20)); Yii::app()->cache && Yii::app()->cache->set('news_new', $news_new); } //热门资讯 Yii::app()->cache && ($news_hot = Yii::app()->cache->get('news_host')); if ($news_hot == false) { $news_hot = Post::model()->getList(array('order' => 't.view_count DESC, t.id DESC', 'limit' => 20)); Yii::app()->cache && Yii::app()->cache->set('news_hot', $news_hot); } //最新图集 $image_new = Image::model()->getList(array('limit' => 10)); //热门图集 $image_hot = Image::model()->getList(array('limit' => 10, 'order' => 'view_count DESC, t.id DESC')); //最新软件 $soft_new = Soft::model()->getList(array('limit' => 20)); //热门软件 $soft_hot = Soft::model()->getList(array('limit' => 10, 'order' => 'down_count DESC, t.id DESC')); //最新视频 //$video_new = Video::model()->findAll("status=:status AND catalog_id = 13 ORDER BY id DESC Limit 20", array(':status'=>'Y')); //热门视频 //$video_hot = Video::model()->findAll("status=:status AND catalog_id = 13 ORDER BY view_count DESC, video_score DESC, id DESC Limit 20", array(':status'=>'Y')); //友情链接 $link_logos = Link::model()->findAll("logo !='' AND status_is='Y'", array('order' => 'sortorder ASC, id DESC')); $link_texts = Link::model()->findAll("logo ='' or logo is null AND status_is='Y'", array('order' => 'sortorder ASC, id DESC')); $this->render('index', compact(array('index_top_banner', 'index_mid_banner', 'index_bottom_banner', 'link_logos', 'link_texts', 'news_new', 'news_hot', 'image_new', 'image_hot', 'soft_new', 'soft_hot', 'video_new', 'video_hot'))); }
public function run() { $id = Yii::app()->request->getParam('id'); $post = Soft::model()->findByPk(intval($id)); if (false == $post || $post->status == 'N') { throw new CHttpException(404, Yii::t('common', 'The requested page does not exist.')); } //更新浏览次数 $post->updateCounters(array('view_count' => 1), 'id=:id', array('id' => $id)); //seo信息 $this->controller->_seoTitle = empty($post->seo_title) ? $post->title . ' - ' . $this->controller->_setting['site_name'] : $post->seo_title; $this->controller->_seoKeywords = empty($post->seo_keywords) ? $post->tags : $post->seo_keywords; $this->controller->_seoDescription = empty($post->seo_description) ? $this->controller->_seoDescription : $post->seo_description; //最近的软件 $last_softs = Soft::model()->findAll(array('condition' => 'catalog_id = ' . $post->catalog_id, 'order' => 'id DESC', 'limit' => 10)); //nav $navs = array(); $navs[] = array('url' => $this->controller->createUrl('soft/view', array('id' => $id)), 'name' => $post->title); $tplVar = array('soft' => $post, 'navs' => $navs, 'last_softs' => $last_softs); $this->controller->render('view', $tplVar); }
public function run() { $this->controller->layout = false; $view_url = Yii::app()->request->getParam('view_url'); $content_id = Yii::app()->request->getParam('content_id'); $topic_type = Yii::app()->request->getParam('topic_type'); $cur_url = Yii::app()->request->hostinfo . Yii::app()->request->getUrl(); $post = false; //评论类型 switch ($topic_type) { case 'post': $post = Post::model()->findByPk($content_id); break; case 'image': $post = Image::model()->findByPk($content_id); break; case 'soft': $post = Soft::model()->findByPk($content_id); break; case 'video': $post = Video::model()->findByPk($content_id); break; } if (!$post) { throw new CHttpException(404, Yii::t('admin', 'Loading Error')); } //评论内容 $model = new Comment('create'); $criteria = new CDbCriteria(); $criteria->with = array('user'); $criteria->addColumnCondition(array('content_id' => $content_id)); $criteria->addColumnCondition(array('t.status' => Comment::STATUS_SHOW)); $criteria->addColumnCondition(array('type' => $this->controller->_type_ids[$topic_type])); $criteria->addCondition('u.uid > 0'); $criteria->order = 't.id DESC'; $criteria->select = 't.id, user_id, content_id, content, t.create_time '; //分页 $count = $model->count($criteria); $pages = new CPagination($count); $pages->pageSize = 10; $criteria->limit = $pages->pageSize; $criteria->offset = $pages->currentPage * $pages->pageSize; $comments = $model->findAll($criteria); //回复 if ($comments) { foreach ($comments as $c) { $replies[$c->id] = Reply::model()->with('user')->findAll(array('condition' => 'cid = ' . $c->id . ' AND t.status = "' . Reply::STATUS_SHOW . '" AND u.uid > 0', 'order' => 'id')); } } else { $comments = array(); $replies = array(); } if (Yii::app()->request->isPostRequest) { $uid = Yii::app()->user->id; if (!$uid) { $this->message('script', Yii::t('common', 'You Need Login')); } $model->attributes = $_POST['Comment']; $model->content_id = $content_id; $model->type = $this->controller->_type_ids[$topic_type]; $model->user_id = $uid; $model->status = 'N'; $model->client_ip = Yii::app()->request->userHostAddress; $model->create_time = time(); $ret_url = $_POST['ret_url']; if ($model->save()) { $this->controller->message('script', Yii::t('common', 'Submit Success, Waiting Pass'), $ret_url); } } $data = array('model' => $model, 'view_url' => $view_url, 'cur_url' => $cur_url, 'comments' => $comments, 'pagebar' => $pages, 'replies' => $replies); $this->controller->render('create', $data); }
/** * 提交评论 * * @return [type] [description] */ public function actionCreate() { $this->layout = false; $view_url = $this->_request->getParam('view_url'); $topic_id = $this->_request->getParam('topic_id'); $topic_type = $this->_request->getParam('topic_type'); $cur_url = $this->_request->hostinfo . $this->_request->getUrl(); $post = false; //评论类型 switch ($topic_type) { case 'post': $post = Post::model()->findByPk($topic_id); break; case 'image': $post = Image::model()->findByPk($topic_id); break; case 'soft': $post = Soft::model()->findByPk($topic_id); break; case 'video': $post = Video::model()->findByPk($topic_id); break; } if (!$post) { throw new CHttpException(404, Yii::t('admin', 'Submit Error')); break; } //评论内容 $model = new Comment('create'); $criteria = new CDbCriteria(); $condition = "topic_id={$topic_id} AND status='Y' AND type={$this->_type_ids[$topic_type]}"; $criteria->condition = $condition; $criteria->order = 'id DESC'; $criteria->select = "id, user_id, topic_id, content, create_time "; //分页 $count = $model->count($criteria); $pages = new CPagination($count); $pages->pageSize = 10; $criteria->limit = $pages->pageSize; $criteria->offset = $pages->currentPage * $pages->pageSize; $comments = $model->findAll($criteria); //回复 if ($comments) { foreach ((array) $comments as $c) { $replies[$c->id] = Reply::model()->findAll('cid=:cid AND status=:status ORDER BY id', array(':cid' => $c->id, ':status' => 'Y')); } } //加载css,js Yii::app()->clientScript->registerCssFile($this->_stylePath . "/css/comment.css"); Yii::app()->clientScript->registerCssFile($this->_static_public . "/js/kindeditor/code/prettify.css"); Yii::app()->clientScript->registerScriptFile($this->_static_public . "/js/jquery/jquery.js"); Yii::app()->clientScript->registerScriptFile($this->_static_public . "/js/kindeditor/code/prettify.js", CClientScript::POS_END); if ($this->_request->isPostRequest) { $uid = Yii::app()->user->id; if (!$uid) { $this->message('script', Yii::t('common', 'You Need Login')); } $model->attributes = $_POST['Comment']; $model->topic_id = $topic_id; $model->type = $this->_type_ids[$topic_type]; $model->user_id = $uid; $model->status = 'N'; $model->client_ip = $this->_request->userHostAddress; $model->create_time = time(); $ret_url = $_POST['ret_url']; if ($model->save()) { $this->message('script', Yii::t('common', 'Submit Success, Waiting Pass'), $ret_url); //$this->redirect($ret_url); } } $data = array('model' => $model, 'view_url' => $view_url, 'cur_url' => $cur_url, 'comments' => $comments, 'pagebar' => $pages, 'replies' => $replies); $this->render('create', $data); }
/** * * 软件下载 */ public function actionDownload($id) { //限制下载频率 $cookie = Yii::app()->request->getCookies(); $cookie_key = 'DL' . $id . 'TIMES'; $down_cookie = $cookie[$cookie_key]->value; if ($down_cookie) { throw new CHttpException(404, Yii::t('common', 'Access frequency too fast')); } $soft = Soft::model()->findByPk($id); if ($soft) { $file = Upload::model()->findByPk($soft->fileid); if ($file && file_exists($file->file_name)) { //更新下载次数 $soft->updateCounters(array('down_count' => 1), 'id=:id', array('id' => $id)); //存储下载cookie次数 unset($cookie[$cookie_key]); $down = 1; $cookie = new CHttpCookie($cookie_key, $down); $cookie->expire = time() + 20; //20秒之后可以再次下载 Yii::app()->request->cookies[$cookie_key] = $cookie; //开始下载 Yii::app()->request->sendFile($soft->title . '.' . $file->file_ext, file_get_contents($file->file_name), $file->file_mime); exit; } else { throw new CHttpException(404, Yii::t('common', 'Source Is Not Found')); } } else { throw new CHttpException(404, Yii::t('common', 'Source Is Not Found')); } }
/** * * 下载 */ private function downloadSitemap() { $criteria = new CDbCriteria(); $criteria->condition = "status = 'Y'"; $criteria->select = 'id, update_time'; $criteria->order = 'id DESC'; $model = Soft::model()->findAll($criteria); foreach ($model as $v) { $this->downloadItems[] = array('url' => $this->createUrl('soft/view', array('id' => $v->id)), 'date' => date(DATE_W3C, $v->update_time)); } }
/** * 批量操作 * */ public function actionBatch() { if ($this->method() == 'GET') { $command = trim($_GET['command']); $ids = intval($_GET['id']); } elseif ($this->method() == 'POST') { $command = trim($_POST['command']); $ids = $_POST['id']; } else { $this->message('errorBack', Yii::t('admin', 'Only POST Or GET')); } empty($ids) && $this->message('error', Yii::t('admin', 'No Select')); switch ($command) { case 'delete': //删除软件 foreach ((array) $ids as $id) { $postModel = Soft::model()->findByPk($id); if ($postModel) { Uploader::deleteFile($postModel->cover_image); $postModel->delete(); } } break; case 'show': //软件显示 foreach ((array) $ids as $id) { $postModel = Soft::model()->findByPk($id); if ($postModel) { $postModel->status = 'Y'; $postModel->save(); } } break; case 'hidden': //软件隐藏 foreach ((array) $ids as $id) { $postModel = Soft::model()->findByPk($id); if ($postModel) { $postModel->status = 'N'; $postModel->save(); } } break; default: throw new CHttpException(404, Yii::t('admin', 'Error Operation')); break; } $this->message('success', Yii::t('admin', 'Batch Operate Success')); }