PageRenderTime 57ms CodeModel.GetById 21ms RepoModel.GetById 1ms app.codeStats 0ms

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

https://github.com/joebushi/joomla
PHP | 62 lines | 37 code | 7 blank | 18 comment | 1 complexity | a0547b937414e13fe0f9028ca8e203c1 MD5 | raw file
Possible License(s): LGPL-2.1, Apache-2.0
  1. <?php
  2. /**
  3. * @version $Id$
  4. * @package Joomla
  5. * @copyright Copyright (C) 2005 - 2010 Open Source Matters, Inc. All rights reserved.
  6. * @license GNU General Public License version 2 or later; see LICENSE.txt
  7. */
  8. // no direct access
  9. defined('_JEXEC') or die;
  10. jimport('joomla.plugin.plugin');
  11. /**
  12. * Editor Readmore buton
  13. *
  14. * @package Editors-xtd
  15. * @since 1.5
  16. */
  17. class plgButtonReadmore extends JPlugin
  18. {
  19. /**
  20. * readmore button
  21. * @return array A two element array of (imageName, textToInsert)
  22. */
  23. function onDisplay($name)
  24. {
  25. $app = JFactory::getApplication();
  26. $doc = &JFactory::getDocument();
  27. $template = $app->getTemplate();
  28. // button is not active in specific content components
  29. $getContent = $this->_subject->getContent($name);
  30. $present = JText::_('ALREADY_EXISTS', true) ;
  31. $js = "
  32. function insertReadmore(editor) {
  33. var content = $getContent
  34. if (content.match(/<hr\s+id=(\"|')system-readmore(\"|')\s*\/*>/i)) {
  35. alert('$present');
  36. return false;
  37. } else {
  38. jInsertEditorText('<hr id=\"system-readmore\" />', editor);
  39. }
  40. }
  41. ";
  42. $doc->addScriptDeclaration($js);
  43. $button = new JObject;
  44. $button->set('modal', false);
  45. $button->set('onclick', 'insertReadmore(\''.$name.'\');return false;');
  46. $button->set('text', JText::_('Readmore'));
  47. $button->set('name', 'readmore');
  48. // TODO: The button writer needs to take into account the javascript directive
  49. //$button->set('link', 'javascript:void(0)');
  50. $button->set('link', '#');
  51. return $button;
  52. }
  53. }