/** * @inheritdoc */ protected function parsePodBaseUrl(DOMDocument $document) { $elem = $document->querySelector('#alpha-inner h3.entry-header a'); return $elem ? $elem->getAttribute('href') : ''; }
/** * Parse document date to POD date. * @param DOMDocument $document * @param string $selector CSS selector with date. * @param string $format date format {@link http://docs.php.net/manual/en/function.strftime.php} * @throws ProviderException when no date element found or format doesn't to date string. * @return string date in format YYYY-MM-DD */ protected function getDateFromDocument(\DOMDocument $document, $selector, $format) { if (!($elem = $document->querySelector($selector))) { throw new ProviderException('Date element node is missing.'); } $text = $elem->textContent; return $this->parseDate($text, $format); }
/** * @inheritdoc */ protected function finalizePod(Pod $pod, DOMDocument $document, $response) { $img = $document->querySelector('.oneHalf.gutter .piccentre img'); if (!$img) { return; } $src = $img->getAttribute('src'); // Replace image to high resolution. $src = preg_replace('/c\\.jpg$/', 'k.jpg', $src); $pod->imageUrl = $src; // Description from the image's "alt" attribute. $pod->desc = $img->getAttribute('alt'); // Get direct link to page. if ($link = $img->parentNode->getAttribute('href')) { $components = parse_url($this->url); $pod->baseUrl = $components['scheme'] . '://' . $components['host'] . $link; } }
/** * @inheritdoc */ protected function parsePodImageUrl(DOMDocument $document) { if (!($elem = $document->querySelector('#content_top .primary_photo img'))) { throw new ProviderException('Picture is missing'); } $src = $elem->getAttribute('src'); if (strpos($src, '//') === 0) { $src = 'http:' . $src; } return $src; }
/** * @inheritdoc */ protected function finalizePod(Pod $pod, DOMDocument $document, $response) { // Wrapper element for date and base url. $element = $document->querySelector('#potd-list-wrap .new-row a.selected'); if ($element && $element->hasChildNodes()) { // Create absolute url from relative. $href = parse_url($element->getAttribute('href')); if (empty($href['scheme'])) { $url = parse_url($this->url); $pod->baseUrl = $url['scheme'] . '://' . $url['host'] . $href['path']; } // Search date element. foreach ($element->childNodes as $child) { if ($child->nodeType == XML_ELEMENT_NODE && $child->getAttribute('class') == 'date') { $pod->date = $this->parseDate($child->textContent, '%d/%m/%Y'); break; } } } // Wrapper element for title, image url and description. $element = $document->getElementById('potd-wrap'); if ($element && $element->hasChildNodes()) { foreach ($element->childNodes as $child) { if ($child->nodeType == XML_ELEMENT_NODE) { switch ($child->tagName) { case 'h1': if (empty($pod->title)) { $pod->title = $child->textContent; } break; case 'div': if ($child->getAttribute('id') == 'image-caption') { $pod->desc = $child->textContent; } break; case 'img': $pod->imageUrl = $child->getAttribute('src'); if (($pos = strpos($pod->imageUrl, '?')) !== false) { $pod->imageUrl = substr($pod->imageUrl, 0, $pos); } break; } } } } }
/** * @inheritdoc */ protected function finalizePod(Pod $pod, DOMDocument $document, $response) { $container = $document->querySelector('.container .leftCol .section.main_profile'); if (!$container) { throw new ProviderException('Container wrapper is missing in document.'); } foreach ($container->childNodes as $child) { if ($child->nodeType != XML_ELEMENT_NODE) { continue; } switch ($child->tagName) { case 'h1': // title $pod->title = $child->textContent; break; case 'h5': // date $pod->date = $this->parseDate($child->textContent, '%d %B %Y'); break; case 'span': // image url if ($child->hasChildNodes()) { $img = $child->lastChild; if ($img->tagName == 'img') { $src = $img->getAttribute('src'); if (($pos = strrpos($src, '?')) !== false) { $src = substr($src, 0, $pos); } $pod->imageUrl = $src; } } break; case 'div': // description if (!$pod->desc && $child->hasChildNodes()) { foreach ($child->childNodes as $node) { if ($node->nodeType == XML_ELEMENT_NODE && $node->tagName == 'p') { $pod->desc .= $node->textContent . "\n"; } } $pod->desc = trim($pod->desc); } break; } } }