MyBB-Plugins Forums
Can't edit (shop) plugin? Help please! - Printable Version

+- MyBB-Plugins Forums (http://forums.mybb-plugins.com)
+-- Forum: Archived Forums (http://forums.mybb-plugins.com/Forum-Archived-Forums)
+--- Forum: MyBB 1.6.x (http://forums.mybb-plugins.com/Forum-MyBB-1-6-x)
+---- Forum: NewPoints (http://forums.mybb-plugins.com/Forum-NewPoints)
+---- Thread: Can't edit (shop) plugin? Help please! (/Thread-Can-t-edit-shop-plugin-Help-please)

Pages: 1 2


Can't edit (shop) plugin? Help please! - Kentai - 08-11-2010

I use the legacy view for the user details and I also display the shop items (I edited them into the postbit_classic template to show up.)
However their layout is obviously meant for the horizontal view.

That is the reason why I tried to edit the output in the newpoints_shop.php file.
Thankfully the code is easy on the eyes and finding the right places to edit wasn't a problem

the real problem is this, and I had the exact same problem once before on another occasion:

as soon as I edit anything in the newpoints_shop.php file and upload it, the whole shop plugin vanishes from the admin control pannel (I didn't even bother to check whether the plug-in still worked on the board^^)

does anyone know how I can get around this problem?

it is very urgent and since the layout of how the items are displayed is predefined in the {$post['newpoints_WHATSTHISNAMEAGAIN']} function (sry to lazy to look the exact name up, if you need to know just ask and I'll look it up...), I see no other way, than editing the newpoints_shop.php code.

sy,
Kentai


RE: Can't edit (shop) plugin? Help please! - Diogo Parrinha - 08-11-2010

Are you editing it with something like Notepad++ ? Not Notepad because that will break your files.


RE: Can't edit (shop) plugin? Help please! - Kentai - 08-11-2010

I am editing it with the best php editor possible ^^
PsPad.

I am quite experienced with php, html, css and mysql.
However I have started working with myBB only a few days ago and I am still unfamiliar with some things.

I was thinkind that there might be some kind of file imprint on the database after installing, that has to match the actual file or something like that, that would explain why tempering has such harmful effects.

But as I said, the software is new to me, so I don't know.


RE: Can't edit (shop) plugin? Help please! - Diogo Parrinha - 08-11-2010

Where are you uploading newpoints_shop.php to? To inc/plugins/newpoints/ right?


RE: Can't edit (shop) plugin? Help please! - Kentai - 08-11-2010

of course^^
If I wouldn't it wouldn't have any effect^^

Edit:
I did it! I found a part of the code where I could insert my additional coding without reprecutions :3

thanks for the support and quick replying though ^-^

sy,
Kentai


RE: Can't edit (shop) plugin? Help please! - Diogo Parrinha - 08-11-2010

You're welcome Smile


RE: Can't edit (shop) plugin? Help please! - Kentai - 08-11-2010

Oh, but now there is still one part of the problem I can't solve:

I changed the code in line 1273 to:

PHP Code:
$shop_items .= '<a href="'.$mybb->settings['bburl'].'/newpoints.php?action=shop&amp;shop_action=view&amp;iid='.$iid.'"><img src="'.$mybb->settings['bburl'].'/'.$item['icon'].'" title="'.htmlspecialchars_uni($item['name']).'"></a><br />'

what I did was simply add a "<br/>" tag behind every item icon that would be saved in the output array as this code snippet.

However I can not find the part of the code, which adds the "Items:" text before the first icon.

I want to add a "<br/>" tag after that as well, so the first icon will be in the center and the layout is smoother.

Does anyone know, where I can find that part of the code?
It has eluded me sofar...

sy,
Kentai

PS:
When the problem is solved, I'll post the edited file for other Legacy stlye shop users.


RE: Can't edit (shop) plugin? Help please! - Diogo Parrinha - 08-11-2010

It's inside the language file Smile


RE: Can't edit (shop) plugin? Help please! - Kentai - 08-12-2010

Ok, I owe you.

and here the repay:
It is dirty, dirty coding, but hell if I cared xD

to adapt the item postbit display to vertical postbit (postbit_classic), edit your

newpoints_shop.php

(ONLY ABOVE THE ADMIN PART) to this:

PHP Code:
<?php
/***************************************************************************
 *
 *   NewPoints Shop plugin (/inc/plugins/newpoints/languages/english/newpoints_shop.php)
 *     Author: Pirata Nervo
 *   Copyright: Â© 2009-2010 Pirata Nervo
 *   
 *   Website: http://www.consoleworld.nett
 *
 *   Integrates a shop system with NewPoints.
 *
 ***************************************************************************/
 
/****************************************************************************
    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.
    
    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.
    
    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
****************************************************************************/

// Disallow direct access to this file for security reasons
if(!defined("IN_MYBB"))
{
    die(
"Direct initialization of this file is not allowed.<br /><br />Please make sure IN_MYBB is defined.");
}

$plugins->add_hook("newpoints_start""newpoints_shop_page");

if (
defined("IN_ADMINCP"))
{
    
$plugins->add_hook("newpoints_admin_stats_noaction_end""newpoints_shop_admin_stats");
    
    
$plugins->add_hook('newpoints_admin_load''newpoints_shop_admin');
    
$plugins->add_hook('newpoints_admin_newpoints_menu''newpoints_shop_admin_newpoints_menu');
    
$plugins->add_hook('newpoints_admin_newpoints_action_handler''newpoints_shop_admin_newpoints_action_handler');
    
$plugins->add_hook('newpoints_admin_newpoints_permissions''newpoints_shop_admin_permissions');
    
    
$plugins->add_hook("newpoints_admin_grouprules_add""newpoints_shop_admin_rule");
    
$plugins->add_hook("newpoints_admin_grouprules_edit""newpoints_shop_admin_rule");
    
$plugins->add_hook("newpoints_admin_grouprules_add_insert""newpoints_shop_admin_rule_post");
    
$plugins->add_hook("newpoints_admin_grouprules_edit_update""newpoints_shop_admin_rule_post");
}
else
{
    
$plugins->add_hook("newpoints_stats_start""newpoints_shop_stats");
    
$plugins->add_hook("member_profile_end""newpoints_shop_profile");
    
    
$plugins->add_hook('postbit_prev''newpoints_shop_postbit');
    
$plugins->add_hook('postbit_pm''newpoints_shop_postbit');
    
$plugins->add_hook('postbit_announcement''newpoints_shop_postbit');
    
$plugins->add_hook('postbit''newpoints_shop_postbit');
    
    
$plugins->add_hook("newpoints_default_menu""newpoints_shop_menu");
}

// backup shop fields too
$plugins->add_hook("newpoints_task_backup_tables""newpoints_shop_backup");

function 
newpoints_shop_info()
{
    return array(
        
"name"            => "Shop",
        
"description"    => "Integrates a shop system with NewPoints.",
        
"website"        => "http://www.mybb-plugins.com",
        
"author"        => "Pirata Nervo",
        
"authorsite"    => "http://www.consoleworld.net",
        
"version"        => "1.4",
        
"guid"             => "",
        
"compatibility" => "1*"
    
);
}

function 
newpoints_shop_install()
{
    global 
$db;
    
$db->write_query("ALTER TABLE `".TABLE_PREFIX."users` ADD `newpoints_items` TEXT NOT NULL DEFAULT '';");
    
$db->write_query("ALTER TABLE `".TABLE_PREFIX."newpoints_grouprules` ADD `items_rate` DECIMAL(3,3) NOT NULL default '1';");
    
    
// add settings
    
newpoints_add_setting('newpoints_shop_sendable''newpoints_shop''Send items''Allow users to send items to other users.''yesno''1'1);
    
newpoints_add_setting('newpoints_shop_sellable''newpoints_shop''Sell items''Allow users to sell items.''yesno''1'2);
    
newpoints_add_setting('newpoints_shop_lastpurchases''newpoints_shop''Last Purchases''Number of last purchases to show in statistics.''text''10'3);
    
newpoints_add_setting('newpoints_shop_percent''newpoints_shop''Sell Percentage''The (discounted) rate at which items can be sold for.''text''0.75'4);
    
newpoints_add_setting('newpoints_shop_viewothers''newpoints_shop''Can View Others\' inventories''Allow users to view other users\' inventories. Note, admins always are able to view other users\' inventories.''yesno''1'5);
    
newpoints_add_setting('newpoints_shop_itemsprofile''newpoints_shop''Items on profile''Number of items to show in profile page. Set to 0 to disable this feature.''text''5'6);
    
newpoints_add_setting('newpoints_shop_itemspostbit''newpoints_shop''Items on postbit''Number of items to show in postbit. Set to 0 to disable this feature.''text''5'7);
    
    
$db->write_query("CREATE TABLE `".TABLE_PREFIX."newpoints_shop_categories` (
      `cid` bigint(30) UNSIGNED NOT NULL auto_increment,
      `name` varchar(100) NOT NULL default '',
      `description` TEXT NOT NULL default '',
      `visible` smallint(1) NOT NULL default '1',
      `icon` varchar(255) NOT NULL default '',
      `usergroups` varchar(100) NOT NULL default '',
      `disporder` int(5) NOT NULL default '0',
      `items` int(10) NOT NULL default '0',
      `expanded` smallint(1) NOT NULL default '1',
      PRIMARY KEY  (`cid`)
        ) TYPE=MyISAM"
);
    
    
$db->write_query("CREATE TABLE `".TABLE_PREFIX."newpoints_shop_items` (
      `iid` bigint(30) UNSIGNED NOT NULL auto_increment,
      `name` varchar(100) NOT NULL default '',
      `description` TEXT NOT NULL default '',
      `price` DECIMAL(16,2) NOT NULL default '0',
      `icon` varchar(255) NOT NULL default '',
      `visible` smallint(1) NOT NULL default '1',
      `disporder` int(5) NOT NULL default '0',
      `infinite` smallint(1) NOT NULL default '0',
      `stock` int(10) NOT NULL default '0',
      `sendable` smallint(1) NOT NULL default '1',
      `sellable` smallint(1) NOT NULL default '1',
      `cid` int(10) NOT NULL default '0',
      `pm` text NOT NULL,
      PRIMARY KEY  (`iid`)
        ) TYPE=MyISAM"
);
    
    
rebuild_settings();
}

function 
newpoints_shop_is_installed()
{
    global 
$db;
    if(
$db->field_exists('newpoints_items''users'))
    {
        return 
true;
    }
    return 
false;
}

function 
newpoints_shop_uninstall()
{
    global 
$db;
    
$db->write_query("ALTER TABLE `".TABLE_PREFIX."users` DROP `newpoints_items`;");
    
$db->write_query("ALTER TABLE `".TABLE_PREFIX."newpoints_grouprules` DROP `items_rate`;");
    
    
// delete settings
    
newpoints_remove_settings("'newpoints_shop_sendable','newpoints_shop_sellable','newpoints_shop_lastpurchases','newpoints_shop_percent','newpoints_shop_viewothers','newpoints_shop_itemsprofile','newpoints_shop_itemspostbit'");
    
rebuild_settings();
    
    if(
$db->table_exists('newpoints_shop_categories'))
    {
        
$db->drop_table('newpoints_shop_categories');
    }
    
    if(
$db->table_exists('newpoints_shop_items'))
    {
        
$db->drop_table('newpoints_shop_items');
    }
    
    
newpoints_remove_log(array('shop_purchase''shop_send''shop_sell'));
}

function 
newpoints_shop_activate()
{
    global 
$db$mybb;
    
    
newpoints_add_template('newpoints_shop''
<html>
<head>
<title>{$lang->newpoints} - {$lang->newpoints_shop}</title>
{$headerinclude}
</head>
<body>
{$header}
<table width="100%" border="0" align="center">
<tr>
<td valign="top" width="180">
<table border="0" cellspacing="{$theme[\'borderwidth\']}" cellpadding="{$theme[\'tablespace\']}" class="tborder">
<tr>
<td class="thead"><strong>{$lang->newpoints_menu}</strong></td>
</tr>
{$options}
</table>
</td>
<td valign="top">
{$inline_errors}
<table border="0" cellspacing="{$theme[\'borderwidth\']}" cellpadding="{$theme[\'tablespace\']}" class="tborder">
<tr>
<td class="thead" colspan="5"><strong><div style="float: right"><a href="{$mybb->settings[\'bburl\']}/newpoints.php?action=shop&amp;shop_action=myitems" style="text-decoration: underline">{$lang->newpoints_shop_myitems}</a></div>{$lang->newpoints_shop}</strong></td>
</tr>
<tr>
<td class="tcat" width="1%"><strong>{$lang->newpoints_shop_icon}</strong></td>
<td class="tcat"><strong>{$lang->newpoints_shop_name}</strong></td>
<td class="tcat" width="20%" align="center"><strong>{$lang->newpoints_shop_price}</strong></td>
<td class="tcat" width="20%" align="center"><strong>{$lang->newpoints_shop_stock}</strong></td>
<td class="tcat" width="10%" align="center"><strong>{$lang->newpoints_shop_buy}</strong></td>
</tr>
{$cats}
</table>
</td>
</tr>
</table>
{$footer}
</body>
</html>'
);
    
    
newpoints_add_template('newpoints_shop_category''
<table border="0" cellspacing="{$theme[\'borderwidth\']}" cellpadding="{$theme[\'tablespace\']}" class="tborder">
<tr>
<td class="thead" colspan="5"><div class="expcolimage"><img src="{$theme[\'imgdir\']}/{$expcolimage}" id="cat_{$category[\'cid\']}_img" class="expander" alt="{$expaltext}" title="{$expaltext}" /></div>
{$category[\'icon\']} <strong>{$category[\'name\']}</strong> <span class="smalltext">{$category[\'description\']}</span></td>
</tr>
</table>
<div style="max-height: 200px; overflow: auto;">
<table border="0" cellspacing="{$theme[\'borderwidth\']}" cellpadding="{$theme[\'tablespace\']}" class="tborder">
<tbody id="cat_{$category[\'cid\']}_e" style="{$expdisplay}">
{$items}
</tbody>
</table>
</div>'
);
    
    
newpoints_add_template('newpoints_shop_item''
<tr>
<td class="{$bgcolor}" width="1%" valign="middle" align="center">{$item[\'icon\']}</td>
<td class="{$bgcolor}" valign="middle"><a href="{$mybb->settings[\'bburl\']}/newpoints.php?action=shop&amp;shop_action=view&amp;iid={$item[\'iid\']}">{$item[\'name\']}</a><br /><span class="smalltext">{$item[\'description\']}</span></td>
<td class="{$bgcolor}" width="20%" align="center" valign="middle">{$item[\'price\']}</td>
<td class="{$bgcolor}" width="20%" align="center" valign="middle">{$item[\'stock\']}</td>
<td class="{$bgcolor}" width="10%" align="center" valign="middle"><form action="newpoints.php?action=do_shop&amp;shop_action=buy" method="POST"><input type="hidden" name="postcode" value="{$mybb->post_code}"><input type="hidden" name="iid" value="{$item[\'iid\']}"><input type="submit" name="buy" value="{$lang->newpoints_shop_buy}"></form></td>
</tr>'
);
    
    
newpoints_add_template('newpoints_shop_no_items''
<tr>
<td class="trow1" colspan="5">{$lang->newpoints_shop_no_items}</td>
</tr>'
);
    
    
newpoints_add_template('newpoints_shop_no_cats''
<tr>
<td class="trow1" colspan="5">{$lang->newpoints_shop_no_cats}</td>
</tr>'
);
    
    
newpoints_add_template('newpoints_shop_myitems''
<html>
<head>
<title>{$lang->newpoints} - {$lang->newpoints_shop_myitems}</title>
{$headerinclude}
</head>
<body>
{$header}
<table width="100%" border="0" align="center">
<tr>
<td valign="top" width="180">
<table border="0" cellspacing="{$theme[\'borderwidth\']}" cellpadding="{$theme[\'tablespace\']}" class="tborder">
<tr>
<td class="thead"><strong>{$lang->newpoints_menu}</strong></td>
</tr>
{$options}
</table>
</td>
<td valign="top">
{$inline_errors}
<table border="0" cellspacing="{$theme[\'borderwidth\']}" cellpadding="{$theme[\'tablespace\']}" class="tborder">
<tr>
<td class="thead" colspan="4"><strong><div style="float: right"><a href="{$mybb->settings[\'bburl\']}/newpoints.php?action=shop">{$lang->newpoints_shop}</a></div>{$lang->newpoints_shop_myitems}</strong></td>
</tr>
{$items}
</table>
{$multipage}
</td>
</tr>
</table>
{$footer}
</body>
</html>'
);
    
    
newpoints_add_template('newpoints_shop_myitems_item''
<td class="{$bgcolor}" width="50%" valign="middle" align="center">
<fieldset class="{$invert_bgcolor}" style="width: 80%;"><legend>{$item[\'icon\']} <strong><a href="{$mybb->settings[\'bburl\']}/newpoints.php?action=shop&amp;shop_action=view&amp;iid={$item[\'iid\']}">{$item[\'name\']}</a></strong></legend>
<div align="left"><span class="smalltext">{$item[\'description\']}</span></div>
<div align="left">
{$lang->newpoints_shop_price}: {$item[\'price\']}<br />
{$lang->newpoints_shop_quantity}: {$item[\'quantity\']}
</div>
</fieldset>
<fieldset class="{$invert_bgcolor}" style="width: 80%; margin-bottom: 5px;">
<legend>{$lang->newpoints_shop_options}</legend>
<table border="0">
<tr>
{$send}{$sell}
</tr>
</table>
</fieldset>
</td>
'
);
    
    
newpoints_add_template('newpoints_shop_myitems_item_empty''
<td class="{$bgcolor}" width="50%" valign="middle"></td>
'
);
    
    
newpoints_add_template('newpoints_shop_myitems_no_items''
<tr>
<td class="trow1" colspan="2">{$lang->newpoints_shop_no_items}</td>
</tr>'
);
    
    
newpoints_add_template('newpoints_shop_do_action''
<head>
<title>{$lang->newpoints} - {$lang->newpoints_shop_action}</title>
{$headerinclude}
</head>
<body>
{$header}
<form action="newpoints.php?action=do_shop" method="POST">
<input type="hidden" name="postcode" value="{$mybb->post_code}">
<input type="hidden" name="shop_action" value="{$shop_action}">
{$fields}
<table border="0" cellspacing="{$theme[\'borderwidth\']}" cellpadding="{$theme[\'tablespace\']}" class="tborder">
<tr>
<td class="thead" colspan="{$colspan}"><strong>{$lang->newpoints_shop_action}:</strong> {$item[\'name\']}</td>
</tr>
<tr>
{$data}
</tr>
<tr>
<td class="tfoot" width="100%" align="center" colspan="{$colspan}"><input type="submit" name="submit" value="{$lang->newpoints_shop_confirm}"></td>
</tr>
</table>
</form>
{$footer}
</body>
</html>'
);
    
    
newpoints_add_template('newpoints_shop_stats''
<table border="0" cellspacing="{$theme[\'borderwidth\']}" cellpadding="{$theme[\'tablespace\']}" class="tborder">
<tr>
<td class="thead" colspan="4"><strong>{$lang->newpoints_shop_lastpurchases}</strong></td>
</tr>
<tr>
<td class="tcat" width="40%"><strong>{$lang->newpoints_shop_user}</strong></td>
<td class="tcat" width="30%"><strong>{$lang->newpoints_shop_item}</strong></td>
<td class="tcat" width="30%" align="center"><strong>{$lang->newpoints_shop_date}</strong></td>
</tr>
{$last_purchases}
</table><br />'
);
    
    
newpoints_add_template('newpoints_shop_stats_purchase''
<tr>
<td class="{$bgcolor}" width="40%">{$purchase[\'user\']}</td>
<td class="{$bgcolor}" width="30%">{$purchase[\'item\']}</td>
<td class="{$bgcolor}" width="30%" align="center">{$purchase[\'date\']}</td>
</tr>'
);
    
    
newpoints_add_template('newpoints_shop_stats_nopurchase''
<tr>
<td class="trow1" width="100%" colspan="3">{$lang->newpoints_shop_no_purchases}</td>
</tr>'
);
    
    
newpoints_add_template('newpoints_shop_profile''<tr>
    <td class="trow2"><strong>{$lang->newpoints_shop_items}:</strong></td>
    <td class="trow2">{$shop_items} <span class="smalltext">(<a href="{$mybb->settings[\'bburl\']}/newpoints.php?action=shop&amp;shop_action=myitems&amp;uid={$memprofile[\'uid\']}">{$lang->newpoints_shop_view_all_items}</a>)</span></td>
</tr>'
);

    
newpoints_add_template('newpoints_shop_postbit''
    <br />{$lang->newpoints_shop_items}: {$shop_items} <span class="smalltext">(<a href="{$mybb->settings[\'bburl\']}/newpoints.php?action=shop&amp;shop_action=myitems&amp;uid={$post[\'uid\']}">{$lang->newpoints_shop_view_all_items}</a>)</span>'
);
    
    
newpoints_add_template('newpoints_shop_view_item''
<html>
<head>
<title>{$lang->newpoints} - {$lang->newpoints_shop_view_item}</title>
{$headerinclude}
</head>
<body>
{$header}
<table width="100%" border="0" align="center">
<tr>
<td valign="top" width="180">
<table border="0" cellspacing="{$theme[\'borderwidth\']}" cellpadding="{$theme[\'tablespace\']}" class="tborder">
<tr>
<td class="thead"><strong>{$lang->newpoints_menu}</strong></td>
</tr>
{$options}
</table>
</td>
<td valign="top">
{$inline_errors}
<table border="0" cellspacing="{$theme[\'borderwidth\']}" cellpadding="{$theme[\'tablespace\']}" class="tborder">
<tr>
<td class="thead" width="100%"><strong>{$lang->newpoints_shop_view_item}:</strong> {$item[\'name\']}</td>
</tr>
<tr>
<td class="trow1" width="100%">{$item[\'icon\']} {$item[\'name\']}<br /><span class="smalltext">{$item[\'description\']}</span></td>
</tr>
<tr>
<td class="trow2" width="100%"><strong>{$lang->newpoints_shop_price}:</strong> {$item[\'price\']}</td>
</tr>
<tr>
<td class="trow1" width="100%"><strong>{$lang->newpoints_shop_stock}:</strong> {$item[\'stock\']}</td>
</tr>
<tr>
<td class="trow2" width="100%"><strong>{$lang->newpoints_shop_sendable}:</strong> {$item[\'sendable\']}</td>
</tr>
<tr>
<td class="trow1" width="100%"><strong>{$lang->newpoints_shop_sellable}:</strong> {$item[\'sellable\']}</td>
</tr>
<tr>
<td class="tfoot" width="100%" align="center" colspan="2"><form action="newpoints.php?action=do_shop&amp;shop_action=buy" method="POST"><input type="hidden" name="postcode" value="{$mybb->post_code}"><input type="hidden" name="iid" value="{$item[\'iid\']}"><input type="submit" name="buy" value="{$lang->newpoints_shop_buy}"></form></td>
</tr>
</table>
{$footer}
</body>
</html>
'
);
    
    
// edit templates
    
newpoints_find_replace_templatesets('newpoints_statistics''#'.preg_quote('width="60%">').'#''width="60%">{$newpoints_shop_lastpurchases}');
    
newpoints_find_replace_templatesets('newpoints_postbit''#'.preg_quote('{$donate}').'#''{$donate}{$post[\'newpoints_shop_items\']}');
    
    require_once 
MYBB_ROOT."inc/adminfunctions_templates.php";
    
find_replace_templatesets("member_profile"'#'.preg_quote('{$warning_level}').'#''{$warning_level}'.'{$newpoints_shop_profile}');
}

function 
newpoints_shop_deactivate()
{
    global 
$db$mybb;
    
    
newpoints_remove_templates("'newpoints_shop','newpoints_shop_category','newpoints_shop_item','newpoints_shop_no_items','newpoints_shop_no_cats','newpoints_shop_myitems','newpoints_shop_myitems_item','newpoints_shop_myitems_no_items','newpoints_shop_do_action','newpoints_shop_stats','newpoints_shop_stats_purchase','newpoints_shop_stats_nopurchase','newpoints_shop_myitems_item_empty','newpoints_shop_profile','newpoints_shop_view_item','newpoints_shop_postbit'");
    
    
// edit templates
    
newpoints_find_replace_templatesets('newpoints_statistics''#'.preg_quote('{$newpoints_shop_lastpurchases}').'#''');
    
newpoints_find_replace_templatesets('newpoints_profile''#'.preg_quote('{$newpoints_shop_profile}').'#''');
    
newpoints_find_replace_templatesets('newpoints_postbit''#'.preg_quote('{$post[\'newpoints_shop_items\']}').'#''');
    
    require_once 
MYBB_ROOT."inc/adminfunctions_templates.php";
    
find_replace_templatesets("member_profile"'#'.preg_quote('{$newpoints_shop_profile}').'#'''0);
}

// show shop in the list
function newpoints_shop_menu(&$menu)
{
    global 
$mybb$lang;
    
newpoints_lang_load("newpoints_shop");
    
    if (
$mybb->input['action'] == 'shop')
        
$menu[] = "&raquo; <a href=\"{$mybb->settings['bburl']}/newpoints.php?action=shop\">".$lang->newpoints_shop."</a>";
    else
        
$menu[] = "<a href=\"{$mybb->settings['bburl']}/newpoints.php?action=shop\">".$lang->newpoints_shop."</a>";
}

function 
newpoints_shop_get_item($iid 0)
{
    global 
$db$mybb;
    if (!
$iid)
        return 
false;
        
    
$query $db->simple_select('newpoints_shop_items''*''iid=\''.intval($iid).'\'');
    
$item $db->fetch_array($query);
        
    return 
$item;
}

function 
newpoints_shop_get_category($cid 0)
{
    global 
$db$mybb;
    if (!
$cid)
        return 
false;
        
    
$query $db->simple_select('newpoints_shop_categories''*''cid=\''.intval($cid).'\'');
    
$cat $db->fetch_array($query);
        
    return 
$cat;
}

/* Checks if the primary or any of the additional groups of the current user are in the groups list passed as a parameter
 * @param String group ids seperated by a comma
 * @return true if the user has permissions, false if not
*/
function newpoints_check_permissions($groups_comma)
{
    global 
$mybb;
    
    if (
$groups_comma == '')
        return 
false;
    
    
$groups explode(","$groups_comma);
    
$add_groups explode(","$mybb->user['additionalgroups']);
    
    if (!
in_array($mybb->user['usergroup'], $groups)) { // primary user group not allowed
        // check additional groups
        
if ($add_groups) {
            if (
count(array_intersect($add_groups$groups)) == 0)
                return 
false;
            else
                return 
true;
        }
        else 
            return 
false;
    }
    else
        return 
true;
}

function 
newpoints_shop_page()
{
    global 
$mybb$db$lang$cache$theme$header$templates$plugins$headerinclude$footer$options$inline_errors;
    
    if (!
$mybb->user['uid'])
        return;
        
    
newpoints_lang_load("newpoints_shop");
        
    if (
$mybb->input['action'] == "do_shop")
    {
        
verify_post_check($mybb->input['postcode']);
        
        
$plugins->run_hooks("newpoints_do_shop_start");
        
        switch (
$mybb->input['shop_action'])
        {
            case 
'buy':
                
$plugins->run_hooks("newpoints_shop_buy_start");
            
                
// check if the item exists
                
if (!($item newpoints_shop_get_item($mybb->input['iid'])))
                {
                    
error($lang->newpoints_shop_invalid_item);
                }
                
                
// check if the item is assigned to category
                
if (!($cat newpoints_shop_get_category($item['cid'])))
                {
                    
error($lang->newpoints_shop_invalid_cat);
                }

                
// check if we have permissions to view the parent category
                
if (!newpoints_check_permissions($cat['usergroups']))
                {
                    
error_no_permission();
                }
                
                if (
$item['visible'] == || $cat['visible'] == 0)
                    
error_no_permission();
                
                if (
floatval($item['price']) > floatval($mybb->user['newpoints']))
                {
                    
$errors[] = $lang->newpoints_shop_not_enough;
                }
                
                if (
$item['infinite'] != && $item['stock'] <= 0)
                {
                    
$errors[] = $lang->newpoints_shop_out_of_stock;
                }
                
                if (!empty(
$errors))
                {
                    
$inline_errors inline_error($errors$lang->newpoints_shop_inline_errors);
                    
$mybb->input = array();
                    
$mybb->input['action'] = 'shop';
                }
                else {
                    
$myitems = @unserialize($mybb->user['newpoints_items']);
                    if (!
$myitems)
                        
$myitems = array();
                    
$myitems[] = $item['iid'];
                    
$db->update_query('users', array('newpoints_items' => serialize($myitems)), 'uid=\''.$mybb->user['uid'].'\'');
                    
                    
// update stock
                    
if ($item['infinite'] != 1)
                        
$db->update_query('newpoints_shop_items', array('stock' => $item['stock']-1), 'iid=\''.$item['iid'].'\'');
                    
                    
// check group rules - primary group check
                    
$grouprules newpoints_getrules('group'$mybb->user['usergroup']);
                    if (!
$grouprules)
                        
$grouprules['items_rate'] = 1.0// no rule set so default income rate is 1
                    
                    // if the group items rate is 0, the price of the item is 0
                    
if (floatval($grouprules['items_rate']) == 0)
                        
$item['price'] = 0;
                    else
                        
$item['price'] = $item['price']*floatval($grouprules['items_rate']);
                    
                    
// get money from user
                    
newpoints_addpoints($mybb->user['uid'], -(floatval($item['price'])));
                    
                    if (!empty(
$item['pm']))
                    {
                        
// send PM if item has private message
                        
newpoints_send_pm(array('subject' => $lang->newpoints_shop_bought_item_pm_subject'message' => $item['pm'], 'touid' => $mybb->user['uid'], 'receivepms' => 1), -1);
                    }
                    
                    
$plugins->run_hooks("newpoints_shop_buy_end");
                    
                    
// log purchase
                    
newpoints_log('shop_purchase'$lang->sprintf($lang->newpoints_shop_purchased_log$item['iid'], $item['price']));
                    
                    
redirect($mybb->settings['bburl']."/newpoints.php?action=shop"$lang->newpoints_shop_item_bought$lang->newpoints_shop_item_bought_title);
                }
            break;
            
            case 
'send':
                
$plugins->run_hooks("newpoints_shop_send_start");
            
                
// check if the item exists
                
if (!($item newpoints_shop_get_item($mybb->input['iid'])))
                {
                    
error($lang->newpoints_shop_invalid_item);
                }
                
                
// check if the item is assigned to category
                
if (!($cat newpoints_shop_get_category($item['cid'])))
                {
                    
error($lang->newpoints_shop_invalid_cat);
                }

                
// check if we have permissions to view the parent category
                
if (!newpoints_check_permissions($cat['usergroups']))
                {
                    
error_no_permission();
                }
                
                if (
$item['visible'] == || $cat['visible'] == 0)
                    
error_no_permission();
                
                
$myitems = @unserialize($mybb->user['newpoints_items']);
                if (!
$myitems)
                    
error($lang->newpoints_shop_inventory_empty);
                
                
// make sure we own the item
                
$key array_search($item['iid'], $myitems);
                if (
$key === false)
                    
error($lang->newpoints_shop_selected_item_not_owned);
                    
                
$lang->newpoints_shop_action $lang->newpoints_shop_send_item;
                
$item['name'] = htmlspecialchars_uni($item['name']);
                
                global 
$shop_action$data$colspan;
                
$colspan 2;
                
$shop_action 'do_send';
                
$fields '<input type="hidden" name="iid" value="'.$item['iid'].'">';
                
$data "<td class=\"trow1\" width=\"50%\"><strong>".$lang->newpoints_shop_send_item_username.":</strong><br /><small>".$lang->newpoints_shop_send_item_message."</small></td><td class=\"trow1\" width=\"50%\"><input type=\"text\" class=\"textbox\" name=\"username\" value=\"\"></td>";
                
                
$plugins->run_hooks("newpoints_shop_send_end");
                
                eval(
"\$page = \"".$templates->get('newpoints_shop_do_action')."\";");
                
output_page($page);
            break;
            
            case 
'do_send':
                
$plugins->run_hooks("newpoints_shop_do_send_start");
            
                
// check if the item exists
                
if (!($item newpoints_shop_get_item($mybb->input['iid'])))
                {
                    
error($lang->newpoints_shop_invalid_item);
                }
                
                
// check if the item is assigned to category
                
if (!($cat newpoints_shop_get_category($item['cid'])))
                {
                    
error($lang->newpoints_shop_invalid_cat);
                }

                
// check if we have permissions to view the parent category
                
if (!newpoints_check_permissions($cat['usergroups']))
                {
                    
error_no_permission();
                }
                
                if (
$item['visible'] == || $cat['visible'] == 0)
                    
error_no_permission();
                
                
$myitems = @unserialize($mybb->user['newpoints_items']);
                if (!
$myitems)
                    
error($lang->newpoints_shop_inventory_empty);
                
                
// make sure we own the item
                
$key array_search($item['iid'], $myitems);
                if (
$key === false)
                    
error($lang->newpoints_shop_selected_item_not_owned);
                
                
$username trim($mybb->input['username']);
                if (!(
$user newpoints_getuser_byname($username)))
                {
                    
error($lang->newpoints_shop_invalid_user);
                }
                else
                {
                    
// send item to the selected user
                    
$useritems = @unserialize($user['newpoints_items']);
                    if (!
$useritems)
                        
$useritems = array();
                    
$useritems[] = $item['iid'];
                    
$db->update_query('users', array('newpoints_items' => serialize($useritems)), 'uid=\''.$user['uid'].'\'');
                    
                    
// remove item from our inventory
                    
unset($myitems[$key]);
                    
sort($myitems);
                    
$db->update_query('users', array('newpoints_items' => serialize($myitems)), 'uid=\''.$mybb->user['uid'].'\'');
                    
                    
$plugins->run_hooks("newpoints_shop_do_send_end");
                    
                    
// send pm to user
                    
newpoints_send_pm(array('subject' => $lang->newpoints_shop_item_received_title'message' => $lang->sprintf($lang->newpoints_shop_item_receivedhtmlspecialchars_uni($mybb->user['username']), htmlspecialchars_uni($item['name'])), 'touid' => $user['uid'], 'receivepms' => 1), -1);
                    
                    
// log
                    
newpoints_log('shop_send'$lang->sprintf($lang->newpoints_shop_sent_log$item['iid'], $user['uid'], $user['username']));
                    
                    
redirect($mybb->settings['bburl']."/newpoints.php?action=shop&amp;shop_action=myitems"$lang->newpoints_shop_item_sent$lang->newpoints_shop_item_sent_title);
                }
            break;
            
            case 
'sell':
                
$plugins->run_hooks("newpoints_shop_sell_start");
            
                
// check if the item exists
                
if (!($item newpoints_shop_get_item($mybb->input['iid'])))
                {
                    
error($lang->newpoints_shop_invalid_item);
                }
                
                
// check if the item is assigned to category
                
if (!($cat newpoints_shop_get_category($item['cid'])))
                {
                    
error($lang->newpoints_shop_invalid_cat);
                }

                
// check if we have permissions to view the parent category
                
if (!newpoints_check_permissions($cat['usergroups']))
                {
                    
error_no_permission();
                }
                
                if (
$item['visible'] == || $cat['visible'] == 0)
                    
error_no_permission();
                
                
$myitems = @unserialize($mybb->user['newpoints_items']);
                if (!
$myitems)
                    
error($lang->newpoints_shop_inventory_empty);
                
                
// make sure we own the item
                
$key array_search($item['iid'], $myitems);
                if (
$key === false)
                    
error($lang->newpoints_shop_selected_item_not_owned);
                    
                
$lang->newpoints_shop_action $lang->newpoints_shop_sell_item;
                
$item['name'] = htmlspecialchars_uni($item['name']);
                
                global 
$shop_action$data$colspan;
                
$colspan 1;
                
$shop_action 'do_sell';
                
$fields '<input type="hidden" name="iid" value="'.$item['iid'].'">';
                
$data "<td class=\"trow1\" width=\"100%\">".$lang->sprintf($lang->newpoints_shop_sell_item_confirmhtmlspecialchars_uni($item['name']), newpoints_format_points(floatval($item['price'])*$mybb->settings['newpoints_shop_percent']))."</td>";
                
                
$plugins->run_hooks("newpoints_shop_sell_end");
                
                eval(
"\$page = \"".$templates->get('newpoints_shop_do_action')."\";");
                
output_page($page);
            break;
            
            case 
'do_sell':
                
$plugins->run_hooks("newpoints_shop_do_sell_start");
            
                
// check if the item exists
                
if (!($item newpoints_shop_get_item($mybb->input['iid'])))
                {
                    
error($lang->newpoints_shop_invalid_item);
                }
                
                
// check if the item is assigned to category
                
if (!($cat newpoints_shop_get_category($item['cid'])))
                {
                    
error($lang->newpoints_shop_invalid_cat);
                }

                
// check if we have permissions to view the parent category
                
if (!newpoints_check_permissions($cat['usergroups']))
                {
                    
error_no_permission();
                }
                
                if (
$item['visible'] == || $cat['visible'] == 0)
                    
error_no_permission();
                
                
$myitems = @unserialize($mybb->user['newpoints_items']);
                if (!
$myitems)
                    
error($lang->newpoints_shop_inventory_empty);
                
                
// make sure we own the item
                
$key array_search($item['iid'], $myitems);
                if (
$key === false)
                    
error($lang->newpoints_shop_selected_item_not_owned);
                    
                
// remove item from our inventory
                
unset($myitems[$key]);
                
sort($myitems);
                
$db->update_query('users', array('newpoints_items' => serialize($myitems)), 'uid=\''.$mybb->user['uid'].'\'');
                
                
// update stock
                
if ($item['infinite'] != 1)
                    
$db->update_query('newpoints_shop_items', array('stock' => $item['stock']+1), 'iid=\''.$item['iid'].'\'');
                
                
newpoints_addpoints($mybb->user['uid'], floatval($item['price'])*$mybb->settings['newpoints_shop_percent']);
                
                
$plugins->run_hooks("newpoints_shop_do_sell_end");
                    
                
// log
                
newpoints_log('shop_sell'$lang->sprintf($lang->newpoints_shop_sell_log$item['iid'], floatval($item['price'])*$mybb->settings['newpoints_shop_percent']));
                    
                
redirect($mybb->settings['bburl']."/newpoints.php?action=shop&amp;shop_action=myitems"$lang->newpoints_shop_item_sell$lang->newpoints_shop_item_sell_title);
            break;
            
            default:
                
error_no_permission();
        }
        
        
$plugins->run_hooks("newpoints_do_shop_end");
    }
    
    
// shop page
    
if ($mybb->input['action'] == "shop")
    {
        
$plugins->run_hooks("newpoints_shop_start");
        
        if (
$mybb->input['shop_action'] == 'view')
        {
            
// check if the item exists
            
if (!($item newpoints_shop_get_item($mybb->input['iid'])))
            {
                
error($lang->newpoints_shop_invalid_item);
            }
            
            
// check if the item is assigned to category
            
if (!($cat newpoints_shop_get_category($item['cid'])))
            {
                
error($lang->newpoints_shop_invalid_cat);
            }

            
// check if we have permissions to view the parent category
            
if (!newpoints_check_permissions($cat['usergroups']))
            {
                
error_no_permission();
            }
            
            if (
$item['visible'] == || $cat['visible'] == 0)
                
error_no_permission();
            
            
$item['name'] = htmlspecialchars_uni($item['name']);
            
$item['description'] = htmlspecialchars_uni($item['description']);
            
            
// check group rules - primary group check
            
$grouprules newpoints_getrules('group'$mybb->user['usergroup']);
            if (!
$grouprules)
                
$grouprules['items_rate'] = 1.0// no rule set so default income rate is 1
            
            // if the group items rate is 0, the price of the item is 0
            
if (floatval($grouprules['items_rate']) == 0)
                
$item['price'] = 0;
            else
                
$item['price'] = $item['price']*floatval($grouprules['items_rate']);
            
            
$item['price'] = newpoints_format_points($item['price']);
            if (
$item['price'] > $mybb->user['newpoints'])
                
$item['price'] = '<span style="color: #FF0000;">'.$item['price'].'</span>';
                
            
// build icon
            
if ($item['icon'] != '')
            {
                
$item['icon'] = htmlspecialchars_uni($item['icon']);
                
$item['icon'] = '<img src="'.$mybb->settings['bburl'].'/'.$item['icon'].'">';
            }
            else
                
$item['icon'] = '<img src="'.$mybb->settings['bburl'].'/images/newpoints/default.png">';
                
            if (
$item['infinite'] == 1)
                
$item['stock'] = $lang->newpoints_shop_infinite;
            else
                
$item['stock'] = intval($item['stock']);
                
            if (
$item['sendable'] == 1)
                
$item['sendable'] = $lang->newpoints_shop_yes;
            else
                
$item['sendable'] = $lang->newpoints_shop_no;
                
            if (
$item['sellable'] == 1)
                
$item['sellable'] = $lang->newpoints_shop_yes;
            else
                
$item['sellable'] = $lang->newpoints_shop_no;
            
            eval(
"\$page = \"".$templates->get('newpoints_shop_view_item')."\";");
        }
        elseif (
$mybb->input['shop_action'] == 'myitems')
        {
            
$uid intval($mybb->input['uid']);
            
$uidpart '';
            if (
$uid 0)
            {
                
$user get_user($uid);
                
// we're viewing someone else's inventory
                
if (!empty($user))
                {
                    
// we can't view others inventories if we don't have enough previleges
                    
if ($mybb->settings['newpoints_shop_viewothers'] != && $mybb->usergroup['cancp'] != && $mybb->user['uid'] != $uid)
                        
error_no_permission();
                        
                    
$myitems = @unserialize($user['newpoints_items']);
                    
$lang->newpoints_shop_myitems $lang->sprintf($lang->newpoints_shop_items_usernamehtmlspecialchars_uni($user['username']));
                    
$uidpart "&amp;uid=".$uid// we need this for pagination
                
}
                else
                    
$myitems = @unserialize($mybb->user['newpoints_items']);
            }
            else
                
$myitems = @unserialize($mybb->user['newpoints_items']);
            
$items '';
            
$newrow true;
            
$invert_bgcolor alt_trow();
            
            if (
$mybb->settings['newpoints_shop_sendable'] != 1)
                
$sendable false;
            else
                
$sendable true;
                
            if (
$mybb->settings['newpoints_shop_sellable'] != 1)
                
$sellable false;
            else
                
$sellable true;
                
            require_once 
MYBB_ROOT."inc/class_parser.php";
            
$parser = new postParser;
                
            
$parser_options = array(
                
'allow_mycode' => 1,
                
'allow_smilies' => 1,
                
'allow_imgcode' => 0,
                
'allow_html' => 0,
                
'filter_badwords' => 1
            
);
            
            if (!empty(
$myitems))
            {
                
// pagination
                
$per_page 10;
                
$mybb->input['page'] = intval($mybb->input['page']);
                if(
$mybb->input['page'] && $mybb->input['page'] > 1)
                {
                    
$mybb->input['page'] = intval($mybb->input['page']);
                    
$start = ($mybb->input['page']*$per_page)-$per_page;
                }
                else
                {
                    
$mybb->input['page'] = 1;
                    
$start 0;
                }
                
                
// total items
                
$total_rows $db->fetch_field($db->simple_select("newpoints_shop_items""COUNT(iid) as items"'visible=1 AND iid IN ('.implode(','array_unique($myitems)).')'), "items");
                
                
// multi-page
                
if ($total_rows $per_page)
                    
$multipage multipage($total_rows$per_page$mybb->input['page'], $mybb->settings['bburl']."/newpoints.php?action=shop&shop_action=myitems".$uidpart);
                
                
$query $db->simple_select('newpoints_shop_items''*''visible=1 AND iid IN ('.implode(','array_unique($myitems)).')', array('limit' => "{$start}{$per_page}"));
                while (
$item $db->fetch_array($query))
                {
                    if (
$newrow === true)
                    {
                        
$trstart '<tr>';
                        
$trend '';
                        
$newrow false;
                    }
                    elseif (
$newrow === false)
                    {
                        
$trstart '';
                        
$trend '</tr>';
                        
$newrow true;
                    }
                    
                    if (
$sellable === true && $item['sellable'])
                    {
                        if (
$sendable === true && $item['sendable'])
                            
$tdstart '<td width="50%">';
                        else
                            
$tdstart '<td width="100%">';
                        
                        
$sell $tdstart.'<form action="newpoints.php" method="POST"><input type="hidden" name="action" value="do_shop"><input type="hidden" name="shop_action" value="sell"><input type="hidden" name="iid" value="'.$item['iid'].'"><input type="hidden" name="postcode" value="'.$mybb->post_code.'"><input type="submit" name="submit" value="'.$lang->newpoints_shop_sell.'"></form></td>';
                    }
                    else
                        
$sell '';
                    
                    if (
$sendable === true && $item['sendable'])
                    {
                        if (
$sell == '')
                            
$tdstart '<td width="100%">';
                        else
                            
$tdstart '<td width="50%">';
                        
                        
$send $tdstart.'<form action="newpoints.php" method="POST"><input type="hidden" name="action" value="do_shop"><input type="hidden" name="shop_action" value="send"><input type="hidden" name="iid" value="'.$item['iid'].'"><input type="hidden" name="postcode" value="'.$mybb->post_code.'"><input type="submit" name="submit" value="'.$lang->newpoints_shop_send.'"></form></td>';
                    }
                    else
                        
$send '';
                        
                    if (!
$send && !$sell)
                        
$send $lang->newpoints_shop_no_options;
                        
                    
$item['description'] = $parser->parse_message($item['description'], $parser_options);
                    
                    
// check group rules - primary group check
                    
$grouprules newpoints_getrules('group'$mybb->user['usergroup']);
                    if (!
$grouprules)
                        
$grouprules['items_rate'] = 1.0// no rule set so default income rate is 1
                    
                    // if the group items rate is 0, the price of the item is 0
                    
if (floatval($grouprules['items_rate']) == 0)
                        
$item['price'] = 0;
                    else
                        
$item['price'] = $item['price']*floatval($grouprules['items_rate']);
                    
                    
$item['price'] = newpoints_format_points($item['price']);
                    
$item['quantity'] = count(array_keys($myitems$item['iid']));
                    
                    
// build icon
                    
if ($item['icon'] != '')
                    {
                        
$item['icon'] = htmlspecialchars_uni($item['icon']);
                        
$item['icon'] = '<img src="'.$mybb->settings['bburl'].'/'.$item['icon'].'">';
                    }
                    else
                        
$item['icon'] = '<img src="'.$mybb->settings['bburl'].'/images/newpoints/default.png">';
                    
                    
$bgcolor alt_trow();
                    
$invert_bgcolor alt_trow();
                    eval(
"\$items .= \"".$trstart.$templates->get('newpoints_shop_myitems_item').$trend."\";");
                }
                
                if (!
$items)
                {
                    eval(
"\$items = \"".$templates->get('newpoints_shop_myitems_no_items')."\";");
                }
                else {
                    if (
$newrow === false// we haven't closed the row, that means there's a missing td
                    
{
                        eval(
"\$items .= \"".$templates->get('newpoints_shop_myitems_item_empty')."</tr>"."\";");
                        
$newrow true;
                    }
                }
            }
            else {
                eval(
"\$items = \"".$templates->get('newpoints_shop_myitems_no_items')."\";");
            }
            
            eval(
"\$page = \"".$templates->get('newpoints_shop_myitems')."\";");
        }
        else {
            
            
// check group rules - primary group check
            
$grouprules newpoints_getrules('group'$mybb->user['usergroup']);
            if (!
$grouprules)
                
$grouprules['items_rate'] = 1.0// no rule set so default income rate is 1
            
            // if the group items rate is 0, the price of the item is 0
            
$itemsrate floatval($grouprules['items_rate']);
            
            global 
$cats$items;
            
            
// get categories
            
$query $db->simple_select('newpoints_shop_categories''*''', array('order_by' => 'disporder''order_dir' => 'ASC'));
            while (
$cat $db->fetch_array($query))
            {
                
$categories[$cat['cid']] = $cat;
            }
            
            
// get items and store them in their categories
            
$query $db->simple_select('newpoints_shop_items''*''visible=1 AND cid>0', array('order_by' => 'disporder''order_dir' => 'ASC'));
            while (
$item $db->fetch_array($query))
            {
                
$items_array[$item['cid']][$item['iid']] = $item;
            }
            
            
$cats '';
            
$bgcolor '';
            
$bgcolor alt_trow();
            
            
// build items and categories
            
if (!empty($categories))
            {
                foreach (
$categories as $cid => $category)
                {
                    
$items '';
                    
                    if (
$category['items'] > && !empty($items_array[$category['cid']]))
                    {
                        foreach (
$items_array as $cid => $member)
                        {
                            if (
$cid != $category['cid'])
                                continue;
                                
                            
$bgcolor alt_trow();
                            foreach (
$member as $iid => $item)
                            {
                                
// skip hidden items
                                
if ($item['visible'] == 0)
                                    continue;
                                
                                if (
$item['infinite'] == 1)
                                    
$item['stock'] = $lang->newpoints_shop_infinite;
                                    
                                if (
$item['price'] > $mybb->user['newpoints'])
                                    
$enough_money false;
                                else
                                    
$enough_money true;
                                
                                
$item['name'] = htmlspecialchars_uni($item['name']);
                                
$item['description'] = htmlspecialchars_uni($item['description']);
                                
$item['price'] = newpoints_format_points($item['price']*$itemsrate);
                                
                                
// build icon
                                
if ($item['icon'] != '')
                                {
                                    
$item['icon'] = htmlspecialchars_uni($item['icon']);
                                    
$item['icon'] = '<img src="'.$mybb->settings['bburl'].'/'.$item['icon'].'">';
                                }
                                else
                                    
$item['icon'] = '<img src="'.$mybb->settings['bburl'].'/images/newpoints/default.png">';
                                
                                if (!
$enough_money)
                                    
$item['price'] = '<span style="color: #FF0000;">'.$item['price'].'</span>';
                                
                                eval(
"\$items .= \"".$templates->get('newpoints_shop_item')."\";");
                            }
                        }
                    }
                    else
                        eval(
"\$items = \"".$templates->get('newpoints_shop_no_items')."\";");
                        
                    
// if it's not visible, don't show it
                    
if ($category['visible'] == 0)
                        continue;
                        
                    
// check if we have permissions to view the category
                    
if (!newpoints_check_permissions($category['usergroups']))
                        continue;
                        
                    
// Expanded by default feature
                    
global $extdisplay$expcolimage$expdisplay$expaltext$icon;
                    
                    
$expdisplay '';
                    if(
intval($category['expanded']) == 0)
                    {
                        
$expcolimage "collapse_collapsed.gif";
                        
$expdisplay "display: none;";
                        
$expaltext "[+]";
                    }
                    else
                    {
                        
$expcolimage "collapse.gif";
                        
$expaltext "[-]";
                    }

                    
// build icon
                    
if ($category['icon'] != '')
                    {
                        
$category['icon'] = htmlspecialchars_uni($category['icon']);
                        
$category['icon'] = '<img src="'.$mybb->settings['bburl'].'/'.$category['icon'].'" style="vertical-align:middle">';
                    }
                    
                    
// sanitize html
                    
$category['description'] = htmlspecialchars_uni($category['description']);
                    
$category['name'] = htmlspecialchars_uni($category['name']);
                    
                    eval(
"\$cats .= \"".$templates->get('newpoints_shop_category')."\";");
                }
            }
            else {
                eval(
"\$cats = \"".$templates->get('newpoints_shop_no_cats')."\";");
            }
            
            eval(
"\$page = \"".$templates->get('newpoints_shop')."\";");
        }
        
        
$plugins->run_hooks("newpoints_shop_end");
        
        
// output page
        
output_page($page);
    }
}

function 
newpoints_shop_profile()
{
    global 
$mybb$lang$db$memprofile$templates$newpoints_shop_profile;
    
    if (
$mybb->settings['newpoints_shop_itemsprofile'] == 0)
    {
        
$newpoints_shop_profile '';
        return;
    }
    
    
// load language
    
newpoints_lang_load("newpoints_shop");
    
    global 
$shop_items;
    
    
$shop_items '';
    if (empty(
$memprofile['newpoints_items']))
        
$shop_items $lang->newpoints_shop_user_no_items;
    else{
        
$items unserialize($memprofile['newpoints_items']);
        if (!empty(
$items))
        {
            
// do not show multiple icons of the same item if we own more than one
            
$query $db->simple_select('newpoints_shop_items''iid,name,icon''visible=1 AND iid IN ('.implode(','array_unique($items)).')', array('limit' => intval($mybb->settings['newpoints_shop_itemsprofile'])));
            while (
$item $db->fetch_array($query))
            {
                if (
$item['icon'] != '')
                    
$shop_items .= '<a href="'.$mybb->settings['bburl'].'/newpoints.php?action=shop&amp;shop_action=view&amp;iid='.$item['iid'].'"><img src="'.$mybb->settings['bburl'].'/'.$item['icon'].'" title="'.htmlspecialchars_uni($item['name']).'"></a> ';
                else
                    
$shop_items .= '<a href="'.$mybb->settings['bburl'].'/newpoints.php?action=shop&amp;shop_action=view&amp;iid='.$item['iid'].'"><img src="'.$mybb->settings['bburl'].'/images/newpoints/default.png" title="'.htmlspecialchars_uni($item['name']).'"></a> ';
            }
        }
        else
            
$shop_items $lang->newpoints_shop_user_no_items;
    }
    
    eval(
"\$newpoints_shop_profile = \"".$templates->get('newpoints_shop_profile')."\";");
}

function 
newpoints_shop_postbit(&$post)
{
    global 
$mybb$lang$db$templates;
    
    
$post['newpoints_shop_items'] = '';
    
    if (
$mybb->settings['newpoints_shop_itemspostbit'] == 0)
    {
        return;
    }
    
    if (empty(
$post['newpoints_items']))
    {
        return;
    }
    
    
$items unserialize($post['newpoints_items']);
    if (empty(
$items))
    {
        return;
    }
    
    
// load language
    
newpoints_lang_load("newpoints_shop");
    
    static 
$postbit_items_cache// we need to cache all items' icons and names to use less queries
    
    
if(!isset($postbit_items_cache) || !is_array($postbit_items_cache))
    {
        
$postbit_items_cache = array();
        
$query $db->simple_select('newpoints_shop_items''iid,name,icon''visible=1');
        while (
$item $db->fetch_array($query))
        {
            
$postbit_items_cache[$item['iid']] = array('name' => $item['name'], 'icon' => $item['icon']);
        }
    }
    
    if (empty(
$postbit_items_cache))
        return;
    
    
$shop_items '';
    
$count 1;
    
    
$items array_unique($items);
    foreach (
$postbit_items_cache as $iid => $item)
    {
        if (!
in_array($iid$items))
            continue;
        
        if (
$item['icon'] != '')
            
$shop_items .= '<a href="'.$mybb->settings['bburl'].'/newpoints.php?action=shop&amp;shop_action=view&amp;iid='.$iid.'"><img src="'.$mybb->settings['bburl'].'/'.$item['icon'].'" title="'.htmlspecialchars_uni($item['name']).'"></a><br />';
        else
            
$shop_items .= '<a href="'.$mybb->settings['bburl'].'/newpoints.php?action=shop&amp;shop_action=view&amp;iid='.$iid.'"><img src="'.$mybb->settings['bburl'].'/images/newpoints/default.png" title="'.htmlspecialchars_uni($item['name']).'"></a> ';
            
        
$count++;
        if (
$count > (int)$mybb->settings['newpoints_shop_itemspostbit'])
            break;
    }
    
    eval(
"\$post['newpoints_shop_items'] = \"".$templates->get('newpoints_shop_postbit')."\";");
    if (
$shop_items != '')
        
$post['newpoints_shop_items_count'] = count($items);
    else
        
$post['newpoints_shop_items_count'] = "0";
}

function 
newpoints_shop_stats()
{
    global 
$mybb$db$templates$cache$theme$newpoints_shop_lastpurchases$last_purchases$lang;
    
    
// load language
    
newpoints_lang_load("newpoints_shop");
    
$last_purchases '';
    
    
// build stats table
    
$query $db->simple_select('newpoints_log''*''action=\'shop_purchase\'', array('order_by' => 'date''order_dir' => 'DESC''limit' => intval($mybb->settings['newpoints_shop_lastpurchases'])));
    while(
$purchase $db->fetch_array($query)) {
        
$bgcolor alt_trow();
        
$data explode('-'$purchase['data']);
        
        
$item newpoints_shop_get_item($data[0]);
        
$purchase['item'] = htmlspecialchars_uni($item['name']);
        
        
$link build_profile_link(htmlspecialchars_uni($purchase['username']), intval($purchase['uid']));
        
$purchase['user'] = $link;
        
        
$purchase['date'] = my_date($mybb->settings['dateformat'], intval($purchase['date']), ''false);
        
        eval(
"\$last_purchases .= \"".$templates->get('newpoints_shop_stats_purchase')."\";");
    }
    
    if (!
$last_purchases)
        eval(
"\$last_purchases = \"".$templates->get('newpoints_shop_stats_nopurchase')."\";");
        
    eval(
"\$newpoints_shop_lastpurchases = \"".$templates->get('newpoints_shop_stats')."\";");
}

function 
newpoints_shop_backup(&$backup_fields)
{
    global 
$db$table;
    
$backup_fields[] = 'newpoints_items';




RE: Can't edit (shop) plugin? Help please! - Diogo Parrinha - 08-12-2010

That NewPoints version is a bit old y'know ? Tongue