Guest User

theme1382: theme-function.php

a guest
Apr 13th, 2013
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.40 KB | None | 0 0
  1. <?php
  2.  
  3. // The excerpt based on words
  4. function my_string_limit_words($string, $word_limit)
  5. {
  6. $words = explode(' ', $string, ($word_limit + 1));
  7. if(count($words) > $word_limit)
  8. array_pop($words);
  9. return implode(' ', $words).'...';
  10. }
  11.  
  12.  
  13. // The excerpt based on character
  14. function my_string_limit_char($excerpt, $substr=0)
  15. {
  16.  
  17. $string = strip_tags(str_replace('...', '...', $excerpt));
  18. if ($substr>0) {
  19. $string = substr($string, 0, $substr);
  20. }
  21. return $string;
  22. }
  23.  
  24.  
  25. add_action( 'after_setup_theme', 'my_setup' );
  26.  
  27.  
  28. // Remove invalid tags
  29. function remove_invalid_tags($str, $tags)
  30. {
  31. foreach($tags as $tag)
  32. {
  33. $str = preg_replace('#^<\/'.$tag.'>|<'.$tag.'>$#', '', trim($str));
  34. }
  35.  
  36. return $str;
  37. }
  38.  
  39. // Generates a random string (for embedding flash)
  40. function theme1382_random($length){
  41.  
  42. srand((double)microtime()*1000000 );
  43.  
  44. $random_id = "";
  45.  
  46. $char_list = "abcdefghijklmnopqrstuvwxyz";
  47.  
  48. for($i = 0; $i < $length; $i++) {
  49. $random_id .= substr($char_list,(rand()%(strlen($char_list))), 1);
  50. }
  51.  
  52. return $random_id;
  53. }
  54.  
  55.  
  56. // Remove Empty Paragraphs
  57. add_filter('the_content', 'shortcode_empty_paragraph_fix');
  58. function shortcode_empty_paragraph_fix($content)
  59. {
  60. $array = array (
  61. '<p>[' => '[',
  62. ']</p>' => ']',
  63. ']<br />' => ']'
  64. );
  65.  
  66. $content = strtr($content, $array);
  67.  
  68. return $content;
  69. }
  70.  
  71.  
  72.  
  73.  
  74. // For embedding video file
  75. function mytheme_video($file, $image, $width, $height, $color){
  76.  
  77. //Template URL
  78. $template_url = get_template_directory_uri();
  79.  
  80. //Unique ID
  81. $id = "video-".theme1382_random(15);
  82.  
  83. $object_height = $height + 39;
  84.  
  85. //JS
  86. $output = '<script type="text/javascript">'."\n";
  87. $output .= 'var flashvars = {};'."\n";
  88. $output .= 'flashvars.player_width="'.$width.'";'."\n";
  89. $output .= 'flashvars.player_height="'.$height.'"'."\n";
  90. $output .= 'flashvars.player_id="'.$id.'";'."\n";
  91. $output .= 'flashvars.thumb="'.$image.'";'."\n";
  92. $output .= 'flashvars.colorTheme="'.$color.'";'."\n";
  93. $output .= 'var params = { "wmode": "transparent" };'."\n";
  94. $output .= 'params.wmode = "transparent";'."\n";
  95. $output .= 'params.quality = "high";';
  96. $output .= 'params.allowFullScreen = "true";'."\n";
  97. $output .= 'params.allowScriptAccess = "always";'."\n";
  98. $output .= 'params.quality="high";'."\n";
  99. $output .= 'var attributes = {};'."\n";
  100. $output .= 'attributes.id = "'.$id.'";'."\n";
  101. $output .= 'swfobject.embedSWF("'.$template_url.'/flash/video.swf?fileVideo='.$file.'", "'.$id.'", "'.$width.'", "'.$object_height.'", "9.0.0", false, flashvars, params, attributes);'."\n";
  102. $output .= '</script>'."\n\n";
  103.  
  104. $output .= '<div class="video-bg" style="width:'.$width.'px; height:'.$height.'px; background-image:url('.$image.')">'."\n";
  105. $output .= '</div>'."\n";
  106.  
  107. //HTML
  108. $output .= '<div id="'.$id.'">'."\n";
  109. $output .= '<a href="http://www.adobe.com/go/getflashplayer">'."\n";
  110. $output .= '<img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player" />'."\n";
  111. $output .= '</a>'."\n";
  112. $output .= '</div>';
  113.  
  114. return $output;
  115.  
  116. }
  117.  
  118.  
  119.  
  120. // Add Thumb Column
  121. if ( !function_exists('fb_AddThumbColumn') && function_exists('add_theme_support') ) {
  122. // for post and page
  123. add_theme_support('post-thumbnails', array( 'post', 'page' ) );
  124. function fb_AddThumbColumn($cols) {
  125. $cols['thumbnail'] = __('Thumbnail');
  126. return $cols;
  127. }
  128. function fb_AddThumbValue($column_name, $post_id) {
  129. $width = (int) 35;
  130. $height = (int) 35;
  131. if ( 'thumbnail' == $column_name ) {
  132. // thumbnail of WP 2.9
  133. $thumbnail_id = get_post_meta( $post_id, '_thumbnail_id', true );
  134. // image from gallery
  135. $attachments = get_children( array('post_parent' => $post_id, 'post_type' => 'attachment', 'post_mime_type' => 'image') );
  136. if ($thumbnail_id)
  137. $thumb = wp_get_attachment_image( $thumbnail_id, array($width, $height), true );
  138. elseif ($attachments) {
  139. foreach ( $attachments as $attachment_id => $attachment ) {
  140. $thumb = wp_get_attachment_image( $attachment_id, array($width, $height), true );
  141. }
  142. }
  143. if ( isset($thumb) && $thumb ) {
  144. echo $thumb;
  145. } else {
  146. echo __('None');
  147. }
  148. }
  149. }
  150. // for posts
  151. add_filter( 'manage_posts_columns', 'fb_AddThumbColumn' );
  152. add_action( 'manage_posts_custom_column', 'fb_AddThumbValue', 10, 2 );
  153. // for pages
  154. add_filter( 'manage_pages_columns', 'fb_AddThumbColumn' );
  155. add_action( 'manage_pages_custom_column', 'fb_AddThumbValue', 10, 2 );
  156. }
  157.  
  158.  
  159.  
  160.  
  161. ?>
Advertisement
Add Comment
Please, Sign In to add comment