Esempio n. 1
0
 /**
  * @param Query $query
  * @return Result|null
  */
 private function get($query)
 {
     if (!$this->cache) {
         return null;
     } elseif (!($serialized = $this->cache->get($query->getHashKey()))) {
         return null;
     }
     return unserialize($serialized);
 }
 /**
  * @inheritdoc
  */
 public function handle($arguments)
 {
     if (!Cache::has('site-' . $arguments)) {
         $this->replyWithMessage("Não foi encontrado nenhum site com esse argumento.");
         return;
     }
     $site = Cache::get('site-' . $arguments);
     // Validate if the URL isn't on the database yet
     if (Site::where('url', '=', $site)->first() != null) {
         $this->replyWithMessage("O site {$site} já se encontra na base de dados.");
         return;
     }
     $site_obj = new Site();
     $site_obj->url = $site;
     $site_obj->save();
     $this->replyWithMessage($site . " foi adicionado à base de dados.", true);
     // Notify the sitesbloqueados.pt about the new site
     $url = 'https://sitesbloqueados.pt/wp-json/ahoy/refresh';
     $cmd = "curl -X GET -H 'Content-Type: application/json'";
     $cmd .= " " . "'" . $url . "'";
     $cmd .= " > /dev/null 2>&1 &";
     exec($cmd, $output);
     // Flush the PAC cache
     Cache::tags(['generate_pac'])->flush();
     // Remove the cache
     Cache::forget('site-' . $arguments);
     Cache::forget('site-list');
 }
Esempio n. 3
0
 /**
  * @throws \Exception
  */
 public function handle()
 {
     $name = $this->argument('name');
     $isUserRestrict = $this->confirm('User restricted ?', false);
     $author = $this->ask("Your username", Cache::get('developer.username', ''));
     Cache::forever('developer.username', $author);
     $generator = new Generator($name, $isUserRestrict, $author);
     $templateData = $generator->getTemplateData();
     $files = $generator->getFiles();
     $belongToRelations = $this->getRelation('BelongTo');
     if ($isUserRestrict) {
         $belongToRelations[] = 'user';
     }
     $belongToRelations = array_unique($belongToRelations);
     $manyToManyRelations = $this->getRelation('ManyToMany');
     $manyToManyRelations = array_unique($manyToManyRelations);
     $fields = $this->getFields();
     $this->summary($templateData, $isUserRestrict);
     $this->fieldsSummary($fields);
     $this->generate($generator, $fields, ['belongTo' => $belongToRelations, 'manyToMany' => $manyToManyRelations]);
     $this->runComposerDumpAutoload();
     $this->migrateDatabase();
     $this->generateDocumentation();
     $this->info("");
     $this->info("What you need to do now ?");
     $this->info("\t [] Add Acl/Scope to your route in routes.php");
     $this->info("\t [] Fill data provider for " . $files['controllerTest']);
     $this->info("\t [] Fill data provider for " . $files['repositoryTest']);
 }
 private function _fetchDataset($filter)
 {
     return Cache::get($this->key, function () use($filter) {
         Cache::add($this->key, $data = $this->_getDataPartialRecursive($filter), 60);
         return $data;
     });
 }
Esempio n. 5
0
 /**
  * Return a simple list of entries in the table.
  *
  * May cache the results for up to 60 minutes.
  *
  * @return	array of Fluent objects
  */
 public static function tableToArray()
 {
     $me = new static();
     $cache_key = $me->cacheKey();
     // Return the array from the cache if it is present.
     if (Cache::has($cache_key)) {
         return (array) Cache::get($cache_key);
     }
     // Otherwise put the results into the cache and return them.
     $results = [];
     $query = static::all();
     // If the current model uses softDeletes then fix the
     // query to exclude those objects.
     foreach (class_uses(__CLASS__) as $traitName) {
         if ($traitName == 'SoftDeletes') {
             $query = static::whereNull('deleted_at')->get();
             break;
         }
     }
     /** @var Cacheable $row */
     foreach ($query as $row) {
         $results[$row->getIndexKey()] = $row->toFluent();
     }
     Cache::put($cache_key, $results, 60);
     return $results;
 }
