Esempio n. 1
0
 public static function setFieldData()
 {
     $fieldData = array();
     $article = new Article();
     $arr = $article->getFillable();
     foreach ($arr as $v) {
         $fieldData[$v] = Input::get($v);
     }
     $fieldData['user_id'] = Auth::user()->id;
     $fieldData['tags'] = Tag::SetArticleTags($fieldData['tags'], $fieldData['new_tags']);
     // 文件上传
     if (Request::hasFile('pic')) {
         $pic = Request::file('pic');
         if ($pic->isValid()) {
             $newName = md5(rand(1, 1000) . $pic->getClientOriginalName()) . "." . $pic->getClientOriginalExtension();
             $pic->move('uploads', $newName);
             $fieldData['pic'] = $newName;
         }
     } else {
         unset($fieldData['pic']);
     }
     unset($fieldData['new_tags']);
     unset($arr);
     unset($article);
     return $fieldData;
 }
Esempio n. 2
0
 public function testMergeIntoSelf()
 {
     $tag = Tag::firstOrCreate(['name' => 'Tag 1']);
     $this->assertSame(1, Tag::count());
     $tag->merge($tag);
     $this->assertSame(1, Tag::count());
 }
Esempio n. 3
0
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     // 从数据库中获取的ArticleTag集合
     $tags = \App\Model\Tag::all();
     // 初始化博客的路径
     $dir = "/root/blog";
     $file_system = new Filesystem();
     $files = $file_system->allFiles($dir);
     foreach ($files as $file) {
         $file_extension = $file_system->extension($file);
         if ($file_extension != 'md') {
             continue;
         }
         $create_time_stamp = $file_system->lastModified($file);
         $create_time = gmdate("Y-m-d", $create_time_stamp);
         $file_content = $file_system->get($file);
         $file_name = preg_replace('/^.+[\\\\\\/]/', '', $file);
         $file_name = explode(".md", $file_name);
         $blog_name = $file_name[0];
         $last_dir = dirname($file);
         $current_tag_name = preg_replace('/^.+[\\\\\\/]/', '', $last_dir);
         $article_type_id = 0;
         foreach ($tags as $tag) {
             $tag_name = $tag->name;
             if (strcmp($current_tag_name, $tag_name) == 0) {
                 $article_type_id = $tag->id;
                 break;
             }
         }
         $article_id = \App\Model\Article::create(['cate_id' => $article_type_id, 'user_id' => 1, 'title' => $blog_name, 'content' => $file_content, 'tags' => $article_type_id, 'created_at' => $create_time, 'updated_at' => $create_time])->id;
         \App\Model\ArticleStatus::create(['art_id' => $article_id, 'view_number' => 0]);
     }
 }
 public function getTag($id)
 {
     $article = Article::getArticleListByTagId($id);
     $page = new EndaPage($article['page']);
     viewInit();
     return homeView('searchTag', ['articleList' => $article, 'tagName' => Tag::getTagNameByTagId($id), 'page' => $page]);
 }
Esempio n. 5
0
 /**
  * Sync tag relation adding new tags as needed
  *
  * @param array $tags
  */
 public function syncTags(array $tags)
 {
     Tag::addNeededTags($tags);
     if (count($tags)) {
         $this->tags()->sync(Tag::whereIn('tag', $tags)->lists('id')->all());
         return;
     }
     $this->tags()->detach();
 }
Esempio n. 6
0
 public function json(Request $request)
 {
     $tags = Tag::where('name', 'LIKE', '%' . $request->input('term') . '%')->get();
     $out = array();
     foreach ($tags as $tag) {
         $out[] = array('label' => $tag->name);
     }
     return Response::json($out);
 }
Esempio n. 7
0
 /**
  * @testdox Tags can be added to Job Lists.
  * @test
  */
 public function tags()
 {
     $type = new \App\Model\JobType();
     $type->save();
     $jobList = new JobList();
     $jobList->type_id = $type->id;
     $jobList->save();
     $jobList->addTags('one,two');
     $this->assertEquals(2, Tag::count());
 }
