/** * gmt date. the timezone up to current user data. * * @param string $date_format date format can use both date() function or strftime() function * @param integer $timestamp localtime timestamp. * @param type $timezone php timezone (http://www.php.net/manual/en/timezones.php) * @return null */ public static function gmtDate($date_format = '%Y-%m-%d %H:%M:%S', $timestamp = '', $timezone = '') { // check empty date format if (empty($date_format)) { $date_format = '%Y-%m-%d %H:%M:%S'; } // check timestamp if (empty($timestamp)) { $timestamp = time(); } else { if (!self::isValidTimeStamp($timestamp)) { $timestamp = strtotime($timestamp); } } // make very sure that selected timezone is in the timezone list or converted to real timezone. if ($timezone != null) { $timezone = static::isValidTimezone($timezone); } // check timezone if ($timezone == null) { $account_model = new \Model_Accounts(); $cookie = $account_model->getAccountCookie(); $site_timezone = static::getRealTimezoneValue(\Model_Config::getval('site_timezone')); if (!isset($cookie['account_id'])) { // not member or not log in. use default config timezone. $timezone = $site_timezone; } else { // find timezone for current user. $row = \Model_Accounts::find($cookie['account_id']); if (!empty($row)) { $timezone = static::getRealTimezoneValue($row->account_timezone); } else { $timezone = $site_timezone; } } unset($account_model, $cookie, $row, $site_timezone); } // what format of the date_format (use date() value or strftime() value) if (strpos($date_format, '%') !== false) { // use strftime() format return \Date::forge($timestamp)->set_timezone($timezone)->format($date_format); } else { // use date() format return date($date_format, strtotime(\Date::forge($timestamp)->set_timezone($timezone)->format('%Y-%m-%d %H:%M:%S'))); } }
public function action_deleteAvatar() { // get account id from cookie $account = new \Model_Accounts(); $cookie = $account->getAccountCookie(); if (\Input::method() == 'POST') { if (!\Extension\NoCsrf::check()) { // validate token failed $output['form_status'] = 'error'; $output['form_status_message'] = \Lang::get('fslang_invalid_csrf_token'); $output['result'] = false; } else { if (!isset($cookie['account_id']) || \Model_Accounts::isMemberLogin() == false) { $output['result'] = false; } else { $output['result'] = true; $account->deleteAccountAvatar($cookie['account_id']); } } } unset($account, $cookie); if (\Input::is_ajax()) { // re-generate csrf token for ajax form to set new csrf. $output['csrf_html'] = \Extension\NoCsrf::generate(); $response = new \Response(); $response->set_header('Content-Type', 'application/json'); $response->body(json_encode($output)); return $response; } else { if (\Input::referrer() != null && \Input::referrer() != \Uri::main()) { \Response::redirect(\Input::referrer()); } else { \Response::redirect(\Uri::base()); } } }
// get browser class for use instead of fuelphp agent which is does not work. include_once APPPATH . 'vendor' . DS . 'browser' . DS . 'lib' . DS . 'Browser.php'; $browser = new Browser(); $pc_class = ''; if (!$browser->isMobile() && !$browser->isTablet()) { $pc_class .= ' pc_device'; } elseif ($browser->isMobile()) { $pc_class .= ' mobile_device'; } elseif ($browser->isTablet()) { $pc_class .= ' tablet_device'; } unset($browser); // get admin cookie. if (!isset($cookie_admin) || !isset($cookie_admin['account_display_name'])) { $model_account = new \Model_Accounts(); $cookie_admin = $model_account->getAccountCookie('admin'); if ($cookie_admin == null) { $cookie_admin = $model_account->getAccountCookie(); } unset($model_account); if (is_array($cookie_admin) && array_key_exists('account_id', $cookie_admin)) { $account_id = $cookie_admin['account_id']; } } if (!isset($account_id)) { $account_id = 0; } // load functions file to work with theme. include_once __DIR__ . DS . 'inc_functions.php'; // get admin avatar at navbar $admin_navbar_avatar = getAdminAvatar($account_id);
/** * check member permission. * if account id is not set, get it from member cookie. * * @param string $page_name * @param string $action * @param integer $account_id * @return boolean */ public static function checkMemberPermission($page_name = '', $action = '', $account_id = '') { if ($account_id == null) { // account id is empty, get it from cookie. $model_accounts = new \Model_Accounts(); $cm_account = $model_accounts->getAccountCookie('member'); $account_id = isset($cm_account['account_id']) ? $cm_account['account_id'] : '0'; unset($cm_account, $model_accounts); } return static::checkAdminPermission($page_name, $action, $account_id); }