kUtRL/_install.php

104 lines
4.9 KiB
PHP
Raw Normal View History

2021-08-25 23:06:22 +00:00
<?php
/**
* @brief kUtRL, a plugin for Dotclear 2
2021-11-06 15:43:02 +00:00
*
* @package Dotclear
* @subpackage Plugin
2021-11-06 15:43:02 +00:00
*
* @author Jean-Christian Denis and contributors
2021-11-06 15:43:02 +00:00
*
* @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/
if (!defined('DC_CONTEXT_ADMIN')) {
return;
}
2021-08-25 23:06:22 +00:00
try {
2022-12-22 20:18:49 +00:00
// Compare versions
2022-12-10 14:34:50 +00:00
if (!dcCore::app()->newVersion(
2022-12-22 14:37:09 +00:00
basename(__DIR__),
2022-12-10 14:34:50 +00:00
dcCore::app()->plugins->moduleInfo(basename(__DIR__), 'version')
2022-12-07 23:10:29 +00:00
)) {
return null;
}
2022-12-22 20:18:49 +00:00
// Table
2022-11-20 16:15:36 +00:00
$t = new dbStruct(dcCore::app()->con, dcCore::app()->prefix);
2022-12-01 22:22:10 +00:00
$t->{initkUtRL::KURL_TABLE_NAME}
->kut_id('bigint', 0, false)
->blog_id('varchar', 32, false)
->kut_service('varchar', 32, false, "'kUtRL'")
->kut_type('varchar', 32, false)
->kut_hash('varchar', 32, false)
->kut_url('text', 0, false)
->kut_dt('timestamp', 0, false, 'now()')
->kut_password('varchar', 32, true)
->kut_counter('bigint', 0, false, 0)
->primary('pk_kutrl', 'kut_id')
->index('idx_kut_blog_id', 'btree', 'blog_id')
->index('idx_kut_hash', 'btree', 'kut_hash')
->index('idx_kut_service', 'btree', 'kut_service')
->index('idx_kut_type', 'btree', 'kut_type');
2022-11-20 16:15:36 +00:00
$ti = new dbStruct(dcCore::app()->con, dcCore::app()->prefix);
$changes = $ti->synchronize($t);
2022-12-22 20:18:49 +00:00
// upgrade version < 2022.12.22 : upgrade settings id and ns and array
$current = dcCore::app()->getVersion(basename(__DIR__));
if ($current && version_compare($current, '2022.12.22', '<')) {
$record = dcCore::app()->con->select(
'SELECT * FROM ' . dcCore::app()->prefix . dcNamespace::NS_TABLE_NAME . ' ' .
"WHERE setting_ns = 'kUtRL' "
);
while ($record->fetch()) {
if (preg_match('/^kutrl_(.*?)$/', $record->setting_id, $match)) {
$cur = dcCore::app()->con->openCursor(dcCore::app()->prefix . dcNamespace::NS_TABLE_NAME);
// avoid the use of serialize function
if (in_array($record->setting_id, ['kutrl_srv_custom'])) {
$cur->setting_value = json_encode(@unserialize(base64_decode((string) $record->setting_value)));
}
$cur->setting_id = $match[1];
$cur->setting_ns = basename(__DIR__);
$cur->update(
"WHERE setting_id = '" . $record->setting_id . "' and setting_ns = 'kUtRL' " .
'AND blog_id ' . (null === $record->blog_id ? 'IS NULL ' : ("= '" . dcCore::app()->con->escape($record->blog_id) . "' "))
);
}
}
} else {
// Settings
$s = dcCore::app()->blog->settings->addNamespace(basename(__DIR__));
2022-12-22 14:37:09 +00:00
2022-12-22 20:18:49 +00:00
$s->put('active', false, 'boolean', 'Enabled kutrl plugin', false, true);
$s->put('plugin_service', 'default', 'string', 'Service to use to shorten links on third part plugins', false, true);
$s->put('admin_service', 'local', 'string', 'Service to use to shorten links on admin', false, true);
$s->put('tpl_service', 'local', 'string', 'Service to use to shorten links on template', false, true);
$s->put('wiki_service', 'local', 'string', 'Service to use to shorten links on contents', false, true);
$s->put('allow_external_url', true, 'boolean', 'Limited short url to current blog\'s url', false, true);
$s->put('tpl_passive', true, 'boolean', 'Return long url on kutrl tags if kutrl is unactivate', false, true);
$s->put('tpl_active', false, 'boolean', 'Return short url on dotclear tags if kutrl is active', false, true);
$s->put('admin_entry_default', true, 'boolean', 'Create short link on new entry by default', false, true);
# Settings for "local" service
$local_css = ".shortenkutrlwidget input { border: 1px solid #CCCCCC; }\n" .
'.dc-kutrl input { border: 1px solid #CCCCCC; margin: 10px; }';
$s->put('srv_local_protocols', 'http:,https:,ftp:,ftps:,irc:', 'string', 'Allowed kutrl local service protocols', false, true);
$s->put('srv_local_public', false, 'boolean', 'Enabled local service public page', false, true);
$s->put('srv_local_css', $local_css, 'string', 'Special CSS for kutrl local service', false, true);
$s->put('srv_local_404_active', false, 'boolean', 'Use special 404 page on unknow urls', false, true);
# Settings for "bilbolinks" service
$s->put('srv_bilbolinks_base', 'http://tux-pla.net/', 'string', 'URL of bilbolinks service', false, true);
# Settings for "YOURLS" service
$s->put('srv_yourls_base', '', 'string', 'URL of YOURLS service', false, true);
$s->put('srv_yourls_username', '', 'string', 'User name to YOURLS service', false, true);
$s->put('srv_yourls_password', '', 'string', 'User password to YOURLS service', false, true);
}
2021-11-06 15:43:02 +00:00
return true;
} catch (Exception $e) {
2022-11-20 16:15:36 +00:00
dcCore::app()->error->add($e->getMessage());
2021-10-26 21:03:38 +00:00
}
2021-11-06 15:43:02 +00:00
return false;