| Server IP : 38.190.208.107 / Your IP : 216.73.217.46 Web Server : nginx/1.28.1 System : Linux ht2026040333114 6.1.0-10-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.1.37-1 (2023-07-03) x86_64 User : root ( 0) PHP Version : 8.2.28 Disable Function : passthru,exec,system,putenv,chroot,chgrp,chown,shell_exec,popen,proc_open,pcntl_exec,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,imap_open,apache_setenv,eval,assert,passthru,system,exec,shell_exec,popen,proc_open MySQL : OFF | cURL : ON | WGET : OFF | Perl : OFF | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : /www/wwwroot/wp.3/wp-content/plugins/ewww-image-optimizer/classes/ |
Upload File : |
<?php
/**
* Class file for EwwwDB
*
* EwwwDB contains methods for working with the ewwwio_images table.
*
* @link https://ewww.io
* @package EWWW_Image_Optimizer
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/**
* DB class extension to for working with the ewwwio_images table.
*
* Provides functions needed to ensure that all data in the table is in utf8 format.
*
* @see wpdb
*/
class EwwwDB extends wpdb {
/**
* Ensures use of some variant of utf8 for interacting with the images table.
*/
public function init_charset() {
parent::init_charset();
if ( strpos( $this->charset, 'utf8' ) === false ) {
$this->charset = 'utf8';
}
}
/**
* Inserts multiple records into the table at once.
*
* Takes an associative array and creates a database record for each array item, using a single
* MySQL query. Column names are extracted from the key names of the first record.
*
* @param string $table Name of table to be used in INSERT statement.
* @param array $data Records to be inserted into table. Default none. Accepts an array of arrays,
* see example below.
* @param array $format List of formats for values in each record. Each sub-array should have the
* same number of items as $formats. Default '%s'. Accepts '%s', '%d', '%f'.
* @return int|false Number of rows affected or false on error.
*/
public function insert_multiple( $table, $data, $format ) {
if ( empty( $table ) || ! ewww_image_optimizer_iterable( $data ) || ! ewww_image_optimizer_iterable( $format ) ) {
return false;
}
/*
* Given a multi-dimensional array like so:
* array(
* [0] =>
* 'path' => '/some/image/path/here.jpg'
* 'gallery' => 'something'
* 'orig_size => 5678
* 'attachment_id => 2
* 'resize' => 'thumb'
* 'pending' => 1
* [1] =>
* 'path' => '/some/image/path/another.jpg'
* 'gallery' => 'something'
* 'orig_size => 1234
* 'attachment_id => 3
* 'resize' => 'full'
* 'pending' => 1
* )
*/
ewwwio_debug_message( 'we have records to store via ewwwdb' );
$multi_formats = array();
$values = array();
foreach ( $data as $record ) {
if ( ! ewww_image_optimizer_iterable( $record ) ) {
continue;
}
$record = $this->process_fields( $table, $record, $format );
if ( false === $record ) {
return false;
}
$formats = array();
foreach ( $record as $value ) {
if ( is_null( $value['value'] ) ) {
$formats[] = 'NULL';
continue;
}
$formats[] = $value['format'];
$values[] = $value['value'];
}
$multi_formats[] = '(' . implode( ',', $formats ) . ')';
}
$first = reset( $data );
$fields = '`' . implode( '`, `', array_keys( $first ) ) . '`';
$multi_formats = implode( ',', $multi_formats );
$this->check_current_query = false;
return $this->query( $this->prepare( "INSERT INTO `$table` ($fields) VALUES $multi_formats", $values ) );
}
}