Esempio n. 6
0
 /**
  * Returns cached data
  *
  * @param  string  $key
  * @return mixed
  */
 public static function get($key)
 {
     if (!isset(static::$cache[$key])) {
         static::$cache[$key] = parent::get($key);
     }
     return static::$cache[$key];
 }
Esempio n. 7
0
 /**
  * Returns the current cached items assembly if
  * it exists inside the cache. Returns false
  * otherwise.
  *
  * @return bool|\Illuminate\Database\Eloquent\Collection
  */
 public function getCachedAssemblyItems()
 {
     if ($this->hasCachedAssemblyItems()) {
         return Cache::get($this->getAssemblyCacheKey());
     }
     return false;
 }
Esempio n. 8
0
 /**
  * Check the token
  *
  * @param   string  $token
  * @return  boolean
  */
 public function check($token)
 {
     if (!Cache::has($this->getCacheKey())) {
         return false;
     }
     return Cache::get($this->getCacheKey()) === $token;
 }
Esempio n. 9
0
 public function isAdmin()
 {
     if (Cache::has('role.' . Auth::id()) && Cache::get('role.' . Auth::id()) === 'admin') {
         return true;
     }
     return false;
 }
Esempio n. 10
0
 /**
  * Handle an incoming request.
  *
  * @param  \Illuminate\Http\Request $request
  * @param  \Closure $next
  * @return mixed
  */
 public function handle($request, Closure $next)
 {
     if (Cache::get('role.' . Auth::id()) == 'admin') {
         return $next($request);
     }
     abort(404);
 }
 /**
  * Bind data to the view.
  *
  * @param  View  $view
  * @return void
  */
 public function compose(View $view)
 {
     if (!Cache::get('popular_categories')) {
         Cache::put('popular_categories', $this->categories->getPopular(), 60);
     }
     $view->with('popular_categories', Cache::get('popular_categories'));
 }
Esempio n. 12
0
 public function fetch(Route $route, Request $request)
 {
     $key = self::makeCacheKey($request->url());
     if (Cache::has($key)) {
         return Cache::get($key);
     }
 }
 /**
  * Bind data to the view.
  *
  * @param  View  $view
  * @return void
  */
 public function compose(View $view)
 {
     if (!Cache::get('recent_posts')) {
         Cache::put('recent_posts', $this->posts->getAll('published', null, 'published_at', 'desc', 5), 10);
     }
     $view->with('recent_posts', Cache::get('recent_posts'));
 }
 /**
  * @return string
  */
 protected function getTimestampMigrationName()
 {
     if (!Cache::has(static::CACHENAME)) {
         Cache::forever(static::CACHENAME, date('Y_m_d_His') . '_' . $this->getMigrationName());
     }
     return Cache::get(static::CACHENAME);
 }
Esempio n. 15
0
 /**
  * Determine the current website data.
  *
  * Returns null if the web site is not found in the websites table.
  *
  * @return	array
  */
 public static function currentWebsiteData()
 {
     static $current_data;
     $BASE_URL = static::currentServerName();
     $cache_key = 'website-data.' . $BASE_URL;
     // Get the current ID from the cache if it is present.
     if (empty($current_data)) {
         if (Cache::has($cache_key)) {
             return Cache::get($cache_key);
         }
     }
     // If the cache doesn't have it then get it from the database.
     if (empty($current_data)) {
         // Have to do this using a raw query because Laravel doesn't INSTR.
         try {
             /** @var Website $result */
             $result = static::whereRaw("INSTR('" . $BASE_URL . "', `http_host`) > 0")->orderBy(DB::raw('LENGTH(`http_host`)'), 'desc')->first();
             if (empty($result)) {
                 $current_data = null;
             } else {
                 $current_data = $result->toArray();
             }
             Cache::put($cache_key, $current_data, 60);
         } catch (\Exception $e) {
             $current_data = null;
         }
     }
     return $current_data;
 }
Esempio n. 16
0
 public function prettifyOnlineStatus($presence, $accounts)
 {
     $key = 'online_status';
     if (Cache::has($key)) {
         return Cache::get($key);
     } else {
         $user_string = '<strong>Online Status</strong><br/>';
         $found = false;
         foreach ($presence as $seo => $response) {
             $data = json_decode($response->getBody(), true);
             if (isset($data['state']) && $data['state'] == "Online") {
                 foreach ($data['devices'] as $device) {
                     if ($device['type'] == "XboxOne") {
                         foreach ($device['titles'] as $title) {
                             if (in_array($title['id'], $this->acceptedGameIds)) {
                                 $found = true;
                                 $gt = $accounts->where('seo', $seo)->first();
                                 $user_string .= "<strong>" . $gt->gamertag . ": </strong>" . $title['name'];
                                 if (isset($title['activity'])) {
                                     $user_string .= " (" . $title['activity']['richPresence'] . ")";
                                 }
                                 $user_string .= "<br/>";
                             }
                         }
                     }
                 }
             }
         }
         if (!$found) {
             $user_string = 'No-one is online. Pity us.';
         }
         Cache::put($key, $user_string, 5);
         return $user_string;
     }
 }
 public function show()
 {
     $options = Config::get('onepager.options');
     $progressBar = Cache::get('progressBar', function () {
         $c = curl_init('https://www.startnext.com/sanktionsfrei/widget/?w=200&amp;h=300&amp;l=de');
         curl_setopt($c, CURLOPT_RETURNTRANSFER, true);
         $html = curl_exec($c);
         if (curl_error($c)) {
             die(curl_error($c));
         }
         $status = curl_getinfo($c, CURLINFO_HTTP_CODE);
         curl_close($c);
         $percent = 0;
         if ($status == 200) {
             $crawler = new Crawler();
             $crawler->addHTMLContent($html, 'UTF-8');
             // get the percentage for the progressbar
             $styleString = $crawler->filter('.bar.bar-1')->attr('style');
             $stringArray = explode(':', $styleString);
             $percent = substr($stringArray[1], 0, -2);
             // get the text for the progressbar
             $textArray = $crawler->filter('.status-text span')->extract(['_text']);
         }
         return ['percent' => $percent, 'progressText' => $textArray[0]];
     }, 5);
     return view('home', ['options' => $options, 'percent' => $progressBar['percent'], 'progressText' => $progressBar['progressText']]);
 }
Esempio n. 18
0
 public function update($id)
 {
     try {
         $groups = Cache::get('admin.adkats.special.groups');
         $player = Special::findOrFail($id);
         foreach ($groups as $group) {
             if ($group['group_key'] == Input::get('group')) {
                 $newGroup = $group['group_name'];
                 break;
             }
         }
         $player->player_group = Input::get('group');
         $player->save();
         if (is_null($player->player)) {
             $soldierName = $player->player_identifier;
         } else {
             $soldierName = $player->player->SoldierName;
         }
         $message = sprintf('%s group has been changed to %s.', $soldierName, $newGroup);
         return MainHelper::response(null, $message);
     } catch (ModelNotFoundException $e) {
         $message = sprintf('No player found with special id of %u', $id);
         return MainHelper::response(null, $message, 'error', 404);
     } catch (Exception $e) {
         return MainHelper::response($e, $e->getMessage(), 'error', 500);
     }
 }
Esempio n. 19
0
 public function mtime()
 {
     if (Cache::has('mtime:' . $this->name)) {
         return Cache::get('mtime:' . $this->name);
     }
     return FALSE;
 }
