]> git.mxchange.org Git - friendica.git/blob - mod/admin.php
openid settings appearing when disabled, don't tag numbers, install admin not getting set
[friendica.git] / mod / admin.php
1 <?php
2
3  /**
4   * Friendika admin
5   */
6   
7  
8 function admin_init(&$a) {
9         if(!is_site_admin()) {
10                 notice( t('Permission denied.') . EOL);
11                 return;
12         }
13 }
14
15 function admin_post(&$a){
16         if(!is_site_admin()) {
17                 return login(false);
18         }
19         
20         // urls
21         if ($a->argc > 1){
22                 switch ($a->argv[1]){
23                         case 'site':
24                                 admin_page_site_post($a);
25                                 break;
26                         case 'users':
27                                 admin_page_users_post($a);
28                                 break;
29                         case 'plugins':
30                                 if ($a->argc > 2 && 
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';
35                                                         $func($a);
36                                                 }
37                                 }
38                                 goaway($a->get_baseurl() . '/admin/plugins/' . $a->argv[2] );
39                                 return; // NOTREACHED                                                   
40                                 break;
41                         case 'logs':
42                                 admin_page_logs_post($a);
43                                 break;
44                 }
45         }
46
47         goaway($a->get_baseurl() . '/admin' );
48         return; // NOTREACHED   
49 }
50
51 function admin_content(&$a) {
52
53         if(!is_site_admin()) {
54                 return login(false);
55         }
56
57         /**
58          * Side bar links
59          */
60
61         // array( url, name, extra css classes )
62         $aside = Array(
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")
66         );
67         
68         /* get plugins admin page */
69         
70         $r = q("SELECT * FROM `addon` WHERE `plugin_admin`=1");
71         $aside['plugins_admin']=Array();
72         foreach ($r as $h){
73                 $plugin =$h['name'];
74                 $aside['plugins_admin'][] = Array($a->get_baseurl()."/admin/plugins/".$plugin, $plugin, "plugin");
75                 // temp plugins with admin
76                 $a->plugins_admin[] = $plugin;
77         }
78                 
79         $aside['logs'] = Array($a->get_baseurl()."/admin/logs/", t("Logs"), "logs");
80
81         $t = get_markup_template("admin_aside.tpl");
82         $a->page['aside'] = replace_macros( $t, array(
83                         '$admin' => $aside, 
84                         '$h_pending' => t('User registrations waiting for confirmation'),
85                         '$admurl'=> $a->get_baseurl()."/admin/"
86         ));
87
88
89
90         /**
91          * Page content
92          */
93         $o = '';
94         
95         // urls
96         if ($a->argc > 1){
97                 switch ($a->argv[1]){
98                         case 'site':
99                                 $o = admin_page_site($a);
100                                 break;
101                         case 'users':
102                                 $o = admin_page_users($a);
103                                 break;
104                         case 'plugins':
105                                 $o = admin_page_plugins($a);
106                                 break;
107                         case 'logs':
108                                 $o = admin_page_logs($a);
109                                 break;                          
110                         default:
111                                 notice( t("Item not found.") );
112                 }
113         } else {
114                 $o = admin_page_summary($a);
115         }
116         return $o;
117
118
119
120 /**
121  * Admin Summary Page
122  */
123 function admin_page_summary(&$a) {
124         $r = q("SELECT `page-flags`, COUNT(uid) as `count` FROM `user` GROUP BY `page-flags`");
125         $accounts = Array(
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)
130         );
131         $users=0;
132         foreach ($r as $u){ $accounts[$u['page-flags']][1] = $u['count']; $users+=$u['count']; }
133
134         
135         $r = q("SELECT COUNT(id) as `count` FROM `register`");
136         $pending = $r[0]['count'];
137         
138         
139         
140         
141         
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 )
152         ));
153 }
154
155
156 /**
157  * Admin Site Page
158  */
159 function admin_page_site_post(&$a){
160         if (!x($_POST,"page_site")){
161                 return;
162         }
163
164         
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);
170         
171         
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']))         : '');  
174         
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);
186
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);
193
194
195         set_config('config','sitename',$sitename);
196         if ($banner==""){
197                 // don't know why, but del_config doesn't work...
198                 q("DELETE FROM `config` WHERE `cat` = '%s' AND `k` = '%s' LIMIT 1",
199                         dbesc("system"),
200                         dbesc("banner")
201                 );
202         } else {
203                 set_config('system','banner', $banner);
204         }
205         set_config('system','language', $language);
206         set_config('system','theme', $theme);
207         set_config('system','maximagesize', $maximagesize);
208         
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",
218                         dbesc("system"),
219                         dbesc("directory_submit_url")
220                 );
221         } else {
222                 set_config('system','directory_submit_url', $global_directory);
223         }
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);
237
238         info( t('Site settings updated.') . EOL);
239         goaway($a->get_baseurl() . '/admin/site' );
240         return; // NOTREACHED   
241         
242 }
243  
244 function admin_page_site(&$a) {
245         
246         /* Installed langs */
247         $lang_choices = array();
248         $langs = glob('view/*/strings.php');
249         
250         if(is_array($langs) && count($langs)) {
251                 if(! in_array('view/en/strings.php',$langs))
252                         $langs[] = 'view/en/';
253                 asort($langs);
254                 foreach($langs as $l) {
255                         $t = explode("/",$l);
256                         $lang_choices[$t[1]] = $t[1];
257                 }
258         }
259         
260         /* Installed themes */
261         $theme_choices = array();
262         $files = glob('view/theme/*');
263         if($files) {
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;
268                 }
269         }
270         
271         
272         /* Banner */
273         $banner = get_config('system','banner');
274         if($banner == false) 
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);
277         
278         //echo "<pre>"; var_dump($lang_choices); die("</pre>");
279
280         /* Register policy */
281         $register_choices = Array(
282                 REGISTER_CLOSED => t("Closed"),
283                 REGISTER_APPROVE => t("Requires approval"),
284                 REGISTER_OPEN => t("Open")
285         ); 
286         
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'),
296                 
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),
303
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."),
305
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."),
313                         
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)."),
326
327                         
328         ));
329
330 }
331
332
333 /**
334  * Users admin page
335  */
336 function admin_page_users_post(&$a){
337         $pending = ( x(£_POST, 'pending') ? $_POST['pending'] : Array() );
338         $users = ( x($_POST, 'user') ? $_POST['user'] : Array() );
339         
340         if (x($_POST,'page_users_block')){
341                 foreach($users as $uid){
342                         q("UPDATE `user` SET `blocked`=1-`blocked` WHERE `uid`=%s",
343                                 intval( $uid )
344                         );
345                 }
346                 notice( sprintf( tt("%s user blocked", "%s users blocked/unblocked", count($users)), count($users)) );
347         }
348         if (x($_POST,'page_users_delete')){
349                 require_once("include/Contact.php");
350                 foreach($users as $uid){
351                         user_remove($uid);
352                 }
353                 notice( sprintf( tt("%s user deleted", "%s users deleted", count($users)), count($users)) );
354         }
355         
356         if (x($_POST,'page_users_approve')){
357                 require_once("mod/regmod.php");
358                 foreach($pending as $hash){
359                         user_allow($hash);
360                 }
361         }
362         if (x($_POST,'page_users_deny')){
363                 require_once("mod/regmod.php");
364                 foreach($pending as $hash){
365                         user_deny($hash);
366                 }
367         }
368         goaway($a->get_baseurl() . '/admin/users' );
369         return; // NOTREACHED   
370 }
371  
372 function admin_page_users(&$a){
373         if ($a->argc>2) {
374                 $uid = $a->argv[3];
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                                           
380                 }               
381                 switch($a->argv[2]){
382                         case "delete":{
383                                 // delete user
384                                 require_once("include/Contact.php");
385                                 user_remove($uid);
386                                 
387                                 notice( sprintf(t("User '%s' deleted"), $user[0]['username']) . EOL);
388                         }; break;
389                         case "block":{
390                                 q("UPDATE `user` SET `blocked`=%d WHERE `uid`=%s",
391                                         intval( 1-$user[0]['blocked'] ),
392                                         intval( $uid )
393                                 );
394                                 notice( sprintf( ($user[0]['blocked']?t("User '%s' unblocked"):t("User '%s' blocked")) , $user[0]['username']) . EOL);
395                         }; break;
396                 }
397                 goaway($a->get_baseurl() . '/admin/users' );
398                 return; // NOTREACHED   
399                 
400         }
401         
402         /* get pending */
403         $pending = q("SELECT `register`.*, `contact`.`name`, `user`.`email`
404                                  FROM `register`
405                                  LEFT JOIN `contact` ON `register`.`uid` = `contact`.`uid`
406                                  LEFT JOIN `user` ON `register`.`uid` = `user`.`uid`;");
407         
408         /* get users */
409
410         $total = q("SELECT count(*) as total FROM `user` where 1");
411         if(count($total)) {
412                 $a->set_pager_total($total[0]['total']);
413                 $a->set_pager_itemspage(100);
414         }
415
416         $users = q("SELECT `user` . * , `contact`.`name` , `contact`.`url` , `contact`.`micro`, `lastitem`.`lastitem_date`
417                                 FROM
418                                         (SELECT MAX(`item`.`changed`) as `lastitem_date`, `item`.`uid`
419                                         FROM `item`
420                                         WHERE `item`.`type` = 'wall'
421                                         GROUP BY `item`.`uid`) AS `lastitem`
422                                                  RIGHT OUTER JOIN `user` ON `user`.`uid` = `lastitem`.`uid`,
423                                            `contact`
424                                 WHERE
425                                            `user`.`uid` = `contact`.`uid`
426                                                 AND `user`.`verified` =1
427                                         AND `contact`.`self` =1
428                                 ORDER BY `contact`.`name` LIMIT %d, %d
429                                 ",
430                                 intval($a->pager['start']),
431                                 intval($a->pager['itemspage'])
432                                 );
433                                         
434         function _setup_users($e){
435                 $accounts = Array(
436                         t('Normal Account'), 
437                         t('Soapbox Account'),
438                         t('Community/Celebrity Account'),
439                         t('Automatic Friend Account')
440                 );
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']);
445                 return $e;
446         }
447         $users = array_map("_setup_users", $users);
448         
449         $t = get_markup_template("admin_users.tpl");
450         $o = replace_macros($t, array(
451                 // strings //
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'),
464                 
465                 '$h_users' => t('Users'),
466                 '$th_users' => array( t('Name'), t('Email'), t('Register date'), t('Last login'), t('Last item'),  t('Account') ),
467
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?'),
470
471
472                 // values //
473                 '$baseurl' => $a->get_baseurl(),
474
475                 '$pending' => $pending,
476                 '$users' => $users,
477         ));
478         $o .= paginate($a);
479         return $o;
480 }
481
482
483 /*
484  * Plugins admin page
485  */
486
487 function admin_page_plugins(&$a){
488         
489         /**
490          * Single plugin
491          */
492         if ($a->argc == 3){
493                 $plugin = $a->argv[2];
494                 if (!is_file("addon/$plugin/$plugin.php")){
495                         notice( t("Item not found.") );
496                         return;
497                 }
498                 
499                 if (x($_GET,"a") && $_GET['a']=="t"){
500                         // Toggle plugin status
501                         $idx = array_search($plugin, $a->plugins);
502                         if ($idx){
503                                 unset($a->plugins[$idx]);
504                                 uninstall_plugin($plugin);
505                                 info( sprintf( t("Plugin %s disabled."), $plugin ) );
506                         } else {
507                                 $a->plugins[] = $plugin;
508                                 install_plugin($plugin);
509                                 info( sprintf( t("Plugin %s enabled."), $plugin ) );
510                         }
511                         set_config("system","addon", implode(", ",$a->plugins));
512                         goaway($a->get_baseurl() . '/admin/plugins' );
513                         return; // NOTREACHED   
514                 }
515                 // display plugin details
516                 require_once('library/markdown.php');
517
518                 if (in_array($plugin, $a->plugins)){
519                         $status="on"; $action= t("Disable");
520                 } else {
521                         $status="off"; $action= t("Enable");
522                 }
523                 
524                 $readme=Null;
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>";
530                 } 
531                 
532                 $admin_form="";
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);
537                 }
538                 
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(),
546                 
547                         '$plugin' => $plugin,
548                         '$status' => $status,
549                         '$action' => $action,
550                         '$info' => get_plugin_info($plugin),
551                 
552                         '$admin_form' => $admin_form,
553                         
554                         '$readme' => $readme
555                 ));
556         } 
557          
558          
559         
560         /**
561          * List plugins
562          */
563         
564         $plugins = array();
565         $files = glob("addon/*/");
566         if($files) {
567                 foreach($files as $file) {      
568                         if (is_dir($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);
572                         }
573                 }
574         }
575         
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(),
582         
583                 '$plugins' => $plugins
584         ));
585 }
586
587
588 /**
589  * Logs admin page
590  */
591  
592 function admin_page_logs_post(&$a) {
593         if (x($_POST,"page_logs")) {
594
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);
598
599                 set_config('system','logfile', $logfile);
600                 set_config('system','debugging',  $debugging);
601                 set_config('system','loglevel', $loglevel);
602
603                 
604         }
605
606         info( t("Log settings updated.") );
607         goaway($a->get_baseurl() . '/admin/logs' );
608         return; // NOTREACHED   
609 }
610  
611 function admin_page_logs(&$a){
612         
613         $log_choices = Array(
614                 LOGGER_NORMAL => 'Normal',
615                 LOGGER_TRACE => 'Trace',
616                 LOGGER_DEBUG => 'Debug',
617                 LOGGER_DATA => 'Data',
618                 LOGGER_ALL => 'All'
619         );
620         
621         $t = get_markup_template("admin_logs.tpl");
622
623         $f = get_config('system','logfile');
624         $size = filesize($f);
625         if($size > 5000000)
626                 $size = 5000000;
627
628         $data = '';
629         $fp = fopen($f,'r');
630         if($fp) {
631                 $seek = fseek($fp,0-$size,SEEK_END);
632                 if($seek === 0) {
633                         fgets($fp); // throw away the first partial line
634                         $data = escape_tags(fread($fp,$size));
635                         while(! feof($fp))
636                                 $data .= escape_tags(fread($fp,4096));
637                 }
638                 fclose($fp);
639         }
640
641
642         return replace_macros($t, array(
643                 '$title' => t('Administration'),
644                 '$page' => t('Logs'),
645                 '$submit' => t('Submit'),
646                 '$clear' => t('Clear'),
647                 '$data' => $data,
648                 '$baseurl' => $a->get_baseurl(),
649                 '$logname' =>  get_config('system','logfile'),
650                 
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),
655         ));
656 }
657