return $this->msg;
}
+ public function handleError($e)
+ {
+ if ($e instanceof ClientException) {
+ $this->clientError($e->getMessage(), $e->getCode());
+ } elseif ($e instanceof ServerException) {
+ $this->serverError($e->getMessage(), $e->getCode());
+ } else {
+ // If it wasn't specified more closely which kind of exception it was
+ $this->serverError($e->getMessage(), 500);
+ }
+ }
+
static public function run(array $args=array(), $output='php://output', $indent=null) {
$class = get_called_class();
$action = new $class($output, $indent);
+ set_exception_handler(array($action, 'handleError'));
$action->execute($args);
return $action;
}
} else {
common_debug('Prepare failed for Action.');
}
- }
-
- $this->flush();
- Event::handle('EndActionExecute', array($this));
+ $this->flush();
+ Event::handle('EndActionExecute', array($this));
+ }
}
/**
*
* @return nothing
*/
- function showPage()
+ public function showPage()
{
if (GNUsocial::isAjax()) {
self::showAjax();
{
$theme = new Theme($mainTheme);
- // Some themes may have external stylesheets, such as using the
- // Google Font APIs to load webfonts.
+ // Some themes may have external stylesheets
foreach ($theme->getExternals() as $url) {
$this->cssLink($url, $mainTheme, $media);
}
$this->script('extlib/jquery.form.js');
$this->script('extlib/jquery-ui/jquery-ui.js');
$this->script('extlib/jquery.cookie.js');
- $this->inlineScript('if (typeof window.JSON !== "object") { $.getScript("'.common_path('js/extlib/json2.js', GNUsocial::isHTTPS()).'"); }');
Event::handle('EndShowJQueryScripts', array($this));
}
if (Event::handle('StartShowStatusNetScripts', array($this))) {
$this->script('util.js');
$this->script('xbImportNode.js');
- $this->script('geometa.js');
// This route isn't available in single-user mode.
// Not sure why, but it causes errors here.
// TRANS: Localized tooltip for '...' expansion button on overlong remote messages.
$messages['showmore_tooltip'] = _m('TOOLTIP', 'Show more');
+ $messages['popup_close_button'] = _m('TOOLTIP', 'Close popup');
$messages = array_merge($messages, $this->getScriptMessages());
if (Event::handle('StartScriptVariables', array($this, &$vars))) {
$vars['urlNewNotice'] = common_local_url('newnotice');
+ $vars['xhrTimeout'] = ini_get('max_execution_time')*1000; // milliseconds
+ Event::handle('EndScriptVariables', array($this, &$vars));
}
- if (!empty($vars)) {
- $this->inlineScript('SN.V = ' . json_encode($vars));
- }
+
+ $this->inlineScript('SN.V = ' . json_encode($vars) . ';');
+
return $vars;
}
*/
function showFeeds()
{
- $feeds = $this->getFeeds();
-
- if ($feeds) {
- foreach ($feeds as $feed) {
- $this->element('link', array('rel' => $feed->rel(),
- 'href' => $feed->url,
- 'type' => $feed->mimeType(),
- 'title' => $feed->title));
- }
+ foreach ($this->getFeeds() as $feed) {
+ $this->element('link', array('rel' => $feed->rel(),
+ 'href' => $feed->url,
+ 'type' => $feed->mimeType(),
+ 'title' => $feed->title));
}
}
// if logo is an uploaded file, try to fall back to HTTPS file URL
$httpUrl = common_config('site', 'logo');
if (!empty($httpUrl)) {
- $f = File::getKV('url', $httpUrl);
- if (!empty($f) && !empty($f->filename)) {
- // this will handle the HTTPS case
- $logoUrl = File::url($f->filename);
+ try {
+ $f = File::getByUrl($httpUrl);
+ if (!empty($f->filename)) {
+ // this will handle the HTTPS case
+ $logoUrl = File::url($f->filename);
+ }
+ } catch (NoResultException $e) {
+ // no match
}
}
}
function showExportData()
{
$feeds = $this->getFeeds();
- if ($feeds) {
- $fl = new FeedList($this);
- $fl->show($feeds);
+ if (!empty($feeds)) {
+ $fl = new FeedList($this, $feeds);
+ $fl->show();
}
}
$url = $sslimage;
} else if (preg_match('#^http://i.creativecommons.org/#', $image)) {
// CC support HTTPS on their images
- $url = preg_replace('/^http/', 'https', $image);
+ $url = preg_replace('/^http/', 'https', $image, 1);
} else {
// Better to show mixed content than no content
$url = $image;
* Upstream bug is::
* https://pear.php.net/bugs/bug.php?id=20291
*/
- function booleanintstring($key, $def)
+ function booleanintstring($key, $def=false)
{
return $this->boolean($key, $def) ? '1' : '0';
}
$this->endDocument('json');
break;
default:
- throw new ServerException($msg, $code);
+ common_log(LOG_ERR, 'Handled serverError ('._ve($code).') but cannot output into desired format ('._ve($this->format).'): '._ve($msg));
+ $action = new ServerErrorAction($msg, $code);
+ $action->execute();
}
exit((int)$code);
if (!array_key_exists($code, ClientErrorAction::$status)) {
$code = 400;
}
-
+
$status_string = ClientErrorAction::$status[$code];
switch ($format) {
}
$this->initDocument('json');
$error_array = array('error' => $msg, 'request' => $_SERVER['REQUEST_URI']);
- $this->text(json_encode($error_array));
+ print(json_encode($error_array));
$this->endDocument('json');
break;
case 'text':
echo $msg;
break;
default:
- throw new ClientException($msg, $code);
+ common_log(LOG_ERR, 'Handled clientError ('._ve($code).') but cannot output into desired format ('._ve($this->format).'): '._ve($msg));
+ $action = new ClientErrorAction($msg, $code);
+ $action->execute();
}
exit((int)$code);
}
*/
function getFeeds()
{
- return null;
+ return array();
}
/**