Skip to content

Commit

Permalink
Fix CS & phpstan issues
Browse files Browse the repository at this point in the history
  • Loading branch information
carstingaxion committed Aug 31, 2023
1 parent fa18669 commit c386ab4
Show file tree
Hide file tree
Showing 7 changed files with 156 additions and 62 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
</p>
</div>

## About
## About

![](https://raw.githubusercontent.com/figuren-theater/.github/main/assets/pagespeed-figuren.theater.svg)

Expand Down Expand Up @@ -60,7 +60,7 @@ Figuren_Theater::API\get_...()

### Plugins included

This package contains the following plugins.
This package contains the following plugins.
Thoose are completely managed by code and lack of their typical UI.

* [Cache-Control](https://github.com/carstingaxion/wordpress-cache-control)
Expand Down Expand Up @@ -107,7 +107,7 @@ who participated in this project.

## License

This project is licensed under the [GPL-3.0-or-later](LICENSE.md), see the [LICENSE](LICENSE) file for details
This project is licensed under the **GPL-3.0-or-later**, see the [LICENSE](/LICENSE) file for details

## Acknowledgments

Expand Down
1 change: 1 addition & 0 deletions assets/svg/admin-post.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 4 additions & 1 deletion inc/cache-enabler/namespace.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,13 @@ function() use ( $_options ) {
add_filter(
'cache_enabler_page_contents_before_store',
function( $html_to_save ) {
// Get secret login slug.
$login_slug = (string) getenv( 'FT_SECURITY_LOGIN_SLUG' );

// Make sure our Login-URL never lands in cache
// this also prevents the admin_bar of
// dripping into the cache for whatever reason.
$security_alert = (bool) strpos( $html_to_save, getenv( 'FT_SECURITY_LOGIN_SLUG' ) );
$security_alert = (bool) strpos( $html_to_save, $login_slug );
return ( $security_alert ) ? '' : $html_to_save;
}
);
Expand Down
6 changes: 5 additions & 1 deletion inc/namespace.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,14 @@

use Altis;

const ASSETS_URL = '/FT/ft-performance/assets/';

/**
* Register module.
*
* @return void
*/
function register() {
function register() :void {

$use_cache = defined( 'WP_CACHE' ) && constant( 'WP_CACHE' );

Expand Down
154 changes: 111 additions & 43 deletions inc/pwa/namespace.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,22 @@
namespace Figuren_Theater\Performance\PWA;

use Figuren_Theater;

use Figuren_Theater\Options;

use Figuren_Theater\Performance;
use Figuren_Theater\Theming\Themed_Login;
use FT_VENDOR_DIR;
use function add_action;
use function add_filter;
use WP_CONTENT_URL;
use function esc_url;
use function get_option;
use function get_permalink;
use function get_post;
use function get_term;
use function get_term_link;
use function get_the_excerpt;
use function get_the_title;
use function home_url;
use WPMU_PLUGIN_URL;
use WP_DEBUG;
use WP_Web_App_Manifest;

Expand Down Expand Up @@ -60,11 +68,17 @@ function load_plugin() :void {
add_filter( 'wp_service_worker_plugin_asset_caching', __NAMESPACE__ . '\\theme_asset_caching' );
add_filter( 'wp_service_worker_core_asset_caching', __NAMESPACE__ . '\\theme_asset_caching' );

// UNUSED, at the moment
// @see docblock
//
// Enable offline music.
// add_filter( 'wp_front_service_worker', __NAMESPACE__ . '\\wp_front_service_worker__offline_media' );
/**
* Enable offline media.
*
* UNUSED, at the moment
*
* @todo #25 Re-Enable offline media.
*
* @see docblock of wp_front_service_worker__offline_media()
*
* add_filter( 'wp_front_service_worker', __NAMESPACE__ . '\\wp_front_service_worker__offline_media' );
*/
}

/**
Expand All @@ -88,7 +102,30 @@ function filter_options() :void {
BASENAME,
);
}

/**
* Add the web app manifest url to the list of 'prefetch'ed ressources.
*
* The used filter: Filters domains and URLs for resource hints of relation type.
*
* @param array<int, string|array<string, string>> $urls {
* Array of resources and their attributes, or URLs to print for resource hints.
*
* @type array|string ...$0 {
* Array of resource attributes, or a URL string.
*
* @type string $href URL to include in resource hints. Required.
* @type string $as How the browser should treat the resource
* (`script`, `style`, `image`, `document`, etc).
* @type string $crossorigin Indicates the CORS policy of the specified resource.
* @type float $pr Expected probability that the resource hint will be used.
* @type string $type Type of the resource (`text/html`, `text/css`, etc).
* }
* }
* @param string $relation_type The relation type the URLs are printed for,
* e.g. 'preconnect' or 'prerender'.
*
* @return array<int, string|array<string, string>>
*/
function prefetch_manifest( array $urls, string $relation_type ) : array {

if ( ! class_exists( 'WP_Web_App_Manifest' ) ) {
Expand All @@ -102,60 +139,73 @@ function prefetch_manifest( array $urls, string $relation_type ) : array {
return $urls;
}

/**
* Overriding the (default) manifest json.
*
* There are more possible values for this, including 'orientation' and 'scope.'
* See the documentation: https://developers.google.com/web/fundamentals/web-app-manifest/
*
* @param array<string, string|array<string, string>> $manifest Data of the manifest, to send in the REST API response.
*
* @return array<string, string|array<string, string>> $manifest Data of the manifest, to send in the REST API response.
*/
function modify_manifest( array $manifest ) : array {

$manifest = __add_app_shortcuts( $manifest );
$manifest = __set_colors( $manifest );
$manifest = __set_defaults( $manifest );
$manifest = __set_screenshots( $manifest );
$manifest = set_shortcuts( $manifest );
$manifest = set_colors( $manifest );
$manifest = set_defaults( $manifest );
$manifest = set_screenshots( $manifest );

return $manifest;
}

/**
* Enables overriding the manifest json.
* Provide an app shortcut to the latest news via either the defined blog_posts page or the default_category.
*
* There are more possible values for this, including 'orientation' and 'scope.'
* See the documentation: https://developers.google.com/web/fundamentals/web-app-manifest/
* Overriding the (default) manifest json.
*
* @param array $manifest The manifest to send in the REST API response.
* @param array<string, string|array<string, string>> $manifest Data of the manifest, to send in the REST API response.
*
* @return array<string, string|array<string, string>> $manifest Data of the manifest, to send in the REST API response.
*/
function __add_app_shortcuts( array $manifest ) : array {
function set_shortcuts( array $manifest ) : array {

if ( $page_for_posts_id = \get_option( 'page_for_posts' ) ) {
$page_for_posts = \get_post( $page_for_posts_id );
$page_for_posts_id = get_option( 'page_for_posts' );
if ( \is_int( $page_for_posts_id ) && ! empty( $page_for_posts_id ) ) {
$page_for_posts = get_post( $page_for_posts_id );
if ( is_a( $page_for_posts, 'WP_Post' ) ) {
// $relative_url = str_replace(\home_url(), '', \get_permalink( $page_for_posts ));
$name = \get_the_title( $page_for_posts );
$url = \get_permalink( $page_for_posts );
$excerpt = \get_the_excerpt( $page_for_posts );
$name = get_the_title( $page_for_posts );
$url = get_permalink( $page_for_posts );
$excerpt = get_the_excerpt( $page_for_posts );
}
} else {
// try to use the default category for posts
// as the base url for any kind of news
$default_category = \get_term( \get_option( 'default_category' ), 'category' );
// Try to use the default category for posts
// as the base url for any kind of news.
$default_category = get_term( get_option( 'default_category' ), 'category' );
if ( is_a( $default_category, 'WP_Term' ) ) {
$name = $default_category->name;
$url = \get_term_link( $default_category );
$url = get_term_link( $default_category );
$excerpt = $default_category->description;
}
}

if ( $name && \esc_url( $url ) ) {
if ( $name && \is_string( $url ) && esc_url( $url ) ) {

$excerpt = ( ! empty( $excerpt ) ) ? $excerpt : __( 'News', 'figurentheater' );

$manifest['shortcuts'][] = [
'name' => $name,
// "url" => $relative_url,
'url' => $url,
'description' => $excerpt,

// Icons 2 SVG 2 data-uri
// https://icon-sets.iconify.design/dashicons/admin-post/
/**
* Icons 2 SVG 2 data-uri
*
* @see https://icon-sets.iconify.design/dashicons/admin-post/
*/
'icons' => [
[
'src' => WP_CONTENT_URL . '/mu-plugins/Figuren_Theater/assets/svg/admin-post.svg',
'src' => WPMU_PLUGIN_URL . Performance\ASSETS_URL . 'svg/admin-post.svg',
'type' => 'image/svg+xml',
'purpose' => 'any monochrome',
],
Expand All @@ -166,7 +216,16 @@ function __add_app_shortcuts( array $manifest ) : array {
return $manifest;
}

function __set_colors( array $manifest ) : array {
/**
* Provide app colors for background and theme.
*
* Overriding the (default) manifest json.
*
* @param array<string, string|array<string, string>> $manifest Data of the manifest, to send in the REST API response.
*
* @return array<string, string|array<string, string>> $manifest Data of the manifest, to send in the REST API response.
*/
function set_colors( array $manifest ) : array {
$relevant_colors = Themed_Login\ft_get_relevant_colors();

$manifest['background_color'] = $relevant_colors['ft_accent'];
Expand All @@ -176,33 +235,42 @@ function __set_colors( array $manifest ) : array {
}

/**
* Enables overriding the manifest json.
* Provide app defaults for OS integration and UI.
*
* There are more possible values for this, including 'orientation' and 'scope.'
* See the documentation: https://developers.google.com/web/fundamentals/web-app-manifest/
* Overriding the (default) manifest json.
*
* @param array $manifest The manifest to send in the REST API response.
* @param array<string, string|array<string, string>> $manifest Data of the manifest, to send in the REST API response.
*
* @return array<string, string|array<string, string>> $manifest Data of the manifest, to send in the REST API response.
*/
function __set_defaults( array $manifest ) : array {
function set_defaults( array $manifest ) : array {

$manifest['orientation'] = 'any';
$manifest['display'] = 'standalone';
$manifest['url_handler'] = [
'origin' => \home_url( '/', 'https' ),
'origin' => home_url( '/', 'https' ),
];

return $manifest;
}

function __set_screenshots( array $manifest ) : array {
/**
* Provide an app screenshot of the home-page to be shown in the install dialog.
*
* Overriding the (default) manifest json.
*
* @param array<string, string|array<string, string>> $manifest Data of the manifest, to send in the REST API response.
*
* @return array<string, string|array<string, string>> $manifest Data of the manifest, to send in the REST API response.
*/
function set_screenshots( array $manifest ) : array {

if ( ! isset( $manifest['screenshots'] ) ) {
$manifest['screenshots'] = [];
}

$manifest['screenshots'][] = [
// 'src' => \BrowserShots::get_shot( \home_url(), 900, 2000 ),
'src' => get_shot( \home_url(), 900, 2000, 'home' ),
'src' => get_shot( home_url(), 900, 2000, 'home' ),
'sizes' => '900x2000',
'type' => 'image/jpeg',
];
Expand Down
39 changes: 26 additions & 13 deletions inc/sqlite-object-cache/namespace.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,14 @@
use Figuren_Theater;
use Figuren_Theater\Options;
use function add_action;
use function add_filter;
use function current_user_can;
use function get_current_screen;
use function remove_submenu_page;
use function wp_dequeue_style;

const BASENAME = 'sqlite-object-cache/sqlite-object-cache.php';
const PLUGINPATH = WP_PLUGIN_DIR . '/' . BASENAME; // @TODO ugly hardcoded WP_CONTENT_DIR inside plugin, needs issue !!
const PLUGINPATH = BASENAME; // @TODO ugly hardcoded WP_CONTENT_DIR inside plugin, needs issue !!

/**
* Bootstrap module, when enabled.
Expand All @@ -39,15 +40,15 @@ function load_plugin() :void {

// Remove 'Activate'-Link from Plugins on the Plugin-List
// (1) is Plugin is not allowed or (2) if is PRODUCTION environment.
add_action( 'plugin_action_links', __NAMESPACE__ . '\\remove_plugin_action_links', 10, 2 );
add_action( 'network_admin_plugin_action_links', __NAMESPACE__ . '\\remove_plugin_action_links', 10, 4 );
add_filter( 'plugin_action_links', __NAMESPACE__ . '\\remove_plugin_action_links', 10, 2 );
add_filter( 'network_admin_plugin_action_links', __NAMESPACE__ . '\\remove_plugin_action_links', 10, 4 );

$config = Figuren_Theater\get_config()['modules']['performance'];
if ( ! $config['sqlite-object-cache'] ) {
return;
}

require_once PLUGINPATH; // phpcs:ignore WordPressVIPMinimum.Files.IncludingFile.UsingCustomConstant
require_once WP_PLUGIN_DIR . '/' . PLUGINPATH; // phpcs:ignore WordPressVIPMinimum.Files.IncludingFile.UsingCustomConstant

add_action( 'admin_menu', __NAMESPACE__ . '\\remove_menu', 11 );
add_action( 'admin_enqueue_scripts', __NAMESPACE__ . '\\remove_scripts', 11 );
Expand Down Expand Up @@ -94,26 +95,38 @@ function remove_menu() :void {
remove_submenu_page( 'options-general.php', 'sqlite_object_cache_settings' );
}

/**
* Remove JS, that is loaded on every wp-admin request.
*
* Still allows the loading for the admin-screen of the plugin.
*
* @return void
*/
function remove_scripts() : void {

if ( 'settings_page_sqlite_object_cache_settings' === get_current_screen()->id ) {
$current_screen = get_current_screen();
if ( \is_null( $current_screen ) ) {
return;
}

wp_dequeue_style( 'sqlite_object_cache-admin' );
if ( 'settings_page_sqlite_object_cache_settings' === $current_screen->id ) {
return;
}

wp_dequeue_style( 'sqlite_object_cache-admin' );
}

/**
* Replace 'Update' & 'Deactivate' etc. Links from the wp-admin/plugins.php list with a note on the autoloading of this plugin.
*
* @param string[] $links_array An array of plugin action links. By default this can include 'activate', 'deactivate', and 'delete'. With Multisite active this can also include 'network_active' and 'network_only' items.
* @param string $plugin_file_name Path to the plugin file relative to the plugins directory.
* @param array<string, mixed> $plugin_data Contains all the plugin meta information, like Name, Description, Author, AuthorURI etc.
* @param string $context The plugin status. It can include by default: ‘all’, ‘active’, ‘recently_activated’, ‘inactive’, ‘upgrade’, ‘dropins’, ‘mustuse’, and ‘search’.
*
* @param [string[]] $links_array An array of plugin action links. By default this can include 'activate', 'deactivate', and 'delete'. With Multisite active this can also include 'network_active' and 'network_only' items.
* @param [string] $plugin_file_name Path to the plugin file relative to the plugins directory.
* @param [Array] $plugin_data Contains all the plugin meta information, like Name, Description, Author, AuthorURI etc.
* @param [String] $context The plugin status. It can include by default: ‘all’, ‘active’, ‘recently_activated’, ‘inactive’, ‘upgrade’, ‘dropins’, ‘mustuse’, and ‘search’.
*
* @return [Array] $links_array
* @return string[] $links_array
*/
function remove_plugin_action_links( $links_array, $plugin_file_name, $plugin_data = null, $context = null ) {
function remove_plugin_action_links( array $links_array, string $plugin_file_name, array $plugin_data = null, string $context = null ) : array {

if ( BASENAME !== $plugin_file_name ) {
return $links_array;
Expand Down
Loading

0 comments on commit c386ab4

Please sign in to comment.