public function filter_shortcode_flickr($code_to_replace, $code_name, $attr_array, $code_contents, $post) { $id = $attr_array['id']; $size = isset($attr_array['size']) ? '_' . $attr_array['size'] : Options::get('flickrsilo__flickr_size'); $info = "flickr{$id}"; $flickr = $post->info->{$info}; $f = new Flickr(array('user_id' => $post->author->id)); if (!$flickr) { // this photo's details aren't cached on this post. Let's grab 'em $xml = $f->photosGetInfo($id); if (!$xml->photo) { return $code_to_replace; } // get an array of the 'photo' element from the XML $p = (array) $xml->photo->attributes(); $flickr = $p['@attributes']; // stuff in the URL to the photopage $flickr['photopage'] = (string) $xml->photo->urls[0]->url[0]; // and if it's a video, we want its dimensions if ('video' == $flickr['media']) { if (0 == $xml->photo->video['ready']) { return $code_to_replace; } $flickr['height'] = (string) $xml->photo->video->attributes()->height; $flickr['width'] = (string) $xml->photo->video->attributes()->width; } // cache this array on this post $post->info->{$info} = $flickr; $post->update(); } if ('photo' == $flickr['media']) { $markup = '<a href="' . $flickr['photopage'] . '">'; $markup .= '<img src="'; $markup .= $f->getPhotoURL($flickr, $size); $markup .= '"'; if (isset($attr_array['class'])) { $markup .= ' class="' . $attr_array['class'] . '"'; } $markup .= '></a>'; } else { $photo_id = $flickr['id']; $secret = $flickr['secret']; $height = $flickr['height']; $width = $flickr['width']; $markup = <<<EOF <object type="application/x-shockwave-flash" width="{$width}" height="{$height}" data="//www.flickr.com/apps/video/stewart.swf?v=109786" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"> <param name="flashvars" value="intl_lang=en-us&photo_secret={$secret}&photo_id={$id}&flickr_show_info_box=true&hd_default=false"></param> <param name="movie" value="//www.flickr.com/apps/video/stewart.swf?v=109786"></param><param name="bgcolor" value="#000000"></param><param name="allowFullScreen" value="true"></param><embed type="application/x-shockwave-flash" src="//www.flickr.com/apps/video/stewart.swf?v=109786" bgcolor="#000000" allowfullscreen="true" flashvars="intl_lang=en-us&photo_secret={$secret}&photo_id={$id}&flickr_show_info_box=true&hd_default=false" height="{$height}" width="{$width}"></embed></object> EOF; } return $markup; }
/** * 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_contents() { $flickr = new Flickr(); $token = Options::get( 'flickr_token_' . User::identify()->id ); $result = $flickr->call( 'flickr.auth.checkToken', array( 'api_key' => $flickr->key, 'auth_token' => $token ) ); $photos = $flickr->GetPublicPhotos( $result->auth->user['nsid'], null, 5 ); foreach( $photos['photos'] as $photo ){ $url = $flickr->getPhotoURL( $photo ); echo '<img src="' . $url . '" width="150px" alt="' . ( isset( $photo['title'] ) ? $photo['title'] : _t('This photo has no title') ) . '">'; } }
/** * 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); }