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

Jurgen Strydom http://www.flatspike.com

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

PHP Flickr! personal photo album

This code uses your Flickr! account and creates the URLs to the pictures for display on your own personal website! The full documentation is available at http://www.strydominc.za.net/index.php?p=projectdetail&d=phpflickrphoto

   1  
   2  <?php
   3  /**********************************************************************************************
   4  www.strydominc.za.net
   5  Created by Jurgen Strydom, 19-08-2006, jurgen.strydom@gmail.com
   6  Read the readme.txt
   7  Version 1.01, 19-08-2006
   8  **********************************************************************************************/
   9  ?>
  10  <link href="pagefloat.css" rel="stylesheet" type="text/css">
  11  <?php
  12  //Stuff you should update for your script
  13  $api_key = "6cacc91553b802874c6bbad658c9ce94"; // get yours at http://flickr.com/services/api/key.gne
  14  $my_id = "46772344@N00"; // use idgetr: http://idgettr.com/ to find yours if you already changed it to a name
  15  $rows = 10;
  16  //Let the code do the walking from here on
  17  $photos = ($rows * 2);
  18  if (empty($_REQUEST['n'])) {
  19  $pagenum = 1;
  20  } else {
  21  $pagenum = $_REQUEST['n'];
  22  }
  23  //http://static.flickr.com/{server-id}/{id}_{secret}_[mstb].jpg //how the url is created for the images
  24  $xml = simplexml_load_file("http://flickr.com/services/rest/?method=flickr.people.getPublicPhotos&user_id=$my_id&api_key=$api_key&per_page=$photos&page=$pagenum");
  25  $total = $xml->photos['total'];
  26  $pages = $total % $photos;
  27  $pages = ($total + $photos - $pages) / $photos;
  28  
  29  ?><table width="700" border="0" cellpadding="0" cellspacing="0">
  30  <tr><td height="10" colspan="2" valign="top" align="left">Please select a page: <?php
  31  for ($k = 1; $k<=$pages; $k++) { ?>
  32  <table width="25" border="0" cellpadding="0" cellspacing="0" align="center" class="pagefloat"> <?php
  33  ?>
  34    <tr>
  35      <td width="25" height="10" valign="top" align="center"><a href="photos.php?n=<?php echo $k?>">
  36  	<?php if ($k == $pagenum) {
  37  		 	echo "<u><b>", $k, "</b></u>";
  38  		 } else {
  39  		 	echo "<b>", $k, "</b>";
  40  		 } ?></a></td>
  41    </tr>
  42  </table>
  43  <?php } 
  44  ?>
  45  </td></tr>
  46  <tr>
  47      <td height="10" colspan="2" valign="top" align="left">&nbsp;</td>
  48  </tr>
  49  <?php
  50  
  51  if (($pagenum * $photos) > $total) {
  52  	$to = $total % $photos;
  53  } else { $to = $photos; }
  54  for ($k = 0; $k<$to; $k++) {
  55  if (($k % 2) == 0) {
  56  ?>
  57  <tr>
  58  <td width="350" height="100" valign="top" align="center">
  59  <?php } else {?>
  60  <td width="350" valign="top" align="center">
  61  <?php }
  62  echo "<b>" , $xml->photos->photo[$k]['title'], "</b>";
  63  ?>
  64  <br>
  65  <a href="http://www.flickr.com/photos/jurgenstrydom/<?php echo $xml->photos->photo[$k]['id'];?>"><img src="<?php 
  66  echo "http://static.flickr.com/";
  67  echo $xml->photos->photo[$k]['server'];
  68  echo "/";
  69  echo $xml->photos->photo[$k]['id'];
  70  echo "_";
  71  echo $xml->photos->photo[$k]['secret'];
  72  echo "_m.jpg"; 
  73  ?>"
  74  alt="<?php echo $xml->photos->photo[$k]['title'] ?>" border="0"></a>
  75  </td>
  76  <?php
  77  if (($k % 2) == 1) {
  78  ?> </tr>  <tr>
  79      <td height="10" colspan="2" valign="top" align="left">&nbsp;</td>
  80    </tr>  
  81    <?php
  82  }
  83  }
  84  ?>
  85  </table>
  86  <?php
  87  /**********************************************************************************************
  88  Changelog:
  89  
  90  Version 1.01
  91  Fixed a bug that caused code below this script to output incorrect display.
  92  
  93  Version 1
  94  First release.
  95  **********************************************************************************************/
  96  ?>

