Scott Lawrence -- ' . 'yorgle@gmail.com' ); // v1.06 - 2018-09-17 LIBRARY // v1.05 - 2018-08-08 siteconfig.json, _site for hiding, config file pulled out // v1.04 - 2018-08-06 Markdown, multiple renderer support, sites dir // v1.03 - 2018-08-04 auto-adding (dir).js, (dir).css if they exist // v1.02 - 2018-08-01 added searching for other files, and just redirecting if they're not php // doesn't work right. // v1.01 - 2018-07-31 config file is json now (cleaner this way) // v1.00 - 2018-07-27 initial version //////////////////////////////////////////////////////////////////////////////// // MIT License: // Copyright 2018 Scott Lawrence // // Permission is hereby granted, free of charge, to any person obtaining a // copy of this software and associated documentation files (the "Software"), // to deal in the Software without restriction, including without limitation // the rights to use, copy, modify, merge, publish, distribute, sublicense, // and/or sell copies of the Software, and to permit persons to whom the // Software is furnished to do so, subject to the following conditions: // // The above copyright notice and this permission notice shall be included // in all copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. //////////////////////////////////////////////////////////////////////////////// // load in the config file... if( !file_exists( _LLMIN_CONF_ )) { die( _LLMIN_CONF_ . ': Config file not found!' ); } $confjson = file_get_contents( _LLMIN_CONF_ ); $config = (object) json_decode( $confjson ); // additional support libraries for php generation include_once( 'contrib/markdown_1.0.1g/markdown.php' ); // let's resolve the request. $config->Request->Page = $config->Request->Default; // start with the default if( isset( $_REQUEST[ 'requestpath' ])) { $config->Request->Page = $_REQUEST[ 'requestpath' ]; // passed in via htaccess rule // first, if it's a file request, sort that out llmp_LibraryFile( $config->Request->Page ); } llmp_SetupRequest( $config->Request->Page ); //// PAGE CONFIG ////////////////////////////////////////////////////// // If the config file for the page wasn't found, we generate an internal 404 error if( !$config->Request->Found ) { header('HTTP/1.0 404 Not Found', true, 404); $config->Page = llmp_PageInternal(); } else { // okay! the config json file exists, let's load it in... $confjson = file_get_contents( $config->Request->ConfigFile ); $config->Page = json_decode( $confjson ); } //// PAGE CHANGES ////////////////////////////////////////////////////// // auto-add the page's js and css $pagejs = ltrim( $config->Request->Page, '_' ) . '.js'; $pagecss = ltrim( $config->Request->Page, '_' ) . '.css'; if( file_exists( $config->Request->PageDir . $pagejs )) $config->Page->JS[] = $pagejs; if( file_exists( $config->Request->PageDir . $pagecss )) $config->Page->CSS[] = $pagecss; // The CSS/JS in that file are probably all relative to that directory, so let's tweak that. foreach( $config->Page->CSS as $i => $r ) { if( 'http' != substr( $r, 0, 4 )) { $config->Page->CSS[ $i ] = llmp_PageDir( $r ); } } foreach( $config->Page->JS as $i => $r ) { if( 'http' != substr( $r, 0, 4 )) { $config->Page->JS[ $i ] = llmp_PageDir( $r ); } } //// PAGE ROUTING ////////////////////////////////////////////////////// // and set up the path to the page file. if( count( $config->Request->PathParts ) > 1 ) { $config->Page->File = llmp_PageDir( $config->Request->PathParts[1] ); } else { $config->Page->File = llmp_PageDir( $config->Page->File ); } // search for the file. $config->Page->FileExtension = pathinfo( $config->Page->File, PATHINFO_EXTENSION); if( empty( $config->Page->FileExtension )) { // no extension, assume it's php $config->Page->FileExtension = 'php'; $config->Page->File .= '.php'; } // if the file is there as-is, and it's not one we care about, just refresh to it if( file_exists( $config->Page->File ) && !in_array( $config->Page->FileExtension, array_keys( (array)$config->Render )) ) { // provide the file header( "Refresh:0; url=../" . $config->Page->File ); exit; } //// DISPLAY TEMPLATE ////////////////////////////////////////////////////// // okay! We're ready to roll! let's build and actually send the page to the user! ?> Core->CSS, $config->Page->CSS ) as $cssfile ) { ?> Render->{ $config->Page->FileExtension }; // top page content wrapping if( $render->Wrap == true ) { llmp_PageTitle(); ?>
Type == 'require' ) { require( $config->Page->File ); } else if( $render->Type == 'markdown' ) { $filecontents = Markdown( llmp_ExpandVars( file_get_contents( $config->Page->File ))); print( $filecontents ); } else if( $render->Type == 'plaintext' ) { $filecontents = llmp_ExpandVars( file_get_contents( $config->Page->File )); print( '
' . $filecontents . '
' ); } else if( $render->Type == 'immediate' ) { print( $config->Page->Contents ); } // bottom page content wrapping if( $render->Wrap == true) { print( '
' ); llmp_PageFooter(); } // and include all of the javascript files to the bottom foreach( array_merge( $config->Core->JS, $config->Page->JS ) as $jsfile ) { ?> Request->Page = trim( $page, "/" ); $config->Request->PathParts = explode( '/', $config->Request->Page ); $config->Request->PageDir = $config->Request->PathBase . $config->Request->PathParts[0] . '/'; $config->Request->ConfigFile = $config->Request->PageDir . 'siteconfig.json'; if( is_dir( $config->Request->Page )){ $config->Request->Found = false; } else { $config->Request->Found = file_exists( $config->Request->ConfigFile ); } return $config->Request->Found; } // llmp_PageDir // generate the web path name for the page's directory // useful for linking to files/images in the same directory. // ie: // helper function for pages to setup page directory stuff function llmp_PageDir( $txt = '' ) { global $config; if( 'http' == substr( $txt, 0 , 4 )) { return $txt; } return $config->Request->PageDir . $txt; } // llmp_ExpandVars // Expand variables like ${xxx} with the contents from $config-Request->xxx etc function llmp_ExpandVars( $text ) { global $config; foreach( $config->Request as $k => $v ) { if( is_array( $v ) ) { $v = implode( '/', $v ); } $text = str_replace( '${' . $k . '}', $v, $text ); } return $text; } // llmp_PageTitle // Generate the standard header box with bootstrap-coloring per Page // if no title is passed in, the title from the config file is used function llmp_PageTitle( $pageheader='', $headerColor = false ) { global $config; if( $pageheader == '' ) { $pageheader = $config->Page->Title; } if( $headerColor == false ) { $headerColor = 'info'; if( isset( $config->Page->HeadingColor )) { $headerColor = $config->Page->HeadingColor; } } ?>

The requested path, ' . $config->Request->Page . ' was not found.'; } return (object) [ 'CSS' => [], 'JS' => [], 'Title' => $title, 'HeadingColor' => $headerColor, 'File' => 'nofile.int', 'Contents' => $content, 'Wrap' => true ]; } // llmp_library_file function llmp_LibraryFile( $path ) { $lKey = '${LIBRARY}'; $p = strpos( $path, $lKey ); if( $p === false ) { return; } $path = 'libraries' . substr( $path, $p + strlen( $lKey ) ); if( file_exists( $path )) { header( 'X-X-Path: ' . $path ); header( 'Content-Type: application/javascript' ); //' . mime_content_type( $path ) ); header( 'Content-Length: ' . filesize( $path ) ); ob_clean(); flush(); readfile( $path ); exit; } else { header( "HTTP/1.0 404 Not Found" ); die(); } }