X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=lib%2Fmicroappplugin.php;h=53fe5e9995eab4d7bf467c7015d769c8122dbd04;hb=945920f24dba53d8367160b221bc842db0768fc4;hp=23b4b5bb8422b7636b7d1896bccbcdba08c107d8;hpb=7184036cf2f8dd0641b23449341be989f085c920;p=quix0rs-gnu-social.git diff --git a/lib/microappplugin.php b/lib/microappplugin.php index 23b4b5bb84..53fe5e9995 100644 --- a/lib/microappplugin.php +++ b/lib/microappplugin.php @@ -4,7 +4,7 @@ * Copyright (C) 2011, StatusNet, Inc. * * Superclass for microapp plugin - * + * * PHP version 5 * * This program is free software: you can redistribute it and/or modify @@ -39,8 +39,8 @@ if (!defined('STATUSNET')) { * * This class lets you define micro-applications with different kinds of activities. * - * The applications work more-or-less like other - * + * The applications work more-or-less like other + * * @category Microapp * @package StatusNet * @author Evan Prodromou @@ -48,23 +48,95 @@ if (!defined('STATUSNET')) { * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0 * @link http://status.net/ */ - -abstract class MicroAppPlugin extends Plugin +abstract class MicroAppPlugin extends ActivityHandlerPlugin { - abstract function types(); - abstract function saveNoticeFromActivity($activity); - abstract function activityFromNotice($notice); - abstract function showNotice($notice, $out); - abstract function entryForm(); + /** + * 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 + */ + abstract function appTitle(); + + /** + * 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 + */ + abstract function entryForm($out); + + /** + * + */ + public function newFormAction() { + // such as 'newbookmark' or 'newevent' route + return 'new'.$this->tag(); + } + + /** + * Output the HTML for this kind of object in a list + * + * @param NoticeListItem $nli The list item being shown. + * + * @return boolean hook value + */ + function onStartShowNoticeItem(NoticeListItem $nli) + { + if (!$this->isMyNotice($nli->notice)) { + return true; + } - function isMyNotice($notice) { - $types = $this->types(); - return in_array($notice->object_type, $types); + // Legacy use was creating a "NoticeListItemAdapter", but + // nowadays we solve that using event handling for microapps. + // This section will remain until all plugins are fixed. + $adapter = $this->adaptNoticeListItem($nli) ?: $nli; + + $adapter->showNotice(); + $adapter->showNoticeAttachments(); + $adapter->showNoticeFooter(); + + 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 isMyActivity($activity) { - $types = $this->types(); - return (count($activity->objects) == 1 && - in_array($activity->objects[0]->type, $types)); + function onStartShowEntryForms(&$tabs) + { + $tabs[$this->tag()] = array('title' => $this->appTitle(), + 'href' => common_local_url($this->newFormAction()), + ); + return true; + } + + function onStartMakeEntryForm($tag, $out, &$form) + { + if ($tag == $this->tag()) { + $form = $this->entryForm($out); + return false; + } + + return true; } }