Skip to content

MslsCustomFilter class tested #307

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions includes/MslsBlogCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ public function __construct() {
$this->objects[ $blog->userblog_id ] = new MslsBlog( $blog, $description );
}
}

uasort( $this->objects, array( MslsBlog::class, $this->objects_order ) );
}
}
Expand All @@ -109,7 +110,7 @@ public function __construct() {
*
* @return string|bool
*/
public static function get_configured_blog_description( $blog_id, $description = false ) {
public static function get_configured_blog_description( int $blog_id, $description = false ) {
if ( $description ) {
return $description;
}
Expand Down Expand Up @@ -138,7 +139,8 @@ public function get_blogs_of_reference_user( MslsOptions $options ) {
1
)
);
$blogs = get_blogs_of_user( $reference_user );

$blogs = get_blogs_of_user( $reference_user );

/**
* @todo Check if this is still useful
Expand Down Expand Up @@ -229,10 +231,21 @@ public function get_current_blog() {
*
* @return MslsBlog[]
*/
public function get_objects() {
public function get_objects(): array {
return apply_filters( 'msls_blog_collection_get_objects', $this->objects );
}

/**
* Gets a specific blog-object
*
* @param int $blog_id
*
* @return ?MslsBlog
*/
public function get_object( int $blog_id ): ?MslsBlog {
return $this->get_objects()[ $blog_id ] ?? null;
}

/**
* Is plugin active in the blog with that blog_id
*
Expand Down
16 changes: 8 additions & 8 deletions includes/MslsContentTypes.php
Original file line number Diff line number Diff line change
@@ -1,29 +1,27 @@
<?php
/**
* MslsContentTypes
* @author Dennis Ploetner <[email protected]>
* @since 0.9.8
*/

namespace lloc\Msls;

/**
* Supported content types
*
* @package Msls
*/
abstract class MslsContentTypes extends MslsRegistryInstance {

/**
* Request
*
* @var string
*/
protected $request;

/**
* Types
*
* @var array
*/
protected $types = [];
protected $types = array();

/**
* Factory method
Expand All @@ -33,13 +31,14 @@ abstract class MslsContentTypes extends MslsRegistryInstance {
* @return MslsContentTypes
*/
public static function create() {
$_request = MslsPlugin::get_superglobals( [ 'taxonomy' ] );
$_request = MslsPlugin::get_superglobals( array( 'taxonomy' ) );

return '' != $_request['taxonomy'] ? MslsTaxonomy::instance() : MslsPostType::instance();
}

/**
* Check for post_type
*
* @return bool
*/
public function is_post_type() {
Expand All @@ -48,6 +47,7 @@ public function is_post_type() {

/**
* Check for taxonomy
*
* @return bool
*/
public function is_taxonomy() {
Expand All @@ -68,6 +68,7 @@ public function acl_request() {

/**
* Getter
*
* @return array
*/
abstract public static function get(): array;
Expand All @@ -78,5 +79,4 @@ abstract public static function get(): array;
* @return string
*/
abstract public function get_request(): string;

}
21 changes: 8 additions & 13 deletions includes/MslsCustomColumn.php
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
<?php
/**
* MslsCustomColumn
* @author Dennis Ploetner <[email protected]>
* @since 0.9.8
*/

namespace lloc\Msls;

/**
* Handling of existing/not existing translations in the backend listings of
* various post types
*
* @package Msls
*/
class MslsCustomColumn extends MslsMain {
Expand All @@ -30,9 +26,9 @@ public static function init() {
$post_type = MslsPostType::instance()->get_request();

if ( ! empty( $post_type ) ) {
add_filter( "manage_{$post_type}_posts_columns", [ $obj, 'th' ] );
add_action( "manage_{$post_type}_posts_custom_column", [ $obj, 'td' ], 10, 2 );
add_action( 'trashed_post', [ $obj, 'delete' ] );
add_filter( "manage_{$post_type}_posts_columns", array( $obj, 'th' ) );
add_action( "manage_{$post_type}_posts_custom_column", array( $obj, 'td' ), 10, 2 );
add_action( 'trashed_post', array( $obj, 'delete' ) );
}
}

Expand All @@ -53,11 +49,11 @@ public function th( $columns ) {
foreach ( $blogs as $blog ) {
$language = $blog->get_language();

$icon_type= $this->options->admin_display === 'label' ? 'label' : 'flag';
$icon_type = $this->options->admin_display === 'label' ? 'label' : 'flag';

$icon = new MslsAdminIcon( null );
$icon = new MslsAdminIcon( null );
$icon->set_language( $language );
$icon->set_icon_type( $icon_type );
$icon->set_icon_type( $icon_type );

if ( $post_id = get_the_ID() ) {
$icon->set_id( $post_id );
Expand All @@ -78,7 +74,7 @@ public function th( $columns ) {
* Table body
*
* @param string $column_name
* @param int $item_id
* @param int $item_id
*
* @codeCoverageIgnore
*/
Expand Down Expand Up @@ -113,5 +109,4 @@ public function td( $column_name, $item_id ) {
}
}
}

}
15 changes: 5 additions & 10 deletions includes/MslsCustomColumnTaxonomy.php
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
<?php
/**
* MslsCustomColumnTaxonomy
* @author Dennis Ploetner <[email protected]>
* @since 0.9.8
*/

namespace lloc\Msls;

/**
* Handling of existing/not existing translations in the backend
* listings of various taxonomies
*
* @package Msls
*/
class MslsCustomColumnTaxonomy extends MslsCustomColumn {
Expand All @@ -30,9 +26,9 @@ public static function init() {
$taxonomy = MslsTaxonomy::instance()->get_request();

if ( ! empty( $taxonomy ) ) {
add_filter( "manage_edit-{$taxonomy}_columns", [ $obj, 'th' ] );
add_action( "manage_{$taxonomy}_custom_column", [ $obj, 'column_default' ], - 100, 3 );
add_action( "delete_{$taxonomy}", [ $obj, 'delete' ] );
add_filter( "manage_edit-{$taxonomy}_columns", array( $obj, 'th' ) );
add_action( "manage_{$taxonomy}_custom_column", array( $obj, 'column_default' ), - 100, 3 );
add_action( "delete_{$taxonomy}", array( $obj, 'delete' ) );
}
}

Expand All @@ -44,7 +40,7 @@ public static function init() {
*
* @param string $deprecated
* @param string $column_name
* @param int $item_id
* @param int $item_id
*/
public function column_default( $deprecated, $column_name, $item_id ) {
$this->td( $column_name, $item_id );
Expand All @@ -60,5 +56,4 @@ public function column_default( $deprecated, $column_name, $item_id ) {
public function delete( $object_id ) {
$this->save( $object_id, MslsOptionsTax::class );
}

}
14 changes: 7 additions & 7 deletions includes/MslsCustomFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public function add_filter(): void {
$id = (
filter_has_var( INPUT_GET, 'msls_filter' ) ?
filter_input( INPUT_GET, 'msls_filter', FILTER_SANITIZE_NUMBER_INT ) :
''
'0'
);

$blogs = $this->collection->get();
Expand All @@ -54,7 +54,7 @@ public function add_filter(): void {
printf(
'<option value="%d" %s>%s</option>',
$blog->userblog_id,
selected( $id, $blog->userblog_id, false ),
selected( intval( $id ), $blog->userblog_id, false ),
sprintf(
__( 'Not translated in the %s-blog', 'multisite-language-switcher' ),
$blog->get_description()
Expand All @@ -73,18 +73,18 @@ public function add_filter(): void {
* @return bool|\WP_Query
*/
public function execute_filter( \WP_Query $query ) {
$blogs = $this->collection->get();

if ( ! filter_has_var( INPUT_GET, 'msls_filter' ) ) {
return false;
}

$id = filter_input( INPUT_GET, 'msls_filter', FILTER_SANITIZE_NUMBER_INT );
if ( isset( $blogs[ $id ] ) ) {
$id = filter_input( INPUT_GET, 'msls_filter', FILTER_SANITIZE_NUMBER_INT );
$blog = $this->collection->get_object( intval( $id ) );

if ( $blog ) {
$sql_cache = MslsSqlCacher::create( __CLASS__, __METHOD__ );

// load post we need to exclude (they already have a translation) from search query
$translated_posts = ( new TranslatedPostsQuery( $sql_cache ) )( $blogs[ $id ]->get_language() );
$translated_posts = ( new TranslatedPostsQuery( $sql_cache ) )( $blog->get_language() );

$exclude_ids = array();
foreach ( $translated_posts as $post ) {
Expand Down
6 changes: 0 additions & 6 deletions includes/MslsGetSet.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
<?php
/**
* MslsGetSet
*
* @author Dennis Ploetner <[email protected]>
* @since 0.9.8
*/

namespace lloc\Msls;

Expand Down
16 changes: 6 additions & 10 deletions includes/MslsJson.php
Original file line number Diff line number Diff line change
@@ -1,24 +1,21 @@
<?php
/**
* MslsJson
* @author Dennis Ploetner <[email protected]>
* @since 0.9.9
*/

namespace lloc\Msls;

/**
* Container for an array which will used in JavaScript as object in JSON
*
* @example https://gist.githubusercontent.com/lloc/2c232cef3f910acf692f/raw/1c4f62e1de57ca48f19c37e3a63e7dc311b76b2f/MslsJson.php
* @package Msls
*/
class MslsJson {

/**
* Container
*
* @var array
*/
protected array $arr = [];
protected array $arr = array();

/** MslsLanguageArray
* Adds a value label pair to the internal class container
Expand All @@ -29,10 +26,10 @@ class MslsJson {
* @return MslsJson
*/
public function add( $value, $label ) {
$this->arr[] = [
$this->arr[] = array(
'value' => intval( $value ),
'label' => strval( $label ),
];
);

return $this;
}
Expand All @@ -57,7 +54,7 @@ public static function compare( array $a, array $b ) {
public function get(): array {
$arr = $this->arr;

usort( $arr, [ __CLASS__, 'compare' ] );
usort( $arr, array( __CLASS__, 'compare' ) );

return $arr;
}
Expand All @@ -79,5 +76,4 @@ public function encode(): string {
public function __toString() {
return $this->encode();
}

}
12 changes: 4 additions & 8 deletions includes/MslsLanguageArray.php
Original file line number Diff line number Diff line change
@@ -1,21 +1,18 @@
<?php
/**
* MslsLanguageArray
* @author Dennis Ploetner <[email protected]>
* @since 0.9.8
*/

namespace lloc\Msls;

/**
* Stores the language input from post
*
* @example https://gist.githubusercontent.com/lloc/2c232cef3f910acf692f/raw/c78a78b42cb4c9e97a118523f7497f02b838a2ee/MslsLanguageArray.php
* @package Msls
*/
class MslsLanguageArray {

/**
* Generic container
*
* @var array
*/
protected $arr;
Expand All @@ -25,7 +22,7 @@ class MslsLanguageArray {
*
* @param array $arr
*/
public function __construct( array $arr = [] ) {
public function __construct( array $arr = array() ) {
foreach ( $arr as $key => $value ) {
$this->set( $key, $value );
}
Expand All @@ -37,7 +34,7 @@ public function __construct( array $arr = [] ) {
* - $value must be an integer > 0
*
* @param string $key
* @param mixed $value
* @param mixed $value
*
* @return MslsLanguageArray
*/
Expand Down Expand Up @@ -77,5 +74,4 @@ public function get_arr( $key = '' ) {

return $arr;
}

}
Loading
Loading