| Current Path : /proc/self/cwd/components/com_easyfolderlistingpro/helpers/ |
| Current File : //proc/self/cwd/components/com_easyfolderlistingpro/helpers/EFLPExplorerList.Class.php |
<?php
/**
* @name EFLPExplorerList
* @description
* @author Michael Gilkes (Valor Apps)
* @created Tuesday, July 01, 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(JPATH_ADMINISTRATOR.'/components/com_easyfolderlistingpro/helpers/eflphelper.php');
require_once("EFLPList.Class.php");
class EFLPExplorerList extends EFLPList
{
const EXPLORER_STYLES = 'css/explorer.css';
protected static $basicLoaded = false;
protected $max_width = 50;
protected $max_height = 50;
protected $currentFolder = array(
'relpath' => '',
'level' => 0,
'name' => '',
'parent' => ''
);
protected $parentFolder = array(
'relpath' => '',
'level' => 0,
'name' => '',
'parent' => ''
);
/**
*
*/
public function setCurrentFolder($folder)
{
$this->currentFolder = array_merge($this->currentFolder, $folder);
}
/**
*
*/
public function setParentFolder($folder)
{
$this->parentFolder = array_merge($this->parentFolder, $folder);
}
/**
* Overrides the parent moethod. Generates the HTML Table code
*/
public function renderHTML()
{
//setup the custom javascript
//$this->setupJavascript();
//load the custom styles for the explorer view to work
$this->loadBasicStyles();
//return the paginated table html
return parent::renderHTML();
}
/**
* Overrides the parent method to not show the collapse/expand control
*/
protected function addCollapseExpandControl()
{
$html = '';
return $html;
}
/**
* Loads the basic hard-coded styles to make the explorer view work
*/
protected function loadBasicStyles()
{
if (self::$basicLoaded == false)
{
$path = JUri::base(true).'/media/com_easyfolderlistingpro/'.self::EXPLORER_STYLES;
//Add the css to the document head.
JFactory::getDocument()->addStyleSheet($path);
//set flag
self::$basicLoaded = true;
}
}
protected function resetModals($class = null)
{
$html = "\n".'<script type="text/javascript">'."\n";
//get the modal type
$modaltype = $this->get('modaltype');
if ($this->mootools || $modaltype == 'mootools')
{
if (empty($class)) { $class = self::MODAL_MOO; }
$html.= "SqueezeBox.assign($$('a.".$class."'), { parse: 'rel' });";
}
elseif ($modaltype == 'auto')
{
if (empty($class)) { $class = self::MODAL_JQY; }
$html.= EFLPHelper::jQyModalScript($class, self::MODAL_ID);
}
$html.= "\n".'</script>';
return $html;
}
/*
<ul class="thumbs">
<?php foreach ($this->subfolders as $subfolder) : ?>
<li class="thumb">
<a href="index.php?option=com_easyfolderlistingpro&view=imagedialog&tmpl=component&fieldid=<?php echo $this->state->get('field.id'); ?>&folder=<?php echo rawurlencode($subfolder->path_relative); ?>">
<div class="thumb-icon">
<img src="<?php echo $imagedatum->url; ?>" alt="<?php echo $imagedatum->name.' - '.$imagedatum->size; ?>" width="<?php echo $imagedatum->width; ?>px" height="<?php echo $imagedatum->height; ?>px" />
</div>
<div class="thumb-name">
<?php echo $subfolder->name; ?>
</div>
</a>
</li>
<?php endforeach; ?>
<?php foreach ($this->imagesdata as $imagedatum) : ?>
<li class="thumb">
<a href="javascript:void(0)" onclick="document.id('image_url').value='<?php echo $imagedatum->path_relative;?>'">
<div class="thumb-icon">
<img src="<?php echo $imagedatum->url; ?>" alt="<?php echo $imagedatum->name.' - '.$imagedatum->size; ?>" width="<?php echo $imagedatum->width; ?>px" height="<?php echo $imagedatum->height; ?>px" />
</div>
<div class="thumb-name">
<?php echo JHtml::_('string.truncate', $imagedatum->name, 10, false); ?>
</div>
</a>
</li>
<?php endforeach; ?>
</ul>
*/
/**
*
*/
public function buildUnorderedList($token = null)
{
//start the ul. Ignore the 'liststyle' property
$html = '<ul id="'.$this->listingId.'" ';
//add the class
$html.= 'class="'.self::CLASS_PREFIX.'thumbs" ';
//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 files before
if ($this->get('filesposition'))
{
$html.= $this->handleFiles($this->currentFolder['relpath'], $this->currentFolder['level']);
}
if ($this->get('subfolders'))
{
$parent = $this->currentFolder['name'];
$path = $this->currentFolder['relpath'];
if ($this->currentFolder['level'] == 0)
{
$parent = '/';
}
$html.= $this->handleSubfolders($parent, $path);
}
//place the files after
if (!$this->get('filesposition'))
{
$html.= $this->handleFiles($this->currentFolder['relpath'], $this->currentFolder['level']);
}
//end the ul
$html.= '</ul>'."\n";
$html.= '<br style="clear:both;"/>'."\n";
//add modal code
$html.= $this->resetModals();
return $html;
}
/**
*
*/
protected function handleFiles($relative_path, $level, $nest = true)
{
$html = '';
$ttClass = '';
foreach ($this->files as $i => $file)
{
if ($file['relpath'] == $relative_path)
{
//format the tooltip
$ttCode = JText::_('PLG_CONTENT_EFLP_TOOLTIP_TITLE').':';
//add the full filename
$ttCode.= ' ';
$ttCode.= JText::_('PLG_CONTENT_EFLP_FILENAME_TEXT');
$ttCode.= ' '.$this->get('separator').' ';
$ttCode.= $this->acquireFilename($i);
//add the subfolder info
if ($this->get('subfoldercolumn'))
{
$ttCode.= ' | ';
$ttCode.= JText::_('PLG_CONTENT_EFLP_RELPATH_TEXT');
$ttCode.= ' '.$this->get('separator').' ';
$ttCode.= $file['relpath'];
}
//display the file size first
if ($this->get('size') && $this->get('sizefirst'))
{
$ttCode.= ' | ';
$ttCode.= JText::_('PLG_CONTENT_EFLP_SIZE_TEXT');
$ttCode.= ' '.$this->get('separator').' ';
$ttCode.= $this->readableFileSize($file['bytes']);
}
//display the date
if ($this->get('date'))
{
$ttCode.= ' | ';
$ttCode.= JText::_('PLG_CONTENT_EFLP_DATE_TEXT');
$ttCode.= ' '.$this->get('separator').' ';
//get the date type
$datetype = $this->get('datetype');
//display the date/time in human readable form
$ttCode.= $this->readableDateTime($file[$datetype]);
}
//display the file size last
if ($this->get('size') && !$this->get('sizefirst'))
{
$ttCode.= ' | ';
$ttCode.= JText::_('PLG_CONTENT_EFLP_SIZE_TEXT');
$ttCode.= ' '.$this->get('separator').' ';
$ttCode.= $this->readableFileSize($file['bytes']);
}
//start the li row tag
$html.= "\t".'<li class="thumb';
//add the tooltip code
$html.= '" title="'.htmlspecialchars($ttCode);
//close the li start tag
$html.= '">';
//Add download checkbox here
$html.= $this->addCheckbox($i);
//add icon
if ($this->files[$i]['image'])
{
//get the adjusted file size
$size = EFLPHelper::adjustSize($this->files[$i]['image']['width'], $this->files[$i]['image']['height'], $this->max_width, $this->max_height);
//get the preview image src. turn off logging.
$uri = 'index.php?option=com_easyfolderlistingpro&view=preview&format=raw&nolog=true&data='.$this->obfuscatedFileData($i);
$src = JRoute::_($uri, false);
$html.= '<div class="thumb-icon">'."\n";
$html.= "\t".'<img src="'.$src.'" alt="'.$this->files[$i]['filename'].'.'.$this->files[$i]['ext'].'" width="'.$size['width'].'px" height="'.$size['height'].'px" /> '."\n";
$html.= '</div>'."\n";
}
else
{
$html.= $this->attachFileIcon($this->files[$i]['ext']);
}
//add the filename
$html.= $this->formatFilename($i);
//Note: We do NOT offer subfoldercolumn for explorer list
// Also, we are ignoring file size and date/time for now.
//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 class="thumb">';
//Add the exclamation icon
$html.= '<div class="thumb-folder">'."\n";
$html.= '<img src="'.$this->config->get('nofilesicon_hd').'" alt="'.JText::_($this->config->get('nofilesalt')).'" width="50px" height="50px" /> ';
$html.= '</div>'."\n";
//show the empty message
$html.= "\t\t".'<div class="thumb-message">'."\n";
$html.= '<span class="'.self::CLASS_PREFIX.'empty">'.JText::_('PLG_CONTENT_EFLP_NO_FILES_NOTICE').'</span>';
$html.= "\t\t".'</div>'."\n";
//close the li tag
$html.= '</li>'."\n";
}
}
return $html;
}
/**
* Overrides the parent method. Adds the HTML code to display folder icons relating to the files
*/
protected function attachFileIcon($ext)
{
$html = '';
//check all the published icons
foreach ($this->iconsdata as $i => $icon)
{
if (stripos($icon['exts'], $ext) !== false && ValorUtilities::isUserAllowed($icon['access']))
{
//display the icon related to the file type
$html .= '<img src="'.$icon['location_hd'].'" alt="'.JText::_($icon['alt']).'" width="50px" height="50px" /> ';
break;
}
}
if (empty($html))
{
//display the default icon
$html .= '<img src="'.$this->config->get('defaulticon_hd').'" alt="'.JText::_($this->config->get('defaultalt')).'" width="50px" height="50px" /> ';
}
$html = '<div class="thumb-icon">'.$html.'</div>'."\n";
return $html;
}
/**
* Overrides the parent method. Formats the file name and links it.
*/
protected function formatFilename($index)
{
$html = '';
//get the formatted filename
$filename = $this->acquireFilename($index);
//add all the linkage
$html.= $this->formatLinks($filename, $index);
return $html;
}
/**
*
*/
protected function acquireFilename($index)
{
//format the filename with utf-8 encoding if needed
$filename = $this->fixLang($this->files[$index]['filename']);
//add the extension to the file
if ($this->get('extensions'))
{
$filename.= '.'.$this->files[$index]['ext'];
}
return $filename;
}
/**
* Overrides the parent method. The method now only links the filename.
*/
protected function formatLinks($datum, $index)
{
$html = '';
//truncate the filename
$datum = JHtml::_('string.truncate', $datum, 10, false);
//determine whether you can download or preview the file, based on its type
$canDownload = $this->validForDownload($this->files[$index]['ext']);
$canPreview = $this->validForPreview($this->files[$index]['ext']);
$html.= '<div class="thumb-name">';
//format the file name linkage
if ($this->get('preview') == 'link' && $canPreview == true)
{
$html .= $this->formatPreview($datum, $index);
}
elseif ($this->get('download') == 'link' && $canDownload == true)
{
$html .= $this->formatDownload($datum, $index);
}
elseif ($this->get('linktofiles'))
{
$html .= $this->formatPlainLink($datum, $index);
}
else
{
$html .= $datum;
}
$html.= '</div>'."\n";
$html.= '<div class="thumb-post">';
//force download with icon
if ($this->get('download') == 'icon' && $canDownload == true)
{
//generate the html img for the download icon
$icon = '<img src="'.$this->config->get('downloadicon').'" alt="'.JText::_($this->config->get('downloadalt')).'" /> ';
//make it a link
$html .= $this->formatDownload($icon, $index);
}
//preview with icon
if ($this->get('preview') == 'icon' && $canPreview == true)
{
//generate the html img for the preview icon
$icon = '<img src="'.$this->config->get('previewicon').'" alt="'.JText::_($this->config->get('previewalt')).'" /> ';
//make it a link
$html .= $this->formatPreview($icon, $index);
}
$html.= '</div>'."\n";
return $html;
}
/*
<?php if (!empty($this->state->parent)) : ?>
<?php //prepare parent value
$parent = $this->state->get('parent');
$parent = ($parent=='..') ? '' : $parent ;
?>
<li class="thumb">
<a href="index.php?option=com_easyfolderlistingpro&view=imagedialog&tmpl=component&fieldid=<?php echo $this->state->get('field.id'); ?>&folder=<?php echo rawurlencode($parent); ?>">
<div class="thumb-icon">
<span class="icon-folderup"></span>
</div>
<div class="thumb-name">
<?php echo JText::_('COM_EFLP_FOLDER_UP'); ?>
</div>
</a>
</li>
<?php endif; ?>
*/
/**
*
*/
protected function handleSubfolders($parent, $path)
{
$html = '';
//set the prefix for the framework
$jsfix = 'jqy';
if ($this->mootools)
{
$jsfix = 'moo';
}
if ($parent != '/')
{
$parent_folder = $this->findParentFolder($this->parentFolder);
$data = $this->obfuscatedFolderData($parent_folder, $this->parentFolder);
$html.= '<li class="thumb">'."\n";
$html.= "\t".'<a href="javascript:void(0);" onclick="eflp_'.$jsfix.'_explore(\''.$this->listingId.'\', \''.$data.'\');">'."\n";
$html.= "\t\t".'<div class="thumb-folder">'."\n";
$html.= "\t\t\t".'<img src="'.$this->config->get('folderupicon_hd').'" alt="'.JText::_($this->config->get('folderupalt')).'" width="50px" height="50px" /> '."\n";
$html.= "\t\t".'</div>'."\n";
$html.= "\t\t".'<div class="thumb-name">'."\n";
$html.= "\t\t\t".JText::_('PLG_CONTENT_EFLP_FOLDER_UP')."\n";
$html.= "\t\t".'</div>'."\n";
$html.= "\t".'</a>'."\n";
$html.= '</li>'."\n";
}
//Note: folders are already ordered by ascending or descending
foreach ($this->folders as $i => $dir)
{
if ($dir['parent'] == $parent && $dir['relpath'] == $path.'/'.$dir['name'])
{
$data = $this->obfuscatedFolderData($this->currentFolder, $dir);
//create the li for the subfolder name
$html.= '<li class="thumb">'."\n";
$html.= "\t".'<a href="javascript:void(0);" onclick="eflp_'.$jsfix.'_explore(\''.$this->listingId.'\', \''.$data.'\');">'."\n";
$html.= "\t\t".'<div class="thumb-folder">'."\n";
$html.= "\t\t\t".'<img src="'.$this->config->get('subfoldericon_hd').'" alt="'.JText::_($this->config->get('subfolderalt')).'" width="50px" height="50px" /> '."\n";
$html.= "\t\t".'</div>'."\n";
$html.= "\t\t".'<div class="thumb-name">'."\n";
//add the formatted subfolder name
$html.= "\t\t\t".$this->fixLang($this->folders[$i]['name'])."\n";
$html.= "\t\t".'</div>'."\n";
$html.= "\t".'</a>'."\n";
//close the li for subfolder name
$html.= '</li>'."\n";
}
}
return $html;
}
protected function findParentFolder($current)
{
//initialize the found array
$found = array(
'relpath' => '',
'level' => 0,
'name' => '',
'parent' => ''
);
$i = 0;
$stop = false;
while ($i < count($this->folders) && $stop == false)
{
$level = (int)$this->folders[$i]['level'];
$parent_level = (int)$current['level'] - 1;
if ($level == $parent_level && $this->folders[$i]['name'] == $current['parent'])
{
$found = $this->folders[$i];
$stop = true;
}
$i++;
}
return $found;
}
protected function obfuscatedFolderData($parentFolder, $currentFolder)
{
$data = array();
$data['parent'] = $parentFolder;
$data['current'] = $currentFolder;
return ValorUtilities::obfuscate($data);
}
}