rebase code on oct-10-2023

This commit is contained in:
Rachit Bhargava
2023-10-10 17:51:46 -04:00
parent b16ad94b69
commit 8f1a2c3a66
2197 changed files with 184921 additions and 35568 deletions

View File

@@ -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 were 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 were 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 were 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 were 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 were 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.