primo commit

This commit is contained in:
2024-12-17 17:34:10 +01:00
commit e650f8df99
16435 changed files with 2451012 additions and 0 deletions

View File

@ -0,0 +1,139 @@
<?php
/**
* @package Articles Field
* @version 4.3.2
*
* @author Peter van Westen <info@regularlabs.com>
* @link https://regularlabs.com
* @copyright Copyright © 2024 Regular Labs All Rights Reserved
* @license GNU General Public License version 2 or later
*/
use Bluecoder\Component\Jfilters\Administrator\Model\Filter\Option\Collection as JfiltersCollection;
use Joomla\CMS\Language\Text as JText;
use RegularLabs\Library\Document as RL_Document;
use RegularLabs\Library\Extension as RL_Extension;
use RegularLabs\Library\FieldsPlugin;
use RegularLabs\Plugin\Fields\Articles\Helper;
defined('_JEXEC') or die;
if ( ! is_file(JPATH_LIBRARIES . '/regularlabs/regularlabs.xml')
|| ! class_exists('RegularLabs\Library\Parameters')
|| ! class_exists('RegularLabs\Library\DownloadKey')
|| ! class_exists('RegularLabs\Library\FieldsPlugin')
)
{
return;
}
if ( ! RL_Document::isJoomlaVersion(4))
{
RL_Extension::disable('articles', 'plugin', 'fields');
RL_Document::adminError(
JText::sprintf('RL_PLUGIN_HAS_BEEN_DISABLED', JText::_('ARTICLESFIELD'))
);
return;
}
if (true)
{
class PlgFieldsArticles extends FieldsPlugin
{
/**
* Prepares the field value.
*
* @param string $context The context.
* @param stdclass $item The item.
* @param stdclass $field The field.
*
* @return string
*
* @since 3.7.0
*/
public function onCustomFieldsPrepareField($context, $item, $field)
{
// Check if the field should be processed by us
if (!$this->isTypeSupported($field->type)) {
return;
}
// The field's rawvalue should be an array
if (!is_array($field->rawvalue)) {
$field->rawvalue = (array) $field->rawvalue;
}
return parent::onCustomFieldsPrepareField($context, $item, $field);
}
public function onJFiltersOptionsAfterCreation(JfiltersCollection $options)
{
$attributes = $options->getFilterItem()->getAttributes();
if ($attributes->get('type') !== $this->_name)
{
return $options;
}
$sort_by = $attributes->get('options_sort_by', 'title');
$sort_direction = strtoupper($attributes->get('options_sort_direction', 'ASC'));
$options_by_id = [];
foreach ($options as $option)
{
$label = $option->getLabel();
$options_by_id[$label] = $option;
}
$ids = array_keys($options_by_id);
$articles = Helper::getArticlesByIds($ids);
$this->orderArticles($articles, $sort_by, $sort_direction, $options_by_id);
$options->clearItems(false);
foreach ($articles as $article)
{
$option = $options_by_id[$article->id];
if ( ! empty($article->title))
{
$option->setLabel($article->title);
}
$options->addItem($option);
}
return $options;
}
private function orderArticles(&$articles, $sort_by, $sort_direction, $options)
{
if ($sort_by === 'label')
{
Helper::orderArticles($articles, 'title', $sort_direction);
return;
}
$ordered = [];
foreach ($articles as $article)
{
$order = ($sort_direction === 'DESC')
? (10000000 - $options[$article->id]->getData()->count)
: str_pad($options[$article->id]->getData()->count, 8, '0', STR_PAD_LEFT);
$ordered[$order . '.' . $article->title . '.' . $article->id] = $article;
}
ksort($ordered);
$articles = array_values($ordered);
}
}
}

View File

@ -0,0 +1,38 @@
<?xml version="1.0" encoding="utf-8"?>
<extension version="4" type="plugin" group="fields" method="upgrade">
<name>PLG_FIELDS_ARTICLES</name>
<description>PLG_FIELDS_ARTICLES_DESC</description>
<version>4.3.2</version>
<creationDate>October 2024</creationDate>
<author>Regular Labs (Peter van Westen)</author>
<authorEmail>info@regularlabs.com</authorEmail>
<authorUrl>https://regularlabs.com</authorUrl>
<copyright>Copyright © 2024 Regular Labs - All Rights Reserved</copyright>
<license>GNU General Public License version 2 or later</license>
<namespace path="src">RegularLabs\Plugin\Fields\Articles</namespace>
<scriptfile>script.install.php</scriptfile>
<files>
<file plugin="articles">articles.php</file>
<folder>language</folder>
<folder>layouts</folder>
<folder>params</folder>
<folder>src</folder>
<folder>tmpl</folder>
</files>
<config>
<fields name="params" addfieldprefix="RegularLabs\Library\Form\Field">
<fieldset name="basic">
<field name="@load_script_descriptions" type="LoadMedia" filetype="script" file="regularlabs.admin-form-descriptions"/>
<field name="@load_language_regularlabs" type="LoadLanguage" extension="plg_system_regularlabs"/>
<field name="@license" type="License" extension="ARTICLESFIELD"/>
<field name="@version" type="Version" extension="ARTICLESFIELD"/>
<field name="@header" type="Header" label="ARTICLESFIELD" description="ARTICLESFIELD_DESC" url="https://regularlabs.com/articlesfield"/>
<field name="multiple" type="Radio" class="btn-group rl-btn-group btn-group-md btn-group-yesno" default="0" label="RL_FIELD_PARAM_MULTIPLE" description="RL_FIELD_PARAM_MULTIPLE_DESC">
<option value="1">JYES</option>
<option value="0">JNO</option>
</field>
<field name="@note__select_style" type="OnlyPro" label="RL_FIELD_SELECT_STYLE" description="RL_FIELD_SELECT_STYLE_DESC"/>
</fieldset>
</fields>
</config>
</extension>

View File

