Esempio n. 1
0
 public function settings($page_id = NULL)
 {
     valid::id_key($page_id);
     $page = ORM::factory('page')->where('fk_site', $this->site_id)->find($page_id);
     if (!$page->loaded) {
         die('invalid page id');
     }
     if ($_POST) {
         # Validate page_name & duplicate check
         $directory = empty($_POST['directory']) ? NULL : $_POST['directory'];
         $new_page_name = $filename = self::validate_page_name($_POST['label'], $_POST['page_name'], $directory, $_POST['page_name']);
         if (!empty($directory)) {
             $new_page_name = "{$directory}/{$filename}";
         }
         # if this page was the homepage, update homepage value
         if ($this->homepage == $_POST['old_page_name']) {
             $site = ORM::factory('site', $this->site_id);
             $site->homepage = $filename;
             $site->save();
             yaml::edit_site_value($this->site_name, 'site_config', 'homepage', $filename);
             $_POST['enable'] = 'yes';
             # force homepage to be enabled.
         }
         $page->page_name = $new_page_name;
         $page->title = $_POST['title'];
         $page->meta = $_POST['meta'];
         $page->label = $_POST['label'];
         $page->template = $_POST['template'];
         $page->menu = $_POST['menu'];
         $page->enable = isset($_POST['enable']) ? $_POST['enable'] : 'yes';
         $page->save();
         # did the page name change?
         # update all children within this "folder"
         if ($_POST['old_page_name'] != $filename) {
             # if this page is protected update the pages_config file.
             yaml::edit_key($this->site_name, 'pages_config', $_POST['old_page_name'], $filename);
             $old_full_page = empty($_POST['directory']) ? $_POST['old_page_name'] : $_POST['directory'] . '/' . $_POST['old_page_name'];
             $dir_pages = self::get_folder_filenames($old_full_page, 'change');
             # if this page has children, update them!
             foreach ($dir_pages as $page_id => $page_name) {
                 $page = ORM::factory('page')->where('fk_site', $this->site_id)->find($page_id);
                 if (!$page->loaded) {
                     continue;
                 }
                 $page->page_name = "{$new_page_name}/{$page_name}";
                 $page->save();
             }
         }
         # if the page was the account page, update site_config
         if ($this->account_page == $_POST['old_page_name']) {
             yaml::edit_site_value($this->site_name, 'site_config', 'account_page', $filename);
         }
         # should we publish this page?
         if (isset($_POST['publish']) and 'yes' == $_POST['publish']) {
             $cache = DATAPATH . "{$this->site_name}/cache/{$page_id}.html";
             if (file_exists($cache)) {
                 unlink($cache);
             }
         }
         die('Page Settings Saved');
         # success
     }
     # Is this a subpage? (pop the end filename node from the directory.)
     $filename = $page->page_name;
     $directory = '';
     $directory_array = explode('/', $filename);
     if (1 < count($directory_array)) {
         $filename = array_pop($directory_array);
         $directory = implode('/', $directory_array);
     }
     $primary = new View("page/page_settings");
     $primary->page = $page;
     $primary->filename = $filename;
     $primary->dir = $directory;
     # get available templates from theme.
     if ($templates = yaml::parse($this->site_name, NULL, "themes/{$this->theme}/config")) {
         $primary->templates = $templates;
     } else {
         $primary->templates = array('master' => 'default layout');
     }
     # Javascript duplicate page_name filter Validation
     # convert filter_array to string to use as javascript array
     $filter_array = self::get_folder_filenames($directory, NULL, $filename);
     $filter_string = implode("','", $filter_array);
     $primary->page_filter_js = "'{$filter_string}'";
     # is page protected?
     $primary->is_protected = yaml::does_key_exist($this->site_name, 'pages_config', $page->page_name) ? TRUE : FALSE;
     die($primary);
 }