The Higher Education and Research forge

Home My Page Projects Code Snippets Project Openings MonLabo
Summary Activity Tracker Tasks Docs SCM Files Dokuwiki Continious Integration Listes Sympa

SCM Repository

authorHerve Suaudeau <herve.suaudeau@parisdescartes.fr>
Mon, 5 Oct 2020 23:30:30 +0000 (01:30 +0200)
committerHerve Suaudeau <herve.suaudeau@parisdescartes.fr>
Mon, 5 Oct 2020 23:30:30 +0000 (01:30 +0200)
admin/MonLabo-admin.php
admin/includes/inc-lib-forms.php
admin/includes/inc-lib-tables.php
admin/js/MonLabo-admin.js
changelog.txt
includes/MonLabo-generate-HTML.php

index ba38980..af5ffd3 100644 (file)
@@ -451,14 +451,20 @@ class MonLabo_admin {
                echo( ' '.$args['description'] );
        }
        function MonLabo_img_field_generic_render( $args ) {
+               $generate_HTML = New MonLabo_generate_HTML();
                echo( "<div class='image-preview-wrapper'>" );
-               echo( "<div class='MonLabo-persons-list'><ul><li><a href='#'><img width='60' height='60' id='image-preview' class='wp-image-8 alignleft img-arrondi wp-post-image' src='". $this->options[$args['settings_group']][$args['option_name']] ."' alt='". $this->options[$args['settings_group']][$args['option_name']] ."' /></a>" );
+               echo( "<div class='MonLabo-persons-list'><ul><li><a href='#'>"
+                       ."<img width='60' height='60' id='image-preview' class='wp-image-8 alignleft img-arrondi wp-post-image' src='". $generate_HTML->image_from_id_or_url($this->options[$args['settings_group']][$args['option_name']]) ."' alt='". $this->options[$args['settings_group']][$args['option_name']] ."' />"
+                       ."</a>" );
                echo( '</li></ul></div>' );
                echo( '</div>' );
-               echo( '<input type="button" class="upload_image_button button" value="'. __( 'Choisir ou téléverser', 'mon-laboratoire' ).'"' );
-               echo( ' onclick="imageMediaMenu(\''. __('Choisir une image', 'mon-laboratoire' ).'\',\''. __( 'utiliser cette image', 'mon-laboratoire' ).'\');" />' );
-               echo( "<input type='text' name='".$args['settings_group'].'['.$args['option_name']."]' id='image_attachment_url' value='". $this->options[$args['settings_group']][$args['option_name']]."' />" );
-               echo( "<input type='hidden' name='not_used' id='image_attachment_id' value='0' />" );
+               echo( '<input type="button" class="upload_image_button button" value="'. __( 'Choisir média', 'mon-laboratoire' ).'"'
+                       . ' onclick="imageMediaMenu('
+                       . "'" . __( 'Choisir une image', 'mon-laboratoire' ) . "',"
+                       . "'" . __( 'utiliser cette image', 'mon-laboratoire' ) . "',"
+                       . "'image-preview','image_attachment_id'"
+                       . ');" />');
+               echo( "<input type='hidden' name='".$args['settings_group'].'['.$args['option_name']."]' id='image_attachment_id' value='". $this->options[$args['settings_group']][$args['option_name']]."' />" );
        }
 
        function MonLabo_color_picker_generic_render( $args ) {
index d3f4eb5..7994906 100644 (file)
@@ -350,10 +350,16 @@ function generate_square_image_form( $isMandatory, $legend, $name, $description,
                . '\'' . $name.'\''
                . ');" />';
        $retval .= "<input type='hidden' name='".$name."' id='".$name."' value='".$valeur_initiale."' />&nbsp;";
-       $retval .= $MonLabo_generate_HTML->image_from_id_or_url( $valeur_initiale,
-               array("image_id" => $name."-image-preview", "href" => "#", "a_class" => "hover-zoom-square30", "hide_if_empty" => "true" )
-        );
-       $retval .= '</div>';
+       $url = $MonLabo_generate_HTML->image_from_id_or_url( $valeur_initiale );
+       if( empty( $valeur_initiale ) ) {
+               $supl_class = " hidden";
+               $url = '#';
+       } else {
+               $supl_class = "";
+       }
+       $retval .= "<a href='#' class='hover-zoom-square30'>";
+       $retval .= "<img width='30' height='30' id='" . $name."-image-preview' class='wp-image-8 wp-post-image" . $supl_class."' src='".  $url ."' alt='".$valeur_initiale."'>";
+       $retval .= '</a></div>';
        return $retval;
 }
 
index 13447bd..17956c5 100644 (file)
@@ -59,7 +59,7 @@ function generate_table_admin_for_persons( $status ) {
                                $person_array['logo'].= '<img id="image-preview-'.$person_information->id.'" src="'.$person_information->alternate_image.'" class="wp-image-6 alignright img-arrondi wp-post-image" alt="'.$person_information->alternate_image.'" />';
                        } else {
                                //Display default image
-                               $person_array['logo'].= '<img id="image-preview-'.$person_information->id.'" src="'.$options2['MonLabo_img_par_defaut'].'" class="wp-image-6 alignright img-arrondi wp-post-image" alt="'.$options2['MonLabo_img_par_defaut'].'" />';
+                               $person_array['logo'].= '<img id="image-preview-'.$person_information->id.'" src="'.$generate_HTML->image_from_id_or_url($options2['MonLabo_img_par_defaut']).'" class="wp-image-6 alignright img-arrondi wp-post-image" alt="'.$options2['MonLabo_img_par_defaut'].'" />';
                        }
                        $person_array['logo'] .= '</a>';
 
@@ -147,9 +147,7 @@ function generate_table_admin_for_teams() {
                        $team_array['id'] = $team_information->id;
                        $team_array['name_fr'] = '<small>'.$team_information->name_fr.'</small>';
                        $team_array['name_en'] = '<small>'.$team_information->name_en.'</small>';
-                       $team_array['logo'] = $generate_HTML->image_from_id_or_url( $team_information->logo,
-                               array("href" => "#", "a_class" => "hover-zoom-square30", "width" => 24, "height" =>24 )
-                        );
+                       $team_array['logo'] = ( empty( $team_information->logo ) ? '' : '<a href="#" class="hover-zoom-square30"><img src="'.$generate_HTML->image_from_id_or_url( $team_information->logo).'" height="24" alt="'.$team_information->logo.'" /></a>' );
                        if ( !empty( $team_information->wp_post_id ) ) {
                                $teams_links = Array();
                                foreach ( explode( ', ', $team_information->wp_post_id ) as $id ) {
@@ -223,9 +221,7 @@ function generate_table_admin_for_thematics() {
                        $thematic_array['id'] = $thematic_information->id;
                        $thematic_array['name_fr'] = '<small>'.$thematic_information->name_fr.'</small>';
                        $thematic_array['name_en'] = '<small>'.$thematic_information->name_en.'</small>';
-                       $thematic_array['logo'] = $generate_HTML->image_from_id_or_url( $thematic_information->logo,
-                               array("href" => "#", "a_class" => "hover-zoom-square30", "width" => 24, "height" =>24 )
-                        );
+                       $thematic_array['logo'] = ( empty( $thematic_information->logo ) ? '' : '<a href="#" class="hover-zoom-square30"><img src="'.$generate_HTML->image_from_id_or_url($thematic_information->logo).'" height="24" alt="'.$thematic_information->logo.'" /></a>' );
                        $thematic_array['external_url'] = ( empty( $thematic_information->external_url ) ? '' : '<a href="'.$thematic_information->external_url.'">'.__( 'lien', 'mon-laboratoire' ).'</a>' );
                        $thematic_array['hal_publi_thematic_id'] = $thematic_information->hal_publi_thematic_id;
                        $teams_information = $MonLabo_access_data->get_teams_information_for_a_thematic( $thematic_information->id );
@@ -294,9 +290,7 @@ function generate_table_admin_for_units() {
                        $unit_array['id'] = $unit_information->id;
                        $unit_array['name_fr'] = '<small>'.$unit_information->name_fr.'</small>';
                        $unit_array['name_en'] = '<small>'.$unit_information->name_en.'</small>';
-                       $unit_array['logo'] = $generate_HTML->image_from_id_or_url( $unit_information->logo,
-                               array("href" => "#", "a_class" => "hover-zoom-square30", "width" => 24, "height" =>24 )
-                        );
+                       $unit_array['logo'] = ( empty( $unit_information->logo ) ? '' : '<a href="#" class="hover-zoom-square30"><img src="'.$generate_HTML->image_from_id_or_url( $unit_information->logo ).'" height="24" alt="'.$unit_information->logo.'" /></a>' );
                        $unit_array['code'] = $unit_information->code;
                        $unit_array['affiliations'] = '<small>'.$unit_information->affiliations.'</small>';
                        $unit_array['external_url'] = ( empty( $unit_information->external_url ) ? '' : '<a href="'.$unit_information->external_url.'">'.__( 'lien', 'mon-laboratoire' ).'</a>' );
index 9a37a67..179df9e 100644 (file)
@@ -242,10 +242,7 @@ function displayOneMorePageField() {
  * @since 2.1.0 with name effacer_choix_media
  * @since 2.8.0 renamed selectNoPicture
  */
-function selectNoPicture( imagePreviewFieldId = 'image-preview',
-       imageAttachementUrlFieldId = 'image_attachment_url',
-       imageAttachementIdFieldId = 'image_attachment_id' ) {
-       jQuery( '#' + imageAttachementUrlFieldId ).val( '' );
+function selectNoPicture( imagePreviewFieldId ,        imageAttachementIdFieldId ) {
     jQuery( '#' + imageAttachementIdFieldId ).val( '' );
        jQuery( '#' + imagePreviewFieldId ).attr( 'src', '' ).css( 'width', 'auto' );
        jQuery( '#' + imagePreviewFieldId ).removeAttr( 'srcset' );
index 5aeb9df..8a88877 100644 (file)
@@ -77,7 +77,6 @@ Remember, check_admin_referer alone is not bulletproof security. Do not rely on
 == Changelog ==
 
 = 3.1 =
-===> Vérifier que la gestion des logos des équipes, unités et autre sont bien gérés.
 * EVOL: A person can have several pages
 * CODE : Secure ajax code with a nonce to prevent unauthorized access
 * CODE : Secure all actions that accept POST with a nonce to prevent unauthorized access
@@ -99,6 +98,7 @@ Remember, check_admin_referer alone is not bulletproof security. Do not rely on
 * BUG : Correction of poor display of radio buttons in config interface.
 * DESIGN : Always display customize text config tab. Lighten functionalites config tab.
 * EVOL : Can use several emails for a single person
+* CODE/BUG : Rewrite all code for chose an image as a logo for Thematic, team or unit. Sometimes it was non functionnal.
 
 = 3.0.5 =
 (GIT tag v3.0.5)
index 2eb0956..5c44b4d 100644 (file)
@@ -183,11 +183,8 @@ class MonLabo_generate_HTML {
                $wp_post_ids = explode( ',', $team_information->wp_post_id );
                $wp_post_id = $wp_post_ids[0];
                // Prepare picture of the team
-
-               if ( $with_logo ) {
-                       $team_logo = $this->image_from_id_or_url( $team_information->logo,
-                               array( "img_class" => 'wp-image-8 alignleft wp-post-image team_logo', "width" => 70, "height" =>70, "alt" => ' ' )
-                        );
+               if ( ( '' != $team_information->logo ) && $with_logo ) {
+                       $team_logo = "<img src='".$this->image_from_id_or_url($team_information->logo)."' class='wp-image-8 alignleft wp-post-image team_logo' height='70' width='70' alt=' ' />";
                } else {
                        $team_logo = '';
                }
@@ -619,17 +616,9 @@ class MonLabo_generate_HTML {
                                        $logos_other_thematics .= "<div class='teams-list-other-thematics-logos'>";
                                        foreach ( $thematics_information[$team_information->id] as $other_thematic ) {
                                                if ( $other_thematic->id != $thematic ) {
-                                                       //$logos_other_thematics .= "<a href='".$other_thematic->external_url."' class='MonLaboLink' title='Other thematic of the team : ";
-                                                       //$logos_other_thematics .= MonLaboLib::to_html( $other_thematic->$nom )."'>";
-                                                       $logos_other_thematics .= $this->image_from_id_or_url( $other_thematic->logo,
-                                                               array(
-                                                                       "a_class" => 'MonLaboLink',
-                                                                       "href"=> $other_thematic->external_url,
-                                                                       "img_class" => 'thematics_logo',
-                                                                       "alt" => " ",
-                                                                       "title" => 'Other thematic of the team : '. MonLaboLib::to_html( $other_thematic->$nom ) )
-                                                       );
-                                                       $logos_other_thematics .= "</a>";
+                                                       $logos_other_thematics .= "<a href='".$other_thematic->external_url."' class='MonLaboLink' title='Other thematic of the team : ";
+                                                       $logos_other_thematics .= MonLaboLib::to_html( $other_thematic->$nom )."'><img src='".$this->image_from_id_or_url( $other_thematic->logo );
+                                                       $logos_other_thematics .= "' class='thematics_logo' alt=' '></a>";
                                                }
                                        }
                                        $logos_other_thematics .= '</div>';
@@ -1059,56 +1048,16 @@ class MonLabo_generate_HTML {
        }
 
        /**
-        * Create HTML code of an image from an image ID or URL (autodetect)
+        * Get URL of an image from an image ID or URL (autodetect)
         *
         * @param string $id_or_url value that can be either an URL or a WordPress image ID
-        * @param  array $imagedata array of facultative parameters
-        *  'image_id' => ID of the image
-        *  'href' => link of of surrounding <a> (no link if empty)
-        *  'a_class' => class of surrounding <a>
-        *  'img_class' => class of <img>
-        *  'width width' => of the image in pixels
-        *  'height' => height of the image in pixels
-        *  'alt' => alt fielf of <img>
-        *  'title' => title fielf of <a>
-        *  'default_image' => iamge to display if $id_or_url empty
-        *
-        * @return string code HTML
+        * @return string URL
         */
-       function image_from_id_or_url( $id_or_url, $imagedata ){
-               $a_class                = empty( $imagedata['a_class'] )                ? '' : $imagedata['a_class'];
-               $href                   = empty( $imagedata['href'] )                   ? '' : $imagedata['href'];
-               $image_id               = empty( $imagedata['image_id'] )               ? uniqid() : $imagedata['image_id'];
-               $img_class              = empty( $imagedata['img_class'] )              ? "wp-image-8 wp-post-image" : $imagedata['img_class'];
-               $width                  = empty( $imagedata['width'] )                  ? 30 : $imagedata['width'];
-               $height                 = empty( $imagedata['height'] )                 ? 30 : $imagedata['height'];
-               $default_image  = empty( $imagedata['default_image'] )  ? '' : $imagedata['default_image'];
-               $alt                    = empty( $imagedata['alt'] )                    ? $id_or_url : $imagedata['alt'];
-               $title                  = empty( $imagedata['title'] )                  ? '' : " title='" . $imagedata['title'] . "'";
-               $default_image  = empty( $imagedata['default_image'] )  ? '' : $imagedata['default_image'];
-               $hide_if_empty  = empty( $imagedata['hide_if_empty'] )  ? false : $imagedata['hide_if_empty'];
-
-               $html = "";
-               $supl_class = "";
-               if( empty( $id_or_url ) ) {
-                       $url = $default_image;
-                       if ( empty($default_image)  ) {
-                               $supl_class=" hidden";
-                       }
-               } elseif ( is_numeric( $id_or_url ) ) {
-                       $url = wp_get_attachment_image_src( $id_or_url, array( $width, $height ) )[0];
+       function image_from_id_or_url( $id_or_url ){
+               if ( is_numeric( $id_or_url ) ) {
+                       return wp_get_attachment_image_src( $id_or_url, array( $width, $height ) )[0];
                } else {
-                       $url = $id_or_url;
+                       return $id_or_url;
                }
-               if( ( !empty( $url ) ) or $hide_if_empty ) {
-                       if( !empty( $href ) ) {
-                               $html .= "<a href='" . $href . "' class='" . $a_class . "'".$title.">";
-                       }
-                       $html .= "<img width='" . $width . "' height='" . $height . "' id='" . $image_id . "' class='" . $img_class . $supl_class."' src='".$url."' alt='".$alt."'>";
-                       if( !empty( $href ) ) {
-                               $html .= '</a>';
-                       }
-               }
-               return $html;
        }
 }