caching = false;
if (!isset($_GET['author'])) {
PEAR::raiseError(new PEAR_Error('Unknown Author'));
} else {
$interface->assign('author', $_GET['author']);
}
// Retrieve User Search History
if (isset($_COOKIE['search'])) {
$sHistory = unserialize($_COOKIE['search']);
$lastSearch = $sHistory[count($sHistory) - 1];
$interface->assign('lastsearch', $lastSearch);
}
if (!$interface->is_cached('layout.tpl|Author' . $_GET['author'])) {
// Clean up author string
$author = $_GET['author'];
if (substr($author, strlen($author) - 1, 1) == ",") {
$author = substr($author, 0, strlen($author) - 1);
}
$author = explode(',', $author);
$interface->assign('author', $author);
// Connect To Wikipedia
if (!isset($_GET['page']) || ($_GET['page'] == 1)) {
$url = 'http://en.wikipedia.org/w/api.php?action=query&prop=revisions&rvprop=content&format=php&titles=' . urlencode("$author[1] $author[0]");
$client = new HTTP_Request();
$client->setMethod(HTTP_REQUEST_METHOD_GET);
$client->setURL($url);
$result = $client->sendRequest();
if (!PEAR::isError($result)) {
$body = unserialize($client->getResponseBody());
//Check if data exists or not
if(!$body['query']['pages']['-1']) {
$body = array_shift($body['query']['pages']);
$info['name'] = $body['title'];
$body = array_shift($body['revisions']);
$body = explode("\n", $body['*']);
$done = 0;
while(!$done) {
if($body[0] == '') {
array_shift($body);
continue;
}
switch(substr($body[0], 0, 2)){
case "[[" :
case "{{" :
case "}}" :
case "]]" :
case "| " :
//echo " sub : '" . substr($body[0], 0, 2) . "' ";
$stpos = stripos($body[0], "image:");
if(!$stpos)
$stpos = stripos($body[0], "image");
if($stpos) {
$len = 4;
$endpos = stripos($body[0], ".jpg");
if(!$endpos) {
$len = 4;
$endpos = stripos($body[0], ".gif");
}
if($endpos) {
$image = substr($body[0], $stpos,
$endpos + $len - $stpos);
}
}
array_shift($body);
break;
default :
$done = 1;
break;
}
}
$desc = "";
$done = 0;
while(!$done) {
if(substr($body[0], 0, 2) == "==")
$done = 1;
else {
$desc .= $body[0];
array_shift($body);
}
}
//Create links to wikipedia
$pattern = array();
$replacement = array();
$pattern[] = '/(\x5b\x5b)([^\x5d|]*)(\x5d\x5d)/';
$replacement[] = '$2';
$pattern[] = '/(\x5b\x5b)([^\x5d]*)\x7c([^\x5d]*)(\x5d\x5d)/';
$replacement[] = '$3';
// Removes citation
$pattern[] = '/({{)[^}]*(}})/';
$replacement[] = "";
$desc = preg_replace($pattern, $replacement, $desc);
$info['image'] = $image;
$info['description'] = $desc;
$interface->assign('info', $info);
}
}
}
}
// Get records by this author
$this->db = new SOLR($configArray['SOLR']['url']);
$result = $this->db->query('author:"' . $_GET['author'] . '"', null, 0, 20);
if (isset($result['record']['id'])) {
// Hack for issue with XML_Serializer
$result['record'] = array($result['record']);
}
$interface->assign('recordSet', $result['record']);
$link = (strstr($_SERVER['REQUEST_URI'], 'page=')) ? str_replace('page=' . $_GET['page'], '', $_SERVER['REQUEST_URI']) . 'page=%d' : $_SERVER['REQUEST_URI'] . '&page=%d';
$options = array('totalItems' => $result['RecordCount'],
'mode' => 'sliding',
'path' => '',
'fileName' => $link,
'delta' => 5,
'perPage' => 20,
'nextImg' => 'Next »',
'prevImg' => '« Prev',
'separator' => '',
'spacesBeforeSeparator' => 0,
'spacesAfterSeparator' => 0,
'append' => false,
'clearIfVoid' => true,
'urlVar' => 'page',
'curPageSpanPre' => '',
'curPageSpanPost' => '');
$pager =& Pager::factory($options);
$interface->assign('pager', $pager);
$interface->setTemplate('home.tpl');
$interface->display('layout.tpl', 'Author' . $_GET['author']);
}
}
?>