From 5c477f9b7fef7a1f66e7726307a572642673400e Mon Sep 17 00:00:00 2001 From: Beanow Date: Fri, 11 Jul 2014 01:35:30 +0200 Subject: [PATCH] Faster import, better admin panel. --- include/submit.php | 16 +++++----- mod/admin.php | 58 +++++++++++++++++++++++++++++++----- mod/moderate.php | 10 +++---- view/theme/default/style.css | 5 +++- 4 files changed, 68 insertions(+), 21 deletions(-) diff --git a/include/submit.php b/include/submit.php index 23cf829b..00d5b983 100644 --- a/include/submit.php +++ b/include/submit.php @@ -84,6 +84,7 @@ function run_submit($url) { elseif($parms['explicit-hide'] && $profile_exists) { logger('User opted out of the directory.'); nuke_record($url); + return true; //This is a good update. } //This is most likely a problem with the site configuration. Ignore. @@ -95,7 +96,7 @@ function run_submit($url) { if($profile_exists) { nuke_record($url); } - return false; + return true; //This is a good update. } $photo = $parms['photo']; @@ -210,13 +211,13 @@ function run_submit($url) { $status = false; - $img_str = fetch_url($photo,true); - $img = new Photo($img_str); - if($img) { - $img->scaleImageSquare(80); - $r = $img->store($profile_id); - } if($profile_id) { + $img_str = fetch_url($photo,true); + $img = new Photo($img_str); + if($img) { + $img->scaleImageSquare(80); + $r = $img->store($profile_id); + } $r = q("UPDATE `profile` SET `photo` = '%s' WHERE `id` = %d LIMIT 1", dbesc($a->get_baseurl() . '/photo/' . $profile_id . '.jpg'), intval($profile_id) @@ -225,6 +226,7 @@ function run_submit($url) { } else{ nuke_record($url); + return false; } $submit_end = microtime(true); diff --git a/mod/admin.php b/mod/admin.php index 72b161ca..13886ba1 100755 --- a/mod/admin.php +++ b/mod/admin.php @@ -18,11 +18,11 @@ function admin_content(&$a) { $flagged = ''; foreach($r as $rr) { if($rr['reason'] == 1) - $str = 'Censor'; + $str = 'Adult'; if($rr['reason'] == 2) $str = 'Dead'; - $flagged .= ''. - "$str profile: [#{$rr['pid']}] {$rr['name']} ({$rr['total']}x) - {$rr['homepage']}
"; + $flagged .= ''. + "{$rr['total']}x $str - [#{$rr['pid']}] {$rr['name']} ({$rr['homepage']})
"; } } else { $flagged = 'No entries.'; @@ -67,6 +67,7 @@ function admin_post(&$a) if($batch){ require_once('include/submit.php'); + require_once('include/site-health.php'); //First get all data from file. $data = file_get_contents($file); @@ -95,10 +96,21 @@ function admin_post(&$a) $_SESSION['import_total']++; $_SESSION['import_failed']++; 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)){ $_SESSION['import_failed']--; $_SESSION['import_success']++; } + }catch(\Exception $ex){/* We tried... */} } else break; @@ -106,17 +118,18 @@ function admin_post(&$a) $left = count($list); - $s = $_SESSION['import_success']; + $success = $_SESSION['import_success']; + $skipped = $_SESSION['import_skipped']; $total = $_SESSION['import_total']; $errors = $_SESSION['import_failed']; if($left > 0){ - notice("$left items left in batch.
Stats: $s / $total success, $errors errors."); + notice("$left items left in batch...
$success updated profiles.
$errors import errors."); file_put_contents($file, implode("\r\n", $list)); $fid = uniqid('autosubmit_'); echo '
'. - ''; + ''; } else { - notice("Completed batch! $s / $total success. $errors errors."); + notice("Completed batch! $success updated. $errors errors."); unlink($file); unset($_SESSION['import_progress']); } @@ -124,8 +137,12 @@ function admin_post(&$a) return; } + + //Doing a poll from the directory? elseif($url){ + require_once('include/site-health.php'); + $result = fetch_url($url."/lsearch?p=$page&n=$perPage&search=.*"); if($result) $data = json_decode($result); @@ -136,8 +153,33 @@ function admin_post(&$a) $rows = ''; foreach($data->results as $profile){ + + //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); $progress = min((($page+1) * $perPage), $data->total); @@ -153,7 +195,7 @@ function admin_post(&$a) ''; } else { - goaway($a->get_baseurl().'/import'); + goaway($a->get_baseurl().'/admin'); } } diff --git a/mod/moderate.php b/mod/moderate.php index f3a64626..0d1b9879 100755 --- a/mod/moderate.php +++ b/mod/moderate.php @@ -135,12 +135,12 @@ function moderate_content(&$a) { $c .= '
' . $rr['homepage'] . '
'; $o .= '
'; - $checked = (($reason === 'censor') ? 'checked="checked" ' : ''); - $o .= 'Censor Profile

'; - $checked = (($reason === 'dead') ? 'checked="checked" ' : ''); - $o .= 'Dead Account

'; + $checked = (($reason === '1') ? 'checked="checked" ' : ''); + $o .= '

'; + $checked = (($reason === '2') ? 'checked="checked" ' : ''); + $o .= '

'; - $o .= 'Bogus request

'; + $o .= '

'; $o .= '

'; diff --git a/view/theme/default/style.css b/view/theme/default/style.css index 0088ab94..e85116e5 100755 --- a/view/theme/default/style.css +++ b/view/theme/default/style.css @@ -1603,8 +1603,11 @@ input#dfrn-url { } .flagged-entries{ - max-height:500px; + max-height:315px; overflow:auto; + border:1px solid #ccc; + padding:5px; + line-height:1.3em; } .profile-moderate-preview{