2010-09-05 23:03:31 +01:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* StatusNet, the distributed open-source microblogging tool
|
|
|
|
*
|
|
|
|
* Plugin to implement the Account Manager specification
|
|
|
|
*
|
|
|
|
* PHP version 5
|
|
|
|
*
|
|
|
|
* LICENCE: 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 Plugin
|
|
|
|
* @package StatusNet
|
|
|
|
* @author Craig Andrews <candrews@integralblue.com>
|
|
|
|
* @copyright 2009 Free Software Foundation, Inc http://www.fsf.org
|
|
|
|
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
|
|
|
|
* @link http://status.net/
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (!defined('STATUSNET') && !defined('LACONICA')) {
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
class AccountManagerPlugin extends Plugin
|
|
|
|
{
|
2019-06-03 01:56:52 +01:00
|
|
|
const PLUGIN_VERSION = '2.0.0';
|
|
|
|
|
2010-09-05 23:03:31 +01:00
|
|
|
const AM_REL = 'acct-mgmt';
|
|
|
|
|
|
|
|
function __construct()
|
|
|
|
{
|
|
|
|
parent::__construct();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Hook for RouterInitialized event.
|
|
|
|
*
|
2014-11-07 14:24:05 +00:00
|
|
|
* @param URLMapper $m path-to-action mapper
|
2010-09-05 23:03:31 +01:00
|
|
|
* @return boolean hook return
|
|
|
|
*/
|
2014-11-07 14:24:05 +00:00
|
|
|
public function onRouterInitialized(URLMapper $m)
|
2010-09-05 23:03:31 +01:00
|
|
|
{
|
|
|
|
// Discovery actions
|
|
|
|
$m->connect('main/amcd.json',
|
2019-07-11 19:14:03 +01:00
|
|
|
['action' => 'AccountManagementControlDocument']);
|
2010-09-05 23:03:31 +01:00
|
|
|
$m->connect('main/amsessionstatus',
|
2019-07-11 19:14:03 +01:00
|
|
|
['action' => 'AccountManagementSessionStatus']);
|
2010-09-05 23:03:31 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
function onStartHostMetaLinks(&$links) {
|
2013-09-30 16:13:03 +01:00
|
|
|
$links[] = new XML_XRD_Element_Link(AccountManagerPlugin::AM_REL,
|
|
|
|
common_local_url('AccountManagementControlDocument'));
|
2010-09-05 23:03:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
function onStartShowHTML($action)
|
|
|
|
{
|
|
|
|
//Account management discovery link
|
|
|
|
header('Link: <'.common_local_url('AccountManagementControlDocument').'>; rel="'. AccountManagerPlugin::AM_REL.'"; type="application/json"');
|
|
|
|
|
|
|
|
//Account management login status
|
|
|
|
$cur = common_current_user();
|
|
|
|
if(empty($cur)) {
|
|
|
|
header('X-Account-Management-Status: none');
|
|
|
|
} else {
|
|
|
|
//TODO it seems " should be escaped in the name and id, but the spec doesn't seem to indicate how to do that
|
|
|
|
header('X-Account-Management-Status: active; name="' . $cur->nickname . '"; id="' . $cur->nickname . '"');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function onLoginAction($action, &$login) {
|
2019-06-03 01:56:52 +01:00
|
|
|
switch ($action)
|
2010-09-05 23:03:31 +01:00
|
|
|
{
|
|
|
|
case 'AccountManagementControlDocument':
|
|
|
|
$login = true;
|
|
|
|
return false;
|
|
|
|
default:
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-12 15:03:30 +01:00
|
|
|
public function onPluginVersion(array &$versions): bool
|
2010-09-05 23:03:31 +01:00
|
|
|
{
|
|
|
|
$versions[] = array('name' => 'AccountManager',
|
2019-06-03 01:56:52 +01:00
|
|
|
'version' => self::PLUGIN_VERSION,
|
2010-09-05 23:03:31 +01:00
|
|
|
'author' => 'Craig Andrews',
|
2019-11-21 00:21:22 +00:00
|
|
|
'homepage' => GNUSOCIAL_ENGINE_REPO_URL . 'tree/master/plugins/AccountManager',
|
2010-09-05 23:03:31 +01:00
|
|
|
'rawdescription' =>
|
2011-04-06 13:57:48 +01:00
|
|
|
// TRANS: Plugin description.
|
2010-09-05 23:03:31 +01:00
|
|
|
_m('The Account Manager plugin implements the Account Manager specification.'));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|