extract() public static method

Extracts urls from a string of text.
public static extract ( string $string ) : array
$string string
return array $urls
Esempio n. 1
0
 public function handle()
 {
     $client = new Client();
     $post = DB::table('posts')->where('id', $this->post_id)->first();
     $urls = \Purl\Url::extract($post->content);
     if (config('twitter.oauth_token')) {
         $credentials = array('consumer_key' => config('twitter.id'), 'consumer_secret' => config('twitter.secret'), 'oauth_token' => config('twitter.oauth_token'), 'oauth_token_secret' => config('twitter.oauth_secret'));
         $auth = new SingleUserAuth($credentials, new ArraySerializer());
         $params = ['status' => $post->content];
         $response = $auth->post('statuses/update', $params);
     }
     if (config('linkedin.oauth_token')) {
         try {
             $post_data = array('comment' => $post->content, 'content' => array('description' => $post->content), 'visibility' => array('code' => 'anyone'));
             if (!empty($urls)) {
                 $post_data['content']['submittedUrl'] = trim($urls[0]);
             }
             $request_body = $post_data;
             $linkedin_resource = '/v1/people/~/shares';
             $request_format = 'json';
             $linkedin_params = array('oauth2_access_token' => config('linkedin.oauth_token'), 'format' => $request_format);
             $linkedinurl_info = parse_url('https://api.linkedin.com' . $linkedin_resource);
             if (isset($linkedinurl_info['query'])) {
                 $query = parse_str($linkedinurl_info['query']);
                 $linkedin_params = array_merge($linkedin_params, $query);
             }
             $request_url = 'https://api.linkedin.com' . $linkedinurl_info['path'] . '?' . http_build_query($linkedin_params);
             $request_body = json_encode($request_body);
             $linkedin_response = CurlRequester::requestCURL('POST', $request_url, $request_body, $request_format);
         } catch (Exception $e) {
         }
     }
     if (config('facebook.oauth_token')) {
         try {
             $post_data = array('access_token' => config('facebook.oauth_token'), 'message' => $post->content);
             if (!empty($urls)) {
                 $post_data['link'] = trim($urls[0]);
             }
             $res = $client->post('https://graph.facebook.com/me/feed', array('query' => $post_data));
             $response_body = $res->getBody();
             $response_body = json_decode($response_body, true);
         } catch (Exception $e) {
         }
     }
 }
Esempio n. 2
0
 public function testExtract()
 {
     $urls = Url::extract("test\nmore test https://google.com ftp://jwage.com ftps://jwage.com http://google.com\ntesting this out http://jwage.com more text https://we-are-a-professional-studio-of.photography");
     $this->assertEquals(6, count($urls));
     $this->assertEquals('https://google.com/', (string) $urls[0]);
     $this->assertEquals('ftp://jwage.com/', (string) $urls[1]);
     $this->assertEquals('ftps://jwage.com/', (string) $urls[2]);
     $this->assertEquals('http://google.com/', (string) $urls[3]);
     $this->assertEquals('http://jwage.com/', (string) $urls[4]);
     $this->assertEquals('https://we-are-a-professional-studio-of.photography/', (string) $urls[5]);
 }
Esempio n. 3
0
 public function testExtract()
 {
     $urls = Url::extract("test\nmore test https://google.com ftp://jwage.com ftps://jwage.com http://google.com\ntesting this out http://jwage.com more text");
     $this->assertEquals(5, count($urls));
     $this->assertEquals('https://google.com/', (string) $urls[0]);
     $this->assertEquals('ftp://jwage.com/', (string) $urls[1]);
     $this->assertEquals('ftps://jwage.com/', (string) $urls[2]);
     $this->assertEquals('http://google.com/', (string) $urls[3]);
     $this->assertEquals('http://jwage.com/', (string) $urls[4]);
 }
Esempio n. 4
0
use GuzzleHttp\Client;
use TwitterOAuth\Auth\SingleUserAuth;
use TwitterOAuth\Serializer\ArraySerializer;
$app->get('/', 'HomeController@index');
$app->get('/publish', 'HomeController@publish');
$app->get('/{category}', 'HomeController@index');
use Carbon\Carbon;
$app->get('/d/e/f', function () {
    $date = date('Y-m-d', strtotime('+' . mt_rand(1, 30) . ' days'));
    $times = config('times.publishing_times');
    $index = array_rand($times);
    $date_time = Carbon::parse($date . ' ' . $times[$index]);
});
$app->get('fo/fa/fi', function () {
    $post = DB::table('posts')->where('id', 2)->first();
    $urls = \Purl\Url::extract($post->content);
    if (!empty($urls)) {
        return $urls[0];
    }
});
$app->get('/a/b/c', function () {
    $client = new Client();
    $content = 'The App-ocalypse: can web standards make mobile apps obsolete? http://arstechnica.com/information-technology/2015/12/the-app-ocalypse-can-web-standards-make-mobile-apps-obsolete/';
    $post_url = 'http://arstechnica.com/information-technology/2015/12/the-app-ocalypse-can-web-standards-make-mobile-apps-obsolete/';
    $content = 'testing ahead';
    /*
    
    
    Twitter::setOAuthToken(config('twitter.oauth_token'));
    Twitter::setOAuthTokenSecret(config('twitter.oauth_secret'));
    $twitter_response = Twitter::statusesUpdate($content);