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;
}
common_config_set('db', 'database', $mirror);
}
- $status = $this->prepare($args);
- if ($status) {
- $this->handle($args);
- } else {
- common_debug('Prepare failed for Action.');
- }
-
- $this->flush();
+ if (Event::handle('StartActionExecute', array($this, &$args))) {
+ $prepared = $this->prepare($args);
+ if ($prepared) {
+ $this->handle($args);
+ } else {
+ common_debug('Prepare failed for Action.');
+ }
- Event::handle('EndActionExecute', array($status, $this));
+ $this->flush();
+ Event::handle('EndActionExecute', array($this));
+ }
}
/**
$this->action = strtolower($this->trimmed('action'));
if ($this->ajax || $this->boolean('ajax')) {
- // check with StatusNet::isAjax()
- StatusNet::setAjax(true);
+ // check with GNUsocial::isAjax()
+ GNUsocial::setAjax(true);
}
if ($this->needLogin) {
*
* @return nothing
*/
- function showPage()
+ public function showPage()
{
- if (StatusNet::isAjax()) {
+ if (GNUsocial::isAjax()) {
self::showAjax();
return;
}
} else {
// favicon.ico should be HTTPS if the rest of the page is
$this->element('link', array('rel' => 'shortcut icon',
- 'href' => common_path('favicon.ico', StatusNet::isHTTPS())));
+ 'href' => common_path('favicon.ico', GNUsocial::isHTTPS())));
}
if (common_config('site', 'mobile')) {
{
$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', StatusNet::isHTTPS()).'"); }');
- $this->script('extlib/jquery.infieldlabel.js');
Event::handle('EndShowJQueryScripts', array($this));
}
$this->inlineScript('var _peopletagAC = "' .
common_local_url('peopletagautocomplete') . '";');
$this->showScriptMessages();
+ $this->showScriptVariables();
// Anti-framing code to avoid clickjacking attacks in older browsers.
// This will show a blank page if the page is being framed, which is
// consistent with the behavior of the 'X-Frame-Options: SAMEORIGIN'
// TRANS: Localized tooltip for '...' expansion button on overlong remote messages.
$messages['showmore_tooltip'] = _m('TOOLTIP', 'Show more');
-
- // TRANS: Inline reply form submit button: submits a reply comment.
- $messages['reply_submit'] = _m('BUTTON', 'Reply');
-
- // TRANS: Placeholder text for inline reply form. Clicking in this box will turn it into a mini notice form.
- $messages['reply_placeholder'] = _m('Write a reply...');
+ $messages['popup_close_button'] = _m('TOOLTIP', 'Close popup');
$messages = array_merge($messages, $this->getScriptMessages());
return $messages;
}
+ protected function showScriptVariables()
+ {
+ $vars = array();
+
+ if (Event::handle('StartScriptVariables', array($this, &$vars))) {
+ $vars['urlNewNotice'] = common_local_url('newnotice');
+ }
+ if (!empty($vars)) {
+ $this->inlineScript('SN.V = ' . json_encode($vars));
+ }
+ return $vars;
+ }
+
/**
* If the action will need localizable text strings, export them here like so:
*
*/
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));
}
}
$this->elementStart('a', array('class' => 'home bookmark',
'href' => $url));
- if (StatusNet::isHTTPS()) {
+ if (GNUsocial::isHTTPS()) {
$logoUrl = common_config('site', 'ssllogo');
if (empty($logoUrl)) {
// if logo is an uploaded file, try to fall back to HTTPS file URL
function showExportData()
{
$feeds = $this->getFeeds();
- if ($feeds) {
- $fl = new FeedList($this);
- $fl->show($feeds);
+ if (!empty($feeds)) {
+ $fl = new FeedList($this, $feeds);
+ $fl->show();
}
}
$image = common_config('license', 'image');
$sslimage = common_config('license', 'sslimage');
- if (StatusNet::isHTTPS()) {
+ 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);
+ $url = preg_replace('/^http/', 'https', $image, 1);
} else {
// Better to show mixed content than no content
$url = $image;
}
}
+ /**
+ * This is a cheap hack to avoid a bug in DB_DataObject
+ * where '' is non-type-aware compared to 0, which means it
+ * will always be true for values like false and 0 too...
+ *
+ * Upstream bug is::
+ * https://pear.php.net/bugs/bug.php?id=20291
+ */
+ function booleanintstring($key, $def=false)
+ {
+ return $this->boolean($key, $def) ? '1' : '0';
+ }
+
/**
* Integer value of an argument
*
$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();
}
/**