Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add settings for auto-subscribe cats for new users and uncomment it #3238

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
60 changes: 37 additions & 23 deletions plugins/plg_system_kunena/kunena.php
Expand Up @@ -189,7 +189,7 @@ protected function runJoomlaContentEvent( &$text, &$params, $page = 0 )
*/
public function onUserAfterSave($user, $isnew, $success, $msg)
{
//Don't continue if the user wasn't stored successfully
// Don't continue if the user wasn't stored successfully
if (!$success)
{
return;
Expand All @@ -201,30 +201,44 @@ public function onUserAfterSave($user, $isnew, $success, $msg)
$kuser->save();
}

/*
$subscribedCategories = $this->params->get('ksystem_subscribed_cats');
$subscribe_cats = $this->params->get('ksystem_subscribe_users_cat');
$subscribe_cats_blocked = $this->params->get('ksystem_subscribe_users_blocked_cat');

// See: http://www.kunena.org/forum/159-k-16-common-questions/63438-category-subscriptions-default-subscribed#63554
// TODO: Subscribe user to every category if he is new and Kunena is configured to do so
if ($isnew) {
$subscribedCategories = '1,2,3,4,5,6,7,8,9,10';
$db = Jfactory::getDBO();
$query = "INSERT INTO #__kunena_user_categories (user_id,category_id,subscribed)
SELECT {{$db->quote($user->userid)} AS user_id, c.id as category_id, 1
FROM #__kunena_categories AS c
LEFT JOIN #__kunena_user_categories AS s ON c.id=s.category_id AND s.user_id={{$db->quote($user->userid)}
WHERE c.parent>0 AND c.id IN ({$subscribedCategories}) AND s.user_id IS NULL";
$db->setQuery ( $query );
$db->query ();
KunenaError::checkDatabaseError();

// Here's also query to subscribe all users (including blocked) to all existing cats:
$query = "INSERT INTO #__kunena_user_categories (user_id,category_id,subscribed)
SELECT u.id AS user_id, c.id AS category_id, 1
FROM #__users AS u
JOIN #__kunena_categories AS c ON c.parent>0
LEFT JOIN #__kunena_user_categories AS s ON u.id=s.user_id
WHERE c.id IN ({$subscribedCategories}) AND s.user_id IS NULL";
// Subscribe user to every category if he is new and Kunena is configured to do so
if ($subscribe_cats)
{
$db = JFactory::getDbo();

if ($isnew)
{
if (!$subscribe_cats_blocked)
{
$query = "INSERT INTO #__kunena_user_categories (user_id,category_id,subscribed)
SELECT {{$db->quote($user->userid)} AS user_id, c.id as category_id, 1
FROM #__kunena_categories AS c
LEFT JOIN #__kunena_user_categories AS s ON c.id=s.category_id AND s.user_id={{$db->quote($user->userid)}
WHERE c.parent_id>0 AND c.id IN ({$subscribedCategories}) AND s.user_id IS NULL";
$db->setQuery($query);
$db->execute();
KunenaError::checkDatabaseError();
}
else
{
// Here's also query to subscribe all users (including blocked) to all existing cats:
$query = "INSERT INTO #__kunena_user_categories (user_id,category_id,subscribed)
SELECT u.id AS user_id, c.id AS category_id, 1
FROM #__users AS u
JOIN #__kunena_categories AS c ON c.parent_id>0
LEFT JOIN #__kunena_user_categories AS s ON u.id=s.user_id
WHERE c.id IN ({$subscribedCategories}) AND s.user_id IS NULL";
$db->setQuery($query);
$db->execute();
KunenaError::checkDatabaseError();
}
}
}
*/
}

/**
Expand Down
9 changes: 9 additions & 0 deletions plugins/plg_system_kunena/kunena.xml
Expand Up @@ -25,6 +25,15 @@
<option value="title">PLG_SYSTEM_KUNENA_JCONTENTPLUGINS_TARGET_TITLES</option>
<option value="body">PLG_SYSTEM_KUNENA_JCONTENTPLUGINS_TARGET_BODIES</option>
</field>
<field name="ksystem_subscribed_cats" type="text" default="25" description="PLG_SYSTEM_KUNENA_SUSBSCRIBE_ALL_CATS_LIST_DESC" label="PLG_SYSTEM_KUNENA_SUSBSCRIBE_ALL_CATS_LIST_LABEL" />
<field name="ksystem_subscribe_users_cat" type="list" default="0" label="PLG_SYSTEM_KUNENA_SUSBSCRIBE_ALL_CATS_LABEL" description="PLG_SYSTEM_KUNENA_SUSBSCRIBE_ALL_CATS_DESC" class="inputbox">
<option value="0">JNO</option>
<option value="1">JYES</option>
</field>
<field name="ksystem_subscribe_users_blocked_cat" type="list" default="0" label="PLG_SYSTEM_KUNENA_SUSBSCRIBE_BLOCKED_ALL_CATS_LABEL" description="PLG_SYSTEM_KUNENA_SUSBSCRIBE_BLOCKED_ALL_CATS_DESC" class="inputbox">
<option value="0">JNO</option>
<option value="1">JYES</option>
</field>
</fieldset>
</fields>
</config>
Expand Down
Expand Up @@ -17,3 +17,9 @@ PLG_SYSTEM_KUNENA_JCONTENTPLUGINS_TARGET="Run plugins on"
PLG_SYSTEM_KUNENA_JCONTENTPLUGINS_TARGET_DESC="Which data do you want to run Joomla content plugins on? (Hold down CTRL key to click on more)"
PLG_SYSTEM_KUNENA_JCONTENTPLUGINS_TARGET_TITLES="Titles"
PLG_SYSTEM_KUNENA_JCONTENTPLUGINS_TARGET_BODIES="Bodies"
PLG_SYSTEM_KUNENA_SUSBSCRIBE_ALL_CATS_LABEL="Subscribe users to all categories"
PLG_SYSTEM_KUNENA_SUSBSCRIBE_ALL_CATS_DESC="Subscribe automatically the new users after their registration to all categories. Enable this if you are sure what you are doing because it can impact the performance."
PLG_SYSTEM_KUNENA_SUSBSCRIBE_BLOCKED_ALL_CATS_LABEL="Subscribe blocked users to all categories"
PLG_SYSTEM_KUNENA_SUSBSCRIBE_BLOCKED_ALL_CATS_DESC="Subscribe automatically the new users and the blocked users after their registration to all categories. Enable this if you are sure what you are doing because it can impact the performance."
PLG_SYSTEM_KUNENA_SUSBSCRIBE_ALL_CATS_LIST_LABEL="Enter categories list separated by commas."
PLG_SYSTEM_KUNENA_SUSBSCRIBE_ALL_CATS_LIST_DESC="Enter the categories list separated by commas where the users will be subscribed."