/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

  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. defined('JPATH_BASE') or die;
  10. /**
  11. * Supports a modal newsfeeds picker.
  12. *
  13. * @package Joomla.Administrator
  14. * @subpackage com_newsfeeds
  15. * @since 1.6
  16. */
  17. class JFormFieldModal_Newsfeeds extends JFormField
  18. {
  19. /**
  20. * The form field type.
  21. *
  22. * @var string
  23. * @since 1.6
  24. */
  25. protected $type = 'Modal_Newsfeeds';
  26. /**
  27. * Method to get the field input markup.
  28. *
  29. * @return string The field input markup.
  30. * @since 1.6
  31. */
  32. protected function getInput()
  33. {
  34. // Load the javascript
  35. JHtml::_('behavior.framework');
  36. JHtml::_('behavior.modal', 'input.modal');
  37. // Build the script.
  38. $script = array();
  39. $script[] = ' function jSelectChart_'.$this->id.'(id, name, object) {';
  40. $script[] = ' document.id("'.$this->id.'_id").value = id;';
  41. $script[] = ' document.id("'.$this->id.'_name").value = name;';
  42. $script[] = ' SqueezeBox.close();';
  43. $script[] = ' }';
  44. // Add the script to the document head.
  45. JFactory::getDocument()->addScriptDeclaration(implode("\n", $script));
  46. // Build the script.
  47. $script = array();
  48. $script[] = ' window.addEvent("domready", function() {';
  49. $script[] = ' var div = new Element("div").setStyle("display", "none").inject(document.id("menu-types"), "before");';
  50. $script[] = ' document.id("menu-types").inject(div, "bottom");';
  51. $script[] = ' });';
  52. // Add the script to the document head.
  53. JFactory::getDocument()->addScriptDeclaration(implode("\n", $script));
  54. // Get the title of the linked chart
  55. $db = JFactory::getDBO();
  56. $db->setQuery(
  57. 'SELECT name' .
  58. ' FROM #__newsfeeds' .
  59. ' WHERE id = '.(int) $this->value
  60. );
  61. try
  62. {
  63. $title = $db->loadResult();
  64. }
  65. catch (RuntimeException $e)
  66. {
  67. JError::raiseWarning(500, $e->getMessage);
  68. }
  69. if (empty($title)) {
  70. $title = JText::_('COM_NEWSFEEDS_SELECT_A_FEED');
  71. }
  72. $link = 'index.php?option=com_newsfeeds&amp;view=newsfeeds&amp;layout=modal&amp;tmpl=component&amp;function=jSelectChart_'.$this->id;
  73. JHtml::_('behavior.modal', 'a.modal');
  74. $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" />';
  75. $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";
  76. // The active newsfeed id field.
  77. if (0 == (int) $this->value)
  78. {
  79. $value = '';
  80. }
  81. else
  82. {
  83. $value = (int) $this->value;
  84. }
  85. // class='required' for client side validation
  86. $class = '';
  87. if ($this->required) {
  88. $class = ' class="required modal-value"';
  89. }
  90. $html .= '<input type="hidden" id="'.$this->id.'_id"'.$class.' name="'.$this->name.'" value="'.$value.'" />';
  91. return $html;
  92. }
  93. }