Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 335 lines (273 sloc) 9.142 kb
e2a2349 Marc Weber adding php download script. I'm not proud of it - but it works
authored
1 <?php
2
3 // I just tried to make this downloadeer work.
4 // Probably there are many ways to improve it.
5
6 ob_start();
7
8 define('TMP', '/tmp/vam-downloader');
9 define('HISTORY_FILE', 'previous_downloads.txt');
10
11 define('NAME_CACHE_FILE', 'name_cache');
12 define('RECREATE_CACHE_HOURS', 48 * 2);
13
e894e4b Marc Weber udpate php file
authored
14 function name_cache(){
15 $a = json_decode(file_get_contents(NAME_CACHE_FILE), true);
16 ksort($a);
17 return $a;
18 }
19
20 function _htmlentities($s){
21 return htmlentities($s, ENT_QUOTES, "UTF-8" );
22 }
23
e2a2349 Marc Weber adding php download script. I'm not proud of it - but it works
authored
24 function downloadFile( $fullPath, $name = '' ){
25
26 if ($name == '')
27 $name = basename($fullPath);
28
29 // Must be fresh start
30 if( headers_sent() )
31 die('Headers Sent');
32
33 // Required for some browsers
34 if(ini_get('zlib.output_compression'))
35 ini_set('zlib.output_compression', 'Off');
36
37 // File Exists?
38 if( file_exists($fullPath) ){
39
40 // Parse Info / Get Extension
41 $fsize = filesize($fullPath);
42 $path_parts = pathinfo($name);
43 $ext = strtolower($path_parts["PATHINFO_EXTENSION"]);
44
45 // Determine Content Type
46 switch ($ext) {
47 case "pdf": $ctype="application/pdf"; break;
48 case "exe": $ctype="application/octet-stream"; break;
49 case "zip": $ctype="application/zip"; break;
50 case "doc": $ctype="application/msword"; break;
51 case "xls": $ctype="application/vnd.ms-excel"; break;
52 case "ppt": $ctype="application/vnd.ms-powerpoint"; break;
53 case "gif": $ctype="image/gif"; break;
54 case "png": $ctype="image/png"; break;
55 case "jpeg":
56 case "jpg": $ctype="image/jpg"; break;
57 default: $ctype="application/force-download";
58 }
59
60 header("Pragma: public"); // required
61 header("Expires: 0");
62 header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
63 header("Cache-Control: private",false); // required for certain browsers
64 header("Content-Type: $ctype");
65 header("Content-Disposition: attachment; filename=\"".$name."\";" );
66 header("Content-Transfer-Encoding: binary");
67 header("Content-Length: ".$fsize);
68 ob_clean();
69 flush();
70 readfile( $fullPath );
71
72 } else
73 throw new Exception("File $fullPath Not Found");
74 }
75
76
77 function vimrc($names, $silent){
78 $c = $silent ? 'install#Install' : 'ActivateAddons';
79 return "
80 set nocompatible
81 filetype indent plugin on | syn on
82 set hidden
83
84 let g:vim_addon_manager = {}
85 ".(
86 $silent ? "
87 redir! > log-vim.txt
88 let g:vim_addon_manager.dont_source = 1
89 let g:vim_addon_manager.auto_install = 1
90 let g:vim_addon_manager.log_to_buf = 1
91 \" activation is disabled manually enabling VAM-kr
92 exec 'set runtimepath+='.filter([\$HOME.'/.vim', \$HOME.'/vimfiles'],'isdirectory(v:val)')[0].'/vim-addons/vim-addon-manager-known-repositories'
93 " : "
94 "
95 )."
96
97
98 \" use either windows or linux location - whichever exists
99 exec 'set runtimepath+='.filter([\$HOME.'/.vim', \$HOME.'/vimfiles'],'isdirectory(v:val)')[0].'/vim-addons/vim-addon-manager'
100 call vam#".$c."(".json_encode($names).", {'auto_install' : 1})
101 ";
102 }
103
e894e4b Marc Weber udpate php file
authored
104 function vimrc2(){
e2a2349 Marc Weber adding php download script. I'm not proud of it - but it works
authored
105 return vimrc(array(), true)
106 .'
e894e4b Marc Weber udpate php file
authored
107 let info = {}
108 for n in vam#install#KnownAddons(0)
109 let repo = get(g:vim_addon_manager["plugin_sources"],n,{})
110 if repo != {}
111 let info[n] = vam#DisplayAddonInfoLines(n, repo)
112 endif
113 endfor
114
115 fun! Encode(thing, ...)
116 let nl = a:0 > 0 ? (a:1 ? "\\n" : "") : ""
117 if type(a:thing) == type("")
118 return \'"\'.escape(a:thing,\'"\\\').\'"\'
119 elseif type(a:thing) == type({}) && !has_key(a:thing, \'json_special_value\')
120 let pairs = []
121 for [Key, Value] in items(a:thing)
122 call add(pairs, Encode(Key).\':\'.Encode(Value))
123 unlet Key | unlet Value
124 endfor
125 return "{".nl.join(pairs, ",".nl)."}"
126 elseif type(a:thing) == type(0)
127 return a:thing
128 elseif type(a:thing) == type([])
129 return \'[\'.join(map(copy(a:thing), "Encode(v:val)"),",").\']\'
130 else
131 throw "unexpected new thing: ".string(a:thing)
132 endif
133 endf
134
135 call writefile( [Encode(info)], "names")
e2a2349 Marc Weber adding php download script. I'm not proud of it - but it works
authored
136 ';
137 }
138
139 function aszip($names){
140
141 set_time_limit(60*60);
142
143
144 file_put_contents(HISTORY_FILE, date('Y-m-d H:m:s').'|'.json_encode($names)."\n", FILE_APPEND | LOCK_EX );
145 $dir = TMP.'/'.rand(1000,9999);
146 system('mkdir -p '.$dir.'; chmod -R 777 '.$dir);
147 # mkdir($dir, '', true);
148 file_put_contents($dir.'/_vimrc', vimrc($names, false));
149 file_put_contents($dir.'/_vimrc-fetch', vimrc($names, true));
150 $cmd = '
151 dir='.$dir.'
152 cd $dir
153 exec 2>&1
154 exec > log.txt
155 mkdir -p .vim/vim-addons
156 PATH=/var/run/current-system/sw/bin
157 git clone --depth 1 git://github.com/MarcWeber/vim-addon-manager.git .vim/vim-addons/vim-addon-manager
158 # git clone --depth 1 git://github.com/MarcWeber/vim-addon-manager-known-repositories.git .vim/vim-addons/vim-addon-manager-known-repositories
159
160 export HOME=$dir
161
162 vim -u ~/_vimrc-fetch -U NONE -N -c "qa!" &>/dev/null
163
164 mv .vim vimfiles
165
166 zip -r vam.zip *
167 ';
168 echo $cmd;
169 system("$cmd 2>&1");
170 downloadFile( $dir.'/vam.zip', $name = 'vam.zip');
171 system('rm -fr '.$dir);
172 exit();
173 }
174
e894e4b Marc Weber udpate php file
authored
175 if (isset($_GET['plugin_info'])){
176 $a = name_cache();
177 $s = implode("\n", $a[base64_decode($_GET['plugin_info'])]);
178
94b8fcf Marc Weber latest downlsoade updates
authored
179 if (strpos($s, "deprecated:") != false){
e894e4b Marc Weber udpate php file
authored
180 echo "PAY ATTENTION TO THE deprecated NOTICE!";
181 }
182
183 echo '<pre>';
184 echo _htmlentities($s);
185 echo '</pre>';
186
187
188 echo '
189 </body>
190 </html>
191 ';
192 exit();
193 }
194
e2a2349 Marc Weber adding php download script. I'm not proud of it - but it works
authored
195 if (isset($_POST['names'])){
196 if ($_POST['spam_protection'] != 'V I M'){
197 echo 'you failed - SPAM protection. Reread instructions';
198 exit();
199 } else {
200 $names = preg_split('/[ ,]+/', $_POST['names']);
201 $errors = array();
94b8fcf Marc Weber latest downlsoade updates
authored
202 $name_cache = name_cache();
e894e4b Marc Weber udpate php file
authored
203 foreach($names as &$n){
e2a2349 Marc Weber adding php download script. I'm not proud of it - but it works
authored
204 if (preg_match('/^(VAM|vim-addon-manager|VAM-kr|vim-addon-manager-known-repositories)$/', $n)){
205 $errors[] = $n.' will be included automatically, retry';
206 }
e894e4b Marc Weber udpate php file
authored
207 $n = preg_replace('/[[\]\'"]/', '', $n);
94b8fcf Marc Weber latest downlsoade updates
authored
208 if (!isset($name_cache[$n]) && !preg_match('/^(github|git|hg):/', $n))
209 $errors[] = 'name '.$n.' unkown. Check against list at the bottom of main page';
e2a2349 Marc Weber adding php download script. I'm not proud of it - but it works
authored
210 }
211 if (count($errors) > 0){
212 foreach($errors as $err){
213 echo $err.'<br/>';
214 }
215 exit();
216 } else {
217 aszip($names);
218 }
219 }
220 }
221
222 ?>
223
224 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
225 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
226 <html>
227 <head>
94b8fcf Marc Weber latest downlsoade updates
authored
228 <title>VAM for Windows Downloader & VAM pool viewer</title>
e2a2349 Marc Weber adding php download script. I'm not proud of it - but it works
authored
229 <meta name="robots" content="index,nofollow" />
230 <meta http-equiv="content-type" content="text/html; charset=utf-8" />
231 </head>
232 <body>
233
94b8fcf Marc Weber latest downlsoade updates
authored
234 <style type="text/css" media="all">
235 .links a {
236 text-decoration: none;
237 color: #000;
238 }
239
240 .hide_link {
241 font-size: small;
242 color: #CCC !important;
243 }
244
245 </style>
246
247
e2a2349 Marc Weber adding php download script. I'm not proud of it - but it works
authored
248 <h1>VAM downloader for Windows users</h1>
249
94b8fcf Marc Weber latest downlsoade updates
authored
250 <div>
e2a2349 Marc Weber adding php download script. I'm not proud of it - but it works
authored
251 Installing git, mercurial, zip commands can be tedious on windows.
252 This page let's you download VAM and its plugins.
94b8fcf Marc Weber latest downlsoade updates
authored
253 </div>
254
255 <h2>HOWTO</h2>
256 <p>
257 Fill in the form, then copy the _vimrc and vimfiles into your user directory. https using self signed certificate is supported.
258 </p>
e2a2349 Marc Weber adding php download script. I'm not proud of it - but it works
authored
259
260 <form method="post">
e894e4b Marc Weber udpate php file
authored
261 Put in "V I M" (mind the spaces, spam protection): <br/>
e2a2349 Marc Weber adding php download script. I'm not proud of it - but it works
authored
262 <input type="text" name="spam_protection" value="value"> <br/>
263
264 The plugin names you want separated by , or space (VAM-kr and VAM will be included always):<br/>
e894e4b Marc Weber udpate php file
authored
265 Yes, from now one '"[] will be stripped so pasting a list is fine, also. This
266 way you can update everyhting at once easily.<br/>
e2a2349 Marc Weber adding php download script. I'm not proud of it - but it works
authored
267 <input type="text" name="names" value="tlib vim-addon-commenting"><br/>
268
269 <input type="submit" name="go" value="download zip"><br/>
270 Be patient. Fetching repositories by mercurial, svn or git can take some time.
271
272 </form>
273
274 If you have trouble contact Marc Weber by email (marco-oweber ATT gmx.de)
275 or on irc.freenode.net (#vim).
276
277 <br/>
278 <br/>
279 <br/>
280 <br/>
281 <br/>
282
283 <a href="<?php echo HISTORY_FILE; ?>">previous downloads</a>
284
94b8fcf Marc Weber latest downlsoade updates
authored
285 <br/>
286 You want to say thanks? Goto <a href="http://www.vim.org">http://www.vim.org</a> and visit some of the sponsors ..
287
e2a2349 Marc Weber adding php download script. I'm not proud of it - but it works
authored
288 <?php
289
290 function known_names(){
291 if (!file_exists(NAME_CACHE_FILE) || (( (time() - filemtime(NAME_CACHE_FILE)) / 60 / 60) > RECREATE_CACHE_HOURS)){
292 echo "\n<br/>updating name cache ..<br/>\n";
293 ob_end_flush();
294 flush();
295 $dir = TMP.'/'.rand(1000,9999);
296 system('mkdir -p '.$dir.'; chmod -R 777 '.$dir);
297
298 file_put_contents($dir.'/_vimrc-fetch', vimrc2());
299 $cmd = '
300 dir='.$dir.'
301 cd $dir
302 exec 2>&1
303 exec > log.txt
304 mkdir -p .vim/vim-addons
305 PATH=/var/run/current-system/sw/bin
306 git clone --depth 1 git://github.com/MarcWeber/vim-addon-manager.git .vim/vim-addons/vim-addon-manager
307 export HOME=$dir
308
309 vim -u ~/_vimrc-fetch -U NONE -N -c "qa!" &>/dev/null
310 ';
311 system("$cmd");
312 file_put_contents(NAME_CACHE_FILE, file_get_contents($dir.'/names'));
313 system('rm -fr $dir');
314 }
94b8fcf Marc Weber latest downlsoade updates
authored
315 $s = '<div class="links"> You can click on these links: </br>';
e894e4b Marc Weber udpate php file
authored
316 foreach(name_cache() as $key => $v){
94b8fcf Marc Weber latest downlsoade updates
authored
317 $dep = (strpos(implode("\n", $v), "deprecated:") != false);
318 $s .=
319 '<a class="'.($dep ? "hide_link" : '').'" target="n" href="?plugin_info='.base64_encode($key).'" >'
320 . _htmlentities($key)
321 .'</a>'
322 .', ';
e894e4b Marc Weber udpate php file
authored
323 }
94b8fcf Marc Weber latest downlsoade updates
authored
324 $s .= "</div>";
e2a2349 Marc Weber adding php download script. I'm not proud of it - but it works
authored
325 return $s;
326 }
327
328 echo '<br/><br/><br/><strong>This list of known plugin names is updated every '.RECREATE_CACHE_HOURS.' hours:</strong><br/>';
329 echo known_names();
330
331 ?>
332
333 </body>
334 </html>
Something went wrong with that request. Please try again.