add() публичный Метод

Adds one or more query parameters.
public add ( mixed $parameters, string $value = null ) : Horde_Url
$parameters mixed Either the name value or an array of name/value pairs.
$value string If specified, the value part ($parameters is then assumed to just be the parameter name).
Результат Horde_Url This (modified) object, to allow chaining.
Пример #1
0
 public function testAddOverwrite()
 {
     $url = new Horde_Url('test');
     $url->add('foo', 1);
     $this->assertEquals('test?foo=1', (string) $url);
     $url->add('foo', 2);
     $this->assertEquals('test?foo=2', (string) $url);
 }
Пример #2
0
 /**
  * Perform search
  *
  * @throws Mnemo_Exception
  */
 protected function _doSearch()
 {
     $search_pattern = $this->_vars->get('search_pattern');
     $search_type = $this->_vars->get('search_type');
     $search_desc = $search_type == 'desc';
     $search_body = $search_type == 'body';
     if (!empty($search_pattern) && ($search_body || $search_desc)) {
         $search_pattern = '/' . preg_quote($search_pattern, '/') . '/i';
         $search_result = array();
         foreach ($this->_notes as $memo_id => $memo) {
             if ($search_desc && preg_match($search_pattern, $memo['desc']) || $search_body && preg_match($search_pattern, $memo['body'])) {
                 $search_result[$memo_id] = $memo;
             }
         }
         $this->_notes = $search_result;
     } elseif ($search_type == 'tags') {
         // Tag search, use the browser.
         $this->_browser->clearSearch();
         $tags = $GLOBALS['injector']->getInstance('Mnemo_Tagger')->split($this->_vars->get('search_pattern'));
         foreach ($tags as $tag) {
             $this->_browser->addTag($tag);
         }
         $this->_notes = $this->_browser->getSlice();
         $this->_handleActions(false);
         return;
     }
     $this->_baseurl->add(array('actionID' => 'search_memos', 'search_pattern' => $search_pattern, 'search_type' => $search_type));
 }
Пример #3
0
 public function testBaseUrlWithParametersWithoutAnchor()
 {
     $base = new Horde_Url('test');
     $base->add('foo', 0);
     $url = new Horde_Core_Smartmobile_Url($base);
     $url->add(array('foo' => 1, 'bar' => 2));
     $this->assertEquals('test?foo=1&bar=2', (string) $url);
 }
Пример #4
0
 public function testLink()
 {
     $url = new Horde_Url('test', true);
     $url->add(array('foo' => 1, 'bar' => 2));
     $this->assertEquals('test?foo=1&bar=2', (string) $url);
     $this->assertEquals('<a href="test?foo=1&amp;bar=2">', $url->link());
     $this->assertEquals('<a href="test?foo=1&amp;bar=2" title="foo&amp;bar">', $url->link(array('title' => 'foo&bar')));
     $this->assertEquals('<a href="test?foo=1&amp;bar=2" title="foo&bar">', $url->link(array('title.raw' => 'foo&bar')));
 }
Пример #5
0
 /**
  * Builds URL strings for various targets
  * @param string $controller  The internal name of the controller or page
  * @param array $details      The parameters to attach either as path or as get parameters
  * @param boolean $full       Generate a full url or relative to dolcore, defaults to false
  * @param boolean $legacy     Generate an url for the legacy target page or for a dolcore controller. Ignored if one is missing
  * @returns string  The generated URL
  */
 public function getUrlFor($controller, array $details = null, $full = false, $legacy = false)
 {
     switch ($controller) {
         case 'discussion':
             if ($legacy) {
                 $parameters = array('position' => 700, 'frage_id' => $details['discussion_id']);
                 $url = new Horde_Url($GLOBALS['conf']['path']['dol2day_front'], true);
                 return $url->add($parameters)->toString();
             }
             break;
     }
 }
Пример #6
0
/**
 * Construct the URL back to a supplied search
 */
function _getSearchUrl($vars)
{
    $qUrl = new Horde_Url();
    $queue = (int) $vars->get('queue');
    $qUrl->add(array('queue' => $queue));
    $summary = $vars->get('summary');
    if ($summary) {
        $qUrl->add('summary', $summary);
    }
    $states = $vars->get('states');
    if (is_array($states)) {
        foreach ($states as $type => $state) {
            if (is_array($state)) {
                foreach ($state as $s) {
                    $qUrl->add("states[{$type}][]", $s);
                }
            } else {
                $qUrl->add("states[{$type}]", $state);
            }
        }
    }
    return substr($qUrl, 1);
}
Пример #7
0
 /**
  * @TODO: For reverse requests come up with a reasonable algorithm for
  *        checking if we have a lat/lng in the US since the
  *        findNearestAddress method is US only. If non-us, fallback to a
  *        findNearest or findPostalcode or similar request. Also will need
  *        to normalize the various response structures.
  *
  * 'locations' will trigger a forward geocoding request.
  * 'lat' and 'lon' will trigger a reverse geocoding request.
  *
  * @throws Horde_Exception
  */
 protected function _handle(Horde_Variables $vars)
 {
     if ($vars->location) {
         $url = new Horde_Url('http://ws.geonames.org/searchJSON');
         $url->add(array('q' => $vars->location));
     } elseif ($vars->lat && $vars->lon) {
         $url = new Horde_Url('http:/ws.geonames.org/findNearestJSON');
         $url->add(array('lat' => $vars->lat, 'lng' => $vars->lon));
     } else {
         throw new Horde_Exception('Incorrect parameters');
     }
     $response = $GLOBALS['injector']->getInstance('Horde_Core_Factory_HttpClient')->create()->get($url);
     return new Horde_Core_Ajax_Response_Prototypejs(array('results' => $response->getBody(), 'status' => 200));
 }
