Your IP : 216.73.216.41


Current Path : /home/purehotels/public_html/administrator/components/com_easyfolderlistingpro/models/
Upload File :
Current File : /home/purehotels/public_html/administrator/components/com_easyfolderlistingpro/models/dashboard.php

<?php
/**
* @version		3.2
* @author		Michael A. Gilkes (michael@valorapps.com)
* @copyright	Michael Albert Gilkes
* @license		GNU/GPLv3

Easy Folder Listing Pro Component for Joomla!
Copyright (C) 2012-2016 Michael Albert Gilkes (Valor Apps)

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

// No direct access to this file
defined('_JEXEC') or die('Restricted access');

//load the JFile library
jimport('joomla.filesystem.file');


/**
 * EasyFolderListingPro Dashboard Model
 */
class EasyFolderListingProModelDashboard extends JModelLegacy
{
	public function getExtensionList()
	{
		//Create a new query object.
		$db	= $this->getDbo();
		$query = $db->getQuery(true);
		
		$query->select('`extension_id`, `name`, `type`, `enabled`, `folder`, `manifest_cache`');
		$query->from('#__extensions');
		$query->where('`element` LIKE '.$db->Quote('%easyfolderlistingpro'));
		
		$db->setQuery($query);
		$exts = $db->loadAssocList();
		
		// Check for a database error.
		if ($db->getErrorNum())
		{
			JLog::add($db->getErrorMsg(), JLog::ERROR, 'com_easyfolderlistingpro');
			//$e = new JException($db->getErrorMsg());
		}
		
		return $exts;
	}
	
	public function getErrorLogs()
	{
		$errors = array();
		$logpath = JFactory::getConfig()->get('log_path').'/valorapps.errors.php';
		
		if (JFile::exists($logpath))
		{
			//get the error file contents
			$contents = JFile::read($logpath);
			
			//replace all newlines and carriage returns with spaces
			$contents = str_replace(array("\r\n", "\n", "\r"), ' ', $contents);
			
			//Example of date format in error log file: 2014-01-12T00:10:25+00:00
			$pattern = '/([0-9]{4}\-[0-9]{2}\-[0-9]{2}T[0-9]{2}\:[0-9]{2}\:[0-9]{2}\+[0-9]{2}\:[0-9]{2})\t([A-Za-z]+)\t([A-Za-z_\-]+)\t(.+?)(?=$| [0-9]{4}\-[0-9]{2}\-[0-9]{2}T[0-9]{2}\:[0-9]{2}\:[0-9]{2}\+[0-9]{2}\:[0-9]{2})/';
			preg_match_all($pattern, $contents, $matches, PREG_SET_ORDER);
			
			$errors = array_map('EasyFolderListingProModelDashboard::removeFirst', $matches);
			
			//order by most recent first
			$errors = array_reverse($errors);
		}
		else
		{
			//if the file doesn't exist, then no errors have been logged yet.
			//don't do anything. just return empty array
		}
		
		return $errors;
	}
	
	static function removeFirst($array)
	{
		$shorter = array();
		for ($i = 1; $i < count($array); $i++)
		{
			$shorter[$i-1] = $array[$i];
		}
		return $shorter;
	}
	
	public function getChangeLog()
	{
		$log = '';
		$logpath = JPATH_ADMINISTRATOR.'/components/com_easyfolderlistingpro/CHANGELOG.php';
		
		if (JFile::exists($logpath))
		{
			//get the error file contents
			$content = JFile::read($logpath);
			
			//remove the first 13 lines
			$log = preg_replace("/^(.*\n){13}/", "", $content);
		}
		else
		{
			//if the file doesn't exist, something is serioiusly wrong
			JLog::add(JText::sprintf('COM_EFLP_CHANGELOG_MISSING', $logpath), JLog::ERROR, 'com_easyfolderlistingpro');
		}
		
		return $log;
	}
	
	public function getAttributeList()
	{
		//Get the form.
		JForm::addFormPath(JPATH_COMPONENT.'/models/forms');
		JForm::addFieldPath(JPATH_COMPONENT.'/models/fields');

		try
		{
			$form = JForm::getInstance('com_easyfolderlistingpro.profile', 'profile', array('control'=>'jform'), false, false);
		}
		catch (Exception $e)
		{
			JLog::add($e->getMessage(), JLog::ERROR, 'com_easyfolderlistingpro');
		}
		
		$attrs = array();
		
		//set up the list of fields to exclude
		$ignore = array('id', 'published', 'checked_out', 'checked_out_time', 'access', 'title');
		
		//add the first 'profile' custom field
		$attrs[] = $this->addAttr('profile', 'COM_EFLP_PROFILE_IDNAME_LABEL', '1', 'COM_EFLP_PROFILE_IDNAME_DESC');
		
		foreach ($form->getFieldsets() as $fieldsets)
		{
			$fields = $form->getFieldset($fieldsets->name);
			foreach ($fields as $field)
			{
				$property = $field->fieldname;
				$type = $form->getFieldAttribute($field->fieldname, 'type');
				if ($type != 'spacer' && $type != 'hidden' && !in_array($property, $ignore))
				{
					$label = $form->getFieldAttribute($field->fieldname, 'label');
					//$default = $form->getFieldAttribute($field->fieldname, 'default');
					$default = $field->value;
					$desc = $form->getFieldAttribute($field->fieldname, 'description');
					
					$attrs[] = $this->addAttr($property, $label, $default, $desc);
				}
			}
		}
		
		return $attrs;
	}
	
	protected function addAttr($attr, $name, $default, $desc)
	{
		return array('attr'=>$attr, 'name'=>$name, 'default'=>$default, 'desc'=>$desc);
	}
	
	public function getArchiveList()
	{
		$db	= $this->getDbo();
		$query = $db->getQuery(true);
		
		$query->select('`id`, `file_path`, `created_time`, `life_time`');
		$query->from('#__eflp_archives');
		
		$db->setQuery($query);
		$archives = $db->loadAssocList();
		
		// Check for a database error.
		if ($db->getErrorNum())
		{
			JLog::add($db->getErrorMsg(), JLog::ERROR, 'com_easyfolderlistingpro');
			//$e = new JException($db->getErrorMsg());
		}
		
		return $archives;
	}
}