slawkens / myaac-plugins

GNU General Public License v3.0
1 stars 2 forks source link

/?gifts not working #1

Open chac4l opened 5 months ago

chac4l commented 5 months ago

image

my page ?gifts is not rendering gifts.html.twig. it only shows gift-header.html.twig. i also found out there is another gifts.php on /gesior-shop-system/pages. slightly difference oon line 14, the file on gesior has csrfProtect(); , when applied to my ''system'' gift page, it comes back with http500.

Any idea?

CODE gifts.php on html/system/pages: `<?php /**

require_once(PLUGINS . 'gesior-shop-system/libs/shop-system.php'); require_once(PLUGINS . 'gesior-shop-system/config.php');

if(!$config['gifts_system']) { if(!admin()) { $errors[] = 'The gifts system is disabled.'; $twig->display('error_box.html.twig', array('errors' => $errors)); return; } else { warning("You're able to access this page but it is disabled for normal users.
Its enabled for you so you can view/edit shop offers before displaying them to users.
You can enable it by editing this line in myaac config.local.php file:
<p style=\"margin-left: 3em;\">\$config['gifts_system'] = true;

"); } }

if(GesiorShop::getDonationType() == 'coins' && !fieldExist('coins', 'accounts')) { $errors[] = "Your server doesn't support accounts.coins. Please change back config.donation_type to points."; $twig->display('error_box.html.twig', array('errors' => $errors)); return; }

if($logged) { $user_premium_points = $account_logged->getCustomField(GesiorShop::getDonationType()); } else { $was_before = $config['friendly_urls']; $config['friendly_urls'] = true; $user_premium_points = generateLink(getLink('?subtopic=accountmanagement') . '&redirect=' . urlencode(BASE_URL . '?subtopic=gifts'), 'Login first'); $config['friendly_urls'] = $was_before; }

if(!empty($action)) { $errors = array(); if(!$logged || !$account_logged->isLoaded()) { $errors[] = 'Please login first'; $twig->display('error_box.html.twig', array('errors' => $errors)); return; }

switch ($action) {
    case 'select_player':
        $buy_id = isset($_REQUEST['buy_id']) ? (int)$_REQUEST['buy_id'] : null;
        if(empty($buy_id)) {
            $errors[] = 'Please <a href="?subtopic=gifts">select item</a> first.';
            break;
        }

        $buy_offer = GesiorShop::getOfferById($buy_id);
        if(!isset($buy_offer['id']) || $buy_offer['hidden'] == '1') {
            $errors[] = 'Offer with ID <b>' . $buy_id . '</b> doesn\'t exist. Please <a href="?subtopic=gifts">select item</a> again.';
            break;
        }

        if($user_premium_points < $buy_offer['points']) {
            $errors[] = 'For this item you need <b>' . $buy_offer['points'] . '</b> points. You have only <b>' . $user_premium_points . '</b> premium points. Please <a href="?subtopic=gifts">select other item</a> or buy premium points.';
            break;
        }

        GesiorShop::selectPlayerAction($account_logged, $buy_id, $buy_offer, $user_premium_points);
        break;

    case 'confirm_transaction':
        $buy_id = isset($_POST['buy_id']) ? (int)$_POST['buy_id'] : null;
        if(empty($buy_id)) {
            $errors[] = 'Please <a href="?subtopic=gifts">select item</a> first.';
            break;
        }

        $buy_offer = GesiorShop::getOfferById($buy_id);
        if(!isset($buy_offer['id']) || $buy_offer['hidden'] == '1') {
            $errors[] = 'Offer with ID <b>' . $buy_id . '</b> doesn\'t exist. Please <a href="?subtopic=gifts">select item</a> again.';
            break;
        }

        $buy_from = isset($_POST['buy_from']) ? stripslashes(urldecode($_POST['buy_from'])) : '';
        if(empty($buy_from)) {
            $buy_from = 'Anonymous';
        }

        if(!check_name($buy_from)) {
            $errors[] = 'Invalid nick ("from player") format. Please <a href="?subtopic=gifts&action=select_player&buy_id=' . $buy_id . '">select other name</a> or contact with administrator.';
            break;
        }

        $buy_name = isset($_POST['buy_name']) ? stripslashes(urldecode($_POST['buy_name'])) : '';
        if(!check_name($buy_name)) {
            $errors[] = 'Invalid name format. Please <a href="?subtopic=gifts&action=select_player&buy_id=' . $buy_id . '">select other name</a> or contact with administrator.';
            break;
        }

        if($user_premium_points < $buy_offer['points']) {
            $errors[] = 'For this item you need <b>' . $buy_offer['points'] . '</b> points. You have only <b>' . $user_premium_points . '</b> premium points. Please <a href="?subtopic=gifts">select other item</a> or buy premium points.';
            break;
        }

        $buy_player = new OTS_Player();
        $buy_player->find($buy_name);
        if(!$buy_player->isLoaded()) {
            $errors[] = 'Player with name <b>' . $buy_name . '</b> doesn\'t exist. Please <a href="?subtopic=gifts&action=select_player&buy_id=' . $buy_id . '">select other name</a>.';
            break;
        }

        if ($buy_player->isDeleted()) {
            $errors[] = 'Player with name <b>' . $buy_name . '</b> has been deleted. Please <a href="?subtopic=gifts&action=select_player&buy_id=' . $buy_id . '">select other name</a>.';
            break;
        }

        GesiorShop::confirmTransactionAction($account_logged, $buy_player, $buy_id, $buy_offer, $buy_from, $buy_name, $user_premium_points, $errors);
        break;

    case 'show_history':
        GesiorShop::showHistoryAction($account_logged);
        break;
}

if(!empty($errors)) {
    $twig->display('error_box.html.twig', array('errors' => $errors));
}

} else { unset($_SESSION['viewed_confirmation_page']);

$offer_categories = array();
$tmp_query = $db->query('SELECT `id`, `name` FROM `' . 'z_shop_categories` WHERE `hidden` != 1')
    ->fetchAll();
foreach($tmp_query as $tmp_res) {
    $offer_categories[$tmp_res['id']] = $tmp_res['name'];
}

$get_offer_category = $_GET['offercat'] ?? 1;
$tmp = '';
if($cache->enabled() && $cache->fetch('mounts', $tmp)) {
    $config['mounts'] = unserialize($tmp);
} else {
    $mounts = new DOMDocument();
    $file = $config['data_path'] . 'XML/mounts.xml';
    if (file_exists($file)) {
        $mounts->load($file);
        if ($mounts) {
            $config['mounts'] = array();
            foreach ($mounts->getElementsByTagName('mount') as $mount) {
                $id = $mount->getAttribute('id');
                $config['mounts'][$id] = $mount->getAttribute('clientid');
            }
            if ($cache->enabled()) {
                $cache->set('mounts', serialize($config['mounts']), 120);
            }
        }
    }
}

$offers_fetch = array();
$tmp = null;
if($cache->enabled() && $cache->fetch('shop_offers_fetch', $tmp)) {
    $offers_fetch = unserialize($tmp);
} else {
    $offers_fetch = GesiorShop::getOffers();

    if($cache->enabled()) {
        $cache->set('shop_offers_fetch', serialize($offers_fetch), 120);
    }
}

if (isset($_REQUEST['success'])) {
    $twig->display('gesior-shop-system/templates/success.html.twig');
}

if (isset($_REQUEST['cancel'])) {
    $twig->display('gesior-shop-system/templates/cancel.html.twig');
}

$twig->display('gesior-shop-system/templates/gifts-header.html.twig', [
    'user_premium_points' => $user_premium_points,
]);

if (config('enable_most_popular_items')) {
    $twig->display('gesior-shop-system/templates/most-popular.html.twig', [
        'offers' => GesiorShop::getMostPopular(),
    ]);
}

$twig->display('gesior-shop-system/templates/gifts.html.twig', array(
    'title' => $title,
    'logged' => !empty($logged) ? $logged : false,
    'user_premium_points' => $user_premium_points,
    'offer_categories' => $offer_categories,
    'offers_fetch' => $offers_fetch,
    'get_offer_category' => $get_offer_category,
    'outfit_colors' => $config['shop_outfit_colors'],
));

} `

CODE /html/plugins/gesior-shop-system/templates/gifts.html.twig: `<!DOCTYPE html>

Gifts
{% if warning is defined %}

{{ warning }}

{% endif %} {% for id, name in offer_categories %} {{ name }} {% endfor %} {% if offers_fetch|length > 0 %} {% for offer in offers_fetch if offer.category_id == get_offer_category %} {% endfor %} {% else %} {% endif %}
Picture Description Points Select product
{{ offer.images|raw }} {{ offer.name }}
{{ offer.description|raw }}
{{ offer.points }} {% if logged %}
{{ csrf() }}
{% else %} Login to buy {% endif %}
There are no offers here.
`
slawkens commented 5 months ago

Enable dev env as stated here, in the Errors category:

I get white page with error 500

And then post the error you are getting.