• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

joindin / callingallpapers-cli / 19017699028

02 Nov 2025 08:25PM UTC coverage: 26.857% (-12.5%) from 39.394%
19017699028

push

github

heiglandreas
Move to coveralls action

405 of 1508 relevant lines covered (26.86%)

0.52 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/Parser/Lanyrd/Entry.php
1
<?php
2
/**
3
 * Copyright (c) 2015-2015 Andreas Heigl<andreas@heigl.org>
4
 *
5
 * Permission is hereby granted, free of charge, to any person obtaining a copy
6
 * of this software and associated documentation files (the "Software"), to deal
7
 * in the Software without restriction, including without limitation the rights
8
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
 * copies of the Software, and to permit persons to whom the Software is
10
 * furnished to do so, subject to the following conditions:
11
 *
12
 * The above copyright notice and this permission notice shall be included in
13
 * all copies or substantial portions of the Software.
14
 *
15
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
 * THE SOFTWARE.
22
 *
23
 * @author    Andreas Heigl<andreas@heigl.org>
24
 * @copyright 2015-2015 Andreas Heigl/callingallpapers.com
25
 * @license   http://www.opensource.org/licenses/mit-license.php MIT-License
26
 * @version   0.0
27
 * @since     06.03.2012
28
 * @link      http://github.com/joindin/callingallpapers
29
 */
30
namespace Callingallpapers\Parser\Lanyrd;
31

32
use Callingallpapers\Entity\Cfp;
33
use Callingallpapers\Service\TimezoneService;
34
use GuzzleHttp\Client;
35

36
class Entry
37
{
38
    /** @var  Cfp */
39
    protected $cfp;
40

41
    /** @var Client */
42
    protected $client;
43

44
    public function __construct(Cfp $cfp, Client $client, TimezoneService $timezoneService)
×
45
    {
46
        $this->cfp = $cfp;
×
47
        $this->client = $client;
×
48
        $this->tzService = $timezoneService;
×
49
    }
50

51
    public function parse($uri)
×
52
    {
53
        $cfp = clone($this->cfp);
×
54
        try {
55
            $dom = new \DOMDocument('1.0', 'UTF-8');
×
56

57
            $content = file_Get_contents($uri);
×
58
            $content = mb_convert_encoding($content, 'UTF-8');
×
59
            $dom->loadHTML('<?xml version="1.0" charset="UTF-8" ?>' . $content);
×
60
            $dom->preserveWhiteSpace = false;
×
61

62
            $timezone = 'UTC';
×
63
            $xpath = new \DOMXPath($dom);
×
64

65
            $eventLocation = new Location();
×
66
            $cfp->location = $eventLocation->parse($dom, $xpath);
×
67

68
            try {
69
                $location = $this->getLatLonForLocation($cfp->location);
×
70
                $cfp->latitude = $location[0];
×
71
                $cfp->longitude = $location[1];
×
72
                $timezone = $this->tzService->getTimezoneForLocation($location[0], $location[1]);
×
73
            } catch (\UnexpectedValueException $e) {
×
74
                error_log($e->getMessage());
×
75
            }
76
            $cfp->timezone = $timezone;
×
77

78

79
            $closingDateParser = new ClosingDate($timezone);
×
80
            $cfp->dateEnd = $closingDateParser->parse($dom, $xpath);
×
81

82
            $eventPageDom = $this->getEventPage($xpath);
×
83
            $eventXpath = new \DOMXPath(($eventPageDom));
×
84

85
            $descriptionParser = new Description();
×
86
            $cfp->description = $descriptionParser->parse($dom, $xpath);
×
87

88
            $openingDateParser = new OpeningDate($timezone);
×
89
            try {
90
                $cfp->dateStart = $openingDateParser->parse($dom, $xpath);
×
91
            } catch (\Exception $e) {
×
92
            }
93

94
            $cfpUriParser = new Uri();
×
95
            $cfp->uri = $cfpUriParser->parse($dom, $xpath);
×
96

97
            $confNameParser = new EventName();
×
98
            $cfp->conferenceName = $confNameParser->parse($dom, $xpath);
×
99

100
            $confUriParser = new EventUri();
×
101
            $cfp->conferenceUri  = $confUriParser->parse($eventPageDom, $eventXpath);
×
102

103
            $eventStartDate = new EventStartDate($timezone);
×
104
            $cfp->eventStartDate = $eventStartDate->parse($dom, $xpath);
×
105

106
            try {
107
                $eventEndDate      = new EventEndDate($timezone);
×
108
                $cfp->eventEndDate = $eventEndDate->parse($dom, $xpath);
×
109
            } catch (\InvalidArgumentException $e) {
×
110
                $cfp->eventEndDate = $cfp->eventStartDate;
×
111
            }
112

113
            $eventLocation = new Location();
×
114
            $cfp->location = $eventLocation->parse($dom, $xpath);
×
115

116
            try {
117
                $location = $this->getLatLonForLocation($cfp->location);
×
118
                $cfp->latitude = $location[0];
×
119
                $cfp->longitude = $location[1];
×
120
            } catch (\UnexpectedValueException $e) {
×
121
                error_log($e->getMessage());
×
122
            }
123

124
            try {
125
                $tags = new Tags();
×
126
                $cfp->tags = $tags->parse($eventPageDom, $eventXpath);
×
127
            } catch (\InvalidArgumentException $e) {
×
128
                $cfp->tags = [];
×
129
            }
130

131
            return $cfp;
×
132
        } catch (\Exception $e) {
×
133
            throw $e;
×
134
        }
135
    }
136

137
    protected function getLatLonForLocation($location)
×
138
    {
139
        $result = $this->client->get(sprintf(
×
140
            'https://nominatim.openstreetmap.org/search?q=%1$s&format=json',
×
141
            urlencode($location)
×
142
        ));
×
143

144
        $locations = json_decode($result->getBody()->getContents());
×
145

146
        if (empty($locations)) {
×
147
            return [0, 0];
×
148
        }
149
        $location = $locations[0];
×
150

151
        return [$location->lat, $location->lon];
×
152
    }
153

154
    public function getEventPage($xpath)
×
155
    {
156
        $confPath = $xpath->query("//h3/a[contains(@class, 'summary')]");
×
157

158
        if (! $confPath || $confPath->length == 0) {
×
159
            throw new \InvalidArgumentException('We can\'t find an EventPage');
×
160
        }
161

162
        $dom = new \DOMDocument('1.0', 'UTF-8');
×
163

164
        $context = stream_context_create([
×
165
            'ssl' => [
×
166
                'verify_peer'   => false,
×
167
                'verify_peer_name' => false,
×
168
            ]
×
169
        ]);
×
170
        $content = file_get_contents('https://lanyrd.com' . $confPath->item(0)->attributes->getNamedItem('href')->textContent, false, $context);
×
171
        $content = mb_convert_encoding($content, 'UTF-8');
×
172
        $dom->loadHTML('<?xml version="1.0" charset="UTF-8" ?>' . $content);
×
173
        $dom->preserveWhiteSpace = false;
×
174

175
        return $dom;
×
176
    }
177
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc