rebase code on oct-10-2023
This commit is contained in:
@@ -18,13 +18,6 @@ abstract class Imagify_Abstract_Background_Process extends Imagify_WP_Background
|
||||
*/
|
||||
protected $prefix = 'imagify';
|
||||
|
||||
/**
|
||||
* URL to query on.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $query_url = '';
|
||||
|
||||
/**
|
||||
* Set to true to automatically displatch at the end of the page.
|
||||
*
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
<?php
|
||||
|
||||
use Imagify\Traits\InstanceGetterTrait;
|
||||
use Imagify\User\User;
|
||||
|
||||
/**
|
||||
* Class that handles admin ajax/post callbacks.
|
||||
@@ -221,13 +220,13 @@ class Imagify_Admin_Ajax_Post extends Imagify_Admin_Ajax_Post_Deprecated {
|
||||
$process = imagify_get_optimization_process( $media_id, $context );
|
||||
|
||||
if ( ! $process->is_valid() ) {
|
||||
return new WP_Error( 'invalid_media', __( 'This media is not valid.', 'imagify' ) );
|
||||
return new \WP_Error( 'invalid_media', __( 'This media is not valid.', 'imagify' ) );
|
||||
}
|
||||
|
||||
$data = $process->get_data();
|
||||
|
||||
if ( ! $data->is_already_optimized() ) {
|
||||
return new WP_Error( 'not_already_optimized', __( 'This media does not have the right optimization status.', 'imagify' ) );
|
||||
return new \WP_Error( 'not_already_optimized', __( 'This media does not have the right optimization status.', 'imagify' ) );
|
||||
}
|
||||
|
||||
if ( ! $process->has_webp() ) {
|
||||
@@ -238,7 +237,7 @@ class Imagify_Admin_Ajax_Post extends Imagify_Admin_Ajax_Post_Deprecated {
|
||||
$deleted = $process->delete_webp_files();
|
||||
|
||||
if ( is_wp_error( $deleted ) ) {
|
||||
return new WP_Error( 'webp_not_deleted', __( 'Previous WebP files could not be deleted.', 'imagify' ) );
|
||||
return new \WP_Error( 'webp_not_deleted', __( 'Previous WebP files could not be deleted.', 'imagify' ) );
|
||||
}
|
||||
|
||||
return true;
|
||||
@@ -842,7 +841,7 @@ class Imagify_Admin_Ajax_Post extends Imagify_Admin_Ajax_Post_Deprecated {
|
||||
imagify_die();
|
||||
}
|
||||
|
||||
$user = new User();
|
||||
$user = new Imagify_User();
|
||||
$views = Imagify_Views::get_instance();
|
||||
$unconsumed_quota = $views->get_quota_percent();
|
||||
$message = '';
|
||||
@@ -1149,7 +1148,7 @@ class Imagify_Admin_Ajax_Post extends Imagify_Admin_Ajax_Post_Deprecated {
|
||||
imagify_die();
|
||||
}
|
||||
|
||||
$notice = htmlspecialchars( wp_unslash( $_GET['ad'] ) );
|
||||
$notice = filter_input( INPUT_GET, 'ad', FILTER_SANITIZE_STRING );
|
||||
|
||||
if ( ! $notice ) {
|
||||
imagify_maybe_redirect();
|
||||
@@ -1216,8 +1215,8 @@ class Imagify_Admin_Ajax_Post extends Imagify_Admin_Ajax_Post_Deprecated {
|
||||
* @return string
|
||||
*/
|
||||
public function get_context( $method = 'GET', $parameter = 'context' ) {
|
||||
$context = 'POST' === $method ? wp_unslash( $_POST[ $parameter ] ) : wp_unslash( $_GET[ $parameter ] ); // phpcs:ignore WordPress.Security.NonceVerification.Missing, WordPress.Security.NonceVerification.Recommended
|
||||
$context = htmlspecialchars( $context );
|
||||
$method = 'POST' === $method ? INPUT_POST : INPUT_GET;
|
||||
$context = filter_input( $method, $parameter, FILTER_SANITIZE_STRING );
|
||||
|
||||
return imagify_sanitize_context( $context );
|
||||
}
|
||||
@@ -1247,15 +1246,14 @@ class Imagify_Admin_Ajax_Post extends Imagify_Admin_Ajax_Post_Deprecated {
|
||||
*
|
||||
* @since 1.9
|
||||
*
|
||||
* @param string $method The method used: 'GET' (default), or 'POST'.
|
||||
* @param string $parameter The name of the parameter to look for.
|
||||
*
|
||||
* @param string $method The method used: 'GET' (default), or 'POST'.
|
||||
* @param string $parameter The name of the parameter to look for.
|
||||
* @return string
|
||||
*/
|
||||
public function get_folder_type( $method = 'GET', $parameter = 'folder_type' ) {
|
||||
$folder_type = 'POST' === $method ? wp_unslash( $_POST[ $parameter ] ) : wp_unslash( $_GET[ $parameter ] ); // phpcs:ignore WordPress.Security.NonceVerification.Missing, WordPress.Security.NonceVerification.Recommended
|
||||
$method = 'POST' === $method ? INPUT_POST : INPUT_GET;
|
||||
|
||||
return htmlspecialchars( $folder_type );
|
||||
return filter_input( $method, $parameter, FILTER_SANITIZE_STRING );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1263,14 +1261,13 @@ class Imagify_Admin_Ajax_Post extends Imagify_Admin_Ajax_Post_Deprecated {
|
||||
*
|
||||
* @since 1.9
|
||||
*
|
||||
* @param string $method The method used: 'GET' (default), or 'POST'.
|
||||
* @param string $parameter The name of the parameter to look for.
|
||||
*
|
||||
* @param string $method The method used: 'GET' (default), or 'POST'.
|
||||
* @param string $parameter The name of the parameter to look for.
|
||||
* @return string
|
||||
*/
|
||||
public function get_imagify_action( $method = 'GET', $parameter = 'imagify_action' ) {
|
||||
$action = 'POST' === $method ? wp_unslash( $_POST[ $parameter ] ) : wp_unslash( $_GET[ $parameter ] ); // phpcs:ignore WordPress.Security.NonceVerification.Missing, WordPress.Security.NonceVerification.Recommended
|
||||
$action = htmlspecialchars( $action );
|
||||
$method = 'POST' === $method ? INPUT_POST : INPUT_GET;
|
||||
$action = filter_input( $method, $parameter, FILTER_SANITIZE_STRING );
|
||||
|
||||
return $action ? $action : 'optimize';
|
||||
}
|
||||
|
||||
@@ -4,54 +4,62 @@ defined( 'ABSPATH' ) || die( 'Cheatin’ uh?' );
|
||||
/**
|
||||
* Class that display the "custom folders" files.
|
||||
*
|
||||
* @since 1.7
|
||||
* @package Imagify
|
||||
* @since 1.7
|
||||
* @author Grégory Viguier
|
||||
*/
|
||||
class Imagify_Files_List_Table extends WP_List_Table {
|
||||
|
||||
/**
|
||||
* Class version.
|
||||
*
|
||||
* @var string
|
||||
* @var string
|
||||
* @since 1.7
|
||||
* @author Grégory Viguier
|
||||
*/
|
||||
const VERSION = '1.1';
|
||||
|
||||
/**
|
||||
* Class version.
|
||||
*
|
||||
* @var string
|
||||
* @var string
|
||||
* @since 1.7
|
||||
* @author Grégory Viguier
|
||||
*/
|
||||
const PER_PAGE_OPTION = 'imagify_files_per_page';
|
||||
|
||||
/**
|
||||
* List of the folders containing the listed files.
|
||||
*
|
||||
* @var array
|
||||
* @since 1.7
|
||||
* @var array
|
||||
* @since 1.7
|
||||
* @author Grégory Viguier
|
||||
*/
|
||||
protected $folders = array();
|
||||
|
||||
/**
|
||||
* Filesystem object.
|
||||
*
|
||||
* @var Imagify_Filesystem
|
||||
* @since 1.7.1
|
||||
* @var object Imagify_Filesystem
|
||||
* @since 1.7.1
|
||||
* @author Grégory Viguier
|
||||
*/
|
||||
protected $filesystem;
|
||||
|
||||
/**
|
||||
* Views object.
|
||||
*
|
||||
* @var Imagify_Views
|
||||
* @since 1.9
|
||||
* @var object Imagify_Views
|
||||
* @since 1.9
|
||||
* @author Grégory Viguier
|
||||
*/
|
||||
protected $views;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @since 1.7
|
||||
* @since 1.7
|
||||
* @author Grégory Viguier
|
||||
*
|
||||
* @param array $args An associative array of arguments.
|
||||
*/
|
||||
@@ -72,7 +80,8 @@ class Imagify_Files_List_Table extends WP_List_Table {
|
||||
/**
|
||||
* Prepares the list of items for displaying.
|
||||
*
|
||||
* @since 1.7
|
||||
* @since 1.7
|
||||
* @author Grégory Viguier
|
||||
*/
|
||||
public function prepare_items() {
|
||||
global $wpdb;
|
||||
@@ -99,8 +108,8 @@ class Imagify_Files_List_Table extends WP_List_Table {
|
||||
$file_ids = array();
|
||||
$where = '';
|
||||
|
||||
$sent_orderby = isset( $_GET['orderby'] ) ? htmlspecialchars( wp_unslash( $_GET['orderby'] ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification.Missing, WordPress.Security.NonceVerification.Recommended
|
||||
$sent_order = isset( $_GET['order'] ) ? htmlspecialchars( wp_unslash( $_GET['order'] ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification.Missing, WordPress.Security.NonceVerification.Recommended
|
||||
$sent_orderby = filter_input( INPUT_GET, 'orderby', FILTER_SANITIZE_STRING );
|
||||
$sent_order = filter_input( INPUT_GET, 'order', FILTER_SANITIZE_STRING );
|
||||
$folder_filter = self::get_folder_filter();
|
||||
$status_filter = self::get_status_filter();
|
||||
|
||||
@@ -218,7 +227,8 @@ class Imagify_Files_List_Table extends WP_List_Table {
|
||||
/**
|
||||
* Message to be displayed when there are no items.
|
||||
*
|
||||
* @since 1.7
|
||||
* @since 1.7
|
||||
* @author Grégory Viguier
|
||||
*/
|
||||
public function no_items() {
|
||||
if ( self::get_status_filter() ) {
|
||||
@@ -285,7 +295,8 @@ class Imagify_Files_List_Table extends WP_List_Table {
|
||||
/**
|
||||
* Display views.
|
||||
*
|
||||
* @since 1.7
|
||||
* @since 1.7
|
||||
* @author Grégory Viguier
|
||||
*/
|
||||
public function views() {
|
||||
global $wpdb;
|
||||
@@ -401,7 +412,8 @@ class Imagify_Files_List_Table extends WP_List_Table {
|
||||
/**
|
||||
* Get an associative array ( option_name => option_title ) with the list of bulk actions available on this table.
|
||||
*
|
||||
* @since 1.7
|
||||
* @since 1.7
|
||||
* @author Grégory Viguier
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
@@ -415,7 +427,8 @@ class Imagify_Files_List_Table extends WP_List_Table {
|
||||
* Get a list of columns. The format is:
|
||||
* 'internal-name' => 'Title'
|
||||
*
|
||||
* @since 1.7
|
||||
* @since 1.7
|
||||
* @author Grégory Viguier
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
@@ -439,7 +452,8 @@ class Imagify_Files_List_Table extends WP_List_Table {
|
||||
*
|
||||
* The second format will make the initial sorting order be descending.
|
||||
*
|
||||
* @since 1.7
|
||||
* @since 1.7
|
||||
* @author Grégory Viguier
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
@@ -455,7 +469,8 @@ class Imagify_Files_List_Table extends WP_List_Table {
|
||||
/**
|
||||
* Get a column contents.
|
||||
*
|
||||
* @since 1.7
|
||||
* @since 1.7
|
||||
* @author Grégory Viguier
|
||||
*
|
||||
* @param string $column The column "name": "cb", "title", "optimization_level", etc.
|
||||
* @param object $item The current item. It must contain at least a $process property.
|
||||
@@ -474,7 +489,8 @@ class Imagify_Files_List_Table extends WP_List_Table {
|
||||
/**
|
||||
* Handles the checkbox column output.
|
||||
*
|
||||
* @since 1.7
|
||||
* @since 1.7
|
||||
* @author Grégory Viguier
|
||||
*
|
||||
* @param object $item The current item. It must contain at least a $process property.
|
||||
*/
|
||||
@@ -489,7 +505,8 @@ class Imagify_Files_List_Table extends WP_List_Table {
|
||||
/**
|
||||
* Handles the title column output.
|
||||
*
|
||||
* @since 1.7
|
||||
* @since 1.7
|
||||
* @author Grégory Viguier
|
||||
*
|
||||
* @param object $item The current item. It must contain at least a $process property.
|
||||
*/
|
||||
@@ -538,7 +555,8 @@ class Imagify_Files_List_Table extends WP_List_Table {
|
||||
/**
|
||||
* Handles the parent folder column output.
|
||||
*
|
||||
* @since 1.7
|
||||
* @since 1.7
|
||||
* @author Grégory Viguier
|
||||
*
|
||||
* @param object $item The current item. It must contain at least a $process property.
|
||||
*/
|
||||
@@ -572,7 +590,8 @@ class Imagify_Files_List_Table extends WP_List_Table {
|
||||
/**
|
||||
* Handles the optimization data column output.
|
||||
*
|
||||
* @since 1.7
|
||||
* @since 1.7
|
||||
* @author Grégory Viguier
|
||||
*
|
||||
* @param object $item The current item. It must contain at least a $process property.
|
||||
*/
|
||||
@@ -623,7 +642,8 @@ class Imagify_Files_List_Table extends WP_List_Table {
|
||||
/**
|
||||
* Handles the status column output.
|
||||
*
|
||||
* @since 1.7
|
||||
* @since 1.7
|
||||
* @author Grégory Viguier
|
||||
*
|
||||
* @param object $item The current item. It must contain at least a $process property.
|
||||
*/
|
||||
@@ -657,7 +677,8 @@ class Imagify_Files_List_Table extends WP_List_Table {
|
||||
/**
|
||||
* Handles the optimization level column output.
|
||||
*
|
||||
* @since 1.7
|
||||
* @since 1.7
|
||||
* @author Grégory Viguier
|
||||
*
|
||||
* @param object $item The current item. It must contain at least a $process property.
|
||||
*/
|
||||
@@ -672,7 +693,8 @@ class Imagify_Files_List_Table extends WP_List_Table {
|
||||
/**
|
||||
* Handles the actions column output.
|
||||
*
|
||||
* @since 1.7
|
||||
* @since 1.7
|
||||
* @author Grégory Viguier
|
||||
*
|
||||
* @param object $item The current item. It must contain at least a $process property.
|
||||
*/
|
||||
@@ -708,7 +730,8 @@ class Imagify_Files_List_Table extends WP_List_Table {
|
||||
/**
|
||||
* Prints a button to optimize the file.
|
||||
*
|
||||
* @since 1.7
|
||||
* @since 1.7
|
||||
* @author Grégory Viguier
|
||||
*
|
||||
* @param object $item The current item. It must contain at least a $process property.
|
||||
*/
|
||||
@@ -735,7 +758,8 @@ class Imagify_Files_List_Table extends WP_List_Table {
|
||||
/**
|
||||
* Prints a button to retry to optimize the file.
|
||||
*
|
||||
* @since 1.7
|
||||
* @since 1.7
|
||||
* @author Grégory Viguier
|
||||
*
|
||||
* @param object $item The current item. It must contain at least a $process property.
|
||||
*/
|
||||
@@ -765,7 +789,8 @@ class Imagify_Files_List_Table extends WP_List_Table {
|
||||
/**
|
||||
* Prints buttons to re-optimize the file to other levels.
|
||||
*
|
||||
* @since 1.7
|
||||
* @since 1.7
|
||||
* @author Grégory Viguier
|
||||
*
|
||||
* @param object $item The current item. It must contain at least a $process property.
|
||||
*/
|
||||
@@ -808,7 +833,8 @@ class Imagify_Files_List_Table extends WP_List_Table {
|
||||
/**
|
||||
* Prints a button to generate WebP versions if they are missing.
|
||||
*
|
||||
* @since 1.7
|
||||
* @since 1.7
|
||||
* @author Grégory Viguier
|
||||
*
|
||||
* @param object $item The current item. It must contain at least a $process property.
|
||||
*/
|
||||
@@ -823,7 +849,8 @@ class Imagify_Files_List_Table extends WP_List_Table {
|
||||
/**
|
||||
* Prints a button to delete WebP versions when the status is "already_optimized".
|
||||
*
|
||||
* @since 1.9.6
|
||||
* @since 1.9.6
|
||||
* @author Grégory Viguier
|
||||
*
|
||||
* @param object $item The current item. It must contain at least a $process property.
|
||||
*/
|
||||
@@ -838,7 +865,8 @@ class Imagify_Files_List_Table extends WP_List_Table {
|
||||
/**
|
||||
* Prints a button to restore the file.
|
||||
*
|
||||
* @since 1.7
|
||||
* @since 1.7
|
||||
* @author Grégory Viguier
|
||||
*
|
||||
* @param object $item The current item. It must contain at least a $process property.
|
||||
*/
|
||||
@@ -860,7 +888,8 @@ class Imagify_Files_List_Table extends WP_List_Table {
|
||||
/**
|
||||
* Prints a button to check if the file has been modified or not.
|
||||
*
|
||||
* @since 1.7
|
||||
* @since 1.7
|
||||
* @author Grégory Viguier
|
||||
*
|
||||
* @param object $item The current item. It must contain at least a $process property.
|
||||
*/
|
||||
@@ -876,7 +905,8 @@ class Imagify_Files_List_Table extends WP_List_Table {
|
||||
/**
|
||||
* Prints a button for the comparison tool (before / after optimization).
|
||||
*
|
||||
* @since 1.7
|
||||
* @since 1.7
|
||||
* @author Grégory Viguier
|
||||
*
|
||||
* @param object $item The current item. It must contain at least a $process property.
|
||||
*/
|
||||
@@ -922,7 +952,8 @@ class Imagify_Files_List_Table extends WP_List_Table {
|
||||
* Add the folder_id and folder_path properties to the $item if not set yet.
|
||||
* It may happen if the $item doesn't come from the prepare() method.
|
||||
*
|
||||
* @since 1.7
|
||||
* @since 1.7
|
||||
* @author Grégory Viguier
|
||||
*
|
||||
* @param object $item The current item. It must contain at least a $process property.
|
||||
* @return object The current item.
|
||||
@@ -957,7 +988,8 @@ class Imagify_Files_List_Table extends WP_List_Table {
|
||||
/**
|
||||
* Get the name of the default primary column.
|
||||
*
|
||||
* @since 1.7
|
||||
* @since 1.7
|
||||
* @author Grégory Viguier
|
||||
*
|
||||
* @return string Name of the default primary column, in this case, 'title'.
|
||||
*/
|
||||
@@ -968,7 +1000,8 @@ class Imagify_Files_List_Table extends WP_List_Table {
|
||||
/**
|
||||
* Get a list of CSS classes for the WP_List_Table table tag.
|
||||
*
|
||||
* @since 1.7
|
||||
* @since 1.7
|
||||
* @author Grégory Viguier
|
||||
*
|
||||
* @return array List of CSS classes for the table tag.
|
||||
*/
|
||||
@@ -979,7 +1012,8 @@ class Imagify_Files_List_Table extends WP_List_Table {
|
||||
/**
|
||||
* Allow to save the screen options when submitted by the user.
|
||||
*
|
||||
* @since 1.7
|
||||
* @since 1.7
|
||||
* @author Grégory Viguier
|
||||
*
|
||||
* @param bool|int $status Screen option value. Default false to skip.
|
||||
* @param string $option The option name.
|
||||
@@ -997,7 +1031,8 @@ class Imagify_Files_List_Table extends WP_List_Table {
|
||||
/**
|
||||
* Get the requested folder filter.
|
||||
*
|
||||
* @since 1.7
|
||||
* @since 1.7
|
||||
* @author Grégory Viguier
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
@@ -1015,7 +1050,8 @@ class Imagify_Files_List_Table extends WP_List_Table {
|
||||
/**
|
||||
* Get the requested status filter.
|
||||
*
|
||||
* @since 1.7
|
||||
* @since 1.7
|
||||
* @author Grégory Viguier
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
@@ -1031,7 +1067,7 @@ class Imagify_Files_List_Table extends WP_List_Table {
|
||||
'unoptimized' => 1,
|
||||
'errors' => 1,
|
||||
);
|
||||
$filter = isset( $_GET['status-filter'] ) ? trim( htmlspecialchars( wp_unslash( $_GET['status-filter'] ) ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification.Missing, WordPress.Security.NonceVerification.Recommended
|
||||
$filter = trim( filter_input( INPUT_GET, 'status-filter', FILTER_SANITIZE_STRING ) );
|
||||
$filter = isset( $values[ $filter ] ) ? $filter : '';
|
||||
|
||||
return $filter;
|
||||
|
||||
@@ -1,7 +1,4 @@
|
||||
<?php
|
||||
|
||||
use Imagify\User\User;
|
||||
|
||||
defined( 'ABSPATH' ) || die( 'Cheatin’ uh?' );
|
||||
|
||||
/**
|
||||
@@ -306,7 +303,7 @@ class Imagify_Requirements {
|
||||
return self::$supports['over_quota'];
|
||||
}
|
||||
|
||||
$user = new User();
|
||||
$user = new Imagify_User();
|
||||
|
||||
self::$supports['over_quota'] = $user->get_error() ? false : $user->is_over_quota();
|
||||
|
||||
|
||||
@@ -131,13 +131,10 @@ class Imagify_Settings {
|
||||
* @return bool
|
||||
*/
|
||||
public function is_form_submit() {
|
||||
if ( ! isset( $_POST['option_page'], $_POST['action'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing
|
||||
return false;
|
||||
}
|
||||
|
||||
return htmlspecialchars( wp_unslash( $_POST['option_page'] ) ) === $this->settings_group && htmlspecialchars( wp_unslash( $_POST['action'] ) ) === 'update'; // phpcs:ignore WordPress.Security.NonceVerification.Missing
|
||||
return filter_input( INPUT_POST, 'option_page', FILTER_SANITIZE_STRING ) === $this->settings_group && filter_input( INPUT_POST, 'action', FILTER_SANITIZE_STRING ) === 'update';
|
||||
}
|
||||
|
||||
|
||||
/** ----------------------------------------------------------------------------------------- */
|
||||
/** ON FORM SUBMIT ========================================================================== */
|
||||
/** ----------------------------------------------------------------------------------------- */
|
||||
|
||||
262
wp/wp-content/plugins/imagify/inc/classes/class-imagify-user.php
Normal file
262
wp/wp-content/plugins/imagify/inc/classes/class-imagify-user.php
Normal file
@@ -0,0 +1,262 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Imagify User class.
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
class Imagify_User {
|
||||
/**
|
||||
* The Imagify user ID.
|
||||
*
|
||||
* @since 1.0
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $id;
|
||||
|
||||
/**
|
||||
* The user email.
|
||||
*
|
||||
* @since 1.0
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $email;
|
||||
|
||||
/**
|
||||
* The plan ID.
|
||||
*
|
||||
* @since 1.0
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
public $plan_id;
|
||||
|
||||
/**
|
||||
* The plan label.
|
||||
*
|
||||
* @since 1.2
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $plan_label;
|
||||
|
||||
/**
|
||||
* The total quota.
|
||||
*
|
||||
* @since 1.0
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
public $quota;
|
||||
|
||||
/**
|
||||
* The total extra quota (Imagify Pack).
|
||||
*
|
||||
* @since 1.0
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
public $extra_quota;
|
||||
|
||||
/**
|
||||
* The extra quota consumed.
|
||||
*
|
||||
* @since 1.0
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
public $extra_quota_consumed;
|
||||
|
||||
/**
|
||||
* The current month consumed quota.
|
||||
*
|
||||
* @since 1.0
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
public $consumed_current_month_quota;
|
||||
|
||||
/**
|
||||
* The next month date to credit the account.
|
||||
*
|
||||
* @since 1.1.1
|
||||
*
|
||||
* @var Date
|
||||
*/
|
||||
public $next_date_update;
|
||||
|
||||
/**
|
||||
* If the account is activate or not.
|
||||
*
|
||||
* @since 1.0.1
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public $is_active;
|
||||
|
||||
/**
|
||||
* Store a \WP_Error object if the request to fetch the user data failed.
|
||||
* False overwise.
|
||||
*
|
||||
* @var bool|\WP_Error
|
||||
* @since 1.9.9
|
||||
*/
|
||||
private $error;
|
||||
|
||||
/**
|
||||
* The constructor.
|
||||
*
|
||||
* @since 1.0
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct() {
|
||||
$user = get_imagify_user();
|
||||
|
||||
if ( is_wp_error( $user ) ) {
|
||||
$this->error = $user;
|
||||
return;
|
||||
}
|
||||
|
||||
$this->id = $user->id;
|
||||
$this->email = $user->email;
|
||||
$this->plan_id = (int) $user->plan_id;
|
||||
$this->plan_label = ucfirst( $user->plan_label );
|
||||
$this->quota = $user->quota;
|
||||
$this->extra_quota = $user->extra_quota;
|
||||
$this->extra_quota_consumed = $user->extra_quota_consumed;
|
||||
$this->consumed_current_month_quota = $user->consumed_current_month_quota;
|
||||
$this->next_date_update = $user->next_date_update;
|
||||
$this->is_active = $user->is_active;
|
||||
$this->error = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the possible error returned when fetching user data.
|
||||
*
|
||||
* @since 1.9.9
|
||||
*
|
||||
* @return bool|\WP_Error A \WP_Error object if the request to fetch the user data failed. False overwise.
|
||||
*/
|
||||
public function get_error() {
|
||||
return $this->error;
|
||||
}
|
||||
|
||||
/**
|
||||
* Percentage of consumed quota, including extra quota.
|
||||
*
|
||||
* @since 1.0
|
||||
*
|
||||
* @return float|int
|
||||
*/
|
||||
public function get_percent_consumed_quota() {
|
||||
static $done = false;
|
||||
|
||||
if ( $this->get_error() ) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
$quota = $this->quota;
|
||||
$consumed_quota = $this->consumed_current_month_quota;
|
||||
|
||||
if ( imagify_round_half_five( $this->extra_quota_consumed ) < $this->extra_quota ) {
|
||||
$quota += $this->extra_quota;
|
||||
$consumed_quota += $this->extra_quota_consumed;
|
||||
}
|
||||
|
||||
if ( ! $quota || ! $consumed_quota ) {
|
||||
$percent = 0;
|
||||
} else {
|
||||
$percent = 100 * $consumed_quota / $quota;
|
||||
$percent = round( $percent, 1 );
|
||||
$percent = min( max( 0, $percent ), 100 );
|
||||
}
|
||||
|
||||
$percent = (float) $percent;
|
||||
|
||||
if ( $done ) {
|
||||
return $percent;
|
||||
}
|
||||
|
||||
$previous_percent = Imagify_Data::get_instance()->get( 'previous_quota_percent' );
|
||||
|
||||
// Percent is not 100% anymore.
|
||||
if ( 100.0 === (float) $previous_percent && $percent < 100 ) {
|
||||
/**
|
||||
* Triggered when the consumed quota percent decreases below 100%.
|
||||
*
|
||||
* @since 1.7
|
||||
* @author Grégory Viguier
|
||||
*
|
||||
* @param float|int $percent The current percentage of consumed quota.
|
||||
*/
|
||||
do_action( 'imagify_not_over_quota_anymore', $percent );
|
||||
}
|
||||
|
||||
// Percent is not >= 80% anymore.
|
||||
if ( (float) $previous_percent >= 80.0 && $percent < 80 ) {
|
||||
/**
|
||||
* Triggered when the consumed quota percent decreases below 80%.
|
||||
*
|
||||
* @since 1.7
|
||||
* @author Grégory Viguier
|
||||
*
|
||||
* @param float|int $percent The current percentage of consumed quota.
|
||||
* @param float|int $previous_percent The previous percentage of consumed quota.
|
||||
*/
|
||||
do_action( 'imagify_not_almost_over_quota_anymore', $percent, $previous_percent );
|
||||
}
|
||||
|
||||
if ( (float) $previous_percent !== (float) $percent ) {
|
||||
Imagify_Data::get_instance()->set( 'previous_quota_percent', $percent );
|
||||
}
|
||||
|
||||
$done = true;
|
||||
|
||||
return $percent;
|
||||
}
|
||||
|
||||
/**
|
||||
* Count percent of unconsumed quota.
|
||||
*
|
||||
* @since 1.0
|
||||
*
|
||||
* @return float|int
|
||||
*/
|
||||
public function get_percent_unconsumed_quota() {
|
||||
return 100 - $this->get_percent_consumed_quota();
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the user has a free account.
|
||||
*
|
||||
* @since 1.1.1
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function is_free() {
|
||||
return 1 === $this->plan_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the user has consumed all his/her quota.
|
||||
*
|
||||
* @since 1.1.1
|
||||
* @since 1.9.9 Return false if the request to fetch the user data failed.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function is_over_quota() {
|
||||
if ( $this->get_error() ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return (
|
||||
$this->is_free()
|
||||
&&
|
||||
floatval( 100 ) === round( $this->get_percent_consumed_quota() )
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,20 +1,18 @@
|
||||
<?php
|
||||
|
||||
use Imagify\User\User;
|
||||
|
||||
defined( 'ABSPATH' ) || die( 'Cheatin’ uh?' );
|
||||
|
||||
/**
|
||||
* Class that handles templates and menus.
|
||||
*
|
||||
* @since 1.7
|
||||
* @since 1.7
|
||||
* @author Grégory Viguier
|
||||
*/
|
||||
class Imagify_Views {
|
||||
|
||||
/**
|
||||
* Class version.
|
||||
*
|
||||
* @var string
|
||||
* @var string
|
||||
* @since 1.7
|
||||
*/
|
||||
const VERSION = '1.1';
|
||||
@@ -22,56 +20,64 @@ class Imagify_Views {
|
||||
/**
|
||||
* Slug used for the settings page URL.
|
||||
*
|
||||
* @var string
|
||||
* @since 1.7
|
||||
* @var string
|
||||
* @since 1.7
|
||||
* @access protected
|
||||
*/
|
||||
protected $slug_settings;
|
||||
|
||||
/**
|
||||
* Slug used for the bulk optimization page URL.
|
||||
*
|
||||
* @var string
|
||||
* @since 1.7
|
||||
* @var string
|
||||
* @since 1.7
|
||||
* @access protected
|
||||
*/
|
||||
protected $slug_bulk;
|
||||
|
||||
/**
|
||||
* Slug used for the "custom folders" page URL.
|
||||
*
|
||||
* @var string
|
||||
* @since 1.7
|
||||
* @var string
|
||||
* @since 1.7
|
||||
* @access protected
|
||||
*/
|
||||
protected $slug_files;
|
||||
|
||||
/**
|
||||
* A list of JS templates to print at the end of the page.
|
||||
*
|
||||
* @var array
|
||||
* @since 1.9
|
||||
* @var array
|
||||
* @since 1.9
|
||||
* @access protected
|
||||
*/
|
||||
protected $templates_in_footer = [];
|
||||
|
||||
/**
|
||||
* Stores the "custom folders" files list instance.
|
||||
*
|
||||
* @var Imagify_Files_List_Table
|
||||
* @since 1.7
|
||||
* @var object Imagify_Files_List_Table
|
||||
* @since 1.7
|
||||
* @access protected
|
||||
*/
|
||||
protected $list_table;
|
||||
|
||||
/**
|
||||
* Filesystem object.
|
||||
*
|
||||
* @var Imagify_Filesystem
|
||||
* @since 1.7.1
|
||||
* @var object Imagify_Filesystem
|
||||
* @since 1.7.1
|
||||
* @access protected
|
||||
* @author Grégory Viguier
|
||||
*/
|
||||
protected $filesystem;
|
||||
|
||||
/**
|
||||
* The single instance of the class.
|
||||
*
|
||||
* @var object
|
||||
* @since 1.7
|
||||
* @var object
|
||||
* @since 1.7
|
||||
* @access protected
|
||||
*/
|
||||
protected static $_instance;
|
||||
|
||||
@@ -83,7 +89,9 @@ class Imagify_Views {
|
||||
/**
|
||||
* The constructor.
|
||||
*
|
||||
* @since 1.7
|
||||
* @since 1.7
|
||||
* @author Grégory Viguier
|
||||
* @access protected
|
||||
*/
|
||||
protected function __construct() {
|
||||
$this->slug_settings = IMAGIFY_SLUG;
|
||||
@@ -95,7 +103,9 @@ class Imagify_Views {
|
||||
/**
|
||||
* Get the main Instance.
|
||||
*
|
||||
* @since 1.7
|
||||
* @since 1.7
|
||||
* @author Grégory Viguier
|
||||
* @access public
|
||||
*
|
||||
* @return object Main instance.
|
||||
*/
|
||||
@@ -110,7 +120,9 @@ class Imagify_Views {
|
||||
/**
|
||||
* Launch the hooks.
|
||||
*
|
||||
* @since 1.7
|
||||
* @since 1.7
|
||||
* @author Grégory Viguier
|
||||
* @access public
|
||||
*/
|
||||
public function init() {
|
||||
// Menu items.
|
||||
@@ -140,7 +152,9 @@ class Imagify_Views {
|
||||
/**
|
||||
* Add sub-menus for all sites.
|
||||
*
|
||||
* @since 1.7
|
||||
* @since 1.7
|
||||
* @author Grégory Viguier
|
||||
* @access public
|
||||
*/
|
||||
public function add_site_menus() {
|
||||
$wp_context = imagify_get_context( 'wp' );
|
||||
@@ -173,7 +187,9 @@ class Imagify_Views {
|
||||
/**
|
||||
* Add menu and sub-menus in the network admin when Imagify is network-activated.
|
||||
*
|
||||
* @since 1.7
|
||||
* @since 1.7
|
||||
* @author Grégory Viguier
|
||||
* @access public
|
||||
*/
|
||||
public function add_network_menus() {
|
||||
global $submenu;
|
||||
@@ -216,7 +232,9 @@ class Imagify_Views {
|
||||
/**
|
||||
* Add links to the plugin row in the plugins list.
|
||||
*
|
||||
* @since 1.7
|
||||
* @since 1.7
|
||||
* @author Grégory Viguier
|
||||
* @access public
|
||||
*
|
||||
* @param array $actions An array of action links.
|
||||
* @return array
|
||||
@@ -236,7 +254,9 @@ class Imagify_Views {
|
||||
/**
|
||||
* The main settings page.
|
||||
*
|
||||
* @since 1.7
|
||||
* @since 1.7
|
||||
* @author Grégory Viguier
|
||||
* @access public
|
||||
*/
|
||||
public function display_settings_page() {
|
||||
$this->print_template( 'page-settings' );
|
||||
@@ -245,7 +265,9 @@ class Imagify_Views {
|
||||
/**
|
||||
* The bulk optimization page.
|
||||
*
|
||||
* @since 1.7
|
||||
* @since 1.7
|
||||
* @author Grégory Viguier
|
||||
* @access public
|
||||
*/
|
||||
public function display_bulk_page() {
|
||||
$types = array();
|
||||
@@ -341,7 +363,9 @@ class Imagify_Views {
|
||||
/**
|
||||
* The page displaying the "custom folders" files.
|
||||
*
|
||||
* @since 1.7
|
||||
* @since 1.7
|
||||
* @author Grégory Viguier
|
||||
* @access public
|
||||
*/
|
||||
public function display_files_list() {
|
||||
$this->print_template( 'page-files-list' );
|
||||
@@ -350,7 +374,9 @@ class Imagify_Views {
|
||||
/**
|
||||
* Initiate the "custom folders" list table data.
|
||||
*
|
||||
* @since 1.7
|
||||
* @since 1.7
|
||||
* @author Grégory Viguier
|
||||
* @access public
|
||||
*/
|
||||
public function load_files_list() {
|
||||
// Instantiate the list.
|
||||
@@ -370,7 +396,9 @@ class Imagify_Views {
|
||||
/**
|
||||
* Get the settings page slug.
|
||||
*
|
||||
* @since 1.7
|
||||
* @since 1.7
|
||||
* @author Grégory Viguier
|
||||
* @access public
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
@@ -381,7 +409,9 @@ class Imagify_Views {
|
||||
/**
|
||||
* Get the bulk optimization page slug.
|
||||
*
|
||||
* @since 1.7
|
||||
* @since 1.7
|
||||
* @author Grégory Viguier
|
||||
* @access public
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
@@ -392,7 +422,9 @@ class Imagify_Views {
|
||||
/**
|
||||
* Get the "custom folders" files page slug.
|
||||
*
|
||||
* @since 1.7
|
||||
* @since 1.7
|
||||
* @author Grégory Viguier
|
||||
* @access public
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
@@ -408,14 +440,16 @@ class Imagify_Views {
|
||||
/**
|
||||
* Tell if we’re displaying the settings page.
|
||||
*
|
||||
* @since 1.9
|
||||
* @since 1.9
|
||||
* @author Grégory Viguier
|
||||
* @access public
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function is_settings_page() {
|
||||
global $pagenow;
|
||||
|
||||
$page = htmlspecialchars( wp_unslash( $_GET['page'] ) ); // phpcs:ignore WordPress.Security.NonceVerification.Missing, WordPress.Security.NonceVerification.Recommended
|
||||
$page = filter_input( INPUT_GET, 'page', FILTER_SANITIZE_STRING );
|
||||
|
||||
if ( $this->get_settings_page_slug() !== $page ) {
|
||||
return false;
|
||||
@@ -431,14 +465,16 @@ class Imagify_Views {
|
||||
/**
|
||||
* Tell if we’re displaying the bulk optimization page.
|
||||
*
|
||||
* @since 1.9
|
||||
* @since 1.9
|
||||
* @author Grégory Viguier
|
||||
* @access public
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function is_bulk_page() {
|
||||
global $pagenow;
|
||||
|
||||
$page = htmlspecialchars( wp_unslash( $_GET['page'] ) ); // phpcs:ignore WordPress.Security.NonceVerification.Missing, WordPress.Security.NonceVerification.Recommended
|
||||
$page = filter_input( INPUT_GET, 'page', FILTER_SANITIZE_STRING );
|
||||
|
||||
return 'upload.php' === $pagenow && $this->get_bulk_page_slug() === $page;
|
||||
}
|
||||
@@ -446,14 +482,16 @@ class Imagify_Views {
|
||||
/**
|
||||
* Tell if we’re displaying the custom files list page.
|
||||
*
|
||||
* @since 1.9
|
||||
* @since 1.9
|
||||
* @author Grégory Viguier
|
||||
* @access public
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function is_files_page() {
|
||||
global $pagenow;
|
||||
|
||||
$page = htmlspecialchars( wp_unslash( $_GET['page'] ) ); // phpcs:ignore WordPress.Security.NonceVerification.Missing, WordPress.Security.NonceVerification.Recommended
|
||||
$page = filter_input( INPUT_GET, 'page', FILTER_SANITIZE_STRING );
|
||||
|
||||
return 'upload.php' === $pagenow && $this->get_files_page_slug() === $page;
|
||||
}
|
||||
@@ -461,20 +499,26 @@ class Imagify_Views {
|
||||
/**
|
||||
* Tell if we’re displaying the WP media library page.
|
||||
*
|
||||
* @since 1.9
|
||||
* @since 1.9
|
||||
* @author Grégory Viguier
|
||||
* @access public
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function is_wp_library_page() {
|
||||
global $pagenow;
|
||||
|
||||
return 'upload.php' === $pagenow && ! isset( $_GET['page'] ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended
|
||||
$page = filter_input( INPUT_GET, 'page', FILTER_SANITIZE_STRING );
|
||||
|
||||
return 'upload.php' === $pagenow && ! $page;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tell if we’re displaying a media page.
|
||||
*
|
||||
* @since 1.9
|
||||
* @since 1.9
|
||||
* @author Grégory Viguier
|
||||
* @access public
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
@@ -492,7 +536,9 @@ class Imagify_Views {
|
||||
/**
|
||||
* Get the remaining quota in percent.
|
||||
*
|
||||
* @since 1.8.1
|
||||
* @since 1.8.1
|
||||
* @author Grégory Viguier
|
||||
* @access public
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
@@ -503,7 +549,7 @@ class Imagify_Views {
|
||||
return $quota;
|
||||
}
|
||||
|
||||
$user = new User();
|
||||
$user = new Imagify_User();
|
||||
$quota = $user->get_percent_unconsumed_quota();
|
||||
|
||||
return $quota;
|
||||
@@ -512,7 +558,9 @@ class Imagify_Views {
|
||||
/**
|
||||
* Get the HTML class used for the quota (to change the color when out of quota for example).
|
||||
*
|
||||
* @since 1.8.1
|
||||
* @since 1.8.1
|
||||
* @author Grégory Viguier
|
||||
* @access public
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
@@ -540,7 +588,9 @@ class Imagify_Views {
|
||||
/**
|
||||
* Get the HTML tag used for the quota (the weather-like icon).
|
||||
*
|
||||
* @since 1.8.1
|
||||
* @since 1.8.1
|
||||
* @author Grégory Viguier
|
||||
* @access public
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
@@ -572,7 +622,9 @@ class Imagify_Views {
|
||||
/**
|
||||
* Get a template contents.
|
||||
*
|
||||
* @since 1.7
|
||||
* @since 1.7
|
||||
* @author Grégory Viguier
|
||||
* @access public
|
||||
*
|
||||
* @param string $template The template name.
|
||||
* @param mixed $data Some data to pass to the template.
|
||||
@@ -596,7 +648,9 @@ class Imagify_Views {
|
||||
/**
|
||||
* Print a template.
|
||||
*
|
||||
* @since 1.7
|
||||
* @since 1.7
|
||||
* @author Grégory Viguier
|
||||
* @access public
|
||||
*
|
||||
* @param string $template The template name.
|
||||
* @param mixed $data Some data to pass to the template.
|
||||
@@ -608,7 +662,9 @@ class Imagify_Views {
|
||||
/**
|
||||
* Add a template to the list of JS templates to print at the end of the page.
|
||||
*
|
||||
* @since 1.7
|
||||
* @since 1.7
|
||||
* @author Grégory Viguier
|
||||
* @access public
|
||||
*
|
||||
* @param string $template The template name.
|
||||
*/
|
||||
@@ -635,7 +691,9 @@ class Imagify_Views {
|
||||
/**
|
||||
* Print the JS templates that have been added to the "queue".
|
||||
*
|
||||
* @since 1.9
|
||||
* @since 1.9
|
||||
* @author Grégory Viguier
|
||||
* @access public
|
||||
*/
|
||||
public function print_js_templates() {
|
||||
if ( ! $this->templates_in_footer ) {
|
||||
@@ -659,7 +717,9 @@ class Imagify_Views {
|
||||
/**
|
||||
* Create HTML attributes from an array.
|
||||
*
|
||||
* @since 1.9
|
||||
* @since 1.9
|
||||
* @access public
|
||||
* @author Grégory Viguier
|
||||
*
|
||||
* @param array $attributes A list of attribute pairs.
|
||||
* @return string HTML attributes.
|
||||
|
||||
Reference in New Issue
Block a user