function __construct($data) { $pq = null; include_once dirname(__FILE__) . '/../PhpQuery/PhpQuery.php'; if (file_exists(dirname(__FILE__) . '/jQueryServer.config.php')) { include_once dirname(__FILE__) . '/jQueryServer.config.php'; if ($jQueryServerConfig) { $this->config = array_merge_recursive($this->config, $jQueryServerConfig); } } if ($this->config['refererMustMatch']) { foreach ($this->config['allowedRefererHosts'] as $i => $host) { if ($host == '.') { $this->config['allowedRefererHosts'][$i] = $_SERVER['HTTP_HOST']; } } $referer = parse_url($_SERVER['HTTP_REFERER'], PHP_URL_HOST); $authorized = $referer && in_array($referer, $this->config['allowedRefererHosts']); if (!$authorized) { throw new \Exception("Host '{$_SERVER['HTTP_REFERER']}' not authorized to make requests."); return; } } // PhpQueryClass::$debug = true; // if (! function_exists('json_decode')) { // include_once(dirname(__FILE__).'/JSON.php'); // $this->json = new Services_JSON(SERVICES_JSON_LOOSE_TYPE); // } // $data = $this->jsonDecode($data); $data = PhpQuery::parseJSON($data); // load document (required for first $data element) if (is_array($data[0]) && isset($data[0]['url'])) { $this->options = $data[0]; $ajax = $this->options; $this->calls = array_slice($data, 1); $ajax['success'] = array($this, 'success'); PhpQuery::ajax($ajax); } else { throw new \Exception("URL needed to download content"); } }
/** * Enter description here... * * @link http://docs.jquery.com/Ajax/load * @param $url * @param null $data * @param null $callback * @return PhpQuery|QueryTemplatesSource|QueryTemplatesParse|QueryTemplatesSourceQuery * @todo Support $selector */ public function load($url, $data = null, $callback = null) { if ($data && !is_array($data)) { $callback = $data; $data = null; } if (mb_strpos($url, ' ') !== false) { $matches = null; if (extension_loaded('mbstring') && PhpQuery::$mbstringSupport) { mb_ereg('^([^ ]+) (.*)$', $url, $matches); } else { preg_match('@^([^ ]+) (.*)$@', $url, $matches); } $url = $matches[1]; $selector = $matches[2]; // FIXME this sucks, pass as callback param $this->_loadSelector = $selector; } $ajax = array('url' => $url, 'type' => $data ? 'POST' : 'GET', 'data' => $data, 'complete' => $callback, 'success' => array($this, '__loadSuccess')); PhpQuery::ajax($ajax); return $this; }
/** * 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))); } }