newDocument() public static method

Chainable.
public static newDocument ( unknown_type $markup = null, $contentType = null ) : phpQueryObject | QueryTemplatesSource | QueryTemplatesParse | QueryTemplatesSourceQuery
$markup unknown_type
return phpQueryObject | QueryTemplatesSource | QueryTemplatesParse | QueryTemplatesSourceQuery
Example #1
0
 public function get_data()
 {
     if (!class_exists('phpQuery')) {
         include dirname(__FILE__) . '/phpQuery.php';
     }
     $response = wp_remote_get($this->url . '/tags');
     if (is_wp_error($response)) {
         return false;
     }
     phpQuery::newDocument($response['body']);
     $version = false;
     $zip_url = false;
     foreach (pq('table.tags a.name') as $tag) {
         $tag = pq($tag);
         if (version_compare($tag->text(), $version, '>=')) {
             $href = $tag->attr('href');
             $commit = substr($href, strrpos($href, '/') + 1);
             $zip_url = $this->url . '/snapshot/' . $commit . '.zip';
             $version = $tag->text();
             $updated_at = $tag->parent()->prev()->text();
         }
     }
     $this->new_version = $version;
     $this->zip_url = $zip_url;
     $this->updated_at = date('Y-m-d', strtotime($updated_at));
     $this->description = pq('div.page_footer_text')->text();
 }
Example #2
0
 function getBody()
 {
     if ($this->parts && $this->body === null) {
         foreach ($this->parts as $part) {
             $partNo = $part['partNo'];
             $encoding = $part['encoding'];
             $charset = $part['charset'];
             $body = imap_fetchbody($this->message->getMailbox(), $this->message->getUID(), $partNo, FT_UID);
             $body = BrIMAP::decode($body, $encoding);
             if ($charset) {
                 $body = @iconv($charset, 'UTF-8', $body);
             }
             $body = trim($body);
             $body = preg_replace('~<head[^>]*?>.*?</head>~ism', '', $body);
             $body = preg_replace('~<meta[^>]*?>~ism', '', $body);
             $body = preg_replace('~<base[^>]*?>~ism', '', $body);
             $body = preg_replace('~<style[^>]*?>.*?</style>~ism', '', $body);
             if ($this->isHTML && $body) {
                 try {
                     $doc = phpQuery::newDocument($body);
                     $bodyTag = $doc->find('body');
                     if ($bodyTag->length() > 0) {
                         $body = trim(pq($bodyTag)->html());
                     } else {
                         $body = trim($doc->html());
                     }
                     phpQuery::unloadDocuments();
                 } catch (Exception $e) {
                 }
             }
             $this->body .= $body;
         }
     }
     return $this->body;
 }
Example #3
0
 public function find_product_url($product_name)
 {
     $url = 'http://ek.ua/';
     $data = array('search_' => $product_name);
     $response = Request::factory($url)->query($data)->execute();
     //echo Debug::vars($response->body());
     //echo Debug::vars($response->headers());
     $response = $response->body();
     try {
         $doc = phpQuery::newDocument($response);
     } catch (Exception $ex) {
         $errors[] = $ex->getMessage();
         echo Debug::vars($errors);
     }
     if (!isset($errors)) {
         /* Нужно взять заголовок и найти в нем слово найдено */
         /*
          * что я заметил, удивительно но на разных машинах этот заголовои идет с разным классом
          * на данный момент этот класс oth
          */
         $str = $doc->find('h1.oth')->html();
         if (preg_match('/найдено/', $str)) {
             echo Debug::vars('алилуя !!!');
             die;
         }
         return $str;
     }
 }
 public function test_data()
 {
     $this->prepareLookup();
     $this->preparePages();
     $access = AccessTable::byTableName('dropdowns', 'test1');
     $data = $access->getData();
     $this->assertEquals('["1","[\\"title1\\",\\"This is a title\\"]"]', $data[0]->getValue());
     $this->assertEquals('["1","title1"]', $data[1]->getValue());
     $this->assertEquals('John', $data[2]->getValue());
     $this->assertEquals('1', $data[0]->getRawValue());
     $this->assertEquals('1', $data[1]->getRawValue());
     $this->assertEquals('John', $data[2]->getRawValue());
     $this->assertEquals('This is a title', $data[0]->getDisplayValue());
     $this->assertEquals('title1', $data[1]->getDisplayValue());
     $this->assertEquals('John', $data[2]->getDisplayValue());
     $R = new \Doku_Renderer_xhtml();
     $data[0]->render($R, 'xhtml');
     $pq = \phpQuery::newDocument($R->doc);
     $this->assertEquals('This is a title', $pq->find('a')->text());
     $this->assertContains('title1', $pq->find('a')->attr('href'));
     $R = new \Doku_Renderer_xhtml();
     $data[1]->render($R, 'xhtml');
     $pq = \phpQuery::newDocument($R->doc);
     $this->assertEquals('title1', $pq->find('a')->text());
     $this->assertContains('title1', $pq->find('a')->attr('href'));
     $R = new \Doku_Renderer_xhtml();
     $data[2]->render($R, 'xhtml');
     $this->assertEquals('John', $R->doc);
 }
