ScoopIt::getShares()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 15
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 1 Features 0
Metric Value
c 2
b 1
f 0
dl 0
loc 15
rs 9.4285
cc 1
eloc 8
nc 1
nop 1
1
<?php
2
3
/*
4
 * This file is part of the SocialShare package.
5
 *
6
 * (c) Kévin Dunglas <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace SocialShare\Provider;
13
14
/**
15
 * Scoop.it!
16
 *
17
 * @author David Duquenoy <[email protected]>
18
 * @author Kévin Dunglas <[email protected]>
19
 */
20
class ScoopIt implements ProviderInterface
21
{
22
    const NAME = 'scoopit';
23
    const SHARE_URL = 'https://www.scoop.it/bookmarklet?url=%s';
24
    const BUTTON_URL = 'http://www.scoop.it/button?position=horizontal&url=%s';
25
    const DTD = '<!DOCTYPE html>';
26
27
    /**
28
     * {@inheritdoc}
29
     */
30
    public function getName()
31
    {
32
        return self::NAME;
33
    }
34
35
    /**
36
     * {@inheritdoc}
37
     */
38
    public function getLink($url, array $options = array())
39
    {
40
        return sprintf(self::SHARE_URL, urlencode($url));
41
    }
42
43
    /**
44
     * {@inheritdoc}
45
     */
46
    public function getShares($url)
47
    {
48
        $html = file_get_contents(sprintf(self::BUTTON_URL, urlencode($url)));
49
50
        // Disable libxml errors
51
        $internalErrors = libxml_use_internal_errors(true);
52
        $document = new \DOMDocument();
53
        $document->loadHTML(self::DTD.$html);
54
        $aggregateCount = $document->getElementById('scoopit_count');
55
56
        // Restore libxml errors
57
        libxml_use_internal_errors($internalErrors);
58
59
        return intval($aggregateCount->nodeValue);
60
    }
61
}
62