Skip to content

Commit

Permalink
Merge pull request #7 from keanpedersen/master
Browse files Browse the repository at this point in the history
Preliminary support for dummy images by HTTP request...which makes it possible to call images from stylesheets.
  • Loading branch information
kerns committed Jun 21, 2013
2 parents 750f108 + e42688b commit c25268f
Showing 1 changed file with 32 additions and 6 deletions.
38 changes: 32 additions & 6 deletions dummy/dummy.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,13 +127,17 @@ function dummy_ad($folder) {

}

function dummy_image($path, $params) {
function dummy_image($path, $params, $pathtype = "URI") {
global $dummy_path;
$basePath = dirname(__FILE__)."/assets/image/";
$imgFn = getRandomFile($basePath, $path);

if ($params == "") {
$result = $dummy_path."/assets/image/".$imgFn;
if ($pathtype == "URI") {
$result = $dummy_path."/assets/image/".$imgFn;
} else {
$result = $basePath . $imgFn;
}
} else {
$params = str_replace(" ", "", $params);
$params = explode(",", $params);
Expand Down Expand Up @@ -244,7 +248,11 @@ function dummy_image($path, $params) {
imagedestroy($img);
imagedestroy($cImg);
}
$result = $nImgUrl;
if ($pathtype == "URI") {
$result = $nImgUrl;
} else {
$result = $nImgFn;
}
}
print $result;
}
Expand Down Expand Up @@ -335,7 +343,7 @@ function getFilesRecursively($basePath, $path = "", $files = array()) {
return $files;
}

function dummy($a) {
function dummy($a, $internalcall = false) {
global $delimiter;

// Parse the command
Expand All @@ -355,12 +363,30 @@ function dummy($a) {
if (substr($path, -1) != "/") {
$path.= "/";
}
dummy_image($path, $params);
dummy_image($path, $params, $internalcall ? 'FILE' : 'URI');
} else {
dummy_text($cmdraw, $params);
}

}

// Check for the presense of a direct call
// If that is the case, we call dummy() with the query part
if (basename(__FILE__) === basename($_SERVER['SCRIPT_FILENAME'])) {
ob_start();
dummy($_SERVER['QUERY_STRING'], true);
$content = ob_get_contents();
ob_end_clean();
// figure out the image type
$imgtype = exif_imagetype($content);
$contenttype = image_type_to_mime_type($imgtype);
header("Content-type: " . $contenttype);
readfile($content);
exit();

}


// SO ENDS THE DUMMY CORE


Expand Down Expand Up @@ -548,4 +574,4 @@ function dumb_question($p) {
return false;
}

/* eof */
/* eof */

0 comments on commit c25268f

Please sign in to comment.