Example #1
0
function processUploads()
{
    global $uploadsFolder, $portfolioFolder;
    $files = array_values(preg_grep("/[.](jpg|jpeg|png)\$/i", scandir($uploadsFolder)));
    foreach ($files as $filename) {
        $id = getNextImageId();
        $pathInfo = pathinfo($filename);
        $extension = strtolower($pathInfo["extension"]);
        $origFile = "{$portfolioFolder}/{$id}-original.{$extension}";
        rename("{$uploadsFolder}/{$filename}", $origFile);
        createImages($origFile, $id);
        $dbFilename = "{$portfolioFolder}/{$id}-db.json";
        $imageDb = array("id" => $id, "sort" => intval($id) * 10000, "original" => $filename, "uploaded" => gmdate("Y-m-d"), "display" => false, "caption" => "", "description" => "", "badge" => "");
        saveDb($dbFilename, $imageDb);
    }
    $msg = "Images processed: " . count($files);
    return array("count" => count($files), "files" => $files, "message" => $msg);
}
Example #2
0
//When included as part of a drupal module $file name is set in the module
//When called as a Jquery enpoint dirctly the manifest file should be specified in the query
//In both modes this output is intended to act as a service endpoint called within yesno.js
//The service returns the url of the next image to return by selecting a random line in the manifest
/**
 *TODO - This needs to be converted to read the next image from the DB when in drupal mode - this operation should take into account any response threshhold for 
 *       the question and should pick a random value from the manifest entries that have not yet reached their threshold - speed may be an issue here
 *       To get a single random value use limit based on a count of the available manifest entries 
 **/
//Handle a non Drupal request
if ($_GET["filename"]) {
    if ($_GET["objectid"]) {
        getImageForObject($_GET["filename"], $_GET["objectid"]);
    } else {
        getNextImageId($_GET["filename"]);
    }
}
/**
 *Gets the url for the next image to display by retrieving a random entry from a fixed length record manifest file
 *Used when operating without a DB
 **/
function getNextImageId($filename)
{
    //Filename will point to the text file but want to read the mfx file
    $folder = pathinfo($filename, PATHINFO_DIRNAME);
    $base = pathinfo($filename, PATHINFO_FILENAME);
    //At the moment just read the manifest into an array
    //$urls = file($filename,FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
    $mfx = "{$folder}/{$base}.mfx";
    $fp = fopen($mfx, "r");