0.4
This commit is contained in:
parent
4d20641b1b
commit
cc04a4c0b3
3 changed files with 51 additions and 92 deletions
|
@ -1,8 +1,8 @@
|
||||||
{
|
{
|
||||||
"name": "petermolnar/wp-extraexif",
|
"name": "petermolnar/wp-extraexif",
|
||||||
"description": "Autofill content and tags from featured image EXIF & IPTC",
|
"description": "WordPress plugin to extract EXIF via exiftool",
|
||||||
"require": {
|
"require": {
|
||||||
"php": ">=5.3.0",
|
"php": ">=5.4.0",
|
||||||
},
|
},
|
||||||
"license": "GPLv3",
|
"license": "GPLv3",
|
||||||
"authors": [
|
"authors": [
|
||||||
|
|
21
readme.txt
21
readme.txt
|
@ -1,13 +1,13 @@
|
||||||
=== wp-extraexif ===
|
=== wp-extraexif ===
|
||||||
Contributors: cadeyrn
|
Contributors: cadeyrn
|
||||||
Tags:
|
Tags: exif, image, media
|
||||||
Requires at least: 3.0
|
Requires at least: 4.0
|
||||||
Tested up to: 4.5.3
|
Tested up to: 4.6
|
||||||
Stable tag: 0.1
|
Stable tag: 0.4
|
||||||
License: GPLv3
|
License: GPLv3
|
||||||
License URI: http://www.gnu.org/licenses/gpl-3.0.html
|
License URI: http://www.gnu.org/licenses/gpl-3.0.html
|
||||||
|
|
||||||
Autofill content and tags from featured image EXIF & IPTC
|
A plugin that uses [exiftool](http://owl.phy.queensu.ca/~phil/exiftool/) to read EXIF values of an image.
|
||||||
|
|
||||||
== Description ==
|
== Description ==
|
||||||
|
|
||||||
|
@ -26,6 +26,17 @@ Version numbering logic:
|
||||||
* every .B version indicates new features.
|
* every .B version indicates new features.
|
||||||
* every ..C indicates bugfixes for A.B version.
|
* every ..C indicates bugfixes for A.B version.
|
||||||
|
|
||||||
|
= 0.4 =
|
||||||
|
*2016-09-07*
|
||||||
|
|
||||||
|
* filters added for extractable EXIF values
|
||||||
|
|
||||||
|
= 0.3 =
|
||||||
|
*2016-08-20*
|
||||||
|
|
||||||
|
* EXIF is not merged with WordPress attachment meta any more but instead created as standalone JSON files based on the full file path hash, so it's easy to read.
|
||||||
|
|
||||||
|
|
||||||
= 0.1 =
|
= 0.1 =
|
||||||
*2016-07-22*
|
*2016-07-22*
|
||||||
|
|
||||||
|
|
118
wp-extraexif.php
118
wp-extraexif.php
|
@ -2,8 +2,8 @@
|
||||||
/*
|
/*
|
||||||
Plugin Name: wp-extraexif
|
Plugin Name: wp-extraexif
|
||||||
Plugin URI: https://github.com/petermolnar/wp-extraexif
|
Plugin URI: https://github.com/petermolnar/wp-extraexif
|
||||||
Description: Read extra EXIF for images with exiftool
|
Description: Read EXIF for images with cli `exiftool`
|
||||||
Version: 0.2
|
Version: 0.4
|
||||||
Author: Peter Molnar <hello@petermolnar.net>
|
Author: Peter Molnar <hello@petermolnar.net>
|
||||||
Author URI: http://petermolnar.net/
|
Author URI: http://petermolnar.net/
|
||||||
License: GPLv3
|
License: GPLv3
|
||||||
|
@ -29,38 +29,11 @@ namespace WP_EXTRAEXIF;
|
||||||
|
|
||||||
\add_action( 'init', 'WP_EXTRAEXIF\init' );
|
\add_action( 'init', 'WP_EXTRAEXIF\init' );
|
||||||
\register_activation_hook( __FILE__ , '\WP_EXTRAEXIF\plugin_activate' );
|
\register_activation_hook( __FILE__ , '\WP_EXTRAEXIF\plugin_activate' );
|
||||||
\register_deactivation_hook( __FILE__ , '\WP_EXTRAEXIF\plugin_deactivate' );
|
//\register_deactivation_hook( __FILE__ , '\WP_EXTRAEXIF\plugin_deactivate' );
|
||||||
|
|
||||||
define ( 'WP_EXTRAEXIF\CACHEDIR', \WP_CONTENT_DIR . DIRECTORY_SEPARATOR.
|
define ( 'WP_EXTRAEXIF\CACHE', \WP_CONTENT_DIR . DIRECTORY_SEPARATOR.
|
||||||
'cache' . DIRECTORY_SEPARATOR . 'exif' . DIRECTORY_SEPARATOR );
|
'cache' . DIRECTORY_SEPARATOR . 'exif' . DIRECTORY_SEPARATOR );
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
function defaults() {
|
|
||||||
// hardcoded
|
|
||||||
$config = array (
|
|
||||||
// exiftool value => store as meta key
|
|
||||||
'LensID' => 'lens',
|
|
||||||
'GPSLatitude' => 'geo_latitude',
|
|
||||||
'GPSLongitude' => 'geo_longitude',
|
|
||||||
'GPSAltitude' => 'geo_altitude',
|
|
||||||
'Title' => 'title',
|
|
||||||
);
|
|
||||||
|
|
||||||
$ini = dirname( __FILE__ ) . DIRECTORY_SEPARATOR . 'config.ini';
|
|
||||||
if ( file_exists ( $ini ) ) {
|
|
||||||
$config = array_merge ( $config, parse_ini_file( $ini ) );
|
|
||||||
}
|
|
||||||
|
|
||||||
$current = \get_option( __NAMESPACE__ );
|
|
||||||
|
|
||||||
if ( $current != $config )
|
|
||||||
\update_option( __NAMESPACE__, $config );
|
|
||||||
|
|
||||||
return $config;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* activate hook
|
* activate hook
|
||||||
*/
|
*/
|
||||||
|
@ -74,7 +47,7 @@ function plugin_activate() {
|
||||||
if ( true !== $test )
|
if ( true !== $test )
|
||||||
die ( $test );
|
die ( $test );
|
||||||
|
|
||||||
$dirs = [ CACHEDIR ];
|
$dirs = [ CACHE ];
|
||||||
foreach ( $dirs as $dir ) {
|
foreach ( $dirs as $dir ) {
|
||||||
if ( ! is_dir( $dir ) ) {
|
if ( ! is_dir( $dir ) ) {
|
||||||
if ( ! mkdir( $dir ) )
|
if ( ! mkdir( $dir ) )
|
||||||
|
@ -83,20 +56,13 @@ function plugin_activate() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* activate hook
|
|
||||||
*/
|
|
||||||
function plugin_deactivate() {
|
|
||||||
\delete_option( __NAMESPACE__ );
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
function init() {
|
function init() {
|
||||||
add_filter( 'wp_read_image_metadata', 'WP_EXTRAEXIF\read_extra_exif', 1, 3 );
|
add_filter( 'wp_read_image_metadata', 'WP_EXTRAEXIF\read_extra_exif', 1, 3 );
|
||||||
|
|
||||||
$dirs = [ CACHEDIR ];
|
$dirs = [ CACHE ];
|
||||||
foreach ( $dirs as $dir ) {
|
foreach ( $dirs as $dir ) {
|
||||||
if ( ! is_dir( $dir ) ) {
|
if ( ! is_dir( $dir ) ) {
|
||||||
if ( ! mkdir( $dir ) )
|
if ( ! mkdir( $dir ) )
|
||||||
|
@ -105,6 +71,10 @@ function init() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* check the existence and executability of exiftool
|
||||||
|
*
|
||||||
|
*/
|
||||||
function test_exiftool () {
|
function test_exiftool () {
|
||||||
if ( ! function_exists( 'exec' ) )
|
if ( ! function_exists( 'exec' ) )
|
||||||
return "This plugin requires `exec` function which is not available.";
|
return "This plugin requires `exec` function which is not available.";
|
||||||
|
@ -141,49 +111,6 @@ function read_extra_exif ( $meta, $path ='', $sourceImageType = '' ) {
|
||||||
return $meta;
|
return $meta;
|
||||||
}
|
}
|
||||||
|
|
||||||
$extra = \get_option( __NAMESPACE__, defaults() );
|
|
||||||
|
|
||||||
$args = $metaextra = array();
|
|
||||||
|
|
||||||
foreach ($extra as $exiftoolID => $metaid ) {
|
|
||||||
// only try to get the missing
|
|
||||||
if ( ! isset( $meta[ $metaid ]) ) {
|
|
||||||
$args[] = $exiftoolID;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( empty( $args ) )
|
|
||||||
return $meta;
|
|
||||||
|
|
||||||
$args = join(' -', $args);
|
|
||||||
$cmd = "exiftool -s -{$args} {$path}";
|
|
||||||
|
|
||||||
//debug("Extracting extra EXIF for {$path} with command {$cmd}", 7 );
|
|
||||||
exec( $cmd, $exif, $retval);
|
|
||||||
|
|
||||||
if ($retval != 0 ) {
|
|
||||||
debug("Extracting extra EXIF failed with error code ${retval}", 4 );
|
|
||||||
return $meta;
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach ( $exif as $cntr => $data ) {
|
|
||||||
$data = array_map( 'trim', explode (' : ', $data ) );
|
|
||||||
|
|
||||||
if ( $data[0] == 'GPSLatitude' || $data[0] == 'GPSLongitude' )
|
|
||||||
$data[1] = exif_gps2dec( $data[1] );
|
|
||||||
elseif ( $data[0] == 'GPSAltitude' )
|
|
||||||
$data[1] = exif_gps2alt( $data[1] );
|
|
||||||
|
|
||||||
$metaextra[ $extra[ $data[0] ] ] = $data[1];
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( ! empty( $metaextra ) ) {
|
|
||||||
//debug ( "Adding extra EXIF", 7);
|
|
||||||
//debug ( $metaextra, 7 );
|
|
||||||
$meta = array_merge($meta, $metaextra);
|
|
||||||
}
|
|
||||||
|
|
||||||
//debug ( $path );
|
|
||||||
exif_cache( $path );
|
exif_cache( $path );
|
||||||
|
|
||||||
return $meta;
|
return $meta;
|
||||||
|
@ -216,15 +143,33 @@ function exif_gps2alt ( $string ) {
|
||||||
return $alt;
|
return $alt;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
function clear_cache() {
|
||||||
|
$list = scandir( CACHE );
|
||||||
|
|
||||||
|
foreach ($list as $key => $name ) {
|
||||||
|
$path = realpath( CACHE . $name );
|
||||||
|
|
||||||
|
if ( is_file( $path ) && ! in_array ( $name, array( '.', '..' ) ) ) {
|
||||||
|
unlink( $path );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
function exif_cache( $jpg ) {
|
function exif_cache( $jpg ) {
|
||||||
|
|
||||||
if ( ! is_file( $jpg ) ) {
|
if ( ! is_file( $jpg ) ) {
|
||||||
debug( "nonexistend JPG file at {$jpg}", 4 );
|
debug( "nonexistent JPG file at {$jpg}", 4 );
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$hash = md5 ( $jpg );
|
$hash = md5 ( $jpg );
|
||||||
$cached = CACHEDIR . $hash;
|
$cached = CACHE . $hash;
|
||||||
$img_timestamp = @filemtime ( $jpg );
|
$img_timestamp = @filemtime ( $jpg );
|
||||||
|
|
||||||
if ( is_file( $cached ) ) {
|
if ( is_file( $cached ) ) {
|
||||||
|
@ -251,11 +196,13 @@ function exif_cache( $jpg ) {
|
||||||
'Create Date',
|
'Create Date',
|
||||||
'Copyright Notice',
|
'Copyright Notice',
|
||||||
];
|
];
|
||||||
|
$filters = \apply_filters( 'wp_extraexif_list', $filters );
|
||||||
|
|
||||||
$merges = [
|
$merges = [
|
||||||
'Shutter Speed' => 'Exposure Time',
|
'Shutter Speed' => 'Exposure Time',
|
||||||
'Aperture' => 'F Number',
|
'Aperture' => 'F Number',
|
||||||
];
|
];
|
||||||
|
$merges = \apply_filters( 'wp_extraexif_merges', $merges );
|
||||||
|
|
||||||
$mapping = [
|
$mapping = [
|
||||||
'Make' => 'make',
|
'Make' => 'make',
|
||||||
|
@ -273,6 +220,7 @@ function exif_cache( $jpg ) {
|
||||||
'Create Date' => 'date',
|
'Create Date' => 'date',
|
||||||
'Copyright Notice' => 'copyright',
|
'Copyright Notice' => 'copyright',
|
||||||
];
|
];
|
||||||
|
$mapping = \apply_filters( 'wp_extraexif_mapping', $mapping );
|
||||||
|
|
||||||
$cmd = "exiftool {$jpg}";
|
$cmd = "exiftool {$jpg}";
|
||||||
exec( $cmd, $exif_raw, $retval);
|
exec( $cmd, $exif_raw, $retval);
|
||||||
|
|
Loading…
Reference in a new issue