+
+
+/**
+ * Users admin page
+ */
+function admin_page_users_post(&$a){
+ $pending = ( x($_POST, 'pending') ? $_POST['pending'] : Array() );
+ $users = ( x($_POST, 'user') ? $_POST['user'] : Array() );
+
+ if (x($_POST,'page_users_block')){
+ foreach($users as $uid){
+ q("UPDATE `user` SET `blocked`=1-`blocked` WHERE `uid`=%s",
+ intval( $uid )
+ );
+ }
+ notice( sprintf( tt("%s user blocked", "%s users blocked/unblocked", count($users)), count($users)) );
+ }
+ if (x($_POST,'page_users_delete')){
+ require_once("include/Contact.php");
+ foreach($users as $uid){
+ user_remove($uid);
+ }
+ notice( sprintf( tt("%s user deleted", "%s users deleted", count($users)), count($users)) );
+ }
+
+ if (x($_POST,'page_users_approve')){
+ require_once("mod/regmod.php");
+ foreach($pending as $hash){
+ user_allow($hash);
+ }
+ }
+ if (x($_POST,'page_users_deny')){
+ require_once("mod/regmod.php");
+ foreach($pending as $hash){
+ user_deny($hash);
+ }
+ }
+ goaway($a->get_baseurl() . '/admin/users' );
+ return; // NOTREACHED
+}
+
+function admin_page_users(&$a){
+ if ($a->argc>2) {
+ $uid = $a->argv[3];
+ $user = q("SELECT * FROM `user` WHERE `uid`=%d", intval($uid));
+ if (count($user)==0){
+ notice( 'User not found' . EOL);
+ goaway($a->get_baseurl() . '/admin/users' );
+ return; // NOTREACHED
+ }
+ switch($a->argv[2]){
+ case "delete":{
+ // delete user
+ require_once("include/Contact.php");
+ user_remove($uid);
+
+ notice( sprintf(t("User '%s' deleted"), $user[0]['username']) . EOL);
+ }; break;
+ case "block":{
+ 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($a->get_baseurl() . '/admin/users' );
+ return; // NOTREACHED
+
+ }
+
+ /* get pending */
+ $pending = q("SELECT `register`.*, `contact`.`name`, `user`.`email`
+ FROM `register`
+ LEFT JOIN `contact` ON `register`.`uid` = `contact`.`uid`
+ LEFT JOIN `user` ON `register`.`uid` = `user`.`uid`;");
+
+ /* get users */
+
+ $total = q("SELECT count(*) as total FROM `user` where 1");
+ if(count($total)) {
+ $a->set_pager_total($total[0]['total']);
+ $a->set_pager_itemspage(100);
+ }
+
+ $users = q("SELECT `user` . * , `contact`.`name` , `contact`.`url` , `contact`.`micro`, `lastitem`.`lastitem_date`
+ FROM
+ (SELECT MAX(`item`.`changed`) as `lastitem_date`, `item`.`uid`
+ FROM `item`
+ WHERE `item`.`type` = 'wall'
+ GROUP BY `item`.`uid`) AS `lastitem`
+ RIGHT OUTER JOIN `user` ON `user`.`uid` = `lastitem`.`uid`,
+ `contact`
+ WHERE
+ `user`.`uid` = `contact`.`uid`
+ AND `user`.`verified` =1
+ AND `contact`.`self` =1
+ ORDER BY `contact`.`name` LIMIT %d, %d
+ ",
+ intval($a->pager['start']),
+ intval($a->pager['itemspage'])
+ );
+
+ function _setup_users($e){
+ $accounts = Array(
+ t('Normal Account'),
+ t('Soapbox Account'),
+ t('Community/Celebrity Account'),
+ t('Automatic Friend Account')
+ );
+ $e['page-flags'] = $accounts[$e['page-flags']];
+ $e['register_date'] = relative_date($e['register_date']);
+ $e['login_date'] = relative_date($e['login_date']);
+ $e['lastitem_date'] = relative_date($e['lastitem_date']);
+ return $e;
+ }
+ $users = array_map("_setup_users", $users);
+
+ $t = get_markup_template("admin_users.tpl");
+ $o = replace_macros($t, array(
+ // strings //
+ '$title' => t('Administration'),
+ '$page' => t('Users'),
+ '$submit' => t('Submit'),
+ '$select_all' => t('select all'),
+ '$h_pending' => t('User registrations waiting for confirm'),
+ '$th_pending' => array( t('Request date'), t('Name'), t('Email') ),
+ '$no_pending' => t('No registrations.'),
+ '$approve' => t('Approve'),
+ '$deny' => t('Deny'),
+ '$delete' => t('Delete'),
+ '$block' => t('Block'),
+ '$unblock' => t('Unblock'),
+
+ '$h_users' => t('Users'),
+ '$th_users' => array( t('Name'), t('Email'), t('Register date'), t('Last login'), t('Last item'), t('Account') ),
+
+ '$confirm_delete_multi' => t('Selected users will be deleted!\n\nEverything these users had posted on this site will be permanently deleted!\n\nAre you sure?'),
+ '$confirm_delete' => t('The user {0} will be deleted!\n\nEverything this user has posted on this site will be permanently deleted!\n\nAre you sure?'),
+
+
+ // values //
+ '$baseurl' => $a->get_baseurl(),
+
+ '$pending' => $pending,
+ '$users' => $users,
+ ));
+ $o .= paginate($a);
+ return $o;
+}
+
+
+/*
+ * Plugins admin page
+ */
+
+function admin_page_plugins(&$a){
+
+ /**
+ * Single plugin
+ */
+ if ($a->argc == 3){
+ $plugin = $a->argv[2];
+ if (!is_file("addon/$plugin/$plugin.php")){
+ notice( t("Item not found.") );
+ return;
+ }
+
+ if (x($_GET,"a") && $_GET['a']=="t"){
+ // Toggle plugin status
+ $idx = array_search($plugin, $a->plugins);
+ if ($idx){
+ unset($a->plugins[$idx]);
+ uninstall_plugin($plugin);
+ info( sprintf( t("Plugin %s disabled."), $plugin ) );
+ } else {
+ $a->plugins[] = $plugin;
+ install_plugin($plugin);
+ info( sprintf( t("Plugin %s enabled."), $plugin ) );
+ }
+ set_config("system","addon", implode(", ",$a->plugins));
+ goaway($a->get_baseurl() . '/admin/plugins' );
+ return; // NOTREACHED
+ }
+ // display plugin details
+ require_once('library/markdown.php');
+
+ if (in_array($plugin, $a->plugins)){
+ $status="on"; $action= t("Disable");
+ } else {
+ $status="off"; $action= t("Enable");
+ }
+
+ $readme=Null;
+ if (is_file("addon/$plugin/README.md")){
+ $readme = file_get_contents("addon/$plugin/README.md");
+ $readme = Markdown($readme);
+ } else if (is_file("addon/$plugin/README")){
+ $readme = "<pre>". file_get_contents("addon/$plugin/README") ."</pre>";
+ }
+
+ $admin_form="";
+ if (is_array($a->plugins_admin) && in_array($plugin, $a->plugins_admin)){
+ @require_once("addon/$plugin/$plugin.php");
+ $func = $plugin.'_plugin_admin';
+ $func($a, $admin_form);
+ }
+
+ $t = get_markup_template("admin_plugins_details.tpl");
+ return replace_macros($t, array(
+ '$title' => t('Administration'),
+ '$page' => t('Plugins'),
+ '$toggle' => t('Toggle'),
+ '$settings' => t('Settings'),
+ '$baseurl' => $a->get_baseurl(),
+
+ '$plugin' => $plugin,
+ '$status' => $status,
+ '$action' => $action,
+ '$info' => get_plugin_info($plugin),
+
+ '$admin_form' => $admin_form,
+
+ '$readme' => $readme
+ ));
+ }
+
+
+
+ /**
+ * List plugins
+ */
+
+ $plugins = array();
+ $files = glob("addon/*/");
+ if($files) {
+ foreach($files as $file) {
+ if (is_dir($file)){
+ list($tmp, $id)=array_map("trim", explode("/",$file));
+ $info = get_plugin_info($id);
+ $plugins[] = array( $id, (in_array($id, $a->plugins)?"on":"off") , $info);
+ }
+ }
+ }
+
+ $t = get_markup_template("admin_plugins.tpl");
+ return replace_macros($t, array(
+ '$title' => t('Administration'),
+ '$page' => t('Plugins'),
+ '$submit' => t('Submit'),
+ '$baseurl' => $a->get_baseurl(),
+
+ '$plugins' => $plugins
+ ));
+}
+
+
+/**
+ * Logs admin page
+ */
+
+function admin_page_logs_post(&$a) {
+ if (x($_POST,"page_logs")) {
+
+ $logfile = ((x($_POST,'logfile')) ? notags(trim($_POST['logfile'])) : '');
+ $debugging = ((x($_POST,'debugging')) ? true : false);
+ $loglevel = ((x($_POST,'loglevel')) ? intval(trim($_POST['loglevel'])) : 0);
+
+ set_config('system','logfile', $logfile);
+ set_config('system','debugging', $debugging);
+ set_config('system','loglevel', $loglevel);
+
+
+ }
+
+ info( t("Log settings updated.") );
+ goaway($a->get_baseurl() . '/admin/logs' );
+ return; // NOTREACHED
+}
+
+function admin_page_logs(&$a){
+
+ $log_choices = Array(
+ LOGGER_NORMAL => 'Normal',
+ LOGGER_TRACE => 'Trace',
+ LOGGER_DEBUG => 'Debug',
+ LOGGER_DATA => 'Data',
+ LOGGER_ALL => 'All'
+ );
+
+ $t = get_markup_template("admin_logs.tpl");
+
+ $f = get_config('system','logfile');
+ $size = filesize($f);
+ if($size > 5000000 || $size < 0)
+ $size = 5000000;
+
+ $data = '';
+ $fp = fopen($f,'r');
+ if($fp) {
+ $seek = fseek($fp,0-$size,SEEK_END);
+ if($seek === 0) {
+ fgets($fp); // throw away the first partial line
+ $data = escape_tags(fread($fp,$size));
+ while(! feof($fp))
+ $data .= escape_tags(fread($fp,4096));
+ }
+ fclose($fp);
+ }
+
+
+ return replace_macros($t, array(
+ '$title' => t('Administration'),
+ '$page' => t('Logs'),
+ '$submit' => t('Submit'),
+ '$clear' => t('Clear'),
+ '$data' => $data,
+ '$baseurl' => $a->get_baseurl(),
+ '$logname' => get_config('system','logfile'),
+
+ // name, label, value, help string, extra data...
+ '$debugging' => array('debugging', t("Debugging"),get_config('system','debugging'), ""),
+ '$logfile' => array('logfile', t("Log file"), get_config('system','logfile'), t("Must be writable by web server. Relative to your Friendika index.php.")),
+ '$loglevel' => array('loglevel', t("Log level"), get_config('system','loglevel'), "", $log_choices),
+ ));
+}
+
+function admin_page_remoteupdate_post(&$a) {
+ // this function should be called via ajax post
+ if(!is_site_admin()) {
+ return login(false);
+ }
+
+
+ if (x($_POST,'remotefile') && $_POST['remotefile']!=""){
+ $remotefile = $_POST['remotefile'];
+ $ftpdata = (x($_POST['ftphost'])?$_POST:false);
+ doUpdate($remotefile, $ftpdata);
+ } else {
+ echo "No remote file to download. Abort!";
+ }
+
+ killme();
+}
+
+function admin_page_remoteupdate(&$a) {
+ if(!is_site_admin()) {
+ return login(false);
+ }
+
+ $canwrite = canWeWrite();
+ $canftp = function_exists('ftp_connect');
+
+ $needupdate = true;
+ $u = checkUpdate();
+ if (!is_array($u)){
+ $needupdate = false;
+ $u = array('','','');
+ }
+
+ $tpl = get_markup_template("admin_remoteupdate.tpl");
+ return replace_macros($tpl, array(
+ '$baseurl' => $a->get_baseurl(),
+ '$submit' => t("Update now"),
+ '$close' => t("Close"),
+ '$localversion' => FRIENDIKA_VERSION,
+ '$remoteversion' => $u[1],
+ '$needupdate' => $needupdate,
+ '$canwrite' => $canwrite,
+ '$canftp' => $canftp,
+ '$ftphost' => array('ftphost', t("FTP Host"), '',''),
+ '$ftppath' => array('ftppath', t("FTP Path"), '/',''),
+ '$ftpuser' => array('ftpuser', t("FTP User"), '',''),
+ '$ftppwd' => array('ftppwd', t("FTP Password"), '',''),
+ '$remotefile'=>array('remotefile','', $u['2'],'')
+ ));
+
+}