function onEndShowScripts($action) { if (isset($action->recaptchaPluginNeedsOutput) && $action->recaptchaPluginNeedsOutput) { // Load the AJAX API if (GNUsocial::isHTTPS()) { $url = "https://www.google.com/recaptcha/api/js/recaptcha_ajax.js"; } else { $url = "http://www.google.com/recaptcha/api/js/recaptcha_ajax.js"; } $action->script($url); // And when we're ready, fill out the captcha! $key = json_encode($this->public_key); $action->inlinescript("\$(function(){Recaptcha.create({$key}, 'recaptcha');});"); } return true; }
function common_path($relative, $ssl = false, $addSession = true) { $pathpart = common_config('site', 'path') ? common_config('site', 'path') . "/" : ''; if ($ssl && common_config('site', 'ssl') === 'sometimes' || GNUsocial::isHTTPS() || common_config('site', 'ssl') === 'always') { $proto = 'https'; if (is_string(common_config('site', 'sslserver')) && mb_strlen(common_config('site', 'sslserver')) > 0) { $serverpart = common_config('site', 'sslserver'); } else { if (common_config('site', 'server')) { $serverpart = common_config('site', 'server'); } else { common_log(LOG_ERR, 'Site server not configured, unable to determine site name.'); } } } else { $proto = 'http'; if (common_config('site', 'server')) { $serverpart = common_config('site', 'server'); } else { common_log(LOG_ERR, 'Site server not configured, unable to determine site name.'); } } if ($addSession) { $relative = common_inject_session($relative, $serverpart); } return $proto . '://' . $serverpart . '/' . $pathpart . $relative; }
/** * 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((GNUsocial::isHTTPS() ? 'https' : '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; } $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; }
/** * output a css link * * @param string $src relative path within the theme directory, or an absolute path * @param string $theme 'theme' that contains the stylesheet * @param string media 'media' attribute of the tag * * @return void */ function cssLink($src, $theme = null, $media = null) { if (Event::handle('StartCssLinkElement', array($this, &$src, &$theme, &$media))) { $url = parse_url($src); if (empty($url['scheme']) && empty($url['host']) && empty($url['query']) && empty($url['fragment'])) { if (file_exists(Theme::file($src, $theme))) { $src = Theme::path($src, $theme); } else { $src = common_path($src, GNUsocial::isHTTPS()); } $src .= '?version=' . GNUSOCIAL_VERSION; } $this->element('link', array('rel' => 'stylesheet', 'type' => 'text/css', 'href' => $src, 'media' => $media)); Event::handle('EndCssLinkElement', array($this, $src, $theme, $media)); } }
/** * Build a full URL to the given theme's base directory, possibly * using an offsite theme server path. * * @param string $group configuration section name to pull paths from * @param string $fallbackSubdir default subdirectory under INSTALLDIR * @param string $name theme name * * @return string URL * * @todo consolidate code with that for other customizable paths */ protected function relativeThemePath($group, $fallbackSubdir, $name) { if (GNUsocial::isHTTPS()) { $sslserver = common_config($group, 'sslserver'); if (empty($sslserver)) { if (is_string(common_config('site', 'sslserver')) && mb_strlen(common_config('site', 'sslserver')) > 0) { $server = common_config('site', 'sslserver'); } else { if (common_config('site', 'server')) { $server = common_config('site', 'server'); } } $path = common_config('site', 'path') . '/'; if ($fallbackSubdir) { $path .= $fallbackSubdir . '/'; } } else { $server = $sslserver; $path = common_config($group, 'sslpath'); if (empty($path)) { $path = common_config($group, 'path'); } } $protocol = 'https'; } else { $path = common_config($group, 'path'); if (empty($path)) { $path = common_config('site', 'path') . '/'; if ($fallbackSubdir) { $path .= $fallbackSubdir . '/'; } } $server = common_config($group, 'server'); if (empty($server)) { $server = common_config('site', 'server'); } $protocol = 'http'; } if ($path[strlen($path) - 1] != '/') { $path .= '/'; } if ($path[0] != '/') { $path = '/' . $path; } return $protocol . '://' . $server . $path . $name; }
function main() { global $user, $action; if (!_have_config()) { $msg = sprintf(_("No configuration file found. Try running " . "the installation program first.")); $sac = new ServerErrorAction($msg); $sac->showPage(); return; } // Make sure RW database is setup setupRW(); // XXX: we need a little more structure in this script // get and cache current user (may hit RW!) $user = common_current_user(); // initialize language env common_init_language(); $path = getPath($_REQUEST); $r = Router::get(); $args = $r->map($path); if (!$args) { // TRANS: Error message displayed when trying to access a non-existing page. $cac = new ClientErrorAction(_('Unknown page'), 404); $cac->showPage(); return; } $site_ssl = common_config('site', 'ssl'); // If the request is HTTP and it should be HTTPS... if ($site_ssl != 'never' && !GNUsocial::isHTTPS() && common_is_sensitive($args['action'])) { common_redirect(common_local_url($args['action'], $args)); } $args = array_merge($args, $_REQUEST); Event::handle('ArgsInitialize', array(&$args)); $action = basename($args['action']); if (!$action || !preg_match('/^[a-zA-Z0-9_-]*$/', $action)) { common_redirect(common_local_url('public')); } // If the site is private, and they're not on one of the "public" // parts of the site, redirect to login if (!$user && common_config('site', 'private') && !isLoginAction($action) && !preg_match('/rss$/', $action) && $action != 'robotstxt' && !preg_match('/^Api/', $action)) { // set returnto $rargs =& common_copy_args($args); unset($rargs['action']); if (common_config('site', 'fancy')) { unset($rargs['p']); } if (array_key_exists('submit', $rargs)) { unset($rargs['submit']); } foreach (array_keys($_COOKIE) as $cookie) { unset($rargs[$cookie]); } common_set_returnto(common_local_url($action, $rargs)); common_redirect(common_local_url('login')); } $action_class = ucfirst($action) . 'Action'; if (!class_exists($action_class)) { // TRANS: Error message displayed when trying to perform an undefined action. $cac = new ClientErrorAction(_('Unknown action'), 404); $cac->showPage(); } else { try { call_user_func("{$action_class}::run", $args); } catch (ClientException $cex) { $cac = new ClientErrorAction($cex->getMessage(), $cex->getCode()); $cac->showPage(); } catch (ServerException $sex) { // snort snort guffaw $sac = new ServerErrorAction($sex->getMessage(), $sex->getCode(), $sex); $sac->showPage(); } catch (Exception $ex) { $sac = new ServerErrorAction($ex->getMessage(), 500, $ex); $sac->showPage(); } } }
public static function isHTTPS() { return GNUsocial::isHTTPS(); }
static function staticPath($plugin, $relative) { $isHTTPS = GNUsocial::isHTTPS(); if ($isHTTPS) { $server = common_config('plugins', 'sslserver'); } else { $server = common_config('plugins', 'server'); } if (empty($server)) { if ($isHTTPS) { $server = common_config('site', 'sslserver'); } if (empty($server)) { $server = common_config('site', 'server'); } } if ($isHTTPS) { $path = common_config('plugins', 'sslpath'); } else { $path = common_config('plugins', 'path'); } if (empty($path)) { // XXX: extra stat(). if (@file_exists(INSTALLDIR . '/local/plugins/' . $plugin . '/' . $relative)) { $path = common_config('site', 'path') . '/local/plugins/'; } else { $path = common_config('site', 'path') . '/plugins/'; } } if ($path[strlen($path) - 1] != '/') { $path .= '/'; } if ($path[0] != '/') { $path = '/' . $path; } $protocol = $isHTTPS ? 'https' : 'http'; return $protocol . '://' . $server . $path . $plugin . '/' . $relative; }
/** * Show content license. * * @return nothing */ function showContentLicense() { if (Event::handle('StartShowContentLicense', array($this))) { switch (common_config('license', 'type')) { case 'private': // TRANS: Content license displayed when license is set to 'private'. // TRANS: %1$s is the site name. $this->element('p', null, sprintf(_('Content and data of %1$s are private and confidential.'), common_config('site', 'name'))); // fall through // fall through case 'allrightsreserved': if (common_config('license', 'owner')) { // TRANS: Content license displayed when license is set to 'allrightsreserved'. // TRANS: %1$s is the copyright owner. $this->element('p', null, sprintf(_('Content and data copyright by %1$s. All rights reserved.'), common_config('license', 'owner'))); } else { // TRANS: Content license displayed when license is set to 'allrightsreserved' and no owner is set. $this->element('p', null, _('Content and data copyright by contributors. All rights reserved.')); } break; case 'cc': // fall through // fall through default: $this->elementStart('p'); $image = common_config('license', 'image'); $sslimage = common_config('license', 'sslimage'); if (GNUsocial::isHTTPS()) { if (!empty($sslimage)) { $url = $sslimage; } else { if (preg_match('#^http://i.creativecommons.org/#', $image)) { // CC support HTTPS on their images $url = preg_replace('/^http/', 'https', $image); } else { // Better to show mixed content than no content $url = $image; } } } else { $url = $image; } $this->element('img', array('id' => 'license_cc', 'src' => $url, 'alt' => common_config('license', 'title'), 'width' => '80', 'height' => '15')); $this->text(' '); // TRANS: license message in footer. // TRANS: %1$s is the site name, %2$s is a link to the license URL, with a licence name set in configuration. $notice = _('All %1$s content and data are available under the %2$s license.'); $link = sprintf('<a class="license" rel="external license" href="%1$s">%2$s</a>', htmlspecialchars(common_config('license', 'url')), htmlspecialchars(common_config('license', 'title'))); $this->raw(@sprintf(htmlspecialchars($notice), htmlspecialchars(common_config('site', 'name')), $link)); $this->elementEnd('p'); break; } Event::handle('EndShowContentLicense', array($this)); } }