Comments

s1dd’s picture

I am having the same exact issue as described and really need a fix. Any help would be appreciated T_T

Katou’s picture

Status: Active » Needs review

Hi,

I had a similar problem, although instead of getting a page not found I was redirected to the index of the forum. I write a fix for the issue I experienced, and it sounds like your issue is basically the same.

For mod author; The issue is related to $user->page not being set properly in phpbb. The values are the same on every page. I didn't want to go butchering up the PHPBB code so here's a fix for the module. It's probably not the best way at all, but gives you something to work with. Actual line that causes this issue in code fix comment.

Add this to the closing statement of function _phpbbforum_replace_urls after line 44 in phpbbforum.hooks.inc (It's in the module folder)

Original:

  }

  return $output;
}

Fixed:

  }
  //VB (katou)
  // MCP action fix. In PHPBB's /includes/functions.php  line 2883, $user->page['page'] does not get set properly in embedded mode, 
  // It's always set as index.php , instead of changing to mcp.php.
  // This causes the "Do you want to do this action?" confirm box's action to always set to index.php, instead of mcp.php.
  // The following code checks what the action is, and rewrites index.php into mcp.php. 
  // NOTE: the "approve" action is an array.
    $action1 = $_POST['action'];
    if((is_array($action1))) {
        $action1 = array_values($action1);
        $action1 = (strtolower($action1[0]));    
    }
    switch($action1) {
        case "queue":
        case "approve":
        case "disapprove":
        case "delete":
        case "delete_topic":
        case "unlock":
        case "lock_post":
        case "unlock_post":
        case "make_normal":
        case "make_sticky":
        case "make_announce":
        case "make_global":
        case "move":
        case "split_all":
        case 'fork':
        case 'delete_topic':
        case 'delete_post': 
            $output = str_replace("index.php", "mcp.php", $output); 
            break;
        default:
            break; 
    }
    //\VB (katou)
  return $output;
}

This should restore most of the functionality to the MCP. I may of missed something here and there though, but hopefully it's enough for the mod author to release a real fix in the next patch.

jmomandown’s picture

Where in the code do you find the machine action names in phpbb? I extend this work around for add friend and foes as well as the ucp functionality for a few MOD's

Lula’s picture

I'm using the 7.x-1.x-dev version and Phpbb 3.0.10.

I don't know why my particular embeded set up did this, or if anyone else finds the same problem, but whilst the above code worked for a large number of the site actions where the quickmod was concerned (many thanks to Katou for posting this), a lot of other actions still failed to work correctly and would still be sent to the wrong URL after giving the confirm box. After a bit of poking about in the code (I'm not a coder, I'm a newb and learning) I realised that some urls should have been going to other files such as posting.php and simply needed to be directed back to their original destination again.

It's probably not the best way to do it, but 'may' help someone as it appeared to fix my issue. So here's my additional bit of code for what it's worth.

Place the following between 'default:' and 'break;' in Katou's code above...

/** If the current page with the meta-redirect isnt index.php
 *  and isnt picked out by a specific action, then we need to
 *  make sure that we return the new url with the current file
 *  in use as the destination.
 */	
        $url = $_GET['q'];
	$url = str_replace("phpbbforum/", "", $url);
	   if ($url != "index.php") {
		$output = str_replace("index.php", $url, $output);
       }    

I don't know if this will fix all the issues, if it will work with whatever particular embedded setup you maybe using, or even what the long term repercussions of using it will be, so add it at your own risk, but if we're lucky it may just save someone else a few hours of head scratching :)

mholve’s picture

Between Katou and Lulu's two code snippets inserted into phpbbforum.hooks.inc I was able to fix my issue(s)! Hooray!

Many thanks, guys.

kanted’s picture

When I click yes to confirm the deletion of a post. It used to bring me back to index page without action performed.Applied the Katou and Lulu's and it worked

~smiles
Vk

haffmans’s picture

The way I solved this (I got completely wrong paths due to a somewhat custom setup, in several places):

