changed git call from https to git readonly
[atutor.git] / mods / wiki / plugins / aview / imgappend.php
1 <?php
2
3 /*
4    This plugin provides a below-every-page image uploading function
5    similar to the one of the edit page. The advantage is faster access
6    and that it is working without JavaScript.
7 */
8
9
10 $ewiki_plugins["view_append"][] = "ewiki_aview_image_append";
11 $ewiki_plugins["action"]["imageappend"] = "ewiki_action_image_append";
12
13
14 $ewiki_t["en"]["IMAGEAPPEND_FORM0"] = '<img src="imageappend.jpeg" width="80" height="60" alt="imageappend" align="left" /> <b>Append an Image</b><br />';
15 $ewiki_t["en"]["NO_IMAGEAPPEND"] = "The image uploading succeeded, but the page couldn't get updated. Please try the image upload function on EditThisPage.";
16
17
18
19
20 function ewiki_aview_image_append($id, $data, $action) {
21
22    $URL = ewiki_script("imageappend", $id);
23    $TXT = ewiki_t("IMAGEAPPEND_FORM0");
24    $BTN1 = ewiki_t("UPLOAD_PICTURE_BUTTON");
25
26    $accept = (defined("EWIKI_IMAGE_ACCEPT") ? ' accept="'.EWIKI_IMAGE_ACCEPT.'">' : "");
27    return(<<<___
28 <div class="imageappend">
29 <form action="$URL" method="POST" enctype="multipart/form-data">
30   $TXT
31   <input type="file" name="imagefile" $accept><br />
32   <input type="submit" value="$BTN1">
33 </form>
34 </div>
35 ___
36    );
37 }
38
39
40
41 function ewiki_action_image_append($id, $data, $action) {
42
43    #-- invalid $id value
44    if (empty($data) ||
45        !$data["version"] ||
46        (EWIKI_DB_F_TEXT != ($data["flags"] & EWIKI_DB_F_TYPE)))
47    {
48       $o = ewiki_t("CANNOTCHANGEPAGE");
49    }
50
51    #-- temporary upload-file found
52    elseif ($fa = $_FILES["imagefile"]) {
53
54       #-- guess HTTP meta data
55       $meta = array(
56          "X-Content-Type" => $fa["type"],
57         #"X-Content-Length" => $fa["size"],
58       );
59       if ($s = $fa["name"]) {
60          $meta["Content-Location"] = $s;
61          ($p = 0) or
62          ($p = strrpos($s, "/")) and ($p++) or
63          ($p = strrpos($s, '\\')) and ($p++);
64          $meta["Content-Disposition"] = 'inline; filename="'.urlencode(substr($s, $p)).'"';
65       }
66
67       #-- proceed an image (reject binary, resize if too large)
68       $result = ewiki_binary_save_image(
69           $fa["tmp_name"],      // uploaded file location
70           "",                   // no predefined $id
71           "RETURN",             // do not die() on error
72           $meta,                // =Content-Location
73           0,                    // =do not accept plain binary
74           1                     // =care for images
75       );
76
77       #-- database rejected file
78       if (!$result) {
79          $o = ewiki_t("BIN_NOIMG");
80       }
81
82       #-- if picture stored in db
83       else {
84
85          $loop = 3;
86          while($loop--) {
87
88             $data = ewiki_db::GET($id);
89
90             $data["version"]++;
91             $data["content"] = rtrim($data["content"], "\n") . "\n\n" .
92                                "[\"AppendedPicture\"$result]\n\n\n";
93
94             $result = ewiki_db::WRITE($data);
95
96             if ($result) {
97                break;
98             }
99
100          }
101
102          if ($result) {
103             $o = ewiki_page("view/$id");
104             ewiki_log("image appended to '$id'");
105          }
106          else {
107             $o .= ewiki_t("NO_IMAGEAPPEND");
108          }
109
110       }
111
112    }
113
114    #-- no upload-file
115    else {
116       $o .= ewiki_t("BIN_NOIMG");
117 #"You did not select an image, or something went really wrong during tansmission. Plase go back to the previous page.";
118    }
119
120    return($o);
121 }
122
123
124 ?>