forked from Labs64/credit-tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcredit-tracker-shortcodes.php
135 lines (114 loc) · 4.37 KB
/
credit-tracker-shortcodes.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
<?php
/**
* Plugin shortcodes.
*
* @package Credit_Tracker
* @author Labs64 <[email protected]>
* @license GPL-2.0+
* @link http://www.labs64.com
* @copyright 2013 Labs64
*/
// add shortcodes
add_shortcode('credit_tracker_table', 'credit_tracker_table_shortcode');
add_filter('img_caption_shortcode', 'credit_tracker_caption_shortcode_filter', 10, 3);
function credit_tracker_table_shortcode($atts)
{
extract(shortcode_atts(
array(
'id' => '',
'size' => 'thumbnail',
'style' => 'default',
), $atts)
);
if (is_numeric($size)) {
$size = array($size, $size);
}
$request = array(
'size' => $size,
'include' => $id
);
$images = get_images($request);
$ret = '<table id="credit-tracker-table" class="credit-tracker-' . $style . '"><thead>';
$ret .= '<th>' . ' ' . '</th>';
$ret .= '<th>' . __('Ident-Nr.', CT_SLUG) . '</th>';
$ret .= '<th>' . __('Author', CT_SLUG) . '</th>';
$ret .= '<th>' . __('Publisher', CT_SLUG) . '</th>';
$ret .= '<th>' . __('Copyright', CT_SLUG) . '</th>';
$ret .= '<th>' . __('License', CT_SLUG) . '</th>';
$ret .= '</thead><tbody>';
if (empty($images)) {
$ret .= '<tr class="credit-tracker-row"><td colspan="6" class="credit-tracker-column-empty">' . __('No images found', CT_SLUG) . '</td></tr>';
}
foreach ($images as $image) {
if (!empty($image['author'])) {
$ct_copyright_format = ct_get_source_copyright($image['source']);
if (empty($ct_copyright_format)) {
$ct_copyright_format = get_single_option('ct_copyright_format');
}
$ret .= '<tr>';
$ret .= '<td>' . '<img width="' . $image['width'] . '" height="' . $image['height'] . '" src="' . $image['url'] . '" class="attachment-thumbnail" alt="' . $image['alt'] . '">' . '</td>';
$ret .= '<td>' . $image['ident_nr'] . '</td>';
$ret .= '<td>' . $image['author'] . '</td>';
$ret .= '<td>' . $image['publisher'] . '</td>';
$ret .= '<td>' . process_item_copyright($image, $ct_copyright_format) . '</td>';
$ret .= '<td>' . $image['license'] . '</td>';
$ret .= '</tr>';
}
}
$ret .= '</tbody></table>';
return $ret;
}
function credit_tracker_caption_shortcode_filter($val, $attr, $content = null)
{
extract(shortcode_atts(
array(
'id' => '',
'align' => 'aligncenter',
'width' => '',
'caption' => '',
'type' => 'caption'
), $attr)
);
$ct_override_caption_shortcode = get_single_option('ct_override_caption_shortcode');
if ((bool)$ct_override_caption_shortcode) {
if (1 > (int)$width) {
return $val;
}
$id_orig = $id;
if ($id) {
$id = esc_attr($id);
}
// extract attachment id
preg_match("/\d+/", $id, $matches);
if (!empty($matches)) {
$id = $matches[0];
}
// find attachment
$request = array(
'size' => 'thumbnail',
'include' => $id
);
$images = get_images($request);
if (empty($images)) {
return $val;
}
$image = reset($images);
$ct_copyright_format = ct_get_source_copyright($image['source']);
if (empty($ct_copyright_format)) {
$ct_copyright_format = get_single_option('ct_copyright_format');
}
$content = str_replace('<img', '<img itemprop="contentUrl"', $content);
$ret = '<div id="' . $id_orig . '" class="wp-caption ' . esc_attr($align) . '" itemscope itemtype="http://schema.org/ImageObject" style="width: ' . (0 + (int)$width) . 'px">';
$ret .= do_shortcode($content);
$ret .= '<p class="wp-caption-text" itemprop="copyrightHolder">' . process_item_copyright($image, $ct_copyright_format) . '</p>';
$ret .= '<meta itemprop="name" content="' . $image['title'] . '">';
$ret .= '<meta itemprop="caption" content="' . $image['caption'] . '">';
$ret .= '<meta itemprop="author" content="' . $image['author'] . '">';
$ret .= '<meta itemprop="publisher" content="' . $image['publisher'] . '">';
$ret .= '</div>';
return $ret;
} else {
return $val;
}
}
?>