public function report($params) { $this->resetStatus(); $inputs = array('height' => array('name' => 'height', 'required' => true, 'number' => true), 'weight' => array('name' => 'weight', 'required' => true, 'number' => true), 'neck' => array('name' => 'neck', 'required' => true, 'number' => true), 'waist' => array('name' => 'waist', 'required' => true, 'number' => true), 'extras' => array('name' => 'extras', 'alfanum' => true)); Session::get('gender') == 2 ? $inputs['hip'] = array('required' => true, 'numeric' => true) : ($params['hip'] = ''); $v = Validation::check($inputs); if ($v == false) { $this->status['errors'] = Flash::showMessages(); $this->return_json($this->status); return false; } else { $r = new MfrUserReport(); $r->last_updated = time(); $r->user_id = Session::get('id'); $r->height = $params['height']; $r->weight = $params['weight']; $r->neck_measurement = $params['neck']; $r->waist_measurement = $params['waist']; $r->waist_measurement = $params['waist']; $r->hip_measurement = $params['hip']; $r->waist_measurement = $params['waist']; $r->observations = $params['extras']; $r->save(); $this->status['success'] = 'ok'; } return $this->return_json($this->status); }
public function checkActive() { if (Session::get('active') !== 1) { header("Location: {$this->location}/"); exit; } }
public function setSession($last_checked_message) { Session::set('last_chat_message', $last_checked_message); $u = new MfrUsers(); $u->id = Session::get('id'); $u->last_chat_message = $last_checked_message; $u->save(); }
private static function setLanguage() { if (!Session::get('application-language')) { $lang = get_browser_language(); # Set the language in_array($lang, Config::get('language')['allowed-languages']) ? Session::set('application-language', $lang) : Session::set('application-language', Config::get('language')['default-language']); } include_once ROOT . DS . 'app' . DS . 'languages' . DS . Session::get('application-language') . '.php'; Lang::set($marianaFrameworkLanguageArray); }
public function check_first_not_exists() { if (Session::get('level') < 2) { $r = $this->r(); # Se estiver feito redireciona para inicio if ($r > 0) { header("location:javascript://history.go(-1)"); die; } } return true; }
public function newRecipe() { $return = array(); $return['success'] = 'fail'; $return['errors'] = array(); if (!isset($this->params['title']) || strlen($this->params['title']) < 10) { array_push($return['errors'], Lang::get('at-least-10-characters-title')); } if (!isset($this->params['question-body']) || strlen($this->params['question-body']) < 30) { array_push($return['errors'], Lang::get('at-least-30-characters-body')); } if (!isset($this->params['quantity']) || sizeof($this->params['quantity']) < 3) { array_push($return['errors'], Lang::get('at-least-3-ingredients')); } if (sizeof($return['errors']) > 0) { return $this->return_json($return); } // if everything passes: $user_id = Session::get('id'); $thumbnail = ''; if (isset($_FILES)) { $file = $_FILES['file']; $path = UPLOAD_PATH . DS . $user_id . DS; $u = new Framework\Upload\Upload(); $thumbnail = $u->single($file, $path); $thumbnail = '/app/files/uploads/' . $user_id . '/' . $thumbnail; } $recipe = new MfrUserRecipes(); $recipe->user_id = Session::get('id'); $recipe->date_created = time(); $recipe->last_updated = time(); $recipe->name = $this->params['title']; $recipe->instructions = $this->params['question-body']; $recipe->lang = 'pt'; $recipe->thumbnail = $thumbnail; $recipe_id = $recipe->saveGetId(); foreach ($this->params['ingredient'] as $key => $value) { $ingredient = MfrAlimentos::where('name_pt', trim($value))->first(); if (isset($ingredient->id) && $ingredient->id > 0) { $addIngredient = new MfrUserRecipesAlimentos(); $addIngredient->recipe_id = $recipe_id; $addIngredient->alimento_id = $ingredient->id; $addIngredient->date_created = time(); $addIngredient->last_updated = time(); $addIngredient->save(); } } $return['success'] = 'ok'; return $this->return_json($return); }
public function checkRememberMe() { // STEP 1: Check if there is a active session.. if (!isset($_SESSION["id"]) || empty($_SESSION["id"])) { $cookieId = Config::get("cookieID"); //STEP 2: Check for cookie that identifies this session (set at config)... if (isset($_COOKIE[Config::get("cookieID")]) && isset($_COOKIE[Config::get("cookieHash")])) { // STEP 3: Decrypt the hash $decriptedHash = Criptography::decript($_COOKIE[Config::get("cookieHash")]); $confirmation = Sessions::where("id", $_COOKIE[Config::get("cookieID")])->also("hash", $decriptedHash)->first(); // STEP 4: if exists in the database: $setSession = json_decode($confirmation["json_session"]); foreach ($setSession as $key => $pair) { Session::set($key, $pair); } } } }
public static function getNewChatMessages($conversation_id) { $last_message = Session::get('last-chat-message'); $messages = MfrChatMessages::where('conversation_id', $conversation_id)->also('id', '>', $last_message)->desc()->as_array()->get(); $last_message = $messages[0]['id']; $messages = array_reverse($messages); $i = 0; foreach ($messages as $message) { $u = MfrUsers::find($message['user_id'])[0]; if ($u->avatar == '' || ($u->avatar = null)) { $u->avatar = DEFAULT_IMAGE; } $messages[$i]['user-info'] = $u; $i++; } Session::set('last-chat-message', $last_message); return $messages; }
public static function store($filename, $logMessage, $userinfo = false, $mail = false) { # File name $filename = FILE_PATH . DS . 'logs' . DS . $filename . '.log'; # Extra stuff $extras = ''; $datetime = date('Y-m-d H:i:s'); # Open the handle $fd = fopen($filename, 'a'); # Debug Backtrace $debugBacktrace = debug_backtrace(); $line = $debugBacktrace[1]['line']; $file = $debugBacktrace[1]['file']; # Simple Message $message = preg_replace('/\\s+/', ' ', trim($logMessage)); $log = "\r\n" . 'DATE: ' . $datetime . ' || ACTION: ' . $logMessage . ' || FILE AND LINE: ' . $file . ' - ' . $line; # If wants user info: if ($userinfo) { $session = \Mariana\Framework\Session\Session::display(); $cookie = \Mariana\Framework\Session\Cookie::display(); if ($session) { $extras .= ' || SESSION: ' . $session; } if (isset($cookie)) { $extras .= ' || COOKIES: ' . html_entity_decode($cookie); } $ip = self::getIp(); $uid = self::getUniqueIdentifyer(); $log = "\r\n" . 'DATE: ' . $datetime . ' || IP: ' . $ip . ' || UNIQUE: ' . $uid . ' || ACTION: ' . $logMessage . ' || FILE AND LINE: ' . $file . ' - ' . $line . ' || EXTRA INFO: ' . $extras; } fwrite($fd, $log); fclose($fd); if ($mail) { mail(Config::get('security-report-email-address'), $message, $log); } }
public static function user_files($user_id = false) { $user_id !== false ?: ($user_id = Session::get('id')); $files = MfrUserFiles::where('user_id', $user_id)->get(); return $files; }
public static function getAnswer($id, $topic_id) { $user_id = Session::get('id'); $sql = "\n Select\n DISTINCT (makefitreal.mfr_forum_answers.id),\n makefitreal.mfr_forum_answers.topic_id as subject_id,\n makefitreal.mfr_forum_answers.date_created,\n makefitreal.mfr_forum_answers.last_updated,\n makefitreal.mfr_forum_answers.content,\n makefitreal.mfr_forum_answers.accepted,\n makefitreal.mfr_forum_answers.user_id,\n makefitreal.mfr_users.level,\n makefitreal.mfr_users.avatar,\n makefitreal.mfr_forum_likes.subject_id,\n makefitreal.wp_users.ID As ID1,\n makefitreal.mfr_forum_topics.user_id As owner_id,\n (SELECT count(makefitreal.mfr_forum_likes.id) FROM makefitreal.mfr_forum_likes WHERE makefitreal.mfr_forum_likes.subject_id = :topicId AND makefitreal.mfr_forum_likes.type = 'answer') as likes,\n (SELECT count(makefitreal.mfr_forum_likes.id) FROM makefitreal.mfr_forum_likes WHERE makefitreal.mfr_forum_likes.subject_id = :topicId AND makefitreal.mfr_forum_likes.type = 'answer' AND makefitreal.mfr_forum_likes.user_id = :sessionId ) as i_like,\n makefitreal.wp_users.user_nicename\n From\n makefitreal.mfr_forum_likes ,\n makefitreal.mfr_forum_answers\n Inner Join\n makefitreal.mfr_users\n On makefitreal.mfr_forum_answers.user_id = makefitreal.mfr_users.id\n Inner Join\n makefitreal.wp_users\n On makefitreal.mfr_users.id = makefitreal.wp_users.ID Inner Join\n makefitreal.mfr_forum_topics\n On makefitreal.mfr_forum_answers.topic_id = makefitreal.mfr_forum_topics.id\n Where\n makefitreal.mfr_forum_answers.id = :id"; $stmt = Mariana\Framework\Database::getConnection()->prepare($sql); $stmt->bindParam(':sessionId', $user_id); $stmt->bindParam(':id', $id); $stmt->bindParam(':topicId', $topic_id); $stmt->execute(); return $stmt->fetch(PDO::FETCH_ASSOC); }
<!-- Forum List Item template --> <script> // Render the last posts var $$scope2 = <?php echo json_encode($scope['topics']['topics']); ?> ; var Template = new Template(); Template.render('forum-list','topics_container',$$scope2); var array_of_stuff = { user_id: '<?php echo \Mariana\Framework\Session\Session::get("id") ? \Mariana\Framework\Session\Session::get("id") : 0; ?> ', fail: '<?php echo $scope['navbar-stuff']['fail']; ?> ' }; var Forum = new Forum('<?php echo COACHING_URL; ?> ',array_of_stuff); $('input[name="answer-filter"]').on('change',function(){ filter();
public function myRecipes() { $scope = array('title' => 'Make Fit Real User Area', 'website' => $this->website, 'csrf' => $this->csrf, 'intro-title' => Lang::get('intro-title-diet')); $navbar_stuff = $this->navbar_stuff(); $scope['navbar-stuff'] = $navbar_stuff['stuff']; $scope['navbar-links'] = $navbar_stuff['links']; $scope['coaching-status'] = MfrUsers::current_status(); $scope['average-status']['kcals'] = $scope['coaching-status'][2]['value'] / 4; $scope['average-status']['protein'] = $scope['coaching-status'][3]['value'] / 4; $scope['average-status']['carbs'] = $scope['coaching-status'][4]['value'] / 4; $scope['average-status']['fat'] = $scope['coaching-status'][5]['value'] / 4; $scope['average-status']['macros'] = $scope['coaching-status'][6]['value']; $scope['recipes'] = MfrUserRecipes::allRecipes(Session::get('id')); View::render('coaching/user/diet/adapt-from-blog/index.php', $scope); }
  Favorito(s):   </div> {{ if ( this.accepted == 1){ }} <div style="width: 100%; text-align: center"> <b><i class="fa fa-check text-green fa-2x"></i></b> </div> {{ } }} </td> <td class="talk-it" style="padding:10px;"> <small id="reply-content-{{ this.id }}"> {{ this.content }} </small> <footer style="display: inline-block; width:100%; margin-top:10px"> <span><small class="undercover-a pink-text pointer" onclick="editAnswer( {{this.id}})">Editar   </small></span> {{ if ( this.owner_id == <?php echo \Mariana\Framework\Session\Session::get('id'); ?> || this.level > 1 ) { }} <span><small class="undercover-a pink-text pointer" onclick="deleteAnswer( {{this.id}} )">Apagar   </small></span> <span><small class="undercover-a pink-text pointer" onclick="acceptAnswer({{ this.id }} , {{ this.subject_id }})">Aceitar resposta   </small></span> {{ } }} <span><small class="undercover-a pink-text pointer "><a class="undercover-a" href="http://www.facebook.com/sharer.php?u=<?php echo COACHING_URL; ?> /forum/topic/{{ this.subject_id }}"> Partilhar   </a></small></span> </footer> <footer> <div class="reply-author"> <p class="pull-right">{{ timeConverter(this.date_created) }}</p> <table>
<!-- // RIGHT PANEL --> <div class="col-lg-8"> <?php foreach ($scope['recipes'] as $key => $value) { ?> <a class="undercover-a"> <form class="login list-panel pointer" onclick="adaptRecipe(<?php echo $value->id; ?> )"> <div class="row"> <div class="col-lg-8"> <h4 class="p-0-20 text-pink "> <small class="pull-right"> <?php if ($value->ID === \Mariana\Framework\Session\Session::get('id')) { echo '<i class="fa fa-times pink-text rotate-on-hover" onclick="deleteRecipe(event); " data-id="<?= $value->id ; ?>"> </i>'; } ?> </small><span class="text-capitalize-first"> <?php echo $value->name; ?> </span> </h4> <p><?php echo mfr_excerpt($value->instructions, 250); ?> </p> <p> <small class="pull-right pink-text">Clicar para adaptar.</small>
private function navbar_stuff() { Session::get('nice_name') ? $nice_name = Session::get('nice_name') : ($nice_name = Lang::get('guest')); Session::get('id') ? $logout = Lang::get('logout') : ($logout = Lang::get('sign-in')); switch (Session::get('level')) { case 1: // Make Fit Real Manager $links = $this->user_links; break; case 2: // Make Fit Real Coach $links = $this->coach_links; break; default: // Make Fit Real User $links = $this->manager_links; } return array('stuff' => array('welcome' => Lang::get('hello'), 'user_nice_name' => $nice_name, 'logout' => $logout, 'please-contact-admin' => Lang::get('please-contact-admin'), 'unable-to-preform-action' => Lang::get('unable-to-preform-action'), 'fail' => Lang::get('fail'), 'success' => Lang::get('success')), 'links' => $links); }
/** * Default method; */ public function tracking($request = array()) { $user_id = Session::get('id'); $time = time(); /** * @recieved: * POST http://localhost:8000/coaching/workout-tracking/ array(4) { ["workout-id"]=>string(1) "1" ["workout-day"]=>string(1) "1" ["weight"]=>array(3) { [11]=>string(1) "0" [1]=>string(1) "0" [16]=>string(1) "0" } ["exercise-complete"]=>array(3) { [11]=>string(5) "false" [1]=>string(5) "false" [16]=>string(5) "false" } } * @objective: update into mfr-treinos-progresso if ( ['exercise-complete'][id] = "true" */ foreach ($request['exercise-complete'] as $key => $pair) { $exercise_id = $key; if ($pair == 'true') { $sql = 'UPDATE `mfr_treinos_progresso` SET `weight` = ?, `last_updated` = ?, `attempts` = 0 WHERE `mfr_treinos_progresso`.`user_id` = ? AND `mfr_treinos_progresso`.`exercise_id` = ? AND `mfr_treinos_progresso`.`workout_id` = ?;'; $stmt = Database::getConnection()->prepare($sql); $stmt->bindParam(1, $request['weight'][$key]); $stmt->bindParam(2, $time); $stmt->bindParam(3, $user_id); $stmt->bindParam(4, $key); $stmt->bindParam(5, $request['workout-id']); $stmt->execute(); } if ($pair == 'false') { if ($request['attempts'][$key] + 1 > 3) { array_push($this->errors, Lang::get('maximum-attemps-at-exercise')); (double) ($new_weight = (double) $request['weight'][$key] * 0.75); $sql = 'UPDATE `mfr_treinos_progresso` SET `weight` = ?, `last_updated` = ?, `attempts` = 0 WHERE `mfr_treinos_progresso`.`user_id` = ? AND `mfr_treinos_progresso`.`exercise_id` = ? AND `mfr_treinos_progresso`.`workout_id` = ?;'; $stmt = Database::getConnection()->prepare($sql); $stmt->bindParam(1, $new_weight); $stmt->bindParam(2, $time); $stmt->bindParam(3, $user_id); $stmt->bindParam(4, $key); $stmt->bindParam(5, $request['workout-id']); $stmt->execute(); } else { $attempts = $request['attempts'][$key] + 1; $sql = 'UPDATE `mfr_treinos_progresso` SET `last_updated` = ?, `attempts` = ? WHERE `user_id` = ? AND `mfr_treinos_progresso`.`exercise_id` = ? AND `workout_id` = ?;'; $stmt = Database::getConnection()->prepare($sql); $stmt->bindParam(1, $time); $stmt->bindParam(2, $attempts); $stmt->bindParam(3, $user_id); $stmt->bindParam(4, $key); $stmt->bindParam(5, $request['workout-id']); $stmt->execute(); } } } echo json_encode(array('success' => 'ok', 'errors' => $this->errors)); }
public function csrf() { return Session::csrf($_POST['csrf']); }
public function signup($params = array()) { # Requirements $this->load(); $this->status['status'] = 'fail'; # Params $user_login = $params['username']; $user_name = $params['name']; $user_email = $params['email']; $user_password = $params['password']; $user_password_2 = $params['password_confirm']; $brought_by = $params['code']; $brought_by = str_replace('#mfr_', '', strtolower($brought_by)); # Validation if (!Session::csrf($params['mariana-csrf'])) { $this->status['errors'] = array(Lang::get('csrf-check-fail')); $this->return_json($this->status); return header('HTTP/1.0 200 OK'); } $inputs = array('username' => array('name' => 'username', 'required' => true, 'alfanum' => true), 'password' => array('name' => 'password', 'required' => true, 'alfanum' => true, 'min' => 3, 'max' => 32), 'password_confirm' => array('name' => 'password_confirm', 'matches' => 'password', 'required' => true), 'email' => array('required' => true, 'email' => true)); if (Validation::check($inputs) === false) { $this->status['errors'] = Framework\Session\Flash::showMessages(); $this->return_json($this->status); return header('HTTP/1.0 200 OK'); } $check_if_username_exists = WpUsers::wp_unique_user($user_login, $user_email); if ($check_if_username_exists) { $this->status['errors'] = $check_if_username_exists; $this->return_json($this->status); return header('HTTP/1.0 200 OK'); } # Create entry on both databases $user_id = wp_create_user($user_login, $user_password, $user_email); MfrUsers::wp_create_user($user_id, $user_name, $brought_by); # Notify wp_new_user_notification($user_id, $user_password); # Sign the user in $params = array(); $params['username'] = $user_login; $params['password'] = $user_password; $this->login($params); $this->return_json($this->status); # Forcing code 200 - Dunno why but keeps failing on this specific function return header('HTTP/1.0 200 OK'); }