public function translate($text, $fromLang, $toLang) { $textArray = TextSplitter::explode($text); $urls = []; foreach ($textArray as $text) { $urls[] = $this->rootURL . $this->translatePath . '?' . http_build_query(['lang' => $fromLang . '-' . $toLang, 'text' => $text]); } $translateArray = []; foreach (CurlHelper::multi($urls) as $rawTranslate) { $rawTranslate = trim($rawTranslate, '"'); $translateArray[] = str_replace('\\n', $this->eolSymbol, $rawTranslate); } return TextSplitter::implode($translateArray); }
protected function parseGalleryPage($url) { $doc = new DOMDocument(); $doc->loadHTML(file_get_contents($this->base_url . $url)); $xpath = new DOMXPath($doc); $gallery_url = $xpath->query("//div[@class='content img_list']//a/@href")->item(0)->nodeValue; $doc->loadHTML(file_get_contents($this->base_url . $gallery_url)); $xpath = new DOMXPath($doc); //get urls on photo page $urls = []; foreach ($xpath->query("//ul[@id='photo_carousel']//a/@href") as $attr) { $urls[] = $this->base_url . $attr->nodeValue; } $imgs = []; foreach (CurlHelper::multi($urls) as $url => $html) { if ($html) { $imgs[] = $this->parseImgPage($html); } } return $imgs; }