Fix mod/admin.php formatting

This commit is contained in:
Hypolite Petovan 2017-11-29 20:28:30 -05:00
parent a5e9117524
commit 3cebdee867

View file

@ -5,7 +5,6 @@
*
* @brief Friendica admin
*/
use Friendica\App;
use Friendica\Core\System;
use Friendica\Core\Config;
@ -30,7 +29,8 @@ require_once 'include/items.php';
* @param App $a
*
*/
function admin_post(App $a) {
function admin_post(App $a)
{
if (!is_site_admin()) {
@ -75,7 +75,9 @@ function admin_post(App $a) {
$theme = $a->argv[2];
if (is_file("view/theme/$theme/config.php")) {
function __call_theme_admin_post(App $a, $theme) {
function __call_theme_admin_post(App $a, $theme)
{
$orig_theme = $a->theme;
$orig_page = $a->page;
$orig_session_theme = $_SESSION['theme'];
@ -145,7 +147,8 @@ function admin_post(App $a) {
* @param App $a
* @return string
*/
function admin_content(App $a) {
function admin_content(App $a)
{
if (!is_site_admin()) {
return login(false);
@ -160,7 +163,6 @@ function admin_content(App $a) {
// $toDelete = new APCIterator('user', APC_ITER_VALUE);
// apc_delete($toDelete);
//}
// Header stuff
$a->page['htmlhead'] .= replace_macros(get_markup_template('admin_settings_head.tpl'), array());
@ -283,7 +285,8 @@ function admin_content(App $a) {
* @param App $a
* @return string
*/
function admin_page_blocklist(App $a) {
function admin_page_blocklist(App $a)
{
$blocklist = Config::get('system', 'blocklist');
$blocklistform = array();
if (is_array($blocklist)) {
@ -322,7 +325,8 @@ function admin_page_blocklist(App $a) {
*
* @param App $a
*/
function admin_page_blocklist_post(App $a) {
function admin_page_blocklist_post(App $a)
{
if (!x($_POST, "page_blocklist_save") && (!x($_POST['page_blocklist_edit']))) {
return;
}
@ -370,7 +374,8 @@ function admin_page_blocklist_post(App $a) {
* @param App $a
* @return string
*/
function admin_page_deleteitem(App $a) {
function admin_page_deleteitem(App $a)
{
$t = get_markup_template("admin_deleteitem.tpl");
return replace_macros($t, array(
@ -384,6 +389,7 @@ function admin_page_deleteitem(App $a) {
'$form_security_token' => get_form_security_token("admin_deleteitem")
));
}
/**
* @brief Process send data from Admin Delete Item Page
*
@ -392,7 +398,8 @@ function admin_page_deleteitem(App $a) {
*
* @param App $a
*/
function admin_page_deleteitem_post(App $a) {
function admin_page_deleteitem_post(App $a)
{
if (!x($_POST['page_deleteitem_submit'])) {
return;
}
@ -435,7 +442,8 @@ function admin_page_deleteitem_post(App $a) {
* @param App $a
* @return string
*/
function admin_page_federation(App $a) {
function admin_page_federation(App $a)
{
// get counts on active friendica, diaspora, redmatrix, hubzilla, gnu
// social and statusnet nodes this node is knowing
//
@ -445,7 +453,8 @@ function admin_page_federation(App $a) {
// Add more platforms if you like, when one returns 0 known nodes it is not
// displayed on the stats page.
$platforms = array('Friendi%%a', 'Diaspora', '%%red%%', 'Hubzilla', 'BlaBlaNet', 'GNU Social', 'StatusNet', 'Mastodon', 'Pleroma');
$colors = array('Friendi%%a' => '#ffc018', // orange from the logo
$colors = array(
'Friendi%%a' => '#ffc018', // orange from the logo
'Diaspora' => '#a1a1a1', // logo is black and white, makes a gray
'%%red%%' => '#c50001', // fire red from the logo
'Hubzilla' => '#43488a', // blue from the logo
@ -453,7 +462,8 @@ function admin_page_federation(App $a) {
'GNU Social' => '#a22430', // dark red from the logo
'StatusNet' => '#789240', // the green from the logo (red and blue have already others
'Mastodon' => '#1a9df9', // blue from the Mastodon logo
'Pleroma' => '#E46F0F'); // Orange from the text that is used on Pleroma instances
'Pleroma' => '#E46F0F' // Orange from the text that is used on Pleroma instances
);
$counts = array();
$total = 0;
@ -574,7 +584,8 @@ function admin_page_federation(App $a) {
* @param App $a
* @return string
*/
function admin_page_queue(App $a) {
function admin_page_queue(App $a)
{
// 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`
@ -608,10 +619,10 @@ function admin_page_queue(App $a) {
* @param App $a
* @return string
*/
function admin_page_summary(App $a) {
function admin_page_summary(App $a)
{
// are there MyISAM tables in the DB? If so, trigger a warning message
$r = q("SELECT `engine` FROM `information_schema`.`tables` WHERE `engine` = 'myisam' AND `table_schema` = '%s' LIMIT 1",
dbesc(dba::database_name()));
$r = q("SELECT `engine` FROM `information_schema`.`tables` WHERE `engine` = 'myisam' AND `table_schema` = '%s' LIMIT 1", dbesc(dba::database_name()));
$showwarning = false;
$warningtext = array();
if (DBM::is_result($r)) {
@ -702,7 +713,8 @@ function admin_page_summary(App $a) {
*
* @param App $a
*/
function admin_page_site_post(App $a) {
function admin_page_site_post(App $a)
{
check_form_security_token_redirectOnErr('/admin/site', 'admin_site');
if (!empty($_POST['republish_directory'])) {
@ -736,7 +748,8 @@ function admin_page_site_post(App $a) {
$new_host = str_replace("http://", "@", normalise_link($new_url));
$old_host = str_replace("http://", "@", normalise_link($old_url));
function update_table($table_name, $fields, $old_url, $new_url) {
function update_table($table_name, $fields, $old_url, $new_url)
{
global $a;
$dbold = dbesc($old_url);
@ -758,7 +771,6 @@ function admin_page_site_post(App $a) {
goaway('admin/site');
}
}
// update tables
// update profile links in the format "http://server.tld"
update_table("profile", array('photo', 'thumb'), $old_url, $new_url);
@ -933,9 +945,7 @@ function admin_page_site_post(App $a) {
if ($banner == "") {
// don't know why, but del_config doesn't work...
q("DELETE FROM `config` WHERE `cat` = '%s' AND `k` = '%s' LIMIT 1",
dbesc("system"),
dbesc("banner")
q("DELETE FROM `config` WHERE `cat` = '%s' AND `k` = '%s' LIMIT 1", dbesc("system"), dbesc("banner")
);
} else {
Config::set('system', 'banner', $banner);
@ -1026,7 +1036,6 @@ function admin_page_site_post(App $a) {
info(t('Site settings updated.') . EOL);
goaway('admin/site');
return; // NOTREACHED
}
/**
@ -1037,8 +1046,8 @@ function admin_page_site_post(App $a) {
* @param App $a
* @return string
*/
function admin_page_site(App $a) {
function admin_page_site(App $a)
{
/* Installed langs */
$lang_choices = get_available_languages();
@ -1058,8 +1067,9 @@ function admin_page_site(App $a) {
$allowed_theme_list = Config::get('system', 'allowed_themes');
foreach ($files as $file) {
if (intval(file_exists($file.'/unsupported')))
if (intval(file_exists($file . '/unsupported'))) {
continue;
}
$f = basename($file);
@ -1264,9 +1274,7 @@ function admin_page_site(App $a) {
'$worker_frontend' => array('worker_frontend', t('Enable frontend worker'), Config::get('system','frontend_worker'), sprintf(t('When enabled the Worker process is triggered when backend access is performed (e.g. messages being delivered). On smaller sites you might want to call %s/worker on a regular basis via an external cron job. You should only enable this option if you cannot utilize cron/scheduled jobs on your server.'), System::baseUrl())),
'$form_security_token' => get_form_security_token("admin_site")
));
}
/**
@ -1281,8 +1289,8 @@ function admin_page_site(App $a) {
* @param App $a
* @return string
* */
function admin_page_dbsync(App $a) {
function admin_page_dbsync(App $a)
{
$o = '';
if ($a->argc > 3 && intval($a->argv[3]) && $a->argv[2] === 'mark') {
@ -1302,8 +1310,7 @@ function admin_page_dbsync(App $a) {
$o .= sprintf(t("Database structure update %s was successfully applied."), DB_UPDATE_VERSION) . "<br />";
Config::set('database', 'dbupdate_' . DB_UPDATE_VERSION, 'success');
} else {
$o .= sprintf(t("Executing of database structure update %s failed with error: %s"),
DB_UPDATE_VERSION, $retval)."<br />";
$o .= sprintf(t("Executing of database structure update %s failed with error: %s"), DB_UPDATE_VERSION, $retval) . "<br />";
}
if ($a->argv[2] === 'check') {
return $o;
@ -1311,14 +1318,13 @@ function admin_page_dbsync(App $a) {
}
if ($a->argc > 2 && intval($a->argv[2])) {
require_once('update.php');
require_once 'update.php';
$func = 'update_' . intval($a->argv[2]);
if (function_exists($func)) {
$retval = $func();
if ($retval === UPDATE_FAILED) {
$o .= sprintf(t("Executing %s failed with error: %s"), $func, $retval);
}
elseif ($retval === UPDATE_SUCCESS) {
} elseif ($retval === UPDATE_SUCCESS) {
$o .= sprintf(t('Update %s was successfully applied.', $func));
Config::set('database', $func, 'success');
} else {
@ -1360,7 +1366,6 @@ function admin_page_dbsync(App $a) {
}
return $o;
}
/**
@ -1368,7 +1373,8 @@ function admin_page_dbsync(App $a) {
*
* @param App $a
*/
function admin_page_users_post(App $a) {
function admin_page_users_post(App $a)
{
$pending = (x($_POST, 'pending') ? $_POST['pending'] : array());
$users = (x($_POST, 'user') ? $_POST['user'] : array());
$nu_name = (x($_POST, 'new_user_name') ? $_POST['new_user_name'] : '');
@ -1379,7 +1385,7 @@ function admin_page_users_post(App $a) {
check_form_security_token_redirectOnErr('/admin/users', 'admin_users');
if (!($nu_name === "") && !($nu_email === "") && !($nu_nickname === "")) {
require_once('include/user.php');
require_once 'include/user.php';
$result = create_user(array('username' => $nu_name, 'email' => $nu_email,
'nickname' => $nu_nickname, 'verified' => 1, 'language' => $nu_language));
@ -1426,13 +1432,11 @@ function admin_page_users_post(App $a) {
'subject' => sprintf(t('Registration details for %s'), $a->config['sitename']),
'preamble' => $preamble,
'body' => $body));
}
if (x($_POST, 'page_users_block')) {
foreach ($users as $uid) {
q("UPDATE `user` SET `blocked` = 1-`blocked` WHERE `uid` = %s",
intval($uid)
q("UPDATE `user` SET `blocked` = 1-`blocked` WHERE `uid` = %s", intval($uid)
);
}
notice(sprintf(tt("%s user blocked/unblocked", "%s users blocked/unblocked", count($users)), count($users)));
@ -1472,7 +1476,8 @@ function admin_page_users_post(App $a) {
* @param App $a
* @return string
*/
function admin_page_users(App $a) {
function admin_page_users(App $a)
{
if ($a->argc > 2) {
$uid = $a->argv[3];
$user = q("SELECT `username`, `blocked` FROM `user` WHERE `uid` = %d", intval($uid));
@ -1491,16 +1496,13 @@ function admin_page_users(App $a) {
break;
case "block":
check_form_security_token_redirectOnErr('/admin/users', 'admin_users', 't');
q("UPDATE `user` SET `blocked` = %d WHERE `uid` = %s",
intval(1-$user[0]['blocked']),
intval($uid)
q("UPDATE `user` SET `blocked` = %d WHERE `uid` = %s", intval(1 - $user[0]['blocked']), intval($uid)
);
notice(sprintf(($user[0]['blocked'] ? t("User '%s' unblocked") : t("User '%s' blocked")), $user[0]['username']) . EOL);
break;
}
goaway('admin/users');
return ''; // NOTREACHED
}
/* get pending */
@ -1550,9 +1552,7 @@ function admin_page_users(App $a) {
FROM `user`
INNER JOIN `contact` ON `contact`.`uid` = `user`.`uid` AND `contact`.`self`
WHERE `user`.`verified`
ORDER BY $sql_order $sql_order_direction LIMIT %d, %d",
intval($a->pager['start']),
intval($a->pager['itemspage'])
ORDER BY $sql_order $sql_order_direction LIMIT %d, %d", intval($a->pager['start']), intval($a->pager['itemspage'])
);
//echo "<pre>$users"; killme();
@ -1602,9 +1602,7 @@ function admin_page_users(App $a) {
array_push($users, array_pop($tmp_users));
}
$th_users = array_map(null,
array(t('Name'), t('Email'), t('Register date'), t('Last login'), t('Last item'), t('Account')),
$valid_orders
$th_users = array_map(null, array(t('Name'), t('Email'), t('Register date'), t('Last login'), t('Last item'), t('Account')), $valid_orders
);
$t = get_markup_template("admin_users.tpl");
@ -1653,7 +1651,6 @@ function admin_page_users(App $a) {
return $o;
}
/**
* @brief Plugins admin page
*
@ -1670,8 +1667,8 @@ function admin_page_users(App $a) {
* @param App $a
* @return string
*/
function admin_page_plugins(App $a) {
function admin_page_plugins(App $a)
{
/*
* Single plugin
*/
@ -1705,9 +1702,11 @@ function admin_page_plugins(App $a) {
require_once('library/markdown.php');
if (in_array($plugin, $a->plugins)) {
$status="on"; $action= t("Disable");
$status = "on";
$action = t("Disable");
} else {
$status="off"; $action= t("Enable");
$status = "off";
$action = t("Enable");
}
$readme = Null;
@ -1750,12 +1749,9 @@ function admin_page_plugins(App $a) {
));
}
/*
* List plugins
*/
if (x($_GET, "a") && $_GET['a'] == "r") {
check_form_security_token_redirectOnErr(System::baseUrl() . '/admin/plugins', 'admin_themes', 't');
reload_plugins();
@ -1809,14 +1805,14 @@ function admin_page_plugins(App $a) {
* @param string $th
* @param int $result
*/
function toggle_theme(&$themes,$th,&$result) {
function toggle_theme(&$themes, $th, &$result)
{
for ($x = 0; $x < count($themes); $x ++) {
if ($themes[$x]['name'] === $th) {
if ($themes[$x]['allowed']) {
$themes[$x]['allowed'] = 0;
$result = 0;
}
else {
} else {
$themes[$x]['allowed'] = 1;
$result = 1;
}
@ -1829,13 +1825,13 @@ function toggle_theme(&$themes,$th,&$result) {
* @param string $th
* @return int
*/
function theme_status($themes,$th) {
function theme_status($themes, $th)
{
for ($x = 0; $x < count($themes); $x ++) {
if ($themes[$x]['name'] === $th) {
if ($themes[$x]['allowed']) {
return 1;
}
else {
} else {
return 0;
}
}
@ -1843,12 +1839,12 @@ function theme_status($themes,$th) {
return 0;
}
/**
* @param array $themes
* @return string
*/
function rebuild_theme_table($themes) {
function rebuild_theme_table($themes)
{
$o = '';
if (count($themes)) {
foreach ($themes as $th) {
@ -1863,7 +1859,6 @@ function rebuild_theme_table($themes) {
return $o;
}
/**
* @brief Themes admin page
*
@ -1880,8 +1875,8 @@ function rebuild_theme_table($themes) {
* @param App $a
* @return string
*/
function admin_page_themes(App $a) {
function admin_page_themes(App $a)
{
$allowed_themes_str = Config::get('system', 'allowed_themes');
$allowed_themes_raw = explode(',', $allowed_themes_str);
$allowed_themes = array();
@ -1954,12 +1949,14 @@ function admin_page_themes(App $a) {
}
// display theme details
require_once('library/markdown.php');
require_once 'library/markdown.php';
if (theme_status($themes, $theme)) {
$status="on"; $action= t("Disable");
$status = "on";
$action = t("Disable");
} else {
$status="off"; $action= t("Enable");
$status = "off";
$action = t("Enable");
}
$readme = Null;
@ -1972,7 +1969,9 @@ function admin_page_themes(App $a) {
$admin_form = "";
if (is_file("view/theme/$theme/config.php")) {
function __get_theme_admin_form(App $a, $theme) {
function __get_theme_admin_form(App $a, $theme)
{
$orig_theme = $a->theme;
$orig_page = $a->page;
$orig_session_theme = $_SESSION['theme'];
@ -2051,7 +2050,6 @@ function admin_page_themes(App $a) {
}
}
$t = get_markup_template("admin_plugins.tpl");
return replace_macros($t, array(
'$title' => t('Administration'),
@ -2069,13 +2067,13 @@ function admin_page_themes(App $a) {
));
}
/**
* @brief Prosesses data send by Logs admin page
*
* @param App $a
*/
function admin_page_logs_post(App $a) {
function admin_page_logs_post(App $a)
{
if (x($_POST, "page_logs")) {
check_form_security_token_redirectOnErr('/admin/logs', 'admin_logs');
@ -2109,8 +2107,8 @@ function admin_page_logs_post(App $a) {
* @param App $a
* @return string
*/
function admin_page_logs(App $a) {
function admin_page_logs(App $a)
{
$log_choices = array(
LOGGER_NORMAL => 'Normal',
LOGGER_TRACE => 'Trace',
@ -2134,12 +2132,10 @@ function admin_page_logs(App $a) {
'$clear' => t('Clear'),
'$baseurl' => System::baseUrl(true),
'$logname' => Config::get('system', 'logfile'),
// name, label, value, help string, extra data...
'$debugging' => array('debugging', t("Enable Debugging"), Config::get('system', 'debugging'), ""),
'$logfile' => array('logfile', t("Log file"), Config::get('system', 'logfile'), t("Must be writable by web server. Relative to your Friendica top-level directory.")),
'$loglevel' => array('loglevel', t("Log level"), Config::get('system', 'loglevel'), "", $log_choices),
'$form_security_token' => get_form_security_token("admin_logs"),
'$phpheader' => t("PHP logging"),
'$phphint' => t("To enable logging of PHP errors and warnings you can add the following to the .htconfig.php file of your installation. The filename set in the 'error_log' line is relative to the friendica top-level directory and must be writeable by the web server. The option '1' for 'log_errors' and 'display_errors' is to enable these options, set to '0' to disable them."),
@ -2166,7 +2162,8 @@ function admin_page_logs(App $a) {
* @param App $a
* @return string
*/
function admin_page_viewlogs(App $a) {
function admin_page_viewlogs(App $a)
{
$t = get_markup_template("admin_viewlogs.tpl");
$f = Config::get('system', 'logfile');
$data = '';
@ -2208,8 +2205,8 @@ function admin_page_viewlogs(App $a) {
*
* @param App $a
*/
function admin_page_features_post(App $a) {
function admin_page_features_post(App $a)
{
check_form_security_token_redirectOnErr('/admin/features', 'admin_manage_features');
logger('postvars: ' . print_r($_POST, true), LOGGER_DATA);
@ -2256,8 +2253,8 @@ function admin_page_features_post(App $a) {
* @param App $a
* @return string
*/
function admin_page_features(App $a) {
function admin_page_features(App $a)
{
if ((argc() > 1) && (argv(1) === 'features')) {
$arr = array();
$features = get_features(false);
@ -2266,7 +2263,6 @@ function admin_page_features(App $a) {
$arr[$fname] = array();
$arr[$fname][0] = $fdata[0];
foreach (array_slice($fdata, 1) as $f) {
$set = Config::get('feature', $f[0], $f[3]);
$arr[$fname][1][] = array(
array('feature_' . $f[0], $f[1], $set, $f[2], array(t('Off'), t('On'))),