PageRenderTime 6ms CodeModel.GetById 1ms app.highlight 3ms RepoModel.GetById 0ms app.codeStats 0ms

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