• Resolved jhdean

    (@jhdean)


    Hi David,

    I entered a fairly long template in the EXIF/Template Value text box. When I save changes the template is truncated. This is fine if I keep a copy in another file and paste it in after making edits. I assume it is stored somewhere as it works even though it doesn’t all show in the text box.

    Is there a way to edit it in the browser when it has more characters than the text box can display at once?

    Here is the example which creates a link using the hyphenated lower case title and the actual title of the image:
    template:( <a id="detail-title" target="blank" href="https://www.jhdstaging.jeffreyhdean.com/portfolio/ [+iptc:2#103+] /"> [+iptc:2#005+] </a>)

    Thanks,
    Jeff

    https://www.ads-software.com/plugins/media-library-assistant/

Viewing 9 replies - 1 through 9 (of 9 total)
  • Thread Starter jhdean

    (@jhdean)

    Also,

    I didn’t see it in the documentation. Is there way to change the case of what is being mapped and do a search and replace as well.

    I want to convert “File Name” to “file-name”.

    I am doing this in Lightroom with a Keyboard Maestro script but it requires another step and using another IPTC field.

    Thanks,
    Jeff

    Plugin Author David Lingren

    (@dglingren)

    Thanks for your questions. I entered the template you gave in your first post in the EXIF/Template text box on the Settings/Media Library Assistant IPTC/EXIF tab.

    As you observed, the text box only shows the first part of the template. In my browser (Internet Explorer 11 in Windows Seven), you can access and edit the rest of the value by placing the cursor in the text box and using the arrow keys to move back and forth through the entire template.

    I scrolled to the bottom and clicked “Save Changes”. I do not see any truncation of the template I entered. Is the example you gave being truncated on your system? If so, what browser do you use?

    You also wrote “Is there way to change the case of what is being mapped and do a search and replace as well.” This is a variation on an earlier support topic:

    Using media Path to populate att. Category

    If you look at that topic and the other topics it references you will see how they use the mla-simple-mapping-hooks-example.php.txt example in the /media-library-assistant/examples directory. You can do anything you want with the data being mapped by adapting the example code to your specific needs. If you need additional help with that, post an update here and I will give you more specific information.

    I will leave this topic unresolved until I hear back from you on the truncation issue. Thanks for your interest in the plugin.

    Thread Starter jhdean

    (@jhdean)

    The truncation and lack of the use of the right arrow to navigate beyond it is manifesting on my Mac using Chrome, Firefox and Safari.

    I’ll check the other topic for ways to manipulate the data. Thanks for the great plugin.

    Jeff

    Thread Starter jhdean

    (@jhdean)

    The truncation and lack of the use of the right arrow to navigate beyond it is manifesting on my Mac using Chrome, Firefox and Safari.

    I’m trying to decide whether modifying the mla-mapping-hooks-example.php file is over my head or not. I found reference to the php srtrolower( ) function and added that.

    $new_title = strtolower(str_replace( array( ' '), '-', $old_value ));

    So if the mla_mapping_updates_filter( ) function is called after the mapping rules are evaluated and before the fields are updated, how do I get the $new_title value into the template in place of “[+iptc:2#103+] ” if the template has already been evaluated during the initial mapping rule evaluation?

    Jeff

    Plugin Author David Lingren

    (@dglingren)

    Thanks for posting your updates and for taking the time to play with the suggested example plugin. Including your code sample is also very helpful.

    Regarding “The truncation and lack of the use of the right arrow to navigate beyond it is manifesting on my Mac using Chrome, Firefox and Safari.” – I have tried your template on all three of those browsers (in Windows Seven) and do not see the truncation issue in any of them. I’d hate to think it’s Mac-specific.

    However, working with your template did uncover some MLA defects in the handling of double-quotes in the EXIF/Template field. Thank you for bringing this to my attention!

    I will be uploading a new Development Version with a fix for these defects. Perhaps that will help with the truncation as well, although I think that unlikely.

    Regarding your PHP coding adventures, first make sure you are using the mla-simple-mapping-hooks-example.php.txt (note simple) file. The other mapping example is much more complicated!

    Assuming you’re using the “simple” example, I can give you some code to put in the mla_mapping_updates_filter() function, but I want to make sure I clearly understand your goal. The example you gave was “File Name” to “file-name”; is that literally true or do you want a more general conversion of whatever is found in the IPTC 2#103 field? Your code sample suggests that you want to convert the entire value to lowercase and replace all spaces with dashes; is that right? IPTC 2#103 is defined as:

    original-transmission-reference – Max 32 characters of a code representing the location of original transmission

    That seems like an odd choice for building a URL – are you just using it as a carrier for something else?

    Any additional details you can supply will let me be more specifically helpful.

    Thread Starter jhdean

    (@jhdean)

    Hi David,

    The IPTC 2#103 was something I was using as a carrier for an already converted image title. I populated it in Lightroom with the lowercase and hyphenated Title. With that I was able to test the mapping rule which proved to work.

    So now I am trying to use the filter() function to convert the Title on the fly as the images are imported in order to save the extra work in Lightroom. Thus, I don’t intend to continue using IPTC 2#103 if I can get the php to do the job.

    The intent is to pull the Title from IPTC 2#005 and convert it to hyphenated lowercase to be used in the URL with the actual Title used in-between the <a tags.

    template:( <a id="detail-title" target="blank" href="https://www.jhdstaging.jeffreyhdean.com/portfolio/ [+ ****THE RESULT OF THE PHP FUNCTION GOES HERE**** +] /"> [+iptc:2#005+] </a>)

    My simplified sense of how this would work is:
    1. The mapping rules evaluate the image data.
    2. The php function converts the Title.
    3 The result is passed into the mapping rule template.
    4. The data is written to the fields.
    Is this anywhere close to what happens? I am rather confused about how it can work as it seems the php function has to be run simultaneously with the template.

    Thank you for your generous support,
    Jeff

    Plugin Author David Lingren

    (@dglingren)

    I think I understand what you are after, but it occurs to me that there is one more piece of information I need.

    Where do the template results go, i.e., what field are you storing the URL in? Is it a Standard field like Title or a custom field or somewhere else?

    Can you tell me all of the details about the rule containing the template?

    Thread Starter jhdean

    (@jhdean)

    It is in the Title field. I am doing it there because I need to display the link in the FooBox lightbox and Title is the only choice that works among the choices it offers.

    The rule details are:
    Field Title: Title
    IPTC value: None
    EXIF/Template Value: template:( [+iptc:2#005+] )
    Priority: EXIF
    Existing Text: Replace

    Thanks,
    Jeff

    Plugin Author David Lingren

    (@dglingren)

    Thanks for working with me offline to develop and test the solution for your application. Here is the final version of the small custom plugin we came up with:

    <?php
    /**
     * Provides an example of the filters provided by the IPTC/EXIF and Custom Field mapping features
     *
     * In this example the Title is replaced by a hyperlink using the IPTC 2#005 Object Name value.
     */
    
    /*
    Plugin Name: MLA jhdean Mapping Hooks Example
    Plugin URI: https://fairtradejudaica.org/media-library-assistant-a-wordpress-plugin/
    Description: Replace Title with hyperlink, for Jeff Dean.
    Author: David Lingren
    Version: 1.00
    Author URI: https://fairtradejudaica.org/our-story/staff/
    
    Copyright 2014 - 2015 David Lingren
    
        This program is free software; you can redistribute it and/or modify
        it under the terms of the GNU General Public License as published by
        the Free Software Foundation; either version 2 of the License, or
        (at your option) any later version.
    
        This program is distributed in the hope that it will be useful,
        but WITHOUT ANY WARRANTY; without even the implied warranty of
        MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
        GNU General Public License for more details.
    
        You can get a copy of the GNU General Public License by writing to the
        Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA
    */
    
    /**
     * Class MLA jhdean Mapping Hooks Example hooks one of the filters provided by the MLA mapping features
     *
     * Call it anything you want, but give it an unlikely and hopefully unique name. Hiding everything
     * else inside a class means this is the only name you have to worry about.
     */
    class MLAjhdeanMappingHooksExample {
        /**
         * Initialization function, similar to __construct()
         *
         * Installs filters and actions that handle the MLA hooks for uploading and mapping.
         */
        public static function initialize() {
            /*
             * The filters are only useful in the admin section; exit if in the "front-end" posts/pages.
             */
            if ( ! is_admin() )
                return;
    
            add_filter( 'mla_mapping_updates', 'MLAjhdeanMappingHooksExample::mla_mapping_updates_filter', 10, 5 );
        }
    
        /**
         * MLA Mapping Updates Filter
         *
         * This filter is called AFTER all mapping rules are applied.
         * You can add, change or remove updates for the attachment's
         * standard fields, taxonomies and/or custom fields.
         *
         * @param    array    updates for the attachment's standard fields, taxonomies and/or custom fields
         * @param    integer post ID to be evaluated
         * @param    string     category/scope to evaluate against: custom_field_mapping or single_attachment_mapping
         * @param    array     mapping rules
         * @param    array     attachment_metadata, default NULL
         *
         * @return    array    updated attachment's updates
         */
        public static function mla_mapping_updates_filter( $updates, $post_id, $category, $settings, $attachment_metadata ) {
            /*
             * We are only concerned with Standard Field mapping
             */
            if ( ! in_array( $category, array( 'iptc_exif_mapping', 'iptc_exif_standard_mapping' ) ) ) {
                return $updates;
            }
    
            /*
             * If $updates[ 'post_title' ] is set, some mapping rule
             * has been set up, so we respect the result. If not,
             * use whatever the current Title value is.
             */
            if ( isset( $updates[ 'post_title' ] ) ) {
                $old_value = $updates[ 'post_title' ];
            } else {
                $post = get_post( $post_id );
                $old_value = $post->post_title;
            }
    
            /*
             * Derive the new Title from the IPTC Object Name, if present.
             * You can use MLAOptions::mla_get_data_source() to get anything available.
             */
            $my_setting = array(
                'data_source' => 'template',
                'meta_name' => '([+iptc:2#005+])',
                'option' => 'raw'
            );
            $object_name = trim( MLAOptions::mla_get_data_source( $post_id, 'single_attachment_mapping', $my_setting, NULL ) );
    
            if ( ! empty( $object_name ) ) {
                $object_link = strtolower( str_replace( array( ' ', '-', '_', '.' ), '-', $object_name ) );
    
                $new_title = sprintf( '<a id="detail-title" target="blank" href="https://www.jhdstaging.jeffreyhdean.com/portfolio/%1$s/"> %2$s </a>', $object_link, $object_name );
    
                if ( $old_value != $new_title ) {
                    $updates[ 'post_title' ] = $new_title;
                }
            }
    
            return $updates;
        } // mla_mapping_updates_filter
    } //MLAjhdeanMappingHooksExample
    
    /*
     * Install the filters at an early opportunity
     */
    add_action('init', 'MLAjhdeanMappingHooksExample::initialize');
    ?>

    I will add this example to the /media-library-assistant/examples directory in my next MLA version. Thanks again for the application idea, for your help and for your donation in support of our work and the MLA plugin.

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘EXIF/Template Value editing’ is closed to new replies.