function flickr_get_photoset()
{
    global $flickr_api_key, $flickr_token, $last_xml, $theme;
    #$photoset=0;
    # Make sure a photoset exists for this theme
    flickr_api("http://flickr.com/services/rest/", array("api_key" => $flickr_api_key, "method" => "flickr.photosets.getList", "auth_token" => $flickr_token));
    #echo nl2br(htmlspecialchars($last_xml));
    # List all photosets.
    $p = xml_parser_create();
    xml_parse_into_struct($p, $last_xml, $vals, $index);
    xml_parser_free($p);
    #echo "<pre>Index array\n";
    #print_r($index);
    #echo "\nVals array\n";
    #print_r($vals);
    $last_photoset_id = "";
    $photosets = array();
    for ($n = 0; $n < count($vals); $n++) {
        if (isset($vals[$n]["tag"]) && $vals[$n]["tag"] == "PHOTOSET" && isset($vals[$n]["attributes"]["ID"])) {
            # Read the photoset ID and set, ready for nested title tag later
            $last_photoset_id = $vals[$n]["attributes"]["ID"];
        }
        if (isset($vals[$n]["tag"]) && $vals[$n]["tag"] == "TITLE") {
            # Read the title and set
            $photosets[$vals[$n]["value"]] = $last_photoset_id;
        }
    }
    # $photosets now contains a list of all the user's photosets.
    # Look for the name of the current collection.
    $photoset_name = sql_value("select name value from collection where ref='{$theme}'", "");
    if (array_key_exists($photoset_name, $photosets)) {
        # Name already exists. Just use this photoset ID.
        $photoset = $photosets[$photoset_name];
    } else {
        # Name does not exist. Set to zero so it is created during sync.
        $photoset = 0;
    }
    $photoset_array = array($photoset_name, $photoset);
    return $photoset_array;
}
Example #2
0
		<form method="post" action="sync.php?theme=<?php 
        echo $theme;
        ?>
"><input type="submit" name="reload" value="<?php 
        echo $lang["reload"];
        ?>
