Пример #1
0
function writeVideoPost($post)
{
    $player = getPlayer($post);
    $caption = getCaption($post);
    return $player . $caption;
}
function buildTemplate5(&$stories)
{
    $s &= $stories;
    list($s_1, $s_2, $s_3, $s_4, $s_5, $s_6) = $stories;
    $s_1_image_url = getImageLink($s_1, 'large');
    $s_1_caption = getCaption($s_1);
    $s_2_image_url = getImageLink($s_2, 'small');
    $s_2_caption = getCaption($s_2);
    $s_3_image_url = getImageLink($s_3, 'small');
    $s_3_caption = getCaption($s_3);
    $s_4_image_url = getImageLink($s_4, 'large');
    $s_4_caption = getCaption($s_4);
    $s_5_image_url = getImageLink($s_5, 'small');
    $s_5_caption = getCaption($s_5);
    $s_6_image_url = getImageLink($s_6, 'small');
    $s_6_caption = getCaption($s_6);
    //$code = '<div id="featured_story" class="clearfix">';
    $code = '<div class="clearfix featured_story">';
    $code .= '<div id=story_1_image" class="thumb">' . $s_1_image_url . '</div>';
    $code .= '<div class="storyBlockWrap"><h1 id="story_1_title">' . getStoryLink($s_1) . '</h1>';
    $code .= '<p id="story_1_caption">' . $s_1_caption . '</p>';
    $code .= '<div class="related_story">';
    $code .= '<div id="story_2_image" class="slot">' . $s_2_image_url . '</div>';
    $code .= '<p id="story_2_title">' . getStoryLink($s_2) . '</p>';
    $code .= '</div>';
    $code .= '<div class="related_story">';
    $code .= '<div id="story_3_image" class="slot">' . $s_3_image_url . '</div>';
    $code .= '<p id="story_3_title">' . getStoryLink($s_3) . '</p>';
    $code .= '</div>';
    $code .= '</div><!-- end storyBlockWrap --></div><!-- end featured_story -->';
    //$code .= '<div id="featured_story" class="clearfix">';
    $code .= '<div class="clearfix featured_story">';
    $code .= '<div id=story_4_image" class="thumb">' . $s_4_image_url . '</div>';
    $code .= '<div class="storyBlockWrap"><h1 id="story_4_title">' . getStoryLink($s_4) . '</h1>';
    $code .= '<p id="story_4_caption">' . $s_4_caption . '</p>';
    $code .= '<div class="related_story">';
    $code .= '<div id="story_5_image" class="slot">' . $s_5_image_url . '</div>';
    $code .= '<p id="story_5_title">' . getStoryLink($s_5) . '</p>';
    $code .= '</div>';
    $code .= '<div class="related_story">';
    $code .= '<div id="story_6_image" class="slot">' . $s_6_image_url . '</div>';
    $code .= '<p id="story_6_title">' . getStoryLink($s_6) . '</p>';
    $code .= '</div>';
    $code .= '</div><!-- end storyBlockWrap --></div><!-- end featured_story -->';
    /*
    $code = '<div id="featured-story">';
    $code .= '<div id="story-1-image" style="margin: 0 10px 0 0; float: left">'.$s_1_image_url.'</div>';
    $code .= '<div class="story-content"><p id="story-1-title">'.getStoryLink($s_1).'</p>';
    $code .= '<p id="story-1-caption">'.$s_1_caption.'</p>';
    $code .= '<div id="story-2-image" class="slot" style="width: 40px; height: 30px; float: left; margin: 0 10px 0 0;">'.$s_2_image_url.'</div>';
    $code .= '<p id="story-2-title">'.getStoryLink($s_2).'</p>';
    $code .= '<div id="story-3-image" class="slot" style="width: 40px; height: 30px; float: left; margin: 0 10px 0 0;">'.$s_3_image_url.'</div>';
    $code .= '<p id="story-3-title">'.getStoryLink($s_3).'</p>';
    $code .= '</div>';
    $code .= '<div class="spacer" style="clear: both;">';
    $code .= '</div>';
    $code .= '<div id="story-4-image" style="margin: 0 40px 0 0; float: left">'.$s_4_image_url.'</div>';
    $code .= '<div class="story-content"><p id="story-4-title">'.getStoryLink($s_4).'</p>';
    $code .= '<p id="story-4-caption">'.$s_4_caption.'</p>';
    $code .= '<div id="story-5-image" class="slot" style="width: 40px; height: 30px; float: left; margin: 0 10px 0 0;">'.$s_5_image_url.'</div>';
    $code .= '<p id="story-5-title">'.getStoryLink($s_5).'</p>';
    $code .= '<div id="story-6-image" class="slot" style="width: 40px; height: 30px; float: left; margin: 0 10px 0 0;">'.$s_6_image_url.'</div>';
    $code .= '<p id="story-6-title">'.getStoryLink($s_6).'</p>';
    $code .= '</div>';
    $code .= '</div>';
    */
    return $code;
}
function uploadImages($images, $imageAlbums)
{
    global $fbo, $key, $uid, $batchSize, $nohash;
    $albumImages = getAlbumImages($imageAlbums);
    $c = count($images);
    $a = 0;
    $b = 0;
    $md5s = array();
    // Loop through all the images. Skip by batch size.
    for ($a = 0; $a < $c; $a += $batchSize) {
        $imagesToUpload = array();
        // empty the array for images to upload.
        // For for the batch size while $b is less than the batch size OR a + b is less than the total number of images.
        for ($b = 0; $b < $batchSize && $a + $b < $c; $b++) {
            $z = $a + $b;
            // Get the "real" image index number.
            $image = $images[$z];
            // Pull out the image to manipulate
            $caption = getCaption($image);
            // Get the caption of the image
            $md5 = md5_file($image);
            // Get the MD5 of the image.
            // Check for duplicate images.
            if (array_key_exists("md5", $albumImages) && array_search($md5, $albumImages["md5"]) !== false) {
                disp("Skipping: {$image} already uploaded (MD5 Check)", 3);
                continue;
            }
            // Check for duplicate images in the queue.
            if (array_search($md5, $md5s) !== false) {
                disp("Skipping: Identical image to {$image} already queued (MD5 Check)", 3);
                continue;
            }
            $md5s[] = $md5;
            list($process, $thumb) = makeThumbBatch($image);
            $temp["image"] = $image;
            $temp["caption"] = $caption;
            $temp["process"] = $process;
            $temp["thumb"] = $thumb;
            $temp["caption"] = $caption . ($nohash ? "" : "\n\n\n" . $md5);
            $temp["uploaded"] = false;
            $temp["errors"] = 0;
            $imagesToUpload[] = $temp;
        }
        while (1) {
            $j = 0;
            for ($i = 0; $i < count($imagesToUpload); $i++) {
                if ($imagesToUpload[$i]["uploaded"]) {
                    continue;
                }
                disp("Waiting for processing to finish on: " . $imagesToUpload[$i]["image"], 5);
                // If the process continues to fail, just mark as uploaded and move on.
                if (waitToProcess($imagesToUpload[$i]["process"])) {
                    disp("Image Conversion Failed, skipping: " . $imagesToUpload[$i]["image"], 2);
                    $imagesToUpload[$i]["uploaded"] = true;
                    continue;
                }
                disp("Finished Processing.", 5);
                try {
                    $fbo->api_client->photos_upload($imagesToUpload[$i]["thumb"], getUploadAID($imageAlbums, $uploadAlbumIdx), $imagesToUpload[$i]["caption"], $uid);
                    $imageAlbums["size"][$uploadAlbumIdx]++;
                    $imagesToUpload[$i]["uploaded"] = true;
                    disp("Uploaded: " . $imagesToUpload[$i]["image"], 3);
                    $j++;
                } catch (Exception $e) {
                    disp($e->getCode() . " " . $e->getMessage(), 5);
                    switch ($e->getCode()) {
                        case 1:
                        case 2:
                        case 5:
                            disp("Non-fatal error: " . $e->getMessage(), 3);
                            break;
                        case 100:
                        case 101:
                        case 103:
                        case 104:
                        case 120:
                        case 200:
                            disp("Fatal error: " . $e->getMessage() . "\n Please submit a bug report: \nhttp://github.com/jedediahfrey/Facebook-PHP-Batch-Picture-Uploader", 1);
                            break;
                        case 102:
                            disp("Could not login. Try creating a new auth code.", 1);
                        case 321:
                            disp($e->getMessage() . ". Should have been caught earlier.", 3);
                            $imageAlbums["size"][$uploadAlbumIdx] = 200;
                            break;
                        case 324:
                            disp($e->getMessage() . ". Bad Graphics/ImageMagick output? Skipping " . $imagesToUpload[$i]["image"], 3);
                            $imagesToUpload[$i]["uploaded"] = true;
                            break;
                        case 325:
                            disp($e->getMessage() . ". Allow php_batch_uploader to upload files directly: \nhttp://www.facebook.com/authorize.php?v=1.0&api_key={$key}&ext_perm=photo_upload\n\n", 1);
                            break;
                    }
                    $imagesToUpload[$i]["errors"]++;
                }
            }
            // If all images have been uploaded, break out of the while loop.
            if ($j == 0) {
                break;
            }
        }
    }
}