@ -0,0 +1,72 @@
;; @package Articles Field
;; @version 4.3.2
;;
;; @author Peter van Westen <info@regularlabs.com>
;; @link https://regularlabs.com
;; @copyright Copyright © 2024 Regular Labs All Rights Reserved
;; @license GNU General Public License version 2 or later
;;
;; @translate Want to help with translations? See: https://regularlabs.com/translate
PLG_FIELDS_ARTICLES="Fields - Regular Labs - Articles"
PLG_FIELDS_ARTICLES_DESC="Articles Field - connect other articles to your content item"
ARTICLESFIELD="Articles Field"
ARTICLESFIELD_DESC="<p>The Articles field enables you to link to other articles from the current item.</p>"
PLG_FIELDS_ARTICLES_LABEL="Articles (%s)"
FLDA_ADD_LINKED_FIELDS_FIELDS="Linked Fields"
FLDA_ADD_LINKED_FIELDS_FIELDS_DESC="Select the Articles Fields through which other articles are linking to the current article."
FLDA_ARTICLE_GROUPING="Grouping"
FLDA_ARTICLE_GROUPING_DESC="Select how you would like the articles to be grouped in the article select field."
FLDA_CATEGORIES_DESC="Select the categories to limit the articles by. Only articles under these categories will be available to select in the select list."
FLDA_CUSTOM_FIELD_DESC="Select the custom field value to use. Only articles having the given value for the given custom field will be available to select in the select list."
FLDA_CUSTOM_HTML="Custom HTML"
FLDA_CUSTOM_HTML_DESC="Set a custom HTML as the layout for each element. You can use [data] tags to output available article data."
FLDA_FIELD_TYPE="Field Type"
FLDA_FIELD_TYPE_DESC="Select the type of field to use."
FLDA_FILTER_BY_AUTHORS="Filter by Authors"
FLDA_FILTER_BY_AUTHORS_DESC="Select to filter by Authors"
FLDA_FILTER_BY_CATEGORIES="Filter by Categories"
FLDA_FILTER_BY_CATEGORIES_DESC="Select to filter by Categories"
FLDA_FILTER_BY_CUSTOM_FIELDS="Filter by Custom Fields"
FLDA_FILTER_BY_CUSTOM_FIELDS_DESC="Select to filter by Custom Fields"
FLDA_FILTER_BY_LANGUAGE="Filter by Language"
FLDA_FILTER_BY_LANGUAGE_DESC="Select to filter by Language"
FLDA_FILTER_BY_TAGS="Filter by Tags"
FLDA_FILTER_BY_TAGS_DESC="Select to filter by Tags"
FLDA_FILTER_SHOW_CATEGORY="Show Category Title"
FLDA_FILTER_SHOW_CATEGORY_DESC="Select to show the name of the Category near the title of the article in the article select field. This only applies when the select includes articles from multiple categories."
FLDA_FILTER_SHOW_UNPUBLISHED="Show Unpublished Articles"
FLDA_FILTER_SHOW_UNPUBLISHED_DESC="Select to show unpublished articles in the article select field. Selected unpublished articles will only show on the frontend output when they get published."
FLDA_IGNORE_FILTER_FOR_ADMINISTRATORS="Ignore for Administrators"
FLDA_IGNORE_FILTER_FOR_ADMINISTRATORS_DESC="Select to ignore the filter field for administrators (users with core admin rights)."
FLDA_INPUT_OPTIONS="Input Select Options"
FLDA_INPUT_OPTIONS_DESC="These options only affect the article select field. They do not affect the frontend display."
FLDA_LANGUAGE_CURRENT="Current Language"
FLDA_LANGUAGE_CURRENT_DESC="Select to use the current articles language to limit the articles by. Only articles assigned to this language will be available to select in the select list."
FLDA_LANGUAGE_DESC="Select the language to limit the articles by. Only articles assigned t this language will be available to select in the select list."
FLDA_LAST_SEPARATOR="Separator"
FLDA_LAST_SEPARATOR_DESC="Choose a different separator to place in between the last 2 elements."
FLDA_LAYOUT_CUSTOM_HTML="Custom HTML"
FLDA_LAYOUT_TITLE="Title"
FLDA_LAYOUT_TITLE_CUSTOM_FIELD="Title + Custom Field"
FLDA_LIMIT="Limit"
FLDA_LINK_ARTICLES="Articles"
FLDA_LINK_ARTICLES_DESC="This field enables you to select other articles to link to."
FLDA_LINK_TITLE="Link Title"
FLDA_LINK_TITLE_DESC="Select to add a link to the article titles."
FLDA_LINKED_ARTICLES="Articles - Linked"
FLDA_LINKED_ARTICLES_DESC="This field will show articles linking to the current article (via other Articles Fields)."
FLDA_ORDER_OF_SELECTION="Order of Selection"
FLDA_OUTPUT_LIMIT="Output Limit"
FLDA_OUTPUT_LIMIT_DESC="Set the maximum number of articles to show on the frontend. Set to 0 to show all."
FLDA_OUTPUT_TITLE_CUSTOM_FIELD="[[%1:title%]] ([[%2:custom field%]])"
FLDA_SEPARATOR="Separator"
FLDA_SEPARATOR_DESC="Choose a separator for multiple elements."
FLDA_TAGS_DESC="Select the tags to limit the articles by. Only articles that have any of these tags will be available to select in the select list."
FLDA_USE_LAST_SEPARATOR="Use Last Separator"
FLDA_USE_LAST_SEPARATOR_DESC="Select to use a different separator to place in between the last 2 elements."
FLDA_USE_SEPARATOR="Use Separator"
FLDA_USE_SEPARATOR_DESC="Select to use a separator for multiple elements."
FLDA_USERS_DESC="Select the users to limit the articles by. Only articles created by these users will be available to select in the select list."

View File

@ -0,0 +1,12 @@
;; @package Articles Field
;; @version 4.3.2
;;
;; @author Peter van Westen <info@regularlabs.com>
;; @link https://regularlabs.com
;; @copyright Copyright © 2024 Regular Labs All Rights Reserved
;; @license GNU General Public License version 2 or later
;;
;; @translate Want to help with translations? See: https://regularlabs.com/translate
PLG_FIELDS_ARTICLES="Fields - Regular Labs - Articles"
PLG_FIELDS_ARTICLES_DESC="Articles Field - connect other articles to your content item"

View File

@ -0,0 +1,16 @@
;; @package Articles Field
;; @version 4.3.2
;;
;; @author Peter van Westen <info@regularlabs.com>
;; @link https://regularlabs.com
;; @copyright Copyright © 2024 Regular Labs All Rights Reserved
;; @license GNU General Public License version 2 or later
;;
;; @translate Want to help with translations? See: https://regularlabs.com/translate
PLG_FIELDS_ARTICLESLINKED="Fields - Regular Labs - Articles (Linked)"
PLG_FIELDS_ARTICLESLINKED_DESC="Articles Field - connect other articles to your content item"
PLG_FIELDS_ARTICLESLINKED_LABEL="Articles - Linked (%s)"
FLDA_THE_MAIN_FIELD_PLUGIN="the main Articles Field plugin"

View File

@ -0,0 +1,12 @@
;; @package Articles Field
;; @version 4.3.2
;;
;; @author Peter van Westen <info@regularlabs.com>
;; @link https://regularlabs.com
;; @copyright Copyright © 2024 Regular Labs All Rights Reserved
;; @license GNU General Public License version 2 or later
;;
;; @translate Want to help with translations? See: https://regularlabs.com/translate
PLG_FIELDS_ARTICLESLINKED="Fields - Regular Labs - Articles (Linked)"
PLG_FIELDS_ARTICLESLINKED_DESC="Articles Field - connect other articles to your content item"

View File

@ -0,0 +1,56 @@
;; @package Articles Field
;; @version 1.2.1
;;
;; @author Peter van Westen <info@regularlabs.com>
;; @link http://www.regularlabs.com
;; @copyright Copyright © 2018 Regular Labs All Rights Reserved
;; @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL
;;
;; @translate Want to help with translations? See: https://www.regularlabs.com/translate
;;
;; @translation Tradotto da: Roberto Nervi <r.nervi@tiscali.it>, $Red <redwebsite@altervista.org> RedWebSite (redwebsite.altervista.org)
; PLG_FIELDS_ARTICLES="Fields - Regular Labs - Articles"
; PLG_FIELDS_ARTICLES_DESC="Articles Field - connect other articles to your content item"
; ARTICLES_FIELD="Articles Field"
; ARTICLES_FIELD_DESC="<p>The Articles field enables you to link to other articles from the current item.</p>"
PLG_FIELDS_ARTICLES_LABEL="Articoli (%s)"
; FLDA_ADD_LINKED_FIELDS_FIELDS="Linked Fields"
; FLDA_ADD_LINKED_FIELDS_FIELDS_DESC="Select the Articles fields through which other articles are linking to the current article."
; FLDA_CATEGORIES_DESC="Select the categories to limit the articles by. Only articles under these categories will be available to select in the select list."
; FLDA_CUSTOM_FIELD_DESC="Select the custom field value to use. Only articles having the given value for the given custom field will be available to select in the select list."
FLDA_CUSTOM_HTML="HTML Personalizzato"
; FLDA_CUSTOM_HTML_DESC="Set a custom HTML as the layout for each element. You can use [data] tags to output available article data."
FLDA_FIELD_TYPE="Tipo di campo"
; FLDA_FIELD_TYPE_DESC="Select the type of field to use."
; FLDA_FILTER_BY_AUTHORS="Filter by Authors"
; FLDA_FILTER_BY_AUTHORS_DESC="Select to filter by Authors"
FLDA_FILTER_BY_CATEGORIES="Filtra per Categorie"
; FLDA_FILTER_BY_CATEGORIES_DESC="Select to filter by Categories"
; FLDA_FILTER_BY_CUSTOM_FIELDS="Filter by Custom Fields"
; FLDA_FILTER_BY_CUSTOM_FIELDS_DESC="Select to filter by Custom Fields"
; FLDA_FILTER_BY_LANGUAGE="Filter by Language"
; FLDA_FILTER_BY_LANGUAGE_DESC="Select to filter by Language"
; FLDA_FILTER_BY_TAGS="Filter by Tags"
; FLDA_FILTER_BY_TAGS_DESC="Select to filter by Tags"
; FLDA_LANGUAGE_CURRENT="Current Language"
; FLDA_LANGUAGE_CURRENT_DESC="Select the use the current articles language to limit the articles by. Only articles assigned t this language will be available to select in the select list."
; FLDA_LANGUAGE_DESC="Select the language to limit the articles by. Only articles assigned t this language will be available to select in the select list."
FLDA_LAYOUT_CUSTOM_HTML="HTML Personalizzato"
FLDA_LAYOUT_TITLE="Titolo"
; FLDA_LAYOUT_TITLE_CUSTOM_FIELD="Title + Custom Field"
; FLDA_LINK_ARTICLES="Link Articles"
; FLDA_LINK_ARTICLES_DESC="This field enables you to select other articles to link to."
; FLDA_LINK_TITLE="Link Title"
; FLDA_LINK_TITLE_DESC="Select to add a link to the article titles."
; FLDA_LINKED_ARTICLES="Show Linked Articles"
; FLDA_LINKED_ARTICLES_DESC="This field will show articles linking to the current article (via other Articles fields)."
; FLDA_OUTPUT_TITLE_CUSTOM_FIELD="[[%1:title%]] ([[%2:custom field%]])"
FLDA_SEPARATOR="Separatore"
; FLDA_SEPARATOR_DESC="Choose a separator for repeated elements."
; FLDA_TAGS_DESC="Select the tags to limit the articles by. Only articles that have any of these tags will be available to select in the select list."
; FLDA_USE_SEPARATOR="Use Separator"
; FLDA_USE_SEPARATOR_DESC="Select to use a separator for repeated elements."
; FLDA_USERS_DESC="Select the users to limit the articles by. Only articles created by these users will be available to select in the select list."

View File

@ -0,0 +1,14 @@
;; @package Articles Field
;; @version 1.2.1
;;
;; @author Peter van Westen <info@regularlabs.com>
;; @link http://www.regularlabs.com
;; @copyright Copyright © 2018 Regular Labs All Rights Reserved
;; @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL
;;
;; @translate Want to help with translations? See: https://www.regularlabs.com/translate
;;
;; @translation Tradotto da: Roberto Nervi <r.nervi@tiscali.it>, $Red <redwebsite@altervista.org> RedWebSite (redwebsite.altervista.org)
; PLG_FIELDS_ARTICLES="Fields - Regular Labs - Articles"
; PLG_FIELDS_ARTICLES_DESC="Articles Field - connect other articles to your content item"

View File

@ -0,0 +1,26 @@
<?php
/**
* @package Articles Field
* @version 4.3.2
*
* @author Peter van Westen <info@regularlabs.com>
* @link https://regularlabs.com
* @copyright Copyright © 2024 Regular Labs All Rights Reserved
* @license GNU General Public License version 2 or later
*/
defined('_JEXEC') or die;
use RegularLabs\Plugin\Fields\Articles\Helper;
/*
* @var array $displayData
* @var object $layout
* @var object $field
* @var string $layout_type
*/
extract($displayData);
$ids = (array) $field->value;
echo Helper::renderLayout($ids, $layout, $field, $layout_type);

View File

@ -0,0 +1,15 @@
<?php
/**
* @package Articles Field
* @version 4.3.2
*
* @author Peter van Westen <info@regularlabs.com>
* @link https://regularlabs.com
* @copyright Copyright © 2024 Regular Labs All Rights Reserved
* @license GNU General Public License version 2 or later
*/
defined('_JEXEC') or die();
// Only used in Pro version

View File

@ -0,0 +1,15 @@
<?php
/**
* @package Articles Field
* @version 4.3.2
*
* @author Peter van Westen <info@regularlabs.com>
* @link https://regularlabs.com
* @copyright Copyright © 2024 Regular Labs All Rights Reserved
* @license GNU General Public License version 2 or later
*/
defined('_JEXEC') or die;
// Only used in Pro version

View File

@ -0,0 +1,34 @@
<?php
/**
* @package Articles Field
* @version 4.3.2
*
* @author Peter van Westen <info@regularlabs.com>
* @link https://regularlabs.com
* @copyright Copyright © 2024 Regular Labs All Rights Reserved
* @license GNU General Public License version 2 or later
*/
defined('_JEXEC') or die();
use Joomla\CMS\Router\Route as JRoute;
use Joomla\Component\Content\Site\Helper\RouteHelper as JContentHelperRoute;
/*
* @var array $displayData
* @var object $article
* @var object $settings
*/
extract($displayData);
$title = htmlentities($article->title);
if ($settings->link_title)
{
$slug = $article->alias ? ($article->id . ':' . $article->alias) : $article->id;
$link = JRoute::link('site', JContentHelperRoute::getArticleRoute($slug, $article->catid, $article->language));
$title = '<a href="' . $link . '">' . $title . '</a>';
}
echo $title;

View File

