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

/administrator/components/com_newsfeeds/models/fields/modal/newsfeeds.php

https://bitbucket.org/eternaware/joomus
PHP | 108 lines | 59 code | 15 blank | 34 comment | 4 complexity | c4a0fd5bdac2168cbe29d21fe541983a MD5 | raw file
Possible License(s): LGPL-2.1
  1<?php
  2/**
  3 * @package     Joomla.Administrator
  4 * @subpackage  com_newsfeeds
  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('JPATH_BASE') or die;
 11
 12/**
 13 * Supports a modal newsfeeds picker.
 14 *
 15 * @package     Joomla.Administrator
 16 * @subpackage  com_newsfeeds
 17 * @since       1.6
 18 */
 19class JFormFieldModal_Newsfeeds extends JFormField
 20{
 21	/**
 22	 * The form field type.
 23	 *
 24	 * @var		string
 25	 * @since	1.6
 26	 */
 27	protected $type = 'Modal_Newsfeeds';
 28
 29	/**
 30	 * Method to get the field input markup.
 31	 *
 32	 * @return	string	The field input markup.
 33	 * @since	1.6
 34	 */
 35	protected function getInput()
 36	{
 37		// Load the javascript
 38		JHtml::_('behavior.framework');
 39		JHtml::_('behavior.modal', 'input.modal');
 40
 41		// Build the script.
 42		$script = array();
 43		$script[] = '	function jSelectChart_'.$this->id.'(id, name, object) {';
 44		$script[] = '		document.id("'.$this->id.'_id").value = id;';
 45		$script[] = '		document.id("'.$this->id.'_name").value = name;';
 46		$script[] = '		SqueezeBox.close();';
 47		$script[] = '	}';
 48
 49		// Add the script to the document head.
 50		JFactory::getDocument()->addScriptDeclaration(implode("\n", $script));
 51
 52		// Build the script.
 53		$script = array();
 54		$script[] = '	window.addEvent("domready", function() {';
 55		$script[] = '		var div = new Element("div").setStyle("display", "none").inject(document.id("menu-types"), "before");';
 56		$script[] = '		document.id("menu-types").inject(div, "bottom");';
 57		$script[] = '	});';
 58
 59		// Add the script to the document head.
 60		JFactory::getDocument()->addScriptDeclaration(implode("\n", $script));
 61
 62		// Get the title of the linked chart
 63		$db = JFactory::getDBO();
 64		$db->setQuery(
 65			'SELECT name' .
 66			' FROM #__newsfeeds' .
 67			' WHERE id = '.(int) $this->value
 68		);
 69
 70		try
 71		{
 72			$title = $db->loadResult();
 73		}
 74		catch (RuntimeException $e)
 75		{
 76			JError::raiseWarning(500, $e->getMessage);
 77		}
 78
 79		if (empty($title)) {
 80			$title = JText::_('COM_NEWSFEEDS_SELECT_A_FEED');
 81		}
 82
 83		$link = 'index.php?option=com_newsfeeds&amp;view=newsfeeds&amp;layout=modal&amp;tmpl=component&amp;function=jSelectChart_'.$this->id;
 84
 85		JHtml::_('behavior.modal', 'a.modal');
 86		$html = "\n".'<div class="input-append"><input type="text" class="input-medium" id="'.$this->id.'_name" value="'.htmlspecialchars($title, ENT_QUOTES, 'UTF-8').'" disabled="disabled" />';
 87		$html .= '<a class="modal btn" title="'.JText::_('COM_NEWSFEEDS_CHANGE_FEED_BUTTON').'"  href="'.$link.'" rel="{handler: \'iframe\', size: {x: 800, y: 450}}"><i class="icon-feed" title="'.JText::_('COM_NEWSFEEDS_CHANGE_FEED_BUTTON').'"></i> '.JText::_('JSELECT').'</a></div>'."\n";
 88		// The active newsfeed id field.
 89		if (0 == (int) $this->value)
 90		{
 91			$value = '';
 92		}
 93		else
 94		{
 95			$value = (int) $this->value;
 96		}
 97
 98		// class='required' for client side validation
 99		$class = '';
100		if ($this->required) {
101			$class = ' class="required modal-value"';
102		}
103
104		$html .= '<input type="hidden" id="'.$this->id.'_id"'.$class.' name="'.$this->name.'" value="'.$value.'" />';
105
106		return $html;
107	}
108}