/** * Test the installation. * This function checks some of the basic functionality of qb (for example class * autoloading) and shows the value of some internal constants as well as other * useful information like qbURL return values. It can be used to debug your qb * installation. * @return bool True if the function was executed to the end. */ function qb_test() { header('Content-type: text/plain'); echo "Hi. This is qb " . QB_VERSION . ", nice to meet you.\n"; echo "If you can read this, you've included qb correctly and requested some tests.\n\n"; echo "First of all, some basic settings and what they are set to:\n"; echo "qb is installed in: " . QB_LIBDIR . "\n"; echo "Request origin: " . QB_REQDIR . "\n"; echo "Server document root: " . QB_DOCROOT . "\n"; echo "Requested URI path: " . QB_URIPATH . "\n\n"; if (QB_OURAUTOLOAD) { echo "qb will take care of autoloading its own classes.\n"; echo "If your application needs an __autoload() function, please define it\n"; echo "before including qb and call qb_autoload(\$class) as a fallback.\n"; } else { echo "You have defined your own class autoloader. If autoloading of qb's classes\n"; echo "fails, make sure it is calling qb_autoload(\$class) as a fallback.\n"; } echo "\nChecking class autoloading...\n"; new qbException(); echo "Class autoloading seems to be working.\n\n"; echo "BaseDir is: " . qbURL::getBaseDir() . "\n"; echo "BaseURL is: " . qbURL::getBaseURL() . "\n"; echo "Thus, virtual file requested is: " . qbURL::getVFile() . "\n"; echo "\nThis is the end of the automatic tests.\n"; echo "Check out http://scytale.name/proj/qb/ if something doesn't work.\n"; return true; }
/** * Set the URL base path. * * Automatically adds a leading slash and removes trailing ones. */ public static function setBasePath($path) { // If set to false or null, use auto-detection. if ($path === false || $path === null) { self::$basePath = null; return self::getBasePath(); } assert(is_string($path)); return self::$basePath = '/' . trim($path, '/'); }
function qb_buildpage($path, $template = 'html') { // Set $filename to the real filename. $filename = QB_SRC . $path . QB_SUF_SRC; // Check whether that really is under the source directory. if (!qbString::startsWith(realpath(QB_SRC), realpath($filename), false)) { return ''; } // Set $t to the contents of the file. if (($t = @file_get_contents($filename)) === false) { // If the file doesn't exist, return an error. // TODO: This never happens, because main logic already checks for the // existence of the file. return qb_template(QB_TPL_PAGE . '.' . $template, array('title' => 'file not found', 'content' => '<p class=\'qb_error\'>The file ' . htmlspecialchars($path) . ' could not be found.</p>')); } else { // File exists. Let $page[0] be the first line, $page[1] be the rest. $page = explode("\n", $t, 2); // Throw all tags in the first line into $tokens. preg_match_all('|<(.*):(.*)>(?!>)|U', $page[0], $tokens, PREG_SET_ORDER); // Initialize $meta as empty array. $meta = array(); foreach ($tokens as $token) { // Let $k be the name of the tag, $v its value. $k = $token[1]; $v = $token[2]; if ($k == '') { // Special case: the <:...> tag is a shortcut for <title:...> $k = 'title'; } if ($k == 'tags') { // Special case: expand the "tags" tag via a freaky regex that // splits them by spaces, multiword tags can be supplied by // using quotation marks. Should resemble Flickr's tag parsing // logic somehow. preg_match_all('%"(?! )([^"]+)(?<! )"|([^ ]+)%', $v, $tags, PREG_PATTERN_ORDER); // Initialize $parsedtags. $parsedtags = array(); foreach ($tags[0] as $tag) { // Remove quotation marks and spaces. $tag = str_replace('"', '', trim($tag)); // If there's something left, add it to $parsedtags array. if (strlen($tag) > 0) { $parsedtags[] = $tag; } } // Remove duplicate values, save the result in $v. $v = array_unique($parsedtags); if (count($v) > 0) { // If there are any tags left, create a "spantags" template // variable and put them in it. The "tags" variable stays // an array. No idea what's the use in it, but whatever. $meta['spantags'] = '<span class=\'tag\'>' . implode('</span> <span class=\'tag\'>', $v) . '</span>'; // Create a funky "ultags" for people who prefer that. $meta['ultags'] = '<ul class=\'tag\'><li>' . implode("</li>\n<li>", $v) . '</li></ul>'; } } // Create a template variable with that value. $meta[$k] = $v; } // "path" contains the handler plus $path, double slashes removed. $meta['path'] = preg_replace('|/+|', '/', qbURL::getHandler() . $path); // "content" contains the second and all following lines. $meta['content'] = $page[1]; // "escapedcontent" is like "content", but with escaped HTML characters. $meta['escapedcontent'] = htmlspecialchars($meta['content']); // "created" is the date the file was created. if (!array_key_exists('created', $meta)) { $meta['created'] = qb_created($path); } // "modified" is the modification date of the file. // "modified" and "created" can be overriden in the meta line. if (!array_key_exists('modified', $meta)) { $meta['modified'] = filemtime($filename); } if ($meta['modified'] == '!' || abs($meta['modified'] - $meta['created']) <= QB_OOPSTIME) { // If set to ! or in oops tolerance, simulate an unmodified file. $meta['modified'] = $meta['created']; } // If the two timestamps differ, set "wasmodified". if ($meta['created'] != $meta['modified']) { $meta['wasmodified'] = $meta['modified']; } // Run the template, return the result. return qb_template(QB_TPL_ARTICLE . '.' . $template, $meta); } }