1

Topic: Turn IMG tags off

by individual forum. Has anyone thought about anything like this? Some forums I want only discussion, others I would like to make available for pictures but I dont want pictures uploaded to my server. How hard would it be to make a check for each forum- img on or off?



Thanks!

Re: Turn IMG tags off

Sounds like a decent candidate for a mod, if anything.

It wouldn't be too hard... maybe creating a new column in the forums table (like useimg or something) set as an integer, 1 for images allowed and 0 for images not allowed. At the top of viewtopic.php it could redefine $pun_config['p_message_img_tag'] = $res['useimg'] based on the information in that column.

Or maybe people could just link to their images. wink

I don't HAVE a signature, ok?

3 (edited by bbaweb 2006-03-19 21:15)

Re: Turn IMG tags off

I have a mod for you

##   Mod title:  Switch Images off in a Forum.
##   Mod version:  1.0 Beta
##   Works on PunBB:  1.2.*
##   Release date:  2006-03-18
##   Author:  Peter Shave - test.oziweb.org
##   Description:  Allows images to be turned off in a forum.
##   Affected files:  admin_forum.php
##                        view_topic.php
##                        include/parser.php
##   Affects DB:  Yes
##                    Add field no_images to forums table.
##                    type tinyint 1 default value =0             
##   Notes:  No
##   Update Notes:  No update available from old version.
##
##   DISCLAIMER:  Please note that "mods" are not officially supported by
##                    PunBB. Installation of this modification is done at your
##                    own risk. Backup your forum database and any and all
##                    applicable files before proceeding.


#---------[ 1. OPEN ]

    admin_forums.php

#---------[ 2. Find (about line 170)]

    // Start with the forum details
    $forum_name = trim($_POST['forum_name']);
    $forum_desc = pun_linebreaks(trim($_POST['forum_desc']));
    $cat_id = intval($_POST['cat_id']);
    $sort_by = intval($_POST['sort_by']);

#---------[ 3. ADD AFTER ]

    $no_images = intval($_POST['no_images']);

#---------[ 4. FIND (about line 182)]

    $db->query('UPDATE '.$db->prefix.'forums SET forum_name=\''.$db->escape($forum_name).'\', forum_desc='.$forum_desc.', redirect_url='.$redirect_url.', sort_by='.$sort_by.', cat_id='.$cat_id.' WHERE id='.$forum_id) or error('Unable to update forum', __FILE__, __LINE__, $db->error());

#---------[ 5. Comment out above line and add below ]

    $db->query('UPDATE '.$db->prefix.'forums SET forum_name=\''.$db->escape($forum_name).'\', forum_desc='.$forum_desc.', redirect_url='.$redirect_url.', sort_by='.$sort_by.', cat_id='.$cat_id.' ,no_images='.$no_images.' WHERE id='.$forum_id) or error('Unable to update forum', __FILE__, __LINE__, $db->error());

#---------[ 4. FIND ]

    // Fetch forum info
    $result = $db->query('SELECT id, forum_name, forum_desc, redirect_url, num_topics, sort_by, cat_id FROM '.$db->prefix.'forums WHERE id='.$forum_id) or error('Unable to fetch forum info', __FILE__, __LINE__, $db->error());

#---------[ 5. COMMENT OUT ABOVE LINE AND ADD BELOW ]

    // Fetch forum info
    $result = $db->query('SELECT id, forum_name, forum_desc, redirect_url, num_topics, sort_by, cat_id, no_images FROM '.$db->prefix.'forums WHERE id='.$forum_id) or error('Unable to fetch forum info', __FILE__, __LINE__, $db->error());

#---------[ 6. FIND  (about line 280)]

    <tr>
        <th scope="row">Sort topics by</th>
        <td>
        <select name="sort_by" tabindex="4">
        <option value="0"<?php if ($cur_forum['sort_by'] == '0') echo ' selected="selected"' ?>>Last post</option>
        <option value="1"<?php if ($cur_forum['sort_by'] == '1') echo ' selected="selected"' ?>>Topic start</option>
        </select>
        </td>
    </tr>

