Skip to content

Commit

Permalink
Adverts
Browse files Browse the repository at this point in the history
  • Loading branch information
ArtemKo7v committed May 24, 2017
1 parent b780efc commit 51d4b3f
Show file tree
Hide file tree
Showing 7 changed files with 176 additions and 61 deletions.
35 changes: 33 additions & 2 deletions css/ethplorer.css
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,37 @@ tr.paginationFooter td ul.pagination {
.nav-tabs.unclickable {
pointer-events: none;
}
.ethplorer-adv {

.navbar.navbar-inverse {
padding-bottom:0px;
padding-top:0px;
border: 0px;
border-radius: 0px;
}

#ethplorer-note {
display:none;
width: 100%;
background-color: rgba(19,150,226,1);
padding: 10px;
margin-bottom: 20px;
margin-top: -20px;
}

#ethplorer-note .ethplorer-note {
color: white;
text-align: center;
display:none;
}

#ethplorer-note img,
#ethplorer-note .ethplorer-note img {
height: 35px;
}

#ethplorer-note .ethplorer-note a {
color: white;
text-decoration: none;
border-bottom: 2px solid white;
}

.table.unclickable {
Expand Down Expand Up @@ -979,6 +1006,10 @@ li.ui-menu-item.have-more {
}

@media screen and (max-width: 399px) {
#ethplorer-note {
margin-top: 0px;
}

.total-records {
display: none;
}
Expand Down
23 changes: 23 additions & 0 deletions go.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

ob_clean();
header("HTTP/1.0 200 OK");

$aConfig = require_once dirname(__FILE__) . '/service/config.php';

$sLink = "https://ethplorer.io";

if(isset($_GET["link"]) && strlen($_GET["link"])>0){
$sLink = $_GET["link"];
$fp = @fopen(dirname(__FILE__) . "/service/log/go-links.log", "a+");
if($fp){
$t = date('Y-m-d H:i:s')." - ".$sLink." - ".@getenv("REMOTE_ADDR")." - ".@getenv("HTTP_REFERER"). " - ".@getenv("HTTP_USER_AGENT")."\r\n";
@fwrite($fp, $t);
}
}

header("HTTP/1.1 301 Moved Permanently");
header("Location: " . $sLink);

?>

11 changes: 3 additions & 8 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,13 @@
<script src="/js/bignumber.js"></script>
<script src="/js/ethplorer.js?v=<?=$codeVersion?>"></script>
<script src="/js/ethplorer-search.js?v=<?=$codeVersion?>"></script>
<script src="/js/ethplorer-adv.js?v=<?=$codeVersion?>"></script>
<script src="/js/ethplorer-note.js?v=<?=$codeVersion?>"></script>
<script src="/js/config.js"></script>
<script src="/js/md5.min.js"></script>
</head>
<body>
<div style="position: relative; min-height: 100vh;">
<nav class="navbar navbar-inverse" style="padding-bottom:0px; padding-top:0px;">
<nav class="navbar navbar-inverse">
<div class="container">
<div class="navbar-header">
<a class="navbar-logo-small" href="/"><img title="Ethplorer" src="/favicon.ico"></a>
Expand All @@ -107,6 +107,7 @@
</div>
</div>
</nav>
<div id="ethplorer-note"></div>
<div class="container">
<div class="starter-template">
<div id="page-create" class="page">
Expand All @@ -127,12 +128,6 @@
<h3 id="error-reason" class="text-danger"></h3>
</div>

<div class="ethplorer-adv">
<div class="col-xs-12">
Sponsored Link: <span id="ethplorer-adv"></span>
</div>
</div>

<div>
<div class="hidden-xs col-sm-2"></div>
<div class="col-xs-12 col-sm-8">
Expand Down
56 changes: 56 additions & 0 deletions js/ethplorer-note.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*!
* Copyright 2017 Everex https://everex.io
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

EthplorerNote = {
service: "/service/service.php",
next: 0,
init: function(container, callback){
EthplorerNote.container = container;

var inner = $('<DIV>');
inner.addClass('ethplorer-note');
EthplorerNote.container.append(inner);
EthplorerNote.inner = inner;

EthplorerNote.callback = callback;
EthplorerNote.loadNext();
},
loadNext: function(){
$.getJSON(EthplorerNote.service, {notes: 1, note: EthplorerNote.next}, function(data, status, xhr){
if('undefined' !== typeof(data.link)){
EthplorerNote.inner.fadeOut(300, function(_data){
return function(){
var link = "/go.php?link=" + _data.link;
EthplorerNote.inner.html(_data.html.replace('%link%', link));
if('undefined' !== typeof(_data.next)){
EthplorerNote.next = _data.next;
}
if(_data.image){
var img = $('<IMG>');
img.attr('src', _data.image);
EthplorerNote.inner.prepend(img);
}
EthplorerNote.inner.fadeIn(500);
}
}(data));
if(data.hasNext){
setTimeout(EthplorerNote.loadNext, 5000);
}
EthplorerNote.container.show();
}
});
}
};
6 changes: 3 additions & 3 deletions js/ethplorer.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,9 +160,9 @@ Ethplorer = {
}

// @see ethplorer-adv.js
if('undefined' !== typeof(EthplorerAdv)){
EthplorerAdv.init($('#ethplorer-adv'), function(){
$('.ethplorer-adv').show();
if('undefined' !== typeof(EthplorerNote)){
EthplorerNote.init($('#ethplorer-note'), function(){
$('#ethplorer-note').show();
});
}

Expand Down
8 changes: 5 additions & 3 deletions service/lib/ethplorer.php
Original file line number Diff line number Diff line change
Expand Up @@ -1617,16 +1617,18 @@ public function sortTokensByTxsCount($a, $b) {
return ($a['txsCount'] < $b['txsCount']) ? 1 : -1;
}

public function getActiveAdverts(){
public function getActiveNotes(){
$result = array();
if(isset($this->aSettings['adv'])){
$all = $this->aSettings['adv'];
foreach($all as $one){
if(isset($one['activeTo'])){
if($one['activeTo'] <= time()){
if(isset($one['activeTill'])){
if($one['activeTill'] <= time()){
continue;
}
}
$one['link'] = urlencode($one['link']);
$one['hasNext'] = (count($all) > 1);
$result[] = $one;
}
}
Expand Down
98 changes: 53 additions & 45 deletions service/service.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,69 +17,77 @@

require dirname(__FILE__) . '/lib/ethplorer.php';

$es = Ethplorer::db(require_once dirname(__FILE__) . '/config.php');

$data = isset($_GET["data"]) ? $_GET["data"] : false;
$page = isset($_GET["page"]) ? $_GET["page"] : false;
$refresh = isset($_GET["refresh"]) ? $_GET["refresh"] : false;
$search = isset($_GET["search"]) ? $_GET["search"] : false;
$adv = isset($_GET["adv"]) ? $_GET["adv"] : false;
$adv = isset($_GET["notes"]) ? $_GET["notes"] : false;

// Allow cross-domain ajax requests
header('Access-Control-Allow-Origin: *');

$pageSize = 10;

// Parse page data
if($page && (FALSE !== strpos($page, '='))){
$aPageData = explode('&', $page);
foreach($aPageData as $pageDataString){
$aPageParams = explode('=', $pageDataString);
if(2 === count($aPageParams)){
switch($aPageParams[0]){
case 'pageSize':
$pageSize = intval($aPageParams[1]);
break;
case 'transfers':
case 'issuances':
case 'holders':
case 'chainy':
$es->setPager($aPageParams[0], intval($aPageParams[1]));
break;
case 'filter':
$es->setFilter($aPageParams[1]);
break;
$result = array();

$aConfig = require_once dirname(__FILE__) . '/config.php';

if(strlen($search) || (false !== $data)){

$es = Ethplorer::db($aConfig);

if(strlen($search)){
$result = $es->searchToken($search);
}else{
// Parse page data
if($page && (FALSE !== strpos($page, '='))){
$aPageData = explode('&', $page);
foreach($aPageData as $pageDataString){
$aPageParams = explode('=', $pageDataString);
if(2 === count($aPageParams)){
switch($aPageParams[0]){
case 'pageSize':
$pageSize = intval($aPageParams[1]);
break;
case 'transfers':
case 'issuances':
case 'holders':
case 'chainy':
$es->setPager($aPageParams[0], intval($aPageParams[1]));
break;
case 'filter':
$es->setFilter($aPageParams[1]);
break;
}
}
}
if($refresh){
$es->setPager('refresh', $refresh);
}
}
}
if($refresh){
$es->setPager('refresh', $refresh);
}
}

$result = array();

if(strlen($search)){
$result = $es->searchToken($search);
}else if(false !== $data){
$es->setPageSize($pageSize);
if($es->isValidAddress($data)){
$result = $es->getAddressDetails($data);
}elseif($es->isValidTransactionHash($data)){
$result = $es->getTransactionDetails($data);
}
if(!isset($result['pager'])){
$result['pager'] = array(
'pageSize' => $pageSize
);
$es->setPageSize($pageSize);
if($es->isValidAddress($data)){
$result = $es->getAddressDetails($data);
}elseif($es->isValidTransactionHash($data)){
$result = $es->getTransactionDetails($data);
}
if(!isset($result['pager'])){
$result['pager'] = array(
'pageSize' => $pageSize
);
}
$result['ethPrice'] = $es->getETHPrice();
}
$result['ethPrice'] = $es->getETHPrice();
}

if($adv){
$all = $es->getActiveAdverts();
unset($aConfig['mongo']);
$es = Ethplorer::db($aConfig);
$all = $es->getActiveNotes();
$index = isset($_GET["note"]) && (abs((int)$_GET["note"] < count($all))) ? abs((int)$_GET["note"]) : rand(0, count($all) - 1);
if(count($all)){
$result = $all[rand(0, count($all) - 1)];
$result = $all[$index];
}
}

Expand Down

0 comments on commit 51d4b3f

Please sign in to comment.