/**
  * Store a newly created resource in storage.
  *
  * @param Request $request
  * @return array
  */
 public function store(Request $request)
 {
     $this->validate($request, ['category_id' => 'required', 'tags_id' => 'required', 'title' => 'required|max:250', 'alias' => 'required|max:250', 'description' => 'required', 'short_description' => 'required|max:1000', 'meta_description' => 'required|max:1000']);
     $article = new Articles();
     $article->fill($request->all());
     $article->user_id = Auth::user()->id;
     $article->save();
     //        $article = Auth::user()->articles()->create($request->all());
     /**
      * Check tags_id input and create tags if not number in input
      */
     $tag_ids = [];
     foreach ($request->input('tags_id') as $tag_input) {
         if (ctype_digit($tag_input)) {
             //it`s number, save to ids array
             array_push($tag_ids, $tag_input);
         } else {
             //create new tag with this input name if not exist
             $tag = Tags::where('name', $tag_input)->first();
             if (!$tag) {
                 $tag = Tags::create(['name' => $tag_input]);
             }
             array_push($tag_ids, $tag->id);
         }
     }
     $article->tags()->attach($tag_ids);
     \Flash::success('Article created');
     return redirect()->action('ArticlesController@index');
 }
Esempio n. 2
0
 public function check_tag($tag)
 {
     $tags = Tags::where('tag', '=', $tag)->get()->toArray();
     if (count($tags) == 1) {
         return TRUE;
     }
     return FALSE;
 }
 /**
  * Define your route model bindings, pattern filters, etc.
  *
  * @param  \Illuminate\Routing\Router  $router
  * @return void
  */
 public function boot(Router $router)
 {
     parent::boot($router);
     $router->model('todos', 'App\\Todos');
     $router->model('tags', 'App\\Tags');
     $router->bind('tagsearch', function ($name) {
         return \App\Tags::where('name', $name)->firstOrFail();
     });
 }
Esempio n. 4
0
 public function searchTag($term)
 {
     if (isset($term)) {
         $results = Tags::where('content', 'LIKE', "%{$term}%")->get();
     } else {
         $results = $this->getAllTags();
     }
     return $results;
 }
Esempio n. 5
0
 /**
  * Display the specified resource.
  *
  * @param  string $name
  * @return Response
  */
 public function show($name)
 {
     $tag = Tags::where('name', $name)->first();
     if (!$tag) {
         return redirect()->action('CategoriesController@index');
     }
     $pageDescription = 'Tag: ' . $name;
     $articles = $tag->articles()->simplePaginate(Articles::itemsPerPage);
     return view('articles.index', compact('articles', 'pageDescription'));
 }
Esempio n. 6
0
 public function searchPostsByHashtag(Request $request)
 {
     $data = $request->all();
     preg_match_all('/\\b([a-zA-Z0-9]+)\\b/', strtoupper($data['HashtagSearch']), $matches, PREG_PATTERN_ORDER);
     $hashtags = $matches[1];
     $posts = Posts::all()->toArray();
     $rank = array();
     foreach ($hashtags as $ht) {
         foreach ($posts as $key => $post) {
             if (!array_key_exists($key, $rank)) {
                 $rank += array($key => 0);
             }
             $postHashtag = Tags::where('PostID', '=', $post['id'])->get()->toArray();
             foreach ($postHashtag as $pht) {
                 if (stripos(Hashtags::find($pht['HashtagID'])->Hashtag, $ht) !== false) {
                     $rank[$key]++;
                 }
             }
         }
     }
     foreach ($rank as $key => $value) {
         if ($value < 1) {
             unset($rank[$key]);
         }
     }
     arsort($rank);
     $result = array();
     $posts = Posts::all();
     foreach ($rank as $key => $value) {
         $result += array($key => $posts[$key]);
     }
     preg_match_all('/\\b([a-zA-Z0-9]+)\\b/', $data['HashtagSearch'], $matches, PREG_PATTERN_ORDER);
     $hashtags = $matches[1];
     $Hashtags = '';
     foreach ($hashtags as $ht) {
         $Hashtags .= $ht . ' ';
     }
     return view('search')->with(['Posts' => $result, 'Hashtags' => $Hashtags]);
 }
Esempio n. 7
0
 public static function removeTag($postID)
 {
     Tags::where('PostID', '=', $postID)->delete();
 }
