PHP (NextCloud) events/listeners best practices

To give a bit on context, I am building an app in nextcloud and I am going to shoot & listen to a lot for events. I have got 2 options to tackle this problem.

1. Creating a lot of events & listeners;

For every single action within a service, I can shoot out an event which will have a listener attached. This means that I will get a lot of events and listeners within the system. Example;

$dispatcher->dispatchTyped(new reorderEvent());
$dispatcher->dispatchTyped(new assignEvent());

2. Creating 1 event for a model with actions;

I can also create just 1 event that will pass through just an action string/enum. This will reduce the amount of event files within the application. Example;

class ActionEnum: string 
{
    case REORDER;
    case ASSIGN;
}

$dispatcher->dispatchTyped(new updatedEvent(ActionEnum::REORDER));
$dispatcher->dispatchTyped(new updatedEvent(ActionEnum::ASSIGN));

Now the multi-million dollar question is, which would be considered best-practice in the long run? Or is there another solution that is even better to use?

Why is my XCLASSes action for the EXT:sf_event_mgt EventController ignored?

I’m trying to add a button that allows users to subscribe to my event calender via a webcall:// link. I use type=9819 to trigger the function.

I can‘t get my icalAction to work, it just gets ignored and typo3 uses the listAction from the extension instead.

Im using typo3 13.4 and sitepackage. I would like to manage the output in a fluid template

My folder structure is:

/packages
└── studilife
    ├── Classes
    │    └── Controller
    │        └── EventController.php
    ├── Configuration
    │   └── Sets
    │       └── Studilife
    │           └── TyposScript
    │               └── setup.typoscript
    ├── Resources
    │   └── Private
    │       └── Extensions
    │           └── SfEventMgt
    │               └── Templates
    │                   └── Event
    │                       └── Ical.html
    └── ext_localconf.php

This is my code so far:

ext_localconf.php:

$GLOBALS['TYPO3_CONF_VARS']['SYS']['Objects'][DERHANSENSfEventMgtControllerEventController::class] = [
    'className' => StudentStudilifeControllerEventController::class,
];

TYPO3CMSExtbaseUtilityExtensionUtility::configurePlugin(
    'SfEventMgt',
    'Event',
    [
        DERHANSENSfEventMgtControllerEventController::class => 'list,detail,register,ical'
    ],
    []
);

setup.typoscript:

plugin.tx_sfeventmgt {
    view {
        templateRootPaths {
            100 = EXT:studilife/Resources/Private/Extensions/SfEventMgt/Templates/
        }
        partialRootPaths {
            100 = EXT:studilife/Resources/Private/Extensions/SfEventMgt/Partials/
        }
        layoutRootPaths {
            100 = EXT:studilife/Resources/Private/Extensions/SfEventMgt/Layouts/
        }
    }
    settings {
        calendar{
            showWeekNumber = 0
        }
    }
}

pageEventICalendar = PAGE
pageEventICalendar {
    typeNum = 9819
    settings.format = txt
    config {
        disableAllHeaderCode = 1
        xhtml_cleaning = none
        admPanel = 0
        metaCharset = utf-8
        locale_all = en_EN
        additionalHeaders.10.header = Content-Type:text/calendar;charset=utf-8
        disablePrefixComment = 1
        linkVars >

    }

    10 = USER
    10 {
        userFunc = TYPO3CMSExtbaseCoreBootstrap->run
        extensionName = SfEventMgt
        pluginName = Event
        vendorName = DERHANSEN
        controller = Event
        action = ical
    }
}

eventController.php:

<?php
namespace StudentStudilifeController;

class EventController extends DERHANSENSfEventMgtControllerEventController
{
    public function icalAction()
    {
        $events = $this->eventRepository->findAll();
        $this->view->assign('events', $events);

        $this->view->setFormat('txt');
        header('Content-Type: text/calendar; charset=utf-8');
        header('Content-Disposition: attachment; filename="events.ics"');
    }
}

Im trying to get my Action to be recognized by typo3. The typoscript works fine so far, but the eventController.php is just ignored. Its my first time trying to change the behaviour of an extension, so i probably miss something very basic. I tryed to use this official typo3 documentation: https://docs.typo3.org/m/typo3/reference-coreapi/main/en-us/ApiOverview/Xclasses/Index.html.

Thanks for your help

Showing dynamic or different menus on wordpress not working in my theme

On my WordPress page, there’s a primary menu that shows up at the header of all pages, but I want to show a different set of menus for pages in the route /tech-products.

Based on my research on this site, adding the following to my function.php and then setting up the menu in Appearance → Menus → Manage Locations is expected to work, but it doesn’t work.

function register_custom_menus() {
    register_nav_menus(array(
        'primary' => 'Primary Menu',
        'tech_products_menu' => 'Tech Products Menu',
    ));
}
add_action('init', 'register_custom_menus');

How to properly display form data using shortcode in a custom WordPress plugin?

I’m creating a custom WordPress plugin that includes a contact form rendered using a shortcode.

Here’s my current code:

function custom_contact_form() {
  ob_start();
  ?>
  <form method="post" action="">
    <input type="text" name="name" required>
    <input type="email" name="email" required>
    <input type="submit" name="submit" value="Send">
  </form>
  <?php
  return ob_get_clean();
}
add_shortcode('contact_form', 'custom_contact_form');

I tried:

  • Using $_POST to capture form data inside the function
  • Adding action="<?php echo esc_url($_SERVER['REQUEST_URI']); ?>" to the form
  • Checking if the shortcode runs correctly in a page

But I’m not sure how to process the form submission inside the shortcode, or how to show the submitted data.

Filament filter on another table column

I’ve searched for this answer but didn’t find any, so I’m here to ask. I’m using Filament 3.2 on Laravel 12. I have a RelationManager based on a table tournament_players that has a relation on players table. I have to show and filter the results of tournament_players based on the column sex in players table that has only 2 possible values: M and F. In the columns i’ve defined the relationship and everything works

TablesColumnsTextColumn::make('player.sex')
                    ->label(__('Sex'))
                    ->sortable()
                    ->searchable(),

But when i get to filters I cannot make it work. That’s the basic

TablesFiltersSelectFilter::make('player.sex')
                    ->label(__('Sex'))
                    ->options([
                        'M' => __('Male'),
                        'F' => __('Female'),
                    ])
                    ->default(null),

Using it like this it’s not working because the query to list results doesn’t load the relation as expected. Adding the relationship like this:

->relationship('player', 'sex')

is not working also because the result is to overwrite my options with a list of M and F taken from all the players in the tournament_players table. Methods like modifyQueryUsing or getSearchResultUsing don’t give better results. What I’m doing wrong?

How to get inserted model or collection when using fillAndInsert which just returns a boolean?

$transactionsData is an array, and I want the id from transaction id from the transaction model for each item and assign it to the details to insert the id to the transaction item table, how can I achieve it in Laravel 12 fillAndInsert method, I tried tap method to use but it also returns boolen value.

$transactions = Transaction::fillAndInsert($transactionsData);

$transactionDetailsData = array_map(function ($detail, $index) use ($transactions) {
    $detail['transaction_detail_id'] = $transactions[$index]['id'];
    return $detail;
}, $transactionDetailsData, array_keys($transactionDetailsData));

TransactionItem::fillAndInsert($transactionDetailsData);

Json response not rendering to html table, only shows raw json data

I am returning json response from index method of my controller class.

use AppHttpControllersController;
use IlluminateHttpRequest;
use AppModelsAdminServicesFinish;

class FinishController extends Controller
{
    public function index()
    {
        $finishes = Finish::select('id','name')->where('status', 1)->orderBy('id','desc')->get();
        return response()->json(['finishes'=>$finishes]);
    }
}

My route function:

Route::get('admin_finish', [FinishController::class, 'index'])->name('admin_finish.index');

In my blade php file, I am trying to render this json response to html table. But it’s only showing raw json data.

