Mixin_Gallery_Image_Mapper

Sets the alttext property as the post title.

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_Image_Mapper extends Mixin 
  2. function destroy($image) 
  3. $retval = $this->call_parent('destroy', $image); 
  4. // Delete tag associations with the image 
  5. if (!is_numeric($image)) { 
  6. $image = $image->{$image->id_field}; 
  7. wp_delete_object_term_relationships($image, 'ngg_tag'); 
  8. C_Photocrati_Transient_Manager::flush('displayed_gallery_rendering'); 
  9. return $retval; 
  10. function _save_entity($entity) 
  11. $entity->updated_at = time(); 
  12. // If successfully saved, then import metadata and 
  13. $retval = $this->call_parent('_save_entity', $entity); 
  14. if ($retval) { 
  15. include_once NGGALLERY_ABSPATH . '/admin/functions.php'; 
  16. $image_id = $this->get_id($entity); 
  17. if (!isset($entity->meta_data['saved'])) { 
  18. nggAdmin::import_MetaData($image_id); 
  19. C_Photocrati_Transient_Manager::flush('displayed_gallery_rendering'); 
  20. return $retval; 
  21. function reimport_metadata($image_or_id) 
  22. // Get the image 
  23. $image = NULL; 
  24. if (is_int($image_or_id)) { 
  25. $image = $this->object->find($image_or_id); 
  26. } else { 
  27. $image = $image_or_id; 
  28. // Reset all image details that would have normally been imported 
  29. $image->alttext = ''; 
  30. $image->description = ''; 
  31. if (is_array($image->meta_data)) { 
  32. unset($image->meta_data['saved']); 
  33. wp_delete_object_term_relationships($image->{$image->id_field}, 'ngg_tag'); 
  34. nggAdmin::import_MetaData($image); 
  35. return $this->object->save($image); 
  36. /** 
  37. * Retrieves the id from an image 
  38. * @param $image 
  39. * @return bool 
  40. */ 
  41. function get_id($image) 
  42. $retval = FALSE; 
  43. // Have we been passed an entity and is the id_field set? 
  44. if ($image instanceof stdClass) { 
  45. if (isset($image->id_field)) { 
  46. $retval = $image->{$image->id_field}; 
  47. } else { 
  48. $retval = $image->id(); 
  49. // If we still don't have an id, then we'll lookup the primary key 
  50. // and try fetching it manually 
  51. if (!$retval) { 
  52. $key = $this->object->get_primary_key_column(); 
  53. $retval = $image->{$key}; 
  54. return $retval; 
  55. function get_post_title($entity) 
  56. return $entity->alttext; 
  57. function set_defaults($entity) 
  58. // If not set already, we'll add an exclude property. This is used 
  59. // by NextGEN Gallery itself, as well as the Attach to Post module 
  60. $this->object->_set_default_value($entity, 'exclude', 0); 
  61. // Ensure that the object has a description attribute 
  62. $this->object->_set_default_value($entity, 'description', ''); 
  63. // If not set already, set a default sortorder 
  64. $this->object->_set_default_value($entity, 'sortorder', 0); 
  65. // The imagedate must be set 
  66. if (!isset($entity->imagedate) or is_null($entity->imagedate) or $entity->imagedate == '0000-00-00 00:00:00') { 
  67. $entity->imagedate = date("Y-m-d H:i:s"); 
  68. // If a filename is set, and no alttext is set, then set the alttext 
  69. // to the basename of the filename (legacy behavior) 
  70. if (isset($entity->filename)) { 
  71. $path_parts = M_I18n::mb_pathinfo($entity->filename); 
  72. $alttext = !isset($path_parts['filename']) ? substr($path_parts['basename'], 0, strpos($path_parts['basename'], '.')) : $path_parts['filename']; 
  73. $this->object->_set_default_value($entity, 'alttext', $alttext); 
  74. // Set unique slug 
  75. if (isset($entity->alttext) && empty($entity->image_slug)) { 
  76. $entity->image_slug = nggdb::get_unique_slug(sanitize_title_with_dashes($entity->alttext), 'image'); 
  77. // Ensure that the exclude parameter is an integer or boolean-evaluated 
  78. // value 
  79. if (is_string($entity->exclude)) { 
  80. $entity->exclude = intval($entity->exclude); 
  81. // Trim alttext and description 
  82. $entity->description = trim($entity->description); 
  83. $entity->alttext = trim($entity->alttext); 
  84. /** 
  85. * Finds all images for a gallery 
  86. * @param $gallery 
  87. * @param bool $model 
  88. * @return array 
  89. */ 
  90. function find_all_for_gallery($gallery, $model = FALSE) 
  91. $retval = array(); 
  92. $gallery_id = 0; 
  93. if (is_object($gallery)) { 
  94. if (isset($gallery->id_field)) { 
  95. $gallery_id = $gallery->{$gallery->id_field}; 
  96. } else { 
  97. $key = $this->object->get_primary_key_column(); 
  98. if (isset($gallery->{$key})) { 
  99. $gallery_id = $gallery->{$key}; 
  100. } elseif (is_numeric($gallery)) { 
  101. $gallery_id = $gallery; 
  102. if ($gallery_id) { 
  103. $retval = $this->object->select()->where(array("galleryid = %s", $gallery_id))->run_query(FALSE, $model); 
  104. return $retval;