| 1 |
<?php
|
| 2 |
// $Id: phpbbforum.hooks.inc,v 1.6 2009/03/15 13:49:36 vb Exp $
|
| 3 |
/**
|
| 4 |
* Copyright 2007-2009 by Vadim G.B. (http://vgb.org.ru)
|
| 5 |
*/
|
| 6 |
|
| 7 |
//if (variable_get("phpbbforum_page_frame", 0) == '1' || variable_get("phpbbforum_page_frame", 0) == '2') {
|
| 8 |
|
| 9 |
/**
|
| 10 |
* replaces msg links.
|
| 11 |
*/
|
| 12 |
function _phpbbforum_replace_msg_links($output) {
|
| 13 |
//global $site_forum_url;
|
| 14 |
|
| 15 |
//if (strpos($output, $site_forum_url) === false) {
|
| 16 |
$output = _phpbbforum_replace_links($output);
|
| 17 |
//}
|
| 18 |
return $output;
|
| 19 |
}
|
| 20 |
|
| 21 |
|
| 22 |
/**
|
| 23 |
* replaces urls.
|
| 24 |
*/
|
| 25 |
function _phpbbforum_replace_urls($output, $decode = false) {
|
| 26 |
global $phpbb_config, $site_forum_url, $site_phpbb_page, $phpbb_root_path;
|
| 27 |
|
| 28 |
$phpbb_url = $phpbb_config['forum_url'];
|
| 29 |
//http://vgb.net.ru/phpbbforum/mcp.php?i=reports&mode=reports
|
| 30 |
$q_phpbbforum = 'q='. $site_phpbb_page;
|
| 31 |
$str = array('../', '/index.php?'. $q_phpbbforum);
|
| 32 |
//$str = array('../', 'www/index.php?'. $q_phpbbforum, '/index.php?'. $q_phpbbforum, 'www/index.php');
|
| 33 |
$output = str_replace($str, '', $output);
|
| 34 |
//http://vgb.net.ru/phpbbforumforum/index.php?q=phpbbforum/mcp.php
|
| 35 |
if (strpos($output, $site_forum_url) === false) {
|
| 36 |
$output = str_replace($phpbb_url, $site_forum_url, $output);
|
| 37 |
$output = str_replace($phpbb_root_path, $site_forum_url .'/', $output);
|
| 38 |
}
|
| 39 |
if ($decode) {
|
| 40 |
$output = urldecode($output);
|
| 41 |
}
|
| 42 |
return $output;
|
| 43 |
}
|
| 44 |
|
| 45 |
/**
|
| 46 |
* _phpbbforum_variable_get
|
| 47 |
*/
|
| 48 |
function _phpbbforum_variable_get($var, $val = null) {
|
| 49 |
if (!empty($var) && isset($_SESSION[$var]))
|
| 50 |
return $_SESSION[$var];
|
| 51 |
return $val;
|
| 52 |
}
|
| 53 |
|
| 54 |
/**
|
| 55 |
* _phpbbforum_variable_set
|
| 56 |
*/
|
| 57 |
function _phpbbforum_variable_set($var, $val = null) {
|
| 58 |
if (!empty($var))
|
| 59 |
$_SESSION[$var] = $val;
|
| 60 |
return $val;
|
| 61 |
}
|
| 62 |
|
| 63 |
/**
|
| 64 |
* _phpbbforum_set_result.
|
| 65 |
*/
|
| 66 |
function _phpbbforum_set_result($result = array()) {
|
| 67 |
//variable_set("phpbbforum_result", $result);
|
| 68 |
$_SESSION['phpbbforum_result'] = $result;
|
| 69 |
return $result;
|
| 70 |
}
|
| 71 |
|
| 72 |
/**
|
| 73 |
* _phpbbforum_get_result.
|
| 74 |
*/
|
| 75 |
function _phpbbforum_get_result() {
|
| 76 |
//$result = variable_get("phpbbforum_result", array());
|
| 77 |
//return $result;
|
| 78 |
if (isset($_SESSION['phpbbforum_result']))
|
| 79 |
return $_SESSION['phpbbforum_result'];
|
| 80 |
return array();
|
| 81 |
}
|
| 82 |
|
| 83 |
/**
|
| 84 |
* _phpbbforum_set_request.
|
| 85 |
*/
|
| 86 |
function _phpbbforum_set_request($request = array()) {
|
| 87 |
//variable_set("phpbbforum_request", $request);
|
| 88 |
//return $request;
|
| 89 |
$_SESSION['phpbbforum_request'] = $request;
|
| 90 |
return $request;
|
| 91 |
}
|
| 92 |
|
| 93 |
/**
|
| 94 |
* _phpbbforum_get_request.
|
| 95 |
*/
|
| 96 |
function _phpbbforum_get_request() {
|
| 97 |
//$request = variable_get("phpbbforum_request", array());
|
| 98 |
//return $request;
|
| 99 |
if (isset($_SESSION['phpbbforum_request']))
|
| 100 |
return $_SESSION['phpbbforum_request'];
|
| 101 |
return array();
|
| 102 |
}
|
| 103 |
|
| 104 |
/**
|
| 105 |
* _phpbbforum_set_destination.
|
| 106 |
*/
|
| 107 |
function _phpbbforum_set_destination($url = '', $query = array()) {
|
| 108 |
$destination = array('url' => $url, 'query' => $query);
|
| 109 |
//variable_set("phpbbforum_destination", $destination);
|
| 110 |
$_SESSION['phpbbforum_destination'] = $destination;
|
| 111 |
return $destination;
|
| 112 |
}
|
| 113 |
|
| 114 |
/**
|
| 115 |
* _phpbbforum_get_destination.
|
| 116 |
*/
|
| 117 |
function _phpbbforum_get_destination() {
|
| 118 |
//$destination = variable_get("phpbbforum_destination", array());
|
| 119 |
//return $destination;
|
| 120 |
if (isset($_SESSION['phpbbforum_destination']))
|
| 121 |
return $_SESSION['phpbbforum_destination'];
|
| 122 |
return array();
|
| 123 |
}
|
| 124 |
/**
|
| 125 |
* _phpbbforum_set_comments_destination.
|
| 126 |
*/
|
| 127 |
function _phpbbforum_set_comments_destination($url = '', $query = array()) {
|
| 128 |
$destination = array('url' => $url, 'query' => $query);
|
| 129 |
//variable_set("phpbbforum_comments_destination", $destination);
|
| 130 |
$_SESSION['phpbbforum_comments_destination'] = $destination;
|
| 131 |
return $destination;
|
| 132 |
}
|
| 133 |
|
| 134 |
/**
|
| 135 |
* _phpbbforum_get_comments_destination.
|
| 136 |
*/
|
| 137 |
function _phpbbforum_get_comments_destination() {
|
| 138 |
//$destination = variable_get("phpbbforum_comments_destination", array());
|
| 139 |
//return $destination;
|
| 140 |
if (isset($_SESSION['phpbbforum_comments_destination']))
|
| 141 |
return $_SESSION['phpbbforum_comments_destination'];
|
| 142 |
return array();
|
| 143 |
}
|
| 144 |
|
| 145 |
/**
|
| 146 |
* _phpbbforum_goto.
|
| 147 |
*/
|
| 148 |
function _phpbbforum_goto($url, $drupal = true) {
|
| 149 |
@restore_error_handler();
|
| 150 |
phpbb_load();
|
| 151 |
|
| 152 |
if (drupal)
|
| 153 |
drupal_goto($url);
|
| 154 |
header('Location: ' . $url);
|
| 155 |
exit;
|
| 156 |
}
|
| 157 |
|
| 158 |
////////////////////////////////////////////////////////////////////////////////
|
| 159 |
|
| 160 |
/**
|
| 161 |
* _phpbbforum_hook
|
| 162 |
*/
|
| 163 |
function _phpbbforum_hook($hook) {
|
| 164 |
$name = $hook['name'];
|
| 165 |
$fn = '_phpbbforum_hook_'. $name;
|
| 166 |
if (function_exists($fn)) {
|
| 167 |
$fn($hook);
|
| 168 |
}
|
| 169 |
}
|
| 170 |
|
| 171 |
/**
|
| 172 |
* _phpbbforum_hook_login
|
| 173 |
*/
|
| 174 |
function _phpbbforum_hook_login($hook) {
|
| 175 |
$redirect = _phpbbforum_replace_urls($hook['redirect']);
|
| 176 |
_phpbbforum_login_external($redirect);
|
| 177 |
}
|
| 178 |
|
| 179 |
/**
|
| 180 |
* _phpbbforum_hook_logout
|
| 181 |
*/
|
| 182 |
function _phpbbforum_hook_logout($hook) {
|
| 183 |
$redirect = _phpbbforum_replace_forum_url($hook['redirect']);
|
| 184 |
_phpbbforum_logout_external($redirect);
|
| 185 |
}
|
| 186 |
|
| 187 |
/**
|
| 188 |
* _phpbbforum_hook_user_delete
|
| 189 |
*/
|
| 190 |
function _phpbbforum_hook_user_delete($hook) {
|
| 191 |
_phpbbforum_user_delete($hook['username']);
|
| 192 |
}
|
| 193 |
|
| 194 |
//} // if (variable_get("phpbbforum_page_frame", 0) == '1' || variable_get("phpbbforum_page_frame", 0) == '2') {
|
| 195 |
|
| 196 |
////////////////////////////////////////////////////////////////////////////////
|
| 197 |
|
| 198 |
function _phpbbforum_login_external($redirect = '') {
|
| 199 |
if (_phpbbforum_drupal_login()) {
|
| 200 |
$url = $redirect;
|
| 201 |
if (variable_get("phpbbforum_page_frame", 0) == '2') {
|
| 202 |
$destination = _phpbbforum_get_destination();
|
| 203 |
$url = $destination['url'];
|
| 204 |
_phpbbforum_set_destination();
|
| 205 |
}
|
| 206 |
drupal_goto($url);
|
| 207 |
}
|
| 208 |
}
|
| 209 |
|
| 210 |
function _phpbbforum_logout_external($redirect = '') {
|
| 211 |
_phpbbforum_drupal_logout($redirect);
|
| 212 |
}
|
| 213 |
|
| 214 |
function _phpbbforum_user_delete($username) {
|
| 215 |
$account = user_load(array('name' => $username));
|
| 216 |
if ($account) {
|
| 217 |
user_delete($account, $account->uid);
|
| 218 |
}
|
| 219 |
}
|
| 220 |
|