improve/inc/module/dcdeprecated.php

90 lines
2.5 KiB
PHP
Raw Normal View History

<?php
/**
* @brief improve, a plugin for Dotclear 2
2021-11-01 21:17:44 +00:00
*
* @package Dotclear
* @subpackage Plugin
2021-11-01 21:17:44 +00:00
*
* @author Jean-Christian Denis and contributors
2021-11-01 21:17:44 +00:00
*
* @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/
declare(strict_types=1);
2022-12-21 14:41:27 +00:00
namespace Dotclear\Plugin\improve\Module;
/* improve */
2022-12-21 14:41:27 +00:00
use Dotclear\Plugin\improve\Action;
2022-12-03 22:31:36 +00:00
/* clearbricks */
use files;
use path;
/**
* Improve action module Dotclear depreciated
*/
2022-12-21 14:41:27 +00:00
class dcdeprecated extends Action
{
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' => []];
protected function init(): bool
{
$this->setProperties([
'id' => 'dcdeprecated',
'name' => __('Dotclear deprecated'),
'description' => __('Search for use of deprecated Dotclear functions'),
'priority' => 520,
'types' => ['plugin', 'theme'],
]);
2022-12-03 22:31:36 +00:00
$this->loadDeprecatedDefinition();
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']);
}
}
}
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))) {
return null;
}
2022-12-03 22:31:36 +00:00
foreach ($this->deprecated[$this->path_extension] as $d) {
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> '));
}
}
return true;
}
2021-11-01 21:17:44 +00:00
}