Custom input box showing up at the top of a post

Discussion forum for Extension Writers regarding Extension Development.
User avatar
cancertalk
Registered User
Posts: 21
Joined: Tue Jun 12, 2018 10:51 pm
Name: Vincent Gledhill

Custom input box showing up at the top of a post

Post by cancertalk »

Hello People. I am not a coder, but, I am knowledgable enough to give this a go.

In my forum f=13 I would like an extra input box for "GKI" number, so that when posting a message into this forum, it looks something like this.
GKI Number
Message text... blah blah blah.
Please can some kind soul take a look and help me get it working. I am trying to save the world from CANCER here!

I asked chat GPT4 to write me the extension, and it gave me the following code.

Code: Select all

ext/
└── Vincent/
    └── gki/
        ├── config/
        │   └── services.yml
        ├── event/
        │   └── main_listener.php
        ├── language/
        │   └── en/
        │       └── common.php
        ├── migrations/
        │   └── v_0_1_0.php
        ├── styles/
        │   └── all/
        │       └── template/
        │           ├── posting_buttons.html
        │           └── viewtopic_body_post_row_before.html
        ├── composer.json
        └── ext.php
Here is the code for all the files I have.

composer.json

Code: Select all

{
    "name": "Vincent/gki",
    "type": "phpbb-extension",
    "description": "GKI Number Extension",
    "homepage": "https://www.metcancer.com",
    "version": "0.1.0",
    "time": "2024-06-28",
    "license": "GPL-2.0",
    "authors": [
        {
            "name": "Vincent",
            "homepage": "https://www.metcancer.com"
        }
    ],
    "require": {
        "php": ">=7.1",
        "phpbb/phpbb": ">=3.3.12"
    },
    "extra": {
        "display-name": "GKI Number Extension",
        "soft-require": {
            "phpbb/phpbb": ">=3.3.12"
        }
    }
}
ext.php

Code: Select all

{
    "name": "Vincent/gki",
    "type": "phpbb-extension",
    "description": "GKI Number Extension",
    "homepage": "https://www.metcancer.com",
    "version": "0.1.0",
    "time": "2024-06-28",
    "license": "GPL-2.0",
    "authors": [
        {
            "name": "Vincent",
            "homepage": "https://www.metcancer.com"
        }
    ],
    "require": {
        "php": ">=7.1",
        "phpbb/phpbb": ">=3.3.12"
    },
    "extra": {
        "display-name": "GKI Number Extension",
        "soft-require": {
            "phpbb/phpbb": ">=3.3.12"
        }
    }
}
services.yml

Code: Select all

services:
    Vincent.gki.listener:
        class: Vincent\gki\event\main_listener
        arguments:
            - '@request'
            - '@template'
            - '@user'
            - '@auth'
            - '@dbal.conn'
            - '@config'
        tags:
            - { name: event.listener }
main_listener.php

Code: Select all

<?php
namespace Vincent\gki\event;

use Symfony\Component\EventDispatcher\EventSubscriberInterface;

class main_listener implements EventSubscriberInterface
{
    protected $request;
    protected $template;
    protected $user;
    protected $auth;
    protected $db;
    protected $config;

    public function __construct(\phpbb\request\request_interface $request, \phpbb\template\template $template, \phpbb\user $user, \phpbb\auth\auth $auth, \phpbb\db\driver\driver_interface $db, \phpbb\config\config $config)
    {
        $this->request = $request;
        $this->template = $template;
        $this->user = $user;
        $this->auth = $auth;
        $this->db = $db;
        $this->config = $config;
    }

    static public function getSubscribedEvents()
    {
        return array(
            'core.submit_post_end' => 'add_gki_number',
            'core.posting_modify_template_vars' => 'add_gki_input_field',
            'core.viewtopic_modify_post_row' => 'display_gki_number',
        );
    }

