Exemplo n.º 1
0
 public function page($slug = "", $values = array(), $layout = "")
 {
     $location = "{$this->path}/{$slug}.html";
     if ($layout == "") {
         $layout = \Lobby\FS::get("/src/Data/themes/{$this->theme}/layout.html");
     }
     if ($this->titleTag && $values["{{page-title}}"] != $this->name) {
         $layout = str_replace("<title>{{page-title}}</title>", "<title>{{page-title}} - {{site-name}}</title>", $layout);
     }
     if (isset($values['{{page-title}}']) && isset($values['{{page-content}}'])) {
         $toReplace = array("{{page-title}}" => "", "{{page-content}}" => "", "{{site-head}}" => "", "{{site-name}}" => $this->name, "{{site-tagline}}" => $this->tagline, "{{site-sidebar}}" => "");
         $result = array_merge($toReplace, $values);
         foreach ($result as $from => $to) {
             $layout = str_replace($from, $to, $layout);
         }
         /* Make directory if it doesn't exist */
         $dir = dirname($location);
         if (!file_exists($dir)) {
             mkdir($dir);
         }
         /* Make the Page file */
         file_put_contents($location, $layout);
         return true;
     } else {
         return false;
     }
 }
Exemplo n.º 2
0
 /**
  * Map static functions into object methods
  */
 public function __call($function, $args)
 {
     switch ($function) {
         case "exists":
         case "loc":
             return FS::$function($this->base . "/" . $args[0]);
         case "get":
             return FS::get($this->base . "/" . $args[0]);
         case "write":
         case "remove":
             return call_user_func_array(FS::$function, array($this->base . "/" . $args[0], $args[1], $args[2]));
     }
 }
Exemplo n.º 3
0
 public static function __constructStatic()
 {
     /**
      * Callback on fatal errors
      */
     register_shutdown_function(function () {
         return \Lobby::fatalErrorHandler();
     });
     if (!isset($_SERVER["SERVER_NAME"])) {
         /**
          * Lobby is not loaded by browser request, but by a script
          * so $_SERVER vars won't exist. This will cause problems
          * for URL making, hence we must define it's CLI
          */
         self::$cli = true;
     }
     self::sysInfo();
     self::config();
     $lobbyInfo = FS::get("/lobby.json");
     if ($lobbyInfo !== false) {
         $lobbyInfo = json_decode($lobbyInfo);
         \Lobby::$version = $lobbyInfo->version;
         \Lobby::$versionName = $lobbyInfo->codename;
         \Lobby::$versionReleased = $lobbyInfo->released;
     }
     /**
      * Some checking to make sure Lobby works fine
      */
     if (!is_writable(L_DIR)) {
         $error = array("Fatal Error", "The permissions of the Lobby folder is invalid. You should change the permission of <blockquote>" . L_DIR . "</blockquote>to read and write (0755).");
         if (\Lobby::getSysInfo("os") === "linux") {
             $error[1] .= "<p clear>On Linux systems, do this in terminal : <blockquote>sudo chown \${USER}:www-data " . L_DIR . " -R && sudo chmod u+rwx,g+rw,o+r " . L_DIR . " -R</blockquote></p>";
         }
         \Response::showError($error[0], $error[1]);
     }
     \Assets::config(array("basePath" => L_DIR, "baseURL" => self::getURL(), "serveFile" => "includes/serve-assets.php", "debug" => self::getConfig("debug")));
 }
Exemplo n.º 4
0
 /**
  * Create Tables in the DB
  * Supports both MySQL & SQLite
  */
 public static function makeDatabase($prefix, $db_type = "mysql")
 {
     try {
         if ($db_type === "mysql") {
             $sql_code = "\n        CREATE TABLE IF NOT EXISTS `{$prefix}options` (\n          `id` int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY,\n          `name` varchar(64) NOT NULL,\n          `value` text CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL\n        ) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;\n        CREATE TABLE IF NOT EXISTS `{$prefix}data` (\n          `id` int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY,\n          `app` varchar(50) NOT NULL,\n          `name` varchar(150) NOT NULL,\n          `value` longblob NOT NULL,\n          `created` datetime NOT NULL,\n          `updated` datetime NOT NULL\n        ) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1;";
             /**
              * Create Tables
              */
             $sql = self::$dbh->prepare($sql_code);
             $sql->execute();
         } else {
             /**
              * SQLite
              * Multiple commands separated by ';' cannot be don in SQLite
              * Weird, :P
              */
             $sql_code = "\n        CREATE TABLE IF NOT EXISTS `{$prefix}options` (\n          `id` INTEGER PRIMARY KEY AUTOINCREMENT,\n          `name` varchar(64) NOT NULL,\n          `value` text NOT NULL\n        );\n        ";
             self::$dbh->exec($sql_code);
             $sql_code = "\n        CREATE TABLE IF NOT EXISTS `{$prefix}data` (\n          `id` INTEGER PRIMARY KEY AUTOINCREMENT,\n          `app` varchar(50) NOT NULL,\n          `name` varchar(150) NOT NULL,\n          `value` blob NOT NULL,\n          `created` datetime NOT NULL,\n          `updated` datetime NOT NULL\n        );";
             self::$dbh->exec($sql_code);
         }
         /* Insert The Default Data In To Tables */
         $lobby_info = FS::get("/lobby.json");
         $lobby_info = json_decode($lobby_info, true);
         $sql = self::$dbh->prepare("\n        INSERT INTO `{$prefix}options`\n          (`name`, `value`)\n        VALUES\n          ('lobby_version', ?),\n          ('lobby_version_release', ?);");
         $sql->execute(array($lobby_info['version'], $lobby_info['released']));
         return true;
     } catch (\PDOException $Exception) {
         self::$error = $Exception->getMessage();
         self::log("Install error : " . self::$error);
         return false;
     }
 }
