Mixin_Gallery_Mapper

The NextGEN Gallery 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  
  1. class Mixin_Gallery_Mapper extends Mixin 
  2. /** 
  3. * Uses the title property as the post title when the Custom Post driver 
  4. * is used 
  5. */ 
  6. function get_post_title($entity) 
  7. return $entity->title; 
  8. function _save_entity($entity) 
  9. // A bug in NGG 2.1.24 allowed galleries to be created with spaces in the directory name, unreplaced by dashes 
  10. // This causes a few problems everywhere, so we here allow users a way to fix those galleries by just re-saving 
  11. if (FALSE !== strpos($entity->path, ' ')) { 
  12. $storage = C_Gallery_Storage::get_instance(); 
  13. $abspath = $storage->get_gallery_abspath($entity->{$entity->id_field}); 
  14. $pre_path = $entity->path; 
  15. $entity->path = str_replace(' ', '-', $entity->path); 
  16. $new_abspath = str_replace($pre_path, $entity->path, $abspath); 
  17. // Begin adding -1, -2, etc until we have a safe target: rename() will overwrite existing directories 
  18. if (@file_exists($new_abspath)) { 
  19. $max_count = 100; 
  20. $count = 0; 
  21. $corrected_abspath = $new_abspath; 
  22. while (@file_exists($corrected_abspath) && $count <= $max_count) { 
  23. $count++; 
  24. $corrected_abspath = $new_abspath . '-' . $count; 
  25. $new_abspath = $corrected_abspath; 
  26. $entity->path = $entity->path . '-' . $count; 
  27. @rename($abspath, $new_abspath); 
  28. $slug = $entity->slug; 
  29. $entity->slug = str_replace(' ', '-', $entity->slug); 
  30. // Note: we do the following to mimic the behaviour of esc_url so that slugs are always valid in URLs after escaping 
  31. $entity->slug = preg_replace('|[^a-z0-9 \\-~+_.#=!&;, /:%@$\\|*\'()\\x80-\\xff]|i', '', $entity->slug); 
  32. if ($slug != $entity->slug) { 
  33. // creating new slug for the gallery 
  34. $entity->slug = nggdb::get_unique_slug($entity->slug, 'gallery'); 
  35. $retval = $this->call_parent('_save_entity', $entity); 
  36. if ($retval) { 
  37. do_action('ngg_created_new_gallery', $entity->{$entity->id_field}); 
  38. C_Photocrati_Transient_Manager::flush('displayed_gallery_rendering'); 
  39. return $retval; 
  40. function destroy($gallery, $with_dependencies = FALSE) 
  41. $retval = FALSE; 
  42. if ($gallery) { 
  43. $gallery_id = is_numeric($gallery) ? $gallery : $gallery->{$gallery->id_field}; 
  44. // TODO: Look into making this operation more efficient 
  45. if ($with_dependencies) { 
  46. $image_mapper = C_Image_Mapper::get_instance(); 
  47. // Delete the image files from the filesystem 
  48. $settings = C_NextGen_Settings::get_instance(); 
  49. if ($settings->deleteImg) { 
  50. $storage = C_Gallery_Storage::get_instance(); 
  51. $storage->delete_gallery($gallery); 
  52. // Delete the image records from the DB 
  53. $image_mapper->delete()->where(array("galleryid = %d", $gallery_id))->run_query(); 
  54. $image_key = $image_mapper->get_primary_key_column(); 
  55. $image_table = $image_mapper->get_table_name(); 
  56. // Delete tag associations no longer needed. The following SQL statement 
  57. // deletes all tag associates for images that no longer exist 
  58. global $wpdb; 
  59. $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})"); 
  60. $retval = $this->call_parent('destroy', $gallery); 
  61. if ($retval) { 
  62. do_action('ngg_delete_gallery', $gallery); 
  63. C_Photocrati_Transient_Manager::flush('displayed_gallery_rendering'); 
  64. return $retval; 
  65. function set_preview_image($gallery, $image, $only_if_empty = FALSE) 
  66. $retval = FALSE; 
  67. // We need the gallery object 
  68. if (is_numeric($gallery)) { 
  69. $gallery = $this->object->find($gallery); 
  70. // We need the image id 
  71. if (!is_numeric($image)) { 
  72. if (method_exists($image, 'id')) { 
  73. $image = $image->id(); 
  74. } else { 
  75. $image = $image->{$image->id_field}; 
  76. if ($gallery && $image) { 
  77. if ($only_if_empty && !$gallery->previewpic or !$only_if_empty) { 
  78. $gallery->previewpic = $image; 
  79. $retval = $this->object->save($gallery); 
  80. return $retval; 
  81. /** 
  82. * Sets default values for the gallery 
  83. */ 
  84. function set_defaults($entity) 
  85. // If author is missing, then set to the current user id 
  86. // TODO: Using wordpress function. Should use abstraction 
  87. $this->object->_set_default_value($entity, 'author', get_current_user_id());