* (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)) {
* 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) {
$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;
}
}
/**
+ * 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;
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
);
}
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();
}
}
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) {
}
$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';