nggAdmin

NggAdmin - Class for admin operation.

Defined (1)

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

/products/photocrati_nextgen/modules/ngglegacy/admin/functions.php  
  1. class nggAdmin{ 
  2.  
  3. /** 
  4. * create a new gallery & folder 
  5. * @class nggAdmin 
  6. * @param string $name of the gallery 
  7. * @param string $defaultpath 
  8. * @param bool $output if the function should show an error messsage or not 
  9. * @return 
  10. */ 
  11. static function create_gallery($title, $defaultpath, $output = true) { 
  12.  
  13. global $user_ID; 
  14. $fs = C_Fs::get_instance(); 
  15. $storage = C_Gallery_Storage::get_instance(); 
  16.  
  17. // get the current user ID 
  18. wp_get_current_user(); 
  19.  
  20. //cleanup pathname 
  21. $name = sanitize_file_name( sanitize_title($title) ); 
  22. $name = apply_filters('ngg_gallery_name', $name); 
  23. $txt = ''; 
  24.  
  25. $galleryObj = new stdClass; 
  26. $galleryObj->path = ''; 
  27. $nggRoot = $storage->get_gallery_abspath($galleryObj); 
  28.  
  29. // No gallery name ? 
  30. if ( empty($name) ) { 
  31. if ($output) nggGallery::show_error( __('No valid gallery name!', 'nggallery') ); 
  32. return false; 
  33.  
  34. $galleryObj = new stdClass; 
  35. $galleryObj->path = $fs->join_paths($defaultpath, $name); 
  36. $gallery_path = $storage->get_gallery_abspath($galleryObj); 
  37.  
  38. // check for main folder 
  39. if ( !is_dir($nggRoot) ) { 
  40. if ( !wp_mkdir_p( $nggRoot ) ) { 
  41. $txt = __('Directory', 'nggallery').' <strong>' . esc_html( $nggRoot ) . '</strong> '.__('didn\'t exist. Please create first the main gallery folder ', 'nggallery').'!<br />'; 
  42. $txt .= __('Check this link, if you didn\'t know how to set the permission :', 'nggallery').' <a href="http://codex.wordpress.org/Changing_File_Permissions">http://codex.wordpress.org/Changing_File_Permissions</a> '; 
  43. if ($output) nggGallery::show_error($txt); 
  44. return false; 
  45.  
  46. // 1. Check for existing folder 
  47. if ( is_dir($gallery_path) && !(SAFE_MODE) ) { 
  48. $suffix = 1; 
  49. do { 
  50. $alt_name = substr ($name, 0, 200 - ( strlen( $suffix ) + 1 ) ) . "_$suffix"; 
  51. $galleryObj->path = $fs->join_paths($defaultpath, $alt_name); 
  52. $gallery_path = $storage->get_gallery_abspath($galleryObj); 
  53. $dir_check = is_dir($gallery_path); 
  54. $suffix++; 
  55. } while ( $dir_check ); 
  56. $name = $alt_name; 
  57.  
  58. $thumb_path = $fs->join_paths($gallery_path, 'thumbs'); 
  59.  
  60. // 2. Create new gallery folder 
  61. if ( !wp_mkdir_p ($gallery_path) ) 
  62. $txt = __('Unable to create directory ', 'nggallery') . esc_html($gallery_path) . '!<br />'; 
  63.  
  64. // 3. Check folder permission 
  65. if ( !is_writeable($gallery_path) ) 
  66. $txt .= __('Directory', 'nggallery').' <strong>' . esc_html($gallery_path) . '</strong> '.__('is not writeable !', 'nggallery').'<br />'; 
  67.  
  68. // 4. Now create thumbnail folder inside 
  69. if ( !is_dir($thumb_path) ) { 
  70. if ( !wp_mkdir_p ($thumb_path) ) 
  71. $txt .= __('Unable to create directory ', 'nggallery').' <strong>' . esc_html($thumb_path) . '/thumbs !</strong>'; 
  72.  
  73. if (SAFE_MODE) { 
  74. $help = __('The server setting Safe-Mode is on !', 'nggallery'); 
  75. $help .= '<br />'.__('If you have problems, please create directory', 'nggallery').' <strong>' . esc_html($gallery_path) . '</strong> '; 
  76. $help .= __('and the thumbnails directory', 'nggallery').' <strong>' . esc_html($thumb_path) . '</strong> '.__('with permission 777 manually !', 'nggallery'); 
  77. if ($output) nggGallery::show_message($help); 
  78.  
  79. // show a error message 
  80. if ( !empty($txt) ) { 
  81. if (SAFE_MODE) { 
  82. // for safe_mode , better delete folder, both folder must be created manually 
  83. @rmdir($thumb_path); 
  84. @rmdir($gallery_path); 
  85. if ($output) nggGallery::show_error($txt); 
  86. return false; 
  87.  
  88. // now add the gallery to the database 
  89. $galleryID = nggdb::add_gallery($title, $defaultpath . $name, '', 0, 0, $user_ID ); 
  90. // here you can inject a custom function 
  91. do_action('ngg_created_new_gallery', $galleryID); 
  92.  
  93. // return only the id if defined 
  94. if ($output == false) 
  95. return $galleryID; 
  96.  
  97. if ($galleryID != false && !isset($_REQUEST['attach_to_post'])) 
  98. $url = admin_url() . 'admin.php?page=nggallery-manage-gallery&mode=edit&gid=' . $galleryID; 
  99. $message = sprintf(__('Gallery successfully created. <a href="%s" target="_blank">Manage gallery</a>', 'nggallery'), $url); 
  100. if ($output) 
  101. nggGallery::show_message($message, 'gallery_created_msg'); 
  102. return true; 
  103.  
  104. /** 
  105. * Scan folder for new images 
  106. * @class nggAdmin 
  107. * @param string $dirname 
  108. * @return array $files list of image filenames 
  109. */ 
  110. static function scandir( $dirname = '.' ) { 
  111. $ext = apply_filters('ngg_allowed_file_types', array('jpeg', 'jpg', 'png', 'gif') ); 
  112.  
  113. $files = array(); 
  114. if( $handle = opendir( $dirname ) ) { 
  115. while( false !== ( $file = readdir( $handle ) ) ) { 
  116. $info = M_I18n::mb_pathinfo( $file ); 
  117. // just look for images with the correct extension 
  118. if ( isset($info['extension']) ) { 
  119. if ( in_array( strtolower($info['extension']), $ext) ) { 
  120. if (!seems_utf8($file)) { 
  121. $file = utf8_encode( $file ); 
  122.  
  123. $files[] = $file; 
  124.  
  125. closedir( $handle ); 
  126. sort( $files ); 
  127. return ( $files ); 
  128.  
  129. /** 
  130. * nggAdmin::createThumbnail() - function to create or recreate a thumbnail 
  131. * @class nggAdmin 
  132. * @param object | int $image contain all information about the image or the id 
  133. * @return string result code 
  134. * @since v1.0.0 
  135. */ 
  136. static function create_thumbnail($image) { 
  137.  
  138. if (is_object($image)) { 
  139. if (isset($image->id)) { 
  140. $image = $image->id; 
  141. elseif (isset($image->pid)) { 
  142. $image = $image->pid; 
  143. $storage = C_Gallery_Storage::get_instance(); 
  144.  
  145. // XXX NextGEN Legacy wasn't handling watermarks or reflections at this stage, so we're forcefully disabling them to maintain compatibility 
  146. $params = array('watermark' => false, 'reflection' => false); 
  147. $result = $storage->generate_thumbnail($image, $params); 
  148.  
  149. if (!$result) 
  150. // XXX there isn't any error handling unfortunately at the moment in the generate_thumbnail functions, need a way to return proper error status 
  151. return __('Error while creating thumbnail.', 'nggallery'); 
  152.  
  153. // success 
  154. return '1'; 
  155.  
  156. /** 
  157. * nggAdmin::resize_image() - create a new image, based on the height /width 
  158. * @class nggAdmin 
  159. * @param object | int $image contain all information about the image or the id 
  160. * @param integer $width optional 
  161. * @param integer $height optional 
  162. * @return string result code 
  163. */ 
  164. static function resize_image($image, $width = 0, $height = 0) 
  165. if (is_object($image)) { 
  166. if (isset($image->id)) { 
  167. $image = $image->id; 
  168. elseif (isset($image->pid)) { 
  169. $image = $image->pid; 
  170.  
  171. $storage = C_Gallery_Storage::get_instance(); 
  172. // XXX maybe get rid of this...it's needed to get width/height defaults, placing these directly in generate_image_size could have unwanted consequences 
  173. $settings = C_NextGen_Settings::get_instance(); 
  174.  
  175. // XXX NextGEN Legacy wasn't handling watermarks or reflections at this stage, so we're forcefully disabling them to maintain compatibility 
  176. $params = array('watermark' => false, 'reflection' => false); 
  177.  
  178. if ($width > 0) { 
  179. $params['width'] = $width; 
  180. else { 
  181. $params['width'] = $settings->imgWidth; 
  182.  
  183. if ($height > 0) { 
  184. $params['height'] = $height; 
  185. else { 
  186. $params['height'] = $settings->imgHeight; 
  187.  
  188. $result = $storage->generate_image_size($image, 'full', $params); 
  189.  
  190. if (!$result) 
  191. // XXX there isn't any error handling unfortunately at the moment in the generate_thumbnail functions, need a way to return proper error status 
  192. return __('Error while resizing image.', 'nggallery'); 
  193.  
  194. // success 
  195. return '1'; 
  196.  
  197. /** 
  198. * Rotated/Flip an image based on the orientation flag or a definded angle 
  199. * @param int|object $image 
  200. * @param string (optional) $dir, CW (clockwise)or CCW (counter clockwise), if set to false, the exif flag will be used 
  201. * @param string (optional) $flip, could be either false | V (flip vertical) | H (flip horizontal) 
  202. * @return string result code 
  203. */ 
  204. static function rotate_image($image, $dir = false, $flip = false) 
  205. if (is_object($image)) { 
  206. if (isset($image->id)) $image = $image->id; 
  207. elseif (isset($image->pid)) $image = $image->pid; 
  208. $storage = C_Gallery_Storage::get_instance(); 
  209.  
  210. // XXX NextGEN Legacy wasn't handling watermarks or reflections at this stage, so we're forcefully disabling them to maintain compatibility 
  211. $params = array('watermark' => false, 'reflection' => false); 
  212. $rotation = null; 
  213.  
  214. if ($dir === 'CW') { 
  215. $rotation = 90; 
  216. else if ($dir === 'CCW') { 
  217. $rotation = -90; 
  218. // if you didn't define a rotation, we look for the orientation flag in EXIF 
  219. else if ($dir === false) { 
  220. $meta = new nggMeta( $image); 
  221. $exif = $meta->get_EXIF(); 
  222.  
  223. if (isset($exif['Orientation'])) { 
  224.  
  225. switch ($exif['Orientation']) { 
  226. case 5 : // vertical flip + 90 rotate right 
  227. $flip = 'V'; 
  228. case 6 : // 90 rotate right 
  229. $rotation = 90; 
  230. break; 
  231. case 7 : // horizontal flip + 90 rotate right 
  232. $flip = 'H'; 
  233. case 8 : // 90 rotate left 
  234. $rotation = -90; 
  235. break; 
  236. case 4 : // vertical flip 
  237. $flip = 'V'; 
  238. break; 
  239. case 3 : // 180 rotate left 
  240. $rotation = -180; 
  241. break; 
  242. case 2 : // horizontal flip 
  243. $flip = 'H'; 
  244. break; 
  245. case 1 : // no action in the case it doesn't need a rotation 
  246. default: 
  247. return '0'; 
  248. break; 
  249. } else 
  250. return '0'; 
  251.  
  252. if ($rotation != null) { 
  253. $params['rotation'] = $rotation; 
  254.  
  255. if ($flip != null) { 
  256. $params['flip'] = $flip; 
  257.  
  258. $result = $storage->generate_image_size($image, 'full', $params); 
  259.  
  260. if (!$result) 
  261. // XXX there isn't any error handling unfortunately at the moment in the generate_thumbnail functions, need a way to return proper error status 
  262. return __('Error while rotating image.', 'nggallery'); 
  263.  
  264. // success 
  265. return '1'; 
  266.  
  267. /** 
  268. * nggAdmin::set_watermark() - set the watermark for the image 
  269. * @class nggAdmin 
  270. * @param object | int $image contain all information about the image or the id 
  271. * @return string result code 
  272. */ 
  273. static function set_watermark($image) { 
  274.  
  275. if (is_object($image)) { 
  276. if (isset($image->id)) { 
  277. $image = $image->id; 
  278. elseif (isset($image->pid)) { 
  279. $image = $image->pid; 
  280.  
  281. $storage = C_Gallery_Storage::get_instance(); 
  282.  
  283. // XXX NextGEN Legacy was only handling watermarks at this stage, so we're forcefully disabling all else 
  284. $params = array('watermark' => true, 'reflection' => false, 'crop' => false); 
  285. $result = $storage->generate_image_size($image, 'full', $params); 
  286.  
  287. if (!$result) 
  288. // XXX there isn't any error handling unfortunately at the moment in the generate_thumbnail functions, need a way to return proper error status 
  289. return __('Error while applying watermark to image.', 'nggallery'); 
  290.  
  291. // success 
  292. return '1'; 
  293.  
  294. /** 
  295. * Recover image from backup copy and reprocess it 
  296. * @class nggAdmin 
  297. * @since 1.5.0 
  298. * @param object | int $image contain all information about the image or the id 
  299. * @return string result code 
  300. */ 
  301.  
  302. static function recover_image($image) { 
  303.  
  304. return C_Gallery_Storage::get_instance()->recover_image($image); 
  305.  
  306. /** 
  307. * Add images to database 
  308. * @class nggAdmin 
  309. * @param int $galleryID 
  310. * @param array $imageslist 
  311. * @return array $image_ids Id's which are sucessful added 
  312. */ 
  313. static function add_Images($galleryID, $imageslist) { 
  314.  
  315. global $wpdb, $ngg; 
  316.  
  317. $image_ids = array(); 
  318.  
  319. if ( is_array($imageslist) ) { 
  320. foreach($imageslist as $picture) { 
  321.  
  322. // filter function to rename/change/modify image before 
  323. $picture = apply_filters('ngg_pre_add_new_image', $picture, $galleryID); 
  324.  
  325. // strip off the extension of the filename 
  326. $path_parts = M_I18n::mb_pathinfo( $picture ); 
  327. $alttext = ( !isset($path_parts['filename']) ) ? substr($path_parts['basename'], 0, strpos($path_parts['basename'], '.')) : $path_parts['filename']; 
  328. // save it to the database 
  329. $pic_id = nggdb::add_image( $galleryID, $picture, '', $alttext ); 
  330.  
  331. if (C_NextGen_Settings::get_instance()->imgBackup && !empty($pic_id)) 
  332. $storage = C_Gallery_Storage::get_instance(); 
  333. $storage->backup_image($pic_id); 
  334.  
  335. if ( !empty($pic_id) ) 
  336. $image_ids[] = $pic_id; 
  337.  
  338. // add the metadata 
  339. nggAdmin::import_MetaData( $pic_id ); 
  340.  
  341. // auto rotate 
  342. nggAdmin::rotate_image( $pic_id ); 
  343.  
  344. // Autoresize image if required 
  345. if ($ngg->options['imgAutoResize']) { 
  346. $imagetmp = nggdb::find_image( $pic_id ); 
  347. $sizetmp = @getimagesize ( $imagetmp->imagePath ); 
  348. $widthtmp = $ngg->options['imgWidth']; 
  349. $heighttmp = $ngg->options['imgHeight']; 
  350. if (($sizetmp[0] > $widthtmp && $widthtmp) || ($sizetmp[1] > $heighttmp && $heighttmp)) { 
  351. nggAdmin::resize_image( $pic_id ); 
  352.  
  353. // action hook for post process after the image is added to the database 
  354. $image = array( 'id' => $pic_id, 'filename' => $picture, 'galleryID' => $galleryID); 
  355. do_action('ngg_added_new_image', $image); 
  356.  
  357. } // is_array 
  358.  
  359. // delete dirsize after adding new images 
  360. delete_transient( 'dirsize_cache' ); 
  361.  
  362. do_action('ngg_after_new_images_added', $galleryID, $image_ids ); 
  363.  
  364. return $image_ids; 
  365.  
  366.  
  367. /** 
  368. * Import some meta data into the database (if avialable) 
  369. * @class nggAdmin 
  370. * @param array|int $imagesIds 
  371. * @return string result code 
  372. */ 
  373. static function import_MetaData($imagesIds) { 
  374.  
  375. global $wpdb; 
  376.  
  377. require_once(NGGALLERY_ABSPATH . '/lib/image.php'); 
  378.  
  379. if (!is_array($imagesIds)) 
  380. $imagesIds = array($imagesIds); 
  381.  
  382. foreach($imagesIds as $imageID) { 
  383.  
  384. // Get the image 
  385. $image = NULL; 
  386. if (is_int($imageID)) { 
  387. $image = C_Image_Mapper::get_instance()->find($imageID); 
  388. else $image = $imageID; 
  389.  
  390. if ($image) { 
  391.  
  392. $meta = nggAdmin::get_MetaData( $image); 
  393.  
  394. // get the title 
  395. $alttext = empty( $meta['title'] ) ? $image->alttext : $meta['title']; 
  396.  
  397. // get the caption / description field 
  398. $description = empty( $meta['caption'] ) ? $image->description : $meta['caption']; 
  399.  
  400. // get the file date/time from exif 
  401. $timestamp = $meta['timestamp']; 
  402.  
  403. // first update database 
  404. $result = $wpdb->query( 
  405. $wpdb->prepare("UPDATE $wpdb->nggpictures SET 
  406. alttext = %s,  
  407. description = %s,  
  408. imagedate = %s 
  409. WHERE pid = %d", $alttext, $description, $timestamp, $image->pid) ); 
  410.  
  411. if ($result === false) 
  412. return ' <strong>' . esc_html( $image->filename ) . ' ' . __('(Error : Couldn\'t not update data base)', 'nggallery') . '</strong>'; 
  413.  
  414. //this flag will inform us that the import is already one time performed 
  415. $meta['common']['saved'] = true; 
  416. $result = nggdb::update_image_meta($image->pid, $meta['common']); 
  417.  
  418. if ($result === false) 
  419. return ' <strong>' . esc_html( $image->filename ) . ' ' . __('(Error : Couldn\'t not update meta data)', 'nggallery') . '</strong>'; 
  420.  
  421. // add the tags if we found some 
  422. if ($meta['keywords']) { 
  423. $taglist = explode(', ', $meta['keywords']); 
  424. wp_set_object_terms($image->pid, $taglist, 'ngg_tag'); 
  425.  
  426. } else 
  427. return ' <strong>' . esc_html( $image->filename ) . ' ' . __('(Error : Couldn\'t not find image)', 'nggallery') . '</strong>';// error check 
  428.  
  429. return '1'; 
  430.  
  431. /** 
  432. * nggAdmin::get_MetaData() 
  433. * @class nggAdmin 
  434. * @require NextGEN Meta class 
  435. * @param int $id image ID 
  436. * @return array metadata 
  437. */ 
  438. static function get_MetaData($image_or_id) { 
  439.  
  440. require_once(NGGALLERY_ABSPATH . '/lib/meta.php'); 
  441.  
  442. $meta = array(); 
  443.  
  444. $pdata = new nggMeta($image_or_id); 
  445.  
  446. $meta['title'] = trim ( $pdata->get_META('title') ); 
  447. $meta['caption'] = trim ( $pdata->get_META('caption') ); 
  448. $meta['keywords'] = trim ( $pdata->get_META('keywords') ); 
  449. $meta['timestamp'] = $pdata->get_date_time(); 
  450. // this contain other useful meta information 
  451. $meta['common'] = $pdata->get_common_meta(); 
  452. // hook for addon plugin to add more meta fields 
  453. $meta = apply_filters('ngg_get_image_metadata', $meta, $pdata); 
  454.  
  455. return $meta; 
  456.  
  457.  
  458. /** 
  459. * Maybe import some meta data to the database. The functions checks the flag 'saved' 
  460. * and if based on compat reason (pre V1.4.0) we save then some meta datas to the database 
  461. * @since V1.4.0 
  462. * @param int $id 
  463. * @return result 
  464. */ 
  465. function maybe_import_meta( $image_or_id ) { 
  466.  
  467. require_once(NGGALLERY_ABSPATH . '/lib/meta.php'); 
  468. $id = is_int($image_or_id) ? $image_or_id : $image_or_id->{$image_or_id->id_field}; 
  469. $meta_obj = new nggMeta( $image_or_id ); 
  470.  
  471. if ( $meta_obj->image->meta_data['saved'] != true ) { 
  472. $common = $meta_obj->get_common_meta(); 
  473. //this flag will inform us that the import is already one time performed 
  474. $common['saved'] = true; 
  475. $result = nggdb::update_image_meta($id, $common); 
  476. } else 
  477. return false; 
  478.  
  479. return $result; 
  480.  
  481.  
  482. /** 
  483. * nggAdmin::import_gallery() 
  484. * TODO: Check permission of existing thumb folder & images 
  485. * @class nggAdmin 
  486. * @param string $galleryfolder contains relative path to the gallery itself 
  487. * @return void 
  488. */ 
  489. static function import_gallery($galleryfolder, $gallery_id=NULL) { 
  490.  
  491. global $wpdb, $user_ID; 
  492.  
  493. // get the current user ID 
  494. wp_get_current_user(); 
  495.  
  496. $created_msg = ''; 
  497.  
  498. // remove trailing slash at the end, if somebody use it 
  499. $galleryfolder = untrailingslashit($galleryfolder); 
  500.  
  501. $fs = C_Fs::get_instance(); 
  502. if (is_null($gallery_id)) { 
  503. $gallerypath = $fs->join_paths($fs->get_document_root('content'), $galleryfolder); 
  504. } else { 
  505. $storage = C_Gallery_Storage::get_instance(); 
  506. $gallerypath = $storage->get_gallery_abspath($gallery_id); 
  507.  
  508. if (!is_dir($gallerypath)) { 
  509. nggGallery::show_error(sprintf(__("Directory <strong>%s</strong> doesn`t exist!", 'nggallery'), esc_html($gallerypath))); 
  510. return ; 
  511.  
  512. // read list of images 
  513. $new_imageslist = nggAdmin::scandir($gallerypath); 
  514.  
  515. if (empty($new_imageslist)) { 
  516. nggGallery::show_message(sprintf(__("Directory <strong>%s</strong> contains no pictures", 'nggallery'), esc_html($gallerypath))); 
  517. return; 
  518.  
  519. // take folder name as gallery name 
  520. $galleryname = basename($galleryfolder); 
  521. $galleryname = apply_filters('ngg_gallery_name', $galleryname); 
  522.  
  523. // check for existing gallery folder 
  524. if (is_null($gallery_id)) 
  525. $gallery_id = $wpdb->get_var("SELECT gid FROM $wpdb->nggallery WHERE path = '$galleryfolder' "); 
  526.  
  527. if (!$gallery_id) { 
  528. // now add the gallery to the database 
  529. $gallery_id = nggdb::add_gallery( $galleryname, $galleryfolder, '', 0, 0, $user_ID ); 
  530. if (!$gallery_id) { 
  531. nggGallery::show_error(__('Database error. Could not add gallery!', 'nggallery')); 
  532. return; 
  533. else { 
  534. do_action('ngg_created_new_gallery', $gallery_id); 
  535. $created_msg = sprintf( 
  536. _n("Gallery <strong>%s</strong> successfully created!", 'Galleries <strong>%s</strong> successfully created!', 1, 'nggallery'),  
  537. esc_html($galleryname) 
  538. ); 
  539.  
  540. // Look for existing image list 
  541. $old_imageslist = $wpdb->get_col("SELECT filename FROM $wpdb->nggpictures WHERE galleryid = '$gallery_id' "); 
  542.  
  543. // if no images are there, create empty array 
  544. if ($old_imageslist == NULL) 
  545. $old_imageslist = array(); 
  546.  
  547. // check difference 
  548. $new_images = array_diff($new_imageslist, $old_imageslist); 
  549.  
  550. // all images must be valid files 
  551. foreach($new_images as $key => $picture) { 
  552.  
  553. // filter function to rename/change/modify image before 
  554. $picture = apply_filters('ngg_pre_add_new_image', $picture, $gallery_id); 
  555. $new_images[$key] = $picture; 
  556.  
  557. if (!@getimagesize($gallerypath . '/' . $picture) ) { 
  558. unset($new_images[$key]); 
  559. @unlink($gallerypath . '/' . $picture); 
  560.  
  561. // add images to database 
  562. $image_ids = nggAdmin::add_Images($gallery_id, $new_images); 
  563. do_action('ngg_after_new_images_added', $gallery_id, $image_ids); 
  564.  
  565. //add the preview image if needed 
  566. nggAdmin::set_gallery_preview ( $gallery_id ); 
  567.  
  568. // now create thumbnails 
  569. nggAdmin::do_ajax_operation( 'create_thumbnail' , $image_ids, __('Create new thumbnails', 'nggallery') ); 
  570.  
  571. //TODO:Message will not shown, because AJAX routine require more time, message should be passed to AJAX 
  572. $message = $created_msg . sprintf(_n('%s picture successfully added', '%s pictures successfully added', count($image_ids), 'nggallery'), count($image_ids)); 
  573. $message .= ' [<a href="' . admin_url() . 'admin.php?page=nggallery-manage-gallery&mode=edit&gid=' . $gallery_id . '" >'; 
  574. $message .= __('Edit gallery', 'nggallery'); 
  575. $message .= '</a>]'; 
  576.  
  577. nggGallery::show_message($message); 
  578.  
  579. return; 
  580.  
  581. /** 
  582. * Capability check. Check is the ID fit's to the user_ID 
  583. * @class nggAdmin 
  584. * @param int $check_ID is the user_id 
  585. * @return bool $result 
  586. */ 
  587. static function can_manage_this_gallery($check_ID) { 
  588.  
  589. global $user_ID, $wp_roles; 
  590.  
  591. if ( !current_user_can('NextGEN Manage others gallery') ) { 
  592. // get the current user ID 
  593. wp_get_current_user(); 
  594.  
  595. if ( $user_ID != $check_ID) 
  596. return false; 
  597.  
  598. return true; 
  599.  
  600.  
  601. /** 
  602. * Initate the Ajax operation 
  603. * @class nggAdmin 
  604. * @param string $operation name of the function which should be executed 
  605. * @param array $image_array 
  606. * @param string $title name of the operation 
  607. * @return string the javascript output 
  608. */ 
  609. static function do_ajax_operation( $operation, $image_array, $title = '' ) { 
  610.  
  611. if ( !is_array($image_array) || empty($image_array) ) 
  612. return; 
  613.  
  614. $js_array = implode('", "', $image_array); 
  615.  
  616. // send out some JavaScript, which initate the ajax operation 
  617. ?> 
  618. <script type="text/javascript"> 
  619.  
  620. Images = new Array("<?php echo $js_array; ?>"); 
  621.  
  622. nggAjaxOptions = { 
  623. operation: "<?php echo $operation; ?>",  
  624. ids: Images,  
  625. header: "<?php echo $title; ?>",  
  626. maxStep: Images.length 
  627. }; 
  628.  
  629. jQuery(document).ready( function() { 
  630. nggProgressBar.init( nggAjaxOptions ); 
  631. nggAjax.init( nggAjaxOptions ); 
  632. } ); 
  633. </script> 
  634.  
  635. <?php 
  636.  
  637. /** 
  638. * nggAdmin::set_gallery_preview() - define a preview pic after the first upload, can be changed in the gallery settings 
  639. * @class nggAdmin 
  640. * @param int $galleryID 
  641. * @return void 
  642. */ 
  643. static function set_gallery_preview( $galleryID ) 
  644. $gallery_mapper = C_Gallery_Mapper::get_instance(); 
  645. if (($gallery = $gallery_mapper->find($galleryID))) { 
  646. if (!$gallery->previewpic) { 
  647. $image_mapper = C_Image_Mapper::get_instance(); 
  648. if (($image = $image_mapper->select()->where(array('galleryid = %d', $galleryID))->where(array('exclude != 1'))-> 
  649. order_by($image_mapper->get_primary_key_column())->limit(1)->run_query())) { 
  650. $gallery->previewpic = $image->{$image->id_field}; 
  651. $gallery_mapper->save($gallery); 
  652.  
  653. /** 
  654. * Return a JSON coded array of Image ids for a requested gallery 
  655. * @class nggAdmin 
  656. * @param int $galleryID 
  657. * @return arry (JSON) 
  658. */ 
  659. static function get_image_ids( $galleryID ) { 
  660.  
  661. if ( !function_exists('json_encode') ) 
  662. return(-2); 
  663.  
  664. $gallery = nggdb::get_ids_from_gallery($galleryID, 'pid', 'ASC', false); 
  665.  
  666. header('Content-Type: text/plain; charset=' . get_option('blog_charset'), true); 
  667. $output = json_encode($gallery); 
  668.  
  669. return $output; 
  670.  
  671. /** 
  672. * Deprecated function, restored to fix compatibility with "NextGen Public Uploader" 
  673. * @deprecated 
  674. * @class nggAdmin 
  675. * @param string $filename 
  676. * @return bool $result 
  677. */ 
  678. function chmod($filename = '') 
  679. $stat = @stat(dirname($filename)); 
  680. $perms = $stat['mode'] & 0000666; 
  681. if (@chmod($filename, $perms)) 
  682. return true; 
  683. return false; 
  684.  
  685. } // END class nggAdmin