Advertisement
Guest User

npu-upload.php

a guest
Feb 6th, 2013
1,529
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 22.19 KB | None | 0 0
  1. <?php
  2.  
  3. if (!class_exists("npuGalleryUpload")) {
  4.  
  5.     // Public Variables
  6.     class npuGalleryUpload {
  7.         public $arrImageIds;
  8.         public $strGalleryPath = false;
  9.         public $blnRedirectPage = false;
  10.         public $arrUploadedThumbUrls = false;
  11.         public $arrUploadedImageUrls = false;
  12.         public $arrErrorMsg = array();
  13.         public $arrImageMsg = array();
  14.         public $arrErrorMsg_widg = array();
  15.         public $arrImageMsg_widg = array();
  16.         public $arrImageNames = array();
  17.         public $arrImageMeta = array();
  18.         public $strTitle = false;
  19.         public $strDescription = false;
  20.         public $strKeywords = false;
  21.         public $strTimeStamp = false;
  22.  
  23.         // Function: Constructors
  24.         public function __construct()
  25.         {
  26.             add_shortcode("ngg_uploader", array(&$this, 'shortcode_show_uploader')); // Shortcode Uploader
  27.             add_action('widgets_init', array(&$this, 'npu_upload_register')); // Widget Uploader
  28.         }
  29.  
  30.         // Function: Register Widget
  31.         public function npu_upload_register() {
  32.             $options = get_option('npu_gal_upload');
  33.             if (!$options) {
  34.                 $options = array();
  35.             }
  36.             $widget_ops = array('classname' => 'npu_gallery_upload', 'description' => __('Upload images to a NextGEN Gallery', 'nggallery'));
  37.             $control_ops = array('width' => 250, 'height' => 200, 'id_base' => 'npu-gallery-upload');
  38.             $name = __('NextGEN Uploader','nggallery');
  39.             $id = false;
  40.             foreach (array_keys($options) as $o) {
  41.                 if (!isset($options[$o]['title'])) {
  42.                     continue;
  43.                 }
  44.                 $id = "npu-gallery-upload-$o";
  45.                 wp_register_sidebar_widget($id, $name, array(&$this, 'npu_upload_output'), $widget_ops, array('number' => $o));
  46.                 wp_register_widget_control($id, $name, array(&$this, 'npu_upload_control'), $control_ops, array('number' => $o));
  47.             }
  48.             if ( !$id ) {
  49.                 wp_register_sidebar_widget( 'npu-gallery-upload-1', $name, array(&$this, 'npu_upload_output'), $widget_ops, array( 'number' => -1 ) );
  50.                 wp_register_widget_control( 'npu-gallery-upload-1', $name, array(&$this, 'npu_upload_control'), $control_ops, array( 'number' => -1 ) );
  51.             }
  52.         }
  53.  
  54.         // Function: Widget Control
  55.         public function npu_upload_control($widget_args = 1) {
  56.             global $wp_registered_widgets, $wpdb;
  57.             static $updated = false;
  58.             if (is_numeric($widget_args)) {
  59.                 $widget_args = array('number' => $widget_args);
  60.             }
  61.             $widget_args = wp_parse_args($widget_args, array('number' => -1));
  62.             extract($widget_args, EXTR_SKIP);
  63.             $options = get_option('npu_gal_upload');
  64.             if (!is_array($options)) {
  65.                 $options = array();
  66.             }
  67.             if (!$updated && !empty($_POST['sidebar'])) {
  68.                 $sidebar = (string) $_POST['sidebar'];
  69.                 $sidebar_widgets = wp_get_sidebars_widgets();
  70.                 if (isset($sidebar_widgets[$sidebar])) {
  71.                     $this_sidebar = &$sidebar_widgets[$sidebar];
  72.                 } else {
  73.                     $this_sidebar = array();
  74.                 }
  75.                 foreach ($this_sidebar as $_widget_id) {
  76.                     if ('npu_gallery_upload' == $wp_registered_widgets[$_widget_id]['classname'] && isset($wp_registered_widgets[$_widget_id]['params'][0]['number'])) {
  77.                         $widget_number = $wp_registered_widgets[$_widget_id]['params'][0]['number'];
  78.                         if (!in_array("npu-gallery-upload-{$widget_number}", $_POST['widget-id'])) {
  79.                             unset ($options[$widget_number]);
  80.                         }
  81.                     }
  82.                 }
  83.                 foreach ((array)$_POST['widget_npu_upload'] as $widget_number => $widget_npu_upload) {
  84.                     if (!isset($widget_npu_upload['gal_id']) && isset($options[$widget_number])) {
  85.                         continue;
  86.                     }
  87.                     $widget_npu_upload = stripslashes_deep($widget_npu_upload);
  88.                     $options[$widget_number]['title'] = $widget_npu_upload['title'];
  89.                     $options[$widget_number]['gal_id'] = $widget_npu_upload['gal_id'];
  90.                 }
  91.                 update_option('npu_gal_upload', $options);
  92.                 $updated = true;
  93.             }
  94.             if (-1 == $number) {
  95.                 $title = 'Upload';
  96.                 $gal_id = 0;
  97.                 $number = '%i%';
  98.             } else {
  99.                 extract((array)$options[$number]);
  100.             }
  101.             include_once (NGGALLERY_ABSPATH."lib/ngg-db.php");
  102.             $nggdb = new nggdb();
  103.             $gallerylist = $nggdb->find_all_galleries('gid', 'DESC');
  104.             ?>
  105.             <p>
  106.                 <label for="npu_upload-title-<?php echo $number; ?>"><?php _e('Title:','nggallery'); ?>
  107.                     <input id="npu_upload-title-<?php echo $number; ?>" name="widget_npu_upload[<?php echo $number; ?>][title]" type="text" class="widefat" value="<?php echo $title; ?>" />
  108.                 </label>
  109.             </p>
  110.             <p>
  111.                 <label for="npu_upload-id-<?php echo $number; ?>"><?php _e('Upload to :','nggallery'); ?>
  112.                     <select id="npu_upload-id-<?php echo $number; ?>" name="widget_npu_upload[<?php echo $number; ?>][gal_id]" >
  113.                         <option value="0" ><?php _e('Choose gallery', 'nggallery') ?></option>
  114.                         <?php
  115.                             foreach ($gallerylist as $gallery) {
  116.                                 $name = ( empty($gallery->title) ) ? $gallery->name : $gallery->title;
  117.                                 echo '<option ' . selected( $gallery->gid , $gal_id ) . ' value="' . $gallery->gid . '">ID: ' . $gallery->gid . ' &ndash; ' . $name . '</option>';
  118.                             }
  119.                         ?>
  120.                     </select>
  121.                 </label>
  122.             </p>
  123.             <input type="hidden" id="npu_upload-submit-<?php echo $number; ?>" name="widget_npu_upload[<?php echo $number; ?>][submit]" value="1" />
  124.             <?php
  125.         }
  126.  
  127.         // Function: Widget Output
  128.         public function npu_upload_output($args, $widget_args = 1, $options = false) {
  129.             extract($args, EXTR_SKIP);
  130.             if (is_numeric($widget_args)) {
  131.                 $widget_args = array('number' => $widget_args);
  132.             }
  133.             $widget_args = wp_parse_args($widget_args, array('number' => -1));
  134.             extract($widget_args, EXTR_SKIP);
  135.             if(!$options) {
  136.                 $options = get_option('npu_gal_upload');
  137.             }
  138.             $gal_id = $options[$number]['gal_id'];
  139.             $count = count((array)$_FILES['imagefiles']['tmp_name']);
  140.             $x = $_FILES['imagefiles'];
  141.             for($i=0; $i<$count; $i++){
  142.             $_FILES['imagefiles']['name']= $x['name'][$i];
  143.             $_FILES['imagefiles']['type']= $x['type'][$i];
  144.             $_FILES['imagefiles']['tmp_name']= $x['tmp_name'][$i];
  145.             $_FILES['imagefiles']['error']= $x['error'][$i];
  146.             $_FILES['imagefiles']['size']= $x['size'][$i];
  147.             $this->handleUpload_widget();
  148.             }
  149.             echo $args['before_widget'];
  150.             echo $args['before_title'].$options[$number]['title'].$args['after_title'];
  151.             $this->display_uploader_widget($gal_id, false);
  152.             echo $args['after_widget'];
  153.         }
  154.  
  155.         // Function: Add Scripts
  156.         public function add_scripts () {
  157.             wp_register_script('ngg-ajax', NGGALLERY_URLPATH .'admin/js/ngg.ajax.js', array('jquery'), '1.0.0');
  158.             // Setup Array
  159.             wp_localize_script('ngg-ajax', 'nggAjaxSetup', array(
  160.                         'url' => admin_url('admin-ajax.php'),
  161.                         'action' => 'ngg_ajax_operation',
  162.                         'operation' => '',
  163.                         'nonce' => wp_create_nonce( 'ngg-ajax' ),
  164.                         'ids' => '',
  165.                         'permission' => __('You do not have the correct permission', 'nggallery'),
  166.                         'error' => __('Unexpected Error', 'nggallery'),
  167.                         'failure' => __('Upload Failed', 'nggallery')
  168.             ) );
  169.             wp_register_script('ngg-progressbar', NGGALLERY_URLPATH .'admin/js/ngg.progressbar.js', array('jquery'), '1.0.0');
  170.             wp_register_script('swfupload_f10', NGGALLERY_URLPATH .'admin/js/swfupload.js', array('jquery'), '2.2.0');
  171.             wp_enqueue_script( 'jquery-ui-tabs' );
  172.             wp_enqueue_script( 'mutlifile', NGGALLERY_URLPATH .'admin/js/jquery.MultiFile.js', array('jquery'), '1.1.1' );
  173.             wp_enqueue_script( 'ngg-swfupload-handler', NGGALLERY_URLPATH .'admin/js/swfupload.handler.js', array('swfupload_f10'), '1.0.0' );
  174.             wp_enqueue_script( 'ngg-ajax' );
  175.             wp_enqueue_script( 'ngg-progressbar' );
  176.         }
  177.  
  178.         // Function: Shortcode Form
  179.         public function display_uploader($gal_id, $strDetailsPage = false, $blnShowAltText = true, $echo = true) {
  180.             $strOutput = "";
  181.             if (count($this->arrErrorMsg) > 0) {
  182.                 $strOutput .= "<div class=\"upload_error\">";
  183.                 foreach ($this->arrErrorMsg as $msg) {
  184.                     $strOutput .= $msg;
  185.                 }
  186.                 $strOutput .= "</div>";
  187.             }
  188.             if (count($this->arrImageMsg) > 0) {
  189.                 $strOutput .= "<div class=\"upload_error\">";
  190.                 foreach ($this->arrImageMsg as $msg) {
  191.                     $strOutput .= $msg;
  192.                 }
  193.                 $strOutput .= "</div>";
  194.             }
  195.             if (!is_user_logged_in() && get_option('npu_user_role_select') != 99) {
  196.                 $strOutput .= "<div class=\"need_login\">";
  197.                 if(get_option('npu_notlogged')) {
  198.                     $strOutput .= get_option('npu_notlogged');
  199.                 } else {
  200.                     $strOutput .= "You must be registered and logged in to upload images.";
  201.                 }
  202.                 $strOutput .= "</div>";
  203.             } else {
  204.                 $npu_selected_user_role = get_option('npu_user_role_select');
  205.                 if (current_user_can('level_'. $npu_selected_user_role . '') || get_option('npu_user_role_select') == 99) {
  206.                     $strOutput .= "<div id=\"uploadimage\">";
  207.                     $strOutput .= "\n\t<form name=\"uploadimage\" id=\"uploadimage_form\" method=\"POST\" enctype=\"multipart/form-data\" accept-charset=\"utf-8\" >";
  208.                     $strOutput .= wp_nonce_field('ngg_addgallery', '_wpnonce', true , false);
  209.                     $strOutput .= "\n\t<div class=\"uploader\">";
  210.                     //select
  211.                     $strOutput .= "\n\tGalerie: <select name=\"galleryselect\">";
  212.                     $sql = "SELECT gid, title FROM wp_ngg_gallery ORDER BY title";
  213.                     $result = mysql_query($sql);
  214.                     while ($array = mysql_fetch_array($result)) {
  215.                         $strOutput .= "\n\t<option value=\"".$array['gid']."\">".$array['title']."</option>";
  216.                     }
  217.                     $strOutput .= "\n\t</select><br><br>";
  218.                     //select end
  219.                     $strOutput .= "\n\t<input type=\"file\" name=\"imagefiles[]\" id=\"imagefiles\" multiple=\"multiple\" />";
  220.                     $strOutput .= "\n</div>";
  221.                     //$strOutput .= "\n<input type=\"hidden\" name=\"galleryselect\" value=\"{$gal_id}\">";
  222.                     if (!$strDetailsPage) {
  223.                         $strOutput .= "\n\t<div class=\"image_details_textfield\">";
  224.                         if ($blnShowAltText) {}
  225.                         $strOutput .= "\n\t</div>";
  226.                     }
  227.                     if(get_option('npu_image_description_select') == 'Enabled') {
  228.                         $strOutput .= "<br />";
  229.                         if(get_option('npu_description_text')) {
  230.                             $strOutput .= get_option('npu_description_text');
  231.                         } else {
  232.                         $strOutput .= __('Description:', 'ngg-public-uploader');
  233.                         }
  234.                         $strOutput .= "<br />";
  235.                         $strOutput .= "\n\t<input type=\"text\" name=\"imagedescription\" id=\"imagedescription\"/>";
  236.                     }
  237.                     $strOutput .= "\n\t<div class=\"submit\"><br />";
  238.                     if(get_option('npu_upload_button')) {
  239.                         $strOutput .= "\n\t\t<input class=\"button-primary\" type=\"submit\" name=\"uploadimage\" id=\"uploadimage_btn\" ";
  240.                         $strOutput .= 'value="' . get_option("npu_upload_button") . '" >';
  241.                     } else {
  242.                         $strOutput .= "\n\t\t<input class=\"button-primary\" type=\"submit\" name=\"uploadimage\" id=\"uploadimage_btn\" value=\"Upload\" />";
  243.                     }
  244.                     $strOutput .= "\n\t\t</div>";
  245.                     $strOutput .= "\n</form>";
  246.                     $strOutput .= "\n</div>";
  247.                 }
  248.             }
  249.             if ($echo) {
  250.                 echo $strOutput;
  251.             } else {
  252.                 return $strOutput;
  253.             }
  254.         }
  255.  
  256.         // Function: Widget Form
  257.         public function display_uploader_widget($gal_id, $strDetailsPage = false, $blnShowAltText = true, $echo = true) {
  258.             $strOutput = "";
  259.             if (count($this->arrErrorMsg_widg) > 0) {
  260.                 $strOutput .= "<div class=\"upload_error\">";
  261.                 foreach ($this->arrErrorMsg_widg as $msg) {
  262.                     $strOutput .= $msg;
  263.                 }
  264.                 $strOutput .= "</div>";
  265.             }
  266.             if (count($this->arrImageMsg_widg) > 0) {
  267.                 $strOutput .= "<div class=\"upload_error\">";
  268.                 foreach ($this->arrImageMsg_widg as $msg) {
  269.                     $strOutput .= $msg;
  270.                 }
  271.                 $strOutput .= "</div>";
  272.             }
  273.             if (!is_user_logged_in() && get_option('npu_user_role_select') != 99) {
  274.                 $strOutput .= "<div class=\"need_login\">";
  275.                 if(get_option('npu_notlogged')) {
  276.                     $strOutput .= get_option('npu_notlogged');
  277.                 } else {
  278.                     $strOutput .= "You must be registered and logged in to upload images.";
  279.                 }
  280.                 $strOutput .= "</div>";
  281.             } else {
  282.                 $npu_selected_user_role = get_option('npu_user_role_select');
  283.                 if (current_user_can('level_'. $npu_selected_user_role . '') || get_option('npu_user_role_select') == 99) {
  284.                     $strOutput .= "<div id=\"uploadimage\">";
  285.                     $strOutput .= "\n\t<form name=\"uploadimage_widget\" id=\"uploadimage_form_widget\" method=\"POST\" enctype=\"multipart/form-data\" accept-charset=\"utf-8\" >";
  286.                     $strOutput .= wp_nonce_field('ngg_addgallery', '_wpnonce', true , false);
  287.                     $strOutput .= "\n\t<div class=\"uploader\">";
  288.                     //select
  289.                     $strOutput .= "\n\tGalerie: <select name=\"galleryselect\">";
  290.                     $sql = "SELECT gid, title FROM wp_ngg_gallery ORDER BY title";
  291.                     $result = mysql_query($sql);
  292.                     while ($array = mysql_fetch_array($result)) {
  293.                         $strOutput .= "\n\t<option value=\"".$array['gid']."\">".$array['title']."</option>";
  294.                     }
  295.                     $strOutput .= "\n\t</select><br><br>";
  296.                     //select end
  297.                     $strOutput .= "\n\t<input type=\"file\" name=\"imagefiles[]\" id=\"imagefiles\" multiple=\"multiple\" />";
  298.                     $strOutput .= "\n</div>";
  299.                     //$strOutput .= "\n<input type=\"hidden\" name=\"galleryselect\" value=\"{$gal_id}\">";
  300.                     if (!$strDetailsPage) {
  301.                         $strOutput .= "\n\t<div class=\"image_details_textfield\">";
  302.                         if ($blnShowAltText) {}
  303.                         $strOutput .= "\n\t</div>";
  304.                     }
  305.                     if(get_option('npu_image_description_select') == 'Enabled') {
  306.                         $strOutput .= "<br />";
  307.                         if(get_option('npu_description_text')) {
  308.                             $strOutput .= get_option('npu_description_text');
  309.                         } else {
  310.                             $strOutput .= __('Description:', 'ngg-public-uploader');
  311.                         }
  312.                         $strOutput .= "<br />";
  313.                         $strOutput .= "\n\t<input type=\"text\" name=\"imagedescription\" id=\"imagedescription\"/>";
  314.                     }
  315.                     $strOutput .= "\n\t<div class=\"submit\"><br />";
  316.                     if(get_option('npu_upload_button')) {
  317.                         $strOutput .= "\n\t\t<input class=\"button-primary\" type=\"submit\" name=\"uploadimage_widget\" id=\"uploadimage_btn\" ";
  318.                         $strOutput .= 'value="' . get_option("npu_upload_button") . '" >';
  319.                     } else {
  320.                         $strOutput .= "\n\t\t<input class=\"button-primary\" type=\"submit\" name=\"uploadimage_widget\" id=\"uploadimage_btn\" value=\"Upload\" />";
  321.                     }
  322.                     $strOutput .= "\n\t\t</div>";
  323.                     $strOutput .= "\n</form>";
  324.                     $strOutput .= "\n</div>";
  325.                 }
  326.             }
  327.             if ($echo) {
  328.                 echo $strOutput;
  329.             } else {
  330.                 return $strOutput;
  331.             }
  332.         }
  333.  
  334.         // Function: Handle Upload for Shortcode
  335.         public function handleUpload() {
  336.             global $wpdb;
  337.             require_once(dirname (__FILE__). '/class.npu_uploader.php');
  338.             require_once(NGGALLERY_ABSPATH . '/lib/meta.php');
  339.             $ngg->options['swfupload'] = false;
  340.             if ( isset( $_POST['uploadimage'] ) ) {
  341.                 check_admin_referer('ngg_addgallery');
  342.                 if ( !isset($_FILES['MF__F_0_0']['error']) || $_FILES['MF__F_0_0']['error'] == 0) {
  343.                     $objUploaderNggAdmin = new UploaderNggAdmin();
  344.                     $messagetext = $objUploaderNggAdmin->upload_images();
  345.                     $this->arrImageIds = $objUploaderNggAdmin->arrImageIds;
  346.                     $this->strGalleryPath = $objUploaderNggAdmin->strGalleryPath;
  347.                     $this->arrImageNames = $objUploaderNggAdmin->arrImageNames;
  348.                     if (is_array($objUploaderNggAdmin->arrThumbReturn) && count($objUploaderNggAdmin->arrThumbReturn) > 0) {
  349.                         foreach ($objUploaderNggAdmin->arrThumbReturn as $strReturnMsg) {
  350.                             if ($strReturnMsg != '1') {
  351.                                 $this->arrErrorMsg[] = $strReturnMsg;
  352.                             }
  353.                         }
  354.                         if(get_option('npu_upload_success')) {
  355.                             $this->arrImageMsg[] = get_option('npu_upload_success')."<br>";
  356.                         } else {
  357.                             $this->arrImageMsg[] = "Thank you! Your image has been submitted and is pending review.";
  358.                         }
  359.                         $this->sendEmail();
  360.                     }
  361.                     if (is_array($this->arrImageIds) && count($this->arrImageIds) > 0) {
  362.                         foreach ($this->arrImageIds as $imageId) {
  363.                             $pic = nggdb::find_image($imageId);
  364.                             $objEXIF = new nggMeta($pic->imagePath);
  365.                             $this->strTitle = $objEXIF->get_META('title');
  366.                             $this->strDescription = $objEXIF->get_META('caption');
  367.                             $this->strKeywords = $objEXIF->get_META('keywords');
  368.                             $this->strTimeStamp = $objEXIF->get_date_time();
  369.                         }
  370.                     } else {
  371.                         if(get_option('npu_no_file')) {
  372.                         $this->arrErrorMsg[] = get_option('npu_no_file')."<br>";
  373.                         } else {
  374.                         $this->arrErrorMsg[] = "You must select a file to upload";
  375.                         }
  376.                     }
  377.                     $this->update_details();
  378.                 } else {
  379.                     if(get_option('npu_upload_failed')) {
  380.                     $this->arrErrorMsg[] = get_option('npu_upload_failed');
  381.                     } else {
  382.                     $this->arrErrorMsg[] = "Upload failed!";
  383.                     }
  384.                 }
  385.                 if (count($this->arrErrorMsg) > 0 && (is_array($this->arrImageIds) &&count($this->arrImageIds) > 0)) {
  386.                     $gal_id = $_POST['galleryselect'];
  387.                     foreach ($this->arrImageIds as $intImageId) {
  388.                         $filename = $wpdb->get_var("SELECT filename FROM $wpdb->nggpictures WHERE pid = '$intImageId' ");
  389.                         if ($filename) {
  390.                             $gallerypath = $wpdb->get_var("SELECT path FROM $wpdb->nggallery WHERE gid = '$gal_id' ");
  391.                             if ($gallerypath){
  392.                                 @unlink(WINABSPATH . $gallerypath . '/thumbs/thumbs_' .$filename);
  393.                                 @unlink(WINABSPATH . $gallerypath . '/' . $filename);
  394.                             }
  395.                             $delete_pic = $wpdb->query("DELETE FROM $wpdb->nggpictures WHERE pid = $intImageId");
  396.                         }
  397.                     }
  398.                 }
  399.             }
  400.         }
  401.  
  402.         // Function: Handle Upload for Widget
  403.         public function handleUpload_widget() {
  404.             global $wpdb;
  405.             require_once(dirname (__FILE__). '/class.npu_uploader.php');
  406.             require_once(NGGALLERY_ABSPATH . '/lib/meta.php');
  407.             $ngg->options['swfupload'] = false;
  408.             if (isset($_POST['uploadimage_widget'])){
  409.                 check_admin_referer('ngg_addgallery');
  410.                 if ( ! isset($_FILES['MF__F_0_0']['error']) || $_FILES['MF__F_0_0']['error'] == 0 ) {
  411.                     $objUploaderNggAdmin = new UploaderNggAdmin();
  412.                     $messagetext = $objUploaderNggAdmin->upload_images_widget();
  413.                     $this->arrImageIds = $objUploaderNggAdmin->arrImageIds;
  414.                     $this->strGalleryPath = $objUploaderNggAdmin->strGalleryPath;
  415.                     $this->arrImageNames = $objUploaderNggAdmin->arrImageNames;
  416.                     if (is_array($objUploaderNggAdmin->arrThumbReturn) && count($objUploaderNggAdmin->arrThumbReturn) > 0) {
  417.                         foreach ($objUploaderNggAdmin->arrThumbReturn as $strReturnMsg) {
  418.                             if ($strReturnMsg != '1') {
  419.                                 $this->arrErrorMsg_widg[] = $strReturnMsg;
  420.                             }
  421.                         }
  422.                         if(get_option('npu_upload_success')) {
  423.                             $this->arrImageMsg_widg[] = get_option('npu_upload_success')."<br>";
  424.                         } else {
  425.                             $this->arrImageMsg_widg[] = "Thank you! Your image has been submitted and is pending review.";
  426.                         }
  427.                         $this->sendEmail();
  428.                     }
  429.                     if (is_array($this->arrImageIds) && count($this->arrImageIds) > 0) {
  430.                         foreach ($this->arrImageIds as $imageId) {
  431.                             $pic = nggdb::find_image($imageId);
  432.                             $objEXIF = new nggMeta($pic->imagePath);
  433.                             $this->strTitle = $objEXIF->get_META('title');
  434.                             $this->strDescription = $objEXIF->get_META('caption');
  435.                             $this->strKeywords = $objEXIF->get_META('keywords');
  436.                             $this->strTimeStamp = $objEXIF->get_date_time();
  437.                         }
  438.                     } else {
  439.                         if(get_option('npu_no_file')) {
  440.                         $this->arrErrorMsg_widg[] = get_option('npu_no_file');
  441.                         } else {
  442.                         $this->arrErrorMsg_widg[] = "You must select a file to upload";
  443.                         }
  444.                     }
  445.                     $this->update_details();
  446.                 } else {
  447.                     if ( get_option('npu_upload_failed') ) {
  448.                        $this->arrErrorMsg_widg[] = get_option('npu_upload_failed')."<br>";
  449.                     } else {
  450.                        $this->arrErrorMsg_widg[] = "Upload failed!";
  451.                     }
  452.                 }
  453.                 if (count($this->arrErrorMsg_widg) > 0 && (is_array($this->arrImageIds) &&count($this->arrImageIds) > 0)) {
  454.                     $gal_id = $_POST['galleryselect'];
  455.                     foreach ($this->arrImageIds as $intImageId) {
  456.                         $filename = $wpdb->get_var("SELECT filename FROM $wpdb->nggpictures WHERE pid = '$intImageId' ");
  457.                         if ($filename) {
  458.                             $gallerypath = $wpdb->get_var("SELECT path FROM $wpdb->nggallery WHERE gid = '$gal_id' ");
  459.                             if ($gallerypath){
  460.                                 @unlink(WINABSPATH . $gallerypath . '/thumbs/thumbs_' .$filename);
  461.                                 @unlink(WINABSPATH . $gallerypath . '/' . $filename);
  462.                             }
  463.                             $delete_pic = $wpdb->query("DELETE FROM $wpdb->nggpictures WHERE pid = $intImageId");
  464.                         }
  465.                     }
  466.                 }
  467.             }
  468.         }
  469.  
  470.         // Function: Update Details
  471.         public function update_details() {
  472.             global $wpdb;
  473.             $arrUpdateFields = array();
  474.             if (isset($_POST['imagedescription']) && !empty($_POST['imagedescription'])) {
  475.                 $this->strDescription = $wpdb->escape($_POST['imagedescription']);
  476.                 $arrUpdateFields[] = "description = '$this->strDescription'";
  477.             } else {
  478.                 return;
  479.             }
  480.             if (isset ($_POST['alttext']) && !empty($_POST['alttext'])) {
  481.                 $this->strTitle = $wpdb->escape($_POST['alttext']);
  482.                 $arrUpdateFields[] = "alttext = '$this->strTitle'";
  483.             }
  484.             if (isset ($_POST['tags']) && !empty($_POST['tags'])) {
  485.                 $this->strKeywords = $_POST['tags'];
  486.             }
  487.             if (count($arrUpdateFields) > 0) {
  488.             if ( ! get_option('npu_exclude_select')  ) {
  489.                 $npu_exclude_id = 0;
  490.             } else {
  491.                 $npu_exclude_id = 1;
  492.             }
  493.                 $strUpdateFields = implode(", ", $arrUpdateFields);
  494.                 $pictures = $this->arrImageIds;
  495.                 if (count($pictures) > 0) {
  496.                     foreach( $pictures as $pid ) {
  497.                         $strQuery = "UPDATE $wpdb->nggpictures SET ";
  498.                         $strQuery .= $strUpdateFields. ", exclude = $npu_exclude_id WHERE pid = $pid";
  499.                         $wpdb->query($strQuery);
  500.                         $arrTags = explode(',', $this->strKeywords);
  501.                         wp_set_object_terms($pid, $arrTags, 'ngg_tag');
  502.                     }
  503.                 }
  504.             }
  505.         }
  506.  
  507.         // Function: Shortcode
  508.         public function shortcode_show_uploader($atts) {
  509.             global $wpdb;
  510.             $default_gallery = get_option('npu_default_gallery');
  511.             extract(shortcode_atts(array(
  512.                 'id' => $default_gallery,
  513.                 'template' => ''
  514.             ), $atts));
  515.             $count = count((array)$_FILES['imagefiles']['tmp_name']);
  516.             $x = $_FILES['imagefiles'];
  517.             for($i=0; $i<$count; $i++){
  518.             $_FILES['imagefiles']['name']= $x['name'][$i];
  519.             $_FILES['imagefiles']['type']= $x['type'][$i];
  520.             $_FILES['imagefiles']['tmp_name']= $x['tmp_name'][$i];
  521.             $_FILES['imagefiles']['error']= $x['error'][$i];
  522.             $_FILES['imagefiles']['size']= $x['size'][$i];
  523.             $this->handleUpload();
  524.             }
  525.             $out = $this->display_uploader($id, false, true, false);
  526.             return $out;
  527.         }
  528.  
  529.         // Function: Send Email Notice
  530.         public function sendEmail() {
  531.             if(get_option('npu_notification_email')){
  532.                 $to = get_option('npu_notification_email');
  533.                 $subject = "New Image Pending Review - NextGEN Public Uploader";
  534.                 $message = "A new image has been submitted and is waiting to be reviewed.";
  535.                 wp_mail( $to, $subject, $message);
  536.             }
  537.         }
  538.  
  539.     }
  540. }
  541.  
  542. // Create Uploader
  543. $npuUpload = new npuGalleryUpload();
  544.  
  545. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement