/**
 * Short function to get translation
 *
 * Acts as a _() alternative. Will also log missing translations.
 *
 * @param string $key The key to translate (example: HELLO_WORLD)
 *
 * @return string Will return proper translation, hard-coded value or given key.
 */
function t($key)
{
    if (!empty($key)) {
        $translation = Translation::Get($key);
        if (!is_null($translation)) {
            return $translation;
        } else {
            if ($key == 'PAGE_TITLE') {
                return PAGE_TITLE;
            } else {
                if ($key == 'YEAR') {
                    return date('Y');
                } else {
                    if ($key == 'USERNAME' && LOGGEDIN) {
                        return session('username');
                    } else {
                        Lightwork::Log(sprintf('Missing translation key: %s (%s)', $key, Translation::Language()), Lightwork::LOG_DEBUG);
                    }
                }
            }
        }
    }
    return $key;
}
示例#2
0
/**
 * File used for general HTML 5 templating
 *
 * This file contains the basic templating needed for a properly valid HTML 5 page (doctype, head, body, ...)
 *
 * @author Perfler Dominik <*****@*****.**>
 * @copyright 2014-2015 Perfler Dominik
 * @license MIT
 */
require_once dirname(__FILE__) . '/bootstrap.php';
// Bootstrap this request
?>
<!DOCTYPE html>
<html lang="<?php 
echo Translation::Language();
?>
">
	<head>
		<?php 
Template::Load('page/head');
?>
	</head>
	<?php 
flush();
?>
	<body>
		<?php 
Template::Load('page/jsvars');
Template::Load('page/loader');
Menu::Draw('navigation');
示例#3
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
 }
示例#4
0
                    } else {
                        Lightwork::Log('Requested script ' . $page['customscript'] . ' could not be found.', Lightwork::LOG_WARN);
                    }
                    // The defined script could not be found, log this event
                }
                $success = embed($page);
                // Try to embed this page
                if (!$page['partial']) {
                    echo '</div>';
                }
                // Close the open container div (if this is no partial site)
                if ($success) {
                    if ($page['cache']) {
                        $content = ob_get_flush();
                        // The page was created successfully and we can flush it
                        Cache::Write('pages/' . Translation::Language() . '/' . $page['id'], $content, $page['cacheduration'], true);
                        // Write the successfully embeded page to cache
                    }
                } else {
                    ob_end_clean();
                    Lightwork::Log('Page is missing: ' . $page['path'] . '.', Lightwork::LOG_WARN);
                    // Page is missing, log this
                    Lightwork::Done(404, 'ERROR_PAGE_VANISHED');
                    // Page did not embed successfully - it is supposed to be there but isn't
                }
            }
        }
    }
}
function embed($page)
{