root/afridex/plugins/fresh-page/RCCWP_SnipshotCallback.php @ 23

Revision 21, 3.5 kB (checked in by admin, 18 years ago)
Line 
1
2<?
3
4require( dirname(__FILE__) . '/../../../wp-config.php' );
5if (!(is_user_logged_in() && current_user_can('edit_posts')))
6        die("Athentication failed!");
7
8
9        //print_r("Req\n");
10        //print_r($_REQUEST);
11        //print_r("Files\n");
12        //print_r($_FILES);
13        //print_r("Get\n");
14        //print_r($_GET);
15        //print_r("Post\n");
16        //print_r($_POST);
17//$filepath = dirname(__FILE__) . '/files/log.txt';
18//file_put_contents($filepath, , FILE_APPEND);
19
20//
21    //Snipshot callback test
22    //
23    //Install this script on your server to test and debug callbacks from
24    //www.snipshot.com. Note: this script will need read and write access
25    //to your image directory.
26
27    //CHANGE THIS TO THE DIRECTORY WHERE YOUR IMAGES WILL BE SAVED
28    $IMG_DIR = './files';
29    chdir($IMG_DIR);
30   
31    //CHANGE THIS TO THE NAME OF THE FIELD THAT CARRIES THE IMAGE DATA OR URL
32    $OUTPUT = 'file';
33
34    function print_pre($r, $desc=''){
35        echo '<pre>' . $desc . ' ' . print_r($r) . '</pre>';
36    }
37    function glob_rsort_modtime( $patt ) {
38        if ( ( $files = @glob($patt, GLOB_BRACE) ) === false )
39            return array(false, 'Glob error.');
40        if ( !count($files) )
41            return array(false, 'No files found.');
42        $rtn = array();
43        foreach ( $files as $filename )
44            $rtn[$filename] = filemtime($filename);
45        arsort($rtn);
46        reset($rtn);
47        foreach ( $rtn as $filename => $t )
48            $rtn[$filename] = date('r', $t);
49        return $rtn;
50    }
51?>
52<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
53<html lang="en">
54<head>
55    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
56    <title>Snipshot callback</title>
57   
58    <? 
59        $operationSuccess = "false";
60        if (!empty($_REQUEST)){
61            //print_pre($_REQUEST, 'REQUEST');
62            if (!empty($_FILES)){ //snipshot_callback_agent=snipshot
63                //print_pre($_FILES[$OUTPUT], 'FILES');   
64                move_uploaded_file(
65                    $_FILES[$OUTPUT]['tmp_name'], 
66                    $_FILES[$OUTPUT]['name']
67                );//file_put_contents($filepath, time()."trying ".$_FILES[$OUTPUT]['name']."\n", FILE_APPEND);
68                //file_put_contents("log.txt", time()."trying ".basename($_GET[$OUTPUT]));
69            } 
70            else if (!empty($_GET[$OUTPUT])){ //snipshot_callback_agent=user
71                $data = file_get_contents($_GET[$OUTPUT]);
72                //echo "\nfrom ----".$_GET[$OUTPUT]."\n";
73                $fp = fopen(basename($_GET[$OUTPUT]), 'wb');
74                //echo "\nfrom ----".basename($_GET[$OUTPUT])."\n";
75                fwrite($fp, $data);
76                fclose($fp);
77                chmod(basename($_GET[$OUTPUT]), 0644);
78                $filename = basename($_GET[$OUTPUT]);
79
80                //$filename = 'hello_'.time() . '.jpg';
81                //rename(basename($_GET[$OUTPUT]), $filename);
82
83                $operationSuccess = "true";
84                //file_put_contents("log.txt", var_export($_REQUEST, true)."\n new name = $filename\n",FILE_APPEND);
85            }
86        }
87       
88        //$file_list = glob_rsort_modtime('{*.jpg,*.png,*.gif,*.tif,*.psd,*.pdf}');
89        //$file_list = array_slice($file_list, 0, 10);
90        //print_pre($file_list, 'LAST 10 IMAGES');
91        //foreach($file_list as $fn => $mt){
92         //   echo '<p><img src="'.$fn.'"/>';
93        //}
94    ?>
95</head>
96<body>
97
98        <script language="javascript">
99
100                var par = window.parent.document;
101               
102                if (<?=$operationSuccess?>){
103                       
104
105
106                }
107               
108        </script>
109        <h3> The file was updated successfuly</h3>
110        <p> Please save the page in order to see the changes. <a href="" onclick="parent.GB_hide();">Close this window</a> </p>
111</body>
112</html>
Note: See TracBrowser for help on using the browser.