/**
  * Handle an incoming request.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  \Closure  $next
  * @return mixed
  */
 public function handle($request, Closure $next)
 {
     $referer = $request->server->get('referer');
     // Referer is not provided, we continue
     if (is_null($referer) or env('APP_ENV', 'production') !== 'production') {
         return $next($request);
     }
     // Handle the dictionnary.
     // @todo Refactor that
     $dir = realpath(dirname(__FILE__) . '/../../../../../') . '/';
     $path = $dir . 'spammers.json';
     $file = file_get_contents($path);
     // Dictionnary is not readable, abort.
     if (empty($file)) {
         abort(500, 'Unable to read spammers.json');
     }
     $dictionary = json_decode($file);
     // Parse the referer
     $url = new Parser(new PublicSuffixList([]));
     $host = $url->parseHost($referer)->host;
     // Compare dictionary against the referer...
     $search = Arr::where($dictionary, function ($key, $value) use($host) {
         return mb_stripos($host, $value) !== false;
     });
     // ...and check for results
     if (count($search) > 0) {
         abort(500, 'Spammers protection');
     }
     // No spam, we can continue :)
     return $next($request);
 }
 /**
  * Determine if a user exists in the repository.
  *
  * @param  string  $identification
  * @param  string  $type  Must be one of properties defined in User class
  * @return bool
  */
 public function has($identification, $type = 'uid')
 {
     if ($type == "uid") {
         return Arr::has($this->items, $identification);
     } else {
         return Arr::where((array) $this->items, function ($key, $value) use($identification, $type) {
             if (property_exists($value, $type)) {
                 return false;
             }
             return $value->{$type} == $identification;
         });
     }
 }
 /**
  * Iterate through the flattened array of settings and removes
  * all user settings. A new array is build and returned.
  *
  * User settings are found to start with the 'User" key followed by a number,
  * both parts are separated by a dot ('.').
  *
  * @param $allSettings
  * @return array
  */
 public static function FilterOutUserSettings($allSettings)
 {
     $allNonUserSetting = Arr::where($allSettings, function ($k) {
         if ("User." === substr($k, 0, 5)) {
             $kparts = explode('.', $k);
             $user = User::ofUsername($kparts[1])->first();
             if ($user instanceof User) {
                 return false;
             }
         }
         return true;
     });
     return $allNonUserSetting;
 }
Ejemplo n.º 4
0
 public function getTransactionsAttribute()
 {
     return Cache::remember('transactions-on-currency-' . $this->id, Cache::get('altwallets.transactions.ttl'), function () {
         $transactions = $this->client->listtransactions();
         $filtered = array_reverse(Arr::where($transactions, function ($key, $transaction) {
             if (in_array($transaction->category, ['send', 'receive', 'move'])) {
                 return true;
             }
             return false;
         }));
         return array_map(function ($transaction) {
             return new Transaction((array) $transaction);
         }, $filtered);
     });
 }
Ejemplo n.º 5
0
 /**
  * Filter the array using the given callback.
  *
  * @param  array $array
  * @param  callable $callback
  * @return array
  */
 function array_where($array, callable $callback)
 {
     return Arr::where($array, $callback);
 }
Ejemplo n.º 6
0
 /**
  * Validate an attribute is unique among other values.
  *
  * @param  string  $attribute
  * @param  mixed   $value
  * @param  array   $parameters
  * @return bool
  */
 protected function validateDistinct($attribute, $value, $parameters)
 {
     $attributeName = $this->getPrimaryAttribute($attribute);
     $explicitPath = $this->getLeadingExplicitAttributePath($attributeName);
     $attributeData = $this->extractDataFromPath($explicitPath);
     $data = Arr::where(Arr::dot($attributeData), function ($key) use($attribute, $attributeName) {
         return $key != $attribute && Str::is($attributeName, $key);
     });
     return !in_array($value, array_values($data));
 }
Ejemplo n.º 7
0
 /**
  * Get the numeric parameters from a given list.
  *
  * @param  array  $parameters
  * @return array
  */
 protected function getNumericParameters(array $parameters)
 {
     return Arr::where($parameters, function ($k, $v) {
         return is_numeric($k);
     });
 }
Ejemplo n.º 8
0
 /**
  * Get an array of items from the cache, or store the default value forever.
  *
  * @param  array  $keys
  * @param  \Closure  $callback
  * @return mixed
  */
 public function rememberManyForever(array $keys, Closure $callback)
 {
     $values = $this->getMany($keys);
     $items = Arr::where($values, function ($key, $value) {
         return is_null($value);
     });
     if (!empty($items)) {
         $items = array_combine(array_keys($items), $callback(array_keys($items)));
         $this->foreverMany($items);
         $values = array_replace($values, $items);
     }
     return $values;
 }
Ejemplo n.º 9
0
 /**
  * Filter the array using the given Closure.
  *
  * @param  array     $array
  * @param  \Closure  $callback
  * @return array
  */
 function array_where($array, Closure $callback)
 {
     return Arr::where($array, $callback);
 }
Ejemplo n.º 10
0
 /**
  * Run a filter over each of the items.
  *
  * @param  callable|null  $callback
  * @return static
  */
 public function filter(callable $callback = null)
 {
     if ($callback) {
         return new static(Arr::where($this->items, $callback));
     }
     return new static(array_filter($this->items));
 }
Ejemplo n.º 11
0
 private function prepareDataToJson($admin = false)
 {
     // apply admin filter
     return Arr::where($this->getData(), function ($key, $value) use($admin) {
         $meta = Arr::get($this->metas, $key);
         return $admin === false && $meta['admin'] === true ? false : true;
     });
 }
Ejemplo n.º 12
0
 /**
  * Validate an attribute is unique among other values.
  *
  * @param  string  $attribute
  * @param  mixed   $value
  * @param  array   $parameters
  * @return bool
  */
 protected function validateDistinct($attribute, $value, $parameters)
 {
     $attributeName = $this->getPrimaryAttribute($attribute);
     $data = Arr::where(Arr::dot($this->data), function ($key) use($attribute, $attributeName) {
         return $key != $attribute && Str::is($attributeName, $key);
     });
     return !in_array($value, array_values($data));
 }
Ejemplo n.º 13
0
 /**
  * search descendants getter
  *
  * @param string $siteKey site key
  * @param string $name    the name
  * @return array
  */
 public function fetchDescendant($siteKey, $name)
 {
     $data = $this->getData($siteKey, $this->getHead($name));
     return Arr::where($data, function ($idx, $item) use($name) {
         return Str::startsWith($item->name, $name) && $name !== $item->name;
     });
 }