PageRenderTime 36ms CodeModel.GetById 9ms RepoModel.GetById 0ms app.codeStats 0ms

/lib/magirc/denora/Objects.class.php

https://github.com/CerberusStyle/magirc
PHP | 197 lines | 172 code | 12 blank | 13 comment | 49 complexity | abc5903bfb2657c286998a20c6001849 MD5 | raw file
Possible License(s): GPL-3.0, LGPL-2.1, MPL-2.0-no-copyleft-exception
  1. <?php
  2. Class Server {
  3. public $server;
  4. public $online;
  5. public $description;
  6. public $connect_time;
  7. public $split_time;
  8. public $version;
  9. public $uptime;
  10. public $motd;
  11. public $motd_html;
  12. public $users;
  13. public $users_max;
  14. public $users_max_time;
  15. public $ping;
  16. public $ping_max;
  17. public $ping_max_time;
  18. public $opers;
  19. public $opers_max;
  20. public $opers_max_time;
  21. public $country;
  22. public $country_code;
  23. function __construct() {
  24. $this->online = $this->online == 'Y';
  25. $this->motd_html = $this->motd ? Magirc::irc2html($this->motd) : null;
  26. $this->motd = htmlentities($this->motd, ENT_COMPAT, "UTF-8");
  27. }
  28. }
  29. Class User {
  30. // From SQL
  31. public $nickname;
  32. public $realname;
  33. public $hostname;
  34. private $hostname_cloaked;
  35. public $username;
  36. public $swhois;
  37. public $connect_time;
  38. public $server;
  39. public $server_country;
  40. public $server_country_code;
  41. public $away;
  42. public $away_msg;
  43. public $client;
  44. public $client_html;
  45. public $online;
  46. public $quit_time;
  47. public $quit_msg;
  48. public $country_code;
  49. public $country;
  50. public $service;
  51. // User modes, only used internally
  52. private $mode_la, $mode_lb, $mode_lc, $mode_ld, $mode_le, $mode_lf, $mode_lg, $mode_lh, $mode_li, $mode_lj, $mode_lk, $mode_ll, $mode_lm, $mode_ln, $mode_lo, $mode_lp, $mode_lq, $mode_lr, $mode_ls, $mode_lt, $mode_lu, $mode_lv, $mode_lw, $mode_lx, $mode_ly, $mode_lz;
  53. private $mode_ua, $mode_ub, $mode_uc, $mode_ud, $mode_ue, $mode_uf, $mode_ug, $mode_uh, $mode_ui, $mode_uj, $mode_uk, $mode_ul, $mode_um, $mode_un, $mode_uo, $mode_up, $mode_uq, $mode_ur, $mode_us, $mode_ut, $mode_uu, $mode_uv, $mode_uw, $mode_ux, $mode_uy, $mode_uz;
  54. private $cmode_lq, $cmode_la, $cmode_lo, $cmode_lh, $cmode_lv;
  55. // Filled by the constructor
  56. private $umodes;
  57. #public $cmodes;
  58. public $operator;
  59. public $operator_level;
  60. public $helper;
  61. public $bot;
  62. function __construct() {
  63. $this->online = $this->online == 'Y';
  64. $this->away = $this->away == 'Y';
  65. $this->realname = htmlentities($this->realname, ENT_COMPAT, "UTF-8");
  66. $this->swhois = htmlentities($this->swhois, ENT_COMPAT, "UTF-8");
  67. $this->away_msg = htmlentities($this->away_msg, ENT_COMPAT, "UTF-8");
  68. $this->client_html = $this->client ? Magirc::irc2html($this->client) : null;
  69. $this->client = htmlentities($this->client, ENT_COMPAT, "UTF-8");
  70. $this->quit_msg = htmlentities($this->quit_msg, ENT_COMPAT, "UTF-8");
  71. $this->service = $this->service == 'Y';
  72. if (Protocol::host_cloaking && !empty($this->hostname_cloaked)) $this->hostname = $this->hostname_cloaked;
  73. // User modes
  74. for ($j = 97; $j <= 122; $j++) {
  75. $mode_l = 'mode_l'.chr($j);
  76. $mode_u = 'mode_u'.chr($j);
  77. if (isset($this->$mode_l)) {
  78. if ($this->$mode_l == "Y") {
  79. $this->$mode_l = true;
  80. $this->umodes .= chr($j);
  81. } else {
  82. $this->$mode_l = false;
  83. }
  84. }
  85. if (isset($this->$mode_u)) {
  86. if ($this->$mode_u == "Y") {
  87. $this->$mode_u = true;
  88. $this->umodes .= chr($j - 32);
  89. } else {
  90. $this->$mode_u = false;
  91. }
  92. }
  93. }
  94. // Channel modes
  95. $cmodes = null;
  96. if ($this->cmode_lq == 'Y') $cmodes .= "q";
  97. if ($this->cmode_la == 'Y') $cmodes .= "a";
  98. if ($this->cmode_lo == 'Y') $cmodes .= "o";
  99. if ($this->cmode_lh == 'Y') $cmodes .= "h";
  100. if ($this->cmode_lv == 'Y') $cmodes .= "v";
  101. $this->cmodes = $cmodes ? "+".$cmodes : null;
  102. // Futher info
  103. $this->bot = $this->hasMode(Protocol::bot_mode);
  104. if (!Protocol::oper_hidden_mode || !$this->hasMode(Protocol::oper_hidden_mode)) {
  105. $this->helper = $this->hasMode(Protocol::helper_mode);
  106. $levels = Protocol::$oper_levels;
  107. if (!empty($levels)) {
  108. foreach ($levels as $mode => $level) {
  109. $mode = Denora::getSqlMode($mode);
  110. if ($this->$mode) {
  111. $this->operator_level = $level;
  112. break;
  113. }
  114. }
  115. } elseif ($this->mode_lo) {
  116. $this->operator_level = "Operator";
  117. }
  118. if ($this->operator_level) $this->operator = true;
  119. }
  120. // Get the server country if user country is local
  121. if ($this->country_code == 'local' && $this->server_country_code) {
  122. $this->country = $this->server_country;
  123. $this->country_code = $this->server_country_code;
  124. }
  125. }
  126. private function hasMode($mode) {
  127. return $mode ? strstr($this->umodes, $mode) !== false : false;
  128. }
  129. }
  130. class Channel {
  131. // From SQL
  132. public $channel;
  133. public $users;
  134. public $users_max;
  135. public $users_max_time;
  136. public $topic;
  137. public $topic_html;
  138. public $topic_author;
  139. public $topic_time;
  140. public $kicks;
  141. // User modes, only used internally
  142. private $mode_la, $mode_lb, $mode_lc, $mode_ld, $mode_le, $mode_lf, $mode_lg, $mode_lh, $mode_li, $mode_lj, $mode_lk, $mode_ll, $mode_lm, $mode_ln, $mode_lo, $mode_lp, $mode_lq, $mode_lr, $mode_ls, $mode_lt, $mode_lu, $mode_lv, $mode_lw, $mode_lx, $mode_ly, $mode_lz;
  143. private $mode_ua, $mode_ub, $mode_uc, $mode_ud, $mode_ue, $mode_uf, $mode_ug, $mode_uh, $mode_ui, $mode_uj, $mode_uk, $mode_ul, $mode_um, $mode_un, $mode_uo, $mode_up, $mode_uq, $mode_ur, $mode_us, $mode_ut, $mode_uu, $mode_uv, $mode_uw, $mode_ux, $mode_uy, $mode_uz;
  144. private $mode_lf_data, $mode_lj_data, $mode_lk_data, $mode_ll_data, $mode_ul_data, $mode_uf_data, $mode_uj_data;
  145. // Filled by the constructor
  146. public $modes;
  147. private $modes_data;
  148. public $DT_RowId;
  149. function __construct() {
  150. $this->DT_RowId = $this->channel;
  151. $this->topic_html = $this->topic ? Magirc::irc2html($this->topic) : null;
  152. $this->topic = htmlentities($this->topic, ENT_COMPAT, "UTF-8");
  153. $this->users_max_time = date('Y-m-d H:i:s', $this->users_max_time);
  154. // Channel modes
  155. for ($j = 97; $j <= 122; $j++) {
  156. $mode_l = 'mode_l'.chr($j);
  157. $mode_u = 'mode_u'.chr($j);
  158. if (isset($this->$mode_l)) {
  159. if ($this->$mode_l == "Y") {
  160. $this->$mode_l = true;
  161. $this->modes .= chr($j);
  162. } else {
  163. $this->$mode_l = false;
  164. }
  165. }
  166. if (isset($this->$mode_u)) {
  167. if ($this->$mode_u == "Y") {
  168. $this->$mode_u = true;
  169. $this->modes .= chr($j - 32);
  170. } else {
  171. $this->$mode_u = false;
  172. }
  173. }
  174. }
  175. // Channel mode data
  176. if ($this->mode_lf_data) $this->modes_data .= " " . $this->mode_lf_data;
  177. if ($this->mode_lj_data) $this->modes_data .= " " . $this->mode_lj_data;
  178. if ($this->mode_lk_data) $this->modes_data .= " " . $this->mode_lk_data;
  179. if ($this->mode_ll_data) $this->modes_data .= " " . $this->mode_ll_data;
  180. if ($this->mode_uf_data) $this->modes_data .= " " . $this->mode_uf_data;
  181. if ($this->mode_uj_data) $this->modes_data .= " " . $this->mode_uj_data;
  182. if ($this->mode_ul_data) $this->modes_data .= " " . $this->mode_ul_data;
  183. }
  184. }
  185. ?>