1431
Lupin
Re: wgGallery 1.10 ready for testing
  • 2020/3/28 11:06

  • Lupin

  • Just popping in

  • Posts: 92

  • Since: 2007/6/1 2


Running to test it



1432
goffy
How to implement a notification for comments
  • 2020/3/28 7:08

  • goffy

  • Just can't stay away

  • Posts: 535

  • Since: 2010/12/27


You want to get a notification if someone makes a comment?

In this example you can see the implementation in module wgGallery

1) Adapt xoops_version.php
First step:
you have to check whether there is a callback function defined or not
// Comment callback functions
$modversion['comments']['callbackFile']        = 'include/comment_functions.php';
$modversion['comments']['callback']['approve'] = 'wggalleryCommentsApprove';
$modversion['comments']['callback']['update']  = 'wggalleryCommentsUpdate';


if not please as the definition to xoops_version.php

Second step:
You have to add the notification options, which you want to have. In wgGallery we have the option to get a notification of a comment
a) in any case
// Global Events Image commented
$modversion['notification']['event'][] = [
            
'name'          => 'img_comment_all',
            
'category'      => 'global',
            
'admin_only'    => 0,
            
'title'         => _MI_WGGALLERY_GLOBAL_IMG_COMMENT_NOTIFY,
            
'caption'       => _MI_WGGALLERY_GLOBAL_IMG_COMMENT_NOTIFY_CAPTION,
            
'description'   => '',
            
'mail_template' => 'global_img_comment_notify',
            
'mail_subject'  => _MI_WGGALLERY_GLOBAL_IMG_COMMENT_NOTIFY_SUBJECT,
        ];


b) or if an image of a specific album have been commented
// Album Events Image commented
$modversion['notification']['event'][] = [
            
'name'          => 'image_comment',
            
'category'      => 'albums',
            
'admin_only'    => 0,
            
'title'         => _MI_WGGALLERY_ALBUMS_IMG_COMMENT_NOTIFY,
            
'caption'       => _MI_WGGALLERY_ALBUMS_IMG_COMMENT_NOTIFY_CAPTION,
            
'description'   => '',
            
'mail_template' => 'global_img_comment_notify',
            
'mail_subject'  => _MI_WGGALLERY_ALBUMS_IMG_COMMENT_NOTIFY_SUBJECT,
        ];



2) Language files
add the defines to your language file modinfo.php
define('_MI_WGGALLERY_GLOBAL_IMG_COMMENT_NOTIFY''Notify me about new comments for images');
define('_MI_WGGALLERY_GLOBAL_IMG_COMMENT_NOTIFY_CAPTION''Notify me about comments for images');
define('_MI_WGGALLERY_GLOBAL_IMG_COMMENT_NOTIFY_SUBJECT''Notification about comments for an image');
define('_MI_WGGALLERY_ALBUMS_IMG_COMMENT_NOTIFY''Notify me about new comments for images in this album');
define('_MI_WGGALLERY_ALBUMS_IMG_COMMENT_NOTIFY_CAPTION''Notify me about comments for images in this album');
define('_MI_WGGALLERY_ALBUMS_IMG_COMMENT_NOTIFY_SUBJECT''Notification about new comment for an image');



3) Adapt include/comment_functions.php
In any case a comment is sent and approved xoops with call the callback function wggalleryCommentsApprove($comment)
As a parameter you get the comment object with all necessary information
Therefore we need only to add the call of notification handler
$helper XoopsModulesWggalleryHelper::getInstance();
// send notifications
$imgId               $comment->getVar('com_itemid');
$imageObj            $helper->getHandler('Images')->get($imgId);
$albId               $imageObj->getVar('img_albid');
$tags                = [];
$tags['IMAGE_NAME']  = $imageObj->getVar('img_name');
$tags['IMAGE_URL']   = XOOPS_URL '/modules/' $GLOBALS['xoopsModule']->getVar('dirname') . '/images.php?op=show&img_id=' $imgId '&alb_id=' $albId;
$tags['ALBUM_URL']   = XOOPS_URL '/modules/' $GLOBALS['xoopsModule']->getVar('dirname') . '/albums.php?op=show&alb_id=' $albId;
$notificationHandler xoops_getHandler('notification');
$notificationHandler->triggerEvent('global'0'img_comment_all'$tags, [], $comment->getVar('com_modid'));
$notificationHandler->triggerEvent('albums'$albId'img_comment'$tags);


