public function postIndex()
 {
     $imagem = Input::file('imagem');
     if (is_null($imagem)) {
         throw new Exception('Você não selecionou um arquivo');
     }
     $destinationPath = public_path() . DIRECTORY_SEPARATOR . 'uploads';
     $filename = date('YmdHis') . '_' . $imagem->getClientOriginalName();
     if ($imagem->move($destinationPath, $filename)) {
         //Load view laravel paths
         $paths = Config::get('view.paths');
         //Load file view
         $file = $paths[0] . DIRECTORY_SEPARATOR . Input::get('view') . '.blade.php';
         $html = file_get_contents($file);
         //Init crawler
         $crawler = new HtmlPageCrawler($html);
         //Set filter
         $filter = '#' . Input::get('id');
         //Edit node
         $crawler->filter($filter)->setAttribute('src', '/uploads/' . $filename);
         $newHTML = html_entity_decode($crawler->saveHTML());
         $newHTML = str_replace('%7B%7B', '{{', $newHTML);
         $newHTML = str_replace('%7D%7D', '}}', $newHTML);
         $newHTML = str_replace('%24', '$', $newHTML);
         $newHTML = str_replace('%20', ' ', $newHTML);
         $newHTML = str_replace('%7C', '|', $newHTML);
         //write file
         file_put_contents($file, $newHTML);
         return Redirect::back()->with('alert', 'Banner enviado com sucesso!');
     }
 }
示例#2
0
 function load_admin(\Wa72\HtmlPageDom\HtmlPageCrawler &$c)
 {
     //Append Button
     $c->filter('.mvc-admin-bar .top-bar')->append('<button class="btn btn-success" data-toggle="navigation-edit-' . $this->id . '">Edit Navigation: ' . $this->title . '</button>');
     //Append Edit Area
     $c->filter('.mvc-admin-bar .t-center .v-center')->append(Theme_Loader::get_instance()->render_file('modules/navigation/admin.twig', ['navitems' => $this->nav_items, 'page_identity' => $this->id]));
 }
示例#3
0
文件: Field.php 项目: stwessl/form
 public function __construct(\Wa72\HtmlPageDom\HtmlPageCrawler &$c, $key = false)
 {
     $this->node = $c;
     if ($key === false) {
         $form = $c->saveHTML();
         $key = md5($form . '--' . session_id());
     }
     $this->key = $key;
     $this->secure_input($key);
     $this->process_post();
 }
 /**
  * {@inheritdoc}
  */
 public function listAttribute($content)
 {
     $this->crawler->addContent($content);
     $this->links = array();
     $this->crawler->filter('a')->each(function (HtmlPageCrawler $anchor, $uri) {
         $href = $anchor->attr('href');
         // @todo deprecated method.
         $this->links[] = $this->urlGenerator->generateFromPath($href, array('absolute' => TRUE));
     });
     $this->crawler->remove();
     return implode(',', $this->links);
 }
示例#5
0
 /**
  *
  *
  * @param FilterResponseEvent $event
  */
 public function onRenderOembedAdminProductDetailEditBefore(FilterResponseEvent $event)
 {
     $request = $event->getRequest();
     $response = $event->getResponse();
     $parts_btn = $this->app->renderView('Oembed/Resource/template/admin/embed-button.twig', array());
     $parts_modal = $this->app->renderView('Oembed/Resource/template/admin/embed-modal.twig', array());
     $crawler = new HtmlPageCrawler($response->getContent());
     $crawler->filter('#admin_product_free_area')->before($parts_btn);
     $crawler->filter('body')->append($parts_modal);
     //        $html = $this->getHtml($crawler);
     $html = $crawler->html();
     $html = html_entity_decode($html, ENT_NOQUOTES, 'UTF-8');
     $response->setContent($html);
     $event->setResponse($response);
 }
