| 1 |
<?php |
| 2 |
/** |
| 3 |
* trim and remove empty element |
| 4 |
* |
| 5 |
* @param string $element |
| 6 |
* |
| 7 |
* @return string |
| 8 |
*/ |
| 9 |
function _delete_empty_element( $element ) { |
| 10 |
$element = stripslashes( $element ); |
| 11 |
$element = trim( $element ); |
| 12 |
if ( ! empty( $element ) ) { |
| 13 |
return $element; |
| 14 |
} |
| 15 |
|
| 16 |
return false; |
| 17 |
} |
| 18 |
|
| 19 |
/** |
| 20 |
* Test if page have tags or not... |
| 21 |
* |
| 22 |
* @return boolean |
| 23 |
* @author WebFactory Ltd |
| 24 |
*/ |
| 25 |
function is_page_have_tags() { |
| 26 |
$taxonomies = get_object_taxonomies( 'page' ); |
| 27 |
|
| 28 |
return in_array( 'post_tag', $taxonomies, true ); |
| 29 |
} |
| 30 |
|
| 31 |
/** |
| 32 |
* Register widget on WP |
| 33 |
*/ |
| 34 |
function st_register_widget() { |
| 35 |
register_widget( 'SimpleTags_Widget' ); |
| 36 |
if ( 1 === (int) SimpleTags_Plugin::get_option_value( 'active_terms_display' )){ |
| 37 |
register_widget( 'SimpleTags_Shortcode_Widget' ); |
| 38 |
} |
| 39 |
if ( 1 === (int) SimpleTags_Plugin::get_option_value( 'active_post_tags' )){ |
| 40 |
register_widget( 'SimpleTags_PostTags_Widget' ); |
| 41 |
} |
| 42 |
if ( 1 === (int) SimpleTags_Plugin::get_option_value( 'active_related_posts_new' )){ |
| 43 |
register_widget( 'SimpleTags_RelatedPosts_Widget' ); |
| 44 |
} |
| 45 |
} |
| 46 |
|
| 47 |
/** |
| 48 |
* Change menu item order |
| 49 |
*/ |
| 50 |
add_action('custom_menu_order', 'taxopress_re_order_menu'); |
| 51 |
function taxopress_re_order_menu() { |
| 52 |
global $submenu; |
| 53 |
$newSubmenu = []; |
| 54 |
|
| 55 |
//we only want to do this if taxonomy is active |
| 56 |
$active_taxonomies = isset($_POST['updateoptions']) && |
| 57 |
( |
| 58 |
!isset($_POST['active_taxonomies']) || |
| 59 |
(isset($_POST['active_taxonomies']) && (int)$_POST['active_taxonomies'] === 0) |
| 60 |
) ? 0 : 1; |
| 61 |
if ( (1 === (int) SimpleTags_Plugin::get_option_value( 'active_taxonomies' ) || (isset($_POST['active_taxonomies']) && (int)$_POST['active_taxonomies'] === 1)) && $active_taxonomies === 1 ) { |
| 62 |
foreach ($submenu as $menuName => $menuItems) { |
| 63 |
if ('st_options' === $menuName) { |
| 64 |
$taxopress_settings = $taxopress_taxonomies = false; |
| 65 |
|
| 66 |
$taxopress_submenus = $submenu['st_options']; |
| 67 |
foreach($taxopress_submenus as $key => $taxopress_submenu){ |
| 68 |
if($taxopress_submenu[2] === 'st_options'){//settings |
| 69 |
$taxopress_settings = $taxopress_submenu; |
| 70 |
$taxopress_settings_key= $key; |
| 71 |
unset($taxopress_submenus[$key]); |
| 72 |
} |
| 73 |
if($taxopress_submenu[2] === 'st_taxonomies'){//taxonomies |
| 74 |
$taxopress_taxonomies = $taxopress_submenu; |
| 75 |
$taxopress_taxonomies_key= $key; |
| 76 |
unset($taxopress_submenus[$key]); |
| 77 |
} |
| 78 |
} |
| 79 |
if($taxopress_settings && $taxopress_taxonomies ){ |
| 80 |
//swicth position |
| 81 |
$taxopress_submenus[$taxopress_settings_key] = $taxopress_taxonomies; |
| 82 |
$taxopress_submenus[$taxopress_taxonomies_key] = $taxopress_settings; |
| 83 |
} |
| 84 |
|
| 85 |
//resort array |
| 86 |
ksort($taxopress_submenus); |
| 87 |
|
| 88 |
$submenu['st_options'] = $taxopress_submenus; |
| 89 |
break; |
| 90 |
} |
| 91 |
} |
| 92 |
} |
| 93 |
} |
| 94 |
|
| 95 |
// Init TaxoPress |
| 96 |
function init_simple_tags() |
| 97 |
{ |
| 98 |
new SimpleTags_Client(); |
| 99 |
new SimpleTags_Client_TagCloud(); |
| 100 |
|
| 101 |
// Admin and XML-RPC |
| 102 |
if (is_admin()) { |
| 103 |
require STAGS_DIR . '/inc/class.admin.php'; |
| 104 |
new SimpleTags_Admin(); |
| 105 |
} |
| 106 |
|
| 107 |
add_action('widgets_init', 'st_register_widget'); |
| 108 |
} |
| 109 |
|
| 110 |
function taxopress_admin_pages(){ |
| 111 |
|
| 112 |
$taxopress_pages = [ |
| 113 |
'st_mass_terms', |
| 114 |
'st_auto', |
| 115 |
'st_options', |
| 116 |
'st_manage', |
| 117 |
'st_taxonomies', |
| 118 |
'st_terms_display', |
| 119 |
'st_post_tags', |
| 120 |
'st_related_posts', |
| 121 |
'st_autolinks', |
| 122 |
'st_autoterms', |
| 123 |
'st_suggestterms' |
| 124 |
]; |
| 125 |
|
| 126 |
return apply_filters('taxopress_admin_pages', $taxopress_pages); |
| 127 |
} |
| 128 |
|
| 129 |
function is_taxopress_admin_page(){ |
| 130 |
|
| 131 |
$taxopress_pages = taxopress_admin_pages(); |
| 132 |
|
| 133 |
$is_taxopress_page = false; |
| 134 |
if ( isset( $_GET['page'] ) && in_array( $_GET['page'], $taxopress_pages )) { |
| 135 |
$is_taxopress_page = true; |
| 136 |
} |
| 137 |
|
| 138 |
return apply_filters('is_taxopress_admin_page', $is_taxopress_page); |
| 139 |
} |
| 140 |
|
| 141 |
function taxopress_starts_with( $haystack, $needle ) { |
| 142 |
$length = strlen( $needle ); |
| 143 |
return substr( $haystack, 0, $length ) === $needle; |
| 144 |
} |
| 145 |
|
| 146 |
function taxopress_is_html($string) |
| 147 |
{ |
| 148 |
return preg_match("/<[^<]+>/",$string,$m) != 0; |
| 149 |
} |
| 150 |
|
| 151 |
|
| 152 |
|
| 153 |
function taxopress_is_screen_main_page(){ |
| 154 |
|
| 155 |
if(isset($_GET['action']) && $_GET['action'] === 'edit'){ |
| 156 |
return false; |
| 157 |
} |
| 158 |
|
| 159 |
if(isset($_GET['add']) && $_GET['add'] === 'new_item'){ |
| 160 |
return false; |
| 161 |
} |
| 162 |
|
| 163 |
if(isset($_GET['add']) && $_GET['add'] === 'taxonomy'){ |
| 164 |
return false; |
| 165 |
} |
| 166 |
|
| 167 |
return true; |
| 168 |
} |
| 169 |
|
| 170 |
|
| 171 |
|
| 172 |
function taxopress_format_class($class) |
| 173 |
{ |
| 174 |
return esc_attr(ltrim($class, '.')); |
| 175 |
} |
| 176 |
|
| 177 |
function taxopress_add_class_to_format($xformat, $class) { |
| 178 |
$classes = $class; |
| 179 |
$html = $xformat; |
| 180 |
|
| 181 |
$patterns = array(); |
| 182 |
$replacements = array(); |
| 183 |
|
| 184 |
// matches where anchor has existing classes contained in single quotes |
| 185 |
$patterns[0] = '/<a([^>]*)class=\'([^\']*)\'([^>]*)>/'; |
| 186 |
$replacements[0] = '<a\1class="' . $classes . ' \2"\3>'; |
| 187 |
|
| 188 |
// matches where anchor has existing classes contained in double quotes |
| 189 |
$patterns[1] = '/<a([^>]*)class="([^"]*)"([^>]*)>/'; |
| 190 |
$replacements[1] = '<a\1class="' . $classes . ' \2"\3>'; |
| 191 |
|
| 192 |
// matches where anchor tag has no existing classes |
| 193 |
$patterns[2] = '/<a(?![^>]*class)([^>]*)>/'; |
| 194 |
$replacements[2] = '<a\1 class="' . $classes . '">'; |
| 195 |
|
| 196 |
$html = preg_replace($patterns, $replacements, $html); |
| 197 |
|
| 198 |
return $html; |
| 199 |
} |
| 200 |
|
| 201 |
function taxopress_change_to_strings($join){ |
| 202 |
if(is_array($join)){ |
| 203 |
$join = join(", ", $join); |
| 204 |
} |
| 205 |
return $join; |
| 206 |
} |
| 207 |
|
| 208 |
function taxopress_change_to_array($array){ |
| 209 |
if(!is_array($array)){ |
| 210 |
$array = preg_split("/\s*,\s*/",$array); |
| 211 |
} |
| 212 |
return $array; |
| 213 |
} |
| 214 |
|
| 215 |
function taxopress_html_character_and_entity($enity_code_as_key = false){ |
| 216 |
#Source https://dev.w3.org/html5/html-author/charref |
| 217 |
$character_set = [ |
| 218 |
//'&' => '&', |
| 219 |
'<' => '<', |
| 220 |
'>' => '>', |
| 221 |
' ' => ' ', |
| 222 |
'!' => '!', |
| 223 |
'"' => '"', |
| 224 |
'#' => '#', |
| 225 |
'$'=> '$', |
| 226 |
'%' => '%', |
| 227 |
''' => ''', |
| 228 |
'(' => '(', |
| 229 |
')' => ')', |
| 230 |
'* ' => '*', |
| 231 |
'+' => '+', |
| 232 |
',' => ',', |
| 233 |
'.' => '.', |
| 234 |
'/' => '/', |
| 235 |
':' => ':', |
| 236 |
';' => ';', |
| 237 |
'=' => '=', |
| 238 |
'?' => '?', |
| 239 |
'@' => '@', |
| 240 |
'[' => '[', |
| 241 |
'\' => '\', |
| 242 |
']' => ']', |
| 243 |
'^' => '^', |
| 244 |
'_' => '_', |
| 245 |
'`' => '`', |
| 246 |
'{' => '{', |
| 247 |
'|' => '|', |
| 248 |
'}' => '}', |
| 249 |
'¡' => '¡', |
| 250 |
'¢' => '¢', |
| 251 |
'£' => '£', |
| 252 |
'©' => '©', |
| 253 |
'ª' => 'ª', |
| 254 |
'«' => '«', |
| 255 |
'®' => '®', |
| 256 |
'°' => '°', |
| 257 |
'±' => '±', |
| 258 |
'²' => '²', |
| 259 |
'³' => '³', |
| 260 |
'´' => '´', |
| 261 |
'¹' => '¹', |
| 262 |
'º' => 'º', |
| 263 |
'»' => '»', |
| 264 |
'¼' => '¼', |
| 265 |
'½' => '½', |
| 266 |
'¾' => '¾', |
| 267 |
'→' => '→', |
| 268 |
'←' => '←', |
| 269 |
'↑' => '↑', |
| 270 |
'↓' => '↓', |
| 271 |
]; |
| 272 |
|
| 273 |
if($enity_code_as_key){ |
| 274 |
$character_set = array_flip($character_set); |
| 275 |
} |
| 276 |
|
| 277 |
return $character_set; |
| 278 |
} |