News:

Want to get involved in developing SMF, then why not lend a hand on our github!

Main Menu

[WIP] Wizards SMF Shop

Started by The Wizard, July 31, 2013, 09:57:58 AM

Previous topic - Next topic

The Wizard

[WIP] Wizards SMF Shop

The following is a work in progress.

Wizards SMF Shop is a branch or a variation if you like on the SMF Shop mod.

Some of you might know I was working on a small mod called Wizards Gallery that allows you to Add, Remove, Buy, and Show images of the items you have in inventory.

The more I worked with the original shop mod the more I found out that it needed to be updated to work properly with Wizards Gallery. There was also the problem of Wizards Gallery being a mod of a mod or plug in if you will. I dreamed of a mod where you just use the package manager to install and your done.

And So here I am designing the next generation shop mod. I decided to take the best of the old shop mod and junk the rest.
I have VB Gamers permission to use the original shop code, and fully plan on giving him,  and the original creator credit as well as anybody else who helps on this project.

I am not in this for the money, and so this project will be a free like so many of the other great mods available.

This project will be submitted for approval, and so it needs to be written that way. I will be posting my code here in this thread a page or two at a time for anybody to look over, review and comment or make suggestions. At the moment I am still a few weeks away from even having a 1st draft, and even then I know it will need more work.

Wiz

The Wizard


ShopMain.template.php


<?php

if (!defined('SMF'))
die('Hacking attempt...');

function 
template_main()
{
global $txt$context$modSettings$scripturl$boardurl;

loadTemplate('ShopLinks');
loadTemplate('ShopWizard');

// Catagory Header
echo '
<div class="cat_bar">
<h3 class="catbg" align="center">'
$context['shop_main_Head'], '</h3>
</div>
<table>
<tr valign="top">
<td><br />'
shop_links(), '</td>
<td colspan="2"><br />'
shop_home(), '</td>
</tr>
<tr valign="top">
<td align="center"><br />'
wizard_image(), '</td>
<td><br />'
richest_members_pocket(), '</td>
<td><br />'
richest_members_bank(), '</td>
</tr>
</table>
'
;
}

function 
shop_home()
{
global $txt$modSettings$context;

$txt['shop_welcome_full']  = '<strong>Welcome to Wizards SMF Shop!</strong><br /><br />Here, you can "buy" stuff with the credits you get from posting on the forum!<br />For each post you make on the forum, you\'ll earn %s per new topic and %s per new post';
$txt['shop_welcome_full2']  = ', plus any bonuses ';
$txt['shop_welcome_full3']  = ' (capped at a maximum of %s)';
$txt['shop_currently_have1'] = 'You currently have %s in your pocket';
$txt['shop_currently_have2'] = ' and %s in the bank<br />';
$txt['shop_bonuses']  = 'Bonuses';
$txt['shop_per_word2']  = 'per word';
$txt['shop_per_char2']  = 'per character';

// Display Shop Home
echo '
<div class="cat_bar">
<h3 class="catbg" align="center">'
$txt['shop_link_home'], '</h3>
</div>
<div class="windowbg">
<span class="topslice"><span></span></span>
<div class="content">
<br />'
sprintf($txt['shop_welcome_full'], formatMoney($modSettings['shopPointsPerTopic']), formatMoney($modSettings['shopPointsPerPost'])), '<br />
'
;

// Are we using any bonuses at all?
if ($modSettings['shopPointsPerWord'] != || $modSettings['shopPointsPerChar'] != 0)
{
echo $txt['shop_welcome_full2'];
// Are they capped?
if ($modSettings['shopPointsLimit'] != 0)
printf($txt['shop_welcome_full3'], formatMoney($modSettings['shopPointsLimit']));
}

echo '
<br /><br />
'
sprintf($txt['shop_currently_have1'], formatMoney($context['user']['money'])), ($modSettings['shopBankEnabled'] ? sprintf($txt['shop_currently_have2'], formatMoney($context['user']['moneyBank'])) : ''), '
<br /><br />'
;

// Any bonuses? Show the heading
if ($modSettings['shopPointsPerWord'] != || $modSettings['shopPointsPerChar'] != 0)
echo '
<strong>'
$txt['shop_bonuses'], '</strong><br />';

// Are we using the points per word bonus?
if ($modSettings['shopPointsPerWord'] != 0)
echo '
'
formatMoney($modSettings['shopPointsPerWord']), ' '$txt['shop_per_word2'], '<br />';

// Are we using the points per char bonus?
if ($modSettings['shopPointsPerChar'] != 0)
echo '
'
formatMoney($modSettings['shopPointsPerChar']), ' '$txt['shop_per_char2'], '<br />';

echo '
</div>
<span class="botslice"><span></span></span>
</div>
'
;
}

