Example #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;
 }
 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();
 }
Example #3
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();
 }
 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();
 }
Example #5
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;
 }
 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();
 }
Example #8
0
 private function wrapInput($name, $input)
 {
     $classname = 'form-col-' . str_replace([' ', '.'], '-', $name);
     return PhpQuery::pq('<div class="col-md-6 ' . $classname . '">' . (string) $input . '</div>');
 }
Example #9
0
 /**
  * Enter description here...
  *
  * @param string|PhpQueryObject
  * @return PhpQueryObject|QueryTemplatesSource|QueryTemplatesParse|QueryTemplatesSourceQuery
  */
 public function add($selector = null)
 {
     if (!$selector) {
         return $this;
     }
     $stack = array();
     $this->elementsBackup = $this->elements;
     $found = PhpQuery::pq($selector, $this->getDocumentID());
     $this->merge($found->elements);
     return $this->newInstance();
 }
Example #10
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);
}
 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;
 }
 /**
  * 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);
 }
Example #13
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)));
     }
 }