/** * Return autocomplete results as an XML string * * @param memcached $cache * @param mysql connection $conn * @param string $title * @param int $userid * @param string $nsDefault * @return false in case of error */ public static function getResults($cache, $conn, $title, $userid = '', $nsDefault = '') { if ($nsDefault == 'Place') { return AutoCompleter::getPlaceResults($cache, $conn, $title); } $ns = ''; // validate title and split if (!$title) { return AutoCompleter::formatError('invalid title'); } else { if (strncasecmp($title, 'user:'******'user'; $title = substr($title, 5); } else { if (strncasecmp($title, 'image:', 6) == 0) { $ns = 'image'; $title = substr($title, 6); } else { if (strncasecmp($title, 'surname:', 8) == 0) { $ns = 'surname'; $title = substr($title, 8); } else { if (strncasecmp($title, 'givenname:', 10) == 0) { $ns = 'givenname'; $title = substr($title, 10); } else { if (strncasecmp($title, 'source:', 7) == 0) { $ns = 'source'; $title = substr($title, 7); } else { if (strncasecmp($title, 'place:', 6) == 0) { $ns = 'place'; $title = substr($title, 6); } else { if (strncasecmp($title, 'person:', 7) == 0) { $ns = 'person'; $title = substr($title, 7); } else { if (strncasecmp($title, 'family:', 7) == 0) { $ns = 'family'; $title = substr($title, 7); } else { if (strncasecmp($title, 'mysource:', 9) == 0) { $ns = 'mysource'; $title = substr($title, 9); } else { if (strncasecmp($title, 'repository:', 11) == 0) { $ns = 'repository'; $title = substr($title, 11); } else { if (strncasecmp($title, 'transcript:', 11) == 0) { $ns = 'transcript'; $title = substr($title, 11); } } } } } } } } } } } } // convert and validate ns if (!$ns) { $ns = $nsDefault; } $nsid = @AutoCompleter::$nsToNsid[strtolower($ns)]; if (!$nsid) { $nsid = 0; $ns = ''; } else { $ns = AutoCompleter::$nsidToNs[$nsid]; } // convert and validate userid - must have userid unless searching source, repository, or place $isGlobal = $nsid == 104 || $nsid == 106 || $nsid == 114; if ($nsid == 104) { // is this still needed? $userid = 0; } else { $userid = intval($userid); } if (!$isGlobal && $userid == 0) { return AutoCompleter::formatError('invalid userid'); } // generate db key $dbKey = AutoCompleter::generateDBKey($title, $conn); // look up in cache (sources only) if ($isGlobal && $userid == 0) { // generate cache key $cacheKey = AutoCompleter::generateCacheKey($userid, $nsid, $dbKey); $results = AutoCompleter::lookupCache($cache, $cacheKey); } else { $results = false; } if ($results === false) { // lookup in db $results = AutoCompleter::lookupDB($conn, $userid, $ns, $nsid, $dbKey); if ($results === false) { $results = AutoCompleter::formatError('mysql error'); } else { if ($isGlobal && $userid == 0) { // cache results AutoCompleter::cacheResults($cache, $cacheKey, $results, AutoCompleter::EXP_TIME); } } } return $results; }