/** * Function combines multiple actor thumbnail queries into single SQL query */ function get_actor_thumbnails_batched(&$actors) { if (!count($actors)) { return; } $ids = "'" . join("','", array_map('addslashes', array_extract($actors, 'id'))) . "'"; $SQL = 'SELECT actorid, name, imgurl, UNIX_TIMESTAMP(NOW()) - UNIX_TIMESTAMP(checked) AS cacheage FROM ' . TBL_ACTORS . ' WHERE actorid IN (' . $ids . ')'; $result = runSQL($SQL); $result = array_associate($result, 'actorid'); // loop over actors from full-text field foreach ($actors as $idx => $actor) { // check for actor thumbnail $batch_result = $result[$actor['id']]; if ($batch_result) { $actors[$idx]['imgurl'] = get_actor_image_from_cache($batch_result, $actor['name'], $actor['id']); } else { $actors[$idx]['imgurl'] = getActorThumbnail($actor['name'], $actor['id'], false); } } }
/** * get Thumbnail-URL for an actor * * @param string name of the Actor * @param boolean idSearchAllowed can be used to search by name only if searching by id has already been performed before * @return string the URL to the cached image if exists or a link to img.php */ function getActorThumbnail($name, $actorid = 0, $idSearchAllowed = true) { global $config; $SQL = 'SELECT name, imgurl, UNIX_TIMESTAMP(NOW()) - UNIX_TIMESTAMP(checked) AS cacheage FROM ' . TBL_ACTORS; // identify actor by unique actor id, of by name if ($actorid && $idSearchAllowed) { $result = runSQL($SQL . " WHERE actorid='" . addslashes($actorid) . "'"); } if (!$actorid || count($result) == 0) { $result = runSQL($SQL . " WHERE name='" . addslashes(html_entity_decode($name)) . "'"); } $imgurl = get_actor_image_from_cache($result[0], $name, $actorid); return $imgurl; }