Example #1
0
 /**
  * 
  * @return Wa72\HtmlPageDom\HtmlPageCrawler
  */
 function &c()
 {
     if ($this->c) {
         return $this->c;
     } else {
         return $this->c = Wa72\HtmlPageDom\HtmlPageCrawler::create($this->area->html);
     }
 }
 public function changeBody($body, $trackLinks = false, $email = '', $id = '')
 {
     if ($trackLinks) {
         $page = new \Wa72\HtmlPageDom\HtmlPage($body);
         $links = $page->getCrawler()->filter('a');
         foreach ($links as $link) {
             $link = new \Wa72\HtmlPageDom\HtmlPageCrawler($link);
             $string = $link->attr('href');
             if (substr_count($string, 'javascript') == 0 && substr_count($string, 'mailto') == 0) {
                 if (substr_count($string, '?')) {
                     $string .= '&';
                 } else {
                     $string .= '?';
                 }
                 $string .= 'nwref=' . urlencode($email) . '&nwid=' . $id;
             }
             $link->attr('href', $string);
         }
         $htmlPage = $page->save();
     } else {
         $htmlPage = $body;
     }
 }
Example #3
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);
                     }
                 }
             }
         }
     });
 }