Ejemplo n.º 1
0
 /**
  * Function used initialize the resource handler
  *
  * Will load all active stylesheets and javascripts from the database/cache into this class.
  */
 static function Initialize()
 {
     self::$stylesheets = Cache::Read('resources/stylesheets');
     // Try to load the stylesheets from cache
     if (!self::$stylesheets) {
         if (Database::Fetch(LWC::QUERY_RESOURCES_STYLES)) {
             foreach (Database::Data() as $stylesheet) {
                 self::$stylesheets[$stylesheet['name']] = $stylesheet;
                 // Add the stylesheet to the array
                 if (!is_file(CSS_DIR . $stylesheet['path'] . '.css')) {
                     if (!$stylesheet['source']) {
                         // ...and report so if no souce is available.
                         Lightwork::Log('Resource missing: ' . $stylesheet['name'], Lightwork::LOG_WARN);
                     } else {
                         self::MakeStylesheet($stylesheet['name'], STYLES);
                     }
                     // ...otherwise simply make it.
                 }
             }
             Cache::Write('resources/stylesheets', self::$stylesheets);
             // Write into cache
         }
     }
     self::$scripts = Cache::Read('resources/scripts');
     // Attempt to read scripts from database
     if (!self::$scripts) {
         if (Database::Fetch(LWC::QUERY_RESOURCES_SCRIPTS)) {
             foreach (Database::Data() as $script) {
                 self::$scripts[$script['name']] = $script;
                 // Add script to array
                 if (!is_file(JS_DIR . $script['path'] . '.js')) {
                     if (!$script['source']) {
                         Lightwork::Log('Resource missing: ' . $script['name'], Lightwork::LOG_WARN);
                     } else {
                         self::MakeScript($script['name'], STYLES);
                     }
                     // ...or compile it when a source is available.
                 }
             }
             Cache::Write('resources/scripts', self::$scripts);
             // Save to cache
         }
     }
     self::$initialized = true;
     // Initialized successfully
     return true;
 }