Exemple #1
0
 public function getTags($id)
 {
     $tmp = array();
     $postTags = Post_tags::getPostTags($id);
     //        print_r (count($postTags->getModels()));
     for ($i = 0; $i < count($postTags->getModels()); $i++) {
         array_push($tmp, $postTags->getModels()[$i]['tag_id']);
     }
     //        print_r($tmp);
     $tags = implode("','", $tmp);
     $getTags = Tag::getTags($tags);
     //print_r($getTags->getModels());
     return $getTags;
 }
Exemple #2
0
 /**
  * Get category and category posts
  *
  * @param Request $request
  * @param $alias
  * @return \Illuminate\Contracts\View\Factory|\Illuminate\Http\RedirectResponse|\Illuminate\View\View
  */
 public function category(Request $request, $alias)
 {
     $category = Category::getCategoryByAlias($alias);
     if (empty($category)) {
         return redirect()->back();
     } else {
         $tags = Tag::getTags();
         if (!session()->get($category['id'])) {
             $category_visit = new CategoryVisit();
             $category_visit->category_id = $category['id'];
             $category_visit->save();
             session([$category['id'] => $category['id']]);
         }
         $posts = Category::getCategoryApprovedPosts($category['id'], 5, $request->input('search'), $request->input('tag'));
         $request->flash();
         return view('site.category', compact('category', 'posts', 'tags'));
     }
 }
Exemple #3
0
 /**
  * Export tags
  */
 public function export()
 {
     $data = array(array('Name'));
     $tags = Tag::getTags();
     foreach ($tags as $tag) {
         $tag_array = array();
         $name = $tag['name'];
         array_push($tag_array, $name);
         array_push($data, $tag_array);
     }
     Excel::create('Tags', function ($excel) use($data) {
         $excel->sheet('Tags', function ($sheet) use($data) {
             $sheet->fromArray($data, null, 'A1', false, false);
             $sheet->cells('A1', function ($cells) {
                 $cells->setFontWeight('bold');
             });
         });
     })->export('xls');
 }
Exemple #4
0
 /**
  * Edit post
  *
  * @param Request $request
  * @param int $id
  * @return \Illuminate\Contracts\View\Factory|\Illuminate\Http\RedirectResponse|\Illuminate\View\View
  */
 public function edit(Request $request, $id = 0)
 {
     $post = Post::getPostById($id);
     if (empty($post)) {
         return redirect()->back();
     } else {
         if ($request->isMethod("post")) {
             $rules = ["title" => "required", "alias" => "required|unique:posts,alias," . $id, "content" => "required", 'image' => 'mimes:jpeg,jpg,png'];
             Validator::make($request->all(), $rules)->validate();
             $post->title = $request->input("title");
             $post->alias = $request->input("alias");
             $post->content = $request->input("content");
             $post->meta_keys = $request->input("meta_keys");
             $post->meta_desc = $request->input("meta_desc");
             if (!empty($request->file("image"))) {
                 if (!empty($post->image)) {
                     if (Storage::exists('uploads/' . $post->image) && Storage::exists('uploads/fb-' . $post->image)) {
                         Storage::delete('uploads/' . $post->image, 'uploads/fb-' . $post->image);
                     }
                 }
                 $generated_string = str_random(32);
                 $file = $request->file("image")->store('uploads');
                 $new_file = $generated_string . '.' . $request->file("image")->getClientOriginalExtension();
                 Storage::move($file, 'uploads/' . $new_file);
                 $img = Image::make($request->file('image'));
                 $img->crop(200, 200);
                 $img->save(storage_path('app/public/uploads/' . $new_file));
                 $img = Image::make($request->file('image'));
                 $img->resize(600, 315);
                 $img->save(storage_path('app/public/uploads/fb-' . $new_file));
                 $post->image = $new_file;
             }
             if ($request->has("category")) {
                 $post->category_id = $request->input("category");
             }
             $post->publish = $request->has("publish");
             $post->save();
             $new_tags = [];
             if ($request->has("tags")) {
                 $tags = $request->input("tags");
                 foreach ($tags as $tag) {
                     array_push($new_tags, $tag);
                 }
             }
             $post->tags()->sync($new_tags);
             return redirect()->route('posts');
         } else {
             $categories = Category::getCategoriesByPublish();
             $tags = Tag::getTags();
             return view("site.post.edit", compact("post", "categories", "tags"));
         }
     }
 }
 public function actionEdit($id)
 {
     $request = Yii::$app->getRequest();
     $me = Yii::$app->getUser()->getIdentity();
     $model = $this->findTopicModel($id, ['content', 'node']);
     if (!$me->canEdit($model)) {
         throw new ForbiddenHttpException('您没有权限修改或已超过可修改时间。');
     }
     if ($me->isAdmin()) {
         $model->scenario = Topic::SCENARIO_ADMIN_EDIT;
     } else {
         $model->scenario = Topic::SCENARIO_AUTHOR_EDIT;
     }
     if (!($content = $model->content)) {
         $content = new TopicContent(['topic_id' => $model->id]);
     }
     $oldTags = $model->tags;
     if ($model->load($request->post()) && $model->validate() && $content->load($request->post()) && $content->validate()) {
         //			$model->tags = Tag::editTags($model->tags, $oldTags);
         $model->tags = Tag::getTags($model->tags);
         $model->save(false) && $content->save(false);
         Tag::afterTopicEdit($model->id, $model->tags, $oldTags);
         (new History(['user_id' => $me->id, 'action' => History::ACTION_EDIT_TOPIC, 'action_time' => $model->updated_at, 'target' => $model->id]))->save(false);
         return $this->redirect(Topic::getRedirectUrl($id, 0, $request->get('ip', 1), $request->get('np', 1)));
     }
     return $this->render('edit', ['model' => $model, 'content' => $content]);
 }
 /**
  * 显示所有的tag标签
  */
 public function actionList()
 {
     return $this->render('list', ['tags' => Tag::getTags(1)]);
 }
<?php

/**
 * @author xbzbing <*****@*****.**>
 * @link http://www.crazydb.com
 */
use yii\web\View;
use yii\helpers\Url;
use app\models\Tag;
/* @var View $this */
$tags = Tag::getTags(false, 20);
$colors = ['default', 'primary', 'success', 'info', 'warning', 'danger'];
?>
<div class="widget aside-tags">
    <h3 class="widget_tit with-shadow">
        <i class="glyphicon glyphicon-tags"></i>标签
    </h3>

    <div class="with-shadow">
        <?php 
if ($tags) {
    foreach ($tags as $tag) {
        $color = $colors[mt_rand(0, 5)];
        echo <<<HTML
        <a href="{$tag['url']}" title="{$tag['name']}({$tag['totalCount']})" target="_blank">
            <span class="label label-{$color}">{$tag['name']}</span>
        </a>
HTML;
    }
} else {
    echo '<span class="label label-default">暂无标签</span>';