Advertisement
Guest User

code for function called: sf_get_post_item

a guest
Sep 25th, 2013
176
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 17.42 KB | None | 0 0
  1.  
  2. application/x-httpd-php sf-post-formats.php
  3. PHP script text
  4. <?php
  5.  
  6. /*
  7. *
  8. * Swift Page Builder - Post Format Output Functions
  9. * ------------------------------------------------
  10. * Swift Framework
  11. * Copyright Swift Ideas 2013 - http://www.swiftideas.net
  12. *
  13. */
  14.  
  15.  
  16. /* MAIN GET MEDIA FUNCTION
  17. ================================================== */
  18. function sf_get_post_media($postID, $media_width, $media_height, $video_height, $use_thumb_content) {
  19.  
  20. $format = get_post_format($postID);
  21. $post_media = "";
  22.  
  23. if ($format == "image") {
  24. $post_media = sf_image_post($postID, $media_width, $media_height, $use_thumb_content);
  25. } else if ($format == "video") {
  26. $post_media = sf_video_post($postID, $media_width, $video_height, $use_thumb_content);
  27. } else if ($format == "gallery") {
  28. $post_media = sf_gallery_post($postID, $use_thumb_content);
  29. } else if ($format == "audio") {
  30. $post_media = sf_audio_post($postID);
  31. } else if ($format == "link") {
  32. $post_media = sf_link_post($postID);
  33. } else if ($format == "chat") {
  34. $post_media = sf_chat_post($postID);
  35. }
  36.  
  37. return $post_media;
  38.  
  39. }
  40.  
  41.  
  42. /* GET IMAGE MEDIA
  43. ================================================== */
  44.  
  45. function sf_get_post_format_image_src($post_id){
  46. $format_meta = get_post_format_meta($post_id);
  47. $match = array();
  48. if ($format_meta['image'] != "") {
  49. preg_match('/<img.*?src="([^"]+)"/s', $format_meta['image'], $match);
  50. return $match[1];
  51. }
  52. }
  53.  
  54. function sf_image_post($postID, $media_width, $media_height, $use_thumb_content) {
  55.  
  56. $image = $media_image_url = "";
  57.  
  58. if ($use_thumb_content) {
  59. $media_image = rwmb_meta('sf_thumbnail_image', 'type=image&size=full', $postID);
  60. } else {
  61. $media_image = rwmb_meta('sf_detail_image', 'type=image&size=full', $postID);
  62. }
  63.  
  64. if (!empty($media_image)){
  65. foreach ($media_image as $detail_image) {
  66. $media_image_url = $detail_image['url'];
  67. break;
  68. }
  69. }
  70.  
  71. if (!$media_image) {
  72. $media_image = get_post_thumbnail_id();
  73. $media_image_url = wp_get_attachment_url( $media_image, 'full' );
  74. }
  75.  
  76. $detail_image = aq_resize( $media_image_url, $media_width, $media_height, true, false);
  77.  
  78. if ($detail_image) {
  79. $image = '<img src="'.$detail_image[0].'" width="'.$detail_image[1].'" height="'.$detail_image[2].'" />';
  80. }
  81.  
  82. return $image;
  83. }
  84.  
  85.  
  86. /* GET VIDEO MEDIA
  87. ================================================== */
  88. function sf_video_post($postID, $media_width, $video_height, $use_thumb_content) {
  89.  
  90. $video = $media_video = "";
  91.  
  92. if ($use_thumb_content) {
  93. $media_video = get_post_meta($postID, 'sf_thumbnail_video_url', true);
  94. } else {
  95. $media_video = get_post_meta($postID, 'sf_detail_video_url', true);
  96. }
  97.  
  98. $video = video_embed($media_video, $media_width, $video_height);
  99.  
  100. return $video;
  101. }
  102.  
  103.  
  104. /* GET GALLERY MEDIA
  105. ================================================== */
  106. function sf_gallery_post($postID, $use_thumb_content) {
  107.  
  108. $gallery = '<div class="flexslider item-slider">'."\n";
  109. $gallery .= '<ul class="slides">'."\n";
  110.  
  111. if ($use_thumb_content) {
  112. $media_gallery = rwmb_meta('sf_thumbnail_gallery', 'type=image&size=full-width-image-gallery', $postID);
  113. } else {
  114. $media_gallery = rwmb_meta( 'sf_detail_gallery', 'type=image&size=full-width-image-gallery', $postID);
  115. }
  116.  
  117. foreach ( $media_gallery as $image ) {
  118. $gallery .= "<li><img src='{$image['url']}' width='{$image['width']}' height='{$image['height']}' alt='{$image['alt']}' /></li>";
  119. }
  120.  
  121. $gallery .= '</ul>'."\n";
  122. $gallery .= '</div>'."\n";
  123.  
  124. return $gallery;
  125. }
  126.  
  127.  
  128. /* GET AUDIO MEDIA
  129. ================================================== */
  130. function sf_audio_post($postID) {
  131.  
  132. $audio = "";
  133.  
  134. if (function_exists('get_the_post_format_media')) {
  135.  
  136. $audio = do_shortcode(get_the_post_format_media( 'audio', $null, 1 ));
  137.  
  138. }
  139.  
  140. return $audio;
  141. }
  142.  
  143.  
  144. /* GET LINK MEDIA
  145. ================================================== */
  146. function sf_link_post($postID) {
  147.  
  148. $link = "";
  149.  
  150. if (function_exists('get_the_post_format_url')) {
  151.  
  152. $link = get_the_post_format_url();
  153. $link = '<a href="'.esc_url($link).'" target="_blank" class="link-post-link"><i class="icon-link"></i>'.$link.'</a>';
  154.  
  155. }
  156.  
  157. return $link;
  158. }
  159.  
  160.  
  161. /* GET CHAT MEDIA
  162. ================================================== */
  163. function sf_chat_post($postID) {
  164.  
  165. $chat = "";
  166.  
  167. if (function_exists('get_the_post_format_chat')) {
  168.  
  169. $chat = '<dl class="chat">';
  170. $stanzas = get_the_post_format_chat();
  171.  
  172. foreach ( $stanzas as $stanza ) {
  173. foreach ( $stanza as $row ) {
  174. $time = '';
  175. if ( ! empty( $row['time'] ) )
  176. $time = sprintf( '<time class="chat-timestamp">%s</time>', esc_html( $row['time'] ) );
  177.  
  178. $chat .= sprintf(
  179. '<dt class="chat-author chat-author-%1$s vcard">%2$s <cite class="fn">%3$s</cite>: </dt>
  180. <dd class="chat-text">%4$s</dd>
  181. ',
  182. esc_attr( sanitize_title_with_dashes( $row['author'] ) ), // Slug.
  183. $time,
  184. esc_html( $row['author'] ),
  185. $row['message']
  186. );
  187. }
  188. }
  189.  
  190. $chat .= '</dl><!-- .chat -->';
  191.  
  192. }
  193.  
  194. return $chat;
  195. }
  196.  
  197.  
  198. /* GET POST ITEM
  199. ================================================== */
  200. function sf_get_post_item($postID, $blog_type, $show_title = "yes", $show_excerpt = "yes", $show_details = "yes", $excerpt_length = "20", $content_output = "excerpt", $show_read_more = "yes") {
  201.  
  202. $post_item = "";
  203.  
  204. $post_format = get_post_format($postID);
  205.  
  206. global $sidebars;
  207. $post_format = get_post_format();
  208. if ( $post_format == "" ) {
  209. $post_format = 'standard';
  210. }
  211. $post_title = get_the_title();
  212. $post_author = get_the_author_link();
  213. $post_date = get_the_date();
  214. $post_categories = get_the_category_list(', ');
  215. $post_comments = get_comments_number();
  216. $post_permalink = get_permalink();
  217. $custom_excerpt = get_post_meta($postID, 'sf_custom_excerpt', true);
  218. $post_excerpt = '';
  219. if ($content_output == "excerpt") {
  220. if ($custom_excerpt != '') {
  221. $post_excerpt = custom_excerpt($custom_excerpt, $excerpt_length);
  222. } else {
  223. if ($post_format == "quote") {
  224. $post_excerpt = get_the_content_with_formatting();
  225. } else {
  226. $post_excerpt = excerpt($excerpt_length);
  227. }
  228. }
  229. } else {
  230. $post_excerpt = get_the_content_with_formatting();
  231. }
  232. if ($post_format == "chat") {
  233. $post_excerpt = sf_chat_post($postID);
  234. }
  235.  
  236. $post_item = $thumb_image = $thumb_width = $thumb_height = $bordered_thumb_width = $bordered_thumb_height = $video = $video_height = $bordered_video_height = $item_class = $link_config = $item_icon = '';
  237.  
  238. if ($blog_type == "mini") {
  239. if ($sidebars == "no-sidebars") {
  240. $thumb_width = 446;
  241. $thumb_height = NULL;
  242. $video_height = 335;
  243. } else {
  244. $thumb_width = 290;
  245. $thumb_height = NULL;
  246. $video_height = 218;
  247. }
  248. } else if ($blog_type == "masonry") {
  249. if ($sidebars == "both-sidebars") {
  250. $item_class = "span3";
  251. } else {
  252. $item_class = "span4";
  253. }
  254. $thumb_width = 480;
  255. $thumb_height = NULL;
  256. $video_height = 360;
  257. } else {
  258. if ($sidebars == "both-sidebars") {
  259. if ($show_details == "yes") {
  260. $standard_post_width = "span5";
  261. } else {
  262. $standard_post_width = "span6";
  263. }
  264. } else if ($sidebars == "right-sidebar" || $sidebars == "left-sidebar" || $sidebars == "one-sidebar") {
  265. if ($show_details == "yes") {
  266. $standard_post_width = "span6";
  267. } else {
  268. $standard_post_width = "span7";
  269. }
  270. } else {
  271. if ($show_details == "yes") {
  272. $standard_post_width = "span10";
  273. } else {
  274. $standard_post_width = "span11";
  275. }
  276. }
  277. $thumb_width = 970;
  278. $thumb_height = NULL;
  279. $video_height = 728;
  280. }
  281.  
  282.  
  283. $thumb_type = get_post_meta($postID, 'sf_thumbnail_type', true);
  284. $thumb_image = rwmb_meta('sf_thumbnail_image', 'type=image&size=full');
  285. $thumb_video = get_post_meta($postID, 'sf_thumbnail_video_url', true);
  286. $thumb_gallery = rwmb_meta( 'sf_thumbnail_gallery', 'type=image&size=blog-image' );
  287. $thumb_link_type = get_post_meta($postID, 'sf_thumbnail_link_type', true);
  288. $thumb_link_url = get_post_meta($postID, 'sf_thumbnail_link_url', true);
  289. $thumb_lightbox_thumb = rwmb_meta( 'sf_thumbnail_image', 'type=image&size=large' );
  290. $thumb_lightbox_image = rwmb_meta( 'sf_thumbnail_link_image', 'type=image&size=large' );
  291. $thumb_lightbox_video_url = get_post_meta($postID, 'sf_thumbnail_link_video_url', true);
  292.  
  293. foreach ($thumb_image as $detail_image) {
  294. $thumb_img_url = $detail_image['url'];
  295. break;
  296. }
  297.  
  298. if (!$thumb_image) {
  299. $thumb_image = get_post_thumbnail_id();
  300. $thumb_img_url = wp_get_attachment_url( $thumb_image, 'full' );
  301. }
  302.  
  303. $thumb_lightbox_img_url = wp_get_attachment_url( $thumb_lightbox_image, 'full' );
  304.  
  305. $item_figure = $link_config = "";
  306.  
  307. // LINK TYPE VARIABLES
  308. if ($thumb_link_type == "link_to_url") {
  309. $link_config = 'href="'.$thumb_link_url.'" class="link-to-url"';
  310. $item_icon = "link";
  311. } else if ($thumb_link_type == "link_to_url_nw") {
  312. $link_config = 'href="'.$thumb_link_url.'" class="link-to-url" target="_blank"';
  313. $item_icon = "link";
  314. } else if ($thumb_link_type == "lightbox_thumb") {
  315. $link_config = 'href="'.$thumb_img_url.'" class="view"';
  316. $item_icon = "search";
  317. } else if ($thumb_link_type == "lightbox_image") {
  318. $lightbox_image_url = '';
  319. foreach ($thumb_lightbox_image as $image) {
  320. $lightbox_image_url = $image['full_url'];
  321. }
  322. $link_config = 'href="'.$lightbox_image_url.'" class="view"';
  323. $item_icon = "search";
  324. } else if ($thumb_link_type == "lightbox_video") {
  325. $link_config = 'href="'.$thumb_lightbox_video_url.'" rel="prettyphoto"';
  326. $item_icon = "facetime-video";
  327. } else {
  328. $link_config = 'href="'.$post_permalink.'" class="link-to-post"';
  329. $item_icon = "file-alt";
  330. }
  331.  
  332. // THUMBNAIL MEDIA TYPE SETUP
  333.  
  334. if ($thumb_type != "none") {
  335.  
  336. $item_figure .= '<figure>';
  337.  
  338. if ($thumb_type == "video") {
  339.  
  340. $video = video_embed($thumb_video, $thumb_width, $video_height);
  341.  
  342. $item_figure .= $video;
  343.  
  344. } else if ($thumb_type == "slider") {
  345.  
  346. $item_figure .= '<div class="flexslider thumb-slider"><ul class="slides">';
  347.  
  348. foreach ( $thumb_gallery as $image )
  349. {
  350. $item_figure .= "<li><img src='{$image['url']}' width='{$image['width']}' height='{$image['height']}' alt='{$image['alt']}' /></li>";
  351. }
  352.  
  353. $item_figure .= '</ul><div class="open-item"><a '.$link_config.'></a></div></div>';
  354.  
  355. } else {
  356.  
  357. $image = aq_resize( $thumb_img_url, $thumb_width, $thumb_height, true, false);
  358.  
  359. if ($image) {
  360.  
  361. $item_figure .= '<a '.$link_config.'>';
  362.  
  363. if ($blog_type != "standard") {
  364. $item_figure .= '<div class="overlay"><div class="thumb-info">';
  365. $item_figure .= '<i class="icon-'.$item_icon.'"></i>';
  366. $item_figure .= '</div></div>';
  367. }
  368.  
  369. $item_figure .= '<img src="'.$image[0].'" width="'.$image[1].'" height="'.$image[2].'" />';
  370.  
  371. $item_figure .= '</a>';
  372. }
  373. }
  374.  
  375. $item_figure .= '</figure>';
  376.  
  377. }
  378.  
  379. // MASONRY STYLING
  380. if ($blog_type == "masonry") {
  381.  
  382. if ($post_format == "quote") {
  383. $post_item .= '<div class="quote-display"><i class="icon-quote-left"></i></div>';
  384. } else {
  385. $post_item .= $item_figure;
  386. }
  387.  
  388. $post_item .= '<div class="details-wrap">';
  389.  
  390. if ($show_title == "yes") {
  391. if ($post_format == "link") {
  392. $post_item .= '<h4>'.sf_link_post($postID).'</h4>';
  393. } else {
  394. $post_item .= '<h4><a href="'.$post_permalink.'">'.$post_title.'</a></h4>';
  395. }
  396. }
  397.  
  398. // POST EXCERPT
  399. if ($post_excerpt != "0" && $show_excerpt == "yes") {
  400. $post_item .= '<div class="excerpt">'. $post_excerpt .'</div>';
  401. }
  402.  
  403. if ($show_read_more == "yes") {
  404. $post_item .= '<a class="read-more" href="'.$post_permalink.'">'.__("Read more", "swiftframework").'<i class="icon-angle-right"></i></a>';
  405. }
  406.  
  407. $post_item .= '</div>';
  408.  
  409. // POST DETAILS
  410. if ($show_details == "yes") {
  411. $post_item .= '<div class="post-item-details clearfix">';
  412. $post_item .= '<span class="post-date">'.$post_date.'</span>';
  413. $post_item .= '<div class="comments-likes">';
  414. if ( comments_open() ) {
  415. $post_item .= '<a href="'.$post_permalink.'#comment-area"><i class="icon-comments"></i><span>'. $post_comments .'</span></a> ';
  416. }
  417. if (function_exists( 'lip_love_it_link' )) {
  418. $post_item .= lip_love_it_link(get_the_ID(), '<i class="icon-heart"></i>', '<i class="icon-heart"></i>', false);
  419. }
  420. $post_item .= '</div>';
  421. $post_item .= '</div>';
  422. }
  423.  
  424. // MINI STYLING
  425. } else if ($blog_type == "mini") {
  426.  
  427. $post_item .= $item_figure;
  428.  
  429. $post_item .= '<div class="blog-details-wrap">';
  430.  
  431. if ($show_title == "yes") {
  432. if ($post_format == "link") {
  433. $post_item .= '<h3>'.sf_link_post($postID).'</h3>';
  434. } else {
  435. $post_item .= '<h3><a href="'.$post_permalink.'">'. $post_title .'</a></h3>';
  436. }
  437. }
  438.  
  439. if ($show_details == "yes") {
  440. $post_item .= '<div class="blog-item-details">'. sprintf(__('By <a href="%2$s">%1$s</a> on %3$s', 'swiftframework'), $post_author, get_author_posts_url(get_the_author_meta( 'ID' )), $post_date) .'</div>';
  441.  
  442. $post_item .= '<div class="comments-likes">';
  443. if ( comments_open() ) {
  444. $post_item .= '<a href="'.$post_permalink.'#comment-area"><i class="icon-comments"></i><span>'. $post_comments .'</span></a> ';
  445. }
  446. if (function_exists( 'lip_love_it_link' )) {
  447. $post_item .= lip_love_it_link(get_the_ID(), '<i class="icon-heart"></i>', '<i class="icon-heart"></i>', false);
  448. }
  449. $post_item .= '</div>';
  450. }
  451. if ($show_excerpt == "yes") {
  452. if ($post_format == "quote") {
  453. $post_item .= '<div class="quote-excerpt heading-font">'. $post_excerpt .'</div>';
  454. } else {
  455. $post_item .= '<div class="excerpt">'. $post_excerpt .'</div>';
  456. }
  457. }
  458.  
  459. if ($show_read_more == "yes") {
  460. $post_item .= '<a class="read-more" href="'.$post_permalink.'">'.__("Read more", "swiftframework").'<i class="icon-angle-right"></i></a>';
  461. }
  462.  
  463. $post_item .= '</div>';
  464.  
  465. // STANDARD STYLING
  466. } else {
  467.  
  468. $post_item .= '<div class="row">'; // open row
  469.  
  470. if ($sidebars == "no-sidebars") {
  471. $post_item .= '<div class="standard-post-author span1">';
  472. if(function_exists('get_avatar')) {
  473. $post_item .= '<div class="author-avatar">'. get_avatar(get_the_author_meta('ID'), '164') .'</div>';
  474. }
  475. $post_item .= '<span class="standard-post-author-name">'.__("Posted by", "swiftframework").' '.$post_author.'</span>';
  476. $post_item .= '</div>';
  477. } else if ($sidebars == "right-sidebar" || $sidebars == "left-sidebar" || $sidebars == "one-sidebar") {
  478. $post_item .= '<div class="standard-post-author span1">';
  479. if(function_exists('get_avatar')) {
  480. $post_item .= '<div class="author-avatar">'. get_avatar(get_the_author_meta('ID'), '164') .'</div>';
  481. }
  482. $post_item .= '<span class="standard-post-author-name">'.__("Posted by", "swiftframework").' '.$post_author.'</span>';
  483. $post_item .= '</div>';
  484. }
  485.  
  486. $post_item .= '<div class="standard-post-content '.$standard_post_width.'">'; // open standard-post-content
  487.  
  488. if ($post_format == "quote") {
  489. $post_item .= '<div class="quote-display"><i class="icon-quote-left"></i></div>';
  490. } else {
  491. $post_item .= $item_figure;
  492. if ($show_title) {
  493. if ($post_format == "link") {
  494. $post_item .= '<h2>'.sf_link_post($postID).'</h2>';
  495. } else {
  496. $post_item .= '<h2><a href="'.$post_permalink.'">'. $post_title .'</a></h2>';
  497. }
  498. }
  499. }
  500.  
  501. if ($show_excerpt == "yes") {
  502. if ($post_format == "quote") {
  503. $post_item .= '<div class="quote-excerpt heading-font">'. $post_excerpt .'</div>';
  504. } else {
  505. $post_item .= '<div class="excerpt">'. $post_excerpt .'</div>';
  506. }
  507. }
  508.  
  509. if ($show_read_more == "yes") {
  510. $post_item .= '<a class="read-more" href="'.$post_permalink.'">'.__("Read more", "swiftframework").'<i class="icon-angle-right"></i></a>';
  511. }
  512.  
  513. $post_item .= '</div>'; // close standard-post-content
  514.  
  515. if ($show_details == "yes") {
  516. $post_item .= '<div class="standard-post-details span1">'; // open standard-post-details
  517. if ($sidebars == "both-sidebars") {
  518. $post_item .= '<div class="standard-post-author">';
  519. if(function_exists('get_avatar')) {
  520. $post_item .= '<div class="author-avatar">'. get_avatar(get_the_author_meta('ID'), '164') .'</div>';
  521. }
  522. $post_item .= '<span class="standard-post-author-name">'.__("Posted by", "swiftframework").' '.$post_author.'</span>';
  523. $post_item .= '</div>';
  524. }
  525. $post_item .= '<span class="standard-post-date">'.$post_date.'</span>';
  526. $post_item .= '<div class="comments-likes">';
  527.  
  528. if ( comments_open() ) {
  529. $post_item .= '<div class="comments-wrapper"><a href="'.$post_permalink.'#comment-area"><i class="icon-comments"></i><span>'. $post_comments .'</span></a></div>';
  530. }
  531.  
  532. if (function_exists( 'lip_love_it_link' )) {
  533. $post_item .= lip_love_it_link(get_the_ID(), '<i class="icon-heart"></i>', '<i class="icon-heart"></i>', false);
  534. }
  535.  
  536. $post_item .= '</div>';
  537. $post_item .= '</div>'; // close standard-post-details
  538. }
  539.  
  540. $post_item .= '</div>'; // close row
  541.  
  542. }
  543.  
  544. return $post_item;
  545. }
  546.  
  547. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement