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

Discussion forum for Extension Writers regarding Extension Development.
Webmasterks
Registered User
Posts: 275
Joined: Tue May 27, 2003 11:28 pm
Location: The Hague, The Netherlands

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

Post by Webmasterks »

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: Select all

{
		    "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": "[email protected]"
		        }
		    ]
		}

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: Select all

<?php
		
		namespace 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: Select all

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
User avatar
Brf
Support Team Member
Support Team Member
Posts: 53523
Joined: Tue May 10, 2005 7:47 pm
Location: {postrow.POSTER_FROM}

Re: I asked ChatGPT for an extension to prevent links in first posts. Would this work?

Post by Brf »

That is not an extension if it is telling you to edit functions_posting.php.
It is also using a permission called u_no_links_in_first_post without ever installing that permission.
User avatar
P_I
Community Team Member
Community Team Member
Posts: 2437
Joined: Tue Mar 01, 2011 8:35 pm
Location: Western Canada 🇨🇦

Re: I asked ChatGPT for an extension to prevent links in first posts. Would this work?

Post by P_I »

Allowing new members to post links is one of the best ways that I know to catch spammers. The posted link reveals their intention on your board.
Normal people… believe that if it ain’t broke, don’t fix it. Engineers believe that if it ain’t broke, it doesn’t have enough features yet. – Scott Adams
User avatar
warmweer
Jr. Extension Validator
Posts: 11658
Joined: Fri Jul 04, 2003 6:34 am
Location: Van Allen Bel ... gium

Re: I asked ChatGPT for an extension to prevent links in first posts. Would this work?

Post by warmweer »

:lol: ChatGPT is just as good at creating extensions as I am : 'nuff said.
Spelling is freeware, which means you can use it for free.
On the other hand, it is not open source, which means you cannot change it or publish it in a modified form.


Time flies like an arrow, but fruit flies like a banana.
User avatar
Mick
Support Team Member
Support Team Member
Posts: 26828
Joined: Fri Aug 29, 2008 9:49 am

Re: I asked ChatGPT for an extension to prevent links in first posts. Would this work?

Post by Mick »

A good Q&A + an activated NRU stops all the palarva.
  • "The more connected we get the more alone we become” - Kyle Broflovski© 🇬🇧
User avatar
Times Enemy
Registered User
Posts: 43
Joined: Thu Aug 11, 2022 9:43 pm

Re: I asked ChatGPT for an extension to prevent links in first posts. Would this work?

Post by Times Enemy »

I have tried using ChatGPT to write some extensions for me, and I have learned a lot of what does not work in a phpbb extension, but not much about what does work. Although, I have been able to get an extension listed in the ACP, activated, and apparently installed, then deactivated, and removed, but that is about the limits of my efforts with ChatGPT so far. It is not very keen on playing by the Tutorials. And honestly, my brain is not compatible with how the Tutorials are laid out either. So, between the two of us, we have yet to pump out a functional extension.

I did try to find an extension that is close to what I want to do, and tried reading that, but it got hairy real quick. I would rather just roll my own from the start.

All that to say, if you get ChatGPT to help you create, because it will not do it on its own quite yet, please let me know how you accomplished this miracle.

Return to “Extension Writers Discussion”