/** * Extract a single value * * @param \QueryPath\DOMQuery $item * @param array $mapping * @param string $value * @return string */ protected function _extractValue(\QueryPath\DOMQuery $item, array $mapping, $value = '') { if ($item) { if (!empty($mapping['attr'])) { $value = $item->attr($mapping['attr']); } elseif (!empty($mapping['innerHTML'])) { $value = $item->innerHTML(); } else { $value = $item->text(); } } $value = mb_convert_encoding($value, 'UTF-8', 'auto'); if (!empty($mapping['preg'])) { if (preg_match($mapping['preg'], $value, $matches)) { $value = isset($matches[1]) ? $matches[1] : $matches[0]; } } if (!empty($mapping['wrap'])) { $value = str_replace('|', $value, $mapping['wrap']); } if (!empty($mapping['strtotime'])) { $value = strtotime($value); } if (!isset($mapping['trim']) || !empty($mapping['trim'])) { $value = trim($value); } return $value; }
/** * * @param DOMQuery $showtimesDomList * @param DOMQuery $movieDom * @return array */ private function extractTimes($showtimesDomList, $movieDom) { $index = 0; $times = array(); foreach ($showtimesDomList as $showtimesDom) { $getTicketsLink = $showtimesDom->find('a')->first(); $showtimeTypeDom = new DOMQuery($movieDom->find('h5.li_group')->get($index++)); $showtimeType = $showtimeTypeDom ? $this->getShowtimeType(trim($showtimeTypeDom->text(), ' :\\r\\n')) : 'digital'; if ($getTicketsLink->length > 0) { $timeList = explode('|', $getTicketsLink->attr('data-times')); $link = $getTicketsLink->attr('href'); foreach ($timeList as $movieTime) { $times[] = array('show_date' => $this->currentDate, 'show_time' => $movieTime, 'url' => $link ? "{$link}+{$movieTime}" : '', 'type' => $showtimeType); } } else { $showtimes = trim(preg_replace('/\\s+/', ' ', $showtimesDom->text())); $showtimesArr = preg_split('/(\\|\\s*)+/', $showtimes); $lastAp = 'am'; foreach ($showtimesArr as $timeThing) { if (preg_match('/(am)|(pm)/i', $timeThing)) { $tmp = explode(' ', $timeThing); $lastAp = $tmp[1] ?: $lastAp; $timeThing = $tmp[0]; } $times[] = array('show_date' => $this->currentDate, 'show_time' => date('H:i:s', strtotime("{$timeThing} {$lastAp}")), 'type' => $showtimeType, 'url' => ''); } } } return $times; }