Пример #1
0
    /**
     * Get content
     */
    public function getContent()
    {
        if (get("updatedatabase")) {
            RDR_DBUpdate::run();
            redirect(l("RDR_Home"), 302);
        }
        headline(t("dbupdate.1"));
        ?>
        <div class="indent">
            <?php 
        echo s(t("dbupdate.2"), true);
        ?>
<br/><br/>
            <input type="button" class="btn" value="<?php 
        echo t("dbupdate.3");
        ?>
" onclick="window.location.href = '<?php 
        echo url()->getModifiedUri(false);
        ?>
?updatedatabase=1'"/>
        </div>
        <?php 
    }
Пример #2
0
 /**
  * Load the View
  */
 public function onLoad()
 {
     if (req()->isAjax() && get("code") == self::getValidHash()) {
         $data = null;
         switch (get("action")) {
             case "update-check":
                 # fetching branches from GIT
                 $data = array("error" => t("update.4"));
                 $branches = self::getGitJSON("https://api.github.com/repos/brainfoolong/nreeda/branches");
                 if ($branches) {
                     $newest = null;
                     foreach ($branches as $branch) {
                         if ($branch["name"] == "master") {
                             continue;
                         }
                         if (!$newest || version_compare($branch["name"], $newest, ">")) {
                             $newest = $branch["name"];
                         }
                     }
                     $data = array("version" => $newest, "update" => version_compare($newest, RDR_VERSION, ">"));
                     RDR_Setting::set("latestversion", $newest);
                 }
                 break;
             case "start":
                 if (RDR_Cron::isRunning()) {
                     $data = array("message" => t("update.1"), "event" => "error");
                 } else {
                     RDR_Maintenance::enableMaintenanceMode();
                     $data = array("message" => sprintf(nl2br(t("update.2"), true), url()->getByAlias("root", l("RDR_Maintenance")) . '?disable-maintenance=' . RDR_Maintenance::getValidHash(), 'RDR::$maintenanceMode = true'), "event" => "success", "next" => "check");
                 }
                 break;
             case "check":
                 try {
                     # checking all files and directories for write access
                     $files = CHOQ_FileManager::getFiles(CHOQ_ROOT_DIRECTORY, true, true);
                     $count = 0;
                     $files[] = CHOQ_ROOT_DIRECTORY;
                     foreach ($files as $file) {
                         if (substr($file, 0, 1) == ".") {
                             continue;
                         }
                         if (!is_writable($file)) {
                             $count++;
                         }
                     }
                     if ($count) {
                         error(sprintf(t("update.3"), $count));
                     }
                     $version = RDR_Setting::get("latestversion")->value;
                     $data = array("message" => sprintf(t("update.5"), $version), "event" => "success", "next" => "prepare", "params" => array("version" => $version));
                 } catch (Exception $e) {
                     $data = array("message" => sprintf(t("update.7"), $e->getMessage()), "event" => "error");
                 }
                 break;
             case "prepare":
                 try {
                     # downloading zip file from GIT
                     $url = "https://github.com/brainfoolong/nreeda/archive/" . get("version") . ".zip";
                     $data = RDR_FileContents::get($url);
                     if ($data === false) {
                         return;
                     }
                     $tmpZip = CHOQ_ACTIVE_MODULE_DIRECTORY . "/tmp/update.zip";
                     file_put_contents($tmpZip, $data);
                     $updateDir = CHOQ_ACTIVE_MODULE_DIRECTORY . "/tmp/update";
                     if (!is_dir($updateDir)) {
                         mkdir($updateDir);
                     }
                     # removing all old files
                     $files = CHOQ_FileManager::getFiles($updateDir, true, true);
                     foreach ($files as $file) {
                         if (!is_dir($file)) {
                             unlink($file);
                         }
                     }
                     foreach ($files as $file) {
                         if (is_dir($file)) {
                             rmdir($file);
                         }
                     }
                     # extract zip file to tmp folder
                     $zip = new ZipArchive();
                     $zip->open($tmpZip);
                     $zip->extractTo($updateDir);
                     $zip->close();
                     $folder = $updateDir . "/nreeda-" . get("version");
                     $data = array("message" => t("update.9"), "event" => "success", "next" => "update", "params" => array("updatefolder" => $folder, "rootfolder" => CHOQ_ROOT_DIRECTORY, "updateurl" => url()->getByAlias("base", "modules/RDR/tmp/update/nreeda-" . get("version") . "/update.php")));
                 } catch (Exception $e) {
                     $data = array("message" => sprintf(t("update.7"), $e->getMessage()), "event" => "error");
                 }
                 break;
             case "db":
                 try {
                     RDR_DBUpdate::run();
                     $data = array("message" => t("update.10"), "event" => "success", "next" => "cleanup");
                 } catch (Exception $e) {
                     $data = array("message" => sprintf(t("update.7"), $e->getMessage()), "event" => "error");
                 }
                 break;
             case "cleanup":
                 try {
                     # deleting all update files
                     $updateDir = CHOQ_ACTIVE_MODULE_DIRECTORY . "/tmp/update";
                     if (is_dir($updateDir)) {
                         $files = CHOQ_FileManager::getFiles($updateDir, true, true);
                         foreach ($files as $file) {
                             if (!is_dir($file)) {
                                 unlink($file);
                             }
                         }
                         foreach ($files as $file) {
                             if (is_dir($file)) {
                                 rmdir($file);
                             }
                         }
                     }
                     if (is_dir($updateDir)) {
                         rmdir($updateDir);
                     }
                     $updateFile = CHOQ_ROOT_DIRECTORY . "/update.php";
                     if (file_exists($updateFile)) {
                         unlink($updateFile);
                     }
                     $data = array("message" => t("update.11"), "event" => "success");
                 } catch (Exception $e) {
                     $data = array("message" => sprintf(t("update.7"), $e->getMessage()), "event" => "error");
                 }
                 break;
             case "disable":
                 RDR_Maintenance::disableMaintenanceMode();
                 break;
         }
         echo json_encode($data);
         return;
     }
     needRole(RDR_User::ROLE_ADMIN, true);
     view("RDR_BasicFrame", array("view" => $this));
 }
Пример #3
0
    /**
     * Get content
     */
    public function getContent()
    {
        $errors = $checkErrors = array();
        $writeableFolders = array(CHOQ_ACTIVE_MODULE_DIRECTORY, CHOQ_ACTIVE_MODULE_DIRECTORY . "/public/static", CHOQ_ACTIVE_MODULE_DIRECTORY . "/public/img/favicons", CHOQ_ACTIVE_MODULE_DIRECTORY . "/tmp");
        foreach ($writeableFolders as $folder) {
            if (!is_dir($folder)) {
                $errors[] = sprintf(t("install.folder.notexist"), $folder);
                break;
            }
            if (!is_writable($folder)) {
                $errors[] = sprintf(t("install.folder.writeable"), $folder);
                break;
            }
        }
        if (!ini_get("allow_url_fopen")) {
            $errors[] = sprintf(t("install.php.feature"), "allow_url_fopen");
        }
        if (!function_exists("fsockopen")) {
            $errors[] = sprintf(t("install.php.feature"), "fsockopen/sockets");
        }
        if (!function_exists("simplexml_load_file")) {
            $errors[] = sprintf(t("install.php.feature"), "SimpleXML");
        }
        if (!CHOQ_DB_Mysql::isAvailable()) {
            $errors[] = sprintf(t("install.php.feature"), "MySQLi");
        }
        if (post("install")) {
            try {
                $connString = "mysql://" . post("mysql-user") . ":" . post("mysql-pass") . "@" . post("mysql-host") . "/" . post("mysql-db");
                CHOQ_DB::add($connString, "test");
                db("test")->query("DROP TABLE IF EXISTS " . db("test")->quote("RDR_test"));
                db("test")->query("CREATE TABLE " . db("test")->quote("RDR_test") . " (" . db("test")->quote("id") . " INT NOT NULL)");
                db("test")->query("DROP TABLE IF EXISTS " . db("test")->quote("RDR_test"));
                $fileData = "<?php\nif(!defined(\"CHOQ\")) die();\n/**\n * Local Configuration\n**/\n\n";
                $fileData .= 'CHOQ_DB::add(\'' . $connString . '\');' . "\n";
                $fileData .= 'v("hash.salt", "' . uniqid(NULL, true) . sha1(microtime() . uniqid(NULL, true)) . '");' . "\n";
                $tmpfile = CHOQ_ACTIVE_MODULE_DIRECTORY . "/tmp/_RDR.local.tmp.php";
                file_put_contents($tmpfile, $fileData);
                include $tmpfile;
                $generator = CHOQ_DB_Generator::create(db());
                $tables = $generator->getExistingTables();
                foreach ($tables as $table) {
                    if ($table == "_choqled_metadata" || substr(strtolower($table), 0, 3) == "rdr_") {
                        db()->query("DROP TABLE " . db()->quote($table));
                    }
                }
                RDR_DBUpdate::run();
                $user = new RDR_User(db());
                $user->username = post("admin-user");
                $user->setPassword(post("admin-pass"));
                $user->role = RDR_User::ROLE_ADMIN;
                $user->store();
                rename($tmpfile, CHOQ_ACTIVE_MODULE_DIRECTORY . "/_RDR.local.php");
                redirect(url()->getByAlias("base"));
            } catch (Exception $e) {
                $checkErrors[] = $e->getMessage();
            }
        }
        ?>
        <div class="center">
            <img src="<?php 
        echo url()->getByAlias("public", "img/logo-1.png");
        ?>
" alt=""/>
        </div>
        <?php 
        if (!$errors) {
            $this->showErrors($checkErrors);
            $form = $this->getForm();
            $formTable = new Form_Table($form);
            $formTable->addSubmit(t("install.finish"));
            echo $formTable->getHtml();
            echo "<div class='center'><br/>" . t("install.warn") . "</div>";
        } else {
            $this->showErrors($errors);
        }
    }
