OK - Here is my include.php file -
<?php
defined('APP_DIR') or exit();
function jrFriend_meta(){
$_tmp = array(
'name' => 'Followers to Friends',
'url' => 'friend',
'version' => '0.0.1',
'developer' => 'The Jamroom Network, ©' . strftime('%Y'),
'description' => 'A listener module. Upon follower acceptence, it reciprocates the follow.',
'category' => 'custom',
'requires' => 'jrFollower',
'license' => 'jcl'
);
return $_tmp;
}
function jrFriend_init(){
jrCore_register_event_listener('jrCore', 'db_update_item', 'jrFriend_db_update_item_listener');
jrCore_register_event_listener('jrCore', 'db_create_item', 'jrFriend_db_create_item_listener');
jrCore_register_module_feature('jrCore', 'tool_view', 'jrFriend', 'approve_set', array('Set Approval', 'Set all site profiles to \'Follower Approve\''));
return true;
}
function jrFriend_db_update_item_listener($_data, $_user, $_conf, $_args, $event)
{
if ($_args['module'] == 'jrFollower' && jrCore_checktype($_args['_item_id'], 'number_nz') && isset($_data['follow_active']) && $_data['follow_active'] == 1) {
$_rt = jrCore_db_get_item('jrFollower', $_args['_item_id'], true);
$_tmp = array(
'follow_active' => 1,
'follow_profile_id' => $_rt['_profile_id']
);
jrCore_db_create_item('jrFollower', $_tmp);
}
return $_data;
}
function jrFriend_db_create_item_listener($_data, $_user, $_conf, $_args, $event)
{
if ($_args['module'] == 'jrProfile' && jrCore_checktype($_args['_item_id'], 'number_nz')) {
$_data['profile_jrFollower_approve'] = 'on';
}
return $_data;
}
Note that there is a second listener for 'db_create_item'. This looks for new profiles being created and sets the 'follow approve' to 'on' by default.
Also note that there is also a module tool to set all site profiles to follower approve regardless. The code for that tool is in the index.php file below -
<?php
defined('APP_DIR') or exit();
function view_jrFriend_approve_set($_post, &$_user, &$_conf)
{
jrUser_master_only();
jrCore_page_include_admin_menu();
jrCore_page_admin_tabs('jrFriend');
jrCore_page_banner('Set Follower Approval');
$_tmp = array(
'submit_value' => 'Set Approvals',
'cancel' => "{$_conf['jrCore_base_url']}/{$_post['module_url']}/admin/tools",
'submit_prompt' => 'Are you sure you want to set all your profiles to Follower Approve?',
'submit_modal' => 'update',
'modal_width' => 800,
'modal_height' => 400,
'modal_note' => 'Please be patient whilst group discussions are alternatively imported'
);
jrCore_form_create($_tmp);
$_tmp = array(
'name' => 'dummy',
'value' => 'off',
'type' => 'hidden'
);
jrCore_form_field_create($_tmp);
jrCore_page_display();
}
function view_jrFriend_approve_set_save($_post, &$_user, &$_conf)
{
jrUser_master_only();
jrCore_form_validate($_post);
$pcnt = jrCore_db_get_datastore_item_count('jrProfile');
jrCore_form_modal_notice('update', "Setting {$pcnt} profiles to 'Follower Approve'");
$_s = array(
'return_item_id_only' => true,
'limit' => $pcnt
);
$_rt = jrCore_db_search_items('jrProfile', $_s);
if ($_rt && is_array($_rt) && count($_rt) > 0) {
$_tmp = array();
foreach ($_rt as $rt) {
$_tmp["{$rt}"] = array('profile_jrFollower_approve' => 'on');
}
jrCore_db_update_multiple_items('jrProfile', $_tmp);
}
else {
jrCore_form_modal_notice('update', "Error: Profiles not found");
}
jrCore_form_modal_notice('complete', "Done");
jrCore_form_result();
}
Cheers
Pa
--
Paul Asher - JR Developer and System Import Specialist
updated by @paul: 09/11/16 04:23:49AM