"></form>
		<?php 
    }
}
if ($validtoken) {
    # Valid token... we have a valid token for this user so we're ready to publish.
    if (getval("publish_all", "") != "" || getval("publish_new", "") != "") {
        #$photoset=0;
        # Make sure a photoset exists for this theme
        flickr_api("http://flickr.com/services/rest/", array("api_key" => $flickr_api_key, "method" => "flickr.photosets.getList", "auth_token" => $flickr_token));
        #echo nl2br(htmlspecialchars($last_xml));
        # List all photosets.
        $p = xml_parser_create();
        xml_parse_into_struct($p, $last_xml, $vals, $index);
        xml_parser_free($p);
        #echo "<pre>Index array\n";
        #print_r($index);
        #echo "\nVals array\n";
        #print_r($vals);
        $last_photoset_id = "";
        $photosets = array();
        for ($n = 0; $n < count($vals); $n++) {
            if (isset($vals[$n]["tag"]) && $vals[$n]["tag"] == "PHOTOSET" && isset($vals[$n]["attributes"]["ID"])) {
                # Read the photoset ID and set, ready for nested title tag later
                $last_photoset_id = $vals[$n]["attributes"]["ID"];
function sync_flickr($search, $new_only = false, $photoset = 0, $photoset_name = "", $private = 0)
{
    # For the resources matching $search, synchronise with Flickr.
    global $flickr_api_key, $flickr_token, $flickr_caption_field, $flickr_keywords_field, $flickr_prefix_id_title, $lang;
    $results = do_search($search);
    foreach ($results as $result) {
        global $view_title_field;
        # Fetch some resource details.
        $title = i18n_get_translated($result["field" . $view_title_field]);
        $description = sql_value("select value from resource_data where resource_type_field={$flickr_caption_field} and resource='" . $result["ref"] . "'", "");
        $keywords = sql_value("select value from resource_data where resource_type_field={$flickr_keywords_field} and resource='" . $result["ref"] . "'", "");
        $photoid = sql_value("select flickr_photo_id value from resource where ref='" . $result["ref"] . "'", "");
        # Prefix ID to title?
        if ($flickr_prefix_id_title) {
            $title = $result["ref"] . ") " . $title;
        }
        if (!$new_only || $photoid == "") {
            echo "<li>" . $lang["processing"] . ": " . $title . "\n";
            $im = get_resource_path($result["ref"], true, "scr", false, "jpg");
            # If replacing, add the photo ID of the photo to replace.
            if ($photoid != "") {
                echo "<li>" . str_replace("%photoid", $photoid, $lang["updating_metadata_for_existing_photoid"]);
                # Also resubmit title, description and keywords.
                flickr_api("http://flickr.com/services/rest/", array("api_key" => $flickr_api_key, "method" => "flickr.photos.setTags", "auth_token" => $flickr_token, "photo_id" => $photoid, "tags" => $keywords));
                flickr_api("http://flickr.com/services/rest/", array("api_key" => $flickr_api_key, "method" => "flickr.photos.setMeta", "auth_token" => $flickr_token, "photo_id" => $photoid, "title" => $title, "description" => $description));
            }
            # New uploads only. Send the photo file.
            if ($photoid == "") {
                $url = "http://api.flickr.com/services/upload/";
                # Build paramater list for upload
                $data = array("photo" => "@" . $im, "api_key" => $flickr_api_key, "auth_token" => $flickr_token, "title" => $title, "description" => $description, "tags" => $keywords);
                # Add the signature by signing the data...
                $data["api_sig"] = flickr_sign($data, array("photo"), true);
                # Use CURL to upload the photo.
                $ch = curl_init();
                curl_setopt($ch, CURLOPT_URL, $url);
                curl_setopt($ch, CURLOPT_POST, 1);
                curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
                curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
                $photoid = flickr_get_response_tag(curl_exec($ch), "photoid");
                echo "<li>" . str_replace("%photoid", $photoid, $lang["photo-uploaded"]);
                # Update Flickr tag ID
                sql_query("update resource set flickr_photo_id='" . escape_check($photoid) . "' where ref='" . $result["ref"] . "'");
            }
            $created_new_photoset = false;
            if ($photoset == 0) {
                # Photoset must be created.
                flickr_api("http://flickr.com/services/rest/", array("api_key" => $flickr_api_key, "method" => "flickr.photosets.create", "auth_token" => $flickr_token, "title" => $photoset_name, "primary_photo_id" => $photoid), "", "POST");
                global $last_xml;
                #echo htmlspecialchars($last_xml);
                $pos_1 = strpos($last_xml, "id=\"");
                $pos_2 = strpos($last_xml, "\"", $pos_1 + 5);
                $photoset = substr($last_xml, $pos_1 + 4, $pos_2 - $pos_1 - 4);
                echo "<li>" . str_replace(array("%photoset_name", "%photoset"), array($photoset_name, $photoset), $lang["created-new-photoset"]);
                $created_new_photoset = true;
            }
            # Add to photoset
            if (!$created_new_photoset) {
                flickr_api("http://flickr.com/services/rest/", array("api_key" => $flickr_api_key, "method" => "flickr.photosets.addPhoto", "auth_token" => $flickr_token, "photoset_id" => $photoset, "photo_id" => $photoid));
                echo "<li>" . str_replace(array("%photoid", "%photoset"), array($photoid, $photoset), $lang["added-photo-to-photoset"]);
                #global $last_xml;echo nl2br(htmlspecialchars($last_xml));
            }
            # Set permissions
            echo "<li>" . str_replace("%permission", $private == 0 ? $lang["flickr_public"] : $lang["flickr_private"], $lang["setting-permissions"]);
            flickr_api("http://flickr.com/services/rest/", array("api_key" => $flickr_api_key, "method" => "flickr.photos.setPerms", "auth_token" => $flickr_token, "photo_id" => $photoid, "is_public" => $private == 0 ? 1 : 0, "is_friend" => 0, "is_family" => 0, "perm_comment" => 0, "perm_addmetadata" => 0), "", "POST");
        }
    }
    echo "<li>" . $lang["done"];
}