| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  | defined( 'WPINC' ) || die; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  |  * @return mixed | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  | function glsr( $alias = null ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  | 	$app = \GeminiLabs\SiteReviews\Application::load(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  | 	return !empty( $alias ) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  | 		? $app->make( $alias ) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  | 		: $app; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  | } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |  * @return \WP_Screen|object | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  | function glsr_current_screen() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  | 	if( function_exists( 'get_current_screen' )) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  | 		$screen = get_current_screen(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  | 	return empty( $screen ) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  | 		? (object)array_fill_keys( ['base', 'id', 'post_type'], null ) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  | 		: $screen; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  | } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |  * @param mixed ...$vars | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 28 |  |  |  * @return void | 
            
                                                                        
                            
            
                                    
            
            
                | 29 |  |  |  */ | 
            
                                                                        
                            
            
                                    
            
            
                | 30 |  |  | function glsr_debug( ...$vars ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  | 	if( count( $vars ) == 1 ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  | 		$value = htmlspecialchars( print_r( $vars[0], true ), ENT_QUOTES, 'UTF-8' ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  | 		printf( '<div class="glsr-debug"><pre>%s</pre></div>', $value ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  | 	else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  | 		echo '<div class="glsr-debug-group">'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  | 		foreach( $vars as $var ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  | 			glsr_debug( $var ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  | 		echo '</div>'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  | } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |  * @param string $path | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |  * @param mixed $fallback | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |  * @return string|array | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  | function glsr_get_option( $path = '', $fallback = '' ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  | 	return glsr( 'Database\OptionManager' )->get( 'settings.'.$path, $fallback ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  | } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |  * @return array | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  | function glsr_get_options() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  | 	return glsr( 'Database\OptionManager' )->get( 'settings' ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  | } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |  * @param int $post_id | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |  * @return void|\GeminiLabs\SiteReviews\Review | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  | function glsr_get_review( $post_id ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  | 	$post = get_post( $post_id ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  | 	if( $post instanceof WP_Post ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  | 		return glsr( 'Database\ReviewManager' )->single( $post ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  | } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |  * @return array | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  |  * @todo document change of $reviews->reviews to $reviews->results | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  | function glsr_get_reviews( array $args = array() ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  | 	return glsr( 'Database\ReviewManager' )->get( $args ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  | } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  |  * @return \GeminiLabs\SiteReviews\Modules\Console | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  | function glsr_log() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  | 	$args = func_get_args(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  | 	$context = isset( $args[1] ) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  | 		? $args[1] | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  | 		: []; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  | 	$console = glsr( 'Modules\Console' ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  | 	return !empty( $args ) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 |  |  | 		? $console->log( 'debug', $args[0], $context ) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 |  |  | 		: $console; | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 91 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 92 |  |  |  |