Offline Server  1.6
PHP API documentation
 All Data Structures Namespaces Files Functions Variables Pages
off_dlclient.php
Go to the documentation of this file.
1 <?php
2 
3 function off_dlclient(&$action) {
4  include_once('OFFLINE/Class.OfflineClientBuilder.php');
5 
6  $action->parent->AddJsRef("OFFLINE/Layout/off_dlclient.js");
7  $action->parent->AddCssRef("CORE:welcome.css", true);
8  $action->parent->AddCssRef("OFFLINE:off_dlclient.css", true);
9 
10  $action->lay->set("thisyear",strftime("%Y", time()));
11  $action->lay->set("userRealName",$action->user->firstname." ".$action->user->lastname);
12 
13  /* Get parameters */
14  $parms = array();
15  $parms['os'] = getHttpVars('os', 'none');
16  $parms['arch'] = getHttpVars('arch', 'none');
17 
18  $clientDir = $action->parent->getParam('OFFLINE_CLIENT_BUILD_OUTPUT_DIR', '');
19  if( ! is_dir($clientDir) ) {
20  $action->ExitError(sprintf('OFFLINE_CLIENT_BUILD_OUTPUT_DIR: '._("OFFLINE:%s directory not found"), $clientDir));
21  return;
22  }
23  $clientDir = realpath($clientDir);
24 
25  // 3rd parties developpement
26  $fext = $action->getLayoutFile("off_externals.xml");
27  $action->lay->set("HAVE_EXTERNALS", false);
28  $trd = array();
29  if (file_exists($fext)) {
30  $fdata = file($fext);
31  foreach($fdata as $k=>$v) {
32  $action->lay->set("HAVE_EXTERNALS", true);
33  $ds = explode("#", $v);
34  $trd[] = array( "site"=>$ds[0], "name"=>$ds[1], "license"=>$ds[2]);
35  }
36  }
37  $action->lay->setBlockData("EXTERNALS", $trd);
38 
39  /**
40  * os/arch download requested?
41  */
42  if( $parms['os'] != 'none' && $parms['arch'] != 'none' ) {
43  return sendClient($action, $parms['os'], $parms['arch']);
44  }
45 
46  /**
47  * Create list of os/arch clients available to download
48  */
49  $ocb = new OfflineClientBuilder();
50  $osArchList = $ocb->getOsArchList();
51 
52  $action->lay->set("version",$ocb->getOfflineInfo('Version'));
53  $action->lay->set("buildid",$ocb->getOfflineInfo('BuildID'));
54 
55  $dl_list = array();
56  foreach( $osArchList as &$spec ) {
57  $file = sprintf('%s/%s', $clientDir, $spec['file']);
58  if( ! is_file($file) ) {
59  continue;
60  }
61  $dl_list []= array(
62  'DL_OS' => htmlspecialchars($spec['os']),
63  'DL_ARCH' => htmlspecialchars($spec['arch']),
64  'DL_TITLE' => htmlspecialchars($spec['title']),
65  'DL_ICON' => $spec['icon']
66  );
67  }
68  unset($spec);
69 
70  $action->lay->setBlockData('DL_LIST', $dl_list);
71 
72  return;
73 }
74 
75 function sendClient(&$action, $os, $arch) {
76  include_once('OFFLINE/Class.OfflineClientBuilder.php');
77 
78  $clientDir = $action->parent->getParam('OFFLINE_CLIENT_BUILD_OUTPUT_DIR', '');
79  if( ! is_dir($clientDir) ) {
80  $action->ExitError(sprintf('OFFLINE_CLIENT_BUILD_OUTPUT_DIR: '._("OFFLINE:%s directory not found"), $clientDir));
81  return;
82  }
83  $clientDir = realpath($clientDir);
84 
85  $ocb = new OfflineClientBuilder();
86  $osArchList = $ocb->getOsArchList();
87 
88  $filename = '';
89  foreach( $osArchList as &$spec ) {
90  if( $spec['os'] == $os && $spec['arch'] == $arch ) {
91  $filename = $spec['file'];
92  break;
93  }
94  }
95  unset($spec);
96 
97  if( $filename != '' ) {
98  $sendFile = sprintf('%s/%s', $clientDir, $filename);
99  if( ! is_file($sendFile) ) {
100  $action->ExitError(sprintf(_("OFFLINE:File '%s' not found"), $sendFile));
101  return;
102  }
103  $fileSize = filesize($sendFile);
104  $fh = fopen($sendFile, 'rb');
105  header(sprintf('Content-Type: application/binary'));
106  header(sprintf('Content-Length: %s', $fileSize));
107  header(sprintf('Content-Disposition: attachment; filename=%s', $filename));
108  fpassthru($fh);
109  fclose($fh);
110  exit;
111  }
112  $action->ExitError(sprintf(_("OFFLINE:File not found for '%s'"), sprintf("{os:'%s', arch:'%s'}", $os, $arch)));
113  return;
114 }
115 
116 ?>
sendClient(&$action, $os, $arch)
off_dlclient(&$action)
Definition: off_dlclient.php:3
← centre documentaire © anakeen - published under CC License - Dynacase