YaWK  24.1
Yet another WebKit
update-readUpdateFilebase.php
Go to the documentation of this file.
1 <?php
2 use YAWK\db;
3 use YAWK\update;
4 use YAWK\settings;
5 include '../../system/classes/db.php';
6 include '../../system/classes/language.php';
7 include '../../system/classes/settings.php';
8 include '../../system/classes/update.php';
9 /* set database object */
10 if (!isset($db))
11 { // create new db object
12  $db = new db();
13 }
14 if (!isset($lang))
15 { // create new language object
16  $language = new YAWK\language();
17  // init language
18  $language->init($db, "backend");
19  // convert object param to array !important
20  $lang = (array) $language->lang;
21 }
22 
23 // prepare vars
24 // get local (installed) filebase
25 $localFilebase = parse_ini_file('../../system/update/filebase.current.ini');
26 $updateFilesPath = '../../system/update/updateFiles.ini';
27 
28 // generate new update object
29 $update = new update();
30 // get update filebase from server
31 $updateFilebase = $update->readUpdateFilebaseFromServer();
32 if (!is_array($updateFilebase)){
33  echo $lang['UPDATE_ERROR_READING_UPDATE_INI'].' https://'.$_SERVER['HTTP_HOST'].'/system/update/filebase.current.ini';
34 }
35 // sort arrays by key (file path)
36 ksort($localFilebase);
37 ksort($updateFilebase, SORT_NATURAL);
38 // compare filebase arrays
39 // if file hash is different, add file to differentFiles array
40 $differentFiles = array(); // files with different hash values (those will be updated)
41 $localOnlyFiles = array(); // files only found in local filebase (files that were added by page admin, those will NOT be touched)
42 $updateFiles = ''; // files that will be updated
43 
44 // add files, that are in the update filebase, but not in the local filebase
45 foreach($updateFilebase as $key => $value) {
46  if (!array_key_exists($key, $localFilebase)) {
47  // add file to updateFiles string, which will be written to updateFiles.ini
48  $updateFiles .= "$value=\"$key\"\n";
49  $differentFiles[] = $key;
50  }
51 }
52 
53 // loop through local filebase array (parsed from filebase.current.ini)
54 foreach ($localFilebase as $filePath => $localHash)
55 { // check if file exists in update filebase
56  if (isset($updateFilebase[$filePath]))
57  { // get hash from update filebase
58  $updateHash = $updateFilebase[$filePath];
59  // compare hashes
60  if ($localHash !== $updateHash)
61  { // if hashes are different, add file to differentFiles array
62  $differentFiles[] = $filePath;
63 
64  // add file to updateFiles string, which will be written to updateFiles.ini
65  $updateFiles .= "$localHash=\"$filePath\"\n";
66  }
67  }
68  else
69  { // if file is not found in update filebase, store file path in localOnlyFiles array
70  $localOnlyFiles[] = $filePath;
71  }
72 }
73 
74 // response string, used to echoed to ajax call
75 $response = '';
76 // Write the content to system/update/updateFiles.ini
77 file_put_contents($updateFilesPath, $updateFiles);
78 // if updateFilesPath is not found, throw error
79 if (!file_exists($updateFilesPath))
80 { // if file is not found, throw error
81  $response .= $lang['UPDATE_ERROR_WRITING'].' '.$updateFilesPath;
82 }
83 
84 if (empty($differentFiles))
85 { // if no files with different hash values were found
86  $response .= '<p class="text-success"><b class="animated fadeIn slow delay-2s">'.$lang['UPDATE_ALL_HASHES_SAME'].'</b></p>';
87 }
88 else
89 { // if files with different hash values were found
90  // draw panel
91  $response .= '<div class="panel-group animated fadeIn slow delay-3s" id="accordion" role="tablist" aria-multiselectable="true">
92  <div class="panel panel-default">
93  <div class="panel-heading" role="tab" id="headingUpdateFilebase">
94  <h4 class="panel-title">
95  <a role="button" data-toggle="collapse" data-parent="#accordion" href="#collapseUpdateFilebase" aria-expanded="true" aria-controls="collapseUpdateFilebase">
96  '.$lang['UPDATE_FILEBASE'].'<br>
97  <small>'.$lang['UPDATE_FILEBASE_SUBTEXT'].'</small>
98  </a>
99  </h4>
100  </div>
101  <div id="collapseUpdateFilebase" class="panel-collapse collapse" role="tabpanel" aria-labelledby="headingUpdateFilebase">
102  <div class="panel-body">';
103  $response .= '<p class="animated fadeIn slow"><b>'.$lang['UPDATE_FILES_WITH_DIFFERENT_HASHES'].'</b></p>';
104  foreach ($differentFiles as $file) {
105  $response .= '<span class="animated fadeIn slow delay-1s">- '.$file.'</span><br>';
106  }
107  echo '</div></div></div></div>';
108 }
109 
110 if (empty($localOnlyFiles)){
111  $response .= '<p><b class="animated fadeIn slow delay-3s">'.$lang['UPDATE_NO_FILES_TO_UPDATE'].'</b></p>';
112 }
113 else
114 { // if files with different hash values were found
115  $response .= '<br><br><div class="panel-group animated fadeIn slow delay-3s" id="accordion2" role="tablist" aria-multiselectable="true">
116  <div class="panel panel-default">
117  <div class="panel-heading" role="tab" id="headingOne">
118  <h4 class="panel-title">
119  <a class="collapsed" role="button" data-toggle="collapse" data-parent="#accordion2" href="#collapseOne" aria-expanded="false" aria-controls="collapseOne">
120  '.$lang['UPDATE_FILES_NOT_IN_UPDATE_FILEBASE'].'<br>
121  <small>'.$lang['UPDATE_FILES_WILL_NOT_BE_TOUCHED'].'</small>
122  </a>
123  </h4>
124  </div>
125  <div id="collapseOne" class="panel-collapse collapse" role="tabpanel" aria-labelledby="headingOne">
126  <div class="panel-body">';
127  foreach ($localOnlyFiles as $file) {
128  $response .= '<span class="animated fadeIn slow">- '.$file.'</span><br>';
129  }
130  $response .= '
131  </div>
132  </div>
133  </div>';
134 }
135 
136 if (!empty($response)){
137  echo $response;
138 }
139 else {
140  echo 'There was an error generating the view from no data...';
141 }
print $lang['FILEMAN_UPLOAD']
Mysqli database class; returns db connection object.
Definition: db.php:16
The language class - support multilingual backend.
Definition: language.php:17
Settings class: get and set YaWK system settings.
Definition: settings.php:9
The update class - handles yawk's system update functions.
Definition: update.php:21
foreach($updateFilebase as $key=> $value) foreach($localFilebase as $filePath=> $localHash) $response
if(!isset($db)) if(!isset($lang)) $localFilebase
$value