| @@ 51-135 (lines=85) @@ | ||
| 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 | { |
|
| @@ 51-134 (lines=84) @@ | ||
| 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 | $cfpUriParser = new Uri(); |
|
| 94 | $cfp->uri = $cfpUriParser->parse($dom, $xpath); |
|
| 95 | ||
| 96 | $confNameParser = new EventName(); |
|
| 97 | $cfp->conferenceName = $confNameParser->parse($dom, $xpath); |
|
| 98 | ||
| 99 | $confUriParser = new EventUri(); |
|
| 100 | $cfp->conferenceUri = $confUriParser->parse($eventPageDom, $eventXpath); |
|
| 101 | ||
| 102 | $eventStartDate = new EventStartDate($timezone); |
|
| 103 | $cfp->eventStartDate = $eventStartDate->parse($dom, $xpath); |
|
| 104 | ||
| 105 | try { |
|
| 106 | $eventEndDate = new EventEndDate($timezone); |
|
| 107 | $cfp->eventEndDate = $eventEndDate->parse($dom, $xpath); |
|
| 108 | } catch (\InvalidArgumentException $e) { |
|
| 109 | $cfp->eventEndDate = $cfp->eventStartDate; |
|
| 110 | } |
|
| 111 | ||
| 112 | $eventLocation = new Location(); |
|
| 113 | $cfp->location = $eventLocation->parse($dom, $xpath); |
|
| 114 | ||
| 115 | try { |
|
| 116 | $location = $this->getLatLonForLocation($cfp->location); |
|
| 117 | $cfp->latitude = $location[0]; |
|
| 118 | $cfp->longitude = $location[1]; |
|
| 119 | } catch (\UnexpectedValueException $e) { |
|
| 120 | error_log($e->getMessage()); |
|
| 121 | } |
|
| 122 | ||
| 123 | try { |
|
| 124 | $tags = new Tags(); |
|
| 125 | $cfp->tags = $tags->parse($eventPageDom, $eventXpath); |
|
| 126 | } catch (\InvalidArgumentException $e) { |
|
| 127 | $cfp->tags = []; |
|
| 128 | } |
|
| 129 | ||
| 130 | return $cfp; |
|
| 131 | } catch (\Exception $e) { |
|
| 132 | throw $e; |
|
| 133 | } |
|
| 134 | } |
|
| 135 | ||
| 136 | protected function getLatLonForLocation($location) |
|
| 137 | { |
|