| Current Path : /var/www/html/administrator/components/com_jdonation/controller/ |
| Current File : /var/www/html/administrator/components/com_jdonation/controller/controller.php |
<?php
use Joomla\CMS\Updater\Updater;
use Joomla\CMS\MVC\Model\BaseDatabaseModel;
/**
* @version 4.3
* @package Joomla
* @subpackage Joom Donation
* @author Tuan Pham Ngoc
* @copyright Copyright (C) 2009 - 2022 Ossolution Team
* @license GNU/GPL, see LICENSE.php
*/
// Check to ensure this file is included in Joomla!
defined('_JEXEC') or die('Restricted access');
use Joomla\CMS\Component\ComponentHelper;
use Joomla\CMS\Factory;
use Joomla\CMS\Language\Text;
use Joomla\CMS\Uri\Uri;
class DonationController extends OSFControllerAdmin
{
/**
* Display information
*/
function display($cachable = false, array $urlparams = Array())
{
Factory::getDocument()->addStyleSheet(Uri::base(true) . '/components/com_jdonation/assets/css/style.css');
if (version_compare(JVERSION, '4.0.0-dev', 'ge'))
{
Factory::getDocument()->addStyleSheet(Uri::base(true) . '/components/com_jdonation/assets/css/style4.css');
}
if (version_compare(JVERSION, '3.0', 'lt'))
{
DonationHelper::loadBootstrap();
}
parent::display($cachable, $urlparams);
if ($this->input->getCmd('format', 'html') == 'html')
{
DonationHelper::displayCopyRight();
}
}
public function download_file()
{
$filePath = 'media/com_jdonation/files';
$fileName = $this->input->get('file_name', '', 'none');
if (file_exists(JPATH_ROOT . '/' . $filePath . '/' . $fileName))
{
while (@ob_end_clean()) ;
DonationHelper::processDownload(JPATH_ROOT . '/' . $filePath . '/' . $fileName, $fileName);
exit();
}
else
{
$this->app->enqueueMessage(Text::_('JD_FILE_NOT_EXIST'));
$this->app->redirect('index.php?option=com_jdonation');
}
}
public function upgrade()
{
require_once JPATH_COMPONENT . '/install.jdonation.php';
com_jdonationInstallerScript::updateDatabaseSchema();
}
/**
* Check to see the installed version is up to date or not
*
* @return int 0 : error, 1 : Up to date, 2 : outof date
*/
public function check_update()
{
$component = ComponentHelper::getComponent('com_installer');
$params = $component->params;
$cache_timeout = (int) $params->get('cachetimeout', 6);
$cache_timeout = 3600 * $cache_timeout;
// Get the minimum stability.
$minimum_stability = (int) $params->get('minimum_stability', Updater::STABILITY_STABLE);
if (DonationHelper::isJoomla4())
{
/* @var \Joomla\Component\Installer\Administrator\Model\UpdateModel $model */
$model = $this->app->bootComponent('com_installer')->getMVCFactory()
->createModel('Update', 'Administrator', ['ignore_request' => true]);
}
else
{
BaseDatabaseModel::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_installer/models');
/** @var InstallerModelUpdate $model */
$model = BaseDatabaseModel::getInstance('Update', 'InstallerModel');
}
$model->purge();
$db = Factory::getDbo();
$document = Factory::getDocument();
$installedVersion = DonationHelper::getInstalledVersion();
$db = Factory::getDbo();
$query = $db->getQuery(true);
$query->select('extension_id')
->from('#__extensions')
->where('`type` = "package"')
->where('`element` = "pkg_joomdonation"');
$db->setQuery($query);
$eid = (int) $db->loadResult();
$result['status'] = 0;
if ($eid)
{
$ret = Updater::getInstance()->findUpdates($eid, $cache_timeout, $minimum_stability);
if ($ret)
{
$model->setState('list.start', 0);
$model->setState('list.limit', 0);
$model->setState('filter.extension_id', $eid);
$updates = $model->getItems();
$result['status'] = 2;
if (count($updates))
{
$style = '#update-check span{
font-weight:bold;
color:red;
}';
$result['status'] = 2;
$result['message'] = Text::sprintf('JD_UPDATE_CHECKING_UPDATEFOUND', $updates[0]->version);
}
else
{
$style = '#update-check span{
font-weight:bold;
color:green;
}';
$result['status'] = 2;
$result['message'] = Text::sprintf('JD_UPDATE_CHECKING_UPDATEFOUND', null);
}
}
else
{
$style = '#update-check span{
font-weight:bold;
color:green;
}';
$document->addStyleDeclaration($style);
$result['status'] = 1;
$result['message'] = Text::_('JD_UPDATE_CHECKING_UPTODATE');
}
}
echo json_encode($result);
Factory::getApplication()->close();
}
}