    public function add_gki_number($event)
    {
        $forum_id = $event['forum_id'];
        if ($forum_id != 13) {
            return;
        }

        $gki_number = $this->request->variable('gki_number', '', true);

        $data = array(
            'post_id' => (int) $event['data']['post_id'],
            'user_id' => (int) $this->user->data['user_id'],
            'gki_number' => (string) $gki_number,
        );

        $sql = 'INSERT INTO ' . $this->db->sql_escape('phpbb_gki_numbers') . ' ' . $this->db->sql_build_array('INSERT', $data);
        $this->db->sql_query($sql);
    }

    public function add_gki_input_field($event)
    {
        $forum_id = $event['forum_id'];
        if ($forum_id == 13) {
            $this->template->assign_vars(array(
                'S_GKI_NUMBER_INPUT' => true,
            ));
        }
    }

    public function display_gki_number($event)
    {
        $forum_id = $event['forum_id'];
        if ($forum_id == 13) {
            $post_id = $event['post_row']['POST_ID'];
            $sql = 'SELECT gki_number FROM ' . $this->db->sql_escape('phpbb_gki_numbers') . ' WHERE post_id = ' . (int) $post_id;
            $result = $this->db->sql_query($sql);
            $gki_number = $this->db->sql_fetchfield('gki_number');
            $this->db->sql_freeresult($result);

            $event['post_row']['GKI_NUMBER'] = $gki_number;
        }
    }
}
posting_buttons.html

Code: Select all

<!-- IF S_GKI_NUMBER_INPUT -->
<div class="panel">
    <div class="inner">
        <fieldset class="fields1">
            <dl>
                <dt><label for="gki_number">{L_GKI_NUMBER}:</label></dt>
                <dd><input type="text" name="gki_number" id="gki_number" size="25" maxlength="100" value="" class="inputbox autowidth" /></dd>
            </dl>
        </fieldset>
    </div>
</div>
<!-- ENDIF -->
viewtopic_body_post_row_before.html

Code: Select all

<!-- IF GKI_NUMBER -->
<div class="gki_number">GKI Number: {GKI_NUMBER}</div>
<!-- ENDIF -->
common.php

Code: Select all

<?php
if (!defined('IN_PHPBB')) {
    exit;
}

$lang = array_merge($lang, array(
    'GKI_NUMBER' => 'GKI Number',
));
v_0_1_0.php

Code: Select all

<?php
namespace Vincent\gki\migrations;

class v_0_1_0 extends \phpbb\db\migration\migration
{
    public function effectively_installed()
    {
        return isset($this->config['gki_extension_version']) && version_compare($this->config['gki_extension_version'], '0.1.0', '>=');
    }

    static public function depends_on()
    {
        return array('\phpbb\db\migration\data\v31x\v310');
    }

    public function update_schema()
    {
        return array(
            'add_tables' => array(
                $this->table_prefix . 'gki_numbers' => array(
                    'COLUMNS' => array(
                        'post_id' => array('UINT', 0),
                        'user_id' => array('UINT', 0),
                        'gki_number' => array('VCHAR:255', ''),
                    ),
                    'PRIMARY_KEY' => 'post_id',
                ),
            ),
        );
    }

    public function revert_schema()
    {
        return array(
            'drop_tables' => array(
                $this->table_prefix . 'gki_numbers',
            ),
        );
    }

    public function update_data()
    {
        return array(
            array('config.add', array('gki_extension_version', '0.1.0')),
        );
    }
}
I'm trying to save the world of cancer by spreading the work of Professor Thomas Seyfried.
My YouTube Channel https://YouTube.com/@metcancer
My Website https://metcancer.com
My Community forum https://metcancer.com/forum
User avatar
cancertalk
Registered User
Posts: 21
Joined: Tue Jun 12, 2018 10:51 pm
Name: Vincent Gledhill

Re: Custom input box showing up at the top of a post

Post by cancertalk »

