PageRenderTime 51ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/cpgdbal/bridge/smf20.inc.php

https://github.com/cpg-contrib/coppermine
PHP | 262 lines | 160 code | 48 blank | 54 comment | 16 complexity | 76b5744ebb457ea373299a82cbc4ecb7 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/smf20.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' => 'Simple Machines (SMF) 2.x',
  21. 'short_name' => 'smf20',
  22. 'support_url' => 'http://www.simplemachines.org/',
  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,Settings.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. if (!USE_BRIDGEMGR) {
  35. require_once('../smf/SSI.php');
  36. $boardurl = 'http://www.mysite.com/board';
  37. } else {
  38. require_once($BRIDGE['relative_path_to_config_file'] . 'SSI.php');
  39. }
  40. class cpg_udb extends core_udb {
  41. function cpg_udb()
  42. {
  43. global $BRIDGE, $CONFIG, $boardurl, $db_prefix, $db_connection, $db_server, $db_name, $db_user, $user_settings;
  44. ################### DB #################
  45. $cpgdb =& cpgDB::getInstance();
  46. $cpgdb->connect_to_existing($CONFIG['LINK_ID']);
  47. ##########################################
  48. $this->use_post_based_groups = $BRIDGE['use_post_based_groups'];
  49. $this->boardurl = $boardurl;
  50. $this->multigroups = 1;
  51. $this->group_overrride = 1;
  52. // Board table names
  53. $this->table = array(
  54. 'users' => 'members',
  55. 'groups' => 'membergroups',
  56. );
  57. // Database connection settings
  58. $this->db = array(
  59. 'name' => $db_name,
  60. 'host' => $db_server ? $db_server : 'localhost',
  61. 'user' => $db_user,
  62. 'prefix' =>$db_prefix
  63. );
  64. // Derived full table names
  65. if (strpos($db_prefix, '.') === false) {
  66. /* $this->usertable = '`' . $this->db['name'] . '`.' . $this->db['prefix'] . $this->table['users'];
  67. $this->groupstable = '`' . $this->db['name'] . '`.' . $this->db['prefix'] . $this->table['groups']; */
  68. ########################################## DB #######################################
  69. $this->usertable = $cpgdb->getFullTableNames($this->db['name'], $this->db['prefix'], $this->table['users']);
  70. $this->groupstable = $cpgdb->getFullTableNames($this->db['name'], $this->db['prefix'], $this->table['groups']);
  71. ############################################################################################
  72. } else {
  73. $this->usertable = $this->db['prefix'] . $this->table['users'];
  74. $this->groupstable = $this->db['prefix'] . $this->table['groups'];
  75. }
  76. // Table field names
  77. $this->field = array(
  78. 'username' => 'member_name', // name of 'username' field in users table
  79. 'user_id' => 'id_member', // name of 'id' field in users table
  80. 'password' => 'passwd', // name of the password field in the users table
  81. 'email' => 'email_address', // name of 'email' field in users table
  82. 'regdate' => 'date_registered', // name of 'registered' field in users table
  83. //'lastvisit' => 'UNIX_TIMESTAMP(last_login)', // last time user logged in
  84. 'lastvisit' => 'last_login', // last time user logged in ##### cpgdb_AL
  85. 'active' => 'is_activated', // is user account active?
  86. 'location' => 'location', // name of 'location' field in users table
  87. 'website' => 'website_url', // name of 'website' field in users table
  88. 'usertbl_group_id' => 'id_post_group', // name of 'group id' field in users table
  89. 'grouptbl_group_id' => 'id_group', // name of 'group id' field in groups table
  90. 'grouptbl_group_name' => 'group_name' // name of 'group name' field in groups table
  91. );
  92. // Pages to redirect to
  93. $this->page = array(
  94. 'register' => '/index.php?action=register',
  95. 'editusers' => '/index.php?action=mlist',
  96. 'edituserprofile' => '/index.php?action=profile;u='
  97. );
  98. // Group ids - admin and guest only.
  99. $this->admingroups = array($this->use_post_based_groups ? 101 : 1);
  100. $this->guestgroup = $this->use_post_based_groups ? 1 : 3;
  101. // Connect to db - or supply a connection id to be used instead of making own connection.
  102. $this->connect($db_connection);
  103. }
  104. // overriding authenticate() as we can let SMF do this all for us.
  105. function authenticate()
  106. {
  107. global $USER_DATA, $user_settings;
  108. if (empty($user_settings['id_member'])){
  109. $this->load_guest_data();
  110. } else {
  111. $row = array(
  112. 'id' => $user_settings['id_member'],
  113. 'username' => $user_settings['member_name'],
  114. 'group_id' => $user_settings['id_group']
  115. );
  116. $this->load_user_data($row);
  117. }
  118. $user_group_set = '(' . implode(',', $USER_DATA['groups']) . ')';
  119. $USER_DATA = array_merge($USER_DATA, $this->get_user_data($USER_DATA['groups'][0], $USER_DATA['groups'], $this->guestgroup));
  120. $USER_DATA['can_see_all_albums'] = $USER_DATA['has_admin_access'] = array_intersect($USER_DATA['groups'],$this->admingroups) ? 1 : 0;
  121. // avoids a template error
  122. if (!$USER_DATA['user_id']) $USER_DATA['can_create_albums'] = 0;
  123. // For error checking
  124. $CONFIG['TABLE_USERS'] = '**ERROR**';
  125. define('USER_ID', $USER_DATA['user_id']);
  126. define('USER_NAME', addslashes($USER_DATA['user_name']));
  127. define('USER_GROUP', $USER_DATA['group_name']);
  128. define('USER_GROUP_SET', $user_group_set);
  129. define('USER_IS_ADMIN', $USER_DATA['has_admin_access']);
  130. define('USER_CAN_SEND_ECARDS', (int)$USER_DATA['can_send_ecards']);
  131. define('USER_CAN_RATE_PICTURES', (int)$USER_DATA['can_rate_pictures']);
  132. define('USER_CAN_POST_COMMENTS', (int)$USER_DATA['can_post_comments']);
  133. define('USER_CAN_UPLOAD_PICTURES', (int)$USER_DATA['can_upload_pictures']);
  134. define('USER_CAN_CREATE_ALBUMS', (int)$USER_DATA['can_create_albums']);
  135. define('USER_UPLOAD_FORM', (int)$USER_DATA['upload_form_config']);
  136. define('CUSTOMIZE_UPLOAD_FORM', (int)$USER_DATA['custom_user_upload']);
  137. define('NUM_FILE_BOXES', (int)$USER_DATA['num_file_upload']);
  138. define('NUM_URI_BOXES', (int)$USER_DATA['num_URI_upload']);
  139. $this->session_update();
  140. }
  141. function get_groups($row)
  142. {
  143. global $user_settings;
  144. $i = $this->use_post_based_groups ? 100 : 0;
  145. $data = array();
  146. if ($user_settings['id_group'] == 0){
  147. $data[0] = 2;
  148. } else {
  149. $data[0] = $user_settings['id_group'] + $i;
  150. }
  151. if ($user_settings['additional_groups']){
  152. $groups = explode(',', $user_settings['additional_groups']);
  153. foreach ($groups as $id => $group){
  154. //$data[$id] = $group+$i; This was overwriting the primary group
  155. $data[] = $group+$i; //appends additionalGroups to the primary group.
  156. }
  157. }
  158. if ($this->use_post_based_groups) $data[] = $user_settings['id_post_group'] + $i;
  159. return $data;
  160. }
  161. function collect_groups()
  162. {
  163. global $cpg_db_smf20_inc;
  164. // Use this version to exclude true post based groups
  165. //$sql ="SELECT * FROM {$this->groupstable} WHERE minposts=-1";
  166. // Use this version to include all SMF groups
  167. /* $sql ="SELECT * FROM {$this->groupstable}";
  168. $result = cpg_db_query($sql, $this->link_id);
  169. $udb_groups = array(1=>'Guests', 2=>'Registered');
  170. while ($row = mysql_fetch_assoc($result))
  171. {
  172. $udb_groups[$row[$this->field['grouptbl_group_id']]+100] = utf_ucfirst(utf_strtolower($row[$this->field['grouptbl_group_name']]));
  173. } */
  174. #################################### DB #####################################
  175. $this->cpgudb->query($cpg_db_smf20_inc['get_all_groups'], $this->groupstable);
  176. $udb_groups = array(1=>'Guests', 2=>'Registered');
  177. while ($row = $this->cpgudb->fetchRow()) {
  178. $udb_groups[$row[$this->field['grouptbl_group_id']]+100] = utf_ucfirst(utf_strtolower($row[$this->field['grouptbl_group_name']]));
  179. }
  180. ####################################################################################
  181. return $udb_groups;
  182. }
  183. function login_page()
  184. {
  185. global $CONFIG;
  186. // silly workaround for SMF's redirect check...
  187. $_SESSION['old_url'] = $CONFIG['site_url'] . '?board=redirect';
  188. $this->redirect('/index.php?action=login');
  189. }
  190. function logout_page()
  191. {
  192. global $CONFIG;
  193. // this is a wee bit messy like....
  194. ob_start();
  195. ssi_logout($CONFIG['site_url']);
  196. preg_match('/<a href="(.*)">/', ob_get_clean(), $matches);
  197. $this->boardurl = '';
  198. $this->redirect($matches[1]);
  199. }
  200. function view_users()
  201. {
  202. $this->redirect($this->page['editusers']);
  203. }
  204. function view_profile() {}
  205. }
  206. // and go !
  207. $cpg_udb = new cpg_udb;
  208. }
  209. ?>