diff --git a/_public.php b/_public.php index 6d510c5..f21cfac 100644 --- a/_public.php +++ b/_public.php @@ -14,226 +14,206 @@ if (!defined('DC_RC_PATH')) { return null; } -dcCore::app()->addBehavior( - 'publicEntryAfterContent', - ['facPublic', 'publicEntryAfterContent'] -); +dcCore::app()->addBehavior('publicEntryAfterContent', function (dcCore $core, context $_ctx) { + dcCore::app()->blog->settings->addNamespace('fac'); -/** - * @ingroup DC_PLUGIN_FAC - * @brief Linked feed to entries - public methods. - * @since 2.6 - */ -class facPublic -{ - /** - * Add feed after entry - * - * @param dcCore $core dcCore instance - * @param context $_ctx context instance - */ - public static function publicEntryAfterContent(dcCore $core, context $_ctx) - { - dcCore::app()->blog->settings->addNamespace('fac'); + # Not active or not a post + if (!dcCore::app()->blog->settings->fac->fac_active + || !dcCore::app()->ctx->exists('posts')) { + return null; + } - # Not active or not a post - if (!dcCore::app()->blog->settings->fac->fac_active - || !dcCore::app()->ctx->exists('posts')) { - return null; - } + # Not in page to show + $types = @unserialize((string) dcCore::app()->blog->settings->fac->fac_public_tpltypes); + if (!is_array($types) + || !in_array(dcCore::app()->url->type, $types)) { + return null; + } - # Not in page to show - $types = @unserialize((string) dcCore::app()->blog->settings->fac->fac_public_tpltypes); - if (!is_array($types) - || !in_array(dcCore::app()->url->type, $types)) { - return null; - } + # Get related feed + $fac_url = dcCore::app()->meta->getMetadata([ + 'meta_type' => 'fac', + 'post_id' => dcCore::app()->ctx->posts->post_id, + 'limit' => 1, + ]); + if ($fac_url->isEmpty()) { + return null; + } - # Get related feed - $fac_url = dcCore::app()->meta->getMetadata([ - 'meta_type' => 'fac', - 'post_id' => dcCore::app()->ctx->posts->post_id, - 'limit' => 1, - ]); - if ($fac_url->isEmpty()) { - return null; - } + # Get related format + $fac_format = dcCore::app()->meta->getMetadata([ + 'meta_type' => 'facformat', + 'post_id' => dcCore::app()->ctx->posts->post_id, + 'limit' => 1, + ]); + if ($fac_format->isEmpty()) { + return null; + } - # Get related format - $fac_format = dcCore::app()->meta->getMetadata([ - 'meta_type' => 'facformat', - 'post_id' => dcCore::app()->ctx->posts->post_id, - 'limit' => 1, - ]); - if ($fac_format->isEmpty()) { - return null; - } + # Get format info + $default_format = [ + 'name' => 'default', + 'dateformat' => '', + 'lineslimit' => '5', + 'linestitletext' => '%T', + 'linestitleover' => '%D', + 'linestitlelength' => '150', + 'showlinesdescription' => '0', + 'linesdescriptionlength' => '350', + 'linesdescriptionnohtml' => '1', + 'showlinescontent' => '0', + 'linescontentlength' => '350', + 'linescontentnohtml' => '1', + ]; - # Get format info - $default_format = [ - '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((string) dcCore::app()->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] + ); + } - $formats = @unserialize((string) dcCore::app()->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; - # 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; + } - try { - $feed = feedReader::quickParse($fac_url->meta_id, $cache); - } catch (Exception $e) { - $feed = null; - } + # No entries + if (!$feed) { + return null; + } - # No entries - if (!$feed) { - return null; - } + # Feed title + $feedtitle = ''; + if ('' != dcCore::app()->blog->settings->fac->fac_defaultfeedtitle) { + $feedtitle = '

' . html::escapeHTML( + empty($feed->title) ? + str_replace( + '%T', + __('a related feed'), + dcCore::app()->blog->settings->fac->fac_defaultfeedtitle + ) : + str_replace( + '%T', + $feed->title, + dcCore::app()->blog->settings->fac->fac_defaultfeedtitle + ) + ) . '

'; + } - # Feed title - $feedtitle = ''; - if ('' != dcCore::app()->blog->settings->fac->fac_defaultfeedtitle) { - $feedtitle = '

' . html::escapeHTML( - empty($feed->title) ? - str_replace( + # Feed desc + $feeddesc = ''; + if (dcCore::app()->blog->settings->fac->fac_showfeeddesc + && '' != $feed->description) { + $feeddesc = '

' . context::global_filters( + $feed->description, + ['encode_xml', 'remove_html'] + ) . '

'; + } + + # Date format + $dateformat = '' != $format['dateformat'] ? + $format['dateformat'] : + dcCore::app()->blog->settings->system->date_format . ',' . dcCore::app()->blog->settings->system->time_format; + + # Enrties limit + $entrieslimit = abs((int) $format['lineslimit']); + $uselimit = $entrieslimit > 0 ? true : false; + + echo + '
' . + $feedtitle . $feeddesc . + '
'; + + $i = 0; + foreach ($feed->items as $item) { + # Format date + $date = dt::dt2str($dateformat, $item->pubdate); + + # Entries title + $title = context::global_filters( + str_replace( + [ + '%D', '%T', - __('a related feed'), - dcCore::app()->blog->settings->fac->fac_defaultfeedtitle - ) : - str_replace( + '%A', + '%E', + '%C', + ], + [ + $date, + $item->title, + $item->creator, + $item->description, + $item->content, + ], + $format['linestitletext'] + ), + ['remove_html', 'cut_string' => abs((int) $format['linestitlelength'])], + ); + + # Entries over title + $overtitle = context::global_filters( + str_replace( + [ + '%D', '%T', - $feed->title, - dcCore::app()->blog->settings->fac->fac_defaultfeedtitle - ) - ) . '

'; + '%A', + '%E', + '%C', + ], + [ + $date, + $item->title, + $item->creator, + $item->description, + $item->content, + ], + $format['linestitleover'] + ), + ['remove_html', 'cut_string' => 350], + ); + + # Entries description + $description = ''; + if ($format['showlinesdescription'] + && '' != $item->description) { + $description = '
' . + context::global_filters( + $item->description, + ['remove_html' => (int) $format['linesdescriptionnohtml'], 'cut_string' => abs((int) $format['linesdescriptionlength'])] + ) . '
'; } - # Feed desc - $feeddesc = ''; - if (dcCore::app()->blog->settings->fac->fac_showfeeddesc - && '' != $feed->description) { - $feeddesc = '

' . context::global_filters( - $feed->description, - ['encode_xml', 'remove_html'] - ) . '

'; + # Entries content + $content = ''; + if ($format['showlinescontent'] + && '' != $item->content) { + $content = '
' . + context::global_filters( + $item->content, + ['remove_html' => (int) $format['linescontentnohtml'], 'cut_string' => abs((int) $format['linescontentlength'])] + ) . '
'; } - # Date format - $dateformat = '' != $format['dateformat'] ? - $format['dateformat'] : - dcCore::app()->blog->settings->system->date_format . ',' . dcCore::app()->blog->settings->system->time_format; - - # Enrties limit - $entrieslimit = abs((int) $format['lineslimit']); - $uselimit = $entrieslimit > 0 ? true : false; - echo - '
' . - $feedtitle . $feeddesc . - '
'; + '
' . $title . '
' . + $description . $content; - $i = 0; - foreach ($feed->items as $item) { - # Format date - $date = dt::dt2str($dateformat, $item->pubdate); - - # Entries title - $title = context::global_filters( - str_replace( - [ - '%D', - '%T', - '%A', - '%E', - '%C', - ], - [ - $date, - $item->title, - $item->creator, - $item->description, - $item->content, - ], - $format['linestitletext'] - ), - ['remove_html', 'cut_string' => abs((int) $format['linestitlelength'])], - ); - - # Entries over title - $overtitle = context::global_filters( - str_replace( - [ - '%D', - '%T', - '%A', - '%E', - '%C', - ], - [ - $date, - $item->title, - $item->creator, - $item->description, - $item->content, - ], - $format['linestitleover'] - ), - ['remove_html', 'cut_string' => 350], - ); - - # Entries description - $description = ''; - if ($format['showlinesdescription'] - && '' != $item->description) { - $description = '
' . - context::global_filters( - $item->description, - ['remove_html' => (int) $format['linesdescriptionnohtml'], 'cut_string' => abs((int) $format['linesdescriptionlength'])] - ) . '
'; - } - - # Entries content - $content = ''; - if ($format['showlinescontent'] - && '' != $item->content) { - $content = '
' . - context::global_filters( - $item->content, - ['remove_html' => (int) $format['linescontentnohtml'], 'cut_string' => abs((int) $format['linescontentlength'])] - ) . '
'; - } - - echo - '
' . $title . '
' . - $description . $content; - - $i++; - if ($uselimit && $i == $entrieslimit) { - break; - } + $i++; + if ($uselimit && $i == $entrieslimit) { + break; } - echo '
'; } -} + echo ''; +});