Beispiel #1
0
 /** Default RudraX Plug
  *
  * @RequestMapping(url="combinejs/{mdfile}",type=js)
  *
  */
 function combineJs()
 {
     include_once RUDRA . "/core/handler/ResourceHandler.php";
     //echo "Booba";
     $handler = new ResourceHandler();
     $handler->invokeHandler();
 }
 /**
  * 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;
 }
Beispiel #3
0
}
// instanciate system
$system = System::Instance();
$system->check_system();
$system->load_essential();
// if we're dealing with global resources...
if (!isset($_GET['file'])) {
    // we want scope to serve up other groups of resources
    // default to all, if none specified
    if (!isset($_GET['group'])) {
        $_GET['group'] = 'all';
    }
    switch ($_GET['group']) {
        case 'all':
        default:
            // get resources from system
            $resources = $system->getResources($theme);
            $resources = $resources[$type];
            break;
        case 'uzlet':
            // get resources from system
            $resources = $system->get_uzlet_resources($type);
            break;
    }
} else {
    // otherwise set the resources var as our file
    $resources = $_GET['file'];
}
// pass data to Handle_resources::build function
ResourceHandler::build($type, $resources, $theme);
Beispiel #4
0
 /**
  * Return a css or js from the cache, or build and cache the resource
  *
  * @param string $type
  * @param mixed $resources
  * @param string $theme
  */
 function build($type, $resources, $theme = 'default')
 {
     // set a few variables
     $cache = TRUE;
     $minify = TRUE;
     $cache_dir = FILE_ROOT . 'data/resource_cache/';
     $last_modified = 0;
     $contents = '';
     $encoding_types = array('js' => 'text/javascript', 'css' => 'text/css');
     // ensure constants are defined, if they aren't chances are they should be false
     // whilst constants are used for the configurable settings, we do come checking
     // and then set some equivilent variables.
     // check if the cache flag is true, and check if the cache dir is writable
     $cache = is_writable($cache_dir) && get_config('CACHE_RESOURCES') === TRUE;
     // check if the minify flag is set
     $minify = get_config('MINIFY_RESOURCES') === TRUE;
     // the resources variable should be an array, but might be passed as a string
     if (!is_array($resources)) {
         $resources = array($resources);
     }
     // set a default http status of 200
     $status = 200;
     // collect last modified times from the resources, keeping the newest one
     // whilst checking if the file exists, if any are throw a 404
     foreach ($resources as $key => $file) {
         if ($file === FALSE) {
             unset($resources['$key']);
             continue;
         }
         if (file_exists($file)) {
             $file_time = filemtime($file);
             if ($file_time > $last_modified) {
                 $last_modified = $file_time;
             }
         } else {
             $status = 404;
             // we can use <br /> as as far as the browser is concerned we're sending html
             echo "/* File does not exist: " . $file . " */" . "<br />";
         }
     }
     if ($status === 404) {
         header("HTTP/1.0 404 Not Found");
         exit;
     }
     // generate hash of resources array, include last modified to force a new version
     $hash = md5(serialize($resources) . $last_modified);
     // generate etag string
     $etag = $last_modified . '-' . $hash;
     // check if HTTP_IF_NONE_MATCH matched etag string
     if ($cache && isset($_SERVER['HTTP_IF_NONE_MATCH']) && stripslashes($_SERVER['HTTP_IF_NONE_MATCH']) == '"' . $etag . '"') {
         // return visit and no modifications, send nothing but a 304
         header("HTTP/1.0 304 Not Modified");
         header('Content-Length: 0');
         exit;
     }
     // send etag header
     header("Etag: \"" . $etag . "\"");
     // if cache is true...
     if ($cache) {
         // check if cache file exists...
         $cache_path = $cache_dir . $hash . "." . $type;
         if (file_exists($cache_path)) {
             // and send it to the browser
             if ($fp = fopen($cache_path, 'rb')) {
                 header("Content-Type: " . $encoding_types[$type]);
                 header("Content-Length: " . filesize($cache_path));
                 fpassthru($fp);
                 fclose($fp);
                 exit;
             }
         }
     }
     // if we've reached this point we either didn't want the cache or it didn't exist
     // loop through each file...
     foreach ($resources as $file) {
         // get the file extension...
         $file_extension = pathinfo($file, PATHINFO_EXTENSION);
         // get the file contents...
         $file_contents = file_get_contents($file);
         // if we're dealing with a less file, parse and convert it
         if ($file_extension == 'less') {
             $file_contents = str_replace('{THEME_PATH}', THEME_ROOT . "{$theme}/css/", $file_contents);
             // instantiate less...
             $lc = new lessc();
             try {
                 $file_contents = $lc->compile($file_contents);
             } catch (exception $ex) {
                 // failed to compile, spit 500 and make sure the response isn't cached by browsers/proxies
                 http_response_code(500);
                 header('Cache-Control: no-cache, no-store, must-revalidate');
                 header('Pragma: no-cache');
                 header('Expires: 0');
                 echo "Failed to compile less file - " . $ex->getMessage();
                 exit;
             }
             // and parse the file
             $file_contents = $lc->compile($file_contents);
         }
         // if applicable, minify the contents...
         if ($minify && $type == 'css') {
             $file_contents = ResourceHandler::minifyCSS($file_contents);
         }
         // concatinate file path and contents to var
         $contents .= "/** " . $file . " **/" . "\n";
         $contents .= $file_contents . "\n\n";
     }
     // send content type and length headers
     header("Content-Type: " . $encoding_types[$type]);
     header('Content-Length: ' . strlen($contents));
     echo $contents;
     // if cache is true...
     if ($cache) {
         // write cache file
         if ($fp = fopen($cache_path, 'wb')) {
             fwrite($fp, $contents);
             fclose($fp);
         }
     }
     exit;
 }