This is the error I am now getting.
The migration "\Vincent\gki\migrations\v_0_1_0" is not fulfillable, missing migration "\phpbb\db\migration\data\v31x\v310".
I'm trying to save the world of cancer by spreading the work of Professor Thomas Seyfried.
My YouTube Channel https://YouTube.com/@metcancer
My Website https://metcancer.com
My Community forum https://metcancer.com/forum
User avatar
Kailey
Community Team Leader
Community Team Leader
Posts: 4046
Joined: Mon Sep 01, 2014 1:00 am
Location: sudo rm -rf /
Name: Kailey Snay

Re: Custom input box showing up at the top of a post

Post by Kailey »

Instead of posting code, it would be helpful if you uploaded it to a VCS system (such as GitHub). ;)
cancertalk wrote: Fri Jun 28, 2024 10:24 am I asked chat GPT4 to write me the extension, and it gave me the following code
Chat GPT is not a reliable source and never will be. Basic coding is required, and I would certainly recommend you learn if you would like to develop extensions. Look at other extensions to draw inspiration of coding style.
Kailey Snay - Community Team Leader
Knowledge Base | Documentation | Community rules
If you have any questions about the rules/customs of this website, feel free to send me a PM.

My little corner of the world | Administrator @ phpBB Modders
User avatar
cancertalk
Registered User
Posts: 21
Joined: Tue Jun 12, 2018 10:51 pm
Name: Vincent Gledhill

Re: Custom input box showing up at the top of a post

Post by cancertalk »

AI will NEVER be as good as humans at coding.

Wow!

As for a VCS system, I'm really showing my ignorance now. I haven't got a clue what that is.

I'm just trying to save the world from Cancer.

I thought that might be worth a little love.

Kind Regards
Vince.
Last edited by thecoalman on Sat Jun 29, 2024 7:54 am, edited 1 time in total.
Reason: Remved links.
I'm trying to save the world of cancer by spreading the work of Professor Thomas Seyfried.
My YouTube Channel https://YouTube.com/@metcancer
My Website https://metcancer.com
My Community forum https://metcancer.com/forum
User avatar
warmweer
Jr. Extension Validator
Posts: 12179
Joined: Fri Jul 04, 2003 6:34 am
Location: somewhere in the space-time continuum

Re: Custom input box showing up at the top of a post

Post by warmweer »

cancertalk wrote: Fri Jun 28, 2024 4:31 pm As for a VCS system, I'm really showing my ignorance now. I haven't got a clue what that is.
Version Control System
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
bonelifer
Community Team Member
Community Team Member
Posts: 3639
Joined: Wed Oct 27, 2004 11:35 pm
Name: William

Re: Custom input box showing up at the top of a post

Post by bonelifer »

William Jacoby - Community Team
Knowledge Base | phpBB Board Rules | Search Customisation Database
Please don't contact me via PM or email for phpBB support .

phpBB Modders is looking for developers! If you have phpBB experience and want to join us, click here!
User avatar
Kailey
Community Team Leader
Community Team Leader
Posts: 4046
Joined: Mon Sep 01, 2014 1:00 am
Location: sudo rm -rf /
Name: Kailey Snay

Re: Custom input box showing up at the top of a post

Post by Kailey »

cancertalk wrote: Fri Jun 28, 2024 12:09 pm The migration "\Vincent\gki\migrations\v_0_1_0" is not fulfillable, missing migration "\phpbb\db\migration\data\v31x\v310"
I'm struggling with understanding this. It might be best if we start from the beginning.
  1. What are you trying to do with this extension? What is it's purpose? Saying "I'm just trying to save the world from Cancer" doesn't really tell us anything.
  2. What version of phpBB are you running? I'm guessing 3.2 or 3.3 as your forum appears to be using the font awesome (indicated by lines like this: <i class="icon fa-bars fa-fw" aria-hidden="true"></i>).
  3. Do you have any technical skills at all? If so, what are they?
  4. Depending on 1 and 3, it may be best to hire someone to make this extension for you. Feel free to post in our Wanted! forum and include as much detail as possible.
