BBcode for Flicker images

Rate this:
By Fulco (Contact - View My Woyano)
Published Wed 22 Aug 2007, 895 Views, 1 Comment

Here's my code for pulling a user's public flickr photos and generating BBCode for forums via the phpFlicker package.

Here's my folder structure...

  




I'm sure this isn't the best way to do it, but I want simple and quick.  This took about 30 minutes.

index.php

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Fulco Studios - Flicker Picker</title>
<link rel="shortcut icon" href="images/newicon.ico" />
<link rel="icon" href="images/newicon.ico" />
<script type="text/javascript" src="js/jquery-latest.js"></script>
<script type="text/javascript" src="js/thickbox.js"></script>
<link rel="stylesheet" href="css/thickbox.css" type="text/css" media="screen" />
<link rel="stylesheet" href="css/flick.css" type="text/css" media="screen" />
<?PHP
$api_key = "c933e0d66a6695d005d660392bc496f2";
require_once("phpFlickr/phpFlickr.php");
// Create new phpFlickr object
$f = new phpFlickr($api_key);
$i = 0;
echo "</head>";
if (!empty($_POST['username'])) {
    // Find the NSID of the username inputted via the formsss
    $person = $f->people_findByUsername($_POST['username']);
   
    // Get the friendly URL of the user's photos
    $photos_url = $f->urls_getUserPhotos($person['id']);
   
    // Get the user's most recent 50 public photos
    $photos = $f->people_getPublicPhotos($person['id'], NULL, $_POST['num_pics']);
   
   
    echo "<form id="code"method='post'>";
    echo "<h1>Please Select the photo's you would like to generate BBCode for ...</h1>";
    echo "<table class="images" >";
    echo "<tr>";
    // Loop through the photos and output the html
    foreach ((array)$photos['photo'] as $photo) {
        echo "<td class="image" >";
        echo "<a href="".$f->buildPhotoURL($photo, "Small")."?keepThis=true&TB_iframe=true&height=250&width=400" title="".$photo[title]."" class="thickbox">";
        echo "<img border='0' alt='$photo[title]' ".
            "src=" . $f->buildPhotoURL($photo, "Square") . ">";
        echo "</a>";
        echo "<br /></td>";
       
        echo "<td class="checks" >";
        echo "<input type=checkbox name=box[] value='".$f->buildPhotoURL($photo, "Small").",".$photos_url."".$photo[id]."'>";
        echo "</td>";
       
       
        $i++;
        // If it reaches the sixth photo, insert a line break
        if ($i % 6 == 0) {
            echo "</tr>";
            echo "<tr>";
        }
       
    }
    echo "</tr>";
    echo "</table>";
    echo "<br><div id="initial"><input class="submit" type='submit' value='Display BB-Code'></div>";
    echo "</form>";
} elseif(!empty($_POST['box'])) {
?>
<script type="text/javascript">
addLoadListener(selEct);

function selEct() {
var selector = document.getElementById("displaybb");
selector.select();
}

function addLoadListener(fn)
{
  if (typeof window.addEventListener != 'undefined')
  {
    window.addEventListener('load', fn, false);
  }
  else if (typeof document.addEventListener != 'undefined')
  {
    document.addEventListener('load', fn, false);
  }
  else if (typeof window.attachEvent != 'undefined')
  {
    window.attachEvent('onload', fn);
  }
  else
  {
    var oldfn = window.onload;
    if (typeof window.onload != 'function')
    {
      window.onload = fn;
    }
    else
    {
      window.onload = function()
      {
        oldfn();
        fn();
      };
    }
  }
}
</script>
<?PHP
echo "<body>";
echo "<br />";
echo "<h1>&nbsp;&nbsp;&nbsp;Just press Ctrl+C and then go paste in your post.</h1>";
echo "<textarea name="bbcode" wrap="off" id="displaybb">";
$box = $_POST['box'];

foreach ($box as $box_item) {
    $broke_box = explode(",",$box_item);
    echo "[url=".$broke_box[1]."][img]".$broke_box[0]."[/img][/url]rn";
}
echo "</textarea>";
} else {
?>
<body>
<h1>Enter your Flickr username to search for your photos...</h1>
<div id="initial">
<form method='post'>
    <input name='username'><br /><br />
    <h2>Number of Photos to retrieve?</h2>
      <select name="num_pics" size="1" id="num_pics" style="width:50px;" >
        <option value="6">6</option>
        <option value="12">12</option>
        <option value="18">18</option>
        <option value="24">24</option>
        <option value="36">36</option>
        <option value="48" selected="selected">48</option>
        <option value="54">54</option>
        <option value="60">60</option>
    </select><br /><br />
    <input type='submit' value='Display Photos'>
</form>
</div>
<?PHP
}
?>
<div id="footer">
Provided by <a href="http://www.fulcostudios.com" target="_blank">Fulco Studios</a> v0.3b<br /><br /><br /><a rel="license" href="http://creativecommons.org/licenses/by-nc-sa/3.0/us/">
<img alt="Creative Commons License" style="border-width:0" src="http://i.creativecommons.org/l/by-nc-sa/3.0/us/88x31.png" />
</a>
<br />
This work is licensed under a
<a rel="license" href="http://creativecommons.org/licenses/by-nc-sa/3.0/us/">Creative Commons Attribution-Noncommercial-Share Alike 3.0 United States License</a>.
</div>
</body>
</html>


I know it's not perfect, but it's a decent starting place for me.



This Item
Category: Knowledge, Snippets, Computers
Tags: code, php,flickr, images, bbcode
Share it
Link to this item:
Bookmark this item: RSS Feed

People who liked this item

    1 Comments

  1.  
    JV ~ 16 months ago
    0 votes thumbs up thumbs down
    Sweet!
    [ reply ]
    1.  
      22 votes thumbs up thumbs down
      This is my two cents...

         
      Hey you know AdGuy always gets the last word! ;)

    Please Login to Add Your Comment   ..or..  

    Replying to comment by