TalkPHP

TalkPHP (http://www.talkphp.com/forums.php)
-   Absolute Beginners (http://www.talkphp.com/absolute-beginners/)
-   -   update on my youtube rss grabber need help. [NO FLAME] (http://www.talkphp.com/absolute-beginners/3116-update-my-youtube-rss-grabber-need-help-no-flame.html)

codefreek 07-13-2008 11:44 PM

update on my youtube rss grabber need help. [NO FLAME]
 
please don't flame me for the code i know it's messy but i coded out my ass so some things just came on the page :P
i will fix it later so please try to just focus on helping me
thank you in advance!


PHP Code:

<style type="text/css">
body {
margin:0px 0px 0px 0px;
background: #000000;
padding: 0px;
color: #00FF00;
}
ul { 
list-style-type: none; 

A:hover {text-decoration: underline overline; color: red;}

#videotumbnail {
text-decoration:none;        
width: 200px; 
height: 140px; 
background: #F1F1F1;
color: #FF0000;
padding: 0px;
margin: 0px;



}

#videotitle {
text-decoration:none;
width: 200px;
hight: 140px;        
background: #F1F1F1;
color: #00FF00;
padding: 0px;
border-left: 2px solid #FF7744;
border-right: 2px solid #FF7744;
border-down: 2px solid #FF7744;
border-up: 2px solid #FF7744;
margin: 0px;

}




#all {
text-decoration:none;
width: 200px;
hight: 140px;        
background: #FFFFFF;
color: #00FF00;
padding: 0px;
border-left: 2px solid #FF7744;
border-right: 2px solid #FF7744;
border-down: 2px solid #FF7744;
border-up: 2px solid #FF7744;
margin: 0px;

}

.p {
text-decoration:none;
width: 200px;
hight: 140px;        
background: #FFFFFF;
color: #00FF00;
padding: 0px;
border-left: 2px solid #FF7744;
border-right: 2px solid #FF7744;
border-down: 2px solid #FF7744;
border-up: 2px solid #FF7744;
margin: 0px;

}

#videodescription {
text-decoration:none;
width: 200px;
hight: 140px;        
background: #FFFFFF;
color: #00FF00;
padding: 0px;
margin: 0px;
float:right;


}
</style>    

    
<?php
    
//Codefreek Production 
    //www.talkphp.com 
    //BETA 0.1 RSS Grabber From Youtube 
    //Copyright 08 - 09 by codefreek
    //if you like please pm me and say thank you and i will continue doing more free scripts.

    //only use when needed!
    //ini_set("user_agent","Internet Explorer");

    //Edit here for your rss link
    
$location "http://youtube.com/rss/global/top_rated.rss";
    
$contents file_get_contents($location);
    
$xml      = new SimpleXMLElement($contents);
    
$limiter 0;
    
$limit 0// use 0 for no limit
    
$desclimit 120// use 0 for no limit
    
$i 0;
    
$str "";
        
$img preg_replace('/^.*?(<img [^>]+>).*$/is','\1',$item->description); // Uncomment if you need full <img /> tag
            
$imgsrc preg_replace('/^.*?(<img [^>]*?src="([^"]+)"[^>]*>).*$/is','\2',$item->description);
            
$tmp_desc preg_replace('#.*?(<p>.+?</p>).*#is','\1',$item->description);
            
$tmp_desc trim(preg_replace('#(<[^>]+>|http://\S+|www\.\S+\.\S{2,3}\S+)#','',$tmp_desc));

    




    echo 
"<ul>";
print 
'<div id="all">';
    foreach(
$xml->channel->item as $item) {
    echo 
"<li>";
    
$linkarray explode("=",$item->link);
print 
'<div id="videotitle">';
    echo 
"<a href='".$item->link."' title=''>";
    echo 
"$item->title";
    echo 
"</br>";
    echo 
"</br>";
$desclimit = ($desclimit != && $desclimit $desclimit +$desclimit); // Sanity check
print '<div id="videotumbnail">';
    echo 
"<img src=\"http://s2.ytimg.com/vi/".$linkarray[1]."/default.jpg\" title=\"$item->title.\" />";
    echo 
"</a>";
print 
'<div id="videodescription">';
    echo 
"<p>$item->description</p>";
$str .= "<p>". ((($desclimit != 0) && (strlen($tmp_desc) > $desclimit)) ? substr($tmp_desc,0,$desclimit-3)."..." $tmp_desc) ."</p>";
$str .= $imgsrc;
    if (
$limit != && $i == $limit)
        break;
    
    echo 
"</li>";
    
$limiter++;

// here you can change the 10 to the limit
//you want!
if (isset($_POST['defualt'])) {
    if (
$limiter == 10) break;
  }

if (isset(
$_POST['subfive'])) {
if (
$limiter == 5) break;
} else {
if (isset(
$_POST['subten'])) {
if (
$limiter == 2) break;
}
}



   
    }

    echo 
"</ul>";
print 
"</div>";
print 
"</div>";
print 
"</div>";
print 
"</div>";

    
?>


<b><center>Youtube RSS Grabber 0.1 BETA - By Codefreek</center></b>

</br>
<center><b>NEWS</b>
<ol>
</br>
<p>now you get The video Title when you hover over a tumbnail.
more small changes will be made.</p></ol></center>

</br>

<center><a href="http://www.td4l.org"><p>This site is hosted by: Td4l.org</p></a></center>

<?php
echo "<form action='youtube_rss_grabber.php' name='rss' method='post'>
<input type='submit' name='subten' value='subten'> 
<input type='submit' name='subfive' value='subfive'> 
<input type='submit' name='defualt' value='defualt'> 
</form>"
;
?>

