Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

About this user

http://lordrich.com

« Newer Snippets
Older Snippets »
Showing 1-2 of 2 total  RSS 

Random Flickr Photo

// description of your code here

<?php

    // Displays a single random photo from recent flickr photos with a given tag.
    // Original code stolen from many sources including http://www.thebishop.net/geodog/archives/2004/09/29/fun_hacking_with_flickr_making_a_homemade_flickr_tag_badge_with_magpierss.html and http://prwdot.org/archives/002468.html


    // USER CONFIGURATION SECTION

    // MagpieRSS Configuration
    // This is an example based on my system;
    // you will need to customize it for your system
    // and your preferences. You can remove it entirely
    // if you have done it elsewhere
    // refer to http://magpierss.sourceforge.net/
    require_once('/var/www/bradford/magpierss-0.61/rss_fetch.inc');
    error_reporting(E_ERROR);
    define(MAGPIE_CACHE_ON, true);
    define(MAGPIE_CACHE_DIR, '/var/www/bradford/magpie_cache');
    define(MAGPIE_CACHE_AGE, 300);
    define(MAGPIE_CACHE_FRESH_ONLY, false);
    define(MAGPIE_DETECT_ENCODING, true);
    define(MAGPIE_DEBUG, 0);
    define(MAGPIE_FETCH_TIME_OUT, 15);
    define(MAGPIE_USE_GZIP, true);    

    // flickr configuration
    // How many photos you want to display
    $num_photos = 2; // for some reason it doesn't like 1
    $tag = 'Bradford';
    // URL for the flickr feed you want to use
    $flickr_feed_url ='http://www.flickr.com/services/feeds/photos_public.gne?tags='.$tag.'&format=rss_200';
?>

<?php
    // Fetch the feed
    $flickr = fetch_rss( $flickr_feed_url );
    if ($flickr) {
        $flickr_title = $flickr->channel["title"];
        $flickr_link = $flickr->channel["link"];
?>

<!-- Display the title and link to the feed -->

<?php
    // Pick some random photos
        $random_photos = array_rand($flickr->items,$num_photos);
        foreach ( $random_photos as $random_photo ) {
            $description = explode("\n\n",$flickr->items[$random_photo]["description"]);
?>

    <!-- Display the given photo -->

	<?php echo ereg_replace('<img src=(.*) width=(.*)>', '<img src=\\1 width="150px"/>', $description[1]);
	  die();?> // ok we've got our first photo - lets exit

<?php
        }
      } else {
?>

<!-- Display an error message if things didn't work -->
<p>An error occurred in the MagpieRSS parser:</p>

<p><?php echo magpie_error(); ?></p>

<?php
    } 
?>

Random quotes

Called as quotes.php it will display a single random quote. Called as quotes.php?all=1 it will display all quotes in an unordered list. No database is required, and it should be fairly obvious how to add new quotes.

<?php
$quotes[] = "Boys like hugs too.";
$quotes[] = "Ooh! Train!";
$quotes[] = "La rue est a nous.";
$quotes[] = "The future is unwritten.";

if($all==1) {
        echo "<ul>";
        for($i=0; $i<=count($quotes)-1; $i++) {
                echo "<li>".$quotes[$i]."</li>";
        }
        echo "</ul>";
} else {
        srand ((double) microtime() * 1000000);
        $randomquote = rand(0,count($quotes)-1);
        echo $quotes[$randomquote];
}

?>

« Newer Snippets
Older Snippets »
Showing 1-2 of 2 total  RSS