/**
  * Crawl and process a single URL.
  * @param $url string
  * @return mixed|null
  */
 protected function crawlUrl($url, $parentUrl = null)
 {
     if (!$url || $this->crawled->search($url) !== false || Str::startsWith($url, "#")) {
         return null;
     }
     $this->log("Crawling URL: " . $url);
     $ch = curl_init();
     curl_setopt($ch, CURLOPT_URL, $url);
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
     curl_setopt($ch, CURLOPT_USERAGENT, $this->agent);
     curl_setopt($ch, CURLOPT_HEADER, 1);
     $response = curl_exec($ch);
     $headerSize = curl_getinfo($ch, CURLINFO_HEADER_SIZE);
     $header = $this->parseHeader(substr($response, 0, $headerSize));
     $body = substr($response, $headerSize);
     curl_close($ch);
     $this->crawled->push($url);
     if (!$this->validate($header, $body, $url, $parentUrl)) {
         return null;
     }
     $processed = $this->processHtml($url, HtmlDomParser::str_get_html($body));
     $this->add($processed);
     // Recursively crawl other URLs that were found.
     foreach ($processed['urls'] as $href) {
         $this->crawlUrl($href, $url);
     }
 }
 /**
  * Handle an incoming request.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  \Closure  $next
  * @return mixed
  */
 public function handle($request, Closure $next)
 {
     $IP = new Collection(['172.16.80.25', '::1']);
     if ($IP->search($request->ip()) === false) {
         return redirect('/login');
     }
     return $next($request);
 }
 /**
  * @param $group
  * @param $name
  * @return string
  */
 private function findByGroupAndName($group, $name)
 {
     if (!$this->values) {
         return (object) ['value' => "{$group}::{$name}"];
     }
     $value = $this->values->search(function ($item) use($group, $name) {
         return $item->group == $group && $item->group_name == $name;
     });
     if ($value === false) {
         return (object) ['value' => "{$group}::{$name}"];
     }
     return $this->values[$value];
 }
Example #4
0
 /**
  * @param \Bosnadev\Repositories\Contracts\CriteriaInterface $criteria
  *
  * @return $this
  */
 public function pushCriteria(CriteriaInterface $criteria)
 {
     if ($this->preventCriteriaOverwriting) {
         // Find existing criteria
         $key = $this->criteria->search(function ($item) use($criteria) {
             return is_object($item) and get_class($item) == get_class($criteria);
         });
         // Remove old criteria
         if (is_int($key)) {
             $this->criteria->offsetUnset($key);
         }
     }
     $this->criteria->push($criteria);
     return $this;
 }
 /**
  * regenerate duplicated code
  * @return string
  */
 private function regenerate($code)
 {
     /**
      * Get Codes ID
      */
     $id = $this->codes->search($code);
     /**
      * Regenerate Code
      */
     $this->codes[$id] = $this->generateCode();
     /**
      * Check DB Again for duplication
      */
     $this->checkDatabase();
 }
 /**
  * Return true if user has all roles
  *
  * @param string|array $role
  * @param bool $any
  * @return bool
  */
 public function is($role, $any = false)
 {
     if (is_null($this->slugRoles)) {
         $this->loadRoles();
         $this->slugRoles = $this->roles->lists('slug');
     }
     if ($role instanceof Model) {
         $role = $role->slug;
     }
     if (is_array($role)) {
         foreach ($role as $item) {
             if ($this->slugRoles->search($item) === false) {
                 return false;
             } elseif ($any === true) {
                 return true;
             }
         }
         return true;
     }
     return $this->slugRoles->search($role) !== false;
 }
Example #7
0
 public function testSearchReturnsFalseWhenItemIsNotFound()
 {
     $c = new Collection([1, 2, 3, 4, 5, 'foo' => 'bar']);
     $this->assertFalse($c->search(6));
     $this->assertFalse($c->search('foo'));
     $this->assertFalse($c->search(function ($value) {
         return $value < 1 && is_numeric($value);
     }));
     $this->assertFalse($c->search(function ($value) {
         return $value == 'nope';
     }));
 }
 /**
  * @param string $token
  */
 protected function triggerDeviceError(Collection $devices, $token)
 {
     $device = $devices->search(function ($device) use($token) {
         return $device->token == $token;
     });
     if (!empty($device)) {
         $this->errors[] = $device;
     }
 }
 /**
  * Generate a unique suffix for the given slug (and list of existing, "similar" slugs.
  *
  * @param string $slug
  * @param string $separator
  * @param \Illuminate\Support\Collection $list
  * @return string
  */
 protected function generateSuffix($slug, $separator, Collection $list)
 {
     $len = strlen($slug . $separator);
     // If the slug already exists, but belongs to
     // our model, return the current suffix.
     if ($list->search($slug) === $this->model->getKey()) {
         $suffix = explode($separator, $slug);
         return end($suffix);
     }
     $list->transform(function ($value, $key) use($len) {
         return intval(substr($value, $len));
     });
     // find the highest value and return one greater.
     return $list->max() + 1;
 }
 /**
  * Get the offset of a specified piece of content within this element.
  *
  * @param FluentHtmlElement|string|mixed $content to look for
  * @return mixed key for matching content, or false if not found
  */
 protected function getContentOffset($content)
 {
     return $this->html_contents->search($content);
 }