Esempio n. 1
0
 public function connect()
 {
     if (!self::$connection) {
         try {
             $this->Mongo = new MongoClient();
             if (!$this->Mongo) {
                 throw new Exception(e("Connection Error"), 1);
             }
             $this->Mongo->selectDb(DB_NOSQL_DATABASE);
         } catch (Exception $e) {
             getException($e);
         }
     }
 }
Esempio n. 2
0
 /**
  * Loads a view
  *
  * @param string $name
  * @param string $application = NULL
  * @param string $vars        = NULL
  * @return string value / void
  */
 public function view($name, $vars = NULL, $application = NULL, $return = FALSE)
 {
     if (is_null($application)) {
         $application = whichApplication();
     }
     if (!is_null($application)) {
         $view = "www/applications/{$application}/views/{$name}.php";
         if (is_array($vars)) {
             $key = array_keys($vars);
             $size = sizeof($key);
             for ($i = 0; $i < $size; $i++) {
                 ${$key}[$i] = $vars[$key[$i]];
             }
         } elseif ($vars) {
             return $view;
         }
         if (file_exists($view)) {
             include $view;
             if ($return) {
                 $output = ob_get_contents();
                 ob_end_clean();
                 return $output;
             }
         } else {
             getException("Error 404: {$view} view not found");
         }
     } else {
         return FALSE;
     }
 }
Esempio n. 3
0
 public function load($template, $direct = false)
 {
     if (is_array($this->vars)) {
         $key = array_keys($this->vars);
         $size = sizeof($key);
         for ($i = 0; $i < $size; $i++) {
             ${$key}[$i] = $this->vars[$key[$i]];
         }
     }
     if ($direct) {
         if (is_array($template)) {
             $count = count($template);
             if ($count === 1) {
                 include $template[0];
             } elseif ($count === 2) {
                 include $template[0];
                 include $template[1];
             } elseif ($count === 3) {
                 include $template[0];
                 include $template[1];
                 include $template[2];
             } else {
                 include $template[0];
                 include $template[1];
                 include $template[2];
                 include $template[3];
             }
         } else {
             if (!file_exists($template)) {
                 getException("Error 404: Theme Not Found: " . $template);
             }
             include $template;
         }
     } else {
         $_name = $template;
         $template = "www/lib/themes/{$this->theme}/{$_name}.php";
         $minTemplate = "www/lib/themes/{$this->theme}/min/{$_name}.php";
         if (_get("environment") > 2 and file_exists($minTemplate)) {
             $template = $minTemplate;
         }
         if (!file_exists($template)) {
             getException("Error 404: Theme Not Found: " . $template);
         }
         include $template;
     }
 }
