public function slugs()
 {
     $slugs = Slug::orderBy('updated_at', 'desc')->get();
     /******************/
     $dirtyCities = Flight::doesntHave('city')->orderBy('country_code')->groupBy('city')->get();
     $cleanCities = City::groupBy('city_slug')->get();
     $noMatches = array();
     $dirtyCountries = array();
     $cleanCountries = array();
     foreach ($dirtyCities as $dirtyCity) {
         $similarsArray = array();
         foreach ($cleanCities as $cleanCity) {
             similar_text($dirtyCity->city_slug, $cleanCity->city_slug, $percent);
             $similarityArray[$cleanCity->city_slug] = $percent;
             $cleanCountries[$cleanCity->city_slug] = $cleanCity->country_code;
         }
         //sort in descending order
         arsort($similarityArray);
         //take first few with highest similarity
         $similarityArray = array_slice($similarityArray, 0, 8);
         $noMatches[$dirtyCity->city_slug] = $similarityArray;
         $dirtyCountries[$dirtyCity->city_slug] = $dirtyCity->country_code;
     }
     return view('scrapers.slugs')->with(['slugs' => $slugs, 'noMatches' => $noMatches, 'dirtyCountries' => $dirtyCountries, 'cleanCountries' => $cleanCountries]);
 }
예제 #2
0
 /**
  * Execute the command.
  *
  * @return void
  */
 public function handle()
 {
     $slug = Slug::create(['name' => $this->request->slug, 'slug_attribute_id' => self::SLUG_ATTRIBUTE_MENU]);
     $this->request['slug_id'] = $slug->id;
     $this->request['gallery'] = '';
     // not yet implemented
     $content = Content::create($this->request->all());
     Activity::create(['text' => $this->auth->linkedName() . ' created new content named ' . $content->linkedName(), 'user_id' => $this->auth->id]);
     Session::flash('flash_message', 'Your content has been created!');
 }
예제 #3
0
 function UpdateSlugTable($request)
 {
     if ($request->has('dirty') and $request->has('clean')) {
         $dirty = $request->input('dirty');
         $clean = $request->input('clean');
         $slug = Slug::firstOrNew(['city_slug_dirty' => $dirty]);
         $slug->city_slug_clean = $clean;
         $slug->save();
     }
 }
예제 #4
0
 /**
  * Execute the command.
  *
  * @return void
  */
 public function handle()
 {
     $slug = Slug::create(['name' => $this->request->slug, 'slug_attribute_id' => self::SLUG_ATTRIBUTE_MENU]);
     $this->request['slug_id'] = $slug->id;
     $menu = new Menu($this->request->all());
     $menu->generateOrder();
     if ($menu->location_id == 0) {
         $parent = Menu::findOrFail($menu->parent_id);
         $menu->location_id = $parent->location_id;
     }
     $menu->save();
     Activity::create(['text' => $this->auth->linkedName() . ' created new menu named ' . $menu->linkedName(), 'user_id' => $this->auth->id]);
     Session::flash('flash_message', 'Your menu has been created!');
 }
예제 #5
0
 public function slug(Web $web, $slug)
 {
     $slug = Slug::where('name', $slug)->firstOrFail();
     if ($slug->slug_attribute_id == SlugAttribute::FOR_MENU) {
         $menu = $slug->menu;
         $contents = $menu->contents->sortByDesc(function ($content) {
             return $content->publish_date;
         });
         if (!$contents) {
             dd('no content');
             // show 404
         }
         $first_content = $contents->first();
         if ($first_content->url) {
             return redirect($first_content->url);
         }
         if (count($contents) == 1) {
             $content = $contents->first();
             // dd($content->slug);
             return redirect(action('WelcomeController@slug', ['slug' => $content->slug->name]));
         } else {
             // dd($contents);
             $contents = $contents->take(5);
             // add skip for pagination
             return view('main.multi_dynamic_contents', compact('web', 'contents'));
         }
     } else {
         if ($slug->slug_attribute_id == SlugAttribute::FOR_CONTENT) {
             $content = $slug->content;
             if ($content->url) {
                 return redirect($content->url);
             }
             return view('main.dynamic_content', compact('web', 'content'));
         }
     }
     // show 404
     return '404';
 }
예제 #6
0
 /**
  * @param $slug
  * @return mixed
  */
 private function postBySlug($slug)
 {
     return $post = Slug::where('slug', $slug)->firstOrFail()->post;
 }
예제 #7
0
 /**
  * @return string
  */
 public function getUrlAttribute()
 {
     $category = $this->category ? $this->category->url : '';
     return $category . '/' . $this->id . '-' . Slug::make($this->caption);
 }
 public function ClearUpVariables($data, $hour_stamp)
 {
     //amend values as I wish
     $data['hour_stamp'] = $hour_stamp;
     $data['hour_stamp_flight_number'] = str_replace(' ', '', $hour_stamp . $data['flight_number']);
     //unique column
     $data['scheduled_time'] = Carbon::createFromFormat('d.m. H:i', $data['scheduled_time']);
     //airline code
     preg_match("|^..|", $data['flight_number'], $output_array_3);
     $data['airline_code'] = strtolower($output_array_3[0]);
     if ($data['airline_code'] == "ez") {
         $data['airline_code'] = "u2";
     }
     //easyjet not using their IATA code U2 but EZY - manual correction
     //terminal
     preg_match("|[1-9]|", $data['terminal'], $output_array_4);
     $data['terminal'] = $output_array_4[0];
     //destination
     $data['destination'] = strtolower($data['destination']);
     //keep all such data in lowercase (because Sqlite differentiate between Capitals and lower)
     preg_match("|(.*)\\((.*)\\)|", $data['destination'], $output_array_1);
     if (count($output_array_1) > 1) {
         $CitySlashAirport = $output_array_1[1];
         $data['country_code'] = $output_array_1[2];
     } else {
         $CitySlashAirport = null;
         $data['country_code'] = 'xx';
     }
     unset($data['destination']);
     //in case some strange codes comes
     $country = Country::where('country_code', $data['country_code']);
     if (count($country) == 0) {
         $newcountry = new Country();
         $newcountry->country_code = $data['country_code'];
         $newcountry->country_name = 'Undefined';
         $newcountry->save();
     }
     $output_array_2 = preg_split("|\\/|", $CitySlashAirport);
     $data['city'] = $output_array_2[0];
     if (empty($data['city'])) {
         $data['city'] = 'empty';
     }
     if (count($output_array_2) > 1) {
         $data['airport'] = $output_array_2[1];
     } else {
         $data['airport'] = null;
     }
     //city_slug
     $slug = new SlugClass();
     $data['city_slug'] = $slug->slugify($data['city']);
     //find if this city_slug is in cities table
     $city_slug_in_cities = City::where('city_slug', $data['city_slug'])->first();
     if (empty($city_slug_in_cities)) {
         $city_slug_bridge = Slug::where('city_slug_dirty', $data['city_slug'])->first();
         if (!empty($city_slug_bridge)) {
             $data['city_slug'] = $city_slug_bridge->city_slug_clean;
             echo $data['city_slug'];
         }
     }
     $data = array_map('trim', $data);
     //trim values
     return $data;
 }