Returns an external link passed through the dereferrer to strip session
IDs from the referrer.
public static externalUrl ( string $url, boolean $tag = false ) : string | ||
$url | string | The external URL to link to. |
$tag | boolean | If true, a complete tag is returned, only the url otherwise. |
return | string | The link to the dereferrer script. |
/** * Renders a token into text matching the requested format. * * @param array $options The "options" portion of the token (second * element). * * @return string The text rendered from the token options. */ public function token($options) { if (!isset($options['attr']['alt'])) { $options['attr']['alt'] = $options['src']; } if (strpos($options['src'], '://') === false) { if ($options['src'][0] != '/') { if (strpos($options['src'], ':')) { list($page, $options['src']) = explode(':', $options['src'], 2); } else { $page = Horde_Util::getFormData('page'); if ($page == 'EditPage') { $page = Horde_Util::getFormData('referrer'); } if (empty($page)) { $page = 'Wiki/Home'; } } $params = array('page' => $page, 'mime' => '1', 'file' => $options['src']); $options['src'] = $GLOBALS['registry']->downloadUrl($options['src'], $params)->setRaw(true); } } else { $options['src'] = new Horde_Url(Horde::externalUrl($options['src'])); $options['src']->setRaw(true); } // Send external links through Horde::externalUrl(). if (isset($options['attr']['link']) && strpos($options['attr']['link'], '://')) { $href = htmlspecialchars($options['attr']['link']); unset($options['attr']['link']); return Horde::link(Horde::externalUrl($href), $href) . $this->_token($options) . '</a>'; } else { return $this->_token($options); } }
/** * Renders a token into text matching the requested format. * * @param array $options The "options" portion of the token (second * element). * * @return string The text rendered from the token options. */ public function token($options) { $site = $options['site']; $page = $options['page']; $text = $options['text']; if (isset($this->conf['sites'][$site])) { $href = $this->conf['sites'][$site]; } else { return $text; } // old form where page is at end, // or new form with %s placeholder for sprintf()? if (strpos($href, '%s') === false) { // use the old form $href = $href . $page; } else { // use the new form $href = sprintf($href, $page); } // allow for alternative targets $target = $this->getConf('target', ''); if ($target && trim($target) != '') { $target = " target=\"{$target}\""; } return '<a' . $target . ' href="' . Horde::externalUrl($href) . '">' . $text . '</a>'; }
/** * Renders a token into text matching the requested format. * * @param array $options The "options" portion of the token (second * element). * * @return string The text rendered from the token options. */ public function token($options) { // Create local variables from the options array (text, href, // type). extract($options); // Find the rightmost dot and determine the filename // extension. $pos = strrpos($href, '.'); $ext = Horde_String::lower(substr($href, $pos + 1)); $href = htmlspecialchars($href); // Allow for alternative targets on non-anchor HREFs. if ($href[0] == '#') { $target = ''; } else { $target = $this->getConf('target', ''); } $output = Horde::link(Horde::externalUrl($href), $href, 'external', htmlspecialchars($target)) . htmlspecialchars($text) . '</a>'; // Make numbered references look like footnotes. if ($type == 'footnote') { $output = '<sup>' . $output . '</sup>'; } return $output; }
/** */ public function display(Horde_Core_Prefs_Ui $ui) { global $injector, $prefs, $registry, $session; $twitter = $injector->getInstance('Horde_Service_Twitter'); $token = unserialize($prefs->getValue('twitter')); /* Check for an existing token */ if (!empty($token['key']) && !empty($token['secret'])) { $auth_token = new Horde_Oauth_Token($token['key'], $token['secret']); $twitter->auth->setToken($auth_token); } try { $profile = Horde_Serialize::unserialize($twitter->account->verifyCredentials(), Horde_Serialize::JSON); } catch (Horde_Service_Twitter_Exception $e) { } $view = new Horde_View(array('templatePath' => HORDE_TEMPLATES . '/prefs')); $view->addHelper('Text'); $view->appname = $registry->get('name'); /* Could not find a valid auth token, and we are not in the process of * getting one */ if (empty($profile)) { try { $results = $twitter->auth->getRequestToken(); } catch (Horde_Service_Twitter_Exception $e) { throw new Horde_Exception(sprintf(_("Error connecting to Twitter: %s Details have been logged for the administrator."), $e->getMessage())); } $session->store($results->secret, false, 'twitter_request_secret'); $view->link = new Horde_Url(Horde::externalUrl($twitter->auth->getUserAuthorizationUrl($results), false)); } else { $view->haveSession = true; $view->profile_image_url = $profile->profile_image_url; $view->profile_screenname = $profile->screen_name; $view->profile_name = $profile->name; $view->profile_location = $profile->location; } return $view->render('twitter'); }
/** */ protected function _title() { return Horde::externalUrl('http://facebook.com', true) . $this->getName() . '</a>'; }
<?php } ?> </tr> <?php $futureDays++; ?> <?php } ?> </table> <!-- Logo --> <?php if ($this->logo) { ?> <div class="rightAlign"><?php echo _("Weather data provided by") . ' ' . Horde::link(Horde::externalUrl($this->link), $this->title, '', '_blank', '', $this->title) . Horde_Themes_Image::tag($this->logo); ?> </a></div> <?php } else { ?> <div class="rightAlign"><?php echo _("Weather data provided by") . ' ' . Horde::link(Horde::externalUrl($this->link), $this->title, '', '_blank', '', $this->title) . '<em>' . $this->title; ?> </em></a></div> <?php } ?> <?php }
function _renderVarDisplay_address($form, $var, $vars) { global $registry; $address = $var->getValue($vars); if (preg_match('/((?:A[BL]|B[ABDHLNRST]?|C[ABFHMORTVW]|D[ADEGHLNTY]|E[CHNX]?|F[KY]|G[LUY]?|H[ADGPRSUX]|I[GMPV]|JE|K[ATWY]|L[ADELNSU]?|M[EKL]?|N[EGNPRW]?|O[LX]|P[AEHLOR]|R[GHM]|S[AEGKLMNOPRSTWY]?|T[ADFNQRSW]|UB|W[ACDFNRSV]?|YO|ZE)\\d(?:\\d|[A-Z])? \\d[A-Z]{2})/', $address, $postcode)) { /* UK postcode detected. */ /* Multimap.co.uk generated map */ $mapurl = 'http://www.multimap.com/map/browse.cgi?pc=' . urlencode($postcode[1]); $desc = Horde_Model_Translation::t("Multimap UK map"); $icon = 'map.png'; } elseif (preg_match('/ACT|NSW|NT|QLD|SA|TAS|VIC|WA/', $address)) { /* Australian state detected. */ /* Whereis.com.au generated map */ $mapurl = 'http://www.whereis.com.au/whereis/mapping/geocodeAddress.do?'; $desc = Horde_Model_Translation::t("Whereis Australia map"); $icon = 'map.png'; /* Split out the address, line-by-line. */ $addressLines = explode("\n", $address); for ($i = 0; $i < count($addressLines); $i++) { /* See if it's the street number & name. */ if (preg_match('/(\\d+\\s*\\/\\s*)?(\\d+|\\d+[a-zA-Z])\\s+([a-zA-Z ]*)/', $addressLines[$i], $lineParts)) { $mapurl .= '&streetNumber=' . urlencode($lineParts[2]); $mapurl .= '&streetName=' . urlencode($lineParts[3]); } /* Look for "Suburb, State". */ if (preg_match('/([a-zA-Z ]*),?\\s+' . $aus_state_regexp . '/', $addressLines[$i], $lineParts)) { $mapurl .= '&suburb=' . urlencode($lineParts[1]); } /* Look for "State <4 digit postcode>". */ if (preg_match('/(' . $aus_state_regexp . ')\\s+(\\d{4})/', $addressLines[$i], $lineParts)) { $mapurl .= '&state=' . urlencode($lineParts[1]); } } } elseif (preg_match('/(.*)\\n(.*)\\s*,\\s*(\\w+)\\.?\\s+(\\d+|[a-zA-Z]\\d[a-zA-Z]\\s?\\d[a-zA-Z]\\d)/', $address, $addressParts)) { /* American/Canadian address style. */ /* Mapquest generated map */ $mapurl = 'http://www.mapquest.com/maps/map.adp?size=big&zoom=7'; $desc = Horde_Model_Translation::t("MapQuest map"); $icon = 'map.png'; $country = null; if (!empty($addressParts[4]) && preg_match('|[a-zA-Z]\\d[a-zA-Z]\\s?\\d[a-zA-Z]\\d|', $addressParts[4])) { $country = 'CA'; } if (!empty($addressParts[1])) { $mapurl .= '&address=' . urlencode($addressParts[1]); } if (!empty($addressParts[2])) { $mapurl .= '&city=' . urlencode($addressParts[2]); } if (!empty($addressParts[3])) { $mapurl .= '&state=' . urlencode($addressParts[3]); } if (!empty($addressParts[4])) { if ($country == 'CA') { $mapurl .= '&country=CA'; } $mapurl .= '&zipcode=' . urlencode($addressParts[4]); } /* Yahoo! generated map. */ $mapurl2 = 'http://us.rd.yahoo.com/maps/home/submit_a/*-http://maps.yahoo.com/maps?srchtype=a&getmap=Get+Map&'; $desc2 = Horde_Model_Translation::t("Yahoo! map"); $icon2 = 'map.png'; if (!empty($addressParts[1])) { $mapurl2 .= '&addr=' . urlencode($addressParts[1]); } /* Give precedence to zipcode over city/state */ if (empty($addressParts[4]) && !empty($addressParts[2]) && !empty($addressParts[3])) { $mapurl2 .= '&csz=' . urlencode($addressParts[2] . ' ' . $addressParts[3]); } if (!empty($addressParts[4])) { if (preg_match('|([a-zA-Z]\\d[a-zA-Z])\\s?(\\d[a-zA-Z]\\d)|', $addressParts[4], $pcParts)) { $mapurl2 .= '&country=ca'; /* make sure the postal-code has a space */ $addressParts[4] = $pcParts[1] . ' ' . $pcParts[2]; } $mapurl2 .= '&csz=' . urlencode($addressParts[4]); } /* Google generated map. */ $mapurl3 = 'http://maps.google.com/maps?q=' . urlencode($addressParts[0]) . '&hl=en'; $desc3 = Horde_Model_Translation::t("Google Maps"); $icon3 = 'map.png'; } elseif (preg_match('/(.*?)\\r?\\n([A-Z]{1,3})-(\\d{5})\\s+(.*)/i', $address, $addressParts)) { /* European address style. */ include 'Horde/Nls/Carsigns.php'; $country = array_search(Horde_String::upper($addressParts[2]), $carsigns); /* Map24 generated map. */ if (in_array($country, array('al', 'ad', 'am', 'az', 'be', 'ba', 'bg', 'de', 'dk', 'ee', 'fo', 'fi', 'fr', 'ge', 'gr', 'gb', 'ie', 'is', 'it', 'hr', 'lv', 'li', 'lt', 'lu', 'mt', 'mk', 'md', 'mc', 'nl', 'no', 'pl', 'pt', 'ro', 'ru', 'se', 'ch', 'cs', 'sk', 'si', 'es', 'cz', 'tr', 'ua', 'hu', 'by', 'cy', 'at'))) { if (in_array($country, array('at', 'be', 'ch', 'de', 'dk', 'es', 'fi', 'fr', 'it', 'nl', 'no', 'se'))) { $mirror = $country; } else { $mirror = 'uk'; } $mapurl = 'http://www.' . $mirror . '.map24.com/source/address/v2.0.0/cnt_nav_maplet.php?cid=validateaddr&country=' . $country; $desc = Horde_Model_Translation::t("Map24 map"); $icon = 'map_eu.png'; if (!empty($addressParts[1])) { $mapurl .= '&street=' . urlencode($addressParts[1]); } if (!empty($addressParts[3])) { $mapurl .= '&zip=' . urlencode($addressParts[3]); } if (!empty($addressParts[4])) { $mapurl .= '&city=' . urlencode($addressParts[4]); } } /* Mapquest generated map. */ $mapurl2 = 'http://www.mapquest.com/maps/map.adp?country=' . Horde_String::upper($country); $desc2 = Horde_Model_Translation::t("MapQuest map"); $icon2 = 'map_eu.png'; if (!empty($addressParts[1])) { $mapurl2 .= '&address=' . urlencode($addressParts[1]); } if (!empty($addressParts[3])) { $mapurl2 .= '&zipcode=' . urlencode($addressParts[3]); } if (!empty($addressParts[4])) { $mapurl2 .= '&city=' . urlencode($addressParts[4]); } } $html = nl2br(htmlspecialchars($var->getValue($vars))); if (!empty($mapurl)) { $html .= ' ' . Horde::link(Horde::externalUrl($mapurl), $desc, null, '_blank') . Horde::img($icon, $desc) . '</a>'; } if (!empty($mapurl2)) { $html .= ' ' . Horde::link(Horde::externalUrl($mapurl2), $desc2, null, '_blank') . Horde::img($icon2, $desc2) . '</a>'; } if (!empty($mapurl3)) { $html .= ' ' . Horde::link(Horde::externalUrl($mapurl3), $desc3, null, '_blank') . Horde::img($icon3, $desc3) . '</a>'; } return $html; }
/** * Build the Horde_View object for a FB Post. * * @param stdClass $post The Facebook post object. * * @return string The HTML to render the $post. */ protected function _buildPost($post) { global $prefs; $facebook = $this->_getFacebookObject(); $instance = $this->vars->instance; $uid = $facebook->auth->getLoggedInUser(); $postView = new Horde_View(array('templatePath' => HORDE_TEMPLATES . '/block')); $postView->actorImgUrl = $facebook->users->getThumbnail($post->from->id); $postView->actorProfileLink = Horde::externalUrl($facebook->users->getProfileLink($post->from->id), true); $postView->actorName = $post->from->name; $postView->message = empty($post->message) ? '' : $post->message; $postView->likes = $post->likes->count; $postView->postId = $post->id; $postView->privacy = $post->privacy; $postView->postInfo = sprintf(_("Posted %s"), Horde_Date_Utils::relativeDateTime($post->created_time, $prefs->getValue('date_format'), $prefs->getValue('twentyFour') ? "%H:%M %P" : "%I %M %P")) . ' ' . sprintf(_("Comments: %d"), $post->comments->count); $postView->type = $post->type; if (!empty($post->picture)) { $postView->attachment = new stdClass(); $postView->attachment->image = $post->picture; if (!empty($post->link)) { $postView->attachment->link = Horde::externalUrl($post->link, true); } if (!empty($post->name)) { $postView->attachment->name = $post->name; } if (!empty($post->caption)) { $postView->attachment->caption = $post->caption; } if (!empty($post->icon)) { $postView->icon = $post->icon; } if (!empty($post->description)) { $postView->attachment->description = $post->description; } } if (!empty($post->place)) { $postView->place = array('name' => $post->place->name, 'link' => Horde::externalUrl($facebook->getFacebookUrl() . '/' . $post->place->id, true), 'location' => $post->place->location); } if (!empty($post->with_tags)) { $postView->with = array(); foreach ($post->with_tags->data as $with) { $postView->with[] = array('name' => $with->name, 'link' => Horde::externalUrl($facebook->users->getProfileLink($with->id), true)); } } // Actions $like = ''; foreach ($post->actions as $availableAction) { if ($availableAction->name == 'Like') { $like = '<a href="#" onclick="Horde[\'' . $instance . '_facebook\'].addLike(\'' . $post->id . '\');return false;">' . _("Like") . '</a>'; } } $likes = ''; if ($post->likes->count) { foreach ($post->likes->data as $likeData) { if ($likeData->id == $uid && $post->likes->count > 1) { $likes = sprintf(ngettext("You and %d other person likes this", "You and %d other people like this", $post->likes->count - 1), $post->likes->count - 1); break; } elseif ($likeData->id == $uid) { $likes = _("You like this"); break; } } if (empty($likes)) { $likes = sprintf(ngettext("%d person likes this", "%d persons like this", $post->likes->count), $post->likes->count) . (!empty($like) ? ' ' . $like : ''); } else { $likes = $likes . !empty($like) ? ' ' . $like : ''; } } else { $likes = $like; } $postView->likesInfo = $likes; return $postView->render('facebook_story'); }
/** * Expects * $registry * $notification * $browser * $story_id * $channel_id * */ public function run() { extract($this->_params, EXTR_REFS); global $page_output; $page_output->addScriptFile('syntaxhighlighter/scripts/shCore.js', 'horde'); $page_output->addScriptFile('syntaxhighlighter/scripts/shAutoloader.js', 'horde'); $path = $GLOBALS['registry']->get('jsuri', 'horde') . '/syntaxhighlighter/scripts/'; $brushes = <<<EOT SyntaxHighlighter.autoloader( 'applescript {$path}shBrushAppleScript.js', 'actionscript3 as3 {$path}shBrushAS3.js', 'bash shell {$path}shBrushBash.js', 'coldfusion cf {$path}shBrushColdFusion.js', 'cpp c {$path}shBrushCpp.js', 'c# c-sharp csharp {$path}shBrushCSharp.js', 'css {$path}shBrushCss.js', 'delphi pascal {$path}shBrushDelphi.js', 'diff patch pas {$path}shBrushDiff.js', 'erl erlang {$path}shBrushErlang.js', 'groovy {$path}shBrushGroovy.js', 'java {$path}shBrushJava.js', 'jfx javafx {$path}shBrushJavaFX.js', 'js jscript javascript {$path}shBrushJScript.js', 'perl pl {$path}shBrushPerl.js', 'php {$path}shBrushPhp.js', 'text plain {$path}shBrushPlain.js', 'py python {$path}shBrushPython.js', 'ruby rails ror rb {$path}shBrushRuby.js', 'sass scss {$path}shBrushSass.js', 'scala {$path}shBrushScala.js', 'sql {$path}shBrushSql.js', 'vb vbnet {$path}shBrushVb.js', 'xml xhtml xslt html {$path}shBrushXml.js' ); EOT; $page_output->addInlineScript(array($brushes, 'SyntaxHighlighter.defaults[\'toolbar\'] = false', 'SyntaxHighlighter.all()'), true); $sh_js_fs = $GLOBALS['registry']->get('jsfs', 'horde') . '/syntaxhighlighter/styles/'; $sh_js_uri = Horde::url($GLOBALS['registry']->get('jsuri', 'horde'), false, -1) . '/syntaxhighlighter/styles/'; $page_output->addStylesheet($sh_js_fs . 'shCoreEclipse.css', $sh_js_uri . 'shCoreEclipse.css'); $page_output->addStylesheet($sh_js_fs . 'shThemeEclipse.css', $sh_js_uri . 'shThemeEclipse.css'); $driver = $GLOBALS['injector']->getInstance('Jonah_Driver'); try { $story = $driver->getStory($channel_id, $story_id, !$browser->isRobot()); } catch (Exception $e) { $notification->push(sprintf(_("Error fetching story: %s"), $e->getMessage()), 'horde.warning'); $page_output->header(); $notification->notify(array('listeners' => 'status')); $page_output->footer(); exit; } /* Grab tag related content for entire channel */ $cloud = new Horde_Core_Ui_TagCloud(); $allTags = $driver->listTagInfo(array(), $channel_id); foreach ($allTags as $tag_id => $taginfo) { $cloud->addElement($taginfo['tag_name'], Horde::url('stories/results.php')->add(array('tag_id' => $tag_id, 'channel_id' => $channel_id)), $taginfo['total']); } /* Prepare the story's tags for display */ // FIXME - need to actually use these. $tag_html = array(); $tag_link = Horde::url('stories/results.php')->add('channel_id', $channel_id); foreach ($story['tags'] as $id => $tag) { $link = $tag_link->copy()->add('tag_id', $id); $tag_html[] = $link->link() . $tag . '</a>'; } /* Filter and prepare story content. */ if (!empty($story['body_type']) && $story['body_type'] == 'text') { $story['body'] = $GLOBALS['injector']->getInstance('Horde_Core_Factory_TextFilter')->filter($story['body'], 'text2html', array('parselevel' => Horde_Text_Filter_Text2html::MICRO)); } // @TODO: Where is this used and what for? if (!empty($story['url'])) { $story['body'] .= Horde::link(Horde::externalUrl($story['url'])) . htmlspecialchars($story['url']) . '</a></p>'; } if (empty($story['published_date'])) { $story['published_date'] = false; } $view = new Horde_View(array('templatePath' => array(JONAH_TEMPLATES . '/stories', JONAH_TEMPLATES . '/stories/partial', JONAH_TEMPLATES . '/stories/layout'))); $view->addHelper('Tag'); $view->addHelper('Text'); $view->tagcloud = $cloud->buildHTML(); $view->story = $story; /* Insert link for sharing. */ if ($conf['sharing']['allow']) { $url = Horde::url('stories/share.php')->add(array('id' => $story['id'], 'channel_id' => $channel_id)); $view->sharelink = $url->link() . _("Share this story") . '</a>'; } /* Insert comments. */ if ($conf['comments']['allow']) { if (!$registry->hasMethod('forums/doComments')) { $err = 'User comments are enabled but the forums API is not available.'; Horde::log($err, 'ERR'); } else { try { $comments = $registry->call('forums/doComments', array('jonah', $story_id, 'commentCallback')); } catch (Exception $e) { Horde::log($e, 'ERR'); $comments = array('threads' => '', 'comments' => ''); } $view->comments = $comments; } } $page_output->header(); $notification->notify(array('listeners' => 'status')); echo $view->render('view'); $page_output->footer(); }
/** * Helper method to build a view object for a tweet. * * @param stdClass $tweet The tweet object. * * @return Horde_View The view object, populated with tweet data. */ protected function _buildTweet($tweet) { global $injector, $registry; $view = new Horde_View(array('templatePath' => HORDE_TEMPLATES . '/block')); $view->addHelper('Tag'); $view->ajax_uri = $registry->getServiceLink('ajax', $registry->getApp()); $filter = $injector->getInstance('Horde_Core_Factory_TextFilter'); $instance = $this->vars->i; // Links and media $map = $previews = array(); foreach ($tweet->entities->urls as $link) { $replace = '<a target="_blank" href="' . $link->url . '" title="' . $link->expanded_url . '">' . htmlspecialchars($link->display_url) . '</a>'; $map[$link->indices[0]] = array($link->indices[1], $replace); } if (!empty($tweet->entities->media)) { foreach ($tweet->entities->media as $picture) { $replace = '<a target="_blank" href="' . $picture->url . '" title="' . $picture->expanded_url . '">' . htmlentities($picture->display_url, ENT_COMPAT, 'UTF-8') . '</a>'; $map[$picture->indices[0]] = array($picture->indices[1], $replace); $previews[] = ' <a href="#" onclick="return Horde[\'twitter' . $instance . '\'].showPreview(\'' . $picture->media_url . ':small\');"><img src="' . Horde_Themes::img('mime/image.png') . '" /></a>'; } } if (!empty($tweet->entities->user_mentions)) { foreach ($tweet->entities->user_mentions as $user) { $replace = ' <a target="_blank" title="' . $user->name . '" href="http://twitter.com/' . $user->screen_name . '">@' . htmlentities($user->screen_name, ENT_COMPAT, 'UTF-8') . '</a>'; $map[$user->indices[0]] = array($user->indices[1], $replace); } } if (!empty($tweet->entities->hashtags)) { foreach ($tweet->entities->hashtags as $hashtag) { $replace = ' <a target="_blank" href="http://twitter.com/search?q=#' . urlencode($hashtag->text) . '">#' . htmlentities($hashtag->text, ENT_COMPAT, 'UTF-8') . '</a>'; $map[$hashtag->indices[0]] = array($hashtag->indices[1], $replace); } } $body = ''; $pos = 0; while ($pos <= Horde_String::length($tweet->text) - 1) { if (!empty($map[$pos])) { $entity = $map[$pos]; $body .= $entity[1]; $pos = $entity[0]; } else { $body .= Horde_String::substr($tweet->text, $pos, 1); ++$pos; } } foreach ($previews as $preview) { $body .= $preview; } $view->body = $body; /* If this is a retweet, use the original author's profile info */ if (!empty($tweet->retweeted_status)) { $tweetObj = $tweet->retweeted_status; } else { $tweetObj = $tweet; } /* These are all referencing the *original* tweet */ $view->profileLink = Horde::externalUrl('http://twitter.com/' . htmlspecialchars($tweetObj->user->screen_name), true); $view->profileImg = $GLOBALS['browser']->usingSSLConnection() ? $tweetObj->user->profile_image_url_https : $tweetObj->user->profile_image_url; $view->authorName = '@' . htmlspecialchars($tweetObj->user->screen_name); $view->authorFullname = htmlspecialchars($tweetObj->user->name); $view->createdAt = $tweetObj->created_at; $view->clientText = $filter->filter($tweet->source, 'xss'); $view->tweet = $tweet; $view->instanceid = $instance; return $view; }
protected function _renderVarDisplay_address($form, &$var, &$vars, $text = true) { global $registry; $address = $var->getValue($vars); if (empty($address)) { return ''; } $info = $var->type->parse($address); $google_icon = 'map.png'; if (!empty($info['country'])) { switch ($info['country']) { case 'uk': /* Multimap.co.uk generated map */ $mapurl = 'http://www.multimap.com/map/browse.cgi?pc=' . urlencode($info['zip']); $desc = Horde_Core_Translation::t("Multimap UK map"); $icon = 'map.png'; break; case 'au': /* Whereis.com.au generated map */ $mapurl = 'http://www.whereis.com.au/whereis/mapping/geocodeAddress.do?'; $desc = Horde_Core_Translation::t("Whereis Australia map"); $icon = 'map.png'; /* See if it's the street number & name. */ if (isset($info['streetNumber']) && isset($info['streetName'])) { $mapurl .= '&streetNumber=' . urlencode($info['streetNumber']) . '&streetName=' . urlencode($info['streetName']); } /* Look for "Suburb, State". */ if (isset($info['city'])) { $mapurl .= '&suburb=' . urlencode($info['city']); } /* Look for "State <4 digit postcode>". */ if (isset($info['state'])) { $mapurl .= '&state=' . urlencode($info['state']); } break; case 'us': case 'ca': /* American/Canadian address style. */ /* Mapquest generated map */ $mapurl = 'http://www.mapquest.com/maps/map.adp?size=big&zoom=7'; $desc = Horde_Core_Translation::t("MapQuest map"); $icon = 'map.png'; if (!empty($info['street'])) { $mapurl .= '&address=' . urlencode($info['street']); } if (!empty($info['city'])) { $mapurl .= '&city=' . urlencode($info['city']); } if (!empty($info['state'])) { $mapurl .= '&state=' . urlencode($info['state']); } if (!empty($info['zip'])) { if ($info['country'] == 'ca') { $mapurl .= '&country=CA'; } $mapurl .= '&zipcode=' . urlencode($info['zip']); } /* Yahoo! generated map. */ $mapurl2 = 'http://us.rd.yahoo.com/maps/home/submit_a/*-http://maps.yahoo.com/maps?srchtype=a&getmap=Get+Map&'; $desc2 = Horde_Core_Translation::t("Yahoo! map"); $icon2 = 'map.png'; if (!empty($info['street'])) { $mapurl2 .= '&addr=' . urlencode($info['street']); } /* Give precedence to zipcode over city/state */ if (empty($info['zip']) && !empty($info['city']) && !empty($info['state'])) { $mapurl2 .= '&csz=' . urlencode($info['city'] . ' ' . $info['state']); } if (!empty($info['zip'])) { if (preg_match('|([a-zA-Z]\\d[a-zA-Z])\\s?(\\d[a-zA-Z]\\d)|', $info['zip'], $pcParts)) { $mapurl2 .= '&country=ca'; /* make sure the postal-code has a space */ $info['zip'] = $pcParts[1] . ' ' . $pcParts[2]; } $mapurl2 .= '&csz=' . urlencode($info['zip']); } break; default: if (!count($info)) { break; } /* European address style. */ $google_icon = 'map_eu.png'; /* Mapquest generated map. */ $mapurl2 = 'http://www.mapquest.com/maps/map.adp?country=' . Horde_String::upper($info['country']); $desc2 = Horde_Core_Translation::t("MapQuest map"); $icon2 = 'map_eu.png'; if (!empty($info['street'])) { $mapurl2 .= '&address=' . urlencode($info['street']); } if (!empty($info['zip'])) { $mapurl2 .= '&zipcode=' . urlencode($info['zip']); } if (!empty($info['city'])) { $mapurl2 .= '&city=' . urlencode($info['city']); } break; } } $html = $text ? nl2br(htmlspecialchars($address)) : ''; if (!empty($mapurl)) { $html .= ' ' . Horde::link(Horde::externalUrl($mapurl), $desc, null, '_blank') . Horde::img($icon, $desc) . '</a>'; } if (!empty($mapurl2)) { $html .= ' ' . Horde::link(Horde::externalUrl($mapurl2), $desc2, null, '_blank') . Horde::img($icon2, $desc2) . '</a>'; } /* Google generated map. */ if ($address) { $html .= ' ' . Horde::link(Horde::externalUrl('http://maps.google.com/maps?q=' . urlencode(preg_replace('/\\r?\\n/', ',', $address)) . '&hl=en'), Horde_Core_Translation::t("Google Maps"), null, '_blank') . Horde::img($google_icon, Horde_Core_Translation::t("Google Maps")) . '</a>'; } return $html; }
/** */ protected function _title() { $title = !empty($this->_params['title']) ? $this->_params['title'] : $this->_params['iframe']; $url = new Horde_Url(Horde::externalUrl($this->_params['iframe'])); return htmlspecialchars($title) . $url->link(array('target' => '_blank')) . Horde_Themes_Image::tag('external.png', array('attr' => array('style' => 'vertical-align:middle;padding-left:.3em'))) . '</a>'; }
</em></a></div> <div class="hordeSmStreambody"> <?php echo $this->body; ?> <div class="hordeSmStreaminfo"> <?php echo sprintf(_("Posted %s via %s"), Horde_Date_Utils::relativeDateTime(strtotime($this->createdAt), $GLOBALS['prefs']->getValue('date_format')), $this->clientText); ?> </div> <?php if (!empty($this->tweet->retweeted_status)) { ?> <div class="hordeSmStreaminfo"> <?php echo sprintf(_("Retweeted by %s"), Horde::externalUrl('http://twitter.com/' . $this->escape($this->tweet->user->screen_name), true)) . '@' . $this->escape($this->tweet->user->screen_name); ?> </a> </div> <?php } ?> <div class="hordeSmStreaminfo"> <?php echo Horde::selfUrl()->link(array('onclick' => 'Horde[\'twitter' . $this->instanceid . '\'].buildReply(\'' . (string) $this->tweet->id_str . '\', \'' . $this->tweet->user->screen_name . '\', \'' . $this->tweet->user->name . '\'); return false;')) . _("Reply"); ?> </a> | <?php echo Horde::selfUrl()->link(array('onclick' => 'Horde[\'twitter' . $this->instanceid . '\'].retweet(\'' . (string) $this->tweet->id_str . '\'); return false;')) . _("Retweet"); ?> </a>
// Do we have a good auth token? Keep in mind this is example code, and in a true // callback page we probably wouldn't be doing anything if we already have a token, // but for testing purposes.... if (!empty($auth_token)) { /* Have a token, tell the Twitter client about it */ $twitter->auth->setToken($auth_token); // Do something cool.... // $twitter->statuses->update('Testing Horde/Twitter integration'); } elseif (!empty($_SESSION['twitter_request_secret'])) { /* No existing auth token, maybe we are in the process of getting it? */ $a_token = $twitter->auth->getAccessToken(new Horde_Controller_Request_Http(), $_SESSION['twitter_request_secret']); // Clear the request secret from the session now that we're done with it, // again, using _SESSION for simplicity for this example $_SESSION['twitter_request_secret'] = ''; if ($a_token === false || empty($a_token)) { // We had a request secret, but something went wrong. maybe navigated // back here between requests? echo 'error'; die; } else { // We have a good token, save it to DB etc.... var_dump($a_token); die; } } // No auth token, not in the process of getting one...ask user to verify $results = $twitter->auth->getRequestToken(); $_SESSION['twitter_request_secret'] = $results->secret; // Redirect to auth url Horde::externalUrl($twitter->auth->getUserAuthorizationUrl($results), false)->redirect();
<?php /** * Records clicks and clean the URL with Horde::externalUrl(). * * Copyright 2005-2016 Horde LLC (http://www.horde.org/) * * See the enclosed file LICENSE for license information (BSD). If you * did not receive this file, see http://www.horde.org/licenses/bsdl.php. * * @author Ben Chavet <*****@*****.**> */ require_once __DIR__ . '/lib/Application.php'; Horde_Registry::appInit('trean'); $bookmark_id = Horde_Util::getFormData('b'); if (!$bookmark_id) { exit; } try { $bookmark = $trean_gateway->getBookmark($bookmark_id); ++$bookmark->clicks; $bookmark->save(); header('Location: ' . Horde::externalUrl($bookmark->url)); } catch (Exception $e) { }
/** */ protected function _content() { // Set the requested units. $this->_weather->units = $this->_params['units']; if (!empty($this->_refreshParams) && !empty($this->_refreshParams->location)) { $location = $this->_refreshParams->location; $html = ''; $instance = ''; } else { $instance = hash('md5', mt_rand()); $GLOBALS['injector']->getInstance('Horde_Core_Factory_Imple')->create('WeatherLocationAutoCompleter', array('id' => 'location' . $instance, 'instance' => $instance)); $html = '<div class="horde-content"><input id="location' . $instance . '" name="location' . $instance . '"> <input type="button" id="button' . $instance . '" class="horde-default" value="' . _("Change Location") . '" /><span style="display:none;" id="location' . $instance . '_loading_img">' . Horde_Themes_Image::tag('loading.gif') . '</span></div>'; $location = $this->_params['location']; } // Test location try { $location = $this->_weather->searchLocations($location); } catch (Horde_Service_Weather_Exception $e) { return $e->getMessage(); } $html .= '<div id="weathercontent' . $instance . '">'; if (is_array($location)) { // Several locations returned due to imprecise location parameter. $html = sprintf(_("Several locations possible with the parameter: %s"), $this->_params['location']) . '<br />'; foreach ($location as $real_location) { $html .= '<li>' . $real_location->city . ', ' . $real_location->state . '(' . $real_location->code . ")</li>\n"; } $html .= '</ul>'; return $html; } try { $forecast = $this->_weather->getForecast($location->code, $this->_params['days']); $station = $this->_weather->getStation(); $current = $this->_weather->getCurrentConditions($location->code); } catch (Horde_Service_Weather_Exception $e) { return $e->getMessage(); } // Units to display as $units = $this->_weather->getUnits($this->_weather->units); // Location and local time. $html .= '<div class="control">' . '<strong>' . $station->name . '</strong>'; if ($current->time->timestamp()) { $html .= ' ' . sprintf(_("Local time: %s %s (UTC %s)"), $current->time->strftime($GLOBALS['prefs']->getValue('date_format')), $current->time->strftime($GLOBALS['prefs']->getValue('time_format')), $station->getOffset()); } $html .= '</div>'; $html .= '<div class="horde-content">'; // Sunrise/sunset. if ($station->sunrise) { $html .= '<strong>' . _("Sunrise") . ': </strong>' . Horde_Themes_Image::tag('block/sunrise/sunrise.png', array('alt' => _("Sunrise"))) . sprintf("%s %s", $station->sunrise->strftime($GLOBALS['prefs']->getValue('date_format')), $station->sunrise->strftime($GLOBALS['prefs']->getValue('time_format'))); $html .= ' <strong>' . _("Sunset") . ': </strong>' . Horde_Themes_Image::tag('block/sunrise/sunset.png', array('alt' => _("Sunset"))) . sprintf("%s %s", $station->sunset->strftime($GLOBALS['prefs']->getValue('date_format')), $station->sunset->strftime($GLOBALS['prefs']->getValue('time_format'))); $html .= '<br />'; } // Temperature. $html .= '<strong>' . _("Temperature") . ': </strong>' . $current->temp . '°' . Horde_String::upper($units['temp']); // Dew point. if (is_numeric($current->dewpoint)) { $html .= ' <strong>' . _("Dew point") . ': </strong>' . round($current->dewpoint) . '°' . Horde_String::upper($units['temp']); } // Feels like temperature. // @TODO: Need to parse if wind chill/heat index etc.. // $html .= ' <strong>' . _("Feels like: ") . '</strong>' . // round($this->_weather['feltTemperature']) . '°' . Horde_String::upper($units['temp']); // Pressure and trend. if ($current->pressure) { $html .= '<br /><strong>' . _("Pressure") . ': </strong>'; $trend = $current->pressure_trend; if (empty($trend)) { $html .= sprintf('%d %s', round($current->pressure), $units['pres']); } else { $html .= sprintf(_("%d %s and %s"), round($current->pressure), $units['pres'], _($trend)); } } if ($current->wind_direction) { // Wind. $html .= '<br /><strong>' . _("Wind") . ': </strong>'; $html .= sprintf(_("From the %s (%s °) at %s %s"), $current->wind_direction, $current->wind_degrees, $current->wind_speed, $units['wind']); if ($current->wind_gust > 0) { $html .= ', ' . _("gusting") . ' ' . $current->wind_gust . ' ' . $units['wind']; } } // Humidity. if ($current->humidity) { $html .= '<br /><strong>' . _("Humidity") . ': </strong>' . $current->humidity; } if ($current->visibility) { // Visibility. $html .= ' <strong>' . _("Visibility") . ': </strong>' . round($current->visibility) . ' ' . $units['vis']; } // Current condition. $condition = $current->condition; $html .= '<br /><strong>' . _("Current condition") . ': </strong>' . Horde_Themes_Image::tag('weather/32x32/' . $current->icon) . ' ' . $condition . '</div>'; // Forecast if ($this->_params['days'] > 0) { $html .= '<div class="control"><strong>' . sprintf(_("%d-day forecast"), $this->_params['days']) . '</strong></div>'; $futureDays = 0; $html .= '<table class="horde-block-weather">'; // Headers. $html .= '<tr>'; $html .= '<th>' . _("Day") . '</th><th>' . sprintf(_("Temperature%s(%sHi%s/%sLo%s)"), '<br />', '<span style="color:red">', '</span>', '<span style="color:blue">', '</span>') . '</th><th>' . _("Condition") . '</th>'; if (isset($this->_params['detailedForecast'])) { if (in_array(Horde_Service_Weather::FORECAST_FIELD_PRECIPITATION, $forecast->fields)) { $html .= '<th>' . sprintf(_("Precipitation%schance"), '<br />') . '</th>'; } if (in_array(Horde_Service_Weather::FORECAST_FIELD_HUMIDITY, $forecast->fields)) { $html .= '<th>' . _("Humidity") . '</th>'; } if (in_array(Horde_Service_Weather::FORECAST_FIELD_WIND, $forecast->fields)) { $html .= '<th>' . _("Wind") . '</th>'; } } $html .= '</tr>'; $which = -1; foreach ($forecast as $day) { $which++; if ($which > $this->_params['days']) { break; } $html .= '<tr class="rowEven">'; // Day name. $html .= '<td><strong>'; if ($which == 0) { $html .= _("Today"); } elseif ($which == 1) { $html .= _("Tomorrow"); } else { $html .= strftime('%A', mktime(0, 0, 0, date('m'), date('d') + $futureDays, date('Y'))); } $html .= '</strong><br />' . strftime('%b %d', mktime(0, 0, 0, date('m'), date('d') + $futureDays, date('Y'))) . '</td>'; // Forecast condition. $condition = $day->conditions; // Temperature. $html .= '<td>' . '<span style="color:red">' . $day->high . '°' . Horde_String::upper($units['temp']) . '</span>/' . '<span style="color:blue">' . $day->low . '°' . Horde_String::upper($units['temp']) . '</span></td>'; // Condition. $html .= '<td>' . Horde_Themes_Image::tag('weather/32x32/' . $day->icon) . '<br />' . $condition . '</td>'; if (isset($this->_params['detailedForecast'])) { if (in_array(Horde_Service_Weather::FORECAST_FIELD_PRECIPITATION, $forecast->fields)) { $html .= '<td>' . ($day->precipitation_percent >= 0 ? $day->precipitation_percent . '%' : _("N/A")) . '</td>'; } if (in_array(Horde_Service_Weather::FORECAST_FIELD_HUMIDITY, $forecast->fields)) { $html .= '<td>' . ($day->humidity ? $day->humidity . '%' : _("N/A")) . '</td>'; } if (in_array(Horde_Service_Weather::FORECAST_FIELD_WIND, $forecast->fields)) { // Winds. if ($day->wind_direction) { $html .= '<td>' . ' ' . sprintf(_("From the %s at %s %s"), $day->wind_direction, $day->wind_speed, $units['wind']); if ($day->wind_gust && $day->wind_gust > $day->wind_speed) { $html .= ', ' . _("gusting") . ' ' . $day->wind_gust . ' ' . $units['wind']; } $html .= '</td>'; } else { $html .= '<td>' . _("N/A") . '</td>'; } } } $html .= '</tr>'; $futureDays++; } $html .= '</table>'; } if ($this->_weather->logo) { $html .= '<div class="rightAlign">' . _("Weather data provided by") . ' ' . Horde::link(Horde::externalUrl($this->_weather->link), $this->_weather->title, '', '_blank', '', $this->_weather->title) . Horde_Themes_Image::tag($this->_weather->logo) . '</a></div>'; } else { $html .= '<div class="rightAlign">' . _("Weather data provided by") . ' ' . Horde::link(Horde::externalUrl($this->_weather->link), $this->_weather->title, '', '_blank', '', $this->_weather->title) . '<em>' . $this->_weather->title . '</em>' . '</a></div>'; } return $html . '</div>'; }