Beispiel #1
0
<div class="row">
	<div class="sixteen columns">

		<img src="<?php 
echo placehold_it('640', '480', 'This is a test', '032786');
?>
" />

	</div><!--/columns-->
</div><!--/row-->
function unsplash_it($width = 800, $height = 600, $raw = false, $specific = false)
{
    $override = apply_filters('pre_unsplash_it', false, $width, $height, $raw, $specific);
    if ($override !== false) {
        return $override;
    }
    $skip_list = array(31, 35, 224, 285, 312, 16, 403, 172, 268, 267, 349, 69, 103, 24, 140, 47, 219, 222, 184, 306, 70, 371, 385, 45, 211, 95, 83, 150, 233, 275, 343, 317, 278, 429, 383, 296, 292, 193, 299, 195, 298, 68, 148, 151, 129, 277, 333, 85, 48, 128, 365, 138, 155, 257, 37, 288, 407);
    if (!is_int($specific)) {
        $randID = random_number_between_but_not(0, 874, $skip_list);
        //Update the second number here periodically as more Unsplash.it photos become available.
    } else {
        $randID = $specific;
    }
    //Check if unsplash.it is online
    if (!nebula_is_available('https://unsplash.it')) {
        ga_send_event('send', 'event', 'Error', 'Random Unsplash', 'Unsplash.it Not Available');
        if ($raw) {
            return placehold_it($width, $height, 'Unsplash.it Unavailable', 'ca3838');
        } else {
            return placehold_it($width, $height, 'Unsplash.it Unavailable', 'ca3838') . '" title="Unsplash.it is not available.';
        }
    }
    $image_path = 'https://unsplash.it/' . $width . '/' . $height . '?image=' . $randID;
    $check_image = nebula_is_available($image_path);
    //Ignore errors (because that's what we're looking for)
    $i = 1;
    $attempts = '';
    while (!$check_image) {
        $attempts = ' [Errors: ' . $i . ']';
        if ($specific || $i >= 5) {
            ga_send_event('send', 'event', 'Error', 'Random Unsplash', 'Image Not Found (ID: ' . $randID . ')');
            if ($raw) {
                placehold_it($width, $height, 'ID+' . $randID . '+Not+Found', 'f6b83f');
            } else {
                return placehold_it($width, $height, 'ID+' . $randID . '+Not+Found', 'f6b83f') . '" title="Unsplash image with ID ' . $randID . $attempts;
            }
        }
        $skip_list[] = $randID;
        ga_send_event('send', 'event', 'Error', 'Random Unsplash', 'Image Not Found (ID: ' . $randID . ')' . $attempts);
        $randID = random_number_between_but_not(0, 615, $skipList);
        $image_path = 'https://unsplash.it/' . $width . '/' . $height . '?image=' . $randID;
        $check_image = nebula_is_available($image_path);
        $i++;
    }
    if ($raw) {
        return $image_path;
    } else {
        return $image_path . '" title="Unsplash ID #' . $randID . $attempts;
    }
}