Example #5
0
 function createSpots()
 {
     // TODO :: Some caching ??
     $this->pq = $pq = new phpQuery();
     $this->dom = $dom = $pq->newDocument($this->owner->template->template_source);
     if (!$this->owner instanceof \Frontend) {
         $pq->pq($dom)->attr('xepan-page-content', 'true');
         $pq->pq($dom)->addClass('xepan-page-content');
     }
     foreach ($dom['.xepan-component'] as $d) {
         $d = $pq->pq($d);
         if (!$d->hasClass('xepan-serverside-component')) {
             continue;
         }
         $i = $this->spots++;
         $inner_html = $d->html();
         $with_spot = '{' . $this->owner->template->name . '_' . $i . '}' . $inner_html . '{/}';
         $d->html($with_spot);
     }
     $content = $this->updateBaseHrefForTemplates();
     $content = str_replace('<!--xEpan-ATK-Header-Start', '', $content);
     $content = str_replace('xEpan-ATK-Header-End-->', '', $content);
     $this->owner->template->loadTemplateFromString($content);
     $this->owner->template->trySet($this->app->page . '_active', 'active');
 }
Example #6
0
 /**
  * Query the response for a JQuery compatible CSS selector
  *
  * @link https://code.google.com/p/phpquery/wiki/Selectors
  * @param $selector string
  * @return phpQueryObject
  */
 public function queryHTML($selector)
 {
     if (is_null($this->pq)) {
         $this->pq = phpQuery::newDocument($this->content);
     }
     return $this->pq->find($selector);
 }
Example #7
0
 public function getLinkContent()
 {
     require_once './ThinkPHP/Library/Vendor/Collection/phpQuery.php';
     $link = op_t(I('post.url'));
     $content = get_content_by_url($link);
     $charset = preg_match("/<meta.+?charset=[^\\w]?([-\\w]+)/i", $content, $temp) ? strtolower($temp[1]) : "utf-8";
     \phpQuery::$defaultCharset = $charset;
     \phpQuery::newDocument($content);
     $title = pq("meta[name='title']")->attr('content');
     if (empty($title)) {
         $title = pq("title")->html();
     }
     $title = iconv($charset, "UTF-8", $title);
     $keywords = pq("meta[name='keywords'],meta[name='Keywords']")->attr('content');
     $description = pq("meta[name='description'],meta[name='Description']")->attr('content');
     $url = parse_url($link);
     $img = pq("img")->eq(0)->attr('src');
     if (is_bool(strpos($img, 'http://'))) {
         $img = 'http://' . $url['host'] . $img;
     }
     $title = text($title);
     $description = text($description);
     $keywords = text($keywords);
     $return['title'] = $title;
     $return['img'] = $img;
     $return['description'] = empty($description) ? $title : $description;
     $return['keywords'] = empty($keywords) ? $title : $keywords;
     exit(json_encode($return));
 }
 function testShowData()
 {
     $handler = new Doku_Handler();
     $xhtml = new Doku_Renderer_xhtml();
     $plugin = new syntax_plugin_data_entry();
     $result = $plugin->handle($this->exampleEntry, 0, 10, $handler);
     $plugin->_showData($result, $xhtml);
     $doc = phpQuery::newDocument($xhtml->doc);
     $this->assertEquals(1, pq('div.inline.dataplugin_entry.projects', $doc)->length);
     $this->assertEquals(1, pq('dl dt.type')->length);
     $this->assertEquals(1, pq('dl dd.type')->length);
     $this->assertEquals(1, pq('dl dt.volume')->length);
     $this->assertEquals(1, pq('dl dd.volume')->length);
     $this->assertEquals(1, pq('dl dt.employee')->length);
     $this->assertEquals(1, pq('dl dd.employee')->length);
     $this->assertEquals(1, pq('dl dt.customer')->length);
     $this->assertEquals(1, pq('dl dd.customer')->length);
     $this->assertEquals(1, pq('dl dt.deadline')->length);
     $this->assertEquals(1, pq('dl dd.deadline')->length);
     $this->assertEquals(1, pq('dl dt.server')->length);
     $this->assertEquals(1, pq('dl dd.server')->length);
     $this->assertEquals(1, pq('dl dt.website')->length);
     $this->assertEquals(1, pq('dl dd.website')->length);
     $this->assertEquals(1, pq('dl dt.task')->length);
     $this->assertEquals(1, pq('dl dd.task')->length);
     $this->assertEquals(1, pq('dl dt.tests')->length);
     $this->assertEquals(1, pq('dl dd.tests')->length);
 }
