8 function admin_init(&$a) {
10 notice( t('Permission denied.') . EOL);
15 function admin_post(&$a){
16 if(!is_site_admin()) {
24 admin_page_site_post($a);
27 admin_page_users_post($a);
31 is_file("addon/".$a->argv[2]."/".$a->argv[2].".php")){
32 @include_once("addon/".$a->argv[2]."/".$a->argv[2].".php");
33 if(function_exists($a->argv[2].'_plugin_admin_post')) {
34 $func = $a->argv[2].'_plugin_admin_post';
38 goaway($a->get_baseurl() . '/admin/plugins/' . $a->argv[2] );
42 admin_page_logs_post($a);
47 goaway($a->get_baseurl() . '/admin' );
51 function admin_content(&$a) {
53 if(!is_site_admin()) {
61 // array( url, name, extra css classes )
63 'site' => Array($a->get_baseurl()."/admin/site/", t("Site") , "site"),
64 'users' => Array($a->get_baseurl()."/admin/users/", t("Users") , "users"),
65 'plugins'=> Array($a->get_baseurl()."/admin/plugins/", t("Plugins") , "plugins")
68 /* get plugins admin page */
70 $r = q("SELECT * FROM `addon` WHERE `plugin_admin`=1");
71 $aside['plugins_admin']=Array();
74 $aside['plugins_admin'][] = Array($a->get_baseurl()."/admin/plugins/".$plugin, $plugin, "plugin");
75 // temp plugins with admin
76 $a->plugins_admin[] = $plugin;
79 $aside['logs'] = Array($a->get_baseurl()."/admin/logs/", t("Logs"), "logs");
81 $t = get_markup_template("admin_aside.tpl");
82 $a->page['aside'] = replace_macros( $t, array(
84 '$h_pending' => t('User registrations waiting for confirmation'),
85 '$admurl'=> $a->get_baseurl()."/admin/"
99 $o = admin_page_site($a);
102 $o = admin_page_users($a);
105 $o = admin_page_plugins($a);
108 $o = admin_page_logs($a);
111 notice( t("Item not found.") );
114 $o = admin_page_summary($a);
123 function admin_page_summary(&$a) {
124 $r = q("SELECT `page-flags`, COUNT(uid) as `count` FROM `user` GROUP BY `page-flags`");
126 Array( t('Normal Account'), 0),
127 Array( t('Soapbox Account'), 0),
128 Array( t('Community/Celebrity Account'), 0),
129 Array( t('Automatic Friend Account'), 0)
132 foreach ($r as $u){ $accounts[$u['page-flags']][1] = $u['count']; $users+=$u['count']; }
135 $r = q("SELECT COUNT(id) as `count` FROM `register`");
136 $pending = $r[0]['count'];
142 $t = get_markup_template("admin_summary.tpl");
143 return replace_macros($t, array(
144 '$title' => t('Administration'),
145 '$page' => t('Summary'),
146 '$users' => Array( t('Registered users'), $users),
147 '$accounts' => $accounts,
148 '$pending' => Array( t('Pending registrations'), $pending),
149 '$version' => Array( t('Version'), FRIENDIKA_VERSION),
150 '$build' => get_config('system','build'),
151 '$plugins' => Array( t('Active plugins'), $a->plugins )
159 function admin_page_site_post(&$a){
160 if (!x($_POST,"page_site")){
165 $sitename = ((x($_POST,'sitename')) ? notags(trim($_POST['sitename'])) : '');
166 $banner = ((x($_POST,'banner')) ? trim($_POST['banner']) : false);
167 $language = ((x($_POST,'language')) ? notags(trim($_POST['language'])) : '');
168 $theme = ((x($_POST,'theme')) ? notags(trim($_POST['theme'])) : '');
169 $maximagesize = ((x($_POST,'maximagesize')) ? intval(trim($_POST['maximagesize'])) : 0);
172 $register_policy = ((x($_POST,'register_policy')) ? intval(trim($_POST['register_policy'])) : 0);
173 $register_text = ((x($_POST,'register_text')) ? notags(trim($_POST['register_text'])) : '');
175 $allowed_sites = ((x($_POST,'allowed_sites')) ? notags(trim($_POST['allowed_sites'])) : '');
176 $allowed_email = ((x($_POST,'allowed_email')) ? notags(trim($_POST['allowed_email'])) : '');
177 $block_public = ((x($_POST,'block_public')) ? True : False);
178 $force_publish = ((x($_POST,'publish_all')) ? True : False);
179 $global_directory = ((x($_POST,'directory_submit_url')) ? notags(trim($_POST['directory_submit_url'])) : '');
180 $no_multi_reg = ((x($_POST,'no_multi_reg')) ? True : False);
181 $no_openid = !((x($_POST,'no_openid')) ? True : False);
182 $no_gravatar = !((x($_POST,'no_gravatar')) ? True : False);
183 $no_regfullname = !((x($_POST,'no_regfullname')) ? True : False);
184 $no_utf = !((x($_POST,'no_utf')) ? True : False);
185 $no_community_page = !((x($_POST,'no_community_page')) ? True : False);
187 $verifyssl = ((x($_POST,'verifyssl')) ? True : False);
188 $proxyuser = ((x($_POST,'proxyuser')) ? notags(trim($_POST['global_search_url'])) : '');
189 $proxy = ((x($_POST,'proxy')) ? notags(trim($_POST['global_search_url'])) : '');
190 $timeout = ((x($_POST,'timeout')) ? intval(trim($_POST['timeout'])) : 60);
191 $dfrn_only = ((x($_POST,'dfrn_only')) ? True : False);
192 $ostatus_disabled = !((x($_POST,'ostatus_disabled')) ? True : False);
195 set_config('config','sitename',$sitename);
197 // don't know why, but del_config doesn't work...
198 q("DELETE FROM `config` WHERE `cat` = '%s' AND `k` = '%s' LIMIT 1",
203 set_config('system','banner', $banner);
205 set_config('system','language', $language);
206 set_config('system','theme', $theme);
207 set_config('system','maximagesize', $maximagesize);
209 set_config('config','register_policy', $register_policy);
210 set_config('config','register_text', $register_text);
211 set_config('system','allowed_sites', $allowed_sites);
212 set_config('system','allowed_email', $allowed_email);
213 set_config('system','block_public', $block_public);
214 set_config('system','publish_all', $force_publish);
215 if ($global_directory==""){
216 // don't know why, but del_config doesn't work...
217 q("DELETE FROM `config` WHERE `cat` = '%s' AND `k` = '%s' LIMIT 1",
219 dbesc("directory_submit_url")
222 set_config('system','directory_submit_url', $global_directory);
224 set_config('system','directory_search_url', $global_search_url);
225 set_config('system','block_extended_register', $no_multi_reg);
226 set_config('system','no_openid', $no_openid);
227 set_config('system','no_gravatar', $no_gravatar);
228 set_config('system','no_regfullname', $no_regfullname);
229 set_config('system','no_community_page', $no_community_page);
230 set_config('system','proxy', $no_utf);
231 set_config('system','verifyssl', $verifyssl);
232 set_config('system','proxyuser', $proxyuser);
233 set_config('system','proxy', $proxy);
234 set_config('system','curl_timeout', $timeout);
235 set_config('system','dfrn_only', $dfrn_only);
236 set_config('system','ostatus_disabled', $ostatus_disabled);
238 info( t('Site settings updated.') . EOL);
239 goaway($a->get_baseurl() . '/admin/site' );
240 return; // NOTREACHED
244 function admin_page_site(&$a) {
246 /* Installed langs */
247 $lang_choices = array();
248 $langs = glob('view/*/strings.php');
250 if(is_array($langs) && count($langs)) {
251 if(! in_array('view/en/strings.php',$langs))
252 $langs[] = 'view/en/';
254 foreach($langs as $l) {
255 $t = explode("/",$l);
256 $lang_choices[$t[1]] = $t[1];
260 /* Installed themes */
261 $theme_choices = array();
262 $files = glob('view/theme/*');
264 foreach($files as $file) {
265 $f = basename($file);
266 $theme_name = ((file_exists($file . '/experimental')) ? sprintf("%s - \x28Experimental\x29", $f) : $f);
267 $theme_choices[$f] = $theme_name;
273 $banner = get_config('system','banner');
275 $banner = '<a href="http://project.friendika.com"><img id="logo-img" src="images/friendika-32.png" alt="logo" /></a><span id="logo-text"><a href="http://project.friendika.com">Friendika</a></span>';
276 $banner = htmlspecialchars($banner);
278 //echo "<pre>"; var_dump($lang_choices); die("</pre>");
280 /* Register policy */
281 $register_choices = Array(
282 REGISTER_CLOSED => t("Closed"),
283 REGISTER_APPROVE => t("Requires approval"),
284 REGISTER_OPEN => t("Open")
287 $t = get_markup_template("admin_site.tpl");
288 return replace_macros($t, array(
289 '$title' => t('Administration'),
290 '$page' => t('Site'),
291 '$submit' => t('Submit'),
292 '$registration' => t('Registration'),
293 '$upload' => t('File upload'),
294 '$corporate' => t('Policies'),
295 '$advanced' => t('Advanced'),
297 '$baseurl' => $a->get_baseurl(),
298 // name, label, value, help string, extra data...
299 '$sitename' => array('sitename', t("Site name"), htmlentities($a->config['sitename'], ENT_QUOTES), ""),
300 '$banner' => array('banner', t("Banner/Logo"), $banner, ""),
301 '$language' => array('language', t("System language"), get_config('system','language'), "", $lang_choices),
302 '$theme' => array('theme', t("System theme"), get_config('system','theme'), "Default system theme (which may be over-ridden by user profiles)", $theme_choices),
304 '$maximagesize' => array('maximagesize', t("Maximum image size"), get_config('system','maximagesize'), "Maximum size in bytes of uploaded images. Default is 0, which means no limits."),
306 '$register_policy' => array('register_policy', t("Register policy"), $a->config['register_policy'], "", $register_choices),
307 '$register_text' => array('register_text', t("Register text"), htmlentities($a->config['register_text'], ENT_QUOTES), "Will be displayed prominently on the registration page."),
308 '$allowed_sites' => array('allowed_sites', t("Allowed friend domains"), get_config('system','allowed_sites'), "Comma separated list of domains which are allowed to establish friendships with this site. Wildcards are accepted. Empty to allow any domains"),
309 '$allowed_email' => array('allowed_email', t("Allowed email domains"), get_config('system','allowed_email'), "Comma separated list of domains which are allowed in email addresses for registrations to this site. Wildcards are accepted. Empty to allow any domains"),
310 '$block_public' => array('block_public', t("Block public"), get_config('system','block_public'), "Check to block public access to all otherwise public personal pages on this site unless you are currently logged in."),
311 '$force_publish' => array('publish_all', t("Force publish"), get_config('system','publish_all'), "Check to force all profiles on this site to be listed in the site directory."),
312 '$global_directory' => array('directory_submit_url', t("Global directory update URL"), get_config('system','directory_submit_url'), "URL to update the global directory. If this is not set, the global directory is completely unavailable to the application."),
314 '$no_multi_reg' => array('no_multi_reg', t("Block multiple registrations"), get_config('system','block_extended_register'), "Disallow users to register additional accounts for use as pages."),
315 '$no_openid' => array('no_openid', t("OpenID support"), !get_config('system','no_openid'), "OpenID support for registration and logins."),
316 '$no_gravatar' => array('no_gravatar', t("Gravatar support"), !get_config('system','no_gravatar'), "Search new user's photo on Gravatar."),
317 '$no_regfullname' => array('no_regfullname', t("Fullname check"), !get_config('system','no_regfullname'), "Force users to register with a space between firstname and lastname in Full name, as an antispam measure"),
318 '$no_utf' => array('no_utf', t("UTF-8 Regular expressions"), !get_config('system','proxy'), "Use PHP UTF8 regular expressions"),
319 '$no_community_page' => array('no_community_page', t("Show Community Page"), !get_config('system','no_community_page'), "Display a Community page showing all recent public postings on this site."),
320 '$ostatus_disabled' => array('ostatus_disabled', t("Enable OStatus support"), !get_config('system','ostatus_disable'), "Provide built-in OStatus \x28identi.ca, status.net, etc.\x29 compatibility. All communications in OStatus are public, so privacy warnings will be occasionally displayed."),
321 '$dfrn_only' => array('dfrn_only', t('Only allow Friendika contacts'), get_config('system','dfrn_only'), "All contacts must use Friendika protocols. All other built-in communication protocols disabled."),
322 '$verifyssl' => array('verifyssl', t("Verify SSL"), get_config('system','verifyssl'), "If you wish, you can turn on strict certificate checking. This will mean you cannot connect (at all) to self-signed SSL sites."),
323 '$proxyuser' => array('proxyuser', t("Proxy user"), get_config('system','proxyuser'), ""),
324 '$proxy' => array('proxy', t("Proxy URL"), get_config('system','proxy'), ""),
325 '$timeout' => array('timeout', t("Network timeout"), (x(get_config('system','curl_timeout'))?get_config('system','curl_timeout'):60), "Value is in seconds. Set to 0 for unlimited (not recommended)."),
336 function admin_page_users_post(&$a){
337 $pending = ( x(£_POST, 'pending') ? $_POST['pending'] : Array() );
338 $users = ( x($_POST, 'user') ? $_POST['user'] : Array() );
340 if (x($_POST,'page_users_block')){
341 foreach($users as $uid){
342 q("UPDATE `user` SET `blocked`=1-`blocked` WHERE `uid`=%s",
346 notice( sprintf( tt("%s user blocked", "%s users blocked/unblocked", count($users)), count($users)) );
348 if (x($_POST,'page_users_delete')){
349 require_once("include/Contact.php");
350 foreach($users as $uid){
353 notice( sprintf( tt("%s user deleted", "%s users deleted", count($users)), count($users)) );
356 if (x($_POST,'page_users_approve')){
357 require_once("mod/regmod.php");
358 foreach($pending as $hash){
362 if (x($_POST,'page_users_deny')){
363 require_once("mod/regmod.php");
364 foreach($pending as $hash){
368 goaway($a->get_baseurl() . '/admin/users' );
369 return; // NOTREACHED
372 function admin_page_users(&$a){
375 $user = q("SELECT * FROM `user` WHERE `uid`=%d", intval($uid));
376 if (count($user)==0){
377 notice( 'User not found' . EOL);
378 goaway($a->get_baseurl() . '/admin/users' );
379 return; // NOTREACHED
384 require_once("include/Contact.php");
387 notice( sprintf(t("User '%s' deleted"), $user[0]['username']) . EOL);
390 q("UPDATE `user` SET `blocked`=%d WHERE `uid`=%s",
391 intval( 1-$user[0]['blocked'] ),
394 notice( sprintf( ($user[0]['blocked']?t("User '%s' unblocked"):t("User '%s' blocked")) , $user[0]['username']) . EOL);
397 goaway($a->get_baseurl() . '/admin/users' );
398 return; // NOTREACHED
403 $pending = q("SELECT `register`.*, `contact`.`name`, `user`.`email`
405 LEFT JOIN `contact` ON `register`.`uid` = `contact`.`uid`
406 LEFT JOIN `user` ON `register`.`uid` = `user`.`uid`;");
410 $total = q("SELECT count(*) as total FROM `user` where 1");
412 $a->set_pager_total($total[0]['total']);
413 $a->set_pager_itemspage(100);
416 $users = q("SELECT `user` . * , `contact`.`name` , `contact`.`url` , `contact`.`micro`, `lastitem`.`lastitem_date`
418 (SELECT MAX(`item`.`changed`) as `lastitem_date`, `item`.`uid`
420 WHERE `item`.`type` = 'wall'
421 GROUP BY `item`.`uid`) AS `lastitem`
422 RIGHT OUTER JOIN `user` ON `user`.`uid` = `lastitem`.`uid`,
425 `user`.`uid` = `contact`.`uid`
426 AND `user`.`verified` =1
427 AND `contact`.`self` =1
428 ORDER BY `contact`.`name` LIMIT %d, %d
430 intval($a->pager['start']),
431 intval($a->pager['itemspage'])
434 function _setup_users($e){
437 t('Soapbox Account'),
438 t('Community/Celebrity Account'),
439 t('Automatic Friend Account')
441 $e['page-flags'] = $accounts[$e['page-flags']];
442 $e['register_date'] = relative_date($e['register_date']);
443 $e['login_date'] = relative_date($e['login_date']);
444 $e['lastitem_date'] = relative_date($e['lastitem_date']);
447 $users = array_map("_setup_users", $users);
449 $t = get_markup_template("admin_users.tpl");
450 $o = replace_macros($t, array(
452 '$title' => t('Administration'),
453 '$page' => t('Users'),
454 '$submit' => t('Submit'),
455 '$select_all' => t('select all'),
456 '$h_pending' => t('User registrations waiting for confirm'),
457 '$th_pending' => array( t('Request date'), t('Name'), t('Email') ),
458 '$no_pending' => t('No registrations.'),
459 '$approve' => t('Approve'),
460 '$deny' => t('Deny'),
461 '$delete' => t('Delete'),
462 '$block' => t('Block'),
463 '$unblock' => t('Unblock'),
465 '$h_users' => t('Users'),
466 '$th_users' => array( t('Name'), t('Email'), t('Register date'), t('Last login'), t('Last item'), t('Account') ),
468 '$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?'),
469 '$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?'),
473 '$baseurl' => $a->get_baseurl(),
475 '$pending' => $pending,
487 function admin_page_plugins(&$a){
493 $plugin = $a->argv[2];
494 if (!is_file("addon/$plugin/$plugin.php")){
495 notice( t("Item not found.") );
499 if (x($_GET,"a") && $_GET['a']=="t"){
500 // Toggle plugin status
501 $idx = array_search($plugin, $a->plugins);
503 unset($a->plugins[$idx]);
504 uninstall_plugin($plugin);
505 info( sprintf( t("Plugin %s disabled."), $plugin ) );
507 $a->plugins[] = $plugin;
508 install_plugin($plugin);
509 info( sprintf( t("Plugin %s enabled."), $plugin ) );
511 set_config("system","addon", implode(", ",$a->plugins));
512 goaway($a->get_baseurl() . '/admin/plugins' );
513 return; // NOTREACHED
515 // display plugin details
516 require_once('library/markdown.php');
518 if (in_array($plugin, $a->plugins)){
519 $status="on"; $action= t("Disable");
521 $status="off"; $action= t("Enable");
525 if (is_file("addon/$plugin/README.md")){
526 $readme = file_get_contents("addon/$plugin/README.md");
527 $readme = Markdown($readme);
528 } else if (is_file("addon/$plugin/README")){
529 $readme = "<pre>". file_get_contents("addon/$plugin/README") ."</pre>";
533 if (in_array($plugin, $a->plugins_admin)){
534 @require_once("addon/$plugin/$plugin.php");
535 $func = $plugin.'_plugin_admin';
536 $func($a, $admin_form);
539 $t = get_markup_template("admin_plugins_details.tpl");
540 return replace_macros($t, array(
541 '$title' => t('Administration'),
542 '$page' => t('Plugins'),
543 '$toggle' => t('Toggle'),
544 '$settings' => t('Settings'),
545 '$baseurl' => $a->get_baseurl(),
547 '$plugin' => $plugin,
548 '$status' => $status,
549 '$action' => $action,
550 '$info' => get_plugin_info($plugin),
552 '$admin_form' => $admin_form,
565 $files = glob("addon/*/");
567 foreach($files as $file) {
569 list($tmp, $id)=array_map("trim", explode("/",$file));
570 $info = get_plugin_info($id);
571 $plugins[] = array( $id, (in_array($id, $a->plugins)?"on":"off") , $info);
576 $t = get_markup_template("admin_plugins.tpl");
577 return replace_macros($t, array(
578 '$title' => t('Administration'),
579 '$page' => t('Plugins'),
580 '$submit' => t('Submit'),
581 '$baseurl' => $a->get_baseurl(),
583 '$plugins' => $plugins
592 function admin_page_logs_post(&$a) {
593 if (x($_POST,"page_logs")) {
595 $logfile = ((x($_POST,'logfile')) ? notags(trim($_POST['logfile'])) : '');
596 $debugging = ((x($_POST,'debugging')) ? true : false);
597 $loglevel = ((x($_POST,'loglevel')) ? intval(trim($_POST['loglevel'])) : 0);
599 set_config('system','logfile', $logfile);
600 set_config('system','debugging', $debugging);
601 set_config('system','loglevel', $loglevel);
606 info( t("Log settings updated.") );
607 goaway($a->get_baseurl() . '/admin/logs' );
608 return; // NOTREACHED
611 function admin_page_logs(&$a){
613 $log_choices = Array(
614 LOGGER_NORMAL => 'Normal',
615 LOGGER_TRACE => 'Trace',
616 LOGGER_DEBUG => 'Debug',
617 LOGGER_DATA => 'Data',
621 $t = get_markup_template("admin_logs.tpl");
623 $f = get_config('system','logfile');
624 $size = filesize($f);
631 $seek = fseek($fp,0-$size,SEEK_END);
633 fgets($fp); // throw away the first partial line
634 $data = escape_tags(fread($fp,$size));
636 $data .= escape_tags(fread($fp,4096));
642 return replace_macros($t, array(
643 '$title' => t('Administration'),
644 '$page' => t('Logs'),
645 '$submit' => t('Submit'),
646 '$clear' => t('Clear'),
648 '$baseurl' => $a->get_baseurl(),
649 '$logname' => get_config('system','logfile'),
651 // name, label, value, help string, extra data...
652 '$debugging' => array('debugging', t("Debugging"),get_config('system','debugging'), ""),
653 '$logfile' => array('logfile', t("Log file"), get_config('system','logfile'), t("Must be writable by web server. Relative to your Friendika index.php.")),
654 '$loglevel' => array('loglevel', t("Log level"), get_config('system','loglevel'), "", $log_choices),