+// Page style options, used when rendering pages. Options are exclusive.
+define('SKINNED', 0); // Page is rendered with the normal skin.
+define('SIMPLE', 1); // Page is rendered with a light skin (no leftnav).
+define('NO_SKIN', 2); // Page content is passed as-is (use for csv, xml, ...).
+
+// Hook options bitmasks. Authentication options are mutually exclusive, but
+// others (NO_HTTPS at the moment) are not.
+//
+// With PlStdHook, NO_AUTH indicates that no session will be started, and that
+// the actual handler is responsible for doing authentication; DO_AUTH forces
+// the engine to try to authenticate the user, including redirecting to the
+// login page. Note that DO_AUTH is ignored if AUTH_PUBLIC is requested.
+//
+// Options NO_AUTH and DO_AUTH are ignored with PlTokenHook.
+define('NO_AUTH', 0);
+define('DO_AUTH', 1);
+define('NO_HTTPS', 2);
+
+function pl_autoload($cls, array $pathes = array())
+{
+ $cls = strtolower($cls);
+ if (starts_with($cls, 'xdb')) {
+ $cls = 'xdb';
+ } else if (starts_with($cls, 'pldbtable')) {
+ $cls = 'pldbtableentry';
+ }
+ $basepath = dirname(dirname(dirname(__FILE__)));
+
+ array_unshift($pathes, 'core/classes', 'classes');
+ foreach ($pathes as $path) {
+ if (file_exists("$basepath/$path/$cls.php")) {
+ if (include_once "$basepath/$path/$cls.php") {
+ return true;
+ }
+ }
+ }
+ return false;
+}
+pl_autoload('Env');
+
+function pl_core_include($file)
+{
+ return dirname(__FILE__) . '/' . $file;
+}
+
+function pl_error_handler($errno, $errstr, $errfile, $errline)
+{
+
+ static $errortype;
+ if (!error_reporting())
+ return;
+
+ if (!isset($errortype)) {
+ $errortype = array (
+ E_ERROR => "Error",
+ E_WARNING => "Warning",
+ E_PARSE => "Parsing Error",
+ E_NOTICE => "Notice",
+ E_CORE_ERROR => "Core Error",
+ E_CORE_WARNING => "Core Warning",
+ E_COMPILE_ERROR => "Compile Error",
+ E_COMPILE_WARNING => "Compile Warning",
+ E_USER_ERROR => "User Error",
+ E_USER_WARNING => "User Warning",
+ E_USER_NOTICE => "User Notice",
+ E_STRICT => "Runtime Notice",
+ E_RECOVERABLE_ERROR => "Recoverable Error"
+ );
+ }
+
+ global $globals;
+ if (isset($globals) && !$globals->debug) {
+ if ($errno == E_NOTICE || $errno == E_USER_NOTICE || $errno == E_STRICT) {
+ return;
+ }
+ }
+ $type = isset($errortype[$errno]) ? $errortype[$errno] : $errno;
+ $error = strpos($type, 'Warning') !== false || strpos($type, 'Error') !==false;