<?php
/**
 * @package    VP Advanced User
 * @author     Abhishek Das <info@virtueplanet.com>
 * @copyright  Copyright (C) 2012-2019 VirtuePlanet Services LLP. All rights reserved.
 * @license    GNU General Public License version 2 or later; see LICENSE.txt
 * @link       https://www.virtueplanet.com
 */

defined('_JEXEC') or die;

class VPAdvancedUserMailerData
{
	public $fromname;
	
	public $mailfrom;
	
	public $name;
	
	public $username;
	
	public $email;
	
	public $password_clear;

	public $siteurl;
	
	public $siteurl_html;
	
	public $sitename;
	
	public $offline_logo;
	
	public $offline_logo_link;
	
	public $activate;
	
	public $link_text;
	
	public $link_html;
	
	public $token;
	
	/**
	 * Class constructor
	 *
	 * @param   array  $data  Data to bind.
	 *
	 * @since   1.0.
	 */
	public function __construct($data = null)
	{
		$config             = JFactory::getConfig();
		
		$this->siteurl      = JUri::root();
		$this->siteurl_html = '<a href="' . $this->siteurl . '" target="_blank" class="siteurl-html">' . $this->siteurl . '</a>';
		$this->fromname     = $config->get('fromname');
		$this->mailfrom     = $config->get('mailfrom');
		$this->sitename     = $config->get('sitename');
		$this->offline_logo = '';
		
		$offline_image      = $config->get('offline_image');
		
		if (!empty($offline_image) && is_file(JPATH_ROOT . '/' . $offline_image))
		{
			$attribs  = 'style="display: block; font-family: Helvetica, Arial, sans-serif; color: #ffffff; font-size: 16px;" border="0"';
			$attribs .= ' alt="' . htmlspecialchars($this->sitename) . '"';
			
			if (function_exists('getimagesize'))
			{
				// Get image size
				list($width, $height) = @getimagesize(JPATH_ROOT . '/' . $offline_image);
				
				if (!empty($width) && !empty($height))
				{
					$attribs .= ' width="' . $width . '"  height="' . $height . '"';
				}
			}
			
			$this->offline_logo = '<img src="' . $this->siteurl . $offline_image . '" ' . $attribs . ' />';
		}
		
		if (!empty($this->offline_logo))
		{
			$this->offline_logo_link = '<a href="' . $this->siteurl . '" target="_blank">' . $this->offline_logo . '</a>';
		}
		else
		{
			$site_logo_text = '<h1 style="font-family: Helvetica, Arial, sans-serif; color: #333333; font-size: 32px; font-weight: bold; line-height: 1; margin: 0; padding: 0;">' . $this->sitename . '</h1>';
			$this->offline_logo_link = '<a href="' . $this->siteurl . '" target="_blank" style="text-decoration: none;">' . $site_logo_text . '</a>';
		}
		
		if (is_array($data))
		{
			foreach ($data as $property => $value)
			{
				if (property_exists($this, $property) && !empty($value))
				{
					$this->$property = $value;
				}
			}
		}
	}
}