s9y Reversed Integration via Functions

Discussion corner for Developers of Serendipity.
Post Reply
mojiro
Regular
Posts: 6
Joined: Wed Jan 17, 2007 11:32 pm

s9y Reversed Integration via Functions

Post by mojiro »

Hello s9y people & developers,
that's my first post after the great meeting with forum's search engine :)

What I want (and propably others) is to intergrate s9y in my site. For my
bad luck I didn't discovered s9y earlier so to make my site be based on it.
Anyway...

In general I have understand how s9y works and with search & grep
I figured the code below, that gives me such good output to integrate
s9y easily to my site.

The code is ...

Code: Select all

<?php

$p_current = $_GET['p'];
$a_current = $_GET['a'];

$uurl = "40:30";

$olddir = getcwd();
$serendipity_directory = 'blog/serendipity/';
chdir($serendipity_directory);

include_once('serendipity_config.inc.php');
include_once('include/genpage.inc.php');

$serendipity['serendipityHTTPPath'] = '/';
$serendipity['indexFile'] = '';
$serendipity['implemnt'] = 'true';
$serendipity['yopath'] = $uurl . '&p=index&a=';

serendipity_plugin_api::generate_plugins('right', 'span');

$blog_out = serendipity_smarty_fetch('ENTRIES'      , 'entries.tpl', true);
$sidebar  = serendipity_smarty_fetch('sidebar_right', 'sidebar.tpl', true);

chdir($olddir);

?>
this code gives me 2 variables
$blog_out , has the entries... and
$sidebar , has the right plugins

also by changing $serendipity array, I can change internal s9y links
to show my site's internal links.

'implemnt' & 'yopath', $serendipity array variables, have been added
by me inside s9y code for greater flexibility on changing url's.

I'm just in the last step before the total integration & broswing s9y
with my site's layout. The only problem that I have is, that I cannot
find how can I pass global variables so to change the `Entries` content...

By default s9y uses
"index.php?/archives/2006/11.html" this kind of urls,

I have changed them to
"index.php?40:30&p=index&a=/archives/2006/11.html"

Where could I pass the $_GET['a'] variable at s9y so to change the
`Entries` content ?

I tried many things around $_SERVER & $_GET variables but nothing
with success.

What do you suggest ?
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Re: s9y Reversed Integration via Functions

Post by garvinhicking »

Hi!

Hm, that is a more difficult question.

The code that formats links is in include/functions_permalinks.inc.php, function serendipity_rewriteURL().

It uses the $serendipity['indexFile'] variable (which holds "index.php" usually) and appends a "?/" if no mod_rewrite is used.

So you can either patch up that function to include your stuff, or you could try if you set $serendipity['indexFile'] = 'index.php?:40:30&p=index&a=';

AND it is vital that you then set the s9y configuration "URL Rewriting" from "NONE" to "Apache Errhohandling". Else, s9y would still append a "?/" to your indexFile, and this would then introduce two "?"s and screw up the URL pattern.

Tell me if that works. :-)

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/
mojiro
Regular
Posts: 6
Joined: Wed Jan 17, 2007 11:32 pm

Post by mojiro »

if you mean this function

Code: Select all

function serendipity_rewriteURL($path, $key='baseURL', $forceNone = false) {
    global $serendipity;

    return $serendipity[$key] . ($serendipity['rewrite'] == 'none' || ($serendipity['rewrite'] != 'none' && $forceNone) ? $serendipity['indexFile'] . '?' . $serendipity['yopath'] . '/' : '') . $path;
}
I had already found it and modded it, by adding the $serendipity['yopath']
variable. That was easy and works just fine.

mod_rewrite is not being used.

My problem has nothing to do with the url creation, but with the Url
Queries that are being read from s9y.

s9y when parses its Url's waits for something like
"index.php?/archives/2006/11.html"

Underscored part is what it needs to find Entries for "November 2006"

Since I convert it, to
"index.php?40:30&p=index&a=/archives/2006/11.html"

how can I pass the (underscored) Query to s9y?
Where s9y parses Url's and understands the Url Queries ?

If it is not easily understable what I mean, you can visit my site
(nevermind for the irregular text encoding in Entries, I have just
changed it to English for the moment)
http://www.explode.gr/routing/index.php?40:30

and see that when you click, for example November 2006
it brings again the January Entries.

Since November (and other months) has no Entries it should bring
something like:
No entries to print
I think that, this is happening because s9y has no idea for what I
have in Url, and it just brings first's page Entries.

Propably there is a variable inside s9y code that carries the Url
Queries and I do not enumerate it with the way I did my integration.
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Post by garvinhicking »

Hi!

You could try to change $_SERVER['REQUEST_URI'] in your script, before you include the serendipity file. Serendipity uses that variable to detect it, so if you strip all your extra info from the variable, s9y will have a variable that just looks like usual!

Does that help? Basically the URL parsing is called from within index.php, I'd have to look it up if the tip above does not help.

HTH,
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/
mojiro
Regular
Posts: 6
Joined: Wed Jan 17, 2007 11:32 pm

Post by mojiro »

Propably not, since I do not use s9y's index.php

but...
I will search there inside to see what do you do with
$_SERVER['REQUEST_URI'] variable.

Thanks! I think you helped me enough for today.
mojiro
Regular
Posts: 6
Joined: Wed Jan 17, 2007 11:32 pm

Post by mojiro »

I finally did it! I (partialy) browse s9y from my site

$_SERVER['REQUEST_URI'] should have this format to

Code: Select all

$_SERVER['REQUEST_URI'] = "/" . $serendipity_directory . $p_current . ".php?" . $a_current;
$p_current, is page file
$a_current, is all s9y arguments

also you have to make a new index.php, in order to
include it at your site and make the apropriete mod's
at the same time.

lets say that the name of new index.php is indexed.php

you will comment out all header information like

Code: Select all

/*
// We need to set this to return a 200 since we use .htaccess ErrorDocument
// rules to handle archives.
header('HTTP/1.0 200');

// Session are needed to also remember an autologin user on the frontend
ob_start();
include('serendipity_config.inc.php');
header('Content-Type: text/html; charset='. LANG_CHARSET);

if ($serendipity['expose_s9y']) {
    header('X-Blog: Serendipity'); // Used for installer detection
}

if ($serendipity['CacheControl']) {
    if (!empty($HTTP_SERVER_VARS['SERVER_SOFTWARE']) && strstr($HTTP_SERVER_VARS['SERVER_SOFTWARE'], 'Apache/2')) {
        header('Cache-Control: no-cache, pre-check=0, post-check=0');
    } else {
        header('Cache-Control: private, pre-check=0, post-check=0, max-age=0');
    }
    header('Expires: 0');
    header('Pragma: no-cache');
}
*/
then you will include it after

Code: Select all

...
include_once('include/genpage.inc.php');
include('indexed.php');
...
(from the code I posted at the 1st post).

It is a bit complex but It works!
Of course there is compatility with the standard s9y, that is untouched
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Post by garvinhicking »

Hi!

Great you got it working! Maybe in the future you'll find some thinks you would like to contribute to our code :) :)

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/
Post Reply