PageRenderTime 24ms CodeModel.GetById 12ms RepoModel.GetById 1ms app.codeStats 0ms

/wordpress/wp-content/plugins/nextgen-public-uploader/inc/class.npu_uploader.php

http://ownerpress.googlecode.com/
PHP | 187 lines | 159 code | 4 blank | 24 comment | 34 complexity | 7f68ddd5ef18681d6d9d57983f2ff47e MD5 | raw file
Possible License(s): Apache-2.0, AGPL-1.0, GPL-2.0, GPL-3.0, LGPL-2.1
  1. <?php
  2. // Get NextGEN Gallery Functions
  3. require_once (NGGALLERY_ABSPATH."/admin/functions.php");
  4. class UploaderNggAdmin extends nggAdmin
  5. {
  6. // Public Variables
  7. public $arrImageIds = false;
  8. public $strGalleryPath = false;
  9. public $arrImageNames = false;
  10. public $strFileName = false;
  11. public $blnRedirectPage = false;
  12. public $arrThumbReturn = false;
  13. public $arrEXIF = false;
  14. public $arrErrorMsg = array();
  15. public $arrErrorMsg_widg = array();
  16. function upload_images() {
  17. global $wpdb;
  18. // Image Array
  19. $imageslist = array();
  20. // Get Gallery ID
  21. $galleryID = (int) $_POST['galleryselect'];
  22. if ($galleryID == 0) {
  23. if(get_option('npu_default_gallery')) {
  24. $galleryID = get_option('npu_default_gallery');
  25. } else {
  26. nggGallery::show_error(__('No gallery selected.','nggallery'));
  27. return;
  28. }
  29. }
  30. // Get Gallery Path
  31. $gallerypath = $wpdb->get_var("SELECT path FROM $wpdb->nggallery WHERE gid = '$galleryID' ");
  32. if (!$gallerypath){
  33. nggGallery::show_error(__('Failure in database, no gallery path set.','nggallery'));
  34. return;
  35. }
  36. // Read Image List
  37. $dirlist = $this->scandir(WINABSPATH.$gallerypath);
  38. foreach ($_FILES as $key => $value) {
  39. if ($_FILES[$key]['error'] == 0) {
  40. $temp_file = $_FILES[$key]['tmp_name'];
  41. $filepart = pathinfo ( strtolower($_FILES[$key]['name']) );
  42. // Required Until PHP 5.2.0
  43. $filepart['filename'] = substr($filepart["basename"],0 ,strlen($filepart["basename"]) - (strlen($filepart["extension"]) + 1) );
  44. $filename = sanitize_title($filepart['filename']) . '.' . $filepart['extension'];
  45. // Allowed Extensions
  46. $ext = array('jpeg', 'jpg', 'png', 'gif');
  47. if ( !in_array($filepart['extension'], $ext) || !@getimagesize($temp_file) ){
  48. nggGallery::show_error('<strong>'.$_FILES[$key]['name'].' </strong>'.__('is not a valid file.','nggallery'));
  49. continue;
  50. }
  51. // Check If File Exists
  52. $i = 0;
  53. while (in_array($filename,$dirlist)) {
  54. $filename = sanitize_title($filepart['filename']) . '_' . $i++ . '.' .$filepart['extension'];
  55. }
  56. $dest_file = WINABSPATH . $gallerypath . '/' . $filename;
  57. // Check Folder Permissions
  58. if (!is_writeable(WINABSPATH.$gallerypath)) {
  59. $message = sprintf(__('Unable to write to directory %s. Is this directory writable by the server?', 'nggallery'), WINABSPATH.$gallerypath);
  60. nggGallery::show_error($message);
  61. return;
  62. }
  63. // Save Temporary File
  64. if (!@move_uploaded_file($_FILES[$key]['tmp_name'], $dest_file)){
  65. nggGallery::show_error(__('Error, the file could not moved to : ','nggallery').$dest_file);
  66. $this->check_safemode(WINABSPATH.$gallerypath);
  67. continue;
  68. }
  69. if (!$this->chmod ($dest_file)) {
  70. nggGallery::show_error(__('Error, the file permissions could not set.','nggallery'));
  71. continue;
  72. }
  73. // Add to Image and Dir List
  74. $imageslist[] = $filename;
  75. $dirlist[] = $filename;
  76. }
  77. }
  78. if (count($imageslist) > 0) {
  79. if (get_option('npu_exclude_select') == "Disabled") {
  80. $npu_exclude_id = 0;
  81. } else {
  82. $npu_exclude_id = 1;
  83. }
  84. // Add Images to Database
  85. $image_ids = $this->add_Images($galleryID, $imageslist);
  86. $this->arrThumbReturn = array();
  87. foreach ($image_ids as $pid) {
  88. $wpdb->query("UPDATE $wpdb->nggpictures SET exclude = '$npu_exclude_id' WHERE pid = '$pid'");
  89. $this->arrThumbReturn[] = $this->create_thumbnail($pid);
  90. }
  91. $this->arrImageIds = array();
  92. $this->arrImageIds = $image_ids;
  93. $this->arrImageNames =array();
  94. $this->arrImageNames = $imageslist;
  95. $this->strGalleryPath = $gallerypath;
  96. }
  97. return;
  98. } // End Function
  99. function upload_images_widget() {
  100. global $wpdb;
  101. // Image Array
  102. $imageslist = array();
  103. // Get Gallery ID
  104. $galleryID = (int) $_POST['galleryselect'];
  105. if ($galleryID == 0) {
  106. if(get_option('npu_default_gallery')) {
  107. $galleryID = get_option('npu_default_gallery');
  108. } else {
  109. nggGallery::show_error(__('No gallery selected.','nggallery'));
  110. return;
  111. }
  112. }
  113. // Get Gallery Path
  114. $gallerypath = $wpdb->get_var("SELECT path FROM $wpdb->nggallery WHERE gid = '$galleryID' ");
  115. if (!$gallerypath){
  116. nggGallery::show_error(__('Failure in database, no gallery path set.','nggallery'));
  117. return;
  118. }
  119. // Read Image List
  120. $dirlist = $this->scandir(WINABSPATH.$gallerypath);
  121. foreach ($_FILES as $key => $value) {
  122. if ($_FILES[$key]['error'] == 0) {
  123. $temp_file = $_FILES[$key]['tmp_name'];
  124. $filepart = pathinfo ( strtolower($_FILES[$key]['name']) );
  125. // Required Until PHP 5.2.0
  126. $filepart['filename'] = substr($filepart["basename"],0 ,strlen($filepart["basename"]) - (strlen($filepart["extension"]) + 1) );
  127. $filename = sanitize_title($filepart['filename']) . '.' . $filepart['extension'];
  128. // Allowed Extensions
  129. $ext = array('jpeg', 'jpg', 'png', 'gif');
  130. if ( !in_array($filepart['extension'], $ext) || !@getimagesize($temp_file) ){
  131. nggGallery::show_error('<strong>'.$_FILES[$key]['name'].' </strong>'.__('is not a valid file.','nggallery'));
  132. continue;
  133. }
  134. // Check If File Exists
  135. $i = 0;
  136. while (in_array($filename,$dirlist)) {
  137. $filename = sanitize_title($filepart['filename']) . '_' . $i++ . '.' .$filepart['extension'];
  138. }
  139. $dest_file = WINABSPATH . $gallerypath . '/' . $filename;
  140. // Check Folder Permissions
  141. if (!is_writeable(WINABSPATH.$gallerypath)) {
  142. $message = sprintf(__('Unable to write to directory %s. Is this directory writable by the server?', 'nggallery'), WINABSPATH.$gallerypath);
  143. nggGallery::show_error($message);
  144. return;
  145. }
  146. // Save Temporary File
  147. if (!@move_uploaded_file($_FILES[$key]['tmp_name'], $dest_file)){
  148. nggGallery::show_error(__('Error, the file could not moved to : ','nggallery').$dest_file);
  149. $this->check_safemode(WINABSPATH.$gallerypath);
  150. continue;
  151. }
  152. if (!$this->chmod ($dest_file)) {
  153. nggGallery::show_error(__('Error, the file permissions could not set.','nggallery'));
  154. continue;
  155. }
  156. // Add to Image and Dir List
  157. $imageslist[] = $filename;
  158. $dirlist[] = $filename;
  159. }
  160. }
  161. if (count($imageslist) > 0) {
  162. if (get_option('npu_exclude_select') == "Disabled") {
  163. $npu_exclude_id = 0;
  164. } else {
  165. $npu_exclude_id = 1;
  166. }
  167. // Add Images to Database
  168. $image_ids = $this->add_Images($galleryID, $imageslist);
  169. $this->arrThumbReturn = array();
  170. foreach ($image_ids as $pid) {
  171. $wpdb->query("UPDATE $wpdb->nggpictures SET exclude = '$npu_exclude_id' WHERE pid = '$pid'");
  172. $this->arrThumbReturn[] = $this->create_thumbnail($pid);
  173. }
  174. $this->arrImageIds = array();
  175. $this->arrImageIds = $image_ids;
  176. $this->arrImageNames =array();
  177. $this->arrImageNames = $imageslist;
  178. $this->strGalleryPath = $gallerypath;
  179. }
  180. return;
  181. } // End Function
  182. }
  183. ?>