Пример #8
0
 public function testFromUrl()
 {
     $baseurl = new Horde_Url('test', true);
     $baseurl->add(array('foo' => 1, 'bar' => 2));
     $url = new Horde_Url($baseurl);
     $this->assertEquals('test?foo=1&bar=2', (string) $url);
     $url = new Horde_Url($baseurl, true);
     $this->assertEquals('test?foo=1&bar=2', (string) $url);
     $url = new Horde_Url($baseurl, false);
     $this->assertEquals('test?foo=1&amp;bar=2', (string) $url);
     $baseurl = new Horde_Url('test', false);
     $baseurl->add(array('foo' => 1, 'bar' => 2));
     $url = new Horde_Url($baseurl);
     $this->assertEquals('test?foo=1&amp;bar=2', (string) $url);
     $url = new Horde_Url($baseurl, true);
     $this->assertEquals('test?foo=1&bar=2', (string) $url);
     $url = new Horde_Url($baseurl, false);
     $this->assertEquals('test?foo=1&amp;bar=2', (string) $url);
 }
Пример #9
0
 /**
  * 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());
 }
Пример #10
0
 /**
  * Return an autocomplete search response.
  *
  * @see Horde_Service_Weather_Base::autocompleteLocation()
  */
 public function autocompleteLocation($search)
 {
     $url = new Horde_Url('http://autocomplete.wunderground.com/aq');
     $url->add(array('query' => $search, 'format' => 'JSON'));
     return $this->_parseAutocomplete($this->_makeRequest($url));
 }
Пример #11
0
 /**
  * Produces a directory link used for navigation.
  *
  * @param string $currdir  The current directory string.
  * @param string $url      The URL to link to.
  *
  * @return string  The directory navigation string.
  */
 public static function directoryNavLink($currdir, $url)
 {
     $label = array();
     $root_dir_name = self::$backend['name'];
     if ($currdir == $root_dir_name) {
         $label[] = '[' . $root_dir_name . ']';
     } else {
         $parts = explode('/', $currdir);
         $parts_count = count($parts);
         $url = new Horde_Url($url);
         $label[] = Horde::link($url->add('dir', self::$backend['root']), sprintf(_("Up to %s"), $root_dir_name)) . '[' . $root_dir_name . ']</a>';
         for ($i = 1; $i <= $parts_count; ++$i) {
             $part = array_slice($parts, 0, $i);
             $dir = implode('/', $part);
             if (strstr($dir, self::$backend['root']) !== false && self::$backend['root'] != $dir) {
                 if ($i == $parts_count) {
                     $label[] = $parts[$i - 1];
                 } else {
                     $label[] = Horde::link($url->add('dir', $dir), sprintf(_("Up to %s"), $dir)) . htmlspecialchars($parts[$i - 1]) . '</a>';
                 }
             }
         }
     }
     return implode('/', $label);
 }
Пример #12
0
 /**
  * Create the URL for the keyserver.
  *
  * @param string $uri    Action URI.
  * @param array $params  List of parameters to add to URL.
  *
  * @return Horde_Url  Keyserver URL.
  */
 protected function _createUrl($uri, array $params = array())
 {
     $url = new Horde_Url($this->_keyserver . $uri, true);
     return $url->add($params);
 }
Пример #13
0
 /**
  * Return the rendered inline version of the Horde_Mime_Part object.
  *
  * @return array  See parent::render().
  */
 protected function _renderInline()
 {
     $browser = $this->getConfigParam('browser');
     $notification = $this->getConfigParam('notification');
     $prefs = $this->getConfigParam('prefs');
     $registry = $this->getConfigParam('registry');
     $data = $this->_mimepart->getContents();
     $html = '';
     $title = Horde_Core_Translation::t("vCard");
     $iCal = new Horde_Icalendar();
     if (!$iCal->parsevCalendar($data, 'VCALENDAR', $this->_mimepart->getCharset())) {
         $notification->push(Horde_Core_Translation::t("There was an error reading the contact data."), 'horde.error');
     }
     if (Horde_Util::getFormData('import') && Horde_Util::getFormData('source') && $registry->hasMethod('contacts/import')) {
         $source = Horde_Util::getFormData('source');
         $count = 0;
         foreach ($iCal->getComponents() as $c) {
             if ($c->getType() == 'vcard') {
                 try {
                     $registry->call('contacts/import', array($c, null, $source));
                     ++$count;
                 } catch (Horde_Exception $e) {
                     $notification->push(Horde_Core_Translation::t("There was an error importing the contact data:") . ' ' . $e->getMessage(), 'horde.error');
                 }
             }
         }
         $notification->push(sprintf(Horde_Core_Translation::ngettext("%d contact was successfully added to your address book.", "%d contacts were successfully added to your address book.", $count), $count), 'horde.success');
     }
     $html .= '<table class="horde-table" style="width:100%">';
     foreach ($iCal->getComponents() as $i => $vc) {
         if ($i > 0) {
             $html .= '<tr><td colspan="2">&nbsp;</td></tr>';
         }
         $addresses = $vc->getAllAttributes('EMAIL');
         $html .= '<tr><td colspan="2" class="header">';
         if (($fullname = $vc->getAttributeDefault('FN', false)) === false) {
             $fullname = count($addresses) ? $addresses[0]['value'] : Horde_Core_Translation::t("[No Label]");
         }
         $html .= htmlspecialchars($fullname) . '</td></tr>';
         $n = $vc->printableName();
         if (!empty($n)) {
             $html .= $this->_row(Horde_Core_Translation::t("Name"), $n);
         }
         try {
             $html .= $this->_row(Horde_Core_Translation::t("Alias"), implode("\n", $vc->getAttributeValues('ALIAS')));
         } catch (Horde_Icalendar_Exception $e) {
         }
         try {
             $birthdays = $vc->getAttributeValues('BDAY');
             $birthday = new Horde_Date($birthdays[0]);
             $html .= $this->_row(Horde_Core_Translation::t("Birthday"), $birthday->strftime($prefs->getValue('date_format')));
         } catch (Horde_Icalendar_Exception $e) {
         }
         $photos = $vc->getAllAttributes('PHOTO');
         foreach ($photos as $p => $photo) {
             if (isset($photo['params']['VALUE']) && Horde_String::upper($photo['params']['VALUE']) == 'URI') {
                 $html .= $this->_row(Horde_Core_Translation::t("Photo"), '<img src="' . htmlspecialchars($photo['value']) . '" />', false);
             } elseif (isset($photo['params']['ENCODING']) && Horde_String::upper($photo['params']['ENCODING']) == 'B' && isset($photo['params']['TYPE'])) {
                 if ($browser->hasFeature('datauri') === true || $browser->hasFeature('datauri') >= strlen($photo['value'])) {
                     $html .= $this->_row(Horde_Core_Translation::t("Photo"), '<img src="' . Horde_Url_Data::create($photo['params']['TYPE'], base64_decode($photo['value'])) . '" />', false);
                 } elseif ($this->_imageUrl) {
                     $html .= $this->_row(Horde_Core_Translation::t("Photo"), '<img src="' . $this->_imageUrl->add(array('c' => $i, 'p' => $p)) . '" />', false);
                 }
             }
         }
         $labels = $vc->getAllAttributes('LABEL');
         foreach ($labels as $label) {
             if (isset($label['params']['TYPE'])) {
                 if (!is_array($label['params']['TYPE'])) {
                     $label['params']['TYPE'] = array($label['params']['TYPE']);
                 }
             } else {
                 $label['params']['TYPE'] = array_keys($label['params']);
             }
             $types = array();
             foreach ($label['params']['TYPE'] as $type) {
                 switch (Horde_String::upper($type)) {
                     case 'HOME':
                         $types[] = Horde_Core_Translation::t("Home Address");
                         break;
                     case 'WORK':
                         $types[] = Horde_Core_Translation::t("Work Address");
                         break;
                     case 'DOM':
                         $types[] = Horde_Core_Translation::t("Domestic Address");
                         break;
                     case 'INTL':
                         $types[] = Horde_Core_Translation::t("International Address");
                         break;
                     case 'POSTAL':
                         $types[] = Horde_Core_Translation::t("Postal Address");
                         break;
                     case 'PARCEL':
                         $types[] = Horde_Core_Translation::t("Parcel Address");
                         break;
                     case 'PREF':
                         $types[] = Horde_Core_Translation::t("Preferred Address");
                         break;
                 }
             }
             if (!count($types)) {
                 $types = array(Horde_Core_Translation::t("Address"));
             }
             $html .= $this->_row(implode('/', $types), $label['value']);
         }
         $adrs = $vc->getAllAttributes('ADR');
         foreach ($adrs as $item) {
             if (isset($item['params']['TYPE'])) {
                 if (!is_array($item['params']['TYPE'])) {
                     $item['params']['TYPE'] = array($item['params']['TYPE']);
                 }
             } else {
                 $item['params']['TYPE'] = array_keys($item['params']);
             }
             $address = $item['values'];
             $a = array();
             $a_list = array(Horde_Icalendar_Vcard::ADR_STREET, Horde_Icalendar_Vcard::ADR_LOCALITY, Horde_Icalendar_Vcard::ADR_REGION, Horde_Icalendar_Vcard::ADR_POSTCODE, Horde_Icalendar_Vcard::ADR_COUNTRY);
             foreach ($a_list as $val) {
                 if (isset($address[$val])) {
                     $a[] = $address[$val];
                 }
             }
             $types = array();
             foreach ($item['params']['TYPE'] as $type) {
                 switch (Horde_String::upper($type)) {
                     case 'HOME':
                         $types[] = Horde_Core_Translation::t("Home Address");
                         break;
                     case 'WORK':
                         $types[] = Horde_Core_Translation::t("Work Address");
                         break;
                     case 'DOM':
                         $types[] = Horde_Core_Translation::t("Domestic Address");
                         break;
                     case 'INTL':
                         $types[] = Horde_Core_Translation::t("International Address");
                         break;
                     case 'POSTAL':
                         $types[] = Horde_Core_Translation::t("Postal Address");
                         break;
                     case 'PARCEL':
                         $types[] = Horde_Core_Translation::t("Parcel Address");
                         break;
                     case 'PREF':
                         $types[] = Horde_Core_Translation::t("Preferred Address");
                         break;
                 }
             }
             if (!count($types)) {
                 $types = array(Horde_Core_Translation::t("Address"));
             }
             $html .= $this->_row(implode('/', $types), implode("\n", $a));
         }
         $numbers = $vc->getAllAttributes('TEL');
         foreach ($numbers as $number) {
             if (isset($number['params']['TYPE'])) {
                 if (!is_array($number['params']['TYPE'])) {
                     $number['params']['TYPE'] = array($number['params']['TYPE']);
                 }
                 foreach ($number['params']['TYPE'] as $type) {
                     $number['params'][Horde_String::upper($type)] = true;
                 }
             }
             if (isset($number['params']['FAX'])) {
                 $html .= $this->_row(Horde_Core_Translation::t("Fax"), $number['value']);
             } else {
                 if (isset($number['params']['HOME'])) {
                     $html .= $this->_row(Horde_Core_Translation::t("Home Phone"), $number['value']);
                 } elseif (isset($number['params']['WORK'])) {
                     $html .= $this->_row(Horde_Core_Translation::t("Work Phone"), $number['value']);
                 } elseif (isset($number['params']['CELL'])) {
                     $html .= $this->_row(Horde_Core_Translation::t("Cell Phone"), $number['value']);
                 } else {
                     $html .= $this->_row(Horde_Core_Translation::t("Phone"), $number['value']);
                 }
             }
         }
         $emails = array();
         foreach ($addresses as $address) {
             if (isset($address['params']['TYPE'])) {
                 if (!is_array($address['params']['TYPE'])) {
                     $address['params']['TYPE'] = array($address['params']['TYPE']);
                 }
                 foreach ($address['params']['TYPE'] as $type) {
                     $address['params'][Horde_String::upper($type)] = true;
                 }
             }
             $email = '<a href="';
             if ($registry->hasMethod('mail/compose')) {
                 $email .= $registry->call('mail/compose', array(array('to' => $address['value'])));
             } else {
                 $email .= 'mailto:' . htmlspecialchars($address['value']);
             }
             $email .= '">' . htmlspecialchars($address['value']) . '</a>';
             if (isset($address['params']['PREF'])) {
                 array_unshift($emails, $email);
             } else {
                 $emails[] = $email;
             }
         }
         if (count($emails)) {
             $html .= $this->_row(Horde_Core_Translation::t("Email"), implode("\n", $emails), false);
         }
         try {
             $title = $vc->getAttributeValues('TITLE');
             $html .= $this->_row(Horde_Core_Translation::t("Title"), $title[0]);
         } catch (Horde_Icalendar_Exception $e) {
         }
         try {
             $role = $vc->getAttributeValues('ROLE');
             $html .= $this->_row(Horde_Core_Translation::t("Role"), $role[0]);
         } catch (Horde_Icalendar_Exception $e) {
         }
         try {
             $org = $vc->getAttributeValues('ORG');
             $html .= $this->_row(Horde_Core_Translation::t("Company"), $org[0]);
             if (isset($org[1])) {
                 $html .= $this->_row(Horde_Core_Translation::t("Department"), $org[1]);
             }
         } catch (Horde_Icalendar_Exception $e) {
         }
         try {
             $notes = $vc->getAttributeValues('NOTE');
             $html .= $this->_row(Horde_Core_Translation::t("Notes"), $notes[0]);
         } catch (Horde_Icalendar_Exception $e) {
         }
         try {
             $url = $vc->getAttributeValues('URL');
             $html .= $this->_row(Horde_Core_Translation::t("URL"), '<a href="' . htmlspecialchars($url[0]) . '" target="_blank">' . htmlspecialchars($url[0]) . '</a>', false);
         } catch (Horde_Icalendar_Exception $e) {
         }
     }
     $html .= '</table>';
     if ($registry->hasMethod('contacts/import') && $registry->hasMethod('contacts/sources')) {
         $html .= '<div class="horde-form-buttons"><form action="' . Horde::selfUrl() . '" method="get" name="vcard_import" id="vcard_import">' . Horde_Util::formInput();
         foreach ($_GET as $key => $val) {
             $html .= '<input type="hidden" name="' . htmlspecialchars($key) . '" value="' . htmlspecialchars($val) . '" />';
         }
         $sources = $registry->call('contacts/sources', array(true));
         if (count($sources) > 1) {
             $html .= '<input type="submit" class="horde-default" name="import" value="' . Horde_Core_Translation::t("Add to address book:") . '" />' . ' <label for="add_source" class="hidden">' . Horde_Core_Translation::t("Address Book") . '</label>' . '<select id="add_source" name="source">';
             foreach ($sources as $key => $label) {
                 $selected = $key == $prefs->getValue('add_source') ? ' selected="selected"' : '';
                 $html .= '<option value="' . htmlspecialchars($key) . '"' . $selected . '>' . htmlspecialchars($label) . '</option>';
             }
             $html .= '</select>';
         } else {
             reset($sources);
             $html .= '<input type="submit" class="horde-default" name="import" value="' . Horde_Core_Translation::t("Add to my address book") . '" />' . '<input type="hidden" name="source" value="' . htmlspecialchars(key($sources)) . '" />';
         }
         $html .= '</form></div>';
     }
     Horde::startBuffer();
     $notification->notify(array('listeners' => 'status'));
     return $this->_renderReturn(Horde::endBuffer() . $html, 'text/html; charset=' . $this->getConfigParam('charset'));
 }
