AwesomenessPlugin.php 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. <?php
  2. // This file is part of GNU social - https://www.gnu.org/software/social
  3. //
  4. // GNU social is free software: you can redistribute it and/or modify
  5. // it under the terms of the GNU Affero General Public License as published by
  6. // the Free Software Foundation, either version 3 of the License, or
  7. // (at your option) any later version.
  8. //
  9. // GNU social is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU Affero General Public License for more details.
  13. //
  14. // You should have received a copy of the GNU Affero General Public License
  15. // along with GNU social. If not, see <http://www.gnu.org/licenses/>.
  16. defined('GNUSOCIAL') || die();
  17. /**
  18. * Fun sample plugin: tweaks input data and adds a 'Cornify' widget to sidebar.
  19. *
  20. * @category Plugin
  21. * @package GNUsocial
  22. * @author Jeroen De Dauw <jeroendedauw@gmail.com>
  23. * @copyright 2019 Free Software Foundation, Inc http://www.fsf.org
  24. * @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
  25. */
  26. class AwesomenessPlugin extends Plugin
  27. {
  28. const PLUGIN_VERSION = '13.37.42';
  29. public function onPluginVersion(array &$versions): bool
  30. {
  31. $versions[] = [
  32. 'name' => 'Awesomeness',
  33. 'version' => self::PLUGIN_VERSION,
  34. 'author' => 'Jeroen De Dauw',
  35. 'homepage' => GNUSOCIAL_ENGINE_REPO_URL . 'tree/master/plugins/Awesomeness',
  36. // TRANS: Plugin description for a sample plugin.
  37. 'rawdescription' => _m('The Awesomeness plugin adds additional awesomeness ' .
  38. 'to a GNU social installation.')
  39. ];
  40. return true;
  41. }
  42. /**
  43. * Add the conrnify button
  44. *
  45. * @param Action $action the current action
  46. *
  47. * @return void
  48. */
  49. public function onEndShowSections(Action $action)
  50. {
  51. $action->elementStart('div', ['id' => 'cornify_section',
  52. 'class' => 'section']);
  53. $action->raw(
  54. <<<EOT
  55. <a href="https://www.cornify.com" onclick="cornify_add();return false;">
  56. <img src="https://www.cornify.com/assets/cornify.gif" width="61" height="16" border="0" alt="Cornify" />
  57. </a>
  58. EOT
  59. );
  60. $action->elementEnd('div');
  61. }
  62. public function onEndShowScripts(Action $action)
  63. {
  64. $action->script($this->path('js/cornify.js'));
  65. }
  66. /**
  67. * Hook for new-notice form processing to take our HTML goodies;
  68. * won't affect API posting etc.
  69. *
  70. * @param NewNoticeAction $action
  71. * @param User $user
  72. * @param string $content
  73. * @param array $options
  74. * @return bool hook return
  75. */
  76. public function onStartSaveNewNoticeWeb($action, $user, &$content, &$options)
  77. {
  78. $content = htmlspecialchars($content);
  79. $options['rendered'] = preg_replace("/(^|\s|-)((?:awesome|awesomeness)[\?!\.\,]?)(\s|$)/i", " <b>$2</b> ", $content);
  80. }
  81. }