FALSE, 'full' => FALSE);
// Initialize only once
if ($ready[$full ? 'full' : 'half']) {
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 = '';
}
$init_err_msg = t('Unable to initialize embedded Gallery. You need to configure your embedded Gallery.',
array('@link' => url('admin/settings/gallery/install')));
if ((!$gallery_valid) || (!is_readable($embed_path))) {
if ($report_error) {
gallery_error($init_err_msg);
}
return FALSE;
}
include_once($embed_path);
$params = array('embedUri' => $embed_uri,
'g2Uri' => $g2_uri,
'loginRedirect' => url('user/login', drupal_get_destination(), NULL, TRUE),
'activeUserId' => $uid,
'activeLanguage' => gallery_get_language($user),
'fullInit' => $full,
'apiVersion' => array(1, 2));
$ret = GalleryEmbed::init($params);
if ($ret) {
if ($ret->getErrorCode() & ERROR_PLUGIN_VERSION_MISMATCH) {
if ($report_error) {
gallery_error($vars ? t('Embedding API version is incompatible.') : $init_err_msg, $ret, TRUE);
}
return FALSE;
}
else {
if ($report_error) {
gallery_error($init_err_msg, $ret, TRUE);
}
return FALSE;
}
}
if (!class_exists('GalleryEmbed') || !class_exists('GalleryCoreApi')) {
if ($report_error) {
gallery_error(t('Classes \'GalleryEmbed\' and/or \'GalleryCoreApi\' are not available,
although initialization seemed successful.'));
}
return FALSE;
}
$ready['half'] = $full ? ($ready['full'] = TRUE) : TRUE;
return TRUE;
}
/**
* Function gallery_handle_request().
* (handleRequest extension with error handling)
*/
function gallery_handle_request() {
ob_start();
$result = GalleryEmbed::handleRequest();
$output = ob_get_contents();
ob_end_clean();
if ($output) {
if (!preg_match('%
')) {
// Found the opening
for the image
$open_divs = 0;
}
elseif (!strncmp($value, '
but not the main image one (eg a frame)
$open_divs++;
}
elseif (!strcmp($value, '
')) {
// Found a
but check if it's for the main image or a subcomponent (eg frame)
if ($open_divs > 0) {
$open_divs--;
}
else {
// This must be the closing div for "one-image" so move to next image
$images[] = $image_html;
$image_html = '';
}
}
}
return $images;
}
/**
* Function _gallery_htmlcharsdecode().
* (recover special character's HTML entities, see htmlspecialchars_decode() for php5)
*/
function _gallery_htmlcharsdecode($string) {
return strtr($string, array_flip(get_html_translation_table(HTML_SPECIALCHARS)));
}
/*
* --------------------------------------------------------------------------
* Error, Debug and Status Functions
* --------------------------------------------------------------------------
*/
/**
* Function gallery_error().
*/
function gallery_error($msg, $ret = NULL, $serious = FALSE) {
$error_mode = variable_get('gallery_error_mode', array(GALLERY_ERROR_WATCHDOG));
$admin = user_access('administer site configuration');
$report = $admin && variable_get('gallery_report', 1);
// Verbose error messages
$debug_info = array();
if (in_array(GALLERY_ERROR_VERBOSE, $error_mode) || variable_get('gallery_debug', 0) || $admin) {
$msg = $ret ? (is_object($ret) ? ($msg .'
'. $ret->getAsHtml()) : $ret) : $msg;
if (GALLERY_DEBUGTRACE && function_exists('debug_backtrace')) {
$trace = debug_backtrace();
$source = t('Error in function \':func()\' (:file::line):
',
array(':func' => $trace[1]['function'], ':file' => basename($trace[0]['file']), ':line' => $trace[0]['line']));
$message = $source .'
';
$debug_info = array('Debug Trace' => $trace);
}
}
$message = !empty($message) ? $message : $msg;
// Debug output (skip watchdog)
if (variable_get('gallery_debug', 0) && $admin) {
if ($report) {
_gallery_report_error($debug_info);
}
drupal_set_message($message, 'error');
return;
}
// Error output to browser
if (in_array(GALLERY_ERROR_BROWSER, $error_mode)) {
if ($report) {
_gallery_report_error($debug_info);
}
drupal_set_message($message, 'error');
}
elseif ($serious) {
if ($report) {
_gallery_report_error($debug_info);
}
drupal_set_message($admin ? $message : t('Embedded Gallery2 is not available or requested Gallery URL does not exist.'), 'error');
}
// Error output to watchdog
if (in_array(GALLERY_ERROR_WATCHDOG, $error_mode)) {
watchdog('gallery', $message, WATCHDOG_ERROR);
}
}
/**
* Function _gallery_report_error().
*/
function _gallery_report_error($report = array()) {
require_once(drupal_get_path('module', 'gallery') .'/gallery_help.inc');
require_once(drupal_get_path('module', 'gallery') .'/gallery_report.inc');
drupal_set_message(_gallery_report_help(), 'error');
_gallery_report(FALSE, $report, TRUE);
}
/**
* Function gallery_debug().
*/
function gallery_debug($array, $label = 'Gallery Debug') {
if (variable_get('gallery_debug', 0) && user_access('administer site configuration')) {
drupal_set_message('
'. $label .':'. nl2br(htmlspecialchars(print_r($array, TRUE))), 'error');
}
}
/**
* Function gallery_plugin_status().
*/
function gallery_plugin_status($plugin_names) {
static $all_plugins_status = array();
$plugins_status = array();
if (!_gallery_init(FALSE)) {
gallery_error(t('Unable to initialize Gallery2.'), $ret);
foreach ($plugin_names as $plugin) {
$plugins_status[$plugin] = GALLERY_PLUGIN_STATUS_UNKNOWN;
}
return $plugins_status;
}
// Fetch status of G2 modules
if (empty($plugins_status_cache)) {
list($ret, $plugins_status_cache) = GalleryCoreApi::fetchPluginStatus('module');
if ($ret) {
gallery_error(t('Unable to get Gallery2 module status.'), $ret);
foreach ($plugin_names as $plugin) {
$plugins_status[$plugin] = GALLERY_PLUGIN_STATUS_UNKNOWN;
}
return $plugins_status;
}
}
// Generate array containing module status
foreach ($plugin_names as $plugin) {
if (isset($plugins_status_cache[$plugin])) {
if ($plugins_status_cache[$plugin]['active'] && $plugins_status_cache[$plugin]['available']) {
$plugins_status[$plugin] = GALLERY_PLUGIN_ENABLED;
}
elseif (!isset($plugins_status_cache[$plugin]['active']) && $plugins_status_cache[$plugin]['available']) {
$plugins_status[$plugin] = GALLERY_PLUGIN_NOT_INSTALLED;
}
elseif (($plugins_status_cache[$plugin]['active'] == 0) && $plugins_status_cache[$plugin]['available']) {
$plugins_status[$plugin] = GALLERY_PLUGIN_NOT_ACTIVE;
}
else {
$plugins_status[$plugin] = GALLERY_PLUGIN_DISABLED;
}
}
else {
$plugins_status[$plugin] = GALLERY_PLUGIN_MISSING;
}
}
return $plugins_status;
}
/**
* Function gallery_single_plugin_status().
*/
function gallery_single_plugin_status($plugin_name) {
$status = gallery_plugin_status(array($plugin_name));
return $status[$plugin_name];
}
/**
* Function gallery_set_status().
*/
function gallery_set_status($status = array(), $reset = FALSE) {
$status_array = $status;
if (!$reset) {
$status_array = unserialize(variable_get('gallery_status', serialize(array())));
foreach ($status as $key => $value) {
if (!empty($value)) {
$status_array[$key] = $value;
}
elseif (isset($status_array[$key])) {
unset($status_array[$key]);
}
}
}
variable_set('gallery_status', serialize($status_array));
}
/**
* Function gallery_get_status().
*/
function gallery_get_status() {
return unserialize(variable_get('gallery_status', serialize(array())));
}
/**
* Function gallery_version().
*/
function gallery_version() {
if (!_gallery_init(FALSE)) {
return array();
}
list($core_major, $core_minor) = GalleryCoreApi::getApiVersion();
list($embed_major, $embed_minor) = GalleryEmbed::getApiVersion();
$version = array(
'core' => array('major' => $core_major, 'minor' => $core_minor),
'embed' => array('major' => $embed_major, 'minor' => $embed_minor)
);
// Update version in status messages
$status = array('version' => array(
'title' => t('Gallery2 API version'),
'info' => "$core_major.$core_minor / $embed_major.$embed_minor")
);
gallery_set_status($status);
return $version;
}