PageRenderTime 47ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

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

https://github.com/cpg-contrib/coppermine
PHP | 268 lines | 170 code | 58 blank | 40 comment | 18 complexity | c14739b53c53c442431b366110bc0983 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' => 'PunBB v1.2',
  19. 'short_name' => 'punbb12',
  20. 'support_url' => 'http://www.punbb.org/',
  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 punbb
  38. $this->boardurl = 'http://www.yoursite.com/punbb';
  39. // local path to your punbb config file
  40. require_once('../punbb/config.php');
  41. } else { // the vars from the bridgemgr
  42. $this->boardurl = $BRIDGE['full_forum_url'];
  43. require_once($BRIDGE['relative_path_to_config_file'] . 'config.php');
  44. $this->use_post_based_groups = $BRIDGE['use_post_based_groups'];
  45. }
  46. $this->multigroups = 0;
  47. $this->group_overrride = 0;
  48. // Database connection settings
  49. $this->db = array(
  50. 'name' => $db_name,
  51. 'host' => $db_host,
  52. 'user' => $db_username,
  53. 'password' => $db_password,
  54. 'prefix' =>$db_prefix
  55. );
  56. // Board table names
  57. $this->table = array(
  58. 'users' => 'users',
  59. 'groups' => 'groups',
  60. );
  61. // Derived full table names
  62. $this->usertable = '`' . $this->db['name'] . '`.' . $this->db['prefix'] . $this->table['users'];
  63. $this->groupstable = '`' . $this->db['name'] . '`.' . $this->db['prefix'] . $this->table['groups'];
  64. // Table field names
  65. $this->field = array(
  66. 'username' => 'username', // name of 'username' field in users table
  67. 'user_id' => 'id', // name of 'id' field in users table
  68. 'password' => 'password', // name of 'password' field in users table
  69. 'email' => 'email', // name of 'email' field in users table
  70. 'regdate' => 'registered', // name of 'registered' field in users table
  71. 'location' => 'location', // name of 'location' field in users table
  72. 'website' => 'url', // name of 'website' field in users table
  73. 'lastvisit' => 'last_visit', // name of 'location' field in users table
  74. 'usertbl_group_id' => 'group_id', // name of 'group id' field in users table
  75. 'grouptbl_group_id' => 'g_id', // name of 'group id' field in groups table
  76. 'grouptbl_group_name' => 'g_title' // name of 'group name' field in groups table
  77. );
  78. // Pages to redirect to
  79. $this->page = array(
  80. 'register' => '/register.php',
  81. 'editusers' => '/userlist.php',
  82. 'edituserprofile' => "/profile.php?id="
  83. );
  84. // Group ids
  85. $this->admingroups = array(1);
  86. $this->guestgroup = 3;
  87. // Cookie settings - used in following functions only
  88. $this->cookie_name = $cookie_name;
  89. $this->cookie_seed = $cookie_seed;
  90. // Connect to db
  91. $this->connect();
  92. }
  93. // definition of how to extract id, name, group from a session cookie
  94. function session_extraction()
  95. {
  96. return false; // unused
  97. }
  98. // definition of how to extract an id and password hash from a cookie
  99. function cookie_extraction()
  100. {
  101. $superCage = Inspekt::makeSuperCage();
  102. $id = 0;
  103. $pass_hash = '';
  104. //if (isset($_COOKIE[$this->cookie_name])){
  105. // list($id, $pass_hash) = unserialize($_COOKIE[$this->cookie_name]);
  106. //}
  107. if ($superCage->cookie->keyExists($this->cookie_name)){
  108. list($id, $pass_hash) = unserialize($superCage->cookie->getRaw($this->cookie_name));
  109. }
  110. return ($id) ? array($id, $pass_hash) : false;
  111. }
  112. // definition of actions required to convert a password from user database form to cookie form
  113. function udb_hash_db($password)
  114. {
  115. return md5($this->cookie_seed.$password);
  116. }
  117. // Login
  118. function login_page()
  119. {
  120. global $CONFIG;
  121. $this->redirect('/login.php?action=login&redir='.$CONFIG['site_url']);
  122. }
  123. // Logout
  124. function logout_page()
  125. {
  126. global $CONFIG;
  127. $this->redirect('/login.php?action=out&id='.USER_ID.'&redir='.$CONFIG['site_url']);
  128. }
  129. function view_users() {}
  130. function view_profile($uid) {}
  131. function get_users($options = array())
  132. {
  133. global $CONFIG;
  134. // Copy UDB fields and config variables (just to make it easier to read)
  135. $f =& $this->field;
  136. $C =& $CONFIG;
  137. // Sort codes
  138. $sort_codes = array('name_a' => 'user_name ASC',
  139. 'name_d' => 'user_name DESC',
  140. 'group_a' => 'group_name ASC',
  141. 'group_d' => 'group_name DESC',
  142. 'reg_a' => 'user_regdate ASC',
  143. 'reg_d' => 'user_regdate DESC',
  144. 'pic_a' => 'pic_count ASC',
  145. 'pic_d' => 'pic_count DESC',
  146. 'disku_a' => 'disk_usage ASC',
  147. 'disku_d' => 'disk_usage DESC',
  148. 'lv_a' => 'user_lastvisit ASC',
  149. 'lv_d' => 'user_lastvisit DESC',
  150. );
  151. if (in_array($options['sort'], array('group_a', 'group_d', 'pic_a', 'pic_d', 'disku_a', 'disku_d'))){
  152. $sort = '';
  153. list($this->sortfield, $this->sortdir) = explode(' ', $sort_codes[$options['sort']]);
  154. $this->adv_sort = true;
  155. } else {
  156. $sort = "ORDER BY " . $sort_codes[$options['sort']];
  157. $this->adv_sort = false;
  158. }
  159. // Build WHERE clause, if this is a username search
  160. if ($options['search']) {
  161. $options['search'] = 'AND u.'.$f['username'].' LIKE "'.$options['search'].'" ';
  162. }
  163. $sql = "SELECT group_id, group_name, group_quota FROM {$C['TABLE_USERGROUPS']}";
  164. $result = cpg_db_query($sql);
  165. $groups = array();
  166. while ($row = mysql_fetch_assoc($result)) {
  167. $groups[$row['group_id']] = $row;
  168. }
  169. $sql ="SELECT {$f['grouptbl_group_id']} FROM {$this->groupstable}";
  170. $result = cpg_db_query($sql, $this->link_id);
  171. $udb_groups = array();
  172. while ($row = mysql_fetch_assoc($result)) {
  173. $udb_groups[] = $row['group_id'];
  174. }
  175. $sql = "SELECT u.{$f['user_id']} as user_id, u.{$f['usertbl_group_id']} AS user_group, {$f['username']} as user_name, {$f['email']} as user_email, {$f['regdate']} as user_regdate, {$f['lastvisit']} as user_lastvisit, '' as user_active, 0 AS pic_count ".
  176. "FROM {$this->usertable} AS u ".
  177. "WHERE u.{$f['user_id']} > 1 " . $options['search']
  178. . $sort .
  179. " LIMIT {$options['lower_limit']}, {$options['users_per_page']}";
  180. $result = cpg_db_query($sql, $this->link_id);
  181. // If no records, return empty value
  182. if (!mysql_num_rows($result)) {
  183. return array();
  184. }
  185. // Extract user list to an array
  186. while ($user = mysql_fetch_assoc($result)) {
  187. if ($this->use_post_based_groups){
  188. $gid = $user['user_group'] +100;
  189. } else {
  190. $gid = $user['user_group'] == $this->admingroups[0] ? 1 : 2;
  191. }
  192. $userlist[$user['user_id']] = array_merge($user, $groups[$gid]);
  193. $users[] = $user['user_id'];
  194. }
  195. $user_list_string = implode(', ', $users);
  196. $sql = "SELECT owner_id, COUNT(pid) as pic_count, ROUND(SUM(total_filesize)/1024) as disk_usage FROM {$C['TABLE_PICTURES']} WHERE owner_id IN ($user_list_string) GROUP BY owner_id";
  197. $result = cpg_db_query($sql);
  198. while ($owner = mysql_fetch_assoc($result)) {
  199. $userlist[$owner['owner_id']] = array_merge($userlist[$owner['owner_id']], $owner);
  200. }
  201. if ($this->adv_sort) usort($userlist, array('cpg_udb', 'adv_sort'));
  202. return $userlist;
  203. }
  204. }
  205. // and go !
  206. $cpg_udb = new cpg_udb;
  207. }
  208. ?>