Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added a default expiration date for public links #33

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion classes/ocs_client.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ public function get_api_functions() {
'path' => PARAM_TEXT, // Could be PARAM_PATH, we really don't want to enforce a Moodle understanding of paths.
'shareType' => PARAM_INT,
'publicUpload' => PARAM_RAW, // Actually Boolean, but neither String-Boolean ('false') nor PARAM_BOOL (0/1).
'permissions' => PARAM_INT
'permissions' => PARAM_INT,
'expireDate' => PARAM_TEXT
],
'response' => 'text/xml'
],
Expand Down
9 changes: 7 additions & 2 deletions lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,7 @@ public function get_listing($path='', $page = '') {

/**
* Use OCS to generate a public share to the requested file.
* It sets a default expiration link of 10 years
* This method derives a download link from the public share URL.
*
* @param string $url relative path to the chosen file
Expand All @@ -262,12 +263,16 @@ public function get_listing($path='', $page = '') {
*
*/
public function get_link($url) {
// Todo this is set to ten years, however an issue will be opened for owncloud to enable endless expireDates
$expirationunix = time() + 315569260;
$expiration = (string) date('Y-m-d', $expirationunix);
$ocsparams = [
'path' => $url,
'shareType' => ocs_client::SHARE_TYPE_PUBLIC,
'publicUpload' => false,
'permissions' => ocs_client::SHARE_PERMISSION_READ
];
'permissions' => ocs_client::SHARE_PERMISSION_READ,
'expireDate' => $expiration
];

$response = $this->ocsclient->call('create_share', $ocsparams);
$xml = simplexml_load_string($response);
Expand Down