function mediashareSourceBrowserUpload(&$args) { if (!SecurityUtil::confirmAuthKey()) { return LogUtil::registerAuthidError(); } $dom = ZLanguage::getModuleDomain('mediashare'); $albumId = mediashareGetIntUrl('aid', $args, 0); // Check access if (!mediashareAccessAlbum($albumId, mediashareAccessRequirementAddMedia, '')) { return LogUtil::registerPermissionError(); } // Get parent album information if (!($album = pnModAPIFunc('mediashare', 'user', 'getAlbum', array('albumId' => $albumId)))) { return false; } // Start fetching media items $imageNum = (int) FormUtil::getPassedValue('imagenum'); $statusSet = array(); for ($i = 1; $i <= $imageNum; ++$i) { $uploadInfo = $_FILES["upload{$i}"]; $width = FormUtil::getPassedValue("width{$i}"); $height = FormUtil::getPassedValue("height{$i}"); if (isset($uploadInfo['error']) && $uploadInfo['error'] != 0 && $uploadInfo['name'] != '') { $statusSet[] = array('ok' => false, 'message' => $uploadInfo['name'] . ': ' . mediashareUploadErrorMsg($uploadInfo['error'])); } else { if ($uploadInfo['size'] > 0) { $result = pnModAPIFunc('mediashare', 'source_browser', 'addMediaItem', array('albumId' => $albumId, 'uploadFilename' => $uploadInfo['tmp_name'], 'fileSize' => $uploadInfo['size'], 'filename' => $uploadInfo['name'], 'mimeType' => $uploadInfo['type'], 'title' => null, 'keywords' => null, 'description' => null, 'width' => $width, 'height' => $height)); if ($result === false) { $status = array('ok' => false, 'message' => LogUtil::getErrorMessagesText()); } else { $status = array('ok' => true, 'message' => $result['message'], 'mediaId' => $result['mediaId']); } $statusSet = array_merge($statusSet, array($status)); } } } // Quick count of uploaded images + getting IDs for further editing $editMediaIds = array(); $acceptedImageNum = 0; foreach ($statusSet as $status) { if ($status['ok']) { ++$acceptedImageNum; $editMediaIds[] = $status['mediaId']; } } $album['imageCount'] += $acceptedImageNum; // Update for showing only if ($acceptedImageNum == 0) { $statusSet[] = array('ok' => false, 'message' => __('No media items', $dom)); } if (($items = pnModAPIFunc('mediashare', 'user', 'getMediaItems', array('mediaIdList' => $editMediaIds))) === false) { return false; } $render =& pnRender::getInstance('mediashare', false); $render->assign('statusSet', $statusSet); $render->assign('items', $items); return $render->fetch('mediashare_source_browser_uploadet.html'); }
function mediashareSourceZipUpload(&$args) { if (!SecurityUtil::confirmAuthKey()) { return LogUtil::registerAuthidError(); } $dom = ZLanguage::getModuleDomain('mediashare'); $albumId = mediashareGetIntUrl('aid', $args, 0); // Check access if (!mediashareAccessAlbum($albumId, mediashareAccessRequirementAddMedia, '')) { return LogUtil::registerPermissionError(); } // Get parent album information if (!($album = pnModAPIFunc('mediashare', 'user', 'getAlbum', array('albumId' => $albumId)))) { return false; } // Start fetching media items $imageNum = (int) FormUtil::getPassedValue('imagenum'); $statusSet = array(); $args['albumId'] = $albumId; for ($i = 1; $i <= $imageNum; ++$i) { $uploadInfo = $_FILES["upload{$i}"]; $args['width'] = FormUtil::getPassedValue("width{$i}"); $args['height'] = FormUtil::getPassedValue("height{$i}"); if (isset($uploadInfo['error']) && $uploadInfo['error'] != 0 && $uploadInfo['name'] != '') { $statusSet[] = array('ok' => false, 'message' => $uploadInfo['name'] . ': ' . mediashareUploadErrorMsg($uploadInfo['error'])); } else { if ($uploadInfo['size'] > 0) { $zip = zip_open($uploadInfo['tmp_name']); if (!$zip) { return LogUtil::registerError(__('Could not open the ZIP.', $dom)); } while ($zipEntry = zip_read($zip)) { // echo "Name: ".zip_entry_name($zipEntry)."\n"; // echo "Actual Filesize: ".zip_entry_filesize($zipEntry)."\n"; // echo "Compressed Size: ".zip_entry_compressedsize($zipEntry)."\n"; // echo "Compression Method: ".zip_entry_compressionmethod($zipEntry)."\n"; // echo "<br>\n"; if (zip_entry_filesize($zipEntry) > 0) { $result = mediashareSourceZipAddFile($zip, $zipEntry, $args); if ($result === false) { $status = array('ok' => false, 'message' => LogUtil::getErrorMessagesText()); } else { $status = array('ok' => true, 'message' => $result['message'], 'mediaId' => $result['mediaId']); } $statusSet = array_merge($statusSet, array($status)); } } zip_close($zip); } } } // Quick count of uploaded images + getting IDs for further editing $editMediaIds = array(); $acceptedImageNum = 0; foreach ($statusSet as $status) { if ($status['ok']) { ++$acceptedImageNum; $editMediaIds[] = $status['mediaId']; } } $album['imageCount'] += $acceptedImageNum; // Update for showing only if ($acceptedImageNum == 0) { $statusSet[] = array('ok' => false, 'message' => __('No media items', $dom)); } if (($items = pnModAPIFunc('mediashare', 'user', 'getMediaItems', array('mediaIdList' => $editMediaIds))) === false) { return false; } $render =& pnRender::getInstance('mediashare', false); $render->assign('statusSet', $statusSet); $render->assign('items', $items); return $render->fetch('mediashare_source_zip_uploadet.html'); }
function mediashareUpdateItem($args, $backUrl) { if (!SecurityUtil::confirmAuthKey()) { return LogUtil::registerAuthidError(); } //$albumId = mediashareGetIntUrl('aid', $args, 1); $mediaId = mediashareGetIntUrl('mid', $args, 0); // Check access if (!mediashareAccessItem($mediaId, mediashareAccessRequirementEditMedia, '')) { return LogUtil::registerPermissionError(); } global $mediashare_itemFields; $values = elfisk_decodeInput($mediashare_itemFields); $uploadInfo = $_FILES['upload']; $width = FormUtil::getPassedValue('width'); $height = FormUtil::getPassedValue('height'); if (isset($uploadInfo['error']) && $uploadInfo['error'] != 0 && $uploadInfo['name'] != '') { return LogUtil::registerError(DataUtil::formatForDisplay($uploadInfo['name']) . ': ' . mediashareUploadErrorMsg($uploadInfo['error'])); } $ok = pnModAPIFunc('mediashare', 'edit', 'updateItem', $values + array('mediaId' => $mediaId, 'uploadFilename' => $uploadInfo['tmp_name'], 'fileSize' => $uploadInfo['size'], 'filename' => $uploadInfo['name'], 'mimeType' => $uploadInfo['type'], 'width' => $width, 'height' => $height)); return $ok ? pnRedirect($backUrl) : false; }