Setting up embedded blog

Having trouble installing serendipity?
Post Reply
claudermilk
Regular
Posts: 9
Joined: Sat Sep 06, 2008 3:55 am

Setting up embedded blog

Post by claudermilk »

I've just set up this blog software for my wife's new webpage (not quite yet live) and thought I'd share a few things I learned along the way.

I wanted to maintain the formatting of the overall page, so insisted on going the embed-Serendipity-in-a-page route. Honestly, the documentation while accurate is extremely hard to puzzle out. Even for this programmer. I did finally get it working however. So, here is what I learned.

In the page you are going to embed the blog in (call it blog.php), you must start the page with the famous require block:

Code: Select all

<?php
ob_start();
chdir("<serendipity_dir>/");
require("index.php");
chdir("<original_dir>/");
$blog = ob_get_contents();
ob_end_clean();
?>
Note, there is NO indentation. This is important if you want the RSS/ATOM feeds to work correctly. If you indent this block, the XML definition line wil be indented and not work. Also note, the <?php line is the VERY FIRST ONE--again, any comments before it will get included in the feed XML and break it.

Next, in the main body of the page, wherever you want the blog to appear:

Code: Select all

<?php
echo $blog;
?>
Name the page with .php and Chmod it to be executable. Otherwise it can be your basic everyday HTML page.

Now, in the admin control panel, you must go to the Configuration>Paths page and set your index file name to the page the blog is embedded in.

So as an example, I have Serendipity loaded in a subdirectory called "blog", the include block looks like this:

Code: Select all

<?php
ob_start();
chdir("blog/");
require("index.php");
chdir("../");
$blog = ob_get_contents();
ob_end_clean();
?>
and my index page is called blog.php, so the admin panel setting is "../blog.php". Note the relative paths and trailing slashes.

I also experimented with the separate wrapper method. The only changes are the wrapper file (wrapper.php) consists entirely of the beginning require block above. In blog. php the beginning block is simply

Code: Select all

<?php
require("wrapper.php");
?>
Finally, change the admin panel index file setting to "../wrapper.php".

I stuck with the first method as there is one fewer files for manage. Simpler is better.

So to sum up:
  • Insert the main php block reading the Serendipity index page at the very beginning of your file.
  • Insert the echo statement block where you want the blog to appear within the page.
  • No indentation for RSS/ATOM to work.
  • Set the control panel Configuratio>Paths>index file to the file name that you are embedding in.
Hope this helps someone trying to make heads or tails of the method required to make this work.
judebert
Regular
Posts: 2478
Joined: Sat Oct 15, 2005 6:57 am
Location: Orlando, FL
Contact:

Post by judebert »

Thanks for the writeup! I admit the docs are difficult to understand. Then again, so is embedded mode.

Actually, I'm kind of surprised that a relative path worked for the indexfile. Did you have problems with the absolute path, or did the relative path just work for you in the first place?
Judebert
---
Website | Wishlist | PayPal
claudermilk
Regular
Posts: 9
Joined: Sat Sep 06, 2008 3:55 am

Post by claudermilk »

The relative paths just worked in the first place, and seemed like the logical thing to do at first.
claudermilk
Regular
Posts: 9
Joined: Sat Sep 06, 2008 3:55 am

Gone live

Post by claudermilk »

FYI, I have finally gotten this page live--DNS just propagated a couple of hours ago. 3 month's work from a box-o-parts from newegg to a functioning server with virtual hosting serving a small handful of sites...it's been a long road.

The blog can be found here: http://www.saviyadances.com/blog.php

A final couple of glitches hit me. Loading on the local network set up all the wrong paths so the admin access severely broke. Strangely it was still serving the content. Anyway, a quick reinstall retaining the db fixed that. The only thing that foiled me was I wanted to set up the TinyMCE WYSIWYG editor, but no combination of URLs would convince it to work (I searched here and tried everything, no joy), so went back to FCKEditor. Not quite as polished, but has the advantage of functionality.

