Exemplo n.º 1
0
 /**
  * Handles all resource request that are not js or css
  * 
  * @param type $args
  * @throws Exception
  */
 function index($args)
 {
     //Determine the current theme location
     $theme_location = $this->theme_location;
     $file_location = $theme_location . '/static/' . implode('/', $args);
     if (file_exists($file_location)) {
         $extension = Mvc_Functions::get_extension($file_location);
         $func = "{$extension}_mime";
         if (method_exists($this, $func)) {
             $this->{$func}($file_location);
         } else {
             $mimepath = '/usr/share/magic';
             // may differ depending on your machine
             // try /usr/share/file/magic if it doesn't work
             $mime = finfo_open(FILEINFO_MIME);
             if ($mime === FALSE) {
                 throw new Exception('Unable to open finfo');
             }
             $filetype = finfo_file($mime, $file_location);
             finfo_close($mime);
             if ($filetype === FALSE) {
                 throw new Exception('Unable to recognise filetype');
             }
             header("Content-Type: {$filetype}");
             //			header("X-Content-Type-Options: nosniff");
             header("Access-Control-Allow-Origin:*");
             header('Cache-Control:public, max-age=30672000');
         }
         echo file_get_contents($file_location);
         die;
     } else {
         $this->_404();
         die;
     }
 }
Exemplo n.º 2
0
 function generate_pages()
 {
     //Get all page saved in the pages folder
     echo THEME . '/pages <br>';
     $location = THEME . '/pages';
     $pages = Mvc_Functions::directoryToArray($location, true);
     foreach ($pages as $page) {
         if (Mvc_Functions::get_extension($page) != 'twig') {
             continue;
         }
         //Determine page slug
         $new_loc = str_replace($location . '/', THEME . '/templates/', $page);
         $file = str_replace($location . '/', '', $page);
         $slug = str_replace('.twig', '', $file);
         $template = "templates/{$file}";
         // Determine the page Title
         $title = str_replace('/', ' | ', $slug);
         $title = ucwords(str_replace('-', ' ', $title));
         echo "NEW LOCATION: {$new_loc} | FILE: {$file} | TEMPLATE: {$template} | SLUG: {$slug} | TITLE: {$title} <br>";
         //Copy the file to the layouts location
         if (!is_dir(dirname($new_loc))) {
             mkdir(dirname($new_loc), 0777, true);
         }
         copy($page, $new_loc);
         //Create Page Bean
         $page = current(R::findOrDispense('page', 'slug = :slug', ['slug' => $slug]));
         $page->slug = $slug;
         $page->title = "{$title} | Durbanville Hills";
         $page->template = $template;
         $page->layout = "layouts/default.twig";
         R::store($page);
     }
 }
Exemplo n.º 3
0
 function store_file()
 {
     $value = $this->value;
     //Save the file inside the database
     $file = R::dispense('file');
     $filename = $value[G2_FormMagic::FILE_NAME];
     $filename = preg_replace("([^\\w\\s\\d\\-_~,;:\\[\\]\\(\\).])", '', $filename);
     // Remove any runs of periods (thanks falstro!)
     $filename = preg_replace("([\\.]{2,})", '', $filename);
     //Move the file to an upload directory;
     $directory = "uploads/";
     //check if the current file exist. If it does update the name
     $count = 1;
     $start_looking = $filename;
     while (file_exists($directory . $start_looking)) {
         $start_looking = str_replace('.' . Mvc_Functions::get_extension($filename), '', $filename) . "_{$count}" . '.' . Mvc_Functions::get_extension($filename);
         $count++;
     }
     $filename = $start_looking;
     $full_uri = $directory . $start_looking;
     if (!is_dir(dirname($full_uri))) {
         mkdir(dirname($full_uri), 0777, true);
     }
     if (!file_exists($value[G2_FormMagic::FILE_URI])) {
         return;
     }
     move_uploaded_file($value[G2_FormMagic::FILE_URI], $full_uri);
     //Save the file to database
     $file->name = $filename;
     $file->uri = $full_uri;
     R::store($file);
     $this->area->file = $file;
 }
Exemplo n.º 4
0
 public static function deserialize($audits)
 {
     $audits_d = [];
     foreach ($audits as $ad) {
         $ad->old_obj = unserialize($ad->old_obj);
         $ad->new_obj = unserialize($ad->new_obj);
         foreach ($ad as $field => $value) {
             if (Mvc_Functions::endsWith($field, '_id')) {
                 $bean = substr($field, 0, strpos($field, '_id'));
                 $ad->{$bean};
             }
         }
         $audits_d[] = $ad;
     }
     return $audits_d;
 }
Exemplo n.º 5
0
 function render()
 {
     //Check if a class is defined for a type
     $area = $this->get_area_instance();
     if ($this->editable) {
         $area->editable = true;
     }
     //Remove all funny tags from file
     $content = $area->render();
     $c = \Wa72\HtmlPageDom\HtmlPageCrawler::create($content);
     $c->removeAttr('mvcl-type');
     $c->removeAttr('mvc-type');
     $c->removeAttr('mvc-type');
     $c->removeAttr('mvc-size');
     if ($c->getNode(0)->hasAttributes()) {
         foreach ($c->getNode(0)->attributes as $attr) {
             $name = $attr->nodeName;
             if (Mvc_Functions::startsWith($name, 'mvc')) {
                 $c->removeAttr($name);
             }
         }
     }
     return $c->saveHTML();
 }
Exemplo n.º 6
0
 public function create_pages()
 {
     //Load Page files
     $files = Mvc_Functions::directoryToArray($this->theme . "/pages", true);
     //		var_dump($files);exit;
     //Loop throught the files and read theme seperately
     foreach ($files as $file) {
         if (is_dir($file)) {
             continue;
         }
         $id = $file . "-" . BASE_URL;
         //Check file last modified before loading
         $file_mod_time = current(R::findOrDispense('filem', 'filename = :file', ['file' => $id]));
         if (!$file_mod_time->getID()) {
             $file_mod_time->filename = $id;
             $file_mod_time->last_modified = filemtime($file);
             R::store($file_mod_time);
         } else {
             //				debug($file . ' === ' . filemtime($file) . ' ' . $file_mod_time->last_modified);
             if (filemtime($file) > $file_mod_time->last_modified) {
                 $file_mod_time->last_modified = filemtime($file);
                 R::store($file_mod_time);
             } else {
                 continue;
             }
         }
         list($config, $template) = explode("==", file_get_contents($file));
         list($config, $template) = preg_split('/(==\\n)|(==\\r)/', file_get_contents($file));
         //						parent::$lines = preg_split('/\r\n|\n|\r/', trim(file_get_contents('file.txt')));
         $config = new App_Config_Ini($config);
         if ($config->type) {
             $classname = "Theme_Type_" . ucfirst($config->type);
             if (class_exists($classname)) {
                 $class = new $classname($this);
                 if ($class instanceof Theme_Type) {
                     $class->create($file, $config, $template, filemtime($file));
                 }
             }
         } else {
             $class = new Theme_Type_Page($this);
             $class->create($file, $config, $template, filemtime($file));
         }
     }
     //Remove all pages saved in database that does not exist inside the pages folder
     $this->remove_old_pages();
 }
Exemplo n.º 7
0
 function crud($args)
 {
     $id = array_shift($args);
     //Check if user is loaded
     if (!empty($id) && is_numeric($id)) {
         $user = R::load('user', $id);
         if ($user->isEmpty()) {
             $this->redirect(PACKAGE_URL);
         }
     } else {
         $user = R::dispense('user');
     }
     $old = clone $user;
     $form_view = new G2_TwigView('forms/user');
     $form_view->set('groups', R::findAll('group'));
     // Sets group information
     $form_view->set('user', $user);
     $form = new G2_FormMagic($form_view->get_render());
     //		var_dump($user->export());
     if (empty($_POST)) {
         $data = $user->export();
         $groups = [];
         foreach ($user->sharedGroup as $bean) {
             $groups[] = $bean->name;
         }
         $data['sharedGroup'] = $groups;
         $form->set_data($data);
         //			var_dump($data);exit;
     }
     if ($form->is_posted() && $form->validate()) {
         $data = $form->data();
         //			var_dump($data);exit;
         if ($data['password'] != $user->password) {
             //The Users password changed. Need to re encrypt
             $data['password'] = G()->hash_pass($data['password']);
         }
         foreach ($data as $field => $value) {
             if (is_array($user->{$field}) && Mvc_Functions::startsWith($field, 'shared')) {
                 $bean = strtolower(substr($field, strlen('shared')));
                 $bean_ar = [];
                 foreach ($value as $name) {
                     $bean_ar[] = G()->load_group($name);
                 }
                 $user->{"shared" . ucfirst($bean)} = $bean_ar;
             } else {
                 $user->{$field} = $value;
             }
         }
         if (empty($user->sharedGroup)) {
             $user->sharedGroup = [G()->load_group('default')];
         }
         R::store($user);
         if (empty($old->id)) {
             Audit::create($old, $user, 'New user was created');
         } else {
             Audit::create($old, $user, 'User details was updated');
         }
         $this->redirect(PACKAGE_URL . 'crud/' . $user->id);
     }
     $view = new G2_TwigView('pages/crud');
     $view->set('form', $form->parse());
     $view->render();
 }