G2 in Textpattern with URL Rewrite

paularms's picture

Joined: 2005-05-16
Posts: 13
Posted: Sat, 2005-07-30 00:24

Has anyone successfully embedded G2 into Textpattern? I did a search but came up with nothing.

How Textpattern works:
There is one index.php page, an admin section, a database, and some awesome URL Rewriting (lots of formats). Templates are all stored in the database. The index.php page pretty much just calls the config and publish files in the textpattern directory and parses everything from there.

I've used just some general php embedding, per the instructions, and tested, which works fine. With Textpattern URL Rewrite, I can access the page using both /photos/ or /index.php?s=photos and both return the same result, just the page with all image links broken. Clicking a link will just show you the main gallery page again, never showing an album or item. The problem is that I really want to use the Gallery2 URL Rewrite module, but it doesn't work out-of-the-box.

So I'm going to include a little code here and hopefully it's enough to at least get on the right track towards solving my problem.

Here is the Textpattern .htaccess code, which is subject to change...

 RewriteEngine On
 RewriteCond %{REQUEST_FILENAME} -f [OR]
 RewriteCond %{REQUEST_FILENAME} -d
 RewriteRule ^(.+) - [PT,L]
 RewriteRule ^(.*) index.php

The following is the extremely generic code that I'm using in Textpattern just for testing purposes, whether or not that matters.

$ret = GalleryEmbed::init(array(
	'embedUri' => 'index.php?s=photos', embedPath => 'photos/', 'relativeG2Path' => '../gallery/'));
if ($ret->isError()) {
	$ret->getAsHtml(); // has error details..

$result = GalleryEmbed::handleRequest();
if ($result['isDone']) {
	exit; // G2 has already sent output (redirect or binary data)
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
	<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<?php echo $result['headHtml']; ?>
echo $result['bodyHtml'];

Edit... I'll be using CVS update periodically for G2 until there's a 1.0 final. Right now I'm on G2B4, aka Flippin' Sweet


Joined: 2003-01-04
Posts: 32509
Posted: Sat, 2005-07-30 01:02

in your textpattern .htaccess file, you'll have to add the g2 rewrite rules too.
that means:
1. browse to your g2 within textpattern,
2. click on site admin
3. click on url rewrite
4. enter the embed stuff, click save
5. go to the rules tab, click save

at this point, it will have added the g2 rewrite rules to your existing textpattern htaccess file. maybe you'll have to change the order to make it work.

paularms's picture

Joined: 2005-05-16
Posts: 13
Posted: Sat, 2005-07-30 06:00

No matter what I try, my server is returning a "too many redirects" error.

I think the problem stems from having to first redirect /index.php and then redirect the gallery main.php

paularms's picture

Joined: 2005-05-16
Posts: 13
Posted: Sat, 2005-07-30 20:59

Ah HA! I figured it out...

This is really the only part of the htaccess code that is needed. Ignore the rewritebase and the first set of conditions in the G2 .htaccess.

Here is the solution to my problems: photos is the section that has the G2 embed in the page template. So for the rewrite rule, we must first write to /index.php, call the section variable and then call the g2 variables. It all seems to easy now.

RewriteCond %{QUERY_STRING} view=core.DownloadItem
RewriteCond %{QUERY_STRING} itemId=([0-9]+)
RewriteCond %{HTTP_REFERER} !://paularmstrongdesigns\.com/ [NC]
RewriteRule .   /photos/main.php?g2_view=watermark.DownloadItem&g2_itemId=%1   [L]

RewriteCond %{THE_REQUEST} \ /photos/([^?]+)(\?.|\ .)
RewriteCond %{REQUEST_FILENAME} !main\.php
RewriteRule .   /index.php?s=photos&?g2_view=core.ShowItem&g2_path=%1   [QSA,L]

Of note, this only seems to work with the watermark rewrite and view item rewrites, not with the view or add comments, download item, or slideshow views.


Joined: 2004-11-01
Posts: 133
Posted: Mon, 2005-08-29 20:13

This is a fantastic idea, integrating txp with G2.

Johnworfin's picture

Joined: 2005-09-15
Posts: 36
Posted: Thu, 2005-09-15 16:54

tag for future reference