selectDocument() public static method

$id can be retrived via getDocumentID() or getDocumentIDRef().
public static selectDocument ( unknown_type $id )
$id unknown_type
function getAllSubCategories($filename)
{
    $categories = unserialize(file_get_contents($filename));
    echo "---- run getAllSubCategories() ----\n\r";
    foreach ($categories as $j => $category) {
        if ($category['childrens']) {
            foreach ($category['childrens'] as $k => $children) {
                echo "---- crawling childrens for {$children['name']} ----\n\r";
                $doc = phpQuery::newDocumentHTML(fetch('http://www.walmart.com' . $children['link']));
                phpQuery::selectDocument($doc);
                foreach (pq('.shop-by-category li') as $el) {
                    echo "---- " . pq($el)->find('a')->attr('href') . "} ----\n\r";
                    $childrens[] = array('name' => pq($el)->find('a')->data('name'), 'link' => pq($el)->find('a')->attr('href'));
                }
                $categories[$j]['childrens'][$k]['childrens'] = $childrens;
            }
        }
    }
    echo "---- creating deparment file ----\n\r";
    $file = fopen($filename, 'w+');
    echo "---- writing deparment file ----\n\r";
    fputs($file, serialize($categories));
    echo "---- closing deparment file ----\n\r";
    fclose($file);
}
 function theContent($content)
 {
     $doc = phpQuery::newDocumentHTML($content);
     phpQuery::selectDocument($doc);
     foreach (pq('a') as $link) {
         $linkurl = pq($link)->attr('href');
         $linkHostname = $this->getUrlHostname($linkurl);
         if ($linkHostname != FALSE) {
             if (!in_array($linkHostname, $this->blockedDomains)) {
                 $linkHash = md5($linkurl);
                 $query = "SELECT * FROM {$this->tableBitlyExternal} WHERE id='{$linkHash}'LIMIT 1;";
                 $linkData = $this->db->get_row($query, ARRAY_A);
                 if (empty($linkData)) {
                     $bitly = new Bitly($this->bitlyUsername, $this->bitlyApikey);
                     $shortURL = $bitly->shorten($linkurl);
                     $shortURLData = get_object_vars($bitly->getData());
                     if (!empty($shortURLData)) {
                         $linkData = array('id' => $linkHash, 'url' => $linkurl, 'short_url' => $shortURLData['shortUrl'], 'hash' => $shortURLData['userHash'], 'created' => current_time('mysql'));
                         $this->db->insert($this->tableBitlyExternal, $linkData);
                     }
                 }
                 if (!empty($linkData)) {
                     pq($link)->attr('href', $linkData['short_url']);
                 }
             }
         }
     }
     return $doc->htmlOuter();
 }
 function process() {
     if (!$this->processed) {
         $this->processed = true;
         $this->phpQueryDocument = phpQuery::newDocumentHTML($this->content);
         phpQuery::selectDocument($this->phpQueryDocument);
     }
 }
Example #4
0
function moegirl_analysis($text)
{
    $content = file_get_contents(moegirl_url($text));
    $doc = phpQuery::newDocumentHTML($content);
    phpQuery::selectDocument($doc);
    $ansList = pq(".NetDicBody");
    $ans = 0;
}
Example #5
0
function wikipedia_analysis($text)
{
    $content = file_get_contents(wikipedia_url($text));
    $doc = phpQuery::newDocumentHTML($content);
    phpQuery::selectDocument($doc);
    $ansList = pq(".NetDicBody");
    $ans = 0;
    return $doc;
}
Example #6
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;
 }
Example #7
0
 /**
  * Parse <a href="http://onesocialweb.org/spec/1.0/osw-vcard4.html">VCard4 over XMPP</a>.
  * @param String $xml
  */
 public function parseVCard($xml)
 {
     // TODO ACL
     $this->logger->debug("parseVCard: '{$xml}'");
     $doc = \phpQuery::newDocument($xml);
     \phpQuery::selectDocument($doc);
     $this->fn = pq('vcard fn text')->text();
     $this->note = pq('vcard note text')->text();
     $this->photo = pq('vcard photo uri')->text();
     $this->logger->debug("fn: '{$this->fn}'");
     $this->logger->debug("note: '{$this->note}'");
     $this->logger->debug("photo: '{$this->photo}'");
 }
