WikiHashtagsPlugin.php 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. <?php
  2. /**
  3. * StatusNet, the distributed open-source microblogging tool
  4. *
  5. * Plugin to show WikiHashtags content in the sidebar
  6. *
  7. * PHP version 5
  8. *
  9. * LICENCE: This program is free software: you can redistribute it and/or modify
  10. * it under the terms of the GNU Affero General Public License as published by
  11. * the Free Software Foundation, either version 3 of the License, or
  12. * (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU Affero General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Affero General Public License
  20. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  21. *
  22. * @category Plugin
  23. * @package StatusNet
  24. * @author Evan Prodromou <evan@status.net>
  25. * @copyright 2008 StatusNet, Inc.
  26. * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
  27. * @link http://status.net/
  28. */
  29. if (!defined('STATUSNET')) {
  30. exit(1);
  31. }
  32. /**
  33. * Plugin to use WikiHashtags
  34. *
  35. * @category Plugin
  36. * @package StatusNet
  37. * @author Evan Prodromou <evan@status.net>
  38. * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
  39. * @link http://status.net/
  40. *
  41. * @see Event
  42. */
  43. class WikiHashtagsPlugin extends Plugin
  44. {
  45. const PLUGIN_VERSION = '0.1.0';
  46. function __construct($code=null)
  47. {
  48. parent::__construct();
  49. }
  50. function onStartShowSections(Action $action)
  51. {
  52. $name = $action->trimmed('action');
  53. if ($name == 'tag') {
  54. $taginput = $action->trimmed('tag');
  55. $tag = common_canonical_tag($taginput);
  56. if (!empty($tag)) {
  57. $url = sprintf('http://hashtags.wikia.com/index.php?title=%s&action=render',
  58. urlencode($tag));
  59. $editurl = sprintf('http://hashtags.wikia.com/index.php?title=%s&action=edit',
  60. urlencode($tag));
  61. $request = HTTPClient::start();
  62. $response = $request->get($url);
  63. $html = $response->getBody();
  64. $action->elementStart('div', array('id' => 'wikihashtags', 'class' => 'section'));
  65. if ($response->isOk() && !empty($html)) {
  66. $action->element('style', null,
  67. "span.editsection { display: none }\n".
  68. "table.toc { display: none }");
  69. $action->raw($html);
  70. $action->elementStart('p');
  71. $action->element('a', array('href' => $editurl,
  72. // TRANS: Link title for editing an article on WikiHashTags.
  73. // TRANS: %s is the hash tag page to be edited.
  74. 'title' => sprintf(_m('Edit the article for #%s on WikiHashtags'), $tag)),
  75. // TRANS: Link description for editing an article on WikiHashTags.
  76. _m('Edit'));
  77. $action->element('a', array('href' => 'http://www.gnu.org/copyleft/fdl.html',
  78. // TRANS: Link title for viewing the GFDL.
  79. 'title' => _m('Shared under the terms of the GNU Free Documentation License'),
  80. 'rel' => 'license'),
  81. // TRANS: Link description for viewing the GFDL.
  82. _m('GNU FDL'));
  83. $action->elementEnd('p');
  84. } else {
  85. $action->element('a', array('href' => $editurl),
  86. // TRANS: Link description for editing an article on WikiHashTags.
  87. // TRANS: %s is the hash tag page to be created.
  88. sprintf(_m('Start the article for #%s on WikiHashtags'), $tag));
  89. }
  90. $action->elementEnd('div');
  91. }
  92. }
  93. return true;
  94. }
  95. public function onPluginVersion(array &$versions): bool
  96. {
  97. $versions[] = array('name' => 'WikiHashtags',
  98. 'version' => self::PLUGIN_VERSION,
  99. 'author' => 'Evan Prodromou',
  100. 'homepage' => GNUSOCIAL_ENGINE_REPO_URL . 'tree/master/plugins/WikiHashtags',
  101. 'rawdescription' =>
  102. // TRANS: Plugin description.
  103. _m('Gets hashtag descriptions from <a href="http://hashtags.wikia.com/">WikiHashtags</a>.'));
  104. return true;
  105. }
  106. }