2021-08-20 15:44:19 +00:00
|
|
|
<?php
|
|
|
|
# -- BEGIN LICENSE BLOCK ----------------------------------
|
|
|
|
#
|
|
|
|
# This file is part of fac, a plugin for Dotclear 2.
|
|
|
|
#
|
2021-08-20 16:39:12 +00:00
|
|
|
# Copyright (c) 2009-2021 Jean-Christian Denis and contributors
|
2021-08-20 15:44:19 +00:00
|
|
|
#
|
|
|
|
# Licensed under the GPL version 2.0 license.
|
|
|
|
# A copy of this license is available in LICENSE file or at
|
|
|
|
# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
|
|
|
#
|
|
|
|
# -- END LICENSE BLOCK ------------------------------------
|
|
|
|
|
|
|
|
if (!defined('DC_RC_PATH')) {
|
2021-08-20 16:39:12 +00:00
|
|
|
return null;
|
2021-08-20 15:44:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$core->addBehavior(
|
2021-08-20 16:39:12 +00:00
|
|
|
'publicEntryAfterContent',
|
|
|
|
array('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
|
|
|
|
*
|
|
|
|
* @param dcCore $core dcCore instance
|
|
|
|
* @param context $_ctx context instance
|
|
|
|
*/
|
|
|
|
public static function publicEntryAfterContent(dcCore $core, context $_ctx)
|
|
|
|
{
|
|
|
|
$core->blog->settings->addNamespace('fac');
|
|
|
|
|
|
|
|
# Not active or not a post
|
|
|
|
if (!$core->blog->settings->fac->fac_active
|
|
|
|
|| !$_ctx->exists('posts')) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
# Not in page to show
|
|
|
|
$types = @unserialize($core->blog->settings->fac->fac_public_tpltypes);
|
|
|
|
if (!is_array($types)
|
|
|
|
|| !in_array($core->url->type,$types)) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
# Get related feed
|
|
|
|
$fac_url = $core->meta->getMetadata([
|
|
|
|
'meta_type' => 'fac',
|
|
|
|
'post_id' => $_ctx->posts->post_id,
|
|
|
|
'limit' => 1
|
|
|
|
]);
|
|
|
|
if ($fac_url->isEmpty()) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
# Get related format
|
|
|
|
$fac_format = $core->meta->getMetadata([
|
|
|
|
'meta_type' => 'facformat',
|
|
|
|
'post_id' => $_ctx->posts->post_id,
|
|
|
|
'limit' => 1
|
|
|
|
]);
|
|
|
|
if ($fac_format->isEmpty()) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
# Get format info
|
|
|
|
$default_format = array(
|
|
|
|
'name' => 'default',
|
|
|
|
'dateformat' => '',
|
|
|
|
'lineslimit' => '5',
|
|
|
|
'linestitletext' => '%T',
|
|
|
|
'linestitleover' => '%D',
|
|
|
|
'linestitlelength' => '150',
|
|
|
|
'showlinesdescription' => '0',
|
|
|
|
'linesdescriptionlength' => '350',
|
|
|
|
'linesdescriptionnohtml' => '1',
|
|
|
|
'showlinescontent' => '0',
|
|
|
|
'linescontentlength' => '350',
|
|
|
|
'linescontentnohtml' => '1'
|
|
|
|
);
|
|
|
|
|
|
|
|
$formats = @unserialize($core->blog->settings->fac->fac_formats);
|
|
|
|
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;
|
|
|
|
try {
|
|
|
|
$feed = feedReader::quickParse($fac_url->meta_id, $cache);
|
|
|
|
} catch (Exception $e) {
|
|
|
|
$feed = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
# No entries
|
|
|
|
if (!$feed) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
# Feed title
|
|
|
|
$feedtitle = '';
|
|
|
|
if ('' != $core->blog->settings->fac->fac_defaultfeedtitle) {
|
|
|
|
$feedtitle = '<h3>' . html::escapeHTML(empty($feed->title) ?
|
|
|
|
str_replace(
|
|
|
|
'%T',
|
|
|
|
__('a related feed'),
|
|
|
|
$core->blog->settings->fac->fac_defaultfeedtitle
|
|
|
|
) :
|
|
|
|
str_replace(
|
|
|
|
'%T',
|
|
|
|
$feed->title,
|
|
|
|
$core->blog->settings->fac->fac_defaultfeedtitle
|
|
|
|
)
|
|
|
|
) . '</h3>';
|
|
|
|
}
|
|
|
|
|
|
|
|
# Feed desc
|
|
|
|
$feeddesc = '';
|
|
|
|
if ($core->blog->settings->fac->fac_showfeeddesc
|
|
|
|
&& '' != $feed->description) {
|
|
|
|
$feeddesc =
|
2021-08-23 13:22:15 +00:00
|
|
|
'<p>' . context::global_filters(
|
|
|
|
$feed->description,
|
|
|
|
['encode_xml', 'remove_html']
|
|
|
|
) . '</p>';
|
2021-08-20 16:39:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
# Date format
|
|
|
|
$dateformat = '' != $format['dateformat'] ?
|
|
|
|
$format['dateformat'] :
|
|
|
|
$core->blog->settings->system->date_format . ',' . $core->blog->settings->system->time_format;
|
|
|
|
|
|
|
|
# Enrties limit
|
|
|
|
$entrieslimit = abs((integer) $format['lineslimit']);
|
|
|
|
$uselimit = $entrieslimit > 0 ? true : false;
|
|
|
|
|
|
|
|
echo
|
|
|
|
'<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(
|
|
|
|
array(
|
|
|
|
'%D',
|
|
|
|
'%T',
|
|
|
|
'%A',
|
|
|
|
'%E',
|
|
|
|
'%C'
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
$date,
|
|
|
|
$item->title,
|
|
|
|
$item->creator,
|
|
|
|
$item->description,
|
|
|
|
$item->content
|
|
|
|
),
|
|
|
|
$format['linestitletext']
|
|
|
|
),
|
2021-08-23 13:22:15 +00:00
|
|
|
['remove_html', 'cut_string' => abs((integer) $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(
|
|
|
|
array(
|
|
|
|
'%D',
|
|
|
|
'%T',
|
|
|
|
'%A',
|
|
|
|
'%E',
|
|
|
|
'%C'
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
$date,
|
|
|
|
$item->title,
|
|
|
|
$item->creator,
|
|
|
|
$item->description,
|
|
|
|
$item->content
|
|
|
|
),
|
|
|
|
$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 = '';
|
|
|
|
if ($format['showlinesdescription']
|
|
|
|
&& '' != $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,
|
2021-08-23 13:22:15 +00:00
|
|
|
['remove_html' => (integer) $format['linesdescriptionnohtml'], 'cut_string' => abs((integer) $format['linesdescriptionlength'])]
|
2021-08-20 16:39:12 +00:00
|
|
|
) . '</dd>';
|
|
|
|
}
|
|
|
|
|
|
|
|
# Entries content
|
|
|
|
$content = '';
|
|
|
|
if ($format['showlinescontent']
|
|
|
|
&& '' != $item->content) {
|
|
|
|
$content = '<dd>'.
|
2021-08-23 13:22:15 +00:00
|
|
|
context::global_filters(
|
2021-08-20 16:39:12 +00:00
|
|
|
$item->content,
|
2021-08-23 13:22:15 +00:00
|
|
|
['remove_html' => (integer) $format['linescontentnohtml'], 'cut_string' => abs((integer) $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>';
|
|
|
|
}
|
|
|
|
}
|