/** * Creates the page's display * * @since 1.0 */ function display($tpl = null) { $user = JFactory::getUser(); $aid = JAccess::getAuthorisedViewLevels($user->id); // Get model $model = $this->getModel(); // Get category and set category parameters as VIEW's parameters (category parameters are merged with component/page/author parameters already) $category = $this->get('Category'); $params = $category->parameters; // Get various data from the model $items = $this->get('Data'); // Get field values $_vars = null; FlexicontentFields::getItemFields($items, $_vars, $_view = 'category', $aid); // Zero unneeded search index text foreach ($items as $item) { $item->search_index = ''; } // Use &test=1 to test / preview item data of first item if (JRequest::getCmd('test', 0)) { $item = reset($items); echo "<pre>"; print_r($item); exit; } // Output items in JSON FORMAT echo @json_encode($items); }
function onDisplayFieldValue(&$field, $item, $values = null, $prop = 'display') { if (!in_array($field->field_type, self::$field_types)) { return; } $field->label = JText::_($field->label); $field->{$prop} = ''; $values = $values ? $values : $field->value; if ($field->field_type == 'relation_reverse') { $reverse_field = $field->parameters->get('reverse_field', 0); if (!$reverse_field) { $field->{$prop} = 'Field [id:' . $field->id . '] : ' . JText::_('FLEXI_FIELD_NO_FIELD_SELECTED'); return; } $_itemids_catids = null; // Always ignore passed items, the DB query will determine the items } else { // Compatibility with old values, we no longer serialize all values to one, this way the field can be reversed !!! $values = ($field_data = @unserialize($values)) ? $field_data : $field->value; // No related items, just return empty display if (!$values || !count($values)) { return; } $_itemids_catids = array(); foreach ($values as $i => $val) { list($itemid, $catid) = explode(":", $val); $_itemids_catids[$itemid] = new stdClass(); $_itemids_catids[$itemid]->itemid = $itemid; $_itemids_catids[$itemid]->catid = $catid; $_itemids_catids[$itemid]->value = $val; } } $field->{$prop} = FlexicontentFields::getItemsList($field->parameters, $_itemids_catids, $isform = 0, @$reverse_field, $field, $item); }
function display($tpl = null) { $user = JFactory::getUser(); $dispatcher = JDispatcher::getInstance(); // Initialize some variables $item =& $this->get('Item'); $params =& $item->parameters; $fields =& $this->get('Extrafields'); $tags =& $item->tags; $categories =& $item->categories; $favourites = $item->favourites; $favoured = $item->favoured; // process the new plugins JPluginHelper::importPlugin('content', 'image'); if (!FLEXI_J16GE) { $dispatcher->trigger('onPrepareContent', array(&$item, &$params, 0)); } else { $dispatcher->trigger('onContentPrepare', array('com_content.article', &$item, &$params, 0)); } $document = JFactory::getDocument(); // set document information $document->setTitle($item->title); $document->setName($item->alias); $document->setDescription($item->metadesc); $document->setMetaData('keywords', $item->metakey); // prepare header lines $document->setHeader($this->_getHeaderText($item, $params)); $pdf_format_fields = trim($params->get("pdf_format_fields")); $pdf_format_fields = !$pdf_format_fields ? array() : preg_split("/[\\s]*,[\\s]*/", $pdf_format_fields); $methodnames = array(); foreach ($pdf_format_fields as $pdf_format_field) { @(list($fieldname, $methodname) = preg_split("/[\\s]*:[\\s]*/", $pdf_format_field)); $methodnames[$fieldname] = empty($methodname) ? 'display' : $methodname; } // IF no fields set then just print the item's description text if (!count($pdf_format_fields)) { echo $item->text; return; } foreach ($fields as $field) { if (!isset($methodnames[$field->name])) { continue; } if ($field->iscore) { FlexicontentFields::loadFieldConfig($field, $item); //$results = $dispatcher->trigger('onDisplayCoreFieldValue', array( &$field, $item, &$params, $tags, $categories, $favourites, $favoured )); FLEXIUtilities::call_FC_Field_Func('core', 'onDisplayCoreFieldValue', array(&$field, $item, &$params, $tags, $categories, $favourites, $favoured)); } else { //$results = $dispatcher->trigger('onDisplayFieldValue', array( &$field, $item )); FLEXIUtilities::call_FC_Field_Func($field->field_type, 'onDisplayFieldValue', array(&$field, $item)); } if (@$field->display) { echo '<b>' . $field->label . '</b>: '; echo $field->display . '<br /><br />'; } } }
/** * Creates the page's display * * @since 1.0 */ function display($tpl = null) { $user = JFactory::getUser(); $aid = JAccess::getAuthorisedViewLevels($user->id); // Get model $model = $this->getModel(); // Indicate to model that current view IS item form $model->isForm = false; $cid = $model->_cid ? $model->_cid : $model->get('catid'); // Get current category id // Decide version to load $version = JRequest::getVar('version', 0, 'request', 'int'); // Load specific item version (non-zero), 0 version: is unversioned data, -1 version: is latest version (=default for edit form) $preview = JRequest::getVar('preview', 0, 'request', 'int'); // Preview versioned data FLAG ... if previewing and version is not set then ... we load version -1 (=latest version) $version = $preview && !$version ? -1 : $version; // Allow iLayout from HTTP request, this will be checked during loading item parameters $model->setItemLayout('__request__'); // Indicate to model to merge menu parameters if menu matches $model->mergeMenuParams = true; // Try to load existing item, an 404 error will be raised if item is not found. Also value 2 for check_view_access // indicates to raise 404 error for ZERO primary key too, instead of creating and returning a new item object // Get the item, loading item data and doing parameters merging $item = $model->getItem(null, $check_view_access = 2, $no_cache = $version || $preview, $force_version = $version || $preview ? $version : 0); // ZERO means unversioned data // Get item parameters as VIEW's parameters (item parameters are merged parameters in order: component/category/layout/type/item/menu/access) $params =& $item->parameters; // Get field values $items = array($item); $_vars = null; FlexicontentFields::getItemFields($items, $_vars, $_view = FLEXI_ITEMVIEW, $aid); // Zero unneeded search index text foreach ($items as $item) { $item->search_index = ''; } $item->search_index = ''; // Use &test=1 to test / preview item data if (JRequest::getCmd('test', 0)) { echo "<pre>"; print_r($item); exit; } // Output item in JSON FORMAT echo @json_encode($item); }
/** * count the rows * * @access public * @return void * @since 1.0 */ function countrows() { $start_microtime = microtime(true); // Check for request forgeries //JRequest::checkToken() or jexit( 'Invalid Token' ); //$params = JComponentHelper::getParams( 'com_flexicontent' ); @ob_end_clean(); $indexer = JRequest::getVar('indexer', 'advanced'); $rebuildmode = JRequest::getVar('rebuildmode', ''); $session = JFactory::getSession(); // Retrieve fields, that are assigned as (advanced/basic) searchable/filterable if ($rebuildmode == 'quick' && $indexer == 'advanced') { $nse_fields = FlexicontentFields::getSearchFields('id', $indexer, null, null, $_load_params = false, 0, $search_type = 'non-search'); $nsp_fields = FlexicontentFields::getSearchFields('id', $indexer, null, null, $_load_params = false, 0, $search_type = 'dirty-nosupport'); $session->set($indexer . '_nse_fields', $nse_fields, 'flexicontent'); $session->set($indexer . '_nsp_fields', $nsp_fields, 'flexicontent'); $fields = FlexicontentFields::getSearchFields('id', $indexer, null, null, $_load_params = true, 0, $search_type = 'dirty-search'); } else { $fields = FlexicontentFields::getSearchFields('id', $indexer, null, null, $_load_params = true, 0, $search_type = 'all-search'); } // Get the field ids of the searchable fields $fieldids = array_keys($fields); // Get ids of searchable and ids of item having values for these fields $itemsmodel = $this->getModel('items'); // Get items model to call needed methods $itemids = $itemsmodel->getFieldsItems($fieldids); // Get the items ids that have value for any of the searchable fields // Set item ids into session to avoid recalculation ... $session->set($indexer . '_items_to_index', $itemids, 'flexicontent'); // Set field information into session to avoid recalculation ... $session->set($indexer . '_fields', $fields, 'flexicontent'); echo 'success'; //echo count($fieldids)*count($itemids).'|'; // WARNING: json_encode will output object if given an array with gaps in the indexing //echo '|'.json_encode($itemids); //echo '|'.json_encode($fieldids); echo '|' . count($itemids); echo '|' . count($fieldids); $elapsed_microseconds = round(1000000 * 10 * (microtime(true) - $start_microtime)) / 10; $session->set($indexer . '_total_runtime', $elapsed_microseconds, 'flexicontent'); exit; }
$published = JHTML::image('administrator/components/com_flexicontent/assets/images/tick_f2.png', JText::_('FLEXI_NOT_AVAILABLE'), ' class="fc-man-icon-s" '); } else { if (!$canPublish && $row->published) { // No privilige published $published = JHTML::image('administrator/components/com_flexicontent/assets/images/tick_f2.png', JText::_('FLEXI_NOT_AVAILABLE'), ' class="fc-man-icon-s" '); } else { if (!$canPublish && !$row->published) { // No privilige unpublished $published = JHTML::image('administrator/components/com_flexicontent/assets/images/publish_x_f2.png', JText::_('FLEXI_NOT_AVAILABLE'), ' class="fc-man-icon-s" '); } else { $published = JHTML::_('jgrid.published', $row->published, $i, $ctrl); } } } //check which properties are supported by current field $ft_support = FlexicontentFields::getPropertySupport($row->field_type, $row->iscore); $supportsearch = $ft_support->supportsearch; $supportfilter = $ft_support->supportfilter; $supportadvsearch = $ft_support->supportadvsearch; $supportadvfilter = $ft_support->supportadvfilter; if ($row->issearch == 0 || $row->issearch == 1 || !$supportsearch) { $search_dirty = 0; $issearch = $row->issearch && $supportsearch ? "search.png" : "publish_x" . (!$supportsearch ? '_f2' : '') . ".png"; $issearch_tip = $row->issearch && $supportsearch ? $flexi_yes . ", " . $flexi_toggle : ($supportsearch ? $flexi_no . ", " . $flexi_toggle : $flexi_nosupport); } else { $search_dirty = 1; $issearch = $row->issearch == -1 ? "disconnect.png" : "connect.png"; $issearch_tip = ($row->issearch == 2 ? $flexi_yes : $flexi_no) . ", " . $flexi_toggle . ", " . $flexi_rebuild; } $isfilter = $row->isfilter && $supportfilter ? "filter.png" : "publish_x" . (!$supportfilter ? '_f2' : '') . ".png"; $isfilter_tip = $row->isfilter && $supportfilter ? $flexi_yes . ", " . $flexi_toggle : ($supportsearch ? $flexi_no . ", " . $flexi_toggle : $flexi_nosupport);
function onIndexSearch(&$field, &$post, &$item) { if (!in_array($field->field_type, self::$field_types)) { return; } if (!$field->issearch) { return; } // a. Each of the values of $values array will be added to the basic search index (one record per item) // b. If $values is null then the column value from table 'flexicontent_fields_item_relations' for current field / item pair will be used // 'required_properties' is meant for multi-property fields, do not add to search index if any of these is empty // 'search_properties' contains property fields that should be added as text // 'properties_spacer' is the spacer for the 'search_properties' text // 'filter_func' is the filtering function to apply to the final text FlexicontentFields::onIndexSearch($field, $post, $item, $required_properties = array('title'), $search_properties = array('title', 'text'), $properties_spacer = ' ', $filter_func = 'strip_tags'); return true; }
<div class="lineinfo image_descr"> <?php if ($this->params->get('intro_use_image', 1) && $src) : ?> <figure class="image<?php echo $this->params->get('intro_position') ? ' right' : ' left'; ?>"> <?php if ($this->params->get('intro_link_image', 1)) : ?> <a href="<?php echo JRoute::_(FlexicontentHelperRoute::getItemRoute($item->slug, $item->categoryslug, 0, $item)); ?>" class="hasTip" title="<?php echo JText::_( 'FLEXI_READ_MORE_ABOUT' ) . '::' . htmlspecialchars($item->title, ENT_COMPAT, 'UTF-8'); ?>"> <img src="<?php echo $thumb; ?>" alt="<?php echo htmlspecialchars($item->title, ENT_COMPAT, 'UTF-8'); ?>" /> </a> <?php else : ?> <img src="<?php echo $thumb; ?>" alt="<?php echo htmlspecialchars($item->title, ENT_COMPAT, 'UTF-8'); ?>" /> <?php endif; ?> </figure> <?php endif; ?> <p> <?php FlexicontentFields::getFieldDisplay($item, 'text', $values=null, $method='display'); if ($this->params->get('intro_strip_html', 1)) : echo flexicontent_html::striptagsandcut( $item->fields['text']->display, $this->params->get('intro_cut_text', 200) ); else : echo $item->fields['text']->display; endif; ?> </p> </div> <!-- BOF under-description-line1 block --> <?php if (isset($item->positions['under-description-line1'])) : ?> <div class="lineinfo line3"> <?php foreach ($item->positions['under-description-line1'] as $field) : ?> <span class="element"> <?php if ($field->label) : ?>
} // Remove categories filter if ($display_cat_list || $catid) { foreach ($filters as $i => $filter) { if ($filter->field_type == 'categories') { unset($filters[$i]); break; } } } // Set filter values (initial or locked) via configuration parameters FlexicontentFields::setFilterValues($params, 'persistent_filters', $is_persistent = 1); FlexicontentFields::setFilterValues($params, 'initial_filters', $is_persistent = 0); // 4. Add html to filter objects if (!empty($filters)) { FlexicontentFields::renderFilters($params, $filters, $form_name); } // Restore variables JRequest::setVar('cid', $saved_cid); // restore cid JRequest::setVar('layout', $saved_layout); // restore layout JRequest::setVar('option', $saved_option); // restore option JRequest::setVar('view', $saved_view); // restore view // 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 tooltips
private function _createDisplayHTML(&$field, &$item, &$grouped_fields, $custom_html, $max_count, $pretext, $posttext) { // ******************************** // Parse and identify custom fields // ******************************** //return array('"<b>Custom HTML</b>" display for fieldgroup field, is not implemented yet, please use default HTML'); if (!$custom_html) { return "Empty custom HTML variable for group field: " . $field->label; } $result = preg_match_all("/\\{\\{([a-zA-Z_0-9]+)(##)?([a-zA-Z_0-9]+)?\\}\\}/", $custom_html, $field_matches); $gf_reps = $result ? $field_matches[0] : array(); $gf_names = $result ? $field_matches[1] : array(); $gf_methods = $result ? $field_matches[3] : array(); //foreach ($gf_names as $i => $gf_name) // $parsed_fields[] = $gf_names[$i] . ($gf_methods[$i] ? "->". $gf_methods[$i] : ""); //echo "$custom_html :: Fields for Related Items List: ". implode(", ", $parsed_fields ? $parsed_fields : array() ) ."<br/>\n"; // *********************************************************************** // Parse and identify language strings and then make language replacements // *********************************************************************** $result = preg_match_all("/\\%\\%([^%]+)\\%\\%/", $custom_html, $translate_matches); $translate_strings = $result ? $translate_matches[1] : array('FLEXI_READ_MORE_ABOUT'); foreach ($translate_strings as $translate_string) { $custom_html = str_replace('%%' . $translate_string . '%%', JText::_($translate_string), $custom_html); } // ************************************************************** // Render HTML of grouped fields mentioned inside the custom HTML // ************************************************************** $_rendered_fields = array(); $found_names = array_flip($gf_names); //print_r($gf_names); if (count($gf_names)) { $view = JRequest::getVar('flexi_callview', JRequest::getVar('view', FLEXI_ITEMVIEW)); $gf_props = array(); foreach ($grouped_fields as $grouped_field) { if (!isset($found_names[$grouped_field->name])) { continue; } $pos = $found_names[$grouped_field->name]; $_rendered_fields[$pos] = $grouped_field; // Check if display method is 'label' aka nothing to render if ($gf_methods[$pos] == 'label') { continue; } // Check if display method of the field has been created already $method = $gf_methods[$pos] ? $gf_methods[$pos] : 'display'; if (isset($grouped_field->{$method}) && is_array($grouped_field->{$method})) { continue; } // Render the display method for the given field $_values = $grouped_field->value; $grouped_field->ingroup = 1; // render as array //echo 'Rendering: '. $grouped_field->name . ', method: ' . $method . '<br/>'; //FLEXIUtilities::call_FC_Field_Func($grouped_field->field_type, 'onDisplayFieldValue', array(&$grouped_field, $item, $_values, $method)); unset($grouped_field->{$method}); // Unset display variable to make sure display HTML it is created, because we reuse the field FlexicontentFields::renderField($item, $grouped_field, $_values, $method, $view); // Includes content plugins triggering unset($grouped_field->ingroup); } } // ******************************************************************* // Render the value list of the fieldgroup, using custom HTML for each // value-set of the fieldgroup, and performing the field replacements // ******************************************************************* $custom_display = array(); for ($n = 0; $n < $max_count; $n++) { $rendered_html = $custom_html; foreach ($_rendered_fields as $pos => $_rendered_field) { $pos = $found_names[$_rendered_field->name]; $method = $gf_methods[$pos] ? $gf_methods[$pos] : 'display'; //echo 'Replacing: '. $_rendered_field->name . ', method: ' . $method . ', index: ' .$n. '<br/>'; $rendered_html = str_replace($gf_reps[$pos], @$_rendered_field->{$method}[$n], $rendered_html); //unset($_rendered_field->{$method}); // Unset display of fields in case they need to be rendered again } $custom_display[$n] = $pretext . $rendered_html . $posttext; } return $custom_display; }
function display($tpl = null) { //initialise variables $app = JFactory::getApplication(); $document = JFactory::getDocument(); $cparams = JComponentHelper::getParams('com_flexicontent'); $user = JFactory::getUser(); //add css to document $document->addStyleSheet(JURI::base() . 'components/com_flexicontent/assets/css/flexicontentbackend.css'); if (FLEXI_J30GE) { $document->addStyleSheet(JURI::base() . 'components/com_flexicontent/assets/css/j3x.css'); } else { if (FLEXI_J16GE) { $document->addStyleSheet(JURI::base() . 'components/com_flexicontent/assets/css/j25.css'); } else { $document->addStyleSheet(JURI::base() . 'components/com_flexicontent/assets/css/j15.css'); } } //add js function to overload the joomla submitform FLEXI_J30GE ? JHtml::_('behavior.framework', true) : JHTML::_('behavior.mootools'); JHTML::_('behavior.tooltip'); flexicontent_html::loadFramework('jQuery'); flexicontent_html::loadFramework('select2'); $document->addScript(JURI::root() . 'components/com_flexicontent/assets/js/admin.js'); $document->addScript(JURI::root() . 'components/com_flexicontent/assets/js/validate.js'); //Load pane behavior jimport('joomla.html.pane'); //Import File system jimport('joomla.filesystem.file'); //Get data from the model $model = $this->getModel(); $row = $this->get('Field'); if (FLEXI_J16GE) { $form = $this->get('Form'); } $types = $this->get('Typeslist'); $typesselected = $this->get('Typesselected'); //create the toolbar if ($row->id) { JToolBarHelper::title(JText::_('FLEXI_EDIT_FIELD'), 'fieldedit'); } else { JToolBarHelper::title(JText::_('FLEXI_ADD_FIELD'), 'fieldadd'); } $ctrl = FLEXI_J16GE ? 'fields.' : ''; JToolBarHelper::apply($ctrl . 'apply'); JToolBarHelper::save($ctrl . 'save'); JToolBarHelper::custom($ctrl . 'saveandnew', 'savenew.png', 'savenew.png', 'FLEXI_SAVE_AND_NEW', false); JToolBarHelper::cancel($ctrl . 'cancel'); // Import Joomla plugin that implements the type of current flexi field JPluginHelper::importPlugin('flexicontent_fields', $row->iscore ? 'core' : $row->field_type); // load plugin's english language file then override with current language file $extension_name = 'plg_flexicontent_fields_' . ($row->iscore ? 'core' : $row->field_type); JFactory::getLanguage()->load($extension_name, JPATH_ADMINISTRATOR, 'en-GB', true); JFactory::getLanguage()->load($extension_name, JPATH_ADMINISTRATOR, null, true); //check which properties are supported by current field $ft_support = FlexicontentFields::getPropertySupport($row->field_type, $row->iscore); $supportsearch = $ft_support->supportsearch; $supportadvsearch = $ft_support->supportadvsearch; $supportfilter = $ft_support->supportfilter; $supportadvfilter = $ft_support->supportadvfilter; $supportuntranslatable = $ft_support->supportuntranslatable; $supportvalueseditable = $ft_support->supportvalueseditable; $supportformhidden = $ft_support->supportformhidden; $supportedithelp = $ft_support->supportedithelp; //build selectlists, (for J1.6+ most of these are defined via XML file and custom form field classes) $lists = array(); //build field_type list if (!$row->field_type) { $row->field_type = 'text'; } if ($row->iscore == 1) { $class = 'disabled="disabled"'; } else { $class = ''; $_field_id = '#' . (FLEXI_J16GE ? 'jform_' : '') . 'field_type'; $_row_id = FLEXI_J16GE ? $form->getValue("id") : $row->id; $_ctrl_task = FLEXI_J16GE ? 'task=fields.getfieldspecificproperties' : 'controller=fields&task=getfieldspecificproperties'; $document->addScriptDeclaration("\n\t\t\t\tjQuery(document).ready(function() {\n\t\t\t\t\tjQuery('" . $_field_id . "').on('change', function() {\n\t\t\t\t\t\tjQuery('#fieldspecificproperties').html('<p class=\"centerimg\"><img src=\"components/com_flexicontent/assets/images/ajax-loader.gif\" align=\"center\"></p>');\n\t\t\t\t\t\tjQuery.ajax({\n\t\t\t\t\t\t\ttype: \"GET\",\n\t\t\t\t\t\t\turl: 'index.php?option=com_flexicontent&" . $_ctrl_task . "&cid=" . $_row_id . "&field_type='+this.value+'&format=raw',\n\t\t\t\t\t\t\tsuccess: function(str) {\n\t\t\t\t\t\t\t\tjQuery('#fieldspecificproperties').html(str);\n\t\t\t\t\t\t\t\tvar JTooltips = new Tips(jQuery('#fieldspecificproperties .hasTip'), { maxTitleChars: 50, fixed: false});\t\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\tjQuery('#field_typename').html(jQuery('" . $_field_id . "').val());\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t});\n\t\t\t\t\t});\n\t\t\t\t});\n\t\t\t"); } //build field select list $lists['field_type'] = flexicontent_html::buildfieldtypeslist('field_type', $class, $row->field_type, $group = true); //build type select list $attribs = 'class="use_select2_lib" multiple="multiple" size="6"'; $attribs .= $row->iscore ? ' disabled="disabled"' : ''; $types_fieldname = FLEXI_J16GE ? 'jform[tid][]' : 'tid[]'; $lists['tid'] = flexicontent_html::buildtypesselect($types, $types_fieldname, $typesselected, false, $attribs); // ************************************************************************** // Create fields for J1.5 (J2.5+ uses JForm XML file for most of form fields) // ************************************************************************** if (!FLEXI_J16GE) { //build formhidden selector $formhidden[] = JHTML::_('select.option', 0, JText::_('FLEXI_NO')); $formhidden[] = JHTML::_('select.option', 1, JText::_('FLEXI_FRONTEND')); $formhidden[] = JHTML::_('select.option', 2, JText::_('FLEXI_BACKEND')); $formhidden[] = JHTML::_('select.option', 3, JText::_('FLEXI_BOTH')); $formhidden_fieldname = FLEXI_J16GE ? 'jform[formhidden]' : 'formhidden'; $lists['formhidden'] = JHTML::_('select.radiolist', $formhidden, $formhidden_fieldname, '', 'value', 'text', $row->formhidden); if (FLEXI_ACCESS) { $valueseditable[] = JHTML::_('select.option', 0, JText::_('FLEXI_ANY_EDITOR')); $valueseditable[] = JHTML::_('select.option', 1, JText::_('FLEXI_USE_ACL_PERMISSION')); $valueseditable_fieldname = FLEXI_J16GE ? 'jform[valueseditable]' : 'valueseditable'; $lists['valueseditable'] = JHTML::_('select.radiolist', $valueseditable, $valueseditable_fieldname, '', 'value', 'text', $row->valueseditable); } $edithelp[] = JHTML::_('select.option', 0, JText::_('FLEXI_EDIT_HELP_NONE')); $edithelp[] = JHTML::_('select.option', 1, JText::_('FLEXI_EDIT_HELP_LABEL_TOOLTIP')); $edithelp[] = JHTML::_('select.option', 2, JText::_('FLEXI_EDIT_HELP_LABEL_TOOLTIP_WICON')); $edithelp[] = JHTML::_('select.option', 3, JText::_('FLEXI_EDIT_HELP_INLINE')); $edithelp_fieldname = FLEXI_J16GE ? 'jform[edithelp]' : 'edithelp'; $lists['edithelp'] = JHTML::_('select.radiolist', $edithelp, $edithelp_fieldname, '', 'value', 'text', $row->edithelp); // build the html select list for ordering $query = 'SELECT ordering AS value, label AS text' . ' FROM #__flexicontent_fields' . ' WHERE published >= 0' . ' ORDER BY ordering'; $row->ordering = @$row->ordering; $lists['ordering'] = $row->id ? JHTML::_('list.specificordering', $row, $row->id, $query) : JHTML::_('list.specificordering', $row, '', $query); //build access level list if (FLEXI_ACCESS) { $lang = JFactory::getLanguage(); $lang->_strings['FLEXIACCESS_PADD'] = 'Edit-Value'; $lists['access'] = FAccess::TabGmaccess($row, 'field', 1, 1, 0, 1, 0, 1, 0, 1, 1); } else { $lists['access'] = JHTML::_('list.accesslevel', $row); } } if (!FLEXI_J16GE) { // Create the parameter 's form object parsing the file XML $pluginpath = JPATH_PLUGINS . DS . 'flexicontent_fields' . DS . $row->field_type . '.xml'; if (JFile::exists($pluginpath)) { $form = new JParameter('', $pluginpath); } else { $form = new JParameter('', JPATH_PLUGINS . DS . 'flexicontent_fields' . DS . 'core.xml'); } // Special and Core Groups $form->loadINI($row->attribs); } // fail if checked out not by 'me' if ($row->id) { if ($model->isCheckedOut($user->get('id'))) { JError::raiseWarning('SOME_ERROR_CODE', $row->name . ' ' . JText::_('FLEXI_EDITED_BY_ANOTHER_ADMIN')); $app->redirect('index.php?option=com_flexicontent&view=fields'); } } //clean data JFilterOutput::objectHTMLSafe($row, ENT_QUOTES); // assign permissions for J2.5 if (FLEXI_J16GE) { $permission = FlexicontentHelperPerm::getPerm(); $this->assignRef('permission', $permission); } //assign data to template $this->assignRef('document', $document); $this->assignRef('row', $row); $this->assignRef('lists', $lists); $this->assignRef('form', $form); $this->assignRef('typesselected', $typesselected); $this->assignRef('supportsearch', $supportsearch); $this->assignRef('supportadvsearch', $supportadvsearch); $this->assignRef('supportfilter', $supportfilter); $this->assignRef('supportadvfilter', $supportadvfilter); $this->assignRef('supportuntranslatable', $supportuntranslatable); $this->assignRef('supportvalueseditable', $supportvalueseditable); $this->assignRef('supportformhidden', $supportformhidden); $this->assignRef('supportedithelp', $supportedithelp); parent::display($tpl); }
function onIndexSearch(&$field, &$post, &$item) { if (!$field->iscore) { return; } if (!$field->issearch) { return; } $values = $this->_prepareForSearchIndexing($field, $post, $for_advsearch = 0); // if post is null, indexer is running $filter_func = $field->field_type == 'maintext' ? 'strip_tags' : null; // 'isindexed' is not applicable for basic index and CORE fields $field->isindexed = 0; //in_array($field->field_type, array('type','state','tags','categories','created','createdby','modified','modifiedby')); // if values is null means retrieve data from the DB FlexicontentFields::onIndexSearch($field, $values, $item, $required_properties = array(), $search_properties = array(), $properties_spacer = ' ', $filter_func); return true; }
function onIndexSearch(&$field, &$post, &$item) { if (!$field->iscore) { return; } if (!$field->issearch) { return; } $values = $this->_prepareForSearchIndexing($field, $post, $for_advsearch = 0); $filter_func = $field->field_type == 'maintext' ? 'strip_tags' : null; FlexicontentFields::onIndexSearch($field, $values, $item, $required_properties = array(), $search_properties = array(), $properties_spacer = ' ', $filter_func); return true; }
/** * Creates the item submit form * * @since 1.0 */ function _displayForm($tpl) { jimport('joomla.html.parameter'); // ... we use some strings from administrator part // load english language file for 'com_content' component then override with current language file JFactory::getLanguage()->load('com_content', JPATH_ADMINISTRATOR, 'en-GB', true); JFactory::getLanguage()->load('com_content', JPATH_ADMINISTRATOR, null, true); // load english language file for 'com_flexicontent' component then override with current language file JFactory::getLanguage()->load('com_flexicontent', JPATH_ADMINISTRATOR, 'en-GB', true); JFactory::getLanguage()->load('com_flexicontent', JPATH_ADMINISTRATOR, null, true); // ******************************** // Initialize variables, flags, etc // ******************************** $app = JFactory::getApplication(); $dispatcher = JDispatcher::getInstance(); $document = JFactory::getDocument(); $session = JFactory::getSession(); $user = JFactory::getUser(); $db = JFactory::getDBO(); $uri = JFactory::getURI(); $nullDate = $db->getNullDate(); $menu = $app->getMenu()->getActive(); // We do not have item parameters yet, but we need to do some work before creating the item // Get the COMPONENT only parameter $params = new JRegistry(); $cparams = JComponentHelper::getParams('com_flexicontent'); $params->merge($cparams); // Merge the active menu parameters if ($menu) { $params->merge($menu->params); } // Some flags $enable_translation_groups = flexicontent_db::useAssociations(); //$params->get("enable_translation_groups"); $print_logging_info = $params->get('print_logging_info'); if ($print_logging_info) { global $fc_run_times; } // ***************** // Load JS/CSS files // ***************** FLEXI_J30GE ? JHtml::_('behavior.framework', true) : JHTML::_('behavior.mootools'); flexicontent_html::loadFramework('jQuery'); flexicontent_html::loadFramework('select2'); flexicontent_html::loadFramework('flexi-lib'); // Load custom behaviours: form validation, popup tooltips JHTML::_('behavior.formvalidation'); // load default validation JS to make sure it is overriden JHTML::_('behavior.tooltip'); if (FLEXI_J30GE) { JHtml::_('bootstrap.tooltip'); } //JHTML::_('script', 'joomla.javascript.js', 'includes/js/'); // Add css files to the document <head> section (also load CSS joomla template override) $document->addStyleSheet(JURI::base(true) . '/components/com_flexicontent/assets/css/flexicontent.css'); if (file_exists(JPATH_SITE . DS . 'templates' . DS . $app->getTemplate() . DS . 'css' . DS . 'flexicontent.css')) { $document->addStyleSheet($this->baseurl . '/templates/' . $app->getTemplate() . '/css/flexicontent.css'); } // Fields common CSS $document->addStyleSheet($this->baseurl . '/components/com_flexicontent/assets/css/flexi_form_fields.css'); // Load backend / frontend shared and Joomla version specific CSS (different for frontend / backend) FLEXI_J30GE ? $document->addStyleSheet(JURI::base(true) . '/components/com_flexicontent/assets/css/j3x.css') : $document->addStyleSheet(JURI::base(true) . '/components/com_flexicontent/assets/css/j25.css'); // Add js function to overload the joomla submitform $document->addScript(JURI::base(true) . '/components/com_flexicontent/assets/js/admin.js'); $document->addScript(JURI::base(true) . '/components/com_flexicontent/assets/js/validate.js'); // Add js function for custom code used by FLEXIcontent item form $document->addScript(JURI::base(true) . '/components/com_flexicontent/assets/js/itemscreen.js'); // ********************************************************* // Get item data and create item form (that loads item data) // ********************************************************* if ($print_logging_info) { $start_microtime = microtime(true); } $model = $this->getModel(); // ** WE NEED TO get OR decide the Content Type, before we call the getItem // ** We rely on typeid Request variable to decide type for new items so make sure this is set, // ZERO means allow user to select type, but if user is only allowed a single type, then autoselect it! // Try type from session $jdata = $app->getUserState('com_flexicontent.edit.item.data'); //print_r($jdata); if (!empty($jdata['type_id'])) { JRequest::setVar('typeid', (int) $jdata['type_id']); // This also forces zero if value not set } else { if ($menu && isset($menu->query['typeid'])) { JRequest::setVar('typeid', (int) $menu->query['typeid']); // This also forces zero if value not set } } $new_typeid = JRequest::getVar('typeid', 0, '', 'int'); // Verify type is allowed to the user if (!$new_typeid) { $types = $model->getTypeslist($type_ids_arr = false, $check_perms = true, $_published = true); if ($types && count($types) == 1) { $new_typeid = $types[0]->id; } JRequest::setVar('typeid', $new_typeid); $canCreateType = true; } // FORCE model to load versioned data (URL specified version or latest version (last saved)) $version = JRequest::getVar('version', 0, 'request', 'int'); // Load specific item version (non-zero), 0 version: is unversioned data, -1 version: is latest version (=default for edit form) $item = $model->getItem(null, $check_view_access = false, $no_cache = true, $force_version = $version != 0 ? $version : -1); // -1 version means latest // Replace component/menu 'params' with thee merged component/category/type/item/menu ETC ... parameters $params =& $item->parameters; if ($print_logging_info) { $fc_run_times['get_item_data'] = round(1000000 * 10 * (microtime(true) - $start_microtime)) / 10; } // Load permissions (used by form template) $perms = $this->_getItemPerms($item); // Create submit configuration (for new items) into the session, this is needed before creating the item form $submitConf = $this->_createSubmitConf($item, $perms); // Most core field are created via calling methods of the form (J2.5) $form = $this->get('Form'); // is new item and ownership Flags $isnew = !$item->id; $isOwner = $item->created_by == $user->get('id'); // Get available types and the currently selected/requested type $types = $model->getTypeslist(); $typesselected = $model->getTypesselected(); // Get type parameters, these are needed besides the 'merged' item parameters, e.g. to get Type's default layout $tparams = $this->get('Typeparams'); $tparams = new JRegistry($tparams); // ********************************************************************************************************* // Get language stuff, and also load Template-Specific language file to override or add new language strings // ********************************************************************************************************* if ($enable_translation_groups) { $langAssocs = $params->get('uselang_fe') == 1 ? $this->get('LangAssocs') : false; } $langs = FLEXIUtilities::getLanguages('code'); FLEXIUtilities::loadTemplateLanguageFile($params->get('ilayout', 'default')); // ************************************* // Create captcha field via custom logic // ************************************* // create and set (into HTTP request) a unique item id for plugins that needed it if ($item->id) { $unique_tmp_itemid = $item->id; } else { $unique_tmp_itemid = $app->getUserState('com_flexicontent.edit.item.unique_tmp_itemid'); $unique_tmp_itemid = $unique_tmp_itemid ? $unique_tmp_itemid : date('_Y_m_d_h_i_s_', time()) . uniqid(true); } //print_r($unique_tmp_itemid); JRequest::setVar('unique_tmp_itemid', $unique_tmp_itemid); // Component / Menu Item parameters $allowunauthorize = $params->get('allowunauthorize', 0); // allow unauthorised user to submit new content $unauthorized_page = $params->get('unauthorized_page', ''); // page URL for unauthorized users (via global configuration) $notauth_itemid = $params->get('notauthurl', ''); // menu itemid (to redirect) when user is not authorized to create content // Create captcha field or messages // Maybe some code can be removed by using Joomla's built-in form element (in XML file), instead of calling the captcha plugin ourselves $use_captcha = $params->get('use_captcha', 1); // 1 for guests, 2 for any user $captcha_formop = $params->get('captcha_formop', 0); // 0 for submit, 1 for submit/edit (aka always) $display_captcha = $use_captcha >= 2 || $use_captcha == 1 && $user->guest; $display_captcha = $display_captcha && ($isnew || $captcha_formop); // Trigger the configured captcha plugin if ($display_captcha) { // Get configured captcha plugin $c_plugin = $params->get('captcha', $app->getCfg('captcha')); // TODO add param to override default if ($c_plugin) { $c_name = 'captcha_response_field'; $c_id = $c_plugin == 'recaptcha' ? 'dynamic_recaptcha_1' : 'fc_dynamic_captcha'; $c_class = ' required'; $c_namespace = 'fc_item_form'; // Try to load the configured captcha plugin, (check if disabled or uninstalled), Joomla will enqueue an error message if needed $captcha_obj = JCaptcha::getInstance($c_plugin, array('namespace' => $c_namespace)); if ($captcha_obj) { $captcha_field = $captcha_obj->display($c_name, $c_id, $c_class); $label_class = 'flexi_label'; $label_class .= FLEXI_J30GE ? ' hasTooltip' : ' hasTip'; $label_tooltip = flexicontent_html::getToolTip(null, 'FLEXI_CAPTCHA_ENTER_CODE_DESC', 1, 1); $captcha_field = ' <label id="' . $c_name . '-lbl" for="' . $c_name . '" class="' . $label_class . '" title="' . $label_tooltip . '" > ' . JText::_('FLEXI_CAPTCHA_ENTER_CODE') . ' </label> <div id="container_fcfield_' . $c_plugin . '" class="container_fcfield container_fcfield_name_' . $c_plugin . '"> <div class="fcfieldval_container valuebox fcfieldval_container_' . $c_plugin . '"> ' . $captcha_field . ' </div> </div>'; } } } // ******************************* // CHECK EDIT / CREATE PERMISSIONS // ******************************* // User Group / Author parameters $authorparams = flexicontent_db::getUserConfig($user->id); $max_auth_limit = intval($authorparams->get('max_auth_limit', 0)); // maximum number of content items the user can create $hasTmpEdit = false; $hasCoupon = false; // Check session if ($session->has('rendered_uneditable', 'flexicontent')) { $rendered_uneditable = $session->get('rendered_uneditable', array(), 'flexicontent'); $hasTmpEdit = !empty($rendered_uneditable[$model->get('id')]); $hasCoupon = !empty($rendered_uneditable[$model->get('id')]) && $rendered_uneditable[$model->get('id')] == 2; // editable via coupon } if (!$isnew) { // EDIT action // Finally check if item is currently being checked-out (currently being edited) if ($model->isCheckedOut($user->get('id'))) { $msg = JText::sprintf('FLEXI_DESCBEINGEDITTED', $model->get('title')); $app->redirect(JRoute::_('index.php?view=' . FLEXI_ITEMVIEW . '&cid=' . $model->get('catid') . '&id=' . $model->get('id'), false), $msg); } //Checkout the item $model->checkout(); // Get edit access, this includes privileges edit and edit-own and the temporary EDIT flag ('rendered_uneditable') $canEdit = $model->getItemAccess()->get('access-edit'); // If no edit privilege, check if edit COUPON was provided if (!$canEdit) { $edittok = JRequest::getCmd('edittok', false); if ($edittok) { $query = 'SHOW TABLES LIKE "' . $app->getCfg('dbprefix') . 'flexicontent_edit_coupons"'; $db->setQuery($query); $tbl_exists = (bool) count($db->loadObjectList()); if ($tbl_exists) { $query = 'SELECT * FROM #__flexicontent_edit_coupons ' . ' WHERE token = ' . $db->Quote($edittok) . ' AND id = ' . $model->get('id'); $db->setQuery($query); $tokdata = $db->loadObject(); if ($tokdata) { $hasCoupon = true; $rendered_uneditable = $session->get('rendered_uneditable', array(), 'flexicontent'); $rendered_uneditable[$model->get('id')] = 2; // 2: indicates, that has edit via EDIT Coupon $session->set('rendered_uneditable', $rendered_uneditable, 'flexicontent'); $canEdit = 1; } else { JError::raiseNotice(403, JText::_('EDIT_TOKEN_IS_INVALID') . ' : ' . $edittok); } } } } // Edit check finished, throw error if needed if (!$canEdit) { if ($user->guest) { $uri = JFactory::getURI(); $return = $uri->toString(); $fcreturn = serialize(array('id' => @$this->_item->id, 'cid' => $cid)); // a special url parameter, used by some SEF code $com_users = FLEXI_J16GE ? 'com_users' : 'com_user'; $url = $params->get('login_page', 'index.php?option=' . $com_users . '&view=login'); $return = strtr(base64_encode($return), '+/=', '-_,'); $url .= '&return=' . $return; //$url .= '&return='.urlencode(base64_encode($return)); $url .= '&fcreturn=' . base64_encode($fcreturn); JError::raiseWarning(403, JText::sprintf("FLEXI_LOGIN_TO_ACCESS", $url)); $app->redirect($url); } else { if ($unauthorized_page) { // unauthorized page via global configuration JError::raiseNotice(403, JText::_('FLEXI_ALERTNOTAUTH_TASK')); $app->redirect($unauthorized_page); } else { // user isn't authorize to edit this content $msg = JText::_('FLEXI_ALERTNOTAUTH_TASK'); if (FLEXI_J16GE) { throw new Exception($msg, 403); } else { JError::raiseError(403, $msg); } } } } } else { // CREATE action // Get create access, this includes check of creating in at least one category, and type's "create items" $canAdd = $model->getItemAccess()->get('access-create'); $not_authorised = !$canAdd; // Check if Content Type can be created by current user if (empty($canCreateType)) { if ($new_typeid) { // not needed, already done be model when type_id is set, check and remove $canCreateType = $model->canCreateType(array($new_typeid)); // Can create given Content Type } else { // needed not done be model yet $canCreateType = $model->canCreateType(); // Can create at least one Content Type } } $not_authorised = $not_authorised || !$canCreateType; // Allow item submission by unauthorized users, ... even guests ... if ($allowunauthorize == 2) { $allowunauthorize = !$user->guest; } if ($not_authorised && !$allowunauthorize) { if (!$canCreateType) { $type_name = isset($types[$new_typeid]) ? '"' . JText::_($types[$new_typeid]->name) . '"' : JText::_('FLEXI_ANY'); $msg = JText::sprintf('FLEXI_NO_ACCESS_CREATE_CONTENT_OF_TYPE', $type_name); } else { $msg = JText::_('FLEXI_ALERTNOTAUTH_CREATE'); } } else { if ($max_auth_limit) { $db->setQuery('SELECT COUNT(id) FROM #__content WHERE created_by = ' . $user->id); $authored_count = $db->loadResult(); $content_is_limited = $authored_count >= $max_auth_limit; $msg = $content_is_limited ? JText::sprintf('FLEXI_ALERTNOTAUTH_CREATE_MORE', $max_auth_limit) : ''; } } if ($not_authorised && !$allowunauthorize || @$content_is_limited) { // User isn't authorize to add ANY content if ($notauth_menu = $app->getMenu()->getItem($notauth_itemid)) { // a. custom unauthorized submission page via menu item $internal_link_vars = @$notauth_menu->component ? '&Itemid=' . $notauth_itemid . '&option=' . $notauth_menu->component : ''; $notauthurl = JRoute::_($notauth_menu->link . $internal_link_vars, false); JError::raiseNotice(403, $msg); $app->redirect($notauthurl); } else { if ($unauthorized_page) { // b. General unauthorized page via global configuration JError::raiseNotice(403, $msg); $app->redirect($unauthorized_page); } else { // c. Finally fallback to raising a 403 Exception/Error that will redirect to site's default 403 unauthorized page if (FLEXI_J16GE) { throw new Exception($msg, 403); } else { JError::raiseError(403, $msg); } } } } } // ***************************************************************************** // Get (CORE & CUSTOM) fields and their VERSIONED values and then // (a) Apply Content Type Customization to CORE fields (label, description, etc) // (b) Create the edit html of the CUSTOM fields by triggering 'onDisplayField' // ***************************************************************************** // Check if saving an item that translates an original content in site's default language $site_default = substr(flexicontent_html::getSiteDefaultLang(), 0, 2); $is_content_default_lang = $site_default == substr($item->language, 0, 2); //$modify_untraslatable_values = $enable_translation_groups && !$is_content_default_lang; // && $item->lang_parent_id && $item->lang_parent_id!=$item->id; if ($print_logging_info) { $start_microtime = microtime(true); } $fields = $this->get('Extrafields'); $item->fields =& $fields; if ($print_logging_info) { $fc_run_times['get_field_vals'] = round(1000000 * 10 * (microtime(true) - $start_microtime)) / 10; } if ($print_logging_info) { $start_microtime = microtime(true); } $jcustom = $app->getUserState('com_flexicontent.edit.item.custom'); //print_r($jcustom); foreach ($fields as $field) { // a. Apply CONTENT TYPE customizations to CORE FIELDS, e.g a type specific label & description // NOTE: the field parameters are already created so there is not need to call this for CUSTOM fields, which do not have CONTENT TYPE customizations if ($field->iscore) { FlexicontentFields::loadFieldConfig($field, $item); } // b. Create field 's editing HTML (the form field) // NOTE: this is DONE only for CUSTOM fields, since form field html is created by the form for all CORE fields, EXCEPTION is the 'text' field (see bellow) if (!$field->iscore) { if (isset($jcustom[$field->name])) { $field->value = array(); foreach ($jcustom[$field->name] as $i => $_val) { $field->value[$i] = $_val; } } $is_editable = !$field->valueseditable || $user->authorise('flexicontent.editfieldvalues', 'com_flexicontent.field.' . $field->id); if ($is_editable) { FLEXIUtilities::call_FC_Field_Func($field->field_type, 'onDisplayField', array(&$field, &$item)); if ($field->untranslatable) { $field->html = '<div class="alert alert-info fc-small fc-iblock">' . JText::_('FLEXI_FIELD_VALUE_IS_NON_TRANSLATABLE') . '</div>' . "\n" . $field->html; } } else { if ($field->valueseditable == 1) { $field->html = '<div class="fc-mssg fc-note">' . JText::_($field->parameters->get('no_acc_msg_form') ? $field->parameters->get('no_acc_msg_form') : 'FLEXI_NO_ACCESS_LEVEL_TO_EDIT_FIELD') . '</div>'; } else { if ($field->valueseditable == 2) { FLEXIUtilities::call_FC_Field_Func($field->field_type, 'onDisplayFieldValue', array(&$field, $item)); $field->html = '<div class="fc-mssg fc-note">' . JText::_($field->parameters->get('no_acc_msg_form') ? $field->parameters->get('no_acc_msg_form') : 'FLEXI_NO_ACCESS_LEVEL_TO_EDIT_FIELD') . '</div>' . "\n" . $field->display; } else { if ($field->valueseditable == 3) { FLEXIUtilities::call_FC_Field_Func($field->field_type, 'onDisplayFieldValue', array(&$field, $item)); $field->html = $field->display; } else { if ($field->valueseditable == 4) { $field->html = ''; $field->formhidden = 4; } } } } } } // c. Create main text field, via calling the display function of the textarea field (will also check for tabs) if ($field->field_type == 'maintext') { if (isset($item->item_translations)) { $shortcode = substr($item->language, 0, 2); foreach ($item->item_translations as $lang_id => $t) { if ($shortcode == $t->shortcode) { continue; } $field->name = array('jfdata', $t->shortcode, 'text'); $field->value[0] = html_entity_decode($t->fields->text->value, ENT_QUOTES, 'UTF-8'); FLEXIUtilities::call_FC_Field_Func('textarea', 'onDisplayField', array(&$field, &$item)); $t->fields->text->tab_labels = $field->tab_labels; $t->fields->text->html = $field->html; unset($field->tab_labels); unset($field->html); } } $field->name = 'text'; // NOTE: We use the text created by the model and not the text retrieved by the CORE plugin code, which maybe overwritten with JoomFish/Falang data $field->value[0] = $item->text; // do not decode special characters this was handled during saving ! // Render the field's (form) HTML FLEXIUtilities::call_FC_Field_Func('textarea', 'onDisplayField', array(&$field, &$item)); } } if ($print_logging_info) { $fc_run_times['render_field_html'] = round(1000000 * 10 * (microtime(true) - $start_microtime)) / 10; } // Tags used by the item $usedtagsids = $this->get('UsedtagsIds'); // NOTE: This will normally return the already set versioned value of tags ($item->tags) $usedtagsdata = $model->getUsedtagsData($usedtagsids); // Get the edit lists $lists = $this->_buildEditLists($perms, $params, $authorparams); // Get number of subscribers $subscribers = $this->get('SubscribersCount'); // Get menu overridden categories/main category fields $menuCats = $this->_getMenuCats($item, $perms); // Create placement configuration for CORE properties $placementConf = $this->_createPlacementConf($item, $fields); // Item language related vars $languages = FLEXIUtilities::getLanguages(); $itemlang = new stdClass(); $itemlang->shortcode = substr($item->language, 0, 2); $itemlang->name = $languages->{$item->language}->name; $itemlang->image = '<img src="' . @$languages->{$item->language}->imgsrc . '" alt="' . $languages->{$item->language}->name . '" />'; //Load the JEditor object $editor = JFactory::getEditor(); // ********************************************************** // Calculate a (browser window) page title and a page heading // ********************************************************** // Verify menu item points to current FLEXIcontent object if ($menu) { $menu_matches = false; $view_ok = FLEXI_ITEMVIEW == @$menu->query['view'] || 'article' == @$menu->query['view']; $menu_matches = $view_ok; //$menu_params = $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 { // Calculate default page heading (=called page title in J1.5), which in turn will be document title below !! ... $default_heading = !$isnew ? JText::_('FLEXI_EDIT') : JText::_('FLEXI_NEW'); // Decide to show page heading (=J1.5 page title), there is no need for this in item view $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); } // ************************************************************ // 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 // Add Site Name to page title if ($app->getCfg('sitename_pagetitles', 0) == 1) { $doc_title = $app->getCfg('sitename') . " - " . $doc_title; } elseif ($app->getCfg('sitename_pagetitles', 0) == 2) { $doc_title = $doc_title . " - " . $app->getCfg('sitename'); } // Finally, set document title $document->setTitle($doc_title); // Add title to pathway $pathway = $app->getPathWay(); $pathway->addItem($doc_title, ''); // Get pageclass suffix $pageclass_sfx = htmlspecialchars($params->get('pageclass_sfx')); // Ensure the row data is safe html // @TODO: check if this is really required as it conflicts with the escape function in the tmpl //JFilterOutput::objectHTMLSafe( $item ); $this->assign('action', $uri->toString()); $this->assignRef('item', $item); $this->assignRef('form', $form); // most core field are created via calling methods of the form (J2.5) if ($enable_translation_groups) { $this->assignRef('lang_assocs', $langAssocs); } $this->assignRef('langs', $langs); $this->assignRef('params', $params); $this->assignRef('lists', $lists); $this->assignRef('subscribers', $subscribers); $this->assignRef('editor', $editor); $this->assignRef('user', $user); $this->assignRef('usedtagsdata', $usedtagsdata); $this->assignRef('fields', $fields); $this->assignRef('tparams', $tparams); $this->assignRef('perms', $perms); $this->assignRef('document', $document); $this->assignRef('nullDate', $nullDate); $this->assignRef('menuCats', $menuCats); $this->assignRef('submitConf', $submitConf); $this->assignRef('placementConf', $placementConf); $this->assignRef('itemlang', $itemlang); $this->assignRef('pageclass_sfx', $pageclass_sfx); $this->assign('captcha_errmsg', @$captcha_errmsg); $this->assign('captcha_field', @$captcha_field); // **************************************************************** // SET INTO THE FORM, parameter values for various parameter groups // **************************************************************** if (JHTML::_('date', $item->publish_down, 'Y') <= 1969 || $item->publish_down == $nullDate) { $item->publish_down = JText::_('FLEXI_NEVER'); } // **************************** // Handle Template related work // **************************** // (a) Get the templates structures used to create form fields for template parameters $themes = flexicontent_tmpl::getTemplates(); $tmpls_all = $themes->items; // (b) Get Content Type allowed templates $allowed_tmpls = $tparams->get('allowed_ilayouts'); $type_default_layout = $tparams->get('ilayout', 'default'); if (empty($allowed_tmpls)) { $allowed_tmpls = array(); } if (!is_array($allowed_tmpls)) { $allowed_tmpls = explode("|", $allowed_tmpls); } // (c) Add default layout, unless all templates allowed (=array is empty) if (count($allowed_tmpls) && !in_array($type_default_layout, $allowed_tmpls)) { $allowed_tmpls[] = $type_default_layout; } // (d) Create array of template data according to the allowed templates for current content type if (count($allowed_tmpls)) { foreach ($tmpls_all as $tmpl) { if (in_array($tmpl->name, $allowed_tmpls)) { $tmpls[] = $tmpl; } } } else { $tmpls = $tmpls_all; } // (e) Apply Template Parameters values into the form fields structures foreach ($tmpls as $tmpl) { if (FLEXI_J16GE) { $jform = new JForm('com_flexicontent.template.item', array('control' => 'jform', 'load_data' => true)); $jform->load($tmpl->params); $tmpl->params = $jform; foreach ($tmpl->params->getGroup('attribs') as $field) { $fieldname = $field->__get('fieldname'); $value = $item->itemparams->get($fieldname); if (strlen($value)) { $tmpl->params->setValue($fieldname, 'attribs', $value); } } } else { $tmpl->params->loadINI($item->attribs); } } $this->assignRef('tmpls', $tmpls); // Clear custom form data from session $app->setUserState($form->option . '.edit.' . $form->context . '.custom', false); $app->setUserState($form->option . '.edit.' . $form->context . '.jfdata', false); $app->setUserState($form->option . '.edit.' . $form->context . '.unique_tmp_itemid', false); if ($print_logging_info) { $start_microtime = microtime(true); } parent::display($tpl); if ($print_logging_info) { $fc_run_times['form_rendering'] = round(1000000 * 10 * (microtime(true) - $start_microtime)) / 10; } }
function getItemThumbs(&$params, &$items, $uprefix = 'item', $rprefix = 'nav') { if (!$params->get($uprefix . '_use_image', 1)) { return array(); } if (empty($items)) { return array(); } if ($params->get($uprefix . '_image')) { $img_size_map = array('l' => 'large', 'm' => 'medium', 's' => 'small', 'o' => 'original'); $img_field_size = $img_size_map[$params->get($uprefix . '_image_size', 'l')]; $img_field_name = $params->get($uprefix . '_image'); } if (!empty($img_field_name)) { //$_return = FlexicontentFields::renderFields( false, array_keys($items), array($img_field_name), FLEXI_ITEMVIEW, array('display_'.$img_field_size.'_src')); FlexicontentFields::getFieldDisplay($items, $img_field_name, $values = null, 'display_' . $img_field_size . '_src', FLEXI_ITEMVIEW); } $thumbs = array(); foreach ($items as $item_id => $item) { if (!empty($img_field_name)) { //$src = str_replace(JURI::root(), '', @ $_return[$item_id][$img_field_name] ); $img_field =& $item->fields[$img_field_name]; $src = str_replace(JURI::root(), '', @$img_field->{'display_' . $img_field_size . '_src'}); } else { $src = flexicontent_html::extractimagesrc($item); } $RESIZE_FLAG = !$params->get($uprefix . '_image') || !$params->get($uprefix . '_image_size'); if ($src && $RESIZE_FLAG) { // Resize image when src path is set and RESIZE_FLAG: (a) using image extracted from item main text OR (b) not using image field's already created thumbnails $w = '&w=' . $params->get($rprefix . '_width', 200); $h = '&h=' . $params->get($rprefix . '_height', 200); $aoe = '&aoe=1'; $q = '&q=95'; $zc = $params->get($rprefix . '_method') ? '&zc=' . $params->get($rprefix . '_method') : ''; $ext = strtolower(pathinfo($src, PATHINFO_EXTENSION)); $f = in_array($ext, array('png', 'ico', 'gif')) ? '&f=' . $ext : ''; $conf = $w . $h . $aoe . $q . $zc . $f; $base_url = !preg_match("#^http|^https|^ftp|^/#i", $src) ? JURI::base(true) . '/' : ''; $thumb = JURI::base(true) . '/components/com_flexicontent/librairies/phpthumb/phpThumb.php?src=' . $base_url . $src . $conf; } else { // Do not resize image when (a) image src path not set or (b) using image field's already created thumbnails $thumb = $src; } if ($thumb) { $thumbs[$item_id] = $thumb; } } return $thumbs; }
function display($tpl = null) { //initialise variables $app = JFactory::getApplication(); $option = JRequest::getVar('option'); $document = JFactory::getDocument(); $cparams = JComponentHelper::getParams('com_flexicontent'); $user = JFactory::getUser(); //add css to document $document->addStyleSheetVersion(JURI::base(true) . '/components/com_flexicontent/assets/css/flexicontentbackend.css', FLEXI_VHASH); $document->addStyleSheetVersion(JURI::base(true) . '/components/com_flexicontent/assets/css/j3x.css', FLEXI_VHASH); // Add JS frameworks flexicontent_html::loadFramework('select2'); // Add js function to overload the joomla submitform validation JHTML::_('behavior.formvalidation'); // load default validation JS to make sure it is overriden $document->addScriptVersion(JURI::root(true) . '/components/com_flexicontent/assets/js/admin.js', FLEXI_VHASH); $document->addScriptVersion(JURI::root(true) . '/components/com_flexicontent/assets/js/validate.js', FLEXI_VHASH); //Load pane behavior jimport('joomla.html.pane'); //Import File system jimport('joomla.filesystem.file'); //Get data from the model $model = $this->getModel(); $row = $this->get('Field'); $form = $this->get('Form'); $types = $this->get('Typeslist'); $typesselected = $this->get('Typesselected'); //create the toolbar if ($row->id) { JToolBarHelper::title(JText::_('FLEXI_EDIT_FIELD'), 'fieldedit'); } else { JToolBarHelper::title(JText::_('FLEXI_ADD_FIELD'), 'fieldadd'); } $ctrl = FLEXI_J16GE ? 'fields.' : ''; JToolBarHelper::apply($ctrl . 'apply'); JToolBarHelper::save($ctrl . 'save'); JToolBarHelper::custom($ctrl . 'saveandnew', 'savenew.png', 'savenew.png', 'FLEXI_SAVE_AND_NEW', false); JToolBarHelper::cancel($ctrl . 'cancel'); // Import Joomla plugin that implements the type of current flexi field $extfolder = 'flexicontent_fields'; $extname = $row->iscore ? 'core' : $row->field_type; JPluginHelper::importPlugin('flexicontent_fields', $row->iscore ? 'core' : $row->field_type); // Create class name of the plugin and then create a plugin instance $classname = 'plg' . ucfirst($extfolder) . $extname; // Check max allowed version if (property_exists($classname, 'prior_to_version')) { // Set a system message with warning of failed PHP limits $prior_to_version = $app->getUserStateFromRequest($option . '.flexicontent.prior_to_version_' . $row->field_type, 'prior_to_version_' . $row->field_type, 0, 'int'); $app->setUserState($option . '.flexicontent.prior_to_version_' . $row->field_type, $prior_to_version + 1); if ($prior_to_version < 2) { $close_btn = FLEXI_J30GE ? '<a class="close" data-dismiss="alert">×</a>' : '<a class="fc-close" onclick="this.parentNode.parentNode.removeChild(this.parentNode);">×</a>'; $manifest_path = JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_flexicontent' . DS . 'manifest.xml'; $com_xml = JApplicationHelper::parseXMLInstallFile($manifest_path); $ver_exceeded = version_compare(str_replace(' ', '.', $com_xml['version']), str_replace(' ', '.', $classname::$prior_to_version), '>='); if ($ver_exceeded) { echo ' <span class="fc-note fc-mssg-inline"> ' . $close_btn . ' Warning: installed version of Field: \'<b>' . $extname . '</b>\' was given to be free for FLEXIcontent versions prior to: v' . $classname::$prior_to_version . ' <br/> It may or may not work properly in later versions </span>'; } else { echo ' <span class="fc-info fc-mssg-inline"> ' . $close_btn . ' Note: installed version of Field: \'<b>' . $extname . '</b>\' is given free for FLEXIcontent versions prior to: v' . $classname::$prior_to_version . ', nevertheless it will continue to function after FLEXIcontent is upgraded. </span>'; } } } // load plugin's english language file then override with current language file $extension_name = 'plg_flexicontent_fields_' . ($row->iscore ? 'core' : $row->field_type); JFactory::getLanguage()->load($extension_name, JPATH_ADMINISTRATOR, 'en-GB', true); JFactory::getLanguage()->load($extension_name, JPATH_ADMINISTRATOR, null, true); //check which properties are supported by current field $ft_support = FlexicontentFields::getPropertySupport($row->field_type, $row->iscore); $supportsearch = $ft_support->supportsearch; $supportadvsearch = $ft_support->supportadvsearch; $supportfilter = $ft_support->supportfilter; $supportadvfilter = $ft_support->supportadvfilter; $supportuntranslatable = $ft_support->supportuntranslatable; $supportvalueseditable = $ft_support->supportvalueseditable; $supportformhidden = $ft_support->supportformhidden; $supportedithelp = $ft_support->supportedithelp; //build selectlists, (for J1.6+ most of these are defined via XML file and custom form field classes) $lists = array(); //build field_type list if (!$row->field_type) { $row->field_type = 'text'; } $_attribs = ' class="use_select2_lib fc_skip_highlight" '; if ($row->iscore == 1) { $_attribs .= ' disabled="disabled" '; } else { $_field_id = 'jform_field_type'; $_row_id = $form->getValue("id"); $_ctrl_task = 'task=fields.getfieldspecificproperties'; $document->addScriptDeclaration("\n\t\t\t\tjQuery(document).ready(function() {\n\t\t\t\t\tjQuery('#" . $_field_id . "').on('change', function() {\n\t\t\t\t\t\tjQuery('#fieldspecificproperties').html('<p class=\"centerimg\"><img src=\"components/com_flexicontent/assets/images/ajax-loader.gif\" align=\"center\"></p>');\n\t\t\t\t\t\tjQuery.ajax({\n\t\t\t\t\t\t\ttype: \"GET\",\n\t\t\t\t\t\t\turl: 'index.php?option=com_flexicontent&" . $_ctrl_task . "&cid=" . $_row_id . "&field_type='+this.value+'&format=raw',\n\t\t\t\t\t\t\tsuccess: function(str) {\n\t\t\t\t\t\t\t\tjQuery('#fieldspecificproperties').html(str);\n\t\t\t\t\t\t\t\t" . (FLEXI_J30GE ? "\n\t\t\t\t\t\t\t\t\tjQuery('.hasTooltip').tooltip({'html': true,'container': jQuery('#fieldspecificproperties')});\n\t\t\t\t\t\t\t\t" : "\n\t\t\t\t\t\t\t\tvar tipped_elements = jQuery('#fieldspecificproperties .hasTip');\n\t\t\t\t\t\t\t\ttipped_elements.each(function() {\n\t\t\t\t\t\t\t\t\tvar title = this.get('title');\n\t\t\t\t\t\t\t\t\tif (title) {\n\t\t\t\t\t\t\t\t\t\tvar parts = title.split('::', 2);\n\t\t\t\t\t\t\t\t\t\tthis.store('tip:title', parts[0]);\n\t\t\t\t\t\t\t\t\t\tthis.store('tip:text', parts[1]);\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\tvar ajax_JTooltips = new Tips(\$('fieldspecificproperties').getElements('.hasTip'), { maxTitleChars: 50, fixed: false});\n\t\t\t\t\t\t\t\t") . "\n\t\t\t\t\t\t\t\ttabberAutomatic(tabberOptions, 'fieldspecificproperties');\n\t\t\t\t\t\t\t\tfc_bindFormDependencies('#fieldspecificproperties', 0, '');\n\t\t\t\t\t\t\t\tjQuery('#field_typename').html(jQuery('#" . $_field_id . "').val());\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t});\n\t\t\t\t\t});\n\t\t\t\t});\n\t\t\t"); } //build field select list $fieldtypes = flexicontent_db::getFieldTypes($_grouped = true, $_usage = false, $_published = true); $fftypes = array(); foreach ($fieldtypes as $field_group => $ft_types) { $fftypes[] = $field_group; foreach ($ft_types as $field_type => $ftdata) { $fftypes[] = array('value' => $ftdata->field_type, 'text' => $ftdata->friendly); } $fftypes[] = ''; } $lists['field_type'] = flexicontent_html::buildfieldtypeslist($fftypes, 'jform[field_type]', $row->field_type, $_grouped ? 1 : 0, $_attribs); //build type select list $attribs = 'class="use_select2_lib" multiple="multiple" size="6"'; $attribs .= $row->iscore ? ' disabled="disabled"' : ''; $types_fieldname = FLEXI_J16GE ? 'jform[tid][]' : 'tid[]'; $lists['tid'] = flexicontent_html::buildtypesselect($types, $types_fieldname, $typesselected, false, $attribs); // ************************************************************************** // Create fields for J1.5 (J2.5+ uses JForm XML file for most of form fields) // ************************************************************************** if (!FLEXI_J16GE) { //build formhidden selector $formhidden[] = JHTML::_('select.option', 0, JText::_('FLEXI_NO')); $formhidden[] = JHTML::_('select.option', 1, JText::_('FLEXI_FRONTEND')); $formhidden[] = JHTML::_('select.option', 2, JText::_('FLEXI_BACKEND')); $formhidden[] = JHTML::_('select.option', 3, JText::_('FLEXI_BOTH')); $formhidden_fieldname = FLEXI_J16GE ? 'jform[formhidden]' : 'formhidden'; $lists['formhidden'] = JHTML::_('select.radiolist', $formhidden, $formhidden_fieldname, '', 'value', 'text', $row->formhidden); if (FLEXI_ACCESS) { $valueseditable[] = JHTML::_('select.option', 0, JText::_('FLEXI_ANY_EDITOR')); $valueseditable[] = JHTML::_('select.option', 1, JText::_('FLEXI_USE_ACL_PERMISSION')); $valueseditable_fieldname = FLEXI_J16GE ? 'jform[valueseditable]' : 'valueseditable'; $lists['valueseditable'] = JHTML::_('select.radiolist', $valueseditable, $valueseditable_fieldname, '', 'value', 'text', $row->valueseditable); } $edithelp[] = JHTML::_('select.option', 0, JText::_('FLEXI_EDIT_HELP_NONE')); $edithelp[] = JHTML::_('select.option', 1, JText::_('FLEXI_EDIT_HELP_LABEL_TOOLTIP')); $edithelp[] = JHTML::_('select.option', 2, JText::_('FLEXI_EDIT_HELP_LABEL_TOOLTIP_WICON')); $edithelp[] = JHTML::_('select.option', 3, JText::_('FLEXI_EDIT_HELP_INLINE')); $edithelp_fieldname = FLEXI_J16GE ? 'jform[edithelp]' : 'edithelp'; $lists['edithelp'] = JHTML::_('select.radiolist', $edithelp, $edithelp_fieldname, '', 'value', 'text', $row->edithelp); // build the html select list for ordering $query = 'SELECT ordering AS value, label AS text' . ' FROM #__flexicontent_fields' . ' WHERE published >= 0' . ' ORDER BY ordering'; $row->ordering = @$row->ordering; $lists['ordering'] = $row->id ? JHTML::_('list.specificordering', $row, $row->id, $query) : JHTML::_('list.specificordering', $row, '', $query); //build access level list if (FLEXI_ACCESS) { $lang = JFactory::getLanguage(); $lang->_strings['FLEXIACCESS_PADD'] = 'Edit-Value'; $lists['access'] = FAccess::TabGmaccess($row, 'field', 1, 1, 0, 1, 0, 1, 0, 1, 1); } else { $lists['access'] = JHTML::_('list.accesslevel', $row); } } if (!FLEXI_J16GE) { // Create the parameter 's form object parsing the file XML $pluginpath = JPATH_PLUGINS . DS . 'flexicontent_fields' . DS . $row->field_type . '.xml'; if (JFile::exists($pluginpath)) { $form = new JParameter('', $pluginpath); } else { $form = new JParameter('', JPATH_PLUGINS . DS . 'flexicontent_fields' . DS . 'core.xml'); } // Special and Core Groups $form->loadINI($row->attribs); } // fail if checked out not by 'me' if ($row->id) { if ($model->isCheckedOut($user->get('id'))) { JError::raiseWarning('SOME_ERROR_CODE', $row->name . ' ' . JText::_('FLEXI_EDITED_BY_ANOTHER_ADMIN')); $app->redirect('index.php?option=com_flexicontent&view=fields'); } } //clean data JFilterOutput::objectHTMLSafe($row, ENT_QUOTES); // assign permissions for J2.5 $permission = FlexicontentHelperPerm::getPerm(); $this->assignRef('permission', $permission); //assign data to template $this->assignRef('document', $document); $this->assignRef('row', $row); $this->assignRef('lists', $lists); $this->assignRef('form', $form); $this->assignRef('typesselected', $typesselected); $this->assignRef('supportsearch', $supportsearch); $this->assignRef('supportadvsearch', $supportadvsearch); $this->assignRef('supportfilter', $supportfilter); $this->assignRef('supportadvfilter', $supportadvfilter); $this->assignRef('supportuntranslatable', $supportuntranslatable); $this->assignRef('supportvalueseditable', $supportvalueseditable); $this->assignRef('supportformhidden', $supportformhidden); $this->assignRef('supportedithelp', $supportedithelp); parent::display($tpl); }
/** * Search method * * The sql must return the following fields that are used in a common display routine: * * href, title, section, created, text, browsernav * * @param string Target search string * @param string matching option, natural|natural_expanded|exact|any|all * @param string ordering option, newest|oldest|popular|alpha|category * @param mixed An array if restricted to areas, null if search all */ function onContentSearch($text, $phrase = '', $ordering = '', $areas = null) { $app = JFactory::getApplication(); $view = JRequest::getCMD('view'); $app->setUserState('fc_view_total_' . $view, 0); $app->setUserState('fc_view_limit_max_' . $view, 0); // Check if not requested search areas, inside this search areas of this plugin if (is_array($areas) && !array_intersect($areas, array_keys($this->onContentSearchAreas()))) { return array(); } // Initialize some variables $db = JFactory::getDBO(); $user = JFactory::getUser(); $menu = $app->getMenu()->getActive(); // Get the COMPONENT only parameters and merge current menu item parameters $params = clone JComponentHelper::getParams('com_flexicontent'); if ($menu) { $params->merge($menu->params); } // some parameter shortcuts for SQL query $show_noauth = $params->get('show_noauth', 0); $orderby_override = $params->get('orderby_override', 1); // Compatibility text search (LIKE %word%) for language without spaces $filter_word_like_any = $params->get('filter_word_like_any', 0); // ************************************************ // some parameter shortcuts common with search view // ************************************************ $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; // ******************************************************************** // 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(); } } // ********************** // Load Plugin parameters // ********************** $plugin = JPluginHelper::getPlugin('search', 'flexiadvsearch'); $pluginParams = new JRegistry($plugin->params); // Shortcuts for plugin parameters $search_limit = $params->get('search_limit', $pluginParams->get('search_limit', 20)); // Limits the returned results of this seach plugin $filter_lang = $params->get('filter_lang', $pluginParams->get('filter_lang', 1)); // Language filtering enabled $search_archived = $params->get('search_archived', $pluginParams->get('search_archived', 1)); // Include archive items into the search $browsernav = $params->get('browsernav', $pluginParams->get('browsernav', 2)); // Open search in window (for value 1) // *************************************************************************************************************** // Varous other variable USED in the SQL query like (a) current frontend language and (b) -this- plugin specific ordering, (c) null / now dates, (d) etc // *************************************************************************************************************** // Get current frontend language (fronted user selected) $lang = flexicontent_html::getUserCurrentLang(); // NULL and CURRENT dates, // NOTE: the current date needs to use built-in MYSQL function, otherwise filter caching can not work because the CURRENT DATETIME is continuously different !!! //$now = JFactory::getDate()->toSql(); $_nowDate = 'UTC_TIMESTAMP()'; //$db->Quote($now); $nullDate = $db->getNullDate(); // Section name $searchFlexicontent = JText::_('FLEXICONTENT'); // REMOVED / COMMENTED OUT this feature: // Require any OR all Filters ... this can be user selectable //$show_filtersop = $params->get('show_filtersop', 1); //$default_filtersop = $params->get('default_filtersop', 'all'); //$FILTERSOP = !$show_filtersop ? $default_filtersop : JRequest::getVar('filtersop', $default_filtersop); // **************************************** // Create WHERE clause part for Text Search // **************************************** $si_tbl = !$txtmode ? 'flexicontent_items_ext' : 'flexicontent_advsearch_index'; $search_prefix = JComponentHelper::getParams('com_flexicontent')->get('add_search_prefix') ? 'vvv' : ''; // SEARCH WORD Prefix $text = preg_replace('/(\\b[^\\s,\\.]+\\b)/u', $search_prefix . '$0', trim($text)); if (strlen($text)) { $ts = !$txtmode ? 'ie' : 'ts'; $escaped_text = $db->escape($text, true); $quoted_text = $db->Quote($escaped_text, false); switch ($phrase) { case 'natural': if ($filter_word_like_any) { $_text_match = ' LOWER (' . $ts . '.search_index) LIKE ' . $db->Quote('%' . $escaped_text . '%', false); } else { $_text_match = ' MATCH (' . $ts . '.search_index) AGAINST (' . $quoted_text . ') '; } break; case 'natural_expanded': $_text_match = ' MATCH (' . $ts . '.search_index) AGAINST (' . $quoted_text . ' WITH QUERY EXPANSION) '; break; case 'exact': $words = preg_split('/\\s\\s*/u', $text); $stopwords = array(); $shortwords = array(); if (!$search_prefix) { $words = flexicontent_db::removeInvalidWords($words, $stopwords, $shortwords, $si_tbl, 'search_index', $isprefix = 0); } if (empty($words)) { // All words are stop-words or too short, we could try to execute a query that only contains a LIKE %...% , but it would be too slow JRequest::setVar('ignoredwords', implode(' ', $stopwords)); JRequest::setVar('shortwords', implode(' ', $shortwords)); $_text_match = ' 0=1 '; } else { // speed optimization ... 2-level searching: first require ALL words, then require exact text $newtext = '+' . implode(' +', $words); $quoted_text = $db->escape($newtext, true); $quoted_text = $db->Quote($quoted_text, false); $exact_text = $db->Quote('%' . $escaped_text . '%', false); $_text_match = ' MATCH (' . $ts . '.search_index) AGAINST (' . $quoted_text . ' IN BOOLEAN MODE) AND ' . $ts . '.search_index LIKE ' . $exact_text; } break; case 'all': $words = preg_split('/\\s\\s*/u', $text); $stopwords = array(); $shortwords = array(); if (!$search_prefix) { $words = flexicontent_db::removeInvalidWords($words, $stopwords, $shortwords, $si_tbl, 'search_index', $isprefix = 1); } JRequest::setVar('ignoredwords', implode(' ', $stopwords)); JRequest::setVar('shortwords', implode(' ', $shortwords)); $newtext = '+' . implode('* +', $words) . '*'; $quoted_text = $db->escape($newtext, true); $quoted_text = $db->Quote($quoted_text, false); $_text_match = ' MATCH (' . $ts . '.search_index) AGAINST (' . $quoted_text . ' IN BOOLEAN MODE) '; break; case 'any': default: if ($filter_word_like_any) { $_text_match = ' LOWER (' . $ts . '.search_index) LIKE ' . $db->Quote('%' . $escaped_text . '%', false); } else { $words = preg_split('/\\s\\s*/u', $text); $stopwords = array(); $shortwords = array(); if (!$search_prefix) { $words = flexicontent_db::removeInvalidWords($words, $stopwords, $shortwords, $si_tbl, 'search_index', $isprefix = 1); } JRequest::setVar('ignoredwords', implode(' ', $stopwords)); JRequest::setVar('shortwords', implode(' ', $shortwords)); $newtext = implode('* ', $words) . '*'; $quoted_text = $db->escape($newtext, true); $quoted_text = $db->Quote($quoted_text, false); $_text_match = ' MATCH (' . $ts . '.search_index) AGAINST (' . $quoted_text . ' IN BOOLEAN MODE) '; } break; } // Construct TEXT SEARCH limitation SUB-QUERY (contained in a AND-WHERE clause) $text_where = ' AND ' . $_text_match; } else { $text_where = ''; } // ******************* // Create ORDER clause // ******************* // FLEXIcontent search view, use FLEXIcontent ordering $orderby_join = ''; $orderby_col = ''; if (JRequest::getVar('option') == 'com_flexicontent') { $order = ''; $orderby = flexicontent_db::buildItemOrderBy($params, $order, $_request_var = 'orderby', $_config_param = 'orderby', $_item_tbl_alias = 'i', $_relcat_tbl_alias = 'rel', $_default_order = '', $_default_order_dir = '', $sfx = '', $support_2nd_lvl = false); // Create JOIN for ordering items by a custom field (Level 1) if ('field' == $order[1]) { $orderbycustomfieldid = (int) $params->get('orderbycustomfieldid', 0); $orderby_join .= ' LEFT JOIN #__flexicontent_fields_item_relations AS f ON f.item_id = i.id AND f.field_id=' . $orderbycustomfieldid; } // Create JOIN for ordering items by a custom field (Level 2) if ('field' == $order[2]) { $orderbycustomfieldid_2nd = (int) $params->get('orderbycustomfieldid' . '_2nd', 0); $orderby_join .= ' LEFT JOIN #__flexicontent_fields_item_relations AS f2 ON f2.item_id = i.id AND f2.field_id=' . $orderbycustomfieldid_2nd; } // Create JOIN for ordering items by author's name if (in_array('author', $order) || in_array('rauthor', $order)) { $orderby_col = ''; $orderby_join .= ' LEFT JOIN #__users AS u ON u.id = i.created_by'; } // Create JOIN for ordering items by a most commented if (in_array('commented', $order)) { $orderby_col = ', count(com.object_id) AS comments_total'; $orderby_join .= ' LEFT JOIN #__jcomments AS com ON com.object_id = i.id'; } // Create JOIN for ordering items by a most rated if (in_array('rated', $order)) { $orderby_col = ', (cr.rating_sum / cr.rating_count) * 20 AS votes'; $orderby_join .= ' LEFT JOIN #__content_rating AS cr ON cr.content_id = i.id'; } // Create JOIN for ordering items by their ordering attribute (in item's main category) if (in_array('order', $order)) { $orderby_join .= ' LEFT JOIN #__flexicontent_cats_item_relations AS rel ON rel.itemid = i.id AND rel.catid = i.catid'; } } else { switch ($ordering) { //case 'relevance': $orderby = ' ORDER BY score DESC, i.title ASC'; break; case 'oldest': $orderby = 'i.created ASC'; break; case 'popular': $orderby = 'i.hits DESC'; break; case 'alpha': $orderby = 'i.title ASC'; break; case 'category': $orderby = 'c.title ASC, i.title ASC'; break; case 'newest': $orderby = 'i.created DESC'; break; default: $orderby = 'i.created DESC'; break; } $orderby = ' ORDER BY ' . $orderby; } // **************************************************************************************** // Create JOIN clause and WHERE clause part for filtering by current (viewing) access level // **************************************************************************************** $joinaccess = ''; $andaccess = ''; $select_access = ''; // Extra access columns for main category and content type (item access will be added as 'access') $select_access .= ', c.access as category_access, ty.access as type_access'; if (!$show_noauth) { // User not allowed to LIST unauthorized items $aid_arr = JAccess::getAuthorisedViewLevels($user->id); $aid_list = implode(",", $aid_arr); $andaccess .= ' AND ty.access IN (0,' . $aid_list . ')'; $andaccess .= ' AND c.access IN (0,' . $aid_list . ')'; $andaccess .= ' AND i.access IN (0,' . $aid_list . ')'; $select_access .= ', 1 AS has_access'; } else { // Access Flags for: content type, main category, item $aid_arr = JAccess::getAuthorisedViewLevels($user->id); $aid_list = implode(",", $aid_arr); $select_access .= ', ' . ' CASE WHEN ' . ' ty.access IN (' . $aid_list . ') AND ' . ' c.access IN (' . $aid_list . ') AND ' . ' i.access IN (' . $aid_list . ') ' . ' THEN 1 ELSE 0 END AS has_access'; } // ********************************************************************************************************************************************************** // Create WHERE clause part for filtering by current active language, and current selected contend types ( !! although this is possible via a filter too ...) // ********************************************************************************************************************************************************** $andlang = ''; if ($app->isSite() && (FLEXI_FISH || FLEXI_J16GE && $app->getLanguageFilter()) && $filter_lang) { $andlang .= ' AND ( ie.language LIKE ' . $db->Quote($lang . '%') . (FLEXI_J16GE ? ' OR ie.language="*" ' : '') . ' ) '; } // Filter by currently selected content types $andcontenttypes = count($contenttypes) ? ' AND ie.type_id IN (' . implode(",", $contenttypes) . ') ' : ''; // *********************************************************************** // Create the AND-WHERE clause parts for the currentl active Field Filters // *********************************************************************** $return_sql = 2; $filters_where = array(); foreach ($filters as $field) { // Get value of current filter, and SKIP it if value is EMPTY $filtervalue = JRequest::getVar('filter_' . $field->id, ''); $empty_filtervalue_array = is_array($filtervalue) && !strlen(trim(implode('', $filtervalue))); $empty_filtervalue_string = !is_array($filtervalue) && !strlen(trim($filtervalue)); if ($empty_filtervalue_array || $empty_filtervalue_string) { continue; } // Call field filtering of advanced search to find items matching the field filter (an SQL SUB-QUERY is returned) $field_filename = $field->iscore ? 'core' : $field->field_type; $filtered = FLEXIUtilities::call_FC_Field_Func($field_filename, 'getFilteredSearch', array(&$field, &$filtervalue, &$return_sql)); // An empty return value means no matching values were found $filtered = empty($filtered) ? ' AND 0 ' : $filtered; // A string mean a subquery was returned, while an array means that item ids we returned $filters_where[$field->id] = is_array($filtered) ? ' AND i.id IN (' . implode(',', $filtered) . ')' : $filtered; /*if ($filters_where[$field->id]) { echo "\n<br/>Filter:". $field->name ." : "; print_r($filtervalue); echo "<br>".$filters_where[$field->id]."<br/>"; }*/ } //echo "\n<br/><br/>Filters Active: ". count($filters_where)."<br/>"; //echo "<pre>"; print_r($filters_where); //exit; // ****************************************************** // Create Filters JOIN clauses and AND-WHERE clause parts // ****************************************************** // JOIN clause - USED - to limit returned 'text' to the text of TEXT-SEARCHABLE only fields ... (NOT shared with filters) if (!$txtmode) { $onBasic_textsearch = $text_where; $onAdvanced_textsearch = ''; $join_textsearch = ''; $join_textfields = ''; } else { $onBasic_textsearch = ''; $onAdvanced_textsearch = $text_where; $join_textsearch = ' JOIN #__flexicontent_advsearch_index as ts ON ts.item_id = i.id ' . (count($fields_text) ? 'AND ts.field_id IN (' . implode(',', array_keys($fields_text)) . ')' : ''); $join_textfields = ' JOIN #__flexicontent_fields as f ON f.id=ts.field_id'; } // JOIN clauses ... (shared with filters) $join_clauses = '' . ' JOIN #__categories AS c ON c.id = i.catid' . ' JOIN #__flexicontent_items_ext AS ie ON ie.item_id = i.id' . ' JOIN #__flexicontent_types AS ty ON ie.type_id = ty.id'; $join_clauses_with_text = '' . ' JOIN #__categories AS c ON c.id = i.catid' . ' JOIN #__flexicontent_items_ext AS ie ON ie.item_id = i.id' . $onBasic_textsearch . ' JOIN #__flexicontent_types AS ty ON ie.type_id = ty.id' . ($text_where ? $join_textsearch . $onAdvanced_textsearch . $join_textfields : ''); // AND-WHERE sub-clauses ... (shared with filters) $where_conf = ' WHERE 1 ' . ' AND i.state IN (1,-5' . ($search_archived ? ',' . (FLEXI_J16GE ? 2 : -1) : '') . ') ' . ' AND c.published = 1 ' . ' AND ( i.publish_up = ' . $db->Quote($nullDate) . ' OR i.publish_up <= ' . $_nowDate . ' )' . ' AND ( i.publish_down = ' . $db->Quote($nullDate) . ' OR i.publish_down >= ' . $_nowDate . ' )' . $andaccess . $andlang . $andcontenttypes; // AND-WHERE sub-clauses for text search ... (shared with filters) $and_where_filters = count($filters_where) ? implode(" ", $filters_where) : ''; // ************************************************ // Set variables used by filters creation mechanism // ************************************************ global $fc_searchview; $fc_searchview['join_clauses'] = $join_clauses; $fc_searchview['join_clauses_with_text'] = $join_clauses_with_text; $fc_searchview['where_conf_only'] = $where_conf; // WHERE of the view (mainly configuration dependent) $fc_searchview['filters_where'] = $filters_where; // WHERE of the filters $fc_searchview['search'] = $text_where; // WHERE for text search $fc_searchview['params'] = $params; // view's parameters // ***************************************************************************************************** // Execute search query. NOTE this is skipped it if (a) no text-search and no (b) no filters are active // ***************************************************************************************************** // Do not check for 'contentypes' this are based on configuration and not on form submitted data, // considering contenttypes or other configuration based parameters, will return all items on initial search view display ! if (!count($filters_where) && !strlen($text)) { return array(); } $print_logging_info = $params->get('print_logging_info'); if ($print_logging_info) { global $fc_run_times; $start_microtime = microtime(true); } // ***************************************** // Overcome possible group concat limitation // ***************************************** $query = "SET SESSION group_concat_max_len = 9999999"; $db->setQuery($query); $db->execute(); // ************* // Get the items // ************* $query = 'SELECT SQL_CALC_FOUND_ROWS i.id' . $orderby_col . ' FROM #__content AS i' . $join_clauses_with_text . $orderby_join . $joinaccess . $where_conf . $and_where_filters . ' GROUP BY i.id ' . $orderby; //echo "Adv search plugin main SQL query: ".nl2br($query)."<br/><br/>"; // NOTE: The plugin will return a PRECONFIGURED limited number of results, the SEARCH VIEW to do the pagination, splicing (appropriately) the data returned by all search plugins try { // Get items, we use direct query because some extensions break the SQL_CALC_FOUND_ROWS, so let's bypass them (at this point it is OK) // *** Usage of FOUND_ROWS() will fail when (e.g.) Joom!Fish or Falang are installed, in this case we will be forced to re-execute the query ... // PLUS, we don't need Joom!Fish or Falang layer at --this-- STEP which may slow down the query considerably in large sites $query_limited = $query . ' LIMIT ' . $search_limit . ' OFFSET 0'; $rows = flexicontent_db::directQuery($query_limited); $item_ids = array(); foreach ($rows as $row) { $item_ids[] = $row->id; } // Get current items total for pagination $db->setQuery("SELECT FOUND_ROWS()"); $fc_searchview['view_total'] = $db->loadResult(); $app->setUserState('fc_view_total_' . $view, $fc_searchview['view_total']); } catch (Exception $e) { // Get items via normal joomla SQL layer $db->setQuery(str_replace('SQL_CALC_FOUND_ROWS', '', $query), 0, $search_limit); $item_ids = $db->loadColumn(0); } if (!count($item_ids)) { return array(); } // No items found // ***************** // Get the item data // ***************** $query_data = 'SELECT i.id, i.title AS title, i.created, i.id AS fc_item_id, i.access, ie.type_id, i.language' . (!$txtmode ? ', ie.search_index AS text' : ', GROUP_CONCAT(ts.search_index ORDER BY f.ordering ASC SEPARATOR \' \') AS text') . ', CASE WHEN CHAR_LENGTH(i.alias) THEN CONCAT_WS(\':\', i.id, i.alias) ELSE i.id END as slug' . ', CASE WHEN CHAR_LENGTH(c.alias) THEN CONCAT_WS(\':\', c.id, c.alias) ELSE c.id END as categoryslug' . ', CONCAT_WS( " / ", ' . $db->Quote($searchFlexicontent) . ', c.title, i.title ) AS section' . $select_access . ' FROM #__content AS i' . $join_clauses . $join_textsearch . $join_textfields . ' WHERE i.id IN (' . implode(',', $item_ids) . ') ' . ' GROUP BY i.id ' . ' ORDER BY FIELD(i.id, ' . implode(',', $item_ids) . ')'; //echo nl2br($query)."<br/><br/>"; $db->setQuery($query_data); $list = $db->loadObjectList(); if ($db->getErrorNum()) { echo $db->getErrorMsg(); } if ($print_logging_info) { @($fc_run_times['search_query_runtime'] += round(1000000 * 10 * (microtime(true) - $start_microtime)) / 10); } // ************************************* // Create item links and other variables // ************************************* //echo "<pre>"; print_r($list); echo "</pre>"; if ($list) { if (count($list) >= $search_limit) { $app->setUserState('fc_view_limit_max_' . $view, $search_limit); } $item_cats = FlexicontentFields::_getCategories($list); foreach ($list as $key => $item) { $item->text = preg_replace('/\\b' . $search_prefix . '/', '', $item->text); $item->categories = isset($item_cats[$item->id]) ? $item_cats[$item->id] : array(); // in case of item categories missing // If joomla article view is allowed allowed and then search view may optional create Joomla article links if ($typeData[$item->type_id]->params->get('allow_jview', 0) && $typeData[$item->type_id]->params->get('search_jlinks', 1)) { $item->href = JRoute::_(ContentHelperRoute::getArticleRoute($item->slug, $item->categoryslug, $item->language)); } else { $item->href = JRoute::_(FlexicontentHelperRoute::getItemRoute($item->slug, $item->categoryslug, 0, $item)); } $item->browsernav = $browsernav; } } return $list; }
/** * Method to toggle the given property of given field * * @access public * @return boolean True on success * @since 1.0 */ function toggleprop($cid = array(), $propname = null, &$unsupported = 0, &$locked = 0) { if (!$propname) { return false; } $user = JFactory::getUser(); $affected = 0; if (count($cid)) { // Get fields information from DB $query = 'SELECT field_type, iscore, id' . ' FROM #__flexicontent_fields' . ' WHERE id IN (' . implode(',', $cid) . ') '; $this->_db->setQuery($query); $rows = $this->_db->loadObjectList('id'); // Calculate fields not supporting the property $support_ids = array(); $supportprop_name = 'support' . str_replace('is', '', $propname); foreach ($rows as $id => $row) { $ft_support = FlexicontentFields::getPropertySupport($row->field_type, $row->iscore); $supportprop = isset($ft_support->{$supportprop_name}) ? $ft_support->{$supportprop_name} : false; if ($supportprop) { $support_ids[] = $id; } } $unsupported = count($cid) - count($support_ids); // Check that at least one field that supports the property was found if (!count($support_ids)) { return 0; } // Some fields are marked as 'dirty' $dirty_properties = array('issearch', 'isadvsearch', 'isadvfilter'); $set_clause = in_array($propname, $dirty_properties) ? ' SET ' . $propname . ' = CASE ' . $propname . ' WHEN 2 THEN -1 WHEN -1 THEN 2 WHEN 1 THEN -1 WHEN 0 THEN 2 END' : ' SET ' . $propname . ' = 1-' . $propname; // Toggle the property for fields supporting the property $query = 'UPDATE #__flexicontent_fields' . $set_clause . ' WHERE id IN (' . implode(",", $support_ids) . ')' . ' AND ( checked_out = 0 OR ( checked_out = ' . (int) $user->get('id') . ' ) )'; $this->_db->setQuery($query); if (!($result = $this->_db->execute())) { $this->setError($this->_db->getErrorMsg()); return false; } // Get affected fields, non affected fields must have been locked by another user $affected = $this->_db->getAffectedRows(); $locked = count($support_ids) - $affected; } return $affected; }
function onIndexSearch(&$field, &$post, &$item) { if (!in_array($field->field_type, self::$field_types)) { return; } if (!$field->issearch) { return; } $field->isindexed = true; $field->extra_props = self::$extra_props; FlexicontentFields::onIndexSearch($field, $post, $item, $required_properties = array(), $search_properties = array('text'), $properties_spacer = ' ', $filter_func = null); return true; }
/** * Creates the RSS for the View * * @since 1.0 */ function display($tpl = null) { $db = JFactory::getDBO(); $doc = JFactory::getDocument(); $app = JFactory::getApplication(); $params = $this->get('Params'); $doc->link = JRoute::_(FlexicontentHelperRoute::getCategoryRoute(JRequest::getVar('cid', null, '', 'int'))); $category = $this->get('Category'); // Prepare query to match feed data JRequest::setVar('limit', $params->get('feed_limit')); // Force a specific limit, this will be moved to the model $params->set('orderby', $params->get('feed_orderby', 'rdate')); $params->set('orderbycustomfield', $params->get('feed_orderbycustomfield', 1)); $params->set('orderbycustomfieldid', $params->get('feed_orderbycustomfieldid', 0)); $params->set('orderbycustomfielddir', $params->get('feed_orderbycustomfielddir', 'ASC')); $params->set('orderbycustomfieldint', $params->get('feed_orderbycustomfieldint', 0)); $params->set('orderby_2nd', $params->get('feed_orderby', 'alpha')); $params->set('orderbycustomfield_2nd', $params->get('feed_orderbycustomfield_2nd', 1)); $params->set('orderbycustomfieldid_2nd', $params->get('feed_orderbycustomfieldid_2nd', 0)); $params->set('orderbycustomfielddir_2nd', $params->get('feed_orderbycustomfielddir_2nd', 'ASC')); $params->set('orderbycustomfieldint_2nd', $params->get('feed_orderbycustomfieldint_2nd', 0)); $model = $this->getModel(); $model->setState('limit', $params->get('feed_limit', $model->getState('limit'))); $rows = $this->get('Data'); $feed_summary = $params->get('feed_summary', 0); $feed_summary_cut = $params->get('feed_summary_cut', 200); $feed_use_image = $params->get('feed_use_image', 1); $feed_link_image = $params->get('feed_link_image', 1); $feed_image_source = $params->get('feed_image_source', ''); $feed_image_size = $params->get('feed_image_size', ''); $feed_image_method = $params->get('feed_image_method', 1); $feed_image_width = $params->get('feed_image_width', 100); $feed_image_height = $params->get('feed_image_height', 80); // Retrieve default image for the image field if ($feed_use_image && $feed_image_source) { $query = 'SELECT attribs, name FROM #__flexicontent_fields WHERE id = ' . (int) $feed_image_source; $db->setQuery($query); $image_dbdata = $db->loadObject(); //$image_dbdata->params = FLEXI_J16GE ? new JRegistry($image_dbdata->params) : new JParameter($image_dbdata->params); $img_size_map = array('l' => 'large', 'm' => 'medium', 's' => 'small', '' => ''); $img_field_size = $img_size_map[$feed_image_size]; $img_field_name = $image_dbdata->name; } // TODO render and add extra fields here ... maybe via special display function for feeds view $extra_fields = $params->get('feed_extra_fields', ''); $extra_fields = array_unique(preg_split("/\\s*,\\s*/u", $extra_fields)); if ($extra_fields) { foreach ($extra_fields as $fieldname) { // Render given field for ALL ITEMS FlexicontentFields::getFieldDisplay($rows, $fieldname, $values = null, $method = 'display'); } } foreach ($rows as $row) { // strip html from feed item title $title = $this->escape($row->title); $title = html_entity_decode($title); // url link to article // & used instead of & as this is converted by feed creator $link = JRoute::_(FlexicontentHelperRoute::getItemRoute($row->slug, $category->slug, 0, $row)); // strip html from feed item description text $description = $feed_summary ? $row->introtext . $row->fulltext : $row->introtext; $description = flexicontent_html::striptagsandcut($description, $feed_summary_cut); if ($feed_use_image) { // feed image is enabled $src = ''; $thumb = ''; if ($feed_image_source) { // case 1 use an image field FlexicontentFields::getFieldDisplay($row, $img_field_name, null, 'display', 'module'); $img_field = $row->fields[$img_field_name]; if (!$img_field_size) { $src = str_replace(JURI::root(), '', $img_field->thumbs_src['large'][0]); } else { $src = ''; $thumb = $img_field->thumbs_src[$img_field_size][0]; } } else { // case 2 extract from item $src = flexicontent_html::extractimagesrc($row); } $RESIZE_FLAG = !$feed_image_source || !$img_field_size; if ($src && $RESIZE_FLAG) { // Resize image when src path is set and RESIZE_FLAG: (a) using image extracted from item main text OR (b) not using image field's already created thumbnails $h = '&h=' . $feed_image_height; $w = '&w=' . $feed_image_width; $aoe = '&aoe=1'; $q = '&q=95'; $zc = $feed_image_method ? '&zc=' . $feed_image_method : ''; $ext = pathinfo($src, PATHINFO_EXTENSION); $f = in_array($ext, array('png', 'ico', 'gif')) ? '&f=' . $ext : ''; $conf = $w . $h . $aoe . $q . $zc . $f; $base_url = !preg_match("#^http|^https|^ftp|^/#i", $src) ? JURI::base(true) . '/' : ''; $thumb = JURI::base(true) . '/components/com_flexicontent/librairies/phpthumb/phpThumb.php?src=' . $base_url . $src . $conf; } else { // Do not resize image when (a) image src path not set or (b) using image field's already created thumbnails } if ($thumb) { $description = "\n\t \t\t\t<div class='feed-description'>\n\t\t \t\t\t<a class='feed-readmore' target='_blank' href='" . $link . "'>\n\t\t \t\t\t\t<img src='" . $thumb . "' alt='" . $title . "' title='" . $title . "' align='left'/>\n\t\t \t\t\t</a>\n\t\t \t\t\t<p>" . $description . "</p>\n\t\t \t\t</div>"; } } if ($extra_fields) { foreach ($extra_fields as $fieldname) { if ($row->fields[$fieldname]->display) { $description .= '<br/><b>' . $row->fields[$fieldname]->label . ":</b> " . $row->fields[$fieldname]->display; } } } //$author = $row->created_by_alias ? $row->created_by_alias : $row->author; @($date = $row->created ? date('r', strtotime($row->created)) : ''); // load individual item creator class $item = new JFeedItem(); $item->title = $title; $item->link = $link; $item->description = $description; $item->date = $date; //$item->author = $author; $item->category = $this->escape($category->title); // loads item info into rss array $doc->addItem($item); } }
function renderFields($context, &$row, &$params, $page = 0) { JTable::addIncludePath(JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_flexicontent' . DS . 'tables'); require_once JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_flexicontent' . DS . 'defineconstants.php'; require_once JPATH_SITE . DS . 'components' . DS . 'com_flexicontent' . DS . 'classes' . DS . 'flexicontent.fields.php'; require_once JPATH_SITE . DS . 'components' . DS . 'com_flexicontent' . DS . 'classes' . DS . 'flexicontent.helper.php'; require_once JPATH_SITE . DS . 'components' . DS . 'com_flexicontent' . DS . 'helpers' . DS . 'permission.php'; require_once JPATH_SITE . DS . 'components' . DS . 'com_flexicontent' . DS . 'models' . DS . FLEXI_ITEMVIEW . '.php'; $app = JFactory::getApplication(); $user = JFactory::getUser(); $aid = JAccess::getAuthorisedViewLevels($user->id); $itemmodel = new FlexicontentModelItem(); $item = $itemmodel->getItem($row->id, $check_view_access = false); $view = 'com_content.article' ? FLEXI_ITEMVIEW : 'category'; $items = FlexicontentFields::getFields($item, $view, $_item_params = null, $aid = null, $use_tmpl = false); // $_item_params == null means only retrieve fields // Only Render custom fields $displayed_fields = array(); foreach ($item->fields as $field) { if ($field->iscore) { continue; } $displayed_fields[$field->name] = $field; $values = isset($item->fieldvalues[$field->id]) ? $item->fieldvalues[$field->id] : array(); FlexicontentFields::renderField($item, $field, $values, $method = 'display', $view); } if (!count($displayed_fields)) { return null; } // Render the list of groups $field_html = array(); foreach ($displayed_fields as $field_name => $field) { $_values = null; if (!isset($field->display)) { continue; } $field_html[] = ' <div class="fc-field-box"> ' . ($field->parameters->get('display_label') ? ' <span class="flexi label">' . $field->label . '</span>' : '') . ' <div class="flexi value">' . $field->display . '</div> </div> '; } $_display = '<div class="fc-custom-fields-box">' . implode('', $field_html) . '</div>'; return $_display; }
// *************************************** // Total performance stats of current view // *************************************** $app = JFactory::getApplication(); $_view = JRequest::getWord('view', 'flexicontent'); $_layout = JRequest::getWord('layout', ''); if ($task) { $_msg = ' (TASK: ' . (!FLEXI_J16GE ? $ctrlname . '.' : '') . $task . ')'; } else { $_msg = ' (VIEW: ' . $_view . ($_layout ? ' -- LAYOUT: ' . $_layout : '') . ')'; } // ************************************** // Various Partial time performance stats // ************************************** $fields_render_total = 0; $fields_render_times = FlexicontentFields::getFieldRenderTimes($fields_render_total); $fc_jprof->mark('END: FLEXIcontent component: ' . $_msg); $msg = '<div style="font-family:tahoma!important; font-size:11px!important;">' . implode('<br/>', $fc_jprof->getbuffer()) . '</div>'; $msg .= '<div style="font-family:tahoma!important; font-size:11px!important;">'; if (isset($fc_run_times['initialize_component'])) { $msg .= sprintf('<br/>-- [Initialize component: %.2f s] ', $fc_run_times['initialize_component'] / 1000000); } if (isset($fc_run_times['post_installation_tasks'])) { $msg .= sprintf('<br/>-- [Post installation / DB intergrity TASKs: %.2f s] ', $fc_run_times['post_installation_tasks'] / 1000000); } $msg .= '<small>'; if (isset($fc_run_times['getExistMenuItems'])) { $msg .= sprintf('<br/> - Default menu item for URLs : %.2f s ', $fc_run_times['getExistMenuItems'] / 1000000); } if (isset($fc_run_times['getItemsNoLang'])) { $msg .= sprintf('<br/> - Items language and translation associations: %.2f s ', $fc_run_times['getItemsNoLang'] / 1000000);
/** * Creates the page's display * * @since 1.0 */ function display($tpl = null) { //initialize variables $app = JFactory::getApplication(); $document = JFactory::getDocument(); $menus = $app->getMenu(); $menu = $menus->getActive(); $uri = JFactory::getURI(); $view = JRequest::getCmd('view'); // Get view's Model $model = $this->getModel(); // Get tag and set tag parameters as VIEW's parameters (tag parameters are merged with component/page(=menu item) and optionally with tag cloud parameters) $tag = $model->getTag(); if (empty($tag)) { // Raise a 404 error, if tag doesn't exist or access isn't permitted, maybe move this into model ?? $tid = JRequest::getInt('id', 0); $msg = JText::sprintf($tid ? 'Tag id was not set (is 0)' : 'Tag #%d not found', $tid); if (FLEXI_J16GE) { throw new Exception($msg, 404); } else { JError::raiseError(404, $msg); } } // Get parameters via model $params = $model->getParams(); // Get various data from the model $items = $this->get('Data'); $total = $this->get('Total'); // Make sure field values were retrieved e.g. we need 'item->categories' for template classes $items = FlexicontentFields::getFields($items, $view, $params); // Calculate CSS classes needed to add special styling markups to the items flexicontent_html::calculateItemMarkups($items, $params); // ******************************** // 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 file if (!$params->get('disablecss', '')) { $document->addStyleSheet($this->baseurl . '/components/com_flexicontent/assets/css/flexicontent.css'); $document->addCustomTag('<!--[if IE]><style type="text/css">.floattext {zoom:1;}</style><![endif]-->'); } //allow css override if (file_exists(JPATH_SITE . DS . 'templates' . DS . $app->getTemplate() . DS . 'css' . DS . 'flexicontent.css')) { $document->addStyleSheet($this->baseurl . '/templates/' . $app->getTemplate() . '/css/flexicontent.css'); } // ********************************************************** // Calculate a (browser window) page title and a page heading // ********************************************************** // Verify menu item points to current FLEXIcontent object if ($menu) { $view_ok = 'tags' == @$menu->query['view']; $tid_ok = $tag->id == (int) @$menu->query['id']; $menu_matches = $view_ok && $tid_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_ITEMS_WITH_TAG') . ": " . $tag->name; // Decide to show page heading (=J1.5 page title), this is always yes $show_default_heading = 1; // 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 if (FLEXI_J16GE) { // Not available in J1.5 // Add Site Name to page title if ($app->getCfg('sitename_pagetitles', 0) == 1) { $doc_title = $app->getCfg('sitename') . " - " . $doc_title; } elseif ($app->getCfg('sitename_pagetitles', 0) == 2) { $doc_title = $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 (FLEXI_J16GE) { 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); } } } // ************************************ // Add rel canonical html head link tag (TODO: improve multi-page handing) // ************************************ $base = $uri->getScheme() . '://' . $uri->getHost(); $start = JRequest::getVar('start', ''); $start = $start ? "&start=" . $start : ""; $ucanonical = $base . JRoute::_(FlexicontentHelperRoute::getTagRoute($tag->id) . $start); if ($params->get('add_canonical')) { $head_obj = $document->addHeadLink($ucanonical, 'canonical', 'rel', ''); $defaultCanonical = flexicontent_html::getDefaultCanonical(); if (FLEXI_J30GE && $defaultCanonical != $ucanonical) { unset($head_obj->_links[$defaultCanonical]); } } //ordering $filter_order = JRequest::getCmd('filter_order', 'i.title'); $filter_order_Dir = JRequest::getCmd('filter_order_Dir', 'ASC'); $filter = JRequest::getString('filter'); $lists = array(); $lists['filter_order'] = $filter_order; $lists['filter_order_Dir'] = $filter_order_Dir; $lists['filter'] = $filter; // Create the pagination object $pageNav = $this->get('pagination'); // Create links, etc $link = JRoute::_(FlexicontentHelperRoute::getTagRoute($tag->slug), false); //$print_link = JRoute::_('index.php?view=tags&id='.$tag->slug.'&pop=1&tmpl=component'); $curr_url = $_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('tag', $tag); $this->assignRef('items', $items); $this->assignRef('lists', $lists); $this->assignRef('params', $params); $this->assignRef('pageNav', $pageNav); $this->assignRef('pageclass_sfx', $pageclass_sfx); $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); } }
function getRatingResolution() { if ($this->_rating_resolution) { return $this->_rating_resolution; } $this->_db->setQuery('SELECT * FROM #__flexicontent_fields WHERE field_type="voting"'); $field = $this->_db->loadObject(); $item = JTable::getInstance($type = 'flexicontent_items', $prefix = '', $config = array()); //$item->load( $id ); FlexicontentFields::loadFieldConfig($field, $item); $rating_resolution = (int) $field->parameters->get('rating_resolution', 5); $rating_resolution = $rating_resolution >= 5 ? $rating_resolution : 5; $rating_resolution = $rating_resolution <= 100 ? $rating_resolution : 100; $this->_rating_resolution = $rating_resolution; }
/** * Method to get the active filter result * * @access private * @return string * @since 1.5 */ function _getFiltered(&$filter, $value, $return_sql = true) { $field_type = $filter->field_type; // Sanitize filter values as integers for field that use integer values if (in_array($field_type, array('createdby', 'modifiedby', 'type', 'categories', 'tags'))) { $values = is_array($value) ? $value : array($value); foreach ($values as $i => $v) { $values[$i] = (int) $v; } } switch ($field_type) { case 'createdby': $filter_query = ' AND i.created_by IN (' . implode(",", $values) . ')'; // no db quoting needed since these were typecasted to ints break; case 'modifiedby': $filter_query = ' AND i.modified_by IN (' . implode(",", $values) . ')'; // no db quoting needed since these were typecasted to ints break; case 'type': //$filter_query = ' AND ie.type_id IN ('. implode(",", $values) .')'; // no db quoting needed since these were typecasted to ints $query = 'SELECT item_id' . ' FROM #__flexicontent_items_ext' . ' WHERE type_id IN (' . implode(",", $values) . ')'; //$filter_query = ' AND i.id IN (' . $query . ')'; break; case 'state': $stateids = array('PE' => -3, 'OQ' => -4, 'IP' => -5, 'P' => 1, 'U' => 0, 'A' => FLEXI_J16GE ? 2 : -1, 'T' => -2); $values = is_array($value) ? $value : array($value); $filt_states = array(); foreach ($values as $i => $v) { if (isset($stateids[$v])) { $filt_states[] = $stateids[$v]; } } $filter_query = !count($values) ? ' AND 0 ' : ' AND i.state IN (' . implode(",", $filt_states) . ')'; // no db quoting needed since these were typecasted to ints break; case 'categories': //$filter_query = ' AND rel.catid IN ('. implode(",", $values) .')'; global $globalcats; $cparams = $this->_params; $display_subcats = $cparams->get('display_subcategories_items', 2); // include subcategory items $query_catids = array(); foreach ($values as $id) { $query_catids[$id] = 1; if ($display_subcats == 2 && !empty($globalcats[$id]->descendantsarray)) { foreach ($globalcats[$id]->descendantsarray as $subcatid) { $query_catids[$subcatid] = 1; } } } $query_catids = array_keys($query_catids); $query = 'SELECT itemid' . ' FROM #__flexicontent_cats_item_relations' . ' WHERE catid IN (' . implode(",", $query_catids) . ')'; //$filter_query = ' AND i.id IN (' . $query . ')'; break; case 'tags': $query = 'SELECT itemid' . ' FROM #__flexicontent_tags_item_relations' . ' WHERE tid IN (' . implode(",", $values) . ')'; //$filter_query = ' AND i.id IN (' . $query . ')'; break; default: // Make sure plugin file of current file is loaded and then check if custom filtering function exists $field_type_file = $filter->iscore ? 'core' : $field_type; $path = JPATH_ROOT . DS . 'plugins' . DS . 'flexicontent_fields' . DS . strtolower($field_type_file) . (FLEXI_J16GE ? DS . strtolower($field_type_file) : "") . '.php'; if (file_exists($path)) { require_once $path; $method_exists = method_exists("plgFlexicontent_fields{$field_type_file}", "getFiltered"); } // Use custom field filtering if 'getFiltered' plugin method exists, otherwise try to use our default filtering function $filtered = !@$method_exists ? FlexicontentFields::getFiltered($filter, $value, $return_sql) : FLEXIUtilities::call_FC_Field_Func($field_type_file, 'getFiltered', array(&$filter, &$value, &$return_sql)); break; } if (!isset($filter_query)) { if (isset($filtered)) { // nothing to do } else { if (!isset($query)) { $filtered = ''; echo "Unhandled case for filter: " . $field->name . " in 'FlexicontentModelCategory::getFiltered()', query variable not set<br/>\n"; } else { if (!$return_sql) { //echo "<br>GET FILTERED Items (cat model) -- [".$filter->name."] using in-query ids :<br>". $query."<br>\n"; $db = JFactory::getDBO(); $db->setQuery($query); $filtered = $db->loadColumn(); if ($db->getErrorNum()) { JFactory::getApplication()->enqueueMessage(__FUNCTION__ . '(): SQL QUERY ERROR:<br/>' . nl2br($db->getErrorMsg()), 'error'); } } else { if ($return_sql === 2) { $db = JFactory::getDBO(); static $iids_tblname = array(); if (!isset($iids_tblname[$filter->id])) { $iids_tblname[$filter->id] = 'fc_filter_iids_' . $filter->id; } $tmp_tbl = $iids_tblname[$filter->id]; try { // Use sub-query on temporary table $db->setQuery('CREATE TEMPORARY TABLE IF NOT EXISTS ' . $tmp_tbl . ' (id INT, KEY(`id`))'); $db->query(); $db->setQuery('TRUNCATE TABLE ' . $tmp_tbl); $db->query(); $db->setQuery('INSERT INTO ' . $tmp_tbl . ' ' . $query); $db->query(); $_query = $query; $query = 'SELECT id FROM ' . $tmp_tbl; //echo "<br/><br/>GET FILTERED Items (cat model) -- [".$filter->name."] using temporary table: ".$query." for :".$_query ." <br/><br/>"; /*$db->setQuery($query); $data = $db->loadObjectList(); echo "<pre>"; print_r($data); exit;*/ } catch (Exception $e) { // Ignore table creation error //if ($db->getErrorNum()) echo 'SQL QUERY ERROR:<br/>'.nl2br($db->getErrorMsg()); //echo "<br/><br/>GET FILTERED Items (cat model) -- [".$filter->name."] using subquery: ".$query." <br/><br/>"; } } else { //echo "<br/><br/>GET FILTERED Items (cat model) -- [".$filter->name."] using subquery: ".$query." <br/><br/>"; } } } } if (!isset($filtered) && isset($query)) { $filtered = ' AND i.id IN (' . $query . ')'; } // An empty return value means no matching values were found $filtered = empty($filtered) ? ' AND 0 ' : $filtered; // A string mean a subquery was returned, while an array means that item ids we returned $filter_query = is_array($filtered) ? ' AND i.id IN (' . implode(',', $filtered) . ')' : $filtered; } //echo "<br/>".$filter_query."<br/>"; return $filter_query; }
/** * Method to get the active filter result * * @access private * @return string * @since 1.5 */ function _getFiltered(&$filter, $value) { $field_type = $filter->field_type; // Sanitize filter values as integers for field that use integer values if (in_array($field_type, array('createdby', 'modifiedby', 'type', 'categories', 'tags'))) { $values = is_array($value) ? $value : array($value); foreach ($values as $i => $v) { $values[$i] = (int) $v; } } switch ($field_type) { case 'createdby': $filter_query = ' AND i.created_by IN (' . implode(",", $values) . ')'; // no db quoting needed since these were typecasted to ints break; case 'modifiedby': $filter_query = ' AND i.modified_by IN (' . implode(",", $values) . ')'; // no db quoting needed since these were typecasted to ints break; case 'type': //$filter_query = ' AND ie.type_id IN ('. implode(",", $values) .')'; // no db quoting needed since these were typecasted to ints $query = 'SELECT item_id' . ' FROM #__flexicontent_items_ext' . ' WHERE type_id IN (' . implode(",", $values) . ')'; $filter_query = ' AND i.id IN (' . $query . ')'; break; case 'state': $stateids = array('PE' => -3, 'OQ' => -4, 'IP' => -5, 'P' => 1, 'U' => 0, 'A' => FLEXI_J16GE ? 2 : -1, 'T' => -2); $values = is_array($value) ? $value : array($value); $filt_states = array(); foreach ($values as $i => $v) { if (isset($stateids[$v])) { $filt_states[] = $stateids[$v]; } } $filter_query = !count($values) ? ' AND 1=0 ' : ' AND i.state IN (' . implode(",", $filt_states) . ')'; // no db quoting needed since these were typecasted to ints break; case 'categories': //$filter_query = ' AND rel.catid IN ('. implode(",", $values) .')'; $query = 'SELECT itemid' . ' FROM #__flexicontent_cats_item_relations' . ' WHERE catid IN (' . implode(",", $values) . ')'; $filter_query = ' AND i.id IN (' . $query . ')'; break; case 'tags': $query = 'SELECT itemid' . ' FROM #__flexicontent_tags_item_relations' . ' WHERE tid IN (' . implode(",", $values) . ')'; $filter_query = ' AND i.id IN (' . $query . ')'; break; default: // Make sure plugin file of current file is loaded and then check if custom filtering function exists $field_type_file = $filter->iscore ? 'core' : $field_type; $path = JPATH_ROOT . DS . 'plugins' . DS . 'flexicontent_fields' . DS . strtolower($field_type_file) . (FLEXI_J16GE ? DS . strtolower($field_type_file) : "") . '.php'; if (file_exists($path)) { require_once $path; $method_exists = method_exists("plgFlexicontent_fields{$field_type_file}", "getFiltered"); } // Use custom field filtering if 'getFiltered' plugin method exists, otherwise try to use our default filtering function $filtered = !@$method_exists ? FlexicontentFields::getFiltered($filter, $value, $return_sql = true) : FLEXIUtilities::call_FC_Field_Func($field_type_file, 'getFiltered', array(&$filter, &$value)); // An empty return value means no matching values we found $filtered = empty($filtered) ? ' AND 1=0' : $filtered; // A string mean a subquery was returned, while an array means that item ids we returned $filter_query = is_array($filtered) ? ' AND i.id IN (' . implode(',', $filtered) . ')' : $filtered; break; } //echo "<br/>".$filter_query."<br/>"; return $filter_query; }
protected function getCloseTag() { return FlexicontentFields::replaceFieldValue($this->field, $this->item, $this->field->parameters->get('closetag', ''), 'closetag'); }
function onIndexSearch(&$field, &$post, &$item) { if ( !in_array($field->field_type, self::$field_types) ) return; if ( !$field->issearch ) return; FlexicontentFields::onIndexSearch($field, $post, $item, $required_properties=array('url'), $search_properties=array('title','author','description','audiotype'), $properties_spacer=' ', $filter_func=null); return true; }
static function createItemsListHTML(&$params, &$item_list, $isform = 0, &$parentfield, &$parentitem, &$_item_data = null) { $db = JFactory::getDBO(); global $globalcats, $globalnoroute, $fc_run_times; if (!is_array($globalnoroute)) { $globalnoroute = array(); } // Get fields of type relation static $disallowed_fieldnames = null; $disallowed_fields = array('relation', 'relation_reverse'); if ($disallowed_fieldnames === null) { $query = "SELECT name FROM #__flexicontent_fields WHERE field_type IN ('" . implode("','", $disallowed_fields) . "')"; $db->setQuery($query); $field_name_col = FLEXI_J16GE ? $db->loadColumn() : $db->loadResultArray(); $disallowed_fieldnames = !$field_name_col ? array() : array_flip($field_name_col); } // Prefix - Suffix - Separator parameters, replacing other field values if found $remove_space = $params->get('remove_space', 0); $pretext = $params->get($isform ? 'pretext_form' : 'pretext', ''); $posttext = $params->get($isform ? 'posttext_form' : 'posttext', ''); $separatorf = $params->get($isform ? 'separator' : 'separatorf'); $opentag = $params->get($isform ? 'opentag_form' : 'opentag', ''); $closetag = $params->get($isform ? 'closetag_form' : '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; } // some parameter shortcuts $relitem_html = $params->get($isform ? 'relitem_html_form' : 'relitem_html', '__display_text__'); $displayway = $params->get($isform ? 'displayway_form' : 'displayway', 1); $addlink = $params->get($isform ? 'addlink_form' : 'addlink', 1); $addtooltip = $params->get($isform ? 'addtooltip_form' : 'addtooltip', 1); // Parse and identify custom fields $result = preg_match_all("/\\{\\{([a-zA-Z_0-9]+)(##)?([a-zA-Z_0-9]+)?\\}\\}/", $relitem_html, $field_matches); $custom_field_reps = $result ? $field_matches[0] : array(); $custom_field_names = $result ? $field_matches[1] : array(); $custom_field_methods = $result ? $field_matches[3] : array(); /*foreach ($custom_field_names as $i => $custom_field_name) $parsed_fields[] = $custom_field_names[$i] . ($custom_field_methods[$i] ? "->". $custom_field_methods[$i] : ""); echo "$relitem_html :: Fields for Related Items List: ". implode(", ", $parsed_fields ? $parsed_fields : array() ) ."<br/>\n";*/ // Parse and identify language strings and then make language replacements $result = preg_match_all("/\\%\\%([^%]+)\\%\\%/", $relitem_html, $translate_matches); $translate_strings = $result ? $translate_matches[1] : array('FLEXI_READ_MORE_ABOUT'); foreach ($translate_strings as $translate_string) { $relitem_html = str_replace('%%' . $translate_string . '%%', JText::_($translate_string), $relitem_html); } foreach ($item_list as $result) { // Check if related item is published and skip if not published if ($result->state != 1 && $result->state != -5) { continue; } $itemslug = $result->id . ":" . $result->alias; $catslug = ""; // Check if removed from category or inside a noRoute category or inside a non-published category // and use main category slug or other routable & published category slug $catid_arr = explode(",", $result->catidlist); $catalias_arr = explode(",", $result->cataliaslist); for ($i = 0; $i < count($catid_arr); $i++) { $itemcataliases[$catid_arr[$i]] = $catalias_arr[$i]; } $rel_itemid = $result->id; $rel_catid = !empty($result->rel_catid) ? $result->rel_catid : $result->catid; if (isset($itemcataliases[$rel_catid]) && !in_array($rel_catid, $globalnoroute) && $globalcats[$rel_catid]->published) { $catslug = $rel_catid . ":" . $itemcataliases[$rel_catid]; } else { if (!in_array($result->catid, $globalnoroute) && $globalcats[$result->catid]->published) { $catslug = $globalcats[$result->catid]->slug; } else { foreach ($catid_arr as $catid) { if (!in_array($catid, $globalnoroute) && $globalcats[$catid]->published) { $catslug = $globalcats[$catid]->slug; break; } } } } $result->slug = $itemslug; $result->categoryslug = $catslug; } // Perform field's display replacements if ($i_slave = $parentfield ? $parentitem->id . "_" . $parentfield->id : '') { $fc_run_times['render_subfields'][$i_slave] = 0; } foreach ($custom_field_names as $i => $custom_field_name) { if (isset($disallowed_fieldnames[$custom_field_name])) { continue; } if ($custom_field_methods[$i] == 'label') { continue; } if ($i_slave) { $start_microtime = microtime(true); } $display_var = $custom_field_methods[$i] ? $custom_field_methods[$i] : 'display'; FlexicontentFields::getFieldDisplay($item_list, $custom_field_name, $custom_field_values = null, $display_var); if ($i_slave) { $fc_run_times['render_subfields'][$i_slave] += round(1000000 * 10 * (microtime(true) - $start_microtime)) / 10; } } $tooltip_class = FLEXI_J30GE ? 'hasTooltip' : 'hasTip'; $display = array(); foreach ($item_list as $result) { $url_read_more = JText::_(isset($_item_data->url_read_more) ? $_item_data->url_read_more : 'FLEXI_READ_MORE_ABOUT', 1); $url_class = isset($_item_data->url_class) ? $_item_data->url_class : 'relateditem'; // Check if related item is published and skip if not published if ($result->state != 1 && $result->state != -5) { continue; } // a. Replace some custom made strings $item_url = JRoute::_(FlexicontentHelperRoute::getItemRoute($result->slug, $result->categoryslug, 0, $result)); $item_title_escaped = htmlspecialchars($result->title, ENT_COMPAT, 'UTF-8'); $tooltip_title = flexicontent_html::getToolTip($url_read_more, $item_title_escaped, $translate = 0, $escape = 0); $item_tooltip = ' class="' . $tooltip_class . ' ' . $url_class . '" title="' . $tooltip_title . '" '; $display_text = $displayway ? $result->title : $result->id; $display_text = !$addlink ? $display_text : '<a href="' . $item_url . '"' . ($addtooltip ? $item_tooltip : '') . ' >' . $display_text . '</a>'; $curr_relitem_html = $relitem_html; $curr_relitem_html = str_replace('__item_url__', $item_url, $curr_relitem_html); $curr_relitem_html = str_replace('__item_title_escaped__', $item_title_escaped, $curr_relitem_html); $curr_relitem_html = str_replace('__item_tooltip__', $item_tooltip, $curr_relitem_html); $curr_relitem_html = str_replace('__display_text__', $display_text, $curr_relitem_html); // b. Replace item properties, e.g. {item->id}, (item->title}, etc $null_field = null; FlexicontentFields::doQueryReplacements($curr_relitem_html, $null_field, $result); // c. Replace HTML display of various item fields $err_mssg = 'Cannot replace field: "%s" because it is of not allowed field type: "%s", which can cause loop or other problem'; foreach ($custom_field_names as $i => $custom_field_name) { $_field = @$result->fields[$custom_field_name]; $custom_field_display = ''; if ($is_disallowed_field = isset($disallowed_fieldnames[$custom_field_name])) { $custom_field_display .= sprintf($err_mssg, $custom_field_name, @$_field->field_type); } else { $display_var = $custom_field_methods[$i] ? $custom_field_methods[$i] : 'display'; $custom_field_display .= @$_field->{$display_var}; } $curr_relitem_html = str_replace($custom_field_reps[$i], $custom_field_display, $curr_relitem_html); } $display[] = trim($pretext . $curr_relitem_html . $posttext); } $display = $opentag . implode($separatorf, $display) . $closetag; return $display; }
</span> <?php } ?> <?php if ($fcr_use_image && @$result->fc_item_id) { // FLEXIcontent specific result ?> <?php $src = $thumb = ''; if (!empty($img_field_name)) { FlexicontentFields::getFieldDisplay($fcitems[$i], $img_field_name, $values = null, $method = 'display'); $img_field =& $fcitems[$i]->fields[$img_field_name]; $src = str_replace(JURI::root(), '', @$img_field->thumbs_src[$img_field_size][0]); } else { $src = flexicontent_html::extractimagesrc($fcitems[$i]); } $RESIZE_FLAG = !$this->params->get('fcr_image') || !$this->params->get('fcr_image_size'); if ($src && $RESIZE_FLAG) { // Resize image when src path is set and RESIZE_FLAG: (a) using image extracted from item main text OR (b) not using image field's already created thumbnails $w = '&w=' . $this->params->get('fcr_width', 200); $h = '&h=' . $this->params->get('fcr_height', 200); $aoe = '&aoe=1'; $q = '&q=95'; $zc = $this->params->get('fcr_method') ? '&zc=' . $this->params->get('fcr_method') : ''; $ext = strtolower(pathinfo($src, PATHINFO_EXTENSION)); $f = in_array($ext, array('png', 'ico', 'gif')) ? '&f=' . $ext : '';