A_Image_Options_Form

Class A_Image_Options_Form.

Defined (1)

The class is defined in the following location(s).

/products/photocrati_nextgen/modules/nextgen_other_options/package.module.nextgen_other_options.php  
  1. class A_Image_Options_Form extends Mixin 
  2. function get_model() 
  3. return C_Settings_Model::get_instance(); 
  4. function get_title() 
  5. return __('Image Options', 'nggallery'); 
  6. /** 
  7. * Returns the options available for sorting images 
  8. * @return array 
  9. */ 
  10. function _get_image_sorting_options() 
  11. return array(__('Custom', 'nggallery') => 'sortorder', __('Image ID', 'nggallery') => 'pid', __('Filename', 'nggallery') => 'filename', __('Alt/Title Text', 'nggallery') => 'alttext', __('Date/Time', 'nggallery') => 'imagedate'); 
  12. /** 
  13. * Returns the options available for sorting directions 
  14. * @return array 
  15. */ 
  16. function _get_sorting_direction_options() 
  17. return array(__('Ascending', 'nggallery') => 'ASC', __('Descending', 'nggallery') => 'DESC'); 
  18. /** 
  19. * Returns the options available for matching related images 
  20. */ 
  21. function _get_related_image_match_options() 
  22. return array(__('Categories', 'nggallery') => 'category', __('Tags', 'nggallery') => 'tags'); 
  23. /** 
  24. * Tries to create the gallery storage directory if it doesn't exist 
  25. * already 
  26. * @return string 
  27. */ 
  28. function _create_gallery_storage_dir($gallerypath = NULL) 
  29. $retval = TRUE; 
  30. if (!$gallerypath) { 
  31. $gallerypath = $this->object->get_model()->get('gallerypath'); 
  32. $fs = C_Fs::get_instance(); 
  33. $gallerypath = $fs->join_paths($fs->get_document_root('galleries'), $gallerypath); 
  34. if (!@file_exists($gallerypath)) { 
  35. @mkdir($gallerypath); 
  36. $retval = @file_exists($gallerypath); 
  37. return $retval; 
  38. /** 
  39. * Renders the form 
  40. */ 
  41. function render() 
  42. if (!$this->object->_create_gallery_storage_dir()) { 
  43. $this->object->get_model()->add_error(__('Gallery path does not exist and could not be created', 'nggallery'), 'gallerypath'); 
  44. $settings = $this->object->get_model(); 
  45. return $this->render_partial('photocrati-nextgen_other_options#image_options_tab', array('gallery_path_label' => __('Where would you like galleries stored?', 'nggallery'), 'gallery_path_help' => __('Where galleries and their images are stored', 'nggallery'), 'gallery_path' => $settings->gallerypath, 'delete_image_files_label' => __('Delete Image Files?', 'nggallery'), 'delete_image_files_help' => __('When enabled, image files will be removed after a Gallery has been deleted', 'nggallery'), 'delete_image_files' => $settings->deleteImg, 'show_related_images_label' => __('Show Related Images on Posts?', 'nggallery'), 'show_related_images_help' => __('When enabled, related images will be appended to each post by matching the posts tags/categories to image tags', 'nggallery'), 'show_related_images' => $settings->activateTags, 'related_images_hidden_label' => __('(Show Customization Settings)', 'nggallery'), 'related_images_active_label' => __('(Hide Customization Settings)', 'nggallery'), 'match_related_images_label' => __('How should related images be match?', 'nggallery'), 'match_related_images' => $settings->appendType, 'match_related_image_options' => $this->object->_get_related_image_match_options(), 'max_related_images_label' => __('Maximum # of related images to display', 'nggallery'), 'max_related_images' => $settings->maxImages, 'related_images_heading_label' => __('Heading for related images', 'nggallery'), 'related_images_heading' => $settings->relatedHeading, 'sorting_order_label' => __("What's the default sorting method?", 'nggallery'), 'sorting_order_options' => $this->object->_get_image_sorting_options(), 'sorting_order' => $settings->galSort, 'sorting_direction_label' => __('Sort in what direction?', 'nggallery'), 'sorting_direction_options' => $this->object->_get_sorting_direction_options(), 'sorting_direction' => $settings->galSortDir, 'automatic_resize_label' => __('Automatically resize images after upload', 'nggallery'), 'automatic_resize_help' => __('It is recommended that your images be resized to be web friendly', 'nggallery'), 'automatic_resize' => $settings->imgAutoResize, 'resize_images_label' => __('What should images be resized to?', 'nggallery'), 'resize_images_help' => __('After images are uploaded, they will be resized to the above dimensions and quality', 'nggallery'), 'resized_image_width_label' => __('Width:', 'nggallery'), 'resized_image_height_label' => __('Height:', 'nggallery'), 'resized_image_quality_label' => __('Quality:', 'nggallery'), 'resized_image_width' => $settings->imgWidth, 'resized_image_height' => $settings->imgHeight, 'resized_image_quality' => $settings->imgQuality, 'backup_images_label' => __('Backup the original images?', 'nggallery'), 'backup_images_yes_label' => __('Yes'), 'backup_images_no_label' => __('No'), 'backup_images' => $settings->imgBackup), TRUE); 
  46. function save_action($image_options) 
  47. $save = TRUE; 
  48. if ($image_options) { 
  49. // Update the gallery path. Moves all images to the new location 
  50. if (isset($image_options['gallerypath']) && (!is_multisite() || get_current_blog_id() == 1)) { 
  51. $fs = C_Fs::get_instance(); 
  52. $original_dir = $fs->get_abspath($this->object->get_model()->get('gallerypath')); 
  53. $new_dir = $fs->get_abspath($image_options['gallerypath']); 
  54. $image_options['gallerypath'] = $fs->add_trailing_slash($image_options['gallerypath']); 
  55. // Note: the below file move is disabled because it's quite unreliable as it doesn't perform any checks 
  56. // For instance changing gallery path from /wp-content to /wp-content/gallery would attempt a recursive copy and then delete ALL files under wp-content, which would be disastreus 
  57. # // If the gallery path has changed... 
  58. # if ($original_dir != $new_dir) { 
  59. # // Try creating the new directory 
  60. # if ($this->object->_create_gallery_storage_dir($new_dir) AND is_writable($new_dir)) { 
  61. # // Try moving files 
  62. # $this->object->recursive_copy($original_dir, $new_dir); 
  63. # $this->object->recursive_delete($original_dir); 
  64. # // Update gallery paths 
  65. # $mapper = $this->get_registry()->get_utility('I_Gallery_Mapper'); 
  66. # foreach ($mapper->find_all() as $gallery) { 
  67. # $gallery->path = $image_options['gallerypath'] . $gallery->name; 
  68. # $mapper->save($gallery); 
  69. # } 
  70. # } 
  71. # else { 
  72. # $this->get_model()->add_error("Unable to change gallery path. Insufficient filesystem permissions"); 
  73. # $save = FALSE; 
  74. # } 
  75. # } 
  76. } elseif (isset($image_options['gallerypath'])) { 
  77. unset($image_options['gallerypath']); 
  78. // Update image options 
  79. if ($save) { 
  80. $this->object->get_model()->set($image_options)->save(); 
  81. /** 
  82. * Copies one directory to another 
  83. * @param string $src 
  84. * @param string $dst 
  85. * @return boolean 
  86. */ 
  87. function recursive_copy($src, $dst) 
  88. $retval = TRUE; 
  89. $dir = opendir($src); 
  90. @mkdir($dst); 
  91. while (false !== ($file = readdir($dir))) { 
  92. if ($file != '.' && $file != '..') { 
  93. if (is_dir($src . '/' . $file)) { 
  94. if (!$this->object->recursive_copy($src . '/' . $file, $dst . '/' . $file)) { 
  95. $retval = FALSE; 
  96. break; 
  97. } else { 
  98. if (!copy($src . '/' . $file, $dst . '/' . $file)) { 
  99. $retval = FALSE; 
  100. break; 
  101. closedir($dir); 
  102. return $retval; 
  103. /** 
  104. * Deletes all files within a particular directory 
  105. * @param string $dir 
  106. * @return boolean 
  107. */ 
  108. function recursive_delete($dir) 
  109. $retval = FALSE; 
  110. $fp = opendir($dir); 
  111. while (false !== ($file = readdir($fp))) { 
  112. if ($file != '.' && $file != '..') { 
  113. $file = $dir . '/' . $file; 
  114. if (is_dir($file)) { 
  115. $retval = $this->object->recursive_delete($file); 
  116. } else { 
  117. $retval = unlink($file); 
  118. closedir($fp); 
  119. @rmdir($dir); 
  120. return $retval;