Advertisement
Guest User

Untitled

a guest
Aug 18th, 2017
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.16 KB | None | 0 0
  1. <?php
  2.  
  3. function post_is_in_descendant_category( $cats, $_post = null ){
  4. foreach ( (array) $cats as $cat ) {
  5. // get_term_children() accepts integer ID only
  6. $descendants = get_term_children( (int) $cat, 'category');
  7. if ( $descendants && in_category( $descendants, $_post ) )
  8. return true;
  9. }
  10. return false;
  11. }
  12.  
  13. function exposure_thumb_url($url,$width = 200, $height = null){
  14.  
  15. // Check if WPMU and set correct path
  16. if ( function_exists('get_current_site') ) {
  17. global $blog_id;
  18. if ( !$blog_id ) {
  19. global $current_blog;
  20. $blog_id = $current_blog->blog_id;
  21. }
  22. if ( isset($blog_id) && $blog_id > 0 ) {
  23. $imageParts = explode( 'files/', $url );
  24. if ( isset($imageParts[1]) )
  25. $url = '/blogs.dir/' . $blog_id . '/files/' . $imageParts[1];
  26. }
  27. }
  28.  
  29. $src = get_bloginfo('template_url') . '/thumb.php?src=' . $url . '&w=' .$width . '&h=' . $height . '&zc=1&q=90';
  30.  
  31. return $src ;
  32.  
  33. }
  34.  
  35. function exposure_attachments($instance = null,$args = array()){
  36. extract( $args );
  37.  
  38. $post_id = $instance['post_id'];
  39. $post_id_select = $instance['post_id_select'];
  40. $cat_id = $instance['cat_id'];
  41. $widget_title = $instance['title'];
  42. $image_title = $instance['image_title'];
  43. $image_caption = $instance['image_caption'];
  44. $size = $instance['size'];
  45. $rows = $instance['rows'];
  46. $max = $instance['max'];
  47. $l2p = $instance['l2p'];
  48. $lb = $instance['lb'];
  49. $auto = $instance['auto'];
  50. $speed = $instance['speed'];
  51. $post_content = $instance['post_content'];
  52.  
  53. $wp_resized_image = get_option('woo_wp_attachment');
  54.  
  55. $slider_id = $args['widget_id'];
  56. if($slider_id == ''){ $slider_id = $post_id; }
  57.  
  58. if(!is_home()){
  59. $custom_size = get_post_meta($post_id,'thumbsize',true);
  60. $custom_title = get_post_meta($post_id,'title',true);
  61. $custom_caption = get_post_meta($post_id,'caption',true);
  62. $custom_rows = get_post_meta($post_id,'rows',true);
  63. $custom_lb = get_post_meta($post_id,'lb',true);
  64. }
  65.  
  66. if($custom_size != 'default' AND !empty($custom_size)) {$size = $custom_size;}
  67. if($custom_title != 'default' AND !empty($custom_size)) {$image_title = $custom_title;}
  68. if($custom_caption != 'default' AND !empty($custom_size)) {$image_caption = $custom_caption;}
  69. if($custom_rows != 'default' AND !empty($custom_rows)) {$rows = $custom_rows;}
  70. if($custom_lb != 'default' AND !empty($custom_lb)) {$lb = $custom_lb;}
  71.  
  72. $auto = intval($auto); // Validate int
  73. $speed = intval($speed); // Validate int
  74. $rows = intval($rows); // Validate int
  75.  
  76. //Get the attachments for the Category posts.
  77. if(!empty($cat_id)){
  78. $category = true;
  79. //$post_id = str_replace(' ','-',strtolower(get_cat_name($cat_id)));
  80. $cat_data = get_category($cat_id, ARRAY_A);
  81. $post_id = $cat_data['slug'];
  82. }
  83. if($category == true){
  84. $posts = get_posts('cat='.$cat_id .'&numberposts=' . $max);
  85. $cat_counter = 0;
  86. $attachments = array();
  87. foreach($posts as $post){
  88. //print_r($posts);
  89. $cat_counter++;
  90. $single_attachment = get_children( array(
  91. 'post_parent' => $post->ID,
  92. 'post_status' => 'inherit',
  93. 'post_type' => 'attachment',
  94. 'post_mime_type' => 'image',
  95. 'order' => 'ASC',
  96. 'orderby' => 'menu_order date',
  97. 'numberposts' => 1,
  98. ));
  99. if(!empty($single_attachment)){
  100. if($cat_counter == 1){
  101. $attachments = $single_attachment;
  102. }else{
  103. $attachments = array_merge($attachments, $single_attachment);
  104. }
  105. }
  106. }
  107. }
  108. else {
  109. if($max == "") { $max = 999;}
  110. $attachments = get_children( array(
  111. 'post_parent' => $post_id,
  112. 'post_status' => 'inherit',
  113. 'post_type' => 'attachment',
  114. 'post_mime_type' => 'image',
  115. 'order' => 'ASC',
  116. 'orderby' => 'menu_order date',
  117. 'numberposts' => $max,
  118. ));
  119. }
  120.  
  121.  
  122. $items = count($attachments);
  123.  
  124. //Slider
  125. if($rows > 0) { $slider = true;}
  126.  
  127. if($slider == true){
  128. if($size == 'small'){ $viewable = 4 * $rows; }
  129. if($size == 'medium'){ $viewable = 3 * $rows; }
  130. if($size == 'large'){ $viewable = 2 * $rows; }
  131. if($size == 'full'){ $viewable = 1 * $rows; }
  132. }
  133.  
  134. if($viewable >= $items) {$slider = false;}
  135.  
  136. //Lightbox
  137. if ($lb == 'true' OR $lb == 'on'){$lightbox = true;}
  138. else {$lightbox = false;}
  139.  
  140. //Link 2 Post
  141. if ($l2p == 'true' OR $l2p == 'on'){$link_to_post = true;}
  142. else {$link_to_post = false;}
  143.  
  144.  
  145. $counter = 3;
  146. $iter = 0;
  147. $loop = 0;
  148. if(empty($attachments)){
  149.  
  150. return false; // Bail is there is no attachments
  151.  
  152. }
  153.  
  154. $items = count($attachments);
  155. foreach ( $attachments as $attachment ) {
  156. $counter++;
  157. $loop++;
  158. //print_r($attachment);
  159. $id = $attachment->ID;
  160.  
  161. //Image Setup
  162. if($link_to_post == 'true') {
  163. $link = get_permalink($attachment->post_parent);
  164. } else {
  165. $link = get_attachment_link($id);
  166. }
  167.  
  168. $src = wp_get_attachment_image_src($id, 'large', true); // Thumb.php makes use of the Largest wordpres image and not the source file.
  169. //print_r($src);
  170. $full_image = $src[0];
  171.  
  172. //Content Setup
  173. $att_title = $attachment->post_title;
  174. $att_caption = $attachment->post_excerpt;
  175. $att_content = $attachment->post_content;
  176. $att_comments = $attachment->comment_count;
  177.  
  178. //Setup what goes where
  179. if($image_title == 'off'){$title = '';}
  180. elseif($image_title == 'title'){$title = $att_title;}
  181. elseif ($image_title == 'caption'){$title = $att_caption;}
  182. elseif ($image_title == 'description'){$title = $att_content;}
  183.  
  184. if($image_caption == 'off'){$content = '';}
  185. elseif($image_caption == 'title'){$content = $att_title;}
  186. elseif ($image_caption == 'caption'){$content = $att_caption;}
  187. elseif ($image_caption == 'description'){$content = $att_content;}
  188.  
  189. //Size
  190. if($size == 'small'){$w = 200; $h = 200; $l = 7; $per_row = 4;}
  191. elseif($size == 'medium'){$w = 280; $h = 320; $l = 6; $per_row = 3;}
  192. elseif($size == 'large'){$w = 440; $h = 220; $l = 5; $per_row = 2;}
  193. elseif($size == 'full'){$w = 920; $h = 506; $l = 4; $per_row = 1;}
  194.  
  195. //MOD
  196. if($l == 4) {$mod = ' full first last';}
  197. else {
  198. if($counter%4 == 0)
  199. {$mod = ' first';}
  200. elseif($counter%$l == 0)
  201. {$mod = ' last';}
  202. else{$mod = '';};
  203. if($counter == $l) $counter = 3;
  204. }
  205.  
  206.  
  207.  
  208. if(($iter == 0 ) && $slider == true){$images .= '<div class="slide">' . "\n";}// Slider wrap
  209.  
  210. $iter++;
  211.  
  212. //$img_url = exposure_thumb_url($full_image,$w,$h);
  213. if($size == 'full' AND $wp_resized_image == 'true'){ $img_url = $full_image;}
  214. $img_url = woo_image('key=image&width='.$w.'&height='.$h.'&class=thumb&id='. $id .'&link=img&return=true&src='.$full_image.'&auto_meta=false&meta='.get_the_title($id));
  215.  
  216. $images .= '<div class="image_box'. $mod .'">' . "\n";
  217. if($lightbox == false AND $att_comments != 0) $images .= '<span class="date"><a href="'.$link.'">'. $att_comments . '</a></span>' . "\n";
  218. if(($image_title == 'off' AND $image_caption == 'off') OR ($title == '' AND $content == '')){
  219. //When there is no content for image caption or both is turned off
  220. }
  221. else{
  222.  
  223. $images .= '<div class="text">' . "\n";
  224. if($image_title != 'off')
  225. {
  226. if($lightbox) {
  227. $images .= '<h3><a title="'. $title .'" rel="lightbox['.$post_id.']" href="'. $full_image .'">'. $title .'</a></h3>'. "\n";;
  228. } else {
  229. $images .= '<h3><a title="'. $title .'" href="'. $link .'">'. $title .'</a></h3>' . "\n";
  230. }
  231. }
  232. if($image_caption != 'off') {
  233. if($lightbox) {
  234. $images .= '<p><a title="'. $content .'" rel="lightbox['.$post_id.']" href="'. $full_image .'">'. $content .'</a></p>' . "\n";
  235. } else {
  236. $images .= '<p><a title="'. $content .'" href="'. $link .'">'. $content .'</a></p>' . "\n";
  237. }
  238. }
  239.  
  240. $images .= '</div>' . "\n";
  241. }
  242.  
  243.  
  244.  
  245. if($lightbox){
  246. $images .= '<a class="next" title="' . get_the_title($id) .'" rel="lightbox['.$post_id.']" href="#">'. $img_url .'</a>';
  247. } else {
  248. $images .= '<a class="next" href="#">'. $img_url .'</a>';
  249. }
  250.  
  251. $images .= '</div>' . "\n";
  252.  
  253. if(($iter == $viewable || $loop == $items ) && $slider == true){$images .= '</div>'; $iter = 0;}// Slider wrap
  254. }
  255.  
  256. //Start Output building
  257. $output = '';
  258. $output .= '<div class="picture_widget">';
  259.  
  260. //Heading
  261. $output .= '<div class="heading">';
  262.  
  263. if($widget_title == '' AND $category == false) { $widget_title = get_the_title($post_id);}
  264. //else { $widget_title = get_the_title($post_id);}
  265. if($category == true AND $widget_title == ''){
  266. $output .= '<h2><a href="'. get_category_link($cat_id).'">'. get_cat_name($cat_id) .'</a></h2>';
  267. }
  268. elseif ($widget_title != '' AND $category == true){
  269. $output .= '<h2><a href="'. get_category_link($cat_id).'">'. $widget_title .'</a></h2>';
  270. }
  271. elseif (!is_single() && !is_page()){
  272. $output .= '<h2><a href="'. get_permalink($post_id).'">'. $widget_title .'</a></h2>';
  273. }
  274. else {
  275. $output .= '<h2>'. $widget_title .'</h2>';
  276. }
  277. //$output .= '<a href="#" title="#" class="title_rss">RSS feed (optional)</a>'; ?
  278. $output .= '<div class="clear"></div>';
  279. $output .= '</div>' . "\n";
  280.  
  281. if($slider == true){
  282. $output .= '<div id="slider_'. $slider_id .'">'. "\n" . '<div class="container">'. "\n" . '<div class="slides">'. "\n";
  283. }
  284. //Images
  285. $output .= $images;
  286.  
  287. if($slider == true){
  288. $output .= "</div>\n</div>\n";
  289. $output .= '<a class="slider_left previous" href="#" title="Navigate left">PREV</a>';
  290. $output .= '<a class="slider_right next" href="#" title="Navigate right">NEXT</a>' . "\n";
  291. $output .= "</div>\n";
  292.  
  293. }
  294.  
  295. $output .= '<div class="clear"></div>' . "\n";
  296.  
  297. if($post_content == 'true') {
  298.  
  299. $exp_query = new WP_Query('p=' . $post_id);
  300.  
  301. while ($exp_query->have_posts()) : $exp_query->the_post();
  302.  
  303. $output .= '<div class="widget-post">' . wpautop(get_the_content()) . '</div>';
  304.  
  305. endwhile;
  306.  
  307. }
  308.  
  309. //Category Archives
  310. if($category != true AND !is_page()) {
  311. $cats = get_the_category($post_id);
  312. foreach($cats as $category){
  313.  
  314. $output .= '<a class="archive_link" href="'. get_category_link($category->term_id) .'" title="View '.$category->name .' Archives">' . $category->name . '</a>';
  315.  
  316. }
  317. $output .= '<div class="clear"></div>' . "\n";
  318. }
  319.  
  320.  
  321. if($slider == true){
  322. $output .= '<script type="text/javascript">jQuery(window).load(function(){ jQuery("#slider_'. $slider_id . '").loopedSlider({autoStart:'.$auto.', slidespeed:'.$speed.'});});</script>'; // Init slider wth inline JS
  323. }
  324. $output .= '</div>';
  325. return $output;
  326.  
  327.  
  328. }
  329.  
  330. /*-----------------------------------------------------------------------------------*/
  331. /* WordPress 3.0 New Features Support */
  332. /*-----------------------------------------------------------------------------------*/
  333.  
  334. if ( function_exists('wp_nav_menu') ) {
  335. add_theme_support( 'nav-menus' );
  336. register_nav_menus( array( 'primary-menu' => __( 'Primary Menu' ) ) );
  337. }
  338.  
  339.  
  340. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement