6 require_once("include/remoteupdate.php");
8 function admin_post(&$a){
11 if(!is_site_admin()) {
15 // do not allow a page manager to access the admin panel at all.
17 if(x($_SESSION,'submanage') && intval($_SESSION['submanage']))
26 admin_page_site_post($a);
29 admin_page_users_post($a);
33 is_file("addon/".$a->argv[2]."/".$a->argv[2].".php")){
34 @include_once("addon/".$a->argv[2]."/".$a->argv[2].".php");
35 if(function_exists($a->argv[2].'_plugin_admin_post')) {
36 $func = $a->argv[2].'_plugin_admin_post';
40 goaway($a->get_baseurl(true) . '/admin/plugins/' . $a->argv[2] );
45 if (is_file("view/theme/$theme/config.php")){
46 require_once("view/theme/$theme/config.php");
47 if (function_exists("theme_admin_post")){
51 info(t('Theme settings updated.'));
54 goaway($a->get_baseurl(true) . '/admin/themes/' . $theme );
58 admin_page_logs_post($a);
61 admin_page_remoteupdate_post($a);
66 goaway($a->get_baseurl(true) . '/admin' );
70 function admin_content(&$a) {
72 if(!is_site_admin()) {
76 if(x($_SESSION,'submanage') && intval($_SESSION['submanage']))
83 // array( url, name, extra css classes )
85 'site' => Array($a->get_baseurl(true)."/admin/site/", t("Site") , "site"),
86 'users' => Array($a->get_baseurl(true)."/admin/users/", t("Users") , "users"),
87 'plugins'=> Array($a->get_baseurl(true)."/admin/plugins/", t("Plugins") , "plugins"),
88 'themes' => Array($a->get_baseurl(true)."/admin/themes/", t("Themes") , "themes"),
89 'update' => Array($a->get_baseurl(true)."/admin/update/", t("Update") , "update")
92 /* get plugins admin page */
94 $r = q("SELECT * FROM `addon` WHERE `plugin_admin`=1");
95 $aside['plugins_admin']=Array();
98 $aside['plugins_admin'][] = Array($a->get_baseurl(true)."/admin/plugins/".$plugin, $plugin, "plugin");
99 // temp plugins with admin
100 $a->plugins_admin[] = $plugin;
103 $aside['logs'] = Array($a->get_baseurl(true)."/admin/logs/", t("Logs"), "logs");
105 $t = get_markup_template("admin_aside.tpl");
106 $a->page['aside'] = replace_macros( $t, array(
108 '$h_pending' => t('User registrations waiting for confirmation'),
109 '$admurl'=> $a->get_baseurl(true)."/admin/"
121 switch ($a->argv[1]){
123 $o = admin_page_site($a);
126 $o = admin_page_users($a);
129 $o = admin_page_plugins($a);
132 $o = admin_page_themes($a);
135 $o = admin_page_logs($a);
138 $o = admin_page_remoteupdate($a);
141 notice( t("Item not found.") );
144 $o = admin_page_summary($a);
159 function admin_page_summary(&$a) {
160 $r = q("SELECT `page-flags`, COUNT(uid) as `count` FROM `user` GROUP BY `page-flags`");
162 Array( t('Normal Account'), 0),
163 Array( t('Soapbox Account'), 0),
164 Array( t('Community/Celebrity Account'), 0),
165 Array( t('Automatic Friend Account'), 0)
168 foreach ($r as $u){ $accounts[$u['page-flags']][1] = $u['count']; $users+= $u['count']; }
170 logger('accounts: ' . print_r($accounts,true));
172 $r = q("SELECT COUNT(id) as `count` FROM `register`");
173 $pending = $r[0]['count'];
175 $t = get_markup_template("admin_summary.tpl");
176 return replace_macros($t, array(
177 '$title' => t('Administration'),
178 '$page' => t('Summary'),
179 '$users' => Array( t('Registered users'), $users),
180 '$accounts' => $accounts,
181 '$pending' => Array( t('Pending registrations'), $pending),
182 '$version' => Array( t('Version'), FRIENDICA_VERSION),
183 '$build' => get_config('system','build'),
184 '$plugins' => Array( t('Active plugins'), $a->plugins )
192 function admin_page_site_post(&$a){
193 if (!x($_POST,"page_site")){
197 $sitename = ((x($_POST,'sitename')) ? notags(trim($_POST['sitename'])) : '');
198 $banner = ((x($_POST,'banner')) ? trim($_POST['banner']) : false);
199 $language = ((x($_POST,'language')) ? notags(trim($_POST['language'])) : '');
200 $theme = ((x($_POST,'theme')) ? notags(trim($_POST['theme'])) : '');
201 $maximagesize = ((x($_POST,'maximagesize')) ? intval(trim($_POST['maximagesize'])) : 0);
204 $register_policy = ((x($_POST,'register_policy')) ? intval(trim($_POST['register_policy'])) : 0);
205 $abandon_days = ((x($_POST,'abandon_days')) ? intval(trim($_POST['abandon_days'])) : 0);
207 $register_text = ((x($_POST,'register_text')) ? notags(trim($_POST['register_text'])) : '');
209 $allowed_sites = ((x($_POST,'allowed_sites')) ? notags(trim($_POST['allowed_sites'])) : '');
210 $allowed_email = ((x($_POST,'allowed_email')) ? notags(trim($_POST['allowed_email'])) : '');
211 $block_public = ((x($_POST,'block_public')) ? True : False);
212 $force_publish = ((x($_POST,'publish_all')) ? True : False);
213 $global_directory = ((x($_POST,'directory_submit_url')) ? notags(trim($_POST['directory_submit_url'])) : '');
214 $no_multi_reg = ((x($_POST,'no_multi_reg')) ? True : False);
215 $no_openid = !((x($_POST,'no_openid')) ? True : False);
216 $no_regfullname = !((x($_POST,'no_regfullname')) ? True : False);
217 $no_utf = !((x($_POST,'no_utf')) ? True : False);
218 $no_community_page = !((x($_POST,'no_community_page')) ? True : False);
220 $verifyssl = ((x($_POST,'verifyssl')) ? True : False);
221 $proxyuser = ((x($_POST,'proxyuser')) ? notags(trim($_POST['proxyuser'])) : '');
222 $proxy = ((x($_POST,'proxy')) ? notags(trim($_POST['proxy'])) : '');
223 $timeout = ((x($_POST,'timeout')) ? intval(trim($_POST['timeout'])) : 60);
224 $dfrn_only = ((x($_POST,'dfrn_only')) ? True : False);
225 $ostatus_disabled = !((x($_POST,'ostatus_disabled')) ? True : False);
226 $diaspora_enabled = ((x($_POST,'diaspora_enabled')) ? True : False);
227 $ssl_policy = ((x($_POST,'ssl_policy')) ? intval($_POST['ssl_policy']) : 0);
229 if($ssl_policy != intval(get_config('system','ssl_policy'))) {
230 if($ssl_policy == SSL_POLICY_FULL) {
231 q("update `contact` set
232 `url` = replace(`url` , 'http:' , 'https:'),
233 `photo` = replace(`photo` , 'http:' , 'https:'),
234 `thumb` = replace(`thumb` , 'http:' , 'https:'),
235 `micro` = replace(`micro` , 'http:' , 'https:'),
236 `request` = replace(`request`, 'http:' , 'https:'),
237 `notify` = replace(`notify` , 'http:' , 'https:'),
238 `poll` = replace(`poll` , 'http:' , 'https:'),
239 `confirm` = replace(`confirm`, 'http:' , 'https:'),
240 `poco` = replace(`poco` , 'http:' , 'https:')
243 q("update `profile` set
244 `photo` = replace(`photo` , 'http:' , 'https:'),
245 `thumb` = replace(`thumb` , 'http:' , 'https:')
249 elseif($ssl_policy == SSL_POLICY_SELFSIGN) {
250 q("update `contact` set
251 `url` = replace(`url` , 'https:' , 'http:'),
252 `photo` = replace(`photo` , 'https:' , 'http:'),
253 `thumb` = replace(`thumb` , 'https:' , 'http:'),
254 `micro` = replace(`micro` , 'https:' , 'http:'),
255 `request` = replace(`request`, 'https:' , 'http:'),
256 `notify` = replace(`notify` , 'https:' , 'http:'),
257 `poll` = replace(`poll` , 'https:' , 'http:'),
258 `confirm` = replace(`confirm`, 'https:' , 'http:'),
259 `poco` = replace(`poco` , 'https:' , 'http:')
262 q("update `profile` set
263 `photo` = replace(`photo` , 'https:' , 'http:'),
264 `thumb` = replace(`thumb` , 'https:' , 'http:')
269 set_config('system','ssl_policy',$ssl_policy);
271 set_config('config','sitename',$sitename);
273 // don't know why, but del_config doesn't work...
274 q("DELETE FROM `config` WHERE `cat` = '%s' AND `k` = '%s' LIMIT 1",
279 set_config('system','banner', $banner);
281 set_config('system','language', $language);
282 set_config('system','theme', $theme);
283 set_config('system','maximagesize', $maximagesize);
285 set_config('config','register_policy', $register_policy);
286 set_config('system','account_abandon_days', $abandon_days);
287 set_config('config','register_text', $register_text);
288 set_config('system','allowed_sites', $allowed_sites);
289 set_config('system','allowed_email', $allowed_email);
290 set_config('system','block_public', $block_public);
291 set_config('system','publish_all', $force_publish);
292 if ($global_directory==""){
293 // don't know why, but del_config doesn't work...
294 q("DELETE FROM `config` WHERE `cat` = '%s' AND `k` = '%s' LIMIT 1",
296 dbesc("directory_submit_url")
299 set_config('system','directory_submit_url', $global_directory);
301 set_config('system','directory_search_url', $global_search_url);
302 set_config('system','block_extended_register', $no_multi_reg);
303 set_config('system','no_openid', $no_openid);
304 set_config('system','no_regfullname', $no_regfullname);
305 set_config('system','no_community_page', $no_community_page);
306 set_config('system','no_utf', $no_utf);
307 set_config('system','verifyssl', $verifyssl);
308 set_config('system','proxyuser', $proxyuser);
309 set_config('system','proxy', $proxy);
310 set_config('system','curl_timeout', $timeout);
311 set_config('system','dfrn_only', $dfrn_only);
312 set_config('system','ostatus_disabled', $ostatus_disabled);
313 set_config('system','diaspora_enabled', $diaspora_enabled);
315 info( t('Site settings updated.') . EOL);
316 goaway($a->get_baseurl(true) . '/admin/site' );
317 return; // NOTREACHED
321 function admin_page_site(&$a) {
323 /* Installed langs */
324 $lang_choices = array();
325 $langs = glob('view/*/strings.php');
327 if(is_array($langs) && count($langs)) {
328 if(! in_array('view/en/strings.php',$langs))
329 $langs[] = 'view/en/';
331 foreach($langs as $l) {
332 $t = explode("/",$l);
333 $lang_choices[$t[1]] = $t[1];
337 /* Installed themes */
338 $theme_choices = array();
339 $files = glob('view/theme/*');
341 foreach($files as $file) {
342 $f = basename($file);
343 $theme_name = ((file_exists($file . '/experimental')) ? sprintf("%s - \x28Experimental\x29", $f) : $f);
344 $theme_choices[$f] = $theme_name;
350 $banner = get_config('system','banner');
352 $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>';
353 $banner = htmlspecialchars($banner);
355 //echo "<pre>"; var_dump($lang_choices); die("</pre>");
357 /* Register policy */
358 $register_choices = Array(
359 REGISTER_CLOSED => t("Closed"),
360 REGISTER_APPROVE => t("Requires approval"),
361 REGISTER_OPEN => t("Open")
364 $ssl_choices = array(
365 SSL_POLICY_NONE => t("No SSL policy, links will track page SSL state"),
366 SSL_POLICY_FULL => t("Force all links to use SSL"),
367 SSL_POLICY_SELFSIGN => t("Self-signed certificate, use SSL for local links only (discouraged)")
370 $t = get_markup_template("admin_site.tpl");
371 return replace_macros($t, array(
372 '$title' => t('Administration'),
373 '$page' => t('Site'),
374 '$submit' => t('Submit'),
375 '$registration' => t('Registration'),
376 '$upload' => t('File upload'),
377 '$corporate' => t('Policies'),
378 '$advanced' => t('Advanced'),
380 '$baseurl' => $a->get_baseurl(true),
381 // name, label, value, help string, extra data...
382 '$sitename' => array('sitename', t("Site name"), htmlentities($a->config['sitename'], ENT_QUOTES), ""),
383 '$banner' => array('banner', t("Banner/Logo"), $banner, ""),
384 '$language' => array('language', t("System language"), get_config('system','language'), "", $lang_choices),
385 '$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),
386 '$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),
387 '$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.")),
389 '$register_policy' => array('register_policy', t("Register policy"), $a->config['register_policy'], "", $register_choices),
390 '$register_text' => array('register_text', t("Register text"), htmlentities($a->config['register_text'], ENT_QUOTES), t("Will be displayed prominently on the registration page.")),
391 '$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.')),
392 '$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")),
393 '$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")),
394 '$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.")),
395 '$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.")),
396 '$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.")),
398 '$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.")),
399 '$no_openid' => array('no_openid', t("OpenID support"), !get_config('system','no_openid'), t("OpenID support for registration and logins.")),
400 '$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")),
401 '$no_utf' => array('no_utf', t("UTF-8 Regular expressions"), !get_config('system','no_utf'), t("Use PHP UTF8 regular expressions")),
402 '$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.")),
403 '$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.")),
404 '$diaspora_enabled' => array('diaspora_enabled', t("Enable Diaspora support"), get_config('system','diaspora_enabled'), t("Provide built-in Diaspora network compatibility.")),
405 '$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.")),
406 '$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.")),
407 '$proxyuser' => array('proxyuser', t("Proxy user"), get_config('system','proxyuser'), ""),
408 '$proxy' => array('proxy', t("Proxy URL"), get_config('system','proxy'), ""),
409 '$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).")),
420 function admin_page_users_post(&$a){
421 $pending = ( x($_POST, 'pending') ? $_POST['pending'] : Array() );
422 $users = ( x($_POST, 'user') ? $_POST['user'] : Array() );
424 if (x($_POST,'page_users_block')){
425 foreach($users as $uid){
426 q("UPDATE `user` SET `blocked`=1-`blocked` WHERE `uid`=%s",
430 notice( sprintf( tt("%s user blocked/unblocked", "%s users blocked/unblocked", count($users)), count($users)) );
432 if (x($_POST,'page_users_delete')){
433 require_once("include/Contact.php");
434 foreach($users as $uid){
437 notice( sprintf( tt("%s user deleted", "%s users deleted", count($users)), count($users)) );
440 if (x($_POST,'page_users_approve')){
441 require_once("mod/regmod.php");
442 foreach($pending as $hash){
446 if (x($_POST,'page_users_deny')){
447 require_once("mod/regmod.php");
448 foreach($pending as $hash){
452 goaway($a->get_baseurl(true) . '/admin/users' );
453 return; // NOTREACHED
456 function admin_page_users(&$a){
459 $user = q("SELECT * FROM `user` WHERE `uid`=%d", intval($uid));
460 if (count($user)==0){
461 notice( 'User not found' . EOL);
462 goaway($a->get_baseurl(true) . '/admin/users' );
463 return; // NOTREACHED
468 require_once("include/Contact.php");
471 notice( sprintf(t("User '%s' deleted"), $user[0]['username']) . EOL);
474 q("UPDATE `user` SET `blocked`=%d WHERE `uid`=%s",
475 intval( 1-$user[0]['blocked'] ),
478 notice( sprintf( ($user[0]['blocked']?t("User '%s' unblocked"):t("User '%s' blocked")) , $user[0]['username']) . EOL);
481 goaway($a->get_baseurl(true) . '/admin/users' );
482 return; // NOTREACHED
487 $pending = q("SELECT `register`.*, `contact`.`name`, `user`.`email`
489 LEFT JOIN `contact` ON `register`.`uid` = `contact`.`uid`
490 LEFT JOIN `user` ON `register`.`uid` = `user`.`uid`;");
495 $total = q("SELECT count(*) as total FROM `user` where 1");
497 $a->set_pager_total($total[0]['total']);
498 $a->set_pager_itemspage(100);
502 $users = q("SELECT `user` . * , `contact`.`name` , `contact`.`url` , `contact`.`micro`, `lastitem`.`lastitem_date`
504 (SELECT MAX(`item`.`changed`) as `lastitem_date`, `item`.`uid`
506 WHERE `item`.`type` = 'wall'
507 GROUP BY `item`.`uid`) AS `lastitem`
508 RIGHT OUTER JOIN `user` ON `user`.`uid` = `lastitem`.`uid`,
511 `user`.`uid` = `contact`.`uid`
512 AND `user`.`verified` =1
513 AND `contact`.`self` =1
514 ORDER BY `contact`.`name` LIMIT %d, %d
516 intval($a->pager['start']),
517 intval($a->pager['itemspage'])
520 function _setup_users($e){
523 t('Soapbox Account'),
524 t('Community/Celebrity Account'),
525 t('Automatic Friend Account')
527 $e['page-flags'] = $accounts[$e['page-flags']];
528 $e['register_date'] = relative_date($e['register_date']);
529 $e['login_date'] = relative_date($e['login_date']);
530 $e['lastitem_date'] = relative_date($e['lastitem_date']);
533 $users = array_map("_setup_users", $users);
536 $t = get_markup_template("admin_users.tpl");
537 $o = replace_macros($t, array(
539 '$title' => t('Administration'),
540 '$page' => t('Users'),
541 '$submit' => t('Submit'),
542 '$select_all' => t('select all'),
543 '$h_pending' => t('User registrations waiting for confirm'),
544 '$th_pending' => array( t('Request date'), t('Name'), t('Email') ),
545 '$no_pending' => t('No registrations.'),
546 '$approve' => t('Approve'),
547 '$deny' => t('Deny'),
548 '$delete' => t('Delete'),
549 '$block' => t('Block'),
550 '$unblock' => t('Unblock'),
552 '$h_users' => t('Users'),
553 '$th_users' => array( t('Name'), t('Email'), t('Register date'), t('Last login'), t('Last item'), t('Account') ),
555 '$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?'),
556 '$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?'),
560 '$baseurl' => $a->get_baseurl(true),
562 '$pending' => $pending,
574 function admin_page_plugins(&$a){
580 $plugin = $a->argv[2];
581 if (!is_file("addon/$plugin/$plugin.php")){
582 notice( t("Item not found.") );
586 if (x($_GET,"a") && $_GET['a']=="t"){
587 // Toggle plugin status
588 $idx = array_search($plugin, $a->plugins);
590 unset($a->plugins[$idx]);
591 uninstall_plugin($plugin);
592 info( sprintf( t("Plugin %s disabled."), $plugin ) );
594 $a->plugins[] = $plugin;
595 install_plugin($plugin);
596 info( sprintf( t("Plugin %s enabled."), $plugin ) );
598 set_config("system","addon", implode(", ",$a->plugins));
599 goaway($a->get_baseurl(true) . '/admin/plugins' );
600 return; // NOTREACHED
602 // display plugin details
603 require_once('library/markdown.php');
605 if (in_array($plugin, $a->plugins)){
606 $status="on"; $action= t("Disable");
608 $status="off"; $action= t("Enable");
612 if (is_file("addon/$plugin/README.md")){
613 $readme = file_get_contents("addon/$plugin/README.md");
614 $readme = Markdown($readme);
615 } else if (is_file("addon/$plugin/README")){
616 $readme = "<pre>". file_get_contents("addon/$plugin/README") ."</pre>";
620 if (is_array($a->plugins_admin) && in_array($plugin, $a->plugins_admin)){
621 @require_once("addon/$plugin/$plugin.php");
622 $func = $plugin.'_plugin_admin';
623 $func($a, $admin_form);
626 $t = get_markup_template("admin_plugins_details.tpl");
627 return replace_macros($t, array(
628 '$title' => t('Administration'),
629 '$page' => t('Plugins'),
630 '$toggle' => t('Toggle'),
631 '$settings' => t('Settings'),
632 '$baseurl' => $a->get_baseurl(true),
634 '$plugin' => $plugin,
635 '$status' => $status,
636 '$action' => $action,
637 '$info' => get_plugin_info($plugin),
638 '$str_author' => t('Author: '),
639 '$str_maintainer' => t('Maintainer: '),
641 '$admin_form' => $admin_form,
642 '$function' => 'plugins',
655 $files = glob("addon/*/");
657 foreach($files as $file) {
659 list($tmp, $id)=array_map("trim", explode("/",$file));
660 $info = get_plugin_info($id);
661 $plugins[] = array( $id, (in_array($id, $a->plugins)?"on":"off") , $info);
666 $t = get_markup_template("admin_plugins.tpl");
667 return replace_macros($t, array(
668 '$title' => t('Administration'),
669 '$page' => t('Plugins'),
670 '$submit' => t('Submit'),
671 '$baseurl' => $a->get_baseurl(true),
672 '$function' => 'plugins',
673 '$plugins' => $plugins
677 function toggle_theme(&$themes,$th,&$result) {
678 for($x = 0; $x < count($themes); $x ++) {
679 if($themes[$x]['name'] === $th) {
680 if($themes[$x]['allowed']) {
681 $themes[$x]['allowed'] = 0;
685 $themes[$x]['allowed'] = 1;
692 function theme_status($themes,$th) {
693 for($x = 0; $x < count($themes); $x ++) {
694 if($themes[$x]['name'] === $th) {
695 if($themes[$x]['allowed']) {
708 function rebuild_theme_table($themes) {
711 foreach($themes as $th) {
727 function admin_page_themes(&$a){
729 $allowed_themes_str = get_config('system','allowed_themes');
730 $allowed_themes_raw = explode(',',$allowed_themes_str);
731 $allowed_themes = array();
732 if(count($allowed_themes_raw))
733 foreach($allowed_themes_raw as $x)
735 $allowed_themes[] = trim($x);
738 $files = glob('view/theme/*');
740 foreach($files as $file) {
741 $f = basename($file);
742 $is_experimental = intval(file_exists($file . '/experimental'));
743 $is_unsupported = 1-(intval(file_exists($file . '/unsupported')));
744 $is_allowed = intval(in_array($f,$allowed_themes));
745 $themes[] = array('name' => $f, 'experimental' => $is_experimental, 'supported' => $is_supported, 'allowed' => $is_allowed);
749 if(! count($themes)) {
750 notice( t('No themes found.'));
759 $theme = $a->argv[2];
760 if(! is_dir("view/theme/$theme")){
761 notice( t("Item not found.") );
765 if (x($_GET,"a") && $_GET['a']=="t"){
767 // Toggle theme status
769 toggle_theme($themes,$theme,$result);
770 $s = rebuild_theme_table($themes);
772 info( sprintf('Theme %s enabled.',$theme));
774 info( sprintf('Theme %s disabled.',$theme));
776 set_config('system','allowed_themes',$s);
777 goaway($a->get_baseurl(true) . '/admin/themes' );
778 return; // NOTREACHED
781 // display theme details
782 require_once('library/markdown.php');
784 if (theme_status($themes,$theme)) {
785 $status="on"; $action= t("Disable");
787 $status="off"; $action= t("Enable");
791 if (is_file("view/theme/$theme/README.md")){
792 $readme = file_get_contents("view/theme/$theme/README.md");
793 $readme = Markdown($readme);
794 } else if (is_file("view/theme/$theme/README")){
795 $readme = "<pre>". file_get_contents("view/theme/$theme/README") ."</pre>";
799 if (is_file("view/theme/$theme/config.php")){
800 require_once("view/theme/$theme/config.php");
801 if(function_exists("theme_admin")){
802 $admin_form = theme_admin($a);
808 $screenshot = array( get_theme_screenshot($theme), t('Screenshot'));
809 if(! stristr($screenshot[0],$theme))
812 $t = get_markup_template("admin_plugins_details.tpl");
813 return replace_macros($t, array(
814 '$title' => t('Administration'),
815 '$page' => t('Themes'),
816 '$toggle' => t('Toggle'),
817 '$settings' => t('Settings'),
818 '$baseurl' => $a->get_baseurl(true),
821 '$status' => $status,
822 '$action' => $action,
823 '$info' => get_theme_info($theme),
824 '$function' => 'themes',
825 '$admin_form' => $admin_form,
826 '$str_author' => t('Author: '),
827 '$str_maintainer' => t('Maintainer: '),
828 '$screenshot' => $screenshot,
841 foreach($themes as $th) {
842 $xthemes[] = array($th['name'],(($th['allowed']) ? "on" : "off"), get_theme_info($th['name']));
846 $t = get_markup_template("admin_plugins.tpl");
847 return replace_macros($t, array(
848 '$title' => t('Administration'),
849 '$page' => t('Themes'),
850 '$submit' => t('Submit'),
851 '$baseurl' => $a->get_baseurl(true),
852 '$function' => 'themes',
853 '$plugins' => $xthemes,
854 '$experimental' => t('[Experimental]'),
855 '$unsupported' => t('[Unsupported]')
864 function admin_page_logs_post(&$a) {
865 if (x($_POST,"page_logs")) {
867 $logfile = ((x($_POST,'logfile')) ? notags(trim($_POST['logfile'])) : '');
868 $debugging = ((x($_POST,'debugging')) ? true : false);
869 $loglevel = ((x($_POST,'loglevel')) ? intval(trim($_POST['loglevel'])) : 0);
871 set_config('system','logfile', $logfile);
872 set_config('system','debugging', $debugging);
873 set_config('system','loglevel', $loglevel);
878 info( t("Log settings updated.") );
879 goaway($a->get_baseurl(true) . '/admin/logs' );
880 return; // NOTREACHED
883 function admin_page_logs(&$a){
885 $log_choices = Array(
886 LOGGER_NORMAL => 'Normal',
887 LOGGER_TRACE => 'Trace',
888 LOGGER_DEBUG => 'Debug',
889 LOGGER_DATA => 'Data',
893 $t = get_markup_template("admin_logs.tpl");
895 $f = get_config('system','logfile');
899 if(!file_exists($f)) {
900 $data = t("Error trying to open <strong>$f</strong> log file.\r\n<br/>Check to see if file $f exist and is
904 $fp = fopen($f, 'r');
906 $data = t("Couldn't open <strong>$f</strong> log file.\r\n<br/>Check to see if file $f is readable.");
910 $size = $fstat['size'];
913 if($size > 5000000 || $size < 0)
915 $seek = fseek($fp,0-$size,SEEK_END);
917 fgets($fp); // throw away the first partial line
918 $data = escape_tags(fread($fp,$size));
920 $data .= escape_tags(fread($fp,4096));
927 return replace_macros($t, array(
928 '$title' => t('Administration'),
929 '$page' => t('Logs'),
930 '$submit' => t('Submit'),
931 '$clear' => t('Clear'),
933 '$baseurl' => $a->get_baseurl(true),
934 '$logname' => get_config('system','logfile'),
936 // name, label, value, help string, extra data...
937 '$debugging' => array('debugging', t("Debugging"),get_config('system','debugging'), ""),
938 '$logfile' => array('logfile', t("Log file"), get_config('system','logfile'), t("Must be writable by web server. Relative to your Friendica top-level directory.")),
939 '$loglevel' => array('loglevel', t("Log level"), get_config('system','loglevel'), "", $log_choices),
943 function admin_page_remoteupdate_post(&$a) {
944 // this function should be called via ajax post
945 if(!is_site_admin()) {
950 if (x($_POST,'remotefile') && $_POST['remotefile']!=""){
951 $remotefile = $_POST['remotefile'];
952 $ftpdata = (x($_POST['ftphost'])?$_POST:false);
953 doUpdate($remotefile, $ftpdata);
955 echo "No remote file to download. Abort!";
961 function admin_page_remoteupdate(&$a) {
962 if(!is_site_admin()) {
966 $canwrite = canWeWrite();
967 $canftp = function_exists('ftp_connect');
973 $u = array('','','');
976 $tpl = get_markup_template("admin_remoteupdate.tpl");
977 return replace_macros($tpl, array(
978 '$baseurl' => $a->get_baseurl(true),
979 '$submit' => t("Update now"),
980 '$close' => t("Close"),
981 '$localversion' => FRIENDICA_VERSION,
982 '$remoteversion' => $u[1],
983 '$needupdate' => $needupdate,
984 '$canwrite' => $canwrite,
985 '$canftp' => $canftp,
986 '$ftphost' => array('ftphost', t("FTP Host"), '',''),
987 '$ftppath' => array('ftppath', t("FTP Path"), '/',''),
988 '$ftpuser' => array('ftpuser', t("FTP User"), '',''),
989 '$ftppwd' => array('ftppwd', t("FTP Password"), '',''),
990 '$remotefile'=>array('remotefile','', $u['2'],'')