Пример #14
0
 /**
  * Add the ingo action token to a URL.
  *
  * @param Horde_Url $url  URL.
  *
  * @return Horde_Url  URL with token added (for chainable calls).
  */
 protected function _addToken(Horde_Url $url)
 {
     global $session;
     return $url->add(self::INGO_TOKEN, $session->getToken());
 }
Пример #15
0
     if ($valid && $form->isSubmitted()) {
         // 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 {
Пример #16
0
 /**
  * Make the remote API call.
  *
  * @param Horde_Url $url  The endpoint.
  *
  * @return mixed  The unserialized results form the remote API call.
  * @throws Horde_Service_Weather_Exception
  */
 protected function _makeRequest(Horde_Url $url)
 {
     // Owm returns temperature data in Kelvin by default!
     if ($this->units == Horde_Service_Weather::UNITS_METRIC) {
         $url->add('units', 'metric');
     } else {
         $url->add('units', 'imperial');
     }
     $url->add(array('key' => $this->_key))->setRaw(true);
     $cachekey = md5('hordeweather' . $url);
     if (!empty($this->_cache) && !($results = $this->_cache->get($cachekey, $this->_cache_lifetime)) || empty($this->_cache)) {
         $response = $this->_http->get((string) $url);
         if (!$response->code == '200') {
             throw new Horde_Service_Weather_Exception($response->code);
         }
         $results = $response->getBody();
         if (!empty($this->_cache)) {
             $this->_cache->set($cachekey, $results);
         }
     }
     $results = Horde_Serialize::unserialize($results, Horde_Serialize::JSON);
     if (!$results instanceof StdClass) {
         throw new Horde_Service_Weather_Exception(sprintf('Error, unable to decode response: %s', $results));
     }
     return $results;
 }
Пример #17
0
 * an application, redirect to initial page. This is done in index.php.
 * If we are trying to authenticate to an application, but don't have to,
 * redirect to the requesting URL. */
if ($is_auth) {
    if (!$vars->app) {
        require HORDE_BASE . '/index.php';
        exit;
    } elseif ($url_in && $registry->isAuthenticated(array('app' => $vars->app))) {
        _addAnchor($url_in, 'param', null, $url_anchor)->redirect();
    }
}
/* Redirect the user if an alternate login page has been specified. */
if (!empty($conf['auth']['alternate_login'])) {
    $url = new Horde_Url($conf['auth']['alternate_login'], true);
    if ($vars->app) {
        $url->add('app', $vars->app);
    }
    if (!isset($_COOKIE[session_name()])) {
        $url->add(session_name(), session_id());
    }
    if (empty($url_in)) {
        $url_in = Horde::selfUrl(true, true, true);
    }
    $anchor = _addAnchor($url_in, 'param', $vars, $url_anchor);
    $found = false;
    foreach ($url->parameters as $key => $value) {
        if (strpos($value, '%u') !== false) {
            $url->parameters[$key] = str_replace('%u', $anchor, $value);
            $found = true;
        }
    }
Пример #18
0
 /**
  * Make the remote API call.
  *
  * @param Horde_Url $url  The endpoint.
  *
  * @return mixed  The unserialized results form the remote API call.
  * @throws Horde_Service_Weather_Exception
  */
 protected function _makeRequest(Horde_Url $url)
 {
     $url->add(array('format' => 'json', 'key' => $this->_key))->setRaw(true);
     $cachekey = md5('hordeweather' . $url);
     if (!empty($this->_cache) && !($results = $this->_cache->get($cachekey, $this->_cache_lifetime)) || empty($this->_cache)) {
         $response = $this->_http->get((string) $url);
         if (!$response->code == '200') {
             throw new Horde_Service_Weather_Exception($response->code);
         }
         $results = $response->getBody();
         if (!empty($this->_cache)) {
             $this->_cache->set($cachekey, $results);
         }
     }
     $results = Horde_Serialize::unserialize($results, Horde_Serialize::JSON);
     if (!$results instanceof StdClass) {
         throw new Horde_Service_Weather_Exception(sprintf('Error, unable to decode response: %s', $results));
     }
     return $results;
 }
Пример #19
0
 /**
  * Callback for Horde_Url when generating "simple" compose links. Simple
  * links don't require exterior javascript libraries.
  *
  * @param Horde_Url $url  URL object.
  *
  * @return string  URL string representation.
  */
 public function composeLinkSimpleCallback($url)
 {
     $url->add('popup_link', 1);
     return "javascript:void(window.open('" . strval($url) . "','','width=820,height=600,status=1,scrollbars=yes,resizable=yes'))";
 }
Пример #20
0
 /**
  * Return the current pagerurl.
  *
  * @return Horde_Url  The url
  */
 protected function _getPagerUrl()
 {
     $date_params = Ansel::getDateParameter(array('year' => !empty($this->view->year) ? $this->view->year : 0, 'month' => !empty($this->view->month) ? $this->view->month : 0, 'day' => !empty($this->view->day) ? $this->view->day : 0));
     if (!empty($this->view->gallery_view_url)) {
         $pagerurl = new Horde_Url(str_replace(array('%g', '%s'), array($this->galleryId, $this->gallerySlug), urldecode($this->view->gallery_view_url)));
         $pagerurl->add($date_params)->setRaw(true);
     } else {
         // Build the pager url. Add the needed variables directly to the
         // url instead of passing it as a preserved variable to the pager
         // since the logic to build the URL is already in getUrlFor()
         $pager_params = array_merge(array('gallery' => $this->galleryId, 'view' => 'Gallery', 'slug' => $this->view->gallery->get('slug')), $date_params);
         $pagerurl = Ansel::getUrlfor('view', $pager_params, true);
     }
     return $pagerurl;
 }
Пример #21
0
 /**
  * Obtain the JSON needed to embed a single Vimeo video specified by the
  * parameter. Passing a url is the most effecient as we won't have to query
  * the vimeo service for the url.
  *
  * @param mixed $options  Either an array containing the vimeo url or
  *                        vimeo clip id, OR a scaler containing the clip id.
  * @return unknown
  */
 public function getEmbedJson($options)
 {
     if (!is_array($options)) {
         // Assume it's a video id, need to get the video url
         // @TODO
     }
     // $options should be an array now
     if (empty($options['url']) && !empty($options['video_id'])) {
         // We were originally passed an array, but still need the url
         // @TODO
     }
     // See if we have a cache, and if so, try to get the data from it before
     // polling the vimeo service.
     if (!empty($this->_cache)) {
         $cache_key = 'VimeoJson' . hash('md5', serialize($options));
         $data = $this->_cache->get($cache_key, $this->_cache_lifetime);
         if ($data !== false) {
             return unserialize($data);
         }
     }
     // We should have a url now, and possibly other options.
     $url = new Horde_Url($this->_oembed_endpoint);
     $url->add($options)->setRaw(true);
     try {
         $response = $this->_http_client->request('GET', $url);
     } catch (Horde_Http_Exception $e) {
         // TODO:
         // Some videos it seems are not found via oembed? This appears to be
         // a fringe case, and only happens when I'm attempting to load
         // videos that aren't mine.  Maybe they are marked as
         // non-embeddable? I can't seem to find that setting though....
         // for now, ignore the Http_Client's exception so we don't kill
         // the page...just log it....once we have a logger, that is.
     }
     $results = $response->getBody();
     if (!empty($this->_cache)) {
         $this->_cache->set($cache_key, serialize($results));
     }
     return $results;
 }
Пример #22
0
 /**
  * Return the Gravatar image URL for the specified mail address. The
  * returned URL can be directly used with an IMG tag e.g.:
  * &lt;img src="http://www.gravatar.com/avatar/hash" /&gt;
  *
  * @param string $mail  The mail address.
  * @param mixed $opts   Additional options. If an integer, treated as the
  *                      'size' option.  If an array, the following options
  *                      are available:
  * <pre>
  *   - default: (string) Default behavior. Valid values are '404', 'mm',
  *              'identicon', 'monsterid', 'wavatar', 'retro', 'blank', or
  *              a URL-encoded URL to use as the default image.
  *   - rating: (string) Rating. Valid values are 'g', 'pg', 'r', and 'x'.
  *   - size: (integer) Image size. Valid values are between 1 and 512.
  * </pre>
  *
  * @return Horde_Url  The image URL.
  */
 public function getAvatarUrl($mail, $opts = array())
 {
     if (is_integer($opts)) {
         $opts = array('size' => $opts);
     }
     if (!empty($opts['size']) && ($opts['size'] < 1 || $opts['size'] > 512)) {
         throw InvalidArgumentException('The size parameter is out of bounds');
     }
     $url = new Horde_Url($this->_base . '/avatar/' . $this->getId($mail));
     if (!empty($opts['default'])) {
         $url->add('d', $opts['default']);
     }
     if (!empty($opts['rating'])) {
         $url->add('r', $opts['rating']);
     }
     if (!empty($opts['size'])) {
         $url->add('s', $opts['size']);
     }
     return $url;
 }
Пример #23
0
 /**
  * Generate a URL using the current mailbox.
  *
  * @param string|Horde_Url $page  Page name to link to.
  * @param string $buid            The BUID to use on the linked page.
  * @param boolean $encode         Encode the argument separator?
  *
  * @return Horde_Url  URL to $page with any necessary mailbox information
  *                    added to the parameter list of the URL.
  */
 public function url($page, $buid = null, $encode = true)
 {
     if ($page instanceof Horde_Url) {
         return $page->add($this->urlParams($buid))->setRaw(!$encode);
     }
     switch ($GLOBALS['registry']->getView()) {
         case Horde_Registry::VIEW_BASIC:
         case Horde_Registry::VIEW_DYNAMIC:
             $anchor = is_null($buid) ? 'mbox:' . $this->form_to : 'msg:' . $this->form_to . ';' . $buid;
             return Horde::url('index.php')->setAnchor($anchor);
         case Horde_Registry::VIEW_MINIMAL:
         case Horde_Registry::VIEW_SMARTMOBILE:
             $url = Horde::url('smartmobile.php');
             $anchor = is_null($buid) ? 'mbox=' . $this->form_to : 'msg=' . $this->form_to . ';' . $buid;
             $url->setAnchor('mailbox?' . $anchor);
             return $url;
     }
     return Horde::url($page . '.php')->add($this->urlParams($buid))->setRaw(!$encode);
 }
Пример #24
0
 /**
  * Sends a request and parses the response.
  *
  * @param string $method      A HTTP request method (uppercase).
  * @param string $namespace   An API namespace.
  * @param array $params       URL parameters.
  * @param array|string $data  Request data.
  *
  * @return array  The decoded result data or null if no data has been
  *                returned but the request was still successful.
  * @throws Horde_OpenXchange_Exception.
  */
 protected function _request($method, $namespace, $params, $data = array())
 {
     $uri = new Horde_Url($this->_uri . '/' . $namespace, true);
     try {
         $headers = array();
         if (isset($this->_cookies)) {
             $headers['Cookie'] = implode('; ', $this->_cookies);
         }
         if ($method == 'GET') {
             $params = array_merge($params, $data);
             $data = null;
         }
         $response = $this->_client->request($method, (string) $uri->add($params), $data, $headers);
         if ($cookies = $response->getHeader('set-cookie')) {
             if (!is_array($cookies)) {
                 $cookies = array($cookies);
             }
             foreach ($cookies as $cookie) {
                 $cookie = preg_split('/;\\s*/', $cookie);
                 for ($i = 1, $c = count($cookie); $i < $c; $i++) {
                     list($key, $value) = explode('=', $cookie[$i]);
                     if ($key == 'Expires') {
                         $expire = new Horde_Date($value);
                         if ($expire->before(time())) {
                             continue 2;
                         }
                         break;
                     }
                 }
                 $this->_cookies[] = $cookie[0];
             }
         }
         $body = $response->getBody();
         $data = json_decode($body, true);
         if (!$data) {
             if ($response->code == 200) {
                 return;
             }
             throw new Horde_OpenXchange_Exception($body);
         }
         if (isset($data['error'])) {
             $e = new Horde_OpenXchange_Exception($data['error']);
             $e->details = $data;
             throw $e;
         }
         return $data;
     } catch (Horde_Http_Exception $e) {
         throw new Horde_OpenXchange_Exception($e);
     }
 }
Пример #25
0
$url = new Horde_Url('icon_browser.php');
$vars = $injector->getInstance('Horde_Variables');
if (($app = basename($vars->app)) && in_array($app, $apps)) {
    $img = Horde_Themes::img(null, array('app' => $app, 'theme' => 'default'));
    $img_fs = $img->fs;
    // Throws Exception on error.
    $iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($img_fs));
    // Provide a non-white background for eyeballing transparency.
    echo '<html><body bgcolor="#aaaaaa">' . '<h2>' . sprintf(_("Icons for %s"), $registry->get('name', $app)) . '</h2>';
    foreach ($iterator as $val) {
        if ($val->isFile() && in_array(substr($val->getFilename(), -4), array('.png', '.gif', 'jpg'))) {
            $imgs[] = strval($val);
        }
    }
    if (count($imgs)) {
        natsort($imgs);
        foreach ($imgs as $img) {
            echo Horde_Themes_Image::tag(Horde_Themes::img(str_replace($img_fs . DIRECTORY_SEPARATOR, '', $img), array('app' => $app, 'theme' => 'default')), array('alt' => $img, 'attr' => array('hspace' => 10, 'title' => $img, 'vspace' => 10)));
        }
    } else {
        echo _("No icons found.");
    }
    echo '<p /><a href="' . $url . '">Return to app browser</a></body></html>';
} else {
    // List apps.
    foreach ($apps as $app) {
        if ($name = $registry->get('name', $app)) {
            echo Horde::link($url->add('app', $app)) . htmlspecialchars($name) . ' [' . htmlspecialchars($app) . ']</a><br />';
        }
    }
}
Пример #26
0
 /**
  * Returns a session-id-ified version of $uri.
  * If a full URL is requested, all parameter separators get converted to
  * "&", otherwise to "&amp;".
  *
  * @param mixed $uri      The URI to be modified (either a string or any
  *                        object with a __toString() function).
  * @param boolean $full   Generate a full (http://server/path/) URL.
  * @param mixed $opts     Additional options. If a string/integer, it is
  *                        taken to be the 'append_session' option.  If an
  *                        array, one of the following:
  *   - app: (string) Use this app for the webroot.
  *          DEFAULT: current application
  *   - append_session: (integer) 0 = only if needed [DEFAULT], 1 = always,
  *                     -1 = never.
  *   - force_ssl: (boolean) Ignore $conf['use_ssl'] and force creation of
  *                a SSL URL?
  *                DEFAULT: false
  *
  * @return Horde_Url  The URL with the session id appended (if needed).
  */
 public static function url($uri, $full = false, $opts = array())
 {
     if (is_array($opts)) {
         $append_session = isset($opts['append_session']) ? $opts['append_session'] : 0;
         if (!empty($opts['force_ssl'])) {
             $full = true;
         }
     } else {
         $append_session = $opts;
         $opts = array();
     }
     $puri = parse_url($uri);
     /* @todo Fix for PHP < 5.3.6 */
     if (isset($puri['fragment']) && !isset($puri['path'])) {
         $pos = strpos($uri, '/', strpos($uri, $puri['host']) + strlen($puri['host']));
         $puri['path'] = substr($uri, $pos, strpos($uri, '#', $pos) - $pos);
     }
     /* End fix */
     $url = '';
     $schemeRegexp = '|^([a-zA-Z][a-zA-Z0-9+.-]{0,19})://|';
     $webroot = ltrim($GLOBALS['registry']->get('webroot', empty($opts['app']) ? null : $opts['app']), '/');
     if ($full && !isset($puri['scheme']) && !preg_match($schemeRegexp, $webroot)) {
         /* Store connection parameters in local variables. */
         $server_name = $GLOBALS['conf']['server']['name'];
         $server_port = isset($GLOBALS['conf']['server']['port']) ? $GLOBALS['conf']['server']['port'] : '';
         $protocol = 'http';
         switch ($GLOBALS['conf']['use_ssl']) {
             case 1:
                 $protocol = 'https';
                 break;
             case 2:
                 if ($GLOBALS['browser']->usingSSLConnection()) {
                     $protocol = 'https';
                 }
                 break;
             case 3:
                 $server_port = '';
                 if (!empty($opts['force_ssl'])) {
                     $protocol = 'https';
                 }
                 break;
         }
         /* If using a non-standard port, add to the URL. */
         if (!empty($server_port) && ($protocol == 'http' && $server_port != 80 || $protocol == 'https' && $server_port != 443)) {
             $server_name .= ':' . $server_port;
         }
         $url = $protocol . '://' . $server_name;
     } elseif (isset($puri['scheme'])) {
         $url = $puri['scheme'] . '://' . $puri['host'];
         /* If using a non-standard port, add to the URL. */
         if (isset($puri['port']) && ($puri['scheme'] == 'http' && $puri['port'] != 80 || $puri['scheme'] == 'https' && $puri['port'] != 443)) {
             $url .= ':' . $puri['port'];
         }
     }
     if (isset($puri['path']) && substr($puri['path'], 0, 1) == '/' && (!preg_match($schemeRegexp, $webroot) || preg_match($schemeRegexp, $webroot) && isset($puri['scheme']))) {
         $url .= $puri['path'];
     } elseif (isset($puri['path']) && preg_match($schemeRegexp, $webroot)) {
         if (substr($puri['path'], 0, 1) == '/') {
             $pwebroot = parse_url($webroot);
             $url = $pwebroot['scheme'] . '://' . $pwebroot['host'] . $puri['path'];
         } else {
             $url = $webroot . '/' . $puri['path'];
         }
     } else {
         $url .= '/' . ($webroot ? $webroot . '/' : '') . (isset($puri['path']) ? $puri['path'] : '');
     }
     if (isset($puri['query'])) {
         $url .= '?' . $puri['query'];
     }
     if (isset($puri['fragment'])) {
         $url .= '#' . $puri['fragment'];
     }
     $ob = new Horde_Url($url, $full);
     if (empty($GLOBALS['conf']['session']['use_only_cookies']) && ($append_session == 1 || $append_session == 0 && !isset($_COOKIE[session_name()]))) {
         $ob->add(session_name(), session_id());
     }
     return $ob;
 }
Пример #27
0
 /**
  * Generate a link URL.
  *
  * @param string $node_id  The node ID.
  *
  * @return string  The link tag.
  */
 protected function _generateUrlTag($node_id)
 {
     $url = new Horde_Url($_SERVER['PHP_SELF']);
     return $url->add(Horde_Tree::TOGGLE . $this->_tree->instance, $node_id)->link();
 }
Пример #28
0
 /**
  * Return a properly formatted link depending on the global pretty url
  * configuration
  *
  * @param string $controller       The controller to generate a URL for.
  * @param array $data              The data needed to generate the URL.
  * @param boolean $full            Generate a full URL.
  * @param integer $append_session  0 = only if needed, 1 = always, -1 = never.
  *
  * @return Horde_Url The generated URL
  */
 public static function getUrlFor($controller, $data, $full = false, $append_session = 0)
 {
     global $prefs;
     $rewrite = isset($GLOBALS['conf']['urls']['pretty']) && $GLOBALS['conf']['urls']['pretty'] == 'rewrite';
     switch ($controller) {
         case 'view':
             if ($rewrite && empty($data['special'])) {
                 $url = '';
                 // Viewing a List
                 if ($data['view'] == 'List') {
                     $groupby = isset($data['groupby']) ? $data['groupby'] : $prefs->getValue('groupby');
                     if ($groupby == 'owner' && !empty($data['owner'])) {
                         $url = 'user/' . urlencode($data['owner']) . '/';
                     } elseif ($groupby == 'owner') {
                         $url = 'user/';
                     } elseif ($groupby == 'none') {
                         $url = 'all/';
                     }
                     $url = Horde::url($url, $full, $append_session);
                     //  don't append the page number if it's zero
                     if (!empty($data['page'])) {
                         $url->add('page', $data['page']);
                     }
                     return $url;
                 }
                 // Viewing a Gallery or Image
                 if ($data['view'] == 'Gallery' || $data['view'] == 'Image') {
                     // @TODO: This is needed to correctly generate URLs in
                     // places that are not specifically requested by the user,
                     // for instance, in a gallery block. Otherwise, the proper
                     // date variables would not be attached to the url, since we
                     // don't know them ahead of time.  This is a slight hack and
                     // needs to be corrected, probably by delegating at least
                     // some of the URL generation to the gallery/image/view
                     // object...most likely when we move to PHP5.
                     if (empty($data['year']) && $data['view'] == 'Image') {
                         // Getting these objects is not ideal, but at this point
                         // they should already be locally cached so the cost
                         // is minimized.
                         $i = $GLOBALS['injector']->getInstance('Ansel_Storage')->getImage($data['image']);
                         $g = $GLOBALS['injector']->getInstance('Ansel_Storage')->getGallery($data['gallery']);
                         if ($g->get('view_mode') == 'Date') {
                             $imgDate = new Horde_Date($i->originalDate);
                             $data['year'] = $imgDate->year;
                             $data['month'] = $imgDate->month;
                             $data['day'] = $imgDate->mday;
                         }
                     }
                     $url = 'gallery/' . (!empty($data['slug']) ? $data['slug'] : 'id/' . (int) $data['gallery']) . '/';
                     // See comments below about lightbox
                     if ($data['view'] == 'Image' && (empty($data['gallery_view']) || !empty($data['gallery_view']) && $data['gallery_view'] != 'GalleryLightbox')) {
                         $url .= (int) $data['image'] . '/';
                     }
                     $extras = array();
                     // We may have a value of zero here, but it's the default,
                     // so ignore it if it's empty.
                     if (!empty($data['havesearch'])) {
                         $extras['havesearch'] = $data['havesearch'];
                     }
                     // Block any auto navigation (for date views)
                     if (!empty($data['force_grouping'])) {
                         $extras['force_grouping'] = $data['force_grouping'];
                     }
                     $url = new Horde_Url($url);
                     if (count($extras)) {
                         $url->add($extras);
                     }
                     //Slight hack until we delegate at least some of the url
                     // generation to the gallery/image/view object.
                     if ($data['view'] == 'Image' && !empty($data['gallery_view']) && $data['gallery_view'] == 'GalleryLightbox') {
                         $url->setAnchor($data['image']);
                     }
                 } elseif ($data['view'] == 'Results') {
                     $url = new Horde_Url('tag/' . (!empty($data['tag']) ? urlencode($data['tag']) . '/' : ''));
                     if (!empty($data['actionID'])) {
                         $url->add(array('actionID' => $data['actionID']));
                     }
                     if (!empty($data['owner'])) {
                         $url->add('owner', $data['owner']);
                     }
                 }
                 // Keep the URL as clean as possible - don't append the page
                 // number if it's zero, which would be the default.
                 if (!empty($data['page'])) {
                     $url->add('page', $data['page']);
                 }
                 if (!empty($data['year'])) {
                     $url->add(array('year' => $data['year'], 'month' => empty($data['month']) ? 0 : $data['month'], 'day' => empty($data['day']) ? 0 : $data['day']));
                 }
                 return Horde::url($url, $full, $append_session);
             } else {
                 $url = Horde::url('view.php', $full, $append_session);
                 // See note above about delegating url generation to gallery/view
                 if ($data['view'] == 'Image' && !empty($data['gallery_view']) && $data['gallery_view'] == 'GalleryLightbox') {
                     $data['view'] = 'Gallery';
                     $url->setAnchor($data['image']);
                 }
                 return $url->add($data)->setRaw(true);
             }
         case 'group':
             if ($rewrite) {
                 if (empty($data['groupby'])) {
                     $data['groupby'] = $prefs->getValue('groupby');
                 }
                 if ($data['groupby'] == 'owner') {
                     $url = 'user/';
                 } elseif ($data['groupby'] == 'none') {
                     $url = 'all/';
                 }
                 unset($data['groupby']);
                 $url = Horde::url($url, $full, $append_session);
                 if (count($data)) {
                     $url->add($data);
                 }
                 return $url;
             } else {
                 return Horde::url('group.php', $full, $append_session)->add($data);
             }
         case 'rss_user':
             if ($rewrite) {
                 return Horde::url('user/' . urlencode($data['owner']) . '/rss', $full, $append_session);
             } else {
                 $url = Horde::url(new Horde_Url('rss.php'), $full, $append_session);
                 return $url->add(array('stream_type' => 'user', 'id' => $data['owner']));
             }
         case 'rss_gallery':
             if ($rewrite) {
                 $id = !empty($data['slug']) ? $data['slug'] : 'id/' . (int) $data['gallery'];
                 return Horde::url('gallery/' . $id . '/rss', $full, $append_session);
             } else {
                 return Horde::url('rss.php', $full, $append_session)->add(array('stream_type' => 'gallery', 'id' => (int) $data['gallery']));
             }
         case 'default_view':
             switch ($prefs->getValue('defaultview')) {
                 case 'browse':
                     return Horde::url(new Horde_Url('browse.php'), $full, $append_session);
                 case 'galleries':
                     $url = Ansel::getUrlFor('view', array('view' => 'List'), true);
                     break;
                 case 'mygalleries':
                 default:
                     $url = Ansel::getUrlFor('view', array('view' => 'List', 'owner' => $GLOBALS['registry']->getAuth(), 'groupby' => 'owner'), true);
                     break;
             }
             return $url;
     }
 }