Your IP : 216.73.216.41


Current Path : /proc/self/cwd/components/com_easyfolderlistingpro/helpers/
Upload File :
Current File : //proc/self/cwd/components/com_easyfolderlistingpro/helpers/EFLPSearchList.Class.php

<?php
/**
 * @name          EFLPSearchList
 * @description    
 * @author        Michael Gilkes (Valor Apps)
 * @created       Monday, July 17, 2014
 * @modified      
 * @version       1.0
 * @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 EFLPSearchList extends EFLPListing
{
	protected $criteria = '';
	
	protected $results = array();
	
	/**
	 * Generates the HTML Unordered List code
	 */
	public function renderHTML()
	{
		//holds the final html. enclose listing in a div
		$html = '<div>';
		
		//search he file list for files that match the criteria
		$this->searchFiles();
		
		if (!empty($this->results))
		{
			if (count($this->results) > (int)$this->get('searchlimit'))
			{
				$html.= '<div>'.JText::sprintf('PLG_CONTENT_EFLP_DISPLAY_OF_RESULTS', (int)$this->get('searchlimit'), count($this->results)).'</div>';
			}
			else
			{
				$html.= '<div>'.JText::sprintf('PLG_CONTENT_EFLP_DISPLAY_RESULTS', count($this->results)).'</div>';
			}
		}
		
		//render the html ordered list
		$html.= $this->buildOrderedList();
		
		//close the surrounding div
		$html.= '</div>';
		
		return $html;
	}
	
	/**
	 * Set the serach criteria or search to text
	 */
	public function setSearchText($text)
	{
		$this->criteria = $text;
	}
	
	/**
	 *
	 */
	protected function searchFiles()
	{
		foreach ($this->files as $i => $file)
		{
			if (preg_match("/".$this->criteria."/i", $file['filename']))
			{
				$this->results[$i] = $file;
			}
		}
	}
	
	/**
	 * Returns the ordered list code. 
	 */
	public function buildOrderedList()
	{
		//start the ul
		$html = '<ol id="'.$this->listingId.'_matches" ';
		
		//add the class
		$html.= 'class="'.self::CLASS_PREFIX.'standard" ';
		
		//close the tag
		$html.= '>'."\n";
		
		//display files
		$html.= $this->handleFiles('', 0);
		
		//end the ul
		$html.= '</ol>'."\n";
		
		return $html;
	}
	
	/**
	 * Overrides the parent method. 
	 */
	protected function handleFiles($relative_path, $level, $nest = true)
	{
		$html = '';
		
		$count = 0;
		foreach ($this->results as $i => $file)
		{
			if ($count < (int)$this->get('searchlimit'))
			{
				//start the li row tag
				$html.= "\t".'<li>';
				
				//add the filename
				$html.= $this->formatFilename($i);
				
				//add the subfolder info
				//if ($this->get('subfoldercolumn'))
				{
					//add the separator
					$html.= ' '.$this->get('separator').' ';
					
					//add subfoldercolumn
					$html.= $file['relpath'];
				}
				
				//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";
			}
			$count++;
		}
		
		//there are no files to list
		if (empty($html))
		{
				//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 no files found message
				$html.= '<span class="'.self::CLASS_PREFIX.'empty">'.JText::_('PLG_CONTENT_EFLP_NO_FILES_FOUND').'</span>';
				
				//close the li tag
				$html.= '</li>'."\n";
		}
		
		return $html;
	}
	
}