If you are still willing to learn how to create extensions, we will try to help you as much as we can.
Kailey Snay - Community Team Leader
Knowledge Base | Documentation | Community rules
If you have any questions about the rules/customs of this website, feel free to send me a PM.

My little corner of the world | Administrator @ phpBB Modders
User avatar
danieltj
Infrastructure Team Member
Infrastructure Team Member
Posts: 704
Joined: Thu May 03, 2018 9:32 pm
Location: United Kingdom
Name: Daniel James

Re: Custom input box showing up at the top of a post

Post by danieltj »

If you don’t know how to do this yourself then you should look at hiring someone to make the extension for you. Whilst your cause is very admirable, we’re all volunteers here and time is money.

You’ll need to do the following:
  • Install a migration to add a database column
  • Add a template event to include the input box on the view topic and posting page
  • Add the piece of data as a template variable to the relevant pages (view topic etc)
MY EXTENSIONS:
Verified Profiles | API | Awesome Payments

OPEN SOURCE:
Sponsor me on GitHub | Lead developer for Neptune
User avatar
cancertalk
Registered User
Posts: 21
Joined: Tue Jun 12, 2018 10:51 pm
Name: Vincent Gledhill

Re: Custom input box showing up at the top of a post

Post by cancertalk »

Kailey wrote: Fri Jun 28, 2024 5:22 pm
cancertalk wrote: Fri Jun 28, 2024 12:09 pm The migration "\Vincent\gki\migrations\v_0_1_0" is not fulfillable, missing migration "\phpbb\db\migration\data\v31x\v310"
I'm struggling with understanding this. It might be best if we start from the beginning.
  1. What are you trying to do with this extension? What is it's purpose? Saying "I'm just trying to save the world from Cancer" doesn't really tell us anything.
  2. What version of phpBB are you running? I'm guessing 3.2 or 3.3 as your forum appears to be using the font awesome (indicated by lines like this: <i class="icon fa-bars fa-fw" aria-hidden="true"></i>).
  3. Do you have any technical skills at all? If so, what are they?
  4. Depending on 1 and 3, it may be best to hire someone to make this extension for you. Feel free to post in our Wanted! forum and include as much detail as possible.
If you are still willing to learn how to create extensions, we will try to help you as much as we can.
In forum F=13 this is the "My Cancer Journey Journal" forum. For people to post how they are doing each day on Professor Thomas Seyfried's Press Pulse Protocol. See the scientific literature here https://metcancer.com/press-pulse/

It is a "Diet" drug combination and one of the main criteria is a GKI number (glucose ketone index).

So, what I want to do, is this. In that particular forum and that one only (f=13) when someone goes to post a new topic or reply to the topic it has another "input box" asking for a GKI number, the user fills that in, along with the subject.

In the subsequent thread would be posted.....
subject
GKI 2.4 (or whatever their GKI reading was)
Message body..... lorum ipsum lorum ipsum etc.

My technical skills are... I've built many websites in the past. I have done a course on udemy on building a wordpress theme from scratch.(php) I can use tools like PHPmyAdmin etc.

Input would look like this.. another input box for GKI
Image

Output to look like this
Image

I'm sorry, I can't afford to pay. I'm retired myself due to the cancer, and am trying to help other people who are suffering themselves. See the end of this video to see how passionate about the current cancer system https://youtu.be/jeV4WppmJM4

Kind Regards
Vincent
I'm trying to save the world of cancer by spreading the work of Professor Thomas Seyfried.
My YouTube Channel https://YouTube.com/@metcancer
My Website https://metcancer.com
My Community forum https://metcancer.com/forum
User avatar
GanstaZ
Registered User
Posts: 1230
Joined: Wed Oct 11, 2017 10:29 pm
Location: GZOverse

