Esempio n. 1
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();
 }
Esempio n. 2
0
 function replace_cdn_script_tags(Wa72\HtmlPageDom\HtmlPageCrawler &$c)
 {
     //Find all cdn scripts
     $nodes = $c->filter('script');
     $nodes->each(function (Wa72\HtmlPageDom\HtmlPageCrawler &$node) use($c) {
         /* @var $node \Wa72\HtmlPageDom\HtmlPageCrawler */
         $href = $node->getAttribute('src');
         if (!file_exists(THEME . '/' . $href)) {
             //Check if this is an external link
             if (filter_var($href, FILTER_VALIDATE_URL) === false && Mvc_Functions::startsWith($href, '//')) {
                 //Determine its download location by hashing the url
                 $hash = md5($href);
                 $filename = "static/js/downloaded/{$hash}.js";
                 $file_loc = THEME . "/" . $filename;
                 if (!file_exists($file_loc) && isset($_GET['downloadjs'])) {
                     //Download the link
                     //						echo "$href <br>";
                     if (Mvc_Functions::startsWith($href, '//')) {
                         $href = 'http:' . $href;
                     }
                     $content = file_get_contents($href);
                     debug($href);
                     debug($content);
                     if (empty($content)) {
                         return;
                     }
                     if (!is_dir(dirname($file_loc))) {
                         mkdir(dirname($file_loc));
                     }
                     file_put_contents($file_loc, $content);
                     $c->filter('script[src="' . $href . '"]')->setAttribute('src', $filename);
                 } else {
                     if (file_exists($file_loc)) {
                         $c->filter('script[src="' . $href . '"]')->setAttribute('src', $filename);
                     }
                 }
             }
         }
     });
 }
Esempio n. 3
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();
 }