Ejemplo n.º 1
0
 private function _add_to_page($tool, $page)
 {
     # make sure the tool is an object
     if (!is_object($tool)) {
         $tool = ORM::factory('tool')->where('fk_site', $this->site_id)->find($tool);
         if (!$tool->loaded) {
             return 'invalid tool';
         }
     }
     # make sure the page is an object
     if (!is_object($page)) {
         $page = ORM::factory('page')->where('fk_site', $this->site_id)->find($page);
         if (!$page->loaded) {
             return 'invalid page';
         }
     }
     # is the tool we are trying to add protected?
     if ('yes' == $tool->system_tool->protected) {
         # is this page a root page?
         str_replace('/', '', $page->page_name, $matches);
         if (0 < $matches) {
             return 'protected tools must be on root pages';
         }
         # is this page already protected?
         if ($page_config_value = yaml::does_key_exist($this->site_name, 'pages_config', $page->page_name)) {
             return 'this page already contains a protected tool';
         }
     }
     # get min position of tools on page
     $db = Database::instance();
     $lowest = $db->query("\n      SELECT MIN(position) as lowest\n      FROM pages_tools \n      WHERE page_id ='{$page->id}'\n      AND fk_site = '{$this->site_id}'\n    ")->current()->lowest;
     # add a new record to pages_tools
     # effectively "adding this tool to this page"
     $data = array('tool_id' => $tool->id, 'page_id' => $page->id, 'fk_site' => $this->site_id, 'position' => $lowest - 1);
     $instance_id = $db->insert('pages_tools', $data)->insert_id();
     # only on successs...
     if ('yes' == $tool->system_tool->protected) {
         $toolname = strtolower($tool->system_tool->name);
         # protect the page relative to this new tool.
         $newline = "\n{$page->page_name}:{$toolname}-{$tool->parent_id}";
         yaml::add_value($this->site_name, 'pages_config', $newline);
     }
     return "{$instance_id}";
 }
Ejemplo n.º 2
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);
 }
Ejemplo n.º 3
0
 private function save_page_cache()
 {
     # never save an admin view of a page.
     if ($this->client->can_edit($this->site_id)) {
         return FALSE;
     }
     if (!$this->save_page_as) {
         return FALSE;
     }
     if (file_exists("{$this->page_cache_dir}/{$this->save_page_as}.html") and !$this->save_page_force) {
         return FALSE;
     }
     # cannot save a protected (dynamic) page.
     if ($this->page_name) {
         if (yaml::does_key_exist($this->site_name, 'pages_config', $this->page_name)) {
             return FALSE;
         }
     }
     if (!is_dir("{$this->page_cache_dir}")) {
         mkdir("{$this->page_cache_dir}");
     }
     $date = date('m.d.y g:ia e');
     file_put_contents("{$this->page_cache_dir}/{$this->save_page_as}.html", $this->template->render() . "\n<!-- cached {$date} -->");
     return TRUE;
 }
Ejemplo n.º 4
0
function get_site()
{
    $session = Session::instance();
    $domain_array = explode('.', $_SERVER['HTTP_HOST']);
    # if the url = [subdomain].plusjade.org
    if (in_array(ROOTNAME, $domain_array)) {
        $field_name = 'subdomain';
        $site_name = $domain_array['0'];
        # if no subdomain, set the site_name to the admin account
        if ('2' == count($domain_array)) {
            $site_name = ROOTACCOUNT;
        }
    } else {
        $field_name = 'custom_domain';
        $site_name = $_SERVER['HTTP_HOST'];
    }
    $site = ORM::factory('site')->where(array($field_name => $site_name))->find();
    if (!$site->loaded) {
        header("HTTP/1.0 404 Not Found");
        die('site does not exist');
    }
    # IMPORTANT: sets the site name & non-sensitive site_data.
    $_SESSION['site_name'] = $site->subdomain;
    # Make sure site_config file exists
    # the site_config file is parsed in the root Controller_Core library file.
    $site_config_path = DATAPATH . "{$site->subdomain}/protected/site_config.yml";
    if (!file_exists($site_config_path)) {
        $replacements = array($site->id, $site->subdomain, $site->theme, $site->banner, $site->homepage);
        yaml::new_site_config($site_name, $replacements);
    }
    /*
    --- Route the URL ---
    ---------------------
    * The URL will tell us how to build the page.
        a. is /get/
        b. is file request     
        c. is ajax request
        d. is page_name
           is protected page?
    */
    # Get page_name
    $url_array = URI::url_array();
    $page_name = empty($url_array['0']) ? $site->homepage : $url_array['0'];
    # app/config/routes.php routes the url correctly.
    if ('get' == $page_name) {
        return FALSE;
    }
    if ('files' == $page_name) {
        $file = new Files_Controller();
        die($file->_output($url_array));
    }
    # Is page_name protected?
    $page_config_value = yaml::does_key_exist($site->subdomain, 'pages_config', $page_name);
    # Is protected ajax request?
    # get info from pages_config.yaml
    if ($page_config_value and request::is_ajax()) {
        # extract toolname and parent_id from pages_config.yaml
        $page_data = explode('-', $page_config_value);
        list($toolname, $parent_id) = $page_data;
        # make sure the page_name is correct.
        $url_array['0'] = $page_name;
        # send to tool _ajax handler. we expect raw data output.
        die(Load_Tool::factory($toolname)->_ajax($url_array, $parent_id));
    } elseif (isset($_POST['post_handler']) and request::is_ajax()) {
        # currently only enabled for format  form type.
        list($toolname, $parent_id) = explode(':', $_POST['post_handler']);
        die(Load_Tool::factory($toolname)->_ajax($url_array, $parent_id));
    }
    # Non-protected page_names can be a subdirectory name.
    # do this only if an actual url string is being sent.
    # so we need to get the full url string.
    if (!empty($url_array['1']) and !$page_config_value) {
        $page_name = strstr($_SERVER['REQUEST_URI'], '/');
        $page_name = ltrim($page_name, '/');
    }
    $page = ORM::factory('page')->where(array('fk_site' => $site->id, 'page_name' => $page_name))->find();
    if (!$page->loaded) {
        Event::run('system.404');
    }
    # Load the page!
    $build_page = new Build_Page_Controller();
    die($build_page->_index($page));
}