Sindbad~EG File Manager
<?php
/**
* @package RSDirectory!
* @copyright (c) 2013 - 2021 RSJoomla!
* @link https://www.rsjoomla.com
* @license GNU General Public License http://www.gnu.org/licenses/gpl-3.0.en.html
*/
// No direct access.
defined('_JEXEC') or die('Restricted access');
/**
* Entry Report model.
*/
class RSDirectoryModelEntryReport extends JModelAdmin
{
/**
* Model context string.
*
* @var string
*/
protected $_context = 'com_rsdirectory.entryreport';
/**
* Method for getting the form from the model.
*
* @access public
*
* @param array $data
* @param bool $loadData
*
* @return mixed
*/
public function getForm( $data = array(), $loadData = true )
{
// Get the form.
$form = $this->loadForm( 'com_rsdirectory.entryreport', 'entryreport', array('control' => 'jform', 'load_data' => $loadData) );
if ( empty($form) )
return false;
return $form;
}
/**
* Method to get the data that should be injected in the form.
*
* @access protected
*
* @return array
*/
protected function loadFormData()
{
return JFactory::getApplication()->getUserState('com_rsdirectory.edit.entryreport.data');
}
/**
* Method to get a table object, load it if necessary.
*
* @access public
*
* @param string $type
* @param string $prefix
* @param array $config
*
* @return object
*/
public function getTable( $type = 'ReportedEntry', $prefix = 'RSDirectoryTable', $config = array() )
{
JTable::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_rsdirectory/tables');
return JTable::getInstance($type, $prefix, $config);
}
/**
* Validate form data.
*
* @access public
*
* @param object $form The form to validate against.
* @param array $data The data to validate.
* @param string $group The name of the field group to validate.
*
* @return mixed
*/
public function validate($form, $data, $group = null)
{
$app = JFactory::getApplication();
$return = $data;
if ( empty($data['entry_id']) || !( $this->entry = RSDirectoryHelper::getEntry($data['entry_id']) ) )
{
$app->enqueueMessage( JText::_('COM_RSDIRECTORY_INVALID_ENTRY_SPECIFIED'), 'error' );
$return = false;
}
$config = RSDirectoryConfig::getInstance();
// Sanitize data.
foreach ($data as &$value)
{
$value = trim($value);
}
$user = JFactory::getUser();
if ( empty($user->id) )
{
// Validate the name.
if ( empty($data['name']) )
{
$app->enqueueMessage( JText::_('COM_RSDIRECTORY_NAME_REQUIRED'), 'error' );
$return = false;
}
// Validate the email address.
if ( empty($data['email']) )
{
$app->enqueueMessage( JText::_('COM_RSDIRECTORY_EMAIL_REQUIRED'), 'error' );
$return = false;
}
else if ( !RSDirectoryHelper::email($data['email']) )
{
$app->enqueueMessage( JText::_('COM_RSDIRECTORY_PROVIDE_VALID_EMAIL'), 'error' );
$return = false;
}
}
// Validate the reason.
if ( $config->get('reporting_show_reason_dropdown') )
{
if ( empty($data['reason']) )
{
$app->enqueueMessage( JText::_('COM_RSDIRECTORY_REASON_REQUIRED'), 'error' );
$return = false;
}
else
{
$options = RSDirectoryHelper::getOptions( $config->get('reporting_reasons') );
if ( !in_array( $data['reason'], RSDirectoryHelper::getColumn($options, 'value') ) )
{
$app->enqueueMessage( JText::_('COM_RSDIRECTORY_INVALID_REASON'), 'error' );
$return = false;
}
}
}
else if ( $config->get('reporting_show_message_box') && ( empty($data['message']) || !trim($data['message']) ) )
{
$app->enqueueMessage( JText::_('COM_RSDIRECTORY_MESSAGE_REQUIRED'), 'error' );
$return = false;
}
// Use the captcha
$report_captcha = RSDirectoryHelper::checkUserPermission('report_captcha');
if ($report_captcha) {
// the captcha verification
if ( $config->get('captcha_type') == 'built_in' )
{
require_once JPATH_ADMINISTRATOR . '/components/com_rsdirectory/helpers/captcha/captcha.php';
// Initialize the CAPTCHA object.
$captcha = new RsdirectoryCaptcha('report');
$captcha->case_sensitive = $config->get('captcha_case_sensitive');
// Validate the CAPTCHA value.
if ( empty($data['captcha']) || !$captcha->check( trim($data['captcha']) ) )
{
$app->enqueueMessage( JText::_('COM_RSDIRECTORY_CAPTCHA_ERROR'), 'error' );
$return = false;
}
}
else
{
try {
$input = $app->input;
$response = $input->get('g-recaptcha-response', '', 'raw');
$ip = $input->server->get('REMOTE_ADDR');
$secretKey= $config->get('recaptcha_new_secret_key');
$http = JHttpFactory::getHttp();
if ($request = $http->get('https://www.google.com/recaptcha/api/siteverify?secret='.urlencode($secretKey).'&response='.urlencode($response).'&remoteip='.urlencode($ip))) {
$json = json_decode($request->body);
}
} catch (Exception $e) {
$app->enqueueMessage( $e->getMessage(), 'error' );
$return = false;
}
if (!$json->success) {
$app->enqueueMessage( JText::_('COM_RSDIRECTORY_RECAPTCHA_ERROR'), 'error' );
$return = false;
}
}
}
return $return;
}
/**
* Save the report.
*
* @access public
*
* @param array $data
*
* @return bool
*/
public function save($data)
{
// Exit the function if the data array is invalid.
if (!$data)
return false;
// Get the Entry Report table.
$entryreport = $this->getTable();
$entryreport->user_id = JFactory::getUser()->id;
$entryreport->ip = RSDirectoryHelper::getIp(true);
$entryreport->created_time = JFactory::getDate()->toSql();
$config = RSDirectoryConfig::getInstance();
if ($config->get('send_report_deletion_email', 1)) {
$user = JFactory::getUser();
if (empty($user->id)) {
// Add the unique token
$token = $this->getUniqueToken();
$entryreport->token = $token;
// Send the deletion URL to the specified email
// Create the URL
$uri = JUri::getInstance();
$base = $uri->toString(array('scheme', 'user', 'pass', 'host', 'port'));
$url = $base . JRoute::_('index.php?option=com_rsdirectory&task=removedata.processreport&token=' . $token, false);
// Get JConfig
$config = JFactory::getConfig();
// Try and send the mail
try
{
JFactory::getMailer()->sendMail($config->get('mailfrom'), $config->get('fromname'), $data['email'], JText::sprintf('COM_RSDIRECTORY_SEND_REPORT_DELETION_EMAIL_SUBJECT', $config->get('sitename')), JText::sprintf('COM_RSDIRECTORY_SEND_REPORT_DELETION_EMAIL_BODY', $data['name'], $url), true);
} catch(Exception $e){}
}
}
return $entryreport->save($data);
}
protected function getUniqueToken() {
// Create a token
$token = JApplicationHelper::getHash(JUserHelper::genRandomPassword(10));
// Check if already exists
$db = JFactory::getDbo();
$query = $db->getQuery(true)
->select('COUNT('.$db->qn('id').')')
->from($db->qn('#__rsdirectory_entries_reported'))
->where($db->qn('token') . ' = ' . $db->q($token));
$exists = (int)$db->setQuery($query)->loadResult();
if ($exists) {
return $this->getUniqueToken();
}
return $token;
}
/**
* Get an array of fields that should be skipped when displaying the form to the current user.
*
* @access public
*
* @return array
*/
public function getSkippedFields()
{
$config = RSDirectoryConfig::getInstance();
$skipped = array();
if ( JFactory::getUser()->id )
{
$skipped[] = 'name';
$skipped[] = 'email';
}
if ( !$config->get('reporting_show_reason_dropdown') || !trim( $config->get('reporting_reasons') ) )
{
$skipped[] = 'reason';
}
if ( !$config->get('reporting_show_message_box') )
{
$skipped[] = 'message';
}
return $skipped;
}
}
Sindbad File Manager Version 1.0, Coded By Sindbad EG ~ The Terrorists