Skip to content

Commit

Permalink
Merge pull request #18 from nojimage/develop
Browse files Browse the repository at this point in the history
twitter-text 2.0
  • Loading branch information
nojimage authored Jan 16, 2018
2 parents a2a1fb1 + cdf5093 commit e19d55e
Show file tree
Hide file tree
Showing 32 changed files with 1,673 additions and 2,261 deletions.
57 changes: 54 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,22 @@ Cochrane, this library has been improved and made more complete by Nick Pope.
</a>
</p>

## Requirements ##

- PHP 5.3 or higher
- ext-mbstring
- ext-intl

If the necessary extensions are not installed on the server, please install it additionally or use [symfony/polyfill](https://github.com/symfony/polyfill).

## Install ##

You can install this library into your application using [Composer](https://getcomposer.org/).

```
composer require nojimage/twitter-text-php
```

## Features ##

### Autolink ##
Expand Down Expand Up @@ -47,6 +63,43 @@ Cochrane, this library has been improved and made more complete by Nick Pope.
- Validate different twitter text elements.
- Support for international character sets.

### Parser ###

- Parses a given tweet text with the weighted character count configuration.

## Length validation ##

twitter-text 2.0 introduces configuration files that define how Tweets are parsed for length. This allows for backwards compatibility and flexibility going forward. Old-style traditional 140-character parsing is defined by the v1.json configuration file, whereas v2.json is updated for "weighted" Tweets where ranges of Unicode code points can have independent weights aside from the default weight. The sum of all code points, each weighted appropriately, should not exceed the max weighted length.

Some old methods from twitter-text-php 1.0 have been marked deprecated, such as the `Twitter\Text\Validator::isValidTweetText()`, `Twitter\Text\Validator::getTweetLength()` method. The new API is based on the following method, `Twitter\Text\Parser::parseTweet()`

```(php)
$result = \Twitter\Text\Parser::parseTweet($text);
```

This method takes a string as input and returns a results object that contains information about the string. `Twitter\Text\ParseResults` object includes:

- `weightedLength`: the overall length of the tweet with code points
weighted per the ranges defined in the configuration file.

- `permillage`: indicates the proportion (per thousand) of the weighted
length in comparison to the max weighted length. A value > 1000
indicates input text that is longer than the allowable maximum.

- `valid`: indicates if input text length corresponds to a valid
result.

- `displayRangeStart, displayRangeEnd`: An array of two unicode code point
indices identifying the inclusive start and exclusive end of the
displayable content of the Tweet. For more information, see
the description of `display_text_range` here:
[Tweet updates](https://developer.twitter.com/en/docs/tweets/tweet-updates)

- `validRangeStart, validRangeRnd`: An array of two unicode code point
indices identifying the inclusive start and exclusive end of the valid
content of the Tweet. For more information on the extended Tweet
payload see [Tweet updates](https://developer.twitter.com/en/docs/tweets/tweet-updates)

## Examples ##

For examples, please see `tests/example.php` which you can view in a browser or
Expand All @@ -59,9 +112,7 @@ repository:

https://github.com/twitter/twitter-text

https://github.com/symfony/Yaml

Both requirements already included in `composer.json`, so you should just need to run:
`twitter/twitter-text` already included in `composer.json`, so you should just need to run:

curl -s https://getcomposer.org/installer | php
php composer.phar install
Expand Down
35 changes: 0 additions & 35 deletions compat/Twitter/Autolink.php

This file was deleted.

35 changes: 0 additions & 35 deletions compat/Twitter/Extractor.php

This file was deleted.

33 changes: 0 additions & 33 deletions compat/Twitter/HitHighlighter.php

This file was deleted.

32 changes: 0 additions & 32 deletions compat/Twitter/Validator.php

This file was deleted.

16 changes: 8 additions & 8 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,28 +31,28 @@
"type": "package",
"package": {
"name": "twitter/twitter-text",
"version": "1.14.7",
"version": "2.0.3",
"source": {
"url": "https://github.com/twitter/twitter-text.git",
"type": "git",
"reference": "v1.14.7"
"reference": "v2.0.3"
}
}
}
],
"require": {
"php": ">=5.3.3"
"php": ">=5.3.3",
"ext-mbstring": "*",
"ext-intl": "*"
},
"require-dev": {
"php": ">=5.3.3",
"symfony/yaml": "~2.6.0",
"phpunit/phpunit": "4.8.*|5.7.*",
"twitter/twitter-text": "^1.14.7"
"phpunit/phpunit": "4.8.*|5.7.*|6.5.*",
"twitter/twitter-text": "^2.0.0"
},
"autoload": {
"psr-0": {
"Twitter\\Text\\": "lib/",
"Twitter_": "compat/"
"Twitter\\Text\\": "lib/"
}
},
"scripts": {
Expand Down
Loading

0 comments on commit e19d55e

Please sign in to comment.