#---------[ 7. ADD AFTER ]

    <tr>
        <th scope="row">Turn images off</th>
        <td>
        <select name="no_images" tabindex="5">
        <option value="0"<?php if ($cur_forum['no_images'] == '0') echo ' selected="selected"' ?>>No</option>
        <option value="1"<?php if ($cur_forum['no_images'] == '1') echo ' selected="selected"' ?>>Yes</option>
        </select>
        </td>
    </tr>

###########################################################################################

#---------[ 8. OPEN ]

    viewtopic.php

#---------[ 9. FIND ]

    // Fetch some info about the topic
    if (!$pun_user['is_guest'])
        $result = $db->query('SELECT t.subject, t.closed, t.num_replies, t.sticky, f.id AS forum_id, f.forum_name, f.moderators, fp.post_replies, s.user_id AS is_subscribed FROM '.$db->prefix.'topics AS t INNER JOIN '.$db->prefix.'forums AS f ON f.id=t.forum_id LEFT JOIN '.$db->prefix.'subscriptions AS s ON (t.id=s.topic_id AND s.user_id='.$pun_user['id'].') LEFT JOIN '.$db->prefix.'forum_perms AS fp ON (fp.forum_id=f.id AND fp.group_id='.$pun_user['g_id'].') WHERE (fp.read_forum IS NULL OR fp.read_forum=1) AND t.id='.$id.' AND t.moved_to IS NULL') or error('Unable to fetch topic info', __FILE__, __LINE__, $db->error());
    else
        $result = $db->query('SELECT t.subject, t.closed, t.num_replies, t.sticky, f.id AS forum_id, f.forum_name, f.moderators, fp.post_replies, 0 FROM '.$db->prefix.'topics AS t INNER JOIN '.$db->prefix.'forums AS f ON f.id=t.forum_id LEFT JOIN '.$db->prefix.'forum_perms AS fp ON (fp.forum_id=f.id AND fp.group_id='.$pun_user['g_id'].') WHERE (fp.read_forum IS NULL OR fp.read_forum=1) AND t.id='.$id.' AND t.moved_to IS NULL') or error('Unable to fetch topic info', __FILE__, __LINE__, $db->error());

    if (!$db->num_rows($result))
        message($lang_common['Bad request']);

    $cur_topic = $db->fetch_assoc($result);
    
#---------[ 10. REPLACE WITH ]

    // Fetch some info about the topic
    if (!$pun_user['is_guest'])
        $result = $db->query('SELECT f.no_images, t.subject, t.closed, t.num_replies, t.sticky, f.id AS forum_id, f.forum_name, f.moderators, fp.post_replies, s.user_id AS is_subscribed FROM '.$db->prefix.'topics AS t INNER JOIN '.$db->prefix.'forums AS f ON f.id=t.forum_id LEFT JOIN '.$db->prefix.'subscriptions AS s ON (t.id=s.topic_id AND s.user_id='.$pun_user['id'].') LEFT JOIN '.$db->prefix.'forum_perms AS fp ON (fp.forum_id=f.id AND fp.group_id='.$pun_user['g_id'].') WHERE (fp.read_forum IS NULL OR fp.read_forum=1) AND t.id='.$id.' AND t.moved_to IS NULL') or error('Unable to fetch topic info', __FILE__, __LINE__, $db->error());
    else
        $result = $db->query('SELECT f.no_images, t.subject, t.closed, t.num_replies, t.sticky, f.id AS forum_id, f.forum_name, f.moderators, fp.post_replies, 0 FROM '.$db->prefix.'topics AS t INNER JOIN '.$db->prefix.'forums AS f ON f.id=t.forum_id LEFT JOIN '.$db->prefix.'forum_perms AS fp ON (fp.forum_id=f.id AND fp.group_id='.$pun_user['g_id'].') WHERE (fp.read_forum IS NULL OR fp.read_forum=1) AND t.id='.$id.' AND t.moved_to IS NULL') or error('Unable to fetch topic info', __FILE__, __LINE__, $db->error());
    if (!$db->num_rows($result))
        message($lang_common['Bad request']);

    $cur_topic = $db->fetch_assoc($result);
    $no_images = $cur_topic['no_images'];

