2008-12-31 05:20:19 +09:00
|
|
|
<?php
|
|
|
|
/**
|
2009-08-26 07:12:20 +09:00
|
|
|
* StatusNet, the distributed open-source microblogging tool
|
2008-12-31 05:20:19 +09:00
|
|
|
*
|
2009-08-26 07:12:20 +09:00
|
|
|
* StatusNet-only extensions to the Twitter-like API
|
2008-12-31 05:20:19 +09:00
|
|
|
*
|
|
|
|
* 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 Twitter
|
2009-08-26 07:12:20 +09:00
|
|
|
* @package StatusNet
|
2008-12-31 05:20:19 +09:00
|
|
|
* @author Evan Prodromou <evan@controlyourself.ca>
|
2009-08-26 07:12:20 +09:00
|
|
|
* @copyright 2008 StatusNet, Inc.
|
2008-12-31 05:20:19 +09:00
|
|
|
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
|
2009-08-26 07:16:46 +09:00
|
|
|
* @link http://status.net/
|
2008-12-31 05:20:19 +09:00
|
|
|
*/
|
|
|
|
|
|
|
|
if (!defined('LACONICA')) {
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
require_once INSTALLDIR.'/lib/twitterapi.php';
|
|
|
|
|
|
|
|
/**
|
2009-08-26 07:12:20 +09:00
|
|
|
* StatusNet-specific API methods
|
2008-12-31 05:20:19 +09:00
|
|
|
*
|
|
|
|
* This class handles all /laconica/ API methods.
|
|
|
|
*
|
|
|
|
* @category Twitter
|
2009-08-26 07:12:20 +09:00
|
|
|
* @package StatusNet
|
2008-12-31 05:20:19 +09:00
|
|
|
* @author Evan Prodromou <evan@controlyourself.ca>
|
2009-08-26 07:12:20 +09:00
|
|
|
* @copyright 2008 StatusNet, Inc.
|
2008-12-31 05:20:19 +09:00
|
|
|
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
|
2009-08-26 07:16:46 +09:00
|
|
|
* @link http://status.net/
|
2008-12-31 05:20:19 +09:00
|
|
|
*/
|
|
|
|
|
|
|
|
class TwitapilaconicaAction extends TwitterapiAction
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* A version stamp for the API
|
|
|
|
*
|
2009-08-26 07:12:20 +09:00
|
|
|
* Returns a version number for this version of StatusNet, which
|
2008-12-31 05:20:19 +09:00
|
|
|
* should make things a bit easier for upgrades.
|
2008-12-31 05:59:39 +09:00
|
|
|
* URL: http://identi.ca/api/laconica/version.(xml|json)
|
|
|
|
* Formats: xml, json
|
2008-12-31 05:20:19 +09:00
|
|
|
*
|
|
|
|
* @param array $args Web arguments
|
|
|
|
* @param array $apidata Twitter API data
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*
|
|
|
|
* @see ApiAction::process_command()
|
|
|
|
*/
|
|
|
|
|
|
|
|
function version($args, $apidata)
|
|
|
|
{
|
|
|
|
parent::handle($args);
|
2008-12-31 05:59:39 +09:00
|
|
|
switch ($apidata['content-type']) {
|
|
|
|
case 'xml':
|
|
|
|
$this->init_document('xml');
|
2009-01-16 07:57:15 +09:00
|
|
|
$this->element('version', null, LACONICA_VERSION);
|
2008-12-31 05:59:39 +09:00
|
|
|
$this->end_document('xml');
|
2008-12-31 06:01:14 +09:00
|
|
|
break;
|
2008-12-31 05:59:39 +09:00
|
|
|
case 'json':
|
|
|
|
$this->init_document('json');
|
|
|
|
print '"'.LACONICA_VERSION.'"';
|
|
|
|
$this->end_document('json');
|
2008-12-31 06:01:14 +09:00
|
|
|
break;
|
2008-12-31 05:59:39 +09:00
|
|
|
default:
|
2009-01-16 08:03:38 +09:00
|
|
|
$this->clientError(_('API method not found!'), $code=404);
|
2008-12-31 05:59:39 +09:00
|
|
|
}
|
2008-12-31 05:20:19 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Dump of configuration variables
|
|
|
|
*
|
|
|
|
* Gives a full dump of configuration variables for this instance
|
2009-08-26 07:12:20 +09:00
|
|
|
* of StatusNet, minus variables that may be security-sensitive (like
|
2008-12-31 05:20:19 +09:00
|
|
|
* passwords).
|
2008-12-31 06:14:44 +09:00
|
|
|
* URL: http://identi.ca/api/laconica/config.(xml|json)
|
|
|
|
* Formats: xml, json
|
2008-12-31 05:20:19 +09:00
|
|
|
*
|
|
|
|
* @param array $args Web arguments
|
|
|
|
* @param array $apidata Twitter API data
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*
|
|
|
|
* @see ApiAction::process_command()
|
|
|
|
*/
|
|
|
|
|
|
|
|
function config($args, $apidata)
|
|
|
|
{
|
2008-12-31 06:14:44 +09:00
|
|
|
static $keys = array('site' => array('name', 'server', 'theme', 'path', 'fancy', 'language',
|
|
|
|
'email', 'broughtby', 'broughtbyurl', 'closed',
|
|
|
|
'inviteonly', 'private'),
|
|
|
|
'license' => array('url', 'title', 'image'),
|
|
|
|
'nickname' => array('featured'),
|
|
|
|
'throttle' => array('enabled', 'count', 'timespan'),
|
|
|
|
'xmpp' => array('enabled', 'server', 'user'));
|
|
|
|
|
2008-12-31 05:20:19 +09:00
|
|
|
parent::handle($args);
|
2008-12-31 06:14:44 +09:00
|
|
|
|
|
|
|
switch ($apidata['content-type']) {
|
|
|
|
case 'xml':
|
|
|
|
$this->init_document('xml');
|
2009-01-16 07:57:15 +09:00
|
|
|
$this->elementStart('config');
|
2008-12-31 06:14:44 +09:00
|
|
|
// XXX: check that all sections and settings are legal XML elements
|
|
|
|
foreach ($keys as $section => $settings) {
|
2009-01-16 07:57:15 +09:00
|
|
|
$this->elementStart($section);
|
2008-12-31 06:14:44 +09:00
|
|
|
foreach ($settings as $setting) {
|
2008-12-31 06:19:57 +09:00
|
|
|
$value = common_config($section, $setting);
|
|
|
|
if (is_array($value)) {
|
|
|
|
$value = implode(',', $value);
|
|
|
|
} else if ($value === false) {
|
|
|
|
$value = 'false';
|
|
|
|
} else if ($value === true) {
|
|
|
|
$value = 'true';
|
|
|
|
}
|
2009-01-16 07:57:15 +09:00
|
|
|
$this->element($setting, null, $value);
|
2008-12-31 06:14:44 +09:00
|
|
|
}
|
2009-01-16 07:57:15 +09:00
|
|
|
$this->elementEnd($section);
|
2008-12-31 06:14:44 +09:00
|
|
|
}
|
2009-01-16 07:57:15 +09:00
|
|
|
$this->elementEnd('config');
|
2008-12-31 06:14:44 +09:00
|
|
|
$this->end_document('xml');
|
|
|
|
break;
|
|
|
|
case 'json':
|
|
|
|
$result = array();
|
|
|
|
foreach ($keys as $section => $settings) {
|
|
|
|
$result[$section] = array();
|
|
|
|
foreach ($settings as $setting) {
|
|
|
|
$result[$section][$setting] = common_config($section, $setting);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$this->init_document('json');
|
|
|
|
$this->show_json_objects($result);
|
|
|
|
$this->end_document('json');
|
|
|
|
break;
|
|
|
|
default:
|
2009-01-16 08:03:38 +09:00
|
|
|
$this->clientError(_('API method not found!'), $code=404);
|
2008-12-31 06:14:44 +09:00
|
|
|
}
|
2008-12-31 05:20:19 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* WADL description of the API
|
|
|
|
*
|
|
|
|
* Gives a WADL description of the API provided by this version of the
|
|
|
|
* software.
|
|
|
|
*
|
|
|
|
* @param array $args Web arguments
|
|
|
|
* @param array $apidata Twitter API data
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*
|
|
|
|
* @see ApiAction::process_command()
|
|
|
|
*/
|
|
|
|
|
|
|
|
function wadl($args, $apidata)
|
|
|
|
{
|
|
|
|
parent::handle($args);
|
2009-01-16 08:03:38 +09:00
|
|
|
$this->serverError(_('API method under construction.'), 501);
|
2008-12-31 05:20:19 +09:00
|
|
|
}
|
2009-07-15 23:29:54 +09:00
|
|
|
|
2008-12-31 05:20:19 +09:00
|
|
|
}
|