myBlogNumbers/_public.php

151 lines
4.3 KiB
PHP
Raw Normal View History

2015-04-23 17:27:33 +00:00
<?php
2021-09-02 19:59:31 +00:00
/**
* @brief myBlogNumbers, a plugin for Dotclear 2
2022-11-14 22:20:46 +00:00
*
2021-09-02 19:59:31 +00:00
* @package Dotclear
* @subpackage Plugin
2022-11-14 22:20:46 +00:00
*
2021-09-02 19:59:31 +00:00
* @author Jean-Christian Denis, Pierre Van Glabeke
2022-11-14 22:20:46 +00:00
*
2021-09-02 19:59:31 +00:00
* @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/
2015-04-23 17:27:33 +00:00
if (!defined('DC_RC_PATH')) {
2021-08-27 16:24:02 +00:00
return null;
2015-04-23 17:27:33 +00:00
}
2022-11-14 22:20:46 +00:00
require __DIR__ . '/_widgets.php';
2015-04-23 17:27:33 +00:00
function myBlogNumbersWidgetPublic($w)
{
2021-08-27 16:24:02 +00:00
$content = $addons = '';
2022-11-14 22:20:46 +00:00
$s_line = '<li>%s%s</li>';
2021-08-27 16:24:02 +00:00
$s_title = '<strong>%s</strong> ';
if ($w->offline) {
return;
}
2022-11-14 22:20:46 +00:00
if (($w->homeonly == 1 && !dcCore::app()->url->isHome(dcCore::app()->url->type))
|| ($w->homeonly == 2 && dcCore::app()->url->isHome(dcCore::app()->url->type))) {
2021-08-27 16:24:02 +00:00
return null;
}
2015-04-23 17:27:33 +00:00
2021-08-27 16:24:02 +00:00
# Entry
if ($w->entry_show) {
2022-11-14 22:20:46 +00:00
$title = $w->entry_title ?
2021-08-27 16:24:02 +00:00
sprintf($s_title, html::escapeHTML($w->entry_title)) : '';
2022-11-14 22:20:46 +00:00
$count = dcCore::app()->blog->getPosts([], true)->f(0);
2021-08-27 16:24:02 +00:00
$text = $count == 0 ?
sprintf(__('no entries'), $count) :
sprintf(__('one entry', '%s entries', $count), $count);
$content .= sprintf($s_line, $title, $text);
}
# Cat
if ($w->cat_show) {
2022-11-14 22:20:46 +00:00
$title = $w->cat_title ?
2021-08-27 16:24:02 +00:00
sprintf($s_title, html::escapeHTML($w->cat_title)) : '';
2022-11-14 22:20:46 +00:00
$count = dcCore::app()->blog->getCategories([])->count();
2021-08-27 16:24:02 +00:00
$text = $count == 0 ?
sprintf(__('no categories'), $count) :
sprintf(__('one category', '%s categories', $count), $count);
$content .= sprintf($s_line, $title, $text);
}
# Comment
if ($w->comment_show) {
2022-11-14 22:20:46 +00:00
$title = $w->comment_title ?
2021-08-27 16:24:02 +00:00
sprintf($s_title, html::escapeHTML($w->comment_title)) : '';
$params = [
2022-11-14 22:20:46 +00:00
'post_type' => 'post',
'comment_status' => 1,
'comment_trackback' => 0,
2021-08-27 16:24:02 +00:00
];
2022-11-14 22:20:46 +00:00
$count = dcCore::app()->blog->getComments($params, true)->f(0);
2021-08-27 16:24:02 +00:00
$text = $count == 0 ?
2022-11-14 22:20:46 +00:00
sprintf(__('no comments'), $count) :
2021-08-27 16:24:02 +00:00
sprintf(__('one comment', '%s comments', $count), $count);
2022-11-14 22:20:46 +00:00
$content .= sprintf($s_line, $title, $text);
2021-08-27 16:24:02 +00:00
}
# Trackback
if ($w->trackback_show) {
2022-11-14 22:20:46 +00:00
$title = $w->trackback_title ?
2021-08-27 16:24:02 +00:00
sprintf($s_title, html::escapeHTML($w->trackback_title)) : '';
$params = [
2022-11-14 22:20:46 +00:00
'post_type' => 'post',
'comment_status' => 1,
'comment_trackback' => 1,
2021-08-27 16:24:02 +00:00
];
2022-11-14 22:20:46 +00:00
$count = dcCore::app()->blog->getComments($params, true)->f(0);
2021-08-27 16:24:02 +00:00
$text = $count == 0 ?
2022-11-14 22:20:46 +00:00
sprintf(__('no trackbacks'), $count) :
2021-08-27 16:24:02 +00:00
sprintf(__('one trackback', '%s trackbacks', $count), $count);
2022-11-14 22:20:46 +00:00
$content .= sprintf($s_line, $title, $text);
2021-08-27 16:24:02 +00:00
}
# Tag
2022-11-14 22:20:46 +00:00
if (dcCore::app()->plugins->moduleExists('tags') && $w->tag_show) {
$title = $w->tag_title ?
sprintf($s_title, html::escapeHTML($w->tag_title)) : '';
2021-08-27 16:24:02 +00:00
2022-11-14 22:20:46 +00:00
$count = dcCore::app()->con->select(
2021-08-27 16:24:02 +00:00
'SELECT count(M.meta_id) AS count ' .
2022-11-14 22:20:46 +00:00
'FROM ' . dcCore::app()->prefix . 'meta M ' .
'LEFT JOIN ' . dcCore::app()->prefix . 'post P ON P.post_id=M.post_id ' .
"WHERE M.meta_type='tag' " .
"AND P.blog_id='" . dcCore::app()->blog->id . "' "
2021-08-27 16:24:02 +00:00
)->f(0);
$text = $count == 0 ?
sprintf(__('no tags'), $count) :
sprintf(__('one tag', '%s tags', $count), $count);
$content .= sprintf($s_line, $title, $text);
}
# User (that post)
if ($w->user_show) {
2022-11-14 22:20:46 +00:00
$title = $w->user_title ?
2021-08-27 16:24:02 +00:00
sprintf($s_title, html::escapeHTML($w->user_title)) : '';
2022-11-14 22:20:46 +00:00
$count = dcCore::app()->blog->getPostsUsers('post')->count();
2021-08-27 16:24:02 +00:00
$text = $count == 0 ?
sprintf(__('no author'), $count) :
sprintf(__('one author', '%s authors', $count), $count);
2022-11-14 22:20:46 +00:00
$content .= sprintf($s_line, $title, $text);
2021-08-27 16:24:02 +00:00
}
# --BEHAVIOR-- myBlogNumbersWidgetParse
2022-11-14 22:20:46 +00:00
$addons = dcCore::app()->callBehavior('myBlogNumbersWidgetParse', $w);
2021-08-27 16:24:02 +00:00
# Nothing to display
if (!$content && !$addons) {
return null;
}
# Display
return $w->renderDiv(
$w->content_only,
'myblognumbers ' . $w->class,
'',
2022-11-14 22:20:46 +00:00
($w->title ? $w->renderTitle(html::escapeHTML($w->title)) : '') .
2021-08-27 16:24:02 +00:00
sprintf('<ul>%s</ul>', $content . $addons)
);
2022-11-14 22:20:46 +00:00
}