How do I do 'if $audio_url is 'from that site' { do something}'?

Hello,

I've been using autoblog and it's working great. But now I have issue if there are 2 or more different sources assigned to same post format because each source requires different styling or sometimes being manually posted as well.

The post format is audio and I've tried to do this :

$audio_url = get_permalink();
if (stripos($audio_url, 'mixcloud.com')!==false) { ....do something
} else {
....do this}

I can't get it working. It's always bypassing the 'if' and do the 'else' right away. Is there something I've missed or do I need to add something in the functions.php?

I got the external permalink correct and I've tried preg_match not working as well.

Could anybody help please please

Thanks
Ben

  • Alexander

    Hi @ben_anggoro,

    Sorry this isn't working. I don't see anything wrong with your code. I'd expect that to evaluate properly. Do you have an example of the $audio_url contents? Could be something there throwing this off. Also, where are you implementing this modification? I'll take a look to see if I can spot anything holding this up.

    Thanks for being a WPMU DEV member. Let us know if we can be of any further assistance.
    Best regards,

  • ben_anggoro

    Hi Alex

    I know right. At least now I know I'm not crazy lol.

    The $audio_url is this http://www.mixcloud.com/djspectrumk/glive-spin-republic-by-dj-spectrum-k-23-05-2013/

    What I want to achieve is that if there is a feed coming from mixcloud, it will create an iframe with mixcloud's code, and if it's not mixcloud (could be user uploaded file), then it will output something else. I've tried and it works without the 'IF' so there's nothing wrong with mixcloud iframe.

    Kinda pulling my hair so I try to see what is going to happen if I set the 'false' to 'true' -- if(stripos($audio_url, 'mixcloud')!== true) -- it worked nicely with mixcloud feed but then all other audio posts are having mixcloud iframe on it so none of them working.

    I'm implementing this on index.php

    Thanks again, if you need further info please let me know.

    Regards
    Ben

  • Alexander

    How about something like this?

    $audio_url = 'http://www.mixclaoud.com/djspectrumk/glive-spin-republic-by-dj-spectrum-k-23-05-2013/';
    
    if (preg_match("^http://www.mixcloud.com/.*^",$audio_url) != false) {
        //Do something
    } else {
        //Do something else
    }

    Just gave this a quick test and it works. This matches anything that starts with http://www.mixcloud.com/ which should prevent it from matching occurrences that might happen later on in the string for any reason.

    Let me know what you think of this.

    Best regards

  • ben_anggoro

    Hi Alex

    Thanks for your help & the quick reply. Still no luck here :slight_frown:
    I changed the $audio_url back to get_permalink() though cause I don't get how it could be autoblog if we put the exact URL everytime?

    Wondering what if I just do a long -if and else if- for each of rss feed that I'm fetching rather than if-else if -by post format and inside it another if else by the feed source?

    Is it possible? What do you think - will that simplify?

    so rather than

    if (post format audio) {
           $audio_url = get_permalink();
           ......
           if (preg_match('regex1',$audio_url)) {
           ///do this
           } else  if (preg_match('regex2',$audio_url)) {
           ///do that
           } else {
           ///get busy
           }
    } else if(post format video) {
          $video_url = get_permalink();
          ........

    what if i do

    if (feed source 1) {
           ///get busy
           } else if (feed source 2) {
           ////get busy
           } else if (feed source 3) {
           ////get busy
           .............

    and keep all post format standard.
    Is it possible? If it is, how do we call each of the feed source?

    Many thanks
    Ben

  • Barry

    What I want to achieve is that if there is a feed coming from mixcloud, it will create an iframe with mixcloud's code, and if it's not mixcloud (could be user uploaded file), then it will output something else. I've tried and it works without the 'IF' so there's nothing wrong with mixcloud iframe.

    The permalink will be the link to the post once it is imported - you need to look at the url of the original post don't you? Or am I reading this incorrectly :slight_smile:

  • ben_anggoro

    Hi Barry, thanks for your reply

    Now for the first one

    The permalink will be the link to the post once it is imported - you need to look at the url of the original post don't you? Or am I reading this incorrectly :slight_smile:

    No, it is fetched automatically with the feed. So basically I just copy the standard code from mixcloud to create the iframe, and then on the part where it is suppose to be the post url (original post url from mixcloud) I just put the permalink

    So

    if (stripos($audio_url, 'mixcloud')!==false) {
    <iframe src=<?php the_permalink() ?> ....../>
    ......

    The problem is now, i cant make the stripos() work. It is always bypassing the if and treat everything as non mixcloud. I dont know why. I've tried pregmatch and other ways still cant so I start to think maybe its the template problem.

    Now I don't get what your second reply is about? Cause the question was, how do I do the same kind of looping that I did with the wp post format, but, instead of post format, i want to use the feed source. Or was it actually explain how to do that?
    Lol sorry just got back from work so kind of slow.

    So instead of

    if (post format audio) {
           $audio_url = get_permalink();
           ......
           if (preg_match('regex1',$audio_url)) {
           ///do this
           } else  if (preg_match('regex2',$audio_url)) {
           ///do that
           } else {
           ///get busy
           }
    } else if(post format video) {
          $video_url = get_permalink();
          ........

    as i do now, i want to be able to do it this way :

    if (feed source 1) {
           ///get busy
           } else if (feed source 2) {
           ////get busy
           } else if (feed source 3) {
           ////get busy
           .............

    I wonder will this help me to solve my problem of not able to identify from which source the audio file is coming from, is it possible to do this, and if possible how can I do that?

    Thanks
    Ben

  • Barry

    No, it is fetched automatically with the feed.

    I assume you're not using autoblog then :slight_smile:, because get_permalink when run in the loop *will* return the url on your site - not the url it was imported from.

    Now I don't get what your second reply is about? Cause the question was, how do I do the same kind of looping that I did with the wp post format, but, instead of post format, i want to use the feed source. Or was it actually explain how to do that?
    Lol sorry just got back from work so kind of slow.

    That post had the code to get the original url of the post (which would have the mixcloud in it) as the method you were using, get_permalink, won't work for the reasons I mentioned above.

  • ben_anggoro

    Hi Barry

    I am using wpmu autoblog & I am using the add-on 'original source permalink' so I am getting the source permalink when i run in the loop.

    Now you telling me that is not possible? Then why I'm getting the original permalink everytime i do this? It works for me, even if its not rendered as link because of the problem im having, it shows the full & correct original source url as text, not link.

    If you don't believe me, where am I suppose to go then? lol It's kind of discouraging comment really.

    Ok so actually we can call the original source. Will try that method.

    Thanks
    Ben

  • Barry

    If you don't believe me, where am I suppose to go then? lol It's kind of discouraging comment really.

    I've just given you the exact code to do what you want to do :slight_smile:

    I didn't realise you had the external permalink add on enabled. All it does is get the same information from the post meta and return it, so it is actually doing the same thing as the code I posted above.

    My code, above, will work even if you don't have that add on enabled.

  • ben_anggoro

    Hi Barry!

    It works! Yay! Many thanks for your help. But yes I think something is not right because now the manually posted audio file can't get the right permalink (local) even if it has it. I mean we can see it is having a local permalink, but we can not get it in the loop using get_permalink.

    I think, will need to check the place the filter Is fired, the external link add-on hooks into the_permalink function rather than the get_the_permalink function which might be why you were having issues.

    Is it something that you would do or am i being suggested to do this? If it's the second could you please advise what to do

    Thanks again
    Ben

  • ben_anggoro

    Hi Barry

    Thanks for digging to it, appreciate it. I'll keep looking out for your way around this.

    I'm just wondering - using the same method you showed me yesterday, would it be possible to fetch the item's array manually? I'm just trying to figure out how to show facebook feed nicely. The plugin returns little info & the thumbnail image only.

    Also, is it possible to fetch enclosure?

    Thanks again
    Ben

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.