This document explains how to embed Gallery into a website with an existing community by extending the user API.
Gallery homepagea.) Think of a name to identify the application or community Gallery is being integrated with. This will be referred to as embed-type from this point.
b.) Create a sub-directory in gallery-dir/classes using your embed-type as the dir name. Create 2 files in this directory, User.php and UserDB.php, and copy the following templates into these new files.
class EmbedType_User extends Abstract_User {
function EmbedType_User() {
// -- constructor function
}
function loadByUid($uid) {
// -- your load code here; should return uid, username, fullname,
// -- email, isAdmin, and CreateAlbums perms(or you can default this
// -- to 0 or 1
$this->uid = $returned_uid_value;
$this->username = $returned_username_value;
$this->fullname = $returned_fullname_value;
$this->email = $returned_email_value;
$this->isAdmin = $returned_adminperms_value;
$this->canCreateAlbums = $returned_createalbumsperms_value;
}
function loadByUserName($uname) {
// -- your load code here; should return uid, username, fullname,
// -- email, isAdmin, and perhaps CreateAlbums perms
$this->uid = $returned_uid_value;
$this->username = $returned_username_value;
$this->fullname = $returned_fullname_value;
$this->email = $returned_email_value;
$this->isAdmin = $returned_adminperms_value;
$this->canCreateAlbums = $returned_createalbumsperms_value;
}
}
class EmbedType_UserDB extends Abstract_UserDB {
var $nobody;
var $everybody;
var $loggedIn;
function EmbedType_UserDB() {
$this->nobody = new NobodyUser();
$this->everybody = new EverybodyUser();
$this->loggedIn = new LoggedInUser();
}
function getUserByUsername($username, $level=0) {
if ($level > 1) {
// We've recursed too many times. Abort;
return;
}
if (!strcmp($username, $this->nobody->getUsername())) {
return $this->nobody;
} else if (!strcmp($username, $this->everybody->getUsername())) {
return $this->everybody;
} else if (!strcmp($username, $this->loggedIn->getUsername())) {
return $this->loggedIn;
}
$user = new EmbedType_User();
$user->loadByUsername($username);
return $user;
}
function getUserByUid($uid, $tryOldFormat=false) {
if (!$uid || !strcmp($uid, $this->nobody->getUid())) {
return $this->nobody;
} else if (!strcmp($uid, $this->everybody->getUid())) {
return $this->everybody;
} else if (!strcmp($uid, $this->loggedIn->getUid())) {
return $this->loggedIn;
}
$user = new EmbedType_User();
$user->loadByUid($uid);
return $user;
}
function getUidList() {
// -- Return array of user id's. This is especially needed for the album
// -- permissions page or any page that displays a list of members.
}
}
$GALLERY_EMBEDDED_INSIDE = true;
$GALLERY_EMBEDDED_INSIDE_TYPE = "embed-type"; // -- replace with your embed-type string
This will tell Gallery what it is embedded in and how to find the class include files for this embed-type.
b.) Add a case block to the main switch statement for your embed-type. In this case block, make sure to:
if (isset($GALLERY_EMBEDDED_INSIDE)) {
/* Okay, we are embedded */
switch($GALLERY_EMBEDDED_INSIDE_TYPE) {
case "mecca":
include_once("settings.php"); // -- init code for mecca
$strIncludeDir = $GALLERY_BASEDIR."classes/".$GALLERY_EMBEDDED_INSIDE_TYPE;
include($strIncludeDir . "/UserDB.php");
include($strIncludeDir . "/User.php");
// Load our user database (and user object)
$gallery->userDB = new Mecca_UserDB;
// -- If a user is logged in, initialize $gallery->user
if ( $objMember->isLoggedIn() ) {
$gallery->user = $gallery->userDB->getUserByUid($objMember->getKey());
}
break;
case 'postnuke':
// -- postnuke code...
The album permissions page takes longer to load as the number of users it has to list grows. To speed things up you need to make changes in 2 files.
a.) In your new UserDB class file change the getUidList() method so the uid array that is returned is indexed by the uid itself and the actual array values are the usernames:
Example:
function getUidList() {
$uidList = array();
// -- load active members
$objMember = new clsMember("none");
$objMember->loadItems("tblLogins.intStatus = 1");
// -- build uid array
while ($objRow = $objMember->nextItem()) {
$uidList[$objMember->getKey()] = $objMember->strLoginName;
}
// -- add Nobody & Everybody users to array
$uidList[ $this->nobody->getUid() ] = "(".$this->nobody->getUsername().")";
$uidList[ $this->everybody->getUid() ] = "(".$this->everybody->getUsername().")";
// -- sort array; use asort to maintain key associations
asort($uidList);
return $uidList;
}
b.) In album_permissions.php replace this block of code:
foreach ($gallery->userDB->getUidList() as $uid) {
$tmpUser = $gallery->userDB->getUserByUid($uid);
$uname = $tmpUser->getUsername();
$uAll[$uid] = $uname;
}
with this one:
$aryUidList = $gallery->userDB->getUidList();
foreach ($aryUidList as $uid=>$uname) {
$uAll[$uid] = $uname;
}
Modify gallery-dir/html_wrap/wrapper.header(copy from html_wrap/wrapper.header.default if it doesn't exist) and add a new case block to the switch statement to display your custom header HTML.
Example:
case "mecca":
include_once("lib_layout.php"); // -- contains writeHeader/writeFooter layout functions
if ( basename($_SERVER["PHP_SELF"])!="albums.php" && $gallery->album->fields["title"]) {
// -- if an album is being viewd, add its name to page title
$strPageTitle = $gallery->app->galleryTitle." :: ".$gallery->album->fields["title"];
} else {
$strPageTitle = $gallery->app->galleryTitle;
}
writeHeader($strPageTitle, "gallery"); // -- from lib_layout.php
break;
Modify gallery-dir/html_wrap/wrapper.footer(copy from html_wrap/wrapper.footer.default if it doesn't exist) and add a new case block to the switch statement to display your custom footer HTML.
Example:
case "mecca":
writeFooter(); // -- from lib_layout.php
break;