Beispiel #1
0
function mediashareSourceZipAddFile(&$zip, &$zipEntry, &$args)
{
    $dom = ZLanguage::getModuleDomain('mediashare');
    // Read zip info and file data into buffer
    $zipSize = zip_entry_filesize($zipEntry);
    $zipName = zip_entry_name($zipEntry);
    if (!zip_entry_open($zip, $zipEntry, 'rb')) {
        return array(array('ok' => false, 'message' => __f('Could not open the ZIP: %s', "{$zipName}", $dom)));
    }
    $buffer = zip_entry_read($zipEntry, $zipSize);
    zip_entry_close($zipEntry);
    // Ensure sub-folder exists
    // Split name by slashes into folders and filename and create/verify the folders recursively
    $folders = explode('/', $zipName);
    $albumId = $args['albumId'];
    if (!($subFolderID = mediashareEnsureFolderExists($albumId, $folders, 0))) {
        return false;
    }
    $args['albumId'] = $subFolderID;
    // Get actual filename from folderlist (last item in the array)
    $imageName = $folders[sizeof($folders) - 1];
    // Create tmp. file and copy image data into it
    $tmpdir = pnModGetVar('mediashare', 'tmpDirName');
    $tmpfilename = tempnam($tmpdir, 'IMG');
    if (!($f = fopen($tmpfilename, 'wb'))) {
        @unlink($tmpfilename);
        return false;
    }
    fwrite($f, $buffer);
    fclose($f);
    $args['mimeType'] = '';
    if (function_exists('mime_content_type')) {
        $args['mimeType'] = mime_content_type($tmpfilename);
        if (empty($args['mimeType'])) {
            $args['mimeType'] = mime_content_type($imageName);
        }
    }
    if (empty($args['mimeType'])) {
        $args['mimeType'] = mediashareGetMimeType($imageName);
    }
    $args['uploadFilename'] = $tmpfilename;
    $args['fileSize'] = $zipSize;
    $args['filename'] = $imageName;
    $args['keywords'] = null;
    $args['description'] = null;
    // Create image (or add recursively zip archive)
    $result = pnModAPIFunc('mediashare', 'source_zip', 'addMediaItem', $args);
    if ($result === false) {
        $status = array('ok' => false, 'message' => LogUtil::getErrorMessagesText());
    } else {
        $status = array('ok' => true, 'message' => $result['message'], 'mediaId' => $result['mediaId']);
    }
    $args['albumId'] = $albumId;
    return $status;
}
Beispiel #2
0
function mediashareEnsureFolderExists($parentFolderID, $folders, $folderOffset)
{
    $dom = ZLanguage::getModuleDomain('mediashare');
    // End of recursion?
    if ($folderOffset == sizeof($folders) - 1) {
        return $parentFolderID;
    }
    $folderTitle = $folders[$folderOffset];
    // Get ID of existing folder
    $pntable = pnDBGetTables();
    $foldersTable = $pntable['mediashare_albums'];
    $foldersColumn = $pntable['mediashare_albums_column'];
    $sql = "SELECT {$foldersColumn['id']}\n              FROM {$foldersTable}\n             WHERE {$foldersColumn['parentAlbumId']} = '" . DataUtil::formatForStore($parentFolderID) . "'\n               AND {$foldersColumn['title']} = '" . DataUtil::formatForStore($folderTitle) . "'";
    $result = DBUtil::executeSQL($sql);
    if ($result === false) {
        return LogUtil::registerError(__f('Error in %1$s: %2$s.', array('common.EnsureFolderExists', 'Could not retrieve the folder information.'), $dom), 404);
    }
    // No ID => folder does not exist. Create it.
    if (!$result) {
        if (!($folderID = pnModAPIFunc('mediashare', 'edit', 'addAlbum', array('parentAlbumId' => $parentFolderID, 'title' => $folderTitle, 'description' => '', 'keywords' => '', 'summary' => '')))) {
            return false;
        }
    } else {
        $folderID = DBUtil::marshallObjects($result, array('id'));
        $folderID = (int) $folderID[0]['id'];
    }
    // Recursive to ensure sub-folders exists
    return mediashareEnsureFolderExists($folderID, $folders, $folderOffset + 1);
}