| Current Path : /home/purehotels/public_html/components/com_easyfolderlistingpro/helpers/ |
| Current File : /home/purehotels/public_html/components/com_easyfolderlistingpro/helpers/EFLPTable.Class.php |
<?php
/**
* @name EFLPTable
* @description
* @author Michael Gilkes (Valor Apps)
* @created Monday, March 24, 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 EFLPTable extends EFLPListing
{
//number of pixels for one level space
protected $tabPixels = 27;
/**
* Generates the HTML Table code
*/
public function renderHTML()
{
//holds the final html. enclose the 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 table
$html.= $this->buildTable();
$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 html table code. Deliberately made to separate the table code from the
* renderHTML() method.
*/
public function buildTable($token = null)
{
//default number of columns expected. this is for filename.
$columns = 1;
//add column for size and date, and relpath, it specified
if ($this->get('size')) { $columns++; }
if ($this->get('date')) { $columns++; }
if ($this->get('subfoldercolumn')) { $columns++; }
//add multi-download panel here
if ($this->get('multidownload'))
{
//add column for the checkboxes
$columns++;
}
//start the table
$html = '<table id="'.$this->listingId.'" ';
//setup the styling
if ($this->get('tablestyle') == 'standard')
{
$html.= 'style="background-color:'.$this->get('bordercolor').'; " ';
$html.= 'class="'.self::CLASS_PREFIX.$this->get('tablestyle').'" ';
}
else
{
$html.= 'class="'.$this->get('tablestyle').'" ';
}
//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";
//make sure the process the headings data
$this->processHeadings($columns);
//start the colgroup
$html.= "\t".'<colgroup>';
//Add the column width for the checkboxes
if ($this->get('multidownload'))
{
$html.= "\t\t".'<col width="1%">'."\n";
}
//add column widths for headings
foreach ($this->headings as $heading)
{
$html.= "\t\t".'<col width="'.$heading['percent'].'%">'."\n";
}
//close the column group
$html.= "\t".'</colgroup>'."\n";
//table head section
$html.= "\t".'<thead>'."\n";
$html.= "\t\t".'<tr ';
//setup the styling
if ($this->get('tablestyle') == 'standard')
{
$html.= 'style="';
$html.= 'background-color:'.$this->get('headcolor').';"';
}
$html.= '>'."\n";
//Add the download select all heading
if ($this->get('multidownload'))
{
$html.= "\t\t\t".'<th><input type="checkbox" name="checkall-toggle" value="" title="Check All" onclick="Joomla.checkAll(this)" /></th>'."\n";
}
//add the other headings
foreach ($this->headings as $i => $heading)
{
$text = '';
if ($heading['type'] == 'name')
{
$text = JText::_('PLG_CONTENT_EFLP_FILENAME_TEXT');
}
elseif ($heading['type'] == 'relpath')
{
$text = JText::_('PLG_CONTENT_EFLP_RELPATH_TEXT');
}
elseif ($heading['type'] == 'size')
{
$text = JText::_('PLG_CONTENT_EFLP_SIZE_TEXT');
}
elseif ($heading['type'] == 'date')
{
if ($this->get('time'))
{
$text = JText::_('PLG_CONTENT_EFLP_TIME_TEXT');
}
else
{
$text = JText::_('PLG_CONTENT_EFLP_DATE_TEXT');
}
}
$html.= "\t\t\t".'<th style="">'.$text.'</th>'."\n";
}
$html.= "\t\t".'</tr>'."\n";
$html.= "\t".'</thead>'."\n";
//add the table footer
$html.= $this->buildFooter($columns);
//add the table rows
$html.= $this->buildRows($columns);
//clost the table tag
$html .= '</table>'."\n";
return $html;
}
/**
* Builds the Footer for the table
*/
protected function buildFooter($columns)
{
return '';
}
/**
* Takes the files array and builds the appropriate listing rows
*/
protected function buildRows($columns)
{
$html = '';
//place the files before?
if ($this->get('filesposition'))
{
$html.= $this->handleFiles('', 0, $columns);
}
if ($this->get('subfolders'))
{
$count = count($this->folders);
$html.= $this->handleSubfolders('/', '', $columns, $count);
}
//Or, place the files after?
if (!$this->get('filesposition'))
{
$html.= $this->handleFiles('', 0, $columns);
}
return $html;
}
/**
* Adds html table rows of files in a specified relative path in the folder listing.
*/
protected function handleFiles($relative_path, $level, $columns, $class = '')
{
//holds the html
$html = '';
//space in pixels
$space = ($level * $this->tabPixels);
//count is used to find out the number of rows fo files for this section. It is used for color determination.
$count = 1;
foreach ($this->files as $i => $file)
{
if ($file['relpath'] == $relative_path)
{
//start the table row
$html.= "\t".'<tr';
if ($class != "")
{
$html.= ' class="'.$class.'"';
}
//set the colors if the table style is standard
if ($this->get('tablestyle') == 'standard')
{
//set the colour for the odd row
$color = $this->get('oddcolor');
//is the row even
if ($count%2 == 0)
{
//set the colour for the even row
$color = $this->get('evencolor');
}
//set the background color
$html.= ' style="background-color:'.$color.';"';
}
//close the table row
$html.= '>'."\n";
//Add download checkbox here
if ($this->get('multidownload'))
{
//add the checkbox for the file
$html.= "\t\t".'<td>'."\n";
$html.= $this->addCheckbox($i);
$html.= "\t\t".'</td>'."\n";
}
//add the contents based on the headings
foreach ($this->headings as $j => $meta)
{
$html .= "\t\t".'<td';
if ($j == 0 && $space > 0)
{
//add the necessary space to first meta column
$html.= ' style="padding-left:'.$space.'px;"';
}
$html.= '>';
if ($meta['type'] == 'name')
{
//format filename
$html.= $this->formatFilename($i);
}
elseif ($meta['type'] == 'relpath')
{
//add the relative path
$html.= $file['relpath'];
}
elseif ($meta['type'] == 'size')
{
//show file size in human readable form
$html.= $this->readableFileSize($file['bytes']);
}
elseif ($meta['type'] == 'date')
{
//get the date type
$datetype = $this->get('datetype');
//display the date/time in human readable form
$html.= $this->readableDateTime($file[$datetype]);
}
//close column
$html .= '</td>'."\n";
}
//end the tag
$html .= "\t".'</tr>'."\n";
$count++;
}
}
//there are no files to list
if (empty($html))
{
if ($this->get('showempty') == 1 || ($this->get('showempty') == 2 && $level > 0))
{
//start the table row
$html.= "\t".'<tbody><tr';
//add the class
if ($class != "")
{
$html.= ' class="'.$class.'"';
}
//set the colors if the table style is standard
if ($this->get('tablestyle') == 'standard')
{
$html.= ' style="background-color:'.$this->get('oddcolor').';"';
}
//close the opening tr tag
$html.= '>'."\n";
//filename column
$html.= "\t\t".'<td colspan="'.$columns.'" style="';
//add the necessary space
if ($space > 0)
{
$html.= 'padding-left:'.$space.'px;';
}
//close the opening td tag
$html.= '">';
//Add the exclamation icon
if ($this->get('icons'))
{
$html .= '<img src="'.$this->config->get('nofilesicon').'" alt="'.JText::_($this->config->get('nofilesalt')).'" /> ';
}
//display the empty message
$html.= '<span class="'.self::CLASS_PREFIX.'empty">'.JText::_('PLG_CONTENT_EFLP_NO_FILES_NOTICE').'</span></td>'."\n";
$html.= "\t".'</tr></tbody>'."\n";
}
}
else
{
//surround in tbody for better organisation
$html = "\t".'<tbody>'."\n".$html."\t".'</tbody>'."\n";
}
return $html;
}
/**
* Recursive function to handle all the subfolders and their files, and display the resulting
* html table rows.
*/
protected function handleSubfolders($parent, $path, $columns, $parent_index)
{
$html = '';
$rowclass = 'trigger';
//Note: folders are already ordered by ascending or descending
foreach ($this->folders as $i => $dir)
{
if ($dir['parent'] == $parent && $dir['relpath'] == $path.'/'.$dir['name'])
{
if ($dir['level'] > 1)
{
$rowclass.= ' child-of-'.$this->listingId."sub".$parent_index;
}
//create the id of the table row
$rowid = $this->listingId."sub".$i;
//tbody for subfolder name
$html.= "\t".'<tbody>'."\n";
//table row for the subfolder name
$html.= "\t\t".'<tr id="'.$rowid.'" class="'.$rowclass.'">'."\n";
//table cell for the subfolder name
$html.= "\t\t\t".'<td';
$html.= ' style="'; //removed padding:1px; and placed it in styles.css
//add backgorund color for standard style
if ($this->get('tablestyle') == 'standard')
{
$html.= 'background-color:'.$this->get('subcolor').';';
}
//add proper spacing
if ($dir['level'] > 1)
{
//calculate the space needed
$space = (($dir['level'] - 1) * $this->tabPixels);
$html.= ' padding-left:'.$space.'px;';
}
$html.= '" ';
//merge the columns
$html.= 'colspan="'.$columns.'">';
//format the folder name and display it
$html.= $this->formatSubfolderName($i);
//close the tags
$html.= '</td>'."\n";
$html.= "\t\t".'</tr>'."\n";
$html.= "\t".'</tbody>'."\n";
if ($this->get('filesposition'))
{
//place files before
$html.= $this->handleFiles($dir['relpath'], $dir['level'], $columns, 'child-of-'.$rowid);
$html.= $this->handleSubfolders($dir['name'], $dir['relpath'], $columns, $i);
}
else
{
//place files after
$html.= $this->handleSubfolders($dir['name'], $dir['relpath'], $columns, $i);
$html.= $this->handleFiles($dir['relpath'], $dir['level'], $columns, 'child-of-'.$rowid);
}
}
}
return $html;
}
}