/** * 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; }
/** * Método indicado desde JS como responsable de retornar el html, en este caso utiliza una API de flickr y saca un conjunto de fotos */ function ajax__album_flickr($tag, toba_ajax_respuesta $respuesta) { if (!extension_loaded('curl')) { $prefix = PHP_SHLIB_SUFFIX === 'dll' ? 'php_' : ''; @dl($prefix . 'curl.' . PHP_SHLIB_SUFFIX); if (!extension_loaded('curl')) { echo 'Se necesita instalar la extensión <strong>curl</strong> para acceder al API de Flickr'; return; } } require_once 'lib/flickr_api.php'; $secrets = array('api_key' => 'e5ec32dadfbc7f48fa476a1d62a5c251', 'api_secret' => '579da1ad011ef233'); $flickr = new Flickr($secrets); $photos = $flickr->photosSearch('', $tag); $html = ''; if ($photos && $photos['total'] > 0) { $i = 0; $modulo = 4; $html .= '<table>'; foreach ($photos['photos'] as $photo) { if ($i == 12) { break; } if ($i % $modulo == 0) { $html .= "<tr>\n"; } $url_chica = $flickr->getPhotoURL($photo, 's'); $url_full = 'http://flickr.com/photos/' . $photo['owner'] . '/' . $photo['id']; $html .= "<td><a title='Ver foto' href='{$url_full}' target='_blank'><img src='{$url_chica}' height=75 width=75/></a></td>"; $i++; if ($i % $modulo == 0) { $html .= "</tr>\n"; } } $html .= '</table>'; $html .= "<div style='text-align:center'><em>Mostrando " . $i . ' de ' . $photos['total'] . ' fotos...</em></div>'; } else { $html .= "No se encontraron fotos con el tag <strong>{$tag}</strong>."; } $respuesta->set($html); }