This commit is contained in:
JcDenis 2021-08-17 22:24:00 +02:00
parent 3cc6e0b8c3
commit 69f3aca75c
6 changed files with 479 additions and 479 deletions

View file

@ -1,4 +1,6 @@
entryPhotoExifWidget 1.0 - 2016-11-04
===========================================================
* First release
* Find images of an entry and paste their exif on a widget
20210817. entryPhotoExifWidget 1.0.1
- Move to Franck style
20161104. entryPhotoExifWidget 1.0
- First release
- Find images of an entry and paste their exif on a widget

View file

@ -20,3 +20,9 @@ First install entryPhotoExifWidget, manualy from a zip package or from
Dotaddict repository. (See Dotclear's documentation to know how do this)
Add and configure "Photo Exif Widget" from widgets manager.
# MORE
* License : GNU GPL v2
* Source & contribution : [GitHub Page](https://github.com/JcDenis/entryPhotoExifWidget)
* Packages & details: [Dotaddict Page](https://plugins.dotaddict.org/dc2/details/entryPhotoExifWidget)

View file

@ -12,9 +12,8 @@
#
# -- END LICENSE BLOCK ------------------------------------
if (!defined('DC_CONTEXT_ADMIN'))
{
if (!defined('DC_CONTEXT_ADMIN')) {
return null;
}
require_once dirname(__FILE__).'/_widgets.php';
require_once dirname(__FILE__) . '/_widgets.php';

View file

@ -12,22 +12,20 @@
#
# -- END LICENSE BLOCK ------------------------------------
if (!defined('DC_RC_PATH'))
{
if (!defined('DC_RC_PATH')) {
return null;
}
$this->registerModule(
/* Name */ "Entry Photo Exif Widget",
/* Description*/ "Show images exif of an entry",
/* Author */ "Jean-Christian Denis and contibutors",
/* Version */ '1.0',
/* Properties */
array(
'Entry Photo Exif Widget', // Name
'Show images exif of an entry', // Description
'Jean-Christian Denis and contibutors', // Author
'1.0.1', // Version
[
'permissions' => 'admin',
'type' => 'plugin',
'dc_min' => '2.10',
'support' => 'http://forum.dotclear.org/',
'details' => 'http://plugins.dotaddict.org/dc2/details/photoExifWidget'
)
'details' => 'https://plugins.dotaddict.org/dc2/details/entryPhotoExifWidget'
]
);

View file

@ -12,9 +12,8 @@
#
# -- END LICENSE BLOCK ------------------------------------
if (!defined('DC_RC_PATH'))
{
if (!defined('DC_RC_PATH')) {
return null;
}
require_once dirname(__FILE__).'/_widgets.php';
require_once dirname(__FILE__) . '/_widgets.php';

View file

@ -12,19 +12,15 @@
#
# -- END LICENSE BLOCK ------------------------------------
if (!defined('DC_RC_PATH'))
{
if (!defined('DC_RC_PATH')) {
return null;
}
$core->addBehavior(
'initWidgets',
array('entryPhotoExifWidget','setWidget')
);
$core->addBehavior('initWidgets', ['entryPhotoExifWidget', 'setWidget']);
class entryPhotoExifWidget
{
public static $supported_post_type = array('post','page','gal','galitem');
public static $supported_post_type = array('post', 'page', 'gal', 'galitem');
public static $widget_content = '<ul>%s</ul>';
public static $widget_text = '<li class="epew-%s"><strong>%s</strong> %s</li>';
public static $widget_thumb = '<li><img class="img-thumbnail" alt="%s" src="%s" /></li>';
@ -33,7 +29,7 @@ class entryPhotoExifWidget
{
global $core;
$categories_combo = array('-' => '',__('Uncategorized') => 'null');
$categories_combo = array('-' => '', __('Uncategorized') => 'null');
$categories = $core->blog->getCategories();
while($categories->fetch())
{
@ -52,7 +48,7 @@ class entryPhotoExifWidget
$w->create(
'epew',
__('Entry Photo Exif'),
array('entryPhotoExifWidget','getWidget'),
array('entryPhotoExifWidget', 'getWidget'),
null,
__('Show images exif of an entry')
);
@ -65,85 +61,85 @@ class entryPhotoExifWidget
);
$w->epew->setting(
'showmeta_Title',
sprintf(__('Show metadata: %s'),__('Title')),
sprintf(__('Show metadata: %s'), __('Title')),
0,
'check'
);
$w->epew->setting(
'showmeta_Description',
sprintf(__('Show metadata: %s'),__('Descritpion')),
sprintf(__('Show metadata: %s'), __('Descritpion')),
0,
'check'
);
$w->epew->setting(
'showmeta_Location',
sprintf(__('Show metadata: %s'),__('Location')),
sprintf(__('Show metadata: %s'), __('Location')),
0,
'check'
);
$w->epew->setting(
'showmeta_DateTimeOriginal',
sprintf(__('Show metadata: %s'),__('Date')),
sprintf(__('Show metadata: %s'), __('Date')),
0,
'check'
);
$w->epew->setting(
'showmeta_Make',
sprintf(__('Show metadata: %s'),__('Manufacturer')),
sprintf(__('Show metadata: %s'), __('Manufacturer')),
0,
'check'
);
$w->epew->setting(
'showmeta_Model',
sprintf(__('Show metadata: %s'),__('Model')),
sprintf(__('Show metadata: %s'), __('Model')),
1,
'check'
);
$w->epew->setting(
'showmeta_Lens',
sprintf(__('Show metadata: %s'),__('Lens')),
sprintf(__('Show metadata: %s'), __('Lens')),
1,
'check'
);
$w->epew->setting(
'showmeta_ExposureProgram',
sprintf(__('Show metadata: %s'),__('Exposure program')),
sprintf(__('Show metadata: %s'), __('Exposure program')),
0,
'check'
);
$w->epew->setting(
'showmeta_Exposure',
sprintf(__('Show metadata: %s'),__('Exposure time')),
sprintf(__('Show metadata: %s'), __('Exposure time')),
1,
'check'
);
$w->epew->setting(
'showmeta_FNumber',
sprintf(__('Show metadata: %s'),__('Aperture')),
sprintf(__('Show metadata: %s'), __('Aperture')),
1,
'check'
);
$w->epew->setting(
'showmeta_ISOSpeedRatings',
sprintf(__('Show metadata: %s'),__('Iso speed rating')),
sprintf(__('Show metadata: %s'), __('Iso speed rating')),
1,
'check'
);
$w->epew->setting(
'showmeta_FocalLength',
sprintf(__('Show metadata: %s'),__('Focal lengh')),
sprintf(__('Show metadata: %s'), __('Focal lengh')),
1,
'check'
);
$w->epew->setting(
'showmeta_ExposureBiasValue',
sprintf(__('Show metadata: %s'),__('Exposure bias value')),
sprintf(__('Show metadata: %s'), __('Exposure bias value')),
0,
'check'
);
$w->epew->setting(
'showmeta_MeteringMode',
sprintf(__('Show metadata: %s'),__('Metering mode')),
sprintf(__('Show metadata: %s'), __('Metering mode')),
0,
'check'
);
@ -203,7 +199,7 @@ class entryPhotoExifWidget
}
# Not supported post type
if (!in_array($_ctx->posts->post_type,self::$supported_post_type))
if (!in_array($_ctx->posts->post_type, self::$supported_post_type))
{
return null;
}
@ -216,10 +212,10 @@ class entryPhotoExifWidget
}
# Content lookup
$text = $_ctx->posts->post_excerpt_xhtml.$_ctx->posts->post_content_xhtml;
$text = $_ctx->posts->post_excerpt_xhtml . $_ctx->posts->post_content_xhtml;
# Find source images
$images = self::getImageSource($core,$text,$w->thumbsize);
$images = self::getImageSource($core, $text, $w->thumbsize);
# No images
if (empty($images))
@ -233,17 +229,17 @@ class entryPhotoExifWidget
foreach($images as $img)
{
# List metas
$metas = self::getImageMeta($core,$img['source']);
$metas = self::getImageMeta($core, $img['source']);
$content = '';
foreach($metas as $k => $v)
{
# Don't show unwanted metadata or empty metadata
if (!$w->__get('showmeta_'.$k) || !$w->showmeta && empty($v[1]))
if (!$w->__get('showmeta_' . $k) || !$w->showmeta && empty($v[1]))
{
continue;
}
$content .= sprintf(self::$widget_text,$k,$v[0],$v[1]);
$content .= sprintf(self::$widget_text, $k, $v[0], $v[1]);
}
# No meta
@ -255,7 +251,7 @@ class entryPhotoExifWidget
# Thumbnail
if ($img['thumb'])
{
$content = sprintf(self::$widget_thumb,$img['title'],$img['thumb']).
$content = sprintf(self::$widget_thumb, $img['title'], $img['thumb']).
$content;
}
$contents .= $content;
@ -270,32 +266,32 @@ class entryPhotoExifWidget
# Paste widget
return $w->renderDiv(
$w->content_only,
'photoExifWidget '.$w->class,
'photoExifWidget ' . $w->class,
'',
($w->title ? $w->renderTitle(html::escapeHTML($w->title)) : '').
sprintf(self::$widget_content,$contents)
sprintf(self::$widget_content, $contents)
);
}
public static function getImageSource($core,$subject,$size='')
public static function getImageSource($core, $subject, $size='')
{
# Path and url
$p_url = $core->blog->settings->system->public_url;
$p_site = preg_replace('#^(.+?//.+?)/(.*)$#','$1',$core->blog->url);
$p_site = preg_replace('#^(.+?//.+?)/(.*)$#', '$1', $core->blog->url);
$p_root = $core->blog->public_path;
# Image pattern
$pattern = '(?:'.preg_quote($p_site,'/').')?'.preg_quote($p_url,'/');
$pattern = sprintf('/<img.+?src="%s(.*?\.(?:jpg|jpeg|png|gif))"[^>]+/msu',$pattern);
$pattern = '(?:' . preg_quote($p_site,'/') . ')?' . preg_quote($p_url, '/');
$pattern = sprintf('/<img.+?src="%s(.*?\.(?:jpg|jpeg|png|gif))"[^>]+/msu', $pattern);
# No image
if (!preg_match_all($pattern,$subject,$m))
if (!preg_match_all($pattern, $subject, $m))
{
return;
}
$res = $duplicate = array();
$allowed_ext = array('.jpg','.JPG','.jpeg','.JPEG','.png','.PNG','.gif','.GIF');
$allowed_ext = array('.jpg', '.JPG', '.jpeg', '.JPEG', '.png', '.PNG', '.gif', '.GIF');
# Loop through images
foreach ($m[1] as $i => $img)
@ -306,26 +302,26 @@ class entryPhotoExifWidget
$ext = $info['extension'];
# Not original
if (preg_match('/^\.(.+)_(sq|t|s|m)$/',$base,$mbase))
if (preg_match('/^\.(.+)_(sq|t|s|m)$/', $base, $mbase))
{
$base = $mbase[1];
}
# Full path
$f = $p_root.'/'.$info['dirname'].'/'.$base;
$f = $p_root . '/' . $info['dirname'] . '/' . $base;
# Find extension
foreach($allowed_ext as $end)
{
if (file_exists($f.$end))
if (file_exists($f . $end))
{
$src = $f.$end;
$src = $f . $end;
break;
}
}
# No file
if (!$src || in_array($src,$duplicate))
if (!$src || in_array($src, $duplicate))
{
continue;
}
@ -336,15 +332,15 @@ class entryPhotoExifWidget
# Find thumbnail
if (!empty($size))
{
$t = $p_root.'/'.$info['dirname'].'/.'.$base.'_'.$size.'.jpg';
$t = $p_root . '/' . $info['dirname'] . '/.' . $base . '_' . $size . '.jpg';
if (file_exists($t))
{
$thb = $p_url.(dirname($img) != '/' ? dirname($img) : '').'/.'.$base.'_'.$size.'.jpg';
$thb = $p_url . (dirname($img) != '/' ? dirname($img) : '') . '/.' . $base . '_' . $size . '.jpg';
}
}
# Find image description
if (preg_match('/alt="([^"]+)"/',$m[0][$i],$malt))
if (preg_match('/alt="([^"]+)"/', $m[0][$i], $malt))
{
$alt = $malt[1];
}
@ -359,23 +355,23 @@ class entryPhotoExifWidget
return $res;
}
public static function getImageMeta($core,$src)
public static function getImageMeta($core, $src)
{
$metas = array(
'Title' => array(__('Title:'),''),
'Description' => array(__('Description:'),''),
'Location' => array(__('Location:'),''),
'DateTimeOriginal' => array(__('Date:'),''),
'Make' => array(__('Manufacturer:'),''),
'Model' => array(__('Model:'),''),
'Lens' => array(__('Lens:'),''),
'ExposureProgram' => array(__('Program:'),''),
'Exposure' => array(__('Speed:'),''),
'FNumber' => array(__('Aperture:'),''),
'ISOSpeedRatings' => array(__('ISO:'),''),
'FocalLength' => array(__('Focal:'),''),
'ExposureBiasValue' => array(__('Exposure Bias:'),''),
'MeteringMode' => array(__('Metering mode:'),'')
'Title' => array(__('Title:'), ''),
'Description' => array(__('Description:'), ''),
'Location' => array(__('Location:'), ''),
'DateTimeOriginal' => array(__('Date:'), ''),
'Make' => array(__('Manufacturer:'), ''),
'Model' => array(__('Model:'), ''),
'Lens' => array(__('Lens:'), ''),
'ExposureProgram' => array(__('Program:'), ''),
'Exposure' => array(__('Speed:'), ''),
'FNumber' => array(__('Aperture:'), ''),
'ISOSpeedRatings' => array(__('ISO:'), ''),
'FocalLength' => array(__('Focal:'), ''),
'ExposureBiasValue' => array(__('Exposure Bias:'), ''),
'MeteringMode' => array(__('Metering mode:'), '')
);
$exp_prog = array(
@ -437,9 +433,9 @@ class entryPhotoExifWidget
# DateTimeOriginal
if (!empty($m['DateTimeOriginal']))
{
$dt_ft = $core->blog->settings->system->date_format.', '.$core->blog->settings->system->time_format;
$dt_ft = $core->blog->settings->system->date_format . ', ' . $core->blog->settings->system->time_format;
$dt_tz = $core->blog->settings->system->blog_timezone;
$metas['DateTimeOriginal'][1] = dt::dt2str($dt_ft,$m['DateTimeOriginal'],$dt_tz);
$metas['DateTimeOriginal'][1] = dt::dt2str($dt_ft, $m['DateTimeOriginal'], $dt_tz);
}
# Make
@ -470,14 +466,14 @@ class entryPhotoExifWidget
# Exposure
if (!empty($m['Exposure']))
{
$metas['Exposure'][1] = $m['Exposure'].'s';
$metas['Exposure'][1] = $m['Exposure'] . 's';
}
# FNumber
if (!empty($m['FNumber']))
{
$ap = sscanf($m['FNumber'],'%d/%d');
$metas['FNumber'][1] = $ap ? 'f/'.( $ap[0] / $ap[1]) : $m['FNumber'];
$ap = sscanf($m['FNumber'], '%d/%d');
$metas['FNumber'][1] = $ap ? 'f/' . ( $ap[0] / $ap[1]) : $m['FNumber'];
}
# ISOSpeedRatings
@ -489,8 +485,8 @@ class entryPhotoExifWidget
# FocalLength
if (!empty($m['FocalLength']))
{
$fl = sscanf($m['FocalLength'],'%d/%d');
$metas['FocalLength'][1] = $fl ? $fl[0]/$fl[1].'mm' : $m['FocalLength'];
$fl = sscanf($m['FocalLength'], '%d/%d');
$metas['FocalLength'][1] = $fl ? $fl[0]/$fl[1] . 'mm' : $m['FocalLength'];
}
# ExposureBiasValue