Component-Builder-fork/admin/compiler/joomla_3/BaseControllerAjax.php

81 lines
2.1 KiB
PHP
Raw Normal View History

<?php
/**
* @package Joomla.Component.Builder
*
* @created 30th April, 2015
* @author Llewellyn van der Merwe <https://dev.vdm.io>
* @git Joomla Component Builder <https://git.vdm.dev/joomla/Component-Builder>
* @copyright Copyright (C) 2015 Vast Development Method. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
// No direct access to this file
defined('_JEXEC') or die('Restricted access');
?>
###BOM###
// No direct access to this file
defined('_JEXEC') or die('Restricted access');
use Joomla\CMS\Factory;
use Joomla\CMS\MVC\Controller\BaseController;
use Joomla\CMS\Session\Session;
use Joomla\Utilities\ArrayHelper;
/**
* ###Component### Ajax Base Controller
*/
class ###Component###ControllerAjax extends BaseController
{
public function __construct($config)
{
parent::__construct($config);
// make sure all json stuff are set
Factory::getDocument()->setMimeEncoding( 'application/json' );
2021-08-31 14:00:12 +00:00
// get the application
$app = Factory::getApplication();
2021-08-31 14:00:12 +00:00
$app->setHeader('Content-Disposition','attachment;filename="getajax.json"');
$app->setHeader('Access-Control-Allow-Origin', '*');
// load the tasks ###REGISTER_AJAX_TASK###
}
public function ajax()
{
2021-08-31 14:00:12 +00:00
// get the user for later use
$user = Factory::getUser();
2021-08-31 14:00:12 +00:00
// get the input values
$jinput = Factory::getApplication()->input;
2021-08-31 14:00:12 +00:00
// check if we should return raw
$returnRaw = $jinput->get('raw', false, 'BOOLEAN');
2021-08-31 14:00:12 +00:00
// return to a callback function
$callback = $jinput->get('callback', null, 'CMD');
// Check Token!
$token = Session::getFormToken();
$call_token = $jinput->get('token', 0, 'ALNUM');
if($jinput->get($token, 0, 'ALNUM') || $token === $call_token)
{
2021-08-31 14:00:12 +00:00
// get the task
$task = $this->getTask();
switch($task)
{###AJAX_INPUT_RETURN###
}
}
else
{
2021-08-31 14:00:12 +00:00
// return to a callback function
if($callback)
{
echo $callback."(".json_encode(false).");";
}
2021-08-31 14:00:12 +00:00
elseif($returnRaw)
{
echo json_encode(false);
}
else
{
echo "(".json_encode(false).");";
}
}
}
}