Esempio n. 8
0
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     DB::table('tags')->delete();
     $array = array(array("顶级标签", 0, 0, 0), array("演员", 1), array("编导", 1), array("摄影", 1), array("录音", 1), array("后期", 1), array("美术", 1), array("制片", 1), array("场务", 1), array("后勤", 1), array("活动", 1), array("男演员", 2), array("女演员", 2), array("特约演员", 2), array("群演", 2), array("主导演", 2), array("执行导演", 2), array("副导演", 2), array("编剧", 2), array("主摄影", 4), array("跟焦员", 4), array("摄影助理", 4), array("灯光", 4), array("录音师", 5), array("收音员", 5), array("录音助理", 5), array("后期导演", 6), array("剪辑", 6), array("特效", 6), array("配音", 6), array("作曲", 6), array("美术", 7), array("分镜师", 7), array("化妆师", 7), array("服装师", 7), array("制片人", 8), array("制片主任", 8), array("现场制片", 8), array("外联", 8), array("生活制片", 8), array("制作统筹", 8), array("场务", 9), array("道具师", 9), array("场记", 9), array("财务", 9), array("场地", 10), array("盒饭", 10), array("服装", 10), array("车辆", 10), array("道具", 10), array("模特", 11), array("观众", 11), array("志愿者", 11));
     $count = 1;
     foreach ($array as $item) {
         Tag::create(['id' => $count, 'name' => $item[0], 'parent' => $item[1], 'editable' => count($item) > 2 ? $item[2] : 1, 'deletable' => count($item) > 3 ? $item[3] : 1]);
         $count += 1;
     }
 }
 public function home()
 {
     $this->view->title = $this->view->site_name;
     $this->view->asset_count = Asset::count();
     $this->view->user_count = User::count();
     $this->view->crew_count = Crew::count();
     $this->view->job_list_count = JobList::count();
     $this->view->job_count = Job::count();
     $this->view->tag_count = Tag::count();
     return $this->view;
 }
 /**
  * Display the specified resource.
  *
  * @param  int  $id
  * @return Response
  */
 public function show($id)
 {
     //
     $article = Article::getArticleModelByArticleId($id);
     $tags = Tag::getTagModelByTagIds($article->tags);
     $authorArticle = Article::getArticleModelByUserId($article->user_id);
     ArticleStatus::updateViewNumber($id);
     $data = array('article' => $article, 'tags' => $tags, 'authorArticle' => $authorArticle);
     viewInit();
     return homeView('article', $data);
 }
Esempio n. 11
0
 /**
  * Display the specified resource.
  *
  * @param  int  $id
  * @return Response
  */
 public function show($id)
 {
     //
     $article = Article::getArticleModelByArticleId($id);
     $tags = Tag::getTagModelByTagIds($article->tags);
     $authorArticle = Article::getArticleModelByUserId($article->user_id);
     $commentList = Comment::getCommentListModel($id);
     $data = array('article' => $article, 'tags' => $tags, 'authorArticle' => $authorArticle, 'commentList' => $commentList);
     viewInit();
     return homeView('article', $data);
 }
 public function storeTags($blog, $tags)
 {
     $tag_array = explode(',', $tags);
     foreach ($tag_array as $tag) {
         $t = Tag::where('tag', $tag)->first();
         if (is_null($t)) {
             $blog->tags()->save(new Tag(['tag' => $tag]));
         } else {
             $blog->tags()->save($t);
         }
     }
 }
 /**
  * Run the migrations.
  *
  * @return void
  */
 public function up()
 {
     Schema::create('tags', function (Blueprint $table) {
         $table->increments('id');
         $table->timestamps();
         $table->string('filename');
         $table->string('name');
         $table->string('slug');
         $table->string('description')->default('');
     });
     $tags = [['name' => 'Party', 'filename' => 'noun_132751_cc'], ['name' => 'Konzert', 'filename' => 'noun_14878_cc'], ['name' => 'Vortrag', 'filename' => 'noun_57144_cc']];
     collect($tags)->each(function ($tag) {
         Tag::create($tag);
     });
 }
Esempio n. 14
0
 /**
  * Execute the command.
  *
  * @return array of fieldnames => values
  */
 public function handle()
 {
     $fields = $this->fieldList;
     if ($this->id) {
         $fields = $this->fieldsFromModel($this->id, $fields);
     } else {
         $when = Carbon::now()->addHour();
         $fields['publish_date'] = $when->format('M-j-Y');
         $fields['publish_time'] = $when->format('g:i A');
     }
     foreach ($fields as $fieldName => $fieldValue) {
         $fields[$fieldName] = old($fieldName, $fieldValue);
     }
     return array_merge($fields, ['allTags' => Tag::lists('tag')->all()]);
 }
