You've already forked joomla_test
first commit
This commit is contained in:
@ -0,0 +1 @@
|
||||
<!DOCTYPE html><title></title>
|
@ -0,0 +1 @@
|
||||
<!DOCTYPE html><title></title>
|
@ -0,0 +1,163 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Joomla.Administrator
|
||||
* @subpackage com_newsfeeds
|
||||
*
|
||||
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
defined('JPATH_BASE') or die;
|
||||
|
||||
/**
|
||||
* Supports a modal newsfeeds picker.
|
||||
*
|
||||
* @package Joomla.Administrator
|
||||
* @subpackage com_newsfeeds
|
||||
* @since 1.6
|
||||
*/
|
||||
class JFormFieldModal_Newsfeed extends JFormField
|
||||
{
|
||||
/**
|
||||
* The form field type.
|
||||
*
|
||||
* @var string
|
||||
* @since 1.6
|
||||
*/
|
||||
protected $type = 'Modal_Newsfeed';
|
||||
|
||||
/**
|
||||
* Method to get the field input markup.
|
||||
*
|
||||
* @return string The field input markup.
|
||||
* @since 1.6
|
||||
*/
|
||||
protected function getInput()
|
||||
{
|
||||
$allowEdit = ((string) $this->element['edit'] == 'true') ? true : false;
|
||||
$allowClear = ((string) $this->element['clear'] != 'false') ? true : false;
|
||||
|
||||
// Load language
|
||||
JFactory::getLanguage()->load('com_newsfeeds', JPATH_ADMINISTRATOR);
|
||||
|
||||
// Load the javascript
|
||||
JHtml::_('behavior.framework');
|
||||
JHtml::_('behavior.modal', 'a.modal');
|
||||
JHtml::_('bootstrap.tooltip');
|
||||
|
||||
// Build the script.
|
||||
$script = array();
|
||||
|
||||
// Select button script
|
||||
$script[] = ' function jSelectNewsfeed_'.$this->id.'(id, name, object) {';
|
||||
$script[] = ' document.id("'.$this->id.'_id").value = id;';
|
||||
$script[] = ' document.id("'.$this->id.'_name").value = name;';
|
||||
|
||||
if ($allowEdit)
|
||||
{
|
||||
$script[] = ' jQuery("#'.$this->id.'_edit").removeClass("hidden");';
|
||||
}
|
||||
|
||||
if ($allowClear)
|
||||
{
|
||||
$script[] = ' jQuery("#'.$this->id.'_clear").removeClass("hidden");';
|
||||
}
|
||||
|
||||
$script[] = ' SqueezeBox.close();';
|
||||
$script[] = ' }';
|
||||
|
||||
// Clear button script
|
||||
static $scriptClear;
|
||||
|
||||
if ($allowClear && !$scriptClear)
|
||||
{
|
||||
$scriptClear = true;
|
||||
|
||||
$script[] = ' function jClearNewsfeed(id) {';
|
||||
$script[] = ' document.getElementById(id + "_id").value = "";';
|
||||
$script[] = ' document.getElementById(id + "_name").value = "'.htmlspecialchars(JText::_('COM_NEWSFEEDS_SELECT_A_FEED', true), ENT_COMPAT, 'UTF-8').'";';
|
||||
$script[] = ' jQuery("#"+id + "_clear").addClass("hidden");';
|
||||
$script[] = ' if (document.getElementById(id + "_edit")) {';
|
||||
$script[] = ' jQuery("#"+id + "_edit").addClass("hidden");';
|
||||
$script[] = ' }';
|
||||
$script[] = ' return false;';
|
||||
$script[] = ' }';
|
||||
}
|
||||
|
||||
// Add the script to the document head.
|
||||
JFactory::getDocument()->addScriptDeclaration(implode("\n", $script));
|
||||
|
||||
// Setup variables for display.
|
||||
$html = array();
|
||||
$link = 'index.php?option=com_newsfeeds&view=newsfeeds&layout=modal&tmpl=component&function=jSelectNewsfeed_'.$this->id;
|
||||
|
||||
if (isset($this->element['language']))
|
||||
{
|
||||
$link .= '&forcedLanguage='.$this->element['language'];
|
||||
}
|
||||
|
||||
// Get the title of the linked chart
|
||||
$db = JFactory::getDbo();
|
||||
$db->setQuery(
|
||||
'SELECT name' .
|
||||
' FROM #__newsfeeds' .
|
||||
' WHERE id = '.(int) $this->value
|
||||
);
|
||||
|
||||
try
|
||||
{
|
||||
$title = $db->loadResult();
|
||||
}
|
||||
catch (RuntimeException $e)
|
||||
{
|
||||
JError::raiseWarning(500, $e->getMessage);
|
||||
}
|
||||
|
||||
if (empty($title))
|
||||
{
|
||||
$title = JText::_('COM_NEWSFEEDS_SELECT_A_FEED');
|
||||
}
|
||||
$title = htmlspecialchars($title, ENT_QUOTES, 'UTF-8');
|
||||
|
||||
// The active newsfeed id field.
|
||||
if (0 == (int) $this->value)
|
||||
{
|
||||
$value = '';
|
||||
}
|
||||
else
|
||||
{
|
||||
$value = (int) $this->value;
|
||||
}
|
||||
|
||||
// The current newsfeed display field.
|
||||
$html[] = '<span class="input-append">';
|
||||
$html[] = '<input type="text" class="input-medium" id="'.$this->id.'_name" value="'.$title.'" disabled="disabled" size="35" />';
|
||||
$html[] = '<a class="modal btn hasTooltip" title="'.JHtml::tooltipText('COM_NEWSFEEDS_CHANGE_FEED_BUTTON').'" href="'.$link.'&'.JSession::getFormToken().'=1" rel="{handler: \'iframe\', size: {x: 800, y: 450}}"><i class="icon-file"></i> '.JText::_('JSELECT').'</a>';
|
||||
|
||||
// Edit newsfeed button
|
||||
if ($allowEdit)
|
||||
{
|
||||
$html[] = '<a class="btn hasTooltip'.($value ? '' : ' hidden').'" href="index.php?option=com_newsfeeds&layout=modal&tmpl=component&task=newsfeed.edit&id=' . $value. '" target="_blank" title="'.JHtml::tooltipText('COM_NEWSFEEDS_EDIT_NEWSFEED').'" ><span class="icon-edit"></span> ' . JText::_('JACTION_EDIT') . '</a>';
|
||||
}
|
||||
|
||||
// Clear newsfeed button
|
||||
if ($allowClear)
|
||||
{
|
||||
$html[] = '<button id="'.$this->id.'_clear" class="btn'.($value ? '' : ' hidden').'" onclick="return jClearNewsfeed(\''.$this->id.'\')"><span class="icon-remove"></span> ' . JText::_('JCLEAR') . '</button>';
|
||||
}
|
||||
|
||||
$html[] = '</span>';
|
||||
|
||||
// class='required' for client side validation
|
||||
$class = '';
|
||||
|
||||
if ($this->required)
|
||||
{
|
||||
$class = ' class="required modal-value"';
|
||||
}
|
||||
|
||||
$html[] = '<input type="hidden" id="'.$this->id.'_id"'.$class.' name="'.$this->name.'" value="'.$value.'" />';
|
||||
|
||||
return implode("\n", $html);
|
||||
}
|
||||
}
|
@ -0,0 +1,64 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Joomla.Administrator
|
||||
* @subpackage com_newsfeeds
|
||||
*
|
||||
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
defined('JPATH_BASE') or die;
|
||||
|
||||
JFormHelper::loadFieldClass('list');
|
||||
|
||||
/**
|
||||
* Form Field class for the Joomla Framework.
|
||||
*
|
||||
* @package Joomla.Administrator
|
||||
* @subpackage com_newsfeeds
|
||||
* @since 1.6
|
||||
*/
|
||||
class JFormFieldNewsfeeds extends JFormFieldList
|
||||
{
|
||||
/**
|
||||
* The form field type.
|
||||
*
|
||||
* @var string
|
||||
* @since 1.6
|
||||
*/
|
||||
protected $type = 'Newsfeeds';
|
||||
|
||||
/**
|
||||
* Method to get the field options.
|
||||
*
|
||||
* @return array The field option objects.
|
||||
* @since 1.6
|
||||
*/
|
||||
protected function getOptions()
|
||||
{
|
||||
$options = array();
|
||||
|
||||
$db = JFactory::getDbo();
|
||||
$query = $db->getQuery(true)
|
||||
->select('id As value, name As text')
|
||||
->from('#__newsfeeds AS a')
|
||||
->order('a.name');
|
||||
|
||||
// Get the options.
|
||||
$db->setQuery($query);
|
||||
|
||||
try
|
||||
{
|
||||
$options = $db->loadObjectList();
|
||||
}
|
||||
catch (RuntimeException $e)
|
||||
{
|
||||
JError::raiseWarning(500, $db->getMessage());
|
||||
}
|
||||
|
||||
// Merge any additional options in the XML definition.
|
||||
$options = array_merge(parent::getOptions(), $options);
|
||||
|
||||
return $options;
|
||||
}
|
||||
}
|
@ -0,0 +1,71 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Joomla.Administrator
|
||||
* @subpackage com_newsfeeds
|
||||
*
|
||||
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
defined('JPATH_BASE') or die;
|
||||
|
||||
/**
|
||||
* Supports an HTML select list of newsfeeds
|
||||
*
|
||||
* @package Joomla.Administrator
|
||||
* @subpackage com_newsfeeds
|
||||
* @since 1.6
|
||||
*/
|
||||
class JFormFieldOrdering extends JFormField
|
||||
{
|
||||
/**
|
||||
* The form field type.
|
||||
*
|
||||
* @var string
|
||||
* @since 1.6
|
||||
*/
|
||||
protected $type = 'Ordering';
|
||||
|
||||
/**
|
||||
* Method to get the field input markup.
|
||||
*
|
||||
* @return string The field input markup.
|
||||
* @since 1.6
|
||||
*/
|
||||
protected function getInput()
|
||||
{
|
||||
$html = array();
|
||||
$attr = '';
|
||||
|
||||
// Initialize some field attributes.
|
||||
$attr .= $this->element['class'] ? ' class="'.(string) $this->element['class'].'"' : '';
|
||||
$attr .= ((string) $this->element['disabled'] == 'true') ? ' disabled="disabled"' : '';
|
||||
$attr .= $this->element['size'] ? ' size="'.(int) $this->element['size'].'"' : '';
|
||||
|
||||
// Initialize JavaScript field attributes.
|
||||
$attr .= $this->element['onchange'] ? ' onchange="'.(string) $this->element['onchange'].'"' : '';
|
||||
|
||||
// Get some field values from the form.
|
||||
$newsfeedId = (int) $this->form->getValue('id');
|
||||
$categoryId = (int) $this->form->getValue('catid');
|
||||
|
||||
// Build the query for the ordering list.
|
||||
$query = 'SELECT ordering AS value, name AS text' .
|
||||
' FROM #__newsfeeds' .
|
||||
' WHERE catid = ' . (int) $categoryId .
|
||||
' ORDER BY ordering';
|
||||
|
||||
// Create a read-only list (no name) with a hidden input to store the value.
|
||||
if ((string) $this->element['readonly'] == 'true')
|
||||
{
|
||||
$html[] = JHtml::_('list.ordering', '', $query, trim($attr), $this->value, $newsfeedId ? 0 : 1);
|
||||
$html[] = '<input type="hidden" name="'.$this->name.'" value="'.htmlspecialchars($this->value).'"/>';
|
||||
}
|
||||
// Create a regular list.
|
||||
else {
|
||||
$html[] = JHtml::_('list.ordering', $this->name, $query, trim($attr), $this->value, $newsfeedId ? 0 : 1);
|
||||
}
|
||||
|
||||
return implode($html);
|
||||
}
|
||||
}
|
@ -0,0 +1 @@
|
||||
<!DOCTYPE html><title></title>
|
290
administrator/components/com_newsfeeds/models/forms/newsfeed.xml
Normal file
290
administrator/components/com_newsfeeds/models/forms/newsfeed.xml
Normal file
@ -0,0 +1,290 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<form>
|
||||
<fieldset addfieldpath="/administrator/components/com_categories/models/fields" >
|
||||
<field name="id" type="text" default="0"
|
||||
readonly="true" class="readonly" label="JGLOBAL_FIELD_ID_LABEL"
|
||||
description="JGLOBAL_FIELD_ID_DESC" />
|
||||
|
||||
<field name="name" type="text" label="JGLOBAL_TITLE"
|
||||
description="JFIELD_TITLE_DESC" class="inputbox" size="30"
|
||||
required="true" />
|
||||
|
||||
<field name="alias" type="text" label="JFIELD_ALIAS_LABEL"
|
||||
description="JFIELD_ALIAS_DESC" class="inputbox"
|
||||
size="45" />
|
||||
|
||||
<field name="published" type="list"
|
||||
label="JSTATUS" description="JFIELD_PUBLISHED_DESC"
|
||||
class="inputbox span12 small" size="1" default="1"
|
||||
>
|
||||
<option value="1">
|
||||
JPUBLISHED</option>
|
||||
<option value="0">
|
||||
JUNPUBLISHED</option>
|
||||
<option value="2">
|
||||
JARCHIVED</option>
|
||||
<option value="-2">
|
||||
JTRASHED</option>
|
||||
</field>
|
||||
|
||||
<field name="catid" type="categoryedit" extension="com_newsfeeds"
|
||||
label="JCATEGORY" description="COM_NEWSFEEDS_FIELD_CATEGORY_DESC"
|
||||
class="inputbox" required="true"
|
||||
>
|
||||
</field>
|
||||
|
||||
<field name="language" type="contentlanguage" label="JFIELD_LANGUAGE_LABEL"
|
||||
description="COM_NEWSFEEDS_FIELD_LANGUAGE_DESC" class="inputbox span12 small"
|
||||
>
|
||||
<option value="*">JALL</option>
|
||||
</field>
|
||||
|
||||
<field name="tags"
|
||||
type="tag"
|
||||
label="JTAG"
|
||||
description="JTAG_DESC"
|
||||
class="inputbox span12 small"
|
||||
multiple="true"
|
||||
>
|
||||
</field>
|
||||
|
||||
<field name="description" type="editor" buttons="true" hide="pagebreak,readmore"
|
||||
class="inputbox"
|
||||
filter="JComponentHelper::filterText"
|
||||
label="JGLOBAL_DESCRIPTION" description="COM_NEWSFEEDS_FIELD_DESCRIPTION_DESC" />
|
||||
|
||||
<field name="link" type="url" filter="url" class="inputbox"
|
||||
size="60" label="COM_NEWSFEEDS_FIELD_LINK_LABEL"
|
||||
description="COM_NEWSFEEDS_FIELD_LINK_DESC" required="true" />
|
||||
|
||||
<field name="numarticles" type="Text" class="inputbox"
|
||||
default="5" size="2" label="COM_NEWSFEEDS_FIELD_NUM_ARTICLES_LABEL"
|
||||
description="COM_NEWSFEEDS_FIELD_NUM_ARTICLES_DESC"
|
||||
required="true" />
|
||||
|
||||
<field name="cache_time" type="Text" class="inputbox"
|
||||
default="3600" size="4" label="COM_NEWSFEEDS_FIELD_CACHETIME_LABEL"
|
||||
description="JGLOBAL_FIELD_FIELD_CACHETIME_DESC"
|
||||
required="true" />
|
||||
|
||||
<field name="ordering" type="ordering" class="inputbox"
|
||||
label="JFIELD_ORDERING_LABEL" description="JFIELD_ORDERING_DESC" />
|
||||
|
||||
<field name="rtl" type="list" class="inputbox"
|
||||
default="0" label="COM_NEWSFEEDS_FIELD_RTL_LABEL"
|
||||
description="COM_NEWSFEEDS_FIELD_RTL_DESC"
|
||||
>
|
||||
<option value="0">COM_NEWSFEEDS_FIELD_VALUE_SITE
|
||||
</option>
|
||||
<option value="1">COM_NEWSFEEDS_FIELD_VALUE_LTR
|
||||
</option>
|
||||
<option value="2">COM_NEWSFEEDS_FIELD_VALUE_RTL
|
||||
</option>
|
||||
</field>
|
||||
|
||||
<field name="created" type="calendar"
|
||||
label="JGLOBAL_FIELD_CREATED_LABEL" description="JGLOBAL_FIELD_CREATED_DESC"
|
||||
class="inputbox" size="22" format="%Y-%m-%d %H:%M:%S"
|
||||
filter="user_utc" />
|
||||
|
||||
<field name="created_by" type="user"
|
||||
label="JGLOBAL_FIELD_Created_by_Label" description="JGLOBAL_FIELD_CREATED_BY_DESC" />
|
||||
|
||||
<field name="created_by_alias" type="text"
|
||||
label="JGLOBAL_FIELD_Created_by_alias_Label" description="JGLOBAL_FIELD_CREATED_BY_ALIAS_DESC"
|
||||
class="inputbox" size="20" />
|
||||
|
||||
<field name="modified" type="calendar" class="readonly"
|
||||
label="JGLOBAL_FIELD_Modified_Label" description="COM_NEWSFEEDS_FIELD_MODIFIED_DESC"
|
||||
size="22" readonly="true" format="%Y-%m-%d %H:%M:%S" filter="user_utc" />
|
||||
|
||||
<field name="modified_by" type="user" label="JGLOBAL_FIELD_MODIFIED_BY_LABEL"
|
||||
class="readonly" readonly="true" filter="unset" />
|
||||
|
||||
<field name="version" type="text" class="readonly"
|
||||
label="COM_NEWSFEEDS_FIELD_VERSION_LABEL" size="6" description="COM_NEWSFEEDS_FIELD_VERSION_DESC"
|
||||
readonly="true" filter="unset" />
|
||||
|
||||
<field name="checked_out" type="Text" class="inputbox"
|
||||
size="6" label="JGLOBAL_FIELD_CHECKEDOUT_LABEL"
|
||||
description="JGLOBAL_FIELD_CHECKEDOUT_DESC" readonly="true"
|
||||
filter="unset" />
|
||||
|
||||
<field name="checked_out_time" type="Text" class="inputbox"
|
||||
size="6" label="JGLOBAL_FIELD_CHECKEDOUT_TIME_LABEL"
|
||||
description="JGLOBAL_FIELD_CHECKEDOUT_TIME_DESC"
|
||||
readonly="true" filter="unset" />
|
||||
|
||||
<field name="publish_up" type="calendar"
|
||||
label="JGLOBAL_FIELD_PUBLISH_UP_LABEL" description="JGLOBAL_FIELD_PUBLISH_UP_DESC"
|
||||
class="inputbox" format="%Y-%m-%d %H:%M:%S" size="22"
|
||||
filter="user_utc" />
|
||||
|
||||
<field name="publish_down" type="calendar"
|
||||
label="JGLOBAL_FIELD_PUBLISH_DOWN_LABEL" description="JGLOBAL_FIELD_PUBLISH_DOWN_DESC"
|
||||
class="inputbox" format="%Y-%m-%d %H:%M:%S" size="22"
|
||||
filter="user_utc" />
|
||||
|
||||
<field name="access" type="accesslevel" label="JFIELD_ACCESS_LABEL"
|
||||
description="JFIELD_ACCESS_DESC" class="inputbox span12 small" size="1" />
|
||||
|
||||
<field name="metakey" type="textarea"
|
||||
label="JFIELD_META_KEYWORDS_LABEL" description="JFIELD_META_KEYWORDS_DESC"
|
||||
class="inputbox" rows="3" cols="30" />
|
||||
|
||||
<field name="metadesc" type="textarea"
|
||||
label="JFIELD_META_DESCRIPTION_LABEL" description="JFIELD_META_DESCRIPTION_DESC"
|
||||
class="inputbox" rows="3" cols="30" />
|
||||
|
||||
<field name="xreference" type="text"
|
||||
label="JFIELD_XREFERENCE_LABEL" description="JFIELD_XREFERENCE_DESC"
|
||||
class="inputbox" size="20" />
|
||||
|
||||
</fieldset>
|
||||
<fields name="images">
|
||||
<field
|
||||
name="image_first"
|
||||
type="media"
|
||||
label="COM_NEWSFEEDS_FIELD_FIRST_LABEL"
|
||||
description="COM_NEWSFEEDS_FIELD_FIRST_DESC" />
|
||||
<field
|
||||
name="float_first"
|
||||
type="list"
|
||||
label="COM_NEWSFEEDS_FLOAT_LABEL"
|
||||
description="COM_NEWSFEEDS_FLOAT_DESC">
|
||||
<option value="">JGLOBAL_USE_GLOBAL</option>
|
||||
<option value="right">COM_NEWSFEEDS_RIGHT</option>
|
||||
<option value="left">COM_NEWSFEEDS_LEFT</option>
|
||||
<option value="none">COM_NEWSFEEDS_NONE</option>
|
||||
</field>
|
||||
<field name="image_first_alt"
|
||||
type="text"
|
||||
label="COM_NEWSFEEDS_FIELD_IMAGE_ALT_LABEL"
|
||||
description="COM_NEWSFEEDS_FIELD_IMAGE_ALT_DESC"
|
||||
class="inputbox"
|
||||
size="20" />
|
||||
<field name="image_first_caption"
|
||||
type="text"
|
||||
label="COM_NEWSFEEDS_FIELD_IMAGE_CAPTION_LABEL"
|
||||
description="COM_NEWSFEEDS_FIELD_IMAGE_CAPTION_DESC"
|
||||
class="inputbox"
|
||||
size="20" />
|
||||
<field
|
||||
name="spacer1"
|
||||
type="spacer"
|
||||
hr="true"
|
||||
/>
|
||||
<field
|
||||
name="image_second"
|
||||
type="media"
|
||||
label="COM_NEWSFEEDS_FIELD_SECOND_LABEL"
|
||||
description="COM_NEWSFEEDS_FIELD_SECOND_DESC" />
|
||||
<field
|
||||
name="float_second"
|
||||
type="list"
|
||||
label="COM_NEWSFEEDS_FLOAT_LABEL"
|
||||
description="COM_NEWSFEEDS_FLOAT_DESC">
|
||||
<option value="">JGLOBAL_USE_GLOBAL</option>
|
||||
<option value="right">COM_NEWSFEEDS_RIGHT</option>
|
||||
<option value="left">COM_NEWSFEEDS_LEFT</option>
|
||||
<option value="none">COM_NEWSFEEDS_NONE</option>
|
||||
</field>
|
||||
<field name="image_second_alt"
|
||||
type="text"
|
||||
label="COM_NEWSFEEDS_FIELD_IMAGE_ALT_LABEL"
|
||||
description="COM_NEWSFEEDS_FIELD_IMAGE_ALT_DESC"
|
||||
class="inputbox"
|
||||
size="20" />
|
||||
<field name="image_second_caption"
|
||||
type="text"
|
||||
label="COM_NEWSFEEDS_FIELD_IMAGE_CAPTION_LABEL"
|
||||
description="COM_NEWSFEEDS_FIELD_IMAGE_CAPTION_DESC"
|
||||
class="inputbox"
|
||||
size="20" />
|
||||
</fields>
|
||||
|
||||
<fields name="params">
|
||||
<fieldset name="jbasic" label="JGLOBAL_FIELDSET_DISPLAY_OPTIONS">
|
||||
|
||||
<field name="show_feed_image" type="list"
|
||||
label="COM_NEWSFEEDS_FIELD_SHOW_FEED_IMAGE_LABEL"
|
||||
description="COM_NEWSFEEDS_FIELD_SHOW_FEED_IMAGE_DESC"
|
||||
>
|
||||
<option value="">JGLOBAL_USE_GLOBAL</option>
|
||||
<option value="0">JHIDE</option>
|
||||
<option value="1">JSHOW</option>
|
||||
</field>
|
||||
|
||||
<field name="show_feed_description" type="list"
|
||||
label="COM_NEWSFEEDS_FIELD_SHOW_FEED_DESCRIPTION_LABEL"
|
||||
description="COM_NEWSFEEDS_FIELD_SHOW_FEED_DESCRIPTION_DESC"
|
||||
>
|
||||
<option value="">JGLOBAL_USE_GLOBAL</option>
|
||||
<option value="0">JHIDE</option>
|
||||
<option value="1">JSHOW</option>
|
||||
</field>
|
||||
|
||||
<field name="show_item_description" type="list"
|
||||
label="COM_NEWSFEEDS_FIELD_SHOW_ITEM_DESCRIPTION_LABEL"
|
||||
description="COM_NEWSFEEDS_FIELD_SHOW_ITEM_DESCRIPTION_DESC"
|
||||
>
|
||||
<option value="">JGLOBAL_USE_GLOBAL</option>
|
||||
<option value="0">JHIDE</option>
|
||||
<option value="1">JSHOW</option>
|
||||
</field>
|
||||
|
||||
<field name="feed_character_count" type="text" size="6"
|
||||
default="0" label="COM_NEWSFEEDS_FIELD_CHARACTERS_COUNT_LABEL"
|
||||
description="COM_NEWSFEEDS_FIELD_CHARACTERS_COUNT_DESC" />
|
||||
<field
|
||||
name="newsfeed_layout"
|
||||
type="componentlayout"
|
||||
label="JFIELD_ALT_LAYOUT_LABEL"
|
||||
description="JFIELD_ALT_COMPONENT_LAYOUT_DESC"
|
||||
extension="com_newsfeeds"
|
||||
view="newsfeed"
|
||||
useglobal="true"
|
||||
/>
|
||||
|
||||
<field name="feed_display_order" type="list"
|
||||
label="COM_NEWSFEEDS_FIELD_FEED_DISPLAY_ORDER_LABEL"
|
||||
description="COM_NEWSFEEDS_FIELD_FEED_DISPLAY_ORDER_DESC"
|
||||
>
|
||||
<option value="">JGLOBAL_USE_GLOBAL</option>
|
||||
<option value="des">JGLOBAL_MOST_RECENT_FIRST</option>
|
||||
<option value="asc">JGLOBAL_OLDEST_FIRST</option>
|
||||
</field>
|
||||
|
||||
</fieldset>
|
||||
</fields>
|
||||
|
||||
<fields name="metadata">
|
||||
<fieldset name="jmetadata" label="JGLOBAL_FIELDSET_METADATA_OPTIONS">
|
||||
|
||||
<field name="robots"
|
||||
type="list"
|
||||
label="JFIELD_METADATA_ROBOTS_LABEL"
|
||||
description="JFIELD_METADATA_ROBOTS_DESC"
|
||||
>
|
||||
<option value="">JGLOBAL_USE_GLOBAL</option>
|
||||
<option value="index, follow">JGLOBAL_INDEX_FOLLOW</option>
|
||||
<option value="noindex, follow">JGLOBAL_NOINDEX_FOLLOW</option>
|
||||
<option value="index, nofollow">JGLOBAL_INDEX_NOFOLLOW</option>
|
||||
<option value="noindex, nofollow">JGLOBAL_NOINDEX_NOFOLLOW</option>
|
||||
</field>
|
||||
|
||||
<field name="rights" type="text"
|
||||
label="JFIELD_META_RIGHTS_LABEL" description="JFIELD_META_RIGHTS_DESC"
|
||||
required="false" filter="string" cols="30" rows="2" />
|
||||
</fieldset>
|
||||
|
||||
<field name="hits"
|
||||
type="text"
|
||||
class="readonly"
|
||||
size="6" label="JGLOBAL_HITS"
|
||||
description="COM_WEBLINKS_HITS_DESC"
|
||||
readonly="true"
|
||||
filter="unset" />
|
||||
|
||||
</fields>
|
||||
</form>
|
1
administrator/components/com_newsfeeds/models/index.html
Normal file
1
administrator/components/com_newsfeeds/models/index.html
Normal file
@ -0,0 +1 @@
|
||||
<!DOCTYPE html><title></title>
|
577
administrator/components/com_newsfeeds/models/newsfeed.php
Normal file
577
administrator/components/com_newsfeeds/models/newsfeed.php
Normal file
@ -0,0 +1,577 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Joomla.Administrator
|
||||
* @subpackage com_newsfeeds
|
||||
*
|
||||
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
defined('_JEXEC') or die;
|
||||
|
||||
JLoader::register('NewsfeedsHelper', JPATH_ADMINISTRATOR . '/components/com_newsfeeds/helpers/newsfeeds.php');
|
||||
|
||||
/**
|
||||
* Newsfeed model.
|
||||
*
|
||||
* @package Joomla.Administrator
|
||||
* @subpackage com_newsfeeds
|
||||
* @since 1.6
|
||||
*/
|
||||
class NewsfeedsModelNewsfeed extends JModelAdmin
|
||||
{
|
||||
/**
|
||||
* @var string The prefix to use with controller messages.
|
||||
* @since 1.6
|
||||
*/
|
||||
protected $text_prefix = 'COM_NEWSFEEDS';
|
||||
|
||||
/**
|
||||
* Batch copy items to a new category or current.
|
||||
*
|
||||
* @param integer $value The new category.
|
||||
* @param array $pks An array of row IDs.
|
||||
* @param array $contexts An array of item contexts.
|
||||
*
|
||||
* @return mixed An array of new IDs on success, boolean false on failure.
|
||||
*
|
||||
* @since 11.1
|
||||
*/
|
||||
protected function batchCopy($value, $pks, $contexts)
|
||||
{
|
||||
$categoryId = (int) $value;
|
||||
|
||||
$table = $this->getTable();
|
||||
$i = 0;
|
||||
|
||||
// Check that the category exists
|
||||
if ($categoryId)
|
||||
{
|
||||
$categoryTable = JTable::getInstance('Category');
|
||||
if (!$categoryTable->load($categoryId))
|
||||
{
|
||||
if ($error = $categoryTable->getError())
|
||||
{
|
||||
// Fatal error
|
||||
$this->setError($error);
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->setError(JText::_('JLIB_APPLICATION_ERROR_BATCH_MOVE_CATEGORY_NOT_FOUND'));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (empty($categoryId))
|
||||
{
|
||||
$this->setError(JText::_('JLIB_APPLICATION_ERROR_BATCH_MOVE_CATEGORY_NOT_FOUND'));
|
||||
return false;
|
||||
}
|
||||
|
||||
// Check that the user has create permission for the component
|
||||
$user = JFactory::getUser();
|
||||
if (!$user->authorise('core.create', 'com_newsfeeds.category.' . $categoryId))
|
||||
{
|
||||
$this->setError(JText::_('JLIB_APPLICATION_ERROR_BATCH_CANNOT_CREATE'));
|
||||
return false;
|
||||
}
|
||||
|
||||
// Parent exists so we let's proceed
|
||||
while (!empty($pks))
|
||||
{
|
||||
// Pop the first ID off the stack
|
||||
$pk = array_shift($pks);
|
||||
|
||||
$table->reset();
|
||||
|
||||
// Check that the row actually exists
|
||||
if (!$table->load($pk))
|
||||
{
|
||||
if ($error = $table->getError())
|
||||
{
|
||||
// Fatal error
|
||||
$this->setError($error);
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Not fatal error
|
||||
$this->setError(JText::sprintf('JLIB_APPLICATION_ERROR_BATCH_MOVE_ROW_NOT_FOUND', $pk));
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
// Alter the title & alias
|
||||
$data = $this->generateNewTitle($categoryId, $table->alias, $table->name);
|
||||
$table->name = $data['0'];
|
||||
$table->alias = $data['1'];
|
||||
|
||||
// Reset the ID because we are making a copy
|
||||
$table->id = 0;
|
||||
|
||||
// New category ID
|
||||
$table->catid = $categoryId;
|
||||
|
||||
// TODO: Deal with ordering?
|
||||
//$table->ordering = 1;
|
||||
|
||||
// Check the row.
|
||||
if (!$table->check())
|
||||
{
|
||||
$this->setError($table->getError());
|
||||
return false;
|
||||
}
|
||||
|
||||
// Store the row.
|
||||
if (!$table->store())
|
||||
{
|
||||
$this->setError($table->getError());
|
||||
return false;
|
||||
}
|
||||
|
||||
// Get the new item ID
|
||||
$newId = $table->get('id');
|
||||
|
||||
// Add the new ID to the array
|
||||
$newIds[$i] = $newId;
|
||||
$i++;
|
||||
}
|
||||
|
||||
// Clean the cache
|
||||
$this->cleanCache();
|
||||
|
||||
return $newIds;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to test whether a record can be deleted.
|
||||
*
|
||||
* @param object A record object.
|
||||
* @return boolean True if allowed to delete the record. Defaults to the permission set in the component.
|
||||
* @since 1.6
|
||||
*/
|
||||
protected function canDelete($record)
|
||||
{
|
||||
if (!empty($record->id))
|
||||
{
|
||||
if ($record->published != -2)
|
||||
{
|
||||
return;
|
||||
}
|
||||
$user = JFactory::getUser();
|
||||
|
||||
if (!empty($record->catid))
|
||||
{
|
||||
return $user->authorise('core.delete', 'com_newsfeed.category.' . (int) $record->catid);
|
||||
}
|
||||
else
|
||||
{
|
||||
return parent::canDelete($record);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to test whether a record can have its state changed.
|
||||
*
|
||||
* @param object A record object.
|
||||
* @return boolean True if allowed to change the state of the record. Defaults to the permission set in the component.
|
||||
* @since 1.6
|
||||
*/
|
||||
protected function canEditState($record)
|
||||
{
|
||||
$user = JFactory::getUser();
|
||||
|
||||
if (!empty($record->catid))
|
||||
{
|
||||
return $user->authorise('core.edit.state', 'com_newsfeeds.category.' . (int) $record->catid);
|
||||
}
|
||||
else
|
||||
{
|
||||
return parent::canEditState($record);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a Table object, always creating it.
|
||||
*
|
||||
* @param type The table type to instantiate
|
||||
* @param string A prefix for the table class name. Optional.
|
||||
* @param array Configuration array for model. Optional.
|
||||
* @return JTable A database object
|
||||
*/
|
||||
public function getTable($type = 'Newsfeed', $prefix = 'NewsfeedsTable', $config = array())
|
||||
{
|
||||
return JTable::getInstance($type, $prefix, $config);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to get the record form.
|
||||
*
|
||||
* @param array $data Data for the form.
|
||||
* @param boolean $loadData True if the form is to load its own data (default case), false if not.
|
||||
* @return JForm A JForm object on success, false on failure
|
||||
* @since 1.6
|
||||
*/
|
||||
public function getForm($data = array(), $loadData = true)
|
||||
{
|
||||
// Get the form.
|
||||
$form = $this->loadForm('com_newsfeeds.newsfeed', 'newsfeed', array('control' => 'jform', 'load_data' => $loadData));
|
||||
if (empty($form))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Determine correct permissions to check.
|
||||
if ($this->getState('newsfeed.id'))
|
||||
{
|
||||
// Existing record. Can only edit in selected categories.
|
||||
$form->setFieldAttribute('catid', 'action', 'core.edit');
|
||||
}
|
||||
else
|
||||
{
|
||||
// New record. Can only create in selected categories.
|
||||
$form->setFieldAttribute('catid', 'action', 'core.create');
|
||||
}
|
||||
|
||||
// Modify the form based on access controls.
|
||||
if (!$this->canEditState((object) $data))
|
||||
{
|
||||
// Disable fields for display.
|
||||
$form->setFieldAttribute('ordering', 'disabled', 'true');
|
||||
$form->setFieldAttribute('published', 'disabled', 'true');
|
||||
$form->setFieldAttribute('publish_up', 'disabled', 'true');
|
||||
$form->setFieldAttribute('publish_down', 'disabled', 'true');
|
||||
|
||||
// Disable fields while saving.
|
||||
// The controller has already verified this is a record you can edit.
|
||||
$form->setFieldAttribute('ordering', 'filter', 'unset');
|
||||
$form->setFieldAttribute('published', 'filter', 'unset');
|
||||
$form->setFieldAttribute('publish_up', 'filter', 'unset');
|
||||
$form->setFieldAttribute('publish_down', 'filter', 'unset');
|
||||
}
|
||||
|
||||
return $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to get the data that should be injected in the form.
|
||||
*
|
||||
* @return mixed The data for the form.
|
||||
* @since 1.6
|
||||
*/
|
||||
protected function loadFormData()
|
||||
{
|
||||
// Check the session for previously entered form data.
|
||||
$data = JFactory::getApplication()->getUserState('com_newsfeeds.edit.newsfeed.data', array());
|
||||
|
||||
if (empty($data))
|
||||
{
|
||||
$data = $this->getItem();
|
||||
|
||||
// Prime some default values.
|
||||
if ($this->getState('newsfeed.id') == 0)
|
||||
{
|
||||
$app = JFactory::getApplication();
|
||||
$data->set('catid', $app->input->get('catid', $app->getUserState('com_newsfeeds.newsfeeds.filter.category_id'), 'int'));
|
||||
}
|
||||
}
|
||||
|
||||
$this->preprocessData('com_newsfeeds.newsfeed', $data);
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to save the form data.
|
||||
*
|
||||
* @param array The form data.
|
||||
*
|
||||
* @return boolean True on success.
|
||||
* @since 3.0
|
||||
*/
|
||||
public function save($data)
|
||||
{
|
||||
$app = JFactory::getApplication();
|
||||
|
||||
// Alter the title for save as copy
|
||||
if ($app->input->get('task') == 'save2copy')
|
||||
{
|
||||
list($name, $alias) = $this->generateNewTitle($data['catid'], $data['alias'], $data['name']);
|
||||
$data['name'] = $name;
|
||||
$data['alias'] = $alias;
|
||||
$data['published'] = 0;
|
||||
}
|
||||
|
||||
if (parent::save($data))
|
||||
{
|
||||
|
||||
$assoc = isset($app->item_associations) ? $app->item_associations : 0;
|
||||
if ($assoc)
|
||||
{
|
||||
$id = (int) $this->getState($this->getName() . '.id');
|
||||
$item = $this->getItem($id);
|
||||
|
||||
// Adding self to the association
|
||||
$associations = $data['associations'];
|
||||
|
||||
foreach ($associations as $tag => $id)
|
||||
{
|
||||
if (empty($id))
|
||||
{
|
||||
unset($associations[$tag]);
|
||||
}
|
||||
}
|
||||
|
||||
// Detecting all item menus
|
||||
$all_language = $item->language == '*';
|
||||
|
||||
if ($all_language && !empty($associations))
|
||||
{
|
||||
JError::raiseNotice(403, JText::_('COM_NEWSFEEDS_ERROR_ALL_LANGUAGE_ASSOCIATED'));
|
||||
}
|
||||
|
||||
$associations[$item->language] = $item->id;
|
||||
|
||||
// Deleting old association for these items
|
||||
$db = JFactory::getDbo();
|
||||
$query = $db->getQuery(true)
|
||||
->delete('#__associations')
|
||||
->where($db->quoteName('context') . ' = ' . $db->quote('com_newsfeeds.item'))
|
||||
->where($db->quoteName('id') . ' IN (' . implode(',', $associations) . ')');
|
||||
$db->setQuery($query);
|
||||
$db->execute();
|
||||
|
||||
if ($error = $db->getErrorMsg())
|
||||
{
|
||||
$this->setError($error);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!$all_language && count($associations))
|
||||
{
|
||||
// Adding new association for these items
|
||||
$key = md5(json_encode($associations));
|
||||
$query->clear()
|
||||
->insert('#__associations');
|
||||
|
||||
foreach ($associations as $id)
|
||||
{
|
||||
$query->values($id . ',' . $db->quote('com_newsfeeds.item') . ',' . $db->quote($key));
|
||||
}
|
||||
|
||||
$db->setQuery($query);
|
||||
$db->execute();
|
||||
|
||||
if ($error = $db->getErrorMsg())
|
||||
{
|
||||
$this->setError($error);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to get a single record.
|
||||
*
|
||||
* @param integer The id of the primary key.
|
||||
*
|
||||
* @return mixed Object on success, false on failure.
|
||||
* @since 1.6
|
||||
*/
|
||||
public function getItem($pk = null)
|
||||
{
|
||||
if ($item = parent::getItem($pk))
|
||||
{
|
||||
// Convert the params field to an array.
|
||||
$registry = new JRegistry;
|
||||
$registry->loadString($item->metadata);
|
||||
$item->metadata = $registry->toArray();
|
||||
|
||||
// Convert the images field to an array.
|
||||
$registry = new JRegistry;
|
||||
$registry->loadString($item->images);
|
||||
$item->images = $registry->toArray();
|
||||
}
|
||||
|
||||
// Load associated newsfeeds items
|
||||
$app = JFactory::getApplication();
|
||||
$assoc = isset($app->item_associations) ? $app->item_associations : 0;
|
||||
|
||||
if ($assoc)
|
||||
{
|
||||
$item->associations = array();
|
||||
|
||||
if ($item->id != null)
|
||||
{
|
||||
$associations = JLanguageAssociations::getAssociations('com_newsfeeds', '#__newsfeeds', 'com_newsfeeds.item', $item->id);
|
||||
|
||||
foreach ($associations as $tag => $association)
|
||||
{
|
||||
$item->associations[$tag] = $association->id;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!empty($item->id))
|
||||
{
|
||||
$item->tags = new JHelperTags;
|
||||
$item->tags->getTagIds($item->id, 'com_newsfeeds.newsfeed');
|
||||
$item->metadata['tags'] = $item->tags;
|
||||
}
|
||||
|
||||
return $item;
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepare and sanitise the table prior to saving.
|
||||
*/
|
||||
protected function prepareTable($table)
|
||||
{
|
||||
$date = JFactory::getDate();
|
||||
$user = JFactory::getUser();
|
||||
|
||||
$table->name = htmlspecialchars_decode($table->name, ENT_QUOTES);
|
||||
$table->alias = JApplication::stringURLSafe($table->alias);
|
||||
|
||||
if (empty($table->alias))
|
||||
{
|
||||
$table->alias = JApplication::stringURLSafe($table->name);
|
||||
}
|
||||
|
||||
if (empty($table->id))
|
||||
{
|
||||
// Set the values
|
||||
$table->created = $date->toSql();
|
||||
|
||||
// Set ordering to the last item if not set
|
||||
if (empty($table->ordering))
|
||||
{
|
||||
$db = JFactory::getDbo();
|
||||
$db->setQuery('SELECT MAX(ordering) FROM #__newsfeeds');
|
||||
$max = $db->loadResult();
|
||||
|
||||
$table->ordering = $max + 1;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Set the values
|
||||
$table->modified = $date->toSql();
|
||||
$table->modified_by = $user->get('id');
|
||||
}
|
||||
|
||||
// Increment the content version number.
|
||||
$table->version++;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to change the published state of one or more records.
|
||||
*
|
||||
* @param array $pks A list of the primary keys to change.
|
||||
* @param integer $value The value of the published state.
|
||||
*
|
||||
* @return boolean True on success.
|
||||
* @since 1.6
|
||||
*/
|
||||
public function publish(&$pks, $value = 1)
|
||||
{
|
||||
$result = parent::publish($pks, $value);
|
||||
|
||||
// Clean extra cache for newsfeeds
|
||||
$this->cleanCache('feed_parser');
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* A protected method to get a set of ordering conditions.
|
||||
*
|
||||
* @param object A record object.
|
||||
* @return array An array of conditions to add to add to ordering queries.
|
||||
* @since 1.6
|
||||
*/
|
||||
protected function getReorderConditions($table)
|
||||
{
|
||||
$condition = array();
|
||||
$condition[] = 'catid = ' . (int) $table->catid;
|
||||
return $condition;
|
||||
}
|
||||
|
||||
protected function preprocessForm(JForm $form, $data, $group = 'content')
|
||||
{
|
||||
// Association newsfeeds items
|
||||
$app = JFactory::getApplication();
|
||||
$assoc = isset($app->item_associations) ? $app->item_associations : 0;
|
||||
if ($assoc)
|
||||
{
|
||||
$languages = JLanguageHelper::getLanguages('lang_code');
|
||||
|
||||
// force to array (perhaps move to $this->loadFormData())
|
||||
$data = (array) $data;
|
||||
|
||||
$addform = new SimpleXMLElement('<form />');
|
||||
$fields = $addform->addChild('fields');
|
||||
$fields->addAttribute('name', 'associations');
|
||||
$fieldset = $fields->addChild('fieldset');
|
||||
$fieldset->addAttribute('name', 'item_associations');
|
||||
$fieldset->addAttribute('description', 'COM_NEWSFEEDS_ITEM_ASSOCIATIONS_FIELDSET_DESC');
|
||||
$add = false;
|
||||
foreach ($languages as $tag => $language)
|
||||
{
|
||||
if (empty($data['language']) || $tag != $data['language'])
|
||||
{
|
||||
$add = true;
|
||||
$field = $fieldset->addChild('field');
|
||||
$field->addAttribute('name', $tag);
|
||||
$field->addAttribute('type', 'modal_newsfeed');
|
||||
$field->addAttribute('language', $tag);
|
||||
$field->addAttribute('label', $language->title);
|
||||
$field->addAttribute('translate_label', 'false');
|
||||
$field->addAttribute('edit', 'true');
|
||||
$field->addAttribute('clear', 'true');
|
||||
}
|
||||
}
|
||||
if ($add)
|
||||
{
|
||||
$form->load($addform, false);
|
||||
}
|
||||
}
|
||||
|
||||
parent::preprocessForm($form, $data, $group);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to change the title & alias.
|
||||
*
|
||||
* @param integer $parent_id The id of the parent.
|
||||
* @param string $alias The alias.
|
||||
* @param string $title The title.
|
||||
*
|
||||
* @return array Contains the modified title and alias.
|
||||
*
|
||||
* @since 3.1
|
||||
*/
|
||||
protected function generateNewTitle($category_id, $alias, $name)
|
||||
{
|
||||
// Alter the title & alias
|
||||
$table = $this->getTable();
|
||||
while ($table->load(array('alias' => $alias, 'catid' => $category_id)))
|
||||
{
|
||||
if ($name == $table->name)
|
||||
{
|
||||
$name = JString::increment($name);
|
||||
}
|
||||
$alias = JString::increment($alias, 'dash');
|
||||
}
|
||||
|
||||
return array($name, $alias);
|
||||
}
|
||||
}
|
262
administrator/components/com_newsfeeds/models/newsfeeds.php
Normal file
262
administrator/components/com_newsfeeds/models/newsfeeds.php
Normal file
@ -0,0 +1,262 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Joomla.Administrator
|
||||
* @subpackage com_newsfeeds
|
||||
*
|
||||
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
defined('_JEXEC') or die;
|
||||
|
||||
/**
|
||||
* Methods supporting a list of newsfeed records.
|
||||
*
|
||||
* @package Joomla.Administrator
|
||||
* @subpackage com_newsfeeds
|
||||
* @since 1.6
|
||||
*/
|
||||
class NewsfeedsModelNewsfeeds extends JModelList
|
||||
{
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param array An optional associative array of configuration settings.
|
||||
* @see JController
|
||||
* @since 1.6
|
||||
*/
|
||||
public function __construct($config = array())
|
||||
{
|
||||
if (empty($config['filter_fields']))
|
||||
{
|
||||
$config['filter_fields'] = array(
|
||||
'id', 'a.id',
|
||||
'name', 'a.name',
|
||||
'alias', 'a.alias',
|
||||
'checked_out', 'a.checked_out',
|
||||
'checked_out_time', 'a.checked_out_time',
|
||||
'catid', 'a.catid', 'category_title',
|
||||
'published', 'a.published',
|
||||
'access', 'a.access', 'access_level',
|
||||
'created', 'a.created',
|
||||
'created_by', 'a.created_by',
|
||||
'ordering', 'a.ordering',
|
||||
'language', 'a.language',
|
||||
'publish_up', 'a.publish_up',
|
||||
'publish_down', 'a.publish_down',
|
||||
'cache_time', 'a.cache_time',
|
||||
'numarticles',
|
||||
);
|
||||
|
||||
$app = JFactory::getApplication();
|
||||
$assoc = isset($app->item_associations) ? $app->item_associations : 0;
|
||||
if ($assoc)
|
||||
{
|
||||
$config['filter_fields'][] = 'association';
|
||||
}
|
||||
}
|
||||
|
||||
parent::__construct($config);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to auto-populate the model state.
|
||||
*
|
||||
* Note. Calling getState in this method will result in recursion.
|
||||
*
|
||||
* @param string $ordering An optional ordering field.
|
||||
* @param string $direction An optional direction (asc|desc).
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 1.6
|
||||
*/
|
||||
protected function populateState($ordering = null, $direction = null)
|
||||
{
|
||||
$app = JFactory::getApplication('administrator');
|
||||
|
||||
// Load the filter state.
|
||||
$search = $this->getUserStateFromRequest($this->context . '.filter.search', 'filter_search');
|
||||
$this->setState('filter.search', $search);
|
||||
|
||||
$accessId = $this->getUserStateFromRequest($this->context . '.filter.access', 'filter_access', null, 'int');
|
||||
$this->setState('filter.access', $accessId);
|
||||
|
||||
$state = $this->getUserStateFromRequest($this->context . '.filter.published', 'filter_published', '', 'string');
|
||||
$this->setState('filter.published', $state);
|
||||
|
||||
$categoryId = $this->getUserStateFromRequest($this->context . '.filter.category_id', 'filter_category_id', null);
|
||||
$this->setState('filter.category_id', $categoryId);
|
||||
|
||||
$language = $this->getUserStateFromRequest($this->context . '.filter.language', 'filter_language', '');
|
||||
$this->setState('filter.language', $language);
|
||||
|
||||
// force a language
|
||||
$forcedLanguage = $app->input->get('forcedLanguage');
|
||||
if (!empty($forcedLanguage))
|
||||
{
|
||||
$this->setState('filter.language', $forcedLanguage);
|
||||
$this->setState('filter.forcedLanguage', $forcedLanguage);
|
||||
}
|
||||
|
||||
$tag = $this->getUserStateFromRequest($this->context . '.filter.tag', 'filter_tag', '');
|
||||
$this->setState('filter.tag', $tag);
|
||||
|
||||
// Load the parameters.
|
||||
$params = JComponentHelper::getParams('com_newsfeeds');
|
||||
$this->setState('params', $params);
|
||||
|
||||
// List state information.
|
||||
parent::populateState('a.name', 'asc');
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to get a store id based on model configuration state.
|
||||
*
|
||||
* This is necessary because the model is used by the component and
|
||||
* different modules that might need different sets of data or different
|
||||
* ordering requirements.
|
||||
*
|
||||
* @param string A prefix for the store id.
|
||||
*
|
||||
* @return string A store id.
|
||||
*/
|
||||
protected function getStoreId($id = '')
|
||||
{
|
||||
// Compile the store id.
|
||||
$id .= ':' . $this->getState('filter.search');
|
||||
$id .= ':' . $this->getState('filter.access');
|
||||
$id .= ':' . $this->getState('filter.published');
|
||||
$id .= ':' . $this->getState('filter.category_id');
|
||||
$id .= ':' . $this->getState('filter.language');
|
||||
|
||||
return parent::getStoreId($id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Build an SQL query to load the list data.
|
||||
*
|
||||
* @return JDatabaseQuery
|
||||
*/
|
||||
protected function getListQuery()
|
||||
{
|
||||
// Create a new query object.
|
||||
$db = $this->getDbo();
|
||||
$query = $db->getQuery(true);
|
||||
$user = JFactory::getUser();
|
||||
$app = JFactory::getApplication();
|
||||
|
||||
// Select the required fields from the table.
|
||||
$query->select(
|
||||
$this->getState(
|
||||
'list.select',
|
||||
'a.id, a.name, a.alias, a.checked_out, a.checked_out_time, a.catid,' .
|
||||
' a.numarticles, a.cache_time,' .
|
||||
' a.published, a.access, a.ordering, a.language, a.publish_up, a.publish_down'
|
||||
)
|
||||
);
|
||||
$query->from($db->quoteName('#__newsfeeds') . ' AS a');
|
||||
|
||||
// Join over the language
|
||||
$query->select('l.title AS language_title')
|
||||
->join('LEFT', $db->quoteName('#__languages') . ' AS l ON l.lang_code = a.language');
|
||||
|
||||
// Join over the users for the checked out user.
|
||||
$query->select('uc.name AS editor')
|
||||
->join('LEFT', '#__users AS uc ON uc.id=a.checked_out');
|
||||
|
||||
// Join over the asset groups.
|
||||
$query->select('ag.title AS access_level')
|
||||
->join('LEFT', '#__viewlevels AS ag ON ag.id = a.access');
|
||||
|
||||
// Join over the categories.
|
||||
$query->select('c.title AS category_title')
|
||||
->join('LEFT', '#__categories AS c ON c.id = a.catid');
|
||||
|
||||
// Join over the associations.
|
||||
$assoc = isset($app->item_associations) ? $app->item_associations : 0;
|
||||
if ($assoc)
|
||||
{
|
||||
$query->select('COUNT(asso2.id)>1 as association')
|
||||
->join('LEFT', '#__associations AS asso ON asso.id = a.id AND asso.context=' . $db->quote('com_newsfeeds.item'))
|
||||
->join('LEFT', '#__associations AS asso2 ON asso2.key = asso.key')
|
||||
->group('a.id');
|
||||
}
|
||||
|
||||
// Filter by access level.
|
||||
if ($access = $this->getState('filter.access'))
|
||||
{
|
||||
$query->where('a.access = ' . (int) $access);
|
||||
}
|
||||
|
||||
// Implement View Level Access
|
||||
if (!$user->authorise('core.admin'))
|
||||
{
|
||||
$groups = implode(',', $user->getAuthorisedViewLevels());
|
||||
$query->where('a.access IN (' . $groups . ')');
|
||||
}
|
||||
|
||||
// Filter by published state.
|
||||
$published = $this->getState('filter.published');
|
||||
if (is_numeric($published))
|
||||
{
|
||||
$query->where('a.published = ' . (int) $published);
|
||||
}
|
||||
elseif ($published === '')
|
||||
{
|
||||
$query->where('(a.published IN (0, 1))');
|
||||
}
|
||||
|
||||
// Filter by category.
|
||||
$categoryId = $this->getState('filter.category_id');
|
||||
if (is_numeric($categoryId))
|
||||
{
|
||||
$query->where('a.catid = ' . (int) $categoryId);
|
||||
}
|
||||
|
||||
// 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 LIKE ' . $search . ' OR a.alias LIKE ' . $search . ')');
|
||||
}
|
||||
}
|
||||
|
||||
// Filter on the language.
|
||||
if ($language = $this->getState('filter.language'))
|
||||
{
|
||||
$query->where('a.language = ' . $db->quote($language));
|
||||
}
|
||||
|
||||
// Filter by a single tag.
|
||||
$tagId = $this->getState('filter.tag');
|
||||
if (is_numeric($tagId))
|
||||
{
|
||||
$query->where($db->quoteName('tagmap.tag_id') . ' = ' . (int) $tagId)
|
||||
->join(
|
||||
'LEFT', $db->quoteName('#__contentitem_tag_map', 'tagmap')
|
||||
. ' ON ' . $db->quoteName('tagmap.content_item_id') . ' = ' . $db->quoteName('a.id')
|
||||
. ' AND ' . $db->quoteName('tagmap.type_alias') . ' = ' . $db->quote('com_newsfeeds.newsfeed')
|
||||
);
|
||||
}
|
||||
|
||||
// Add the list ordering clause.
|
||||
$orderCol = $this->state->get('list.ordering');
|
||||
$orderDirn = $this->state->get('list.direction');
|
||||
if ($orderCol == 'a.ordering' || $orderCol == 'category_title')
|
||||
{
|
||||
$orderCol = 'c.title ' . $orderDirn . ', a.ordering';
|
||||
}
|
||||
$query->order($db->escape($orderCol . ' ' . $orderDirn));
|
||||
|
||||
//echo nl2br(str_replace('#__','jos_',$query));
|
||||
return $query;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user