NGG_Adder

Class NGG_Adder.

Defined (1)

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

/admin/class-ngg-adder.php  
  1. class NGG_Adder extends NGG_Post_Admin_Page { 
  2.  
  3. /** 
  4. * Perform the upload and add a new hook for plugins 
  5. * @return void 
  6. */ 
  7. protected function processor() { 
  8.  
  9. /** 
  10. * @global nggdb $nggdb 
  11. */ 
  12. global $nggdb; 
  13.  
  14. $options = get_option( 'ngg_options' ); 
  15.  
  16. $default_path = $options['gallerypath']; 
  17.  
  18. if ( isset( $_POST['addgallery'] ) ) { 
  19. check_admin_referer( 'ngg_addgallery' ); 
  20.  
  21. if ( ! nggGallery::current_user_can( 'NextGEN Add new gallery' ) ) { 
  22. wp_die( __( 'Cheatin’ uh?' ) ); 
  23.  
  24. $new_gallery = esc_attr( $_POST['galleryname'] ); 
  25. $description = esc_attr( $_POST['gallerydesc'] ); 
  26. if ( ! empty( $new_gallery ) ) { 
  27. nggAdmin::create_gallery( $new_gallery, $default_path, true, $description ); 
  28.  
  29. if ( isset( $_POST['zipupload'] ) ) { 
  30. check_admin_referer( 'ngg_addgallery' ); 
  31.  
  32. if ( ! nggGallery::current_user_can( 'NextGEN Upload a zip' ) ) { 
  33. wp_die( __( 'Cheatin’ uh?' ) ); 
  34.  
  35. if ( $_FILES['zipfile']['error'] == 0 || ( ! empty( $_POST['zipurl'] ) ) ) { 
  36. nggAdmin::import_zipfile( intval( $_POST['zipgalselect'] ) ); 
  37. } else { 
  38. nggGallery::show_error( __( 'Upload failed!', 'nggallery' ) ); 
  39.  
  40. if ( isset( $_POST['importfolder'] ) ) { 
  41. check_admin_referer( 'ngg_addgallery' ); 
  42.  
  43. if ( ! nggGallery::current_user_can( 'NextGEN Import image folder' ) ) { 
  44. wp_die( __( 'Cheatin’ uh?' ) ); 
  45.  
  46. $galleryfolder = $_POST['galleryfolder']; 
  47. if ( ( ! empty( $galleryfolder ) ) AND ( $default_path != $galleryfolder ) ) { 
  48. nggAdmin::import_gallery( $galleryfolder ); 
  49.  
  50. if ( isset( $_POST['uploadimage'] ) ) { 
  51. check_admin_referer( 'ngg_addgallery' ); 
  52.  
  53. if ( ! nggGallery::current_user_can( 'NextGEN Upload in all galleries' ) ) { 
  54. wp_die( __( 'Cheatin’ uh?' ) ); 
  55.  
  56. if ( $_FILES['imagefiles']['error'][0] == 0 ) { 
  57. nggAdmin::upload_images(); 
  58. } else { 
  59. nggGallery::show_error( __( 'Upload failed! ' . nggAdmin::decode_upload_error( $_FILES['imagefiles']['error'][0] ),  
  60. 'nggallery' ) ); 
  61.  
  62. if ( isset( $_POST['swf_callback'] ) ) { 
  63. if ( $_POST['galleryselect'] == '0' ) { 
  64. nggGallery::show_error( __( 'You didn\'t select a gallery!', 'nggallery' ) ); 
  65. } else { 
  66. if ( $_POST['swf_callback'] == '-1' ) { 
  67. nggGallery::show_error( __( 'Upload failed!', 'nggallery' ) ); 
  68. } else { 
  69. $gallery = $nggdb->find_gallery( (int) $_POST['galleryselect'] ); 
  70. nggAdmin::import_gallery( $gallery->path ); 
  71.  
  72. if ( isset( $_POST['use_simple'] ) ) { 
  73. check_admin_referer( 'ngg_addgallery' ); 
  74. $options['swfUpload'] = false; 
  75. update_option( 'ngg_options', $options ); 
  76.  
  77. if ( isset( $_POST['use_advanced'] ) ) { 
  78. check_admin_referer( 'ngg_addgallery' ); 
  79. $options['swfUpload'] = true; 
  80. update_option( 'ngg_options', $options ); 
  81.  
  82. do_action( 'ngg_update_addgallery_page' ); 
  83.  
  84.  
  85. /** 
  86. * Render the page content 
  87. * @return void 
  88. */ 
  89. public function display() { 
  90.  
  91. parent::display(); 
  92.  
  93. /** 
  94. * @global nggdb $nggdb 
  95. */ 
  96. global $nggdb; 
  97.  
  98. $args = array( 
  99. 'max_size' => nggGallery::check_memory_limit(),  
  100. 'galleries' => $nggdb->find_all_galleries('gid', 'DESC'),  
  101. 'options' => get_option('ngg_options') 
  102.  
  103. ); 
  104.  
  105. // link for the flash file 
  106. $swf_upload_link = admin_url('/?nggupload'); 
  107.  
  108. // get list of tabs 
  109. $tabs = $this->tabs_order($args); 
  110.  
  111. // with this filter you can add custom file types 
  112. $file_types = apply_filters( 'ngg_swf_file_types', '*.jpg;*.jpeg;*.gif;*.png;*.JPG;*.JPEG;*.GIF;*.PNG' ); 
  113.  
  114. // Set the post params, which plupload will post back with the file, and pass them through a filter. 
  115. $post_params = array( 
  116. "auth_cookie" => (is_ssl() ? $_COOKIE[SECURE_AUTH_COOKIE] : $_COOKIE[AUTH_COOKIE]),  
  117. "logged_in_cookie" => $_COOKIE[LOGGED_IN_COOKIE],  
  118. "_wpnonce" => wp_create_nonce('ngg_swfupload'),  
  119. "galleryselect" => "0",  
  120. ); 
  121. $p = array(); 
  122.  
  123. foreach ( $post_params as $param => $val ) { 
  124. $val = esc_js( $val ); 
  125. $p[] = "'$param' : '$val'"; 
  126.  
  127. $post_params_str = json_encode($post_params); 
  128. ?> 
  129. <div class="wrap"> 
  130. <h2><?php _e('Add Gallery / Images', 'nggallery') ?></h2> 
  131. <div id="slider" style="display: none;"> 
  132. <ul id="tabs"> 
  133. <?php 
  134. foreach($tabs as $tab_key => $tab_name) { 
  135. echo "<li><a class='nav-tab' href='#$tab_key'>$tab_name</a></li>"; 
  136. ?> 
  137. </ul> 
  138. <?php 
  139. foreach($tabs as $tab_key => $tab_name) { 
  140. echo "<div id='$tab_key'>"; 
  141. // Looks for the internal class function, otherwise enable a hook for plugins 
  142. if ( method_exists( $this, "tab_$tab_key" )) 
  143. call_user_func( array( &$this , "tab_$tab_key"), $args ); 
  144. else 
  145. do_action( 'ngg_tab_content_' . $tab_key ); 
  146. echo "</div>"; 
  147. ?> 
  148. </div> 
  149. </div> 
  150. <script type="text/javascript"> 
  151. <?php if( !empty ($args['galleries']) ) { ?> 
  152. <?php if( $args['options']['swfUpload'] ) { ?> 
  153. // plupload script 
  154. jQuery(document).ready(function($) { 
  155. window.uploader = new plupload.Uploader({ 
  156. browse_button: 'plupload-browse-button',  
  157. container: 'plupload-upload-ui',  
  158. drop_element: 'uploadimage',  
  159. file_data_name: 'Filedata',  
  160. url: '<?php echo esc_js( $swf_upload_link ); ?>',  
  161. flash_swf_url: '<?php echo esc_js( includes_url('js/plupload/plupload.flash.swf') ); ?>',  
  162. silverlight_xap_url: '<?php echo esc_js( includes_url('js/plupload/plupload.silverlight.xap') ); ?>',  
  163. filters: { 
  164. mime_types : [ 
  165. {title: '<?php echo esc_js( __('Image Files', 'nggallery') ); ?>', extensions: '<?php echo esc_js( str_replace( array('*.', ';'), array('', ', '), $file_types) ); ?>'} 
  166. ],  
  167. max_file_size: '<?php echo round( (int) wp_max_upload_size() / 1024 ); ?>kb' 
  168. },  
  169. multipart: true,  
  170. urlstream_upload: true,  
  171. multipart_params : <?php echo $post_params_str; ?>,  
  172. <?php if ($args['options']['imgAutoResize'] == true) { ?> 
  173. resize: { 
  174. width: <?php echo esc_js( $args['options']['imgWidth'] ); ?>,  
  175. height: <?php echo esc_js( $args['options']['imgHeight'] ); ?>,  
  176. quality: <?php echo esc_js( $args['options']['imgQuality'] ); ?> 
  177. },  
  178. <?php } ?> 
  179. debug: false,  
  180. preinit : { 
  181. Init: function(up, info) { 
  182. debug('[Init]', 'Info :', info, 'Features :', up.features); 
  183. if (navigator.appVersion.indexOf("MSIE 10") > -1) { 
  184. up.features.triggerDialog = true; 
  185. initUploader(); 
  186. },  
  187. i18n : { 
  188. 'remove' : '<?php _e('remove', 'nggallery') ;?>',  
  189. 'browse' : '<?php _e('Browse...', 'nggallery') ;?>',  
  190. 'upload' : '<?php _e('Upload images', 'nggallery') ;?>' 
  191. }); 
  192.  
  193. uploader.bind('FilesAdded', function(up, files) { 
  194. $.each(files, function(i, file) { 
  195. fileQueued(file); 
  196. }); 
  197.  
  198. up.refresh(); 
  199. }); 
  200.  
  201. uploader.bind('BeforeUpload', function(up, file) { 
  202. uploadStart(file); 
  203. }); 
  204.  
  205. uploader.bind('UploadProgress', function(up, file) { 
  206. uploadProgress(file, file.loaded, file.size); 
  207. }); 
  208.  
  209. uploader.bind('Error', function(up, err) { 
  210. uploadError(err.file, err.code, err.message); 
  211.  
  212. up.refresh(); 
  213. }); 
  214.  
  215. uploader.bind('FileUploaded', function(up, file, response) { 
  216. uploadSuccess(file, response); 
  217. }); 
  218.  
  219. uploader.bind('UploadComplete', function(up, file) { 
  220. uploadComplete(file); 
  221. }); 
  222.  
  223. // on load change the upload to plupload 
  224. uploader.init(); 
  225.  
  226. nggAjaxOptions = { 
  227. header: "<?php _e('Upload images', 'nggallery') ;?>",  
  228. maxStep: 100 
  229. }; 
  230.  
  231. }); 
  232. <?php } else { ?> 
  233. // Browser upload script 
  234. var selDiv = ""; 
  235.  
  236. document.addEventListener("DOMContentLoaded", init, false); 
  237.  
  238. function init() { 
  239. document.querySelector('#imagefiles').addEventListener('change', handleFileSelect, false); 
  240. selDiv = document.querySelector("#uploadQueue"); 
  241.  
  242. function handleFileSelect(e) { 
  243. if(!e.target.files) return; 
  244. selDiv.innerHTML = ""; 
  245. var files = e.target.files; 
  246. for(var i=0; i<files.length; i++) { 
  247. var f = files[i]; 
  248. selDiv.innerHTML += f.name + "<br/>"; 
  249.  
  250. jQuery("#uploadimage_btn").click(function() { 
  251. checkForm('galleryselect'); 
  252. checkImgFile(); 
  253. }); 
  254. <?php } 
  255. } ?> 
  256. //jQuery Tabs script 
  257. jQuery(document).ready(function() { 
  258. jQuery('html, body').scrollTop(0); 
  259. jQuery('#slider').tabs({ fxFade: true, fxSpeed: 'fast' }).css({ 'display': 'block' }); 
  260.  
  261. jQuery("#zip-upload").click(function() { 
  262. checkZipFile(); 
  263. }); 
  264.  
  265. jQuery("#import-folder").click(function() { 
  266. return confirm( 
  267. '<?php echo esc_js(__("This will change folder and file names (e.g. remove spaces, special characters, ...)", "nggallery") )?>' + 
  268. '\n\n' + 
  269. '<?php echo esc_js( __("You will need to update your URLs if you link directly to the images.", "nggallery") )?>' + 
  270. '\n\n' + 
  271. '<?php echo esc_js( __("Press OK to proceed, and Cancel to stop.", "nggallery") )?>' 
  272. ); 
  273. }); 
  274. }); 
  275.  
  276. // File Tree implementation 
  277. jQuery(function() { 
  278. jQuery("span.browsefiles").show().click(function() { 
  279. var browser = jQuery("#file_browser"); 
  280. browser.fileTree({ 
  281. script: "admin-ajax.php?action=ngg_file_browser&nonce=<?php echo wp_create_nonce( 'ngg-ajax' ) ;?>",  
  282. root: jQuery("#galleryfolder").val() 
  283. }, function(folder) { 
  284. jQuery("#galleryfolder").val( folder ); 
  285. }); 
  286. browser.show('slide'); 
  287. }); 
  288. }); 
  289.  
  290. //Check for a selected gallery on basic uploader and zip upload 
  291. function checkForm(buttonID) { 
  292. var e = document.getElementById(buttonID); 
  293. var strUser = e.options[e.selectedIndex].value; 
  294. if (strUser == "0") { 
  295. alert("<?php _e('You didn\'t select a gallery!', 'nggallery')?>"); 
  296. event.preventDefault(); 
  297.  
  298. //Check if the user has selected a zip file 
  299. function checkZipFile() { 
  300. if( !(document.getElementById('zipfile').value || document.getElementById("zipurl").value) ) { 
  301. alert("<?php _e('You didn\'t select a file!', 'nggallery')?>"); 
  302. event.preventDefault(); 
  303.  
  304. //Check if the user has selected an image file 
  305. function checkImgFile() { 
  306. if( !document.getElementById('imagefiles').value ) { 
  307. alert("<?php _e('You didn\'t select a file!', 'nggallery')?>"); 
  308. event.preventDefault(); 
  309. </script> 
  310. <?php 
  311.  
  312.  
  313. /** 
  314. * Create array for tabs and add a filter for other plugins to inject more tabs 
  315. * @return array $tabs 
  316. */ 
  317. private function tabs_order($args) { 
  318.  
  319. $tabs = array(); 
  320.  
  321. if ( nggGallery::current_user_can( 'NextGEN Add new gallery' )) 
  322. $tabs['addgallery'] = __('New gallery', 'nggallery'); 
  323.  
  324. if ( !empty ($args['galleries']) ) 
  325. $tabs['uploadimage'] = __( 'Images', 'nggallery' ); 
  326.  
  327. if ( wpmu_enable_function('wpmuZipUpload') && nggGallery::current_user_can( 'NextGEN Upload a zip' ) ) 
  328. $tabs['zipupload'] = __('ZIP file', 'nggallery'); 
  329.  
  330. if ( wpmu_enable_function('wpmuImportFolder') && nggGallery::current_user_can( 'NextGEN Import image folder' ) ) 
  331. $tabs['importfolder'] = __('Import folder', 'nggallery'); 
  332.  
  333. $tabs = apply_filters('ngg_addgallery_tabs', $tabs); 
  334.  
  335. return $tabs; 
  336.  
  337.  
  338. private function tab_addgallery($args) { 
  339. ?> 
  340. <!-- create gallery --> 
  341. <h3><?php _e('Add a new gallery', 'nggallery') ;?></h3> 
  342. <form name="addgallery" id="addgallery_form" method="POST" action="<?php echo $this->page; ?>" accept-charset="utf-8" > 
  343. <?php wp_nonce_field('ngg_addgallery') ?> 
  344. <table class="form-table"> 
  345. <tr> 
  346. <th><label for="gallery-name"><?php _e('Name', 'nggallery') ;?>:</label></th> 
  347. <td> 
  348. <input type="text" class="regular-text" name="galleryname" id="gallery-name" value=""> 
  349. <br> 
  350. <p> 
  351. <?php printf( __('Create a new, empty gallery in the folder <strong>%s</strong>', 'nggallery'), $args['options']['gallerypath'] ); ?> 
  352. </p> 
  353. <p class="description"> 
  354. <?php printf( __('Allowed characters for file and folder names are "%s".', 'nggallery'), 'a-z, A-Z, 0-9, -, _' ) ?> 
  355. </p> 
  356. </td> 
  357. </tr> 
  358. <tr> 
  359. <th><label for="gallerydesc"><?php _e('Description', 'nggallery') ;?>:</label></th> 
  360. <td> 
  361. <textarea name="gallerydesc" id="gallerydesc" cols="50" rows="3"></textarea> 
  362. <p class="description"> 
  363. <?php _e('Add a description. This is optional and can be changed later.', 'nggallery') ;?> 
  364. </p> 
  365. </td> 
  366. </tr> 
  367. <?php do_action('ngg_add_new_gallery_form'); ?> 
  368. </table> 
  369. <div class="submit"> 
  370. <input class="button-primary" type="submit" name= "addgallery" value="<?php _e('Add gallery', 'nggallery') ;?>"> 
  371. </div> 
  372. </form> 
  373. <?php 
  374.  
  375. private function tab_zipupload($args) { 
  376. ?> 
  377. <!-- zip-file operation --> 
  378. <h3><?php _e('Upload a ZIP File', 'nggallery') ;?></h3> 
  379. <form name="zipupload" id="zipupload_form" method="POST" enctype="multipart/form-data" action="<?php echo $this->page.'#zipupload'; ?>" accept-charset="utf-8" > 
  380. <?php wp_nonce_field('ngg_addgallery') ?> 
  381. <table class="form-table"> 
  382. <tr> 
  383. <th><?php _e('Select ZIP file', 'nggallery') ;?>:</th> 
  384. <td> 
  385. <input type="file" name="zipfile" id="zipfile" class="uploadform"> 
  386. <p class="description"> 
  387. <?php _e('Upload a ZIP file with images', 'nggallery') ;?> 
  388. </p> 
  389. </td> 
  390. </tr> 
  391. <?php if (function_exists('curl_init')) : ?> 
  392. <tr> 
  393. <th><?php _e('or enter URL', 'nggallery') ;?>:</th> 
  394. <td> 
  395. <input type="text" name="zipurl" id="zipurl" class="regular-text code uploadform"> 
  396. <p class="description"> 
  397. <?php _e('Import a ZIP file from a URL', 'nggallery') ;?> 
  398. </p> 
  399. </td> 
  400. </tr> 
  401. <?php endif; ?> 
  402. <tr> 
  403. <th><?php _e('in to', 'nggallery') ;?></th> 
  404. <td> 
  405. <select name="zipgalselect" id="zipgalselect"> 
  406. <option value="0" ><?php _e('a new gallery', 'nggallery') ?></option> 
  407. <?php $this->print_galleries($args['galleries']); ?> 
  408. </select> 
  409. <br><?php echo $args['max_size']; ?> 
  410. <p class="description"> 
  411. <?php printf( __('Note: the upload limit on your server is <strong>%s MB</strong>.', 'nggallery'), wp_max_upload_size() / (1024 * 1024)); ?> 
  412. </p> 
  413. <br> 
  414. <?php if ( is_multisite() && wpmu_enable_function('wpmuQuotaCheck') ) { 
  415. display_space_usage(); 
  416. } ?> 
  417. </td> 
  418. </tr> 
  419. </table> 
  420. <div class="submit"> 
  421. <input class="button-primary" type="submit" name="zipupload" id="zip-upload" value="<?php _e('Start upload', 'nggallery') ;?>"> 
  422. </div> 
  423. </form> 
  424. <?php 
  425.  
  426. private function tab_importfolder($args) { 
  427. ?> 
  428. <!-- import folder --> 
  429. <h3><?php _e('Import an image folder', 'nggallery') ;?></h3> 
  430. <form name="importfolder" id="importfolder_form" method="POST" action="<?php echo $this->page.'#importfolder'; ?>" accept-charset="utf-8" > 
  431. <?php wp_nonce_field('ngg_addgallery') ?> 
  432. <table class="form-table"> 
  433. <tr> 
  434. <th><?php _e('Import from server:', 'nggallery') ;?></th> 
  435. <td> 
  436. <input type="text" id="galleryfolder" class="regular-text code" name="galleryfolder" value="<?php echo $args['options']['gallerypath']; ?>"> 
  437. <span class="browsefiles button" style="display:none"><?php _e('Browse...', 'nggallery'); ?></span> 
  438. <br> 
  439. <div id="file_browser"></div> 
  440. <p class="description"><?php _e('Note: you can change the default path in the gallery settings', 'nggallery') ;?></p> 
  441. <br><?php echo $args['max_size']; ?> 
  442. </td> 
  443. </tr> 
  444. </table> 
  445. <div class="submit"> 
  446. <input class="button-primary" type="submit" name= "importfolder" id="import-folder" value="<?php _e('Import folder', 'nggallery') ;?>"> 
  447. </div> 
  448. </form> 
  449. <?php 
  450.  
  451. private function tab_uploadimage($args) { 
  452. ?> 
  453. <!-- upload images --> 
  454. <h3><?php _e('Upload images', 'nggallery') ;?></h3> 
  455. <form name="uploadimage" id="uploadimage_form" method="POST" enctype="multipart/form-data" action="<?php echo $this->page.'#uploadimage'; ?>" accept-charset="utf-8" > 
  456. <?php wp_nonce_field('ngg_addgallery') ?> 
  457. <table class="form-table"> 
  458. <tr> 
  459. <td class="gallery-selector"> 
  460. <?php _e('in to', 'nggallery') ;?> 
  461. <select name="galleryselect" id="galleryselect"> 
  462. <option value="0" ><?php _e('Choose gallery', 'nggallery') ?></option> 
  463. <?php $this->print_galleries($args['galleries']); ?> 
  464. </select> 
  465. <br> 
  466. <?php echo $args['max_size']; ?> 
  467. <br> 
  468. <?php if ((is_multisite()) && wpmu_enable_function('wpmuQuotaCheck')) display_space_usage(); ?> 
  469. </td> 
  470. </tr> 
  471. <tr> 
  472. <?php if ($args['options']['swfUpload'] ) { ?> 
  473. <td colspan="2"> 
  474. <div id="plupload-upload-ui"> 
  475. <div id="drag-drop-area"> 
  476. <div class="drag-drop-inside"> 
  477. <p class="ngg-dragdrop-info drag-drop-info" > 
  478. <?php _e('Drop your files in this window', 'nggallery'); ?> 
  479. </p> 
  480. <p><?php _e('Or', 'nggallery'); ?></p> 
  481. <p class="drag-drop-buttons"> 
  482. <input id="plupload-browse-button" type="button" value="<?php esc_attr_e('Select Files', 'nggallery'); ?>" class="button"> 
  483. </p> 
  484. </div> 
  485. </div> 
  486. </div> 
  487. </td> 
  488. <?php } else { ?> 
  489. <td><span id='spanButtonPlaceholder'></span> 
  490. <input type="file" name="imagefiles[]" id="imagefiles" class="imagefiles" multiple></td> 
  491. <?php } ?> 
  492. </tr> 
  493. <tr> 
  494. <td> 
  495. <div id='uploadQueue'></div> 
  496. </td> 
  497. </tr> 
  498. </table> 
  499. <div class="submit"> 
  500. <?php if ($args['options']['swfUpload']) { ?> 
  501. <input class="button action" type="submit" name="use_simple" id="use-simple" title="<?php _e('Click here to use the browser upload instead', 'nggallery') ?>" value="<?php _e('Use basic uploader', 'nggallery') ;?>"> 
  502. <?php } else { ?> 
  503. <input class="button action" type="submit" name="use_advanced" id="use-advanced" title="<?php _e('Advanced uploading', 'nggallery') ?>" value="<?php _e('Use advanced uploader', 'nggallery') ;?>"> 
  504. <?php } ?> 
  505. <input class="button-primary" type="submit" name="uploadimage" id="uploadimage_btn" value="<?php _e('Upload images', 'nggallery') ;?>"> 
  506. <?php if ($args['options']['imgAutoResize'] == true) { ?> 
  507. <span class="description"> 
  508. <?php printf( __( 'Your images will be rescaled to max width %1$dpx or max height %2$dpx.', 'nggallery' ), (int) $args['options']['imgWidth' ], (int) $args['options']['imgHeight'] ); ?> 
  509. </span> 
  510. <?php } ?> 
  511. </div> 
  512. </form> 
  513. <?php 
  514.  
  515. /** 
  516. * @param array $galleries 
  517. */ 
  518. private function print_galleries($galleries) { 
  519. foreach($galleries as $gallery) { 
  520. if ( current_user_can( 'NextGEN Upload in all galleries' ) || nggAdmin::can_manage_this_gallery($gallery->author) ) { 
  521. $name = ( empty( $gallery->title ) ) ? $gallery->name : $gallery->title; 
  522. echo '<option value="' . $gallery->gid . '" >' . $gallery->gid . ' - ' . esc_attr( $name ) . '</option>';