| Server IP : 54.36.91.62 / Your IP : 216.73.217.112 Web Server : Apache System : Linux webm013.cluster127.gra.hosting.ovh.net 5.15.206-ovh-vps-grsec-zfs-classid #1 SMP Fri May 15 02:41:25 UTC 2026 x86_64 User : coopiak ( 151928) PHP Version : 8.3.23 Disable Function : _dyuweyrj4,_dyuweyrj4r,dl MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : OFF | Pkexec : OFF Directory : /home/coopiak/amisdesseniors-fr/administrator/components/com_jlexreview/ |
Upload File : |
<?php
/**
* @package JLex Review
* @version 4.3.5
* @copyright Copyright (c) 2013-2018 JLexArt. All rights reserved
* @license GNU General Public License version 2 or later;
* @author www.jlexart.com
*/
defined('_JEXEC') or die;
use Joomla\CMS\Factory;
// b/c plugin - apply for J5
if(version_compare(JVERSION, "5.0.0-alpha", ">=")){
$classmap = JPATH_ROOT.'/plugins/behaviour/compat/compat.xml';
$bcIsOff = true;
if(file_exists($classmap)){
// check bc plugin
$db = Factory::getDbo();
$query = $db->getQuery(true);
$query->select('COUNT(*)')
->from('#__extensions')
->where([
'type='.$db->quote('plugin'),
'element='.$db->quote('compat'),
'folder='.$db->quote('behaviour'),
'enabled=1'
]);
$enabled = (int) $db->setQuery($query)->loadResult();
$bcIsOff = $enabled==0;
}
if($bcIsOff){
JLoader::registerAlias('JFactory', '\\Joomla\\CMS\\Factory', '6.0');
JLoader::registerAlias('JForm', '\\Joomla\\CMS\\Form\\Form', '6.0');
JLoader::registerAlias('JLog', '\\Joomla\\CMS\\Log\\Log', '6.0');
JLoader::registerAlias('JUri', '\\Joomla\\CMS\\Uri\\Uri', '6.0');
JLoader::registerAlias('JFormField', '\\Joomla\\CMS\\Form\\FormField', '6.0');
JLoader::registerAlias('JFile', '\\Joomla\\Filesystem\\File', '6.0');
}
}
jimport('joomla.filesystem.file');
jimport('joomla.filesystem.folder');
set_time_limit(0);
class Com_JLexReviewInstallerScript
{
protected $version = null;
protected $release = null;
protected $releases = array (
"4.0.1",
"4.0.3",
"4.0.5",
"4.0.7",
"4.0.9",
"4.1.3",
"4.1.7",
"4.1.9",
"4.2.3",
"4.2.4",
"4.2.7",
"4.3.5",
"4.3.7",
"5.0.0",
"5.1.3",
"5.1.7",
"5.2.6",
"5.3.1",
"5.3.5",
"5.7.7",
"5.8.1",
"5.8.7",
"5.9.3",
"6.0.1",
"6.1.7",
"6.1.9",
"6.2.3",
"6.3.1",
"6.3.7"
);
protected function build_params($src, $type)
{
jimport('joomla.form.form');
$db = JFactory::getDbo();
$query = $db->getQuery(true);
$params = array();
if($type=="update")
{
if(version_compare($this->version, '4.0.0', '<'))
{
// backup old params
$query->clear()
->select('params')
->from('#__extensions')
->where(array(
$db->quoteName('type').'='.$db->quote('component'),
$db->quoteName('element').'='.$db->quote('com_jlexreview')
));
$oldConfig = $db->setQuery($query)->loadResult();
if($oldConfig)
{
$oldConfig = json_decode($oldConfig);
if($oldConfig)
{
if (isset($oldConfig->factor_default))
{
$params['factor_default'] = $oldConfig->factor_default;
}
}
}
} else {
if(version_compare($this->version, '4.3.5', '<'))
{
// add row(s) for table
$this->execSqlFile($src."/admin/update/4.3.5.sql");
$query->clear()
->update('#__jlexreview')
->set('rating=10')
->where('rating=9.9');
$db->setQuery($query)->execute();
}
if(version_compare($this->version, '5.0.0', '<'))
{
// add row(s) for table
$this->execSqlFile($src."/admin/update/5.0.0.sql");
}
if(version_compare($this->version, '5.1.7', '<'))
{
// add row(s) for table
$this->execSqlFile($src."/admin/update/5.1.7.sql");
}
if(version_compare($this->version, '5.8.7', '<'))
{
// add row(s) for table
$this->execSqlFile($src."/admin/update/5.8.7.sql");
}
if(version_compare($this->version, '6.0.1', '<'))
{
// add row(s) for table
$this->execSqlFile($src."/admin/update/6.0.1.sql");
}
if(version_compare($this->version, '6.1.7', '<'))
{
// add row(s) for table
$this->execSqlFile($src."/admin/update/6.1.7.sql");
}
return;
}
}
// settings
$path = $src . "/admin/models/forms/config";
$files = array(
"advanced.xml",
"comment.xml",
"general.xml",
"layout.xml",
"notification.xml",
"ranking.xml",
"restriction.xml",
"review.xml",
"section.xml",
"user.xml"
);
foreach ($files as $file)
{
$key = str_replace(".xml", "", $file);
if(!is_file($path."/".$file)) continue;
$form = JForm::getInstance("jr_settings_" . $key, $path."/".$file);
foreach ($form->getFieldsets() as $fieldset)
{
//print
foreach ($form->getFieldset($fieldset->name) as $field)
{
$name = $field->fieldname;
$value = $form->getFieldAttribute($name, "default", null, $field->group);
if (empty($name) || !$value)
{
continue;
}
$params[$name] = $value=="now" ? "": $value;
}
}
}
// user group
$query->clear()
->select("id")
->from ("#__usergroups");
$groups = $db->setQuery ($query)->loadColumn();
$groups_admin = array ();
if (in_array(7, $groups)) $groups_admin[] = 7;
if (in_array(8, $groups)) $groups_admin[] = 8;
/* PERMISSION */
$path = JPATH_ADMINISTRATOR . "/components/com_jlexreview/models/forms/config/permission.xml";
$permission = JForm::getInstance("jr_permission", $path);
// user right
foreach ($permission->getFieldset("post_review") as $field)
{
$name = $field->fieldname;
$params[$name] = $groups;
}
foreach ($permission->getFieldset("post_comment") as $field)
{
$name = $field->fieldname;
$params[$name] = $groups;
}
foreach ($permission->getFieldset("post_other") as $field)
{
$name = $field->fieldname;
$params[$name] = $groups;
}
// admin right
foreach ($permission->getFieldset("administration_review") as $field)
{
$name = $field->fieldname;
$params[$name] = $groups_admin;
if (in_array(2, $groups) && ($name=='u_edit_own_review'||$name=='u_del_own_review'))
{
// register group
$params[$name][] = 2;
}
}
foreach ($permission->getFieldset("administration_comment") as $field)
{
$name = $field->fieldname;
$params[$name] = $groups_admin;
if (in_array(2, $groups) && ($name=='u_edit_own_comment'||$name=='u_del_own_comment'))
{
// register group
$params[$name][] = 2;
}
}
foreach ($permission->getFieldset("administration_other") as $field)
{
$name = $field->fieldname;
$params[$name] = $groups_admin;
}
$params = json_encode($params);
$query->clear()
->update('#__extensions')
->set('params='.$db->quote($params))
->where(array(
$db->quoteName('type').'='.$db->quote('component'),
$db->quoteName('element').'='.$db->quote('com_jlexreview')
));
$db->setQuery($query)->execute();
return true;
}
protected function _langnew($path, $version, $tag="en-GB")
{
$key = array_search($version, $this->releases);
if ($key===false || !isset($this->releases[$key+1]))
{
return;
}
$matches = array();
$version = preg_quote(";v" . $this->releases[$key+1]);
$end = preg_quote(";end");
if (!is_file($path))
{
return;
}
preg_match("/{$version}(.*){$end}/msi", file_get_contents($path), $matches);
if (!isset($matches[1]))
{
$this->_langnew($path, $this->releases[$key+1], $tag);
return;
}
$lines = explode(PHP_EOL, $matches[1]);
$newlines = array();
if (!count($lines))
{
return;
}
foreach ($lines as $line)
{
if (!empty($line))
{
$newlines[] = $line;
}
}
if (!count($newlines))
{
return;
}
$data = PHP_EOL . ";v" . $this->releases[$key+1] . PHP_EOL . implode(PHP_EOL, $newlines);
$path2file = JPATH_ADMINISTRATOR . "/language/{$tag}/{$tag}.com_jlexreview.ini";
@file_put_contents($path2file, $data, FILE_APPEND | LOCK_EX);
}
public function _create_simple_form()
{
$formSql = "INSERT INTO `#__jlexreview_form` (`id`, `name`, `params`)
VALUES
(1, 'Default', '{\"fs_subject_field\":\"1\",\"fs_summary_rating\":\"1\",\"fs_criteria_style\":\"slider\",\"fs_data\":[{\"label\":\"Review Content\",\"require\":\"1\",\"hidden\":\"0\",\"id\":\"1\",\"type\":\"textarea\",\"default\":\"\",\"placeholder\":\"\",\"maxlength\":\"\",\"minlength\":\"\",\"rating\":0}]}');
";
$db = JFactory::getDbo();
$db->setQuery($formSql)->execute();
}
public function getParam($param)
{
$db = JFactory::getDbo();
$query = $db->getQuery(true);
$query->select('manifest_cache')
->from('#__extensions')
->where($db->quoteName('name').'=' . $db->quote('com_jlexreview'));
$manifest_cache = $db->setQuery($query)->loadResult();
$manifest = json_decode($manifest_cache,true);
return @$manifest[$param];
}
protected function execSqlFile($sqlfile)
{
$db = JFactory::getDbo();
$buffer = file_get_contents($sqlfile);
// Graceful exit and rollback if read not successful
if($buffer === false)
{
JLog::add(JText::_('JLIB_INSTALLER_ERROR_SQL_READBUFFER' ), JLog::WARNING, 'jerror');
return false;
}
// Create an array of queries from the sql file
$queries = $this->_parseQuery ( $buffer );
if(count($queries)==0) return 0;
// Process each query in the $queries array (split out of sql file).
foreach($queries as $query)
{
$query = trim($query);
if ($query != '' && $query[0]!='#') {
$db->setQuery($query);
if(!$db->execute())
{
JLog::add(JText::sprintf('JLIB_INSTALLER_ERROR_SQL_ERROR', $db->stderr(true)), JLog::WARNING, 'jerror');
return false;
}
}
}
return count($queries);
}
protected function _parseQuery($sql)
{
$start = 0;
$open = false;
$char = '';
$end = strlen($sql);
$queries = array();
for($i = 0; $i < $end; $i ++) {
$current = substr ( $sql, $i, 1 );
if (($current == '"' || $current == '\'')) {
$n = 2;
while ( substr ( $sql, $i - $n + 1, 1 ) == '\\' && $n < $i ) {
$n ++;
}
if ($n % 2 == 0) {
if ($open) {
if ($current == $char) {
$open = false;
$char = '';
}
} else {
$open = true;
$char = $current;
}
}
}
if (($current == ';' && ! $open) || $i == $end - 1) {
$queries [] = substr ( $sql, $start, ($i - $start + 1) );
$start = $i + 1;
}
}
return $queries;
}
public function preflight($type, $parent)
{
$src = $parent->getParent()->getPath('source');
$this->release = $parent->getManifest()->version;
$this->version = $this->getParam('version');
// language
$path = $src . '/admin/language/en-GB.com_jlexreview.ini';
if($type=="update" && version_compare($this->version, '4.0.0', '>='))
{
$this->_langnew($path, $this->version);
} elseif($type=="install") {
// copy to language folder
$dest = JPATH_ADMINISTRATOR . "/language/en-GB/en-GB.com_jlexreview.ini";
JFile::copy($path, $dest);
}
}
public function postflight($type, $parent)
{
$app = JFactory::getApplication();
$session = JFactory::getSession();
$src = $parent->getParent ()->getPath ( 'source' );
$session->set("jr_versions", null);
if($type!="uninstall") $this->build_params($src, $type);
if ($type=="update" && version_compare($this->version, '4.0.0', '<'))
{
$app->enqueueMessage("...Update success to " . $this->release);
$app->enqueueMessage("Please update your configuration again soon.");
$url = JRoute::_('index.php?option=com_jlexreview&view=update&task=transfer',false);
$app->redirect( $url );
}
if ($type=='install')
{
$this->_create_simple_form();
}
}
/**
* Redirect to index page
*
* @param object $parent
*/
public function install($parent)
{
$app = JFactory::getApplication();
$app->enqueueMessage("Thank You For Using JLEX REVIEW product!");
// $parent is the class calling this method
$url = JUri::base(true).'/index.php?option=com_jlexreview';
$parent->getParent()->setRedirectURL($url);
return;
}
}