Example #8
0
 /**
  * @see  HtmlComponent
  */
 public function Render()
 {
     // $template =
     $htmltag = $this->getTag();
     $template = WebApplication::getApplication()->getTemplate(get_class($this));
     $qid = \phpQuery::getDocumentID($htmltag);
     $doc = \phpQuery::newDocumentHTML($template);
     $htmltag->replaceWith($doc['body']->html());
     //$htmltag->html($doc['body']->html());
     \phpQuery::selectDocument($qid);
     $this->beforeRender();
     parent::RenderImpl();
     $this->afterRender();
 }
Example #9
0
function goo_analysis($text)
{
    $content = file_get_contents(goo_url($text));
    $doc = phpQuery::newDocumentHTML($content);
    phpQuery::selectDocument($doc);
    $ansList = pq("#NR-main > section > div > section:nth-child(2) > div > ul > li");
    $ans = 0;
    $ret = "<br />";
    //    echo $ret;
    foreach ($ansList as $li) {
        //        echo pq($li)->html().$ret;
        $ans++;
        //        echo "----------------------------------------------------------------";
    }
    return $ans;
}
Example #10
0
function weblio_analysis($text)
{
    $content = file_get_contents(weblio_url($text));
    $doc = phpQuery::newDocumentHTML($content);
    phpQuery::selectDocument($doc);
    $ansList = pq(".NetDicBody");
    $ans = 0;
    $ret = "<br />";
    //    echo $ret;
    foreach ($ansList as $li) {
        //        echo pq($li)->html().$ret;
        $ans++;
        //        echo "----------------------------------------------------------------";
    }
    return $ans;
}
Example #11
0
function hj_analysis($text)
{
    $content = file_get_contents(hj_url($text));
    $doc = phpQuery::newDocumentHTML($content);
    phpQuery::selectDocument($doc);
    $ansList = pq("#headword_div");
    $ans = array();
    $ret = "<br />";
    for ($i = 1; $i < 10; $i++) {
        $key = "#jpword_" . $i;
        $res = pq($doc)->find($key)->text();
        if ($res != '') {
            //            echo $key.$ret;
            //            echo "[$i]:>>".$res."<<".$ret;
            array_push($ans, $res);
        }
    }
    return sizeof($ans);
    //    return $content;
}
Example #12
0
 private function getWithPHPQuery($selectors)
 {
     require 'phpQuery/phpQuery.php';
     $content = file_get_contents($selectors['url']);
     $doc = phpQuery::newDocumentHTML($content);
     phpQuery::selectDocument($doc);
     $renders = [];
     $items = pq($selectors['item']);
     $items->each(function ($t) {
         if ($selectors['link'] == '.') {
             $item['title'] = pq($t)->text();
         } else {
             $item['title'] = pq($t)->find($selectors['title'])->text();
         }
         if ($selectors['link'] == '.') {
             $item['link'] = pg($t)->getAttribute('href');
         } else {
             $item['link'] = pg($t)->find($selectors['link'])->getAttribute('href');
         }
         $item['digest'] = pg($t)->find($selectors['description'])->text();
         $renders[] = $item;
     });
     return $renders;
 }
 $str = preg_replace(array('`[^a-z0-9]`i', '`[-]+`'), '-', $str);
 $str = strtolower(trim($str, '-'));
 if (!file_exists($filename . '.txt')) {
     $href = pq($el)->attr('href');
     $categorias[] = array('name' => pq($el)->text(), 'alias' => $str, 'url' => $href);
 } else {
     $categorias = unserialize(file_get_contents($filename . '.txt'));
     echo "File load it\n";
     foreach ($categorias as $children) {
         if (!file_exists(str_replace('links', 'customers', $filename) . '-' . $children['alias'] . '.txt')) {
             $links = array();
             echo "Children load it for url: {$children['url']}\n";
             $pages = ['', 'p-2/', 'p-3/', 'p-4/', 'p-5/', 'p-6/', 'p-7/', 'p-8/', 'p-9/', 'p-10/', 'p-11/', 'p-12/', 'p-13/', 'p-14/', 'p-15/', 'p-16/', 'p-17/', 'p-18/', 'p-19/', 'p-20/', 'p-21/', 'p-22/', 'p-23/', 'p-24/', 'p-25/', 'p-26/', 'p-27/', 'p-28/', 'p-29/', 'p-30/'];
             foreach ($pages as $page) {
                 $doc = phpQuery::newDocumentHTML(fetch($children['url'] . $page));
                 phpQuery::selectDocument($doc);
                 foreach (pq('ul.m-results-businesses > li') as $el) {
                     $email = pq($el)->find('.m-result-business--question-form-emails input[name=mailAnunciante]')->val();
                     if (empty($email)) {
                         $email = [];
                         foreach (pq($eq)->find('.m-result-business--question-form-emails select[name=mailAnunciante] option') as $option) {
                             $email[] = pq($option)->val();
                         }
                     }
                     $name = pq($el)->find('h3.itemprop=[name] a')->text();
                     $phone = pq($el)->find('p.itemprop=[telephone]')->text();
                     $website = pq($el)->find('.m-results-business--online a.itemprop=[url]')->attr('href');
                     $links[] = ['email' => $email, 'name' => $name, 'phone' => $phone, 'website' => $website];
                 }
             }
             $file = fopen(str_replace('links', 'customers', $filename) . '-' . $children['alias'] . '.txt', 'w+');
Example #14
0
 function search($q, $el = null)
 {
     switch ($this->parserType) {
         case 'simple':
             $doc = $el ? $this->parser->find('#' . $el) : $this->parser;
             $result = $doc->find($q);
             return $result;
         case 'phpquery':
             phpQuery::selectDocument($this->parser);
             $doc = $el ? pq($el) : $this->parser;
             return $doc->find($q);
         default:
             return $this->xpath->query($q, $el);
     }
 }
Example #15
0
    /**
     * Returns inbox of login or activities of given JID.
     *
     * @param string $jid
     * @param string $box 'inbox' or 'activities'
     */
    private function getAndParseActivities($jid, $box = 'activities')
    {
        $activities = array();
        $node = 'urn:xmpp:microblog:0';
        if ('inbox' == $box) {
            $node = 'http://onesocialweb.org/spec/1.0/inbox';
        }
        /*
                 <iq type="error" id="get1" from="alice@example.org/client" to="bob@example.org/work"><pubsub xmlns="http://jabber.org/protocol/pubsub">
          <items node="urn:xmpp:microblog:0"/>
        </pubsub><error code="503" type="cancel"><service-unavailable xmlns="urn:ietf:params:xml:ns:xmpp-stanzas"/></error></iq>
        */
        $payload = <<<EOD
<pubsub xmlns='http://jabber.org/protocol/pubsub'>
  <items node='{$node}'/>
</pubsub>
EOD;
        $id = $this->idCount++;
        $this->sendIQ($id, $payload, 'get', null, $jid);
        $this->read('iq', $id);
        $stanza = $this->stanzaParser->removeStanza('iq', $id);
        $xml = $stanza->__toString();
        $doc = \phpQuery::newDocument($xml);
        \phpQuery::selectDocument($doc);
        foreach (pq('iq pubsub items item') as $item) {
            $a = new Activity();
            $a->id = pq($item)->attr('id');
            // TODO Check
            $entry = pq($item)->find('entry');
            $a->title = pq($entry)->find('title')->text();
            $a->actor = pq($entry)->find('actor uri')->text();
            $a->inReplyTo = pq($entry)->find('in-reply-to')->attr('href');
            $a->published = pq($entry)->find('published')->text();
            if (!\is_null($a->published)) {
                $a->published = \strtotime($a->published);
            }
            $type = pq($entry)->find('acl-rule acl-subject:first')->attr('type');
            // TODO Read all rules
            $name = pq($entry)->find('acl-rule acl-subject:first')->text();
            switch ($type) {
                case Activity::$EVERYONE:
                    $a->viewable = 'Everyone';
                    $a->toType = Activity::$EVERYONE;
                    break;
                case Activity::$GROUP:
                    $a->viewable = "Group: {$name}";
                    $a->toType = Activity::$GROUP;
                    $a->to = $name;
                    break;
                case Activity::$PERSON:
                    $a->viewable = "Person: {$name}";
                    $a->toType = Activity::$PERSON;
                    $a->to = $name;
                    break;
                default:
                    $a->viewable = "Unknown T: '{$type}' N: '{$name}'";
                    $this->logger->error($a->viewable);
                    break;
            }
            // switch($type)
            $activities[] = $a;
        }
        // foreach(pq('iq pubsub items item') as $item)
        return $activities;
    }
Example #16
0
 /**
  * Return the matching nodes of the expression (xpath or css)
  * @param string $query the expression to search for 
  * @param string $dom the context to search
  * @return DomNodeList|phpQueryObject|SimpleHtmlDom
  */
 public function search($query, $dom = null)
 {
     if ($this->is_xpath($query)) {
         return $dom ? $this->xpath->query($query, $dom) : $this->xpath->query($query);
     }
     switch ($this->parserType) {
         case 'simple':
             $doc = $dom ? $dom : $this->parser;
             return $doc->find($query);
         case 'phpquery':
             phpQuery::selectDocument($this->parser);
             $doc = $dom ? pq($dom) : $this->parser;
             return $doc->find($query);
         default:
             return $this->xpath->query($query, $dom);
     }
 }
Example #17
0
function wpws_parse_byselector($scrap, $url, $selector, $wpwsopt)
{
    global $wpdb;
    $currcharset = get_bloginfo('charset');
    require_once 'includes/phpQuery-onefile.php';
    $doc = phpQuery::newDocumentHTML($scrap, $currcharset);
    phpQuery::selectDocument($doc);
    if ($wpwsopt['output'] == 'text') {
        $output = pq($selector)->text();
    }
    if ($wpwsopt['output'] == 'html') {
        $output = pq($selector)->html();
    }
    if (!empty($wpwsopt['clear_regex'])) {
        $output = preg_replace($wpwsopt['clear_regex'], '', $output);
    }
    if (!empty($wpwsopt['replace_regex'])) {
        $output = preg_replace($wpwsopt['replace_regex'], $wpwsopt['replace_with'], $output);
    }
    if (!empty($wpwsopt['basehref'])) {
        $output = preg_replace('#(href|src)="([^:"]*)("|(?:(?:%20|\\s|\\+)[^"]*"))#', '$1="' . $wpwsopt['basehref'] . '$2$3', $output);
    }
    if (!empty($wpwsopt['striptags'])) {
        $output = wpws_strip_only($output, $wpwsopt['striptags']);
    }
    if (!empty($wpwsopt['htmldecode'])) {
        $output = iconv($wpwsopt['htmldecode'], $currcharset, $output);
    }
    if (empty($output) && $wpwsopt['debug'] == 1) {
        $header = wpws_HEADER . "<!--Warning: Your selector returned an empty string-->";
    } else {
        $header = wpws_HEADER;
    }
    return $header . trim($output) . wpws_FOOTER;
}
Example #18
0
 /**
  * Injects Insert Tags input box and drop down menu to adminForm
  *
  * @access	public
  * @since	1.5
  */
 function onAfterRender()
 {
     //SELECT WHERE I AM ******
     if (!JFactory::getApplication()->isAdmin()) {
         $option = JRequest::getCmd('option', '');
         $view = JRequest::getCmd('view', '');
         if ($option == 'com_content' && $view == 'category') {
             // your processing code here
             $body = JResponse::getBody();
             //JResponse::setBody("saa");
             //TODO WRITE A FIELDS TO CATEGORY EDIT CONTENT ========================
             //$this->addFieldsInCategory();
             //$body = $this->onAfterRenderCategory($body);
             return;
         }
     }
     $body = JResponse::getBody();
     //$model = JController::getInstance("com_content");
     //$state = $model->getModel();
     //$dd = $state->getState("filter.category_id");
     // $state->state->get('filter.category_id');
     $writed = false;
     $id = JRequest::getVar('id');
     $str = '';
     $str_options = '';
     $exist = false;
     $exist_options = false;
     $idgroup = 0;
     $editor =& JFactory::getEditor();
     $oneclicksave = $this->params->get('oneclicksave', 1);
     //Experimental ***************************************  ****************
     if ($oneclicksave == 1 || !empty($id)) {
         //EDIT ARTICLE =====================================================================
         if (!$id) {
             $cid = JRequest::getVar('cid', array(), '', 'array');
             @($id = $cid[0]);
             $view = JRequest::getVar('view');
             if ($view == 'article') {
                 $path = '';
             } else {
                 $path = '..' . DS;
             }
         }
         $task = JRequest::getVar('task');
         $option = JRequest::getVar('option');
         $id = JRequest::getVar('id', JRequest::getVar('a_id'));
         $view = JRequest::getVar('view');
         $layout = JRequest::getVar('layout');
         $pos = strrpos(JPATH_BASE, "administrator");
         $user =& JFactory::getUser();
         //***********************************************************************************************
         //Where we are  ****************  ****************  ****************
         //***********************************************************************************************
         $fontend = false;
         if ($option == 'com_content' && $user->get('id') > 0 && $view == 'form' && $layout == 'edit') {
             $fontend = true;
         }
         $backend = false;
         if ($option == 'com_content' && !empty($pos) && $layout == 'edit') {
             $backend = true;
         }
         $backendcategory = false;
         if (JRequest::getVar('option') == 'com_categories' && JRequest::getVar('view') == "category" && JRequest::getVar('extension') == "com_content") {
             $backendcategory = true;
             $backend = true;
         }
         //EDIT FRONTEND
         if ($fontend && $view == "form") {
             //echo "el id".$id."<br>";
             $id = JRequest::getVar('a_id');
         }
         //***********************************************************************************************
         //If we are in admin content edit or frontend edit   ****************  ****************
         //***********************************************************************************************
         if ($backend || $fontend) {
             $body = str_replace('method="post"', 'method="post" enctype="multipart/form-data" ', $body);
             //DELETE DE ERROR WRONG
             //$body = str_replace('<li>Save failed with the following error: </li>',   '' , $body);
             //$body .= '<style>.message ul li:last-of-type {display: none;} .message ul li:first-of-type {display: block;}</style>';
             //Plugin control for the no insert new rows ****************
             //Author: giuppe
             //**********************************************************
             if (empty($id)) {
                 //***********************************************************************************************
                 //If NEW Redirect  ****************  ****************
                 //***********************************************************************************************
                 if ($backend && !$backendcategory) {
                     $id = $this->getlastId();
                     JError::raiseWarning(100, "CREAR DIR::: " . $id . " -- " . JRequest::getVar("id"));
                     if (!empty($id)) {
                         $url = JURI::base() . "index.php?option=com_content&task=article.edit&id=" . $id;
                         echo "<script>document.location.href='" . $url . "';</script>\n";
                     }
                 }
                 if ($fontend) {
                     $id = $this->getlastId();
                     JError::raiseWarning(100, "CREAR DIR2::: " . $id . " -- " . JRequest::getVar("id"));
                     if (!empty($id)) {
                         //base64_encode($uri)
                         //$uri = $_SERVER["HTTP_REFERER"];
                         $user = JFactory::getUser();
                         $userId = $user->get('id');
                         $uri = JFactory::getURI();
                         $uri = 'index.php?option=com_content&task=article.edit&a_id=' . $id;
                         $app = JFactory::getApplication();
                         $app->setUserState('com_content.edit.article.id', $id);
                         $url = JURI::base() . "index.php?option=com_content&view=form&layout=edit&a_id=" . $id . "&Itemid=" . JRequest::getVar("Itemid") . "&return=" . base64_encode($uri);
                         $button = JHtml::_('link', JRoute::_($url), "TESTO");
                         echo "<script>document.location.href='" . $url . "';</script>\n";
                         //header('Location: '.$url);
                         //JApplication::redirect($url);
                     }
                 }
             }
             //***********************************************************************************************
             //create array of fields  ****************  ****************  ****************
             //***********************************************************************************************
             $fields = array();
             $fields = $this->fields;
             /*if($backendcategory)
             		{
             			if(!empty($id))
             			{
             			    $fields_tmp0 = fieldsattachHelper::getfieldsForAllCategory($id);
             			    $fields = fieldsattachHelper::getfieldsCategory($id);
             			    $fields = array_merge($fields_tmp0, $fields);
             			}
             		   
             		}else{
             		       
             			$fields_tmp0 = fieldsattachHelper::getfieldsForAll($id);
             			//$fields_tmp1 = $this->getfields($id); 
             			$fields_tmp1 = fieldsattachHelper::getfields($id);
             			$fields_tmp1 = array_merge($fields_tmp0, $fields_tmp1);
                 
             			
             			$fields_tmp2 = fieldsattachHelper::getfieldsForArticlesid($id, $fields_tmp1); 
             			$fields = array_merge($fields_tmp1, $fields_tmp2);
             			//$fields = $fields_tmp0;
             		}*/
             //***********************************************************************************************
             //create HTML  with new extra fields  ****************  ****************  ****************
             //***********************************************************************************************
             //include('lib/QueryPath-2.1.1/php/QueryPath/QueryPath.php');
             include 'lib/phpQuery-onefile.php';
             //For j3.0
             //include('lib/ganon.php'); //For j3.1.1 o highter
             $menuTabstr = "";
             if (count($fields) > 0) {
                 $helper = new fieldsattachHelper();
                 $helper->body = $body;
                 $helper->menuTabstr = $str;
                 $helper->str = $str;
                 $helper->str_options = $str_options;
                 //$helper->getinputfields($id, $fields, $backend, $fontend, $backendcategory, $exist_options, &$body,  &$str, &$str_options);
                 $helper->getinputfields($id, $fields, $backend, $fontend, $backendcategory, $exist_options);
                 $str = $helper->str;
                 $menuTabstr = $helper->menuTabstr;
                 //$body =  $helper->body;
                 $exist = $helper->exist;
                 $exist_options = $helper->exist_options;
             }
             //Javascript for reorder li *************
             /*$script = '<script>jQuery(document).ready(function() { jQuery("#myTabTabs").append(jQuery("li.addtab"));
             			jQuery("#myTabTabs li:first").after( jQuery("li.addtab") );
             		});</script>';*/
             if (version_compare(JVERSION, '3.1', '>') == 1) {
                 if ($fontend) {
                     $options = array('replace_entities' => TRUE, 'ignore_parser_warnings' => TRUE);
                     //Load Document
                     $doc = phpQuery::newDocument($body);
                     phpQuery::selectDocument($doc);
                     //Find element
                     pq('.nav-tabs li:first-child')->append($menuTabstr);
                     //Backend
                     if ($backend) {
                         pq('#general')->after($str);
                     }
                     if ($backendcategory) {
                         pq('#details')->after($str);
                     }
                     //Front end
                     if ($fontend) {
                         if (pq("#editor")->length) {
                             pq('#editor')->after($str);
                             // element exists
                         } else {
                             $str = '</fieldset><fieldset><legend>' . strip_tags($menuTabstr) . '</legend>' . $str . '';
                             pq('#adminForm #editor-xtd-buttons')->after($str);
                         }
                     }
                     //Return HTML
                     $body = pq('')->htmlOuter();
                 } else {
                     //Go to beforeRender
                 }
             } else {
                 //echo "running Joomla! 3.0";
                 $options = array('replace_entities' => TRUE, 'ignore_parser_warnings' => TRUE);
                 //Load Document
                 $doc = phpQuery::newDocument($body);
                 phpQuery::selectDocument($doc);
                 //Find element
                 pq('.nav-tabs li:first-child')->append($menuTabstr);
                 if ($backend) {
                     pq('#general')->after($str);
                 }
                 if ($fontend) {
                     pq('#editor')->after($str);
                 }
                 if ($backendcategory) {
                     pq('#details')->after($str);
                 }
                 //Return HTML
                 $body = pq('')->htmlOuter();
             }
             //if($fontend) $html('#editor')->after($str);
             //if($backendcategory) $html('#details')->after($str);
             //$html->find('#myTabTabs')->append($menuTabstr);
         }
     }
     //END Experimental ***************************************  ****************
     if (!$writed) {
         JResponse::setBody($body);
     } else {
         JResponse::setBody("");
     }
 }
function getSubcategorias($url)
{
    $doc = phpQuery::newDocumentHTML(fetch($url));
    phpQuery::selectDocument($doc);
    foreach (pq('.listc li h2 a') as $el) {
        $url = 'http://www.pac.com.ve' . pq($el)->attr('href');
        if (strpos($url, '&ubicacion=')) {
            $href = substr($url, 0, strpos($url, '&ubicacion='));
        } else {
            $href = $url;
        }
        echo 'LINEA ' . __LINE__ . ': ' . $url . "\n";
        echo 'LINEA ' . __LINE__ . ': ' . $href . "\n";
        $subcategorias[] = array('name' => pq($el)->text(), 'url' => $href, 'childrens' => getSubcategorias($href));
    }
    return isset($subcategorias) ? $subcategorias : null;
}
 /**
  * Returns document with id $id or last used as phpQueryObject.
  * $id can be retrived via getDocumentID() or getDocumentIDRef().
  * Chainable.
  *
  * @see phpQuery::selectDocument()
  * @param unknown_type $id
  * @return phpQueryObject|queryTemplatesFetch|queryTemplatesParse|queryTemplatesPickup
  */
 public static function getDocument($id = null)
 {
     if ($id) {
         phpQuery::selectDocument($id);
     } else {
         $id = phpQuery::$defaultDocumentID;
     }
     return new phpQueryObject($id);
 }
<?php

require_once dirname(__FILE__) . '/../phpQuery.php';
echo __LINE__;
$html = file_get_contents('http://paginasamarillas.infoguia.net/PagAm/PagAm.asp?key=instrumentos-musicales-caracas&cat=752&ciud=41#21101464');
$pq = phpQuery::newDocument($html);
phpQuery::selectDocument($html);
echo __LINE__;
var_dump($pq);
echo __LINE__;
foreach (pq('.menu_aviso') as $link) {
    if (!strpos('?emp=')) {
        continue;
    }
    var_dump($link);
    echo pq($link)->attr('href') . '<br />';
}
echo __LINE__;
//('.menu_contactar').data('mail')
echo __LINE__;
/**
 * Get HTML from a web page using selector
 * @param string $raw_html Raw HTML
 * @param string $selector Selector
 * @param string $output html or text
 * @return string
 */
function wpws_get_html_by_selector($raw_html, $selector, $output = 'html'){
    // Parsing request using phpQuery
    $currcharset = get_bloginfo('charset');
    require_once 'phpQuery-onefile.php';
    $phpquery = phpQuery::newDocumentHTML($raw_html, $currcharset);
    phpQuery::selectDocument($phpquery);
    if($output == 'text')
        return pq($selector)->text();
    if($output == 'html')
        return pq($selector)->html();
    if( empty($output) )
        return new WP_Error('wpws_get_html_by_selector_failed', "Error parsing selector: $selector");
}
Example #23
0
 function setParser($parserType, $html)
 {
     switch (true) {
         case preg_match('/zend/i', $parserType):
             $this->parserType = 'zend';
             $this->parser = new Zend_Dom_Query();
             @$this->parser->setDocumentHtml($html);
             break;
         case preg_match('/simple/i', $parserType):
             $this->parserType = 'simple';
             $this->parser = new Default_Plugin_SimpleHtmlDom($html);
             break;
         case preg_match('/phpquery/i', $parserType):
             //                require_once("phpQuery.php");
             require_once "phpQuery-onefile.php";
             $this->parserType = 'phpquery';
             $this->parser = phpQuery::newDocumentHTML($html, $this->client->charset);
             phpQuery::selectDocument($this->parser);
             break;
         default:
             $this->parserType = 'xpath';
             $this->parser = $this->xpath;
             break;
     }
 }
 /**
  * Enter description here...
  *
  * @param unknown_type $html
  * @param unknown_type $domId
  * @return unknown New DOM ID
  * @todo support PHP tags in input
  * @todo support passing DOMDocument object from self::loadDocument
  */
 protected static function createDocumentWrapper($html, $contentType = null, $documentID = null)
 {
     if (function_exists('domxml_open_mem')) {
         throw new Exception("Old PHP4 DOM XML extension detected. phpQuery won't work until this extension is enabled.");
     }
     //		$id = $documentID
     //			? $documentID
     //			: md5(microtime());
     $document = null;
     if ($html instanceof DOMDOCUMENT) {
         if (self::getDocumentID($html)) {
             // document already exists in phpQuery::$documents, make a copy
             $document = clone $html;
         } else {
             // new document, add it to phpQuery::$documents
             $wrapper = new DOMDocumentWrapper($html, $contentType, $documentID);
         }
     } else {
         $wrapper = new DOMDocumentWrapper($html, $contentType, $documentID);
     }
     //		$wrapper->id = $id;
     // bind document
     phpQuery::$documents[$wrapper->id] = $wrapper;
     // remember last loaded document
     phpQuery::selectDocument($wrapper->id);
     return $wrapper->id;
 }
Example #25
0
 function notify_header_addonmodules_print_layout_main()
 {
     global $main;
     global $addonmodules_print_layout_main_content;
     $addonmodules_print_layout_main_content = str_replace(CHARSET, "UTF-8", $addonmodules_print_layout_main_content);
     $addonmodules_print_layout_main_content = mb_convert_encoding($addonmodules_print_layout_main_content, "UTF-8", mb_internal_encoding());
     // DOMDocumentがjavascriptをうまく処理できないので
     // 適当に置き換えてみる
     preg_match_all("/(<script.*?>.*?<\\/script>)/is", $addonmodules_print_layout_main_content, $match);
     foreach ($match[1] as $k => $v) {
         $addonmodules_print_layout_main_content = str_replace($v, self::replace_key($k), $addonmodules_print_layout_main_content);
     }
     $addonmodules_print_layout_main_content = str_replace("&nbsp;", "%NBSP%", $addonmodules_print_layout_main_content);
     $doc = phpQuery::newDocumentHTML($addonmodules_print_layout_main_content, "UTF-8");
     phpQuery::selectDocument($doc);
     if (is_array($main)) {
         foreach ($main as $v) {
             $css_selector = $v['css_selector'];
             $insert_position = $v['insert_position'];
             $contents = $v['contents'];
             if ($css_selector != "") {
                 if ($insert_position == "append") {
                     pq($css_selector)->append($contents);
                 } else {
                     if ($insert_position == "prepend") {
                         pq($css_selector)->prepend($contents);
                     } else {
                         if ($insert_position == "after") {
                             pq($css_selector)->after($contents);
                         } else {
                             if ($insert_position == "before") {
                                 pq($css_selector)->before($contents);
                             } else {
                                 if ($insert_position == "replaceWith") {
                                     pq($css_selector)->replaceWith($contents);
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     $out = $doc->getDocument()->getDOMDocument()->saveHTML();
     // 置き換えたのを戻す
     foreach ($match[1] as $k => $v) {
         $out = str_replace(self::replace_key($k), $v, $out);
     }
     $out = str_replace("%NBSP%", "&nbsp;", $out);
     $out = str_replace("UTF-8", CHARSET, $out);
     $out = mb_convert_encoding($out, mb_internal_encoding(), "UTF-8");
     $addonmodules_print_layout_main_content = $out;
 }