PluginProbe
Sight – Professional Image Gallery and Portfolio / 1.1.7
Sight – Professional Image Gallery and Portfolio v1.1.7
trunk 1.0.0 1.0.1 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.0.7 1.0.8 1.0.9 1.1.0 1.1.1 1.1.2 1.1.3 1.1.4 1.1.5 1.1.6 1.1.7 1.1.8
sight / render / sight-entry.php

sight-entry.php in Sight – Professional Image Gallery and Portfolio 1.1.7, at render/sight-entry.php

638 lines 16.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * The Class Portfolio Entry
4 *
5 * @link https://codesupply.co
6 * @since 1.0.0
7 *
8 * @package Sight
9 */
10
11 if ( ! class_exists( 'Sight_Entry' ) ) {
12 /**
13 * Create Class Portfolio Entry
14 */
15 class Sight_Entry {
16 /**
17 * The attributes.
18 *
19 * @var string $attributes The attributes.
20 */
21 public $attributes = null;
22
23 /**
24 * The options.
25 *
26 * @var string $options The options.
27 */
28 public $options = null;
29
30 /**
31 * The source.
32 *
33 * @var string $source The source.
34 */
35 public $source = null;
36
37 /**
38 * The object_id.
39 *
40 * @var string $object_id The object_id.
41 */
42 public $object_id = null;
43
44 /**
45 * The object_link.
46 *
47 * @var string $object_link The object_link.
48 */
49 public $object_link = null;
50
51 /**
52 * The attachment_id.
53 *
54 * @var string $attachment_id The attachment_id.
55 */
56 public $attachment_id = null;
57
58 /**
59 * The attachment_lightbox.
60 *
61 * @var string $attachment_lightbox The attachment_lightbox.
62 */
63 public $attachment_lightbox = null;
64
65 /**
66 * The attachment_lightbox_icon.
67 *
68 * @var string $attachment_lightbox_icon The attachment_lightbox_icon.
69 */
70 public $attachment_lightbox_icon = null;
71
72 /**
73 * The attachment_link.
74 *
75 * @var string $attachment_link The attachment_link.
76 */
77 public $attachment_link = null;
78
79 /**
80 * The attachment_link_to.
81 *
82 * @var string $attachment_link_to The attachment_link_to.
83 */
84 public $attachment_link_to = null;
85
86 /**
87 * The attachment_full_link.
88 *
89 * @var string $attachment_full_link The attachment_full_link.
90 */
91 public $attachment_full_link = null;
92
93 /**
94 * The attachment_view_more.
95 *
96 * @var string $attachment_view_more The attachment_view_more.
97 */
98 public $attachment_view_more = null;
99
100 /**
101 * The attachment_view_more_label.
102 *
103 * @var string $attachment_view_more_label The attachment_view_more_label.
104 */
105 public $attachment_view_more_label = null;
106
107 /**
108 * The attachment_html.
109 *
110 * @var string $attachment_html The attachment_html.
111 */
112 public $attachment_html = null;
113
114 /**
115 * The attachment_title.
116 *
117 * @var string $attachment_title The attachment_title.
118 */
119 public $attachment_title = null;
120
121 /**
122 * The attachment_title_tag.
123 *
124 * @var string $attachment_title_tag The attachment_title_tag.
125 */
126 public $attachment_title_tag = 'h3';
127
128 /**
129 * The attachment_meta.
130 *
131 * @var string $attachment_meta The attachment_meta.
132 */
133 public $attachment_meta = null;
134
135 /**
136 * The attachment_caption.
137 *
138 * @var string $attachment_caption The attachment_caption.
139 */
140 public $attachment_caption = null;
141
142 /**
143 * The attachment_orientation.
144 *
145 * @var string $attachment_orientation The attachment_orientation.
146 */
147 public $attachment_orientation = null;
148
149 /**
150 * __construct
151 *
152 * This function will initialize the initialize
153 *
154 * @param array $attributes The attributes of block.
155 * @param array $options The options of block.
156 */
157 public function __construct( $attributes, $options ) {
158 $this->attributes = $attributes;
159 $this->options = $options;
160
161 // Set source of entry.
162 $this->source = $attributes['source'];
163 }
164
165 /**
166 * Init Entry
167 */
168 public function init() {
169 $this->set_object_id();
170 $this->set_object_link();
171 $this->set_attachment_id();
172 $this->set_attachment_lightbox();
173 $this->set_attachment_lightbox_icon();
174 $this->set_attachment_link();
175 $this->set_attachment_link_to();
176 $this->set_attachment_full_link();
177 $this->set_attachment_view_more();
178 $this->set_attachment_view_more_label();
179 $this->set_attachment_html();
180 $this->set_attachment_title();
181 $this->set_attachment_title_tag();
182 $this->set_attachment_meta();
183 $this->set_attachment_caption();
184 $this->set_attachment_orientation();
185 }
186
187 /**
188 * Set Object Id
189 */
190 public function set_object_id() {
191 if ( 'projects' === $this->source ) {
192 $this->object_id = get_the_ID();
193 }
194 if ( 'categories' === $this->source ) {
195 $this->object_id = intval( $this->object_id );
196 }
197 if ( 'post' === $this->source ) {
198 $this->object_id = intval( $this->attachment_id );
199 }
200 if ( 'custom' === $this->source ) {
201 $this->object_id = intval( $this->attachment_id );
202 }
203 }
204
205 /**
206 * Set Object Link
207 */
208 public function set_object_link() {
209 if ( 'projects' === $this->source ) {
210 $this->object_link = get_permalink( get_the_ID() );
211 }
212 if ( 'categories' === $this->source ) {
213 $this->object_link = get_term_link( $this->object_id );
214
215 if ( empty( sight_is_archive() ) ) {
216 $this->object_link = null;
217 }
218 }
219 if ( 'post' === $this->source ) {
220 $this->object_link = get_attachment_link( $this->attachment_id );
221 }
222 if ( 'custom' === $this->source ) {
223 $this->object_link = get_attachment_link( $this->attachment_id );
224 }
225 }
226
227 /**
228 * Set Attachment Id
229 */
230 public function set_attachment_id() {
231 if ( 'projects' === $this->source ) {
232 $this->attachment_id = get_post_thumbnail_id();
233 }
234 }
235
236 /**
237 * Set Attachment Lightbox
238 */
239 public function set_attachment_lightbox() {
240 if ( ! isset( $this->attributes['attachment_lightbox'] ) || ! $this->attributes['attachment_lightbox'] ) {
241 return;
242 }
243
244 $this->attachment_lightbox = true;
245 }
246 /**
247 * Set Attachment Lightbox Icon
248 */
249 public function set_attachment_lightbox_icon() {
250 if ( ! isset( $this->attributes['attachment_lightbox'] ) || ! $this->attributes['attachment_lightbox'] ) {
251 return;
252 }
253 if ( ! isset( $this->attributes['attachment_lightbox_icon'] ) || ! $this->attributes['attachment_lightbox_icon'] ) {
254 return;
255 }
256
257 $this->attachment_lightbox_icon = true;
258 }
259
260 /**
261 * Set Attachment Link
262 */
263 public function set_attachment_link() {
264 $this->attachment_link = wp_get_attachment_image_url( $this->attachment_id, $this->attributes['attachment_size'] );
265 }
266
267 /**
268 * Set Attachment Full Link
269 */
270 public function set_attachment_full_link() {
271 $this->attachment_full_link = wp_get_attachment_image_url( $this->attachment_id, 'full' );
272 }
273
274 /**
275 * Set Attachment Html
276 */
277 public function set_attachment_html() {
278 $attrs = apply_filters( 'sight_portfolio_attachment_attrs', array(), $this->attributes );
279
280 $this->attachment_html = wp_get_attachment_image( $this->attachment_id, $this->attributes['attachment_size'], false, $attrs );
281 }
282
283 /**
284 * Set Attachment Link To
285 */
286 public function set_attachment_link_to() {
287 if ( isset( $this->attributes['attachment_link_to'] ) && $this->attributes['attachment_link_to'] ) {
288 $this->attachment_link_to = $this->attributes['attachment_link_to'];
289 }
290 }
291
292 /**
293 * Set Attachment View More
294 */
295 public function set_attachment_view_more() {
296 if ( isset( $this->attributes['attachment_view_more'] ) && $this->attributes['attachment_view_more'] ) {
297 $this->attachment_view_more = $this->attributes['attachment_view_more'];
298 }
299 }
300
301 /**
302 * Set Attachment View More Label
303 */
304 public function set_attachment_view_more_label() {
305 switch ( $this->attachment_link_to ) {
306 case 'media':
307 $this->attachment_view_more_label = apply_filters( 'sight_portfolio_view_more', esc_html__( 'View Media', 'sight' ), $this );
308 break;
309 case 'page':
310 $this->attachment_view_more_label = apply_filters( 'sight_portfolio_view_more', esc_html__( 'View Project', 'sight' ), $this );
311 break;
312 }
313 }
314
315 /**
316 * Set Attachment Title
317 */
318 public function set_attachment_title() {
319 if ( ! isset( $this->attributes['meta_title'] ) || ! $this->attributes['meta_title'] ) {
320 return;
321 }
322
323 if ( 'projects' === $this->source ) {
324 $this->attachment_title = get_the_title( $this->object_id );
325 }
326 if ( 'categories' === $this->source ) {
327 $this->attachment_title = get_term( $this->object_id, 'sight-categories' )->name;
328 }
329 }
330 /**
331 * Set Attachment Title Tag
332 */
333 public function set_attachment_title_tag() {
334 if ( ! isset( $this->attributes['meta_title'] ) || ! $this->attributes['meta_title'] ) {
335 return;
336 }
337
338 if ( isset( $this->attributes['typography_heading_tag'] ) && $this->attributes['typography_heading_tag'] ) {
339 $this->attachment_title_tag = $this->attributes['typography_heading_tag'];
340 }
341 }
342
343 /**
344 * Set Attachment Meta
345 */
346 public function set_attachment_meta() {
347 ob_start();
348
349 // Meta Category.
350 if ( isset( $this->attributes['meta_category'] ) && $this->attributes['meta_category'] ) {
351
352 if ( 'projects' === $this->source ) {
353
354 $terms_list = array();
355
356 $terms = get_the_terms( $this->object_id, 'sight-categories' );
357
358 foreach ( $terms as $term ) {
359 if ( sight_is_archive() ) {
360 $link = get_term_link( $term );
361
362 if ( ! is_wp_error( $link ) ) {
363 $terms_list[] = '<a class="sight-portfolio-meta-item" href="' . esc_url( $link ) . '" rel="tag">' . $term->name . '</a>';
364 }
365 } else {
366 $terms_list[] = '<span class="sight-portfolio-meta-item">' . $term->name . '</span>';
367 }
368 }
369
370 if ( $terms_list ) {
371 ?>
372 <div class="sight-portfolio-meta-category">
373 <?php call_user_func( 'printf', '%s', join( '', $terms_list ) ); ?>
374 </div>
375 <?php
376 }
377 }
378 }
379
380 // Meta Date.
381 if ( isset( $this->attributes['meta_date'] ) && $this->attributes['meta_date'] ) {
382 ?>
383 <div class="sight-portfolio-meta-date">
384 <?php call_user_func( 'printf', '%s', get_the_date( '', $this->object_id ) ); ?>
385 </div>
386 <?php
387 }
388
389 $this->attachment_meta = ob_get_clean();
390 }
391
392 /**
393 * Set Attachment Caption
394 */
395 public function set_attachment_caption() {
396 if ( ! isset( $this->attributes['meta_caption'] ) || ! $this->attributes['meta_caption'] ) {
397 return;
398 }
399
400 if ( 'projects' === $this->source ) {
401 $this->attachment_caption = sight_get_the_excerpt( $this->object_id, $this->attributes['meta_caption_length'] );
402 }
403 if ( 'categories' === $this->source ) {
404 $this->attachment_caption = sight_str_truncate( term_description( $this->object_id ), $this->attributes['meta_caption_length'] );
405 }
406 if ( 'custom' === $this->source ) {
407 $this->attachment_caption = sight_str_truncate( wp_get_attachment_caption( $this->attachment_id ), $this->attributes['meta_caption_length'] );
408 }
409 if ( 'post' === $this->source ) {
410 $this->attachment_caption = sight_str_truncate( wp_get_attachment_caption( $this->attachment_id ), $this->attributes['meta_caption_length'] );
411 }
412 }
413
414 /**
415 * Set Attachment Orientation
416 */
417 public function set_attachment_orientation() {
418 if ( isset( $this->attributes['attachment_orientation'] ) && $this->attributes['attachment_orientation'] ) {
419 $this->attachment_orientation = sprintf( 'sight-portfolio-overlay-ratio sight-portfolio-ratio-%s', $this->attributes['attachment_orientation'] );
420 }
421 }
422
423 /**
424 * Has Item Content
425 */
426 public function has_item_content() {
427 $has_item_content = false;
428
429 if ( $this->attachment_title ) {
430 $has_item_content = true;
431 }
432 if ( $this->attachment_meta ) {
433 $has_item_content = true;
434 }
435 if ( $this->attachment_caption ) {
436 $has_item_content = true;
437 }
438
439 return apply_filters( 'sight_entry_has_item_content', $has_item_content, $this );
440 }
441
442 /**
443 * Compile Item Class
444 *
445 * @param string $class The class of entry.
446 */
447 public function item_class( $class = array() ) {
448 $classes = array();
449
450 if ( $class ) {
451 if ( ! is_array( $class ) ) {
452 $class = preg_split( '#\s+#', $class );
453 }
454 $classes = array_map( 'esc_attr', $class );
455 } else {
456 // Ensure that we always coerce class to being an array.
457 $class = array();
458 }
459
460 // Set individual class.
461 $classes[] = 'sight-portfolio-entry sight-portfolio-video-wrap';
462
463 // Set entry source.
464 if ( $this->source ) {
465 $classes[] = 'sight-portfolio-entry-' . $this->source;
466 }
467
468 // Set entry object id.
469 if ( $this->object_id ) {
470 $classes[] = 'sight-portfolio-entry-' . $this->object_id;
471 }
472
473 // Set entry link to.
474 if ( $this->attachment_link_to ) {
475 $classes[] = 'sight-portfolio-entry-link-' . $this->attachment_link_to;
476 }
477
478 // Set entry request class.
479 if ( 'standard' === $this->attributes['layout'] ) {
480
481 if ( isset( $_REQUEST['action'] ) && 'sight_portfolio_ajax_load_more' === $_REQUEST['action'] ) {
482 $classes[] = 'sight-portfolio-entry-request';
483 }
484 }
485
486 // For projects.
487 if ( 'projects' === $this->source ) {
488 $post = get_post( get_the_ID() );
489
490 $classes[] = 'type-' . $post->post_type;
491 $classes[] = 'status-' . $post->post_status;
492
493 // Post thumbnails.
494 if ( current_theme_supports( 'post-thumbnails' ) && has_post_thumbnail( $post->ID ) && ! is_attachment( $post ) ) {
495 $classes[] = 'has-post-thumbnail';
496 }
497 }
498
499 call_user_func( 'printf', 'class="%s"', join( ' ', $classes ) );
500 }
501
502 /**
503 * Compile Item Outer Class
504 *
505 * @param string $class The class of entry.
506 */
507 public function item_outer_class( $class = array() ) {
508 $classes = array();
509
510 if ( $class ) {
511 if ( ! is_array( $class ) ) {
512 $class = preg_split( '#\s+#', $class );
513 }
514 $classes = array_map( 'esc_attr', $class );
515 } else {
516 // Ensure that we always coerce class to being an array.
517 $class = array();
518 }
519
520 // Set individual class.
521 $classes[] = 'sight-portfolio-entry-outer';
522
523 call_user_func( 'printf', 'class="%s"', join( ' ', $classes ) );
524 }
525
526 /**
527 * Compile Item Attachment
528 */
529 public function item_attachment() {
530 if ( ! $this->attachment_html ) {
531 return;
532 }
533
534 switch ( $this->attachment_link_to ) {
535 case 'media':
536 $attachment_link = $this->attachment_full_link;
537 break;
538 case 'page':
539 $attachment_link = $this->object_link;
540 break;
541 }
542
543 if ( $this->attachment_lightbox ) {
544 $attachment_link = $this->attachment_full_link;
545 }
546 ?>
547 <div class="sight-portfolio-entry__inner sight-portfolio-entry__thumbnail sight-portfolio-entry__overlay <?php echo esc_attr( $this->attachment_orientation ); ?>">
548 <figure class="sight-portfolio-overlay-background">
549 <?php do_action( 'sight_entry_item_attachment_before', $this ); ?>
550
551 <?php call_user_func( 'printf', '%s', $this->attachment_html ); ?>
552
553 <?php do_action( 'sight_entry_item_attachment_after', $this ); ?>
554
555 <?php
556 if ( $this->attachment_view_more ) {
557 ?>
558 <span class="sight-portfolio-view-more">
559 <span class="sight-portfolio-view-more-label">
560 <?php echo esc_html( $this->attachment_view_more_label ); ?>
561 </span>
562 </span>
563 <?php
564 }
565 ?>
566
567 <?php
568 if ( isset( $this->attributes['video'] ) && $this->attributes['video'] && 'none' !== $this->attributes['video'] ) {
569 sight_get_video_background( $this->attributes['video'], null, null, 'default', (bool) $this->attributes['video_controls'] );
570 }
571 ?>
572
573 <?php
574 if ( isset( $attachment_link ) ) {
575 ?>
576 <a class="sight-portfolio-overlay-link" href="<?php echo esc_url( $attachment_link ); ?>"></a>
577 <?php
578 }
579 ?>
580
581 <?php
582 if ( $this->attachment_lightbox_icon ) {
583 ?>
584 <span class="sight-zoom-icon-popup"></span>
585 <?php
586 }
587 ?>
588 </figure>
589
590 </div>
591 <?php
592 }
593
594 /**
595 * Compile Item Content
596 */
597 public function item_content() {
598 if ( $this->has_item_content() ) {
599 ?>
600 <div class="sight-portfolio-entry__inner sight-portfolio-entry__content">
601 <?php do_action( 'sight_entry_item_content_before', $this ); ?>
602
603 <?php if ( $this->attachment_title ) { ?>
604 <div class="sight-portfolio-entry__title">
605 <?php if ( $this->object_link ) { ?>
606 <<?php echo esc_html( $this->attachment_title_tag ); ?> class="sight-portfolio-entry__heading">
607 <a href="<?php echo esc_url( $this->object_link ); ?>">
608 <?php echo wp_kses( $this->attachment_title, 'post' ); ?>
609 </a>
610 </<?php echo esc_html( $this->attachment_title_tag ); ?>>
611 <?php } else { ?>
612 <<?php echo esc_html( $this->attachment_title_tag ); ?> class="sight-portfolio-entry__heading">
613 <?php echo wp_kses( $this->attachment_title, 'post' ); ?>
614 </<?php echo esc_html( $this->attachment_title_tag ); ?>>
615 <?php } ?>
616 </div>
617 <?php } ?>
618
619 <?php if ( $this->attachment_meta ) { ?>
620 <div class="sight-portfolio-entry__meta">
621 <?php echo wp_kses( $this->attachment_meta, 'post' ); ?>
622 </div>
623 <?php } ?>
624
625 <?php if ( $this->attachment_caption ) { ?>
626 <div class="sight-portfolio-entry__caption">
627 <?php echo wp_kses( $this->attachment_caption, 'post' ); ?>
628 </div>
629 <?php } ?>
630
631 <?php do_action( 'sight_entry_item_content_after', $this ); ?>
632 </div>
633 <?php
634 }
635 }
636 }
637 }
638