Re: Custom input box showing up at the top of a post

Post by GanstaZ »

Why do you want that number in every post? That number seems to be related to user itself and not to a specific forum and all its posts or does that number change very often, that it needs to be posted (updated) with every post?
Usus est magister optimus! phpBB Triton, GZO, Tempest (4.0 theme) & latest php environment.
When answer lies in the question, question becomes redundant!
User avatar
cancertalk
Registered User
Posts: 21
Joined: Tue Jun 12, 2018 10:51 pm
Name: Vincent Gledhill

Re: Custom input box showing up at the top of a post

Post by cancertalk »

In that specific forum f=13 that is for a person to track how they are doing on the protocol.

GKI stands for Glucose Ketone Index. Cancer feeds on sugar. The GKI is a "measure" of blood "Glucose" / "Ketones"

On the "press pulse protocol" people measure their GKI and get a number from the "app" preferably 2.0 or below. Once you are in this "zone" the cancer cells start getting hammered. You are taking one of their "fuels" away.

So, the idea is that people post to their own thread every day, and on every post it shows their GKI reading. Like in the images I made up.
I'm trying to save the world of cancer by spreading the work of Professor Thomas Seyfried.
My YouTube Channel https://YouTube.com/@metcancer
My Website https://metcancer.com
My Community forum https://metcancer.com/forum
User avatar
GanstaZ
Registered User
Posts: 1230
Joined: Wed Oct 11, 2017 10:29 pm
Location: GZOverse

Re: Custom input box showing up at the top of a post

Post by GanstaZ »

I think this topic is more suited for Extension Request forum.
Well.. as I see it, this can be achieved at least in 3 different ways. ChatGPT version is no good (it has many issues).
Is that extra input field really the best or should I say more suited option?
Usus est magister optimus! phpBB Triton, GZO, Tempest (4.0 theme) & latest php environment.
When answer lies in the question, question becomes redundant!
User avatar
cancertalk
Registered User
Posts: 21
Joined: Tue Jun 12, 2018 10:51 pm
Name: Vincent Gledhill

Re: Custom input box showing up at the top of a post

Post by cancertalk »

It is best for the user to put their GKI number in every time. The only reason to force them to do so on each post in this forum is so others that follow in their footsteps can learn. Without the number, the post is irrelevant.
I'm trying to save the world of cancer by spreading the work of Professor Thomas Seyfried.
My YouTube Channel https://YouTube.com/@metcancer
My Website https://metcancer.com
My Community forum https://metcancer.com/forum
User avatar
thecoalman
Community Team Member
Community Team Member
Posts: 6690
Joined: Wed Dec 22, 2004 3:52 am
Location: Pennsylvania, U.S.A.

<---topic icon

Post by thecoalman »

How wide is the range for the numbers? e.g. do you only need a handful of numbers or many of them.

See the heart before my post title, that's post icon and there is no reason it can't be a number. If you go into the ACP >> posting tab >> topic icons link on left. You can create the range of numbers required as images and add them if it's not some large amount.

There is also permission setting for this so you can limit it to just that forum.
“Results! Why, man, I have gotten a lot of results! I have found several thousand things that won’t work.”

Attributed - Thomas Edison
User avatar
Kailey
Community Team Leader
Community Team Leader
Posts: 4046
Joined: Mon Sep 01, 2014 1:00 am
Location: sudo rm -rf /
Name: Kailey Snay

Re: <---topic icon

Post by Kailey »

thecoalman wrote: Mon Jul 01, 2024 9:48 am that's post icon and there is no reason it can't be a number
Maybe this extension then?
Kailey Snay - Community Team Leader
Knowledge Base | Documentation | Community rules
If you have any questions about the rules/customs of this website, feel free to send me a PM.

My little corner of the world | Administrator @ phpBB Modders

Return to “Extension Writers Discussion”