summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--gallery.module2
-rw-r--r--gallery_base.inc72
-rw-r--r--gallery_menu/gallery_menu.module38
3 files changed, 83 insertions, 29 deletions
diff --git a/gallery.module b/gallery.module
index 2aa2efb..ca66a29 100644
--- a/gallery.module
+++ b/gallery.module
@@ -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]'),
diff --git a/gallery_base.inc b/gallery_base.inc
index 9155b8a..3e895aa 100644
--- a/gallery_base.inc
+++ b/gallery_base.inc
@@ -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,20 +198,42 @@ 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().
*/
function gallery_item_details($id, $verbose = FALSE) {
@@ -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;
}
@@ -240,13 +264,39 @@ function gallery_item_details($id, $verbose = FALSE) {
}
/**
+ * 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
diff --git a/gallery_menu/gallery_menu.module b/gallery_menu/gallery_menu.module
index ab78c6a..0b18b93 100644
--- a/gallery_menu/gallery_menu.module
+++ b/gallery_menu/gallery_menu.module
@@ -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,39 +97,22 @@ 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().
*/
function _gallery_menu_traverse(&$tree, &$items) {
@@ -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';