<?php
/**
 * @package         ReReplacer
 * @version         12.4.0PRO
 * 
 * @author          Peter van Westen <info@regularlabs.com>
 * @link            http://regularlabs.com
 * @copyright       Copyright © 2022 Regular Labs All Rights Reserved
 * @license         http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL
 */

namespace RegularLabs\Plugin\System\ReReplacer;

defined('_JEXEC') or die;


use RegularLabs\Component\Conditions\Administrator\Api\Conditions as Api_Conditions;
use RegularLabs\Library\RegEx as RL_RegEx;

class Conditions
{
    public static function itemPass($item, $article = null)
    {
        $pass = (new Api_Conditions($article))
            ->setConditionByExtensionItem('com_rereplacer', $item->id)
            ->pass();

        if ( ! $pass && $item->other_doreplace)
        {
            $item->replace = $item->other_replace;
            // replace \n with newline
            $item->replace = RL_RegEx::replace('(?<!\\\)\\\n', "\n", $item->other_replace);

            $pass = true;
        }

        return $pass ? $item : false;
    }
}
