NGG_Options

Class NGG_Options.

Defined (1)

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

/admin/class-ngg-options.php  
  1. class NGG_Options extends NGG_Post_Admin_Page { 
  2.  
  3. /** 
  4. * Save/Load options and add a new hook for plugins 
  5. */ 
  6. protected function processor() { 
  7.  
  8. global $nggRewrite; 
  9.  
  10. $ngg_options = get_option('ngg_options'); 
  11.  
  12. $old_state = $ngg_options['usePermalinks']; 
  13. $old_slug = $ngg_options['permalinkSlug']; 
  14.  
  15. if ( isset($_POST['updateoption']) ) { 
  16. check_admin_referer('ngg_settings'); 
  17. // get the hidden option fields, taken from WP core 
  18. if ( $_POST['page_options'] ) { 
  19. $options = explode( ', ', stripslashes( $_POST['page_options'] ) ); 
  20. } else { 
  21. $options = false; 
  22.  
  23. if ($options) { 
  24. foreach ($options as $option) { 
  25. $option = trim($option); 
  26. $value = false; 
  27. if ( isset( $_POST[ $option ] ) ) { 
  28. $value = trim( $_POST[ $option ] ); 
  29. if ($value === "true") { 
  30. $value = true; 
  31.  
  32. if ( is_numeric( $value ) ) { 
  33. $value = (int) $value; 
  34.  
  35. $ngg_options[$option] = $value; 
  36.  
  37. // do not allow a empty string 
  38. if ( empty ( $ngg_options['permalinkSlug'] ) ) 
  39. $ngg_options['permalinkSlug'] = 'nggallery'; 
  40.  
  41. // the path should always end with a slash 
  42. $ngg_options['gallerypath'] = trailingslashit($ngg_options['gallerypath']); 
  43. $ngg_options['imageMagickDir'] = trailingslashit($ngg_options['imageMagickDir']); 
  44.  
  45. // the custom sortorder must be ascending 
  46. $ngg_options['galSortDir'] = ($ngg_options['galSort'] == 'sortorder') ? 'ASC' : $ngg_options['galSortDir']; 
  47. // Save options 
  48. update_option('ngg_options', $ngg_options); 
  49.  
  50. // Flush Rewrite rules 
  51. if ( $old_state != $ngg_options['usePermalinks'] || $old_slug != $ngg_options['permalinkSlug'] ) 
  52. $nggRewrite->flush(); 
  53.  
  54. nggGallery::show_message(__('Settings updated successfully', 'nggallery')); 
  55.  
  56. if ( isset($_POST['clearcache']) ) { 
  57. check_admin_referer('ngg_settings'); 
  58.  
  59. $path = WINABSPATH . $ngg_options['gallerypath'] . 'cache/'; 
  60.  
  61. if (is_dir($path)) 
  62. if ($handle = opendir($path)) { 
  63. while (false !== ($file = readdir($handle))) { 
  64. if ($file != '.' && $file != '..') { 
  65. @unlink($path . '/' . $file); 
  66. closedir($handle); 
  67.  
  68. nggGallery::show_message(__('Cache cleared', 'nggallery')); 
  69.  
  70. if ( isset($_POST['createslugs']) ) { 
  71. check_admin_referer('ngg_settings'); 
  72. $this->rebuild_slugs(); 
  73.  
  74. do_action( 'ngg_update_options_page' ); 
  75.  
  76.  
  77. /** 
  78. * Render the page content 
  79. * 20150124:FZSM: there should be a cleaner way to handle this, instead making dynamic functions and actions. 
  80. */ 
  81. public function display() { 
  82.  
  83. parent::display(); 
  84.  
  85. // get list of tabs 
  86. $tabs = $this->get_tabs(); 
  87. $options = get_option('ngg_options'); 
  88.  
  89. ?> 
  90. <div class="wrap"> 
  91. <h2><?php _e('Settings', 'nggallery') ?></h2> 
  92. <div id="slider" style="display: none;"> 
  93. <ul id="tabs"> 
  94. <?php 
  95. foreach($tabs as $tab_key => $tab_name) { 
  96. echo "\n\t\t<li><a class='nav-tab' href='#$tab_key'>$tab_name</a></li>"; 
  97. ?> 
  98. </ul> 
  99. <?php 
  100. foreach($tabs as $tab_key => $tab_name) { 
  101. echo "\n\t<div id='$tab_key'>\n"; 
  102. // Looks for the internal class function, otherwise enable a hook for plugins 
  103. if ( method_exists( $this, "tab_$tab_key" )) 
  104. call_user_func( array( $this , "tab_$tab_key"), $options ); 
  105. else 
  106. do_action( 'ngg_tab_content_' . $tab_key ); 
  107. echo "\n\t</div>"; 
  108. ?> 
  109. </div> 
  110. </div> 
  111. <?php 
  112. $this->print_scripts(); 
  113.  
  114.  
  115. /** 
  116. * Print the JavaScript. 
  117. */ 
  118. private function print_scripts() { 
  119. ?> 
  120. <script type="text/javascript"> 
  121. function insertcode(value) { 
  122. var effectcode, extra; 
  123. switch (value) { 
  124. case 'none': 
  125. effectcode = ""; 
  126. break; 
  127. case "thickbox": 
  128. effectcode = 'class="thickbox" rel="%GALLERY_NAME%"'; 
  129. break; 
  130. case "lightbox": 
  131. effectcode = 'rel="lightbox[%GALLERY_NAME%]"'; 
  132. break; 
  133. case "highslide": 
  134. effectcode = 'class="highslide" onclick="return hs.expand(this, { slideshowGroup: %GALLERY_NAME% })"'; 
  135. break; 
  136. case "shutter": 
  137. effectcode = 'class="shutterset_%GALLERY_NAME%"'; 
  138. break; 
  139. case "photoSwipe": 
  140. effectcode = 'data-size="%IMG_WIDTH%x%IMG_HEIGHT%"'; 
  141. extra = 'Works with <a href="https://wordpress.org/plugins/photo-swipe/">PhotoSwipe</a>.'; 
  142. break; 
  143. default: 
  144. break; 
  145. jQuery("#thumbCode").val(effectcode); 
  146. jQuery("#effects-more").html(extra); 
  147.  
  148. jQuery(document).ready( function($) { 
  149. //$('html, body').scrollTop(0); 
  150. //Set tabs. 
  151. $('#slider').tabs({ fxFade: true, fxSpeed: 'fast' }).css('display', 'block'); 
  152.  
  153. //Set colorpicker. 
  154. $('.picker').wpColorPicker(); 
  155.  
  156. //Set preview for watermark. 
  157. $('#wm-preview-select').on("nggAutocompleteDone", function() { 
  158. $('#wm-preview-image').attr("src", '<?php echo home_url( 'index.php' ); ?>' + '?callback=image&pid=' + this.value + '&mode=watermark'); 
  159. $('#wm-preview-image-url').attr("href", '<?php echo home_url( 'index.php' ); ?>' + '?callback=image&pid=' + this.value + '&mode=watermark'); 
  160. }); 
  161.  
  162. jQuery("#wm-preview-select").nggAutocomplete( { 
  163. type: 'image', domain: "<?php echo home_url('index.php', is_ssl() ? 'https' : 'http'); ?>" 
  164. }); 
  165. }); 
  166. </script> 
  167. <?php 
  168.  
  169. /** 
  170. * Create array for tabs and add a filter for other plugins to inject more tabs 
  171. * @return array $tabs 
  172. */ 
  173. private function get_tabs() { 
  174.  
  175. $tabs = array(); 
  176.  
  177. $tabs['general'] = __('General', 'nggallery'); 
  178. $tabs['images'] = __('Images', 'nggallery'); 
  179. $tabs['gallery'] = __( 'Gallery', 'nggallery' ); 
  180. $tabs['effects'] = __('Effects', 'nggallery'); 
  181. $tabs['watermark'] = __('Watermark', 'nggallery'); 
  182. $tabs['slideshow'] = __('Slideshow', 'nggallery'); 
  183.  
  184. $tabs = apply_filters('ngg_settings_tabs', $tabs); 
  185.  
  186. return $tabs; 
  187.  
  188.  
  189. /** 
  190. * Show the general options. 
  191. */ 
  192. private function tab_general($options) { 
  193. ?> 
  194. <h3><?php _e( 'General settings', 'nggallery' ); ?></h3> 
  195. <form name="generaloptions" method="post" action="<?php echo $this->page; ?>"> 
  196. <?php wp_nonce_field('ngg_settings') ?> 
  197. <input type="hidden" name="page_options" value="gallerypath, silentUpgrade, deleteImg, useMediaRSS, usePicLens, usePermalinks, permalinkSlug, graphicLibrary, imageMagickDir, activateTags, appendType, maxImages" /> 
  198. <table class="form-table ngg-options"> 
  199. <tr> 
  200. <th><label for="gallerypath"><?php _e('Gallery path', 'nggallery'); ?></label></th> 
  201. <td> 
  202. <input <?php $this->readonly(is_multisite()); ?> type="text" class="regular-text code" name="gallerypath" id="gallerypath" value="<?php echo $options['gallerypath']; ?>" /> 
  203. <p class="description"><?php esc_html_e('This is the default path for all galleries', 'nggallery') ?></p> 
  204. </td> 
  205. </tr> 
  206. <tr> 
  207. <th><?php _e('Silent database upgrade', 'nggallery'); ?></th> 
  208. <td> 
  209. <input <?php disabled(is_multisite()); ?> type="checkbox" name="silentUpgrade" id="silentUpgrade" value="true" <?php checked( $options['silentUpgrade']); ?> /> 
  210. <label for="silentUpgrade"><?php _e('Update the database without notice.', 'nggallery') ?></label> 
  211. </td> 
  212. </tr> 
  213. <tr> 
  214. <th><?php _e('Image files', 'nggallery'); ?></th> 
  215. <td> 
  216. <input <?php disabled(is_multisite()); ?> type="checkbox" name="deleteImg" id="deleteImg" value="true" <?php checked( $options['deleteImg']); ?>> 
  217. <label for="deleteImg"> 
  218. <?php _e("Delete files when removing a gallery from the database", 'nggallery'); ?> 
  219. </label> 
  220. </td> 
  221. </tr> 
  222. <tr> 
  223. <th><?php _e('Select graphic library', 'nggallery'); ?></th> 
  224. <td> 
  225. <fieldset> 
  226. <label> 
  227. <input name="graphicLibrary" type="radio" value="gd" <?php checked('gd', $options['graphicLibrary']); ?>> 
  228. <?php _e('GD Library', 'nggallery');?> 
  229. </label><br> 
  230. <label> 
  231. <input name="graphicLibrary" type="radio" value="im" <?php checked('im', $options['graphicLibrary']); ?>> 
  232. <?php _e('ImageMagick (Experimental)', 'nggallery'); ?> 
  233. </label> 
  234. </fieldset> 
  235. <label> 
  236. <?php _e('Path to the ImageMagick library:', 'nggallery'); ?> 
  237. <input <?php $this->readonly(is_multisite()); ?> type="text" class="regular-text code" name="imageMagickDir" value="<?php echo $options['imageMagickDir']; ?>"> 
  238. </label> 
  239. </td> 
  240. </tr> 
  241. <tr> 
  242. <th><?php _e('Media RSS feed', 'nggallery'); ?></th> 
  243. <td> 
  244. <input type="checkbox" name="useMediaRSS" id="useMediaRSS" value="true" <?php checked( $options['useMediaRSS']); ?>> 
  245. <label for="useMediaRSS"><?php esc_html_e('Add a RSS feed to you blog header. Useful for CoolIris/PicLens', 'nggallery') ?></label> 
  246. </td> 
  247. </tr> 
  248. <tr> 
  249. <th><?php _e('PicLens/CoolIris', 'nggallery'); ?> (<a href="http://www.cooliris.com">CoolIris</a>)</th> 
  250. <td> 
  251. <input type="checkbox" id="usePicLens" name="usePicLens" value="true" <?php checked( $options['usePicLens']); ?>> 
  252. <label for="usePicLens"><?php _e('Include support for PicLens and CoolIris', 'nggallery'); ?></label> 
  253. <p class="description"><?php _e('When activated, JavaScript is added to your site footer. Make sure that wp_footer is called in your theme.', 'nggallery') ?></p> 
  254. </td> 
  255. </tr> 
  256. </table> 
  257. <h3><?php _e('Permalinks', 'nggallery') ?></h3> 
  258. <table class="form-table ngg-options"> 
  259. <tr> 
  260. <th><?php _e('Use permalinks', 'nggallery'); ?></th> 
  261. <td> 
  262. <input type="checkbox" name="usePermalinks" id="usePermalinks" value="true" <?php checked( $options['usePermalinks']); ?>> 
  263. <label for="usePermalinks"><?php _e('Adds a static link to all images', 'nggallery'); ?></label> 
  264. <p class="description"><?php _e('When activating this option, you need to update your permalink structure once', 'nggallery'); ?></p> 
  265. </td> 
  266. </tr> 
  267. <tr> 
  268. <th><label for="permalinkSlug"><?php _e('Gallery slug:', 'nggallery'); ?></label></th> 
  269. <td> 
  270. <input type="text" class="regular-text code" name="permalinkSlug" id="permalinkSlug" value="<?php echo $options['permalinkSlug']; ?>"> 
  271. </td> 
  272. </tr> 
  273. <tr> 
  274. <th><label for="createslugs"><?php _e('Recreate URLs', 'nggallery'); ?></label></th> 
  275. <td> 
  276. <input type="submit" name="createslugs" id="createslugs" class="button-secondary" value="<?php _e('Start now »', 'nggallery') ;?>"/> 
  277. <p class="description"><?php _e( "If you've changed these settings, you'll have to recreate the URLs.", 'nggallery'); ?></p> 
  278. </td> 
  279. </tr> 
  280. </table> 
  281. <h3><?php _e('Related images', 'nggallery'); ?></h3> 
  282. <table class="form-table ngg-options"> 
  283. <tr> 
  284. <th><?php _e('Add related images', 'nggallery'); ?></th> 
  285. <td> 
  286. <input name="activateTags" id="activateTags" type="checkbox" value="true" <?php checked( $options['activateTags']); ?>> 
  287. <label for="activateTags"><?php _e('This will add related images to every post', 'nggallery'); ?></label> 
  288. </td> 
  289. </tr> 
  290. <tr> 
  291. <th><?php _e('Match with', 'nggallery'); ?></th> 
  292. <td> 
  293. <fieldset> 
  294. <label> 
  295. <input name="appendType" type="radio" value="category" <?php checked('category', $options['appendType']); ?>> 
  296. <?php _e('Categories', 'nggallery') ;?> 
  297. </label> 
  298. <br> 
  299. <label> 
  300. <input name="appendType" type="radio" value="tags" <?php checked('tags', $options['appendType']); ?>> 
  301. <?php _e('Tags', 'nggallery') ;?> 
  302. </label> 
  303. </fieldset> 
  304. </td> 
  305. </tr> 
  306. <tr> 
  307. <th><label for="maxImages"><?php _e('Max. number of images', 'nggallery'); ?></label></th> 
  308. <td> 
  309. <input name="maxImages" id="maxImages" type="number" step="1" min="1" value="<?php echo $options['maxImages']; ?>" class="small-text"> 
  310. <p class="description"><?php _e('0 will show all images', 'nggallery'); ?></p> 
  311. </td> 
  312. </tr> 
  313. </table> 
  314. <?php submit_button( __('Save Changes'), 'primary', 'updateoption' ); ?> 
  315. </form> 
  316. <?php 
  317.  
  318. /** 
  319. * Show the image and thumbnail related options. 
  320. */ 
  321. private function tab_images($options) { 
  322. ?> 
  323. <h3><?php _e('Image settings', 'nggallery'); ?></h3> 
  324. <form name="imagesettings" method="POST" action="<?php echo $this->page.'#images'; ?>"> 
  325. <?php wp_nonce_field('ngg_settings') ?> 
  326. <input type="hidden" name="page_options" value="imgResize, imgWidth, imgHeight, imgQuality, imgBackup, imgAutoResize, thumbwidth, thumbheight, thumbfix, thumbquality, thumbDifferentSize"> 
  327. <table class="form-table ngg-options"> 
  328. <tr> 
  329. <th><?php _e('Resize images', 'nggallery') ?></th> 
  330. <td> 
  331. <label for="imgWidth"><?php _e('Width', 'nggallery') ?></label> 
  332. <input type="number" step="1" min="0" class="small-text" name="imgWidth" id="imgWidth" value="<?php echo $options['imgWidth']; ?>"> 
  333. <label for="imgHeight"><?php _e('Height', 'nggallery') ?></label> 
  334. <input type="number" step="1" min="0" class="small-text" name="imgHeight" id="imgHeight" value="<?php echo $options['imgHeight']; ?>"> 
  335. <p class="description"><?php _e('Width and height (in pixels). NextCellent Gallery will keep the ratio size.', 'nggallery') ?></p> 
  336. </td> 
  337. </tr> 
  338. <tr> 
  339. <th><label for="imgQuality"><?php _e('Image quality', 'nggallery'); ?></label></th> 
  340. <td><input type="number" step="1" min="0" max="100" class="small-text" name="imgQuality" id="imgQuality" value="<?php echo $options['imgQuality']; ?>">%</td> 
  341. </tr> 
  342. <tr> 
  343. <th><?php _e('Backup original', 'nggallery'); ?></th> 
  344. <td> 
  345. <label> 
  346. <input type="checkbox" name="imgBackup" value="true" <?php checked( $options['imgBackup']); ?>> 
  347. <?php _e('Create a backup for the resized images', 'nggallery'); ?> 
  348. </label> 
  349. </td> 
  350. </tr> 
  351. <tr> 
  352. <th><?php _e('Automatically resize', 'nggallery'); ?></th> 
  353. <td> 
  354. <label> 
  355. <input type="checkbox" name="imgAutoResize" value="1" <?php checked( $options['imgAutoResize']); ?>> 
  356. <?php _e('Automatically resize images on upload.', 'nggallery') ?> 
  357. </label> 
  358. </td> 
  359. </tr> 
  360. </table> 
  361. <h3><?php _e('Thumbnail settings', 'nggallery'); ?></h3> 
  362. <table class="form-table ngg-options"> 
  363. <tr> 
  364. <th><?php _e('Different sizes', 'nggallery'); ?></th> 
  365. <td> 
  366. <input type="checkbox" name="thumbDifferentSize" id="thumbDifferentSize" value="true" <?php checked( $options['thumbDifferentSize']); ?>> 
  367. <label for="thumbDifferentSize"><?php _e('Allows you to make thubnails with dimensions that differ from the rest of the gallery.', 'nggallery') ?></label> 
  368. </td> 
  369. </tr> 
  370. </table> 
  371. <p><?php _e('Please note: if you change the settings below settings, you need to recreate the thumbnails under -> Manage Gallery .', 'nggallery') ?></p> 
  372. <table class="form-table ngg-options"> 
  373. <tr> 
  374. <th><?php _e('Thumbnail size', 'nggallery'); ?></th> 
  375. <td> 
  376. <label for="thumbwidth"><?php _e('Width', 'nggallery') ?></label> 
  377. <input type="number" step="1" min="0" class="small-text" name="thumbwidth" id="thumbwidth" value="<?php echo $options['thumbwidth']; ?>"> 
  378. <label for="thumbheight"><?php _e('Height', 'nggallery') ?></label> 
  379. <input type="number" step="1" min="0" class="small-text" name="thumbheight" id="thumbheight" value="<?php echo $options['thumbheight']; ?>"> 
  380. <p class="description"><?php _e('These values are maximum values.', 'nggallery'); ?></p> 
  381. </td> 
  382. </tr> 
  383. <tr> 
  384. <th><?php _e('Fixed size', 'nggallery'); ?></th> 
  385. <td> 
  386. <input type="checkbox" name="thumbfix" id="thumbfix" value="true" <?php checked( $options['thumbfix']); ?>> 
  387. <label for="thumbfix"><?php _e('Ignore the aspect ratio, so no portrait thumbnails.', 'nggallery') ?></label> 
  388. </td> 
  389. </tr> 
  390. <tr> 
  391. <th><label for="thumbquality"><?php _e('Thumbnail quality', 'nggallery'); ?></label></th> 
  392. <td><input type="number" step="1" min="0" max="100" class="small-text" name="thumbquality" id="thumbquality" value="<?php echo $options['thumbquality']; ?>">%</td> 
  393. </tr> 
  394. </table> 
  395. <h3><?php _e('Single picture', 'nggallery') ?></h3> 
  396. <table class="form-table ngg-options"> 
  397. <tr> 
  398. <th><?php _e('Clear cache folder', 'nggallery'); ?></th> 
  399. <td><input type="submit" name="clearcache" class="button-secondary" value="<?php _e('Proceed now »', 'nggallery') ;?>"/></td> 
  400. </tr> 
  401. </table> 
  402. <?php submit_button( __('Save Changes'), 'primary', 'updateoption' ); ?> 
  403. </form> 
  404.  
  405. <?php 
  406.  
  407. /** 
  408. * Show gallery related settings 
  409. */ 
  410. private function tab_gallery($options) { 
  411. ?> 
  412. <h3><?php _e('Gallery settings', 'nggallery'); ?></h3> 
  413. <form name="galleryform" method="POST" action="<?php echo $this->page . '#gallery'; ?>"> 
  414. <?php wp_nonce_field('ngg_settings') ?> 
  415. <input type="hidden" name="page_options" value="galNoPages, galImages, galColumns, galShowSlide, galTextSlide, galTextGallery, galShowOrder, galImgBrowser, galSort, galSortDir, galHiddenImg, galAjaxNav"> 
  416. <table class="form-table ngg-options"> 
  417. <tr> 
  418. <th><?php _e('Inline gallery', 'nggallery') ?></th> 
  419. <td> 
  420. <input name="galNoPages" id="galNoPages" type="checkbox" value="true" <?php checked( $options['galNoPages']); ?>> 
  421. <label for="galNoPages"><?php _e('Galleries will not be shown on a subpage, but on the same page.', 'nggallery') ?></label> 
  422. </td> 
  423. </tr> 
  424. <tr> 
  425. <th><label for="galImages"><?php _e('Images per page', 'nggallery'); ?></label></th> 
  426. <td> 
  427. <input type="number" step="1" min="0" class="small-text" name="galImages" id="galImages" value="<?php echo $options['galImages']; ?>"> 
  428. <?php _e( 'images', 'nggallery'); ?> 
  429. <p class="description"><?php _e('0 will disable pagination and show all images on one page.', 'nggallery') ?></p> 
  430. </td> 
  431. </tr> 
  432. <tr> 
  433. <th><label for="galColumns"><?php esc_html_e('Columns', 'nggallery'); ?></label></th> 
  434. <td> 
  435. <input type="number" step="1" min="0" class="small-text" name="galColumns" id="galColumns" value="<?php echo $options['galColumns']; ?>"> 
  436. <?php _e( 'columns per page', 'nggallery'); ?> 
  437. <p class="description"><?php _e('0 will display as much columns as possible. This is normally only required for captions below the images.', 'nggallery') ?></p> 
  438. </td> 
  439. </tr> 
  440. <tr> 
  441. <th><?php _e('Slideshow', 'nggallery'); ?></th> 
  442. <td> 
  443. <label> 
  444. <input name="galShowSlide" type="checkbox" value="true" <?php checked( $options['galShowSlide']); ?>> 
  445. <?php _e('Enable slideshow', 'nggallery'); ?> 
  446. </label> 
  447. <br> 
  448. <label> 
  449. <?php _e('Text to show:', 'nggallery'); ?> 
  450. <input type="text" class="regular-text" name="galTextSlide" value="<?php echo $options['galTextSlide'] ?>"> 
  451. </label> 
  452. <input type="text" name="galTextGallery" value="<?php echo $options['galTextGallery'] ?>" class="regular-text"> 
  453. <p class="description"> <?php _e('This is the text the visitors will have to click to switch between display modes.', 'nggallery'); ?></p> 
  454. </td> 
  455. </tr> 
  456. <tr> 
  457. <th><?php _e('Show first', 'nggallery'); ?></th> 
  458. <td> 
  459. <fieldset> 
  460. <label> 
  461. <input name="galShowOrder" type="radio" value="gallery" <?php checked('gallery', $options['galShowOrder']); ?>> 
  462. <?php _e('Thumbnails', 'nggallery') ;?> 
  463. </label> 
  464. <br> 
  465. <label> 
  466. <input name="galShowOrder" type="radio" value="slide" <?php checked('slide', $options['galShowOrder']); ?>> 
  467. <?php _e('Slideshow', 'nggallery') ;?> 
  468. </label> 
  469. </fieldset> 
  470. <p class="description"><?php _e( 'Choose what visitors will see first.', 'nggallery'); ?></p> 
  471. </td> 
  472. </tr> 
  473. <tr> 
  474. <th><?php _e('ImageBrowser', 'nggallery'); ?></th> 
  475. <td> 
  476. <label> 
  477. <input name="galImgBrowser" type="checkbox" value="true" <?php checked( $options['galImgBrowser']); ?>> 
  478. <?php _e('Use ImageBrowser instead of another effect.', 'nggallery'); ?> 
  479. </label> 
  480. </td> 
  481. </tr> 
  482. <tr> 
  483. <th><?php _e('Hidden images', 'nggallery'); ?></th> 
  484. <td> 
  485. <label> 
  486. <input name="galHiddenImg" type="checkbox" value="true" <?php checked( $options['galHiddenImg']); ?>> 
  487. <?php _e('Loads all images for the modal window, when pagination is used (like Thickbox, Lightbox etc.).', 'nggallery'); ?> 
  488. </label> 
  489. <p class="description"> <?php _e('Note: this increases the page load (possibly a lot)', 'nggallery'); ?> 
  490. </td> 
  491. </tr> 
  492. <tr> 
  493. <th><?php _e('AJAX pagination', 'nggallery'); ?></th> 
  494. <td> 
  495. <label> 
  496. <input name="galAjaxNav" type="checkbox" value="true" <?php checked( $options['galAjaxNav']); ?>> 
  497. <?php _e('Use AJAX pagination to browse images without reloading the page.', 'nggallery'); ?> 
  498. </label> 
  499. <p class="description"><?php esc_html_e('Note: works only in combination with the Shutter effect.', 'nggallery'); ?></p> 
  500. </td> 
  501. </tr> 
  502. </table> 
  503. <h3><?php _e('Sort options', 'nggallery'); ?></h3> 
  504. <table class="form-table ngg-options"> 
  505. <tr> 
  506. <th><?php _e('Sort thumbnails', 'nggallery'); ?></th> 
  507. <td> 
  508. <fieldset> 
  509. <label> 
  510. <input name="galSort" type="radio" value="sortorder" <?php checked('sortorder', $options['galSort']); ?>> 
  511. <?php _e('Custom order', 'nggallery'); ?> 
  512. </label><br> 
  513. <label> 
  514. <input name="galSort" type="radio" value="pid" <?php checked('pid', $options['galSort']); ?>> 
  515. <?php _e('Image ID', 'nggallery'); ?> 
  516. </label><br> 
  517. <label> 
  518. <input name="galSort" type="radio" value="filename" <?php checked('filename', $options['galSort']); ?>> 
  519. <?php _e('File name', 'nggallery') ;?> 
  520. </label><br> 
  521. <label> 
  522. <input name="galSort" type="radio" value="alttext" <?php checked('alttext', $options['galSort']); ?>> 
  523. <?php _e('Alt / Title text', 'nggallery') ;?> 
  524. </label><br> 
  525. <label> 
  526. <input name="galSort" type="radio" value="imagedate" <?php checked('imagedate', $options['galSort']); ?>> 
  527. <?php _e('Date / Time', 'nggallery') ;?> 
  528. </label> 
  529. </fieldset> 
  530.  
  531. </td> 
  532. </tr> 
  533. <tr> 
  534. <th><?php _e('Sort direction', 'nggallery') ?></th> 
  535. <td> 
  536. <label> 
  537. <input name="galSortDir" type="radio" value="ASC" <?php checked('ASC', $options['galSortDir']); ?>> 
  538. <?php _e('Ascending', 'nggallery') ;?> 
  539. </label><br> 
  540. <label> 
  541. <input name="galSortDir" type="radio" value="DESC" <?php checked('DESC', $options['galSortDir']); ?>> 
  542. <?php _e('Descending', 'nggallery') ;?> 
  543. </label> 
  544. </td> 
  545. </tr> 
  546. </table> 
  547. <?php submit_button( __('Save Changes'), 'primary', 'updateoption' ); ?> 
  548. </form> 
  549. <?php 
  550.  
  551. /** 
  552. * Show the effect related settings. 
  553. */ 
  554. private function tab_effects($options) { 
  555. ?> 
  556. <h3><?php _e('Effects', 'nggallery'); ?></h3> 
  557. <p> 
  558. <?php _e('Here you can select the thumbnail effect, NextCellent Gallery will integrate the required HTML code in the images. Please note that only the Shutter and Thickbox effect will automatic added to your theme.', 'nggallery'); ?> 
  559. <?php _e('There are some placeholders available you can use in the code below.', 'nggallery'); ?> 
  560. </p> 
  561. <ul style="list-style: inside"> 
  562. <li><strong>%GALLERY_NAME%</strong> - <?php _e('The gallery name.', 'nggallery'); ?></li> 
  563. <li><strong>%IMG_WIDTH%</strong> - <?php _e('The width of the image.', 'nggallery'); ?></li> 
  564. <li><strong>%IMG_HEIGHT%</strong> - <?php _e('The height of the image.', 'nggallery'); ?></li> 
  565. </ul> 
  566. <form name="effectsform" method="POST" action="<?php echo $this->filepath . '#effects'; ?>"> 
  567. <?php wp_nonce_field('ngg_settings') ?> 
  568. <input type="hidden" name="page_options" value="thumbEffect, thumbCode"> 
  569. <table class="form-table ngg-options"> 
  570. <tr> 
  571. <th><label for="thumbEffect"><?php _e('JavaScript Thumbnail effect', 'nggallery') ?></label></th> 
  572. <td> 
  573. <select size="1" id="thumbEffect" name="thumbEffect" onchange="insertcode(this.value)"> 
  574. <option value="none" <?php selected('none', $options['thumbEffect']); ?>><?php _e('None', 'nggallery') ;?></option> 
  575. <option value="thickbox" <?php selected('thickbox', $options['thumbEffect']); ?>><?php _e('Thickbox', 'nggallery') ;?></option> 
  576. <option value="lightbox" <?php selected('lightbox', $options['thumbEffect']); ?>><?php _e('Lightbox', 'nggallery') ;?></option> 
  577. <option value="highslide" <?php selected('highslide', $options['thumbEffect']); ?>><?php _e('Highslide', 'nggallery') ;?></option> 
  578. <option value="shutter" <?php selected('shutter', $options['thumbEffect']); ?>><?php _e('Shutter', 'nggallery') ;?></option> 
  579. <option value="photoSwipe" <?php selected('photoSwipe', $options['thumbEffect']); ?>><?php _e('PhotoSwipe', 'nggallery') ;?></option> 
  580. <option value="custom" <?php selected('custom', $options['thumbEffect']); ?>><?php _e('Custom', 'nggallery') ;?></option> 
  581. </select> 
  582. </td> 
  583. </tr> 
  584. <tr> 
  585. <th><label for="thumbCode"><?php _e('Link Code line', 'nggallery'); ?></label></th> 
  586. <td> 
  587. <textarea class="normal-text code" id="thumbCode" name="thumbCode" cols="50" rows="5"> 
  588. <?php echo htmlspecialchars(stripslashes($options['thumbCode'])); ?> 
  589. </textarea> 
  590. </td> 
  591. </tr> 
  592. </table> 
  593. <?php submit_button( __('Save Changes'), 'primary', 'updateoption' ) ?> 
  594. <p id="effects-more"></p> 
  595. </form> 
  596. <?php 
  597.  
  598. /** 
  599. * Show watermark related settings. 
  600. */ 
  601. private function tab_watermark($options) { 
  602.  
  603. // take the first image as sample 
  604. $image_array = nggdb::find_last_images(0, 1); 
  605. $ngg_image = $image_array[0]; 
  606. $imageID = $ngg_image->pid; 
  607.  
  608. ?> 
  609. <h3><?php _e('Watermark', 'nggallery'); ?></h3> 
  610. <p><?php _e('Please note : you can only activate the watermark under -> Manage Galleries. This action cannot be undone.', 'nggallery') ?></p> 
  611. <form name="watermarkform" method="POST" action="<?php echo $this->page . '#watermark'; ?>"> 
  612. <?php wp_nonce_field('ngg_settings') ?> 
  613. <input type="hidden" name="page_options" value="wmPos, wmXpos, wmYpos, wmType, wmPath, wmFont, wmSize, wmColor, wmText, wmOpaque" /> 
  614. <div id="wm-preview"> 
  615. <h3><?php esc_html_e('Preview', 'nggallery') ?></h3> 
  616. <label for="wm-preview-select"><?php _e('Select an image', 'nggallery'); ?></label> 
  617. <select id="wm-preview-select" name="wm-preview-img" style="width: 200px"> 
  618. <?php echo '<option value="' . $ngg_image->pid . '">' . $ngg_image->pid . ' - ' . $ngg_image->alttext . '</option>'; ?> 
  619. </select> 
  620. <div id="wm-preview-container"> 
  621. <a id="wm-preview-image-url" href="<?php echo home_url( 'index.php' ); ?>?callback=image&pid=<?php echo intval( $imageID ); ?>&mode=watermark" target="_blank" title="<?php _e("View full image", 'nggallery'); ?>"> 
  622. <img id="wm-preview-image" src="<?php echo home_url( 'index.php' ); ?>?callback=image&pid=<?php echo intval( $imageID ); ?>&mode=watermark" /> 
  623. </a> 
  624. </div> 
  625. <h3><?php _e('Position', 'nggallery') ?></h3> 
  626. <table id="wm-position"> 
  627. <tr> 
  628. <td> 
  629. <strong><?php _e('Position', 'nggallery') ?></strong> 
  630. <table> 
  631. <tr> 
  632. <td><input type="radio" name="wmPos" value="topLeft" <?php checked('topLeft', $options['wmPos']); ?> /></td> 
  633. <td><input type="radio" name="wmPos" value="topCenter" <?php checked('topCenter', $options['wmPos']); ?> /></td> 
  634. <td><input type="radio" name="wmPos" value="topRight" <?php checked('topRight', $options['wmPos']); ?> /></td> 
  635. </tr> 
  636. <tr> 
  637. <td><input type="radio" name="wmPos" value="midLeft" <?php checked('midLeft', $options['wmPos']); ?> /></td> 
  638. <td><input type="radio" name="wmPos" value="midCenter" <?php checked('midCenter', $options['wmPos']); ?> /></td> 
  639. <td><input type="radio" name="wmPos" value="midRight" <?php checked('midRight', $options['wmPos']); ?> /></td> 
  640. </tr> 
  641. <tr> 
  642. <td><input type="radio" name="wmPos" value="botLeft" <?php checked('botLeft', $options['wmPos']); ?> /></td> 
  643. <td><input type="radio" name="wmPos" value="botCenter" <?php checked('botCenter', $options['wmPos']); ?> /></td> 
  644. <td><input type="radio" name="wmPos" value="botRight" <?php checked('botRight', $options['wmPos']); ?> /></td> 
  645. </tr> 
  646. </table> 
  647. </td> 
  648. <td> 
  649. <strong><?php _e('Offset', 'nggallery') ?></strong> 
  650. <table border="0"> 
  651. <tr> 
  652. <td><label for="wmXpos">x:</label></td> 
  653. <td><input type="number" step="1" min="0" class="small-text" name="wmXpos" id="wmXpos" value="<?php echo $options['wmXpos'] ?>">px</td> 
  654. </tr> 
  655. <tr> 
  656. <td><label for="wmYpos">y:</label></td> 
  657. <td><input type="number" step="1" min="0" class="small-text" name="wmYpos" id="wmYpos" value="<?php echo $options['wmYpos'] ?>" />px</td> 
  658. </tr> 
  659. </table> 
  660. </td> 
  661. </tr> 
  662. </table> 
  663. </div> 
  664. <h3><label><input type="radio" name="wmType" value="image" <?php checked('image', $options['wmType']); ?>><?php _e('Use image as watermark', 'nggallery') ?></label></h3> 
  665. <table class="wm-table form-table"> 
  666. <tr> 
  667. <th><label for="wmPath"><?php _e('URL to file', 'nggallery'); ?></label></th> 
  668. <td><input type="text" class="regular-text code" name="wmPath" id="wmPath" value="<?php echo $options['wmPath']; ?>"><br> 
  669. </tr> 
  670. </table> 
  671. <h3><label><input type="radio" name="wmType" value="text" <?php checked('text', $options['wmType']); ?>><?php _e('Use text as watermark', 'nggallery') ?></label></h3> 
  672. <table class="wm-table form-table"> 
  673. <tr> 
  674. <th><?php _e('Font', 'nggallery') ?></th> 
  675. <td> 
  676. <select name="wmFont" size="1"> 
  677. <?php 
  678. $fontlist = $this->get_fonts(); 
  679. foreach ( $fontlist as $fontfile ) { 
  680. echo "\n".'<option value="'.$fontfile.'" '. selected($fontfile, $options['wmFont']).' >'.$fontfile.'</option>'; 
  681. ?> 
  682. </select><br> 
  683. <span> 
  684. <?php if ( !function_exists('ImageTTFBBox') ) { 
  685. _e( 'This function will not work, cause you need the FreeType library', 'nggallery' ); 
  686. } else { 
  687. _e( 'You can upload more fonts in the folder <strong>nggallery/fonts</strong>', 'nggallery' ); 
  688. } ?> 
  689. </span> 
  690. </td> 
  691. </tr> 
  692. <tr> 
  693. <th><label for="wmSize"><?php _e('Size', 'nggallery'); ?></label></th> 
  694. <td><input type="number" step="1" min="0" class="small-text" name="wmSize" id="wmSize" value="<?php echo $options['wmSize']; ?>">px</td> 
  695. </tr> 
  696. <tr> 
  697. <th><label for="wmColor"><?php _e('Color', 'nggallery'); ?></label></th> 
  698. <td><input class="picker" type="text" id="wmColor" name="wmColor" value="<?php echo $options['wmColor'] ?>"> 
  699. </tr> 
  700. <tr> 
  701. <th><label for="wmText"><?php _e('Text', 'nggallery'); ?></label></th> 
  702. <td><textarea name="wmText" id="wmText" cols="50" rows="5" class="normal-text"><?php echo $options['wmText'] ?></textarea></td> 
  703. </tr> 
  704. <tr> 
  705. <th><label for="wmOpaque"><?php _e('Opaque', 'nggallery'); ?></label></th> 
  706. <td><input type="number" step="1" min="0" max="100" class="small-text" name="wmOpaque" id="wmOpaque" value="<?php echo $options['wmOpaque'] ?>">%</td> 
  707. </tr> 
  708. </table> 
  709. <div class="clear"></div> 
  710. <?php submit_button( __('Save Changes'), 'primary', 'updateoption' ); ?> 
  711. </form> 
  712. <?php 
  713.  
  714. /** 
  715. * Get the fonts for the slideshow. 
  716. * @return array The fonts. 
  717. */ 
  718. private function get_fonts() { 
  719.  
  720. $ttf_fonts = array (); 
  721.  
  722. // Files in wp-content/plugins/nggallery/fonts directory 
  723. $plugin_root = NGGALLERY_ABSPATH . 'fonts'; 
  724.  
  725. $plugins_dir = @ dir($plugin_root); 
  726. if ($plugins_dir) { 
  727. while (($file = $plugins_dir->read()) !== false) { 
  728. if (preg_match('|^\.+$|', $file)) 
  729. continue; 
  730. if (is_dir($plugin_root.'/'.$file)) { 
  731. $plugins_subdir = @ dir($plugin_root.'/'.$file); 
  732. if ($plugins_subdir) { 
  733. while (($subfile = $plugins_subdir->read()) !== false) { 
  734. if (preg_match('|^\.+$|', $subfile)) 
  735. continue; 
  736. if (preg_match('|\.ttf$|', $subfile)) 
  737. $ttf_fonts[] = "$file/$subfile"; 
  738. } else { 
  739. if (preg_match('|\.ttf$|', $file)) 
  740. $ttf_fonts[] = $file; 
  741.  
  742. return $ttf_fonts; 
  743.  
  744. /** 
  745. * Show slideshow related settings 
  746. */ 
  747. private function tab_slideshow($ngg_options) { 
  748. ?> 
  749. <form name="player_options" method="POST" action="<?php echo $this->page.'#slideshow'; ?>"> 
  750. <?php wp_nonce_field('ngg_settings'); ?> 
  751. <input type="hidden" name="page_options" value="irAutoDim, slideFx, irWidth, irHeight, irRotatetime, irLoop, irDrag, irNavigation, irNavigationDots, irAutoplay, irAutoplayTimeout, irAutoplayHover, irNumber, irClick" /> 
  752. <h3><?php _e('Slideshow', 'nggallery'); ?></h3> 
  753. <table class="form-table ngg-options"> 
  754. <tr> 
  755. <th><?php _e('Fit to space', 'nggallery'); ?></th> 
  756. <td> 
  757. <input type="checkbox" name="irAutoDim" id="irAutoDim" value="true" <?php checked( $ngg_options['irAutoDim']); ?>"> 
  758. <label for="irAutoDim"><?php _e( "Let the slideshow fit in the available space.", 'nggallery'); ?></label> 
  759. </td> 
  760. </tr> 
  761. <tr> 
  762. <th><?php _e('Default size', 'nggallery'); ?></th> 
  763. <td> 
  764. <label for="irWidth"><?php _e('Width', 'nggallery'); ?></label> 
  765. <input <?php $this->readonly($ngg_options['irAutoDim']); ?> type="number" min="0" class="small-text" name="irWidth" id="irWidth" value="<?php echo $ngg_options['irWidth']; ?>"> 
  766. <label for="irHeight"><?php _e('Height', 'nggallery'); ?></label> 
  767. <input <?php $this->readonly($ngg_options['irAutoDim']); ?> type="number" min="0" class="small-text" name="irHeight" id="irHeight" value="<?php echo $ngg_options['irHeight']; ?>"> 
  768. </td> 
  769. </tr> 
  770. <tr> 
  771. <th><label for="slideFx"><?php _e('Transition / Fade effect', 'nggallery'); ?></label></th> 
  772. <td> 
  773. <select size="1" name="slideFx" id="slideFx"> 
  774. <?php 
  775. $options = array( 
  776. __( 'Attention Seekers', 'nggallery' ) => array( "bounce", "flash", "pulse", "rubberBand", "shake", "swing", "tada", "wobble"),  
  777. __( 'Bouncing Entrances', 'nggallery' ) => array( "bounceIn", "bounceInDown", "bounceInLeft", "bounceInRight", "bounceInUp" ),  
  778. __( 'Fading Entrances', 'nggallery' ) => array( "fadeIn", "fadeInDown", "fadeInDownBig", "fadeInLeft", "fadeInLeftBig", "fadeInRight", "fadeInRightBig", "fadeInUp", "fadeInUpBig"),  
  779. __( 'Fading Exits', 'nggallery' ) => array( "fadeOut", "fadeOutDown", "fadeOutDownBig", "fadeOutLeft", "fadeOutLeftBig", "fadeOutRight", "fadeOutRightBig", "fadeOutUp", "fadeOutUpBig"),  
  780. __( 'Flippers', 'nggallery' ) => array( "flip", "flipInX", "flipInY", "flipOutX", "flipOutY" ),  
  781. __( 'Lightspeed', 'nggallery' ) => array( "lightSpeedIn", "lightSpeedOut"),  
  782. __( 'Rotating Entrances', 'nggallery' ) => array( "rotateIn", "rotateInDownLeft", "rotateInDownRight", "rotateInUpLeft", "rotateInUpRight" ),  
  783. __( 'Rotating Exits', 'nggallery' ) => array( "rotateOut", "rotateOutDownLeft", "rotateOutDownRight", "rotateOutUpLeft", "rotateOutUpRight" ),  
  784. __( 'Specials', 'nggallery' ) => array( "hinge", "rollIn", "rollOut" ),  
  785. __( 'Zoom Entrances', 'nggallery' ) => array( "zoomIn", "zoomInDown", "zoomInLeft", "zoomInRight", "zoomInUp" ) 
  786. ); 
  787.  
  788. foreach( $options as $option => $val ) { 
  789. echo $this->convert_fx_to_optgroup( $val, $option, $ngg_options ); 
  790. ?> 
  791. </select> 
  792. <p class="description"> 
  793. <?php _e("These effects are powered by"); ?> <strong>animate.css</strong>. <a target="_blank" href="http://daneden.github.io/animate.css/"><?php _e("Click here for examples of all effects and to learn more."); ?></a></p> 
  794. </td> 
  795. </tr> 
  796. <tr> 
  797. <th><?php _e('Loop', 'nggallery') ?></th> 
  798. <td> 
  799. <input type="checkbox" name="irLoop" id="irLoop" value="true" <?php checked( $ngg_options['irLoop']); ?>"> 
  800. <label for="irLoop"><?php _e( "Infinity loop. Duplicate last and first items to get loop illusion.", 'nggallery'); ?></label> 
  801. </td> 
  802. </tr> 
  803. <tr> 
  804. <th><?php _e('Mouse/touch drag', 'nggallery') ?></th> 
  805. <td> 
  806. <input type="checkbox" name="irDrag" id="irDrag" value="true" <?php checked( $ngg_options['irDrag'] ); ?>"> 
  807. <label for="irDrag"><?php _e( "Enable dragging with the mouse (or touch).", 'nggallery'); ?></label> 
  808. </td> 
  809. </tr> 
  810. <tr> 
  811. <th><?php _e('Previous / Next', 'nggallery') ?></th> 
  812. <td> 
  813. <input type="checkbox" name="irNavigation" id="irNavigation" value="true" <?php checked( $ngg_options['irNavigation'] ); ?>> 
  814. <label for="irNavigation"><?php _e( "Show next/previous buttons.", 'nggallery'); ?></label> 
  815. </td> 
  816. </tr> 
  817. <tr> 
  818. <th><?php _e('Show dots', 'nggallery') ?></th> 
  819. <td> 
  820. <input type="checkbox" name="irNavigationDots" id="irNavigationDots" value="true" <?php checked( $ngg_options['irNavigationDots'] ); ?>> 
  821. <label for="irNavigationDots"><?php _e( "Show dots for each image.", 'nggallery'); ?></label> 
  822. </td> 
  823. </tr> 
  824. <tr> 
  825. <th><?php _e('Autoplay', 'nggallery') ?></th> 
  826. <td> 
  827. <input type="checkbox" name="irAutoplay" id="irAutoplay" value="true" <?php checked( $ngg_options['irAutoplay'] ); ?>> 
  828. <label for="irAutoplay"><?php _e( "Automatically play the images.", 'nggallery'); ?></label> 
  829. </td> 
  830. </tr> 
  831. <tr> 
  832. <th><label for="irRotatetime"><?php _e('Duration', 'nggallery') ?></label></th> 
  833. <td> 
  834. <input <?php $this->readonly( false, $ngg_options['irAutoplay'] ); ?> type="number" step="1" min="0" class="small-text" name="irRotatetime" id="irRotatetime" value="<?php echo $ngg_options['irRotatetime'] ?>"> 
  835. <?php _e('sec.', 'nggallery') ;?> 
  836. </td> 
  837. </tr> 
  838. <tr> 
  839. <th><?php _e('Pause on hover', 'nggallery') ?></th> 
  840. <td> 
  841. <input <?php disabled(false, $ngg_options['irAutoplay']); ?> type="checkbox" name="irAutoplayHover" id="irAutoplayHover" value="true" <?php checked( $ngg_options['irAutoplayHover']); ?>> 
  842. <label for="irAutoplayHover"><?php _e( "Pause when hovering over the slideshow.", 'nggallery'); ?></label> 
  843. </td> 
  844. </tr> 
  845. <tr> 
  846. <th><?php _e('Click for next', 'nggallery') ?></th> 
  847. <td> 
  848. <input type="checkbox" name="irClick" id="irClick" value="true" <?php checked( $ngg_options['irClick']); ?>> 
  849. <label for="irClick"><?php _e( "Click to go to the next image.", 'nggallery'); ?></label></td> 
  850. </tr> 
  851. <tr> 
  852. <th><?php _e('Number of images', 'nggallery') ?></th> 
  853. <td> 
  854. <input type="number" step="1" min="1" class="small-text" name="irNumber" id="irNumber" value="<?php echo $ngg_options['irNumber'] ?>"> 
  855. <label for="irNumber"><?php _e('images', 'nggallery') ;?></label> 
  856. <p class="description"><?php _e( "Number of images to display when using random or latest.", 'nggallery'); ?></p> 
  857. </td> 
  858. </tr> 
  859. </table> 
  860. <?php submit_button( __('Save Changes'), 'primary', 'updateoption' ); ?> 
  861. </form> 
  862. <?php 
  863.  
  864. /** 
  865. * Convert an array of slideshow styles to a html dropdown group. 
  866. * @param array $data The option values (and display). 
  867. * @param string $title The label of the optgroup. 
  868. * @param array $ngg_options The options. 
  869. * @return string The output. 
  870. */ 
  871. private function convert_fx_to_optgroup( $data, $title = null, $ngg_options ) { 
  872.  
  873. if ( is_null( $title ) ) { 
  874. $out = null; 
  875. } else { 
  876. $out = '<optgroup label="' . $title . '">'; 
  877.  
  878. foreach ( $data as $option ) { 
  879. $out .= '<option value="' . $option . '" ' . selected( $option,  
  880. $ngg_options['slideFx'] ) . '>' . $option . '</option>'; 
  881.  
  882. if ( ! is_null( $title ) ) { 
  883. $out .= '</optgroup>'; 
  884.  
  885. return $out; 
  886.  
  887. /** 
  888. * Compare two values and echo readonly if they are. 
  889. * @param mixed $current The current value. 
  890. * @param mixed $other The other value. 
  891. */ 
  892. private function readonly($current, $other = true) { 
  893. if ( $current == $other ) { 
  894. echo 'readonly="readonly"'; 
  895.  
  896. /** 
  897. * Rebuild the slugs with an AJAX-request. 
  898. */ 
  899. private function rebuild_slugs() { 
  900. global $wpdb; 
  901.  
  902. $total = array(); 
  903. // get the total number of images 
  904. $total['images'] = intval( $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->nggpictures") ); 
  905. $total['gallery'] = intval( $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->nggallery") ); 
  906. $total['album'] = intval( $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->nggalbum") ); 
  907.  
  908. $messages = array( 
  909. 'images' => __( 'Rebuild image structure : %s / %s images', 'nggallery' ),  
  910. 'gallery' => __( 'Rebuild gallery structure : %s / %s galleries', 'nggallery' ),  
  911. 'album' => __( 'Rebuild album structure : %s / %s albums', 'nggallery' ),  
  912. ); 
  913.  
  914. foreach ( array_keys( $messages ) as $key ) { 
  915.  
  916. $message = sprintf( $messages[ $key ] ,  
  917. "<span class='ngg-count-current'>0</span>",  
  918. "<span class='ngg-count-total'>" . $total[ $key ] . "</span>" 
  919. ); 
  920.  
  921. echo "<div class='$key updated'><p class='ngg'>$message</p></div>"; 
  922.  
  923. $ajax_url = add_query_arg( 'action', 'ngg_rebuild_unique_slugs', admin_url( 'admin-ajax.php' ) ); 
  924. ?> 
  925. <script type="text/javascript"> 
  926. jQuery(document).ready(function($) { 
  927. var ajax_url = '<?php echo $ajax_url; ?>',  
  928. _action = 'images',  
  929. images = <?php echo $total['images']; ?>,  
  930. gallery = <?php echo $total['gallery']; ?>,  
  931. album = <?php echo $total['album']; ?>,  
  932. total = 0,  
  933. offset = 0,  
  934. count = 50; 
  935.  
  936. var $display = $('.ngg-count-current'); 
  937. $('.finished, .gallery, .album').hide(); 
  938. total = images; 
  939.  
  940. function call_again() { 
  941. if ( offset > total ) { 
  942. offset = 0; 
  943. // 1st run finished 
  944. if (_action == 'images') { 
  945. _action = 'gallery'; 
  946. total = gallery; 
  947. $('.images, .gallery').toggle(); 
  948. $display.html(offset); 
  949. call_again(); 
  950. return; 
  951. // 2nd run finished 
  952. if (_action == 'gallery') { 
  953. _action = 'album'; 
  954. total = album; 
  955. $('.gallery, .album').toggle(); 
  956. $display.html(offset); 
  957. call_again(); 
  958. return; 
  959. // 3rd run finished, exit now 
  960. if (_action == 'album') { 
  961. $('.ngg') 
  962. .html('<?php esc_html_e( 'Done.', 'nggallery' ); ?>') 
  963. .parent('div').hide(); 
  964. $('.finished').show(); 
  965. return; 
  966.  
  967. $.post(ajax_url, {'_action': _action, 'offset': offset}, function(response) { 
  968. $display.html(offset); 
  969.  
  970. offset += count; 
  971. call_again(); 
  972. }); 
  973.  
  974. call_again(); 
  975. }); 
  976. </script> 
  977. <?php