Пример #1
0
 public function news(Request $request)
 {
     if ($request->isMethod('POST')) {
         //            News::create($request->except('_token'));
         // read image from temporary file
         $file = $request->file('imagePrev');
         $img = Image::make($file->getRealPath());
         $nameFile = $file->getClientOriginalName();
         //          resize image
         $img->fit(263, 263);
         // save image
         $img->save("images/" . $nameFile);
         News::create(['text' => $request->input('editor1'), 'header' => $request->input('header'), 'picture' => "images/" . $nameFile]);
         //            switch ( $request->input('type') ) {
         //                case 'insert':
         //                    News::create($request->except('_token'));
         //                    break;
         //                case 'update':
         //                    News::find( $request->input('id') )->update([
         //                        'header' => $request->input('header'),
         //                        'text' => $request->input('editor1'),
         //                    ]);
         //                    break;
         //            }
     }
     if ($request->isMethod('GET')) {
         $item = News::find($request->input('remove'));
         if ($item) {
             $item->delete();
         }
     }
     $news = News::orderBy('created_at', 'DESC')->paginate(15);
     return view('admin/news', ['news' => $news]);
 }
Пример #2
0
 /**
  * Show the form for editing the specified news.
  *
  * @param  int  $id
  * @return \Illuminate\View\View
  */
 public function edit($id)
 {
     $news = News::find($id);
     $direction = News::$direction;
     $language = News::$language;
     return view('admin.news.edit', compact('news', "direction", "language"));
 }
Пример #3
0
 public function show($id)
 {
     $news = News::find($id);
     $news->visit++;
     $news->save();
     return view('news.show')->withNavSelection(3)->withTagSelection(-1)->withNews($news);
 }
Пример #4
0
 public function delete_news(Request $request)
 {
     $id = $request->item_id;
     $news = News::find($id);
     $news->delete();
     return back()->with('message', "Новость удалена");
 }
Пример #5
0
 public function show($id)
 {
     $article = News::find($id);
     $year = Carbon::now();
     $year = $year->year;
     return view('shownews')->with('article', $article)->with('year', $year);
 }
Пример #6
0
 /**
  * Show the form for editing the specified news.
  *
  * @param  int  $id
  * @return \Illuminate\View\View
  */
 public function edit($id)
 {
     $news = News::find($id);
     $sitelanguages = Sitelanguages::site_access()->join('sites', function ($join) {
         $join->on('sites.id', '=', 'sitelanguages.sites_id');
     })->join('languages', 'languages.id', '=', 'sitelanguages.languages_id')->select('sitelanguages.id', \DB::raw(' CONCAT(sites.title, \'-\',languages.code) as site_language'))->get()->lists('site_language', 'id')->prepend('Please select', '');
     $category = Category::site_access()->join('sitelanguages', 'sitelanguages.id', '=', 'category.sitelanguages_id')->join('languages', 'languages.id', '=', 'sitelanguages.languages_id')->join('sites', 'sites.id', '=', 'sitelanguages.sites_id')->select('category.id', 'category.title')->get()->lists('title', 'id')->prepend('Please select', '');
     return view('admin.news.edit', compact('news', "sitelanguages", "category"));
 }
 public function delete($id)
 {
     $entry = News::find($id);
     if (isset($entry)) {
         News::where('id', $id)->update(array('trash' => 1));
         return \Redirect::route('news')->with('success', $entry->title . ' deleted succesfully!');
     } else {
         return \Redirect::route('news')->with('error', 'Failed to delete, invalid credentials.');
     }
 }
Пример #8
0
 public function update(Requests\NewsFormRequest $request, $id)
 {
     $news = News::find($id);
     $news->headline = $request->input('headline');
     $news->message = $request->input('message');
     $news->image = $request->file('image')->getClientOriginalName();
     $news->save();
     $request->file('image')->move(storage_path('app'), $news->image);
     $message = 'Successfully create news';
     return view('news.create', compact('message'));
 }