Esempio n. 8
0
 public function update(Request $request)
 {
     $articleResult = Articles::find($request->input('id'));
     if (!$articleResult) {
         return redirect('backend/articles');
     }
     $request->request->set('published_at', Carbon\Carbon::now());
     $this->validate($request, ['title' => 'required', 'content' => 'required', 'published_at' => 'required', 'tags' => 'required']);
     $input = $request->all();
     $articleResult->update($input);
     $raw_tags = array();
     //文章没有修改前的标签
     foreach ($articleResult->tags as $raw_v) {
         $raw_tags[] = $raw_v->tag_name;
     }
     $new_tags = explode(',', ltrim(rtrim(trim($input['tags']), ','), ','));
     $new_tags = array_unique(array_map('trim', $new_tags));
     //修改后的标签
     $tags_inserts = array_diff($new_tags, $raw_tags);
     //需要和文章新增关系标签
     $tags_deletes = array_diff($raw_tags, $new_tags);
     //需要和文章去除关系的标签
     // 		dd($tags_deletes);
     DB::beginTransaction();
     try {
         if (isset($tags_inserts) && count($tags_inserts)) {
             foreach ($tags_inserts as $tags_insert) {
                 if ($tags_insert) {
                     $tag_res = Tags::where('tag_name', $tags_insert)->first();
                     if (!$tag_res) {
                         $articleResult->tags()->saveMany(new Tags(['tag_name' => $tags_insert, 'use_nums' => 1]));
                     } else {
                         $tag_res->use_nums++;
                         $tag_res->save();
                         $tag_res->articles()->attach($articleResult->id);
                     }
                 }
             }
         }
         unset($tag_res);
         if (isset($tags_deletes) && count($tags_deletes)) {
             foreach ($tags_deletes as $tags_delete) {
                 if ($tags_delete) {
                     $tag_res = Tags::where('tag_name', $tags_delete)->first();
                     if ($tag_res) {
                         $tag_res->use_nums--;
                         $tag_res->save();
                         $tag_res->articles()->detach($articleResult->id);
                     }
                 }
             }
         }
         DB::commit();
     } catch (\Exception $e) {
         DB::rollBack();
         dd($e->getMessage());
     }
     return redirect('backend/articles');
 }
