protected function getPhotoFromGoogleImages(Entity $person) { if ($this->imageExists($person)) { return true; } //construct search query $query = null; if ($person->name_middle) { $query = '"' . $person->name . '"'; } else { if ($org = $person->getRelatedEntitiesQuery('Org', RelationshipTable::POSITION_CATEGORY)->fetchOne()) { $query = '"' . $person->name . '" ' . $org->name; } else { $query = '"' . $person->name . '"'; } } $google = new LsGoogle(); $google->setService('images'); $google->setParameter('imgtype', 'face'); $google->setQuery($query); $google->execute(); $results = $google->getResults(); if ($google->getNumResults() == 0) { return false; } foreach ($results as $key => $result) { $image_url = $result->url; $image_content = $result->contentNoFormatting; if (preg_match('/(jpg|jpeg|gif)$/i', $image_url)) { $this->printDebug("Checking " . basename($image_url)); $basefilename = basename($image_url); if (stristr($basefilename . " " . $image_content, $person->getNameLast())) { //Entity $entity, $url, $title = 'title', $caption='caption', $is_featured = 1, $is_free = 0 $this->printDebug("Imported " . $image_url); return $this->attachImage($person, $image_url, 'Photograph'); } } } $this->printDebug("Photo not found"); return false; }
protected function getLogoFromGoogleImage(Entity $org) { if ($this->imageExists($org)) { return true; } //construct search query $nameParts = array_diff(explode(' ', $org->name), array_merge(LsLanguage::$business, LsLanguage::$businessAbbreviations)); $cleanName = trim(implode(' ', $nameParts)); $query = $cleanName . ' logo'; $this->printDebug("Querying Google with term: " . $query); $google = new LsGoogle(); $google->setService('images'); $google->setQuery($query); $google->execute(); $results = $google->getResults(); foreach ($results as $key => $result) { $image_url = $result->url; $image_content = $result->contentNoFormatting; $this->printDebug("Checking: " . $image_url); if (preg_match('/(png|gif|jpg)$/i', $image_url)) { $this->printDebug("Checking " . $image_url); $basefilename = basename($image_url); //$organization_name_parts = array_diff(explode(' ', strtolower($org->name)), array_merge( LsLanguage::$business, LsLanguage::$businessAbbreviations)); $organization_name_parts = split("[ \\.\\_\\-]", strtolower($org->name)); $organization_name_parts[] = "logo"; $organization_name_parts[] = "seal"; $organization_match_parts = LsArray::arrayTrim(split("[ \\.\\_\\-]", preg_replace("/[0-9]/", "", strtolower(basename(urldecode($basefilename)) . " " . urldecode($image_content))))); $intersect = array_intersect($organization_name_parts, $organization_match_parts); //var_dump($organization_name_parts); //var_dump($organization_match_parts); //var_dump($intersect); if (count($intersect) >= 2) { //Entity $entity, $url, $title = 'title', $caption='caption', $is_featured = 1, $is_free = 0 $attached = $this->attachImage($org, $image_url, 'Organization logo'); if ($attached) { $this->printDebug("Saved"); return true; } } } } $this->printDebug("Logo not found on Google"); return false; }