Mecha CMS

Code snippet collection for developers.

Poll Notification

Author: Taufik Nurrohman · 98 Views

Tweet

Send email notification on every user interaction to the poll widget.

Requires poll extension.

Hook::set([
    'on.poll.set',
    'on.poll.reset'
// $a: current data path
// $b: previous data path
// $c: [$key, $value, $data]
], function($a, $b, $c) {
    $d = Path::D($a);
    if ($path = File::exist([
        $d . '.page',
        $d . '.archive'
    ])) {
        $page = new Page($path);
        $anchor = HTML::a($page->title, $page->url);
        $user = '<strong>' . Get::ip() . '</strong>';
        $key = '<em>' . Request::post('title', $c[0]) . '</em>';
        $from = 'user@from.com'; // site email address
        $to = 'user@to.com'; // your email address
        $subject = 'Poll Notification';
        if ($c[1]) {
            if ($c[1] === -1) {
                $message = '<p>' . $user . ' was cancelled the poll.</p>';
            } else {
                $message = '<p>Poll value of ' . $key . ' was increased by ' . $user . '.</p>';
            }
            $message .= '<p><strong>Page:</strong> ' . $anchor . '</p>';
            Message::send($from, $to, $subject, $message);
        }
    }
});

Replace $from and $to value with valid email addresses.

0 Comments

No comments yet.