Digitalraindrops

wrappers colored code

Jul 21st, 2011
223
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.77 KB | None | 0 0
  1. <?php
  2.  
  3. function theme_get_array_value($arr = array(), $key = null, $def = false){
  4.     if (is_array($arr) && isset($arr[$key])){
  5.         return $arr[$key];
  6.     }
  7.     return $def;
  8. }
  9.  
  10. function theme_is_empty_html($str){
  11.     return (!is_string($str) || strlen(str_replace(array('&nbsp;', ' ', "\n", "\r", "\t"), '', $str)) == 0);
  12. }
  13.  
  14. function theme_is_vmenu_widget($id){
  15.     return (strpos($id, 'vmenu') !== false);
  16. }
  17.  
  18. function theme_trim_long_str($str, $len = 50, $sep = ' '){
  19.     $words = split($sep, $str);
  20.     $wcount = count($words);
  21.     while( $wcount > 0 && strlen(join($sep, array_slice($words, 0, $wcount))) > $len) $wcount--;
  22.     if ($wcount != count($words)) {
  23.         $str = join($sep, array_slice($words, 0, $wcount)) . '&hellip;';
  24.     }
  25.     return $str;
  26. }
  27.  
  28.  
  29. function theme_get_current_url() {
  30.     $pageURL = 'http';
  31.     if (is_ssl()) {
  32.         $pageURL .= 's';
  33.     }
  34.     $pageURL .= '://' . $_SERVER['SERVER_NAME'];
  35.     if ($_SERVER['SERVER_PORT'] != '80') {
  36.         $pageURL .= ':' . $_SERVER["SERVER_PORT"];
  37.     }
  38.     $pageURL .= $_SERVER["REQUEST_URI"];
  39.     return $pageURL;
  40. }
  41.  
  42. function theme_remove_last_slash($url) {
  43.     $len = strlen($url);
  44.     if ( $len > 0 && $url[$len-1] == '/') {
  45.         $url =  substr($url, 0, -1);
  46.     }
  47.     return $url;
  48. }
  49.  
  50. function theme_is_current_url($url) {
  51.     // remove # anchor
  52.     if (strpos( $url, '#' )) {
  53.         $url =  substr($url, 0, strpos( $url, '#'));
  54.     }
  55.    
  56.     $url = theme_remove_last_slash($url);
  57.     $cur = theme_remove_last_slash(theme_get_current_url());
  58.    
  59.     // compare
  60.     return ($cur == $url);
  61. }
  62.  
  63. function theme_prepare_attr($attr = array()) {
  64.     $attr = wp_parse_args($attr);
  65.     if (count($attr)  == 0) return '';
  66.     $result = '';
  67.     foreach($attr as $name => $value){
  68.         if(empty($name) || empty($value)) continue;
  69.         $result .= ' ' . strtolower($name) . '="' . esc_attr($value) . '"';
  70.     }
  71.     return $result;
  72. }
Advertisement
Add Comment
Please, Sign In to add comment