Exemple #1
0
 /**
  * @param array|bool $dataAcl
  * @dataProvider aclDataProvider
  */
 public function testHasWithAcl($dataAcl)
 {
     $this->initAcl(is_array($dataAcl) ? serialize($dataAcl) : $dataAcl);
     $this->cacheConfig->expects($this->never())->method('test');
     $this->model->get();
     $this->assertTrue($this->model->has());
 }
Exemple #2
0
 /**
  * Take a project key and return the properties
  *
  * @param string $identifier
  * @return array
  */
 public function project($identifier)
 {
     if (!$this->cache->has($identifier)) {
         $html = $this->fetch($identifier);
         $project = $this->parse($html);
         $this->cache->set($identifier, $project, $this->expiry);
     }
     return $this->cache->get($identifier);
 }
 public function testGetHasExisting()
 {
     $this->cache->set("foo", "bar");
     $this->assertEquals("bar", $this->cache->get("foo"));
     $this->assertTrue($this->cache->has("foo"));
     //test if cache has been written
     $this->cache->writeCache()->flush(true);
     $this->assertEquals("bar", $this->cache->get("foo"));
 }
 public function embed_gists($content)
 {
     $gists_regex = '/<script[^>]+src="(http:\\/\\/gist.github.com\\/[^"]+)"[^>]*><\\/script>/i';
     // remove gists from multiple-post templates
     if (Options::get('gistextras__removefrommultiple')) {
         if (!in_array(URL::get_matched_rule()->name, array('display_entry', 'display_page'))) {
             return preg_replace($gists_regex, '', $content);
         }
     }
     preg_match_all($gists_regex, $content, $gists);
     for ($i = 0, $n = count($gists[0]); $i < $n; $i++) {
         if (Options::get('gistextras__cachegists')) {
             if (Cache::has($gists[1][$i])) {
                 $gist = Cache::get($gists[1][$i]);
             } else {
                 if ($gist = RemoteRequest::get_contents($gists[1][$i])) {
                     $gist = $this->process_gist($gist);
                     Cache::set($gists[1][$i], $gist, 86400);
                     // cache for 1 day
                 }
             }
         } else {
             $gist = RemoteRequest::get_contents($gists[1][$i]);
             $gist = $this->process_gist($gist);
         }
         // replace the script tag
         $content = str_replace($gists[0][$i], $gist, $content);
     }
     return $content;
 }
 public function get_exchange_rates()
 {
     //		\Cache::forget('money_exchange_rates');
     if (\Cache::has('money_exchange_rates')) {
         $data = \Cache::get('money_exchange_rates');
     } elseif (is_connected("openexchangerates.org")) {
         $api_key = "bbc128aa6f3645d78b098f0eef3dd533";
         $json = file_get_contents("http://openexchangerates.org/api/latest.json?app_id={$api_key}");
         $json = json_decode($json, true);
         $data['rates'] = $json['rates'];
         $data['base'] = $json['base'];
         // $data['json_rates'] = json_encode($json['rates']);
         \Cache::add('money_exchange_rates', $data, 360);
         \Cache::add('money_exchange_rates_default', $data, 50000);
     } else {
         $data = \Cache::get('money_exchange_rates_default');
     }
     $currency_list = \Lst::common('currency1');
     $arr["site_name"] = "Ahmed-Badawy.com";
     $arr["base"] = $data['base'];
     foreach ($currency_list as $key => $val) {
         $n = ['short' => $key, "name" => $val, "value" => $data['rates'][$key]];
         $arr['rates'][$key] = $n;
     }
     return $arr;
 }
 public function get($id, $elequent)
 {
     $cacheKey = self::CACHE . $id;
     if ($elequent) {
         return Email::find($id);
     }
     $cachedData = \Cache::has($cacheKey);
     if (empty($cachedData)) {
         $email = Email::find($id);
         if (!empty($email)) {
             $email = $email->toArray();
             $email['updated_at'] = date('Y-m-d', strtotime($email['updated_at']));
             $email['created_at_formatted'] = date('Y-m-d', strtotime($email['created_at']));
             $email['updated_at_formatted'] = date('Y-m-d', strtotime($email['updated_at']));
             // unset($country['password']);
             //unset($country['code']);
             // Set data in cache
             \Cache::forever($cacheKey, $email);
             return $email;
         } else {
             return false;
         }
     } else {
         return \Cache::get($cacheKey);
     }
 }