Пример #9
0
 /**
  * Display the specified news article.
  *
  * @param  int  $id - id of a news artical
  * @return Response
  */
 public function show($id)
 {
     // find by $id
     $news_item = News::find($id);
     // if no news item found
     if (!$news_item) {
         // set response as an error
         return Response()->json(['message' => 'The news article could not be found', 'code' => 404], 404);
     }
     // set response as json with data
     return Response()->json(['data' => $news_item, 'code' => 200], 200);
 }
Пример #10
0
 public function edit($id, $extra = array())
 {
     $news = \App\News::find($id);
     $extra['types'] = array('news' => 'Frétt');
     $extra['images'] = ['' => ' - Veldu mynd - '];
     if ($news->img()->exists()) {
         foreach ($news->img()->all() as $k => $img) {
             $extra['images'][$img['name']] = $img['name'];
         }
     }
     return parent::edit($id, $extra);
 }
Пример #11
0
 /**
  * Отображает одну новость.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function getShow($id)
 {
     // Получаем новость из БД
     $data['news'] = News::find($id);
     if (!empty($data['news'])) {
         // Последние 3 новости
         $data['latest_news'] = News::where('id', '<>', $id)->orderBy('created_at', 'DESC')->take(3)->get();
         // Отображаем представление
         return view('marketing.news.show', $data);
     } else {
         abort(404);
     }
 }
Пример #12
0
 public function update($id)
 {
     $aNewsData = Input::get('news');
     $validator = Validator::make($aNewsData, ['title' => 'sometimes|required|max:255', 'content' => 'sometimes|required', 'state' => 'sometimes|in:created,visible,deleted']);
     if ($validator->fails()) {
         $aRet = ['success' => 'false', 'errors' => $validator->errors()];
     } elseif ($oNews = News::find($id) and $oNews->fill($aNewsData)->update()) {
         $aRet = ['success' => 'true'];
     } else {
         $aRet = ['success' => 'false'];
     }
     return response()->json($aRet);
 }
Пример #13
0
 public function destroyNews(Request $request)
 {
     $news = News::find($request->news_id);
     if ($news != NULL) {
         try {
             $news->delete();
             $message = array("reponse" => "success", "message" => "La news a bien été supprimée");
         } catch (\Exception $e) {
             $message = array("reponse" => "error", "message" => "Une erreur innatendue s'est produite");
         }
     } else {
         $message = array("reponse" => "error", "message" => "Une erreur innatendue s'est produite");
     }
     echo json_encode($message);
     return Redirect::route('AdminDisplayNews');
 }
Пример #14
0
 /**
  * Update the specified resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function update(Request $request, $id)
 {
     $this->validate($request, ['news_title' => 'required', 'news_text' => 'required']);
     $news = News::find($id);
     $news->is_published = $request->get('is_published') == 'on' ? 1 : 0;
     $news->title = $request->get('news_title');
     $news->text = $request->get('news_text');
     $news->save();
     $news->categories()->detach();
     if ($request->get('news_categories') != null) {
         foreach ($request->get('news_categories') as $category_id) {
             $news->categories()->attach($category_id);
         }
     }
     Session::flash('flash_message', 'Event successfully added!');
     return view('dashboard/create_news')->with('success', 1)->with('categories', Category::get())->with('news', $news);
 }
Пример #15
0
 /**
  * Display a listing of the resource.
  *
  * @return \Illuminate\Http\Response
  */
 public function bulid_slugs()
 {
     $news = News::select(['id', 'title', 'keywords', 'content', 'language'])->get();
     foreach ($news as $news_item) {
         $news_record = News::find($news_item->id);
         if ('fa' == $news_item->language) {
             $news_record->title = persian_normalizer($news_item->title);
             $news_record->keywords = persian_normalizer($news_item->keywords);
             $news_record->content = persian_normalizer($news_item->content);
             $news_record->slug = persian_slug($news_item->title);
         } elseif ('tr' == $news_item->language) {
             $news_record->slug = turkish_slug($news_item->title);
         } else {
             $news_record->slug = str_slug($news_item->title);
         }
         $news_record->save();
     }
     return 'Done bulid slugs';
 }
