function arcmaj3_handler() { #do things... if (Rq('amtask') == 'up') { #Client has finished a barrel. Parse new URL list provided and add to URLs table. Mark barrel's original URLs as completed, excluding URLs that ran into problems. Mark barrel as finished. #For now, all that will be provided here is an Internet Archive identifier. #Check for duplicates. Add new unique URLs matching intake criteria (matching an existing project) to URLs table. } else { if (Rq('amtask') == 'down') { #Client wants a barrel. Compile random URLs from the URL table of unfinished URLs and create a barrel. Mark the URLs as taken. Add barrel to barrels table. #For now, choose an uncompleted URL from the table, and send it. #Barrel format 0.1: #ID,0xURL\n $db = new FractureDB('arcmaj3'); $rowToReturn = $db->getRandomRow('am_urls'); #echo $rowToReturn['id'].','.$rowToReturn['location']; #Barrel format 0.11: #0xURL\n echo 'doom' . $rowToReturn['location'] . "\n"; echo "http://drive.google.com/\n"; // echo "http://wretch.cc/\n"; // echo "http://example.com/\n"; // echo "http://comments.gmane.org/gmane.mail.squirrelmail.plugins/9672\n"; echo "http://futuramerlin.com\n"; // echo "http://archive.org\n"; // echo "https://archive.org\n"; } else { echo 'Unrecognized operation'; } } }
function arcmaj3_handler() { #do things... if (Rq('amtask') == 'up') { echo 'Uploaded barrel received.'; #Client has finished a barrel. Parse new URL list provided and add to URLs table. Mark barrel's original URLs as completed, excluding URLs that ran into problems. Mark barrel as finished. #For now, all that will be provided here is an Internet Archive identifier. #Check for duplicates. Add new unique URLs matching intake criteria (matching an existing project) to URLs table. // $ulBarrel = file_get_contents($_FILES['uploadedBarrelData']['tmp_name']); // $ulFailed = file_get_contents($_FILES['failedUrlData']['tmp_name']); $ulBarrel = preg_replace('/[\\n]+/', "\n", str_replace('\\nhttp://http://', 'http://', base64_decode(Rq('uploadedBarrelData')))); echo 'ulBarrel:' . "\n\n"; //print_r($ulBarrel); echo "\n\n"; echo "\n\n"; $ulFailed = preg_replace('/[\\n]+/', "\n", base64_decode(Rq('failedUrlData'))); $ulBarrel = str_replace("\r", "\n", $ulBarrel); $ulFailed = str_replace("\r", "\n", $ulFailed); $barrelData = explode("\n", $ulBarrel); print_r($barrelData); echo "\n\n"; $failedData = explode("\n", $ulFailed); print_r($failedData); $barrelId = $barrelData[0]; $barrelUserName = $barrelData[1]; $db = new FractureDB('arcmaj3'); $urlsFinished = $db->getRows('am_urls', 'barrel', $barrelId); #Set status to 1. Set who to $barrelUserName. $db->setField('am_barrels', 'status', 1, $barrelId); $db->setField('am_barrels', 'who', $barrelUserName, $barrelId); foreach ($barrelData as $value) { #Add URL to URL list. $potentialProject = get_domain_simple($value); $projects = $db->getRow('am_projects', 'urlPattern', $potentialProject); $projectId = $projects['id']; #$projectId=1; if (strlen($projects['id']) !== 0) { $newUrlId = $db->addRow('am_urls', 'location, project, locationHashUnique', "'" . $value . "', '" . $projectId . "', '" . hash('sha512', $value) . "'"); } } foreach ($urlsFinished as $value) { #Set completed to true. $db->setField('am_urls', 'completed', 1, $value); } foreach ($failedData as $value) { #TODO: Increment failedAttempts, set completed to false, set barrel to 0 $potentialProject = get_domain_simple($value); $projects = $db->getRow('am_projects', 'urlPattern', $potentialProject); $projectId = $projects['id']; $db->addRow('am_urls', 'location, project, locationHashUnique', "'" . $value . "', '" . $projectId . "', '" . hash('sha512', $value) . "'"); $failedRowIdRecord = $db->getRow('am_urls', 'location', $value); $failedRowId = $failedRowIdRecord['id']; echo "\n\nWorking with failed row {$value}, ID {$failedRowId}"; $currentFailed = $db->getField('am_urls', 'failedAttempts', $failedRowId); $currentFailed++; $db->setField('am_urls', 'failedAttempts', $currentFailed, $failedRowId); $db->setField('am_urls', 'completed', 0, $failedRowId); $db->setField('am_urls', 'barrel', 0, $failedRowId); } } else { if (Rq('amtask') == 'down') { #Client wants a barrel. Compile random URLs from the URL table of unfinished URLs and create a barrel. Mark the URLs as taken. Add barrel to barrels table. #For now, choose an uncompleted URL from the table, and send it. #Number of URLs per bucket: $urlsPerBucket = 50; #Barrel format 0.1: #ID,0xURL\n $db = new FractureDB('arcmaj3'); #Make a new barrel. $newBarrelId = $db->addRow('am_barrels', 'status, who, dateAssigned', "'0', '" . Rq('userName') . "', '" . date('Y') . "-" . date('m') . "-" . date('d') . "'"); echo $newBarrelId . "\n"; $urlCounter = 0; while ($urlCounter < $urlsPerBucket) { $rowToReturn = $db->getRandomRow('am_urls', 'barrel', '0'); $db->setField('am_urls', 'barrel', $newBarrelId, $rowToReturn['id']); #echo $rowToReturn['id'].','.$rowToReturn['location']; #Barrel format 0.11: #0xURL\n echo $rowToReturn['location'] . "\n"; $urlCounter++; } // echo "http://drive.google.com/\n"; // echo "http://wretch.cc/\n"; // echo "http://example.com/\n"; // echo "http://comments.gmane.org/gmane.mail.squirrelmail.plugins/9672\n"; // echo "http://futuramerlin.com\n"; // echo "http://archive.org\n"; // echo "https://archive.org\n"; } else { if (Rq('amtask') == 'expireBarrel') { $db = new FractureDB('arcmaj3'); $barrelId = Rq('barrelId'); $db->updateColumn('am_urls', 'barrel', '0', 'barrel', $barrelId); $db->setField('am_barrels', 'status', '2', $barrelId); echo 'Expired barrel ' . $barrelId . '.'; } else { echo 'Unrecognized operation'; } } } }
function arcmaj3_handler() { #do things... if (Rq('amtask') == 'up') { #Client has finished a barrel. Parse new URL list provided and add to URLs table. Mark barrel's original URLs as completed, excluding URLs that ran into problems. Mark barrel as finished. #For now, all that will be provided here is an Internet Archive identifier. } else { if (Rq('amtask') == 'down') { #Client wants a barrel. Compile random URLs from the URL table of unfinished URLs and create a barrel. Mark the URLs as taken. Add barrel to barrels table. #For now, choose an uncompleted URL from the table, and send it. #Barrel format 0.1: #ID,0xURL\n $db = new FractureDB('arcmaj3'); $rowToReturn = $db->getRandomRow('am_urls'); #echo $rowToReturn['id'].','.$rowToReturn['location']; #Barrel format 0.11: #0xURL\n echo 'doom' . $rowToReturn['location'] . "\n"; } else { echo 'Unrecognized operation'; } } }