@extends('admin.index')
@section('admin_content')
    <section>
                    <table id="example2" class="table table-striped table-hover">
                        <thead>
                            <tr>
                                <th>S.No.</th>
                                <th>Finish Name</th>
                                <th>Actions</th>
                            </tr>
                        </thead>
                        <tbody id="i_tbl_finish">
                        </tbody>
                    </table>
    </section>
@endsection

@section('js_scirpts')
    <script>
        $(document).ready(function() {
            $.ajaxSetup({
                headers: {
                    'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                }
            });

            fetchData();

            function fetchData() {
                    $.ajax({
                        type: "GET",
                        url:  "{{ route('admin_finish.index') }}",
                        dataType: 'json'
                        success: function(data) {
                            let rows = '';
                            $.each(data, function(key, finishes) {
                                rows += `
                                    <tr>
                                        <td>${finishes.id}</td>
                                        <td>${finishes.name}</td>
                                        <td>
                                            <button data-id="${finishes.id}" class="btn btn-primary btn-sm edit-post"><i class="fa fa-edit"></i></button>
                                            <button data-id="${finishes.id}" class="btn btn-danger btn-sm delete-post"><i class="fa fa-trash"></i></button>
                                        </td>
                                    </tr>
                                `;
                            });
                            $('#i_tbl_finish').html(rows);
                        },
                        error: function(error) {
                            console.log(error);
                        }
                    });
            }
        });
    </script>
@endsection

But I am getting only raw json data. It seems the ajax function is not working or may be issues with route. But I can not trace out the reason for this. Why is it so? Please see the attached image of my output.

output as raw json data

Nginx location with alias redirect to root [closed]

I need to place a site inside existed project. site.com – this is the main site, site.com/site2/ this is the second one.

  1. When I visite site.com it’s show me /index.php [OK]
  2. When site.com/site2/ it’s show me /site2/web/index.php [OK]
  3. But when site.com/site2/qwe it redirect back to /index.php [FAIL]. I need /site2/web/index.php

The project structure is:

/
/site2/
/site2/web/
/site2/web/index.php
/index.php

Nginx site conf

server {
    root /var/www/site;
    index index.php index.html index.htm;
    ...

    location / {
        try_files $uri $uri/ =404;
    }

    location ~ .php$ {
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/run/php/php7.4-fpm.sock;
    }

    location /site2/ {
        alias /var/www/site/site2/web/;

        add_header X-Location-Visited true always;

        try_files $uri $uri/ /index.php$is_args$args;
        # I'd tried without any result
        # try_files $uri $uri/ /site2/index.php$is_args$args;
        # try_files $uri $uri/ /site2/web/index.php$is_args$args;

        location ~ .php$ {
            include snippets/fastcgi-php.conf;
            fastcgi_param SCRIPT_FILENAME $request_filename;
            fastcgi_pass unix:/run/php/php7.4-fpm.sock;
        }
    }
}

snippets/fastcgi-php.conf

# regex to split $uri to $fastcgi_script_name and $fastcgi_path
fastcgi_split_path_info ^(.+?.php)(/.*)$;

# Check that the PHP script exists before passing it
try_files $fastcgi_script_name =404;

# Bypass the fact that try_files resets $fastcgi_path_info
# see: http://trac.nginx.org/nginx/ticket/321
set $path_info $fastcgi_path_info;
fastcgi_param PATH_INFO $path_info;

fastcgi_index index.php;
include fastcgi.conf;

How to convert PNG image to JPEG using GD and imagejpeg without displaying in browser or saving to file system? [closed]

There are answers on SO about converting an image to a JPEG using PHP’s imagejpeg and either displaying in browser or saving to disk such as this one but I can’t find way to convert to JPEG without displaying or saving so it merely stays in memory without the extra overhead of saving to disk or displaying.

The use case is that the code is in an API endpoint that receives a request from a mobile device, sends a request to one API that returns a PNG file in the form of a string and then must send a JPEG file to a second API that only accepts JPEG files before returning the final result to the user.

While accomplishing these tasks, time is of the essence. Displaying the image in a background thread would be absurd and a waste of resources as would saving it to disk. All I need to do is convert the PNG file to a JPEG file but imagejpeg seems to have the added behavior of outputting the image or saving it.

The code where I receive the image as a PNG string and then must convert it into a JPEG image is;

$response = "xxx"; //png image from an API in the form of string
$image = imagecreatefromstring($response);//convert to in memory image. this line of code works perfectly

imagejpeg($image);//This converts to jpeg and displays file in browser--this displays to browser. I don't want to display it
imagejpeg($image, 'output.jpg', 100); // variation of imagejpeg that saves the file to disk same as imagejpeg($image)--I don't want to save it to disk
imagejpeg($image, NULL,100);//displays to browser. This is the top-voted but not accepted answer in question linked to.

Does imagejpeg have an option to simply change png to jpeg without displaying in a browser or saving to disk?

Note this has nothing to do with compressing files or with converting the image file into a string as in the question referenced. That question is about turning an image into a string. My situation is the exact opposite; I receive the image as a string from the first API and convert it to a file in memory without a problem using imagecreatefromstring($response).

My question is how to convert the PNG image to JPEG efficiently within my API. I don’t want the script to time out or waste resources or possibly crash due to unnecessary activity such as displaying or saving to disk.

Logged User gets recorded in Database when instead I intend to record a financial donor in laravel and laragon

I am working on a website and i needed to record the contributions of members of that organisation in the database. And usually the logged in user can be different from the donor. However, each time I add a new contribution, it records the logged user id in the DB instead of the donor’s id. I have used dd($request->donor_user_id) in the controller to see the id being sent to the controller and it matches that of the donor. However, when I save it to the DB, I see the logged in use id instead.

Everything looks fine for me,yet it does not work. Please what could be causing this issue? See codes below.

The migration/table

public function up(): void
{
    Schema::create('church_parishioner_support_incomes', function (Blueprint $table) {
        $table->id();
        $table->integer('cause_id');
        $table->integer('donor_id');
        $table->integer('is_org_member')->default(0);
        $table->integer('organisation_id')->default(1);
        $table->integer('committee_id')->nullable();
        $table->integer('subactivity_id')->nullable();
        $table->float('amount');
        $table->float('paid');
        $table->float('balance');
        $table->string('comment')->nullable();
        $table->integer('created_by');
        $table->timestamps();
    });

The controller

public function store(Request $request, String $slug){
    $request->validate([
        'cause_id'=>['required', 'integer'],
        'donor_user_id'=>['required', 'integer'],
        'amount'=>['required', 'numeric'],
        'organisation_id'=>['required', 'integer'],
        'paid'=>['required', 'numeric'],
        'balance'=>['required', 'numeric'],
        'comment'=>['nullable'],
    ]);
    //  dd($request->donor_user_id);
    $user=User::findOrFail($request->user);
 
    $income = new ChurchParishionerSupportIncome();
    $income->donor_id=$request->donor_user_id;
    $income->cause_id=$request->cause_id;
    $income->is_org_member=1;
    $income->amount=$request->amount;
    $income->paid=$request->paid;
    $income->balance=$request->balance;
    $income->comment=$request->comment;
    $income->organisation_id=$request->organisation_id;
    $income->created_by=$user;
    $income->save();
   
    toastr('Income saved successfully', 'success');
    return redirect()->route('org.finance.orgmembers-supports.income',['slug'=>$slug, 'user'=>$user]);
}

The route

Route::post('/portal/dashboard/organisation/{slug}/finances/members/members-support-incomes/store', [OrgMembersSupportIncomeController::class, 'store'])->name('org-finance.members-supports.income.store');

The View

<section class="section"> 
<div class="mb-3">
  <a href="{{ route('org.finance.orgmembers-supports.income', [$organisation->slug, 'user'=>$user->id]) }}" class="btn bg-primary custom-txt-bcolor"><i class="fa fa-arrow-left"></i>  
    Go Back</a>
</div>

<div class="row">
  <h5>{{ $income?"Edit Members Support Income Record":"Add Members Support Incomes" }}</h5>
    <div class="col-12 col-md-12 col-lg-12">
      <div class="card card-primary">
        <div class="card-body">
              @if($income !==null)
              <form action="{{ route('org-finance.members-supports.income.update', [$organisation->slug, $income->id, 'user'=>$user->id] ) }}" method="POST" >
              @method('PUT')
              @else
            <form action="{{ route('org-finance.members-supports.income.store', [$organisation->slug, 'user'=>$user->id]) }}" method="POST" >
              @endif
              @csrf

              <div class="form-group">
                <label>Project/Cause</label>
                <select class="form-control select2" name="cause_id">
                  <option value="">Select project/cause</option>
                  @foreach ($causes as $cause )
                    <option {{ $income?$income->cause_id==$cause->id?"selected":"":"" }} value="{{ $cause->id }}">{{ $cause->name }}</option>    
                  @endforeach
                </select>
            </div>

            <div class="form-group">
              <label>Member</label>
              <select class="form-control select2" name="donor_user_id">
                <option value="">Select member</option>
                @foreach ($registeredMembers as $member )
                  <option {{ $income?$income->user_id==$member->user_id?"selected":"":"" }} value="{{ $member->user_id }}">{{ $member->user->first_name }} {{ $member->user->middle_name?$member->user->middle_name:"" }} {{ $member->user->last_name }}</option>    
                @endforeach
              </select>
          </div>
          
              <div class="form-group">
                <label>Amount donated (N)</label>
                <input name="amount" type="number" class="form-control donated_amt" value="{{ $income?$income->amount:"" }}">
              </div>
              <div class="form-group">
                  <label>Paid (N)</label>
                  <input name="paid" type="number" class="form-control paid_amt" value="{{ $income?$income->paid:"" }}">
              </div>
              <div class="form-group">
                  <label>Balance (N)</label>
                  <input name="balance" type="number" class="form-control balance_amt" value="{{ $income?$income->balance:"" }}" readonly>
                </div>
                <div class="form-group">
                  <label>Comment</label>
                  
                  <div class="form-floating">
                    <textarea name="comment" class="form-control" placeholder="Leave a comment here" id="floatingTextarea2" style="height: 100px">{!! $income?$income->comment:"" !!}</textarea>
                  </div>
                </div>
                <input name="organisation_id" type="hidden" class="form-control" value="{{$organisation->id}}" readonly>
              
              <button type="submit" class="btn btn-primary btn_submit">{{ $income?"Update":"Save" }}</button>
            </form>
          </div>
        </div>
      </div>
    </div>
  </div>

How to save PayPal details for the future payment same like card in Stripe session checkout page?

I’m using Stripe Checkout Session for the payment in my laravel project. I’ve included code like while creating checkout session:

'saved_payment_method_options' => ['payment_method_save' => 'enabled'],

I’m trying to do payment with the PayPal it’s not showing me checkbox for save for the future purchase. But when I’m using card it’s showing me checkbox for save it for future purchase. Also address is not showing if I’ve already filled one time. For that I’ve added like:

'customer_update' => [
  'name' => 'auto',
  'address' => 'auto',
],
'billing_address_collection' => 'required',

Also, I’ve question like can I use PayPal as auto payment like card:

$organization->invoicePrice(
$stripePriceId,
$quantity,
[
  'currency' => Config::get('cashier.currency'),
  'default_tax_rates' => $taxObject,
);

Where Organization model has LaravelCashierBillable trait.

Thanks…

Why is in_array not working when both the needle and haystack are very definitely exactly the same? [closed]

This one is a real head scratcher. I’ve exhausted every possible avenue with Gemini AI and even that can’t seem to solve this one.

So, I have this code which I’ve set up as a test:

$nz_array = array('NZ','nz');
$users_countrycode = do_shortcode('[userip_location type="countrycode"]');
echo("Needle = "" . $users_countrycode . ""<br />");
var_dump($nz_array);
echo("<br />Haystack = "" . $nz_array[0] . """);
if(is_string($users_countrycode)){
  echo("<br />Needle is string");
}
if(is_string($nz_array[0])){
  echo("<br />Haystack is string");
}
if($users_countrycode == $nz_array[0]){
  echo("<br />Yes, " . $users_countrycode . " is equal to " . $nz_array[0]);
}
if(in_array($users_countrycode,$nz_array)){
  echo('<br />YES, is in array!');
}

The resulting output is:

Needle = "NZ"
array(2) { [0]=> string(2) "NZ" [1]=> string(2) "nz" }
Haystack = "NZ"
Needle is string
Haystack is string

Note that both the needle and the haystack result as “NZ” and are both strings (note also that I have forced the code to display quotation marks on each side of the resulting “NZ” values to show that there are no hidden spaces, etc), and yet the lines,

if($users_countrycode == $nz_array[0])

and,

if(in_array($users_countrycode,$nz_array))

both result in no output at all! Therefore $users_countrycode does not equal $nz_array[0] and $users_countrycode is not being found in the $nz_array array.

I cannot figure out why. This always used to work perfectly, but has somehow suddenly stopped working for some obscure reason.

Any ideas?

Apache RewriteRule causes unexpected 301 redirect and EUC-KR encoding — project files are UTF-8

I’m experiencing an issue with URL encoding and unexpected redirects on an Apache server.

  • My .htaccess uses RewriteRule to implement human-readable URLs in Korean.
  • All project files are saved in UTF-8.
  • Friendly URLs include UTF-8–encoded Korean characters (e.g. /products/과자/치토스 which is /snacks/Cheetos in English)
  • The actual server-side pages are English-only (e.g. /product_view.php)

Problem:

When I request a UTF-8–encoded URL, Apache responds with a 301 redirect to the same URL — but percent-encoded in EUC-KR, resulting in a unreadable address bar. For example:

Request: /products/과자/치토스 Response: 301 → /products/%B0%FA%C0%DA%C4%A1%C5%E4%BD%BA

address bar: mydomain/products/%B0%FA%C0%DA%C4%A1%C5%E4%BD%B which is unreadable.

The encoding shift seems to be happening during the redirect, even though the source files, HTML headers, and URL are all UTF-8. This causes character corruption and confusing behavior for users.

What I’ve verified:

  • All .php, .js, and .html files are UTF-8 without BOM
  • Apache’s default charset is not explicitly set — I tried AddDefaultCharset UTF-8 in .htaccess but the redirect issue persists
  • RewriteRule itself does not include [R=301], but the redirect still occurs. Here is my RewriteRule code

RewriteRule ^products/([^/]+)/([^/]+) /products/product_view.php?product=$2 [L]

Question:

  • Why is Apache sending a 301 with EUC-KR encoding?
  • How can I ensure that UTF-8 URLs are preserved and served correctly without charset corruption or unwanted redirect?

Thanks in advance for any guidance!

Laravel 12.x, subdomain and Mail::send() error

I’m developing an application where the admin section is accessible via a subdomain like admin.mysite.test.

Everything works fine except sending emails with login credentials for users manually added by the administrator.
The email is sent correctly and is visible with services like Mailtrap, but when redirecting after sending, a 404 is generated, and the debugbar reports that the users route doesn’t exist.

If I make the admin area accessible via mysite.test/admin instead of the subdomain, everything works.

Any ideas?

Below is the resource method for inserting into the database.

     /**
     * Store a newly created resource in storage.
     */
    public function store(UserFormRequest $request)
    {
        $user = new User($request->validated());

        if ($file = $request->validated('image')) {

            $path = $this->upload($file, $this->folder, $this->width, $this->height);

            $user->image = $path;

        }

        $save = $user->save();

        if ($save) {

            $user->generated_password = $request->validated('password');

            Mail::to($user->email)->send(new NewUserCreated($user));
            
            return redirect()->route('admin.users.index')->with('success-message', 'Record inserito con successo.');

        } else {

            return back()->withInput()->with('error-message', 'Qualcosa è andato storto.');

        }
    }