com_extensiondistributor/admin/models/ajax.php

115 lines
4.0 KiB
PHP

<?php
/*----------------------------------------------------------------------------------| www.vdm.io |----/
Agence Agerix
/-------------------------------------------------------------------------------------------------------/
@version 1.x.x
@build 2nd June, 2022
@created 12th December, 2020
@package Extension Distributor
@subpackage ajax.php
@author Emmanuel Danan <https://agerix.fr>
@copyright Copyright (C) 2021. All Rights Reserved.
@license GNU/GPL Version 2 or later - http://www.gnu.org/licenses/gpl-2.0.html
____ _____ _____ __ __ __ __ ___ _____ __ __ ____ _____ _ _ ____ _ _ ____
(_ _)( _ )( _ )( \/ )( ) /__\ / __)( _ )( \/ )( _ \( _ )( \( )( ___)( \( )(_ _)
.-_)( )(_)( )(_)( ) ( )(__ /(__)\ ( (__ )(_)( ) ( )___/ )(_)( ) ( )__) ) ( )(
\____) (_____)(_____)(_/\/\_)(____)(__)(__) \___)(_____)(_/\/\_)(__) (_____)(_)\_)(____)(_)\_) (__)
/------------------------------------------------------------------------------------------------------*/
// No direct access to this file
defined('_JEXEC') or die('Restricted access');
use Joomla\CMS\MVC\Model\ListModel;
use Joomla\Utilities\ArrayHelper;
/**
* Extensiondistributor Ajax List Model
*/
class ExtensiondistributorModelAjax extends ListModel
{
protected $app_params;
public function __construct()
{
parent::__construct();
// get params
$this->app_params = JComponentHelper::getParams('com_extensiondistributor');
}
// Used in maintenance
public function showdir(
$dir,
$folderOnly = false,
$showRoot = false,
$level = 0, // do not use!!!
$ef = '' // do not use!!!
) {
$html = '';
if ((int) $level == 0) {
$dir = realpath($dir);
$ef = ($showRoot ? realpath($dir.'/..').'/' : $dir.'/');
}
if (!file_exists($dir))
return '';
if ($showRoot && (int) $level == 0) {
$html = '<ul id="' . $this->uid . '" class="av-folderlist level-0' . '">';
$subdir = $this->showdir($dir, $folderOnly, $showRoot, $level + 1, $ef);
$name = substr(strrchr($dir, '/'), 1);
$html .= '<li class="av-folderlist-item av-folderlist-dir">' . ($subdir ? '<span class="av-folderlist-tree"></span>' : '') . '<span class="av-folderlist-label" path="' . $name . '">' . $name . '</span>' . $subdir . '</li>';
$html .= '</ul>';
} else {
$list = scandir($dir);
if (is_array($list)) {
$list = array_diff($list, array('.', '..'));
if ($list) {
$folders = array();
$files = array();
foreach ($list as $name) {
if (is_dir($dir . DIRECTORY_SEPARATOR . $name)) {
$folders[] = $name;
} else {
$files[] = $name;
}
}
if (!($folderOnly && !$folders) || !(!$folders || !$files)) {
$html .= '<ul' . ((int) $level == 0 ? ' id="' . $this->uid . '"' : '') . ' class="' . ((int) $level == 0 ? 'av-folderlist ' : '') . 'level-' . (int) $level . '">';
}
sort($folders);
sort($files);
foreach ($folders as $name) {
$fpath = $dir.'/'.$name;
$subdir = $this->showdir($fpath, $folderOnly, $showRoot, $level + 1, $ef);
$fpath = str_replace('\\', '/', str_replace($ef, '', $fpath));
$html .= '<li class="av-folderlist-item av-folderlist-dir">' . ($subdir ? '<span class="av-folderlist-tree"></span>' : '') . '<span class="av-folderlist-label" path="' . $fpath . '">' . $name . '</span>' . $subdir . '</li>';
}
if (!$folderOnly)
foreach ($files as $name) {
$fpath = $dir.'/'.$name;
$fpath = str_replace('\\', '/', str_replace($ef, '', $fpath));
$ext = substr(strrchr($name, '.'), 1);
$html .= '<li class="av-folderlist-item av-folderlist-file' . ($ext ? ' av-folderlist-file-' . $ext : '') . '"><span class="av-folderlist-label" path="' . $fpath . '">' . $name . '</span></li>';
}
if (!($folderOnly && !$folders) || !(!$folders || !$files)) {
$html .= '</ul>';
}
unset($folders, $files, $fpath, $ext);
}
}
}
return $html;
}
}