public function testUrlMissingScheme() { $url = new Horde_Url('example.com/test?foo=1&bar=2'); $url->setScheme(); $this->assertEquals('/test?foo=1&bar=2', $url->toString(true, false)); $this->assertEquals('http://example.com/test?foo=1&bar=2', $url->toString(true, true)); }
/** * Send a POST request * * @param string $method The method to call. * @param array $params The method parameters. * * @return string The request results * @throws Horde_Service_Facebook_Exception */ protected function _postRequest($method, &$params) { $this->_finalizeParams($params); try { $url = new Horde_Url(Horde_Service_Facebook::REST_SERVER_ADDR . $method); $result = $this->_http->request('POST', $url->toString(), $this->_createPostString($params)); } catch (Exception $e) { $this->_facebook->logger->err($e->getMessage()); throw new Horde_Service_Facebook_Exception(Horde_Service_Facebook_Translation::t("Facebook service is unavailable. Please try again later.")); } return $result->getBody(); }
/** * Creates the full URL string. * * @param boolean $raw Whether to output the URL in the raw URL format * or HTML-encoded. * @param boolean $full Output the full URL? * * @return string The string representation of this object. */ public function toString($raw = false, $full = true) { if ($this->toStringCallback || !strlen($this->anchor)) { $baseUrl = $this->_baseUrl->copy(); $baseUrl->parameters = array_merge($baseUrl->parameters, $this->parameters); if (strlen($this->pathInfo)) { $baseUrl->pathInfo = $this->pathInfo; } return $baseUrl->toString($raw, $full); } $url = $this->_baseUrl->toString($raw, $full); if (strlen($this->pathInfo)) { $url = rtrim($url, '/'); $url .= '/' . $this->pathInfo; } if ($this->anchor) { $url .= '#' . ($raw ? $this->anchor : rawurlencode($this->anchor)); } if ($params = $this->_getParameters()) { $url .= '?' . implode($raw ? '&' : '&', $params); } return strval($url); }
/** * Run this request and return the data. * * @return mixed Either raw JSON, or an array of decoded values. * @throws Horde_Service_Facebook_Exception */ public function run() { if ($this->_request != 'POST') { $this->_endpoint->add($this->_params); $params = array(); } else { $params = $this->_params; } try { $result = $this->_http->request($this->_request, $this->_endpoint->toString(true), $params); } catch (Horde_Http_Exception $e) { $this->_facebook->logger->err($e->getMessage()); throw new Horde_Service_Facebook_Exception($e); } if ($result->code != '200') { $body = $result->getBody(); if (($error = json_decode($body, true)) && isset($error['error']['message'])) { throw new Horde_Service_Facebook_Exception($error['error']['message']); } throw new Horde_Service_Facebook_Exception($body); } return json_decode($result->getBody()); }
// Add the item to the inventory. try { $ret = $sesha_driver->add(array('stock_name' => $vars->get('stock_name'), 'note' => $vars->get('note'))); } catch (Sesha_Exception $e) { $notification->push(sprintf(_("There was a problem adding the item: %s"), $ret->getMessage()), 'horde.error'); header('Location: ' . $url); exit; } $stock_id = $ret; $notification->push(_("The item was added succcessfully."), 'horde.success'); // Add categories to the item. $sesha_driver->updateCategoriesForStock($stock_id, $vars->get('category_id')); // Add properties to the item as well. $sesha_driver->updatePropertiesForStock($stock_id, $vars->get('property')); $url->add(array('actionId' => 'view_stock', 'stock_id' => $stock_id->stock_id)); header('Location: ' . $url->toString(true, true)); exit; } break; case 'remove_stock': if (Sesha::isAdmin(Horde_Perms::DELETE)) { try { $ret = $sesha_driver->delete($stock_id); } catch (Sesha_Exception $e) { $notification->push(sprintf(_("There was a problem with the driver while deleting: %s"), $e->getMessage()), 'horde.error'); header('Location: ' . Horde::url($baseUrl . '/list.php', true)); exit; } $notification->push(sprintf(_("Item number %d was successfully deleted"), $stock_id), 'horde.success'); } else { $notification->push(_("You do not have sufficient permissions to delete."), 'horde.error');