/plugins/editors-xtd/readmore/readmore.php

https://bitbucket.org/eternaware/joomus · PHP · 75 lines · 41 code · 7 blank · 27 comment · 1 complexity · 0b7aa0168f72b8730bbbff3aa2a59477 MD5 · raw file

  1. <?php
  2. /**
  3. * @package Joomla.Plugin
  4. * @subpackage Editors-xtd.readmore
  5. *
  6. * @copyright Copyright (C) 2005 - 2012 Open Source Matters, Inc. All rights reserved.
  7. * @license GNU General Public License version 2 or later; see LICENSE.txt
  8. */
  9. defined('_JEXEC') or die;
  10. /**
  11. * Editor Readmore buton
  12. *
  13. * @package Joomla.Plugin
  14. * @subpackage Editors-xtd.readmore
  15. * @since 1.5
  16. */
  17. class plgButtonReadmore extends JPlugin
  18. {
  19. /**
  20. * Constructor
  21. *
  22. * @access protected
  23. * @param object $subject The object to observe
  24. * @param array $config An array that holds the plugin configuration
  25. * @since 1.5
  26. */
  27. public function __construct(& $subject, $config)
  28. {
  29. parent::__construct($subject, $config);
  30. $this->loadLanguage();
  31. }
  32. /**
  33. * readmore button
  34. * @return array A two element array of (imageName, textToInsert)
  35. */
  36. public function onDisplay($name)
  37. {
  38. $app = JFactory::getApplication();
  39. $doc = JFactory::getDocument();
  40. $template = $app->getTemplate();
  41. // button is not active in specific content components
  42. $getContent = $this->_subject->getContent($name);
  43. $present = JText::_('PLG_READMORE_ALREADY_EXISTS', true);
  44. $js = "
  45. function insertReadmore(editor) {
  46. var content = $getContent
  47. if (content.match(/<hr\s+id=(\"|')system-readmore(\"|')\s*\/*>/i)) {
  48. alert('$present');
  49. return false;
  50. } else {
  51. jInsertEditorText('<hr id=\"system-readmore\" />', editor);
  52. }
  53. }
  54. ";
  55. $doc->addScriptDeclaration($js);
  56. $button = new JObject;
  57. $button->modal = false;
  58. $button->onclick = 'insertReadmore(\''.$name.'\');return false;';
  59. $button->text = JText::_('PLG_READMORE_BUTTON_READMORE');
  60. $button->name = 'arrow-down';
  61. // TODO: The button writer needs to take into account the javascript directive
  62. //$button->link', 'javascript:void(0)');
  63. $button->link = '#';
  64. return $button;
  65. }
  66. }