PluginProbe
Sight – Professional Image Gallery and Portfolio / 1.0.4
Sight – Professional Image Gallery and Portfolio v1.0.4
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.0.4, at render/sight-entry.php

636 lines 16.3 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 obgect_link.
46 *
47 * @var string $obgect_link The obgect_link.
48 */
49 public $obgect_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 $this->attachment_html = wp_get_attachment_image( $this->attachment_id, $this->attributes['attachment_size'] );
279 }
280
281 /**
282 * Set Attachment Link To
283 */
284 public function set_attachment_link_to() {
285 if ( isset( $this->attributes['attachment_link_to'] ) && $this->attributes['attachment_link_to'] ) {
286 $this->attachment_link_to = $this->attributes['attachment_link_to'];
287 }
288 }
289
290 /**
291 * Set Attachment View More
292 */
293 public function set_attachment_view_more() {
294 if ( isset( $this->attributes['attachment_view_more'] ) && $this->attributes['attachment_view_more'] ) {
295 $this->attachment_view_more = $this->attributes['attachment_view_more'];
296 }
297 }
298
299 /**
300 * Set Attachment View More Label
301 */
302 public function set_attachment_view_more_label() {
303 switch ( $this->attachment_link_to ) {
304 case 'media':
305 $this->attachment_view_more_label = apply_filters( 'sight_portfolio_view_more', esc_html__( 'View Media', 'sight' ), $this );
306 break;
307 case 'page':
308 $this->attachment_view_more_label = apply_filters( 'sight_portfolio_view_more', esc_html__( 'View Project', 'sight' ), $this );
309 break;
310 }
311 }
312
313 /**
314 * Set Attachment Title
315 */
316 public function set_attachment_title() {
317 if ( ! isset( $this->attributes['meta_title'] ) || ! $this->attributes['meta_title'] ) {
318 return;
319 }
320
321 if ( 'projects' === $this->source ) {
322 $this->attachment_title = get_the_title( $this->object_id );
323 }
324 if ( 'categories' === $this->source ) {
325 $this->attachment_title = get_term( $this->object_id, 'sight-categories' )->name;
326 }
327 }
328 /**
329 * Set Attachment Title Tag
330 */
331 public function set_attachment_title_tag() {
332 if ( ! isset( $this->attributes['meta_title'] ) || ! $this->attributes['meta_title'] ) {
333 return;
334 }
335
336 if ( isset( $this->attributes['typography_heading_tag'] ) && $this->attributes['typography_heading_tag'] ) {
337 $this->attachment_title_tag = $this->attributes['typography_heading_tag'];
338 }
339 }
340
341 /**
342 * Set Attachment Meta
343 */
344 public function set_attachment_meta() {
345 ob_start();
346
347 // Meta Category.
348 if ( isset( $this->attributes['meta_category'] ) && $this->attributes['meta_category'] ) {
349
350 if ( 'projects' === $this->source ) {
351
352 $terms_list = array();
353
354 $terms = get_the_terms( $this->object_id, 'sight-categories' );
355
356 foreach ( $terms as $term ) {
357 if ( sight_is_archive() ) {
358 $link = get_term_link( $term );
359
360 if ( ! is_wp_error( $link ) ) {
361 $terms_list[] = '<a class="sight-portfolio-meta-item" href="' . esc_url( $link ) . '" rel="tag">' . $term->name . '</a>';
362 }
363 } else {
364 $terms_list[] = '<span class="sight-portfolio-meta-item">' . $term->name . '</span>';
365 }
366 }
367
368 if ( $terms_list ) {
369 ?>
370 <div class="sight-portfolio-meta-category">
371 <?php call_user_func( 'printf', '%s', join( '', $terms_list ) ); ?>
372 </div>
373 <?php
374 }
375 }
376 }
377
378 // Meta Date.
379 if ( isset( $this->attributes['meta_date'] ) && $this->attributes['meta_date'] ) {
380 ?>
381 <div class="sight-portfolio-meta-date">
382 <?php call_user_func( 'printf', '%s', get_the_date( '', $this->object_id ) ); ?>
383 </div>
384 <?php
385 }
386
387 $this->attachment_meta = ob_get_clean();
388 }
389
390 /**
391 * Set Attachment Caption
392 */
393 public function set_attachment_caption() {
394 if ( ! isset( $this->attributes['meta_caption'] ) || ! $this->attributes['meta_caption'] ) {
395 return;
396 }
397
398 if ( 'projects' === $this->source ) {
399 $this->attachment_caption = sight_get_the_excerpt( $this->attributes['meta_caption_length'] );
400 }
401 if ( 'categories' === $this->source ) {
402 $this->attachment_caption = sight_str_truncate( term_description( $this->object_id ), $this->attributes['meta_caption_length'] );
403 }
404 if ( 'custom' === $this->source ) {
405 $this->attachment_caption = sight_str_truncate( wp_get_attachment_caption( $this->attachment_id ), $this->attributes['meta_caption_length'] );
406 }
407 if ( 'post' === $this->source ) {
408 $this->attachment_caption = sight_str_truncate( wp_get_attachment_caption( $this->attachment_id ), $this->attributes['meta_caption_length'] );
409 }
410 }
411
412 /**
413 * Set Attachment Orientation
414 */
415 public function set_attachment_orientation() {
416 if ( isset( $this->attributes['attachment_orientation'] ) && $this->attributes['attachment_orientation'] ) {
417 $this->attachment_orientation = sprintf( 'sight-portfolio-overlay-ratio sight-portfolio-ratio-%s', $this->attributes['attachment_orientation'] );
418 }
419 }
420
421 /**
422 * Has Item Content
423 */
424 public function has_item_content() {
425 $has_item_content = false;
426
427 if ( $this->attachment_title ) {
428 $has_item_content = true;
429 }
430 if ( $this->attachment_meta ) {
431 $has_item_content = true;
432 }
433 if ( $this->attachment_caption ) {
434 $has_item_content = true;
435 }
436
437 return apply_filters( 'sight_entry_has_item_content', $has_item_content, $this );
438 }
439
440 /**
441 * Compile Item Class
442 *
443 * @param string $class The class of entry.
444 */
445 public function item_class( $class = array() ) {
446 $classes = array();
447
448 if ( $class ) {
449 if ( ! is_array( $class ) ) {
450 $class = preg_split( '#\s+#', $class );
451 }
452 $classes = array_map( 'esc_attr', $class );
453 } else {
454 // Ensure that we always coerce class to being an array.
455 $class = array();
456 }
457
458 // Set individual class.
459 $classes[] = 'sight-portfolio-entry sight-portfolio-video-wrap';
460
461 // Set entry source.
462 if ( $this->source ) {
463 $classes[] = 'sight-portfolio-entry-' . $this->source;
464 }
465
466 // Set entry object id.
467 if ( $this->object_id ) {
468 $classes[] = 'sight-portfolio-entry-' . $this->object_id;
469 }
470
471 // Set entry link to.
472 if ( $this->attachment_link_to ) {
473 $classes[] = 'sight-portfolio-entry-link-' . $this->attachment_link_to;
474 }
475
476 // Set entry request class.
477 if ( 'standard' === $this->attributes['layout'] ) {
478
479 if ( isset( $_REQUEST['action'] ) && 'sight_portfolio_ajax_load_more' === $_REQUEST['action'] ) {
480 $classes[] = 'sight-portfolio-entry-request';
481 }
482 }
483
484 // For projects.
485 if ( 'projects' === $this->source ) {
486 $post = get_post( get_the_ID() );
487
488 $classes[] = 'type-' . $post->post_type;
489 $classes[] = 'status-' . $post->post_status;
490
491 // Post thumbnails.
492 if ( current_theme_supports( 'post-thumbnails' ) && has_post_thumbnail( $post->ID ) && ! is_attachment( $post ) ) {
493 $classes[] = 'has-post-thumbnail';
494 }
495 }
496
497 call_user_func( 'printf', 'class="%s"', join( ' ', $classes ) );
498 }
499
500 /**
501 * Compile Item Outer Class
502 *
503 * @param string $class The class of entry.
504 */
505 public function item_outer_class( $class = array() ) {
506 $classes = array();
507
508 if ( $class ) {
509 if ( ! is_array( $class ) ) {
510 $class = preg_split( '#\s+#', $class );
511 }
512 $classes = array_map( 'esc_attr', $class );
513 } else {
514 // Ensure that we always coerce class to being an array.
515 $class = array();
516 }
517
518 // Set individual class.
519 $classes[] = 'sight-portfolio-entry-outer';
520
521 call_user_func( 'printf', 'class="%s"', join( ' ', $classes ) );
522 }
523
524 /**
525 * Compile Item Attachment
526 */
527 public function item_attachment() {
528 if ( ! $this->attachment_html ) {
529 return;
530 }
531
532 switch ( $this->attachment_link_to ) {
533 case 'media':
534 $attachment_link = $this->attachment_full_link;
535 break;
536 case 'page':
537 $attachment_link = $this->object_link;
538 break;
539 }
540
541 if ( $this->attachment_lightbox ) {
542 $attachment_link = $this->attachment_full_link;
543 }
544 ?>
545 <div class="sight-portfolio-entry__inner sight-portfolio-entry__thumbnail sight-portfolio-entry__overlay <?php echo esc_attr( $this->attachment_orientation ); ?>">
546 <figure class="sight-portfolio-overlay-background">
547 <?php do_action( 'sight_entry_item_attachment_before', $this ); ?>
548
549 <?php call_user_func( 'printf', '%s', $this->attachment_html ); ?>
550
551 <?php do_action( 'sight_entry_item_attachment_after', $this ); ?>
552
553 <?php
554 if ( $this->attachment_view_more ) {
555 ?>
556 <span class="sight-portfolio-view-more">
557 <span class="sight-portfolio-view-more-label">
558 <?php echo esc_html( $this->attachment_view_more_label ); ?>
559 </span>
560 </span>
561 <?php
562 }
563 ?>
564
565 <?php
566 if ( isset( $this->attributes['video'] ) && $this->attributes['video'] && 'none' !== $this->attributes['video'] ) {
567 sight_get_video_background( $this->attributes['video'], null, null, 'default', (bool) $this->attributes['video_controls'] );
568 }
569 ?>
570
571 <?php
572 if ( isset( $attachment_link ) ) {
573 ?>
574 <a class="sight-portfolio-overlay-link" href="<?php echo esc_url( $attachment_link ); ?>"></a>
575 <?php
576 }
577 ?>
578
579 <?php
580 if ( $this->attachment_lightbox_icon ) {
581 ?>
582 <span class="sight-zoom-icon-popup"></span>
583 <?php
584 }
585 ?>
586 </figure>
587
588 </div>
589 <?php
590 }
591
592 /**
593 * Compile Item Content
594 */
595 public function item_content() {
596 if ( $this->has_item_content() ) {
597 ?>
598 <div class="sight-portfolio-entry__inner sight-portfolio-entry__content">
599 <?php do_action( 'sight_entry_item_content_before', $this ); ?>
600
601 <?php if ( $this->attachment_title ) { ?>
602 <div class="sight-portfolio-entry__title">
603 <?php if ( $this->object_link ) { ?>
604 <<?php echo esc_html( $this->attachment_title_tag ); ?> class="sight-portfolio-entry__heading">
605 <a href="<?php echo esc_url( $this->object_link ); ?>">
606 <?php echo wp_kses( $this->attachment_title, 'post' ); ?>
607 </a>
608 </<?php echo esc_html( $this->attachment_title_tag ); ?>>
609 <?php } else { ?>
610 <<?php echo esc_html( $this->attachment_title_tag ); ?> class="sight-portfolio-entry__heading">
611 <?php echo wp_kses( $this->attachment_title, 'post' ); ?>
612 </<?php echo esc_html( $this->attachment_title_tag ); ?>>
613 <?php } ?>
614 </div>
615 <?php } ?>
616
617 <?php if ( $this->attachment_meta ) { ?>
618 <div class="sight-portfolio-entry__meta">
619 <?php echo wp_kses( $this->attachment_meta, 'post' ); ?>
620 </div>
621 <?php } ?>
622
623 <?php if ( $this->attachment_caption ) { ?>
624 <div class="sight-portfolio-entry__caption">
625 <?php echo wp_kses( $this->attachment_caption, 'post' ); ?>
626 </div>
627 <?php } ?>
628
629 <?php do_action( 'sight_entry_item_content_after', $this ); ?>
630 </div>
631 <?php
632 }
633 }
634 }
635 }
636