~xpattern/xpattern/admin-ui

« back to all changes in this revision

Viewing changes to textpattern/include/txp_file.php

  • Committer: Michael Manfre
  • Date: 2008-02-14 22:14:28 UTC
  • mfrom: (1216.1.44)
  • Revision ID: michael@erfnix-20080214221428-f8oai9c70648x074
Merge in txp trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
14
14
        Use of this mod denotes acceptance of the Textpattern license agreement
15
15
 
16
16
$HeadURL: http://svn.textpattern.com/development/4.0/textpattern/include/txp_file.php $
17
 
$LastChangedRevision: 2530 $
 
17
$LastChangedRevision: 2812 $
18
18
 
19
19
*/
20
20
 
33
33
        );
34
34
 
35
35
        if ($event == 'file') {
36
 
                require_privs('file');          
 
36
                require_privs('file');
37
37
 
38
38
                if(!$step or !in_array($step, array('file_change_max_size','file_change_pageby','file_db_add','file_delete','file_edit','file_insert','file_list','file_replace','file_save','file_reset_count','file_create'))){
39
39
                        file_list();
42
42
 
43
43
// -------------------------------------------------------------
44
44
 
45
 
        function file_list($message = '') 
 
45
        function file_list($message = '')
46
46
        {
47
47
                global $txpcfg, $extensions, $file_base_path, $file_statuses;
48
48
 
258
258
                        pageby_form('file', $file_list_pageby);
259
259
                }
260
260
        }
261
 
        
 
261
 
262
262
// -------------------------------------------------------------
263
263
 
264
264
        function file_search_form($crit, $method)
311
311
                        $condition .= '</span>';
312
312
 
313
313
                        $downloadlink = ($file_exists)?make_download_link($id, htmlspecialchars($filename),$filename):htmlspecialchars($filename);
314
 
                        
 
314
 
315
315
                        $created =
316
316
                                        n.graf(checkbox('publish_now', '1', $publish_now, '', 'publish_now').'<label for="publish_now">'.gTxt('set_to_now').'</label>').
317
317
 
358
358
                                                        )
359
359
                                                );
