Your IP : 216.73.216.41


Current Path : /home/purehotels/public_html/components/com_easyfolderlistingpro/helpers/
Upload File :
Current File : /home/purehotels/public_html/components/com_easyfolderlistingpro/helpers/EFLPList.Class.php

<?php
/**
 * @name          EFLPList
 * @description    
 * @author        Michael Gilkes (Valor Apps)
 * @created       Monday, May 06, 2014
 * @modified      Monday, August 25, 2014
 * @version       1.1
 * @copyright     Copyright (C) 2012-2016 Michael Albert Gilkes. All rights reserved.
 * @license       GNU General Public License version 3 or later; see LICENSE
 */

require_once("EFLPListing.Class.php");


class EFLPList extends EFLPListing
{
	/**
	 * Generates the HTML Unordered List code
	 */
	public function renderHTML()
	{
		//holds the final html. enclose listing in a div
		$html = '<div>';
		
		//add search panel if specified
		$html.= $this->addSearchPanel();
		
		//add multi-download panel here
		if ($this->get('multidownload'))
		{
			//assign the archive download url as the action
			$action = 'index.php?option=com_easyfolderlistingpro&task=archive.download&format=raw';
			
			//create the form id/name from the listing id
			$form_id = $this->listingId.'-multidownload-form';
			
			//start the form tag 
			$enctype = 'multipart/form-data'; //application/x-www-form-urlencoded
			$html.= "\n".'<form id="'.$form_id.'" name="'.$form_id.'" action="'.$action.'" method="post" enctype="'.$enctype.'">'."\n";
		}
		
		//add the multi-download panel controls
		$html.= $this->addMultiDownloadPanel();
		
		//add the icon control to collapse/expand all
		$html.= $this->addCollapseExpandControl();
		
		$html.= '<div id="'.$this->listingId.'-container">';
		
		//render the html unordered list
		$html.= $this->buildUnorderedList();
		
		$html.= '</div>';
		
		if ($this->get('multidownload'))
		{
			//save the archive settings data
			$archive_data = $this->serializeArchiveSettings();
			$html.= '<input type="hidden" name="archive_data" id="archive_data" value="'.$archive_data.'" />'."\n";
			
			//add security token
			$html.= JHtml::_('form.token');
			
			//close the form tag
			$html.= '</form>'."\n";
		}
		
		//close the surrounding div
		$html.= '</div>';
		
		return $html;
	}
	
	/**
	 * Returns the unordered list code. Deliberately made to separate the unordered list code from the 
	 * renderHTML() method.
	 */
	public function buildUnorderedList($token = null)
	{
		//start the ul
		$html = '<ul id="'.$this->listingId.'" style="list-style:'.$this->get('liststyle').';" ';
		
		//add the class
		$html.= 'class="'.self::CLASS_PREFIX.'standard" ';
		
		//add the encrypted parameters
		$html.= 'data-listing="'.$this->serializedParameters.'"';
		
		//add security token
		if (empty($token))
		{
			$token = JSession::getFormToken();
		}
		$html.= ' data-token="'.$token.'"';
		
		//close the tag
		$html.= '>'."\n";
		
		//place the level 0 files before
		if ($this->get('filesposition'))
		{
			$html.= $this->handleFiles('', 0);
		}
		
		if ($this->get('subfolders'))
		{
			//$count = count($this->folders);
			$html.= $this->handleSubfolders('/', '');
		}
		
		//place the level 0 files after
		if (!$this->get('filesposition'))
		{
			$html.= $this->handleFiles('', 0);
		}
		
		//end the ul
		$html.= '</ul>'."\n";
		
		return $html;
	}
	
	/**
	 * Adds list item rows of files in a specified relative path in the folder listing.
	 */
	protected function handleFiles($relative_path, $level, $nest = true)
	{
		$html = '';
		
		foreach ($this->files as $i => $file)
		{
			if ($file['relpath'] == $relative_path)
			{
				//start the li row tag
				$html.= "\t".'<li>';
				
				//Add download checkbox here
				$html.= $this->addCheckbox($i);
				
				//add the filename
				$html.= $this->formatFilename($i);
				
				//Note: we do NOT offer subfoldercolumn for unordered list
				
				//display the file size first
				if ($this->get('size') && $this->get('sizefirst'))
				{
					//add the separator
					$html.= ' '.$this->get('separator').' ';
					
					//show file size in human readable form
					$html.= $this->readableFileSize($file['bytes']);
				}
				
				//display the date
				if ($this->get('date'))
				{
					//add the separator
					$html.= ' '.$this->get('separator').' ';
					
					//get the date type
					$datetype = $this->get('datetype');
					
					//display the date/time in human readable form
					$html.= $this->readableDateTime($file[$datetype]);
				}
				
				//display the file size last
				if ($this->get('size') && !$this->get('sizefirst'))
				{
					//add the separator
					$html.= ' '.$this->get('separator').' ';
					
					//show file size in human readable form
					$html.= $this->readableFileSize($file['bytes']);
				}
				
				//close the li row tag
				$html.= '</li>'."\n";
			}
		}
		
		//there are no files to list
		if (empty($html))
		{
			if ($this->get('showempty') == 1 || ($this->get('showempty') == 2 && $level > 0))
			{
				//open the li tag
				$html.= "\t".'<li>';
				
				//Add the exclamation icon
				if ($this->get('icons'))
				{
					$html .= '<img src="'.$this->config->get('nofilesicon').'" alt="'.JText::_($this->config->get('nofilesalt')).'" /> ';
				}
				
				//show the empty message
				$html.= '<span class="'.self::CLASS_PREFIX.'empty">'.JText::_('PLG_CONTENT_EFLP_NO_FILES_NOTICE').'</span>';
				
				//close the li tag
				$html.= '</li>'."\n";
			}
		}
		
		return $html;
	}
	
	/**
	 * Recursive function to handle all the subfolders and their files, and display the resulting
	 * html list items.
	 */
	protected function handleSubfolders($parent, $path)
	{
		$html = '';
		
		//Note: folders are already ordered by ascending or descending
		foreach ($this->folders as $i => $dir)
		{
			if ($dir['parent'] == $parent && $dir['relpath'] == $path.'/'.$dir['name'])
			{
				//create the id of the list item
				$rowid = $this->listingId.'sub'.$i;
				
				//create the li for the subfolder name
				$html.= "\t".'<li id="'.$rowid.'" class="trigger">';
				
				//add the formatted subfolder name
				$html.= $this->formatSubfolderName($i);
				
				//close the li for subfolder name
				$html.= '</li>'."\n";
				
				//process the children related to the subfolder
				$html.= "\t".'<li class="child-of-'.$rowid.'">';
				
				//children are encased in their own ul element
				$html.= "\n\t\t".'<ul style="list-style-type:'.$this->get('liststyle').';" ';
				$html.= 'class="'.self::CLASS_PREFIX.'standard">'."\n";
				
				if ($this->get('filesposition'))
				{
					//place files before
					$html.= $this->handleFiles($dir['relpath'], $dir['level']);
					$html.= $this->handleSubfolders($dir['name'], $dir['relpath']);
				}
				else
				{
					//place files after
					$html.= $this->handleSubfolders($dir['name'], $dir['relpath']);
					$html.= $this->handleFiles($dir['relpath'], $dir['level']);
				}
				
				//close the child ul tag
				$html.= "\n\t\t".'</ul>'."\n";
				
				//close the subfolder li tag
				$html.= "\t".'</li>'."\n";
			}
		}
		
		return $html;
	}
}