protected $ajax = false;
protected $menus = true;
protected $needLogin = false;
- protected $needPost = false;
+ protected $needPost = false; // implies canPost if true
+ protected $canPost = false; // can this action handle POST method?
// The currently scoped profile (normally Profile::current; from $this->auth_user for API)
protected $scoped = null;
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->clientError(_('This method requires a POST.'), 405);
}
+ // needPost, of course, overrides canPost if true
+ if (!$this->canPost) {
+ $this->canPost = $this->needPost;
+ }
+
$this->args = common_copy_args($args);
- $this->action = $this->trimmed('action');
+ // This could be set with get_called_action and then
+ // chop off 'Action' from the class name. In lower case.
+ $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 true;
}
- function updateScopedProfile() {
+ public function updateScopedProfile()
+ {
$this->scoped = Profile::current();
return $this->scoped;
}
+ public function getScoped()
+ {
+ return ($this->scoped instanceof Profile) ? $this->scoped : null;
+ }
+
+ // Must be run _after_ prepare
+ public function getActionName()
+ {
+ return $this->action;
+ }
+
+ public function isAction(array $names)
+ {
+ foreach ($names as $class) {
+ // PHP is case insensitive, and we have stuff like ApiUpperCaseAction,
+ // but we at least make a point out of wanting to do stuff case-sensitive.
+ $class = ucfirst($class) . 'Action';
+ if ($this instanceof $class) {
+ return true;
+ }
+ }
+ return false;
+ }
+
/**
* Show page, a template method.
*
*/
function showPage()
{
+ if (GNUsocial::isAjax()) {
+ self::showAjax();
+ return;
+ }
if (Event::handle('StartShowHTML', array($this))) {
$this->startHTML();
$this->flush();
}
}
+ public function showAjax()
+ {
+ $this->startHTML('text/xml;charset=utf-8');
+ $this->elementStart('head');
+ // TRANS: Title for conversation page.
+ $this->element('title', null, $this->title());
+ $this->elementEnd('head');
+ $this->elementStart('body');
+ if ($this->getError()) {
+ $this->element('p', array('id'=>'error'), $this->getError());
+ } else {
+ $this->showContent();
+ }
+ $this->elementEnd('body');
+ $this->endHTML();
+ }
+
function endHTML()
{
global $_startTime;
} 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')) {
$this->cssLink('js/extlib/jquery-ui/css/smoothness/jquery-ui.css');
if (Event::handle('StartShowUAStyles', array($this))) {
- $this->comment('[if IE]><link rel="stylesheet" type="text/css" '.
- 'href="'.Theme::path('css/ie.css', 'base').'?version='.GNUSOCIAL_VERSION.'" /><![endif]');
- foreach (array(6,7) as $ver) {
- if (file_exists(Theme::file('css/ie'.$ver.'.css', 'base'))) {
- // Yes, IE people should be put in jail.
- $this->comment('[if lte IE '.$ver.']><link rel="stylesheet" type="text/css" '.
- 'href="'.Theme::path('css/ie'.$ver.'.css', 'base').'?version='.GNUSOCIAL_VERSION.'" /><![endif]');
- }
- }
- if (file_exists(Theme::file('css/ie.css'))) {
- $this->comment('[if IE]><link rel="stylesheet" type="text/css" '.
- 'href="'.Theme::path('css/ie.css', null).'?version='.GNUSOCIAL_VERSION.'" /><![endif]');
- }
Event::handle('EndShowUAStyles', array($this));
}
$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');
+ $this->inlineScript('if (typeof window.JSON !== "object") { $.getScript("'.common_path('js/extlib/json2.js', GNUsocial::isHTTPS()).'"); }');
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 = array_merge($messages, $this->getScriptMessages());
Event::handle('EndScriptMessages', array($this, &$messages));
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));
}
}
*/
function showBody()
{
- $this->elementStart('body', (common_current_user()) ? array('id' => strtolower($this->trimmed('action')),
- 'class' => 'user_in')
- : array('id' => strtolower($this->trimmed('action'))));
+ $params = array('id' => $this->getActionName());
+ if ($this->scoped instanceof Profile) {
+ $params['class'] = 'user_in';
+ }
+ $this->elementStart('body', $params);
$this->elementStart('div', array('id' => 'wrap'));
if (Event::handle('StartShowHeader', array($this))) {
$this->showHeader();
*/
function showLogo()
{
- $this->elementStart('address', array('id' => 'site_contact',
- 'class' => 'vcard'));
+ $this->elementStart('address', array('id' => 'site_contact', 'class' => 'h-card'));
if (Event::handle('StartAddressData', array($this))) {
if (common_config('singleuser', 'enabled')) {
$user = User::singleUser();
$url = common_local_url('public');
}
- $this->elementStart('a', array('class' => 'url home bookmark',
+ $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
}
if (!empty($logoUrl)) {
- $this->element('img', array('class' => 'logo photo',
+ $this->element('img', array('class' => 'logo u-photo p-name',
'src' => $logoUrl,
'alt' => common_config('site', 'name')));
}
- $this->text(' ');
- $this->element('span', array('class' => 'fn org'), common_config('site', 'name'));
$this->elementEnd('a');
Event::handle('EndAddressData', array($this));
$this->elementStart('div', 'input_forms');
+ $this->element('label', array('for'=>'input_form_nav'), _m('TAB', 'Share your:'));
+
if (Event::handle('StartShowEntryForms', array(&$tabs))) {
$this->elementStart('ul', array('class' => 'nav',
'id' => 'input_form_nav'));
'class' => 'input_form_nav_tab');
if ($tag == 'status') {
- // We're actually showing the placeholder form,
- // but we special-case the 'Status' tab as if
- // it were a small version of it.
$attrs['class'] .= ' current';
}
$this->elementStart('li', $attrs);
$this->elementEnd('ul');
- $attrs = array('class' => 'input_form current',
- 'id' => 'input_form_placeholder');
- $this->elementStart('div', $attrs);
- $form = new NoticePlaceholderForm($this);
- $form->show();
- $this->elementEnd('div');
-
foreach ($tabs as $tag => $data) {
$attrs = array('class' => 'input_form',
'id' => 'input_form_'.$tag);
+ if ($tag == 'status') {
+ $attrs['class'] .= ' current';
+ }
$this->elementStart('div', $attrs);
*
* @return nothing
*/
- function showContent()
+ protected function showContent()
{
}
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)) {
// 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 = "<a class=\"license\" rel=\"external license\" href=\"" .
- htmlspecialchars(common_config('license', 'url')) .
- "\">" .
- htmlspecialchars(common_config('license', 'title')) .
- "</a>";
- $this->raw(sprintf(htmlspecialchars($notice),
+ $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');
}
}
+ /**
+ * 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
*
*/
function int($key, $defValue=null, $maxValue=null, $minValue=null)
{
- $arg = strtolower($this->trimmed($key));
+ $arg = intval($this->arg($key));
- if (is_null($arg) || !is_integer($arg)) {
+ if (!is_numeric($this->arg($key)) || $arg != $this->arg($key)) {
return $defValue;
}
*/
function returnToArgs()
{
- $action = $this->trimmed('action');
+ $action = $this->getActionName();
$args = $this->args;
unset($args['action']);
if (common_config('site', 'fancy')) {
*/
function getFeeds()
{
- return null;
+ return array();
}
/**