PHP last.fm chart creator

This code displays the Top 50 artists XML feed from last.fm in a nice presentable way on your website. Can easily be modified to work with any other feed from last.fm, find the full guide at http://www.strydominc.za.net/index.php?p=projectdetail&d=phplastfmchart

   1  
   2  <?php
   3  /**********************************************************************************************
   4  www.strydominc.za.net
   5  Created by Jurgen Strydom, 19-08-2006, jurgen.strydom@gmail.com
   6  Read the readme.txt
   7  Version 1.01, 05-09-2006
   8  **********************************************************************************************/
   9  ?>
  10  <link href="lastfmbar.css" rel="stylesheet" type="text/css">
  11  <div>
  12  <?php
  13  //User settings -> needs your attention
  14  $user = "Alkine"; //Your username
  15  $width = 700; //width of the list
  16  
  17  //Code you should not worry about
  18  $file = "http://ws.audioscrobbler.com/1.0/user/$user/topartists.xml";
  19  $xml = simplexml_load_file("$file");
  20  $big = $xml->artist[0]->playcount;
  21  $total = count($xml->artist);
  22  $factor =  $width /$big;
  23  ?>
  24  <table width="<?php echo $width ?>" border="0" cellpadding="0" cellspacing="0">  
  25   <?php
  26   for ($k=0 ; $k<=$total - 1; $k++) {
  27   	$barlen = round(($xml->artist[$k]->playcount * $factor), 0);
  28   ?>
  29    <tr>
  30      <td width="<?php echo $width ?>" height="10" valign="center"><table width="100%" border="0" cellpadding="0" cellspacing="0">
  31        <!--DWLayoutTable-->
  32        <tr>
  33          <td width="<?php echo $barlen ?>" height="10" valign="center" class="lastfmbar"><?php 
  34  		if ($barlen >= (($width + 100) /2)) {
  35  			echo "<div align=\"right\">", $xml->artist[$k]->playcount, " - <b>", $xml->artist[$k]->name ,"</b></div>";
  36  		}
  37  		if (($barlen < (($width + 100) /2)) && ($barlen >= ($width / 3))) {
  38  			echo "<div align=\"right\">", $xml->artist[$k]->playcount ," -</div>";
  39  		}
  40  		if ($barlen < ($width / 3)) {
  41  			echo "&nbsp;";
  42  		}		
  43  		?></td>
  44          <td width="<?php echo $width - $barlen ?>" valign="center"><?php 
  45  		if ($barlen >= (($width + 100) /2)) {
  46  			echo "&nbsp;";
  47  		}
  48  		if (($barlen < (($width + 100) /2)) && ($barlen >= ($width / 3))) {
  49  			echo "<div align=\"left\"><b>&nbsp;", $xml->artist[$k]->name ,"</b></div>";
  50  		}
  51  		if ($barlen < ($width / 3)) {
  52  			echo "<div align=\"left\">", $xml->artist[$k]->playcount, " - <b>", $xml->artist[$k]->name ,"</b></div>";
  53  		}		
  54  		?></td>
  55        </tr>
  56      </table></td>
  57    </tr>
  58    <?php
  59    }
  60    ?>
  61  </table>
  62  </div>
  63  <?php
  64  /**********************************************************************************************
  65  Changelog:
  66  
  67  Version 1.01
  68  Fixed a bug that caused the bar sizes to display incorrectly.
  69  
  70  Version 1
  71  First release.
  72  **********************************************************************************************/
  73  ?>
« Newer Snippets
Older Snippets »
Showing 1-2 of 2 total  RSS