A_Watermarks_Form

Class A_Watermarks_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_Watermarks_Form extends Mixin 
  2. function get_model() 
  3. return C_Settings_Model::get_instance(); 
  4. function get_title() 
  5. return __('Watermarks', 'nggallery'); 
  6. /** 
  7. * Gets all fonts installed for watermarking 
  8. * @return array 
  9. */ 
  10. function _get_watermark_fonts() 
  11. $retval = array(); 
  12. $path = implode(DIRECTORY_SEPARATOR, array(rtrim(NGGALLERY_ABSPATH, "/\\"), 'fonts')); 
  13. foreach (scandir($path) as $filename) { 
  14. if (strpos($filename, '.') === 0) { 
  15. continue; 
  16. } else { 
  17. $retval[] = $filename; 
  18. return $retval; 
  19. /** 
  20. * Gets watermark sources, along with their respective fields 
  21. * @return array 
  22. */ 
  23. function _get_watermark_sources() 
  24. // We do this so that an adapter can add new sources 
  25. return array(__('Using an Image', 'nggallery') => 'image', __('Using Text', 'nggallery') => 'text'); 
  26. /** 
  27. * Renders the fields for a watermark source (image, text) 
  28. * @return string 
  29. */ 
  30. function _get_watermark_source_fields() 
  31. $retval = array(); 
  32. foreach ($this->object->_get_watermark_sources() as $label => $value) { 
  33. $method = "_render_watermark_{$value}_fields"; 
  34. if ($this->object->has_method($method)) { 
  35. $retval[$value] = $this->object->call_method($method); 
  36. return $retval; 
  37. /** 
  38. * Render fields that are needed when 'image' is selected as a watermark 
  39. * source 
  40. * @return string 
  41. */ 
  42. function _render_watermark_image_fields() 
  43. $message = __('An absolute or relative (to the site document root) file system path', 'nggallery'); 
  44. if (ini_get('allow_url_fopen')) { 
  45. $message = __('An absolute or relative (to the site document root) file system path or an HTTP url', 'nggallery'); 
  46. return $this->object->render_partial('photocrati-nextgen_other_options#watermark_image_fields', array('image_url_label' => __('Image URL:', 'nggallery'), 'watermark_image_url' => $this->object->get_model()->wmPath, 'watermark_image_text' => $message), TRUE); 
  47. /** 
  48. * Render fields that are needed when 'text is selected as a watermark 
  49. * source 
  50. * @return string 
  51. */ 
  52. function _render_watermark_text_fields() 
  53. $settings = $this->object->get_model(); 
  54. return $this->object->render_partial('photocrati-nextgen_other_options#watermark_text_fields', array('fonts' => $this->object->_get_watermark_fonts($settings), 'font_family_label' => __('Font Family:', 'nggallery'), 'font_family' => $settings->wmFont, 'font_size_label' => __('Font Size:', 'nggallery'), 'font_size' => $settings->wmSize, 'font_color_label' => __('Font Color:', 'nggallery'), 'font_color' => strpos($settings->wmColor, '#') === 0 ? $settings->wmColor : "#{$settings->wmColor}", 'watermark_text_label' => __('Text:', 'nggallery'), 'watermark_text' => $settings->wmText, 'opacity_label' => __('Opacity:', 'nggallery'), 'opacity' => $settings->wmOpaque), TRUE); 
  55. function _get_preview_image() 
  56. $registry = $this->object->get_registry(); 
  57. $storage = C_Gallery_Storage::get_instance(); 
  58. $image = C_Image_Mapper::get_instance()->find_first(); 
  59. $imagegen = C_Dynamic_Thumbnails_Manager::get_instance(); 
  60. $size = $imagegen->get_size_name(array('height' => 250, 'crop' => FALSE, 'watermark' => TRUE)); 
  61. $url = $image ? $storage->get_image_url($image, $size) : NULL; 
  62. $abspath = $image ? $storage->get_image_abspath($image, $size) : NULL; 
  63. return array('url' => $url, 'abspath' => $abspath); 
  64. function render() 
  65. $settings = $this->get_model(); 
  66. $image = $this->object->_get_preview_image(); 
  67. return $this->render_partial('photocrati-nextgen_other_options#watermarks_tab', array('notice' => __('Please note: You can only activate the watermark under Manage Gallery. This action cannot be undone.', 'nggallery'), 'watermark_source_label' => __('How will you generate a watermark?', 'nggallery'), 'watermark_sources' => $this->object->_get_watermark_sources(), 'watermark_fields' => $this->object->_get_watermark_source_fields($settings), 'watermark_source' => $settings->wmType, 'position_label' => __('Position:', 'nggallery'), 'position' => $settings->wmPos, 'offset_label' => __('Offset:', 'nggallery'), 'offset_x' => $settings->wmXpos, 'offset_y' => $settings->wmYpos, 'hidden_label' => __('(Show Customization Options)', 'nggallery'), 'active_label' => __('(Hide Customization Options)', 'nggallery'), 'thumbnail_url' => $image['url'], 'preview_label' => __('Preview of saved settings:', 'nggallery'), 'refresh_label' => __('Refresh preview image', 'nggallery'), 'refresh_url' => $settings->ajax_url), TRUE); 
  68. function save_action() 
  69. if ($settings = $this->object->param('watermark_options')) { 
  70. $this->object->get_model()->set($settings)->save(); 
  71. $image = $this->object->_get_preview_image(); 
  72. if (is_file($image['abspath'])) { 
  73. @unlink($image['abspath']);