-
Notifications
You must be signed in to change notification settings - Fork 0
/
functions.php
305 lines (122 loc) · 5.19 KB
/
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
<?php
/**
* Add settings link to plugin page.
*/
function icl_plugin_action_links($links, $file) {
$this_plugin = basename(ICL_PLUGIN_PATH) . '/sitepress.php';
global $sitepress_settings;
if($file == $this_plugin) {
$links[] = '<a href="admin.php?page='.basename(ICL_PLUGIN_PATH).'/menu/languages.php">' . __('Configure', 'sitepress') . '</a>';
}
return $links;
}
if(defined('ICL_DEBUG_MODE') && ICL_DEBUG_MODE){
add_action('admin_notices', '_icl_deprecated_icl_debug_mode');
}
function _icl_deprecated_icl_debug_mode(){
echo '<div class="updated"><p><strong>ICL_DEBUG_MODE</strong> no longer supported. Please use <strong>WP_DEBUG</strong> instead.</p></div>';
}
function icl_js_escape($str){
$str = esc_js($str);
$str = htmlspecialchars_decode($str);
return $str;
}
function icl_nobreak($str){
return preg_replace("# #", ' ', $str);
}
function _icl_tax_has_objects_recursive($id, $term_id = -1, $rec = 0){
// based on the case where two categories were one the parent of another
// eliminating the chance of infinite loops by letting this function calling itself too many times
// 100 is the default limit in most of teh php configuration
//
// this limit this function to work only with categories nested up to 60 levels
// should enough for most cases
if($rec > 60) return false;
global $wpdb;
if($term_id === -1){
$term_id = $wpdb->get_var($wpdb->prepare("SELECT term_id FROM {$wpdb->term_taxonomy} WHERE term_taxonomy_id=%d", $id));
}
$children = $wpdb->get_results($wpdb->prepare("
SELECT term_taxonomy_id, term_id, count FROM {$wpdb->term_taxonomy} WHERE parent = %d
", $term_id));
$count = 0;
foreach($children as $ch){
$count += $ch->count;
}
if($count){
return true;
}else{
foreach($children as $ch){
if(_icl_tax_has_objects_recursive($ch->term_taxonomy_id, $ch->term_id, $rec+1)){
return true;
}
}
}
return false;
}
function icl_get_post_children_recursive($post, $type = 'page'){
global $wpdb;
$post = (array)$post;
$children = $wpdb->get_col($wpdb->prepare("SELECT ID FROM {$wpdb->posts} WHERE post_type=%s AND post_parent IN (".join(',', $post).")", $type));
if(!empty($children)){
$children = array_merge($children, icl_get_post_children_recursive($children));
}
return $children;
}
function icl_get_tax_children_recursive($id, $taxonomy = 'category'){
global $wpdb;
$id = (array)$id;
$children = $wpdb->get_col($wpdb->prepare("SELECT term_id FROM {$wpdb->term_taxonomy} x WHERE x.taxonomy=%s AND parent IN (".join(',', $id).")", $taxonomy));
if(!empty($children)){
$children = array_merge($children, icl_get_tax_children_recursive($children));
}
return $children;
}
function _icl_trash_restore_prompt(){
global $sitepress;
if(isset($_GET['lang'])){
$post = get_post(intval($_GET['post']));
if($post->post_status == 'trash'){
$post_type_object = get_post_type_object( $post->post_type );
$ret = '<p>';
$ret .= sprintf(__('This translation is currently in the trash. You need to either <a href="%s">delete it permanently</a> or <a href="%s">restore</a> it in order to continue.'),
get_delete_post_link($post->ID, '', true) ,
wp_nonce_url( admin_url( sprintf( $post_type_object->_edit_link . '&action=untrash', $post->ID ) ), 'untrash-' . $post->post_type . '_' . $post->ID)
);
$ret .= '</p>';
wp_die($ret);
}
}
}
function icl_pop_info($message, $icon='info', $args = array()){
switch($icon){
case 'info':
$icon = ICL_PLUGIN_URL . '/res/img/info.png';
break;
case 'question':
$icon = ICL_PLUGIN_URL . '/res/img/question1.png';
break;
}
$defaults = array(
'icon_size' => 16
);
extract($defaults);
extract($args, EXTR_OVERWRITE);
?>
<div class="icl_pop_info_wrap">
<img class="icl_pop_info_but" src="<?php echo $icon ?>" width="<?php echo $icon_size ?>" height="<?php echo $icon_size ?>" alt="info" onclick="jQuery('.icl_pop_info').hide();jQuery(this).next().fadeIn();" />
<div class="icl_cyan_box icl_pop_info">
<img align="right" src="<?php echo ICL_PLUGIN_URL ?>/res/img/ico-close.png" width="12" height="12" alt="x" onclick="jQuery(this).parent().fadeOut()" />
<?php echo $message; ?>
</div>
</div>
<?php
}
function icl_is_post_edit(){
static $is;
if(is_null($is)){
global $pagenow;
$is = ($pagenow == 'post-new.php' || ($pagenow == 'post.php' && isset($_GET['action']) && $_GET['action']=='edit'));
}
return $is;
}