Merged import tools with admin view.
This commit is contained in:
parent
5e1be6b2fe
commit
717303e475
5 changed files with 179 additions and 177 deletions
170
mod/admin.php
170
mod/admin.php
|
@ -2,36 +2,162 @@
|
|||
|
||||
|
||||
function admin_content(&$a) {
|
||||
|
||||
if(! $_SESSION['uid']) {
|
||||
notice("Permission denied.");
|
||||
return;
|
||||
goaway($a->get_baseurl());
|
||||
}
|
||||
|
||||
$r = q("SELECT COUNT(*) FROM `flag` as `ftotal` WHERE 1");
|
||||
if(count($r))
|
||||
$a->set_pager_total($r[0]['ftotal']);
|
||||
|
||||
$r = q("SELECT * FROM `flag` WHERE 1 ORDER BY `total` DESC LIMIT %d, %d ",
|
||||
intval($a->pager['start']),
|
||||
intval($a->pager['itemspage'])
|
||||
);
|
||||
|
||||
if(! count($r)) {
|
||||
notice("No entries.");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
//Get 100 flagged entries.
|
||||
$r = q("SELECT `flag`.*, `profile`.`name`, `profile`.`homepage`
|
||||
FROM `flag` JOIN `profile` ON `flag`.`pid`=`profile`.`id`
|
||||
ORDER BY `total` DESC LIMIT 100"
|
||||
);
|
||||
|
||||
if(count($r)) {
|
||||
$flagged = '';
|
||||
foreach($r as $rr) {
|
||||
if($rr['reason'] == 1)
|
||||
$str = 'censor';
|
||||
$str = 'Censor';
|
||||
if($rr['reason'] == 2)
|
||||
$str = 'dead';
|
||||
$o .= '<a href="' . 'moderate/' . $rr['pid'] . '/' . $str . '">'
|
||||
. $str . ' profile: ' . $rr['pid'] . ' (' . $rr['total'] . ')</a><br />';
|
||||
$str = 'Dead';
|
||||
$flagged .= '<a href="' . 'moderate/' . $rr['pid'] . '/' . $str . '">'.
|
||||
"$str profile: [#{$rr['pid']}] {$rr['name']} ({$rr['total']}x) - {$rr['homepage']}</a><br />";
|
||||
}
|
||||
} else {
|
||||
$flagged = 'No entries.';
|
||||
}
|
||||
|
||||
//Get the backlog size.
|
||||
$res = q("SELECT count(*) as `count` FROM `profile` WHERE `updated` < '%s'",
|
||||
dbesc(date('Y-m-d H:i:s', time()-$a->config['maintenance']['min_scrape_delay'])));
|
||||
$backlog = 'unknown';
|
||||
if(count($res)){ $backlog = $res[0]['count'].' entries'; }
|
||||
|
||||
$tpl = file_get_contents('view/admin.tpl');
|
||||
return replace_macros($tpl, array(
|
||||
'$present' => is_file('.htimport') ? ' (present)' : '',
|
||||
'$flagged' => $flagged,
|
||||
'$backlog' => $backlog,
|
||||
'$maintenance_size' => $a->config['maintenance']['max_scrapes'].' items per maintenance call.'
|
||||
));
|
||||
|
||||
}
|
||||
|
||||
$o .= paginate($a);
|
||||
return $o;
|
||||
function admin_post(&$a)
|
||||
{
|
||||
|
||||
//Submit a profile URL.
|
||||
if($_POST['submit_url']){
|
||||
goaway($a->get_baseurl().'/submit?url='.bin2hex($_POST['submit_url']));
|
||||
}
|
||||
|
||||
//Get our input.
|
||||
$url = $_POST['dir_import_url'];
|
||||
$page = intval($_POST['dir_page']);
|
||||
$batch = $_POST['batch_submit'];
|
||||
|
||||
//Directory
|
||||
$file = realpath(__DIR__.'/..').'/.htimport';
|
||||
|
||||
//Per batch setting.
|
||||
$perPage = 200;
|
||||
$perBatch = 2;
|
||||
|
||||
if($batch){
|
||||
|
||||
require_once('include/submit.php');
|
||||
|
||||
//First get all data from file.
|
||||
$data = file_get_contents($file);
|
||||
$list = explode("\r\n", $data);
|
||||
|
||||
//Fresh batch?
|
||||
if(!isset($_SESSION['import_progress'])){
|
||||
|
||||
$_SESSION['import_progress'] = true;
|
||||
$_SESSION['import_success'] = 0;
|
||||
$_SESSION['import_failed'] = 0;
|
||||
$_SESSION['import_total'] = 0;
|
||||
notice("Started new batch. ");
|
||||
|
||||
}
|
||||
|
||||
//Make sure we can use try catch for all sorts of errors.
|
||||
set_error_handler(function($errno, $errstr='', $errfile='', $errline='', $context=array()){
|
||||
if((error_reporting() & $errno) == 0){ return; }
|
||||
throw new \Exception($errstr, $errno);
|
||||
});
|
||||
|
||||
for($i=0; $i<$perBatch; $i++){
|
||||
if($url = array_shift($list)){
|
||||
set_time_limit(15);
|
||||
$_SESSION['import_total']++;
|
||||
$_SESSION['import_failed']++;
|
||||
try{
|
||||
if(run_submit($url)){
|
||||
$_SESSION['import_failed']--;
|
||||
$_SESSION['import_success']++;
|
||||
}
|
||||
}catch(\Exception $ex){/* We tried... */}
|
||||
}
|
||||
else break;
|
||||
}
|
||||
|
||||
$left = count($list);
|
||||
|
||||
$s = $_SESSION['import_success'];
|
||||
$total = $_SESSION['import_total'];
|
||||
$errors = $_SESSION['import_failed'];
|
||||
if($left > 0){
|
||||
notice("$left items left in batch.<br>Stats: $s / $total success, $errors errors.");
|
||||
file_put_contents($file, implode("\r\n", $list));
|
||||
$fid = uniqid('autosubmit_');
|
||||
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>';
|
||||
} else {
|
||||
notice("Completed batch! $s / $total success. $errors errors.");
|
||||
unlink($file);
|
||||
unset($_SESSION['import_progress']);
|
||||
}
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
elseif($url){
|
||||
|
||||
$result = fetch_url($url."/lsearch?p=$page&n=$perPage&search=.*");
|
||||
if($result)
|
||||
$data = json_decode($result);
|
||||
else
|
||||
$data = false;
|
||||
|
||||
if($data){
|
||||
|
||||
$rows = '';
|
||||
foreach($data->results as $profile){
|
||||
$rows .= $profile->url."\r\n";
|
||||
}
|
||||
file_put_contents($file, $rows, $page > 0 ? FILE_APPEND : 0);
|
||||
|
||||
$progress = min((($page+1) * $perPage), $data->total);
|
||||
notice("Imported ".$progress."/".$data->total." URLs.");
|
||||
|
||||
if($progress !== $data->total){
|
||||
$fid = uniqid('autosubmit_');
|
||||
echo
|
||||
'<form method="POST" id="'.$fid.'">'.
|
||||
'<input type="hidden" name="dir_import_url" value="'.$url.'">'.
|
||||
'<input type="hidden" name="dir_page" value="'.($page+1).'">'.
|
||||
'</form>'.
|
||||
'<script type="text/javascript">setTimeout(function(){ document.getElementById("'.$fid.'").submit(); }, 500);</script>';
|
||||
|
||||
} else {
|
||||
goaway($a->get_baseurl().'/import');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
149
mod/import.php
149
mod/import.php
|
@ -1,149 +0,0 @@
|
|||
<?php
|
||||
|
||||
function import_init(&$a)
|
||||
{
|
||||
|
||||
if(! $_SESSION['uid']) {
|
||||
notice("Permission denied.");
|
||||
goaway($a->get_baseurl());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function import_content(&$a)
|
||||
{
|
||||
|
||||
$res = q(
|
||||
"SELECT count(*) as `count` FROM `profile` WHERE `updated` < '%s'",
|
||||
dbesc(date('Y-m-d H:i:s', time()-$a->config['maintenance']['min_scrape_delay']))
|
||||
);
|
||||
$backlog = 'unknown';
|
||||
if(count($res)){
|
||||
$backlog = $res[0]['count'].'/'.$a->config['maintenance']['max_scrapes'].' entries';
|
||||
}
|
||||
|
||||
$tpl = file_get_contents('view/import.tpl');
|
||||
return replace_macros($tpl, array(
|
||||
'$present' => is_file('.htimport') ? ' (present)' : '',
|
||||
'$backlog' => $backlog
|
||||
));
|
||||
|
||||
}
|
||||
|
||||
function import_post(&$a)
|
||||
{
|
||||
|
||||
if($_POST['submit_url']){
|
||||
goaway($a->get_baseurl().'/submit?url='.bin2hex($_POST['submit_url']));
|
||||
}
|
||||
|
||||
//Get our input.
|
||||
$url = $_POST['url'];
|
||||
$page = intval($_POST['page']);
|
||||
$batch = $_POST['batch_submit'];
|
||||
|
||||
//Directory
|
||||
$file = realpath(__DIR__.'/..').'/.htimport';
|
||||
|
||||
//Per batch setting.
|
||||
$perPage = 200;
|
||||
$perBatch = 2;
|
||||
|
||||
if($batch){
|
||||
|
||||
require_once('include/submit.php');
|
||||
|
||||
//First get all data from file.
|
||||
$data = file_get_contents($file);
|
||||
$list = explode("\r\n", $data);
|
||||
|
||||
//Fresh batch?
|
||||
if(!isset($_SESSION['import_progress'])){
|
||||
|
||||
$_SESSION['import_progress'] = true;
|
||||
$_SESSION['import_success'] = 0;
|
||||
$_SESSION['import_failed'] = 0;
|
||||
$_SESSION['import_total'] = 0;
|
||||
notice("Started new batch. ");
|
||||
|
||||
}
|
||||
|
||||
//Make sure we can use try catch for all sorts of errors.
|
||||
set_error_handler(function($errno, $errstr='', $errfile='', $errline='', $context=array()){
|
||||
if((error_reporting() & $errno) == 0){ return; }
|
||||
throw new \Exception($errstr, $errno);
|
||||
});
|
||||
|
||||
for($i=0; $i<$perBatch; $i++){
|
||||
if($url = array_shift($list)){
|
||||
set_time_limit(15);
|
||||
$_SESSION['import_total']++;
|
||||
$_SESSION['import_failed']++;
|
||||
try{
|
||||
if(run_submit($url)){
|
||||
$_SESSION['import_failed']--;
|
||||
$_SESSION['import_success']++;
|
||||
}
|
||||
}catch(\Exception $ex){/* We tried... */}
|
||||
}
|
||||
else break;
|
||||
}
|
||||
|
||||
$left = count($list);
|
||||
|
||||
$s = $_SESSION['import_success'];
|
||||
$total = $_SESSION['import_total'];
|
||||
$errors = $_SESSION['import_failed'];
|
||||
if($left > 0){
|
||||
notice("$left items left in batch.<br>Stats: $s / $total success, $errors errors.");
|
||||
file_put_contents($file, implode("\r\n", $list));
|
||||
$fid = uniqid('autosubmit_');
|
||||
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>';
|
||||
} else {
|
||||
notice("Completed batch! $s / $total success. $errors errors.");
|
||||
unlink($file);
|
||||
unset($_SESSION['import_progress']);
|
||||
}
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
elseif($url){
|
||||
|
||||
$result = fetch_url($url."/lsearch?p=$page&n=$perPage&search=.*");
|
||||
if($result)
|
||||
$data = json_decode($result);
|
||||
else
|
||||
$data = false;
|
||||
|
||||
if($data){
|
||||
|
||||
$rows = '';
|
||||
foreach($data->results as $profile){
|
||||
$rows .= $profile->url."\r\n";
|
||||
}
|
||||
file_put_contents($file, $rows, $page > 0 ? FILE_APPEND : 0);
|
||||
|
||||
$progress = min((($page+1) * $perPage), $data->total);
|
||||
notice("Imported ".$progress."/".$data->total." URLs.");
|
||||
|
||||
if($progress !== $data->total){
|
||||
$fid = uniqid('autosubmit_');
|
||||
echo
|
||||
'<form method="POST" id="'.$fid.'">'.
|
||||
'<input type="hidden" name="url" value="'.$url.'">'.
|
||||
'<input type="hidden" name="page" value="'.($page+1).'">'.
|
||||
// '<input type="submit">'.
|
||||
'</form>'.
|
||||
'<script type="text/javascript">setTimeout(function(){ document.getElementById("'.$fid.'").submit(); }, 500);</script>';
|
||||
|
||||
} else {
|
||||
goaway($a->get_baseurl().'/import');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -68,7 +68,7 @@ function moderate_content(&$a) {
|
|||
$id = intval($a->argv[1]);
|
||||
if($a->argc > 2)
|
||||
$reason = $a->argv[2];
|
||||
|
||||
|
||||
if($id) {
|
||||
$r = q("SELECT * FROM `profile` WHERE `id` = %d LIMIT 1",
|
||||
intval($id)
|
||||
|
@ -80,6 +80,8 @@ function moderate_content(&$a) {
|
|||
);
|
||||
goaway($a->get_baseurl() . '/admin');
|
||||
}
|
||||
}else{
|
||||
goaway($a->get_baseurl() . '/admin');
|
||||
}
|
||||
|
||||
$c .= "<h1>Moderate/delete profile</h1>";
|
||||
|
@ -129,7 +131,7 @@ function moderate_content(&$a) {
|
|||
|
||||
$o .= "<div class=\"directory-end\" ></div>\r\n";
|
||||
|
||||
$c .= '<br /><br /><iframe height="400" width="800" src="' . $rr['homepage'] . '" ></iframe>';
|
||||
$c .= '<br /><br /><iframe height="400" width="800" src="' . $rr['homepage'] . '" class="profile-moderate-preview"></iframe>';
|
||||
$c .= '<br />' . $rr['homepage'] . '<br />';
|
||||
|
||||
$o .= '<form action="moderate" method="post" >';
|
||||
|
|
|
@ -1,9 +1,23 @@
|
|||
<div class="mirror-wrapper">
|
||||
<div class="flagged-wrapper">
|
||||
<h1>Flagged entries</h1>
|
||||
<div class="flagged-entries">$flagged</div>
|
||||
</div>
|
||||
|
||||
<div class="maintenance-wrapper">
|
||||
<h1>Maintenance</h1>
|
||||
<p>
|
||||
<strong>Current backlog: $backlog</strong><br>
|
||||
<i>$maintenance_size</i>
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div class="import-wrapper">
|
||||
<h1>Import tools</h1>
|
||||
<h2>Mirror a directory</h2>
|
||||
<form method="POST">
|
||||
<label>Extract URL's:</label>
|
||||
<input type="text" name="url" value="http://dir.friendica.com">
|
||||
<input type="hidden" name="page" value="0">
|
||||
<input type="text" name="dir_import_url" value="http://dir.friendica.com">
|
||||
<input type="hidden" name="dir_page" value="0">
|
||||
<input type="submit" value="Execute">
|
||||
</form>
|
||||
<br>
|
||||
|
@ -16,5 +30,4 @@
|
|||
<input type="text" name="submit_url" placeholder="Profile url" size="35" />
|
||||
<input type="submit" value="Submit">
|
||||
</form>
|
||||
<h3>Maintenance backlog: $backlog</h3>
|
||||
</div>
|
|
@ -1600,4 +1600,14 @@ input#dfrn-url {
|
|||
width:480px;
|
||||
height:320px;
|
||||
text-align:center;
|
||||
}
|
||||
|
||||
.flagged-entries{
|
||||
max-height:500px;
|
||||
overflow:auto;
|
||||
}
|
||||
|
||||
.profile-moderate-preview{
|
||||
width:80%;
|
||||
min-height:700px;
|
||||
}
|
Loading…
Reference in a new issue