Merge pull request #2589 from rabuzarus/1106-admin-clean

mod/admin.php: some clean up
This commit is contained in:
Michael Vogel 2016-06-11 10:21:43 +02:00 committed by GitHub
commit acb50b343e

View File

@ -282,17 +282,17 @@ function admin_page_federation(&$a) {
foreach ($platforms as $p) { foreach ($platforms as $p) {
// get a total count for the platform, the name and version of the // get a total count for the platform, the name and version of the
// highest version and the protocol tpe // highest version and the protocol tpe
$c = q('SELECT count(*) AS total, platform, network, version FROM gserver $c = q('SELECT COUNT(*) AS `total`, `platform`, `network`, `version` FROM `gserver`
WHERE platform LIKE "%s" AND last_contact > last_failure AND `version` != "" WHERE `platform` LIKE "%s" AND `last_contact` > `last_failure` AND `version` != ""
ORDER BY version ASC;', $p); ORDER BY `version` ASC;', $p);
$total = $total + $c[0]['total']; $total = $total + $c[0]['total'];
// what versions for that platform do we know at all? // what versions for that platform do we know at all?
// again only the active nodes // again only the active nodes
$v = q('SELECT count(*) AS total, version FROM gserver $v = q('SELECT COUNT(*) AS `total, version` FROM `gserver`
WHERE last_contact > last_failure AND platform LIKE "%s" AND `version` != "" WHERE `last_contact` > `last_failure` AND `platform` LIKE "%s" AND `version` != ""
GROUP BY version GROUP BY `version`
ORDER BY version;', $p); ORDER BY `version`;', $p);
// //
// clean up version numbers // clean up version numbers
@ -386,7 +386,10 @@ function admin_page_federation(&$a) {
*/ */
function admin_page_queue(&$a) { function admin_page_queue(&$a) {
// get content from the queue table // get content from the queue table
$r = q("SELECT c.name,c.nurl,q.id,q.network,q.created,q.last from queue as q, contact as c where c.id=q.cid order by q.cid, q.created;"); $r = q("SELECT `c`.`name`, `c`.`nurl`, `q`.`id`, `q`.`network`, `q`.`created`, `q`.`last`
FROM `queue` AS `q`, `contact` AS `c`
WHERE `c`.`id` = `q`.`cid`
ORDER BY `q`.`cid`, `q`.`created`;");
$t = get_markup_template("admin_queue.tpl"); $t = get_markup_template("admin_queue.tpl");
return replace_macros($t, array( return replace_macros($t, array(
@ -416,7 +419,7 @@ function admin_page_queue(&$a) {
* @return string * @return string
*/ */
function admin_page_summary(&$a) { function admin_page_summary(&$a) {
$r = q("SELECT `page-flags`, COUNT(uid) as `count` FROM `user` GROUP BY `page-flags`"); $r = q("SELECT `page-flags`, COUNT(`uid`) AS `count` FROM `user` GROUP BY `page-flags`");
$accounts = array( $accounts = array(
array(t('Normal Account'), 0), array(t('Normal Account'), 0),
array(t('Soapbox Account'), 0), array(t('Soapbox Account'), 0),
@ -431,17 +434,17 @@ function admin_page_summary(&$a) {
logger('accounts: '.print_r($accounts,true),LOGGER_DATA); logger('accounts: '.print_r($accounts,true),LOGGER_DATA);
$r = q("SELECT COUNT(id) as `count` FROM `register`"); $r = q("SELECT COUNT(`id`) AS `count` FROM `register`");
$pending = $r[0]['count']; $pending = $r[0]['count'];
$r = q("select count(*) as total from deliverq where 1"); $r = q("SELECT COUNT(*) AS `total` FROM `deliverq` WHERE 1");
$deliverq = (($r) ? $r[0]['total'] : 0); $deliverq = (($r) ? $r[0]['total'] : 0);
$r = q("select count(*) as total from queue where 1"); $r = q("SELECT COUNT(*) AS `total` FROM `queue` WHERE 1");
$queue = (($r) ? $r[0]['total'] : 0); $queue = (($r) ? $r[0]['total'] : 0);
if (get_config('system','worker')) { if (get_config('system','worker')) {
$r = q("select count(*) as total from workerqueue where 1"); $r = q("SELECT COUNT(*) AS `total` FROM `workerqueue` WHERE 1");
$workerqueue = (($r) ? $r[0]['total'] : 0); $workerqueue = (($r) ? $r[0]['total'] : 0);
} else { } else {
$workerqueue = 0; $workerqueue = 0;
@ -543,7 +546,7 @@ function admin_page_site_post(&$a) {
set_config('system','url',$new_url); set_config('system','url',$new_url);
// send relocate // send relocate
$users = q("SELECT uid FROM user WHERE account_removed = 0 AND account_expired = 0"); $users = q("SELECT `uid` FROM `user` WHERE `account_removed` = 0 AND `account_expired` = 0");
foreach ($users as $user) { foreach ($users as $user) {
proc_run('php', 'include/notifier.php', 'relocate', $user['uid']); proc_run('php', 'include/notifier.php', 'relocate', $user['uid']);
@ -647,41 +650,41 @@ function admin_page_site_post(&$a) {
if($ssl_policy != intval(get_config('system','ssl_policy'))) { if($ssl_policy != intval(get_config('system','ssl_policy'))) {
if($ssl_policy == SSL_POLICY_FULL) { if($ssl_policy == SSL_POLICY_FULL) {
q("update `contact` set q("UPDATE `contact` SET
`url` = replace(`url` , 'http:' , 'https:'), `url` = REPLACE(`url` , 'http:' , 'https:'),
`photo` = replace(`photo` , 'http:' , 'https:'), `photo` = REPLACE(`photo` , 'http:' , 'https:'),
`thumb` = replace(`thumb` , 'http:' , 'https:'), `thumb` = REPLACE(`thumb` , 'http:' , 'https:'),
`micro` = replace(`micro` , 'http:' , 'https:'), `micro` = REPLACE(`micro` , 'http:' , 'https:'),
`request` = replace(`request`, 'http:' , 'https:'), `request` = REPLACE(`request`, 'http:' , 'https:'),
`notify` = replace(`notify` , 'http:' , 'https:'), `notify` = REPLACE(`notify` , 'http:' , 'https:'),
`poll` = replace(`poll` , 'http:' , 'https:'), `poll` = REPLACE(`poll` , 'http:' , 'https:'),
`confirm` = replace(`confirm`, 'http:' , 'https:'), `confirm` = REPLACE(`confirm`, 'http:' , 'https:'),
`poco` = replace(`poco` , 'http:' , 'https:') `poco` = REPLACE(`poco` , 'http:' , 'https:')
where `self` = 1" WHERE `self` = 1"
); );
q("update `profile` set q("UPDATE `profile` SET
`photo` = replace(`photo` , 'http:' , 'https:'), `photo` = REPLACE(`photo` , 'http:' , 'https:'),
`thumb` = replace(`thumb` , 'http:' , 'https:') `thumb` = REPLACE(`thumb` , 'http:' , 'https:')
where 1 " WHERE 1 "
); );
} }
elseif($ssl_policy == SSL_POLICY_SELFSIGN) { elseif($ssl_policy == SSL_POLICY_SELFSIGN) {
q("update `contact` set q("UPDATE `contact` SET
`url` = replace(`url` , 'https:' , 'http:'), `url` = REPLACE(`url` , 'https:' , 'http:'),
`photo` = replace(`photo` , 'https:' , 'http:'), `photo` = REPLACE(`photo` , 'https:' , 'http:'),
`thumb` = replace(`thumb` , 'https:' , 'http:'), `thumb` = REPLACE(`thumb` , 'https:' , 'http:'),
`micro` = replace(`micro` , 'https:' , 'http:'), `micro` = REPLACE(`micro` , 'https:' , 'http:'),
`request` = replace(`request`, 'https:' , 'http:'), `request` = REPLACE(`request`, 'https:' , 'http:'),
`notify` = replace(`notify` , 'https:' , 'http:'), `notify` = REPLACE(`notify` , 'https:' , 'http:'),
`poll` = replace(`poll` , 'https:' , 'http:'), `poll` = REPLACE(`poll` , 'https:' , 'http:'),
`confirm` = replace(`confirm`, 'https:' , 'http:'), `confirm` = REPLACE(`confirm`, 'https:' , 'http:'),
`poco` = replace(`poco` , 'https:' , 'http:') `poco` = REPLACE(`poco` , 'https:' , 'http:')
where `self` = 1" WHERE `self` = 1"
); );
q("update `profile` set q("UPDATE `profile` SET
`photo` = replace(`photo` , 'https:' , 'http:'), `photo` = REPLACE(`photo` , 'https:' , 'http:'),
`thumb` = replace(`thumb` , 'https:' , 'http:') `thumb` = REPLACE(`thumb` , 'https:' , 'http:')
where 1 " WHERE 1 "
); );
} }
} }
@ -876,7 +879,7 @@ function admin_page_site(&$a) {
/* get user names to make the install a personal install of X */ /* get user names to make the install a personal install of X */
$user_names = array(); $user_names = array();
$user_names['---'] = t('Multi user instance'); $user_names['---'] = t('Multi user instance');
$users = q("SELECT username, nickname FROM `user`"); $users = q("SELECT `username`, `nickname` FROM `user`");
foreach ($users as $user) { foreach ($users as $user) {
$user_names[$user['nickname']] = $user['username']; $user_names[$user['nickname']] = $user['username'];
} }
@ -1084,7 +1087,7 @@ function admin_page_dbsync(&$a) {
} }
$failed = array(); $failed = array();
$r = q("select k, v from config where `cat` = 'database' "); $r = q("SELECT `k`, `v` FROM `config` WHERE `cat` = 'database' ");
if(count($r)) { if(count($r)) {
foreach($r as $rr) { foreach($r as $rr) {
$upd = intval(substr($rr['k'],7)); $upd = intval(substr($rr['k'],7));
@ -1225,7 +1228,7 @@ function admin_page_users_post(&$a){
function admin_page_users(&$a){ function admin_page_users(&$a){
if($a->argc>2) { if($a->argc>2) {
$uid = $a->argv[3]; $uid = $a->argv[3];
$user = q("SELECT username, blocked FROM `user` WHERE `uid`=%d", intval($uid)); $user = q("SELECT `username`, `blocked` FROM `user` WHERE `uid` = %d", intval($uid));
if(count($user)==0) { if(count($user)==0) {
notice('User not found'.EOL); notice('User not found'.EOL);
goaway('admin/users'); goaway('admin/users');
@ -1262,7 +1265,7 @@ function admin_page_users(&$a){
/* get users */ /* get users */
$total = q("SELECT count(*) as total FROM `user` where 1"); $total = q("SELECT COUNT(*) AS `total` FROM `user` WHERE 1");
if(count($total)) { if(count($total)) {
$a->set_pager_total($total[0]['total']); $a->set_pager_total($total[0]['total']);
$a->set_pager_itemspage(100); $a->set_pager_itemspage(100);