/[drupal]/contributions/modules/phpbb2drupal/phpbb_redirect.module
ViewVC logotype

Contents of /contributions/modules/phpbb2drupal/phpbb_redirect.module

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


Revision 1.10 - (show annotations) (download) (as text)
Fri Apr 11 16:35:21 2008 UTC (19 months, 2 weeks ago) by nbz
Branch: MAIN
CVS Tags: DRUPAL-6--2-0-BETA1, DRUPAL-6--2-0-BETA2, DRUPAL-6--2-0-BETA3, DRUPAL-6--2-1, DRUPAL-6--2-0, HEAD
Changes since 1.9: +18 -12 lines
File MIME type: text/x-php
#245643 - improved post redirection. Also menu fixes for Drupal 6.2
1 <?php
2 // $Id: phpbb_redirect.module,v 1.9 2008/03/13 23:56:39 nbz Exp $
3 /****************************************************
4 * phpbb_redirect module: redirects links incoming from old phpBB forum to new Drupal forum.
5 *
6 ****************************************************/
7
8 /****************************************************
9 *
10 * Implementation of hook_help()
11 *
12 ****************************************************/
13 function phpbb_redirect_help($path, $arg) {
14 $output = '';
15 switch ($path) {
16 case 'admin/help#phpbb_redirect':
17 $output = '<p>'. t('Redirects links to your old phpBB installation to the new Drupal forum.') .'</p>';
18 $output .= '<p>'. t('This module requires <a href="@cleanurls">clean urls</a> to be active.', array('@cleanurls' => url('admin/settings/clean-urls'))) .'</p>';
19 $output .= '<p>'. t('phpBB_Redirect assumes that the old forum was located in the /forum folder. If that is not true, redirection will not work.') .'</p>';
20 $output .= '<p>'. t('This can be worked around by either adding a redirect in the .htacceass file on apache installations or by manually editing the module.') .'</p>';
21 $output .= '<p>'. t('If you choose to edit the module, all you need to do is change "forum/viewtopic.php" and "forum/viewtopic.php" in the "phpbb_redirect_menu" function. Just replace the "forum" bit with the real old location. e.g. if the old forums were located in the phpbb folder, change these paths to "phpbb/viewtopic.php" and "phpbb/viewtopic.php".') .'</p>';
22 break;
23 }
24 return $output;
25 }
26
27
28 /****************************************************
29 *
30 * Implementation of hook_menu()
31 *
32 ****************************************************/
33 function phpbb_redirect_menu() {
34 $items = array();
35
36 $items['forum/viewtopic.php'] = array(
37 'title' => 'Topic Redirect',
38 'page callback' => 'phpbb_redirect_viewtopic',
39 'access callback' => TRUE,
40 'type' => MENU_CALLBACK
41 );
42 $items['forum/viewforum.php'] = array(
43 'title' => 'Forum Redirect',
44 'page callback' => 'phpbb_redirect_viewforum',
45 'access callback' => TRUE,
46 'type' => MENU_CALLBACK
47 );
48
49 return $items;
50 }
51
52 function phpbb_redirect_viewtopic() {
53 if (isset($_GET['t']) && is_numeric($_GET['t'])) {
54 $topic_id = $_GET['t'];
55
56 $nid = db_result(db_query('SELECT nid FROM {phpbb2drupal_temp_topic} WHERE topic_id = %d', $topic_id));
57
58 header('HTTP/1.1 301 Moved Permanently');
59 drupal_goto("node/$nid");
60
61 }
62 else if (isset($_GET['p'])) {
63 $post = explode('#', $_GET['p']);
64 if (is_numeric($post[0])) {
65 $post_id = $post[0];
66 }
67 else {
68 drupal_goto('/');
69 }
70
71 $cid = db_result(db_query('SELECT cid FROM {phpbb2drupal_temp_post} WHERE post_id = %d', $post_id));
72 $nid = db_result(db_query('SELECT nid FROM {comments} WHERE cid = %d', $cid));
73
74 $node = node_load($nid);
75 $mode =_comment_get_display_setting('mode', $node);
76
77 $flat = in_array($mode, array(COMMENT_MODE_FLAT_COLLAPSED, COMMENT_MODE_FLAT_EXPANDED));
78 if ($flat) {
79 $comments_per_page = _comment_get_display_setting('comments_per_page', $node);
80 $comment_count = db_result(db_query('SELECT COUNT(c.cid) FROM {comments} c WHERE c.nid = %d AND c.status = %d AND c.cid < %d', $nid, COMMENT_PUBLISHED, $cid));
81 $page_number = floor($comment_count / $comments_per_page);
82 }
83
84 if (empty($page_number)) {
85 $pagenum = NULL;
86 }
87 else {
88 $pagenum = 'page='. intval($page_number);
89 }
90
91 header('HTTP/1.1 301 Moved Permanently');
92 drupal_goto("node/$nid", "$pagenum", "comment-$cid");
93 }
94 }
95
96 function phpbb_redirect_viewforum() {
97 if (isset($_GET['f']) && is_numeric($_GET['f'])) {
98 $forum_id = $_GET['f'];
99
100 $tid = db_result(db_query('SELECT tid FROM {phpbb2drupal_temp_forum} WHERE forum_id = %d', $forum_id));
101
102 header('HTTP/1.1 301 Moved Permanently');
103 drupal_goto("forum/$tid");
104 }
105 }
106

  ViewVC Help
Powered by ViewVC 1.1.2