function 
richest_members_pocket()
{
global $txt$context$scripturl;

$txt['shop_richest_pocket'] = '10 Richest Members (Pocket)';

// Display 10 Richest Members (Pocket)
echo '
<div class="cat_bar">
<h3 class="catbg" align="center">'
$txt['shop_richest_pocket'], '</h3>
</div>
<div class="windowbg">
<span class="topslice"><span></span></span>
<div class="content">
'
;

foreach ($context['shop_richest'] as $row)
echo '
<strong><a href="'
$scripturl'?action=profile;u='$row['ID_MEMBER'], '">'$row['realName'], '</a></strong> - 'formatMoney($row['money']), '<br />';

echo '
</div>
<span class="botslice"><span></span></span>
</div>
'
;
}

function 
richest_members_bank()
{
global $modSettings$txt$context$scripturl;

$txt['shop_richest_bank'] = '10 Richest Members (Bank)';

// Display 10 Richest Members (Bank)

// Check to see if the bank's enabled
if ($modSettings['shopBankEnabled'])
{
echo '
<div class="cat_bar">
<h3 class="catbg" align="center">'
$txt['shop_richest_bank'], '</h3>
</div>
<div class="windowbg">
<span class="topslice"><span></span></span>
<div class="content">
'
;

// Richest people (in bank)
foreach ($context['shop_richestBank'] as $row)
echo '
<strong><a href="'
$scripturl'?action=profile;u='$row['ID_MEMBER'], '">'$row['realName'], '</a></strong> - 'formatMoney($row['moneyBank']), '<br />';

echo '
</div>
<span class="botslice"><span></span></span>
</div>
'
;
}
}

// End of Script


Subs-Wizard_Main.php


<?php

if (!defined('SMF'))
die('Hacking attempt...');

function 
ShopMain()
{
global $context$scripturl$txt$smcFunc$modSettings;

loadTemplate('ShopMain');

// Page title for the main page
$context['page_title'] = $txt['shop_main_page_title'];

// Navigational link tree to be shown at the top of the page.
$context['linktree'][] = array(
'url' => $scripturl '?action=shop_main',
'name' => $txt['shop_main']
);

// Title Text
$context['shop_main_Head'] = $txt['shop_main'];

// Write the money in a suitable format.
// Casts the value to a float, and add the prefix and suffix
function formatMoney($money)
{
global $modSettings;

// Cast to float
$money = (float) $money;
// Return amount with prefix and suffix added
return $modSettings['shopCurrencyPrefix'] . $money $modSettings['shopCurrencySuffix'];
}

// 10 richest people (pocket)
// Start with empty list
$context['shop_richest'] = array();
// Get the richest people
$result $smcFunc['db_query'](''"
SELECT id_member, real_name, money
FROM {db_prefix}members
ORDER BY money DESC, real_name
LIMIT 10"
, array());
// Loop through all results

while ($row $smcFunc['db_fetch_assoc']($result))
// And add them to the list
$context['shop_richest'][] = array(
'ID_MEMBER' => $row['id_member'],
'realName' => $row['real_name'],
'money' => $row['money']
);

$smcFunc['db_free_result']($result);

// 10 richest people (Bank)
// Start with an empty list
$context['shop_richestBank'] = array();
// Get the richest people
$result $smcFunc['db_query'](''"
SELECT id_member, real_name, moneyBank
FROM {db_prefix}members
ORDER BY moneyBank DESC, real_name
LIMIT 10"
, array());

// Loop through all results
while ($row $smcFunc['db_fetch_assoc']($result))
// Add them to the list
$context['shop_richestBank'][] = array(
'ID_MEMBER' => $row['id_member'],
'realName' => $row['real_name'],
'moneyBank' => $row['moneyBank']
);

$smcFunc['db_free_result']($result);
}

// End of Script

Advertisement: