fac/_public.php

240 lines
7.2 KiB
PHP
Raw Normal View History

2021-08-20 15:44:19 +00:00
<?php
2021-09-02 19:08:55 +00:00
/**
* @brief fac, a plugin for Dotclear 2
2022-11-20 20:13:56 +00:00
*
2021-09-02 19:08:55 +00:00
* @package Dotclear
* @subpackage Plugin
2022-11-20 20:13:56 +00:00
*
2021-09-02 19:08:55 +00:00
* @author Jean-Christian Denis and Contributors
2022-11-20 20:13:56 +00:00
*
2021-09-02 19:08:55 +00:00
* @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/
2021-08-20 15:44:19 +00:00
if (!defined('DC_RC_PATH')) {
2021-08-20 16:39:12 +00:00
return null;
2021-08-20 15:44:19 +00:00
}
2022-11-20 20:13:56 +00:00
dcCore::app()->addBehavior(
2021-08-20 16:39:12 +00:00
'publicEntryAfterContent',
2022-11-20 20:13:56 +00:00
['facPublic', 'publicEntryAfterContent']
2021-08-20 15:44:19 +00:00
);
/**
* @ingroup DC_PLUGIN_FAC
* @brief Linked feed to entries - public methods.
* @since 2.6
*/
class facPublic
{
2021-08-20 16:39:12 +00:00
/**
* Add feed after entry
2022-11-20 20:13:56 +00:00
*
2021-08-20 16:39:12 +00:00
* @param dcCore $core dcCore instance
* @param context $_ctx context instance
*/
public static function publicEntryAfterContent(dcCore $core, context $_ctx)
{
2022-11-20 20:13:56 +00:00
dcCore::app()->blog->settings->addNamespace('fac');
2021-08-20 16:39:12 +00:00
# Not active or not a post
2022-11-20 20:13:56 +00:00
if (!dcCore::app()->blog->settings->fac->fac_active
|| !dcCore::app()->ctx->exists('posts')) {
2021-08-20 16:39:12 +00:00
return null;
}
# Not in page to show
2022-11-20 20:13:56 +00:00
$types = @unserialize((string) dcCore::app()->blog->settings->fac->fac_public_tpltypes);
2021-08-20 16:39:12 +00:00
if (!is_array($types)
2022-11-20 20:13:56 +00:00
|| !in_array(dcCore::app()->url->type, $types)) {
2021-08-20 16:39:12 +00:00
return null;
}
# Get related feed
2022-11-20 20:13:56 +00:00
$fac_url = dcCore::app()->meta->getMetadata([
2021-08-20 16:39:12 +00:00
'meta_type' => 'fac',
2022-11-20 20:13:56 +00:00
'post_id' => dcCore::app()->ctx->posts->post_id,
'limit' => 1,
2021-08-20 16:39:12 +00:00
]);
if ($fac_url->isEmpty()) {
return null;
}
# Get related format
2022-11-20 20:13:56 +00:00
$fac_format = dcCore::app()->meta->getMetadata([
2021-08-20 16:39:12 +00:00
'meta_type' => 'facformat',
2022-11-20 20:13:56 +00:00
'post_id' => dcCore::app()->ctx->posts->post_id,
'limit' => 1,
2021-08-20 16:39:12 +00:00
]);
if ($fac_format->isEmpty()) {
return null;
}
# Get format info
2022-11-20 20:13:56 +00:00
$default_format = [
'name' => 'default',
'dateformat' => '',
'lineslimit' => '5',
'linestitletext' => '%T',
'linestitleover' => '%D',
'linestitlelength' => '150',
'showlinesdescription' => '0',
2021-08-20 16:39:12 +00:00
'linesdescriptionlength' => '350',
'linesdescriptionnohtml' => '1',
2022-11-20 20:13:56 +00:00
'showlinescontent' => '0',
'linescontentlength' => '350',
'linescontentnohtml' => '1',
];
2021-08-20 16:39:12 +00:00
2022-11-20 20:13:56 +00:00
$formats = @unserialize((string) dcCore::app()->blog->settings->fac->fac_formats);
2021-08-20 16:39:12 +00:00
if (empty($formats)
|| !is_array($formats)
|| !isset($formats[$fac_format->meta_id])) {
$format = $default_format;
} else {
$format = array_merge(
$default_format,
$formats[$fac_format->meta_id]
);
}
# Read feed url
$cache = is_dir(DC_TPL_CACHE . '/fac') ? DC_TPL_CACHE . '/fac' : null;
2022-11-20 20:13:56 +00:00
2021-08-20 16:39:12 +00:00
try {
$feed = feedReader::quickParse($fac_url->meta_id, $cache);
} catch (Exception $e) {
$feed = null;
}
# No entries
if (!$feed) {
return null;
}
# Feed title
$feedtitle = '';
2022-11-20 20:13:56 +00:00
if ('' != dcCore::app()->blog->settings->fac->fac_defaultfeedtitle) {
$feedtitle = '<h3>' . html::escapeHTML(
empty($feed->title) ?
2021-08-20 16:39:12 +00:00
str_replace(
'%T',
__('a related feed'),
2022-11-20 20:13:56 +00:00
dcCore::app()->blog->settings->fac->fac_defaultfeedtitle
) :
2021-08-20 16:39:12 +00:00
str_replace(
'%T',
$feed->title,
2022-11-20 20:13:56 +00:00
dcCore::app()->blog->settings->fac->fac_defaultfeedtitle
2021-08-20 16:39:12 +00:00
)
) . '</h3>';
}
# Feed desc
$feeddesc = '';
2022-11-20 20:13:56 +00:00
if (dcCore::app()->blog->settings->fac->fac_showfeeddesc
2021-08-20 16:39:12 +00:00
&& '' != $feed->description) {
2022-11-20 20:13:56 +00:00
$feeddesc = '<p>' . context::global_filters(
$feed->description,
2021-08-23 13:22:15 +00:00
['encode_xml', 'remove_html']
) . '</p>';
2021-08-20 16:39:12 +00:00
}
# Date format
2022-11-20 20:13:56 +00:00
$dateformat = '' != $format['dateformat'] ?
2021-08-20 16:39:12 +00:00
$format['dateformat'] :
2022-11-20 20:13:56 +00:00
dcCore::app()->blog->settings->system->date_format . ',' . dcCore::app()->blog->settings->system->time_format;
2021-08-20 16:39:12 +00:00
# Enrties limit
2022-11-20 20:13:56 +00:00
$entrieslimit = abs((int) $format['lineslimit']);
$uselimit = $entrieslimit > 0 ? true : false;
2021-08-20 16:39:12 +00:00
2022-11-20 20:13:56 +00:00
echo
2021-08-20 16:39:12 +00:00
'<div class="post-fac">' .
$feedtitle . $feeddesc .
'<dl>';
$i = 0;
foreach ($feed->items as $item) {
# Format date
$date = dt::dt2str($dateformat, $item->pubdate);
# Entries title
2021-08-23 13:22:15 +00:00
$title = context::global_filters(
2021-08-20 16:39:12 +00:00
str_replace(
2022-11-20 20:13:56 +00:00
[
2021-08-20 16:39:12 +00:00
'%D',
'%T',
'%A',
'%E',
2022-11-20 20:13:56 +00:00
'%C',
],
[
2021-08-20 16:39:12 +00:00
$date,
$item->title,
$item->creator,
$item->description,
2022-11-20 20:13:56 +00:00
$item->content,
],
2021-08-20 16:39:12 +00:00
$format['linestitletext']
),
2022-11-20 20:13:56 +00:00
['remove_html', 'cut_string' => abs((int) $format['linestitlelength'])],
2021-08-20 16:39:12 +00:00
);
# Entries over title
2021-08-23 13:22:15 +00:00
$overtitle = context::global_filters(
2021-08-20 16:39:12 +00:00
str_replace(
2022-11-20 20:13:56 +00:00
[
2021-08-20 16:39:12 +00:00
'%D',
'%T',
'%A',
'%E',
2022-11-20 20:13:56 +00:00
'%C',
],
[
2021-08-20 16:39:12 +00:00
$date,
$item->title,
$item->creator,
$item->description,
2022-11-20 20:13:56 +00:00
$item->content,
],
2021-08-20 16:39:12 +00:00
$format['linestitleover']
),
2021-08-23 13:22:15 +00:00
['remove_html', 'cut_string' => 350],
2021-08-20 16:39:12 +00:00
);
# Entries description
$description = '';
2022-11-20 20:13:56 +00:00
if ($format['showlinesdescription']
2021-08-20 16:39:12 +00:00
&& '' != $item->description) {
$description = '<dd>' .
2021-08-23 13:22:15 +00:00
context::global_filters(
2021-08-20 16:39:12 +00:00
$item->description,
2022-11-20 20:13:56 +00:00
['remove_html' => (int) $format['linesdescriptionnohtml'], 'cut_string' => abs((int) $format['linesdescriptionlength'])]
2021-08-20 16:39:12 +00:00
) . '</dd>';
}
# Entries content
$content = '';
2022-11-20 20:13:56 +00:00
if ($format['showlinescontent']
2021-08-20 16:39:12 +00:00
&& '' != $item->content) {
2022-11-20 20:13:56 +00:00
$content = '<dd>' .
2021-08-23 13:22:15 +00:00
context::global_filters(
2021-08-20 16:39:12 +00:00
$item->content,
2022-11-20 20:13:56 +00:00
['remove_html' => (int) $format['linescontentnohtml'], 'cut_string' => abs((int) $format['linescontentlength'])]
2021-08-20 16:39:12 +00:00
) . '</dd>';
}
echo
'<dt><a href="' . $item->link . '" ' .
'title="' . $overtitle . '">' . $title . '</a></dt>' .
$description . $content;
$i++;
if ($uselimit && $i == $entrieslimit) {
break;
}
}
echo '</dl></div>';
}
2022-11-20 20:13:56 +00:00
}