![]() Server : Apache/2 System : Linux server-15-235-50-60 5.15.0-164-generic #174-Ubuntu SMP Fri Nov 14 20:25:16 UTC 2025 x86_64 User : gositeme ( 1004) PHP Version : 8.2.29 Disable Function : exec,system,passthru,shell_exec,proc_close,proc_open,dl,popen,show_source,posix_kill,posix_mkfifo,posix_getpwuid,posix_setpgid,posix_setsid,posix_setuid,posix_setgid,posix_seteuid,posix_setegid,posix_uname Directory : /home/gositeme/domains/gositeme.com/public_html/wp-content/plugins/fs-poster/App/Providers/ |
<?php
namespace FSPoster\App\Providers;
use wpdb;
/**
* Class DB
* @package FSPoster\App\Providers
*/
class DB
{
const PLUGIN_DB_PREFIX = 'fs_';
/**
* @return wpdb
*/
public static function DB ()
{
global $wpdb;
return $wpdb;
}
/**
* @param $tbName
*
* @return string
*/
public static function table ( $tbName )
{
return self::DB()->base_prefix . self::PLUGIN_DB_PREFIX . $tbName;
}
/**
* @param $tbName
*
* @return string
*/
public static function WPtable ( $tbName, $multisite = FALSE )
{
$multisitePrefix = '';
if ( $multisite && is_multisite() && Helper::getBlogId() > 1 )
{
$multisitePrefix = Helper::getBlogId() . '_';
}
return self::DB()->base_prefix . $multisitePrefix . $tbName;
}
/**
* @param $table
* @param null $where
*
* @return mixed
*/
public static function fetch ( $table, $where = NULL )
{
$whereQuery = '';
$argss = [];
$where = is_numeric( $where ) && $where > 0 ? [ $where ] : $where;
if ( ! empty( $where ) && is_array( $where ) )
{
$whereQuery = '';
foreach ( $where as $filed => $value )
{
$filed = $filed === 0 ? 'id' : $filed;
$whereQuery .= ( $whereQuery === '' ? '' : ' AND ' ) . $filed . '=%s';
$argss[] = (string) $value;
}
$whereQuery = ' WHERE ' . $whereQuery;
}
if ( empty( $argss ) )
{
return DB::DB()->get_row( "SELECT * FROM " . DB::table( $table ) . $whereQuery, ARRAY_A );
}
return DB::DB()->get_row( DB::DB()->prepare( "SELECT * FROM " . DB::table( $table ) . $whereQuery, $argss ), ARRAY_A );
}
/**
* @param $table
* @param null $where
*
* @return mixed
*/
public static function fetchAll ( $table, $where = NULL )
{
$whereQuery = '';
$argss = [];
$where = is_numeric( $where ) && $where > 0 ? [ $where ] : $where;
if ( ! empty( $where ) && is_array( $where ) )
{
$whereQuery = '';
foreach ( $where as $filed => $value )
{
$filed = $filed === 0 ? 'id' : $filed;
$whereQuery .= ( $whereQuery === '' ? '' : ' AND ' ) . $filed . '=%s';
$argss[] = (string) $value;
}
$whereQuery = ' WHERE ' . $whereQuery;
}
if ( empty( $argss ) )
{
return DB::DB()->get_results( "SELECT * FROM " . DB::table( $table ) . $whereQuery, ARRAY_A );
}
return DB::DB()->get_results( DB::DB()->prepare( "SELECT * FROM " . DB::table( $table ) . $whereQuery, $argss ), ARRAY_A );
}
public static function insertAll($table, $columns, $rows) {
$table = DB::table( $table );
$columnList = '`' . implode('`, `', $columns) . '`';
$sql = "INSERT INTO `$table` ($columnList) VALUES\n";
$placeholders = array();
$data = array();
while ($row = array_splice($rows, 0, 1)) {
$rowPlaceholders = array();
foreach ($row[0] as $value) {
$data[] = $value;
$rowPlaceholders[] = is_numeric($value) ? '%d' : '%s';
}
$placeholders[] = '(' . implode(', ', $rowPlaceholders) . ')';
}
$sql .= implode(",\n", $placeholders);
return self::DB()->query(self::DB()->prepare($sql, $data));
}
}