Exemplo n.º 1
2
 /**
  * @param $numero
  * @return array
  * @throws \Exception
  */
 public function consulta($numero)
 {
     $numero = str_replace(['-', '(', ')', '*', ' '], '', $numero);
     $curl = new Curl();
     $data = ['numero' => $numero];
     $html = $curl->simple('https://www.qual-operadora.net/', $data);
     #dd($html);
     phpQuery::newDocumentHTML($html, $charset = 'utf-8');
     $pesquisa = [];
     foreach (phpQuery::pq('#modulo-consulta-operadora #consulta_num') as $pqDiv) {
         $dados = [];
         $dados['operadoraTipo'] = explode('-', str_replace([' ', ':'], '', trim(phpQuery::pq('table span.verde:first', $pqDiv)->text())));
         if (isset($dados['operadoraTipo'][0])) {
             $dados['operadora'] = $dados['operadoraTipo'][0];
         }
         if (isset($dados['operadoraTipo'][1])) {
             $dados['tipo'] = $dados['operadoraTipo'][1];
             unset($dados['operadoraTipo']);
         }
         $dados['portabilidade'] = preg_replace('/[áàãâä]/ui', 'a', str_replace([' ', ':'], '', trim(phpQuery::pq('table span.verde:last', $pqDiv)->text())));
         $dados['dataPortabilidade'] = preg_replace('/[áàãâä]/ui', 'a', str_replace([' ', ':'], '', trim(phpQuery::pq('h2 span.verde:last', $pqDiv)->text())));
         $dados['numero'] = trim(phpQuery::pq('input:[name="numero"]', $pqDiv)->val());
         $pesquisa = $dados;
     }
     return $pesquisa;
 }
Exemplo n.º 2
0
    protected function doRemoveNamespacedNodes(&$pq)
    {
        $xsl = <<<____EOF
      <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" exclude-result-prefixes="xsl">
          <xsl:template match="*[local-name()=name()]">
              <xsl:element name="{local-name()}">
                  <xsl:apply-templates select="@* | node()"/>
              </xsl:element>
          </xsl:template>
          <xsl:template match="@* | text()">
              <xsl:copy/>
          </xsl:template>
      </xsl:stylesheet>
____EOF;
        $xsl = \DOMDocument::loadXml($xsl);
        $proc = new \XSLTProcessor();
        $proc->importStyleSheet($xsl);
        $pq->document = $proc->transformToDoc($pq->document);
        for ($i = $pq->document->documentElement->attributes->length; $i >= 0; --$i) {
            $attr = $pq->document->documentElement->attributes->item($i);
            if (substr($attr->name, 0, 6) === 'xmlns:') {
                $pq->document->documentElement->removeAttributeNode($attr);
            }
        }
        $pq = PhpQuery::newDocumentHTML($pq->document->saveHTML());
        return $this;
    }
Exemplo n.º 3
0
 public function render()
 {
     $args = $this->arguments;
     PhpQuery::newDocument();
     $this->markup = PhpQuery::pq($this->template);
     $label = $this->markup['label'];
     $textarea = $this->markup['textarea'];
     $description = $this->markup['.help-block'];
     foreach ($args as $key => $arg) {
         switch ($key) {
             case 'class':
                 $textarea->addClass($arg);
                 break;
             case 'label':
                 $label->removeClass('hidden')->html($arg);
                 break;
             case 'description':
                 $description->html($arg);
                 break;
             case 'value':
                 $textarea->html($arg);
                 break;
             case 'id':
                 $label->attr('for', $arg);
                 // pass to default
             // pass to default
             default:
                 $textarea->attr($key, $arg);
                 break;
         }
     }
     return parent::render();
 }
Exemplo n.º 4
0
 public function render()
 {
     $args = $this->arguments;
     PhpQuery::newDocument();
     $this->markup = PhpQuery::pq($this->template);
     $label = $this->markup['label'];
     $select = $this->markup['select'];
     // label
     if (isset($args['label'])) {
         $label->removeClass('hidden')->html($args['label']);
     }
     // id
     if (isset($args['id'])) {
         $label->attr('for', $args['id']);
         $select->attr('id', $args['id']);
     }
     // name
     if (isset($args['name'])) {
         $select->attr('name', $args['name']);
     }
     $menus = XeMenu::getAll(XeSite::getCurrentSiteKey());
     foreach ($menus as $menu) {
         $option = PhpQuery::pq('<option></option>');
         $option->appendTo($select)->attr('value', $menu->id)->html($menu->title);
         if (isset($args['selected']) && $menu->id == $args['selected']) {
             $option->attr('selected', 'selected');
         } elseif (isset($args['value']) && $menu->id == $args['value']) {
             $option->attr('selected', 'selected');
         }
     }
     return parent::render();
 }