Exemple #7
0
 /**
  * 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);
 }
Exemple #8
0
 /**
  * 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);
     }
 }
Exemple #9
0
 public function generate($args)
 {
     if (count($args) != 1) {
         die(self::$usageMessage);
     }
     $model = $args[0];
     $table = Str::plural(Str::lower($model));
     $options = array('Model' => $model, 'Table' => $table, 'DefaultField' => 'text', 'ParentID' => 'parent_id', 'Leaf' => 'leaf');
     $r = new ReflectionClass($model);
     preg_match_all('#@(.*?)\\n#s', $r->getDocComment(), $annotations);
     if (!empty($annotations)) {
         foreach ($annotations[0] as $annotation) {
             preg_match('#@(?P<name>\\w+)[ ]*(\\([ ]*(?P<value>\\w+)[ ]*\\))?\\n#s', $annotation, $a);
             if (array_key_exists($a['name'], $options)) {
                 $options[$a['name']] = $a['value'];
             }
         }
     }
     $columns = DB::query('SHOW columns from ' . $table);
     if (Cache::has('ext' . $model, $columns)) {
         $was_cached = true;
     } else {
         Cache::forever('ext' . $model, $columns);
         $was_cached = false;
     }
     // Generate code
     $this->generateExtModel($columns, $model, $options);
     $this->generateGrid($columns, $model, $options, $was_cached);
     $this->generateForm($columns, $model, $options, $was_cached);
     $this->generateTree($model, $options, $was_cached);
     /**************************************************************/
     echo 'Task executed successfully';
 }
Exemple #10
0
   /**
    * Generate the widget and return it as string
    *
    * @return string
    */
   public function generate()
   {
       $arrButtons = array('copy', 'delete', 'drag');
       // Make sure there is at least an empty array
       if (!is_array($this->varValue) || empty($this->varValue)) {
           $this->varValue = array('');
       }
       // Initialize the tab index
       if (!\Cache::has('tabindex')) {
           \Cache::set('tabindex', 1);
       }
       $return = '<ul id="ctrl_' . $this->strId . '" class="tl_listwizard">';
       // Add input fields
       for ($i = 0, $c = count($this->varValue); $i < $c; $i++) {
           $return .= '
   <li><input type="text" name="' . $this->strId . '[]" class="tl_text" value="' . \StringUtil::specialchars($this->varValue[$i]) . '"' . $this->getAttributes() . '> ';
           // Add buttons
           foreach ($arrButtons as $button) {
               if ($button == 'drag') {
                   $return .= ' <button type="button" class="drag-handle" title="' . \StringUtil::specialchars($GLOBALS['TL_LANG']['MSC']['move']) . '">' . \Image::getHtml('drag.svg') . '</button>';
               } else {
                   $return .= ' <button type="button" data-command="' . $button . '" title="' . \StringUtil::specialchars($GLOBALS['TL_LANG']['MSC']['lw_' . $button]) . '">' . \Image::getHtml($button . '.svg') . '</button>';
               }
           }
           $return .= '</li>';
       }
       return $return . '
 </ul>
 <script>Backend.listWizard("ctrl_' . $this->strId . '")</script>';
   }
