Faster import, better admin panel.
This commit is contained in:
parent
717303e475
commit
5c477f9b7f
4 changed files with 68 additions and 21 deletions
|
@ -84,6 +84,7 @@ function run_submit($url) {
|
||||||
elseif($parms['explicit-hide'] && $profile_exists) {
|
elseif($parms['explicit-hide'] && $profile_exists) {
|
||||||
logger('User opted out of the directory.');
|
logger('User opted out of the directory.');
|
||||||
nuke_record($url);
|
nuke_record($url);
|
||||||
|
return true; //This is a good update.
|
||||||
}
|
}
|
||||||
|
|
||||||
//This is most likely a problem with the site configuration. Ignore.
|
//This is most likely a problem with the site configuration. Ignore.
|
||||||
|
@ -95,7 +96,7 @@ function run_submit($url) {
|
||||||
if($profile_exists) {
|
if($profile_exists) {
|
||||||
nuke_record($url);
|
nuke_record($url);
|
||||||
}
|
}
|
||||||
return false;
|
return true; //This is a good update.
|
||||||
}
|
}
|
||||||
|
|
||||||
$photo = $parms['photo'];
|
$photo = $parms['photo'];
|
||||||
|
@ -210,13 +211,13 @@ function run_submit($url) {
|
||||||
|
|
||||||
$status = false;
|
$status = false;
|
||||||
|
|
||||||
|
if($profile_id) {
|
||||||
$img_str = fetch_url($photo,true);
|
$img_str = fetch_url($photo,true);
|
||||||
$img = new Photo($img_str);
|
$img = new Photo($img_str);
|
||||||
if($img) {
|
if($img) {
|
||||||
$img->scaleImageSquare(80);
|
$img->scaleImageSquare(80);
|
||||||
$r = $img->store($profile_id);
|
$r = $img->store($profile_id);
|
||||||
}
|
}
|
||||||
if($profile_id) {
|
|
||||||
$r = q("UPDATE `profile` SET `photo` = '%s' WHERE `id` = %d LIMIT 1",
|
$r = q("UPDATE `profile` SET `photo` = '%s' WHERE `id` = %d LIMIT 1",
|
||||||
dbesc($a->get_baseurl() . '/photo/' . $profile_id . '.jpg'),
|
dbesc($a->get_baseurl() . '/photo/' . $profile_id . '.jpg'),
|
||||||
intval($profile_id)
|
intval($profile_id)
|
||||||
|
@ -225,6 +226,7 @@ function run_submit($url) {
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
nuke_record($url);
|
nuke_record($url);
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
$submit_end = microtime(true);
|
$submit_end = microtime(true);
|
||||||
|
|
|
@ -18,11 +18,11 @@ function admin_content(&$a) {
|
||||||
$flagged = '';
|
$flagged = '';
|
||||||
foreach($r as $rr) {
|
foreach($r as $rr) {
|
||||||
if($rr['reason'] == 1)
|
if($rr['reason'] == 1)
|
||||||
$str = 'Censor';
|
$str = 'Adult';
|
||||||
if($rr['reason'] == 2)
|
if($rr['reason'] == 2)
|
||||||
$str = 'Dead';
|
$str = 'Dead';
|
||||||
$flagged .= '<a href="' . 'moderate/' . $rr['pid'] . '/' . $str . '">'.
|
$flagged .= '<a href="' . 'moderate/' . $rr['pid'] . '/' . $rr['reason'] . '">'.
|
||||||
"$str profile: [#{$rr['pid']}] {$rr['name']} ({$rr['total']}x) - {$rr['homepage']}</a><br />";
|
"{$rr['total']}x $str - [#{$rr['pid']}] {$rr['name']} ({$rr['homepage']})</a><br />";
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$flagged = 'No entries.';
|
$flagged = 'No entries.';
|
||||||
|
@ -67,6 +67,7 @@ function admin_post(&$a)
|
||||||
if($batch){
|
if($batch){
|
||||||
|
|
||||||
require_once('include/submit.php');
|
require_once('include/submit.php');
|
||||||
|
require_once('include/site-health.php');
|
||||||
|
|
||||||
//First get all data from file.
|
//First get all data from file.
|
||||||
$data = file_get_contents($file);
|
$data = file_get_contents($file);
|
||||||
|
@ -95,10 +96,21 @@ function admin_post(&$a)
|
||||||
$_SESSION['import_total']++;
|
$_SESSION['import_total']++;
|
||||||
$_SESSION['import_failed']++;
|
$_SESSION['import_failed']++;
|
||||||
try{
|
try{
|
||||||
|
|
||||||
|
//A site may well turn 'sour' during the import.
|
||||||
|
//Check the health again for this reason.
|
||||||
|
$site = parse_site_from_url($url);
|
||||||
|
$r = q("SELECT * FROM `site-health` WHERE `base_url`= '%s' ORDER BY `id` ASC LIMIT 1", $site);
|
||||||
|
if(count($r) && intval($r[0]['health_score']) < $a->config['site-health']['skip_import_threshold']){
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
//Do the submit if health is ok.
|
||||||
if(run_submit($url)){
|
if(run_submit($url)){
|
||||||
$_SESSION['import_failed']--;
|
$_SESSION['import_failed']--;
|
||||||
$_SESSION['import_success']++;
|
$_SESSION['import_success']++;
|
||||||
}
|
}
|
||||||
|
|
||||||
}catch(\Exception $ex){/* We tried... */}
|
}catch(\Exception $ex){/* We tried... */}
|
||||||
}
|
}
|
||||||
else break;
|
else break;
|
||||||
|
@ -106,17 +118,18 @@ function admin_post(&$a)
|
||||||
|
|
||||||
$left = count($list);
|
$left = count($list);
|
||||||
|
|
||||||
$s = $_SESSION['import_success'];
|
$success = $_SESSION['import_success'];
|
||||||
|
$skipped = $_SESSION['import_skipped'];
|
||||||
$total = $_SESSION['import_total'];
|
$total = $_SESSION['import_total'];
|
||||||
$errors = $_SESSION['import_failed'];
|
$errors = $_SESSION['import_failed'];
|
||||||
if($left > 0){
|
if($left > 0){
|
||||||
notice("$left items left in batch.<br>Stats: $s / $total success, $errors errors.");
|
notice("$left items left in batch...<br>$success updated profiles.<br>$errors import errors.");
|
||||||
file_put_contents($file, implode("\r\n", $list));
|
file_put_contents($file, implode("\r\n", $list));
|
||||||
$fid = uniqid('autosubmit_');
|
$fid = uniqid('autosubmit_');
|
||||||
echo '<form method="POST" id="'.$fid.'"><input type="hidden" name="batch_submit" value="1"></form>'.
|
echo '<form method="POST" id="'.$fid.'"><input type="hidden" name="batch_submit" value="1"></form>'.
|
||||||
'<script type="text/javascript">setTimeout(function(){ document.getElementById("'.$fid.'").submit(); }, 500);</script>';
|
'<script type="text/javascript">setTimeout(function(){ document.getElementById("'.$fid.'").submit(); }, 300);</script>';
|
||||||
} else {
|
} else {
|
||||||
notice("Completed batch! $s / $total success. $errors errors.");
|
notice("Completed batch! $success updated. $errors errors.");
|
||||||
unlink($file);
|
unlink($file);
|
||||||
unset($_SESSION['import_progress']);
|
unset($_SESSION['import_progress']);
|
||||||
}
|
}
|
||||||
|
@ -124,8 +137,12 @@ function admin_post(&$a)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Doing a poll from the directory?
|
||||||
elseif($url){
|
elseif($url){
|
||||||
|
|
||||||
|
require_once('include/site-health.php');
|
||||||
|
|
||||||
$result = fetch_url($url."/lsearch?p=$page&n=$perPage&search=.*");
|
$result = fetch_url($url."/lsearch?p=$page&n=$perPage&search=.*");
|
||||||
if($result)
|
if($result)
|
||||||
$data = json_decode($result);
|
$data = json_decode($result);
|
||||||
|
@ -136,8 +153,33 @@ function admin_post(&$a)
|
||||||
|
|
||||||
$rows = '';
|
$rows = '';
|
||||||
foreach($data->results as $profile){
|
foreach($data->results as $profile){
|
||||||
$rows .= $profile->url."\r\n";
|
|
||||||
|
//Skip known profiles.
|
||||||
|
$purl = $profile->url;
|
||||||
|
$nurl = str_replace(array('https:','//www.'), array('http:','//'), $purl);
|
||||||
|
$r = q("SELECT count(*) as `matched` FROM `profile` WHERE (`homepage` = '%s' OR `nurl` = '%s') LIMIT 1",
|
||||||
|
dbesc($purl),
|
||||||
|
dbesc($nurl)
|
||||||
|
);
|
||||||
|
if(count($r) && $r[0]['matched']){
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Find out site health.
|
||||||
|
else{
|
||||||
|
|
||||||
|
$site = parse_site_from_url($purl);
|
||||||
|
$r = q("SELECT * FROM `site-health` WHERE `base_url`= '%s' ORDER BY `id` ASC LIMIT 1", $site);
|
||||||
|
if(count($r) && intval($r[0]['health_score']) < $a->config['site-health']['skip_import_threshold']){
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
$rows .= $profile->url."\r\n";
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
file_put_contents($file, $rows, $page > 0 ? FILE_APPEND : 0);
|
file_put_contents($file, $rows, $page > 0 ? FILE_APPEND : 0);
|
||||||
|
|
||||||
$progress = min((($page+1) * $perPage), $data->total);
|
$progress = min((($page+1) * $perPage), $data->total);
|
||||||
|
@ -153,7 +195,7 @@ function admin_post(&$a)
|
||||||
'<script type="text/javascript">setTimeout(function(){ document.getElementById("'.$fid.'").submit(); }, 500);</script>';
|
'<script type="text/javascript">setTimeout(function(){ document.getElementById("'.$fid.'").submit(); }, 500);</script>';
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
goaway($a->get_baseurl().'/import');
|
goaway($a->get_baseurl().'/admin');
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -135,12 +135,12 @@ function moderate_content(&$a) {
|
||||||
$c .= '<br />' . $rr['homepage'] . '<br />';
|
$c .= '<br />' . $rr['homepage'] . '<br />';
|
||||||
|
|
||||||
$o .= '<form action="moderate" method="post" >';
|
$o .= '<form action="moderate" method="post" >';
|
||||||
$checked = (($reason === 'censor') ? 'checked="checked" ' : '');
|
$checked = (($reason === '1') ? 'checked="checked" ' : '');
|
||||||
$o .= '<input type="radio" name="action" value="censor"' . $checked . '>Censor Profile<br /><br />';
|
$o .= '<label><input type="radio" name="action" value="censor"' . $checked . '>Censor Profile</label><br /><br />';
|
||||||
$checked = (($reason === 'dead') ? 'checked="checked" ' : '');
|
$checked = (($reason === '2') ? 'checked="checked" ' : '');
|
||||||
$o .= '<input type="radio" name="action" value="dead"' . $checked . '" >Dead Account<br /><br />';
|
$o .= '<label><input type="radio" name="action" value="dead"' . $checked . '" >Dead Account</label><br /><br />';
|
||||||
|
|
||||||
$o .= '<input type="radio" name="action" value="bogus" >Bogus request<br /><br />';
|
$o .= '<label><input type="radio" name="action" value="bogus" >Bogus request</label><br /><br />';
|
||||||
|
|
||||||
|
|
||||||
$o .= '<input type="hidden" name="id" value="' . $id . '" ><br /><br />';
|
$o .= '<input type="hidden" name="id" value="' . $id . '" ><br /><br />';
|
||||||
|
|
|
@ -1603,8 +1603,11 @@ input#dfrn-url {
|
||||||
}
|
}
|
||||||
|
|
||||||
.flagged-entries{
|
.flagged-entries{
|
||||||
max-height:500px;
|
max-height:315px;
|
||||||
overflow:auto;
|
overflow:auto;
|
||||||
|
border:1px solid #ccc;
|
||||||
|
padding:5px;
|
||||||
|
line-height:1.3em;
|
||||||
}
|
}
|
||||||
|
|
||||||
.profile-moderate-preview{
|
.profile-moderate-preview{
|
||||||
|
|
Loading…
Reference in a new issue