| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  | namespace samsoncms\cms; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  | use samson\core\CompressableExternalModule; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | use samsonphp\event\Event; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  | use samsonphp\router\Module; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  |  * SamsonCMS external compressible application for integrating | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  |  * @author Vitaly Iegorov <[email protected]> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  | class Application extends CompressableExternalModule | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  |     const EVENT_IS_CMS = 'samsonsms.is.cms'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |     /** @var string Module identifier */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |     public $id = 'cms'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |     public $baseUrl = 'cms'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |     /** @var bool Flag that currently we are woring in SamsonCMS */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |     protected $isCMS = false; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |     public function init(array $params = array()) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |         //trace('cmsInit'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |         // Old applications main page rendering | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |         Event::subscribe('template.main.rendered', array($this, 'oldMainRenderer')); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |         // Old applications menu rendering | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |         Event::subscribe('template.menu.rendered', array($this, 'oldMenuRenderer')); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |         Event::subscribe('samson.url.build', array($this, 'buildUrl')); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |         Event::subscribe('samson.url.args.created', array($this, 'parseUrl')); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |         Event::subscribe(Module::EVENT_ROUTE_FOUND, array($this, 'activeModuleHandler')); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |         Event::subscribe('samsonphp.router.create.module.routes', array($this, 'updateCMSPrefix')); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |         //[PHPCOMPRESSOR(remove,start)] | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |         $moduleList   = $this->system->module_stack; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |         foreach ($this->system->module_stack as $id => $module) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |             if (!$this->isModuleDependent($module) && $id != 'core' && !$this->ifModuleRelated($module)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |                 unset($moduleList[$id]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |         // Generate resources for new module | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |         $this->system->module('resourcer')->generateResources($moduleList, $this->path() . 'app/view/index.php'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |         //[PHPCOMPRESSOR(remove,end)] | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |         // Call parent initialization | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |         return parent::init($params); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |      * If module is dependent from current module through composer.json. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |      * @param $module Module for checking | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |      * @return bool True if module dependent | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 61 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 62 |  |  |     protected function isModuleDependent($module) | 
            
                                                                        
                            
            
                                    
            
            
                | 63 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 64 |  |  |         return isset($module->composerParameters['composerName']) && in_array($module->composerParameters['composerName'], $this->composerParameters['required']); | 
            
                                                                        
                            
            
                                    
            
            
                | 65 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |     public function isCMS() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  |         return $this->isCMS; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |     public function activeModuleHandler($module) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  |         // Define if routed module is related to SamsonCMS | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  |         if($this->isCMS = $this->ifModuleRelated($module)){ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  |             // TODO: This should be removed - Reparse url | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  |             url()->parse(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  |             // Switch template to SamsonCMS | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  |             $this->system->template($this->path() . 'app/view/index.php', true); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  |             Event::fire(self::EVENT_IS_CMS, array(&$this)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  |      * Callback for adding SamsonCMS related modules prefix to routes. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 |  |  |      * @param $module | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 |  |  |      * @param $prefix | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 |  |  |     public function updateCMSPrefix($module, &$prefix) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 94 |  |  |         if (($module->id != $this->id) && $this->ifModuleRelated($module)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 95 |  |  |             $prefix = '/' . $this->baseUrl . $prefix; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 96 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 97 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 98 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 99 |  |  |     public function buildUrl(&$urlObj, &$httpHost, &$urlParams) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 100 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 101 |  |  |         if ($this->isCMS) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 102 |  |  |             array_unshift($urlParams, $this->baseUrl); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 103 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 104 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 105 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 106 |  |  |     public function parseUrl(&$urlObj, &$urlArgs) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 107 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 108 |  |  |         if ($this->isCMS) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 109 |  |  |             array_shift($urlArgs); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 110 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 111 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 112 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 113 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 114 |  |  |      * Check if passed module is related to SamsonCMS. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 115 |  |  |      * Also method stores data to flag variable. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 116 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 117 |  |  |      * @param $module | 
            
                                                                                                            
                            
            
                                    
            
            
                | 118 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 119 |  |  |      * @return bool True if module related to SamsonCMS | 
            
                                                                                                            
                            
            
                                    
            
            
                | 120 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 121 |  |  |     public function ifModuleRelated($module) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 122 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 123 |  |  |         // Analyze if module class or one of its parents has samsoncms\ namespace pattern | 
            
                                                                                                            
                            
            
                                    
            
            
                | 124 |  |  |         return sizeof(preg_grep('/samsoncms\\\\/i', array_merge(array(get_class($module)), class_parents($module)))); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 125 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 126 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 127 |  |  |     public function __base() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 128 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 129 |  |  |         $templateModule = $this->system->module('template'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 130 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 131 |  |  |         // Switch system to SamsonCMS template module | 
            
                                                                                                            
                            
            
                                    
            
            
                | 132 |  |  |         $this->system->active($templateModule); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 133 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 134 |  |  |         // Call template handler | 
            
                                                                                                            
                            
            
                                    
            
            
                | 135 |  |  |         $templateModule->__handler(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 136 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 137 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 138 |  |  |     public function oldMainRenderer(&$html) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 139 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 140 |  |  |         // Render application main page block | 
            
                                                                                                            
                            
            
                                    
            
            
                | 141 |  |  |         foreach (\samsoncms\Application::loaded() as $app) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 142 |  |  |             // Show only visible apps | 
            
                                                                                                            
                            
            
                                    
            
            
                | 143 |  |  |             if ($app->hide == false /*&& $app->findView('sub_menu')*/) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 144 |  |  |                 $html .= $app->main(); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 145 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 146 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 147 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 148 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 149 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 150 |  |  |      * @deprecated All application should draw menu block via events | 
            
                                                                                                            
                            
            
                                    
            
            
                | 151 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 152 |  |  |     public function oldMenuRenderer(&$html, &$subMenu) | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 153 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 154 |  |  |         // Iterate loaded samson\cms\application | 
            
                                                                                                            
                            
            
                                    
            
            
                | 155 |  |  |         foreach (\samsoncms\Application::loaded() as $app) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 156 |  |  |             // Show only visible apps | 
            
                                                                                                            
                            
            
                                    
            
            
                | 157 |  |  |             if ($app->hide == false) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 158 |  |  |                 // Render application menu item | 
            
                                                                                                            
                            
            
                                    
            
            
                | 159 |  |  |                 $html .= m('template') | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 160 |  |  |                     ->view('menu/item') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 161 |  |  |                     ->active(url()->module == $app->id() ? 'active' : '') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 162 |  |  |                     ->app($app) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 163 |  |  |                     ->icon($app->icon) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 164 |  |  |                     ->name(isset($app->name{0}) ? $app->name : '') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 165 |  |  |                     ->output(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 166 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 167 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 168 |  |  |         $subMenu = ''; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 169 |  |  |         // Find current SamsonCMS application | 
            
                                                                                                            
                            
            
                                    
            
            
                | 170 |  |  |         if (\samsoncms\Application::find(url()->module, $app/*@var $app App*/)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 171 |  |  |             // If module has sub_menu view - render it | 
            
                                                                                                            
                            
            
                                    
            
            
                | 172 |  |  |             if ($app->findView('sub_menu')) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 173 |  |  |                 // Explode url by symbols '/' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 174 |  |  |                 $url = explode('/', $_SERVER['REQUEST_URI']); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 175 |  |  |                 // If isset url with params search and param page equal 0 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 176 |  |  |                 if (isset($url[4]) && $url[3] != 'form') { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 177 |  |  |                     // Default value for search field | 
            
                                                                                                            
                            
            
                                    
            
            
                | 178 |  |  |                     $paramSearch = urldecode($url[4]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 179 |  |  |                     // Set params search | 
            
                                                                                                            
                            
            
                                    
            
            
                | 180 |  |  |                     $app->set($paramSearch, 'search'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 181 |  |  |                 } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 182 |  |  | 				 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 183 |  |  |                 $subMenu .= $app->view('sub_menu')->set(t($app->name, true), 'appName')->output(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 184 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 185 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 186 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 187 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 188 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 189 |  |  |      * @deprecated | 
            
                                                                                                            
                            
            
                                    
            
            
                | 190 |  |  |      * @return string Page title | 
            
                                                                                                            
                            
            
                                    
            
            
                | 191 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 192 |  |  |     public function oldGetTitle() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 193 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 194 |  |  |         $local   = m('local'); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 195 |  |  |         $current = m(); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 196 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 197 |  |  |         return isset($current['title']) ? $current['title'] : | 
            
                                                                                                            
                            
            
                                    
            
            
                | 198 |  |  |             (isset($local['title']) ? $local['title'] : ''); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 199 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 200 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 201 |  |  |  | 
            
                        
This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.