Пример #16
0
 public function spotlight(Request $request)
 {
     $month = array('', 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec');
     $day = array('', '1st', '2nd', '3rd', '4th', '5th', '6th', '7th', '8th', '9th', '10th', '11th', '12th', '13th', '14th', '15th', '16th', '17th', '18th', '19th', '20th', '21st', '22nd', '23rd', '24th', '25th', '26th', '27th', '28th', '29th', '30th', '31st');
     $filepath = public_path('../HomepageConfig.json');
     $file = fopen($filepath, "r");
     $config = json_decode(fread($file, filesize($filepath)));
     fclose($file);
     $newconfig = clone $config;
     $newconfig->spotlights = array();
     for ($i = 0; $i < count($request->input('newsid')); $i++) {
         $news = News::find($request->input('newsid')[$i]);
         if ($news != null) {
             $time = $news->created_at;
             $newconfig->spotlights[$i] = array('newsid' => $request->input('newsid')[$i], 'month' => $month[$time->month], 'day' => $day[$time->day], 'title' => $news->title);
         }
     }
     $file = fopen($filepath, "w");
     fwrite($file, json_encode($newconfig));
     fclose($file);
     return Redirect::to('admin/homepage');
 }
Пример #17
0
 public function delete($id)
 {
     $news = News::find($id);
     return view('admin.news.delete')->withNews($news);
 }
Пример #18
0
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $slug
  * @return Response
  */
 public function destroy(Request $request)
 {
     $model = News::find($request->id);
     if (empty($model)) {
         Flash::error('Impossible de supprimer cette news.');
         return Redirect::back();
     }
     $title = $model->title;
     $model->delete();
     makeModification('news', 'The news &laquo; ' . $title . ' &raquo; has been removed.');
     Flash::success('La news a bien été supprimé.');
     return redirect('news');
 }
Пример #19
0
 public function update(Request $request, $newsID)
 {
     if (!Auth::check() || !Auth::user()->is_admin) {
         return response(view('errors.403', ['error' => $this->errorMessages['incorrect_permissions']]), 403);
     }
     $data = $request->only(['mce_0', 'mce_1', 'tags', 'featured_image']);
     // Validate all input
     $validator = Validator::make($data, ['mce_0' => 'required', 'mce_1' => 'required', 'featured_image' => 'image|sometimes']);
     if ($validator->fails()) {
         // If validation fails, redirect back to
         // registration form with errors
         return Redirect::back()->withErrors($validator)->withInput();
     }
     if ($request->hasFile('featured_image')) {
         $data['featured_image'] = MediaController::uploadImage($request->file('featured_image'), time(), $directory = "news_images", $bestFit = true, $fitDimensions = [1920, 1080]);
     } else {
         unset($data['featured_image']);
     }
     $data['title'] = $data['mce_0'];
     $data['content'] = $data['mce_1'];
     $news = News::find($newsID);
     $news->update($data);
     return Redirect::route('news.edit', [$news->id]);
 }
Пример #20
0
 public function post($id)
 {
     $nav = new category();
     $menu_top = $nav->menu_top($nav->all()->toArray());
     $news = News::getList();
     $post = News::find($id);
     $auth = User::all();
     $count = newsComment::getCount($id);
     $review = newsComment::getreview($id);
     return view('frontend.pages.post', array('post' => $post, 'auth' => $auth, 'news' => $news, 'menu_top' => $menu_top, 'count' => $count, 'review' => $review));
 }
Пример #21
0
 /**
  * Update the specified resource in storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function update($id)
 {
     $input = Input::all();
     $news = News::find($id);
     $validation = Validator::make($input, News::$news_update_rules);
     if ($validation->passes()) {
         if (Input::get('types') == 'news') {
             if (Input::file('coverImage') != null) {
                 $image = Input::file('coverImage');
                 $extension = $image->getClientOriginalExtension();
                 $filename = sha1(time() . time()) . ".{$extension}";
                 $upload_success = \Image::make($image)->resize(\Config::get('image.news_image_width'), \Config::get('image.news_image_height'))->save(\Config::get('image.news_image') . $filename);
                 if ($upload_success) {
                     $news->types = Input::get('types');
                     $news->author = Input::get('author');
                     $news->content = Input::get('content');
                     $news->title = Input::get('title');
                     $news->coverImage = $filename;
                     $news->save();
                     return Redirect::to('admin/newsList');
                 }
             } else {
                 $news->types = Input::get('types');
                 $news->author = Input::get('author');
                 $news->content = Input::get('content');
                 $news->title = Input::get('title');
                 $news->save();
                 return Redirect::to('admin/newsList');
             }
         } elseif (Input::get('types') == 'development') {
             if (Input::file('coverImage') != null) {
                 $image = Input::file('coverImage');
                 $extension = $image->getClientOriginalExtension();
                 $filename = sha1(time() . time()) . ".{$extension}";
                 $upload_success = \Image::make($image)->save(\Config::get('image.news_image') . $filename);
                 if ($upload_success) {
                     $news->types = Input::get('types');
                     $news->author = Input::get('author');
                     $news->content = Input::get('content');
                     $news->title = Input::get('title');
                     $news->coverImage = $filename;
                     $news->save();
                     return Redirect::to('admin/newsList');
                 }
             } else {
                 $news->types = Input::get('types');
                 $news->author = Input::get('author');
                 $news->content = Input::get('content');
                 $news->title = Input::get('title');
                 $news->save();
                 return Redirect::to('admin/newsList');
             }
         }
     } else {
         $error = $validation->errors()->first();
         return Redirect::back()->withInput(Input::all())->with(compact('error'));
     }
 }
Пример #22
0
 public function unpublish($id)
 {
     $news = News::find($id);
     $news->active = 0;
     $news->save();
     return 'true';
 }
Пример #23
0
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function destroy($id)
 {
     News::find($id)->delete();
     return redirect('/admin/news');
 }
Пример #24
0
 public function show_news($id)
 {
     $this->data['news'] = News::find($id);
     return view('news_full', $this->data);
 }
Пример #25
0
 public function item($id)
 {
     // Get all articles
     $news = News::find($id);
     return view('site.news.view_news', compact('news'));
 }
Пример #26
0
 public function postEditNews(Request $request, $id)
 {
     $article = News::find($id);
     $article->title = $request->title;
     $article->slug = $request->slug;
     $article->anonce = $request->anonce;
     $article->container = $request->editor;
     $article->category = $request->category;
     $article->date_publish = Carbon::parse($request->date_publish)->format('Y-m-d H:i');
     if ($request->has_preview == 0) {
         $article->preview = null;
     }
     if ($request->hasFile('preview')) {
         $file = $request->file('preview');
         $filename = str_random(10);
         $extension = $file->getClientOriginalExtension();
         $surl = $this->globalSiteSettings['site_url'];
         $imgurl = $surl . '/uploads/' . $filename . '.' . $extension;
         Image::make($request->file('preview'))->fit(500, 200)->save(public_path() . '/uploads/' . $filename . '.' . $extension);
         $article->preview = $imgurl;
     }
     if ($article->save()) {
         return redirect('/dashboard/news');
     }
 }
Пример #27
0
 /**
  * Remove the specified resource from storage.
  *
  * @param $id
  * @return Response
  */
 public function postDelete(DeleteRequest $request, $id)
 {
     $news = News::find($id);
     $news->delete();
 }
Пример #28
0
 /**
  * Удаляет новость
  *
  * @param  int  $id
  * @return Response
  */
 public function getDelete($id)
 {
     $news = News::find($id);
     if (empty($news)) {
         abort(404);
     }
     // Удаляем изображение
     File::delete(public_path('assets' . DIRECTORY_SEPARATOR . 'img' . DIRECTORY_SEPARATOR . 'news' . DIRECTORY_SEPARATOR . $news->thumbnail));
     $news->delete();
     return redirect()->action('Admin\\NewsController@getIndex')->with('success', 'Новость успешно удалена.');
 }
Пример #29
0
 public function detail_news($id)
 {
     $news = News::find($id);
     //        die();
     return view('detail_news', ['news' => $news]);
 }
Пример #30
0
 /**
  * Remove the specified resource from storage.
  *
  * @param  int $id
  * @return Response
  */
 public function destroy($id)
 {
     $news = News::find($id);
     $news->delete();
     // redirect
     Session::flash('success-delete', 'Material delete!');
     return Redirect::to('administrator/edit');
 }