360
360
                        } else {
361
 
                        
 
361
 
362
362
                                $form = tr(
363
363
                                                        tda(
364
364
                                                                hed(gTxt('file_relink'),3).
415
415
                         created = now(),
416
416
                         modified = now()
417
417
                ");
418
 
                
 
418
 
419
419
                if ($rs) {
420
420
                        $GLOBALS['ID'] = mysql_insert_id( );
421
421
                        return $GLOBALS['ID'];
422
422
                }
423
423
 
424
424
                return false;
425
 
        }       
426
 
        
 
425
        }
 
426
 
427
427
// -------------------------------------------------------------
428
 
        function file_create() 
429
 
        {       
 
428
        function file_create()
 
429
        {
430
430
                global $txpcfg,$extensions,$txp_user,$file_base_path;
431
431
                extract($txpcfg);
432
432
                extract(doSlash(gpsa(array('filename','category','permissions','description'))));
433
433
 
434
434
                $size = filesize(build_file_path($file_base_path,$filename));
435
435
                $id = file_db_add($filename,$category,$permissions,$description, $size);
436
 
                
 
436
 
437
437
                if($id === false){
438
438
                        file_list(gTxt('file_upload_failed').' (db_add)');
439
439
                } else {
449
449
        }
450
450
 
451
451
// -------------------------------------------------------------
452
 
        function file_insert() 
453
 
        {       
 
452
        function file_insert()
 
453
        {
454
454
                global $txpcfg,$extensions,$txp_user,$file_base_path,$file_max_upload_size;
455
455
                extract($txpcfg);
456
456
                extract(doSlash(gpsa(array('category','permissions','description'))));
474
474
                if (!is_file(build_file_path($file_base_path,$name))) {
475
475
 
476
476
                        $id = file_db_add($name,$category,$permissions,$description,$size);
477
 
                        
 
477
 
478
478
                        if(!$id){
479
479
                                file_list(gTxt('file_upload_failed').' (db_add)');
480
480
                        } else {
481
481
 
482
482
                                $id = assert_int($id);
483
483
                                $newpath = build_file_path($file_base_path,trim($name));
484
 
                                
 
484
 
485
485
                                if(!shift_uploaded_file($file, $newpath)) {
486
486
                                        safe_delete("txp_file","id = $id");
487
487
                                        safe_alter("txp_file", "auto_increment=$id");
508
508
 
509
509
// -------------------------------------------------------------
510
510
        function file_replace()
511
 
        {       
 
511
        {
512
512
                global $txpcfg,$extensions,$txp_user,$file_base_path;
513
513
                extract($txpcfg);
514
514
                $id = assert_int(gps('id'));
515
515
 
516
516
                $rs = safe_row('filename','txp_file',"id = $id");
517
 
                
 
517
 
518
518
                if (!$rs) {
519
519
                        file_list(messenger(gTxt('invalid_id'),$id,''));
520
520
                        return;
521
521
                }
522
522
 
523
523
                extract($rs);
524
 
                
 
524
 
525
525
                $file = file_get_uploaded();
526
526
                $name = file_get_uploaded_name();
527
527
 
546
546
                                file_list($newpath.sp.gTxt('upload_dir_perms'));
547
547
                                // rename tmp back
548
548
                                rename($newpath.'.tmp',$newpath);
549
 
                                
 
549
 
550
550
                                // remove tmp upload
551
 
                                unlink($file);                          
 
551
                                unlink($file);
552
552
                        } else {
553
553
                                file_set_perm($newpath);
554
554
                                if ($size = filesize($newpath))
566
566
 
567
567
 
568
568
// -------------------------------------------------------------
569
 
        function file_reset_count() 
 
569
        function file_reset_count()
570
570
        {
571
571
                extract(doSlash(gpsa(array('id','filename','category','description'))));
572
 
                
 
572
 
573
573
                if ($id) {
574
574
                        $id = assert_int($id);
575
575
                        if (safe_update('txp_file','downloads = 0',"id = $id")) {
577
577
                        }
578
578
                } else {
579
579
                        file_list(gTxt('reset_file_count_failure'));
580
 
                }               
 
580
                }
581
581
        }
582
582
 
583
583
// -------------------------------------------------------------
584
584
 
585
 
        function file_save() 
 
585
        function file_save()
586
586
        {
587
587
                global $file_base_path;
588
588
 
599
599
                $perms = doSlash($permissions);
600
600
 
601
601
                $old_filename = fetch('filename','txp_file','id',$id);
602
 
                
 
602
 
603
603
                if ($old_filename != false && strcmp($old_filename, $filename) != 0)
604
604
                {
605
605
                        $old_path = build_file_path($file_base_path,$old_filename);
617
617
                                file_set_perm($new_path);
618
618
                        }
619
619
                }
620
 
                
 
620
 
621
621
                $created_ts = @safe_strtotime($year.'-'.$month.'-'.$day.' '.$hour.':'.$minute.':'.$second);
622
622
                if ($publish_now)
623
623
                        $created = 'now()';
715
715
// -------------------------------------------------------------
716
716
        function file_get_uploaded()
717
717
        {
718
 
                return get_uploaded_file($_FILES['thefile']['tmp_name']);               
 
718
                return get_uploaded_file($_FILES['thefile']['tmp_name']);
719
719
        }
720
 
        
 
720
 
721
721
// -------------------------------------------------------------
722
722
        function file_set_perm($file)
723
723
        {
724
724
                return @chmod($file,0644);
725
 
        }       
 
725
        }
726
726
 
727
727
// -------------------------------------------------------------
728
728
        function file_upload_form($label,$pophelp,$step,$id='')
729
729
        {
730
730
                global $file_max_upload_size;
731
 
                
 
731
 
732
732
                if (!$file_max_upload_size || intval($file_max_upload_size)==0) $file_max_upload_size = 2*(1024*1024);
733
 
                
 
733
 
734
734
                $max_file_size = (intval($file_max_upload_size) == 0) ? '': intval($file_max_upload_size);
735
 
                        
 
735
 
736
736
                return upload_form($label, $pophelp, $step, 'file', $id, $max_file_size);
737
737
        }
738
 
        
 
738
 
739
739
// -------------------------------------------------------------
740
 
        function file_change_pageby() 
 
740
        function file_change_pageby()
741
741
        {
742
742
                event_change_pageby('file');
743
743
                file_list();
744
744
        }
745
 
        
 
745
 
746
746
// -------------------------------------------------------------
747
 
        function file_change_max_size() 
 
747
        function file_change_max_size()
748
748
        {
749
749
                // DEPRECATED function; removed old code
750
750
                file_list();
758
758
                $url = filedownloadurl($id, $filename);
759
759
                return '<a href="'.$url.'">'.$label.'</a>';
760
760
        }
761
 
        
 
761
 
762
762
// -------------------------------------------------------------
763
763
        function get_filenames()
764
764
        {
765
765
                global $file_base_path;
766
 
                
 
766
 
767
767
                $dirlist = array();
768
768
 
769
769
                if (!is_dir($file_base_path))
770
 
                        return $dirlist;                
771
 
                
 
770
                        return $dirlist;
 
771
 
772
772
                if (chdir($file_base_path)) {
773
773
                        if (function_exists('glob'))
774
774
                                $g_array = glob("*.*");
779
779
                                        $g_array[] = $filename;
780
780
                                }
781
781
                                closedir($dh);
782
 
                                
 
782
 
783
783
                        }
784
 
                        
 
784
 
785
785
                        if ($g_array) {
786
786
                                foreach ($g_array as $filename) {
787
787
                                        if (is_file($filename)) {
799
799
                                $files[$a['filename']] = $a['filename'];
800
800
                        }
801
801
                }
802
 
                
 
802
 
803
803
                return array_diff($dirlist,$files);
804
804
        }
805
 
        
 
805
 
806
806
?>