Exemple #11
0
 /**
  * Search for movie title
  *
  * @param string $q The search query
  *
  * @return Response
  */
 public function searchTitle($q)
 {
     // init result array
     $result = array();
     // trim query
     $q = trim($q);
     // create slug from query
     $q_slug = str_slug('imdb-' . $q);
     // check if search is in cache
     if (\Cache::has($q_slug)) {
         // retrieve item from cache
         $item = \Cache::get($q_slug);
         // add data to array
         $result = array('fromcache' => true, 'data' => $item);
     } else {
         // url encode query
         $q = urlencode($q);
         // Use the Imdb Api to search for movie
         $imdbResult = json_decode(file_get_contents(sprintf(env('IMDB_SEARCH_TITLE_URL'), $q)));
         // only proceed if the most popular title array is filled and at least contains 1 movie
         if (isset($imdbResult->title_popular) && is_array($imdbResult->title_popular) && count($imdbResult->title_popular) > 0) {
             // extract year from title_description
             $year = intval(substr($imdbResult->title_popular[0]->title_description, 0, 4));
             // create object for this movie
             $item = new ImdbMovie($imdbResult->title_popular[0]->id, $imdbResult->title_popular[0]->title, $year);
             // add item to cache for a year
             \Cache::add($q_slug, $item, 60 * 24 * 365);
             // add data to array
             $result = array('fromcache' => false, 'data' => $item);
         }
     }
     // return json formatted response
     return response()->json($result);
 }
 function action_add_template_vars($theme)
 {
     $username = Options::get('freshsurf__username');
     $password = Options::get('freshsurf__password');
     $count = Options::get('freshsurf__count');
     if ($username != '' && $password != '') {
         if (Cache::has('freshsurf__' . $username)) {
             $response = Cache::get('freshsurf__' . $username);
         } else {
             $request = new RemoteRequest("https://{$username}:{$password}@" . self::BASE_URL . "posts/recent?count={$count}", 'GET', 20);
             $request->execute();
             $response = $request->get_response_body();
             Cache::set('freshsurf__' . $username, $response);
         }
         $delicious = @simplexml_load_string($response);
         if ($delicious instanceof SimpleXMLElement) {
             $theme->delicious = $delicious;
         } else {
             $theme->delicious = @simplexml_load_string('<posts><post href="#" description="Could not load feed from delicious.  Is username/password correct?"/></posts>');
             Cache::expire('freshsurf__' . $username);
         }
     } else {
         $theme->delicious = @simplexml_load_string('<posts></posts>');
     }
 }
Exemple #13
0
 public function render()
 {
     $key = md5($this->getPath());
     $lastModified = $this->files->lastModified($this->getPath());
     $generate = false;
     if ($lastModifiedCache = \Cache::get("{$key}.lastmodified", false) !== false && \Cache::has($key)) {
         if ($lastModified !== $lastModified) {
             $generate = true;
         }
     } else {
         $generate = true;
     }
     if (config('app.debug')) {
         $generate = true;
     }
     $rendered = '';
     if ($generate === true) {
         $rendered = $this->parser->parse($this->files->get($this->getPath()));
         \Cache::forever($key, $rendered);
         \Cache::forever("{$key}.lastmodified", $lastModified);
     } else {
         $rendered = \Cache::get($key, false);
     }
     return $rendered;
 }
Exemple #14
0
 /**
  * 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')));
         }
     }
 }
 public function SitemapBuild()
 {
     //return cached sitemap if exsist
     if (Cache::has('sitemap')) {
         $xml = Cache::get('sitemap');
     } else {
         $types = Options::get_group(__CLASS__);
         //..or generate a new one
         $xml = '<?xml version="1.0" encoding="UTF-8"?><?xml-stylesheet type="text/xsl" href="' . $this->get_url() . '/sitemap.xsl"?><urlset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd" xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"></urlset>';
         $xml = new SimpleXMLElement($xml);
         if (array_key_exists('any', $types) && $types['any'] || empty($types)) {
             // Retrieve all published content, regardless of the type
             $content['any'] = Posts::get(array('content_type' => 'any', 'status' => 'published', 'nolimit' => 1));
         } else {
             // Retreive all published content for select content types
             $content['posts'] = Posts::get(array('content_type' => array_keys($types, 1), 'status' => 'published', 'nolimit' => 1));
         }
         // Add the index page first
         $url = $xml->addChild('url');
         $url_loc = $url->addChild('loc', Site::get_url('habari'));
         // Generate the `<url>`, `<loc>`, `<lastmod>` markup for each post and page.
         foreach ($content as $entries) {
             foreach ($entries as $entry) {
                 $url = $xml->addChild('url');
                 $url_loc = $url->addChild('loc', $entry->permalink);
                 $url_lastmod = $url->addChild('lastmod', $entry->updated->get('c'));
             }
         }
         $xml = $xml->asXML();
         Cache::set('sitemap', $xml);
     }
     return $xml;
 }
Exemple #16
0
 /**
  * Get cached data.
  *
  * @param string $index
  *
  * @return bool|array
  */
 public function getCache($index)
 {
     if (\Cache::has($index)) {
         return unserialize(\Cache::get($index));
     }
     return false;
 }