Exemplo n.º 5
0
 public function render()
 {
     $args = $this->arguments;
     PhpQuery::newDocument();
     $this->markup = PhpQuery::pq($this->template);
     $label = $this->markup['label'];
     $input = $this->markup['input'];
     foreach ($args as $key => $arg) {
         switch ($key) {
             case 'class':
                 $input->addClass($arg);
                 break;
             case 'label':
                 $label->removeClass('hidden')->html($arg);
                 break;
             case 'id':
                 $label->attr('for', $arg);
                 // pass to default
             // pass to default
             default:
                 $input->attr($key, $arg);
                 break;
         }
     }
     return parent::render();
 }
Exemplo n.º 6
0
 public function render()
 {
     $args = $this->arguments;
     PhpQuery::newDocument();
     $this->markup = PhpQuery::pq($this->template);
     $labelEl = $this->markup['label'];
     $selectEl = $this->markup['select'];
     $selectedValue = array_get($args, 'selected', null);
     if ($selectedValue === null) {
         $selectedValue = array_get($args, 'value', null);
     }
     foreach ($args as $key => $arg) {
         switch ($key) {
             case 'class':
                 $selectEl->addClass($arg);
                 break;
             case 'label':
                 $labelEl->removeClass('hidden')->html($arg);
                 break;
             case 'options':
                 $options = $arg;
                 if (is_callable($options)) {
                     $options = $options();
                 }
                 foreach ($options as $value => $option) {
                     if (is_array($option) === false) {
                         $text = $option;
                         if (is_string($value) === false) {
                             $value = $option;
                         }
                         $selected = '';
                     } else {
                         $value = array_get($option, 'value', $value);
                         $text = array_get($option, 'text', $value);
                     }
                     if ($selectedValue === null) {
                         $selected = array_get($option, 'selected', false) ? 'selected="selected"' : '';
                     } else {
                         $selected = $value === $selectedValue ? 'selected="selected"' : '';
                     }
                     $optionEl = PhpQuery::pq("<option value=\"{$value}\" {$selected} \">{$text}</option>");
                     $selectEl->append($optionEl);
                 }
                 break;
             case 'id':
                 $labelEl->attr('for', $arg);
                 // pass to default
             // pass to default
             default:
                 if (is_string($arg)) {
                     $selectEl->attr($key, $arg);
                 }
                 break;
         }
     }
     return parent::render();
 }
 /**
  * UIObject가 출력될 때 호출되는 메소드이다.
  *
  * @return string
  */
 public function render()
 {
     if (is_callable($this->callback)) {
         $callback = $this->callback;
         if ($this->markup === null) {
             PhpQuery::newDocument();
             $this->markup = PhpQuery::pq($this->template);
         }
         $callback($this->markup);
     }
     return $this->markup === null ? $this->template : $this->markup;
 }
Exemplo n.º 8
0
 /**
  * Enter description here...
  *
  * @param \PhpQuery\PhpQueryObject $self
  * @param                          $arg1
  * @return null|\PhpQuery\PhpQueryObject
  */
 public static function script($self, $arg1)
 {
     $params = func_get_args();
     $params = array_slice($params, 2);
     $return = null;
     $config = self::$config;
     if (\PhpQuery\Plugin\UtilScripts::$scriptMethods[$arg1]) {
         PhpQuery::callbackRun(\PhpQuery\Plugin\UtilScripts::$scriptMethods[$arg1], array($self, $params, &$return, $config));
     } else {
         if ($arg1 != '__config' && file_exists(dirname(__FILE__) . "/Scripts/{$arg1}.php")) {
             PhpQuery::debug("Loading script '{$arg1}'");
             require dirname(__FILE__) . "/Scripts/{$arg1}.php";
         } else {
             PhpQuery::debug("Requested script '{$arg1}' doesn't exist");
         }
     }
     return $return ? $return : $self;
 }
Exemplo n.º 9
0
 public function render()
 {
     $args = $this->arguments;
     PhpQuery::newDocument();
     $this->markup = PhpQuery::pq($this->template);
     $label = $this->markup['label'];
     $this->box = $this->markup['.checkbox'];
     $checkboxes = array_get($args, 'checkboxes');
     $nameGlobal = array_get($args, 'name');
     $labelText = array_get($args, 'label');
     if ($labelText !== null) {
         $label->removeClass('hidden')->html($labelText);
     }
     // checkbox가 따로 있을 경우
     if ($checkboxes !== null) {
         foreach ((array) $checkboxes as $arg) {
             $checkboxObj = PhpQuery::pq("<label class=\"checkbox-inline\"><input type=\"checkbox\"><span></span></label>");
             $arg = array_add($arg, 'name', $nameGlobal . '[]');
             $this->appendCheckbox($checkboxObj, $arg);
         }
         // checkbox가 따로 없을 경우
     } else {
         $checkboxObj = PhpQuery::pq("<input type=\"checkbox\">");
         foreach ($args as $key => $arg) {
             switch ($key) {
                 case 'class':
                     $checkboxObj->addClass('class', $arg);
                     break;
                 case 'id':
                     $label->attr('for', $arg);
                     // pass to default
                 // pass to default
                 default:
                     $checkboxObj->attr($key, $arg);
                     break;
             }
         }
     }
     return parent::render();
 }
Exemplo n.º 10
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
 }
Exemplo n.º 11
0
 /**
  * @param PhpQueryObject $pq
  * @dataProvider provider
  * @return void
  */
 public function testCssParser()
 {
     PhpQuery::$enableCssShorthand = FALSE;
     $expected_html = '<div style="color:red;display:none;margin:20px;padding:10px"><span>Hello World!</span></div>';
     $expected_pq = PhpQuery::newDocumentHTML($expected_html);
     $test_pq = PhpQuery::newDocumentHTML('<div style="margin:10px; padding:10px">');
     $test = pq('div');
     $test->append('<span>Hello World!</span>');
     $test->hide();
     $test->css('color', 'red');
     $test->css('margin', '20px');
     $this->assertEqualXMLStructure($expected_pq->find('div')->elements[0], $test->elements[0]);
 }
Exemplo n.º 12
0
 /**
  * UIObject가 출력될 때 호출되는 메소드이다.
  *
  * @return string
  */
 public function render()
 {
     if (is_callable($this->callback)) {
         $callback = $this->callback;
         if ($this->markup === null) {
             PhpQuery::newDocument();
             $this->markup = PhpQuery::pq($this->template);
         }
         $callback($this->markup);
     }
     $viewStr = $this->markup === null ? $this->template : (string) $this->markup;
     return new Expression($viewStr);
 }
Exemplo n.º 13
0
 /**
  * Enter description here...
  *
  * @param \DOMNode|PhpQueryObject|string $document
  * @param                                $node
  * @param string                         $type
  * @param                                $callback
  *
  * @TODO namespace events
  * @TODO support more than event in $type (space-separated)
  */
 public static function remove($document, $node, $type = null, $callback = null)
 {
     $documentID = PhpQuery::getDocumentID($document);
     $eventNode = self::getNode($documentID, $node);
     if (is_object($eventNode) && isset($eventNode->eventHandlers[$type])) {
         if ($callback) {
             foreach ($eventNode->eventHandlers[$type] as $k => $handler) {
                 if ($handler['callback'] == $callback) {
                     unset($eventNode->eventHandlers[$type][$k]);
                 }
             }
         } else {
             unset($eventNode->eventHandlers[$type]);
         }
     }
 }
Exemplo n.º 14
0
 public function rastrear($codigo)
 {
     $curl = new Curl();
     $html = $curl->simple('http://websro.correios.com.br/sro_bin/txect01$.QueryList?P_LINGUA=001&P_TIPO=001&P_COD_UNI=' . $codigo);
     phpQuery::newDocumentHTML($html, $charset = 'utf-8');
     $rastreamento = array();
     $c = 0;
     foreach (phpQuery::pq('tr') as $tr) {
         $c++;
         if (count(phpQuery::pq($tr)->find('td')) == 3 && $c > 1) {
             $rastreamento[] = array('data' => phpQuery::pq($tr)->find('td:eq(0)')->text(), 'local' => phpQuery::pq($tr)->find('td:eq(1)')->text(), 'status' => phpQuery::pq($tr)->find('td:eq(2)')->text());
         }
         if (count(phpQuery::pq($tr)->find('td')) == 1 && $c > 1) {
             $rastreamento[count($rastreamento) - 1]['encaminhado'] = phpQuery::pq($tr)->find('td:eq(0)')->text();
         }
     }
     if (!count($rastreamento)) {
         return false;
     }
     return $rastreamento;
 }
