Skip to content

Commit

Permalink
Joomla 5 support: JPlugin -> CMSPlugin, Jlog -> Log (#76)
Browse files Browse the repository at this point in the history
  • Loading branch information
sergeytolkachyov authored May 1, 2024
1 parent b84d68f commit da81d14
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
22 changes: 12 additions & 10 deletions radicalform.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,16 @@
*/

use Joomla\CMS\Factory;
use Joomla\CMS\Log\Log;
use Joomla\CMS\MVC\Model\BaseDatabaseModel;
use Joomla\CMS\Plugin\CMSPlugin;
use Joomla\CMS\Plugin\PluginHelper;
use Joomla\CMS\Table\Table;
use Joomla\CMS\Uri\Uri;
use Joomla\String\StringHelper;
use Joomla\CMS\HTML\HTMLHelper;

class plgSystemRadicalform extends JPlugin
class plgSystemRadicalform extends CMSPlugin
{
private $logPath;

Expand All @@ -42,15 +44,15 @@ public function __construct(& $subject, $config)

$this->logPath = str_replace('\\', '/', Factory::getConfig()->get('log_path')).'/plg_system_radicalform.php';

JLog::addLogger(
Log::addLogger(
array(
// Sets file name
'text_file' => 'plg_system_radicalform.php',
// Sets the format of each line
'text_entry_format' => "{DATETIME}\t{CLIENTIP}\t{MESSAGE}\t{PRIORITY}"
),
// Sets all but DEBUG log level messages to be sent to the file
JLog::ALL & ~JLog::DEBUG,
Log::ALL & ~Log::DEBUG,
array('plg_system_radicalform')
);

Expand Down Expand Up @@ -997,7 +999,7 @@ public function onAjaxRadicalform()
{
unlink($this->logPath);
$entry= ['rfLatestNumber' => $latestNumber, 'message' => JText::_('PLG_RADICALFORM_CLEAR_HISTORY') ];
JLog::add(json_encode($entry), JLog::NOTICE, 'plg_system_radicalform');
Log::add(json_encode($entry), Log::NOTICE, 'plg_system_radicalform');
}
return "ok";
} else
Expand All @@ -1013,7 +1015,7 @@ public function onAjaxRadicalform()
{
// сбрасываем нумерацию
$entry = ['rfLatestNumber' => 0, 'message' => JText::_('PLG_RADICALFORM_RESET_NUMBER')];
JLog::add(json_encode($entry), JLog::NOTICE, 'plg_system_radicalform');
Log::add(json_encode($entry), Log::NOTICE, 'plg_system_radicalform');

return "ok";
} else
Expand Down Expand Up @@ -1046,7 +1048,7 @@ public function onAjaxRadicalform()
if (Factory::getSession()->isNew() || !Factory::getSession()->checkToken())
{
$input = ['rfLatestNumber' => $latestNumber, 'message' => JText::_('PLG_RADICALFORM_INVALID_TOKEN') ];
JLog::add(json_encode($input), JLog::WARNING, 'plg_system_radicalform');
Log::add(json_encode($input), Log::WARNING, 'plg_system_radicalform');
return JText::_('PLG_RADICALFORM_INVALID_TOKEN');
};

Expand Down Expand Up @@ -1167,15 +1169,15 @@ public function onAjaxRadicalform()
{
unlink($this->logPath);
$entry= ['rfLatestNumber' => $latestNumber, 'message' => JText::_('PLG_RADICALFORM_CLEAR_HISTORY_BY_MAX_LOG') ];
JLog::add(json_encode($entry), JLog::NOTICE, 'plg_system_radicalform');
Log::add(json_encode($entry), Log::NOTICE, 'plg_system_radicalform');
$latestNumber++;
}
}

$input['rfLatestNumber'] = $latestNumber;
$input = array_filter($input, function($value) { return $value !== ''; }); // delete empty fields in input array

JLog::add(json_encode($input), JLog::NOTICE, 'plg_system_radicalform');
Log::add(json_encode($input), Log::NOTICE, 'plg_system_radicalform');

if (isset($input["rfTarget"]) && (!empty($input["rfTarget"])))
{
Expand Down Expand Up @@ -1383,15 +1385,15 @@ public function onAjaxRadicalform()
{
$input=[];
$input["message"]=JText::_('PLG_RADICALFORM_MAIL_DISABLED');
JLog::add(json_encode($input), JLog::WARNING, 'plg_system_radicalform');
Log::add(json_encode($input), Log::WARNING, 'plg_system_radicalform');
return JText::_('PLG_RADICALFORM_MAIL_DISABLED');
}

if ($send !== true)
{
$input=[];
$input["message"]=$send->getMessage();
JLog::add(json_encode($input), JLog::WARNING, 'plg_system_radicalform');
Log::add(json_encode($input), Log::WARNING, 'plg_system_radicalform');
return $send->getMessage();
}
else
Expand Down
4 changes: 2 additions & 2 deletions radicalform.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
<authorUrl>https://hika.su</authorUrl>
<copyright>Copyright (C) 2023 Progreccor. All rights reserved.</copyright>
<license>GNU General Public License version 2 or later;</license>
<version>3.1.4</version>
<creationDate>2023-10-09</creationDate>
<version>3.1.5</version>
<creationDate>2024-04-17</creationDate>
<description>PLG_RADICALFORM_DESC</description>
<scriptfile>script.php</scriptfile>
<files>
Expand Down

0 comments on commit da81d14

Please sign in to comment.