Merge branch 'master' of github.com:h5p/h5p-php-library

pull/38/head
Frode Petterson 2017-03-02 10:18:38 +01:00
commit 90fd9a2a28
1 changed files with 28 additions and 5 deletions

View File

@ -783,7 +783,7 @@ class H5PValidator {
} }
// The rest should be library folders // The rest should be library folders
elseif ($this->h5pF->mayUpdateLibraries()) { elseif ($this->h5pC->mayUpdateLibraries()) {
if (!is_dir($filePath)) { if (!is_dir($filePath)) {
// Ignore this. Probably a file that shouldn't have been included. // Ignore this. Probably a file that shouldn't have been included.
continue; continue;
@ -866,7 +866,7 @@ class H5PValidator {
foreach ($missingLibraries as $libString => $library) { foreach ($missingLibraries as $libString => $library) {
$this->h5pF->setErrorMessage($this->h5pF->t('Missing required library @library', array('@library' => $libString))); $this->h5pF->setErrorMessage($this->h5pF->t('Missing required library @library', array('@library' => $libString)));
} }
if (!$this->h5pF->mayUpdateLibraries()) { if (!$this->h5pC->mayUpdateLibraries()) {
$this->h5pF->setInfoMessage($this->h5pF->t("Note that the libraries may exist in the file you uploaded, but you're not allowed to upload new libraries. Contact the site administrator about this.")); $this->h5pF->setInfoMessage($this->h5pF->t("Note that the libraries may exist in the file you uploaded, but you're not allowed to upload new libraries. Contact the site administrator about this."));
} }
} }
@ -1303,7 +1303,7 @@ class H5PStorage {
* FALSE otherwise * FALSE otherwise
*/ */
public function savePackage($content = NULL, $contentMainId = NULL, $skipContent = FALSE, $options = array()) { public function savePackage($content = NULL, $contentMainId = NULL, $skipContent = FALSE, $options = array()) {
if ($this->h5pF->mayUpdateLibraries()) { if ($this->h5pC->mayUpdateLibraries()) {
// Save the libraries we processed during validation // Save the libraries we processed during validation
$this->saveLibraries(); $this->saveLibraries();
} }
@ -2765,7 +2765,7 @@ class H5PCore {
* @return bool|object Returns endpoint data if found, otherwise FALSE * @return bool|object Returns endpoint data if found, otherwise FALSE
*/ */
public function updateContentTypeCache($postData = NULL) { public function updateContentTypeCache($postData = NULL) {
$endpoint = 'http://hubendpoints/contenttypes'; $endpoint = 'http://api.h5p.org/v1/content-types';
$interface = $this->h5pF; $interface = $this->h5pF;
@ -2791,7 +2791,7 @@ class H5PCore {
$json = json_decode($data); $json = json_decode($data);
// No libraries received // No libraries received
if (!isset($json->libraries) || empty($json->libraries)) { if (!isset($json->contentTypes) || empty($json->contentTypes)) {
$interface->setErrorMessage( $interface->setErrorMessage(
$interface->t('No libraries was received from the Content Type Hub. Please try again later.') $interface->t('No libraries was received from the Content Type Hub. Please try again later.')
); );
@ -2907,6 +2907,29 @@ class H5PCore {
return $val; return $val;
} }
/**
* Check if the current user has permission to update and install new
* libraries.
*
* @param bool [$set] Optional, sets the permission
* @return bool
*/
public function mayUpdateLibraries($set = null) {
static $can;
if ($set !== null) {
// Use value set
$can = $set;
}
if ($can === null) {
// Ask our framework
$can = $this->h5pF->mayUpdateLibraries();
}
return $can;
}
} }
/** /**