Author Topic: Help With Points For Boards  (Read 25203 times)

Offline Tanix

Help With Points For Boards
« on: January 28, 2007, 05:10:03 am »
Currently, you can set boards on or off to count shop points. What would need to be done to set boards instead to a specific multiple of points? A laborious example:
Board 1 - zero so no points
Board 2 - multiple of 1, so regular points are scored for that board.
Board 3 - multiple of 1.5 - so points score for a post in that board is increased by 50%.
Board 4 - multiple of 2 - double points

Offline mikemotorcade

Re: Help With Points For Boards
« Reply #1 on: February 01, 2007, 04:16:33 am »
If you go to "Boards" in the Admin center, then to the settings of a specific board, you can set whether a users post will count towards the shop or not. As far as I know there isn't a way to set a predetermined amount for each board. That would be handy though.

Michael

Offline Tanix

Re: Help With Points For Boards
« Reply #2 on: February 01, 2007, 04:47:41 am »
Yup, seen that thanks. What I'm looking to do is change the marker from on/off to a numeric value (say 0,1 and 2) then multiply the result by the points score for a post.

Why do that? To encourage posting in particular boards where people would score double credits.
« Last Edit: February 01, 2007, 04:49:25 am by Tanix »

Offline mikemotorcade

Re: Help With Points For Boards
« Reply #3 on: February 01, 2007, 05:00:42 am »
Aight. Sorry no help here. ;)

Offline Tanix

Re: Help With Points For Boards
« Reply #4 on: February 01, 2007, 05:05:42 am »
np, thanks for trying.

Offline Pure

Re: Help With Points For Boards
« Reply #5 on: February 06, 2007, 07:38:56 pm »
Something I wouldn't mind also. Very good idea Tanix. I just hope somebody who could implement this will read this topic.

Peace, Lance

Offline Tanix

Re: Help With Points For Boards
« Reply #6 on: February 08, 2007, 05:21:03 pm »
Thanks Pure. I'm having a go myself. Managed to do about half of what's needed I reckon but I'm a bit stuck at the mo on the rest.

Offline feeble

Re: Help With Points For Boards
« Reply #7 on: February 09, 2007, 03:43:36 am »
extremely quick as i have to go to work
you must know what a boardid is and if statements to understand how to implement this btw.

open up sources/Post.php
locate
Code: [Select]
// The bonus for each word...
$points += ($modSettings['shopPointsPerWord'] * str_word_count($plaintext));
// ...and bonus for each letter
$points += ($modSettings['shopPointsPerChar'] * strlen($plaintext));

// Is there a limit set, and are we over it?
if (isset($modSettings['shopPointsLimit']) && $modSettings['shopPointsLimit'] != 0 && $points > $modSettings['shopPointsLimit'])
// If so, set the number of points to the limit
$points = $modSettings['shopPointsLimit'];

// Give the user their points
$result_shop = db_query("
UPDATE {$db_prefix}members
SET money = money + {$points}
WHERE ID_MEMBER = {$ID_MEMBER}
LIMIT 1", __FILE__, __LINE__);

now just add something like this
Code: [Select]
// The bonus for each word...
$points += ($modSettings['shopPointsPerWord'] * str_word_count($plaintext));
// ...and bonus for each letter
$points += ($modSettings['shopPointsPerChar'] * strlen($plaintext));

// Is there a limit set, and are we over it?
if (isset($modSettings['shopPointsLimit']) && $modSettings['shopPointsLimit'] != 0 && $points > $modSettings['shopPointsLimit'])
// If so, set the number of points to the limit
$points = $modSettings['shopPointsLimit'];

if{$board == 1)
$points = $points *2;
elseif($board == 2)
$point = $point * 3;

// Give the user their points
$result_shop = db_query("
UPDATE {$db_prefix}members
SET money = money + {$points}
WHERE ID_MEMBER = {$ID_MEMBER}
LIMIT 1", __FILE__, __LINE__);

Offline Pure

Re: Help With Points For Boards
« Reply #8 on: February 09, 2007, 10:22:31 am »
That's pretty neat actually feeble. I'll give this a shot. Yeah I understand what it means. Cheers. :)

Peace, Lance

Offline Daniel15

Re: Help With Points For Boards
« Reply #9 on: February 10, 2007, 01:11:29 pm »
Sounds like a good idea, and feeble has given me an idea on how to do this :)
I'll try to implement this in a future version. I'm really busy at the moment, and probably won't have it done for a while, though.

