xref: /plugin/zwidoku/zwipush.php (revision f82bbc904bd835fc66a3f52ffaef251433904ec2)
1<?php
2
3/* Process submit request.
4 * S.Chekanov
5**/
6
7
8if(isset($_POST["submit"]) == false && isset($_POST["download"]) == false ) die("Nothing to post");
9if(isset($_POST["zwifile"]) == false) die("No ZWI name");
10if(isset($_POST["posturl"]) == false) die("No post URL name");
11if(isset($_POST["postkey"]) == false) die("No key for URL");
12if(isset($_POST["zwititle"]) == false) die("No title");
13if(isset($_POST["backlink"]) == false) die("No backlink");
14if(isset($_POST["extpath"]) == false) die("No extension path");
15if(isset($_POST["permission"]) == false) die("No permission is given");
16
17
18//print("OK");
19// 0 means nothing to be done
20$Xsubmit=0;
21if(isset($_POST["submit"]) == true) $Xsubmit=1; // send to network
22if(isset($_POST["download"]) == true) $Xsubmit=2; // download
23if ($Xsubmit == 0) die("No action");
24
25
26                            $zwifile=$_POST['zwifile'];
27                            if (file_exists($zwifile)==false) die("ZWI file is missing: $zwifile");
28                            $filePath=$_POST['zwifile'];
29                            $target_url= $_POST['posturl'] . 'put.php';
30                            $postkey=$_POST["postkey"];
31                            $title=$_POST["zwititle"];
32                            $backlink=$_POST["backlink"];
33                            $extpath=$_POST["extpath"];
34                            $permission=$_POST["permission"];
35
36
37// download first
38if ($Xsubmit == 2){
39                    header('Content-Description: File Transfer');
40                                        if (headers_sent()){
41                                                echo ('Some data has already been output to browser, can\'t send ZWI file');
42                                                exit();
43                                        }
44
45
46                       header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
47                       header('Content-Type: application/force-download');
48                       //header("Content-Transfer-Encoding: Binary");
49                       header("Content-type: application/zip");
50                       header("Content-disposition: attachment; filename=\"" . basename($zwifile) . "\"");
51                       readfile($zwifile);
52                       //unlink($zwifile); // delete file
53                       //die();
54                       //echo "<script type='text/javascript'>window.location.replace('" . $newlink . "');</script>";
55
56}
57
58
59
60// submit
61if ($Xsubmit == 1){
62
63			    $ch = curl_init();
64                            curl_setopt($ch, CURLOPT_URL,$target_url);
65                            curl_setopt($ch, CURLOPT_POST,true);
66                            curl_setopt($ch, CURLOPT_RETURNTRANSFER,true);
67                            //If the function curl_file_create exists
68                            if(function_exists('curl_file_create')){
69                              //Use the recommended way, creating a CURLFile object.
70                              $filePath = curl_file_create($filePath);
71                            } else{
72                               //Otherwise, do it the old way.
73                               //Get the canonicalized pathname of our file and prepend
74                               //the @ character.
75                               $filePath = '@' . realpath($filePath);
76                               //Turn off SAFE UPLOAD so that it accepts files
77                               //starting with an @
78                               curl_setopt($ch, CURLOPT_SAFE_UPLOAD, false);
79                            }
80
81                             //Setup our POST fields
82                             $postFields = array(
83                               'zwi' => $filePath,
84                               'pass' => $postkey
85                             );
86                             curl_setopt($ch, CURLOPT_POSTFIELDS, $postFields);
87                             $txt=curl_exec($ch);
88                             curl_close($ch);
89                             $pos1 = strpos($txt, "successfully");
90                             $pos2 = strpos($txt, "updated");
91
92			     if ($txt == false)
93				     die("Failed to send the ZWI file. No server response?");
94                             //$isOK=false;
95                             //if ($pos1 !== false ) $isOK=true;
96                             //if ($pos2 !== false ) $isOK=true;
97
98                             //if ($isOK == false)
99                             //      die("Failed to send the ZWI file. No server response? File: ". $filePath. "mess:" . $txt);
100
101                             $txt=nl2br($txt);
102                             print($txt);
103
104
105$str = <<<EOD
106<!DOCTYPE html>
107<html class="client-nojs" lang="en" dir="ltr">
108<head>
109<meta charset="UTF-8"/>
110<title>ZWI confirm</title>
111<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes, minimum-scale=0.25, maximum-scale=5.0"/>
112<link rel="stylesheet" type="text/css" href="$extpath/css/zwimaker.css" />
113</head>
114<body>
115<p>
116</p>
117<center>
118<h3>'$title' submitted!</h3>
119<p>
120</p>
121Read this article in the Encyclosphere Network in 10 minutes using
122<a href="https://encycloreader.org/">EncycloReader</a>  created by the <a href='https://encyclosphere.org/about/'><img src='$extpath/img/Encyclosphere_logo24px.png' alt="Encyclosphere" style='vertical-align:middle;margin:0;'/>KSF</a>
123<p>
124</p>
125<form>
126<input type="reset" name="reset" value="Back" onClick="window.location='$backlink';" />
127</form>
128<center>
129</body>
130</html>
131EOD;
132                              print($str);
133                              //unlink($zwifile); // delete file
134
135} // end submit
136
137
138
139
140
141
142
143?>
144