/products/photocrati_nextgen/modules/nextgen_other_options/package.module.nextgen_other_options.php

  1. <?php 
  2. class A_Custom_Lightbox_Form extends Mixin 
  3. public function get_model() 
  4. return C_Lightbox_Library_Manager::get_instance()->get('custom_lightbox'); 
  5. /** 
  6. * Returns a list of fields to render on the settings page 
  7. */ 
  8. public function _get_field_names() 
  9. return array('lightbox_library_code', 'lightbox_library_styles', 'lightbox_library_scripts'); 
  10. /** 
  11. * @param $lightbox 
  12. * @return mixed 
  13. */ 
  14. public function _render_lightbox_library_code_field($lightbox) 
  15. return $this->_render_text_field($lightbox, 'code', __('Code', 'nggallery'), $lightbox->code); 
  16. /** 
  17. * @param $lightbox 
  18. * @return mixed 
  19. */ 
  20. public function _render_lightbox_library_styles_field($lightbox) 
  21. return $this->_render_textarea_field($lightbox, 'styles', __('Stylesheet URL', 'nggallery'), implode(' 
  22. ', $lightbox->styles)); 
  23. /** 
  24. * @param $lightbox 
  25. * @return mixed 
  26. */ 
  27. public function _render_lightbox_library_scripts_field($lightbox) 
  28. return $this->_render_textarea_field($lightbox, 'scripts', __('Javascript URL', 'nggallery'), implode(' 
  29. ', $lightbox->scripts)); 
  30. public function _convert_to_urls($input) 
  31. $retval = array(); 
  32. $urls = explode(' 
  33. ', $input); 
  34. foreach ($urls as $url) { 
  35. if (strpos($url, home_url()) === 0) { 
  36. $url = str_replace(home_url(), '', $url); 
  37. } elseif (strpos($url, 'http') === 0) { 
  38. $url = str_replace('https://', '//', $url); 
  39. $url = str_replace('http://', '//', $url); 
  40. $retval[] = $url; 
  41. return $retval; 
  42. public function save_action() 
  43. $settings = C_NextGen_Settings::get_instance(); 
  44. $modified = FALSE; 
  45. if ($params = $this->param('custom_lightbox')) { 
  46. if (array_key_exists('scripts', $params)) { 
  47. $settings->thumbEffectScripts = $this->_convert_to_urls($params['scripts']); 
  48. $modified = TRUE; 
  49. if (array_key_exists('styles', $params)) { 
  50. $settings->thumbEffectStyles = $this->_convert_to_urls($params['styles']); 
  51. $modified = TRUE; 
  52. if (array_key_exists('code', $params)) { 
  53. $settings->thumbEffectCode = $params['code']; 
  54. $modified = TRUE; 
  55. if ($modified) { 
  56. $settings->save(); 
  57. class A_Image_Options_Form extends Mixin 
  58. public function get_model() 
  59. return C_Settings_Model::get_instance(); 
  60. public function get_title() 
  61. return __('Image Options', 'nggallery'); 
  62. /** 
  63. * Returns the options available for sorting images 
  64. * @return array 
  65. */ 
  66. public function _get_image_sorting_options() 
  67. return array(__('Custom', 'nggallery') => 'sortorder', __('Image ID', 'nggallery') => 'pid', __('Filename', 'nggallery') => 'filename', __('Alt/Title Text', 'nggallery') => 'alttext', __('Date/Time', 'nggallery') => 'imagedate'); 
  68. /** 
  69. * Returns the options available for sorting directions 
  70. * @return array 
  71. */ 
  72. public function _get_sorting_direction_options() 
  73. return array(__('Ascending', 'nggallery') => 'ASC', __('Descending', 'nggallery') => 'DESC'); 
  74. /** 
  75. * Returns the options available for matching related images 
  76. */ 
  77. public function _get_related_image_match_options() 
  78. return array(__('Categories', 'nggallery') => 'category', __('Tags', 'nggallery') => 'tags'); 
  79. /** 
  80. * Tries to create the gallery storage directory if it doesn't exist 
  81. * already 
  82. * @return string 
  83. */ 
  84. public function _create_gallery_storage_dir($gallerypath = NULL) 
  85. $retval = TRUE; 
  86. if (!$gallerypath) { 
  87. $gallerypath = $this->object->get_model()->get('gallerypath'); 
  88. $fs = C_Fs::get_instance(); 
  89. $gallerypath = $fs->join_paths($fs->get_document_root('galleries'), $gallerypath); 
  90. if (!@file_exists($gallerypath)) { 
  91. @mkdir($gallerypath); 
  92. $retval = @file_exists($gallerypath); 
  93. return $retval; 
  94. /** 
  95. * Renders the form 
  96. */ 
  97. public function render() 
  98. if (!$this->object->_create_gallery_storage_dir()) { 
  99. $this->object->get_model()->add_error(__('Gallery path does not exist and could not be created', 'nggallery'), 'gallerypath'); 
  100. $settings = $this->object->get_model(); 
  101. 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); 
  102. public function save_action($image_options) 
  103. $save = TRUE; 
  104. if ($image_options) { 
  105. // Update the gallery path. Moves all images to the new location 
  106. if (isset($image_options['gallerypath']) && (!is_multisite() || get_current_blog_id() == 1)) { 
  107. $fs = C_Fs::get_instance(); 
  108. $original_dir = $fs->get_abspath($this->object->get_model()->get('gallerypath')); 
  109. $new_dir = $fs->get_abspath($image_options['gallerypath']); 
  110. $image_options['gallerypath'] = $fs->add_trailing_slash($image_options['gallerypath']); 
  111. } elseif (isset($image_options['gallerypath'])) { 
  112. unset($image_options['gallerypath']); 
  113. // Update image options 
  114. if ($save) { 
  115. $this->object->get_model()->set($image_options)->save(); 
  116. /** 
  117. * Copies one directory to another 
  118. * @param string $src 
  119. * @param string $dst 
  120. * @return boolean 
  121. */ 
  122. public function recursive_copy($src, $dst) 
  123. $retval = TRUE; 
  124. $dir = opendir($src); 
  125. @mkdir($dst); 
  126. while (false !== ($file = readdir($dir))) { 
  127. if ($file != '.' && $file != '..') { 
  128. if (is_dir($src . '/' . $file)) { 
  129. if (!$this->object->recursive_copy($src . '/' . $file, $dst . '/' . $file)) { 
  130. $retval = FALSE; 
  131. break; 
  132. } else { 
  133. if (!copy($src . '/' . $file, $dst . '/' . $file)) { 
  134. $retval = FALSE; 
  135. break; 
  136. closedir($dir); 
  137. return $retval; 
  138. /** 
  139. * Deletes all files within a particular directory 
  140. * @param string $dir 
  141. * @return boolean 
  142. */ 
  143. public function recursive_delete($dir) 
  144. $retval = FALSE; 
  145. $fp = opendir($dir); 
  146. while (false !== ($file = readdir($fp))) { 
  147. if ($file != '.' && $file != '..') { 
  148. $file = $dir . '/' . $file; 
  149. if (is_dir($file)) { 
  150. $retval = $this->object->recursive_delete($file); 
  151. } else { 
  152. $retval = unlink($file); 
  153. closedir($fp); 
  154. @rmdir($dir); 
  155. return $retval; 
  156. class A_Lightbox_Manager_Form extends Mixin 
  157. public function get_model() 
  158. return C_Settings_Model::get_instance(); 
  159. public function get_title() 
  160. return __('Lightbox Effects', 'nggallery'); 
  161. public function render() 
  162. $form_manager = C_Form_Manager::get_instance(); 
  163. // retrieve and render the settings forms for each library 
  164. $sub_fields = array(); 
  165. $form_manager->add_form(NGG_LIGHTBOX_OPTIONS_SLUG, 'custom_lightbox'); 
  166. foreach ($form_manager->get_forms(NGG_LIGHTBOX_OPTIONS_SLUG, TRUE) as $form) { 
  167. $form->enqueue_static_resources(); 
  168. $sub_fields[$form->context] = $form->render(FALSE); 
  169. // Highslide and jQuery.Lightbox were removed in 2.0.73 due to licensing. If a user has selected 
  170. // either of those options we silently make their selection fallback to Fancybox 
  171. $selected = $this->object->get_model()->thumbEffect; 
  172. if (in_array($selected, array('highslide', 'lightbox'))) { 
  173. $selected = 'fancybox'; 
  174. // Render container tab 
  175. return $this->render_partial('photocrati-nextgen_other_options#lightbox_library_tab', array('lightbox_library_label' => __('What effect would you like to use?', 'nggallery'), 'libs' => C_Lightbox_Library_Manager::get_instance()->get_all(), 'selected' => $selected, 'sub_fields' => $sub_fields, 'lightbox_global' => $this->object->get_model()->thumbEffectContext), TRUE); 
  176. public function save_action() 
  177. $settings = $this->object->get_model(); 
  178. // Ensure that a lightbox library was selected 
  179. if ($id = $this->object->param('lightbox_library_id')) { 
  180. $lightboxes = C_Lightbox_Library_Manager::get_instance(); 
  181. if (!$lightboxes->get($id)) { 
  182. $settings->add_error('Invalid lightbox effect selected'); 
  183. } else { 
  184. $settings->thumbEffect = $id; 
  185. // Get thumb effect context 
  186. if ($thumbEffectContext = $this->object->param('thumbEffectContext')) { 
  187. $settings->thumbEffectContext = $thumbEffectContext; 
  188. $settings->save(); 
  189. // Save other forms 
  190. $form_manager = C_Form_Manager::get_instance(); 
  191. $form_manager->add_form(NGG_LIGHTBOX_OPTIONS_SLUG, 'custom_lightbox'); 
  192. foreach ($form_manager->get_forms(NGG_LIGHTBOX_OPTIONS_SLUG, TRUE) as $form) { 
  193. if ($form->has_method('save_action')) { 
  194. $form->save_action(); 
  195. class A_Miscellaneous_Form extends Mixin 
  196. public function get_model() 
  197. return C_Settings_Model::get_instance('global'); 
  198. public function get_title() 
  199. return __('Miscellaneous', 'nggallery'); 
  200. public function render() 
  201. return $this->object->render_partial('photocrati-nextgen_other_options#misc_tab', array('mediarss_activated' => C_NextGen_Settings::get_instance()->useMediaRSS, 'mediarss_activated_label' => __('Add MediaRSS link?', 'nggallery'), 'mediarss_activated_help' => __('When enabled, adds a MediaRSS link to your header. Third-party web services can use this to publish your galleries', 'nggallery'), 'mediarss_activated_no' => __('No'), 'mediarss_activated_yes' => __('Yes'), 'galleries_in_feeds' => C_NextGen_Settings::get_instance()->galleries_in_feeds, 'galleries_in_feeds_label' => __('Display galleries in feeds', 'nggallery'), 'galleries_in_feeds_help' => __('NextGEN hides its gallery displays in feeds other than MediaRSS. This enables image galleries in feeds.', 'nggallery'), 'galleries_in_feeds_no' => __('No'), 'galleries_in_feeds_yes' => __('Yes'), 'cache_label' => __('Clear image cache', 'nggallery'), 'cache_confirmation' => __('Completely clear the NextGEN cache of all image modifications? 
  202.  
  203. Choose [Cancel] to Stop, [OK] to proceed.', 'nggallery'), 'slug_field' => $this->_render_text_field((object) array('name' => 'misc_settings'), 'router_param_slug', __('Permalink slug', 'nggallery'), $this->object->get_model()->router_param_slug), 'maximum_entity_count_field' => $this->_render_number_field((object) array('name' => 'misc_settings'), 'maximum_entity_count', __('Maximum image count', 'nggallery'), $this->object->get_model()->maximum_entity_count, __('This is the maximum limit of images that NextGEN will restrict itself to querying', 'nggallery') . '  
  204. ' . __('Note: This limit will not apply to slideshow widgets or random galleries if/when those galleries specify their own image limits', 'nggallery'), FALSE, '', 1)), TRUE); 
  205. public function cache_action() 
  206. $cache = C_Cache::get_instance(); 
  207. $cache->flush_galleries(); 
  208. C_Photocrati_Transient_Manager::flush(); 
  209. public function save_action() 
  210. if ($settings = $this->object->param('misc_settings')) { 
  211. // The Media RSS setting is actually a local setting, not a global one 
  212. $local_settings = C_NextGen_Settings::get_instance(); 
  213. $local_settings->set('useMediaRSS', $settings['useMediaRSS']); 
  214. unset($settings['useMediaRSS']); 
  215. // It's important the router_param_slug never be empty 
  216. if (empty($settings['router_param_slug'])) { 
  217. $settings['router_param_slug'] = 'nggallery'; 
  218. // If the router slug has changed, then flush the cache 
  219. if ($settings['router_param_slug'] != $this->object->get_model()->router_param_slug) { 
  220. C_Photocrati_Transient_Manager::flush('displayed_gallery_rendering'); 
  221. // Do not allow this field to ever be unset 
  222. if (empty($settings['maximum_entity_count']) || (int) $settings['maximum_entity_count'] <= 0) { 
  223. $settings['maximum_entity_count'] = 500; 
  224. // Save both setting groups 
  225. $this->object->get_model()->set($settings)->save(); 
  226. $local_settings->save(); 
  227. class A_Other_Options_Controller extends Mixin 
  228. public function enqueue_backend_resources() 
  229. $this->call_parent('enqueue_backend_resources'); 
  230. wp_enqueue_script('nextgen_settings_page', $this->get_static_url('photocrati-nextgen_other_options#nextgen_settings_page.js'), array('jquery-ui-accordion', 'jquery-ui-tooltip', 'wp-color-picker', 'jquery.nextgen_radio_toggle'), NGG_SCRIPT_VERSION); 
  231. wp_enqueue_style('nextgen_settings_page', $this->get_static_url('photocrati-nextgen_other_options#nextgen_settings_page.css'), FALSE, NGG_SCRIPT_VERSION); 
  232. public function get_page_title() 
  233. return __('Other Options', 'nggallery'); 
  234. public function get_required_permission() 
  235. return 'NextGEN Change options'; 
  236. class A_Other_Options_Page extends Mixin 
  237. public function setup() 
  238. $this->object->add(NGG_OTHER_OPTIONS_SLUG, array('adapter' => 'A_Other_Options_Controller', 'parent' => NGGFOLDER, 'before' => 'ngg_pro_upgrade')); 
  239. return $this->call_parent('setup'); 
  240. class A_Reset_Form extends Mixin 
  241. public function get_title() 
  242. return __('Reset Options', 'nggallery'); 
  243. public function render() 
  244. return $this->object->render_partial('photocrati-nextgen_other_options#reset_tab', array('reset_value' => __('Reset all options to default settings', 'nggallery'), 'reset_warning' => __('Replace all existing options and gallery options with their default settings', 'nggallery'), 'reset_label' => __('Reset settings', 'nggallery'), 'reset_confirmation' => __('Reset all options to default settings? 
  245.  
  246. Choose [Cancel] to Stop, [OK] to proceed.', 'nggallery')), TRUE); 
  247. public function reset_action() 
  248. global $wpdb; 
  249. // Flush the cache 
  250. C_Photocrati_Transient_Manager::flush(); 
  251. // Uninstall the plugin 
  252. $settings = C_NextGen_Settings::get_instance(); 
  253. if (defined('NGG_PRO_PLUGIN_VERSION') || defined('NEXTGEN_GALLERY_PRO_VERSION')) { 
  254. C_Photocrati_Installer::uninstall('photocrati-nextgen-pro'); 
  255. C_Photocrati_Installer::uninstall('photocrati-nextgen'); 
  256. // removes all ngg_options entry in wp_options 
  257. $settings->reset(); 
  258. $settings->destroy(); 
  259. // clear NextGEN's capabilities from the roles system 
  260. $capabilities = array('NextGEN Gallery overview', 'NextGEN Use TinyMCE', 'NextGEN Upload images', 'NextGEN Manage gallery', 'NextGEN Manage others gallery', 'NextGEN Manage tags', 'NextGEN Edit album', 'NextGEN Change style', 'NextGEN Change options', 'NextGEN Attach Interface'); 
  261. $roles = array('subscriber', 'contributor', 'author', 'editor', 'administrator'); 
  262. foreach ($roles as $role) { 
  263. $role = get_role($role); 
  264. foreach ($capabilities as $capability) { 
  265. if (!is_null($role)) { 
  266. $role->remove_cap($capability); 
  267. // Some installations of NextGen that upgraded from 1.9x to 2.0x have duplicates installed,  
  268. // so for now (as of 2.0.21) we explicitly remove all display types and lightboxes from the 
  269. // db as a way of fixing this. 
  270. $wpdb->query($wpdb->prepare("DELETE FROM {$wpdb->posts} WHERE post_type = %s", 'display_type')); 
  271. $wpdb->query($wpdb->prepare("DELETE FROM {$wpdb->posts} WHERE post_type = %s", 'lightbox_library')); 
  272. // the installation will run on the next page load; so make our own request before reloading the browser 
  273. wp_remote_get(admin_url('plugins.php'), array('timeout' => 180, 'blocking' => true, 'sslverify' => false)); 
  274. header('Location: ' . $_SERVER['REQUEST_URI']); 
  275. throw new E_Clean_Exit(); 
  276. class A_Roles_Form extends Mixin 
  277. public function get_title() 
  278. return __('Roles & Capabilities', 'nggallery'); 
  279. public function render() 
  280. $view = implode(DIRECTORY_SEPARATOR, array(rtrim(NGGALLERY_ABSPATH, '/\\'), 'admin', 'roles.php')); 
  281. include_once $view; 
  282. ob_start(); 
  283. nggallery_admin_roles(); 
  284. $retval = ob_get_contents(); 
  285. ob_end_clean(); 
  286. return $retval; 
  287. class A_Styles_Form extends Mixin 
  288. public function get_model() 
  289. return C_Settings_Model::get_instance(); 
  290. public function get_title() 
  291. return __('Styles', 'nggallery'); 
  292. public function render() 
  293. return $this->object->render_partial('photocrati-nextgen_other_options#styling_tab', array('activateCSS_label' => __('Enable custom CSS', 'nggallery'), 'activateCSS' => $this->object->get_model()->activateCSS, 'select_stylesheet_label' => __('What stylesheet would you like to use?', 'nggallery'), 'stylesheets' => C_NextGen_Style_Manager::get_instance()->find_all_stylesheets(), 'activated_stylesheet' => $this->object->get_model()->CSSfile, 'hidden_label' => __('(Show Customization Options)', 'nggallery'), 'active_label' => __('(Hide Customization Options)', 'nggallery'), 'cssfile_contents_label' => __('File Content:', 'nggallery'), 'writable_label' => __('Changes you make to the contents will be saved to', 'nggallery'), 'readonly_label' => __('You could edit this file if it were writable', 'nggallery')), TRUE); 
  294. public function save_action() 
  295. // Ensure that we have 
  296. if ($settings = $this->object->param('style_settings')) { 
  297. $this->object->get_model()->set($settings)->save(); 
  298. // Are we to modify the CSS file? 
  299. if ($contents = $this->object->param('cssfile_contents')) { 
  300. // Find filename 
  301. $css_file = $settings['CSSfile']; 
  302. $styles = C_NextGen_Style_Manager::get_instance(); 
  303. $styles->save($contents, $css_file); 
  304. /** 
  305. * Registers new AJAX functions for retrieving/updating 
  306. * the contents of CSS stylesheets 
  307. */ 
  308. class A_Stylesheet_Ajax_Actions extends Mixin 
  309. /** 
  310. * Retrieves the contents of the CSS stylesheet specified 
  311. */ 
  312. public function get_stylesheet_contents_action() 
  313. $retval = array(); 
  314. if ($this->object->_authorized_for_stylesheet_action()) { 
  315. $styles = C_NextGen_Style_Manager::get_instance(); 
  316. $abspath = $styles->find_selected_stylesheet_abspath($this->object->param('cssfile')); 
  317. $writepath = $styles->get_selected_stylesheet_saved_abspath($this->object->param('cssfile')); 
  318. if (is_readable($abspath)) { 
  319. $retval['contents'] = file_get_contents($abspath); 
  320. $retval['writable'] = is_writable($abspath); 
  321. $retval['abspath'] = $abspath; 
  322. $retval['writepath'] = $writepath; 
  323. } else { 
  324. $retval['error'] = 'Could not find stylesheet'; 
  325. } else { 
  326. $retval['error'] = 'Unauthorized'; 
  327. return $retval; 
  328. /** 
  329. * Determines if the request is authorized 
  330. * @return boolean 
  331. */ 
  332. public function _authorized_for_stylesheet_action() 
  333. $security = $this->get_registry()->get_utility('I_Security_Manager'); 
  334. $sec_actor = $security->get_current_actor(); 
  335. return $sec_actor->is_allowed('nextgen_edit_style'); 
  336. class A_Thumbnail_Options_Form extends Mixin 
  337. public function get_model() 
  338. return C_Settings_Model::get_instance(); 
  339. public function get_title() 
  340. return __('Thumbnail Options', 'nggallery'); 
  341. public function render() 
  342. $settings = $this->object->get_model(); 
  343. return $this->render_partial('photocrati-nextgen_other_options#thumbnail_options_tab', array('thumbnail_dimensions_label' => __('Default thumbnail dimensions:', 'nggallery'), 'thumbnail_dimensions_help' => __('When generating thumbnails, what image dimensions do you desire?', 'nggallery'), 'thumbnail_dimensions_width' => $settings->thumbwidth, 'thumbnail_dimensions_height' => $settings->thumbheight, 'thumbnail_crop_label' => __('Set fix dimension?', 'nggallery'), 'thumbnail_crop_help' => __('Ignore the aspect ratio, no portrait thumbnails?', 'nggallery'), 'thumbnail_crop' => $settings->thumbfix, 'thumbnail_quality_label' => __('Adjust Thumbnail Quality?', 'nggallery'), 'thumbnail_quality_help' => __('When generating thumbnails, what image quality do you desire?', 'nggallery'), 'thumbnail_quality' => $settings->thumbquality, 'size_list_label' => __('Size List', 'nggallery'), 'size_list_help' => __('List of default sizes used for thumbnails and images', 'nggallery'), 'size_list' => $settings->thumbnail_dimensions), TRUE); 
  344. public function save_action() 
  345. if ($settings = $this->object->param('thumbnail_settings')) { 
  346. $this->object->get_model()->set($settings)->save(); 
  347. class A_Watermarking_Ajax_Actions extends Mixin 
  348. /** 
  349. * Gets the new watermark preview url based on the new settings 
  350. * @return array 
  351. */ 
  352. public function get_watermark_preview_url_action() 
  353. $security = $this->get_registry()->get_utility('I_Security_Manager'); 
  354. $sec_actor = $security->get_current_actor(); 
  355. if ($sec_actor->is_allowed('nextgen_edit_settings')) { 
  356. $settings = C_NextGen_Settings::get_instance(); 
  357. $imagegen = C_Dynamic_Thumbnails_Manager::get_instance(); 
  358. $mapper = C_Image_Mapper::get_instance(); 
  359. $image = $mapper->find_first(); 
  360. $storage = C_Gallery_Storage::get_instance(); 
  361. $sizeinfo = array('quality' => 100, 'height' => 250, 'crop' => FALSE, 'watermark' => TRUE); 
  362. $size = $imagegen->get_size_name($sizeinfo); 
  363. $thumbnail_url = $storage->get_image_url($image, $size); 
  364. // Temporarily update the watermark options. Generate a new image based 
  365. // on these settings 
  366. if ($watermark_options = $this->param('watermark_options')) { 
  367. $watermark_options['wmFont'] = trim($watermark_options['wmFont']); 
  368. $settings->set($watermark_options); 
  369. $storage->generate_image_size($image, $size); 
  370. $thumbnail_url = $storage->get_image_url($image, $size); 
  371. $settings->load(); 
  372. return array('thumbnail_url' => $thumbnail_url); 
  373. } else { 
  374. return array('thumbnail_url' => '', 'error' => 'You are not allowed to perform this operation'); 
  375. class A_Watermarks_Form extends Mixin 
  376. public function get_model() 
  377. return C_Settings_Model::get_instance(); 
  378. public function get_title() 
  379. return __('Watermarks', 'nggallery'); 
  380. /** 
  381. * Gets all fonts installed for watermarking 
  382. * @return array 
  383. */ 
  384. public function _get_watermark_fonts() 
  385. $retval = array(); 
  386. $path = implode(DIRECTORY_SEPARATOR, array(rtrim(NGGALLERY_ABSPATH, '/\\'), 'fonts')); 
  387. foreach (scandir($path) as $filename) { 
  388. if (strpos($filename, '.') === 0) { 
  389. continue; 
  390. } else { 
  391. $retval[] = $filename; 
  392. return $retval; 
  393. /** 
  394. * Gets watermark sources, along with their respective fields 
  395. * @return array 
  396. */ 
  397. public function _get_watermark_sources() 
  398. // We do this so that an adapter can add new sources 
  399. return array(__('Using an Image', 'nggallery') => 'image', __('Using Text', 'nggallery') => 'text'); 
  400. /** 
  401. * Renders the fields for a watermark source (image, text) 
  402. * @return string 
  403. */ 
  404. public function _get_watermark_source_fields() 
  405. $retval = array(); 
  406. foreach ($this->object->_get_watermark_sources() as $label => $value) { 
  407. $method = "_render_watermark_{$value}_fields"; 
  408. if ($this->object->has_method($method)) { 
  409. $retval[$value] = $this->object->call_method($method); 
  410. return $retval; 
  411. /** 
  412. * Render fields that are needed when 'image' is selected as a watermark 
  413. * source 
  414. * @return string 
  415. */ 
  416. public function _render_watermark_image_fields() 
  417. $message = __('An absolute or relative (to the site document root) file system path', 'nggallery'); 
  418. if (ini_get('allow_url_fopen')) { 
  419. $message = __('An absolute or relative (to the site document root) file system path or an HTTP url', 'nggallery'); 
  420. 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); 
  421. /** 
  422. * Render fields that are needed when 'text is selected as a watermark 
  423. * source 
  424. * @return string 
  425. */ 
  426. public function _render_watermark_text_fields() 
  427. $settings = $this->object->get_model(); 
  428. 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); 
  429. public function _get_preview_image() 
  430. $registry = $this->object->get_registry(); 
  431. $storage = C_Gallery_Storage::get_instance(); 
  432. $image = C_Image_Mapper::get_instance()->find_first(); 
  433. $imagegen = C_Dynamic_Thumbnails_Manager::get_instance(); 
  434. $size = $imagegen->get_size_name(array('height' => 250, 'crop' => FALSE, 'watermark' => TRUE)); 
  435. $url = $image ? $storage->get_image_url($image, $size) : NULL; 
  436. $abspath = $image ? $storage->get_image_abspath($image, $size) : NULL; 
  437. return array('url' => $url, 'abspath' => $abspath); 
  438. public function render() 
  439. $settings = $this->get_model(); 
  440. $image = $this->object->_get_preview_image(); 
  441. 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); 
  442. public function save_action() 
  443. if ($settings = $this->object->param('watermark_options')) { 
  444. $this->object->get_model()->set($settings)->save(); 
  445. $image = $this->object->_get_preview_image(); 
  446. if (is_file($image['abspath'])) { 
  447. @unlink($image['abspath']); 
  448. class C_Settings_Model extends C_Component 
  449. /** 
  450. * @var C_NextGen_Settings_Base 
  451. */ 
  452. public $wrapper = NULL; 
  453. static $_instances = array(); 
  454. static function get_instance($context = FALSE) 
  455. if (!isset(self::$_instances[$context])) { 
  456. $klass = get_class(); 
  457. self::$_instances[$context] = new $klass(); 
  458. return self::$_instances[$context]; 
  459. public function define($context = FALSE) 
  460. parent::define($context); 
  461. $this->add_mixin('Mixin_Validation'); 
  462. if ($this->has_context('global') or $this->has_context('site')) { 
  463. $this->wrapper = C_NextGen_Settings::get_instance(); 
  464. } else { 
  465. $this->wrapper = C_NextGen_Settings::get_instance(); 
  466. public function __get($key) 
  467. return $this->wrapper->get($key); 
  468. public function __set($key, $value) 
  469. $this->wrapper->set($key, $value); 
  470. return $this; 
  471. public function __isset($key) 
  472. return $this->wrapper->is_set($key); 
  473. public function __call($method, $args) 
  474. if (!$this->get_mixin_providing($method)) { 
  475. return call_user_func_array(array(&$this->wrapper, $method), $args); 
  476. } else { 
  477. return parent::__call($method, $args); 
.