1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* @link https://dukt.net/twitter/ |
4
|
|
|
* @copyright Copyright (c) 2018, Dukt |
5
|
|
|
* @license https://github.com/dukt/twitter/blob/master/LICENSE.md |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
namespace dukt\twitter\services; |
9
|
|
|
|
10
|
|
|
use dukt\twitter\lib\AutoLink; |
11
|
|
|
use yii\base\Component; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* Twitter Service |
15
|
|
|
* |
16
|
|
|
* @author Dukt <[email protected]> |
17
|
|
|
* @since 3.0 |
18
|
|
|
*/ |
19
|
|
|
class Twitter extends Component |
20
|
|
|
{ |
21
|
|
|
// Public Methods |
22
|
|
|
// ========================================================================= |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* Returns the tweet with URLs transformed into HTML links |
26
|
|
|
* |
27
|
|
|
* @param int $text The tweet's text. |
28
|
|
|
* @param array $options Options to pass to AutoLink. |
29
|
|
|
* |
30
|
|
|
* @return string |
31
|
|
|
*/ |
32
|
|
|
public function autoLinkTweet($text, $options = []) |
33
|
|
|
{ |
34
|
|
|
$twitter = AutoLink::create(); |
35
|
|
|
|
36
|
|
|
$aliases = [ |
37
|
|
|
'urlClass' => 'setURLClass', |
38
|
|
|
'usernameClass' => 'setUsernameClass', |
39
|
|
|
'listClass' => 'setListClass', |
40
|
|
|
'hashtagClass' => 'setHashtagClass', |
41
|
|
|
'cashtagClass' => 'setCashtagClass', |
42
|
|
|
'noFollow' => 'setNoFollow', |
43
|
|
|
'external' => 'setExternal', |
44
|
|
|
'target' => 'setTarget', |
45
|
|
|
'noOpener' => 'setNoOpener' |
46
|
|
|
]; |
47
|
|
|
|
48
|
|
|
foreach ($options as $k => $v) { |
49
|
|
|
if (isset($aliases[$k])) { |
50
|
|
|
$twitter->{$aliases[$k]}($v); |
51
|
|
|
} |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
$html = $twitter->autoLink($text); |
55
|
|
|
|
56
|
|
|
return $html; |
57
|
|
|
} |
58
|
|
|
} |
59
|
|
|
|