Need help with a component

Dominik L Posted in Component Development 6 months ago

I am about to create a component

My goal is, to disable photo upload on wall and profile for users who are not verified OR admin

ossn_com.php

<?php

function disablephoto_init(){
    ossn_extend_view('js/opensource.socialnetwork', 'disablephoto/js'); 
}
ossn_register_callback('ossn', 'init', 'disablephoto_init');

and my js.php file in plugins folder:

// Function to check if the user is verified
function isVerifiedUser(params) {
    if (params.user) {
        // Check if the user is an admin or marked as a verified user
        if (params.user.isAdmin() || (params.user.is_verified_user !== undefined && params.user.is_verified_user === true)) {
            return true; // User is verified
        }
    }
    return false; // User is not verified
}

// Check if the user is not verified and apply CSS rules
if (!isVerifiedUser(params)) {
    // Applying the first CSS rule
    var uploadPhotoElements = document.querySelectorAll('.upload-photo');
    for (var i = 0; i < uploadPhotoElements.length; i++) {
        uploadPhotoElements[i].style.display = 'none';
    }

    // Applying the second CSS rule
    var ossnWallPhotoElements = document.querySelectorAll('.ossn-wall-container .controls .ossn-wall-photo');
    for (var j = 0; j < ossnWallPhotoElements.length; j++) {
        ossnWallPhotoElements[j].style.display = 'none';
    }
}

But it is not working, can someone please help?

Replies
German Dominik L Replied 5 months ago

@Arsalan

you gave me this code

ossn_register_callback('action', 'load', function($c, $t, $p){
        if($p['action'] == 'ossn/photos/add'){
            //your other condition here 
            ossn_trigger_message("Photos upload not allowed");
            redirect(REF);
        }
});

How can I extend it for the WallCOntainer?

I tried

if($p['action'] == 'ossn/wall/photos/add'){

and

if($p['action'] == 'wall/photos/add'){

can you help me, please?

German Dominik L Replied 5 months ago

Okay, I found it

You need to logout and login, to make it work after a user got verified

<?php
/**
 * Open Source Social Network
 *
 * @package   Dominik Lieger
 * @author    Dominik Lieger
 * @version   1.0.0
 * @license   GPL v2 https://www.gnu.org/licenses/old-licenses/gpl-2.0.html
 * @link      https://www.example.com
 */

function disablephoto_init() {
    if (ossn_isLoggedin() && !ossn_isAdminLoggedin()) {
        $user = ossn_loggedin_user();

        // Überprüfe, ob der Benutzer verifiziert ist
        if ((isset($user->is_verified_user) && !$user->is_verified_user) || !isset($user->is_verified_user)) {

            // Entferne die Foto-Upload-Menüs
            ossn_unregister_menu_item('photo', 'photo', 'wall/container/controls/home');
            ossn_unregister_menu_item('photo', 'photo', 'wall/container/controls/user');
            ossn_unregister_menu_item('photo', 'photo', 'wall/container/controls/group');

            // Callback für Foto-Upload-Aktion registrieren
            ossn_register_callback('action', 'load', function($c, $t, $p) {
                if (ossn_isLoggedin()) { // Überprüfe, ob der Benutzer eingeloggt ist
                    if ($p['action'] == 'ossn/photos/add') {
                        // Zeige die Nachricht an, dass der Foto-Upload nicht erlaubt ist
                        ossn_trigger_message(ossn_print('photos:upload:not:allowed'), 'error');
                        redirect(REF); // Weiterleitung zur vorherigen Seite
                    }
                }
            });
        }
    }
}

// Registriere die Hauptinitialisierungsfunktion
ossn_register_callback('ossn', 'init', 'disablephoto_init');
?>
German Dominik L Replied 5 months ago

okay, i don't get it

can you please help? :/

German Dominik L Replied 5 months ago

nevermind, i guessed I found it

German Dominik L Replied 5 months ago

hey, regarding the album stuff

can I somehow use ossn_unregister_menu_item to disable album creation?

I know you gave me some ideas but I don't understand it :/

Indonesian Arsalan Shah Replied 6 months ago

The third option may be simply reject photos upload and give error message

    ossn_register_callback('action', 'load', function($c, $t, $p){
            if($p['action'] == 'ossn/photos/add'){
                //your other condition here 
                ossn_trigger_message("Photos upload not allowed");
                redirect(REF);
            }
    });
German Dominik L Replied 6 months ago

Thank youuuuu!

Indonesian Arsalan Shah Replied 6 months ago

These are static buttons you may override the entire page handler for photos and may add condition there

https://github.com/opensource-socialnetwork/opensource-socialnetwork/blob/master/components/OssnPhotos/ossn_com.php#L496-L502

or

Extend photos/pages/albums and see if any useful parameter inside it and then using js inside extended option to hide the button. I am afraid i am not available right now to write a code.

German Dominik L Replied 6 months ago

Okay thanks

But a question:

How can I disable uploading photo to album when unverified? Because people can bypass my idea with creating an album and uploading photos there

Indonesian Arsalan Shah Replied 6 months ago

If it is working then leave it.