Beispiel #1
0
 function save()
 {
     //Update html value to match new uploaded file
     $c = \Wa72\HtmlPageDom\HtmlPageCrawler::create($this->area->html);
     if ($this->area->file != null) {
         $c->setAttribute('src', $this->area->file->uri);
     }
     $this->area->html = $c->saveHTML();
     R::store($this->area);
     return true;
 }
Beispiel #2
0
 function save()
 {
     //Update html value to match new uploaded file
     $c = \Wa72\HtmlPageDom\HtmlPageCrawler::create($this->area->html);
     if ($this->area->file != null) {
         $c->setAttribute('style', 'background-image:url(\'' . $this->area->file->uri . '\');');
     }
     $this->area->html = $c->saveHTML();
     R::store($this->area);
     return true;
 }
Beispiel #3
0
 public function __construct($form, $s_key = false)
 {
     $this->string = $form;
     //Load html in html parser
     $this->c = HtmlPageCrawler::create($this->string);
     if ($s_key) {
         $this->s_key = $s_key;
     } else {
         $this->s_key = md5($this->c->saveHTML());
     }
     // Look for all standerd inputs and special input divs
     $this->assemble_fields();
 }
Beispiel #4
0
 function process_html()
 {
     //Find the post table name
     $c = HtmlPageCrawler::create($this->html);
     $model = $this->loadModel('post_model');
     /* @var $model Post_Model */
     $table = $c->filter('attribute[key="post-type"]')->text();
     $this->posts = $model->get_posts($table);
     $fields = $c->filter('field');
     foreach ($fields as $field) {
         $fieldname = $field->getAttribute('name');
         $type = $field->getAttribute('type') ? $field->getAttribute('type') : 'text';
         $show = $field->getAttribute('show') == 'true' ? true : false;
         $model->create_field($table, $fieldname, $type, $show);
     }
 }
Beispiel #5
0
 function get_areas($html)
 {
     //Load the html into a dom document
     //		$dom = new DOMDocument("4.0", 'UTF-8');
     //		$dom->loadHTML($html);
     $dom = HtmlPageCrawler::create($html);
     //Look for html nodes that has the mvc:edit attribute
     //		$nodes = $this->find_editable($dom);
     $nodes = $dom->filter('[mvcl-edit]');
     $instance =& $this;
     $area_beans = $nodes->each(function ($node) use($nodes_c, $instance) {
         $field_name = $node->getAttribute('mvcl-edit');
         /* @var $node HtmlPageCrawler */
         $field_type = $node->getAttribute('mvcl-type');
         $starting_html = $node->saveHTML();
         return $instance->load_area($instance->page->id, $field_name, $field_type, $starting_html);
     });
     // Convert these nodes to area beens
     //		$area_beans = $this->nodes_to_beans($nodes);
     return $area_beans;
 }
Beispiel #6
0
 function get_areas($html)
 {
     //Load the html into a dom document
     //		$dom = new DOMDocument("4.0", 'UTF-8');
     //		$dom->loadHTML($html);
     $dom = HtmlPageCrawler::create($html);
     //Look for html nodes that has the mvc:edit attribute
     //		$nodes = $this->find_editable($dom);
     $nodes = $dom->filter('[mvc-edit]');
     $instance =& $this;
     $area_beans = $nodes->each(function ($node) use($nodes_c, $instance) {
         $field_name = $node->getAttribute('mvc-edit');
         /* @var $node HtmlPageCrawler */
         $field_type = $node->getAttribute('mvc-type');
         $starting_html = $node->saveHTML();
         return $instance->load_area($instance->page->id, $field_name, $field_type, $starting_html);
     });
     // Delete all areas that are not relevant but connected to this page
     $areas = R::findAll('area', 'page_id = :page', ['page' => $this->page->id]);
     $not_loaded = [];
     foreach ($areas as $area) {
         $bid = $area->id;
         foreach ($area_beans as $area_b) {
             if ($area_b->id == $bid) {
                 $found = true;
                 break;
             }
         }
         if (!$found) {
             $not_loaded[] = $area;
         }
     }
     R::trashAll($not_loaded);
     // Convert these nodes to area beens
     //		$area_beans = $this->nodes_to_beans($nodes);
     return $area_beans;
 }
Beispiel #7
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();
 }
 public function testText()
 {
     // ATTENTION: Contrary to the parent Crawler class, which returns the text from the first element only,
     // this functions returns the combined text of all elements (as jQuery does)
     $c = HtmlPageCrawler::create('<p>abc</p><p>def</p>');
     $this->assertEquals('abcdef', $c->text());
     $c->text('jklo');
     $this->assertEquals('jklojklo', $c->text());
 }