| Server IP : 195.130.67.5 / Your IP : 216.73.216.231 Web Server : Microsoft-IIS/10.0 System : Windows NT WEBSERVER1 10.0 build 17763 (Windows Server 2016) i586 User : IUSR ( 0) PHP Version : 7.4.19 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : OFF | Perl : OFF | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : C:/Old Sites/moke/administrator/components/com_imageads/ |
Upload File : |
<?php
/**
* @version $Id: controller.php
* @package ImageAds
* @author Andrey Sokolnikov <aasfalcon@gmail.com>
* @copyright (C) 2011 Emergination, LLC. All rights reserved.
* @license http://www.gnu.org/licenses/gpl-3.0.html GNU/GPL
*/
// no direct access
defined('_JEXEC') or die('Restricted access');
// parent class
jimport('joomla.application.component.controller');
/**
* Admin controller
*
* @package ImageAds
*/
class imageadsControllerAdmin extends JController
{
/**
* List of request IDs
*
* @access private
* @var array
*/
var $_cid;
/**
* Constructor
*
* @access public
* @param array $default
*/
function __construct($default = array())
{
parent::__construct($default);
$this->_cid = JRequest::getVar('cid', array(0));
JArrayHelper::toInteger($this->_cid);
}
/**
* Show ads list
*
* @access public
*/
function ad()
{
JRequest::setVar('view', 'ad');
$this->display();
}
/**
* Show ads list
*
* @access public
*/
function ads()
{
JRequest::setVar('view', 'ads');
$this->display();
}
/**
* Save and return to editor
*
* @access public
*/
function adApply()
{
$this->adSave(true);
}
/**
* Approve ad
*
* @access public
*/
function adApprove()
{
JRequest::setVar('approved', 1);
$this->adSave(false, JText::_('COM_IMAGEADS_AD_APPROVED'));
}
/**
* Unapprove ad
*
* @access public
*/
function adReject()
{
JRequest::setVar('approved', 0);
$this->adSave(false, JText::_('COM_IMAGEADS_AD_REJECTED'));
}
/**
* Save edited ad
*
* @access public
* @param bool $apply True returns to editor, false (default) to list
* @param null $success_message Message to show on success
*/
function adSave($apply = false, $success_message = null)
{
$params = JComponentHelper::getParams(IA_OPTION);
// check the form token
JRequest::checkToken() or die('Invalid token');
$model = $this->getModel('Ad');
$model->setId(JRequest::getInt('id'));
$ad = &$model->getAd();
// remember approved status change
$being_approved = !$ad->approved && JRequest::getInt('approved');
$being_rejected = $ad->approved && !JRequest::getInt('approved');
// save the ad
$success = $model->saveAd(JRequest::get('post', JREQUEST_ALLOWHTML));
$message = $success_message ?
$success_message : JText::_('COM_IMAGEADS_AD_SAVED');
$list_url = 'index.php?option='.IA_OPTION;
$record_url = $list_url . '&task=ad&cid[]='.$ad->id;
if ($success) {
// use frontend helper for upload
$lang = &JFactory::getLanguage();
$lang->load(IA_OPTION, JPATH_SITE);
require_once JPATH_COMPONENT_SITE.DS.'classes'.DS.'helper.php';
$file = JRequest::getVar('image', null, 'files');
if (!$file['error']) {
// process uploaded file
$result = imageadsHelper::uploadImage($file, $ad, true);
// redirect with error message on error
if (!$result['success']) {
$this->setRedirect($record_url, $result['message'], 'error');
return;
}
}
} else {
$message = sprintf(JText::_('COM_IMAGEADS_AD_SAVE_ERROR'), $ad->getError());
}
// disallow approval of ads without image
if ($being_approved && !$ad->image_filename) {
$being_approved = false;
JRequest::setVar('approved', $ad->approved, 'post');
JError::raiseWarning(500, JText::_('COM_IMAGEADS_CANT_APPROVE'));
$success_message = null;
}
// send approve/reject information email to the ad owner
if ($success && ($being_approved || $being_rejected)) {
// subject and body
$subject = $being_approved ?
sprintf( JText::_('COM_IMAGEADS_MAIL_APPROVED_SUBJECT'), $params->get('site_name') ) :
sprintf( JText::_('COM_IMAGEADS_MAIL_REJECTED_SUBJECT'), $params->get('site_name') );
$body = $being_approved ?
sprintf( JText::_('COM_IMAGEADS_MAIL_APPROVED_BODY'), $ad->display_url, $params->get('admin_email') ) :
sprintf( JText::_('COM_IMAGEADS_MAIL_REJECTED_BODY'), $ad->display_url, $params->get('admin_email') );
// to
$user = JFactory::getUser($ad->user_id);
// from
$config =& JFactory::getConfig();
$sender = array(
$config->getValue( 'config.mailfrom' ),
$config->getValue( 'config.fromname' ),
);
// send the message
$mailer = JFactory::getMailer();
$mailer->setSender($sender);
$mailer->addRecipient($user->email);
$mailer->setSubject($subject);
$mailer->setBody($body);
if (!$mailer->send()) {
JError::raiseWarning(500, JText::_('COM_IMAGEADS_MAIL_FAILED'));
}
}
// Clean cache
$cache = &JFactory::getCache('mod_imageads');
$cache->clean();
// redirect
$return_url = $apply || !$success ? $record_url : $list_url;
$this->setRedirect($return_url, $message,
$success ? 'message' : 'error');
}
/**
* Show configuration screen
*
* @access public
*/
function config() {
JRequest::setVar('tmpl', 'component'); //force the component template
JRequest::setVar('view', 'config');
$this->display();
}
/**
* Save component configuration
*
* @access public
*/
function configSave()
{
// check the form token
JRequest::checkToken() or die('Invalid token');
$model = $this->getModel('Config');
$model->saveParams(JRequest::get('post', JREQUEST_ALLOWHTML));
$this->config();
}
/**
* Overriden display method
*
* @param bool $cacheable
*/
function display($cacheable = false)
{
// load admin styleshit
JHTML::_('stylesheet', 'admin.css', IA_URI_ASSETS_ADMIN . 'css/');
parent::display($cacheable);
if (JRequest::getCmd('task') != 'config')
{
// display component version
echo '<div class="ia_version">'.IA_VERSION_INFO."</div>";
}
}
}