示例#1
0
文件: pages.php 项目: juaniiie/mwi
 public function post_create()
 {
     $validation = Pages\Model\Page::validate(Input::all());
     if ($validation->passes()) {
         $is_home_post = Input::get('is_home');
         // If post comming from duplicate
         // we have parend_id and parent_slug
         $slug = Input::get('slug');
         $parent_slug = Input::get('parent_slug');
         if (isset($parent_slug) and !empty($parent_slug)) {
             $slug = $parent_slug . '/' . $slug;
         }
         $parent_id = Input::get('parent_id');
         $parent_id = $parent_id != 0 ? $parent_id : 0;
         $restricted_to = Input::get('restricted_to');
         if ($restricted_to == null) {
             $restricted_to = array('0' => '0');
         }
         $restricted_to = implode(',', $restricted_to);
         $page = new Pages\Model\Page();
         $page->parent_id = $parent_id;
         $page->title = Input::get('title');
         $page->slug = $slug;
         $page->status = Input::get('status');
         $page->meta_title = Input::get('meta_title');
         $page->meta_keywords = Input::get('meta_keywords');
         $page->meta_description = Input::get('meta_description');
         $page->body = Input::get('body');
         $page->restricted_to = $restricted_to;
         $page->is_home = (isset($is_home_post) and $is_home_post == 1) ? 1 : 0;
         $page->strict_uri = Input::get('strict_uri');
         $page->save();
         // the user want to create a navigation link?
         $navigation_id = Input::get('navigation_group_id');
         if (is_numeric($navigation_id) and $navigation_id != 0) {
             // If the user want to create a link
             // for this page, we need to set this
             // page as live or it will break navigation
             $page->status = 'live';
             $page->save();
             $link = new Navigation\Model\Link();
             // add a link for this page to the navigation
             $link->title = Str::title($page->title);
             $link->link_type = 'page';
             $link->page_id = $page->id;
             $link->group_id = $navigation_id;
             $link->save();
         }
         $this->data['message'] = Lang::line('pages::lang.Page was successfully created')->get(ADM_LANG);
         $this->data['message_type'] = 'success';
         return Redirect::to(ADM_URI . '/pages')->with($this->data);
     } else {
         return Redirect::to(ADM_URI . '/pages/new')->with_errors($validation)->with_input();
     }
 }
示例#2
0
文件: links.php 项目: juaniiie/mwi
 public function post_create()
 {
     $rules = array('title' => 'required|max:50', 'link_type' => 'required|link_type', 'restricted_to' => 'required');
     $validation = Navigation\Validator::make(Input::all(), $rules)->speaks(ADM_LANG);
     if ($validation->passes()) {
         $restricted_to_array = Input::get('restricted_to');
         // If there is many restrictions selected
         // and the ANY option is selected as well
         // just save the link with the any value 0
         // and remove all the others since any precced other values
         if (in_array(0, $restricted_to_array)) {
             $restricted_to = 0;
         } else {
             $restricted_to = !empty($restricted_to_array) ? implode(',', $restricted_to_array) : 0;
         }
         $link = new Navigation\Model\Link();
         $link->parent = 0;
         // set message for new link creation post
         Session::flash('message', Lang::line('navigation::lang.Link was successfully created')->get(ADM_LANG));
         $link->title = Input::get('title');
         $link->link_type = Input::get('link_type');
         $link->url = URL::valid(Input::get('url')) ? Input::get('url') : '';
         $link->module_id = 0;
         $link->uri = trim(Input::get('uri'), "/");
         $link->page_id = Input::get('page_id');
         $link->target = Input::get('target');
         $link->class = Input::get('class');
         $link->restricted_to = $restricted_to;
         $link->group_id = Input::get('group_id');
         $link->save();
         Event::fire('mwi.navigation_link_created', array($link));
         Session::flash('message_type', 'success');
         // return success so javascript can refresh the page
         echo 'success';
     } else {
         return View::make('navigation::backend.partials.links.message')->with('errors', $validation->errors);
     }
 }