Vanilla 1 is no longer supported or maintained. If you need a copy, you can get it here.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.

Programming help needed: how to perform a re-write of the entire page?

DavidKDavidK New
edited October 2007 in Vanilla 1.0 Help
A lot of work places block the URL's of community forums and so I've decided that I want to allow my users to use alternate URL's and domain names. So, if I have: I could also allow my users to reach the site via other friendly domain names: And if the worst comes to pass by the IP address: The problem I have is that I want them to be able to stay on the domain that they accessed via. And if someone posts a link to and someone else is viewing on then the viewer using the IP address shouldn't be bounced over to I've done this before with vBulletin and had something that looked like this in the piece of code that echoes the entire page out: <code> $findArray = array( '', '', '', '', '', '', '', '', '', '' ); $replaceArray = array( $vbulletin->options['bburl'], $vbulletin->options['bburl'], $vbulletin->options['bburl'], $vbulletin->options['bburl'], $vbulletin->options['bburl'], $vbulletin->options['bburl'], $vbulletin->options['bburl'], $vbulletin->options['bburl'], $vbulletin->options['bburl'], $vbulletin->options['bburl'] ); $vartext = str_replace($findArray, $replaceArray, $vartext); </code> Where options['bburl'] is the current URL, and $vartext contained the text of the page before it gets sent over the wire (the output buffer). You'll also note that those who access via SSL get to stay on SSL. So I know how to do this, but what I don't know and my question is: Where do I do this? As in... how can I add this piece of code or the equivalent to the code to allow it to take affect across all pages on the site and re-write the output HTML so that the URL's remain correct for the domain that the site is being accessed over?


  • edited October 2007
    Good news is that doing this with Vanilla should be much easier :-)

    Best place to add this would probably be to edit conf/settings.php.

    Near the top of that file, there is a line that looks something like this: $Configuration['BASE_URL'] = 'http://your.base.url/to/vanilla/';

    All you would need to do is read what URL the user is using, (I think $_SERVER['HTTP_HOST'] would be useful here) strip off anything that comes after 'forum/' and set it in that field. Another setting that is domain specific is the cookie domain, you might be able to get away with leaving it blank, but test out the sessions on each address you access the site with to make sure that it is possible to login.
  • Max_BMax_B New
    edited October 2007
    edited out, redundant.
  • WallPhone, That doesn't answer it I'm afraid. As I outlined, it may solve the navigational links and make those work, but it doesn't solve intra-site links posted within the comments themselves. I really need to replace all instances of one string in the output HTML with another string. So is there a place that is called at the end of every page in which the output buffer can be read and then modified?
  • themes/page_end.php contains the closing HTML tag, so that would be the earliest place you would want to grab and edit a output buffer.

    Grahack is going to release a caching extension soon that does a lot of work with output buffers, that would be a good one to work from.
  • What an advertising !!!
    I'm about to be ready, but there are still some important questions to be solved, like the general use of this file: themes/page_end.php
    I was about to decide to not caching it. I think I'm gonna ask the community...
  • "that does a lot of work with output buffers"
    It's not really true... I just check if a cache file could be used, if not, I let Vanilla execute fully, then grab the buffer to perhaps store it if cache is needed.
    What I recently decided is to include in the buffer (and before the closing tags, that's what is tricky), a custom string (benchmark tools).

    I found here some much heavier buffer processing!
  • edited October 2007
    A more interesting trick: if you ever want to change for another theme, just separate your parsing from the theme.
    Create a custom control that would be called after PageEnd.
    In this control, you simply grab the buffer and act on it as you need.

    This could be done in an extension (that you could share ;) ).
    Not tested. In a default.php file that you'll save under extensions/BufferTorture, write:
    <?php class BufferTorture extends Control { function BufferTorture(){} function Render() { $content = ob_get_flush(); // here you can torture your $content // ... echo $content; exit; } } $Page->AddRenderControl( $Context->ObjectFactory->NewContextObject( $Context, 'BufferTorture' ), pow(2,20) );
    Still the question, is it a clean way to execute as late as possible...
  • I've followed your advice and created this: It even has the same name. As a bonus I've added gzip of the output by default. Vanilla is now working over 4 domains and the IP address quite fine, so those who have been blocked now have a workaround. Cheers
This discussion has been closed.