Skip to content

Commit

Permalink
widget, movie are called from core class, using proper hacks, link ma…
Browse files Browse the repository at this point in the history
…ker factory has a static constructor
  • Loading branch information
jcvignoli committed Jun 9, 2022
1 parent 460501a commit d462edd
Show file tree
Hide file tree
Showing 30 changed files with 194 additions and 130 deletions.
3 changes: 2 additions & 1 deletion dist/ACKNOWLEDGMENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
**Some admin panels icons** made by [Yusuke Kamiyamane](https://p.yusukekamiyamane.com/ "Yusuke Kamiyamane homepage")

# Tools
**Highslide JS Thumbnail viewer** by [Highslide](https://highslide.com/ "Highslide website")
**HighslideJS modal window** by [Highslide](https://highslide.com/ "Highslide website")
**Bootstrap modal window** by [Mark Otto](https://getbootstrap.com/ "Bootstrap website")
**Monolog logger** by [Seldaek](https://github.com/Seldaek/monolog/ "Monolog GIT")

# Development
Expand Down
20 changes: 10 additions & 10 deletions dist/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,21 @@
*/

/**
* Note: Classes class/class-updates.php, class/class-admin.php, vendor/autoload.php have a spl_autoload_register()
* Can't make it general, the class called in each file is different
* Note: Classes with spl_autoload_register():
* class/class-updates.php,
* class/plugins/autoload.php,
* class/class-admin.php,
* vendor/autoload.php
* Don't want to make an autoload for all classes, some will be called only under certain circonstances (admin, etc)
*/

# Vendor Libraries
include_once __DIR__ . '/vendor/autoload.php'; // with spl_autoload_register().
# Vendor Libraries
include_once __DIR__ . '/vendor/autoload.php';

# Lumiere Classes (no autoload, don't want all classes)
# Lumiere Classes
include_once __DIR__ . '/class/class-settings.php';
include_once __DIR__ . '/class/trait-settings-global.php';
include_once __DIR__ . '/class/tools/class-pluginsdetect.php';
include_once __DIR__ . '/class/tools/class-utils.php';
include_once __DIR__ . '/class/plugins/autoload.php';
include_once __DIR__ . '/class/class-core.php'; // activated in lumiere-movies.php
include_once __DIR__ . '/class/frontend/trait-frontend.php';
include_once __DIR__ . '/class/tools/class-pluginsdetect.php';
include_once __DIR__ . '/class/frontend/class-movie.php';
include_once __DIR__ . '/class/class-widget.php';

22 changes: 22 additions & 0 deletions dist/class/class-core.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
use \Lumiere\Plugins\Imdbphp;
use \Lumiere\Plugins\Logger;
use \Lumiere\Virtual_Page;
use \Lumiere\Movie;
use \Imdb\Title;
use \Imdb\Person;

Expand Down Expand Up @@ -178,6 +179,27 @@ function(): void {
// Register Gutenberg blocks.
add_action( 'init', [ $this, 'lumiere_register_gutenberg_blocks' ] );

// Movie class if it is not an admin page
if ( ! is_admin() ) {
add_action(
'init',
function(): void {
include_once __DIR__ . '/frontend/class-movie.php';
Movie::lumiere_movie_start();
},
0
);
}

// Widget
add_action(
'widgets_init',
function(): void {
include_once __DIR__ . '/class-widget.php';
Widget::lumiere_widget_start();
}
);

/**
* Updates.
*/
Expand Down
8 changes: 5 additions & 3 deletions dist/class/class-widget.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@
wp_die( 'You can not call directly this page' );
}

if ( ! trait_exists( 'Lumiere\Frontend' ) ) {
include_once __DIR__ . '/frontend/trait-frontend.php';
}

use \Lumiere\Movie;
use \Lumiere\Plugins\Polylang;
use \Lumiere\Link_Makers\Link_Factory;
Expand Down Expand Up @@ -254,6 +258,7 @@ public function lumiere_register_widget_block(): void {
public function widget( $args, $instance ) {

// Start Movie class.
include_once __DIR__ . '/frontend/class-movie.php';
$movie_class = new Movie( new Polylang() );

// Execute logging.
Expand Down Expand Up @@ -412,6 +417,3 @@ public function update( $new_instance, $old_instance ) {
}

}

// Instead of starting the class, add an action.
add_action( 'set_current_user', [ 'Lumiere\Widget', 'lumiere_widget_start' ] );
53 changes: 27 additions & 26 deletions dist/class/frontend/class-movie.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@
wp_die( 'You can not call directly this page' );
}

if ( ! trait_exists( 'Lumiere\Frontend' ) ) {
include_once __DIR__ . '/trait-frontend.php';
}

use \Imdb\Title;
use \Imdb\TitleSearch;
use \Lumiere\Plugins\Polylang;
Expand All @@ -41,11 +45,11 @@ class Movie {
private ?Polylang $plugin_polylang = null;

/**
* Make sure $link_maker is executed once in this class
* Make sure events are runned once in this class
*
* @var bool $link_maker_trigger
* @var bool $movie_run_once
*/
private bool $link_maker_trigger = false;
private bool $movie_run_once = false;

/**
* HTML allowed for use of wp_kses_post()
Expand Down Expand Up @@ -110,7 +114,7 @@ public function lumiere_show( array $imdb_id_or_title_outside = null ): string {
* Start PluginsDetect class
* Is instanciated only if not instanciated already
* Use lumiere_set_plugins_array() in trait to set $plugins_in_use var in trait
* @since 3.7.1
* @since 3.8
*/
if ( count( $this->plugins_in_use ) === 0 ) {
$this->lumiere_set_plugins_array();
Expand All @@ -120,28 +124,31 @@ public function lumiere_show( array $imdb_id_or_title_outside = null ): string {
$logger = $this->logger->log();

/**
* Start Link Factory sub class
* Is instantiated only if not instanciated already, using $link_maker_trigger
* @since 3.7.1
* Run Factory Class, Show log for link maker and plugin detect
* Is instantiated only if not instanciated already, using $run_once in this class
* @since 3.8
*/
if ( $this->link_maker_trigger === false ) {
if ( $this->movie_run_once === false ) {

// Run again the factory class (already runned in trait) to build link maker
$this->link_maker = Link_Factory::lumiere_link_factory_start();

$this->link_maker = $this->factory_class->lumiere_select_link_maker();
// Log the current link maker
$logger->debug( '[Lumiere][' . self::CLASS_NAME . '] Using the link maker class: ' . str_replace( 'Lumiere\Link_Makers\\', '', get_class( $this->link_maker ) ) );

// Set the trigger to true so it is not called again.
$this->link_maker_trigger = true;
// Log PluginsDetect, $this->plugins_in_use in trait
$logger->debug( '[Lumiere][' . self::CLASS_NAME . '] The following plugins compatible with Lumière! are in use: [' . join( ', ', $this->plugins_in_use ) . ']' );
$logger->debug( '[Lumiere][' . self::CLASS_NAME . '] Calling IMDbPHP class.' );

// Set the trigger to true so this is not called again.
$this->movie_run_once = true;
}

$config_class = $this->config_class;
$lumiere_count_me_siffer = isset( $lumiere_count_me_siffer ) ? $lumiere_count_me_siffer : 0; # var for counting only one results
$imdb_id_or_title = $imdb_id_or_title_outside !== null ? $imdb_id_or_title_outside : null;
$output = '';

$logger->debug( '[Lumiere][' . self::CLASS_NAME . '] The following plugins compatible with Lumière! are in use: [' . join( ', ', $this->plugins_in_use ) . ']' );
$logger->debug( '[Lumiere][' . self::CLASS_NAME . '] Calling IMDbPHP class.' );

$search = new TitleSearch( $this->imdbphp_class, $logger );

// $imdb_id_or_title var comes from custom post's field in widget or in post
Expand Down Expand Up @@ -326,6 +333,9 @@ private function lumiere_link_finder( array $correspondances ): string {
* Each one has its own class passed in $link_maker,
* according to which option the lumiere_select_link_maker() found in Frontend.
*/
if ( ! isset( $this->link_maker ) ) { // Needed if called from Taxonomy pages
$this->link_maker = Link_Factory::lumiere_link_factory_start();
}
return $this->link_maker->lumiere_popup_film_link( $link_parsed );

}
Expand All @@ -349,6 +359,9 @@ private function lumiere_link_finder_oldway( array $correspondances ): string {
* Each one has its own class passed in $link_maker,
* according to which option the lumiere_select_link_maker() found in Frontend.
*/
if ( ! isset( $this->link_maker ) ) { // Needed if called from Taxonomy pages
$this->link_maker = Link_Factory::lumiere_link_factory_start();
}
return $this->link_maker->lumiere_popup_film_link( $link_parsed );

}
Expand Down Expand Up @@ -1729,15 +1742,3 @@ public static function lumiere_movie_start (): void {
}

} // end of class


/**
* Auto load the class
* Conditions: not admin area
* @TODO: Pass this into core class?
*/
if ( ! is_admin() ) {
//new Movie( new Polylang() );
add_action( 'init', [ 'Lumiere\Movie', 'lumiere_movie_start' ], 1 );
}

2 changes: 1 addition & 1 deletion dist/class/frontend/class-popup-movie.php
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ public function lumiere_popup_movie_layout(): void {
$movie_results = $this->movie;

// Build Link Factory class
$this->link_maker = $this->factory_class->lumiere_select_link_maker();
$this->link_maker = Link_Factory::lumiere_link_factory_start();
$this->logger->log()->debug( '[Lumiere][popupPersonClass] Using the link maker class: ' . str_replace( 'Lumiere\Link_Makers\\', '', get_class( $this->link_maker ) ) );

$this->display_menu( $this->movie );
Expand Down
2 changes: 1 addition & 1 deletion dist/class/frontend/class-popup-person.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ public function lumiere_popup_person_layout(): void {
$this->find_person();

// Build Link Factory class
$this->link_maker = $this->factory_class->lumiere_select_link_maker();
$this->link_maker = Link_Factory::lumiere_link_factory_start();
$this->logger->log()->debug( '[Lumiere][popupPersonClass] Using the link maker class: ' . str_replace( 'Lumiere\Link_Makers\\', '', get_class( $this->link_maker ) ) );

// Show menu.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* @copyright (c) 2022, Lost Highway
*
* @version 1.0
* @since 3.7.1
* @since 3.8
* @package lumiere-movies
*/

Expand Down
4 changes: 2 additions & 2 deletions dist/class/frontend/link_makers/class-bootstrap-links.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* @copyright (c) 2022, Lost Highway
*
* @version 1.0
* @since 3.7
* @since 3.8
* @package lumiere-movies
*/

Expand Down Expand Up @@ -39,7 +39,7 @@ public function __construct() {
$this->settings_open();

// Registers javascripts and styles.
add_action( 'init', [ $this, 'lumiere_bootstrap_register_assets' ], 0 );
add_action( 'init', [ $this, 'lumiere_bootstrap_register_assets' ], 1 ); // must be after Core class call

// Execute javascripts and styles only if the vars in lumiere_bootstrap_core were not already enqueued
// (prevents a bug if the vars are displayed twice, the popup doesn't open).
Expand Down
2 changes: 1 addition & 1 deletion dist/class/frontend/link_makers/class-classic-links.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public function __construct() {
$this->settings_open();

// Registers javascripts and styles.
add_action( 'init', [ $this, 'lumiere_classic_register_assets' ], 0 );
add_action( 'init', [ $this, 'lumiere_classic_register_assets' ], 1 ); // must be after Core class call

// Execute javascripts and styles only if the vars in lumiere_classic_links was not already enqueued
// (prevents a bug if the vars are displayed twice, the popup doesn't open).
Expand Down
2 changes: 1 addition & 1 deletion dist/class/frontend/link_makers/class-highslide-links.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public function __construct() {
$this->settings_open();

// Registers javascripts and styles.
add_action( 'init', [ $this, 'lumiere_highslide_register_assets' ], 0 );
add_action( 'init', [ $this, 'lumiere_highslide_register_assets' ], 1 ); // must be after Core class call

// Execute javascripts and styles only if the vars in lumiere_highslide_options were not already enqueued
// (prevents a bug if the vars are displayed twice, the popup doesn't open).
Expand Down
12 changes: 11 additions & 1 deletion dist/class/frontend/link_makers/class-link-factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* @author Lost Highway <https://www.jcvignoli.com/blog>
* @copyright (c) 2022, Lost Highway
*
* @since 3.7.1
* @since 3.8
* @version 1.0
* @package lumiere-movies
*/
Expand Down Expand Up @@ -84,4 +84,14 @@ public function lumiere_select_link_maker (): Bootstrap_Links|AMP_Links|No_Links

}

/**
* Static call of the current class
*
* @return void Build the class
*/
public static function lumiere_link_factory_start (): Bootstrap_Links|AMP_Links|No_Links|Highslide_Links|Classic_Links {

return ( new self() )->lumiere_select_link_maker();

}
}
2 changes: 1 addition & 1 deletion dist/class/frontend/link_makers/class-no-links.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* @copyright (c) 2022, Lost Highway
*
* @version 1.0
* @since 3.7.1
* @since 3.8
* @package lumiere-movies
*/

Expand Down
15 changes: 3 additions & 12 deletions dist/class/frontend/trait-frontend.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@

namespace Lumiere;

include_once __DIR__ . '/link_makers/autoload.php';

use \Lumiere\PluginsDetect;
use \Lumiere\Utils;
use \Lumiere\Link_Makers\Link_Factory;
Expand All @@ -36,13 +34,6 @@ trait Frontend {
*/
public array $plugins_in_use = [];

/**
* Factory class for building $link_maker object
*
* @var Link_Factory $factory_class The factory class that will determine which class to use
*/
public Link_Factory $factory_class;

/**
* Class for building links, i.e. Highslide
* Built in class Link Factory
Expand Down Expand Up @@ -95,9 +86,9 @@ public function __construct( ?string $logger_name = 'unknownOrigin', ?bool $scre
$this->imdbphp_class = new Imdbphp();

// Instanciate link maker classes (\Lumiere\Link_Maker\Link_Factory)
// Need to construct both classes for sub factory heading and taxonomy pages
$this->factory_class = new Link_Factory();
$this->link_maker = $this->factory_class->lumiere_select_link_maker();
// Runned again in dependent classes, but need to be run twice: 1/ JS&CSS 2/ Detect if AMP is in use
include_once __DIR__ . '/link_makers/autoload.php';
Link_Factory::lumiere_link_factory_start();

// Start checking if current page is block editor
add_action( 'init', [ $this, 'lumiere_frontend_is_editor' ], 0 );
Expand Down
13 changes: 9 additions & 4 deletions dist/class/theme/class-taxonomy-people-standard.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@
* You can replace the occurences of the word s_tandar_d, rename this file, and then copy it in your theme folder
* Or easier: just use Lumière admin interface to do it automatically
*
* Version: 3.4
* Version: 3.5
*
* This template retrieves automaticaly the occurence of the name selected
* If used along with Polylang WordPress plugin, a form is displayed to filter by available language
* Almost compatible with AMP WordPress plugin, since WP submit_button() does not seem to be yet AMP compliant
* Almost compatible with AMP WordPress plugin, because WP submit_button() does not seem to be yet AMP compliant
* It uses \Lumiere\Frontend trait and builds its $this->link_maker var
*
* @package lumiere-movies
*/
Expand All @@ -23,6 +24,7 @@
use \Imdb\Person;
use \Imdb\PersonSearch;
use \Lumiere\Plugins\Polylang;
use \Lumiere\Link_Makers\Link_Factory;
use \WP_Query;

class Taxonomy_People_Standard {
Expand Down Expand Up @@ -89,7 +91,7 @@ public function __construct( ?Polylang $plugin_polylang = null ) {
// List of potential parameters for a person.
$this->array_people = $this->config_class->array_people;

// Display the page.
// Display the page. Must not be included into an add_action(), as should be displayed directly.
$this->lumiere_taxo_layout_standard();

// Remove action that breaks everything in trait-frontend.php, function is executed later
Expand Down Expand Up @@ -145,8 +147,12 @@ private function lumiere_taxo_layout_standard(): void {
// Build array of plugins from trait-frontend.php
$this->lumiere_set_plugins_array();

// Simplify coding
$logger = $this->logger->log();

// Build the Link Maker var in trait
$this->link_maker = Link_Factory::lumiere_link_factory_start();

$logger->debug( '[Lumiere][taxonomy_' . $this->taxonomy_title . '] Using the link maker class: ' . get_class( $this->link_maker ) );

echo '<br />';
Expand Down Expand Up @@ -448,4 +454,3 @@ private function portrait(): void {
}

new Taxonomy_People_Standard( new Polylang() );

Loading

0 comments on commit d462edd

Please sign in to comment.