Odd embedded behaviour

Having trouble installing serendipity?
Post Reply
TheCafFiend
Regular
Posts: 5
Joined: Mon Dec 05, 2011 7:17 pm

Odd embedded behaviour

Post by TheCafFiend »

Greetings all,

I have been reading through these forums for a bit as I have been using serendipity, and I have to say I am impressed with the helpfulness so far. I couldn't find anything related to my specific problem, so, here I am posting about it.

Background: The blog is embedded (yes, embedded, more on that shortly) at: http://www.maplelangley.com/jericho.php#1 . Now, it is embedded because of all of the custom formatting, php, etc, that is working in the background to serve up those pages: It is also embedded as a sort of "testing ground" for our next project (still all secret like) that will be even more dynamically generated, so it isn't really useful to (learn a new template language) and then try to modify a template so that it does all of the same dynamic generation... Including as we develop it, changing it multiple times, and therefore having to also go modify the s9y template. We really only choose serendipity in order to have a blog that we could embedd anywhere, and it worked great to start with, but we have started to run into some issues.

Now, the most obvious one is that if you go to http://maplelangley.com/serendipity_admin.php, you can see right away from the login screen that it is not loading the css. This was working before, when I had the "serendipity index file" option set to "ser-index-ser.php" which is what I ended up renaming the index.php provided with serendipity to. However, that means that it loads that file if you click on a blog entry to display just that entry, which of course had no formatting.

I created blog_wrapper.php, and set it as the index file, with all of our current custom formatting: That actually seemed to work, clicking authors, or blog posts, loaded the content in that page, exactly as I wanted. The relevant code from that is:

Code: Select all

<?php
// serendipity stuff:

$keygetter = array_keys($_REQUEST);

$urlpath = 'http://www.maplelangley.com/ser-index-ser.php?'; // set path to orig file

$urlpath .= $keygetter[0]; // append the variables passed to this file

$urlpath = str_replace('_', '.', $urlpath);

ob_start();
require $urlpath;
$blog_data = ob_get_contents();
ob_end_clean();

?>
And then it just echos blog_data later, mostly as per the embedding option listed on the s9y site.

Now, I assume as a result of that change, the admin backend does not appear to have the serendipity_admin.css file applied (Which as I understand, does not exist, but is generated somehow). Also, when the blog becomes long enough, the "next page" link does not work, linking to "http://www.maplelangley.com/blog_wrappe ... ho/P2.html", which returns an error indicating that the require line inside the wrapper is failing: "http://www.maplelangley.com/ser-index-s ... ho/P2.html"

My questions are:

How can I change this so the backend has CSS and looks pretty again? While I think black text on a white background is fine, end users do not always agree :)

How do I make the next page link work correctly? This seems odd to me given that the entry and author links work fine. Would it be better perhaps to embedd the original index file (now ser-index-ser.php) in an iframe within that tab? Any other suggestions? I am looking for things that are easy to maintain long term, as the end user may be requiring changes later in the sites lifecycle.

Let me know if there is any other info I can provide for help!
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Re: Odd embedded behaviour

Post by garvinhicking »

Hi!

Glad to hear from your experiments. Let's see how I can help. :-)

The first problem in your code is, IMHO, that you use a URL include. That's really a dirty way to do, because it leads to 2 apache requests for each of your page, where one should suffice.

So to get this properly off the ground, you should first rename ser-index-ser.php back to index.php. Ideally, you should never have to rename any s9y file even when embedding. The wrapper file now will get much more important. You need to set it as your "directory index file", like you actually already tried to.

Now that wrapper should simply include 'index.php', *without* the http:// part, so that no additional HTTP request will be performed:

Code: Select all

<?php
// serendipity stuff:
ob_start();
require 'index.php';
$blog_data = ob_get_contents();
ob_end_clean();

?>
Also make sure your .htaccess file always referrs to your wrapper PHP file, not index.php itself. The CSS itself is routed through the index file (i.e. your wrapper file and then the s9y file), so your own wrapper file might need some URL distiction rules to NOT create any of your output if special URLs like the CSS or RSS feeds are called.

