예제 #1
0
 function nav_save()
 {
     G2_User::init();
     if (G()->logged_in() && !empty($_POST)) {
         if (!empty($_POST['items']) && !empty($_POST['identity'])) {
             // Delete all current navigation details
             $navitems = R::findAll('navitem', 'identity=:id', ['id' => $_POST['identity']]);
             R::trashAll($navitems);
             foreach ($_POST['items'] as $new_item) {
                 $nav = R::dispense('navitem');
                 $nav->identity = $_POST['identity'];
                 $nav->label = $new_item['label'];
                 $nav->href = !$new_item['href'] ? null : $new_item['href'];
                 $nav->order = $new_item['order'];
                 //@todo parent node support
                 R::store($nav);
             }
             echo json_encode(['success' => true, 'message' => 'Content Saved Successfully']);
         } else {
             echo json_encode(['success' => false, 'message' => 'Data sent not correct']);
         }
     } else {
         echo json_encode(['success' => false, 'message' => 'Not Logged in']);
     }
     die;
 }
예제 #2
0
 public function __before()
 {
     G2_User::init();
     if (!G()->logged_in()) {
         $this->redirect(BASE_URL);
     }
 }
예제 #3
0
 public function create($filename, \App_Config_Ini $config, $template, $mtime)
 {
     //Add the meta config to this config
     $meta_config = $this->get_meta_config();
     //First load the page that matches the slug
     $existing = current(R::findOrDispense('page', 'slug = :slug', ['slug' => $config->page->slug]));
     if ($existing->getID() && $existing->gen_filename != $filename) {
         throw new Exception("A page already exists inside the database with the same slug but built with the onscreen page creator");
         return false;
     }
     $page = current(R::findOrDispense('page', 'gen_filename = :file', ['file' => $filename]));
     /* @var $page \RedBeanPHP\OODBBean */
     /**
      * Creates the page database object
      */
     if (!$page->getID()) {
         // The Page does not exist
         $page->gen_filename = $filename;
         $page->title = $config->page->title;
         $page->description = $config->page->description;
     } else {
         $old_slug = $page->slug;
         $meta = new Meta_Generator($meta_config);
         $page->title = !empty($config->page->title) ? $config->page->title : $meta->get_title($page->slug);
         $page->description = !empty($config->page->description) ? $config->page->description : $meta->get_description($page->slug);
     }
     $page->slug = $config->page->slug;
     $page->layout = $this->theme->load_layout($config->page->layout ? $config->page->layout : 'layouts.default.twig', $this->theme->theme)->file;
     /*
      * Create the template file in the theme
      */
     $page->template = $this->theme->generate_template($filename, $template, $mtime);
     R::store($page);
     // Create a route for this page for loading
     $r_func = function ($slug) use($page) {
         //Load the front end instance loader
         $theme = Theme_Loader::get_instance();
         $theme->set_theme(THEME);
         G2_User::init();
         if (G()->logged_in()) {
             $theme->logged_in();
         }
         $_SESSION['theme'] = $theme;
         //Render the theme
         if ($theme->page_exists($page->slug)) {
             $theme->render($page->slug);
         }
     };
     $route = new Router();
     if (isset($old_slug)) {
         $route->delete_route($old_slug);
     }
     $route->create_route($page->slug, $r_func);
 }
예제 #4
0
 public function _404()
 {
     //Load the front end instance loader
     $theme = Theme_Loader::get_instance();
     $theme->set_theme(THEME);
     G2_User::init();
     if (G()->logged_in()) {
         $theme->logged_in();
     }
     $_SESSION['theme'] = $theme;
     if ($theme->page_exists('404')) {
         http_response_code(404);
         $theme->render('404');
     } else {
         parent::_404();
     }
 }
예제 #5
0
 function __construct()
 {
     G2_User::init();
     parent::__construct();
     $this->template = new G2_TwigTemplate('templates/default.twig');
     $this->template->user = G()->get_user();
     $this->template->admin_url = $this->get_package_uri(true);
     $packages = MVC_Router::getInstance()->get_packages_loaded();
     foreach ($packages as $key => $package) {
         if (!method_exists($package, 'get_admin_controller')) {
             unset($packages[$key]);
             continue;
         }
         if (method_exists($package, 'get_permission') && !Permission::has_permission($package->get_permission())) {
             unset($packages[$key]);
             continue;
         }
         $packages[$key]->link = $this->get_package_uri(true) . 'package/' . $packages[$key]->name;
     }
     $this->template->packages = $packages;
     $this->template->alert = Admin_Alert::get_instance();
 }