Esempio n. 1
0
 public static function _create_website($site_name, $theme = 'base', $user_id = NULL, $email = NULL)
 {
     # Make sure the site_name is unique.
     $site_name = valid::filter_php_url($site_name);
     $site = ORM::factory('site');
     if ($site->subdomain_exists($site_name)) {
         return 'Site name already exists.';
     }
     # create data folder structure for site
     $source = DOCROOT . '_assets/data/_stock';
     $dest = DATAPATH . $site_name;
     if (!is_dir($source)) {
         return '_stock folder does not exist.';
     }
     if (!Jdirectory::copy($source, $dest)) {
         return 'Unable to make data folder';
     }
     # add the theme.
     Theme_Controller::_new_website_theme($site_name, $theme);
     # create site table row.
     $new_site = ORM::factory('site');
     $new_site->subdomain = $site_name;
     $new_site->theme = $theme;
     $new_site->save();
     # Establish user access and claim status.
     if (empty($user_id)) {
         # by given email address
         $claimed = $email;
         # by cookie if no_register
         # cookie::set("unclaimed_$new_site->id", sha1("r-A-n_$new_site->id-D-o:m"));
         # $claimed = null;
     } else {
         # or by user_id if user is registered.
         $new_site->add(ORM::factory('account_user', $user_id));
         $new_site->claimed = 'yes';
         $claimed = 'true';
     }
     # save the site.
     $new_site->save();
     # create site_config file.
     $replacements = array($new_site->id, $site_name, $new_site->theme, '', 'home', $claimed);
     yaml::new_site_config($site_name, $replacements);
     # create static pages.
     $new_page = ORM::factory('page');
     $new_page->fk_site = $new_site->id;
     $new_page->page_name = 'home';
     $new_page->label = 'Home';
     $new_page->position = 0;
     $new_page->menu = 'yes';
     $new_page->save();
     ## This is normally where we would add sample tools with sample data
     ## and attach them to various pages.
     ## -------------------------------------------
     /*
     # add sample tools to homepage.
     $sample_tools = array(
       'Format',
       'Navigation',
       'Album',
       'Text'
     );
     #TODO establish types of tools, with views, etc.
     foreach($sample_tools as $name)
       Tool_Controller::_create_tool($new_page->id, $name, $site_name, FALSE, TRUE);
     */
     /*
         # create new pages with page_builders pre installed.
         # this should use the logic in the pages controller
         # since we are creating pages w/ tools and not the other way around.
         $install = array(
           'Account',
           #'Blog',
           #'Forum',
           #'Calendar'
         );
         foreach($install as $toolname)
           Tool_Controller::_auto_builder($toolname, $new_site->id, $site_name, 'base');
     */
     if (empty($user_id)) {
         url::redirect("http://{$site_name}." . ROOTDOMAIN . "/get/admin?email={$email}");
     }
     return 'Website Created!';
 }
Esempio n. 2
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));
}