solved AutoFollow for Forum

Elise
Elise
@elise
8 years ago
249 posts
I would like my new members to get notified of new post in the forum.

I read the docs on auto-follow and I am wondering if it's possible to use this so that new user get notification of my main forum's topics (it's a category)? Or is there some other way to do this?

Thanks!

updated by @elise: 03/07/17 03:56:52PM
Holly Dilatush
Holly Dilatush
@holly-dilatush
8 years ago
212 posts
Different thinking (I like it) but similar question here:https://www.jamroom.net/the-jamroom-network/forum/my_posts/44572/groups-to-jrdiscussion-following
Elise
Elise
@elise
8 years ago
249 posts
Lol, I asked about auto-follow because I saw your post about it :)

On my end, I use Forum so my members can follow the entire category in one click.
But I'm looking for a way for every new member to automatically follow a specific forum category upon registration.

Thanks for the link!
paul
@paul
8 years ago
4,331 posts
A simple custom module to 'listen' for new members and add them to the jrForum follow_category database table.


--
Paul Asher - JR Developer and System Import Specialist
Elise
Elise
@elise
8 years ago
249 posts
Ok, i tried to do this, mostly by copying what I found elsewhere.
Can I get a code review? I have not tried this but I don't think it will work as is.
zip

Elise
Elise
@elise
8 years ago
249 posts
include.php

<?php
/**
 * @copyright 2016 Talldude Networks, LLC.
 */

// make sure we are not being called directly
defined('APP_DIR') or exit();

/**
 * meta
 */
function jrAutoNotify_meta(){
    $_tmp = array(
        'name'        => 'Auto Notify',
        'url'         => 'auto-notify',
        'version'     => '0.0.1',
        'developer'   => 'The Jamroom Network, ©' . strftime('%Y'),
        'description' => 'A listener module. Upon user registration, auto notify on forum posts in specified categories',
        'category'    => 'custom',
        'requires'    => '',
        'license'     => 'jcl'
    );
    return $_tmp;
}

/**
 * init
 */
function jrAutoNotify_init(){
   // Event Listener
   jrCore_register_event_listener('jrUser', 'signup_activated', 'jrAutoNotify_signup_activated_listener');

    return true;
}

//----------------------
// EVENT LISTENERS
//----------------------


/**
 * Listen for the 'signup_activated' event and add user as watcher of forum category
 * @param $_data array incoming data array
 * @param $_user array current user info
 * @param $_conf array Global config
 * @param $_args array additional info about the module
 * @param $event string Event Trigger name
 * @return array
 */
function jrAutoNotify_signup_activated_listener($_data, $_user, $_conf, $_args, $event)
{ if (isset($_conf['jrAutoNotify_category_id']) && strlen($_conf['jrAutoNotify_category_id']) > 0) { $cid = (int) $_conf['jrAutoNotify_category_id']; $uid = (int) $_user['_user_id']; $tbl = jrCore_db_table_name('jrForum', 'follow_category'); $req = "INSERT IGNORE INTO {$tbl} (follow_cat_id,follow_user_id) VALUES ('{$cid}','{$uid}')"; //i dont know what this does... $tag = $_ln['jrForum'][119]; jrCore_db_query($req); // reset forum cache for this user jrCore_delete_all_cache_entries('jrForum', $_user['_user_id']); } return $_data; }
Elise
Elise
@elise
8 years ago
249 posts
config.php
 
<?php

// make sure we are not being called directly
defined('APP_DIR') or exit();

/**
 * config
 */
function jrAutoNotify_config(){
    // Additional  Fields
    $_tmp = array(
        'name'     => 'category_id',
        'type'     => 'text',
        'default'  => '1',
        'validate' => '',
        'label'    => 'forum category id for notification',
        'help'     => 'category id',
        'section'  => 'notify forum category',
        'order'    => 1
    );
    jrCore_register_setting('jrAutoNotify', $_tmp);

    return true;
}


updated by @elise: 11/20/16 03:16:01PM
Elise
Elise
@elise
8 years ago
249 posts
index.php

<?php
/**
 * @copyright 2016 Talldude Networks, LLC.
 */

// make sure we are not being called directly
defined('APP_DIR') or exit();

//------------------------------
// auto_notify_save
//------------------------------
function view_jrAutoNotify($_post, &$_user, &$_conf)
{ jrUser_master_only(); jrCore_page_include_admin_menu(); jrCore_page_admin_tabs('jrAutoNotify'); jrCore_page_banner('Choose Auto Notificaton'); // Form init $_tmp = array( 'submit_value' => 'Set Notifications', 'cancel' => "{$_conf['jrCore_base_url']}/{$_post['module_url']}/admin/tools", 'submit_prompt' => 'Are you sure you want to set this Auto Notificaton?', 'submit_modal' => 'update', 'modal_width' => 800, 'modal_height' => 400, 'modal_note' => 'Please Wait' ); jrCore_form_create($_tmp); $_tmp = array( 'name' => 'dummy', 'value' => 'off', 'type' => 'hidden' ); jrCore_form_field_create($_tmp); jrCore_page_display(); }
michael
@michael
8 years ago
7,746 posts
looking at it now:
* Changed folder name xxxjrAutoNotify to xxAutoNotify
* Renamed all instances of jrAutoNotify everywhere in the files to xxAutoNotify to match folder name
* index.php contains a view called view_xxAutoNotify() there is no view url specified, needs changing.

Anything in the index.php file is a view used to take control of a url, so since the module wants to take control of the 'auto-notify' url any url found at site.com/auto-notify will look for function in index.php and if its not there, it will look for a file index.tpl in the /modules/xxAutoNotify/templates/index.tpl

The URL that the module wants to take control of is found in the _meta() function in include.php, here:
/**
 * meta
 */
function xxAutoNotify_meta(){
    $_tmp = array(
        'name'        => 'Auto Notify',
        'url'         => 'auto-notify',
.......
}


To take control of a specific url, like site.com/auto-notify/speedway that would correspond to
index.php:
function view_xxAutoNotify_speedway($_post, $_user, $_conf)
{ return 'I like going to the speedway'; }

You cant have a view function without a view specified so view_xxAutoNotify() won't work, if you want it to be the default for all non defined views, then use view_xxAutoNotify_default.

--
* adding a changelog.txt and incrementing the version to 1.0.0
* removed the hyphen in auto-notify url because I worry it could be interpreted incorrectly (personal preference not a requirement)

--
have just installed the module: The index.php file is not needed at all, there are no views for this module. Deleted it.

--
* config.php is good, it just needs a bit of cleaning up, it would have worked though.

--
Tested, seams to be good, have added a requirement for the jrForum module since it wont do anything without that and added a check before trying to write to the datastore.

Other than that, well done.

Attached
zip
xxAutoNotify.zip  •  2KB


updated by @michael: 11/20/16 11:22:51PM
Elise
Elise
@elise
8 years ago
249 posts
Thanks for the explanation and the review Michael!
michael
@michael
8 years ago
7,746 posts
The working module is attached too.
Elise
Elise
@elise
8 years ago
249 posts
LOL I saw that and downloaded it :)

Tags