Exemplo n.º 5
0
 public static function get($path)
 {
     return \Lobby\FS::get(APP_DIR . $path);
 }
Exemplo n.º 6
0
 /**
  * Fetch the questions array
  */
 public function questions($class)
 {
     return json_decode(\Lobby\FS::get("/src/Data/questions.{$class}.json"), true);
 }
Exemplo n.º 7
0
<?php

if (isset($_POST['answers'])) {
    /**
     * The Default Values
     */
    $class = $_SESSION['kerala-it-exam-class'];
    $questions = $this->questions($class);
    $marks = json_decode(\Lobby\FS::get("/src/Data/mark.json"), true);
    $awarded = array();
    $total_mark = $marks['total'];
    /**
     * The User Data
     */
    $answers = $_POST['answers'];
    $mark = 0;
    /**
     * We don't do any checking, because I don't think the user will try to crack
     * the software. Why would he ? Also, because I'm lazy
     */
    $short = $answers['short'];
    $multiple = $answers['multiple'];
    $note = $answers['note'];
    /**
     * First, Short Answers
     */
    foreach ($short as $qID => $answer) {
        /**
         * The right answer is hashed with MD5
         */
        $right_answer = strtolower($questions['short'][$qID]['answer']);
Exemplo n.º 8
0
 public static function makeDatabase($prefix)
 {
     try {
         /* Create Tables */
         $sql = self::$dbh->prepare("\n        CREATE TABLE IF NOT EXISTS `{$prefix}options` (\n          `id` int(11) NOT NULL AUTO_INCREMENT,\n          `name` varchar(64) NOT NULL,\n          `val` text NOT NULL,\n          PRIMARY KEY (`id`),\n          UNIQUE(`name`)\n        ) ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;\n        CREATE TABLE IF NOT EXISTS `{$prefix}data` (\n          `id` int(11) NOT NULL AUTO_INCREMENT,\n          `app` varchar(50) NOT NULL,\n          `name` varchar(150) NOT NULL,\n          `content` longtext NOT NULL,\n          `created` datetime NOT NULL,\n          `updated` datetime NOT NULL,\n           PRIMARY KEY (`id`)\n        ) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;");
         $sql->execute();
         /* Insert The Default Data In To Tables */
         $lobby_info = \Lobby\FS::get("/lobby.json");
         $lobby_info = json_decode($lobby_info, true);
         $sql = self::$dbh->prepare("\n        INSERT INTO `{$prefix}options` (\n          `id`, \n          `name`, \n          `val`\n        ) VALUES (\n          NULL,\n          'lobby_version',\n          ?\n        ),(\n          NULL,\n          'lobby_version_release',\n          ?\n        );");
         $sql->execute(array($lobby_info['version'], $lobby_info['released']));
         return true;
     } catch (\PDOException $Exception) {
         return false;
     }
 }
Exemplo n.º 9
0
<?php

/**
 * Add the <head> files if it's not the install page
 */
if (!\Lobby::status("lobby.install")) {
    /**
     * Left Menu
     */
    \Lobby\UI\Panel::addTopItem("lobbyHome", array("text" => "Home", "href" => L_URL, "position" => "left"));
    $adminArray = array("text" => "Admin", "href" => "/admin", "position" => "left");
    $adminArray["subItems"] = array("app_manager" => array("text" => "Apps", "href" => "/admin/apps.php"), "lobby_store" => array("text" => "Lobby Store", "href" => "/admin/lobby-store.php"), "about" => array("text" => "Settings", "href" => "/admin/settings.php"));
    \Lobby\UI\Panel::addTopItem("lobbyAdmin", $adminArray);
    if (\Lobby\FS::exists("/upgrade.lobby")) {
        require_once L_DIR . "/includes/src/Update.php";
        $l_info = json_decode(\Lobby\FS::get("/lobby.json"));
        if ($lobby_version != $l_info->version) {
            Lobby\DB::saveOption("lobby_latest_version", $l_info->version);
            Lobby\DB::saveOption("lobby_latest_version_release", $l_info->released);
        }
        \Lobby\Update::finish_software_update();
    }
}
if (\Lobby::status("lobby.admin")) {
    /**
     * Add Admin Pages' stylesheet, script
     */
    \Assets::js("admin", "/admin/js/admin.js");
    /**
     * Add sidebar
     */
Exemplo n.º 10
0
 public static function finish_software_update($admin_previously_installed = false)
 {
     FS::write("/upgrade.lobby", "1", "w");
     if ($admin_previously_installed) {
         FS::remove("/contents/modules/admin/disabled.txt");
     }
     $latest_version = DB::getOption("lobby_latest_version");
     self::log("Updated Lobby to version {$latest_version}");
     /**
      * Remove Depreciated Files
      */
     $deprecatedFilesInfoLoc = "/contents/update/removeFiles.php";
     if (FS::exists($deprecatedFilesInfoLoc)) {
         $files = FS::get($deprecatedFilesInfoLoc);
         $files = explode("\n", $files);
         if (count($files) !== 0) {
             $files = array_filter($files);
             foreach ($files as $file) {
                 $fileLoc = L_DIR . "/{$file}";
                 if (file_exists($fileLoc) && $fileLoc != L_DIR) {
                     FS::remove($fileLoc);
                     self::log("Removed Deprecated File: {$fileLoc}");
                 }
             }
             copy(FS::loc($deprecatedFilesInfoLoc), FS::loc("{$deprecatedFilesInfoLoc}.txt"));
             FS::remove($deprecatedFilesInfoLoc);
             self::log("Finished Removing Deprecated Files");
         }
     }
     /**
      * Database Update
      */
     if (FS::exists("/update/sqlExecute.sql")) {
         self::log("Upgrading Lobby Database");
         $sqlCode = FS::get("/update/sqlExecute.sql");
         $sql = \Lobby\DB::prepare($sqlCode);
         if (!$sql->execute()) {
             echo ser("Error", "Database Update Couldn't be made. <a href='update.php'>Try again</a>");
         } else {
             FS::remove("/update/sqlExecute.sql");
         }
         self::log("Updated Lobby Database");
     }
     FS::remove("/upgrade.lobby");
     self::log("Lobby is successfully Updated.");
 }
Exemplo n.º 11
0
 /**
  * Get the manifest info of app as array
  */
 private function setInfo()
 {
     $manifest = FS::exists($this->dir . "/manifest.json") ? FS::get($this->dir . "/manifest.json") : false;
     if ($manifest) {
         $details = json_decode($manifest, true);
         $details = array_replace_recursive(self::$manifestConfig, $details);
         /**
          * Add extra info with the manifest info
          */
         $details['id'] = $this->app;
         $details['dir'] = $this->dir;
         $details['url'] = Lobby::getURL() . "/app/{$this->app}";
         $details['srcURL'] = Lobby::getURL() . "/contents/apps/{$this->app}";
         $details['adminURL'] = Lobby::getURL() . "/admin/app/{$this->app}";
         /**
          * Prefer SVG over PNG
          */
         $details['logo'] = $details['logo'] !== false ? FS::exists($this->dir . "/src/image/logo.svg") ? self::$appsURL . "/{$this->app}/src/image/logo.svg" : self::$appsURL . "/{$this->app}/src/image/logo.png" : Themes::getThemeURL() . "/src/main/image/app-logo.png";
         $details["latestVersion"] = isset(self::$appUpdates[$this->app]) ? self::$appUpdates[$this->app] : null;
         $details = \Hooks::applyFilters("app.manifest", $details);
         /**
          * Insert the info as a property
          */
         $this->info = $details;
         /**
          * Whether app is enabled
          */
         $this->enabled = in_array($this->app, self::getEnabledApps(), true);
         return $details;
     } else {
         return false;
     }
 }
Exemplo n.º 12
0
if (preg_match("/,/", $f)) {
    $files = explode(",", $f);
} else {
    /**
     * Only 1 File is present
     */
    $files = array($f);
}
/* Loop through files and */
foreach ($files as $file) {
    $file = str_replace(L_URL, "", $file);
    if ($file == "/includes/lib/jquery/jquery-ui.js" || $file == "/includes/lib/jquery/jquery.js" || $file == "/includes/lib/core/JS/main.js" || $file == "/includes/lib/core/JS/app.js") {
        $extraContent .= \Lobby\FS::get($file);
    } else {
        if (\Lobby\FS::exists($file)) {
            $content .= \Lobby\FS::get($file);
        } else {
            $type_of_file = isset($js) ? "JavaScript" : "CSS";
            \Lobby::log("{$type_of_file} file was not found in location given : {$file}");
        }
    }
    if (isset($css)) {
        $to_replace = array("<?L_URL?>" => L_URL, "<?THEME_URL?>" => THEME_URL);
        if (isset($_GET['APP_URL'])) {
            $to_replace["<?APP_URL?>"] = htmlspecialchars(urldecode($_GET['APP_URL']));
            $to_replace["<?APP_SRC?>"] = htmlspecialchars(urldecode($_GET['APP_SRC']));
        }
        foreach ($to_replace as $from => $to) {
            $content = str_replace($from, $to, $content);
        }
    }
Exemplo n.º 13
0
 public static function finish_software_update($admin_previously_installed = false)
 {
     if ($admin_previously_installed) {
         \Lobby\FS::remove("/contents/modules/admin/disabled.txt");
     }
     $latest_version = getOption("lobby_latest_version");
     \Lobby::log("Updated Lobby Software To version {$latest_version}");
     /* Remove Depreciated Files */
     if (\Lobby\FS::exists("/contents/update/removeFiles.php")) {
         $files = \Lobby\FS::get("/contents/update/removeFiles.php");
         $files = explode("\n", $files);
         if (count($files) != 0) {
             foreach ($files as $file) {
                 // iterate files
                 $fileLoc = L_DIR . "/{$file}";
                 if (file_exists($fileLoc) && $fileLoc != L_DIR) {
                     $type = filetype($fileLoc);
                     if ($type == "file") {
                         \Lobby\FS::remove($fileLoc);
                     } else {
                         if ($type == "dir") {
                             rmdir($fileLoc);
                         }
                     }
                 }
             }
             \Lobby\FS::remove(L_DIR . "/contents/update/removeFiles.php");
             \Lobby::log("Removed Deprecated Files");
         }
     }
     /**
      * Database Update
      */
     if (\Lobby\FS::exists("/update/sqlExecute.sql")) {
         \Lobby::log("Upgrading Lobby Database");
         $sqlCode = \Lobby\FS::get("/update/sqlExecute.sql");
         $sql = \Lobby\DB::prepare($sqlCode);
         if (!$sql->execute()) {
             ser("Error", "Database Update Couldn't be made. <a href='update.php'>Try again</a>");
         } else {
             \Lobby\FS::remove("/update/sqlExecute.sql");
         }
         \Lobby::log("Updated Lobby Database");
     }
     $oldVer = getOption("lobby_version");
     saveOption("lobby_version", $latest_version);
     saveOption("lobby_version_release", getOption("lobby_latest_version_release"));
     \Lobby\FS::remove("/upgrade.lobby");
     \Lobby::log("Lobby is successfully Updated.");
 }
Exemplo n.º 14
0
if (isset($_GET['id'])) {
    $data = $this->getPages($name, $_GET['id']);
    $valid = $data['title'] == "" ? false : true;
}
if (isset($_POST['submit'])) {
    $pname = $valid === true ? $_GET['id'] : $_POST['name'];
    $title = $_POST['title'];
    $body = $_POST['content'];
    $slug = $_POST['slug'];
    if ($pname == "" || $body == "" || $title == "" || $slug == "") {
        \Lobby::ser("Fill Up", "Please fill up all the fields");
    } else {
        if (!ctype_alnum(str_replace(" ", "", $pname))) {
            \Lobby::ser("Invalid Name", "The page name should only contain alphanumeric characters");
        } else {
            $layout = \Lobby\FS::get("/src/Data/themes/{$site['theme']}/layout.html");
            $gSite = new sigeSite($site);
            $page = $gSite->page($slug, array("{{page-title}}" => $title, "{{page-content}}" => $body));
            if ($page === true) {
                $this->addPage($name, $pname, array("title" => $title, "slug" => $slug, "body" => $body));
                \Lobby::sss("Page Updated", "The page was successfully " . ($valid ? "updated" : "created"));
            } else {
                \Lobby::ser("Error", "Some error was occured while creating the page. Try again.");
            }
            $data = $this->getPages($name, $pname);
        }
    }
}
?>
  <form method="POST" action="<?php 
echo \Lobby::u();