-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtemplate-functions.php
163 lines (133 loc) · 5.08 KB
/
template-functions.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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
<?php
if ( !function_exists('print_lang_value') ) {
function print_lang_value($value, $lang_code){
$lang_code = substr($lang_code,0,2);
if ( is_array($value) ){
foreach($value as $current_value){
$print_values[] = get_lang_value($current_value, $lang_code);
}
echo implode(', ', $print_values);
}else{
echo get_lang_value($value, $lang_code);
}
return;
}
}
if ( !function_exists('get_lang_value') ) {
function get_lang_value($string, $lang_code, $default_lang_code = 'en'){
$lang_value = array();
$occs = preg_split('/\|/', $string);
foreach ($occs as $occ){
$re_sep = (strpos($occ, '~') !== false ? '/\~/' : '/\^/');
$lv = preg_split($re_sep, $occ);
$lang = substr($lv[0],0,2);
$value = $lv[1];
$lang_value[$lang] = $value;
}
if ( isset($lang_value[$lang_code]) ){
$translated = $lang_value[$lang_code];
}else{
$translated = $lang_value[$default_lang_code];
}
return $translated;
}
}
if ( !function_exists('format_date') ) {
function format_date($string){
$date_formated = '';
if (strpos($string,'-') !== false) {
$date_formated = substr($string,8,2) . '/' . substr($string,5,2) . '/' . substr($string,0,4);
}else{
$date_formated = substr($string,6,2) . '/' . substr($string,4,2) . '/' . substr($string,0,4);
}
return $date_formated;
}
}
if ( !function_exists('format_act_date') ) {
function format_act_date($string, $lang){
$months = array();
$months['pt'] = array('Janeiro','Feveiro', 'Março', 'Abril', 'Maio', 'Junho',
'Julho', 'Agosto', 'Setembro', 'Outubro', 'Novembro', 'Dezembro');
$months['es'] = array('Enero','Febrero', 'Marzo', 'Abril', 'Mayo', 'Junio',
'Julio', 'Agosto', 'Septiembre', 'Octubre', 'Noviembre', 'Diciembre');
$date_formated = '';
if (strpos($string,'-') !== false) {
if ($lang != 'en'){
$month_val = intval(substr($string,5,2));
$month_name = $months[$lang][$month_val-1];
} else {
$month_name = strftime("%B", strtotime($string));
}
$date_formated = substr($string,8,2) . ' ' . __('of','leisref') . ' ' . $month_name . ' ' . __('of', 'leisref') . ' ' . substr($string,0,4);
}else{
$date_formated = substr($string,6,2) . '/' . substr($string,4,2) . '/' . substr($string,0,4);
}
return $date_formated;
}
}
if ( !function_exists('isUTF8') ) {
function isUTF8($string){
return (utf8_encode(utf8_decode($string)) == $string);
}
}
if ( !function_exists('translate_label') ) {
function translate_label($texts, $label, $group=NULL) {
// labels on texts.ini must be array key without spaces
$label_norm = preg_replace('/[&,\'\s]+/', '_', $label);
if($group == NULL) {
if(isset($texts[$label_norm]) and $texts[$label_norm] != "") {
return $texts[$label_norm];
}
} else {
if(isset($texts[$group][$label_norm]) and $texts[$group][$label_norm] != "") {
return $texts[$group][$label_norm];
}
}
// case translation not found return original label ucfirst
return ucfirst($label);
}
}
if ( !function_exists('get_site_meta_tags') ) {
function get_site_meta_tags($url){
$site_title = array();
$fp = @file_get_contents($url);
if ($fp) {
$res = preg_match("/<title>(.*)<\/title>/siU", $fp, $title_matches);
if ($res) {
$site_title = preg_replace('/\s+/', ' ', $title_matches[1]);
$site_title = trim($site_title);
}
$site_meta_tags = get_meta_tags($url);
$site_meta_tags['title'] = $site_title;
foreach ($site_meta_tags as $key => $value) {
if (!isUTF8($value)){
$site_meta_tags[$key] = utf8_encode($value);
}
}
}
return $site_meta_tags;
}
}
if ( !function_exists('real_site_url') ) {
function real_site_url($path = ''){
$site_url = get_site_url();
// check for multi-language-framework plugin
if ( function_exists('mlf_parseURL') ) {
global $mlf_config;
$current_language = substr( strtolower(get_bloginfo('language')),0,2 );
if ( $mlf_config['default_language'] != $current_language ){
$site_url .= '/' . $current_language;
}
}
$current_language = substr( strtolower(get_bloginfo('language')),0,2 );
if ( $mlf_config['default_language'] != $current_language ){
$site_url .= '/' . $current_language;
}
if ($path != ''){
$site_url .= '/' . $path;
}
$site_url .= '/';
return $site_url;
}
}
?>