protected function getPhotoFromWikipedia(Entity $person) { if ($this->imageExists($person)) { return true; } //construct search query $wikipedia = new LsWikipedia(); $response = $wikipedia->requestImages($person->name); if (!$response) { return false; } $matches = $response->query->pages->page; $this->printDebug("Images on Wikipedia page: " . count($matches)); foreach ($matches as $match) { $ii = (array) $match->imageinfo->ii; $attributes = $ii['@attributes']; $photo_url = $attributes['url']; $photo_alt = $attributes['comment']; //var_dump($photo_alt); $this->printDebug("Checking: " . $photo_url); if (preg_match('/^http.*' . $person->name_last . '.*(jpg|jpeg|gif)$/i', $photo_url)) { $this->printDebug("Photo found on URL: " . $photo_url); return $this->attachImage($person, $photo_url, 'Photograph'); } } $this->printDebug("Photo not found"); return false; }
protected function getLogoFromWikipedia(Entity $org) { if ($this->imageExists($org)) { return true; } //construct search query $wikipedia = new LsWikipedia(); $response = $wikipedia->requestImages($org->name); if (!$response) { return false; } $matches = $response->query->pages->page; $this->printDebug("Images on Wikipedia page: " . count($matches)); foreach ($matches as $match) { $ii = (array) $match->imageinfo->ii; $attributes = $ii['@attributes']; $logo_image_url = $attributes['url']; $logo_image_alt = $attributes['comment']; if (preg_match('/^http.*(Wikinews|Wikiversity|Wikisource|Wikiquote|Wikibooks|Wiktionary|Commons-logo)/i', $logo_image_url)) { continue; } $this->printDebug("Checking: " . $logo_image_url); $org_name_parts = split("[ \\.\\_\\-]", strtolower($org->name)); $org_name_parts[] = "logo"; $org_name_parts[] = "seal"; $image_name_parts = split("[ \\.\\_\\-]", preg_replace("/[0-9]/", "", strtolower(basename(urldecode($logo_image_url))))); $intersect = array_intersect($image_name_parts, $org_name_parts); if (count($intersect) >= 2) { if ($this->attachImage($org, $logo_image_url, 'Organization logo')) { $this->printDebug("Saved"); return true; } } /* if((preg_match('/^http.*(logo|seal).*(png|gif|svg|jpg)$/i', $logo_image_url)) ) { $this->printDebug( "Found 1"); if($this->attachImage($org, $logo_image_url, 'Organization logo')) { $this->printDebug( "Committed"); return true; } } if( (preg_match('/(png|gif|svg|jpg)$/i',$logo_image_url) && preg_match('/\b(logo|seal)\b/i',$logo_image_alt)) ) { $this->printDebug( "Found 2"); if($this->attachImage($org, $logo_image_url, 'Organization logo')) { $this->printDebug( "Committed"); return true; } } if(preg_match('/^http.*'.str_replace(LsLanguage::$punctuations, '_', $org->name).'.+\.(png|gif|svg)$/i', $logo_image_url)) { $this->printDebug( "Found 3"); if( $this->attachImage($org, $logo_image_url, 'Organization logo')) { $this->printDebug( "Committed"); return true; } } */ } $this->printDebug("Logo not found on Wikipedia"); return false; }