예제 #1
0
 public function index()
 {
     Cache::loadPage('', 30);
     $inputData = array();
     $postid = 0;
     Model::loadWithPath('post', System::getThemePath() . 'model/');
     if (!($match = Uri::match('post\\/(.*?)\\.html$'))) {
         Redirect::to('404page');
     }
     $friendly_url = addslashes($match[1]);
     $loadData = Post::get(array('cacheTime' => 30, 'where' => "where friendly_url='{$friendly_url}'"));
     if (!isset($loadData[0]['postid'])) {
         Redirect::to('404page');
     }
     $inputData = $loadData[0];
     if (Request::has('btnComment')) {
         try {
             sendComment($loadData[0]['postid']);
             $inputData['commentAlert'] = '<div class="alert alert-success">Send comment success.</div>';
         } catch (Exception $e) {
             $inputData['commentAlert'] = '<div class="alert alert-warning">' . $e->getMessage() . '</div>';
         }
     }
     $postid = $loadData[0]['postid'];
     $listTag = PostTags::renderToLink($postid);
     $inputData['listTag'] = $listTag;
     $inputData['listComments'] = Comments::get(array('where' => "where postid='{$postid}' AND status='1'", 'orderby' => "order by postid desc"));
     Post::upView($postid);
     System::setTitle(ucfirst($loadData[0]['title']));
     $keywords = isset($loadData[0]['keywords'][4]) ? $loadData[0]['keywords'] : System::getKeywords();
     System::setKeywords($keywords);
     self::makeContent('post', $inputData);
     Cache::savePage();
 }
예제 #2
0
 /**
  * 标签首页
  */
 public function actionIndex()
 {
     $postTagsModel = new PostTags();
     $postTagsCriteria = new CDbCriteria();
     $condition = '1';
     $postTagsCriteria->condition = $condition;
     $postTagsCriteria->order = 't.id DESC';
     $count = $postTagsModel->count($postTagsCriteria);
     $post2TagsPages = new CPagination($count);
     $post2TagsPages->pageSize = 300;
     $pageParams = XUtils::buildCondition($_GET, array());
     $post2TagsPages->params = is_array($pageParams) ? $pageParams : array();
     $postTagsCriteria->limit = $post2TagsPages->pageSize;
     $postTagsCriteria->offset = $post2TagsPages->currentPage * $post2TagsPages->pageSize;
     $data['bagecmsDataList'] = $postTagsModel->findAll($postTagsCriteria);
     $data['bagecmsPagebar'] = $post2TagsPages;
     $this->render('index', $data);
 }
예제 #3
0
 /**
  * Adds tags to a post
  */
 public function addTags($tags)
 {
     foreach ($tags as $t) {
         $t = trim($t);
         $tag = Tags::findFirst(array("tag = '{$t}'"));
         if (!$tag) {
             $tag = new Tags();
             $tag->tag = $t;
             $tag->save();
         }
         $postTag = PostTags::findFirst(array("conditions" => "posts_id = ?1 AND tags_id = ?2", "bind" => array(1 => $this->id, 2 => $tag->id)));
         if (!$postTag) {
             $postTag = new PostTags();
             $postTag->posts_id = $this->id;
             $postTag->tags_id = $tag->id;
             $postTag->save();
         }
         unset($tag);
         unset($postTag);
     }
 }
예제 #4
0
 public function edit()
 {
     if (!($match = Uri::match('\\/edit\\/(\\d+)'))) {
         Redirect::to(ADMINCP_URL . 'post/');
     }
     $postid = $match[1];
     $post = array('alert' => '');
     if (Request::has('btnSave')) {
         try {
             updateProcess($postid);
             $post['alert'] = '<div class="alert alert-success">Save changes success.</div>';
         } catch (Exception $e) {
             $post['alert'] = '<div class="alert alert-warning">' . $e->getMessage() . '</div>';
         }
     }
     $loadData = Post::get(array('cache' => 'no', 'isHook' => 'no', 'query' => "select p.*,c.title as cattitle from " . Database::getPrefix() . "post p," . Database::getPrefix() . "categories c where p.catid=c.catid AND p.postid='{$postid}'"));
     $post['edit'] = $loadData[0];
     $post['tags'] = PostTags::renderToText($postid);
     System::setTitle('Edit post - ' . ADMINCP_TITLE);
     View::make('admincp/head');
     self::makeContents('postEdit', $post);
     View::make('admincp/footer');
 }
예제 #5
0
파일: Tag.php 프로젝트: koakumasd/blogsite
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getPostTags()
 {
     return $this->hasMany(PostTags::className(), ['tag_id' => 'tag_id']);
 }
예제 #6
0
function insertProcess()
{
    $send = Request::get('send');
    $valid = Validator::make(array('send.title' => 'min:1|slashes', 'send.keywords' => 'slashes', 'tags' => 'slashes', 'send.catid' => 'slashes', 'send.type' => 'slashes', 'send.allowcomment' => 'slashes'));
    if (!$valid) {
        throw new Exception("Error Processing Request: " . Validator::getMessage());
    }
    $friendlyUrl = trim(String::makeFriendlyUrl($send['title']));
    $getData = Post::get(array('where' => "where friendly_url='{$friendlyUrl}'"));
    if (isset($getData[0]['postid'])) {
        throw new Exception("This post exists in database.");
    }
    $uploadMethod = Request::get('uploadMethod');
    switch ($uploadMethod) {
        case 'frompc':
            if (Request::hasFile('imageFromPC')) {
                if (Request::isImage('imageFromPC')) {
                    $send['image'] = File::upload('imageFromPC');
                }
            }
            break;
        case 'fromurl':
            if (Request::isImage('imageFromUrl')) {
                $url = Request::get('imageFromUrl');
                $send['image'] = File::upload('uploadFromUrl');
            }
            break;
    }
    $send['userid'] = Users::getCookieUserId();
    if (!Request::has('send.catid')) {
        $loadCat = Categories::get(array('limitShow' => 1));
        if (isset($loadCat[0]['catid'])) {
            $send['catid'] = $loadCat[0]['catid'];
        }
    }
    if (!($id = Post::insert($send))) {
        throw new Exception("Error. " . Database::$error);
    }
    $tags = trim(Request::get('tags'));
    $parse = explode(',', $tags);
    $total = count($parse);
    $insertData = array();
    for ($i = 0; $i < $total; $i++) {
        $insertData[$i]['title'] = trim($parse[$i]);
        $insertData[$i]['postid'] = $id;
    }
    PostTags::insert($insertData);
}
예제 #7
0
파일: Post2tags.php 프로젝트: bigbol/ziiwo
 /**
  * tags 更新操作 parent:tags
  *
  * @param $tags
  * @param $titleId
  * @param $model
  * @param $jumpUri
  */
 protected function _tagsUpdate($tags = '', $title_id = 0, $catalog_id = 0, $redirect)
 {
     $tagsRelation = new Post2tags();
     $tagsRelationArray = $tagsRelation->findAll('title_id=:title_id', array('title_id' => $title_id));
     $tagsArray = array();
     foreach ((array) $tagsRelationArray as $row) {
         $tagsArray[] = $row['tag_name'];
     }
     $titleTags = implode(',', $tagsArray);
     $explodeTags = array_unique(explode(',', str_replace(array(' ', ','), ',', $tags)));
     $tagCount = 0;
     foreach ((array) $explodeTags as $value) {
         $tagCount++;
         if ($tagCount >= 10) {
             unset($explodeTags);
             break;
         }
         $TagsArrayNew[] = $value;
         if (!in_array($value, $tagsArray)) {
             $dao = new PostTags();
             $get_data = $dao->find('tag_name=:tag_name', array('tag_name' => $value));
             if (empty($get_data)) {
                 $dao->catalog_id = $catalog_id;
                 $dao->data_count = 1;
                 $dao->tag_name = $value;
                 $dao->create_time = time();
                 $id = $dao->save();
             } else {
                 $get_data->data_count = $get_data->data_count + 1;
                 $get_data->save();
             }
             //写入关联
             self::_tagsRelation($value, $title_id);
         }
     }
     foreach ($tagsArray as $tagName) {
         if (!in_array($tagName, $TagsArrayNew)) {
             $getTagsCount = Post2tags::model()->count('title_id!=:title_id AND tag_name=:tag_name', array('title_id' => $title_id, 'tag_name' => $tagName));
             if ($getTagsCount) {
                 Yii::app()->db->createCommand("UPDATE {{news_tags}} SET data_count=data_count+1 WHERE tag_name='{$tagName}'")->execute();
             } else {
                 PostTags::model()->deleteAll('tag_name=:tag_name', array('tag_name' => $tagName));
             }
             Post2tags::model()->deleteAll('tag_name=:tag_name AND title_id=:title_id', array('tag_name' => $tagName, 'title_id' => $title_id));
         }
     }
 }
예제 #8
0
 /**
  * 标签管理
  *
  */
 public function actionPostTags()
 {
     $model = new PostTags();
     $criteria = new CDbCriteria();
     $condition = '1';
     $tagName = $this->_gets->getParam('tagName');
     $tagName && ($condition .= ' AND tag_name LIKE \'%' . $tagName . '%\'');
     $catalog_id = intval($this->_gets->getParam('catalog_id'));
     $catalog_id && ($condition .= ' AND t.catalog_id= ' . $catalog_id);
     $criteria->condition = $condition;
     $criteria->order = 't.id DESC';
     $criteria->with = 'catalog';
     $count = $model->count($criteria);
     $pages = new CPagination($count);
     $pages->pageSize = 13;
     $pageParams = XUtils::buildCondition($_GET, array('tagName', 'catalog_id'));
     $pages->params = is_array($pageParams) ? $pageParams : array();
     $criteria->limit = $pages->pageSize;
     $criteria->offset = $pages->currentPage * $pages->pageSize;
     $result = $model->findAll($criteria);
     $this->render('post_tags', array('datalist' => $result, 'pagebar' => $pages));
 }
예제 #9
0
?>
<!-- widget -->
<div class="row">
<div class="col-lg-12">
<h4><strong>POPULAR POST</strong></h4>
<ul class="ulMenu2">
  <?php 
echo $listPost;
?>
</ul>
</div>
</div>
<!-- widget -->

<?php 
$tags = PostTags::get(array('limitShow' => 10, 'orderby' => 'group by title order by count(title) desc'));
$total = count($tags);
$li = '';
if (isset($tags[0]['tagid'])) {
    for ($i = 0; $i < $total; $i++) {
        $li .= '
<li><a href="' . $tags[$i]['url'] . '">' . $tags[$i]['title'] . '</a></li>
  ';
    }
}
$listTag = $li;
?>
<!-- widget -->
<div class="row">
<div class="col-lg-12">
<h4><strong>TAGS</strong></h4>