Esempio n. 1
0
 public function delete()
 {
     if (!isset($_GET['dir'])) {
         $_GET['dir'] = '';
     }
     $dir = self::validate_dir($_GET['dir']);
     if (empty($_POST['json'])) {
         die('nothing sent');
     }
     $json = self::validate_json($_POST['json']);
     foreach ($json as $asset) {
         $ext = strrchr($asset->name, '.');
         $full_path = "{$dir}/{$asset->name}";
         if (is_dir($full_path)) {
             if ('_tmb' == $asset->name) {
                 die('Cannot delete this folder.');
             }
             Jdirectory::remove($full_path);
         } elseif (file_exists($full_path)) {
             if (unlink($full_path)) {
                 if (array_key_exists($ext, $this->image_types)) {
                     # get and recurse the _tmb directory.
                     $thumb_dirs = Jdirectory::contents("{$dir}/_tmb/", 'root', 'list_dir');
                     foreach ($thumb_dirs as $tmb_dir) {
                         if (file_exists("{$dir}/_tmb/{$tmb_dir}/{$asset->name}")) {
                             unlink("{$dir}/_tmb/{$tmb_dir}/{$asset->name}");
                         }
                     }
                 }
             }
         }
     }
     die('Assets deleted');
 }
Esempio n. 2
0
 public function delete()
 {
     $tool = $this->get_tool();
     # Protect account tool.
     if ('account' == $tool->system_tool->name) {
         die('Account tool cannot be deleted, since other tools depend on it!');
     }
     # delete all page instances of this tool first
     $db = Database::instance();
     $db->delete('pages_tools', array('tool_id' => $this->tool_id, 'fk_site' => $this->site_id));
     # delete the parent table row.
     $parent = ORM::factory($tool->system_tool->name)->where('fk_site', $this->site_id)->find($tool->parent_id)->delete_tool();
     # is tool protected?
     # note: the page may not be set if the page was deleted but the tool still exists.
     if ('yes' == $tool->system_tool->protected) {
         if (isset($tool->pages->current()->page_name)) {
             yaml::delete_value($this->site_name, 'pages_config', $tool->pages->current()->page_name);
         }
     }
     # DELETE the custom folder for this tool. (houses custom css files)
     $custom_folder = $this->assets->themes_dir("{$this->theme}/tools/" . strtolower($tool->system_tool->name) . "/{$tool->parent_id}");
     if (is_dir($custom_folder)) {
         Jdirectory::remove($custom_folder);
     }
     $tool->delete();
     die('Tool deleted from system');
 }
Esempio n. 3
0
 /**
  * set some sitewide settings
  */
 public function settings()
 {
     if (!$this->client->can_edit($this->site_id)) {
         die('Please login');
     }
     $site = ORM::factory('site', $this->site_id);
     if (!$site->loaded) {
         die('site not found');
     }
     if ($_POST) {
         $homepage = explode(':', $_POST['homepage']);
         $site->custom_domain = $_POST['custom_domain'];
         $site->homepage = $homepage[0];
         $site->save();
         # should we publish the entire site?
         if (isset($_POST['publish']) and 'yes' == $_POST['publish']) {
             $cache_dir = DATAPATH . "{$this->site_name}/cache";
             if (is_dir($cache_dir)) {
                 Jdirectory::remove($cache_dir);
             }
             mkdir($cache_dir);
         }
         # update site_config.yml if new homepage
         # and force page to be enabled.
         if ($this->homepage != $homepage[0]) {
             yaml::edit_site_value($this->site_name, 'site_config', 'homepage', $_POST['homepage']);
             $page = ORM::factory('page', $homepage[1]);
             $page->enable = 'yes';
             $page->save();
         }
         die('Sitewide settings saved.');
     }
     $pages = ORM::factory('page')->where('fk_site', $this->site_id)->orderby('page_name')->find_all();
     $primary = new View('admin/settings');
     $primary->pages = $pages;
     $primary->custom_domain = $site->custom_domain;
     $primary->js_rel_command = 'close-base';
     die($primary);
 }
