function recreateThumbnails() { global $TABLE_PREFIX; $tableNameWithoutPrefix = getTablenameWithoutPrefix($_REQUEST['tablename']); // error checking $stopPrefix = "STOPJS:"; // this tells javascript to stop creating thumbnails $requiredFields = array('tablename', 'fieldname', 'maxHeight', 'maxWidth'); foreach ($requiredFields as $fieldname) { if (!@$_REQUEST[$fieldname]) { die($stopPrefix . "Required fieldname '{$fieldname}' not specified!"); } } if (preg_match('/[^0-9\\_]/i', $_REQUEST['maxHeight'])) { die($stopPrefix . "Invalid value for max height!\n"); } if (preg_match('/[^0-9\\_]/i', $_REQUEST['maxWidth'])) { die($stopPrefix . "Invalid value for max width!\n"); } // get upload count static $count; if ($count == '') { $where = mysql_escapef("tableName = ? AND fieldName = ?", $tableNameWithoutPrefix, $_REQUEST['fieldname']); $totalUploads = mysql_count('uploads', $where); } // load upload $whereEtc = mysql_escapef("tableName = ? AND fieldname = ?", $tableNameWithoutPrefix, $_REQUEST['fieldname']); $whereEtc .= " LIMIT 1 OFFSET " . intval($_REQUEST['offset']); @(list($upload) = mysql_select('uploads', $whereEtc)); // if ($upload) { // get uploadDir and uploadUrl $schema = loadSchema($upload['tableName']); list($uploadDir, $uploadUrl) = getUploadDirAndUrl($schema[$upload['fieldName']]); // get upload's absolute filepath $absoluteFilepath = addUploadPathPrefix($upload['filePath'], $uploadDir); // make path absolute // error checking if (!file_exists($absoluteFilepath)) { $error = "Upload doesn't exist '{$absoluteFilepath}'!<br/>\n"; $error .= "Found in: {$upload['tableName']}, {$upload['fieldName']}, record {$upload['recordNum']}."; die($error); } ### resize image $isImage = preg_match("/\\.(gif|jpg|jpeg|png)\$/i", $absoluteFilepath); if ($isImage) { $thumbNum = $_REQUEST['thumbNum']; $thumbSavePath = preg_replace("|([^/]+)\$|", "thumb{$thumbNum}/\$1", $absoluteFilepath); $thumbUrlPath = preg_replace("|([^/]+)\$|", "thumb{$thumbNum}/\$1", $upload['urlPath']); // erase old thumbnail if (file_exists($thumbSavePath)) { @unlink($thumbSavePath) || die("Can't erase old thumbnail '{$thumbSavePath}': {$php_errormsg}"); } // create new thumbnail list($thumbWidth, $thumbHeight) = saveResampledImageAs($thumbSavePath, $absoluteFilepath, $_REQUEST['maxWidth'], $_REQUEST['maxHeight']); doAction('upload_thumbnail_save', array($tableNameWithoutPrefix, $_REQUEST['fieldname'], $thumbNum, $thumbSavePath)); // update upload database $query = "UPDATE `{$TABLE_PREFIX}uploads`\n"; $query .= " SET `thumbFilepath{$thumbNum}` = '" . mysql_escape(removeUploadPathPrefix($thumbSavePath, $uploadDir)) . "',\n"; $query .= " `thumbUrlPath{$thumbNum}` = '" . mysql_escape(removeUploadPathPrefix($thumbUrlPath, $uploadUrl)) . "',\n"; $query .= " `thumbWidth{$thumbNum}` = '" . mysql_escape($thumbWidth) . "',\n"; $query .= " `thumbHeight{$thumbNum}` = '" . mysql_escape($thumbHeight) . "'\n"; $query .= " WHERE num = '" . mysql_escape($upload['num']) . "'"; mysql_query($query) or die("MySQL Error: " . htmlencode(mysql_error()) . "\n"); } } // print status message $offset = $_REQUEST['offset'] + 1; if ($offset <= $totalUploads) { print "{$offset}/{$totalUploads}"; } else { print "done"; } exit; }
if (!array_key_exists('fieldName', $_REQUEST)) { die("no 'fieldName' value specified!"); } if (!array_key_exists($fieldname, $schema)) { die("Can't find field '" . htmlencode($fieldname) . "' in table '" . htmlencode($tableName) . "'!"); } if ($schema[$fieldname]['type'] != 'upload' && $schema[$fieldname]['type'] != 'wysiwyg') { die("Field '" . htmlencode($fieldname) . "' isn't an upload field!"); } if ($schema[$fieldname]['type'] == 'wysiwyg' && !@$schema[$fieldname]['allowUploads']) { die("Wysiwyg field '" . htmlencode($fieldname) . "' doesn't allow uploads!"); } if (!@$_REQUEST['num'] && !@$_REQUEST['preSaveTempId']) { die("No record 'num' or 'preSaveTempId' was specified!"); } list($uploadDir, $uploadUrl) = getUploadDirAndUrl($schema[$fieldname]); if (!file_exists($uploadDir)) { mkdir_recursive($uploadDir, 0755); } // create upload dir (if not possible, dir not exists error will show below) if (!file_exists($uploadDir)) { die("Upload directory '" . htmlencode($uploadDir) . "' doesn't exist!"); } elseif (!is_writable($uploadDir)) { die("Upload directory '" . htmlencode($uploadDir) . "' isn't writable!"); } // submit uploads if (@$_REQUEST['submitUploads']) { submitUploadForm(); // if this is the flash uploader, report the errors instead of generating a non-flash upload html form if (isFlashUploader()) { print $GLOBALS['errors'];
function _showUpload($fieldSchema, $record) { global $preSaveTempId, $SETTINGS, $menu; $prefixText = @$fieldSchema['fieldPrefix']; $description = @$fieldSchema['description']; if ($prefixText) { $prefixText .= "<br/>"; } // create uploadList url $uploadList = "?" . "menu=" . urlencode($menu) . "&action=uploadList" . "&fieldName=" . urlencode($fieldSchema['name']) . "&num=" . urlencode(@$_REQUEST['num']) . "&preSaveTempId=" . urlencode($preSaveTempId); // create uploadLink url $uploadLink = "?menu=" . urlencode($menu) . "&action=uploadForm" . "&fieldName=" . urlencode($fieldSchema['name']) . "&num=" . urlencode(@$_REQUEST['num']) . "&preSaveTempId=" . urlencode($preSaveTempId) . "&TB_iframe=true&height=350&width=700&modal=true"; // error checking $errors = ''; list($uploadDir, $uploadUrl) = getUploadDirAndUrl($fieldSchema); if (!file_exists($uploadDir)) { mkdir_recursive($uploadDir, 0755); } // create upload dir (if not possible, dir not exists error will show below) if (!file_exists($uploadDir)) { $errors .= "Upload directory '" . htmlencode($uploadDir) . "' doesn't exist!.<br/>\n"; } elseif (!is_writable($uploadDir)) { $errors .= "Upload directory '" . htmlencode($uploadDir) . "' isn't writable!.<br/>\n"; } // display errors if ($errors) { print <<<__HTML__ <tr> <td valign="top"><br/>{$fieldSchema['label']}<br/></td> <td><div id='alert'><span>{$errors}</span></div></td> </tr> __HTML__; return; } // display field ?> <tr> <td style="vertical-align: top"><?php echo $fieldSchema['label']; ?> </td> <td> <?php echo $prefixText; ?> <iframe id="<?php echo $fieldSchema['name']; ?> _iframe" src="<?php echo $uploadList; ?> " height="100" width="100%" frameborder="0" class="uploadIframe"></iframe><br/> <?php $displayDefaultLink = applyFilters('edit_show_upload_link', true, $fieldSchema, $record); ?> <?php if ($displayDefaultLink) { ?> <div style="position: relative; height: 24px;"> <div style="position: absolute; top: 6px; width: 100%; text-align: center;"> <?php if (inDemoMode()) { ?> <a href="javascript:alert('<?php echo jsEncode(t('This feature is disabled in demo mode.')); ?> ')"><b><?php echo t('Add or Upload File(s)'); ?> </b></a> <?php } else { ?> <a href="<?php echo $uploadLink; ?> " class="thickbox"><b><?php echo t('Add or Upload File(s)'); ?> </b></a> <?php } ?> </div> <div style="position: absolute; z-index: 1; width: 100%; text-align: center;"> <div id="<?php echo $fieldSchema['name']; ?> _uploadButton"></div> </div> </div> <?php $useFlashUploader = !@$SETTINGS['advanced']['disableFlashUploader']; ?> <?php if ($useFlashUploader && !inDemoMode()) { ?> <?php $fileExtCSV = implode(',', preg_split("/\\s*\\,\\s*/", strtolower($fieldSchema['allowedExtensions']))); ?> <div id="<?php echo $fieldSchema['name']; ?> _uploadTips" style="display: none; text-align: center; font-size: xx-small; margin-top: 2px;"> <?php $isMac = preg_match('/macintosh|mac os x/i', @$_SERVER['HTTP_USER_AGENT']); $key = $isMac ? '<Command>' : '<Ctrl>'; if (@$fieldSchema['maxUploads'] != 1) { echo htmlencode(t("Tip: hold {$key} to select multiple files")); } ?> <br/> <?php echo $description; ?> </div> <div class="uploadifyQueue" id="<?php echo $fieldSchema['name']; ?> _uploadQueue"></div> <script type="text/javascript">// <![CDATA[ $(document).ready(function() { $('#<?php echo $fieldSchema['name']; ?> _uploadButton').uploadify(generateUploadifyOptions({ 'script' : <?php echo json_encode(basename(@$_SERVER['SCRIPT_NAME'])); ?> , 'modifyAfterSave' : <?php echo count(getUploadInfoFields($fieldSchema['name'])); ?> , 'menu' : <?php echo json_encode($menu); ?> , 'fieldName' : <?php echo json_encode($fieldSchema['name']); ?> , 'num' : <?php echo json_encode(@$_REQUEST['num'] ? $_REQUEST['num'] : ''); ?> , 'preSaveTempId' : <?php echo json_encode($preSaveTempId); ?> , 'buttonText' : <?php echo json_encode(t('Upload File(s)')); ?> , 'fileExtCSV' : <?php echo json_encode($fileExtCSV); ?> , 'maxUploadSizeKB' : <?php echo json_encode($fieldSchema['checkMaxUploadSize'] ? $fieldSchema['maxUploadSizeKB'] : 0); ?> , 'loginDataEncoded' : <?php echo json_encode(@$_COOKIE[loginCookie_name(true)]); ?> , 'queueID' : <?php echo json_encode($fieldSchema['name'] . "_uploadQueue"); ?> })); }); // ]]></script> <?php } ?> <?php } ?> </td> </tr> <?php }