public static function process() { $security = new Security(); $security->verifyPre(); $data = stream_get_contents(fopen('php://input', 'r')); $compressedSize = strlen($data); $security->verifyCompressedData($data, $compressedSize); $data = @gzdecode($data); $uncompressedSize = strlen($data); $security->validateData($data, $uncompressedSize); $json = json_decode($data, true); $security->validateJson($json); if (isset($json['icon'])) { $img = self::getServerIcon($json['icon']); $json['icon'] = $img; $data = json_encode($json); $uncompressedSize = strlen($data); } $key = Util::uuid(false); $cacheFile = Cache::getFile($key); Log::info("Uploaded {$uncompressedSize} bytes as {$key} to {$cacheFile}"); Cache::put($key, $data); header("Location: " . BASE_URL_VIEW . "/?id={$key}"); self::error("Compressed Size: {$compressedSize}\nUncompressed Size: {$uncompressedSize}\nRaw Upload: " . BASE_URL_VIEW . "/?id={$key}&raw=1"); }
public function showAll() { $key = cacheKey('Beneficiaries', 'showAll'); if (Cache::has($key)) { $data = Cache::get($key); } else { $data = array(); $beneficiaries = Auth::user()->beneficiaries()->orderBy('id', 'ASC')->get(); // to get the avg per month we first need the number of months foreach ($beneficiaries as $ben) { $name = Crypt::decrypt($ben->name); $bene = array('id' => intval($ben->id), 'name' => $name); $now = new Carbon('now'); $thisMonth = $ben->transactions()->where(DB::Raw('DATE_FORMAT(`date`,"%m-%Y")'), '=', $now->format('m-Y'))->sum('amount'); $bene['month'] = floatval($thisMonth); $data[] = $bene; } unset($name); $name = array(); // order by alfabet // Obtain a list of columns foreach ($data as $key => $row) { $id[$key] = $row['id']; $name[$key] = $row['name']; } array_multisort($name, SORT_ASC, $id, SORT_DESC, $data); Cache::put($key, $data, 1440); } return View::make('beneficiaries.all')->with('beneficiaries', $data); }
/** * Execute the console command. * * @return mixed */ public function fire() { $size = DB::table('path_records')->sum('size'); Cache::put('statTotalSize', $size, 60); $formatted = DisplaySize::format($size, 2); $this->info($formatted); }
public function store($cacheable) { if (is_null($this->cache_minutes)) { return $this->storeForever($cacheable); } \Cache::put($this->cache_key, $cacheable, $this->cache_minutes); }
/** * Caches a model * * @param string $model The name of the model * @param string $keyPart The key to use to cache the model (e.g. primary key) * @param \App\LaravelRestCms\BaseModel $data The model instance * @return string */ public static function cache($model, $keyPart, $data) { $key = static::getCacheKey($model, $keyPart); \Cache::forget($key); \Cache::put($key, $data, static::$cacheTime); return $model; }
public static function getVersions() { $response = array(); if (UrlUtils::checkRemoteFile('http://www.technicpack.net/api/minecraft', 15)['success']) { $response = UrlUtils::get_url_contents('http://www.technicpack.net/api/minecraft', 15); if ($response['success']) { $response = json_decode($response['data'], true); krsort($response); Cache::put('minecraftversions', $response, 180); return $response; } } if (UrlUtils::checkRemoteFile('https://s3.amazonaws.com/Minecraft.Download/versions/versions.json', 15)['success']) { $response = UrlUtils::get_url_contents('https://s3.amazonaws.com/Minecraft.Download/versions/versions.json', 15); if ($response['success']) { $mojangResponse = json_decode($response['data'], true); $versions = array(); foreach ($mojangResponse['versions'] as $versionEntry) { if ($versionEntry['type'] != 'release') { continue; } $mcVersion = $versionEntry['id']; $versions[$mcVersion] = array('version' => $mcVersion); } krsort($versions); Cache::put('minecraftversions', $versions, 180); return $versions; } } return $response; }
/** * Execute the console command. * * @return mixed */ public function fire() { if (!$this->argument('number')) { return $this->error('No number specified.'); } Cache::put('whatsAppAction_' . $this->argument('number'), 'stop', 5); }
/** * Asks the module to handle a GET (Read) request * * @param $view * @param $args * @return Response */ protected function handleGet($view, $args) { $artist = $view; if (!isset($artist)) { return new Response(array('message' => "The Hive Radio music artist cover API version {$this->VERSION}", 'usage' => "cover/[artist]"), 200); } else { if (\Cache::has("artist_cover_{$artist}")) { return $this->buildImageResponse(\Cache::get("artist_cover_{$artist}")); } else { $youtube_response = file_get_contents("https://www.googleapis.com/youtube/v3/search?q={$artist}&key=" . \Config::get('icebreath.covers.youtube_api_key') . "&fields=items(id(kind,channelId),snippet(thumbnails(medium)))&part=snippet,id"); $youtube_json = json_decode($youtube_response, true); $items = $youtube_json['items']; $youtube_source = null; for ($i = 0; $i < sizeof($items); $i++) { if ((string) $items[$i]["id"]["kind"] != "youtube#channel") { continue; } else { $youtube_source = $items[$i]["snippet"]["thumbnails"]["medium"]["url"]; break; } } if (isset($youtube_source) && !empty($youtube_source)) { $data = file_get_contents($youtube_source); $expiresAt = Carbon::now()->addHours(\Config::get('icebreath.covers.cache_time')); \Cache::put("artist_cover_{$artist}", $data, $expiresAt); return $this->buildImageResponse($data); } return $this->buildImageResponse(\File::get(base_path() . '/' . \Config::get('icebreath.covers.not_found_img'))); } } }
/** * get static data from cache or from remote */ private function get_arrays() { if (Cache::has('stops')) { $sn = Cache::get('stops'); extract($sn); } else { // vars $base_url = 'http://api.hannesv.be/'; $endpoint = 'nmbs/stations.json'; $cache_time = 120; // minutes // get stop names $client = new Client($base_url); $result = $client->get($endpoint)->send()->json(); // start empty $stop_names = array(); $inverted = array(); // loop foreach ($result['stations'] as $station) { $stop_names[(int) $station['sid']] = $station['stop']; $inverted[$station['stop']] = (int) $station['sid']; } // cache result Cache::put('stops', compact('stop_names', 'inverted'), $cache_time); } // return return array($stop_names, $inverted); }
/** * Cache route * * @param Route $route * @param Request $request * @param Response $response */ public function put(Route $route, Request $request, Response $response) { $key = $this->makeCacheKey($request->url()); if (!Cache::has($key)) { Cache::put($key, $response->getContent(), 60); } }
public function get_mails(Request $request) { $mbox = imap_open("{email.mindfiresolutions.com:143}INBOX", "*****@*****.**", "1mfmail2016#") or die("can't connect: " . imap_last_error()); $MC = imap_check($mbox); $count = 0; $count_total = $MC->Nmsgs; $last_page = $count_total % 10; $this->number_of_pages = ($count_total - $last_page) / 10; $this->result = imap_fetch_overview($mbox, "1:{$MC->Nmsgs}", 0); $i = 0; foreach ($this->result as $overview) { $message = imap_fetchbody($mbox, $overview->msgno, 1.1); $this->msg[$i] = $message; $i++; \Cache::put($overview->msgno, $overview->subject, 5); } krsort($this->result); /*This sorting does not help.Please use only rsort.*/ $str[0] = 'success'; $result_json = array(); $result_json['val'] = $this->result; $result_json['num'] = $this->number_of_pages; $result_json['total'] = $count_total; return response()->json($result_json); }
public static function setup($client_id, $client_secret, $podio_username, $podio_password, $options = array('session_manager' => null, 'curl_options' => array())) { // Setup client info self::$client_id = $client_id; self::$client_secret = $client_secret; // Setup curl self::$url = empty($options['api_url']) ? 'https://api.podio.com:443' : $options['api_url']; self::$debug = self::$debug ? self::$debug : false; self::$ch = curl_init(); self::$headers = array('Accept' => 'application/json'); curl_setopt(self::$ch, CURLOPT_RETURNTRANSFER, true); curl_setopt(self::$ch, CURLOPT_SSL_VERIFYPEER, 1); curl_setopt(self::$ch, CURLOPT_SSL_VERIFYHOST, 2); curl_setopt(self::$ch, CURLOPT_USERAGENT, 'Podio PHP Client/' . self::VERSION); curl_setopt(self::$ch, CURLOPT_HEADER, true); curl_setopt(self::$ch, CURLINFO_HEADER_OUT, true); if ($options && !empty($options['curl_options'])) { curl_setopt_array(self::$ch, $options['curl_options']); } if (!Cache::has('podio_oauth')) { self::authenticate_with_password($podio_username, $podio_password); Cache::put('podio_oauth', Podio::$oauth, 480); self::$oauth = Cache::get('podio_oauth'); } // Register shutdown function for debugging and session management register_shutdown_function('Podio::shutdown'); }
public function findByLocale($locale) { if ($this->cacheEnabled) { $data = \Cache::get($this->getLocaleCacheKey($locale)); if (!empty($data)) { return $data; } } $siteConfiguration = SiteConfiguration::whereLocale($locale)->first(); if (!empty($siteConfiguration)) { if ($this->cacheEnabled) { \Cache::put($this->getLocaleCacheKey($locale), $siteConfiguration, $this->cacheLifeTime); } return $siteConfiguration; } $siteConfiguration = SiteConfiguration::whereLocale(\Config::get('app.locale'))->first(); if (!empty($siteConfiguration)) { if ($this->cacheEnabled) { \Cache::put($this->getLocaleCacheKey($locale), $siteConfiguration, $this->cacheLifeTime); } return $siteConfiguration; } $siteConfiguration = SiteConfiguration::orderBy('id', 'asc')->first(); if ($this->cacheEnabled) { \Cache::put($this->getLocaleCacheKey($locale), $siteConfiguration, $this->cacheLifeTime); } return $siteConfiguration; }
public function add_message(Request $request) { if (\Cache::has('addmsg.user.' . $this->user->id)) { return response()->json(['errors' => 'Вы слишком часто отправляете сообщения!']); } \Cache::put('addmsg.user.' . $this->user->id, '', 0.05); //$this->redis->del(self::CHAT_CHANNEL, 5); $gameid = \DB::table('games')->max('id'); $stavki = \DB::table('bets')->where('user_id', '=', $this->user->id)->get(); //$stavki = \DB::table('bets')->where('user_id', '=' , $this->user->id)->where('game_id', '=', $gameid)->get(); if ($this->user->banchat == 1) { return response()->json(['errors' => 'Вы забанены в чате ! Срок : Навсегда']); } $userid = $this->user->steamid64; $admin = $this->user->is_admin; $username = htmlspecialchars($this->user->username); $avatar = $this->user->avatar; $time = date('H:i', time()); $messages = $this->_validateMessage($request); if ($this->user->is_admin == 0) { if ($stavki == null) { return response()->json(['errors' => 'Вы должны поставить ставку чтобы писать в чате']); } //if(strlen($messages) > 0){ //return response()->json(['errors'=>'Чат отключён']); //} } function object_to_array($data) { if (is_array($data) || is_object($data)) { $result = array(); foreach ($data as $key => $value) { $result[$key] = object_to_array($value); } return $result; } return $data; } $words = file_get_contents(dirname(__FILE__) . '/words.json'); $words = object_to_array(json_decode($words)); foreach ($words as $key => $value) { $messages = str_ireplace($key, $value, $messages); } if ($this->user->is_admin == 1) { if (substr_count($messages, '/clear')) { $this->redis->del(self::CHAT_CHANNEL); \DB::table('chat')->delete(); return response()->json(['succes' => 'Вы отчистили чат']); } } if (preg_match("/href|url|http|www|.ru|.com|.net|.info|.org/i", $messages)) { return response()->json(['errors' => 'Ссылки запрещены !']); } $username = htmlspecialchars(preg_replace('/' . \App\Game::zapretsite() . '/i', '', $username)); $returnValue = ['userid' => $userid, 'avatar' => $avatar, 'time' => $time, 'messages' => htmlspecialchars($messages), 'username' => $username, 'admin' => $admin]; $this->redis->rpush(self::CHAT_CHANNEL, json_encode($returnValue)); $this->redis->publish(self::NEW_MSG_CHANNEL, json_encode($returnValue)); return response()->json(['succes' => 'Ваше сообщение отправлено']); }
public function getActivities() { if (!Cache::has('github')) { $activities = $this->activity->forUser('nwidart')->activities(30); Cache::put('github', $activities, 1440); } return Cache::get('github', []); }
public function getTotalUsers() { if (!Cache::has('totalOwlooUsers')) { $data = OwlooUser::count(); Cache::put('totalOwlooUsers', $data, 1440); } return Cache::get('totalOwlooUsers'); }
/** * 保存access token */ public static function putAccessTokenIntoCache($token, $user_id = null) { if ($user_id == null) { Cache::put('cheshang_access_token', $token, self::CACHE_EXPIRED); } else { Cache::put("cheshang_access_token_user_{$user_id}", $token, self::CACHE_EXPIRED); } }
public static function set($key, $value) { $setting = Setting::firstOrNew(['key' => $key]); $setting->key = $key; $setting->value = $value; Cache::put($key, $value, self::$expireTime); return $setting->save(); }
/** * {@inheritdoc} */ public function redirect() { /** @type TemporaryCredentials $temp */ $temp = $this->server->getTemporaryCredentials(); $identifier = $temp->getIdentifier(); \Cache::put($identifier, $temp, 3); return new RedirectResponse($this->server->getAuthorizationUrl($temp)); }
/** * {@inheritdoc} */ public function redirect() { $state = null; if ($this->usesState()) { $state = Str::random(40); \Cache::put($state, $state, 3); } return new RedirectResponse($this->getAuthUrl($state)); }
function option($key, $default = '') { $options = Cache::get('options'); if (!array_get($options, $key)) { Cache::put('options', \App\Model\Option::all()->lists('value', 'key'), config('app.option_exp', 10)); $options = Cache::get('options'); } return array_get($options, $key, $default); }
public function sendSMS($mobile) { $verifyCode = mt_rand(100000, 999999); \Cache::put($mobile . 'VerifyCode', $verifyCode, 30); $postArr = ['apikey' => $this->apikey, 'text' => urlencode($this->sendText . $verifyCode), 'mobile' => $mobile]; $options = array('headers' => array('Accept:application/json;charset=utf-8;', 'Content-Type:application/x-www-form-urlencoded;charset=utf-8;'), 'strings' => true); $response = $this->http->post($this->sendUrl, $postArr, $options); return $response['data']; }
/** * Handle an incoming request. * * @param \Illuminate\Http\Request $request * @param \Closure $next * @return mixed */ public function handle($request, Closure $next) { $response = $next($request); $key = $this->makeCacheKey($request); if (!\Cache::has($key)) { \Cache::put($key, $response->getContent(), 1); } return $response; }
public function setUp() { parent::setUp(); Cache::flush(); Cache::put('queue-checker-job-value', 0, 60); Cache::put('queue-checker-command-value', 2, 60); $command = new QueueCheckerResetCommand(); $this->tester = new CommandTester($command); }
public function getHome() { $key = cacheKey('home', Session::get('period')); if (Cache::has($key)) { $data = Cache::get($key); } else { $max = 0; $min = 1000000; $data = array('accounts' => array(), 'budgets' => array(), 'targets' => array()); // we need this list: $accounts = Auth::user()->accounts()->get(); foreach ($accounts as $a) { $account = array('id' => intval($a->id), 'name' => Crypt::decrypt($a->name), 'currentbalance' => $a->balance()); $account['header'] = $account['currentbalance'] < 0 ? array('style' => 'color:red;', 'class' => 'tt', 'title' => $account['name'] . ' has a balance below zero. Try to fix this.') : array(); $min = $account['currentbalance'] < $min ? $account['currentbalance'] : $min; $max = $account['currentbalance'] > $max ? $account['currentbalance'] : $max; $data['accounts'][] = $account; } $min = $min > 0 ? 0 : $min; $max = $max < 0 ? 0 : $max; $min = floor($min / 1000) * 1000; $max = ceil($max / 1000) * 1000; $sum = 0; foreach ($data['accounts'] as $index => $account) { $sum += $account['currentbalance']; } $data['acc_data']['sum'] = $sum; // now everything for budgets: $data['budgets'] = Budget::getHomeOverview(); // some extra budget data: $monthlyAmount = Setting::getSetting('monthlyAmount', Session::get('period')->format('Y-m-') . '01'); if (is_null($monthlyAmount)) { $monthlyAmount = intval(Setting::getSetting('defaultAmount')); } $data['budget_data']['amount'] = $monthlyAmount; $data['budget_data']['spent_outside'] = floatval(Auth::user()->transactions()->where('amount', '<', 0)->whereNull('budget_id')->where(DB::Raw('DATE_FORMAT(`date`,"%m-%Y")'), '=', Session::get('period')->format('m-Y'))->sum('amount')) * -1; // targets, cant make it better im afraid. $data['targets'] = Target::getHomeOverview(); Cache::put($key, $data, 2440); } // flash some warnings: if (Auth::user()->transactions()->count() == 0) { Session::flash('warning', 'There are no transactions saved yet. Create some to make this overview less boring (Create → New transaction).'); } if (count($data['budgets']) == 0) { Session::flash('warning', 'You don\'t have any budgets defined.'); } if (count($data['accounts']) == 0) { Session::flash('warning', 'You do not have any accounts added. You should do this first (Create → New account)'); } if (Holmes::isMobile()) { return View::make('mobile.home.home')->with('data', $data); } else { return View::make('home.home')->with('data', $data); } }
public function testErrorHandlingWhenCommandValueBiggerAsJobValue() { $errorHandlerMock = m::mock('Schickling\\QueueChecker\\ErrorHandlers\\ErrorHandlerInterface'); $errorHandlerMock->shouldReceive('handle'); $this->app->instance('Schickling\\QueueChecker\\ErrorHandlers\\ErrorHandlerInterface', $errorHandlerMock); Cache::put('queue-checker-command-value', 3, 0); Cache::put('queue-checker-job-value', 2, 0); Queue::shouldReceive('connected')->once()->andReturn(true); $this->tester->execute(array()); }
public static function getChans() { if (Cache::has('chans')) { $chans = Cache::get('chans'); } else { $chans = self::chanStat(); Cache::put('chans', $chans, 120); } return $chans; }
public static function getGroups() { if (Cache::has('groups')) { $groups = Cache::get('groups'); } else { $groups = self::statGroups(); Cache::put('groups', $groups, 120); } return $groups; }
/** * @test */ public function test_clear_all_removes_all_in_tag() { \Cache::put('original', 'original', 60); $this->repo->put('key', 'value', 60); $this->repo->put('key2', 'value', 60); $this->repo->clear(); $this->assertNull($this->repo->get('key')); $this->assertNull($this->repo->get('key2')); $this->assertEquals('original', \Cache::get('original')); }
/** * @param string $content */ public function setCacheFromContent($content) { if ($this->option['cache-static-content'] === true) { /** * 0 as minutes stores forever */ $this->cache->put('content-' . $this->entity, $content, $this->option('timeout')); } $this->setETagFromContent($content); }