Example #9
0
function real_test($idnum, $name)
{
    error_reporting(E_ALL);
    ini_set('display_errors', 'On');
    include './vendor/autoload.php';
    //$idnum = '130123198706234534';
    //$name = '祁星月';
    $url = 'http://www.runchina.org.cn/portal.php?mod=score&ac=personal';
    $headstr = "-H 'Pragma: no-cache' -H 'Origin: http://www.runchina.org.cn' -H 'Accept-Encoding: gzip, deflate' -H 'Accept-Language: zh-CN,zh;q=0.8,en;q=0.6,zh-TW;q=0.4,ja;q=0.2' -H 'Upgrade-Insecure-Requests: 1' -H 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.103 Safari/537.36' -H 'Content-Type: application/x-www-form-urlencoded' -H 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8' -H 'Cache-Control: no-cache' -H 'Referer: http://www.runchina.org.cn/portal.php?mod=score&ac=personal' -H 'Cookie: SMHa_2132_saltkey=tQi19Tmq; SMHa_2132_lastvisit=1468828350; SMHa_2132_sid=l9z09Q; SMHa_2132_lastact=1468832009%09portal.php%09score; Hm_lvt_b0a502205e02e6127ae831a751ff05b3=1468831949; Hm_lpvt_b0a502205e02e6127ae831a751ff05b3=1468832009' -H 'Connection: keep-alive'";
    $data = array('idnum' => $idnum, 'name' => $name);
    $reg = '/\'([A-Za-z]+)\\:\\s?([^\']+)\'/';
    preg_match_all($reg, $headstr, $matches);
    $keys = $matches[1];
    $values = $matches[2];
    $headers = array_combine($keys, $values);
    $ch = curl_init($url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
    $content = curl_exec($ch);
    $pq = phpQuery::newDocument($content);
    $real_items = array();
    $results = $pq->find("table tr:gt(0)");
    foreach ($results as $result) {
        $x = $result->nodeValue;
        $v = explode("\n", $x);
        $real_items[] = array($v[0], trim($v[2]), trim($v[5]), trim($v[6]));
    }
    echo json_encode($real_items);
}
Example #10
0
 public function addclass($html, $selector, $class)
 {
     require __DIR__ . '/phpQuery.php';
     $pq = \phpQuery::newDocument($html);
     $pq[$selector]->addClass($class);
     return new \Twig_Markup($pq, 'UTF-8');
 }
Example #11
0
 function __construct($bookfile)
 {
     $src = file_get_contents($bookfile);
     $this->source_dir = dirname($bookfile);
     list($meta, $src) = explode("\n\n", $src, 2);
     foreach (explode("\n", $meta) as $line) {
         list($k, $v) = explode(":", $line, 2);
         list($dk, $mk) = explode('-', trim($k), 2);
         if ($dk == 'doc') {
             $this->doc_meta[$mk] = trim($v);
         } else {
             if ($dk) {
                 $this->meta[$dk . $mk] = trim($v);
             }
         }
     }
     $src = $this->fetch_includes($src);
     $layout = "default_layout.html";
     if (true) {
         $this->html = $this->layout($layout, array("content" => Markdown($src)));
     } else {
         $this->html = '<div id="body"><div id="cont">' . Markdown($src) . "</div></div>";
     }
     if ($this->doc_meta['toc-levels']) {
         $this->levels = explode(',', $this->doc_meta['toc-levels']);
     } else {
         $this->levels = array('h1', 'h2');
     }
     $doc = phpQuery::newDocument($this->html);
     $this->docID = $doc->getDocumentID();
 }
 /**
  * ___render___
  *
  * @method ___render___
  * @param {string} $content
  */
 protected function ___render___($content)
 {
     if ($content && is_string($content)) {
         if ($this->functions_for_render && (is_array($this->functions_for_render) || $this->functions_for_render instanceof ArrayObject)) {
             $before = $this->cache_read === true ? array() : array_filter((array) $this->functions_for_render, create_function('$v', 'return $v[\'after_cache\'] !== true;'));
             $after = array_filter((array) $this->functions_for_render, create_function('$v', 'return $v[\'after_cache\'] === true;'));
         } else {
             $before = $after = array();
         }
         if (0 < count($before) || 0 < count($after)) {
             $pq = phpQuery::newDocument($content);
             //before cache
             foreach ($before as $fn) {
                 $pq = call_user_func($fn, $pq);
             }
             if ($this->cache_file && !$this->cache_read) {
                 file_put_contents($this->cache_file, $pq);
             }
             //after cache
             foreach ($before as $fn) {
                 $pq = call_user_func($fn, $pq);
             }
             $content = $pq;
         } else {
             if ($this->cache_file) {
                 file_put_contents($this->cache_file, $content);
             }
         }
     }
     echo $content;
 }
Example #13
0
 function Plugins_RunServerSideComponent($obj, $page)
 {
     include_once getcwd() . '/lib/phpQuery.php';
     $pq = new \phpQuery();
     $doc = $pq->newDocument($page['content']);
     $server = $doc['[data-is-serverside-component=true]'];
     foreach ($doc['[data-is-serverside-component=true]'] as $ssc) {
         $options = array();
         foreach ($ssc->attributes as $attrName => $attrNode) {
             $options[$attrName] = $pq->pq($ssc)->attr($attrName);
         }
         $namespace = $pq->pq($ssc)->attr('data-responsible-namespace');
         $view = $pq->pq($ssc)->attr('data-responsible-view');
         if (!file_exists($path = getcwd() . DS . 'epan-components' . DS . $namespace . DS . 'lib' . DS . 'View' . DS . 'Tools' . DS . str_replace("View_Tools_", "", $view) . '.php')) {
             $temp_view = $this->owner->add('View_Error')->set("Server Side Component Not Found :: {$namespace}/{$view}");
         } else {
             $temp_view = $this->owner->add("{$namespace}/{$view}", array('html_attributes' => $options, 'data_options' => $pq->pq($ssc)->attr('data-options')));
         }
         if (!$_GET['cut_object'] and !$_GET['cut_page']) {
             $html = $temp_view->getHTML();
             $pq->pq($ssc)->html("")->append($html);
         }
     }
     $page['content'] = $doc->htmlOuter();
 }
Example #14
0
 public function run()
 {
     $content = ob_get_clean();
     $formatted = phpQuery::newDocument($content);
     $imageNodes = pq('img');
     foreach ($imageNodes as $imNode) {
         $imNode = pq($imNode);
         $imPath = $imNode->attr('src');
         $thumbPath = $this->thumbsDir . '/' . basename($imPath);
         //$thumbPath = dirname($imPath).'/thumbs/'.basename($imPath);
         // Create thumbnail if not exists
         if (!file_exists($thumbPath)) {
             $imgObj = Yii::app()->simpleImage->load($imPath);
             if (!isset($this->thumbHeight)) {
                 $imgObj->resizeToWidth($this->thumbWidth);
             } else {
                 $imgObj->resize($this->thumbWidth, $this->thumbHeight);
             }
             $imgObj->save($thumbPath);
         }
         $imNode->wrap('<a href="' . $imPath . '" rel="gallery"></a>');
         $imNode->attr('src', Yii::app()->request->baseUrl . DIRECTORY_SEPARATOR . $thumbPath);
     }
     echo $formatted;
 }
Example #15
0
 public function success($response)
 {
     $pq = phpQuery::newDocument($response);
     foreach ($this->calls as $k => $r) {
         // check if method exists
         if (!method_exists(get_class($pq), $r['method'])) {
             throw new Exception("Method '{$r['method']}' not implemented in phpQuery, sorry...");
             // execute method
         } else {
             $pq = call_user_func_array(array($pq, $r['method']), $r['arguments']);
         }
     }
     if (!isset($this->options['dataType'])) {
         $this->options['dataType'] = '';
     }
     switch (strtolower($this->options['dataType'])) {
         case 'json':
             if ($pq instanceof PHPQUERYOBJECT) {
                 $results = array();
                 foreach ($pq as $node) {
                     $results[] = pq($node)->htmlOuter();
                 }
                 print phpQuery::toJSON($results);
             } else {
                 print phpQuery::toJSON($pq);
             }
             break;
         default:
             print $pq;
     }
     // output results
 }
Example #16
0
 /**
  * @return void
  */
 function testMultiInsert()
 {
     // Multi-insert
     $pq = phpQuery::newDocument('<li><span class="field1"></span><span class="field1"></span></li>')->find('.field1')->php('longlongtest');
     $validResult = '<li><span class="field1"><php>longlongtest</php></span><span class="field1"><php>longlongtest</php></span></li>';
     similar_text($pq->htmlOuter(), $validResult, $similarity);
     $this->assertGreaterThan(80, $similarity);
 }
 public function test_HTMLinclusion()
 {
     $input = file_get_contents(dirname(__FILE__) . '/input.txt');
     $xhtml = p_render('xhtml', p_get_instructions($input), $info);
     $doc = phpQuery::newDocument($xhtml);
     // HTML Check - there should be no bold tag anywhere
     $this->assertEquals(0, pq('bold', $doc)->length);
 }
Example #18
0
 protected function _processHtml($return_raw, &$np)
 {
     // Query document for tables with stream data.
     $pq = \phpQuery::newDocument($return_raw);
     $mounts = array();
     $tables_1 = $pq->find('table:has(td.streamdata)');
     if ($tables_1->length > 0) {
         $tables = $tables_1;
         $table_selector = 'td.streamdata';
     } else {
         return false;
     }
     foreach ($tables as $table) {
         $streamdata = pq($table)->find($table_selector);
         $mount = array();
         $i = 0;
         foreach ($streamdata as $cell) {
             $pq_cell = pq($cell);
             $cell_name = $pq_cell->prev()->html();
             $cell_name_clean = preg_replace('/[^\\da-z_]/i', '', str_replace(' ', '_', strtolower($cell_name)));
             $cell_value = trim($pq_cell->html());
             if (!empty($cell_name_clean) && !empty($cell_value)) {
                 $mount[$cell_name_clean] = $cell_value;
             }
             $i++;
         }
         $mounts[] = $mount;
     }
     if (count($mounts) == 0) {
         return false;
     }
     $active_mounts = array();
     foreach ($mounts as $mount) {
         if (count($mount) >= 9) {
             $active_mounts[] = $mount;
         }
     }
     if (count($active_mounts) == 0) {
         return false;
     }
     // Sort in descending order of listeners.
     usort($active_mounts, function ($a, $b) {
         $a_list = (int) $a[5];
         $b_list = (int) $b[5];
         if ($a_list == $b_list) {
             return 0;
         } else {
             return $a_list > $b_list ? -1 : 1;
         }
     });
     $temp_array = $active_mounts[0];
     $np['current_song'] = $this->getSongFromString($temp_array['current_song'], ' - ');
     $np['meta']['status'] = 'online';
     $np['meta']['bitrate'] = $temp_array['bitrate'];
     $np['meta']['format'] = $temp_array['content_type'];
     $np['listeners']['current'] = (int) $temp_array['current_listeners'];
     return true;
 }
Example #19
0
 public static function renderInfo($id, $type, $parent, $tmpl)
 {
     global $wp_post_statuses, $wp_post_types;
     switch ($type) {
         case 'post':
             //get information about page or post
             $post = get_post($id);
             if ($post->ID) {
                 $tmpl = mvb_Model_Template::retrieveSub('POST', $tmpl);
                 $tmpl = phpQuery::newDocument($tmpl);
                 $data = $parent->getConfig()->getRestriction('post', $id);
                 foreach ($data as $key => $value) {
                     $tmpl['#' . $key]->attr('checked', 'checked');
                 }
                 if ($parent->getCurrentUser()) {
                     $tmpl['.save-postinfo-all']->attr('disabled', 'disabled');
                 }
                 $tmpl['.category-title']->html(mvb_Model_Helper::editPostLink($post));
                 //check what type of post is it and render exclude if page
                 if (isset($wp_post_types[$post->post_type])) {
                     if ($wp_post_types[$post->post_type]->capability_type != 'page') {
                         $tmpl['#exclude']->remove();
                     }
                 }
                 $tmpl = $tmpl->htmlOuter();
             }
             break;
         case 'taxonomy':
             //get information about category
             $taxonomy = mvb_Model_Helper::getTaxonomyByTerm($id);
             $term = get_term($id, $taxonomy);
             if ($term->term_id) {
                 $tmpl = mvb_Model_Template::retrieveSub('CATEGORY', $tmpl);
                 $tmpl = phpQuery::newDocument($tmpl);
                 $data = $parent->getConfig()->getRestriction('taxonomy', $id);
                 foreach ($data as $key => $value) {
                     $tmpl['#' . $key]->attr('checked', 'checked');
                 }
                 if ($parent->getCurrentUser()) {
                     $tmpl['.save-postinfo-all']->attr('disabled', 'disabled');
                 }
                 $tmpl['.category-title']->html(mvb_Model_Helper::editTermLink($term));
                 $tmpl['.subposts']->html(sprintf(mvb_Model_Label::get('LABEL_178'), $term->name));
                 if (mvb_Model_Helper::isPremium()) {
                     $tmpl['.premium']->removeClass('premium');
                     $tmpl['#premium-ind']->html('&nbsp;');
                 }
                 $tmpl = $tmpl->htmlOuter();
             }
             break;
         default:
             $tmpl = '';
             break;
     }
     $tmpl = mvb_Model_Label::clearLabels($tmpl);
     $result = array('status' => 'success', 'html' => mvb_Model_Template::clearTemplate($tmpl));
     return $result;
 }
Example #20
0
 private function GetPicture()
 {
     $outSite = file_get_contents('http://www.gifbin.com/random');
     require __DIR__ . "/phpQuery/phpQuery.php";
     $document = \phpQuery::newDocument($outSite);
     $hentry = $document->find('#gif');
     unset($outSite, $document);
     return $hentry;
 }
Example #21
0
 public function getAnyImg($page, $selectors, $return, $dop)
 {
     $result = '';
     $html = phpQuery::newDocument($page);
     foreach ($html->find($selectors) as $e) {
         $result .= pq($e)->{$return}($dop);
     }
     return $result;
 }
Example #22
0
 /**
  * @param $conf ConfNode
  * @param $html
  * @return array|float|int|String
  */
 public static function parseHtml($conf, $html)
 {
     query::$defaultCharset = "utf-8";
     $doc = query::newDocument($html);
     query::selectDocument($doc);
     $value = self::queryValue(pq($doc), $conf);
     //清理内存
     query::unloadDocuments($doc);
     return $value;
 }
 /**
  * @return Feed
  */
 function parseMetadata()
 {
     $feed = new Feed();
     \phpQuery::newDocument($this->getText());
     $feed->setUrl($this->url);
     $feed->setTitle(pq('b.xcontrast_txt')->text());
     $feed->setAuthor(pq('a.xcontrast_txt:nth-child(5)')->text());
     $feed->setUpdatedDate(0);
     return $feed;
 }
Example #24
0
 /**
  * Initialize the phpQuery scraper for use.
  *
  * @param string $url
  *
  * @return void
  */
 protected function initScraper($url)
 {
     $ch = curl_init();
     curl_setopt($ch, CURLOPT_URL, $url);
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
     curl_setopt($ch, CURLOPT_TIMEOUT, 15);
     curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
     $response = curl_exec($ch);
     curl_close($ch);
     \phpQuery::newDocument($response);
 }
Example #25
0
 /**
  *
  */
 public function onAfterRender()
 {
     if (!$this->params->get('backwards_compat', false)) {
         return;
     }
     $app = JFactory::getApplication();
     if ($app->isAdmin()) {
         return;
     }
     // We want RokBox only on frontend
     $document = JFactory::getDocument();
     $doctype = $document->getType();
     if ($doctype == 'html') {
         $body = JResponse::getBody();
         if (!class_exists('phpQuery', false)) {
             require_once JPATH_PLUGINS . '/system/rokbox/lib/pq.php';
         }
         //$html = str_get_html($body);
         $pq = phpQuery::newDocument($body);
         foreach ($pq->find('a[rel^="rokbox"]') as $element) {
             $element = pq($element);
             $title = $element->attr('title');
             $rel = $element->attr('rel');
             preg_match("/\\((.+)\\)/", $rel, $album);
             $album = isset($album[1]) ? $album[1] : false;
             //preg_match("/\[(\d{1,})\s(\d{1,})\]\[module=(.+)\]/", $rel, $module);
             preg_match("/\\[module=(.+)\\]/", $rel, $module);
             $module = isset($module[1]) ? '#' . $module[1] : false;
             preg_match("/\\[(\\d{1,})\\s+(\\d{1,})\\]/", $rel, $size);
             $size = isset($size[1]) && isset($size[2]) ? $size[1] . ' ' . $size[2] : false;
             if (strlen($title)) {
                 @(list($title, $caption) = explode(' :: ', $title));
                 $caption = '<h4>' . $title . '</h4>' . (isset($caption) && strlen($caption) ? '<span>' . $caption . '</span>' : '');
             }
             $element->removeAttr('rel');
             $element->attr('data-rokbox', '');
             if ($title) {
                 $element->attr('data-rokbox-caption', $caption);
             }
             if ($album) {
                 $element->attr('data-rokbox-album', $album);
             }
             if ($module) {
                 $element->attr('data-rokbox-element', $module);
             }
             if ($size) {
                 $element->attr('data-rokbox-size', $size);
             }
         }
         JResponse::setBody($pq->getDocument()->htmlOuter());
         //$links = preg_match_all("|<a[^>]+rel\s*=\s*["']([^"']+)["'][^>]*>(.*?)<\/a>|i", $body, matches);
         //var_dump($this->getAttribute(, $body));
     }
 }
Example #26
0
 public function parseTest()
 {
     $html = file_get_contents('http://dmtoys.com.ua');
     $results = phpQuery::newDocument($html);
     $resultsA = pq($results)['img'];
     $dd = [];
     foreach ($resultsA as $key => $value) {
         $dd[]['href'] = pq($value)->attr('src');
     }
     phpQuery::unloadDocuments();
     return $dd;
 }
 /**
  * Will be triggered when the app's 'booting' event is triggered
  */
 public function launching()
 {
     /**
      * registering default commands
      */
     $this->with([self::PROVIDES_SERVICE], function (IBladedManager $manager) {
         $manager->registerCommandNamespace('scope', Scope::class);
         \phpQuery::newDocument();
         $manager->registerCommandNamespace('form', Form::class);
         $manager->registerCommandNamespace('template', Template::class);
     });
 }
Example #28
0
 private function parse($data)
 {
     $data = iconv('gbk', 'utf-8', $data);
     $data = tidy_repair_string($data);
     $doc = phpQuery::newDocument($data);
     foreach (pq('tr') as $index => $tr) {
         if ($index < 3) {
             continue;
         }
         $item = array('date' => pq($tr)->find('td:eq(0)')->text(), 'tag' => pq($tr)->find('td:eq(2)')->text(), 'number' => pq($tr)->find('td:eq(3)')->text());
         var_dump($item);
     }
 }
 public function getPageItems($html)
 {
     // @todo writre a comprehensive test case to verify the number of results found after revealing coommented elements.
     $doc = phpQuery::newDocument($html);
     $this->revealHiddenResults($doc);
     $items = $doc['.s-result-list .s-result-item'];
     $extracted = array();
     foreach ($items as $node) {
         $data = $this->basedata;
         $extracted[] = $this->extractItemData($node, $data);
     }
     return $extracted;
 }
Example #30
-5
function scrap_overstock_all($url, $id)
{
    $curl_result = get_web_page($url);
    if ($curl_result['http_code'] == 200) {
        $document = phpQuery::newDocument($curl_result['content']);
        $result['offerprice'] = str_replace('$', '', pq_get_first_text('span[itemprop=price]'));
        $result['prime'] = $result['quantity'] && $result['offerprice'] ? 'Yes' : 'No';
        $result['scrapok'] = true;
    } else {
        $result['scrapok'] = false;
    }
    return $result;
}