| 1 |  |  | <?php namespace Webwizo\ShortCodes\View; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | use ArrayAccess; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  | use Closure; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | use Illuminate\Support\MessageBag; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  | use Illuminate\Contracts\Support\Renderable; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  | use Illuminate\View\View as IlluminateView; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  | use Illuminate\View\Engines\EngineInterface; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  | use Webwizo\Shortcodes\Compilers\ShortcodeCompiler; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  | class View extends IlluminateView implements ArrayAccess, Renderable { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  |      * Short code engine resolver | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |      *  @var ShortcodeCompiler | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |     public $shortcode; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |      * Create a new view instance. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |      * @param \Illuminate\View\Factory|Factory                           $factory | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |      * @param \Illuminate\View\Compilers\EngineInterface|EngineInterface $engine | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |      * @param  string                                                    $view | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |      * @param  string                                                    $path | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |      * @param  array                                                     $data | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |      * @param ShortcodeCompiler                                          $shortcode | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |     public function __construct(Factory $factory, EngineInterface $engine, $view, $path, $data = array(), ShortcodeCompiler $shortcode) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |         parent::__construct($factory, $engine, $view, $path, $data); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |         $this->shortcode = $shortcode; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |      * Enable the shortcodes | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 37 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 38 |  |  |     public function withShortcodes() | 
            
                                                                        
                            
            
                                    
            
            
                | 39 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 40 |  |  |         $this->shortcode->enable(); | 
            
                                                                        
                            
            
                                    
            
            
                | 41 |  |  |         return $this; | 
            
                                                                        
                            
            
                                    
            
            
                | 42 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |      * Disable the shortcodes | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |     public function withoutShortcodes() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |         $this->shortcode->disable(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |         return $this; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |     public function withStripShortcodes() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |         $this->shortcode->setStrip(true); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |         return $this; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |      * Get the contents of the view instance. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |      * @return string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |     protected function renderContents() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |         // We will keep track of the amount of views being rendered so we can flush | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |         // the section after the complete rendering operation is done. This will | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |         // clear out the sections for any separate views that may be rendered. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  |         $this->factory->incrementRender(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  |         $this->factory->callComposer($this); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  |         $contents = $this->getContents(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  |          | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  |         if($this->shortcode->getStrip()) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  |         { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  |             // strip content without shortcodes | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  |             $contents = $this->shortcode->strip($contents); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  |         else | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  |         { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  |             // compile the shortcodes | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  |             $contents = $this->shortcode->compile($contents); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  |         // Once we've finished rendering the view, we'll decrement the render count | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  |         // so that each sections get flushed out next time a view is created and | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 |  |  |         // no old sections are staying around in the memory of an environment. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 |  |  |         $this->factory->decrementRender(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 |  |  |         return $contents; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 94 |  |  |  | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 95 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 96 |  |  |  |