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 mediashare_vfs_db_dump() { $fileref = $_GET['ref']; // Retrieve image information if (!($media = pnModAPIFunc('mediashare', 'vfs_db', 'getMedia', array('fileref' => $fileref)))) { return false; } // Check access if (!mediashareAccessAlbum($media['albumId'], mediashareAccessRequirementView, null)) { return LogUtil::registerPermissionError(); } // Some Mediashare users have reported this to make their setup work. The buffer may contain something // due to a buggy template or block while (@ob_end_clean()) { } if (pnConfigGetVar('UseCompression') == 1) { // With the "while (@ob_end_clean());" stuff above we are guranteed that no z-buffering is done // But(!) the "ob_start("ob_gzhandler");" made by pnAPI.php means a "Content-Encoding: gzip" is set. // So we need to reset this header since no compression is done header("Content-Encoding: identity"); } // Check cached versus modified date $lastModifiedDate = date('D, d M Y H:i:s T', $media['modifiedDate']); $currentETag = $media['modifiedDate']; global $HTTP_SERVER_VARS; $cachedDate = isset($HTTP_SERVER_VARS['HTTP_IF_MODIFIED_SINCE']) ? $HTTP_SERVER_VARS['HTTP_IF_MODIFIED_SINCE'] : null; $cachedETag = isset($HTTP_SERVER_VARS['HTTP_IF_NONE_MATCH']) ? $HTTP_SERVER_VARS['HTTP_IF_NONE_MATCH'] : null; // If magic quotes are on then all query/post variables are escaped - so strip slashes to make a compare possible // - only cachedETag is expected to contain quotes if (get_magic_quotes_gpc()) { $cachedETag = stripslashes($cachedETag); } if ((empty($cachedDate) || $lastModifiedDate == $cachedDate) && '"' . $currentETag . '"' == $cachedETag) { header("HTTP/1.1 304 Not Modified"); header("Status: 304 Not Modified"); header("Expires: " . date('D, d M Y H:i:s T', time() + 180 * 24 * 3600)); // My PHP insists on Expires in 1981 as default! header('Pragma: cache'); // My PHP insists on putting a pragma "no-cache", so this is an attempt to avoid that header('Cache-Control: public'); header("ETag: \"{$media['modifiedDate']}\""); return true; } header("Expires: " . date('D, d M Y H:i:s T', time() + 180 * 24 * 3600)); // My PHP insists on Expires in 1981 as default! header('Pragma: cache'); // My PHP insists on putting a pragma "no-cache", so this is an attempt to avoid that header('Cache-Control: public'); header("ETag: \"{$media['modifiedDate']}\""); // Ensure correct content-type and a filename for eventual download header("Content-Type: {$media['mimeType']}"); header("Content-Disposition: inline; filename=\"{$media['title']}\""); header("Last-Modified: {$lastModifiedDate}"); header("Content-Length: " . strlen($media['data'])); echo $media['data']; return true; }
function mediashareSourceYoutubeSave(&$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) { $videoytcode = FormUtil::getPassedValue("videoytcode{$i}"); $args['width'] = FormUtil::getPassedValue("width{$i}"); $args['height'] = FormUtil::getPassedValue("height{$i}"); $result = mediashareSourceYoutubeAdd($videoytcode, $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)); } // 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_youtube_added.html'); }
/** * Find / paste */ function mediashare_external_finditem($args) { // FIXME access check $albumId = mediashareGetIntUrl('aid', $args, 1); $mediaId = mediashareGetIntUrl('mid', $args, 0); $mode = FormUtil::getPassedValue('mode'); $cmd = FormUtil::getPassedValue('cmd'); $onlyMine = mediashareGetIntUrl('onlymine', $args, 0); $uploadFailed = false; if ($cmd == 'selectAlbum') { $mediaId = 0; } else { if (isset($_POST['selectButton'])) { $file = isset($_FILES['upload']) ? $_FILES['upload'] : null; if (!empty($file) && $file['error'] == 0 && mediashareAccessAlbum($albumId, mediashareAccessRequirementEditAlbum)) { $result = pnModAPIFunc('mediashare', 'source_browser', 'addMediaItem', array('albumId' => $albumId, 'uploadFilename' => $file['tmp_name'], 'fileSize' => $file['size'], 'filename' => $file['name'], 'mimeType' => $file['type'], 'title' => null, 'keywords' => null, 'description' => null, 'width' => 0, 'height' => 0)); if ($result === false) { $uploadFailed = true; } else { $mediaId = $result['mediaId']; } } if (!$uploadFailed) { return pnRedirect(pnModUrl('mediashare', 'external', 'pasteitem', array('aid' => $albumId, 'mid' => $mediaId, 'mode' => $mode))); } } } $mediaItem = pnModAPIFunc('mediashare', 'user', 'getMediaItem', array('mediaId' => $mediaId)); $render =& pnRender::getInstance('mediashare', false); mediashareExternalLoadTheme($render); $render->assign('albumId', $albumId); $render->assign('mediaId', $mediaId); $render->assign('mediaItem', $mediaItem); $render->assign('mode', $mode); $render->assign('onlyMine', $onlyMine); $render->assign('hasEditAccess', mediashareAccessAlbum($albumId, mediashareAccessRequirementEditAlbum)); if ($uploadFailed) { $render->assign('uploadErrorMessage', LogUtil::getErrorMessagesText()); } echo $render->fetch('mediashare_external_finditem.html'); return true; }
function decode(&$render) { $dom = ZLanguage::getModuleDomain('mediashare'); $this->clearValidation($render); $value = FormUtil::getPassedValue($this->inputName, null, 'POST'); $albumId = FormUtil::getPassedValue("{$this->inputName}_album", null, 'POST'); $newAlbum = FormUtil::getPassedValue("{$this->inputName}_newalbum", null, 'POST'); if (!empty($newAlbum)) { if (mediashareAccessAlbum($albumId, mediashareAccessRequirementAddAlbum, '')) { $newAlbumID = pnModAPIFunc('mediashare', 'edit', 'addAlbum', array('title' => $newAlbum, 'keywords' => '', 'summary' => '', 'description' => '', 'template' => null, 'parentAlbumId' => $albumId)); if ($newAlbumID === false) { $this->setError(LogUtil::getErrorMessagesText()); } else { $albumId = $newAlbumID; } } else { $this->setError(__('You do not have access to this feature', $dom)); } } $file = isset($_FILES["{$this->inputName}_upload"]) ? $_FILES["{$this->inputName}_upload"] : null; if (!empty($file) && $file['error'] == 0) { if (mediashareAccessAlbum($albumId, mediashareAccessRequirementAddMedia, '')) { $result = pnModAPIFunc('mediashare', 'source_browser', 'addMediaItem', array('albumId' => $albumId, 'uploadFilename' => $file['tmp_name'], 'fileSize' => $file['size'], 'filename' => $file['name'], 'mimeType' => $file['type'], 'title' => null, 'keywords' => null, 'description' => null, 'width' => 0, 'height' => 0)); if ($result === false) { $this->setError(LogUtil::getErrorMessagesText()); } else { $value = $result['mediaId']; } } else { $this->setError(__('You do not have access to this feature', $dom)); } } $this->selectedItemId = $value; }
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 mediashare_user_displaygb($args) { $mediaId = mediashareGetIntUrl('mid', $args, 0); $viewkey = FormUtil::getPassedValue('viewkey'); if (!($mediaItem = pnModAPIFunc('mediashare', 'user', 'getMediaItem', array('mediaId' => $mediaId)))) { return false; } $albumId = $mediaItem['parentAlbumId']; // Check access if (!mediashareAccessAlbum($albumId, mediashareAccessRequirementViewSomething, $viewkey)) { return LogUtil::registerPermissionError(); } // Build the output $render =& pnRender::getInstance('mediashare', false); $render->assign('mediaItem', $mediaItem); $render->display('mediashare_user_displaygb.html'); return true; }
function mediashare_remote_newalbum() { if (!mediashareAccessAlbum($_POST['set_albumName'], mediashareAccessRequirementAddAlbum, '')) { return LogUtil::registerPermissionError(); } // FIXME direct use of $_POST if (!($newAlbumID = pnModAPIFunc('mediashare', 'edit', 'addAlbum', array('title' => $_POST['newAlbumTitle'], 'keywords' => '', 'summary' => '', 'description' => $_POST['newAlbumDesc'], 'template' => null, 'parentAlbumId' => $_POST['set_albumName'])))) { return mediashareErrorAPIRemote(); } echo "__#GR2PROTO__\nstatus=0\nstatus_text=ok\nalbum_name={$newAlbumID}"; return true; }
function mediashare_invitation_list($args) { $albumId = mediashareGetIntUrl('aid', $args, 1); // Check access if (!mediashareAccessAlbum($albumId, mediashareAccessRequirementEditAccess, '')) { return LogUtil::registerPermissionError(); } if (isset($_POST['expireButton'])) { return mediashareExpireInvitations($args); } else { if (isset($_POST['deleteButton'])) { return mediashareDeleteInvitations($args); } } if (!($album = pnModAPIFunc('mediashare', 'user', 'getAlbum', array('albumId' => $albumId)))) { return false; } if (!($invitations = pnModAPIFunc('mediashare', 'invitation', 'getInvitations', array('albumId' => $albumId)))) { return false; } $render =& pnRender::getInstance('mediashare', false); $render->assign('album', $album); $render->assign('invitations', $invitations); $render->assign('accessSelected', 0); $render->assign('sendSelected', 0); $render->assign('listSelected', 1); return $render->fetch('mediashare_invitation_list.html'); }
/** * Access edit */ function mediashare_edit_access($args) { $albumId = mediashareGetIntUrl('aid', $args, 1); // Check access if (!mediashareAccessAlbum($albumId, mediashareAccessRequirementEditAccess, '')) { return LogUtil::registerPermissionError(); } if (isset($_POST['cancelButton'])) { return pnRedirect(pnModURL('mediashare', 'edit', 'view', array('aid' => $albumId))); } if (isset($_POST['saveButton'])) { return mediashareUpdateAccess($args); } // Fetch current album if (!($album = pnModAPIFunc('mediashare', 'user', 'getAlbum', array('albumId' => $albumId)))) { return false; } if (!($access = pnModAPIFunc('mediashare', 'edit', 'getAccessSettings', array('albumId' => $albumId)))) { return false; } // Build the output $render =& pnRender::getInstance('mediashare', false); $render->assign('album', $album); $render->assign('access', $access); $render->assign('accessSelected', 1); $render->assign('sendSelected', 0); $render->assign('listSelected', 0); return $render->fetch('mediashare_edit_access.html'); }
/** * Move album */ function mediashare_editapi_moveAlbum($args) { // Check access if (!SecurityUtil::checkPermission('mediashare::', '::', ACCESS_EDIT)) { return LogUtil::registerPermissionError(); } $dom = ZLanguage::getModuleDomain('mediashare'); $albumId = (int) $args['albumId']; $dstAlbumId = (int) $args['dstAlbumId']; if ($albumId == 1) { return LogUtil::registerError(__('Cannot move top album', $dom)); } if ($albumId == $dstAlbumId) { return LogUtil::registerError(__('Cannot move album to self', $dom)); } if ($dstAlbumId == 0) { return LogUtil::registerError(__('Cannot move album outsite root album', $dom)); } // Process if (!($album = pnModAPIFunc('mediashare', 'user', 'getAlbum', array('albumId' => $albumId)))) { return false; } if (!($dstAlbum = pnModAPIFunc('mediashare', 'user', 'getAlbum', array('albumId' => $dstAlbumId)))) { return false; } if (!mediashareAccessAlbum($albumId, mediashareAccessRequirementEditAccess, '') || !mediashareAccessAlbum($dstAlbumId, mediashareAccessRequirementAddAlbum, '')) { return LogUtil::registerPermissionError(); } $isChild = pnModAPIFunc('mediashare', 'edit', 'isChildAlbum', array('albumId' => $dstAlbumId, 'parentAlbumId' => $albumId)); if ($isChild === true) { return LogUtil::registerError(__('Cannot move album below self', $dom)); } $album = array('id' => $albumId, 'parentAlbumId' => $dstAlbumId); $album = DBUtil::updateObject($album, 'mediashare_albums', '', 'id'); if ($album === false) { return LogUtil::registerError(__f('Error in %1$s: %2$s.', array('editapi.moveAlbum', 'Could not move the album.'), $dom)); } if (!pnModAPIFunc('mediashare', 'edit', 'updateNestedSetValues')) { return false; } return true; }