Jump to content

foucquet

Members
  • Posts

    48
  • Joined

  • Last visited

Profile Information

  • Gender
    Not Telling

foucquet's Achievements

Member

Member (2/5)

0

Reputation

  1. Thanks, that's so obvious now that I see it. I was busy playing around with str functions and getting nowhere...
  2. I am parsing an rss feed from my flickr photostream using this:- <?php $url = "http://api.flickr.com/services/feeds/photos_public.gne?id=49466419@N05&lang=en-us&format=rss_200"; $rss = simplexml_load_file($url); if($rss) { echo '<h1>'.$rss->channel->title.'</h1>'; echo '<li>'.$rss->channel->pubDate.'</li>'; $items = $rss->channel->item; foreach($items as $item) { $title = $item->title; $link = $item->link; $published_on = $item->pubDate; $description = $item->description; echo '<h3><a href="'.$link.'">'.$title.'</a></h3>'; echo '<span>('.$published_on.')</span>'; echo '<p>'.$description.'</p>'; } } ?> which gives me this as the description for each image:- public 'description' => string ' <p><a href="http://www.flickr.com/people/alfthomas/">Alf Thomas</a> posted a photo:</p> <p><a href="http://www.flickr.com/photos/alfthomas/14064465890/" title="harlaw_12"> <img src="http://farm6.staticflickr.com/5077/14064465890_83c02ecec6_m.jpg" width="240" height="110" alt="harlaw_12" /> </a> </p> <p>A view of Harlaw Reservoir.</p>' (length=338) What I actually want is the photo (linked back) without the "Alf Thomas posted a photo" bit, does anyone have any idea how I would go about cloning that bit out?
  3. Of course! What a dummy, Iknew a fresh pair of eyes would help - thanks.
  4. I am trying to put an rss feed from my Flickr account into my website I have got thus far with my class:- <?php // Flickr Class class flickr { // Properties var $feed; //=================== // Construct Flickr function __construct($feed) { $this->feed = $feed; } //=================== // Parse Method function parse() { $rss = simplexml_load_file($this->feed); $photodisp = array(); foreach ($rss->channel->item as $item) { $link = (string) $item->link; // Link to this photo $title = (string) $item->title; // Title of this photo $media = $item->children('http://search.yahoo.com/mrss/'); $thumb = $media->thumbnail->attributes(); $url = (string) $thumb['url']; // URL of the thumbnail $width = (string) $thumb['width']; // Width of the thumbnail $height = (string) $thumb['height']; // Height of the thumbnail $photodisp[] = <<<________________EOD {$title} ________________EOD; } return $photodisp; } //=================== // Display Method function display($numrows=6,$head="Photos on Flickr") { $photodisp = $this->parse(); $i = 0; $thumbs = <<<____________EOD $head ____________EOD; while ( $i < $numrows ) { $thumbs .= $photodisp[$i]; $i++; } $trim = str_replace('http://api.flickr.com/services/feeds/photos_public.gne?id=', '',$this->feed); $user = str_replace('〈=en-us&format=rss_200','',$trim); $thumbs .= <<<____________EOD View All Photos on Flickr ____________EOD; return $thumbs; } //=================== } //End of Class ?> // <- Line 66 and it gives me "Parse error: syntax error, unexpected end of file in C:\wamp\www\image-a-nation\test4_class.php on line 66". I thought it might be an unclosed brace/bracket or something like that, but no amount of checking finds anything - would appreciate a fresh pair of eyes...
  5. Hmm, didn't spot that one - definitely an autopilot typo... Thanks
  6. I am trying to iterate through an array of images and am having trouble with next/prev links. I thought that this should basically work as a starting point:- $images = array(); $img_loc = 'images/'; if ($handle = opendir($img_loc)) { while (false !== ($file = readdir($handle))) { if ($file != "." && $file != "..") { $images[] = $file; } } closedir($handle); } //>>> ==================================================================================== //>>> Block of code for Next/Prev links on images if (isset($_REQUEST['id'])) { $id = $_REQUEST['id']; } else { $id = 0; // Whatever the default starting value should be } $self = $_SERVER['PHP_SELF'] . "?$id="; $first = 0; // Because arrays are numbered from 0 $last = 7; $pic = $img_loc . $images[$id]; echo "<p><img src=\"$pic\"></p>"; if ($id < $last) { echo "<a href=".$self.($id + 1)."><h3>Next</h3></a>"; } if ($id > $first) { echo "<a href=".$self.($id - 1)."><h3>Previous</h3></a>"; } //=====================================================================================<<< //>>> ==================================================================================== //>>> Checking on what the variables are doing var_dump ($images); echo "File location = " . $pic . "<br>"; echo "First = " . $first . "<br>"; echo "Last = " . $last . "<br>"; echo "File id = " . $id . "<br>"; echo "Self = " . $self . "<br>"; echo "Server = " . $_SERVER['PHP_SELF'] . "<br>"; //=====================================================================================<<< and to an extent it does giving me:- IMAGE Next array (size = 8 ) 0 => string 'decisions.jpg' (length=13) 1 => string 'dual_concentration.jpg' (length=22) 2 => string 'generation_gap.jpg' (length=18) 3 => string 'just_looking.jpg' (length=16) 4 => string 'mid_stride.jpg' (length=14) 5 => string 'no7.jpg' (length=7) 6 => string 'plugged.jpg' (length=11) 7 => string 'runner.jpg' (length=10) File location = images/decisions.jpg First = 0 Last = 7 File id = 0 Self = /imageanation/next_prev_link_test.php?0= Server = /imageanation/next_prev_link_test.php However when I click next it changes the url from localhost/imageanation/next_prev_link_test.php to localhost/imageanation/next_prev_link_test.php?0=1 and reloads the same image. Hours of head scratching has not provided me with any solution, which I am sure will be quite simple if I could only see it.
  7. OK, OK, I'm a complete dummy - didn't even spot those errors, too busy looking for everything but the bleedin' obvious! That indeed now works (hides head in shame!)
  8. I am trying to bring a flickr feed into a webpage, and can't work out why this:- <?php // >>> Set up the variables needed <<< $photos = array(); $encode_params = array(); $maximgs = 19; // >>> This need to be 1 less than actual req'd No. as array counts from 0 <<< // >>> Set up the parameters for the API <<< $api_params = array( 'api_key' => 'my api key', 'method' => 'flickr.photos.search', 'user_id' => 'my id', 'format' => 'php_serial', ); //>>> Encode the parameters ready to make API request <<< foreach($api_params as $k => $v){ $encode_params[] = urlencode($k) . '=' . urlencode($v); } var_dump($encode_params); // >>> Construct API url and make the request <<< $api_url = 'http://api.flickr.com/services/rest/?' . implode('&', $encode_params); var_dump($api_url); // >>> Retrieve images <<< $rsp = file_get_contents($api_url); $rsp_obj = unserialize($rsp); echo $rsp_obj; var-dump($rsp_obj['photos']['photo']); //>>> Line 37 <<< ?> gives me "Parse error: syntax error, unexpected T_VAR in C:\wamp\www\php\flickr tests\prev3~.php on line 37".
  9. What a dummy! Didn't spot the underscore, so bleedin' obvious when pointed out. That works perfectly MMDE thanks.
  10. I am trying to pull images from my Flickr account with some success except that of accessing the description to be used as a caption for the image. What I have so far is:- <?php //>>> Define some variables $maximgs = 5; $images = array(); $params = array( 'api_key' => '***********************', 'method' => 'flickr.photos.search', 'user_id' => '****************', 'sort' => 'date-posted-desc', 'format' => 'php_serial', 'extras' => 'description', ); $encoded_params = array(); foreach ($params as $key => $value){ $encoded_params[] = urlencode($key) . '=' . urlencode($value); } //>>> Make request and decode the response $url = 'http://api.flickr.com/services/rest/?' . implode('&', $encoded_params); $response = file_get_contents($url); $response_object = unserialize($response); //var_dump($response_object['photos']['photo']); //>>> Why is this returning 100 results? if($response_object['stat'] !== 'ok'){ echo "Something went wrong!"; } //>>> Select the required number of images ($maximgs) for($loop = 0; $loop <= $maximgs; $loop++){ $images = $response_object['photos']['photo'][$loop]; var_dump($images); //>>> Url of the individual image location for the img src. $imgurl = 'http://farm'.$images['farm'].'.'.'static'.'.'.'flickr.com/'. $images['server'].'/'.$images['id'].'_'.$images['secret'].'_n.jpg'; //>>> Url of the individual image for the link. $flkrurl = 'http://www.flickr.com/photos/'.$images['owner'].'/'.$images['id'].'/'; /*The complete Url (<a href="link($flkrurl)"> <img alt="$images['title']" src="image location"($imgurl) width="required width of image" /> </a>) */ $compurl = '<a href="'.$flkrurl.'" target="_blank">'.'<img alt="'. $images['title'].'" src="'.$imgurl.'" width="320px" /></a>'; //>>> Display Images echo $compurl . '<br />' . $images['description']['content']; //<<<<<< Line 66 } ?> Which annoyingly throws this error:- Notice: Undefined index: content in C:\wamp\www\php\flickr_test1.php on line 66 The result of a var_dump():- array 'id' => string '6914498038' (length=10) 'owner' => string '************' (length=12) 'secret' => string '601a885f31' (length=10) 'server' => string '7137' (length=4) 'farm' => float 8 'title' => string 'newhaven_15' (length=11) 'ispublic' => int 1 'isfriend' => int 0 'isfamily' => int 0 'description' => array '_content' => string 'Great reflections found in Newhaven Harbour.' (length=44) with the info that I want to extract underlined. What I can't figure out is how to find out the name of the array below "description =>". I have been scratching my head for several hours now and am no nearer to working it out. Maybe a genius here will have the solution.
  11. Well, this is truly weird! Out of sheer desperation I deleted the oldest post, making the second oldest post the oldest, and it seems to have solved the problem, why I haven't a clue. All I can assume is that there is some sort of problem with the image attached to that particular post - requires some investigation. I can't think why I didn't do this in the first place to test if it was a problem with the particular post or a programming problem. The next step is to post the same image as the newest post and see if it throws the same error, if it does then I know it is the image, but if it doesn't then I will be even more puzzled that at present... Update:- Curiouser and curiouser, just posted the problem image as the newest post and it is behaving exactly how I would expect - WTF!"
  12. I had a quick look and everything seems to be right, I am beginning to suspect that it is because the versions of PHP are different, 5.3.4 on the laptop and 5.3.8 on the PC. Not even going to think about all ths for the next week or so, too busy with Xmas related stuff...
  13. If it helps any I inserted - var_dump($photo, $photos, $result, $imgurl); below $imgurl = $result; - and it returned the following:- $photos= object(stdClass)[301] public 'ID' => int 71 public 'post_author' => string '1' (length=1) public 'post_date' => string '2011-12-09 08:25:38' (length=19) public 'post_date_gmt' => string '2011-12-09 08:25:38' (length=19) public 'post_content' => string '' (length=0) public 'post_title' => string 'loch-linnhe-at-port-appin' (length=25) public 'post_excerpt' => string 'Loch Linnhe at Port Appin' (length=25) public 'post_status' => string 'inherit' (length=7) public 'comment_status' => string 'open' (length=4) public 'ping_status' => string 'open' (length=4) public 'post_password' => string '' (length=0) public 'post_name' => string 'loch-linnhe-at-port-appin' (length=25) public 'to_ping' => string '' (length=0) public 'pinged' => string '' (length=0) public 'post_modified' => string '2011-12-09 08:25:38' (length=19) public 'post_modified_gmt' => string '2011-12-09 08:25:38' (length=19) public 'post_content_filtered' => string '' (length=0) public 'post_parent' => int 78 public 'guid' => string 'http://localhost/wordpress/wp-content/uploads/2011/12/loch-linnhe-at-port-appin.jpg' (length=83) public 'menu_order' => int 0 public 'post_type' => string 'attachment' (length=10) public 'post_mime_type' => string 'image/jpeg' (length=10) public 'comment_count' => string '0' (length=1) public 'filter' => string 'raw' (length=3) $photo= array empty $result= string 'http://localhost/wordpress/wp-content/uploads/2011/12/loch-linnhe-at-port-appin.jpg' (length=83) $imgurl= string 'http://localhost/wordpress/wp-content/uploads/2011/12/loch-linnhe-at-port-appin.jpg' (length=83) However on hitting the last image the return was the following:- $photos= null $photos= array empty $result= null $imgurl= null everything empty.
  14. Aye, I use both echo and var_dump() when debugging, but neither of these tell me why this works on my laptop setup but not on the PC setup, surely if it works on one it should work on the other. I agree that this is the case with the PC, but it is not on my laptop, and I can't figure out why the PC set up is throwing this error. To make it just a little clearer, this works to pick up the exif data from each sucessive image, working Previous/Next, which is fine as long as I do not go back to the first (oldest) image; when it hits the oldest post it throws the error, at least on my PC setup. Surely if it works on one then it should, in theory, work on both :-\
  15. OK, I am developing a Wordpress theme, not getting much response fromt their support, so I thought I would ask here especially as is does not seem to be a pure Wordpress problem. Can anyone explain why this:- $size = "full"; $photos = get_children( array( 'post_parent' => $post->ID, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => 'ASC', 'orderby' => 'menu_order ID') ); if ($photos) { $photo = array_shift($photos); $result = wp_get_attachment_url($photo->ID, $size); } $imgurl = $result; $exif = exif_read_data($imgurl, 'EXIF'); //<<<<<< Line 67 $exifdata = array(); format_exif_data($exif); should work on my laptop, but give me a "Warning: exif_read_data() [function.exif-read-data]: Filename cannot be empty in C:\wamp\www\wordpress\wp-content\themes\image-a-nation\index.php on line 67" on my PC? I have the same version of WAMP installed on both, so this strikes me a just a little weird, and much head scratching over the weekend has not shed any light at all. Hopefully someone can save me from insanity...
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.