Commit 23959868 authored by profix898's avatar profix898

- bugfix: Gallery2 JS and CSS broken (#188035 and #224019)

- bugfix: report version info for all gallery* modules
- bugfix: session handling to prevent TempIds
- bugfix: session handling to workaround [sf#1967484] new admin session protection (#250770)
- bugfix: hide search for user without proper permission
- feature: integration with advanced help module (TODO: write documentation)
- task: cleanup block tpl code
- task: add base api version constant
parent 9460d7b0
......@@ -363,8 +363,10 @@ function gallery_user($op, &$edit, &$user, $category = NULL) {
* Implementation of hook_search().
*/
function gallery_search($op = 'search', $keys = NULL) {
require_once(drupal_get_path('module', 'gallery') .'/gallery_search.inc');
return _gallery_search($op, $keys);
if (user_access('access gallery') && (gallery_single_plugin_status('search') == GALLERY_PLUGIN_ENABLED)) {
require_once(drupal_get_path('module', 'gallery') .'/gallery_search.inc');
return _gallery_search($op, $keys);
}
}
/**
......@@ -394,6 +396,16 @@ function gallery_form_alter(&$form, $form_state, $form_id) {
else if ($form_id == 'user_login_block' || $form_id == 'user_login') {
$form['#validate'][] = 'gallery_auth_validate';
}
// Add advanced help to gallery forms
if (module_exists('advanced_help')) {
require_once(drupal_get_path('module', 'gallery') .'/gallery_help.inc');
$help = _gallery_advanced_help_get_form_help($form_id);
foreach ($help as $element => $topic) {
$help_icon = theme('advanced_help_topic', 'gallery', $topic);
$form[$element]['#description'] = $help_icon .' '. $form[$element]['#description'];
}
}
}
/**
......
......@@ -6,6 +6,8 @@
* Base functions
*/
define('GALLERY_BASE_API', 1);
define('GALLERY_ERROR_WATCHDOG', 1);
define('GALLERY_ERROR_BROWSER', 2);
define('GALLERY_ERROR_VERBOSE', 3);
......@@ -159,6 +161,15 @@ function _gallery_init($full = FALSE, $vars = NULL, $report_error = TRUE) {
gallery_error(t('Failed to register event listeners.'), $ret);
}
}
// Session handling
$g2_session =& $GLOBALS['gallery']->getSession();
$g2_session->doNotUseTempId();
//
list ($ret, $g2_admin) = GalleryCoreApi::isUserInSiteAdminGroup();
if (!$ret && $g2_admin) {
$g2_session->put('session.siteAdminActivityTimestamp', time());
}
$ready['half'] = $params['fullInit'] ? ($ready['full'] = TRUE) : TRUE;
......@@ -395,11 +406,11 @@ function gallery_item_details($id, $verbose = FALSE) {
$details['g2type'] = $entity->entityType;
$details['g2owner'] = $entity->ownerId;
$details['g2parent'] = $entity->parentId;
// Drupal node properties (no g2 prefix)
// Drupal node properties (without g2 prefix)
$details['title'] = _gallery_htmlcharsdecode($entity->title);
$details['created'] = $entity->creationTimestamp;
$details['changed'] = $entity->modificationTimestamp;
// Gallery2 item properties (with g2 prefix)
if ($verbose) {
$details['g2description'] = _gallery_htmlcharsdecode($entity->description);
$details['g2summary'] = _gallery_htmlcharsdecode($entity->summary);
......@@ -495,7 +506,7 @@ function gallery_set_meta($meta) {
if (empty($meta_memory)) {
$meta_memory[] = md5('<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>');
}
// Handle head/meta data
foreach ($meta as $include) {
if (!in_array(($md5 = md5($include)), $meta_memory)) {
$meta_memory[] = $md5;
......@@ -515,29 +526,10 @@ function gallery_set_css($css) {
// Debug output
gallery_debug($css, t('Head [CSS]'));
// Handle css styles and includes
$css = preg_replace('/<link(.*?)href="([^"]*)"(.*?)\/>/i', '${2}', $css);
foreach ($css as $include) {
if (!in_array(($md5 = md5($include)), $css_memory)) {
$css_memory[] = $md5;
if (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 .'" />');
}
else {
$include = preg_replace(array('#^'. $base_url .'#', '#^'. base_path() .'#', '#^/#'), '', $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('<link type="text/css" rel="stylesheet" media="all" href="'. $include .'" />');
}
else {
// Gallery's css must always be added first to allow overriding from the module(s)
drupal_add_css($include, 'module', 'all', FALSE);
}
}
drupal_set_html_head($include);
}
}
}
......@@ -561,24 +553,10 @@ function gallery_set_javascript($javascript) {
$inline = preg_replace('/<script([^>]*)>(.*?)<\/script>/is', '\2', $inline);
drupal_add_js(implode("\n", $inline), 'inline');
// Javascript files
$files = preg_replace('/<script(.*?)src="([^"]*)"([^>]*)>(.*?)<\/script>/i', '${2}', $files);
foreach ($files as $include) {
if (!in_array(($md5 = md5($include)), $js_memory)) {
$js_memory[] = $md5;
if (variable_get('gallery_outside', 0)) {
// drupal_add_js() does not support external paths
drupal_set_html_head('<script type="text/javascript" src="'. $include .'"></script>');
}
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, $type = 'module', $scope = 'header', $defer = FALSE, $cache = FALSE, $preprocess = FALSE);
}
}
drupal_set_html_head($include);
}
}
}
......@@ -592,14 +570,14 @@ function gallery_context(&$params, $setcontext = FALSE) {
static $context_cache = NULL;
if ($setcontext) {
// store new context
// 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
// Get context parameters
if (isset($params)) {
// return requested context parameters
// Return requested context parameters
$params = is_array($params) ? $params : array($params);
foreach($params as $param) {
if (!isset($context_cache[$param])) {
......@@ -610,7 +588,7 @@ function gallery_context(&$params, $setcontext = FALSE) {
$params = $context;
}
else {
// return all stored context parameters
// Return all stored context parameters
$params = $context_cache;
}
......@@ -755,11 +733,11 @@ function _gallery_report_error($report = array()) {
/**
* Function gallery_debug().
*/
function gallery_debug($output, $label = '', $html = FALSE) {
function gallery_debug($output, $label = NULL, $html = FALSE) {
if (variable_get('gallery_debug', 0) && user_access('administer site configuration')) {
// Output debug log into a collapsible fieldset
$fieldset = array(
'#title' => t('Gallery Debug: '). check_plain($label),
'#title' => t('Gallery Debug') . (isset($label) ? (': '. check_plain($label)) : ''),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
'#value' => '<pre>'. ($html ? $output : htmlspecialchars(print_r($output, TRUE))) .'</pre>',
......
......@@ -237,15 +237,15 @@ function _gallery_block_split_imageblock($html) {
$images = array();
$image_html = '';
$ndx = $open_divs = 0;
$found_image_block_class = false;
$found_image_block_class = FALSE;
$imageblock_class = '<div class="block-imageblock-ImageBlock';
// Iterate through this array and combine again, but on a per-image basis
foreach ($html_array as $value) {
$value = trim($value);
if (!strcmp($value, '<div class="block-imageblock-ImageBlock">')) {
// Found the opening <div> for the image block (G2.3).
// We want to remove this.
$found_image_block_class = true;
if (!strncmp($value, $imageblock_class, strlen($imageblock_class))) {
// Found the opening <div> for the image block (G2.3). We want to remove this.
$found_image_block_class = TRUE;
} else {
$image_html .= $value;
}
......@@ -269,8 +269,7 @@ function _gallery_block_split_imageblock($html) {
}
}
}
// If using G2.3 there is a final <div> from <div class="block-imageblock-ImageBlock">
// that must be removed.
// If using G2.3 there is a final <div> from imageblock that must be removed.
if ($found_image_block_class) {
unset($images[count($images)-1]);
}
......@@ -292,21 +291,20 @@ function template_preprocess_gallery_block_image_block(&$variables) {
*/
function template_preprocess_gallery_block_grid_block(&$variables) {
$images = _gallery_block_split_imageblock($variables['content']);
// Filter the images
// Filter the images (and split columns)
array_walk($images, 'filter_xss_admin');
$images = array_chunk($images, $variables['num_cols']);
// Leave the whole content in in case themes want to do more formatting,
// but filter it for security.
// Leave the whole content in in case themes want to do more formatting
$variables['content'] = filter_xss_admin($variables['content']);
$variables['images'] = array();
$row = 0;
foreach ($images as $image_row) {
$variables['images'][] = array(
'data' => $image_row,
'zebra' => $row % 2 == 0 ? 'odd' : 'even',
);
$row++;
$variables['images'][] = array(
'data' => $image_row,
'zebra' => ($row % 2 == 0) ? 'odd' : 'even'
);
$row++;
}
$variables['class'] = check_plain($variables['class']);
$variables['num_cols'] = check_plain($variables['num_cols']);
}
\ No newline at end of file
}
......@@ -3,7 +3,7 @@
/**
* gallery.module : gallery_help.inc
* Help info
* Help and documentation
*/
/**
......@@ -140,3 +140,23 @@ function _gallery_report_help() {
return t('<p><strong>A serious error has occured. This can happen due to an incorrect configuration or a bug in the gallery module. If you plan to submit a bug report to the issue queue at <a href="@gallery-issues">drupal.org</a> consider to include the <a href="@report">pre-generated report file</a>.</strong></p>',
array('@gallery-issues' => 'http://drupal.org/project/issues/gallery', '@report' => url('admin/settings/gallery/report/download')));
}
/**
* Function _gallery_advanced_help_get_form_help().
*/
function _gallery_advanced_help_get_form_help($form_id, $module = 'gallery') {
static $form_help = NULL;
if (!isset($form_help)) {
$module_path = drupal_get_path('module', $module);
if (file_exists("$module_path/help/$module.forms_help.ini")) {
$info = parse_ini_file("./$module_path/help/$module.forms_help.ini", TRUE);
foreach ($info["$module-forms"] as $form => $topic) {
$form = explode('@', $form);
$form_help[$form[1]][$form[0]] = $topic;
}
}
}
return isset($form_help[$form_id]) ? $form_help[$form_id] : array();
}
......@@ -42,7 +42,7 @@ function _gallery_report($download = FALSE, $report = array(), $cache = FALSE) {
$modules = drupal_system_listing('\.module$', 'modules', 'name', 0);
system_get_files_database($modules, 'module');
foreach ($modules as $name => $module) {
if (in_array($name, array('gallery', 'gallery_menu', 'gallery_content'))) {
if (preg_match('/^gallery[]$|^gallery_/', $name)) {
$info = drupal_parse_info_file(dirname($module->filename) .'/'. $module->name .'.info');
$report['Module']['Version'][$info['name']] = array(
'Version' => isset($info['version']) ? $info['version'] : 'unknown',
......
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