Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 24 additions & 16 deletions radicalform.php
Original file line number Diff line number Diff line change
Expand Up @@ -666,6 +666,30 @@ public function onAjaxRadicalform()
}



// Вычисляем номер заявки (rfLatestNumber)
$config = Factory::getConfig();
$log_path = str_replace('\\', '/', $config->get('log_path'));
$data = $this->getCSV($log_path . '/plg_system_radicalform.php', "\t");

// Удаляем комментарии и пустые строки
if (count($data) > 0) {
for ($i = 0; $i < 6; $i++) {
if (count($data[$i]) < 4 || $data[$i][0][0] == '#') {
unset($data[$i]);
}
}
}
$latestNumber = 1;
if (count($data) > 0) {
$data = array_reverse($data);
$json = json_decode($data[0][2], true);
if (is_array($json) && isset($json['rfLatestNumber'])) {
$latestNumber = $json['rfLatestNumber'] + 1;
}
}
$input['rfLatestNumber'] = $latestNumber;

if (isset($get['deletefile']) && isset($get['catalog']) && isset($get['uniq']))
{
return $this->deleteUploadedFile($get['catalog'], $get['deletefile'], $get['uniq']);
Expand Down Expand Up @@ -970,22 +994,6 @@ public function onAjaxRadicalform()
}
}

// here we get latest serial number from log file
$latestNumber=1;
if(count($data)>0)
{
$data = array_reverse($data);
$json = json_decode($data[0][2], true);
if (is_array($json))
{
if (isset($json['rfLatestNumber']))
{
$latestNumber = $json['rfLatestNumber'] + 1;
}
}
}


