Пример #1
0
	function onDisplayField(&$field, &$item)
	{
		// execute the code only if the field type match the plugin type
		if ( !in_array($field->field_type, self::$field_types) ) return;
		
		$field->label = JText::_($field->label);
		
		// initialize framework objects and other variables
		$document  = JFactory::getDocument();
		$app  = JFactory::getApplication();
		$user = JFactory::getUser();
		
		
		// Create the editor object of editor prefered by the user,
		// this will also add the needed JS to the HTML head
		$editor_name = $user->getParam('editor', $app->getCfg('editor'));
		$editor = JFactory::getEditor($editor_name);
		
		
		// Some field parameters for the textarea
		$show_buttons = false;//(boolean) $field->parameters->get( 'show_buttons', 1 ) ;
		
		// some parameter shortcuts
		$size      = $field->parameters->get( 'size', 30 ) ;
		$cols      = $field->parameters->get( 'cols', 75 ) ;
		$rows      = $field->parameters->get( 'rows', 20 ) ;
		$multiple  = $field->parameters->get( 'allow_multiple', 1 ) ;
		$max_values= (int)$field->parameters->get( 'max_values', 0 ) ;
		
		// This is field 's MAIN value property
		$value_usage   = $field->parameters->get( 'default_value_use', 0 ) ;
		$default_value = ($item->version == 0 || $value_usage > 0) ? $field->parameters->get( 'default_value', '' ) : '';
		
		// Optional value properties
		$title_usage   = $field->parameters->get( 'title_usage', 0 ) ;
		$default_title = ($item->version == 0 || $title_usage > 0) ? JText::_($field->parameters->get( 'default_value_title', '' )) : '';
		$usetitle      = $field->parameters->get( 'use_title', 0 ) ;
		
		$required   = $field->parameters->get( 'required', 0 ) ;
		$required   = $required ? ' required' : '';
		
		// Initialise property with default value
		if ( !$field->value ) {
			$field->value = array();
			$field->value[0]['title'] = JText::_($default_title);
			$field->value[0]['text']  = JText::_($default_value);
			$field->value[0] = serialize($field->value[0]);
		}
		
		$js = "";
		
		if ($multiple) // handle multiple records
		{
			if (!FLEXI_J16GE) $document->addScript( JURI::root(true).'/components/com_flexicontent/assets/js/sortables.js' );
			
			// Add the drag and drop sorting feature
			$js .= "
			jQuery(document).ready(function(){
				jQuery('#sortables_".$field->id."').sortable({
					handle: '.fcfield-drag',
					containment: 'parent',
					tolerance: 'pointer'
				});
			});
			";
			
			$fieldname = FLEXI_J16GE ? 'custom['.$field->name.']' : $field->name;
			$elementid = FLEXI_J16GE ? 'custom_'.$field->name : $field->name;
			
			if ($max_values) FLEXI_J16GE ? JText::script("FLEXI_FIELD_MAX_ALLOWED_VALUES_REACHED", true) : fcjsJText::script("FLEXI_FIELD_MAX_ALLOWED_VALUES_REACHED", true);
			$js .= "
			var uniqueRowNum".$field->id."	= ".count($field->value).";  // Unique row number incremented only
			var rowCount".$field->id."	= ".count($field->value).";      // Counts existing rows to be able to limit a max number of values
			var maxValues".$field->id."		= ".$max_values.";

			function addField".$field->id."(el) {
				if((rowCount".$field->id." >= maxValues".$field->id.") && (maxValues".$field->id." != 0)) {
					alert(Joomla.JText._('FLEXI_FIELD_MAX_ALLOWED_VALUES_REACHED') + maxValues".$field->id.");
					return 'cancel';
				}

				var thisField 	 = $(el).getPrevious().getLast();
				var thisNewField = thisField.clone();
				
				jQuery(thisNewField.getElements('label.labeltitle')).text('".JText::_( 'FLEXI_FIELD_TERMTITLE' )." '+parseInt(rowCount".$field->id."+1)+':');
				jQuery(thisNewField.getElements('label.labeltext')).text('".JText::_( 'FLEXI_FIELD_TERMTEXT' )." '+parseInt(rowCount".$field->id."+1)+':');
				jQuery(thisNewField).find('label.labeltitle').attr('for', '".$elementid."_'+uniqueRowNum".$field->id."+'_title');
				jQuery(thisNewField).find('label.labeltext').attr('for', '".$elementid."_'+uniqueRowNum".$field->id."+'_text');
				";
				
			if ($usetitle) $js .= "
				jQuery(thisNewField.getElements('textarea.termtitle')).val('');
				thisNewField.getElements('textarea.termtitle').setProperty('name','".$fieldname."['+uniqueRowNum".$field->id."+'][title]');
				thisNewField.getElements('textarea.termtitle').setProperty('id','".$elementid."_'+uniqueRowNum".$field->id."+'_title');
				";
				
			$js .= "
				var container = jQuery(thisNewField).find('.fctextbox');
				container.after('<div class=\"fctextbox\"></div>');
				container.find('textarea').show().appendTo(container.next());
				container.remove();
				jQuery(thisNewField).find('.fctextbox').find('textarea').val('');
				jQuery(thisNewField).find('.fctextbox').find('textarea').attr('name','".$fieldname."['+uniqueRowNum".$field->id."+'][text]');
				jQuery(thisNewField).find('.fctextbox').find('textarea').attr('id','".$elementid."_'+uniqueRowNum".$field->id."+'_text');
				jQuery(thisNewField).find('.fctextbox').find('textarea').removeClass();
				jQuery(thisNewField).find('.fctextbox').find('textarea').addClass('termtext');
				";
				
			$js .= "
				jQuery(thisNewField).css('display', 'none');
				jQuery(thisNewField).insertAfter( jQuery(thisField) );
				
				jQuery('#sortables_".$field->id."').sortable({
					handle: '.fcfield-drag',
					containment: 'parent',
					tolerance: 'pointer'
				});
				
				//jQuery(thisNewField).show('slideDown');
				jQuery(thisNewField).show();
				tinyMCE.execCommand('mceAddControl', false, '".$elementid."_'+uniqueRowNum".$field->id."+'_text');
				
				rowCount".$field->id."++;       // incremented / decremented
				uniqueRowNum".$field->id."++;   // incremented only
			}

			function deleteField".$field->id."(el)
			{
				if(rowCount".$field->id." <= 1) return;
				var row = jQuery(el).closest('li');
				jQuery(row).hide('slideUp', function() { jQuery(this).remove(); } );
				rowCount".$field->id."--;
			}
			";
			
			$css = '
			#sortables_'.$field->id.' { float:left; margin: 0px; padding: 0px; list-style: none; white-space: nowrap; }
			#sortables_'.$field->id.' li {
				clear: both !important;
				display: block;
				list-style: none !important;
				height: auto !important;
				position: relative !important;
				background:#EAEAEA !important;
				border-radius:5px !important;
				margin-bottom:10px !important;
				padding:5px !important;
				border:1px solid #ccc !important;
			}
			#sortables_'.$field->id.' li.sortabledisabled {
				background : transparent url(components/com_flexicontent/assets/images/move3.png) no-repeat 0px 1px;
			}
			#sortables_'.$field->id.' li input { cursor: text;}
			#add'.$field->name.' { margin-top: 5px; clear: both; display:block; }
			#sortables_'.$field->id.' li .admintable { text-align: left; }
			#sortables_'.$field->id.' li:only-child span.fcfield-drag, #sortables_'.$field->id.' li:only-child input.fcfield-button { display:none; }
			#sortables_'.$field->id.' label.label, #sortables_'.$field->id.' .termtitle, #sortables_'.$field->id.' .termtext, #sortables_'.$field->id.' input.fcfield-button {
				float: none;
				display: inline-block;
			}
			';
			
			$remove_button = '<input class="fcfield-button" type="button" value="'.JText::_( 'FLEXI_REMOVE_VALUE' ).'" onclick="deleteField'.$field->id.'(this);" />';
			$move2 	= '<span class="fcfield-drag">'.JHTML::image ( JURI::base().'components/com_flexicontent/assets/images/move2.png', JText::_( 'FLEXI_CLICK_TO_DRAG' ) ) .'</span>';
		} else {
			$remove_button = '';
			$move2 = '';
			$js = '';
			$css = '';
		}
		
		if ($js)  $document->addScriptDeclaration($js);
		if ($css) $document->addStyleDeclaration($css);
		
		$field->html = array();
		$n = 0;
		foreach ($field->value as $value) {
			if ( @unserialize($value)!== false || $value === 'b:0;' ) {
				$value = unserialize($value);
			} else {
				$value = array('title' => $value, 'text' => '');
			}
			$fieldname = FLEXI_J16GE ? 'custom['.$field->name.']['.$n.']' : $field->name.'['.$n.']';
			$elementid = FLEXI_J16GE ? 'custom_'.$field->name.'_'.$n : $field->name.'_'.$n;
			
			if ($usetitle) $title = '
				<br/><label class="label labeltitle" for="'.$elementid.'_title">'.JText::_( 'FLEXI_FIELD_TERMTITLE' ).' '.($multiple?($n+1):'').':</label><br/>
				<textarea class="fcfield_textval termtitle'.$required.'" id="'.$elementid.'_title" name="'.$fieldname.'[title]" cols="'.$cols.'" rows="'.$rows.'">'.$value['title'].'</textarea><br/><br/>
			';
			
			/*if ($usetitle) $text = '
				<label class="label labeltext" for="'.$fieldname.'[text]">'.JText::_( 'FLEXI_FIELD_TERMTEXT' ).' '.($multiple?($n+1):'').':</label>
				<input class="fcfield_textval termtext" name="'.$fieldname.'[text]" type="text" size="'.$size.'" value="'.@$value['text'].'" />
			';*/
			$text = '
				<label class="label labeltext" for="'.$elementid.'_text">'.JText::_( 'FLEXI_FIELD_TERMTEXT' ).' '.($multiple?($n+1):'').':</label>
				'.
				//<textarea class="fcfield_textval termtext" name="'.$fieldname.'[text]" cols="'.$cols.'" rows="'.$rows.'">'.@$value['text'].'</textarea>
				'<div class="fctextbox">'.$editor->display($fieldname.'[text]', $value['text'], $width='100%', $height='100%', $cols, $rows, $show_buttons, $elementid.'_text') . '</div>
			';
			
			
			$field->html[] = '
				'.@$title.'
				'.$text.'
				<div class="clear"></div>
				'.$move2.'
				'.$remove_button.'
				<div class="clear"></div>
				';
			
			$n++;
			if (!$multiple) break;  // multiple values disabled, break out of the loop, not adding further values even if the exist
		}
		
		if ($multiple) { // handle multiple records
			$_list = "<li>". implode("</li>\n<li>", $field->html) ."</li>\n";
			$field->html = '
				<ul class="fcfield-sortables" id="sortables_'.$field->id.'">' .$_list. '</ul>
				<input type="button" class="fcfield-addvalue" onclick="addField'.$field->id.'(this);" value="'.JText::_( 'FLEXI_ADD_VALUE' ).'" />
			';
		} else {  // handle single values
			$field->html = $field->html[0];
		}
	}
    function onDisplayField(&$field, &$item)
    {
        if (!in_array($field->field_type, self::$field_types)) {
            return;
        }
        $field->label = JText::_($field->label);
        $use_ingroup = $field->parameters->get('use_ingroup', 0);
        if ($use_ingroup) {
            $field->formhidden = 3;
        }
        if ($use_ingroup && empty($field->ingroup)) {
            return;
        }
        // initialize framework objects and other variables
        $document = JFactory::getDocument();
        // ****************
        // Number of values
        // ****************
        $multiple = $use_ingroup || (int) $field->parameters->get('allow_multiple', 0);
        $max_values = $use_ingroup ? 0 : (int) $field->parameters->get('max_values', 0);
        $required = $field->parameters->get('required', 0);
        $required = $required ? ' required' : '';
        $add_position = (int) $field->parameters->get('add_position', 3);
        // **************
        // Value handling
        // **************
        // Optional form elements
        $use_label = (int) $field->parameters->get('use_label', 1);
        $use_cc = (int) $field->parameters->get('use_cc', 1);
        $use_phone = (int) $field->parameters->get('use_phone', 3);
        $show_part_labels = (int) $field->parameters->get('show_part_labels', 0);
        // Input field display size & max characters
        if ($use_label) {
            $label_size = (int) $field->parameters->get('label_size', 48);
            $label_maxlength = (int) $field->parameters->get('label_maxlength', 0);
            // client/server side enforced
        }
        if ($use_cc) {
            $cc_size = (int) $field->parameters->get('cc_size', 6);
            $cc_maxlength = (int) $field->parameters->get('cc_maxlength', 0);
            // client/server side enforced
        }
        $phone1_size = (int) $field->parameters->get('phone1_size', 12);
        $phone1_maxlength = (int) $field->parameters->get('phone1_maxlength', 0);
        // client/server side enforced
        $phone2_size = (int) $field->parameters->get('phone2_size', 12);
        $phone2_maxlength = (int) $field->parameters->get('phone2_maxlength', 0);
        // client/server side enforced
        $phone3_size = (int) $field->parameters->get('phone3_size', 12);
        $phone3_maxlength = (int) $field->parameters->get('phone3_maxlength', 0);
        // client/server side enforced
        // Create extra HTML TAG parameters for the form field(s)
        if ($use_label) {
            $label_attribs = ' size="' . $label_size . '"' . ($label_maxlength ? ' maxlength="' . $label_maxlength . '" ' : '');
        }
        if ($use_cc) {
            $cc_attribs = ' size="' . $cc_size . '"' . ($cc_maxlength ? ' maxlength="' . $cc_maxlength . '" ' : '');
        }
        $phone1_attribs = ' size="' . $phone1_size . '"' . ($phone1_maxlength ? ' maxlength="' . $phone1_maxlength . '" ' : '');
        $phone2_attribs = ' size="' . $phone2_size . '"' . ($phone2_maxlength ? ' maxlength="' . $phone2_maxlength . '" ' : '');
        $phone3_attribs = ' size="' . $phone3_size . '"' . ($phone3_maxlength ? ' maxlength="' . $phone3_maxlength . '" ' : '');
        // Initialise property with default value
        if (!$field->value) {
            $field->value = array();
            $field->value[0] = array('label' => '', 'cc' => '', 'phone1' => '', 'phone2' => '', 'phone3' => '');
            $field->value[0] = serialize($field->value[0]);
        }
        // CSS classes of value container
        $value_classes = 'fcfieldval_container valuebox fcfieldval_container_' . $field->id;
        // Field name and HTML TAG id
        $fieldname = 'custom[' . $field->name . ']';
        $elementid = 'custom_' . $field->name;
        $js = "";
        $css = "";
        if ($multiple) {
            // Add the drag and drop sorting feature
            if (!$use_ingroup) {
                $js .= "\n\t\t\tjQuery(document).ready(function(){\n\t\t\t\tjQuery('#sortables_" . $field->id . "').sortable({\n\t\t\t\t\thandle: '.fcfield-drag-handle',\n\t\t\t\t\tcontainment: 'parent',\n\t\t\t\t\ttolerance: 'pointer'\n\t\t\t\t});\n\t\t\t});\n\t\t\t";
            }
            if ($max_values) {
                FLEXI_J16GE ? JText::script("FLEXI_FIELD_MAX_ALLOWED_VALUES_REACHED", true) : fcjsJText::script("FLEXI_FIELD_MAX_ALLOWED_VALUES_REACHED", true);
            }
            $js .= "\n\t\t\tvar uniqueRowNum" . $field->id . "\t= " . count($field->value) . ";  // Unique row number incremented only\n\t\t\tvar rowCount" . $field->id . "\t= " . count($field->value) . ";      // Counts existing rows to be able to limit a max number of values\n\t\t\tvar maxValues" . $field->id . " = " . $max_values . ";\n\t\t\t\n\t\t\tfunction addField" . $field->id . "(el, groupval_box, fieldval_box, params)\n\t\t\t{\n\t\t\t\tvar insert_before   = (typeof params!== 'undefined' && typeof params.insert_before   !== 'undefined') ? params.insert_before   : 0;\n\t\t\t\tvar remove_previous = (typeof params!== 'undefined' && typeof params.remove_previous !== 'undefined') ? params.remove_previous : 0;\n\t\t\t\tvar scroll_visible  = (typeof params!== 'undefined' && typeof params.scroll_visible  !== 'undefined') ? params.scroll_visible  : 1;\n\t\t\t\tvar animate_visible = (typeof params!== 'undefined' && typeof params.animate_visible !== 'undefined') ? params.animate_visible : 1;\n\t\t\t\t\n\t\t\t\tif((rowCount" . $field->id . " >= maxValues" . $field->id . ") && (maxValues" . $field->id . " != 0)) {\n\t\t\t\t\talert(Joomla.JText._('FLEXI_FIELD_MAX_ALLOWED_VALUES_REACHED') + maxValues" . $field->id . ");\n\t\t\t\t\treturn 'cancel';\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\tvar lastField = fieldval_box ? fieldval_box : jQuery(el).prev().children().last();\n\t\t\t\tvar newField  = lastField.clone();\n\t\t\t\t\n\t\t\t\ttheInput = newField.find('input.phonelabel').first();\n\t\t\t\ttheInput.val('');\n\t\t\t\ttheInput.attr('name','custom[" . $field->name . "]['+uniqueRowNum" . $field->id . "+'][label]');\n\t\t\t\ttheInput.attr('id','" . $elementid . "_'+uniqueRowNum" . $field->id . "+'_label');\n\t\t\t\tnewField.find('.phonelabel-lbl').first().attr('for','" . $elementid . "_'+uniqueRowNum" . $field->id . "+'_label');\n\t\t\t\t\n\t\t\t\ttheInput = newField.find('input.phonecc').first();\n\t\t\t\ttheInput.val('');\n\t\t\t\ttheInput.attr('name','custom[" . $field->name . "]['+uniqueRowNum" . $field->id . "+'][cc]');\n\t\t\t\ttheInput.attr('id','" . $elementid . "_'+uniqueRowNum" . $field->id . "+'_cc');\n\t\t\t\tnewField.find('.phonecc-lbl').first().attr('for','" . $elementid . "_'+uniqueRowNum" . $field->id . "+'_cc');\n\t\t\t\t\n\t\t\t\ttheInput = newField.find('input.phonenum1').first();\n\t\t\t\ttheInput.val('');\n\t\t\t\ttheInput.attr('name','custom[" . $field->name . "]['+uniqueRowNum" . $field->id . "+'][phone1]');\n\t\t\t\ttheInput.attr('id','" . $elementid . "_'+uniqueRowNum" . $field->id . "+'_phone1');\n\t\t\t\tnewField.find('.phonenum1-lbl').first().attr('for','" . $elementid . "_'+uniqueRowNum" . $field->id . "+'_phone1');\n\t\t\t\t\n\t\t\t\ttheInput = newField.find('input.phonenum2').first();\n\t\t\t\ttheInput.val('');\n\t\t\t\ttheInput.attr('name','custom[" . $field->name . "]['+uniqueRowNum" . $field->id . "+'][phone2]');\n\t\t\t\ttheInput.attr('id','" . $elementid . "_'+uniqueRowNum" . $field->id . "+'_phone2');\n\t\t\t\tnewField.find('.phonenum2-lbl').first().attr('for','" . $elementid . "_'+uniqueRowNum" . $field->id . "+'_phone2');\n\t\t\t\t\n\t\t\t\ttheInput = newField.find('input.phonenum3').first();\n\t\t\t\ttheInput.val('');\n\t\t\t\ttheInput.attr('name','custom[" . $field->name . "]['+uniqueRowNum" . $field->id . "+'][phone3]');\n\t\t\t\ttheInput.attr('id','" . $elementid . "_'+uniqueRowNum" . $field->id . "+'_phone3');\n\t\t\t\tnewField.find('.phonenum3-lbl').first().attr('for','" . $elementid . "_'+uniqueRowNum" . $field->id . "+'_phone3');\n\t\t\t\t";
            // Add new field to DOM
            $js .= "\n\t\t\t\tlastField ?\n\t\t\t\t\t(insert_before ? newField.insertBefore( lastField ) : newField.insertAfter( lastField ) ) :\n\t\t\t\t\tnewField.appendTo( jQuery('#sortables_" . $field->id . "') ) ;\n\t\t\t\tif (remove_previous) lastField.remove();\n\t\t\t\t";
            // Add new element to sortable objects (if field not in group)
            if (!$use_ingroup) {
                $js .= "\n\t\t\t\tjQuery('#sortables_" . $field->id . "').sortable({\n\t\t\t\t\thandle: '.fcfield-drag-handle',\n\t\t\t\t\tcontainment: 'parent',\n\t\t\t\t\ttolerance: 'pointer'\n\t\t\t\t});\n\t\t\t\t";
            }
            // Show new field, increment counters
            $js .= "\n\t\t\t\t//newField.fadeOut({ duration: 400, easing: 'swing' }).fadeIn({ duration: 200, easing: 'swing' });\n\t\t\t\tif (scroll_visible) fc_scrollIntoView(newField, 1);\n\t\t\t\tif (animate_visible) newField.css({opacity: 0.1}).animate({ opacity: 1 }, 800);\n\t\t\t\t\n\t\t\t\trowCount" . $field->id . "++;       // incremented / decremented\n\t\t\t\tuniqueRowNum" . $field->id . "++;   // incremented only\n\t\t\t}\n\n\t\t\tfunction deleteField" . $field->id . "(el, groupval_box, fieldval_box)\n\t\t\t{\n\t\t\t\t// Find field value container\n\t\t\t\tvar row = fieldval_box ? fieldval_box : jQuery(el).closest('li');\n\t\t\t\t\n\t\t\t\t// Add empty container if last element, instantly removing the given field value container\n\t\t\t\tif(rowCount" . $field->id . " == 1)\n\t\t\t\t\taddField" . $field->id . "(null, groupval_box, row, {remove_previous: 1, scroll_visible: 0, animate_visible: 0});\n\t\t\t\t\n\t\t\t\t// Remove if not last one, if it is last one, we issued a replace (copy,empty new,delete old) above\n\t\t\t\tif(rowCount" . $field->id . " > 1) {\n\t\t\t\t\t// Destroy the remove/add/etc buttons, so that they are not reclicked, while we do the hide effect (before DOM removal of field value)\n\t\t\t\t\trow.find('.fcfield-delvalue').remove();\n\t\t\t\t\trow.find('.fcfield-insertvalue').remove();\n\t\t\t\t\trow.find('.fcfield-drag-handle').remove();\n\t\t\t\t\t// Do hide effect then remove from DOM\n\t\t\t\t\trow.slideUp(400, function(){ this.remove(); });\n\t\t\t\t\trowCount" . $field->id . "--;\n\t\t\t\t}\n\t\t\t}\n\t\t\t";
            $css .= '';
            $remove_button = '<span class="fcfield-delvalue" title="' . JText::_('FLEXI_REMOVE_VALUE') . '" onclick="deleteField' . $field->id . '(this);"></span>';
            $move2 = '<span class="fcfield-drag-handle" title="' . JText::_('FLEXI_CLICK_TO_DRAG') . '"></span>';
            $add_here = '';
            $add_here .= $add_position == 2 || $add_position == 3 ? '<span class="fcfield-insertvalue fc_before" onclick="addField' . $field->id . '(null, jQuery(this).closest(\'ul\'), jQuery(this).closest(\'li\'), {insert_before: 1});" title="' . JText::_('FLEXI_ADD_BEFORE') . '"></span> ' : '';
            $add_here .= $add_position == 1 || $add_position == 3 ? '<span class="fcfield-insertvalue fc_after"  onclick="addField' . $field->id . '(null, jQuery(this).closest(\'ul\'), jQuery(this).closest(\'li\'), {insert_before: 0});" title="' . JText::_('FLEXI_ADD_AFTER') . '"></span> ' : '';
        } else {
            $remove_button = '';
            $move2 = '';
            $add_here = '';
            $js .= '';
            $css .= '';
        }
        if ($js) {
            $document->addScriptDeclaration($js);
        }
        if ($css) {
            $document->addStyleDeclaration($css);
        }
        if ($show_part_labels) {
            $part1_lbl = $use_phone > 1 ? 'PLG_FLEXICONTENT_FIELDS_PHONENUMBERS_PHONE_AREA_CODE' : '';
            $part2_lbl = $use_phone == 2 ? 'PLG_FLEXICONTENT_FIELDS_PHONENUMBERS_PHONE_LOCAL_NUM' : ($use_phone == 3 ? 'PLG_FLEXICONTENT_FIELDS_PHONENUMBERS_PHONE_PART_2' : '');
            $part3_lbl = $use_phone > 2 ? 'PLG_FLEXICONTENT_FIELDS_PHONENUMBERS_PHONE_PART_3' : '';
        }
        // *****************************************
        // Create field's HTML display for item form
        // *****************************************
        $field->html = array();
        $n = 0;
        //if ($use_ingroup) {print_r($field->value);}
        foreach ($field->value as $value) {
            // Compatibility for unserialized values (e.g. reload user input after form validation error) or for NULL values in a field group
            if (!is_array($value)) {
                $v = !empty($value) ? @unserialize($value) : false;
                $value = $v !== false || $v === 'b:0;' ? $v : array('label' => '', 'cc' => '', 'phone1' => $value, 'phone2' => '', 'phone3' => '');
            }
            if (empty($value['label']) && empty($value['cc']) && empty($value['phone1']) && empty($value['phone2']) && empty($value['phone3']) && !$use_ingroup && $n) {
                continue;
            }
            // If at least one added, skip empty if not in field group
            $fieldname_n = $fieldname . '[' . $n . ']';
            $elementid_n = $elementid . '_' . $n;
            $phonelabel = !$use_label ? '' : '
				<tr><td class="key">' . JText::_('PLG_FLEXICONTENT_FIELDS_PHONENUMBERS_PHONE_LABEL') . '</td><td>
					<input class="fcfield_textval phonelabel" name="' . $fieldname_n . '[label]" id="' . $elementid_n . '_label" type="text" value="' . @$value['label'] . '" ' . $label_attribs . ' />
				</td></tr>';
            $phonecc = !$use_cc ? '' : '
				<tr><td class="key">' . JText::_('PLG_FLEXICONTENT_FIELDS_PHONENUMBERS_COUNTRY_CODE') . '</td><td>
					<input class="phonecc fcfield_textval inlineval" name="' . $fieldname_n . '[cc]" id="' . $elementid_n . '_cc" type="text" value="' . @$value['cc'] . '" ' . $cc_attribs . ' />
				</td></tr>';
            $phone = '
				<tr><td class="key">' . JText::_('PLG_FLEXICONTENT_FIELDS_PHONENUMBERS_PHONE_NUMBER') . '</td><td>
					<div class="nowrap_box">
						' . ($show_part_labels && $part2_lbl ? '<label class="label phonenum1-lbl" for="' . $elementid_n . '_phone2" >' . JText::_($part2_lbl) . '</label><br/>' : '') . '
						<input class="phonenum1 fcfield_textval inlineval validate-numeric' . $required . '" name="' . $fieldname_n . '[phone1]" id="' . $elementid_n . '_phone1" type="text" value="' . $value['phone1'] . '" ' . $phone1_attribs . ' />
						' . ($use_phone > 1 ? '-' : '') . '
					</div>
					
					' . ($use_phone >= 2 ? '
					<div class="nowrap_box">
						' . ($show_part_labels && $part3_lbl ? '<label class="label phonenum2-lbl" for="' . $elementid_n . '_phone3" >' . JText::_($part3_lbl) . '</label><br/>' : '') . '
						<input class="phonenum2 fcfield_textval inlineval validate-numeric' . $required . '" name="' . $fieldname_n . '[phone2]" id="' . $elementid_n . '_phone2" type="text" value="' . $value['phone2'] . '" ' . $phone2_attribs . ' />
						' . ($use_phone > 2 ? '-' : '') . '
					</div>' : '') . '
					
					' . ($use_phone > 2 ? '
					<div class="nowrap_box">
						' . ($show_part_labels && $part1_lbl ? '<label class="label phonenum3-lbl" for="' . $elementid_n . '_phone1" >' . JText::_($part1_lbl) . '</label><br/>' : '') . '
						<input class="phonenum3 fcfield_textval inlineval validate-numeric' . $required . '" name="' . $fieldname_n . '[phone3]" id="' . $elementid_n . '_phone3" type="text" value="' . $value['phone3'] . '" ' . $phone3_attribs . ' />
					</div>' : '') . '
				</td></tr>';
            $field->html[] = '
				' . ($use_ingroup ? '' : $move2) . '
				' . ($use_ingroup ? '' : $remove_button) . '
				' . ($use_ingroup || !$add_position ? '' : $add_here) . '
				' . ($use_ingroup ? '' : '<div class="fcclear"></div>') . '
				<table class="admintable"><tbody>
				' . $phonelabel . '
				' . $phonecc . '
				' . $phone . '
				</tbody></table>
				';
            $n++;
            if (!$multiple) {
                break;
            }
            // multiple values disabled, break out of the loop, not adding further values even if the exist
        }
        if ($use_ingroup) {
            // do not convert the array to string if field is in a group
        } else {
            if ($multiple) {
                // handle multiple records
                $field->html = '<li class="' . $value_classes . '">' . implode('</li><li class="' . $value_classes . '">', $field->html) . '</li>';
                $field->html = '<ul class="fcfield-sortables" id="sortables_' . $field->id . '">' . $field->html . '</ul>';
                if (!$add_position) {
                    $field->html .= '<span class="fcfield-addvalue" onclick="addField' . $field->id . '(this);" title="' . JText::_('FLEXI_ADD_TO_BOTTOM') . '"></span>';
                }
            } else {
                // handle single values
                $field->html = '<div class="fcfieldval_container valuebox fcfieldval_container_' . $field->id . '">' . $field->html[0] . '</div>';
            }
        }
    }
Пример #3
0
    function onDisplayField(&$field, &$item)
    {
        if (!in_array($field->field_type, self::$field_types)) {
            return;
        }
        $field->label = JText::_($field->label);
        $use_ingroup = $field->parameters->get('use_ingroup', 0);
        if ($use_ingroup) {
            $field->formhidden = 3;
        }
        if ($use_ingroup && empty($field->ingroup)) {
            return;
        }
        // initialize framework objects and other variables
        $document = JFactory::getDocument();
        $app = JFactory::getApplication();
        $user = JFactory::getUser();
        // Create the editor object of editor prefered by the user,
        // this will also add the needed JS to the HTML head
        $editor_name = $field->parameters->get('editor', $user->getParam('editor', $app->getCfg('editor')));
        $editor = JFactory::getEditor($editor_name);
        $editor_plg_params = array();
        // Override parameters of the editor plugin, ignored by most editors !!
        // ****************
        // Number of values
        // ****************
        $multiple = $use_ingroup || (int) $field->parameters->get('allow_multiple', 0);
        $max_values = $use_ingroup ? 0 : (int) $field->parameters->get('max_values', 0);
        $required = (int) $field->parameters->get('required', 0);
        $required = $required ? ' required' : '';
        $add_position = (int) $field->parameters->get('add_position', 3);
        // **********
        // Term title
        // **********
        // Label
        $title_label = JText::_($field->parameters->get('title_label', 'FLEXI_FIELD_TERMTITLE'));
        // Default value
        $title_usage = $field->parameters->get('title_usage', 0);
        $default_title = $item->version == 0 || $title_usage > 0 ? JText::_($field->parameters->get('default_value_title', '')) : '';
        $default_title = $default_title ? JText::_($default_title) : '';
        // Input field display size & max characters
        $title_size = $field->parameters->get('title_size', 80);
        $title_maxlength = $field->parameters->get('title_size', 0);
        // ***********************
        // Term text (description)
        // ***********************
        // Label
        $value_label = JText::_($field->parameters->get('value_label', 'FLEXI_FIELD_TERMTEXT'));
        // Default value
        $value_usage = $field->parameters->get('default_value_use', 0);
        $default_value = $item->version == 0 || $value_usage > 0 ? $field->parameters->get('default_value', '') : '';
        $default_value = $default_value ? JText::_($default_value) : '';
        // Editing method, text editor or HTML editor
        $use_html = $field->parameters->get('use_html', 1);
        // *** Simple Textarea ***
        $rows = $field->parameters->get('rows', 3);
        $cols = $field->parameters->get('cols', 80);
        $maxlength = (int) $field->parameters->get('maxlength', 0);
        // client/server side enforced when using textarea, otherwise this will depend on the HTML editor (and only will be client size only)
        // *** HTML Editor configuration  ***
        $width = $field->parameters->get('width', '98%');
        if ($width != (int) $width) {
            $width .= 'px';
        }
        $height = $field->parameters->get('height', '250px');
        if ($height != (int) $height) {
            $height .= 'px';
        }
        // Decide editor plugin buttons to SKIP
        $show_buttons = $field->parameters->get('show_buttons', 1);
        $skip_buttons = $field->parameters->get('skip_buttons', '');
        $skip_buttons = is_array($skip_buttons) ? $skip_buttons : explode('|', $skip_buttons);
        // Clear empty value
        if (empty($skip_buttons[0])) {
            unset($skip_buttons[0]);
        }
        // Force skipping pagebreak and readmore for CUSTOM textarea fields
        if ($field->field_type == 'textarea') {
            if (!in_array('pagebreak', $skip_buttons)) {
                $skip_buttons[] = 'pagebreak';
            }
            if (!in_array('readmore', $skip_buttons)) {
                $skip_buttons[] = 'readmore';
            }
        }
        $skip_buttons_arr = $show_buttons && $editor_name == 'jce' && count($skip_buttons) ? $skip_buttons : (bool) $show_buttons;
        // JCE supports skipping buttons
        // Initialise property with default value
        if (!$field->value) {
            $field->value = array();
            $field->value[0]['title'] = $default_title;
            $field->value[0]['text'] = $default_value;
            $field->value[0] = serialize($field->value[0]);
        }
        // CSS classes of value container
        $value_classes = 'fcfieldval_container valuebox fcfieldval_container_' . $field->id;
        // Field name and HTML TAG id
        $fieldname = 'custom[' . $field->name . ']';
        $elementid = 'custom_' . $field->name;
        $js = "";
        $css = "";
        if ($multiple) {
            // Add the drag and drop sorting feature
            if (!$use_ingroup) {
                $js .= "\n\t\t\tjQuery(document).ready(function(){\n\t\t\t\tjQuery('#sortables_" . $field->id . "').sortable({\n\t\t\t\t\thandle: '.fcfield-drag-handle',\n\t\t\t\t\tcontainment: 'parent',\n\t\t\t\t\ttolerance: 'pointer'\n\t\t\t\t});\n\t\t\t});\n\t\t\t";
            }
            if ($max_values) {
                FLEXI_J16GE ? JText::script("FLEXI_FIELD_MAX_ALLOWED_VALUES_REACHED", true) : fcjsJText::script("FLEXI_FIELD_MAX_ALLOWED_VALUES_REACHED", true);
            }
            $js .= "\n\t\t\tvar uniqueRowNum" . $field->id . "\t= " . count($field->value) . ";  // Unique row number incremented only\n\t\t\tvar rowCount" . $field->id . "\t= " . count($field->value) . ";      // Counts existing rows to be able to limit a max number of values\n\t\t\tvar maxValues" . $field->id . " = " . $max_values . ";\n\t\t\t\n\t\t\tfunction addField" . $field->id . "(el, groupval_box, fieldval_box, params)\n\t\t\t{\n\t\t\t\tvar insert_before   = (typeof params!== 'undefined' && typeof params.insert_before   !== 'undefined') ? params.insert_before   : 0;\n\t\t\t\tvar remove_previous = (typeof params!== 'undefined' && typeof params.remove_previous !== 'undefined') ? params.remove_previous : 0;\n\t\t\t\tvar scroll_visible  = (typeof params!== 'undefined' && typeof params.scroll_visible  !== 'undefined') ? params.scroll_visible  : 1;\n\t\t\t\tvar animate_visible = (typeof params!== 'undefined' && typeof params.animate_visible !== 'undefined') ? params.animate_visible : 1;\n\t\t\t\t\n\t\t\t\tif((rowCount" . $field->id . " >= maxValues" . $field->id . ") && (maxValues" . $field->id . " != 0)) {\n\t\t\t\t\talert(Joomla.JText._('FLEXI_FIELD_MAX_ALLOWED_VALUES_REACHED') + maxValues" . $field->id . ");\n\t\t\t\t\treturn 'cancel';\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\tvar lastField = fieldval_box ? fieldval_box : jQuery(el).prev().children().last();\n\t\t\t\tvar newField  = lastField.clone();\n\t\t\t\t\n\t\t\t\t// Update the new term title\n\t\t\t\tnewField.find('input.termtitle').val('');\n\t\t\t\tnewField.find('input.termtitle').attr('name','" . $fieldname . "['+uniqueRowNum" . $field->id . "+'][title]');\n\t\t\t\tnewField.find('input.termtitle').attr('id','" . $elementid . "_'+uniqueRowNum" . $field->id . "+'_title');\n\t\t\t\t\n\t\t\t\t";
            // NOTE: HTML tag id of this form element needs to match the -for- attribute of label HTML tag of this FLEXIcontent field, so that label will be marked invalid when needed
            $js .= "\n\t\t\t\t// Update the new term description\n\t\t\t\tvar boxClass = 'termtext';\n\t\t\t\tvar container = newField.find('.fc_'+boxClass);\n\t\t\t\tvar hasTinyMCE = typeof tinyMCE === 'undefined' ? false : tinyMCE.get( container.find('textarea').first().attr('id') );\n\t\t\t\tvar hasCodeMirror = typeof CodeMirror === 'undefined' ? false : container.find('textarea').next().hasClass('CodeMirror');\n\t\t\t\t\n\t\t\t\tcontainer.after('<div class=\"nowrap_box fc_'+boxClass+'\" style=\"min-width: 50%;\"></div>');  // Append a new container box\n\t\t\t\tcontainer.find('label.labeltext').show().appendTo(container.next()); // Copy the label\n\t\t\t\tcontainer.find('textarea').first().show().css('visibility', 'visible').appendTo(container.next()); // Copy only the textarea (first make it visible) into the new container\n\t\t\t\tcontainer.remove(); // Remove old (cloned) container box along with all the contents\n\t\t\t\t\n\t\t\t\t// Prepare the new textarea for attaching the HTML editor\n\t\t\t\ttheArea = newField.find('.fc_'+boxClass).find('textarea');\n\t\t\t\ttheArea.val('');\n\t\t\t\ttheArea.attr('name','" . $fieldname . "['+uniqueRowNum" . $field->id . "+'][text]');\n\t\t\t\ttheArea.attr('id','" . $elementid . "_'+uniqueRowNum" . $field->id . "+'_text');\n\t\t\t\ttheArea.removeClass(); // Remove all classes from the textarea\n\t\t\t\t\n\t\t\t\t// Update the labels\n\t\t\t\tnewField.find('label.labeltitle').attr('for', '" . $elementid . "_'+uniqueRowNum" . $field->id . "+'_title');\n\t\t\t\tnewField.find('label.labeltext').attr('for', '" . $elementid . "_'+uniqueRowNum" . $field->id . "+'_text');\n\t\t\t\t";
            // Add new field to DOM
            $js .= "\n\t\t\t\tlastField ?\n\t\t\t\t\t(insert_before ? newField.insertBefore( lastField ) : newField.insertAfter( lastField ) ) :\n\t\t\t\t\tnewField.appendTo( jQuery('#sortables_" . $field->id . "') ) ;\n\t\t\t\tif (remove_previous) lastField.remove();\n\t\t\t\t";
            // Attach a new JS HTML editor object
            if ($use_html) {
                $js .= "\n\t\t\t\tif (hasCodeMirror) {\n\t\t\t\t\tvar CM = CodeMirror.fromTextArea(theArea.get(0),\n\t\t\t\t\t{\n\t\t\t\t\t\tmode: 'application/x-httpd-php',\n\t\t\t\t\t\tindentUnit: 2,\n\t\t\t\t\t\tlineNumbers: true,\n\t\t\t\t\t\tmatchBrackets: true,\n\t\t\t\t\t\tlineWrapping: true,\n\t\t\t\t\t\tonCursorActivity: function() \n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tCM.setLineClass(hlLine, null);\n\t\t\t\t\t\t\thlLine = CM.setLineClass(CM.getCursor().line, 'activeline');\n\t\t\t\t\t\t}\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t\tif (hasTinyMCE)\n\t\t\t\t{\n          if(tinyMCE.majorVersion >= 4) {\n          \t//var ed = new tinymce.Editor('textareaid', { mode : 'exact' }, tinymce.EditorManager);\n\t\t\t\t\t\t//tinyMCE.init({  mode : 'exact',  elements :'" . $elementid . "_'+uniqueRowNum" . $field->id . "+'_text'  });\n          \t//tinyMCE.editors['" . $elementid . "_'+uniqueRowNum" . $field->id . "+'_text'].show();\n\t\t\t\t\t\ttinyMCE.EditorManager.execCommand('mceAddEditor', true, '" . $elementid . "_'+uniqueRowNum" . $field->id . "+'_text');\n          } else {\n          \ttinyMCE.EditorManager.execCommand('mceAddControl', true, '" . $elementid . "_'+uniqueRowNum" . $field->id . "+'_text');\n\t\t\t\t\t\t//tinyMCE.execCommand('mceAddControl', true, '" . $elementid . "_'+uniqueRowNum" . $field->id . "+'_text');\n          }\n          //tinyMCE.EditorManager.execCommand('mceFocus', false, '" . $elementid . "_'+uniqueRowNum" . $field->id . "+'_text');\n\t\t\t\t\ttheArea.addClass('mce_editable').addClass(boxClass);\n\t\t\t\t\tnewField.find('.mce-container').css('display', '');\n\t\t\t\t}\n\t\t\t\t";
            }
            // Add new element to sortable objects (if field not in group)
            if (!$use_ingroup) {
                $js .= "\n\t\t\t\tjQuery('#sortables_" . $field->id . "').sortable({\n\t\t\t\t\thandle: '.fcfield-drag-handle',\n\t\t\t\t\tcontainment: 'parent',\n\t\t\t\t\ttolerance: 'pointer'\n\t\t\t\t});\n\t\t\t\t";
            }
            // Show new field, increment counters
            $js .= "\n\t\t\t\t//newField.fadeOut({ duration: 400, easing: 'swing' }).fadeIn({ duration: 200, easing: 'swing' });\n\t\t\t\tif (scroll_visible) fc_scrollIntoView(newField, 1);\n\t\t\t\tif (animate_visible) newField.css({opacity: 0.1}).animate({ opacity: 1 }, 800);\n\t\t\t\t\n\t\t\t\trowCount" . $field->id . "++;       // incremented / decremented\n\t\t\t\tuniqueRowNum" . $field->id . "++;   // incremented only\n\t\t\t}\n\n\t\t\tfunction deleteField" . $field->id . "(el, groupval_box, fieldval_box)\n\t\t\t{\n\t\t\t\t// Find field value container\n\t\t\t\tvar row = fieldval_box ? fieldval_box : jQuery(el).closest('li');\n\t\t\t\t\n\t\t\t\t// Add empty container if last element, instantly removing the given field value container\n\t\t\t\tif(rowCount" . $field->id . " == 1)\n\t\t\t\t\taddField" . $field->id . "(null, groupval_box, row, {remove_previous: 1, scroll_visible: 0, animate_visible: 0});\n\t\t\t\t\n\t\t\t\t// Remove if not last one, if it is last one, we issued a replace (copy,empty new,delete old) above\n\t\t\t\tif(rowCount" . $field->id . " > 1) {\n\t\t\t\t\t// Destroy the remove/add/etc buttons, so that they are not reclicked, while we do the hide effect (before DOM removal of field value)\n\t\t\t\t\trow.find('.fcfield-delvalue').remove();\n\t\t\t\t\trow.find('.fcfield-insertvalue').remove();\n\t\t\t\t\trow.find('.fcfield-drag-handle').remove();\n\t\t\t\t\t// Do hide effect then remove from DOM\n\t\t\t\t\trow.slideUp(400, function(){\n\t\t\t\t\t\tvar txtareas = jQuery(this).find('textarea');\n\t\t\t\t\t\ttxtareas.each(function( i, txtarea) {\n\t\t\t\t\t\t\tvar areaid = jQuery(txtarea).attr('id');\n\t\t\t\t\t\t\tvar hasTinyMCE = typeof tinyMCE === 'undefined' ? false : tinyMCE.get(areaid);\n\t\t\t\t\t\t\tif (hasTinyMCE) tinymce.EditorManager.execCommand('mceRemoveEditor', false, areaid);\n\t\t\t\t\t\t\tvar hasCodeMirror = typeof CodeMirror === 'undefined' ? false : jQuery(txtarea).first().next().hasClass('CodeMirror');\n\t\t\t\t\t\t\tif (hasCodeMirror) jQuery(txtarea).first().next().get(0).CodeMirror.toTextArea();\n\t\t\t\t\t\t});\n\t\t\t\t\t\tthis.remove();\n\t\t\t\t\t});\n\t\t\t\t\trowCount" . $field->id . "--;\n\t\t\t\t}\n\t\t\t}\n\t\t\t";
            $css .= '';
            $remove_button = '<span class="fcfield-delvalue" title="' . JText::_('FLEXI_REMOVE_VALUE') . '" onclick="deleteField' . $field->id . '(this);"></span>';
            $move2 = '<span class="fcfield-drag-handle" title="' . JText::_('FLEXI_CLICK_TO_DRAG') . '"></span>';
            $add_here = '';
            $add_here .= $add_position == 2 || $add_position == 3 ? '<span class="fcfield-insertvalue fc_before" onclick="addField' . $field->id . '(null, jQuery(this).closest(\'ul\'), jQuery(this).closest(\'li\'), {insert_before: 1});" title="' . JText::_('FLEXI_ADD_BEFORE') . '"></span> ' : '';
            $add_here .= $add_position == 1 || $add_position == 3 ? '<span class="fcfield-insertvalue fc_after"  onclick="addField' . $field->id . '(null, jQuery(this).closest(\'ul\'), jQuery(this).closest(\'li\'), {insert_before: 0});" title="' . JText::_('FLEXI_ADD_AFTER') . '"></span> ' : '';
        } else {
            $remove_button = '';
            $move2 = '';
            $add_here = '';
            $js .= '';
            $css .= '';
        }
        if ($js) {
            $document->addScriptDeclaration($js);
        }
        if ($css) {
            $document->addStyleDeclaration($css);
        }
        // *****************************************
        // Create field's HTML display for item form
        // *****************************************
        $field->html = array();
        $n = 0;
        //if ($use_ingroup) {print_r($field->value);}
        foreach ($field->value as $value) {
            // Compatibility for unserialized values (e.g. reload user input after form validation error) or for NULL values in a field group
            if (!is_array($value)) {
                $v = !empty($value) ? @unserialize($value) : false;
                $value = $v !== false || $v === 'b:0;' ? $v : array('title' => $value, 'text' => '');
            }
            if (empty($value['title']) && !$use_ingroup && $n) {
                continue;
            }
            // If at least one added, skip empty if not in field group
            $fieldname_n = $fieldname . '[' . $n . ']';
            $elementid_n = $elementid . '_' . $n;
            $title = '
				<div class="nowrap_box fc_termtitle">
					<label class="label label-info labeltitle" for="' . $elementid_n . '_title">' . $title_label . '</label>
					<input class="fcfield_textval termtitle ' . $required . '" id="' . $elementid_n . '_title" name="' . $fieldname_n . '[title]" type="text" size="' . $title_size . '" maxlength="' . $title_maxlength . '" value="' . htmlspecialchars(@$value['title'], ENT_COMPAT, 'UTF-8') . '" />
				</div>';
            // NOTE: HTML tag id of this form element needs to match the -for- attribute of label HTML tag of this FLEXIcontent field, so that label will be marked invalid when needed
            //display($name, $html, $width, $height, $col, $row, $buttons = true, $id = null, $asset = null, $author = null, $params = array())
            $text = !$use_html ? '
				<textarea class="fcfield_textval termtext" id="' . $elementid_n . '_text" name="' . $fieldname_n . '[text]" cols="' . $cols . '" rows="' . $rows . '">' . htmlspecialchars($value['text'], ENT_COMPAT, 'UTF-8') . '</textarea>
				' : $editor->display($fieldname_n . '[text]', htmlspecialchars($value['text'], ENT_COMPAT, 'UTF-8'), $width = '100%', $height = '100%', $cols, $rows, $show_buttons, $elementid_n . '_text');
            $text = '
				<div class="nowrap_box fc_termtext" style="min-width: 50%;">
					<label class="label label-info labeltext" for="' . $elementid_n . '_text">' . $value_label . ' ' . '</label>
					' . $text . '
				</div>';
            $field->html[] = '
				' . ($use_ingroup ? '' : $move2) . '
				' . ($use_ingroup ? '' : $remove_button) . '
				' . ($use_ingroup || !$add_position ? '' : $add_here) . '
				' . ($use_ingroup ? '' : '<div class="fcclear"></div>') . '
				' . $title . '
				' . $text . '
				';
            $n++;
            if (!$multiple) {
                break;
            }
            // multiple values disabled, break out of the loop, not adding further values even if the exist
        }
        if ($use_ingroup) {
            // do not convert the array to string if field is in a group
        } else {
            if ($multiple) {
                // handle multiple records
                $field->html = '<li class="' . $value_classes . '">' . implode('</li><li class="' . $value_classes . '">', $field->html) . '</li>';
                $field->html = '<ul class="fcfield-sortables" id="sortables_' . $field->id . '">' . $field->html . '</ul>';
                if (!$add_position) {
                    $field->html .= '<span class="fcfield-addvalue fccleared" onclick="addField' . $field->id . '(this);" title="' . JText::_('FLEXI_ADD_TO_BOTTOM') . '"></span>';
                }
            } else {
                // handle single values
                $field->html = '<div class="fcfieldval_container valuebox fcfieldval_container_' . $field->id . '">' . $field->html[0] . '</div>';
            }
        }
    }
Пример #4
0
    function onDisplayField(&$field, &$item)
    {
        if (!in_array($field->field_type, self::$field_types)) {
            return;
        }
        $field->label = JText::_($field->label);
        $use_ingroup = $field->parameters->get('use_ingroup', 0);
        $ajax = !empty($field->isAjax);
        if ($use_ingroup) {
            $field->formhidden = 3;
        }
        if ($use_ingroup && empty($field->ingroup) && !$ajax) {
            return;
        }
        // initialize framework objects and other variables
        $document = JFactory::getDocument();
        // some parameter shortcuts
        $sql_mode = $field->parameters->get('sql_mode', 0);
        $field_elements = $field->parameters->get('field_elements');
        $cascade_after = (int) $field->parameters->get('cascade_after', 0);
        // ****************
        // Number of values
        // ****************
        $multiple = $use_ingroup || (int) $field->parameters->get('allow_multiple', 0);
        $min_values = $use_ingroup ? 0 : (int) $field->parameters->get('min_values', 0);
        $max_values = $use_ingroup ? 0 : (int) $field->parameters->get('max_values', 0);
        $required = $field->parameters->get('required', 0);
        //$required   = $required ? ' required' : '';
        $add_position = (int) $field->parameters->get('add_position', 3);
        // Sanitize limitations
        $exact_values = $field->parameters->get('exact_values', 0);
        if ($required && !$min_values) {
            $min_values = 1;
        }
        if ($exact_values) {
            $max_values = $min_values = $exact_values;
        }
        $js_popup_err = $field->parameters->get('js_popup_err', 0);
        // **************
        // Value handling
        // **************
        // Default value
        $value_usage = $field->parameters->get('default_value_use', 0);
        $default_values = $item->version == 0 || $value_usage > 0 ? trim($field->parameters->get('default_values', '')) : '';
        // *************************
        // Input field configuration
        // *************************
        // DISPLAY using prettyCheckable JS
        $use_jslib = $field->parameters->get('use_jslib', 2);
        $use_prettycheckable = $use_jslib == 2;
        static $prettycheckable_added = null;
        if ($use_prettycheckable && $prettycheckable_added === null) {
            $prettycheckable_added = flexicontent_html::loadFramework('prettyCheckable');
        }
        // Display text label, use checkbox/radio image field for more
        $form_vals_display = $field->parameters->get('form_vals_display', 1);
        // this field includes image but it can be more convenient/compact not to be display image in item form
        // when field is displayed as drop-down select (item edit form only)
        $firstoptiontext = $field->parameters->get('firstoptiontext', 'FLEXI_SELECT');
        $usefirstoption = $field->parameters->get('usefirstoption', 1);
        $size = $field->parameters->get('size', 6);
        $size = $size ? ' size="' . $size . '"' : '';
        // Prefix - Suffix - Separator (item FORM) parameters, for the checkbox/radio elements
        $pretext = $field->parameters->get('pretext_form', '');
        $posttext = $field->parameters->get('posttext_form', '');
        $separator = $field->parameters->get('separator', 0);
        $opentag = $field->parameters->get('opentag_form', '');
        $closetag = $field->parameters->get('closetag_form', '');
        switch ($separator) {
            case 0:
                $separator = '&nbsp;';
                break;
            case 1:
                $separator = '<br />';
                break;
            case 2:
                $separator = '&nbsp;|&nbsp;';
                break;
            case 3:
                $separator = ',&nbsp;';
                break;
            case 4:
                $separator = $closetag . $opentag;
                break;
            default:
                $separator = '&nbsp;';
                break;
        }
        // Initialise property with default value
        if (!$field->value) {
            $field->value = preg_split("/\\s*,\\s*/u", $default_values);
        }
        // CSS classes of value container
        $value_classes = 'fcfieldval_container valuebox fcfieldval_container_' . $field->id;
        // Field name and HTML TAG id
        $fieldname = 'custom[' . $field->name . ']';
        $elementid = 'custom_' . $field->name;
        $js = "";
        $css = "";
        // *********************************************************************************************
        // Handle adding the needed JS code to CASCADE (listen to) changes of the dependent master field
        // *********************************************************************************************
        if ($cascade_after && !$ajax) {
            $byIds = FlexicontentFields::indexFieldsByIds($item->fields);
            if (isset($byIds[$cascade_after])) {
                $cascade_prompt = $field->parameters->get('cascade_prompt', '');
                $cascade_prompt = $cascade_prompt ? JText::_($cascade_prompt) : JText::_('FLEXI_PLEASE_SELECT') . ': ' . $byIds[$cascade_after]->label;
                $srcELid = 'custom_' . $byIds[$cascade_after]->name;
                $trgELid = $elementid;
                // Get values of cascade (on) source field
                $field->valgrps = $byIds[$cascade_after]->value ? $byIds[$cascade_after]->value : array();
                foreach ($field->valgrps as &$vg) {
                    if (is_array($vg)) {
                    } else {
                        if (@unserialize($vg) !== false || $vg === 'b:0;') {
                            $vg = unserialize($vg);
                        } else {
                            $vg = array($vg);
                        }
                    }
                }
                unset($vg);
            } else {
                $cascade_after = 0;
                echo 'Error in field ' . $field->label . ' [' . $field->id . ']' . ' cannot cascaded after field no: ' . $cascade_after . ', field was not found <br/>';
            }
        } else {
            if ($cascade_after && $ajax) {
                $field->valgrps = isset($field->valgrps) ? $field->valgrps : array();
                $field->valgrps = is_array($field->valgrps) ? $field->valgrps : preg_split("/\\s*,\\s*/u", trim($field->valgrps));
            }
        }
        // ***********************
        // Handle multiple records
        // ***********************
        if ($multiple && !$ajax) {
            // Add the drag and drop sorting feature
            if (!$use_ingroup) {
                $js .= "\n\t\t\tjQuery(document).ready(function(){\n\t\t\t\tjQuery('#sortables_" . $field->id . "').sortable({\n\t\t\t\t\thandle: '.fcfield-drag-handle',\n\t\t\t\t\tcontainment: 'parent',\n\t\t\t\t\ttolerance: 'pointer'\n\t\t\t\t});\n\t\t\t});\n\t\t\t";
            }
            if ($max_values) {
                FLEXI_J16GE ? JText::script("FLEXI_FIELD_MAX_ALLOWED_VALUES_REACHED", true) : fcjsJText::script("FLEXI_FIELD_MAX_ALLOWED_VALUES_REACHED", true);
            }
            $js .= "\n\t\t\tvar uniqueRowNum" . $field->id . "\t= " . count($field->value) . ";  // Unique row number incremented only\n\t\t\tvar rowCount" . $field->id . "\t= " . count($field->value) . ";      // Counts existing rows to be able to limit a max number of values\n\t\t\tvar maxValues" . $field->id . " = " . $max_values . ";\n\t\t\t\n\t\t\tfunction addField" . $field->id . "(el, groupval_box, fieldval_box, params)\n\t\t\t{\n\t\t\t\tvar insert_before   = (typeof params!== 'undefined' && typeof params.insert_before   !== 'undefined') ? params.insert_before   : 0;\n\t\t\t\tvar remove_previous = (typeof params!== 'undefined' && typeof params.remove_previous !== 'undefined') ? params.remove_previous : 0;\n\t\t\t\tvar scroll_visible  = (typeof params!== 'undefined' && typeof params.scroll_visible  !== 'undefined') ? params.scroll_visible  : 1;\n\t\t\t\tvar animate_visible = (typeof params!== 'undefined' && typeof params.animate_visible !== 'undefined') ? params.animate_visible : 1;\n\t\t\t\t\n\t\t\t\tif((rowCount" . $field->id . " >= maxValues" . $field->id . ") && (maxValues" . $field->id . " != 0)) {\n\t\t\t\t\talert(Joomla.JText._('FLEXI_FIELD_MAX_ALLOWED_VALUES_REACHED') + maxValues" . $field->id . ");\n\t\t\t\t\treturn 'cancel';\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\t// Find last container of fields and clone it to create a new container of fields\n\t\t\t\tvar lastField = fieldval_box ? fieldval_box : jQuery(el).prev().children().last();\n\t\t\t\tvar newField  = lastField.clone();\n\t\t\t\t\n\t\t\t\t// Remove HTML added by prettyCheckable JS, from the dupicate new INPUT SET\n\t\t\t\tvar prettyContainers = newField.find('.prettyradio, .prettycheckbox');\n\t\t\t\tprettyContainers.find('input, label').each(function() {\n\t\t\t\t\tvar el = jQuery(this);\n\t\t\t\t\tel.insertAfter(el.parent());\n\t\t\t\t});\n\t\t\t\tprettyContainers.remove();\n\t\t\t\t\n\t\t\t\t\n\t\t\t\t// Update INPUT SET container id\n\t\t\t\tnewField.find('.fc_input_set').attr('id', '" . $elementid . "_'+uniqueRowNum" . $field->id . ");\n\t\t\t\tvar js_class = '" . ($use_prettycheckable && $prettycheckable_added ? ' use_prettycheckable' : '') . "';\n\t\t\t\t\n\t\t\t\t// Update the new INPUT SET\n\t\t\t\tvar theSet = newField.find('input:radio, input:checkbox');\n\t\t\t\t//if(window.console) window.console.log('theSet.length: ' + theSet.length);\n\t\t\t\tvar nr = 0;\n\t\t\t\ttheSet.each(function() {\n\t\t\t\t\tvar elem = jQuery(this);\n\t\t\t\t\telem.attr('name', '" . $fieldname . "['+uniqueRowNum" . $field->id . "+']" . (self::$valueIsArr ? '[]' : '') . "');\n\t\t\t\t\telem.attr('id', '" . $elementid . "_'+uniqueRowNum" . $field->id . "+'_'+nr);\n\t\t\t\t\telem.attr('class', '" . $elementid . "_'+uniqueRowNum" . $field->id . " + js_class);\n\t\t\t\t\t" . ($use_prettycheckable && $prettycheckable_added ? "elem.attr('data-element-grpid', '" . $elementid . "_'+uniqueRowNum" . $field->id . ");" : "elem.attr('data-element-grpid', '" . $elementid . "_'+uniqueRowNum" . $field->id . ");") . "\n\t\t\t\t\t" . ($use_prettycheckable && $prettycheckable_added ? "elem.prev('label').attr('for', '" . $elementid . "_'+uniqueRowNum" . $field->id . "+'_'+nr);" : "elem.next('label').attr('for', '" . $elementid . "_'+uniqueRowNum" . $field->id . "+'_'+nr);") . "\n\t\t\t\t\tnr++;\n\t\t\t\t});\n\t\t\t\t\n\t\t\t\t// Reapply prettyCheckable JS \n\t\t\t\tnewField.find('.use_prettycheckable').each(function() {\n\t\t\t\t\tvar elem = jQuery(this);\n\t\t\t\t\tvar lbl = elem.prev('label');\n\t\t\t\t\tvar lbl_html = lbl.html();\n\t\t\t\t\tlbl.remove();\n\t\t\t\t\telem.prettyCheckable({ label: lbl_html });\n\t\t\t\t});\n\t\t\t\t";
            // Add new field to DOM
            $js .= "\n\t\t\t\tlastField ?\n\t\t\t\t\t(insert_before ? newField.insertBefore( lastField ) : newField.insertAfter( lastField ) ) :\n\t\t\t\t\tnewField.appendTo( jQuery('#sortables_" . $field->id . "') ) ;\n\t\t\t\tif (remove_previous) lastField.remove();\n\t\t\t\t";
            // Listen to the changes of cascade-after field
            if ($cascade_after) {
                $js .= "\n\t\t\t\tfc_cascade_field_funcs['" . $srcELid . "_'+uniqueRowNum" . $field->id . "] = function(rowNo){\n\t\t\t\t\treturn function () {\n\t\t\t\t\t\tfcCascadedField(" . $field->id . ", '" . $item->id . "', '" . $field->field_type . "', 'select#" . $srcELid . "_'+rowNo+', input." . $srcELid . "_'+rowNo, '" . $trgELid . "_'+rowNo, '" . $cascade_prompt . "', " . self::$promptEnabled . ", rowNo);\n\t\t\t\t\t}\n\t\t\t\t}(uniqueRowNum" . $field->id . ");\n\t\t\t\tfc_cascade_field_funcs['" . $srcELid . "_'+uniqueRowNum" . $field->id . "]();\n\t\t\t\t";
            }
            // Add new element to sortable objects (if field not in group)
            if (!$use_ingroup) {
                $js .= "\n\t\t\t\tjQuery('#sortables_" . $field->id . "').sortable({\n\t\t\t\t\thandle: '.fcfield-drag-handle',\n\t\t\t\t\tcontainment: 'parent',\n\t\t\t\t\ttolerance: 'pointer'\n\t\t\t\t});\n\t\t\t\t";
            }
            // Show new field, increment counters
            $js .= "\n\t\t\t\t//newField.fadeOut({ duration: 400, easing: 'swing' }).fadeIn({ duration: 200, easing: 'swing' });\n\t\t\t\tif (scroll_visible) fc_scrollIntoView(newField, 1);\n\t\t\t\tif (animate_visible) newField.css({opacity: 0.1}).animate({ opacity: 1 }, 800);\n\t\t\t\t\n\t\t\t\trowCount" . $field->id . "++;       // incremented / decremented\n\t\t\t\tuniqueRowNum" . $field->id . "++;   // incremented only\n\t\t\t}\n\n\t\t\tfunction deleteField" . $field->id . "(el, groupval_box, fieldval_box)\n\t\t\t{\n\t\t\t\t// Find field value container\n\t\t\t\tvar row = fieldval_box ? fieldval_box : jQuery(el).closest('li');\n\t\t\t\t\n\t\t\t\t// Add empty container if last element, instantly removing the given field value container\n\t\t\t\tif(rowCount" . $field->id . " == 1)\n\t\t\t\t\taddField" . $field->id . "(null, groupval_box, row, {remove_previous: 1, scroll_visible: 0, animate_visible: 0});\n\t\t\t\t\n\t\t\t\t// Remove if not last one, if it is last one, we issued a replace (copy,empty new,delete old) above\n\t\t\t\tif(rowCount" . $field->id . " > 1) {\n\t\t\t\t\t// Destroy the remove/add/etc buttons, so that they are not reclicked, while we do the hide effect (before DOM removal of field value)\n\t\t\t\t\trow.find('.fcfield-delvalue').remove();\n\t\t\t\t\trow.find('.fcfield-insertvalue').remove();\n\t\t\t\t\trow.find('.fcfield-drag-handle').remove();\n\t\t\t\t\t// Do hide effect then remove from DOM\n\t\t\t\t\trow.slideUp(400, function(){ this.remove(); });\n\t\t\t\t\trowCount" . $field->id . "--;\n\t\t\t\t}\n\t\t\t}\n\t\t\t";
            $css .= '';
            $remove_button = '<span class="fcfield-delvalue" title="' . JText::_('FLEXI_REMOVE_VALUE') . '" onclick="deleteField' . $field->id . '(this);"></span>';
            $move2 = '<span class="fcfield-drag-handle" title="' . JText::_('FLEXI_CLICK_TO_DRAG') . '"></span>';
            $add_here = '';
            $add_here .= $add_position == 2 || $add_position == 3 ? '<span class="fcfield-insertvalue fc_before" onclick="addField' . $field->id . '(null, jQuery(this).closest(\'ul\'), jQuery(this).closest(\'li\'), {insert_before: 1});" title="' . JText::_('FLEXI_ADD_BEFORE') . '"></span> ' : '';
            $add_here .= $add_position == 1 || $add_position == 3 ? '<span class="fcfield-insertvalue fc_after"  onclick="addField' . $field->id . '(null, jQuery(this).closest(\'ul\'), jQuery(this).closest(\'li\'), {insert_before: 0});" title="' . JText::_('FLEXI_ADD_AFTER') . '"></span> ' : '';
        } else {
            $remove_button = '';
            $move2 = '';
            $add_here = '';
            $js .= '';
            $css .= '';
        }
        // Added field's custom CSS / JS
        if (!$ajax && $js) {
            $document->addScriptDeclaration($js);
        }
        if (!$ajax && $css) {
            $document->addStyleDeclaration($css);
        }
        // **************************
        // Get indexed element values
        // **************************
        // If cascading we will get it inside the value loop for every value, thus supporting field grouping properly
        $elements = !$cascade_after ? $this->getLimitedProps($field, $item) : array();
        if (!is_array($elements)) {
            $field->html = $elements;
            return;
        }
        // *****************************************
        // Create field's HTML display for item form
        // *****************************************
        // Alternative form field display as drop-down select to save space
        if ($field->parameters->get('display_as_select', 0)) {
            $options = array();
            if ($usefirstoption) {
                $options[] = JHTML::_('select.option', '', JText::_($firstoptiontext));
            }
            foreach ($elements as $element) {
                $options[] = JHTML::_('select.option', $element->value, $element->text);
            }
            $field->html = JHTML::_('select.genericlist', $options, $fieldname, 'multiple="multiple" class="' . $required . '"' . $size, 'value', 'text', $field->value, $elementid);
            return;
        }
        // Create the attributes of the form field
        $fftype = 'checkbox';
        $display_as_checkbox = 1;
        if ($display_as_checkbox) {
            $classes = $use_prettycheckable && $prettycheckable_added ? ' use_prettycheckable ' : '';
            //$classes .= $required;
            $onchange = '';
            // Extra properties
            $attribs = '';
            if ($exact_values) {
                $attribs .= ' data-exact_values="' . $exact_values . '" ';
            } else {
                if ($max_values) {
                    $attribs .= ' data-max_values="' . $max_values . '" ';
                }
                if ($min_values) {
                    $attribs .= ' data-min_values="' . $min_values . '" ';
                }
            }
            if ($js_popup_err) {
                $attribs .= ' data-js_popup_err="' . $js_popup_err . '" ';
            }
            if ($max_values || $min_values || $exact_values) {
                $classes .= ' validate-cboxlimitations ';
            } else {
                if ($required) {
                    $classes .= ' validate-checkbox ';
                }
            }
            // No min/max/exact values allow basic 'required' validation
            if ($onchange) {
                $attribs .= ' onchange="' . $onchange . '" ';
            }
        }
        $label_class = 'fccheckradio_lbl' . (FLEXI_J30GE ? ' hasTooltip' : ' hasTip');
        $label_style = 'vertical-align: unset!important;';
        // Handle case of FORM fields that each value is an array of values
        // (e.g. selectmultiple, checkbox), and that multi-value input is also enabled
        $is_array_already = is_array($field->value) ? is_array(reset($field->value)) : false;
        $values = self::$valueIsArr && !$multiple && !$is_array_already ? array($field->value) : $field->value;
        // *****************************************
        // Create field's HTML display for item form
        // *****************************************
        $field->html = array();
        $n = $ajax ? $field->valindex : 0;
        $js = "";
        foreach ($values as $value) {
            // Compatibility for serialized values
            if (self::$valueIsArr) {
                if (is_array($value)) {
                } else {
                    if (@unserialize($value) !== false || $value === 'b:0;') {
                        $value = unserialize($value);
                    }
                }
            }
            // Make sure value is an array
            if (!is_array($value)) {
                $value = strlen($value) ? array($value) : array();
            }
            // Skip empty if not in field group, and at least one value was added
            if (!count($value) && !$use_ingroup && $n) {
                continue;
            }
            // Get options according to cascading, this is here so that it works with field grouping too
            if ($cascade_after) {
                $elements = $this->getLimitedProps($field, $item, !$ajax ? $cascade_prompt : null, $ajax, $n);
            }
            if (1) {
                $fieldname_n = $fieldname . '[' . $n . ']' . (self::$valueIsArr ? '[]' : '');
                $elementid_n = $elementid . '_' . $n;
                // Create form field options
                $i = 0;
                $options = array();
                foreach ($elements as $element) {
                    if (!empty($element->isprompt)) {
                        $options[] = '<span style="float: left;" class="' . $element->isprompt . '">' . $element->text . '</span>';
                        continue;
                    }
                    $checked = in_array($element->value, $value) ? ' checked="checked"' : '';
                    $elementid_no = $elementid_n . '_' . $i;
                    //echo " &nbsp; &nbsp; $elementid_n , $elementid_no , $fieldname_n  , &nbsp; value: {$element->value} <br/>\n";
                    $input_attribs = $use_prettycheckable && $prettycheckable_added ? ' data-customClass="fcradiocheckimage"' : '';
                    $input_attribs .= ' class="' . @$classes . ' ' . $elementid_n . '" ';
                    $input_fld = ' <input type="' . $fftype . '" id="' . $elementid_no . '" data-element-grpid="' . $elementid_n . '" name="' . $fieldname_n . '" ' . $attribs . $input_attribs . ' value="' . $element->value . '" ' . $checked . ' />';
                    $options[] = '' . $pretext . ($use_prettycheckable && $prettycheckable_added ? $input_fld : '') . '<label for="' . $elementid_no . '" class="' . $label_class . '" style="' . $label_style . '" title="' . $element->label_tip . '">' . (!$use_prettycheckable || !$prettycheckable_added ? $input_fld : '') . ($form_vals_display != 1 ? $element->text : '') . ($form_vals_display == 2 ? ' <br/>' : '') . ($form_vals_display > 0 ? $element->image_html : '') . '</label>' . $posttext;
                    $i++;
                }
                // Apply (item form) separator and open/close tags to create the radio field
                $form_field = $opentag . implode($separator, $options) . $closetag;
            }
            if (!$ajax) {
                $field->html[] = '
					' . '<div id="' . $elementid_n . '" class="fc_input_set">' . $form_field . '</div>' . ($cascade_after ? '<span class="field_cascade_loading"></span>' : '') . '
					' . ($use_ingroup ? '' : $move2) . '
					' . ($use_ingroup ? '' : $remove_button) . '
					' . ($use_ingroup || !$add_position ? '' : $add_here) . '
					';
                // Listen to the changes of cascade-after field
                if ($cascade_after && !$ajax) {
                    $js .= "\n\t\t\t\tjQuery(document).ready(function(){\n\t\t\t\t\tfc_cascade_field_funcs['" . $srcELid . '_' . $n . "'] = function(){\n\t\t\t\t\t\tfcCascadedField(" . $field->id . ", '" . $item->id . "', '" . $field->field_type . "', 'select#" . $srcELid . '_' . $n . ", input." . $srcELid . '_' . $n . "', '" . $trgELid . '_' . $n . "', '" . $cascade_prompt . "', " . self::$promptEnabled . ", " . $n . ");\n\t\t\t\t\t}\n\t\t\t\t\tfc_cascade_field_funcs['" . $srcELid . '_' . $n . "']();\n\t\t\t\t});\n\t\t\t\t";
                }
            } else {
                $field->html = $form_field;
            }
            $n++;
            if (!$multiple) {
                break;
            }
            // multiple values disabled, break out of the loop, not adding further values even if the exist
        }
        if ($js) {
            $document->addScriptDeclaration($js);
        }
        if ($ajax) {
            return;
            // Done
        } else {
            if ($use_ingroup) {
                // do not convert the array to string if field is in a group
            } else {
                if ($multiple) {
                    // handle multiple records
                    $field->html = '<li class="' . $value_classes . '">' . implode('</li><li class="' . $value_classes . '">', $field->html) . '</li>';
                    $field->html = '<ul class="fcfield-sortables" id="sortables_' . $field->id . '">' . $field->html . '</ul>';
                    if (!$add_position) {
                        $field->html .= '<span class="fcfield-addvalue" onclick="addField' . $field->id . '(this);" title="' . JText::_('FLEXI_ADD_TO_BOTTOM') . '"></span>';
                    }
                } else {
                    // handle single values
                    $field->html = '<div class="fcfieldval_container valuebox fcfieldval_container_' . $field->id . '">' . $field->html[0] . '</div>';
                }
            }
        }
        // Add message box about allowed # values
        if ($exact_values) {
            $field->html = '<div class="alert alert-info fc-small fc-iblock">' . JText::sprintf('FLEXI_FIELD_NUM_VALUES_EXACTLY', $exact_values) . '</div><div class="clear"></div>' . $field->html;
        } else {
            if ($max_values || $min_values > 1) {
                $field->html = '<div class="alert alert-info fc-small fc-iblock">' . JText::sprintf('FLEXI_FIELD_NUM_VALUES_BETWEEN', $min_values, $max_values) . '</div><div class="clear"></div>' . $field->html;
            }
        }
    }
Пример #5
0
    function onDisplayField(&$field, &$item)
    {
        // execute the code only if the field type match the plugin type
        if (!in_array($field->field_type, self::$field_types)) {
            return;
        }
        $field->label = JText::_($field->label);
        $date_source = $field->parameters->get('date_source', 0);
        if ($date_source) {
            $date_source_str = 'Automatic field (shows this content \'s %s publication date)';
            $date_source_str = sprintf($date_source_str, $date_source == 1 ? '<b>start</b>' : '<b>end</b>');
            $_value = $date_source == 1 ? $item->publish_up : $item->publish_down;
            $field->html = '<div style="float:left">' . ' <div class="fc_mini_note_box">' . $date_source_str . '</div>' . $_value . '</div>';
            return;
        }
        // initialize framework objects and other variables
        $document = JFactory::getDocument();
        $config = JFactory::getConfig();
        $app = JFactory::getApplication();
        $user = JFactory::getUser();
        // some parameter shortcuts
        $size = (int) $field->parameters->get('size', 30);
        $multiple = $field->parameters->get('allow_multiple', 1);
        $max_values = (int) $field->parameters->get('max_values', 0);
        $disable_keyboardinput = $field->parameters->get('disable_keyboardinput', 0);
        $required = $field->parameters->get('required', 0);
        $required = $required ? ' required' : '';
        // find timezone and create user instructions, both according to given configuration
        $show_usage = $field->parameters->get('show_usage', 0);
        $date_allowtime = $field->parameters->get('date_allowtime', 1);
        $use_editor_tz = $field->parameters->get('use_editor_tz', 0);
        $use_editor_tz = $date_allowtime ? $use_editor_tz : 0;
        $timezone = false;
        $append_str = '';
        if ($date_allowtime) {
            $append_str = JText::_('FLEXI_DATE_CAN_ENTER_TIME');
            $append_str .= $date_allowtime == 2 ? '<br/>' . JText::_('FLEXI_DATE_USE_ZERO_TIME_ON_EMPTY') : '';
            if ($use_editor_tz == 0) {
                // Raw date storing, ignoring timezone. NOTE: this is OLD BEHAVIOUR
                $timezone = FLEXI_J16GE ? 'UTC' : 0;
                $append_str .= '<br/>' . JText::_('FLEXI_DATE_TIMEZONE_USAGE_DISABLED');
            } else {
                $append_str .= '<br/>' . JText::_('FLEXI_DATE_TIMEZONE_USAGE_ENABLED');
                // Use timezone of editor, unlogged editor will use site's default timezone
                $timezone = $user->getParam('timezone', $config->get('offset'));
                if (FLEXI_J16GE) {
                    $tz = new DateTimeZone($timezone);
                    $tz_offset = $tz->getOffset(new JDate()) / 3600;
                } else {
                    $tz_offset = $timezone;
                }
                $tz_info = $tz_offset > 0 ? ' UTC +' . $tz_offset : ' UTC ' . $tz_offset;
                $append_str .= '<br/>' . JText::_($user->id ? 'FLEXI_DATE_ENTER_HOURS_IN_YOUR_TIMEZONE' : 'FLEXI_DATE_ENTER_HOURS_IN_TIMEZONE') . ': ' . $tz_info;
            }
        }
        $append_str = $append_str ? '<b>' . JText::_('FLEXI_NOTES') . '</b>: ' . $append_str : '';
        // Initialise property with default value
        if (!$field->value) {
            $field->value = array();
            $field->value[0] = '';
        }
        // Field name and HTML TAG id
        $fieldname = FLEXI_J16GE ? 'custom[' . $field->name . '][]' : $field->name . '[]';
        $elementid = FLEXI_J16GE ? 'custom_' . $field->name : $field->name;
        $js = "";
        if ($multiple) {
            if (!FLEXI_J16GE) {
                $document->addScript(JURI::root(true) . '/components/com_flexicontent/assets/js/sortables.js');
            }
            // Add the drag and drop sorting feature
            $js .= "\r\n\t\t\tjQuery(document).ready(function(){\r\n\t\t\t\tjQuery('#sortables_" . $field->id . "').sortable({\r\n\t\t\t\t\thandle: '.fcfield-drag',\r\n\t\t\t\t\tcontainment: 'parent',\r\n\t\t\t\t\ttolerance: 'pointer'\r\n\t\t\t\t});\r\n\t\t\t});\r\n\t\t\t";
            if ($max_values) {
                FLEXI_J16GE ? JText::script("FLEXI_FIELD_MAX_ALLOWED_VALUES_REACHED", true) : fcjsJText::script("FLEXI_FIELD_MAX_ALLOWED_VALUES_REACHED", true);
            }
            $js .= "\r\n\t\t\tvar uniqueRowNum" . $field->id . "\t= " . count($field->value) . ";  // Unique row number incremented only\r\n\t\t\tvar rowCount" . $field->id . "\t= " . count($field->value) . ";      // Counts existing rows to be able to limit a max number of values\r\n\t\t\tvar maxValues" . $field->id . " = " . $max_values . ";\r\n\r\n\t\t\tfunction addField" . $field->id . "(el) {\r\n\t\t\t\tif((rowCount" . $field->id . " >= maxValues" . $field->id . ") && (maxValues" . $field->id . " != 0)) {\r\n\t\t\t\t\talert(Joomla.JText._('FLEXI_FIELD_MAX_ALLOWED_VALUES_REACHED') + maxValues" . $field->id . ");\r\n\t\t\t\t\treturn 'cancel';\r\n\t\t\t\t}\r\n\t\t\t\t\r\n\t\t\t\tvar thisField \t = jQuery(el).prev().children().last();\r\n\t\t\t\tvar thisNewField = thisField.clone();\r\n\t\t\t\t\r\n\t\t\t\tjQuery(thisNewField).find('input').first().val('');  /* First element is the value input field, second is e.g remove button */\r\n\t\t\t\t\r\n\t\t\t\tjQuery(thisNewField).css('display', 'none');\r\n\t\t\t\tjQuery(thisNewField).insertAfter( jQuery(thisField) );\r\n\r\n\t\t\t\tvar input = jQuery(thisNewField).find('input').first();\r\n\t\t\t\tinput.attr('id', '" . $elementid . "_'+uniqueRowNum" . $field->id . ");\r\n\t\t\t\tvar img = input.next();\r\n\t\t\t\timg.attr('id', '" . $elementid . "_' +uniqueRowNum" . $field->id . " +'_img');\r\n\t\t\t\t\r\n\t\t\t\tCalendar.setup({\r\n\t\t\t\t\tinputField:\tinput.attr('id'),\r\n\t\t\t\t\tifFormat:\t\t'%Y-%m-%d',\r\n\t\t\t\t\tbutton:\t\t\timg.attr('id'),\r\n\t\t\t\t\talign:\t\t\t'Tl',\r\n\t\t\t\t\tsingleClick:\ttrue\r\n\t\t\t\t});\r\n\t\t\t";
            if ($disable_keyboardinput) {
                $js .= "\r\n\t\t\t\t\tjQuery('#'+input.attr('id')).on('keydown keypress keyup', false);\r\n\t\t\t\t";
            }
            $js .= "\r\n\t\t\t\tjQuery('#sortables_" . $field->id . "').sortable({\r\n\t\t\t\t\thandle: '.fcfield-drag',\r\n\t\t\t\t\tcontainment: 'parent',\r\n\t\t\t\t\ttolerance: 'pointer'\r\n\t\t\t\t});\r\n\t\t\t\t\r\n\t\t\t\tjQuery(thisNewField).show('slideDown');\r\n\t\t\t\t\r\n\t\t\t\trowCount" . $field->id . "++;       // incremented / decremented\r\n\t\t\t\tuniqueRowNum" . $field->id . "++;   // incremented only\r\n\t\t\t}\r\n\r\n\t\t\tfunction deleteField" . $field->id . "(el)\r\n\t\t\t{\r\n\t\t\t\tif(rowCount" . $field->id . " <= 1) return;\r\n\t\t\t\tvar row = jQuery(el).closest('li');\r\n\t\t\t\tjQuery(row).hide('slideUp', function() { this.remove(); } );\r\n\t\t\t\trowCount" . $field->id . "--;\r\n\t\t\t}\r\n\t\t\t";
            $css = '
			#sortables_' . $field->id . ' { float:left; margin: 0px; padding: 0px; list-style: none; white-space: nowrap; }
			#sortables_' . $field->id . ' li {
				clear: both;
				display: block;
				list-style: none;
				height: auto;
				position: relative;
			}
			#sortables_' . $field->id . ' li.sortabledisabled {
				background : transparent url(components/com_flexicontent/assets/images/move3.png) no-repeat 0px 1px;
			}
			#sortables_' . $field->id . ' li input { cursor: text;}
			#add' . $field->name . ' { margin-top: 5px; clear: both; display:block; }
			#sortables_' . $field->id . ' li .admintable { text-align: left; }
			#sortables_' . $field->id . ' li:only-child span.fcfield-drag, #sortables_' . $field->id . ' li:only-child input.fcfield-button { display:none; }
			';
            $remove_button = '<input class="fcfield-button" type="button" value="' . JText::_('FLEXI_REMOVE_VALUE') . '" onclick="deleteField' . $field->id . '(this);" />';
            $move2 = '<span class="fcfield-drag">' . JHTML::image(JURI::base() . 'components/com_flexicontent/assets/images/move2.png', JText::_('FLEXI_CLICK_TO_DRAG')) . '</span>';
        } else {
            $remove_button = '';
            $move2 = '';
            $js = '';
            $css = '';
        }
        if ($js) {
            $document->addScriptDeclaration($js);
        }
        if ($css) {
            $document->addStyleDeclaration($css);
        }
        $field->html = array();
        $n = 0;
        $skipped_vals = array();
        foreach ($field->value as $value) {
            $elementid_n = $elementid . '_' . $n;
            $calendar = FlexicontentFields::createCalendarField($value, $date_allowtime, $fieldname, $elementid_n, $attribs_arr = array('class' => 'fcfield_textval' . $required), $skip_on_invalid = true, $timezone);
            if (!$calendar) {
                $skipped_vals[] = $value;
                continue;
            }
            $field->html[] = '
				' . $calendar . '
				' . $move2 . '
				' . $remove_button . '
				';
            if ($disable_keyboardinput) {
                $document->addScriptDeclaration("\r\n\t\t\t\t\tjQuery(document).ready(function(){\r\n\t\t\t\t\t\tjQuery('#" . $elementid_n . "').on('keydown keypress keyup', false);\r\n\t\t\t\t\t});\r\n\t\t\t\t");
            }
            $n++;
            if (!$multiple) {
                break;
            }
            // multiple values disabled, break out of the loop, not adding further values even if the exist
        }
        if ($multiple) {
            // handle multiple records
            $_list = "<li>" . implode("</li>\n<li>", $field->html) . "</li>\n";
            $field->html = '
				<ul class="fcfield-sortables" id="sortables_' . $field->id . '">' . $_list . '</ul>
				<input type="button" class="fcfield-addvalue" onclick="addField' . $field->id . '(this);" value="' . JText::_('FLEXI_ADD_VALUE') . '" />
			';
        } else {
            // handle single values
            $field->html = '<div>' . $field->html[0] . '</div>';
        }
        $field->html = '<div style="float:left">' . ($show_usage && $append_str ? ' <div class="fc_mini_note_box">' . $append_str . '</div>' : '') . $field->html . '</div>';
        if (count($skipped_vals)) {
            $app->enqueueMessage(JText::sprintf('FLEXI_FIELD_EDIT_VALUES_SKIPPED', $field->label, implode(',', $skipped_vals)), 'notice');
        }
    }
Пример #6
0
    function onDisplayField(&$field, &$item)
    {
        // execute the code only if the field type match the plugin type
        if (!in_array($field->field_type, self::$field_types)) {
            return;
        }
        $field->label = JText::_($field->label);
        // initialize framework objects and other variables
        $document = JFactory::getDocument();
        // some parameter shortcuts
        $size = (int) $field->parameters->get('size', 30);
        $multiple = $field->parameters->get('allow_multiple', 1);
        $max_values = (int) $field->parameters->get('max_values', 0);
        $required = $field->parameters->get('required', 0);
        $required = $required ? ' required' : '';
        // This is field 's MAIN value property
        $link_usage = $field->parameters->get('default_link_usage', 0);
        $default_link = $item->version == 0 || $link_usage > 0 ? $field->parameters->get('default_link', '') : '';
        $allow_relative_addrs = $field->parameters->get('allow_relative_addrs', 0);
        // Optional value properties
        $title_usage = $field->parameters->get('title_usage', 0);
        $default_title = $item->version == 0 || $title_usage > 0 ? JText::_($field->parameters->get('default_title', '')) : '';
        $usetitle = $field->parameters->get('use_title', 0);
        $text_usage = $field->parameters->get('text_usage', 0);
        $default_text = $item->version == 0 || $text_usage > 0 ? $field->parameters->get('default_text', '') : '';
        $usetext = $field->parameters->get('use_text', 0);
        $class_usage = $field->parameters->get('class_usage', 0);
        $default_class = $item->version == 0 || $class_usage > 0 ? $field->parameters->get('default_class', '') : '';
        $useclass = $field->parameters->get('use_class', 0);
        $id_usage = $field->parameters->get('id_usage', 0);
        $default_id = $item->version == 0 || $id_usage > 0 ? $field->parameters->get('default_id', '') : '';
        $useid = $field->parameters->get('use_id', 0);
        $class_choices = $field->parameters->get('class_choices', '');
        // Initialise property with default value
        if (!$field->value) {
            $field->value = array();
            $field->value[0]['link'] = JText::_($default_link);
            $field->value[0]['title'] = JText::_($default_title);
            $field->value[0]['text'] = JText::_($default_text);
            $field->value[0]['class'] = JText::_($default_class);
            $field->value[0]['id'] = JText::_($default_id);
            $field->value[0]['hits'] = 0;
            $field->value[0] = serialize($field->value[0]);
        }
        // Field name and HTML TAG id
        $fieldname = FLEXI_J16GE ? 'custom[' . $field->name . ']' : $field->name;
        $elementid = FLEXI_J16GE ? 'custom_' . $field->name : $field->name;
        $js = "";
        if ($multiple) {
            if (!FLEXI_J16GE) {
                $document->addScript(JURI::root(true) . '/components/com_flexicontent/assets/js/sortables.js');
            }
            // Add the drag and drop sorting feature
            $js .= "\n\t\t\tjQuery(document).ready(function(){\n\t\t\t\tjQuery('#sortables_" . $field->id . "').sortable({\n\t\t\t\t\thandle: '.fcfield-drag',\n\t\t\t\t\tcontainment: 'parent',\n\t\t\t\t\ttolerance: 'pointer'\n\t\t\t\t});\n\t\t\t});\n\t\t\t";
            if ($max_values) {
                FLEXI_J16GE ? JText::script("FLEXI_FIELD_MAX_ALLOWED_VALUES_REACHED", true) : fcjsJText::script("FLEXI_FIELD_MAX_ALLOWED_VALUES_REACHED", true);
            }
            $js .= "\n\t\t\tvar uniqueRowNum" . $field->id . "\t= " . count($field->value) . ";  // Unique row number incremented only\n\t\t\tvar rowCount" . $field->id . "\t= " . count($field->value) . ";      // Counts existing rows to be able to limit a max number of values\n\t\t\tvar maxValues" . $field->id . " = " . $max_values . ";\n\n\t\t\tfunction addField" . $field->id . "(el) {\n\t\t\t\tif((rowCount" . $field->id . " >= maxValues" . $field->id . ") && (maxValues" . $field->id . " != 0)) {\n\t\t\t\t\talert(Joomla.JText._('FLEXI_FIELD_MAX_ALLOWED_VALUES_REACHED') + maxValues" . $field->id . ");\n\t\t\t\t\treturn 'cancel';\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\tvar thisField \t = jQuery(el).prev().children().last();\n\t\t\t\tvar thisNewField = thisField.clone();\n\t\t\t\t\n\t\t\t\tjQuery(thisNewField).find('input.urllink').attr('value','" . $default_link . "');\n\t\t\t\tjQuery(thisNewField).find('input.urllink').attr('name','" . $fieldname . "['+uniqueRowNum" . $field->id . "+'][link]');\n\t\t\t\tjQuery(thisNewField).find('input.urllink').attr('id','" . $elementid . "_'+uniqueRowNum" . $field->id . ");\n\t\t\t\t";
            if ($usetitle) {
                $js .= "\n\t\t\t\tjQuery(thisNewField).find('input.urltitle').attr('value','" . $default_title . "');\n\t\t\t\tjQuery(thisNewField).find('input.urltitle').attr('name','" . $fieldname . "['+uniqueRowNum" . $field->id . "+'][title]');\n\t\t\t\t";
            }
            if ($usetext) {
                $js .= "\n\t\t\t\tjQuery(thisNewField).find('input.urllinktext').attr('value','" . $default_text . "');\n\t\t\t\tjQuery(thisNewField).find('input.urllinktext').attr('name','" . $fieldname . "['+uniqueRowNum" . $field->id . "+'][linktext]');\n\t\t\t\t";
            }
            if ($useclass) {
                $js .= "\n\t\t\t\tjQuery(thisNewField).find('.urlclass').attr('value','" . $default_class . "');\n\t\t\t\tjQuery(thisNewField).find('.urlclass').attr('name','" . $fieldname . "['+uniqueRowNum" . $field->id . "+'][class]');\n\t\t\t\t";
            }
            if ($useid) {
                $js .= "\n\t\t\t\tjQuery(thisNewField).find('input.urlid').attr('value','" . $default_id . "');\n\t\t\t\tjQuery(thisNewField).find('input.urlid').attr('name','" . $fieldname . "['+uniqueRowNum" . $field->id . "+'][id]');\n\t\t\t\t";
            }
            $js .= "\n\t\t\t\tjQuery(thisNewField).find('input.urlhits').attr('value','0');\n\t\t\t\tjQuery(thisNewField).find('input.urlhits').attr('name','" . $fieldname . "['+uniqueRowNum" . $field->id . "+'][hits]');\n\t\t\t\t\n\t\t\t\t// Set hits to zero for new row value\n\t\t\t\tjQuery(thisNewField).find('span span').html('0');\n\t\t\t\tjQuery(thisNewField).css('display', 'none');\n\t\t\t\tjQuery(thisNewField).insertAfter( jQuery(thisField) );\n\t\t\t\t\n\t\t\t\tjQuery('#sortables_" . $field->id . "').sortable({\n\t\t\t\t\thandle: '.fcfield-drag',\n\t\t\t\t\tcontainment: 'parent',\n\t\t\t\t\ttolerance: 'pointer'\n\t\t\t\t});\n\t\t\t\t\n\t\t\t\tjQuery(thisNewField).show('slideDown');\n\t\t\t\t\n\t\t\t\trowCount" . $field->id . "++;       // incremented / decremented\n\t\t\t\tuniqueRowNum" . $field->id . "++;   // incremented only\n\t\t\t}\n\n\t\t\tfunction deleteField" . $field->id . "(el)\n\t\t\t{\n\t\t\t\tif(rowCount" . $field->id . " <= 1) return;\n\t\t\t\tvar row = jQuery(el).closest('li');\n\t\t\t\tjQuery(row).hide('slideUp', function() { this.remove(); } );\n\t\t\t\trowCount" . $field->id . "--;\n\t\t\t}\n\t\t\t";
            $css = '
			#sortables_' . $field->id . ' { float:left; margin: 0px; padding: 0px; list-style: none; white-space: nowrap; }
			#sortables_' . $field->id . ' li {
				clear: both;
				display: block;
				list-style: none;
				height: auto;
				position: relative;
			}
			#sortables_' . $field->id . ' li.sortabledisabled {
				background : transparent url(components/com_flexicontent/assets/images/move3.png) no-repeat 0px 1px;
			}
			#sortables_' . $field->id . ' li input { cursor: text;}
			#add' . $field->name . ' { margin-top: 5px; clear: both; display:block; }
			#sortables_' . $field->id . ' li .admintable { text-align: left; }
			#sortables_' . $field->id . ' li:only-child span.fcfield-drag, #sortables_' . $field->id . ' li:only-child input.fcfield-button { display:none; }
			';
            $remove_button = '<input class="fcfield-button" type="button" value="' . JText::_('FLEXI_REMOVE_VALUE') . '" onclick="deleteField' . $field->id . '(this);" />';
            $move2 = '<span class="fcfield-drag">' . JHTML::image(JURI::base() . 'components/com_flexicontent/assets/images/move2.png', JText::_('FLEXI_CLICK_TO_DRAG')) . '</span>';
        } else {
            $remove_button = '';
            $move2 = '';
            $js = '';
            $css = '';
        }
        if ($js) {
            $document->addScriptDeclaration($js);
        }
        if ($css) {
            $document->addStyleDeclaration($css);
        }
        // Create once the options for field properties that have drop down-selection
        if ($useclass == 2) {
            $class_options = $this->getClassOptions($class_choices);
        }
        $field->html = array();
        $n = 0;
        foreach ($field->value as $value) {
            if (!strlen($value)) {
                continue;
            }
            $value = unserialize($value);
            $fieldname_n = $fieldname . '[' . $n . ']';
            $elementid_n = $elementid . '_' . $n;
            $has_prefix = preg_match("#^http|^https|^ftp#i", $value['link']);
            $link = '
				<tr><td class="key">' . JText::_('FLEXI_FIELD_URL') . '</td><td>
					<input class="urllink ' . $required . '" id="' . $elementid_n . '" name="' . $fieldname_n . '[link]" type="text" size="' . $size . '" value="' . $value['link'] . '" />
				</td></tr>';
            $autoprefix = '';
            if ($allow_relative_addrs == 2) {
                $autoprefix = '
				<tr><td class="key">' . JText::_('FLEXI_EXTWL_AUTOPREFIX') . '</td><td>
					<input class="autoprefix" id="' . $elementid . '_autoprefix_0" name="' . $fieldname_n . '[autoprefix]" type="radio" value="0" ' . (!$has_prefix ? 'checked="checked"' : '') . '/>
					<label for="' . $elementid . '_autoprefix_0">' . JText::_('FLEXI_NO') . '</label>
					<input class="autoprefix" id="' . $elementid . '_autoprefix_1" name="' . $fieldname_n . '[autoprefix]" type="radio" value="1" ' . ($has_prefix ? 'checked="checked"' : '') . '/>
					<label for="' . $elementid . '_autoprefix_1">' . JText::_('FLEXI_YES') . '</label>
				</td></tr>';
            }
            $title = '';
            if ($usetitle) {
                $title = '
				<tr><td class="key">' . JText::_('FLEXI_EXTWL_URLTITLE') . '</td><td>
					<input class="urltitle" name="' . $fieldname_n . '[title]" type="text" size="' . $size . '" value="' . (@$value['title'] ? $value['title'] : $default_title) . '" />
				</td></tr>';
            }
            $linktext = '';
            if ($usetext) {
                $linktext = '
				<tr><td class="key">' . JText::_('FLEXI_EXTWL_URLLINK_TEXT') . '</td><td>
					<input class="urllinktext" name="' . $fieldname_n . '[linktext]" type="text" size="' . $size . '" value="' . (@$value['linktext'] ? $value['linktext'] : $default_text) . '" />
				</td></tr>';
            }
            $class = '';
            if ($useclass == 1) {
                $class = '
					<tr><td class="key">' . JText::_('FLEXI_EXTWL_URLCLASS') . '</td><td>
						<input class="urlclass" name="' . $fieldname_n . '[class]" type="text" size="' . $size . '" value="' . (@$value['class'] ? $value['class'] : $default_class) . '" />
					</td></tr>';
            } else {
                if ($useclass == 2) {
                    $class_value = @$value['class'] ? $value['class'] : $default_class;
                    $class_attribs = ' class="urlclass" ';
                    $class = '
					<tr><td class="key">' . JText::_('FLEXI_EXTWL_URLCLASS') . '</td><td>
						' . JHTML::_('select.genericlist', $class_options, $fieldname_n . '[class]', $class_attribs, 'value', 'text', $class_value, $class_elementid = '') . '
					</td></tr>';
                }
            }
            $id = '';
            if ($useid) {
                $id = '
				<tr><td class="key">' . JText::_('FLEXI_EXTWL_URLID') . '</td><td>
					<input class="urlid" name="' . $fieldname_n . '[id]" type="text" size="' . $size . '" value="' . (@$value['id'] ? $value['id'] : $default_id) . '" />
				</td></tr>';
            }
            $hits = (int) @$value['hits'];
            $hits = '
				<tr><td class="key">' . JText::_('FLEXI_EXTWL_POPULARITY') . '</td><td>
					<input class="urlhits" name="' . $fieldname_n . '[hits]" type="hidden" value="' . $hits . '" />
					<span class="hits"><span class="hitcount">' . $hits . '</span> ' . JText::_('FLEXI_FIELD_HITS') . '</span>
				</td></tr>';
            $field->html[] = '
				<table class="admintable"><tbody>
				' . $link . '
				' . $autoprefix . '
				' . $title . '
				' . $linktext . '
				' . $class . '
				' . $id . '
				' . $hits . '
				</tbody></table>
				' . $move2 . '
				' . $remove_button . '
				';
            $n++;
            if (!$multiple) {
                break;
            }
            // multiple values disabled, break out of the loop, not adding further values even if the exist
        }
        if ($multiple) {
            // handle multiple records
            $_list = "<li>" . implode("</li>\n<li>", $field->html) . "</li>\n";
            $field->html = '
				<ul class="fcfield-sortables" id="sortables_' . $field->id . '">' . $_list . '</ul>
				<input type="button" class="fcfield-addvalue" onclick="addField' . $field->id . '(this);" value="' . JText::_('FLEXI_ADD_WEBLINK') . '" />
			';
        } else {
            // handle single values
            $field->html = $field->html[0];
        }
    }
Пример #7
0
    function onDisplayField(&$field, &$item)
    {
        // execute the code only if the field type match the plugin type
        if (!in_array($field->field_type, self::$field_types)) {
            return;
        }
        $field->label = JText::_($field->label);
        $app = JFactory::getApplication();
        $user = JFactory::getUser();
        $document = JFactory::getDocument();
        static $common_js_css_added = false;
        // some parameter shortcuts
        $multiple = $field->parameters->get('allow_multiple', 1);
        $max_values = (int) $field->parameters->get('max_values', 0);
        $image_source = $field->parameters->get('image_source', 0);
        if ($image_source > 1) {
            global $fc_folder_mode_err;
            if (empty($fc_folder_mode_err[$field->id])) {
                echo __FUNCTION__ . "(): folder-mode: " . $image_source . " not implemented please change image-source mode in image/gallery field with id: " . $field->id;
                $fc_folder_mode_err[$field->id] = 1;
                $image_source = 1;
            }
        }
        $imagepicker = $field->parameters->get('imagepicker', 1);
        $all_media = $field->parameters->get('list_all_media_files', 0);
        $unique_thumb_method = $field->parameters->get('unique_thumb_method', 0);
        $dir = $field->parameters->get('dir');
        $dir_url = str_replace('\\', '/', $dir);
        // Get a unique id to use as item id if current item is new
        $u_item_id = $item->id ? $item->id : JRequest::getVar('unique_tmp_itemid');
        // Check if using folder of original content being translated
        $of_usage = $field->untranslatable ? 1 : $field->parameters->get('of_usage', 0);
        $u_item_id = $of_usage && $item->lang_parent_id && $item->lang_parent_id != $item->id ? $item->lang_parent_id : $u_item_id;
        // FLAG to indicate if images are shared across fields, has the effect of adding field id to image thumbnails
        $multiple_image_usages = !$image_source && $all_media && $unique_thumb_method == 0;
        $extra_prefix = $multiple_image_usages ? 'fld' . $field->id . '_' : '';
        $required = $field->parameters->get('required', 0);
        $required = $required ? ' required' : '';
        $autoupload = $field->parameters->get('autoupload', 0);
        $autoassign = $field->parameters->get('autoassign', 0);
        $always_allow_removal = $field->parameters->get('always_allow_removal', 0);
        $thumb_w_s = $field->parameters->get('w_s', 120);
        $thumb_h_s = $field->parameters->get('h_s', 90);
        // optional properies configuration
        $linkto_url = $field->parameters->get('linkto_url', 0);
        $alt_usage = $field->parameters->get('alt_usage', 0);
        $title_usage = $field->parameters->get('title_usage', 0);
        $desc_usage = $field->parameters->get('desc_usage', 0);
        $default_alt = $item->version == 0 || $alt_usage > 0 ? $field->parameters->get('default_alt', '') : '';
        $default_title = $item->version == 0 || $title_usage > 0 ? JText::_($field->parameters->get('default_title', '')) : '';
        $default_desc = $item->version == 0 || $desc_usage > 0 ? $field->parameters->get('default_desc', '') : '';
        $usealt = $field->parameters->get('use_alt', 1);
        $usetitle = $field->parameters->get('use_title', 1);
        $usedesc = $field->parameters->get('use_desc', 1);
        $none_props = !$linkto_url && !$usealt && !$usetitle && !$usedesc;
        if (!$common_js_css_added) {
            $js = "\n\t\t\t\tfunction fx_toggle_upload_select_tbl (obj_changed, obj_disp_toggle) {\n\t\t\t\t\tif (jQuery(obj_disp_toggle).length == 0)\n\t\t\t\t\t\tobj_disp_toggle = jQuery(obj_changed).closest('.fcfieldval_container').find('table.img_upload_select');\n\t\t\t\t\telse\n\t\t\t\t\t\tobj_disp_toggle = jQuery(obj_disp_toggle);\n\t\t\t\t\tif (obj_changed.checked)\n\t\t\t\t\t\tobj_disp_toggle.css('display', 'table');\n\t\t\t\t\telse\n\t\t\t\t\t\tobj_disp_toggle.css('display', 'none');\n\t\t\t\t}\n\t\t\t\t";
            $document->addScriptDeclaration($js);
            $common_js_css_added = true;
        }
        $field->html = '';
        // Make sure value is an array of values
        if (!$field->value) {
            $field->value = array();
            $field->value[0]['originalname'] = '';
            $field->value[0] = serialize($field->value[0]);
        }
        if ($multiple) {
            if (!FLEXI_J16GE) {
                $document->addScript(JURI::root(true) . '/components/com_flexicontent/assets/js/sortables.js');
            }
            //add the drag and drop sorting feature
            $js = "\n\t\t\tjQuery(document).ready(function(){\n\t\t\t\tjQuery('#sortables_" . $field->id . "').sortable({\n\t\t\t\t\thandle: '.fcfield-drag',\n\t\t\t\t\tcontainment: 'parent',\n\t\t\t\t\ttolerance: 'pointer'\n\t\t\t\t});\n\t\t\t});\n\t\t\t";
            $fieldname = FLEXI_J16GE ? 'custom[' . $field->name . ']' : $field->name;
            $elementid = FLEXI_J16GE ? 'custom_' . $field->name : $field->name;
            // WARNING: bellow we also use $field->name which is different than $fieldname
            if ($max_values) {
                FLEXI_J16GE ? JText::script("FLEXI_FIELD_MAX_ALLOWED_VALUES_REACHED", true) : fcjsJText::script("FLEXI_FIELD_MAX_ALLOWED_VALUES_REACHED", true);
            }
            $auto_enable_imgpicker = 0;
            // Disabled to help performance
            $js .= "\n\t\t\tvar uniqueRowNum" . $field->id . "\t= " . count($field->value) . ";  // Unique row number incremented only\n\t\t\tvar rowCount" . $field->id . "\t= " . count($field->value) . ";      // Counts existing rows to be able to limit a max number of values\n\t\t\tvar maxValues" . $field->id . "\t= " . $max_values . ";\n\n\t\t\tfunction addField" . $field->id . "(el) {\n\t\t\t\tif((rowCount" . $field->id . " >= maxValues" . $field->id . ") && (maxValues" . $field->id . " != 0)) {\n\t\t\t\t\talert(Joomla.JText._('FLEXI_FIELD_MAX_ALLOWED_VALUES_REACHED') + maxValues" . $field->id . ");\n\t\t\t\t\treturn 'cancel';\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\tvar thisField \t = \$(el).getPrevious().getLast();\n\t\t\t\tvar thisNewField = thisField.clone();\n\t\t\t\tif (MooTools.version>='1.2.4') {\n\t\t\t\t\tvar fx = new Fx.Morph(thisNewField, {duration: 0, transition: Fx.Transitions.linear});\n\t\t\t\t} else {\n\t\t\t\t\tvar fx = thisNewField.effects({duration: 0, transition: Fx.Transitions.linear});\n\t\t\t\t}\n\t\t\t\t\n\t\t\t" . ($image_source ? "" : "\n\t\t\t\tvar has_imagepicker = jQuery(thisNewField).find('ul.image_picker_selector').length != 0;\n\t\t\t\tvar has_select2     = jQuery(thisNewField).find('div.select2-container').length != 0;\n\t\t\t\tif (has_imagepicker) jQuery(thisNewField).find('ul.image_picker_selector').remove();\n\t\t\t\tif (has_select2)     jQuery(thisNewField).find('div.select2-container').remove();\n\t\t\t\t") . "\n\t\t\t\n\t\t\t\tthisNewField.getElements('input.newfile').setProperty('value','');\n\t\t\t\tthisNewField.getElements('input.newfile').setProperty('name','" . $field->name . "['+uniqueRowNum" . $field->id . "+']');\n\t\t\t\tthisNewField.getElements('input.newfile').setProperty('id','" . $elementid . "_'+uniqueRowNum" . $field->id . "+'_newfile');\n\t\t\t\t\n\t\t\t\tthisNewField.getElements('input.originalname').setProperty('value','');\n\t\t\t\tthisNewField.getElements('input.originalname').setProperty('name','" . $fieldname . "['+uniqueRowNum" . $field->id . "+'][originalname]');\n\t\t\t\tthisNewField.getElements('input.originalname').setProperty('id','" . $elementid . "_'+uniqueRowNum" . $field->id . "+'_originalname');\n\t\t\t\t\n\t\t\t\tthisNewField.getElements('.existingname').setProperty('value','');\n\t\t\t\tthisNewField.getElements('.existingname').addClass('no_value_selected');\n\t\t\t\tthisNewField.getElements('.existingname').setProperty('name','" . $fieldname . "['+uniqueRowNum" . $field->id . "+'][existingname]');\n\t\t\t\tthisNewField.getElements('.existingname').setProperty('id','" . $elementid . "_'+uniqueRowNum" . $field->id . "+'_existingname');\n\t\t\t\t\n\t\t\t" . ($image_source ? "" : "\n\t\t\t\tif (has_imagepicker && " . $auto_enable_imgpicker . " ) jQuery(thisNewField).find('select.image-picker').imagepicker({ hide_select:false, show_label:true });\n\t\t\t\tif (has_select2)  jQuery(thisNewField).find('select.use_select2_lib').select2();\n\t\t\t\t") . "\n\t\t\t\tthisNewField.getElements('a.addfile_" . $field->id . "').setProperty('id','" . $elementid . "_'+uniqueRowNum" . $field->id . "+'_addfile');\n\t\t\t\tthisNewField.getElements('a.addfile_" . $field->id . "').setProperty('href','" . JURI::base(true) . '/index.php?option=com_flexicontent&view=fileselement&tmpl=component&layout=image&filter_secure=M&folder_mode=1&' . (FLEXI_J30GE ? JSession::getFormToken() : JUtility::getToken()) . '=1&field=' . $field->id . '&u_item_id=' . $u_item_id . '&targetid=' . $elementid . "_'+uniqueRowNum" . $field->id . "+'_existingname&thumb_w=" . $thumb_w_s . '&thumb_h=' . $thumb_h_s . '&autoassign=' . $autoassign . "');\n\t\t\t\t\n\t\t\t\t// COPYING an existing value\n\t\t\t\tif (thisNewField.getElement('img.preview_image')) {\n\t\t\t\t\tvar tmpDiv = jQuery('<div class=\"empty_image empty_image" . $field->id . "\" style=\"height:" . $field->parameters->get('h_s') . "px; width:" . $field->parameters->get('w_s') . "px;\"></div>');\n\t\t\t\t\ttmpDiv.attr('id','" . $elementid . "_'+uniqueRowNum" . $field->id . "+'_preview_image');\n\t\t\t\t\ttmpDiv.insertAfter( jQuery(thisNewField).find('img.preview_image') );\n\t\t\t\t\tjQuery(thisNewField).find('img.preview_image').remove();\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\t// COPYING an empty value\n\t\t\t\telse if (thisNewField.getElement('div.empty_image')) {\n\t\t\t\t\tjQuery(thisNewField).find('div.empty_image').attr('id','" . $elementid . "_'+uniqueRowNum" . $field->id . "+'_preview_image');\n\t\t\t\t\tjQuery(thisNewField).find('div.empty_image').html('');\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\tvar imgchange_toggler = jQuery(thisNewField).find('input.imgchange');\n\t\t\t\tif (imgchange_toggler.length) {\n\t\t\t\t\timgchange_toggler.prop('name','" . $field->name . "['+uniqueRowNum" . $field->id . "+']');\n\t\t\t\t\timgchange_toggler.prop('id','" . $elementid . "_'+uniqueRowNum" . $field->id . "+'_change');\n\t\t\t\t\timgchange_toggler.parent().find('label').prop('for','" . $elementid . "_'+uniqueRowNum" . $field->id . "+'_change');\n\t\t\t\t\t\n\t\t\t\t\tthisNewField.getElements('table.img_upload_select').setProperty('id','" . $field->name . "_upload_select_tbl_'+uniqueRowNum" . $field->id . ");\n\t\t\t\t\tthisNewField.getElements('table.img_upload_select').setStyle('display', 'table');\n\t\t\t\t\tjQuery(thisNewField).find('input.imgchange').prop('checked', true);\n\t\t\t\t}\n\t\t\t\t";
            if ($linkto_url) {
                $js .= "\n\t\t\t\tthisNewField.getElements('input.imglink').setProperty('value','');\n\t\t\t\tthisNewField.getElements('input.imglink').setProperty('name','" . $fieldname . "['+uniqueRowNum" . $field->id . "+'][urllink]');\n\t\t\t\t";
            }
            if ($usealt) {
                $js .= "\n\t\t\t\tthisNewField.getElements('input.imgalt').setProperty('value','" . $default_alt . "');\n\t\t\t\tthisNewField.getElements('input.imgalt').setProperty('name','" . $fieldname . "['+uniqueRowNum" . $field->id . "+'][alt]');\n\t\t\t\t";
            }
            if ($usetitle) {
                $js .= "\n\t\t\t\tthisNewField.getElements('input.imgtitle').setProperty('value','" . $default_title . "');\n\t\t\t\tthisNewField.getElements('input.imgtitle').setProperty('name','" . $fieldname . "['+uniqueRowNum" . $field->id . "+'][title]');\n\t\t\t\t";
            }
            if ($usedesc) {
                $js .= "\n\t\t\t\tthisNewField.getElements('textarea.imgdesc').setProperty('value','" . $default_desc . "');\n\t\t\t\tthisNewField.getElements('textarea.imgdesc').setProperty('name','" . $fieldname . "['+uniqueRowNum" . $field->id . "+'][desc]');\n\t\t\t\t";
            }
            $js .= "\n\t\t\t\tjQuery(thisNewField).insertAfter( jQuery(thisField) );\n\t\t\t\t" . "\n\t\t\t\t\n\t\t\t\tSqueezeBox.initialize({});\n\t\t\t\tif (MooTools.version>='1.2.4') {\n\t\t\t\t\tSqueezeBox.assign(\$\$('a.addfile_" . $field->id . "'), {\n\t\t\t\t\t\tparse: 'rel'\n\t\t\t\t\t});\n\t\t\t\t} else {\n\t\t\t\t\t\$\$('a.addfile_" . $field->id . "').each(function(el) {\n\t\t\t\t\t\tel.addEvent('click', function(e) {\n\t\t\t\t\t\t\tnew Event(e).stop();\n\t\t\t\t\t\t\tSqueezeBox.fromElement(el);\n\t\t\t\t\t\t});\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\tjQuery('#sortables_" . $field->id . "').sortable({\n\t\t\t\t\thandle: '.fcfield-drag',\n\t\t\t\t\tcontainment: 'parent',\n\t\t\t\t\ttolerance: 'pointer'\n\t\t\t\t});\n\n\t\t\t\tfx.start({ 'opacity': 1 }).chain(function(){\n\t\t\t\t\tthis.setOptions({duration: 600});\n\t\t\t\t\tthis.start({ 'opacity': 0 });\n\t\t\t\t\t})\n\t\t\t\t\t.chain(function(){\n\t\t\t\t\t\tthis.setOptions({duration: 300});\n\t\t\t\t\t\tthis.start({ 'opacity': 1 });\n\t\t\t\t\t});\n\n\t\t\t\trowCount" . $field->id . "++;       // incremented / decremented\n\t\t\t\tuniqueRowNum" . $field->id . "++;   // incremented only\n\t\t\t}\n\n\t\t\tfunction deleteField" . $field->id . "(el)\n\t\t\t{\n\t\t\t\tvar field\t= \$(el);\n\t\t\t\t\n\t\t\t\tif(rowCount" . $field->id . " == 1)\n\t\t\t\t{\n\t\t\t\t\taddField" . $field->id . "(field.getParent().getParent().getParent().getElement('input.fcfield-addvalue'));\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\tvar originalfftag = 'input.originalname';\n\t\t\t\tvar existingfftag = '" . ($image_source ? "input" : "select") . "' + '.existingname';\n\t\t\t\t\n\t\t\t\tvar originalname = jQuery(field).parent().find( originalfftag ).val();\n\t\t\t\tvar existingname = jQuery(field).parent().find( existingfftag ).val();\n\t\t\t\t\n\t\t\t\tif ( originalname != '' || existingname != '' ) {\n\t\t\t\t\tvar valcounter = \$('" . $field->name . "');\n\t\t\t\t\tif ( !valcounter.value || valcounter.value=='1' ) valcounter.value = '';\n\t\t\t\t\telse valcounter.value = parseInt(valcounter.value) - 1;\n\t\t\t\t\t//alert(valcounter.value);\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\tif(rowCount" . $field->id . " > 0)\n\t\t\t\t{\n\t\t\t\t\tvar row\t\t= field.getParent();\n\t\t\t\t\tif (MooTools.version>='1.2.4') {\n\t\t\t\t\t\tvar fx = new Fx.Morph(row, {duration: 300, transition: Fx.Transitions.linear});\n\t\t\t\t\t} else {\n\t\t\t\t\t\tvar fx = row.effects({duration: 300, transition: Fx.Transitions.linear});\n\t\t\t\t\t}\n\t\t\t\t\t\n\t\t\t\t\tfx.start({\n\t\t\t\t\t\t'height': 0,\n\t\t\t\t\t\t'opacity': 0\n\t\t\t\t\t\t}).chain(function(){\n\t\t\t\t\t\t\t(MooTools.version>='1.2.4')  ?  row.destroy()  :  row.remove();\n\t\t\t\t\t\t});\n\t\t\t\t\trowCount" . $field->id . "--;\n\t\t\t\t}\n\t\t\t}\n\t\t\t";
            $css = '
			#sortables_' . $field->id . ' {
				float:left!important; margin:0px!important; padding:0px!important;
				list-style:none!important; white-space:normal!important;
			}
			#sortables_' . $field->id . ' li {
				' . ($none_props ? 'float:left!important; clear:none!important; white-space:normal!important;' : 'clear:both!important;') . '
				display: block!important;
				list-style: none!important;
				position: relative;  .' . '
			}
			#sortables_' . $field->id . ' li input { cursor:text; }
			#add' . $field->name . ' { margin-top:5px; clear:both; display:block; }
			#sortables_' . $field->id . ' li .admintable { text-align:left; }
			#sortables_' . $field->id . ' li:only-child span.fcfield-drag { display:none; }
			#sortables_' . $field->id . ' li .fcimg_preview_box { min-width:' . ($thumb_w_s + 6) . 'px; min-height:' . ($thumb_h_s + 8) . 'px; }
			/*#sortables_' . $field->id . ' li:only-child input.fcfield-button { display:none; }*/
			';
            $remove_button = '<input class="fcfield-button" style="margin: 0px 0px 4px 8px !important;" type="button" value="' . JText::_('FLEXI_REMOVE_VALUE') . '" onclick="deleteField' . $field->id . '(this);" />';
            $move2 = ($none_props ? '<br/>' : '') . '<span class="fcfield-drag">' . JHTML::image(JURI::base() . 'components/com_flexicontent/assets/images/move2.png', JText::_('FLEXI_CLICK_TO_DRAG')) . '</span>';
        } else {
            $remove_button = '';
            $move2 = '';
            $js = '';
            $css = '';
        }
        // Common JS/CSS
        $image_folder = JURI::root(true) . '/' . $dir_url;
        $js .= "\n\t\t\tvar fc_db_img_path='" . $image_folder . "';\n\t\t\tfunction qmAssignFile" . $field->id . "(tagid, file, file_url) {\n\t\t\t\tvar replacestr = (tagid.indexOf('_existingname') > -1) ? '_existingname' : '_newfile';\n\t\t\t\tvar elementid = tagid.replace(replacestr,'');\n\t\t\t\t\n\t\t\t\tvar originalname = \$( elementid + '_originalname' ).getProperty('value');\n\t\t\t\tvar existingname = \$( elementid + '_existingname' ).getProperty('value');\n\t\t\t\t\n\t\t\t\tvar valcounter = \$('" . $field->name . "');\n\t\t\t\t\n\t\t\t\tif (file=='') {  // DB-mode\n\t\t\t\t\n\t\t\t\t\tvar newfilename  = \$( elementid + '_newfile' ).getProperty('value');\n\t\t\t\t\t\n\t\t\t\t\tif ( replacestr == '_newfile' ) {\n\t\t\t\t\t\n\t\t\t\t\t\tif ( \$( elementid + '_newfile' ).hasClass('no_value_selected') && newfilename!='' ) {\n\t\t\t\t\t\t\tvar modify = ( originalname=='' && existingname=='' );\n\t\t\t\t\t\t\t\$( elementid + '_newfile' ).removeClass('no_value_selected');\n\t\t\t\t\t\t} else if ( !\$( elementid + '_newfile' ).hasClass('no_value_selected') && newfilename=='' ) {\n\t\t\t\t\t\t\tvar modify = -1;\n\t\t\t\t\t\t\t\$( elementid + '_newfile' ).addClass('no_value_selected');\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tvar modify = 0;\n\t\t\t\t\t\t}\n\t\t\t\t\t\t\n\t\t\t\t\t\t\$( elementid + '_existingname' ).setProperty('value', '');\n\t\t\t\t\t\t\$( elementid + '_existingname' ).addClass('no_value_selected');\n\t\t\t\t\t} else {\n\t\t\t\t\t\n\t\t\t\t\t\tif ( \$( elementid + '_existingname' ).hasClass('no_value_selected') && existingname!='' ) {\n\t\t\t\t\t\t\tvar modify = ( originalname=='' && newfilename=='' );\n\t\t\t\t\t\t\t\$( elementid + '_existingname' ).removeClass('no_value_selected');\n\t\t\t\t\t\t} else if ( !\$( elementid + '_existingname' ).hasClass('no_value_selected') && existingname=='' ) {\n\t\t\t\t\t\t\tvar modify = -1;\n\t\t\t\t\t\t\t\$( elementid + '_existingname' ).addClass('no_value_selected');\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tvar modify = 0;\n\t\t\t\t\t\t}\n\t\t\t\t\t\t\n\t\t\t\t\t\t\$( elementid + '_newfile' ).setProperty('value', '');\n\t\t\t\t\t\t\$( elementid + '_newfile' ).addClass('no_value_selected');\n\t\t\t\t\t}\n\t\t\t\t\t\n\t\t\t\t\tif (modify>0) {\n\t\t\t\t\t\tif ( valcounter.value=='' ) valcounter.value = '1';\n\t\t\t\t\t\telse valcounter.value = parseInt(valcounter.value) + modify;\n\t\t\t\t\t} else if (modify<0) {\n\t\t\t\t\t\tif ( valcounter.value=='1' ) valcounter.value = '';\n\t\t\t\t\t\telse valcounter.value = parseInt(valcounter.value) + modify;\n\t\t\t\t\t}\n\t\t\t\t\t\n\t\t\t\t} else {  // Folder mode\n\t\t\t\t\n\t\t\t\t\tif ( originalname=='' && existingname=='' ) {\n\t\t\t\t\t\tif ( valcounter.value=='' ) valcounter.value = '1';\n\t\t\t\t\t\telse valcounter.value = parseInt(valcounter.value) + 1;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\t//alert(valcounter.value);\n\t\t\t\t\n\t\t\t\tvar existing_obj = \$( elementid + '_existingname' );\n\t\t\t\tvar original_obj = \$( elementid + '_originalname' );\n\t\t\t\t\n\t\t\t\tvar prv_obj = \$( elementid + '_preview_image' );\n\t\t\t\t\n\t\t\t\t// Folder-Mode\n\t\t\t\tif (file != '')  existing_obj.setProperty('value', file);\n\t\t\t\toriginal_obj.setProperty('value', '');\n\t\t\t\t// DB-Mode\n\t\t\t\tif (file == '') jQuery( '#' + elementid + '_imgdelete' ).remove();\n\t\t\t\t\n\t\t\t\tif (prv_obj) {\n\t\t\t\t\tpreview_msg = '<span id=\"'+elementid+'_preview_msg\"></span>';\n\t\t\t\t\tif (file || !\$( elementid + '_existingname' ).hasClass('no_value_selected') ) {\n\t\t\t\t\t\tvar preview_container = '<img class=\"preview_image\" id=\"'+elementid+'_preview_image\" src=\"'+file_url+'\" style=\"border: 1px solid silver; float:left;\" alt=\"Preview image\" />';\n\t\t\t\t\t} else {\n\t\t\t\t\t\tvar preview_container = '<img class=\"preview_image\" id=\"'+elementid+'_preview_image\" src=\"\" style=\"border: 1px solid silver; float:left;\" alt=\"Preview image\" />';\n\t\t\t\t\t\t\n\t\t\t\t\t\t/*var preview_container = '<div class=\"empty_image empty_image" . $field->id . "\" id=\"'+elementid+'_preview_image\" style=\"height:" . $field->parameters->get('h_s') . "px; width:" . $field->parameters->get('w_s') . "px;\">'\n\t\t\t\t\t\tif ( replacestr == '_newfile' && newfilename!='' )\n\t\t\t\t\t\t\tpreview_container += newfilename.replace(/^.*[\\\\/]/, '');\n\t\t\t\t\t\tpreview_container = preview_container + '</div>';*/\n\t\t\t\t\t}\n\t\t\t\t\t\n\t\t\t\t\tvar tmpDiv = jQuery(preview_container);\n\t\t\t\t\ttmpDiv.insertAfter( jQuery(prv_obj) );\n\t\t\t\t\tvar tmpDiv = jQuery(preview_msg);\n\t\t\t\t\ttmpDiv.insertAfter( jQuery(prv_obj) );\n\t\t\t\t\tjQuery(prv_obj).remove();\n\t\t\t\t\t\n\t\t\t\t\tif (file || !\$( elementid + '_existingname' ).hasClass('no_value_selected') ) {\n\t\t\t\t\t} else {\n\t\t\t\t\t\tloadImagePreview(tagid, elementid+'_preview_image', elementid+'_preview_msg', " . $thumb_w_s . ", " . $thumb_h_s . ");\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\t(MooTools.version>='1.2.4') ?  window.SqueezeBox.close()  :  window.document.getElementById('sbox-window').close();\n\t\t\t}\n\t\t";
        $css .= '
			.empty_image' . $field->id . ' { word-wrap:break-word !important; }
			table.fcfield' . $field->id . '.img_upload_select { float:left; clear:none; border:1px dashed gray; margin-bottom:16px; }
			table.fcfield' . $field->id . '.img_upload_select li { min-height:' . ($thumb_h_s + 56) . 'px; }
			table.fcfield' . $field->id . '.img_upload_select ul { height:' . ($thumb_h_s + 96) . 'px; }
			table.fcfield' . $field->id . '.img_upload_select ul { width:' . 2 * ($thumb_w_s + 64) . 'px; }
		';
        if ($js) {
            $document->addScriptDeclaration($js);
        }
        if ($css) {
            $document->addStyleDeclaration($css);
        }
        flexicontent_html::loadFramework('flexi-lib');
        if ($image_source) {
            JHTML::_('behavior.modal', 'a.addfile_' . $field->id);
        } else {
            $select = $this->buildSelectList($field);
        }
        $class = ' class="' . $required . ' "';
        $onchange = ' onchange="';
        //$onchange .= ($required) ? ' fx_img_toggle_required(this,$(\''.$field->name.'originalname\')); ' : '';
        $onchange .= " qmAssignFile" . $field->id . "(this.id, '', '');";
        $js_submit = FLEXI_J16GE ? "Joomla.submitbutton('items.apply')" : "submitbutton('apply')";
        $onchange .= $autoupload && $app->isAdmin() ? $js_submit : '';
        $onchange .= ' "';
        $i = -1;
        // Count DB values (may contain invalid entries)
        $n = 0;
        // Count sortable records added (the verified values or a single empty record if no good values)
        $count_vals = 0;
        // Count non-empty sortable records added
        $image_added = false;
        $skipped_vals = array();
        foreach ($field->value as $value) {
            $value = unserialize($value);
            $i++;
            $fieldname = FLEXI_J16GE ? 'custom[' . $field->name . '][' . $n . ']' : $field->name . '[' . $n . ']';
            $elementid = FLEXI_J16GE ? 'custom_' . $field->name . '_' . $n : $field->name . '_' . $n;
            $image_name = trim(@$value['originalname']);
            // Check and rebuild thumbnails if needed
            $rebuild_res = plgFlexicontent_fieldsImage::rebuildThumbs($field, $value, $item);
            // Check if rebuilding thumbnails failed (e.g. file has been deleted)
            if (!$rebuild_res) {
                // For non-empty value set a message when we have examined all values
                if ($image_name) {
                    $skipped_vals[] = $image_name;
                }
                // Skip current value but add and an empty image container if no other image exists
                if ($image_added || $i + 1 < count($field->value)) {
                    continue;
                } else {
                    $image_name = '';
                }
            } else {
                $count_vals++;
            }
            if ($image_source) {
                $select = "\n\t\t\t\t<input class='existingname fcfield_textval' id='" . $elementid . "_existingname' name='" . $fieldname . "[existingname]' value='" . $image_name . "' readonly='readonly' style='float:none;' />\n\t\t\t\t" . ($none_props ? '<br/>' : '') . "\n\t\t\t\t<div class=\"fcfield-button-add\" style='margin: 0px 0px 4px -4px; display:inline-block;'>\n\t\t\t\t\t<a class=\"addfile_" . $field->id . "\" id='" . $elementid . "_addfile' title=\"" . JText::_('FLEXI_SELECT_IMAGE') . "\"\n\t\t\t\t\t\t" . "href=\"" . JURI::base(true) . '/index.php?option=com_flexicontent&view=fileselement&tmpl=component&layout=image&filter_secure=M&folder_mode=1&' . (FLEXI_J30GE ? JSession::getFormToken() : JUtility::getToken()) . '=1&field=' . $field->id . '&u_item_id=' . $u_item_id . '&targetid=' . $elementid . "_existingname&thumb_w={$thumb_w_s}&thumb_h={$thumb_h_s}&autoassign=" . $autoassign . "\"\n\t\t\t\t\t\trel=\"{handler: 'iframe', size: {x: (MooTools.version>='1.2.4' ? window.getSize().x : window.getSize().size.x)-100, y: (MooTools.version>='1.2.4' ? window.getSize().y : window.getSize().size.y)-100}}\">" . JText::_('FLEXI_SELECT_IMAGE') . "</a>\n\t\t\t\t</div>\n\t\t\t\t";
            }
            // Add current image or add an empty image container
            $delete = $remove = $change = '';
            if ($image_name) {
                if (!$multiple) {
                    $remove_disabled = '';
                    if (!$image_source) {
                        $canDeleteImage = $this->canDeleteImage($field, $image_name, $item);
                        $delete_disabled = $canDeleteImage ? '' : ' disabled="disabled"';
                        $delete = '<div id="' . $elementid . '_imgdelete" class="imgdelete">';
                        $delete .= ' <input class="imgdelete" type="checkbox" name="' . $fieldname . '[delete]" id="' . $elementid . '_delete" value="1"' . $delete_disabled . ' />';
                        $delete .= ' <label for="' . $elementid . '_delete">' . JText::_('FLEXI_FIELD_DELETE_FILE') . '</label>';
                        $delete .= '</div>';
                        $remove_disabled = $always_allow_removal ? '' : $canDeleteImage ? ' disabled="disabled"' : '';
                    }
                    $remove = '<div id="' . $elementid . '_imgremove" class="imgremove">';
                    $remove .= ' <input class="imgremove" type="checkbox" name="' . $fieldname . '[remove]" id="' . $elementid . '_remove" value="1"' . $remove_disabled . ' />';
                    $remove .= ' <label style="display:inline;" for="' . $elementid . '_remove">' . JText::_('FLEXI_FIELD_REMOVE_VALUE') . '</label>';
                    $remove .= '</div>';
                }
                $originalname = '<input name="' . $fieldname . '[originalname]" id="' . $elementid . '_originalname" type="hidden" class="originalname" value="' . $value['originalname'] . '" />';
                $img_link = JURI::root(true) . '/' . $dir_url;
                $img_link .= $image_source ? '/item_' . $u_item_id . '_field_' . $field->id : "";
                $img_link .= '/s_' . $extra_prefix . $value['originalname'];
                $imgpreview = '<img class="preview_image" id="' . $elementid . '_preview_image" src="' . $img_link . '" style="border: 1px solid silver; float:left;" alt="Preview image" />';
            } else {
                $originalname = '<input name="' . $fieldname . '[originalname]" id="' . $elementid . '_originalname" type="hidden" class="originalname" value="" />';
                $imgpreview = '<div class="empty_image empty_image' . $field->id . '" id="' . $elementid . '_preview_image" style="height:' . $field->parameters->get('h_s') . 'px; width:' . $field->parameters->get('w_s') . 'px;"></div>';
            }
            if (!$image_source) {
                $change .= !$multiple ? ' <input class="imgchange" style="display:none;" type="checkbox" name="' . $fieldname . '[change]" id="' . $elementid . '_change" onchange="fx_toggle_upload_select_tbl(this, $(\'' . $field->name . '_upload_select_tbl_' . $n . '\'))" value="1" ' . ($image_name ? '' : ' checked="checked" ') . '/>' : ' <input class="imgchange" style="display:none;" type="checkbox" name="' . $fieldname . '[change]" id="' . $elementid . '_change" onchange="fx_toggle_upload_select_tbl(this)" value="1" ' . ($image_name ? '' : ' checked="checked" ') . ' />';
                $change .= ' <span></span><label class="fcfield-button" style="margin: 0px 0px 4px 0px !important;" for="' . $elementid . '_change">' . JText::_('FLEXI_TOGGLE_IMAGE_SELECTOR') . '</label>';
            }
            if ($linkto_url) {
                $urllink = '<tr>
					<td class="key">' . JText::_('FLEXI_FIELD_LINKTO_URL') . ':</td>
					<td><input class="imglink" size="40" name="' . $fieldname . '[urllink]" value="' . (isset($value['urllink']) ? $value['urllink'] : '') . '" type="text" /></td>
				</tr>';
            }
            if ($usealt) {
                $alt = '<tr>
					<td class="key">' . JText::_('FLEXI_FIELD_ALT') . ')</td>
					<td><input class="imgalt" size="40" name="' . $fieldname . '[alt]" value="' . (isset($value['alt']) ? $value['alt'] : $default_alt) . '" type="text" /></td>
				</tr>';
            }
            if ($usetitle) {
                $title = '<tr>
					<td class="key">' . JText::_('FLEXI_FIELD_TITLE') . ': (' . JText::_('FLEXI_FIELD_TOOLTIP') . ')</td>
					<td><input class="imgtitle" size="40" name="' . $fieldname . '[title]" value="' . (isset($value['title']) ? $value['title'] : $default_title) . '" type="text" /></td>
				</tr>';
            }
            if ($usedesc) {
                $desc = '<tr>
					<td class="key">' . JText::_('FLEXI_FIELD_LONGDESC') . ': <br/>(' . JText::_('FLEXI_FIELD_TOOLTIP') . ')</td>
					<td><textarea class="imgdesc" name="' . $fieldname . '[desc]" rows="5" cols="28" >' . (isset($value['desc']) ? $value['desc'] : $default_desc) . '</textarea></td>
				</tr>';
            }
            $curr_select = str_replace('__FORMFLDNAME__', $fieldname . '[existingname]', $select);
            $curr_select = str_replace('__FORMFLDID__', $elementid . '_existingname', $curr_select);
            $field->html[] = '
			' . ($image_source ? $curr_select : $change) . '
			' . $move2 . '
			' . $remove_button . '<br/>
			<div class="fcimg_preview_box" style="float:left!important; clear:none!important; margin-right:5px!important;">
				' . $imgpreview . '
				' . $originalname . '
				<div style="float:left; clear:both;" class="imgactions_box">
					' . ($remove ? $remove : '') . '
					' . ($delete ? $delete : '') . '
				</div>
			</div>
			' . ($linkto_url || $usealt || $usetitle || $usedesc ? '
			<div style="float:left; clear:none;" class="img_value_props">
				<table class="admintable"><tbody>
					' . @$urllink . '
					' . @$alt . '
					' . @$title . '
					' . @$desc . '
				</tbody></table>
			</div>' : '') . (!$image_source ? '
				<table class="admintable fcfield' . $field->id . ' img_upload_select" id="' . $field->name . '_upload_select_tbl_' . $n . '" style="' . ($image_name ? "display:none;" : "") . '" ><tbody>
					<tr class="img_newfile_row">
						<td class="key fckey_high">' . JText::_('FLEXI_FIELD_NEWFILE') . ':</td>
						<td style="white-space: normal;">' . '<input name="' . $field->name . '[' . $n . ']" id="' . $elementid . '_newfile"  class="newfile no_value_selected" ' . $onchange . ' type="file" /><br/><br/>' . '<b>' . JText::_('FLEXI_FIELD_MAXSIZE') . '</b>: ' . $field->parameters->get('upload_maxsize') / 1000000 . ' MBs &nbsp; - &nbsp; <br/>' . '<b>' . JText::_('FLEXI_FIELD_ALLOWEDEXT') . '</b>: ' . str_replace(",", ", ", $field->parameters->get('upload_extensions')) . '
						</td>
					</tr>
					<tr class="img_existingfile_row">
						<td class="key fckey_high">' . JText::_(!$image_source ? 'FLEXI_FIELD_EXISTINGFILE' : 'FLEXI_SELECT') . ':</td>
						<td>' . $curr_select . '</td>
					</tr>
				</tbody></table>
			' : '');
            $n++;
            $image_added = true;
            if (!$multiple) {
                break;
            }
            // multiple values disabled, break out of the loop, not adding further values even if the exist
        }
        if ($multiple) {
            // handle multiple records
            $field->html = '<li class="fcfieldval_container">' . implode('</li><li class="fcfieldval_container">', $field->html) . '</li>';
            $field->html = '<ul class="fcfield-sortables" id="sortables_' . $field->id . '">' . $field->html . '</ul>';
            $field->html .= '<input type="button" class="fcfield-addvalue" style="float:left; clear:both;" onclick="addField' . $field->id . '(this);" value=" -- ' . JText::_('FLEXI_ADD_IMAGE_CONTAINER') . ' -- " />';
        } else {
            // handle single values
            $field->html = '<div class="fcfieldval_container">' . $field->html[0] . '</div>';
        }
        $field->html .= '<input id="' . $field->name . '" class="' . $required . '" style="display:none;" name="__fcfld_valcnt__[' . $field->name . ']" value="' . ($count_vals ? $count_vals : '') . '" />';
        if (count($skipped_vals)) {
            $app->enqueueMessage(JText::sprintf('FLEXI_FIELD_EDIT_VALUES_SKIPPED', $field->label, implode(',', $skipped_vals)), 'notice');
        }
    }
Пример #8
0
    function onDisplayField(&$field, &$item)
    {
        if (!in_array($field->field_type, self::$field_types)) {
            return;
        }
        $field->label = JText::_($field->label);
        $use_ingroup = $field->parameters->get('use_ingroup', 0);
        if ($use_ingroup) {
            $field->formhidden = 3;
        }
        if ($use_ingroup && empty($field->ingroup)) {
            return;
        }
        $app = JFactory::getApplication();
        $user = JFactory::getUser();
        $document = JFactory::getDocument();
        static $common_js_css_added = false;
        // Get a unique id to use as item id if current item is new
        $u_item_id = $item->id ? $item->id : JRequest::getVar('unique_tmp_itemid');
        // Check if using folder of original content being translated
        $of_usage = $field->untranslatable ? 1 : $field->parameters->get('of_usage', 0);
        $u_item_id = $of_usage && $item->lang_parent_id && $item->lang_parent_id != $item->id ? $item->lang_parent_id : $u_item_id;
        // ****************
        // Number of values
        // ****************
        $multiple = $use_ingroup || (int) $field->parameters->get('allow_multiple', 0);
        $max_values = $use_ingroup ? 0 : (int) $field->parameters->get('max_values', 0);
        $required = $field->parameters->get('required', 0);
        $required = $required ? ' required' : '';
        $add_position = (int) $field->parameters->get('add_position', 3);
        $image_source = $field->parameters->get('image_source', 0);
        if ($image_source > 1) {
            global $fc_folder_mode_err;
            if (empty($fc_folder_mode_err[$field->id])) {
                echo __FUNCTION__ . "(): folder-mode: " . $image_source . " not implemented please change image-source mode in image/gallery field with id: " . $field->id;
                $fc_folder_mode_err[$field->id] = 1;
                $image_source = 1;
            }
        }
        $existing_imgs = $field->parameters->get('existing_imgs', 1);
        $all_media = $field->parameters->get('list_all_media_files', 0);
        $unique_thumb_method = $field->parameters->get('unique_thumb_method', 0);
        $dir = $field->parameters->get('dir');
        $dir_url = str_replace('\\', '/', $dir);
        // FLAG to indicate if images are shared across fields, has the effect of adding field id to image thumbnails
        $multiple_image_usages = !$image_source && $all_media && $unique_thumb_method == 0;
        $extra_prefix = $multiple_image_usages ? 'fld' . $field->id . '_' : '';
        $autoupload = $field->parameters->get('autoupload', 0);
        $autoassign = $field->parameters->get('autoassign', 0);
        $always_allow_removal = $field->parameters->get('always_allow_removal', 0);
        $imgsel_visible = $field->parameters->get('imgsel_visible', 0);
        $thumb_w_s = $field->parameters->get('w_s', 120);
        $thumb_h_s = $field->parameters->get('h_s', 90);
        // optional properies configuration
        $linkto_url = $field->parameters->get('linkto_url', 0);
        $alt_usage = $field->parameters->get('alt_usage', 0);
        $title_usage = $field->parameters->get('title_usage', 0);
        $desc_usage = $field->parameters->get('desc_usage', 0);
        $cust1_usage = $field->parameters->get('cust1_usage', 0);
        $cust2_usage = $field->parameters->get('cust2_usage', 0);
        $default_alt = $item->version == 0 || $alt_usage > 0 ? $field->parameters->get('default_alt', '') : '';
        $default_title = $item->version == 0 || $title_usage > 0 ? JText::_($field->parameters->get('default_title', '')) : '';
        $default_desc = $item->version == 0 || $desc_usage > 0 ? $field->parameters->get('default_desc', '') : '';
        $default_cust1 = $item->version == 0 || $cust1_usage > 0 ? $field->parameters->get('default_cust1', '') : '';
        $default_cust2 = $item->version == 0 || $cust2_usage > 0 ? $field->parameters->get('default_cust2', '') : '';
        $usealt = $field->parameters->get('use_alt', 1);
        $usetitle = $field->parameters->get('use_title', 1);
        $usedesc = $field->parameters->get('use_desc', 1);
        $usecust1 = $field->parameters->get('use_cust1', 0);
        $usecust2 = $field->parameters->get('use_cust2', 0);
        $none_props = !$linkto_url && !$usealt && !$usetitle && !$usedesc && !$usecust1 && !$usecust2;
        if (!$common_js_css_added) {
            $js = "\n\t\t\t\tfunction fx_toggle_upload_select_tbl (obj_changed, objid_disp_toggle) {\n\t\t\t\t\tvar value_container = jQuery(obj_changed).closest('.fcfieldval_container');\n\t\t\t\t\tobj_disp_toggle = value_container.find('table.img_upload_select');\n\t\t\t\t\tif (obj_changed.checked) {\n\t\t\t\t\t\tobj_disp_toggle.css('display', 'table');\n\t\t\t\t\t\tvalue_container.css('width', '100%');\n\t\t\t\t\t} else {\n\t\t\t\t\t\tobj_disp_toggle.css('display', 'none');\n\t\t\t\t\t\tvalue_container.css('width', '');\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\t\t";
            $document->addScriptDeclaration($js);
            $common_js_css_added = true;
        }
        $field->html = '';
        // Initialise property with default value
        if (!$field->value) {
            $field->value = array();
            $field->value[0]['originalname'] = '';
            $field->value[0] = serialize($field->value[0]);
        }
        // CSS classes of value container
        $value_classes = 'fcfieldval_container valuebox fcfieldval_container_' . $field->id;
        // Field name and HTML TAG id
        $fieldname = 'custom[' . $field->name . ']';
        $elementid = 'custom_' . $field->name;
        $js = "\n\t\t\tvar fc_field_dialog_handle_" . $field->id . ";\n\t\t";
        $css = "";
        if ($multiple) {
            // Add the drag and drop sorting feature
            if (!$use_ingroup) {
                $js .= "\n\t\t\tjQuery(document).ready(function(){\n\t\t\t\tjQuery('#sortables_" . $field->id . "').sortable({\n\t\t\t\t\thandle: '.fcfield-drag-handle',\n\t\t\t\t\tcontainment: 'parent',\n\t\t\t\t\ttolerance: 'pointer'\n\t\t\t\t});\n\t\t\t});\n\t\t\t";
            }
            // WARNING: bellow we also use $field->name which is different than $fieldname
            if ($max_values) {
                FLEXI_J16GE ? JText::script("FLEXI_FIELD_MAX_ALLOWED_VALUES_REACHED", true) : fcjsJText::script("FLEXI_FIELD_MAX_ALLOWED_VALUES_REACHED", true);
            }
            $auto_enable_imgpicker = 0;
            // Disabled imagepicker during copy to help performance
            $js .= "\n\t\t\tvar uniqueRowNum" . $field->id . "\t= " . count($field->value) . ";  // Unique row number incremented only\n\t\t\tvar rowCount" . $field->id . "\t= " . count($field->value) . ";      // Counts existing rows to be able to limit a max number of values\n\t\t\tvar maxValues" . $field->id . " = " . $max_values . ";\n\t\t\t\n\t\t\tfunction addField" . $field->id . "(el, groupval_box, fieldval_box, params)\n\t\t\t{\n\t\t\t\tvar insert_before   = (typeof params!== 'undefined' && typeof params.insert_before   !== 'undefined') ? params.insert_before   : 0;\n\t\t\t\tvar remove_previous = (typeof params!== 'undefined' && typeof params.remove_previous !== 'undefined') ? params.remove_previous : 0;\n\t\t\t\tvar scroll_visible  = (typeof params!== 'undefined' && typeof params.scroll_visible  !== 'undefined') ? params.scroll_visible  : 1;\n\t\t\t\tvar animate_visible = (typeof params!== 'undefined' && typeof params.animate_visible !== 'undefined') ? params.animate_visible : 1;\n\t\t\t\t\n\t\t\t\tif((rowCount" . $field->id . " >= maxValues" . $field->id . ") && (maxValues" . $field->id . " != 0)) {\n\t\t\t\t\talert(Joomla.JText._('FLEXI_FIELD_MAX_ALLOWED_VALUES_REACHED') + maxValues" . $field->id . ");\n\t\t\t\t\treturn 'cancel';\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\tvar lastField = fieldval_box ? fieldval_box : jQuery(el).prev().children().last();\n\t\t\t\tvar newField  = lastField.clone();\n\t\t\t\t\n\t\t\t" . ($image_source ? "" : "\n\t\t\t\tvar has_imagepicker = newField.find('ul.image_picker_selector').length != 0;\n\t\t\t\tvar has_select2     = newField.find('div.select2-container').length != 0;\n\t\t\t\tif (has_imagepicker) newField.find('ul.image_picker_selector').remove();\n\t\t\t\tif (has_select2)     newField.find('div.select2-container').remove();\n\t\t\t\t") . "\n\t\t\t\n\t\t\t\tnewField.find('input.hasvalue').val('');\n\t\t\t\tnewField.find('input.hasvalue').attr('name','" . $elementid . "_'+uniqueRowNum" . $field->id . "+'_hasvalue');\n\t\t\t\tnewField.find('input.hasvalue').attr('id','" . $elementid . "_'+uniqueRowNum" . $field->id . ");\n\t\t\t\t\n\t\t\t\tnewField.find('input.newfile').val('');\n\t\t\t\tnewField.find('input.newfile').attr('name','" . $field->name . "['+uniqueRowNum" . $field->id . "+']');\n\t\t\t\tnewField.find('input.newfile').attr('id','" . $elementid . "_'+uniqueRowNum" . $field->id . "+'_newfile');\n\t\t\t\t\n\t\t\t\tnewField.find('input.originalname').val('');\n\t\t\t\tnewField.find('input.originalname').attr('name','" . $fieldname . "['+uniqueRowNum" . $field->id . "+'][originalname]');\n\t\t\t\tnewField.find('input.originalname').attr('id','" . $elementid . "_'+uniqueRowNum" . $field->id . "+'_originalname');\n\t\t\t\t\n\t\t\t\tnewField.find('.existingname').val('');\n\t\t\t\tnewField.find('.existingname').addClass('no_value_selected');\n\t\t\t\tnewField.find('.existingname').attr('name','" . $fieldname . "['+uniqueRowNum" . $field->id . "+'][existingname]');\n\t\t\t\tnewField.find('.existingname').attr('id','" . $elementid . "_'+uniqueRowNum" . $field->id . "+'_existingname');\n\t\t\t\t\n\t\t\t" . ($image_source ? "" : "\n\t\t\t\tif (has_imagepicker && " . $auto_enable_imgpicker . " ) newField.find('select.image-picker').imagepicker({ hide_select:false, show_label:true });\n\t\t\t\tif (has_select2)  newField.find('select.use_select2_lib').show().select2();\n\t\t\t\t") . "\n\t\t\t\tnewField.find('a.addfile_" . $field->id . "').attr('id','" . $elementid . "_'+uniqueRowNum" . $field->id . "+'_addfile');\n\t\t\t\tnewField.find('a.addfile_" . $field->id . "').attr('href','" . JURI::base(true) . '/index.php?option=com_flexicontent&view=fileselement&tmpl=component&layout=image&filter_secure=M&folder_mode=1&' . (FLEXI_J30GE ? JSession::getFormToken() : JUtility::getToken()) . '=1&field=' . $field->id . '&u_item_id=' . $u_item_id . '&targetid=' . $elementid . "_'+uniqueRowNum" . $field->id . "+'_existingname&thumb_w=" . $thumb_w_s . '&thumb_h=' . $thumb_h_s . '&autoassign=' . $autoassign . "');\n\t\t\t\t\n\t\t\t\t// COPY an preview box\n\t\t\t\tvar img_preview = newField.find('img.preview_image');\n\t\t\t\tvar empty_img   = newField.find('img.preview_image');\n\t\t\t\tvar old_preview = img_preview.length ? img_preview : newField.find('div.empty_image');\n\t\t\t\t\n\t\t\t\tif (old_preview.length)\n\t\t\t\t{\n\t\t\t\t\tvar tmpDiv = jQuery('<div class=\"empty_image empty_image" . $field->id . "\" style=\"height:" . $field->parameters->get('h_s') . "px; width:" . $field->parameters->get('w_s') . "px;\"></div>');\n\t\t\t\t\ttmpDiv.attr('id','" . $elementid . "_'+uniqueRowNum" . $field->id . "+'_preview_image');\n\t\t\t\t\ttmpDiv.insertAfter( old_preview );\n\t\t\t\t\told_preview.remove();\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\tvar imgchange_toggler = newField.find('input.imgchange');\n\t\t\t\tif (imgchange_toggler.length) {\n\t\t\t\t\timgchange_toggler.prop('name','" . $field->name . "['+uniqueRowNum" . $field->id . "+']');\n\t\t\t\t\timgchange_toggler.prop('id','" . $elementid . "_'+uniqueRowNum" . $field->id . "+'_change');\n\t\t\t\t\timgchange_toggler.parent().find('label').prop('for','" . $elementid . "_'+uniqueRowNum" . $field->id . "+'_change');\n\t\t\t\t\t\n\t\t\t\t\tnewField.find('table.img_upload_select').attr('id','" . $field->name . "_upload_select_tbl_'+uniqueRowNum" . $field->id . ");\n\t\t\t\t\tnewField.find('table.img_upload_select').css('display', 'table');\n\t\t\t\t\tnewField.find('input.imgchange').prop('checked', true);\n\t\t\t\t}\n\t\t\t\t\t";
            if ($linkto_url) {
                $js .= "\n\t\t\t\tnewField.find('input.imglink').val('');\n\t\t\t\tnewField.find('input.imglink').attr('name','" . $fieldname . "['+uniqueRowNum" . $field->id . "+'][urllink]');\n\t\t\t\tnewField.find('input.imglink').attr('id','" . $elementid . "_'+uniqueRowNum" . $field->id . "+'_urllink');\n\t\t\t\t\t";
            }
            if ($usealt) {
                $js .= "\n\t\t\t\tnewField.find('input.imgalt').val('" . $default_alt . "');\n\t\t\t\tnewField.find('input.imgalt').attr('name','" . $fieldname . "['+uniqueRowNum" . $field->id . "+'][alt]');\n\t\t\t\tnewField.find('input.imgalt').attr('id','" . $elementid . "_'+uniqueRowNum" . $field->id . "+'_alt');\n\t\t\t\t\t";
            }
            if ($usetitle) {
                $js .= "\n\t\t\t\tnewField.find('input.imgtitle').val('" . $default_title . "');\n\t\t\t\tnewField.find('input.imgtitle').attr('name','" . $fieldname . "['+uniqueRowNum" . $field->id . "+'][title]');\n\t\t\t\tnewField.find('input.imgtitle').attr('id','" . $elementid . "_'+uniqueRowNum" . $field->id . "+'_title');\n\t\t\t\t\t";
            }
            if ($usedesc) {
                $js .= "\n\t\t\t\tnewField.find('textarea.imgdesc').val('" . $default_desc . "');\n\t\t\t\tnewField.find('textarea.imgdesc').attr('name','" . $fieldname . "['+uniqueRowNum" . $field->id . "+'][desc]');\n\t\t\t\t\t";
            }
            if ($usecust1) {
                $js .= "\n\t\t\t\tnewField.find('input.imgcust1').val('" . $default_cust1 . "');\n\t\t\t\tnewField.find('input.imgcust1').attr('name','" . $fieldname . "['+uniqueRowNum" . $field->id . "+'][cust1]');\n\t\t\t\t\t";
            }
            if ($usecust2) {
                $js .= "\n\t\t\t\tnewField.find('input.imgcust2').val('" . $default_cust2 . "');\n\t\t\t\tnewField.find('input.imgcust2').attr('name','" . $fieldname . "['+uniqueRowNum" . $field->id . "+'][cust2]');\n\t\t\t\t\t";
            }
            // Add new field to DOM
            $js .= "\n\t\t\t\tlastField ?\n\t\t\t\t\t(insert_before ? newField.insertBefore( lastField ) : newField.insertAfter( lastField ) ) :\n\t\t\t\t\tnewField.appendTo( jQuery('#sortables_" . $field->id . "') ) ;\n\t\t\t\tif (remove_previous) lastField.remove();\n\t\t\t\t\n\t\t\t\t// Add jQuery modal window to the select image file button\n\t\t\t\tjQuery('a.addfile_" . $field->id . "').each(function(index, value) {\n\t\t\t\t\tjQuery(this).on('click', function() {\n\t\t\t\t\t\tvar url = jQuery(this).attr('href');\n\t\t\t\t\t\tfc_field_dialog_handle_" . $field->id . " = fc_showDialog(url, 'fc_modal_popup_container');\n\t\t\t\t\t\treturn false;\n\t\t\t\t\t});\n\t\t\t\t});\n\t\t\t\t";
            // Add new element to sortable objects (if field not in group)
            if (!$use_ingroup) {
                $js .= "\n\t\t\t\tjQuery('#sortables_" . $field->id . "').sortable({\n\t\t\t\t\thandle: '.fcfield-drag-handle',\n\t\t\t\t\tcontainment: 'parent',\n\t\t\t\t\ttolerance: 'pointer'\n\t\t\t\t});\n\t\t\t\t";
            }
            // Show new field, increment counters
            $js .= "\n\t\t\t\t//newField.fadeOut({ duration: 400, easing: 'swing' }).fadeIn({ duration: 200, easing: 'swing' });\n\t\t\t\tif (scroll_visible) fc_scrollIntoView(newField, 1);\n\t\t\t\tif (animate_visible) newField.css({opacity: 0.1}).animate({ opacity: 1 }, 800);\n\t\t\t\t\n\t\t\t\trowCount" . $field->id . "++;       // incremented / decremented\n\t\t\t\tuniqueRowNum" . $field->id . "++;   // incremented only\n\t\t\t}\n\n\t\t\tfunction deleteField" . $field->id . "(el, groupval_box, fieldval_box)\n\t\t\t{\n\t\t\t\t// Find field value container\n\t\t\t\tvar row = fieldval_box ? fieldval_box : jQuery(el).closest('li');\n\t\t\t\t\n\t\t\t\t// When removing a field value we need to check if it had value and decrement the value counter\n\t\t\t\tvar originalfftag = 'input.originalname';\n\t\t\t\tvar existingfftag = '" . ($image_source ? "input" : "select") . "' + '.existingname';\n\t\t\t\tvar originalname = row.find( originalfftag ).val();\n\t\t\t\tvar existingname = row.find( existingfftag ).val();\n\t\t\t\t\n\t\t\t\tif ( originalname != '' || existingname != '' )\n\t\t\t\t{\n\t\t\t\t\t// A non-empty container is being removed ... get counter (which is optionally used as 'required' form element and empty it if is 1, or decrement if 2 or more)\n\t\t\t\t\tvar valcounter = document.getElementById('" . $field->name . "');\n\t\t\t\t\tvalcounter.value = ( !valcounter.value || valcounter.value=='1' )  ?  ''  :  parseInt(valcounter.value) - 1;\n\t\t\t\t\t//if(window.console) window.console.log ('valcounter.value: ' + valcounter.value);\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\t// Add empty container if last element, instantly removing the given field value container\n\t\t\t\tif(rowCount" . $field->id . " == 1)\n\t\t\t\t\taddField" . $field->id . "(null, groupval_box, row, {remove_previous: 1, scroll_visible: 0, animate_visible: 0});\n\t\t\t\t\n\t\t\t\t// Remove if not last one, if it is last one, we issued a replace (copy,empty new,delete old) above\n\t\t\t\tif(rowCount" . $field->id . " > 1) {\n\t\t\t\t\t// Destroy the remove/add/etc buttons, so that they are not reclicked, while we do the hide effect (before DOM removal of field value)\n\t\t\t\t\trow.find('.fcfield-delvalue').remove();\n\t\t\t\t\trow.find('.fcfield-insertvalue').remove();\n\t\t\t\t\trow.find('.fcfield-drag-handle').remove();\n\t\t\t\t\t// Do hide effect then remove from DOM\n\t\t\t\t\trow.slideUp(400, function(){ this.remove(); });\n\t\t\t\t\trowCount" . $field->id . "--;\n\t\t\t\t}\n\t\t\t}\n\t\t\t";
            $css .= '
			ul#sortables_' . $field->id . ' {
				float:left; margin:0px; padding:0px;
				list-style:none; white-space:normal;
			}
			ul#sortables_' . $field->id . ' li {
				' . ($none_props ? 'clear:none; white-space:normal;' : '') . '
				float:left;
				display: block;
				list-style: none;
				position: relative;  .' . '
			}
			.fcfieldval_container_' . $field->id . ' input { cursor:text; }
			.fcfieldval_container_' . $field->id . ' .fcimg_preview_box { min-width:' . ($thumb_w_s + 6) . 'px; min-height:' . ($thumb_h_s + 8) . 'px; }
			';
            $remove_button = '<span class="fcfield-delvalue" title="' . JText::_('FLEXI_REMOVE_VALUE') . '" onclick="deleteField' . $field->id . '(this);"></span>';
            $move2 = '<span class="fcfield-drag-handle" title="' . JText::_('FLEXI_CLICK_TO_DRAG') . '"></span>';
            $add_here = '';
            $add_here .= $add_position == 2 || $add_position == 3 ? '<span class="fcfield-insertvalue fc_before" onclick="addField' . $field->id . '(null, jQuery(this).closest(\'ul\'), jQuery(this).closest(\'li\'), {insert_before: 1});" title="' . JText::_('FLEXI_ADD_BEFORE') . '"></span> ' : '';
            $add_here .= $add_position == 1 || $add_position == 3 ? '<span class="fcfield-insertvalue fc_after"  onclick="addField' . $field->id . '(null, jQuery(this).closest(\'ul\'), jQuery(this).closest(\'li\'), {insert_before: 0});" title="' . JText::_('FLEXI_ADD_AFTER') . '"></span> ' : '';
        } else {
            $remove_button = '';
            $move2 = '';
            $add_here = '';
            $js .= '';
            $css .= '';
        }
        // Common JS/CSS
        $image_folder = JURI::root(true) . '/' . $dir_url;
        $js .= "\n\t\t\tvar fc_db_img_path='" . $image_folder . "';\n\t\t\tfunction qmAssignFile" . $field->id . "(tagid, file, file_url, action)\n\t\t\t{\n\t\t\t\t// Get TAG ID of the main form element of this field\n\t\t\t\tvar action = typeof action!== 'undefined' ? action : '0';\n\t\t\t\tvar ff_suffix = (tagid.indexOf('_existingname') > -1) ? '_existingname' : '_newfile';\n\t\t\t\tvar elementid = tagid.replace(ff_suffix,'');\n\t\t\t\t\n\t\t\t\t// Get current value of new / existing filename fields\n\t\t\t\tvar hasvalue_obj = jQuery('#' + elementid );\n\t\t\t\tvar original_obj = jQuery('#' + elementid + '_originalname' );\n\t\t\t\tvar existing_obj = jQuery('#' + elementid + '_existingname' );\n\t\t\t\tvar existingAllowed = existing_obj.length != 0;\n\t\t\t\t\n\t\t\t\tvar originalname = original_obj.val();\n\t\t\t\tvar existingname = existingAllowed ? existing_obj.val() : '';\n\t\t\t\t\n\t\t\t\t// a flag if file URL was given\n\t\t\t\tvar fileUrlGiven = file_url!='';\n\t\t\t\t\n\t\t\t\tif (file=='')  // DB-mode\n\t\t\t\t{\n\t\t\t\t\tvar newfilename  = jQuery('#' + elementid + '_newfile' ).val();\n\t\t\t\t\t\n\t\t\t\t\t// Assigning newfile\n\t\t\t\t\tif ( ff_suffix == '_newfile' )\n\t\t\t\t\t{\n\t\t\t\t\t\tif ( jQuery('#' + elementid + '_newfile' ).hasClass('no_value_selected') && newfilename!='' ) {\n\t\t\t\t\t\t\tvar modify = ( originalname=='' && existingname=='' ) ? 1 : 0;\n\t\t\t\t\t\t\tjQuery('#' + elementid + '_newfile' ).removeClass('no_value_selected');\n\t\t\t\t\t\t} else if ( !jQuery('#' + elementid + '_newfile' ).hasClass('no_value_selected') && newfilename=='' ) {\n\t\t\t\t\t\t\tvar modify = -1;\n\t\t\t\t\t\t\tjQuery('#' + elementid + '_newfile' ).addClass('no_value_selected');\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tvar modify = 0;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (existingAllowed) existing_obj.addClass('no_value_selected').val('');\n\t\t\t\t\t}\n\t\t\t\t\t\n\t\t\t\t\t// Assigning existingfile\n\t\t\t\t\telse\n\t\t\t\t\t{\n\t\t\t\t\t\t//alert('existingAllowed: ' + existingAllowed + ', existingname: ' + existingname + ', no_value_selected: ' + (existing_obj.hasClass('no_value_selected') ? 'yes' : 'no'));\n\t\t\t\t\t\tif ( existingAllowed && existingname!='' && existing_obj.hasClass('no_value_selected') ) {\n\t\t\t\t\t\t\tvar modify = ( originalname=='' ) ? 1 : 0;\n\t\t\t\t\t\t\texisting_obj.removeClass('no_value_selected');\n\t\t\t\t\t\t} else if ( existingAllowed && existingname=='' && !existing_obj.hasClass('no_value_selected') ) {\n\t\t\t\t\t\t\tvar modify = -1;\n\t\t\t\t\t\t\texisting_obj.addClass('no_value_selected');\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tvar modify = 0;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tjQuery('#' + elementid + '_newfile' ).addClass('no_value_selected').val('');\n\t\t\t\t\t}\n\t\t\t\t\t\n\t\t\t\t\t// Increment/decrement the form field used as value counter, we do not use ZERO in case of decrement, instead we set to empty string, so that is-required validation works\n\t\t\t\t\tvar valcounter = document.getElementById('" . $field->name . "');\n\t\t\t\t\tif (modify>0)\n\t\t\t\t\t{\n\t\t\t\t\t\tif ( typeof valcounter.value === 'undefined' || valcounter.value=='' ) valcounter.value = '1';\n\t\t\t\t\t\telse valcounter.value = parseInt(valcounter.value) + modify;\n\t\t\t\t\t\thasvalue_obj.val('1');  // value assigned\n\t\t\t\t\t}\n\t\t\t\t\t\n\t\t\t\t\telse if (modify<0)\n\t\t\t\t\t{\n\t\t\t\t\t\tif ( valcounter.value=='1' ) valcounter.value = '';\n\t\t\t\t\t\telse valcounter.value = parseInt(valcounter.value) + modify;\n\t\t\t\t\t\thasvalue_obj.val('');  // value de-assigned, (or ? fieldgroup is being deleted)\n\t\t\t\t\t}\n\t\t\t\t\t\n\t\t\t\t} else {  // Folder mode\n\t\t\t\t\t\n\t\t\t\t\tif ( originalname=='' && existingname=='' ) {\n\t\t\t\t\t\t// Increment/Make non-empty the form field used as value counter, so that is-required validation works\n\t\t\t\t\t\tvar valcounter = document.getElementById('" . $field->name . "');\n\t\t\t\t\t\tif ( valcounter.value=='' ) valcounter.value = '1';\n\t\t\t\t\t\telse valcounter.value = parseInt(valcounter.value) + 1;\n\t\t\t\t\t}\n\t\t\t\t\thasvalue_obj.val('1');  // value assigned\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\t//if(window.console) window.console.log(valcounter.value);\n\t\t\t\t\n\t\t\t\tvar prv_obj = jQuery('#' + elementid + '_preview_image' );\n\t\t\t\t\n\t\t\t\t// DB-Mode\n\t\t\t\tif (file == '') {\n\t\t\t\t\tvar imgdel_box = jQuery( '#' + elementid + '_imgdelete' );\n\t\t\t\t\t//imgdel_box.remove();\n\t\t\t\t\timgdel_box.hide();\n\t\t\t\t\tif (originalname) {\n\t\t\t\t\t\timgdel_box.find('input').prop('type', 'text');\n\t\t\t\t\t\timgdel_box.find('input').val(originalname);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\t// Folder-Mode\n\t\t\t\tif (file != '' && existingAllowed)  existing_obj.val(file);\n\t\t\t\t\n\t\t\t\t// DB-Mode, Folder-Mode empty original value\n\t\t\t\toriginal_obj.val('');\n\t\t\t\t\n\t\t\t\tif (prv_obj) {\n\t\t\t\t\tpreview_msg = '<span id=\"'+elementid+'_preview_msg\"></span>';\n\t\t\t\t\tif (file || (fileUrlGiven && existingAllowed && !existing_obj.hasClass('no_value_selected')) ) {\n\t\t\t\t\t\tvar preview_container = '<img class=\"preview_image\" id=\"'+elementid+'_preview_image\" src=\"'+file_url+'\" style=\"border: 1px solid silver; float:left;\" alt=\"Preview image\" />';\n\t\t\t\t\t} else if (action!='0') {\n\t\t\t\t\t\tvar preview_container = '<div class=\"empty_image empty_image" . $field->id . "\" id=\"'+elementid+'_preview_image\" style=\"height:" . $field->parameters->get('h_s') . "px; width:" . $field->parameters->get('w_s') . "px;\">';\n\t\t\t\t\t} else {\n\t\t\t\t\t\tvar preview_container = '<img class=\"preview_image\" id=\"'+elementid+'_preview_image\" src=\"\" style=\"border: 1px solid silver; float:left;\" alt=\"Preview image\" />';\n\t\t\t\t\t}\n\t\t\t\t\t\n\t\t\t\t\tvar tmpDiv = jQuery(preview_container);\n\t\t\t\t\ttmpDiv.insertAfter( prv_obj );\n\t\t\t\t\tvar tmpDiv = jQuery(preview_msg);\n\t\t\t\t\ttmpDiv.insertAfter( prv_obj );\n\t\t\t\t\tprv_obj.remove();\n\t\t\t\t\t\n\t\t\t\t\tif (file || (fileUrlGiven && existingAllowed && !existing_obj.hasClass('no_value_selected')) || action!='0') {\n\t\t\t\t\t} else {\n\t\t\t\t\t\tfc_loadImagePreview(tagid, elementid+'_preview_image', elementid+'_preview_msg', " . $thumb_w_s . ", " . '0' . ");\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\t// Close dialog if open,  action=='1'  means do not closing modal popup\n\t\t\t\tif (action!='1' && fc_field_dialog_handle_" . $field->id . ")\n\t\t\t\t\tfc_field_dialog_handle_" . $field->id . ".dialog('close');\n\t\t\t}\n\t\t";
        $css .= '
			table.fcfield' . $field->id . '.img_upload_select li { min-height:' . ($thumb_h_s + 56) . 'px; }
			table.fcfield' . $field->id . '.img_upload_select ul { height:' . ($thumb_h_s + 96) . 'px; }
			table.fcfield' . $field->id . '.img_upload_select ul { width:' . 2 * ($thumb_w_s + 64) . 'px; }
			table.fcfield' . $field->id . '.img_upload_select ul.image_picker_selector { min-height: 400px; max-height: 600px; height: unset; width:100%; box-sizing: border-box; }
		';
        if ($js) {
            $document->addScriptDeclaration($js);
        }
        if ($css) {
            $document->addStyleDeclaration($css);
        }
        flexicontent_html::loadFramework('flexi-lib');
        // Add jQuery modal window to the select image file button, the container will be created if it does not exist already
        if ($image_source) {
            $js = "\n\t\t\tjQuery(document).ready(function() {\n\t\t\t\tjQuery('a.addfile_" . $field->id . "').each(function(index, value) {\n\t\t\t\t\tjQuery(this).on('click', function() {\n\t\t\t\t\t\tvar url = jQuery(this).attr('href');\n\t\t\t\t\t\tfc_field_dialog_handle_" . $field->id . " = fc_showDialog(url, 'fc_modal_popup_container');\n\t\t\t\t\t\treturn false;\n\t\t\t\t\t});\n\t\t\t\t});\n\t\t\t});\n\t\t\t";
            if ($js) {
                $document->addScriptDeclaration($js);
            }
        } else {
            $select = $existing_imgs ? $this->buildSelectList($field) : '';
        }
        $class = ' class="' . $required . ' "';
        $onchange = ' onchange="';
        $onchange .= " qmAssignFile" . $field->id . "(this.id, '', '');";
        $js_submit = FLEXI_J16GE ? "Joomla.submitbutton('items.apply')" : "submitbutton('apply')";
        $onchange .= $autoupload && $app->isAdmin() ? $js_submit : '';
        $onchange .= ' "';
        $i = -1;
        // Count DB values (may contain invalid entries)
        $n = 0;
        // Count sortable records added (the verified values or a single empty record if no good values)
        $count_vals = 0;
        // Count non-empty sortable records added
        $image_added = false;
        $skipped_vals = array();
        $uploadLimitsTxt = $this->getUploadLimitsTxt($field);
        foreach ($field->value as $value) {
            // Compatibility for unserialized values (e.g. reload user input after form validation error) or for NULL values in a field group
            if (!is_array($value)) {
                $v = !empty($value) ? @unserialize($value) : false;
                $value = $v !== false || $v === 'b:0;' ? $v : array('originalname' => $value);
            }
            $i++;
            $fieldname_n = $fieldname . '[' . $n . ']';
            $elementid_n = $elementid . '_' . $n;
            $image_name = !empty($value['existingname']) ? $value['existingname'] : trim(@$value['originalname']);
            // existingname should be present only via form reloading
            // Check and rebuild thumbnails if needed
            $rebuild_res = !empty($value['existingname']) ? true : plgFlexicontent_fieldsImage::rebuildThumbs($field, $value, $item);
            // Check if rebuilding thumbnails failed (e.g. file has been deleted)
            if (!$rebuild_res) {
                // For non-empty value set a message when we have examined all values
                if ($image_name) {
                    $skipped_vals[] = $image_name;
                }
                // Skip current value but add and an empty image container if :
                // (a) no other image exists or  (b) field is in a group
                if (!$use_ingroup && ($image_added || $i + 1 < count($field->value))) {
                    continue;
                } else {
                    // 1st value or empty value for fieldgroup position
                    $image_name = '';
                }
            } else {
                $count_vals++;
            }
            if ($image_source) {
                $linkfsel = JURI::base(true) . '/index.php?option=com_flexicontent&amp;view=fileselement&amp;tmpl=component&amp;layout=image&amp;filter_secure=M&amp;folder_mode=1' . '&amp;field=' . $field->id . '&amp;u_item_id=' . $u_item_id . '&amp;targetid=' . $elementid_n . "_existingname&amp;thumb_w={$thumb_w_s}&amp;thumb_h={$thumb_h_s}&amp;autoassign=" . $autoassign . '&amp;' . (FLEXI_J30GE ? JSession::getFormToken() : JUtility::getToken()) . '=1';
                $_prompt_txt = JText::_('FLEXI_SELECT_IMAGE');
                $select = '
				<input class="existingname fcfield_textval" id="' . $elementid_n . '_existingname" name="' . $fieldname_n . '[existingname]" value="' . $image_name . '" readonly="readonly" style="float:none;" />
				' . ($none_props ? '<br/>' : '') . '
				<span class="fcfield-button-add">
					<a class="addfile_' . $field->id . '" id="' . $elementid_n . '_addfile" title="' . $_prompt_txt . '" href="' . $linkfsel . '" >' . $_prompt_txt . '
					</a>
				</span>';
            }
            // Add current image or add an empty image container
            $delete = $remove = $change = '';
            if ($image_name) {
                if (!$multiple) {
                    $remove_disabled = '';
                    if (!$image_source) {
                        $canDeleteImage = $this->canDeleteImage($field, $image_name, $item);
                        $delete_disabled = $canDeleteImage ? '' : ' disabled="disabled"';
                        $delete = '<div id="' . $elementid_n . '_imgdelete" class="imgdelete">';
                        $delete .= ' <input class="imgdelete" type="checkbox" name="' . $fieldname_n . '[delete]" id="' . $elementid_n . '_delete" value="1"' . $delete_disabled . ' />';
                        $delete .= ' <label for="' . $elementid_n . '_delete">' . JText::_('FLEXI_FIELD_DELETE_FILE') . '</label>';
                        $delete .= '</div>';
                        $remove_disabled = $always_allow_removal ? '' : ($canDeleteImage ? ' disabled="disabled"' : '');
                    }
                    $remove = '<div id="' . $elementid_n . '_imgremove" class="imgremove">';
                    $remove .= ' <input class="imgremove" type="checkbox" name="' . $fieldname_n . '[remove]" id="' . $elementid_n . '_remove" value="1"' . $remove_disabled . ' />';
                    $remove .= ' <label style="display:inline;" for="' . $elementid_n . '_remove">' . JText::_('FLEXI_FIELD_REMOVE_VALUE') . '</label>';
                    $remove .= '</div>';
                }
                $originalname = '<input name="' . $fieldname_n . '[originalname]" id="' . $elementid_n . '_originalname" type="hidden" class="originalname" value="' . $value['originalname'] . '" />';
                if ($use_ingroup) {
                    $originalname .= '<input name="' . $elementid_n . '_hasvalue" id="' . $elementid_n . '" type="hidden" class="hasvalue ' . ($use_ingroup ? $required : '') . '" value="' . $value['originalname'] . '" />';
                }
                if (!empty($image_name)) {
                    $img_link = JURI::root(true) . '/' . $dir_url;
                    $img_link .= $image_source ? '/item_' . $u_item_id . '_field_' . $field->id : "";
                    $img_link .= $item->id ? '/s_' . $extra_prefix . $image_name : '/original/' . $image_name;
                    if (isset($value['existingname'])) {
                        $img_link = str_replace('\\', '/', $img_link);
                        $img_link = JURI::root() . 'components/com_flexicontent/librairies/phpthumb/phpThumb.php?src=' . $img_link . '&amp;w=120&amp;h=90';
                    }
                } else {
                    $img_link = '';
                }
                $imgpreview = '<img class="preview_image" id="' . $elementid_n . '_preview_image" src="' . $img_link . '" style="border: 1px solid silver; float:left;" alt="Preview image" />';
            } else {
                $originalname = '<input name="' . $fieldname_n . '[originalname]" id="' . $elementid_n . '_originalname" type="hidden" class="originalname" value="" />';
                if ($use_ingroup) {
                    $originalname .= '<input name="' . $elementid_n . '_hasvalue" id="' . $elementid_n . '" type="hidden" class="hasvalue ' . ($use_ingroup ? $required : '') . '" value="" />';
                }
                $imgpreview = '<div class="empty_image empty_image' . $field->id . '" id="' . $elementid_n . '_preview_image" style="height:' . $field->parameters->get('h_s') . 'px; width:' . $field->parameters->get('w_s') . 'px;"></div>';
            }
            if (!$image_source && !$imgsel_visible) {
                $change .= ' <input class="imgchange" style="display:none;" type="checkbox" name="' . $fieldname_n . '[change]" id="' . $elementid_n . '_change" onchange="fx_toggle_upload_select_tbl(this)" value="1" ' . ($image_name ? '' : ' checked="checked" ') . '/>';
                $change .= ' <span></span><label class="fcfield-button" style="margin: 0px 0px 4px 0px !important;" for="' . $elementid_n . '_change">' . JText::_('FLEXI_TOGGLE_IMAGE_SELECTOR') . '</label>';
            }
            if ($linkto_url) {
                $urllink = '<tr>
					<td class="key">' . JText::_('FLEXI_FIELD_LINKTO_URL') . '</td>
					<td><input class="imglink" size="40" name="' . $fieldname_n . '[urllink]" value="' . (isset($value['urllink']) ? $value['urllink'] : '') . '" type="text" /></td>
				</tr>';
            }
            if ($usealt) {
                $alt = '<tr>
					<td class="key">' . JText::_('FLEXI_FIELD_ALT') . '</td>
					<td><input class="imgalt" size="40" name="' . $fieldname_n . '[alt]" value="' . (isset($value['alt']) ? $value['alt'] : $default_alt) . '" type="text" /></td>
				</tr>';
            }
            if ($usetitle) {
                $title = '<tr>
					<td class="key">' . JText::_('FLEXI_FIELD_TITLE') . ': (' . JText::_('FLEXI_FIELD_TOOLTIP') . ')</td>
					<td><input class="imgtitle" size="40" name="' . $fieldname_n . '[title]" value="' . (isset($value['title']) ? $value['title'] : $default_title) . '" type="text" /></td>
				</tr>';
            }
            if ($usedesc) {
                $desc = '<tr>
					<td class="key">' . JText::_('FLEXI_FIELD_LONGDESC') . ': <br/>(' . JText::_('FLEXI_FIELD_TOOLTIP') . ')</td>
					<td><textarea class="imgdesc" name="' . $fieldname_n . '[desc]" rows="3" cols="28" >' . (isset($value['desc']) ? $value['desc'] : $default_desc) . '</textarea></td>
				</tr>';
            }
            if ($usecust1) {
                $cust1 = '<tr>
					<td class="key">' . JText::_('FLEXI_FIELD_IMG_CUST1') . '</td>
					<td><input class="imgcust1" size="40" name="' . $fieldname_n . '[cust1]" value="' . (isset($value['cust1']) ? $value['cust1'] : $default_cust1) . '" type="text" /></td>
				</tr>';
            }
            if ($usecust2) {
                $cust2 = '<tr>
					<td class="key">' . JText::_('FLEXI_FIELD_IMG_CUST2') . '</td>
					<td><input class="imgcust2" size="40" name="' . $fieldname_n . '[cust2]" value="' . (isset($value['cust2']) ? $value['cust2'] : $default_cust2) . '" type="text" /></td>
				</tr>';
            }
            $curr_select = $select ? str_replace('__FORMFLDNAME__', $fieldname_n . '[existingname]', $select) : '';
            $curr_select = $select ? str_replace('__FORMFLDID__', $elementid_n . '_existingname', $curr_select) : '';
            $field->html[] = '
			' . ($image_source ? $curr_select : $change) . '
			' . ($multiple ? '
				' . (!$none_props ? '<div class="fcclear"></div>' : '') . '
				<div class="nowrap_box">
				' . ($use_ingroup ? '' : $move2) . '
				' . ($use_ingroup ? '' : $remove_button) . '
				' . ($use_ingroup || !$add_position ? '' : $add_here) . '
				</div>
				<div class="fcclear"></div>
				' : '') . '
			<div class="fcimg_preview_box" style="float:left!important; clear:none!important; margin-right:5px!important;">
				' . $imgpreview . '
				' . $originalname . '
				<div style="float:left; clear:both;" class="imgactions_box">
					' . ($remove ? $remove : '') . '
					' . ($delete ? $delete : '') . '
				</div>
			</div>
			' . ($linkto_url || $usealt || $usetitle || $usedesc || $usecust1 || $usecust2 ? '
			<div style="float:left; clear:none;" class="img_value_props">
				<table class="admintable"><tbody>
					' . @$urllink . '
					' . @$alt . '
					' . @$title . '
					' . @$desc . '
					' . @$cust1 . '
					' . @$cust2 . '
				</tbody></table>
			</div>' : '') . (!$image_source ? '
				<table class="admintable fcfield' . $field->id . ' img_upload_select" id="' . $field->name . '_upload_select_tbl_' . $n . '" style="' . ($image_name && $imgsel_visible == 0 ? "display:none;" : "") . ($multiple ? '' : 'width:auto;') . '" >
				<tbody>
					<tr class="img_newfile_row">
						' . ($curr_select ? '<td class="key fckey_high">' . JText::_('FLEXI_FIELD_NEWFILE') . ':</td>' : '') . '
						<td style="white-space: normal;">' . '<input name="' . $field->name . '[' . $n . ']" id="' . $elementid_n . '_newfile" class="newfile no_value_selected" ' . $onchange . ' type="file" /><br/>' . $uploadLimitsTxt . '<br/><span class="label label-info">' . JText::_('FLEXI_FIELD_ALLOWEDEXT') . '</span>' . '<span style="margin-left:12px;">' . str_replace(",", ", ", $field->parameters->get('upload_extensions')) . '</span>
						</td>
					</tr>
					' . ($curr_select ? '
					<tr class="img_existingfile_row">
						<td class="key fckey_high">' . JText::_(!$image_source ? 'FLEXI_FIELD_EXISTINGFILE' : 'FLEXI_SELECT') . ':</td>
						<td>' . $curr_select . '</td>
					</tr>
					' : '') . '
				</tbody></table>
			' : '');
            $n++;
            $image_added = true;
            if (!$multiple) {
                break;
            }
            // multiple values disabled, break out of the loop, not adding further values even if the exist
        }
        if ($use_ingroup) {
            // do not convert the array to string if field is in a group
        } else {
            if ($multiple) {
                // handle multiple records
                $field->html = '<li class="' . $value_classes . '">' . implode('</li><li class="' . $value_classes . '">', $field->html) . '</li>';
                $field->html = '<ul class="fcfield-sortables" id="sortables_' . $field->id . '">' . $field->html . '</ul>';
                if (!$add_position) {
                    $field->html .= '<span class="fcfield-addvalue fccleared" onclick="addField' . $field->id . '(this);" title="' . JText::_('FLEXI_ADD_TO_BOTTOM') . '"></span>';
                }
            } else {
                // handle single values
                $field->html = '<div class="fcfieldval_container valuebox fcfieldval_container_' . $field->id . '">' . $field->html[0] . '</div>';
            }
        }
        // This is field HTML that is created regardless of values
        $non_value_html = '<input id="' . $field->name . '" class="' . ($use_ingroup ? '' : $required) . '" type="hidden" name="__fcfld_valcnt__[' . $field->name . ']" value="' . ($count_vals ? $count_vals : '') . '" />';
        if ($use_ingroup) {
            $field->html[-1] = $non_value_html;
        } else {
            $field->html .= $non_value_html;
        }
        if (count($skipped_vals)) {
            $app->enqueueMessage(JText::sprintf('FLEXI_FIELD_EDIT_VALUES_SKIPPED', $field->label, implode(',', $skipped_vals)), 'notice');
        }
    }
Пример #9
0
    function onDisplayField(&$field, &$item)
    {
        // execute the code only if the field type match the plugin type
        if (!in_array($field->field_type, self::$field_types)) {
            return;
        }
        $field->label = JText::_($field->label);
        // initialize framework objects and other variables
        $document = JFactory::getDocument();
        // some parameter shortcuts
        $default_value_use = $field->parameters->get('default_value_use', 0);
        $default_value = $item->version == 0 || $default_value_use > 0 ? $field->parameters->get('default_value', '') : '';
        $maxlength = (int) $field->parameters->get('maxlength', 0);
        $size = (int) $field->parameters->get('size', 30);
        $multiple = $field->parameters->get('allow_multiple', 1);
        $max_values = (int) $field->parameters->get('max_values', 0);
        $required = $field->parameters->get('required', 0);
        $required = $required ? ' required' : '';
        // add setMask function on the document.ready event
        $inputmask = $field->parameters->get('inputmask', false);
        $custommask = $field->parameters->get('custommask', false);
        static $inputmask_added = false;
        if ($inputmask && !$inputmask_added) {
            $inputmask_added = true;
            flexicontent_html::loadFramework('inputmask');
        }
        // create extra HTML TAG parameters for the text form field
        $attribs = $field->parameters->get('extra_attributes', '');
        if ($maxlength) {
            $attribs .= ' maxlength="' . $maxlength . '" ';
        }
        // Initialise property with default value
        if (!$field->value) {
            $field->value = array();
            $field->value[0] = JText::_($default_value);
        } else {
            for ($n = 0; $n < count($field->value); $n++) {
                $field->value[$n] = htmlspecialchars($field->value[$n], ENT_QUOTES, 'UTF-8');
            }
        }
        // Field name and HTML TAG id
        $fieldname = FLEXI_J16GE ? 'custom[' . $field->name . '][]' : $field->name . '[]';
        $elementid = FLEXI_J16GE ? 'custom_' . $field->name : $field->name;
        $js = "";
        if ($multiple) {
            if (!FLEXI_J16GE) {
                $document->addScript(JURI::root(true) . '/components/com_flexicontent/assets/js/sortables.js');
            }
            // Add the drag and drop sorting feature
            $js .= "\r\n\t\t\tjQuery(document).ready(function(){\r\n\t\t\t\tjQuery('#sortables_" . $field->id . "').sortable({\r\n\t\t\t\t\thandle: '.fcfield-drag',\r\n\t\t\t\t\tcontainment: 'parent',\r\n\t\t\t\t\ttolerance: 'pointer'\r\n\t\t\t\t});\r\n\t\t\t});\r\n\t\t\t";
            if ($max_values) {
                FLEXI_J16GE ? JText::script("FLEXI_FIELD_MAX_ALLOWED_VALUES_REACHED", true) : fcjsJText::script("FLEXI_FIELD_MAX_ALLOWED_VALUES_REACHED", true);
            }
            $js .= "\r\n\t\t\tvar uniqueRowNum" . $field->id . "\t= " . count($field->value) . ";  // Unique row number incremented only\r\n\t\t\tvar rowCount" . $field->id . "\t= " . count($field->value) . ";      // Counts existing rows to be able to limit a max number of values\r\n\t\t\tvar maxValues" . $field->id . " = " . $max_values . ";\r\n\r\n\t\t\tfunction addField" . $field->id . "(el) {\r\n\t\t\t\tif((rowCount" . $field->id . " >= maxValues" . $field->id . ") && (maxValues" . $field->id . " != 0)) {\r\n\t\t\t\t\talert(Joomla.JText._('FLEXI_FIELD_MAX_ALLOWED_VALUES_REACHED') + maxValues" . $field->id . ");\r\n\t\t\t\t\treturn 'cancel';\r\n\t\t\t\t}\r\n\t\t\t\t\r\n\t\t\t\tvar thisField \t = jQuery(el).prev().children().last();\r\n\t\t\t\tvar thisNewField = thisField.clone();\r\n\t\t\t\t\r\n\t\t\t\tjQuery(thisNewField).find('input').first().val('');  /* First element is the value input field, second is e.g remove button */\r\n\r\n\t\t\t\tvar has_inputmask = jQuery(thisNewField).find('input.has_inputmask').length != 0;\r\n\t\t\t\tif (has_inputmask)  jQuery(thisNewField).find('input.has_inputmask').inputmask();\r\n\t\t\t\t\r\n\t\t\t\tvar has_select2 = jQuery(thisNewField).find('div.select2-container').length != 0;\r\n\t\t\t\tif (has_select2) {\r\n\t\t\t\t\tjQuery(thisNewField).find('div.select2-container').remove();\r\n\t\t\t\t\tjQuery(thisNewField).find('select.use_select2_lib').select2();\r\n\t\t\t\t}\r\n\t\t\t\t\r\n\t\t\t\tjQuery(thisNewField).css('display', 'none');\r\n\t\t\t\tjQuery(thisNewField).insertAfter( jQuery(thisField) );\r\n\r\n\t\t\t\tvar input = jQuery(thisNewField).find('input').first();\r\n\t\t\t\tinput.attr('id', '" . $elementid . "_'+uniqueRowNum" . $field->id . ");\r\n\t\t\t\t";
            if ($field->field_type == 'textselect') {
                $js .= "\r\n\t\t\t\tthisNewField.parent().find('select.fcfield_textselval').val('');\r\n\t\t\t\t";
            }
            $js .= "\r\n\t\t\t\tjQuery('#sortables_" . $field->id . "').sortable({\r\n\t\t\t\t\thandle: '.fcfield-drag',\r\n\t\t\t\t\tcontainment: 'parent',\r\n\t\t\t\t\ttolerance: 'pointer'\r\n\t\t\t\t});\r\n\t\t\t\t\r\n\t\t\t\tjQuery(thisNewField).show('slideDown');\r\n\t\t\t\t\r\n\t\t\t\trowCount" . $field->id . "++;       // incremented / decremented\r\n\t\t\t\tuniqueRowNum" . $field->id . "++;   // incremented only\r\n\t\t\t}\r\n\r\n\t\t\tfunction deleteField" . $field->id . "(el)\r\n\t\t\t{\r\n\t\t\t\tif(rowCount" . $field->id . " <= 1) return;\r\n\t\t\t\tvar row = jQuery(el).closest('li');\r\n\t\t\t\tjQuery(row).hide('slideUp', function() { this.remove(); } );\r\n\t\t\t\trowCount" . $field->id . "--;\r\n\t\t\t}\r\n\t\t\t";
            $css = '
			#sortables_' . $field->id . ' { float:left; margin: 0px; padding: 0px; list-style: none; white-space: nowrap; }
			#sortables_' . $field->id . ' li {
				clear: both;
				display: block;
				list-style: none;
				height: auto;
				position: relative;
			}
			#sortables_' . $field->id . ' li.sortabledisabled {
				background : transparent url(components/com_flexicontent/assets/images/move3.png) no-repeat 0px 1px;
			}
			#sortables_' . $field->id . ' li input { cursor: text;}
			#add' . $field->name . ' { margin-top: 5px; clear: both; display:block; }
			#sortables_' . $field->id . ' li .admintable { text-align: left; }
			#sortables_' . $field->id . ' li:only-child span.fcfield-drag, #sortables_' . $field->id . ' li:only-child input.fcfield-button { display:none; }
			';
            $remove_button = '<input class="fcfield-button" type="button" value="' . JText::_('FLEXI_REMOVE_VALUE') . '" onclick="deleteField' . $field->id . '(this);" />';
            $move2 = '<span class="fcfield-drag">' . JHTML::image(JURI::base() . 'components/com_flexicontent/assets/images/move2.png', JText::_('FLEXI_CLICK_TO_DRAG')) . '</span>';
        } else {
            $remove_button = '';
            $move2 = '';
            $js = '';
            $css = '';
        }
        // Drop-Down select for textselect field type
        if ($field->field_type == 'textselect') {
            static $select2_added = false;
            if (!$select2_added) {
                $select2_added = true;
                flexicontent_html::loadFramework('select2');
            }
            $sel_classes = ' fcfield_textselval use_select2_lib ';
            $sel_onchange = "this.getParent().getElement('input.fcfield_textval').setProperty('value', this.getProperty('value')); this.setProperty('value', ''); ";
            $sel_attribs = ' class="' . $sel_classes . '" onchange="' . $sel_onchange . '"';
            $fieldname_sel = FLEXI_J16GE ? 'custom[' . $field->name . '_sel][]' : $field->name . '_sel[]';
            $sel_ops = plgFlexicontent_fieldsText::buildSelectOptions($field, $item);
            $select_field = JHTML::_('select.genericlist', $sel_ops, $fieldname_sel, $sel_attribs, 'value', 'text', array());
        } else {
            $select_field = '';
        }
        if ($js) {
            $document->addScriptDeclaration($js);
        }
        if ($css) {
            $document->addStyleDeclaration($css);
        }
        if ($custommask && $inputmask == "__custom__") {
            $validate_mask = " data-inputmask=\" " . $custommask . " \" ";
        } else {
            $validate_mask = $inputmask ? " data-inputmask=\" 'alias': '" . $inputmask . "' \" " : "";
        }
        $classes = 'fcfield_textval inputbox' . $required . ($inputmask ? ' has_inputmask' : '');
        $field->html = array();
        $n = 0;
        foreach ($field->value as $value) {
            $elementid_n = $elementid . '_' . $n;
            $text_field = '<input ' . $validate_mask . ' id="' . $elementid_n . '" name="' . $fieldname . '" class="' . $classes . '" type="text" size="' . $size . '" value="' . $value . '" ' . $attribs . ' />';
            $field->html[] = '
				' . $text_field . '
				' . $select_field . '
				' . $move2 . '
				' . $remove_button . '
				';
            $n++;
            if (!$multiple) {
                break;
            }
            // multiple values disabled, break out of the loop, not adding further values even if the exist
        }
        if ($multiple) {
            // handle multiple records
            $_list = "<li>" . implode("</li>\n<li>", $field->html) . "</li>\n";
            $field->html = '
				<ul class="fcfield-sortables" id="sortables_' . $field->id . '">' . $_list . '</ul>
				<input type="button" class="fcfield-addvalue" onclick="addField' . $field->id . '(this);" value="' . JText::_('FLEXI_ADD_VALUE') . '" />
			';
        } else {
            // handle single values
            $field->html = $field->html[0];
        }
    }
Пример #10
0
    function onDisplayField(&$field, &$item)
    {
        if (!in_array($field->field_type, self::$field_types)) {
            return;
        }
        $field->label = JText::_($field->label);
        $use_ingroup = $field->parameters->get('use_ingroup', 0);
        $ajax = !empty($field->isAjax);
        if ($use_ingroup) {
            $field->formhidden = 3;
        }
        if ($use_ingroup && empty($field->ingroup) && !$ajax) {
            return;
        }
        // initialize framework objects and other variables
        $document = JFactory::getDocument();
        // some parameter shortcuts
        $sql_mode = $field->parameters->get('sql_mode', 0);
        $field_elements = $field->parameters->get('field_elements');
        $cascade_after = (int) $field->parameters->get('cascade_after', 0);
        // ****************
        // Number of values
        // ****************
        $multiple = $use_ingroup || (int) $field->parameters->get('allow_multiple', 0);
        $min_values = $use_ingroup ? 0 : (int) $field->parameters->get('min_values', 0);
        $max_values = $use_ingroup ? 0 : (int) $field->parameters->get('max_values', 0);
        $required = $field->parameters->get('required', 0);
        $required = $required ? ' required' : '';
        $add_position = (int) $field->parameters->get('add_position', 3);
        // Sanitize limitations
        $exact_values = $field->parameters->get('exact_values', 0);
        if ($required && !$min_values) {
            $min_values = 1;
        }
        if ($exact_values) {
            $max_values = $min_values = $exact_values;
        }
        $js_popup_err = $field->parameters->get('js_popup_err', 0);
        // **************
        // Value handling
        // **************
        // Default value
        $value_usage = $field->parameters->get('default_value_use', 0);
        $default_values = $item->version == 0 || $value_usage > 0 ? trim($field->parameters->get('default_values', '')) : '';
        // *************************
        // Input field configuration
        // *************************
        // DISPLAY using select2 JS
        $use_jslib = $field->parameters->get('use_jslib', 1);
        $use_select2 = $use_jslib == 1;
        static $select2_added = null;
        if ($use_select2 && $select2_added === null) {
            $select2_added = flexicontent_html::loadFramework('select2');
        }
        // Parameters for DISPLAY with / without using select2 JS
        $size = $field->parameters->get('size', 6);
        $size = $size ? ' size="' . $size . '"' : '';
        // Initialise property with default value
        if (!$field->value) {
            $field->value = preg_split("/\\s*,\\s*/u", $default_values);
        }
        // CSS classes of value container
        $value_classes = 'fcfieldval_container valuebox fcfieldval_container_' . $field->id;
        // Field name and HTML TAG id
        $fieldname = 'custom[' . $field->name . ']';
        $elementid = 'custom_' . $field->name;
        $js = "";
        $css = "";
        // *********************************************************************************************
        // Handle adding the needed JS code to CASCADE (listen to) changes of the dependent master field
        // *********************************************************************************************
        if ($cascade_after && !$ajax) {
            $byIds = FlexicontentFields::indexFieldsByIds($item->fields);
            if (isset($byIds[$cascade_after])) {
                $cascade_prompt = $field->parameters->get('cascade_prompt', '');
                $cascade_prompt = $cascade_prompt ? JText::_($cascade_prompt) : JText::_('FLEXI_PLEASE_SELECT') . ': ' . $byIds[$cascade_after]->label;
                $srcELid = 'custom_' . $byIds[$cascade_after]->name;
                $trgELid = $elementid;
                // Get values of cascade (on) source field
                $field->valgrps = $byIds[$cascade_after]->value ? $byIds[$cascade_after]->value : array();
                foreach ($field->valgrps as &$vg) {
                    if (is_array($vg)) {
                    } else {
                        if (@unserialize($vg) !== false || $vg === 'b:0;') {
                            $vg = unserialize($vg);
                        } else {
                            $vg = array($vg);
                        }
                    }
                }
                unset($vg);
            } else {
                $cascade_after = 0;
                echo 'Error in field ' . $field->label . ' [' . $field->id . ']' . ' cannot cascaded after field no: ' . $cascade_after . ', field was not found <br/>';
            }
        } else {
            if ($cascade_after && $ajax) {
                $field->valgrps = isset($field->valgrps) ? $field->valgrps : array();
                $field->valgrps = is_array($field->valgrps) ? $field->valgrps : preg_split("/\\s*,\\s*/u", trim($field->valgrps));
            }
        }
        // ***********************
        // Handle multiple records
        // ***********************
        if ($multiple && !$ajax) {
            // Add the drag and drop sorting feature
            if (!$use_ingroup) {
                $js .= "\n\t\t\tjQuery(document).ready(function(){\n\t\t\t\tjQuery('#sortables_" . $field->id . "').sortable({\n\t\t\t\t\thandle: '.fcfield-drag-handle',\n\t\t\t\t\tcontainment: 'parent',\n\t\t\t\t\ttolerance: 'pointer'\n\t\t\t\t});\n\t\t\t});\n\t\t\t";
            }
            if ($max_values) {
                FLEXI_J16GE ? JText::script("FLEXI_FIELD_MAX_ALLOWED_VALUES_REACHED", true) : fcjsJText::script("FLEXI_FIELD_MAX_ALLOWED_VALUES_REACHED", true);
            }
            $js .= "\n\t\t\tvar uniqueRowNum" . $field->id . "\t= " . count($field->value) . ";  // Unique row number incremented only\n\t\t\tvar rowCount" . $field->id . "\t= " . count($field->value) . ";      // Counts existing rows to be able to limit a max number of values\n\t\t\tvar maxValues" . $field->id . " = " . $max_values . ";\n\t\t\t\n\t\t\tfunction addField" . $field->id . "(el, groupval_box, fieldval_box, params)\n\t\t\t{\n\t\t\t\tvar insert_before   = (typeof params!== 'undefined' && typeof params.insert_before   !== 'undefined') ? params.insert_before   : 0;\n\t\t\t\tvar remove_previous = (typeof params!== 'undefined' && typeof params.remove_previous !== 'undefined') ? params.remove_previous : 0;\n\t\t\t\tvar scroll_visible  = (typeof params!== 'undefined' && typeof params.scroll_visible  !== 'undefined') ? params.scroll_visible  : 1;\n\t\t\t\tvar animate_visible = (typeof params!== 'undefined' && typeof params.animate_visible !== 'undefined') ? params.animate_visible : 1;\n\t\t\t\t\n\t\t\t\tif((rowCount" . $field->id . " >= maxValues" . $field->id . ") && (maxValues" . $field->id . " != 0)) {\n\t\t\t\t\talert(Joomla.JText._('FLEXI_FIELD_MAX_ALLOWED_VALUES_REACHED') + maxValues" . $field->id . ");\n\t\t\t\t\treturn 'cancel';\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\t// Find last container of fields and clone it to create a new container of fields\n\t\t\t\tvar lastField = fieldval_box ? fieldval_box : jQuery(el).prev().children().last();\n\t\t\t\tvar newField  = lastField.clone();\n\t\t\t\t\n\t\t\t\t// Update the new select field\n\t\t\t\tvar elem= newField.find('select.fcfield_textselval').first();\n\t\t\t\telem.val('');\n\t\t\t\telem.attr('name', '" . $fieldname . "['+uniqueRowNum" . $field->id . "+']" . (self::$valueIsArr ? '[]' : '') . "');\n\t\t\t\telem.attr('id', '" . $elementid . "_'+uniqueRowNum" . $field->id . ");\n\t\t\t\telem.attr('data-uniqueRowNum', uniqueRowNum" . $field->id . ");\n\t\t\t\t\n\t\t\t\t// Destroy any select2 elements\n\t\t\t\tvar has_select2 = newField.find('div.select2-container').length != 0;\n\t\t\t\tif (has_select2) {\n\t\t\t\t\tnewField.find('div.select2-container').remove();\n\t\t\t\t\tnewField.find('select.use_select2_lib').select2('destroy').show().select2();\n\t\t\t\t}\n\t\t\t\t";
            // Add new field to DOM
            $js .= "\n\t\t\t\tlastField ?\n\t\t\t\t\t(insert_before ? newField.insertBefore( lastField ) : newField.insertAfter( lastField ) ) :\n\t\t\t\t\tnewField.appendTo( jQuery('#sortables_" . $field->id . "') ) ;\n\t\t\t\tif (remove_previous) lastField.remove();\n\t\t\t\t";
            // Listen to the changes of cascade-after field
            if ($cascade_after) {
                $js .= "\n\t\t\t\tfc_cascade_field_funcs['" . $srcELid . "_'+uniqueRowNum" . $field->id . "] = function(rowNo){\n\t\t\t\t\treturn function () {\n\t\t\t\t\t\tfcCascadedField(" . $field->id . ", '" . $item->id . "', '" . $field->field_type . "', 'select#" . $srcELid . "_'+rowNo+', input." . $srcELid . "_'+rowNo, '" . $trgELid . "_'+rowNo, '" . $cascade_prompt . "', " . self::$promptEnabled . ", rowNo);\n\t\t\t\t\t}\n\t\t\t\t}(uniqueRowNum" . $field->id . ");\n\t\t\t\tfc_cascade_field_funcs['" . $srcELid . "_'+uniqueRowNum" . $field->id . "]();\n\t\t\t\t";
            }
            // Add new element to sortable objects (if field not in group)
            if (!$use_ingroup) {
                $js .= "\n\t\t\t\tjQuery('#sortables_" . $field->id . "').sortable({\n\t\t\t\t\thandle: '.fcfield-drag-handle',\n\t\t\t\t\tcontainment: 'parent',\n\t\t\t\t\ttolerance: 'pointer'\n\t\t\t\t});\n\t\t\t\t";
            }
            // Show new field, increment counters
            $js .= "\n\t\t\t\t//newField.fadeOut({ duration: 400, easing: 'swing' }).fadeIn({ duration: 200, easing: 'swing' });\n\t\t\t\tif (scroll_visible) fc_scrollIntoView(newField, 1);\n\t\t\t\tif (animate_visible) newField.css({opacity: 0.1}).animate({ opacity: 1 }, 800);\n\t\t\t\t\n\t\t\t\trowCount" . $field->id . "++;       // incremented / decremented\n\t\t\t\tuniqueRowNum" . $field->id . "++;   // incremented only\n\t\t\t}\n\n\t\t\tfunction deleteField" . $field->id . "(el, groupval_box, fieldval_box)\n\t\t\t{\n\t\t\t\t// Find field value container\n\t\t\t\tvar row = fieldval_box ? fieldval_box : jQuery(el).closest('li');\n\t\t\t\t\n\t\t\t\t// Add empty container if last element, instantly removing the given field value container\n\t\t\t\tif(rowCount" . $field->id . " == 1)\n\t\t\t\t\taddField" . $field->id . "(null, groupval_box, row, {remove_previous: 1, scroll_visible: 0, animate_visible: 0});\n\t\t\t\t\n\t\t\t\t// Remove if not last one, if it is last one, we issued a replace (copy,empty new,delete old) above\n\t\t\t\tif(rowCount" . $field->id . " > 1) {\n\t\t\t\t\t// Destroy the remove/add/etc buttons, so that they are not reclicked, while we do the hide effect (before DOM removal of field value)\n\t\t\t\t\trow.find('.fcfield-delvalue').remove();\n\t\t\t\t\trow.find('.fcfield-insertvalue').remove();\n\t\t\t\t\trow.find('.fcfield-drag-handle').remove();\n\t\t\t\t\t// Do hide effect then remove from DOM\n\t\t\t\t\trow.slideUp(400, function(){ this.remove(); });\n\t\t\t\t\trowCount" . $field->id . "--;\n\t\t\t\t}\n\t\t\t}\n\t\t\t";
            $css .= '';
            $remove_button = '<span class="fcfield-delvalue" title="' . JText::_('FLEXI_REMOVE_VALUE') . '" onclick="deleteField' . $field->id . '(this);"></span>';
            $move2 = '<span class="fcfield-drag-handle" title="' . JText::_('FLEXI_CLICK_TO_DRAG') . '"></span>';
            $add_here = '';
            $add_here .= $add_position == 2 || $add_position == 3 ? '<span class="fcfield-insertvalue fc_before" onclick="addField' . $field->id . '(null, jQuery(this).closest(\'ul\'), jQuery(this).closest(\'li\'), {insert_before: 1});" title="' . JText::_('FLEXI_ADD_BEFORE') . '"></span> ' : '';
            $add_here .= $add_position == 1 || $add_position == 3 ? '<span class="fcfield-insertvalue fc_after"  onclick="addField' . $field->id . '(null, jQuery(this).closest(\'ul\'), jQuery(this).closest(\'li\'), {insert_before: 0});" title="' . JText::_('FLEXI_ADD_AFTER') . '"></span> ' : '';
        } else {
            $remove_button = '';
            $move2 = '';
            $add_here = '';
            $js .= '';
            $css .= '';
        }
        // Added field's custom CSS / JS
        if (!$ajax && $js) {
            $document->addScriptDeclaration($js);
        }
        if (!$ajax && $css) {
            $document->addStyleDeclaration($css);
        }
        // **************************
        // Get indexed element values
        // **************************
        // If cascading we will get it inside the value loop for every value, thus supporting field grouping properly
        $elements = !$cascade_after ? $this->getLimitedProps($field, $item) : array();
        if (!is_array($elements)) {
            $field->html = $elements;
            return;
        }
        // *****************************************
        // Create field's HTML display for item form
        // *****************************************
        // Create form field options
        $options = array();
        foreach ($elements as $element) {
            $options[] = JHTML::_('select.option', $element->value, $element->text);
        }
        // Create the attributes of the form field
        $display_as_select = 1;
        if ($display_as_select) {
            $classes = 'fcfield_textselval' . ($use_jslib && $select2_added ? ' use_select2_lib' : '');
            $classes .= $required;
            $onchange = '';
            // Extra properties
            $attribs = 'multiple="multiple" ' . $size;
            $display_label_form = (int) $field->parameters->get('display_label_form', 1);
            $placeholder = $display_label_form == -1 ? $field->label : '';
            $attribs .= $placeholder ? ' placeholder="' . $placeholder . '" ' : '';
            if ($exact_values) {
                $attribs .= ' data-exact_values="' . $exact_values . '" ';
            } else {
                if ($max_values) {
                    $attribs .= ' data-max_values="' . $max_values . '" ';
                }
                if ($min_values) {
                    $attribs .= ' data-min_values="' . $min_values . '" ';
                }
            }
            if ($js_popup_err) {
                $attribs .= ' data-js_popup_err="' . $js_popup_err . '" ';
            }
            if ($max_values || $min_values || $exact_values) {
                $classes .= ' validate-sellimitations ';
            }
            if ($classes) {
                $attribs .= ' class="' . $classes . '" ';
            }
            if ($onchange) {
                $attribs .= ' onchange="' . $onchange . '" ';
            }
        }
        // Handle case of FORM fields that each value is an array of values
        // (e.g. selectmultiple, checkbox), and that multi-value input is also enabled
        $is_array_already = is_array($field->value) ? is_array(reset($field->value)) : false;
        $values = self::$valueIsArr && !$multiple && !$is_array_already ? array($field->value) : $field->value;
        // *****************************************
        // Create field's HTML display for item form
        // *****************************************
        $field->html = array();
        $n = $ajax ? $field->valindex : 0;
        $js = "";
        foreach ($values as $value) {
            // Compatibility for serialized values
            if (self::$valueIsArr) {
                if (is_array($value)) {
                } else {
                    if (@unserialize($value) !== false || $value === 'b:0;') {
                        $value = unserialize($value);
                    }
                }
            }
            // Make sure value is an array
            if (!is_array($value)) {
                $value = strlen($value) ? array($value) : array();
            }
            // Skip empty if not in field group, and at least one value was added
            if (!count($value) && !$use_ingroup && $n) {
                continue;
            }
            // Get options according to cascading, this is here so that it works with field grouping too
            if ($cascade_after) {
                $elements = $this->getLimitedProps($field, $item, !$ajax ? $cascade_prompt : null, $ajax, $n);
                $options =& $elements;
            }
            if (!$ajax) {
                $fieldname_n = $fieldname . '[' . $n . ']' . (self::$valueIsArr ? '[]' : '');
                $elementid_n = $elementid . '_' . $n;
                $form_field = JHTML::_('select.genericlist', $options, $fieldname_n, $attribs . ' data-uniqueRowNum="' . $n . '"', 'value', 'text', $value, $elementid_n);
                $field->html[] = '
					' . $form_field . ($cascade_after ? '<span class="field_cascade_loading"></span>' : '') . '
					' . ($use_ingroup ? '' : $move2) . '
					' . ($use_ingroup ? '' : $remove_button) . '
					' . ($use_ingroup || !$add_position ? '' : $add_here) . '
					';
                // Listen to the changes of cascade-after field
                if ($cascade_after && !$ajax) {
                    $js .= "\n\t\t\t\tjQuery(document).ready(function(){\n\t\t\t\t\tfc_cascade_field_funcs['" . $srcELid . '_' . $n . "'] = function(){\n\t\t\t\t\t\tfcCascadedField(" . $field->id . ", '" . $item->id . "', '" . $field->field_type . "', 'select#" . $srcELid . '_' . $n . ", input." . $srcELid . '_' . $n . "', '" . $trgELid . '_' . $n . "', '" . $cascade_prompt . "', " . self::$promptEnabled . ", " . $n . ");\n\t\t\t\t\t}\n\t\t\t\t\tfc_cascade_field_funcs['" . $srcELid . '_' . $n . "']();\n\t\t\t\t});\n\t\t\t\t";
                }
            } else {
                $field->html = JHTML::_('select.options', $options, 'value', 'text', $value, $translate = false);
            }
            $n++;
            if (!$multiple) {
                break;
            }
            // multiple values disabled, break out of the loop, not adding further values even if the exist
        }
        if ($js) {
            $document->addScriptDeclaration($js);
        }
        if ($ajax) {
            return;
            // Done
        } else {
            if ($use_ingroup) {
                // do not convert the array to string if field is in a group
            } else {
                if ($multiple) {
                    // handle multiple records
                    $field->html = '<li class="' . $value_classes . '">' . implode('</li><li class="' . $value_classes . '">', $field->html) . '</li>';
                    $field->html = '<ul class="fcfield-sortables" id="sortables_' . $field->id . '">' . $field->html . '</ul>';
                    if (!$add_position) {
                        $field->html .= '<span class="fcfield-addvalue" onclick="addField' . $field->id . '(this);" title="' . JText::_('FLEXI_ADD_TO_BOTTOM') . '"></span>';
                    }
                } else {
                    // handle single values
                    $field->html = '<div class="fcfieldval_container valuebox fcfieldval_container_' . $field->id . '">' . $field->html[0] . '</div>';
                }
            }
        }
        // Add message box about allowed # values
        if ($exact_values) {
            $field->html = '<div class="alert alert-info fc-small fc-iblock">' . JText::sprintf('FLEXI_FIELD_NUM_VALUES_EXACTLY', $exact_values) . '</div><div class="clear"></div>' . $field->html;
        } else {
            if ($max_values || $min_values > 1) {
                $field->html = '<div class="alert alert-info fc-small fc-iblock">' . JText::sprintf('FLEXI_FIELD_NUM_VALUES_BETWEEN', $min_values, $max_values) . '</div><div class="clear"></div>' . $field->html;
            }
        }
    }
Пример #11
0
    function onDisplayField(&$field, &$item)
    {
        if (!in_array($field->field_type, self::$field_types)) {
            return;
        }
        $field->label = JText::_($field->label);
        $use_ingroup = $field->parameters->get('use_ingroup', 0);
        if ($use_ingroup) {
            $field->formhidden = 3;
        }
        if ($use_ingroup && empty($field->ingroup)) {
            return;
        }
        // initialize framework objects and other variables
        $document = JFactory::getDocument();
        // ****************
        // Number of values
        // ****************
        $multiple = $use_ingroup || (int) $field->parameters->get('allow_multiple', 0);
        $max_values = $use_ingroup ? 0 : (int) $field->parameters->get('max_values', 0);
        $required = $field->parameters->get('required', 0);
        $required = $required ? ' required' : '';
        $add_position = (int) $field->parameters->get('add_position', 3);
        // *************
        // Email address
        // *************
        // Default value
        $addr_usage = $field->parameters->get('default_value_use', 0);
        $default_addr = $item->version == 0 || $addr_usage > 0 ? $field->parameters->get('default_value', '') : '';
        $default_addr = $default_addr ? JText::_($default_addr) : '';
        // Input field display size & max characters
        $size = (int) $field->parameters->get('size', 30);
        $maxlength = (int) $field->parameters->get('maxlength', 0);
        // client/server side enforced
        $inputmask = $field->parameters->get('inputmask', 'email');
        // create extra HTML TAG parameters for the form field
        $attribs = $field->parameters->get('extra_attributes', '');
        if ($maxlength) {
            $attribs .= ' maxlength="' . $maxlength . '" ';
        }
        $attribs .= ' size="' . $size . '" ';
        $classes = $required;
        static $inputmask_added = false;
        if ($inputmask && !$inputmask_added) {
            $inputmask_added = true;
            flexicontent_html::loadFramework('inputmask');
        }
        if ($inputmask) {
            $attribs .= " data-inputmask=\" 'alias': 'email' \" ";
            $classes .= ' has_inputmask';
        }
        $classes .= ' validate-email';
        // *************************************
        // Email title & linking text (optional)
        // *************************************
        // Default value
        $title_usage = $field->parameters->get('title_usage', 0);
        $default_title = $item->version == 0 || $title_usage > 0 ? JText::_($field->parameters->get('default_value_title', '')) : '';
        $default_title = $default_title ? JText::_($default_title) : '';
        $usetitle = $field->parameters->get('use_title', 0);
        // Initialise property with default value
        if (!$field->value) {
            $field->value = array();
            $field->value[0]['addr'] = $default_addr;
            $field->value[0]['text'] = $default_title;
            $field->value[0] = serialize($field->value[0]);
        }
        // CSS classes of value container
        $value_classes = 'fcfieldval_container valuebox fcfieldval_container_' . $field->id;
        // Field name and HTML TAG id
        $fieldname = 'custom[' . $field->name . ']';
        $elementid = 'custom_' . $field->name;
        $js = "";
        $css = "";
        if ($multiple) {
            // Add the drag and drop sorting feature
            if (!$use_ingroup) {
                $js .= "\n\t\t\tjQuery(document).ready(function(){\n\t\t\t\tjQuery('#sortables_" . $field->id . "').sortable({\n\t\t\t\t\thandle: '.fcfield-drag-handle',\n\t\t\t\t\tcontainment: 'parent',\n\t\t\t\t\ttolerance: 'pointer'\n\t\t\t\t});\n\t\t\t});\n\t\t\t";
            }
            if ($max_values) {
                FLEXI_J16GE ? JText::script("FLEXI_FIELD_MAX_ALLOWED_VALUES_REACHED", true) : fcjsJText::script("FLEXI_FIELD_MAX_ALLOWED_VALUES_REACHED", true);
            }
            $js .= "\n\t\t\tvar uniqueRowNum" . $field->id . "\t= " . count($field->value) . ";  // Unique row number incremented only\n\t\t\tvar rowCount" . $field->id . "\t= " . count($field->value) . ";      // Counts existing rows to be able to limit a max number of values\n\t\t\tvar maxValues" . $field->id . " = " . $max_values . ";\n\t\t\t\n\t\t\tfunction addField" . $field->id . "(el, groupval_box, fieldval_box, params)\n\t\t\t{\n\t\t\t\tvar insert_before   = (typeof params!== 'undefined' && typeof params.insert_before   !== 'undefined') ? params.insert_before   : 0;\n\t\t\t\tvar remove_previous = (typeof params!== 'undefined' && typeof params.remove_previous !== 'undefined') ? params.remove_previous : 0;\n\t\t\t\tvar scroll_visible  = (typeof params!== 'undefined' && typeof params.scroll_visible  !== 'undefined') ? params.scroll_visible  : 1;\n\t\t\t\tvar animate_visible = (typeof params!== 'undefined' && typeof params.animate_visible !== 'undefined') ? params.animate_visible : 1;\n\t\t\t\t\n\t\t\t\tif((rowCount" . $field->id . " >= maxValues" . $field->id . ") && (maxValues" . $field->id . " != 0)) {\n\t\t\t\t\talert(Joomla.JText._('FLEXI_FIELD_MAX_ALLOWED_VALUES_REACHED') + maxValues" . $field->id . ");\n\t\t\t\t\treturn 'cancel';\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\tvar lastField = fieldval_box ? fieldval_box : jQuery(el).prev().children().last();\n\t\t\t\tvar newField  = lastField.clone();\n\t\t\t\t";
            // NOTE: HTML tag id of this form element needs to match the -for- attribute of label HTML tag of this FLEXIcontent field, so that label will be marked invalid when needed
            // Update the new email address
            $js .= "\n\t\t\t\tvar theInput = newField.find('input.emailaddr').first();\n\t\t\t\ttheInput.val('" . $default_addr . "');\n\t\t\t\ttheInput.attr('name','" . $fieldname . "['+uniqueRowNum" . $field->id . "+'][addr]');\n\t\t\t\ttheInput.attr('id','" . $elementid . "_'+uniqueRowNum" . $field->id . "+'_addr');\n\t\t\t\tnewField.find('.emailaddr-lbl').first().attr('for','" . $elementid . "_'+uniqueRowNum" . $field->id . "+'_addr');\n\t\t\t\t";
            // Update the new email linking text
            if ($usetitle) {
                $js .= "\n\t\t\t\tvar theInput = newField.find('input.emailtext').first();\n\t\t\t\ttheInput.val('" . $default_title . "');\n\t\t\t\ttheInput.attr('name','" . $fieldname . "['+uniqueRowNum" . $field->id . "+'][text]');\n\t\t\t\ttheInput.attr('id','" . $elementid . "_'+uniqueRowNum" . $field->id . "+'_text');\n\t\t\t\tnewField.find('.emailtext-lbl').first().attr('for','" . $elementid . "_'+uniqueRowNum" . $field->id . "+'_text');\n\t\t\t\t\n\t\t\t\t// Update inputmask\n\t\t\t\tvar has_inputmask = newField.find('input.has_inputmask').length != 0;\n\t\t\t\tif (has_inputmask)  newField.find('input.has_inputmask').inputmask();\n\t\t\t\t";
            }
            // Add new field to DOM
            $js .= "\n\t\t\t\tlastField ?\n\t\t\t\t\t(insert_before ? newField.insertBefore( lastField ) : newField.insertAfter( lastField ) ) :\n\t\t\t\t\tnewField.appendTo( jQuery('#sortables_" . $field->id . "') ) ;\n\t\t\t\tif (remove_previous) lastField.remove();\n\t\t\t\t";
            // Add new element to sortable objects (if field not in group)
            if (!$use_ingroup) {
                $js .= "\n\t\t\t\tjQuery('#sortables_" . $field->id . "').sortable({\n\t\t\t\t\thandle: '.fcfield-drag-handle',\n\t\t\t\t\tcontainment: 'parent',\n\t\t\t\t\ttolerance: 'pointer'\n\t\t\t\t});\n\t\t\t\t";
            }
            // Show new field, increment counters
            $js .= "\n\t\t\t\t//newField.fadeOut({ duration: 400, easing: 'swing' }).fadeIn({ duration: 200, easing: 'swing' });\n\t\t\t\tif (scroll_visible) fc_scrollIntoView(newField, 1);\n\t\t\t\tif (animate_visible) newField.css({opacity: 0.1}).animate({ opacity: 1 }, 800);\n\t\t\t\t\n\t\t\t\trowCount" . $field->id . "++;       // incremented / decremented\n\t\t\t\tuniqueRowNum" . $field->id . "++;   // incremented only\n\t\t\t}\n\n\t\t\tfunction deleteField" . $field->id . "(el, groupval_box, fieldval_box)\n\t\t\t{\n\t\t\t\t// Find field value container\n\t\t\t\tvar row = fieldval_box ? fieldval_box : jQuery(el).closest('li');\n\t\t\t\t\n\t\t\t\t// Add empty container if last element, instantly removing the given field value container\n\t\t\t\tif(rowCount" . $field->id . " == 1)\n\t\t\t\t\taddField" . $field->id . "(null, groupval_box, row, {remove_previous: 1, scroll_visible: 0, animate_visible: 0});\n\t\t\t\t\n\t\t\t\t// Remove if not last one, if it is last one, we issued a replace (copy,empty new,delete old) above\n\t\t\t\tif(rowCount" . $field->id . " > 1) {\n\t\t\t\t\t// Destroy the remove/add/etc buttons, so that they are not reclicked, while we do the hide effect (before DOM removal of field value)\n\t\t\t\t\trow.find('.fcfield-delvalue').remove();\n\t\t\t\t\trow.find('.fcfield-insertvalue').remove();\n\t\t\t\t\trow.find('.fcfield-drag-handle').remove();\n\t\t\t\t\t// Do hide effect then remove from DOM\n\t\t\t\t\trow.slideUp(400, function(){ this.remove(); });\n\t\t\t\t\trowCount" . $field->id . "--;\n\t\t\t\t}\n\t\t\t}\n\t\t\t";
            $css .= '';
            $remove_button = '<span class="fcfield-delvalue" title="' . JText::_('FLEXI_REMOVE_VALUE') . '" onclick="deleteField' . $field->id . '(this);"></span>';
            $move2 = '<span class="fcfield-drag-handle" title="' . JText::_('FLEXI_CLICK_TO_DRAG') . '"></span>';
            $add_here = '';
            $add_here .= $add_position == 2 || $add_position == 3 ? '<span class="fcfield-insertvalue fc_before" onclick="addField' . $field->id . '(null, jQuery(this).closest(\'ul\'), jQuery(this).closest(\'li\'), {insert_before: 1});" title="' . JText::_('FLEXI_ADD_BEFORE') . '"></span> ' : '';
            $add_here .= $add_position == 1 || $add_position == 3 ? '<span class="fcfield-insertvalue fc_after"  onclick="addField' . $field->id . '(null, jQuery(this).closest(\'ul\'), jQuery(this).closest(\'li\'), {insert_before: 0});" title="' . JText::_('FLEXI_ADD_AFTER') . '"></span> ' : '';
        } else {
            $remove_button = '';
            $move2 = '';
            $add_here = '';
            $js .= '';
            $css .= '';
        }
        if ($js) {
            $document->addScriptDeclaration($js);
        }
        if ($css) {
            $document->addStyleDeclaration($css);
        }
        // *****************************************
        // Create field's HTML display for item form
        // *****************************************
        $field->html = array();
        $n = 0;
        //if ($use_ingroup) {print_r($field->value);}
        foreach ($field->value as $value) {
            // Compatibility for unserialized values (e.g. reload user input after form validation error) or for NULL values in a field group
            if (!is_array($value)) {
                $v = !empty($value) ? @unserialize($value) : false;
                $value = $v !== false || $v === 'b:0;' ? $v : array('addr' => $value, 'text' => '');
            }
            if (empty($value['addr']) && !$use_ingroup && $n) {
                continue;
            }
            // If at least one added, skip empty if not in field group
            $fieldname_n = $fieldname . '[' . $n . ']';
            $elementid_n = $elementid . '_' . $n;
            $value['addr'] = !empty($value['addr']) ? $value['addr'] : '';
            $value['addr'] = htmlspecialchars(FLEXI_J30GE ? JStringPunycode::emailToUTF8($value['addr']) : $value['addr'], ENT_COMPAT, 'UTF-8');
            $addr = '
				<div class="nowrap_box">
					<label class="label emailaddr-lbl" for="' . $elementid_n . '_addr">' . JText::_('FLEXI_FIELD_EMAILADDRESS') . '</label>
					<input class="emailaddr fcfield_textval ' . $classes . '" name="' . $fieldname_n . '[addr]" id="' . $elementid_n . '_addr" type="text" value="' . $value['addr'] . '" ' . $attribs . ' />
				</div>';
            $text = '';
            if ($usetitle) {
                $value['text'] = !empty($value['text']) ? $value['text'] : $default_title;
                $value['text'] = isset($value['text']) ? htmlspecialchars($value['text'], ENT_COMPAT, 'UTF-8') : '';
                $text = '
				<div class="nowrap_box">
					<label class="label emailtext-lbl" for="' . $elementid_n . '_text">' . JText::_('FLEXI_FIELD_EMAILTITLE') . '</label>
					<input class="emailtext fcfield_textval" name="' . $fieldname_n . '[text]"  id="' . $elementid_n . '_text" type="text" size="' . $size . '" value="' . $value['text'] . '" />
				</div>';
            }
            $field->html[] = '
				' . $addr . '
				' . $text . '
				' . ($use_ingroup ? '' : $move2) . '
				' . ($use_ingroup ? '' : $remove_button) . '
				' . ($use_ingroup || !$add_position ? '' : $add_here) . '
				';
            $n++;
            if (!$multiple) {
                break;
            }
            // multiple values disabled, break out of the loop, not adding further values even if the exist
        }
        if ($use_ingroup) {
            // do not convert the array to string if field is in a group
        } else {
            if ($multiple) {
                // handle multiple records
                $field->html = '<li class="' . $value_classes . '">' . implode('</li><li class="' . $value_classes . '">', $field->html) . '</li>';
                $field->html = '<ul class="fcfield-sortables" id="sortables_' . $field->id . '">' . $field->html . '</ul>';
                if (!$add_position) {
                    $field->html .= '<span class="fcfield-addvalue" onclick="addField' . $field->id . '(this);" title="' . JText::_('FLEXI_ADD_TO_BOTTOM') . '"></span>';
                }
            } else {
                // handle single values
                $field->html = '<div class="fcfieldval_container valuebox fcfieldval_container_' . $field->id . '">' . $field->html[0] . '</div>';
            }
        }
    }
Пример #12
0
    function onDisplayField(&$field, &$item)
    {
        // execute the code only if the field type match the plugin type
        if (!in_array($field->field_type, self::$field_types)) {
            return;
        }
        $field->label = JText::_($field->label);
        // some parameter shortcuts
        $document = JFactory::getDocument();
        $app = JFactory::getApplication();
        $size = $field->parameters->get('size', 30);
        $max_values = (int) $field->parameters->get('max_values', 0);
        $required = $field->parameters->get('required', 0);
        $required = $required ? ' required' : '';
        $fieldname = FLEXI_J16GE ? 'custom[' . $field->name . '][]' : $field->name . '[]';
        if ($max_values) {
            FLEXI_J16GE ? JText::script("FLEXI_FIELD_MAX_ALLOWED_VALUES_REACHED", true) : fcjsJText::script("FLEXI_FIELD_MAX_ALLOWED_VALUES_REACHED", true);
        }
        $js = "\n\t\t\tvar value_counter" . $field->id . "=" . count($field->value) . ";\n\t\t\tvar maxValues" . $field->id . "=" . $max_values . ";\n\t\t\t\n\t\t\tfunction qfSelectFile" . $field->id . "(id, file) {\n\t\t\t\tif((value_counter" . $field->id . " >= maxValues" . $field->id . ") && (maxValues" . $field->id . " != 0)) {\n\t\t\t\t\talert(Joomla.JText._('FLEXI_FIELD_MAX_ALLOWED_VALUES_REACHED') + maxValues" . $field->id . ");\n\t\t\t\t\treturn 'cancel';\n\t\t\t\t}\n\t\t\t\t\n\t\t\t  value_counter" . $field->id . "++;\n\t\t\t  var valcounter = \$('" . $field->name . "');\n\t\t\t\tvalcounter.value = value_counter" . $field->id . ";\n\t\t\t\t\n\t\t\t\tvar name \t= 'a_name'+id;\n\t\t\t\tvar ixid \t= 'a_id'+id;\n\t\t\t\tvar li \t\t= document.createElement('li');\n\t\t\t\tvar txt\t\t= document.createElement('span');\n\t\t\t\tvar hid\t\t= document.createElement('input');\n\t\t\t\tvar span\t= document.createElement('span');\n\t\t\t\tvar img\t\t= document.createElement('img');\n\t\t\t\t\n\t\t\t\tvar filelist = document.getElementById('sortables_" . $field->id . "');\n\t\t\t\t\n\t\t\t\t\$(span).addClass('fcfield-drag');\n\t\t\t\t\n\t\t\t\tvar button = document.createElement('input');\n\t\t\t\tbutton.type = 'button';\n\t\t\t\tbutton.name = 'removebutton_'+id;\n\t\t\t\tbutton.id = 'removebutton_'+id;\n\t\t\t\t\$(button).addClass('fcfield-button');\n\t\t\t\t\$(button).addEvent('click', function() { deleteField" . $field->id . "(this) });\n\t\t\t\tbutton.value = '" . JText::_('FLEXI_REMOVE_FILE', true) . "';\n\t\t\t\t\n\t\t\t\ttxt.type = 'text';\n\t\t\t\ttxt.size = '" . $size . "';\n\t\t\t\ttxt.readonly = 'readonly';  /*txt.disabled = 'disabled';*/  /*txt.dir='rtl';*/\n\t\t\t\ttxt.id\t= name;\n\t\t\t\ttxt.innerHTML\t= file;\n\t\t\t\ttxt.addClass('fcfield_textval inputbox inline_style_published');\n\t\t\t\t\n\t\t\t\thid.type = 'hidden';\n\t\t\t\thid.name = '" . $fieldname . "';\n\t\t\t\thid.value = id;\n\t\t\t\thid.id = ixid;\n\t\t\t\t\n\t\t\t\timg.src = '" . JURI::base() . "components/com_flexicontent/assets/images/move2.png';\n\t\t\t\timg.alt = '" . JText::_('FLEXI_CLICK_TO_DRAG', true) . "';\n\t\t\t\t\n\t\t\t\tfilelist.appendChild(li);\n\t\t\t\tli.appendChild(txt);\n\t\t\t\tli.appendChild(span);\n\t\t\t\tspan.appendChild(img);\n\t\t\t\tli.appendChild(button);\n\t\t\t\tli.appendChild(hid);\n\t\t\t\t\n\t\t\t\tjQuery('#sortables_" . $field->id . "').sortable({\n\t\t\t\t\thandle: '.fcfield-drag',\n\t\t\t\t\tcontainment: 'parent',\n\t\t\t\t\ttolerance: 'pointer'\n\t\t\t\t});\n\t\t\t}\n\t\t\t";
        if (!FLEXI_J16GE) {
            $document->addScript(JURI::root(true) . '/components/com_flexicontent/assets/js/sortables.js');
        }
        // Add the drag and drop sorting feature
        $js .= "\n\t\tjQuery(document).ready(function(){\n\t\t\tjQuery('#sortables_" . $field->id . "').sortable({\n\t\t\t\thandle: '.fcfield-drag',\n\t\t\t\tcontainment: 'parent',\n\t\t\t\ttolerance: 'pointer'\n\t\t\t});\n\t\t});\n\t\t";
        $js .= "\t\t\t\t\t\n\t\tfunction deleteField" . $field->id . "(el)\n\t\t{\n\t\t  value_counter" . $field->id . "--;\n\t\t\t\n\t\t  var valcounter = \$('" . $field->name . "');\n\t\t\tif ( value_counter" . $field->id . " > 0 ) valcounter.value = value_counter" . $field->id . ";\n\t\t\telse valcounter.value = '';\n\t\t\t\n\t\t\tvar row = jQuery(el).closest('li');\n\t\t\tjQuery(row).hide('slideUp', function() { jQuery(this).remove(); } );\n\t\t}\n\t\t";
        $css = '
		#sortables_' . $field->id . ' { float:left; margin: 0px; padding: 0px; list-style: none; white-space: normal; }
		#sortables_' . $field->id . ' li {
			clear: both;
			display: block;
			list-style: none;
			height: auto;
			position: relative;
		}
		#sortables_' . $field->id . ' li span.fcfield_textval { cursor:text; padding:4px!important; font-family:tahoma!important; white-space:pre-wrap!important; word-wrap:break-word!important; }
		#sortables_' . $field->id . ' li span.inline_style_published   { color:#444!important; }
		#sortables_' . $field->id . ' li span.inline_style_unpublished { background: #ffffff; color:gray; border-width:0px; text-decoration:line-through; }
		';
        $remove_button = '<input class="fcfield-button" type="button" value="' . JText::_('FLEXI_REMOVE_FILE') . '" onclick="deleteField' . $field->id . '(this);" />';
        $move2 = '<span class="fcfield-drag">' . JHTML::image(JURI::base() . 'components/com_flexicontent/assets/images/move2.png', JText::_('FLEXI_CLICK_TO_DRAG')) . '</span>';
        if ($js) {
            $document->addScriptDeclaration($js);
        }
        if ($css) {
            $document->addStyleDeclaration($css);
        }
        JHTML::_('behavior.modal', 'a.modal_' . $field->id);
        $files_data = !empty($field->value) ? $this->getFileData($field->value, $published = false) : array();
        $field->html = array();
        $i = 0;
        foreach ($files_data as $file_id => $file_data) {
            /*$field->html[] = ($file_data->published ?
            		'  <input class="fcfield_textval inputbox inline_style_published" size="'.$size.'" type="text" id="a_name'.$i.'" value="'.$file_data->filename.'" readonly="readonly" dir="rtl"/>' :
            		'  <input class="fcfield_textval inputbox inline_style_unpublished" size="'.$size.'" style="'.$inline_style_unpublished.'" type="text" id="a_name'.$i.'" value="'.$file_data->filename.' [UNPUBLISHED]" readonly="readonly" dir="rtl"/>'
            		)*/
            $filename_original = $file_data->filename_original ? $file_data->filename_original : $file_data->filename;
            $field->html[] = ($file_data->published ? '  <span class="fcfield_textval inputbox inline_style_published" type="text" id="a_name' . $i . '" readonly="readonly" >' . $filename_original . '</span> ' . ($file_data->url ? ' [' . $file_data->altname . ']' : '') : '  <span class="fcfield_textval inputbox inline_style_unpublished" style="' . $inline_style_unpublished . '" type="text" id="a_name' . $i . '" [UNPUBLISHED]" readonly="readonly" >' . $filename_original . '</span> ' . ($file_data->url ? ' [' . $file_data->altname . ']' : '')) . $move2 . $remove_button . '  <input type="hidden" id="a_id' . $i . '" name="' . $fieldname . '" value="' . $file_id . '" />';
            $i++;
            //if ($max_values && $i >= $max_values) break;  // break out of the loop, if maximum file limit was reached
        }
        $field->html = count($field->html) ? '<li>' . implode('</li><li>', $field->html) . '</li>' : '';
        $field->html = '<ul class="fcfield-sortables" id="sortables_' . $field->id . '">' . $field->html . '</ul>';
        $user = JFactory::getUser();
        $autoselect = $field->parameters->get('autoselect', 1);
        $linkfsel = JURI::base(true) . '/index.php?option=com_flexicontent&amp;view=fileselement&amp;tmpl=component&amp;index=' . $i . '&amp;field=' . $field->id . '&amp;itemid=' . $item->id . '&amp;autoselect=' . $autoselect . '&amp;items=0&amp;filter_uploader=' . $user->id . '&amp;' . (FLEXI_J30GE ? JSession::getFormToken() : JUtility::getToken()) . '=1';
        $field->html .= "\n\t\t<div class=\"fcclear\"></div>\n\t\t<div class=\"fcfield-button-add\">\n\t\t\t<div class=\"blank\">\n\t\t\t\t<a class=\"modal_" . $field->id . "\" title=\"" . JText::_('FLEXI_ADD_FILE') . "\" href=\"" . $linkfsel . "\" rel=\"{handler: 'iframe', size: {x:(MooTools.version>='1.2.4' ? window.getSize().x : window.getSize().size.x)-100, y: (MooTools.version>='1.2.4' ? window.getSize().y : window.getSize().size.y)-100}}\">" . JText::_('FLEXI_ADD_FILE') . "</a>\n\t\t\t</div>\n\t\t</div>\n\t\t";
        $field->html .= '<input id="' . $field->name . '" class="' . $required . '" style="display:none;" name="__fcfld_valcnt__[' . $field->name . ']" value="' . ($i ? $i : '') . '" />';
    }
Пример #13
0
    function onDisplayField(&$field, &$item)
    {
        if (!in_array($field->field_type, self::$field_types)) {
            return;
        }
        $field->label = JText::_($field->label);
        $use_ingroup = $field->parameters->get('use_ingroup', 0);
        if ($use_ingroup) {
            $field->formhidden = 3;
        }
        if ($use_ingroup && empty($field->ingroup)) {
            return;
        }
        // initialize framework objects and other variables
        $document = JFactory::getDocument();
        // ****************
        // Number of values
        // ****************
        $multiple = $use_ingroup || (int) $field->parameters->get('allow_multiple', 0);
        $max_values = $use_ingroup ? 0 : (int) $field->parameters->get('max_values', 0);
        $required = $field->parameters->get('required', 0);
        $required = $required ? ' required' : '';
        $add_position = (int) $field->parameters->get('add_position', 3);
        // ***
        // URL
        // ***
        // Default value
        $link_usage = $field->parameters->get('default_link_usage', 0);
        $default_link = $item->version == 0 || $link_usage > 0 ? $field->parameters->get('default_link', '') : '';
        $default_link = $default_link ? JText::_($default_link) : '';
        $allow_relative_addrs = $field->parameters->get('allow_relative_addrs', 0);
        // *********************************************************
        // URL title, linking text, CSS class, HTML tag id (optional)
        // **********************************************************
        // Default value
        $title_usage = $field->parameters->get('title_usage', 0);
        $default_title = $item->version == 0 || $title_usage > 0 ? JText::_($field->parameters->get('default_title', '')) : '';
        $default_title = $default_title ? JText::_($default_title) : '';
        $usetitle = $field->parameters->get('use_title', 0);
        // *****************************
        // URL other optional properties
        // *****************************
        $text_usage = $field->parameters->get('text_usage', 0);
        $default_text = $item->version == 0 || $text_usage > 0 ? $field->parameters->get('default_text', '') : '';
        $default_text = $default_text ? JText::_($default_text) : '';
        $usetext = $field->parameters->get('use_text', 0);
        $class_usage = $field->parameters->get('class_usage', 0);
        $default_class = $item->version == 0 || $class_usage > 0 ? $field->parameters->get('default_class', '') : '';
        $default_class = $default_class ? JText::_($default_class) : '';
        $useclass = $field->parameters->get('use_class', 0);
        // Css class names
        $class_choices = $field->parameters->get('class_choices', '');
        if ($useclass == 2) {
            $class_options = $this->getClassOptions($class_choices);
        }
        $id_usage = $field->parameters->get('id_usage', 0);
        $default_id = $item->version == 0 || $id_usage > 0 ? $field->parameters->get('default_id', '') : '';
        $default_id = $default_id ? JText::_($default_id) : '';
        $useid = $field->parameters->get('use_id', 0);
        // **********
        // Hits usage
        // **********
        $usehits = $field->parameters->get('use_hits', 1);
        // Form fields display parameters
        $size = (int) $field->parameters->get('size', 30);
        // Initialise property with default value
        if (!$field->value) {
            $field->value = array();
            $field->value[0]['link'] = $default_link;
            $field->value[0]['title'] = $default_title;
            $field->value[0]['linktext'] = $default_text;
            $field->value[0]['class'] = $default_class;
            $field->value[0]['id'] = $default_id;
            $field->value[0]['hits'] = 0;
            $field->value[0] = serialize($field->value[0]);
        }
        // CSS classes of value container
        $value_classes = 'fcfieldval_container valuebox fcfieldval_container_' . $field->id;
        // Field name and HTML TAG id
        $fieldname = 'custom[' . $field->name . ']';
        $elementid = 'custom_' . $field->name;
        $js = "";
        $css = "";
        if ($multiple) {
            // Add the drag and drop sorting feature
            if (!$use_ingroup) {
                $js .= "\n\t\t\tjQuery(document).ready(function(){\n\t\t\t\tjQuery('#sortables_" . $field->id . "').sortable({\n\t\t\t\t\thandle: '.fcfield-drag-handle',\n\t\t\t\t\tcontainment: 'parent',\n\t\t\t\t\ttolerance: 'pointer'\n\t\t\t\t});\n\t\t\t});\n\t\t\t";
            }
            if ($max_values) {
                FLEXI_J16GE ? JText::script("FLEXI_FIELD_MAX_ALLOWED_VALUES_REACHED", true) : fcjsJText::script("FLEXI_FIELD_MAX_ALLOWED_VALUES_REACHED", true);
            }
            $js .= "\n\t\t\tvar uniqueRowNum" . $field->id . "\t= " . count($field->value) . ";  // Unique row number incremented only\n\t\t\tvar rowCount" . $field->id . "\t= " . count($field->value) . ";      // Counts existing rows to be able to limit a max number of values\n\t\t\tvar maxValues" . $field->id . " = " . $max_values . ";\n\t\t\t\n\t\t\tfunction addField" . $field->id . "(el, groupval_box, fieldval_box, params)\n\t\t\t{\n\t\t\t\tvar insert_before   = (typeof params!== 'undefined' && typeof params.insert_before   !== 'undefined') ? params.insert_before   : 0;\n\t\t\t\tvar remove_previous = (typeof params!== 'undefined' && typeof params.remove_previous !== 'undefined') ? params.remove_previous : 0;\n\t\t\t\tvar scroll_visible  = (typeof params!== 'undefined' && typeof params.scroll_visible  !== 'undefined') ? params.scroll_visible  : 1;\n\t\t\t\tvar animate_visible = (typeof params!== 'undefined' && typeof params.animate_visible !== 'undefined') ? params.animate_visible : 1;\n\t\t\t\t\n\t\t\t\tif((rowCount" . $field->id . " >= maxValues" . $field->id . ") && (maxValues" . $field->id . " != 0)) {\n\t\t\t\t\talert(Joomla.JText._('FLEXI_FIELD_MAX_ALLOWED_VALUES_REACHED') + maxValues" . $field->id . ");\n\t\t\t\t\treturn 'cancel';\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\tvar lastField = fieldval_box ? fieldval_box : jQuery(el).prev().children().last();\n\t\t\t\tvar newField  = lastField.clone();\n\t\t\t\t";
            // NOTE: HTML tag id of this form element needs to match the -for- attribute of label HTML tag of this FLEXIcontent field, so that label will be marked invalid when needed
            // Update new URL's address
            $js .= "\n\t\t\t\ttheInput = newField.find('input.urllink').first();\n\t\t\t\ttheInput.val('" . $default_link . "');\n\t\t\t\ttheInput.attr('name','" . $fieldname . "['+uniqueRowNum" . $field->id . "+'][link]');\n\t\t\t\ttheInput.attr('id','" . $elementid . "_'+uniqueRowNum" . $field->id . ");\n\t\t\t\t";
            if ($allow_relative_addrs == 2) {
                $js .= "\n\t\t\t\tvar nr = 0;\n\t\t\t\tnewField.find('input.autoprefix').each(function() {\n\t\t\t\t\tvar elem = jQuery(this);\n\t\t\t\t\telem.attr('name','" . $fieldname . "['+uniqueRowNum" . $field->id . "+'][autoprefix]');\n\t\t\t\t\telem.attr('id','" . $elementid . "_'+uniqueRowNum" . $field->id . "+'_autoprefix_'+nr);\n\t\t\t\t\telem.next('label').attr('for', '" . $elementid . "_'+uniqueRowNum" . $field->id . "+'_autoprefix_'+nr);\n\t\t\t\t\tnr++;\n\t\t\t\t});\n\t\t\t\t";
            }
            // Update new URL optional properties
            if ($usetitle) {
                $js .= "\n\t\t\t\ttheInput = newField.find('input.urltitle').first();\n\t\t\t\ttheInput.val('" . $default_title . "');\n\t\t\t\ttheInput.attr('name','" . $fieldname . "['+uniqueRowNum" . $field->id . "+'][title]');\n\t\t\t\ttheInput.attr('id','" . $elementid . "_'+uniqueRowNum" . $field->id . "+'_title');\n\t\t\t\t";
            }
            if ($usetext) {
                $js .= "\n\t\t\t\ttheInput = newField.find('input.urllinktext').first();\n\t\t\t\ttheInput.val('" . $default_text . "');\n\t\t\t\ttheInput.attr('name','" . $fieldname . "['+uniqueRowNum" . $field->id . "+'][linktext]');\n\t\t\t\ttheInput.attr('id','" . $elementid . "_'+uniqueRowNum" . $field->id . "+'_linktext');\n\t\t\t\t";
            }
            if ($useclass) {
                $js .= "\n\t\t\t\ttheInput = newField.find('input.urlclass').first();\n\t\t\t\ttheInput.val('" . $default_class . "');\n\t\t\t\ttheInput.attr('name','" . $fieldname . "['+uniqueRowNum" . $field->id . "+'][class]');\n\t\t\t\ttheInput.attr('id','" . $elementid . "_'+uniqueRowNum" . $field->id . "+'_class');\n\t\t\t\t";
            }
            if ($useid) {
                $js .= "\n\t\t\t\ttheInput = newField.find('input.urlid').first();\n\t\t\t\ttheInput.val('" . $default_id . "');\n\t\t\t\ttheInput.attr('name','" . $fieldname . "['+uniqueRowNum" . $field->id . "+'][id]');\n\t\t\t\ttheInput.attr('id','" . $elementid . "_'+uniqueRowNum" . $field->id . "+'_id');\n\t\t\t\t";
            }
            if ($usehits) {
                $js .= "\n\t\t\t\ttheInput = newField.find('input.urlhits').first();\n\t\t\t\ttheInput.val('0');\n\t\t\t\ttheInput.attr('name','" . $fieldname . "['+uniqueRowNum" . $field->id . "+'][hits]');\n\t\t\t\ttheInput.attr('id','" . $elementid . "_'+uniqueRowNum" . $field->id . "+'_hits');\n\t\t\t\t\n\t\t\t\t// Set hits to zero for new row value\n\t\t\t\tnewField.find('span span').html('0');\n\t\t\t\t";
            }
            // Add new field to DOM
            $js .= "\n\t\t\t\tlastField ?\n\t\t\t\t\t(insert_before ? newField.insertBefore( lastField ) : newField.insertAfter( lastField ) ) :\n\t\t\t\t\tnewField.appendTo( jQuery('#sortables_" . $field->id . "') ) ;\n\t\t\t\tif (remove_previous) lastField.remove();\n\t\t\t\t";
            // Add new element to sortable objects (if field not in group)
            if (!$use_ingroup) {
                $js .= "\n\t\t\t\tjQuery('#sortables_" . $field->id . "').sortable({\n\t\t\t\t\thandle: '.fcfield-drag-handle',\n\t\t\t\t\tcontainment: 'parent',\n\t\t\t\t\ttolerance: 'pointer'\n\t\t\t\t});\n\t\t\t\t";
            }
            // Show new field, increment counters
            $js .= "\n\t\t\t\t//newField.fadeOut({ duration: 400, easing: 'swing' }).fadeIn({ duration: 200, easing: 'swing' });\n\t\t\t\tif (scroll_visible) fc_scrollIntoView(newField, 1);\n\t\t\t\tif (animate_visible) newField.css({opacity: 0.1}).animate({ opacity: 1 }, 800);\n\t\t\t\t\n\t\t\t\t// Enable tooltips on new element\n\t\t\t\t" . (FLEXI_J30GE ? "\n\t\t\t\t\tnewField.find('.hasTooltip').tooltip({'html': true,'container': newField});\n\t\t\t\t" : "\n\t\t\t\t\tvar tipped_elements = newField.find('.hasTip');\n\t\t\t\t\ttipped_elements.each(function() {\n\t\t\t\t\t\tvar title = this.get('title');\n\t\t\t\t\t\tif (title) {\n\t\t\t\t\t\t\tvar parts = title.split('::', 2);\n\t\t\t\t\t\t\tthis.store('tip:title', parts[0]);\n\t\t\t\t\t\t\tthis.store('tip:text', parts[1]);\n\t\t\t\t\t\t}\n\t\t\t\t\t});\n\t\t\t\t\tvar ajax_JTooltips = new Tips(\$('#sortables_" . $field->id . "').getNext().getElements('.hasTip'), { maxTitleChars: 50, fixed: false});\n\t\t\t\t") . "\n\t\t\t\t\n\t\t\t\trowCount" . $field->id . "++;       // incremented / decremented\n\t\t\t\tuniqueRowNum" . $field->id . "++;   // incremented only\n\t\t\t}\n\n\t\t\tfunction deleteField" . $field->id . "(el, groupval_box, fieldval_box)\n\t\t\t{\n\t\t\t\t// Find field value container\n\t\t\t\tvar row = fieldval_box ? fieldval_box : jQuery(el).closest('li');\n\t\t\t\t\n\t\t\t\t// Add empty container if last element, instantly removing the given field value container\n\t\t\t\tif(rowCount" . $field->id . " == 1)\n\t\t\t\t\taddField" . $field->id . "(null, groupval_box, row, {remove_previous: 1, scroll_visible: 0, animate_visible: 0});\n\t\t\t\t\n\t\t\t\t// Remove if not last one, if it is last one, we issued a replace (copy,empty new,delete old) above\n\t\t\t\tif(rowCount" . $field->id . " > 1) {\n\t\t\t\t\t// Destroy the remove/add/etc buttons, so that they are not reclicked, while we do the hide effect (before DOM removal of field value)\n\t\t\t\t\trow.find('.fcfield-delvalue').remove();\n\t\t\t\t\trow.find('.fcfield-insertvalue').remove();\n\t\t\t\t\trow.find('.fcfield-drag-handle').remove();\n\t\t\t\t\t// Do hide effect then remove from DOM\n\t\t\t\t\trow.slideUp(400, function(){ this.remove(); });\n\t\t\t\t\trowCount" . $field->id . "--;\n\t\t\t\t}\n\t\t\t}\n\t\t\t";
            $css .= '';
            $remove_button = '<span class="fcfield-delvalue" title="' . JText::_('FLEXI_REMOVE_VALUE') . '" onclick="deleteField' . $field->id . '(this);"></span>';
            $move2 = '<span class="fcfield-drag-handle" title="' . JText::_('FLEXI_CLICK_TO_DRAG') . '"></span>';
            $add_here = '';
            $add_here .= $add_position == 2 || $add_position == 3 ? '<span class="fcfield-insertvalue fc_before" onclick="addField' . $field->id . '(null, jQuery(this).closest(\'ul\'), jQuery(this).closest(\'li\'), {insert_before: 1});" title="' . JText::_('FLEXI_ADD_BEFORE') . '"></span> ' : '';
            $add_here .= $add_position == 1 || $add_position == 3 ? '<span class="fcfield-insertvalue fc_after"  onclick="addField' . $field->id . '(null, jQuery(this).closest(\'ul\'), jQuery(this).closest(\'li\'), {insert_before: 0});" title="' . JText::_('FLEXI_ADD_AFTER') . '"></span> ' : '';
        } else {
            $remove_button = '';
            $move2 = '';
            $add_here = '';
            $js .= '';
            $css .= '';
        }
        if ($js) {
            $document->addScriptDeclaration($js);
        }
        if ($css) {
            $document->addStyleDeclaration($css);
        }
        // *****************************************
        // Create field's HTML display for item form
        // *****************************************
        $field->html = array();
        $n = 0;
        //if ($use_ingroup) {print_r($field->value);}
        foreach ($field->value as $value) {
            // Compatibility for unserialized values (e.g. reload user input after form validation error) or for NULL values in a field group
            if (!is_array($value)) {
                $v = !empty($value) ? @unserialize($value) : false;
                $value = $v !== false || $v === 'b:0;' ? $v : array('link' => $value, 'title' => '', 'linktext' => '', 'class' => '', 'id' => '', 'hits' => 0);
            }
            if (empty($value['link']) && !$use_ingroup && $n) {
                continue;
            }
            // If at least one added, skip empty if not in field group
            $fieldname_n = $fieldname . '[' . $n . ']';
            $elementid_n = $elementid . '_' . $n;
            // NOTE: HTML tag id of this form element needs to match the -for- attribute of label HTML tag of this FLEXIcontent field, so that label will be marked invalid when needed
            $value['link'] = !empty($value['link']) ? $value['link'] : $default_link;
            $value['link'] = htmlspecialchars(FLEXI_J30GE ? JStringPunycode::urlToUTF8($value['link']) : $value['link'], ENT_COMPAT, 'UTF-8');
            $link = '
				<tr><td class="key">' . JText::_('FLEXI_FIELD_URL') . '</td><td>
					<input class="urllink fcfield_textval ' . $required . '" name="' . $fieldname_n . '[link]" id="' . $elementid_n . '" type="text" size="' . $size . '" value="' . $value['link'] . '" />
				</td></tr>';
            $autoprefix = '';
            if ($allow_relative_addrs == 2) {
                $_tip_title = flexicontent_html::getToolTip(null, 'FLEXI_EXTWL_IS_RELATIVE_DESC', 1, 1);
                $_tip_class = FLEXI_J30GE ? 'hasTooltip' : 'hasTip';
                $is_absolute = (bool) parse_url($value['link'], PHP_URL_SCHEME);
                // preg_match("#^http|^https|^ftp#i", $value['link']);
                $autoprefix = '
				<tr><td class="key ' . $_tip_class . '" title="' . $_tip_title . '">' . JText::_('FLEXI_EXTWL_IS_RELATIVE') . ' *</td><td>
					<input class="autoprefix" id="' . $elementid_n . '_autoprefix_0" name="' . $fieldname_n . '[autoprefix]" type="radio" value="0" ' . (!$is_absolute ? 'checked="checked"' : '') . '/>
					<label for="' . $elementid_n . '_autoprefix_0">' . JText::_('FLEXI_YES') . '</label>
					<input class="autoprefix" id="' . $elementid_n . '_autoprefix_1" name="' . $fieldname_n . '[autoprefix]" type="radio" value="1" ' . ($is_absolute ? 'checked="checked"' : '') . '/>
					<label for="' . $elementid_n . '_autoprefix_1">' . JText::_('FLEXI_NO') . '</label>
				</td></tr>';
            }
            $title = '';
            if ($usetitle) {
                $value['title'] = !empty($value['title']) ? $value['title'] : $default_title;
                $value['title'] = htmlspecialchars($value['title'], ENT_COMPAT, 'UTF-8');
                $title = '
				<tr><td class="key">' . JText::_('FLEXI_EXTWL_URLTITLE') . '</td><td>
					<input class="urltitle fcfield_textval" name="' . $fieldname_n . '[title]" id="' . $elementid_n . '_title" type="text" size="' . $size . '" value="' . $value['title'] . '" />
				</td></tr>';
            }
            $linktext = '';
            if ($usetext) {
                $value['linktext'] = !empty($value['linktext']) ? $value['linktext'] : $default_text;
                $value['linktext'] = htmlspecialchars($value['linktext'], ENT_COMPAT, 'UTF-8');
                $linktext = '
				<tr><td class="key">' . JText::_('FLEXI_EXTWL_URLLINK_TEXT') . '</td><td>
					<input class="urllinktext fcfield_textval" name="' . $fieldname_n . '[linktext]" id="' . $elementid_n . '_linktext" type="text" size="' . $size . '" value="' . $value['linktext'] . '" />
				</td></tr>';
            }
            $class = '';
            if ($useclass) {
                $value['class'] = !empty($value['class']) ? $value['class'] : $default_class;
                $value['class'] = htmlspecialchars($value['class'], ENT_COMPAT, 'UTF-8');
            }
            if ($useclass == 1) {
                $class = '
					<tr><td class="key">' . JText::_('FLEXI_EXTWL_URLCLASS') . '</td><td>
						<input class="urlclass fcfield_textval" name="' . $fieldname_n . '[class]" id="' . $elementid_n . '_class" type="text" size="' . $size . '" value="' . $value['class'] . '" />
					</td></tr>';
            } else {
                if ($useclass == 2) {
                    $class_attribs = ' class="urlclass" ';
                    $class = '
					<tr><td class="key">' . JText::_('FLEXI_EXTWL_URLCLASS') . '</td><td>
						' . JHTML::_('select.genericlist', $class_options, $fieldname_n . '[class]', $class_attribs, 'value', 'text', $value['class'], $class_elementid = $elementid_n . '_class') . '
					</td></tr>';
                }
            }
            $id = '';
            if ($useid) {
                $value['id'] = !empty($value['id']) ? $value['id'] : $default_id;
                $value['id'] = htmlspecialchars($value['id'], ENT_COMPAT, 'UTF-8');
                $id = '
				<tr><td class="key">' . JText::_('FLEXI_EXTWL_URLID') . '</td><td>
					<input class="urlid" name="' . $fieldname_n . '[id]" id="' . $elementid_n . '_id" type="text" size="' . $size . '" value="' . $value['id'] . '" />
				</td></tr>';
            }
            $hits = '';
            if ($usehits) {
                $hits = (int) @$value['hits'];
                $hits = '
					<tr><td class="key">' . JText::_('FLEXI_EXTWL_POPULARITY') . '</td><td>
						<input class="urlhits" name="' . $fieldname_n . '[hits]" id="' . $elementid_n . '_hits" type="hidden" value="' . $hits . '" />
						<span class="hits"><span class="hitcount">' . $hits . '</span> ' . JText::_('FLEXI_FIELD_HITS') . '</span>
					</td></tr>';
            }
            $field->html[] = '
				' . ($use_ingroup ? '' : $move2) . '
				' . ($use_ingroup ? '' : $remove_button) . '
				' . ($use_ingroup || !$add_position ? '' : $add_here) . '
				' . ($use_ingroup ? '' : '<div class="fcclear"></div>') . '
				<table class="admintable"><tbody>
				' . $link . '
				' . $autoprefix . '
				' . $title . '
				' . $linktext . '
				' . $class . '
				' . $id . '
				' . $hits . '
				</tbody></table>
				';
            $n++;
            if (!$multiple) {
                break;
            }
            // multiple values disabled, break out of the loop, not adding further values even if the exist
        }
        if ($use_ingroup) {
            // do not convert the array to string if field is in a group
        } else {
            if ($multiple) {
                // handle multiple records
                $field->html = '<li class="' . $value_classes . '">' . implode('</li><li class="' . $value_classes . '">', $field->html) . '</li>';
                $field->html = '<ul class="fcfield-sortables" id="sortables_' . $field->id . '">' . $field->html . '</ul>';
                if (!$add_position) {
                    $field->html .= '<span class="fcfield-addvalue fccleared" onclick="addField' . $field->id . '(this);" title="' . JText::_('FLEXI_ADD_TO_BOTTOM') . '"></span>';
                }
            } else {
                // handle single values
                $field->html = '<div class="fcfieldval_container valuebox fcfieldval_container_' . $field->id . '">' . $field->html[0] . '</div>';
            }
        }
    }
Пример #14
0
    function onDisplayField(&$field, &$item)
    {
        if (!in_array($field->field_type, self::$field_types)) {
            return;
        }
        $field->label = JText::_($field->label);
        $use_ingroup = 0;
        // Not supported  //$field->parameters->get('use_ingroup', 0);
        if ($use_ingroup) {
            $field->formhidden = 3;
        }
        if ($use_ingroup && empty($field->ingroup)) {
            return;
        }
        // initialize framework objects and other variables
        $document = JFactory::getDocument();
        $app = JFactory::getApplication();
        // ****************
        // Number of values
        // ****************
        $multiple = $use_ingroup || 1;
        $max_values = $use_ingroup ? 0 : (int) $field->parameters->get('max_values', 0);
        $required = $field->parameters->get('required', 0);
        $required = $required ? ' required' : '';
        // Input field configuration
        $size = (int) $field->parameters->get('size', 30);
        $client = $app->isAdmin() ? '../' : '';
        $flexiparams = JComponentHelper::getParams('com_flexicontent');
        $mediapath = $flexiparams->get('media_path', 'components/com_flexicontent/medias');
        // Load file data
        if (!$field->value) {
            $files_data = array();
            $field->value = array();
        } else {
            $files_data = $this->getFileData($field->value, $published = false);
            $field->value = array();
            foreach ($files_data as $file_id => $file_data) {
                $field->value[] = $file_id;
            }
        }
        // CSS classes of value container
        $value_classes = 'fcfieldval_container valuebox fcfieldval_container_' . $field->id;
        $value_classes .= ' floated';
        // Field name and HTML TAG id
        $fieldname = 'custom[' . $field->name . '][]';
        //$elementid = 'custom_'.$field->name;
        $js = "";
        $css = "";
        if ($multiple) {
            // Add the drag and drop sorting feature
            if (!$use_ingroup) {
                $js .= "\n\t\t\tjQuery(document).ready(function(){\n\t\t\t\tjQuery('#sortables_" . $field->id . "').sortable({\n\t\t\t\t\thandle: '.fcfield-drag-handle',\n\t\t\t\t\tcontainment: 'parent',\n\t\t\t\t\ttolerance: 'pointer'\n\t\t\t\t});\n\t\t\t});\n\t\t\t";
            }
            if ($max_values) {
                FLEXI_J16GE ? JText::script("FLEXI_FIELD_MAX_ALLOWED_VALUES_REACHED", true) : fcjsJText::script("FLEXI_FIELD_MAX_ALLOWED_VALUES_REACHED", true);
            }
            $js .= "\n\t\t\tvar uniqueRowNum" . $field->id . "\t= " . count($field->value) . ";  // Unique row number incremented only\n\t\t\tvar rowCount" . $field->id . "\t= " . count($field->value) . ";      // Counts existing rows to be able to limit a max number of values\n\t\t\tvar maxValues" . $field->id . " = " . $max_values . ";\n\t\t\t\n\t\t\tfunction qfSelectFile" . $field->id . "(obj, id, file)\n\t\t\t{\n\t\t\t\tvar insert_before   = (typeof params!== 'undefined' && typeof params.insert_before   !== 'undefined') ? params.insert_before   : 0;\n\t\t\t\tvar remove_previous = (typeof params!== 'undefined' && typeof params.remove_previous !== 'undefined') ? params.remove_previous : 0;\n\t\t\t\tvar scroll_visible  = (typeof params!== 'undefined' && typeof params.scroll_visible  !== 'undefined') ? params.scroll_visible  : 1;\n\t\t\t\tvar animate_visible = (typeof params!== 'undefined' && typeof params.animate_visible !== 'undefined') ? params.animate_visible : 1;\n\t\t\t\t\n\t\t\t\tif((rowCount" . $field->id . " >= maxValues" . $field->id . ") && (maxValues" . $field->id . " != 0)) {\n\t\t\t\t\talert(Joomla.JText._('FLEXI_FIELD_MAX_ALLOWED_VALUES_REACHED') + maxValues" . $field->id . ");\n\t\t\t\t\treturn 'cancel';\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\tif (1)\n\t\t\t\t{\n\t\t\t\t\t// A non-empty container is being removed ... get counter (which is optionally used as 'required' form element and empty it if is 1, or decrement if 2 or more)\n\t\t\t\t\tvar valcounter = document.getElementById('" . $field->name . "');\n\t\t\t\t\tif ( typeof valcounter.value === 'undefined' || valcounter.value=='' ) valcounter.value = '1';\n\t\t\t\t\telse valcounter.value = parseInt(valcounter.value) + 1;\n\t\t\t\t\t//if(window.console) window.console.log ('valcounter.value: ' + valcounter.value);\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\tif (file.substring(0,7)!='http://' || file.substring(0,8)!='https://') {\n\t\t\t\t\tfile = '" . str_replace('\\', '/', JPATH_ROOT) . "/" . $mediapath . "/'+file;\n\t\t\t\t}\n\t\t\t\tthumb_src = '" . JURI::root(true) . "/components/com_flexicontent/librairies/phpthumb/phpThumb.php?src='+file+'&w=100&h=100&zc=1';\n\t\t\t\t\n\t\t\t\tvar lastField = null;\n\t\t\t\tvar newField = jQuery('\\\n\t\t\t\t<li class=\"" . $value_classes . "\">\\\n\t\t\t\t\t<img alt=\"Thumbnail\" src=\"'+thumb_src+'\" class=\"thumbs\">\\\n\t\t\t\t\t<input type=\"hidden\" id=\"a_id'+id+'_" . $field->id . "\" name=\"" . $fieldname . "\" value=\"'+id+'\" class=\"contains_fileid\"/> \\\n\t\t\t\t\t<span class=\"fcfield-drag-handle\" title=\"" . JText::_('FLEXI_CLICK_TO_DRAG') . "\"></span> \\\n\t\t\t\t\t<span class=\"fcfield-button fcfield-delvalue\" title=\"" . JText::_('FLEXI_REMOVE_VALUE') . "\" onclick=\"deleteField" . $field->id . "(this);\"></span> \\\n\t\t\t\t</li>\\\n\t\t\t\t');\n\t\t\t\t\t";
            // Add new field to DOM
            $js .= "\n\t\t\t\tlastField ?\n\t\t\t\t\t(insert_before ? newField.insertBefore( lastField ) : newField.insertAfter( lastField ) ) :\n\t\t\t\t\tnewField.appendTo( jQuery('#sortables_" . $field->id . "') ) ;\n\t\t\t\tif (remove_previous) lastField.remove();\n\t\t\t\t";
            // Add new element to sortable objects (if field not in group)
            if (!$use_ingroup) {
                $js .= "\n\t\t\t\tjQuery('#sortables_" . $field->id . "').sortable({\n\t\t\t\t\thandle: '.fcfield-drag-handle',\n\t\t\t\t\tcontainment: 'parent',\n\t\t\t\t\ttolerance: 'pointer'\n\t\t\t\t});\n\t\t\t\t";
            }
            // Show new field, increment counters
            $js .= "\n\t\t\t\t//newField.fadeOut({ duration: 400, easing: 'swing' }).fadeIn({ duration: 200, easing: 'swing' });\n\t\t\t\tif (scroll_visible) fc_scrollIntoView(newField, 1);\n\t\t\t\tif (animate_visible) newField.css({opacity: 0.1}).animate({ opacity: 1 }, 800);\n\t\t\t\t\n\t\t\t\trowCount" . $field->id . "++;       // incremented / decremented\n\t\t\t\tuniqueRowNum" . $field->id . "++;   // incremented only\n\t\t\t}\n\n\t\t\tfunction deleteField" . $field->id . "(el, groupval_box, fieldval_box)\n\t\t\t{\n\t\t\t\t// Find field value container\n\t\t\t\tvar row = fieldval_box ? fieldval_box : jQuery(el).closest('li');\n\t\t\t\t\n\t\t\t\tif ( 1 )\n\t\t\t\t{\n\t\t\t\t\t// A deleted container always has a value, thus decrement (or empty) the counter value in the 'required' form element\n\t\t\t\t\tvar valcounter = document.getElementById('" . $field->name . "');\n\t\t\t\t\tvalcounter.value = ( !valcounter.value || valcounter.value=='1' )  ?  ''  :  parseInt(valcounter.value) - 1;\n\t\t\t\t\t//if(window.console) window.console.log ('valcounter.value: ' + valcounter.value);\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\t// Add empty container if last element, instantly removing the given field value container\n\t\t\t\tif(rowCount" . $field->id . " == 0)\n\t\t\t\t\taddField" . $field->id . "(null, groupval_box, row, {remove_previous: 1, scroll_visible: 0, animate_visible: 0});\n\t\t\t\t\n\t\t\t\t// Remove if not last one, if it is last one, we issued a replace (copy,empty new,delete old) above\n\t\t\t\tif(rowCount" . $field->id . " > 0) {\n\t\t\t\t\t// Destroy the remove/add/etc buttons, so that they are not reclicked, while we do the hide effect (before DOM removal of field value)\n\t\t\t\t\trow.find('.fcfield-delvalue').remove();\n\t\t\t\t\trow.find('.fcfield-insertvalue').remove();\n\t\t\t\t\trow.find('.fcfield-drag-handle').remove();\n\t\t\t\t\t// Do hide effect then remove from DOM\n\t\t\t\t\trow.slideUp(400, function(){ this.remove(); });\n\t\t\t\t\trowCount" . $field->id . "--;\n\t\t\t\t}\n\t\t\t}\n\t\t\t";
            $css .= '
			#sortables_' . $field->id . ' li img.thumbs { border:1px solid silver; padding:0;  margin:0px 4px 6px 0px; float:left; clear:both; }
			';
            $remove_button = '<span class="fcfield-delvalue" title="' . JText::_('FLEXI_REMOVE_VALUE') . '" onclick="deleteField' . $field->id . '(this);"></span>';
            $move2 = '<span class="fcfield-drag-handle" title="' . JText::_('FLEXI_CLICK_TO_DRAG') . '"></span>';
        } else {
            $remove_button = '';
            $move2 = '';
            $js .= '';
            $css .= '';
        }
        if ($js) {
            $document->addScriptDeclaration($js);
        }
        if ($css) {
            $document->addStyleDeclaration($css);
        }
        JHTML::_('behavior.modal', 'a.modal_' . $field->id);
        $field->html = array();
        $n = 0;
        foreach ($files_data as $file_id => $file_data) {
            $img_path = substr($file_data->filename, 0, 7) != 'http://' || substr($file_data->filename, 0, 8) != 'https://' ? JPATH_ROOT . DS . $mediapath . DS . $file_data->filename : $file_data->filename;
            $src = JURI::root(true) . '/components/com_flexicontent/librairies/phpthumb/phpThumb.php?src=' . $img_path . '&w=100&h=100&zc=1';
            $field->html[] = '
				<img class="thumbs" src="' . $src . '" alt="Thumbnail" />
				' . '
				' . '<input type="hidden" id="a_id' . $file_id . '_' . $field->id . '" name="' . $fieldname . '" value="' . $file_id . '"  class="contains_fileid" />' . '
				' . ($use_ingroup ? '' : $move2) . '
				' . ($use_ingroup ? '' : $remove_button) . '
				';
            $n++;
            //if ($max_values && $n >= $max_values) break;  // break out of the loop, if maximum file limit was reached
        }
        if ($use_ingroup) {
            // do not convert the array to string if field is in a group
        } else {
            if ($multiple) {
                // handle multiple records
                $field->html = '<li class="' . $value_classes . '">' . implode('</li><li class="' . $value_classes . '">', $field->html) . '</li>';
                $field->html = '<ul class="fcfield-sortables" id="sortables_' . $field->id . '">' . $field->html . '</ul>';
            } else {
                // handle single values
                $field->html = '<div class="fcfieldval_container valuebox fcfieldval_container_' . $field->id . '">' . $field->html[0] . '</div>';
            }
        }
        // Add button for popup file selection
        $autoselect = $field->parameters->get('autoselect', 1);
        $linkfsel = JURI::base(true) . '/index.php?option=com_flexicontent&amp;view=fileselement&amp;tmpl=component&amp;layout=image&amp;filter_secure=M&amp;index=' . $n . '&amp;autoselect=' . $autoselect . '&amp;field=' . $field->id . '&amp;' . (FLEXI_J30GE ? JSession::getFormToken() : JUtility::getToken()) . '=1';
        $field->html .= '
			<span class="fcfield-button-add">
				<a class="modal_' . $field->id . '" title="' . JText::_('FLEXI_ADD_FILE') . '" href="' . $linkfsel . '" rel="{handler: \'iframe\', size: {x:(MooTools.version>=\'1.2.4\' ? window.getSize().x : window.getSize().size.x)-100, y: (MooTools.version>=\'1.2.4\' ? window.getSize().y : window.getSize().size.y)-100}}">' . JText::_('FLEXI_ADD_FILE') . '</a>
			</span>
			';
        $field->html .= '<input id="' . $field->name . '" class="' . $required . '" type="hidden" name="__fcfld_valcnt__[' . $field->name . ']" value="' . ($n ? $n : '') . '" />';
    }
Пример #15
0
	/**
	 * Utility function to load each JS Frameworks once
	 *
	 * @param 	string 		$text
	 * @param 	int 		$nb
	 * @return 	string
	 * @since 1.5
	 */
	static function loadFramework( $framework, $mode='' )
	{
		// Detect already loaded framework
		static $_loaded = array();
		if ( isset($_loaded[$framework]) ) return $_loaded[$framework];
		$_loaded[$framework] = false;
		
		// Get frameworks that are configured to be loaded manually in frontend (e.g. via the Joomla template)
		$app = JFactory::getApplication();
		static $load_frameworks = null;
		static $load_jquery = null;
		if ( !isset($load_frameworks[$framework]) ) {
			$flexiparams = JComponentHelper::getParams('com_flexicontent');
			//$load_frameworks = $flexiparams->get('load_frameworks', array('jQuery','image-picker','masonry','select2','inputmask','prettyCheckable','fancybox'));
			//$load_frameworks = FLEXIUtilities::paramToArray($load_frameworks);
			//$load_frameworks = array_flip($load_frameworks);
			//$load_jquery = isset($load_frameworks['jQuery']) || !$app->isSite();
			if ( $load_jquery===null ) $load_jquery = $flexiparams->get('loadfw_jquery', 1)==1  ||  !$app->isSite();
			$load_framework = $flexiparams->get( 'loadfw_'.strtolower(str_replace('-','_',$framework)), 1 );
			$load_frameworks[$framework] = $load_framework==1  ||  ($load_framework==2 && !$app->isSite());
		}
		
		// Set loaded flag
		$_loaded[$framework] = $load_frameworks[$framework];
		// Do not progress further if it is disabled
		if ( !$load_frameworks[$framework] ) return false;
		
		// Load Framework
		$document = JFactory::getDocument();
		$js = "";
		$css = "";
		switch ( $framework )
		{
			case 'jQuery':
				if ($load_jquery) flexicontent_html::loadJQuery();
				break;
			
			case 'mCSB':
				if ($load_jquery) flexicontent_html::loadJQuery();
				
				$framework_path = JURI::root(true).'/components/com_flexicontent/librairies/mCSB';
				$document->addScript($framework_path.'/jquery.mCustomScrollbar.min.js');
				$document->addStyleSheet($framework_path.'/jquery.mCustomScrollbar.css');
				$js .= "
					jQuery(document).ready(function(){
					    jQuery('.fc_add_scroller').mCustomScrollbar({
					    	theme:'dark-thick',
					    	advanced:{updateOnContentResize: true}
					    });
					    jQuery('.fc_add_scroller_horizontal').mCustomScrollbar({
					    	theme:'dark-thick',
					    	horizontalScroll:true,
					    	advanced:{updateOnContentResize: true}
					    });
					});
				";
				break;
			
			case 'image-picker':
				if ($load_jquery) flexicontent_html::loadJQuery();
				
				$framework_path = JURI::root(true).'/components/com_flexicontent/librairies/image-picker';
				$document->addScript($framework_path.'/image-picker.min.js');
				$document->addStyleSheet($framework_path.'/image-picker.css');
				break;
			
			case 'masonry':
				$framework_path = JURI::root(true).'/components/com_flexicontent/librairies/masonry';
				$document->addScript($framework_path.'/masonry.pkgd.min.js');
				
				break;
			
			case 'select2':
				if ($load_jquery) flexicontent_html::loadJQuery();
				
				$framework_path = JURI::root(true).'/components/com_flexicontent/librairies/select2';
				$framework_folder = JPATH_SITE .DS.'components'.DS.'com_flexicontent'.DS.'librairies'.DS.'select2';
				$document->addScript($framework_path.'/select2.min.js');
				$document->addStyleSheet($framework_path.'/select2.css');
				
				$user_lang = flexicontent_html::getUserCurrentLang();
				if ( $user_lang && $user_lang!='en' )
				{
					// Try language shortcode
					$framework_folder.DS.'select2_locale_'.$user_lang.'.js';
					if ( file_exists($framework_folder.DS.'select2_locale_'.$user_lang.'.js') ) {
						$document->addScript($framework_path.'/select2_locale_'.$user_lang.'.js');
					}
					// Try coutry language code
					else {
						$languages = FLEXIUtilities::getLanguages($hash='shortcode');
						$lang_code = isset($languages->$user_lang->code) ? $languages->$user_lang->code : false;
						if ( $lang_code && file_exists($framework_folder.'/select2_locale_'.$lang_code.'.js') ) {
							$document->addScript($framework_path.'/select2_locale_'.$lang_code.'.js');
						}
					}
				}
				
				$js .= "
					jQuery(document).ready(function() {
						
						"/* Attach select2 to specific to select elements having specific CSS class, show selected values as both: unselectable and disabled */."
						jQuery('select.use_select2_lib').select2({
							/*hideSelectionFromResult: function(selectedObject) { selectedObject.removeClass('select2-result-selectable').addClass('select2-result-unselectable').addClass('select2-disabled'); return false; }*/
						});
						
						jQuery('div.use_select2_lib').each(function() {
							var el_container = jQuery(this);
							var el_select = el_container.next('select');
							
							"/* MULTI-SELECT2: Initialize internal labels, placing the label so that it overlaps the text filter box */."
							var fc_label_text = el_select.attr('data-fc_label_text');
							if (!fc_label_text) fc_label_text = el_select.attr('fc_label_text');
							if (fc_label_text) {
								var _label = (fc_label_text.length >= 30) ? fc_label_text.substring(0, 28) + '...' : fc_label_text;
								
								jQuery('<span/>', {
									'class': 'fc_has_inner_label fc_has_inner_label_select2',
									'text': _label
								}).prependTo(el_container.find('.select2-search-field'));
							}
							
							"/* MULTI-SELECT2: Initialize internal prompts, placing the prompt so that it overlaps the text filter box */."
							var fc_prompt_text = el_select.attr('data-fc_prompt_text');
							if (!fc_prompt_text) fc_prompt_text = el_select.attr('fc_prompt_text');
							if (fc_prompt_text) {
								var _prompt = (fc_prompt_text.length >= 30) ? fc_prompt_text.substring(0, 28) + '...' : fc_prompt_text;
								
								jQuery('<span/>', {
									'class': 'fc_has_inner_prompt fc_has_inner_prompt_select2',
									'text': _prompt
								}).prependTo(el_container.find('.select2-search-field')).hide();
							}
							
							"/* SINGLE-SELECT2: Highlight selects with an active value */."
							if ( ! el_select.attr('multiple') ) {
								var el = el_container.find('.select2-choice');
								var val = el_select.val();
								if (val === null) {
									el.addClass('fc_highlight_disabled');
								} else if (val.length) {
									el.addClass('fc_highlight');
								} else {
									el.removeClass('fc_highlight');
								}
							}
						});
						
						"/* MULTI-SELECT2: */."
						jQuery('select.use_select2_lib').on('select2-open', function() {
							"/* Add events to handle focusing the text filter box (hide inner label) */."
							var el_container = jQuery(this).parent();
							var el = jQuery(this).parent().find('.select2-input');
							var el_label = el.prevAll('.fc_has_inner_label');
							if (el_label) el_label.hide();
							var el_prompt = el.prevAll('.fc_has_inner_prompt');
							if (el_prompt) el_prompt.show();
							
							"/* Allow listing already selected options WHEN having class 'select2_list_selected' */."
							if (jQuery(this).hasClass('select2_list_selected')) {
								var els = jQuery('#select2-drop').find('.select2-selected');
								els.addClass('select2-selected-highlight').addClass('select2-disabled').removeClass('select2-selected').removeClass('select2-result-selectable');
							}
						}).on('select2-close', function() {
							"/* Add events to handle bluring the text filter box (show inner label) */."
							var el_container = jQuery(this).parent();
							var el = jQuery(this).parent().find('.select2-input');
							var el_label = el.prevAll('.fc_has_inner_label');
							if (el_label) el_label.show();
							var el_prompt = el.prevAll('.fc_has_inner_prompt');
							if (el_prompt) el_prompt.hide();
							
							"/* Restore already selected options state */."
							if (jQuery(this).hasClass('select2_list_selected')) {
								var els = jQuery('#select2-drop').find('.select2-selected-highlight');
								els.removeClass('select2-selected-highlight').removeClass('select2-disabled').addClass('select2-result-selectable');
							}
						}).on
						
						"/* SINGLE-SELECT2: Add events to handle highlighting selected value */."
						('change', function() {
							var el_select = jQuery(this);
							if ( ! el_select.attr('multiple') ) {
								var el = jQuery(this).prev('div').find('.select2-choice');
								var val = el_select.val();
								if (val.length) {
									el.addClass('fc_highlight');
								} else {
									el.removeClass('fc_highlight');
								}
							}
						});
						
						"/* SINGLE-SELECT2: Add events to handle highlighting selected value */."
						jQuery('div.use_select2_lib.select2-container-multi input').on('keydown', function() {
							var el = jQuery(this);
							setTimeout(function() {
								if (el.val().length) {
									var el_prompt = el.prevAll('.fc_has_inner_prompt');
									if (el_prompt) el_prompt.hide();
								} else {
									var el_prompt = el.prevAll('.fc_has_inner_prompt');
									if (el_prompt) el_prompt.show();
								}
							}, 0);
						});
						
						"/* SELECT2: scrollbar wrap problem */."
						jQuery('select.use_select2_lib').on('loaded open', function() {
							var ul = jQuery('#select2-drop ul.select2-results');
							var needsScroll= ul.prop('scrollHeight') > ul.prop('clientHeight');
							if (needsScroll) ul.css('overflow-y', 'scroll');
							else  ul.css('overflow-y', 'auto');
						});
						
					});
				";
				break;
			
			case 'inputmask':
				if ($load_jquery) flexicontent_html::loadJQuery();
				
				$framework_path = JURI::root(true).'/components/com_flexicontent/librairies/inputmask';
				$document->addScript($framework_path.'/jquery.inputmask.bundle.min.js');
				
				// Extra inputmask declarations definitions, e.g. ...
				/*$js .= "
					jQuery.extend(jQuery.inputmask.defaults.definitions, {
					    'f': {
					        \"validator\": \"[0-9\(\)\.\+/ ]\",
					        \"cardinality\": 1,
					        'prevalidator': null
					    }
					});
				";*/
				
				// Attach inputmask to all input fields that have appropriate tag parameters
				$js .= "
					jQuery(document).ready(function(){
					    jQuery(\":input\").inputmask();
					});
				";
				break;
			
			case 'prettyCheckable':
				if ($load_jquery) flexicontent_html::loadJQuery();
				
				$framework_path = JURI::root(true).'/components/com_flexicontent/librairies/prettyCheckable';
				$document->addScript($framework_path.'/prettyCheckable.js');
				$document->addStyleSheet($framework_path.'/prettyCheckable.css');
				$js .= "
					jQuery(document).ready(function(){
						jQuery('input.use_prettycheckable').prettyCheckable();
						jQuery('div.fcradiocheckimage').each(
							function() {
								jQuery(this).find('label').append(jQuery(this).next('label').html());
								jQuery(this).next('label').remove();
							});
					});
				";
				break;
			
			case 'fancybox':
				if ($load_jquery) flexicontent_html::loadJQuery();
				
				$framework_path = JURI::root(true).'/components/com_flexicontent/librairies/fancybox';
				
				// Add mousewheel plugin (this is optional)
				$document->addScript($framework_path.'/lib/jquery.mousewheel-3.0.6.pack.js');
				
				// Add fancyBox CSS / JS
				$document->addStyleSheet($framework_path.'/source/jquery.fancybox.css?v=2.1.1');
				$document->addScript($framework_path.'/source/jquery.fancybox.pack.js?v=2.1.1');
				
				// Optionally add helpers - button, thumbnail and/or media
				$document->addStyleSheet($framework_path.'/source/helpers/jquery.fancybox-buttons.css?v=1.0.4');
				$document->addScript($framework_path.'/source/helpers/jquery.fancybox-buttons.js?v=1.0.4');
				$document->addScript($framework_path.'/source/helpers/jquery.fancybox-media.js?v=1.0.4');
				$document->addStyleSheet($framework_path.'/source/helpers/jquery.fancybox-thumbs.css?v=1.0.7');
				$document->addScript($framework_path.'/source/helpers/jquery.fancybox-thumbs.js?v=1.0.7');
				
				// Attach fancybox to all elements having a specific CSS class
				$js .= "
					jQuery(document).ready(function(){
						jQuery('.fancybox').fancybox();
					});
				";
				break;
			
			case 'galleriffic':
				if ($load_jquery) flexicontent_html::loadJQuery();
				
				$framework_path = JURI::root(true).'/components/com_flexicontent/librairies/galleriffic';
				$document->addStyleSheet($framework_path.'/css/basic.css');
				$document->addStyleSheet($framework_path.'/css/galleriffic-3.css');
				$document->addScript($framework_path.'/js/jquery.galleriffic.js');
				$document->addScript($framework_path.'/js/jquery.opacityrollover.js');
				
				//$view_width = 500;
				$js = "
				//document.write('<style>.noscript { display: none; }</style>');
				jQuery(document).ready(function() {
					// We only want these styles applied when javascript is enabled
					jQuery('div.navigation').css({'width' : '150px', 'float' : 'left'});
					jQuery('div.content').css({'display' : 'inline-block', 'float' : 'none'});
	
					// Initially set opacity on thumbs and add
					// additional styling for hover effect on thumbs
					var onMouseOutOpacity = 0.67;
					jQuery('#gf_thumbs ul.thumbs li').opacityrollover({
						mouseOutOpacity:   onMouseOutOpacity,
						mouseOverOpacity:  1.0,
						fadeSpeed:         'fast',
						exemptionSelector: '.selected'
					});
					
					// Initialize Advanced Galleriffic Gallery
					var gallery = jQuery('#gf_thumbs').galleriffic({
						delay:                     2500,
						numThumbs:                 4,
						preloadAhead:              10,
						enableTopPager:            true,
						enableBottomPager:         true,
						maxPagesToShow:            20,
						imageContainerSel:         '#gf_slideshow',
						controlsContainerSel:      '#gf_controls',
						captionContainerSel:       '#gf_caption',
						loadingContainerSel:       '#gf_loading',
						renderSSControls:          true,
						renderNavControls:         true,
						playLinkText:              'Play Slideshow',
						pauseLinkText:             'Pause Slideshow',
						prevLinkText:              '&lsaquo; Previous Photo',
						nextLinkText:              'Next Photo &rsaquo;',
						nextPageLinkText:          'Next &rsaquo;',
						prevPageLinkText:          '&lsaquo; Prev',
						enableHistory:             false,
						autoStart:                 false,
						syncTransitions:           true,
						defaultTransitionDuration: 900,
						onSlideChange:             function(prevIndex, nextIndex) {
							// 'this' refers to the gallery, which is an extension of jQuery('#gf_thumbs')
							this.find('ul.thumbs').children()
								.eq(prevIndex).fadeTo('fast', onMouseOutOpacity).end()
								.eq(nextIndex).fadeTo('fast', 1.0);
						},
						onPageTransitionOut:       function(callback) {
							this.fadeTo('fast', 0.0, callback);
						},
						onPageTransitionIn:        function() {
							this.fadeTo('fast', 1.0);
						}
					});
				});
				";
				break;
			
			case 'elastislide':
				if ($load_jquery) flexicontent_html::loadJQuery();
				
				$framework_path = JURI::root(true).'/components/com_flexicontent/librairies/elastislide';
				$document->addStyleSheet($framework_path.'/css/demo.css');
				$document->addStyleSheet($framework_path.'/css/style.css');
				$document->addStyleSheet($framework_path.'/css/elastislide.css');
				
				$document->addScript($framework_path.'/js/jquery.tmpl.min.js');
				$document->addScript($framework_path.'/js/jquery.easing.1.3.js');
				$document->addScript($framework_path.'/js/jquery.elastislide.js');
				//$document->addScript($framework_path.'/js/gallery.js'); // replace with field specific: gallery_tmpl.js
				break;
			
			case 'photoswipe':
				if ($load_jquery) flexicontent_html::loadJQuery();
				
				$framework_path = JURI::root(true).'/components/com_flexicontent/librairies/photoswipe';
				
				//$document->addStyleSheet($framework_path.'/lib/jquery.mobile/jquery.mobile.css');
				$document->addStyleSheet($framework_path.'/photoswipe.css');
				
				//$document->addScript($framework_path.'/lib/jquery.mobile/jquery.mobile.js');
				$document->addScript($framework_path.'/lib/simple-inheritance.min.js');
				//$document->addScript($framework_path.'/lib/jquery.animate-enhanced.min.js');
				$document->addScript($framework_path.'/code.photoswipe.min.js');
				
				$js = "
				jQuery(document).ready(function() {
					var myPhotoSwipe = jQuery('.photoswipe_fccontainer a').photoSwipe(); 
				});
				";
				break;
			
			case 'fcxSlide':
				if ($load_jquery) flexicontent_html::loadJQuery();
				
				$framework_path = JURI::root(true).'/components/com_flexicontent/librairies/fcxSlide';
				$document->addScript($framework_path.'/class.fcxSlide.js');
				//$document->addScript($framework_path.'/class.fcxSlide.packed.js');
				break;
			
			case 'imagesLoaded':
				$framework_path = JURI::root(true).'/components/com_flexicontent/librairies/imagesLoaded';
				$document->addScript($framework_path.'/imagesloaded.pkgd.min.js');
				break;
			
			case 'noobSlide':
				// Make sure mootools are loaded
				FLEXI_J30GE ? JHtml::_('behavior.framework', true) : JHTML::_('behavior.mootools');
				
				$framework_path = JURI::root(true).'/components/com_flexicontent/librairies/noobSlide';
				//$document->addScript($framework_path.'/_class.noobSlide.js');
				$document->addScript($framework_path.'/_class.noobSlide.packed.js');
				break;
			
			case 'zTree':
				if ($load_jquery) flexicontent_html::loadJQuery();
				
				$framework_path = JURI::root(true).'/components/com_flexicontent/librairies/zTree';
				$document->addStyleSheet($framework_path.'/css/flexi_ztree.css');
				$document->addStyleSheet($framework_path.'/css/zTreeStyle/zTreeStyle.css');
				$document->addScript($framework_path.'/js/jquery.ztree.all-3.5.min.js');
				//$document->addScript($framework_path.'/js/jquery.ztree.core-3.5.js');
				//$document->addScript($framework_path.'/js/jquery.ztree.excheck-3.5.js');
				//$document->addScript($framework_path.'/js/jquery.ztree.exedit-3.5.js');
				break;
			
			
			case 'plupload':
				if ($load_jquery) flexicontent_html::loadJQuery();
				
				$framework_path = JURI::root(true).'/components/com_flexicontent/librairies/plupload';
				$document->addScript($framework_path.'/js/plupload.full.min.js');
				
				if ($mode=='ui') {
					$document->addStyleSheet($framework_path.'/js/jquery.ui.plupload/css/jquery.ui.plupload.css');
					$document->addScript($framework_path.'/js/jquery.ui.plupload/jquery.ui.plupload.min.js');
					$document->addScript($framework_path.'/js/themeswitcher.js');
				} else {
					$document->addStyleSheet($framework_path.'/js/jquery.plupload.queue/css/jquery.plupload.queue.css');
					$document->addScript($framework_path.'/js/jquery.plupload.queue/jquery.plupload.queue.js');
				}
				// For debugging
				//$document->addScript($framework_path.'/js/moxie.min.js');
				//$document->addScript($framework_path.'/js/plupload.dev.js');
				break;
			
			case 'flexi_tmpl_common':
				if ($load_jquery) flexicontent_html::loadJQuery();
				flexicontent_html::loadFramework('select2');  // make sure select2 is loaded
				
				$js = "
					var _FC_GET = ".json_encode($_GET).";
				";
				//var _FC_POST = ".json_encode($_POST).";
				//var _FC_REQUEST = ".json_encode($_REQUEST).";
				$document->addScript( JURI::root(true).'/components/com_flexicontent/assets/js/tmpl-common.js' );
				FLEXI_J16GE ? JText::script("FLEXI_APPLYING_FILTERING", true) : fcjsJText::script("FLEXI_APPLYING_FILTERING", true);
				FLEXI_J16GE ? JText::script("FLEXI_TYPE_TO_LIST", true) : fcjsJText::script("FLEXI_TYPE_TO_LIST", true);
				FLEXI_J16GE ? JText::script("FLEXI_TYPE_TO_FILTER", true) : fcjsJText::script("FLEXI_TYPE_TO_FILTER", true);
				break;
			
			case 'flexi-lib':
				if ($load_jquery) flexicontent_html::loadJQuery();
				
				$document->addScript( JURI::root(true).'/components/com_flexicontent/assets/js/flexi-lib.js' );
				FLEXI_J16GE ? JText::script("FLEXI_NOT_AN_IMAGE_FILE", true) : fcjsJText::script("FLEXI_NOT_AN_IMAGE_FILE", true);
				break;
			
			default:
				JFactory::getApplication()->enqueueMessage(__FUNCTION__.' Cannot load unknown Framework: '.$framework, 'error');
				break;
		}
		
		// Add custom JS & CSS code
		if ($js)  $document->addScriptDeclaration($js);
		if ($css) $document->addStyleDeclaration($css);
		return $_loaded[$framework];
	}
Пример #16
0
    function onDisplayField(&$field, &$item)
    {
        if (!in_array($field->field_type, self::$field_types)) {
            return;
        }
        // Check max allowed version
        $manifest_path = JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_flexicontent' . DS . 'manifest.xml';
        $com_xml = JApplicationHelper::parseXMLInstallFile($manifest_path);
        if (version_compare(str_replace(' ', '.', $com_xml['version']), str_replace(' ', '.', self::$prior_to_version), '>=')) {
            echo '
			<span class="fc-note fc-nobgimage fc-mssg">
				Warning: installed version of Field: \'<b>' . $field->field_type . '</b>\' was meant for FLEXIcontent versions prior to: v' . self::$prior_to_version . ' <br/> It may or may not work properly in later versions<br/>
			</span>';
        }
        $field->label = JText::_($field->label);
        $use_ingroup = 0;
        // Field grouped should not be recursively grouped
        if ($use_ingroup) {
            $field->formhidden = 3;
        }
        if ($use_ingroup && empty($field->ingroup)) {
            return;
        }
        $compact_edit = $field->parameters->get('compact_edit', 0);
        // initialize framework objects and other variables
        $document = JFactory::getDocument();
        $db = JFactory::getDBO();
        $tooltip_class = FLEXI_J30GE ? 'hasTooltip' : 'hasTip';
        // ****************
        // Number of values
        // ****************
        $multiple = $use_ingroup || (int) $field->parameters->get('allow_multiple', 0);
        $max_values = $use_ingroup ? 0 : (int) $field->parameters->get('max_values', 0);
        $required = $field->parameters->get('required', 0);
        $required = $required ? ' required' : '';
        $add_position = (int) $field->parameters->get('add_position', 3);
        // **************
        // Value handling
        // **************
        // Get fields belonging to this field group
        $grouped_fields = $this->getGroupFields($field);
        // Get values of fields making sure that also empty values are created too
        $max_count = 1;
        $this->getGroupFieldsValues($grouped_fields, $item, $max_count);
        // Render Form HTML of the field
        foreach ($grouped_fields as $field_id => $grouped_field) {
            for ($n = count($grouped_field->value); $n < $max_count; $n++) {
                $grouped_field->value[$n] = null;
            }
            $grouped_field->ingroup = 1;
            $grouped_field->item_id = $item->id;
            FLEXIUtilities::call_FC_Field_Func($grouped_field->field_type, 'onDisplayField', array(&$grouped_field, &$item));
            unset($grouped_field->ingroup);
        }
        $js = "";
        $css = "";
        if ($multiple) {
            // Add the drag and drop sorting feature
            if (!$use_ingroup) {
                $js .= "\n\t\t\tjQuery(document).ready(function(){\n\t\t\t\tjQuery('#sortables_" . $field->id . "').sortable({\n\t\t\t\t\thandle: '.fcfield-drag-handle',\n\t\t\t\t\tcontainment: 'parent',\n\t\t\t\t\ttolerance: 'pointer'\n\t\t\t\t});\n\t\t\t});\n\t\t\t";
            }
            $js .= "\n\t\t\tjQuery(document).ready(function(){" . ($compact_edit == 2 ? "jQuery('#sortables_" . $field->id . "').find('.toggle_group_down').trigger('click');" : "") . ($compact_edit == 1 ? "jQuery('#sortables_" . $field->id . "').find('.toggle_group_up').trigger('click');" : "") . "});\n\t\t\t";
            if ($max_values) {
                FLEXI_J16GE ? JText::script("FLEXI_FIELD_MAX_ALLOWED_VALUES_REACHED", true) : fcjsJText::script("FLEXI_FIELD_MAX_ALLOWED_VALUES_REACHED", true);
            }
            $js .= "\n\t\t\tvar uniqueRowNum" . $field->id . "\t= " . $max_count . ";  // Unique row number incremented only\n\t\t\tvar rowCount" . $field->id . "\t= " . $max_count . ";      // Counts existing rows to be able to limit a max number of values\n\t\t\tvar maxValues" . $field->id . " = " . $max_values . ";\n\t\t\t";
            // Create function call for add/deleting Field values
            $addField_pattern = "\n\t\t\t\tvar fieldval_box = groupval_box.find('.fcfieldval_container__GRP_FID_');\n\t\t\t\tfieldval_box.find('.invalid').removeClass('invalid').attr('aria-invalid', 'false');\n\t\t\t\tvar newSubLabel = fieldval_box.prev('label.sub_label');\n\t\t\t\tvar newLabelFor = 'custom_%s_'+uniqueRowNum" . $field->id . ";\n\t\t\t\tnewSubLabel.attr('for', newLabelFor);\n\t\t\t\tnewSubLabel.attr('for_bck', newLabelFor);\n\t\t\t\tfcflabels[ newLabelFor ] = newSubLabel;\n\t\t\t\taddField_GRP_FID_(null, groupval_box, groupval_box.find('.fcfieldval_container__GRP_FID_'), add_params);";
            $delField_pattern = "\n\t\t\t\tif(rowCount" . $field->id . " == 1)\n\t\t\t\t{\n\t\t\t\t\t// We need to update the current grouped label of the field if this was the last element being re-added\n\t\t\t\t\tvar fieldval_box = groupval_box.find('.fcfieldval_container__GRP_FID_');\n\t\t\t\t\tfieldval_box.find('.invalid').removeClass('invalid').attr('aria-invalid', 'false');\n\t\t\t\t\tvar newSubLabel = fieldval_box.prev('label.sub_label');\n\t\t\t\t\tvar newLabelFor = 'custom_%s_'+uniqueRowNum" . $field->id . ";\n\t\t\t\t\tnewSubLabel.attr('for', newLabelFor);\n\t\t\t\t\tnewSubLabel.attr('for_bck', newLabelFor);\n\t\t\t\t\tfcflabels[ newLabelFor ] = newSubLabel;\n\t\t\t\t}\n\t\t\t\tdeleteField_GRP_FID_(null, groupval_box, groupval_box.find('.fcfieldval_container__GRP_FID_'));\n\t\t\t\t";
            $addField_funcs = $delField_funcs = '';
            foreach ($grouped_fields as $field_id => $grouped_field) {
                $addField_funcs .= str_replace("_GRP_FID_", $grouped_field->id, sprintf($addField_pattern, $grouped_field->name));
                $delField_funcs .= str_replace("_GRP_FID_", $grouped_field->id, sprintf($delField_pattern, $grouped_field->name));
            }
            $js .= "\n\t\t\tfunction addField" . $field->id . "(el, groupval_box, fieldval_box, params)\n\t\t\t{\n\t\t\t\tvar insert_before   = (typeof params!== 'undefined' && typeof params.insert_before   !== 'undefined') ? params.insert_before   : 0;\n\t\t\t\tvar remove_previous = (typeof params!== 'undefined' && typeof params.remove_previous !== 'undefined') ? params.remove_previous : 0;\n\t\t\t\tvar scroll_visible  = (typeof params!== 'undefined' && typeof params.scroll_visible  !== 'undefined') ? params.scroll_visible  : 1;\n\t\t\t\tvar animate_visible = (typeof params!== 'undefined' && typeof params.animate_visible !== 'undefined') ? params.animate_visible : 1;\n\t\t\t\t\n\t\t\t\tif((rowCount" . $field->id . " >= maxValues" . $field->id . ") && (maxValues" . $field->id . " != 0)) {\n\t\t\t\t\talert(Joomla.JText._('FLEXI_FIELD_MAX_ALLOWED_VALUES_REACHED') + maxValues" . $field->id . ");\n\t\t\t\t\treturn 'cancel';\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\t// Find last container of fields and clone it to create a new container of fields\n\t\t\t\tvar lastField = fieldval_box ? fieldval_box : jQuery(el).prev().children().last();\n\t\t\t\tvar newField  = lastField.clone();\n\t\t\t\t\n\t\t\t\t// Need to at least change FORM field names and HTML tag IDs before adding the container to the DOM\n\t\t\t\tvar theSet = newField.find('input, select');\n\t\t\t\tvar nr = 0;\n\t\t\t\ttheSet.each(function() {\n\t\t\t\t\tvar elem = jQuery(this);\n\t\t\t\t\telem.attr('name', '_duplicated_" . $field->id . "_'+uniqueRowNum" . $field->id . "+'_'+nr);\n\t\t\t\t\telem.attr('id', '_duplicated_" . $field->id . "_'+uniqueRowNum" . $field->id . "+'_'+nr);\n\t\t\t\t\tnr++;\n\t\t\t\t});\n\t\t\t\t";
            // Add new field to DOM
            $js .= "\n\t\t\t\tlastField ?\n\t\t\t\t\t(insert_before ? newField.insertBefore( lastField ) : newField.insertAfter( lastField ) ) :\n\t\t\t\t\tnewField.appendTo( jQuery('#sortables_" . $field->id . "') ) ;\n\t\t\t\t";
            // Add new element to sortable objects (if field not in group)
            if (!$use_ingroup) {
                $js .= "\n\t\t\t\tjQuery('#sortables_" . $field->id . "').sortable({\n\t\t\t\t\thandle: '.fcfield-drag-handle',\n\t\t\t\t\tcontainment: 'parent',\n\t\t\t\t\ttolerance: 'pointer'\n\t\t\t\t});\n\t\t\t\t\n\t\t\t\t// Add new values for each field\n\t\t\t\tvar groupval_box = newField;\n\t\t\t\tvar add_params = {remove_previous: 1, scroll_visible: 0, animate_visible: 0};\n\t\t\t\t" . $addField_funcs . "\n\t\t\t\t";
            }
            // Readd prettyCheckable and remove previous if so requested
            $js .= "\n\t\t\t\tif (remove_previous) lastField.remove();\n\t\t\t\t";
            // Show new field, increment counters
            $js .= "\n\t\t\t\t//newField.fadeOut({ duration: 400, easing: 'swing' }).fadeIn({ duration: 200, easing: 'swing' });\n\t\t\t\tif (scroll_visible) fc_scrollIntoView(newField, 1);\n\t\t\t\tif (animate_visible) newField.css({opacity: 0.1}).animate({ opacity: 1 }, 800);\n\t\t\t\t\n\t\t\t\t// Enable tooltips on new element\n\t\t\t\tnewField.find('.hasTooltip').tooltip({'html': true,'container': newField});\n\t\t\t\t\n\t\t\t\trowCount" . $field->id . "++;       // incremented / decremented\n\t\t\t\tuniqueRowNum" . $field->id . "++;   // incremented only\n\t\t\t}\n\n\t\t\tfunction deleteField" . $field->id . "(el)\n\t\t\t{\n\t\t\t\tvar row = jQuery(el).closest('li');\n\t\t\t\t\n\t\t\t\t// Do cleanup by calling the deleteField of each individual field, these functions will re-add last element as empty if needed\n\t\t\t\tvar groupval_box = jQuery(el).closest('li');\n\t\t\t\t" . $delField_funcs . "\n\t\t\t\tif(rowCount" . $field->id . " == 1)\n\t\t\t\t{\n\t\t\t\t\tuniqueRowNum" . $field->id . "++;   // increment unique row id, since last group was re-added\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\t// Also remove the group field values container if not last one\n\t\t\t\tif(rowCount" . $field->id . " > 1) {\n\t\t\t\t\t// Destroy the remove/add/etc buttons, so that they are not reclicked, while we do the hide effect (before DOM removal of field value)\n\t\t\t\t\trow.find('.fcfield-delvalue').remove();\n\t\t\t\t\trow.find('.fcfield-insertvalue').remove();\n\t\t\t\t\trow.find('.fcfield-drag-handle').remove();\n\t\t\t\t\t// Do hide effect then remove from DOM\n\t\t\t\t\trow.fadeOut(420, function(){ this.remove(); });\n\t\t\t\t\trowCount" . $field->id . "--;\n\t\t\t\t}\n\t\t\t}\n\t\t\t";
            $css .= '';
            $remove_button = '<span class="fcfield-delvalue" title="' . JText::_('FLEXI_REMOVE_VALUE') . '" onclick="deleteField' . $field->id . '(this);"></span>';
            $move2 = '<span class="fcfield-drag-handle" title="' . JText::_('FLEXI_CLICK_TO_DRAG') . '"></span>';
            $add_here = '';
            $add_here .= $add_position == 2 || $add_position == 3 ? '<span class="fcfield-insertvalue fc_before" onclick="addField' . $field->id . '(null, jQuery(this).closest(\'ul\'), jQuery(this).closest(\'li\'), {insert_before: 1});" title="' . JText::_('FLEXI_ADD_BEFORE') . '"></span> ' : '';
            $add_here .= $add_position == 1 || $add_position == 3 ? '<span class="fcfield-insertvalue fc_after"  onclick="addField' . $field->id . '(null, jQuery(this).closest(\'ul\'), jQuery(this).closest(\'li\'), {insert_before: 0});" title="' . JText::_('FLEXI_ADD_AFTER') . '"></span> ' : '';
            if ($compact_edit) {
                $add_here .= '
				<button class="toggle_group_down btn btn-small btn-success" style="' . ($compact_edit == 2 ? 'display:none;' : '') . ' min-width: 120px;" onclick="fc_toggle_box_via_btn(jQuery(this).closest(\'li\').find(\'.fcfieldval_container_outer:not(.fcAlwaysVisibleField)\'), this, \'\', jQuery(this).next(), 1); return false;">
					<i class="icon-downarrow"></i>' . JText::_('FLEXI_FIELD_GROUP_EDIT_DETAILS') . '
				</button>
				<button class="toggle_group_up   btn btn-small" style="' . ($compact_edit == 1 ? 'display:none;' : '') . ' min-width: 120px;" onclick="fc_toggle_box_via_btn(jQuery(this).closest(\'li\').find(\'.fcfieldval_container_outer:not(.fcAlwaysVisibleField)\'), this, \'\', jQuery(this).prev(), 0); return false;">
					<i class="icon-uparrow"></i>' . JText::_('FLEXI_FIELD_GROUP_HIDE_DETAILS') . '
				</button>
			';
            }
        } else {
            $remove_button = '';
            $move2 = '';
            $add_here = '';
            $js .= '';
            $css .= '';
        }
        if ($js) {
            $document->addScriptDeclaration($js);
        }
        if ($css) {
            $document->addStyleDeclaration($css);
        }
        $close_btn = FLEXI_J30GE ? '<a class="close" data-dismiss="alert">&#215;</a>' : '<a class="fc-close" onclick="this.parentNode.parentNode.removeChild(this.parentNode);">&#215;</a>';
        $alert_box = FLEXI_J30GE ? '<div %s class="alert alert-%s %s">' . $close_btn . '%s</div>' : '<div %s class="fc-mssg fc-%s %s">' . $close_btn . '%s</div>';
        if ($compact_edit) {
            $compact_edit_excluded = $field->parameters->get('compact_edit_excluded', array());
            if (empty($compact_edit_excluded)) {
                $compact_edit_excluded = array();
            }
            if (!is_array($compact_edit_excluded)) {
                $compact_edit_excluded = preg_split("/[\\|,]/", $compact_edit_excluded);
            }
            $compact_edit_excluded = array_flip($compact_edit_excluded);
        }
        $field->html = array();
        for ($n = 0; $n < $max_count; $n++) {
            $field->html[$n] = '
				' . ($use_ingroup ? '' : $move2) . '
				' . ($use_ingroup ? '' : $remove_button) . '
				' . ($use_ingroup || !$add_position ? '' : $add_here) . '
				';
            // Append item-form display HTML of the every field in the group
            $i = 0;
            foreach ($grouped_fields as $field_id => $grouped_field) {
                $lbl_class = 'flexi label sub_label';
                $lbl_title = '';
                // field has tooltip
                $edithelp = $grouped_field->edithelp ? $grouped_field->edithelp : 1;
                if ($grouped_field->description && ($edithelp == 1 || $edithelp == 2)) {
                    $lbl_class .= ($edithelp == 2 ? ' fc_tooltip_icon ' : ' ') . $tooltip_class;
                    $lbl_title = flexicontent_html::getToolTip(trim($field->label, ':'), $grouped_field->description, 0, 1);
                }
                $field->html[$n] .= '<div class="fcclear"></div>
				<div class="fcfieldval_container_outer' . ($compact_edit && isset($compact_edit_excluded[$field_id]) ? ' fcAlwaysVisibleField' : '') . '">
					<label class="' . $lbl_class . '" title="' . $lbl_title . '" for="custom_' . $grouped_field->name . '_' . $n . '" for_bck="custom_' . $grouped_field->name . '_' . $n . '">' . $grouped_field->label . '</label>
					<div class="fcfieldval_container valuebox fcfieldval_container_' . $grouped_field->id . ' container_fcfield_name_' . $grouped_field->name . '" >
						' . ($grouped_field->description && $edithelp == 3 ? sprintf($alert_box, '', 'info', 'fc-nobgimage', $grouped_field->description) : '') . '
						' . @$grouped_field->html[$n] . '
					</div>
				</div>
				';
                $i++;
            }
            if (!$multiple) {
                break;
            }
            // multiple values disabled, break out of the loop, not adding further values even if the exist
        }
        // Non value HTML
        $non_value_html = '';
        foreach ($grouped_fields as $field_id => $grouped_field) {
            $non_value_html .= @$grouped_field->html[-1];
        }
        // Implode form HTML as a list
        $list_classes = "fcfield-sortables";
        $list_classes .= " fcfield-group";
        if (count($field->html)) {
            $field->html = '<li class="fcfieldval_container valuebox fcfieldval_container_' . $field->id . ' container_fcfield_name_' . $field->name . '">' . implode('</li><li class="fcfieldval_container valuebox fcfieldval_container_' . $field->id . ' container_fcfield_name_' . $field->name . '">', $field->html) . '</li>';
            $field->html = '<div id="sortables_outer_' . $field->id . '"><ul class="' . $list_classes . '" id="sortables_' . $field->id . '">' . $field->html . '</ul></div>';
        } else {
            $field->html = '';
        }
        if (!$add_position) {
            $field->html .= '<span class="fcfield-addvalue fccleared" onclick="addField' . $field->id . '(this);" title="' . JText::_('FLEXI_ADD_TO_BOTTOM') . '"></span>';
        }
        // Append non value html of fields
        $field->html = ($field->parameters->get('compact_edit_global', 0) ? '
			<div class="toggle_all_values_buttons_box">
				<span id="sortables_' . $field->id . '_btn" class="btn" onclick="fc_toggle_box_via_btn(jQuery(\'#sortables_outer_' . $field->id . '\'), this, \'\', jQuery(this).next(), 0); return false;">
					<i class="icon-uparrow"></i>' . JText::_('FLEXI_FIELD_GROUP_HIDE_VALUES') . '
				</span>
				<span id="sortables_' . $field->id . '_btn" class="btn btn-success" onclick="fc_toggle_box_via_btn(jQuery(\'#sortables_outer_' . $field->id . '\'), this, \'\', jQuery(this).prev(), 1); return false;" style="display:none;">
					<i class="icon-downarrow"></i>' . JText::_('FLEXI_FIELD_GROUP_SHOW_VALUES') . '
				</span>
			</div>
				' : '') . '
			' . $field->html . ($non_value_html ? '
				<div class="fcclear"></div>' . $non_value_html : '');
    }
Пример #17
0
    function onDisplayField(&$field, &$item)
    {
        $field->label = JText::_($field->label);
        // execute the code only if the field type match the plugin type
        if (!in_array($field->field_type, self::$field_types)) {
            return;
        }
        // some parameter shortcuts
        $document = JFactory::getDocument();
        $app = JFactory::getApplication();
        $client = $app->isAdmin() ? '../' : '';
        $flexiparams = JComponentHelper::getParams('com_flexicontent');
        $mediapath = $flexiparams->get('media_path', 'components/com_flexicontent/medias');
        $size = $field->parameters->get('size', 30);
        $max_values = (int) $field->parameters->get('max_values', 0);
        $required = $field->parameters->get('required', 0);
        $required = $required ? ' required' : '';
        $fieldname = FLEXI_J16GE ? 'custom[' . $field->name . '][]' : $field->name . '[]';
        if ($max_values) {
            FLEXI_J16GE ? JText::script("FLEXI_FIELD_MAX_ALLOWED_VALUES_REACHED", true) : fcjsJText::script("FLEXI_FIELD_MAX_ALLOWED_VALUES_REACHED", true);
        }
        $js = "\n\t\tfunction randomString() {\n\t\t\tvar chars = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz';\n\t\t\tvar string_length = 6;\n\t\t\tvar randomstring = '';\n\t\t\tfor (var i=0; i<string_length; i++) {\n\t\t\t\tvar rnum = Math.floor(Math.random() * chars.length);\n\t\t\t\trandomstring += chars.substring(rnum,rnum+1);\n\t\t\t}\n\t\t\treturn randomstring;\n\t\t}\n\n\t\tvar value_counter" . $field->id . "=" . count($field->value) . ";\n\t\tvar maxValues" . $field->id . "=" . $max_values . ";\n\n\t\tfunction qfSelectFile" . $field->id . "(id, file) {\n\t\t\tif((value_counter" . $field->id . " >= maxValues" . $field->id . ") && (maxValues" . $field->id . " != 0)) {\n\t\t\t\talert(Joomla.JText._('FLEXI_FIELD_MAX_ALLOWED_VALUES_REACHED') + maxValues" . $field->id . ");\n\t\t\t\treturn 'cancel';\n\t\t\t}\n\t\t\t\n\t\t  value_counter" . $field->id . "++;\n\t\t  var valcounter = \$('" . $field->name . "');\n\t\t\tvalcounter.value = value_counter" . $field->id . ";\n\n\t\t\tvar name \t= 'a_name'+id;\n\t\t\tvar ixid \t= randomString();\n\t\t\tvar li \t\t= document.createElement('li');\n\t\t\tvar thumb\t= document.createElement('img');\n\t\t\tvar hid\t\t= document.createElement('input');\n\t\t\tvar span\t= document.createElement('span');\n\t\t\tvar img\t\t= document.createElement('img');\n\n\t\t\tvar filelist = document.getElementById('sortables_" . $field->id . "');\n\t\t\tif(file.substring(0,7)!='http://')\n\t\t\t\tfile = '" . str_replace('\\', '/', JPATH_ROOT) . "/" . $mediapath . "/'+file;\n\t\t\t\$(li).addClass('minigallery');\n\t\t\t\$(thumb).addClass('thumbs');\n\t\t\t\$(span).addClass('fcfield-drag');\n\n\t\t\tvar button = document.createElement('input');\n\t\t\tbutton.type = 'button';\n\t\t\tbutton.name = 'removebutton_'+id;\n\t\t\tbutton.id = 'removebutton_'+id;\n\t\t\t\$(button).addClass('fcfield-button');\n\t\t\t\$(button).addEvent('click', function() { deleteField" . $field->id . "(this) });\n\t\t\tbutton.value = '" . JText::_('FLEXI_REMOVE_FILE', true) . "';\n\n\t\t\tthumb.src = '" . JURI::root(true) . "/components/com_flexicontent/librairies/phpthumb/phpThumb.php?src='+file+'&w=100&h=100&zc=1';\n\t\t\tthumb.alt ='" . JText::_('FLEXI_CLICK_TO_DRAG', true) . "';\n\n\t\t\thid.type = 'hidden';\n\t\t\thid.name = '" . $fieldname . "';\n\t\t\thid.value = id;\n\t\t\thid.id = ixid;\n\n\t\t\timg.src = '" . JURI::base() . "components/com_flexicontent/assets/images/move2.png';\n\t\t\timg.alt = '" . JText::_('FLEXI_CLICK_TO_DRAG', true) . "';\n\n\t\t\tfilelist.appendChild(li);\n\t\t\tli.appendChild(thumb);\n\t\t\tli.appendChild(span);\n\t\t\tspan.appendChild(img);\n\t\t\tli.appendChild(button);\n\t\t\tli.appendChild(hid);\n\n\t\t\tjQuery('#sortables_" . $field->id . "').sortable({\n\t\t\t\thandle: '.fcfield-drag',\n\t\t\t\tcontainment: 'parent',\n\t\t\t\ttolerance: 'pointer'\n\t\t\t});\n\t\t}\n\n\t\tfunction deleteField" . $field->id . "(el) {\n\t\t  value_counter" . $field->id . "--;\n\n\t\t  var valcounter = \$('" . $field->name . "');\n\t\t\tif ( value_counter" . $field->id . " > 0 ) valcounter.value = value_counter" . $field->id . ";\n\t\t\telse valcounter.value = '';\n\t\t\t\n\t\t\tvar row = jQuery(el).closest('li');\n\t\t\tjQuery(row).hide('slideUp', function() { \$(this).remove(); } );\n\t\t}\n\t\t";
        $document->addScriptDeclaration($js);
        // Add the drag and drop sorting feature
        $js = "\n\t\tjQuery(document).ready(function(){\n\t\t\tjQuery('#sortables_" . $field->id . "').sortable({\n\t\t\t\thandle: '.fcfield-drag',\n\t\t\t\tcontainment: 'parent',\n\t\t\t\ttolerance: 'pointer'\n\t\t\t});\n\t\t});\n\t\t";
        if (!FLEXI_J16GE) {
            $document->addScript(JURI::root(true) . '/components/com_flexicontent/assets/js/sortables.js');
        }
        $document->addScriptDeclaration($js);
        $css = '
		#sortables_' . $field->id . ' { float:left; margin: 0px; padding: 0px; list-style: none; white-space: nowrap; }
		#sortables_' . $field->id . ' li {
			list-style: none;
			height: 130px;
			width: 100px;
			margin: 8px 0px 0px 12px !important;
			float:left;
		}
		#sortables_' . $field->id . ' li img.thumbs {
			border: 1px solid silver;
			padding: 0;  margin: 0px 0px 6px 0px;
			float: left; clear:both;
			}
		#sortables_' . $field->id . ' li input.fcfield-button { float:left!important; }
		#sortables_' . $field->id . ' li span.fcfield-drag img { float:left!important; margin:2px 0px 0px 0px!important; }
		';
        $document->addStyleDeclaration($css);
        $move2 = '<span class="fcfield-drag">' . JHTML::image(JURI::base() . 'components/com_flexicontent/assets/images/move2.png', JText::_('FLEXI_CLICK_TO_DRAG')) . '</span>';
        JHTML::_('behavior.modal', 'a.modal_' . $field->id);
        $i = 0;
        $field->html = '<ul class="fcfield-sortables" id="sortables_' . $field->id . '">';
        if ($field->value) {
            foreach ($field->value as $file) {
                $field->html .= '<li>';
                $filename = $this->getFileName($file);
                $img_path = $filename->filename;
                if (substr($filename->filename, 0, 7) != 'http://') {
                    $img_path = JPATH_ROOT . DS . $mediapath . DS . $filename->filename;
                }
                $src = JURI::root(true) . '/components/com_flexicontent/librairies/phpthumb/phpThumb.php?src=' . $img_path . '&w=100&h=100&zc=1';
                $field->html .= ' <img class="thumbs" src="' . $src . '" alt="Thumbnail" />';
                $field->html .= '  <input type="hidden" id="a_id' . $i . '" name="' . $fieldname . '" value="' . $file . '" />';
                $field->html .= $move2;
                $field->html .= '  <input class="inputbox fcfield-button" type="button" onclick="deleteField' . $field->id . '(this);" value="' . JText::_('FLEXI_REMOVE_FILE') . '" />';
                $field->html .= '</li>';
                $i++;
            }
        }
        $autoselect = $field->parameters->get('autoselect', 1);
        $linkfsel = JURI::base(true) . '/index.php?option=com_flexicontent&amp;view=fileselement&amp;tmpl=component&amp;layout=image&amp;filter_secure=M&amp;index=' . $i . '&amp;autoselect=' . $autoselect . '&amp;field=' . $field->id . '&amp;' . (FLEXI_J30GE ? JSession::getFormToken() : JUtility::getToken()) . '=1';
        $field->html .= "\n\t\t</ul>\n\t\t<div class=\"fcfield-button-add\">\n\t\t\t<div class=\"blank\">\n\t\t\t\t<a class=\"modal_" . $field->id . "\" title=\"" . JText::_('FLEXI_ADD_FILE') . "\" href=\"" . $linkfsel . "\" rel=\"{handler: 'iframe', size: {x:(MooTools.version>='1.2.4' ? window.getSize().x : window.getSize().size.x)-100, y: (MooTools.version>='1.2.4' ? window.getSize().y : window.getSize().size.y)-100}}\">" . JText::_('FLEXI_ADD_FILE') . "</a>\n\t\t\t</div>\n\t\t</div>\n\t\t";
        $field->html .= '<input id="' . $field->name . '" class="' . $required . '" style="display:none;" name="__fcfld_valcnt__[' . $field->name . ']" value="' . ($i ? $i : '') . '" />';
    }
Пример #18
0
    function onDisplayField(&$field, &$item)
    {
        // execute the code only if the field type match the plugin type
        if (!in_array($field->field_type, self::$field_types)) {
            return;
        }
        $field->label = JText::_($field->label);
        // initialize framework objects and other variables
        $document = JFactory::getDocument();
        // some parameter shortcuts
        $size = (int) $field->parameters->get('size', 30);
        $multiple = $field->parameters->get('allow_multiple', 1);
        $max_values = (int) $field->parameters->get('max_values', 0);
        $required = $field->parameters->get('required', 0);
        $required = $required ? ' required' : '';
        // This is field 's MAIN value property
        $link_usage = $field->parameters->get('link_usage', 0);
        $default_link = $item->version == 0 || $link_usage > 0 ? $field->parameters->get('default_value_link', '') : '';
        // Optional value properties
        $title_usage = $field->parameters->get('title_usage', 0);
        $default_title = $item->version == 0 || $title_usage > 0 ? JText::_($field->parameters->get('default_value_title', '')) : '';
        $usetitle = $field->parameters->get('use_title', 0);
        // Initialise property with default value
        if (!$field->value) {
            $field->value = array();
            $field->value[0]['link'] = JText::_($default_link);
            $field->value[0]['title'] = JText::_($default_title);
            $field->value[0]['hits'] = 0;
            $field->value[0] = serialize($field->value[0]);
        }
        // Field name and HTML TAG id
        $fieldname = FLEXI_J16GE ? 'custom[' . $field->name . ']' : $field->name;
        $elementid = FLEXI_J16GE ? 'custom_' . $field->name : $field->name;
        $js = "";
        if ($multiple) {
            if (!FLEXI_J16GE) {
                $document->addScript(JURI::root(true) . '/components/com_flexicontent/assets/js/sortables.js');
            }
            // Add the drag and drop sorting feature
            $js .= "\r\n\t\t\tjQuery(document).ready(function(){\r\n\t\t\t\tjQuery('#sortables_" . $field->id . "').sortable({\r\n\t\t\t\t\thandle: '.fcfield-drag',\r\n\t\t\t\t\tcontainment: 'parent',\r\n\t\t\t\t\ttolerance: 'pointer'\r\n\t\t\t\t});\r\n\t\t\t});\r\n\t\t\t";
            if ($max_values) {
                FLEXI_J16GE ? JText::script("FLEXI_FIELD_MAX_ALLOWED_VALUES_REACHED", true) : fcjsJText::script("FLEXI_FIELD_MAX_ALLOWED_VALUES_REACHED", true);
            }
            $js .= "\r\n\t\t\tvar uniqueRowNum" . $field->id . "\t= " . count($field->value) . ";  // Unique row number incremented only\r\n\t\t\tvar rowCount" . $field->id . "\t= " . count($field->value) . ";      // Counts existing rows to be able to limit a max number of values\r\n\t\t\tvar maxValues" . $field->id . " = " . $max_values . ";\r\n\r\n\t\t\tfunction addField" . $field->id . "(el) {\r\n\t\t\t\tif((rowCount" . $field->id . " >= maxValues" . $field->id . ") && (maxValues" . $field->id . " != 0)) {\r\n\t\t\t\t\talert(Joomla.JText._('FLEXI_FIELD_MAX_ALLOWED_VALUES_REACHED') + maxValues" . $field->id . ");\r\n\t\t\t\t\treturn 'cancel';\r\n\t\t\t\t}\r\n\t\t\t\t\r\n\t\t\t\tvar thisField \t = jQuery(el).prev().children().last();\r\n\t\t\t\tvar thisNewField = thisField.clone();\r\n\t\t\t\t\r\n\t\t\t\tjQuery(thisNewField).find('input.urllink').attr('value','" . $default_link . "');\r\n\t\t\t\tjQuery(thisNewField).find('input.urllink').attr('name','" . $fieldname . "['+uniqueRowNum" . $field->id . "+'][link]');\r\n\t\t\t\tjQuery(thisNewField).find('input.urllink').attr('id','" . $elementid . "_'+uniqueRowNum" . $field->id . ");\r\n\t\t\t\t";
            if ($usetitle) {
                $js .= "\r\n\t\t\t\tjQuery(thisNewField).find('input.urltitle').attr('value','" . $default_title . "');\r\n\t\t\t\tjQuery(thisNewField).find('input.urltitle').attr('name','" . $fieldname . "['+uniqueRowNum" . $field->id . "+'][title]');\r\n\t\t\t\t";
            }
            $js .= "\r\n\t\t\t\tjQuery(thisNewField).find('input.urlhits').attr('value','0');\r\n\t\t\t\tjQuery(thisNewField).find('input.urlhits').attr('name','" . $fieldname . "['+uniqueRowNum" . $field->id . "+'][hits]');\r\n\t\t\t\t\r\n\t\t\t\t// Set hits to zero for new row value\r\n\t\t\t\tjQuery(thisNewField).find('span span').html('0');\r\n\t\t\t\tjQuery(thisNewField).css('display', 'none');\r\n\t\t\t\tjQuery(thisNewField).insertAfter( jQuery(thisField) );\r\n\t\t\t\t\r\n\t\t\t\tjQuery('#sortables_" . $field->id . "').sortable({\r\n\t\t\t\t\thandle: '.fcfield-drag',\r\n\t\t\t\t\tcontainment: 'parent',\r\n\t\t\t\t\ttolerance: 'pointer'\r\n\t\t\t\t});\r\n\t\t\t\t\r\n\t\t\t\tjQuery(thisNewField).show('slideDown');\r\n\t\t\t\t\r\n\t\t\t\trowCount" . $field->id . "++;       // incremented / decremented\r\n\t\t\t\tuniqueRowNum" . $field->id . "++;   // incremented only\r\n\t\t\t}\r\n\r\n\t\t\tfunction deleteField" . $field->id . "(el)\r\n\t\t\t{\r\n\t\t\t\tif(rowCount" . $field->id . " <= 1) return;\r\n\t\t\t\tvar row = jQuery(el).closest('li');\r\n\t\t\t\tjQuery(row).hide('slideUp', function() { jQuery(this).remove(); } );\r\n\t\t\t\trowCount" . $field->id . "--;\r\n\t\t\t}\r\n\t\t\t";
            $css = '
			#sortables_' . $field->id . ' { float:left; margin: 0px; padding: 0px; list-style: none; white-space: nowrap; }
			#sortables_' . $field->id . ' li {
				clear: both;
				display: block;
				list-style: none;
				height: auto;
				position: relative;
			}
			#sortables_' . $field->id . ' li.sortabledisabled {
				background : transparent url(components/com_flexicontent/assets/images/move3.png) no-repeat 0px 1px;
			}
			#sortables_' . $field->id . ' li input { cursor: text;}
			#add' . $field->name . ' { margin-top: 5px; clear: both; display:block; }
			#sortables_' . $field->id . ' li .admintable { text-align: left; }
			#sortables_' . $field->id . ' li:only-child span.fcfield-drag, #sortables_' . $field->id . ' li:only-child input.fcfield-button { display:none; }
			#sortables_' . $field->id . ' label.label, #sortables_' . $field->id . ' input.urllink, #sortables_' . $field->id . ' input.urltitle, #sortables_' . $field->id . ' input.fcfield-button {
				float: none!important;
				display: inline-block!important;
			}
			';
            $remove_button = '<input class="fcfield-button" type="button" value="' . JText::_('FLEXI_REMOVE_VALUE') . '" onclick="deleteField' . $field->id . '(this);" />';
            $move2 = '<span class="fcfield-drag">' . JHTML::image(JURI::base() . 'components/com_flexicontent/assets/images/move2.png', JText::_('FLEXI_CLICK_TO_DRAG')) . '</span>';
        } else {
            $remove_button = '';
            $move2 = '';
            $js = '';
            $css = '';
        }
        if ($js) {
            $document->addScriptDeclaration($js);
        }
        if ($css) {
            $document->addStyleDeclaration($css);
        }
        $field->html = array();
        $n = 0;
        foreach ($field->value as $value) {
            if (!strlen($value)) {
                continue;
            }
            // Compatibility for old unserialized values
            if (@unserialize($value) !== false || $value === 'b:0;') {
                $value = unserialize($value);
            } else {
                $value = array('link' => $value, 'title' => '', 'hits' => 0);
            }
            $fieldname_n = $fieldname . '[' . $n . ']';
            $elementid_n = $elementid . '_' . $n;
            $link = '
				<label class="label">' . JText::_('FLEXI_FIELD_URL') . ':</label>
				<input class="urllink fcfield_textval' . $required . '" name="' . $fieldname_n . '[link]" id="' . $elementid_n . '" type="text" size="' . $size . '" value="' . $value['link'] . '" />
			';
            $title = '';
            if ($usetitle) {
                $title = '
				<label class="label">' . JText::_('FLEXI_FIELD_URLTITLE') . ':</label>
				<input class="urltitle fcfield_textval" name="' . $fieldname_n . '[title]" type="text" size="' . $size . '" value="' . @$value['title'] . '" />
			';
            }
            $hits = (int) @$value['hits'];
            $hits = '
					<input class="urlhits" name="' . $fieldname_n . '[hits]" type="hidden" value="' . $hits . '" />
					<span class="hits"><span class="hitcount">' . $hits . '</span> ' . JText::_('FLEXI_FIELD_HITS') . '</span>
			';
            $field->html[] = '
				' . $link . '
				' . $title . '
				' . $hits . '
				' . $move2 . '
				' . $remove_button . '
				';
            $n++;
            if (!$multiple) {
                break;
            }
            // multiple values disabled, break out of the loop, not adding further values even if the exist
        }
        if ($multiple) {
            // handle multiple records
            $_list = "<li>" . implode("</li>\n<li>", $field->html) . "</li>\n";
            $field->html = '
				<ul class="fcfield-sortables" id="sortables_' . $field->id . '">' . $_list . '</ul>
				<input type="button" class="fcfield-addvalue" onclick="addField' . $field->id . '(this);" value="' . JText::_('FLEXI_ADD_VALUE') . '" />
			';
        } else {
            // handle single values
            $field->html = $field->html[0];
        }
    }
Пример #19
0
	/**
	 * After component has created its output, this is good place to make global replacements
	 *
	 * @access public
	 * @return boolean
	 */
	public function onAfterRender()
	{
		$fparams = JComponentHelper::getParams('com_flexicontent');
		$session = JFactory::getSession();
		
		// If this is reached we now that the code for setting screen cookie has been added
		if ( $session->get('screenSizeCookieToBeAdded', 0, 'flexicontent') ) {
			$session->set('screenSizeCookieTried', 1, 'flexicontent');
			$session->set('screenSizeCookieToBeAdded', 0, 'flexicontent');
		}
		
		// Load language string for javascript usage in J1.5
		if ( !FLEXI_J16GE && class_exists('fcjsJText') )  fcjsJText::load();
		
		// Add performance message at document's end
		global $fc_performance_msg;
		if ($fc_performance_msg) {
			$html = JResponse::getBody();
			$inline_css = 'margin:12px 1% !important; text-align:left !important; float:none !important; width:auto!important; display:block !important;';
			$inline_js_close_btn = !FLEXI_J30GE ? 'onclick="this.parentNode.parentNode.removeChild(this.parentNode);"' : '';
			$inline_css_close_btn = !FLEXI_J30GE ? 'float:right; display:block; font-size:18px; cursor: pointer;' : '';
			$html = str_replace('</body>',
				'<div class="fc-mssg fc-info" style="'.$inline_css.'" >'.
					'<a class="close" data-dismiss="alert" '.$inline_js_close_btn.' style="'.$inline_css_close_btn.'" >&#215;</a>'.
					$fc_performance_msg.
				'</div>'."\n</body>", $html
			);
			JResponse::setBody($html);
		}
		
		return true;
	}