If you use mod_rewrite, the most simple way of course would be just to change the rewriterules for CSS and RSS to refer to index.php instead of your wrapper php file.

Once that all works, the CSS should appear and we can go from there?

Best 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/
TheCafFiend
Regular
Posts: 5
Joined: Mon Dec 05, 2011 7:17 pm

Re: Odd embedded behaviour

Post by TheCafFiend »

Hi Garvin,

Thanks for the reply! I will start working on changing this over later today: In the meantime, will the "index.php" file (once it is renamed) be able to "see" the url variables being passed to the wrapper file? I am still learning PHP, but just as I wrote that I realized that if it is included it quite possibly still has access to those variables, that would make my whole translation and re-posting bit rather, well, dirty as you said.

My .htaccess should point to the actual front page, shouldn't it? That is currently "index.php" which is why I renamed serendipity's file, but I can easily change that and point the .htaccess at it: The embedded blog is more of a sub page.

I am a bit unclear on the functioning of mod_rewrite: Any handy links to point me to for some education about it? If I could set it up that way, it would be great, but I have to check if my hosting supports it, and I couldn't find any mention of it.

Alternativly, any examples of some php to check if the CSS or RSS URL is being called? I am fine modifying code so that the wrapper doesn't spit out the rest if it finds it, but finding it sounds potentially tricky. However mod_rewrite certainly sounds easier, I will check my host again.


Edit: So, I changed the file names around, and the CSS now applies to the admin area (which is awesome!) my .htaccess currently points to "overview.php", which is the home page. No mod-rewrite rules in my .htaccess, and my serendipity config index file is now set to blog_wrapper, which has no fancy logic to not pass anything else if it is called as a CSS sheet. However, I am assuming since the include is pretty much the first thing, it is passing the CSS first so the browser works fine. (Actually, when I checked by going to the URL, the only thing that seems to come out is the css. ) Blog_wrapper also now just includes "index.php" and doesn't do any magic to pass it variables, and all almost works.

The only problem left now, is that the "next page" link at the bottom of http://www.maplelangley.com/jericho.php#1 now loads the blog wrapper (Hooray not an ugly error!) but does not load the second page of results. The URl it goes to is: http://www.maplelangley.com/blog_wrappe ... ho/P2.html, which seems to me like it should be /archive/P2.html or something, so clearly I missed something. This URL loads the first page of the blog results. Is this because it is called from the page jericho.php? What is the easiest way to fix this? That blog is only one tab of a page with three tabs full of info, and changing the layout to put only the blog on onepage is going to be a hard sell, so I'd like to avoid it if I can.

Thanks so much for the help so far: When we are using an embedded serendipity for our next, larger project (starting soon) I will remember your paypal link.
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Re: Odd embedded behaviour

Post by garvinhicking »

Hi!

Great we're making progress. :)
but does not load the second page of results. The URl it goes to is: http://www.maplelangley.com/blog_wrappe ... ho/P2.html, which seems to me like it should be /archive/P2.html or something, so clearly I missed something. This URL loads the first page of the blog results. Is this because it is called from the page jericho.php? What is the easiest way to fix this? That blog is only one tab of a page with three tabs full of info, and changing the layout to put only the blog on onepage is going to be a hard sell, so I'd like to avoid it if I can.
That's true, it should basically go to blog_wrapper.php?/archives/P2.html.

Can you show the current configuration of your s9y permalink and path setup? And what your .htaccess looks like exactly? That "/jericho/" might stem from a problematic URL parsing logic that we use to deduce the proper HTTP path. This got changed a few times in the last years, and since not so many people use embedding it might be a glitch that we could try to fix together, if you have the patience to inspect this. :)
Thanks so much for the help so far: When we are using an embedded serendipity for our next, larger project (starting soon) I will remember your paypal link.
Much appreciated, thanks. But I do this for the fun of it, so don't feel pushed to do this - I'm happy enough if you enjoy using serendipity. :)

Best 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/
TheCafFiend
Regular
Posts: 5
Joined: Mon Dec 05, 2011 7:17 pm

