New Paste

 

Recent Pastes

Administrate




PageLines PasteBin.

PasteID: 1lj
Pasted by Anonymous, 2012-12-04 01:27:33 GMT
Expires Never
Paste size 11.79 Kb
Toggle Expand   Wrap   Raw
Copy Contents   Copy URL
 
  1. <?php
  2. /*
  3. 	Section: PostPins
  4. 	Author: PageLines
  5. 	Author URI: http://www.pagelines.com
  6. 	Description: A continuous list of post 'pins', inspired by Pinterest. Loaded dynamically and arranged organically.
  7. 	Class Name: PostPins	
  8. 	Workswith: templates, main
  9. 	Edition: Pro
  10. 	Demo: http://demo.pagelines.com/framework/postpins/
  11. 	Version: 1.3
  12. */
  13.  
  14. /**
  15.  * Main section class
  16.  *
  17.  * @package PageLines Framework
  18.  * @author PageLines
  19.  */
  20. class PostPins extends PageLinesSection {
  21.  
  22. 	/**
  23. 	 * Load styles and scripts
  24. 	 */
  25. 	function section_styles(){
  26. 		wp_enqueue_script('masonry', $this->base_url.'/script.masonry.js', array( 'jquery' ) );
  27. 		wp_enqueue_script('infinitescroll', $this->base_url.'/script.infinitescroll.js', array( 'jquery' ) );
  28. 	}
  29.  
  30. 	function section_head(){
  31.  
  32. 		$width = (ploption('pins_width', $this->oset)) ? ploption('pins_width', $this->oset) : 255;
  33. 		$gutter_width = (ploption('pins_gutterwidth', $this->oset)) ? ploption('pins_gutterwidth', $this->oset) : 15;
  34. 		?>
  35. 		<style>.postpin-wrap{width: <?php echo $width;?>px; }</style>
  36. 		<script>
  37.  
  38. 		jQuery(document).ready(function () {
  39.  
  40. 			var theContainer = jQuery('.postpin-list');
  41. 			var containerWidth = theContainer.width();
  42.  
  43.  
  44. 			theContainer.imagesLoaded(function(){
  45.  
  46. 				theContainer.masonry({
  47. 					itemSelector : '.postpin-wrap',
  48. 					columnWidth: <?php echo $width;?>,
  49. 					gutterWidth: <?php echo $gutter_width;?>,
  50. 					isFitWidth: true
  51. 				});
  52.  
  53. 			});
  54.  
  55. 			<?php if(ploption('pins_loading', $this->oset) == 'infinite'): ?>
  56.  
  57. 				theContainer.infinitescroll({
  58. 					navSelector : '.iscroll',
  59. 					nextSelector : '.iscroll a',
  60. 					itemSelector : '.postpin-list .postpin-wrap',
  61. 					loadingText : 'Loading...',
  62. 					loadingImg :  '<?php echo $this->base_url."/load.gif";?>',
  63. 					donetext : 'No more pages to load.',
  64. 					debug : true,
  65. 					loading: {
  66. 						finishedMsg: 'No more pages to load.'
  67. 					}
  68. 				}, function(arrayOfNewElems) {
  69. 					theContainer.imagesLoaded(function(){
  70. 						theContainer.masonry('appended', jQuery(arrayOfNewElems));
  71. 					});
  72. 				});
  73.  
  74. 			<?php endif;?>
  75.  
  76. 		});
  77.  
  78. 			<?php if(ploption('pins_loading', $this->oset) != 'infinite'): ?>
  79. 			jQuery('.fetchpins a').live('click', function(e) {
  80. 				e.preventDefault();
  81. 				jQuery(this).addClass('loading').text('<?php _e('Loading...', 'pagelines');?>');
  82. 				jQuery.ajax({
  83. 					type: "GET",
  84. 					url: jQuery(this).attr('href') + '#pinboard',
  85. 					dataType: "html",
  86. 					success: function(out) {
  87.  
  88. 						result = jQuery(out).find('.pinboard .postpin-wrap');
  89. 						nextlink = jQuery(out).find('.fetchpins a').attr('href');
  90.  
  91. 						var theContainer = jQuery('.postpin-list');
  92.  
  93. 						theContainer.append(result);
  94.  
  95. 						theContainer.imagesLoaded(function(){
  96. 							theContainer.masonry('appended', result);
  97. 						});
  98.  
  99. 						jQuery('.fetchpins a').removeClass('loading').text('<?php _e('Load More Posts', 'pagelines');?>');
  100.  
  101.  
  102.  
  103. 						if (nextlink != undefined) {
  104. 							jQuery('.fetchpins a').attr('href', nextlink);
  105. 						} else {
  106. 							jQuery('.fetchpins').remove();
  107. 						}
  108. 					}
  109. 				});
  110. 			});
  111. 			<?php endif;?>
  112.  
  113.  
  114. 		</script>
  115. 	<?php }
  116.  
  117. 	/* Section template.
  118. 	 ****************************/
  119. 	function pl_current_url(){
  120.  
  121.  
  122. 		$url = "http://" . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
  123.  
  124. 		return substr($url,0,strpos($url, '?'));
  125. 	}
  126.  
  127. 	/**
  128. 	* Section template.
  129. 	*/
  130.    function section_template() { 
  131.  
  132.  
  133. 		global $wp_query;
  134. 		global $post; 
  135.  
  136. 		if( is_category() )
  137. 			$category = $wp_query->query_vars['category_name'];
  138. 		else
  139. 			$category = (ploption('pins_category', $this->oset)) ? ploption('pins_category', $this->oset) : null;
  140.  
  141. 		$number_of_pins = (ploption('pins_number', $this->oset)) ? ploption('pins_number', $this->oset) : 15;
  142.  
  143. 		$current_url = $this->pl_current_url();
  144.  
  145. 		$image_size = ( ploption( 'pins_thumbsize', $this->oset ) ) ? ploption( 'pins_thumbsize', $this->oset ) : 'medium';
  146.  
  147. 		$page = (isset($_GET['pins']) && $_GET['pins'] != 1) ? $_GET['pins'] : 1;
  148.  
  149. 		$out = '';
  150.  
  151. 		$meta_top = '';
  152.  
  153. 		foreach( $this->load_posts( $number_of_pins, $page, $category, $wp_query->query_vars['tag'],$wp_query->query_vars['s'], $wp_query->query_vars['author_name']) as $key => $p ){
  154.  
  155. 			if(has_post_thumbnail($p->ID) && get_the_post_thumbnail($p->ID) != ''){
  156. 				$thumb = get_the_post_thumbnail($p->ID, $image_size );
  157.  
  158. 				$check = strpos( $thumb, 'data-lazy-src' );			
  159. 				if( $check ) {					
  160. 					// detected lazy-loader.			
  161. 					$thumb = preg_replace( '#\ssrc="[^"]*"#', '', $thumb );
  162. 					$thumb = str_replace( 'data-lazy-', '', $thumb );	
  163. 				}
  164. 				$image = sprintf('<div class="pin-img-wrap"><a class="pin-img" href="%s">%s</a></div>', get_permalink( $p->ID ), $thumb);
  165. 			} else 
  166. 				$image = '';
  167.  
  168.  
  169. 			$meta_bottom = sprintf(
  170. 				'<div class="pin-meta pin-bottom subtext">%s <span class="divider">/</span> %s</div>', 
  171. 				get_the_time('M j, Y', $p->ID),
  172. 				$this->pl_get_comments_link($p->ID)
  173. 			);
  174.  
  175. 			if(!isset($category)){
  176. 				$meta_top = sprintf(
  177. 					'<div class="pin-meta pin-top subtext">%s</div>', 
  178. 					get_the_category_list( ', ', '', $p->ID)
  179. 				);
  180. 			}
  181.  
  182. 			$content = sprintf(
  183. 				'%s<h4 class="headline pin-title"><a href="%s">%s</a></h4><div class="pin-excerpt summary">%s %s</div>%s', 
  184. 				$meta_top,
  185. 				get_permalink( $p->ID ), 
  186. 				$p->post_title, 
  187. 				( $p->post_excerpt ) ? custom_trim_excerpt($p->post_excerpt, 25) : custom_trim_excerpt($p->post_content, 25), 
  188. 				pledit($p->ID),
  189. 				$meta_bottom
  190. 			);			
  191. 			$out .= sprintf(
  192. 				'<div class="postpin-wrap"><article class="postpin">%s<div class="postpin-pad">%s</div></article></div>', 
  193. 				$image,
  194. 				$content
  195. 			);
  196. 		}
  197. 		$pg = $page+1;
  198. 		$u = $current_url.'?pins='.$pg;
  199.  
  200. 		$next_posts = $this->load_posts($number_of_pins, $pg, $category);
  201.  
  202. 		if( !empty($next_posts) ){
  203.  
  204. 			$class = ( ploption('pins_loading', $this->oset) == 'infinite' ) ? 'iscroll' : 'fetchpins';
  205.  
  206. 			$display = ($class == 'iscroll') ? 'style="display: none"' : '';	
  207.  
  208. 			$next_url = sprintf('<div class="%s fetchlink" %s><a class="btn" href="%s">%s</a></div>', $class, $display, $u, __('Load More Posts', 'pagelines'));
  209.  
  210. 		} else
  211. 			$next_url = '';
  212.  
  213. 		printf('<div class="pinboard fix"><div class="postpin-list fix">%s</div>%s<div class="clear"></div></div>', $out, $next_url);
  214. 	}
  215.  
  216. 	function pl_get_comments_link( $post_id ){
  217.  
  218. 		$num_comments = get_comments_number($post_id);
  219. 		 if ( comments_open() ){
  220. 		 	  if($num_comments == 0){
  221. 		 	  	  $comments = __('Add Comment', 'pagelines');
  222. 		 	  }
  223. 		 	  elseif($num_comments > 1){
  224. 		 	  	  $comments = $num_comments.' '. __('Comments');
  225. 		 	  }
  226. 		 	  else{
  227. 		 	  	   $comments ="1 Comment";
  228. 		 	  }
  229. 		 $write_comments = '<a href="' . get_comments_link($post_id) .'">'. $comments.'</a>';
  230. 		 }
  231. 		else{$write_comments =  '';}
  232.  
  233. 		return $write_comments;
  234.  
  235. 	}
  236.  
  237. 	function load_posts( $number = 20, $page = 1, $category = null, $tag = null, $s = null, $author = null ){
  238. 		$query = array();
  239.  
  240. 		if(isset($category))
  241. 			$query['category_name'] = $category;
  242.  
  243. 		if ( isset( $tag ) )
  244. 			$query['tag'] = $tag;
  245.  
  246.  		if( isset( $s ) )
  247.  			$query['s'] = $s;
  248.  		 		if( isset( $author ) )
  249.  			$query['author_name'] = $author;
  250. 		$query['paged'] = $page;
  251.  
  252. 		$query['showposts'] = $number; 		
  253.  
  254. 		$q = new WP_Query($query);
  255.  
  256. 		return $q->posts;
  257. 	}
  258.  
  259. 	/**
  260. 	 *
  261. 	 * Page-by-page options for PostPins
  262. 	 *
  263. 	 */
  264. 	function section_optionator( $settings ){
  265. 		$settings = wp_parse_args( $settings, $this->optionator_default );
  266.  
  267. 			$page_metatab_array = array(
  268. 					'pins_width' => array(
  269. 							'version'		=> 'pro',
  270. 							'type' 			=> 'text_small',
  271. 							'inputlabel' 	=> __( 'Pin Width in Pixels', 'pagelines' ),
  272. 							'title' 		=> __( 'Pin Width', 'pagelines' ),
  273. 							'shortexp' 		=> __( 'The width of post pins in pixels. Default is <strong>237px</strong>.', 'pagelines' )
  274. 					),
  275. 					'pins_thumbsize'	=> array(
  276. 						'type'	=> 'select',
  277. 						'default'	=>	'large',
  278. 						'selectvalues'	=> $this->get_image_sizes(),
  279. 						'inputlabel' 	=> __( 'Select attachment image source', 'pagelines' ),
  280. 						'title' 		=> __( 'Attachment source', 'pagelines' ),
  281. 						'shortexp' 		=> __( 'Select image type: thumbnail, medium, large etc.', 'pagelines' )
  282. 						),
  283. 					'pins_gutterwidth' => array(
  284. 							'version'		=> 'pro',
  285. 							'type' 			=> 'text_small',
  286. 							'inputlabel' 	=> __( 'Pin Gutter Width in Pixels', 'pagelines' ),
  287. 							'title' 		=> __( 'Pin Gutter Width', 'pagelines' ),
  288. 							'shortexp' 		=> __( 'The width of the spacing between post pins in pixels. Default is <strong>15px</strong>.', 'pagelines' )
  289. 					),
  290. 					'pins_number' => array(
  291. 						'version'		=> 'pro',
  292. 						'type' 			=> 'text_small',
  293. 						'inputlabel' 	=> __( 'Number of Pins To Load', 'pagelines' ),
  294. 						'title' 		=> __( 'Number of Pins to Load', 'pagelines' ),
  295. 						'shortexp' 		=> __( 'The number of posts to pull at a time in the section. Default is <strong>15 posts</strong>.', 'pagelines' ),
  296. 						'exp' 			=> __( "Control the amount of posts that are pulled for use in the Pins section at a time.", 'pagelines' ),
  297. 					), 
  298. 					'pins_loading' => array(
  299. 						'version'		=> 'pro',
  300. 						'type' 			=> 'select',
  301. 						'selectvalues' => array(
  302. 							'infinite' 		=> array('name' => __( 'Use Infinite Scrolling', 'pagelines' ) ),
  303. 							'ajax' 			=> array('name' => __( 'Use Load Posts Link (AJAX)', 'pagelines' ) ),						
  304. 						),
  305. 						'inputlabel' 	=> __( 'Pin Loading Method', 'pagelines' ),
  306. 						'title' 		=> __( 'Post Pin Loading', 'pagelines' ),
  307. 						'shortexp' 		=> __( 'Select the mode for loading new pins on the page. Default is to use <strong>Load Posts Link</strong>.', 'pagelines' ),
  308. 						'exp' 			=> __( "Use infinite scroll loading to automatically load new pins when users get to the bottom of the page. Alternatively, you can use a link that users can click to 'load new pins' into the page.", 'pagelines' ),
  309. 					),
  310. 					'pins_category' => array(
  311. 						'version'		=> 'pro',
  312. 						'taxonomy_id'	=> 'category',
  313. 						'type' 			=> 'select_taxonomy',
  314. 						'inputlabel' 	=> __( 'Pin Post Category', 'pagelines' ),
  315. 						'title' 		=> __( 'Pins Category/Posts Mode', 'pagelines' ),
  316. 						'shortexp' 		=> __( 'Select a post category to use with post pins, leave default for all posts.', 'pagelines' ),
  317. 						'exp' 			=> __( "You can select to use only posts from a specific category, leave blank to use all posts. Default is to show all posts.", 'pagelines' ),
  318. 					)
  319. 				);
  320.  
  321. 			$metatab_settings = array(
  322. 					'id' 		=> 'postpins_options',
  323. 					'name' 		=> __( 'PostPins', 'pagelines' ),
  324. 					'icon' 		=> $this->icon, 
  325. 					'clone_id'	=> $settings['clone_id'], 
  326. 					'active'	=> $settings['active']
  327. 				);
  328.  
  329. 			register_metatab( $metatab_settings, $page_metatab_array );
  330.  
  331. 	}
  332. 	function get_image_sizes() {
  333. 		global $_wp_additional_image_sizes;
  334.  
  335. 		$sizes = array(
  336. 				'thumbnail' => array( 'name' => 'Thumbnail' ),
  337. 				'medium'=> array( 'name' => 'Medium' ),
  338. 				'large'	=> array( 'name' => 'Large' ),
  339. 				'full'	=> array( 'name' => 'Full' )
  340. 				);
  341. 		if ( is_array( $_wp_additional_image_sizes ) && ! empty( $_wp_additional_image_sizes ) )
  342. 			foreach ( $_wp_additional_image_sizes as $size => $data )
  343. 				$sizes[] = array( 'name' => $size );
  344.  
  345. 		return $sizes;
  346. 	}
  347. }
 
 
 

 
 
 
 
 
Written by Xan Manning, 2010.
YOU NEED FLASH!