_admin = MUser::userInSession(); if (!$this->_admin) { //if user is loged in? $server = MServer::serverWithIndex(xi("host")); //filter server plugins if (class_exists("RFilter")) { RFilter::apply("SERVER_FILTER", $server); } //if auth is disabled if ($server && !$server->mongoAuth() && !$server->controlAuth()) { MUser::login("rockmongo_memo", "rockmongo_memo", xi("host"), "admin", 10800); $this->_admin = MUser::userInSession(); } else { $this->redirect("login.index", array( "host" => xi("host"))); } } if (!$this->_admin->validate()) { $this->redirect("login.index", array( "host" => $this->_admin->hostIndex() )); } $this->_server = MServer::serverWithIndex($this->_admin->hostIndex()); $this->_mongo = $this->_server->mongo(); //log query if (isset($MONGO["features"]["log_query"]) && $MONGO["features"]["log_query"] == "on") { $this->_logQuery = true; } //render header if (!$this->isAjax()) { render_view("header"); } } /** called after action call **/ public function onAfter() { if (!$this->isAjax()) { render_view("footer"); } } /** * handle exception in runtime * * @param Exception $exception exception to handle */ public function exceptionHandler($exception) { $message = $exception->getMessage(); render_view("exception", array( "message" => $message )); render_view("footer"); exit(); } /** * convert variable from string values * * @param MongoDB $mongodb MongoDB instance * @param string $dataType data type * @param string $format string format * @param string $value string value * @param integer $integerValue integer value * @param long $longValue long value * @param string $doubleValue float value * @param string $boolValue boolea value * @param string $mixedValue mixed value (array or object) * @return mixed * @throws Exception */ protected function _convertValue($mongodb, $dataType, $format, $value, $integerValue, $longValue, $doubleValue, $boolValue, $mixedValue) { $realValue = null; switch ($dataType) { case "integer": if (class_exists("MongoInt32")) { $realValue = new MongoInt32($integerValue); } else { $realValue = intval($realValue); } break; case "long": if (class_exists("MongoInt64")) { $realValue = new MongoInt64($longValue); } else { $realValue = $longValue; } break; case "float": case "double": $realValue = doubleval($doubleValue); break; case "string": $realValue = $value; break; case "boolean": $realValue = ($boolValue == "true"); break; case "null": $realValue = NULL; break; case "mixed": $eval = new VarEval($mixedValue, $format, $mongodb); $realValue = $eval->execute(); if ($realValue === false) { throw new Exception("Unable to parse mixed value, just check syntax!"); } break; } return $realValue; } protected function _encodeJson($var) { if (function_exists("json_encode")) { return json_encode($var); } import("classes.Services_JSON"); $service = new Services_JSON(); return $service->encode($var); } /** * Output variable as JSON * * @param mixed $var variable * @param boolean $exit if exit after output */ protected function _outputJson($var, $exit = true) { echo $this->_encodeJson($var); if ($exit) { exit(); } } protected function _decodeJson($var) { import("classes.Services_JSON"); $service = new Services_JSON(SERVICES_JSON_LOOSE_TYPE); $ret = array(); $decode = $service->decode($var); return $decode; } /** * Export var as string then highlight it. * * @param mixed $var variable to be exported * @param string $format data format, array|json * @param boolean $label if add label to field * @return string */ protected function _highlight($var, $format = "array", $label = false) { import("classes.VarExportor"); $exportor = new VarExportor($this->_mongo->selectDB("admin"), $var); $varString = null; $highlight = true; switch ($this->_server->docsRender()) { case "default": $varString = $exportor->export($format, $label); break; case "plain": $varString = $exportor->export($format, false); $label = false; $highlight = false; break; default: $varString = $exportor->export($format, $label); break; } $string = null; if ($highlight) { if ($format == "array") { $string = highlight_string("<?php ', "/") . "/", '', $string, 1); } else { $string = json_format_html($varString); } } else { $string = "