Esempio n. 15
0
 public function delete()
 {
     $id = Input::get('id');
     $validator = Validator::make(array('id' => $id), array('id' => 'required|integer'));
     if ($validator->fails()) {
         return $this->responseJson(false, $validator->messages(), 101);
     }
     $tag = Tag::find($id);
     if (!$tag) {
         return $this->responseJson(false, "不存在该标签!", 102);
     }
     $tag->delete();
     ArticleAttribute::where('attribute_key', 'tag_id')->where('attribute_value', $id)->delete();
     return $this->responseJson(true, "成功删除标签!", 200);
 }
Esempio n. 16
0
 /**
  * @testdox Assets can be tagged.
  * @test
  */
 public function tags()
 {
     $asset = new Asset();
     $asset->identifier = 'TEST123';
     $asset->save();
     $this->assertEquals(0, Tag::count());
     $this->assertEquals(0, $asset->tags->count());
     $asset->addTags('One,Two');
     $asset->load('tags');
     $this->assertEquals(2, Tag::count());
     $this->assertEquals(2, $asset->tags->count());
     $asset->addTags('One,Two,Three');
     $asset->load('tags');
     $this->assertEquals(3, $asset->tags->count());
     // Make sure empty tags aren't added.
     $asset->addTags('One,Two,,Three');
     $asset->load('tags');
     $this->assertEquals(3, $asset->tags->count());
 }
Esempio n. 17
0
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     $tag_array = array();
     $first_add = true;
     $dir = "/root/blog";
     $file_system = new Filesystem();
     $files = $file_system->allFiles($dir);
     foreach ($files as $file) {
         $file_extension = $file_system->extension($file);
         if ($file_extension != 'md') {
             continue;
         }
         $last_dir = dirname($file);
         $tag_name = preg_replace('/^.+[\\\\\\/]/', '', $last_dir);
         $create_time_stamp = $file_system->lastModified($file);
         $create_time = gmdate("Y-m-d", $create_time_stamp);
         if ($first_add) {
             $tag_info = array();
             $tag_info[0] = $tag_name;
             $tag_info[1] = $create_time;
             $tag_array[0] = $tag_info;
             $first_add = false;
         }
         $is_new = true;
         foreach ($tag_array as $tag) {
             if (strcmp($tag[0], $tag_name) == 0) {
                 $is_new = false;
             }
         }
         if ($is_new) {
             $tag_count = count($tag_array);
             $tag_info = array();
             $tag_info[0] = $tag_name;
             $tag_info[1] = $create_time;
             $tag_array[$tag_count] = $tag_info;
         }
     }
     foreach ($tag_array as $tag_io) {
         \App\Model\Tag::create(['name' => $tag_io[0]]);
         \App\Model\Category::create(['cate_name' => $tag_io[0], 'as_name' => $tag_io[0], 'parent_id' => 0, 'seo_key' => $tag_io[0], 'seo_desc' => $tag_io[0], 'created_at' => $tag_io[1], 'updated_at' => $tag_io[1]]);
     }
 }
Esempio n. 18
0
 public function getTag($id)
 {
     $article = Article::getArticleListByTagId($id);
     viewInit();
     return homeView('searchTag', ['article' => $article, 'tagName' => Tag::getTagNameByTagId($id)]);
 }
Esempio n. 19
0
 public static function setFieldData()
 {
     $fieldData = array();
     $tag = new Tag();
     $arr = $tag->getFillable();
     foreach ($arr as $v) {
         $fieldData[$v] = Input::get($v);
     }
     unset($arr);
     unset($fieldData['number']);
     unset($tag);
     return $fieldData;
 }
Esempio n. 20
0
 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store()
 {
     $data = \Input::all();
     $tag = \App\Model\Tag::create($data);
     return back();
 }
Esempio n. 21
0
                                {!! Form::submit('修改', ['class' => 'btn btn-success']) !!}
                            </div>
                        </div>
                        {!! Form::close() !!}
                </div>
            </div>
        </div>


<script type="text/javascript" src="{{ asset('/plugin/tags/jquery-ui.js ') }}"></script>
<script type="text/javascript" src="{{ asset('/plugin/tags/bootstrap-tokenfield.js ') }}" charset="UTF-8"></script>

<script type="text/javascript">
    $('#tags').tokenfield({
        autocomplete: {
            source: <?php 
echo \App\Model\Tag::getTagStringAll();
?>
,
            delay: 100

        },
        showAutocompleteOnFocus: !0,
        delimiter: [","],
        tokens: <?php 
echo \App\Model\Tag::getTagStringByTagIds($article->tags);
?>
    })
