Example #1
0
 private function generateContent()
 {
     ob_start();
     // Requesting P page
     $method = false;
     $call_object = false;
     // Find in classes under Vendor - Modules
     $real_class = Converter::to_camel_case(P);
     $class = '\\TMCms\\Modules\\' . $real_class . '\\Cms' . $real_class;
     if (!class_exists($class)) {
         // Not vendor module - check main CMS admin object
         $class = '\\TMCms\\Admin\\' . $real_class . '\\Cms' . $real_class;
         $call_object = true;
         if (!class_exists($class)) {
             // Search for exclusive module CMS pages created in Project folder for this individual site
             $file_path = DIR_MODULES . strtolower($real_class) . '/' . 'Cms' . $real_class . '.php';
             if (file_exists($file_path)) {
                 require_once $file_path;
                 // Check for module itself
                 $file_path = DIR_MODULES . strtolower($real_class) . '/' . 'Module' . $real_class . '.php';
                 if (file_exists($file_path)) {
                     require_once $file_path;
                 }
                 // Require all objects class files
                 $objects_path = DIR_MODULES . strtolower($real_class) . '/Entity/';
                 if (file_exists($objects_path)) {
                     foreach (array_diff(scandir($objects_path), ['.', '..']) as $object_file) {
                         require_once $objects_path . $object_file;
                     }
                 }
                 // CmsClass
                 $real_class = Converter::to_camel_case(P);
                 $class = '\\TMCms\\Modules\\' . $real_class . '\\Cms' . $real_class;
             }
         }
     }
     // Try autoload PSR-0 or PSR-4
     if (!class_exists($class)) {
         $class = 'TMCms\\Modules\\' . $real_class . '\\Cms' . $real_class;
     }
     // Try to find the right directory of requested class
     if (!class_exists($class)) {
         $class_name = 'Cms' . $real_class;
         $directory_iterator = new RecursiveDirectoryIterator(DIR_MODULES);
         $iterator = new RecursiveIteratorIterator($directory_iterator);
         foreach ($iterator as $file) {
             if ($file->getFilename() == $class_name . '.php') {
                 $module_path = $file->getPathInfo()->getPathName();
                 $module_name = $file->getPathInfo()->getFilename();
                 $module_directory_iterator = new RecursiveDirectoryIterator($module_path);
                 $module_iterator = new RecursiveIteratorIterator($module_directory_iterator);
                 foreach ($module_iterator as $module_file) {
                     $module_file_directory = $module_file->getPathInfo()->getFilename();
                     $module_file_name = $module_file->getFileName();
                     if (!in_array($module_file_name, ['.', '..']) and in_array($module_file_directory, [$module_name, 'Entity'])) {
                         require_once $module_file->getPathName();
                     }
                 }
                 $class = implode('\\', ['\\TMCms', 'Modules', $module_name, $class_name]);
                 break;
             }
         }
     }
     // Still no class
     if (!class_exists($class)) {
         dump('Requested class "' . $class . '" not found');
     }
     // Check existence of requested method
     if (class_exists($class)) {
         $call_object = true;
         // Check requested method exists or set default
         if (method_exists($class, P_DO)) {
             $method = P_DO;
         } else {
             $method = '_default';
         }
         // Final check we have anything to run
         if (!method_exists($class, $method)) {
             dump('Method "' . $method . '" not found in class "' . $class . '"');
         }
     }
     // Check user's permission
     if (!Users::getInstance()->checkAccess(P, $method)) {
         error('You do not have permissions to access this page ("' . P . ' - ' . $method . '")');
         die;
     }
     // Call required method
     if ($call_object) {
         $obj = new $class();
         $obj->{$method}();
     } else {
         call_user_func([$class, $method]);
     }
     $this->content = ob_get_clean();
 }