Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
  • 3 commits
  • 1 file changed
  • 0 comments
  • 1 contributor
Nov 28, 2012
Formatting and Display: create new option to allow user to insert equ…
…ivalent of a WordPress [gallery] element at top or bottom of syndicated posts. Useful for feeds where the images are in enclosures but not in post content.
522487f
Enclosures / Allow MediaRSS packages and other enclosures recognized …
…by SimplePie to be pulled into gallery.
5f8f003
Tweak / Take down number of image posts handled on any given update c…
…ycle down by a bit.
25dc5ed

Showing 1 changed file with 60 additions and 1 deletion. Show diff stats Hide diff stats

  1. 61  fwp-sic-em/SicEm.php
61  fwp-sic-em/SicEm.php
@@ -35,6 +35,9 @@ function SicEm () {
35 35
 		add_action('feedwordpress_admin_page_posts_save', array(&$this, 'save_settings'), 10, 2);
36 36
 		add_filter('feedwordpress_diagnostics', array(&$this, 'diagnostics'), 10, 2);
37 37
 		
  38
+		// If user opts for it, put a gallery at the end of syndicated posts
  39
+		add_filter('the_content', array(&$this, 'the_content'), 200000, 2);
  40
+		
38 41
 		global $pagenow;
39 42
 		global $sicem_path;
40 43
 		if (WP_ADMIN) : // set up image picker through massive fuckery
@@ -113,6 +116,19 @@ function display_settings ($page, $box = NULL) {
113 116
 			'default-input-value' => 'default',
114 117
 			);
115 118
 			
  119
+			$insertGallerySelector = array(
  120
+			"no" => __("<em>Leave it alone.</em> Just show the post as it appeared on the feed"),
  121
+			"before" => __("<em>Gallery above post.</em> Insert a gallery of attached images at the top of syndicated posts."),
  122
+			"after" => __("<em>Gallery below post.</em> Insert a gallery of attached images at the bottom of syndicated posts."),
  123
+			);
  124
+
  125
+			$igsParams = array(
  126
+			'input-name' => 'sicem_insert_gallery',
  127
+			'setting-default' => NULL,
  128
+			'global-setting-default' => 'no',
  129
+			'default-input-value' => 'default',
  130
+			);
  131
+			
116 132
 			$globalDefaultFeaturedImage = get_option('feedwordpress_featured_image_default', NULL);
117 133
 			if ($page->for_feed_settings()) :
118 134
 				$defaultFeaturedImage = $page->link->setting('featured image default', 'featured_image_default', NULL);
@@ -183,6 +199,14 @@ function display_settings ($page, $box = NULL) {
183 199
 		<div><label>Name: <input type="text" name="sicem_custom_field_name" value="<?php print esc_attr($customFieldName); ?>" size="15" placeholder="custom field name" /></label>
184 200
 		<div class="setting-description">Leave blank if you don't need to store the URL.</div></div></td></tr>
185 201
 		
  202
+		<tr><th scope="row"><?php _e('Display Image Gallery with Post:'); ?></th>
  203
+		<td><p style="margin-top:0px">When WordPress displays a syndicated post with captured images attached to it...</p>
  204
+		<?php
  205
+			$page->setting_radio_control(
  206
+				'sicem insert gallery', 'sicem_insert_gallery',
  207
+				$insertGallerySelector, $igsParams);
  208
+		?></td></tr>
  209
+
186 210
 		<tr><th scope="row"><?php _e('Image Size: '); ?></th>
187 211
 		<td>
188 212
 <?php
@@ -236,6 +260,7 @@ function save_settings ($params, $page) {
236 260
 			$page->update_setting('feature captured images', $params['sicem_feature_images']);
237 261
 			$page->update_setting('featured image default', $params['sicem_default_featured_image']);
238 262
 			$page->update_setting('sicem custom field', $params['sicem_custom_field_name']);
  263
+			$page->update_setting('sicem insert gallery', $params['sicem_insert_gallery']);
239 264
 			
240 265
 			// empty strings mean a null value
241 266
 			foreach (array('crop ratio', 'resize') as $key) :
@@ -276,6 +301,33 @@ function save_settings ($params, $page) {
276 301
 	// FUNCTIONALITY ///////////////////////////////////////////////////////////
277 302
 	////////////////////////////////////////////////////////////////////////////
278 303
 	var $post;
  304
+
  305
+	function the_content ($content) {
  306
+		global $post;
  307
+		
  308
+		if (function_exists('is_syndicated')) :
  309
+			if (is_syndicated()) :
  310
+				$source = get_syndication_feed_object($post->ID);
  311
+				$ig = $source->setting('sicem insert gallery', 'sicem_insert_gallery', 'no');
  312
+				switch ($ig) :
  313
+				case 'before' :
  314
+					$content = do_shortcode('[gallery]')."\n\n".$content;
  315
+					break;
  316
+				case 'after' :
  317
+					$content = $content."\n\n".do_shortcode('[gallery]');
  318
+					break;
  319
+					
  320
+				// Leave it.
  321
+				case 'no' :
  322
+				default :
  323
+					// NOOP
  324
+				endswitch;
  325
+			endif;
  326
+		endif;
  327
+		
  328
+		return $content;
  329
+	}
  330
+
279 331
 	function process_post ($data, $post) {
280 332
 		$img_src = FeedWordPressHTML::attributeRegex('img', 'src');
281 333
 		
@@ -314,6 +366,13 @@ function process_post ($data, $post) {
314 366
 			endforeach;
315 367
 		endif;
316 368
 
  369
+		$enclosures = $post->entry->get_enclosures();
  370
+		if (is_array($enclosures) and count($enclosures) > 0) :
  371
+			foreach ($enclosures as $enclosure) :
  372
+				$data['meta']['_syndicated_image_capture'][] = $enclosure->get_link();
  373
+			endforeach;
  374
+		endif;
  375
+		
317 376
 		$thumb_id = $post->link->setting('featured image default', 'featured_image_default', NULL);
318 377
 		if ($thumb_id) :
319 378
 			$data['meta']['_thumbnail_id'] = $thumb_id;
@@ -329,7 +388,7 @@ function process_captured_images ($delta) {
329 388
 		$q = new WP_Query(array(
330 389
 		'post_type' => 'any',
331 390
 		'meta_key' => '_syndicated_image_capture',
332  
-		'posts_per_page' => 15,
  391
+		'posts_per_page' => 10,
333 392
 		));
334 393
 		
335 394
 		while ($q->have_posts()) : $q->the_post();

No commit comments for this range

Something went wrong with that request. Please try again.