lastBlogUpdate/_public.php

101 lines
3.7 KiB
PHP
Raw Normal View History

2015-04-22 21:44:23 +00:00
<?php
2021-09-02 19:25:11 +00:00
/**
* @brief lastBlogUpdate, a plugin for Dotclear 2
2022-11-15 21:39:21 +00:00
*
2021-09-02 19:25:11 +00:00
* @package Dotclear
* @subpackage Plugin
2022-11-15 21:39:21 +00:00
*
2021-09-02 19:25:11 +00:00
* @author Jean-Christian Denis, Pierre Van Glabeke
2022-11-15 21:39:21 +00:00
*
2021-09-02 19:25:11 +00:00
* @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/
2015-04-22 21:44:23 +00:00
if (!defined('DC_RC_PATH')) {
2021-09-02 19:25:11 +00:00
return null;
2015-04-22 21:44:23 +00:00
}
2022-11-15 21:39:21 +00:00
require __DIR__ . '/_widgets.php';
2015-04-22 21:44:23 +00:00
function lastBlogUpdateWidgetPublic($w)
{
2021-09-02 19:25:11 +00:00
if ($w->offline) {
return null;
}
# Nothing to display
2022-11-15 21:39:21 +00:00
if ($w->homeonly == 1 && dcCore::app()->url->type != 'default'
2022-11-20 20:17:29 +00:00
|| $w->homeonly == 2 && dcCore::app()->url->type == 'default'
2022-11-15 21:39:21 +00:00
|| !$w->blog_show && !$w->post_show && !$w->comment_show && !$w->media_show
|| !$w->blog_text && !$w->post_text && !$w->comment_text && !$w->media_text) {
2021-09-02 19:25:11 +00:00
return null;
}
$blog = $post = $comment = $media = $addons = '';
# Blog
if ($w->blog_show && $w->blog_text) {
$title = $w->blog_title ? sprintf('<strong>%s</strong>', html::escapeHTML($w->blog_title)) : '';
2022-11-15 21:39:21 +00:00
$text = dt::str($w->blog_text, dcCore::app()->blog->upddt, dcCore::app()->blog->settings->system->blog_timezone);
$blog = sprintf('<li>%s%s</li>', $title, $text);
2021-09-02 19:25:11 +00:00
}
# Post
if ($w->post_show && $w->post_text) {
2022-11-15 21:39:21 +00:00
$rs = dcCore::app()->blog->getPosts(['limit' => 1, 'no_content' => true]);
2021-09-02 19:25:11 +00:00
if (!$rs->isEmpty()) {
$title = $w->post_title ? sprintf('<strong>%s</strong>', html::escapeHTML($w->post_title)) : '';
2022-11-15 21:39:21 +00:00
$text = dt::str($w->post_text, strtotime($rs->post_upddt), dcCore::app()->blog->settings->system->blog_timezone);
$link = $rs->getURL();
$over = $rs->post_title;
2021-09-02 19:25:11 +00:00
$post = sprintf('<li>%s<a href="%s" title="%s">%s</a></li>', $title, $link, $over, $text);
}
}
# Comment
if ($w->comment_show && $w->comment_text) {
2022-11-15 21:39:21 +00:00
$rs = dcCore::app()->blog->getComments(['limit' => 1, 'no_content' => true]);
2021-09-02 19:25:11 +00:00
if (!$rs->isEmpty()) {
$title = $w->comment_title ? sprintf('<strong>%s</strong>', html::escapeHTML($w->comment_title)) : '';
2022-11-15 21:39:21 +00:00
$text = dt::str($w->comment_text, strtotime($rs->comment_upddt), dcCore::app()->blog->settings->system->blog_timezone);
$link = dcCore::app()->blog->url . dcCore::app()->getPostPublicURL($rs->post_type, html::sanitizeURL($rs->post_url)) . '#c' . $rs->comment_id;
$over = $rs->post_title;
2021-09-02 19:25:11 +00:00
$comment = sprintf('<li>%s<a href="%s" title="%s">%s</a></li>', $title, $link, $over, $text);
}
}
# Media
if ($w->media_show && $w->media_text) {
2022-11-15 21:39:21 +00:00
$rs = dcCore::app()->con->select(
'SELECT media_upddt FROM ' . dcCore::app()->prefix . dcMedia::MEDIA_TABLE_NAME . ' ' .
"WHERE media_path='" . dcCore::app()->con->escape(dcCore::app()->blog->settings->system->public_path) . "' " .
'ORDER BY media_upddt DESC ' . dcCore::app()->con->limit(1)
2021-09-02 19:25:11 +00:00
);
if (!$rs->isEmpty()) {
$title = $w->media_title ? sprintf('<strong>%s</strong>', html::escapeHTML($w->media_title)) : '';
2022-11-15 21:39:21 +00:00
$text = dt::str($w->media_text, strtotime($rs->f('media_upddt')), dcCore::app()->blog->settings->system->blog_timezone);
2021-09-02 19:25:11 +00:00
$media = sprintf('<li>%s%s</li>', $title, $text);
}
}
# --BEHAVIOR-- lastBlogUpdateWidgetParse
2022-11-15 21:39:21 +00:00
$addons = dcCore::app()->callBehavior('lastBlogUpdateWidgetParse', $w);
2021-09-02 19:25:11 +00:00
# Nothing to display
if (!$blog && !$post && !$comment && !$media && !$addons) {
return null;
}
# Display
return $w->renderDiv(
$w->content_only,
'lastblogupdate ' . $w->class,
'',
($w->title ? $w->renderTitle(html::escapeHTML($w->title)) : '') .
sprintf('<ul>%s</ul>', $blog . $post . $comment . $media . $addons)
);
2022-11-15 21:39:21 +00:00
}