In phpbb/includes/functions.php, around line 4003, add in an extra call to _phpbbforum_replace_urls():

                        $template->set_filenames(array(
                                'body' => 'message_body.html')
                        );

                        //VB
                        if (defined('PHPBB_API_EMBEDDED'))
                        {
                                $msg_text = _phpbbforum_replace_urls($msg_text, true);
                        }
                        //\VB

                        $template->assign_vars(array(
                                'MESSAGE_TITLE'         => $msg_title,
                                'MESSAGE_TEXT'          => $msg_text,
                                'S_USER_WARNING'        => ($errno == E_USER_WARNING) ? true : false,
                                'S_USER_NOTICE'         => ($errno == E_USER_NOTICE) ? true : false)
                        );

In the module's phpbbforum/phpbbforum.hooks.inc in function _phpbbforum_replace_urls(): make $user global, and use $user->page['page_dir'] . '/' in the $str array as well (you may even be able to remove the '../' entry, I'm not 100% sure):

/**
 * replaces urls.
 */
function _phpbbforum_replace_urls($output, $decode = false) {
  global $phpbb_config, $site_forum_url, $site_base_url, $site_phpbb_page, $site_phpbb_page_lang, $phpbb_root_path, $user;

  if (strpos($output, $site_base_url . $phpbb_root_path) !== false) {
    $output = str_replace($site_base_url, '', $output);
  }

  $phpbb_url = $phpbb_config['forum_url'];
  $q_phpbbforum = 'q=' . $site_phpbb_page;
  $q_phpbbforum_lang = 'q=' . $site_phpbb_page_lang;
  
  $str = array($user->page['page_dir'] . '/', '../', '/index.php?' . $q_phpbbforum_lang, '/index.php?' . $q_phpbbforum);
  if ($decode) {
    $output = urldecode($output);
  }
  $output = str_replace($str, '', $output);
  if (strpos($output, $site_forum_url) === false) {
    $output = str_replace($phpbb_url, $site_forum_url, $output);
    $output = str_replace($phpbb_root_path, $site_forum_url . '/', $output);
  }

  return $output;
}

Finally I also had to modify the phpbbdrupalbridge/phpbb_api_hooks.php file to get the ucp/mcp actions correct. The trick is similar to the above. Around line 211 in that file:

/**
 * replaces cp_action.
 */
function _phpbbforum_replace_cp_action($p_class, $output) {

  global $phpEx, $user;

//   $output = str_replace('../index.' . $phpEx, $p_class . '.' . $phpEx, $output);
  $output = str_replace($user->page['page_dir'] . '/index.' . $phpEx, $p_class . '.' . $phpEx, $output);
  
  //$output = str_replace('../index.php', $p_class .'.php', $output);
  $output = str_replace('&', '&', $output);

  return $output;
}

In this last case I did replace the old '../index.' replacement with the new one, and have not yet encountered any issues.

I must admit I haven't thoroughly tested my solution yet, but so far it seems to do the trick - the module's hooks rewrite the URLs and links properly to the desired form, whereas previously I had links pointing to ../../../drupal/index.php (as I said: custom setup - Drupal and phpBB aren't very close to each other in the installation).

thijsvdanker’s picture

StatusFileSize
new1.39 KB

I haven't dived into the why, but Katou's code in #2 and Lula's in #4 together fixed the issue for me.
I've attached their code in the patch.

thijsvdanker’s picture

Version: 7.x-1.0-alpha3 » 7.x-1.x-dev
Component: User interface » Code
stompeduns’s picture

#2 and #4 together worked great for me too. Finally I can delete posts. :D

Valera Tumash’s picture

#2 and #4 together have worked for me as well. phpbb v3.0.10

MathieuMa’s picture

Gosh, thanks for this ... i've been fighting with it since half a day ... !!!
I tried the cleaner method, but it didn't worked - too tired to check it out more.

Countzero’s picture

Issue summary: View changes

Thanks a ton to #2, #4 and #8. You guys rock.

shirisha2325’s picture

Hello

Im using Drupal 7.38 and PHPBB 3.0.12 versions and my database is
mysql 5.. The problem is that i have selected the option of phpbb display way
as "In the drupal page".. Whenever the click the url it is automatically
adding the word forum to the url and displaying the error "Page not found"

For example the original url is
http://www.example.in:8080/drupal7/forum/viewforum.php?f=5 it is showing as
http://www.example.in:8080/drupal7/forum/forum/viewforum.php?f=5. Please help
me..

Thankyou

shirisha2325’s picture

Issue summary: View changes
Status: Needs review » Active
shirisha2325’s picture

Issue summary: View changes