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')); }
/** * 处理ajax收藏操作 * */ private function _opCollection() { $uid = Yii::app()->user->id; if (!$uid) { $ret = array('state' => 'error', 'message' => Yii::t('common', 'You Need Login')); return $ret; } $postid = Yii::app()->request->getParam('id'); $post = Post::model()->findByPk($postid); if (!$post) { $ret = array('state' => 'error', 'message' => Yii::t('common', 'Collect Failed')); return $ret; } $collect_mod = new Collect(); //判断是否已经收藏 $exist_collect = $collect_mod->find('user_id=:uid AND cid=:cid AND type=:type_id', array(':uid' => $uid, ':cid' => $postid, ':type_id' => $type_id)); if ($exist_collect) { $ret = array('state' => 'error', 'message' => Yii::t('common', 'You Have Collected it')); } else { //收藏 $collect_mod->cid = $postid; $collect_mod->title = $post->title; $collect_mod->user_id = $uid; $collect_mod->url = Yii::app()->request->hostinfo . $this->controller->createUrl('post/view', array('id' => $postid)); $collect_mod->type = $type_id; $collect_mod->create_time = time(); if ($collect_mod->save()) { $post->updateCounters(array('favorite_count' => 1), 'id=:id', array('id' => $postid)); $ret = array('state' => 'success', 'message' => Yii::t('common', 'Collect Success'), 'count' => $post->favorite_count + 1); } else { $ret = array('state' => 'error', 'message' => Yii::t('common', 'Collect Failed')); } } return $ret; }
/** * Generate sitemap. */ public function actionSitemapxml() { $posts = Post::model()->findAll(array('order' => 'createTime DESC', 'condition' => 'status=' . Post::STATUS_PUBLISHED)); $pages = Page::model()->findAll(array('order' => 'createTime DESC', 'condition' => 'status=' . Page::STATUS_PUBLISHED)); header('Content-Type: application/xml'); $this->renderPartial('../site/sitemapxml', array('posts' => $posts, 'pages' => $pages)); }
public function actionComments($id) { if (null === ($model = Post::model()->findByPk($id))) { throw new CHttpException(404); } $this->sendResponse(200, CJSON::encode($model->comments)); }
public function actionAbout2() { Yii::app()->clientScript->registerCssFile(Yii::app()->theme->baseUrl . '/css/post.css'); Yii::app()->clientScript->registerCssFile(Yii::app()->theme->baseUrl . '/css/xinjia.css'); $catalog_id = Yii::app()->request->getQuery('id'); if ($catalog_id == '') { $catalog_id = 32; } // $post = Post::model()->findByPk($id); // $post->view_count += 1; // $post->save(); //$catalog_id = $post->catalog_id; // nybanner_mls nybanner_gflc nybanner_gfht nybanner_fcjj if ($catalog_id == 32) { $banner_name = "nybanner_mls"; } if ($catalog_id == 33) { $banner_name = "nybanner_gflc"; } if ($catalog_id == 34) { $banner_name = "nybanner_gfht"; } if ($catalog_id == 36) { $banner_name = "nybanner_fcjj"; } $prev_post = Post::model()->findAll(array('select' => 'id, title, content, view_count', 'condition' => ' catalog_id = :catalog_id', 'params' => array(':catalog_id' => $catalog_id), 'order' => 'id ASC', 'limit' => 1)); $this->render('about_2', array('banner_name' => $banner_name, 'post' => $post, 'prev_post' => $prev_post[0])); }
/** * On rebuild of the search index, rebuild all post records * * @param type $event */ public static function onSearchRebuild($event) { foreach (Post::model()->findAll() as $obj) { # HSearch::getInstance()->addModel($obj); print "p"; } }
public function actionIndex() { $posts = Post::model()->recently()->findAll(); // renders the view file 'protected/views/site/index.php' // using the default layout 'protected/views/layouts/main.php' $this->render('index'); }
public function actionWrite() { $post = new Post(); $post->blog_id = Yii::app()->getRequest()->getParam('blog-id'); if ($postId = (int) Yii::app()->getRequest()->getQuery('id')) { $post = Post::model()->findUserPost($postId, Yii::app()->getUser()->getId()); if (null === $post) { throw new CHttpException(404); } } if (Yii::app()->getRequest()->getIsPostRequest() && !empty($_POST['Post'])) { $data = Yii::app()->getRequest()->getPost('Post'); $data['user_id'] = Yii::app()->getUser()->getId(); $data['status'] = Yii::app()->getRequest()->getPost('draft', Post::STATUS_PUBLISHED); $data['tags'] = Yii::app()->getRequest()->getPost('tags'); if ($post->createPublicPost($data)) { $message = Yii::t('BlogModule.blog', 'Post sent for moderation!'); $redirect = ['/blog/publisher/my']; if ($post->isDraft()) { $message = Yii::t('BlogModule.blog', 'Post saved!'); } if ($post->isPublished()) { $message = Yii::t('BlogModule.blog', 'Post published!'); $redirect = ['/blog/post/show', 'slug' => $post->slug]; } Yii::app()->getUser()->setFlash(\yupe\widgets\YFlashMessages::SUCCESS_MESSAGE, $message); $this->redirect($redirect); } } $this->render('write', ['post' => $post, 'blogs' => (new Blog())->getListForUser(Yii::app()->getUser()->getId())]); }
function testIsDeleted() { $post = Post::model()->findByPk(1); $this->assertFalse($post->isRemoved()); $post = Post::model()->findByPk(2); $this->assertTrue($post->isRemoved()); }
public function actionDelete() { if (Post::model()->deleteUserPost(Yii::app()->getRequest()->getQuery('id'), Yii::app()->getUser()->getId())) { Yii::app()->ajax->success(); } Yii::app()->ajax->failure(); }
public function loadTerm($limit = 5, $data, $type = array(), $operation = 'OR') { $labels = unserialize($data); $cond = ''; $cond = "post_image!='' "; $criteria = new CDbCriteria(); if (is_array($type)) { $criteria->with = $type; } foreach ($type as $key) { if (!empty($labels)) { $first = true; foreach ($labels as $label => $val) { if ($first) { $cond .= ' AND '; $first = false; } $cond .= " {$key}.term_id='{$val}' "; if (end($labels) !== $val) { $cond .= $operation; } } } } $criteria->condition = $cond; $criteria->order = 'ID DESC'; $criteria->limit = $limit; $criteria->together = true; $model = Post::model()->is_publish()->findAll($criteria); return $model; }
public function actionPosts($name) { $tag = urldecode($name); $this->setSiteTitle(t('tag_posts', 'main', array('{name}' => $tag))); // @todo 关键字的描述没有指定 $this->setPageKeyWords($tag); $this->setPageDescription(t('tag_posts_page_description', 'main', array('{name}' => $tag))); cs()->registerMetaTag('all', 'robots'); $cmd = app()->getDb()->createCommand()->select('p.id')->from(TABLE_TAG . ' t')->where('t.name = :tagname', array(':tagname' => $tag))->join(TABLE_POST_TAG . ' pt', 'pt.tag_id = t.id')->join(TABLE_POST . ' p', 'p.id = pt.post_id'); $ids = $cmd->queryColumn(); if (count($ids) > 0) { $criteria = new CDbCriteria(); if (param('post_list_type') == POST_LIST_TYPE_TITLE) { $criteria->select = array('t.id', 't.title', 't.visit_nums', 't.comment_nums', 't.create_time'); } $criteria->order = 't.istop, t.create_time desc, t.id desc'; $criteria->addInCondition('t.id', $ids)->addCondition('t.state = :state'); $criteria->params += array(':state' => POST_STATE_ENABLED); $count = Post::model()->count($criteria); $pages = new CPagination($count); $pages->setPageSize(param('postCountOfTitleListPage')); $pages->applyLimit($criteria); $posts = Post::model()->findAll($criteria); } $listType = param('post_list_type'); $view = $listType == POST_LIST_TYPE_SUMMARY ? '/post/_summary_list' : '/post/_title_list'; $blockTitle = t('tag_posts', 'main', array('{name}' => $tag)); $data = array('blockTitle' => $blockTitle, 'posts' => $posts, 'pages' => $pages); $postListHtml = $this->renderPartial($view, $data, true); $this->render('posts', array('postListHtml' => $postListHtml)); }
public function actionAbout1() { Yii::app()->clientScript->registerCssFile(Yii::app()->theme->baseUrl . '/css/post.css'); Yii::app()->clientScript->registerCssFile(Yii::app()->theme->baseUrl . '/css/xinjia.css'); $catalog_id = Yii::app()->request->getQuery('id'); if ($catalog_id == '') { $catalog_id = 27; } // $post = Post::model()->findByPk($id); // $post->view_count += 1; // $post->save(); //$catalog_id = $post->catalog_id; //SUPERIORITY CONTACT US È˲ÅÕÐļJOIN US if ($catalog_id == 27) { $cat_name_en = "MAPLECITY PFOFILE"; } if ($catalog_id == 28) { $cat_name_en = "SUPERIORITY"; } if ($catalog_id == 30) { $cat_name_en = "CONTACT US"; } if ($catalog_id == 31) { $cat_name_en = "JOIN US"; } $prev_post = Post::model()->findAll(array('select' => 'id, title, content, view_count', 'condition' => ' catalog_id = :catalog_id', 'params' => array(':catalog_id' => $catalog_id), 'order' => 'id ASC', 'limit' => 1)); //$prev_post->view_count += 1; //$prev_post->save(); $next_post = Post::model()->findAll(array('select' => 'id, title', 'condition' => 'id < :id AND catalog_id = :catalog_id', 'params' => array(':id' => $id, ':catalog_id' => $catalog_id), 'order' => 'id DESC', 'limit' => 1)); $this->render('about', array('cat_name_en' => $cat_name_en, 'post' => $post, 'prev_post' => $prev_post[0], 'next_post' => $next_post[0])); }
public function run() { $criteria = new CdbCriteria(); $criteria->limit = $this->data('limit'); $criteria->offset = $this->data('offset'); $criteria->condition = "post_status='publish' AND (post_modified <= '" . date('Y-m-d H:i:s') . "' AND post_modified >= '" . $this->data('time') . "')"; $criteria->order = 'post_hits DESC'; if ($this->data('autoByTerm')) { if (isset($_GET['id'])) { $category = Category::model()->findByPK((int) $_GET['id']); $label = Label::model()->findByPK((int) $_GET['id']); $topic = Topic::model()->findByPK((int) $_GET['id']); $tag = Tag::model()->findByPK((int) $_GET['id']); if ($category != null) { $criteria = $this->getCriteriaTerm('categories', $criteria); } elseif ($label != null) { $criteria = $this->getCriteriaTerm('labels', $criteria); } elseif ($topic != null) { $criteria = $this->getCriteriaTerm('topics', $criteria); } elseif ($tag != null) { $criteria = $this->getCriteriaTerm('tags', $criteria); } } } $model = Post::model()->findAll($criteria); if ($model != null) { $this->layout($model); } }
public function actionEdit() { $id = Yii::app()->request->getParam('id'); $edited = false; $model = Post::model()->findByPk($id); if ($model->content->canWrite()) { if (isset($_POST['Post'])) { $_POST['Post'] = Yii::app()->input->stripClean($_POST['Post']); $model->attributes = $_POST['Post']; if ($model->validate()) { $model->save(); // Reload record to get populated updated_at field $model = Post::model()->findByPk($id); // Return the new post $output = $this->widget('application.modules_core.post.widgets.PostWidget', array('post' => $model, 'justEdited' => true), true); Yii::app()->clientScript->render($output); echo $output; return; } } $this->renderPartial('edit', array('post' => $model, 'edited' => $edited), false, true); } else { throw new CHttpException(403, Yii::t('PostModule.controllers_PostController', 'Access denied!')); } }
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 static function onNewComment(CommentEvent $event) { $comment = $event->getComment(); $module = $event->getModule(); $parent = $comment->getParent(); //ответ на комментарий if ($comment->hasParent()) { if (null !== $parent && $parent->user_id) { $notify = NotifySettings::model()->getForUser($parent->user_id); if (null !== $notify && $notify->isNeedSendForCommentAnswer()) { Yii::app()->mail->send($module->email, $parent->email, Yii::t('NotifyModule.notify', 'Reply to your comment on the website "{app}"!', ['{app}' => CHtml::encode(Yii::app()->name)]), Yii::app()->getController()->renderPartial('comment-reply-notify-email', ['model' => $comment], true)); } } } //нотификация автору поста if ('Post' === $comment->model) { $post = Post::model()->cache(Yii::app()->getModule('yupe')->coreCacheTime)->with(['createUser'])->get((int) $comment->model_id); if (null !== $post) { //пропускаем автора поста + если отвечают на комментарий автора поста - он уже получил уведомление выше if ($comment->user_id != $post->create_user_id) { $notify = NotifySettings::model()->getForUser($post->create_user_id); if (null != $notify && $notify->isNeedSendForNewPostComment()) { Yii::app()->mail->send($module->email, $post->createUser->email, Yii::t('NotifyModule.notify', 'New comment to your post on website "{app}"!', ['{app}' => CHtml::encode(Yii::app()->name)]), Yii::app()->getController()->renderPartial('comment-new-notify-email', ['model' => $comment], true)); } } } } }
public function init() { $this->states = States::model()->findAll('country_id=:country_id', array(':country_id' => 1)); $this->districts = Districts::model()->findAll(); $this->functionalAreas_models = FunctionalAreas::model()->findAll(); $this->latest_posts = Post::model()->findAll(array('order' => 'id DESC', 'limit' => 5)); $this->latest_resumes = User::model()->findAllByAttributes(array('showOnSearch' => 'Y'), array('order' => 'id DESC', 'limit' => 5)); }
public function delete() { $post_id = $_GET['id']; Post::model()->delete($post_id); Tag::model()->delete($post_id); Comment::model()->delete($post_id); Application::redirect(array('post' => 'index')); }
private function loadPost($id, $slug) { $model = Post::model()->is_publish()->findByAttributes(array('ID' => (int) $id, 'post_link' => $slug)); if ($model === null) { throw new CHttpException(404, 'The requested page does not exist.'); } return $model; }
/** * This is the default 'index' action that is invoked * when an action is not explicitly requested by users. */ public function actionIndex() { //latestnews $dataProvider = Post::model()->latestNews(); $dataProvider2 = Buku::model()->latestBook(); //$dataProvider3= Anggota::model()->rekomen(); $this->render('index', array('dataProvider' => $dataProvider, 'dataProvider2' => $dataProvider2)); }
private function loadModel($id) { $model = Post::model()->findByPk($id); if ($model == null) { throw new CHttpException('404', 'No model with that ID could be found.'); } return $model; }
/** * Returns the data model based on the primary key given in the GET variable. * If the data model is not found, an HTTP exception will be raised. * @param integer $id the ID of the model to be loaded * @return Post the loaded model * @throws CHttpException */ public function loadModel($id) { $model = Post::model()->findByPk($id); if ($model === null) { throw new CHttpException(404, 'The requested page does not exist.'); } return $model; }
public function loadPost($id) { $model = Post::model()->findByPk($id); if (null === $model) { throw new CHttpException(404, Yii::t('app', 'The requested page does not exist.')); } return $model; }
public function getSimilarPosts(Post $post, $limit = 10) { $criteria = new CDbCriteria(); $criteria->limit = $limit; $criteria->order = 'publish_time DESC'; $criteria->addNotInCondition('t.id', [$post->id]); $criteria->mergeWith(Post::model()->public()->published()->getFindByTagsCriteria($post->getTags())); return Post::model()->findAll($criteria); }
public function doRestList() { $criteria = $this->getModel()->with($this->nestedRelations)->onTarget($this->plainFilter['target_id'])->postOnly(); $countCriteria = Post::model()->postOnly()->onTarget($this->plainFilter['target_id']); $this->applyCustomFilters($criteria, $countCriteria); $criteria->orderBy('created_ts', 'DESC'); $totalCount = $countCriteria->count(); $this->outputHelper('Records Retrieved Successfully', $criteria->limit($this->restLimit)->offset($this->restOffset)->findAll(), (int) $totalCount); }
public function run() { $criteria = ['limit' => $this->limit, 'order' => 't.id DESC']; if (is_array($this->criteria) && !empty($this->criteria)) { $criteria = CMap::mergeArray($criteria, $this->criteria); } $posts = Post::model()->published()->with('createUser', 'commentsCount', 'blog')->public()->cache($this->cacheTime)->findAll($criteria); $this->render($this->view, ['models' => $posts]); }
public function actionpostshare($postId) { $model = Post::model()->find('id=:id', array('id' => $postId)); $newPost = new Post(); $newPost->user_id = Yii::app()->user->userId; $newPost->message = $model->message; $newPost->date = date('Y-m-d H:i:s'); $newPost->save(); }
function testModelSave() { $this->setUp(); $post = Post::model()->findByPk(1); $post->setStatus('archived'); $post->save(); $post = Post::model()->findByPk(1); $this->assertEquals('archived', $post->getStatusText(FALSE)); }
public function run() { $model = Post::model(); $criteria = new CDbCriteria(); $criteria->order = 'count DESC'; $criteria->limit = $this->limit; $criteria->join = sprintf('JOIN `%s` p ON et.%s = p.id AND p.status = %s', $model->tableName(), $model->modelTableFk, $model::STATUS_PUBLISHED); $this->render('tagsCloud', ['tags' => $model->getAllTagsWithModelsCount($criteria)]); }