Mixin_Gallery_Mapper
The WordPress Core Mixin Gallery Mapper class.
Defined (1)
The class is defined in the following location(s).
- /products/photocrati_nextgen/modules/nextgen_data/package.module.nextgen_data.php
- class Mixin_Gallery_Mapper extends Mixin
- {
- /**
- * Uses the title property as the post title when the Custom Post driver
- * is used
- */
- function get_post_title($entity)
- {
- return $entity->title;
- }
- function _save_entity($entity)
- {
- // A bug in NGG 2.1.24 allowed galleries to be created with spaces in the directory name, unreplaced by dashes
- // This causes a few problems everywhere, so we here allow users a way to fix those galleries by just re-saving
- if (FALSE !== strpos($entity->path, ' ')) {
- $storage = C_Gallery_Storage::get_instance();
- $abspath = $storage->get_gallery_abspath($entity->{$entity->id_field});
- $pre_path = $entity->path;
- $entity->path = str_replace(' ', '-', $entity->path);
- $new_abspath = str_replace($pre_path, $entity->path, $abspath);
- // Begin adding -1, -2, etc until we have a safe target: rename() will overwrite existing directories
- if (@file_exists($new_abspath)) {
- $max_count = 100;
- $count = 0;
- $corrected_abspath = $new_abspath;
- while (@file_exists($corrected_abspath) && $count <= $max_count) {
- $count++;
- $corrected_abspath = $new_abspath . '-' . $count;
- }
- $new_abspath = $corrected_abspath;
- $entity->path = $entity->path . '-' . $count;
- }
- @rename($abspath, $new_abspath);
- }
- $slug = $entity->slug;
- $entity->slug = str_replace(' ', '-', $entity->slug);
- // Note: we do the following to mimic the behaviour of esc_url so that slugs are always valid in URLs after escaping
- $entity->slug = preg_replace('|[^a-z0-9 \\-~+_.#=!&;, /:%@$\\|*\'()\\x80-\\xff]|i', '', $entity->slug);
- if ($slug != $entity->slug) {
- // creating new slug for the gallery
- $entity->slug = nggdb::get_unique_slug($entity->slug, 'gallery');
- }
- $retval = $this->call_parent('_save_entity', $entity);
- if ($retval) {
- do_action('ngg_created_new_gallery', $entity->{$entity->id_field});
- C_Photocrati_Transient_Manager::flush('displayed_gallery_rendering');
- }
- return $retval;
- }
- function destroy($gallery, $with_dependencies = FALSE)
- {
- $retval = FALSE;
- if ($gallery) {
- $gallery_id = is_numeric($gallery) ? $gallery : $gallery->{$gallery->id_field};
- // TODO: Look into making this operation more efficient
- if ($with_dependencies) {
- $image_mapper = C_Image_Mapper::get_instance();
- // Delete the image files from the filesystem
- $settings = C_NextGen_Settings::get_instance();
- if ($settings->deleteImg) {
- $storage = C_Gallery_Storage::get_instance();
- $storage->delete_gallery($gallery);
- }
- // Delete the image records from the DB
- $image_mapper->delete()->where(array("galleryid = %d", $gallery_id))->run_query();
- $image_key = $image_mapper->get_primary_key_column();
- $image_table = $image_mapper->get_table_name();
- // Delete tag associations no longer needed. The following SQL statement
- // deletes all tag associates for images that no longer exist
- global $wpdb;
- $wpdb->query("\n\t\t\t\t\tDELETE wptr.* FROM {$wpdb->term_relationships} wptr\n\t\t\t\t\tINNER JOIN {$wpdb->term_taxonomy} wptt\n\t\t\t\t\tON wptt.term_taxonomy_id = wptr.term_taxonomy_id\n\t\t\t\t\tWHERE wptt.term_taxonomy_id = wptr.term_taxonomy_id\n\t\t\t\t\tAND wptt.taxonomy = 'ngg_tag'\n\t\t\t\t\tAND wptr.object_id NOT IN (SELECT {$image_key} FROM {$image_table})");
- }
- $retval = $this->call_parent('destroy', $gallery);
- if ($retval) {
- do_action('ngg_delete_gallery', $gallery);
- C_Photocrati_Transient_Manager::flush('displayed_gallery_rendering');
- }
- }
- return $retval;
- }
- function set_preview_image($gallery, $image, $only_if_empty = FALSE)
- {
- $retval = FALSE;
- // We need the gallery object
- if (is_numeric($gallery)) {
- $gallery = $this->object->find($gallery);
- }
- // We need the image id
- if (!is_numeric($image)) {
- if (method_exists($image, 'id')) {
- $image = $image->id();
- } else {
- $image = $image->{$image->id_field};
- }
- }
- if ($gallery && $image) {
- if ($only_if_empty && !$gallery->previewpic or !$only_if_empty) {
- $gallery->previewpic = $image;
- $retval = $this->object->save($gallery);
- }
- }
- return $retval;
- }
- /**
- * Sets default values for the gallery
- */
- function set_defaults($entity)
- {
- // If author is missing, then set to the current user id
- // TODO: Using wordpress function. Should use abstraction
- $this->object->_set_default_value($entity, 'author', get_current_user_id());
- }
- }