Offline dada

Re: Help With Points For Boards
« Reply #10 on: March 20, 2007, 06:58:05 pm »
yes i totaly agree with you, this should be implemented in earlyer stage becouse now serious boards are having trouble by ppl posting too much in offtopic.

there is so many thigns needed and not needed in shop mod but this one is must have becouse on other sort of forums like phpbb there is this option and i dont think is hard to invest it.

anyways if you found any alternativ solution i would gladly try it.

Offline Daniel15

Re: Help With Points For Boards
« Reply #11 on: March 31, 2007, 10:36:45 pm »
OK, I've started working on this, and an initial version is currently available in SMFShop Development Version (see the beta testing topic if you'd like to help beta-test the new version of SMFShop) :).
Take a look at the attached screenshot to see how the settings look at the moment (excuse the really stupid grammar mistake in the last setting!)

To get this working on SMFShop 3.0, follow these steps. Make a backup of any edited files, as you'll need to restore the originals if a new version of SMFShop comes out.

Open Sources/ManageBoards.php, and find:
Code: (php) [Select]
$boardOptions['countMoney'] = isset($_POST['countMoney']);$boardOptions['posts_count'] = isset($_POST['count']);
Replace with:
Code: (php) [Select]
$boardOptions['posts_count'] = isset($_POST['count']);

Find:
Code: (php) [Select]
// Checkboxes....

Add before:
Code: (php) [Select]
// Begin SMFShop code
// Are we counting credits in this board?
// TODO: Rename this? It's kept as countMoney for backwards compatibility...
$boardOptions['countMoney'] = isset($_POST['countMoney']);
// How many credits do we get per post/topic?
$boardOptions['shop_pertopic'] = !empty($_POST['shop_pertopic']) ? (int) $_POST['shop_pertopic'] : 0;
$boardOptions['shop_perpost'] = !empty($_POST['shop_perpost']) ? (int) $_POST['shop_perpost'] : 0;
// Bonuses in this board?
$boardOptions['shop_bonuses'] = isset($_POST['shop_bonuses']);
// End SMFShop code

