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
*/
2022-11-13 20:30:48 +00:00
if ( ! isset ( $old_version )) {
return null ;
}
2021-10-31 22:22:34 +00:00
# Move old filters lists from settings to database
if ( $old_version && version_compare ( '0.6.6' , $old_version , '>=' )) {
2022-11-30 23:42:12 +00:00
$f = dcCore :: app () -> con -> select ( 'SELECT * FROM ' . dcCore :: app () -> prefix . dcNamespace :: NS_TABLE_NAME . " WHERE setting_ns='enhancePostContent' AND blog_id IS NOT NULL " );
2021-08-23 23:55:52 +00:00
2021-10-31 22:22:34 +00:00
while ( $f -> fetch ()) {
2021-11-01 09:33:43 +00:00
if ( preg_match ( '#enhancePostContent_(.*?)List#' , $f -> setting_id , $m )) {
2021-10-31 22:22:34 +00:00
$curlist = @ unserialize ( $f -> setting_value );
if ( is_array ( $curlist )) {
2021-11-01 09:33:43 +00:00
foreach ( $curlist as $k => $v ) {
2022-11-30 23:42:12 +00:00
$cur = dcCore :: app () -> con -> openCursor ( dcCore :: app () -> prefix . initEnhancePostContent :: EPC_TABLE_NAME );
dcCore :: app () -> con -> writeLock ( dcCore :: app () -> prefix . initEnhancePostContent :: EPC_TABLE_NAME );
2021-08-23 23:55:52 +00:00
2022-11-30 23:42:12 +00:00
$cur -> epc_id = dcCore :: app () -> con -> select ( 'SELECT MAX(epc_id) FROM ' . dcCore :: app () -> prefix . initEnhancePostContent :: EPC_TABLE_NAME . ' ' ) -> f ( 0 ) + 1 ;
2021-11-01 09:33:43 +00:00
$cur -> blog_id = $f -> blog_id ;
2021-10-31 22:22:34 +00:00
$cur -> epc_filter = strtolower ( $m [ 1 ]);
2021-11-01 09:33:43 +00:00
$cur -> epc_key = $k ;
$cur -> epc_value = $v ;
2021-08-23 23:55:52 +00:00
2021-10-31 22:22:34 +00:00
$cur -> insert ();
2022-11-13 20:30:48 +00:00
dcCore :: app () -> con -> unlock ();
2021-10-31 22:22:34 +00:00
}
2021-08-24 20:05:23 +00:00
}
2022-11-30 23:42:12 +00:00
dcCore :: app () -> con -> execute ( 'DELETE FROM ' . dcCore :: app () -> prefix . dcNamespace :: NS_TABLE_NAME . " WHERE setting_id=' " . $f -> setting_id . " ' AND setting_ns='enhancePostContent' AND blog_id=' " . $f -> blog_id . " ' " );
2021-08-24 20:05:23 +00:00
}
2021-10-31 22:22:34 +00:00
}
2022-11-13 20:30:48 +00:00
# Move old filter name to filter id
2021-10-31 22:22:34 +00:00
} elseif ( $old_version && version_compare ( '2021.10.05' , $old_version , '>=' )) {
2022-11-30 23:42:12 +00:00
$rs = dcCore :: app () -> con -> select ( 'SELECT epc_id, epc_filter FROM ' . dcCore :: app () -> prefix . initEnhancePostContent :: EPC_TABLE_NAME );
2021-11-01 09:33:43 +00:00
while ( $rs -> fetch ()) {
2022-11-30 23:42:12 +00:00
$cur = dcCore :: app () -> con -> openCursor ( dcCore :: app () -> prefix . initEnhancePostContent :: EPC_TABLE_NAME );
2021-10-31 22:22:34 +00:00
$cur -> epc_filter = strtolower ( $rs -> epc_filter );
2021-11-01 09:33:43 +00:00
$cur -> update ( 'WHERE epc_id = ' . $rs -> epc_id . ' ' );
2022-11-13 20:30:48 +00:00
dcCore :: app () -> blog -> triggerBlog ();
2021-08-24 20:05:23 +00:00
}
2021-11-01 09:33:43 +00:00
}