Esempio n. 4
0
 private function update()
 {
     $sites = ORM::factory('site')->find_all();
     foreach ($sites as $site) {
         # $theme_dir = $this->assets->themes_dir();
         $theme_dir = DATAPATH . "{$site->subdomain}/themes";
         $themes = Jdirectory::contents($theme_dir, 'root', 'list_dir');
         foreach ($themes as $theme) {
             $tool_dir = "{$theme_dir}/{$theme}/tools";
             if (!is_dir($tool_dir)) {
                 continue;
             }
             $toolnames = Jdirectory::contents($tool_dir, 'root', 'list_dir');
             foreach ($toolnames as $toolname) {
                 $created = "{$theme_dir}/{$theme}/tools/{$toolname}/_created";
                 if (!is_dir($created)) {
                     continue;
                 }
                 $instances = Jdirectory::contents($created, 'root', 'list_dir');
                 foreach ($instances as $instance) {
                     $path = "{$theme_dir}/{$theme}/tools/{$toolname}/_created/{$instance}";
                     if (is_dir($path)) {
                         rename($path, "{$theme_dir}/{$theme}/tools/{$toolname}/{$instance}");
                     }
                 }
                 if (is_dir($created)) {
                     rmdir($created);
                 }
             }
         }
     }
     echo 'done';
     die;
     echo kohana::debug($themes);
     die;
 }
Esempio n. 5
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. 6
0
 private function safe_mode($page_name, $site_name)
 {
     if (ROOTACCOUNT != $this->site_name) {
         die('return 404 not found');
     }
     $site = ORM::factory('site', $site_name);
     if (!$site->has(ORM::factory('account_user', $this->account_user->get_user()->id))) {
         return $this->plusjade_dashboard($page_name, 'You cannot edit this site.');
     }
     $theme_path = DATAPATH . "{$site_name}/themes/safe_mode";
     # delete safe-mode if it exists (might be tainted)
     if (is_dir($theme_path)) {
         Jdirectory::remove($theme_path);
     }
     # create it from stock.
     if (!is_dir(DOCROOT . "_assets/themes/safe_mode")) {
         return $this->plusjade_dashboard($page_name, 'Safe_mode theme does not exist. Please contact support@plusjade.com!!');
     }
     if (!Jdirectory::copy(DOCROOT . "_assets/themes/safe_mode", $theme_path)) {
         return $this->plusjade_dashboard($page_name, 'Uh oh, not even this worked. Please contact support@plusjade.com!!');
     }
     $site->theme = 'safe_mode';
     $site->save();
     if (yaml::edit_site_value($site_name, 'site_config', 'theme', 'safe_mode')) {
         return $this->plusjade_dashboard($page_name, "Safe-mode activated for <b>{$site_name}</b>");
     }
     return $this->plusjade_dashboard($page_name, 'safe-mode theme could not be activated');
 }
Esempio n. 7
0
 public static function _new_website_theme($site_name, $theme)
 {
     $source = DOCROOT . "_assets/themes/{$theme}";
     $dest = DATAPATH . "{$site_name}/themes/{$theme}";
     if (!is_dir($source)) {
         die('This theme does not exist.');
     }
     if (!Jdirectory::copy($source, $dest)) {
         die('Unable to create theme.');
     }
     # Error
     # Parse tokens.
     $type = 'css';
     if (is_dir("{$dest}/{$type}")) {
         $dir = dir("{$dest}/{$type}");
         while ($file = $dir->read()) {
             if ('.' != $file && '..' != $file) {
                 self::new_parse_and_save($theme, $type, $file, file_get_contents("{$dest}/{$type}/{$file}"), $site_name);
             }
         }
         $dir->close();
     }
     return TRUE;
 }