4) Add notification template to language file

Add a notification template to language/english/mail_template (or in your language file directory).
Use the name you defined in xoops_version.php, in our example:
'mail_template' => 'global_img_comment_notify'


Thats all :)



1433
Mamba
Re: wgGallery 1.10 ready for testing
  • 2020/3/27 22:45

  • Mamba

  • Moderator

  • Posts: 11375

  • Since: 2004/4/23


The new comment notifications work! Nice job, Goffy!

Congratulations!
Support XOOPS => DONATE
Use 2.5.10 | Docs | Modules | Bugs



1434
goffy
Re: wgGallery 1.10 ready for testing
  • 2020/3/27 20:50

  • goffy

  • Just can't stay away

  • Posts: 535

  • Since: 2010/12/27


Hi Pino

can you please test last version from github?

Dont forget to adapt .\wggallery\language\italian\mail_template\global_img_comment_notify.tpl



1435
goffy
Re: wgGallery 1.10 ready for testing
  • 2020/3/26 6:44

  • goffy

  • Just can't stay away

  • Posts: 535

  • Since: 2010/12/27


Hi Michael

thank you
I will check it



1436
Mamba
Re: wgGallery 1.10 ready for testing
  • 2020/3/25 22:30

  • Mamba

  • Moderator

  • Posts: 11375

  • Since: 2004/4/23


In SmartFAQ in xoops_version.php you have this code:

// Comments
$modversion['hasComments']          = 1;
$modversion['comments']['itemName'] = 'faqid';
$modversion['comments']['pageName'] = 'faq.php';
// Comment callback functions
$modversion['comments']['callbackFile']        = 'include/comment_functions.php';
$modversion['comments']['callback']['approve'] = 'smartfaq_com_approve';
$modversion['comments']['callback']['update']  = 'smartfaq_com_update';
// Notification
$modversion['hasNotification']             = 1;
$modversion['notification']['lookup_file'] = 'include/notification.inc.php';
$modversion['notification']['lookup_func'] = 'smartfaq_notify_iteminfo';

$modversion['notification']['category'][] = [
    
'name'           => 'global_faq',
    
'title'          => _MI_SF_GLOBAL_FAQ_NOTIFY,
    
'description'    => _MI_SF_GLOBAL_FAQ_NOTIFY_DSC,
    
'subscribe_from' => ['index.php''category.php''faq.php'],
];


I think, that's the way to implement it....
Support XOOPS => DONATE
Use 2.5.10 | Docs | Modules | Bugs



1437
Mamba
Re: wgGallery 1.10 ready for testing
  • 2020/3/25 22:07

  • Mamba

  • Moderator

  • Posts: 11375

  • Since: 2004/4/23


I just checked - so the code itself is in the /include/notifications_functions.php around line 192:

if ($module->getVar('hascomments')) {
        
$com_config $module->getInfo('comments');
        if (!empty(
$category['item_name']) && $category['item_name'] == $com_config['itemName']) {
            if (!
is_dir($dir XOOPS_ROOT_PATH '/language/' $xoopsConfig['language'] . '/mail_template/')) {
                
$dir XOOPS_ROOT_PATH '/language/english/mail_template/';
            }
            
$mail_template_dir $dir;

            include_once 
$GLOBALS['xoops']->path('include/comment_constants.php');
            
$config_handler xoops_getHandler('config');
            
$com_config     $config_handler->getConfigsByCat(0$module_id);
            if (!
$enabled_only) {
                
$insert_comment true;
                
$insert_submit  true;
            } else {
                
$insert_comment false;
                
$insert_submit  false;
                switch (
$com_config['com_rule']) {
                    case 
XOOPS_COMMENT_APPROVENONE:
                        
// comments disabled, no comment events
                        
break;
                    case 
XOOPS_COMMENT_APPROVEALL:
                        
// all comments are automatically approved, no 'submit'
                        
if (!$override_comment) {
                            
$insert_comment true;
                        }
                        break;
                    case 
XOOPS_COMMENT_APPROVEUSER:
                    case 
XOOPS_COMMENT_APPROVEADMIN:
                        
// comments first submitted, require later approval
                        
if (!$override_comment) {
                            
$insert_comment true;
                        }
                        if (!
$override_commentsubmit) {
                            
$insert_submit true;
                        }
                        break;
                }
            }
            if (
$insert_comment) {
                
$event = array(
                    
'name'              => 'comment',
                    
'category'          => $category['name'],
                    
'title'             => _NOT_COMMENT_NOTIFY,
                    
'caption'           => _NOT_COMMENT_NOTIFYCAP,
                    
'description'       => _NOT_COMMENT_NOTIFYDSC,
                    
'mail_template_dir' => $mail_template_dir,
                    
'mail_template'     => 'comment_notify',
                    
'mail_subject'      => _NOT_COMMENT_NOTIFYSBJ);
                if (!
$enabled_only || notificationEventEnabled($category$event$module)) {
                    
$event_array[] = $event;
                }
            }
            if (
$insert_submit) {
                
$event = array(
                    
'name'              => 'comment_submit',
                    
'category'          => $category['name'],
                    
'title'             => _NOT_COMMENTSUBMIT_NOTIFY,
                    
'caption'           => _NOT_COMMENTSUBMIT_NOTIFYCAP,
                    
'description'       => _NOT_COMMENTSUBMIT_NOTIFYDSC,
                    
'mail_template_dir' => $mail_template_dir,
                    
'mail_template'     => 'commentsubmit_notify',
                    
'mail_subject'      => _NOT_COMMENTSUBMIT_NOTIFYSBJ,
                    
'admin_only'        => 1);
                if (!
$enabled_only || notificationEventEnabled($category$event$module)) {
                    
$event_array[] = $event;
                }
            }
        }
    }
Support XOOPS => DONATE
Use 2.5.10 | Docs | Modules | Bugs



1438
Mamba
Re: wgGallery 1.10 ready for testing
  • 2020/3/25 21:54

  • Mamba

  • Moderator

  • Posts: 11375

  • Since: 2004/4/23


I'm not sure about the documentation, but it seems like SmartFAQ had it implemented, as they point out in this Q&A
And if you look there - they have an option to subscribe to new comments, so check out the code in SmartFAQ

If you figure that out, please share your solution....
Support XOOPS => DONATE
Use 2.5.10 | Docs | Modules | Bugs



1439
goffy
Re: wgGallery 1.10 ready for testing
  • 2020/3/25 21:40

  • goffy

  • Just can't stay away

  • Posts: 535

  • Since: 2010/12/27


Hi

is there somewhere a documentation how to implement this feature "get notification for each comment"



1440
alain01
Re: xNewsletter 1.4 RC ready for testing
  • 2020/3/25 11:05

  • alain01

  • Just can't stay away

  • Posts: 530

  • Since: 2003/6/20


Modules, books (tuto) !
Well done, Goffy,
as usually !
Thank you.
I will test in next days !

This module is perfect for our web site (https://www.monxoops.fr/) with "Allow new user registration" set to "no".




TopTop
« 1 ... 141 142 143 (144) 145 146 147 ... 29424 »



Login

Who's Online

213 user(s) are online (145 user(s) are browsing Support Forums)


Members: 0


Guests: 213


more...

Donat-O-Meter

Stats
Goal: $100.00
Due Date: Jun 30
Gross Amount: $0.00
Net Balance: $0.00
Left to go: $100.00
Make donations with PayPal!

Latest GitHub Commits