PageRenderTime 33ms CodeModel.GetById 8ms RepoModel.GetById 0ms app.codeStats 0ms

/com_flexicontent_v2.x/admin/elements/fields.php

http://flexicontent.googlecode.com/
PHP | 176 lines | 96 code | 29 blank | 51 comment | 18 complexity | 396f6d8f21479d7ccd8732362ad8ef6b MD5 | raw file
Possible License(s): MIT, GPL-2.0, Apache-2.0
  1. <?php
  2. /**
  3. * @version 1.5 stable $Id: fields.php 1683 2013-06-02 07:51:11Z ggppdk $
  4. * @package Joomla
  5. * @subpackage FLEXIcontent
  6. * @copyright (C) 2009 Emmanuel Danan - www.vistamedia.fr
  7. * @license GNU/GPL v2
  8. *
  9. * FLEXIcontent is a derivative work of the excellent QuickFAQ component
  10. * @copyright (C) 2008 Christoph Lukes
  11. * see www.schlu.net for more information
  12. *
  13. * FLEXIcontent is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. */
  18. // Check to ensure this file is included in Joomla!
  19. defined('_JEXEC') or die('Restricted access');
  20. if (FLEXI_J16GE) {
  21. jimport('joomla.html.html');
  22. jimport('joomla.form.formfield');
  23. jimport('joomla.form.helper');
  24. JFormHelper::loadFieldClass('list');
  25. }
  26. /**
  27. * Renders a fields element
  28. *
  29. * @package Joomla
  30. * @subpackage FLEXIcontent
  31. * @since 1.5
  32. */
  33. class JFormFieldFields extends JFormField
  34. {
  35. /**
  36. * Element name
  37. *
  38. * @access protected
  39. * @var string
  40. */
  41. var $type = 'Fields';
  42. function getInput()
  43. {
  44. $doc = JFactory::getDocument();
  45. $db = JFactory::getDBO();
  46. $cparams = JComponentHelper::getParams('com_flexicontent');
  47. if (FLEXI_J16GE) {
  48. $node = & $this->element;
  49. $attributes = get_object_vars($node->attributes());
  50. $attributes = $attributes['@attributes'];
  51. } else {
  52. $attributes = & $node->_attributes;
  53. }
  54. // *******************************************************************
  55. // Option labels and option values (for the created SELECT form field)
  56. // *******************************************************************
  57. $otext = ((boolean) @ $attributes['fieldnameastext']) ? "CONCAT(label, ' [', `name`, ']')" : 'label';
  58. $ovalue = ((boolean) @ $attributes['fieldnameasvalue']) ? '`name`' : 'id'; // for old FC versions compatibility, second option must be like id
  59. // *********************************
  60. // IS advanced filter / search FLAGs
  61. // *********************************
  62. $and = '';
  63. $isnotcore = (boolean) @ $attributes['isnotcore'];
  64. if ($isnotcore) {
  65. $and .= ' AND iscore = 0';
  66. }
  67. $isadvsearch = (int) @ $attributes['isadvsearch'];
  68. if($isadvsearch) {
  69. $and .= ' AND isadvsearch='.$isadvsearch;
  70. }
  71. $isadvfilter = (int) @ $attributes['isadvfilter'];
  72. if($isadvfilter) {
  73. $and .= ' AND isadvfilter='.$isadvfilter;
  74. }
  75. // ********************************
  76. // INCLUDE/EXCLUDE some field types
  77. // ********************************
  78. $field_type = (string) @ $attributes['field_type'];
  79. if($field_type) {
  80. $field_type = explode(",", $field_type);
  81. foreach($field_type as $i => $ft) $field_type_quoted[$i] = $db->Quote($ft);
  82. $and .= " AND field_type IN (". implode(",", $field_type_quoted).")";
  83. }
  84. $exclude_field_type = (string) @ $attributes['exclude_field_type'];
  85. if($exclude_field_type) {
  86. $exclude_field_type = explode(",", $exclude_field_type);
  87. foreach($exclude_field_type as $i => $ft) $exclude_field_type_quoted[$i] = $db->Quote($ft);
  88. $and .= " AND field_type NOT IN (". implode(",", $exclude_field_type_quoted).")";
  89. }
  90. $orderable = (int) @ $attributes['orderable'];
  91. if ($orderable) {
  92. $non_orderable = $cparams->get('non_orderable_types', 'toolbar,file,image,groupmarker,fcpagenav,minigallery,weblink,email');
  93. $non_orderable = explode(",", $non_orderable);
  94. foreach($non_orderable as $i => $ft) $non_orderable_quoted[$i] = $db->Quote($ft);
  95. $and .= " AND field_type NOT IN (". implode(",", $non_orderable_quoted).")";
  96. }
  97. // **************************
  98. // Retrieve field data for DB
  99. // **************************
  100. $query = 'SELECT '.$ovalue.' AS value, '.$otext.' AS text'
  101. .' FROM #__flexicontent_fields'
  102. .' WHERE published = 1'
  103. . $and
  104. .' ORDER BY label ASC, id ASC'
  105. ;
  106. $db->setQuery($query);
  107. $fields = $db->loadObjectList();
  108. // ***********************************
  109. // Values, form field name and id, etc
  110. // ***********************************
  111. $values = FLEXI_J16GE ? $this->value : $value;
  112. if ( empty($values) ) $values = array();
  113. else if ( ! is_array($values) ) $values = !FLEXI_J16GE ? array($values) : explode("|", $values);
  114. $fieldname = FLEXI_J16GE ? $this->name : $control_name.'['.$name.']';
  115. $element_id = FLEXI_J16GE ? $this->id : $control_name.$name;
  116. $name = FLEXI_J16GE ? $attributes['name'] : $name;
  117. $control_name = FLEXI_J16GE ? str_replace($name, '', $element_id) : $control_name;
  118. // *******************************************
  119. // HTML Tag parameters parameters, and styling
  120. // *******************************************
  121. $attribs = ' style="float:left;" ';
  122. if (@$attributes['multiple']=='multiple' || @$attributes['multiple']=='true' ) {
  123. $attribs .= ' multiple="true" ';
  124. $attribs .= (@$attributes['size']) ? ' size="'.$attributes['size'].'" ' : ' size="6" ';
  125. $fieldname .= !FLEXI_J16GE ? "[]" : ""; // NOTE: this added automatically in J2.5
  126. $maximize_link = "<a style='display:inline-block;".(FLEXI_J16GE ? 'float:left; margin: 6px 0px 0px 18px;':'margin:0px 0px 6px 12px')."' href='javascript:;' onclick='$element_id = document.getElementById(\"$element_id\"); if ($element_id.size<16) { ${element_id}_oldsize=$element_id.size; $element_id.size=16;} else { $element_id.size=${element_id}_oldsize; } ' >Maximize/Minimize</a>";
  127. } else {
  128. if ((boolean) @ $attributes['displa_useglobal']) {
  129. array_unshift($fields, JHTML::_('select.option', '' , JText::_('FLEXI_USE_GLOBAL')));
  130. array_unshift($fields, JHTML::_('select.option', '0', JText::_('FLEXI_NOT_SET'))); // Compatibility with older FC versions
  131. } else {
  132. array_unshift($fields, JHTML::_('select.option', '0', JText::_('FLEXI_PLEASE_SELECT')));
  133. }
  134. $attribs .= 'class="inputbox"';
  135. $maximize_link = '';
  136. }
  137. if ($onchange = @$attributes['onchange']) {
  138. $onchange = str_replace('{control_name}', $control_name, $onchange);
  139. $attribs .= ' onchange="'.$onchange.'"';
  140. }
  141. // ***********************
  142. // Create the field's HTML
  143. // ***********************
  144. $html = JHTML::_('select.genericlist', $fields, $fieldname, $attribs, 'value', 'text', $values, $element_id);
  145. return $html.$maximize_link;
  146. }
  147. }