Your IP : 216.73.216.85


Current Path : /home/smartconb/www/armencom33/administrator/components/com_eyesite/models/
Upload File :
Current File : /home/smartconb/www/armencom33/administrator/components/com_eyesite/models/config.php

<?php
/********************************************************************
Product		: Eyesite
Date		: 22 January 2024
Copyright	: Les Arbres Design 2009-2024
Contact		: https://www.lesarbresdesign.info
Licence		: GNU General Public License
*********************************************************************/
defined('_JEXEC') or die('Restricted access');

use Joomla\CMS\Factory;
use Joomla\CMS\Language\Text;
use Joomla\CMS\Component\ComponentHelper;

class EyesiteModelConfig extends LAE_model
{
var $data;

//-------------------------------------------------------------------------------
// Get the component parameters
// Returns a stdClass Object containing all our parameters
//
function getData()
{
	$component_params = ComponentHelper::getParams(LAE_COMPONENT);
	$this->data = $component_params->toObject();

// set defaults for all our parameters

	if (!isset($this->data->emailto))      $this->data->emailto      = '';
	if (!isset($this->data->extensions))   $this->data->extensions   = 'php,js,htm,html,css,ini,sql,jpg,htaccess,xml';
	if (!isset($this->data->incdirs))      $this->data->incdirs      = '%SITE_ROOT%,S';
   	if (!isset($this->data->excdirs))      $this->data->excdirs      = 
	   "%SITE_ROOT%/tmp,\n%SITE_ROOT%/administrator/logs,\n%SITE_ROOT%/administrator/cache,\n%SITE_ROOT%/cache";
	if (!isset($this->data->excfiles))     $this->data->excfiles     = '';
	if (!isset($this->data->case_sensitive)) $this->data->case_sensitive = 0;
	if (!isset($this->data->days_to_keep))   $this->data->days_to_keep = 365;
	if (!isset($this->data->email_max_size)) $this->data->email_max_size = 20000;
	if (!isset($this->data->scan_language)) $this->data->scan_language = '0';
	return $this->data;
}

//-------------------------------------------------------------------------------
// Get the post data
//
function getPostData()
{
	$jinput = Factory::getApplication()->input;
	$this->data->emailto      = $jinput->get('emailto', '', 'STRING');
	$this->data->extensions   = $jinput->get('extensions', '', 'STRING');
	$this->data->incdirs      = $jinput->get('incdirs', '', 'STRING');
	$this->data->excdirs      = $jinput->get('excdirs', '', 'STRING');
	$this->data->excfiles     = $jinput->get('excfiles', '', 'STRING');
	$this->data->case_sensitive = $jinput->get('case_sensitive', 0, 'INT');
	$this->data->days_to_keep   = $jinput->get('days_to_keep', '', 'STRING');
	$this->data->email_max_size = $jinput->get('email_max_size', '', 'STRING');
	$this->data->scan_language  = $jinput->get('scan_language', '', 'STRING');
	return $this->data;
}

// ------------------------------------------------------------------------------------
// Validate the configuration data
// Return TRUE on success or FALSE if not
//
function check()
{
	$errors = array();
    $warnings = array();

// check that at least one include directory is specified
// each directory must be followed by S (recurse subdirectories) or N (do not recurse)

	$incdirs = str_replace('%SITE_ROOT%', JPATH_ROOT, $this->data->incdirs);		// resolve %SITE_ROOT%
	$incdirs = LAE_helper::expand_cs_list($incdirs);								// get array of included directories
	$numdirs = count($incdirs);
	if (($numdirs < 2) || (($numdirs % 2) != 0))	// must be in pairs
		$errors[] = Text::_('COM_EYESITE_DIR_INC_ERROR1');
	$new_incdirs = array();                                             // in case there aren't any
	if (empty($errors))
		{
		$new_excdirs = array();                                             // in case there aren't any
		for ($i = 0; $i < $numdirs; $i = $i+2)
			{
			$path = $incdirs[$i];
			$flag = $incdirs[$i+1];
			$path = rtrim($path, '\/');
			$new_incdirs[] = $path.','.$flag;				// we will re-make the incdirs parameter
			if (!file_exists($path))
				{
				$errors[] = Text::_('COM_EYESITE_DIR_INC_ERROR2').' '.$incdirs[$i];
				continue;
				}
			if (!is_readable($path))
				$errors[] = Text::_('COM_EYESITE_DIR_INC_ERROR3').' '.$incdirs[$i];
			if (($flag != 'S') && ($flag != 'N'))
				$errors[] = Text::_('COM_EYESITE_DIR_INC_ERROR1');
			}
		$this->data->incdirs = implode(",\n",$new_incdirs);		// re-make the incdirs parameter
		}
        
// check the exclude directories

	$excdirs = str_replace('%SITE_ROOT%', JPATH_ROOT, $this->data->excdirs);		// resolve %SITE_ROOT%
	$excdirs = LAE_helper::expand_cs_list($excdirs);									// get array of excluded directories
	$new_excdirs = array();                                             // in case there aren't any
    foreach ($excdirs as $excdir)
		{
		$excdir = rtrim($excdir, '\/');
		$new_excdirs[] = $excdir;										// we will re-make the excdirs parameter
        if (!file_exists($excdir))
            {
            $warnings[] = Text::_('COM_EYESITE_DIR_EXC_ERROR').' '.$excdir;
            continue;
            }
		}
	$this->data->excdirs = implode(",\n",$new_excdirs);					// re-make the excdirs parameter

// check the email address - it can be a list of email addresses, or blank (in which case no emails are sent)

	if (!empty($this->data->emailto))
		{
		$ret = self::validate_email_list($this->data->emailto);
		if ($ret != '')
			$errors[] = Text::_('COM_EYESITE_INVALID').': '.Text::_('COM_EYESITE_EMAIL_ADDRESS').' '.$ret;	      
		}

// days to keep must be a positive integer

	if (!LAE_helper::is_posint($this->data->days_to_keep))
		$errors[] = Text::_('COM_EYESITE_INVALID').': '.Text::_('COM_EYESITE_DAYS_TO_KEEP');
	
// email_max_size must be a positive integer

	if (!LAE_helper::is_posint($this->data->email_max_size))
		$errors[] = Text::_('COM_EYESITE_INVALID').': '.Text::_('COM_EYESITE_EMAIL_MAX_SIZE');

// show warnings and errors

	if (!empty($warnings))
		$this->app->enqueueMessage(implode('<br>',$warnings), 'notice');
	if (empty($errors))
    	return true;
	$this->app->enqueueMessage(implode('<br>',$errors), 'error');
	return false;
}

//---------------------------------------------------------------
// Save component parameters
// Returns TRUE on success or FALSE if there is an error
//
function store()
{
	$this->getData();							// get the currently saved parameters
	$post_data = $this->getPostData();			// overwrite with post data

// save the component parameters

	$this->data->incdirs = str_replace(JPATH_ROOT, '%SITE_ROOT%', $this->data->incdirs);
	$this->data->excdirs = str_replace(JPATH_ROOT, '%SITE_ROOT%', $this->data->excdirs);
	$this->data->excfiles = str_replace(JPATH_ROOT, '%SITE_ROOT%', $this->data->excfiles);
	$query = "UPDATE `#__extensions` SET `params` = ".$this->_db->Quote(json_encode($this->data)).
			" WHERE `type` = 'component' AND `element` = 'com_eyesite'";
	$result = $this->ladb_execute($query);
	if ($result === false)
		{
		$this->app->enqueueMessage($this->ladb_error_text, 'error');
		return false;
		}
        
// clear the cache.

	$this->cleanCache('_system', 0);
	$this->cleanCache('_system', 1);        
	return true;
}

//-------------------------------------------------------------------------------
// Validate multiple email addresses
// if all are valid, returns an empty string
// if any are invalid, returns the first invalid one
// NOTE: $email_list is altered so that each email address only occurs once 
// 
static function validate_email_list(&$email_list, $allow_blank=true)
{
	$email_list = str_replace(' ', '', $email_list);			// remove spaces
	trim($email_list,',');										// trim off any spare commas
	if ($email_list == '')
		{
		if ($allow_blank)
			return '';
		return '( )';
		}
	$email_list = strtolower($email_list);					// make all lower case for array_unique() call
	$email_addresses = explode(',', $email_list);			// make it an array
	$email_addresses = array_unique($email_addresses);		// remove any duplicates
	$email_list = implode(',', $email_addresses);			// recreate the original email list to return
	foreach ($email_addresses as $address)
		if (filter_var($address, FILTER_VALIDATE_EMAIL) === false)
			return '('.$address.')';			
	return '';
}

//-------------------------------------------------------------------------------
// Find the difference between an old and a new config
//
function difference($old_config)
{
	$diff_text = '';
	if ($old_config->emailto != $this->data->emailto)
		$diff_text .= Text::_('COM_EYESITE_EMAIL_ADDRESS').': '.$old_config->emailto.' -> '.$this->data->emailto.'<br>';
	if ($old_config->extensions != $this->data->extensions)
		$diff_text .= Text::_('COM_EYESITE_FILE_EXT').': '.$old_config->extensions.' -> '.$this->data->extensions.'<br>';
	if ($old_config->incdirs != $this->data->incdirs)
		$diff_text .= Text::_('COM_EYESITE_DIR_INC').': '.$old_config->incdirs.' -> '.$this->data->incdirs.'<br>';
	if ($old_config->excdirs != $this->data->excdirs)
		$diff_text .= Text::_('COM_EYESITE_DIR_EXC').': '.$old_config->excdirs.' -> '.$this->data->excdirs.'<br>';
	if ($old_config->excfiles != $this->data->excfiles)
		$diff_text .= Text::_('COM_EYESITE_FILE_EXC').': '.$old_config->excfiles.' -> '.$this->data->excfiles.'<br>';
	if ($old_config->case_sensitive != $this->data->case_sensitive)
		$diff_text .= Text::_('COM_EYESITE_CASE_SENSITIVE').': '.$old_config->case_sensitive.' -> '.$this->data->case_sensitive.'<br>';
	if ($old_config->days_to_keep != $this->data->days_to_keep)
		$diff_text .= Text::_('COM_EYESITE_DAYS_TO_KEEP').': '.$old_config->days_to_keep.' -> '.$this->data->days_to_keep.'<br>';
	if ($old_config->email_max_size != $this->data->email_max_size)
		$diff_text .= Text::_('COM_EYESITE_EMAIL_MAX_SIZE').': '.$old_config->email_max_size.' -> '.$this->data->email_max_size.'<br>';
	if ($old_config->scan_language != $this->data->scan_language)
		$diff_text .= Text::_('JFIELD_LANGUAGE_LABEL').': '.$old_config->scan_language.' -> '.$this->data->scan_language.'<br>';
	return $diff_text;
}

//-------------------------------------------------------------------------------
// Get the plugin TID if it has been stored on the update_sites record
// Return false if there is no update_sites record for the plugin
//
function get_plugin_tid()
{
    $component = ComponentHelper::getComponent('com_installer');
    $params = $component->params;
    $cache_timeout = $params->get('cachetimeout', 6, 'int');
    if ($cache_timeout == 0)
        $this->ladb_execute("UPDATE `#__update_sites` SET `enabled` = 0 WHERE `name` LIKE '%Eyesite%'");		
    $query = "SELECT count(*) FROM `#__update_sites` WHERE `type` = 'extension' AND `name` = 'Eyesite Plugin'";
    $result = $this->ladb_loadResult($query);
	if ($result == 0)
		return false;	// not installed
    $query = "SELECT `extra_query` FROM `#__update_sites` WHERE `type` = 'extension' AND `name` = 'Eyesite Plugin'";
    $result = $this->ladb_loadResult($query);

    if (strlen($result) == 36)
        return substr($result,4);
    else
        return true;	// installed but no TID
}

//-------------------------------------------------------------------------------
// save the extra_query on the update site record
//
function save_plugin_tid($purchase_id)
{
    $extra_query = 'tid='.$purchase_id;
    $query = "UPDATE `#__update_sites` SET `extra_query` = ".$this->_db->Quote($extra_query).
        " WHERE `type` = 'extension' AND `name` = 'Eyesite Plugin'";
	$result = $this->ladb_execute($query);
	if ($result === false)
		{
		$this->app->enqueueMessage($this->ladb_error_text, 'error');
		return false;
		}
	return true;
}

}