2017 © Pedro Peláez
 

library tweet-entity-linker

Convert Twitter API Tweet entities such as URLs, Hashtags and User Mentions into their respective HTML entities.

image

jedkirby/tweet-entity-linker

Convert Twitter API Tweet entities such as URLs, Hashtags and User Mentions into their respective HTML entities.

  • Wednesday, August 16, 2017
  • by jedkirby
  • Repository
  • 1 Watchers
  • 10 Stars
  • 870 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 2 Forks
  • 1 Open issues
  • 12 Versions
  • 5 % Grown

The README.md

Tweet Entity Linker

Author Build Status Test Coverage StyleCI Packagist Packagist, (*1)

Tweet Entity Linker is a very simple package and requires minimal setup. It's designed to simply only convert a tweets text, along with it's entities, to a HTML rich string enabling linking of URLs, User Mentions and Hashtags., (*2)

Installation

This package can be installed via Composer:, (*3)

``` bash $ composer require jedkirby/tweet-entity-linker, (*4)


It requires **PHP >= 5.6.4**. Usage ------- The following guide assumes that you've imported the class `Jedkirby\TweetEntityLinker\Tweet` into your namespace. The `Tweet` class requires that you pass it parameters so it's able to create the linkified text. Generally these parameters will be the responses from Twitter API endpoints, like [statuses/show/:id](https://dev.twitter.com/rest/reference/get/statuses/show/id), however, it's not required. The following pseudo code should help explain what's needed when using the response from the API (Please see the [example response](https://dev.twitter.com/rest/reference/get/statuses/show/id#example-response)): ``` php $request = Api::get('https://api.twitter.com/1.1/statuses/show/123456'); $tweet = Tweet::make( $request['text'], $request['entities']['urls'], $request['entities']['user_mentions'], $request['entities']['hashtags'], $request['entities']['cashtags'] );

Now the Tweet class has been populated with the parameters it needs, you can call the linkify() method to return the text with URLs, User Mentions and Hashtags converted to their HTML entities:, (*5)

``` php $text = $tweet->linkify();, (*6)


### Manually Creating Parameters You're able to create the parametes manually, however, they require some specific properties in order for the `linkify()` method to function correctly, these are as follows: #### Parameter 1: Text This field is _always_ required, and if containing either a URL, User Mention or Hashtag, the corresponding parameter array's should be populated. The following example assumes we have all of those: ``` php $text = 'This notifies @jedkirby, with the hashtag #Awesome, and the URL https://t.co/Ed4omjYz.';

Parameter 2: URLs

The URLs parameter is an array of array's, of which it must contain the url and display_url fields:, (*7)

``` php $urls = [ [ 'url' => 'https://t.co/Ed4omjYz', 'display_url' => 'https://jedkirby.com' ] ];, (*8)


#### Parameter 3: User Mentions The User Mentions parameter is an array of array's, of which it must contain only a `screen_name` field: ``` php $mentions = [ [ 'screen_name' => 'jedkirby' ] ];

Parameter 4: Hashtags

The Hashtags parameter is an array of array's, of which it must contain only a text field:, (*9)

``` php $hashtags = [ [ 'text' => 'Awesome' ] ];, (*10)


#### Parameter 5: Cashtags The Hashtags parameter is an array of array's, of which it must contain only a `text` field: ```php $cashtags = [ [ 'text' => 'AAPL' ] ];

Result

When putting all the above parameters together, you'd get the following:, (*11)

``` php $tweet = Tweet::make( $text, $urls, $mentions, $hashtags, $cashtags );, (*12)

var_dump($tweet->linkify());, (*13)


With the response being: ``` none string(262) "This notifies @<a href="https://twitter.com/jedkirby" target="_blank">jedkirby</a>, with the hashtag #<a href="https://twitter.com/hashtag/Awesome" target="_blank">Awesome</a>, and the URL <a href="https://t.co/Ed4omjYz" target="_blank">https://jedkirby.com</a>."

Testing

Unit tests can be run inside the package:, (*14)

bash $ ./vendor/bin/phpunit, (*15)

Contributing