Esempio n. 4
0
 /**
  * Select database driver and make connection
  *
  * @return void
  */
 public function connect()
 {
     $this->db = get("db");
     if (!file_exists("www/config/database.php")) {
         getException("You must rename and configure your 'config/database.php'");
     }
     if (!self::$connection) {
         $port = $this->db["dbPort"] === 3306 ? "" : ":" . $this->db["dbPort"];
         if ($this->db["dbPDO"]) {
             self::$connection = TRUE;
             $this->PDO = $this->db["dbPDO"];
             if ($this->db["dbDriver"] === "mysql" or $this->db["dbDriver"] === "mysqli") {
                 try {
                     $this->Database = new PDO("mysql:host=" . $this->db["dbHost"] . $port . ";dbname=" . $this->db["dbName"], $this->db["dbUser"], $this->db["dbPwd"]);
                 } catch (PDOException $e) {
                     getException("Database Error: " . $e->getMessage());
                 }
             } elseif ($this->db["dbDriver"] === "pgsql") {
                 try {
                     $this->Database = new PDO("pgsql:host=" . $this->db["dbHost"] . " port=" . $this->db["dbPort"] . " dbname=" . $this->db["dbName"], $this->db["dbUser"], $this->db["dbPwd"]);
                 } catch (PDOException $e) {
                     getException("Database Error: " . $e->getMessage());
                 }
             } elseif ($this->db["dbDriver"] === "sqlite") {
                 try {
                     $this->Database = new PDO("sqlite:" . $this->db["dbFilename"]);
                 } catch (PDOException $e) {
                     getException("Database Error: " . $e->getMessage());
                 }
             } elseif ($this->db["dbDriver"] === "oracle") {
                 try {
                     $this->Database = new PDO("OCI:dbname=" . $this->db["dbName"] . ";charset=UTF-8", $this->db["dbUser"], $this->db["dbPwd"]);
                 } catch (PDOException $e) {
                     getException("Database Error: " . $e->getMessage());
                 }
             }
         } else {
             if ($this->db["dbDriver"] === "mssql") {
                 $this->Database = $this->driver("MsSQL_Db");
                 self::$connection = $this->Database->connect($this->db);
             } elseif ($this->db["dbDriver"] === "mysql") {
                 $this->Database = $this->driver("MySQL_Db");
                 self::$connection = $this->Database->connect($this->db);
             } elseif ($this->db["dbDriver"] === "mysqli") {
                 $this->Database = $this->driver("MySQLi_Db");
                 self::$connection = $this->Database->connect($this->db);
             } elseif ($this->db["dbDriver"] === "pgsql") {
                 $this->Database = $this->driver("PgSQL_Db");
                 self::$connection = $this->Database->connect($this->db);
             } elseif ($this->db["dbDriver"] === "sqlite") {
                 $this->Database = $this->driver("SQLite_Db");
                 self::$connection = $this->Database->connect($this->db);
             } elseif ($this->db["dbDriver"] === "oracle") {
                 $this->Database = $this->driver("Oracle_Db");
                 self::$connection = $this->Database->connect($this->db);
             }
         }
     }
 }
Esempio n. 5
0
 /**
  * Select database driver and make connection
  *
  * @return void
  */
 public function connect()
 {
     if (!self::$connection) {
         try {
             $this->db = get("db");
             $this->Mongo = new Mongo("mongodb://" . $this->db["dbNoSQLHost"] . ":" . $this->db["dbNoSQLPort"]);
             if (!$this->Mongo) {
                 throw new Exception(e("Connection Error"), 1);
             }
             if ($this->db["dbNoSQLUser"] !== "" and $this->db["dbNoSQLPwd"] !== "") {
                 $this->Mongo->selectDb($this->db["dbNoSQLDatabase"])->authenticate($this->db["dbNoSQLUser"], $this->db["dbNoSQLPwd"]);
             } else {
                 $this->Mongo->selectDb($this->db["dbNoSQLDatabase"]);
             }
         } catch (Exception $e) {
             getException($e);
         }
     }
 }
Esempio n. 6
0
File: db.php Progetto: no2key/MuuCMS
 /**
  * Select database driver and make connection
  *
  * @return void
  */
 public function connect()
 {
     $this->db = get("db");
     if (!file_exists("www/config/database.php")) {
         getException("You must rename and configure your 'config/database.php'");
     }
     if (!self::$connection) {
         if ($this->db["dbController"] === "mysql" or $this->db["dbController"] === "mysqli") {
             try {
                 $this->Database = new PDO("mysql:host=" . $this->db["dbHost"] . ";dbname=" . $this->db["dbName"], $this->db["dbUser"], $this->db["dbPwd"]);
             } catch (PDOException $e) {
                 getException("Database Error: " . $e->getMessage());
             }
         } elseif ($this->db["dbController"] === "pgsql") {
             try {
                 $this->Database = new PDO("pgsql:host=" . $this->db["dbHost"] . ";dbname=" . $this->db["dbName"], $this->db["dbUser"], $this->db["dbPwd"]);
             } catch (PDOException $e) {
                 getException("Database Error: " . $e->getMessage());
             }
         } elseif ($this->db["dbController"] === "sqlite") {
             try {
                 $this->Database = new PDO("sqlite:" . $this->db["dbFilename"]);
             } catch (PDOException $e) {
                 getException("Database Error: " . $e->getMessage());
             }
         } elseif ($this->db["dbController"] === "oracle") {
             try {
                 $this->Database = new PDO("OCI:dbname=" . $this->db["dbName"] . ";charset=UTF-8", $this->db["dbUser"], $this->db["dbPwd"]);
             } catch (PDOException $e) {
                 getException("Database Error: " . $e->getMessage());
             }
         }
     }
 }