Esempio n. 20
0
 public function render($format = 'atom', $cache = FALSE, $cacheTime = 3600)
 {
     $channel = $this->channel;
     $channel->pubdate = $this->formatDate($this->channel->pubdate, $format);
     $items = $this->items;
     foreach ($items as $item) {
         $item->pubdate = $this->formatDate($item->pubdate, $format);
     }
     if ($format == 'atom') {
         $this->content_type = 'application/atom+xml';
     } else {
         $this->content_type = 'application/rss+xml';
     }
     if ($cache == TRUE && Cache::has('feed-' . $format)) {
         return response()->view('feed::' . $format, Cache::get('feed-' . $format))->header('Content-Type', $this->content_type)->header('Content-Type', 'text/xml');
     } elseif ($cache == TRUE) {
         Cache::put('feed-' . $format, compact('channel', 'items'), $cacheTime);
         return response()->view('feed::' . $format, compact('channel', 'items'))->header('Content-Type', $this->content_type)->header('Content-Type', 'text/xml');
     } elseif ($cache == FALSE && Cache::has('feed-' . $format)) {
         Cache::forget('feed-' . $format);
         return response()->view('feed::' . $format, compact('channel', 'items'))->header('Content-Type', $this->content_type)->header('Content-Type', 'text/xml');
     } else {
         return response()->view('feed::' . $format, compact('channel', 'items'))->header('Content-Type', $this->content_type)->header('Content-Type', 'text/xml');
     }
 }
 /**
  * @param $identifier
  */
 public function restore($identifier)
 {
     $carts = LaravelCacheStorage::get($this->cachePrefix . $identifier);
     if ($carts) {
         static::$cart = $carts;
     }
 }
 public function get($key)
 {
     if (Cache::has($key)) {
         return Cache::get($key);
     }
     return false;
 }
 /**
  * Fetch the stored config from the cache.
  *
  * @return mixed
  */
 public function fetchConfig()
 {
     if (Cache::has($this->getCacheKey())) {
         return Cache::get($this->getCacheKey());
     }
     return null;
 }
Esempio n. 24
0
 protected static function getAccounts()
 {
     if (!($accounts = Cache::get('vk:accounts'))) {
         $accounts = config('vkapi.accounts');
         Cache::put('vk:accounts', $accounts, Carbon::now()->addMinutes(30));
     }
     return $accounts;
 }
Esempio n. 25
0
 public function getName()
 {
     $result = Cache::get('tattler:users:' . $this->userName);
     if ($result) {
         return $result;
     }
     //throw new \Exception('User\'s socket not found');
 }
Esempio n. 26
0
 /**
  * 验证码是否一致
  * @param string $phone 电话号码
  * @param string $captcha 验证码
  * @return bool
  */
 public static function checkCaptcha($phone, $captcha)
 {
     $captcha_service = Cache::get($phone);
     if ($captcha != $captcha_service) {
         return true;
     }
     return false;
 }
Esempio n. 27
0
 private function verifyNewChallenge($latestChallenge)
 {
     $lastChallengeSent = Cache::get('last_challenge_sent');
     if ($lastChallengeSent) {
         return $lastChallengeSent->published_at != $latestChallenge->published_at;
     }
     return true;
 }
Esempio n. 28
0
 public function __construct()
 {
     //初始化缓存
     //Event::fire('cache.init');
     //获取配置
     $this->initConfig();
     View::share('setting', Cache::get('setting'));
 }
Esempio n. 29
0
 public function getStatsForStudent($studentId)
 {
     $stats = Cache::get('stats_' . $studentId);
     if ($stats) {
         return response(['stats' => $stats], 200);
     }
     return response(null, 400);
 }
Esempio n. 30
0
 public static function remember($key, $callback)
 {
     if (!Cache::has($key)) {
         $value = $callback();
         Cache::put($key, $value, 60);
     }
     return Cache::get($key);
 }