/** * Database constructor. */ public function __construct() { /** @var PDO $statsdb */ $this->_db = new \PDO(Mvc::getConfig()->getData('database')); // Set errormode to exceptions $this->_db->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION); }
public final function runAjax() { $action = Mvc::param('action'); $action = explode('-', $action, 2); $action = $action[1]; $nonce = Mvc::param('nonce'); if (method_exists($this, $action)) { if (strstr($action, 'admin') && !wp_verify_nonce($nonce, $action)) { self::send(array('error' => true, 'message' => 'You are not authorized.')); } $this->{$action}(); } else { self::send(array('error' => true, 'message' => 'This action does not exist.')); } }
public function on_activation() { if (current_user_can('administrator')) { $data = get_plugin_data(Mvc::$pluginFile); Mvc::$pluginVersion = $data['Version']; Mvc::log($data); $version = Mvc::option('version', ''); if ($version != Mvc::$pluginVersion) { require_once ABSPATH . 'wp-admin/includes/upgrade.php'; $this->controller->on_upgrade($version, Mvc::$pluginVersion); Mvc::option('version', Mvc::$pluginVersion); } $this->controller->on_activation(); } }
public function __construct($type = NULL) { switch ($type) { case NULL: if (!Session::exists('user_id')) { Mvc::init('LoginModel', 'login', $args); die; } break; case 'ajax': if (!Session::exists('user_id')) { $data['error'] = 'Please Login to Continue'; header('Content-Type: application/json'); echo json_encode($data); die; } break; default: break; } }
} /* * 创建应用目录 */ private static function createAppDir() { $array = array(COMMON_PATH, COMMON_CONFIG_PATH, COMMON_LIB_PATH, COMMON_MODEL_PATH, EXTENDS_PATH, ORG_PATH, TOOL_PATH, APP_PATH, APP_CONFIG_PATH, APP_CONTROLLER_PATH, APP_MODEL_PATH, APP_VIEW_PATH, APP_TPL_PATH, APP_TPL_PATH, APP_PUBLIC_PATH, TEMP_PATH, LOG_PATH, COMPILE_PATH, CACHE_PATH); foreach ($array as $v) { is_dir($v) || mkdir($v, 0777, true); } $tpl = array(0 => array('source' => TPL_PATH . '/message.tpl', 'dest' => APP_TPL_PATH . '/message.tpl'), 1 => array('source' => TPL_PATH . '/trace.tpl', 'dest' => APP_TPL_PATH . '/trace.tpl')); foreach ($tpl as $k => $v) { is_file($v['dest']) || copy($v['source'], $v['dest']); } /* $message_tpl = TPL_PATH.'/message.tpl'; $app_message_tpl = APP_TPL_PATH.'/message.tpl'; is_file($app_message_tpl) || copy($message_tpl,$app_message_tpl);*/ } /* * 载入框架运行所需的文件 */ private static function importFile() { $files = array(CORE_PATH . '/View.class.php', TPLENGINE_PATH . '/Smarty/Smarty.class.php', CORE_PATH . '/Controller.class.php', CORE_PATH . '/Application.class.php', CORE_PATH . '/Log.class.php', FUNCTION_PATH . '/function.php'); foreach ($files as $v) { require_once $v; } } } Mvc::run();
<?php switch ($action) { case "index": Mvc::View(basename(__FILE__, ".php")); break; case "UserList": Mvc::View(basename(__FILE__, ".php"), "list"); break; case "GetIdByLogin": $log = $_REQUEST["login"]; $r = $db->QueryOne("select id from Users where Login='******' "); die($r["id"]); break; case "UserData": $db->Query("select id, Login, FirstName, LastName,Permission, Mail from Users order by Login"); while ($buf = $db->Fetch()) { $data[] = array("id" => $buf["id"], "Login" => $buf["Login"], "FirstName" => $buf["FirstName"], "LastName" => $buf["LastName"], "Permission" => $buf["Permission"], "Mail" => $buf["Mail"]); } $db->StopFetch(); if ($data == null) { die("{\"data\": []}"); } die("{\"data\": " . json_encode($data) . "}"); break; // ACTION ========================= // ACTION ========================= case "Create": $login = $_REQUEST["login"]; $pas = $_REQUEST["password"]; $fir = $_REQUEST["firstname"];
public static function createPages($totalCount, $currPage, $perPage, $baseUrl) { ob_start(); $numPages = (int) ($totalCount / $perPage) + 1; echo ' | '; for ($i = 1; $i <= $numPages; $i++) { if ($i == $currPage) { echo $i; } else { ?> <a href="<?php echo Mvc::paramReplace('&pg', $i, $baseUrl); ?> "><?php echo $i; ?> </a><?php } echo ' | '; } return ob_get_clean(); }
<?php switch ($action) { // ACTION ========================= case "index": Mvc::View(basename(__FILE__, ".php")); break; default: echo "Action not found"; break; }
public static function paramReplace($name, $value, $url = '') { $regex = "/({$name}=[^&\\?\\/]+)/"; Mvc::log($regex); $url = $url ? $url : $_SERVER['REQUEST_URI']; if ($value === '') { return preg_replace($regex, '', $url); } else { if (preg_match($regex, $url) == 1) { return preg_replace($regex, $name . '=' . $value, $url); } else { return $url . "{$name}={$value}"; } } }
public function save() { Mvc::log('saving', $this->key, $this->value); return Mvc::option($this->key, $this->value); }