Sources/Post.php, find:
Code: (php) [Select]
// BEGIN SMFShop New Version (Build 12) code
// Get if this board gives credits for posting
$result_shop = db_query("
SELECT countMoney
FROM {$db_prefix}boards
WHERE ID_BOARD = $board
LIMIT 1", __FILE__, __LINE__);
$row_shop = mysql_fetch_array($result_shop, MYSQL_ASSOC);

// If we do give credits...
if (isset($row_shop['countMoney']) && $row_shop['countMoney'] == "1") {
// New topic?
if ($newTopic)
$points = $modSettings['shopPointsPerTopic'];
else
$points = $modSettings['shopPointsPerPost'];

// Now, on to bonuses.
// Strip out all BBCode
$plaintext = preg_replace('[\[(.*?)\]]', ' ', $_POST['message']);
// Convert all newlines into spaces
$plaintext = str_replace(array('<br />', "\r", "\n"), ' ', $plaintext);
// Convert multiple successive spaces into a single space
$plaintext = preg_replace('/\s+/', ' ', $plaintext);

// The bonus for each word...
$points += ($modSettings['shopPointsPerWord'] * str_word_count($plaintext));
// ...and bonus for each letter
$points += ($modSettings['shopPointsPerChar'] * strlen($plaintext));

// Is there a limit set, and are we over it?
if (isset($modSettings['shopPointsLimit']) && $modSettings['shopPointsLimit'] != 0 && $points > $modSettings['shopPointsLimit'])
// If so, set the number of points to the limit
$points = $modSettings['shopPointsLimit'];

// Give the user their points
$result_shop = db_query("
UPDATE {$db_prefix}members
SET money = money + {$points}
WHERE ID_MEMBER = {$ID_MEMBER}
LIMIT 1", __FILE__, __LINE__);
}
// END SMFShop

Replace with:
Code: (php) [Select]
// Begin SMFShop code
// Get some information on this board
$result_shop = db_query("
SELECT countMoney, shop_pertopic, shop_perpost, shop_bonuses
FROM {$db_prefix}boards
WHERE ID_BOARD = $board
LIMIT 1", __FILE__, __LINE__);
$boardInfo = mysql_fetch_assoc($result_shop);

// If we do give credits...
if (!empty($boardInfo['countMoney']))
{
// New topic?
if ($newTopic)
$points = ($boardInfo['shop_pertopic'] != 0) ? $boardInfo['shop_pertopic'] : $modSettings['shopPointsPerTopic'];
else
$points = ($boardInfo['shop_perpost'] != 0) ? $boardInfo['shop_perpost'] : $modSettings['shopPointsPerPost'];


// Are bonuses allowed in this board?
if (!empty($boardInfo['shop_bonuses']))
{
// Strip out all BBCode
$plaintext = preg_replace('[\[(.*?)\]]', ' ', $_POST['message']);
// Convert all newlines into spaces
$plaintext = str_replace(array('<br />', "\r", "\n"), ' ', $plaintext);
// Convert multiple successive spaces into a single space
$plaintext = preg_replace('/\s+/', ' ', $plaintext);

// The bonus for each word...
$points += ($modSettings['shopPointsPerWord'] * str_word_count($plaintext));
// ...and bonus for each letter
$points += ($modSettings['shopPointsPerChar'] * strlen($plaintext));

// Is there a limit set, and are we over it?
if (isset($modSettings['shopPointsLimit']) && $modSettings['shopPointsLimit'] != 0 && $points > $modSettings['shopPointsLimit'])
// If so, set the number of points to the limit
$points = $modSettings['shopPointsLimit'];
}

// Give the user their points
$result_shop = db_query("
UPDATE {$db_prefix}members
SET money = money + {$points}
WHERE ID_MEMBER = {$ID_MEMBER}
LIMIT 1", __FILE__, __LINE__);
}
// End SMFShop code

Sources/Subs-Boards.php, find:
Code: (php) [Select]
                //BEGIN SMFShop Shop MOD 1.3 (Build 6) code
// Should posts in this board give credits?
                if (isset($boardOptions['countMoney']))
                    $boardUpdates[] = 'countMoney = ' . ($boardOptions['countMoney'] ? '1' : '0');
                //End Shop MOD

Replace with:
Code: (php) [Select]
// Begin SMFShop code
// Should posts in this board give gredits?
if (isset($boardOptions['countMoney']))
$boardUpdates[] = 'countMoney = ' . ($boardOptions['countMoney'] ? '1' : '0');
// Custom credits per post/topic
if (isset($boardOptions['shop_pertopic']))
$boardUpdates[] = 'shop_pertopic = ' . (int) $boardOptions['shop_pertopic'];
if (isset($boardOptions['shop_perpost']))
$boardUpdates[] = 'shop_perpost = ' . (int) $boardOptions['shop_perpost'];

// Any bonuses here?
if (isset($boardOptions['shop_bonuses']))
$boardUpdates[] = 'shop_bonuses = ' . ($boardOptions['shop_bonuses'] ? '1' : '0');
// End SMFShop code

Find:
Code: (php) [Select]
'countMoney' => 1,

Replace with:
Code: (php) [Select]
// Begin SMFShop code
'countMoney' => 1,
'shop_pertopic' => 0,
'shop_perpost' => 0,
'shop_bonuses' => 1,
// End SMFShop code

Find:
Code: [Select]
b.countMoney,
Replace with:
Code: [Select]
b.countMoney, b.shop_pertopic, b.shop_perpost, b.shop_bonuses
Find:
Code: (php) [Select]
'countMoney' => $row['countMoney'],

Replace with:
Code: (php) [Select]
// Begin SMFShop code
'countMoney' => $row['countMoney'],
'shop_pertopic' => $row['shop_pertopic'],
'shop_perpost' => $row['shop_perpost'],
'shop_bonuses' => $row['shop_bonuses'],
// End SMFShop code

Themes/default/ManageBoards.template.php, find:
Code: (php) [Select]
    //BEGIN SMFShop Shop MOD 1.3 (Build 6) code
loadLanguage("Shop");
echo '                     <tr>
<td>
<b>', $txt['shop_count_points'], '</b><br />
', $txt['shop_count_points_msg'], '<br /><br />
</td>
<td valign="top" align="right">
<input type="checkbox" name="countMoney"', $context['board']['countMoney'] ? ' checked="checked"' : '', ' class="check" />
</td>
</tr>';
//END SHOP MOD

Replace with:
Code: (php) [Select]
// Begin SMFShop code
loadLanguage('Shop');
echo '
<tr>
<td>
<b>', $txt['shop_count_points'], '</b><br />
', $txt['shop_count_points_msg'], '<br /><br />
</td>
<td valign="top" align="right">
<input type="checkbox" name="countMoney"', $context['board']['countMoney'] ? ' checked="checked"' : '', ' class="check" />
</td>
</tr>
<tr>
<td>
<b>', $txt['shop_credits'], '</b><br />
', $txt['shop_credits_msg'], '<br /><br />
</td>
<td valign="top" align="right">
', $txt['shop_per_new_topic'], ': ', $modSettings['shopCurrencyPrefix'], '<input type="text" name="shop_pertopic" value="', $context['board']['shop_pertopic'], '" size="5" />', $modSettings['shopCurrencySuffix'], '<br />
', $txt['shop_per_new_post'], ': ', $modSettings['shopCurrencyPrefix'], '<input type="text" name="shop_perpost" value="', $context['board']['shop_perpost'], '" size="5" />', $modSettings['shopCurrencySuffix'], '
</td>
</tr>
<tr>
<td>
<b>', $txt['shop_bonuses_enabled'], '</b><br />
', $txt['shop_bonuses_enabled_msg'], '<br /><br />
</td>
<td valign="top" align="right">
<input type="checkbox" name="shop_bonuses"', $context['board']['shop_bonuses'] ? ' checked="checked"' : '', ' class="check" />
</td>
</tr>';
// End SMFShop code

Themes/default/languages/Shop.english.php, at the very bottom (above ?>), add:
Code: (php) [Select]
// New entries in SMFShop Development Version
$txt['shop_bonuses_enabled'] = 'Enable Shop Bonuses';
$txt['shop_bonuses_enabled_msg'] = 'Shop Bonuses will be take effect in this board';
$txt['shop_credits'] = 'Shop Credits';
$txt['shop_credits_msg'] = 'If custom values are set for these two settings, they will override the settings set on the SMFShop administration page. Set these to "0" to use the default values (currently ' . $modSettings['shopCurrencyPrefix'] . $modSettings['shopPointsPerTopic'] . $modSettings['shopCurrencySuffix'] . ' per topic, and ' . $modSettings['shopCurrencyPrefix'] . $modSettings['shopPointsPerPost'] . $modSettings['shopCurrencySuffix'] . ' per post)';

Then, run this query in phpMyAdmin:
Code: [Select]
ALTER TABLE `smf_boards` ADD `shop_pertopic` DECIMAL( 9, 2 ) UNSIGNED NOT NULL ,
ADD `shop_perpost` DECIMAL( 9, 2 ) UNSIGNED NOT NULL ,
ADD `shop_bonuses` TINYINT( 1 ) UNSIGNED NOT NULL DEFAULT '1';

I'm hoping that this works, I haven't actually tested it on a fresh SMFShop 3.0 installation...
« Last Edit: April 01, 2007, 11:40:36 am by Daniel15 »

Offline perplexed

Re: Help With Points For Boards
« Reply #12 on: April 03, 2007, 08:06:11 am »
:((  ok I followed all of the above and its broken

I run the query and I got this message:

Quote
Error

SQL query:

ALTER TABLE `smf_boards` ADD `shop_pertopic` DECIMAL( 9, 2 ) UNSIGNED NOT NULL ,
ADD `shop_perpost` DECIMAL( 9, 2 ) UNSIGNED NOT NULL ,
ADD `shop_bonuses` TINYINT( 1 ) UNSIGNED NOT NULL DEFAULT '1'

MySQL said: Documentation
#1060 - Duplicate column name 'shop_pertopic'

and when I go to admin > boards in my forum I get this:

Quote
Database Error
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '.permission_mode, c.ID_CAT, c.name AS cName, c.catOrder, c.canCollapse
FROM sm' at line 4
File: /home/******/public_html/testforum/Sources/Subs-Boards.php
Line: 1486

Note: It appears that your database may require an upgrade. Your forum's files are currently at version SMF 1.1.2, while your database is at version 1.1.1. The above error might possibly go away if you execute the latest version of upgrade.php.

I don't need to run the upgrade thing, will restoring the sources files fix it or do I have to do something with the database now too?

help!

« Last Edit: April 03, 2007, 08:23:48 am by perplexed »
Estne volumen in toga, an solum tibi libet me videre?

Offline Daniel15

Re: Help With Points For Boards
« Reply #13 on: April 03, 2007, 04:38:47 pm »
What's on lines 1480- 1490 in Subs-Boards.php (use an editor like Notepad++ that shows line numbers)?

Offline perplexed

Re: Help With Points For Boards
« Reply #14 on: April 03, 2007, 06:37:05 pm »
Code: [Select]
// Load a lot of usefull information regarding the boards and categories.
function getBoardTree()
{
global $db_prefix, $cat_tree, $boards, $boardList, $txt, $modSettings;

// Getting all the board and category information you'd ever wanted.
$request = db_query("
SELECT
IFNULL(b.ID_BOARD, 0) AS ID_BOARD, b.ID_PARENT, b.name AS bName, b.description, b.childLevel,
b.boardOrder, b.countPosts, b.memberGroups, b.ID_THEME, b.override_theme,
b.countMoney, b.shop_pertopic, b.shop_perpost, b.shop_bonuses b.permission_mode, c.ID_CAT, c.name AS cName, c.catOrder, c.canCollapse
FROM {$db_prefix}categories AS c
LEFT JOIN {$db_prefix}boards AS b ON (b.ID_CAT = c.ID_CAT)
ORDER BY c.catOrder, b.childLevel, b.boardOrder", __FILE__, __LINE__);
$cat_tree = array();
$boards = array();
$last_board_order = 0;
while ($row = mysql_fetch_assoc($request))
{
if (!isset($cat_tree[$row['ID_CAT']]))
{
$cat_tree[$row['ID_CAT']] = array(
'node' => array(
'id' => $row['ID_CAT'],
'name' => $row['cName'],
'order' => $row['catOrder'],
'canCollapse' => $row['canCollapse']
),
'is_first' => empty($cat_tree),
'last_board_order' => $last_board_order,
'children' => array()
);
$prevBoard = 0;
$curLevel = 0;
}

if (!empty($row['ID_BOARD']))
{
if ($row['childLevel'] != $curLevel)
$prevBoard = 0;

$boards[$row['ID_BOARD']] = array(
'id' => $row['ID_BOARD'],
'category' => $row['ID_CAT'],
'parent' => $row['ID_PARENT'],
'level' => $row['childLevel'],
'order' => $row['boardOrder'],
'name' => $row['bName'],
'memberGroups' => explode(',', $row['memberGroups']),
'description' => $row['description'],
'count_posts' => empty($row['countPosts']),
'theme' => $row['ID_THEME'],
'override_theme' => $row['override_theme'],// Begin SMFShop code
'countMoney' => $row['countMoney'],
'shop_pertopic' => $row['shop_pertopic'],
'shop_perpost' => $row['shop_perpost'],
'shop_bonuses' => $row['shop_bonuses'],
// End SMFShop code
'use_local_permissions' => !empty($modSettings['permission_enable_by_board']) && $row['permission_mode'] == 1,
'permission_mode' => empty($modSettings['permission_enable_by_board']) ? (empty($row['permission_mode']) ? 'normal' : ($row['permission_mode'] == 2 ? 'no_polls' : ($row['permission_mode'] == 3 ? 'reply_only' : 'read_only'))) : 'normal',
'prev_board' => $prevBoard
);
$prevBoard = $row['ID_BOARD'];
$last_board_order = $row['boardOrder'];

if (empty($row['childLevel']))
{
$cat_tree[$row['ID_CAT']]['children'][$row['ID_BOARD']] = array(
'node' => &$boards[$row['ID_BOARD']],
'is_first' => empty($cat_tree[$row['ID_CAT']]['children']),
'children' => array()
);
$boards[$row['ID_BOARD']]['tree'] = &$cat_tree[$row['ID_CAT']]['children'][$row['ID_BOARD']];
}
else
{
// Parent doesn't exist!


this line

   // Getting all the board and category information you'd ever wanted.
   $request = db_query("
      SELECT    <-------------------------

near the top of the code above, is line 1480, Daniel
Estne volumen in toga, an solum tibi libet me videre?