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.

130 lines
3.1 KiB

15 years ago
15 years ago
15 years ago
12 years ago
12 years ago
12 years ago
12 years ago
15 years ago
15 years ago
15 years ago
15 years ago
  1. <?Php
  2. /**
  3. * \class User
  4. * \brief Handles the user's login and user.
  5. *
  6. */
  7. class User {
  8. private $xmppSession;
  9. public $username = '';
  10. private $password = '';
  11. private $config = array();
  12. public $userdir;
  13. public $useruri;
  14. public $sizelimit;
  15. /**
  16. * Class constructor. Reloads the user's session or attempts to authenticate
  17. * the user.
  18. * Note that the constructor is private. This class is a singleton.
  19. */
  20. function __construct()
  21. {
  22. if($this->isLogged()) {
  23. global $session;
  24. $this->username = $session['user'].'@'.$session['host'];
  25. $this->config = $session['config'];
  26. $this->sizelimit = (int)Conf::getServerConfElement('sizeLimit');
  27. $this->userdir = DOCUMENT_ROOT.'/users/'.$this->username.'/';
  28. $this->useruri = BASE_URI.'users/'.$this->username.'/';
  29. }
  30. }
  31. /**
  32. * Get the current size in bytes of the user directory
  33. */
  34. function dirSize()
  35. {
  36. $sum = 0;
  37. foreach($this->getDir() as $s)
  38. $sum = $sum + filesize($s['dir']);
  39. return $sum;
  40. }
  41. /**
  42. * Get a list of the files in the user dir with uri, dir and thumbs
  43. */
  44. function getDir()
  45. {
  46. $dir = array();
  47. if(is_dir($this->userdir))
  48. foreach(scandir($this->userdir) as $s) {
  49. if(
  50. $s != '.' &&
  51. $s != '..' &&
  52. substr($s, 0, 6) != 'thumb_' &&
  53. substr($s, 0, 7) != 'medium_' &&
  54. $s != 'index.html') {
  55. $file = array(
  56. 'uri' => $this->useruri.$s,
  57. 'dir' => $this->userdir.$s,
  58. 'thumb' => $this->useruri.'thumb_'.$s,
  59. 'medium' => $this->useruri.'medium_'.$s);
  60. $dir[$s] = $file;
  61. }
  62. }
  63. return $dir;
  64. }
  65. /**
  66. * Checks if the user has an open session.
  67. */
  68. function isLogged()
  69. {
  70. // User is not logged in if both the session vars and the members are unset.
  71. global $session;
  72. return $session['on'];
  73. }
  74. function desauth()
  75. {
  76. $pd = new modl\PresenceDAO();
  77. $pd->clearPresence($this->username);
  78. if($this->isLogged()) {
  79. $p = new moxl\PresenceUnavaiable();
  80. $p->request();
  81. }
  82. $sess = Session::start(APP_NAME);
  83. Session::dispose(APP_NAME);
  84. }
  85. function getLogin()
  86. {
  87. return $this->username;
  88. }
  89. function getPass()
  90. {
  91. return $this->password;
  92. }
  93. function setConfig(array $config)
  94. {
  95. global $session;
  96. $session['config'] = $config;
  97. $sess = Session::start(APP_NAME);
  98. $sess->set('session', $session);
  99. }
  100. function getConfig($key = false)
  101. {
  102. if($key == false)
  103. return $this->config;
  104. if(isset($this->config[$key]))
  105. return $this->config[$key];
  106. }
  107. }