@ -0,0 +1,74 @@
<?php
/**
* @package Articles Field
* @version 4.3.2
*
* @author Peter van Westen <info@regularlabs.com>
* @link https://regularlabs.com
* @copyright Copyright © 2024 Regular Labs All Rights Reserved
* @license GNU General Public License version 2 or later
*/
defined('_JEXEC') or die();
use Joomla\CMS\Language\Text as JText;
use Joomla\CMS\Router\Route as JRoute;
use Joomla\Component\Content\Site\Helper\RouteHelper as JContentHelperRoute;
use Joomla\Component\Fields\Administrator\Helper\FieldsHelper as JFieldsHelper;
use RegularLabs\Plugin\Fields\Articles\Helper;
/*
* @var array $displayData
* @var object $article
* @var object $settings
*/
extract($displayData);
$title = htmlentities($article->title);
if ($settings->link_title)
{
$slug = $article->alias ? ($article->id . ':' . $article->alias) : $article->id;
$link = JRoute::link('site', JContentHelperRoute::getArticleRoute($slug, $article->catid, $article->language));
$title = '<a href="' . $link . '">' . $title . '</a>';
}
// No custom field found. Just return title
if (empty($settings->custom_field))
{
echo $title;
return;
}
$fields = JFieldsHelper::getFields('com_content.article', $article);
// No custom fields found. Just return title
if (empty($fields))
{
return $title;
}
foreach ($fields as $field)
{
if ($field->id != $settings->custom_field)
{
continue;
}
// field has no value
if (empty($field->value))
{
break;
}
Helper::prepareCustomField('com_content.article', $article, $field);
echo JText::sprintf('FLDA_OUTPUT_TITLE_CUSTOM_FIELD', $title, $field->value);
return;
}
// No custom field found. Just return title
echo $title;

View File

@ -0,0 +1,129 @@
<?xml version="1.0" encoding="utf-8"?>
<form>
<fields name="fieldparams" addfieldprefix="RegularLabs\Library\Form\Field">
<fieldset name="fieldparams" addfieldprefix="RegularLabs\Plugin\Fields\Articles\Form\Field">
<field name="@load_script_descriptions" type="LoadMedia" filetype="script" file="regularlabs.admin-form-descriptions"/>
<field name="field_type" type="List" label="FLDA_FIELD_TYPE" description="FLDA_FIELD_TYPE_DESC" default="articles">
<option value="articles">FLDA_LINK_ARTICLES</option>
<option value="" disabled="true">FLDA_LINKED_ARTICLES</option>
<option value="" disabled="true">RL_ONLY_AVAILABLE_IN_PRO_LIST_OPTION</option>
</field>
<field name="multiple" type="List" label="RL_FIELD_PARAM_MULTIPLE" description="RL_FIELD_PARAM_MULTIPLE_DESC" default="">
<option value="">COM_FIELDS_FIELD_USE_GLOBAL</option>
<option value="1">JYES</option>
<option value="0">JNO</option>
</field>
<field name="@description_link_articles" type="Note" description="FLDA_LINK_ARTICLES_DESC"/>
<field name="@block__filters__a" type="Block" start="1" label="RL_FILTERS"/>
<field name="@block__filters_categories__a" type="Block" start="1" label="RL_CATEGORIES"/>
<field name="filter_categories" type="Radio" default="0" class="btn-group rl-btn-group btn-group-md btn-group-yesno" label="FLDA_FILTER_BY_CATEGORIES">
<option value="0">JNO</option>
<option value="1">JYES</option>
<option value="current" class="btn btn-outline-info">RL_CURRENT</option>
</field>
<field name="categories" type="ContentCategories" label="RL_CATEGORIES" description="FLDA_CATEGORIES_DESC" multiple="1" simple="1" showon="filter_categories:1"/>
<field name="categories_inc_children" type="Radio" default="0" class="btn-group rl-btn-group btn-group-md btn-group-yesno" label="RL_INCLUDE_CHILD_CATEGORIES" description="RL_INCLUDE_CHILD_ITEMS_DESC" showon="filter_categories:1,current">
<option value="0">JNO</option>
<option value="1">JYES</option>
<option value="2" class="btn btn-outline-info">RL_ONLY</option>
</field>
<field name="@block__filters_categories__b" type="Block" end="1"/>
<field name="@block__filters_tags__a" type="Block" start="1" label="RL_TAGS"/>
<field name="@free__filters_tags" type="OnlyPro" label="FLDA_FILTER_BY_TAGS"/>
<field name="@block__filters_tags__b" type="Block" end="1"/>
<field name="@block__filters_language__a" type="Block" start="1" label="RL_LANGUAGE"/>
<field name="@free__filters_language" type="OnlyPro" label="FLDA_FILTER_BY_LANGUAGE"/>
<field name="@block__filters_languages__b" type="Block" end="1"/>
<field name="@block__filters_users__a" type="Block" start="1" label="JAUTHOR"/>
<field name="@free__filters_users" type="OnlyPro" label="FLDA_FILTER_BY_AUTHORS"/>
<field name="@block__filters_users__b" type="Block" end="1"/>
<field name="@block__filters_custom_fields__a" type="Block" start="1" label="RL_CUSTOM_FIELDS"/>
<field name="@free__filter_customfields" type="OnlyPro" label="FLDA_FILTER_BY_CUSTOM_FIELDS"/>
<field name="@block__filters_custom_fields__b" type="Block" end="1"/>
<field name="@block__filters__b" type="Block" end="1"/>
<field name="@block__articles_ordering__a" type="Block" start="1" label="RL_ORDERING"/>
<field name="articles_ordering" type="List" class="w-auto" label="RL_ORDERING_PRIMARY" description="JGLOBAL_FIELD_FIELD_ORDERING_DESC" default="title">
<option value="none">FLDA_ORDER_OF_SELECTION</option>
<option value="ordering">JFIELD_ORDERING_LABEL</option>
<option value="id">JGRID_HEADING_ID</option>
<option value="title">JGLOBAL_TITLE</option>
<option value="alias">JFIELD_ALIAS_LABEL</option>
<option value="hits">JGLOBAL_HITS</option>
<option value="created">JGLOBAL_CREATED_DATE</option>
<option value="modified">JGLOBAL_MODIFIED_DATE</option>
<option value="publish_up">JGLOBAL_PUBLISHED_DATE</option>
<option value="featured">JFEATURED</option>
<option value="category_lft">JGLOBAL_CATEGORY_ORDER_LABEL</option>
<option value="category_title">JGLOBAL_LIST_TITLE_LABEL</option>
</field>
<field name="articles_ordering_direction" type="Radio" default="ASC" class="btn-group rl-btn-group btn-group-md btn-group-yesno" label="RL_ORDER_DIRECTION_PRIMARY" description="JGLOBAL_ORDER_DIRECTION_DESC" showon="articles_ordering!:none">
<option value="ASC" class="btn btn-outline-info">JGLOBAL_ORDER_ASCENDING</option>
<option value="DESC" class="btn btn-outline-info">JGLOBAL_ORDER_DESCENDING</option>
</field>
<field name="articles_ordering_2" type="List" class="w-auto" label="RL_ORDERING_SECONDARY" description="JGLOBAL_FIELD_FIELD_ORDERING_DESC" default="created" showon="articles_ordering!:none[AND]articles_ordering!:id">
<option value="ordering">JFIELD_ORDERING_LABEL</option>
<option value="id">JGRID_HEADING_ID</option>
<option value="title">JGLOBAL_TITLE</option>
<option value="alias">JFIELD_ALIAS_LABEL</option>
<option value="hits">JGLOBAL_HITS</option>
<option value="created">JGLOBAL_CREATED_DATE</option>
<option value="modified">JGLOBAL_MODIFIED_DATE</option>
<option value="publish_up">JGLOBAL_PUBLISHED_DATE</option>
<option value="featured">JFEATURED</option>
<option value="category_lft">JGLOBAL_CATEGORY_ORDER_LABEL</option>
<option value="category_title">JGLOBAL_LIST_TITLE_LABEL</option>
</field>
<field name="articles_ordering_direction_2" type="Radio" default="DESC" class="btn-group rl-btn-group btn-group-md" label="RL_ORDER_DIRECTION_SECONDARY" description="JGLOBAL_ORDER_DIRECTION_DESC" showon="articles_ordering!:none[AND]articles_ordering!:id">
<option value="ASC" class="btn btn-outline-info">JGLOBAL_ORDER_ASCENDING</option>
<option value="DESC" class="btn btn-outline-info">JGLOBAL_ORDER_DESCENDING</option>
</field>
<field name="@block__articles_ordering__b" type="Block" end="1"/>
<field name="@block__output_limit__a" type="Block" start="1" label="FLDA_OUTPUT_LIMIT"/>
<field name="@free__output_limit" type="OnlyPro" label="FLDA_LIMIT" description="FLDA_OUTPUT_LIMIT_DESC"/>
<field name="@block__output_limit__b" type="Block" end="1"/>
<field name="@block__layout__a" type="Block" start="1" label="RL_LAYOUT"/>
<field name="layout" type="List" class="w-auto" label="RL_LAYOUT" description="RL_LAYOUT_DESC" default="title">
<option value="title">FLDA_LAYOUT_TITLE</option>
<option value="title_custom">FLDA_LAYOUT_TITLE_CUSTOM_FIELD</option>
<option value="" disabled="true">FLDA_LAYOUT_CUSTOM_HTML</option>
<option value="" disabled="true">RL_ONLY_AVAILABLE_IN_PRO_LIST_OPTION</option>
</field>
<field name="custom_field" type="CustomField" label="RL_CUSTOM_FIELD" description="FLDA_CUSTOM_FIELD_DESC" class="w-auto" default="" exclude="articles" showon="layout:title_custom"/>
<field name="link_title" type="Radio" default="1" class="btn-group rl-btn-group btn-group-md btn-group-yesno" label="FLDA_LINK_TITLE" description="FLDA_LINK_TITLE_DESC" showon="layout:title,title_custom">
<option value="1">JYES</option>
<option value="0">JNO</option>
</field>
<field name="custom_html" type="TextArea" texttype="html" filter="raw" label="FLDA_CUSTOM_HTML" description="FLDA_CUSTOM_HTML_DESC" default="&lt;a href=&quot;[url]&quot;&gt;[title]&lt;/a&gt; ([hits])" showon="layout:custom_html"/>
<field name="use_separator" type="Radio" default="1" class="btn-group rl-btn-group btn-group-md btn-group-yesno" label="FLDA_USE_SEPARATOR" description="FLDA_USE_SEPARATOR_DESC">
<option value="1">JYES</option>
<option value="0">JNO</option>
</field>
<field name="@showon__use_separator__a" type="ShowOn" value="use_separator:1"/>
<field name="separator" type="Text" class="w-12" label="FLDA_SEPARATOR" description="FLDA_SEPARATOR_DESC" default=", " filter="raw"/>
<field name="use_last_separator" type="Radio" default="0" class="btn-group rl-btn-group btn-group-md btn-group-yesno" label="FLDA_USE_LAST_SEPARATOR" description="FLDA_USE_LAST_SEPARATOR_DESC">
<option value="1">JYES</option>
<option value="0">JNO</option>
</field>
<field name="last_separator" type="Text" class="w-12" label="FLDA_LAST_SEPARATOR" description="FLDA_LAST_SEPARATOR_DESC" default=" &amp; " filter="raw" showon="use_last_separator:1"/>
<field name="@showon__use_separator__b" type="ShowOn"/>
<field name="@block__layout__b" type="Block" end="1"/>
<field name="@block__input_options__a" type="Block" start="1" label="FLDA_INPUT_OPTIONS"/>
<field name="@description_field_option" type="Note" description="FLDA_INPUT_OPTIONS_DESC" class="alert alert-info"/>
<field name="show_unpublished" type="Radio" default="1" class="btn-group rl-btn-group btn-group-md btn-group-yesno" label="FLDA_FILTER_SHOW_UNPUBLISHED" description="FLDA_FILTER_SHOW_UNPUBLISHED_DESC">
<option value="0">JNO</option>
<option value="1">JYES</option>
</field>
<field name="show_category" type="Radio" default="1" class="btn-group rl-btn-group btn-group-md btn-group-yesno" label="FLDA_FILTER_SHOW_CATEGORY" description="FLDA_FILTER_SHOW_CATEGORY_DESC">
<option value="0">JNO</option>
<option value="1">JYES</option>
</field>
<field name="@free__articles_grouping" type="OnlyPro" label="FLDA_ARTICLE_GROUPING" description="FLDA_ARTICLE_GROUPING_DESC"/>
<!-- >>> [PRO] >>> -->
<field name="articles_grouping" type="List" class="w-auto" label="FLDA_ARTICLE_GROUPING" description="FLDA_ARTICLE_GROUPING_DESC" default="title">
<option value="">JNONE</option>
<option value="category">RL_CATEGORY</option>
</field>
<field name="@block__input_options__b" type="Block" end="1"/>
</fieldset>
</fields>
</form>

View File

@ -0,0 +1,57 @@
<?php
/**
* @package Articles Field
* @version 4.3.2
*
* @author Peter van Westen <info@regularlabs.com>
* @link https://regularlabs.com
* @copyright Copyright © 2024 Regular Labs All Rights Reserved
* @license GNU General Public License version 2 or later
*/
defined('_JEXEC') or die;
use Joomla\CMS\Filesystem\File as JFile;
use Joomla\CMS\Filesystem\Folder as JFolder;
class PlgFieldsArticlesInstallerScript
{
public function postflight($install_type, $adapter)
{
if ( ! in_array($install_type, ['install', 'update']))
{
return true;
}
self::deleteJoomla3Files();
return true;
}
private static function delete($files = [])
{
foreach ($files as $file)
{
if (is_dir($file))
{
JFolder::delete($file);
}
if (is_file($file))
{
JFile::delete($file);
}
}
}
private static function deleteJoomla3Files()
{
self::delete(
[
JPATH_SITE . '/plugins/fields/articles/fields',
JPATH_SITE . '/plugins/fields/articles/helper.php',
JPATH_SITE . '/plugins/fields/articles/filters.php',
]
);
}
}

View File

@ -0,0 +1,212 @@
<?php
/**
* @package Articles Field
* @version 4.3.2
*
* @author Peter van Westen <info@regularlabs.com>
* @link https://regularlabs.com
* @copyright Copyright © 2024 Regular Labs All Rights Reserved
* @license GNU General Public License version 2 or later
*/
namespace RegularLabs\Plugin\Fields\Articles;
defined('_JEXEC') or die();
use Joomla\CMS\Factory as JFactory;
use RegularLabs\Library\ArrayHelper as RL_Array;
use RegularLabs\Library\DB as RL_DB;
use RegularLabs\Library\Input as RL_Input;
class Filters
{
private $db;
private $form;
private $params;
public function __construct($params, $form = null)
{
$this->params = $params;
$this->form = $form;
$this->db = JFactory::getDbo();
}
public function addToQuery(&$query)
{
$this->addCategoriesToQuery($query);
}
public function get()
{
$filters = [];
if ($this->params->get('filter_categories'))
{
$categories = RL_Array::toArray($this->params->get('categories'));
if ($this->params->get('filter_categories') === 'current')
{
$categories = [$this->getCurrentCategoryId()];
}
$filters['filter_categories'] = true;
$filters['categories'] = $categories;
$filters['categories_inc_children'] = $this->params->get('categories_inc_children');
}
return $filters;
}
public function getCategories()
{
if ( ! $this->params->get('filter_categories'))
{
return [];
}
if ($this->params->get('filter_categories') === 'current')
{
return [$this->getCurrentCategoryId()];
}
$categories = (array) $this->params->get('categories', []);
if (empty($categories))
{
return [];
}
$inc_children = $this->params->get('categories_inc_children');
if ( ! $inc_children)
{
return $categories;
}
$children = $this->getCategoriesChildIds($categories);
if ($inc_children == 2)
{
return $children;
}
return [...$categories, ...$children];
}
public function getCurrentArticleId(): int
{
if (
RL_Input::getCmd('option') != 'com_content'
|| ! in_array(RL_Input::getCmd('view'), ['form', 'article'])
|| ! in_array(RL_Input::getCmd('layout'), ['edit', 'modal'])
)
{
return 0;
}
if ($this->form && $this->form->getValue('id'))
{
return (int) $this->form->getValue('id');
}
return RL_Input::getInt('id');
}
private function addCategoriesToQuery(&$query)
{
$categories = $this->getCategories();
if (empty($categories))
{
return $categories;
}
$query->where(RL_DB::is('a.catid', $categories));
return $categories;
}
private function addCustomFieldsToQuery(&$query)
{
}
private function addTagsToQuery(&$query)
{
}
private function addUsersToQuery(&$query)
{
}
private function filterDownArticlesByCustomFields(&$ids, $id, $value)
{
}
private function getArticlesByCustomFields()
{
}
private function getCategoriesChildIds($categories = [])
{
$children = [];
$query = RL_DB::getQuery()
->select('category.id')
->from(RL_DB::quoteName('#__categories', 'category'))
->where('category.extension = ' . RL_DB::quote('com_content'))
->where('category.published = 1');
while ( ! empty($categories))
{
$query->clear('where')
->where(RL_DB::is('category.parent_id', $categories));
$this->db->setQuery($query);
$categories = $this->db->loadColumn();
$children = [...$children, ...$categories];
}
return $children;
}
private function getCurrentArticleLanguage()
{
}
private function getCurrentCategoryId(): int
{
if ($this->form && $this->form->getValue('catid'))
{
return (int) $this->form->getValue('catid');
}
$id = $this->getCurrentArticleId();
if ( ! $id)
{
return 0;
}
$query = RL_DB::getQuery()
->select('content.catid')
->from(RL_DB::quoteName('#__content', 'content'))
->where('content.id = ' . $id);
$this->db->setQuery($query);
return (int) $this->db->loadResult();
}
private function getTags()
{
}
private function getTagsChildIds($tags = [])
{
}
private function getUsers()
{
}
}

