diff -ur concerto-1.9.3-NoCAS/common/upload.php concerto-1.9.3-NoCAS-patched//common/upload.php --- concerto-1.9.3-NoCAS/common/upload.php 2010-03-14 17:10:28.000000000 -0700 +++ concerto-1.9.3-NoCAS-patched//common/upload.php 2011-10-14 12:41:36.377109240 -0700 @@ -74,6 +74,9 @@ var $retval; //I //Since a contructor can't return var $cid; //I //The ID of the content created (if you get that far) + var $mp_prefix; //I // filename prefix for multi-page input + var $mp_count; //I // page count (default=1) + function __construct($name_in, $start_date_in, $end_date_in, $feeds_in, $duration_in, $content_i_in, $ctype_in, $user_id_in, $auto_in = 1){ $this->name = $name_in; @@ -89,6 +92,9 @@ $this->auto = $auto_in; //This field specificies if the uploader should run in automatic mode or manual processing. I like auto mode, but thats just me $this->status = ""; + + $this->mp_prefix=""; + $this->mp_count=1; if($this->auto){ $this->filer(); @@ -97,6 +103,7 @@ return true; } } + //Determines which steps need to be applied to the content function filer(){ if(empty($this->feeds)){ @@ -204,10 +211,12 @@ return false; } } + function typer(){ //We could add enchanted MIME typing here, but for now we'll trust browsers return $this->content_i['type']; } + function jpeg_cleaner($loc = ''){ //echo "Starting JPEG cleaner"; $temp_dir = $this->get_temp_dir(); @@ -275,6 +284,7 @@ } } } + function png_cleaner($loc = ''){ //echo "Starting PNG cleaner"; $temp_dir = $this->get_temp_dir(); @@ -359,6 +369,7 @@ } } } + function gif_cleaner($loc = ''){ //echo "Starting GIF cleaner"; $temp_dir = $this->get_temp_dir(); @@ -428,42 +439,68 @@ } } - function pdf_cleaner(){ + function pdf_cleaner($loc = ''){ $temp_dir = $this->get_temp_dir(); $temp_name = $this->user_id . "-" . time() . ".pdf"; $temp_dest = $temp_dir . $temp_name; - if(move_uploaded_file($this->content_i['tmp_name'], $temp_dest)){ - $source = $temp_dest; - $target = $temp_dir . $this->user_id . "-" . time() . ".png"; - $command = "convert " . $source . " " . $target; //This command relies on Image Magick & GS to be installed - exec($command, $output, $return); - unlink($source); - if($return != 0){ - $this->status = $this->status . "Your PDF couldn't be converted to an image. "; - $this->retval = false; + if ($loc!='') + { + $temp_dest=$loc; + } + else + { + if(!move_uploaded_file($this->content_i['tmp_name'], $temp_dest)) + { + $this->retval=false; + $this->status=$this->status."Permissions error, contact an administrator. [Type: P]"; return false; } - $this->content_i['temp_name'] = $target; - $this->content_i['type'] = "image/png"; - if($this->auto){ - $this->png_cleaner($target); - } else { - $this->retval = true; - return true; - } - } else { - $this->status = $this->status . "Permissions error, contact an administrator. [Type: P]"; + } + $source = $temp_dest; + $target = $temp_dir . $this->user_id . "-" . time() . ".png"; + $command = "convert " . $source . " " . $target; //This command relies on Image Magick & GS to be installed + exec($command, $output, $return); + unlink($source); + if($return != 0){ + $this->status = $this->status . "Your PDF couldn't be converted to an image. "; $this->retval = false; return false; } + $this->content_i['temp_name'] = $target; + $this->content_i['type'] = "image/png"; + if($this->auto) + { + if (file_exists($target)) + $this->png_cleaner($target); + else + { + $this->mp_prefix=substr($target,0,strlen($target)-4); + $this->mp_count=0; + do + { + $target=$this->mp_prefix."-".$this->mp_count.".png"; + if (file_exists($target)) + { + $this->mp_count=$this->mp_count+1; + } + } + while (file_exists($target)); + $target=$this->mp_prefix."-0.png"; + $this->png_cleaner($target); + } + } else { + $this->retval = true; + return true; + } } + function ppt_cleaner(){ $temp_dir = $this->get_temp_dir(); $temp_name = $this->user_id . "-" . time() . ".ppt"; $temp_dest = $temp_dir . $temp_name; if(move_uploaded_file($this->content_i['tmp_name'], $temp_dest)){ $source = $temp_dest; - $target = $temp_dir . $this->user_id . "-" . time() . ".png"; + $target = $temp_dir . $this->user_id . "-" . time() . ".pdf"; $command = COMMON_DIR . "scripts/DocumentConverter.py " . $source . " " . $target; //This command relies on open office //echo $command; exec($command, $output, $return); @@ -475,43 +512,72 @@ return false; } $this->content_i['temp_name'] = $target; - $this->content_i['type'] = "image/png"; + $this->content_i['type'] = "application/pdf"; $this->status = $this->status . "Please check to ensure your powerpoint was correctly converted. "; if($this->auto){ - $this->png_cleaner($target); + $this->pdf_cleaner($target); } else { $this->retval = true; return true; } } else { - $this->status = $this->status . "PPT permission overflow. Please contact an administrator. "; - $this->retval = false; - return false; + $this->status = $this->status . "PPT permission overflow. Please contact an administrator. "; + $this->retval = false; + return false; } } + function mover($current_loc){ $this->content_o = $current_loc; $ext = substr(strrchr($current_loc, "."), 1); $content = new Content(); + $pp=pathinfo($current_loc); //print_r($this); - if($content->create_content($this->name, $this->user_id, $this->content_o, $this->mime_type, $this->type_id, $this->start_date, $this->end_date)){ - $this->cid = $content->id; - - $target_loc = IMAGE_DIR . $this->cid . "." . $ext; - rename($current_loc, $target_loc); - $content->content = $this->cid . "." . $ext; - $content->set_properties(); - - $this->submit_tofeeds(); - - $this->retval = true; - return true; //The content is finished uploading - } else { - $this->retval = false; - $this->status = $this->status . $content->status; - return false; //Failure making a content isn't a good thing + if ($this->mp_count==1) // single page? + { + if($content->create_content($this->name, $this->user_id, $this->content_o, $this->mime_type, $this->type_id, $this->start_date, $this->end_date)){ + $this->cid = $content->id; + + $fn=$pp['basename']; + $target_loc = IMAGE_DIR . $this->cid . "." . $ext; + rename($current_loc, $target_loc); + $content->content = $this->cid . "." . $ext; + $content->set_properties(); + + $this->submit_tofeeds(); + + $this->retval = true; + return true; //The content is finished uploading + } else { + $this->retval = false; + $this->status = $this->status . $content->status; + return false; //Failure making a content isn't a good thing + } + } + else + { + for ($i=0; $i<$this->mp_count; $i++) + { + $pagenum=$i+1; + $pagename= $this->name . " (" . $pagenum . "/" . $this->mp_count . ") "; + $c=new Content(); + if($c->create_content($pagename, $this->user_id, $this->content_o, $this->mime_type, $this->type_id, $this->start_date, $this->end_date)) + { + $this->cid = $c->id; + $current_loc= $this->mp_prefix . "-" . $i . ".png"; + $target_loc = IMAGE_DIR . $this->cid . ".png"; + rename($current_loc, $target_loc); + $c->content=$this->cid . ".png"; + $c->set_properties(); + $this->submit_tofeeds(); + } + } + $this->status=$this->status."The last page of your multi-page submission is shown here. "; + $this->retval=true; + return $this->retval; } } + function submit_tofeeds(){ //Submits the content to feeds, addressed the auto-approve issue for moderators foreach($this->feeds as $fid){ $f = new Feed($fid);