the script is also available on PasteBin.be

delayedinsanity 07-13-2008 11:52 PM

What's going wrong?
-m

delayedinsanity 07-14-2008 12:51 AM

Still not sure what the specific problem is, whether it's a php problem, whether it's the way things are being displayed... but you have a lot of typo's in there that may be changing things from the way you expect to see them.

In your css, for #videotitle, #all, #videodescription and .p the 'height' attribute is missing the letter e.
-m

codefreek 07-14-2008 01:00 AM

you see that i get 2 thumbnails :S
that is one of the problems.

and then the limit of description text is not working :S

ps, i fixed
the height typo..

delayedinsanity 07-14-2008 02:26 AM

Where is the $item object being created? It's not included in your source up there, so when I run the script locally I get a bunch of undefined errors.
-m

codefreek 07-14-2008 02:36 AM

foreach($xml->channel->item as $item) {
$location = "http://youtube.com/rss/global/top_rated.rss";
$contents = file_get_contents($location);
$xml = new SimpleXMLElement($contents);

delayedinsanity 07-14-2008 03:56 AM

I stripped a lot of your formatting out to debug this, and this is what I came up with that works just fine (without styles):

PHP Code:

<?php

$contents 
file_get_contents('http://youtube.com/rss/global/top_rated.rss');
$xml      = new SimpleXMLElement($contents);

$rss_count 0;

$desclimit 225// use 0 for no limit

foreach ($xml->channel->item as $item)
{
    
$img preg_replace('/^.*?(<img [^>]+>).*$/is','\1',$item->description); // Uncomment if you need full <img /> tag
    
$imgsrc preg_replace('/^.*?(<img [^>]*?src="([^"]+)"[^>]*>).*$/is','\2',$item->description);
    
$tmp_desc preg_replace('#.*?(<p>.+?</p>).*#is','\1',$item->description);
    
$tmp_desc trim(preg_replace('#(<[^>]+>|http://\S+|www\.\S+\.\S{2,3}\S+)#','',$tmp_desc));

    
$linkarray explode("=",$item->link);

    echo 
'<a href="',$item->link,'"><img src="http://s2.ytimg.com/vi/',$linkarray[1],'/default.jpg" title="$item->title." style="float: left;" /></a>';
    echo 
'<h2><a href="',$item->link,'">',$item->title,'</a></h2>';

    echo 
'<p style="clear: both;">'.((($desclimit != 0) && (strlen($tmp_desc) > $desclimit)) ? substr($tmp_desc,0,$desclimit-3)."..." $tmp_desc).'</p>';

    
$rss_count++;

    if (isset(
$_GET['limit']) && (int) $_GET['limit'] == $rss_count)
        break;

}

?>


<b><center>Youtube RSS Grabber 0.1 BETA - By Codefreek</center></b>

</br>
<center><b>NEWS</b>
<ol>
</br>
<p>now you get The video Title when you hover over a tumbnail.
more small changes will be made.</p></ol></center>

</br>

<center><a href="http://www.td4l.org"><p>This site is hosted by: Td4l.org</p></a></center>

<?php
echo '<form action="',$_SERVER['PHP_SELF'],'" name="rss" method="get">';
echo 
'<input type="submit" name="subten" value="subten">';
echo 
'<input type="submit" name="subfive" value="subfive">';
echo 
'<input type="submit" name="defualt" value="defualt">';
echo 
'</form>';
?>

This is just a stripped down version of yours, not my own version. A few things I came across:
  • You had a few variables you weren't using. $limit and $i, which you do a check on further down, but nowhere do you increment these values or give them a reason to exist. They seemed sad, so I let them go home.
  • Your post if/else structure to determine the amount of results returned was a little convoluted. I switched it to a simple GET method so you only have to run one check.
  • Your string replacement routines (preg_replace) were trying to run on $item which doesn't exist outside of the foreach, so I moved them.
  • Your $desclimit reality check isn't really necessary, you should just add a comment in to the script if you want, that says something along the lines of "If you enter this amount any lower than 45 characters, the description returned will be too short to be readable"... or something.
  • Finally your description limiter wasn't working because you were echoing $item->description directly, and not $str which is where you were performing the truncate.

codefreek 07-14-2008 12:12 PM

delayedinsanity, thank you but you stripped out the functions to let only see the so many items you click for example u press 4 you only see top 4.

i will try fix it my way but thank you for the pointers.

delayedinsanity 07-14-2008 12:55 PM

I didn't strip out any functions, just orphaned variables and css.

Either way some of the points still stand... such as your description limit wasn't working because you never sent it to the screen.
-m

codefreek 07-14-2008 02:07 PM

why isn't this working.
PHP Code:

echo '<a href="',$item->link,'"><img src=\"http://s2.ytimg.com/vi/".$linkarray[1]."/default.jpg\" title=\"$item->title.\" /></a>'


Tanax 07-14-2008 02:17 PM

Well, you're using "," instead of "." at the beginning with $item->link

codefreek 07-14-2008 02:21 PM

you can do that.

codefreek 07-14-2008 02:25 PM

i tryed this, but now the $item->title is not working :S
PHP Code:

echo '<a href="',$item->link,'"><img src="http://s2.ytimg.com/vi/',$linkarray[1],'/default.jpg" title=".$item->title." style="float: left;" /></a>'


codefreek 07-14-2008 02:30 PM

i fixed it now :D
just add "'..'"
PHP Code:

echo '<a href="',$item->link,'"><img src="http://s2.ytimg.com/vi/',$linkarray[1],'/default.jpg" title="'.$item->title.'" style="float: left;" /></a>'



All times are GMT. The time now is 02:38 AM.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0