SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Member
    Join Date
    May 2009
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Smile Php Rss to Mail Post

    Hi everyone,

    I have the following code used to auto post on my blog from my video site rss news:

    Code:
    <?php
    
    //Your Blog’s Keyword:
    $keyword = "something";
    
    //How many articles do you want to grab each time?
    $num = 10;
    
    //Get the RSS Feed - In this instance, we’re using a google blogsearch feed based on our chosen keyword
    $feed = simplexml_load_file("videosite . com / rss / $keyword");
    
    //Loop through our keywords
    foreach ($feed->channel->item as $item) {
    
    if($i < $num){
    
    //Have a bit of a rest so we’re not posting too fast to our blogger blog
    sleep(10);
    
    $title = $item ->title;
    $title = str_replace("<b>", "", $title);
    $subject = str_replace("</b>", "", $title);
    $link = $item->link;
    
    $description = $item ->description;
    $description = str_replace("<b>", "", $description);
    $body = str_replace("</b>", "", $description);
    
    //put our secret blogger email address here:
    $to = "mymail . pass(a)blog.com";
    
    //ignore this line - the script just needs something in the “From” field.
    $headers = "From: mail(a)whatever.com";
    
    //Send the email / How’d we go?
    if(mail($to, $subject, $body, $headers)) {
    echo $subject. " - sent<br>";
    }
    else
    {
    echo $subject. " - NOT sent<br>";
    
    }
    }
    //add one to our counter
    $i++;
    
    }
    
    ?>
    
    
    But, there´re are some problems that I need advice...

    1) Every time I run this scipt, it keep posting reapeted videos when there´re no new videos posted on my site. Is it possible to prevent double post (based on title or date) ?

    2) I want the script to read the video url of rss wich is given on <link> code inside rss and use the url to build a picture template of preview video images. The generated rss link is something like: http : / / videosite . com /movies/123456/ videoname . html and the preview images of video should use some variables of that url, like: http : / / pc . videosite . com /f/456/1_123456.jpg and second image: http : / / pc . videosite . com /f/456/2_123456.jpg, and third http : / / pc . videosite . com /f/456/3_123456.jpg, and so on... the variable change is on the number before underline and the three numbers before ".jpg" wich is used on the url as an id.

    Is it possible to make this ? ? ? I tried searching everywhere but no success.

    Thanks in advance.

  2. #2
    SitePoint Addict KJedi's Avatar
    Join Date
    Sep 2005
    Location
    Ukraine, Nikolaev
    Posts
    231
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    1. is simple - remember the biggest date/time of all your videos you grab and ignore everything less or equal next time. This works fine if you have precise time of the post on the video site
    2. For the second one you may use the following code (not tested!):
    PHP Code:
    $url = (string)$item->link;
    $url explode('/'$url);
    $n $url[sizeof($url)-2];
    $last3Digits substr($n, -3);
    for (
    $j 1$j <= 3$j++)
    {
    $imageUrl 'http://pc.videosite.com/f/'.$last3Digits.'/'.$j.'_'.$n.'.jpg';
    //do what you want with $imageUrl

    IQ RIA - Delivering smart web-applications
    High-quality PHP, Yii, Ruby on Rails, ExtJS, Backbone, EmberJS and jQuery consulting.
    Dashboards, HTML5 and CRM development.
    Request a quote now!

  3. #3
    SitePoint Member
    Join Date
    May 2009
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by KJedi View Post
    1. is simple - remember the biggest date/time of all your videos you grab and ignore everything less or equal next time. This works fine if you have precise time of the post on the video site
    2. For the second one you may use the following code (not tested!):
    PHP Code:
    $url = (string)$item->link;
    $url explode('/'$url);
    $n $url[sizeof($url)-2];
    $last3Digits substr($n, -3);
    for (
    $j 1$j <= 3$j++)
    {
    $imageUrl 'ht tp://pc.videosite. com/f/'.$last3Digits.'/'.$j.'_'.$n.'.jpg';
    //do what you want with $imageUrl

    Thanks for fast response but can you write it on my previous code because I&#180;m dumb with php, but I can&#180;t do it in javascript (wich I&#180;m familiarized). I trying inputting your code on mine but without any effect or got errors and I know I did it wrong, just don&#180;t know how to do right !

    Also, here&#180;s a "template" of the email body I need, must be something like:

    Code:
    <div class="imgpost">
    
    <p><img src="ht tp://pc.videosite. com/f/345/1_12345.jpg" border="0" height="120" width="160" /></p>
    <p><img src="ht tp://pc.videosite. com/f/345/2_12345.jpg" border="0" height="120" width="160" /></p>
    <p><img src="ht tp://pc.videosite. com/f/345/3_12345.jpg" border="0" height="120" width="160" /></p>
    <p><img src="ht tp://pc.videosite. com/f/345/4_12345.jpg" border="0" height="120" width="160" /></p>
    <p><img src="ht tp://pc.videosite. com/f/345/5_12345.jpg" border="0" height="120" width="160" /></p>
    <p><img src="ht tp://pc.videosite. com/f/345/6_12345.jpg" border="0" height="120" width="160" /></p>
    <p><img src="ht tp://pc.videosite. com/f/345/7_12345.jpg" border="0" height="120" width="160" /></p>
    <p><img src="ht tp://pc.videosite. com/f/345/8_12345.jpg" border="0" height="120" width="160" /></p>
    <p><img src="ht tp://pc.videosite. com/f/345/9_12345.jpg" border="0" height="120" width="160" /></p>
    <p><img src="ht tp://pc.videosite. com/f/345/10_12345.jpg" border="0" height="120" width="160" /></p>
    
    
    </div>
    
    
    <span class="fullpost">
    
    
    <center>
    <input class="sbuttonpost" value="Load Movie" onclick="frames['IFrameName'].location.href='[LINK FROM RSS FEED]' type="submit" width="560" style='display: none'></center>
    
    <div id="viewPort">
    
    
    <center>
    
    <iframe name="IFrameName" id="iframeContent" hspace="0" vspace="0" frameborder="0" scrolling="no"></iframe>
    
    </center>
    </div>
    1. The images are movie previews and the last 3 digits must be pulled from $link url (url on feed is something like ht tp://videosite.com/videos/12345/title_of_the_movie.html) generated by rss feed for each feed. Each feed have a different number, because it&#180;s the movie id so, for example... one is 12345, other is 98765 and other is 67890, always five digits and last three are the ids for pulling on the <img src=...> tag after videosite.com/f/, but the id must be full (5 digits) before .jpg extension inside that tag.

    2. The $link variable also must be pulled inside [LINK FROM RSS FEED] on template.

    3. As I&#180;m a dummie in PHP I can&#180;t imagine how to prevent the double post... in javascript the method should be writing a log file in txt and compare the post title from rss feed to the log, If same title exists, pass to next feed or die. But I can&#180;t make it on javascript as the movie script is in php and it&#180;s a premade php video site.

    For now thanks a lot !

  4. #4
    SitePoint Member
    Join Date
    May 2009
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    No clue ?


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •