/** * Get the number of days to list. * * @param string Start date * @param string End date * @return int Number of days */ function getDayNumber($start, $end) { Pluf::loadFunction('Pluf_Date_Compare'); $diff = Pluf_Date_Compare($start . ' 00:00:00', $end . ' 00:00:00'); return (int) $diff / 86400; }
/** * Process the request. * * When processing the request, if a session is found with * Pluf_User creditentials the corresponding user is loaded into * $request->user. * * FIXME: We should logout everybody when the session table is emptied. * * @param Pluf_HTTP_Request The request * @return bool false */ function process_request(&$request) { $session = new Pluf_Session(); $user_model = Pluf::f('pluf_custom_user', 'Pluf_User'); $user = new $user_model(); if (!isset($request->COOKIE[$session->cookie_name])) { // No session is defined. We set an empty user and empty // session. $request->user = $user; $request->session = $session; if (isset($request->COOKIE[$request->session->test_cookie_name])) { $request->session->test_cookie = $request->COOKIE[$request->session->test_cookie_name]; } return false; } try { $data = self::_decodeData($request->COOKIE[$session->cookie_name]); } catch (Exception $e) { $request->user = $user; $request->session = $session; if (isset($request->COOKIE[$request->session->test_cookie_name])) { $request->session->test_cookie = $request->COOKIE[$request->session->test_cookie_name]; } return false; } $set_lang = false; if (isset($data[$user->session_key])) { // We can get the corresponding user $found_user = new $user_model($data[$user->session_key]); if ($found_user->id == $data[$user->session_key]) { // User found! $request->user = $found_user; // If the last login is from 12h or more, set it to // now. Pluf::loadFunction('Pluf_Date_Compare'); if (43200 < Pluf_Date_Compare($request->user->last_login)) { $request->user->last_login = gmdate('Y-m-d H:i:s'); $request->user->update(); } $set_lang = $found_user->language; } else { $request->user = $user; } } else { $request->user = $user; } if (isset($data['Pluf_Session_key'])) { $sql = new Pluf_SQL('session_key=%s', $data['Pluf_Session_key']); $found_session = Pluf::factory('Pluf_Session')->getList(array('filter' => $sql->gen())); if (isset($found_session[0])) { $request->session = $found_session[0]; } else { $request->session = $session; } } else { $request->session = $session; } if ($set_lang and false == $request->session->getData('pluf_language', false)) { $request->session->setData('pluf_language', $set_lang); } if (isset($request->COOKIE[$request->session->test_cookie_name])) { $request->session->test_cookie = $request->COOKIE[$request->session->test_cookie_name]; } return false; }