AnonSec Shell
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/models/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ HOME ]     

Current File : /home/coopiak/amisdesseniors-fr/administrator/components/com_jlexreview/models//import.php
<?php
/**
 * @package		JLex Review
 * @version		4.2.3
 * @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;

jimport('joomla.filesystem.file');

require_once dirname(__FILE__) . '/../libs/import.php';
require_once dirname(__FILE__) . '/../libs/others/csv/vendor/autoload.php';

class JLexReviewModelImport extends JModelLegacy
{
	public function upload()
	{
		$app 		= JFactory::getApplication();
		$entry_id 	= $app->getInput()->getInt("entry_id", 0);
		$session 	= JFactory::getSession();

		if($entry_id<1)
		{
			$this->setError("Entry item not found.");
			return false;
		}

		// upload csv file
		$file = array_key_exists('file', $_FILES) ? $_FILES['file'] : null;
		$time = time();

		if(empty($file) || $file['size']==0)
		{
			$this->setError("You must select file to import.");
			return false;
		}

		// safe filename
		$filename 	= JFile::makeSafe($file['name']);
		$extension  = strtolower(JFile::getExt($filename) );
		$dest 		= JPATH_ROOT . "/tmp/import_" . $time . '.tmp';

		if($extension!='csv')
		{
			$this->setError("Only support *.csv file.");
			return false;
		}

		if(!JFile::upload($file['tmp_name'], $dest))
		{
			// throw an error message
			return false;
		}

		$session->set('import_' . $time, $entry_id);

		return $time;
	}

	public function getParse()
	{
		$session = JFactory::getSession();
		$id = JFactory::getApplication()->getInput()->getInt('id', 0);

		$entry_id = $session->get('import_' . $id, null);
		$file   = JPATH_ROOT."/tmp/import_" . $id . '.tmp';

		if($entry_id<1 || !file_exists($file))
		{
			throw new Exception("File CSV not found or Session expired.", 404);
		}

		// check form of entry item
		$query = $this->_db->getQuery(true);
		$query->select("f.id,f.params")
			  ->from("#__jlexreview_entry entry")
			  ->innerJoin("#__jlexreview_form f ON f.id=entry.section_file")
			  ->where("entry.id=" . $entry_id);

		$form = $this->_db->setQuery($query)->loadObject();
		if(!$form)
		{
			$this->setError("Section form not found.");
			return false;
		}

		$csv = new \ParseCsv\Csv();
		$csv->heading = false;
		$csv->enclose_all = true;
		$csv->auto($file);

		if(!count($csv->data))
		{
			$this->setError("Don't find any row to import. Try again with another file.");
			return false;
		}

		$result = new stdClass();
		$result->form = json_decode($form->params);
		$result->form_id = $form->id;
		$result->csv  = $csv->data;

		return $result;
	}

	public function getForm()
	{
		$path 	= dirname(__FILE__) . "/forms/import.xml";
		$form 	= JForm::getInstance("jreview_import", $path);

		$form->addFieldPath(dirname (__FILE__) . "/fields");

		return $form;
	}

	public function import()
	{
		$app 	 = JFactory::getApplication();
		$session = JFactory::getSession();
		$id 	 = $app->getInput()->getInt("id", 0);
		$entry_id = $session->get('import_' . $id, null);
		
		$parse 	 = $this->getParse();
		if(!$parse) return false;

		$file 	= JPATH_ROOT . "/tmp/import_" . $id . '.tmp';
		$now 	= JFactory::getDate()->toSql();
		$import_success = 0;
		$import_failure = 0;

		$csv = new \ParseCsv\Csv();
		$csv->heading = !$app->getInput()->getBool("heading",1)==true;
		$csv->enclose_all = true;
		$csv->auto($file);

		$data = $app->getInput()->get("jform", null, "array");

		if(!$data || !count($data))
		{
			$this->setError("No row found.");
			return false;
		}

		// assign entry id
		$data["entry_id"]  = $entry_id;
		$data["user_type"] = 0; // alway is guest
		$data["published"] = $app->getInput()->getInt("auto_published",0);
		
		// create log file
		$log = JPATH_ROOT . "/tmp/import_" . $id . ".log";
		$log_content = "";
		JFile::write($log, $log_content);

		$count_file = JPATH_ROOT . "/tmp/import_" . $id . ".txt";
		$count_content = "0,0";
		JFile::write($count_file, $count_content);
		

		$ratingModel = $this->getInstance('Rating', 'JLexReviewModel');

		foreach($csv->data as $key => $item)
		{
			$data_clone = $data;

			foreach($data_clone as $k=>$value)
			{
				if(is_array($value))
				{
					foreach($value as $k2=>$v2)
					{
						if(is_array($v2))
						{
							// checkbox
							$checkbox = array();
							if(count($v2))
							{
								foreach ($v2 as $k3=>$v3)
								{
									$select = false;
									if(preg_match("/^\#([0-9]+)$/", $v3, $matches))
									{
										$select = $item[$matches[1]];
									} else {
										$select = $v3==1?true:false;
									}

									if($select) $checkbox[]=$k3;
								}
							}

							$data_clone[$k][$k2] = $checkbox;
						} else {
							if(preg_match("/^\#([0-9]+)$/", $v2, $matches))
							{
								$data_clone[$k][$k2] = $item[$matches[1]];
							}
						}
					}
				} else {
					if(preg_match("/^\#([0-9]+)$/", $value, $matches))
					{
						$data_clone[$k] = $item[$matches[1]];
					}
				}
			}
			
			$ratingModel->_errors = array();
			$return = $ratingModel->save($data_clone);
			
			if($return>0)
			{
				$import_success+=1;
				file_put_contents($log, $item[0] . ": One row imported. " . PHP_EOL . "----" . PHP_EOL , FILE_APPEND | LOCK_EX);
			} else {
				$errors = $ratingModel->getErrors();
				$errors_string = array();
				foreach ($errors as $error)
				{
					if ($error instanceof Exception)
					{
						$errors_string[] = $error->getMessage();
					} else {
						$errors_string[] = $error;
					}
				}

				file_put_contents($log, $item[0] . ": " . implode(", ", $errors_string) . PHP_EOL . "----" . PHP_EOL , FILE_APPEND | LOCK_EX);
				$import_failure+=1;
			}

			// update
			$count_content = $import_success . "," . $import_failure;
			JFile::write($count_file, $count_content);

			sleep(1);
		}

		return $import_success;
	}



	/** IMPORTING FROM 3RD-PARTY **/
	public function getApps()
    {
    	$path 	 = dirname (__FILE__)."/import";
    	$plugins = JFolder::files($path, ".php");

    	if(!count($plugins)) return null;

    	$list = array();

    	foreach($plugins as $k=>$plg)
    	{
    		$plg_path 	 = $path . "/" . $plg;
    		$plg_part 	 = explode (".", $plg);
    		$nameOfClass = "JLexReviewImport" . $plg_part[0];

    		require_once $plg_path;

    		$class = new $nameOfClass();
    		$list [$k] = array(
    				"name" 	=> $class->name,
    				"count" => $class->getCountReview (),
    				"key" 	=> $plg_part [0]
    			);
    	}

    	// get section files
    	$forms = array();
    	$query = $this->_db->getQuery(true);
    	$query->select('*')
    		  ->from('#__jlexreview_form')
    		  ->order('name ASC');

    	$rows  = $this->_db->setQuery($query)
    					->loadObjectList();

    	foreach($rows as $row)
    	{
    		$fields = array();
    		$params = json_decode($row->params);

    		foreach($params->fs_data as $field)
    		{
    			if($field->type!='textarea') continue;
    			$fields[] = array(
    					'name' 	=> $field->label,
    					'value' => $field->id
    				);
    		}

    		$forms[$row->id] = array(
    				'id'		=> $row->id,
    				'name' 		=> $row->name,
    				'fields' 	=> $fields
    			);
    	}

    	return array(
    			'apps' 	=> $list,
    			'forms' => $forms
    		);
    }

    public function migrator()
    {
        $app = JFactory::getApplication();
        $plg = $app->getInput()->getCmd("migrator", "");

        $response = array();

        if(!preg_match("/^[A-z0-9\_]+$/", $plg))
        {
            $this->setError("Migrator not found.");
            return false;
        }

        $plg_path = dirname(__FILE__) . "/import/" . $plg . ".php";
        if(!is_file($plg_path))
        {
            $this->setError("Migrator not found.");
            return false;
        }

        require_once $plg_path;
        $nameOfClass = "JLexReviewImport".$plg;

        $class = new $nameOfClass();
        $getTotal = $app->getInput()->getBool("gtotal", false);
        
        if($getTotal)
        {
            $response["total"] = $class->getCountReview();
            if(!is_numeric($response["total"]) || !$response["total"])
            {
                $response["total"] = 0;
            }

            if($response["total"]==0)
            {
                return $response;
            }
        }

        $offset = $app->getInput()->getInt("offset", 0);
        $section_file = $app->getInput()->getInt("section_file", 0);
        $review_field = $app->getInput()->getInt("review_field", "");

        $class->setParams('section_file', $section_file);
        $class->setParams('review_field', $review_field);

        if(!$class->import($offset))
        {
            $response["success"] = -1;
        } else {
            $response["success"] = $class->total;
        }

        return $response;
    }
}

Anon7 - 2022
AnonSec Team