AssEdbeta: the semi-automatic assistant editor
$Html... time elapsed: $Time seconds.
END; exit; } /******************************************************************************************************************************************** * Function: SaveReload() * Saves variables and reloads the page to move on to the next stage */ function SaveReload() { $_SESSION['Stage'] = $this->Stage; $_SESSION['PostData'] = $this->PostData; $_SESSION['QueryKey'] = $this->QueryKey; $_SESSION['StickyHtml'] = $this->StickyHtml; if (isset($this->WebEnv)) $_SESSION['WebEnv'] = $this->WebEnv; if (isset($this->AuthorList)) $_SESSION['AuthorList'] = $this->AuthorList; if (isset($this->AllResults)) $_SESSION['AllResults'] = $this->AllResults; if (isset($this->CurResults)) $_SESSION['CurResults'] = $this->CurResults; if ($this->Stage[0] == "searches") { foreach ($this->PostData['Searches'] as $k => $Search) { if ($this->Stage[1] > $k) $this->Html .= "\n" . $Search['SearchString'] . ": 100% (" . $Search['Count'] . " / " . $Search['Count'] . ")
\n"; elseif (($this->Stage[1] == $k) and !empty($Search['Count'])) { $width = ($this->Stage[2] / $Search['Count']) * 600; $pc = round(($width / 6), 2); $width = round($width); $width2 = 600 - $width; $this->Html .= "\n" . $Search['SearchString'] . ": " . $pc . "% (" . $this->Stage[2] . " / " . $Search['Count'] . ")
\n"; } else $this->Html .= "\n" . $Search['SearchString'] . ": 0%
\n"; } $this->Html .= "\nPost-search filters: 0%
\n"; if (!empty($this->PostData['UseScores'])) $this->Html .= "\nScore calculation: 0%
\n"; } elseif ($this->Stage[0] == "filters") { if (empty($_SESSION['Filtered']) and isset($_SESSION['ToFilter'])) $_SESSION['Filtered'] = $_SESSION['ToFilter'] - count($this->AllResults[1]); foreach ($this->PostData['Searches'] as $k => $Search) { $this->Html .= "\n" . $Search['SearchString'] . ": 100% (" . $Search['Count'] . " / " . $Search['Count'] . ")
\n"; } if (isset($_SESSION['Filtered']) and isset($_SESSION['ToFilter'])) { $width = ($_SESSION['Filtered'] / $_SESSION['ToFilter']) * 600; $pc = round(($width / 6), 2); $width = round($width); $width2 = 600 - $width; $this->Html .= "\nApplying limits and filters: " . $pc . "%
\n"; } else $this->Html .= "\nPost-search filters: 0%
\n"; if (!empty($this->PostData['UseScores'])) $this->Html .= "\nScore calculation: 0%
\n"; } else { foreach ($this->PostData['Searches'] as $k => $Search) { $this->Html .= "\n" . $Search['SearchString'] . ": 100% (" . $Search['Count'] . " / " . $Search['Count'] . ")
\n"; } $this->Html .= "\nPost-search filters: 100%
\n"; if (empty($this->Stage[1])) $this->Html .= "\nScore calculation: 0%
\n"; else { $total = count($this->AuthorList); $done = $this->Stage[1]; $pc = round((($done / $total) * 100), 2); $red = round($pc * 6); $grey = 600 - $red; $this->Html .= "\nCalculating score: " . $pc . "%
\n"; } } $this->Title = "AssEd: Processing searches..."; $this->OutputHtml(true); } /******************************************************************************************************************************************** * Function: PrintResults() * Prints the search results */ function PrintResults() { $_SESSION['Stage'] = $this->Stage; // Save these two variables into the session to enable re-ordering if (isset($this->AuthorList)) $_SESSION['AuthorList'] = $this->AuthorList; $this->Title = "AssEd: Search complete"; if (empty($this->AuthorList)) $this->Html .= "Sorry, it would appear that nobody has that particularly combination of skills.
\n"; else { $this->Html .= "| Author | \n"; // Print the column headers $i = 0; foreach ($this->PostData['Searches'] as $Search) { $i += 1; $this->Html .= "" . $Search['SearchString'] . "↓ | \n"; } // Check the limits if ($this->PostData['Active-All']) $this->Html .= "All pubs ↓ | \n"; if ($this->PostData['Active-5yr']) $this->Html .= "5yr ↓ | \n"; if ($this->PostData['Active']) $this->Html .= "1yr ↓ | \n"; if ($this->PostData['Active-Senior']) $this->Html .= "Last Au ↓ | \n"; if ($this->PostData['UseScores']) { $this->Html .= "Score ↓ | \n"; $this->Html .= "Avg Sc ↓ | \n"; } $this->Html .= "
|---|---|---|---|---|---|---|---|
| " . $Author . " | \n"; // Loop through the search terms for ($i = 1; $i <= $j; $i++) { $this->Html .= "PostData['Searches'][$i]['SearchString']) . ")\">" . $Items[$i] . " | \n"; } // Check the limits if ($this->PostData['Active-All']) $this->Html .= "" . $Items['All'] . " | \n"; if ($this->PostData['Active-5yr']) { $t = array(date('Y'), date('m'), date('d')); $pdat2 = implode("/", $t); $t[0] -= 5; $pdat1 = implode("/", $t); $this->Html .= "" . $Items['5yr'] . " | \n"; } if ($this->PostData['Active']) { $t = array(date('Y'), date('m'), date('d')); $pdat2 = implode("/", $t); $t[0] -= 1; $pdat1 = implode("/", $t); $this->Html .= "" . $Items['1yr'] . " | \n"; } if ($this->PostData['Active-Senior']) $this->Html .= "" . $Items['Senior'] . " | \n"; if ($this->PostData['UseScores']) { $this->Html .= "" . $Items['Score'] . " | \n"; $this->Html .= "" . $Items['AvgSc'] . " | \n"; } $this->Html .= "
Notice: Updated old cache file from v0.4 to v0.5 for '{$this->SearchTerm}'.
\n"; rename($o, $c); } /*** END TEMP FIX ***/ if (($s = $this->CheckCache()) !== 0) { // See if we already have this search cached $Attribs = $this->GetCacheAttribs(); // If the cache is up-to-date, we can fetch the attributes and then exit this search ready for the next one $this->PostData['Searches'][$this->Stage[1]]['Count'] = $Attribs['Count']; if ($s == 2) { // If the cache is old, we'll have to update it /*** CACHE UPDATER ***/ $this->CurResults = $this->GetCacheResults(); // First, extract the old cache results $old_count = count($this->CurResults); $updated = getdate($Attribs['Updated']); $updated = array($updated['year'], $updated['mon'], 01); $now = getdate(); $now = array($now['year'], $now['mon'], 01); $this->PubmedIDs(true, implode("/", $updated), implode("/", $now), false); // Add the new items to them if (!empty($this->PostData['Searches'][$this->Stage[1]]['Count'])) $this->PubmedExtractAuthors(true, false); $added = count($this->CurResults) - $old_count; $added_papers = $this->PostData['Searches'][$this->Stage[1]]['Count']; $updated[0] -= $this->MinDate; $now[0] -= $this->MinDate; $this->PubmedIDs(true, implode("/", $updated), implode("/", $now), false); // And remove the old ones if (!empty($this->PostData['Searches'][$this->Stage[1]]['Count'])) $this->PubmedExtractAuthors(true, true); $removed = ($old_count + $added) - count($this->CurResults); $removed_papers = $this->PostData['Searches'][$this->Stage[1]]['Count']; $this->PubMedIDs(); // Run a normal PubMedIDs in order to get the new hit count $this->SaveAuthors(); $new_count = count($this->CurResults); $this->StickyHtml .= "Notice: updated cache for {$this->SearchTerm}: added $added counts for $added_papers papers and removed $removed counts for $removed_papers papers. New total is $new_count authors from {$this->PostData['Searches'][$this->Stage[1]]['Count']} papers.
\n"; unset($this->CurResults); } unset($this->Translation, $this->WebEnv); return true; } /***/ // Otherwise, run the search if ($this->PubmedExtractAuthors() === false) exit; /***/ // We will only ever get this far if the search has completed // - so, we can now cache the author list $this->SaveAuthors(); unset($this->Translation, $this->WebEnv, $_SESSION['WebEnv'], $this->CurResults, $_SESSION['CurResults']); return true; } /*************************************************************************************************************************************** * Function: PubmedIds ( ) * - Gets a list of PubMed IDs and saves an Entrez session variable for later retrieval of the full items * - Using $force causes old caches to be deleted first */ function PubmedIds($force = false, $mindate = null, $maxdate = null, $escape_empty_results = true, $retmax = 20) { // Die on error -- This should NEVER occur, and can probably be deleted. if (empty($this->SearchTerm)) die( "Error: missing search term for new search in this->PubmedIds.
" ); if (empty($mindate) and empty($maxdate) and !empty($this->PostData['Searches'][$this->Stage[1]]['Since'])) { $y = date('Y') - $this->PostData['Searches'][$this->Stage[1]]['Since']; $mindate = $y . "/" . date('m') . "/01"; $maxdate = date('Y/m/01'); } require_once("lib/eSearch.php"); try { $eSearch = new eSearch( "pubmed", $this->SearchTerm, $mindate, $maxdate, $retmax ); if ($force) { $eSearch->MakeCacheName(); $eSearch->DeleteCache(); } $eSearch->Run(2); } catch (Exception $e) { $this->Html .= "Warning: caught an exception when trying to retreive the XML data from PubMed. I am going to reload the page and hope that the problem goes away. The error given was: " . $e->getMessage() . "
\n"; $eSearch->DeleteCache(); $this->SaveReload(); exit; } $this->QueryKey = $eSearch->QueryKey; // Save entrez's "session" variables $this->WebEnv = $eSearch->WebEnv; $this->Count = $eSearch->Count; if ($escape_empty_results and empty($eSearch->Count)) { // Check that pubmed actually has some entries matching the query $this->Html .= "Sorry, PubMed has no items matching your search for " . $QueryData['term'] . ". Check your spelling, or try an older date cutoff.
\n"; $this->OutputHtml(); exit; } if ($this->Stage[0] == "searches") { $this->PostData['Searches'][$this->Stage[1]]['Translation'] = substr($eSearch->Translation, 0, -40); // Cut everything outside the brackets in the translation -- this cuts off the EDAT conditions to make a cache month non-specific $this->PostData['Searches'][$this->Stage[1]]['Count'] = $this->Count; // Update the counts (GetCounts() does not support data ranges) } unset($eSearch); return true; } /**************************************************************************************************************************************** * Function PubmedExtractAuthors ( single, reverse, noisy ) * - Takes the search and finds all authors * I'm not entirely sure what the most efficient way of doing this is. I have tried using the XML>Array function, but this is * insanely memory intensive. The simple loop and text-search works, but I'm not convinced that there aren't better ways (a * preg_match, perhaps?) to do it. * Input vars: * - Single: gets all results in a single file rather than [$ncbi_RetMax] items at a time (used when updating caches at the start of the month) * - Reverse: subtracts matching authors from the list, instead of increasing their counts * - Noisy: debug mode -- prints the list of changed authors */ function PubmedExtractAuthors($single = false, $reverse = false) { Global $ncbi_CachePath, $ncbi_RetMax; // Check if we have a partial cache if (!$single and ($this->Stage[2] == 1)) { $i = 50001; while (true) { $c = $ncbi_CachePath . "AssEd/tmp/" . trim($this->MinDate, ".") . "," . md5($this->Translation) . "," . $i; if ((file_exists($c)) and (date('Y', filectime($c)) == date('Y')) and (date('m', filectime($c)) == date('m'))) { $this->Stage[2] = $i; $i += 50000; $_SESSION['Cleanup'][] = $c; continue; } else break; } } // Run the search require_once("lib/eSummary.php"); try { $eSummary = new eSummary( "pubmed", $this->QueryKey, $this->WebEnv, $this->Stage[2], $ncbi_RetMax ); $eSummary->Identifier = $this->MinDate . "-" . $this->Translation; if ($single) $eSummary->RetMax = $this->PostData['Searches'][$this->Stage[1]]['Count']; // If we're retrieving this as a single file, amend the "retmax" to get all of the results $eSummary->Run(); if (!empty($eSummary->Html)) $this->Html .= $eSummary->Html; // Save any HTML messages generated by eSummary $_SESSION['Cleanup'][] = $eSummary->CacheName; // Prepare to delete the cache file when done } catch (Exception $e) { $this->Html .= "Warning: caught an exception when trying to retreive the XML data from PubMed. I am going to clear the cache, reload the page, and hope that the problem goes away. The error given was: " . $e->getMessage() . "
\n"; $eSummary->DeleteCache(); $this->PubmedIds(true); $this->SaveReload(); exit; } $lines = explode("\n", $eSummary->Xml); // Extract all of the authors from the XML string unset($eSummary); // destroy eSummary so as to save on memory foreach ($lines as $line) { $line = trim($line); if (substr($line, 0, 34) == "Warning: caught an exception when trying to retreive the XML data from PubMed. I am going to reload the page and hope that the problem goes away. The error given was: " . $e->getMessage() . "
\n"; $this->SaveReload(); exit; } if (isset($r)) return $r; else return true; } /**************************************************************************************************************************************** * Function: PubmedIgnore ( Author ) * - Checks whether the author matches the entries in the ignore list */ function PubmedIgnore($key) { $s = $key . " AND (" . $this->PostData['Ignore'] . ")"; require_once("lib/eSearch.php"); try{ $eSearch = new eSearch( "pubmed", $s, $this->PostData['IgnoreCoAus'], date('Y/m/d'), 20, "count"); $eSearch->Run(2); if (!empty($eSearch->Count)) return true; } catch (Exception $e) { $this->Html .= "Warning: caught an exception when trying to retreive the XML data from PubMed. I am going to reload the page and hope that the problem goes away. The error given was: " . $e->getMessage() . "
\n"; $this->SaveReload(); exit; } return false; } /**************************************************************************************************************************************** * Function: CalculateScore ( Author ) * - Calculates a score for Author */ function CalculateScore($Author) { $this->Stage = array("scores", $Author, 0); $this->SearchTerm = "\"" . $Author . "\""; // First, get the author's publication list and produce an array containing information about those publications require_once("lib/eSearch.php"); require_once("lib/eSummary.php"); try { $eSearch = new eSearch( "pubmed", $this->SearchTerm, "1900/01/01", date('Y/m/01')); $eSearch->Run(2); } catch (Exception $e) { $this->Html .= "Warning: caught an exception when trying to retreive the XML data from PubMed. I am going to reload the page and hope that the problem goes away. The error given was: " . $e->getMessage() . "
\n"; $this->SaveReload(); exit; } try { $eSummary = new eSummary("pubmed", $eSearch->QueryKey, $eSearch->WebEnv, 0, $eSearch->Count); $eSummary->Run(1); } catch (Exception $e) { $this->Html .= "Warning: caught an exception when trying to retreive the XML data from PubMed. I am going to reload the page and hope that the problem goes away. The error given was: " . $e->getMessage() . "
\n"; $this->SaveReload(); exit; } foreach ($eSummary->Array['DocSum'] as $Pub) { // Open the score by first/last authorship if (!is_array($Pub['AuthorList']) OR !isset($Pub['AuthorList']['Author']) OR !is_array($Pub['AuthorList']['Author'])) $PubList[$Pub['Id']] = $this->PostData['ScoreFirstAu']; elseif (!empty($this->PostData['ScoreFirstAu']) and ($Pub['AuthorList']['Author'][0] == $Author)) $PubList[$Pub['Id']] = $this->PostData['ScoreFirstAu']; elseif (!empty($this->PostData['ScoreLastAu']) and ($Pub['LastAuthor'] == $Author)) $PubList[$Pub['Id']] = $this->PostData['ScoreLastAu']; else $PubList[$Pub['Id']] = 1; if (!empty($this->PostData['WeightJournal']) and (in_array($Pub['Source'], $this->PostData['ScoreJournal']) OR in_array($Pub['ISSN'], $this->PostData['ScoreJournal']) OR in_array($Pub['Source'], $this->PostData['FullJournalName']))) $PubList[$Pub['Id']] = $PubList[$Pub['Id']] * $this->PostData['WeightJournal']; if (!empty($this->PostData['WeightDoi']) and !empty($Pub['DOI'])) { $Doi = explode("/", $Pub['DOI']); if (in_array($Doi[0], $this->PostData['ScoreDoi'])) $PubList[$Pub['Id']] = $PubList[$Pub['Id']] * $this->PostData['WeightDoi']; } // Weight the score by age if ($this->PostData['ScoreAge']) { $Timestamp = strtotime($Pub['PubDate']); $Age = time() - $Timestamp; $Age = $Age / 31570560; if ($Age < 1) $Weight = 2; // If the publication is less than a year old, double the score else $Weight = 0.5 + (1 / $Age); // Otherwise, weight it by 0.5 + (1 / Age) $PubList[$Pub['Id']] = $PubList[$Pub['Id']] * $Weight; } } // now weight those which matched our searches if (!empty($this->PostData['ScoreProportions'])) { // First get the matching IDs for each search foreach ($this->PostData['Searches'] as $Search) { $this->SearchTerm = "\"" . $Author . "\" (" . $Search['SearchString'] . ")"; try { $eSearch = new eSearch( "pubmed", $this->SearchTerm, "1900/01/01", date('Y/m/01'), $Search['AtMost']); $eSearch->Run(2); } catch (Exception $e) { $this->Html .= "Warning: caught an exception when trying to retreive the XML data from PubMed. I am going to reload the page and hope that the problem goes away. The error given was: " . $e->getMessage() . "
\n"; $this->SaveReload(); exit; } $IdLists[$Search['SearchString']] = $eSearch->IdList; // Calculate the weight to be given to each search -- the weight diminishes logarithmically thus giving additional weight to rare terms // ***** If editing these, also edit AuthorProfile.php! **** $weight[$Search['SearchString']] = 2; if ($Search['Count'] < 1000000) $weight[$Search['SearchString']] = 3; if ($Search['Count'] < 100000) $weight[$Search['SearchString']] = 4; if ($Search['Count'] < 10000) $weight[$Search['SearchString']] = 6; if ($Search['Count'] < 1000) $weight[$Search['SearchString']] = 9; if ($Search['Count'] < 100) $weight[$Search['SearchString']] = 13; } // Now amend the scores for the matching items foreach($PubList as $k => &$v) { foreach($IdLists as $SearchString => $IdList) { if (in_array($k, $IdList)) $v = $v * $weight[$SearchString]; } } } $count = count($PubList); // Now compile the scores $score = array_sum($PubList); // And adjust according to optimum publication range /* if (!empty($this->PostData['ScoreOptimalLow']) and !empty($this->PostData['ScoreOptimalHigh'])) { $d = 1; if ($count < $this->PostData['ScoreOptimalLow']) $d = ($this->PostData['ScoreOptimalLow'] - $count); elseif ($count > $this->PostData['ScoreOptimalHigh']) $d = ($count - $this->PostData['ScoreOptimalHigh']); $weight = 1 / $d; $score = $score * $weight; } */ $score = round($score * 100); return $score; } /************************************************************************************************************************************************* FILESYSTEM/CACHE FUNCTIONS ************************** 1. GetCacheName - returns full path to md5 hashed translated query filename 2. GetCacheAttribs - returns an assoc for the file metadata above the [Results] header 3. GetCacheResults - returns an assoc for the search results 4. CheckCache - checks to see if the cache file exists, and if so, if it is current 5. SaveAuthors - dumps the author list in a cache file 6. TempSave - dumps the author list to a temporary file - this saves memory and cpu as the CurResults array grows, and also prevents loss of data if search is interrupted 7. TempRead - extracts the author list from the temporary file and reads it back into this->CurResults **************************************************************************************************************************************************/ /*************************************************************************************************************************************** * Function: GetCacheName ( ) * - Makes the cache filename */ function GetCacheName($Search = null, $Path = null) { Global $ncbi_CachePath; if (empty($Search)) $Search = $this->Stage[1]; // Set the QueryTranslation to the currently active query $Translation = $this->PostData['Searches'][$Search]['Translation']; $MinDate = str_replace("/", "", $this->PostData['Searches'][$Search]['Since']); // Escape slashes from date -- I don't think there is any possible way that this script could be used for a filesystem attack, but best be safe... if (empty($Path)) $Path = "author_lists/"; // The default path is to the final author lists cache $f = $ncbi_CachePath . "AssEd/" . $Path . $MinDate . "-" . md5($Translation) . ".txt"; // Build the filename from the full path and md5 scrambled translation return $f; } /*************************************************************************************************************************************** * Function GetCacheAttribs * - Gets everything above the [Results] section from the cache file */ function GetCacheAttribs($Search = null) { if (empty($Search)) $Search = $this->Stage[1]; // Set the QueryTranslation to the currently active query $f = $this->GetCacheName($Search); if (!file_exists($f)) { $this->StickyHtml .= "Warning: script ran GetCacheAttribs() on a non-existent cache.
\n"; return 0; // Return 0 for files which do not exist } $x = file_get_contents($f); // Extract from the file $x = str_replace("\r\n", "\n", $x); // This is a (temp?) fix for processing *nix generated author lists on windows servers $a = explode("[Results]\n", $x); $a = explode("\n", $a[0]); foreach ($a as $k => $v) { if (empty($v)) continue; $v = explode("=", $v); $r[$v[0]] = $v[1]; } /*** TEMP FIX ***/ // This is for v0.3 cache files which had Expiry attributes not Updated attribs. It can be deleted once the old cache files have been updated if (empty($r['Updated'])) $r['Updated'] = filectime($f); return $r; } /*************************************************************************************************************************************** * Function GetCacheResults * - Extracts the author list from a cache file and returns it as an array */ function GetCacheResults($Search = null, $AtLeast = null, $AtMost = null) { if (empty($Search)) $Search = $this->Stage[1]; // Set the QueryTranslation to the currently active query if (!$this->CheckCache($Search)) return false; // If the cache doesn't exist, return false $f = $this->GetCacheName($Search); $x = file_get_contents($f); // Extract from the file $x = str_replace("\r\n", "\n", $x); // This is a (temp?) fix for processing *nix generated author lists on windows servers $a = explode("[Results]\n", $x); $a = explode("\n", $a[1]); foreach ($a as $k => $v) { if (empty($v)) continue; $v = explode("=", $v); if (isset($AtLeast) and ($v[1] < $AtLeast)) continue; if (isset($AtMost) and ($v[1] > $AtMost)) continue; $r[$v[0]] = $v[1]; } return $r; } /*************************************************************************************************************************************** * Function CheckCache * - checks to see if the cache file exists, and if so, if it is current */ function CheckCache($Search = null) { if (empty($Search)) $Search = $this->Stage[1]; // Set the QueryTranslation to the currently active query $f = $this->GetCacheName($Search); if (!file_exists($f)) return 0; // Return 0 for files which do not exist $a = $this->GetCacheAttribs($Search); if ((date('Y', $a['Updated']) == date('Y')) and (date('m', $a['Updated']) == date('m'))) return 1; // Return 1 for files which are up-to-date return 2; // Return 2 for files which need updating } /**************************************************************************************************************************************** * Function: SaveAuthors * - I wanted to use an XML layout for the saved authors list, but that considerably raises the amount of memory required (e.g. to get * the array back out of the xml file). Therefore, we have to put up with a cheap and dirty solution * - In v0.4 this had a "TempSave" option, now moved to a dedicated function */ function SaveAuthors() { $cutoff = 1; // If there are too many results, we can ignore all who have only one item $total = count($this->CurResults); // for the sake of performance if ($total > 250000) $cutoff = 2; // (the original cutoff was based on results for the search - i.e. this->PostData[Searches][n][Count]) foreach ($this->CurResults as $author => $count) { if ($count >= $cutoff) $a[] = $author . "=" . $count; } if ($this->CheckCache() and ($o = $this->GetCacheAttribs())) { // Find out when the cache was first made if (!empty($o['Created'])) $Created = $o['Created']; // This if/else is to cope with pre v0.5 cache files which do not have the created else $Created = $o['Updated']; // data - when those cache files have been updated, this can be removed. } else $Created = time(); $t = "SearchTerm=" . $this->SearchTerm . "\nMinDate=" . $this->MinDate . "\nQueryTranslation=" . $this->Translation ."\nCreated=" . $Created ."\nUpdated=" . time() . "\nCount=" . $this->PostData['Searches'][$this->Stage[1]]['Count'] . "\nAuCount=" . count($this->CurResults) . "\n\n[Results]\n" . implode("\n", $a); $c = $this->GetCacheName(); // Save the cache to the file if (file_exists($c)) unlink($c); $f = fopen($c, 'w+'); fwrite($f, $t); fclose($f); unset($a, $t, $f, $o); if (!empty($_SESSION['Cleanup'])) foreach ($_SESSION['Cleanup'] as $f) { if (file_exists($f)) unlink($f); } // At this point we can delete the redundant XML files return true; } /**************************************************************************************************************************************** * Function: TempSave * - Makes a temporary file of results part way through the search just in-case it gets interrupted * - Moved out from SaveAuthors in v0.5 */ function TempSave() { Global $ncbi_CachePath; $c = $ncbi_CachePath . "AssEd/tmp/" . trim($this->MinDate, ".") . "," . md5($this->Translation) . "," . $this->Stage[2]; foreach ($this->CurResults as $author => $count) { $a[] = $author . "=" . $count; } $t = "[Results]\n" . implode("\n", $a); // Stripped down version of SaveAuthors(); if (file_exists($c)) unlink($c); $f = fopen($c, 'w+'); fwrite($f, $t); fclose($f); $_SESSION['Cleanup'][] = $c; // Add this to the list of temporary files which will need deleting at the end of the search return true; } /**************************************************************************************************************************************** * Function TempRead * - Extracts saved authors from temporary files and reads them into the CurResults array */ function TempRead() { Global $ncbi_CachePath; $i = 50001; while ($i <= $this->PostData['Searches'][$this->Stage[1]]['Count']) { $c = $ncbi_CachePath . "AssEd/tmp/" . trim($this->MinDate, ".") . "," . md5($this->Translation) . "," . $i; if (file_exists($c)) { $x = file_get_contents($c); $x = str_replace("\r\n", "\n", $x); // This is a fix for processing *nix generated author lists on windows servers $a = explode("[Results]\n", $x); unset($x, $c); $a = explode("\n", $a[1]); foreach ($a as $k => $r) { $r = explode("=", $r); if (empty($r[1])) continue; if (!empty($this->CurResults[$r[0]])) $this->CurResults[$r[0]] += $r[1]; else $this->CurResults[$r[0]] = $r[1]; unset($a[$k], $r); // Memory saving device -- very large datasets can cause the memory to exceed 512M here } $i += 50000; continue; } else break; } return true; } } ?>