Commit adefaf3d authored by profix898's avatar profix898

- task: complete update to D6 (block handling, page context, etc.) + various bugfixes

parent 6539308d
......@@ -10,7 +10,6 @@
* Implementation of hook_install().
*/
function gallery_install() {
drupal_set_message(t(''));
}
/**
......@@ -78,7 +77,7 @@ function gallery_update_1() {
* Implementation of hook_update_N().
* (initial update to Drupal 6)
*/
function gallery_update_6001() {
function gallery_update_6000() {
$delta = 0;
$new = $migrate = array();
// Image block settings
......@@ -87,7 +86,7 @@ function gallery_update_6001() {
$delta++;
$new += array(
'gallery_block_'. $delta .'_type' => 'imageblock',
'gallery_block_'. $delta .'_imageblock_num_cols' => 1,
'gallery_block_'. $delta .'_imageblock_num_cols' => 1
);
$migrate += array(
'gallery_block_image_'. $i .'_blockid' => 'gallery_block_'. $delta .'_blockid',
......@@ -100,8 +99,9 @@ function gallery_update_6001() {
'gallery_block_image_'. $i .'_album_frame' => 'gallery_block_'. $delta .'_imageblock_album_frame',
'gallery_block_image_'. $i .'_item_frame' => 'gallery_block_'. $delta .'_imageblock_item_frame',
'gallery_block_image_'. $i .'_link_target' => 'gallery_block_'. $delta .'_imageblock_link_target',
'gallery_block_image_'. $i .'_link' => 'gallery_block_'. $delta .'_imageblock_link',
'gallery_block_image_'. $i .'_link' => 'gallery_block_'. $delta .'_imageblock_link'
);
$ret[] = update_sql("UPDATE {blocks} SET delta = 'block-%d' WHERE module = 'gallery' AND delta = 'image-%d'", $delta, $i);
}
// Grid block settings
$gridblock_num = variable_get('gallery_block_grid_num', 1);
......@@ -120,25 +120,22 @@ function gallery_update_6001() {
'gallery_block_grid_'. $i .'_album_frame' => 'gallery_block_'. $delta .'_imageblock_album_frame',
'gallery_block_grid_'. $i .'_item_frame' => 'gallery_block_'. $delta .'_imageblock_item_frame',
'gallery_block_grid_'. $i .'_link_target' => 'gallery_block_'. $delta .'_imageblock_link_target',
'gallery_block_grid_'. $i .'_link' => 'gallery_block_'. $delta .'_imageblock_link',
'gallery_block_grid_'. $i .'_link' => 'gallery_block_'. $delta .'_imageblock_link'
);
$ret[] = update_sql("UPDATE {blocks} SET delta = 'block-%d' WHERE module = 'gallery' AND delta = 'grid-%d'", $delta, $i);
}
$new['gallery_block_num'] = $delta;
// Array containing obsolete variables
$obsolete = array('gallery_page_callback', 'gallery_block_image_num', 'gallery_block_grid_num');
// Update variables
$ret = gallery_update_variables($migrate, $obsolete);
// Add new variables
foreach ($new as $name => $value) {
db_query("INSERT INTO {variable} (name, value) VALUES ('%s', '%s')", $name, $value);
}
// 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");
cache_clear_all('variables', 'cache');
menu_rebuild();
......
......@@ -357,8 +357,8 @@ function gallery_elements() {
* (add image link underneath textareas)
*/
function gallery_g2image_textarea($element) {
require_once(drupal_get_path('module', 'gallery') .'/gallery_g2image.inc');
if (_gallery_g2image_page_match() && !strstr($_GET['q'], 'gallery')
require_once(drupal_get_path('module', 'gallery') .'/gallery_g2image.inc');
if (_gallery_g2image_page_match() && !strstr($_GET['q'], 'gallery')
&& (variable_get('gallery_g2image_mode', 'disabled') == 'standalone')
&& (user_access('access standalone g2image'))) {
gallery_g2image_add_js();
......@@ -395,12 +395,12 @@ function gallery_page() {
if ($result && !$result['isDone']) {
// Allow modules to alter the page
drupal_alter('gallery_page', $result, array());
// Add css/js for this page
// Add css/js/meta for this page
gallery_set_head($result['headHtml'], TRUE);
// Add pathbar. See http://gallery.menalto.com/node/33447
if (isset($result['themeData'])) {
$breadcrumb = array(l(t('Home'), ''));
// Some themes (eg hybrid) do not set $result['themeData']['parents']
// Some themes (e.g. hybrid) do not set $result['themeData']['parents']
if ($result['themeData']['parents']) {
foreach ($result['themeData']['parents'] as $parent) {
$parent_title = $parent['title'];
......@@ -418,6 +418,8 @@ function gallery_page() {
}
}
drupal_set_breadcrumb($breadcrumb);
// store G2 page context
gallery_context($result['themeData'], TRUE);
}
// Hack to get the admin sidebar
if (variable_get('gallery_move_admin_sidebar_to_block', 0)) {
......
......@@ -71,7 +71,7 @@ function _gallery_init($full = FALSE, $vars = NULL, $report_error = TRUE) {
$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')));
if ((!$gallery_valid) || (!is_readable($embed_path))) {
if (!$gallery_valid || !is_readable($embed_path)) {
if ($report_error) {
gallery_error($init_err_msg);
}
......@@ -105,24 +105,21 @@ function _gallery_init($full = FALSE, $vars = NULL, $report_error = TRUE) {
}
// Allow modules to alter the init parameters
drupal_alter('gallery_init', $params);
drupal_alter('gallery_init', $params, array());
// Initialize Gallery2
include_once($embed_path);
$ret = GalleryEmbed::init($params);
if ($ret) {
if ($ret->getErrorCode() & ERROR_PLUGIN_VERSION_MISMATCH) {
if ($report_error) {
if ($report_error) {
if ($ret->getErrorCode() & ERROR_PLUGIN_VERSION_MISMATCH) {
gallery_error($vars ? t('Embedding API version is incompatible.') : $init_err_msg, $ret, TRUE);
}
return FALSE;
}
else {
if ($report_error) {
else {
gallery_error($init_err_msg, $ret, TRUE);
}
return FALSE;
}
return FALSE;
}
// Check if initialization was successful
......@@ -147,11 +144,10 @@ function _gallery_init($full = FALSE, $vars = NULL, $report_error = TRUE) {
// Set theme for embedded gallery
if ((!$full || !$ready['half']) && isset($params['themeId'])) {
// TODO: G2.3
/*$ret = GalleryEmbed::setThemeForRequest($g2_theme);
$ret = GalleryEmbed::setThemeForRequest($params['themeId']);
if ($ret && $report_error) {
gallery_error(t('Error settings embedded theme (%theme).', array('%theme' => $g2_theme)));
}*/
gallery_error(t('Error settings embedded theme (%theme).', array('%theme' => $params['themeId'])));
}
}
// Allow other modules to perform post-init tasks
module_invoke_all('gallery_init', $full);
......@@ -218,7 +214,7 @@ function gallery_get_language($user) {
// 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 $language->language;
return $lang;
}
/**
......@@ -507,6 +503,42 @@ function gallery_set_javascript($javascript) {
}
}
/**
* Function gallery_context().
* (store and/or access the context of the current gallery page)
*/
function gallery_context(&$params, $setcontext = FALSE) {
static $context_cache = NULL;
if ($setcontext) {
// store new context
$context_cache = (isset($params) && count($params)) ? $params : array();
gallery_debug($context_cache, t('Context cache'));
}
else if (isset($context_cache)) {
// get context parameters
if (isset($params)) {
// return requested context parameters
$params = is_array($params) ? $params : array($params);
foreach($params as $param) {
if (!isset($context_cache[$param])) {
return FALSE;
}
$context[$param] = $context_cache[$param];
}
$params = $context;
}
else {
// return all stored context parameters
$params = $context_cache;
}
return TRUE;
}
return FALSE;
}
/**
* Function gallery_get_blocks().
*/
......@@ -614,11 +646,9 @@ function _gallery_htmlcharsdecode($string) {
return strtr($string, array_flip(get_html_translation_table(HTML_SPECIALCHARS)));
}
/*
* --------------------------------------------------------------------------
/* --------------------------------------------------------------------------
* Error, Debug and Status Functions
* --------------------------------------------------------------------------
*/
* -------------------------------------------------------------------------- */
/**
* Function gallery_error().
......
......@@ -52,19 +52,39 @@ function _gallery_block($op = 'list', $delta = 0, $edit = array()) {
*/
function _gallery_block_map($refresh = FALSE) {
// Get block map from cache (or rebuild map)
$cache = cache_get('gallery:blocksmap', 'cache');
$cache = cache_get('gallery:blockmap', 'cache');
if (!$cache || $refresh) {
// Rebuild block map
$block_map = array();
$g2_blocks = gallery_get_blocks();
foreach ($g2_blocks as $plugin => $blocks) {
foreach (array_keys($blocks) as $block) {
switch ($block) {
// Blocks with no required parameter
case 'AlbumSelect':
case 'AlbumTree':
case 'ShowCart':
case 'LanguageSelector':
case 'MembersSummary':
case 'QuotasSummary':
case 'RssBlock':
$params = array();
break;
// Parameter defaults to 'item'
// (required by 'ViewComments', 'AddComment', 'ItemInfo', 'ItemLinks',
// 'PeerList', 'CustomFields', 'ExifInfo', 'KeywordLinks', 'Rating', ...)
default:
$params = array('item');
}
//
$block_map[strtolower($block)] = array(
'plugin' => $plugin,
'block' => $block
'block' => $block,
'params' => $params
);
}
}
cache_set('gallery:blocksmap', $block_map, 'cache', CACHE_PERMANENT);
cache_set('gallery:blockmap', $block_map, 'cache', CACHE_PERMANENT);
}
else {
$block_map = $cache->data;
......@@ -96,19 +116,25 @@ function _gallery_block_block($delta) {
$block_type = variable_get('gallery_block_'. $delta .'_type', 'imageblock');
$plugin = $block_map[$block_type]['plugin'];
$plugin_block = $block_map[$block_type]['block'];
$params = $block_map[$block_type]['params'];
//
// ImageBlock needs special handling
if ($plugin_block == 'ImageBlock') {
return _gallery_block_image_block($delta, $plugin, $plugin_block);
}
//
$params = array();
// Check for required parameters
if (!gallery_context($params)) {
return FALSE;
}
// Add custom parameters
$g2_blocks = gallery_get_blocks();
foreach ($g2_blocks[$plugin][$plugin_block]['vars'] as $parameter => $options) {
$block = strtolower($plugin_block .'_'. $parameter);
$element = 'gallery_block_'. $delta .'_'. $block;
$params[$parameter] = variable_get($element, $options['default']);
if (isset($g2_blocks[$plugin][$plugin_block]['vars'])) {
foreach ($g2_blocks[$plugin][$plugin_block]['vars'] as $parameter => $options) {
$block = strtolower($plugin_block .'_'. $parameter);
$element = 'gallery_block_'. $delta .'_'. $block;
$params[$parameter] = variable_get($element, $options['default']);
}
}
return _gallery_block_get_block($plugin, $plugin_block, $params);
......@@ -151,9 +177,8 @@ function _gallery_block_image_block($delta, $plugin, $plugin_block) {
* Function _gallery_block_get_block().
*/
function _gallery_block_get_block($plugin, $plugin_block, $params, $extra = array()) {
//
// Handle useralbum feature (for ImageBlocks)
if ($plugin_block == 'ImageBlock') {
// Handle useralbum feature
if (preg_match('/user(:([\d]+))?/i', $params['itemId'], $param_uid)) {
require_once(drupal_get_path('module', 'gallery') .'/gallery_user.inc');
$params['itemId'] = gallery_user_useralbum(isset($param_uid[2]) ? $param_uid[2] : NULL, FALSE);
......@@ -162,7 +187,7 @@ function _gallery_block_get_block($plugin, $plugin_block, $params, $extra = arra
unset($params['itemId']);
}
}
gallery_debug($params, t('Block parameters'));
// Get the block from G2
list($ret, $content, $head) = GalleryEmbed::getBlock($plugin, $plugin_block, $params);
......@@ -170,19 +195,24 @@ function _gallery_block_get_block($plugin, $plugin_block, $params, $extra = arra
gallery_error(t('Error trying to get block.'), $ret);
return array();
}
$content = trim($content);
// Allow other modules to alter the block output
drupal_alter('gallery_block', $content, array('params' => $params, 'extra' => $extra));
// Format the block content
$block = array();
if ($content) {
if (!empty($content)) {
$block['subject'] = t('Gallery');
if (isset($extra['num_cols'])) {
$class = isset($extra['class']) ? $extra['class'] : 'gallery-grid-block';
$block['content'] = theme('gallery_block_grid_block', $content, $extra['num_cols'], $class);
}
else {
$class = isset($extra['class']) ? $extra['class'] : 'g2image_centered';
$block['content'] = theme('gallery_block_image_block', $content, $class);
$block['content'] = $content;
//
if ($plugin_block == 'ImageBlock') {
if (isset($extra['num_cols'])) {
$class = isset($extra['class']) ? $extra['class'] : 'gallery-grid-block';
$block['content'] = theme('gallery_block_grid_block', $content, $extra['num_cols'], $class);
}
else {
$class = isset($extra['class']) ? $extra['class'] : 'g2image_centered';
$block['content'] = theme('gallery_block_image_block', $content, $class);
}
}
// Add css/js to the page
if ($head) {
......
......@@ -76,7 +76,7 @@ function _gallery_block_admin_block($delta) {
'#type' => 'fieldset',
'#title' => t('%block settings', array('%block' => $plugin_block)),
'#collapsible' => FALSE,
'#collapsed' => FALSE,
'#collapsed' => FALSE
);
$form[$block_type][] = $param_form;
}
......@@ -297,6 +297,7 @@ function _gallery_block_admin_imageblock($delta, $plugin, $plugin_block, $g2_blo
*/
function _gallery_block_admin_update($form, &$form_state) {
_gallery_block_admin_save(0, $form_state['values']);
db_query("UPDATE {blocks} SET title = '%s' WHERE module = '%s' AND delta = '%s'", $form_state['values']['title'], $form_state['values']['module'], $form_state['values']['delta']);
}
/**
......
......@@ -122,11 +122,12 @@ function gallery_filter_process($text) {
gallery_error(t('Error trying to get image block.'), $ret);
continue;
}
if ($content) {
$content = trim($content);
if (!empty($content)) {
$params['class'] = 'giImageBlock'. ($params['class'] ? ' '. $params['class'] : '');
$content = '<div class ="'. $params['class'] .'">'. $content .'</div>';
// Allow other modules to alter the filter output
drupal_alter('gallery_filter', $content, array('params' => $params));
$content = '<div class ="'. $params['class'] .'">'. $content .'</div>';
}
// Replace G2 filter tag with image block html (or at least remove filter tag)
$text = str_replace($match[0], $content, $text);
......
......@@ -57,7 +57,7 @@ function _gallery_install_status_report($install_status) {
foreach ($install_status as $step => $status) {
// Find the combination of status and severity of the plugin
$severity = ($status['status'] <= 0) ? $status['severity'] : GALLERY_SEVERITY_SUCCESS;
if (!$status['status']) {
if (!$status['status'] && $severity == GALLERY_SEVERITY_ERROR) {
$error = TRUE;
}
$row = array();
......@@ -150,29 +150,31 @@ function _gallery_install_status($form_state) {
// Step 3: Drupal Modules and Gallery2 Plugins check
$form += _gallery_install_plugins($install_status);
// Step 4: Clean URL configuration
_gallery_install_urlrewrite_check($install_status);
if (_gallery_install_urlrewrite($public_path, $htaccess_path, TRUE)) {
$form['urlrewrite'] = array(
'#type' => 'fieldset',
'#title' => t('Clean URLs / URL Rewrite settings'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
'#description' => t('Overview of your URL Rewrite settings as specified during install.')
if (gallery_single_plugin_status('rewrite') == GALLERY_PLUGIN_ENABLED) {
if (_gallery_install_urlrewrite($public_path, $htaccess_path, TRUE)) {
$form['urlrewrite'] = array(
'#type' => 'fieldset',
'#title' => t('Clean URLs / URL Rewrite settings'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
'#description' => t('Overview of your URL Rewrite settings as specified during install.')
);
$form['urlrewrite']['htaccess_public_path'] = array(
'#title' => t('Public path to your .htaccess file'),
'#type' => 'item',
'#value' => $public_path
);
$form['urlrewrite']['htaccess_public_path'] = array(
'#title' => t('Public path to your .htaccess file'),
'#type' => 'item',
'#value' => $public_path
);
$form['urlrewrite']['htaccess_filesystem_path'] = array(
'#title' => t('Filesystem path to your .htaccess file'),
'#type' => 'item',
'#value' => $htaccess_path
);
$form['urlrewrite']['htaccess_filesystem_path'] = array(
'#title' => t('Filesystem path to your .htaccess file'),
'#type' => 'item',
'#value' => $htaccess_path
);
}
}
// Step 5: User Synchronization
$install_status['usersync']['status'] = TRUE;
$install_status['usersync']['info'] = t('Your initial user synchronization has been completed already.<br /> If you
......@@ -1123,6 +1125,10 @@ function _gallery_install_urlrewrite(&$public_path, &$htaccess_path, $load_confi
list($ret, $rewrite_api) = GalleryCoreApi::newFactoryInstance('RewriteApi');
if ($ret || !isset($rewrite_api)) {
gallery_error(t('Error trying to create URL Rewrite plugin instance.'), $ret);
if (!$ret) {
drupal_set_message(t('URL Rewrite plugin could not be instantiated.
Please check its configuration in standalone Gallery2.'), 'error');
}
return FALSE;
}
......@@ -1144,7 +1150,7 @@ function _gallery_install_urlrewrite(&$public_path, &$htaccess_path, $load_confi
$htaccess_path = $params['embeddedHtaccess'];
}
}
// Check for trailing slash
$public_path .= (substr($public_path, -1) != '/') ? '/' : '';
$htaccess_path .= (substr($htaccess_path, -1) != '/') ? '/' : '';
......@@ -1170,7 +1176,7 @@ function _gallery_install_urlrewrite(&$public_path, &$htaccess_path, $load_confi
return FALSE;
}
if ($code) {
$errstr = $code .' - '. $errstr;
$errstr = $code .' - '. (is_array($errstr) ? $errstr[1] : $errstr);
drupal_set_message(t('The Gallery2 URL Rewrite plugin returned the following error:') .'<br /><pre>'. $errstr .'</pre>', 'error');
return FALSE;
}
......
......@@ -11,7 +11,7 @@
*/
function _gallery_report($download = FALSE, $report = array(), $cache = FALSE) {
// provide download of the cached report
if ($download && ($content = cache_get('gallery_report_'. session_id()))) {
if ($download && ($content = cache_get('gallery:report_'. session_id()))) {
_gallery_report_download($content->data);
}
......@@ -100,10 +100,10 @@ function _gallery_report($download = FALSE, $report = array(), $cache = FALSE) {
$content = theme('gallery_report', $report);
if ($cache) {
if ($cache_content = cache_get('gallery_report_'. session_id())) {
if ($cache_content = cache_get('gallery:report_'. session_id())) {
$content .= $cache_content->data;
}
cache_set('gallery_report_'. session_id(), 'cache', $content, time()+600);
cache_set('gallery:report_'. session_id(), $content, 'cache', time()+600);
}
if ($download) {
_gallery_report_download($content);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment