120 lines
3.4 KiB
PHP
120 lines
3.4 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.json.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\Controller\BaseController;
|
|
use Joomla\Utilities\ArrayHelper;
|
|
|
|
/**
|
|
* Extensiondistributor Ajax Base Controller
|
|
*/
|
|
class ExtensiondistributorControllerAjax extends BaseController
|
|
{
|
|
public function __construct($config)
|
|
{
|
|
parent::__construct($config);
|
|
// make sure all json stuff are set
|
|
JFactory::getDocument()->setMimeEncoding( 'application/json' );
|
|
// get the application
|
|
$app = JFactory::getApplication();
|
|
$app->setHeader('Content-Disposition','attachment;filename="getajax.json"');
|
|
$app->setHeader('Access-Control-Allow-Origin', '*');
|
|
// load the tasks
|
|
$this->registerTask('showdir', 'ajax');
|
|
}
|
|
|
|
public function ajax()
|
|
{
|
|
// get the user for later use
|
|
$user = JFactory::getUser();
|
|
// get the input values
|
|
$jinput = JFactory::getApplication()->input;
|
|
// check if we should return raw
|
|
$returnRaw = $jinput->get('raw', false, 'BOOLEAN');
|
|
// return to a callback function
|
|
$callback = $jinput->get('callback', null, 'CMD');
|
|
// Check Token!
|
|
$token = JSession::getFormToken();
|
|
$call_token = $jinput->get('token', 0, 'ALNUM');
|
|
if($jinput->get($token, 0, 'ALNUM') || $token === $call_token)
|
|
{
|
|
// get the task
|
|
$task = $this->getTask();
|
|
switch($task)
|
|
{
|
|
case 'showdir':
|
|
try
|
|
{
|
|
$dirValue = $jinput->get('dir', NULL, 'STRING');
|
|
$folderonlyValue = $jinput->get('folderonly', false, 'BOOLEAN');
|
|
$showrootValue = $jinput->get('showroot', false, 'BOOLEAN');
|
|
$result = $this->getModel('ajax')->showdir($dirValue, $folderonlyValue, $showrootValue);
|
|
if($callback)
|
|
{
|
|
echo $callback . "(".json_encode($result).");";
|
|
}
|
|
elseif($returnRaw)
|
|
{
|
|
echo json_encode($result);
|
|
}
|
|
else
|
|
{
|
|
echo "(".json_encode($result).");";
|
|
}
|
|
}
|
|
catch(Exception $e)
|
|
{
|
|
if($callback)
|
|
{
|
|
echo $callback."(".json_encode($e).");";
|
|
}
|
|
elseif($returnRaw)
|
|
{
|
|
echo json_encode($e);
|
|
}
|
|
else
|
|
{
|
|
echo "(".json_encode($e).");";
|
|
}
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
// return to a callback function
|
|
if($callback)
|
|
{
|
|
echo $callback."(".json_encode(false).");";
|
|
}
|
|
elseif($returnRaw)
|
|
{
|
|
echo json_encode(false);
|
|
}
|
|
else
|
|
{
|
|
echo "(".json_encode(false).");";
|
|
}
|
|
}
|
|
}
|
|
}
|