Commit 1a2bb090 authored by profix898's avatar profix898

- task: port back some changes from D6 version

- task: refactor #179567 and #179555
parent c3b424c8
......@@ -389,7 +389,7 @@ function gallery_page($internal = FALSE) {
// Some themes (eg hybrid) do not set $result['themeData']['parents']
if ($result['themeData']['parents']) {
foreach ($result['themeData']['parents'] as $parent) {
$parent_title = $parent['title'];
$parent_title = _gallery_htmlcharsdecode($parent['title']);
// Simple strip of bbcode (italic, bold)
$parent_title = str_replace(
array('[i]', '[/i]', '[b]', '[/b]'),
......
......@@ -178,7 +178,9 @@ function gallery_get_language($user) {
* (retrieve all image frames from Gallery2)
*/
function gallery_get_image_frames() {
_gallery_init();
if (!_gallery_init()) {
return array('none' => t('None'));
}
// List of available image frames
list($ret, $imageframe) = GalleryCoreApi::newFactoryInstance('ImageFrameInterface_1_1');
if ($ret || !isset($imageframe)) {
......@@ -196,19 +198,41 @@ function gallery_get_image_frames() {
* Function gallery_generate_url().
*/
function gallery_generate_url($params, $html = TRUE, $full = TRUE) {
if (!isset($GLOBALS['gallery'])) {
if (!_gallery_init()) {
return '';
}
}
$options = array();
$options['forceFullUrl'] = $full;
$options['htmlEntities'] = $html;
$url_generator =& $GLOBALS['gallery']->getUrlGenerator();
if (!$url_generator) {
gallery_error(t('Error: UrlGenerator not available'));
return '';
}
return $url_generator->generateUrl($params, $options);
}
/**
* Function gallery_album_tree().
*/
function gallery_album_tree($root = NULL, $depth = NULL, $user = NULL) {
if (!_gallery_init()) {
return array();
}
list($ret, $tree) = GalleryCoreApi::fetchAlbumTree($root, $depth, $user);
if ($ret) {
gallery_error(t('Error fetching album tree'), $ret);
return array();
}
return $tree;
}
/**
* Function gallery_item_details().
*/
......@@ -226,12 +250,12 @@ function gallery_item_details($id, $verbose = FALSE) {
$details['g2owner'] = $entity->ownerId;
$details['g2parent'] = $entity->parentId;
// Drupal node properties (no g2 prefix)
$details['title'] = strtr($entity->title, array_flip(get_html_translation_table(HTML_SPECIALCHARS)));
$details['title'] = _gallery_htmlcharsdecode($entity->title);
$details['created'] = $entity->creationTimestamp;
if ($verbose) {
$details['g2description'] = $entity->description;
$details['g2summary'] = $entity->summary;
$details['g2description'] = _gallery_htmlcharsdecode($entity->description);
$details['g2summary'] = _gallery_htmlcharsdecode($entity->summary);
$details['g2keywords'] = $entity->keywords;
$details['g2theme'] = $entity->theme;
}
......@@ -239,14 +263,40 @@ function gallery_item_details($id, $verbose = FALSE) {
return $details;
}
/**
* Function gallery_db_query().
*/
function gallery_db_query($query, $data = NULL) {
if (!isset($GLOBALS['gallery'])) {
if (!_gallery_init()) {
return FALSE;
}
}
list ($ret, $search) = $GLOBALS['gallery']->search($query, $data);
if ($ret) {
return FALSE;
}
$results = array();
while ($result = $search->nextResult()) {
$results += $result;
}
return $results;
}
/**
* Function gallery_flush_entity_cache().
*/
function gallery_flush_entity_cache() {
if (!isset($GLOBALS['gallery'])) {
if (!_gallery_init()) {
return FALSE;
}
}
$platform =& $GLOBALS['gallery']->getPlatform();
$cache_basedir = $GLOBALS['gallery']->getConfig('data.gallery.cache');
$cache_dir = $cache_basedir .'entity';
if ($platform->file_exists($cache_dir)) {
if (!$platform->recursiveRmDir($cache_dir)) {
return FALSE;
......@@ -375,6 +425,14 @@ function _gallery_split_imageblock($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
......
......@@ -23,6 +23,19 @@ function gallery_menu_menu($may_cache) {
);
}
else {
// Initialize G2
if (!_gallery_init(FALSE)) {
return $items;
}
// Rebuild the menu if the G2 album structure changed
$timestamp = variable_get('gallery_menu_timestamp', 0);
$query = 'SELECT COUNT([GalleryEntity::id]) FROM [GalleryEntity], [GalleryAlbumItem] WHERE
[GalleryAlbumItem::id] = [GalleryEntity::id] AND [GalleryEntity::modificationTimeStamp] > ?';
if (($results = gallery_db_query($query, array($timestamp))) && $results[0]) {
cache_clear_all('gallery_menu:', 'cache', TRUE);
variable_set('gallery_menu_timestamp', time());
}
// Insert the menu items
$items = gallery_menu_build_menu();
}
}
......@@ -84,38 +97,21 @@ function gallery_menu_album($id) {
function gallery_menu_build_menu() {
global $user;
$items = array();
if (!_gallery_init(TRUE)) {
return $items;
}
$depth = variable_get('gallery_menu_depth', 0);
$tree = _gallery_menu_album_tree(NULL, $depth ? $depth : NULL);
$cid = 'gallery_menu:'. $user->uid .':'. md5(serialize($tree));
$cid = 'gallery_menu:'. $user->uid;
if ($cache = cache_get($cid)) {
$items = unserialize($cache->data);
}
else {
$depth = variable_get('gallery_menu_depth', 0);
$tree = gallery_album_tree(NULL, $depth ? $depth : NULL);
_gallery_menu_traverse($tree, $items);
cache_set($cid, 'cache', serialize($items), CACHE_TEMPORARY);
}
GalleryEmbed::done();
return $items;
}
/**
* Function _gallery_menu_album_tree().
*/
function _gallery_menu_album_tree($root = NULL, $depth = NULL, $user = NULL) {
list($ret, $tree) = GalleryCoreApi::fetchAlbumTree($root, $depth, $user);
if ($ret) {
gallery_error(t('Error fetching album tree'), $ret);
return FALSE;
}
return $tree;
}
/**
* Function _gallery_menu_traverse().
*/
......@@ -190,7 +186,7 @@ function _gallery_menu_settings_table() {
}
$depth = variable_get('gallery_menu_depth', 0);
$tree = _gallery_menu_album_tree(NULL, $depth ? $depth : NULL);
$tree = gallery_album_tree(NULL, $depth ? $depth : NULL);
$form = _gallery_menu_settings_traverse($tree);
$form['#theme'] = 'gallery_menu_settings_table';
......
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