Commit c15e9178 authored by kiz_0987's avatar kiz_0987

Initial Gallery2.1 compatible module for Drupal 4.7

parent 9e95ee77
This module would not exist without image_filter by Eric Scouten (http://drupal.org/node/9707). I started with that module and transformed it bit by bit into this module. While there's not a lot of original code left, I wouldn't have been able
to do this without using image_filter as a template.
// $Id$
kiz_0987:
This gallery.module was based on original code by walkah. The gallery_filter part is almost
entirely based on work by MichelleC and Waldemar. The g2image application is by capt_kirk.
Thanks for all your efforts.
MichelleC (g2_filter):
This module would not exist without image_filter by Eric Scouten (http://drupal.org/node/9707). I started with that module and transformed it bit by bit into this module. While there's not a lot of original code left, I wouldn't have been able to do this without using image_filter as a template.
This module is dependent on Drupal (of course), Gallery 2, and the gallery.module (http://drupal.org/project/gallery) so thanks to everyone for all the work on those. Without them, this module would be useless. :)
\ No newline at end of file
This diff is collapsed.
This diff is collapsed.
Installation Instructions
-------------------------
$Id$
1. Install Gallery 2 and Drupal (see their respective installation
documents). Gallery2 should be *inside* your Drupal installation
so that it's accessible by the same website. If you accidentally
install Gallery somewhere else, you can create a symlink to it
from inside your drupal site, eg:
cd /var/www/drupal.site
ln -s /path/to/gallery2
HELP
----
For more help, check out:
http://codex.gallery2.org/index.php/Gallery2:How_to_Embed_Gallery2_in_Drupal
Or you can move Gallery2. If you're going to do that, read this
FAQ:
http://codex.gallery2.org/index.php/Gallery2:FAQ#How_can_I_move_my_gallery_installation_from_one_folder_to_another.3F
Requirements
------------
Gallery2.1 (CVS)
Image Block module installed and activated in Gallery2
Image Frame module installed and activated in Gallery2
Drupal 4.7 (CVS)
gallery.module
2. Copy gallery.module to your drupal modules/ directory.
Installation Instructions
-------------------------
3. Enable the gallery module in administer -> modules in your drupal
installation.
1. Install Gallery 2.1 and Drupal 4.7 (see their respective installation
documents).
***Warning*** - Do not name your G2 directory "gallery", call it something else
(eg "gallery2"). Calling it "gallery" will cause a conflict with the Drupal gallery.module
as Drupal assumes that http://www.example.com/gallery refers to the Drupal module.
4. Go to administer -> settings -> gallery and enter the path to your
gallery2 installation. So if your Drupal is installed at:
/var/www/www.drupal.site
2. Ensure that "Image Block" and "Image Frame" modules are installed and activated in Gallery2.
Check them in the non-embedded Gallery. See Gallery2:Download for instructions to download it
if it was not included in your installation.
And your gallery2 is at:
/var/www/drupal.site/gallery2
3. Log out of G2 (non-embedded) - people have reported errors relating to sessions if this is not
done.
Then your Gallery2 path would be:
gallery2/
4. Copy the entire gallery module directory to your drupal modules/ directory.
Your gallery should now be available at:
5. Enable the gallery module in administer -> modules in your drupal
installation.
http://your.site/gallery
6. Go to administer -> settings -> gallery and enter the URI of Gallery2.
Leave "autodetect" selected and click "submit". A series of tests will run to check if
everything is OK. There is a HELP link.
5. Enable the "Gallery Block" in administer -> blocks
7. Enable the "Gallery Block" in administer -> blocks, and optionally the "Gallery Navigation"
block.
Note: the default themes don't work so well with Drupal yet. You'll get best
results if you edit the default theme and move all the blocks out of the sidebar
and into the album and photo pages. There's a drupal specific theme on the way,
stay tuned.
Optional Steps
--------------
1. Tolerant base_url. To ensure http://www.example.com and http://example.com both work and avoid
potential session problems, use the tolerant base_url patch in your
drupal settings.php file. See http://drupal.org/node/6554
2. Themeing. If you want to, you can add your own drupal_g2.css file in your *drupal* theme dir
and it will automatically be loaded after the one in the gallery.module dir.
3. Sidebar. Go to your G2 site admin and include the blocks you want in the sidebar (under
Themes). I use "Item Actions" and "Album Quick Links (DHTML)". To use the latter
you need to have installed the Album Select module.
Note: To get the rewrite module working, you need to first configure and
use it with the standalone Gallery2 install. Once it's working there disable
all the rules except for the 'Show Item' rule and set its URL pattern to:
gallery/%path%
4. URL Rewrite.
Then when you browse to http://your.site/gallery you should see short urls
inside drupal.
Troubleshooting
---------------
See http://codex.gallery2.org/index.php/Gallery2:How_to_Embed_Gallery2_in_Drupal
NOTE: this is beta software, so it might not always work. If you have
questions or problems contact:
Kieran Parsons <kiz_0987@yahoo.com>
James Walker <walkah@walkah.net>
$Id$
Overview
---------
This is an integration module for gallery2
This is an integration module for Gallery2.1 with Drupal 4.7
(http://gallery.menalto.com/).
NOTE: Gallery 2 is still alpha software (use at your own risk)
Requirements
------------
* Gallery 2 CVS HEAD (from 2004-01-24 or later)
* Drupal 4.5.x or later
* Gallery 2.1 CVS HEAD (with ImageBlock and ImageFrame modules installed and activated)
* Drupal 4.7 CVS HEAD (preferably after 4.7beta5 was released)
For installation instructions please see INSTALL.txt
Known issues:
1. Deselecting all "Image Data" checkboxes will result in an error for Drupal 4.7 beta 5 and
below. Update to CVS HEAD version of Drupal to remove error.
Author
-------
James Walker <walkah@walkah.net>
Kieran Parsons <kiz_0987@yahoo.com>
1) Unpack the g2_filter module into your /modules directory.
2) Enable the module under admin/modules.
3) Add the filter to at least one of your input types at /admin/filters
3) Configure the filter. This is important because there are some path settings it needs to know.
This module creates a filter that lets you embed items from your embedded Gallery 2 install.
Requirements:
* Gallery 2 - http://gallery.menalto.com/
* gallery.module - http://drupal.org/project/gallery
Syntax:
[G2:item_id class=name size=number frame=name]
* item_id (required) *
This is the item ID from G2. If you look at the URL of the item, this is the last number.
* class *
The block that G2 returns is wrapped in a DIV so additional styling can be done. The classes for this DIV are located in g2_filter.css. Included with the module are "left", "right", and "nowrap". These position the image block to the left or right or on a line all its own with the text not wrapping. You can also add your own class(es) to the CSS file and they will automatically be available.
* size *
The length of the longest side for the thumbnail. The other side is determined automatically to keep the same aspect ratio.
* frame *
G2 comes with several item/album frames and allows you to add more. You can use any of these frames for the embedded thumbnail just by specifying a name. Frames included with the default install are: Bamboo, Book, Branded Wood, Dot Apple, Dots, Flicking, Gold, Gold 2, Polaroid, Polaroids, Shadow, Shells, Slide, Solid, Spiral Notebook, Wood.
Send comments to mcox@charter.net
Left to do as of 2005/Oct/21:
* Add arguments for the rest of the "show" items
* Add arguments for the rest of the "block" items
* Improve the CSS for the div class.
* Investigate the float clearing brought up by kiz
Keizo's notes:
/******issues that remain
*should we keep n as an option in the config settings? see comments in get_settings_form()
*should n be required to solve that issue?
*how should the 'show' param be implemented. I've put it in the settings, which works good for defaults.
*How should the syntax be? it could be caption=yes/no title=yes/no date=yes/no etc.
*is that optimal? how about about show=title,caption,date ..this one seems easier interms of usability, yes?
*are the syntax standard enough? it would be a pain to change them later
*since it would break all instances of the filters use.
*Should we make the default tag [image:id] instead of G2? like the image filter? or may [img:id]? or just lower case [g2:id] for easyness?
*what should we use as the default for 'type', right now it's viewedImage. recentImage might be more useful?
*do we need to bother making different types per block? I don't think so, people could just make a second block
*still need to implement link target
*does the 'frame=' work? its not working for me in this version, i didn't look too closely as to why
***features wish list
*I would like it so there was an 'see all photos' link when an album is displayed. selecting an item_id of an album with n=1 does this.
*any possible to make the block display horizontally?
*and ofcourse an auto javescript thing to auto insert the [G2] tags
*/
Oct 21, 2005
* Changed class names internally to add "giImageBlock." to make them unique. Classes are still refered to as "left, right, nowrap" in the filter call.
* Moved CSS file links to the HEAD via theme_add_style()
Oct 7, 2005
* Add ability to specify "none" for class and not have block wrapped in div (not added to docs)
* Removed redundant / from frame CSS link
This diff is collapsed.
/* $Id$ */
/**
* Drupal embeded Gallery2 css overrides.
* These do not make a perfect theme, but are not bad as a first step.
*/
/* Increase font size */
#gallery {
font-size: 100%;
}
/* Remove the header */
#gsHeader {
display: none;
}
/* Removes the Gallery Title (as Drupal displays it)*/
#gallery .gbBlock h2 {
display: none;
}
/* Do not display the breadcrumb */
#gsNavBar div.gbBreadCrumb {
display: none;
}
/* The system links ("Site Admin", "Your Album") should no longer float as the
breadcrumb has been removed. Just align right */
#gsNavBar div.gbSystemLinks {
text-align: right;
float: none;
}
/* .block-gallery is in the sidebar */
.block-gallery #gsSidebar {
border: none;
width: auto;
overflow: hidden;
}
.block-gallery div.block-core-ItemLinks {
margin: 0;
border-bottom: 1px solid #aaa;
}
.block-gallery .gbBlock {
padding: 0 5px 3px 5px;
}
/* Navigation Tree */
.block-gallery .dtree {
font-size: 1em;
}
/* For g2ic_plugin */
img.g2image_float_left, div.g2image_float_left
{
float: left;
margin: 4px;
}
img.g2image_float_right, div.g2image_float_right {
float: right;
margin: 4px;
}
img.g2image_centered, div.g2image_centered {
display: block;
margin-left: auto;
margin-right: auto;
text-align: center;
}
.g2image_clear_images {
clear: both;
}
.post-content img
{
float: left;
clear: both;
margin: 4px;
}
.page-content img
{
float: left;
clear: both;
margin: 4px;
}
/* Embed success, warning, error messages */
.g2_embed_success {
color: green;
}
.g2_embed_warning {
color: #f63;
}
.g2_embed_error {
color: red;
font-weight: bold;
}
// $Id$
function g2ic_open(field) {
// Find the form id by going back through the hierarchy. Kludge until can get the form id
// directly from drupal.
var element = document.getElementById(field).parentNode;
while (element.tagName != 'FORM') {
element = element.parentNode;
}
var form = element.id;
var url = G2IMAGE_URI + 'g2image.php?g2ic_form='+form+'&g2ic_field='+field+'&g2ic_tinymce=0';
var name = 'g2image';
var w = 600;
var h = 600;
var valLeft = (screen.width) ? (screen.width-w)/2 : 0;
var valTop = (screen.height) ? (screen.height-h)/2 : 0;
var features = 'width='+w+',height='+h+',left='+valLeft+',top='+valTop+',resizable=1,scrollbars=1';
window.open(url, name, features);
}
This diff is collapsed.
<?php
// $Id$
/**
* gallery.module : gallery_base.inc
* Base functions
*/
/* --------------------------------------------------------------------------
* Gallery init and misc functions
* --------------------------------------------------------------------------
*/
/**
* fetch a galleryEmbed object
*/
function _gallery_init($full = false, $vars = null) {
global $user;
if (!$vars) {
$embedPath = variable_get('gallery_dir', './gallery2/') . 'embed.php';
$g2Uri = variable_get('gallery_uri', '/gallery2/');
$embedUri = variable_get('gallery_embed_uri', '?q=gallery');
$gallery_valid = variable_get('gallery_valid', 0);
} else {
$embedPath = $vars['gallery_dir'] . 'embed.php';
$g2Uri = $vars['gallery_uri'];
$embedUri = $vars['gallery_embed_uri'];
$gallery_valid = $vars['gallery_valid'];
}
if (!$gallery_valid) {
// It's probably now bad practice to return a null here, given that $ret=null is a gallery2
// success response
return array(false, null);
}
include_once($embedPath);
$new_user_needed = false;
$active_id = ($user->uid>0) ? $user->uid : '';
$params = array('embedUri' => $embedUri,
'g2Uri' => $g2Uri,
'loginRedirect' => url('user/login', null, null, true),
'activeUserId' => $active_id,
'activeLanguage' => gallery_get_language($user),
'fullInit' => $full);
$ret = GalleryEmbed::init($params);
if (!$ret) {
// No error returned, but it is still possible that the ExternalID mapping has not been done
$ret2 = GalleryEmbed::isExternalIdMapped($user->uid, 'GalleryUser');
if ($ret2 && ($ret2->getErrorCode() & ERROR_MISSING_OBJECT)) {
// Need to make a new user, but don't try to map anonymous user.
$new_user_needed = ($user->uid>0);
}
}
if (($new_user_needed) || ($ret && ($ret->getErrorCode() & ERROR_MISSING_OBJECT))) {
// Our user mapping is missing. Make a mapping, or create a new user.
$g2_user = null;
// Get the G2 user that matches the Drupal username
list ($ret, $g2_user) = GalleryCoreApi::fetchUserByUsername($user->name);
if ($ret && !($ret->getErrorCode() & ERROR_MISSING_OBJECT)) {
return array(false, $ret);
}
if (!isset($g2_user)) {
// No G2 user with a matching username. If this is the admin user, we're going to
// try a little harder and match it to the oldest admin in G2.
if ($user->uid == 1) {
list ($ret, $admin_group_id) = GalleryCoreApi::getPluginParameter('module', 'core', 'id.adminGroup');
if ($ret) {
return array(false, $ret);
}
list ($ret, $g2_users) = GalleryCoreApi::fetchUsersForGroup($admin_group_id);
if ($ret) {
return array(false, $ret);
}
$keys = array_keys($g2_users);
$g2_user_name = $g2_users[$keys[0]];
list ($ret, $g2_user) = GalleryCoreApi::fetchUserByUsername($g2_user_name);
if ($ret) {
return array(false, $ret);
}
}
}
if (isset($g2_user)) {
// The G2 user was found so add to the External ID Map
$ret = GalleryEmbed::addExternalIdMapEntry($user->uid, $g2_user->getId(), 'GalleryUser');
if ($ret) {
return array(false, $ret);
}
} else {
// No matching G2 user found -- create one.
return gallery_modify_user($user, 'create');
}
}
return array(true, null);
}
/**
* Include css files as needed
*/
function gallery_css_include($css_file = 'drupal_g2.css') {
/* The theme may not exist, so neither does path_to_theme(), so need to init */
global $theme;
if ($theme === NULL) {
$theme = init_theme();
}
$output = theme('stylesheet_import', base_path() . drupal_get_path('module', 'gallery') .
'/' . $css_file,'screen') ."\n";
$themecss = base_path() . path_to_theme() .'/' . $css_file;
if (file_exists($themecss)) {
$output .= theme('stylesheet_import', $themecss,'screen') . "\n";
}
return $output;
}
/**
* Include head information with check made for uniqueness (see drupal_add_js)
*/
function gallery_set_html_head($info, $unique=true) {
static $sent = array();
if ($unique) {
// Only set html head if this info has not been sent before.
$hash_info = md5($info);
if (!isset($sent[$hash_info])) {
drupal_set_html_head($info);
$sent[$hash_info] = true;
}
} else {
drupal_set_html_head($info);
}
}
/**
* Get the language for the user. If unknown, make a best guess.
*/
function gallery_get_language($user) {
// Added depdev patch for language support (http://drupal.org/node/32374)
// without i18 part (I seem to remember a Rewrite issue with it
// Added test for no user language defined
if (($user->uid==0 || !($user->language)) && module_exist('locale')) {
// This is a visitor and locale module is enabled
// Get drupal's default language
$result = db_query('SELECT locale, name FROM {locales_meta} WHERE isdefault = 1');
$row = db_fetch_object($result);
return $row->locale;
} else {
return $user->language;
}
}
/*
* --------------------------------------------------------------------------
* Error Functions
* --------------------------------------------------------------------------
*/
function gallery_error($message, $ret) {
// Changed default, just in case!
$error_mode = variable_get('gallery_error_mode', array(1));
if (in_array(2, $error_mode)) {
drupal_set_message($message);
}
if (isset($ret)) {
$full_message = $message . '<br/>' . $ret->getAsHtml();
} else {
$full_message = $message;
}
if (in_array(1, $error_mode)) {
watchdog('gallery', $full_message, WATCHDOG_ERROR);
}
}
?>
\ No newline at end of file
div.giImageBlock.left{
/* $Id$ */
div.giImageBlock.left {
float: left;
margin: 1em;
}
div.giImageBlock.right{
div.giImageBlock.right {
float: right;
margin: 1em;
}
......@@ -11,4 +13,8 @@ div.giImageBlock.right{
div.giImageBlock.nowrap {
float: none;
margin: 1em
}
\ No newline at end of file
}
.giImageBlock-clear-both {
clear: both;
}
<?php
// $Id$
/**
* gallery.module : gallery_filter.inc
* Gallery Filter functions (originally by MichelleC and Waldemar)
*/
// ***************** The Filter in Action ***********************
define('GALLERY__FILTER_WORD', 1);
define('GALLERY_FILTER_INTEGER', 2);
define('GALLERY_FILTER_STRING', 3);
function gallery_filter_attr_value($text, $value_type = GALLERY_FILTER_WORD) {
// Strip off initial and final quotes.
$first = substr($text, 0, 1);
if ($first == "\"" || $first == "\'") {
if (substr($text, -1, 1) == $first) {
$text = substr($text, 1, -1);
}
}
switch ($value_type) {
case GALLERY_FILTER_WORD :
return preg_replace("/\W/", '', $text);
case GALLERY_FILTER_INTEGER :
return preg_replace("/\D/", '', $text);
default :
return check_plain($text);
}
}
// Execute filter on given text.
function gallery_filter_process($text) {
// Find all the image codes and loop over them, replacing each with the Gallery2 image block
$prefix = variable_get('gallery_filter_prefix', 'G2');
$matchetxt = "/\[".trim($prefix).":(\d+)(\s*,)?\s*(.*?)\]/i";
preg_match_all($matchetxt, $text, $matches, PREG_SET_ORDER);
// If we have at least one match, set everything up
if (count($matches) > 0) {
// Set the default and path variables based on module settings
$default_size = variable_get('gallery_filter_default_size', 150);
$default_div_class = variable_get('gallery_filter_default_div_class', 'nowrap');
$default_album_frame = variable_get('gallery_filter_default_album_frame', '');
$default_item_frame = variable_get('gallery_filter_default_item_frame', '');
$default_block_type = variable_get('gallery_filter_default_block_type', 'recentImage');
$default_n_images = variable_get('gallery_filter_n_images', 1);
$default_show = variable_get('gallery_filter_default_show', 'none');
$default_link_target = variable_get('gallery_filter_default_link_target', '');
if ($default_album_frame == 'none') {
$default_album_frame = '';
}
if ($default_item_frame == 'none') {
$default_item_frame = '';
}
// This will hold the list of frames used for images so we can add the CSS link(s) at the end
$frame_list = array ();
// This sets up the embedding
list ($success, $ret) = _gallery_init(true);
if (!$success) {
gallery_error(t('Unable to initialize embedded Gallery'), $ret);
return;
}
}
foreach ($matches as $match) {
// Pull out the arguments into the $args array
$args = array ();
preg_match_all("/(\w+)\=(\"[^\"]*\"|\S*)/", $match[3], $a, PREG_SET_ORDER);
foreach ($a as $arg) {
$args[strtolower($arg[1])] = $arg[2];
}
// Set number of images to show
$n_images = gallery_filter_attr_value($args['n'], GALLERY_FILTER_INTEGER);
if ($n_images == 0) {
// No size specified; use the default
$n_images = $default_n_images;
}
// Set the block type
$block_type = gallery_filter_attr_value($args['type'], GALLERY_FILTER_WORD);
if (empty($block_type)) {
// No block type specified; use the default
$block_type = $default_block_type;
}
if ($n_images <= 1)
$block_type = 'specificItem'; //so it shows something if n=1 and an album is selected
// Set the size of the thumbnail
$size = gallery_filter_attr_value($args['size'], GALLERY_FILTER_INTEGER);
if ($size == 0) {
// No size specified; use the default
$size = $default_size;
}
// Set the class of the div
$div_class = gallery_filter_attr_value($args['class'], GALLERY_FILTER_WORD);
if (empty ($div_class)) {
// No class specified; use the default
$div_class = $default_div_class;
}
// Switch the class to g2image versions (adds consistency)
switch ($div_class) {
case 'left':
$div_class = "g2image_float_left";
break;
case 'right':
$div_class = "g2image_float_right";
break;
case 'center':
case 'centre':
$div_class = "g2image_centered";
break;
case 'normal':
$div_class = "g2image_normal";
break;
}
// Set the overriding, album, and item frames
$frame = gallery_filter_attr_value($args['frame'], GALLERY_FILTER_WORD);
$album_frame = gallery_filter_attr_value($args['aframe'], GALLERY_FILTER_WORD);
$item_frame = gallery_filter_attr_value($args['iframe'], GALLERY_FILTER_WORD);
if (empty ($frame)) {
// No overriding frame given; check for album_frame and item_frame
if (empty ($album_frame)) {
// No album frame specified; use the default one
$album_frame = $default_album_frame;
}
if (empty ($item_frame)) {
// No item frame specified; use the default one
$item_frame = $default_item_frame;
}
} else {
// Overriding frame given; use it
$album_frame = $frame;
$item_frame = $frame;
}
// Add the requested frames to the array so we can get the CSS later. Don't worry about
// dupes at this point; they will be filtered out later.
array_push($frame_list, $frame);
array_push($frame_list, $album_frame);
array_push($frame_list, $item_frame);
// This part actually fetches the image block. It uses the same paramaters as the code
// found under "Image Block" in site admin in Gallery2.
$show = $default_show;
// Not customized yet:
$link_target = $default_link_target;
$param_blocks_array = array_fill(0, $n_images, $block_type);
$params['itemId'] = $match[1];
$params['blocks'] = is_array($param_blocks_array) ? implode('|', $param_blocks_array) : "";
$param_show_array = $show;
$params['show'] = is_array($param_show_array) ? implode('|', $param_show_array) : "";
$params['maxSize'] = $size;
// Add frames and link target using g2_filter code from MichelleC
$params['albumFrame'] = $album_frame;
$params['itemFrame'] = $item_frame;
$params['linkTarget'] = $link_target;
$g2_head = array();
$block = array ();
list ($ret, $content, $head) = GalleryEmbed::getImageBlock($params);
if ($ret) {
gallery_error(t('Unable to get Gallery image block'), $ret);
return;
} else {
if ($content) {
// Add a div around the table for styling
if ($div_class != 'none') {
$content = '<div class ="giImageBlock '.$div_class.'">'.$content.'</div>';
}
// This puts the image block HTML back into the rest of the text
$text = str_replace($match[0], $content, $text);
}
if ($head) {
$g2_head[] = $head;
}
}
} // end of for loop through matches
// If we had at least one match, finish up by adding the css. Unfotunately if there are multiple
// images on a page this will get added multiple times.
if (count($matches) > 0) {
GalleryEmbed :: done();