Lines 74-79
Link Here
|
74 |
var $retval; //I //Since a contructor can't return |
74 |
var $retval; //I //Since a contructor can't return |
75 |
var $cid; //I //The ID of the content created (if you get that far) |
75 |
var $cid; //I //The ID of the content created (if you get that far) |
76 |
|
76 |
|
|
|
77 |
var $mp_prefix; //I // filename prefix for multi-page input |
78 |
var $mp_count; //I // page count (default=1) |
79 |
|
77 |
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){ |
80 |
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){ |
78 |
|
81 |
|
79 |
$this->name = $name_in; |
82 |
$this->name = $name_in; |
Lines 89-94
Link Here
|
89 |
$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 |
92 |
$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 |
90 |
|
93 |
|
91 |
$this->status = ""; |
94 |
$this->status = ""; |
|
|
95 |
|
96 |
$this->mp_prefix=""; |
97 |
$this->mp_count=1; |
92 |
|
98 |
|
93 |
if($this->auto){ |
99 |
if($this->auto){ |
94 |
$this->filer(); |
100 |
$this->filer(); |
Lines 97-102
Link Here
|
97 |
return true; |
103 |
return true; |
98 |
} |
104 |
} |
99 |
} |
105 |
} |
|
|
106 |
|
100 |
//Determines which steps need to be applied to the content |
107 |
//Determines which steps need to be applied to the content |
101 |
function filer(){ |
108 |
function filer(){ |
102 |
if(empty($this->feeds)){ |
109 |
if(empty($this->feeds)){ |
Lines 204-213
Link Here
|
204 |
return false; |
211 |
return false; |
205 |
} |
212 |
} |
206 |
} |
213 |
} |
|
|
214 |
|
207 |
function typer(){ |
215 |
function typer(){ |
208 |
//We could add enchanted MIME typing here, but for now we'll trust browsers |
216 |
//We could add enchanted MIME typing here, but for now we'll trust browsers |
209 |
return $this->content_i['type']; |
217 |
return $this->content_i['type']; |
210 |
} |
218 |
} |
|
|
219 |
|
211 |
function jpeg_cleaner($loc = ''){ |
220 |
function jpeg_cleaner($loc = ''){ |
212 |
//echo "Starting JPEG cleaner"; |
221 |
//echo "Starting JPEG cleaner"; |
213 |
$temp_dir = $this->get_temp_dir(); |
222 |
$temp_dir = $this->get_temp_dir(); |
Lines 275-280
Link Here
|
275 |
} |
284 |
} |
276 |
} |
285 |
} |
277 |
} |
286 |
} |
|
|
287 |
|
278 |
function png_cleaner($loc = ''){ |
288 |
function png_cleaner($loc = ''){ |
279 |
//echo "Starting PNG cleaner"; |
289 |
//echo "Starting PNG cleaner"; |
280 |
$temp_dir = $this->get_temp_dir(); |
290 |
$temp_dir = $this->get_temp_dir(); |
Lines 359-364
Link Here
|
359 |
} |
369 |
} |
360 |
} |
370 |
} |
361 |
} |
371 |
} |
|
|
372 |
|
362 |
function gif_cleaner($loc = ''){ |
373 |
function gif_cleaner($loc = ''){ |
363 |
//echo "Starting GIF cleaner"; |
374 |
//echo "Starting GIF cleaner"; |
364 |
$temp_dir = $this->get_temp_dir(); |
375 |
$temp_dir = $this->get_temp_dir(); |
Lines 428-469
Link Here
|
428 |
} |
439 |
} |
429 |
} |
440 |
} |
430 |
|
441 |
|
431 |
function pdf_cleaner(){ |
442 |
function pdf_cleaner($loc = ''){ |
432 |
$temp_dir = $this->get_temp_dir(); |
443 |
$temp_dir = $this->get_temp_dir(); |
433 |
$temp_name = $this->user_id . "-" . time() . ".pdf"; |
444 |
$temp_name = $this->user_id . "-" . time() . ".pdf"; |
434 |
$temp_dest = $temp_dir . $temp_name; |
445 |
$temp_dest = $temp_dir . $temp_name; |
435 |
if(move_uploaded_file($this->content_i['tmp_name'], $temp_dest)){ |
446 |
if ($loc!='') |
436 |
$source = $temp_dest; |
447 |
{ |
437 |
$target = $temp_dir . $this->user_id . "-" . time() . ".png"; |
448 |
$temp_dest=$loc; |
438 |
$command = "convert " . $source . " " . $target; //This command relies on Image Magick & GS to be installed |
449 |
} |
439 |
exec($command, $output, $return); |
450 |
else |
440 |
unlink($source); |
451 |
{ |
441 |
if($return != 0){ |
452 |
if(!move_uploaded_file($this->content_i['tmp_name'], $temp_dest)) |
442 |
$this->status = $this->status . "Your PDF couldn't be converted to an image. "; |
453 |
{ |
443 |
$this->retval = false; |
454 |
$this->retval=false; |
|
|
455 |
$this->status=$this->status."Permissions error, contact an administrator. [Type: P]"; |
444 |
return false; |
456 |
return false; |
445 |
} |
457 |
} |
446 |
$this->content_i['temp_name'] = $target; |
458 |
} |
447 |
$this->content_i['type'] = "image/png"; |
459 |
$source = $temp_dest; |
448 |
if($this->auto){ |
460 |
$target = $temp_dir . $this->user_id . "-" . time() . ".png"; |
449 |
$this->png_cleaner($target); |
461 |
$command = "convert " . $source . " " . $target; //This command relies on Image Magick & GS to be installed |
450 |
} else { |
462 |
exec($command, $output, $return); |
451 |
$this->retval = true; |
463 |
unlink($source); |
452 |
return true; |
464 |
if($return != 0){ |
453 |
} |
465 |
$this->status = $this->status . "Your PDF couldn't be converted to an image. "; |
454 |
} else { |
|
|
455 |
$this->status = $this->status . "Permissions error, contact an administrator. [Type: P]"; |
456 |
$this->retval = false; |
466 |
$this->retval = false; |
457 |
return false; |
467 |
return false; |
458 |
} |
468 |
} |
|
|
469 |
$this->content_i['temp_name'] = $target; |
470 |
$this->content_i['type'] = "image/png"; |
471 |
if($this->auto) |
472 |
{ |
473 |
if (file_exists($target)) |
474 |
$this->png_cleaner($target); |
475 |
else |
476 |
{ |
477 |
$this->mp_prefix=substr($target,0,strlen($target)-4); |
478 |
$this->mp_count=0; |
479 |
do |
480 |
{ |
481 |
$target=$this->mp_prefix."-".$this->mp_count.".png"; |
482 |
if (file_exists($target)) |
483 |
{ |
484 |
$this->mp_count=$this->mp_count+1; |
485 |
} |
486 |
} |
487 |
while (file_exists($target)); |
488 |
$target=$this->mp_prefix."-0.png"; |
489 |
$this->png_cleaner($target); |
490 |
} |
491 |
} else { |
492 |
$this->retval = true; |
493 |
return true; |
494 |
} |
459 |
} |
495 |
} |
|
|
496 |
|
460 |
function ppt_cleaner(){ |
497 |
function ppt_cleaner(){ |
461 |
$temp_dir = $this->get_temp_dir(); |
498 |
$temp_dir = $this->get_temp_dir(); |
462 |
$temp_name = $this->user_id . "-" . time() . ".ppt"; |
499 |
$temp_name = $this->user_id . "-" . time() . ".ppt"; |
463 |
$temp_dest = $temp_dir . $temp_name; |
500 |
$temp_dest = $temp_dir . $temp_name; |
464 |
if(move_uploaded_file($this->content_i['tmp_name'], $temp_dest)){ |
501 |
if(move_uploaded_file($this->content_i['tmp_name'], $temp_dest)){ |
465 |
$source = $temp_dest; |
502 |
$source = $temp_dest; |
466 |
$target = $temp_dir . $this->user_id . "-" . time() . ".png"; |
503 |
$target = $temp_dir . $this->user_id . "-" . time() . ".pdf"; |
467 |
$command = COMMON_DIR . "scripts/DocumentConverter.py " . $source . " " . $target; //This command relies on open office |
504 |
$command = COMMON_DIR . "scripts/DocumentConverter.py " . $source . " " . $target; //This command relies on open office |
468 |
//echo $command; |
505 |
//echo $command; |
469 |
exec($command, $output, $return); |
506 |
exec($command, $output, $return); |
Lines 475-517
Link Here
|
475 |
return false; |
512 |
return false; |
476 |
} |
513 |
} |
477 |
$this->content_i['temp_name'] = $target; |
514 |
$this->content_i['temp_name'] = $target; |
478 |
$this->content_i['type'] = "image/png"; |
515 |
$this->content_i['type'] = "application/pdf"; |
479 |
$this->status = $this->status . "Please check to ensure your powerpoint was correctly converted. "; |
516 |
$this->status = $this->status . "Please check to ensure your powerpoint was correctly converted. "; |
480 |
if($this->auto){ |
517 |
if($this->auto){ |
481 |
$this->png_cleaner($target); |
518 |
$this->pdf_cleaner($target); |
482 |
} else { |
519 |
} else { |
483 |
$this->retval = true; |
520 |
$this->retval = true; |
484 |
return true; |
521 |
return true; |
485 |
} |
522 |
} |
486 |
} else { |
523 |
} else { |
487 |
$this->status = $this->status . "PPT permission overflow. Please contact an administrator. "; |
524 |
$this->status = $this->status . "PPT permission overflow. Please contact an administrator. "; |
488 |
$this->retval = false; |
525 |
$this->retval = false; |
489 |
return false; |
526 |
return false; |
490 |
} |
527 |
} |
491 |
} |
528 |
} |
|
|
529 |
|
492 |
function mover($current_loc){ |
530 |
function mover($current_loc){ |
493 |
$this->content_o = $current_loc; |
531 |
$this->content_o = $current_loc; |
494 |
$ext = substr(strrchr($current_loc, "."), 1); |
532 |
$ext = substr(strrchr($current_loc, "."), 1); |
495 |
$content = new Content(); |
533 |
$content = new Content(); |
|
|
534 |
$pp=pathinfo($current_loc); |
496 |
//print_r($this); |
535 |
//print_r($this); |
497 |
if($content->create_content($this->name, $this->user_id, $this->content_o, $this->mime_type, $this->type_id, $this->start_date, $this->end_date)){ |
536 |
if ($this->mp_count==1) // single page? |
498 |
$this->cid = $content->id; |
537 |
{ |
499 |
|
538 |
if($content->create_content($this->name, $this->user_id, $this->content_o, $this->mime_type, $this->type_id, $this->start_date, $this->end_date)){ |
500 |
$target_loc = IMAGE_DIR . $this->cid . "." . $ext; |
539 |
$this->cid = $content->id; |
501 |
rename($current_loc, $target_loc); |
540 |
|
502 |
$content->content = $this->cid . "." . $ext; |
541 |
$fn=$pp['basename']; |
503 |
$content->set_properties(); |
542 |
$target_loc = IMAGE_DIR . $this->cid . "." . $ext; |
504 |
|
543 |
rename($current_loc, $target_loc); |
505 |
$this->submit_tofeeds(); |
544 |
$content->content = $this->cid . "." . $ext; |
506 |
|
545 |
$content->set_properties(); |
507 |
$this->retval = true; |
546 |
|
508 |
return true; //The content is finished uploading |
547 |
$this->submit_tofeeds(); |
509 |
} else { |
548 |
|
510 |
$this->retval = false; |
549 |
$this->retval = true; |
511 |
$this->status = $this->status . $content->status; |
550 |
return true; //The content is finished uploading |
512 |
return false; //Failure making a content isn't a good thing |
551 |
} else { |
|
|
552 |
$this->retval = false; |
553 |
$this->status = $this->status . $content->status; |
554 |
return false; //Failure making a content isn't a good thing |
555 |
} |
556 |
} |
557 |
else |
558 |
{ |
559 |
for ($i=0; $i<$this->mp_count; $i++) |
560 |
{ |
561 |
$pagenum=$i+1; |
562 |
$pagename= $this->name . " (" . $pagenum . "/" . $this->mp_count . ") "; |
563 |
$c=new Content(); |
564 |
if($c->create_content($pagename, $this->user_id, $this->content_o, $this->mime_type, $this->type_id, $this->start_date, $this->end_date)) |
565 |
{ |
566 |
$this->cid = $c->id; |
567 |
$current_loc= $this->mp_prefix . "-" . $i . ".png"; |
568 |
$target_loc = IMAGE_DIR . $this->cid . ".png"; |
569 |
rename($current_loc, $target_loc); |
570 |
$c->content=$this->cid . ".png"; |
571 |
$c->set_properties(); |
572 |
$this->submit_tofeeds(); |
573 |
} |
574 |
} |
575 |
$this->status=$this->status."The last page of your multi-page submission is shown here. "; |
576 |
$this->retval=true; |
577 |
return $this->retval; |
513 |
} |
578 |
} |
514 |
} |
579 |
} |
|
|
580 |
|
515 |
function submit_tofeeds(){ //Submits the content to feeds, addressed the auto-approve issue for moderators |
581 |
function submit_tofeeds(){ //Submits the content to feeds, addressed the auto-approve issue for moderators |
516 |
foreach($this->feeds as $fid){ |
582 |
foreach($this->feeds as $fid){ |
517 |
$f = new Feed($fid); |
583 |
$f = new Feed($fid); |