Skip to content

Commit

Permalink
Merge branch 'master' into patch-4
Browse files Browse the repository at this point in the history
  • Loading branch information
EdwardBock committed Jun 23, 2020
2 parents ed17599 + 77714fe commit 73c526b
Show file tree
Hide file tree
Showing 8 changed files with 83 additions and 22 deletions.
2 changes: 2 additions & 0 deletions inc/creative-common.inc
Expand Up @@ -161,6 +161,8 @@ class CreativeCommon {
'label' => __('Public Domain', 'media_license'),
'cc_path' => '',
);

$licenses = apply_filters(Plugin::FILTER_EDIT_LICENSE_NAME, $licenses);

return $licenses;
}
Expand Down
6 changes: 3 additions & 3 deletions inc/meta-fields.inc
Expand Up @@ -56,7 +56,7 @@ class MetaFields {
public function add_fields($fields){

/**
* lizenses selection
* licenses selection
*/
$list = CreativeCommon::getList();
$selections = array();
Expand All @@ -67,7 +67,7 @@ class MetaFields {
);
}
$fields[Plugin::META_LICENSE] = array(
'label' => __('Lizense','media_license'),
'label' => __('License','media_license'),
'input' => 'select',
'value' => '',
'helps' => __('Add license to caption if provided','media_license'),
Expand Down Expand Up @@ -156,4 +156,4 @@ class MetaFields {

}

}
}
62 changes: 55 additions & 7 deletions js/api.js
Expand Up @@ -15,7 +15,17 @@

