2021-09-10 19:06:49 +00:00
|
|
|
<?php
|
2021-09-10 19:18:51 +00:00
|
|
|
/**
|
|
|
|
* @brief postWidgetText, a plugin for Dotclear 2
|
2021-11-06 15:11:19 +00:00
|
|
|
*
|
2021-09-10 19:18:51 +00:00
|
|
|
* @package Dotclear
|
|
|
|
* @subpackage Plugin
|
2021-11-06 15:11:19 +00:00
|
|
|
*
|
2021-09-10 19:18:51 +00:00
|
|
|
* @author Jean-Christian Denis and Contributors
|
2021-11-06 15:11:19 +00:00
|
|
|
*
|
2021-09-10 19:18:51 +00:00
|
|
|
* @copyright Jean-Christian Denis
|
|
|
|
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
|
|
|
|
*/
|
2021-09-10 19:06:49 +00:00
|
|
|
/**
|
|
|
|
* @ingroup DC_PLUGIN_POSTWIDGETTEXT
|
2021-10-30 13:49:37 +00:00
|
|
|
* @brief postWidgetText - admin methods.
|
2021-10-30 08:30:01 +00:00
|
|
|
* @since 2.20
|
2021-09-10 19:06:49 +00:00
|
|
|
*/
|
2021-10-30 08:30:01 +00:00
|
|
|
class adminPostWidgetText
|
2021-09-10 19:06:49 +00:00
|
|
|
{
|
2021-10-29 22:36:04 +00:00
|
|
|
public static function sortbyCombo()
|
|
|
|
{
|
|
|
|
return [
|
|
|
|
__('Post title') => 'post_title',
|
|
|
|
__('Post date') => 'post_dt',
|
|
|
|
__('Widget title') => 'option_title',
|
|
|
|
__('Widget date') => 'option_upddt',
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
2022-11-15 21:05:23 +00:00
|
|
|
public static function adminFiltersLists($sorts)
|
2021-10-29 22:36:04 +00:00
|
|
|
{
|
|
|
|
$sorts['pwt'] = [
|
|
|
|
__('Post widget text'),
|
|
|
|
self::sortbyCombo(),
|
|
|
|
'post_dt',
|
|
|
|
'desc',
|
2022-11-15 21:07:37 +00:00
|
|
|
[__('entries per page'), 20],
|
2021-10-29 22:36:04 +00:00
|
|
|
];
|
|
|
|
}
|
|
|
|
|
2022-11-15 21:05:23 +00:00
|
|
|
public static function adminBlogPreferencesForm(dcSettings $blog_settings)
|
2021-10-30 08:02:04 +00:00
|
|
|
{
|
|
|
|
echo '
|
|
|
|
<div class="fieldset">
|
|
|
|
<h4 id="pwt_params">' . __('Post widget text') . '</h4>
|
|
|
|
<div class="two-cols">
|
|
|
|
<div class="col">
|
|
|
|
<p><label for="active">' .
|
2021-11-06 15:11:19 +00:00
|
|
|
form::checkbox('active', 1, (bool) $blog_settings->postwidgettext->postwidgettext_active) .
|
2021-10-30 08:41:54 +00:00
|
|
|
__('Enable post widget text on this blog') . '</label></p>
|
2021-10-30 08:02:04 +00:00
|
|
|
</div>
|
|
|
|
<div class="col">
|
|
|
|
<p><label for="importexport_active">' .
|
2021-11-06 15:11:19 +00:00
|
|
|
form::checkbox('importexport_active', 1, (bool) $blog_settings->postwidgettext->postwidgettext_importexport_active) .
|
2021-10-30 08:02:04 +00:00
|
|
|
__('Enable import/export behaviors') . '</label></p>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<br class="clear" />
|
|
|
|
</div>';
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function adminBeforeBlogSettingsUpdate(dcSettings $blog_settings)
|
|
|
|
{
|
|
|
|
$blog_settings->postwidgettext->put('postwidgettext_active', !empty($_POST['active']));
|
|
|
|
$blog_settings->postwidgettext->put('postwidgettext_importexport_active', !empty($_POST['importexport_active']));
|
2021-10-30 08:30:01 +00:00
|
|
|
}
|
|
|
|
|
2022-11-15 21:05:23 +00:00
|
|
|
public static function adminDashboardFavorites(dcFavorites $favs)
|
2021-10-30 08:30:01 +00:00
|
|
|
{
|
|
|
|
$favs->register('postWidgetText', [
|
|
|
|
'title' => __('Post widget text'),
|
2022-11-15 21:05:23 +00:00
|
|
|
'url' => dcCore::app()->adminurl->get('admin.plugin.postWidgetText'),
|
2022-11-26 14:04:22 +00:00
|
|
|
'small-icon' => dcPage::getPF('postWidgetText/icon.svg'),
|
|
|
|
'large-icon' => dcPage::getPF('postWidgetText/icon.svg'),
|
2022-12-03 15:49:44 +00:00
|
|
|
'permissions' => dcCore::app()->auth->makePermissions([
|
2022-11-20 20:53:22 +00:00
|
|
|
dcAuth::PERMISSION_USAGE,
|
|
|
|
dcAuth::PERMISSION_CONTENT_ADMIN,
|
2022-12-03 15:49:44 +00:00
|
|
|
]),
|
2021-10-30 08:30:01 +00:00
|
|
|
]);
|
|
|
|
}
|
2021-10-30 08:02:04 +00:00
|
|
|
|
2021-10-30 08:30:01 +00:00
|
|
|
public static function adminPostHeaders()
|
2021-09-10 19:18:51 +00:00
|
|
|
{
|
2022-11-15 21:05:23 +00:00
|
|
|
$editor = dcCore::app()->auth->getOption('editor');
|
2021-10-30 13:31:51 +00:00
|
|
|
|
2021-11-06 15:11:19 +00:00
|
|
|
return
|
2022-11-15 21:05:23 +00:00
|
|
|
dcCore::app()->callBehavior('adminPostEditor', $editor['xhtml'], 'pwt', ['#post_wtext'], 'xhtml') .
|
2021-10-30 13:31:51 +00:00
|
|
|
dcPage::jsLoad(dcPage::getPF('postWidgetText/js/post.js'));
|
2021-09-10 19:18:51 +00:00
|
|
|
}
|
|
|
|
|
2021-10-30 08:30:01 +00:00
|
|
|
public static function adminPostFormItems($main, $sidebar, $post)
|
2021-09-10 19:18:51 +00:00
|
|
|
{
|
|
|
|
# _POST fields
|
2021-11-06 15:11:19 +00:00
|
|
|
$title = $_POST['post_wtitle'] ?? '';
|
|
|
|
$content = $_POST['post_wtext'] ?? '';
|
2021-09-10 19:18:51 +00:00
|
|
|
|
|
|
|
# Existing post
|
|
|
|
if ($post) {
|
2021-11-06 15:11:19 +00:00
|
|
|
$post_id = (int) $post->post_id;
|
2021-09-10 19:18:51 +00:00
|
|
|
|
2022-11-15 21:05:23 +00:00
|
|
|
$pwt = new postWidgetText();
|
2021-11-06 15:11:19 +00:00
|
|
|
$w = $pwt->getWidgets(['post_id' => $post_id]);
|
2021-09-10 19:18:51 +00:00
|
|
|
|
|
|
|
# Existing widget
|
|
|
|
if (!$w->isEmpty()) {
|
2021-11-06 15:11:19 +00:00
|
|
|
$title = $w->option_title;
|
2021-09-10 19:18:51 +00:00
|
|
|
$content = $w->option_content;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-11-06 15:11:19 +00:00
|
|
|
$main['post_widget'] = '<div id="post-wtext-form">' .
|
2021-10-29 23:12:43 +00:00
|
|
|
'<h4>' . __('Additional widget') . '</h4>' .
|
2021-09-10 19:18:51 +00:00
|
|
|
|
2021-10-29 23:14:58 +00:00
|
|
|
'<p class="col">' .
|
2021-10-29 23:12:43 +00:00
|
|
|
'<label class="bold" for="post_wtitle">' . __('Widget title:') . '</label>' .
|
|
|
|
form::field('post_wtitle', 20, 255, html::escapeHTML($title), 'maximal') .
|
|
|
|
'</p>' .
|
2021-09-10 19:18:51 +00:00
|
|
|
|
2021-10-29 23:12:43 +00:00
|
|
|
'<p class="area" id="post-wtext">' .
|
2021-11-06 15:11:19 +00:00
|
|
|
'<label class="bold" for="post_wtext">' . __('Wigdet text:') . '</label>' .
|
2021-10-29 23:12:43 +00:00
|
|
|
form::textarea('post_wtext', 50, 5, html::escapeHTML($content)) .
|
|
|
|
'</p>' .
|
2021-09-10 19:18:51 +00:00
|
|
|
|
|
|
|
'</div>';
|
|
|
|
}
|
|
|
|
|
2021-10-30 08:30:01 +00:00
|
|
|
public static function adminAfterPostSave($cur, $post_id)
|
2021-09-10 19:18:51 +00:00
|
|
|
{
|
2021-11-06 15:11:19 +00:00
|
|
|
$post_id = (int) $post_id;
|
2021-09-10 19:18:51 +00:00
|
|
|
|
|
|
|
# _POST fields
|
2021-11-06 15:11:19 +00:00
|
|
|
$title = $_POST['post_wtitle'] ?? '';
|
|
|
|
$content = $_POST['post_wtext'] ?? '';
|
2021-09-10 19:18:51 +00:00
|
|
|
|
|
|
|
# Object
|
2022-11-15 21:05:23 +00:00
|
|
|
$pwt = new postWidgetText();
|
2021-09-10 19:18:51 +00:00
|
|
|
|
|
|
|
# Get existing widget
|
2021-10-29 23:12:43 +00:00
|
|
|
$w = $pwt->getWidgets(['post_id' => $post_id]);
|
2021-09-10 19:18:51 +00:00
|
|
|
|
|
|
|
# If new content is empty, delete old existing widget
|
|
|
|
if (empty($title) && empty($content) && !$w->isEmpty()) {
|
|
|
|
$pwt->delWidget($w->option_id);
|
|
|
|
}
|
|
|
|
|
|
|
|
# If new content is not empty
|
|
|
|
if (!empty($title) || !empty($content)) {
|
2021-11-06 15:11:19 +00:00
|
|
|
$wcur = $pwt->openCursor();
|
2021-09-10 19:18:51 +00:00
|
|
|
$wcur->post_id = $post_id;
|
2021-10-29 23:12:43 +00:00
|
|
|
$wcur->option_type = 'postwidgettext';
|
|
|
|
$wcur->option_lang = $cur->post_lang;
|
|
|
|
$wcur->option_format = $cur->post_format;
|
|
|
|
$wcur->option_title = $title;
|
|
|
|
$wcur->option_content = $content;
|
2021-09-10 19:18:51 +00:00
|
|
|
|
|
|
|
# Create widget
|
|
|
|
if ($w->isEmpty()) {
|
|
|
|
$id = $pwt->addWidget($wcur);
|
|
|
|
}
|
|
|
|
# Upddate widget
|
|
|
|
else {
|
2021-10-29 23:12:43 +00:00
|
|
|
$pwt->updWidget($w->option_id, $wcur);
|
2021-09-10 19:18:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-30 08:30:01 +00:00
|
|
|
public static function adminBeforePostDelete($post_id)
|
2021-09-10 19:18:51 +00:00
|
|
|
{
|
2021-11-06 15:11:19 +00:00
|
|
|
$post_id = (int) $post_id;
|
2021-09-10 19:18:51 +00:00
|
|
|
|
|
|
|
# Object
|
2022-11-15 21:05:23 +00:00
|
|
|
$pwt = new postWidgetText();
|
2021-09-10 19:18:51 +00:00
|
|
|
|
|
|
|
# Get existing widget
|
2021-10-29 23:12:43 +00:00
|
|
|
$w = $pwt->getWidgets(['post_id' => $post_id]);
|
2021-09-10 19:18:51 +00:00
|
|
|
|
|
|
|
# If new content is empty, delete old existing widget
|
|
|
|
if (!$w->isEmpty()) {
|
|
|
|
$pwt->delWidget($w->option_id);
|
|
|
|
}
|
|
|
|
}
|
2021-10-30 08:30:01 +00:00
|
|
|
|
|
|
|
public static function exportSingle(dcCore $core, $exp, $blog_id)
|
|
|
|
{
|
2021-11-06 15:11:19 +00:00
|
|
|
$exp->export(
|
|
|
|
'postwidgettext',
|
2021-10-30 08:30:01 +00:00
|
|
|
'SELECT option_type, option_content, ' .
|
|
|
|
'option_content_xhtml, W.post_id ' .
|
2022-11-15 21:05:23 +00:00
|
|
|
'FROM ' . dcCore::app()->prefix . 'post_option W ' .
|
|
|
|
'LEFT JOIN ' . dcCore::app()->prefix . 'post P ' .
|
2021-10-30 08:30:01 +00:00
|
|
|
'ON P.post_id = W.post_id ' .
|
|
|
|
"WHERE P.blog_id = '" . $blog_id . "' " .
|
|
|
|
"AND W.option_type = 'postwidgettext' "
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function exportFull(dcCore $core, $exp)
|
|
|
|
{
|
2021-11-06 15:11:19 +00:00
|
|
|
$exp->export(
|
|
|
|
'postwidgettext',
|
2021-10-30 08:30:01 +00:00
|
|
|
'SELECT option_type, option_content, ' .
|
2021-11-06 15:11:19 +00:00
|
|
|
'option_content_xhtml, W.post_id ' .
|
2022-11-15 21:05:23 +00:00
|
|
|
'FROM ' . dcCore::app()->prefix . 'post_option W ' .
|
|
|
|
'LEFT JOIN ' . dcCore::app()->prefix . 'post P ' .
|
2021-10-30 08:30:01 +00:00
|
|
|
'ON P.post_id = W.post_id ' .
|
|
|
|
"WHERE W.option_type = 'postwidgettext' "
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function importInit($bk, dcCore $core)
|
|
|
|
{
|
2022-11-15 21:05:23 +00:00
|
|
|
$bk->cur_postwidgettext = dcCore::app()->con->openCursor(
|
|
|
|
dcCore::app()->prefix . 'post_option'
|
2021-10-30 08:30:01 +00:00
|
|
|
);
|
2022-11-15 21:05:23 +00:00
|
|
|
$bk->postwidgettext = new postWidgetText();
|
2021-10-30 08:30:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public static function importSingle($line, $bk, dcCore $core)
|
|
|
|
{
|
2021-11-06 15:11:19 +00:00
|
|
|
if ($line->__name == 'postwidgettext'
|
|
|
|
&& isset($bk->old_ids['post'][(int) $line->post_id])
|
2021-10-30 08:30:01 +00:00
|
|
|
) {
|
2021-11-06 15:11:19 +00:00
|
|
|
$line->post_id = $bk->old_ids['post'][(int) $line->post_id];
|
2021-10-30 08:30:01 +00:00
|
|
|
|
|
|
|
$exists = $bk->postwidgettext->getWidgets([
|
2022-11-15 21:07:37 +00:00
|
|
|
'post_id' => $line->post_id,
|
2021-10-30 08:30:01 +00:00
|
|
|
]);
|
|
|
|
|
|
|
|
if ($exists->isEmpty()) {
|
|
|
|
$bk->cur_postwidgettext->clean();
|
|
|
|
|
2021-11-06 15:11:19 +00:00
|
|
|
$bk->cur_postwidgettext->post_id = (int) $line->post_id;
|
|
|
|
$bk->cur_postwidgettext->option_type = (string) $line->option_type;
|
|
|
|
$bk->cur_postwidgettext->option_lang = (string) $line->option_lang;
|
|
|
|
$bk->cur_postwidgettext->option_format = (string) $line->option_format;
|
|
|
|
$bk->cur_postwidgettext->option_content = (string) $line->option_content;
|
|
|
|
$bk->cur_postwidgettext->option_content_xhtml = (string) $line->option_content_xhtml;
|
2021-10-30 08:30:01 +00:00
|
|
|
|
|
|
|
$bk->postwidgettext->addWidget(
|
|
|
|
$bk->cur_postwidgettext
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function importFull($line, $bk, dcCore $core)
|
|
|
|
{
|
|
|
|
if ($line->__name == 'postwidgettext') {
|
|
|
|
$exists = $bk->postwidgettext->getWidgets([
|
2022-11-15 21:07:37 +00:00
|
|
|
'post_id' => $line->post_id,
|
2021-10-30 08:30:01 +00:00
|
|
|
]);
|
|
|
|
|
|
|
|
if ($exists->isEmpty()) {
|
|
|
|
$bk->cur_postwidgettext->clean();
|
|
|
|
|
2021-11-06 15:11:19 +00:00
|
|
|
$bk->cur_postwidgettext->post_id = (int) $line->post_id;
|
|
|
|
$bk->cur_postwidgettext->option_type = (string) $line->option_type;
|
|
|
|
$bk->cur_postwidgettext->option_format = (string) $line->option_format;
|
|
|
|
$bk->cur_postwidgettext->option_content = (string) $line->option_content;
|
|
|
|
$bk->cur_postwidgettext->option_content = (string) $line->option_content;
|
|
|
|
$bk->cur_postwidgettext->option_content_xhtml = (string) $line->option_content_xhtml;
|
2021-10-30 08:30:01 +00:00
|
|
|
|
|
|
|
$bk->postwidgettext->addWidget(
|
|
|
|
$bk->cur_postwidgettext
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-11-06 15:11:19 +00:00
|
|
|
}
|