Esempio n. 9
0
 /**
  * Update the specified resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function update(Requests\PostRequest $request, $id)
 {
     $post = Posts::where('id', $id)->firstOrFail();
     if (!empty($request->file('image')) && $request->file('image')->isValid()) {
         $destinationPath = public_path() . "/images/";
         // upload path
         $extension = $request->file('image')->getClientOriginalExtension();
         // getting image extension
         $fileName = $post->url . '.' . $extension;
         // renameing image
         $request->file('image')->move($destinationPath, $fileName);
         // uploading file to given path
         $post->image = $fileName;
     }
     $post->fill($request->only(['title', 'post']));
     $post->save();
     Posts::findOrFail($id)->tags()->detach();
     $tags = [];
     foreach ($this->getTags($request->input('tags')) as $tag) {
         if (!empty($tag)) {
             $isFind = Tags::where('name', $tag)->get()->count();
             if ($isFind == 0) {
                 $tags[] = new Tags(['name' => $tag]);
             } else {
                 $tags[] = Tags::where('name', $tag)->first();
             }
         }
     }
     $post->tags()->saveMany($tags);
     return back();
 }
Esempio n. 10
0
 public function newTopic(Request $request)
 {
     $user = Auth::user();
     if ($user && $user->role == "editor") {
         // Als de gebruiker ingelogd is en editor is, anders niets doen
         try {
             $filename = uniqid();
             DB::beginTransaction();
             $topic = new Artefact();
             $topic->author = $user->id;
             $thread = DB::table('artefacts')->max('thread') + 1;
             $topic->thread = $thread;
             if ($request->input('topic_title')) {
                 $topic->title = $request->input('topic_title');
             } else {
                 $topic->title = 'No title';
             }
             if ($request->input('topic_copyright')) {
                 $topic->copyright = $request->input('topic_copyright');
             }
             // De eigenlijke inhoud verwerken en het type bepalen en juist zetten
             $at = null;
             switch ($request->input('topic_temp_type')) {
                 case 'text':
                     if ($request->input('topic_text')) {
                         $topic->contents = $request->input('topic_text');
                     }
                     $at = ArtefactType::where('description', 'text')->first();
                     break;
                 case 'video':
                     if ($request->input('topic_url') && $request->input('topic_url') != null && $request->input('topic_url') != '') {
                         // URL meegegeven voor video
                         $url = $request->input('topic_url');
                         if (strpos($url, 'youtube') !== false || strpos($url, 'youtu.be') !== false) {
                             // Youtube video
                             $yt = BmoocController::parseYoutube($url);
                             if ($yt && $yt != '') {
                                 $topic->url = 'http://www.youtube.com/embed/' . $yt;
                                 $at = ArtefactType::where('description', 'video_youtube')->first();
                             } else {
                                 throw new Exception('The URL you entered is not a valid link to a YouTube video');
                             }
                         } elseif (strpos($url, 'vimeo.com') !== false) {
                             // Vimeo video
                             $topic->url = '//player.vimeo.com/video/' . substr($url, strpos($url, 'vimeo.com/') + 10);
                             $at = ArtefactType::where('description', 'video_vimeo')->first();
                         } else {
                             throw new Exception('The URL you entered is not a valid link to a YouTube or Vimeo video.');
                         }
                     } else {
                         // Kan niet voorkomen, maar voor de veiligheid wel fout opwerpen
                         //$topic->url = 'https://www.youtube.com/embed/YecyKnQUcBY'; // Dummy video
                         throw new Exception('No video URL provided for new topic of type video');
                     }
                     break;
                 case 'image':
                     if (Input::file('topic_upload') && Input::file('topic_upload')->isValid()) {
                         $extension = strtolower(Input::file('topic_upload')->getClientOriginalExtension());
                         if (in_array($extension, ['jpg', 'png', 'gif', 'jpeg'])) {
                             $destinationPath = 'uploads';
                             Input::file('topic_upload')->move($destinationPath, $filename);
                             $topic->url = $filename;
                             $at = ArtefactType::where('description', 'local_image')->first();
                         } else {
                             throw new Exception('Image should be a JPEG, PNG or GIF.');
                         }
                     } elseif ($request->input('topic_url') && $request->input('topic_url') != null && $request->input('topic_url') != '') {
                         // URL voor de afbeelding
                         if (getimagesize($request->input('topic_url'))) {
                             // De afbeelding is een echte afbeelding als dit niet false teruggeeft
                             $topic->url = $request->input('topic_url');
                             $at = ArtefactType::where('description', 'remote_image')->first();
                         } else {
                             throw new Exception('The document in the url is not an image');
                         }
                     }
                     break;
                 case 'file':
                     if (Input::file('topic_upload') && Input::file('topic_upload')->isValid()) {
                         $extension = strtolower(Input::file('topic_upload')->getClientOriginalExtension());
                         if (in_array($extension, ['pdf'])) {
                             $destinationPath = 'uploads';
                             Input::file('topic_upload')->move($destinationPath, $filename);
                             $topic->url = $filename;
                             $at = ArtefactType::where('description', 'local_pdf')->first();
                         } else {
                             throw new Exception('File should be a PDF.');
                         }
                     } elseif ($request->input('topic_url') && $request->input('topic_url') != null && $request->input('topic_url') != '') {
                         // URL voor de afbeelding
                         if (getimagesize($request->input('topic_url'))) {
                             // De afbeelding is een echte afbeelding als dit niet false teruggeeft
                             $topic->url = $request->input('topic_url');
                             $at = ArtefactType::where('description', 'remote_pdf')->first();
                         }
                     }
                     break;
             }
             // Thumbnails opslaan
             if (isset($topic->url)) {
                 // small
                 if ($request->input('thumbnail_small') && $request->input('thumbnail_small') != null && $request->input('thumbnail_small') != '') {
                     $destinationPath = 'uploads/thumbnails/small/' . $topic->url;
                     $data = base64_decode(preg_replace('#^data:image/\\w+;base64,#i', '', $request->input('thumbnail_small')));
                     file_put_contents($destinationPath, $data);
                 }
                 // large
                 if ($request->input('thumbnail_large') && $request->input('thumbnail_large') != null && $request->input('thumbnail_large') != '') {
                     $destinationPath = 'uploads/thumbnails/large/' . $topic->url;
                     $data = base64_decode(preg_replace('#^data:image/\\w+;base64,#i', '', $request->input('thumbnail_large')));
                     file_put_contents($destinationPath, $data);
                 }
             }
             if ($at) {
                 $at->artefacts()->save($topic);
             } else {
                 throw new Exception('Selected file is not a valid image or PDF.');
             }
             // Einde inhoud verwerken en type bepalen
             // Bijlage verwerken
             if (Input::file('topic_attachment') && Input::file('topic_attachment')->isValid()) {
                 $extension = strtolower(Input::file('topic_attachment')->getClientOriginalExtension());
                 if (in_array($extension, ['jpg', 'png', 'gif', 'jpeg', 'pdf'])) {
                     $destinationPath = 'uploads/attachments';
                     $filename = base64_encode(Input::file('topic_attachment')->getClientOriginalName() . time()) . '.' . $extension;
                     Input::file('topic_attachment')->move($destinationPath, $filename);
                     //$topic->url = $filename;
                     $topic->attachment = $filename;
                 } else {
                     throw new Exception('Attachment should be a JPG, PNG, GIF or PDF');
                 }
             }
             // Topic opslaan
             $topic->save();
             // Tags verwerken
             if ($request->input('topic_new_tag')) {
                 foreach ($request->input('topic_new_tag') as $newtag) {
                     if ($newtag != '') {
                         $existingtag = Tags::where('tag', strtolower($newtag))->first();
                         if ($existingtag) {
                             $existingtag->artefacts()->save($topic);
                         } else {
                             $newTag = Tags::create(['tag' => strtolower($newtag), 'times_used' => 1]);
                             $newTag->artefacts()->save($topic);
                         }
                     } else {
                         throw new Exception('Tags must not be empty!');
                     }
                 }
             }
             DB::commit();
             // add handler for Ajax requests
             if ($request->isXmlHttpRequest()) {
                 return Response::json(['status' => '200', 'url' => URL::to('/')], 200);
             } else {
                 return Redirect::back();
             }
         } catch (Exception $e) {
             DB::rollback();
             //return view('errors.topic', ['error' => $e]);
             throw $e;
         }
     }
     // End if ($user)
 }
Esempio n. 11
0
 public function tag($slug)
 {
     $tag = Tags::where('slug', $slug)->with('posts')->first();
     return view('page.tag')->with(compact('tag'));
 }
Esempio n. 12
0
 /**
  * Check tags_id input and create tags if not number in input
  *
  * @param array $tags
  * @return array tags_ids
  */
 public function checkTags(array $tags)
 {
     $tag_ids = [];
     foreach ($tags as $tag_input) {
         if (ctype_digit($tag_input)) {
             //it`s number, save to ids array
             array_push($tag_ids, $tag_input);
         } else {
             //create new tag with this input name if not exist
             $tag = Tags::where('name', $tag_input)->first();
             if (!$tag) {
                 $tag = Tags::create(['name' => $tag_input]);
             }
             array_push($tag_ids, $tag->id);
         }
     }
     return $tag_ids;
 }
 private function savePostsTags($data, $post_id)
 {
     $tags = explode(',', $data);
     foreach ($tags as $tag) {
         $normalized = $this->strtoupperForCN($tag);
         $tag_ref = Tags::where('normalized', $normalized)->first();
         if (is_null($tag_ref)) {
             $tag_ref = Tags::create(['name' => $tag, 'normalized' => $normalized]);
         }
         $posts_tags = PostsTags::where('post_id', $post_id)->where('tag_id', $tag_ref->id)->first();
         if (is_null($posts_tags)) {
             $posts_tags = PostsTags::create(['post_id' => $post_id, 'tag_id' => $tag_ref->id]);
         }
     }
 }