Exemple #17
0
 /**
  * Fetch setting
  *
  * @param $key
  * @return null
  */
 public function get($key)
 {
     /**
      * Setup cache key
      */
     $cacheKey = 'setting_' . md5($key);
     /**
      * Check if in cache
      */
     if (\Cache::has($cacheKey)) {
         return \Cache::get($cacheKey);
     }
     /**
      * Fetch from database
      */
     $setting = Setting::where('key', '=', $key)->first();
     /**
      * If a row was found, return the value
      */
     if (is_object($setting) && $setting->getId()) {
         /**
          * Store in cache
          */
         \Cache::forever($cacheKey, $setting->getValue());
         /**
          * Return the data
          */
         return $setting->getValue();
     }
     return null;
 }
 public static function get_stat($type, $month = NULL)
 {
     $str = 'chicklet_stat_' . $type;
     if ($month != NULL) {
         $str .= '_' . $month;
     }
     if (Cache::has($str)) {
         return Cache::get($str);
     }
     switch ($type) {
         case 'entries':
         case 'posts':
             $params = array('content_type' => array(Post::type('entry'), Post::type('link')), 'nolimit' => TRUE);
             $stat = count(Posts::get($params));
             break;
         case 'subscribers':
             $stat = self::fetch();
             break;
         case 'comments':
             $stat = Comments::count_total(Comment::STATUS_APPROVED);
             break;
         case 'tags':
             $stat = count(Tags::vocabulary()->get_tree());
             break;
         default:
             $stat = 0;
             break;
     }
     Cache::set($str, $stat);
     return $stat;
 }
Exemple #19
0
 private function _setModuleList()
 {
     if (\Cache::has('modules.backend.list')) {
         $this->_moduleList = \Cache::get('modules.backend.list');
         return;
     }
     $moduleDir = app_path() . '/../modules/';
     $result = array();
     if ($handle = opendir($moduleDir)) {
         while (false !== ($dir = readdir($handle))) {
             if ($dir != '.' && $dir != '..') {
                 if (is_dir($moduleDir . $dir)) {
                     $backendData = false;
                     if (file_exists($moduleDir . $dir . '/backend.json')) {
                         $backendData = json_decode(file_get_contents($moduleDir . $dir . '/backend.json'));
                     }
                     $result[] = ['name' => $dir, "dir" => $moduleDir . $dir, 'backend' => $backendData];
                 }
             }
         }
         closedir($handle);
     }
     $this->_moduleList = $result;
     \Cache::forever('modules.backend.list', $result);
 }
 public function getProfile($username)
 {
     $var_cache = 'instagramProfile' . $username;
     if (!Cache::has($var_cache)) {
         $data = InstagramProfile::whereUsername($username)->first();
         if ($data) {
             $profile = NULL;
             $profile['username'] = strtolower($data['username']);
             $profile['name'] = $data['name'];
             $profile['bio'] = $data['bio'];
             $profile['website'] = $data['website'];
             $profile['picture'] = str_replace('_normal.', '.', $data['picture']);
             $auxformat = explode("-", $data['in_owloo_from']);
             $year = $auxformat[0];
             $day = $auxformat[2];
             $month = strtolower($this->getMonth($auxformat[1], 'large'));
             $profile['in_owloo_from'] = $day . ' ' . $month . ' ' . $year;
             $profile['followed_by_count'] = $this->owloo_number_format($data['followed_by_count']);
             $profile['follows_count'] = $this->owloo_number_format($data['follows_count']);
             $profile['media_count'] = $this->owloo_number_format($data['media_count']);
             $profile['followed_by_history_30'] = json_decode($data['followed_by_history_30'], true);
             $profile['followed_by_grow']['grow_1'] = $this->formatGrow($data['followed_by_grow_1'], $data['followed_by_count']);
             $profile['followed_by_grow']['grow_7'] = $this->formatGrow($data['followed_by_grow_7'], $data['followed_by_count']);
             $profile['followed_by_grow']['grow_15'] = $this->formatGrow($data['followed_by_grow_15'], $data['followed_by_count']);
             $profile['followed_by_grow']['grow_30'] = $this->formatGrow($data['followed_by_grow_30'], $data['followed_by_count']);
             $profile['most_mentions'] = json_decode($data['most_mentions'], true);
             $profile['most_hashtags'] = json_decode($data['most_hashtags'], true);
             $profile['last_post'] = json_decode($data['last_post'], true);
             Cache::put($var_cache, $profile, 1440);
         } else {
             return 'Invalid method';
         }
     }
     return Cache::get($var_cache);
 }
 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);
 }
 public function movies_info()
 {
     if (\Cache::has('genres_actors')) {
         $data = \Cache::get('genres_actors');
     } else {
         $obj = new \movies_model();
         $players_json_array = $obj->where('id', '>', 0)->lists('players');
         $actors = [];
         foreach ($players_json_array as $p) {
             $out = json_decode($p);
             if (isset($out->actors) && $out->actors) {
                 $actors = array_unique(array_merge($out->actors, $actors));
             }
             if (isset($out->actor) && $out->actor) {
                 $actors = array_unique(array_merge($out->actor, $actors));
             }
         }
         $franch = $obj->where('franchises', '!=', '')->orderBy("year", "asc")->get(['franchises', 'link_id']);
         $final = [];
         foreach ($franch as $f) {
             $final[slash($f->franchises)][] = ["franch" => $f->franchises, "id" => $f->link_id];
         }
         $franch = [$final];
         sort($franch);
         sort($actors);
         $data['actors'] = $actors;
         $genres = \movies_model::lists('genre')->unique()->sort();
         $data['genres'] = $genres;
         $data['franch'] = $franch;
         \Cache::add('genres_actors', $data, 4320);
     }
     return $data;
 }
 public function test_has()
 {
     Cache::expire('foo');
     $this->assertFalse(Cache::has('foo'), 'The cache has a value that has been explicitly expired.');
     Cache::set('foo', 'a value');
     $this->assertTrue(Cache::has('foo'), 'The cache does not have a value that has been explicitly set.');
 }
