Skip to content

Commit

Permalink
Release
Browse files Browse the repository at this point in the history
  • Loading branch information
par274 committed Jan 11, 2023
0 parents commit b656c7e
Show file tree
Hide file tree
Showing 30 changed files with 1,730 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
src/vendor
src/composer.lock
4 changes: 4 additions & 0 deletions .htaccess
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<Files "app.php">
Order Deny,Allow
Deny from all
</Files>
281 changes: 281 additions & 0 deletions app.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,281 @@
<?php

namespace Init;

use PlatformRunDirect\Templater;

use Symfony\Component\Serializer\Encoder\JsonEncoder;
use Symfony\Component\Serializer\Encoder\XmlEncoder;
use Symfony\Component\Serializer\Normalizer\ObjectNormalizer;
use Symfony\Component\Serializer\Serializer;

use Symfony\Component\DomCrawler\Crawler;

use GuzzleHttp\Client;

class app
{
protected $request;
protected $db;

protected $query;
protected $post;

protected $serializer;

protected $template;

protected $tokens = [
'90b8ae9fdc3c428586ec5a738f124a57',
'b1e2e7689ae44dbe955ae04a6ada4004',
'c7f84a864b0f431f970a4cdefedc6db'
];

public function RunPlatform()
{
$this->request = new \PlatformRunDirect\Request();

$this->query = new \PlatformRunDirect\Get();
$this->post = new \PlatformRunDirect\Post();

$encoders = [new JsonEncoder()];
$normalizers = [new ObjectNormalizer()];

$this->serializer = new Serializer($normalizers, $encoders);

$this->template = new Templater();
$this->templaterController();
}

public function RenderPlatformDirect()
{
if ($this->request->getRequestMethod() == "GET")
{
$client = new Client([
'http_errors' => false,
'timeout' => 3,
'connect_timeout' => 3.14
]);

$response = $client->request('GET', 'http://www.koeri.boun.edu.tr/scripts/lst4.asp');

if ($response->getStatusCode() == 200)
{
$content = $response->getBody()->getContents();
}
else
{
if ($this->query->has('xml'))
{
$this->renderStream(
$this->xmlSerialize([
'status' => 'fail-response-error',
'message' => 'The connection to the site could not be established.'
]),
'application/xml'
);
}
else
{
$this->renderStream(
$this->jsonSerialize([
'status' => 'fail-response-error',
'message' => 'The connection to the site could not be established.'
])
);
}

return false;
}

$output = [
'status' => 'ok',
'data' => $this->getData($content)
];

if ($this->query->has('json'))
{
$data = $this->jsonSerialize($output);
$this->renderStream($data);
}
else if ($this->query->has('xml'))
{
$data = $this->xmlSerialize($output);
$this->renderStream($data, 'application/xml');
}
else
{
$data = [
'data' => [
'json' => $this->jsonSerialize($output)
]
];
echo $this->template->render('{page_container:table}', $data);
}
}
elseif ($this->request->getRequestMethod() == "POST")
{
}
}

protected function getData($html)
{
$crawler = new Crawler($html);
$rawData = $crawler->filter('pre')->html();

$lines = explode("\r\n", $rawData);
//$lines = array_slice($lines, 0, 200);

foreach ($lines as $item)
{
$parts = explode(' ', $item);
$parts = \array_filter($parts, function ($line)
{
if (strlen($line) > 1)
{
$line = \strip_tags($line);
$line = \trim($line);

return $line;
}
});

if (count($parts) > 1)
{
$lineItems[] = \array_values($parts);
}
}

foreach (\array_slice($lineItems, 2) as $row)
{
$dateTime = \strtotime(
\str_replace('.', '-', $row[0])
);

$revisionDateTime = null;
if (isset($row[9]))
{
$revisionDateTime = \strtotime(
\str_replace(['.', '(', ')'], ['-', '', ''], $row[9])
);
$revisionDateTime = date('d-m-Y H:i', $revisionDateTime);
}

$data[] = [
'date' => [
'humanreadable' => (new \PlatformRunDirect\DateTime())->getFullDateTime($dateTime),
'date' => date('d-m-Y', $dateTime),
'time' => date('H:i', $dateTime)
],
'geo' => [
'full' => \sprintf('%s,%s', $row[1], $row[2]),
'latitude' => \trim($row[1]),
'longitude' => \trim($row[2])
],
'depth' => \trim($row[3]),
'ml' => $row[5],
'location' => [
'full' => \trim(
\ucwords(\strtolower($row[7]))
),
'city' => \trim(
\ucwords(
\strtolower(preg_replace('/([a-zA-Z- ]+)(?:\s)?\(([a-zA-Z ]+)\)/', '$1', $row[7]))
)
),
'state' => \trim(
\ucwords(
\strtolower(preg_replace('/([a-zA-Z- ]+)(?:\s)?\(([a-zA-Z ]+)\)/', '$2', $row[7]))
)
)
],
'accuracy' => (isset($row[9])) ? \trim("{$row[8]} {$revisionDateTime}") : \trim($row[8])
];
}

return $data;
}

protected function controlToken()
{
if ($this->query->has('token'))
{
if (in_array($this->query->get('token'), $this->tokens))
{
return true;
}

return [
'status' => 'fail-token-not-confirmed',
'message' => 'Token not confirmed.'
];
}

return [
'status' => 'fail-token-missing',
'message' => 'Token is missing.'
];
}

protected function streamableRandomFile(): string
{
$v4 = \PlatformRunDirect\Uuid::v4();

return "IGS_STREAMABLE_PACKAGE_PLATFORM_{$v4}.miniature";
}

protected function jsonSerialize(array $data)
{
return $this->serializer->serialize(
$data,
'json',
['json_encode_options' => \JSON_PRESERVE_ZERO_FRACTION]
);
}

protected function xmlSerialize(array $data)
{
return (new XmlEncoder())->encode(
$data,
'xml',
[
'xml_encoding' => 'utf-8',
XmlEncoder::ENCODER_IGNORED_NODE_TYPES => [\XML_COMMENT_NODE]
]
);
}

protected function renderStream($data, string $type = 'application/json')
{
return $this->request->setContentDispositionStreamed(
$this->streamableRandomFile(),
$data,
$type
);
}

private function templaterController()
{
$this->template->addGlobals([
'app' => [
'uri' => \PlatformRunDirect\AppSub::getFullUrl(),
'public_dir' => \PlatformRunDirect\AppSub::getPublicDir(),
'ajax_path' => $this->getAjaxPath(),
'request' => $this->request,
'post' => $this->post,
'query' => $this->query,
'serializer' => $this->serializer
]
]);
}

public function getAjaxPath()
{
if (\PlatformRunDirect\AppSub::getSubDir())
{
return "/" . \PlatformRunDirect\AppSub::getSubDir();
}

return '';
}
}
12 changes: 12 additions & 0 deletions index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

ini_set('max_execution_time', 900);

//Application location.
define('APPLICATION_SELF', __DIR__ . '/src');

require(APPLICATION_SELF . '/vendor/autoload.php');
$app = new \Init\app();

$app->RunPlatform();
$app->RenderPlatformDirect();
22 changes: 22 additions & 0 deletions license.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
MIT License

Copyright (c) 2023 Mention Community Bulletin Board
Copyright (c) 2023 author parantezprojects@gmailc.com / https://www.r10.net/profil/90047-scarecrow.html

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
14 changes: 14 additions & 0 deletions public/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
var app = {};

if (window.jQuery === undefined) jQuery = $ = {};

!(function ($, window, document) {
"use strict";

$(function () {
$('.app-table > table').DataTable({
'pageLength': 10
});
});

})(window.jQuery, window, document);
27 changes: 27 additions & 0 deletions public/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
.app-introduction, .app-table, .app-end {
padding: 0 15px;
}

.bg-dark hr {
border-top: 1px solid rgb(69, 77, 85);
}

.bg-dark .pagination .page-link {
color: #fff;
background-color: #343a40;
border: 1px solid #454d55;
}

.bg-dark .pagination .page-link:hover {
background-color: #31373d;
}

.bg-dark .table-dark.table-bordered {
border: 1px solid #454d55;
border-right: none;
border-top: none
}

.bg-dark .app-table .custom-select {
color: #000;
}
7 changes: 7 additions & 0 deletions public/vendor/bootstrap/bootstrap.min.css

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions public/vendor/bootstrap/bootstrap.min.css.map

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions public/vendor/bootstrap/bootstrap.min.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions public/vendor/bootstrap/bootstrap.min.js.map

Large diffs are not rendered by default.

Empty file.
4 changes: 4 additions & 0 deletions public/vendor/bootstrap/popper.min.js

Large diffs are not rendered by default.

52 changes: 52 additions & 0 deletions public/vendor/vendor.css

Large diffs are not rendered by default.

141 changes: 141 additions & 0 deletions public/vendor/vendor.js

Large diffs are not rendered by default.

Loading

0 comments on commit b656c7e

Please sign in to comment.