| Server IP : 195.130.67.5 / Your IP : 216.73.217.154 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/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');
// controller base class
jimport('joomla.application.component.controller');
// utilites
jimport('joomla.utilities.date');
// use backend table classes
JTable::addIncludePath(JPATH_COMPONENT_ADMINISTRATOR.DS.'tables');
// helper
require_once JPATH_COMPONENT_SITE.DS.'classes'.DS.'helper.php';
/**
* ImageAds component controller
*
* @package ImageAds
*/
class imageadsController extends JController {
/**
* Display a view
*/
function display($cachable = false, $urlparams = false)
{
$document = JFactory::getDocument();
$document->addStyleSheet(IA_URI_ASSETS_SITE . 'css/frontend.css');
// Set the default view name and format from the Request.
$vName = JRequest::getCmd('view', 'default');
JRequest::setVar('view', $vName);
parent::display($cachable, $urlparams);
return $this;
}
/**
* Save newly created ad
*/
function saveAd()
{
// check the form token
JRequest::checkToken() or die('Invalid token, please refresh the page');
$table = JTable::getInstance('Ads', 'imageadsTable');
$user = JFactory::getUser();
$back_url = 'index.php?option=' . IA_OPTION . '&view=newad&data='
. base64_encode(serialize(JRequest::get('post')));
// create record
$date = new JDate();
$table->reset();
$table->link_url = JRequest::getString('link_url', null, 'post');
$table->display_url = JRequest::getString('display_url', null, 'post');
// no double quotes in alt text
$table->alt_text = str_replace('"', '\'', JRequest::getString('alt_text', null, 'post'));
$table->user_id = $user->id;
$table->created_at = $date->toMySQL();
if (!$user->id) {
$this->setRedirect($back_url, JText::_('COM_IMAGEADS_ERROR_INVALID_USER'), 'error');
$this->redirect();
}
$success = $table->check() && $table->store();
$return_url = $success ?
'index.php?option=' . IA_OPTION . '&view=addetails&id='.$table->id :
$back_url;
$this->setRedirect($return_url,
$success ? JText::_('COM_IMAGEADS_AD_CREATED') : $table->getError(),
$success ? 'message' : 'error');
}
/**
* Upload ad image
*/
function uploadImage()
{
// check the form token
JRequest::checkToken() or die('Invalid token, please refresh the page');
// get ad table
$model = &$this->getModel('AdDetails', 'imageadsModel');
$model->setId(JRequest::getInt('id', 0));
$ad = $model->getAd();
$return_url = imageadsHelper::getFullUrl(
'index.php?option=' . IA_OPTION . '&view=addetails&id=' . $ad->id);
// security: check if current user is the owner, and image is not uploaded yet
$user = &JFactory::getUser();
if ($ad->user_id != $user->id || $ad->image_filename) {
$this->setRedirect($return_url,
JText::_('COM_IMAGEADS_ERROR_ACCESS_DENIED'), 'error');
$this->redirect();
}
$message = imageadsHelper::uploadImage($file, $ad);
// process file
$file = JRequest::getVar('image', null, 'files');
$result = imageadsHelper::uploadImage($file, $ad);
// redirect with message
$this->setRedirect($return_url, $result['message'],
$result['success'] ? 'message' : 'error');
}
}