2021-09-25 21:14:51 +00:00
< ? php
/**
* @ brief improve , a plugin for Dotclear 2
2021-11-01 21:17:44 +00:00
*
2021-09-25 21:14:51 +00:00
* @ package Dotclear
* @ subpackage Plugin
2021-11-01 21:17:44 +00:00
*
2021-09-25 21:14:51 +00:00
* @ author Jean - Christian Denis and contributors
2021-11-01 21:17:44 +00:00
*
2021-09-25 21:14:51 +00:00
* @ copyright Jean - Christian Denis
* @ copyright GPL - 2.0 https :// www . gnu . org / licenses / gpl - 2.0 . html
*/
2021-11-13 21:57:51 +00:00
declare ( strict_types = 1 );
namespace plugins\improve\module ;
/* improve */
use plugins\improve\action ;
2022-12-03 22:31:36 +00:00
/* clearbricks */
use files ;
use path ;
2021-11-13 21:57:51 +00:00
/**
* Improve action module Dotclear depreciated
*/
class dcdeprecated extends action
2021-09-25 21:14:51 +00:00
{
2022-12-01 10:09:24 +00:00
/** @var array Deprecated functions [filetype [pattern, deprecated, replacement, version, help link]] */
2022-12-03 22:31:36 +00:00
private $deprecated = [ 'php' => [], 'js' => []];
2021-09-25 21:14:51 +00:00
protected function init () : bool
{
$this -> setProperties ([
2021-11-08 23:40:39 +00:00
'id' => 'dcdeprecated' ,
'name' => __ ( 'Dotclear deprecated' ),
'description' => __ ( 'Search for use of deprecated Dotclear functions' ),
'priority' => 520 ,
2021-11-13 21:57:51 +00:00
'types' => [ 'plugin' , 'theme' ],
2021-09-25 21:14:51 +00:00
]);
2022-12-03 22:31:36 +00:00
$this -> loadDeprecatedDefinition ();
2021-09-25 21:14:51 +00:00
return true ;
}
2022-12-03 22:31:36 +00:00
private function loadDeprecatedDefinition ()
{
$path = path :: real ( __DIR__ . '/dcdeprecated' );
if ( ! $path ) {
return [];
}
if ( ! is_dir ( $path ) || ! is_readable ( $path )) {
return [];
}
$files = files :: scandir ( $path );
foreach ( $files as $file ) {
if ( substr ( $file , 0 , 1 ) == '.' ) {
continue ;
}
$tmp = require $path . '/' . $file ;
if ( is_array ( $tmp ) && isset ( $tmp [ 'php' ])) {
$this -> deprecated [ 'php' ] = array_merge ( $this -> deprecated [ 'php' ], $tmp [ 'php' ]);
}
if ( is_array ( $tmp ) && isset ( $tmp [ 'js' ])) {
$this -> deprecated [ 'js' ] = array_merge ( $this -> deprecated [ 'js' ], $tmp [ 'js' ]);
}
}
}
2021-09-25 21:14:51 +00:00
public function isConfigured () : bool
{
return true ;
}
public function readFile ( & $content ) : ? bool
{
2022-12-03 22:31:36 +00:00
if ( ! in_array ( $this -> path_extension , array_keys ( $this -> deprecated ))) {
2021-09-25 21:14:51 +00:00
return null ;
}
2022-12-03 22:31:36 +00:00
foreach ( $this -> deprecated [ $this -> path_extension ] as $d ) {
2021-09-25 21:14:51 +00:00
if ( preg_match ( '/' . $d [ 0 ] . '/i' , $content )) {
2022-12-01 10:09:24 +00:00
$this -> setWarning ( sprintf ( __ ( 'Possible use of deprecated "%s", you should use "%s" instead since Dotclear %s.' ), $d [ 1 ], __ ( $d [ 2 ]), $d [ 3 ]) . ( empty ( $d [ 4 ]) ? '' : ' <a href="' . $d [ '4' ] . '">' . __ ( 'Help' ) . '</a> ' ));
2021-09-25 21:14:51 +00:00
}
}
return true ;
}
2021-11-01 21:17:44 +00:00
}