/** * @param string $string * * @return string */ public function clean($string) { $reg = '#' . preg_quote($this->browser->getHost()) . '/ch\\d+ \\[([^\\]]+)\\]#'; $string = preg_replace($reg, '$1', $string); $string = preg_replace('/\\[[^\\[\\]]+\\]/', '', $string); // remove BB tags return $string; }
/** * @param Item $item * * @return string */ public function getSourceForFill(Item $item) { /* @var $source Source */ foreach ($item->getSources() as $source) { if (strpos($source->getUrl(), $this->browser->getHost()) === 0) { return $source->getUrl(); } } return ''; }
/** * Search source by name. * * @param array $data * * @return ItemSearch[] */ public function search(array $data) { // if the db does not exists, send a request to download if (!file_exists($this->titles_db)) { return []; } $search = $this->getUnifiedTitle($data['name']); // search by name $aids = []; $fp = gzopen($this->titles_db, 'r'); while (!gzeof($fp)) { $line = trim(gzgets($fp, 4096)); list($aid, $type, $lang, $unified) = explode('|', $line); if (mb_strpos($unified, $search, 0, 'utf8') === 0) { if ($type == 1 || $type == 4 && $lang == $this->locale || empty($titles[$aid])) { $aids[] = $aid; } } } gzclose($fp); $aids = array_unique($aids); // get all names for aid $items = []; $fp = gzopen($this->titles_db, 'r'); while (!gzeof($fp)) { $line = trim(gzgets($fp, 4096)); list($aid, $type, $lang, , $title) = explode('|', $line); if (in_array($aid, $aids)) { $items[$aid][$lang][$type] = $title; } } gzclose($fp); // build result foreach ($items as $aid => $item) { if (!empty($item[$this->locale])) { $main_name = $this->getNameForLocale($this->locale, $item); } elseif ($this->locale != 'en' && !empty($item['en'])) { $main_name = $this->getNameForLocale('en', $item); } else { $main_name = $this->getNameForLocale(array_keys($item)[0], $item); } $description = []; foreach ($item as $names) { foreach ($names as $name) { $description[] = $name; } } sort($description); $items[$aid] = new ItemSearch($main_name, $this->getLinkForFill($this->browser->getHost() . str_replace('#ID#', $aid, self::ITEM_LINK)), $this->router->generate('ani_db_media_cover', ['id' => $aid]), implode("\n", array_unique($description)), $this->browser->getHost() . str_replace('#ID#', $aid, self::ITEM_LINK)); } return $items; }
/** * @param string $url * * @return bool */ public function isSupportedUrl($url) { return strpos($url, $this->browser->getHost()) === 0; }
/** * Test get host */ public function testGetHost() { $this->assertEquals($this->host, $this->browser->getHost()); }