| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | namespace GeminiLabs\Castor\Helpers; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | use GeminiLabs\Castor\Helpers\Media; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  | use GeminiLabs\Castor\Helpers\PostMeta; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  | use GeminiLabs\Castor\Helpers\Theme; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  | use GeminiLabs\Castor\Helpers\Utility; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  | class Render | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  | 	public $media; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  | 	public $postmeta; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  | 	public $theme; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  | 	public $utility; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  | 	public function __construct( Media $media, PostMeta $postmeta, Theme $theme, Utility $utility ) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  | 	{ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  | 		$this->media    = $media; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  | 		$this->postmeta = $postmeta; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  | 		$this->theme    = $theme; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  | 		$this->utility  = $utility; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  | 	public function blockquote( $metaKey = false, array $attributes = [] ) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  | 	{ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  | 		if( $value = $this->postmeta->get( $metaKey )) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  | 			$this->utility->printTag( 'blockquote', wp_strip_all_tags( $value ), $attributes ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  | 	public function button( $postId = 0, $title = false ) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  | 	{ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  | 		$post = get_post( $postId ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  | 		if( !$postId || !$post )return; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  | 		if( !$title ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  | 			$title = $post->post_title; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  | 		printf( '<a href="%s" class="button"><span>%s</span></a>', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  | 			get_permalink( $post->ID ), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  | 			$title | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  | 		); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  | 	public function buttons( $postIds = [] ) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  | 	{ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  | 		foreach( (array) $postIds as $postId ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  | 			$this->button( $postId ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  | 	} | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 52 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 53 |  |  | 	public function content( $metaKey = false ) | 
            
                                                                        
                            
            
                                    
            
            
                | 54 |  |  | 	{ | 
            
                                                                        
                            
            
                                    
            
            
                | 55 |  |  | 		$content = $metaKey | 
            
                                                                        
                            
            
                                    
            
            
                | 56 |  |  | 			? $this->postmeta->get( $metaKey ) | 
            
                                                                        
                            
            
                                    
            
            
                | 57 |  |  | 			: get_the_content(); | 
            
                                                                        
                            
            
                                    
            
            
                | 58 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 59 |  |  | 		echo str_replace( ']]>', ']]>', apply_filters( 'the_content', $content )); | 
            
                                                                        
                            
            
                                    
            
            
                | 60 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  | 	public function featured( $args = [] ) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  | 	{ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  | 		$args = wp_parse_args( $args, [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  | 			'class'  => 'featured', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  | 			'image'  => get_post_thumbnail_id(), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  | 			'player' => '', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  | 			'video'  => 'featured_video', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  | 		]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  | 		$featuredHtml = $this->media->video( wp_parse_args( $args, [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  | 			'url' => $args['video'], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  | 		])); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  | 		if( empty( $featuredHtml ) && $featuredImage = $this->media->getImage( $args['image'] )) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  | 			$featuredHtml = sprintf( '<div class="featured-image"><img src="%s" alt="%s"></div><figcaption>%s</figcaption>', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  | 				$featuredImage->large['url'], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  | 				$featuredImage->alt, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  | 				$featuredImage->caption | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  | 			); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  | 		if( !empty( $featuredHtml )) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  | 			printf( '<figure class="%s">%s</figure>', $args['class'], $featuredHtml ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  | 	public function field( $name, array $args = [] ) | 
                            
                    |  |  |  | 
                                                                                        
                                                                                            
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  | 	{ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 |  |  | 	public function form( $name, array $args = [] ) | 
                            
                    |  |  |  | 
                                                                                        
                                                                                            
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 |  |  | 	{ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 |  |  | 	public function gallery( array $args = [] ) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 94 |  |  | 	{ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 95 |  |  | 		echo $this->media->gallery( $args ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 96 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 97 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 98 |  |  | 	public function title( $metaKey = false, array $attributes = [] ) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 99 |  |  | 	{ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 100 |  |  | 		$tag = apply_filters( 'castor/render/title/tag', 'h2' ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 101 |  |  | 		$value = $metaKey | 
            
                                                                                                            
                            
            
                                    
            
            
                | 102 |  |  | 			? $this->postmeta->get( $metaKey ) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 103 |  |  | 			: $this->theme->pageTitle(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 104 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 105 |  |  | 		if( !$value )return; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 106 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 107 |  |  | 		$this->utility->printTag( $tag, wp_strip_all_tags( $value ), $attributes ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 108 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 109 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 110 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 111 |  |  | 	 * @param array|string $args | 
            
                                                                                                            
                            
            
                                    
            
            
                | 112 |  |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 113 |  |  | 	 * @return string|null | 
            
                                                                                                            
                            
            
                                    
            
            
                | 114 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 115 |  |  | 	public function video( $args ) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 116 |  |  | 	{ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 117 |  |  | 		echo $this->media->video( $args ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 118 |  |  | 	} | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 119 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 120 |  |  |  | 
            
                        
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.