View File

@ -0,0 +1,240 @@
<?php
/**
* @package Articles Field
* @version 4.3.2
*
* @author Peter van Westen <info@regularlabs.com>
* @link https://regularlabs.com
* @copyright Copyright © 2024 Regular Labs All Rights Reserved
* @license GNU General Public License version 2 or later
*/
namespace RegularLabs\Plugin\Fields\Articles\Form\Field;
defined('_JEXEC') or die();
use Joomla\CMS\HTML\HTMLHelper as JHtml;
use Joomla\CMS\Language\Text as JText;
use Joomla\Registry\Registry;
use RegularLabs\Library\ArrayHelper as RL_Array;
use RegularLabs\Library\DB as RL_DB;
use RegularLabs\Library\Document as RL_Document;
use RegularLabs\Library\Form\Form as RL_Form;
use RegularLabs\Library\Form\FormField as RL_Field;
use RegularLabs\Library\Parameters as RL_Parameters;
use RegularLabs\Plugin\Fields\Articles\Filters;
use RegularLabs\Plugin\Fields\Articles\Helper;
class ArticlesField extends RL_Field
{
protected function getInput()
{
$this->params = $this->element->attributes();
$plugin_params = RL_Parameters::getPlugin('articles', 'fields');
if ( ! is_array($this->value))
{
$this->value = explode(',', $this->value);
}
$attributes = [
'fieldtype' => 'articles',
'multiple' => $this->get('multiple', $plugin_params->multiple),
'currentid' => $this->getCurrentArticleId(),
'ordering' => $this->get('articles_ordering', 'title'),
'ordering_direction' => $this->get('articles_ordering_direction', 'ASC'),
'ordering_2' => $this->get('articles_ordering_2', 'created'),
'ordering_direction_2' => $this->get('articles_ordering_direction_2', 'DESC'),
'grouping' => $this->get('articles_grouping', ''),
'show_category' => $this->get('show_category', '1'),
'show_unpublished' => $this->get('show_unpublished', '1'),
];
$filters = $this->getFilters();
$attributes = [...$attributes, ...$filters];
$this->attributes = new Registry($attributes);
// Fix for subform fields which doesn't show the dropdown select list properly
RL_Document::styleDeclaration(
'.table-responsive {overflow-x: visible;}'
);
return RL_Form::selectListAjax(
$this::class,
$this->name,
$this->value,
$this->id,
$attributes
);
//
// return RL_Form::selectlist(
// $options,
// $this->name,
// $this->value,
// $this->id,
// [
// 'size' => $this->attributes->get('size'),
// 'multiple' => $this->attributes->get('multiple'),
// ]);
}
protected function getListOptions(array $attributes): int|array
{
$this->attributes = new Registry($attributes);
return $this->getOptions();
}
protected function getOptions()
{
$query = $this->db->getQuery(true)
->select('COUNT(*)')
->from($this->db->quoteName('#__content', 'a'))
->where('a.access > -1');
$filters = new Filters($this->attributes, $this->form);
$filters->addToQuery($query);
if ($this->max_list_count)
{
$this->db->setQuery($query);
$total = $this->db->loadResult();
if ($total > $this->max_list_count)
{
return -1;
}
}
$categories = $filters->getCategories();
$primary_ordering = $this->attributes->get('ordering', 'title');
$primary_direction = $this->attributes->get('ordering_direction', 'ASC');
$secondary_ordering = $this->attributes->get('ordering_2', 'created');
$secondary_direction = $this->attributes->get('ordering_direction_2', 'DESC');
$ordering = Helper::getFullOrdering($primary_ordering, $primary_direction, $secondary_ordering, $secondary_direction);
$place_selected_at_top = false;
if ($ordering == 'none')
{
$ordering = 'a.title ASC';
$place_selected_at_top = true;
}
$grouping = $this->attributes->get('grouping', '');
$show_category = $this->attributes->get('show_category', 1) && count($categories) != 1;
$extras = ['unpublished', 'language'];
$query->clear('select')
->select('a.id, a.title as name, a.language, a.state as published')
->join('LEFT', $this->db->quoteName('#__categories', 'c') . ' ON c.id = a.catid');
if (
$show_category
)
{
$query->select(['a.catid', 'c.title as cat']);
}
if ($show_category && $grouping != 'category')
{
$extras[] = 'cat';
}
if (RL_Document::isAdmin())
{
$extras[] = 'id';
}
$query->where(RL_DB::is('a.state', [0, 1]));
if ( ! $this->attributes->get('show_unpublished', 1))
{
RL_DB::addArticleIsPublishedFilters($query);
}
$ordering = trim($ordering, ', ');
if ($ordering)
{
$query->order($ordering);
}
$this->db->setQuery($query);
$list = $this->db->loadObjectList('id');
if ($place_selected_at_top && ! empty($this->value))
{
$selected = [];
foreach ($this->value as $value)
{
if (isset($list[$value]))
{
$selected[$value] = $list[$value];
unset($list[$value]);
}
}
$list = $selected + $list;
}
switch ($grouping)
{
default:
$options = $this->getOptionsByList($list, $extras);
break;
}
$currentid = $this->attributes->get('currentid');
if (isset($options[$currentid]) && isset($options[$currentid]->text))
{
$options[$currentid]->disable = true;
$options[$currentid]->text .= ' (' . JText::_('RL_CURRENT') . ')';
}
if ($this->attributes->get('multiple'))
{
return $options;
}
array_unshift($options, JHtml::_('select.option', '-', '&nbsp;', 'value', 'text', true));
array_unshift($options, JHtml::_('select.option', '', '- ' . JText::_('Select Item') . ' -'));
return $options;
}
private function flattenGroups($groups, $level = 0)
{
}
private function flattenOptions($options)
{
}
private function getCurrentArticleId()
{
$filters = new Filters($this, $this->form);
return $filters->getCurrentArticleId();
}
private function getFilters()
{
$filters = new Filters($this, $this->form);
return $filters->get();
}
private function getOptionsByListGroupedByCategory($list, $extras = [])
{
}
}

