Skip to content

Commit

Permalink
Add Find Gateways list
Browse files Browse the repository at this point in the history
  • Loading branch information
partydragen committed Oct 26, 2024
1 parent 763d283 commit fc358ec
Show file tree
Hide file tree
Showing 3 changed files with 118 additions and 1 deletion.
60 changes: 60 additions & 0 deletions upload/custom/panel_templates/Default/store/gateways.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,66 @@
</tbody>
</table>
</div>

<br />
<h5 style="display:inline">{$FIND_GATEWAYS}</h5>
<div class="float-md-right">
<a href="{$VIEW_ALL_GATEWAYS_LINK}" class="btn btn-primary" target="_blank">{$VIEW_ALL_GATEWAYS} &raquo;</a>
</div>
<br /><br />

{if count($WEBSITE_GATEWAYS)}
<div class="table-responsive">
<table class="table table-striped">
<colgroup>
<col width="70%">
<col width="20%">
<col width="10%">
</colgroup>
<thead>
<tr>
<th>{$GATEWAY}</th>
<th>{$STATS}</th>
<th>{$ACTIONS}</th>
</tr>
</thead>
<tbody>
{foreach from=$WEBSITE_GATEWAYS item=item}
<tr>
<td>
<strong>{$item.name}</strong> <small>{$item.latest_version}</small>
<br />
<small>{$item.author_x}</small>
<br />
<small>{$item.updated_x}</small>
</td>
<td>
<div class="star-rating view">
<span class="far fa-star" data-rating="1"
style="color:gold;"></span>
<span class="far fa-star" data-rating="2" style="color:gold"></span>
<span class="far fa-star" data-rating="3"
style="color:gold;"></span>
<span class="far fa-star" data-rating="4"
style="color:gold;"></span>
<span class="far fa-star" data-rating="5"
style="color:gold;"></span>
<input type="hidden" name="rating" class="rating-value"
value="{($item.rating/10)|round}">
</div>
{$item.downloads_full}<br />
{$item.views_full}
</td>
<td><a href="{$item.url}" target="_blank"
class="btn btn-primary btn-sm">{$VIEW} &raquo;</a></td>
</tr>
{/foreach}
</tbody>
</table>
</div>
{else}
<div class="alert alert-warning">{$UNABLE_TO_RETRIEVE_GATEWAYS}</div>
{/if}
{/if}

<center>
Expand Down
4 changes: 4 additions & 0 deletions upload/modules/Store/language/en_UK.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@
"admin/fields": "Fields",
"admin/fields_info": "Fields enable you to create customisable products such as allowing users to select the colour of their name upon purchase.",
"admin/gateways": "Gateways",
"admin/gateway": "Gateway",
"admin/hide_category_from_dropdown_menu": "Do not display this category in the subcategory drop down menu.",
"admin/hide_category_from_menu": "Do not display this category menu.",
"admin/hide_product_from_store": "Do not display this product on store.",
Expand Down Expand Up @@ -228,6 +229,9 @@
"admin/supports_subscriptions": "Supports subscriptions",
"admin/view_placeholders": "View Placeholders",
"admin/global_actions": "Global Actions",
"admin/find_gateways": "Find Gateways",
"admin/view_all_gateways": "View all gateways",
"admin/unable_to_retrieve_gateways": "Unable to retrieve gateways",
"general/agree_t_and_c_purchase": "I agree to the {{termsLinkStart}}terms and conditions{{termsLinkEnd}} of this purchase.",
"general/accept_terms": "You must accept the terms and conditions",
"general/buy": "Buy",
Expand Down
55 changes: 54 additions & 1 deletion upload/modules/Store/pages/panel/gateways.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,61 @@
];
}

// Get gateways from Nameless website
$cache->setCache('all_gateways');
if ($cache->isCached('all_gateways')) {
$all_gateways = $cache->retrieve('all_gateways');
} else {
$all_gateways = [];
$all_gateways_query = HttpClient::get('https://namelesscms.com/index.php?route=/api/v2/resources&category=12');

if ($all_gateways_query->hasError()) {
$all_gateways_error = $all_gateways_query->getError();
} else {
$all_gateways_query = json_decode($all_gateways_query->contents());
$timeago = new TimeAgo(TIMEZONE);

foreach ($all_gateways_query->resources as $item) {
$all_gateways[] = [
'name' => Output::getClean($item->name),
'description' => Output::getPurified($item->description),
'description_short' => Text::truncate(Output::getPurified($item->description)),
'author' => Output::getClean($item->author->username),
'author_x' => $language->get('admin', 'author_x', ['author' => Output::getClean($item->author->username)]),
'updated_x' => $language->get('admin', 'updated_x', ['updatedAt' => date(DATE_FORMAT, $item->updated)]),
'url' => Output::getClean($item->url),
'latest_version' => Output::getClean($item->latest_version),
'rating' => Output::getClean($item->rating),
'downloads' => Output::getClean($item->downloads),
'views' => Output::getClean($item->views),
'rating_full' => $language->get('admin', 'rating_x', ['rating' => Output::getClean($item->rating * 2) . '/100']),
'downloads_full' => $language->get('admin', 'downloads_x', ['downloads' => Output::getClean($item->downloads)]),
'views_full' => $language->get('admin', 'views_x', ['views' => Output::getClean($item->views)])
];
}

$cache->store('all_gateways', $all_gateways, 3600);
}
}

if (count($all_gateways)) {
if (count($all_gateways) > 3) {
$rand_keys = array_rand($all_gateways, 3);
$all_gateways = [$all_gateways[$rand_keys[0]], $all_gateways[$rand_keys[1]], $all_gateways[$rand_keys[2]]];
}
}

$smarty->assign([
'GATEWAYS_LIST' => $gateways_list
'GATEWAYS_LIST' => $gateways_list,
'FIND_GATEWAYS' => $store_language->get('admin', 'find_gateways'),
'VIEW' => $language->get('general', 'view'),
'GATEWAY' => $store_language->get('admin', 'gateway'),
'STATS' => $language->get('admin', 'stats'),
'ACTIONS' => $language->get('general', 'actions'),
'WEBSITE_GATEWAYS' => $all_gateways,
'VIEW_ALL_GATEWAYS' => $store_language->get('admin', 'view_all_gateways'),
'VIEW_ALL_GATEWAYS_LINK' => 'https://namelesscms.com/resources/category/12-store-gateways/',
'UNABLE_TO_RETRIEVE_GATEWAYS' => $all_gateways_error ?? $store_language->get('admin', 'unable_to_retrieve_gateways'),
]);
}

Expand Down

0 comments on commit fc358ec

Please sign in to comment.