Twitter::processShareData()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 4
c 1
b 0
f 0
dl 0
loc 7
rs 10
cc 2
nc 2
nop 0
1
<?php
2
3
/**
4
 * @link https://github.com/yiimaker/yii2-social-share
5
 * @copyright Copyright (c) 2017-2021 Volodymyr Kupriienko
6
 * @license BSD 3-Clause License
7
 */
8
9
namespace ymaker\social\share\drivers;
10
11
use ymaker\social\share\base\AbstractDriver;
12
13
/**
14
 * Driver for Twitter.
15
 *
16
 * @see https://twitter.com
17
 *
18
 * @author Vladimir Kuprienko <[email protected]>
19
 *
20
 * @since 1.0
21
 */
22
class Twitter extends AbstractDriver
23
{
24
    /**
25
     * @var bool|string
26
     */
27
    public $account = false;
28
29
    /**
30
     * {@inheritdoc}
31
     */
32
    protected function processShareData()
33
    {
34
        $this->url = static::encodeData($this->url);
35
        $this->description = static::encodeData($this->description);
36
37
        if (\is_string($this->account)) {
38
            $this->appendToData('account', $this->account);
39
        }
40
    }
41
42
    /**
43
     * {@inheritdoc}
44
     */
45
    protected function buildLink()
46
    {
47
        $link = 'http://twitter.com/share?url={url}&text={description}';
48
49
        if ($this->account) {
50
            $this->addUrlParam($link, 'via', '{account}');
51
        }
52
53
        return $link;
54
    }
55
56
    /**
57
     * {@inheritdoc}
58
     */
59
    protected function getMetaTags()
60
    {
61
        return [
62
            ['name' => 'twitter:card',         'content' => 'summary_large_image'],
63
            ['name' => 'twitter:title',        'content' => '{title}'],
64
            ['name' => 'twitter:description',  'content' => '{description}'],
65
            ['name' => 'twitter:image',        'content' => '{imageUrl}'],
66
        ];
67
    }
68
}
69