View File

@ -0,0 +1,67 @@
<?php
/**
* @package Articles Field
* @version 4.3.2
*
* @author Peter van Westen <info@regularlabs.com>
* @link https://regularlabs.com
* @copyright Copyright © 2024 Regular Labs All Rights Reserved
* @license GNU General Public License version 2 or later
*/
namespace RegularLabs\Plugin\Fields\Articles\Form\Field;
defined('_JEXEC') or die;
use Joomla\CMS\HTML\HTMLHelper as JHtml;
use Joomla\Component\Fields\Administrator\Helper\FieldsHelper as JFieldsHelper;
use RegularLabs\Library\Form\Form as RL_Form;
use RegularLabs\Library\Form\FormField as RL_Field;
class ArticlesFieldsField extends RL_Field
{
protected function getInput()
{
$this->params = $this->element->attributes();
if ( ! is_array($this->value))
{
$this->value = explode(',', $this->value);
}
$options = $this->getOptions();
return RL_Form::selectlist(
$options,
$this->name,
$this->value,
$this->id,
['multiple' => true]
);
}
protected function getOptions()
{
$options = parent::getOptions();
$fields = JFieldsHelper::getFields('com_content.article', null, false, null, true);
foreach ($fields as $field)
{
if ($field->type != 'articles')
{
continue;
}
$options[] = JHtml::_('select.option', $field->id, $field->title);
}
// Sorting the fields based on the text which is displayed
usort(
$options,
fn($a, $b) => strcmp($a->text, $b->text)
);
return $options;
}
}

View File

@ -0,0 +1,70 @@
<?php
/**
* @package Articles Field
* @version 4.3.2
*
* @author Peter van Westen <info@regularlabs.com>
* @link https://regularlabs.com
* @copyright Copyright © 2024 Regular Labs All Rights Reserved
* @license GNU General Public License version 2 or later
*/
namespace RegularLabs\Plugin\Fields\Articles\Form\Field;
defined('_JEXEC') or die;
use Joomla\CMS\HTML\HTMLHelper as JHtml;
use Joomla\CMS\Language\Text as JText;
use Joomla\Component\Fields\Administrator\Helper\FieldsHelper as JFieldsHelper;
use RegularLabs\Library\ArrayHelper as RL_Array;
use RegularLabs\Library\Form\Form as RL_Form;
use RegularLabs\Library\Form\FormField as RL_Field;
class CustomFieldField extends RL_Field
{
protected function getInput()
{
$this->params = $this->element->attributes();
if ( ! is_array($this->value))
{
$this->value = explode(',', $this->value);
}
$options = $this->getOptions();
return RL_Form::selectlist(
$options,
$this->name,
$this->value,
$this->id
);
}
protected function getOptions()
{
$excludes = RL_Array::toArray($this->get('exclude'));
$options = parent::getOptions();
$fields = JFieldsHelper::getFields('com_content.article');
foreach ($fields as $field)
{
if (in_array($field->type, $excludes))
{
continue;
}
$options[] = JHtml::_('select.option', $field->id, $field->title);
}
if ( ! empty($options))
{
array_unshift($options, JHtml::_('select.option', '-', '&nbsp;', 'value', 'text', true));
array_unshift($options, JHtml::_('select.option', '', '- ' . JText::_('JSELECT') . ' -', 'value', 'text', false));
}
return $options;
}
}

View File

