enhancePostContent/_install.php

90 lines
3.3 KiB
PHP
Raw Normal View History

2021-08-23 23:55:52 +00:00
<?php
2021-09-02 18:35:25 +00:00
/**
* @brief enhancePostContent, a plugin for Dotclear 2
2021-11-01 09:33:43 +00:00
*
2021-09-02 18:35:25 +00:00
* @package Dotclear
* @subpackage Plugin
2021-11-01 09:33:43 +00:00
*
2021-09-02 18:35:25 +00:00
* @author Jean-Christian Denis and Contributors
2021-11-01 09:33:43 +00:00
*
2021-09-02 18:35:25 +00:00
* @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/
2021-08-23 23:55:52 +00:00
if (!defined('DC_CONTEXT_ADMIN')) {
return null;
2021-08-23 23:55:52 +00:00
}
2022-12-01 09:32:38 +00:00
try {
2022-12-10 14:20:39 +00:00
# Version
if (!dcCore::app()->newVersion(
basename(__DIR__),
dcCore::app()->plugins->moduleInfo(basename(__DIR__), 'version')
)) {
2022-12-01 09:32:38 +00:00
return null;
}
2021-08-23 23:55:52 +00:00
# Database
2022-11-13 20:30:48 +00:00
$s = new dbStruct(dcCore::app()->con, dcCore::app()->prefix);
2022-12-12 22:09:12 +00:00
$s->{initEnhancePostContent::TABLE_NAME}
2021-11-01 09:33:43 +00:00
->epc_id('bigint', 0, false)
->blog_id('varchar', 32, false)
->epc_type('varchar', 32, false, "'epc'")
->epc_filter('varchar', 64, false)
->epc_key('varchar', 255, false)
->epc_value('text', 0, false)
->epc_upddt('timestamp', 0, false, 'now()')
2021-08-23 23:55:52 +00:00
->primary('pk_epc', 'epc_id')
->index('idx_epc_blog_id', 'btree', 'blog_id')
->index('idx_epc_type', 'btree', 'epc_type')
->index('idx_epc_filter', 'btree', 'epc_filter')
->index('idx_epc_key', 'btree', 'epc_key');
2021-08-23 23:55:52 +00:00
2022-11-13 20:30:48 +00:00
$si = new dbStruct(dcCore::app()->con, dcCore::app()->prefix);
$changes = $si->synchronize($s);
2021-11-01 09:33:43 +00:00
$s = null;
# Settings
2022-12-10 14:20:39 +00:00
dcCore::app()->blog->settings->addNamespace(basename(__DIR__));
$s = dcCore::app()->blog->settings->__get(basename(__DIR__));
2021-11-01 09:33:43 +00:00
$s->put('enhancePostContent_active', false, 'boolean', 'Enable enhancePostContent', false, true);
$s->put('enhancePostContent_list_sortby', 'epc_key', 'string', 'Admin records list field order', false, true);
$s->put('enhancePostContent_list_order', 'desc', 'string', 'Admin records list order', false, true);
$s->put('enhancePostContent_list_nb', 20, 'integer', 'Admin records list nb per page', false, true);
$s->put('enhancePostContent_allowedtplvalues', serialize(libEPC::defaultAllowedTplValues()), 'string', 'List of allowed template values', false, true);
$s->put('enhancePostContent_allowedpubpages', serialize(libEPC::defaultAllowedPubPages()), 'string', 'List of allowed template pages', false, true);
# Filters settings
2021-10-31 22:22:34 +00:00
$filters = libEPC::getFilters();
2021-11-01 09:33:43 +00:00
foreach ($filters as $id => $filter) {
# Only editable options
$opt = [
2021-10-31 22:22:34 +00:00
'nocase' => $filter->nocase,
'plural' => $filter->plural,
'style' => $filter->style,
'notag' => $filter->notag,
'tplValues' => $filter->tplValues,
2022-11-13 20:30:48 +00:00
'pubPages' => $filter->pubPages,
];
2021-10-31 22:22:34 +00:00
$s->put('enhancePostContent_' . $id, serialize($opt), 'string', 'Settings for ' . $id, false, true);
2021-11-01 09:33:43 +00:00
/* # only tables
if (isset($filter['list'])) {
$s->put('enhancePostContent_' . $id . 'List', serialize($filter['list']), 'string', 'List for ' . $id, false, true);
}
*/
}
2021-10-31 22:22:34 +00:00
# Update old versions
2022-12-10 14:20:39 +00:00
$old_version = dcCore::app()->getVersion($mod_id);
2021-10-31 22:22:34 +00:00
if ($old_version && version_compare('2021.10.05', $old_version, '>=')) {
include_once dirname(__FILE__) . '/inc/lib.epc.update.php';
}
return true;
} catch (Exception $e) {
2022-11-13 20:30:48 +00:00
dcCore::app()->error->add($e->getMessage());
2021-08-23 23:55:52 +00:00
}
2021-11-01 09:33:43 +00:00
return false;