Skip to content

Instantly share code, notes, and snippets.

@lianglee
Created May 11, 2023 19:21
Show Gist options
  • Save lianglee/1c2fa4ef1aea09cb081bf626798e71b3 to your computer and use it in GitHub Desktop.
Save lianglee/1c2fa4ef1aea09cb081bf626798e71b3 to your computer and use it in GitHub Desktop.
components\PrivacyChanger\actions\wall\post\privacy_change.php
<?php
/**
* Open Source Social Network
* @link https://www.opensource-socialnetwork.org/
* @package Privacy Changer
* @author Michael Zülsdorff <[email protected]>
* @copyright (C) Michael Zülsdorff
* @license GNU General Public License https://www.gnu.de/documents/gpl-2.0.en.html
*/
$user = ossn_loggedin_user();
$id = input('post');
$ossnwall = new OssnWall();
$post = $ossnwall->GetPost($id);
//Text disappear if we don't encode it again. We need to find a good solution though for OSSN posts edits :)
$json = $post->description;
$data = json_decode($json, true);
$text = ossn_restore_new_lines($data['post']);
$text = ossn_input_escape($text);
$data['post'] = $text;
$rejson = json_encode($data, JSON_UNESCAPED_UNICODE);
$post->description = "{$rejson}";
if ($user && $post && ossn_is_xhr()) {
header('Content-Type: application/json');
if (($post->type != 'user') || ($post->type == 'user' && !$user->canModerate())) {
if (($post->type != 'user') || ($post->type == 'user' && $post->poster_guid != $user->guid && $post->owner_guid != $user->guid)) {
echo json_encode(array(
'success' => 0,
'error' => ossn_print('com:privacy:changer:access:denied'),
));
exit;
}
}
$post->data = new stdClass;
if ($post->access == OSSN_PUBLIC) {
$post->data->access = OSSN_FRIENDS;
$icon = 'fa-users';
$title = ossn_print('title:access:3');
$menu = ossn_print("com:privacy:changer:change:privacy:3");
} else {
if ($post->access == OSSN_FRIENDS) {
$post->data->access = OSSN_PUBLIC;
$icon = 'fa-globe-americas';
$title = ossn_print('title:access:2');
$menu = ossn_print("com:privacy:changer:change:privacy:2");
}
}
if ($post->save()) {
echo json_encode(array(
'success' => 1,
'icon' => $icon,
'title' => $title,
'menu' => $menu,
));
exit;
} else {
echo json_encode(array(
'success' => 0,
'error' => ossn_print('com:privacy:changer:change:failed'),
));
exit;
}
}
ossn_trigger_message(ossn_print('com:privacy:changer:access:denied'), 'error');
redirect(REF);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment