PWA Code using SimpleXML

pwaplusphp_functions.php

#----------------------------------------------------------------------------
# Picasa Album Data
#
# xmlns='http://www.w3.org/2005/Atom' 
# xmlns:gphoto='http://schemas.google.com/photos/2007' 
# xmlns:media='http://search.yahoo.com/mrss/' 
# xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/
# Used in: Random.php
#----------------------------------------------------------------------------
function gdata_album($pwaplusphp_options) {
  $test=0;
  $file = ($pwaplusphp_options['SAVEFILE']) ? $pwaplusphp_options['SAVEFILE'] : $pwaplusphp_options['FILE'];
//  $file =$pwaplusphp_options['FILE'];

  $feed = simplexml_load_file($file);

  # OpenSearch
  $opensearch=$feed->children('http://a9.com/-/spec/opensearchrss/1.0/');
  $total_albums = trim($opensearch->totalResults);

  # Atom
  $children=$feed->children('http://www.w3.org/2005/Atom');
  for ($i=0; $i < $total_albums; $i++) {

    $album[$i]['id'] = trim($childern->entry[$i]->id);
    $album[$i]['published'] = trim($childern->entry[$i]->published);
    $album[$i]['updated'] = trim($childern->entry[$i]->updated);
    $album[$i]['title'] = trim($childern->entry[$i]->title);
    $album[$i]['summary'] = trim($childern->entry[$i]->summary);
    $album[$i]['rights'] = trim($childern->entry[$i]->rights);
//    $album[$i]['link'] = trim($childern->entry[$i]->link->attributes()->href);

    # Gphoto
    $gphoto = $feed->children('http://www.w3.org/2005/Atom')
      ->entry[$i]
      ->children('http://schemas.google.com/photos/2007');
    $album[$i]['gphoto:name'] = trim($gphoto->name);
    $album[$i]['gphoto:location'] = trim($gphoto->location);
    $album[$i]['gphoto:access'] = trim($gphoto->access);
    $album[$i]['gphoto:timestamp'] = trim($gphoto->timestamp);
    $album[$i]['gphoto:numphotos'] = trim($gphoto->numphotos);

    # Media:Group
    $media = $feed->children('http://www.w3.org/2005/Atom')
      ->entry[$i]
      ->children('http://search.yahoo.com/mrss/')
      ->group
      ->children('http://search.yahoo.com/mrss/');
    $album[$i]['media:description'] = trim($media->description);
    $album[$i]['media:thumbnail'] = trim($media->thumbnail->attributes()->url);
    $album[$i]['media:title'] = trim($media->title);
  }

  # Test Output
  if ($test==1) {
    for ($i=0; $i <= $total_albums; $i++) {
      echo $album[$i]['id'] . '<BR>';
      echo $album[$i]['published'] . '<BR>';
      echo $album[$i]['updated'] . '<BR>';
      echo $album[$i]['title'] . '<BR>';
      echo $album[$i]['summary'] . '<BR>';
      echo $album[$i]['rights'] . '<BR>';
      echo $album[$i]['link'] . '<BR>';
      echo $album[$i]['gphoto:name'] . '<BR>';
      echo $album[$i]['gphoto:location'] . '<BR>';
      echo $album[$i]['gphoto:access'] . '<BR>';
      echo $album[$i]['gphoto:timestamp'] . '<BR>';
      echo $album[$i]['gphoto:numphotos'] . '<BR>';
      echo $album[$i]['media:description'] . '<BR>';
      echo $album[$i]['media:thumbnail'] . '<BR>';
      echo $album[$i]['media:title'] . '<BR><BR>';
      echo '<HR>';
    }
  }
  return $album;
}

#----------------------------------------------------------------------------
# Picasa Photo Data
#
# xmlns='http://www.w3.org/2005/Atom' 
# xmlns:gphoto='http://schemas.google.com/photos/2007' 
# xmlns:media='http://search.yahoo.com/mrss/' 
# xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/
# xmlns:exif="http://schemas.google.com/photos/exif/2007"
# Used in: Random.php
#----------------------------------------------------------------------------
function gdata_photo($pwaplusphp_options) {
  $test=0;
  $file = ($pwaplusphp_options['SAVEFILE']) ? $pwaplusphp_options['SAVEFILE'] : $pwaplusphp_options['FILE'];
//  $file =$pwaplusphp_options['FILE'];

  $feed = simplexml_load_file($file);

  # OpenSearch
  $opensearch=$feed->children('http://a9.com/-/spec/opensearchrss/1.0/');
  $total_photos = trim($opensearch->totalResults);
  if (($pwaplusphp_options['IMAGES_ON_FRONT'] != 0 ) && 
    ($pwaplusphp_options['IMAGES_ON_FRONT'] < $total_photos) &&
    (is_home() || is_author() || is_archive())) {
    $total_photos =  $pwaplusphp_options['IMAGES_ON_FRONT'];
  }

  # Atom
  $children=$feed->children('http://www.w3.org/2005/Atom');
  $gphoto = $feed->children('http://schemas.google.com/photos/2007');
  $albumid= trim($gphoto->id);
  for ($i=0; $i < $total_photos; $i++) {

    $photos[$i]['id'] = $albumid;
    $photos[$i]['published'] = trim($children->entry[$i]->published);
    $photos[$i]['updated'] = trim($children->entry[$i]->updated);
    $photos[$i]['title'] = trim($feed->title);
    $photos[$i]['summary'] = trim($children->entry[$i]->summary);
    $photos[$i]['rights'] = trim($feed->rights);
    $photos[$i]['link'] = trim($feed->link->attributes()->href);

    # Gphoto
    $gphoto = $feed->children('http://www.w3.org/2005/Atom')
      ->entry[$i]
      ->children('http://schemas.google.com/photos/2007');
    $photos[$i]['gphoto:id'] = trim($gphoto->id);
    $photos[$i]['gphoto:name'] = trim($gphoto->name);
    $photos[$i]['gphoto:location'] = trim($gphoto->location);
    $photos[$i]['gphoto:access'] = trim($gphoto->access);
    $photos[$i]['gphoto:timestamp'] = trim($gphoto->timestamp);
    $photos[$i]['gphoto:numphotos'] = trim($gphoto->numphotos);
    $photos[$i]['gphoto:commentcount'] = trim($gphoto->commentCount);

    # Media:Group
    $media = $feed->children('http://www.w3.org/2005/Atom')
      ->entry[$i]
      ->children('http://search.yahoo.com/mrss/')
      ->group
      ->children('http://search.yahoo.com/mrss/');
    $photos[$i]['media:content'] = trim($media->content->attributes()->url);
    $photos[$i]['media:description'] = trim($media->description);

    $tnht = trim($media->thumbnail->attributes()->height);
    $tnwd = trim($media->thumbnail->attributes()->width);
    // Temporary? fix for 26/May gdata api bug
    if (($tnht == $pwaplusphp_options['GALLERY_THUMBSIZE']) ||
      ($tnwd == $pwaplusphp_options['GALLERY_THUMBSIZE'])) {
      $photos[$i]['media:thumbnail'] = trim($media->thumbnail->attributes()->url);
    }
    //$photos[$i]['media:thumbnail'] = trim($media->thumbnail->attributes()->url);
    $photos[$i]['media:title'] = trim($media->title);

    # Exif:Tags
    $exif = $feed->children('http://www.w3.org/2005/Atom')
      ->entry[$i]
      ->children('http://schemas.google.com/photos/exif/2007')
      ->tags
      ->children('http://schemas.google.com/photos/exif/2007');
    $photos[$i]['exif:fstop'] = trim($exif->fstop);
    $photos[$i]['exif:make'] = trim($exif->make);
    $photos[$i]['exif:model'] = trim($exif->model);
    $photos[$i]['exif:distance'] = trim($exif->distance);
    $photos[$i]['exif:exposure'] = trim($exif->exposure);
    $photos[$i]['exif:flash'] = trim($exif->flash);
    $photos[$i]['exif:focallength'] = trim($exif->focallength);
    $photos[$i]['exif:iso'] = trim($exif->iso);
    $photos[$i]['exif:time'] = trim($exif->time);
  }

  # Test Output
  if ($test==1) {
    for ($i=0; $i < $total_photos; $i++) {
      echo 'ID: '. $photos[$i]['id'] .'<BR>';
      echo 'Published: '. $photos[$i]['published'] .'<BR>';
      echo 'Updated: '. $photos[$i]['updated'] .'<BR>';
      echo 'Title: '. $photos[$i]['title'] .'<BR>';
      echo 'Summary: '. $photos[$i]['summary'] .'<BR>';
      echo 'Rights: '. $photos[$i]['rights'] . '<BR>';
      echo 'Link: '. $photos[$i]['link'] . '<BR>';
      echo 'GID: '. $photos[$i]['gphoto:id'] . '<BR>';
      //echo 'GName: '. $photos[$i]['gphoto:name'] . '<BR>';
      //echo 'Glocation: '. $photos[$i]['gphoto:location'] . '<BR>';
      echo 'Gaccess: '. $photos[$i]['gphoto:access'] . '<BR>';
      echo 'Gtimestamp: '. $photos[$i]['gphoto:timestamp'] . '<BR>';
      //echo 'Gnumphotos: '. $photos[$i]['gphoto:numphotos'] . '<BR>';
      echo 'GCommentcount: '. $photos[$i]['gphoto:commentcount'] . '<BR>';
      echo 'MContent: '. $photos[$i]['media:content'] . '<BR>';
      echo 'MDesc: '. $photos[$i]['media:description'] . '<BR>';
      echo 'MThumb: '. $photos[$i]['media:thumbnail'] . '<BR>';
      echo 'MTitle: '. $photos[$i]['media:title'] . '<BR>';
      echo 'Exfstop: '. $photos[$i]['exif:fstop'] . '<BR>';
      echo 'ExMake: '. $photos[$i]['exif:make'] . '<BR>';
      echo 'ExModel: '. $photos[$i]['exif:model'] . '<BR>';
      echo 'ExDist: '. $photos[$i]['exif:distance'] . '<BR>';
      echo 'ExExpos: '. $photos[$i]['exif:exposure'] . '<BR>';
      echo 'ExFlash: '. $photos[$i]['exif:flash'] . '<BR>';
      echo 'ExFocal: '. $photos[$i]['exif:focallength'] . '<BR>';
      echo 'ExIso: '. $photos[$i]['exif:iso'] . '<BR>';
      echo 'ExTime: '. $photos[$i]['exif:time'] . '<BR>';
      echo '<HR>';
    }
  }
  return $photos;
}

#----------------------------------------------------------------------------
# Picasa Photo Comment Data
#
# xmlns='http://www.w3.org/2005/Atom' 
# xmlns:gphoto='http://schemas.google.com/photos/2007' 
# xmlns:media='http://search.yahoo.com/mrss/' 
# xmlns:exif="http://schemas.google.com/photos/exif/2007"
# Used in: Random.php
#----------------------------------------------------------------------------
function gdata_comments($file) {
  $test=1;
  $feed = simplexml_load_file($file);
print_r($feed);


  for ($i=0; $i <= 1; $i++) {
    //the comment
    $comment[$i]['comment'] = trim($feed->entry[$i]->content);
      echo 'Comment: '. $comment[$i]['comment'] . '<BR>';
    //the nickname
    $gphoto = $feed->children('http://www.w3.org/2005/Atom')
      ->entry[$i]
      ->children('http://schemas.google.com/photos/2007');
    $comment[$i]['nickname'] = trim($gphoto->nickname);

    //the image
    $commenturl = trim($children->entry[$i]->id);
    list($imageurl,$junk) = split("/commentid",$commenturl);
    $image_feed_url = $imageurl . "?imgmax=32";
    $new_feed = simplexml_load_file($image_feed_url);

    $media = $new_feed->children('http://search.yahoo.com/mrss/')
      ->group
      ->children('http://search.yahoo.com/mrss/');
    $comment[$i]['thepic'] = trim($media->content->attributes()->url);
    $big_size_code = "s" . get_option("pwaplusphp_image_size");
    $comment[$i]['pic_big_img'] = str_replace("s32-c",$big_size_code,$comment[$i]['thepic']);
  }

  # Test Output
  if ($test==1) {
    for ($i=0; $i < $total_photos; $i++) {
      echo 'Comment: '. $comment[$i]['comment'] . '<BR>';
      echo 'nickname: '. $comment[$i]['nickname'] . '<BR>';
      echo 'thepic: '. $comment[$i]['thepic'] . '<BR>';
      echo 'thepic: '. $comment[$i]['pic_big_img'] . '<BR>';
      echo '<HR>';
    }
  }
  return $comment;
}

dumpAlbumList.php

#----------------------------------------------------------------------------
# Create the output
#----------------------------------------------------------------------------
  $albums = gdata_album($pwaplusphp_options);
  $total_albums	= count($albums);
  for ($i=1; $i <= $total_albums; $i++) {
loop
  }

showAlbumContents.php

...
#----------------------------------------------------------------------------
# Output Photos
#----------------------------------------------------------------------------
  $photos = gdata_photo($pwaplusphp_options);
  $total_photos = count($photos);

  for ($i=0; $i < $total_photos; $i++) {
loop
  }

Leave a Reply

Your email address will not be published. Required fields are marked *