X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=lib%2Faction.php;h=4e629c2bc34d0b6c3fb730670d53bdbafc6ebe69;hb=73dbc5ca1b203758693f73d6423fea71ef6b6fb6;hp=66a5c69a719dd009bd00c2b661079300020203d9;hpb=f35ea45e09a344f405f4a4c45f1c6a34d7e835e0;p=quix0rs-gnu-social.git diff --git a/lib/action.php b/lib/action.php index 66a5c69a71..4e629c2bc3 100644 --- a/lib/action.php +++ b/lib/action.php @@ -95,9 +95,22 @@ class Action extends HTMLOutputter // lawsuit 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; } @@ -125,11 +138,10 @@ class Action extends HTMLOutputter // lawsuit } else { common_debug('Prepare failed for Action.'); } - } - $this->flush(); - - Event::handle('EndActionExecute', array($this)); + $this->flush(); + Event::handle('EndActionExecute', array($this)); + } } /** @@ -206,7 +218,7 @@ class Action extends HTMLOutputter // lawsuit * * @return nothing */ - function showPage() + public function showPage() { if (GNUsocial::isAjax()) { self::showAjax(); @@ -417,8 +429,6 @@ class Action extends HTMLOutputter // lawsuit $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()).'"); }'); - $this->script('extlib/jquery.infieldlabel.js'); Event::handle('EndShowJQueryScripts', array($this)); } @@ -432,6 +442,7 @@ class Action extends HTMLOutputter // lawsuit $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' @@ -461,12 +472,7 @@ class Action extends HTMLOutputter // lawsuit // 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()); @@ -480,6 +486,19 @@ class Action extends HTMLOutputter // lawsuit 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: * @@ -528,15 +547,11 @@ class Action extends HTMLOutputter // lawsuit */ 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)); } } @@ -1029,9 +1044,9 @@ class Action extends HTMLOutputter // lawsuit function showExportData() { $feeds = $this->getFeeds(); - if ($feeds) { - $fl = new FeedList($this); - $fl->show($feeds); + if (!empty($feeds)) { + $fl = new FeedList($this, $feeds); + $fl->show(); } } @@ -1151,7 +1166,7 @@ class Action extends HTMLOutputter // lawsuit $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; @@ -1364,7 +1379,7 @@ class Action extends HTMLOutputter // lawsuit * 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'; } @@ -1440,7 +1455,9 @@ class Action extends HTMLOutputter // lawsuit $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); @@ -1468,7 +1485,7 @@ class Action extends HTMLOutputter // lawsuit if (!array_key_exists($code, ClientErrorAction::$status)) { $code = 400; } - + $status_string = ClientErrorAction::$status[$code]; switch ($format) { @@ -1487,7 +1504,7 @@ class Action extends HTMLOutputter // lawsuit } $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': @@ -1496,7 +1513,9 @@ class Action extends HTMLOutputter // lawsuit 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); } @@ -1652,7 +1671,7 @@ class Action extends HTMLOutputter // lawsuit */ function getFeeds() { - return null; + return array(); } /**