Beispiel #5
0
 /**
  * Function to get the "heart" beating
  *
  * After all the nasty PHP stuff is done (sessions, database, error handling, configuration, ...) we can finally get started with Lightwork...
  *
  * @param mixed $status If set together with $message an error page will be forced to display.
  * @param string $message If set together with $status an error page will be forced to display.
  */
 static function Initialize($status = null, $message = null)
 {
     if (isset($_GET['page']) || $status != null) {
         header('Content-Type: text/html; charset=utf-8');
         // Twice is better than once - set the charset and content-type
         header('Content-Language: ' . Translation::Language());
         // Set the content-language to the current translation language
         self::$pages = Cache::Read('pages');
         // Try to read all pages from cache
         if (!self::$pages) {
             if (Database::Fetch(LWC::QUERY_PAGES)) {
                 self::$pages = Database::Data();
                 // We got the pages, saving them...
                 Cache::Write('pages', self::$pages);
                 // ...and caching them.
             }
         }
         ResourceHandler::Initialize();
         // Initialize the resource handler - essentially it loads all stylesheets and javascripts
         if (DEBUG_MAKEALL) {
             ResourceHandler::MakeAll(STYLES);
         }
         // Incase it is required we will compile & minify all stylesheets and scripts (might make requests slow - debugging only)
         if ($status == null) {
             if (!empty($_GET['page'])) {
                 self::HandlePage($_GET['page']);
             } else {
                 self::HandlePage();
             }
             // Page parameter is empty or not set - page handler will use index by default
             unset($_GET['page']);
             // Unset the original page parameter from $_GET array...
             unset($_REQUEST['page']);
             // ...and $_REQUEST array.
         } else {
             self::SetError($status, $message);
         }
         // Since we need to force an error we are doing so now.
         self::$request = self::REQUEST_PAGE;
         // Set the request type
         Lightwork::Log(sprintf('This is a page request. (%s)', self::$page['key']), Lightwork::LOG_DEBUG);
         // Log this successfully handled request
     } else {
         if (isset($_GET['script'])) {
             self::$scripts = Cache::Read('scripts');
             // Attempt to read enabled scripts from cache
             if (!self::$scripts) {
                 if (Database::Fetch(LWC::QUERY_SCRIPTS)) {
                     self::$scripts = Database::Data();
                     // We got the scripts, lets save them...
                     Cache::Write('scripts', self::$scripts);
                     // ...and cache them.
                 }
             }
             if (!empty($_GET['script'])) {
                 self::HandleScript($_GET['script']);
             } else {
                 self::SetError('error', 'ERROR_BAD_REQUEST');
             }
             //There is no default so we fail...
             unset($_GET['script']);
             // Unset the original script from $_GET...
             unset($_REQUEST['script']);
             // ...and $_REQUEST.
             self::$request = self::REQUEST_SCRIPT;
             // Set this request as a script request
             Lightwork::Log(sprintf('This is a script request. (%s)', self::$script['key']), Lightwork::LOG_DEBUG);
             // Log this successful script handling
         } else {
             if (isset($_GET['file'])) {
                 self::$files = Cache::Read('files');
                 // Attempt to read available files from cache
                 if (!self::$files) {
                     if (Database::Fetch(LWC::QUERY_FILES)) {
                         self::$files = Database::Data();
                         // We got the files, saving them for now...
                         Cache::Write('files', self::$files);
                         // ...and caching them for later.
                     }
                 }
                 // Grab file from parameters, no default
                 if (!empty($_GET['file'])) {
                     self::HandleFile($_GET['file']);
                 }
                 unset($_GET['file']);
                 // Unset the original file from $_GET...
                 unset($_REQUEST['file']);
                 // ...and $_REQUEST.
                 self::$request = self::REQUEST_FILE;
                 // Mark this request as a file request
                 Lightwork::Log(sprintf('This is a file request. (%s)', self::$file['path']), Lightwork::LOG_DEBUG);
                 // Log this successful file handling
             } else {
                 if (isset($_GET['cronjob'])) {
                     self::$cronjobs = Cache::Read('cronjobs');
                     // Attempt to read available cronjobs from cache
                     if (!self::$cronjobs) {
                         if (Database::Fetch(LWC::QUERY_CRONJOBS)) {
                             self::$cronjobs = Database::Data();
                             // We got the cronjobs, saving them...
                             Cache::Write('cronjobs', self::$cronjobs);
                             // ...and caching them.
                         } else {
                             self::$cronjobs = array();
                         }
                         // Return no cronjobs if we couldn't get any cronjobs
                     }
                     self::HandleCronjob($_GET['cronjob']);
                     // Handle a single cronjob if necessary
                     self::$request = self::REQUEST_CRONJOB;
                     // Mark this request as a cronjob request
                     Lightwork::Log('This is a cronjob request.', Lightwork::LOG_DEBUG);
                     // Log this successful cronjob handling
                 } else {
                     if (isset($_GET['sitemap'])) {
                         // Load pages
                         self::$pages = Cache::Read('pages');
                         // Since this is the sitemap we still need to load the pages from cache...
                         if (!self::$pages) {
                             if (Database::Fetch(LWC::QUERY_PAGES)) {
                                 self::$pages = Database::Data();
                                 // ...or database.
                                 Cache::Write('pages', self::$pages);
                             }
                         }
                         self::$request = self::REQUEST_SITEMAP;
                         Lightwork::Log('This is a sitemap request.', Lightwork::LOG_DEBUG);
                     } else {
                         Lightwork::Log('This is an invalid request!', Lightwork::LOG_DEBUG);
                         // We will output a simple log message if we received an invalid request...
                         echo 'Lightwork was not set up properly! (invalid rewrite rules)';
                         // ...and output an error message.
                         die;
                     }
                 }
             }
         }
     }
     self::$initialized = true;
     // Initialization is done
 }
Beispiel #6
0
<base href="<?php 
echo WEB_ROOT;
?>
" />
<?php 
foreach (ResourceHandler::GetStylesheets() as $stylesheet) {
    echo '<link rel="stylesheet" href="css/' . $stylesheet['path'] . '.css" />';
}
foreach (ResourceHandler::GetScripts() as $script) {
    echo '<script type="text/javascript" src="js/' . $script['path'] . '.js"></script>';
}
?>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />

<link rel="shortcut icon" type="image/x-icon" href="img/icons/favicon.ico" />

<meta name="application-name" content="Lightwork" />
<meta name="msapplication-TileColor" content="#ffffff" />
<meta name="msapplication-square70x70logo" content="img/tiles/small.png" />
<meta name="msapplication-square150x150logo" content="img/tiles/medium.png" />
<meta name="msapplication-wide310x150logo" content="img/tiles/wide.png" />
<meta name="msapplication-square310x310logo" content="img/tiles/large.png" />

<title data-page="<?php 
echo PAGE_TITLE;
?>
"><?php 
echo Lightwork::Title();
?>
</title>
Beispiel #7
0
<?php

// Default RudraX Plug
RudraX::mapRequest("combinejs/{mdfile}", function () {
    include_once RUDRA . "/core/handler/ResourceHandler.php";
    $handler = new ResourceHandler();
    $handler->invokeHandler();
});
RudraX::mapRequest("template/{temp}", function ($temp = "nohandler") {
    return RudraX::invokeHandler($temp);
});
RudraX::mapRequest('data/{eventname}', function ($eventName = "dataHandler") {
    $controller = RudraX::getDataController();
    $controller->invokeHandler($eventName);
});
RudraX::mapRequest("resources.json", function ($cb = "") {
    require_once RUDRA . '/core/model/Header.php';
    echo $cb . "((" . json_encode(Header::getModules()) . ").bundles)";
});
// Default Plug for default page
RudraX::mapRequest("", function () {
    return RudraX::invokeHandler("Index");
});