New Paste

 

Recent Pastes

Administrate




PageLines PasteBin.

PasteID: 8lc
Pasted by Anonymous, 2012-07-02 19:32:27 GMT
Expires Never
Paste size 10.52 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.2.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. 		$url = "http://" . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
  122.  
  123. 		return substr($url,0,strpos($url, '?'));
  124. 	}
  125.  
  126. 	/**
  127. 	* Section template.
  128. 	*/
  129.    function section_template() { 
  130. 		global $wp_query;
  131. 		global $post; 
  132.  
  133. 		if( is_archive() )
  134. 			$category = $wp_query->query_vars['category_name'];
  135. 		else
  136. 			$category = (ploption('pins_category', $this->oset)) ? ploption('pins_category', $this->oset) : null;
  137.  
  138. 		$number_of_pins = (ploption('pins_number', $this->oset)) ? ploption('pins_number', $this->oset) : 15;
  139.  
  140. 		$current_url = $this->pl_current_url();
  141.  
  142. 		$page = (isset($_GET['pins']) && $_GET['pins'] != 1) ? $_GET['pins'] : 1;
  143.  
  144. 		$out = '';
  145.  
  146. 		$meta_top = '';
  147.  
  148. 		foreach( $this->load_posts( $number_of_pins, $page, $category, $wp_query->query_vars['tag'] ) as $key => $p ){
  149.  
  150. 			if(has_post_thumbnail($p->ID) && get_the_post_thumbnail($p->ID) != ''){
  151. 				$thumb = get_the_post_thumbnail($p->ID);
  152.  
  153. 			 	$check = strpos( $thumb, 'data-lazy-src' );
  154.  
  155. 				if( $check ) {
  156.  
  157. 					// detected lazy-loader.
  158.  
  159. 					$thumb = preg_replace( '#\ssrc="[^"]*"#', '', $thumb );
  160. 					$thumb = str_replace( 'data-lazy-', '', $thumb );	
  161. 				}
  162.  
  163. 				$image = sprintf('<div class="pin-img-wrap"><a class="pin-img" href="%s">%s</a></div>', get_permalink( $p->ID ), $thumb);
  164. 			//	plprint( $image );
  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. 				custom_trim_excerpt($p->post_content, 25), 
  188. 				pledit($p->ID),
  189. 				$meta_bottom
  190. 			);
  191.  
  192.  
  193.  
  194. 			$out .= sprintf(
  195. 				'<div class="postpin-wrap"><article class="postpin">%s<div class="postpin-pad">%s</div></article></div>', 
  196. 				$image,
  197. 				$content
  198. 			);
  199. 		}
  200. 		$pg = $page+1;
  201. 		$u = $current_url.'?pins='.$pg;
  202.  
  203. 		$next_posts = $this->load_posts($number_of_pins, $pg, $category);
  204.  
  205. 		if( !empty($next_posts) ){
  206.  
  207. 			$class = ( ploption('pins_loading', $this->oset) == 'infinite' ) ? 'iscroll' : 'fetchpins';
  208.  
  209. 			$display = ($class == 'iscroll') ? 'style="display: none"' : '';	
  210.  
  211. 			$next_url = sprintf('<div class="%s fetchlink" %s><a class="btn" href="%s">%s</a></div>', $class, $display, $u, __('Load More Posts', 'pagelines'));
  212.  
  213. 		} else
  214. 			$next_url = '';
  215.  
  216. 		printf('<div class="pinboard fix"><div class="postpin-list fix">%s</div>%s<div class="clear"></div></div>', $out, $next_url);
  217. 	}
  218.  
  219. 	function pl_get_comments_link( $post_id ){
  220.  
  221. 		$num_comments = get_comments_number($post_id);
  222. 		 if ( comments_open() ){
  223. 		 	  if($num_comments == 0){
  224. 		 	  	  $comments = __('Add Comment', 'pagelines');
  225. 		 	  }
  226. 		 	  elseif($num_comments > 1){
  227. 		 	  	  $comments = $num_comments.' '. __('Comments');
  228. 		 	  }
  229. 		 	  else{
  230. 		 	  	   $comments ="1 Comment";
  231. 		 	  }
  232. 		 $write_comments = '<a href="' . get_comments_link($post_id) .'">'. $comments.'</a>';
  233. 		 }
  234. 		else{$write_comments =  '';}
  235.  
  236. 		return $write_comments;
  237.  
  238. 	}
  239.  
  240. 	function load_posts( $number = 20, $page = 1, $category = null, $tag = null ){
  241. 		$query = array();
  242.  
  243. 		if(isset($category))
  244. 			$query['category_name'] = $category;
  245.  
  246. 		if ( isset( $tag ) )
  247. 			$query['tag'] = $tag;
  248.  
  249. 		$query['paged'] = $page;
  250.  
  251. 		$query['showposts'] = $number; 		
  252.  
  253. 		$q = new WP_Query($query);
  254.  
  255. 		return $q->posts;
  256. 	}
  257.  
  258. 	/**
  259. 	 *
  260. 	 * Page-by-page options for PostPins
  261. 	 *
  262. 	 */
  263. 	function section_optionator( $settings ){
  264. 		$settings = wp_parse_args( $settings, $this->optionator_default );
  265.  
  266. 			$page_metatab_array = array(
  267. 					'pins_width' => array(
  268. 							'version'		=> 'pro',
  269. 							'type' 			=> 'text_small',
  270. 							'inputlabel' 	=> __( 'Pin Width in Pixels', 'pagelines' ),
  271. 							'title' 		=> __( 'Pin Width', 'pagelines' ),
  272. 							'shortexp' 		=> __( 'The width of post pins in pixels. Default is <strong>237px</strong>.', 'pagelines' )
  273. 					),
  274. 					'pins_gutterwidth' => array(
  275. 							'version'		=> 'pro',
  276. 							'type' 			=> 'text_small',
  277. 							'inputlabel' 	=> __( 'Pin Gutter Width in Pixels', 'pagelines' ),
  278. 							'title' 		=> __( 'Pin Gutter Width', 'pagelines' ),
  279. 							'shortexp' 		=> __( 'The width of the spacing between post pins in pixels. Default is <strong>15px</strong>.', 'pagelines' )
  280. 					),
  281. 					'pins_number' => array(
  282. 						'version'		=> 'pro',
  283. 						'type' 			=> 'text_small',
  284. 						'inputlabel' 	=> __( 'Number of Pins To Load', 'pagelines' ),
  285. 						'title' 		=> __( 'Number of Pins to Load', 'pagelines' ),
  286. 						'shortexp' 		=> __( 'The number of posts to pull at a time in the section. Default is <strong>15 posts</strong>.', 'pagelines' ),
  287. 						'exp' 			=> __( "Control the amount of posts that are pulled for use in the Pins section at a time.", 'pagelines' ),
  288. 					), 
  289. 					'pins_loading' => array(
  290. 						'version'		=> 'pro',
  291. 						'type' 			=> 'select',
  292. 						'selectvalues' => array(
  293. 							'infinite' 		=> array('name' => __( 'Use Infinite Scrolling', 'pagelines' ) ),
  294. 							'ajax' 			=> array('name' => __( 'Use Load Posts Link (AJAX)', 'pagelines' ) ),						
  295. 						),
  296. 						'inputlabel' 	=> __( 'Pin Loading Method', 'pagelines' ),
  297. 						'title' 		=> __( 'Post Pin Loading', 'pagelines' ),
  298. 						'shortexp' 		=> __( 'Select the mode for loading new pins on the page. Default is to use <strong>Load Posts Link</strong>.', 'pagelines' ),
  299. 						'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' ),
  300. 					),
  301. 					'pins_category' => array(
  302. 						'version'		=> 'pro',
  303. 						'taxonomy_id'	=> 'category',
  304. 						'type' 			=> 'select_taxonomy',
  305. 						'inputlabel' 	=> __( 'Pin Post Category', 'pagelines' ),
  306. 						'title' 		=> __( 'Pins Category/Posts Mode', 'pagelines' ),
  307. 						'shortexp' 		=> __( 'Select a post category to use with post pins, leave default for all posts.', 'pagelines' ),
  308. 						'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' ),
  309. 					)
  310. 				);
  311.  
  312. 			$metatab_settings = array(
  313. 					'id' 		=> 'postpins_options',
  314. 					'name' 		=> __( 'PostPins', 'pagelines' ),
  315. 					'icon' 		=> $this->icon, 
  316. 					'clone_id'	=> $settings['clone_id'], 
  317. 					'active'	=> $settings['active']
  318. 				);
  319.  
  320. 			register_metatab( $metatab_settings, $page_metatab_array );
  321.  
  322. 	}
  323.  
  324. }
 
 
 

 
 
 
 
 
Written by Xan Manning, 2010.
YOU NEED FLASH!