Please see CONTRIBUTING for details., (*16)

License

jedkirby/tweet-entity-linker is licensed under the MIT license. See the LICENSE file for more details., (*17)

The Versions

16/08 2017

dev-master

9999999-dev https://jedkirby.com

Convert Twitter API Tweet entities such as URLs, Hashtags and User Mentions into their respective HTML entities.

  Sources   Download

MIT

The Requires

  • php >=5.6.4

 

The Development Requires

entity twitter convert tweet hashtag linkify

26/01 2017

dev-feature/travis-php-cs

dev-feature/travis-php-cs https://jedkirby.com

Convert Twitter API Tweet entities such as URLs, Hashtags and User Mentions into their respective HTML entities.

  Sources   Download

MIT

The Requires

  • php >=5.6.4

 

The Development Requires

entity twitter convert tweet hashtag linkify

26/01 2017

dev-feature/twitter-text-conformance

dev-feature/twitter-text-conformance https://jedkirby.com

Convert Twitter API Tweet entities such as URLs, Hashtags and User Mentions into their respective HTML entities.

  Sources   Download

MIT

The Requires

  • php >=5.6.4

 

The Development Requires

entity twitter convert tweet hashtag linkify

10/01 2017

1.2.4

1.2.4.0 https://jedkirby.com

Convert Twitter API Tweet entities such as URLs, Hashtags and User Mentions into their respective HTML entities.

  Sources   Download

MIT

The Requires

  • php >=5.6.4

 

The Development Requires

entity twitter convert tweet hashtag linkify

10/01 2017

1.2.3

1.2.3.0 https://jedkirby.com

Convert Twitter API Tweet entities such as URLs, Hashtags and User Mentions into their respective HTML entities.

  Sources   Download

MIT

The Requires

  • php >=5.6.4

 

The Development Requires

entity twitter convert tweet hashtag linkify

10/01 2017

1.2.1

1.2.1.0 https://jedkirby.com

Convert Twitter API Tweet entities such as URLs, Hashtags and User Mentions into their respective HTML entities.

  Sources   Download

MIT

The Requires

  • php >=5.6.4

 

The Development Requires

entity twitter convert tweet hashtag linkify

09/01 2017

1.2.0

1.2.0.0 https://jedkirby.com

Convert Twitter API Tweet entities such as URLs, Hashtags and User Mentions into their respective HTML entities.

  Sources   Download

MIT

The Requires

  • php >=5.6.4

 

The Development Requires

entity twitter convert tweet hashtag linkify

08/01 2017

1.1.3

1.1.3.0 https://jedkirby.com

Convert Twitter API Tweet entities such as URLs, Hashtags and User Mentions into their respective HTML entities.

  Sources   Download

MIT

The Requires

  • php >=5.6.4

 

The Development Requires

entity twitter convert tweet hashtag linkify

07/01 2017

1.1.2

1.1.2.0 https://jedkirby.com

Convert Twitter API Tweet entities such as URLs, Hashtags and User Mentions into their respective HTML entities.

  Sources   Download

MIT

The Requires

  • php >=5.6.4

 

The Development Requires

entity twitter convert tweet hashtag linkify

07/01 2017

1.1.1

1.1.1.0 https://jedkirby.com

Convert Twitter API Tweet entities such as URLs, Hashtags and User Mentions into their respective HTML entities.

  Sources   Download

MIT

The Requires

  • php >=5.6.4

 

The Development Requires

entity twitter convert tweet hashtag linkify

06/01 2017

1.1.0

1.1.0.0 https://jedkirby.com

Convert Twitter API Tweet entities such as URLs, Hashtags and User Mentions into their respective HTML entities.

  Sources   Download

MIT

The Requires

  • php >=5.6.4

 

The Development Requires

entity twitter convert tweet hashtag linkify

06/01 2017

1.0.0

1.0.0.0 https://jedkirby.com

Convert Twitter API Tweet entities such as URLs, Hashtags and User Mentions into their respective HTML entities.

  Sources   Download

MIT

The Requires

  • php >=5.6.4

 

The Development Requires

entity twitter convert tweet hashtag linkify