2021-08-25 23:06:22 +00:00
|
|
|
<?php
|
2021-09-02 12:32:26 +00:00
|
|
|
/**
|
|
|
|
* @brief kUtRL, a plugin for Dotclear 2
|
2021-11-06 15:43:02 +00:00
|
|
|
*
|
2021-09-02 12:32:26 +00:00
|
|
|
* @package Dotclear
|
|
|
|
* @subpackage Plugin
|
2021-11-06 15:43:02 +00:00
|
|
|
*
|
2021-09-02 12:32:26 +00:00
|
|
|
* @author Jean-Christian Denis and contributors
|
2021-11-06 15:43:02 +00:00
|
|
|
*
|
2021-09-02 12:32:26 +00:00
|
|
|
* @copyright Jean-Christian Denis
|
|
|
|
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
|
|
|
|
*/
|
2021-11-06 15:43:02 +00:00
|
|
|
# This file takes records from plugin dcMiniUrl
|
2021-08-25 23:06:22 +00:00
|
|
|
# and inserts them into plugin kUtRL.
|
|
|
|
|
2021-11-06 15:43:02 +00:00
|
|
|
if (!defined('DC_CONTEXT_ADMIN')) {
|
|
|
|
return;
|
|
|
|
}
|
2021-08-25 23:06:22 +00:00
|
|
|
|
2022-11-20 16:15:36 +00:00
|
|
|
$miniurl_patch = new dcMiniUrl2kUtRL();
|
2021-11-06 15:43:02 +00:00
|
|
|
if ($miniurl_patch->parseRecords()) {
|
|
|
|
try {
|
2022-11-20 16:15:36 +00:00
|
|
|
dcCore::app()->plugins->deactivateModule('dcMiniUrl');
|
2021-11-06 15:43:02 +00:00
|
|
|
} catch (Exception $e) {
|
2022-11-20 16:15:36 +00:00
|
|
|
//dcCore::app()->error->add($e->getMessage());
|
2021-09-02 12:32:26 +00:00
|
|
|
}
|
2021-08-25 23:06:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
class dcMiniUrl2kUtRL
|
|
|
|
{
|
2022-11-20 16:15:36 +00:00
|
|
|
public $con;
|
2021-09-02 12:32:26 +00:00
|
|
|
public $k_tb;
|
|
|
|
public $m_tb;
|
|
|
|
|
2022-11-20 16:15:36 +00:00
|
|
|
public function __construct()
|
2021-09-02 12:32:26 +00:00
|
|
|
{
|
2022-11-20 16:15:36 +00:00
|
|
|
$this->con = dcCore::app()->con;
|
|
|
|
$this->k_tb = dcCore::app()->prefix . 'kutrl';
|
|
|
|
$this->m_tb = dcCore::app()->prefix . 'miniurl';
|
2021-09-02 12:32:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function parseRecords()
|
|
|
|
{
|
|
|
|
$rs = $this->con->select(
|
2021-11-06 15:43:02 +00:00
|
|
|
'SELECT * FROM ' . $this->m_tb . ' '
|
2021-09-02 12:32:26 +00:00
|
|
|
);
|
|
|
|
|
2021-11-06 15:43:02 +00:00
|
|
|
while ($rs->fetch()) {
|
|
|
|
if ($rs->miniurl_type == 'customurl' || $rs->miniurl_type == 'miniurl') {
|
|
|
|
if ($this->exists($rs)) {
|
|
|
|
continue;
|
|
|
|
}
|
2021-09-02 12:32:26 +00:00
|
|
|
|
|
|
|
$this->insertKutrl($rs);
|
|
|
|
$this->insertLocal($rs);
|
2021-11-06 15:43:02 +00:00
|
|
|
} else {
|
2021-09-02 12:32:26 +00:00
|
|
|
$this->insertOther($rs);
|
|
|
|
}
|
|
|
|
}
|
2021-11-06 15:43:02 +00:00
|
|
|
|
2021-09-02 12:32:26 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
private function insertKutrl($rs)
|
|
|
|
{
|
2021-11-06 15:43:02 +00:00
|
|
|
$cur = $this->common($rs);
|
|
|
|
$cur->kut_service = 'kutrl';
|
|
|
|
$cur->kut_type = 'local';
|
|
|
|
$cur->kut_counter = 0;
|
2021-09-02 12:32:26 +00:00
|
|
|
$cur->kut_password = null;
|
|
|
|
|
|
|
|
$cur->insert();
|
|
|
|
$this->con->unlock();
|
|
|
|
}
|
|
|
|
|
|
|
|
private function insertLocal($rs)
|
|
|
|
{
|
2021-11-06 15:43:02 +00:00
|
|
|
$cur = $this->common($rs);
|
2021-09-02 12:32:26 +00:00
|
|
|
$cur->kut_service = 'local';
|
2021-11-06 15:43:02 +00:00
|
|
|
$cur->kut_type = $rs->miniurl_type == 'customurl' ?
|
2021-09-02 12:32:26 +00:00
|
|
|
'localcustom' : 'localnormal';
|
|
|
|
|
|
|
|
$cur->insert();
|
|
|
|
$this->con->unlock();
|
|
|
|
}
|
|
|
|
|
|
|
|
private function insertOther($rs)
|
|
|
|
{
|
|
|
|
$cur = $this->common($rs);
|
|
|
|
|
|
|
|
$cur->insert();
|
|
|
|
$this->con->unlock();
|
|
|
|
}
|
|
|
|
|
|
|
|
private function common($rs)
|
|
|
|
{
|
|
|
|
$cur = $this->con->openCursor($this->k_tb);
|
|
|
|
$this->con->writeLock($this->k_tb);
|
2021-11-06 15:43:02 +00:00
|
|
|
$cur->kut_id = $this->nextId();
|
|
|
|
$cur->blog_id = $rs->blog_id;
|
|
|
|
$cur->kut_service = 'unknow';
|
|
|
|
$cur->kut_type = $rs->miniurl_type;
|
|
|
|
$cur->kut_hash = $rs->miniurl_id;
|
|
|
|
$cur->kut_url = $rs->miniurl_str;
|
|
|
|
$cur->kut_dt = $rs->miniurl_dt;
|
|
|
|
$cur->kut_counter = $rs->miniurl_counter;
|
2021-09-02 12:32:26 +00:00
|
|
|
$cur->kut_password = $rs->miniurl_password;
|
|
|
|
|
|
|
|
return $cur;
|
|
|
|
}
|
|
|
|
|
|
|
|
private function exists($rs)
|
|
|
|
{
|
|
|
|
$chk = $this->con->select(
|
2021-11-06 15:43:02 +00:00
|
|
|
'SELECT kut_hash FROM ' . $this->k_tb . ' ' .
|
|
|
|
"WHERE blog_id = '" . $rs->blog_id . "' " .
|
|
|
|
"AND kut_service = 'local' " .
|
|
|
|
"AND kut_hash = '" . $rs->miniurl_id . "' "
|
2021-09-02 12:32:26 +00:00
|
|
|
);
|
2021-11-06 15:43:02 +00:00
|
|
|
|
2021-09-02 12:32:26 +00:00
|
|
|
return !$chk->isEmpty();
|
|
|
|
}
|
|
|
|
|
|
|
|
private function nextId()
|
|
|
|
{
|
|
|
|
return $this->con->select(
|
2021-11-06 15:43:02 +00:00
|
|
|
'SELECT MAX(kut_id) FROM ' . $this->k_tb . ' '
|
2021-09-02 12:32:26 +00:00
|
|
|
)->f(0) + 1;
|
|
|
|
}
|
2021-11-06 15:43:02 +00:00
|
|
|
}
|