Created
October 16, 2012 05:58
-
-
Save samacs/3897436 to your computer and use it in GitHub Desktop.
Simple module to get articles in Joomla >1.6
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
abstract class modBreakingNews | |
{ | |
public function getArticles(&$params) | |
{ | |
$db =& JFactory::getDbo(); | |
$application =& JFactory::getApplication(); | |
$applicationParams = $application->getParams(); | |
$model = JModel::getInstance('Articles', 'ContentModel', array('ignore_request' => true)); | |
$model->setState('list.select', 'a.title, a.introtext, a.fulltext, a.attribs, a.created, a.id, a.alias, a.catid, a.publish_up'); | |
$model->setState('params', $applicationParams); | |
$catids = $params->get('catids'); | |
// Access filter | |
$access = !JComponentHelper::getParams('com_content')->get('show_noauth'); | |
$authorised = JAccess::getAuthorisedViewLevels(JFactory::getUser()->get('id')); | |
if ($catids) { | |
if ($params->get('show_child_category_articles', 0) && (int) $params->get('levels', 0) > 0) { | |
// Get an instance of the generic categories model | |
$categories = JModel::getInstance('Categories', 'ContentModel', array('ignore_request' => true)); | |
$categories->setState('params', $applicationParams); | |
$levels = $params->get('levels', 1) ? $params->get('levels', 1) : 9999; | |
$categories->setState('filter.get_children', $levels); | |
$categories->setState('filter.published', 1); | |
$categories->setState('filter.access', $access); | |
$additional_catids = array(); | |
foreach($catids as $catid) { | |
$categories->setState('filter.parentId', $catid); | |
$recursive = true; | |
$items = $categories->getItems($recursive); | |
if ($items) { | |
foreach($items as $category) { | |
$condition = (($category->level - $categories->getParent()->level) <= $levels); | |
if ($condition) { | |
$additional_catids[] = $category->id; | |
} | |
} | |
} | |
} | |
$catids = array_unique(array_merge($catids, $additional_catids)); | |
} | |
} | |
$model->setState('filter.category_id', $catids); | |
$model->setState('filter.access', $access); | |
// Filter by language | |
$model->setState('filter.language',$application->getLanguageFilter()); | |
// Ordering | |
$model->setState('list.ordering', $params->get('article_ordering', 'a.ordering')); | |
$model->setState('list.direction', $params->get('article_ordering_direction', 'ASC')); | |
$model->setState('list.start', 0); | |
$count = array_sum(explode(',', trim($params->get('articles_per_column')))); | |
$model->setState('list.limit', $count); | |
// New Parameters | |
$model->setState('filter.featured', $params->get('show_front', 'show')); | |
$model->setState('filter.published', 1); | |
$date_filtering = $params->get('date_filtering', 'off'); | |
if ($date_filtering !== 'off') { | |
$model->setState('filter.date_filtering', $date_filtering); | |
$model->setState('filter.date_field', $params->get('date_field', 'a.created')); | |
$model->setState('filter.start_date_range', $params->get('start_date_range', '1000-01-01 00:00:00')); | |
$model->setState('filter.end_date_range', $params->get('end_date_range', '9999-12-31 23:59:59')); | |
$model->setState('filter.relative_date', $params->get('relative_date', 30)); | |
} | |
// Display options | |
$show_date = $params->get('show_date', 0); | |
$show_date_field = $params->get('show_date_field', 'created'); | |
$show_date_format = $params->get('show_date_format', 'Y-m-d H:i:s'); | |
$show_category = $params->get('show_category', 0); | |
$show_hits = $params->get('show_hits', 0); | |
$show_author = $params->get('show_author', 0); | |
$show_images = $params->get('show_images', 1); | |
$show_introtext = $params->get('show_introtext', 0); | |
$truncate_introtext = $params->get('truncate_introtext', 0); | |
$introtext_limit = $params->get('introtext_limit', 100); | |
$articles = $model->getItems(); | |
return $articles; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8"?> | |
<extension type="module" version="2.5" method="upgrade" client="site"> | |
<name>Breaking News</name> | |
<author>Saul Martinez</author> | |
<authorEmail>[email protected]</authorEmail> | |
<authorUrl>http://sharkwebintelligence.com</authorUrl> | |
<creationDate>February 2012</creationDate> | |
<version>1.0</version> | |
<description> | |
<![CDATA[ | |
<h3>Breaking News</h3> | |
<p>Shows featured articles in different layouts.</p> | |
]]> | |
</description> | |
<files> | |
<filename module="mod_breaking_news">mod_breaking_news.php</filename> | |
<filename>helper.php</filename> | |
<filename>mod_breaking_news.xml</filename> | |
<folder>css</folder> | |
<folder>images</folder> | |
<folder>js</folder> | |
<folder>tmpl</folder> | |
</files> | |
<languages> | |
<language tag="es-ES">es-ES.mod_breaking_news.ini</language> | |
</languages> | |
<config> | |
<fields name="params"> | |
<fieldset name="basic"> | |
<field | |
name="catids" | |
type="category" | |
extension="com_content" | |
size="10" | |
multiple="true" | |
label="JCATEGORY" | |
description="MOD_BREAKING_NEWS_CATEGORY_LABEL"> | |
<option value="">MOD_BREAKING_NEWS_ALL_CATEGORIES_OPTION</option> | |
</field> | |
</fieldset> | |
<fieldset name="filtering" label="MOD_BREAKING_NEWS_FILTERING_FIELDSET_LABEL"> | |
<field | |
name="show_child_category_articles" | |
type="radio" | |
default="0" | |
label="MOD_BREAKING_NEWS_SHOWCHILDCATEGORYARTICLES_LABEL" | |
description="MOD_BREAKING_NEWS_SHOWCHILDCATEGORYARTICLES_DESC"> | |
<option value="1">MOD_BREAKING_NEWS_INCLUDE_OPTION</option> | |
<option value="0">MOD_BREAKING_NEWS_EXCLUDE_OPTION</option> | |
</field> | |
<field | |
name="levels" | |
type="text" | |
default="1" | |
label="MOD_BREAKING_NEWS_CATEGORY_DEPTH_LABEL" | |
description="MOD_BREAKING_NEWS_CATEGORY_DEPTH_DESC" /> | |
<field | |
name="show_front" | |
type="radio" | |
default="show" | |
label="MOD_BREAKING_NEWS_SHOWFEATURED_LABEL" | |
description="MOD_BREAKING_NEWS_SHOWFEATURED_DESC"> | |
<option value="show">JSHOW</option> | |
<option value="hide">JHIDE</option> | |
<option value="only">MOD_BREAKING_NEWS_ONLYFEATURED_OPTION</option> | |
</field> | |
<field | |
name="count" | |
type="text" | |
default="20" | |
label="MOD_BREAKING_NEWS_COUNT_LABEL" | |
description="MOD_BREAKING_NEWS_COUNT_DESC" /> | |
<field | |
name="date_filtering" | |
type="radio" | |
default="off" | |
label="MOD_BREAKING_NEWS_DATEFILTERING_LABEL" | |
description="MOD_BREAKING_NEWS_DATEFILTERING_DESC"> | |
<option value="off">MOD_BREAKING_NEWS_OPTION_OFF</option> | |
<option value="range">MOD_BREAKING_NEWS_OPTION_DATERANGE</option> | |
<option value="relative">MOD_BREAKING_NEWS_OPTION_RELATIVEDAY</option> | |
</field> | |
<field | |
name="date_field" | |
type="list" | |
default="a.created" | |
label="MOD_BREAKING_NEWS_DATERANGEFIELD_LABEL" | |
description="MOD_BREAKING_NEWS_DATERANGEFIELD_DESC"> | |
<option value="a.created">MOD_BREAKING_NEWS_OPTION_CREATED</option> | |
<option value="a.modified">MOD_BREAKING_NEWS_OPTION_MODIFIED</option> | |
<option value="a.publish_up">MOD_BREAKING_NEWS_OPTION_STARTPUBLISHING</option> | |
</field> | |
<field | |
name="start_date_range" | |
type="calendar" | |
format="%Y-%m-%d %H:%M:%S" | |
label="MOD_BREAKING_NEWS_STARTDATE_LABEL" | |
description="MOD_BREAKING_NEWS_STARTDATE_DESC" | |
size="22" | |
filter="user_utc" /> | |
<field | |
name="end_date_range" | |
type="calendar" | |
format="%Y-%m-%d %H:%M:%S" | |
label="MOD_BREAKING_NEWS_ENDDATE_LABEL" | |
description="MOD_BREAKING_NEWS_ENDDATE_DESC" | |
size="22" | |
filter="user_utc" /> | |
<field | |
name="relative_date" | |
type="text" | |
default="30" | |
label="MOD_BREAKING_NEWS_RELATIVEDATE_LABEL" | |
description="MOD_BREAKING_NEWS_RELATIVEDATE_DESC" /> | |
</fieldset> | |
<fieldset name="ordering" label="MOD_BREAKING_NEWS_ORDERING_FIELDSET_LABEL"> | |
<field | |
name="article_ordering" | |
type="list" | |
default="a.title" | |
label="MOD_BREAKING_NEWS_ARTICLEORDERING_LABEL" | |
description="MOD_BREAKING_NEWS_ARTICLEORDERING_DESC"> | |
<option value="a.ordering">MOD_BREAKING_NEWS_OPTION_ORDERING</option> | |
<option value="fp.ordering">MOD_BREAKING_NEWS_OPTION_ORDERINGFEATURED</option> | |
<option value="a.hits">MOD_BREAKING_NEWS_OPTION_HITS</option> | |
<option value="a.title">JGLOBAL_TITLE</option> | |
<option value="a.id">MOD_BREAKING_NEWS_OPTION_ID</option> | |
<option value="a.alias">JFIELD_ALIAS_LABEL</option> | |
<option value="a.created">MOD_BREAKING_NEWS_OPTION_CREATED</option> | |
<option value="modified">MOD_BREAKING_NEWS_OPTION_MODIFIED</option> | |
<option value="publish_up">MOD_BREAKING_NEWS_OPTION_STARTPUBLISHING</option> | |
<option value="a.publish_down">MOD_BREAKING_NEWS_OPTION_FINISHPUBLISHING</option> | |
</field> | |
<field | |
name="article_ordering_direction" | |
type="list" | |
default="ASC" | |
label="MOD_BREAKING_NEWS_ARTICLEORDERINGDIR_LABEL" | |
description="MOD_BREAKING_NEWS_ARTICLEORDERINGDIR_DESC"> | |
<option value="DESC">MOD_BREAKING_NEWS_OPTION_DESCENDING</option> | |
<option value="ASC">MOD_BREAKING_NEWS_OPTION_ASCENDING</option> | |
</field> | |
</fieldset> | |
<fieldset name="display" label="MOD_BREAKING_NEWS_DISPLAY_FIELDSET_LABEL"> | |
<field | |
name="link_titles" | |
type="radio" | |
default="1" | |
label="MOD_BREAKING_NEWS_LINKTITLES_LABEL" | |
description="MOD_BREAKING_NEWS_LINKTITLES_DESC"> | |
<option value="1">JYES</option> | |
<option value="0">JNO</option> | |
</field> | |
<field | |
name="show_date" | |
type="radio" | |
default="0" | |
label="JDATE" | |
description="MOD_BREAKING_NEWS_FIELD_SHOWDATE_DESC"> | |
<option value="1">JSHOW</option> | |
<option value="0">JHIDE</option> | |
</field> | |
<field | |
name="show_date_field" | |
type="list" | |
default="created" | |
label="MOD_BREAKING_NEWS_DATEFIELD_LABEL" | |
description="MOD_BREAKING_NEWS_DATEFIELD_DESC"> | |
<option value="created">MOD_BREAKING_NEWS_OPTION_CREATED</option> | |
<option value="modified">MOD_BREAKING_NEWS_OPTION_MODIFIED</option> | |
<option value="publish_up">MOD_BREAKING_NEWS_OPTION_STARTPUBLISHING</option> | |
</field> | |
<field | |
name="show_date_format" | |
type="text" | |
default="Y-m-d H:i:s" | |
label="MOD_BREAKING_NEWS_DATEFIELDFORMAT_LABEL" | |
description="MOD_BREAKING_NEWS_DATEFIELDFORMAT_DESC" /> | |
<field | |
name="show_category" | |
type="radio" | |
default="0" | |
label="JCATEGORY" | |
description="MOD_BREAKING_NEWS_SHOWCATEGORY_DESC"> | |
<option value="1">JSHOW</option> | |
<option value="0">JHIDE</option> | |
</field> | |
<field | |
name="show_hits" | |
type="radio" | |
default="0" | |
label="MOD_BREAKING_NEWS_SHOWHITS_LABEL" | |
description="MOD_BREAKING_NEWS_SHOWHITS_DESC"> | |
<option value="1">JSHOW</option> | |
<option value="0">JHIDE</option> | |
</field> | |
<field | |
name="show_author" | |
type="radio" | |
default="0" | |
label="JAUTHOR" | |
description="MOD_BREAKING_NEWS_SHOWAUTHOR_DESC"> | |
<option value="1">JSHOW</option> | |
<option value="0">JHIDE</option> | |
</field> | |
<field | |
name="show_images" | |
type="text" | |
default="1, 0" | |
label="MOD_BREAKING_NEWS_SHOW_IMAGES_LABEL" | |
description="MOD_BREAKING_NEWS_SHOW_IMAGES_DESC" /> | |
<field | |
name="image_width" | |
type="text" | |
default="350" | |
label="MOD_BREAKING_NEWS_IMAGE_WIDTH_LABEL" | |
description="MOD_BREAKING_NEWS_IMAGE_WIDTH_DESC" /> | |
<field | |
name="image_height" | |
type="text" | |
default="233" | |
label="MOD_BREAKING_NEWS_IMAGE_HEIGHT_LABEL" | |
description="MOD_BREAKING_NEWS_IMAGE_HEIGHT_DESC" /> | |
<field | |
name="show_introtext" | |
type="radio" | |
default="0" | |
label="MOD_BREAKING_NEWS_SHOWINTROTEXT_LABEL" | |
description="MOD_BREAKING_NEWS_SHOWINTROTEXT_DESC"> | |
<option value="1">JSHOW</option> | |
<option value="0">JHIDE</option> | |
</field> | |
<field | |
name="truncate_introtext" | |
type="radio" | |
default="0" | |
label="MOD_BREAKING_NEWS_TRUNCATE_INTROTEXT_LABEL" | |
description="MOD_BREAKING_NEWS_TRUNCATE_INTROTEXT_DESC"> | |
<option value="1">JYES</option> | |
<option value="0">JNO</option> | |
</field> | |
<field | |
name="introtext_limit" | |
type="text" | |
default="100" | |
label="MOD_BREAKING_NEWS_INTROTEXTLIMIT_LABEL" | |
description="MOD_BREAKING_NEWS_INTROTEXTLIMIT_DESC" /> | |
<field | |
name="show_readmore" | |
label="JGLOBAL_SHOW_READMORE_LABEL" | |
description="JGLOBAL_SHOW_READMORE_DESC" | |
type="radio" | |
default="0"> | |
<option value="1">JSHOW</option> | |
<option value="0">JHIDE</option> | |
</field> | |
<field | |
name="show_readmore_title" | |
label="JGLOBAL_SHOW_READMORE_TITLE_LABEL" | |
description="JGLOBAL_SHOW_READMORE_TITLE_DESC" | |
type="radio" | |
default="1"> | |
<option value="1">JSHOW</option> | |
<option value="0">JHIDE</option> | |
</field> | |
<field | |
name="readmore_limit" | |
type="text" | |
default="15" | |
label="JGLOBAL_SHOW_READMORE_LIMIT_LABEL" | |
description="JGLOBAL_SHOW_READMORE_LIMIT_DESC" /> | |
</fieldset> | |
<fieldset name="advanced"> | |
<field | |
name="layout" | |
type="modulelayout" | |
label="JFIELD_ALT_LAYOUT_LABEL" | |
description="JFIELD_ALT_MODULE_LAYOUT_DESC" /> | |
<field | |
name="moduleclass_sfx" | |
type="text" | |
label="COM_MODULES_FIELD_MODULECLASS_SFX_LABEL" | |
description="COM_MODULES_FIELD_MODULECLASS_SFX_DESC" /> | |
<field | |
name="owncache" | |
type="list" | |
default="1" | |
label="COM_MODULES_FIELD_CACHING_LABEL" | |
description="COM_MODULES_FIELD_CACHING_DESC" > | |
<option value="1">JGLOBAL_USE_GLOBAL</option> | |
<option value="0">COM_MODULES_FIELD_VALUE_NOCACHING</option> | |
</field> | |
<field | |
name="cache_time" | |
type="text" | |
default="900" | |
label="COM_MODULES_FIELD_CACHE_TIME_LABEL" | |
description="COM_MODULES_FIELD_CACHE_TIME_DESC" /> | |
</fieldset> | |
</fields> | |
</config> | |
</extension> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment