public function tags() { $message_to_show = ""; if ($_SERVER['REQUEST_METHOD'] == 'POST') { $tag = new Tags(); $tag_name = Input::get('tag_name'); // OK if (!empty($tag_name)) { $is_tag_already_exist = $tag->check_tag($tag_name); if (!$is_tag_already_exist) { $is_tag_inserted = $tag->insert_tag($tag_name); if ($is_tag_inserted) { $message_to_show = "Tag Inserted successfully"; return redirect("/admin/tags")->withMessage($message_to_show); } else { $message_to_show = "Tag Not Inserted, Try after some time"; } } else { $message_to_show = "Tag already exist, insert any other tag"; } } else { $message_to_show = "Complete info not given, please give all information"; } return redirect("/admin/tags")->withMessage($message_to_show); } else { $tag = new Tags(); $get_all_tags = $tag->get_all_tags(); if (!empty($get_all_tags)) { $return_data = $get_all_tags; } else { $return_data = "No Tag Found"; } return view('/admin/tags')->withTags($return_data); } }
/** * @param $id * @param TagRequest $request * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector */ public function update($id, TagRequest $request) { // $tags = Tags::findorfail($id); $tags->update($request->all()); return redirect(action('TagsController@index')); }
/** * Run the database seeds. * * @return void */ public function run() { $faker = Faker::create(); foreach (range(1, 10) as $index) { Tags::create(['name' => $faker->word]); } }
/** * 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'); }
/** * Store a newly created resource in storage. * * @param Request $request * @return Response */ public function store(Request $request) { $this->validate($request, ['name' => 'required']); Tags::create($request->all()); \Flash::success('Tag created'); return redirect('/tags'); }
public function random_tag() { $tags = \App\Tags::all(); $random_key = array_rand($tags->toArray(), 1); //dd($this->tags[$random_key]->name); return $tags[$random_key]->id; }
public function getAllTag() { $tag_css = array('label-default', 'label-success', 'label-warning', 'label-info'); $page_title = "All Tags"; $tags = Tags::all(); $data = compact('page_title', 'tags', 'tag_css'); return view('tags.index', $data); }
public function find_and_get_tag_ids($keywords) { $tag_ids = Tags::whereIn('tag', $keywords)->get(); if (count($tag_ids) > 0) { return $tag_ids->toArray(); } else { return ""; } }
/** * 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(); }); }
/** * Run the database seeds. * * @return void */ public function run() { $loop = 35; $faker = $this->getFaker(); for ($i = 0; $i < $loop; $i++) { $name = $faker->word; $user = $this->getRandomUser(); $data = ['tag' => $name, 'created_by' => $user]; \App\Tags::create($data); print 'Done ' . $loop . ' entries was created'; } }
/** * Run the database seeds. * * @return void */ public function run() { $faker = Faker::create(); //a real lesson id //a real tag id $lessonIds = Lesson::get()->lists('id')->all(); //returns an array of all lesson ids $tagIds = Tags::get()->lists('id')->all(); //returns an array of all tag ids foreach (range(1, 30) as $index) { //use query builder DB::table('lessons_tags')->insert(['lessons_id' => $faker->randomElement($lessonIds), 'tags_id' => $faker->randomElement($tagIds)]); } }
/** * Display the specified resource. * * @param int $id * @return Response */ public function show($id) { try { $resp = Tags::find($id); if (!$resp) { return $this->respondNotFound(); } /*foreach ($resp->points as $point) { var_dump($point); }*/ return Fractal::item($resp, new \App\Transformers\TagTransformer())->responseJson(200); } catch (Exception $e) { return $this->respondWithError(); } }
/** * Bootstrap any application services. * * @return void */ public function boot(Request $request) { $uri = $request->path(); //获取当前uri,做导航栏active, 面包学导航 $navLists = config('myConfig.navLists'); $activeNav = []; foreach ($navLists as $key => $navList) { foreach ($navList as $navLt) { if (preg_match($navLt, $uri)) { if ($key == 'articles_one') { $activeNav = ['articles', '']; } else { $activeNav = [$key]; } break; } } } // dd($activeNav); $tagLists = Tags::getTagList(config('myConfig.tagListsNums')); view()->share(['tagLists' => $tagLists, 'activeNavs' => $activeNav]); }
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'); }
/** * Update the specified resource in storage. * * @param int $id * @return Response */ public function update($id, Requests\PostsFormRequest $request) { $post = Posts::findOrFail($id); $input = $request->all(); $input['alias'] = HelperFunctions::str2url($request->title); $post->update($input); $categories_ids = []; foreach ($input['categories_list'] as $value) { $category = Categories::findOrNew($value); if ($category->exists) { array_push($categories_ids, $value); } else { $category->name = $value; $category->save(); array_push($categories_ids, $category->id); } } $post->categories()->sync($categories_ids); $tags_ids = []; foreach ($input['tags_list'] as $value) { $tag = Tags::findOrNew($value); if ($tag->exists) { array_push($tags_ids, $value); } else { $tag->name = $value; $tag->save(); array_push($tags_ids, $tag->id); } } $post->tags()->sync($tags_ids); \Session::flash('success', 'Post updated'); return redirect('/'); }
public function post_question() { if ($_SERVER['REQUEST_METHOD'] == 'POST') { $root_cat_id = Input::get('root'); // OK $child_cat_id = Input::get('child'); // OK $sub_cat_id = Input::get('sub'); // OK $question_content = Input::get('question_content'); // OK $tags = Input::get('tags'); // OK $cat_id = $root_cat_id; if ($child_cat_id != null) { $cat_id = $child_cat_id; } if ($sub_cat_id != null) { $cat_id = $sub_cat_id; } $tags_array = array(); if (!empty($tags)) { foreach ($tags as $tag) { array_push($tags_array, $tag); } } $tag_obj = new Tags(); $get_tags_info = $tag_obj->get_tags_ids($tags_array); $tags_ids = array(); if (!empty($get_tags_info)) { foreach ($get_tags_info as $tag_info) { array_push($tags_ids, $tag_info['id']); } } $user = new User(); $get_user_data = $user->get_user_profile_data(); $user_id = $get_user_data['id']; $question = new Questions(); $is_question_posted = $question->post_question($user_id, $cat_id, $question_content); if ($is_question_posted) { $question_id = $is_question_posted['id']; } $question_tag = new Question_Tag(); $insert_question_tag_data = $question_tag->insert_question_tag_data($question_id, $tags_ids); if ($insert_question_tag_data) { return redirect("/"); } else { return redirect("user/profile"); } } else { $cat = new Category(); $root_category = array(); $all_tags = array(); $root_categories = $cat->get_categories_by_parent_id(0); foreach ($root_categories as $category) { array_push($root_category, $category['title']); } $tag = new Tags(); $get_all_tags = $tag->get_all_tags(); if (!empty($get_all_tags)) { $all_tags = $get_all_tags; } return view('user/post_question')->withRootCategories($root_categories)->withTags($all_tags); } }
/** * 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(); }
public function getTagsByPropositionId($propositionId) { return Tags::join('propositions_tags', 'propositions_tags.tag_id', '=', 'tags.id')->join('propositions', 'propositions.propositionId', '=', 'propositions_tags.proposition_id')->where('propositions.propositionId', '=', $propositionId)->get(); }
public function TagQuestions($id) { $tag = Tags::findorfail($id); $questions = $tag->questions; return view('Question.tagQuestions', compact('tag', 'questions')); }
/** * 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)); }
/** * 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; }
public static function removeTag($postID) { Tags::where('PostID', '=', $postID)->delete(); }
public function datavis(Request $request) { $user = Auth::user(); //$user = $request->user(); //dd($request); $topics = Artefact::with(['the_author', 'tags', 'last_modifier'])->whereNull('parent_id')->orderBy('created_at', 'desc')->orderBy('last_modified', 'desc')->get(); $auteurs = DB::table('users')->select('id', 'name')->distinct()->get(); $tags = Tags::orderBy('tag')->get(); $aantalAntwoorden = DB::table('artefacts')->select(DB::raw('count(*) as aantal_antwoorden, thread'))->groupBy('thread')->get(); return view('datavis', ['topic' => $topics, 'user' => $user, 'auteurs' => $auteurs, 'tags' => $tags, 'aantalAntwoorden' => $aantalAntwoorden]); }
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]); }
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); }
public function tag($slug) { $tag = Tags::where('slug', $slug)->with('posts')->first(); return view('page.tag')->with(compact('tag')); }
Response::done($response); } else { CoreUtils::notFound(); } } } } // Tag list if (preg_match(new RegExp('^tags'), $data)) { $Pagination = new Pagination("cg/tags", 20, $CGDb->count('tags')); CoreUtils::fixPath("/cg/tags/{$Pagination->page}"); $heading = "Tags"; $title = "Page {$Pagination->page} - {$heading} - {$Color} Guide"; $Tags = Tags::getFor(null, $Pagination->getLimit(), true); if (isset($_GET['js'])) { $Pagination->respond(Tags::getTagListHTML($Tags, NOWRAP), '#tags tbody'); } $js = array('paginate'); if (Permission::sufficient('staff')) { $js[] = "{$do}-tags"; } CoreUtils::loadPage(array('title' => $title, 'heading' => $heading, 'view' => "{$do}-tags", 'css' => "{$do}-tags", 'js' => $js)); } // Change list if (preg_match(new RegExp('^changes'), $data)) { $Pagination = new Pagination("cg/changes", 50, $Database->count('log__color_modify')); CoreUtils::fixPath("/cg/changes/{$Pagination->page}"); $heading = "Major {$Color} Changes"; $title = "Page {$Pagination->page} - {$heading} - {$Color} Guide"; $Changes = Updates::get(null, $Pagination->getLimitString()); if (isset($_GET['js'])) {
public function postUpdate(Request $request) { $all = $request->all(); $validator = Validator::make($all, ['id' => 'required', 'title' => 'required|max:255', 'content' => 'required']); if (isset($all['active'])) { $all['active'] = true; } else { $all['active'] = false; } if ($validator->fails()) { $page_title = 'Edit Post'; $categories = Categories::all(); $tags = Tags::all(); $data = compact('page_title', 'categories', 'tags'); return view('posts.edit', $data)->withErrors($validator->errors()); } $post = Posts::findOrFail($all['id']); $markdown_content = $all['content']; $html_content = $this->htmlMarkdownConvertor->convertMarkdownToHtml($markdown_content); $post->title = $all['title']; $post->content = $html_content; $post->markdown_content = $markdown_content; $post->active = $all['active']; $post->category_id = $all['category_id']; if (Gate::allows('update-post', $post)) { $post->save(); $this->savePostsTags($all['tags'], $post->id); } return redirect(route('getPostPage')); }
/** * Store a newly created resource in storage. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function store(Request $request) { //Default for number of images in the post $num_img = 0; $locationID = null; $taglist = null; if (Auth::user()->uuid) { if ($request->data) { $json = $request->data; $topicUUID = rand(0, 10) . str_random(12) . rand(0, 10); $topicSlug = str_slug($json['title'], "-") . '-' . $topicUUID; //Reviews if ($json['reviews'] != 'false') { $count = 0; foreach ($json['reviews'] as $review) { //there is a bug that says name is empty sometime if (!empty($review['name'])) { $review_data[$count] = array('topic_uuid' => $topicUUID, 'user_uuid' => Auth::user()->uuid, 'criteria' => $review['name'], 'scores' => $review['rating'], 'is_template' => TRUE, 'created_at' => date("Y-m-d H:i:s")); $count++; } } Reviews::insert($review_data); } //Location if (!empty($json['location'])) { $locationID = $json['location']['id']; //Check location exists, if not create $location_exist = DB::table('locations')->where('external_id', $locationID)->count(); if ($location_exist == 0) { $location = new Location(); $location->source = 'facebook'; //hardcode for now $location->external_id = $locationID; $location->name = $json['location']['name']; $location->category = !empty($json['location']['category']) ? $json['location']['category'] : null; $location->street = !empty($json['location']['location']['street']) ? $json['location']['location']['street'] : null; $location->city = !empty($json['location']['location']['city']) ? $json['location']['location']['city'] : null; $location->state = !empty($json['location']['location']['state']) ? $json['location']['location']['state'] : null; $location->country = !empty($json['location']['location']['country']) ? $json['location']['location']['country'] : null; $location->zip = !empty($json['location']['location']['zip']) ? $json['location']['location']['zip'] : null; $location->latitude = $json['location']['location']['latitude']; $location->longitude = $json['location']['location']['longitude']; $location->save(); } //GEt the ID } //Tag list - to store in the topic table if (!empty($json['tags'])) { $taglist = implode(",", $json['tags']); } //Images if (!empty($json['images'])) { $count = 0; //Insert images in another table foreach ($json['images'] as $image) { $img_data[$count] = array('topic_uuid' => $topicUUID, 'user_uuid' => Auth::user()->uuid, 'filename' => $image, 'created_at' => date("Y-m-d H:i:s")); $count++; } $num_img = $count; TopicImages::insert($img_data); } $topic = new Topic(); $topic->uuid = $topicUUID; $topic->type = $json['type']; $topic->uid = Auth::user()->uuid; $topic->topic = clean($json['title']); $topic->body = preg_replace('/(<[^>]+) style=".*?"/i', '$1', clean($json['body'])); $topic->text = clean($json['text']); $topic->category = $json['categories']; $topic->slug = $topicSlug; $topic->num_img = $num_img; $topic->tags = $taglist; $topic->location_id = $locationID; $topic->save(); $tag_data = array(); $count = 0; //Tags - to store in tags table if (!empty($json['tags'])) { //Insert tags in another table foreach ($json['tags'] as $tag) { Redis::zadd('post:tag' . $tag, $topic->uuid, $topic->uuid); Redis::sadd('post:' . $topic->uuid . ':tags', $tag); //Master link of tags Redis::sadd('post:tags', $tag); $tag_data[$count] = array('topic_uuid' => $topicUUID, 'title' => clean($tag), 'created_at' => date("Y-m-d H:i:s")); $count++; } Tags::insert($tag_data); } $topicEvents = Topic::find($topic->id); event(new \App\Events\TopicPostEvent($topicEvents)); $data = array("slug" => $topicSlug, "author" => Auth::user()->displayname, "type" => $json['type'], "topic_uuid" => $topicUUID); return $data; } } else { return "not login"; } }
<thead><?php $cspan = Permission::sufficient('staff') ? '" colspan="2' : ''; $refresher = Permission::sufficient('staff') ? " <button class='typcn typcn-arrow-sync refresh-all' title='Refresh usage data on this page'></button>" : ''; echo $thead = <<<HTML \t\t\t<tr> \t\t\t\t<th class="tid">ID</th> \t\t\t\t<th class="name{$cspan}">Name</th> \t\t\t\t<th class="title">Description</th> \t\t\t\t<th class="type">Type</th> \t\t\t\t<th class="uses">Uses{$refresher}</th> \t\t\t</tr> HTML; ?> </thead> <?php echo Tags::getTagListHTML($Tags); ?> <tfoot><?php echo $thead; ?> </tfoot> </table> <?php echo $Pagination->HTML; ?> </div> <? echo CoreUtils::exportVars(array( 'Color' => $Color, 'color' => $color, 'TAG_TYPES_ASSOC' => Tags::$TAG_TYPES_ASSOC,