2009-05-15 22:57:26 +01:00
|
|
|
<?php
|
|
|
|
/**
|
2009-08-25 23:29:56 +01:00
|
|
|
* StatusNet, the distributed open-source microblogging tool
|
2009-05-15 22:57:26 +01:00
|
|
|
*
|
|
|
|
* Plugin to show WikiHashtags content in the sidebar
|
|
|
|
*
|
|
|
|
* 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
|
2009-08-25 23:29:56 +01:00
|
|
|
* @package StatusNet
|
|
|
|
* @author Evan Prodromou <evan@status.net>
|
|
|
|
* @copyright 2008 StatusNet, Inc.
|
2009-05-15 22:57:26 +01:00
|
|
|
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
|
2009-08-25 23:29:56 +01:00
|
|
|
* @link http://status.net/
|
2009-05-15 22:57:26 +01:00
|
|
|
*/
|
|
|
|
|
2009-08-25 23:42:34 +01:00
|
|
|
if (!defined('STATUSNET')) {
|
2009-05-15 22:57:26 +01:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Plugin to use WikiHashtags
|
|
|
|
*
|
|
|
|
* @category Plugin
|
2009-08-25 23:29:56 +01:00
|
|
|
* @package StatusNet
|
|
|
|
* @author Evan Prodromou <evan@status.net>
|
2009-05-15 22:57:26 +01:00
|
|
|
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
|
2009-08-25 23:29:56 +01:00
|
|
|
* @link http://status.net/
|
2009-05-15 22:57:26 +01:00
|
|
|
*
|
|
|
|
* @see Event
|
|
|
|
*/
|
|
|
|
class WikiHashtagsPlugin extends Plugin
|
|
|
|
{
|
2019-06-03 01:56:52 +01:00
|
|
|
const PLUGIN_VERSION = '0.1.0';
|
2010-01-08 08:29:09 +00:00
|
|
|
|
2009-05-15 22:57:26 +01:00
|
|
|
function __construct($code=null)
|
|
|
|
{
|
|
|
|
parent::__construct();
|
|
|
|
}
|
|
|
|
|
2014-06-28 15:09:46 +01:00
|
|
|
function onStartShowSections(Action $action)
|
2009-05-15 22:57:26 +01:00
|
|
|
{
|
|
|
|
$name = $action->trimmed('action');
|
|
|
|
|
|
|
|
if ($name == 'tag') {
|
|
|
|
$taginput = $action->trimmed('tag');
|
|
|
|
$tag = common_canonical_tag($taginput);
|
|
|
|
|
|
|
|
if (!empty($tag)) {
|
|
|
|
$url = sprintf('http://hashtags.wikia.com/index.php?title=%s&action=render',
|
|
|
|
urlencode($tag));
|
|
|
|
$editurl = sprintf('http://hashtags.wikia.com/index.php?title=%s&action=edit',
|
|
|
|
urlencode($tag));
|
|
|
|
|
2009-10-28 19:29:20 +00:00
|
|
|
$request = HTTPClient::start();
|
|
|
|
$response = $request->get($url);
|
|
|
|
$html = $response->getBody();
|
2009-05-15 22:57:26 +01:00
|
|
|
|
|
|
|
$action->elementStart('div', array('id' => 'wikihashtags', 'class' => 'section'));
|
|
|
|
|
2009-10-28 19:29:20 +00:00
|
|
|
if ($response->isOk() && !empty($html)) {
|
2009-05-15 23:16:32 +01:00
|
|
|
$action->element('style', null,
|
|
|
|
"span.editsection { display: none }\n".
|
|
|
|
"table.toc { display: none }");
|
2009-05-15 22:57:26 +01:00
|
|
|
$action->raw($html);
|
2009-05-15 23:16:32 +01:00
|
|
|
$action->elementStart('p');
|
|
|
|
$action->element('a', array('href' => $editurl,
|
2011-06-17 14:54:34 +01:00
|
|
|
// TRANS: Link title for editing an article on WikiHashTags.
|
|
|
|
// TRANS: %s is the hash tag page to be edited.
|
2011-03-30 21:30:23 +01:00
|
|
|
'title' => sprintf(_m('Edit the article for #%s on WikiHashtags'), $tag)),
|
2011-06-17 14:54:34 +01:00
|
|
|
// TRANS: Link description for editing an article on WikiHashTags.
|
2011-03-30 21:30:23 +01:00
|
|
|
_m('Edit'));
|
2009-05-15 23:16:32 +01:00
|
|
|
$action->element('a', array('href' => 'http://www.gnu.org/copyleft/fdl.html',
|
2011-06-17 14:54:34 +01:00
|
|
|
// TRANS: Link title for viewing the GFDL.
|
2011-03-30 21:30:23 +01:00
|
|
|
'title' => _m('Shared under the terms of the GNU Free Documentation License'),
|
2009-05-15 23:16:32 +01:00
|
|
|
'rel' => 'license'),
|
2011-06-17 14:54:34 +01:00
|
|
|
// TRANS: Link description for viewing the GFDL.
|
|
|
|
_m('GNU FDL'));
|
2009-05-15 23:16:32 +01:00
|
|
|
$action->elementEnd('p');
|
2009-05-15 22:57:26 +01:00
|
|
|
} else {
|
|
|
|
$action->element('a', array('href' => $editurl),
|
2011-06-17 14:54:34 +01:00
|
|
|
// TRANS: Link description for editing an article on WikiHashTags.
|
|
|
|
// TRANS: %s is the hash tag page to be created.
|
2011-03-30 21:30:23 +01:00
|
|
|
sprintf(_m('Start the article for #%s on WikiHashtags'), $tag));
|
2009-05-15 22:57:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
$action->elementEnd('div');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2010-01-08 08:29:09 +00:00
|
|
|
|
2019-08-12 15:03:30 +01:00
|
|
|
public function onPluginVersion(array &$versions): bool
|
2010-01-08 08:29:09 +00:00
|
|
|
{
|
|
|
|
$versions[] = array('name' => 'WikiHashtags',
|
2019-06-03 01:56:52 +01:00
|
|
|
'version' => self::PLUGIN_VERSION,
|
2010-01-08 08:29:09 +00:00
|
|
|
'author' => 'Evan Prodromou',
|
2019-11-21 00:21:22 +00:00
|
|
|
'homepage' => GNUSOCIAL_ENGINE_REPO_URL . 'tree/master/plugins/WikiHashtags',
|
2010-01-08 08:29:09 +00:00
|
|
|
'rawdescription' =>
|
2011-06-17 14:54:34 +01:00
|
|
|
// TRANS: Plugin description.
|
2010-01-08 08:29:09 +00:00
|
|
|
_m('Gets hashtag descriptions from <a href="http://hashtags.wikia.com/">WikiHashtags</a>.'));
|
|
|
|
return true;
|
|
|
|
}
|
2009-05-15 22:57:26 +01:00
|
|
|
}
|