#---------[ 11. FIND ]

    // Perform the main parsing of the message (BBCode, smilies, censor words etc)
    $cur_post['message'] = parse_message($cur_post['message'], $cur_post['hide_smilies']);

#---------[ 12. REPLACE WITH ]

    // Perform the main parsing of the message (BBCode, smilies, censor words etc)
    $cur_post['message'] = parse_message($cur_post['message'], $cur_post['hide_smilies'], $no_images);

###########################################################################################

#---------[ 13. OPEN ]

    include/parser.php

#---------[ 14. FIND ]

    // Parse message text
    //
    function parse_message($text, $hide_smilies)

#---------[ 15. REPLACE WITH ]

    // Parse message text
    //
    function parse_message($text, $hide_smilies,$no_images='0')

#---------[ 16. FIND ]

        if ($pun_config['p_message_img_tag'] == '1')
        {
//            $text = preg_replace('#\[img\]((ht|f)tps?://)([^\s<"]*?)\.(jpg|jpeg|png|gif)\[/img\]#e', 'handle_img_tag(\'$1$3.$4\')', $text);
            $text = preg_replace('#\[img\]((ht|f)tps?://)([^\s<"]*?)\[/img\]#e', 'handle_img_tag(\'$1$3\')', $text);
        }

#---------[ 17. REPLACE WITH ]

    if ($no_images != '1')
    {
        if ($pun_config['p_message_img_tag'] == '1')
        {
//            $text = preg_replace('#\[img\]((ht|f)tps?://)([^\s<"]*?)\.(jpg|jpeg|png|gif)\[/img\]#e', 'handle_img_tag(\'$1$3.$4\')', $text);
            $text = preg_replace('#\[img\]((ht|f)tps?://)([^\s<"]*?)\[/img\]#e', 'handle_img_tag(\'$1$3\')', $text);
        }
    }
    else
    {
        $text = preg_replace('#\[img\]((ht|f)tps?://)([^\s<"]*?)\[/img\]#e', '', $text);
    }

#---------[ ADD FIELD TO DATABASE ]

Do not forget to add a new field to the forums table.
field = no_images
type = tinyint
length=1
default = 0

#---------[ END OF MOD ]

4 (edited by TFD 2006-03-18 12:55)

Re: Turn IMG tags off

I just replied over on punres! Thanks! Im trying it out now.

5

Re: Turn IMG tags off

hmm doesnt seem to be working. I turned imgs on in permissions then went to the forum and  went  to "turn images off?" and set it to YES and saved. When I go back it is reset to NO. DOes this in each forum that I change. Always resets to NO.

6 (edited by TFD 2006-03-18 21:01)

Re: Turn IMG tags off

wait I had reuploaded my original code but it didnt show. So I went back and this is what My code shows:


        if ($pun_config['p_message_img_tag'] == '1')
        {
//            $text = preg_replace('#\[img\]((ht|f)tps?://)([^\s<"]*?)\.(jpg|jpeg|png|gif)\[/img\]#e', 'handle_img_tag(\'$1$3.$4\')', $text);
            $text = preg_replace('#\[img\]((ht|f)tps?://)([^\s<"]*?)\[/img\]#e', 'handle_img_tag(\'$1$3\')', $text);
        }


You say to look for:

if ($pun_config['p_message_img_tag'] == '1')
    {
        $text = preg_replace('#\[img\]((ht|f)tps?://)([^\s<"]*?)\.(jpg|jpeg|png|gif)\[/img\]#e', 'handle_img_tag(\'$1$3.$4\',\'right\')', $text);
    }


There is a difference between what comes default in mine and what you say to  look for, an extra line of code with the line you want me to replace is // out.

Please advise!! Thanks

Re: Turn IMG tags off

TFD wrote:

wait I had reuploaded my original code but it didnt show. So I went back and this is what My code shows:


        if ($pun_config['p_message_img_tag'] == '1')
        {
//            $text = preg_replace('#\[img\]((ht|f)tps?://)([^\s<"]*?)\.(jpg|jpeg|png|gif)\[/img\]#e', 'handle_img_tag(\'$1$3.$4\')', $text);
            $text = preg_replace('#\[img\]((ht|f)tps?://)([^\s<"]*?)\[/img\]#e', 'handle_img_tag(\'$1$3\')', $text);
        }


