function onStartShowSections(Action $action) { $name = $action->trimmed('action'); if ($name == 'tag') { $taginput = $action->trimmed('tag'); $tag = common_canonical_tag($taginput); if (!empty($tag)) { $url = sprintf('http://hashtags.wikia.com/index.php?title=%s&action=render', urlencode($tag)); $editurl = sprintf('http://hashtags.wikia.com/index.php?title=%s&action=edit', urlencode($tag)); $request = HTTPClient::start(); $response = $request->get($url); $html = $response->getBody(); $action->elementStart('div', array('id' => 'wikihashtags', 'class' => 'section')); if ($response->isOk() && !empty($html)) { $action->element('style', null, "span.editsection { display: none }\n" . "table.toc { display: none }"); $action->raw($html); $action->elementStart('p'); $action->element('a', array('href' => $editurl, 'title' => sprintf(_m('Edit the article for #%s on WikiHashtags'), $tag)), _m('Edit')); $action->element('a', array('href' => 'http://www.gnu.org/copyleft/fdl.html', 'title' => _m('Shared under the terms of the GNU Free Documentation License'), 'rel' => 'license'), _m('GNU FDL')); $action->elementEnd('p'); } else { $action->element('a', array('href' => $editurl), sprintf(_m('Start the article for #%s on WikiHashtags'), $tag)); } $action->elementEnd('div'); } } return true; }
/** * Menu item for personal subscriptions/groups area * * @param Action $action action being executed * * @return boolean hook return */ function onEndAccountSettingsNav($action) { $action_name = $action->trimmed('action'); common_debug("ACTION NAME = " . $action_name); $action->menuItem(common_local_url('mirrorsettings'), _m('MENU', 'Mirroring'), _m('Configure mirroring of posts from other feeds'), $action_name === 'mirrorsettings'); return true; }
/** * Add extra <meta> headers for certain pages that geourl.org understands * * @param Action $action page being shown * * @return boolean event handler flag */ function onEndShowHeadElements(Action $action) { $name = $action->trimmed('action'); $location = null; if ($action instanceof ShowstreamAction) { $profile = $action->getTarget(); if (!empty($profile->lat) && !empty($profile->lon)) { $location = $profile->lat . ', ' . $profile->lon; } } elseif ($action instanceof ShownoticeAction) { // FIXME: getNotice in ShownoticeAction will do a new lookup, we should fix those classes // so they can reliably just get a pre-stored notice object which was fetched in Shownotice prepare()... $notice = $action->notice; if ($notice instanceof Notice && !empty($notice->lat) && !empty($notice->lon)) { $location = $notice->lat . ', ' . $notice->lon; } } if (!is_null($location)) { $action->element('meta', array('name' => 'ICBM', 'content' => $location)); $action->element('meta', array('name' => 'DC.title', 'content' => $action->title())); } return true; }
/** * Add extra <meta> headers for certain pages that geourl.org understands * * @param Action $action page being shown * * @return boolean event handler flag */ function onEndShowHeadElements($action) { $name = $action->trimmed('action'); $location = null; if ($name == 'showstream') { $profile = $action->profile; if (!empty($profile) && !empty($profile->lat) && !empty($profile->lon)) { $location = $profile->lat . ', ' . $profile->lon; } } else { if ($name == 'shownotice') { $notice = $action->profile; if (!empty($notice) && !empty($notice->lat) && !empty($notice->lon)) { $location = $notice->lat . ', ' . $notice->lon; } } } if (!empty($location)) { $action->element('meta', array('name' => 'ICBM', 'content' => $location)); $action->element('meta', array('name' => 'DC.title', 'content' => $action->title())); } return true; }
/** * Add the Twitter Settings page to the Connect Settings menu * * @param Action $action The calling page * * @return boolean hook return */ function onEndConnectSettingsNav($action) { if (self::hasKeys()) { $action_name = $action->trimmed('action'); $action->menuItem(common_local_url('twittersettings'), _m('MENU', 'Twitter'), _m('Twitter integration options'), $action_name === 'twittersettings'); } return true; }
/** * Add the FetLife Settings page to the Account Settings menu * * @param Action $action The calling page * @return boolean hook return */ function onEndAccountSettingsNav($action) { $action_name = $action->trimmed('action'); $action->menuItem(common_local_url('fetlifesettings'), 'FetLife', 'FetLife integration options', 'fetlifesettings' === $action_name); return true; }
/** * If a notice has a title, show it in the <h1> element * * @param Action $action Action being executed * * @return boolean hook value */ function onStartShowPageTitle($action) { $actionName = $action->trimmed('action'); if ($actionName == 'shownotice') { $title = Notice_title::fromNotice($action->notice); if (!empty($title)) { $action->element('h1', null, $title); return false; } } return true; }
function onEndShowSections(Action $action) { $actionName = $action->trimmed('action'); // These are the ones that have maps on 'em if (!in_array($actionName, array('showstream', 'all'))) { return true; } $action->elementStart('div', array('id' => 'entity_map', 'class' => 'section')); // TRANS: Header for Map widget that displays a map with geodata for notices. $action->element('h2', null, _m('Map')); $action->element('div', array('id' => 'map_canvas', 'class' => 'gray smallmap', 'style' => "width: 100%; height: 240px")); $mapAct = $actionName == 'showstream' ? 'usermap' : 'allmap'; $mapUrl = common_local_url($mapAct, array('nickname' => $action->trimmed('nickname'))); $action->element('a', array('href' => $mapUrl), _m('Full size')); $action->elementEnd('div'); }
/** * Link in a styelsheet for the onboarding actions * * @param Action $action Action being shown * * @return boolean hook flag */ function onEndShowStatusNetStyles($action) { if (in_array($action->trimmed('action'), array('userdirectory', 'groupdirectory'))) { $action->cssLink($this->path('css/directory.css')); } return true; }
/** * Meta tags for "claiming" a site * * We add extra meta tags that search engines like Yahoo!, Google, and Bing * require to let you claim your site. * * @param Action $action Action being executed * * @return boolean hook value. */ function onStartShowHeadElements($action) { $actionName = $action->trimmed('action'); $singleUser = common_config('singleuser', 'enabled'); // Different "top" pages if it's single user or not if ($singleUser && $actionName == 'showstream' || !$singleUser && $actionName == 'public') { $keys = array('googlekey' => 'google-site-verification', 'yahookey' => 'y_key', 'bingkey' => 'msvalidate.01'); // XXX: is this the same for all sites? foreach ($keys as $config => $metaname) { $content = common_config('sitemap', $config); if (!empty($content)) { $action->element('meta', array('name' => $metaname, 'content' => $content)); } } } return true; }
/** * Show some extra instructions for using OpenID * * @param Action $action Action being executed * * @return boolean hook value */ function onEndShowPageNotice($action) { $name = $action->trimmed('action'); switch ($name) { case 'register': if (common_logged_in()) { $instr = '(Have an [OpenID](http://openid.net/)? ' . '[Add an OpenID to your account](%%action.openidsettings%%)!'; } else { $instr = '(Have an [OpenID](http://openid.net/)? ' . 'Try our [OpenID registration]' . '(%%action.openidlogin%%)!)'; } break; case 'login': $instr = '(Have an [OpenID](http://openid.net/)? ' . 'Try our [OpenID login]' . '(%%action.openidlogin%%)!)'; break; default: return true; } $output = common_markup_to_html($instr); $action->raw($output); return true; }
/** * Hook for adding extra JavaScript * * This makes sure our scripts get loaded for map-related pages * * @param Action $action Action object for the page * * @return boolean event handler return */ function onEndShowScripts($action) { $actionName = $action->trimmed('action'); if (!in_array($actionName, array('showstream', 'all', 'usermap', 'allmap'))) { return true; } switch ($this->provider) { case 'cloudmade': $action->script('http://tile.cloudmade.com/wml/0.2/web-maps-lite.js'); break; case 'google': $action->script(sprintf('http://maps.google.com/maps?file=api&v=2&sensor=false&key=%s', urlencode($this->apikey))); break; case 'microsoft': $action->script('http://dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=6'); break; case 'openlayers': // Use our included stripped & minified OpenLayers. $action->script($this->path('OpenLayers/OpenLayers.js')); break; case 'yahoo': $action->script(sprintf('http://api.maps.yahoo.com/ajaxymap?v=3.8&appid=%s', urlencode($this->apikey))); break; case 'geocommons': // don't support this yet // don't support this yet default: return true; } if ($this->provider == 'openlayers') { // We have an optimized path for our default case. // // Note that OpenLayers.js needs to be separate, or it won't // be able to find its UI images and styles. $action->script($this->path('usermap-mxn-openlayers.min.js')); } else { $action->script(sprintf('%s?(%s)', $this->path('js/mxn.js'), $this->provider)); $action->script($this->path('usermap.js')); } $action->inlineScript(sprintf('var _provider = "%s";', $this->provider)); // usermap and allmap handle this themselves if (in_array($actionName, array('showstream', 'all'))) { $action->inlineScript('$(document).ready(function() { ' . ' var user = null; ' . ($actionName == 'showstream' ? ' user = scrapeUser(); ' : '') . ' var notices = scrapeNotices(user); ' . ' var canvas = $("#map_canvas")[0]; ' . ' if (typeof(canvas) != "undefined") { showMapstraction(canvas, notices); } ' . '});'); } return true; }
/** * Hook profile update to prevent blacklisted homepages or nicknames * * Throws an exception if there's a blacklisted homepage or nickname. * * @param Action $action Action being called (usually register) * * @return boolean hook value */ function onStartProfileSaveForm($action) { $homepage = strtolower($action->trimmed('homepage')); if (!empty($homepage)) { if (!$this->_checkUrl($homepage)) { // TRANS: Validation failure for URL. %s is the URL. $msg = sprintf(_m("You may not use homepage \"%s\"."), $homepage); throw new ClientException($msg); } } $nickname = strtolower($action->trimmed('nickname')); if (!empty($nickname)) { if (!$this->_checkNickname($nickname)) { // TRANS: Validation failure for nickname. %s is the nickname. $msg = sprintf(_m("You may not use nickname \"%s\"."), $nickname); throw new ClientException($msg); } } return true; }
/** * Hook for adding extra JavaScript * * This makes sure our scripts get loaded for map-related pages * * @param Action $action Action object for the page * * @return boolean event handler return */ function onEndShowScripts($action) { $actionName = $action->trimmed('action'); if (!in_array($actionName, array('showstream', 'all', 'usermap', 'allmap'))) { return true; } switch ($this->provider) { case 'cloudmade': $action->script('http://tile.cloudmade.com/wml/0.2/web-maps-lite.js'); break; case 'google': $action->script(sprintf('http://maps.google.com/maps?file=api&v=2&sensor=false&key=%s', urlencode($this->apikey))); break; case 'microsoft': $action->script('http://dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=6'); break; case 'openlayers': // XXX: is this not nice...? $action->script('http://openlayers.org/api/OpenLayers.js'); break; case 'yahoo': $action->script(sprintf('http://api.maps.yahoo.com/ajaxymap?v=3.8&appid=%s', urlencode($this->apikey))); break; case 'geocommons': // don't support this yet // don't support this yet default: return true; } $action->script(sprintf('%s?(%s)', common_path('plugins/Mapstraction/js/mxn.js'), $this->provider)); $action->script(common_path('plugins/Mapstraction/usermap.js')); $action->inlineScript(sprintf('var _provider = "%s";', $this->provider)); // usermap and allmap handle this themselves if (in_array($actionName, array('showstream', 'all'))) { $action->inlineScript('$(document).ready(function() { ' . ' var user = null; ' . ($actionName == 'showstream' ? ' user = scrapeUser(); ' : '') . ' var notices = scrapeNotices(user); ' . ' showMapstraction($("#map_canvas"), notices); ' . '});'); } return true; }
/** * Hook profile update to prevent blacklisted homepages or nicknames * * Throws an exception if there's a blacklisted homepage or nickname. * * @param Action $action Action being called (usually register) * * @return boolean hook value */ function onStartProfileSaveForm($action) { $homepage = strtolower($action->trimmed('homepage')); if (!empty($homepage)) { if (!$this->_checkUrl($homepage)) { $msg = sprintf(_m("You may not use homepage '%s'."), $homepage); throw new ClientException($msg); } } $nickname = strtolower($action->trimmed('nickname')); if (!empty($nickname)) { if (!$this->_checkNickname($nickname)) { $msg = sprintf(_m("You may not use nickname '%s'."), $nickname); throw new ClientException($msg); } } return true; }
/** * Event handler for registration attempts; rejects the registration * if email field is missing. * * @param Action $action Action being executed * * @return bool hook result code */ function onStartRegistrationTry($action) { $email = $action->trimmed('email'); if (empty($email)) { $action->showForm(_m('You must provide an email address to register.')); return false; } // Default form will run address format validation and reject if bad. return true; }
function onEndGroupSaveForm(Action $action) { // The Action class must contain this method assert(is_callable(array($action, 'getGroup'))); $gps = null; if ($action->getGroup() instanceof User_group) { $gps = Group_privacy_settings::getKV('group_id', $action->getGroup()->id); } $orig = null; if (empty($gps)) { $gps = new Group_privacy_settings(); $gps->group_id = $action->getGroup()->id; } else { $orig = clone $gps; } $gps->allow_privacy = $action->trimmed('allow_privacy'); $gps->allow_sender = $action->trimmed('allow_sender'); if (empty($orig)) { $gps->created = common_sql_now(); $gps->insert(); } else { $gps->update($orig); } return true; }
/** * Show some extra instructions for using OpenID * * @param Action $action Action being executed * * @return boolean hook value */ function onEndShowPageNotice($action) { $name = $action->trimmed('action'); switch ($name) { case 'register': if (common_logged_in()) { // TRANS: Page notice for logged in users to try and get them to add an OpenID account to their StatusNet account. // TRANS: This message contains Markdown links in the form (description)[link]. $instr = _m('(Have an [OpenID](http://openid.net/)? ' . '[Add an OpenID to your account](%%action.openidsettings%%)!'); } else { // TRANS: Page notice for anonymous users to try and get them to register with an OpenID account. // TRANS: This message contains Markdown links in the form (description)[link]. $instr = _m('(Have an [OpenID](http://openid.net/)? ' . 'Try our [OpenID registration]' . '(%%action.openidlogin%%)!)'); } break; case 'login': // TRANS: Page notice on the login page to try and get them to log on with an OpenID account. // TRANS: This message contains Markdown links in the form (description)[link]. $instr = _m('(Have an [OpenID](http://openid.net/)? ' . 'Try our [OpenID login]' . '(%%action.openidlogin%%)!)'); break; default: return true; } $output = common_markup_to_html($instr); $action->raw($output); return true; }
/** * Menu item for personal subscriptions/groups area * * @param Action $action action being executed * * @return boolean hook return */ function onEndAccountSettingsNav($action) { $action_name = $action->trimmed('action'); $action->menuItem(common_local_url('pollsettings'), _m('MENU', 'Polls'), _m('Configure poll behavior'), $action_name === 'pollsettings'); return true; }
/** * Menu item for admin panel * * @param Action $action action being executed * * @return boolean hook return */ function onEndAdminPanelNav($action) { $action_name = $action->trimmed('action'); $action->out->menuItem(common_local_url('qvitteradminsettings'), _m('MENU', 'Qvitter'), _m('Qvitter Sidebar Notice'), $action_name === 'qvitteradminsettings'); return true; }
/** * If a notice has a title, show it in the <title> element * * @param Action $action Action being executed * * @return boolean hook value */ function onStartShowHeadTitle($action) { $actionName = $action->trimmed('action'); if ($actionName == 'shownotice') { $title = Notice_title::fromNotice($action->notice); if (!empty($title)) { $action->element('title', null, sprintf(_m("%1\$s - %2\$s"), $title, common_config('site', 'name'))); } } return true; }