static function createFilter(&$filter, $value = '', $formName = 'adminForm', $indexed_elements = false, $search_prop = '') { static $apply_cache = null; static $faceted_overlimit_msg = null; $user = JFactory::getUser(); $mainframe = JFactory::getApplication(); //$cparams = $mainframe->getParams('com_flexicontent'); $cparams = JComponentHelper::getParams('com_flexicontent'); // createFilter maybe called in backend too ... $print_logging_info = $cparams->get('print_logging_info'); $option = JRequest::getVar('option'); $view = JRequest::getVar('view'); $is_fc_component = $option == 'com_flexicontent'; $isCategoryView = $is_fc_component && $view == 'category'; $isSearchView = $is_fc_component && $view == 'search'; if ($print_logging_info) { global $fc_run_times; $start_microtime = microtime(true); } // Apply caching to filters regardless of cache setting ... $apply_cache = FLEXI_CACHE; if ($apply_cache) { $itemcache = JFactory::getCache('com_flexicontent_filters'); // Get Joomla Cache of '...items' Caching Group $itemcache->setCaching(1); // Force cache ON $itemcache->setLifeTime(FLEXI_CACHE_TIME); // Set expire time (default is 1 hour) } $isdate = in_array($filter->field_type, array('date', 'created', 'modified')) || $filter->parameters->get('isdate', 0); $default_size = $isdate ? 15 : 30; $_s = $isSearchView ? '_s' : ''; // Some parameter shortcuts $label_filter = $filter->parameters->get('display_label_filter' . $_s, 0); // How to show filter label $size = $filter->parameters->get('text_filter_size', $default_size); // Size of filter $faceted_filter = $filter->parameters->get('faceted_filter' . $_s, 2); $display_filter_as = $filter->parameters->get('display_filter_as' . $_s, 0); // Filter Type of Display $filter_as_range = in_array($display_filter_as, array(2, 3)); $require_all = !in_array($display_filter_as, array(1, 2, 3)) ? $filter->parameters->get('filter_values_require_all', 0) : 0; $combine_tip = $filter->parameters->get('filter_values_require_all_tip', 0); $show_matching_items = $filter->parameters->get('show_matching_items' . $_s, 1); $show_matches = $filter_as_range || !$faceted_filter ? 0 : $show_matching_items; $hide_disabled_values = $filter->parameters->get('hide_disabled_values' . $_s, 0); $get_filter_vals = in_array($display_filter_as, array(0, 2, 4, 5, 6)); $filter_ffname = 'filter_' . $filter->id; $filter_ffid = $formName . '_' . $filter->id . '_val'; // Make sure the current filtering values match the field filter configuration to single or multi-value if (in_array($display_filter_as, array(2, 3, 5, 6))) { if (!is_array($value)) { $value = strlen($value) ? array($value) : array(); } } else { if (is_array($value)) { $value = @$value[0]; } } //print_r($value); // Alter search property name (indexed fields only), remove underscore _ at start & end of it if ($indexed_elements && $search_prop) { preg_match("/^_([a-zA-Z_0-9]+)_\$/", $search_prop, $prop_matches); $search_prop = @$prop_matches[1]; } // Get filtering values, this can be cached if not filtering according to current category filters if ($get_filter_vals) { $view_join = ''; $view_where = ''; $filters_where = array(); // *** Limiting of displayed filter values according to current category filtering, but show all field values if filter is active if ($isCategoryView) { // category view, use parameter to decide if limitting filter values global $fc_catview; if ($faceted_filter) { $view_join = @$fc_catview['join_clauses']; $view_where = $fc_catview['where_conf_only']; $filters_where = $fc_catview['filters_where']; $view_total = isset($fc_catview['view_total']) ? $fc_catview['view_total'] : 0; if ($fc_catview['alpha_where']) { $filters_where['alpha'] = $fc_catview['alpha_where']; } // we use count bellow ... so add it only if it is non-empty } } else { if ($isSearchView) { // search view, use parameter to decide if limitting filter values global $fc_searchview; if (empty($fc_searchview)) { return array(); } // search view plugin disabled ? if ($faceted_filter) { $view_join = $fc_searchview['join_clauses']; $view_where = $fc_searchview['where_conf_only']; $filters_where = $fc_searchview['filters_where']; $view_total = isset($fc_searchview['view_total']) ? $fc_searchview['view_total'] : 0; } } } $createFilterValues = !$isSearchView ? 'createFilterValues' : 'createFilterValuesSearch'; // This is hack for filter core properties to be filterable in search view without being added to the adv search index if ($filter->field_type == 'coreprops' && $view == 'search') { $createFilterValues = 'createFilterValues'; } // Get filter values considering PAGE configuration (regardless of ACTIVE filters) if ($apply_cache) { $results_page = $itemcache->call(array('FlexicontentFields', $createFilterValues), $filter, $view_join, $view_where, array(), $indexed_elements, $search_prop); } else { if (!$isSearchView) { $results_page = FlexicontentFields::createFilterValues($filter, $view_join, $view_where, array(), $indexed_elements, $search_prop); } else { $results_page = FlexicontentFields::createFilterValuesSearch($filter, $view_join, $view_where, array(), $indexed_elements, $search_prop); } } // Get filter values considering ACTIVE filters, but only if there is at least ONE filter active $faceted_max_item_limit = 10000; if ($faceted_filter == 2 && count($filters_where)) { if ($view_total <= $faceted_max_item_limit) { // DO NOT cache at this point the filter combinations are endless, so they will produce big amounts of cached data, that will be rarely used ... if (!$isSearchView) { $results_active = FlexicontentFields::createFilterValues($filter, $view_join, $view_where, $filters_where, $indexed_elements, $search_prop); } else { $results_active = FlexicontentFields::createFilterValuesSearch($filter, $view_join, $view_where, $filters_where, $indexed_elements, $search_prop); } } else { if ($faceted_overlimit_msg === null) { // Set a notice message about not counting item per filter values and instead showing item TOTAL of current category / view $faceted_overlimit_msg = 1; $filter_messages = JRequest::getVar('filter_message', array()); $filter_messages[] = JText::sprintf('FLEXI_FACETED_ITEM_LIST_OVER_LIMIT', $faceted_max_item_limit, $view_total); JRequest::setVar('filter_messages', $filter_messages); } } } // Decide which results to show those based: (a) on active filters or (b) on page configuration // This depends if hiding disabled values (for FACETED: 2) AND if active filters exist $use_active_vals = $hide_disabled_values && isset($results_active); $results_shown = $use_active_vals ? $results_active : $results_page; $update_found = !$use_active_vals && isset($results_active); // Set usage counters $results = array(); foreach ($results_shown as $i => $result) { $results[$i] = $result; // FACETED: 0,1 or NOT showing usage // Set usage to non-zero value e.g. -1 ... which maybe used (e.g. disabling values) but not be displayed if (!$show_matches || $faceted_filter < 2) { $results[$i]->found = -1; } else { if ($update_found) { $results[$i]->found = (int) @$results_active[$i]->found; } else { } } // Append value usage to value's label if ($faceted_filter == 2 && $show_matches && $results[$i]->found) { $results[$i]->text .= ' (' . $results[$i]->found . ')'; } } } else { $faceted_filter = 0; // clear faceted filter flag } // Prepend Field's Label to filter HTML // Commented out because it was moved in to form template file //$filter->html = $label_filter==1 ? $filter->label.': ' : ''; $filter->html = ''; // *** Create the form field(s) used for filtering switch ($display_filter_as) { case 0: case 2: case 6: // 0: Select (single value selectable), 2: Dual select (value range), 6: Multi Select (multiple values selectable) $options = array(); // MULTI-select does not has an internal label a drop-down list option if ($display_filter_as != 6) { $first_option_txt = $label_filter == 2 ? $filter->label : JText::_('FLEXI_ANY'); $options[] = JHTML::_('select.option', '', '- ' . $first_option_txt . ' -'); } // Make use of select2 lib flexicontent_html::loadFramework('select2'); $classes = " use_select2_lib"; $extra_param = ''; // MULTI-select: special label and prompts if ($display_filter_as == 6) { $classes .= ' fc_label_internal fc_prompt_internal'; // Add field's LABEL internally or click to select PROMPT (via js) $_inner_lb = $label_filter == 2 ? $filter->label : JText::_('FLEXI_CLICK_TO_LIST'); // Add type to filter PROMPT (via js) $extra_param = ' data-fc_label_text="' . flexicontent_html::escapeJsText($_inner_lb, 's') . '"'; $extra_param .= ' fc_prompt_text="' . flexicontent_html::escapeJsText(JText::_('FLEXI_TYPE_TO_FILTER'), 's') . '"'; } // Create HTML tag attributes $attribs_str = ' class="fc_field_filter' . $classes . '" ' . $extra_param; $attribs_str .= $display_filter_as == 6 ? ' multiple="multiple" size="20" ' : ''; //$attribs_str .= ($display_filter_as==0 || $display_filter_as==6) ? ' onchange="document.getElementById(\''.$formName.'\').submit();"' : ''; foreach ($results as $result) { if (!strlen($result->value)) { continue; } $options[] = JHTML::_('select.option', $result->value, $result->text, 'value', 'text', $disabled = $faceted_filter == 2 && !$result->found); } if ($display_filter_as == 6 && $combine_tip) { $filter->html .= ' <span class="fc_filter_tip_inline">' . JText::_(!$require_all ? 'FLEXI_ANY_OF' : 'FLEXI_ALL_OF') . '</span> '; } if ($display_filter_as == 0 || $display_filter_as == 6) { $filter->html .= JHTML::_('select.genericlist', $options, $filter_ffname . '[]', $attribs_str, 'value', 'text', $value, $filter_ffid); } else { $filter->html .= JHTML::_('select.genericlist', $options, $filter_ffname . '[1]', $attribs_str, 'value', 'text', @$value[1], $filter_ffid . '1'); $filter->html .= '<span class="fc_range"></span>'; $filter->html .= JHTML::_('select.genericlist', $options, $filter_ffname . '[2]', $attribs_str, 'value', 'text', @$value[2], $filter_ffid . '2'); } break; case 1: case 3: // (TODO: autocomplete) ... 1: Text input, 3: Dual text input (value range), both of these can be JS date calendars $_inner_lb = $label_filter == 2 ? $filter->label : JText::_($isdate ? 'FLEXI_CLICK_CALENDAR' : 'FLEXI_TYPE_TO_LIST'); $_inner_lb = flexicontent_html::escapeJsText($_inner_lb, 's'); $attribs_str = ' class="fc_field_filter fc_label_internal fc_iscalendar" data-fc_label_text="' . $_inner_lb . '"'; $attribs_arr = array('class' => 'fc_field_filter fc_label_internal fc_iscalendar', 'data-fc_label_text' => $_inner_lb); if ($display_filter_as == 1) { if ($isdate) { $filter->html .= FlexicontentFields::createCalendarField($value, $allowtime = 0, $filter_ffname, $filter_ffid, $attribs_arr); } else { $filter->html .= '<input id="' . $filter_ffid . '" name="' . $filter_ffname . '" ' . $attribs_str . ' type="text" size="' . $size . '" value="' . @$value . '" />'; } } else { if ($isdate) { $filter->html .= '<span class="fc_filter_element">'; $filter->html .= FlexicontentFields::createCalendarField(@$value[1], $allowtime = 0, $filter_ffname . '[1]', $filter_ffid . '1', $attribs_arr); $filter->html .= '</span>'; $filter->html .= '<span class="fc_range"></span>'; $filter->html .= '<span class="fc_filter_element">'; $filter->html .= FlexicontentFields::createCalendarField(@$value[2], $allowtime = 0, $filter_ffname . '[2]', $filter_ffid . '2', $attribs_arr); $filter->html .= '</span>'; } else { $size = (int) ($size / 2); $filter->html .= '<span class="fc_filter_element">'; $filter->html .= '<input name="' . $filter_ffname . '[1]" ' . $attribs_str . ' type="text" size="' . $size . '" value="' . @$value[1] . '" />'; $filter->html .= '</span>'; $filter->html .= '<span class="fc_range"></span>'; $filter->html .= '<span class="fc_filter_element">'; $filter->html .= '<input name="' . $filter_ffname . '[2]" ' . $attribs_str . ' type="text" size="' . $size . '" value="' . @$value[2] . '" />' . "\n"; $filter->html .= '</span>'; } } break; case 4: case 5: // 4: radio (single value selectable), 5: checkbox (multiple values selectable) $lf_min = 10; // add parameter for this ? $add_lf = count($results) >= $lf_min; if ($add_lf) { flexicontent_html::loadFramework('mCSB'); } $clear_values = 0; $value_style = $clear_values ? 'float:left; clear:both;' : ''; $i = 0; $checked = $display_filter_as == 5 ? !count($value) || !strlen(reset($value)) : !strlen($value); $checked_attr = $checked ? 'checked="checked"' : ''; $checked_class = $checked ? 'fc_highlight' : ''; $checked_class_li = $checked ? ' fc_checkradio_checked' : ''; $filter->html .= '<span class="fc_checkradio_group_wrapper fc_add_scroller' . ($add_lf ? ' fc_list_filter_wrapper' : '') . '">'; $filter->html .= '<ul class="fc_field_filter fc_checkradio_group' . ($add_lf ? ' fc_list_filter' : '') . '">'; $filter->html .= '<li class="fc_checkradio_option fc_checkradio_special' . $checked_class_li . '" style="' . $value_style . '">'; $filter->html .= $label_filter == 2 ? ' <span class="fc_filter_label_inline">' . $filter->label . '</span> ' : ''; if ($display_filter_as == 4) { $filter->html .= ' <input href="javascript:;" onchange="fc_toggleClassGrp(this, \'fc_highlight\', 1);" '; $filter->html .= ' id="' . $filter_ffid . $i . '" type="radio" name="' . $filter_ffname . '" '; $filter->html .= ' value="" ' . $checked_attr . ' class="fc_checkradio" />'; } else { $filter->html .= ' <input href="javascript:;" onchange="fc_toggleClass(this, \'fc_highlight\', 1);" '; $filter->html .= ' id="' . $filter_ffid . $i . '" type="checkbox" name="' . $filter_ffname . '[' . $i . ']" '; $filter->html .= ' value="" ' . $checked_attr . ' class="fc_checkradio" />'; } $filter->html .= '<label class="hasTip ' . $checked_class . '" for="' . $filter_ffid . $i . '" ' . ' title="::' . JText::_('FLEXI_REMOVE_ALL') . '"' . ($checked ? ' style="display:none!important;" ' : 'style="background:none!important; padding-left:0px!important;"') . '>' . '<span class="fc_delall_filters"></span>'; $filter->html .= '</label> ' . ($combine_tip ? ' <span class="fc_filter_tip_inline">' . JText::_(!$require_all ? 'FLEXI_ANY_OF' : 'FLEXI_ALL_OF') . '</span> ' : '') . ' </li>'; $i++; foreach ($results as $result) { if (!strlen($result->value)) { continue; } $checked = $display_filter_as == 5 ? in_array($result->value, $value) : $result->value == $value; $checked_attr = $checked ? ' checked=checked ' : ''; $disable_attr = $faceted_filter == 2 && !$result->found ? ' disabled=disabled ' : ''; $checked_class = $checked ? 'fc_highlight' : ''; $checked_class .= $faceted_filter == 2 && !$result->found ? ' fcdisabled ' : ''; $checked_class_li = $checked ? ' fc_checkradio_checked' : ''; $filter->html .= '<li class="fc_checkradio_option' . $checked_class_li . '" style="' . $value_style . '">'; if ($display_filter_as == 4) { $filter->html .= ' <input href="javascript:;" onchange="fc_toggleClassGrp(this, \'fc_highlight\');" '; $filter->html .= ' id="' . $filter_ffid . $i . '" type="radio" name="' . $filter_ffname . '" '; $filter->html .= ' value="' . $result->value . '" ' . $checked_attr . $disable_attr . ' class="fc_checkradio" />'; } else { $filter->html .= ' <input href="javascript:;" onchange="fc_toggleClass(this, \'fc_highlight\');" '; $filter->html .= ' id="' . $filter_ffid . $i . '" type="checkbox" name="' . $filter_ffname . '[' . $i . ']" '; $filter->html .= ' value="' . $result->value . '" ' . $checked_attr . $disable_attr . ' class="fc_checkradio" />'; } $filter->html .= '<label class="' . $checked_class . '" for="' . $filter_ffid . $i . '">'; $filter->html .= $result->text; $filter->html .= '</label>'; $filter->html .= '</li>'; $i++; } $filter->html .= '</ul>'; $filter->html .= '</span>'; break; } if ($print_logging_info) { $current_filter_creation = round(1000000 * 10 * (microtime(true) - $start_microtime)) / 10; $flt_active_count = isset($filters_where) ? count($filters_where) : 0; $faceted_str = array(0 => 'non-FACETED ', 1 => 'FACETED: current view (cacheable) ', 2 => 'FACETED: current filters:' . " (" . $flt_active_count . ' active) '); $fc_run_times['create_filter'][$filter->name] = $current_filter_creation; if (isset($fc_run_times['_create_filter_init'])) { $fc_run_times['create_filter'][$filter->name] -= $fc_run_times['_create_filter_init']; $fc_run_times['create_filter_init'] = $fc_run_times['_create_filter_init']; unset($fc_run_times['_create_filter_init']); } $fc_run_times['create_filter_type'][$filter->name] = $faceted_str[$faceted_filter]; } //$filter_display_typestr = array(0=>'Single Select', 1=>'Single Text', 2=>'Range Dual Select', 3=>'Range Dual Text', 4=>'Radio Buttons', 5=>'Checkbox Buttons'); //echo "FIELD name: <b>". $filter->name ."</b> Field Type: <b>". $filter->field_type."</b> Filter Type: <b>". $filter_display_typestr[$display_filter_as] ."</b> (".$display_filter_as.") ".sprintf(" %.2f s",$current_filter_creation/1000000)." <br/>"; }
function onDisplayFilter(&$filter, $value = '', $formName = 'adminForm', $isSearchView = 0) { if ($filter->iscore != 1) { return; } // performance check $db = JFactory::getDBO(); $formfieldname = 'filter_' . $filter->id; $_s = $isSearchView ? '_s' : ''; $display_filter_as = $filter->parameters->get('display_filter_as' . $_s, 0); // Filter Type of Display $faceted_filter = $filter->parameters->get('faceted_filter' . $_s, 0); // Filter Type of Display $disable_keyboardinput = $filter->parameters->get('disable_keyboardinput', 0); $filter_as_range = in_array($display_filter_as, array(2, 3, 8)); // Create first prompt option of drop-down select $label_filter = $filter->parameters->get('display_label_filter' . $_s, 2); $first_option_txt = $label_filter == 2 ? $filter->label : JText::_('FLEXI_ALL'); // Prepend Field's Label to filter HTML //$filter->html = $label_filter==1 ? $filter->label.': ' : ''; $filter->html = ''; switch ($filter->field_type) { case 'title': $_inner_lb = $label_filter == 2 ? $filter->label : JText::_('FLEXI_TYPE_TO_LIST'); $_inner_lb = flexicontent_html::escapeJsText($_inner_lb, 's'); $attribs_str = ' class="fc_field_filter fc_label_internal" data-fc_label_text="' . $_inner_lb . '"'; $filter_ffname = 'filter_' . $filter->id; $filter_ffid = $formName . '_' . $filter->id . '_val'; $filter->html .= '<input id="' . $filter_ffid . '" name="' . $filter_ffname . '" ' . $attribs_str . ' type="text" size="20" value="' . $value . '" />'; break; case 'createdby': // Authors // WARNING: we can not use column alias in from, join, where, group by, can use in having (some DB e.g. mysql) and in order-by // partial SQL clauses $filter->filter_valuesselect = ' i.created_by AS value, CASE WHEN usr.name IS NULL THEN CONCAT(\'' . JText::_('FLEXI_NOT_ASSIGNED') . ' ID:\', i.created_by) ELSE usr.name END AS text'; $filter->filter_valuesjoin = ' JOIN #__users AS usr ON usr.id = i.created_by'; $filter->filter_valueswhere = ' AND i.created_by <> 0'; // full SQL clauses $filter->filter_groupby = ' GROUP BY i.created_by '; $filter->filter_having = null; // this indicates to use default, space is use empty $filter->filter_orderby = ' ORDER by text'; // default will order by value and not by label FlexicontentFields::createFilter($filter, $value, $formName); break; case 'modifiedby': // Modifiers // WARNING: we can not use column alias in from, join, where, group by, can use in having (some DB e.g. mysql) and in order-by // partial SQL clauses $filter->filter_valuesselect = ' i.modified_by AS value, CASE WHEN usr.name IS NULL THEN CONCAT(\'' . JText::_('FLEXI_NOT_ASSIGNED') . ' ID:\', i.modified_by) ELSE usr.name END AS text'; $filter->filter_valuesjoin = ' JOIN #__users AS usr ON usr.id = i.modified_by'; $filter->filter_valueswhere = ' AND i.modified_by <> 0'; // full SQL clauses $filter->filter_groupby = ' GROUP BY i.modified_by '; $filter->filter_having = null; // this indicates to use default, space is use empty $filter->filter_orderby = ' ORDER by text'; // default will order by value and not by label FlexicontentFields::createFilter($filter, $value, $formName); break; case 'type': // Document Type // WARNING: we can not use column alias in from, join, where, group by, can use in having (some DB e.g. mysql) and in order-by // partial SQL clauses $filter->filter_valuesselect = ' ict.id AS value, ict.name AS text'; $filter->filter_valuesjoin = '' . ' JOIN #__flexicontent_items_ext AS iext ON iext.item_id = i.id' . ' JOIN #__flexicontent_types AS ict ON iext.type_id = ict.id'; $filter->filter_valueswhere = ' '; // ... a space, (indicates not needed and prevents using default) // full SQL clauses $filter->filter_groupby = ' GROUP BY ict.id'; $filter->filter_having = null; // this indicates to use default, space is use empty $filter->filter_orderby = ' ORDER by text'; // default will order by value and not by label FlexicontentFields::createFilter($filter, $value, $formName); break; case 'state': $options = array(); $options[] = JHTML::_('select.option', '', '- ' . $first_option_txt . ' -'); $options[] = JHTML::_('select.option', 'P', JText::_('FLEXI_PUBLISHED')); $options[] = JHTML::_('select.option', 'U', JText::_('FLEXI_UNPUBLISHED')); $options[] = JHTML::_('select.option', 'PE', JText::_('FLEXI_PENDING')); $options[] = JHTML::_('select.option', 'OQ', JText::_('FLEXI_TO_WRITE')); $options[] = JHTML::_('select.option', 'IP', JText::_('FLEXI_IN_PROGRESS')); $options[] = JHTML::_('select.option', 'A', JText::_('FLEXI_ARCHIVED')); //$options[] = JHTML::_('select.option', 'T', JText::_( 'FLEXI_TRASHED' ) ); break; case 'categories': // Initialize options $options = array(); // MULTI-select does not has an internal label a drop-down list option if ($display_filter_as != 6) { $first_option_txt = $label_filter == 2 ? $filter->label : JText::_('FLEXI_ANY'); $options[] = JHTML::_('select.option', '', '- ' . $first_option_txt . ' -'); } // Get categories global $globalcats; $rootcatid = $filter->parameters->get('rootcatid', ''); $option = JRequest::getVar('option', ''); $view = JRequest::getVar('view', ''); $cid = JFactory::getApplication()->isSite() ? JRequest::getInt('cid', '') : 0; $cids = JRequest::getVar('cids', array(), $hash = 'default', 'array'); JArrayHelper::toInteger($cids, array()); $cats = array(); if ($option == 'com_flexicontent' && $view == 'category' && count($cids)) { // Current view is category view limit to descendants } else { if ($option == 'com_flexicontent' && $view == 'category' && $cid) { // Current view is category view limit to descendants $cids = array($cid); //$options[] = JHTML::_('select.option', $globalcats[$cid]->id, $globalcats[$cid]->treename); //$cats = $globalcats[$cid]->childrenarray; } else { if ($rootcatid) { // If configured ... limit to subcategory tree of a specified category $cids = array($rootcatid); //$options[] = JHTML::_('select.option', $globalcats[$rootcatid]->id, $globalcats[$rootcatid]->treename); //$cats = $globalcats[$rootcatid]->childrenarray; } } } if (count($cids)) { foreach ($cids as $_cid) { if (!isset($globalcats[$_cid])) { continue; } if (count($cids) > 1) { $cat_obj = new stdClass(); $cat_obj->id = $globalcats[$_cid]->id; $cat_obj->treename = $globalcats[$_cid]->title; // $globalcats[$_cid]->treename; $cat_obj->totalitems = $globalcats[$_cid]->totalitems; $cats[] = $cat_obj; } if (empty($globalcats[$_cid]->childrenarray)) { continue; } foreach ($globalcats[$_cid]->childrenarray as $child) { $_child = clone $child; $_child->treename = ' ' . str_replace('<sup>|_</sup> ', '', str_replace(' . ', '', $_child->treename)); $cats[] = $_child; } } } else { $cats = $globalcats; // All categories by default } if (!empty($cats)) { foreach ($cats as $k => $list) { $options[] = JHTML::_('select.option', $list->id, $list->treename . ($faceted_filter ? ' (<' . $list->totalitems . ')' : '')); } } $extra_classes = ' select2_list_selected'; break; case 'tags': // WARNING: we can not use column alias in from, join, where, group by, can use in having (some DB e.g. mysql) and in order-by // partial SQL clauses $filter->filter_valuesselect = ' tags.id AS value, tags.name AS text'; if (!$faceted_filter) { $filter->filter_valuesfrom = ' FROM #__flexicontent_tags AS tags '; } else { $filter->filter_valuesjoin = ' JOIN #__flexicontent_tags_item_relations AS tagsrel ON tagsrel.itemid = i.id ' . ' JOIN #__flexicontent_tags AS tags ON tags.id = tagsrel.tid '; } $filter->filter_valueswhere = ' '; // ... a space, (indicates not needed and prevents using default) // full SQL clauses $filter->filter_groupby = ' GROUP BY tags.id '; $filter->filter_having = null; // this indicates to use default, space is use empty $filter->filter_orderby = ' ORDER by text'; // default will order by value and not by label FlexicontentFields::createFilter($filter, $value, $formName); break; case 'created': // creation dates // creation dates case 'modified': // modification dates $date_filter_group = $filter->parameters->get('date_filter_group', 'month'); if ($date_filter_group == 'year') { $date_valformat = '%Y'; } else { if ($date_filter_group == 'month') { $date_valformat = '%Y-%m'; } else { $date_valformat = '%Y-%m-%d'; } } // Display date 'label' can be different than the (aggregated) date value $date_filter_label_format = $filter->parameters->get('date_filter_label_format', ''); $date_txtformat = $date_filter_label_format ? $date_filter_label_format : $date_valformat; // If empty then same as value if ($disable_keyboardinput) { $filter_ffid = $formName . '_' . $filter->id . '_val'; $document = JFactory::getDocument(); switch ($display_filter_as) { case 1: $document->addScriptDeclaration("\n\t\t\t\t\t\t\t\t\t\tjQuery(document).ready(function(){\n\t\t\t\t\t\t\t\t\t\t\tjQuery('#" . $filter_ffid . "').on('keydown keypress keyup', false);\n\t\t\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\t\t"); break; case 3: $document->addScriptDeclaration("\n\t\t\t\t\t\t\t\t\t\tjQuery(document).ready(function(){\n\t\t\t\t\t\t\t\t\t\t\tjQuery('#" . $filter_ffid . "1').on('keydown keypress keyup', false);\n\t\t\t\t\t\t\t\t\t\t\tjQuery('#" . $filter_ffid . "2').on('keydown keypress keyup', false);\n\t\t\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\t\t"); break; } } $filter_as_range = in_array($display_filter_as, array(2, 3, 8)); // We don't want null date if using a range $nullDate_quoted = $db->Quote($db->getNullDate()); $valuecol = sprintf(' CASE WHEN i.%s=' . $nullDate_quoted . ' THEN ' . $nullDate_quoted . ' ELSE DATE_FORMAT(i.%s, "%s") END ', $filter->field_type, $filter->field_type, $date_valformat); $textcol = sprintf(' CASE WHEN i.%s=' . $nullDate_quoted . ' THEN "' . JText::_('FLEXI_NEVER') . '" ELSE DATE_FORMAT(i.%s, "%s") END ', $filter->field_type, $filter->field_type, $date_txtformat); // WARNING: we can not use column alias in from, join, where, group by, can use in having (some DB e.g. mysql) and in order-by // partial SQL clauses $filter->filter_valuesselect = ' ' . $valuecol . ' AS value, ' . $textcol . ' AS text'; $filter->filter_valuesjoin = ' '; // ... a space, (indicates not needed and prevents using default) $filter->filter_valueswhere = $filter_as_range ? ' AND i.' . $filter->field_type . '<>' . $nullDate_quoted : ' '; // ... a space, (indicates not needed and prevents using default) // full SQL clauses $filter->filter_groupby = ' GROUP BY ' . $valuecol; $filter->filter_having = null; // this indicates to use default, space is use empty $filter->filter_orderby = ' ORDER BY ' . $valuecol; FlexicontentFields::createFilter($filter, $value, $formName); break; default: $filter->html .= 'Field type: ' . $filter->field_type . ' can not be used as search filter'; break; } // a. If field filter has defined a custom SQL query to create filter (drop-down select) options, execute it and then create the options if (!empty($query)) { $db->setQuery($query); $lists = $db->loadObjectList(); $options = array(); $options[] = JHTML::_('select.option', '', '- ' . $first_option_txt . ' -'); foreach ($lists as $list) { $options[] = JHTML::_('select.option', $list->value, $list->text . ($count_column ? ' (' . $list->found . ')' : '')); } } // b. If field filter has defined drop-down select options the create the drop-down select form field if (!empty($options)) { // Make use of select2 lib flexicontent_html::loadFramework('select2'); $classes = " use_select2_lib" . @$extra_classes; $extra_param = ''; // MULTI-select: special label and prompts if ($display_filter_as == 6) { $classes .= ' fc_label_internal fc_prompt_internal'; // Add field's LABEL internally or click to select PROMPT (via js) $_inner_lb = $label_filter == 2 ? $filter->label : JText::_('FLEXI_CLICK_TO_LIST'); // Add type to filter PROMPT (via js) $extra_param = ' data-fc_label_text="' . flexicontent_html::escapeJsText($_inner_lb, 's') . '"'; $extra_param .= ' data-fc_prompt_text="' . flexicontent_html::escapeJsText(JText::_('FLEXI_TYPE_TO_FILTER'), 's') . '"'; } // Create HTML tag attributes $attribs_str = ' class="fc_field_filter' . $classes . '" ' . $extra_param; $attribs_str .= $display_filter_as == 6 ? ' multiple="multiple" size="20" ' : ''; //$attribs_str .= ($display_filter_as==0 || $display_filter_as==6) ? ' onchange="document.getElementById(\''.$formName.'\').submit();"' : ''; // Filter name and id $filter_ffname = 'filter_' . $filter->id; $filter_ffid = $formName . '_' . $filter->id . '_val'; // Create filter $filter->html .= JHTML::_('select.genericlist', $options, $filter_ffname . '[]', $attribs_str, 'value', 'text', $value, $filter_ffid); } // Special CASE 'categories' filter, replace some tags in filter HTML ... if ($filter->field_type == 'categories') { $filter->html = str_replace('<sup>|_</sup>', '\'-', $filter->html); } }
$actions_arr[] = ($filename_shown && $link_filename ? $icon . ' ' : '') . '<a href="' . $dl_link . '" class="' . $file_classes . ' fcfile_downloadFile" title="' . $downloadsinfo . '" >' . ($filename_shown && $link_filename ? $name_str : $downloadstext) . '</a>'; } if ($authorized && $allowview && !$file_data->url) { $actions_arr[] = ' <a href="' . $dl_link . '?method=view" class="fancybox ' . $file_classes . ' fcfile_viewFile" data-fancybox-type="iframe" title="' . $viewinfo . '" > ' . $viewtext . ' </a>'; $fancybox_needed = 1; } // ADD TO CART: the link will add file to download list (tree) (handled via a downloads manager module) if ($authorized && $allowaddtocart && !$file_data->url) { // CSS class to anchor downloads list adding function $addtocart_classes = $file_classes . ($file_classes ? ' ' : '') . 'fcfile_addFile'; $attribs = ' class="' . $addtocart_classes . '"'; $attribs .= ' title="' . $addtocartinfo . '"'; $attribs .= ' filename="' . flexicontent_html::escapeJsText($_filetitle, 's') . '"'; $attribs .= ' fieldid="' . $field->id . '"'; $attribs .= ' contentid="' . $item->id . '"'; $attribs .= ' fileid="' . $file_data->id . '"'; $actions_arr[] = '<a href="javascript:;" ' . $attribs . ' >' . $addtocarttext . '</a>'; } // SHARE FILE VIA EMAIL: open a popup or inline email form ... if ($is_public && $allowshare && !$com_mailto_found) { // skip share popup form button if com_mailto is missing $str .= ' com_mailto component not found, please disable <b>download link sharing parameter</b> in this file field'; } else { if ($is_public && $allowshare) { $send_onclick = 'window.open(\'%s\',\'win2\',\'' . $status . '\'); return false;'; $send_form_url = 'index.php?option=com_flexicontent&tmpl=component' . '&task=call_extfunc&exttype=plugins&extfolder=flexicontent_fields&extname=file&extfunc=share_file_form' . '&file_id=' . $file_id . '&content_id=' . $item->id . '&field_id=' . $field->id; $actions_arr[] = '<a href="javascript:;" class="fcfile_shareFile" onclick="' . sprintf($send_onclick, JRoute::_($send_form_url)) . '" title="' . $shareinfo . '">' . $sharetext . '</a>'; }
/** * Creates the page's display * * @since 1.0 */ function display($tpl = null) { //initialize variables $option = JRequest::getVar('option'); $app = JFactory::getApplication(); $document = JFactory::getDocument(); $db = JFactory::getDBO(); $menus = $app->getMenu(); $menu = $menus->getActive(); $uri = JFactory::getURI(); $pathway = $app->getPathway(); // Get view's Model $model = $this->getModel(); $error = ''; $rows = null; $total = 0; $form_id = $form_name = "searchForm"; // Get parameters via model $params = $model->getParams(); // Get various data from the model $areas = $this->get('areas'); $state = $this->get('state'); $searchword = $state->get('keyword'); $searchphrase = $state->get('match'); $searchordering = $state->get('ordering'); // *********************************************************** // some parameter shortcuts common with advanced search plugin // *********************************************************** $canseltypes = $params->get('canseltypes', 1); $txtmode = $params->get('txtmode', 0); // 0: BASIC Index, 1: ADVANCED Index without search fields user selection, 2: ADVANCED Index with search fields user selection // Get if text searching according to specific (single) content type $show_txtfields = $params->get('show_txtfields', 1); //0:hide, 1:according to content, 2:use custom configuration $show_txtfields = $txtmode ? 0 : $show_txtfields; // disable this flag if using BASIC index for text search // Get if filtering according to specific (single) content type $show_filters = $params->get('show_filters', 1); //0:hide, 1:according to content, 2:use custom configuration // Force single type selection and showing the content type selector $type_based_search = $show_filters == 1 || $show_txtfields == 1; $canseltypes = $type_based_search ? 1 : $canseltypes; // ******************************** // Load needed JS libs & CSS styles // ******************************** FLEXI_J30GE ? JHtml::_('behavior.framework', true) : JHTML::_('behavior.mootools'); flexicontent_html::loadFramework('jQuery'); flexicontent_html::loadFramework('flexi_tmpl_common'); // Add css files to the document <head> section (also load CSS joomla template override) if (!$params->get('disablecss', '')) { $document->addStyleSheetVersion($this->baseurl . '/components/com_flexicontent/assets/css/flexicontent.css', FLEXI_VERSION); $document->addStyleSheetVersion($this->baseurl . '/components/com_flexicontent/assets/css/flexi_filters.css', FLEXI_VERSION); //$document->addCustomTag('<!--[if IE]><style type="text/css">.floattext {zoom:1;}</style><![endif]-->'); } if (file_exists(JPATH_SITE . DS . 'templates' . DS . $app->getTemplate() . DS . 'css' . DS . 'flexicontent.css')) { $document->addStyleSheetVersion($this->baseurl . '/templates/' . $app->getTemplate() . '/css/flexicontent.css', FLEXI_VERSION); } // ********************************************************** // Calculate a (browser window) page title and a page heading // ********************************************************** // Verify menu item points to current FLEXIcontent object if ($menu) { $view_ok = 'search' == @$menu->query['view']; $menu_matches = $view_ok; //$menu_params = FLEXI_J16GE ? $menu->params : new JParameter($menu->params); // Get active menu item parameters } else { $menu_matches = false; } // MENU ITEM matched, use its page heading (but use menu title if the former is not set) if ($menu_matches) { $default_heading = FLEXI_J16GE ? $menu->title : $menu->name; // Cross set (show_) page_heading / page_title for compatibility of J2.5+ with J1.5 template (and for J1.5 with J2.5 template) $params->def('page_heading', $params->get('page_title', $default_heading)); $params->def('page_title', $params->get('page_heading', $default_heading)); $params->def('show_page_heading', $params->get('show_page_title', 0)); $params->def('show_page_title', $params->get('show_page_heading', 0)); } else { // Clear some menu parameters //$params->set('pageclass_sfx', ''); // CSS class SUFFIX is behavior, so do not clear it ? // Calculate default page heading (=called page title in J1.5), which in turn will be document title below !! ... // meta_params->get('page_title') is meant for <title> but let's use as ... default page heading $default_heading = JText::_('FLEXI_SEARCH'); // Decide to show page heading (=J1.5 page title), this default to no $show_default_heading = 0; // Set both (show_) page_heading / page_title for compatibility of J2.5+ with J1.5 template (and for J1.5 with J2.5 template) $params->set('page_title', $default_heading); $params->set('page_heading', $default_heading); $params->set('show_page_heading', $show_default_heading); $params->set('show_page_title', $show_default_heading); } // Prevent showing the page heading if ... currently no reason if (0) { $params->set('show_page_heading', 0); $params->set('show_page_title', 0); } // ************************************************************ // Create the document title, by from page title and other data // ************************************************************ // Use the page heading as document title, (already calculated above via 'appropriate' logic ...) $doc_title = $params->get('page_title'); // Check and prepend or append site name to page title if ($doc_title != $app->getCfg('sitename')) { if ($app->getCfg('sitename_pagetitles', 0) == 1) { $doc_title = JText::sprintf('JPAGETITLE', $app->getCfg('sitename'), $doc_title); } elseif ($app->getCfg('sitename_pagetitles', 0) == 2) { $doc_title = JText::sprintf('JPAGETITLE', $doc_title, $app->getCfg('sitename')); } } // Finally, set document title $document->setTitle($doc_title); // ************************ // Set document's META tags // ************************ // Workaround for Joomla not setting the default value for 'robots', so component must do it $app_params = $app->getParams(); if ($_mp = $app_params->get('robots')) { $document->setMetadata('robots', $_mp); } // Overwrite with menu META data if menu matched if ($menu_matches) { if ($_mp = $menu->params->get('menu-meta_description')) { $document->setDescription($_mp); } if ($_mp = $menu->params->get('menu-meta_keywords')) { $document->setMetadata('keywords', $_mp); } if ($_mp = $menu->params->get('robots')) { $document->setMetadata('robots', $_mp); } if ($_mp = $menu->params->get('secure')) { $document->setMetadata('secure', $_mp); } } // ******************************************************************** // Get Content Types allowed for user selection in the Search Form // Also retrieve their configuration, plus the currently selected types // ******************************************************************** // Get them from configuration $contenttypes = $params->get('contenttypes', array()); // Sanitize them $contenttypes = !is_array($contenttypes) ? array($contenttypes) : $contenttypes; $contenttypes = array_unique(array_map('intval', $contenttypes)); // Make sure these are integers since we will be using them UNQUOTED // Force hidden content type selection if only 1 content type was initially configured $canseltypes = count($contenttypes) == 1 ? 0 : $canseltypes; // Type data and configuration (parameters), if no content types specified then all will be retrieved $typeData = flexicontent_db::getTypeData(implode(",", $contenttypes)); $contenttypes = array(); foreach ($typeData as $tdata) { $contenttypes[] = $tdata->id; } // Get Content Types to use either those currently selected in the Search Form, or those hard-configured in the search menu item if ($canseltypes) { $form_contenttypes = JRequest::getVar('contenttypes', array()); // Sanitize them $form_contenttypes = !is_array($form_contenttypes) ? array($form_contenttypes) : $form_contenttypes; $form_contenttypes = array_unique(array_map('intval', $form_contenttypes)); // Make sure these are integers since we will be using them UNQUOTED $_contenttypes = array_intersect($contenttypes, $form_contenttypes); if (!empty($_contenttypes)) { $contenttypes = $_contenttypes; } // catch empty case: no content types were given or not-allowed content types were passed } // Check for zero content type (can occur during sanitizing content ids to integers) if (!empty($contenttypes)) { foreach ($contenttypes as $i => $v) { if (!strlen($contenttypes[$i])) { unset($contenttypes[$i]); } } } // Type based seach, get a single content type (first one, if more than 1 were given ...) if ($type_based_search && !empty($contenttypes)) { $single_contenttype = reset($contenttypes); $contenttypes = array($single_contenttype); } else { $single_contenttype = false; } // ************************************* // Text Search Fields of the search form // ************************************* if (!$txtmode) { $txtflds = array(); $fields_text = array(); } else { $txtflds = ''; if ($show_txtfields) { if ($show_txtfields == 1) { $txtflds = $single_contenttype ? $typeData[$single_contenttype]->params->get('searchable', '') : ''; } else { $txtflds = $params->get('txtflds', ''); } } // Sanitize them $txtflds = preg_replace("/[\"'\\\\]/u", "", $txtflds); $txtflds = array_unique(preg_split("/\\s*,\\s*/u", $txtflds)); if (!strlen($txtflds[0])) { unset($txtflds[0]); } // Create a comma list of them $txtflds_list = count($txtflds) ? "'" . implode("','", $txtflds) . "'" : ''; // Retrieve field properties/parameters, verifying the support to be used as Text Search Fields // This will return all supported fields if field limiting list is empty $fields_text = FlexicontentFields::getSearchFields($key = 'id', $indexer = 'advanced', $txtflds_list, $contenttypes, $load_params = true, 0, 'search'); if (empty($fields_text)) { // all entries of field limiting list were invalid , get ALL if (!empty($contenttypes)) { $fields_text = FlexicontentFields::getSearchFields($key = 'id', $indexer = 'advanced', null, $contenttypes, $load_params = true, 0, 'search'); } else { $fields_text = array(); } } } // ******************************** // Filter Fields of the search form // ******************************** // Get them from type configuration or from search menu item $filtflds = ''; if ($show_filters) { if ($show_filters == 1) { $filtflds = $single_contenttype ? $typeData[$single_contenttype]->params->get('filters', '') : ''; } else { $filtflds = $params->get('filtflds', ''); } } // Sanitize them $filtflds = preg_replace("/[\"'\\\\]/u", "", $filtflds); $filtflds = array_unique(preg_split("/\\s*,\\s*/u", $filtflds)); if (!strlen($filtflds[0])) { unset($filtflds[0]); } // Create a comma list of them $filtflds_list = count($filtflds) ? "'" . implode("','", $filtflds) . "'" : ''; // Retrieve field properties/parameters, verifying the support to be used as Filter Fields // This will return all supported fields if field limiting list is empty if (count($filtflds)) { $filters_tmp = FlexicontentFields::getSearchFields($key = 'name', $indexer = 'advanced', $filtflds_list, $contenttypes, $load_params = true, 0, 'filter'); // Use custom order $filters = array(); if ($canseltypes && $show_filters) { foreach ($filtflds as $field_name) { if (empty($filters_tmp[$field_name])) { continue; } $filter_id = $filters_tmp[$field_name]->id; $filters[$filter_id] = $filters_tmp[$field_name]; } } else { foreach ($filters_tmp as $filter) { $filters[$filter->id] = $filter; // index by filter_id in this case too (for consistency, although we do not use the array index ?) } } unset($filters_tmp); } // If configured filters were not found/invalid for the current content type(s) // then retrieve all fields marked as filterable for the give content type(s) this is useful to list per content type filters automatically, even when not set or misconfigured if (empty($filters)) { if (!empty($contenttypes)) { $filters = FlexicontentFields::getSearchFields($key = 'id', $indexer = 'advanced', null, $contenttypes, $load_params = true, 0, 'filter'); } else { $filters = array(); } } // **************************************** // Create Form Elements (the 'lists' array) // **************************************** $lists = array(); // *** Selector of Content Types if ($canseltypes) { $types = array(); if ($show_filters) { $types[] = JHTML::_('select.option', '', JText::_('FLEXI_PLEASE_SELECT')); } foreach ($typeData as $type) { $types[] = JHTML::_('select.option', $type->id, JText::_($type->name)); } $multiple_param = $show_filters ? ' onchange="adminFormPrepare(this.form); this.form.submit();" ' : ' multiple="multiple" '; $attribs = $multiple_param . ' size="5" class="fc_field_filter use_select2_lib fc_label_internal fc_prompt_internal"'; $attribs .= ' data-fc_label_text="' . flexicontent_html::escapeJsText(JText::_('FLEXI_CLICK_TO_LIST'), 's') . '"'; $attribs .= ' data-fc_prompt_text="' . flexicontent_html::escapeJsText(JText::_('FLEXI_TYPE_TO_FILTER'), 's') . '"'; $lists['contenttypes'] = JHTML::_('select.genericlist', $types, 'contenttypes[]', $attribs, 'value', 'text', empty($form_contenttypes) ? '' : $form_contenttypes, 'contenttypes'); /* $checked = !count($form_contenttypes) || !strlen($form_contenttypes[0]); $checked_attr = $checked ? 'checked="checked"' : ''; $checked_class = $checked ? 'fc_highlight' : ''; $lists['contenttypes'] = '<ul class="fc_field_filter fc_checkradio_group">'; $lists['contenttypes'] .= ' <li class="fc_checkradio_option fc_checkradio_special">'; $lists['contenttypes'] .= ' <input href="javascript:;" onclick="fc_toggleClass(this, \'fc_highlight\', 1);" '; $lists['contenttypes'] .= ' id="_contenttypes_0" type="checkbox" name="contenttypes[0]" '; $lists['contenttypes'] .= ' value="" '.$checked_attr.' class="fc_checkradio" />'; $lists['contenttypes'] .= ' <label class="'.$checked_class.'" for="_contenttypes_0">'; $lists['contenttypes'] .= ' -'.JText::_('FLEXI_ALL').'-'; $lists['contenttypes'] .= ' </label>'; $lists['contenttypes'] .= ' </li>'; foreach($typeData as $type) { $checked = in_array($type->value, $form_contenttypes); $checked_attr = $checked ? 'checked=checked' : ''; $checked_class = $checked ? ' fc_highlight' : ''; $lists['contenttypes'] .= ' <li class="fc_checkradio_option">'; $lists['contenttypes'] .= ' <input href="javascript:;" onclick="fc_toggleClass(this, \'fc_highlight\');" '; $lists['contenttypes'] .= ' id="_contenttypes_'.$type->value.'" type="checkbox" name="contenttypes[]" '; $lists['contenttypes'] .= ' value="'.$type->value.'" '.$checked_attr.' class="fc_checkradio" />'; $lists['contenttypes'] .= ' <label class="'.$checked_class.'" for="_contenttypes_'.$type->value.'">'; $lists['contenttypes'] .= ' '.JText::_($type->text); $lists['contenttypes'] .= ' </label>'; $lists['contenttypes'] .= ' </li>'; } $lists['contenttypes'] .= '</ul>'; */ } // *** Selector of Fields for text searching if ($txtmode == 2 && count($fields_text)) { // Get selected text fields in the Search Form $form_txtflds = JRequest::getVar('txtflds', array()); if (!$form_txtflds || empty($form_txtflds)) { $form_txtflds = array(); //array('__FC_ALL__'); //array_keys($fields_text); } $attribs = ' multiple="multiple" size="5" class="fc_field_filter use_select2_lib fc_label_internal fc_prompt_internal"'; $attribs .= ' data-fc_label_text="' . flexicontent_html::escapeJsText(JText::_('FLEXI_CLICK_TO_LIST'), 's') . '"'; $attribs .= ' data-fc_prompt_text="' . flexicontent_html::escapeJsText(JText::_('FLEXI_TYPE_TO_FILTER'), 's') . '"'; $lists['txtflds'] = JHTML::_('select.genericlist', $fields_text, 'txtflds[]', $attribs, 'name', 'label', $form_txtflds, 'txtflds'); /* $checked = !count($form_txtflds) || !strlen($form_txtflds[0]); $checked_attr = $checked ? 'checked="checked"' : ''; $checked_class = $checked ? 'fc_highlight' : ''; $lists['txtflds'] = '<ul class="fc_field_filter fc_checkradio_group">'; $lists['txtflds'] .= ' <li class="fc_checkradio_option fc_checkradio_special">'; $lists['txtflds'] .= ' <input href="javascript:;" onclick="fc_toggleClass(this, \'fc_highlight\', 1);" '; $lists['txtflds'] .= ' id="_txtflds_0" type="checkbox" name="txtflds[0]" value="" '; $lists['txtflds'] .= ' value="" '.$checked_attr.' class="fc_checkradio" />'; $lists['txtflds'] .= ' <label class="'.$checked_class.'" for="_txtflds_0">'; $lists['txtflds'] .= ' -'.JText::_('FLEXI_ALL').'-'; $lists['txtflds'] .= ' </label>'; $lists['txtflds'] .= ' </li>'; foreach($fields_text as $field) { $checked = in_array($field->name, $form_txtflds); $checked_attr = $checked ? 'checked=checked' : ''; $checked_class = $checked ? ' fc_highlight' : ''; $lists['txtflds'] .= ' <li class="fc_checkradio_option">'; $lists['txtflds'] .= ' <input href="javascript:;" onclick="fc_toggleClass(this, \'fc_highlight\');" '; $lists['txtflds'] .= ' id="_txtflds_'.$field->id.'" type="checkbox" name="txtflds[]" '; $lists['txtflds'] .= ' value="'.$field->name.'" '.$checked_attr.' class="fc_checkradio" />'; $lists['txtflds'] .= ' <label class="class=""'.$checked_class.'" for="_txtflds_'.$field->id.'">'; $lists['txtflds'] .= ' '.JText::_($field->label); $lists['txtflds'] .= ' </label>'; $lists['txtflds'] .= ' </li>'; } $lists['txtflds'] .= '</ul>'; */ } // *** Selector of FLEXIcontent Results Ordering if ($orderby_override = $params->get('orderby_override', 1)) { $lists['orderby'] = flexicontent_html::ordery_selector($params, $form_id, $autosubmit = 0); } // *** Selector of Pagination Limit if ($limit_override = $params->get('limit_override', 1)) { $lists['limit'] = flexicontent_html::limit_selector($params, $form_id, $autosubmit = 0); } // *** Selector of non-FLEXIcontent Results Ordering if ($show_searchordering = $params->get('show_searchordering', 1)) { // built select lists $orders = array(); $orders[] = JHTML::_('select.option', 'newest', JText::_('FLEXI_ADV_NEWEST_FIRST')); $orders[] = JHTML::_('select.option', 'oldest', JText::_('FLEXI_ADV_OLDEST_FIRST')); $orders[] = JHTML::_('select.option', 'popular', JText::_('FLEXI_ADV_MOST_POP')); $orders[] = JHTML::_('select.option', 'alpha', JText::_('FLEXI_ADV_ALPHA')); $orders[] = JHTML::_('select.option', 'category', JText::_('FLEXI_ADV_SEARCH_SEC_CAT')); $lists['ordering'] = JHTML::_('select.genericlist', $orders, 'o', 'class="fc_field_filter use_select2_lib"', 'value', 'text', $searchordering, 'ordering'); } // *** Selector for usage of Search Text if ($show_searchphrase = $params->get('show_searchphrase', 1)) { $searchphrase_names = array('natural' => 'FLEXI_NATURAL_PHRASE', 'natural_expanded' => 'FLEXI_NATURAL_PHRASE_GUESS_RELEVANT', 'all' => 'FLEXI_ALL_WORDS', 'any' => 'FLEXI_ANY_WORDS', 'exact' => 'FLEXI_EXACT_PHRASE'); $phrases = array(); foreach ($searchphrase_names as $searchphrase_value => $searchphrase_name) { $_obj = new stdClass(); $_obj->value = $searchphrase_value; $_obj->text = $searchphrase_name; $phrases[] = $_obj; } $lists['searchphrase'] = JHTML::_('select.genericlist', $phrases, 'p', 'class="fc_field_filter use_select2_lib"', 'value', 'text', $searchphrase, 'searchphrase', $_translate = true); /*$lists['searchphrase'] = '<ul class="fc_field_filter fc_checkradio_group">'; foreach ($searchphrase_names as $searchphrase_value => $searchphrase_name) { $lists['searchphrase'] .= ' <li class="fc_checkradio_option fc_checkradio_special">'; $checked = $searchphrase_value == $searchphrase; $checked_attr = $checked ? 'checked=checked' : ''; $checked_class = $checked ? 'fc_highlight' : ''; $lists['searchphrase'] .= ' <input href="javascript:;" onclick="fc_toggleClassGrp(this.parentNode, \'fc_highlight\');" id="searchphrase_'.$searchphrase_value.'" type="radio" name="p" value="'.$searchphrase_value.'" '.$checked_attr.' />'; $lists['searchphrase'] .= ' <label class="'.$checked_class.'" style="display:inline-block; white-space:nowrap;" for="searchphrase_'.$searchphrase_value.'">'; $lists['searchphrase'] .= JText::_($searchphrase_name); $lists['searchphrase'] .= ' </label>'; $lists['searchphrase'] .= ' </li>'; } $lists['searchphrase'] .= '</ul>';*/ } // *** Selector for filter combination /*if($show_filtersop = $params->get('show_filtersop', 1)) { $default_filtersop = $params->get('default_filtersop', 'all'); $filtersop = JRequest::getVar('filtersop', $default_filtersop); $filtersop_arr = array(); $filtersop_arr[] = JHTML::_('select.option', 'all', JText::_( 'FLEXI_SEARCH_ALL' ) ); $filtersop_arr[] = JHTML::_('select.option', 'any', JText::_( 'FLEXI_SEARCH_ANY' ) ); $lists['filtersop']= JHTML::_('select.radiolist', $filtersop_arr, 'filtersop', '', 'value', 'text', $filtersop ); }*/ // *** Selector of Search Areas // If showing this is disabled, then FLEXIcontent (advanced) search model will not use all search areas, // but instead it will use just 'flexicontent' search area, that is the search area of FLEXIcontent (advanced) search plugin if ($params->get('show_searchareas', 0)) { // Get Content Types currently selected in the Search Form $form_areas = JRequest::getVar('areas', array()); //if ( empty($form_areas) || !count($form_areas) ) $form_areas = array('flexicontent'); $checked = empty($form_areas) || !count($form_areas); $checked_attr = $checked ? 'checked="checked"' : ''; $checked_class = $checked ? 'fc_highlight' : ''; // Create array of area options $options = array(); foreach ($areas['search'] as $area => $label) { $_area = new stdClass(); $_area->text = $label; $_area->value = $area; $options[] = $_area; } $attribs = ' multiple="multiple" size="5" class="fc_field_filter use_select2_lib fc_label_internal fc_prompt_internal"'; $attribs .= ' data-fc_label_text="' . flexicontent_html::escapeJsText(JText::_('FLEXI_CLICK_TO_LIST'), 's') . '"'; $attribs .= ' data-fc_prompt_text="' . flexicontent_html::escapeJsText(JText::_('FLEXI_TYPE_TO_FILTER'), 's') . '"'; $lists['areas'] = JHTML::_('select.genericlist', $options, 'areas[]', $attribs, 'value', 'text', $form_areas, 'areas', $do_jtext = true); /* $lists['areas'] = '<ul class="fc_field_filter fc_checkradio_group">'; $lists['areas'] .= ' <li class="fc_checkradio_option fc_checkradio_special">'; $lists['areas'] .= ' <input href="javascript:;" onclick="fc_toggleClass(this, \'fc_highlight\', 1);" '; $lists['areas'] .= ' id="area_0" type="checkbox" name="area[0]" '; $lists['areas'] .= ' value="" '.$checked_attr.' class="fc_checkradio" />'; $lists['areas'] .= ' <label class="'.$checked_class.'" for="_txtflds_0">'; $lists['areas'] .= ' -'.JText::_('FLEXI_CONTENT_ONLY').'-'; $lists['areas'] .= ' </label>'; $lists['areas'] .= ' </li>'; foreach($areas['search'] as $area_name => $area_label) { $checked = in_array($area_name, $form_areas); $checked_attr = $checked ? 'checked=checked' : ''; $checked_class = $checked ? ' fc_highlight' : ''; $lists['areas'] .= ' <li class="fc_checkradio_option">'; $lists['areas'] .= ' <input href="javascript:;" onclick="fc_toggleClass(this, \'fc_highlight\');" '; $lists['areas'] .= ' id="area_'.$area_name.'" type="checkbox" name="areas[]" '; $lists['areas'] .= ' value="'.$area_name.'" '.$checked_attr.' class="fc_checkradio" />'; $lists['areas'] .= ' <label class="'.$checked_class.'" for="area_'.$area_name.'">'; $lists['areas'] .= ' '.JText::_($area_label); $lists['areas'] .= ' </label>'; $lists['areas'] .= ' </li>'; } $lists['areas'] .= '</ul>'; */ } // log the search FLEXIadvsearchHelper::logSearch($searchword); //limit searchword $min_word_len = $app->getUserState($option . '.min_word_len', 0); $min = $min_word_len ? $min_word_len : $params->get('minchars', 3); $max = $params->get('maxchars', 200); if (FLEXIadvsearchHelper::limitSearchWord($searchword, $min, $max)) { $error = JText::sprintf('FLEXI_SEARCH_MESSAGE', $min, $max); } // sanitise searchword if (FLEXIadvsearchHelper::santiseSearchWord($searchword, $state->get('match'), $min)) { $error = JText::_('IGNOREKEYWORD'); } if (!$searchword && count(JRequest::get('post'))) { //$error = JText::_( 'Enter a search keyword' ); } // put the filtered results back into the model // for next release, the checks should be done in the model perhaps... $state->set('keyword', $searchword); $filter_word_like_any = $params->get('filter_word_like_any', 0); if (!$error) { require_once JPATH_SITE . DS . 'components' . DS . 'com_flexicontent' . DS . 'helpers' . DS . 'route.php'; $results = $this->get('data'); $total = $this->get('total'); $pageNav = $this->get('pagination'); // URL-encode filter values foreach ($_GET as $i => $v) { if (substr($i, 0, 6) === "filter") { $_revert = array('%21' => '!', '%2A' => '*', '%27' => "'", '%28' => '(', '%29' => ')'); $v = str_replace('&', '__amp__', $v); $v = strtr(rawurlencode($v), $_revert); $pageNav->setAdditionalUrlParam($i, $v); } } if ($state->get('match') == 'exact') { $searchwords = array($searchword); //$needle = $searchword; } else { $searchwords = preg_split("/\\s+/u", $searchword); //print_r($searchwords); } // Create regular expressions, for highlighting the matched words $w_regexp_highlight = array(); foreach ($searchwords as $n => $_word) { $w_regexp_highlight[$_word] = mb_strlen($_word, 'utf-8') <= 2 || $n + 1 < count($searchwords) ? '#\\b(' . preg_quote($_word, '#') . ')\\b#iu' : '#\\b(' . preg_quote($_word, '#') . ')#iu'; } for ($i = 0; $i < count($results); $i++) { $result =& $results[$i]; if (strlen($searchwords[0])) { $parts = FLEXIadvsearchHelper::prepareSearchContent($result->text, $params->get('text_chars', 200), $searchwords); //if( count($parts)>1 ) { echo "<pre>"; print_r($parts); exit;} foreach ($parts as $word_found => $part) { if (!$word_found) { continue; } $searchRegex = $w_regexp_highlight[$word_found]; $parts[$word_found] = preg_replace($searchRegex, '_fc_highlight_start_\\0_fc_highlight_end_', $part); } $result->text = implode($parts, " <br/> "); $replace_count_total = 0; // This is for LIKE %word% search for languages without spaces if ($filter_word_like_any) { if (strlen($word_found) <= 2) { continue; } // Do not highlight too small words, since we do not consider spaces foreach ($searchwords as $_word) { $searchRegex = '#(' . preg_quote($_word, '#') . '[^\\s]*)#iu'; $result->text = preg_replace($searchRegex, '_fc_highlight_start_\\0_fc_highlight_end_', $result->text, 1, $replace_count); if ($replace_count) { $replace_count_total++; } } } $result->text = str_replace('_fc_highlight_start_', '<span class="highlight">', $result->text); $result->text = str_replace('_fc_highlight_end_', '</span>', $result->text); // Add some message about matches /*if ( $state->get('match')=='any' ) { $text_search_header = "<u><b>".JText::sprintf('Text Search matched at least %d %% (%d out of %d words)', $replace_count_total/count($searchwords) * 100, $replace_count_total, count($searchwords)).": </b></u><br/>"; } else if ( $state->get('match')=='all' ) { $text_search_header = "<u><b>".JText::sprintf('Text Search (all %d words required)', count($searchwords)).": </b></u><br/>"; } else if ( $state->get('match')=='exact' ) { $text_search_header = "<u><b>".JText::_('Text Search (exact phrase)').": </b></u><br/>"; } else if ( $state->get('match')=='natural_expanded' ) { $text_search_header = "<u><b>".JText::_('Text Search (phrase, guessing related)').": </b></u><br/>"; } else if ( $state->get('match')=='natural' ) { $text_search_header = "<u><b>".JText::_('Text Search (phrase)').": </b></u><br/>"; } $result->text = $text_search_header . $result->text;*/ } else { $parts = FLEXIadvsearchHelper::prepareSearchContent($result->text, $params->get('text_chars', 200), array()); $result->text = implode($parts, " <br/> "); } /*if ( !empty($result->fields_text) ) { $result->text .= "<br/><u><b>".JText::_('Attribute filters matched')." : </b></u>"; $result->fields_text = str_replace('[span=highlight]', '<span class="highlight">', $result->fields_text); $result->fields_text = str_replace('[/span]', '</span>', $result->fields_text); $result->fields_text = str_replace('[br /]', '<br />', $result->fields_text); $result->text .= $result->fields_text; }*/ $result->text = str_replace('[[[', '<', $result->text); $result->text = str_replace(']]]', '>', $result->text); $result->created = $result->created ? JHTML::Date($result->created) : ''; $result->count = $i + 1; } } $this->result = JText::sprintf('FLEXI_TOTALRESULTSFOUND', $total); // ****************************************************************** // Create HTML of filters (-AFTER- getData of model have been called) // ****************************************************************** foreach ($filters as $filter) { $filter->parameters->set('display_label_filter_s', 0); $filter->value = JRequest::getVar('filter_' . $filter->id, false); //$fieldsearch = $app->getUserStateFromRequest( 'flexicontent.search.'.'filter_'.$filter->id, 'filter_'.$filter->id, array(), 'array' ); //echo "Field name: ".$filter->name; echo ":: ". 'filter_'.$filter->id ." :: value: "; print_r($filter->value); echo "<br/>\n"; $field_filename = $filter->iscore ? 'core' : $filter->field_type; FLEXIUtilities::call_FC_Field_Func($field_filename, 'onAdvSearchDisplayFilter', array(&$filter, $filter->value, $form_id)); } //echo "<pre>"; print_r($_GET); exit; // Create links $link = JRoute::_(FlexicontentHelperRoute::getSearchRoute(0, $menu_matches ? $menu->id : 0)); //$print_link = JRoute::_('index.php?view=search&pop=1&tmpl=component&print=1'); $curr_url = str_replace('&', '&', $_SERVER['REQUEST_URI']); $print_link = $curr_url . (strstr($curr_url, '?') ? '&' : '?') . 'pop=1&tmpl=component&print=1'; $pageclass_sfx = htmlspecialchars($params->get('pageclass_sfx')); $this->assignRef('action', $link); // $uri->toString() $this->assignRef('print_link', $print_link); $this->assignRef('contenttypes', $contenttypes); $this->assignRef('filters', $filters); $this->assignRef('results', $results); $this->assignRef('lists', $lists); $this->assignRef('params', $params); $this->assignRef('pageNav', $pageNav); $this->assignRef('pageclass_sfx', $pageclass_sfx); $this->assignRef('typeData', $typeData); $this->assign('ordering', $state->get('ordering')); $this->assign('searchword', $searchword); $this->assign('searchphrase', $state->get('match')); $this->assign('searchareas', $areas); $this->assign('total', $total); $this->assign('error', $error); $this->assignRef('document', $document); $this->assign('form_id', $form_id); $this->assign('form_name', $form_name); $print_logging_info = $params->get('print_logging_info'); if ($print_logging_info) { global $fc_run_times; $start_microtime = microtime(true); } parent::display($tpl); if ($print_logging_info) { @($fc_run_times['template_render'] += round(1000000 * 10 * (microtime(true) - $start_microtime)) / 10); } }
static function createFilter(&$filter, $value = '', $formName = 'adminForm', $indexed_elements = false, $search_prop = '') { static $apply_cache = null; static $faceted_overlimit_msg = null; $user = JFactory::getUser(); $cparams = JComponentHelper::getParams('com_flexicontent'); // createFilter maybe called in backend too ... $print_logging_info = $cparams->get('print_logging_info'); $option = JRequest::getVar('option'); $view = JRequest::getVar('view'); $is_fc_component = $option == 'com_flexicontent'; $isCategoryView = $is_fc_component && $view == 'category'; $isSearchView = $is_fc_component && $view == 'search'; if ($print_logging_info) { global $fc_run_times; $start_microtime = microtime(true); } // Apply caching to filters regardless of cache setting ... $apply_cache = FLEXI_CACHE; if ($apply_cache) { $itemcache = JFactory::getCache('com_flexicontent_filters'); // Get Joomla Cache of '...items' Caching Group $itemcache->setCaching(1); // Force cache ON $itemcache->setLifeTime(FLEXI_CACHE_TIME); // Set expire time (default is 1 hour) } $isDate = in_array($filter->field_type, array('date', 'created', 'modified')) || $filter->parameters->get('isdate', 0); $default_size = $isDate ? 15 : 30; $_s = $isSearchView ? '_s' : ''; // Some parameter shortcuts $label_filter = $filter->parameters->get('display_label_filter' . $_s, 0); // How to show filter label $size = $filter->parameters->get('text_filter_size', $default_size); // Size of filter $faceted_filter = $filter->parameters->get('faceted_filter' . $_s, 2); $display_filter_as = $filter->parameters->get('display_filter_as' . $_s, 0); // Filter Type of Display $isSlider = $display_filter_as == 7 || $display_filter_as == 8; $slider_display_config = $filter->parameters->get('slider_display_config' . $_s, 1); // Slider found values: 1 or custom values/labels: 2 $filter_vals_display = $filter->parameters->get('filter_vals_display' . $_s, 0); $isRange = in_array($display_filter_as, array(2, 3, 8)); $require_all_param = $filter->parameters->get('filter_values_require_all', 0); $require_all = count($value) > 1 && !$isRange ? $require_all_param : 0; $combine_tip = $filter->parameters->get('filter_values_require_all_tip', 0); $show_matching_items = $filter->parameters->get('show_matching_items' . $_s, 1); $show_matches = $isRange || !$faceted_filter ? 0 : $show_matching_items; $hide_disabled_values = $filter->parameters->get('hide_disabled_values' . $_s, 0); $get_filter_vals = in_array($display_filter_as, array(0, 2, 4, 5, 6)) || $isSlider && $slider_display_config == 1; $filter_ffname = 'filter_' . $filter->id; $filter_ffid = $formName . '_' . $filter->id . '_val'; // Make sure the current filtering values match the field filter configuration to single or multi-value if (in_array($display_filter_as, array(2, 3, 5, 6, 8))) { if (!is_array($value)) { $value = strlen($value) ? array($value) : array(); } } else { if (is_array($value)) { $value = @$value[0]; } } // Escape values for output if (!is_array($value)) { $value = htmlspecialchars($value, ENT_COMPAT, 'UTF-8'); } else { foreach ($value as $i => $v) { $value[$i] = htmlspecialchars($value[$i], ENT_COMPAT, 'UTF-8'); } } // Alter search property name (indexed fields only), remove underscore _ at start & end of it if ($indexed_elements && $search_prop) { preg_match("/^_([a-zA-Z_0-9]+)_\$/", $search_prop, $prop_matches); $search_prop = @$prop_matches[1]; } // Get filtering values, this can be cached if not filtering according to current category filters if ($get_filter_vals) { $view_join = ''; $view_join_n_text = ''; $view_where = ''; $filters_where = array(); $text_search = ''; $view_total = 0; // *** Limiting of displayed filter values according to current category filtering, but show all field values if filter is active if ($isCategoryView) { // category view, use parameter to decide if limitting filter values global $fc_catview; if ($faceted_filter) { $view_join = @$fc_catview['join_clauses']; $view_join_n_text = @$fc_catview['join_clauses_with_text']; $view_where = @$fc_catview['where_conf_only']; $filters_where = @$fc_catview['filters_where']; $text_search = $fc_catview['search']; $view_total = isset($fc_catview['view_total']) ? $fc_catview['view_total'] : 0; } } else { if ($isSearchView) { // search view, use parameter to decide if limitting filter values global $fc_searchview; if (empty($fc_searchview)) { return array(); } // search view plugin disabled ? if ($faceted_filter) { $view_join = $fc_searchview['join_clauses']; $view_join_n_text = $fc_searchview['join_clauses_with_text']; $view_where = $fc_searchview['where_conf_only']; $filters_where = $fc_searchview['filters_where']; $text_search = $fc_searchview['search']; $view_total = isset($fc_searchview['view_total']) ? $fc_searchview['view_total'] : 0; } } } $createFilterValues = !$isSearchView ? 'createFilterValues' : 'createFilterValuesSearch'; // This is hack for filter core properties to be filterable in search view without being added to the adv search index if ($filter->field_type == 'coreprops' && $view == 'search') { $createFilterValues = 'createFilterValues'; } // Get filter values considering PAGE configuration (regardless of ACTIVE filters) if ($apply_cache) { $results_page = $itemcache->call(array('FlexicontentFields', $createFilterValues), $filter, $view_join, $view_where, array(), $indexed_elements, $search_prop); } else { if (!$isSearchView) { $results_page = FlexicontentFields::createFilterValues($filter, $view_join, $view_where, array(), $indexed_elements, $search_prop); } else { $results_page = FlexicontentFields::createFilterValuesSearch($filter, $view_join, $view_where, array(), $indexed_elements, $search_prop); } } // Get filter values considering ACTIVE filters, but only if there is at least ONE filter active $faceted_max_item_limit = 10000; if ($faceted_filter == 2) { if ($view_total <= $faceted_max_item_limit) { // DO NOT cache at this point the filter combinations are endless, so they will produce big amounts of cached data, that will be rarely used ... // but if only a single filter is active we can get the cached result of it ... because its own filter_where is not used for the filter itself if (!$text_search && (count($filters_where) == 0 || count($filters_where) == 1 && isset($filters_where[$filter->id]))) { $results_active = $results_page; } else { if (!$isSearchView) { $results_active = FlexicontentFields::createFilterValues($filter, $view_join_n_text, $view_where, $filters_where, $indexed_elements, $search_prop); } else { $results_active = FlexicontentFields::createFilterValuesSearch($filter, $view_join_n_text, $view_where, $filters_where, $indexed_elements, $search_prop); } } } else { if ($faceted_overlimit_msg === null) { // Set a notice message about not counting item per filter values and instead showing item TOTAL of current category / view $faceted_overlimit_msg = 1; $filter_messages = JRequest::getVar('filter_message', array()); $filter_messages[] = JText::sprintf('FLEXI_FACETED_ITEM_LIST_OVER_LIMIT', $faceted_max_item_limit, $view_total); JRequest::setVar('filter_messages', $filter_messages); } } } // Decide which results to show those based: (a) on active filters or (b) on page configuration // This depends if hiding disabled values (for FACETED: 2) AND if active filters exist $use_active_vals = $hide_disabled_values && isset($results_active); $results_shown = $use_active_vals ? $results_active : $results_page; $update_found = !$use_active_vals && isset($results_active); // Set usage counters $add_usage_counters = $faceted_filter == 2 && $show_matches; $results = array(); foreach ($results_shown as $i => $result) { $results[$i] = $result; // FACETED: 0,1 or NOT showing usage // Set usage to non-zero value e.g. -1 ... which maybe used (e.g. disabling values) but not be displayed if (!$show_matches || $faceted_filter < 2) { $results[$i]->found = -1; } else { if ($update_found) { $results[$i]->found = (int) @$results_active[$i]->found; } else { } } // Append value usage to value's label if ($add_usage_counters && $results[$i]->found) { $results[$i]->text .= ' (' . $results[$i]->found . ')'; } // THESE for indexed fields should have been cloned, so it is ok to modify } } else { $add_usage_counters = false; $faceted_filter = 0; // clear faceted filter flag } // Prepend Field's Label to filter HTML // Commented out because it was moved in to form template file //$filter->html = $label_filter==1 ? $filter->label.': ' : ''; $filter->html = ''; // *** Create the form field(s) used for filtering switch ($display_filter_as) { case 0: case 2: case 6: // 0: Select (single value selectable), 2: Dual select (value range), 6: Multi Select (multiple values selectable) $options = array(); // MULTI-select does not has an internal label a drop-down list option if ($display_filter_as != 6) { if ($label_filter == -1) { // *** e.g. BACKEND ITEMS MANAGER custom filter $filter->html = '<span class="' . $filter->parameters->get('label_filter_css' . $_s, 'label') . '">' . $filter->label . '</span>'; $first_option_txt = ''; } else { if ($label_filter == 2) { $first_option_txt = $filter->label; } else { $first_option_txt = $filter->parameters->get('filter_usefirstoption' . $_s, 0) ? $filter->parameters->get('filter_firstoptiontext' . $_s, 'FLEXI_ALL') : 'FLEXI_ANY'; $first_option_txt = JText::_($first_option_txt); } } $options[] = JHTML::_('select.option', '', !$first_option_txt ? '-' : '- ' . $first_option_txt . ' -'); } foreach ($results as $result) { if (!strlen($result->value)) { continue; } $options[] = JHTML::_('select.option', $result->value, $result->text, 'value', 'text', $disabled = $faceted_filter == 2 && !$result->found); } // Make use of select2 lib flexicontent_html::loadFramework('select2'); $classes = " use_select2_lib"; $extra_param = ''; // MULTI-select: special label and prompts if ($display_filter_as == 6) { //$classes .= ' fc_label_internal fc_prompt_internal'; $classes .= ' fc_prompt_internal'; // Add field's LABEL internally or click to select PROMPT (via js) $_inner_lb = $label_filter == 2 ? $filter->label : JText::_('FLEXI_CLICK_TO_LIST'); // Add type to filter PROMPT (via js) //$extra_param = ' data-fc_label_text="'.flexicontent_html::escapeJsText($_inner_lb,'s').'"'; $extra_param = ' placeholder="' . flexicontent_html::escapeJsText($_inner_lb, 's') . '"'; $extra_param .= ' data-fc_prompt_text="' . flexicontent_html::escapeJsText(JText::_('FLEXI_TYPE_TO_FILTER'), 's') . '"'; } // Create HTML tag attributes $attribs_str = ' class="fc_field_filter' . $classes . '" ' . $extra_param; $attribs_str .= $display_filter_as == 6 ? ' multiple="multiple" size="20" ' : ''; if ($extra_attribs = $filter->parameters->get('filter_extra_attribs' . $_s, '')) { $attribs_str .= $extra_attribs; } //$attribs_str .= ($display_filter_as==0 || $display_filter_as==6) ? ' onchange="document.getElementById(\''.$formName.'\').submit();"' : ''; if ($display_filter_as == 6 && $combine_tip) { $filter->html .= ' <span class="fc_filter_tip_inline badge badge-info">' . JText::_(!$require_all_param ? 'FLEXI_ANY_OF' : 'FLEXI_ALL_OF') . '</span> '; } if ($display_filter_as == 0) { $filter->html .= JHTML::_('select.genericlist', $options, $filter_ffname, $attribs_str, 'value', 'text', $value, $filter_ffid); } else { if ($display_filter_as == 6) { $filter->html .= JHTML::_('select.genericlist', $options, $filter_ffname . '[]', $attribs_str, 'value', 'text', $value, $filter_ffid); } else { $filter->html .= JHTML::_('select.genericlist', $options, $filter_ffname . '[1]', $attribs_str, 'value', 'text', @$value[1], $filter_ffid . '1'); $filter->html .= '<span class="fc_range"></span>'; $filter->html .= JHTML::_('select.genericlist', $options, $filter_ffname . '[2]', $attribs_str, 'value', 'text', @$value[2], $filter_ffid . '2'); } } break; case 1: case 3: case 7: case 8: // (TODO: autocomplete) ... 1: Text input, 3: Dual text input (value range), both of these can be JS date calendars, 7: Slider, 8: Slider range if (!$isSlider) { $_inner_lb = $label_filter == 2 ? $filter->label : JText::_($isDate ? 'FLEXI_CLICK_CALENDAR' : ''); $_inner_lb = flexicontent_html::escapeJsText($_inner_lb, 's'); //$attribs_str = ' class="fc_field_filter fc_label_internal '.($isDate ? 'fc_iscalendar' : '').'" data-fc_label_text="'.$_inner_lb.'"'; //$attribs_arr = array('class'=>'fc_field_filter fc_label_internal '.($isDate ? 'fc_iscalendar' : '').'', 'data-fc_label_text' => $_inner_lb ); $attribs_str = ' class="fc_field_filter ' . ($isDate ? 'fc_iscalendar' : '') . '" placeholder="' . $_inner_lb . '"'; $attribs_arr = array('class' => 'fc_field_filter ' . ($isDate ? 'fc_iscalendar' : '') . '', 'placeholder' => $_inner_lb); } else { $attribs_str = ""; $value1 = $display_filter_as == 8 ? @$value[1] : $value; $value2 = @$value[2]; if ($isSlider && $slider_display_config == 1) { $start = $min = 0; $end = $max = -1; $step = 1; $step_values = array(0 => "''"); $step_labels = array(0 => JText::_('FLEXI_ANY')); $i = 1; foreach ($results as $result) { if (!strlen($result->value)) { continue; } $step_values[] = "'" . $result->value . "'"; $step_labels[] = $result->text; if ($result->value == $value1) { $start = $i; } if ($result->value == $value2) { $end = $i; } $i++; } // Set max according considering the skipped empty values $max = $i - 1 + ($display_filter_as == 7 ? 0 : 1); //count($results)-1; if ($end == -1) { $end = $max; } // Set end to last element if it was not set if ($display_filter_as == 8) { $step_values[] = "''"; $step_labels[] = JText::_('FLEXI_ANY'); } $step_range = "step: 1,\n\t\t\t\t\t\t\trange: {'min': " . $min . ", 'max': " . $max . "},"; } else { if ($isSlider) { $custom_range = $filter->parameters->get('slider_custom_range' . $_s, "'min': '', '25%': 500, '50%': 2000, '75%': 10000, 'max': ''"); $custom_labels = preg_split("/\\s*##\\s*/u", $filter->parameters->get('slider_custom_labels' . $_s, 'label_any ## label_500 ## label_2000 ## label_10000 ## label_any')); if ($filter->parameters->get('slider_custom_labels_jtext' . $_s, 0)) { foreach ($custom_labels as $i => $custom_label) { $custom_labels[$i] = JText::_($custom_label); } // Language filter the custom labels } $custom_vals = json_decode('{' . str_replace("'", '"', $custom_range) . '}', true); if (!$custom_vals) { $filter->html = ' <div class="alert"> Bad syntax for custom range for slider filter: ' . $filter->label . "\n\t\t\t\t\t\t\t\tEXAMPLE: <br/> 'min': 0, '25%': 500, '50%': 2000, '75%': 10000, 'max': 50000" . ' </div>'; break; } if (!strlen($custom_vals['min'])) { $custom_vals['min'] = "''"; } if (!strlen($custom_vals['max'])) { $custom_vals['max'] = "''"; } $start = 0; $end = count($custom_vals) - 1; $step_values = $custom_vals; $step_labels =& $custom_labels; $i = 0; $set_start = strlen($value1) > 0; $set_end = strlen($value1) > 0; foreach ($custom_vals as $n => $custom_val) { if ($set_start && $custom_val == $value1) { $start = $i; } if ($set_end && $custom_val == $value2) { $end = $i; } $custom_vals[$n] = $i++; } $step_range = ' snap: true, range: ' . json_encode($custom_vals) . ', '; } } flexicontent_html::loadFramework('nouislider'); $left_no = $display_filter_as == 7 ? '' : '1'; $rght_no = '2'; // sometimes unused $js = "\n\t\t\t\t\tjQuery(document).ready(function(){\n\t\t\t\t\t\tvar slider = document.getElementById('" . $filter_ffid . "_nouislider');\n\t\t\t\t\t\t\n\t\t\t\t\t\tvar input1 = document.getElementById('" . $filter_ffid . $left_no . "');\n\t\t\t\t\t\tvar input2 = document.getElementById('" . $filter_ffid . $rght_no . "');\n\t\t\t\t\t\tvar isSingle = " . ($display_filter_as == 7 ? '1' : '0') . ";\n\t\t\t\t\t\t\n\t\t\t\t\t\tvar step_values = [" . implode(', ', $step_values) . "];\n\t\t\t\t\t\tvar step_labels = [\"" . implode('", "', array_map('addslashes', $step_labels)) . "\"];\n\t\t\t\t\t\t\n\t\t\t\t\t\tnoUiSlider.create(slider, {" . ($display_filter_as == 7 ? "\n\t\t\t\t\t\t\t\tstart: " . $start . ",\n\t\t\t\t\t\t\t\tconnect: false,\n\t\t\t\t\t\t\t" : "\n\t\t\t\t\t\t\t\tstart: [" . $start . ", " . $end . "],\n\t\t\t\t\t\t\t\tconnect: true,\n\t\t\t\t\t\t\t") . "\n\t\t\t\t\t\t\t\t" . $step_range . "\n\t\t\t\t\t\t});\n\t\t\t\t\t\t\n\t\t\t\t\t\tvar tipHandles = slider.getElementsByClassName('noUi-handle'),\n\t\t\t\t\t\ttooltips = [];\n\t\t\t\t\t\t\n\t\t\t\t\t\t// Add divs to the slider handles.\n\t\t\t\t\t\tfor ( var i = 0; i < tipHandles.length; i++ ){\n\t\t\t\t\t\t\ttooltips[i] = document.createElement('span');\n\t\t\t\t\t\t\ttipHandles[i].appendChild(tooltips[i]);\n\t\t\t\t\t\t\t\n\t\t\t\t\t\t\ttooltips[i].className += 'fc-sliderTooltip'; // Add a class for styling\n\t\t\t\t\t\t\ttooltips[i].innerHTML = '<span></span>'; // Add additional markup\n\t\t\t\t\t\t\ttooltips[i] = tooltips[i].getElementsByTagName('span')[0]; // Replace the tooltip reference with the span we just added\n\t\t\t\t\t\t}\n\t\t\t\t\t\t\n\t\t\t\t\t\t// When the slider changes, display the value in the tooltips and set it into the input form elements\n\t\t\t\t\t\tslider.noUiSlider.on('update', function( values, handle ) {\n\t\t\t\t\t\t\tvar value = parseInt(values[handle]);\n\t\t\t\t\t\t\tvar i = value;\n\t\t\t\t\t\t\t\n\t\t\t\t\t\t\tif ( handle ) {\n\t\t\t\t\t\t\t\tinput2.value = typeof step_values[value] !== 'undefined' ? step_values[value] : value;\n\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\tinput1.value = typeof step_values[value] !== 'undefined' ? step_values[value] : value;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tvar tooltip_text = typeof step_labels[value] !== 'undefined' ? step_labels[value] : value;\n\t\t\t\t\t\t\tvar max_len = 36;\n\t\t\t\t\t\t\ttooltips[handle].innerHTML = tooltip_text.length > max_len+4 ? tooltip_text.substring(0, max_len)+' ...' : tooltip_text;\n\t\t\t\t\t\t\tvar left = jQuery(tooltips[handle]).closest('.noUi-origin').position().left;\n\t\t\t\t\t\t\tvar width = jQuery(tooltips[handle]).closest('.noUi-base').width();\n\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t//window.console.log ('handle: ' + handle + ', left : ' + left + ', width : ' + width);\n\t\t\t\t\t\t\tif (isSingle) {\n\t\t\t\t\t\t\t\tleft<(50/100)*width ?\n\t\t\t\t\t\t\t\t\tjQuery(tooltips[handle]).parent().removeClass('fc-left').addClass('fc-right') :\n\t\t\t\t\t\t\t\t\tjQuery(tooltips[handle]).parent().removeClass('fc-right').addClass('fc-left');\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\telse if (handle) {\n\t\t\t\t\t\t\t\tleft<=(76/100)*width ?\n\t\t\t\t\t\t\t\t\tjQuery(tooltips[handle]).parent().removeClass('fc-left').addClass('fc-right') :\n\t\t\t\t\t\t\t\t\tjQuery(tooltips[handle]).parent().removeClass('fc-right').addClass('fc-left');\n\t\t\t\t\t\t\t\tleft<=(49/100)*width ?\n\t\t\t\t\t\t\t\t\tjQuery(tooltips[handle]).parent().addClass('fc-bottom') :\n\t\t\t\t\t\t\t\t\tjQuery(tooltips[handle]).parent().removeClass('fc-bottom');\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\telse {\n\t\t\t\t\t\t\t\tleft>=(24/100)*width ?\n\t\t\t\t\t\t\t\t\tjQuery(tooltips[handle]).parent().removeClass('fc-right').addClass('fc-left') :\n\t\t\t\t\t\t\t\t\tjQuery(tooltips[handle]).parent().removeClass('fc-left').addClass('fc-right');\n\t\t\t\t\t\t\t\tleft>=(51/100)*width ?\n\t\t\t\t\t\t\t\t\tjQuery(tooltips[handle]).parent().addClass('fc-bottom') :\n\t\t\t\t\t\t\t\t\tjQuery(tooltips[handle]).parent().removeClass('fc-bottom');\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t});\n\t\t\t\t\t\t\n\t\t\t\t\t\t// Handle form autosubmit\n\t\t\t\t\t\tslider.noUiSlider.on('change', function() {\n\t\t\t\t\t\t\tvar slider = jQuery('#" . $filter_ffid . "_nouislider');\n\t\t\t\t\t\t\tvar jform = slider.closest('form');\n\t\t\t\t\t\t\tvar form = jform.get(0);\n\t\t\t\t\t\t\tadminFormPrepare(form, parseInt(jform.attr('data-fc-autosubmit')));\n\t\t\t\t\t\t});\n\t\t\t\t\t\t\n\t\t\t\t\t\tinput1.addEventListener('change', function(){\n\t\t\t\t\t\t\tvar value = 0; // default is first value = empty\n\t\t\t\t\t\t\tfor(var i=1; i<step_values.length-1; i++) {\n\t\t\t\t\t\t\t\tif (step_values[i] == this.value) { value=i; break; }\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tslider.noUiSlider.set([value, null]);\n\t\t\t\t\t\t});\n\t\t\t\t\t\t" . ($display_filter_as == 8 ? "\n\t\t\t\t\t\tinput2.addEventListener('change', function(){\n\t\t\t\t\t\t\tvar value = step_values.length-1; // default is last value = empty\n\t\t\t\t\t\t\tfor(var i=1; i<step_values.length-1; i++) {\n\t\t\t\t\t\t\t\tif (step_values[i] == this.value) { value=i; break; }\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tslider.noUiSlider.set([null, value]);\n\t\t\t\t\t\t});\n\t\t\t\t\t\t" : "") . "\n\t\t\t\t\t});\n\t\t\t\t"; JFactory::getDocument()->addScriptDeclaration($js); //JFactory::getDocument()->addStyleDeclaration(""); } if ($display_filter_as == 1 || $display_filter_as == 7) { if ($isDate && !$isSlider) { $filter->html .= ' <span class="fc_filter_element"> ' . FlexicontentFields::createCalendarField($value, $allowtime = 0, $filter_ffname, $filter_ffid, $attribs_arr) . ' </span>'; } else { $filter->html .= ($isSlider ? '<div id="' . $filter_ffid . '_nouislider" class="fcfilter_with_nouislider"></div><div class="fc_slider_input_box">' : '') . ' <span class="fc_filter_element"> <input id="' . $filter_ffid . '" name="' . $filter_ffname . '" ' . $attribs_str . ' type="text" size="' . $size . '" value="' . @$value . '" /> </span> ' . ($isSlider ? '</div>' : ''); } } else { if ($isDate && !$isSlider) { $filter->html .= ' <span class="fc_filter_element"> ' . FlexicontentFields::createCalendarField(@$value[1], $allowtime = 0, $filter_ffname . '[1]', $filter_ffid . '1', $attribs_arr) . ' </span> <span class="fc_range"></span> <span class="fc_filter_element"> ' . FlexicontentFields::createCalendarField(@$value[2], $allowtime = 0, $filter_ffname . '[2]', $filter_ffid . '2', $attribs_arr) . ' </span>'; } else { $size = (int) ($size / 2); $filter->html .= ($isSlider ? '<div id="' . $filter_ffid . '_nouislider" class="fcfilter_with_nouislider"></div><div class="fc_slider_input_box">' : '') . ' <span class="fc_filter_element"> <input name="' . $filter_ffname . '[1]" ' . $attribs_str . ' id="' . $filter_ffid . '1" type="text" size="' . $size . '" value="' . @$value[1] . '" /> </span> <span class="fc_range"></span> <span class="fc_filter_element"> <input name="' . $filter_ffname . '[2]" ' . $attribs_str . ' id="' . $filter_ffid . '2" type="text" size="' . $size . '" value="' . @$value[2] . '" /> </span> ' . ($isSlider ? '</div>' : ''); } } break; case 4: case 5: // 4: radio (single value selectable), 5: checkbox (multiple values selectable) $lf_min = 10; // add parameter for this ? $add_lf = count($results) >= $lf_min; if ($add_lf) { flexicontent_html::loadFramework('mCSB'); } $clear_values = 0; $value_style = $clear_values ? 'float:left; clear:both;' : ''; $i = 0; $checked = $display_filter_as == 5 ? !count($value) || !strlen(reset($value)) : !strlen($value); $checked_attr = $checked ? 'checked="checked"' : ''; $checked_class = $checked ? 'fc_highlight' : ''; $checked_class_li = $checked ? ' fc_checkradio_checked' : ''; $filter->html .= '<div class="fc_checkradio_group_wrapper fc_add_scroller' . ($add_lf ? ' fc_list_filter_wrapper' : '') . '">'; $filter->html .= '<ul class="fc_field_filter fc_checkradio_group' . ($add_lf ? ' fc_list_filter' : '') . '">'; $filter->html .= '<li class="fc_checkradio_option fc_checkradio_special' . $checked_class_li . '" style="' . $value_style . '">'; $filter->html .= $label_filter == 2 ? ' <span class="fc_filter_label_inline">' . $filter->label . '</span> ' : ''; if ($display_filter_as == 4) { $filter->html .= ' <input href="javascript:;" onchange="fc_toggleClassGrp(this, \'fc_highlight\', 1);" '; $filter->html .= ' id="' . $filter_ffid . $i . '" type="radio" name="' . $filter_ffname . '" '; $filter->html .= ' value="" ' . $checked_attr . ' class="fc_checkradio" />'; } else { $filter->html .= ' <input href="javascript:;" onchange="fc_toggleClass(this, \'fc_highlight\', 1);" '; $filter->html .= ' id="' . $filter_ffid . $i . '" type="checkbox" name="' . $filter_ffname . '[' . $i . ']" '; $filter->html .= ' value="" ' . $checked_attr . ' class="fc_checkradio" />'; } $tooltip_class = FLEXI_J30GE ? ' hasTooltip' : ' hasTip'; $tooltip_title = flexicontent_html::getToolTip('FLEXI_REMOVE_ALL', '', $translate = 1, $escape = 1); $filter->html .= '<label class="' . $checked_class . $tooltip_class . '" for="' . $filter_ffid . $i . '" ' . ' title="' . $tooltip_title . '" ' . ($checked ? ' style="display:none!important;" ' : ' style="background:none!important; padding-left:0px!important;" ') . '>' . '<span class="fc_delall_filters"></span>'; $filter->html .= '</label> ' . ($combine_tip ? ' <span class="fc_filter_tip_inline badge badge-info">' . JText::_(!$require_all_param ? 'FLEXI_ANY_OF' : 'FLEXI_ALL_OF') . '</span> ' : '') . ' </li>'; $i++; foreach ($results as $result) { if (!strlen($result->value)) { continue; } $checked = $display_filter_as == 5 ? in_array($result->value, $value) : $result->value == $value; $checked_attr = $checked ? ' checked=checked ' : ''; $disable_attr = $faceted_filter == 2 && !$result->found ? ' disabled=disabled ' : ''; $checked_class = $checked ? 'fc_highlight' : ''; $checked_class .= $faceted_filter == 2 && !$result->found ? ' fcdisabled ' : ''; $checked_class_li = $checked ? ' fc_checkradio_checked' : ''; $filter->html .= '<li class="fc_checkradio_option' . $checked_class_li . '" style="' . $value_style . '">'; // *** PLACE image before label (and e.g. (default) above the label) if ($filter_vals_display == 2) { $filter->html .= "<span class='fc_filter_val_img'><img onclick=\"jQuery(this).closest('li').find('input').click();\" src='" . $result->image_url . "' /></span>"; } if ($display_filter_as == 4) { $filter->html .= ' <input href="javascript:;" onchange="fc_toggleClassGrp(this, \'fc_highlight\');" '; $filter->html .= ' id="' . $filter_ffid . $i . '" type="radio" name="' . $filter_ffname . '" '; $filter->html .= ' value="' . $result->value . '" ' . $checked_attr . $disable_attr . ' class="fc_checkradio" />'; } else { $filter->html .= ' <input href="javascript:;" onchange="fc_toggleClass(this, \'fc_highlight\');" '; $filter->html .= ' id="' . $filter_ffid . $i . '" type="checkbox" name="' . $filter_ffname . '[' . $i . ']" '; $filter->html .= ' value="' . $result->value . '" ' . $checked_attr . $disable_attr . ' class="fc_checkradio" />'; } $filter->html .= '<label class="fc_filter_val fc_cleared ' . $checked_class . '" for="' . $filter_ffid . $i . '">'; if ($filter_vals_display == 0 || $filter_vals_display == 2) { $filter->html .= "<span class='fc_filter_val_lbl'>" . $result->text . "</span>"; } else { if ($add_usage_counters && $result->found) { $filter->html .= "<span class='fc_filter_val_lbl'>(" . $result->found . ")</span>"; } } $filter->html .= '</label>'; // *** PLACE image after label (and e.g. (default) next to the label) if ($filter_vals_display == 1) { $filter->html .= "<span class='fc_filter_val_img'>" . "<img onclick=\"jQuery(this).closest('li').find('input').click();\" src='" . $result->image_url . "' />" . "</span>"; } $filter->html .= '</li>'; $i++; } $filter->html .= '</ul>'; $filter->html .= '</div>'; break; } if ($print_logging_info) { $current_filter_creation = round(1000000 * 10 * (microtime(true) - $start_microtime)) / 10; $flt_active_count = isset($filters_where) ? count($filters_where) : 0; $faceted_str = array(0 => 'non-FACETED ', 1 => 'FACETED: current view (cacheable) ', 2 => 'FACETED: current filters:' . " (" . $flt_active_count . ' active) '); $fc_run_times['create_filter'][$filter->name] = $current_filter_creation + (!empty($fc_run_times['create_filter'][$filter->name]) ? $fc_run_times['create_filter'][$filter->name] : 0); if (isset($fc_run_times['_create_filter_init'])) { $fc_run_times['create_filter'][$filter->name] -= $fc_run_times['_create_filter_init']; $fc_run_times['create_filter_init'] = $fc_run_times['_create_filter_init'] + (!empty($fc_run_times['create_filter_init']) ? $fc_run_times['create_filter_init'] : 0); unset($fc_run_times['_create_filter_init']); } $fc_run_times['create_filter_type'][$filter->name] = $faceted_str[$faceted_filter]; } //$filter_display_typestr = array(0=>'Single Select', 1=>'Single Text', 2=>'Range Dual Select', 3=>'Range Dual Text', 4=>'Radio Buttons', 5=>'Checkbox Buttons'); //echo "FIELD name: <b>". $filter->name ."</b> Field Type: <b>". $filter->field_type."</b> Filter Type: <b>". $filter_display_typestr[$display_filter_as] ."</b> (".$display_filter_as.") ".sprintf(" %.2f s",$current_filter_creation/1000000)." <br/>"; }
function onDisplayFieldValue(&$field, $item, $values = null, $prop = 'display') { // Get isMobile / isTablet Flags static $isMobile = null; static $isTablet = null; static $useMobile = null; if ($useMobile === null) { $cparams = JComponentHelper::getParams('com_flexicontent'); $force_desktop_layout = $cparams->get('force_desktop_layout', 0); //$start_microtime = microtime(true); $mobileDetector = flexicontent_html::getMobileDetector(); $isMobile = $mobileDetector->isMobile(); $isTablet = $mobileDetector->isTablet(); $useMobile = $force_desktop_layout ? $isMobile && !$isTablet : $isMobile; //$time_passed = round(1000000 * 10 * (microtime(true) - $start_microtime)) / 10; //printf('<br/>-- [Detect Mobile: %.3f s] ', $time_passed/1000000); } // 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); static $multiboxadded = false; static $fancyboxadded = false; static $gallerifficadded = false; static $elastislideadded = false; static $photoswipeadded = false; $values = $values ? $values : $field->value; $view = JRequest::getVar('flexi_callview', JRequest::getVar('view', FLEXI_ITEMVIEW)); $multiple = $field->parameters->get('allow_multiple', 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; } } $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); // 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 : $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 . '_' : ''; $usealt = $field->parameters->get('use_alt', 1); $alt_usage = $field->parameters->get('alt_usage', 0); $default_alt = $alt_usage == 2 ? $field->parameters->get('default_alt', '') : ''; $usetitle = $field->parameters->get('use_title', 1); $title_usage = $field->parameters->get('title_usage', 0); $default_title = $title_usage == 2 ? JText::_($field->parameters->get('default_title', '')) : ''; $usedesc = $field->parameters->get('use_desc', 1); $desc_usage = $field->parameters->get('desc_usage', 0); $default_desc = $desc_usage == 2 ? $field->parameters->get('default_desc', '') : ''; // Separators / enclosing characters $remove_space = $field->parameters->get('remove_space', 0); $pretext = FlexicontentFields::replaceFieldValue($field, $item, $field->parameters->get('pretext', ''), 'pretext'); $posttext = FlexicontentFields::replaceFieldValue($field, $item, $field->parameters->get('posttext', ''), 'posttext'); $separatorf = $field->parameters->get('separatorf', 0); $opentag = FlexicontentFields::replaceFieldValue($field, $item, $field->parameters->get('opentag', ''), 'opentag'); $closetag = FlexicontentFields::replaceFieldValue($field, $item, $field->parameters->get('closetag', ''), 'closetag'); if ($pretext) { $pretext = $remove_space ? $pretext : $pretext . ' '; } if ($posttext) { $posttext = $remove_space ? $posttext : ' ' . $posttext; } switch ($separatorf) { case 0: $separatorf = ' '; break; case 1: $separatorf = '<br />'; break; case 2: $separatorf = ' | '; break; case 3: $separatorf = ', '; break; case 4: $separatorf = $closetag . $opentag; break; case 5: $separatorf = ''; break; default: $separatorf = ' '; break; } // intro-full mode get their values from item's parameters if ($image_source == -1) { $values = array(); $_image_name = $view == 'item' ? 'full' : 'intro'; $_image_path = $item->images->get('image_' . $_image_name, ''); if ($_image_path) { $image_by_params = array(); // field attributes (mode-specific) $image_by_params['image_size'] = $_image_name; $image_by_params['image_path'] = $_image_path; // field attributes (value) $image_by_params['originalname'] = basename($_image_path); $image_by_params['alt'] = $item->images->get($_image_name . '_alt', ''); $image_by_params['title'] = $item->images->get($_image_name . '_alt', ''); $image_by_params['desc'] = $item->images->get($_image_name . '_caption', ''); $image_by_params['urllink'] = ''; $values = array(serialize($image_by_params)); } } // Check for deleted image files or image files that cannot be thumbnailed, // rebuilding thumbnails as needed, and then assigning checked values to a new array $usable_values = array(); if ($values) { foreach ($values as $index => $value) { $value = unserialize($value); if (plgFlexicontent_fieldsImage::rebuildThumbs($field, $value, $item)) { $usable_values[] = $values[$index]; } } } $values =& $usable_values; // Allow for thumbnailing of the default image $field->using_default_value = false; if (!count($values)) { // Create default image to be used if (a) no image assigned OR (b) images assigned have been deleted $default_image = $field->parameters->get('default_image', ''); if ($default_image) { $default_image_val = array(); // field attributes (default value specific) $default_image_val['default_image'] = $default_image; // holds complete relative path and indicates that it is default image for field // field attributes (value) $default_image_val['originalname'] = basename($default_image); $default_image_val['alt'] = $default_alt; $default_image_val['title'] = $default_title; $default_image_val['desc'] = $default_desc; $default_image_val['urllink'] = ''; // Create thumbnails for default image if (plgFlexicontent_fieldsImage::rebuildThumbs($field, $default_image_val, $item)) { $values = array(serialize($default_image_val)); } // Also default image can (possibly) be used across multiple fields, so set flag to add field id to filenames of thumbnails $multiple_image_usages = true; $extra_prefix = 'fld' . $field->id . '_'; $field->using_default_value = true; } } // Check for no values, and return empty display, otherwise assign (possibly) altered value array to back to the field if (!count($values)) { $field->{$prop} = ''; return; } $field->value = $values; $app = JFactory::getApplication(); $document = JFactory::getDocument(); $option = JRequest::getVar('option'); jimport('joomla.filesystem'); $isFeedView = JRequest::getCmd('format', null) == 'feed'; $isItemsManager = $app->isAdmin() && $view == 'items' && $option == 'com_flexicontent'; $isSite = $app->isSite(); // some parameter shortcuts $uselegend = $field->parameters->get('uselegend', 1); $usepopup = $field->parameters->get('usepopup', 1); $popuptype = $field->parameters->get('popuptype', 1); $popuptype_mobile = $field->parameters->get('popuptype_mobile', $popuptype); // this defaults to desktop when empty $popuptype = $useMobile ? $popuptype_mobile : $popuptype; $grouptype = $field->parameters->get('grouptype', 1); $grouptype = $multiple ? 0 : $grouptype; // Field in gallery mode: Force grouping of images per field (current item) // Needed by some js galleries $thumb_w_s = $field->parameters->get('w_s', 120); $thumb_h_s = $field->parameters->get('h_s', 90); // Check and disable 'uselegend' $legendinview = $field->parameters->get('legendinview', array(FLEXI_ITEMVIEW, 'category')); $legendinview = FLEXIUtilities::paramToArray($legendinview); if ($view == FLEXI_ITEMVIEW && !in_array(FLEXI_ITEMVIEW, $legendinview)) { $uselegend = 0; } if ($view == 'category' && !in_array('category', $legendinview)) { $uselegend = 0; } if ($isItemsManager && !in_array('backend', $legendinview)) { $uselegend = 0; } // Check and disable 'usepopup' $popupinview = $field->parameters->get('popupinview', array(FLEXI_ITEMVIEW, 'category', 'backend')); $popupinview = FLEXIUtilities::paramToArray($popupinview); if ($view == FLEXI_ITEMVIEW && !in_array(FLEXI_ITEMVIEW, $popupinview)) { $usepopup = 0; } if ($view == 'category' && !in_array('category', $popupinview)) { $usepopup = 0; } if ($view == 'module' && !in_array('module', $popupinview)) { $usepopup = 0; } if ($isItemsManager && !in_array('backend', $popupinview)) { $usepopup = 0; } // FORCE multibox popup in backend ... if ($isItemsManager) { $popuptype = 1; } // remaining parameters shortcuts $showtitle = $field->parameters->get('showtitle', 0); $showdesc = $field->parameters->get('showdesc', 0); $linkto_url = $field->parameters->get('linkto_url', 0); $url_target = $field->parameters->get('url_target', '_self'); $isLinkToPopup = $linkto_url && $url_target == 'multibox'; $useogp = $field->parameters->get('useogp', 0); $ogpinview = $field->parameters->get('ogpinview', array()); $ogpinview = FLEXIUtilities::paramToArray($ogpinview); $ogpthumbsize = $field->parameters->get('ogpthumbsize', 2); // load the tooltip library if redquired if ($uselegend) { JHTML::_('behavior.tooltip'); } // MultiBox maybe added in extra cases besides popup // (a) in Item manager, (b) When linking to URL in popup target $view_allows_mb = $isItemsManager || $isSite && !$isFeedView; $config_needs_mb = $isLinkToPopup || $usepopup && $popuptype == 1; if ($view_allows_mb && $config_needs_mb) { if (!$multiboxadded) { //echo $field->name.": multiboxadded"; FLEXI_J30GE ? JHtml::_('behavior.framework', true) : JHTML::_('behavior.mootools'); // Multibox integration use different version for FC v2x if (FLEXI_J16GE) { // Include MultiBox CSS files $document->addStyleSheet(JURI::root(true) . '/components/com_flexicontent/librairies/multibox/Styles/multiBox.css'); // NEW ie6 hack if (substr($_SERVER['HTTP_USER_AGENT'], 0, 34) == "Mozilla/4.0 (compatible; MSIE 6.0;") { $document->addStyleSheet(JURI::root(true) . '/components/com_flexicontent/librairies/multibox/Styles/multiBoxIE6.css'); } // This is the new code for new multibox version, old multibox hack is the following lines // Include MultiBox Javascript files $document->addScript(JURI::root(true) . '/components/com_flexicontent/librairies/multibox/Scripts/overlay.js'); $document->addScript(JURI::root(true) . '/components/com_flexicontent/librairies/multibox/Scripts/multiBox.js'); // Add js code for creating a multibox instance $extra_options = ''; if ($isItemsManager) { $extra_options .= '' . ',showNumbers: false' . ',showControls: false'; } $box = "\n\t\t\t\t\t\twindow.addEvent('domready', function(){\n\t\t\t\t\t\t\t//call multiBox\n\t\t\t\t\t\t\tvar initMultiBox = new multiBox({\n\t\t\t\t\t\t\t\tmbClass: '.mb',//class you need to add links that you want to trigger multiBox with (remember and update CSS files)\n\t\t\t\t\t\t\t\tcontainer: \$(document.body),//where to inject multiBox\n\t\t\t\t\t\t\t\tdescClassName: 'multiBoxDesc',//the class name of the description divs\n\t\t\t\t\t\t\t\tpath: './Files/',//path to mp3 and flv players\n\t\t\t\t\t\t\t\tuseOverlay: true,//use a semi-transparent background. default: false;\n\t\t\t\t\t\t\t\tmaxSize: {w:4000, h:3000},//max dimensions (width,height) - set to null to disable resizing\n\t\t\t\t\t\t\t\taddDownload: false,//do you want the files to be downloadable?\n\t\t\t\t\t\t\t\tpathToDownloadScript: './Scripts/forceDownload.asp',//if above is true, specify path to download script (classicASP and ASP.NET versions included)\n\t\t\t\t\t\t\t\taddRollover: true,//add rollover fade to each multibox link\n\t\t\t\t\t\t\t\taddOverlayIcon: true,//adds overlay icons to images within multibox links\n\t\t\t\t\t\t\t\taddChain: true,//cycle through all images fading them out then in\n\t\t\t\t\t\t\t\trecalcTop: true,//subtract the height of controls panel from top position\n\t\t\t\t\t\t\t\taddTips: true,//adds MooTools built in 'Tips' class to each element (see: http://mootools.net/docs/Plugins/Tips)\n\t\t\t\t\t\t\t\tautoOpen: 0//to auto open a multiBox element on page load change to (1, 2, or 3 etc)\n\t\t\t\t\t\t\t\t" . $extra_options . "\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\t});\n\t\t\t\t\t"; $document->addScriptDeclaration($box); } else { // Include MultiBox CSS files $document->addStyleSheet(JURI::root(true) . '/components/com_flexicontent/librairies/multibox/multibox.css'); // OLD ie6 hack $csshack = ' <!--[if lte IE 6]> <style type="text/css"> .MultiBoxClose, .MultiBoxPrevious, .MultiBoxNext, .MultiBoxNextDisabled, .MultiBoxPreviousDisabled { behavior: url(' . 'components/com_flexicontent/librairies/multibox/iepngfix.htc); } </style> <![endif]--> '; $document->addCustomTag($csshack); // Include MultiBox Javascript files $document->addScript(JURI::root(true) . '/components/com_flexicontent/librairies/multibox/js/overlay.js'); $document->addScript(JURI::root(true) . '/components/com_flexicontent/librairies/multibox/js/multibox.js'); // Add js code for creating a multibox instance $extra_options = $isItemsManager ? ', showNumbers: false, showControls: false' : ''; $box = "\n\t\t\t\t\t\tvar box = {};\n\t\t\t\t\t\twindow.addEvent('domready', function(){\n\t\t\t\t\t\t\tbox = new MultiBox('mb', {descClassName: 'multiBoxDesc', useOverlay: true" . $extra_options . " });\n\t\t\t\t\t\t});\n\t\t\t\t\t"; $document->addScriptDeclaration($box); } $multiboxadded = true; } } // Regardless if above has added multibox , we will add a different JS gallery if so configured because it maybe needed if (!$isSite || $isFeedView) { // Is backend OR it is a feed view, do not add any JS library } else { if ($usepopup) { switch ($popuptype) { // Add Fancybox image popup case 4: if (!$fancyboxadded) { $fancyboxadded = true; flexicontent_html::loadFramework('fancybox'); } break; // Add Galleriffic inline slideshow gallery // Add Galleriffic inline slideshow gallery case 5: $inline_gallery = 1; if (!$gallerifficadded) { flexicontent_html::loadFramework('galleriffic'); $gallerifficadded = true; } break; // Add Elastislide inline carousel gallery (Responsive image gallery with togglable thumbnail-strip, plus previewer and description) // Add Elastislide inline carousel gallery (Responsive image gallery with togglable thumbnail-strip, plus previewer and description) case 7: if (!$elastislideadded) { flexicontent_html::loadFramework('elastislide'); $elastislideadded = true; } $uid = 'es_' . $field->name . "_fcitem" . $item->id; $js = file_get_contents(JPATH_SITE . DS . 'components' . DS . 'com_flexicontent' . DS . 'librairies' . DS . 'elastislide' . DS . 'js' . DS . 'gallery_tmpl.js'); $js = str_replace('unique_gal_id', $uid, $js); $js = str_replace('__thumb_width__', $field->parameters->get('w_s', 120), $js); $document->addScriptDeclaration($js); $document->addCustomTag(' <script id="img-wrapper-tmpl_' . $uid . '" type="text/x-jquery-tmpl"> <div class="rg-image-wrapper"> {{if itemsCount > 1}} <div class="rg-image-nav"> <a href="#" class="rg-image-nav-prev">' . JText::_('FLEXI_PREVIOUS') . '</a> <a href="#" class="rg-image-nav-next">' . JText::_('FLEXI_NEXT') . '</a> </div> {{/if}} <div class="rg-image"></div> <div class="rg-loading"></div> <div class="rg-caption-wrapper"> <div class="rg-caption" style="display:none;"> <p></p> </div> </div> </div> </script> '); break; // Add PhotoSwipe popup carousel gallery // Add PhotoSwipe popup carousel gallery case 8: if (!$photoswipeadded) { flexicontent_html::loadFramework('photoswipe'); $photoswipeadded = true; } break; } } } // Extra thumbnails sub-folder for various if ($field->using_default_value) { $extra_folder = ''; // default value } else { if ($image_source == -1) { $extra_folder = 'intro_full'; // intro-full images mode } else { if ($image_source > 0) { $extra_folder = 'item_' . $u_item_id . '_field_' . $field->id; // folder-mode 1 if ($image_source > 1) { } // TODO } else { $extra_folder = ''; // db-mode } } } // Create thumbs/image Folder and URL paths $thumb_folder = JPATH_SITE . DS . JPath::clean($dir . ($extra_folder ? DS . $extra_folder : '')); $thumb_urlpath = $dir_url . ($extra_folder ? '/' . $extra_folder : ''); if ($field->using_default_value) { // default image of this field, these are relative paths up to site root $orig_urlpath = str_replace('\\', '/', dirname($default_image_val['default_image'])); } else { if ($image_source == -1) { // intro-full image values, these are relative paths up to the site root, must be calculated later !! $orig_urlpath = str_replace('\\', '/', dirname($image_by_params['image_path'])); } else { if ($image_source > 0) { // various folder-mode(s) $orig_urlpath = $thumb_urlpath . '/original'; } else { // db-mode $cparams = JComponentHelper::getParams('com_flexicontent'); $orig_urlpath = str_replace('\\', '/', JPath::clean($cparams->get('file_path', 'components/com_flexicontent/uploads'))); } } } $i = -1; $field->{$prop} = array(); $field->thumbs_src['backend'] = array(); $field->thumbs_src['small'] = array(); $field->thumbs_src['medium'] = array(); $field->thumbs_src['large'] = array(); $field->thumbs_src['original'] = array(); foreach ($values as $val) { // Unserialize value's properties and check for empty original name property $value = unserialize($val); $image_name = trim(@$value['originalname']); if (!strlen($image_name)) { continue; } $i++; // Create thumbnails urls, note thumbnails have already been verified above $wl = $field->parameters->get('w_l', 800); $hl = $field->parameters->get('h_l', 600); $title = @$value['title'] ? $value['title'] : ''; $alt = @$value['alt'] ? $value['alt'] : flexicontent_html::striptagsandcut($item->title, 60); $alt = flexicontent_html::escapeJsText($alt, 's'); $desc = @$value['desc'] ? $value['desc'] : ''; $srcb = $thumb_urlpath . '/b_' . $extra_prefix . $image_name; // backend $srcs = $thumb_urlpath . '/s_' . $extra_prefix . $image_name; // small $srcm = $thumb_urlpath . '/m_' . $extra_prefix . $image_name; // medium $srcl = $thumb_urlpath . '/l_' . $extra_prefix . $image_name; // large $srco = $orig_urlpath . '/' . $image_name; // original image // Create a popup url link $urllink = @$value['urllink'] ? $value['urllink'] : ''; if ($urllink && false === strpos($urllink, '://')) { $urllink = 'http://' . $urllink; } // Create a popup tooltip (legend) $tip = $title . '::' . $desc; $tip = flexicontent_html::escapeJsText($tip, 's'); $legend = $uselegend && (!empty($title) || !empty($desc)) ? ' class="hasTip" title="' . $tip . '"' : ''; // Create a unique id for the link tags, and a class name for image tags $uniqueid = $field->item_id . '_' . $field->id . '_' . $i; $class_img_field = 'fc_field_image'; // Decide thumbnail to use $thumb_size = 0; if ($isItemsManager) { $thumb_size = -1; } else { if ($view == 'category') { $thumb_size = $field->parameters->get('thumbincatview', 1); } else { if ($view == FLEXI_ITEMVIEW) { $thumb_size = $field->parameters->get('thumbinitemview', 2); } } } switch ($thumb_size) { case -1: $src = $srcb; break; case 1: $src = $srcs; break; case 2: $src = $srcm; break; case 3: $src = $srcl; break; // this makes little sense, since both thumbnail and popup image are size 'large' // this makes little sense, since both thumbnail and popup image are size 'large' case 4: $src = $srco; break; default: $src = $srcs; break; } // Create a grouping name switch ($grouptype) { case 0: $group_name = 'fcview_' . $view . '_fcitem_' . $field->item_id . '_fcfield_' . $field->id; break; case 1: $group_name = 'fcview_' . $view . '_fcitem_' . $field->item_id; break; case 2: $group_name = 'fcview_' . $view; break; default: $group_name = ''; break; } // ADD some extra (display) properties that point to all sizes, currently SINGLE IMAGE only if ($i == 0) { $field->{"display_backend_src"} = JURI::root(true) . '/' . $srcb; $field->{"display_small_src"} = JURI::root(true) . '/' . $srcs; $field->{"display_medium_src"} = JURI::root(true) . '/' . $srcm; $field->{"display_large_src"} = JURI::root(true) . '/' . $srcl; $field->{"display_original_src"} = JURI::root(true) . '/' . $srco; } $field->thumbs_src['backend'][] = JURI::root(true) . '/' . $srcb; $field->thumbs_src['small'][] = JURI::root(true) . '/' . $srcs; $field->thumbs_src['medium'][] = JURI::root(true) . '/' . $srcm; $field->thumbs_src['large'][] = JURI::root(true) . '/' . $srcl; $field->thumbs_src['original'][] = JURI::root(true) . '/' . $srco; $field->thumbs_path['backend'][] = JPATH_SITE . DS . $srcb; $field->thumbs_path['small'][] = JPATH_SITE . DS . $srcs; $field->thumbs_path['medium'][] = JPATH_SITE . DS . $srcm; $field->thumbs_path['large'][] = JPATH_SITE . DS . $srcl; $field->thumbs_path['original'][] = JPATH_SITE . DS . $srco; // Suggest image for external use, e.g. for Facebook etc if ($isSite && !$isFeedView && $useogp) { if (in_array($view, $ogpinview)) { switch ($ogpthumbsize) { case 1: $ogp_src = $field->{"display_small_src"}; break; // this maybe problematic, since it maybe too small or not accepted by social website // this maybe problematic, since it maybe too small or not accepted by social website case 2: $ogp_src = $field->{"display_medium_src"}; break; case 3: $ogp_src = $field->{"display_large_src"}; break; case 4: $ogp_src = $field->{"display_original_src"}; break; default: $ogp_src = $field->{"display_medium_src"}; break; } $document->addCustomTag('<link rel="image_src" href="' . $ogp_src . '" />'); $document->addCustomTag('<meta property="og:image" content="' . $ogp_src . '" />'); } } // Check if a custom URL-only (display) variable was requested and return it here, // without rendering the extra image parameters like legend, pop-up, etc if (in_array($prop, array("display_backend_src", "display_small_src", "display_medium_src", "display_large_src", "display_original_src"))) { return $field->{$prop}; } // Create image tags (according to configuration parameters) that will be used for the requested 'display' variable switch ($prop) { case 'display_backend': $img_legend = '<img src="' . JURI::root(true) . '/' . $srcb . '" alt="' . $alt . '"' . $legend . ' class="' . $class_img_field . '" />'; $img_nolegend = '<img src="' . JURI::root(true) . '/' . $srcb . '" alt="' . $alt . '" class="' . $class_img_field . '" />'; break; case 'display_small': $img_legend = '<img src="' . JURI::root(true) . '/' . $srcs . '" alt="' . $alt . '"' . $legend . ' class="' . $class_img_field . '" />'; $img_nolegend = '<img src="' . JURI::root(true) . '/' . $srcs . '" alt="' . $alt . '" class="' . $class_img_field . '" />'; break; case 'display_medium': $img_legend = '<img src="' . JURI::root(true) . '/' . $srcm . '" alt="' . $alt . '"' . $legend . ' class="' . $class_img_field . '" />'; $img_nolegend = '<img src="' . JURI::root(true) . '/' . $srcm . '" alt="' . $alt . '" class="' . $class_img_field . '" />'; break; case 'display_large': $img_legend = '<img src="' . JURI::root(true) . '/' . $srcl . '" alt="' . $alt . '"' . $legend . ' class="' . $class_img_field . '" />'; $img_nolegend = '<img src="' . JURI::root(true) . '/' . $srcl . '" alt="' . $alt . '" class="' . $class_img_field . '" />'; break; case 'display_original': $img_legend = '<img src="' . JURI::root(true) . '/' . $srco . '" alt="' . $alt . '"' . $legend . ' class="' . $class_img_field . '" />'; $img_nolegend = '<img src="' . JURI::root(true) . '/' . $srco . '" alt="' . $alt . '" class="' . $class_img_field . '" />'; break; case 'display': default: $img_legend = '<img src="' . JURI::root(true) . '/' . $src . '" alt="' . $alt . '"' . $legend . ' class="' . $class_img_field . '" />'; $img_nolegend = '<img src="' . JURI::root(true) . '/' . $src . '" alt="' . $alt . '" class="' . $class_img_field . '" />'; break; } // ********************************************* // FINALLY CREATE the field display variable ... // ********************************************* if ($isItemsManager) { // CASE 1: Handle image displayed in backend items manager if ($usepopup) { $field->{$prop} = ' <a href="../' . $srcl . '" id="mb' . $uniqueid . '" class="mb" rel="[images]" > ' . $img_legend . ' </a> <div class="multiBoxDesc mb' . $uniqueid . '">' . ($desc ? $desc : $title) . '</div> '; } else { $field->{$prop} = $img_legend; } return; // Single image always ... } else { if ($linkto_url && $urllink) { // CASE 2: Handle linking to a URL instead of image zooming popup if ($url_target == 'multibox') { // (a) Link to URL that opens inside a popup $field->{$prop}[] = ' <script>document.write(\'<a href="' . $urllink . '" id="mb' . $uniqueid . '" class="mb" rel="width:\'+((MooTools.version>=\'1.2.4\' ? window.getSize().x : window.getSize().size.x)-150)+\',height:\'+((MooTools.version>=\'1.2.4\' ? window.getSize().y : window.getSize().size.y)-150)+\'">\')</script> ' . $img_legend . ' <script>document.write(\'</a>\')</script> <div class="multiBoxDesc mbox_img_url mb' . $uniqueid . '">' . ($desc ? $desc : $title) . '</div> '; } else { // (b) Just link to URL $field->{$prop}[] = ' <a href="' . $urllink . '" target="' . $url_target . '"> ' . $img_legend . ' </a> '; } } else { if ($usepopup) { // CASE 3: Handle image zooming popup // no popup if image is the largest one if ($prop == 'display_large' || $prop == 'display_original') { $field->{$prop}[] = $img_legend; continue; } switch ($popuptype) { case 1: // Multibox image popup $group_str = $group_name ? 'rel="[' . $group_name . ']"' : ''; $field->{$prop}[] = ' <a href="' . $srcl . '" id="mb' . $uniqueid . '" class="mb" ' . $group_str . ' > ' . $img_legend . ' </a> <div class="multiBoxDesc mb' . $uniqueid . '">' . ($desc ? $desc : $title) . '</div> '; break; case 2: // Rokbox image popup $title_attr = flexicontent_html::escapeJsText($desc ? $desc : $title, 's'); $group_str = ''; // no support for image grouping $field->{$prop}[] = ' <a href="' . $srcl . '" rel="rokbox[' . $wl . ' ' . $hl . ']" ' . $group_str . ' title="' . $title_attr . '" data-rokbox data-rokbox-caption="' . $title_attr . '"> ' . $img_nolegend . ' </a> '; break; case 3: // JCE popup image popup $title_attr = flexicontent_html::escapeJsText($desc ? $desc : $title, 's'); $group_str = $group_name ? 'rel="group[' . $group_name . ']"' : ''; $field->{$prop}[] = ' <a href="' . $srcl . '" class="jcepopup" ' . $group_str . ' title="' . $title_attr . '"> ' . $img_nolegend . ' </a> '; break; case 4: // Fancybox image popup $title_attr = flexicontent_html::escapeJsText($desc ? $desc : $title, 's'); $group_str = $group_name ? 'data-fancybox-group="' . $group_name . '"' : ''; $field->{$prop}[] = ' <a href="' . $srcl . '" class="fancybox" ' . $group_str . ' title="' . $title_attr . '"> ' . $img_nolegend . ' </a> '; break; case 5: // Galleriffic inline slideshow gallery $group_str = ''; // image grouping: not needed / not applicatble $field->{$prop}[] = ' <a class="thumb" name="drop" href="' . $srcl . '" style=""> ' . $img_legend . ' </a> <div class="caption"> ' . '<b>' . $title . '</b><br/>' . $desc . ' </div> '; break; case 6: // (Widgetkit) SPOTlight image popup $title_attr = flexicontent_html::escapeJsText($desc ? $desc : $title, 's'); $group_str = $group_name ? 'data-spotlight-group="' . $group_name . '"' : ''; $field->{$prop}[] = ' <a href="' . $srcl . '" data-lightbox="on" data-spotlight="effect:bottom" ' . $group_str . ' title="' . $title_attr . '"> ' . $img_nolegend . ' <div class="overlay"> ' . '<b>' . $title . '</b>: ' . $desc . ' </div> </a> '; break; case 7: // Elastislide inline carousel gallery (Responsive image gallery with togglable thumbnail-strip, plus previewer and description) // *** NEEDS: thumbnail list must be created with large size thubmnails, these will be then thumbnailed by the JS gallery code $title_attr = flexicontent_html::escapeJsText($desc ? $desc : $title, 's'); $img_legend_custom = ' <img src="' . JURI::root(true) . '/' . $src . '" alt ="' . $alt . '"' . $legend . ' class="' . $class_img_field . '" data-large="' . JURI::root(true) . '/' . $srcl . '" data-description="' . $title_attr . '"/> '; $group_str = $group_name ? 'rel="[' . $group_name . ']"' : ''; $field->{$prop}[] = ' <li><a href="javascript:;"> ' . $img_legend_custom . ' </a></li> '; break; case 8: // PhotoSwipe popup carousel gallery $group_str = $group_name ? 'rel="[' . $group_name . ']"' : ''; $field->{$prop}[] = ' <a href="' . $srcl . '" ' . $group_str . ' > ' . $img_legend . ' </a> '; break; default: // Unknown Gallery Type, just add thumbails ... $field->{$prop}[] = $img_legend; break; } } else { // CASE 4: Plain Thumbnail List without any (popup / inline) gallery code $field->{$prop}[] = $img_legend; } } } $n = count($field->{$prop}) - 1; if ($showtitle && $title || $showdesc && $desc) { $field->{$prop}[$n] = '<div class="fc_img_tooltip_data" style="float:left; margin-right:8px;" >' . $field->{$prop}[$i]; } if ($showtitle && $title) { $field->{$prop}[$n] .= '<div class="fc_img_tooltip_title" style="line-height:1em; font-weight:bold;">' . $title . '</div>'; } if ($showdesc && $desc) { $field->{$prop}[$n] .= '<div class="fc_img_tooltip_desc" style="line-height:1em;">' . $desc . '</div>'; } if ($showtitle && $title || $showdesc && $desc) { $field->{$prop}[$n] .= '</div>'; } $field->{$prop}[$n] = $pretext . $field->{$prop}[$i] . $posttext; } // ************************************************************ // Apply separator and open/close tags and handle SPECIAL CASEs: // by add some exta html required by some JS image libraries // ************************************************************ // Check for no values found if (!count($field->{$prop})) { $field->{$prop} = ''; return; } // Galleriffic inline slideshow gallery if ($usepopup && $popuptype == 5) { $field->{$prop} = $opentag . ' <div id="gf_container"> <div id="gallery" class="content"> <div id="gf_controls" class="controls"></div> <div class="slideshow-container"> <div id="gf_loading" class="loader"></div> <div id="gf_slideshow" class="slideshow"></div> </div> <div id="gf_caption" class="caption-container"></div> </div> <div id="gf_thumbs" class="navigation"> <ul class="thumbs noscript"> <li> ' . implode("</li>\n<li>", $field->{$prop}) . ' </li> </ul> </div> <div style="clear: both;"></div> </div> ' . $closetag; } else { if ($usepopup && $popuptype == 7) { //$max_width = $field->parameters->get( 'w_l', 800 ); // this should be size of previewer aka size of large image thumbnail $field->{$prop} = ' <div id="rg-gallery_' . $uid . '" class="rg-gallery" > <div class="rg-thumbs"> <!-- Elastislide Carousel Thumbnail Viewer --> <div class="es-carousel-wrapper"> <div class="es-nav"> <span class="es-nav-prev">' . JText::_('FLEXI_PREVIOUS') . '</span> <span class="es-nav-next">' . JText::_('FLEXI_NEXT') . '</span> </div> <div class="es-carousel"> <ul> ' . implode('', $field->{$prop}) . ' </ul> </div> </div> <!-- End Elastislide Carousel Thumbnail Viewer --> </div><!-- rg-thumbs --> </div><!-- rg-gallery --> '; } else { if ($usepopup && $popuptype == 8) { $field->{$prop} = ' <span class="photoswipe_fccontainer" > ' . implode($separatorf, $field->{$prop}) . ' </span> '; } else { $field->{$prop} = implode($separatorf, $field->{$prop}); } } } // Apply open/close tags $field->{$prop} = $opentag . $field->{$prop} . $closetag; }
function onDisplayFieldValue(&$field, $item, $values = null, $prop = 'display') { // execute the code only if the field type match the plugin type if (!in_array($field->field_type, self::$field_types)) { return; } static $langs = null; if ($langs === null) { $langs = FLEXIUtilities::getLanguages('code'); } static $tooltips_added = false; static $isMobile = null; static $isTablet = null; static $useMobile = null; if ($useMobile === null) { $cparams = JComponentHelper::getParams('com_flexicontent'); $force_desktop_layout = $cparams->get('force_desktop_layout', 0); //$start_microtime = microtime(true); $mobileDetector = flexicontent_html::getMobileDetector(); $isMobile = $mobileDetector->isMobile(); $isTablet = $mobileDetector->isTablet(); //$time_passed = round(1000000 * 10 * (microtime(true) - $start_microtime)) / 10; //printf('<br/>-- [Detect Mobile: %.3f s] ', $time_passed/1000000); } if (!$tooltips_added) { FLEXI_J30GE ? JHtml::_('bootstrap.tooltip') : JHTML::_('behavior.tooltip'); $tooltips_added = true; } $field->label = JText::_($field->label); $values = $values ? $values : $field->value; if (empty($values)) { $field->{$prop} = ''; return; } // Prefix - Suffix - Separator parameters, replacing other field values if found $remove_space = $field->parameters->get('remove_space', 0); $pretext = FlexicontentFields::replaceFieldValue($field, $item, $field->parameters->get('pretext', ''), 'pretext'); $posttext = FlexicontentFields::replaceFieldValue($field, $item, $field->parameters->get('posttext', ''), 'posttext'); $separatorf = $field->parameters->get('separatorf', 1); $opentag = FlexicontentFields::replaceFieldValue($field, $item, $field->parameters->get('opentag', ''), 'opentag'); $closetag = FlexicontentFields::replaceFieldValue($field, $item, $field->parameters->get('closetag', ''), 'closetag'); if ($pretext) { $pretext = $remove_space ? $pretext : $pretext . ' '; } if ($posttext) { $posttext = $remove_space ? $posttext : ' ' . $posttext; } // some parameter shortcuts $useicon = $field->parameters->get('useicon', 1); $lowercase_filename = $field->parameters->get('lowercase_filename', 1); $link_filename = $field->parameters->get('link_filename', 1); $display_filename = $field->parameters->get('display_filename', 1); $display_lang = $field->parameters->get('display_lang', 1); $display_size = $field->parameters->get('display_size', 0); $display_hits = $field->parameters->get('display_hits', 0); $display_descr = $field->parameters->get('display_descr', 1); $add_lang_img = $display_lang == 1 || $display_lang == 3; $add_lang_txt = $display_lang == 2 || $display_lang == 3 || $isMobile; $add_hits_img = $display_hits == 1 || $display_hits == 3; $add_hits_txt = $display_hits == 2 || $display_hits == 3 || $isMobile; $usebutton = $field->parameters->get('usebutton', 1); $buttonsposition = $field->parameters->get('buttonsposition', 1); $use_infoseptxt = $field->parameters->get('use_infoseptxt', 1); $use_actionseptxt = $field->parameters->get('use_actionseptxt', 1); $infoseptxt = $use_infoseptxt ? ' ' . $field->parameters->get('infoseptxt', '') . ' ' : ' '; $actionseptxt = $use_actionseptxt ? ' ' . $field->parameters->get('actionseptxt', '') . ' ' : ' '; $allowdownloads = $field->parameters->get('allowdownloads', 1); $downloadstext = $allowdownloads == 2 ? $field->parameters->get('downloadstext', 'FLEXI_DOWNLOAD') : 'FLEXI_DOWNLOAD'; $downloadstext = JText::_($downloadstext); $downloadsinfo = JText::_('FLEXI_FIELD_FILE_DOWNLOAD_INFO', true); $allowview = $field->parameters->get('allowview', 0); $viewtext = $allowview == 2 ? $field->parameters->get('viewtext', 'FLEXI_FIELD_FILE_VIEW') : 'FLEXI_FIELD_FILE_VIEW'; $viewtext = JText::_($viewtext); $viewinfo = JText::_('FLEXI_FIELD_FILE_VIEW_INFO', true); $allowshare = $field->parameters->get('allowshare', 0); $sharetext = $allowshare == 2 ? $field->parameters->get('sharetext', 'FLEXI_FIELD_FILE_EMAIL_TO_FRIEND') : 'FLEXI_FIELD_FILE_EMAIL_TO_FRIEND'; $sharetext = JText::_($sharetext); $shareinfo = JText::_('FLEXI_FIELD_FILE_EMAIL_TO_FRIEND_INFO', true); $allowaddtocart = $field->parameters->get('use_downloads_manager', 0); $addtocarttext = $allowaddtocart == 2 ? $field->parameters->get('addtocarttext', 'FLEXI_FIELD_FILE_ADD_TO_DOWNLOADS_CART') : 'FLEXI_FIELD_FILE_ADD_TO_DOWNLOADS_CART'; $addtocarttext = JText::_($addtocarttext); $addtocartinfo = JText::_('FLEXI_FIELD_FILE_ADD_TO_DOWNLOADS_CART_INFO', true); $noaccess_display = $field->parameters->get('noaccess_display', 1); $noaccess_url_unlogged = $field->parameters->get('noaccess_url_unlogged', false); $noaccess_url_logged = $field->parameters->get('noaccess_url_logged', false); $noaccess_msg_unlogged = JText::_($field->parameters->get('noaccess_msg_unlogged', '')); $noaccess_msg_logged = JText::_($field->parameters->get('noaccess_msg_logged', '')); $noaccess_addvars = $field->parameters->get('noaccess_addvars', 0); // Select appropriate messages depending if user is logged on $noaccess_url = JFactory::getUser()->guest ? $noaccess_url_unlogged : $noaccess_url_logged; $noaccess_msg = JFactory::getUser()->guest ? $noaccess_msg_unlogged : $noaccess_msg_logged; // VERIFY downloads manager module is installed and enabled static $mod_is_enabled = null; if ($allowaddtocart && $mod_is_enabled === null) { $db = JFactory::getDBO(); $query = "SELECT published FROM #__modules WHERE module = 'mod_flexidownloads' AND published = 1"; $db->setQuery($query); $mod_is_enabled = $db->loadResult(); if (!$mod_is_enabled) { $app = JFactory::getApplication(); $app->enqueueMessage("FILE FIELD: please disable parameter \"Use Downloads Manager Module\", the module is not install or not published", 'message'); } } $allowaddtocart = $allowaddtocart ? $mod_is_enabled : 0; // Downloads manager feature if ($allowshare) { if (file_exists(JPATH_SITE . DS . 'components' . DS . 'com_mailto' . DS . 'helpers' . DS . 'mailto.php')) { $com_mailto_found = true; require_once JPATH_SITE . DS . 'components' . DS . 'com_mailto' . DS . 'helpers' . DS . 'mailto.php'; $status = 'width=700,height=360,menubar=yes,resizable=yes'; } else { $com_mailto_found = false; } } if ($pretext) { $pretext = $remove_space ? $pretext : $pretext . ' '; } if ($posttext) { $posttext = $remove_space ? $posttext : ' ' . $posttext; } // Description as tooltip if ($display_descr == 2) { JHTML::_('behavior.tooltip'); } switch ($separatorf) { case 0: $separatorf = ' '; break; case 1: $separatorf = '<br />'; break; case 2: $separatorf = ' | '; break; case 3: $separatorf = ', '; break; case 4: $separatorf = $closetag . $opentag; break; case 5: $separatorf = ''; break; default: $separatorf = ' '; break; } // initialise property $field->{$prop} = array(); // Get user access level (these are multiple for J2.5) $user = JFactory::getUser(); if (FLEXI_J16GE) { $aid_arr = JAccess::getAuthorisedViewLevels($user->id); } else { $aid = (int) $user->get('aid'); } $n = 0; // Get All file information at once (Data maybe cached already) // TODO (maybe) e.g. contentlists should could call this function ONCE for all file fields, // This may be done by adding a new method to fields to prepare multiple fields with a single call $files_data = $this->getFileData($values, $published = true); //print_r($files_data); exit; // Optimization, do some stuff outside the loop static $hits_icon = null; if ($hits_icon === null && ($display_hits == 1 || $display_hits == 3)) { if ($display_hits == 1) { $_tooltip_title = ''; $_tooltip_content = '%s ' . JText::_('FLEXI_HITS', true); $_attribs = FLEXI_J30GE ? 'class="hasTooltip icon-hits" title="' . JHtml::tooltipText($_tooltip_title, $_tooltip_content, 0, 0) . '"' : 'class="hasTip icon-hits" title="' . $_tooltip_title . '::' . $_tooltip_content . '"'; } else { $_attribs = ' class="icon-hits"'; } $hits_icon = FLEXI_J16GE ? JHTML::image('components/com_flexicontent/assets/images/' . 'user.png', JText::_('FLEXI_HITS'), $_attribs) : JHTML::_('image.site', 'user.png', 'components/com_flexicontent/assets/images/', NULL, NULL, JText::_('FLEXI_HITS'), $_attribs); $hits_icon .= ' '; } $show_filename = $display_filename || $prop == 'namelist'; $public_acclevel = !FLEXI_J16GE ? 0 : 1; foreach ($files_data as $file_id => $file_data) { // Check if it exists and get file size $basePath = $file_data->secure ? COM_FLEXICONTENT_FILEPATH : COM_FLEXICONTENT_MEDIAPATH; $abspath = str_replace(DS, '/', JPath::clean($basePath . DS . $file_data->filename)); if ($display_size) { $path_exists = file_exists($abspath); $file_data->size = $path_exists ? filesize($abspath) : 0; } // ***************************** // Check user access on the file // ***************************** $authorized = true; $is_public = true; if (!empty($file_data->access)) { if (FLEXI_J16GE) { $authorized = in_array($file_data->access, $aid_arr); $is_public = in_array($public_acclevel, $aid_arr); } else { $authorized = $file_data->access <= $aid; $is_public = $file_data->access <= $public_acclevel; } } // If no access and set not to show then continue if (!$authorized && !$noaccess_display) { continue; } // Initialize CSS classes variable $file_classes = !$authorized ? 'fcfile_noauth' : ''; // ***************************** // Prepare displayed information // ***************************** // a. ICON: create it according to filetype $icon = ''; if ($useicon) { $file_data = $this->addIcon($file_data); $_tooltip_title = ''; $_tooltip_content = JText::_('FLEXI_FIELD_FILE_TYPE', true) . ': ' . $file_data->ext; $icon = FLEXI_J30GE ? JHTML::image($file_data->icon, $file_data->ext, 'class="icon-mime hasTooltip" title="' . JHtml::tooltipText($_tooltip_title, $_tooltip_content, 1, 0) . '"') : JHTML::image($file_data->icon, $file_data->ext, 'class="icon-mime hasTip" title="' . $_tooltip_title . '::' . $_tooltip_content . '"'); $icon = '<span class="fcfile_mime">' . $icon . '</span>'; } // b. LANGUAGE: either as icon or as inline text or both $lang = ''; $lang_str = ''; $file_data->language = $file_data->language == '' ? '*' : $file_data->language; if ($display_lang && $file_data->language != '*') { $lang = '<span class="fcfile_lang">'; if ($add_lang_img && @$langs->{$file_data->language}->imgsrc) { if (!$add_lang_txt) { $_tooltip_title = JText::_('FLEXI_LANGUAGE', true); $_tooltip_content = $file_data->language == '*' ? JText::_("All") : $langs->{$file_data->language}->name; $_attribs = FLEXI_J30GE ? 'class="hasTooltip icon-lang" title="' . JHtml::tooltipText($_tooltip_title, $_tooltip_content, 0, 0) . '"' : 'class="hasTip icon-lang" title="' . $_tooltip_title . '::' . $_tooltip_content . '"'; } else { $_attribs = ' class="icon-lang"'; } $lang .= "\n" . '<img src="' . $langs->{$file_data->language}->imgsrc . '" ' . $_attribs . ' /> '; } if ($add_lang_txt) { $lang .= '[' . ($file_data->language == '*' ? JText::_("FLEXI_ALL_LANGUAGES") : $langs->{$file_data->language}->name) . ']'; } $lang .= '</span>'; } // c. SIZE: in KBs / MBs $sizeinfo = ''; if ($display_size) { $sizeinfo = '<span class="fcfile_size">'; if ($display_size == 1) { $sizeinfo .= '(' . number_format($file_data->size / 1024, 0) . ' ' . JTEXT::_('FLEXI_KBS') . ')'; } else { if ($display_size == 2) { $sizeinfo .= '(' . number_format($file_data->size / 1048576, 2) . ' ' . JTEXT::_('FLEXI_MBS') . ')'; } else { $sizeinfo .= '(' . number_format($file_data->size / 1073741824, 2) . ' ' . JTEXT::_('FLEXI_GBS') . ')'; } } $sizeinfo .= '</span>'; } // d. HITS: either as icon or as inline text or both $hits = ''; if ($display_hits) { $hits = '<span class="fcfile_hits">'; if ($add_hits_img && @$hits_icon) { $hits .= sprintf($hits_icon, $file_data->hits); } if ($add_hits_txt) { $hits .= '(' . $file_data->hits . ' ' . JTEXT::_('FLEXI_HITS') . ')'; } $hits .= '</span>'; } // e. FILENAME / TITLE: decide whether to show it (if we do not use button, then displaying of filename is forced) $_filetitle = $file_data->altname ? $file_data->altname : $file_data->filename; if ($lowercase_filename) { $_filetitle = mb_strtolower($_filetitle, "UTF-8"); } $filename_original = $file_data->filename_original ? $file_data->filename_original : $file_data->filename; ${$filename_original} = str_replace(array("'", "\""), array("\\'", ""), $filename_original); $filename_original = htmlspecialchars($filename_original, ENT_COMPAT, 'UTF-8'); $name_str = $display_filename == 2 ? $filename_original : $_filetitle; $name_classes = $file_classes . ($file_classes ? ' ' : '') . 'fcfile_title'; $name_html = '<span class="' . $name_classes . '">' . $name_str . '</span>'; // f. DESCRIPTION: either as tooltip or as inline text $descr_tip = $descr_inline = $descr_icon = ''; if (!empty($file_data->description)) { if (!$authorized) { if ($noaccess_display != 2) { $descr_tip = flexicontent_html::escapeJsText($name_str . '::' . $file_data->description, 's'); $descr_icon = '<img src="components/com_flexicontent/assets/images/comment.png" class="hasTip" title="' . $descr_tip . '"/>'; $descr_inline = ''; } } else { if ($display_descr == 1 || $prop == 'namelist') { // As tooltip $descr_tip = flexicontent_html::escapeJsText($name_str . '::' . $file_data->description, 's'); $descr_icon = '<img src="components/com_flexicontent/assets/images/comment.png" class="hasTip" title="' . $descr_tip . '"/>'; $descr_inline = ''; } else { if ($display_descr == 2) { // As inline text $descr_inline = ' <span class="fcfile_descr_inline fc-mssg fc-caption" style="max-wdith">' . nl2br($file_data->description) . '</span>'; } } } if ($descr_icon) { $descr_icon = ' <span class="fcfile_descr_tip">' . $descr_icon . '</span>'; } } // ***************************** // Create field's displayed html // ***************************** // [1]: either create the download link -or- use no authorized link ... if (!$authorized) { $dl_link = $noaccess_url; if ($noaccess_msg) { $str = '<span class="fcfile_noauth_msg fc-mssg-inline fc-noauth">' . $noaccess_msg . '</span> '; } } else { $dl_link = JRoute::_('index.php?option=com_flexicontent&id=' . $file_id . '&cid=' . $field->item_id . '&fid=' . $field->id . '&task=download'); $str = ''; } // SOME behavior FLAGS $not_downloadable = !$dl_link || $prop == 'namelist'; $filename_shown = !$authorized || $show_filename; $filename_shown_as_link = $filename_shown && $link_filename && !$usebutton; // [2]: Add information properties: filename, and icons with optional inline text $info_arr = array(); if ($filename_shown && !$filename_shown_as_link || $not_downloadable) { // Filename will be shown if not l $info_arr[] = $icon . ' ' . $name_html; } if ($lang) { $info_arr[] = $lang; } if ($sizeinfo) { $info_arr[] = $sizeinfo; } if ($hits) { $info_arr[] = $hits; } if ($descr_icon) { $info_arr[] = $descr_icon; } $str .= implode($info_arr, $infoseptxt); // [3]: Display the buttons: DOWNLOAD, SHARE, ADD TO CART $actions_arr = array(); // *********************** // CASE 1: no download ... // *********************** // EITHER (a) Current user NOT authorized to download file AND no access URL is not configured // OR (b) creating a file list with no download links, (the 'prop' display variable is 'namelist') if ($not_downloadable) { // nothing to do here, the file name/title will be shown above } else { if ($usebutton) { $file_classes .= ($file_classes ? ' ' : '') . 'fc_button fcsimple'; // Add an extra css class (button display) // DOWNLOAD: single file instant download if ($allowdownloads) { // NO ACCESS: add file info via form field elements, in case the URL target needs to use them $file_data_fields = ""; if (!$authorized && $noaccess_addvars) { $file_data_fields = '<input type="hidden" name="fc_field_id" value="' . $field->id . '"/>' . "\n" . '<input type="hidden" name="fc_item_id" value="' . $field->item_id . '"/>' . "\n" . '<input type="hidden" name="fc_file_id" value="' . $file_id . '"/>' . "\n"; } // The download button in a mini form ... $actions_arr[] = '' . '<form id="form-download-' . $field->id . '-' . ($n + 1) . '" method="post" action="' . $dl_link . '" style="display:inline-block;" >' . $file_data_fields . '<input type="submit" name="download-' . $field->id . '[]" class="' . $file_classes . ' fcfile_downloadFile" title="' . $downloadsinfo . '" value="' . $downloadstext . '"/>' . '</form>' . "\n"; } if ($authorized && $allowview && !$file_data->url) { $actions_arr[] = ' <a href="' . $dl_link . '?method=view" class="fancybox ' . $file_classes . ' fcfile_viewFile" data-fancybox-type="iframe" title="' . $viewinfo . '" style="line-height:1.3em;" > ' . $viewtext . ' </a>'; $fancybox_needed = 1; } // ADD TO CART: the link will add file to download list (tree) (handled via a downloads manager module) if ($authorized && $allowaddtocart && !$file_data->url) { // CSS class to anchor downloads list adding function $addtocart_classes = $file_classes . ($file_classes ? ' ' : '') . 'fcfile_addFile'; $attribs = ' class="' . $addtocart_classes . '"'; $attribs .= ' title="' . $addtocartinfo . '"'; $attribs .= ' filename="' . flexicontent_html::escapeJsText($_filetitle, 's') . '"'; $attribs .= ' fieldid="' . $field->id . '"'; $attribs .= ' contentid="' . $field->item_id . '"'; $attribs .= ' fileid="' . $file_data->id . '"'; $actions_arr[] = '<input type="button" ' . $attribs . ' value="' . $addtocarttext . '" />'; } // SHARE FILE VIA EMAIL: open a popup or inline email form ... if ($is_public && $allowshare && !$com_mailto_found) { // skip share popup form button if com_mailto is missing $actions_arr[] = ' com_mailto component not found, please disable <b>download link sharing parameter</b> in this file field'; } else { if ($is_public && $allowshare) { $send_onclick = 'window.open(\'%s\',\'win2\',\'' . $status . '\'); return false;'; $send_form_url = 'index.php?option=com_flexicontent&tmpl=component' . '&task=call_extfunc&exttype=plugins&extfolder=flexicontent_fields&extname=file&extfunc=share_file_form' . '&file_id=' . $file_id . '&content_id=' . $item->id . '&field_id=' . $field->id; $actions_arr[] = '<input type="button" class="' . $file_classes . ' fcfile_shareFile" onclick="' . sprintf($send_onclick, JRoute::_($send_form_url)) . '" title="' . $shareinfo . '" value="' . $sharetext . '" />'; } } } else { // DOWNLOAD: single file instant download if ($allowdownloads) { // NO ACCESS: add file info via URL variables, in case the URL target needs to use them if (!$authorized && $noaccess_addvars) { $dl_link .= '&fc_field_id="' . $field->id . '&fc_item_id="' . $field->item_id . '&fc_file_id="' . $file_id; } // The download link, if filename/title not shown, then display a 'download' prompt text $actions_arr[] = ($filename_shown && $link_filename ? $icon . ' ' : '') . '<a href="' . $dl_link . '" class="' . $file_classes . ' fcfile_downloadFile" title="' . $downloadsinfo . '" >' . ($filename_shown && $link_filename ? $name_str : $downloadstext) . '</a>'; } if ($authorized && $allowview && !$file_data->url) { $actions_arr[] = ' <a href="' . $dl_link . '?method=view" class="fancybox ' . $file_classes . ' fcfile_viewFile" data-fancybox-type="iframe" title="' . $viewinfo . '" > ' . $viewtext . ' </a>'; $fancybox_needed = 1; } // ADD TO CART: the link will add file to download list (tree) (handled via a downloads manager module) if ($authorized && $allowaddtocart && !$file_data->url) { // CSS class to anchor downloads list adding function $addtocart_classes = $file_classes . ($file_classes ? ' ' : '') . 'fcfile_addFile'; $attribs = ' class="' . $addtocart_classes . '"'; $attribs .= ' title="' . $addtocartinfo . '"'; $attribs .= ' filename="' . flexicontent_html::escapeJsText($_filetitle, 's') . '"'; $attribs .= ' fieldid="' . $field->id . '"'; $attribs .= ' contentid="' . $field->item_id . '"'; $attribs .= ' fileid="' . $file_data->id . '"'; $actions_arr[] = '<a href="javascript:;" ' . $attribs . ' >' . $addtocarttext . '</a>'; } // SHARE FILE VIA EMAIL: open a popup or inline email form ... if ($is_public && $allowshare && !$com_mailto_found) { // skip share popup form button if com_mailto is missing $str .= ' com_mailto component not found, please disable <b>download link sharing parameter</b> in this file field'; } else { if ($is_public && $allowshare) { $send_onclick = 'window.open(\'%s\',\'win2\',\'' . $status . '\'); return false;'; $send_form_url = 'index.php?option=com_flexicontent&tmpl=component' . '&task=call_extfunc&exttype=plugins&extfolder=flexicontent_fields&extname=file&extfunc=share_file_form' . '&file_id=' . $file_id . '&content_id=' . $item->id . '&field_id=' . $field->id; $actions_arr[] = '<a href="javascript:;" class="fcfile_shareFile" onclick="' . sprintf($send_onclick, JRoute::_($send_form_url)) . '" title="' . $shareinfo . '">' . $sharetext . '</a>'; } } } } //Display the buttons "DOWNLOAD, SHARE, ADD TO CART" before or after the filename if ($buttonsposition) { $str .= (count($actions_arr) ? $infoseptxt : "") . '<span class="fcfile_actions">' . implode($actions_arr, $actionseptxt) . '</span>'; } else { $str = (count($actions_arr) ? $infoseptxt : "") . '<span class="fcfile_actions">' . implode($actions_arr, $actionseptxt) . '</span>' . $str; } // [4]: Add the file description (if displayed inline) if ($descr_inline) { $str .= $descr_inline; } // Values Prefix and Suffix Texts $field->{$prop}[] = $pretext . $str . $posttext; // Some extra data for developers: (absolute) file URL and (absolute) file path $field->url[] = $dl_link; $file->abspath[] = $abspath; $field->file_data[] = $file_data; $n++; } if (!empty($fancybox_needed)) { flexicontent_html::loadFramework('fancybox'); } // Apply seperator and open/close tags if (count($field->{$prop})) { $field->{$prop} = implode($separatorf, $field->{$prop}); $field->{$prop} = $opentag . $field->{$prop} . $closetag; } else { $field->{$prop} = ''; } }
function onDisplayFilter(&$filter, $value='', $formName='adminForm') { if ( !in_array($filter->field_type, self::$field_types) ) return; $db = JFactory::getDBO(); $formfieldname = 'filter_'.$filter->id; $display_filter_as = $filter->parameters->get( 'display_filter_as', 0 ); // Filter Type of Display $filter_as_range = in_array($display_filter_as, array(2,3,)) ; // Create first prompt option of drop-down select $label_filter = $filter->parameters->get( 'display_label_filter', 2 ) ; $first_option_txt = $label_filter==2 ? $filter->label : JText::_('FLEXI_ALL'); // Prepend Field's Label to filter HTML //$filter->html = $label_filter==1 ? $filter->label.': ' : ''; $filter->html = ''; $props_type = $filter->parameters->get('props_type'); switch ($props_type) { case 'language': // Authors // WARNING: we can not use column alias in from, join, where, group by, can use in having (mysql) and in order by // partial SQL clauses if (!FLEXI_J16GE) break; $filter->filter_valuesselect = ' i.language AS value, CONCAT_WS(\': \', lg.title, lg.title_native) AS text'; $filter->filter_valuesjoin = ' JOIN #__languages AS lg ON i.language = lg.lang_code'; $filter->filter_valueswhere = ' AND lg.published <> 0'; // full SQL clauses $filter->filter_groupby = ' GROUP BY i.language '; $filter->filter_having = null; // this indicates to use default, space is use empty $filter->filter_orderby = ' ORDER BY lg.title ASC '; FlexicontentFields::createFilter($filter, $value, $formName); break; default: $filter->html .= 'CORE property field of type: '.$props_type.' can not be used as search filter'; break; } // a. If field filter has defined a custom SQL query to create filter (drop-down select) options, execute it and then create the options if ( !empty($query) ) { $db->setQuery($query); $lists = $db->loadObjectList(); $options = array(); $options[] = JHTML::_('select.option', '', '- '.$first_option_txt.' -'); foreach ($lists as $list) $options[] = JHTML::_('select.option', $list->value, $list->text . ($count_column ? ' ('.$list->found.')' : '') ); } // b. If field filter has defined drop-down select options the create the drop-down select form field if ( !empty($options) ) { // Make use of select2 lib flexicontent_html::loadFramework('select2'); $classes = " use_select2_lib". @ $extra_classes; $extra_param = ''; // MULTI-select: special label and prompts if ($display_filter_as == 6) { $classes .= ' fc_label_internal fc_prompt_internal'; // Add field's LABEL internally or click to select PROMPT (via js) $_inner_lb = $label_filter==2 ? $filter->label : JText::_('FLEXI_CLICK_TO_LIST'); // Add type to filter PROMPT (via js) $extra_param = ' data-fc_label_text="'.flexicontent_html::escapeJsText($_inner_lb,'s').'"'; $extra_param .= ' data-fc_prompt_text="'.flexicontent_html::escapeJsText(JText::_('FLEXI_TYPE_TO_FILTER'),'s').'"'; } // Create HTML tag attributes $attribs_str = ' class="fc_field_filter'.$classes.'" '.$extra_param; $attribs_str .= $display_filter_as==6 ? ' multiple="multiple" size="20" ' : ''; //$attribs_str .= ($display_filter_as==0 || $display_filter_as==6) ? ' onchange="document.getElementById(\''.$formName.'\').submit();"' : ''; // Filter name and id $filter_ffname = 'filter_'.$filter->id; $filter_ffid = $formName.'_'.$filter->id.'_val'; // Create filter $filter->html .= JHTML::_('select.genericlist', $options, $filter_ffname.'[]', $attribs_str, 'value', 'text', $value, $filter_ffid); } // Special CASE 'categories' filter, replace some tags in filter HTML ... //if ( $props_type == 'alias') $filter->html = str_replace('_', ' ', $filter->html); }