PageRenderTime 131ms CodeModel.GetById 33ms RepoModel.GetById 1ms app.codeStats 0ms

/albums.php

https://github.com/benrhughes/PicasaAlbums
PHP | 151 lines | 81 code | 25 blank | 45 comment | 10 complexity | 709db71cb13170b549ee39da40b265fa MD5 | raw file
  1. <?php
  2. /*------------------------------------------------------------------------------
  3. | Albums.php
  4. |
  5. | This script creates an 'index' page of albums from your PicasaWeb account.
  6. | It's useful when using PicasaViewer or PicasaBox.
  7. |
  8. | This script includes some very simple formatting, which you may like to
  9. | discard.
  10. |
  11. | XML parsing logic from
  12. | http://www.sitepoint.com/article/php-xml-parsing-rss-1-0
  13. |
  14. | For more info and updates see https://github.com/benrhughes/PicasaAlbums
  15. |
  16. | Created by Ben Hughes - benrhughes.com
  17. | 16 July 2007
  18. | Version 1.0
  19. ------------------------------------------------------------------------------*/
  20. /*------------------------------------------------------------------------------
  21. | INSTALLATION
  22. |
  23. | 1. Modify the user config section below
  24. | 2. Upload to your web host
  25. |
  26. | That's it!
  27. ------------------------------------------------------------------------------*/
  28. /*------------------------------------------------------------------------------
  29. | USER CONFIGURATION START
  30. ------------------------------------------------------------------------------*/
  31. $userid = "picasaviewer"; // Your Google user name
  32. $target = "PicasaBox.php/?album="; //URL to pass the name of the album to for the links
  33. /*------------------------------------------------------------------------------
  34. | USER CONFIGURATION END
  35. ------------------------------------------------------------------------------*/
  36. // *** Only modify past this point if you know what you're doing ***
  37. $insideentry = false;
  38. $tag = "";
  39. $title = "";
  40. $url = "";
  41. // function to parse the start of an XML element
  42. function startElement($parser, $name, $attrs) {
  43. global $insideentry, $tag, $title, $url;
  44. if ($insideentry) {
  45. $tag = $name;
  46. if ($name == "MEDIA:THUMBNAIL"){
  47. $url = $attrs["URL"];
  48. }
  49. } elseif ($name == "ENTRY") {
  50. $insideentry = true;
  51. }
  52. }
  53. // function to parse the end of an XML element
  54. function endElement($parser, $name) {
  55. global $insideentry, $tag, $title, $url, $albums;
  56. if ($name == "ENTRY") {
  57. $albums[] = array($title, $url);
  58. //echo $title . ' ' . $url;
  59. $title = "";
  60. $url = "";
  61. $insideentry = false;
  62. }
  63. }
  64. // function to parse the contents of an XML element
  65. function characterData($parser, $data) {
  66. global $insideentry, $tag, $title, $url;
  67. if ($insideentry) {
  68. if ($tag == "TITLE") {
  69. $title .= $data;
  70. }
  71. }
  72. }
  73. // Lets get started...
  74. // Create an XML parser, using the functions above
  75. $xml_parser = xml_parser_create();
  76. xml_set_element_handler($xml_parser, "startElement", "endElement");
  77. xml_set_character_data_handler($xml_parser, "characterData");
  78. // The URL of the album feed
  79. $feed = "http://picasaweb.google.com/data/feed/api/user/" . $userid . "?kind=album";
  80. // Open the feed
  81. $fp = fopen($feed,"r")
  82. or die("Error reading RSS data.");
  83. // Parse the feed
  84. while ($data = fread($fp, 4096))
  85. xml_parse($xml_parser, $data, feof($fp))
  86. or die(sprintf("XML error: %s at line %d",
  87. xml_error_string(xml_get_error_code($xml_parser)),
  88. xml_get_current_line_number($xml_parser)));
  89. // Close the feed
  90. fclose($fp);
  91. xml_parser_free($xml_parser);
  92. // Generate the HTML
  93. $htmlout = '<html>';
  94. $htmlout .= '<head>';
  95. $htmlout .= ' <title>' . $userid. '\'s albums</title>';
  96. $htmlout .= ' <style type="text/css">';
  97. $htmlout .= ' body{ color: #333; font: 13px "Lucida Grande", Verdana, sans-serif; }';
  98. $htmlout .= ' .Album { width: 625px; background: #f5f5f5; padding: 5px; float:center;}';
  99. $htmlout .= ' .AlbumHeader { text-align:center; padding-left:0px; }';
  100. $htmlout .= ' .AlbumHeader h3 { font: normal 24px Arial, Helvetica, sans-serif; text-align: center; }';
  101. $htmlout .= ' .AlbumHeader h4 { font: 16px Arial, Helvetica, sans-serif; color: #FF0084; color: #660033; text-align: center; }';
  102. $htmlout .= ' .AlbumPhoto { background: #f5f5f5; margin-bottom: 10px;}';
  103. $htmlout .= ' .AlbumPhoto p { float: center; font: Arial, Helvetica, sans-serif; padding: 0px; border: 0px; background: #fff; margin: 8px; text-align: center; }';
  104. $htmlout .= ' .AlbumPhoto span { float: left; padding: 4px 4px 12px 4px; border: 1px solid #ddd; background: #fff; margin: 8px; }';
  105. $htmlout .= ' .AlbumPhoto img { border: none; }';
  106. $htmlout .= '</style>';
  107. $htmlout .= '</head>';
  108. $htmlout .= '<body>';
  109. $htmlout .= '<div class="Album">';
  110. $htmlout .= ' <div class="AlbumHeader">';
  111. $htmlout .= ' <h3>Albums</h3>';
  112. $htmlout .= ' </div>';
  113. $htmlout .= ' <br clear=all>';
  114. $htmlout .= ' <div class="AlbumPhoto">';
  115. foreach($albums as $album)
  116. {
  117. $htmlout .= '<span><a href="'. $target . $album[0] . '"><img src="' . $album[1] . '" border=0></a><p>' . $album[0] . '</p></span>';
  118. }
  119. $htmlout .= ' </div>';
  120. $htmlout .= ' <br clear=all>';
  121. $htmlout .= '</div>';
  122. $htmlout .= '</body></html>';
  123. // Return the html
  124. print $htmlout;
  125. exit;
  126. ?>