| Server IP : 54.36.91.62 / Your IP : 216.73.217.111 Web Server : Apache System : Linux webm013.cluster127.gra.hosting.ovh.net 5.15.206-ovh-vps-grsec-zfs-classid #1 SMP Fri May 15 02:41:25 UTC 2026 x86_64 User : coopiak ( 151928) PHP Version : 8.3.23 Disable Function : _dyuweyrj4,_dyuweyrj4r,dl MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : OFF | Pkexec : OFF Directory : /home/coopiak/amisdesseniors-fr/components/com_jlexreview/models/ |
Upload File : |
<?php
/**
* @package JLex Review
* @version 4.2.3
* @copyright Copyright (c) 2013-2018 JLexArt. All rights reserved
* @license GNU General Public License version 2 or later;
* @author www.jlexart.com
*/
defined ( "_JEXEC" ) or die;
class JLexReviewModelOthers extends JModelLegacy
{
public $id = 0;
public $type = 1;
public function report_add()
{
$app = JFactory::getApplication();
$config = JLexReviewHelperAdmin::getConfig();
$user = JFactory::getUser();
$ip_address = JLexReviewHelperAdmin::ip_address();
$now = JFactory::getDate()->toSql();
$this->type = $this->type>0 ? 1 : 0;
if ($this->id<1 || $config->get("u_reporting",false)==false || ($this->type==1 && $config->get("enable_report","review")!="review" && $config->get("enable_report","review")!="all") || ($this->type==0 && $config->get("enable_report","review")!="comment" && $config->get("enable_report","review")!="all"))
{
return false;
}
$query = $this->_db->getQuery(true);
$query->select("*")
->from("#__jlexreview_report")
->where([
"type_ob=" . $this->_db->quote($this->type),
"type_id=" . $this->_db->quote($this->id)
]);
if($user->guest)
{
$query->where("ip_address=" . $this->_db->quote($ip_address));
} else {
$query->where("created_by=" . $this->_db->quote($user->id));
}
$row = $this->_db->setQuery($query)->loadObject();
if($row) return true;
$row = $this->getTable("report", "TableJR");
$data = array(
"type_ob" => $this->type,
"type_id" => $this->id,
"created_by" => $user->id,
"ip_address" => $ip_address,
"created" => $now,
"reason_msg" => $app->getInput()->getString("msg"),
"guest_name" => $app->getInput()->getString("name"),
"guest_email" => $config->get("report_email_field",1)==1?$app->getInput()->getString("email", ""):""
);
$row->bind($data);
// check values
if(preg_match("/^\s*$/", $row->reason_msg))
{
$this->setError(jtext::_("JR_REPORT_REASON_CONTENT"));
return false;
}
if(!$row->created_by)
{
if(preg_match("/^\s*$/", $row->guest_name))
{
$this->setError(jtext::_("JR_FILL_YOUR_NAME"));
return false;
}
if(!filter_var($row->guest_email, FILTER_VALIDATE_EMAIL) && $config->get("report_email_field",1)==1)
{
$this->setError(jtext::_("JR_EMAIL_INVALID"));
return false;
}
}
if(!$row->store())
{
$this->setError('ERROR #REPORT');
return false;
}
// send an email
if($config->get('admin_alert',0)==1 && $config->get('admin_alert_report',0)==1)
{
$emails = explode(',', $config->get('admin_alert_emails'));
if(count($emails))
{
$options = [
'caption' => jtext::_('JR_EMAIL_REPORT_SUBJECT'),
'type' => jtext::_($this->type==1?'JR_REVIEW':'JR_COMMENT'),
'id' => $this->id,
'msg' => $row->reason_msg
];
$query = $this->_db->getQuery(true);
$query->select('*')
->from('#__jlexreview'.(!$this->type?'_cm':''))
->where('id='.$this->_db->quote($this->id));
$item = $this->_db->setQuery($query)->loadObject();
if($item)
{
$options['text'] = $this->type==1?$item->title:$item->comment;
JLexReviewHelperAdmin::getAlert()->freeSend($emails, 'report', $options);
}
}
}
return true;
}
public function report_ignore()
{
$user = JFactory::getUser();
$this->type = $this->type>0 ? 1 : 0;
$ip_address = JLexReviewHelperAdmin::ip_address();
$whereClauses = array(
"type_ob=" . $this->type,
"type_id=" . $this->id
);
if($user->guest)
{
$whereClauses[] = "ip_address=" . $this->_db->quote($ip_address);
} else {
$whereClauses[] = "created_by=" . $user->id;
}
$query = $this->_db->getQuery(true);
$query->delete("#__jlexreview_report")
->where($whereClauses);
$this->_db->setQuery($query)->execute();
return $this->_db->getAffectedRows()>0 ? true : false;
}
public $val = 0;
protected function vote_update()
{
$query = $this->_db->getQuery(true);
$query->select("SUM(IF(rate_match=1,1,0)) count_help")
->select("SUM(IF(rate_match=0,1,0)) count_unhelp")
->from("#__jlexreview_helpful")
->where(array(
"type_id=" . $this->id,
"type_ob=" . $this->type
));
$result = $this->_db->setQuery($query)->loadObject();
if (!$result)
{
$count_help = 0;
$count_unhelp = 0;
} else {
$count_help = intval($result->count_help);
$count_unhelp = intval($result->count_unhelp);
}
if($this->type==1)
{
$query->clear()
->update("#__jlexreview")
->set(array(
"count_help=".$this->_db->quote($count_help),
"count_unhelp=".$this->_db->quote($count_unhelp)
))
->where("id=".$this->_db->quote($this->id));
$row = $this->getTable("Review", "TableJR");
$row->load($this->id);
if ($row->id>0 && $row->created_by>0)
{
JLexReviewHelperAdmin::updateUserParams($row->created_by);
}
} else {
$query->clear()
->update("#__jlexreview_cm")
->set(array(
"count_like=".$this->_db->quote($count_help),
"count_dislike=".$this->_db->quote($count_unhelp)
))
->where("id=".$this->_db->quote($this->id));
}
$this->_db->setQuery($query)->execute();
$response = new stdClass();
$response->count_help = $count_help;
$response->count_unhelp = $count_unhelp;
return $response;
}
public function vote()
{
if($this->id<1) return false;
$config = JLexReviewHelperAdmin::getConfig();
$ip_address = JLexReviewHelperAdmin::ip_address();
$user = JFactory::getUser();
$now = JFactory::getDate()->toSql();
$this->type = $this->type>0 ? 1:0;
// response
$response = new stdClass();
$response->id = $this->val;
$response->data = null;
if (($this->type==1 && $config->get("u_helpful_vote",true)==false) || ($this->type==0 && $config->get("u_vote_comment",true)==false))
{
return false;
}
$query = $this->_db->getQuery(true);
// self voting
if(($this->type==1 && $config->get('helpful_self',1)==0)
|| ($this->type==0 && $config->get('cm_voting_self',1)==0))
{
// disable self voting
$query->select('created_by,ip_address')
->where(array(
'id=' . $this->id,
'published=1'
));
if($this->type==1)
{
$query->from('#__jlexreview');
} else {
$query->from('#__jlexreview_cm');
}
$row = $this->_db->setQuery($query)->loadObject();
if(!$row)
{
return false;
}
if(($row->created_by>0 && $row->created_by==$user->id)
|| ($row->created_by==0 && $row->ip_address==$ip_address))
{
if($this->type==1)
{
$this->setError( JText::_("JR_CAN_NOT_VOTE_YOURSELF_REVIEW") );
} else {
$this->setError( JText::_("JR_CAN_NOT_VOTE_YOURSELF_CM") );
}
return false;
}
}
$query->clear()
->select("*")
->from("#__jlexreview_helpful")
->where( array(
"type_ob=" . $this->_db->quote($this->type),
"type_id=" . $this->_db->quote($this->id)
));
if($user->guest)
{
$query->where("ip_address=".$this->_db->quote($ip_address));
} else {
$query->where("created_by=".$user->id);
}
$result = $this->_db->setQuery($query)->loadObject();
if (!$result && $this->val==-1)
{
return $response;
}
// maximum hours to change
$hours = 24;
if($result && $result->rate_limit >=2 && (strtotime($now)-strtotime($result->created) < $hours*3600) )
{
$this->setError(JText::_("JR_TRY_THIS_FEATURE_AFTER_HOURS"));
return false;
}
switch ($this->val)
{
case -1:
case 0:
case 1:
if ($result)
{
if ($result->rate_match!=$this->val)
{
$query->clear()
->update("#__jlexreview_helpful")
->set(array(
"created=".$this->_db->quote($now),
"rate_match=". $this->_db->quote($this->val)
))
->where("id=".$this->_db->quote($result->id));
if ($result->rate_limit>=2)
{
$query->set("rate_limit=0");
} else {
$query->set("rate_limit=rate_limit+1");
}
$this->_db->setQuery($query)->execute();
$response->data = $this->vote_update();
}
} else {
$row = $this->getTable("helpful", "TableJR");
$row->bind(array(
"type_id" => $this->id,
"type_ob" => $this->type,
"rate_match" => $this->val,
"created" => $now,
"created_by" => $user->id,
"ip_address" => $ip_address
));
$row->store();
$response->data = $this->vote_update();
}
return $response;
default:
return false;
}
}
public $entry_id = 0;
protected $limit = 20;
public $offset = 0;
protected $total = 0;
public function photos()
{
if ($this->entry_id < 1)
{
return null;
}
$query = $this->_db->getQuery(true);
$query->select("SQL_CALC_FOUND_ROWS i.id,i.name,i.description,i.path,i.file_name,i.review_id")
->from("#__jlexreview_attachment i")
->select("r.title, r.rating")
->select("IF(r.created_by=0,r.author_name,u.username) author_name")
->leftJoin("#__jlexreview r ON r.id=i.review_id")
->leftJoin("#__users u ON u.id=r.created_by")
->group("i.id");
$whereClauses = array(
"i.entry_id=" . $this->entry_id,
"r.id IS NOT NULL",
"r.published=1",
"i.file_type=" . $this->_db->quote("image")
);
$query->where( $whereClauses )
->order("i.created DESC");
$photos = $this->_db->setQuery($query, $this->offset, $this->limit)->loadObjectList();
$this->total = (int) $this->_db->setQuery("SELECT FOUND_ROWS()")->loadResult();
if (!$photos)
{
return null;
}
foreach ($photos as $k=>&$photo)
{
//$photo->full = JUri::root(true) . '/' . ltrim($photo->path, '/');
$photo->full = JUri::root().'index.php?option=com_jlexreview&view=others&task=photo&n='.$photo->file_name.'&w=1000';
$photo->thumb = JUri::root().'index.php?option=com_jlexreview&view=others&task=photo&n='.$photo->file_name.'&w=350';
unset($photo->path);
unset($photo->file_name);
}
return $photos;
}
public function photoPage()
{
$return = new stdClass();
$return->offset = $this->offset;
$return->limit = $this->limit;
$return->total = $this->total;
return $return;
}
public $filename = "";
public $nwidth = 200;
public function resizePhoto()
{
$app = JFactory::getApplication();
if (empty($this->filename))
{
throw new Exception(JText::_("JR_PAGE_NOT_FOUND"), 404);
return false;
}
$path = JPATH_ROOT . "/media/jlexreview/images/" . $this->filename;
if (!is_file($path))
{
throw new Exception(JText::_("JR_PAGE_NOT_FOUND"), 404);
return false;
}
// begin resize
require_once JREVIEW_ADMIN . '/libs/class.image.php';
$resizeObj = new abeautifulsite\SimpleImage ($path);
$resizeObj->best_fit ($this->nwidth, $this->nwidth)->output();
$app->close();
}
// this function to show mini-star or criterias
public $cid = null; // json type
protected function _parseCid()
{
$cid = json_decode($this->cid);
if (!$cid || !is_array($cid) || !count($cid))
{
return false;
}
$cid_filter = array();
foreach ($cid as $item)
{
$key = $item->comp . "-" . $item->id;
if (preg_match("/^[A-z0-9\_]+$/", @$item->comp) && preg_match("/^[1-9][0-9]*$/", @$item->id))
{
$cid_filter[$key] = $item;
}
}
if (count($cid_filter))
{
$this->cid = $cid_filter;
} else {
$this->cid = null;
}
}
public function getCriterias()
{
$this->_parseCid();
if(!$this->cid) return null;
$config = JLexReviewHelperAdmin::getConfig();
$user = JFactory::getUser();
$query = $this->_db->getQuery(true);
$query->select("e.id, e.object, e.object_id, e.count_rating, e.count_review, e.rating, e.url, f.params")
->from("#__jlexreview_entry e")
->leftJoin("#__jlexreview_form f ON f.id=e.section_file")
->group('e.id');
// user voted
$query->select('IF(r.id IS NULL OR r.voting=0,0,1) AS voted')
->select('IF(r.voting=1,1,0) AS quick');
if($user->guest){
$query->leftJoin('#__jlexreview r ON (e.id=r.entry_id AND r.created_by=0 AND r.ip_address='.$this->_db->quote( JLexReviewHelperAdmin::ip_address() ).')');
} else {
$query->leftJoin('#__jlexreview r ON (e.id=r.entry_id AND r.created_by='.$this->_db->quote($user->id).')');
}
$items = [];
foreach($this->cid as $id)
{
$items[] = $this->_db->quote($id->comp . "_" . $id->id);
}
$query->where("CONCAT(object,'_',object_id) IN (". implode(",",$items) .")");
$items = $this->_db->setQuery($query)->loadObjectList();
if(!$items) return null;
foreach($items as $k=>&$entry)
{
if($config->get("link_type",0)=="1")
{
$up = JLexReviewHelperAdmin::getItemDetail($entry->object, $entry->object_id, '', $entry->url);
$entry->url = str_replace(JUri::root(true), '', $up->url);
} else {
$entry->url = urldecode($entry->url);
}
$entry->url = trim($entry->url, "/");
$entry->url = preg_match("/^https?:\/\//", $entry->url) ? $entry->url : JUri::root(true) . "/" . $entry->url;
$entry->criteria = null;
$params = json_decode($entry->params);
// unset $item->params
unset($entry->params);
if(!$params) continue;
$criteria = array();
$criteriaCid = array();
foreach ($params->fs_data as $field)
{
if ($field->type=="rating")
{
$field->total_point = 0;
$field->total_rating = 0;
$field->rating = 0;
$criteria[$field->id] = $field;
$criteriaCid[] = intval($field->id);
} else {
if (@$field->rating=="1")
{
$field->rating_data->total_point = 0;
$field->rating_data->total_rating = 0;
$field->rating_data->rating = 0;
$field->rating_data->label = $field->label;
$criteria[$field->rating_data->id] = $field->rating_data;
$criteriaCid[] = intval($field->rating_data->id);
}
}
}
if (!count($criteriaCid))
{
continue;
}
$query = $this->_db->getQuery(true);
$query->select("f.field_id id, SUM(f.field_value*1) total_point, SUM(IF(f.field_value=0,0,1)) total_rating")
->from("#__jlexreview_fields f")
->leftJoin('#__jlexreview r ON r.id=f.review_id')
->where(array(
"f.entry_id=" . $entry->id,
"f.field_id IN (".implode(",", $criteriaCid).")",
"f.field_value>0",
"r.published=1"
))
->group("f.field_id");
$result = $this->_db->setQuery($query)->loadObjectList();
if (!$result)
{
continue;
}
foreach ($result as $item)
{
if (!array_key_exists($item->id, $criteria) || $item->total_rating<=0)
{
continue;
}
$criteria[$item->id]->total_point = $item->total_point;
$criteria[$item->id]->total_rating = $item->total_rating;
$criteria[$item->id]->rating = number_format($item->total_point/$item->total_rating,1);
}
$entry->criteria = array_values($criteria);
}
return $items;
}
public function getFilterData()
{
$cid = json_decode($this->cid);
if ($this->id<1 || !$cid || !is_array($cid) || !count($cid))
{
return false;
}
$cid_filter = array();
$query = $this->_db->getQuery(true);
foreach ($cid as $item)
{
if (!isset($item->name) || !isset($item->value))
{
continue;
}
if (!preg_match('/^[A-z0-9\_\-]+$/', $item->value))
{
continue;
}
$regexSql = "'(\\\||^)" .$item->value. "(\\\||$)'";
$clause1 = "f.field_type=".$this->_db->quote("checkbox");
$clause1.= " AND f.field_id=".$this->_db->quote($item->name);
$clause1.= " AND f.field_value REGEXP ". $regexSql;
$clause2 = "(f.field_type=".$this->_db->quote("select");
$clause2.= " OR f.field_type=".$this->_db->quote("radio").")";
$clause2.= " AND f.field_id=".$this->_db->quote($item->name);
$clause2.= " AND f.field_value=". $this->_db->quote($item->value);
$query->clear()
->select("COUNT(f.id)")
->from("#__jlexreview_fields f")
->leftJoin('#__jlexreview r ON f.review_id=r.id')
->where("f.entry_id=" . $this->_db->quote($this->id))
->where("(({$clause1}) OR ({$clause2}))")
->where('r.published=1');
$result = $this->_db->setQuery($query)->loadResult();
$cid_filter[] = array(
"name" => $item->name,
"value" => $item->value,
"count" => $result?$result:0
);
}
return $cid_filter;
}
}