PageRenderTime 26ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 0ms

/cpgdbal/bridge/vbulletin30.inc.php

https://github.com/cpg-contrib/coppermine
PHP | 239 lines | 142 code | 33 blank | 64 comment | 14 complexity | 1cb84ad5ac5524c9f65fd2fba7c92c72 MD5 | raw file
  1. <?php
  2. /*************************
  3. Coppermine Photo Gallery
  4. ************************
  5. Copyright (c) 2003-2008 Dev Team
  6. v1.1 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.5.0
  12. $HeadURL: https://coppermine.svn.sourceforge.net/svnroot/coppermine/trunk/cpg1.5.x/bridge/vbulletin30.inc.php $
  13. $Revision: 5129 $
  14. $LastChangedBy: gaugau $
  15. $Date: 2008-10-18 16:03:12 +0530 (Sat, 18 Oct 2008) $
  16. **********************************************/
  17. if (!defined('IN_COPPERMINE')) die('Not in Coppermine...');
  18. if (isset($bridge_lookup)) {
  19. $default_bridge_data[$bridge_lookup] = array(
  20. 'full_name' => 'vBulletin 3.0',
  21. 'short_name' => 'vbulletin30',
  22. 'support_url' => 'http://www.vbulletin.com/',
  23. 'full_forum_url_default' => 'http://www.yoursite.com/board',
  24. 'full_forum_url_used' => 'mandatory,not_empty,no_trailing_slash',
  25. 'relative_path_to_config_file_default' => '../board/',
  26. 'relative_path_to_config_file_used' => 'lookfor,includes/config.php',
  27. 'use_post_based_groups_default' => '0',
  28. 'use_post_based_groups_used' => 'radio,1,0',
  29. );
  30. } else {
  31. // Switch that allows overriding the bridge manager with hard-coded values
  32. define('USE_BRIDGEMGR', 1);
  33. require_once 'bridge/udb_base.inc.php';
  34. class cpg_udb extends core_udb {
  35. function cpg_udb()
  36. {
  37. global $BRIDGE;
  38. ################### DB #################
  39. global $CONFIG;
  40. $cpgdb =& cpgDB::getInstance();
  41. $cpgdb->connect_to_existing($CONFIG['LINK_ID']);
  42. ##########################################
  43. if (!USE_BRIDGEMGR) {
  44. $this->boardurl = 'http://www.yousite.com/vb3';
  45. require_once('../vb3/includes/config.php');
  46. } else {
  47. $this->boardurl = $BRIDGE['full_forum_url'];
  48. require_once($BRIDGE['relative_path_to_config_file'] . 'includes/config.php');
  49. $this->use_post_based_groups = $BRIDGE['use_post_based_groups'];
  50. }
  51. $this->multigroups = 1;
  52. // Database connection settings
  53. if (isset($config['Database']['dbname']))
  54. {
  55. // Running on vBulletin 3.5.x
  56. $this->db = array(
  57. 'name' => $config['Database']['dbname'],
  58. 'host' => $config['MasterServer']['servername'] ? $config['MasterServer']['servername'] : 'localhost',
  59. 'user' => $config['MasterServer']['username'],
  60. 'password' => $config['MasterServer']['password'],
  61. 'prefix' => $config['Database']['tableprefix']
  62. );
  63. } else {
  64. // Running on vBulletin 3.0.x
  65. $this->db = array(
  66. 'name' => $dbname,
  67. 'host' => $servername ? $servername : 'localhost',
  68. 'user' => $dbusername,
  69. 'password' => $dbpassword,
  70. 'prefix' =>$tableprefix
  71. );
  72. }
  73. // Board table names
  74. $this->table = array(
  75. 'users' => 'user',
  76. 'groups' => 'usergroup',
  77. 'sessions' => 'session'
  78. );
  79. // Derived full table names
  80. /* $this->usertable = '`' . $this->db['name'] . '`.' . $this->db['prefix'] . $this->table['users'];
  81. $this->groupstable = '`' . $this->db['name'] . '`.' . $this->db['prefix'] . $this->table['groups'];
  82. $this->sessionstable = '`' . $this->db['name'] . '`.' . $this->db['prefix'] . $this->table['sessions']; */
  83. ########################################## DB #######################################
  84. $this->usertable = $cpgdb->getFullTableNames($this->db['name'], $this->db['prefix'], $this->table['users']);
  85. $this->groupstable = $cpgdb->getFullTableNames($this->db['name'], $this->db['prefix'], $this->table['groups']);
  86. $this->sessionstable = $cpgdb->getFullTableNames($this->db['name'], $this->db['prefix'], $this->table['sessions']);
  87. #############################################################################################
  88. // Table field names
  89. $this->field = array(
  90. 'username' => 'username', // name of 'username' field in users table
  91. 'user_id' => 'userid', // name of 'id' field in users table
  92. 'password' => 'password', // name of 'password' field in users table
  93. 'email' => 'email', // name of 'email' field in users table
  94. 'regdate' => 'joindate', // name of 'registered' field in users table
  95. 'location' => "''", // name of 'location' field in users table
  96. 'website' => 'homepage', // name of 'website' field in users table
  97. 'usertbl_group_id' => 'usergroupid', // name of 'group id' field in users table
  98. 'grouptbl_group_id' => 'usergroupid', // name of 'group id' field in groups table
  99. 'grouptbl_group_name' => 'title' // name of 'group name' field in groups table
  100. );
  101. // Pages to redirect to
  102. $this->page = array(
  103. 'register' => '/register.php',
  104. 'editusers' => '/memberlist.php',
  105. 'edituserprofile' => "/member.php?u=",
  106. );
  107. // Group ids - admin and guest only.
  108. $this->admingroups = array(6);
  109. $this->guestgroup = $this->use_post_based_groups ? 101 : 3;
  110. // Use a special function to collect groups for cpg groups table
  111. $this->group_overrride = 0;
  112. // Cookie settings - used in following functions only
  113. if (isset($config['Misc']['cookieprefix']))
  114. {
  115. // get cookieprefix from vb3.5.x
  116. $this->cookie_name = $config['Misc']['cookieprefix'];
  117. } else {
  118. // get cookieprefix from vb3.0.x
  119. $this->cookie_name = $cookieprefix;
  120. }
  121. // Connect to db
  122. $this->connect();
  123. }
  124. // definition of how to extract id, name, group from a session cookie
  125. function session_extraction()
  126. {
  127. global $cpg_db_vbulletin30_inc; ###### cpgdb_AL
  128. $superCage = Inspekt::makeSuperCage();
  129. //if (isset($_COOKIE[$this->cookie_name . 'sessionhash'])) {
  130. // $session_id = addslashes($_COOKIE[$this->cookie_name . 'sessionhash']);
  131. if ($superCage->cookie->keyExists($this->cookie_name . 'sessionhash')) {
  132. $session_id = $superCage->cookie->getEscaped($this->cookie_name . 'sessionhash');
  133. /* $sql = "SELECT u.{$this->field['user_id']}, u.{$this->field['password']}, u.{$this->field['grouptbl_group_id']}+100 AS usergroupid FROM {$this->usertable} AS u, {$this->sessionstable} AS s WHERE s.{$this->field['user_id']}=u.{$this->field['user_id']} AND s.sessionhash='$session_id'";
  134. $result = cpg_db_query($sql, $this->link_id);
  135. if (mysql_num_rows($result)){
  136. $row = mysql_fetch_array($result);
  137. return $row;
  138. } else {
  139. return false;
  140. } */
  141. ####################################### DB #######################################
  142. $this->cpgudb->query($cpg_db_vbulletin30_inc['session_extraction'], $this->field['user_id'], $this->field['password'],
  143. $this->field['grouptbl_group_id'], $this->usertable, $this->sessionstable, $session_id);
  144. $rowset = $this->cpgudb->fetchRowSet();
  145. if (count($rowset)) {
  146. $row = $rowset[0];
  147. return $row;
  148. } else {
  149. return false;
  150. }
  151. #######################################################################################
  152. }
  153. }
  154. // Get groups of which user is member
  155. function get_groups($row)
  156. {
  157. global $cpg_db_vbulletin30_inc; ###### cpgdb_AL
  158. $data[0] = in_array($row['group_id'] - 100, $this->admingroups) ? 1 : 2;
  159. if ($this->use_post_based_groups){
  160. /* $sql = "SELECT g.{$this->field['usertbl_group_id']}+100 AS group_id, u.* FROM {$this->usertable} AS u, {$this->groupstable} as g WHERE g.{$this->field['grouptbl_group_id']} = u.{$this->field['usertbl_group_id']} AND u.{$this->field['user_id']} = '{$row['id']}'";
  161. $result = cpg_db_query($sql, $this->link_id);
  162. $row = mysql_fetch_array($result); */
  163. ######################################## DB ########################################
  164. $this->cpgudb->query($cpg_db_vbulletin30_inc['get_groups'], $this->field['usertbl_group_id'], $this->usertable,
  165. $this->groupstable, $thisfield['grouptbl_group_id'], $this->field['user_id'], $row['id']);
  166. $row = $this->cpgudb->fetchRow();
  167. ##########################################################################################
  168. $data[0] = $row['group_id'];
  169. if ($row['membergroupids']){
  170. $groups = explode(',', $row['membergroupids']);
  171. foreach ($groups as $id => $group){
  172. $data[] = $group+100;
  173. }
  174. }
  175. }
  176. return $data;
  177. }
  178. // definition of how to extract an id and password hash from a cookie
  179. function cookie_extraction()
  180. {
  181. return false;
  182. }
  183. // definition of actions required to convert a password from user database form to cookie form
  184. function udb_hash_db($password)
  185. {
  186. return $password; // unused
  187. }
  188. function login_page()
  189. {
  190. $this->redirect("/index.php");
  191. }
  192. function logout_page()
  193. {
  194. $this->redirect("/login.php?do=logout&u=".USER_ID);
  195. }
  196. }
  197. // and go !
  198. $cpg_udb = new cpg_udb;
  199. }
  200. ?>