What is the correct class for username on wall?

Dominik L Posted in Technical Support 3 months ago

I try to create a component showing some info beside the username on wall

I already managed to show the information in profile using .ossn-profile .user-fullname in JS

var element = document.querySelector('.ossn-profile .user-fullname');

But I cannot find the correct class for the wall

I already tried .ossn-wall-item .meta .user a

and

something like

var element = document.querySelector('[data-username=\"{$user->username}\"]');

and

var element = document.querySelector('.ossn-wall [data-username=\"{$user->username}\"]');

and also

var elements = document.querySelectorAll('.ossn-wall .ossn-output-user-url[data-username=\"{$user->username}\"]');

And yes, I am using ChatGPT and it works well, but I cannot find the correct css for username on wall

Replies
German Dominik L Replied 3 months ago

Thank you @Arsalan, the url.php file helped me

Indonesian Arsalan Shah Replied 3 months ago

Callbacks must not echo anything this will break your site.

You need to edit wallpost template or look this https://github.com/opensource-socialnetwork/opensource-socialnetwork/blob/master/system/plugins/default/output/user/url.php

German Dominik L Replied 3 months ago

I tried

this:

function ossn_wall_age_display($callback, $type, $params) {
    if (isset($params['post']->poster_guid)) {
        $user = ossn_user_by_guid($params['post']->poster_guid);
        if ($user && !empty($user->birthdate)) {
            $age = calculate_age($user->birthdate);

            echo "<script>
                document.addEventListener('DOMContentLoaded', function() {
                    var users = document.querySelectorAll('.ossn-wall-item .meta .user a');
                    users.forEach(function(userElement) {
                        if (userElement.textContent.trim() === '{$user->fullname}') {
                            userElement.setAttribute('data-age', '{$age}');
                            userElement.setAttribute('data-birthdate', '{$user->birthdate}');
                            if ({$age}) {
                                userElement.textContent += ' (' + {$age} + ')';
                            }
                        }
                    });
                });
            </script>";
        }
    }
}

this:

function ossn_wall_age_display($callback, $type, $params) {
    if (isset($params['post']->poster_guid)) {
        $user = ossn_user_by_guid($params['post']->poster_guid);
        if ($user && !empty($user->birthdate)) {
            $age = calculate_age($user->birthdate);

            echo "<script>
                document.addEventListener('DOMContentLoaded', function() {
                    var users = document.querySelectorAll('.ossn-wall .ossn-output-user-url');
                    users.forEach(function(userElement) {
                        if (userElement.textContent.trim() === '{$user->fullname}') {
                            userElement.setAttribute('data-age', '{$age}');
                            userElement.setAttribute('data-birthdate', '{$user->birthdate}');
                            if ({$age}) {
                                userElement.textContent += ' (' + {$age} + ')';
                            }
                        }
                    });
                });
            </script>";
        }
    }
}

and this:

function ossn_wall_age_display($callback, $type, $params) {
    if (isset($params['post']->poster_guid)) {
        $user = ossn_user_by_guid($params['post']->poster_guid);
        if ($user && !empty($user->birthdate)) {
            $age = calculate_age($user->birthdate);

            echo "<script>
                document.addEventListener('DOMContentLoaded', function() {
                    var users = document.querySelectorAll('.ossn-output-user-url');
                    users.forEach(function(userElement) {
                        if (userElement.textContent.trim() === '{$user->fullname}') {
                            userElement.setAttribute('data-age', '{$age}');
                            userElement.setAttribute('data-birthdate', '{$user->birthdate}');
                            if ({$age}) {
                                userElement.textContent += ' (' + {$age} + ')';
                            }
                        }
                    });
                });
            </script>";
        }
    }
}
Indonesian Arsalan Shah Replied 3 months ago

But class is correct. Make sure and verify that of your newseed have these classes for user link or not

User url have class .ossn-output-user-url

var Users = $('.ossn-output-user-url');
German Dominik L Replied 3 months ago

and yes, I have to use chatgpt, because i am not a programmer and i have nobody to help me

Rafael is not available anymore and there are no other programmers for me, so I have to help myself and 90% of the time chatgpt works

German Dominik L Replied 3 months ago

I also tried ossn-output-user-url but with no success

Indonesian Arsalan Shah Replied 3 months ago

Because you are using chatgpt. Is it so hard to simply right click and see browser console for correct class? :) simply open browser console and see correct class.

enter image description here