Skip to content

Commit

Permalink
id given to taxonomy links in class Movie, fixed latest tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jcvignoli committed Nov 10, 2024
1 parent ba1848e commit 6c7e618
Show file tree
Hide file tree
Showing 15 changed files with 90 additions and 64 deletions.
3 changes: 2 additions & 1 deletion dist/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ v.4.2.1
* [feature] Language form in Taxonomy pages is automatically submitted on language change (added jquery script in lumiere_scripts.js and renamed <input type="submit" name="submit"> to <input type="submit" name="submit_lang"> - "name" couldn't be "submit")
* [bug] Couldn't save Popups settings in General settings (fixed class Save_options method lumiere_general_options_save(), added "! isset( $_POST['imdbpopup_modal_window'] )" )
* [bug] Notices weren't displayed (trait Admin_General had a sanitize_key() instead of esc_url() in method lumiere_get_current_admin_url())
* [bug] Link to activate taxoonomy when it's not activated (next to "Data Management") was outdated (updated in template admin-menu-first-part.php)
* [bug] Link to activate taxonomy when it's not activated (next to "Data Management") was outdated (updated in template admin-menu-first-part.php)
* [bug] Movies languages were not available (changed IMDb method from languages() to language(), using GraphQL)
* [technical] Taxonomy pages for people also retrieve pages written about the person (previously only posts were retrieved, added 'page' to queries in classes Polylang and Taxonomy_People_Standard)
* [technical] Renamed database table names (from imdb* to lumiere_*)

Expand Down
32 changes: 20 additions & 12 deletions dist/class/frontend/class-movie-data.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ protected function lumiere_movies_country ( Title $movie ): string {

for ( $i = 0; $i < $nbtotalcountry; $i++ ) {

$output .= $this->lumiere_make_display_taxonomy( 'country', esc_attr( $country[ $i ] ), '', 'one' );
$output .= $this->lumiere_make_display_taxonomy( 'country', esc_attr( $country[ $i ] ), '', 'one', sanitize_text_field( $movie->title() ) );
if ( $i < $nbtotalcountry - 1 ) {
$output .= ', ';
}
Expand Down Expand Up @@ -163,7 +163,10 @@ protected function lumiere_movies_runtime( Title $movie ): string {
protected function lumiere_movies_language( Title $movie ): string {

$output = '';
$languages = $movie->languages();

// @var array<int, string> $languages
$languages = $movie->language();

$nbtotallanguages = count( $languages );

if ( $nbtotallanguages === 0 ) {
Expand All @@ -179,7 +182,7 @@ protected function lumiere_movies_language( Title $movie ): string {

for ( $i = 0; $i < $nbtotallanguages; $i++ ) {

$output .= $this->lumiere_make_display_taxonomy( 'language', esc_attr( $languages[ $i ] ), '', 'one' );
$output .= $this->lumiere_make_display_taxonomy( 'language', esc_attr( $languages[ $i ] ), '', 'one', sanitize_text_field( $movie->title() ) );
if ( $i < $nbtotallanguages - 1 ) {
$output .= ', ';
}
Expand Down Expand Up @@ -252,7 +255,7 @@ protected function lumiere_movies_genre( Title $movie ): string {

for ( $i = 0; $i < $nbtotalgenre; $i++ ) {

$output .= $this->lumiere_make_display_taxonomy( 'genre', esc_attr( $genre[ $i ] ), '', 'one' );
$output .= $this->lumiere_make_display_taxonomy( 'genre', esc_attr( $genre[ $i ] ), '', 'one', sanitize_text_field( $movie->title() ) );
if ( $i < $nbtotalgenre - 1 ) {
$output .= ', ';
}
Expand Down Expand Up @@ -298,7 +301,7 @@ protected function lumiere_movies_keyword( Title $movie ): string {

for ( $i = 0; $i < $nbtotalkeywords && $i < $limit_keywords; $i++ ) {

$output .= $this->lumiere_make_display_taxonomy( 'keyword', esc_attr( $keywords[ $i ] ), '', 'one' );
$output .= $this->lumiere_make_display_taxonomy( 'keyword', esc_attr( $keywords[ $i ] ), '', 'one', sanitize_text_field( $movie->title() ) );
if ( $i < $nbtotalkeywords - 1 ) {
$output .= ', ';
}
Expand Down Expand Up @@ -470,7 +473,7 @@ protected function lumiere_movies_color( Title $movie ): string {

for ( $i = 0; $i < $nbtotalcolors; $i++ ) {

$output .= $this->lumiere_make_display_taxonomy( 'color', esc_attr( $colors[ $i ] ), '', 'one' );
$output .= $this->lumiere_make_display_taxonomy( 'color', esc_attr( $colors[ $i ] ), '', 'one', sanitize_text_field( $movie->title() ) );
if ( $i < $nbtotalcolors - 1 ) {
$output .= ', ';
}
Expand Down Expand Up @@ -568,7 +571,7 @@ protected function lumiere_movies_composer( Title $movie ): string {

for ( $i = 0; $i < $nbtotalcomposer; $i++ ) {

$output .= $this->lumiere_make_display_taxonomy( 'composer', esc_attr( $composer[ $i ]['name'] ), '', 'one' );
$output .= $this->lumiere_make_display_taxonomy( 'composer', esc_attr( $composer[ $i ]['name'] ), '', 'one', sanitize_text_field( $movie->title() ) );
if ( $i < $nbtotalcomposer - 1 ) {
$output .= ', ';
}
Expand Down Expand Up @@ -748,7 +751,8 @@ protected function lumiere_movies_director( Title $movie ): string {
'director',
esc_attr( $director[ $i ]['name'] ),
'',
'one'
'one',
sanitize_text_field( $movie->title() )
);

if ( $i < $nbtotaldirector - 1 ) {
Expand Down Expand Up @@ -808,7 +812,8 @@ protected function lumiere_movies_creator( Title $movie ): string {
'creator',
esc_attr( $creator[ $i ]['name'] ),
'',
'one'
'one',
sanitize_text_field( $movie->title() )
);

if ( $i < $nbtotalcreator - 1 ) {
Expand Down Expand Up @@ -869,7 +874,8 @@ protected function lumiere_movies_producer( Title $movie ): string {
'producer',
esc_attr( $producer[ $i ]['name'] ),
esc_attr( $producer[ $i ]['role'] ),
'two'
'two',
sanitize_text_field( $movie->title() )
);
}

Expand Down Expand Up @@ -935,7 +941,8 @@ protected function lumiere_movies_writer( Title $movie ): string {
'writer',
esc_attr( $writer[ $i ]['name'] ),
esc_attr( $writer[ $i ]['role'] ),
'two'
'two',
sanitize_text_field( $movie->title() )
);
}

Expand Down Expand Up @@ -1000,7 +1007,8 @@ protected function lumiere_movies_actor( Title $movie ): string {
'actor',
esc_attr( $cast[ $i ]['name'] ),
esc_attr( $cast[ $i ]['role'] ),
'two'
'two',
sanitize_text_field( $movie->title() )
);
}

Expand Down
16 changes: 10 additions & 6 deletions dist/class/frontend/class-movie.php
Original file line number Diff line number Diff line change
Expand Up @@ -445,10 +445,11 @@ private function lumiere_movie_wrapper( string $html, string $item ): string {
* @param string $first_title mandatory: the name of the first string to display, ie "Stanley Kubrick"
* @param string|null $second_title optional: the name of a second string to display, utilised in $layout 'two', ie "director"
* @param string $layout optional: the type of the layout, either 'one' or 'two', one by default
* @param string|null $movie_title Optional: movie's title, null by default
*
* @return string the text to be outputed
*/
protected function lumiere_make_display_taxonomy( string $type_item, string $first_title, ?string $second_title = null, string $layout = 'one' ): string {
protected function lumiere_make_display_taxonomy( string $type_item, string $first_title, ?string $second_title = null, string $layout = 'one', ?string $movie_title = null ): string {

/**
* Vars and sanitization
Expand Down Expand Up @@ -526,12 +527,17 @@ protected function lumiere_make_display_taxonomy( string $type_item, string $fir
/**
* Layout
*/

// Build the id for the link <a id="$link_id">
$link_id = ( $movie_title ?? '' ) . '_' . $lang_term . '_' . $taxonomy_category_full . '_' . $taxonomy_term;
$link_id = preg_replace( "/^'|[^A-Za-z0-9\'-]|'|\-$/", '_', $link_id ) ?? '';
$link_id = 'link_taxo_' . strtolower( str_replace( '-', '_', $link_id ) );

// layout=two: display the layout for double entry details, ie actors
if ( $layout === 'two' ) {

$output .= "\n\t\t\t" . '<div align="center" class="lumiere_container">';
$output .= "\n\t\t\t\t" . '<div class="lumiere_align_left lumiere_flex_auto">';
$output .= "\n\t\t\t\t\t<a class=\"lum_link_taxo_page\" href=\""
$output .= "\n\t\t\t\t\t<a id=\"" . $link_id . '" class="lum_link_taxo_page" href="'
. esc_url( $this->lumiere_get_taxo_link( $taxonomy_term, $taxonomy_category_full ) )
. '" title="' . esc_html__( 'Find similar taxonomy results', 'lumiere-movies' )
. '">';
Expand All @@ -545,14 +551,12 @@ protected function lumiere_make_display_taxonomy( string $type_item, string $fir

// layout=one: display the layout for all details separated by comas, ie keywords
} elseif ( $layout === 'one' ) {

$output .= '<a class="lum_link_taxo_page" '
$output .= '<a id="' . $link_id . '" class="lum_link_taxo_page" '
. 'href="' . esc_url( $this->lumiere_get_taxo_link( $taxonomy_term, $taxonomy_category_full ) )
. '" '
. 'title="' . esc_html__( 'Find similar taxonomy results', 'lumiere-movies' ) . '">';
$output .= $taxonomy_term;
$output .= '</a>';

}

return $output;
Expand Down
8 changes: 4 additions & 4 deletions dist/vendor/composer/installed.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
"source": {
"type": "git",
"url": "https://github.com/jcvignoli/imdbphp.git",
"reference": "602b3c82fffba52937f35b559f77a53f78b61d03"
"reference": "fba666afab7c30fa6f05cd1ba68e29bccda51925"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/jcvignoli/imdbphp/zipball/602b3c82fffba52937f35b559f77a53f78b61d03",
"reference": "602b3c82fffba52937f35b559f77a53f78b61d03",
"url": "https://api.github.com/repos/jcvignoli/imdbphp/zipball/fba666afab7c30fa6f05cd1ba68e29bccda51925",
"reference": "fba666afab7c30fa6f05cd1ba68e29bccda51925",
"shasum": ""
},
"require": {
Expand All @@ -34,7 +34,7 @@
"phpunit/phpunit": "^9.5",
"wapmorgan/php-deprecation-detector": "@stable"
},
"time": "2024-10-07T14:44:26+00:00",
"time": "2024-11-10T22:11:10+00:00",
"default-branch": true,
"type": "library",
"installation-source": "dist",
Expand Down
6 changes: 3 additions & 3 deletions dist/vendor/composer/installed.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
'name' => 'jcvignoli/lumiere-movies',
'pretty_version' => 'dev-master',
'version' => 'dev-master',
'reference' => '8db91c2507de450502b66e2fed8602e5c57d99b1',
'reference' => 'ba1848e88fc763d17e8af3f2584f9f95ca114fd4',
'type' => 'library',
'install_path' => __DIR__ . '/../../',
'aliases' => array(),
Expand All @@ -13,7 +13,7 @@
'jcvignoli/imdbphp' => array(
'pretty_version' => 'dev-master',
'version' => 'dev-master',
'reference' => '602b3c82fffba52937f35b559f77a53f78b61d03',
'reference' => 'fba666afab7c30fa6f05cd1ba68e29bccda51925',
'type' => 'library',
'install_path' => __DIR__ . '/../jcvignoli/imdbphp',
'aliases' => array(
Expand All @@ -24,7 +24,7 @@
'jcvignoli/lumiere-movies' => array(
'pretty_version' => 'dev-master',
'version' => 'dev-master',
'reference' => '8db91c2507de450502b66e2fed8602e5c57d99b1',
'reference' => 'ba1848e88fc763d17e8af3f2584f9f95ca114fd4',
'type' => 'library',
'install_path' => __DIR__ . '/../../',
'aliases' => array(),
Expand Down
5 changes: 2 additions & 3 deletions dist/vendor/jcvignoli/imdbphp/src/Imdb/Title.php
Original file line number Diff line number Diff line change
Expand Up @@ -671,11 +671,10 @@ public function keywords()

#--------------------------------------------------------[ Language Stuff ]---

/** Get movies original language
/** Get movies original languages
* @return string language
* @brief There is not really a main language on the IMDB sites (yet), so this
* simply returns the first one
* @see IMDB page / (TitlePage)
* @return array<int, string> languages
*/
public function language()
{
Expand Down
2 changes: 1 addition & 1 deletion psalm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
<globals>
<!-- Personal Globals Psalm is not aware of -->
<var name="_GET" type="array{ taxotype: string, amp: string|null, wpamp: string|null, search_nonce: string, moviesearched: string, film: string|null, norecursive: string|null, info: string|null, mid: string|null, generaloption: string|null, subsection: string, helpsub: string|null, widgetoption: string|null, dothis: string, type: string, where: string, _wpnonce_linkcopytaxo: string, cacheoption: string|null, _nonce_cache_deleteindividual: string, _nonce_cache_refreshindividual: string, _wpnonce_lum_taxo_polylangform: string, tag_lang: string|null, page: string|null, _wp_http_referer: string, submit_lang: string, _wpnonce: string }" />
<var name="_POST" type="array{ imdb_imdburlstringtaxo: string, imdb_imdburlpopups: string, lum_widget_movieid: string, lum_widget_movietitle: string, lum_form_type_query: string, lum_form_query_value: string, lumiere_autotitlewidget_perpost: string, lum_metabox_nonce: string, lumiere_update_general_settings: string|null, '_nonce_general_settings': string, lumiere_reset_general_settings: string|null, lumiere_update_cache_settings: string, '_nonce_cache_settings': string, lumiere_reset_cache_settings: string, lumiere_update_data_settings: string, '_nonce_data_settings': string, lumiere_reset_data_settings: string, imdbwidgetorder: string, imdbwidgetorderContainer: array{string}|null, imdb_cachedeletefor_movies: array|null, imdb_cachedeletefor_people: array|null, imdb_imdbcacheautorefreshcron: string, imdb_imdbcachekeepsizeunder: string, delete_ticked_cache: string, delete_query_cache: string, delete_all_cache: string, _nonce_cache_all_and_query_check: string, _wpnonce_lum_taxo_polylangform: string }" />
<var name="_POST" type="array{ imdb_imdburlstringtaxo: string, imdb_imdburlpopups: string, lum_widget_movieid: string, lum_widget_movietitle: string, lum_form_type_query: string, lum_form_query_value: string, lumiere_autotitlewidget_perpost: string, lum_metabox_nonce: string, lumiere_update_general_settings: string|null, '_nonce_general_settings': string, lumiere_reset_general_settings: string|null, lumiere_update_cache_settings: string, '_nonce_cache_settings': string, lumiere_reset_cache_settings: string, lumiere_update_data_settings: string, '_nonce_data_settings': string, lumiere_reset_data_settings: string, imdbwidgetorder: string, imdbwidgetorderContainer: array{string}|null, imdb_cachedeletefor_movies: array|null, imdb_cachedeletefor_people: array|null, imdb_imdbcacheautorefreshcron: string, imdb_imdbcachekeepsizeunder: string, delete_ticked_cache: string, delete_query_cache: string, delete_all_cache: string, _nonce_cache_all_and_query_check: string, _wpnonce_lum_taxo_polylangform: string, imdbpopup_modal_window: string }" />
</globals>
<issueHandlers>
<!-- Remove the include error, since the includes for webserver are different from local -->
Expand Down
3 changes: 2 additions & 1 deletion src/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ v.4.2.1
* [feature] Language form in Taxonomy pages is automatically submitted on language change (added jquery script in lumiere_scripts.js and renamed &lt;input type="submit" name="submit"&gt; to &lt;input type="submit" name="submit_lang"&gt; - "name" couldn't be "submit")
* [bug] Couldn't save Popups settings in General settings (fixed class Save_options method lumiere_general_options_save(), added "! isset( $_POST['imdbpopup_modal_window'] )" )
* [bug] Notices weren't displayed (trait Admin_General had a sanitize_key() instead of esc_url() in method lumiere_get_current_admin_url())
* [bug] Link to activate taxoonomy when it's not activated (next to "Data Management") was outdated (updated in template admin-menu-first-part.php)
* [bug] Link to activate taxonomy when it's not activated (next to "Data Management") was outdated (updated in template admin-menu-first-part.php)
* [bug] Movies languages were not available (changed IMDb method from languages() to language(), using GraphQL)
* [technical] Taxonomy pages for people also retrieve pages written about the person (previously only posts were retrieved, added 'page' to queries in classes Polylang and Taxonomy_People_Standard)
* [technical] Renamed database table names (from imdb* to lumiere_*)

Expand Down
32 changes: 20 additions & 12 deletions src/class/frontend/class-movie-data.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ protected function lumiere_movies_country ( Title $movie ): string {

for ( $i = 0; $i < $nbtotalcountry; $i++ ) {

$output .= $this->lumiere_make_display_taxonomy( 'country', esc_attr( $country[ $i ] ), '', 'one' );
$output .= $this->lumiere_make_display_taxonomy( 'country', esc_attr( $country[ $i ] ), '', 'one', sanitize_text_field( $movie->title() ) );
if ( $i < $nbtotalcountry - 1 ) {
$output .= ', ';
}
Expand Down Expand Up @@ -163,7 +163,10 @@ protected function lumiere_movies_runtime( Title $movie ): string {
protected function lumiere_movies_language( Title $movie ): string {

$output = '';
$languages = $movie->languages();

// @var array<int, string> $languages
$languages = $movie->language();

$nbtotallanguages = count( $languages );

if ( $nbtotallanguages === 0 ) {
Expand All @@ -179,7 +182,7 @@ protected function lumiere_movies_language( Title $movie ): string {

for ( $i = 0; $i < $nbtotallanguages; $i++ ) {

$output .= $this->lumiere_make_display_taxonomy( 'language', esc_attr( $languages[ $i ] ), '', 'one' );
$output .= $this->lumiere_make_display_taxonomy( 'language', esc_attr( $languages[ $i ] ), '', 'one', sanitize_text_field( $movie->title() ) );
if ( $i < $nbtotallanguages - 1 ) {
$output .= ', ';
}
Expand Down Expand Up @@ -252,7 +255,7 @@ protected function lumiere_movies_genre( Title $movie ): string {

for ( $i = 0; $i < $nbtotalgenre; $i++ ) {

$output .= $this->lumiere_make_display_taxonomy( 'genre', esc_attr( $genre[ $i ] ), '', 'one' );
$output .= $this->lumiere_make_display_taxonomy( 'genre', esc_attr( $genre[ $i ] ), '', 'one', sanitize_text_field( $movie->title() ) );
if ( $i < $nbtotalgenre - 1 ) {
$output .= ', ';
}
Expand Down Expand Up @@ -298,7 +301,7 @@ protected function lumiere_movies_keyword( Title $movie ): string {

for ( $i = 0; $i < $nbtotalkeywords && $i < $limit_keywords; $i++ ) {

$output .= $this->lumiere_make_display_taxonomy( 'keyword', esc_attr( $keywords[ $i ] ), '', 'one' );
$output .= $this->lumiere_make_display_taxonomy( 'keyword', esc_attr( $keywords[ $i ] ), '', 'one', sanitize_text_field( $movie->title() ) );
if ( $i < $nbtotalkeywords - 1 ) {
$output .= ', ';
}
Expand Down Expand Up @@ -470,7 +473,7 @@ protected function lumiere_movies_color( Title $movie ): string {

for ( $i = 0; $i < $nbtotalcolors; $i++ ) {

$output .= $this->lumiere_make_display_taxonomy( 'color', esc_attr( $colors[ $i ] ), '', 'one' );
$output .= $this->lumiere_make_display_taxonomy( 'color', esc_attr( $colors[ $i ] ), '', 'one', sanitize_text_field( $movie->title() ) );
if ( $i < $nbtotalcolors - 1 ) {
$output .= ', ';
}
Expand Down Expand Up @@ -568,7 +571,7 @@ protected function lumiere_movies_composer( Title $movie ): string {

for ( $i = 0; $i < $nbtotalcomposer; $i++ ) {

$output .= $this->lumiere_make_display_taxonomy( 'composer', esc_attr( $composer[ $i ]['name'] ), '', 'one' );
$output .= $this->lumiere_make_display_taxonomy( 'composer', esc_attr( $composer[ $i ]['name'] ), '', 'one', sanitize_text_field( $movie->title() ) );
if ( $i < $nbtotalcomposer - 1 ) {
$output .= ', ';
}
Expand Down Expand Up @@ -748,7 +751,8 @@ protected function lumiere_movies_director( Title $movie ): string {
'director',
esc_attr( $director[ $i ]['name'] ),
'',
'one'
'one',
sanitize_text_field( $movie->title() )
);

if ( $i < $nbtotaldirector - 1 ) {
Expand Down Expand Up @@ -808,7 +812,8 @@ protected function lumiere_movies_creator( Title $movie ): string {
'creator',
esc_attr( $creator[ $i ]['name'] ),
'',
'one'
'one',
sanitize_text_field( $movie->title() )
);

if ( $i < $nbtotalcreator - 1 ) {
Expand Down Expand Up @@ -869,7 +874,8 @@ protected function lumiere_movies_producer( Title $movie ): string {
'producer',
esc_attr( $producer[ $i ]['name'] ),
esc_attr( $producer[ $i ]['role'] ),
'two'
'two',
sanitize_text_field( $movie->title() )
);
}

Expand Down Expand Up @@ -935,7 +941,8 @@ protected function lumiere_movies_writer( Title $movie ): string {
'writer',
esc_attr( $writer[ $i ]['name'] ),
esc_attr( $writer[ $i ]['role'] ),
'two'
'two',
sanitize_text_field( $movie->title() )
);
}

Expand Down Expand Up @@ -1000,7 +1007,8 @@ protected function lumiere_movies_actor( Title $movie ): string {
'actor',
esc_attr( $cast[ $i ]['name'] ),
esc_attr( $cast[ $i ]['role'] ),
'two'
'two',
sanitize_text_field( $movie->title() )
);
}

Expand Down
Loading

0 comments on commit 6c7e618

Please sign in to comment.