var id = api.get_image_id(img);
if(id){
if(!$(img).closest(".wp-caption").length){
var $figCaption = $(img).closest("figure").find("figcaption");
if(
(
$figCaption.length === 0
||
$figCaption.text().length === 0
)
&&
!$(img).closest(".wp-caption").length
){
// if image has no caption try to find one
ids.push(id);
if(typeof map[id] === typeof undefined){
map[id] = [];
Expand Down Expand Up @@ -45,7 +55,13 @@
for(var id in result.captions){
if(!result.captions.hasOwnProperty(id)) continue;
for(var i in map[id]){
process_image(map[id][i], result.captions[id]);
if(!map[id].hasOwnProperty(i)) continue;

var caption = result.captions[id];
if(caption.length > 0){
var element = map[id][i];
process_image(element, caption);
}
}
}

Expand All @@ -59,12 +75,13 @@
* @param element
* @param caption
*/
function process_image(element, caption){
var $img = $(element);

var $figure = $("<figure></figure>")
function process_image(element, caption) {
var $img = $(element);
var $figure = $("<figure></figure>")
.addClass("wp-caption media-license__figure");


if($img.hasClass("alignright")){
$figure.addClass("alignright");
$img.removeClass("alignright");
Expand All @@ -73,8 +90,15 @@
$figure.addClass("alignleft");
$img.removeClass("alignleft");
}
if($img.hasClass("aligncenter")){
$figure.addClass("aligncenter");
$img.removeClass("aligncenter");
}

// check parent -
if( ! $img.parent("figure" ) ) {

console.log( $img, $img.parent("figure" ), $img.parent("figure" ).length );
if( ! $img.parent("figure" ).length ) {
$img.wrap($figure);
} else {
$img.parent().addClass("media-license__figure");
Expand All @@ -92,6 +116,30 @@
$img.parent().find("figcaption").addClass("media-license__figcaption").html( caption );
}

if ($img.hasClass("alignright")) {
$figure.addClass("alignright");
$img.removeClass("alignright");
}
if ($img.hasClass("alignleft")) {
$figure.addClass("alignleft");
$img.removeClass("alignleft");
}
// check parent -
if (!$img.parent("figure")) {
$img.wrap($figure);
} else {
$img.parent().addClass("media-license__figure");
}

if ($img.parent().find("figcaption").length == 0) {
// we need a empty figcaption and fill with data from api
var $caption = $("<figcaption>" + caption + "</figcaption>").addClass("wp-caption-text media-license__figcaption");
$img.after($caption);
} else {
// add author information to existing figcaption
var $current_caption = $(caption).filter(".media-license__author").get(0);
$img.parent().find("figcaption").addClass("media-license__figcaption").append($current_caption);
}

}

Expand Down
2 changes: 1 addition & 1 deletion languages/media_license-de_DE.po
Expand Up @@ -21,7 +21,7 @@ msgstr ""
"X-Poedit-SearchPathExcluded-0: *.js\n"

#: media-license.php:120
msgid "Lizense"
msgid "License"
msgstr "Lizenz"

#: media-license.php:123
Expand Down
2 changes: 1 addition & 1 deletion languages/media_license.pot
Expand Up @@ -21,7 +21,7 @@ msgstr ""
"X-Poedit-SearchPathExcluded-0: *.js\n"

#: media-license.php:120
msgid "Lizense"
msgid "License"
msgstr ""

#: media-license.php:123
Expand Down
10 changes: 8 additions & 2 deletions media-license.php
Expand Up @@ -3,11 +3,11 @@
* Plugin Name: Media License
* Plugin URI: https://github.com/palasthotel/media-license
* Description: Advanced caption with license for media files
* Version: 1.3.0
* Version: 1.3.1
* Author: Palasthotel <rezeption@palasthotel.de> (in person: Edward Bock)
* Author URI: http://www.palasthotel.de
* Requires at least: 4.0
* Tested up to: 5.2.2
* Tested up to: 5.3.2
* License: http://www.gnu.org/licenses/gpl-2.0.html GPLv2
* @copyright Copyright (c) 2014, Palasthotel
* @package Palasthotel\MediaLicense
Expand Down Expand Up @@ -45,6 +45,12 @@ class Plugin {
const FILTER_ADD_FIELDS_NAME = "media_license_add_fields";
const FILTER_ADD_FIELDS_NUM_ARGS = 1;

/**
* add license filter
*/
const FILTER_EDIT_LICENSE_NAME = "media_license_edit_licenses";
const FILTER_EDIT_LICENSE_NUM_ARGS = 1;

const FILTER_AUTOLOAD_ASYNC_IMAGE_LICENSE = "media_license_autoload_async_image_license";

/**
Expand Down
10 changes: 7 additions & 3 deletions readme.txt
@@ -1,10 +1,10 @@
=== Media License ===
Contributors: palasthotel, edwardbock
Contributors: palasthotel, edwardbock, kroppenstedt
Donate link: http://palasthotel.de/
Tags: media, extension, license
Requires at least: 4.0
Tested up to: 5.2.2
Stable tag: 1.3.0
Stable tag: 1.3.1
License: GPLv3
License URI: http://www.gnu.org/licenses/gpl

Expand Down Expand Up @@ -34,6 +34,10 @@ Yes you can with the filter function "media_license_add_fields".

== Changelog ==

= 1.3.1 =
* Bugfix: Do not do anything on empty caption
* Bugfix: Gutenberg caption without wp-caption class fix

= 1.3.0 =
* Bugfix: Gutenberg support
* Optimization: Changed default value for filter media_license_autoload_async_image_license
Expand Down Expand Up @@ -76,4 +80,4 @@ Yes you can with the filter function "media_license_add_fields".
== Upgrade Notice ==

= 1.3.0 =
Default behaviors changed. See changelog.
Default behaviors changed. See changelog.
11 changes: 6 additions & 5 deletions templates/media-license-caption.tpl.php
Expand Up @@ -17,9 +17,8 @@
/**
* if there is a caption save it to output
*/
if ( "" != $caption )
{
$output = $caption;
if ( "" != $caption ) {
$output = "<span class='media-license__caption'>" . strip_tags($output) . "</span>";
}

/**
Expand All @@ -37,8 +36,10 @@
$pre_link = "<a href=\"{$media_license_url}\" >";
$post_link = "</a>";
}


$output .= "<span class='media-license__author'>";
$output .= __(" by ", "media-license" ) . $pre_link . $media_license_author . $post_link . " ";
$output .= "</span>";
}

/**
Expand All @@ -53,4 +54,4 @@
/**
* shout it out!
*/
echo $output;
echo $output;

0 comments on commit 73c526b

Please sign in to comment.