Re: Odd embedded behaviour

Post by TheCafFiend »

I do like progress!

So, if I go directly to blog_wrapper.php?/archives/P2.html, then it displays the second page, so it would seem that it is just generating the wrong link, which seems a bit odd given that the rest of the links seem to work... I even made a post using the extended body just to check and see if that was working correctly. Anyways, info as requested:
.htaccess

Code: Select all

# BEGIN s9y
DirectoryIndex /overview.php

<Files *.tpl.php>
    deny from all
</Files>

<Files *.tpl>
    deny from all
</Files>

<Files *.sql>
    deny from all
</Files>

<Files *.inc.php>
    deny from all
</Files>

<Files *.db>
    deny from all
</Files>

# END s9y
This is fairly straightforward, pretty default stuff: I have to modify the directoryindex every time serendipity saves it though, because the blog page is not the front page of the site :)

As for my permalink and paths:
Info from serendipity config
Info from serendipity config
serendipityinfo.png (85.46 KiB) Viewed 7455 times
Most of that is default: I think I modified the relative path perhaps?

Let me know if there is any other info that would be useful!
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Re: Odd embedded behaviour

Post by garvinhicking »

Hi!

Okay, let's try to tackle this one by one, do you have some patience? *g*

One question - you link to "jericho.php" - why exactly is that? You should actually link to the wrapper itself: http://www.maplelangley.com/blog_wrapper.php -- once you do that, the next/previous page links do show up properly!

Best 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/
TheCafFiend
Regular
Posts: 5
Joined: Mon Dec 05, 2011 7:17 pm

Re: Odd embedded behaviour

Post by TheCafFiend »

garvinhicking wrote:Hi!

Okay, let's try to tackle this one by one, do you have some patience? *g*

One question - you link to "jericho.php" - why exactly is that? You should actually link to the wrapper itself: http://www.maplelangley.com/blog_wrapper.php -- once you do that, the next/previous page links do show up properly!

Best regards,
Garvin

Huh, it does work that way. Interesting. Jericho is a page with three tabs, the blog is only one of the tabs, that is why I had setup another file as the wrapper: Basically so if someone clicked on a title of a blog, it would go to a page with just blog contents. The top section of jericho.php and blog_wrapper.php are identical:

Code: Select all

ob_start();
require 'index.php';
$blog_data = ob_get_contents();
ob_end_clean();
I would tend to think this would make them generate the same links. I even checked, both php segments are early in the head section, blog_wrapper called my main stylesheet just before the serendipity bit above, but jericho had it slightly after. This had no effect, but reading your post I realized that there was really no reason to use a different file as a wrapper anyways: When I set jericho.php to be the wrapper, everything worked, remarkably enough, even though it generates a lot of extra stuff even if called as a CSS sheet or anything.

Is there any impact (besides server performance) of it generating all of that? Also, is it easy to disable it?

Thanks so much for the assistance in resolving this. I have local copies of most of this, and a small local server, so let me know if I can help, if you want to chase down what was causing it to generate that odd link to the archives.

This resolution is even better because it does not break them out of the tabbed page into another page.
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Re: Odd embedded behaviour

Post by garvinhicking »

Hi!

Yes, definitely only using a single wrapper is the best way to go with.
Is there any impact (besides server performance) of it generating all of that? Also, is it easy to disable it?
You could try to change the wrapper to:

Code: Select all

ob_start();
require 'index.php';
$blog_data = ob_get_contents();
ob_end_clean();

if ($serendipity['view'] == 'css' || $serendipity['view'] == 'plugin') {
  echo $blog_data;
  exit;
}
That should make the process end, when the CSS view is used.

Glad to hear that we're near the final solutioon! :)

Best 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/
TheCafFiend
Regular
Posts: 5
Joined: Mon Dec 05, 2011 7:17 pm

Re: Odd embedded behaviour

Post by TheCafFiend »

Sorry for the delay, I was out of town for the weekend, which I really only got to do because all of this was working :D

Everything seems to be working just fine now: I appreciate your taking the time to answer a small usage case!
Post Reply