Friendica Communications Platform (please note that this is a clone of the repository at github, issues are handled there) https://friendi.ca
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 
 
 
 
 

148 linhas
3.7 KiB

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