Exemple #24
0
 /**
  * Runs all jobs that do not have a cool down.
  * Returns false or the number of executed jobs.
  * 
  * @return boolean|int
  */
 public function run()
 {
     $now = time();
     if ($this->cache->has($this->cacheKey)) {
         $executed = $this->cache->get($this->cacheKey);
         if ($now - $executed < $this->coolDown * 60) {
             return false;
         }
     }
     $this->cache->forever($this->cacheKey, $now);
     $counter = 0;
     foreach ($this->jobs as $name => $jobBag) {
         $job = $this->getOrMake($name);
         $key = $this->makeCacheKey($name);
         $executed = null;
         if ($this->cache->has($key)) {
             $executed = $this->cache->get($key);
             if ($now - $executed < $job->getInterval() * 60) {
                 continue;
             }
         }
         if ($job->getActive()) {
             $now = time();
             $job->run($executed);
             $this->cache->forever($key, $now);
             $counter++;
         }
     }
     return $counter;
 }
Exemple #25
0
 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' => 'Ваше сообщение отправлено']);
 }
Exemple #26
0
 /**
  * Handle an incoming request.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  \Closure  $next
  * @return mixed
  */
 public function handle($request, Closure $next)
 {
     $key = $this->makeCacheKey($request);
     if (\Cache::has($key)) {
         return \Cache::get($key);
     }
     return $next($request);
 }
Exemple #27
0
 public function getActivities()
 {
     if (!Cache::has('github')) {
         $activities = $this->activity->forUser('nwidart')->activities(30);
         Cache::put('github', $activities, 1440);
     }
     return Cache::get('github', []);
 }
 /**
  * @return Response|null
  */
 public function getResponseFromCache()
 {
     if ($this->option('cache-static-content') === false || !$this->cache->has('content-' . $this->entity)) {
         return null;
     }
     /**
      * Generate new Response from cached content
      */
     $response = new Response();
     $this->isFromCache = true;
     $response->setContent($this->cache->get('content-' . $this->entity));
     /**
      * TODO check if setting content-type is needed
      */
     $this->setResponseHeader($response);
     return $response;
 }
Exemple #29
0
 public function test_expire()
 {
     $value = rand(0, 999999);
     Cache::set('habari:test', $value);
     $this->assert_true(Cache::has('habari:test'), 'Cache value not stored as expected.');
     Cache::expire('habari:test');
     $this->assert_false(Cache::has('habari:test'), 'Cache value did not expire as expected.');
 }
 public function viewBook($bookcode)
 {
     if (Cache::has('bookingcode')) {
         echo "you have 60 minutes / 1 hour before the";
     } else {
         return Redirect::to('/');
     }
 }