TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 07-13-2008, 11:44 PM   #1 (permalink)
Super Moderator
Inquisitive 
 
codefreek's Avatar
 
Join Date: Sep 2007
Location: Near you.
Posts: 791
Thanks: 241
codefreek is on a distinguished road
Application Error 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
codefreek is offline  
Reply With Quote
Old 07-13-2008, 11:52 PM   #2 (permalink)
is cute and cuddly
 
delayedinsanity's Avatar
 
Join Date: Mar 2008
Location: Vegas, Baby
Posts: 963
Thanks: 31
delayedinsanity is on a distinguished road
Default

What's going wrong?
-m
delayedinsanity is offline  
Reply With Quote
Old 07-14-2008, 12:51 AM   #3 (permalink)
is cute and cuddly
 
delayedinsanity's Avatar
 
Join Date: Mar 2008
Location: Vegas, Baby
Posts: 963
Thanks: 31
delayedinsanity is on a distinguished road
Default

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
delayedinsanity is offline  
Reply With Quote
Old 07-14-2008, 01:00 AM   #4 (permalink)
Super Moderator
Inquisitive 
 
codefreek's Avatar
 
Join Date: Sep 2007
Location: Near you.
Posts: 791
Thanks: 241
codefreek is on a distinguished road
Default

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..
codefreek is offline  
Reply With Quote
Old 07-14-2008, 02:26 AM   #5 (permalink)
is cute and cuddly
 
delayedinsanity's Avatar
 
Join Date: Mar 2008
Location: Vegas, Baby
Posts: 963
Thanks: 31
delayedinsanity is on a distinguished road
Default

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
delayedinsanity is offline  
Reply With Quote
Old 07-14-2008, 02:36 AM   #6 (permalink)
Super Moderator
Inquisitive 
 
codefreek's Avatar
 
Join Date: Sep 2007
Location: Near you.
Posts: 791
Thanks: 241
codefreek is on a distinguished road
Default

foreach($xml->channel->item as $item) {
$location = "http://youtube.com/rss/global/top_rated.rss";
$contents = file_get_contents($location);
$xml = new SimpleXMLElement($contents);
codefreek is offline  
Reply With Quote
Old 07-14-2008, 03:56 AM   #7 (permalink)
is cute and cuddly
 
delayedinsanity's Avatar
 
Join Date: Mar 2008
Location: Vegas, Baby
Posts: 963
Thanks: 31
delayedinsanity is on a distinguished road
Default

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.
delayedinsanity is offline  
Reply With Quote
The Following User Says Thank You to delayedinsanity For This Useful Post:
codefreek (07-14-2008)
Old 07-14-2008, 12:12 PM   #8 (permalink)
Super Moderator
Inquisitive 
 
codefreek's Avatar
 
Join Date: Sep 2007
Location: Near you.
Posts: 791
Thanks: 241
codefreek is on a distinguished road
Default

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.
codefreek is offline  
Reply With Quote
Old 07-14-2008, 12:55 PM   #9 (permalink)
is cute and cuddly
 
delayedinsanity's Avatar
 
Join Date: Mar 2008
Location: Vegas, Baby
Posts: 963
Thanks: 31
delayedinsanity is on a distinguished road
Default

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
delayedinsanity is offline  
Reply With Quote
The Following User Says Thank You to delayedinsanity For This Useful Post:
codefreek (07-14-2008)
Old 07-14-2008, 02:07 PM   #10 (permalink)
Super Moderator
Inquisitive 
 
codefreek's Avatar
 
Join Date: Sep 2007
Location: Near you.
Posts: 791
Thanks: 241
codefreek is on a distinguished road
Default

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>'
codefreek is offline  
Reply With Quote
Old 07-14-2008, 02:17 PM   #11 (permalink)
The Prestige
Upcoming Programmer Inquisitive 
 
Tanax's Avatar
 
Join Date: Sep 2007
Location: Sweden, Stockholm
Posts: 1,080
Thanks: 115
Tanax is on a distinguished road
Default

Well, you're using "," instead of "." at the beginning with $item->link
__________________
Tanax is offline  
Reply With Quote
Old 07-14-2008, 02:21 PM   #12 (permalink)
Super Moderator
Inquisitive 
 
codefreek's Avatar
 
Join Date: Sep 2007
Location: Near you.
Posts: 791
Thanks: 241
codefreek is on a distinguished road
Default

you can do that.
codefreek is offline  
Reply With Quote
Old 07-14-2008, 02:25 PM   #13 (permalink)
Super Moderator
Inquisitive 
 
codefreek's Avatar
 
Join Date: Sep 2007
Location: Near you.
Posts: 791
Thanks: 241
codefreek is on a distinguished road
Default

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 is offline  
Reply With Quote
Old 07-14-2008, 02:30 PM   #14 (permalink)
Super Moderator
Inquisitive 
 
codefreek's Avatar
 
Join Date: Sep 2007
Location: Near you.
Posts: 791
Thanks: 241
codefreek is on a distinguished road
Default

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>'
codefreek is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT. The time now is 06:19 AM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design