PageRenderTime 49ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/wp-content/plugins/nextgen-gallery/admin/addgallery.php

https://gitlab.com/blueprintmrk/bladencountyrecords
PHP | 417 lines | 308 code | 62 blank | 47 comment | 46 complexity | ffa9327d770b0b50eb4226c388abeaca MD5 | raw file
  1. <?php
  2. if(preg_match('#' . basename(__FILE__) . '#', $_SERVER['PHP_SELF'])) { die('You are not allowed to call this page directly.'); }
  3. // sometimes a error feedback is better than a white screen
  4. @ini_set('error_reporting', E_ALL ^ E_NOTICE);
  5. class nggAddGallery {
  6. /**
  7. * PHP4 compatibility layer for calling the PHP5 constructor.
  8. *
  9. */
  10. function nggAddGallery() {
  11. return $this->__construct();
  12. }
  13. /**
  14. * nggOptions::__construct()
  15. *
  16. * @return void
  17. */
  18. function __construct() {
  19. // same as $_SERVER['REQUEST_URI'], but should work under IIS 6.0
  20. $this->filepath = admin_url() . 'admin.php?page=' . $_GET['page'];
  21. //Look for POST updates
  22. if ( !empty($_POST) )
  23. $this->processor();
  24. }
  25. /**
  26. * Perform the upload and add a new hook for plugins
  27. *
  28. * @return void
  29. */
  30. function processor() {
  31. global $wpdb, $ngg;
  32. $defaultpath = $ngg->options['gallerypath'];
  33. if ($_POST['addgallery']){
  34. check_admin_referer('ngg_addgallery');
  35. if ( !nggGallery::current_user_can( 'NextGEN Add new gallery' ))
  36. wp_die(__('Cheatin&#8217; uh?'));
  37. $newgallery = esc_attr( $_POST['galleryname']);
  38. if ( !empty($newgallery) )
  39. nggAdmin::create_gallery($newgallery, $defaultpath);
  40. }
  41. if ($_POST['zipupload']){
  42. check_admin_referer('ngg_addgallery');
  43. if ( !nggGallery::current_user_can( 'NextGEN Upload a zip' ))
  44. wp_die(__('Cheatin&#8217; uh?'));
  45. if ($_FILES['zipfile']['error'] == 0 || (!empty($_POST['zipurl'])))
  46. nggAdmin::import_zipfile( intval( $_POST['zipgalselect'] ) );
  47. else
  48. nggGallery::show_error( __('Upload failed!','nggallery') );
  49. }
  50. if ($_POST['importfolder']){
  51. check_admin_referer('ngg_addgallery');
  52. if ( !nggGallery::current_user_can( 'NextGEN Import image folder' ))
  53. wp_die(__('Cheatin&#8217; uh?'));
  54. $galleryfolder = $_POST['galleryfolder'];
  55. if ( ( !empty($galleryfolder) ) AND ($defaultpath != $galleryfolder) )
  56. nggAdmin::import_gallery($galleryfolder);
  57. }
  58. if ($_POST['uploadimage']){
  59. check_admin_referer('ngg_addgallery');
  60. if ( !nggGallery::current_user_can( 'NextGEN Upload in all galleries' ))
  61. wp_die(__('Cheatin&#8217; uh?'));
  62. if ( $_FILES['imagefiles']['error'][0] == 0 )
  63. $messagetext = nggAdmin::upload_images();
  64. else
  65. nggGallery::show_error( __('Upload failed! ' . nggAdmin::decode_upload_error( $_FILES['imagefiles']['error'][0]),'nggallery') );
  66. }
  67. if (isset($_POST['swf_callback'])){
  68. if ($_POST['galleryselect'] == '0' )
  69. nggGallery::show_error(__('No gallery selected !','nggallery'));
  70. else {
  71. // get the path to the gallery
  72. $galleryID = (int) $_POST['galleryselect'];
  73. $gallerypath = $wpdb->get_var("SELECT path FROM $wpdb->nggallery WHERE gid = '$galleryID' ");
  74. nggAdmin::import_gallery($gallerypath);
  75. }
  76. }
  77. if ( isset($_POST['disable_flash']) ){
  78. check_admin_referer('ngg_addgallery');
  79. $ngg->options['swfUpload'] = false;
  80. update_option('ngg_options', $ngg->options);
  81. }
  82. if ( isset($_POST['enable_flash']) ){
  83. check_admin_referer('ngg_addgallery');
  84. $ngg->options['swfUpload'] = true;
  85. update_option('ngg_options', $ngg->options);
  86. }
  87. do_action( 'ngg_update_addgallery_page' );
  88. }
  89. /**
  90. * Render the page content
  91. *
  92. * @return void
  93. */
  94. function controller() {
  95. global $ngg, $nggdb;
  96. // check for the max image size
  97. $this->maxsize = nggGallery::check_memory_limit();
  98. //get all galleries (after we added new ones)
  99. $this->gallerylist = $nggdb->find_all_galleries('gid', 'DESC');
  100. $this->defaultpath = $ngg->options['gallerypath'];
  101. // link for the flash file
  102. $swf_upload_link = NGGALLERY_URLPATH . 'admin/upload.php';
  103. // get list of tabs
  104. $tabs = $this->tabs_order();
  105. ?>
  106. <?php if($ngg->options['swfUpload'] && !empty ($this->gallerylist) ) { ?>
  107. <!-- SWFUpload script -->
  108. <script type="text/javascript">
  109. var ngg_swf_upload;
  110. window.onload = function () {
  111. ngg_swf_upload = new SWFUpload({
  112. // Backend settings
  113. upload_url : "<?php echo esc_attr( $swf_upload_link ); ?>",
  114. flash_url : "<?php echo NGGALLERY_URLPATH; ?>admin/js/swfupload.swf",
  115. // Button Settings
  116. button_placeholder_id : "spanButtonPlaceholder",
  117. button_width: 300,
  118. button_height: 27,
  119. button_window_mode: SWFUpload.WINDOW_MODE.TRANSPARENT,
  120. button_cursor: SWFUpload.CURSOR.HAND,
  121. // File Upload Settings
  122. file_size_limit : "<?php echo wp_max_upload_size(); ?>b",
  123. file_types : "*.jpg;*.jpeg;*.gif;*.png;*.JPG;*.JPEG;*.GIF;*.PNG",
  124. file_types_description : "<?php _e('Image Files', 'nggallery') ;?>",
  125. // Queue handler
  126. file_queued_handler : fileQueued,
  127. // Upload handler
  128. upload_start_handler : uploadStart,
  129. upload_progress_handler : uploadProgress,
  130. upload_error_handler : uploadError,
  131. upload_success_handler : uploadSuccess,
  132. upload_complete_handler : uploadComplete,
  133. post_params : {
  134. "auth_cookie" : "<?php echo (is_ssl() ? $_COOKIE[SECURE_AUTH_COOKIE] : $_COOKIE[AUTH_COOKIE]); ?>",
  135. "logged_in_cookie": "<?php echo $_COOKIE[LOGGED_IN_COOKIE]; ?>",
  136. "_wpnonce" : "<?php echo wp_create_nonce('ngg_swfupload'); ?>",
  137. "galleryselect" : "0"
  138. },
  139. // i18names
  140. custom_settings : {
  141. "remove" : "<?php _e('remove', 'nggallery') ;?>",
  142. "browse" : "<?php _e('Browse...', 'nggallery') ;?>",
  143. "upload" : "<?php _e('Upload images', 'nggallery') ;?>"
  144. },
  145. // Debug settings
  146. debug: false
  147. });
  148. // on load change the upload to swfupload
  149. initSWFUpload();
  150. nggAjaxOptions = {
  151. header: "<?php _e('Upload images', 'nggallery') ;?>",
  152. maxStep: 100
  153. };
  154. };
  155. </script>
  156. <?php } else { ?>
  157. <!-- MultiFile script -->
  158. <script type="text/javascript">
  159. /* <![CDATA[ */
  160. jQuery(document).ready(function(){
  161. jQuery('#imagefiles').MultiFile({
  162. STRING: {
  163. remove:'[<?php _e('remove', 'nggallery') ;?>]'
  164. }
  165. });
  166. });
  167. /* ]]> */
  168. </script>
  169. <?php } ?>
  170. <!-- jQuery Tabs script -->
  171. <script type="text/javascript">
  172. /* <![CDATA[ */
  173. jQuery(document).ready(function(){
  174. jQuery('html,body').scrollTop(0);
  175. jQuery('#slider').tabs({ fxFade: true, fxSpeed: 'fast' });
  176. });
  177. // File Tree implementation
  178. jQuery(function() {
  179. jQuery("span.browsefiles").show().click(function(){
  180. jQuery("#file_browser").fileTree({
  181. script: "admin-ajax.php?action=ngg_file_browser&nonce=<?php echo wp_create_nonce( 'ngg-ajax' ) ;?>",
  182. root: jQuery("#galleryfolder").val(),
  183. }, function(folder) {
  184. jQuery("#galleryfolder").val( folder );
  185. });
  186. jQuery("#file_browser").show('slide');
  187. });
  188. });
  189. /* ]]> */
  190. </script>
  191. <div id="slider" class="wrap">
  192. <ul id="tabs">
  193. <?php
  194. foreach($tabs as $tab_key => $tab_name) {
  195. echo "\n\t\t<li><a href='#$tab_key'>$tab_name</a></li>";
  196. }
  197. ?>
  198. </ul>
  199. <?php
  200. foreach($tabs as $tab_key => $tab_name) {
  201. echo "\n\t<div id='$tab_key'>\n";
  202. // Looks for the internal class function, otherwise enable a hook for plugins
  203. if ( method_exists( $this, "tab_$tab_key" ))
  204. call_user_func( array( &$this , "tab_$tab_key") );
  205. else
  206. do_action( 'ngg_tab_content_' . $tab_key );
  207. echo "\n\t</div>";
  208. }
  209. ?>
  210. </div>
  211. <?php
  212. }
  213. /**
  214. * Create array for tabs and add a filter for other plugins to inject more tabs
  215. *
  216. * @return array $tabs
  217. */
  218. function tabs_order() {
  219. $tabs = array();
  220. if ( !empty ($this->gallerylist) )
  221. $tabs['uploadimage'] = __( 'Upload Images', 'nggallery' );
  222. if ( nggGallery::current_user_can( 'NextGEN Add new gallery' ))
  223. $tabs['addgallery'] = __('Add new gallery', 'nggallery');
  224. if ( wpmu_enable_function('wpmuZipUpload') && nggGallery::current_user_can( 'NextGEN Upload a zip' ) )
  225. $tabs['zipupload'] = __('Upload a Zip-File', 'nggallery');
  226. if ( wpmu_enable_function('wpmuImportFolder') && nggGallery::current_user_can( 'NextGEN Import image folder' ) )
  227. $tabs['importfolder'] = __('Import image folder', 'nggallery');
  228. $tabs = apply_filters('ngg_addgallery_tabs', $tabs);
  229. return $tabs;
  230. }
  231. function tab_addgallery() {
  232. ?>
  233. <!-- create gallery -->
  234. <h2><?php _e('Add new gallery', 'nggallery') ;?></h2>
  235. <form name="addgallery" id="addgallery_form" method="POST" action="<?php echo $this->filepath; ?>" accept-charset="utf-8" >
  236. <?php wp_nonce_field('ngg_addgallery') ?>
  237. <table class="form-table">
  238. <tr valign="top">
  239. <th scope="row"><?php _e('New Gallery', 'nggallery') ;?>:</th>
  240. <td><input type="text" size="35" name="galleryname" value="" /><br />
  241. <?php if(!is_multisite()) { ?>
  242. <?php _e('Create a new , empty gallery below the folder', 'nggallery') ;?> <strong><?php echo $this->defaultpath ?></strong><br />
  243. <?php } ?>
  244. <i>( <?php _e('Allowed characters for file and folder names are', 'nggallery') ;?>: a-z, A-Z, 0-9, -, _ )</i></td>
  245. </tr>
  246. <?php do_action('ngg_add_new_gallery_form'); ?>
  247. </table>
  248. <div class="submit"><input class="button-primary" type="submit" name= "addgallery" value="<?php _e('Add gallery', 'nggallery') ;?>"/></div>
  249. </form>
  250. <?php
  251. }
  252. function tab_zipupload() {
  253. ?>
  254. <!-- zip-file operation -->
  255. <h2><?php _e('Upload a Zip-File', 'nggallery') ;?></h2>
  256. <form name="zipupload" id="zipupload_form" method="POST" enctype="multipart/form-data" action="<?php echo $this->filepath.'#zipupload'; ?>" accept-charset="utf-8" >
  257. <?php wp_nonce_field('ngg_addgallery') ?>
  258. <table class="form-table">
  259. <tr valign="top">
  260. <th scope="row"><?php _e('Select Zip-File', 'nggallery') ;?>:</th>
  261. <td><input type="file" name="zipfile" id="zipfile" size="35" class="uploadform"/><br />
  262. <?php _e('Upload a zip file with images', 'nggallery') ;?></td>
  263. </tr>
  264. <?php if (function_exists('curl_init')) : ?>
  265. <tr valign="top">
  266. <th scope="row"><?php _e('or enter a Zip-File URL', 'nggallery') ;?>:</th>
  267. <td><input type="text" name="zipurl" id="zipurl" size="35" class="uploadform"/><br />
  268. <?php _e('Import a zip file with images from a url', 'nggallery') ;?></td>
  269. </tr>
  270. <?php endif; ?>
  271. <tr valign="top">
  272. <th scope="row"><?php _e('in to', 'nggallery') ;?></th>
  273. <td><select name="zipgalselect">
  274. <option value="0" ><?php _e('a new gallery', 'nggallery') ?></option>
  275. <?php
  276. foreach($this->gallerylist as $gallery) {
  277. if ( !nggAdmin::can_manage_this_gallery($gallery->author) )
  278. continue;
  279. $name = ( empty($gallery->title) ) ? $gallery->name : $gallery->title;
  280. echo '<option value="' . $gallery->gid . '" >' . $gallery->gid . ' - ' . $name . '</option>' . "\n";
  281. }
  282. ?>
  283. </select>
  284. <br /><?php echo $this->maxsize; ?>
  285. <br /><?php echo _e('Note : The upload limit on your server is ','nggallery') . "<strong>" . ini_get('upload_max_filesize') . "Byte</strong>\n"; ?>
  286. <br /><?php if ( (is_multisite()) && wpmu_enable_function('wpmuQuotaCheck') ) display_space_usage(); ?></td>
  287. </tr>
  288. </table>
  289. <div class="submit"><input class="button-primary" type="submit" name= "zipupload" value="<?php _e('Start upload', 'nggallery') ;?>"/></div>
  290. </form>
  291. <?php
  292. }
  293. function tab_importfolder() {
  294. ?>
  295. <!-- import folder -->
  296. <h2><?php _e('Import image folder', 'nggallery') ;?></h2>
  297. <form name="importfolder" id="importfolder_form" method="POST" action="<?php echo $this->filepath.'#importfolder'; ?>" accept-charset="utf-8" >
  298. <?php wp_nonce_field('ngg_addgallery') ?>
  299. <table class="form-table">
  300. <tr valign="top">
  301. <th scope="row"><?php _e('Import from Server path:', 'nggallery') ;?></th>
  302. <td><input type="text" size="35" id="galleryfolder" name="galleryfolder" value="<?php echo $this->defaultpath; ?>" /><span class="browsefiles button" style="display:none"><?php _e('Browse...', 'nggallery'); ?></span><br />
  303. <div id="file_browser"></div>
  304. <br /><i>( <?php _e('Note : Change the default path in the gallery settings', 'nggallery') ;?> )</i>
  305. <br /><?php echo $this->maxsize; ?>
  306. <?php if (SAFE_MODE) {?><br /><?php _e(' Please note : For safe-mode = ON you need to add the subfolder thumbs manually', 'nggallery') ;?><?php }; ?></td>
  307. </tr>
  308. </table>
  309. <div class="submit"><input class="button-primary" type="submit" name= "importfolder" value="<?php _e('Import folder', 'nggallery') ;?>"/></div>
  310. </form>
  311. <?php
  312. }
  313. function tab_uploadimage() {
  314. global $ngg;
  315. ?>
  316. <!-- upload images -->
  317. <h2><?php _e('Upload Images', 'nggallery') ;?></h2>
  318. <form name="uploadimage" id="uploadimage_form" method="POST" enctype="multipart/form-data" action="<?php echo $this->filepath.'#uploadimage'; ?>" accept-charset="utf-8" >
  319. <?php wp_nonce_field('ngg_addgallery') ?>
  320. <table class="form-table">
  321. <tr valign="top">
  322. <th scope="row"><?php _e('Upload image', 'nggallery') ;?></th>
  323. <td><span id='spanButtonPlaceholder'></span><input type="file" name="imagefiles[]" id="imagefiles" size="35" class="imagefiles"/></td>
  324. </tr>
  325. <tr valign="top">
  326. <th scope="row"><?php _e('in to', 'nggallery') ;?></th>
  327. <td><select name="galleryselect" id="galleryselect">
  328. <option value="0" ><?php _e('Choose gallery', 'nggallery') ?></option>
  329. <?php
  330. foreach($this->gallerylist as $gallery) {
  331. //special case : we check if a user has this cap, then we override the second cap check
  332. if ( !current_user_can( 'NextGEN Upload in all galleries' ) )
  333. if ( !nggAdmin::can_manage_this_gallery($gallery->author) )
  334. continue;
  335. $name = ( empty($gallery->title) ) ? $gallery->name : $gallery->title;
  336. echo '<option value="' . $gallery->gid . '" >' . $gallery->gid . ' - ' . $name . '</option>' . "\n";
  337. } ?>
  338. </select>
  339. <br /><?php echo $this->maxsize; ?>
  340. <br /><?php if ((is_multisite()) && wpmu_enable_function('wpmuQuotaCheck')) display_space_usage(); ?></td>
  341. </tr>
  342. </table>
  343. <div class="submit">
  344. <?php if ($ngg->options['swfUpload']) { ?>
  345. <input type="submit" name="disable_flash" id="disable_flash" title="<?php _e('The batch upload requires Adobe Flash 10, disable it if you have problems','nggallery') ?>" value="<?php _e('Disable flash upload', 'nggallery') ;?>" />
  346. <?php } else { ?>
  347. <input type="submit" name="enable_flash" id="enable_flash" title="<?php _e('Upload multiple files at once by ctrl/shift-selecting in dialog','nggallery') ?>" value="<?php _e('Enable flash based upload', 'nggallery') ;?>" />
  348. <?php } ?>
  349. <input class="button-primary" type="submit" name="uploadimage" id="uploadimage_btn" value="<?php _e('Upload images', 'nggallery') ;?>" />
  350. </div>
  351. </form>
  352. <?php
  353. }
  354. }
  355. ?>