Friendica Communications Platform (please note that this is a clone of the repository at github, issues are handled there) https://friendi.ca
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

150 lines
3.7 KiB

10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
  1. <?php
  2. require_once('mod/settings.php');
  3. if(! function_exists('delegate_init')) {
  4. function delegate_init(&$a) {
  5. return settings_init($a);
  6. }
  7. }
  8. if(! function_exists('delegate_content')) {
  9. function delegate_content(&$a) {
  10. if(! local_user()) {
  11. notice( t('Permission denied.') . EOL);
  12. return;
  13. }
  14. if($a->argc > 2 && $a->argv[1] === 'add' && intval($a->argv[2])) {
  15. // delegated admins can view but not change delegation permissions
  16. if(x($_SESSION,'submanage') && intval($_SESSION['submanage']))
  17. goaway($a->get_baseurl() . '/delegate');
  18. $id = $a->argv[2];
  19. $r = q("select `nickname` from user where uid = %d limit 1",
  20. intval($id)
  21. );
  22. if(count($r)) {
  23. $r = q("select id from contact where uid = %d and nurl = '%s' limit 1",
  24. intval(local_user()),
  25. dbesc(normalise_link($a->get_baseurl() . '/profile/' . $r[0]['nickname']))
  26. );
  27. if(count($r)) {
  28. q("insert into manage ( uid, mid ) values ( %d , %d ) ",
  29. intval($a->argv[2]),
  30. intval(local_user())
  31. );
  32. }
  33. }
  34. goaway($a->get_baseurl() . '/delegate');
  35. }
  36. if($a->argc > 2 && $a->argv[1] === 'remove' && intval($a->argv[2])) {
  37. // delegated admins can view but not change delegation permissions
  38. if(x($_SESSION,'submanage') && intval($_SESSION['submanage']))
  39. goaway($a->get_baseurl() . '/delegate');
  40. q("delete from manage where uid = %d and mid = %d limit 1",
  41. intval($a->argv[2]),
  42. intval(local_user())
  43. );
  44. goaway($a->get_baseurl() . '/delegate');
  45. }
  46. $full_managers = array();
  47. // These people can manage this account/page with full privilege
  48. $r = q("SELECT * FROM `user` WHERE `email` = '%s' AND `password` = '%s' ",
  49. dbesc($a->user['email']),
  50. dbesc($a->user['password'])
  51. );
  52. if(count($r))
  53. $full_managers = $r;
  54. $delegates = array();
  55. // find everybody that currently has delegated management to this account/page
  56. $r = q("select * from user where uid in ( select uid from manage where mid = %d ) ",
  57. intval(local_user())
  58. );
  59. if(count($r))
  60. $delegates = $r;
  61. $uids = array();
  62. if(count($full_managers))
  63. foreach($full_managers as $rr)
  64. $uids[] = $rr['uid'];
  65. if(count($delegates))
  66. foreach($delegates as $rr)
  67. $uids[] = $rr['uid'];
  68. // find every contact who might be a candidate for delegation
  69. $r = q("select nurl from contact where substring_index(contact.nurl,'/',3) = '%s'
  70. and contact.uid = %d and contact.self = 0 and network = '%s' ",
  71. dbesc(normalise_link($a->get_baseurl())),
  72. intval(local_user()),
  73. dbesc(NETWORK_DFRN)
  74. );
  75. if(! count($r)) {
  76. notice( t('No potential page delegates located.') . EOL);
  77. return;
  78. }
  79. $nicknames = array();
  80. if(count($r)) {
  81. foreach($r as $rr) {
  82. $nicknames[] = "'" . dbesc(basename($rr['nurl'])) . "'";
  83. }
  84. }
  85. $potentials = array();
  86. $nicks = implode(',',$nicknames);
  87. // get user records for all potential page delegates who are not already delegates or managers
  88. $r = q("select `uid`, `username`, `nickname` from user where nickname in ( $nicks )");
  89. if(count($r))
  90. foreach($r as $rr)
  91. if(! in_array($rr['uid'],$uids))
  92. $potentials[] = $rr;
  93. require_once("mod/settings.php");
  94. settings_init($a);
  95. $o = replace_macros(get_markup_template('delegate.tpl'),array(
  96. '$header' => t('Delegate Page Management'),
  97. '$base' => $a->get_baseurl(),
  98. '$desc' => t('Delegates are able to manage all aspects of this account/page except for basic account settings. Please do not delegate your personal account to anybody that you do not trust completely.'),
  99. '$head_managers' => t('Existing Page Managers'),
  100. '$managers' => $full_managers,
  101. '$head_delegates' => t('Existing Page Delegates'),
  102. '$delegates' => $delegates,
  103. '$head_potentials' => t('Potential Delegates'),
  104. '$potentials' => $potentials,
  105. '$remove' => t('Remove'),
  106. '$add' => t('Add'),
  107. '$none' => t('No entries.')
  108. ));
  109. return $o;
  110. }
  111. }