public function render() { // Create the path titles with urls $parents = explode('/', $this->page->slug); $current = current(array_reverse($parents)); debug("Current" . $current); $urls = []; foreach ($parents as $slug) { if ($slug == $current) { break; } $parentp = R::findOne('page', 'slug = :slug', ['slug' => $slug]); $title = $parentp->title; $title = current(explode(' | ', $title)); foreach (self::$remove as $string) { $title = str_replace($string, '', $title); } $exploded = explode(' | ', $title); foreach ($exploded as $rem) { self::$remove[] = $rem; } $title = str_replace('|', '', $title); $title = trim($title); $u = ['label' => $title, 'href' => $parentp->slug]; $urls[] = $u; } $title = $this->page->title; $title = current(explode(' | ', $title)); foreach (self::$remove as $string) { $title = str_replace($string, '', $title); } // $title = trim(str_replace('|', '', $title)); $urls[] = ['label' => $title, 'href' => $this->page->slug]; return Theme_Loader::get_instance()->render_file('modules/breadcrumb/breadcrumb.twig', ['urls' => $urls]); }
function douban_callback() { OAuthRequester::requestAccessToken(DOUBAN_KEY, $_SESSION['oauth_token'], 0, 'POST', $options = array('oauth_verifier' => $_SESSION['oauth_token'])); $req = new OAuthRequester('http://api.douban.com/people/' . urlencode('@me'), 'get'); $res = $req->doRequest(); $user_data = new SimpleXMLElement($res['body']); $uid = array_pop(explode('/', $user_data->id)); $auth_type = 'douban'; $auth = R::findOne('oauth', "uid=? AND type=?", array($uid, $auth_type)); if (!$auth) { $auth = R::dispense('oauth'); $auth->uid = $uid; $auth->type = $auth_type; $encrypt_key = rand(100000, 999999); $auth->secret = $encrypt_key; } else { $encrypt_key = $auth->secret; } $cookie_str = sha1(implode('', array($uid, $auth_type, $_SERVER['REMOTE_ADDR'], $_SERVER['HTTP_USER_AGENT'], $encrypt_key))); $expire = time() + 3600 * 24 * 365; setcookie('s', $cookie_str, $expire); setcookie('auth_type', $auth_type, $expire); setcookie('uid', $uid, $expire); $auth->setMeta('buildcommand.unique', array(array('uid', 'type'))); $auth->setMeta('buildcommand.indexes', array('uid' => 'uid')); R::store($auth); }
/** * Function to get event details by event id * @param int $eventId Id of the event for which details are to be found * @param int $userId Id of the user who is seeing the event * @return array * **/ public function getEventDetails($eventId, $userId) { $return['event_details'] = array(); $return['userParticiaptionStatus'] = null; $return['participantDetails'] = array(); // get event details $eventDetails = \R::findOne($this->_name, 'id = :eid AND status = 1', array(':eid' => $eventId)); if ($eventDetails) { // get details of participants $getUserParticipationDetails = "SELECT u.id as userid ,u.first_name,u.last_name ,upe.participation_id\r\n FROM users_events_participation upe \r\n JOIN users u ON upe.users_id = u.id AND upe.events_id = :eId\r\n WHERE upe.participation_id IN (1,3)\r\n ORDER BY (u.id = :uId) DESC, u.id"; $rows = \R::getAll($getUserParticipationDetails, array(':eId' => $eventId, ':uId' => $userId)); $return['event_details'] = $eventDetails->export(false); $usersParticpating = array(); // array containing profile pic of the user who are participating $objServerInfo = new \services\helpers\ServerInfo(); if (!empty($rows)) { // if first row is for given user then handle it accordingly if ($rows[0]['userid'] == $userId) { $return['userParticiaptionStatus'] = $rows[0]['participation_id']; unset($rows[0]); } // details f other participants foreach ($rows as $record) { $profilepic = $objServerInfo->getScheme() . "://" . $objServerInfo->getHost() . APPLICATION_BASE . 'images/' . $record['userid'] . '_pp.jpg'; $picPath = APPLICATION_DIR . "/images/{$record['userid']}_pp.jpg"; $record['profilepic'] = @is_file($picPath) ? $profilepic : null; $usersParticpating[] = $record; } } $return['participantDetails'] = $usersParticpating; } return $return; }
public function init() { // check if logged in session is valid, if not redir to main page if (!isset($_SESSION['loginHash'])) { Framework::Redir("site/index"); die; } $activeSession = R::findOne('session', ' hash = ? AND ip = ? AND expires > ?', array($_SESSION['loginHash'], $_SERVER['REMOTE_ADDR'], time())); if (!$activeSession) { unset($_SESSION['loginHash']); Framework::Redir("site/index/main/session_expired"); die; } $activeSession->expires = time() + SESSION_MAX_AGE * 2; R::store($activeSession); $this->session = $activeSession; $this->user = R::load('user', $this->session->user->getId()); Framework::TPL()->assign('user_premium', $this->user->hasPremium()); // check needed rights if any foreach ($this->_rights as $r) { if (!$this->user->hasRight($r)) { Framework::Redir("game/index"); die; } } }
/** * this is stupid * @see Controller_GameAuth::init() */ public function init() { // check if logged in session is valid, if not redir to main page if (!isset($_SESSION['loginHash'])) { $this->error('not_loggedin'); die; } // check if secure hash is valid if ($_SERVER['REQUEST_METHOD'] == 'POST') { if (!$this->checkSecureHash($_POST['fSecureHash'])) { $this->error('Ungültiger fSecureHash.'); die; } } $activeSession = R::findOne('session', ' hash = ? AND ip = ? AND expires > ?', array($_SESSION['loginHash'], $_SERVER['REMOTE_ADDR'], time())); if (!$activeSession) { unset($_SESSION['loginHash']); $this->error('not_loggedin'); die; } $activeSession->expires = time() + SESSION_MAX_AGE; R::store($activeSession); $this->session = $activeSession; $this->user = $this->session->user; //R::load('user', $this->session->user->getId()); // check needed rights if any foreach ($this->_rights as $r) { if (!$this->user->hasRight($r)) { $this->error('no_rights'); die; } } }
public function save() { GUMP::add_validator("unique", function ($field, $input, $param = NULL) { $checkExistingUser = R::findOne('user', 'user=?', array($input)); if ($checkExistingUser == NULL) { return FALSE; } else { return TRUE; } }); GUMP::add_validator("strong", function ($field, $input, $param = NULL) { return checkPasswordStrength($input); }); $rules = array('reseller_username' => 'required|alpha_numeric|max_len,10|min_len,6|unique', 'reseller_password' => 'required|max_len,10|min_len,7|strong'); $filters = array('reseller_username' => 'trim|sanitize_string', 'reseller_password' => 'trim|sanitize_string|md5'); $app = Slim::getInstance(); $post = $app->request()->post(); // $app - Slim main app instance $postValues = $gump->filter($post, $filters); $validated = $gump->validate($gump->filter($postValues, $filters), $rules); if ($validated === TRUE) { $createUser = R::dispense('user'); $createUser->user = $postValues['reseller_username']; $createUser->user = $postValues['reseller_password']; } else { $this->setError($gump->get_readable_errors(true)); } if ($this->getError() == "") { $this->fails = FALSE; } else { $this->fails = TRUE; } }
/** * Given a name, get the custom field data model. Attempts to retrieve from cache, if it is not available, * will attempt to retrieve from persistent storage, cache the model, and return. * @param string $name * @return CustomFieldData model * @throws NotFoundException */ public static function getByName($name, $shouldCache = true) { if (isset(self::$cachedModelsByName[$name])) { return self::$cachedModelsByName[$name]; } try { return GeneralCache::getEntry('CustomFieldData' . $name); } catch (NotFoundException $e) { assert('is_string($name)'); assert('$name != ""'); $bean = R::findOne('customfielddata', "name = :name ", array(':name' => $name)); assert('$bean === false || $bean instanceof RedBean_OODBBean'); if ($bean === false) { $customFieldData = new CustomFieldData(); $customFieldData->name = $name; $customFieldData->serializedData = serialize(array()); // An unused custom field data does not present as needing saving. $customFieldData->setNotModified(); } else { $customFieldData = self::makeModel($bean); } if ($shouldCache) { self::$cachedModelsByName[$name] = $customFieldData; GeneralCache::cacheEntry('CustomFieldData' . $name, $customFieldData); } return $customFieldData; } }
public function show_Chat() { $lastMessage = $_POST["time"]; if ($lastMessage < 0 || !is_numeric($lastMessage)) { $this->error('Invalid lastMessage-Timestamp'); } if ($lastMessage < time() - CHAT_LIFETIME) { $lastMessage = time() - CHAT_LIFETIME; } $messages = R::find('chat_message', ' map = ? AND time > ? AND ((type = ? || (type = ? AND visible_for_id = ?)) || player_id = ?) ORDER BY time ASC', array($this->mapPosition->map, $lastMessage, 'public', 'private', $this->user->id, $this->user->id)); $m = array(); $latest = $lastMessage; foreach ($messages as $msg) { $to = ""; $type = $msg->player_id != null && $msg->player_id == $this->user->id ? "own" : $msg->type; if ($type == "own" && $msg->visible_for_id != null) { $p = R::findOne('user', ' id = ?', array($msg->visible_for_id)); if ($p != false) { $to = htmlspecialchars($p->username); } } $m[] = array('time' => date("H:i:s", $msg->time), 'author' => htmlspecialchars($msg->author), 'pid' => $msg->player_id != null ? $msg->player_id : "-1", 'text' => $msg->text, 'type' => $type, 'to' => $to); $latest = $msg->time; } $this->output('messages', $m); $this->output('timestamp', $latest); }
public static function getByUrl($url) { $data = R::findOne('page', 'url=?', [$url]); if (!empty($data)) { $data['body'] = Page::getBody(_WEB . Page::$buffer_dir . $data['filename'] . '.html'); } return $data; }
public static function isBanned($type, $value) { $ban = R::findOne('banlist', ' type=:type AND value=:value ', array(':type' => $type, ':value' => $value)); if (isset($ban) && $ban->id) { return true; } return false; }
function load_data($slug) { $page = R::findOne('page', 'slug = :slug', ['slug' => $slug]); if (empty($page)) { $page = $this->create_data($slug); } return $page; }
public function show_Use() { $userPos = R::findOne('map_position', ' user_id = ?', array($this->user->getID())); $this->output('maintext', 'Dieser Teleporter ist ein Admin-Item. Damit kannst du dich durch die Gegend teleportieren'); $this->output('form', array('target' => 'teleport', 'elements' => array(array('desc' => 'X', 'name' => 'x', 'type' => 'text'), array('desc' => 'Y', 'name' => 'y', 'type' => 'text'), array('name' => 'map', 'desc' => 'Karte', 'type' => 'select', 'options' => array('main' => 'Main', 'main2' => 'Main2', 'main3' => 'Main3', 'supermarket' => 'Supermarkt', 'livinghouse' => 'Wohnhaus'), 'value' => $userPos->map)))); //$this->output('options', array('use' => 'Zurück')); }
public static function showBlockBySlug($name) { $block = R::findOne('blocks', " url=:url ", array(':url' => $name)); if (isset($block) && $block->id) { echo $block->content; } return false; }
public function isValidAccessKey($accessKeyId) { $row = \R::findOne($this->_name, 'access_key_id = :akid', array(':akid' => $accessKeyId)); if ($row) { return $row; } return false; }
/** Update - automatically called by RedBean when stored. */ public function update() { parent::update(); $test = R::findOne("subscription", "email=? and id<>?", array($this->email, $this->id)); if ($test) { $this->bean->id = $test->id; } }
public function isUserSubscribed() { $user = R::findOne('subscriptions', ' email=:email AND category_id=:category_id AND city_id=:city_id ', array(':email' => $this->_email, ':category_id' => $this->_category_id, ':city_id' => $this->_city_id)); if ($user && $user->id) { return $user->id; } return false; }
public function loadUserByUsername($username) { $user = \R::findOne('user', ' username = ? ', array($username)); if (!$user) { throw new UsernameNotFoundException(sprintf('Username "%s" does not exist.', $username)); } return new User($user['username'], $user['password'], explode(',', $user['roles']), true, true, true, true); }
public function getJobFromToken($token) { $job = R::findOne('jobs', ' id=:id AND token=:token ', array(':id' => $this->_id, ':token' => $token)); if (isset($job) && $job->id) { return $job; } return false; }
/** User logs in */ public static function login($l, $p) { $user = R::findOne("user", "(@email=:l) and pwhash=:p", array('l' => $l, 'p' => sha1($p))); if (!$user) { RedView::end('error', 'User name and password don\'t match.'); } $_SESSION['user'] = $user->export(); RedView::end('message', 'Logged in.'); }
function getLastPosition($clientid) { $menu = R::findOne('menu', "client_id = ? ORDER BY pos DESC", array($clientid)); if ($menu) { return $menu->pos; } else { return 0; } }
public function init() { parent::init(); $this->myQuests = R::related($this->user, 'company_quest'); if (!R::findOne('company', ' user_id = ?', array($this->user->id))) { $this->error('Du besitzt keine Firma. Geh ins Nachbargebäude und gründe dort eine Firma bevor du Aufträge annehmen kannst.'); } }
function getLastPosition($idsubmenu) { $galeria = R::findOne('galeria', "submenu_id = ? ORDER BY pos DESC", array($idsubmenu)); if ($galeria) { return $galeria->pos; } else { return 0; } }
function equipe($slug) { global $twig, $base, $titre; $personne = R::findOne("personnes", "slug = ?", [$slug]); if (!$personne) { return not_found(); } return $twig->render("equipe.html", compact("base", "titre", "personne")); }
public function show_Use() { $this->output('maintext', "Hier kannst du ein NPC erstellen."); $userPos = R::findOne('map_position', ' user_id = ?', array($this->user->getID())); $charImg = array(); for ($i = 1; $i <= HIGHEST_CHAR_IMG; $i++) { $charImg[$i] = $i; } $this->output('form', array('target' => 'make', 'elements' => array(array('name' => 'name', 'desc' => 'Name', 'type' => 'text'), array('name' => 'type', 'desc' => 'Typ', 'type' => 'text'), array('name' => 'x', 'desc' => 'X', 'type' => 'text', 'value' => $userPos->x), array('name' => 'y', 'desc' => 'Y', 'type' => 'text', 'value' => $userPos->y), array('name' => 'map', 'desc' => 'Karte', 'type' => 'select', 'options' => array('main' => 'Main', 'main2' => 'Main2', 'main2' => 'Main3', 'supermarket' => 'Supermarkt', 'livinghouse' => 'Wohnhaus', 'adminhouse' => 'Adminhaus', 'businesscenter' => 'BusinessCenter', 'tradingcenter' => 'TradingCenter', 'casino' => 'Casino'), 'value' => $userPos->map), array('name' => 'can_walk', 'desc' => 'Kann rumlaufen?', 'type' => 'checkbox', 'value' => 1), array('name' => 'characterImage', 'desc' => 'Bild', 'type' => 'select', 'options' => $charImg), array('name' => 'lookDirection', 'desc' => 'Blickrichtung', 'type' => 'select', 'options' => array('0' => 'Hoch', '1' => 'Rechts', '2' => 'Runter', '3' => 'Links'))))); }
public function changePassword($username, $password, $newPassword) { $user = R::findOne('users', 'username = ?', [$username]); if (!$user || !password_verify($password, $user['password'])) { return false; } $user['password'] = password_hash($newPassword, PASSWORD_DEFAULT); $userId = R::store($user); return $userId > 0; }
public function deleteMessage($user_id, $m_id) { $message = R::findOne('message', ' recipient_id = ? && id = ? ', [$user_id, $m_id]); if ($message == NULL) { return NULL; } R::trash($message); $data = array("rc" => 0); return json_encode($data); }
public function init() { parent::init(); mt_srand((double) microtime(true) * 123456); $this->_myGame = R::findOne('blackjack', ' user_id = ?', array($this->user->getID())); if ($this->_myGame != null) { $this->_myCards = json_decode($this->_myGame->user_cards, true); $this->_dealerCards = json_decode($this->_myGame->dealer_cards, true); } }
public function beforeProcessing(&$context) { $user = R::findOne('user', 'LOWER(name) = LOWER(?)', [$context->key]); if (empty($user)) { $user = R::dispense('user'); $user->name = $context->key; R::store($user); } $context->user = $user; }
public function sendPromo() { $promo = R::findOne('promo', 'id = ?', [$promo_id]); $devices = R::findAll('device'); foreach ($devices as $device) { $user = R::findOne('user', 'id = ?', [$device->user_id]); $msg = isset($user) ? $user->name . " esta promoción podría interesarte, " . $promo->title : "Esta promoción podría interesarte, " . $promo->title; Notification::sendPush($device->token, $msg, ["user_id" => $user->id, "promo_id" => $promo->id], 0); } }
/** * Function to clear invalid login attempts * @param string $username email or username of user * @return int login attempts left * **/ public function clearInvalidLoginAttempts($username) { $userRow = \R::findOne('users', 'email=:ui OR user_name = :ui', array(':ui' => $username)); if ($userRow) { $userAttemptRow = \R::findOne($this->_name, 'user_id = :ui', array(':ui' => $userRow->id)); if ($userAttemptRow) { \R::trash($userAttemptRow); } } }