A_NextGen_AddGallery_Ajax

Class A_NextGen_AddGallery_Ajax.

Defined (1)

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

/products/photocrati_nextgen/modules/nextgen_addgallery_page/package.module.nextgen_addgallery_page.php  
  1. class A_NextGen_AddGallery_Ajax extends Mixin 
  2. function cookie_dump_action() 
  3. foreach ($_COOKIE as $key => &$value) { 
  4. if (is_string($value)) { 
  5. $value = stripslashes($value); 
  6. return array('success' => 1, 'cookies' => $_COOKIE); 
  7. function upload_image_action() 
  8. $retval = array(); 
  9. $created_gallery = FALSE; 
  10. $gallery_id = intval($this->param('gallery_id')); 
  11. $gallery_name = urldecode($this->param('gallery_name')); 
  12. $gallery_mapper = C_Gallery_Mapper::get_instance(); 
  13. $error = FALSE; 
  14. if ($this->validate_ajax_request('nextgen_upload_image', TRUE)) { 
  15. // We need to create a gallery 
  16. if ($gallery_id == 0) { 
  17. if (strlen($gallery_name) > 0) { 
  18. $gallery = $gallery_mapper->create(array('title' => $gallery_name)); 
  19. if (!$gallery->save()) { 
  20. $retval['error'] = $gallery->get_errors(); 
  21. $error = TRUE; 
  22. } else { 
  23. $created_gallery = TRUE; 
  24. $gallery_id = $gallery->id(); 
  25. } else { 
  26. $error = TRUE; 
  27. $retval['error'] = __("No gallery name specified", 'nggallery'); 
  28. // Upload the image to the gallery 
  29. if (!$error) { 
  30. $retval['gallery_id'] = $gallery_id; 
  31. $settings = C_NextGen_Settings::get_instance(); 
  32. $storage = C_Gallery_Storage::get_instance(); 
  33. try { 
  34. if ($storage->is_zip()) { 
  35. if ($results = $storage->upload_zip($gallery_id)) { 
  36. $retval = $results; 
  37. } else { 
  38. $retval['error'] = __('Failed to extract images from ZIP', 'nggallery'); 
  39. } elseif ($image = $storage->upload_image($gallery_id)) { 
  40. $retval['image_ids'] = array($image->id()); 
  41. $retval['image_errors'] = array(); 
  42. // check if image was resized correctly 
  43. if ($settings->imgAutoResize) { 
  44. $image_path = $storage->get_full_abspath($image); 
  45. $image_thumb = new C_NggLegacy_Thumbnail($image_path, true); 
  46. if ($image_thumb->error) { 
  47. $retval['image_errors'][] = array('id' => $image->id(), 'error' => sprintf(__('Automatic image resizing failed [%1$s].', 'nggallery'), $image_thumb->errmsg)); 
  48. $image_thumb = null; 
  49. // check if thumb was generated correctly 
  50. $thumb_path = $storage->get_thumb_abspath($image); 
  51. if (!file_exists($thumb_path)) { 
  52. $retval['image_errors'][] = array('id' => $image->id(), 'error' => __('Thumbnail generation failed.', 'nggallery')); 
  53. } else { 
  54. $retval['error'] = __('Image generation failed', 'nggallery'); 
  55. $error = TRUE; 
  56. } catch (E_NggErrorException $ex) { 
  57. $retval['error'] = $ex->getMessage(); 
  58. $error = TRUE; 
  59. if ($created_gallery) { 
  60. $gallery_mapper->destroy($gallery_id); 
  61. } catch (Exception $ex) { 
  62. $retval['error'] = __("An unexpected error occured.", 'nggallery'); 
  63. $retval['error_details'] = $ex->getMessage(); 
  64. $error = TRUE; 
  65. } else { 
  66. $retval['error'] = __("No permissions to upload images. Try refreshing the page or ensuring that your user account has sufficient roles/privileges.", 'nggallery'); 
  67. $error = TRUE; 
  68. if ($error) { 
  69. return $retval; 
  70. } else { 
  71. $retval['gallery_name'] = esc_html($gallery_name); 
  72. return $retval; 
  73. function get_import_root_abspath() 
  74. if (is_multisite()) { 
  75. $root = C_Gallery_Storage::get_instance()->get_upload_abspath(); 
  76. } else { 
  77. $root = NGG_IMPORT_ROOT; 
  78. $root = str_replace('/', DIRECTORY_SEPARATOR, $root); 
  79. return untrailingslashit($root); 
  80. function browse_folder_action() 
  81. $retval = array(); 
  82. $html = array(); 
  83. if ($this->validate_ajax_request('nextgen_upload_image', TRUE)) { 
  84. if ($dir = urldecode($this->param('dir'))) { 
  85. $fs = C_Fs::get_instance(); 
  86. $root = $this->get_import_root_abspath(); 
  87. $browse_path = $fs->join_paths($root, $dir); 
  88. if (strpos(realpath($browse_path), realpath($root)) !== FALSE) { 
  89. if (@file_exists($browse_path)) { 
  90. $files = scandir($browse_path); 
  91. natcasesort($files); 
  92. if (count($files) > 2) { 
  93. /** The 2 accounts for . and .. */ 
  94. $html[] = "<ul class=\"jqueryFileTree\" style=\"display: none;\">"; 
  95. foreach ($files as $file) { 
  96. $file_path = $fs->join_paths($browse_path, $file); 
  97. $rel_file_path = str_replace($root, '', $file_path); 
  98. if (@file_exists($file_path) && $file != '.' && $file != '..' && is_dir($file_path)) { 
  99. $html[] = "<li class=\"directory collapsed\"><a href=\"#\" rel=\"" . htmlentities($rel_file_path) . "/\">" . htmlentities($file) . "</a></li>"; 
  100. $html[] = "</ul>"; 
  101. $retval['html'] = implode("\n", $html); 
  102. } else { 
  103. $retval['error'] = __("Directory does not exist.", 'nggallery'); 
  104. } else { 
  105. $retval['error'] = __("No permissions to browse folders. Try refreshing the page or ensuring that your user account has sufficient roles/privileges.", 'nggallery'); 
  106. } else { 
  107. $retval['error'] = __("No directory specified.", 'nggallery'); 
  108. } else { 
  109. $retval['error'] = __("No permissions to browse folders. Try refreshing the page or ensuring that your user account has sufficient roles/privileges.", 'nggallery'); 
  110. return $retval; 
  111. function import_folder_action() 
  112. $retval = array(); 
  113. if ($this->validate_ajax_request('nextgen_upload_image', TRUE)) { 
  114. if ($folder = $this->param('folder')) { 
  115. $storage = C_Gallery_Storage::get_instance(); 
  116. $fs = C_Fs::get_instance(); 
  117. try { 
  118. $keep_files = $this->param('keep_location') == 'on'; 
  119. $gallery_title = $this->param('gallery_title', NULL); 
  120. if (empty($gallery_title)) { 
  121. $gallery_title = NULL; 
  122. $root = $this->get_import_root_abspath(); 
  123. $import_path = $fs->join_paths($root, $folder); 
  124. if (strpos(realpath($import_path), realpath($root)) !== FALSE) { 
  125. $retval = $storage->import_gallery_from_fs($import_path, FALSE, !$keep_files, $gallery_title); 
  126. if (!$retval) { 
  127. $retval = array('error' => "Could not import folder. No images found."); 
  128. } else { 
  129. $retval['error'] = __("No permissions to import folders. Try refreshing the page or ensuring that your user account has sufficient roles/privileges.", 'nggallery'); 
  130. } catch (E_NggErrorException $ex) { 
  131. $retval['error'] = $ex->getMessage(); 
  132. } catch (Exception $ex) { 
  133. $retval['error'] = __("An unexpected error occured.", 'nggallery'); 
  134. $retval['error_details'] = $ex->getMessage(); 
  135. } else { 
  136. $retval['error'] = __("No folder specified", 'nggallery'); 
  137. } else { 
  138. $retval['error'] = __("No permissions to import folders. Try refreshing the page or ensuring that your user account has sufficient roles/privileges.", 'nggallery'); 
  139. return $retval; 
  140. function import_media_library_action() 
  141. $retval = array(); 
  142. $created_gallery = FALSE; 
  143. $gallery_id = intval($this->param('gallery_id')); 
  144. $gallery_name = urldecode($this->param('gallery_name')); 
  145. $gallery_mapper = C_Gallery_Mapper::get_instance(); 
  146. $image_mapper = C_Image_Mapper::get_instance(); 
  147. $attachment_ids = $this->param('attachment_ids'); 
  148. if ($this->validate_ajax_request('nextgen_upload_image', TRUE)) { 
  149. if (empty($attachment_ids) || !is_array($attachment_ids)) { 
  150. $retval['error'] = __('An unexpected error occured.', 'nggallery'); 
  151. if (empty($retval['error']) && $gallery_id == 0) { 
  152. if (strlen($gallery_name) > 0) { 
  153. $gallery = $gallery_mapper->create(array('title' => $gallery_name)); 
  154. if (!$gallery->save()) { 
  155. $retval['error'] = $gallery->get_errors(); 
  156. } else { 
  157. $created_gallery = TRUE; 
  158. $gallery_id = $gallery->id(); 
  159. } else { 
  160. $retval['error'] = __('No gallery name specified', 'nggallery'); 
  161. if (empty($retval['error'])) { 
  162. $retval['gallery_id'] = $gallery_id; 
  163. $storage = C_Gallery_Storage::get_instance(); 
  164. foreach ($attachment_ids as $id) { 
  165. try { 
  166. $abspath = get_attached_file($id); 
  167. $file_data = @file_get_contents($abspath); 
  168. $file_name = M_I18n::mb_basename($abspath); 
  169. $attachment = get_post($id); 
  170. if (empty($file_data)) { 
  171. $retval['error'] = __('Image generation failed', 'nggallery'); 
  172. break; 
  173. $image = $storage->upload_base64_image($gallery_id, $file_data, $file_name); 
  174. if ($image) { 
  175. // Potentially import metadata from WordPress 
  176. $image = $image_mapper->find($image->id()); 
  177. if (!empty($attachment->post_excerpt)) { 
  178. $image->alttext = $attachment->post_excerpt; 
  179. if (!empty($attachment->post_content)) { 
  180. $image->description = $attachment->post_content; 
  181. $image = apply_filters('ngg_medialibrary_imported_image', $image, $attachment); 
  182. $image_mapper->save($image); 
  183. } else { 
  184. $retval['error'] = __('Image generation failed', 'nggallery'); 
  185. break; 
  186. $retval['image_ids'][] = $image->{$image->id_field}; 
  187. } catch (E_NggErrorException $ex) { 
  188. $retval['error'] = $ex->getMessage(); 
  189. if ($created_gallery) { 
  190. $gallery_mapper->destroy($gallery_id); 
  191. } catch (Exception $ex) { 
  192. $retval['error'] = __('An unexpected error occured.', 'nggallery'); 
  193. $retval['error_details'] = $ex->getMessage(); 
  194. } else { 
  195. $retval['error'] = __('No permissions to upload images. Try refreshing the page or ensuring that your user account has sufficient roles/privileges.', 'nggallery'); 
  196. if (!empty($retval['error'])) { 
  197. return $retval; 
  198. } else { 
  199. $retval['gallery_name'] = esc_html($gallery_name); 
  200. return $retval;