Esempio n. 7
0
 /**
  * Load template
  *
  * @return void
  */
 public function load($template, $direct = FALSE)
 {
     if (is_array($this->vars)) {
         $key = array_keys($this->vars);
         $size = sizeof($key);
         for ($i = 0; $i < $size; $i++) {
             ${$key}[$i] = $this->vars[$key[$i]];
         }
     }
     if ($direct) {
         if (is_array($template)) {
             for ($i = 0; $i <= count($template) - 1; $i++) {
                 include $template[$i];
             }
         } else {
             if (!file_exists($template)) {
                 getException("Error 404: Theme Not Found: " . $template);
             }
             include $template;
         }
     } else {
         $template = "www/lib/themes/{$this->theme}/{$template}.php";
         if (!file_exists($template)) {
             getException("Error 404: Theme Not Found: " . $template);
         }
         include $template;
     }
 }
Esempio n. 8
0
/**
 * execute
 *
 * Executes the run() method which is inside all application controllers 
 * 
 * @return void
 * @link		
 */
function execute()
{
    global $Load, $ZP;
    $applicationController = FALSE;
    $match = FALSE;
    $special = FALSE;
    $params = array();
    if (file_exists("www/config/routes.php")) {
        include "www/config/routes.php";
        if (is_array($routes)) {
            $application = segment(0, isLang());
            foreach ($routes as $route) {
                $pattern = $route["pattern"];
                $match = preg_match($pattern, $application);
                if ($match) {
                    $application = $route["application"];
                    $applicationController = $route["controller"];
                    $method = $route["method"];
                    $params = $route["params"];
                    break;
                }
            }
        }
    }
    if (!$match) {
        if (!segment(0)) {
            $application = get("defaultApplication");
        } elseif (segment(0) and !segment(1)) {
            $application = isLang() ? get("defaultApplication") : segment(0);
        } else {
            $application = segment(0, isLang());
            $applicationController = segment(1, isLang());
            if (isController($applicationController, $application)) {
                $Controller = getController($applicationController, $application);
                $controllerFile = getController($applicationController, $application, TRUE);
                $method = segment(2, isLang());
                if (!isMethod($method, $Controller)) {
                    if (isMethod("index", $Controller)) {
                        $method = "index";
                        $special = TRUE;
                    } else {
                        getException("Method \"{$method}\" doesn't exists");
                    }
                }
            } else {
                $applicationController = FALSE;
                $Controller = getController(NULL, $application);
                $controllerFile = getController(NULL, $application, TRUE);
                $method = segment(1, isLang());
                if (!isMethod($method, $Controller)) {
                    if (isMethod("index", $Controller)) {
                        $method = "index";
                        $special = TRUE;
                    } else {
                        getException("Method \"{$method}\" doesn't exists");
                    }
                }
            }
            if ($applicationController) {
                if (segments() >= 3) {
                    $j = isLang() ? 4 : 3;
                    $j = $special ? $j - 1 : $j;
                    for ($i = 0; $i < segments(); $i++) {
                        if (segment($j) or segment($j) === 0) {
                            $params[$i] = segment($j);
                            $j++;
                        }
                    }
                }
            } else {
                $count = $special ? 1 : 2;
                if (segments() > $count) {
                    $j = isLang() ? 3 : 2;
                    $j = $special ? $j - 1 : $j;
                    for ($i = 0; $i < segments(); $i++) {
                        if (segment($j) or segment($j) === 0) {
                            $params[$i] = segment($j);
                            $j++;
                        }
                    }
                }
            }
        }
    }
    if (get("webSituation") !== "Active" and !SESSION("ZanUserID") and $application !== "cpanel") {
        die(get("webMessage"));
    }
    $Load->app($application);
    $controllerFile = $applicationController ? getController($applicationController, $application, TRUE) : getController(NULL, $application, TRUE);
    if (!$controllerFile) {
        getException("The application \"{$application}\" doesn't exists");
    }
    $Controller = isset($Controller) ? $Controller : getController(NULL, $application);
    if (isset($method) and count($params) > 0) {
        if (isMethod($method, $Controller)) {
            try {
                $Reflection = new ReflectionMethod($Controller, $method);
                if (!$Reflection->isPublic()) {
                    throw new RuntimeException("The called method is not public.", 100);
                }
                call_user_func_array(array($Controller, $method), $params);
            } catch (RuntimeException $e) {
                getException($e);
            }
        } else {
            if (isController($controllerFile, TRUE)) {
                if (isset($method) and count($params) > 0) {
                    if (isMethod($method, $Controller)) {
                        try {
                            $Reflection = new ReflectionMethod($Controller, $method);
                            if (!$Reflection->isPublic()) {
                                throw new RuntimeException("The called method is not public.", 100);
                            }
                            call_user_func_array(array($Controller, $method), $params);
                        } catch (RuntimeException $e) {
                            getException($e);
                        }
                    }
                }
            } else {
                if (method_exists($Controller, "index")) {
                    try {
                        $reflection = new ReflectionMethod($Controller, "index");
                        if (!$reflection->isPublic()) {
                            throw new RuntimeException("The called method is not public.", 100);
                        } elseif ($Reflection->getNumberOfRequiredParameters() > 0 and count($params) === 0) {
                            throw new RuntimeException("The called method need required parameters (" . getParameters($Reflection->getParameters()) . ").", 200);
                        }
                        call_user_func_array(array($Controller, "index"), $params);
                    } catch (RuntimeException $e) {
                        getException($e);
                    }
                } else {
                    getException("Method index doesn't exists");
                }
            }
        }
    } elseif (isset($method)) {
        if (isMethod($method, $Controller)) {
            try {
                $Reflection = new ReflectionMethod($Controller, $method);
                if (!$Reflection->isPublic()) {
                    throw new RuntimeException("The called method is not public.", 100);
                } elseif ($Reflection->getNumberOfRequiredParameters() > 0 and count($params) === 0) {
                    throw new RuntimeException("The called method need required parameters (" . getParameters($Reflection->getParameters()) . ").", 200);
                }
                $Controller->{$method}();
            } catch (RuntimeException $e) {
                getException($e);
            }
        } else {
            if (isMethod("index", $Controller)) {
                call_user_func_array(array($Controller, "index"), $params);
            } else {
                getException("Method \"index\" doesn't exists");
            }
        }
    } else {
        if (isMethod("index", $Controller)) {
            try {
                $Reflection = new ReflectionMethod($Controller, "index");
                if (!$Reflection->isPublic()) {
                    throw new RuntimeException("The called method is not public.", 100);
                } elseif ($Reflection->getNumberOfRequiredParameters() > 0 and count($params) === 0) {
                    throw new RuntimeException("The called method need required parameters (" . getParameters($Reflection->getParameters()) . ").", 200);
                }
                call_user_func_array(array($Controller, "index"), $params);
            } catch (RuntimeException $e) {
                getException($e);
            }
        } else {
            getException("Method \"index\" doesn't exists");
        }
    }
}
Esempio n. 9
0
 public function view($name, $vars = null, $application = null, $return = false)
 {
     if (is_null($application)) {
         $application = whichApplication();
     }
     if (!is_null($application) and is_string($application) and is_string($name)) {
         $theme = _get("webTheme");
         if (file_exists("www/lib/themes/{$theme}/views/{$application}/{$name}.php")) {
             $view = "www/lib/themes/{$theme}/views/{$application}/{$name}.php";
             $minView = "www/lib/themes/{$theme}/views/{$application}/min/{$name}.php";
         } else {
             $view = "www/applications/{$application}/views/{$name}.php";
             $minView = "www/applications/{$application}/views/min/{$name}.php";
         }
         if (_get("environment") > 2 and file_exists($minView)) {
             $view = $minView;
         }
         if (is_array($vars)) {
             $key = array_keys($vars);
             $size = sizeof($key);
             for ($i = 0; $i < $size; $i++) {
                 ${$key}[$i] = $vars[$key[$i]];
             }
         } elseif ($vars) {
             return $view;
         }
         if (file_exists($view)) {
             ob_start();
             include $view;
             if ($return) {
                 $output = ob_get_contents();
                 ob_clean();
                 return $output;
             }
         } else {
             getException("Error 404: {$view} view not found");
         }
     } else {
         return false;
     }
 }
