PHP Classes

File: examples/embedded_alternate.php

Recommend this page to a friend!
  Classes of Andy Loftus  >  Photo Album  >  examples/embedded_alternate.php  >  Download  
File: examples/embedded_alternate.php
Role: Example script
Content type: text/plain
Description: Alternate method to embed PhotoAlbum in existing webpage.
Class: Photo Album
Display interactive photo album
Author: By
Last change:
Date: 11 years ago
Size: 4,178 bytes


Class file image Download

// Synopsis: 1. Create page as normal.
    // 2. Add PhotoAlbum <head> elements to normal html
    // <head>.
    // 3. Create a <div> where you want the PhotoAlbum.
    // 4. Print output from $album->generate_html_content.
    // 5. Close the </div>.

$doc_root = '/var/www/htdocs/pictures';
$web_root = '/pictures';

// NOTE: PhotoAlbum creates headers that must go in the <head>
    // section.
    // This example shows how to accomplish this if you don't
    // have access to the webpage template or can't use the
    // method shown in "embedded.php".
    // This method uses the ob_get_contents() php function to
    // read the current ob into a string, then uses the
    // preg_replace() function to replace the </head> tag with
    // the PhotoAlbum headers prepended to it. Then just print
    // the string and it will re-populate the output buffer.

    // Create new photo album object
$album = new PhotoAlbum;

// Set album variables
$album->CELLS_PER_ROW = 5;
$album->IMAGE_MAX_SIZE = 700;
$album->THUMB_MAX_SIZE = 100;
$album->IMAGE_QUALITY = 85;
// doctype unused for embedded page
    //$album->DOCTYPE = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "">';
    // title unused for embedded page
    //$album->TITLE = 'CREW Mission Archives - Photo Documentary';

    // Where to find required files for include
$album->LIGHTBOX_JS = "$web_root/js/lightbox.js";
$album->LIGHTBOX_CSS = "$web_root/css/lightbox.css";
$album->PROTOTYPE_JS = "$web_root/js/prototype.lite.js";
$album->MOO_FX_JS = "$web_root/js/moo.fx.js";
$album->MOO_FX_PACK_JS = "$web_root/js/moo.fx.pack.js";

// Add any optional HTML settings
$album->LINKS[] =
'<link rel="stylesheet" type="text/css" href="/crew/css/photoalbum.css" />';
$album->SCRIPTS[] =
'<script type="text/javascript">' .
file_get_contents("$doc_root/js/photoalbum.js") .
// Create photo album
$rv = $album->create_album();
$rv !== TRUE)
'Error: The following problem occurred: '.$album->ERR);

// Get photo_album headers. These will be added to HTML head later.
    // NOTE: This is step 2 from the Synopsis above
$new_headers = array();
$retval = $album->generate_html_head($new_headers);
$retval !== TRUE)
"Error in album.generate_html_head, album said: $album-ERR");

// Get html content for PhotoAlbum
$album_content = array();
$retval = $album->generate_html_content($album_content);
$retval !== TRUE)
$album_content = array("Error in album.generate_html_content, album said: $album-ERR");

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "">
<html xmlns="" xml: lang="en" lang="en">
<title>PhotoAlbum Sample - Embedded PhotoAlbum</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<link href="/pictures/css/main.css" rel="stylesheet" type="text/css" />
<div id="main_contents">
<h3>PhotoAlbum embedded in existing webpage.</h3>
This sample uses php <tt>ob_get_contents()</tt> to add additional
headers into &lt;head&gt;.
<div id="photo_album">
// Add PhotoAlbum headers to html head
$ob_str = ob_get_contents();
$new_headers[] = '</head>';
$ob_str = preg_replace('/<\/head>/', join('', $new_headers), $ob_str);

// Add photo_album content to the html body
<div style="height: 2em; width: 100%; background-color: #000000;
color: #000000;"><div>