Esempio n. 14
0
 public function loadAcademy($id)
 {
     $academy = Academy::where('academy_id', $id)->first();
     $data = array('academy_name' => $academy->academy_name);
     Mail::send('email.email', $data, function ($message) {
         $message->from('*****@*****.**', 'Demo Account');
         $message->subject('Enquiry');
         $message->to('*****@*****.**');
     });
     $tags = Tags::where('academy_id', $id)->get();
     $artifacts = Artifacts::where('academy_id', $id)->get();
     return view('pages.academy')->with('academy', $academy)->with("tags", $tags)->with("artifacts", $artifacts);
 }
Esempio n. 15
0
 /**
  * Show the form for editing the specified resource.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function edit($id)
 {
     if (!AuthController::checkPermission()) {
         return redirect('/');
     }
     $Post = Posts::find($id);
     $ahtk = Tags::where('PostID', '=', $id)->get()->toArray();
     $Hashtag = '';
     foreach ($ahtk as $k) {
         $ht = Hashtags::find($k['HashtagID'])['Hashtag'];
         if (strlen($ht) > 0) {
             $Hashtag .= '#' . $ht . ' ';
         }
     }
     return view('admin.editpost', compact('Post') + array('Hashtag' => $Hashtag));
 }
Esempio n. 16
0
 public function searchTags($start)
 {
     $tags = Tags::where('tag', 'like', $start . '%')->orderBy('times_used', 'desc')->orderBy('tag', 'asc')->lists('tag');
     return response()->json($tags);
 }