6 require_once("include/remoteupdate.php");
12 function admin_post(&$a){
15 if(!is_site_admin()) {
19 // do not allow a page manager to access the admin panel at all.
21 if(x($_SESSION,'submanage') && intval($_SESSION['submanage']))
30 admin_page_site_post($a);
33 admin_page_users_post($a);
37 is_file("addon/".$a->argv[2]."/".$a->argv[2].".php")){
38 @include_once("addon/".$a->argv[2]."/".$a->argv[2].".php");
39 if(function_exists($a->argv[2].'_plugin_admin_post')) {
40 $func = $a->argv[2].'_plugin_admin_post';
44 goaway($a->get_baseurl(true) . '/admin/plugins/' . $a->argv[2] );
49 if (is_file("view/theme/$theme/config.php")){
50 require_once("view/theme/$theme/config.php");
51 if (function_exists("theme_admin_post")){
55 info(t('Theme settings updated.'));
58 goaway($a->get_baseurl(true) . '/admin/themes/' . $theme );
62 admin_page_logs_post($a);
65 admin_page_remoteupdate_post($a);
70 goaway($a->get_baseurl(true) . '/admin' );
78 function admin_content(&$a) {
80 if(!is_site_admin()) {
84 if(x($_SESSION,'submanage') && intval($_SESSION['submanage']))
91 // array( url, name, extra css classes )
93 'site' => Array($a->get_baseurl(true)."/admin/site/", t("Site") , "site"),
94 'users' => Array($a->get_baseurl(true)."/admin/users/", t("Users") , "users"),
95 'plugins'=> Array($a->get_baseurl(true)."/admin/plugins/", t("Plugins") , "plugins"),
96 'themes' => Array($a->get_baseurl(true)."/admin/themes/", t("Themes") , "themes"),
97 'update' => Array($a->get_baseurl(true)."/admin/update/", t("Update") , "update")
100 /* get plugins admin page */
102 $r = q("SELECT * FROM `addon` WHERE `plugin_admin`=1");
103 $aside['plugins_admin']=Array();
106 $aside['plugins_admin'][] = Array($a->get_baseurl(true)."/admin/plugins/".$plugin, $plugin, "plugin");
107 // temp plugins with admin
108 $a->plugins_admin[] = $plugin;
111 $aside['logs'] = Array($a->get_baseurl(true)."/admin/logs/", t("Logs"), "logs");
113 $t = get_markup_template("admin_aside.tpl");
114 $a->page['aside'] = replace_macros( $t, array(
116 '$h_pending' => t('User registrations waiting for confirmation'),
117 '$admurl'=> $a->get_baseurl(true)."/admin/"
129 switch ($a->argv[1]){
131 $o = admin_page_site($a);
134 $o = admin_page_users($a);
137 $o = admin_page_plugins($a);
140 $o = admin_page_themes($a);
143 $o = admin_page_logs($a);
146 $o = admin_page_remoteupdate($a);
149 notice( t("Item not found.") );
152 $o = admin_page_summary($a);
170 function admin_page_summary(&$a) {
171 $r = q("SELECT `page-flags`, COUNT(uid) as `count` FROM `user` GROUP BY `page-flags`");
173 Array( t('Normal Account'), 0),
174 Array( t('Soapbox Account'), 0),
175 Array( t('Community/Celebrity Account'), 0),
176 Array( t('Automatic Friend Account'), 0)
179 foreach ($r as $u){ $accounts[$u['page-flags']][1] = $u['count']; $users+= $u['count']; }
181 logger('accounts: ' . print_r($accounts,true));
183 $r = q("SELECT COUNT(id) as `count` FROM `register`");
184 $pending = $r[0]['count'];
186 $t = get_markup_template("admin_summary.tpl");
187 return replace_macros($t, array(
188 '$title' => t('Administration'),
189 '$page' => t('Summary'),
190 '$users' => Array( t('Registered users'), $users),
191 '$accounts' => $accounts,
192 '$pending' => Array( t('Pending registrations'), $pending),
193 '$version' => Array( t('Version'), FRIENDICA_VERSION),
194 '$build' => get_config('system','build'),
195 '$plugins' => Array( t('Active plugins'), $a->plugins )
204 function admin_page_site_post(&$a){
205 if (!x($_POST,"page_site")){
209 check_form_security_token_redirectOnErr('/admin/site', 'admin_site');
211 $sitename = ((x($_POST,'sitename')) ? notags(trim($_POST['sitename'])) : '');
212 $banner = ((x($_POST,'banner')) ? trim($_POST['banner']) : false);
213 $language = ((x($_POST,'language')) ? notags(trim($_POST['language'])) : '');
214 $theme = ((x($_POST,'theme')) ? notags(trim($_POST['theme'])) : '');
215 $maximagesize = ((x($_POST,'maximagesize')) ? intval(trim($_POST['maximagesize'])) : 0);
218 $register_policy = ((x($_POST,'register_policy')) ? intval(trim($_POST['register_policy'])) : 0);
219 $abandon_days = ((x($_POST,'abandon_days')) ? intval(trim($_POST['abandon_days'])) : 0);
221 $register_text = ((x($_POST,'register_text')) ? notags(trim($_POST['register_text'])) : '');
223 $allowed_sites = ((x($_POST,'allowed_sites')) ? notags(trim($_POST['allowed_sites'])) : '');
224 $allowed_email = ((x($_POST,'allowed_email')) ? notags(trim($_POST['allowed_email'])) : '');
225 $block_public = ((x($_POST,'block_public')) ? True : False);
226 $force_publish = ((x($_POST,'publish_all')) ? True : False);
227 $global_directory = ((x($_POST,'directory_submit_url')) ? notags(trim($_POST['directory_submit_url'])) : '');
228 $no_multi_reg = ((x($_POST,'no_multi_reg')) ? True : False);
229 $no_openid = !((x($_POST,'no_openid')) ? True : False);
230 $no_regfullname = !((x($_POST,'no_regfullname')) ? True : False);
231 $no_utf = !((x($_POST,'no_utf')) ? True : False);
232 $no_community_page = !((x($_POST,'no_community_page')) ? True : False);
234 $verifyssl = ((x($_POST,'verifyssl')) ? True : False);
235 $proxyuser = ((x($_POST,'proxyuser')) ? notags(trim($_POST['proxyuser'])) : '');
236 $proxy = ((x($_POST,'proxy')) ? notags(trim($_POST['proxy'])) : '');
237 $timeout = ((x($_POST,'timeout')) ? intval(trim($_POST['timeout'])) : 60);
238 $dfrn_only = ((x($_POST,'dfrn_only')) ? True : False);
239 $ostatus_disabled = !((x($_POST,'ostatus_disabled')) ? True : False);
240 $diaspora_enabled = ((x($_POST,'diaspora_enabled')) ? True : False);
241 $ssl_policy = ((x($_POST,'ssl_policy')) ? intval($_POST['ssl_policy']) : 0);
243 if($ssl_policy != intval(get_config('system','ssl_policy'))) {
244 if($ssl_policy == SSL_POLICY_FULL) {
245 q("update `contact` set
246 `url` = replace(`url` , 'http:' , 'https:'),
247 `photo` = replace(`photo` , 'http:' , 'https:'),
248 `thumb` = replace(`thumb` , 'http:' , 'https:'),
249 `micro` = replace(`micro` , 'http:' , 'https:'),
250 `request` = replace(`request`, 'http:' , 'https:'),
251 `notify` = replace(`notify` , 'http:' , 'https:'),
252 `poll` = replace(`poll` , 'http:' , 'https:'),
253 `confirm` = replace(`confirm`, 'http:' , 'https:'),
254 `poco` = replace(`poco` , 'http:' , 'https:')
257 q("update `profile` set
258 `photo` = replace(`photo` , 'http:' , 'https:'),
259 `thumb` = replace(`thumb` , 'http:' , 'https:')
263 elseif($ssl_policy == SSL_POLICY_SELFSIGN) {
264 q("update `contact` set
265 `url` = replace(`url` , 'https:' , 'http:'),
266 `photo` = replace(`photo` , 'https:' , 'http:'),
267 `thumb` = replace(`thumb` , 'https:' , 'http:'),
268 `micro` = replace(`micro` , 'https:' , 'http:'),
269 `request` = replace(`request`, 'https:' , 'http:'),
270 `notify` = replace(`notify` , 'https:' , 'http:'),
271 `poll` = replace(`poll` , 'https:' , 'http:'),
272 `confirm` = replace(`confirm`, 'https:' , 'http:'),
273 `poco` = replace(`poco` , 'https:' , 'http:')
276 q("update `profile` set
277 `photo` = replace(`photo` , 'https:' , 'http:'),
278 `thumb` = replace(`thumb` , 'https:' , 'http:')
283 set_config('system','ssl_policy',$ssl_policy);
285 set_config('config','sitename',$sitename);
287 // don't know why, but del_config doesn't work...
288 q("DELETE FROM `config` WHERE `cat` = '%s' AND `k` = '%s' LIMIT 1",
293 set_config('system','banner', $banner);
295 set_config('system','language', $language);
296 set_config('system','theme', $theme);
297 set_config('system','maximagesize', $maximagesize);
299 set_config('config','register_policy', $register_policy);
300 set_config('system','account_abandon_days', $abandon_days);
301 set_config('config','register_text', $register_text);
302 set_config('system','allowed_sites', $allowed_sites);
303 set_config('system','allowed_email', $allowed_email);
304 set_config('system','block_public', $block_public);
305 set_config('system','publish_all', $force_publish);
306 if ($global_directory==""){
307 // don't know why, but del_config doesn't work...
308 q("DELETE FROM `config` WHERE `cat` = '%s' AND `k` = '%s' LIMIT 1",
310 dbesc("directory_submit_url")
313 set_config('system','directory_submit_url', $global_directory);
316 set_config('system','block_extended_register', $no_multi_reg);
317 set_config('system','no_openid', $no_openid);
318 set_config('system','no_regfullname', $no_regfullname);
319 set_config('system','no_community_page', $no_community_page);
320 set_config('system','no_utf', $no_utf);
321 set_config('system','verifyssl', $verifyssl);
322 set_config('system','proxyuser', $proxyuser);
323 set_config('system','proxy', $proxy);
324 set_config('system','curl_timeout', $timeout);
325 set_config('system','dfrn_only', $dfrn_only);
326 set_config('system','ostatus_disabled', $ostatus_disabled);
327 set_config('system','diaspora_enabled', $diaspora_enabled);
329 info( t('Site settings updated.') . EOL);
330 goaway($a->get_baseurl(true) . '/admin/site' );
331 return; // NOTREACHED
339 function admin_page_site(&$a) {
341 /* Installed langs */
342 $lang_choices = array();
343 $langs = glob('view/*/strings.php');
345 if(is_array($langs) && count($langs)) {
346 if(! in_array('view/en/strings.php',$langs))
347 $langs[] = 'view/en/';
349 foreach($langs as $l) {
350 $t = explode("/",$l);
351 $lang_choices[$t[1]] = $t[1];
355 /* Installed themes */
356 $theme_choices = array();
357 $files = glob('view/theme/*');
359 foreach($files as $file) {
360 $f = basename($file);
361 $theme_name = ((file_exists($file . '/experimental')) ? sprintf("%s - \x28Experimental\x29", $f) : $f);
362 $theme_choices[$f] = $theme_name;
368 $banner = get_config('system','banner');
370 $banner = '<a href="http://friendica.com"><img id="logo-img" src="images/friendica-32.png" alt="logo" /></a><span id="logo-text"><a href="http://friendica.com">Friendica</a></span>';
371 $banner = htmlspecialchars($banner);
373 //echo "<pre>"; var_dump($lang_choices); die("</pre>");
375 /* Register policy */
376 $register_choices = Array(
377 REGISTER_CLOSED => t("Closed"),
378 REGISTER_APPROVE => t("Requires approval"),
379 REGISTER_OPEN => t("Open")
382 $ssl_choices = array(
383 SSL_POLICY_NONE => t("No SSL policy, links will track page SSL state"),
384 SSL_POLICY_FULL => t("Force all links to use SSL"),
385 SSL_POLICY_SELFSIGN => t("Self-signed certificate, use SSL for local links only (discouraged)")
388 $t = get_markup_template("admin_site.tpl");
389 return replace_macros($t, array(
390 '$title' => t('Administration'),
391 '$page' => t('Site'),
392 '$submit' => t('Submit'),
393 '$registration' => t('Registration'),
394 '$upload' => t('File upload'),
395 '$corporate' => t('Policies'),
396 '$advanced' => t('Advanced'),
398 '$baseurl' => $a->get_baseurl(true),
399 // name, label, value, help string, extra data...
400 '$sitename' => array('sitename', t("Site name"), htmlentities($a->config['sitename'], ENT_QUOTES), ""),
401 '$banner' => array('banner', t("Banner/Logo"), $banner, ""),
402 '$language' => array('language', t("System language"), get_config('system','language'), "", $lang_choices),
403 '$theme' => array('theme', t("System theme"), get_config('system','theme'), t("Default system theme - may be over-ridden by user profiles - <a href='#' id='cnftheme'>change theme settings</a>"), $theme_choices),
404 '$ssl_policy' => array('ssl_policy', t("SSL link policy"), (string) intval(get_config('system','ssl_policy')), t("Determines whether generated links should be forced to use SSL"), $ssl_choices),
405 '$maximagesize' => array('maximagesize', t("Maximum image size"), get_config('system','maximagesize'), t("Maximum size in bytes of uploaded images. Default is 0, which means no limits.")),
407 '$register_policy' => array('register_policy', t("Register policy"), $a->config['register_policy'], "", $register_choices),
408 '$register_text' => array('register_text', t("Register text"), htmlentities($a->config['register_text'], ENT_QUOTES), t("Will be displayed prominently on the registration page.")),
409 '$abandon_days' => array('abandon_days', t('Accounts abandoned after x days'), get_config('system','account_abandon_days'), t('Will not waste system resources polling external sites for abandonded accounts. Enter 0 for no time limit.')),
410 '$allowed_sites' => array('allowed_sites', t("Allowed friend domains"), get_config('system','allowed_sites'), t("Comma separated list of domains which are allowed to establish friendships with this site. Wildcards are accepted. Empty to allow any domains")),
411 '$allowed_email' => array('allowed_email', t("Allowed email domains"), get_config('system','allowed_email'), t("Comma separated list of domains which are allowed in email addresses for registrations to this site. Wildcards are accepted. Empty to allow any domains")),
412 '$block_public' => array('block_public', t("Block public"), get_config('system','block_public'), t("Check to block public access to all otherwise public personal pages on this site unless you are currently logged in.")),
413 '$force_publish' => array('publish_all', t("Force publish"), get_config('system','publish_all'), t("Check to force all profiles on this site to be listed in the site directory.")),
414 '$global_directory' => array('directory_submit_url', t("Global directory update URL"), get_config('system','directory_submit_url'), t("URL to update the global directory. If this is not set, the global directory is completely unavailable to the application.")),
416 '$no_multi_reg' => array('no_multi_reg', t("Block multiple registrations"), get_config('system','block_extended_register'), t("Disallow users to register additional accounts for use as pages.")),
417 '$no_openid' => array('no_openid', t("OpenID support"), !get_config('system','no_openid'), t("OpenID support for registration and logins.")),
418 '$no_regfullname' => array('no_regfullname', t("Fullname check"), !get_config('system','no_regfullname'), t("Force users to register with a space between firstname and lastname in Full name, as an antispam measure")),
419 '$no_utf' => array('no_utf', t("UTF-8 Regular expressions"), !get_config('system','no_utf'), t("Use PHP UTF8 regular expressions")),
420 '$no_community_page' => array('no_community_page', t("Show Community Page"), !get_config('system','no_community_page'), t("Display a Community page showing all recent public postings on this site.")),
421 '$ostatus_disabled' => array('ostatus_disabled', t("Enable OStatus support"), !get_config('system','ostatus_disable'), t("Provide built-in OStatus \x28identi.ca, status.net, etc.\x29 compatibility. All communications in OStatus are public, so privacy warnings will be occasionally displayed.")),
422 '$diaspora_enabled' => array('diaspora_enabled', t("Enable Diaspora support"), get_config('system','diaspora_enabled'), t("Provide built-in Diaspora network compatibility.")),
423 '$dfrn_only' => array('dfrn_only', t('Only allow Friendica contacts'), get_config('system','dfrn_only'), t("All contacts must use Friendica protocols. All other built-in communication protocols disabled.")),
424 '$verifyssl' => array('verifyssl', t("Verify SSL"), get_config('system','verifyssl'), t("If you wish, you can turn on strict certificate checking. This will mean you cannot connect (at all) to self-signed SSL sites.")),
425 '$proxyuser' => array('proxyuser', t("Proxy user"), get_config('system','proxyuser'), ""),
426 '$proxy' => array('proxy', t("Proxy URL"), get_config('system','proxy'), ""),
427 '$timeout' => array('timeout', t("Network timeout"), (x(get_config('system','curl_timeout'))?get_config('system','curl_timeout'):60), t("Value is in seconds. Set to 0 for unlimited (not recommended).")),
429 '$form_security_token' => get_form_security_token("admin_site"),
441 function admin_page_users_post(&$a){
442 $pending = ( x($_POST, 'pending') ? $_POST['pending'] : Array() );
443 $users = ( x($_POST, 'user') ? $_POST['user'] : Array() );
445 check_form_security_token_redirectOnErr('/admin/users', 'admin_users');
447 if (x($_POST,'page_users_block')){
448 foreach($users as $uid){
449 q("UPDATE `user` SET `blocked`=1-`blocked` WHERE `uid`=%s",
453 notice( sprintf( tt("%s user blocked/unblocked", "%s users blocked/unblocked", count($users)), count($users)) );
455 if (x($_POST,'page_users_delete')){
456 require_once("include/Contact.php");
457 foreach($users as $uid){
460 notice( sprintf( tt("%s user deleted", "%s users deleted", count($users)), count($users)) );
463 if (x($_POST,'page_users_approve')){
464 require_once("mod/regmod.php");
465 foreach($pending as $hash){
469 if (x($_POST,'page_users_deny')){
470 require_once("mod/regmod.php");
471 foreach($pending as $hash){
475 goaway($a->get_baseurl(true) . '/admin/users' );
476 return; // NOTREACHED
483 function admin_page_users(&$a){
486 $user = q("SELECT * FROM `user` WHERE `uid`=%d", intval($uid));
487 if (count($user)==0){
488 notice( 'User not found' . EOL);
489 goaway($a->get_baseurl(true) . '/admin/users' );
490 return ''; // NOTREACHED
494 check_form_security_token_redirectOnErr('/admin/users', 'admin_users', 't');
496 require_once("include/Contact.php");
499 notice( sprintf(t("User '%s' deleted"), $user[0]['username']) . EOL);
502 check_form_security_token_redirectOnErr('/admin/users', 'admin_users', 't');
503 q("UPDATE `user` SET `blocked`=%d WHERE `uid`=%s",
504 intval( 1-$user[0]['blocked'] ),
507 notice( sprintf( ($user[0]['blocked']?t("User '%s' unblocked"):t("User '%s' blocked")) , $user[0]['username']) . EOL);
510 goaway($a->get_baseurl(true) . '/admin/users' );
511 return ''; // NOTREACHED
516 $pending = q("SELECT `register`.*, `contact`.`name`, `user`.`email`
518 LEFT JOIN `contact` ON `register`.`uid` = `contact`.`uid`
519 LEFT JOIN `user` ON `register`.`uid` = `user`.`uid`;");
524 $total = q("SELECT count(*) as total FROM `user` where 1");
526 $a->set_pager_total($total[0]['total']);
527 $a->set_pager_itemspage(100);
531 $users = q("SELECT `user` . * , `contact`.`name` , `contact`.`url` , `contact`.`micro`, `lastitem`.`lastitem_date`
533 (SELECT MAX(`item`.`changed`) as `lastitem_date`, `item`.`uid`
535 WHERE `item`.`type` = 'wall'
536 GROUP BY `item`.`uid`) AS `lastitem`
537 RIGHT OUTER JOIN `user` ON `user`.`uid` = `lastitem`.`uid`,
540 `user`.`uid` = `contact`.`uid`
541 AND `user`.`verified` =1
542 AND `contact`.`self` =1
543 ORDER BY `contact`.`name` LIMIT %d, %d
545 intval($a->pager['start']),
546 intval($a->pager['itemspage'])
549 function _setup_users($e){
552 t('Soapbox Account'),
553 t('Community/Celebrity Account'),
554 t('Automatic Friend Account')
556 $e['page-flags'] = $accounts[$e['page-flags']];
557 $e['register_date'] = relative_date($e['register_date']);
558 $e['login_date'] = relative_date($e['login_date']);
559 $e['lastitem_date'] = relative_date($e['lastitem_date']);
562 $users = array_map("_setup_users", $users);
565 $t = get_markup_template("admin_users.tpl");
566 $o = replace_macros($t, array(
568 '$title' => t('Administration'),
569 '$page' => t('Users'),
570 '$submit' => t('Submit'),
571 '$select_all' => t('select all'),
572 '$h_pending' => t('User registrations waiting for confirm'),
573 '$th_pending' => array( t('Request date'), t('Name'), t('Email') ),
574 '$no_pending' => t('No registrations.'),
575 '$approve' => t('Approve'),
576 '$deny' => t('Deny'),
577 '$delete' => t('Delete'),
578 '$block' => t('Block'),
579 '$unblock' => t('Unblock'),
581 '$h_users' => t('Users'),
582 '$th_users' => array( t('Name'), t('Email'), t('Register date'), t('Last login'), t('Last item'), t('Account') ),
584 '$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?'),
585 '$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?'),
587 '$form_security_token' => get_form_security_token("admin_users"),
590 '$baseurl' => $a->get_baseurl(true),
592 '$pending' => $pending,
606 function admin_page_plugins(&$a){
612 $plugin = $a->argv[2];
613 if (!is_file("addon/$plugin/$plugin.php")){
614 notice( t("Item not found.") );
618 if (x($_GET,"a") && $_GET['a']=="t"){
619 // Toggle plugin status
620 $idx = array_search($plugin, $a->plugins);
622 unset($a->plugins[$idx]);
623 uninstall_plugin($plugin);
624 info( sprintf( t("Plugin %s disabled."), $plugin ) );
626 $a->plugins[] = $plugin;
627 install_plugin($plugin);
628 info( sprintf( t("Plugin %s enabled."), $plugin ) );
630 set_config("system","addon", implode(", ",$a->plugins));
631 goaway($a->get_baseurl(true) . '/admin/plugins' );
632 return ''; // NOTREACHED
634 // display plugin details
635 require_once('library/markdown.php');
637 if (in_array($plugin, $a->plugins)){
638 $status="on"; $action= t("Disable");
640 $status="off"; $action= t("Enable");
644 if (is_file("addon/$plugin/README.md")){
645 $readme = file_get_contents("addon/$plugin/README.md");
646 $readme = Markdown($readme);
647 } else if (is_file("addon/$plugin/README")){
648 $readme = "<pre>". file_get_contents("addon/$plugin/README") ."</pre>";
652 if (is_array($a->plugins_admin) && in_array($plugin, $a->plugins_admin)){
653 @require_once("addon/$plugin/$plugin.php");
654 $func = $plugin.'_plugin_admin';
655 $func($a, $admin_form);
658 $t = get_markup_template("admin_plugins_details.tpl");
659 return replace_macros($t, array(
660 '$title' => t('Administration'),
661 '$page' => t('Plugins'),
662 '$toggle' => t('Toggle'),
663 '$settings' => t('Settings'),
664 '$baseurl' => $a->get_baseurl(true),
666 '$plugin' => $plugin,
667 '$status' => $status,
668 '$action' => $action,
669 '$info' => get_plugin_info($plugin),
670 '$str_author' => t('Author: '),
671 '$str_maintainer' => t('Maintainer: '),
673 '$admin_form' => $admin_form,
674 '$function' => 'plugins',
687 $files = glob("addon/*/");
689 foreach($files as $file) {
691 list($tmp, $id)=array_map("trim", explode("/",$file));
692 $info = get_plugin_info($id);
693 $plugins[] = array( $id, (in_array($id, $a->plugins)?"on":"off") , $info);
698 $t = get_markup_template("admin_plugins.tpl");
699 return replace_macros($t, array(
700 '$title' => t('Administration'),
701 '$page' => t('Plugins'),
702 '$submit' => t('Submit'),
703 '$baseurl' => $a->get_baseurl(true),
704 '$function' => 'plugins',
705 '$plugins' => $plugins
710 * @param array $themes
714 function toggle_theme(&$themes,$th,&$result) {
715 for($x = 0; $x < count($themes); $x ++) {
716 if($themes[$x]['name'] === $th) {
717 if($themes[$x]['allowed']) {
718 $themes[$x]['allowed'] = 0;
722 $themes[$x]['allowed'] = 1;
730 * @param array $themes
734 function theme_status($themes,$th) {
735 for($x = 0; $x < count($themes); $x ++) {
736 if($themes[$x]['name'] === $th) {
737 if($themes[$x]['allowed']) {
750 * @param array $themes
753 function rebuild_theme_table($themes) {
756 foreach($themes as $th) {
774 function admin_page_themes(&$a){
776 $allowed_themes_str = get_config('system','allowed_themes');
777 $allowed_themes_raw = explode(',',$allowed_themes_str);
778 $allowed_themes = array();
779 if(count($allowed_themes_raw))
780 foreach($allowed_themes_raw as $x)
782 $allowed_themes[] = trim($x);
785 $files = glob('view/theme/*');
787 foreach($files as $file) {
788 $f = basename($file);
789 $is_experimental = intval(file_exists($file . '/experimental'));
790 $is_supported = 1-(intval(file_exists($file . '/unsupported'))); // Is not used yet
791 $is_allowed = intval(in_array($f,$allowed_themes));
792 $themes[] = array('name' => $f, 'experimental' => $is_experimental, 'supported' => $is_supported, 'allowed' => $is_allowed);
796 if(! count($themes)) {
797 notice( t('No themes found.'));
806 $theme = $a->argv[2];
807 if(! is_dir("view/theme/$theme")){
808 notice( t("Item not found.") );
812 if (x($_GET,"a") && $_GET['a']=="t"){
814 // Toggle theme status
816 toggle_theme($themes,$theme,$result);
817 $s = rebuild_theme_table($themes);
819 info( sprintf('Theme %s enabled.',$theme));
821 info( sprintf('Theme %s disabled.',$theme));
823 set_config('system','allowed_themes',$s);
824 goaway($a->get_baseurl(true) . '/admin/themes' );
825 return ''; // NOTREACHED
828 // display theme details
829 require_once('library/markdown.php');
831 if (theme_status($themes,$theme)) {
832 $status="on"; $action= t("Disable");
834 $status="off"; $action= t("Enable");
838 if (is_file("view/theme/$theme/README.md")){
839 $readme = file_get_contents("view/theme/$theme/README.md");
840 $readme = Markdown($readme);
841 } else if (is_file("view/theme/$theme/README")){
842 $readme = "<pre>". file_get_contents("view/theme/$theme/README") ."</pre>";
846 if (is_file("view/theme/$theme/config.php")){
847 require_once("view/theme/$theme/config.php");
848 if(function_exists("theme_admin")){
849 $admin_form = theme_admin($a);
855 $screenshot = array( get_theme_screenshot($theme), t('Screenshot'));
856 if(! stristr($screenshot[0],$theme))
859 $t = get_markup_template("admin_plugins_details.tpl");
860 return replace_macros($t, array(
861 '$title' => t('Administration'),
862 '$page' => t('Themes'),
863 '$toggle' => t('Toggle'),
864 '$settings' => t('Settings'),
865 '$baseurl' => $a->get_baseurl(true),
868 '$status' => $status,
869 '$action' => $action,
870 '$info' => get_theme_info($theme),
871 '$function' => 'themes',
872 '$admin_form' => $admin_form,
873 '$str_author' => t('Author: '),
874 '$str_maintainer' => t('Maintainer: '),
875 '$screenshot' => $screenshot,
888 foreach($themes as $th) {
889 $xthemes[] = array($th['name'],(($th['allowed']) ? "on" : "off"), get_theme_info($th['name']));
893 $t = get_markup_template("admin_plugins.tpl");
894 return replace_macros($t, array(
895 '$title' => t('Administration'),
896 '$page' => t('Themes'),
897 '$submit' => t('Submit'),
898 '$baseurl' => $a->get_baseurl(true),
899 '$function' => 'themes',
900 '$plugins' => $xthemes,
901 '$experimental' => t('[Experimental]'),
902 '$unsupported' => t('[Unsupported]')
913 function admin_page_logs_post(&$a) {
914 if (x($_POST,"page_logs")) {
915 check_form_security_token_redirectOnErr('/admin/logs', 'admin_logs');
917 $logfile = ((x($_POST,'logfile')) ? notags(trim($_POST['logfile'])) : '');
918 $debugging = ((x($_POST,'debugging')) ? true : false);
919 $loglevel = ((x($_POST,'loglevel')) ? intval(trim($_POST['loglevel'])) : 0);
921 set_config('system','logfile', $logfile);
922 set_config('system','debugging', $debugging);
923 set_config('system','loglevel', $loglevel);
928 info( t("Log settings updated.") );
929 goaway($a->get_baseurl(true) . '/admin/logs' );
930 return; // NOTREACHED
937 function admin_page_logs(&$a){
939 $log_choices = Array(
940 LOGGER_NORMAL => 'Normal',
941 LOGGER_TRACE => 'Trace',
942 LOGGER_DEBUG => 'Debug',
943 LOGGER_DATA => 'Data',
947 $t = get_markup_template("admin_logs.tpl");
949 $f = get_config('system','logfile');
953 if(!file_exists($f)) {
954 $data = t("Error trying to open <strong>$f</strong> log file.\r\n<br/>Check to see if file $f exist and is
958 $fp = fopen($f, 'r');
960 $data = t("Couldn't open <strong>$f</strong> log file.\r\n<br/>Check to see if file $f is readable.");
964 $size = $fstat['size'];
967 if($size > 5000000 || $size < 0)
969 $seek = fseek($fp,0-$size,SEEK_END);
971 fgets($fp); // throw away the first partial line
972 $data = escape_tags(fread($fp,$size));
974 $data .= escape_tags(fread($fp,4096));
981 return replace_macros($t, array(
982 '$title' => t('Administration'),
983 '$page' => t('Logs'),
984 '$submit' => t('Submit'),
985 '$clear' => t('Clear'),
987 '$baseurl' => $a->get_baseurl(true),
988 '$logname' => get_config('system','logfile'),
990 // name, label, value, help string, extra data...
991 '$debugging' => array('debugging', t("Debugging"),get_config('system','debugging'), ""),
992 '$logfile' => array('logfile', t("Log file"), get_config('system','logfile'), t("Must be writable by web server. Relative to your Friendica top-level directory.")),
993 '$loglevel' => array('loglevel', t("Log level"), get_config('system','loglevel'), "", $log_choices),
995 '$form_security_token' => get_form_security_token("admin_logs"),
1002 function admin_page_remoteupdate_post(&$a) {
1003 // this function should be called via ajax post
1004 if(!is_site_admin()) {
1009 if (x($_POST,'remotefile') && $_POST['remotefile']!=""){
1010 $remotefile = $_POST['remotefile'];
1011 $ftpdata = (x($_POST['ftphost'])?$_POST:false);
1012 doUpdate($remotefile, $ftpdata);
1014 echo "No remote file to download. Abort!";
1024 function admin_page_remoteupdate(&$a) {
1025 if(!is_site_admin()) {
1026 return login(false);
1029 $canwrite = canWeWrite();
1030 $canftp = function_exists('ftp_connect');
1035 $needupdate = false;
1036 $u = array('','','');
1039 $tpl = get_markup_template("admin_remoteupdate.tpl");
1040 return replace_macros($tpl, array(
1041 '$baseurl' => $a->get_baseurl(true),
1042 '$submit' => t("Update now"),
1043 '$close' => t("Close"),
1044 '$localversion' => FRIENDICA_VERSION,
1045 '$remoteversion' => $u[1],
1046 '$needupdate' => $needupdate,
1047 '$canwrite' => $canwrite,
1048 '$canftp' => $canftp,
1049 '$ftphost' => array('ftphost', t("FTP Host"), '',''),
1050 '$ftppath' => array('ftppath', t("FTP Path"), '/',''),
1051 '$ftpuser' => array('ftpuser', t("FTP User"), '',''),
1052 '$ftppwd' => array('ftppwd', t("FTP Password"), '',''),
1053 '$remotefile'=>array('remotefile','', $u['2'],'')