SMFShop > Coding
Help With Points For Boards
dada:
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.
Daniel15:
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) ---$boardOptions['countMoney'] = isset($_POST['countMoney']);$boardOptions['posts_count'] = isset($_POST['count']);
--- End code ---
Replace with:
--- Code: (php) ---$boardOptions['posts_count'] = isset($_POST['count']);
--- End code ---
Find:
--- Code: (php) ---// Checkboxes....
--- End code ---
Add before:
--- Code: (php) --- // 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
--- End code ---
Sources/Post.php, find:
--- Code: (php) --- // 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
--- End code ---
Replace with:
--- Code: (php) --- // 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
--- End code ---
Sources/Subs-Boards.php, find:
--- Code: (php) --- //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
--- End code ---
Replace with:
--- Code: (php) --- // 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
--- End code ---
Find:
--- Code: (php) ---'countMoney' => 1,
--- End code ---
Replace with:
--- Code: (php) --- // Begin SMFShop code
'countMoney' => 1,
'shop_pertopic' => 0,
'shop_perpost' => 0,
'shop_bonuses' => 1,
// End SMFShop code
--- End code ---
Find:
--- Code: ---b.countMoney,
--- End code ---
Replace with:
--- Code: ---b.countMoney, b.shop_pertopic, b.shop_perpost, b.shop_bonuses
--- End code ---
Find:
--- Code: (php) ---'countMoney' => $row['countMoney'],
--- End code ---
Replace with:
--- Code: (php) --- // Begin SMFShop code
'countMoney' => $row['countMoney'],
'shop_pertopic' => $row['shop_pertopic'],
'shop_perpost' => $row['shop_perpost'],
'shop_bonuses' => $row['shop_bonuses'],
// End SMFShop code
--- End code ---
Themes/default/ManageBoards.template.php, find:
--- Code: (php) --- //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
--- End code ---
Replace with:
--- Code: (php) --- // 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
--- End code ---
Themes/default/languages/Shop.english.php, at the very bottom (above ?>), add:
--- Code: (php) ---// 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)';
--- End code ---
Then, run this query in phpMyAdmin:
--- Code: ---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';
--- End code ---
I'm hoping that this works, I haven't actually tested it on a fresh SMFShop 3.0 installation...
perplexed:
:(( 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'
--- End quote ---
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.
--- End quote ---
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!
Daniel15:
What's on lines 1480- 1490 in Subs-Boards.php (use an editor like Notepad++ that shows line numbers)?
perplexed:
--- Code: ---// 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!
--- End code ---
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
Navigation
[0] Message Index
[#] Next page
[*] Previous page
Go to full version