Forums like this one have been invaluable for the multitude of tasks and problem-solving required to get a server up and running.
delakut
Posts: 2
Joined: Fri Oct 15, 2010 2:49 pm

Re: Setting up embedded blog

Post by delakut »

The thread from 'claudermilk' helped me to set up an embed blog in my homepage. It worked quite good except for a few problems after the chances. Maybe others had the same problems and are still looking for a solution. I try to write down what problems I had and how I solved them.

4 problems and solutions:
1. Like 'claudermilk' already wrote the <?php ob_start() … ob_end_clean(); ?> block has to be in the very first line of your code. It’s not only about the RSS/ATOM, feeds the login plugin will also not work correct.

2. The biggest problem was that the ‘next page’ link always redirected me to my front page and not to the second page.
Solution: Go in the ‘Serendipity Administration Suite’ to 'Appearance and Options' under ‘Configuration’ and set ‘URL Rewiting’ to ‘Use Apache errorhandling’ or ‘Use Apache mod_write’. The .htaccess file in the serendipity folder has to be writeable.

3. Another problem was that the plugins ‘serendipity_event_loginform’ and ‘serendipity_plugin_loginform’ did not recognize the ‘Save information’ input on my start page. If I closed my browser I had always to login again.
Solution: I made a few chances in the functions_config.inc.php and functions_permalinks.inc.php.

In the functions_config.inc.php I replaced the variable ‘$serendipity['serendipityHTTPPath']’ with a ‘/’ in two functions. With this changes cookies are not limited anymore to the serendipity folder and can also be read under the root folder.

Original code:

Code: Select all

setcookie("serendipity[$name]", $value, time()+60*60*24*30, $serendipity['serendipityHTTPPath'], $host, $secure);
New code:

Code: Select all

setcookie("serendipity[$name]", $value, time()+60*60*24*30, '/', $host, $secure);
Original code:

Code: Select all

setcookie("serendipity[$name]", '', time()-4000, $serendipity['serendipityHTTPPath'], $host);
New code:

Code: Select all

setcookie("serendipity[$name]", '', time()-4000, '/', $host);
Under the functions_permalinks.inc.php I modified the ‘$url’ variable.
Original code:

Code: Select all

$url = $serendipity['serendipityHTTPPath'] . $serendipity['indexFile'] . '?' . $uri['path'] . $qst;
    
    $url = str_replace(
        array(
            $serendipity['indexFile'] . '&',
            '"',
            "'",
            '<',
            '>',
            '`'
        ),

        array(
            '',
            '',
            '',
            '',
            ''

        ),

        $url);
New code:

Code: Select all

$url = $serendipity['indexFile'] . '?' . $uri['path'] . $qst;

    $url = str_replace(
        array(
            $serendipity['indexFile'] . '&',
            '"',
            "'",
            '<',
            '>',
            '`',
            '..'
        ),

        array(
            '',
            '',
            '',
            '',
            '',
            ''
        ),

        $url);
4. Another problem occurred as I used Google webmaster tools to see how my page appears to Google. I got a 404 "Not found" error even though I didn’t get any error messages from Firefox or IE. I got this error only if I called my page with the pure host adress without the index.html file behind it.
Solution: Add 'if ($uri == '/') {$uri = '/index.html';}' in the index.php in the serendipity root folder.

New Code:

Code: Select all

$track_referer = true;
$uri = $_SERVER['REQUEST_URI'];
if ($uri == '/') {$uri = '/index.html';}

$serendipity['uriArguments'] = serendipity_getUriArguments($uri);
I hope I could help some of you and maybe give a few suggestions.
I’m not a programmer. So if you use my suggestions you do it on your own risk :)
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Re: Setting up embedded blog

Post by garvinhicking »

Hi!

Thanks a lot for sharing this! I am sure some people will definitely find this helpful. I didn't have the time right now to check your changes, but as long as they work for you it's worth putting them here!

Regards,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
Post Reply