/** * Load attributes based on database arguments * * Loads all the DB stuff * * @param array $args $_REQUEST array * * @return success flag */ protected function prepare(array $args = array()) { parent::prepare($args); if ($this->boolean('ajax')) { GNUsocial::setApi(true); } $this->notice = $this->getNotice(); if (!$this->notice->inScope($this->scoped)) { // TRANS: Client exception thrown when trying a view a notice the user has no access to. throw new ClientException(_('Access restricted.'), 403); } $this->profile = $this->notice->getProfile(); if (!$this->profile instanceof Profile) { // TRANS: Server error displayed trying to show a notice without a connected profile. $this->serverError(_('Notice has no profile.'), 500); } try { $this->user = $this->profile->getUser(); } catch (NoSuchUserException $e) { // FIXME: deprecate $this->user stuff in extended classes $this->user = null; } try { $this->avatar = $this->profile->getAvatar(AVATAR_PROFILE_SIZE); } catch (Exception $e) { $this->avatar = null; } return true; }
function handle($args) { // Trigger short error responses; not a human-readable web page. GNUsocial::setApi(true); // We're not a general oEmbed proxy service; limit to valid sessions. $token = $this->trimmed('token'); if (!$token || $token != common_session_token()) { // TRANS: Client error displayed when the session token does not match or is not given. $this->clientError(_m('There was a problem with your session token. ' . 'Try again, please.')); } $format = $this->arg('format'); if ($format && $format != 'json') { // TRANS: Client exception thrown when requesting a different format than JSON. throw new ClientException(_m('Invalid format; only JSON supported.')); } $url = $this->arg('url'); if (!common_valid_http_url($url)) { // TRANS: Client exception thrown when not providing a valid URL. throw new ClientException(_m('Invalid URL.')); } $params = array(); if ($this->arg('maxwidth')) { $params['maxwidth'] = $this->arg('maxwidth'); } if ($this->arg('maxheight')) { $params['maxheight'] = $this->arg('maxheight'); } $data = oEmbedHelper::getObject($url, $params); $this->init_document('json'); print json_encode($data); }
/** * Check pre-requisites and instantiate attributes * * @param Array $args array of arguments (URL, GET, POST) * * @return boolean success flag */ function prepare($args) { parent::prepare($args); if ($this->boolean('ajax')) { GNUsocial::setApi(true); } // Only allow POST requests if ($_SERVER['REQUEST_METHOD'] != 'POST') { // TRANS: Client error displayed trying to perform any request method other than POST. // TRANS: Do not translate POST. $this->clientError(_m('This action only accepts POST requests.')); } // CSRF protection $token = $this->trimmed('token'); if (!$token || $token != common_session_token()) { // TRANS: Client error displayed when the session token is not okay. $this->clientError(_m('There was a problem with your session token.' . ' Try again, please.')); } // Only for logged-in users $this->user = common_current_user(); if (empty($this->user)) { // TRANS: Error message displayed when trying to perform an action that requires a logged in user. $this->clientError(_m('Not logged in.')); } // Profile to subscribe to $this->search = $this->arg('search'); if (empty($this->search)) { // TRANS: Client error displayed trying to subscribe to a non-existing profile. $this->clientError(_m('No such profile.')); } return true; }
/** * For initializing members of the class. * * @param array $argarray misc. arguments * * @return boolean true */ function prepare($argarray) { parent::prepare($argarray); if ($this->boolean('ajax')) { GNUsocial::setApi(true); } $this->user = common_current_user(); if (empty($this->user)) { // TRANS: Client exception thrown trying to respond to a poll while not logged in. throw new ClientException(_m('You must be logged in to respond to a poll.'), 403); } if ($this->isPost()) { $this->checkSessionToken(); } $id = $this->trimmed('id'); $this->poll = Poll::getKV('id', $id); if (empty($this->poll)) { // TRANS: Client exception thrown trying to respond to a non-existing poll. throw new ClientException(_m('Invalid or missing poll.'), 404); } $selection = intval($this->trimmed('pollselection')); if ($selection < 1 || $selection > count($this->poll->getOptions())) { // TRANS: Client exception thrown responding to a poll with an invalid answer. throw new ClientException(_m('Invalid poll selection.')); } $this->selection = $selection; return true; }
/** * For initializing members of the class. * * @param array $argarray misc. arguments * * @return boolean true */ function prepare($argarray) { parent::prepare($argarray); if ($this->boolean('ajax')) { GNUsocial::setApi(true); // short error results! } $rsvpId = $this->trimmed('rsvp'); if (empty($rsvpId)) { // TRANS: Client exception thrown when referring to a non-existing RSVP ("please respond") item. throw new ClientException(_m('No such RSVP.')); } $this->rsvp = RSVP::getKV('id', $rsvpId); if (empty($this->rsvp)) { // TRANS: Client exception thrown when referring to a non-existing RSVP ("please respond") item. throw new ClientException(_m('No such RSVP.')); } $this->event = Happening::getKV('id', $this->rsvp->event_id); if (empty($this->event)) { // TRANS: Client exception thrown when referring to a non-existing event. throw new ClientException(_m('No such event.')); } $this->user = common_current_user(); if (empty($this->user)) { // TRANS: Client exception thrown when trying tp RSVP ("please respond") while not logged in. throw new ClientException(_m('You must be logged in to RSVP for an event.')); } return true; }
protected function doPost() { try { $request = Subscription_queue::pkeyGet(array('subscriber' => $this->scoped->id, 'subscribed' => $this->target->id)); if ($request instanceof Subscription_queue) { $request->abort(); } } catch (AlreadyFulfilledException $e) { common_debug('Tried to cancel a non-existing pending subscription'); } if (GNUsocial::isAjax()) { $this->startHTML('text/xml;charset=utf-8'); $this->elementStart('head'); // TRANS: Title after unsubscribing from a group. $this->element('title', null, _m('TITLE', 'Unsubscribed')); $this->elementEnd('head'); $this->elementStart('body'); $subscribe = new SubscribeForm($this, $this->target); $subscribe->show(); $this->elementEnd('body'); $this->endHTML(); exit; } common_redirect(common_local_url('subscriptions', array('nickname' => $this->scoped->getNickname())), 303); }
/** * Check for an API key, and throw an exception if it's not set * * @param array $args URL and POST params * * @return boolean continuation flag */ function prepare($args) { GNUsocial::setApi(true); // reduce exception reports to aid in debugging parent::prepare($args); if (!common_config('globalapi', 'enabled')) { throw new ClientException(_('Global API not enabled.'), 403); } $apikey = $this->trimmed('apikey'); if (empty($apikey)) { throw new ClientException(_('No API key.'), 403); } $expected = common_config('globalapi', 'key'); if ($expected != $apikey) { // FIXME: increment a counter by IP address to prevent brute-force // attacks on the key. throw new ClientException(_('Bad API key.'), 403); } $email = common_canonical_email($this->trimmed('email')); if (empty($email)) { throw new ClientException(_('No email address.')); } if (!Validate::email($email, common_config('email', 'check_domain'))) { throw new ClientException(_('Invalid email address.')); } $this->email = $email; return true; }
protected function handle() { GNUsocial::setApi(true); // Minimize error messages to aid in debugging parent::handle(); if ($this->isPost()) { return $this->handlePost(); } return $this->handleGet(); }
protected function showActionContent(ManagedAction $action, $verb, Notice $target, Profile $scoped) { if (!GNUsocial::isAjax()) { $nl = new NoticeListItem($target, $action, array('options' => false, 'attachments' => false, 'item_tag' => 'div', 'id_prefix' => 'fave')); $nl->show(); } $form = $this->getActivityForm($action, $verb, $target, $scoped); $form->show(); return false; }
protected function prepare(array $args = array()) { GNUsocial::setApi(true); // Send smaller error pages parent::prepare($args); if (!isset($_SERVER['CONTENT_TYPE'])) { // TRANS: Client error. Do not translate "Content-type" $this->clientError(_m('Salmon requires a Content-type header.')); } $envxml = null; switch ($_SERVER['CONTENT_TYPE']) { case 'application/magic-envelope+xml': $envxml = file_get_contents('php://input'); break; case 'application/x-www-form-urlencoded': $envxml = Magicsig::base64_url_decode($this->trimmed('xml')); break; default: // TRANS: Client error. Do not translate the quoted "application/[type]" strings. $this->clientError(_m('Salmon requires "application/magic-envelope+xml". For Diaspora we also accept "application/x-www-form-urlencoded" with an "xml" parameter.', 415)); } try { if (empty($envxml)) { throw new ClientException('No magic envelope supplied in POST.'); } $magic_env = new MagicEnvelope($envxml); // parse incoming XML as a MagicEnvelope $entry = $magic_env->getPayload(); // Not cryptographically verified yet! $this->activity = new Activity($entry->documentElement); if (empty($this->activity->actor->id)) { common_log(LOG_ERR, "broken actor: " . var_export($this->activity->actor->id, true)); common_log(LOG_ERR, "activity with no actor: " . var_export($this->activity, true)); // TRANS: Exception. throw new Exception(_m('Received a salmon slap from unidentified actor.')); } // ensureProfiles sets $this->actor and $this->oprofile $this->ensureProfiles(); } catch (Exception $e) { common_debug('Salmon envelope parsing failed with: ' . $e->getMessage()); $this->clientError($e->getMessage()); } // Cryptographic verification test if (!$magic_env->verify($this->actor)) { common_log(LOG_DEBUG, "Salmon signature verification failed."); // TRANS: Client error. $this->clientError(_m('Salmon signature verification failed.')); } return true; }
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 showPage() { if (GNUsocial::isAjax()) { $this->extraHeaders(); $this->ajaxErrorMsg(); exit; } if ($this->minimal) { // Even more minimal -- we're in a machine API // and don't want to flood the output. $this->extraHeaders(); $this->showContent(); } else { parent::showPage(); } // We don't want to have any more output after this exit; }
/** * Show the form for OpenID management * * We have one form with a few different submit buttons to do different things. * * @return void */ function showContent() { $provider = $this->trimmed('provider'); if (!empty($provider) || GNUsocial::isAjax()) { $this->showAddFeedForm($provider); } else { $this->elementStart('div', array('id' => 'add-mirror')); $this->showAddWizard(); $this->elementEnd('div'); $mirror = new SubMirror(); $mirror->subscriber = $this->scoped->getID(); if ($mirror->find()) { while ($mirror->fetch()) { $this->showFeedForm($mirror); } } } }
/** * For initializing members of the class. * * @param array $argarray misc. arguments * * @return boolean true */ function prepare($argarray) { parent::prepare($argarray); if ($this->boolean('ajax')) { GNUsocial::setApi(true); } $this->user = common_current_user(); if (empty($this->user)) { throw new ClientException(_m("You must be logged in to answer to a question."), 403); } $id = substr($this->trimmed('id'), 7); $this->answer = QnA_Answer::getKV('id', $id); $this->question = $this->answer->getQuestion(); if (empty($this->answer) || empty($this->question)) { throw new ClientException(_m('Invalid or missing answer.'), 404); } $this->answerText = $this->trimmed('answer'); return true; }
protected function prepare(array $args = array()) { // If we die, show short error messages. GNUsocial::setApi(true); parent::prepare($args); $this->groups = array(); $this->profiles = array(); $term = $this->arg('term'); $limit = $this->arg('limit'); if ($limit > 200) { $limit = 200; } //prevent DOS attacks if (substr($term, 0, 1) == '@') { //profile search $term = substr($term, 1); $profile = new Profile(); $profile->limit($limit); $profile->whereAdd('nickname like \'' . trim($profile->escape($term), '\'') . '%\''); $profile->whereAdd(sprintf('id in (SELECT id FROM user) OR ' . 'id in (SELECT subscribed from subscription' . ' where subscriber = %d)', $this->scoped->id)); if ($profile->find()) { while ($profile->fetch()) { $this->profiles[] = clone $profile; } } } if (substr($term, 0, 1) == '!') { //group search $term = substr($term, 1); $group = new User_group(); $group->limit($limit); $group->whereAdd('nickname like \'' . trim($group->escape($term), '\'') . '%\''); //Can't post to groups we're not subscribed to...: $group->whereAdd(sprintf('id in (SELECT group_id FROM group_member' . ' WHERE profile_id = %d)', $this->scoped->id)); if ($group->find()) { while ($group->fetch()) { $this->groups[] = clone $group; } } } return true; }
/** * For initializing members of the class. * * @param array $argarray misc. arguments * * @return boolean true */ function prepare($argarray) { parent::prepare($argarray); if ($this->boolean('ajax')) { GNUsocial::setApi(true); } $this->user = common_current_user(); if (empty($this->user)) { // TRANS: Client exception thrown when trying to create a new bookmark while not logged in. throw new ClientException(_m('Must be logged in to post a bookmark.'), 403); } if ($this->isPost()) { $this->checkSessionToken(); } $this->title = $this->trimmed('title'); $this->url = $this->trimmed('url'); $this->tags = $this->trimmed('tags'); $this->description = $this->trimmed('description'); return true; }
/** * For initializing members of the class. * * @param array $argarray misc. arguments * * @return boolean true */ function prepare($argarray) { parent::prepare($argarray); if ($this->boolean('ajax')) { GNUsocial::setApi(true); } $this->user = common_current_user(); if (empty($this->user)) { throw new ClientException(_m("You must be logged in to close a question."), 403); } if ($this->isPost()) { $this->checkSessionToken(); } $id = substr($this->trimmed('id'), 9); $this->question = QnA_Question::getKV('id', $id); if (empty($this->question)) { // TRANS: Client exception thrown trying to respond to a non-existing question. throw new ClientException(_m('Invalid or missing question.'), 404); } return true; }
/** * For initializing members of the class. * * @param array $argarray misc. arguments * * @return boolean true */ function prepare($argarray) { parent::prepare($argarray); if ($this->boolean('ajax')) { GNUsocial::setApi(true); // short error results! } $eventId = $this->trimmed('event'); if (empty($eventId)) { // TRANS: Client exception thrown when referring to a non-existing event. throw new ClientException(_m('No such event.')); } $this->event = Happening::getKV('id', $eventId); if (empty($this->event)) { // TRANS: Client exception thrown when referring to a non-existing event. throw new ClientException(_m('No such event.')); } $this->user = common_current_user(); if (empty($this->user)) { // TRANS: Client exception thrown when trying to RSVP ("please respond") while not logged in. throw new ClientException(_m('You must be logged in to RSVP for an event.')); } common_debug(print_r($this->args, true)); switch (strtolower($this->trimmed('submitvalue'))) { case 'yes': $this->verb = RSVP::POSITIVE; break; case 'no': $this->verb = RSVP::NEGATIVE; break; case 'maybe': $this->verb = RSVP::POSSIBLE; break; default: // TRANS: Client exception thrown when using an invalid value for RSVP ("please respond"). throw new ClientException(_m('Unknown submit value.')); } return true; }
/** * For initializing members of the class. * * @param array $argarray misc. arguments * * @return boolean true */ function prepare($argarray) { parent::prepare($argarray); if ($this->boolean('ajax')) { GNUsocial::setApi(true); } common_debug("in qnanewanswer"); $this->user = common_current_user(); if (empty($this->user)) { throw new ClientException(_m("You must be logged in to answer to a question."), 403); } if ($this->isPost()) { $this->checkSessionToken(); } $id = substr($this->trimmed('id'), 9); $this->question = QnA_Question::getKV('id', $id); if (empty($this->question)) { throw new ClientException(_m('Invalid or missing question.'), 404); } $this->answerText = $this->trimmed('answer'); 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; }
static function mailPaths() { $paths = array(INSTALLDIR . '/local/mail-src/', INSTALLDIR . '/mail-src/'); $site = GNUsocial::currentSite(); if (!empty($site)) { array_unshift($paths, INSTALLDIR . '/local/mail-src/' . $site . '/'); } return $paths; }
/** * The beef of the installer! * Create database, config file, and admin user. * * Prerequisites: validation of input data. * * @return boolean success */ function doInstall() { global $config; $this->updateStatus("Initializing..."); ini_set('display_errors', 1); error_reporting(E_ALL & ~E_STRICT & ~E_NOTICE); if (!defined('GNUSOCIAL')) { define('GNUSOCIAL', true); } if (!defined('STATUSNET')) { define('STATUSNET', true); } require_once INSTALLDIR . '/lib/framework.php'; GNUsocial::initDefaults($this->server, $this->path); if ($this->siteProfile == "singleuser") { // Until we use ['site']['profile']==='singleuser' everywhere $config['singleuser']['enabled'] = true; } try { $this->db = $this->setupDatabase(); if (!$this->db) { // database connection failed, do not move on to create config file. return false; } } catch (Exception $e) { // Lower-level DB error! $this->updateStatus("Database error: " . $e->getMessage(), true); return false; } // Make sure we can write to the file twice $oldUmask = umask(00); if (!$this->skipConfig) { $this->updateStatus("Writing config file..."); $res = $this->writeConf(); if (!$res) { $this->updateStatus("Can't write config file.", true); return false; } } if (!empty($this->adminNick)) { // Okay, cross fingers and try to register an initial user if ($this->registerInitialUser()) { $this->updateStatus("An initial user with the administrator role has been created."); } else { $this->updateStatus("Could not create initial user account.", true); return false; } } if (!$this->skipConfig) { $this->updateStatus("Setting site profile..."); $res = $this->writeSiteProfile(); if (!$res) { $this->updateStatus("Can't write to config file.", true); return false; } } // Restore original umask umask($oldUmask); // Set permissions back to something decent chmod(INSTALLDIR . '/config.php', 0644); $scheme = $this->ssl === 'always' ? 'https' : 'http'; $link = "{$scheme}://{$this->server}/{$this->path}"; $this->updateStatus("GNU social has been installed at {$link}"); $this->updateStatus('<strong>DONE!</strong> You can visit your <a href="' . htmlspecialchars($link) . '">new GNU social site</a> (log in as "' . htmlspecialchars($this->adminNick) . '"). If this is your first GNU social install, make your experience the best possible by visiting our resource site to join the <a href="https://gnu.io/social/resources/">mailing list or IRC.</a>. <a href="' . htmlspecialchars($link) . '/doc/faq/">FAQ is found here</a>.'); 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((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; }
/** * Load the default or specified configuration file. * Modifies global $config and may establish plugins. * * @throws NoConfigException */ protected static function loadConfigFile($conffile = null) { global $_server, $_path, $config; // From most general to most specific: // server-wide, then vhost-wide, then for a path, // finally for a dir (usually only need one of the last two). if (isset($conffile)) { $config_files = array($conffile); } else { $config_files = array('/etc/statusnet/statusnet.php', '/etc/statusnet/laconica.php', '/etc/laconica/laconica.php', '/etc/statusnet/' . $_server . '.php', '/etc/laconica/' . $_server . '.php'); if (strlen($_path) > 0) { $config_files[] = '/etc/statusnet/' . $_server . '_' . $_path . '.php'; $config_files[] = '/etc/laconica/' . $_server . '_' . $_path . '.php'; } $config_files[] = INSTALLDIR . '/config.php'; } self::$have_config = false; foreach ($config_files as $_config_file) { if (@file_exists($_config_file)) { // Ignore 0-byte config files if (filesize($_config_file) > 0) { include $_config_file; self::$config_files[] = $_config_file; self::$have_config = true; } } } if (!self::$have_config) { throw new NoConfigException("No configuration file found.", $config_files); } // Check for database server; must exist! if (empty($config['db']['database'])) { throw new ServerException("No database server for this site."); } }
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(); } } }
/** * 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)); } }
function showRepresentation() { if (Event::handle('StartShowAttachmentRepresentation', array($this->out, $this->attachment))) { if (!empty($this->attachment->mimetype)) { $mediatype = common_get_mime_media($this->attachment->mimetype); // FIXME: Get proper mime recognition of Ogg files! If system has 'mediainfo', this should do it: // $ mediainfo --inform='General;%InternetMediaType%' if ($this->attachment->mimetype === 'application/ogg') { $mediatype = 'video'; // because this element can handle Ogg/Vorbis etc. on its own } switch ($mediatype) { // Anything we understand as an image, if we need special treatment, do it in StartShowAttachmentRepresentation case 'image': try { // Tell getThumbnail that we can show an animated image if it has one (4th arg, "force_still") $thumb = $this->attachment->getThumbnail(null, null, false, false); $this->out->element('img', array('class' => 'u-photo', 'src' => $thumb->getUrl(), 'alt' => '')); } catch (UseFileAsThumbnailException $e) { $this->out->element('img', array('class' => 'u-photo', 'src' => $e->file->getUrl(), 'alt' => $e->file->title)); } catch (UnsupportedMediaException $e) { // FIXME: Show a good representation of unsupported/unshowable images } break; // HTML5 media elements // HTML5 media elements case 'audio': case 'video': try { $thumb = $this->attachment->getThumbnail(); $poster = $thumb->getUrl(); unset($thumb); } catch (Exception $e) { $poster = null; } $this->out->elementStart($mediatype, array('class' => "attachment_player u-{$mediatype}", 'poster' => $poster, 'controls' => 'controls')); $this->out->element('source', array('src' => $this->attachment->getUrl(), 'type' => $this->attachment->mimetype)); $this->out->elementEnd($mediatype); break; default: switch ($this->attachment->mimetype) { case 'text/html': if (!empty($this->attachment->filename) && (GNUsocial::isAjax() || common_config('attachments', 'show_html'))) { // Locally-uploaded HTML. Scrub and display inline. $this->showHtmlFile($this->attachment); break; } // Fall through to default if it wasn't a _local_ text/html File object // Fall through to default if it wasn't a _local_ text/html File object default: Event::handle('ShowUnsupportedAttachmentRepresentation', array($this->out, $this->attachment)); } } } else { Event::handle('ShowUnsupportedAttachmentRepresentation', array($this->out, $this->attachment)); } } Event::handle('EndShowAttachmentRepresentation', array($this->out, $this->attachment)); }
protected function prepare(array $args = array()) { GNUsocial::setApi(true); // reduce exception reports to aid in debugging return parent::prepare($args); }
break; case 'invite': $reminders[] = $types['invite']; break; case 'all': $reminders = $types; break; } if (have_option('u', 'universe')) { $sn = new Status_network(); try { if ($sn->find()) { while ($sn->fetch()) { try { $server = $sn->getServerName(); GNUsocial::init($server); // Different queue manager, maybe! $qm = QueueManager::get(); foreach ($reminders as $reminder) { extract($reminder); $qm->enqueue(array($type, $opts), 'siterem'); if (!$quiet) { print "Sent pending {$type} reminders for {$server}.\n"; } } } catch (Exception $e) { // keep going common_log(LOG_ERR, "Couldn't init {$server}.\n", __FILE__); if (!$quiet) { print "Couldn't init {$server}.\n"; }
/** * 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; }