PluginProbe
Image Source Control Lite – Show Image Credits and Captions / 1.10
Image Source Control Lite – Show Image Credits and Captions v1.10
3.12.0 3.11.0 trunk 1.1 1.1.1 1.1.2 1.1.2.1 1.1.3 1.10 1.10.1 1.10.2 1.10.3 1.10.4 1.10.5 1.2 1.2.0.1 1.2.0.2 1.2.0.3 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.3.4.1 1.3.5 All 110 releases
image-source-control-isc / public / public.php

public.php in Image Source Control Lite – Show Image Credits and Captions 1.10, at public/public.php

762 lines 30.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 //avoid direct calls to this file
3 if (!function_exists('add_action')) {
4 header('Status: 403 Forbidden');
5 header('HTTP/1.1 403 Forbidden');
6 exit();
7 }
8 if (!class_exists('ISC_Public')) {
9
10 /**
11 * handles all admin functionalities
12 *
13 * @since 1.7
14 * @todo move frontend-only functions from general class here
15 */
16 class ISC_Public extends ISC_Class {
17
18 public function __construct() {
19 parent::__construct();
20
21 add_action('wp_enqueue_scripts', array($this, 'front_scripts'));
22 add_action('wp_head', array($this, 'front_head'));
23
24 /**
25 * filters need to be above 10 in order to interpret also gallery shortcode
26 */
27 add_filter('the_content', array($this, 'content_filter'), 20);
28 add_filter('the_excerpt', array($this, 'excerpt_filter'), 20);
29 add_shortcode('isc_list', array($this, 'list_post_attachments_with_sources_shortcode'));
30 add_shortcode('isc_list_all', array($this, 'list_all_post_attachments_sources_shortcode'));
31 }
32
33 /**
34 * Enqueue scripts for the front-end.
35 */
36 public function front_scripts() {
37 // inject in footer as we only do stuff after dom-ready
38 wp_enqueue_script('isc_front_js', plugins_url('/assets/js/front-js.js', __FILE__), array('jquery'), ISCVERSION, true);
39 }
40
41 /**
42 * Front-end scripts in <head /> section.
43 */
44 public function front_head()
45 {
46 $options = $this->get_isc_options();
47 ?>
48 <script type="text/javascript">
49 /* <![CDATA[ */
50 var isc_front_data =
51 {
52 caption_position : '<?php echo $options['caption_position']; ?>',
53 }
54 /* ]]> */
55 </script>
56 <style>
57 .isc-source { position: relative; }
58 </style>
59 <?php
60 }
61
62 /**
63 * add captions to post content and include source into caption, if this setting is enabled
64 *
65 * @param string $content post content
66 * @return string $content
67 *
68 * @update 1.4.3
69 */
70 public function content_filter($content)
71 {
72
73 // display inline sources
74 $options = $this->get_isc_options();
75 if( isset($options['display_type']) && is_array($options['display_type']) && in_array('overlay', $options['display_type'] ) ) {
76 /**
77 * split content where `isc_stop_overlay` is found to not display overlays starting there
78 */
79 if( strpos( $content, 'isc_stop_overlay' ) ){
80 list( $content, $content_after ) = explode( 'isc_stop_overlay', $content, 2 );
81 } else {
82 $content_after = '';
83 }
84
85 /**
86 * removed [caption], because this check runs after the hook that interprets shortcodes
87 * img tag is checked individually since there is a different order of attributes when images are used in gallery or individually
88 *
89 * 0 – full match
90 * 1 - <figure> if set
91 * 2 – alignment
92 * 3 – inner code starting with <a>
93 * 4 – opening link attribute
94 * 5 – "rel" attribute from link tag
95 * 6 – image id from link wp-att- value in "rel" attribute
96 * 7 – full img tag
97 * 8 – image URL
98 * 9 – (unused)
99 * 10 - </figure>
100 *
101 * tested with:
102 * * with and without [caption]
103 * * with and without link attibute
104 *
105 * potential issues:
106 * * line breaks in the code
107 */
108 $pattern = '#(<[^>]*class="[^"]*(alignleft|alignright|alignnone|aligncenter).*)?((<a [^>]*(rel="[^"]*[^"]*wp-att-(\d+)"[^>]*)>)? *(<img [^>]*[^>]*src="(.+)".*\/?>).*(</a>)??[^<]*).*(<\/figure.*>)?#isU';
109 $count = preg_match_all($pattern, $content, $matches);
110
111 // error_log(print_r($content, true)); error_log(print_r($matches, true));
112 if (false !== $count) {
113 for ($i=0; $i < $count; $i++) {
114
115 /**
116 * interpret the image tag
117 *
118 * we only need the ID if we don’t have it yet
119 * it can be retrieved from "wp-image-" class (single) or "aria-describedby="gallery-1-34" in gallery
120 */
121 $id = $matches[6][$i];
122 $img_tag = $matches[7][$i];
123
124 if( ! $id ){
125 $success = preg_match('#wp-image-(\d+)|aria-describedby="gallery-1-(\d+)#is', $img_tag, $matches_id);
126 if( $success ){
127 $id = $matches_id[1] ? intval( $matches_id[1] ) : intval( $matches_id[2] );
128 }
129 }
130
131 // if ID is still missing get image by URL
132 if( ! $id ){
133 $src = $matches[8][$i];
134 $id = $this->get_image_by_url($src);
135 }
136
137 // don’t show caption for own image if admin choose not to do so
138 if($options['exclude_own_images']){
139 if(get_post_meta($id, 'isc_image_source_own', true)) {
140 continue;
141 }
142 }
143
144 // don’t display empty sources
145 if( !$source_string = $this->render_image_source_string( $id ) ) {
146 continue;
147 }
148
149 // get any alignment from the original code
150 preg_match('#alignleft|alignright|alignnone|aligncenter#is', $matches[0][$i], $matches_align);
151 $alignment = isset( $matches_align[0] ) ? $matches_align[0] : '';
152
153 $source = '<span class="isc-source-text">' . $options['source_pretext'] . ' ' . $source_string . '</span>';
154 $old_content = $matches[3][$i];
155 $new_content = str_replace('wp-image-' . $id, 'wp-image-' . $id . ' with-source', $old_content);
156
157 $content = str_replace($old_content, '<div id="isc_attachment_' . $id . '" class="isc-source ' . $alignment . '"> ' . $new_content . $source . '</div>', $content);
158
159 }
160 }
161 /**
162 * attach follow content back
163 */
164 $content = $content . $content_after;
165 }
166
167 // attach image source list to content, if option is enabled
168 if ((isset($options['list_on_archives']) && $options['list_on_archives']) ||
169 (is_singular() && isset($options['display_type']) && is_array($options['display_type']) && in_array('list', $options['display_type']))) {
170 $content = $content . $this->list_post_attachments_with_sources();
171 }
172
173 return $content;
174 }
175
176 /**
177 * add image source of featured image to post excerpts
178 *
179 * @param string $excerpt post excerpt
180 * @return string $excerpt
181 *
182 * @update 1.4.3
183 */
184 public function excerpt_filter($excerpt)
185 {
186
187 // display inline sources
188 $options = $this->get_isc_options();
189 $post = get_post();
190
191 if (empty($options['list_on_excerpts'])) return $excerpt;
192
193 $source_string = $this->get_thumbnail_source_string($post->ID);
194
195 $excerpt = $excerpt . $source_string;
196
197 return $excerpt;
198 }
199
200 /**
201 * create image sources list for all images of this post
202 *
203 * @since 1.0
204 * @updated 1.1, 1.3.5
205 * @updated 1.5 use new render function to create basic image source string
206 *
207 * @param int $post_id id of the current post/page
208 * @return echo output
209 */
210 public function list_post_attachments_with_sources($post_id = 0)
211 {
212 global $post;
213 if (empty($post_id)) {
214 if (!empty($post->ID)) {
215 $post_id = $post->ID;
216 } else {
217 return;
218 }
219 }
220
221 $attachments = get_post_meta($post_id, 'isc_post_images', true);
222
223 // if attachments is an empty string, search for images in it
224 if ($attachments == '') {
225 // unregister our content filter in order to prevent infinite loops when calling the_content in the next steps
226 remove_filter( 'the_content', array( $this, 'content_filter' ), 20 );
227
228 $this->save_image_information_on_load();
229 $this->update_image_posts_meta($post_id, $post->post_content);
230
231 $attachments = get_post_meta($post_id, 'isc_post_images', true);
232 }
233
234 $return = '';
235 if (!empty($attachments)) {
236 $atts = array();
237 foreach ($attachments as $attachment_id => $attachment_array) {
238
239 $own = get_post_meta($attachment_id, 'isc_image_source_own', true);
240 $source = get_post_meta($attachment_id, 'isc_image_source', true);
241
242 // check if source of own images can be displayed
243 if ( ($own == '' && $source == '' ) || ($own != '' && $this->_options['exclude_own_images'])) {
244 unset($atts[$attachment_id]);
245 continue;
246 } else {
247 $atts[$attachment_id]['title'] = get_the_title($attachment_id);
248 $atts[$attachment_id]['source'] = $this->render_image_source_string($attachment_id);
249 }
250
251 }
252
253 $return = $this->render_attachments($atts);
254 }
255
256 return $return;
257 }
258
259 /**
260 * render attachment list
261 *
262 * @param array $attachments
263 * @updated 1.3.5
264 * @updated 1.5 removed rendering the license to an earlier function
265 */
266 protected function render_attachments($attachments)
267 {
268 // don't display anything, if no image sources displayed
269 if ($attachments == array()) {
270 return ;
271 }
272
273
274 $options = $this->get_isc_options();
275
276 ob_start();
277 $headline = $this->_options['image_list_headline'];
278 ?><div class="isc_image_list_box"><?php
279 printf('<p class="isc_image_list_title">%1$s</p>', $headline); ?>
280 <ul class="isc_image_list"><?php
281
282 foreach ($attachments as $atts_id => $atts_array) {
283 if (empty($atts_array['source'])) {
284 continue;
285 }
286 printf('<li>%1$s: %2$s</li>', $atts_array['title'], $atts_array['source']);
287 }
288 ?></ul></div><?php
289 return ob_get_clean();
290 }
291
292 /**
293 * shortcode function to list all image sources
294 * @param arr $atts
295 */
296 public function list_post_attachments_with_sources_shortcode($atts = array())
297 {
298 global $post;
299 extract(shortcode_atts(array('id' => 0), $atts));
300
301 // if $id not set, use the current ID from the post
302 if (empty($id)) {
303 $id = $post->ID;
304 }
305
306 if (empty($id)) {
307 return;
308 }
309 return $this->list_post_attachments_with_sources($id);
310 }
311
312 /**
313 * create shortcode to list all image sources in the frontend
314 * @param array $atts
315 * @since 1.1.3
316 */
317 public function list_all_post_attachments_sources_shortcode($atts = array())
318 {
319 extract(shortcode_atts(array(
320 'per_page' => 99999,
321 'before_links' => '',
322 'after_links' => '',
323 'prev_text' => '&#171; Previous',
324 'next_text' => 'Next &#187;',
325 'included' => 'displayed'
326 ),
327 $atts));
328
329 if ('&#171; Previous' == $prev_text)
330 $prev_text = __('&#171; Previous', 'image-source-control-isc');
331 if ('Next &#187;' == $next_text)
332 $next_text = __('Next &#187;', 'image-source-control-isc');
333
334 // retrieve all attachments
335 $args = array(
336 'post_type' => 'attachment',
337 'numberposts' => -1,
338 'post_status' => null,
339 'post_parent' => null
340 );
341
342 // check mode
343 if( $included === 'all' ){
344 // load all images
345
346 } else { // load only images attached to posts
347 $args['meta_query'] = array(
348 array(
349 'key' => 'isc_image_posts',
350 'value' => 'a:0:{}',
351 'compare' => '!='
352 )
353 );
354 }
355
356 $attachments = get_posts($args);
357 if (empty($attachments)) {
358 return;
359 }
360
361 $options = $this->get_isc_options();
362
363 $connected_atts = array();
364
365 foreach ($attachments as $_attachment) {
366 $connected_atts[$_attachment->ID]['source'] = get_post_meta($_attachment->ID, 'isc_image_source', true);
367 $connected_atts[$_attachment->ID]['own'] = get_post_meta($_attachment->ID, 'isc_image_source_own', true);
368 // jump to next element if author images are not to be included in the list
369 if($options['exclude_own_images'] && '' != $connected_atts[$_attachment->ID]['own']) {
370 unset($connected_atts[$_attachment->ID]);
371 continue;
372 }
373
374 $connected_atts[$_attachment->ID]['title'] = $_attachment->post_title;
375 $connected_atts[$_attachment->ID]['author_name'] = '';
376 if ('' != $connected_atts[$_attachment->ID]['own']) {
377 $connected_atts[$_attachment->ID]['author_name'] = get_the_author_meta('display_name', $_attachment->post_author);
378 }
379
380 $metadata = get_post_meta($_attachment->ID, 'isc_image_posts', true);
381 $usage_data = '';
382
383 if (is_array($metadata) && array() != $metadata) {
384 $usage_data .= "<ul style='margin: 0;'>";
385 $usage_data_array = array();
386 foreach($metadata as $data) {
387 // only list published posts
388 if(get_post_status($data) == 'publish') {
389 $usage_data_array[] = sprintf(__('<li><a href="%1$s" title="View %2$s">%3$s</a></li>', 'image-source-control-isc'),
390 esc_url(get_permalink($data)),
391 esc_attr(get_the_title($data)),
392 esc_html(get_the_title($data))
393 );
394 }
395 }
396 if ( 'all' !== $included && $usage_data_array === array() ) {
397 unset($connected_atts[$_attachment->ID]);
398 continue;
399 }
400 $usage_data .= implode( '', $usage_data_array );
401 $usage_data .= "</ul>";
402 }
403
404 $connected_atts[$_attachment->ID]['posts'] = $usage_data;
405 }
406
407 $total = count($connected_atts);
408
409 if (0 == $total)
410 return;
411
412 $page = isset($_GET['isc-page']) ? intval($_GET['isc-page']) : 1;
413 $down_limit = 1; // First page
414
415 $up_limit = 1;
416
417 if ($per_page < $total) {
418 $rem = $total % $per_page; // The Remainder of $total/$per_page
419 $up_limit = ($total - $rem) / $per_page;
420 if (0 < $rem) {
421 $up_limit++; //If rem is positive, add the last page that contains less than $per_page attachment;
422 }
423 }
424
425 ob_start();
426 if ( 2 > $up_limit ) {
427 $this->display_all_attachment_list($connected_atts);
428 } else {
429 $starting_atts = $per_page * ($page - 1); // for page 2 and 3 $per_page start display on $connected_atts[3*(2-1) = 3]
430 $paged_atts = array_slice($connected_atts, $starting_atts, $per_page, true);
431 $this->display_all_attachment_list($paged_atts);
432 $this->pagination_links($up_limit, $before_links, $after_links, $prev_text, $next_text);
433 }
434 if (isset($options['webgilde']) && true == $options['webgilde']) {
435 ?>
436 <p class="isc-backlink"><?php printf(__('Image list created by <a href="%s" title="Image Source Control">Image Source Control Plugin</a>', 'image-source-control-isc'), WEBGILDE); ?></p>
437 <?php
438 }
439
440 $output = ob_get_clean();
441 return $output;
442 }
443
444
445 /**
446 * performs rendering of all attachments list
447 * @since 1.1.3
448 * @update 1.5 added new method to get source
449 */
450 public function display_all_attachment_list($atts)
451 {
452 if (!is_array($atts) || $atts == array())
453 return;
454 $options = $this->get_isc_options();
455
456 /**
457 * added comment `isc_stop_overlay` as a class to the table to suppress overlays within it starting at that point
458 * todo: allow overlays to start again after the table
459 *
460 */
461 ?><div class="isc_all_image_list_box isc_stop_overlay">
462 <table>
463 <thead>
464 <?php if ($options['thumbnail_in_list']) : ?>
465 <th><?php _e('Thumbnail', 'image-source-control-isc'); ?></th>
466 <?php endif; ?>
467 <th><?php _e("Attachment's ID", 'image-source-control-isc'); ?></th>
468 <th><?php _e('Title', 'image-source-control-isc'); ?></th>
469 <th><?php _e('Attached to', 'image-source-control-isc'); ?></th>
470 <th><?php _e('Source', 'image-source-control-isc'); ?></th>
471 </thead>
472 <tbody>
473 <?php foreach ($atts as $id => $data) : ?>
474 <?php
475 $source = $this->render_image_source_string($id);
476 ?>
477 <tr>
478 <?php
479 $v_align = '';
480 if ($options['thumbnail_in_list']) :
481 $v_align = 'style="vertical-align: top;"';
482 ?>
483 <?php if ('custom' != $options['thumbnail_size']) : ?>
484 <td><?php echo wp_get_attachment_image($id, $options['thumbnail_size']); ?></td>
485 <?php else : ?>
486 <td><?php echo wp_get_attachment_image($id, array($options['thumbnail_width'], $options['thumbnail_height'])); ?></td>
487 <?php endif; ?>
488 <?php endif; ?>
489 <td <?php echo $v_align;?>><?php echo $id; ?></td>
490 <td <?php echo $v_align;?>><?php echo $data['title']; ?></td>
491 <td <?php echo $v_align;?>><?php echo $data['posts']; ?></td>
492 <td <?php echo $v_align;?>><?php echo $source; ?></td>
493 </tr>
494 <?php endforeach; ?>
495 </tbody>
496 </table></div>
497 <?php
498 }
499
500 /**
501 * Render pagination links, use $before_links and after_links to wrap pagination links inside an additional block
502 * @param int $max_page total page count
503 * @param string $before_links optional html to display before pagination links
504 * @param string $after_links optional html to display after pagination links
505 * @param string $prev_text text for the previous page link
506 * @param string $next_text text for the next page link
507 * @since 1.1.3
508 *
509 */
510 public function pagination_links($max_page, $before_links, $after_links, $prev_text, $next_text)
511 {
512 if ((!isset($max_page)) || (!isset($before_links)) || (!isset($after_links)) || (!isset($prev_text)) || (!isset($next_text)))
513 return;
514 if (!empty($before_links))
515 echo $before_links;
516 ?>
517 <div class="isc-paginated-links">
518 <?php
519 $page = isset($_GET['isc-page']) ? intval($_GET['isc-page']) : 1;
520 if ($max_page < $page) {
521 $page = $max_page;
522 }
523 if ($page < 1) {
524 $page = 1;
525 }
526 $min_page = 1;
527 $backward_distance = $page - $min_page;
528 $forward_distance = $max_page - $page;
529
530 $page_link = get_page_link();
531
532 /**
533 * Remove the query_string of the page_link (?page_id=xyz for the standard permalink structure),
534 * which is already captured in $_SERVER['QUERY_STRING'].
535 * @todo replace regex with other value (does WP store the url path without attributes somewhere?
536 * >get_page_link() returns the permalink but for the default WP permalink structure, the permalink looks like "http://domain.tld/?p=52", while $_GET
537 * still has a field named 'page_id' with the same value of 52.
538 */
539
540 $pos = strpos($page_link, '?');
541 if (false !== $pos) {
542 $page_link = substr($page_link, 0, $pos);
543 }
544
545 /**
546 * Unset the actual "$_GET['isc-page']" variable (if is set). Pagination variable will be appended to the new query string with a different value for each
547 * pagination link.
548 */
549
550 if (isset($_GET['isc-page'])) {
551 unset($_GET['isc-page']);
552 }
553
554 $query_string = http_build_query($_GET);
555
556 $isc_query_tag = '';
557 if (empty($query_string)) {
558 $isc_query_tag = '?isc-page=';
559 } else {
560 $query_string = '?' . $query_string;
561 $isc_query_tag = '&isc-page=';
562 }
563
564 if ($min_page != $page) {
565 ?>
566 <a href="<?php echo $page_link . $query_string . $isc_query_tag . ($page-1); ?>" class="prev page-numbers"><?php echo $prev_text; ?></a>
567 <?php
568 }
569
570 if (5 < $max_page) {
571
572 if (3 < $backward_distance) {
573 ?>
574 <a href="<?php echo $page_link . $query_string . $isc_query_tag; ?>1" class="page-numbers">1</a>
575 <span class="page-numbers dots">...</span>
576 <a href="<?php echo $page_link . $query_string . $isc_query_tag . ($page-2);?>" class="page-numbers"><?php echo $page-2; ?></a>
577 <a href="<?php echo $page_link . $query_string . $isc_query_tag . ($page-1);?>" class="page-numbers"><?php echo $page-1; ?></a>
578 <span class="page-numbers current"><?php echo $page; ?></span>
579 <?php
580 } else {
581 for ($i = 1; $i <= $page; $i++) {
582 if ($i == $page) {
583 ?>
584 <span class="page-numbers current"><?php echo $i; ?></span>
585 <?php
586 } else {
587 ?>
588 <a href="<?php echo $page_link . $query_string . $isc_query_tag . $i;?>" class="page-numbers"><?php echo $i; ?></a>
589 <?php
590 }
591 }
592 }
593
594 if (3 < $forward_distance) {
595 ?>
596 <a href="<?php echo $page_link . $query_string . $isc_query_tag . ($page+1);?>" class="page-numbers"><?php echo $page+1; ?></a>
597 <a href="<?php echo $page_link . $query_string . $isc_query_tag . ($page+2);?>" class="page-numbers"><?php echo $page+2; ?></a>
598 <span class="page-numbers dots">...</span>
599 <a href="<?php echo $page_link . $query_string . $isc_query_tag . $max_page;?>" class="page-numbers"><?php echo $max_page; ?></a>
600 <?php
601 } else {
602 for ($i = $page+1; $i <= $max_page; $i++) {
603 ?>
604 <a href="<?php echo $page_link . $query_string . $isc_query_tag . $i;?>" class="page-numbers"><?php echo $i; ?></a>
605 <?php
606 }
607 }
608 } else {
609 for ($i = 1; $i <= $max_page; $i++) {
610 if ($i == $page) {
611 ?>
612 <span class="page-numbers current"><?php echo $i; ?></span>
613 <?php
614 } else {
615 ?>
616 <a href="<?php echo $page_link . $query_string . $isc_query_tag . $i;?>" class="page-numbers"><?php echo $i; ?></a>
617 <?php
618 }
619 }
620 }
621 if ($page != $max_page) {
622 ?>
623 <a href="<?php echo $page_link . $query_string . $isc_query_tag . ($page+1);?>" class="next page-numbers"><?php echo $next_text; ?></a>
624 <?php
625 }
626 ?>
627 </div>
628 <?php
629 echo $after_links;
630 }
631
632 /**
633 * get source string of a feature image
634 *
635 * @since 1.8
636 * @param $post_id
637 * @return source string
638 */
639 function get_thumbnail_source_string($post_id = 0){
640
641 if(empty($post_id)) return '';
642
643 $options = $this->get_isc_options();
644
645 if(has_post_thumbnail($post_id)){
646 $id = get_post_thumbnail_id($post_id);
647 $thumb = get_post($post_id);
648
649 // don’t show caption for own image if admin choose not to do so
650 if($options['exclude_own_images']){
651 if(get_post_meta($id, 'isc_image_source_own', true)) return '';
652 }
653 // don’t display empty sources
654 $src = $thumb->guid;
655 if(!$source_string = $this->render_image_source_string($id)) return '';
656
657 return '<p class="isc-source-text">' . $options['source_pretext'] . ' ' . $source_string . '</p>';
658 }
659
660 return '';
661 }
662
663 /**
664 * load an image source string by url
665 *
666 * @updated 1.5
667 * @deprecated since 1.9
668 * @param string $url url of the image
669 * @return type
670 */
671 public function get_source_by_url($url)
672 {
673 // get the id by the image source
674 $id = $this->get_image_by_url($url);
675
676 return $this->render_image_source_string($id);
677
678 }
679
680 /**
681 * render source string of single image by its id
682 * this only returns the string with source and license (and urls),
683 * but no wrapping, because the string is used in a lot of functions
684 * (e.g. image source list where title is prepended)
685 *
686 * @updated 1.5 wrapped source into source url
687 *
688 * @param int $id id of the image
689 * @return bool|string false if no source was given, else string with source
690 */
691 public function render_image_source_string($id){
692 $id = absint($id);
693
694 $options = $this->get_isc_options();
695
696 $metadata['source'] = get_post_meta($id, 'isc_image_source', true);
697 $metadata['source_url'] = get_post_meta($id, 'isc_image_source_url', true);
698 $metadata['own'] = get_post_meta($id, 'isc_image_source_own', true);
699 $metadata['licence'] = get_post_meta($id, 'isc_image_licence', true);
700
701 $source = '';
702
703 $att_post = get_post($id);
704
705 if ('' != $metadata['own']) {
706 if ($this->_options['use_authorname']) {
707 if (!empty($att_post)) {
708 $source = get_the_author_meta('display_name', $att_post->post_author);
709 }
710 } else {
711 $source = $this->_options['by_author_text'];
712 }
713 } else {
714 if ('' != $metadata['source']) {
715 $source = $metadata['source'];
716 }
717 }
718
719 if($source == '') return false;
720
721 // wrap link around source, if given
722 if('' != $metadata['source_url']){
723 $source = sprintf('<a href="%2$s" target="_blank" rel="nofollow">%1$s</a>', $source, $metadata['source_url']);
724 }
725
726 // add license if enabled
727 if($options['enable_licences'] && isset($metadata['licence']) && $metadata['licence']) {
728 $licences = $this->licences_text_to_array($options['licences']);
729 if(isset($licences[$metadata['licence']]['url'])) $licence_url = $licences[$metadata['licence']]['url'];
730
731 if(isset($licence_url) && $licence_url != '') {
732 $source = sprintf('%1$s | <a href="%3$s" target="_blank" rel="nofollow">%2$s</a>', $source, $metadata['licence'], $licence_url);
733 } else {
734 $source = sprintf('%1$s | %2$s', $source, $metadata['licence']);
735 }
736 }
737
738 return $source;
739 }
740
741 /**
742 * save image information for a post when it is viewed – only called when using isc_list function
743 * (to help indexing old posts)
744 *
745 * @since 1.1
746 */
747 public function save_image_information_on_load()
748 {
749 global $post;
750 if (empty($post->ID)) {
751 return;
752 }
753
754 $post_id = $post->ID;
755 $_content = $post->post_content;
756
757 $this->save_image_information($post_id, $_content);
758 }
759
760 }
761 }
762