mirror of
https://github.com/DanielnetoDotCom/YouPHPTube
synced 2025-10-06 03:50:04 +02:00
API for updating profile/background image
This commit is contained in:
parent
a417717819
commit
238a6f1b10
2 changed files with 115 additions and 0 deletions
|
@ -2052,4 +2052,89 @@ if (typeof gtag !== \"function\") {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function updateUserImages($params = array()) {
|
||||||
|
|
||||||
|
$id = $this->id;
|
||||||
|
$obj = new stdClass();
|
||||||
|
|
||||||
|
// Update Background Image
|
||||||
|
if (isset($params['backgroundImg']) && $params['backgroundImg'] != '') {
|
||||||
|
|
||||||
|
$background = file_get_contents($params['backgroundImg']);
|
||||||
|
$ext = pathinfo(parse_url($params['backgroundImg'], PHP_URL_PATH), PATHINFO_EXTENSION);
|
||||||
|
$allowed = array('jpg', 'jpeg', 'gif', 'png');
|
||||||
|
if (!in_array(strtolower($ext), $allowed)) {
|
||||||
|
return "File extension error background Image, We allow only (" . implode(",", $allowed) . ")";
|
||||||
|
}
|
||||||
|
|
||||||
|
$backgroundPath = "videos/userPhoto/tmp_background{$id}.".$ext;
|
||||||
|
$oldfile = "videos/userPhoto/background{$id}.png";
|
||||||
|
$file = "videos/userPhoto/background{$id}.jpg";
|
||||||
|
|
||||||
|
if (!isset($global['systemRootPath'])) {
|
||||||
|
$global['systemRootPath'] = '../../';
|
||||||
|
}
|
||||||
|
|
||||||
|
$filePath = $global['systemRootPath'] . $backgroundPath;
|
||||||
|
|
||||||
|
$updateBackground = file_put_contents($filePath, $background);
|
||||||
|
|
||||||
|
convertImage($filePath, $global['systemRootPath'].$file, 70);
|
||||||
|
if (file_exists($filePath)) {
|
||||||
|
unlink($filePath);
|
||||||
|
}
|
||||||
|
if (file_exists($oldfile)) {
|
||||||
|
unlink($oldfile);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($updateBackground) {
|
||||||
|
$obj->background = 'Background has been updated!';
|
||||||
|
} else {
|
||||||
|
$obj->background = 'Error updating background.';
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->setBackgroundURL($file);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update Profile Image
|
||||||
|
if (isset($params['profileImg']) && $params['profileImg'] != '') {
|
||||||
|
|
||||||
|
$photo = file_get_contents($params['profileImg']);
|
||||||
|
$photoPath = "videos/userPhoto/photo{$id}.png";
|
||||||
|
|
||||||
|
if (!isset($global['systemRootPath'])) {
|
||||||
|
$global['systemRootPath'] = '../../';
|
||||||
|
}
|
||||||
|
|
||||||
|
$filePath = $global['systemRootPath'] . $photoPath;
|
||||||
|
|
||||||
|
if (file_exists($filePath)) {
|
||||||
|
unlink($filePath);
|
||||||
|
}
|
||||||
|
|
||||||
|
$updateProfile = file_put_contents($filePath, $photo);
|
||||||
|
if ($updateProfile) {
|
||||||
|
$obj->profile = 'Profile has been updated!';
|
||||||
|
} else {
|
||||||
|
$obj->profile = 'Error updating profile.';
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->setPhotoURL($photoPath);
|
||||||
|
}
|
||||||
|
|
||||||
|
$formats = "ssi";
|
||||||
|
$values[] = $this->photoURL;
|
||||||
|
$values[] = $this->backgroundURL;
|
||||||
|
$values[] = $this->id;
|
||||||
|
|
||||||
|
$sql .= "UPDATE users SET "
|
||||||
|
. "photoURL = ?, backgroundURL = ?, "
|
||||||
|
. " modified = now() WHERE id = ?";
|
||||||
|
|
||||||
|
$insert_row = sqlDAL::writeSql($sql, $formats, $values);
|
||||||
|
$obj->save = $insert_row; // create/update data for photoURL / backgroundURL
|
||||||
|
|
||||||
|
return $obj;
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1127,6 +1127,36 @@ class API extends PluginAbstract {
|
||||||
return new ApiObject("", false, $t);
|
return new ApiObject("", false, $t);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param type $parameters
|
||||||
|
* ['APISecret' mandatory for security reasons - required]
|
||||||
|
* ['user' usename of the user - required]
|
||||||
|
* ['backgroundImg' URL path of the image - optional]
|
||||||
|
* ['profileImg' URL path of the image - optional]
|
||||||
|
* @example {webSiteRootURL}plugin/API/{getOrSet}.json.php?APIName={APIName}&APISecret={APISecret}&user=admin
|
||||||
|
* @return \ApiObject
|
||||||
|
*/
|
||||||
|
public function set_api_userImages($parameters) {
|
||||||
|
global $global;
|
||||||
|
require_once $global['systemRootPath'] . 'objects/video.php';
|
||||||
|
// $obj = $this->startResponseObject($parameters);
|
||||||
|
$dataObj = $this->getDataObject();
|
||||||
|
if ($dataObj->APISecret === @$_GET['APISecret']) {
|
||||||
|
|
||||||
|
$user = new User("", $parameters['user'], false);
|
||||||
|
if (empty($user->getUser())) {
|
||||||
|
return new ApiObject("User Not defined");
|
||||||
|
}
|
||||||
|
|
||||||
|
// UPDATED USER
|
||||||
|
$updateUser = $user->updateUserImages($parameters);
|
||||||
|
|
||||||
|
return new ApiObject("", false, $updateUser);
|
||||||
|
} else {
|
||||||
|
return new ApiObject("API Secret is not valid");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class ApiObject {
|
class ApiObject {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue