public function init(array $options) { // base url if (isset($options['baseURL'])) { $this->baseURL = $options['baseURL']; } else { $this->baseURL = 'http://' . $_SERVER['SERVER_NAME']; } if (isset($options['ezrpPath'])) { $this->ezrpPath = $options['ezrpPath']; } $this->sessionID = $options['sessionID']; $verifyURL = new Net_URL2(rtrim($this->baseURL, '/') . $this->ezrpPath); $verifyURL->setQueryVariable('ezrpd', $this->driver); $this->verifyURL = $verifyURL->getURL(); }
/** * Required to request the root i-name (XRI) XRD which will provide an * error message that the i-name does not exist, or else return a valid * XRD document containing the i-name's Canonical ID. * * @param string $url URI * @param string $serviceType Optional service type * * @return HTTP_Request * @todo Finish this a bit better using the QXRI rules. */ protected function get($url, $serviceType = null) { $request = new HTTP_Request2($url, HTTP_Request2::METHOD_GET, $this->getHttpRequestOptions()); $netURL = new Net_URL2($url); $request->setHeader('Accept', 'application/xrds+xml'); if ($serviceType) { $netURL->setQueryVariable('_xrd_r', 'application/xrds+xml'); $netURL->setQueryVariable('_xrd_t', $serviceType); } else { $netURL->setQueryVariable('_xrd_r', 'application/xrds+xml;sep=false'); } $request->setURL($netURL->getURL()); try { return $request->send(); } catch (HTTP_Request2_Exception $e) { throw new Services_Yadis_Exception('Invalid response to Yadis protocol received: ' . $e->getMessage(), $e->getCode()); } }
/** * Sets a an existing query parameter to value or creates a new one if the $key * doesn't exist. * * @param string $key query parameter name. * @param string $value query value. * * @return none */ public function setQueryVariable($key, $value) { Validate::isString($key, 'key'); Validate::isString($value, 'value'); $this->_url->setQueryVariable($key, $value); }
public function MakePagination($query, $rpp_def = NULL, $location = "DB") { $return_set = array(); $this->{$location}->query($query); // This query should select all needed fields from database if ((int) $this->_S->Get('rpp') != 0) { if (isset($_POST['rpp'])) { if ((int) $_POST['rpp'] == 0) { $this->_S->Set('rpp', 50); } else { $this->_S->Set('rpp', (int) $_POST['rpp']); } } $rpp = (int) $this->_S->Get('rpp'); } else { $this->_S->Set('rpp', 50); $rpp = (int) $this->_S->Get('rpp'); } // http://pear.php.net/package/Net_URL2 $op = new Net_URL2($_SERVER["REQUEST_URI"]); $op->unsetQueryVariable('cpage'); $op->setQueryVariable('cpage', ''); $str = (string) $op; if (strpos($str, "search=1")) { $str = str_replace("search=1", "search=0", $str); } $OptionForm = new TForm(); $OptionForm->Action = $str . $this->CurrentPage; $OptionForm->Name = "paginationform"; $OptionForm->class_name = "pagination_form"; $TSelect = new TForm_TSelect('rpp'); $TSelect->class_name = 'select2'; $TSelect->style = 'width: 60px;'; $OptionForm->Add("SlRPP", $TSelect); $OptionForm->SlRPP->Label = "Rezultate pe pagina: "; $OptionForm->SlRPP->label_class = 'inline'; $OptionForm->SlRPP->AddOption('10', '10'); $OptionForm->SlRPP->AddOption('20', '20'); $OptionForm->SlRPP->AddOption('30', '30'); $OptionForm->SlRPP->AddOption('50', '50'); $OptionForm->SlRPP->AddOption('100', '100'); $OptionForm->SlRPP->Value = $rpp; $OptionForm->SlRPP->Paragraph = false; $OptionForm->SlRPP->onChange = 'this.form.submit();'; $total_pages = ceil($this->{$location}->numRows() / $rpp); if (!$this->CurrentPage || $this->CurrentPage <= 0 || $this->CurrentPage > $total_pages) { $this->CurrentPage = 1; } $return_set[1] = " LIMIT " . ($this->CurrentPage - 1) * $rpp . ", " . $rpp; $TSelect = new TForm_TSelect('pag'); $TSelect->class_name = 'select2'; $TSelect->style = 'width: 60px;'; $OptionForm->Add('SlPag', $TSelect); for ($i = 1; $i <= $total_pages; $i++) { $OptionForm->SlPag->AddOption($str . $i, $i); } $OptionForm->SlPag->Label = "Afiseaza pagina: "; $OptionForm->SlPag->label_class = 'inline'; $OptionForm->SlPag->Paragraph = false; $OptionForm->SlPag->Value = $str . $this->CurrentPage; $OptionForm->SlPag->onChange = 'pagination_check_link(this.options[this.selectedIndex].value);'; $return_set[2] = "<div class=\"result_pages\">" . $OptionForm->Html() . ""; $ppages = ''; $j = 0; $nextpage = $pervpage = ''; if ($this->CurrentPage != 1) { $pervpage = '<li><a href="' . $str . '1"> <i class="icon-double-angle-left"></i></a></li><li><a href="' . $str . ($this->CurrentPage - 1) . '"> <i class="icon-angle-left"></i></a></li>'; } else { $pervpage = '<li class="disabled"><a href="' . $str . '1"> <i class="icon-double-angle-left"></i></a></li><li class="disabled"><a href="' . $str . ($this->CurrentPage - 1) . '"> <i class="icon-angle-left"></i></a></li>'; } if ($this->CurrentPage != $total_pages) { $nextpage = '<li><a href="' . $str . ($this->CurrentPage + 1) . '"><i class="icon-angle-right"></i> </a></li><li><a href="' . $str . $total_pages . '"><i class="icon-double-angle-right"></i> </a></li>'; } else { $nextpage = '<li class="disabled"><a href="' . $str . ($this->CurrentPage + 1) . '"><i class="icon-angle-right"></i> </a></li><li class="disabled"><a href="' . $str . $total_pages . '"><i class="icon-double-angle-right"></i> </a></li>'; } for ($i = 0; $i <= $j + 10; $i++) { if ($this->CurrentPage - 5 + $i > 0 && $this->CurrentPage - 5 + $i <= $total_pages) { if ($this->CurrentPage == $this->CurrentPage - 5 + $i) { $ppages .= '<li class="active"><a>' . ($this->CurrentPage - 5 + $i) . '</a></li>'; } else { $ppages .= '<li><a href="' . $str . ($this->CurrentPage - 5 + $i) . '">' . ($this->CurrentPage - 5 + $i) . '</a></li>'; } } else { if ($this->CurrentPage - 5 + $i <= $total_pages) { $j++; } } } $return_set[2] .= '<ul class="pagination">'; if ($total_pages > 1) { $return_set[2] .= $pervpage . $ppages . $nextpage; } else { $return_set[2] .= '<li class="active"><a>' . $this->CurrentPage . '</a></li>'; } $return_set[2] .= '</ul>'; $return_set[2] .= '</div>'; return $return_set; }
/** * GET Request * * @param $url * @param $datas * @return string */ public function get_request($url, $datas = array()) { $body = ''; try { $url2 = new Net_URL2($url); foreach ($datas as $key => $val) { $url2->setQueryVariable($key, mb_convert_encoding($val, $this->response_encoding, 'UTF-8'), true); } $this->http->setURL($url2); $this->http->setMethod(HTTP_Request2::METHOD_GET); if (!empty($this->cookies)) { foreach ($this->cookies as $cookie) { $this->http->addCookie($cookie['name'], $cookie['value']); } } $response = $this->http->send(); if (count($response->getCookies())) { $this->cookies = $response->getCookies(); } $body = mb_convert_encoding($response->getBody(), 'UTF-8', $this->response_encoding); } catch (Exception $e) { debug($e->getMessage()); } return $body; }
/** * Adds a nonce to the openid.return_to URL parameter. Only used in OpenID 1.1 * * @return void */ protected function addNonce() { $nonce = $this->getNonce()->createNonceAndStore(); $returnToURL = new Net_URL2($this->message->get('openid.return_to')); $returnToURL->setQueryVariable(OpenID_Nonce::RETURN_TO_NONCE, urlencode($nonce)); $this->message->set('openid.return_to', $returnToURL->getURL()); // Observing $logMessage = "Nonce: {$nonce}\n"; $logMessage = 'New ReturnTo: ' . $returnToURL->getURL() . "\n"; $logMessage .= 'OP URIs: ' . print_r($this->serviceEndpoint->getURIs(), true); OpenID::setLastEvent(__METHOD__, $logMessage); }
/** * testValidateReturnToOneOneImmediateNegative * * @return void */ public function testValidateReturnToOneOneImmediateNegative() { $opEndpoint = new OpenID_ServiceEndpoint(); $opEndpoint->setURIs(array($this->opEndpointURL)); $opEndpoints = new OpenID_ServiceEndpoints($this->claimedID, $opEndpoint); $nonce = new OpenID_Nonce($this->opEndpointURL); $nonceValue = $nonce->createNonce(); $rt = new Net_URL2('http://examplerp.com'); $rt->setQueryVariable(OpenID_Nonce::RETURN_TO_NONCE, $nonceValue); $setupMessage = new OpenID_Message(); $setupMessage->set('openid.identity', $this->claimedID); $setupMessage->set('openid.return_to', $rt->getURL()); $setupMessage->set(OpenID_Nonce::RETURN_TO_NONCE, $nonceValue); $this->message = new OpenID_Message(); $this->message->set('openid.mode', OpenID::MODE_ID_RES); $this->message->set(OpenID_Nonce::RETURN_TO_NONCE, $nonceValue); $this->message->set('openid.user_setup_url', 'http://examplerp.com/?' . $setupMessage->getHTTPFormat()); $this->discover = $this->getMock('OpenID_Discover', array('__get'), array($this->claimedID)); $this->discover->expects($this->once())->method('__get')->will($this->returnValue($opEndpoints)); $this->store->expects($this->once())->method('getDiscover')->will($this->returnValue($this->discover)); $this->store->expects($this->any())->method('getNonce')->will($this->returnValue($nonceValue)); $this->createObjects(); }
/** * Tests setQueryVariable(). */ public function testSetQueryVariable() { $url = new Net_URL2('http://www.example.com/'); $url->setQueryVariable('pear', 'fun'); $this->assertEquals($url->getURL(), 'http://www.example.com/?pear=fun'); }
/** * Adds a query parameter to the uri query string. * * @param string $name Parameter name * @param mixed $value Parameter value (can be an an array) * @param bool $preencoded Whether the parameter value is already * urlencoded or not (default: false) * * @return void * @todo report a bug / provide a patch for Net_URL2 */ public function addQueryParameter($name, $value, $encoded = false) { // FIXME: Net_URL2 query string management is broken and should // be reimplemented: // - does not encode values when passing an array, // - does not provide an option for already encoded values, // - slow (reparse all query variables each time). // Need a good bug report. $this->_uri->setQueryVariable($name, $value); }
public function appDir($path = '') { $url = new \Net_URL2($this->path . '/app/' . Config::get('application.directory', 'dist') . '/' . ltrim($path, '/')); $url->setQueryVariable('ver', Config::get('application.version', 'false')); return $url->getURL(); }