Open Journal Systems  3.3.0
utils.php
1 <?php
2 
3  function sac_clean($string) {
4  // Tidy a string
5  $string = str_replace("\n", "", $string);
6  $string = str_replace("\r", "", $string);
7  $string = str_replace("\t", "", $string);
8 
9  $string = preg_replace('/\t/', '', $string);
10  $string = preg_replace('/\s\s+/', ' ', $string);
11  $string = trim($string);
12  return $string;
13  }
14 
15  function base64chunk($in, $out) {
16  // Base64 encode, then chunk, a file
17  // By 'MitMacher' from http://www.php.net/manual/en/function.base64-encode.php#92762
18 
19  $fh_in = fopen($in, 'rb');
20  $fh_out = fopen($out, 'ab');
21 
22  $cache = '';
23  $eof = false;
24 
25  while (true) {
26  if (!$eof) {
27  if (!feof($fh_in)) {
28  $row = fgets($fh_in, 4096);
29  } else {
30  $row = '';
31  $eof = true;
32  }
33  }
34 
35  if ($cache !== '') {
36  $row = $cache . $row;
37  }
38  elseif ($eof) {
39  break;
40  }
41 
42  $b64 = base64_encode($row);
43  $put = '';
44 
45  if (strlen($b64) < 76) {
46  if ($eof) {
47  $put = $b64 . "\r\n";
48  $cache = '';
49  } else {
50  $cache = $row;
51  }
52  } elseif (strlen($b64) > 76) {
53  do {
54  $put .= substr($b64, 0, 76) . "\r\n";
55  $b64 = substr($b64, 76);
56  } while (strlen($b64) > 76);
57 
58  $cache = base64_decode($b64);
59  } else {
60  if (!$eof && $b64{75} == '=') {
61  $cache = $row;
62  } else {
63  $put = $b64."\r\n";
64  $cache = '';
65  }
66  }
67 
68  if ($put !== '') {
69  fputs($fh_out, $put);
70  }
71  }
72 
73  fclose($fh_in);
74  }
75 
76 ?>