EmbeddedGallery

Note: The recipes here are for PmWiki versions 0.6 and 1.0 only. For PmWiki 2.0 recipes, see Cookbook.


tarta.

Goal

To try and describe how one user was able to embed the Menalto Gallery inside of PmWiki.

Solution

NOTE: Proceed at your own risk!

This recipe assumes you are starting off with an unmodifed version of Gallery. If you have customized your Gallery install already, then please be careful and do not overwrite your changes with mine. Also, these changes were made to Gallery 1, I have not tried out Gallery 2. The changes should work with just any version 1 Gallery.

This is not going to be simple modification because to get this working requires some ugly hacks.

  • Download and unpack the zip file located in the files section of this recipe. This zip file can not just be dropped in place (sorry). It contains some drop in code and some files that just contain code segments.
  • Upload the files gallery/html_wrap/wrapper.footer and gallery/html_wrap/wrapper.header from the zip file to the html_wrap directory of your Gallery installation. Make sure that you do not overwrite any custom modifications you have already made. These two files form the meat of the embedding:
    • wrapper.header - Turns on output buffering so that everything output by Gallery can be saved into a variable
    • wrapper.footer - Does all the work of displaying Gallery with your PmWiki style. It sets up custom view handler and then sources the pmwiki.php file so that it performs the page displaying.
  • Take a look at the file gallery/config.php from the zip file. This file contains templates for the variables that need to be added to your config.php file. You need to modify the following varable:
    • $PMWIKI_BASE_DIR - Point this to where pmwiki.php is stored
Optionally if you are using my UserAuth software, set up the following variables. If you don't use UserAuth you can probably ignore them:
  • $HTPASSWD_CODE_DIR - Point this to where the HtPasswd.php class is stored
  • $HTPASSWD_FILE - Point this to the .htpasswd file used for your UserAuth install
  • You may now need to modify the util.php file in your Gallery installation. I had to change one line of code so that URL rewriting would be active even though the Gallery is embedded. The way we have embedded Gallery still allows URL rewriting to function. I had to change this line:
	if (!$GALLERY_EMBEDDED_INSIDE && $gallery->app->feature["rewrite"]) {
To this:
	if ($gallery->app->feature["rewrite"]) {
  • Upload the file pmwiki/local/register_globals.php from the zip file to the local directory under your PmWiki installation. This file basically is a hack to get around the fact that when we load the pmwiki.php code from inside of Gallery the variable scopes is different and hence all of PmWiki's global variables are no longer global. Does that make any sense? Any ways this file is loaded by Gallery and sets up all the global variables that PmWiki will need. NOTE: Your installation of PmWiki may have more global variables than listed in my version. If so then you need to generate your own register_globals.php file. To do this, modify your pmwiki.php code so that it outputs the Php $GLOBALS array after all config files have been loaded and it is just about to call the read handler.

The code to do this is something like this:

  foreach(array_keys($GLOBALS) as $g) {
     print "global \$$g;<BR>";
   }
   exit;

Place the above code right before the following line in pmwiki.php

   $HandleActions[$action]($pagename);

Make sure to edit out all the global variables that do not look like WikiWords.

If you are having problems with your embedding of Gallery within PmWiki then it is most likely the result of a global variable not being included in register_globals.php. If you are having a problem then you probably need to create your own version of this file.

  • Look at the file pmwiki/local/config.php from the zip file. It contains the following snippet of code that you need to put in your PmWiki config.php file. It basically senses that PmWiki is being called from inside of Gallery and sets the browse handler appropriately. Also note that the code points to a Gallery specific PmWiki style template. You can use your existing template but it is going to have unnecessary items such as "Edit" and "Page History" links that do not make any sense when Gallery is displayed. To make your own template just copy your existing one and remove the parts that don't make sense.
  • And I think that about wraps it up. There may be some parts that try to access my UserAuth code. If those cause you problems then simply remove them. I have tried to document everything I did. If I have forgotten something then please help me figure it out and fix this recipe!

Optional for using Gallery with UserAuth:

  • Upload the directory classes/pmwiki from the zip file to your Gallery's classes directory. You should not have to modify this code as long as you set up the variables mentioned earlier in the config.php file correctly.
  • Look at init.php from the zip file and seach for "pmwiki" in that file. The case statement for pmwiki should be added to your init.php. This case statement tells Gallery to use classes that utilize my UserAuth software for handling logins. Do not just overwrite your init.php with my version since you are probably running a different version of Gallery than I am.

Discussion

This recipe may not work for you perfectly the first time. You are going to have to get your hands dirty and actually change code in various places. It could get messy. But if you do find that part of this recipe is wrong or has caveats then please help out by fixing this page! I hope this solution works out for you, but I do not guarantee that it will.

Example

You can see an example of this recipe in action at my LookGallery. -- JM

If you get this working then please post your example here.

Files

History

If you make updates to this recipe then please update the history here.

November 24, 2004 - Version 0.1 - Initial release of recipe. -- JM

Comments & Bugs


Question:

I'm trying to get this working here (http://www.hogbay.com/gallery/) on my website. If you visit that url you'll see that Gallery is embedded, but pmwiki is throwing lots of errors that look like this:

Warning: array_keys(): The first argument should be an array in /www/h/hogbay/htdocs/index.php on line 392

My line 392 is in the FmtPageName function and looks like this:

 $fmt = preg_replace(array_keys($FmtP),array_values($FmtP),$fmt);

Does anyone have ideas on why that would be? Could it be because I don't have the proper values in register_globals.php file? I coudln't figure out how to print out the values from the $GLOBALS array. Whenever I printed things out I just seemed to get values of globals, not their names.

Also what is PMWIKI_BASE_DIR supposed to look like? My pmwiki.php index file is named index.php and is located in the htdocs folder. The only way that I could make things work was by using this value:

$PMWIKI_BASE_DIR = "/www/h/hogbay/htdocs";

Is that the right way to do things? Or can I specify a more local path?

Answer

To fix all the errors showing up on your pages try editing your php.ini file that is in the same directory (or parent directory) of your PmWiki installation. If you do not have a php.ini file then grab one from the net somewhere for your providers Php version and put it at the highest level of your webspace. Edit the line that named error_reporting to turn off showing warnings. This should get rid of all these nasty warnings you are getting.

PMWIKI_BASE_DIR is just the location of where your PmWiki installation is located. If you have changed your pmwiki.php to be named index.php then you will have to edit the software I have provided to load the PmWiki software using that name. I suggest that instead of renaming pmwiki.php to index.php to looking setting up mod_rewrite or at least just having index.php be symbolic link to pmwiki.php.


Note on Using with PmWiki Version 2

To get this working with PmWiki Version 2 you need to first regenerate your register_globals.php file and then change the following line from wrapper.footer:

  $GalleryUnsafeGlobals = $GLOBALS;

To:

  $GalleryUnsafeGlobals = array_keys($GLOBALS);


Question: I'm looking for a Wrapper to display any link inside the main area? Is this possible to do by rewriting the code above. The Wrappet function I'm looking for is of the same functionality as the Mambo server wrapper.

Contributors


pmwiki-2.3.32 -- Last modified by {{}}?

from IP: 85.171.160.186 ip should be disabled by default for security reasons