示例#1
0
 /**
  * Check the consistency of an album feed request for specifically-sized images
  */
 public function testImgAlbumQuery()
 {
     $queryString = "https://picasaweb.google.com/data/feed/api/user/sample.user/albumid/1?imgmax=800";
     $query = new Zend_Gdata_Photos_AlbumQuery();
     $query->setUser("sample.user");
     $query->setAlbumId("1");
     $query->setImgMax("800");
     // Assert that the set ImgMax is correct
     $this->assertEquals("800", $query->getImgMax());
     $generatedString = $query->getQueryUrl();
     // Assert that the generated query matches the correct one
     $this->assertEquals($queryString, $generatedString);
     // Check that ImgMax is set back to null
     $queryString = "https://picasaweb.google.com/data/feed/api/user/sample.user/albumid/1";
     $query->setImgMax(null);
     $generatedString = $query->getQueryUrl();
     // Assert that the generated query matches the correct one
     $this->assertEquals($queryString, $generatedString);
 }
示例#2
0
function add_embpicasa_shortcode($atts, $content = null)
{
    extract(shortcode_atts(array("id" => ''), $atts));
    // do not display anything if there is no "id"
    if (empty($id)) {
        return '';
    }
    $options = get_option('embpicasa_options');
    // do not display anything in loop if "Show only on single post"
    if (!is_single() && $options['embpicasa_options_single_only'] == 'yes') {
        return '';
    }
    if (!empty($options['embpicasa_options_login']) && !empty($options['embpicasa_options_password'])) {
        try {
            set_include_path(implode(PATH_SEPARATOR, array(realpath(dirname(__FILE__) . '/library'), get_include_path())));
            require_once 'Zend/Loader.php';
            Zend_Loader::loadClass('Zend_Gdata');
            Zend_Loader::loadClass('Zend_Gdata_Query');
            Zend_Loader::loadClass('Zend_Gdata_ClientLogin');
            Zend_Loader::loadClass('Zend_Gdata_Photos');
            Zend_Loader::loadClass('Zend_Gdata_Photos_UserQuery');
            Zend_Loader::loadClass('Zend_Gdata_Photos_AlbumQuery');
            Zend_Loader::loadClass('Zend_Gdata_Photos_PhotoQuery');
            $client = Zend_Gdata_ClientLogin::getHttpClient($options['embpicasa_options_login'], $options['embpicasa_options_password'], Zend_Gdata_Photos::AUTH_SERVICE_NAME);
            $service = new Zend_Gdata_Photos($client);
            $photos = array();
            $query = new Zend_Gdata_Photos_AlbumQuery();
            $query->setAlbumId($id);
            // http://code.google.com/intl/ru/apis/picasaweb/docs/1.0/reference.html
            $thumb_suffix = $options['embpicasa_options_thumb_crop'] == 'no' ? 'u' : 'c';
            $full_suffix = $options['embpicasa_options_full_crop'] == 'no' ? 'u' : 'c';
            $query->setThumbsize($options['embpicasa_options_thumb_size'] . $thumb_suffix);
            $query->setImgMax($options['embpicasa_options_full_size'] . $full_suffix);
            $results = $service->getAlbumFeed($query);
            while ($results != null) {
                foreach ($results as $entry) {
                    foreach ($results as $photo) {
                        $photos[] = array('thumbnail' => $photo->mediaGroup->thumbnail[0]->url, 'fullsize' => $photo->mediaGroup->content[0]->url, 'title' => $photo->mediaGroup->description->text);
                    }
                }
                try {
                    $results = $results->getNextFeed();
                } catch (Exception $e) {
                    $results = null;
                }
            }
            $plugin_template = dirname(__FILE__) . '/loop-picasa.php';
            $theme_template = get_theme_root() . '/' . get_template() . '/loop-picasa.php';
            $template_path = file_exists($theme_template) ? $theme_template : $plugin_template;
            ob_start();
            include $template_path;
            $html = ob_get_contents();
            ob_end_clean();
            return $html;
        } catch (Exception $ex) {
            return '<p style="color:red">' . $ex->getMessage() . '</p>';
        }
    } else {
        return '';
        //empty login or password
    }
}