public function parse_tokens($body) { # NEWSLETTER TOKEN. str_replace('{{newsletter}}', '', $body, $count); if (0 < $count) { $pages_config = yaml::parse($this->site_name, 'pages_config'); if (empty($pages_config['newsletter'])) { return $body; } $parent_id = explode('-', $pages_config['newsletter']); $parent_id = $parent_id['1']; # get the newsletter HTML. $newsletter = new Newsletter_Controller(); $body = str_replace('{{newsletter}}', $newsletter->_index($parent_id), $body); } # ------------------------------------------------------ # SHOWROOM TOKEN. format: {showroom_cats:parent_id:parameters} $pattern = '/{showroom_cats:(\\d+)\\:(\\w+)\\}/'; if (0 < preg_match($pattern, $body, $match)) { # get the page name. $page_name = yaml::does_value_exist($this->site_name, 'pages_config', "showroom-{$match[1]}"); if (!$page_name) { return $body; } # get the showroom category html. $showroom = ORM::factory('showroom', $match[1]); if (!$showroom->loaded) { return $body; } # how should the list be displayed? if (!empty($match[2]) and 'flat' == $match[2]) { # showing only root categories. $root_cats = ORM::factory('showroom_cat')->where(array('fk_site' => $this->site_id, 'showroom_id' => $showroom->id, 'local_parent' => $showroom->root_id))->orderby(array('lft' => 'asc'))->find_all(); $categories = Tree::display_flat_tree('showroom', $root_cats, $page_name); } else { $categories = Tree::display_tree('showroom', $showroom->showroom_cats, $page_name); } $body = preg_replace($pattern, $categories, $body, 1); } /* -------------------------------------------- */ # google map! format: {google_map:parent_id:parameters} $pattern = '/{google_map:(\\d+)\\:(\\w+)\\}/'; if (0 < preg_match($pattern, $body, $match)) { } return $body; }
/** * Loads URI, and Input into this controller. * * @return void */ public function __construct() { $session = Session::instance(); $site_config = yaml::parse($_SESSION['site_name'], 'site_config'); foreach ($site_config as $key => $value) { $this->{$key} = $value; } // --- Setup our required library instances --- // -------------------------------------------- # Auth Instance for editing site capability $this->client = new Auth($this->claimed); # Account Instance for user account tool. $this->account_user = new Account(); # assets instance to fetch datapath urls. $this->assets = Assets::instance($this->site_name, $this->theme); # URI should always be available $this->uri = URI::instance(); # Input should always be available $this->input = Input::instance(); if (Kohana::$instance == NULL) { # Set the instance to the first controller loaded Kohana::$instance = $this; } }
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); }