From caadd8ed93d7a388a9868af6732db3214b08fd6a Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Fri, 15 May 2009 17:57:26 -0400 Subject: add WikiHashtagsPlugin --- plugins/WikiHashtagsPlugin.php | 109 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 109 insertions(+) create mode 100644 plugins/WikiHashtagsPlugin.php (limited to 'plugins') diff --git a/plugins/WikiHashtagsPlugin.php b/plugins/WikiHashtagsPlugin.php new file mode 100644 index 000000000..4d386e198 --- /dev/null +++ b/plugins/WikiHashtagsPlugin.php @@ -0,0 +1,109 @@ +. + * + * @category Plugin + * @package Laconica + * @author Evan Prodromou + * @copyright 2008 Control Yourself, Inc. + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ + */ + +if (!defined('LACONICA')) { + exit(1); +} + +define('WIKIHASHTAGSPLUGIN_VERSION', '0.1'); + +/** + * Plugin to use WikiHashtags + * + * @category Plugin + * @package Laconica + * @author Evan Prodromou + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ + * + * @see Event + */ + +class WikiHashtagsPlugin extends Plugin +{ + function __construct($code=null) + { + parent::__construct(); + } + + function onStartShowSections($action) + { + common_debug('WikiHashtags: got called'); + $name = $action->trimmed('action'); + + if ($name == 'tag') { + common_debug('WikiHashtags: called by tag'); + + $taginput = $action->trimmed('tag'); + $tag = common_canonical_tag($taginput); + + if (!empty($tag)) { + common_debug('WikiHashtags: have a tag: ' . $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)); + + common_debug('WikiHashtags: have an url: ' . $url); + + $context = stream_context_create(array('http' => array('method' => "GET", + 'header' => + "User-Agent: " . $this->userAgent()))); + $html = @file_get_contents($url, false, $context); + + common_debug('WikiHashtags: results are: ' . $html); + + $action->elementStart('div', array('id' => 'wikihashtags', 'class' => 'section')); + + $action->element('h2', null, _('WikiHashtags')); + + if (!empty($html)) { + $action->element('style', null, 'span.editsection { display: none }'); + $action->raw($html); + $action->element('a', array('href' => $editurl), + _('Edit')); + } else { + $action->element('a', array('href' => $editurl), + sprintf(_('Start the article for #%s on WikiHashtags'), $tag)); + } + + $action->elementEnd('div'); + } + } + + return true; + } + + function userAgent() + { + return 'WikiHashtagsPlugin/'.WIKIHASHTAGSPLUGIN_VERSION . + ' Laconica/' . LACONICA_VERSION; + } +} -- cgit v1.2.3-54-g00ecf