public function __construct() { //DB $this->_app = \Frame\Application::getInstance(); $this->_session = $this->_app->getSession(); $this->_config = $this->_app->getConfig(); $this->_view = new \Frame\View(); $this->_db = $this->_app->getDatabase(); }
public static function isLogged($type = 1) { $session = \Frame\Application::getInstance()->getSession(); if ($session->is_logged && $session->user_info['type'] >= $type) { return true; } return false; }
public static function getServersInfo() { $db = \Frame\Application::getInstance()->getDatabase(); $sth = $db->prepare('SELECT players FROM servers WHERE status="1"'); $sth->execute(); $servers = $sth->rowCount(); $players = 0; $info = $sth->fetchAll(\PDO::FETCH_ASSOC); for ($i = 0; $i < $servers; $i++) { $players = $info[$i]['players'] + $players; } $data['players'] = $players; $data['servers'] = $servers; return $data; }
public function getVotes($id) { $sth = $this->db->prepare('SELECT v.player_name,v.date,s.motd FROM votes v LEFT JOIN servers s ON v.server_id = s.server_id WHERE v.server_id=? AND s.user_id = ?'); $user_id = \Frame\Application::getInstance()->getSession()->user_info['user_id']; $sth->execute(array($id, $user_id)); $row = $sth->fetchAll(\PDO::FETCH_ASSOC); if ($sth->rowCount() > 0) { $data['player'] = filter_var_array($row, FILTER_SANITIZE_SPECIAL_CHARS); $data['title'] = 'Гласове за сървър'; $data['subTitle'] = $data['player'][0]['motd']; } else { $data['title'] = 'Гласове за сървър'; $data['subTitle'] = "Няма данни"; $data['messages']['error'][] = 'Няма гласували за сървърът Ви!'; } return $data; }
public function getDefaultMethod() { $method = \Frame\Application::getInstance()->getConfig()->appConfig['default_method']; if ($method) { return $method; } else { return 'index'; } }
public function addServer() { if ($this->validateFields()) { try { $query = new \Classes\MinecraftServerPing($this->ip_address, $this->port); $info = $query->Query(); } catch (\Classes\MinecraftPingException $e) { $this->data['error'][] = 'За да бъде записан,сървърът трябва да е ОНЛАЙН.'; return false; } $sql = 'SELECT server_id FROM servers WHERE ip_address=? AND port=?'; $sth = $this->db->prepare($sql); $sth->execute(array($this->ip_address, $this->port)); if ($sth->rowCount() != 0) { $this->data['error'][] = 'Има вече сървър с такова IP:Port'; return false; } else { if ($this->server_name == null) { $this->server_name = $info['motd']; } $sql = 'INSERT INTO servers (ip_address,port,motd,description,tags,user_id,youtubevid,favicon,website,players,maxplayers,status) VALUES(?,?,?,?,?,?,?,?,?,?,?,?)'; $sth = $this->db->prepare($sql); $user_id = \Frame\Application::getInstance()->getSession()->user_info['user_id']; $sth->execute(array($this->ip_address, $this->port, $this->server_name, $this->description, $this->tags, $user_id, $this->youtubeVideo, $info['favicon'], $this->website, $info['players'], $info['maxplayers'], $info['status'])); $id = $this->db->lastInsertId(); $this->data['message'][] = "Благодарим ви за добавянето на сървъра"; $this->data['message'][] = 'Страница на сървъра: <a href="' . URL . $id . '-' . \Classes\Common::createSlug($this->server_name) . '">ТУК</a>'; } } else { return false; } }
public function vote($id) { if (!$id || !is_numeric($id)) { return false; } if ($_POST) { require_once '../OOP-site/app/classes/recaptchalib.php'; $privatekey = \Frame\Application::getInstance()->getConfig()->appConfig['privateKey']; $resp = recaptcha_check_answer($privatekey, $_SERVER["REMOTE_ADDR"], $_POST["recaptcha_challenge_field"], $_POST["recaptcha_response_field"]); if (!$resp->is_valid) { $this->data['error'][] = 'Грешна индетификация за човешко съществуване!'; return false; } else { $player_name = filter_input(INPUT_POST, 'player_name'); $user_id = \Frame\Application::getInstance()->getSession()->user_info['user_id']; if ($player_name == null) { $this->data['error'][] = 'Въведете името с което играете в сървъра!'; return false; } $sql = 'INSERT INTO votes (player_name,user_id,server_id,date) VALUES(?,?,?,NOW())'; $sth = $this->db->prepare($sql); $sth->execute(array($player_name, $user_id, $id)); $this->data['message'][] = 'Благодарим за гласуването! :))'; return true; } } }
<?php if (!empty($this->message['message'])) { foreach ($this->message['message'] as $msg) { echo '<p class="message">' . $msg . '</p>'; } } if (!empty($this->message['error'])) { foreach ($this->message['error'] as $er) { echo '<p class="error">' . $er . '</p>'; } } ?> <div style="" class="vote"> <form method="post"> <?php require_once '..' . DIRECTORY_SEPARATOR . 'OOP-site' . DIRECTORY_SEPARATOR . 'app' . DIRECTORY_SEPARATOR . 'classes' . DIRECTORY_SEPARATOR . 'recaptchalib.php'; $publickey = \Frame\Application::getInstance()->getConfig()->appConfig['publicKey']; echo recaptcha_get_html($publickey); ?> <label>Потребителско име в сървъра:</label><input type="text" name="player_name" placeholder="Player name" /><br> <input class="button" type="submit" value="Гласувай" /> </form> </div>
public function getServerRules($key) { $rules = \Frame\Application::getInstance()->getConfig()->servers; return $rules[$key]; // Syrvyri na stranica }
ini_set('display_errors', 1); error_reporting(E_ALL); $start = microtime(true); define('FRAME_PATH', __DIR__ . '/../../frame'); define('LIB_PATH', __DIR__ . '/../../libs'); define('VENDOR_PATH', __DIR__ . '/../../demo'); require FRAME_PATH . '/Autoloader.class.php'; //or //require(FRAME_PATH . '/PsrAutoloader.class.php'); require FRAME_PATH . '/Application.class.php'; $root_path_setting = array('Frame' => FRAME_PATH, 'Libs' => LIB_PATH, 'default' => VENDOR_PATH); $autoloader = Autoloader::register($root_path_setting); //or //$autoloader = PsrAutoloader::register($root_path_setting); //get the app $app = \Frame\Application::instance(); //注册module的namespace $app->scripts_namespace = '\\Demo\\Scripts\\'; $app->singleton('request', function ($c) { return new \Libs\Http\BasicScriptsRequest(); }); //router $app->singleton('router', function ($c) { return new \Libs\Router\BasicScriptsRouter($c); }); $app->singleton('response', function ($c) { return new \Libs\Http\BasicScriptsResponse(); }); //声明logWriter $app->singleton('logWriter', function ($c) { return new \Libs\Log\BasicLogWriter();
<?php if ($this->data['server_info']['port'] == 25565) { $port = null; } else { $port = ":" . $this->data['server_info']['port']; } ?> <h3>IP на сървъра: <?php echo $this->data['server_info']['ip_address'] . $port; ?> </h3> <?php if (\Frame\Application::getInstance()->getSession()->user_info['user_id'] == $this->data['server_info']['user_id']) { echo '<a style="width:100%;height:30px;" class="button" href="' . URL . 'server/edit/' . $this->data['server_info']['server_id'] . '">Edit</a>'; } ?> <div class="tabs"> <ul class="tab-links"> <li class="active"><a id="home" href="#tab1">Server</a></li> <li><a href="#tab2">Информация</a></li> <?php if (!empty($this->data['server_info']['youtubevid'])) { ?> <li><a href="#tab3">Youtube Видео</a></li><?php } ?> <li><a href="#tab4">Гласувай!</a></li> <li><a href="#tab5">Банер</a></li> </ul>
public function checkFields() { if (filter_input(INPUT_POST, 'username') == null || filter_input(INPUT_POST, 'password') == null || filter_input(INPUT_POST, 'email' == null)) { $this->data['error'][] = 'Не сте попълнили всички полета за регистрация!'; return false; } $username = trim(filter_input(INPUT_POST, 'username')); $password = trim(filter_input(INPUT_POST, 'password')); $password2 = trim(filter_input(INPUT_POST, 'password2')); $email = trim(filter_input(INPUT_POST, 'email')); if (mb_strlen($username) < 3 || mb_strlen($username) > 50) { $this->data['error'][] = 'Потребителското име трябва да е между 3 и 50 символа'; } if (mb_strlen($password) < 5 || mb_strlen($password) > 50) { $this->data['error'][] = 'Паролата трябва да е между 5 и 50 символа'; } if ($password != $password2) { $this->data['error'][] = 'Паролите не отговарят'; } if (!filter_var($email, FILTER_VALIDATE_EMAIL)) { $this->data['error'][] = "Е-мейлът е невалиден"; } if (empty($this->data)) { $sql = 'SELECT user_id FROM `users` WHERE username=? OR email=?'; $sth = $this->_db->prepare($sql); $sth->execute(array($username, $email)); if ($sth->rowCount() != 0) { $this->data['error'][] = "Съществува потребител с такова потребителско име или e-mail."; return false; } else { $hashedPW = $this->passwordHash($password, \Frame\Application::getInstance()->getConfig()->appConfig['hashingCost']); $sqlInsert = 'INSERT INTO `users` (username,password,email) VALUES(?,?,?)'; $sth = $this->_db->prepare($sqlInsert); $sth->execute(array($username, $hashedPW, $email)); $this->data['message'][] = "Благодарим Ви за регистрацията!Можете да се логнете."; return true; } } else { return false; } }
public function __construct() { $this->_config = \Frame\Application::getInstance()->getConfig(); $this->ns = $this->_config->appConfig['namespaces']['Views']; $this->templateFolder = $this->_config->appConfig['template_folder']; }