New Paste

 

Recent Pastes

Administrate




PageLines PasteBin.

PasteID: 5f3
Pasted by Anonymous, 2013-06-07 16:22:55 GMT
Expires Never
Paste size 12.59 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.4.1
  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. 		$ex_len = ( '' != ploption( 'pins_excerpt', $this->oset ) ) ? ploption( 'pins_excerpt', $this->oset ) : 25;
  154.  
  155. 		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 ){
  156.  
  157. 			if(has_post_thumbnail($p->ID) && get_the_post_thumbnail($p->ID) != ''){
  158. 				$thumb = get_the_post_thumbnail($p->ID, $image_size );
  159.  
  160. 				$check = strpos( $thumb, 'data-lazy-src' );			
  161. 				if( $check ) {					
  162. 					// detected lazy-loader.			
  163. 					$thumb = preg_replace( '#\ssrc="[^"]*"#', '', $thumb );
  164. 					$thumb = str_replace( 'data-lazy-', '', $thumb );	
  165. 				}
  166. 				$image = sprintf('<div class="pin-img-wrap"><a class="pin-img" href="%s">%s</a></div>', get_permalink( $p->ID ), $thumb);
  167. 			} else 
  168. 				$image = '';
  169.  
  170.  
  171. 			$meta_bottom = sprintf(
  172. 				'<div class="pin-meta pin-bottom subtext">%s <span class="divider">/</span> %s</div>', 
  173. 				get_the_time('M j, Y', $p->ID),
  174. 				$this->pl_get_comments_link($p->ID)
  175. 			);
  176.  
  177. 			if(!isset($category)){
  178. 				$meta_top = sprintf(
  179. 					'<div class="pin-meta pin-top subtext">%s</div>', 
  180. 					get_the_category_list( ', ', '', $p->ID)
  181. 				);
  182. 			}
  183.  
  184. 			$content = sprintf(
  185. 				'%s<h4 class="headline pin-title"><a href="%s">%s</a></h4><div class="pin-excerpt summary">%s %s</div>%s', 
  186. 				$meta_top,
  187. 				get_permalink( $p->ID ), 
  188. 				$p->post_title, 
  189. 				( $p->post_excerpt ) ? custom_trim_excerpt($p->post_excerpt, $ex_len) : custom_trim_excerpt($p->post_content, $ex_len), 
  190. 				pledit($p->ID),
  191. 				$meta_bottom
  192. 			);			
  193. 			$out .= sprintf(
  194. 				'<div class="postpin-wrap"><article class="postpin">%s<div class="postpin-pad">%s</div></article></div>', 
  195. 				$image,
  196. 				$content
  197. 			);
  198. 		}
  199. 		$pg = $page+1;
  200. 		$u = $current_url.'?pins='.$pg;
  201.  
  202. 		$next_posts = $this->load_posts($number_of_pins, $pg, $category);
  203.  
  204. 		if( !empty($next_posts) ){
  205.  
  206. 			$class = ( ploption('pins_loading', $this->oset) == 'infinite' ) ? 'iscroll' : 'fetchpins';
  207.  
  208. 			$display = ($class == 'iscroll') ? 'style="display: none"' : '';	
  209.  
  210. 			$next_url = sprintf('<div class="%s fetchlink" %s><a class="btn" href="%s">%s</a></div>', $class, $display, $u, __('Load More Posts', 'pagelines'));
  211.  
  212. 		} else
  213. 			$next_url = '';
  214.  
  215. 		printf('<div class="pinboard fix"><div class="postpin-list fix">%s</div>%s<div class="clear"></div></div>', $out, $next_url);
  216. 	}
  217.  
  218. 	function pl_get_comments_link( $post_id ){
  219.  
  220. 		$num_comments = get_comments_number($post_id);
  221. 		 if ( comments_open() ){
  222. 		 	  if($num_comments == 0){
  223. 		 	  	  $comments = __('Add Comment', 'pagelines');
  224. 		 	  }
  225. 		 	  elseif($num_comments > 1){
  226. 		 	  	  $comments = $num_comments.' '. __('Comments');
  227. 		 	  }
  228. 		 	  else{
  229. 		 	  	   $comments ="1 Comment";
  230. 		 	  }
  231. 		 $write_comments = '<a href="' . get_comments_link($post_id) .'">'. $comments.'</a>';
  232. 		 }
  233. 		else{$write_comments =  '';}
  234.  
  235. 		return $write_comments;
  236.  
  237. 	}
  238.  
  239. 	function load_posts( $number = 20, $page = 1, $category = null, $tag = null, $s = null, $author = null ){
  240.  
  241. 		global $wp_query;
  242.  
  243. 		$query = array();
  244.  
  245. 		if( is_archive() && is_month() )
  246. 			$query['monthnum'] = $wp_query->query_vars['monthnum'];
  247.  
  248. 		if( is_archive() && is_year() )
  249. 			$query['year'] = $wp_query->query_vars['year'];
  250.  
  251. 		if( is_archive() && is_day() )
  252. 			$query['day'] = $wp_query->query_vars['day'];
  253.  
  254. 		if(isset($category))
  255. 			$query['category_name'] = $category;
  256.  
  257. 		if ( isset( $tag ) )
  258. 			$query['tag'] = $tag;
  259.  
  260.  		if( isset( $s ) )
  261.  			$query['s'] = $s;
  262.  		 		if( isset( $author ) )
  263.  			$query['author_name'] = $author;
  264. 		$query['paged'] = $page;
  265.  
  266. 		$query['showposts'] = $number; 		
  267.  
  268. 		$q = new WP_Query($query);
  269.  
  270. 		return $q->posts;
  271. 	}
  272.  
  273. 	/**
  274. 	 *
  275. 	 * Page-by-page options for PostPins
  276. 	 *
  277. 	 */
  278. 	function section_optionator( $settings ){
  279. 		$settings = wp_parse_args( $settings, $this->optionator_default );
  280.  
  281. 			$page_metatab_array = array(
  282. 					'pins_width' => array(
  283. 							'version'		=> 'pro',
  284. 							'type' 			=> 'text_small',
  285. 							'inputlabel' 	=> __( 'Pin Width in Pixels', 'pagelines' ),
  286. 							'title' 		=> __( 'Pin Width', 'pagelines' ),
  287. 							'shortexp' 		=> __( 'The width of post pins in pixels. Default is <strong>237px</strong>.', 'pagelines' )
  288. 					),
  289. 					'pins_thumbsize'	=> array(
  290. 						'type'	=> 'select',
  291. 						'default'	=>	'large',
  292. 						'selectvalues'	=> $this->get_image_sizes(),
  293. 						'inputlabel' 	=> __( 'Select attachment image source', 'pagelines' ),
  294. 						'title' 		=> __( 'Attachment source', 'pagelines' ),
  295. 						'shortexp' 		=> __( 'Select image type: thumbnail, medium, large etc.', 'pagelines' )
  296. 						),
  297. 					'pins_gutterwidth' => array(
  298. 							'version'		=> 'pro',
  299. 							'type' 			=> 'text_small',
  300. 							'inputlabel' 	=> __( 'Pin Gutter Width in Pixels', 'pagelines' ),
  301. 							'title' 		=> __( 'Pin Gutter Width', 'pagelines' ),
  302. 							'shortexp' 		=> __( 'The width of the spacing between post pins in pixels. Default is <strong>15px</strong>.', 'pagelines' )
  303. 					),
  304. 					'pins_number' => array(
  305. 						'version'		=> 'pro',
  306. 						'type' 			=> 'text_small',
  307. 						'inputlabel' 	=> __( 'Number of Pins To Load', 'pagelines' ),
  308. 						'title' 		=> __( 'Number of Pins to Load', 'pagelines' ),
  309. 						'shortexp' 		=> __( 'The number of posts to pull at a time in the section. Default is <strong>15 posts</strong>.', 'pagelines' ),
  310. 						'exp' 			=> __( "Control the amount of posts that are pulled for use in the Pins section at a time.", 'pagelines' ),
  311. 					),
  312. 					'pins_excerpt' => array(
  313. 						'version'		=> 'pro',
  314. 						'type' 			=> 'text_small',
  315. 						'inputlabel' 	=> __( 'Number of words to load.', 'pagelines' ),
  316. 						'title' 		=> __( 'Word Count', 'pagelines' ),
  317. 						'shortexp' 		=> __( 'Number of words to fetch from either content or excerpt if available.', 'pagelines' ),
  318. 					),
  319. 					'pins_loading' => array(
  320. 						'version'		=> 'pro',
  321. 						'type' 			=> 'select',
  322. 						'selectvalues' => array(
  323. 							'infinite' 		=> array('name' => __( 'Use Infinite Scrolling', 'pagelines' ) ),
  324. 							'ajax' 			=> array('name' => __( 'Use Load Posts Link (AJAX)', 'pagelines' ) ),						
  325. 						),
  326. 						'inputlabel' 	=> __( 'Pin Loading Method', 'pagelines' ),
  327. 						'title' 		=> __( 'Post Pin Loading', 'pagelines' ),
  328. 						'shortexp' 		=> __( 'Select the mode for loading new pins on the page. Default is to use <strong>Load Posts Link</strong>.', 'pagelines' ),
  329. 						'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' ),
  330. 					),
  331. 					'pins_category' => array(
  332. 						'version'		=> 'pro',
  333. 						'taxonomy_id'	=> 'category',
  334. 						'type' 			=> 'select_taxonomy',
  335. 						'inputlabel' 	=> __( 'Pin Post Category', 'pagelines' ),
  336. 						'title' 		=> __( 'Pins Category/Posts Mode', 'pagelines' ),
  337. 						'shortexp' 		=> __( 'Select a post category to use with post pins, leave default for all posts.', 'pagelines' ),
  338. 						'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' ),
  339. 					)
  340. 				);
  341.  
  342. 			$metatab_settings = array(
  343. 					'id' 		=> 'postpins_options',
  344. 					'name' 		=> __( 'PostPins', 'pagelines' ),
  345. 					'icon' 		=> $this->icon, 
  346. 					'clone_id'	=> $settings['clone_id'], 
  347. 					'active'	=> $settings['active']
  348. 				);
  349.  
  350. 			register_metatab( $metatab_settings, $page_metatab_array );
  351.  
  352. 	}
  353. 	function get_image_sizes() {
  354. 		global $_wp_additional_image_sizes;
  355.  
  356. 		$sizes = array(
  357. 				'thumbnail' => array( 'name' => 'Thumbnail' ),
  358. 				'medium'=> array( 'name' => 'Medium' ),
  359. 				'large'	=> array( 'name' => 'Large' ),
  360. 				'full'	=> array( 'name' => 'Full' )
  361. 				);
  362. 		if ( is_array( $_wp_additional_image_sizes ) && ! empty( $_wp_additional_image_sizes ) )
  363. 			foreach ( $_wp_additional_image_sizes as $size => $data )
  364. 				$sizes[] = array( 'name' => $size );
  365.  
  366. 		return $sizes;
  367. 	}
  368. }
 
 
 

 
 
 
 
 
Written by Xan Manning, 2010.
YOU NEED FLASH!