if (isset($get['admin']) && $get['admin'] == 2 )
{
if ($this->app->isClient('administrator'))
Expand Down
15 changes: 7 additions & 8 deletions radicalform.xml
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
<?xml version="1.0"?>
<extension type="plugin" version="3.7" method="upgrade" group="system">
<?xml version="1.0" encoding="UTF-8"?>
<extension type="plugin" version="5.0" method="upgrade" group="system">
<name>PLG_RADICALFORM</name>
<author>Progreccor</author>
<authorEmail>info@hika.su</authorEmail>
<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.5</version>
<version>4.0.0</version>
<creationDate>2024-04-17</creationDate>
<description>PLG_RADICALFORM_DESC</description>
<namespace path="src">RadicalForm\Plugin\System\RadicalForm</namespace>
<scriptfile>script.php</scriptfile>
<files>
<filename plugin="radicalform">radicalform.php</filename>
<filename>buttonradicalform.php</filename>
<filename>storageindicator.php</filename>
<filename>historyradicalform.php</filename>
<folder plugin="radicalform">src</folder>
<folder>services</folder>
<filename>telegramchatids.xml</filename>
<filename>customcode.xml</filename>
<filename>emailalternatives.xml</filename>
Expand All @@ -40,7 +39,7 @@
</updateservers>

<config>
<fields name="params" addfieldpath="/plugins/system/radicalform">
<fields name="params" addfieldprefix="RadicalForm\Plugin\System\RadicalForm\Field">
<fieldset name="basic">

<field
Expand Down
248 changes: 146 additions & 102 deletions script.php
Original file line number Diff line number Diff line change
@@ -1,127 +1,171 @@
<?php
// No direct access
defined( '_JEXEC' ) or die;
/**
*
* @package Joomla.Plugin
* @subpackage System.Radicalform
* @since 3.5+
* @author Progreccor
* @license GNU General Public License version 2 or later; see LICENSE.txt
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/

defined('_JEXEC') or die;

use Joomla\CMS\Factory;
use Joomla\CMS\Language\Text;
use Joomla\CMS\Version;

/**
* Installation script for Radicalform plugin
*/
class plgSystemRadicalformInstallerScript
{
function preflight ($type, $parent)
/**
* Minimum PHP version required
* Joomla 5 requires 8.1, Joomla 6 will likely require 8.2+
*/
protected $minPhp = '8.1.0';

/**
* Minimum Joomla version required
*/
protected $minJoomla = '4.4';

/**
* Preflight method
*
* @param string $type The type of change (install, update or discover_install)
* @param object $parent The class calling this method
*
* @return boolean True on success
*/
public function preflight($type, $parent)
{
if (!(version_compare(PHP_VERSION, '5.6.0') >= 0)) {
JFactory::getApplication()->enqueueMessage(JText::_('PLG_RADICALFORM_WRONG_PHP'), 'error');
// Check PHP version
if (!version_compare(PHP_VERSION, $this->minPhp, '>=')) {
Factory::getApplication()->enqueueMessage(
Text::sprintf('PLG_RADICALFORM_WRONG_PHP', $this->minPhp),
'error'
);
return false;
}

jimport('joomla.version');
// and now we check Joomla version
$jversion = new JVersion();

if (!$jversion->isCompatible('3.7'))
{
JFactory::getApplication()->enqueueMessage(JText::_('PLG_RADICALFORM_WRONG_JOOMLA'), 'error');
// Check Joomla version
if (!(new Version())->isCompatible($this->minJoomla)) {
Factory::getApplication()->enqueueMessage(
Text::sprintf('PLG_RADICALFORM_WRONG_JOOMLA', $this->minJoomla),
'error'
);
return false;
}

return true;
}

function uniqidReal($lenght = 23) {
if (function_exists("random_bytes")) {
$bytes = random_bytes(ceil($lenght / 2));
} elseif (function_exists("openssl_random_pseudo_bytes")) {
$bytes = openssl_random_pseudo_bytes(ceil($lenght / 2));
} else {
throw new Exception("no cryptographically secure random function available");
/**
* Generate a real unique ID
*
* @param integer $length Length of the unique ID
*
* @return string
*/
protected function uniqidReal($length = 23)
{
try {
$bytes = random_bytes((int) ceil($length / 2));
} catch (\Exception $e) {
$bytes = openssl_random_pseudo_bytes((int) ceil($length / 2));
}
return substr(bin2hex($bytes), 0, $lenght);
}

return substr(bin2hex($bytes), 0, $length);
}

function postflight( $type, $parent )
/**
* Postflight method
*
* @param string $type The type of change (install, update or discover_install)
* @param object $parent The class calling this method
*
* @return void
*/
public function postflight($type, $parent)
{
$db = Factory::getDbo();
$query = $db->getQuery(true);

// Enable the plugin automatically
$query->update($db->quoteName('#__extensions'))
->set($db->quoteName('enabled') . ' = 1')
->where($db->quoteName('type') . ' = ' . $db->quote('plugin'))
->where($db->quoteName('element') . ' = ' . $db->quote('radicalform'));

try {
$db->setQuery($query)->execute();
} catch (\Exception $e) {
// Silent fail for enable if something is wrong with DB
}

// Handle parameters
try {
$query = $db->getQuery(true)
->select($db->quoteName('params'))
->from($db->quoteName('#__extensions'))
->where($db->quoteName('type') . ' = ' . $db->quote('plugin'))
->where($db->quoteName('folder') . ' = ' . $db->quote('system'))
->where($db->quoteName('element') . ' = ' . $db->quote('radicalform'));

$db = JFactory::getDbo();
$query = $db->getQuery( true );
$query->update( '#__extensions' )->set( 'enabled=1' )->where( 'type=' . $db->q( 'plugin' ) )->where( 'element=' . $db->q( 'radicalform' ) );
$db->setQuery( $query )->execute();

try
{
// Get the params for the radicalform plugin
$params = $db->setQuery(
$db->getQuery(true)
->select($db->quoteName('params'))
->from($db->quoteName('#__extensions'))
->where($db->quoteName('type') . ' = ' . $db->quote('plugin'))
->where($db->quoteName('folder') . ' = ' . $db->quote('system'))
->where($db->quoteName('element') . ' = ' . $db->quote('radicalform'))
)->loadResult();
}
catch (Exception $e)
{
echo JText::sprintf('JLIB_DATABASE_ERROR_FUNCTION_FAILED', $e->getCode(), $e->getMessage()) . '<br />';

return false;
}

$params = json_decode($params, true);

// set the directory to safe place

if (!isset($params['uploadstorage']))
{
$params['uploadstorage'] = JPATH_ROOT.'/images/radicalform'.$this->uniqidReal();
mkdir($params['uploadstorage']);
}

// change bytes to megabytes from previous version of plugin
if (isset($params['maxfile']) && ($params['maxfile'] > 10000))
{
// here we think that this number is bytes
$params['maxfile'] = (int) ($params['maxfile'] / 1048576);
}

// if we update from previous versions -
if($type == "update")
{
if (!isset($params['attachfiles']))
{
$params['attachfiles'] = 1;
}

}

if (!isset($params['downloadpath']) || (trim($params['downloadpath']) == "") )
{
$params['downloadpath'] = "rfA".$this->uniqidReal(3);
}

$params = json_encode($params);

$query = $db->getQuery(true)
->update($db->quoteName('#__extensions'))
->set($db->quoteName('params') . ' = ' . $db->quote($params))
->where($db->quoteName('type') . ' = ' . $db->quote('plugin'))
->where($db->quoteName('folder') . ' = ' . $db->quote('system'))
->where($db->quoteName('element') . ' = ' . $db->quote('radicalform'));

try
{
$db->setQuery($query)->execute();
}
catch (Exception $e)
{
echo JText::sprintf('JLIB_DATABASE_ERROR_FUNCTION_FAILED', $e->getCode(), $e->getMessage()) . '<br />';

return false;
}


JFactory::getApplication()->enqueueMessage(JText::_('PLG_RADICALFORM_WELCOME_MESSAGE'), 'notice');
$paramsJson = $db->setQuery($query)->loadResult();
$params = json_decode($paramsJson, true) ?: [];
} catch (\Exception $e) {
Factory::getApplication()->enqueueMessage(
Text::sprintf('JLIB_DATABASE_ERROR_FUNCTION_FAILED', $e->getCode(), $e->getMessage()),
'error'
);
return;
}

// Set the directory to safe place if not set
if (empty($params['uploadstorage'])) {
$params['uploadstorage'] = JPATH_ROOT . '/images/radicalform' . $this->uniqidReal();
if (!is_dir($params['uploadstorage'])) {
mkdir($params['uploadstorage'], 0755, true);
}
}

// Change bytes to megabytes from previous version of plugin if needed
if (isset($params['maxfile']) && $params['maxfile'] > 10000) {
$params['maxfile'] = (int) ($params['maxfile'] / 1048576);
}

// Update from previous versions
if ($type === 'update') {
if (!isset($params['attachfiles'])) {
$params['attachfiles'] = 1;
}
}

if (empty($params['downloadpath']) || trim($params['downloadpath']) === '') {
$params['downloadpath'] = 'rfA' . $this->uniqidReal(3);
}

$paramsEncoded = json_encode($params);

$query = $db->getQuery(true)
->update($db->quoteName('#__extensions'))
->set($db->quoteName('params') . ' = ' . $db->quote($paramsEncoded))
->where($db->quoteName('type') . ' = ' . $db->quote('plugin'))
->where($db->quoteName('folder') . ' = ' . $db->quote('system'))
->where($db->quoteName('element') . ' = ' . $db->quote('radicalform'));

try {
$db->setQuery($query)->execute();
} catch (\Exception $e) {
Factory::getApplication()->enqueueMessage(
Text::sprintf('JLIB_DATABASE_ERROR_FUNCTION_FAILED', $e->getCode(), $e->getMessage()),
'error'
);
return;
}

Factory::getApplication()->enqueueMessage(Text::_('PLG_RADICALFORM_WELCOME_MESSAGE'), 'notice');
}
}

Loading