You say to look for:

if ($pun_config['p_message_img_tag'] == '1')
    {
        $text = preg_replace('#\[img\]((ht|f)tps?://)([^\s<"]*?)\.(jpg|jpeg|png|gif)\[/img\]#e', 'handle_img_tag(\'$1$3.$4\',\'right\')', $text);
    }


There is a difference between what comes default in mine and what you say to  look for, an extra line of code with the line you want me to replace is // out.

Please advise!! Thanks

Hi Sorry code you have as quoted above is correct ie two lines of code. Leave your code as is.
I modified the parser code at this point to allow images to be aligned left or right for web pages.

Re: Turn IMG tags off

TFD wrote:

hmm doesnt seem to be working. I turned imgs on in permissions then went to the forum and  went  to "turn images off?" and set it to YES and saved. When I go back it is reset to NO. DOes this in each forum that I change. Always resets to NO.

You need to add the field in the forum database through your server control panel and myphpadmin. See the last of the install description.

9 (edited by TFD 2006-03-19 01:28)

Re: Turn IMG tags off

I did change the database. The problem was in the parser.php where the code was different and I uploaded the original over the modified file but forgot to save. It auto saved once I closed it and when I reopened it later it gave no errors but just reset to NO always. Now I tried the install_mod you sent and it doesnt work becauser I did in fact change the database before I made any changes originally.  SO now I go back and make the parser.php change maunally and it still saves "turn images off? NO" and when I try to display and image with  it shows nothing, the pictures arent wotrking.

Thanks!

10 (edited by TFD 2006-03-19 01:47)

Re: Turn IMG tags off

Ok Im going to change the database and all the php files back to original.

11

Re: Turn IMG tags off

TFD wrote:

Ok Im going to change the database and all the php files back to original.

Hi I missed part of the mod see the mod code above I have added

#
#---------[ 6. FIND ]
#
    // Fetch forum info
    $result = $db->query('SELECT id, forum_name, forum_desc, redirect_url, num_topics, sort_by, cat_id FROM '.$db->prefix.'forums WHERE id='.$forum_id) or error('Unable to fetch forum info', __FILE__, __LINE__, $db->error());
    if (!$db->num_rows($result))
        message($lang_common['Bad request']);
#
#---------[ 7. REPLACE WITH ]
#

    // Fetch forum info
    $result = $db->query('SELECT id, forum_name, forum_desc, redirect_url, num_topics, sort_by, cat_id, no_images FROM '.$db->prefix.'forums WHERE id='.$forum_id) or error('Unable to fetch forum info', __FILE__, __LINE__, $db->error());
    if (!$db->num_rows($result))
        message($lang_common['Bad request']);

This picks up the value of the no_images from the database.
This mod does work.

12 (edited by TFD 2006-03-19 02:05)

Re: Turn IMG tags off

OK I got it to work. One thing though. admin/forums/allow images no matter which I choose (yes or no) then save, when I go back it is always set to no even if I changed it. Unlike the radio buttions under permissions that stay on yes or no for IMG tags.


But I dont care! It works and thats all I care about! Thanks bbaweb! Now I can turn img tags off or on in any forum! You rock!







*Admin you can remove all my posts in here. All I needed to do was install the install_mod.no_images.php and make the changes listed above.

13 (edited by TFD 2006-03-19 03:48)

Re: Turn IMG tags off

will you be making the install_mod.no_images.php available to everyone? Makes it a lot easier!

14 (edited by TFD 2006-03-19 02:28)

Re: Turn IMG tags off

Awesome. Got the code change in, now it shows correctly "show img YES or NO"


Thanks!

15 (edited by MrMister 2006-03-19 19:27)

Re: Turn IMG tags off

On parser.php instead of:

function parse_message($text, $hide_smilies, $no_images)

you should use:

function parse_message($text, $hide_smilies, $no_images = '0')

Otherwise you'll get errors from all the other functions that call parse_message() with only 2 parameters.

16

Re: Turn IMG tags off

Thank you for your help.
I have added the correction to the code above.

17

Re: Turn IMG tags off

What would I do if I wanted the topic creator to be able to post Img tags in the topic first post? smile