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] );
44 admin_page_logs_post($a);
47 admin_page_remoteupdate_post($a);
52 goaway($a->get_baseurl(true) . '/admin' );
56 function admin_content(&$a) {
58 if(!is_site_admin()) {
62 if(x($_SESSION,'submanage') && intval($_SESSION['submanage']))
69 // array( url, name, extra css classes )
71 'site' => Array($a->get_baseurl(true)."/admin/site/", t("Site") , "site"),
72 'users' => Array($a->get_baseurl(true)."/admin/users/", t("Users") , "users"),
73 'plugins'=> Array($a->get_baseurl(true)."/admin/plugins/", t("Plugins") , "plugins"),
74 'themes' => Array($a->get_baseurl(true)."/admin/themes/", t("Themes") , "themes"),
75 'update' => Array($a->get_baseurl(true)."/admin/update/", t("Update") , "update")
78 /* get plugins admin page */
80 $r = q("SELECT * FROM `addon` WHERE `plugin_admin`=1");
81 $aside['plugins_admin']=Array();
84 $aside['plugins_admin'][] = Array($a->get_baseurl(true)."/admin/plugins/".$plugin, $plugin, "plugin");
85 // temp plugins with admin
86 $a->plugins_admin[] = $plugin;
89 $aside['logs'] = Array($a->get_baseurl(true)."/admin/logs/", t("Logs"), "logs");
91 $t = get_markup_template("admin_aside.tpl");
92 $a->page['aside'] = replace_macros( $t, array(
94 '$h_pending' => t('User registrations waiting for confirmation'),
95 '$admurl'=> $a->get_baseurl(true)."/admin/"
107 switch ($a->argv[1]){
109 $o = admin_page_site($a);
112 $o = admin_page_users($a);
115 $o = admin_page_plugins($a);
118 $o = admin_page_themes($a);
121 $o = admin_page_logs($a);
124 $o = admin_page_remoteupdate($a);
127 notice( t("Item not found.") );
130 $o = admin_page_summary($a);
139 function admin_page_summary(&$a) {
140 $r = q("SELECT `page-flags`, COUNT(uid) as `count` FROM `user` GROUP BY `page-flags`");
142 Array( t('Normal Account'), 0),
143 Array( t('Soapbox Account'), 0),
144 Array( t('Community/Celebrity Account'), 0),
145 Array( t('Automatic Friend Account'), 0)
148 foreach ($r as $u){ $accounts[$u['page-flags']][1] = $u['count']; $users+= $u['count']; }
150 logger('accounts: ' . print_r($accounts,true));
152 $r = q("SELECT COUNT(id) as `count` FROM `register`");
153 $pending = $r[0]['count'];
155 $t = get_markup_template("admin_summary.tpl");
156 return replace_macros($t, array(
157 '$title' => t('Administration'),
158 '$page' => t('Summary'),
159 '$users' => Array( t('Registered users'), $users),
160 '$accounts' => $accounts,
161 '$pending' => Array( t('Pending registrations'), $pending),
162 '$version' => Array( t('Version'), FRIENDICA_VERSION),
163 '$build' => get_config('system','build'),
164 '$plugins' => Array( t('Active plugins'), $a->plugins )
172 function admin_page_site_post(&$a){
173 if (!x($_POST,"page_site")){
177 $sitename = ((x($_POST,'sitename')) ? notags(trim($_POST['sitename'])) : '');
178 $banner = ((x($_POST,'banner')) ? trim($_POST['banner']) : false);
179 $language = ((x($_POST,'language')) ? notags(trim($_POST['language'])) : '');
180 $theme = ((x($_POST,'theme')) ? notags(trim($_POST['theme'])) : '');
181 $maximagesize = ((x($_POST,'maximagesize')) ? intval(trim($_POST['maximagesize'])) : 0);
184 $register_policy = ((x($_POST,'register_policy')) ? intval(trim($_POST['register_policy'])) : 0);
185 $abandon_days = ((x($_POST,'abandon_days')) ? intval(trim($_POST['abandon_days'])) : 0);
187 $register_text = ((x($_POST,'register_text')) ? notags(trim($_POST['register_text'])) : '');
189 $allowed_sites = ((x($_POST,'allowed_sites')) ? notags(trim($_POST['allowed_sites'])) : '');
190 $allowed_email = ((x($_POST,'allowed_email')) ? notags(trim($_POST['allowed_email'])) : '');
191 $block_public = ((x($_POST,'block_public')) ? True : False);
192 $force_publish = ((x($_POST,'publish_all')) ? True : False);
193 $global_directory = ((x($_POST,'directory_submit_url')) ? notags(trim($_POST['directory_submit_url'])) : '');
194 $no_multi_reg = ((x($_POST,'no_multi_reg')) ? True : False);
195 $no_openid = !((x($_POST,'no_openid')) ? True : False);
196 $no_regfullname = !((x($_POST,'no_regfullname')) ? True : False);
197 $no_utf = !((x($_POST,'no_utf')) ? True : False);
198 $no_community_page = !((x($_POST,'no_community_page')) ? True : False);
200 $verifyssl = ((x($_POST,'verifyssl')) ? True : False);
201 $proxyuser = ((x($_POST,'proxyuser')) ? notags(trim($_POST['proxyuser'])) : '');
202 $proxy = ((x($_POST,'proxy')) ? notags(trim($_POST['proxy'])) : '');
203 $timeout = ((x($_POST,'timeout')) ? intval(trim($_POST['timeout'])) : 60);
204 $dfrn_only = ((x($_POST,'dfrn_only')) ? True : False);
205 $ostatus_disabled = !((x($_POST,'ostatus_disabled')) ? True : False);
206 $diaspora_enabled = ((x($_POST,'diaspora_enabled')) ? True : False);
207 $ssl_policy = ((x($_POST,'ssl_policy')) ? intval($_POST['ssl_policy']) : 0);
209 if($ssl_policy != intval(get_config('system','ssl_policy'))) {
210 if($ssl_policy == SSL_POLICY_FULL) {
211 q("update `contact` set
212 `url` = replace(`url` , 'http:' , 'https:'),
213 `photo` = replace(`photo` , 'http:' , 'https:'),
214 `thumb` = replace(`thumb` , 'http:' , 'https:'),
215 `micro` = replace(`micro` , 'http:' , 'https:'),
216 `request` = replace(`request`, 'http:' , 'https:'),
217 `notify` = replace(`notify` , 'http:' , 'https:'),
218 `poll` = replace(`poll` , 'http:' , 'https:'),
219 `confirm` = replace(`confirm`, 'http:' , 'https:'),
220 `poco` = replace(`poco` , 'http:' , 'https:')
223 q("update `profile` set
224 `photo` = replace(`photo` , 'http:' , 'https:'),
225 `thumb` = replace(`thumb` , 'http:' , 'https:')
229 elseif($ssl_policy == SSL_POLICY_SELFSIGN) {
230 q("update `contact` set
231 `url` = replace(`url` , 'https:' , 'http:'),
232 `photo` = replace(`photo` , 'https:' , 'http:'),
233 `thumb` = replace(`thumb` , 'https:' , 'http:'),
234 `micro` = replace(`micro` , 'https:' , 'http:'),
235 `request` = replace(`request`, 'https:' , 'http:'),
236 `notify` = replace(`notify` , 'https:' , 'http:'),
237 `poll` = replace(`poll` , 'https:' , 'http:'),
238 `confirm` = replace(`confirm`, 'https:' , 'http:'),
239 `poco` = replace(`poco` , 'https:' , 'http:')
242 q("update `profile` set
243 `photo` = replace(`photo` , 'https:' , 'http:'),
244 `thumb` = replace(`thumb` , 'https:' , 'http:')
249 set_config('system','ssl_policy',$ssl_policy);
251 set_config('config','sitename',$sitename);
253 // don't know why, but del_config doesn't work...
254 q("DELETE FROM `config` WHERE `cat` = '%s' AND `k` = '%s' LIMIT 1",
259 set_config('system','banner', $banner);
261 set_config('system','language', $language);
262 set_config('system','theme', $theme);
263 set_config('system','maximagesize', $maximagesize);
265 set_config('config','register_policy', $register_policy);
266 set_config('system','account_abandon_days', $abandon_days);
267 set_config('config','register_text', $register_text);
268 set_config('system','allowed_sites', $allowed_sites);
269 set_config('system','allowed_email', $allowed_email);
270 set_config('system','block_public', $block_public);
271 set_config('system','publish_all', $force_publish);
272 if ($global_directory==""){
273 // don't know why, but del_config doesn't work...
274 q("DELETE FROM `config` WHERE `cat` = '%s' AND `k` = '%s' LIMIT 1",
276 dbesc("directory_submit_url")
279 set_config('system','directory_submit_url', $global_directory);
281 set_config('system','directory_search_url', $global_search_url);
282 set_config('system','block_extended_register', $no_multi_reg);
283 set_config('system','no_openid', $no_openid);
284 set_config('system','no_regfullname', $no_regfullname);
285 set_config('system','no_community_page', $no_community_page);
286 set_config('system','no_utf', $no_utf);
287 set_config('system','verifyssl', $verifyssl);
288 set_config('system','proxyuser', $proxyuser);
289 set_config('system','proxy', $proxy);
290 set_config('system','curl_timeout', $timeout);
291 set_config('system','dfrn_only', $dfrn_only);
292 set_config('system','ostatus_disabled', $ostatus_disabled);
293 set_config('system','diaspora_enabled', $diaspora_enabled);
295 info( t('Site settings updated.') . EOL);
296 goaway($a->get_baseurl(true) . '/admin/site' );
297 return; // NOTREACHED
301 function admin_page_site(&$a) {
303 /* Installed langs */
304 $lang_choices = array();
305 $langs = glob('view/*/strings.php');
307 if(is_array($langs) && count($langs)) {
308 if(! in_array('view/en/strings.php',$langs))
309 $langs[] = 'view/en/';
311 foreach($langs as $l) {
312 $t = explode("/",$l);
313 $lang_choices[$t[1]] = $t[1];
317 /* Installed themes */
318 $theme_choices = array();
319 $files = glob('view/theme/*');
321 foreach($files as $file) {
322 $f = basename($file);
323 $theme_name = ((file_exists($file . '/experimental')) ? sprintf("%s - \x28Experimental\x29", $f) : $f);
324 $theme_choices[$f] = $theme_name;
330 $banner = get_config('system','banner');
332 $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>';
333 $banner = htmlspecialchars($banner);
335 //echo "<pre>"; var_dump($lang_choices); die("</pre>");
337 /* Register policy */
338 $register_choices = Array(
339 REGISTER_CLOSED => t("Closed"),
340 REGISTER_APPROVE => t("Requires approval"),
341 REGISTER_OPEN => t("Open")
344 $ssl_choices = array(
345 SSL_POLICY_NONE => t("No SSL policy, links will track page SSL state"),
346 SSL_POLICY_FULL => t("Force all links to use SSL"),
347 SSL_POLICY_SELFSIGN => t("Self-signed certificate, use SSL for local links only (discouraged)")
350 $t = get_markup_template("admin_site.tpl");
351 return replace_macros($t, array(
352 '$title' => t('Administration'),
353 '$page' => t('Site'),
354 '$submit' => t('Submit'),
355 '$registration' => t('Registration'),
356 '$upload' => t('File upload'),
357 '$corporate' => t('Policies'),
358 '$advanced' => t('Advanced'),
360 '$baseurl' => $a->get_baseurl(true),
361 // name, label, value, help string, extra data...
362 '$sitename' => array('sitename', t("Site name"), htmlentities($a->config['sitename'], ENT_QUOTES), ""),
363 '$banner' => array('banner', t("Banner/Logo"), $banner, ""),
364 '$language' => array('language', t("System language"), get_config('system','language'), "", $lang_choices),
365 '$theme' => array('theme', t("System theme"), get_config('system','theme'), t("Default system theme - may be over-ridden by user profiles"), $theme_choices),
366 '$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),
367 '$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.")),
369 '$register_policy' => array('register_policy', t("Register policy"), $a->config['register_policy'], "", $register_choices),
370 '$register_text' => array('register_text', t("Register text"), htmlentities($a->config['register_text'], ENT_QUOTES), t("Will be displayed prominently on the registration page.")),
371 '$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.')),
372 '$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")),
373 '$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")),
374 '$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.")),
375 '$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.")),
376 '$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.")),
378 '$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.")),
379 '$no_openid' => array('no_openid', t("OpenID support"), !get_config('system','no_openid'), t("OpenID support for registration and logins.")),
380 '$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")),
381 '$no_utf' => array('no_utf', t("UTF-8 Regular expressions"), !get_config('system','no_utf'), t("Use PHP UTF8 regular expressions")),
382 '$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.")),
383 '$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.")),
384 '$diaspora_enabled' => array('diaspora_enabled', t("Enable Diaspora support"), get_config('system','diaspora_enabled'), t("Provide built-in Diaspora network compatibility.")),
385 '$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.")),
386 '$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.")),
387 '$proxyuser' => array('proxyuser', t("Proxy user"), get_config('system','proxyuser'), ""),
388 '$proxy' => array('proxy', t("Proxy URL"), get_config('system','proxy'), ""),
389 '$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).")),
400 function admin_page_users_post(&$a){
401 $pending = ( x($_POST, 'pending') ? $_POST['pending'] : Array() );
402 $users = ( x($_POST, 'user') ? $_POST['user'] : Array() );
404 if (x($_POST,'page_users_block')){
405 foreach($users as $uid){
406 q("UPDATE `user` SET `blocked`=1-`blocked` WHERE `uid`=%s",
410 notice( sprintf( tt("%s user blocked/unblocked", "%s users blocked/unblocked", count($users)), count($users)) );
412 if (x($_POST,'page_users_delete')){
413 require_once("include/Contact.php");
414 foreach($users as $uid){
417 notice( sprintf( tt("%s user deleted", "%s users deleted", count($users)), count($users)) );
420 if (x($_POST,'page_users_approve')){
421 require_once("mod/regmod.php");
422 foreach($pending as $hash){
426 if (x($_POST,'page_users_deny')){
427 require_once("mod/regmod.php");
428 foreach($pending as $hash){
432 goaway($a->get_baseurl(true) . '/admin/users' );
433 return; // NOTREACHED
436 function admin_page_users(&$a){
439 $user = q("SELECT * FROM `user` WHERE `uid`=%d", intval($uid));
440 if (count($user)==0){
441 notice( 'User not found' . EOL);
442 goaway($a->get_baseurl(true) . '/admin/users' );
443 return; // NOTREACHED
448 require_once("include/Contact.php");
451 notice( sprintf(t("User '%s' deleted"), $user[0]['username']) . EOL);
454 q("UPDATE `user` SET `blocked`=%d WHERE `uid`=%s",
455 intval( 1-$user[0]['blocked'] ),
458 notice( sprintf( ($user[0]['blocked']?t("User '%s' unblocked"):t("User '%s' blocked")) , $user[0]['username']) . EOL);
461 goaway($a->get_baseurl(true) . '/admin/users' );
462 return; // NOTREACHED
467 $pending = q("SELECT `register`.*, `contact`.`name`, `user`.`email`
469 LEFT JOIN `contact` ON `register`.`uid` = `contact`.`uid`
470 LEFT JOIN `user` ON `register`.`uid` = `user`.`uid`;");
475 $total = q("SELECT count(*) as total FROM `user` where 1");
477 $a->set_pager_total($total[0]['total']);
478 $a->set_pager_itemspage(100);
482 $users = q("SELECT `user` . * , `contact`.`name` , `contact`.`url` , `contact`.`micro`, `lastitem`.`lastitem_date`
484 (SELECT MAX(`item`.`changed`) as `lastitem_date`, `item`.`uid`
486 WHERE `item`.`type` = 'wall'
487 GROUP BY `item`.`uid`) AS `lastitem`
488 RIGHT OUTER JOIN `user` ON `user`.`uid` = `lastitem`.`uid`,
491 `user`.`uid` = `contact`.`uid`
492 AND `user`.`verified` =1
493 AND `contact`.`self` =1
494 ORDER BY `contact`.`name` LIMIT %d, %d
496 intval($a->pager['start']),
497 intval($a->pager['itemspage'])
500 function _setup_users($e){
503 t('Soapbox Account'),
504 t('Community/Celebrity Account'),
505 t('Automatic Friend Account')
507 $e['page-flags'] = $accounts[$e['page-flags']];
508 $e['register_date'] = relative_date($e['register_date']);
509 $e['login_date'] = relative_date($e['login_date']);
510 $e['lastitem_date'] = relative_date($e['lastitem_date']);
513 $users = array_map("_setup_users", $users);
516 $t = get_markup_template("admin_users.tpl");
517 $o = replace_macros($t, array(
519 '$title' => t('Administration'),
520 '$page' => t('Users'),
521 '$submit' => t('Submit'),
522 '$select_all' => t('select all'),
523 '$h_pending' => t('User registrations waiting for confirm'),
524 '$th_pending' => array( t('Request date'), t('Name'), t('Email') ),
525 '$no_pending' => t('No registrations.'),
526 '$approve' => t('Approve'),
527 '$deny' => t('Deny'),
528 '$delete' => t('Delete'),
529 '$block' => t('Block'),
530 '$unblock' => t('Unblock'),
532 '$h_users' => t('Users'),
533 '$th_users' => array( t('Name'), t('Email'), t('Register date'), t('Last login'), t('Last item'), t('Account') ),
535 '$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?'),
536 '$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?'),
540 '$baseurl' => $a->get_baseurl(true),
542 '$pending' => $pending,
554 function admin_page_plugins(&$a){
560 $plugin = $a->argv[2];
561 if (!is_file("addon/$plugin/$plugin.php")){
562 notice( t("Item not found.") );
566 if (x($_GET,"a") && $_GET['a']=="t"){
567 // Toggle plugin status
568 $idx = array_search($plugin, $a->plugins);
570 unset($a->plugins[$idx]);
571 uninstall_plugin($plugin);
572 info( sprintf( t("Plugin %s disabled."), $plugin ) );
574 $a->plugins[] = $plugin;
575 install_plugin($plugin);
576 info( sprintf( t("Plugin %s enabled."), $plugin ) );
578 set_config("system","addon", implode(", ",$a->plugins));
579 goaway($a->get_baseurl(true) . '/admin/plugins' );
580 return; // NOTREACHED
582 // display plugin details
583 require_once('library/markdown.php');
585 if (in_array($plugin, $a->plugins)){
586 $status="on"; $action= t("Disable");
588 $status="off"; $action= t("Enable");
592 if (is_file("addon/$plugin/README.md")){
593 $readme = file_get_contents("addon/$plugin/README.md");
594 $readme = Markdown($readme);
595 } else if (is_file("addon/$plugin/README")){
596 $readme = "<pre>". file_get_contents("addon/$plugin/README") ."</pre>";
600 if (is_array($a->plugins_admin) && in_array($plugin, $a->plugins_admin)){
601 @require_once("addon/$plugin/$plugin.php");
602 $func = $plugin.'_plugin_admin';
603 $func($a, $admin_form);
606 $t = get_markup_template("admin_plugins_details.tpl");
607 return replace_macros($t, array(
608 '$title' => t('Administration'),
609 '$page' => t('Plugins'),
610 '$toggle' => t('Toggle'),
611 '$settings' => t('Settings'),
612 '$baseurl' => $a->get_baseurl(true),
614 '$plugin' => $plugin,
615 '$status' => $status,
616 '$action' => $action,
617 '$info' => get_plugin_info($plugin),
618 '$str_author' => t('Author: '),
619 '$str_maintainer' => t('Maintainer: '),
621 '$admin_form' => $admin_form,
622 '$function' => 'plugins',
635 $files = glob("addon/*/");
637 foreach($files as $file) {
639 list($tmp, $id)=array_map("trim", explode("/",$file));
640 $info = get_plugin_info($id);
641 $plugins[] = array( $id, (in_array($id, $a->plugins)?"on":"off") , $info);
646 $t = get_markup_template("admin_plugins.tpl");
647 return replace_macros($t, array(
648 '$title' => t('Administration'),
649 '$page' => t('Plugins'),
650 '$submit' => t('Submit'),
651 '$baseurl' => $a->get_baseurl(true),
652 '$function' => 'plugins',
653 '$plugins' => $plugins
657 function toggle_theme(&$themes,$th,&$result) {
658 for($x = 0; $x < count($themes); $x ++) {
659 if($themes[$x]['name'] === $th) {
660 if($themes[$x]['allowed']) {
661 $themes[$x]['allowed'] = 0;
665 $themes[$x]['allowed'] = 1;
672 function theme_status($themes,$th) {
673 for($x = 0; $x < count($themes); $x ++) {
674 if($themes[$x]['name'] === $th) {
675 if($themes[$x]['allowed']) {
688 function rebuild_theme_table($themes) {
691 foreach($themes as $th) {
707 function admin_page_themes(&$a){
709 $allowed_themes_str = get_config('system','allowed_themes');
710 $allowed_themes_raw = explode(',',$allowed_themes_str);
711 $allowed_themes = array();
712 if(count($allowed_themes_raw))
713 foreach($allowed_themes_raw as $x)
715 $allowed_themes[] = trim($x);
718 $files = glob('view/theme/*');
720 foreach($files as $file) {
721 $f = basename($file);
722 $is_experimental = intval(file_exists($file . '/experimental'));
723 $is_unsupported = 1-(intval(file_exists($file . '/unsupported')));
724 $is_allowed = intval(in_array($f,$allowed_themes));
725 $themes[] = array('name' => $f, 'experimental' => $is_experimental, 'supported' => $is_supported, 'allowed' => $is_allowed);
729 if(! count($themes)) {
730 notice( t('No themes found.'));
739 $theme = $a->argv[2];
740 if(! is_dir("view/theme/$theme")){
741 notice( t("Item not found.") );
745 if (x($_GET,"a") && $_GET['a']=="t"){
747 // Toggle theme status
749 toggle_theme($themes,$theme,$result);
750 $s = rebuild_theme_table($themes);
752 info( sprintf('Theme %s enabled.',$theme));
754 info( sprintf('Theme %s disabled.',$theme));
756 set_config('system','allowed_themes',$s);
757 goaway($a->get_baseurl(true) . '/admin/themes' );
758 return; // NOTREACHED
761 // display theme details
762 require_once('library/markdown.php');
764 if (theme_status($themes,$theme)) {
765 $status="on"; $action= t("Disable");
767 $status="off"; $action= t("Enable");
771 if (is_file("view/$theme/README.md")){
772 $readme = file_get_contents("view/$theme/README.md");
773 $readme = Markdown($readme);
774 } else if (is_file("view/$theme/README")){
775 $readme = "<pre>". file_get_contents("view/$theme/README") ."</pre>";
780 $screenshot = array( get_theme_screenshot($theme), t('Screenshot'));
781 if(! stristr($screenshot[0],$theme))
784 $t = get_markup_template("admin_plugins_details.tpl");
785 return replace_macros($t, array(
786 '$title' => t('Administration'),
787 '$page' => t('Themes'),
788 '$toggle' => t('Toggle'),
789 '$settings' => t('Settings'),
790 '$baseurl' => $a->get_baseurl(true),
793 '$status' => $status,
794 '$action' => $action,
795 '$info' => get_theme_info($theme),
796 '$function' => 'themes',
797 '$admin_form' => $admin_form,
798 '$str_author' => t('Author: '),
799 '$str_maintainer' => t('Maintainer: '),
800 '$screenshot' => $screenshot,
813 foreach($themes as $th) {
814 $xthemes[] = array($th['name'],(($th['allowed']) ? "on" : "off"), get_theme_info($th['name']));
818 $t = get_markup_template("admin_plugins.tpl");
819 return replace_macros($t, array(
820 '$title' => t('Administration'),
821 '$page' => t('Themes'),
822 '$submit' => t('Submit'),
823 '$baseurl' => $a->get_baseurl(true),
824 '$function' => 'themes',
825 '$plugins' => $xthemes,
826 '$experimental' => t('[Experimental]'),
827 '$unsupported' => t('[Unsupported]')
836 function admin_page_logs_post(&$a) {
837 if (x($_POST,"page_logs")) {
839 $logfile = ((x($_POST,'logfile')) ? notags(trim($_POST['logfile'])) : '');
840 $debugging = ((x($_POST,'debugging')) ? true : false);
841 $loglevel = ((x($_POST,'loglevel')) ? intval(trim($_POST['loglevel'])) : 0);
843 set_config('system','logfile', $logfile);
844 set_config('system','debugging', $debugging);
845 set_config('system','loglevel', $loglevel);
850 info( t("Log settings updated.") );
851 goaway($a->get_baseurl(true) . '/admin/logs' );
852 return; // NOTREACHED
855 function admin_page_logs(&$a){
857 $log_choices = Array(
858 LOGGER_NORMAL => 'Normal',
859 LOGGER_TRACE => 'Trace',
860 LOGGER_DEBUG => 'Debug',
861 LOGGER_DATA => 'Data',
865 $t = get_markup_template("admin_logs.tpl");
867 $f = get_config('system','logfile');
871 if(!file_exists($f)) {
872 $data = t("Error trying to open <strong>$f</strong> log file.\r\n<br/>Check to see if file $f exist and is
876 $fp = fopen($f, 'r');
878 $data = t("Couldn't open <strong>$f</strong> log file.\r\n<br/>Check to see if file $f is readable.");
882 $size = $fstat['size'];
885 if($size > 5000000 || $size < 0)
887 $seek = fseek($fp,0-$size,SEEK_END);
889 fgets($fp); // throw away the first partial line
890 $data = escape_tags(fread($fp,$size));
892 $data .= escape_tags(fread($fp,4096));
899 return replace_macros($t, array(
900 '$title' => t('Administration'),
901 '$page' => t('Logs'),
902 '$submit' => t('Submit'),
903 '$clear' => t('Clear'),
905 '$baseurl' => $a->get_baseurl(true),
906 '$logname' => get_config('system','logfile'),
908 // name, label, value, help string, extra data...
909 '$debugging' => array('debugging', t("Debugging"),get_config('system','debugging'), ""),
910 '$logfile' => array('logfile', t("Log file"), get_config('system','logfile'), t("Must be writable by web server. Relative to your Friendica top-level directory.")),
911 '$loglevel' => array('loglevel', t("Log level"), get_config('system','loglevel'), "", $log_choices),
915 function admin_page_remoteupdate_post(&$a) {
916 // this function should be called via ajax post
917 if(!is_site_admin()) {
922 if (x($_POST,'remotefile') && $_POST['remotefile']!=""){
923 $remotefile = $_POST['remotefile'];
924 $ftpdata = (x($_POST['ftphost'])?$_POST:false);
925 doUpdate($remotefile, $ftpdata);
927 echo "No remote file to download. Abort!";
933 function admin_page_remoteupdate(&$a) {
934 if(!is_site_admin()) {
938 $canwrite = canWeWrite();
939 $canftp = function_exists('ftp_connect');
945 $u = array('','','');
948 $tpl = get_markup_template("admin_remoteupdate.tpl");
949 return replace_macros($tpl, array(
950 '$baseurl' => $a->get_baseurl(true),
951 '$submit' => t("Update now"),
952 '$close' => t("Close"),
953 '$localversion' => FRIENDICA_VERSION,
954 '$remoteversion' => $u[1],
955 '$needupdate' => $needupdate,
956 '$canwrite' => $canwrite,
957 '$canftp' => $canftp,
958 '$ftphost' => array('ftphost', t("FTP Host"), '',''),
959 '$ftppath' => array('ftppath', t("FTP Path"), '/',''),
960 '$ftpuser' => array('ftpuser', t("FTP User"), '',''),
961 '$ftppwd' => array('ftppwd', t("FTP Password"), '',''),
962 '$remotefile'=>array('remotefile','', $u['2'],'')