Esempio n. 10
0
<pre><?php 
echo getException();
?>
</pre>
Esempio n. 11
0
 public function connect()
 {
     if (!file_exists("www/config/database.php")) {
         getException("You must rename and configure your 'config/database.php'");
     }
     if (!self::$connection) {
         $port = DB_PORT === 3306 ? "" : ":" . DB_PORT;
         if (DB_PDO) {
             self::$connection = true;
             $this->PDO = DB_PDO;
             if (DB_DRIVER === "mysqli" or DB_DRIVER === "mysql") {
                 try {
                     $this->Database = new PDO("mysql:host=" . DB_HOST . $port . ";dbname=" . DB_DATABASE, DB_USER, DB_PWD);
                 } catch (PDOException $e) {
                     getException("Database Error: " . $e->getMessage());
                 }
             } elseif (DB_DRIVER === "pgsql") {
                 try {
                     $this->Database = new PDO("pgsql:host=" . DB_HOST . $port . ";dbname=" . DB_DATABASE, DB_USER, DB_PWD);
                 } catch (PDOException $e) {
                     getException("Database Error: " . $e->getMessage());
                 }
             } elseif (DB_DRIVER === "sqlite") {
                 try {
                     $this->Database = new PDO("sqlite:" . DB_SQLITE_FILENAME);
                 } catch (PDOException $e) {
                     getException("Database Error: " . $e->getMessage());
                 }
             } elseif (DB_DRIVER === "oracle") {
                 try {
                     $this->Database = new PDO("OCI:dbname=" . DB_DATABASE . ";charset=UTF-8", DB_USER, DB_PWD);
                 } catch (PDOException $e) {
                     getException("Database Error: " . $e->getMessage());
                 }
             }
         } else {
             if (DB_DRIVER === "mysqli") {
                 $this->Database = $this->driver("MySQLi_Db");
                 self::$connection = $this->Database->connect();
             } elseif (DB_DRIVER === "mysql") {
                 $this->Database = $this->driver("MySQL_Db");
                 self::$connection = $this->Database->connect();
             } elseif (DB_DRIVER === "pgsql") {
                 $this->Database = $this->driver("PgSQL_Db");
                 self::$connection = $this->Database->connect();
             } elseif (DB_DRIVER === "sqlite") {
                 $this->Database = $this->driver("SQLite_Db");
                 self::$connection = $this->Database->connect();
             } elseif (DB_DRIVER === "oracle") {
                 $this->Database = $this->driver("Oracle_Db");
                 self::$connection = $this->Database->connect();
             } elseif (DB_DRIVER === "mssql") {
                 $this->Database = $this->driver("MsSQL_Db");
                 self::$connection = $this->Database->connect();
             }
         }
     }
 }