Так как решил доделать компонент, подниму тему...
Если в файле machines.php в этом участке :
if ($ordering == 'a.created') {
$query->from('`#__machine` AS a')
->where('a.state = 1')
->order('a.created');
->order('a.created'); заменить на
->order('a.created DESC'); от фид в RSS 2.0 отдается пустым. Atom 1.0 - нормальный, но режет картинки.
Вопрос: почему?
Ниже исходники.
Файл 0:/public_html/components/com_machine/models/machines.php
<?php
defined('_JEXEC') or die;
jimport('joomla.application.component.modellist');
/**
* Methods supporting a list of Machine records.
*/
class MachineModelGoods extends JModelList {
public function __construct($config = array()) {
if (empty($config['filter_fields'])) {
$config['filter_fields'] = array(
'id', 'a.id',
'ordering', 'a.ordering',
'state', 'a.state',
'checked_out', 'a.checked_out',
'checked_out_time', 'a.checked_out_time',
'created_by', 'a.created_by',
'created', 'a.created',
'name_goods', 'a.name_goods',
'id_group', 'a.id_group',
'id_goods', 'a.id_goods',
'catid', 'a.catid',
'featured', 'a.featured',
'hits', 'a.hits'
);
}
parent::__construct($config);
}
/**
* Method to auto-populate the model state.
*
* Note. Calling getState in this method will result in recursion.
*
* @since 1.6
*/
protected function populateState($ordering = null, $direction = null) {
// Initialise variables.
$app = JFactory::getApplication();
// List state information
$limit = $app->getUserStateFromRequest('global.list.limit', 'limit', $app->getCfg('list_limit'));
$this->setState('list.limit', $limit);
$limitstart = JFactory::getApplication()->input->getInt('limitstart', 0);
$this->setState('list.start', $limitstart);
// Load the filter state.
$search = $app->getUserStateFromRequest($this->context . '.filter.search', 'filter_search');
$this->setState('filter.search', $search);
//Filtering catid
$this->setState('filter.catid', $app->getUserStateFromRequest($this->context.'.filter.catid', 'filter_catid', '', 'string'));
$ordering = $this->setState('list.ordering', 'a.created');
if(empty($ordering)) {
$ordering = 'a.ordering';
}
// List state information.
parent::populateState($ordering, $direction);
}
/**
* Build an SQL query to load the list data.
*
* @return JDatabaseQuery
* @since 1.6
*/
protected function getListQuery() {
// Create a new query object.
// $ordering = $this->getState('list.ordering');
$db = $this->getDbo();
$query = $db->getQuery(true);
// Select the required fields from the table.
$query->select(
$this->getState(
'list.select', 'a.*'
)
);
$ordering = $this->getState('list.ordering');
if ($ordering == 'a.created') {
$query->from('`#__machine` AS a')
->where('a.state = 1')
->order('a.created');
}else {
$query->from('`#__machine` AS a')
->where('a.state = 1')
->order('a.created DESC')
->order('a.featured DESC');
}
// Join over the users for the checked out user.
$query->select('uc.name AS editor');
$query->join('LEFT', '#__users AS uc ON uc.id=a.checked_out');
// Join over the created by field 'created_by'
$query->select('created_by.name AS created_by');
$query->join('LEFT', '#__users AS created_by ON created_by.id = a.created_by');
// Join over the category 'catid'
$query->select('catid.title AS catid_title');
$query->join('LEFT', '#__categories AS catid ON catid.id = a.catid');
// Filter by search in title
$search = $this->getState('filter.search');
if (!empty($search)) {
if (stripos($search, 'id:') === 0) {
$query->where('a.id = ' . (int) substr($search, 3));
} else {
$search = $db->Quote('%' . $db->escape($search, true). '%');
$query->where('( a.name_goods LIKE '.$search.' )');
}
}
//Filtering catid
$filter_catid = $this->state->get("filter.catid");
if ($filter_catid) {
$query->where("a.catid = '".$filter_catid."'");
}
return $query;
}
public function getItems() {
return parent::getItems();
}
}
Файл 0:/public_html/components/com_machine/views/machines/view.feed.php
<?php
defined('_JEXEC') or die;
jimport( 'joomla.application.component.view');
class MachineViewGoods extends JViewLegacy
{
/*
protected $items;
protected $pagination;
protected $state;
protected $params;
*/
public function _GetAnswer($address, $xml){
$ch = curl_init($address);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_POST,1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $xml);
$result=curl_exec($ch);
return $result;
}
/**
* Display the view
*/
public function display($tpl = null)
{
$model = $this->getModel();
$model->setState('list.ordering', 'a.created');
$app = JFactory::getApplication();
$doc = &JFactory::getDocument();
$feedEmail = $app->getCfg('feed_email', 'author');
$siteEmail = $app->getCfg('mailfrom');
$state = $this->get('State');
$items = $this->get('Items');
$pagination = $this->get('Pagination');
$params = $app->getParams('com_machine');
JRequest::setVar('limit', $app->getCfg('feed_limit'));
if ($feedEmail != "none")
{
$doc->editorEmail = $siteEmail;
}
foreach ($items as $item)
{
// strip HTML from feed item title
$title = $this->escape($item->name_goods);
$title = html_entity_decode($title, ENT_COMPAT, 'UTF-8');
// url link to article
$link = JRoute::_('index.php?option=com_machine&view=good&id=' . (int)$item->id);
// strip HTML from feed item description text
$description = $item->info_description;
//$author = $item->created_by_alias ? $item->created_by_alias : $item->author;
//$author = $item->author;
$date = ($item->created ? date('r', strtotime($item->created)) : '');
// load individual item creator class
$feeditem = new JFeedItem();
$feeditem->title = $title;
$feeditem->link = $link;
$feeditem->description = '<img src="'.$item->info_img .'"><br><b>'.$orgprice. ' '.JText::_('COM_MACHINE_RUBLEY').'</b> <br>'.$description;
$feeditem->date = $date;
//$feeditem->category = $category->title;
//$feeditem->author = $author;
// We don't have the author email so we have to use site in both cases.
if ($feedEmail == 'site')
{
$feeditem->authorEmail = $siteEmail;
}
elseif($feedEmail === 'author')
{
$feeditem->authorEmail = $item->author_email;
}
// loads item info into RSS array
$doc->addItem($feeditem);
}
// $this->_prepareDocument();
// parent::display($tpl);
}
}