2011-03-06 04:48:10 +09:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* StatusNet - the distributed open-source microblogging tool
|
|
|
|
* Copyright (C) 2011, StatusNet, Inc.
|
|
|
|
*
|
|
|
|
* Superclass for microapp plugin
|
2011-04-03 08:09:02 +09:00
|
|
|
*
|
2011-03-06 04:48:10 +09:00
|
|
|
* PHP version 5
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Affero General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Affero General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
* @category Microapp
|
|
|
|
* @package StatusNet
|
|
|
|
* @author Evan Prodromou <evan@status.net>
|
|
|
|
* @copyright 2011 StatusNet, Inc.
|
|
|
|
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
|
|
|
|
* @link http://status.net/
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (!defined('STATUSNET')) {
|
|
|
|
// This check helps protect against security problems;
|
|
|
|
// your code file can't be executed directly from the web.
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Superclass for microapp plugins
|
|
|
|
*
|
|
|
|
* This class lets you define micro-applications with different kinds of activities.
|
|
|
|
*
|
2011-04-03 08:09:02 +09:00
|
|
|
* The applications work more-or-less like other
|
|
|
|
*
|
2011-03-06 04:48:10 +09:00
|
|
|
* @category Microapp
|
|
|
|
* @package StatusNet
|
|
|
|
* @author Evan Prodromou <evan@status.net>
|
|
|
|
* @copyright 2011 StatusNet, Inc.
|
|
|
|
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
|
|
|
|
* @link http://status.net/
|
|
|
|
*/
|
2014-06-24 23:42:34 +09:00
|
|
|
abstract class MicroAppPlugin extends ActivityHandlerPlugin
|
2011-03-06 04:48:10 +09:00
|
|
|
{
|
2011-03-08 06:36:15 +09:00
|
|
|
/**
|
|
|
|
* Returns a localized string which represents this micro-app,
|
|
|
|
* to be shown to users selecting what type of post to make.
|
|
|
|
* This is paired with the key string in $this->tag().
|
|
|
|
*
|
|
|
|
* All micro-app classes must override this method.
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
2011-03-07 06:33:36 +09:00
|
|
|
abstract function appTitle();
|
2011-03-08 06:36:15 +09:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns a key string which represents this micro-app in HTML
|
|
|
|
* ids etc, as when offering selection of what type of post to make.
|
|
|
|
* This is paired with the user-visible localizable $this->appTitle().
|
|
|
|
*
|
|
|
|
* All micro-app classes must override this method.
|
|
|
|
*/
|
2011-03-07 06:33:36 +09:00
|
|
|
abstract function tag();
|
2011-03-08 06:36:15 +09:00
|
|
|
|
|
|
|
/**
|
|
|
|
* When building the primary notice form, we'll fetch also some
|
|
|
|
* alternate forms for specialized types -- that's you!
|
|
|
|
*
|
|
|
|
* Return a custom Widget or Form object for the given output
|
|
|
|
* object, and it'll be included in the HTML output. Beware that
|
|
|
|
* your form may be initially hidden.
|
|
|
|
*
|
|
|
|
* All micro-app classes must override this method.
|
|
|
|
*
|
|
|
|
* @param HTMLOutputter $out
|
|
|
|
* @return Widget
|
|
|
|
*/
|
2011-03-07 06:33:36 +09:00
|
|
|
abstract function entryForm($out);
|
2011-03-08 06:36:15 +09:00
|
|
|
|
2014-02-24 10:05:31 +09:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
public function newFormAction() {
|
|
|
|
// such as 'newbookmark' or 'newevent' route
|
|
|
|
return 'new'.$this->tag();
|
|
|
|
}
|
|
|
|
|
2011-03-07 06:33:36 +09:00
|
|
|
/**
|
|
|
|
* Output the HTML for this kind of object in a list
|
|
|
|
*
|
|
|
|
* @param NoticeListItem $nli The list item being shown.
|
|
|
|
*
|
|
|
|
* @return boolean hook value
|
2011-03-08 08:15:21 +09:00
|
|
|
*
|
|
|
|
* @fixme WARNING WARNING WARNING this closes a 'div' that is implicitly opened in BookmarkPlugin's showNotice implementation
|
2011-03-07 06:33:36 +09:00
|
|
|
*/
|
|
|
|
function onStartShowNoticeItem($nli)
|
|
|
|
{
|
|
|
|
if (!$this->isMyNotice($nli->notice)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2011-04-20 04:43:06 +09:00
|
|
|
$adapter = $this->adaptNoticeListItem($nli);
|
|
|
|
|
|
|
|
if (!empty($adapter)) {
|
2011-04-20 06:55:57 +09:00
|
|
|
$adapter->showNotice();
|
|
|
|
$adapter->showNoticeAttachments();
|
|
|
|
$adapter->showNoticeInfo();
|
|
|
|
$adapter->showNoticeOptions();
|
2011-04-20 04:43:06 +09:00
|
|
|
} else {
|
|
|
|
$this->oldShowNotice($nli);
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Given a notice list item, returns an adapter specific
|
|
|
|
* to this plugin.
|
|
|
|
*
|
|
|
|
* @param NoticeListItem $nli item to adapt
|
|
|
|
*
|
|
|
|
* @return NoticeListItemAdapter adapter or null
|
|
|
|
*/
|
|
|
|
function adaptNoticeListItem($nli)
|
|
|
|
{
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
function oldShowNotice($nli)
|
|
|
|
{
|
2011-03-07 06:33:36 +09:00
|
|
|
$out = $nli->out;
|
2011-03-08 04:06:46 +09:00
|
|
|
$notice = $nli->notice;
|
2011-03-07 06:33:36 +09:00
|
|
|
|
2011-04-11 08:33:11 +09:00
|
|
|
try {
|
|
|
|
$this->showNotice($notice, $out);
|
|
|
|
} catch (Exception $e) {
|
|
|
|
common_log(LOG_ERR, $e->getMessage());
|
|
|
|
// try to fall back
|
2011-04-11 08:34:48 +09:00
|
|
|
$out->elementStart('div');
|
2011-04-11 08:33:11 +09:00
|
|
|
$nli->showAuthor();
|
|
|
|
$nli->showContent();
|
|
|
|
}
|
2011-03-07 06:33:36 +09:00
|
|
|
|
|
|
|
$nli->showNoticeLink();
|
|
|
|
$nli->showNoticeSource();
|
|
|
|
$nli->showNoticeLocation();
|
|
|
|
$nli->showContext();
|
|
|
|
$nli->showRepeat();
|
2011-04-03 08:09:02 +09:00
|
|
|
|
2011-03-07 06:33:36 +09:00
|
|
|
$out->elementEnd('div');
|
2011-04-03 08:09:02 +09:00
|
|
|
|
2011-03-07 06:33:36 +09:00
|
|
|
$nli->showNoticeOptions();
|
|
|
|
}
|
|
|
|
|
2011-03-07 07:27:03 +09:00
|
|
|
function onStartShowEntryForms(&$tabs)
|
|
|
|
{
|
2014-02-24 10:05:31 +09:00
|
|
|
$tabs[$this->tag()] = array('title' => $this->appTitle(),
|
|
|
|
'href' => common_local_url($this->newFormAction()),
|
|
|
|
);
|
2011-03-07 07:27:03 +09:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
function onStartMakeEntryForm($tag, $out, &$form)
|
|
|
|
{
|
|
|
|
if ($tag == $this->tag()) {
|
|
|
|
$form = $this->entryForm($out);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2011-04-20 04:43:06 +09:00
|
|
|
|
2011-04-20 05:00:31 +09:00
|
|
|
function showNotice($notice, $out)
|
|
|
|
{
|
2011-04-22 03:26:58 +09:00
|
|
|
// TRANS: Server exception thrown when a micro app plugin developer has not done his job too well.
|
|
|
|
throw new ServerException(_('You must implement either adaptNoticeListItem() or showNotice().'));
|
2011-04-20 05:00:31 +09:00
|
|
|
}
|
2011-03-06 04:48:10 +09:00
|
|
|
}
|