/** * Return directory contents for the silo path * * @param string $path The path to retrieve the contents of * @return array An array of MediaAssets describing the contents of the directory */ public function silo_dir( $path ) { $flickr = new Flickr(); $results = array(); $size = Options::get( 'flickrsilo__flickr_size' ); $section = strtok( $path, '/' ); switch ( $section ) { case 'attrib-sa': $xml = $flickr->photosSearch( array( 'user_id' => '', 'license' => '4,5', 'text'=>$_SESSION['flickrsearch'] ) ); foreach( $xml->photos->photo as $photo ) { $props = array(); foreach( $photo->attributes() as $name => $value ) { $props[$name] = (string)$value; } $props = array_merge( $props, self::element_props( $photo, "http://www.flickr.com/photos/{$photo['owner']}/{$photo['id']}", $size ) ); $results[] = new MediaAsset( self::SILO_NAME . '/photos/' . $photo['id'], false, $props ); } break; case 'search': $xml = $flickr->photosSearch( array( 'text'=>$_SESSION['flickrsearch'] ) ); foreach( $xml->photos->photo as $photo ) { $props = array(); foreach( $photo->attributes() as $name => $value ) { $props[$name] = (string)$value; } $props = array_merge( $props, self::element_props( $photo, "http://www.flickr.com/photos/{$_SESSION['nsid']}/{$photo['id']}", $size ) ); $results[] = new MediaAsset( self::SILO_NAME . '/photos/' . $photo['id'], false, $props ); } break; case 'photos': $xml = $flickr->photosSearch(); foreach( $xml->photos->photo as $photo ) { $props = array(); foreach( $photo->attributes() as $name => $value ) { $props[$name] = (string)$value; } $props = array_merge( $props, self::element_props( $photo, "http://www.flickr.com/photos/{$_SESSION['nsid']}/{$photo['id']}", $size ) ); $results[] = new MediaAsset( self::SILO_NAME . '/photos/' . $photo['id'], false, $props ); } break; case 'videos': $xml = $flickr->videoSearch(); foreach( $xml->photos->photo as $photo ) { $props = array(); foreach( $photo->attributes() as $name => $value ) { $props[$name] = (string)$value; } $props = array_merge( $props, self::element_props( $photo, "http://www.flickr.com/photos/{$_SESSION['nsid']}/{$photo['id']}", $size ) ); $props['filetype'] = 'flickrvideo'; $results[] = new MediaAsset( self::SILO_NAME . '/photos/' . $photo['id'], false, $props ); } break; case 'tags': $selected_tag = strtok('/'); if ( $selected_tag ) { $xml = $flickr->photosSearch( array( 'tags'=>$selected_tag ) ); foreach( $xml->photos->photo as $photo ) { $props = array(); foreach( $photo->attributes() as $name => $value ) { $props[$name] = (string)$value; } $props = array_merge( $props, self::element_props( $photo, "http://www.flickr.com/photos/{$_SESSION['nsid']}/{$photo['id']}", $size ) ); $results[] = new MediaAsset( self::SILO_NAME . '/photos/' . $photo['id'], false, $props ); } } else { $xml = $flickr->tagsGetListUser( $_SESSION['nsid'] ); foreach( $xml->who->tags->tag as $tag ) { $results[] = new MediaAsset( self::SILO_NAME . '/tags/' . (string)$tag, true, array( 'title' => (string)$tag ) ); } } break; case 'sets': $selected_set = strtok('/'); if ( $selected_set ) { $xml = $flickr->photosetsGetPhotos( $selected_set ); foreach( $xml->photoset->photo as $photo ) { $props = array(); foreach( $photo->attributes() as $name => $value ) { $props[$name] = (string)$value; } $props = array_merge( $props, self::element_props( $photo, "http://www.flickr.com/photos/{$_SESSION['nsid']}/{$photo['id']}", $size ) ); $results[] = new MediaAsset( self::SILO_NAME . '/photos/' . $photo['id'], false, $props ); } } else { $xml = $flickr->photosetsGetList( $_SESSION['nsid'] ); foreach( $xml->photosets->photoset as $set ) { $results[] = new MediaAsset( self::SILO_NAME . '/sets/' . (string)$set['id'], true, array( 'title' => (string)$set->title ) ); } } break; case '$search': $path = strtok( '/' ); $dosearch = Utils::slugify( $path ); $_SESSION['flickrsearch'] = $path; $section = $path; case '': if ( isset( $_SESSION['flickrsearch'] ) ) { $results[] = new MediaAsset( self::SILO_NAME . '/search', true, array( 'title' => _t( 'Search' ) ) ); $results[] = new MediaAsset( self::SILO_NAME . '/attrib-sa', true, array( 'title' => _t( 'Search CC' ) ) ); } $results[] = new MediaAsset( self::SILO_NAME . '/photos', true, array('title' => _t( 'Photos' ) ) ); $results[] = new MediaAsset( self::SILO_NAME . '/videos', true, array('title' => _t( 'Videos' ) ) ); $results[] = new MediaAsset( self::SILO_NAME . '/tags', true, array('title' => _t( 'Tags' ) ) ); $results[] = new MediaAsset( self::SILO_NAME . '/sets', true, array('title' => _t( 'Sets' ) ) ); break; } return $results; }