Forum Replies Created

Viewing 8 replies - 1 through 8 (of 8 total)
  • Thread Starter hluu

    (@hluu)

    Oh, sorry, I just realize the default powerpress player just uses the audio tag so the player is the browser’s. You have nothing to do with it. My apology.

    Thread Starter hluu

    (@hluu)

    Thank you, Angelo, that works.

    I wouldn’t want the player to pre-load the file, that’d be too slow. I just want it to display the duration if it has the metadata.

    Incidentally, if it doesn’t know the duration, maybe it should display blank rather than 0:00, which is odd looking.

    Thread Starter hluu

    (@hluu)

    This turned out pretty straightforward, as wordpress API makes it easy. Posting code here. Hope this’ll help someone.

    <?php
    
    /*
        Postie add-on to extract [enclosure] short code and insert into meta table the way powerpress does it
        Take, for example,
            [enclosure type="audio/mpeg" url="http://feeds.soundcloud.com/stream/9966888"
                    length="854664" duration="00:23:11"]/>
        and add_post_meta 'enclosure' with value
    
        http://feeds.soundcloud.com/stream/9966888
        854664
        audio/mpeg
        a:1:{s:8:"duration";s:8:"00:23:11";}
    
    */
    
    $enclosure = '';
    
    function extract_enclosure($post) {
        //do something here like update $post['post_content']
        global $enclosure;
    
        // look for a line containing
        // [enclosure ....]
        //
        // may have spaces or > before and spaces after, but must be on line by itself
        $re = '/(\R+|^)[ >]*\[enclosure (.+)?\] *(\R+|$)/m';
    
        if (preg_match($re, $post['post_content'], $m)) {
            // use SimpleXMLElement to parse attribute
            $xml = new SimpleXMLElement("<element {$m[2]} />");
            if ($xml) {
                $enclosure =
                    $xml[0]['url'] . "\n" .
                    $xml[0]['length'] . "\n" .
                    $xml[0]['type'] . "\n" .
                    'a:1:{s:8:"duration";s:8:"' . $xml[0]['duration'] . '";}';
            }
            // replace multiple preceding and trailing \n with 1
            $nl = $m[1] ? "\n" : '';
            $nl .= $m[2] ? "\n" : '';
            $post['post_content'] = preg_replace($re,  $nl, $post['post_content'], 1);
        }
        return $post;
    }
    
    function insert_enclosure($post) {
        global $enclosure;
    
        if ($enclosure) {
            add_post_meta($post['ID'], 'enclosure', $enclosure, true);
        }
        return $post;
    }
    
    add_filter('postie_post_before', 'extract_enclosure');
    add_filter('postie_post_after', 'insert_enclosure');
    
    ?>
    Thread Starter hluu

    (@hluu)

    Ok, I hope I can do this, thanks 🙂

    Thread Starter hluu

    (@hluu)

    Thank you, but I think I went down the wrong path with the [powerpress] shortcode, since that only affects what shows up visually, ie, it will show a media player in the post.

    What I need is to be able to attach a URL to a media file so that it will show up in the feed as an RSS enclosure and be recognized as a podcast episode.

    https://en.wikipedia.org/wiki/RSS_enclosure

    Internally, this isn’t in the post table, but the postmeta table with meta_key ‘enclosure’

    • This reply was modified 8 years, 4 months ago by hluu.
    Thread Starter hluu

    (@hluu)

    Thank you for replying. I know how to do it in the WP editor.

    I’m trying to do it via Postie (post by email). I need to do the equivalent of adding the media URL field in the editor screen — via email.

    Thread Starter hluu

    (@hluu)

    thank you. I managed to do it myself 🙂

    Thread Starter hluu

    (@hluu)

    I mean that in Theme > Default Texts, I have ‘Text for item count’ set to ‘# of rooms’ and that is how it shows in the booking form.

    But when sending email notifications (Your booking request has been sent/accepted/etc), if I add [details] to the email template, the label shows up as ‘Item Count’ and not ‘# of rooms’, which is confusing to the end user.

    like this

    Reservation dates January 31, 2018-February 1, 2018
    Item Count 4

Viewing 8 replies - 1 through 8 (of 8 total)