Home / RSS Feeds / Spreaker Automatic Sync
Duplicate Snippet

Embed Snippet on Your Site

Spreaker Automatic Sync

Runs an hourly background task to fetch the Spreaker RSS feed and automatically creates a new cb-episode draft in JetEngine whenever a new podcast episode is published.

Craig Carroll
<10
Code Preview
php
<?php
<?php
add_action( 'wp_footer', function() {
  if ( ! is_singular( 'cb-episode' ) ) return;
  global $post;
  // --- 1. Episode Meta ---
  $ep_num = get_post_meta( $post->ID, 'episode_number', true );
  $spreaker = get_post_meta( $post->ID, 'spreaker_id', true );
  $playback = get_post_meta( $post->ID, 'playback_url', true );
  $description = get_post_meta( $post->ID, 'episode_description', true );
  
  // --- 5. Takeaways ---
  $quote_steve = get_post_meta( $post->ID, 'key_quote_steve', true );
  $quote_craig = get_post_meta( $post->ID, 'key_quote_craig', true );
  
  // --- 6, 7, 8. New Meta Fields ---
  $key_concepts = get_post_meta( $post->ID, 'key_concepts', true ); // expected JSON or text list
  $references = get_post_meta( $post->ID, 'referenced_in_episode', true ); // expected HTML or text list
  $companion_url = get_post_meta( $post->ID, 'companion_post_url', true );
  
  if ( empty($description) && !empty($post->post_content) ) {
    // Basic fallback for description
    $desc_from_content = strip_tags($post->post_content);
    $first_h3 = strpos($desc_from_content, '<h3>');
    if ($first_h3 !== false) $desc_from_content = substr($desc_from_content, 0, $first_h3);
    $description = trim(wp_trim_words($desc_from_content, 60, '...'));
  }
  // --- Transcript Extraction ---
  $raw_content = $post->post_content;
  $transcript_paragraphs = [];
  if (preg_match('/<h3>\s*Full Transcript\s*<\/h3>(.*?)(?=<h3>|\Z)/si', $raw_content, $tr_match)) {
    $tr_html = preg_replace('/<\/p>\s*<p[^>]*>/i', '|||PARA|||', $tr_match[1]);
    $tr_html = preg_replace('/<br\s*\/?>/i', '|||PARA|||', $tr_html);
    $tr_html = strip_tags(str_replace("\n", '|||PARA|||', $tr_html));
    $parts = explode('|||PARA|||', $tr_html);
    foreach ($parts as $p) {
      if (trim($p) && strlen(trim($p)) > 2) $transcript_paragraphs[] = trim($p);
    }
  }
  // --- 10. Related Episodes ---
  $related_eps = get_posts([
      'post_type' => 'cb-episode',
      'posts_per_page' => 3,
      'post__not_in' => [$post->ID],
      'orderby' => 'date',
      'order' => 'DESC'
  ]);
  ?>
  <style>
  .cb-ep-back { display:inline-flex;align-items:center;gap:8px;font-size:14px;color:var(--cb-muted-fg);text-decoration:none;margin-bottom:32px; }
  .cb-ep-back:hover { color:var(--cb-fg); }
  .cb-ep-title { font-family:'Montserrat',system-ui,sans-serif;font-size:clamp(1.75rem,4vw,2.5rem);font-weight:900;color:#000;margin-bottom:8px;line-height:1.2; }
  .cb-ep-badge { background:hsla(221,100%,40%,0.1);color:hsl(221,100%,40%);padding:4px 10px;border-radius:6px;font-weight:700;font-size:13px;display:inline-block;margin-bottom:16px; }
  .cb-ep-hosts { font-size:15px;color:#4b5563;margin-bottom:24px;line-height:1.6; }
  .cb-ep-hosts a { color:#1d4ed8;text-decoration:none;font-weight:500; }
  .cb-ep-hosts a:hover { text-decoration:underline; }
  .cb-ep-summary { font-size:18px;color:#374151;line-height:1.7;margin-bottom:32px;max-width:48rem; }
  
  /* Player */
  .cb-ep-player-wrap { margin-bottom:40px; }
  
  /* Sections */
  .cb-section-title { font-family:var(--cb-font-display);font-size:22px;font-weight:800;color:#000;margin-bottom:16px;margin-top:48px;border-bottom:2px solid #f3f4f6;padding-bottom:8px; }
  
  /* Takeaways */
  .cb-ep-takeaways { background:#f9fafb;border:1px solid #e5e7eb;border-radius:8px;padding:24px;margin-bottom:40px; }
  .cb-ep-takeaways h3 { font-size:16px;font-weight:700;color:#111827;margin-bottom:12px;margin-top:24px; }
  .cb-ep-takeaways h3:first-child { margin-top:0; }
  .cb-ep-takeaways ul { list-style:none;padding:0;margin:0; }
  .cb-ep-takeaways li { position:relative;padding-left:16px;margin-bottom:10px;font-size:15px;line-height:1.6;color:#374151; }
  .cb-ep-takeaways li::before { content:'•';position:absolute;left:0;color:#9ca3af;font-weight:bold; }
  
  /* Definitions & References */
  .cb-ep-concepts dt { font-weight:700;color:#111827;margin-top:16px;font-size:16px; }
  .cb-ep-concepts dd { margin:4px 0 0 0;font-size:15px;color:#4b5563;line-height:1.6; }
  
  .cb-ep-refs ul { list-style:disc;padding-left:20px; }
  .cb-ep-refs li { margin-bottom:8px;font-size:15px;color:#4b5563; }
  
  /* Companion Link */
  .cb-companion-banner { background:#eff6ff;border:1px solid #bfdbfe;padding:16px 20px;border-radius:8px;margin-bottom:40px;display:flex;align-items:center;gap:12px; }
  .cb-companion-banner a { color:#1e40af;font-weight:600;text-decoration:none; }
  
  /* Transcript */
  .cb-tr-speaker { font-weight:700;color:#111827;font-size:15px;margin-top:20px; }
  .cb-tr-text { font-size:15px;line-height:1.7;color:#374151;margin-top:4px; }
  
  /* Related */
  .cb-related-grid { display:grid;grid-template-columns:repeat(auto-fit,minmax(250px,1fr));gap:20px;margin-top:24px; }
  .cb-related-card { border:1px solid #e5e7eb;border-radius:8px;padding:16px;text-decoration:none;color:inherit;display:block;transition:border-color 0.2s; }
  .cb-related-card:hover { border-color:#9ca3af; }
  .cb-related-card h4 { margin:0 0 8px 0;font-size:16px;font-weight:700;color:#111827;line-height:1.4; }
  .cb-related-card p { margin:0;font-size:14px;color:#6b7280; }
  
  /* Closing Module */
  .cb-closing-module { margin-top:64px;padding-top:32px;border-top:1px solid #e5e7eb;text-align:center;color:#4b5563;font-size:15px;line-height:1.6; }
  .cb-closing-module a { color:#111827;font-weight:600;text-decoration:none; }
  .cb-closing-module a:hover { text-decoration:underline; }
  </style>
  <script>
  document.addEventListener('DOMContentLoaded', function() {
    var main = document.querySelector('.entry-content') || document.querySelector('.site-main') || document.querySelector('main') || document.body;
    if (!main) return;
    var h = '<div class="cb-lovable-wrap">';
    h += cbBuildHeader();
    h += '<div class="cb-container" style="padding-top:48px;padding-bottom:64px;max-width:48rem;">';
    h += '<a href="/podcasts/communication-breakdown/" class="cb-ep-back">← All Episodes</a>';
    // 1. Episode Title and Number
    h += '<span class="cb-ep-badge">EP <?php echo esc_js($ep_num); ?></span>';
    h += '<h1 class="cb-ep-title"><?php echo esc_js($post->post_title); ?></h1>';
    // 2. Host Identification
    h += '<p class="cb-ep-hosts">Hosted by <a href="/about/craig-carroll/">Craig E. Carroll, PhD</a> (Founder, Observatory on Corporate Reputation) and <a href="/about/steve-dowling/">Steve Dowling</a> (former Chief Communications Officer, Apple and OpenAI).</p>';
    // 3. Episode Summary
    h += '<p class="cb-ep-summary"><?php echo esc_js($description); ?></p>';
    // 4. Player embed
    <?php if ($playback || $spreaker) : ?>
    h += '<div class="cb-ep-player-wrap">';
    <?php if ($spreaker) : ?>
      h += '<iframe src="https://widget.spreaker.com/player?episode_id=<?php echo esc_js($spreaker); ?>&theme=light" width="100%" height="200" frameborder="0" style="margin-bottom:16px;"></iframe>';
    <?php else : ?>
      h += '<audio controls src="<?php echo esc_url($playback); ?>" style="width:100%;height:40px;margin-bottom:16px;"></audio>';
    <?php endif; ?>
    h += '<div style="display:flex;gap:12px;font-size:13px;color:#6b7280;justify-content:flex-end;">';
    h += 'Listen on: ';
    h += '<a href="https://podcasts.apple.com/us/podcast/communication-breakdown/id1770179558" target="_blank" style="color:#1d4ed8;text-decoration:none;">Apple</a> | ';
    h += '<a href="https://open.spotify.com/show/4HMRh6LRaGMEYBEmzHqV97" target="_blank" style="color:#1DB954;text-decoration:none;">Spotify</a>';
    h += '</div></div>';
    <?php endif; ?>
    // 5. Dual Takeaways
    <?php if ($quote_steve || $quote_craig) : ?>
    h += '<div class="cb-ep-takeaways">';
    <?php if ($quote_steve) : ?>
      h += '<h3>Three takeaways from Steve Dowling:</h3><ul>';
      <?php foreach (preg_split('/\n+/', $quote_steve) as $line) :
        if (!trim($line)) continue;
      ?>
      h += '<li><?php echo esc_js(ltrim(trim($line), '•·-– ')); ?></li>';
      <?php endforeach; ?>
      h += '</ul>';
    <?php endif; ?>
    
    <?php if ($quote_craig) : ?>
      h += '<h3>Three takeaways from Craig E. Carroll, PhD:</h3><ul>';
      <?php foreach (preg_split('/\n+/', $quote_craig) as $line) :
        if (!trim($line)) continue;
      ?>
      h += '<li><?php echo esc_js(ltrim(trim($line), '•·-– ')); ?></li>';
      <?php endforeach; ?>
      h += '</ul>';
    <?php endif; ?>
    h += '</div>';
    <?php endif; ?>
    // 6. Key concepts defined
    <?php if ($key_concepts) : ?>
    h += '<h2 class="cb-section-title">Key concepts discussed in this episode</h2>';
    h += '<dl class="cb-ep-concepts">';
    <?php 
    // Assuming key concepts might be plain text separated by newlines like "Concept — Definition"
    foreach (preg_split('/\n+/', $key_concepts) as $line) :
        $parts = explode('—', $line, 2);
        if (count($parts) == 2) :
    ?>
    h += '<dt><?php echo esc_js(trim($parts[0])); ?></dt>';
    h += '<dd><?php echo esc_js(trim($parts[1])); ?></dd>';
    <?php else: ?>
    h += '<dd><?php echo esc_js(trim($line)); ?></dd>';
    <?php endif; endforeach; ?>
    h += '</dl>';
    <?php endif; ?>
    // 7. Referenced in this episode
    <?php if ($references) : ?>
    h += '<h2 class="cb-section-title">Referenced in this episode</h2>';
    h += '<div class="cb-ep-refs"><?php echo wp_kses_post(wpautop($references)); ?></div>';
    <?php endif; ?>
    // 8. Companion post link
    <?php if ($companion_url) : ?>
    h += '<div class="cb-companion-banner">';
    h += '<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="#1e40af" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"></path><polyline points="14 2 14 8 20 8"></polyline><line x1="16" y1="13" x2="8" y2="13"></line><line x1="16" y1="17" x2="8" y2="17"></line><polyline points="10 9 9 9 8 9"></polyline></svg>';
    h += '<span>A written companion to this episode is available: <a href="<?php echo esc_url($companion_url); ?>">Read the response brief</a></span>';
    h += '</div>';
    <?php endif; ?>
    // 9. Transcript
    <?php if (!empty($transcript_paragraphs)) : ?>
    h += '<h2 class="cb-section-title">Transcript</h2>';
    h += '<div>';
    <?php foreach ($transcript_paragraphs as $para) :
      if (preg_match('/^(Craig Carroll|Steve Dowling):\s*/i', $para, $m)) :
        $speaker = $m[1];
        $text = substr($para, strlen($m[0]));
    ?>
    h += '<div class="cb-tr-speaker"><?php echo esc_js($speaker); ?></div>';
    h += '<p class="cb-tr-text"><?php echo esc_js($text); ?></p>';
    <?php else : ?>
    h += '<p class="cb-tr-text"><?php echo esc_js($para); ?></p>';
    <?php endif; endforeach; ?>
    h += '</div>';
    <?php endif; ?>
    // 10. Related episodes
    <?php if (!empty($related_eps)) : ?>
    h += '<h2 class="cb-section-title">Related Episodes</h2>';
    h += '<p style="color:#4b5563;font-size:15px;margin-bottom:16px;">You might also find these episodes useful:</p>';
    h += '<div class="cb-related-grid">';
    <?php foreach ($related_eps as $rep) : ?>
    h += '<a href="<?php echo get_permalink($rep->ID); ?>" class="cb-related-card">';
    h += '<h4><?php echo esc_js($rep->post_title); ?></h4>';
    h += '<p><?php echo esc_js(wp_trim_words(get_post_meta($rep->ID, 'episode_description', true) ?: $rep->post_content, 15)); ?></p>';
    h += '</a>';
    <?php endforeach; ?>
    h += '</div>';
    <?php endif; ?>
    // 11. The closing module
    h += '<div class="cb-closing-module">';
    h += '<p><strong>Communication Breakdown</strong> is a production of the <a href="https://corporateobservatory.com">Observatory on Corporate Reputation</a>.<br>';
    h += 'Explore our <a href="https://corporateobservatory.com/scas/">Strategic Communications Advisory Service (SCAS)</a> to learn how we help corporate affairs leaders navigate complex reputational challenges.</p>';
    h += '</div>';
    h += '</div>'; // .cb-container
    h += cbBuildFooter();
    h += cbMobileNavStrip('episodes');
    h += '</div>'; // .cb-lovable-wrap
    main.innerHTML = h;
    if(typeof cbInitSearch === 'function') cbInitSearch();
  });
  </script>
  <?php
});

Comments

Add a Comment