PHP code example of philippoehrlein / kirby-push-notifications

1. Go to this page and download the library: Download philippoehrlein/kirby-push-notifications library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

philippoehrlein / kirby-push-notifications example snippets


return [
    'philippoehrlein.push-notifications' => [
        'vapid' => [
            'publicKey'  => 'your-vapid-public-key',
            'privateKey' => 'your-vapid-private-key',
            'subject'    => 'https://yourdomain.com',
        ],
        'channels' => [
            'panel' => [
                [
                    'value' => 'note-approval',
                    'text' => 'Note Approval',
                    'info' => 'Get informed when a note is waiting for approval',
                ]
            ],
            'website' => [
                [
                    'value' => 'notes',
                    'text'  => 'Notes',
                    'info'  => 'Receive new notes',
                ],
                [
                    'value' => 'photos',
                    'text'  => 'Photography',
                    'info'  => 'Receive the latest Photo series',
                ],
            ]
        ],
        // optional: change DB location
        // 'db' => [
        //     'name' => 'push_notifications',
        //     'dir'  => 'site/push-notifications',
        // ],
        // optional: Web Push default options (TTL, contentType, batchSize, etc.)
        // 'webPush' => [
        //     'contentType' => 'application/json',
        //     'TTL' => 3600,
        //     'urgency' => null,
        //     'topic' => null,
        //     'batchSize' => 1000,
        //     'requestConcurrency' => 100,
        // ],
    ],
];

// site/config/config.php
return [
  'philippoehrlein.push-notifications' => [
    'channels' => [
      [
        'value' => 'news',
        'text'  => 'News',
        'info'  => 'General website updates',
      ],
      [
        'value' => 'notes',
        'text'  => 'Notes',
        'info'  => 'New notes and articles',
      ],
    ],
  ],
];

 snippet('kpn-dialog', slots: true) 

 snippet('kpn-dialog', [
    'headline'    => 'Your Headline',
    'description' => 'Choose the channels you want to receive.',
    // 'channels'   => [['value' => 'news', 'text' => 'News', 'info' => '…']],
], slots: true) 

// site/config/config.php
'hooks' => [
    'page.changeStatus:after' => function ($newPage, $oldPage) {
        if ($newPage->intendedTemplate() === 'note' && $newPage->status() === 'listed') {
            kirby()->trigger('philippoehrlein.push-notifications.send-to-many', [
                'payload' => [
                    'message' => [
                        'title' => kirby()->site()->title()->value(),
                        'body'  => 'New note: ' . $newPage->title()->value(),
                        'data'  => ['url' => $newPage->url()],
                    ],
                    'channel' => 'notes',
                    'options' => ['urgency' => 'normal'],
                ],
            ]);
        }
    },
],