File: pluginserver.php

package info (click to toggle)
tulip 4.6.0dfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 139,284 kB
  • ctags: 35,942
  • sloc: cpp: 289,758; ansic: 27,264; python: 1,256; sh: 923; yacc: 522; xml: 337; makefile: 258; php: 66; lex: 55
file content (44 lines) | stat: -rw-r--r-- 1,346 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
<?php

function contains($str,$substring) {
  if (empty($substring))
    return true;
  return (stripos($str,$substring) !== false);
}

function is_available($path,$os,$arch) {
  return file_exists($path.'/data-'.$os.$arch.'.zip');
}

function find_plugin($name,$os,$arch,$category,$tulip) {
  $serverxml = simplexml_load_file('server.xml');
  $result = array();
  $pluginsxml = $serverxml->xpath("plugins");
  foreach($pluginsxml[0] as $plugin) {
	$attr = $plugin->attributes();
	$attr_name = $attr['name'];
	$pluginname = (string)$attr_name;
    // Check if plugin name matches query
    if (contains($pluginname,$name) === true) {
      $plugindesc = array();
      foreach($plugin->attributes() as $id => $value) {
        $plugindesc[$id]=(string)$value;
      }
      if (is_available($plugindesc['path'],$os,$arch) && contains($plugindesc['category'],$category) && $plugindesc['tulip'] === $tulip)
        array_push($result,$plugindesc);
    }
  }
  return $result;
}

function data_url($name,$os,$arch,$tulip) {
  $find_results = find_plugin($name,$os,$arch,"",$tulip); 
  $plugindesc = $find_results[0];
  return 'http://tulip.labri.fr/'.dirname($_SERVER['REQUEST_URI']).'/'.$plugindesc['path'].'/data-'.$os.$arch.'.zip';
}

function fetch_plugin($name,$os,$arch,$tulip) {
  header('Location: '.data_url($name,$os,$arch,$tulip));
}

?>