Commit dccc293a authored by profix898's avatar profix898
Browse files

- very early D6 version (Oct-01, 2007)

parent e65698fe
......@@ -161,7 +161,7 @@ class G2EmbedDiscoveryUtilities {
$fd = @fsockopen($components['host'], $port, $errno, $errstr, 1);
if (empty($fd)) {
return array(false, null, "Error $errno: '$errstr' retrieving $url");
return array(false, null, "Error $errno: '$errstr' retrieving $g2Uri");
}
$get = $components['path'] . 'embed.php?getEmbedPath=1';
......
......@@ -14,7 +14,7 @@ Note that you will need to download and install Gallery2
Requirements
------------
* Gallery 2.2
* Drupal 5.x
* Drupal 6.x
Installation
------------
......
// $Id$
function g2image_open(field) {
function g2ic_open(field) {
// Set some properties
var form = $('#'+field).parents('form').attr('id');
var url = G2IMAGE_URI+'g2image.php?g2ic_form='+form+'&g2ic_field='+field+'&g2ic_tinymce=0';
var url = Drupal.settings.gallery2.g2image_uri+'g2image.php?g2ic_form='+form+'&g2ic_field='+field+'&g2ic_tinymce=0';
var name = 'g2image';
var w = 600;
var h = 600;
......@@ -14,10 +14,3 @@ function g2image_open(field) {
// Open the G2Image window
window.open(url, name, features);
}
// BUEditor
function g2bueditor_open() {
if (editor.active) {
g2image_open(editor.active.textArea.id);
}
}
......@@ -4,18 +4,20 @@
* Drupal embeded Gallery2 css overrides.
* These do not make a perfect theme, but are not bad as a first step.
*/
/* Increase font size */
/* Increase font size */
#gallery {
font-size: 100%;
}
/*#siteAdminForm {
font-size: 140%;
}*/
/* Remove the header */
#gsHeader {
display: none;
}
/* Removes the Gallery Title (as Drupal displays it) */
/* Removes the Gallery Title (as Drupal displays it)*/
#gallery .gbBlock table h2 {
display: none;
}
......@@ -56,6 +58,7 @@ table.ImageFrame_wood, table.ImageFrame_wood td {
padding: 0px;
}
/* Brings h2 back for siteAdmin pages */
#siteAdminForm .gbBlock h2 {
display: block;
......@@ -80,19 +83,6 @@ table.ImageFrame_wood, table.ImageFrame_wood td {
overflow: hidden;
}
/* Flatten left margin for SiteAdminLinks if moved to Drupal sidebar */
.block-gallery #gsSidebar ul#gbSiteAdminLinks,
.block-gallery #gsSidebar ul#gbSiteAdminLinks li,
.block-gallery #gsSidebar ul#gbSiteAdminLinks li ul,
.block-gallery #gsSidebar ul#gbSiteAdminLinks li ul li {
margin-left: 2px;
}
/* Remove bold font from SiteAdminLinks if moved to Drupal sidebar */
.block-gallery #gsSidebar #gbSiteAdminLinks a {
font-weight: normal;
}
.block-gallery div.block-core-ItemLinks {
margin: 0;
border-bottom: 1px solid #aaa;
......@@ -107,9 +97,8 @@ table.ImageFrame_wood, table.ImageFrame_wood td {
border-top: none;
}
/* Garland adds padding which needs to be removed */
.block-gallery td, th {
padding: 0;
padding: 0; /* Garland adds padding which needs to be removed */
}
/* Navigation Tree */
......@@ -117,7 +106,7 @@ table.ImageFrame_wood, table.ImageFrame_wood td {
font-size: 1em;
}
/* For G2Image */
/* For g2ic_plugin */
img.g2image_float_left, div.g2image_float_left {
float: left;
margin: 0px 4px 4px 0px;
......@@ -135,7 +124,7 @@ img.g2image_centered, div.g2image_centered {
text-align: center;
}
/* Need to center images with frames */
/* Neeed to centre images with frames */
.g2image_centered table {
margin: auto;
}
......@@ -215,11 +204,10 @@ td.gallery-grid-block {
margin: auto;
}*/
/* Garland adds padding which needs to be removed */
.gallery-grid-block table,
.gallery-grid-block .one-image td,
.gallery-grid-block .one-image table {
padding: 0;
padding: 0; /* Garland adds padding which needs to be removed */
margin: auto;
}
......
......@@ -4,3 +4,4 @@ name = "Gallery"
description = "Embeds Gallery2 into Drupal."
package = "Gallery2"
core = 6.x
......@@ -10,15 +10,27 @@
* Implementation of hook_install().
*/
function gallery_install() {
drupal_set_message(t(''));
}
/**
* Implementation of hook_update_N().
* Migrate settings from the 5.x-1.x to 5.x-2.x series
* (migrate settings from the 5.x-1.x to 5.x-2.x (or 6.x-1.x) series)
*/
function gallery_update_1() {
$ret = array();
$variables = array();
// Fetch all gallery-related variables
$result = db_query("SELECT * FROM {variable} WHERE name LIKE 'gallery_%'");
while ($var = db_fetch_object($result)) {
$variables[$var->name] = $var->value;
}
// Remove old variables
db_query("DELETE FROM {variable} WHERE name LIKE 'gallery_%'");
// Array containing 'old name' => 'new name' map
$migrate = array(
$variable_map = array(
// Image block settings
'gallery_album_frame' => 'gallery_block_image_0_album_frame',
'gallery_block_block' => 'gallery_block_image_0_block_block',
......@@ -47,66 +59,32 @@ function gallery_update_1() {
'gallery_use_full_name' => 'gallery_use_fullname',
'gallery_profile_full_name_field' => 'gallery_profile_fullname_field'
);
// Array containing obsolete variables
$obsolete = array('gallery_search_max_items', 'gallery_autodetect_dir', 'gallery_uri', 'gallery_dir');
// Update variables
$ret = gallery_update_variables($migrate, $obsolete);
// Update the blocks
$ret[] = update_sql("UPDATE {blocks} SET delta = 'image-0' WHERE module = 'gallery' AND delta = 0");
$ret[] = update_sql("UPDATE {blocks} SET delta = 'navigation' WHERE module = 'gallery' AND delta = 1");
$ret[] = update_sql("UPDATE {blocks} SET delta = 'grid-0' WHERE module = 'gallery' AND delta = 2");
// Mark gallery configuration invalid. This does NOT reset the configuration, but
// forces the user to run the install wizard to (re)set and verify critical settings.
variable_set('gallery_valid', FALSE);
variable_set('gallery_config_reset', TRUE);
drupal_set_message('You were updating from gallery module 5.x-1.x (or earlier) to the 5.x-2.x
series of the module. All your settings were migrated automatically (see below),
but you will need to re-configure some basic options. Please visit the
Gallery settings page (admin/settings/gallery) to complete the update.',
'error');
cache_clear_all('variables', 'cache');
menu_rebuild();
return $ret;
}
/**
* Function gallery_update_variables().
*/
function gallery_update_variables($migrate, $obsolete) {
$ret = array();
$variables = array();
// Fetch all gallery-related variables
$result = db_query("SELECT * FROM {variable} WHERE name LIKE 'gallery_%'");
while ($var = db_fetch_object($result)) {
$variables[$var->name] = $var->value;
}
// Remove old variables
db_query("DELETE FROM {variable} WHERE name LIKE 'gallery_%'");
// Migrate old variables
foreach ($migrate as $old => $new) {
foreach ($variable_map as $old => $new) {
if (isset($variables[$old])) {
$variables[$new] = $variables[$old];
unset($variables[$old]);
$ret[] = array('success' => TRUE, 'query' => 'Migrating variable ['. $old .' => '. $new .']');
}
}
// Unset obsolete variables
$obsolete = array('gallery_search_max_items', 'gallery_autodetect_dir', 'gallery_uri', 'gallery_dir');
foreach ($obsolete as $var) {
if (isset($variables[$var])) {
unset($variables[$var]);
$ret[] = array('success' => TRUE, 'query' => 'Removing variable ['. $var .']');
}
}
// Mark gallery configuration invalid. This does NOT reset the configuration, but
// forces the user to run the install wizard to (re)set and verify critical settings.
$variables['gallery_valid'] = FALSE;
drupal_set_message('You were updating from gallery module 5.x-1.x (or earlier) to the 6.x-1.x
of the module. All your settings were migrated automatically (see below),
but you will need to re-configure some basic options. Please visit the
Gallery settings page (admin/settings/gallery) to complete the update.',
'error');
// Save resulting variables array
// (all variables not migrated or unset are taken over directly)
foreach ($variables as $name => $value) {
......@@ -114,10 +92,24 @@ function gallery_update_variables($migrate, $obsolete) {
// (i.e. unserialize => serialize and cache_clear_all() for each variable)
db_query("INSERT INTO {variable} (name, value) VALUES ('%s', '%s')", $name, $value);
}
cache_clear_all('variables', 'cache');
menu_rebuild();
return $ret;
}
/**
* Implementation of hook_update_N().
* (initial update to Drupal 6)
*/
function gallery_update_6001() {
$ret = array();
$ret[] = array('success' => TRUE, 'query' => 'Removing variable [gallery_page_callback]');
variable_del('gallery_page_callback');
return $ret;
}
/**
* Implementation of hook_uninstall().
*/
......
This diff is collapsed.
......@@ -6,24 +6,28 @@
* Base functions
*/
define(GALLERY_ERROR_WATCHDOG, 1);
define(GALLERY_ERROR_BROWSER, 2);
define(GALLERY_ERROR_VERBOSE, 3);
define('GALLERY_ERROR_WATCHDOG', 1);
define('GALLERY_ERROR_BROWSER', 2);
define('GALLERY_ERROR_VERBOSE', 3);
define(GALLERY_SEVERITY_SUCCESS, 1);
define(GALLERY_SEVERITY_ERROR, -1);
define(GALLERY_SEVERITY_WARNING, -2);
define(GALLERY_SEVERITY_ADVISE, -3);
define(GALLERY_SEVERITY_UNKNOWN, -4);
define('GALLERY_SEVERITY_SUCCESS', 1);
define('GALLERY_SEVERITY_ERROR', -1);
define('GALLERY_SEVERITY_WARNING', -2);
define('GALLERY_SEVERITY_ADVISE', -3);
define('GALLERY_SEVERITY_UNKNOWN', -4);
define(GALLERY_PLUGIN_ENABLED, 1);
define(GALLERY_PLUGIN_DISABLED, 0);
define(GALLERY_PLUGIN_STATUS_UNKNOWN, -1);
define(GALLERY_PLUGIN_NOT_ACTIVE, -2);
define(GALLERY_PLUGIN_NOT_INSTALLED, -3);
define(GALLERY_PLUGIN_MISSING, -4);
define('GALLERY_PLUGIN_ENABLED', 1);
define('GALLERY_PLUGIN_DISABLED', 0);
define('GALLERY_PLUGIN_STATUS_UNKNOWN', -1);
define('GALLERY_PLUGIN_NOT_ACTIVE', -2);
define('GALLERY_PLUGIN_NOT_INSTALLED', -3);
define('GALLERY_PLUGIN_MISSING', -4);
define(GALLERY_DEBUGTRACE, TRUE);
define('GALLERY_PLUGIN_WANTED', 1);
define('GALLERY_PLUGIN_UNWANTED', 2);
define('GALLERY_PLUGIN_DRUPAL', 3);
define('GALLERY_DEBUGTRACE', TRUE);
/**
* Function gallery_login().
......@@ -57,21 +61,13 @@ function _gallery_init($full = FALSE, $vars = NULL, $report_error = TRUE) {
return TRUE;
}
if (!$vars) {
$embed_path = variable_get('gallery_dir', './gallery2/') .'embed.php';
$g2_uri = variable_get('gallery_uri', '/gallery2/');
$embed_uri = variable_get('gallery_embed_uri', '?q=gallery');
$gallery_valid = variable_get('gallery_valid', 0);
$uid = ($user->uid > 0) ? $user->uid : '';
}
else {
$embed_path = $vars['gallery_dir'] .'embed.php';
$g2_uri = $vars['gallery_uri'];
$embed_uri = $vars['gallery_embed_uri'];
$gallery_valid = $vars['gallery_valid'];
$uid = '';
}
$embed_path = (isset($vars['gallery_dir']) ? $vars['gallery_dir'] : variable_get('gallery_dir', './gallery2/')) .'embed.php';
$g2_uri = isset($vars['gallery_uri']) ? $vars['gallery_uri'] : variable_get('gallery_uri', '/gallery2/');
$embed_uri = isset($vars['gallery_embed_uri']) ? $vars['gallery_embed_uri'] : variable_get('gallery_embed_uri', '?q=gallery');
$gallery_valid = isset($vars) ? (isset($vars['gallery_valid']) ? $vars['gallery_valid'] : TRUE) : variable_get('gallery_valid', 0);
$uid = isset($vars) ? (isset($vars['uid']) ? $vars['uid'] : '') : (($user->uid > 0) ? $user->uid : '');
$init_err_msg = t('Unable to initialize embedded Gallery. You need to <a href="@link"> configure your embedded Gallery</a>.',
array('@link' => url('admin/settings/gallery/install')));
......@@ -81,20 +77,14 @@ function _gallery_init($full = FALSE, $vars = NULL, $report_error = TRUE) {
}
return FALSE;
}
include_once($embed_path);
// i18n url rewrite
$language = gallery_get_language($user);
if (module_exists('i18n')) {
$embed_uri = preg_replace('/index.php\?q=/', i18n_path('index.php?q=', $language), $embed_uri);
}
include_once($embed_path);
$params = array('embedUri' => $embed_uri,
'g2Uri' => $g2_uri,
'loginRedirect' => url('user/login', drupal_get_destination(), NULL, TRUE),
'loginRedirect' => url('user/login', array('query' => drupal_get_destination(), 'absolute' => TRUE)),
'activeUserId' => $uid,
'activeLanguage' => $language,
'activeLanguage' => gallery_get_language($user),
'fullInit' => $full,
'apiVersion' => array(1, 2));
......@@ -132,11 +122,6 @@ function _gallery_init($full = FALSE, $vars = NULL, $report_error = TRUE) {
* (handleRequest extension with error handling)
*/
function gallery_handle_request() {
// Remove the language-prefix for G2
if (!empty($_GET['g2_path']) && module_exists('i18n')) {
i18n_get_lang_prefix($_GET['g2_path'], TRUE);
}
ob_start();
$result = GalleryEmbed::handleRequest();
$output = ob_get_contents();
......@@ -150,12 +135,12 @@ function gallery_handle_request() {
}
else {
// Otherwise (on regular pages) $output means that an error occured
preg_match('%<div id="giStackTrace" [^>]*>(.*?)</div>%is', $output, $matches);
if (variable_get('gallery_error_redirect', 0) && user_access('search content')) {
drupal_set_message('The requested Gallery URL does not exist. The item may have been
moved or deleted. You can search for it below.', 'notice');
drupal_goto('search/gallery');
}
preg_match('%<div id="giStackTrace" [^>]*>(.*?)</div>%is', $output, $matches);
gallery_error(t('Error handling request (invalid request)<br />or the requested Gallery URL does not exist.'), $matches[1], TRUE);
return NULL;
}
......@@ -169,55 +154,13 @@ function gallery_handle_request() {
* (get the language for $user)
*/
function gallery_get_language($user) {
// Default is the user-specific language
$language = $user->uid ? $user->language : '';
// If i18n is enabled, use that language instead
if (module_exists('i18n')) {
$language = i18n_get_lang();
}
// If there is still no language available, try to get the default one
if (empty($language)) {
$language = 'en';
if (module_exists('locale')) {
$result = db_query('SELECT locale FROM {locales_meta} WHERE isdefault = 1');
$language = db_result($result);
}
}
// Convert certain lang codes, e.g. 'esl/spa es' => 'es' or 'fr-ca' => 'fr'
return preg_replace(array('/([\w\/]+) ([a-z]{2,3})/i', '/([a-z]{2,3})-(\w+)/i'), array('${2}', '${1}'), $language);
}
global $language;
/**
* Function gallery_get_themes().
* (retrieve all (active) themes from Gallery2)
*/
function gallery_get_themes() {
if (!_gallery_init()) {
return array();
}
// List of themes
list($ret, $g2_themes) = GalleryCoreApi::fetchPluginStatus('theme', TRUE);
if ($ret) {
gallery_error(t('Error retrieving theme list'), $ret);
return array();
}
$themes = array();
foreach (array_keys($g2_themes) as $themeid) {
// Only active themes
if (!empty($g2_themes[$themeid]['active'])) {
// Get theme details
list($ret, $theme) = GalleryCoreApi::loadPlugin('theme', $themeid, TRUE);
if ($ret) {
gallery_error(t('Error getting theme (:themeid) details',
array(':themeid' => $themeid)), $ret);
return array();
}
$themes[$themeid] = $theme->getName();
}
}
$lang = ($user->uid > 0 && !empty($user->language)) ? $user->language : $language->language;
// Convert certain lang codes, e.g. 'esl/spa es' => 'es' or 'fr-ca' => 'fr'
$lang = preg_replace(array('/([\w\/]+) ([a-z]{2,3})/i', '/([a-z]{2,3})-(\w+)/i'), array('${2}', '${1}'), $lang);
return $themes;
return $language->language;
}
/**
......@@ -237,7 +180,7 @@ function gallery_get_image_frames() {
if ($ret) {
return array('none' => t('None'));
}
return $list;
}
......@@ -245,24 +188,26 @@ function gallery_get_image_frames() {
* Function gallery_generate_url().
*/
function gallery_generate_url($params, $html = TRUE, $full = TRUE) {
if (!_gallery_init(TRUE)) {
return '';
if (!isset($GLOBALS['gallery'])) {
if (!_gallery_init()) {
return '';
}
}
// Get URL generator and generate the url
$url_generator =& $GLOBALS['gallery']->getUrlGenerator();
if (!$url_generator) {
gallery_error(t('Error: UrlGenerator not available'));
return '';
}
$options = array();
$options['forceFullUrl'] = $full;
$options['htmlEntities'] = $html;
if (!isset($params['view'])) {
$params['view'] = 'core.ShowItem';
}
return $url_generator->generateUrl($params, $options);
}
......@@ -270,7 +215,7 @@ function gallery_generate_url($params, $html = TRUE, $full = TRUE) {
* Function gallery_album_tree().
*/
function gallery_album_tree($root = NULL, $depth = NULL, $uid = NULL) {
if (!_gallery_init(TRUE)) {
if (!_gallery_init()) {
return array();
}
// If this is called for the Drupal guest user, pass in G2
......@@ -297,13 +242,10 @@ function gallery_album_tree($root = NULL, $depth = NULL, $uid = NULL) {
*/
function gallery_item_details($id, $verbose = FALSE) {
$details = array();
if (!_gallery_init(TRUE)) {
return $details;
}
// Load entity
list($ret, $entity) = GalleryCoreApi::loadEntitiesById($id);
if ($ret) {
gallery_error(t('Error fetching item details (entityId: :id)',
gallery_error(t('Error fetching album details (entityId: :id)',
array(':id' => $id)), $ret);
return $details;
}
......@@ -319,7 +261,7 @@ function gallery_item_details($id, $verbose = FALSE) {
$details['g2description'] = _gallery_htmlcharsdecode($entity->description);
$details['g2summary'] = _gallery_htmlcharsdecode($entity->summary);
$details['g2keywords'] = $entity->keywords;
$details['g2theme'] = isset($entity->theme) ? $entity->theme : NULL;
$details['g2theme'] = $entity->theme;
}
return $details;
......@@ -329,10 +271,11 @@ function gallery_item_details($id, $verbose = FALSE) {
* Function gallery_db_query().
*/
function gallery_db_query($query, $data = NULL) {
if (!_gallery_init(TRUE)) {
return FALSE;
if (!isset($GLOBALS['gallery'])) {
if (!_gallery_init()) {
return FALSE;
}
}
// Perform query
list ($ret, $search) = $GLOBALS['gallery']->search($query, $data);
if ($ret) {
return FALSE;
......@@ -349,10 +292,11 @@ function gallery_db_query($query, $data = NULL) {
* Function gallery_flush_entity_cache().
*/
function gallery_flush_entity_cache() {
if (!_gallery_init()) {
return FALSE;
if (!isset($GLOBALS['gallery'])) {
if (!_gallery_init()) {
return FALSE;
}
}
// Flush entity cache
$platform =& $GLOBALS['gallery']->getPlatform();
$cache_basedir = $GLOBALS['gallery']->getConfig('data.gallery.cache');
$cache_dir = $cache_basedir .'entity';
......@@ -389,29 +333,21 @@ function gallery_set_css($css) {
if (count($css)) {
$css = preg_replace('/<link(.*?)href="([^"]*)"(.*?)\/>/i', '${2}', $css);
$css = preg_replace(array('#^'. $base_url .'#', '#^'. base_path() .'#', '#^/#'), '', $css);
foreach ($css as $include) {
if (!in_array(($md5 = md5($include)), $css_memory)) {
$css_memory[] = $md5;
if (variable_get('gallery_outside', 0)) {
if (substr($include, 0, 6) == '<style') {
// drupal_add_css() does not support inline styles
drupal_set_html_head($include);
}
elseif (substr($include, 0, 4) == 'http' || variable_get('gallery_outside', 0)) {
// drupal_add_css() does not support external paths
drupal_set_html_head('<link type="text/css" rel="stylesheet" media="all" href="'. $include .'" />');
drupal_set_html_head('<link type="text/css" rel="stylesheet" media="all" href="'. $include .'" />'."\n");
}
else {
$include = preg_replace(array('#^'. $base_url .'#', '#^'. base_path() .'#', '#^/#'), '', $include);
// Workaround for urls containing '&amp;' with @import directive (#157978)
$include = str_replace('&amp;g2_frames', '&g2_frames', $include);
if (substr($include, 0, 6) == '<style') {
// drupal_add_css() does not support inline styles
drupal_set_html_head($include);
}
elseif (substr($include, 0, 4) == 'http') {
// drupal_add_css() does not support external paths
drupal_set_html_head('<style type="text/css" media="all">@import "'. $include .'";</style>');
}
else {
// Gallery's css must always be added first to allow overriding from the module(s)
drupal_add_css($include, 'module', 'all', FALSE);
}
// Gallery's css must always be added first to allow overriding from the module(s)
drupal_add_css($include, 'module', 'all', FALSE);
}
}
}
......@@ -434,59 +370,22 @@ function gallery_set_javascript($javascript) {
drupal_add_js(implode("\n", $inline), 'inline');
// Javascript files
$files = preg_replace('/<script(.*?)src="([^"]*)"([^>]*)>(.*?)<\/script>/i', '${2}', $files);
$files = preg_replace(array('#^'. $base_url .'#', '#^'. base_path() .'#', '#^/#'), '', $files);
foreach ($files as $include) {
if (!in_array(($md5 = md5($include)), $js_memory)) {
$js_memory[] = $md5;
if (variable_get('gallery_outside', 0)) {
if (substr($include, 0, 4) == 'http' || variable_get('gallery_outside', 0)) {
// drupal_add_js() does not support external paths
drupal_set_html_head('<script type="text/javascript" src="'. $include .'"></script>');
drupal_set_html_head('<script type="text/javascript" src="'. $include .'"></script>'."\n");
}
else {
$include = preg_replace(array('#^'. $base_url .'#', '#^'. base_path() .'#', '#^/#'), '', $include);
if (substr($include, 0, 4) == 'http') {
// drupal_add_js() does not support external paths
drupal_set_html_head('<script type="text/javascript" src="'. $include .'"></script>');
}
else {
drupal_add_js($include);
}
drupal_add_js($include);
}
}
}
}
}