Plugin Directory

Changeset 2381538


Ignore:
Timestamp:
09/15/2020 12:29:06 AM (6 years ago)
Author:
Driftless1
Message:

Fix guideline violations

Location:
exifize-my-dates/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • exifize-my-dates/trunk/exifize-my-dates.php

    r1725193 r2381538  
    44Plugin URI: http://wordpress.org/extend/plugins/exifize-my-dates/
    55Description: Photoblog plugin to change the published dates of a selected post type to the EXIF:capture_date of the Featured or 1st attached image of the post.
    6 Version: 1.3
     6Version: 1.5
    77Author: LBell
    8 Author URI: http://twitter.com/lbell
     8Author URI: lorenbell.com
    99License: GPL2
    1010
    11     Copyright 2017 -- Loren Bell
     11    Copyright 2020 -- LBell
    1212    This program is free software; you can redistribute it and/or modify
    1313    it under the terms of the GNU General Public License, version 2, as
     
    4141    <?php
    4242
     43  // Get Post Types
     44  $args=array(
     45    'public'   => true,
     46    //'_builtin' => false
     47  );
     48  $output = 'objects';
     49  $operator = 'and';
     50  $post_types = get_post_types($args,$output,$operator);
     51  $types_list = array();
     52  foreach ($post_types  as $post_type ){
     53    if($post_type->name != 'attachment') $types_list[] = $post_type->name;
     54  }
     55 
    4356    if(isset($_POST['submit']) && $_POST['ptype'] != 'none') {
    44         // Check nonce if we are asked to do something...
    45         if( check_admin_referer('exifize_my_dates_nuclear_nonce') ){
    46             $ptype = $_POST['ptype'];
     57    $ptype = sanitize_text_field( $_POST['ptype'] );
     58
     59    // Check nonce if we are asked to do something...
     60        if( check_admin_referer('exifize_my_dates_nuclear_nonce') && in_array( $ptype, $types_list ) ){
    4761            exifizer_nuclear_option($ptype);
    4862        } else {
     
    5165    }
    5266
    53     $args=array(
    54         'public'   => true,
    55         //'_builtin' => false
    56     );
    57     $output = 'objects';
    58     $operator = 'and';
    59     $post_types = get_post_types($args,$output,$operator);
     67
    6068    ?>
    6169
     
    112120    foreach($allposts as $post) : setup_postdata($post);
    113121
    114         $exifdate = 'none'; //safety
    115         $postid = $post->ID;
    116         $posttitle = $post -> post_title;
    117         $postdate = $post -> post_date;
    118         $metadate = trim(get_post_meta($postid, 'exifize_date', true));
    119         $pediturl = get_admin_url() . "post.php?post=" . $postid . "&action=edit";
    120 
    121         echo "<p>Processing " . $ptype . " <a href = \"". $pediturl . "\" title=\"Edit " . $ptype . " \">" . $postid . ": \"" . $posttitle . "\"</a> ";
    122 
    123         if($metadate && $metadate != ''){                               //If custome meta `efize_date` is set, use it
    124             switch ($metadate){
    125             case date('Y-m-d H:i:s', strtotime($metadate)):  //check for correct date format
    126                 $exifdate = $metadate;
    127                 $exifdetails = "exifize_date custom meta";
     122        $exif_date = 'none'; //safety
     123        $post_id = $post->ID;
     124        $post_title = $post -> post_title;
     125        $post_date = $post -> post_date;
     126        $meta_date = trim(get_post_meta($post_id, 'exifize_date', true));
     127        $post_edit_url = get_admin_url() . "post.php?post=" . $post_id . "&action=edit";
     128
     129        echo "<p>Processing " . $ptype . " <a href = \"". $post_edit_url . "\" title=\"Edit " . $ptype . " \">" . $post_id . ": \"" . $post_title . "\"</a> ";
     130
     131    //If custom meta `exifize_date` is set, use it
     132    if($meta_date && $meta_date != ''){                                 
     133            switch ($meta_date){
     134            case date('Y-m-d H:i:s', strtotime($meta_date)):
     135                $exif_date = $meta_date;
     136                $exif_details = "exifize_date custom meta";
    128137                break;
    129138            case 'skip':
    130                 $exifdate = 'skip';
     139                $exif_date = 'skip';
    131140                break;
    132141            default:
    133                 $exifdate = 'badmeta';
    134             }
     142                $exif_date = 'badmeta';
     143      }
     144    // Otherwise, try to get the featured image id
    135145        }else{
    136             $attachid = get_post_thumbnail_id($postid); // First, try to get the featured image id
    137 
    138             if($attachid){
    139                 $exifdetails = "Featured Image";
    140                 $attachname = get_post( $attachid )->post_title;
    141             }else{                                      // if no featured image id, then get first attached
    142                 $attachargs = array(
    143                     'post_parent' => $postid,
     146            $attach_id = get_post_thumbnail_id($post_id);   
     147            if($attach_id){
     148                $exif_details = "Featured Image";
     149        $attach_name = get_post( $attach_id )->post_title;
     150      // if no featured image id, then get first attached
     151            }else{                                     
     152                $attach_args = array(
     153                    'post_parent' => $post_id,
    144154                    'post_type'   => 'attachment',
    145155                    'numberposts' => 1,
     
    147157                );
    148158
    149                 $attachment = get_posts($attachargs);
     159                $attachment = get_posts($attach_args);
    150160
    151161                if($attachment){
    152                     $attachid = $attachment[0]->ID;
    153                     $attachname = $attachment[0]->post_name;
    154                     $exifdetails = "attached image";
     162                    $attach_id = $attachment[0]->ID;
     163                    $attach_name = $attachment[0]->post_name;
     164                    $exif_details = "attached image";
    155165                } else {
    156                     $exifdetails = "What are you doing, Dave?";
     166                    $exif_details = "What are you doing, Dave?";
    157167                }
    158168            } // end if no featured image
     
    160170
    161171
    162             if(!$attachid){
    163                 $exifdate = "none";  // No attachment or thumbnail ID found
     172            if(!$attach_id){
     173                $exif_date = "none";  // No attachment or thumbnail ID found
    164174            } else {
    165                 echo "using EXIF date from " . $exifdetails . " id ". $attachid . ": \"" . $attachname . "\"</p>";
    166 
    167                 $imgmeta = wp_get_attachment_metadata($attachid, false);
    168 
    169                 if($imgmeta && $imgmeta['image_meta']['created_timestamp'] != 0){           //use EXIF date if not 0
    170                     $exifdate = date("Y-m-d H:i:s", $imgmeta['image_meta']['created_timestamp']);
     175                echo "using EXIF date from " . $exif_details . " id ". $attach_id . ": \"" . $attach_name . "\"</p>";
     176
     177                $img_meta = wp_get_attachment_metadata($attach_id, false);
     178
     179                if($img_meta && $img_meta['image_meta']['created_timestamp'] != 0){         //use EXIF date if not 0
     180                    $exif_date = date("Y-m-d H:i:s", $img_meta['image_meta']['created_timestamp']);
    171181                } else {
    172                     $exifdate = 'badexif';
     182                    $exif_date = 'badexif';
    173183                }
    174184            }// end get EXIF date
    175         }// end no metadate
     185        }// end no meta_date
    176186
    177187        // if we have image meta and it is not 0 then...
    178188
    179         switch ($exifdate){
     189        switch ($exif_date){
    180190        case 'skip':
    181             $exifexcuse = __("SKIP: 'exifize_date' meta is set to 'skip'");
    182             $exifexclass = "updated";
     191            $exif_excuse = __("SKIP: 'exifize_date' meta is set to 'skip'");
     192            $excuse_class = "updated";
    183193            break;
    184194        case 'none':
    185             $exifexcuse = __("SKIP: No attachment, featured image, or 'exifize_date' meta found");
    186             $exifexclass = "updated";
     195            $exif_excuse = __("SKIP: No attachment, featured image, or 'exifize_date' meta found");
     196            $excuse_class = "updated";
    187197            break;
    188198        case 'badexif':
    189             $exifexcuse = __("SKIP: WARNING - image EXIF date missing or can't be read");
    190             $exifexclass = "error";
     199            $exif_excuse = __("SKIP: WARNING - image EXIF date missing or can't be read");
     200            $excuse_class = "error";
    191201            break;
    192202        case 'badmeta':
    193             $exifexcuse = __("SKIP: WARNING - 'exifize_date' custom meta is formatted wrong: ") . $metadate;
    194             $exifexclass = "error";
    195             break;
    196         case $postdate:
    197             $exifexcuse = __("Already EXIFized!");
    198             $exifexclass = "updated \" style=\" background:none ";
     203            $exif_excuse = __("SKIP: WARNING - 'exifize_date' custom meta is formatted wrong: ") . $meta_date;
     204            $excuse_class = "error";
     205            break;
     206        case $post_date:
     207            $exif_excuse = __("Already EXIFized!");
     208            $excuse_class = "updated \" style=\" background:none ";
    199209            break;
    200210        default:
    201211            $update_post = array(
    202                 'ID' => $postid,
    203                 'post_date' => $exifdate,
    204                 'post_date_gmt' => $exifdate,
     212                'ID' => $post_id,
     213                'post_date' => $exif_date,
     214                'post_date_gmt' => $exif_date,
    205215                //'edit_date' => true,
    206216            );
     
    209219
    210220            if($howditgo != 0){
    211                 $exifexcuse = "Post " . $howditgo . " EXIFIZED! using " . $exifdetails . " date: " . $exifdate . " " ;
    212                 $exifexclass = "updated highlight";
     221                $exif_excuse = "Post " . $howditgo . " EXIFIZED! using " . $exif_details . " date: " . $exif_date . " " ;
     222                $excuse_class = "updated highlight";
    213223            }else{
    214                 $exifexcuse = "ERROR... something went wrong... with " . $postid .". You might get that checked out.";
    215                 $exifexclass = "error highlight";
     224                $exif_excuse = "ERROR... something went wrong... with " . $post_id .". You might get that checked out.";
     225                $excuse_class = "error highlight";
    216226            } //end howditgo
    217227        } //end switch
    218228
    219         echo "<div class=\"" . $exifexclass . "\"><p>" . $exifexcuse . "</p></div>";
     229        echo "<div class=\"" . $excuse_class . "\"><p>" . $exif_excuse . "</p></div>";
    220230
    221231    endforeach;
  • exifize-my-dates/trunk/readme.txt

    r1725193 r2381538  
    11=== Plugin Name ===
    2 Contributors: Driftless1
     2Contributors: LBell
    33Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=BTMZ87DJDYBPS
    4 Tags: EXIF, date, photoblog, custom, post, bulk,
     4Tags: EXIF, date, photoblog, custom, post, bulk-date-change
    55Requires at least: 3.0
    6 Tested up to: 4.8.1
    7 Stable tag: 1.3
     6Tested up to: 5.5
     7Stable tag: 1.5
    88License: GPLv2 or later
    99License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    4848== Changelog ==
    4949
     50= 1.4 =
     51* Tested with WP 5.5
     52
    5053= 1.3 =
    5154* Tested with WP 4.8
Note: See TracChangeset for help on using the changeset viewer.