/[drupal]/contributions/modules/phpbbforum/phpbbforum.pages.inc
ViewVC logotype

Contents of /contributions/modules/phpbbforum/phpbbforum.pages.inc

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.16 - (show annotations) (download) (as text)
Mon Aug 31 21:08:03 2009 UTC (2 months, 3 weeks ago) by vb
Branch: MAIN
CVS Tags: DRUPAL-6--2-0-BETA6, DRUPAL-6--2-0-BETA7, DRUPAL-5--2-0-BETA6, HEAD
Changes since 1.15: +196 -19 lines
File MIME type: text/x-php
Bugs and new comments
1 <?php
2 // $Id: phpbbforum.pages.inc,v 1.14 2009/05/10 14:29:39 vb Exp $
3 /**
4 * Copyright 2007-2009 by Vadim G.B. (http://vgb.org.ru)
5 */
6
7 /**
8 * @file
9 * User page callbacks for the forum module.
10 */
11 if (variable_get("phpbbforum_page_frame", 0) == '1' || variable_get("phpbbforum_page_frame", 0) == '2') {
12
13 function phpbbforum_page() {
14
15 if (!_phpbbforum_settings())
16 return '';
17
18 if ($_REQUEST['form_id'] == 'user_login_block' && $_REQUEST['op'] == 'Log in') {
19 return '';
20 }
21
22 $query_string = _phpbbforum_page_get_query();
23
24 parse_str($query_string, $query);
25
26 $output = _phpbbforum_page($query_string, $query);
27
28 return $output;
29 }
30
31 function _phpbbforum_page_get_query() {
32
33 if (PHPBB_MODULE_DEBUG) {
34 $path = urldecode(request_uri());
35 $path = drupal_substr($path, drupal_strlen(base_path()));
36 $path_parsed = _phpbbforum_split_path($path);
37 }
38
39 $query_string = $_SERVER['QUERY_STRING'];
40
41 $query_string = urldecode($query_string);
42
43 $tags = array('<iframe>', '</iframe>', '/iframe',
44 '&lt;iframe&gt;', '&lt;/iframe&gt;',
45 '<script>', '</script>',
46 '&lt;script&gt;', '&lt;/script&gt;',
47 );
48 $query_string = str_replace($tags, '', $query_string);
49
50 $query_string = check_plain($query_string);
51 $query_string = str_replace('&amp;', '&', $query_string);
52
53
54 //http://vgb.net.ru/phpbbforum/viewtopic.php?f=2&t=13
55 //http://vgb.net.ru/phpbbforum/viewtopic.php?f=2&t=13&hilit="></iframe><script>javascript:alert(document.cookie)</script>
56
57 // if (PHPBB_MODULE_DEBUG)
58 //drupal_set_message('QUERY_STRING:'.$query_string .' q= '. $_GET['q']);
59
60 return $query_string;
61 }
62
63 function _phpbbforum_page($phpbbaction, $query = array()) {
64 global $phpbb_config, $phpbb_user, $user, $phpbb_root_path, $phpEx, $_phpbb_base_path,
65 $site_base_url, $site_forum_url, $site_phpbb_page, $_phpbb_result, $_phpbb_embed_mode,
66 $_phpbb_integration_mode, $_phpbb_acp_integration_mode, $_phpbbforum_comments_mode;
67
68 $comments_mode = $_phpbbforum_comments_mode;
69
70 $args = array(
71 "/viewonline.php",
72 "/memberlist.php",
73 "/viewtopic.php",
74 "/viewforum.php",
75 "/posting.php",
76 "/search.php",
77 "/ucp.php",
78 "/report.php",
79 "/mcp.php",
80 "/adm/index.php",
81 "/index.php",
82 "/faq.php",
83 );
84
85 $isamp = false;
86 $isamp1 = false;
87 $strfound = false;
88
89 $str = 'q='. $site_phpbb_page;
90 $len = strlen($str);
91 $stra = $str .'&';
92 $lena = $len + 1;
93 if (substr($phpbbaction, 0, $lena) == $stra) {
94 $phpbbaction = substr($phpbbaction, $lena);
95 $isamp1 = true;
96 }
97 elseif (substr($phpbbaction, 0, $len) == $str)
98 $phpbbaction = substr($phpbbaction, $len);
99
100 //if (PHPBB_MODULE_DEBUG)
101 //drupal_set_message('QUERY_STRING='.$phpbbaction);
102
103 foreach ($args as $str) {
104 $isamp = false;
105 $len = strlen($str);
106 $stra = $str .'&';
107 $lena = $len + 1;
108 if (substr($phpbbaction, 0, $lena) == $stra) {
109 $phpbbaction = substr($phpbbaction, $lena);
110 $isamp = true;
111 $strfound = true;
112 break;
113 }
114 elseif (substr($phpbbaction, 0, $len) == $str) {
115 $phpbbaction = substr($phpbbaction, $len);
116 $strfound = true;
117 break;
118 }
119 }
120
121 if (!$strfound)
122 $str = '';
123
124 //if (PHPBB_MODULE_DEBUG)
125 // drupal_set_message('pa='.$phpbbaction);
126
127 $path = $phpbb_config['forum_url'];
128 $phpbbforum_url = $site_forum_url;
129 //if (PHPBB_MODULE_DEBUG)
130 // drupal_set_message('path='.$path);
131 //if (PHPBB_MODULE_DEBUG)
132 // $path = "http://phpbb.vgb.net.ru";
133
134 if ($strfound) {
135 $path .= $str;
136 $phpbbforum_url .= $str;
137 }
138
139 if ($phpbbaction != "") {
140 if ($isamp1 || $isamp) {
141 $path .= '?';
142 $phpbbforum_url .= '?';
143 }
144 $path .= $phpbbaction;
145 $phpbbforum_url .= $phpbbaction;
146 }
147
148 /*
149 if (PHPBB_MODULE_DEBUG) {
150 if ($isamp1 || $isamp)
151 $amp = '?';
152 else
153 $amp = '';
154 //drupal_set_message('path='.$path.' str='.$str.' action='.$str.$amp.$phpbbaction);
155 drupal_set_message('phpbbforum='.$phpbbforum_url);
156 }
157 */
158 //$output .= $path;
159 //return $output;
160
161 //drupal_set_message('1 str='.$str.' Frame='. $path);
162
163 if ($str == '/adm/index.php') {
164 if ($_phpbb_acp_integration_mode == '0') {
165 drupal_goto($path);
166 }
167 elseif ($_phpbb_acp_integration_mode == '1') {
168 return _phpbbforum_page_inframe($path);
169 }
170 }
171
172 if ($_phpbb_integration_mode == '1') {
173 return _phpbbforum_page_inframe($path);
174 }
175
176 $_phpbb_result = _phpbbforum_get_result();
177 if (!empty($_phpbb_result)) {
178 _phpbbforum_set_result();
179 }
180
181 if (isset($_phpbb_result['hook']) && $_phpbb_result['status'] == 'redirect') {
182 // execute hook
183 _phpbbforum_hook($_phpbb_result['hook']);
184
185 unset($_phpbb_result['hook']);
186 }
187
188 if (phpbb_user_new_privmsg()) {
189 //$url = $site_base_url .'/'. $site_phpbb_page .'/ucp.php?i=pm&mode=popup';
190 //drupal_goto($url);
191 $str = '/ucp.php';
192 $_REQUEST['i'] = 'pm';
193 $_REQUEST['mode'] = 'popup';
194 }
195 if (isset($_phpbb_result['status']) && $_phpbb_result['status'] == 'exit') {
196 // get previous output
197 $output = $_phpbb_result['output'];
198 }
199 else {
200
201 $query['path'] = $str;
202 $_phpbb_result['query'] = $query;
203 $_phpbb_embed_mode['query'] = $query;
204 $_phpbb_embed_mode['redirect'] = variable_get('phpbbforum_redirect', 0);
205 $destination_prev = _phpbbforum_get_destination();
206 _phpbbforum_set_destination($phpbbforum_url, $query);
207
208 switch($str) {
209
210 case '/index.php':
211 case '':
212 _phpbbforum_set_comments_destination();
213 $output = phpbb_api_index('/index.php');
214 break;
215
216 case '/viewforum.php':
217 _phpbbforum_set_comments_destination();
218 $output = phpbb_api_index($str);
219 break;
220 case '/viewtopic.php':
221 //$query['path'] = $str;
222 //_phpbbforum_set_destination($phpbbforum_url, $query);
223 _phpbbforum_set_extra($query);
224
225 $update_topic_view = false;
226 $query_prev = $destination_prev['query'];
227 //$start_prev = $query_prev['start'];
228 $start = $query['start'];
229 if ($query_prev['path'] != $str || $query_prev['t'] != $query['t'] || $query_prev['f'] != $query['f'] || !isset($start)) {
230 $update_topic_view = true;
231 }
232 $_phpbb_embed_mode['update_topic_view'] = $update_topic_view;
233
234 $output = phpbb_api_index($str);
235 break;
236 case '/viewonline.php':
237 _phpbbforum_set_comments_destination();
238 $output = phpbb_api_index($str);
239 break;
240
241 case '/memberlist.php':
242 _phpbbforum_set_comments_destination();
243 $output = phpbb_api_index($str);
244 break;
245
246 case '/ucp.php':
247 //$query['path'] = $str;
248 //_phpbbforum_set_destination($phpbbforum_url, $query);
249 $output = phpbb_api_index($str);
250 break;
251
252 case '/mcp.php':
253 $query_prev = $destination_prev['query'];
254 $t = $query_prev['t'];
255 if ($t) {
256 $query['t'] = $t;
257 }
258 $query['path'] = $str;
259 _phpbbforum_set_destination($phpbbforum_url, $query);
260 _phpbbforum_set_extra($query);
261 $request['action'] = $_REQUEST['action'];
262 _phpbbforum_set_request($request);
263 $output = phpbb_api_index($str);
264 break;
265
266 case '/search.php':
267 $output = phpbb_api_index($str);
268 break;
269
270 case '/posting.php':
271 $output = phpbb_api_index($str);
272 break;
273
274 case '/report.php':
275 $output = phpbb_api_index($str);
276 break;
277
278 case '/faq.php':
279 _phpbbforum_set_comments_destination();
280 $output = phpbb_api_index($str);
281 break;
282
283 default:
284 $output = _phpbbforum_page_inframe($path);
285 return $output;
286 }
287
288 $_phpbb_result = _phpbbforum_get_result();
289
290 if (isset($_phpbb_result['hook'])) {
291 // execute hook
292 _phpbbforum_hook($_phpbb_result['hook']);
293 }
294
295 } //***
296
297 $_phpbb_theme_base_path = $_phpbb_base_path .'styles/'. $phpbb_user->theme['theme_path'];
298
299 $output = theme('phpbbforum_style', $phpbb_user->theme['theme_path'], $_phpbb_theme_base_path, $output);
300
301 $_phpbb_result = _phpbbforum_set_result(array());
302
303 return $output;
304 }
305
306 /**
307 * prints comment page in comments.
308 */
309 function _phpbbforum_comment_render($node, $href, $teaser, &$query) {
310 global $base_url, $phpbb_root_path,
311 $site_base_url, $site_phpbb_page, $site_forum_url, $_phpbb_integration_mode, $_phpbbforum_comments_mode;
312
313 $output = '';
314
315 //$href = $node->links['phpbbforum_comment']['href'];
316
317 $path_string = str_replace($site_base_url, '', $href);
318 $path_string = str_replace('?', '&', $path_string);
319
320 $query_string = str_replace($site_base_url .'/', 'q=', $href);
321 $query_string = str_replace('?', '&', $query_string);
322
323 $path = $path_string;
324 $path = drupal_substr($path, drupal_strlen(base_path()));
325 $path_parsed = _phpbbforum_split_path($path);
326 $path_pquery = $path_parsed['query'];
327
328 parse_str($query_string, $query);
329
330 if (!$teaser) {
331 /*
332 $destination = _phpbbforum_get_comments_destination();
333 if (!empty($destination)) {
334 $dquery = $destination['query'];
335 $_phpbbforum_comments_mode = $destination['query']['comments_mode'];
336 }
337 else {
338 $_phpbbforum_comments_mode = 0;
339 }
340
341 if ($_phpbbforum_comments_mode) {
342 $_phpbbforum_comments_mode = 0;
343 $dquery['comments_mode'] = $_phpbbforum_comments_mode;
344 _phpbbforum_set_comments_destination('', $dquery);
345
346 } else {
347 *
348 */
349 $comment_query = array();
350 $comment_query['comments_mode'] = $_phpbbforum_comments_mode = 1;
351 $comment_query['q'] = $_REQUEST['q'];
352 _phpbbforum_set_comments_destination($comment_query['q'], $comment_query);
353
354 $request = array();
355 foreach($query as $key => $val) {
356 $request[$key] = $val;
357 $_REQUEST[$key] = $val;
358 }
359 //}
360
361 $output = _phpbbforum_page($query_string, $query);
362
363 foreach($request as $key => $val) {
364 $_REQUEST[$key] = $val;
365 }
366 }
367
368 return $output;
369 }
370
371 /**
372 * prints page in a iframe.
373 */
374 function _phpbbforum_page_inframe($path) {
375
376 // Added this to allow the iframe to resize dynamically according to the
377 // page height. -- Daen
378 drupal_add_js(drupal_get_path('module', PHPBB_DRUPAL_MODULE) .'/js/phpbbframe.js', 'module');
379
380 $width = variable_get("phpbbforum_page_width", "100%");
381 $height = variable_get("phpbbforum_page_height", "1024");
382 $scrolling = variable_get("phpbbforum_page_scroll", 2);
383
384 $output = '<iframe id="forumFrame" src="'. $path .'"'; // name="phpbbforum"';
385
386 if ($width && $height) {
387 $output .= ' width="'. $width .'"'.' height="'. $height .'"';
388 }
389 $output .= ' frameborder="0" framespacing="0"';
390 if ($scrolling == 2)
391 $output .= ' scrolling="auto"';
392 elseif ($scrolling == 1)
393 $output .= ' scrolling="yes"';
394 else
395 $output .= ' scrolling="no"';
396 $output .= ' allowtransparency="false"';
397
398 $output .= '><p>'. t('Sorry your browser does not work') .'</p></iframe>';
399
400 return $output;
401 }
402
403
404 /**
405 * replaces forum url.
406 */
407 function _phpbbforum_replace_forum_url($output) {
408 global $phpbb_config, $site_forum_url;
409
410 $phpbb_url = $phpbb_config['forum_url'];
411 $output = str_replace($phpbb_url, $site_forum_url, $output);
412 return $output;
413 }
414
415 /**
416 * replaces block links.
417 */
418 function _phpbbforum_replace_block_links($output) {
419 $output = _phpbbforum_replace_forum_url($output);
420 $output = _phpbbforum_restore_block_links($output);
421 return $output;
422 }
423 /**
424 * restore block links.
425 */
426 function _phpbbforum_restore_block_links($output) {
427 global $phpbb_config, $site_forum_url, $site_phpbb_page;
428
429 $phpbb_url = $phpbb_config['forum_url'];
430
431 // replace back phpbb images
432 $frameurl = $site_forum_url;
433 $imgsrc = '<img src="';
434 $frameurl = $imgsrc . $frameurl;
435 $phpbburl = $imgsrc . $phpbb_url;
436 $output = str_replace($frameurl, $phpbburl, $output);
437
438 $path = '/images';
439 $frameurl = $site_forum_url . $path;
440 $phpbburl = $phpbb_url . $path;
441 $output = str_replace($frameurl, $phpbburl, $output);
442
443 // replace relative phpbb images paths
444 $relurl = '<img src="images';
445 $phpbburl = '<img src="'. $phpbb_url .'/images';
446 $output = str_replace($relurl, $phpbburl, $output);
447
448 return $output;
449 }
450
451 /**
452 * replaces links.
453 */
454 function _phpbbforum_replace_links($output) {
455 $output = _phpbbforum_replace_forum_url($output);
456 $output = _phpbbforum_restore_links($output);
457 return $output;
458 }
459
460 /**
461 * restore links.
462 */
463 function _phpbbforum_restore_links($output) {
464 global $phpbb_config, $site_forum_url, $site_phpbb_page,
465 $_phpbb_result, $_phpbb_embed_mode, $_phpbb_acp_integration_mode;
466
467 $phpbb_url = $phpbb_config['forum_url'];
468 //$str = $_phpbb_embed_mode['path'];
469
470 // replace back phpbb images
471 $frameurl = $site_forum_url;
472 $imgsrc = '<img src="';
473 $frameurl = $imgsrc . $frameurl;
474 $phpbburl = $imgsrc . $phpbb_url;
475 $output = str_replace($frameurl, $phpbburl, $output);
476
477 $path = '/styles';
478 $frameurl = $site_forum_url . $path;
479 $phpbburl = $phpbb_url . $path;
480 $output = str_replace($frameurl, $phpbburl, $output);
481
482 $path = '/images';
483 $frameurl = $site_forum_url . $path;
484 $phpbburl = $phpbb_url . $path;
485 $output = str_replace($frameurl, $phpbburl, $output);
486
487 // replace relative phpbb images paths
488 $relurl = '<img src="images';
489 $phpbburl = '<img src="'. $phpbb_url .'/images';
490 $output = str_replace($relurl, $phpbburl, $output);
491
492 // Find a member in popup
493 $mode = '/memberlist.php?mode=searchuser';
494 $frameurl = $site_forum_url . $mode;
495 $phpbburl = $phpbb_url . $mode;
496 $output = str_replace($frameurl, $phpbburl, $output);
497
498 //http://drupalbridge.org/forum/posting.php?mode=smilies&f=3
499 $mode = '/posting.php?mode=smilies';
500 $frameurl = $site_forum_url . $mode;
501 $phpbburl = $phpbb_url . $mode;
502 $output = str_replace($frameurl, $phpbburl, $output);
503
504 if (/*$str == '/adm/index.php' &&*/ $_phpbb_acp_integration_mode == '0') {
505 $mode = '/adm/index.php';
506 $frameurl = $site_forum_url . $mode;
507 $phpbburl = $phpbb_url . $mode;
508 $output = str_replace($frameurl, $phpbburl, $output);
509 }
510 // Download
511 $path = '/download';
512 $frameurl = $site_forum_url . $path;
513 $phpbburl = $phpbb_url . $path;
514 $output = str_replace($frameurl, $phpbburl, $output);
515 // gallery2
516 $path = '/g2is.php';
517 $frameurl = $site_forum_url . $path;
518 $phpbburl = $phpbb_url . $path;
519 $output = str_replace($frameurl, $phpbburl, $output);
520
521 return $output;
522 }
523
524 /**
525 * Internal function to split a path string into path, query and fragment.
526 */
527 function _phpbbforum_split_path($path) {
528 global $site_base_url;
529 //$path = strtr($path, array('<front>' => variable_get('site_frontpage', 'node')));
530 if (variable_get('clean_url', 0) && strpos($path, '?q=') === 0) {
531 $path = preg_replace('/^\?q=/', '', $path, 1);
532 }
533 if (strpos($path, '?') === FALSE && strpos($path, '&') !== FALSE) {
534 $path = preg_replace('/&/', '?', $path, 1);
535 }
536
537 $parsed = parse_url($path) + array('query' => NULL, 'fragment' => NULL);
538 $result = array(
539 'path' => preg_replace('/[\?\#].*$/', '', $path),
540 'query' => $parsed['query'],
541 'fragment' => $parsed['fragment'],
542 );
543 return $result;
544 }
545
546 /**
547 * replaces comments url.
548 */
549 /*
550 function _phpbbforum_replace_comments_url($output) {
551 global $phpbb_config, $site_forum_url;
552
553 $phpbb_url = $phpbb_config['forum_url'];
554 $output = str_replace($phpbb_url, $site_forum_url, $output);
555 return $output;
556 }
557 */
558
559 /**
560 * creates comments destination url.
561 */
562 function _phpbbforum_comments_destination($url, $destination_url) {
563 global $site_base_url;
564
565 $parsed = parse_url($url);
566 if (!empty($parsed['fragment'])) {
567 $fragment = '#'. $parsed['fragment'];
568 }
569 else {
570 $fragment = '';
571 }
572
573 $q = '/';
574 if (!variable_get('clean_url', 0)) {
575 $q .= '?q=';
576 }
577
578 $url = $site_base_url . $q . $destination_url . $fragment;
579
580 return $url;
581 }
582
583 /**
584 * creates posting destination url.
585 */
586 function _phpbbforum_posting_destination($query) {
587 global $site_base_url, $site_phpbb_page;
588
589 if (!empty($query['f'])) {
590 $f = '&f='. $query['f'];
591 }
592 else {
593 $f = '';
594 }
595 if (!empty($query['t'])) {
596 $t = '&t='. $query['t'];
597 }
598 else {
599 $t = '';
600 }
601
602 $q = '/';
603 if (variable_get('clean_url', 0)) {
604 $q .= $site_phpbb_page .'/posting.php?';
605 }
606 else {
607 $q .= '?q='. $site_phpbb_page .'/posting.php&';
608
609 }
610 $q .= 'mode=reply'. $f . $t;
611
612 $url = $site_base_url . $q;
613
614 return $url;
615 }
616
617 } // if (variable_get("phpbbforum_page_frame", 0) == '1' || variable_get("phpbbforum_page_frame", 0) == '2') {
618
619 if (variable_get("phpbbforum_page_frame", 0) == '2') {
620 /**
621 * sets extra vars.
622 */
623 function _phpbbforum_set_extra($query) {
624
625 global $forum_id, $topic_id, $post_id, $user_id;
626
627 if ($query['f']) {
628 $forum_id = $query['f'];
629 }
630 if ($query['t']) {
631 $topic_id = $query['t'];
632 }
633 if ($query['p']) {
634 $post_id = $query['p'];
635 }
636 if ($query['u']) {
637 $user_id = $query['u'];
638 }
639 }
640
641 } // if (variable_get("phpbbforum_page_frame", 0) == '2') {

  ViewVC Help
Powered by ViewVC 1.1.2