/**
  * Method to get the fields in their positions
  * 
  * @access private
  * @return object
  * @since 1.5
  */
 static function &renderPositions(&$items, $view = FLEXI_ITEMVIEW, $params = null, $use_tmpl = true, &$_rendered = array())
 {
     if (!$items) {
         return;
     }
     if (!$params) {
         return $items;
     }
     if ($view == 'category') {
         $layout = 'clayout';
     }
     if ($view == FLEXI_ITEMVIEW) {
         $layout = 'ilayout';
     }
     // field's source code, can use this JRequest variable, to detect who rendered the fields (e.g. they can detect rendering from 'module')
     JRequest::setVar("flexi_callview", $view);
     if ($use_tmpl && ($view == 'category' || $view == FLEXI_ITEMVIEW)) {
         $fbypos = flexicontent_tmpl::getFieldsByPositions($params->get($layout, 'default'), $view);
     } else {
         // $view == 'module', or other
         // Create a fake template position, for fields defined via parameters
         $fbypos[0] = new stdClass();
         $fbypos[0]->fields = explode(',', $params->get('fields'));
         $fbypos[0]->methods = explode(',', $params->get('methods'));
         $fbypos[0]->position = $view;
     }
     $always_create_fields_display = $params->get('always_create_fields_display', 0);
     // Render some fields by default, this is done for compatibility reasons, but avoid rendering these fields again (2nd time),
     // since some of them may also be in template positions. NOTE: this is not needed since renderField() should detect this case
     if ($always_create_fields_display != 3) {
         // value 3 means never create for any view (blog template incompatible)
         $item = reset($items);
         // get the first item ... so that we can get the name of CORE fields out of it
         // 'description' item field is implicitly used by category layout of some templates (blog), render it
         $custom_values = null;
         if ($view == 'category') {
             if (isset($item->fields['text']) && !isset($_rendered['ALL']['text'])) {
                 $_field_name_ = 'text';
                 FlexicontentFields::renderField($items, $_field_name_, $custom_values, $method = 'display', $view);
             }
             $_rendered['ALL']['text'] = 1;
         } else {
             if ($view == FLEXI_ITEMVIEW) {
                 foreach ($item->fields as $field) {
                     if ($field->iscore && !isset($_rendered['ALL'][$field->name])) {
                         $_field_name_ = $field->name;
                         FlexicontentFields::renderField($items, $_field_name_, $custom_values, $method = 'display', $view);
                     }
                 }
                 $_rendered['ALL']['core'] = 1;
             }
         }
     }
     // *** RENDER fields on DEMAND, (if present in template positions)
     foreach ($fbypos as $pos) {
         // RENDER fields if they are present in a template position (or in a dummy template position ... e.g. when called by module)
         foreach ($pos->fields as $c => $f) {
             // CORE/CUSTOM: Render field (if already rendered above, the function will return result immediately)
             $method = isset($pos->methods[$c]) && $pos->methods[$c] ? $pos->methods[$c] : 'display';
             // Render ANY CORE field with single call for all items, CORE fields are assigned to ALL types,
             // try to get field out of first item, if it does not exist, then field is a CUSTOM field
             $item = reset($items);
             $field = @$item->fields[$f];
             if ($field && $field->iscore) {
                 // Check if already rendered
                 if (!isset($_rendered['ALL']['core']) && !isset($_rendered['ALL'][$f])) {
                     // No custom values for CORE fields, values are decided inside the CORE field
                     $values = null;
                     FlexicontentFields::renderField($items, $f, $values, $method, $view);
                 }
                 $_rendered['ALL'][$f] = 1;
             } else {
                 foreach ($items as $item) {
                     // Check that field with given name: $f exists for current item (AKA, that it is assigned to the item's type)
                     if (!isset($item->fields[$f])) {
                         continue;
                     }
                     // Check if already rendered
                     if (isset($_rendered['ALL'][$f]) || isset($_rendered[$item->id][$f])) {
                         continue;
                     }
                     // Get field and field values, currently, custom field values can be passed only for CUSTOM fields, OR versioned CORE/CUSTOM fields too ...
                     $field = $item->fields[$f];
                     $values = isset($item->fieldvalues[$field->id]) ? $item->fieldvalues[$field->id] : array();
                     // Render the field's display
                     $field = FlexicontentFields::renderField($item, $field, $values, $method, $view);
                     $_rendered[$item->id][$f] = 1;
                 }
             }
             foreach ($items as $item) {
                 // Check that field with given name: $f exists for current item (AKA, that it is assigned to the item's type)
                 if (!isset($item->fields[$f])) {
                     continue;
                 }
                 $field = $item->fields[$f];
                 // Skip field if empty display was produced
                 if (!isset($field->display) || !strlen($field->display)) {
                     continue;
                 }
                 // Set field display HTML/data in the template position,
                 if (!isset($item->positions[$pos->position])) {
                     $item->positions[$pos->position] = new stdClass();
                 }
                 $item->positions[$pos->position]->{$f} = new stdClass();
                 $item->positions[$pos->position]->{$f}->id = $field->id;
                 $item->positions[$pos->position]->{$f}->id = $field->id;
                 $item->positions[$pos->position]->{$f}->name = $field->name;
                 $item->positions[$pos->position]->{$f}->label = $field->parameters->get('display_label') ? $field->label : '';
                 $item->positions[$pos->position]->{$f}->display = $field->display;
             }
         }
     }
     return $items;
 }
<?php
if (!$this->items) {
	// No items exist
	if ($this->getModel()->getState('limit')) {
		// Not creating a category view without items
		echo '<div class="noitems group">' . JText::_( 'FLEXI_NO_ITEMS_FOUND' ) . '</div>';
	}
	return;
}

// routine to determine all used columns for this table
$show_title  = $this->params->get('show_title', 1);
$link_titles = $this->params->get('link_titles', 0);

$layout = $this->params->get('clayout', 'default');
$fbypos = flexicontent_tmpl::getFieldsByPositions($layout, 'category');
$columns = array();
foreach ($this->items as $item) :
	if (isset($item->positions['table'])) :
		foreach ($fbypos['table']->fields as $f) :
			if ( ! @ $columns[$f] ) :
				$columns[$f] = @ $item->fields[$f]->label;
			endif;
		endforeach;
	endif;
endforeach;

$items = & $this->items;

// Decide whether to show the edit column
$buttons_exists = false;