Your IP : 216.73.216.85


Current Path : /home/smartconb/www/armencom33/administrator/components/com_eyesite/helpers/
Upload File :
Current File : /home/smartconb/www/armencom33/administrator/components/com_eyesite/helpers/eyesite_helper.php

<?php
/********************************************************************
Product		: Eyesite
Date		: 6 May 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\Language\LanguageHelper;
use Joomla\CMS\Language\Multilanguage;
use Joomla\CMS\Uri\Uri;
use Joomla\CMS\Component\ComponentHelper;
use Joomla\CMS\HTML\Helpers\Sidebar;

define ("LAE_COMPONENT",      "com_eyesite");
define ("LAE_COMPONENT_NAME", "Eyesite");
define ("LAE_ADMIN_ASSETS_URL", Uri::root(true).'/administrator/components/com_eyesite/assets/');
if (substr(JVERSION,0,1) == '3')
	{
	define ("LAE_FORM_FIELD_PATH",JPATH_ADMINISTRATOR.'/components/com_eyesite/fields_j3'); 
	define ("LAE_FORMS_PATH", JPATH_ADMINISTRATOR.'/components/com_eyesite/forms_j3');
	}
else
	{
	define ("LAE_FORM_FIELD_PATH",JPATH_ADMINISTRATOR.'/components/com_eyesite/fields'); 
	define ("LAE_FORMS_PATH", JPATH_ADMINISTRATOR.'/components/com_eyesite/forms_j4');
	}

define ("LAE_STATE_OK", 0);
define ("LAE_STATE_RUNNING", 1); 
define ("LAE_STATE_NEW", 2);
define ("LAE_STATE_CHANGED", 3);
define ("LAE_STATE_DELETED", 4);

define ("LAE_SQL_DATE_FORMAT", "Y-m-d H:i:s");	// PHP date() string to generate date time in SQL format

define ("LAE_HISTORY_SCAN_STARTED", 1);
define ("LAE_HISTORY_SCAN_NO_CHANGES", 2);
define ("LAE_HISTORY_SCAN_CHANGES", 3);
define ("LAE_HISTORY_SCAN_ERROR", 4);
define ("LAE_HISTORY_ACCEPT", 5);               // no new logs are created with this status
define ("LAE_HISTORY_REJECT", 6);               // no new logs are created with this status
define ("LAE_HISTORY_ACCEPT_ALL", 7);           // no new logs are created with this status
define ("LAE_HISTORY_REJECT_ALL", 8);           // no new logs are created with this status
define ("LAE_HISTORY_SCAN_NOT_STARTED", 9);		// no new logs are created with this status
define ("LAE_HISTORY_EMAIL_FAILED", 10);
define ("LAE_HISTORY_SCAN_EXCEPTION", 11);
define ("LAE_HISTORY_CONFIG_CHANGE", 12);
define ("LAE_HISTORY_EMAIL_OK", 13);
define ("LAE_HISTORY_INFO", 14);
define ("LAE_HISTORY_UPDATE_JOOMLA", 15);
define ("LAE_HISTORY_UPDATE_EXTENSION", 16);
define ("LAE_HISTORY_NEW_EXTENSION", 17);
define ("LAE_MAX_LOCK_SECONDS", 900);
define ("LAE_MAX_VARCHAR_LENGTH", 255);

if (substr(JVERSION,0,1) == '3')
	define("LAE_BS_DATA_CONTENT", "data-content");
else
	define("LAE_BS_DATA_CONTENT", "data-bs-content");

if (class_exists("LAE_helper"))
	return;

class LAE_helper
{

//-------------------------------------------------------------------------------
// Get the text for a state
//
static function state_text($state)
{
	switch ($state)
		{
		case LAE_STATE_OK:      return Text::_('COM_EYESITE_STATE_OK');
		case LAE_STATE_RUNNING: return Text::_('COM_EYESITE_STATE_RUNNING');
		case LAE_STATE_NEW:     return Text::_('COM_EYESITE_STATE_NEW');
		case LAE_STATE_CHANGED: return Text::_('COM_EYESITE_STATE_CHANGED');
		case LAE_STATE_DELETED: return Text::_('COM_EYESITE_STATE_DELETED');
		}
	return 'bad state';
}

//-------------------------------------------------------------------------------
// Send an email
// we don't call $mail->setSender() - the Joomla default is mailfrom and fromname in Joomla Global Config
//
static function send_email($config_data, $subject, $body_text)
{
	if (empty($subject))
		return "Cannot send email, empty subject";
	if (empty($body_text))
		return "Cannot send email, empty body text";
	$app = Factory::getApplication();
	$mailonline = $app->get('mailonline');	
	if ($mailonline == 0)
		{
		LAE_trace::trace("Emailing is disabled in Joomla Global Config");
		return "Emailing is disabled in Joomla Global Config";
		}
    try
		{
		$mailer = Factory::getMailer();
		$mailer->IsHTML(true);
		$mailer->setSubject($subject);
		$mailer->setBody($body_text);
		$addresses = explode(',', $config_data->emailto);
		foreach ($addresses as $address)
			$mailer->addRecipient($address);
		$ret = $mailer->Send();
		}
	catch (Exception $e)
		{
	    $e_msg = $e->getMessage();
	    $e_code = $e->getCode();
        LAE_trace::trace("Joomla Mail exception: [$e_msg] [$e_code]");
        return "Mail exception: [$e_msg] [$e_code]";
		}
	if ($ret === true)
		{
		LAE_trace::trace("mailer->Send() returned true");
		return '';
		}
	else
		{
		LAE_trace::trace("mailer->Send() returned error: ".$mailer->ErrorInfo);
		return Text::_('COM_EYESITE_EMAIL_SEND_FAILED').' '.$mailer->ErrorInfo;
		}
}

//-------------------------------------------------------------------------------
// Make a select list
//
static function make_list($name, $current_value, $items, $extra_class='')
{
	if (empty($items))
		return '';
	$class = "form-select form-control lad-input-inline";
	if (!empty($extra_class))
		$class .= ' '.$extra_class;
	$html = "\n".'<select name="'.$name.'" id="'.$name.'" class="'.$class.'">';
	foreach ($items as $key => $value)
		{
		$selected = '';
		if ($current_value == $key)
			$selected = ' selected="selected"';
		$html .= "\n".'<option value="'.$key.'"'.$selected.'>'.$value.'</option>';
		}
	$html .= '</select>'."\n";
	return $html;
}

//-------------------------------------------------------------------------------
// Return true if supplied argument is a positive integer, else false
//
static function is_posint($arg)
{
	if ($arg === '')
		return false;
	if (!is_numeric($arg))
		return false;
	if (preg_match('/[^\d]/', $arg))
		return false;
	return true;
}

//-------------------------------------------------------------------------------
// Expand a comma delimited list to an array
// (returning an empty array for an empty string)
//
static function expand_cs_list($cs_list)
{
	$cs_list = trim($cs_list,", \n\r\t\v\0");	// trim white space or extra commas
	$a = explode(",",$cs_list);
	$a = array_map('trim',$a);					// trim white space
	if ((count($a) == 1) && ($a[0] == ''))
		return array();
	return $a;
}

// -------------------------------------------------------------------------------
// Create the component menu and make the current item active
//
static function addSubMenu($submenu = '')
{
	$component_params = ComponentHelper::getParams(LAE_COMPONENT);
	$params = $component_params->toObject();	
	if (!empty($params->hide_submenu))
		return;
    if (substr(JVERSION,0,1) == '3')
		{
		JHtmlSidebar::addEntry(Text::_('COM_EYESITE_STATUS'), 'index.php?option='.LAE_COMPONENT.'&task=display', $submenu == 'main');
		JHtmlSidebar::addEntry(Text::_('COM_EYESITE_HISTORY'), 'index.php?option='.LAE_COMPONENT.'&task=history_list', $submenu == 'history');
		JHtmlSidebar::addEntry(Text::_('COM_EYESITE_CONFIGURATION'), 'index.php?option='.LAE_COMPONENT.'&task=configure', $submenu == 'config');
		JHtmlSidebar::addEntry(Text::_('COM_EYESITE_ABOUT'), 'index.php?option='.LAE_COMPONENT.'&task=about', $submenu == 'about');
		}
	else
		{
		Sidebar::addEntry(Text::_('COM_EYESITE_STATUS'), 'index.php?option='.LAE_COMPONENT.'&task=display', $submenu == 'main');
		Sidebar::addEntry(Text::_('COM_EYESITE_HISTORY'), 'index.php?option='.LAE_COMPONENT.'&task=history_list', $submenu == 'history');
		Sidebar::addEntry(Text::_('COM_EYESITE_CONFIGURATION'), 'index.php?option='.LAE_COMPONENT.'&task=configure', $submenu == 'config');
		Sidebar::addEntry(Text::_('COM_EYESITE_ABOUT'), 'index.php?option='.LAE_COMPONENT.'&task=about', $submenu == 'about');
		}
}

// -------------------------------------------------------------------------------
// Draw the component menu
// - called at the start of every view
//
static function viewStart()
{
    if (substr(JVERSION,0,1) == '3')
        {
		$entries = JHtmlSidebar::getEntries();
        if (empty($entries))
            echo '<div id="j-main-container">';
        else
            {
            $sidebar = JHtmlSidebar::render();
            echo '<div id="j-sidebar-container" class="span2">'.$sidebar.'</div>';
            echo '<div id="j-main-container" class="span10">';
            }
        }
    else        // Joomla 4/5
        {
		$entries = Sidebar::getEntries();
		$component_params = ComponentHelper::getParams(LAE_COMPONENT);
		$params = $component_params->toObject();	
		if (empty($params->compact_mode))
	        echo '<div class="row">';
		else
	        echo '<div class="row lad-compact">';
        if (empty($entries))
			echo '<div class="col-md-12">';
        else
            {
            $sidebar = Sidebar::render();
            echo '<div id="j-sidebar-container" class="col-md-2">'.$sidebar.'</div>';
            echo '<div class="col-md-10">';
            echo '<div id="j-main-container" class="j-main-container">';
            }
        }
}

// -------------------------------------------------------------------------------
// Called at the end of every view that calls viewStart()
//
static function viewEnd()
{
    if (substr(JVERSION,0,1) == '3')
    	echo "</div>";                          // close "j-main-container"
    else        // Joomla 4
        {
       	echo "</div>";                          // close "j-main-container"
    	$entries = Sidebar::getEntries();
        if (!empty($entries))
        	echo "</div>";                      // close "col-md-10"
       	echo "</div>";                          // close "row"
        }
}

//-------------------------------------------------------------------------------
// Get client's IP address
//
static function getIPaddress()
{
	$input = Factory::getApplication()->input;
	if (!empty($input->server->getString('REMOTE_ADDR','')))
		$ip = $input->server->getString('REMOTE_ADDR','');
	elseif (!empty($input->server->getString('HTTP_X_FORWARDED_FOR','')))
		$ip = $input->server->getString('HTTP_X_FORWARDED_FOR','');
	else $ip = $input->server->getString('HTTP_CLIENT_IP','');
	return filter_var($ip, FILTER_VALIDATE_IP);
} 

//------------------------------------------------------------------------------
// get the URL language code for a language tag (e.g. fr-FR)
//   'SITE' = get the URL code of the front end default language
//   'CURRENT' = get the URL code of the current active language
//   any other tag = try to find the URL code for it
//
static function get_language_code($tag)
{
    if ($tag == 'SITE')
        $tag = ComponentHelper::getParams('com_languages')->get('site', 'en-GB');
	if ($tag == 'CURRENT')
		$tag = Factory::getLanguage()->get('tag'); 
	$languages = LanguageHelper::getLanguages();
	foreach ($languages as $language)
		if ($language->lang_code == $tag)
			return $language->sef;
	return substr($tag,0,2);
}

//------------------------------------------------------------------------------
// get a URL language parameter, &lang=xx for a specified language tag (e.g. fr-FR)
//
static function get_lang_param($tag)
{
    if (!Multilanguage::isEnabled())
        return '';
	return '&lang='.self::get_language_code($tag);
}

}