Пример #4
0
    /**
     * Load the View
     */
    public function onLoad()
    {
        # load the view
        $view = $this->getParam("view");
        if (RDR::$isInstalled) {
            if (RDR_DBUpdate::updateRequired()) {
                RDR_User::$user = false;
                $view = new RDR_DBUpdate();
            }
        }
        ob_start();
        $view->getContent();
        $content = ob_get_contents();
        ob_end_clean();
        # some html preparations
        $bodyClasses = array("page-" . slugify(strtolower(get_class($view))));
        $jsVars = array();
        $dir = CHOQ_ACTIVE_MODULE_DIRECTORY . "/view";
        $files = array("css" => array(CHOQ_ROOT_DIRECTORY . "/modules/Form/view/_css/form.css", "{$dir}/_css/default.css"), "js" => array("{$dir}/_js/jquery/jquery.js", "{$dir}/_js/default.js", CHOQ_ROOT_DIRECTORY . "/modules/Form/view/_js/form.js"));
        $name = "default";
        html()->addFileGroupToHead($name, "css", CHOQ_ACTIVE_MODULE_DIRECTORY . "/public/static", "static", $files["css"]);
        html()->addFileGroupToHead($name, "js", CHOQ_ACTIVE_MODULE_DIRECTORY . "/public/static", "static", $files["js"]);
        $jsVars["message"] = v("message");
        if (RDR::$isInstalled) {
            $jsVars["proxyUrl"] = l("RDR_Proxy");
            $jsVars["apiUrl"] = l("RDR_API");
        }
        $userData = array();
        if (user()) {
            $jsVars["ajaxUrl"] = l("RDR_Ajax");
            user()->updateNewsCache();
            $userData = user()->getAjaxData();
        }
        if (isMobile()) {
            $dir = CHOQ_ACTIVE_MODULE_DIRECTORY . "/view";
            $files = array("css" => array("{$dir}/_css/mobile.css"), "js" => array());
            $name = "mobile";
            html()->addFileGroupToHead($name, "css", CHOQ_ACTIVE_MODULE_DIRECTORY . "/public/static", "static", $files["css"]);
            html()->addFileGroupToHead($name, "js", CHOQ_ACTIVE_MODULE_DIRECTORY . "/public/static", "static", $files["js"]);
            $bodyClasses[] = "mobile";
        }
        ?>
<!DOCTYPE html>
        <?php 
        html()->getOpeningHTMLTag();
        ?>
        <head>
        <?php 
        html()->getHeadTag();
        ?>
        <link rel="shortcut icon" href="<?php 
        echo url()->getByAlias("public", "favicon.ico");
        ?>
" type="image/icon" />
        <meta name="generator" content="Choqled PHP Framework" />
        <base href="<?php 
        echo url()->getByAlias("base");
        ?>
"/>
        <script type="text/javascript">
        Global.vars = <?php 
        echo json_encode($jsVars, JSON_FORCE_OBJECT);
        ?>
;
        </script>
        <!--[if lte IE 8]>
        <script type="text/javascript">
        $(document).ready(function(){
            Global.message("<?php 
        echo t("iewarning");
        ?>
")
        });
        </script>
        <![endif]-->
        </head>
        <body class="<?php 
        echo implode(" ", $bodyClasses);
        ?>
">
            <div id="top-message"></div>
            <div class="container a">
                <?php 
        view("RDR_Sidebar", array("content" => 1));
        ?>
            </div><div class="container b">
                <div class="content" id="content">
                    <div class="padd">
                        <?php 
        view("RDR_Sidebar", array("icons" => 1));
        ?>
                        <?php 
        echo $content;
        ?>
                    </div>
                </div>
                <div class="padd" id="content"></div>
            </div><div class="container c"></div>
            <script type="text/javascript">Global.init(<?php 
        echo json_encode($userData);
        ?>
);</script>
        </body>
        </html>
        <?php 
    }