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 From c6526c84f5891117fa74a9b6bdae4df4374af18b Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Fri, 15 May 2009 18:16:32 -0400 Subject: License link, no title --- plugins/WikiHashtagsPlugin.php | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'plugins') diff --git a/plugins/WikiHashtagsPlugin.php b/plugins/WikiHashtagsPlugin.php index 4d386e198..141cb07d2 100644 --- a/plugins/WikiHashtagsPlugin.php +++ b/plugins/WikiHashtagsPlugin.php @@ -82,13 +82,20 @@ class WikiHashtagsPlugin extends Plugin $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->element('style', null, + "span.editsection { display: none }\n". + "table.toc { display: none }"); $action->raw($html); - $action->element('a', array('href' => $editurl), + $action->elementStart('p'); + $action->element('a', array('href' => $editurl, + 'title' => sprintf(_('Edit the article for #%s on WikiHashtags'), $tag)), _('Edit')); + $action->element('a', array('href' => 'http://www.gnu.org/copyleft/fdl.html', + 'title' => _('Shared under the terms of the GNU Free Documentation License'), + 'rel' => 'license'), + 'GNU FDL'); + $action->elementEnd('p'); } else { $action->element('a', array('href' => $editurl), sprintf(_('Start the article for #%s on WikiHashtags'), $tag)); -- cgit v1.2.3-54-g00ecf From 5a0edc9b8cbfa10d4dd72603d95708c50e3b8cdb Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Sun, 17 May 2009 12:37:04 -0400 Subject: remove debugging calls --- plugins/WikiHashtagsPlugin.php | 7 ------- 1 file changed, 7 deletions(-) (limited to 'plugins') diff --git a/plugins/WikiHashtagsPlugin.php b/plugins/WikiHashtagsPlugin.php index 141cb07d2..6d186a5fe 100644 --- a/plugins/WikiHashtagsPlugin.php +++ b/plugins/WikiHashtagsPlugin.php @@ -54,32 +54,25 @@ class WikiHashtagsPlugin extends Plugin 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')); if (!empty($html)) { -- cgit v1.2.3-54-g00ecf