PageRenderTime 68ms CodeModel.GetById 30ms RepoModel.GetById 0ms app.codeStats 0ms

/drupal/sites/all/modules/phpbbforum/includes/phpbbvbridge/PhpbbVBridgeApp.php

https://github.com/michaelmcandrew/spr
PHP | 1210 lines | 714 code | 224 blank | 272 comment | 144 complexity | b3201b2ffd9deb7e5b2117dd4b3e8430 MD5 | raw file
  1. <?php
  2. // $Id: PhpbbVBridgeApp.php,v 1.6 2009/05/18 18:13:31 vb Exp $
  3. /*
  4. * PhpbbVBridgeApp
  5. */
  6. require_once(dirname(__FILE__) .'/VBridge/VBridgeApp.php');
  7. require_once(dirname(__FILE__) .'/PhpbbVBridgeException.php');
  8. class PhpbbVBridgeApp extends VBridgeApp
  9. {
  10. //static private $_app;
  11. public function __construct($id, $bridgeData, $appData, $appDataConfig = array())
  12. {
  13. //if (VBRIDGE_DEBUG)
  14. //drupal_set_message(__CLASS__ .'::'.__METHOD__);
  15. parent::__construct($id, $bridgeData, $appData, $appDataConfig);
  16. }
  17. public function __destruct()
  18. {
  19. parent::__destruct();
  20. }
  21. private function __clone()
  22. {
  23. }
  24. protected function createObj($path, $objclass, $subclass = '')
  25. {
  26. $ok = parent::createObj($path, $objclass, $subclass);
  27. return $ok;
  28. }
  29. protected function create()
  30. {
  31. //if (VBRIDGE_DEBUG)
  32. //drupal_set_message(__CLASS__ .'::'.__METHOD__);
  33. parent::create();
  34. return true;
  35. }
  36. public function init($options = array())
  37. {
  38. return true;
  39. }
  40. public function run()
  41. {
  42. }
  43. /*
  44. public function notify($obj, $observable, $type, $event, $val) {
  45. if ($obj instanceof VBridge) {
  46. if (VBRIDGE_DEBUG)
  47. drupal_set_message(__CLASS__ .'::'.__METHOD__. ' type='. $type. 'event='. $event. 'val='. $val);
  48. }
  49. }
  50. */
  51. public function authenticateUserExternal()
  52. {
  53. //$authenticated = authenticate();
  54. }
  55. public function authenticateUser()
  56. {
  57. global $phpbb_user;
  58. global $db, $user, $template, $auth, $config;
  59. if ($this->getStatus())
  60. return false;
  61. phpbb_save();
  62. // Start session management
  63. $user->session_begin();
  64. $auth->acl($user->data);
  65. $user->setup();
  66. $phpbb_user->data['is_registered'] = $user->data['is_registered'];
  67. $phpbb_user->data['is_bot'] = $user->data['is_bot'];
  68. phpbb_load();
  69. return ($phpbb_user->data['user_id'] != ANONYMOUS);
  70. }
  71. public function getAppUser($id, $password = '')
  72. {
  73. if (empty($id))
  74. return false;
  75. $email = $id;
  76. $username = $id;
  77. $username_clean = utf8_clean_string($username);
  78. // authentication
  79. $authenticated = $this->authenticateUser();
  80. //$user = $this->getUser();
  81. /*
  82. if ($authenticated &&
  83. ( ($username == $user->getUserName() || $email == $user->getUserEmail()) )
  84. ) {
  85. return true;
  86. }
  87. */
  88. global $phpbb_config, $phpbb_user;
  89. // authentication!
  90. if ($authenticated &&
  91. !empty($username) && $username_clean == utf8_clean_string($phpbb_user->data['username'])) {
  92. $phpbb_config['user'] = array(
  93. 'status' => LOGIN_SUCCESS,
  94. 'error_msg' => false,
  95. );
  96. return true;
  97. }
  98. if (empty($username))
  99. return false;
  100. global $db, $config;
  101. $sql = 'SELECT *
  102. FROM ' . USERS_TABLE . "
  103. WHERE username_clean = '" . $db->sql_escape($username_clean) . "'";
  104. $result = $db->sql_query($sql);
  105. $row = $db->sql_fetchrow($result);
  106. $db->sql_freeresult($result);
  107. if (!$row)
  108. {
  109. $phpbb_config['user'] = array(
  110. 'status' => LOGIN_ERROR_USERNAME,
  111. 'error_msg' => 'LOGIN_ERROR_USERNAME',
  112. 'user_row' => array('user_id' => ANONYMOUS),
  113. );
  114. $phpbb_user->data['user_id'] = ANONYMOUS;
  115. return false;
  116. }
  117. // Check password ...
  118. if (!empty($password)) {
  119. if (/*!$row['user_pass_convert'] &&*/ phpbb_check_hash($password, $row['user_password'])/*md5($password) == $row['user_password']*/)
  120. {
  121. // Check for old password hash...
  122. /*
  123. if (strlen($row['user_password']) == 32)
  124. {
  125. $hash = phpbb_hash($password);
  126. // Update the password in the users table to the new format
  127. $sql = 'UPDATE ' . USERS_TABLE . "
  128. SET user_password = '" . $db->sql_escape($hash) . "',
  129. user_pass_convert = 0
  130. WHERE user_id = {$row['user_id']}";
  131. $db->sql_query($sql);
  132. $row['user_password'] = $hash;
  133. }
  134. */
  135. /*
  136. if ($row['user_login_attempts'] != 0)
  137. {
  138. // Successful, reset login attempts (the user passed all stages)
  139. $sql = 'UPDATE ' . USERS_TABLE . '
  140. SET user_login_attempts = 0
  141. WHERE user_id = ' . $row['user_id'];
  142. $db->sql_query($sql);
  143. }
  144. */
  145. // User inactive...
  146. if ($row['user_type'] == USER_INACTIVE || $row['user_type'] == USER_IGNORE)
  147. {
  148. $phpbb_config['user'] = array(
  149. 'status' => LOGIN_ERROR_ACTIVE,
  150. 'error_msg' => 'ACTIVE_ERROR',
  151. 'user_row' => $row,
  152. );
  153. }
  154. else {
  155. // Successful login... set user_login_attempts to zero...
  156. $phpbb_config['user'] = array(
  157. 'status' => LOGIN_SUCCESS,
  158. 'error_msg' => false,
  159. 'user_row' => $row,
  160. );
  161. }
  162. $phpbb_user->data = $row;
  163. }
  164. else {
  165. // Give status about wrong password...
  166. $phpbb_config['user'] = array(
  167. 'status' => LOGIN_ERROR_PASSWORD,
  168. 'error_msg' => 'LOGIN_ERROR_PASSWORD',
  169. 'user_row' => $row,
  170. );
  171. /*
  172. // Password incorrect - increase login attempts
  173. $sql = 'UPDATE ' . USERS_TABLE . '
  174. SET user_login_attempts = user_login_attempts + 1
  175. WHERE user_id = ' . $row['user_id'];
  176. $db->sql_query($sql);
  177. */
  178. $phpbb_user->data = $row;
  179. return false;
  180. }
  181. }
  182. else {
  183. $phpbb_config['user'] = array(
  184. 'status' => LOGIN_ERROR_ACTIVE,
  185. 'error_msg' => 'ACTIVE_ERROR',
  186. 'user_row' => $row,
  187. );
  188. $phpbb_user->data = $row;
  189. $phpbb_user->data['user_password'] = "";
  190. }
  191. /*
  192. $found = $this->loadUserByUserName($username, $password);
  193. if (!$found) {
  194. $found = $this->loadUserByEmail($email, $password);
  195. if (!$found) {
  196. $user->clear();
  197. return false;
  198. }
  199. }
  200. if (!empty($password)) {
  201. $valid = $user->validatePassword($password);
  202. if (!$valid) {
  203. $user->setPassword('')
  204. ->setPasswordSalt('');
  205. return false;
  206. }
  207. } else {
  208. $user->setPassword('')
  209. ->setPasswordSalt('');
  210. }
  211. $user->setGuest(true);
  212. */
  213. return true;
  214. }
  215. public function authenticate(&$id, &$password)
  216. {
  217. }
  218. public function loadUser($id, $password = '')
  219. {
  220. if ($this->getStatus())
  221. return false;
  222. if (empty($id))
  223. return false;
  224. if (!is_integer($id)) {
  225. $email = $id;
  226. $username = $id;
  227. }
  228. else {
  229. $email = '';
  230. }
  231. return $this->getUser();
  232. }
  233. public function saveUser()
  234. {
  235. }
  236. public function login($username = '', $password = '', $options = array())
  237. {
  238. global $phpbb_connection, $phpbb_config, $user;
  239. global $db, $user, $template, $auth, $phpEx, $phpbb_root_path, $config;
  240. if ($this->getStatus())
  241. return false;
  242. phpbb_save();
  243. $err = '';
  244. $autologin = true;
  245. $viewonline = 1;
  246. $admin = false;
  247. // Make sure user->setup() has been called
  248. if (empty($user->lang))
  249. {
  250. $user->setup();
  251. }
  252. // Print out error if user tries to authenticate as an administrator without having the privileges...
  253. if ($admin && !$auth->acl_get('a_'))
  254. {
  255. // Not authd
  256. // anonymous/inactive users are never able to go to the ACP even if they have the relevant permissions
  257. if ($user->data['is_registered'])
  258. {
  259. add_log('admin', 'LOG_ADMIN_AUTH_FAIL');
  260. }
  261. //trigger_error('NO_AUTH_ADMIN');
  262. phpbb_load();
  263. return false;
  264. }
  265. if (!empty($username) && !empty($password))
  266. {
  267. $viewonline = (!$viewonline) ? 0 : 1;
  268. $admin = ($admin) ? 1 : 0;
  269. $viewonline = ($admin) ? $user->data['session_viewonline'] : $viewonline;
  270. // Check if the supplied username is equal to the one stored within the database if re-authenticating
  271. if ($admin && utf8_clean_string($username) != utf8_clean_string($user->data['username']))
  272. {
  273. // We log the attempt to use a different username...
  274. add_log('admin', 'LOG_ADMIN_AUTH_FAIL');
  275. //trigger_error('NO_AUTH_ADMIN_USER_DIFFER');
  276. phpbb_load();
  277. return false;
  278. }
  279. // do not allow empty password
  280. //if (!$password)
  281. //{
  282. // trigger_error('NO_PASSWORD_SUPPLIED');
  283. //}
  284. $result = $auth->login($username, $password, $autologin, $viewonline, $admin);
  285. // If admin authentication and login, we will log if it was a success or not...
  286. // We also break the operation on the first non-success login - it could be argued that the user already knows
  287. if ($admin)
  288. {
  289. if ($result['status'] == LOGIN_SUCCESS)
  290. {
  291. add_log('admin', 'LOG_ADMIN_AUTH_SUCCESS');
  292. }
  293. else
  294. {
  295. // Only log the failed attempt if a real user tried to.
  296. // anonymous/inactive users are never able to go to the ACP even if they have the relevant permissions
  297. if ($user->data['is_registered'])
  298. {
  299. add_log('admin', 'LOG_ADMIN_AUTH_FAIL');
  300. }
  301. }
  302. }
  303. // Special cases... determine
  304. switch ($result['status'])
  305. {
  306. case LOGIN_SUCCESS:
  307. // Special case... the user is effectively banned, but we allow founders to login
  308. //if (defined('IN_CHECK_BAN') && $result['user_row']['user_type'] != USER_FOUNDER)
  309. //{
  310. //}
  311. break;
  312. case LOGIN_ERROR_ATTEMPTS:
  313. /*
  314. // Show confirm image
  315. $sql = 'DELETE FROM ' . CONFIRM_TABLE . "
  316. WHERE session_id = '" . $db->sql_escape($user->session_id) . "'
  317. AND confirm_type = " . CONFIRM_LOGIN;
  318. $db->sql_query($sql);
  319. // Generate code
  320. $code = gen_rand_string(mt_rand(5, 8));
  321. $confirm_id = md5(unique_id($user->ip));
  322. $seed = hexdec(substr(unique_id(), 4, 10));
  323. // compute $seed % 0x7fffffff
  324. $seed -= 0x7fffffff * floor($seed / 0x7fffffff);
  325. $sql = 'INSERT INTO ' . CONFIRM_TABLE . ' ' . $db->sql_build_array('INSERT', array(
  326. 'confirm_id' => (string) $confirm_id,
  327. 'session_id' => (string) $user->session_id,
  328. 'confirm_type' => (int) CONFIRM_LOGIN,
  329. 'code' => (string) $code,
  330. 'seed' => (int) $seed)
  331. );
  332. $db->sql_query($sql);
  333. $template->assign_vars(array(
  334. 'S_CONFIRM_CODE' => true,
  335. 'CONFIRM_ID' => $confirm_id,
  336. 'CONFIRM_IMAGE' => '<img src="' . append_sid("{$phpbb_root_path}ucp.$phpEx", 'mode=confirm&amp;id=' . $confirm_id . '&amp;type=' . CONFIRM_LOGIN) . '" alt="" title="" />',
  337. 'L_LOGIN_CONFIRM_EXPLAIN' => sprintf($user->lang['LOGIN_CONFIRM_EXPLAIN'], '<a href="mailto:' . htmlspecialchars($config['board_contact']) . '">', '</a>'),
  338. ));
  339. */
  340. $err = $user->lang[$result['error_msg']];
  341. break;
  342. case LOGIN_ERROR_PASSWORD_CONVERT:
  343. $err = sprintf(
  344. $user->lang[$result['error_msg']],
  345. ($config['email_enable']) ? '<a href="' . append_sid("{$phpbb_root_path}ucp.$phpEx", 'mode=sendpassword') . '">' : '',
  346. ($config['email_enable']) ? '</a>' : '',
  347. ($config['board_contact']) ? '<a href="mailto:' . htmlspecialchars($config['board_contact']) . '">' : '',
  348. ($config['board_contact']) ? '</a>' : ''
  349. );
  350. break;
  351. case LOGIN_BREAK:
  352. //trigger_error($result['error_msg'], E_USER_ERROR);
  353. phpbb_load();
  354. return false;
  355. //break;
  356. // Username, password, etc...
  357. default:
  358. $err = $user->lang[$result['error_msg']];
  359. // Assign admin contact to some error messages
  360. if ($result['error_msg'] == 'LOGIN_ERROR_USERNAME' || $result['error_msg'] == 'LOGIN_ERROR_PASSWORD')
  361. {
  362. $err = (!$config['board_contact']) ? sprintf($user->lang[$result['error_msg']], '', '') : sprintf($user->lang[$result['error_msg']], '<a href="mailto:' . htmlspecialchars($config['board_contact']) . '">', '</a>');
  363. }
  364. break;
  365. }
  366. }
  367. else {
  368. $result = array(
  369. 'status' => LOGIN_ERROR_USERNAME,
  370. 'error_msg' => 'LOGIN_ERROR_USERNAME',
  371. 'user_row' => array('user_id' => ANONYMOUS),
  372. );
  373. $phpbb_user->data['user_id'] = ANONYMOUS;
  374. }
  375. $phpbb_config['user'] = $result;
  376. $phpbb_config['error_msg'] = $err;
  377. phpbb_load();
  378. return ($result['status'] == LOGIN_SUCCESS);
  379. }
  380. public function logout()
  381. {
  382. global $phpbb_config, $user, $auth;
  383. if ($this->getStatus())
  384. return false;
  385. phpbb_save();
  386. if ($user->data['user_id'] != ANONYMOUS)
  387. {
  388. $user->session_kill();
  389. $user->session_begin();
  390. $auth->acl($user->data);
  391. $user->setup();
  392. }
  393. phpbb_load();
  394. }
  395. public function deleteUser($id, $mode = 'retain', $post_username = false)
  396. {
  397. global $phpbb_config, $user;
  398. $return = false;
  399. if ($this->getStatus() || !$id)
  400. return $return;
  401. phpbb_save();
  402. if ($user->data['user_id'] != ANONYMOUS && $user->data['user_id'] != 2 && !$user->data['is_bot'] && $user->data['user_type'] != USER_IGNORE)
  403. {
  404. $return = phpbb_user_delete($mode, $id, $post_username);
  405. }
  406. phpbb_load();
  407. return $return;
  408. }
  409. public function registerUser($username, $password, $email, $data = array())
  410. {
  411. global $phpbb_config, $phpbb_user;
  412. if ($this->getStatus())
  413. return false;
  414. if (empty($username) || empty($password) || empty($email) || strlen($username) > 128) {
  415. $phpbb_config['error_msg'] = "bad username";
  416. return false;
  417. }
  418. $email = strtolower($email);
  419. $username = utf8_normalize_nfc($username);
  420. phpbb_save();
  421. $rc = phpbb_register($username, $password, $email, $data);
  422. phpbb_load();
  423. return $rc;
  424. }
  425. public function updateUser($id, $username = '', $password = '', $email = '', $data = array())
  426. {
  427. global $phpbb_config, $phpbb_user;
  428. $rc = false;
  429. if ($this->getStatus() ||
  430. empty($id) || empty($phpbb_user->data['user_id']) ||
  431. $id == ANONYMOUS || $phpbb_user->data['is_bot'])
  432. return $rc;
  433. if (!empty($username))
  434. {
  435. $username = utf8_normalize_nfc($username);
  436. if (isset($data['username']))
  437. $data['username'] = $username;
  438. else
  439. $data += array('username' => $username);
  440. }
  441. if (!empty($password))
  442. {
  443. //$password = md5($password);
  444. if (isset($data['user_password']))
  445. $data['user_password'] = $password;
  446. else
  447. $data += array('user_password' => $password);
  448. }
  449. if (!empty($email))
  450. {
  451. $email = strtolower($email);
  452. if (isset($data['user_email']))
  453. $data['user_email'] = $email;
  454. elseif ($phpbb_user->data['user_email'] != $email)
  455. $data += array('user_email' => $email);
  456. }
  457. if (!empty($data))
  458. {
  459. phpbb_save();
  460. $rc = phpbb_update_user_data($id, $data);
  461. phpbb_load();
  462. }
  463. return $rc;
  464. }
  465. public function getRecentPosts($options = array('output_method' => ''))
  466. {
  467. $str = '';
  468. if ($this->getStatus())
  469. return $str;
  470. //$this->authenticateUser();
  471. global $phpbb_config, $phpbb_user;
  472. //require_once(dirname(__FILE__) . '/phpbb_api_recent.php');
  473. // Get options
  474. extract($options, EXTR_SKIP);
  475. if ($num_recent < 0)
  476. $num_recent = 0;
  477. $show_results = 'posts';
  478. //$search_id = 'unanswered';
  479. //$search_id = 'egosearch';
  480. // $search_id = 'newposts';
  481. $topic_id = 0;
  482. $post_id = 0;
  483. // Call App function
  484. $posts = phpbb_api_search($num_recent, $show_results, $search_id, $topic_id, $post_id, $sort_days);
  485. if ($output_method == 'array') {
  486. return $posts;
  487. }
  488. return theme_phpbb_api_recent_posts($posts, $options);
  489. }
  490. public function getRecentTopics($options = array('output_method' => ''))
  491. {
  492. $str = '';
  493. if ($this->getStatus())
  494. return $str;
  495. //$this->authenticateUser();
  496. global $phpbb_config, $phpbb_user;
  497. // Get options
  498. extract($options, EXTR_SKIP);
  499. if ($num_recent < 0)
  500. $num_recent = 0;
  501. $show_results = 'topics';
  502. //$search_id = 'unanswered';
  503. // $search_id = 'active_topics';
  504. //$search_id = 'newposts';
  505. $topic_id = 0;
  506. $post_id = 0;
  507. // Call App function
  508. $posts = phpbb_api_search($num_recent, $show_results, $search_id, $topic_id, $post_id, $sort_days);
  509. if ($output_method == 'array') {
  510. return $posts;
  511. }
  512. return theme_phpbb_api_recent_topics($posts, $options);
  513. }
  514. public function getTopPosters($options = array('output_method' => ''))
  515. {
  516. $strreturn = '';
  517. if ($this->getStatus())
  518. return $strreturn;
  519. //$this->authenticateUser();
  520. global $phpbb_config, $phpbb_user;
  521. global $db, $config, $template, $user, $auth, $phpEx, $phpbb_root_path;
  522. // Get options
  523. extract($options, EXTR_SKIP);
  524. if ($num_top <= 0)
  525. $num_top = 1;
  526. phpbb_save();
  527. // Start session management
  528. $user->session_begin();
  529. $auth->acl($user->data);
  530. $user->setup();
  531. $phpbb_url = $phpbb_config['forum_url'];
  532. // Find the latest poster.
  533. $sql = 'SELECT user_id, username, user_posts, user_colour
  534. FROM ' . USERS_TABLE . '
  535. WHERE user_type <> 2
  536. AND user_posts <> 0
  537. ORDER BY user_posts DESC';
  538. $result = $db->sql_query_limit($sql, $num_top);
  539. if ($result === false) {
  540. phpbb_load();
  541. return $strreturn;
  542. }
  543. $posters = array();
  544. while( ($row = $db->sql_fetchrow($result)) && ($row['username'] != '') )
  545. {
  546. $posters[] = array(
  547. 'user_id' => $row['user_id'],
  548. //'S_SEARCH_ACTION'=> append_sid("{$phpbb_url}/search.$phpEx", 'author_id=' . $row['user_id'] . '&amp;sr=posts'),
  549. 'username' => $row['username'], //censor_text($row['username']),
  550. 'USERNAME_COLOR'=> ($row['user_colour']) ? ' style="color:#' . $row['user_colour'] .'"' : '',
  551. //'U_USERNAME' => append_sid("{$phpbb_url}/memberlist.$phpEx", 'mode=viewprofile&amp;u=' . $row['user_id']),
  552. 'link' => '<a href="' . append_sid("{$phpbb_url}/memberlist.$phpEx", 'mode=viewprofile&amp;u=' . $row['user_id']) . '">' . $row['username'] . '</a>',
  553. 'user_posts' => $row['user_posts'],
  554. );
  555. }
  556. $db->sql_freeresult($result);
  557. phpbb_load();
  558. if ($output_method == 'array') {
  559. return $posters;
  560. }
  561. // Call App function
  562. return theme_phpbb_api_topposter($posters, $options);
  563. }
  564. public function getPersonalMessages($options = array('output_method' => ''))
  565. {
  566. $strreturn = '';
  567. if ($this->getStatus())
  568. return $strreturn;
  569. global $phpbb_connection, $phpbb_config, $phpbb_user, $phpbb_func, $phpbb_txt;
  570. global $db, $config, $template, $SID, $_SID, $user, $auth, $phpEx, $phpbb_root_path;
  571. extract($options, EXTR_SKIP);
  572. phpbb_save();
  573. // Start session management
  574. $user->session_begin();
  575. $auth->acl($user->data);
  576. $user->setup();
  577. // Generate logged in/logged out status
  578. if ($user->data['user_id'] == ANONYMOUS || !isset($user->data['is_registered']) || !$user->data['is_registered']) {
  579. phpbb_load();
  580. return $strreturn;
  581. }
  582. $phpbb_url = $phpbb_config['forum_url'];
  583. //include_once($phpbb_root_path . 'includes/functions_display.' . $phpEx);
  584. $l_privmsgs_text = $l_privmsgs_text_unread = $l_message_unread = '';
  585. $s_privmsg_new = false;
  586. // Obtain number of new private messages if user is logged in
  587. if ($user->data['user_new_privmsg'])
  588. {
  589. $l_message_new = ($user->data['user_new_privmsg'] == 1) ? $user->lang['NEW_PM'] : $user->lang['NEW_PMS'];
  590. $l_privmsgs_text = sprintf($l_message_new, $user->data['user_new_privmsg']);
  591. if (!$user->data['user_last_privmsg'] || $user->data['user_last_privmsg'] > $user->data['session_last_visit'])
  592. {
  593. $sql = 'UPDATE ' . USERS_TABLE . '
  594. SET user_last_privmsg = ' . $user->data['session_last_visit'] . '
  595. WHERE user_id = ' . $user->data['user_id'];
  596. $db->sql_query($sql);
  597. $s_privmsg_new = true;
  598. }
  599. else
  600. {
  601. $s_privmsg_new = false;
  602. }
  603. }
  604. else
  605. {
  606. $l_privmsgs_text = $user->lang['NO_NEW_PM'];
  607. $s_privmsg_new = false;
  608. }
  609. if ($user->data['user_unread_privmsg'] && $user->data['user_unread_privmsg'] != $user->data['user_new_privmsg'])
  610. {
  611. $l_message_unread = ($user->data['user_unread_privmsg'] == 1) ? $user->lang['UNREAD_PM'] : $user->lang['UNREAD_PMS'];
  612. $l_privmsgs_text_unread = sprintf($l_message_unread, $user->data['user_unread_privmsg']);
  613. }
  614. phpbb_load();
  615. $output['l_privmsgs_text'] = $l_privmsgs_text;
  616. $output['s_privmsg_new'] = $s_privmsg_new;
  617. $output['l_privmsgs_text_unread'] = $l_privmsgs_text_unread;
  618. $output['l_message_unread'] = $l_message_unread;
  619. if ($output_method == 'array') {
  620. return $output;
  621. }
  622. return theme_phpbb_api_pm($output, $options);
  623. }
  624. public function getWhosOnline($options = array('output_method' => ''))
  625. {
  626. $strreturn = '';
  627. if ($this->getStatus())
  628. return $strreturn;
  629. //$this->authenticateUser();
  630. global $phpbb_config, $phpbb_user;
  631. global $db, $config, $template, $SID, $_SID, $user, $auth, $phpEx, $phpbb_root_path;
  632. extract($options, EXTR_SKIP);
  633. if ($num_top <= 0)
  634. $num_top = 9999;
  635. phpbb_save();
  636. $phpbb_url = $phpbb_config['forum_url'];
  637. // Start session management
  638. $user->session_begin();
  639. $auth->acl($user->data);
  640. $user->setup();
  641. /*
  642. // Generate logged in/logged out status
  643. if ($user->data['user_id'] != ANONYMOUS)
  644. {
  645. $u_login_logout = append_sid("{$phpbb_root_path}ucp.$phpEx", 'mode=logout', true, $user->session_id);
  646. $l_login_logout = sprintf($user->lang['LOGOUT_USER'], $user->data['username']);
  647. }
  648. else
  649. {
  650. $u_login_logout = append_sid("{$phpbb_root_path}ucp.$phpEx", 'mode=login');
  651. $l_login_logout = $user->lang['LOGIN'];
  652. }
  653. // Last visit date/time
  654. $s_last_visit = ($user->data['user_id'] != ANONYMOUS) ? $user->format_date($user->data['session_last_visit']) : '';
  655. */
  656. // Get users online list ... if required
  657. $l_online_users = $online_userlist = $l_online_record = '';
  658. if ($config['load_online'] && $config['load_online_time']/* && $display_online_list*/)
  659. {
  660. $logged_visible_online = $logged_hidden_online = $guests_online = $prev_user_id = 0;
  661. $prev_session_ip = $reading_sql = '';
  662. $f = 0;
  663. /*
  664. if (!empty($_REQUEST['f']))
  665. {
  666. $f = request_var('f', 0);
  667. //$f = 0;
  668. $reading_sql = ' AND s.session_page ' . $db->sql_like_expression("{$db->any_char}_f_={$f}x{$db->any_char}");
  669. }
  670. */
  671. // Get number of online guests
  672. if (!$config['load_online_guests'])
  673. {
  674. if ($db->sql_layer === 'sqlite')
  675. {
  676. $sql = 'SELECT COUNT(session_ip) as num_guests
  677. FROM (
  678. SELECT DISTINCT s.session_ip
  679. FROM ' . SESSIONS_TABLE . ' s
  680. WHERE s.session_user_id = ' . ANONYMOUS . '
  681. AND s.session_time >= ' . (time() - ($config['load_online_time'] * 60)) .
  682. $reading_sql .
  683. ')';
  684. }
  685. else
  686. {
  687. $sql = 'SELECT COUNT(DISTINCT s.session_ip) as num_guests
  688. FROM ' . SESSIONS_TABLE . ' s
  689. WHERE s.session_user_id = ' . ANONYMOUS . '
  690. AND s.session_time >= ' . (time() - ($config['load_online_time'] * 60)) .
  691. $reading_sql;
  692. }
  693. $result = $db->sql_query($sql);
  694. $guests_online = (int) $db->sql_fetchfield('num_guests');
  695. $db->sql_freeresult($result);
  696. }
  697. $sql = 'SELECT u.username, u.username_clean, u.user_id, u.user_type, u.user_allow_viewonline, u.user_colour, s.session_ip, s.session_viewonline
  698. FROM ' . USERS_TABLE . ' u, ' . SESSIONS_TABLE . ' s
  699. WHERE s.session_time >= ' . (time() - (intval($config['load_online_time']) * 60)) .
  700. $reading_sql .
  701. ((!$config['load_online_guests']) ? ' AND s.session_user_id <> ' . ANONYMOUS : '') . '
  702. AND u.user_id = s.session_user_id
  703. ORDER BY u.username_clean ASC, s.session_ip ASC';
  704. //$result = $db->sql_query($sql);
  705. $result = $db->sql_query_limit($sql, $num_top);
  706. while ($row = $db->sql_fetchrow($result))
  707. {
  708. // User is logged in and therefore not a guest
  709. if ($row['user_id'] != ANONYMOUS)
  710. {
  711. // Skip multiple sessions for one user
  712. if ($row['user_id'] != $prev_user_id)
  713. {
  714. if ($row['user_colour'])
  715. {
  716. $user_colour = ' style="color:#' . $row['user_colour'] . '"';
  717. $row['username'] = '<strong>' . $row['username'] . '</strong>';
  718. }
  719. else
  720. {
  721. $user_colour = '';
  722. }
  723. if ($row['session_viewonline'])
  724. {
  725. $user_online_link = $row['username'];
  726. $logged_visible_online++;
  727. }
  728. else
  729. {
  730. $user_online_link = '<em>' . $row['username'] . '</em>';
  731. $logged_hidden_online++;
  732. }
  733. if (($row['session_viewonline']) || $auth->acl_get('u_viewonline'))
  734. {
  735. if ($row['user_type'] <> USER_IGNORE)
  736. {
  737. $user_online_link = '<a href="' . append_sid("{$phpbb_url}/memberlist.$phpEx", 'mode=viewprofile&amp;u=' . $row['user_id']) . '"' . $user_colour . '>' . $user_online_link . '</a>';
  738. }
  739. else
  740. {
  741. $user_online_link = ($user_colour) ? '<span' . $user_colour . '>' . $user_online_link . '</span>' : $user_online_link;
  742. }
  743. $online_userlist .= ($online_userlist != '') ? ', ' . $user_online_link : $user_online_link;
  744. }
  745. }
  746. $prev_user_id = $row['user_id'];
  747. }
  748. else
  749. {
  750. // Skip multiple sessions for one user
  751. if ($row['session_ip'] != $prev_session_ip)
  752. {
  753. $guests_online++;
  754. }
  755. }
  756. $prev_session_ip = $row['session_ip'];
  757. }
  758. $db->sql_freeresult($result);
  759. if (!$online_userlist)
  760. {
  761. $online_userlist = $user->lang['NO_ONLINE_USERS'];
  762. }
  763. //if (empty($_REQUEST['f']))
  764. //if (empty($f))
  765. //{
  766. $online_userlist = $user->lang['REGISTERED_USERS'] . ' ' . $online_userlist;
  767. //}
  768. //else
  769. //{
  770. //$l_online = ($guests_online == 1) ? $user->lang['BROWSING_FORUM_GUEST'] : $user->lang['BROWSING_FORUM_GUESTS'];
  771. //$online_userlist = sprintf($l_online, $online_userlist, $guests_online);
  772. //}
  773. $total_online_users = $logged_visible_online + $logged_hidden_online + $guests_online;
  774. /*
  775. if ($total_online_users > $config['record_online_users'])
  776. {
  777. set_config('record_online_users', $total_online_users, true);
  778. set_config('record_online_date', time(), true);
  779. }
  780. */
  781. // Build online listing
  782. $vars_online = array(
  783. 'ONLINE' => array('total_online_users', 'l_t_user_s'),
  784. 'REG' => array('logged_visible_online', 'l_r_user_s'),
  785. 'HIDDEN' => array('logged_hidden_online', 'l_h_user_s'),
  786. 'GUEST' => array('guests_online', 'l_g_user_s')
  787. );
  788. foreach ($vars_online as $l_prefix => $var_ary)
  789. {
  790. $l_suffix = '';
  791. if ($l_prefix == 'HIDDEN')
  792. {
  793. $l_suffix = '_AND';
  794. }
  795. switch (${$var_ary[0]})
  796. {
  797. case 0:
  798. ${$var_ary[1]} = $user->lang[$l_prefix . '_USERS_ZERO_TOTAL' . $l_suffix];
  799. break;
  800. case 1:
  801. ${$var_ary[1]} = $user->lang[$l_prefix . '_USER_TOTAL' . $l_suffix];
  802. break;
  803. default:
  804. ${$var_ary[1]} = $user->lang[$l_prefix . '_USERS_TOTAL' . $l_suffix];
  805. break;
  806. }
  807. }
  808. unset($vars_online);
  809. $l_online_users = sprintf($l_t_user_s, $total_online_users);
  810. $l_online_users .= sprintf($l_r_user_s, $logged_visible_online);
  811. $l_online_users .= sprintf($l_h_user_s, $logged_hidden_online);
  812. $l_online_users .= sprintf($l_g_user_s, $guests_online);
  813. $l_online_record = sprintf($user->lang['RECORD_ONLINE_USERS'], $config['record_online_users'], $user->format_date($config['record_online_date']));
  814. $l_online_time = ($config['load_online_time'] == 1) ? 'VIEW_ONLINE_TIME' : 'VIEW_ONLINE_TIMES';
  815. $l_online_time = sprintf($user->lang[$l_online_time], $config['load_online_time']);
  816. }
  817. else
  818. {
  819. $l_online_time = '';
  820. }
  821. phpbb_load();
  822. $output['l_online_users'] = $l_online_users;
  823. $output['online_userlist'] = $online_userlist;
  824. if ($output_method == 'array') {
  825. return $output;
  826. }
  827. return theme_phpbb_api_whos_online($output, $options);
  828. }
  829. public function getStatistics($options = array('output_method' => ''))
  830. {
  831. $strreturn = '';
  832. if ($this->getStatus())
  833. return $strreturn;
  834. global $phpbb_config, $phpbb_user, $phpbb_func, $phpbb_txt;
  835. global $db, $config, $template, $SID, $_SID, $user, $auth, $phpEx, $phpbb_root_path;
  836. extract($options, EXTR_SKIP);
  837. phpbb_save();
  838. //$this->authenticateUser();
  839. // Start session management
  840. $user->session_begin();
  841. $auth->acl($user->data);
  842. $user->setup();
  843. // Generate logged in/logged out status
  844. /*
  845. if ($user->data['user_id'] == ANONYMOUS) {
  846. phpbb_load();
  847. return $strreturn;
  848. }
  849. */
  850. $phpbb_url = $phpbb_config['forum_url'];
  851. // Set some stats, get posts count from forums data if we... hum... retrieve all forums data
  852. $total_posts = $config['num_posts'];
  853. $total_topics = $config['num_topics'];
  854. $total_users = $config['num_users'];
  855. $l_total_user_s = ($total_users == 0) ? 'TOTAL_USERS_ZERO' : 'TOTAL_USERS_OTHER';
  856. $l_total_post_s = ($total_posts == 0) ? 'TOTAL_POSTS_ZERO' : 'TOTAL_POSTS_OTHER';
  857. $l_total_topic_s = ($total_topics == 0) ? 'TOTAL_TOPICS_ZERO' : 'TOTAL_TOPICS_OTHER';
  858. $total_posts = sprintf($user->lang[$l_total_post_s], $total_posts);
  859. $total_topics = sprintf($user->lang[$l_total_topic_s], $total_topics);
  860. $total_users = sprintf($user->lang[$l_total_user_s], $total_users);
  861. $newest_user = sprintf($user->lang['NEWEST_USER'], get_username_string('full', $config['newest_user_id'], $config['newest_username'], $config['newest_user_colour']));
  862. phpbb_load();
  863. $output['total_posts'] = $total_posts;
  864. $output['total_topics'] = $total_topics;
  865. $output['total_users'] = $total_users;
  866. $output['newest_user'] = $newest_user;
  867. if ($output_method == 'array') {
  868. return $output;
  869. }
  870. return theme_phpbb_api_board_stats($output, $options);
  871. }
  872. /*
  873. public function isUserOnline($id = 0)
  874. {
  875. return parent::isUserOnline($id);
  876. }
  877. public function isUserActive($id = 0)
  878. {
  879. return parent::isUserActive($id);
  880. }
  881. public function isUserBanned($id = 0)
  882. {
  883. return parent::isUserBanned($id);
  884. }
  885. public function isUserBannedEmail($id = 0)
  886. {
  887. return parent::isUserBannedEmail($id);
  888. }
  889. public function isUserRegistered($id = 0)
  890. {
  891. return parent::isUserRegistered($id);
  892. }
  893. public function isUserUserGuest($id = 0)
  894. {
  895. return parent::isUserGuest($id);
  896. }
  897. public function isUserBot($id = 0)
  898. {
  899. return parent::isUserBot($id);
  900. }
  901. */
  902. //////////////////////
  903. public function validateUserName($username)
  904. {
  905. if (empty($username))
  906. return false;
  907. global $phpbb_config, $config;
  908. phpbb_save();
  909. $check_data = array('username' => $username);
  910. $check_ary['username'] = array(
  911. array('string', false, $config['min_name_chars'], $config['max_name_chars']),
  912. array('username'),
  913. );
  914. $error = validate_data($check_data, $check_ary);
  915. phpbb_load();
  916. return !sizeof($error);
  917. }
  918. public function validateUserPassword($password, $username = '')
  919. {
  920. //drupal_set_message('pass='.$password.' status='.$this->getStatus());
  921. if ($this->getStatus() || empty($password))
  922. return false;
  923. global $phpbb_config, $config;
  924. phpbb_save();
  925. $check_data = array('user_password' => $password);
  926. $check_ary = array(
  927. 'user_password' => array(
  928. array('string', true, $config['min_pass_chars'], $config['max_pass_chars']),
  929. array('password')),
  930. );
  931. $error = validate_data($check_data, $check_ary);
  932. phpbb_load();
  933. //if (VBRIDGE_DEBUG)
  934. // drupal_set_message('pass='.$password.' error='.sizeof($error));
  935. return !sizeof($error);
  936. }
  937. public function validateUserEmail($email, $username = '')
  938. {
  939. if ($this->getStatus() || empty($email))
  940. return false;
  941. global $phpbb_config, $config;
  942. phpbb_save();
  943. $check_data = array('user_email' => $email);
  944. $check_ary = array(
  945. 'user_email' => array(
  946. array('string', false, 6, 60),
  947. array('email')),
  948. );
  949. $error = validate_data($check_data, $check_ary);
  950. phpbb_load();
  951. return !sizeof($error);
  952. }
  953. public function isValidEmail($email)
  954. {
  955. return $this->validateUserEmail($email, '');
  956. }
  957. public function isEmailInUse($email, $username = '')
  958. {
  959. if ($this->getStatus() || empty($email))
  960. return false;
  961. return false;
  962. }
  963. public function isReservedName($name)
  964. {
  965. if (!$this->getStatus() || empty($name))
  966. return true;
  967. return false;
  968. }
  969. }
  970. ?>