Example #1
0
 public function loadPage($slug)
 {
     $inputs = array('slug' => $slug);
     $rules = array('slug' => 'required|alpha_dash');
     $validation = Validator::make($inputs, $rules);
     if ($validation->passes()) {
         $page = Page::where('slug', $slug)->where('private', false)->first();
         if ($page) {
             return view('redminstore::pages.view')->with('page', $page);
         }
     }
     return view('redminstore::general.404');
 }
Example #2
0
 /**
     /* Get all pages.
     /*
     /* @param bool $private To retrieve private or public pages, default public.
     /* @return array(Page) or null if nothing found
 */
 public static function getPages($private = false)
 {
     $pages = Page::where('private', $private)->get();
     return $pages;
 }
Example #3
0
 public function postStore()
 {
     $sid = \Input::get('id');
     $rules = array('image' => 'mimes:jpg,jpeg,png,gif|max:500', 'title' => 'required|regex:/^[a-z,0-9 ._\\(\\)-?]+$/i', 'slug' => 'required|regex:/^[a-z,0-9 ._\\(\\)-?]+$/i', 'content' => 'required');
     $validation = \Validator::make(\Input::all(), $rules);
     if ($validation->fails()) {
         return redirect('admin/pages/' . (isset($sid) ? 'edit/' . $sid : 'create'))->withErrors($validation)->withInput();
     }
     $title = \Input::get('title');
     $slug = \Input::get('slug');
     $content = \Input::get('content');
     $image = \Input::file('image');
     $private = \Input::get('private') == '' ? false : true;
     $category_id = \Input::get('category_id');
     $tags = \Input::get('tags');
     $page = isset($sid) ? Page::find($sid) : new Page();
     if ($page == null) {
         $errors = new \Illuminate\Support\MessageBag();
         $errors->add('editError', "The page cannot be found because it does not exist or may have been deleted.");
         return redirect('/admin/pages')->withErrors($errors);
     }
     $page->title = $title;
     $page->slug = str_replace(' ', '_', $slug);
     // Replace all space with underscore
     $page->content = $content;
     $page->private = $private;
     if ($category_id) {
         $page->category_id = $category_id;
     } else {
         $page->category_id = null;
     }
     $page->save();
     // Save translations
     $translations = \Config::get('redminportal::translation');
     foreach ($translations as $translation) {
         $lang = $translation['lang'];
         if ($lang == 'en') {
             continue;
         }
         $translated_content = array('title' => \Input::get($lang . '_title'), 'slug' => str_replace(' ', '_', \Input::get($lang . '_slug')), 'content' => \Input::get($lang . '_content'));
         // Check if lang exist
         $translated_model = $page->translations->where('lang', $lang)->first();
         if ($translated_model == null) {
             $translated_model = new Translation();
         }
         $translated_model->lang = $lang;
         $translated_model->content = json_encode($translated_content);
         $page->translations()->save($translated_model);
     }
     if (\Input::hasFile('image')) {
         //Upload the file
         $helper_image = new RImage();
         $filename = $helper_image->upload($image, 'pages/' . $page->id, true);
         if ($filename) {
             // create photo
             $newimage = new Image();
             $newimage->path = $filename;
             // save photo to the loaded model
             $page->images()->save($newimage);
         }
     }
     if (!empty($tags)) {
         // Delete old tags
         $page->tags()->detach();
         // Save tags
         foreach (explode(',', $tags) as $tagName) {
             Tag::addTag($page, $tagName);
         }
     }
     return redirect('admin/pages');
 }
 public function getDelete($sid)
 {
     // Find the page using the user id
     $page = Page::find($sid);
     if ($page == null) {
         $errors = new \Illuminate\Support\MessageBag();
         $errors->add('deleteError', "The data cannot be deleted at this time.");
         return redirect('/admin/pages')->withErrors($errors);
     }
     // Delete the page
     $page->delete();
     return redirect('admin/pages');
 }