</script>
@endsection
Esempio n. 22
0
 /**
  * Update the specified resource in storage.
  *
  * @param  int $id
  * @return Response
  */
 public function update(ArticleForm $result, $id)
 {
     //
     try {
         $data = array('title' => $result->input('title'), 'user_id' => Auth::user()->id, 'cate_id' => $result->input('cate_id'), 'content' => $result->input('content'), 'tags' => Tag::SetArticleTags($result->input('tags')));
         if (Request::hasFile('pic')) {
             $data['pic'] = Article::uploadImg('pic');
         }
         if (Article::where('id', $id)->update($data)) {
             Notification::success('更新成功');
             // 清除缓存
             Cache::tags(Article::REDIS_ARTICLE_PAGE_TAG)->flush();
             Cache::forget(Article::REDIS_ARTICLE_CACHE . $id);
             return redirect()->route('backend.article.index');
         }
     } catch (\Exception $e) {
         return redirect()->back()->withErrors(array('error' => $e->getMessage()))->withInput();
     }
 }
Esempio n. 23
0
 /**
  * Remove the specified resource from storage.
  *
  * @param  int $id
  * @return Response
  */
 public function destroy($id)
 {
     //
     if (Tag::destroy($id)) {
         Notification::success('删除成功');
     } else {
         Notification::error('删除失败');
     }
     return redirect()->route('backend.tags.index');
 }
Esempio n. 24
0
 /**
  * Update the specified resource in storage.
  *
  * @param  int $id
  * @return Response
  */
 public function update(ArticleRequest $request, Article $article)
 {
     if ($article = $this->updateArticle($request, $article)) {
         Flash::success('修改成功!');
         return View::make($this->getView('edit'))->withArticle($article)->withTags(Tag::all());
     } else {
         Flash::error('修改失败!');
         return Redirect::back()->withInput();
     }
 }
Esempio n. 25
0
 protected function saveTags($id, $tags)
 {
     //获取标签数组,去重复
     $arrTags = array_unique(explode(' ', $tags));
     if (count($arrTags)) {
         /*储存新的标签名*/
         //取出所有标签名
         $allTags = Tag::lists('name')->toArray();
         //比较获得新标签名
         $newTags = array_diff($arrTags, $allTags);
         //若有新标签则添加
         if (count($newTags)) {
             $arrInsert = array();
             foreach ($newTags as $tag) {
                 $arrInsert[] = array('name' => $tag, 'created_at' => date('Y-m-d h:i:s', time()), 'updated_at' => date('Y-m-d h:i:s', time()));
             }
             Tag::insert($arrInsert);
         }
         /*建立文章与标签的关系*/
         //取出标签的id
         $tagIds = Tag::whereIn('name', $arrTags)->lists('id')->toArray();
         //取出已存在的关系
         $allAttrTagIds = ArticleAttribute::where('article_id', $id)->where('attribute_key', 'tag_id')->lists('attribute_value')->toArray();
         //新增关系
         $newAttrTagIds = array_diff($tagIds, $allAttrTagIds);
         if (count($newAttrTagIds)) {
             $arrInsert = array();
             foreach ($newAttrTagIds as $newAttrTagId) {
                 $arrInsert[] = array('article_id' => $id, 'attribute_key' => 'tag_id', 'attribute_value' => $newAttrTagId, 'created_at' => date('Y-m-d H:i:s', time()), 'updated_at' => date('Y-m-d H:i:s', time()));
             }
             ArticleAttribute::insert($arrInsert);
             Tag::whereIn('id', $newAttrTagIds)->increment('use_number');
         }
         //删除关系
         $delAttrTagIds = array_diff($allAttrTagIds, $tagIds);
         if (count($delAttrTagIds)) {
             ArticleAttribute::where('article_id', $id)->where('attribute_key', 'tag_id')->whereIn('attribute_value', $delAttrTagIds)->delete();
             Tag::whereIn('id', $delAttrTagIds)->decrement('use_number');
         }
     }
 }
Esempio n. 26
0
 /**
  * Add some new tags by ajax.
  *
  * @param Request $request
  */
 public function ajaxAddTags(Request $request)
 {
     $newTags = $request->input('new_tags', []);
     foreach ($newTags as $newTag) {
         $tag = Tag::firstOrCreate(['name' => $newTag]);
     }
     echo "添加成功!";
 }