@ -0,0 +1,371 @@
<?php
/**
* @package Articles Field
* @version 4.3.2
*
* @author Peter van Westen <info@regularlabs.com>
* @link https://regularlabs.com
* @copyright Copyright © 2024 Regular Labs All Rights Reserved
* @license GNU General Public License version 2 or later
*/
namespace RegularLabs\Plugin\Fields\Articles;
defined('_JEXEC') or die;
use Joomla\CMS\Factory as JFactory;
use Joomla\CMS\Plugin\PluginHelper as JPluginHelper;
use Joomla\CMS\Router\Route as JRoute;
use Joomla\Component\Content\Site\Helper\RouteHelper as JContentHelperRoute;
use Joomla\Component\Fields\Administrator\Helper\FieldsHelper as JFieldsHelper;
use Joomla\Registry\Registry as JRegistry;
use RegularLabs\Library\ArrayHelper as RL_Array;
use RegularLabs\Library\Article as RL_Article;
use RegularLabs\Library\Cache as RL_Cache;
use RegularLabs\Library\DB as RL_DB;
use RegularLabs\Library\Parameters as RL_Parameters;
use RegularLabs\Library\Protect as RL_Protect;
use RegularLabs\Library\RegEx as RL_RegEx;
use RegularLabs\Library\StringHelper as RL_String;
use RegularLabs\Plugin\System\ArticlesAnywhere\Helpers\Params as AA_Params;
use RegularLabs\Plugin\System\ArticlesAnywhere\Replace as AA_Replace;
class Helper
{
public static function getArticlesByIds($ids)
{
$articles = [];
foreach ($ids as $id)
{
if ( ! $id)
{
continue;
}
$article = RL_Article::get($id);
if (empty($article->id))
{
continue;
}
if ( ! in_array($article->access, JFactory::getUser()->getAuthorisedViewLevels()))
{
continue;
}
$articles[] = $article;
}
return $articles;
}
public static function getFullOrdering(
$primary_ordering,
$primary_direction,
$secondary_ordering,
$secondary_direction,
$prefix_articles = 'a',
$prefix_categories = 'c'
)
{
$db = JFactory::getDbo();
if ($primary_ordering == 'none')
{
return 'none';
}
self::prepareOrdering($primary_ordering, $primary_direction);
self::prepareOrdering($secondary_ordering, $secondary_direction);
self::prefixOrdering($primary_ordering, $prefix_articles, $prefix_categories);
self::prefixOrdering($secondary_ordering, $prefix_articles, $prefix_categories);
return $db->quoteName($primary_ordering) . ' ' . $primary_direction . ','
. $db->quoteName($secondary_ordering) . ' ' . $secondary_direction;
}
public static function getLinkedArticleIds($field_ids, $article_id, $field)
{
}
public static function orderArticles(
&$articles,
$primary_ordering,
$primary_direction = 'ASC',
$secondary_ordering = '',
$secondary_direction = 'ASC'
)
{
$ordered = self::orderArticlesSet($articles, $primary_ordering, $primary_direction);
if ($primary_ordering == 'none' || $primary_ordering == 'id' || ! $secondary_ordering)
{
$articles = RL_Array::flatten($ordered);
return;
}
foreach ($ordered as &$ordered_set)
{
$ordered_set = self::orderArticlesSet($ordered_set, $secondary_ordering, $secondary_direction);
}
$articles = RL_Array::flatten($ordered);
}
public static function prepareCustomField($context, $item, &$field)
{
JPluginHelper::importPlugin('fields');
// Event allow plugins to modify the output of the field before it is prepared
JFactory::getApplication()->triggerEvent('onCustomFieldsBeforePrepareField', [
$context, $item, &$field
]);
// Gathering the value for the field
$value = JFactory::getApplication()->triggerEvent('onCustomFieldsPrepareField', [
$context, $item, &$field
]);
$value = RL_Array::implode($value, ' ');
// Event allow plugins to modify the output of the prepared field
JFactory::getApplication()->triggerEvent('onCustomFieldsAfterPrepareField', [
$context, $item, $field, &$value
]);
// Assign the value
$field->value = $value;
}
public static function protectArticlesAnywhere(&$string)
{
}
public static function renderLayout(
$ids,
$layout,
$field,
$layout_type = 'title',
$apply_ordering = true
)
{
if (count($ids) === 1)
{
$ids = RL_Array::toArray($ids[0]);
}
$settings = (object) [];
switch ($layout_type)
{
case 'title_custom':
$settings->custom_field = $field->fieldparams->get('custom_field', '');
$settings->link_title = $field->fieldparams->get('link_title', 1);
break;
case 'title':
default:
$settings->link_title = $field->fieldparams->get('link_title', 1);
break;
}
$outputs = self::getOutputs($ids, $layout, $field, $settings, $apply_ordering);
$separator = $field->fieldparams->get('use_separator') ? $field->fieldparams->get('separator', ', ') : '';
$last_separator = $field->fieldparams->get('use_last_separator') ? $field->fieldparams->get('last_separator', ', ') : $separator;
return RL_Array::implode(
$outputs,
$separator,
$last_separator
);
}
public static function replaceDataTags($string, &$article)
{
}
public static function runThroughArticlesAnywhere($string)
{
}
private static function addFilters(&$query, $field)
{
}
private static function getArticleFieldIds()
{
}
private static function getArticleOrderId($article, $ordering)
{
if ( ! isset($article->{$ordering}))
{
return 0;
}
switch ($ordering)
{
case 'ordering':
case 'hits':
return ($article->{$ordering} + 100000000);
case 'created_time':
case 'modified_time':
case 'publish_up':
case 'alias':
case 'title':
default:
return strtolower($article->{$ordering});
}
}
private static function getCategoriesByFieldId($field_id)
{
}
private static function getChildCategories($categories)
{
}
private static function getDataTagValue(&$article, $key)
{
}
private static function getDataTagValueCustomField(&$article, $key)
{
}
private static function getDataTags($html)
{
}
private static function getFieldIdsByType($type = 'articles')
{
$cache = new RL_Cache;
if ($cache->exists())
{
return $cache->get();
}
}
private static function getLinkedArticleIdsByFieldId($field_id, $article_id, $field)
{
}
private static function getOutputs($ids, $layout, $field, $settings, $apply_ordering = true)
{
$ids = array_unique($ids);
$articles = self::getArticlesByIds($ids);
if ($apply_ordering)
{
$primary_ordering = $field->fieldparams->get('articles_ordering', 'title');
$primary_direction = $field->fieldparams->get('articles_ordering_direction', 'ASC');
$secondary_ordering = $field->fieldparams->get('articles_ordering_2', 'created');
$secondary_direction = $field->fieldparams->get('articles_ordering_direction_2', 'DESC');
self::orderArticles($articles, $primary_ordering, $primary_direction, $secondary_ordering, $secondary_direction);
}
return self::getOutputsByArticles($articles, $layout, $settings);
}
private static function getOutputsByArticles($articles, $layout, $settings)
{
$outputs = [];
$total_count = count($articles);
foreach ($articles as $i => $article)
{
$output = $layout->render(compact('article', 'settings'));
if (empty($output))
{
continue;
}
$outputs[] = $output;
}
return $outputs;
}
private static function getSubformFieldIds()
{
}
private static function orderArticlesSet($articles, $ordering, $direction = 'ASC')
{
if ( ! is_array($articles) || count($articles) < 2)
{
return $articles;
}
if ($ordering == 'none')
{
return $articles;
}
self::prepareOrdering($ordering, $direction);
$ordered = [];
// Handle 1st ordering
foreach ($articles as $article)
{
$order_id = self::getArticleOrderId($article, $ordering);
if ( ! isset($ordered[$order_id]))
{
$ordered[$order_id] = [];
}
$ordered[$order_id][] = $article;
}
switch ($direction)
{
case 'DESC':
krsort($ordered);
break;
case 'ASC':
default:
ksort($ordered);
break;
}
return array_values($ordered);
}
private static function prefixOrdering(
&$ordering,
$prefix_articles = 'a',
$prefix_categories = 'c'
)
{
if (str_starts_with($ordering, 'category_'))
{
$ordering = $prefix_categories . '.' . substr($ordering, strlen('category_'));
return;
}
$ordering = $prefix_articles . '.' . $ordering;
}
private static function prepareOrdering(&$ordering, &$direction)
{
if ($ordering == 'featured')
{
$direction = $direction == 'DESC' ? 'ASC' : 'DESC';
}
}
}

View File

@ -0,0 +1,37 @@
<?php
/**
* @package Articles Field
* @version 4.3.2
*
* @author Peter van Westen <info@regularlabs.com>
* @link https://regularlabs.com
* @copyright Copyright © 2024 Regular Labs All Rights Reserved
* @license GNU General Public License version 2 or later
*/
defined('_JEXEC') or die;
use Joomla\CMS\Layout\FileLayout as JLayoutFile;
if (empty($field->value))
{
return;
}
$layout = new JLayoutFile('plg_fields_articles.articles');
$include_paths = $layout->getIncludePaths();
$include_paths[] = JPATH_SITE . '/plugins/fields/articles/layouts';
$layout->setIncludePaths($include_paths);
$layout_type = $field->fieldparams->get('layout', 'title');
$value_layout = new JLayoutFile('plg_fields_articles.' . $layout_type);
$value_layout->setIncludePaths($include_paths);
echo $layout->render([
'context' => $context,
'item' => $item,
'field' => $field,
'layout_type' => $layout_type,
'layout' => $value_layout,
]);