Do you know if there is a mod Limit Guest View...

Started by Panoulis64, June 02, 2025, 01:59:43 PM

Previous topic - Next topic

Panoulis64

Do you know if there is a mod that does the following:
Limit the content of topics for guests, e.g. to 50 word or phrase.
Add a message "Become a member or log in to see more"
From the administration, the admin sets the number of word or phrase.

Doug Heffernan

Quote from: Panoulis64 on June 02, 2025, 01:59:43 PMDo you know if there is a mod that does the following:
Limit the content of topics for guests, e.g. to 50 word or phrase.
Add a message "Become a member or log in to see more"
From the administration, the admin sets the number of word or phrase.

What version of Smf do you need this for? I have coded such a mod, but it's for smf 2.0.x.

https://custom.simplemachines.org/index.php?mod=4169

Panoulis64

Good evening and thanks for the answer. I have smf 2.1.4
Yes, I saw it yesterday while searching. It has some differences from what I was thinking. I want it to read a certain number of words of each text, e.g. 40-50 words and then for more to ask for login or registration.

Doug Heffernan

Quote from: Panoulis64 on June 03, 2025, 11:40:41 AMGood evening and thanks for the answer. I have smf 2.1.4
Yes, I saw it yesterday while searching. It has some differences from what I was thinking. I want it to read a certain number of words of each text, e.g. 40-50 words and then for more to ask for login or registration.

I take it that this is a request for such a mod and not a question if such mod exists. In that case, is this a paid request or a free one?

Panoulis64

And of course it is a question, from someone who since 2009, has been managing a forum for his patriots and their history.
This mod, there is no possibility of payment, concerns voluntary action.
Thank you for your time, to answer.

Panoulis64

For information, I put this code that a friend gave me in Display.php and it temporarily solved the issue. I'm sure a mod would help better.

// ---------------------------------------------------------
    // ΠΕΡΙΟΡΙΣΜΟΣ ΚΕΙΜΕΝΟΥ ΣΕ Ν ΛΕΞΕΙΣ ΓΙΑ ΕΠΙΣΚΕΠΤΕΣ
    global $user_info, $modSettings;

    if (!empty($message['body']) && !empty($user_info['is_guest']))
    {
        // Ανάγνωση limit (λέξεις) από τη βάση, default = 50 αν δεν υπάρχει
        $limit = isset($modSettings['limit_guest_words']) ? (int) $modSettings['limit_guest_words'] : 50;

        // 1) Αφαιρούμε HTML tags
        $plain = strip_tags($message['body']);
        // 2) Συμπιέζουμε πολλαπλά whitespace (space, newline, tab) σε 1 κενό
        $plain = preg_replace('/\s+/', ' ', $plain);
        // 3) Σπάμε σε πίνακα λέξεων
        $words = preg_split('/\s+/u', trim($plain));

        if (count($words) > $limit)
        {
            // Κρατάμε τις πρώτες $limit λέξεις
            $firstN = array_slice($words, 0, $limit);
            $short = implode(' ', $firstN);
            // Συνεχές μήνυμα (χωρίς επιπλέον newline)
            $short .= '... <div class="infobox">Κάνετε<a href="index.php?action=login">είσοδο</a>ή<a href="index.php?action=signup">γίνετε μέλος</a>για να δείτε περισσότερα...</div>';
            preg_replace('/\s+/', ' ', $short);
            $message['body'] = $short;
        }
    }
    // ---------------------------------------------------------

Kindred

Personally, I think this is a very bad idea.

When I visit a site that does this, I leave the site and never come back
Слaва
Украинi

Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

Advertisement: