public static function parse($contents, $id, $type) { $crawler = new Crawler(); $crawler->addHTMLContent($contents, 'UTF-8'); $rows = $crawler->filter('div[class="spaceit_pad"]'); $title = preg_replace('/ (\\w+?) Details/', '$2', $crawler->filter('div[class="normal_header"]')->text()); $result = array(); if ($type === 'anime') { foreach ($rows as $historyItem) { $crawler = new Crawler($historyItem); $date = explode(' ', $crawler->text()); $historyinfo['item'] = new Anime(); $historyinfo['item']->setId((int) $id); $historyinfo['item']->setTitle($title); $historyinfo['item']->setWatchedEpisodes((int) $date[1]); $historyinfo['type'] = $type; $historyinfo['time_updated'] = Date::formatTime($date[4] . ' ' . $date[6]); $result[] = $historyinfo; } } else { foreach ($rows as $historyItem) { $crawler = new Crawler($historyItem); $date = explode(' ', $crawler->text()); $historyinfo['item'] = new Manga(); $historyinfo['item']->setId((int) $id); $historyinfo['item']->setTitle($title); $historyinfo['item']->setChaptersRead((int) $date[1]); $historyinfo['type'] = $type; $historyinfo['time_updated'] = Date::formatTime($date[4] . ' ' . $date[6]); $result[] = $historyinfo; } } return $result; }
/** * Set the time property. * * @param DateTime $time The time of messages. */ public function setTime($time) { $this->time = Date::formatTime($time); }
private static function parseTopicsDetails($item) { $crawler = new Crawler($item); if ($crawler->filter('td')->count() >= 4) { $topics = new Forum(); # id. # Example: # <span id="wt439011">...</span> $topics->setId(str_replace('/forum/?topicid=', '', $crawler->filter('td[class="forum_boardrow1"] a')->attr('href'))); //->filter('span')->attr('id'))); # name. # Example: # <a href="/forum/?topicid=439011">BBCode Fixes</a> $topics->setName($crawler->filter('td[class="forum_boardrow1"] a')->text()); # username. # Example: # <a href="/profile/ratan12">ratan12</a> $topics->setUsername(str_replace('?board=', '', $crawler->filter('span[class="forum_postusername"] a')->text())); # replies. # Example: # <td align="center" width="75" class="forum_boardrow2" style="border-width: 0px 1px 1px 0px;">159</td> $topics->setReplies(str_replace('?board=', '', $crawler->filter('td[class="forum_boardrow2"]')->eq(1)->text())); # creation time. # Example: # <span class="lightLink">Jun 25, 2008</span> $topics->setTime($crawler->filter('span[class="lightLink"]')->text()); //note: eq(1) is the second node and !first. $username = $crawler->filter('td[class="forum_boardrow1"]')->eq(1)->filter('a')->text(); $time = explode("»»", $crawler->filter('td[class="forum_boardrow1"]')->eq(1)->text()); $topics->setReply(array('username' => $username, 'time' => Date::formatTime($time[1]))); return $topics; } else { return; } }
/** * Set the date property. * * @param string $date The creation date of this review */ public function setDate($date) { $this->date = Date::formatTime($date); }
/** * Set the status property. * * @param string $broadcast The next broadcasting time and date. */ public function setBroadcast($broadcast) { $this->broadcast = Date::formatTime($broadcast); }
/** * Set the joinDate property. * * This function is for compatibility with certain parts of API1 * * @param string $joinDate The MAL join date of an user. */ public function setJoinDate($joinDate) { $this->joinDate = $joinDate; $this->joinDate2 = Date::formatTime($joinDate); }
public static function parseHistory($contents) { $crawler = new Crawler(); $crawler->addHTMLContent($contents, 'UTF-8'); $maincontent = $crawler->filter('table')->filter('tr'); //Empty array so we return something non-null if the list is empty. $historylist = array(); foreach ($maincontent as $historyentry) { $crawler = new Crawler($historyentry); // bypass for the MAL generated strings if ($crawler->filter('a')->count() > 0) { if (strpos($crawler->filter('a')->attr('href'), 'anime') !== false) { $historyinfo['item'] = new Anime(); $historyinfo['item']->setWatchedEpisodes((int) $crawler->filter('strong')->text()); $historyinfo['type'] = 'anime'; } else { $historyinfo['item'] = new Manga(); $historyinfo['item']->setChaptersRead((int) $crawler->filter('strong')->text()); $historyinfo['type'] = 'manga'; } $historyinfo['item']->setTitle($crawler->filter('a')->text()); $historyinfo['item']->setId((int) str_replace('/' . $historyinfo['type'] . '.php?id=', '', $crawler->filter('a')->attr('href'))); $historyinfo['time_updated'] = Date::formatTime(substr($crawler->filter('td')->eq(1)->text(), 1)); $historylist[] = $historyinfo; } } return $historylist; }