Need help with a component

Dominik L Posted in Component Development 4 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 4 months ago

Can you maybe explain why my code should not work?

I test it is with an administrator account, with a normal account which is not verified and with a verified account and then every case it is working

Indonesian Arsalan Shah Replied 4 months ago

You are right i updated the code maybe you can try that.

German Dominik L Replied 4 months ago

But your condition was wrong too, because it was disabled for everyone, even administrators and verified users, but the function should only be disabled if non-verified Users

Indonesian Arsalan Shah Replied 4 months ago

Your condition is wrong and may not work for everyone. :)

German Dominik L Replied 4 months ago

I changed it like that:

function disablephoto_init(){
    $user = ossn_loggedin_user();

    if(!ossn_isAdminLoggedin() && (!isset($user->is_verified_user) || $user->is_verified_user == false)){
        // Nur deaktivieren, wenn der Benutzer kein Administrator ist und nicht verifiziert ist
        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');
    }   
}
ossn_register_callback('ossn', 'init', 'disablephoto_init');
?>

Now it seems to work

But one question:

how do I use the "ossnunregistermenu_item" for the upload button on profile picture?

Indonesian Arsalan Shah Replied 4 months ago

Try following (edit it if it didn't work)

<?php
function disablephoto_init() {
        if(ossn_isLoggedin() && !ossn_isAdminLoggedin()) {
                $user = ossn_loggedin_user();
                if((isset($user->is_verified_user) && $user->is_verified_user == false) || !isset($user->is_verified_user)) {
                        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');
                }
        }
}
ossn_register_callback('ossn', 'init', 'disablephoto_init');
German Dominik L Replied 4 months ago

Can you maybe help me?

Indonesian Arsalan Shah Replied 4 months ago

Then the code won't work what your js shows is impossible

German Dominik L Replied 4 months ago

I search for the right classes and strings and tell ChatGPT to use them

German Dominik L Replied 4 months ago

Yes, mostly it works, this time I am helpless

Premium Version

Due to the many requests in the past for additonal features and components we have decided to develope a premium version. Features like Hashtags, Videos, Polls, Events, Stories, Link Preview, etc included in it.

$199 (Life Time)
Learn More

Other Questions