Embedding Serendipity in Something Else
This is not the recommended way to embed with Serendipity. Frankly, it's just a pain to get all the configuration correct. We highly recommend that you embed your "Something Else" into Serendipity, instead.
So, you're determined, eh? Well, then...
The Basics
Serendipity will not run correctly unless it is called from the proper directory. Since it is a PHP program, you'll also need to call it using the proper PHP syntax. Here's the very simplest case:
<?php
chdir("<serendipity_dir>");
require("index.php");
chdir("<original_dir>");
?>
The first line changes to the serendipity directory (substitute the correct directory for <serendipity_dir>, of course). The second actually runs Serendipity and prints everything out. The third switches back to your original directory (naturally, substitute <original_dir>).
You can also save the output to be used later, instead of printing it immediately. This is especially useful if you're embedding Serendipity into a PHP program. One way to save the output is like this:
<?php
ob_start();
chdir("<serendipity_dir>");
require("index.php");
chdir("<original_dir>");
$serendipity_contents = ob_get_contents();
ob_end_clean();
?>
The "ob" stands for "output buffer". This captures the previous stuff into a buffer, gets the contents of the buffer into $serendipity_contents, and then ends the capturing. Now you can just print $serendipity_contents anywhere you want the blog to show up.
Note that this can used as a "wrapper"; it's a little PHP file that calls Serendipity and stores the contents in a variable. For instance, if you saved it as "serendipity_wrapper.php" in any directory, you could then
require("<full_path>/serendipity_wrapper.php");
and you'd get a variable containing $serendipity_contents that you could use anywhere. Neat, eh?
It's more than just neat. If you get errors saying "Warning: Cannot modify header information - headers already sent", you'll need to use the wrapper. No output is allowed before calling Serendipity, so you'll have to call it first. If you want the Serendipity output anywhere other than at the top of the file, you'll need to store the output in a variable and use it later. Here's an example:
<?php
require("wrapper.php"); // stores S9Y in a variable
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"
http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="
http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>
<body>
Your non-Serendipity content goes here.
<?php
echo $serendipity_contents; // Print the variable
?>
More non-Serendipity content here.
</body>
</html>
Just calling Serendipity in the middle of the HTML could have caused the "header already sent" error.
Changing Serendipity's Embedded Appearance
So, now you've got Serendipity embedded, and you'd like to change its appearance. By default, Serendipity attempts to provide its theme and sidebars.
Removing theming and header HTML
To remove the theming and header HTML, go to your admin page and change the configuration. Find the setting for "Is Serendipity embedded?" and change it to "Yes". Now Serendipity will output only its HTML; no stylesheet will be included, and no <HTML>, <HEAD>, or <BODY> tags.
Sidebars are easier, and a bit more obvious. Go to your admin page, choose "Configure Plugins", and set all the sidebar plugins to "Hidden". You could choose to remove them, too. Serendipity will no longer print sidebars.
Other appearance changes
Of course, you can also set variables in your wrapper that affect Serendipity before calling it. More on this as more people get time to update this document.
Known Issues
If you use compressed output buffering, you might get blank pages when embedding Serendipity. This is because multiple gzipped page buffers might not go well with each other. The solution to this is to turn off output compression in the Serendipity or PHP configuration.