示例#6
0
 /**
  * Find and replace static value with dynamic value from created content
  *
  * @param $template, $entity, $view_mode
  *   html string template from component
  *   component entity
  *   view mode of the entity
  *
  * @return
  *   render html for entity
  */
 public function findAndReplace($template, $entity, $view_mode = NULL)
 {
     $html = $this->getHTMLTemplate($template, $view_mode);
     $crawler = new HtmlPageCrawler($html);
     if ($crawler->filterXPath('//*[@data-menu]')->count()) {
         $crawler = $this->findAndReplaceValueForMenuLinks($crawler);
     }
     // get entity view display for entity.
     $entity_type_id = $entity->getEntityTypeId();
     $bundle = $entity->bundle();
     if ($entity_type_id == 'component' || $entity_type_id == 'node' && $view_mode == 'full') {
         $view_mode = 'default';
     }
     $entity_display = \Drupal::entityManager()->getStorage('entity_view_display')->load($entity_type_id . '.' . $bundle . '.' . $view_mode);
     $html = $this->findAndReplaceValueForFields($crawler, $entity, $entity_display, $view_mode);
     return $html;
 }
示例#7
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;
 }
示例#8
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;
 }
 public function postIndex()
 {
     //Load view laravel paths
     $paths = Config::get('view.paths');
     //Load file view
     $file = $paths[0] . DIRECTORY_SEPARATOR . Input::get('view') . '.blade.php';
     $html = file_get_contents($file);
     //Init crawler
     $crawler = new HtmlPageCrawler($html);
     //Set filter
     $filter = '#' . Input::get('id');
     //Edit node
     $crawler->filter($filter)->setInnerHtml(Input::get('html'));
     $newHTML = html_entity_decode($crawler->saveHTML());
     $newHTML = str_replace('%7B%7B', '{{', $newHTML);
     $newHTML = str_replace('%7D%7D', '}}', $newHTML);
     $newHTML = str_replace('%24', '$', $newHTML);
     $newHTML = str_replace('%20', ' ', $newHTML);
     $newHTML = str_replace('%7C', '|', $newHTML);
     //write file
     file_put_contents($file, $newHTML);
 }
示例#10
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);
     }
 }
示例#11
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;
 }
示例#12
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;
 }
示例#13
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();
 }
示例#14
0
 /**
  * Filter nodes by XPath expression
  *
  * @param string $xpath XPath expression
  * @return HtmlPageCrawler
  */
 public function filterXPath($xpath)
 {
     return $this->crawler->filterXPath($xpath);
 }
示例#15
0
文件: index.php 项目: kikyous/CutIt
}
$page = get($_GET['page'], 1);
$site = get($_GET['site']);
$show = get($_GET['show']);
$loader = new Twig_Loader_Filesystem(__DIR__);
$twig = new Twig_Environment($loader, array());
if ($site) {
    $_site = $sites[$site];
    $url_f = $_site['page'];
    if ($show) {
        if (startsWith($show, 'http')) {
            $url = $show;
        } else {
            $url = $url_f(1);
            $url_array = parse_url($url);
            $url = $url_array['scheme'] . '://' . $url_array['host'] . $show;
            $content = new HtmlPageCrawler(file_get_contents($url));
            $content = $content->filter($_site['show_filter']);
            echo $twig->render('show.html', compact('site', 'content', 'url'));
        }
    } else {
        $url = $url_f($page);
        $content = new HtmlPageCrawler(file_get_contents($url));
        $list = $content->filter($_site['index_filter'])->each(function ($node) {
            return $node;
        });
        echo $twig->render('list.html', compact('list', 'page', 'site', 'url'));
    }
} else {
    echo $twig->render('sites.html', compact('sites'));
}
 /**
  * @param string $selector
  * @return static
  */
 public function find($selector)
 {
     return parent::filter($selector);
 }
示例#17
0
 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());
 }
示例#18
0
文件: Form.php 项目: stwessl/form
 public function parent_check(\Wa72\HtmlPageDom\HtmlPageCrawler $node, $count = 0)
 {
     if ($node->nodeName() == '_root') {
         return true;
     }
     $exclude = $node->attr('exclude');
     if (!$exclude) {
         $count++;
         return $this->parent_check($node->parents(), $count);
     } else {
         $node->attr('found-ex', 'FOUND');
         return false;
     }
     return true;
 }