AwesomenessPlugin.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. <?php
  2. /**
  3. * StatusNet, the distributed open-source microblogging tool
  4. *
  5. * Plugin to add additional awesomenss to StatusNet
  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 Jeroen De Dauw <jeroendedauw@gmail.com>
  25. * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
  26. * @link http://status.net/
  27. */
  28. if (!defined('STATUSNET')) {
  29. exit(1);
  30. }
  31. /**
  32. * Fun sample plugin: tweaks input data and adds a 'Cornify' widget to sidebar.
  33. *
  34. * @category Plugin
  35. * @package StatusNet
  36. * @author Jeroen De Dauw <jeroendedauw@gmail.com>
  37. * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
  38. * @link http://status.net/
  39. */
  40. class AwesomenessPlugin extends Plugin
  41. {
  42. const VERSION = '0.0.42';
  43. public function onPluginVersion(&$versions)
  44. {
  45. $versions[] = array(
  46. 'name' => 'Awesomeness',
  47. 'version' => self::VERSION,
  48. 'author' => 'Jeroen De Dauw',
  49. 'homepage' => 'http://status.net/wiki/Plugin:Awesomeness',
  50. // TRANS: Plugin description for a sample plugin.
  51. 'rawdescription' => _m('The Awesomeness plugin adds additional awesomeness ' .
  52. 'to a StatusNet installation.'
  53. )
  54. );
  55. return true;
  56. }
  57. /**
  58. * Add the conrnify button
  59. *
  60. * @param Action $action the current action
  61. *
  62. * @return void
  63. */
  64. function onEndShowSections(Action $action)
  65. {
  66. $action->elementStart('div', array('id' => 'cornify_section',
  67. 'class' => 'section'));
  68. $action->raw(
  69. <<<EOT
  70. <a href="http://www.cornify.com" onclick="cornify_add();return false;">
  71. <img src="http://www.cornify.com/assets/cornify.gif" width="61" height="16" border="0" alt="Cornify" />
  72. </a>
  73. <script type="text/javascript">(function() {
  74. var js = document.createElement('script');
  75. js.type = 'text/javascript';
  76. js.async = true;
  77. js.src = 'http://www.cornify.com/js/cornify.js';
  78. (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(js);
  79. })();</script>
  80. EOT
  81. );
  82. $action->elementEnd('div');
  83. }
  84. /**
  85. * Hook for new-notice form processing to take our HTML goodies;
  86. * won't affect API posting etc.
  87. *
  88. * @param NewNoticeAction $action
  89. * @param User $user
  90. * @param string $content
  91. * @param array $options
  92. * @return boolean hook return
  93. */
  94. function onStartSaveNewNoticeWeb($action, $user, &$content, &$options)
  95. {
  96. $content = htmlspecialchars($content);
  97. $options['rendered'] = preg_replace("/(^|\s|-)((?:awesome|awesomeness)[\?!\.\,]?)(\s|$)/i", " <b>$2</b> ", $content);
  98. }
  99. }