-
Notifications
You must be signed in to change notification settings - Fork 0
/
fz_helper_view.php
131 lines (111 loc) · 3.38 KB
/
fz_helper_view.php
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
<?php
/**
* @file
* Short description.
*
* Long description.
*
* @package FileZ
*/
/**
*
* @param string $path
* @return string Url containing the public path of the project
*/
function public_url_for ($path) {
$args = func_get_args ();
$paths = array (option ('base_path'));
$paths = array_merge ($paths, $args);
return call_user_func_array ('file_path', $paths);
}
/**
* Truncate a string in the middle with "[...]"
*
* @param string $str
* @param integer $size
* @return string Truncated string
*/
function truncate_string ($str, $maxSize) {
if (($size = strlen ($str)) > $maxSize) {
$halfDiff = ($size - $maxSize + 5) / 2;
$str = substr ($str, 0, ($size / 2) - ceil ($halfDiff))
.'[...]'
.substr ($str, ($size / 2) + floor ($halfDiff));
}
return $str;
}
/**
* Translate a string
* @param string
* @return string
*/
function __($msg) {
if (! option ('translate')) return $msg;
return option ('translate')->translate ($msg);
}
/**
* Translate a string with different plural form
* @param string $sing Singular form
* @param string $plur Plural form
* @param integer
* @return string
*/
function __p($sing, $plur, $nb) {
if (! option ('translate')) return $msg;
return option ('translate')->plural ($sing, $plur, $nb);
}
/**
* Translate a string and subtitute values defined in $subtitution
*
* @param string $msg
* @param array $subtitutions ex: array('var'=>'real value') will replace
* %var% by 'real value
* @return string
*/
function __r($msg, array $subtitutions) {
$msg = __($msg);
foreach ($subtitutions as $key => $value)
$msg = str_replace ("%$key%", $value, $msg);
return $msg;
}
/**
* Transform a size in bytes to the shorthand format ('K', 'M', 'G')
*
* @param string $size
* @return integer
*/
function bytesToShorthand ($size) {
return ($size >= 1073741824 ? (round ($size / 1073741824, 2).'G') : (
$size >= 1048576 ? (round ($size / 1048576, 2).'M') : (
$size >= 1024 ? (round ($size / 1024, 2).'K') :
$size.'B')));
}
function doc_img_tag ($name) {
return '<div class="img-block">'
.'<img src="'.url_for('/').'doc/user/'.option ('locale')->getLanguage ().'/images/'.$name.'" />'
.'</div>';
}
function get_mimetype_icon_url ($mimetype, $size = 32) {
$mimetype = str_replace ('/', '-', $mimetype).'.png';
$path = 'resources/images/icons/mimetypes/'.$size.'/';
$mime_basesir = public_url_for ($path);
$root = option ('root_dir').'/';
if (file_exists ($root.$path.$mimetype))
return $mime_basesir.$mimetype;
$mimetype = str_replace ('application-', '', $mimetype);
if (file_exists ($root.$path.$mimetype))
return $mime_basesir.$mimetype;
$mimetype = 'gnome-mime-'.$mimetype;
if (file_exists ($root.$path.$mimetype))
return $mime_basesir.$mimetype;
}
function check_cron() {
if (! option ('installing')) {
$lastCron = Fz_Db::getTable('Info')->getLastCronTimestamp();
$freq = fz_config_get ('cron', 'frequency');
if(strtotime($freq." ".$lastCron) <= time()) {
Fz_Db::getTable('Info')->setLastCronTimestamp(date('Y-m-d H:i:s'));
return "<script src='".url_for('admin/checkFiles')."'></script>";
}
}
}