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

/cpg1.6.x/bridge/xmb.inc.php

https://github.com/cpg-contrib/coppermine
PHP | 271 lines | 180 code | 46 blank | 45 comment | 19 complexity | 9b4a91bafddfba95d8e3100281ee72e0 MD5 | raw file
  1. <?php
  2. /*************************
  3. Coppermine Photo Gallery
  4. ************************
  5. Copyright (c) 2003-2010 Coppermine Dev Team
  6. v1.0 originally written by Gregory Demar
  7. This program is free software; you can redistribute it and/or modify
  8. it under the terms of the GNU General Public License version 3
  9. as published by the Free Software Foundation.
  10. ********************************************
  11. Coppermine version: 1.6.01
  12. $HeadURL$
  13. $Revision$
  14. **********************************************/
  15. if (!defined('IN_COPPERMINE')) die('Not in Coppermine...');
  16. if (isset($bridge_lookup)) {
  17. $default_bridge_data[$bridge_lookup] = array(
  18. 'full_name' => 'XMB 1.9',
  19. 'short_name' => 'xmb',
  20. 'support_url' => 'http://www.xmbforum.com/',
  21. 'full_forum_url_default' => 'http://www.yoursite.com/board',
  22. 'full_forum_url_used' => 'mandatory,not_empty,no_trailing_slash',
  23. 'relative_path_to_config_file_default' => '../board/',
  24. 'relative_path_to_config_file_used' => 'lookfor,config.php',
  25. 'use_post_based_groups_default' => '0',
  26. 'use_post_based_groups_used' => 'radio,1,0',
  27. );
  28. } else {
  29. // Switch that allows overriding the bridge manager with hard-coded values
  30. define('USE_BRIDGEMGR', 1);
  31. require_once 'bridge/udb_base.inc.php';
  32. class cpg_udb extends core_udb {
  33. function cpg_udb()
  34. {
  35. global $BRIDGE;
  36. if (!USE_BRIDGEMGR) { // the vars that are used when bridgemgr is disabled
  37. // URL of your board
  38. $this->boardurl = 'http://localhost/XMB';
  39. // local path to your board's config file
  40. require_once('../XMB/config.php');
  41. $this->use_post_based_groups = 1;
  42. } else { // the vars from the bridgemgr
  43. $this->boardurl = $BRIDGE['full_forum_url'];
  44. require_once($BRIDGE['relative_path_to_config_file'] . 'config.php');
  45. $this->use_post_based_groups = $BRIDGE['use_post_based_groups'];
  46. }
  47. // multiple groups are not actually supported, but need this set due to the unusual group implementation in XMB.
  48. $this->multigroups = 1;
  49. $this->group_overrride = 1;
  50. // Database connection settings
  51. $this->db = array(
  52. 'name' => $dbname,
  53. 'host' => $dbhost,
  54. 'user' => $dbuser,
  55. 'password' => $dbpw,
  56. 'prefix' =>$tablepre
  57. );
  58. // Board table names
  59. $this->table = array(
  60. 'users' => 'members',
  61. 'groups' => 'ranks',
  62. );
  63. // Derived full table names
  64. $this->usertable = '`' . $this->db['name'] . '`.' . $this->db['prefix'] . $this->table['users'];
  65. $this->groupstable = '`' . $this->db['name'] . '`.' . $this->db['prefix'] . $this->table['groups'];
  66. // Table field names
  67. $this->field = array(
  68. 'username' => 'username', // name of 'username' field in users table
  69. 'user_id' => 'uid', // name of 'id' field in users table
  70. 'password' => 'password', // name of 'password' field in users table
  71. 'email' => 'email', // name of 'email' field in users table
  72. 'regdate' => 'regdate', // name of 'registered' field in users table
  73. 'location' => 'location', // name of 'location' field in users table
  74. 'website' => 'site', // name of 'website' field in users table
  75. 'usertbl_group_id' => 'status', // name of 'group id' field in users table
  76. 'grouptbl_group_id' => 'title', // name of 'group id' field in groups table
  77. 'grouptbl_group_name' => 'title', // name of 'group name' field in groups table
  78. );
  79. // Pages to redirect to
  80. $this->page = array(
  81. 'register' => '/register.php',
  82. 'editusers' => '/misc.php?action=list',
  83. 'edituserprofile' => '/member.php?action=viewpro&member='
  84. );
  85. // Group ids
  86. $this->admingroups = array(8,9);
  87. $this->guestgroup = 3;
  88. // Connect to db
  89. $this->connect();
  90. }
  91. function collect_groups()
  92. {
  93. $sql = "SELECT * FROM {$this->groupstable}";
  94. $result = cpg_db_query($sql, $this->link_id);
  95. // XMB has no guest group in groups table, so adding one here
  96. $udb_groups = array(3=>'Guests');
  97. while ($row = mysql_fetch_assoc($result))
  98. {
  99. $udb_groups[$row['id']+100] = utf_ucfirst(utf_strtolower($row[$this->field['grouptbl_group_name']]));
  100. }
  101. return $udb_groups;
  102. }
  103. function get_groups($row)
  104. {
  105. $id = $row['id'];
  106. $sql = "SELECT id FROM {$this->groupstable}, {$this->usertable} WHERE {$this->field['usertbl_group_id']} = {$this->field['grouptbl_group_id']} AND {$this->field['user_id']}='$id'";
  107. $result = cpg_db_query($sql, $this->link_id);
  108. if (mysql_num_rows($result)){
  109. $row = mysql_fetch_row($result);
  110. if ($this->use_post_based_groups){
  111. $row = array($row[0] + 100);
  112. } else {
  113. if (in_array($row[0], $this->admingroups)){
  114. $row = array(1);
  115. } else {
  116. $row = array(2);
  117. }
  118. }
  119. return $row;
  120. } else {
  121. return false;
  122. }
  123. }
  124. function get_users($options = array())
  125. {
  126. global $CONFIG;
  127. // Copy UDB fields and config variables (just to make it easier to read)
  128. $f =& $this->field;
  129. $C =& $CONFIG;
  130. // Sort codes
  131. $sort_codes = array('name_a' => 'user_name ASC',
  132. 'name_d' => 'user_name DESC',
  133. 'group_a' => 'group_name ASC',
  134. 'group_d' => 'group_name DESC',
  135. 'reg_a' => 'user_regdate ASC',
  136. 'reg_d' => 'user_regdate DESC',
  137. 'pic_a' => 'pic_count ASC',
  138. 'pic_d' => 'pic_count DESC',
  139. 'disku_a' => 'disk_usage ASC',
  140. 'disku_d' => 'disk_usage DESC',
  141. 'lv_a' => 'user_lastvisit ASC',
  142. 'lv_d' => 'user_lastvisit DESC',
  143. );
  144. $f['usertbl_group_id'] = 'id';
  145. // Fix the group id, if bridging is enabled
  146. if ($CONFIG['bridge_enable']) {
  147. $f['usertbl_group_id'] .= '+100';
  148. }
  149. // Build WHERE clause, if this is a username search
  150. if ($options['search']) {
  151. $options['search'] = 'WHERE u.'.$f['username'].' LIKE "'.$options['search'].'" ';
  152. }
  153. // Build SQL table, should work with all bridges
  154. $sql = "SELECT {$f['user_id']} as user_id, {$f['username']} as user_name, {$f['email']} as user_email, {$f['regdate']} as user_regdate, lastvisit as user_lastvisit, '' as user_active, ".
  155. "COUNT(pid) as pic_count, ROUND(SUM(total_filesize)/1024) as disk_usage, group_name, group_quota ".
  156. "FROM {$this->usertable} AS u ".
  157. "INNER JOIN {$this->groupstable} AS rank ON u.status = rank.title ".
  158. " INNER JOIN {$C['TABLE_USERGROUPS']} AS g ".
  159. "ON g.group_id = rank.{$f['usertbl_group_id']} LEFT JOIN {$C['TABLE_PICTURES']} AS p ON p.owner_id = u.{$f['user_id']} ".
  160. $options['search'].
  161. "GROUP BY user_id " . "ORDER BY " . $sort_codes[$options['sort']] . " ".
  162. "LIMIT {$options['lower_limit']}, {$options['users_per_page']};";
  163. $result = cpg_db_query($sql);
  164. // If no records, return empty value
  165. if (!$result) {
  166. return array();
  167. }
  168. // Extract user list to an array
  169. while ($user = mysql_fetch_assoc($result)) {
  170. $userlist[] = $user;
  171. }
  172. return $userlist;
  173. }
  174. // definition of how to extract id, name, group from a session cookie
  175. function session_extraction()
  176. {
  177. $superCage = Inspekt::makeSuperCage();
  178. //if (isset($_COOKIE['xmbpw']) && isset($_COOKIE['xmbuser'])){
  179. // return array($this->get_user_id($_COOKIE['xmbuser']), $_COOKIE['xmbpw']);
  180. if ($superCage->cookie->keyExists('xmbpw') && $superCage->cookie->keyExists('xmbuser')){
  181. return array($this->get_user_id($superCage->cookie->getRaw('xmbuser'), $superCage->cookie->getRaw('xmbpw')));
  182. } else {
  183. return false;
  184. }
  185. }
  186. // definition of how to extract an id and password hash from a cookie
  187. function cookie_extraction()
  188. {
  189. return false;
  190. }
  191. // definition of actions required to convert a password from user database form to cookie form
  192. function udb_hash_db($password)
  193. {
  194. return $password;
  195. }
  196. // Login
  197. function login_page()
  198. {
  199. $this->redirect('/misc.php?action=login');
  200. }
  201. // Logout
  202. function logout_page()
  203. {
  204. $this->redirect('/misc.php?action=logout');
  205. }
  206. // View users
  207. function view_users()
  208. {
  209. }
  210. // View user profile
  211. function view_profile($uid)
  212. {
  213. }
  214. // Edit user profile
  215. function edit_profile($uid)
  216. {
  217. $this->redirect($this->page['edituserprofile'].$this->get_user_name($uid));
  218. }
  219. }
  220. // and go !
  221. $cpg_udb = new cpg_udb;
  222. }
  223. ?>