Esempio n. 27
0
                        <div class="form-group">
                            <div class="col-sm-offset-2 col-sm-10">
                                {!! Form::submit('Criar', ['class' => 'btn btn-success']) !!}
                            </div>
                        </div>
                        {!! Form::close() !!}
                </div>
            </div>
        </div>



<script type="text/javascript" src="{{ asset('/plugin/tags/jquery-ui.js ') }}"></script>
<script type="text/javascript" src="{{ asset('/plugin/tags/bootstrap-tokenfield.js ') }}" charset="UTF-8"></script>

<script type="text/javascript">
    $('#tags').tokenfield({
        autocomplete: {
            source: <?php 
echo \App\Model\Tag::getTagStringAll();
?>
,
            delay: 100
        },
        showAutocompleteOnFocus: !0,
        delimiter: [","]
    })
</script>
@endsection
Esempio n. 28
0
 /**
  * @param $info
  * @param $loc Location
  **/
 protected function createEvent($info, $loc)
 {
     // TODO: validate input types
     $event = Event::create(['title' => $info['title'], 'description' => $info['description'], 'hash' => $info['hash'], 'starting_time' => Carbon::parse($info['starting_time']), 'url' => $info['url']]);
     if (isset($info['ending_time'])) {
         $event->ending_time = Carbon::parse($info['ending_time']);
     }
     if (isset($info['notes'])) {
         $event->notes = $info['notes'];
     }
     $event->location()->associate($loc);
     if (isset($info['tags'])) {
         foreach ($info['tags'] as $tagName) {
             try {
                 $tag = Tag::whereName($tagName)->firstOrFail();
                 $event->tags()->save($tag);
             } catch (ModelNotFoundException $e) {
                 $this->raiseIssue("[{$this->name}]: Unknown tag name '{$tagName}'", "The tag '{$tagName}' is not registered.\n\n" . "Full entity info was:\n\n" . var_export($info, true));
                 continue;
             }
         }
     }
     $event->save();
 }
Esempio n. 29
0
 public function save(Request $request)
 {
     if (!$this->user || !$this->user->isClerk()) {
         $this->alert('warning', 'Only Clerks are allowed to edit assets.', false);
         return $this->view;
     }
     $asset = Asset::firstOrNew(['id' => $request->input('id')]);
     $asset->identifier = $request->input('identifier');
     $asset->state_id = $request->input('state_id');
     $asset->suburb_id = $request->input('suburb_id');
     $asset->street_address = $request->input('street_address');
     $asset->location_description = $request->input('location_description');
     $asset->latitude = $request->input('latitude');
     $asset->longitude = $request->input('longitude');
     $asset->comments = $request->input('comments');
     $asset->save();
     $asset->tags()->sync(Tag::getIds($request->input('tags')));
     $file = File::createFromUploaded($request->file('file'));
     if ($file) {
         $asset->files()->attach($file->id);
     }
     return redirect('assets/' . $asset->id);
 }
Esempio n. 30
0
|--------------------------------------------------------------------------
| Application Routes
|--------------------------------------------------------------------------
|
| Here is where you can register all of the routes for an application.
| It's a breeze. Simply tell Laravel the URIs it should respond to
| and give it the controller to call when that URI is requested.
|
*/
Route::get('/', 'IndexController@index');
Route::controllers(['auth' => 'Auth\\AuthController', 'password' => 'Auth\\PasswordController']);
Route::get('/test', function () {
    DB::listen(function ($sql, $bindings, $time) {
        dump($sql);
    });
    $data = \App\Model\Tag::find(68262);
    dump($data);
    //return $data;
});
Route::get('post/search', 'PostController@search');
Route::get('post/random', 'PostController@random');
Route::get('post/tag/{id}', 'PostController@tag');
Route::get('post/category/{id}', ['as' => 'post.category', 'uses' => 'PostController@category']);
Route::get('post/add-tag/{post_id}/{tag_id}', ['as' => 'post.tag.add', 'uses' => 'TagController@addToPost']);
Route::get('post/del-tag/{post_id}/{tag_id}', ['as' => 'post.tag.del', 'uses' => 'TagController@delTagByPost']);
Route::get('post/user/{id}', 'PostController@user');
Route::resource('user', 'UserController');
Route::resource('post', 'PostController');
Route::resource('category', 'CategoryController');
Route::resource('tag', 'TagController');
Route::resource('file', 'FileController');