Exemplo n.º 15
0
 public static function debug($text)
 {
     phpQuery::debug($text);
 }
Exemplo n.º 16
0
 private function wrapInput($name, $input)
 {
     $classname = 'form-col-' . str_replace([' ', '.'], '-', $name);
     return PhpQuery::pq('<div class="col-md-6 ' . $classname . '">' . (string) $input . '</div>');
 }
Exemplo n.º 17
0
 /**
  * Enter description here...
  *
  * @TODO trigger submit for form after form's  submit button has a click event
  * @param      $e
  * @param null $callback
  */
 public static function handleSubmit($e, $callback = null)
 {
     $node = PhpQuery::pq($e->target);
     if (!$node->is('form') || !$node->is('[action]')) {
         return;
     }
     // TODO document.location
     $xhr = isset($node->document->xhr) ? $node->document->xhr : null;
     $submit = pq($e->relatedTarget)->is(':submit') ? $e->relatedTarget : $node->find('*:submit:first')->get(0);
     $data = array();
     foreach ($node->serializeArray($submit) as $r) {
         // XXXt.c maybe $node->not(':submit')->add($sumit) would be better ?
         //		foreach($node->serializeArray($submit) as $r)
         $data[$r['name']] = $r['value'];
     }
     $options = array('type' => $node->attr('method') ? $node->attr('method') : 'GET', 'url' => resolve_url($e->data[0], $node->attr('action')), 'data' => $data, 'referer' => $node->document->location);
     if ($node->attr('enctype')) {
         $options['contentType'] = $node->attr('enctype');
     }
     $xhr = PhpQuery::ajax($options, $xhr);
     if ((!$callback || !$callback instanceof Callback) && $e->data[1]) {
         $callback = $e->data[1];
     }
     if ($xhr->getLastResponse()->isSuccessful() && $callback) {
         PhpQuery::callbackRun($callback, array(self::browserReceive($xhr)));
     }
 }
Exemplo n.º 18
0
 public function dumpTree($html = true, $title = true)
 {
     $output = $title ? 'DUMP #' . PhpQuery::$dumpCount++ . " \n" : '';
     $debug = PhpQuery::$debug;
     PhpQuery::$debug = false;
     foreach ($this->stack() as $node) {
         $output .= $this->__dumpTree($node);
     }
     PhpQuery::$debug = $debug;
     print $html ? nl2br(str_replace(' ', '&nbsp;', $output)) : $output;
     return $this;
 }
Exemplo n.º 19
0
<?php

/**
 * Automated google account login.
 * Uses __config.php to keep login data.
 *
 * @package PhpQuery.Plugins.Scripts
 * @author Tobiasz Cudnik <tobiasz.cudnik/gmail.com>
 */
use PhpQuery\PhpQuery;
PhpQuery::ajaxAllowHost('code.google.com', 'google.com', 'www.google.com', 'mail.google.com', 'docs.google.com', 'reader.google.com');
if (!function_exists('ndfasui8923')) {
    function ndfasui8923($browser, $scope)
    {
        extract($scope);
        $browser->WebBrowser()->find('#Email')->val($config['google_login'][0])->end()->find('#Passwd')->val($config['google_login'][1])->parents('form')->submit();
    }
    $ndfasui8923 = new Callback('ndfasui8923', new CallbackParam(), compact('config', 'self', 'return', 'params'));
}
PhpQuery::plugin('WebBrowser');
$self->document->xhr = PhpQuery::$plugins->browserGet('https://www.google.com/accounts/Login', $ndfasui8923);
//$self->document->xhr = PhpQuery::$plugins->browserGet('https://www.google.com/accounts/Login', create_function('$browser', "
//	\$browser
//		->WebBrowser()
//		->find('#Email')
//			->val('{$config['google_login'][0]}')->end()
//		->find('#Passwd')
//			->val('".str_replace("'", "\\'", $config['google_login'][1])."')
//			->parents('form')
//				->submit();"
//));
Exemplo n.º 20
0
/**
 * Shortcut to phpQuery::pq($arg1, $context)
 * Chainable.
 *
 * @see phpQuery::pq()
 * @return PhpQueryObject|QueryTemplatesSource|QueryTemplatesParse|QueryTemplatesSourceQuery
 * @author Tobiasz Cudnik <tobiasz.cudnik/gmail.com>
 * @package phpQuery
 */
function pq($arg1, $context = NULL)
{
    return PhpQuery::pq($arg1, $context);
}