Quantcast
Channel: phpBB.com
Viewing all articles
Browse latest Browse all 446

Extension Writers Discussion • I asked ChatGPT for an extension to prevent links in first posts. Would this work?

$
0
0
Hi all,

Although I run a forum for over 20 years, I'm still a n00b where it comes to extensions, writing code, etc. So I asked ChatGPT:
Write a detailed extension for my phpbb-forum that prevents putting a link in first posts for new members. Make it a step-by-step tutorial explaining where to find the files that need to be edited and which explicit code needs to be added.
It came back with this:
To create an extension for phpBB that prevents new members from posting links in their first posts, follow this detailed step-by-step tutorial:

Step 1: Extension Setup
Create Extension Directory: Inside the ext directory of your phpBB installation, create a new directory named nolinksinfirstpost .
Create Composer File: Inside the nolinksinfirstpost directory, create a composer.json file with the following content:

Code:

{    "name": "username/nolinksinfirstpost",    "type": "phpbb-extension",    "description": "Prevents new members from posting links in their first posts.",    "license": "GPL-2.0-only",    "authors": [        {            "name": "Your Name",            "email": "your@email.com"        }    ]}

Step 2: Extension Implementation
Create Extension Files:
Create a file named ext.php inside the nolinksinfirstpost directory. This file will handle registration and events.
Add the following code to ext.php :

Code:

<?phpnamespace username\nolinksinfirstpost;class ext extends \phpbb\extension\base{    public function is_enableable()    {        return true;    }    static public function install()    {        // Installation code if needed    }    static public function uninstall()    {        // Uninstallation code if needed    }    static public function enable()    {        // Enable code if needed    }    static public function disable()    {        // Disable code if needed    }}

Hook into phpBB Events:
Open the includes/functions_posting.php file in the phpBB directory.
Inside the submit_post() function, add the following code snippet before the return statement to check and prevent links in first posts:

Code:

if ($auth->acl_get('u_no_links_in_first_post') && $userdata['user_posts'] < 2) {    $message = utf8_clean_string($message);    if (preg_match("/<a\s/i", $message)) {        trigger_error("New members cannot post links in their first post.");    }}

Step 3: Testing and Deployment
Test Your Extension:
Make a test account with a new member role to verify that links cannot be posted in the first post.

Package Your Extension:
Zip the nolinksinfirstpost directory containing the ext.php file and the composer.json file.
Rename the zip file to nolinksinfirstpost.zip .
Upload the zip file to the ext directory on your phpBB server.

Enable the Extension:
Log in as an administrator on your phpBB forum.
Go to the Admin Control Panel (ACP) and navigate to Customise -> Extensions .
Find your extension named "No Links in First Post" and click Enable .

By following these steps, you should have successfully created an extension for phpBB that prevents new members from posting links in their first posts. Remember to test thoroughly and adjust the code as needed for your specific requirements.
Before I spend time on this and run the risk of messing up my forum, I'd like to hear from you guys if this could work?

Thanks in advance.

Kind regards,
Roland

Statistics: Posted by Webmasterks — Wed Mar 27, 2024 1:55 pm



Viewing all articles
Browse latest Browse all 446

Latest Images

Trending Articles





Latest Images