Skip to content
Permalink
Browse files

Init

  • Loading branch information...
alighasemzadeh committed Jun 6, 2019
1 parent 2276a5b commit 9906054c3991ab9559753df7fdb593c8a06db6ff
Showing with 5,885 additions and 280 deletions.
  1. +7 −0 .idea/7ul.iml
  2. +8 −0 .idea/laravel-plugin.xml
  3. +7 −0 .idea/php.xml
  4. +4 −0 .idea/watcherTasks.xml
  5. +1 −0 app/Exports/VisitsExport.php
  6. +47 −0 app/Http/Controllers/Admin/DashboardController.php
  7. +2 −0 app/Http/Controllers/Auth/RegisterController.php
  8. +18 −0 app/Http/Controllers/DashboardController.php
  9. +24 −10 app/Http/Controllers/LinkController.php
  10. +89 −1 app/Http/Controllers/ManageController.php
  11. +69 −0 app/Http/Controllers/ProfileController.php
  12. +1 −0 app/Http/Kernel.php
  13. +24 −0 app/Http/Middleware/AdminMiddleware.php
  14. +6 −1 composer.json
  15. +435 −17 composer.lock
  16. +3 −1 config/7ul.php
  17. +2 −2 database/migrations/2019_05_06_151804_create_visits_table.php
  18. +23 −8 package-lock.json
  19. +5 −2 package.json
  20. +11 −6 public/css/app.css
  21. BIN public/fonts/vendor/@fortawesome/fontawesome-free/webfa-brands-400.eot
  22. +3,442 −0 public/fonts/vendor/@fortawesome/fontawesome-free/webfa-brands-400.svg
  23. BIN public/fonts/vendor/@fortawesome/fontawesome-free/webfa-brands-400.ttf
  24. BIN public/fonts/vendor/@fortawesome/fontawesome-free/webfa-brands-400.woff
  25. BIN public/fonts/vendor/@fortawesome/fontawesome-free/webfa-brands-400.woff2
  26. BIN public/fonts/vendor/@fortawesome/fontawesome-free/webfa-regular-400.eot
  27. +803 −0 public/fonts/vendor/@fortawesome/fontawesome-free/webfa-regular-400.svg
  28. BIN public/fonts/vendor/@fortawesome/fontawesome-free/webfa-regular-400.ttf
  29. BIN public/fonts/vendor/@fortawesome/fontawesome-free/webfa-regular-400.woff
  30. BIN public/fonts/vendor/@fortawesome/fontawesome-free/webfa-regular-400.woff2
  31. BIN public/fonts/vendor/@fortawesome/fontawesome-free/webfa-solid-900.eot
  32. +290 −168 public/fonts/vendor/@fortawesome/fontawesome-free/webfa-solid-900.svg
  33. BIN public/fonts/vendor/@fortawesome/fontawesome-free/webfa-solid-900.ttf
  34. BIN public/fonts/vendor/@fortawesome/fontawesome-free/webfa-solid-900.woff
  35. BIN public/fonts/vendor/@fortawesome/fontawesome-free/webfa-solid-900.woff2
  36. +1 −1 public/js/app.js
  37. BIN public/public.zip
  38. +11 −6 resources/js/app.js
  39. +0 −15 resources/sass/_variables.scss
  40. +10 −2 resources/sass/app.scss
  41. +88 −0 resources/views/admin/dashboard/index.blade.php
  42. +3 −6 resources/views/auth/login.blade.php
  43. +51 −3 resources/views/dashboard/index.blade.php
  44. +1 −1 resources/views/home/index.blade.php
  45. +11 −6 resources/views/layouts/app.blade.php
  46. +159 −18 resources/views/manage/index.blade.php
  47. +162 −0 resources/views/profile/index.blade.php
  48. +21 −0 resources/views/vendor/flash/message.blade.php
  49. +19 −0 resources/views/vendor/flash/modal.blade.php
  50. +27 −6 routes/web.php
@@ -6,6 +6,8 @@
<sourceFolder url="file://$MODULE_DIR$/app" isTestSource="false" packagePrefix="App\" />
<excludeFolder url="file://$MODULE_DIR$/vendor/barryvdh/laravel-debugbar" />
<excludeFolder url="file://$MODULE_DIR$/vendor/beyondcode/laravel-dump-server" />
<excludeFolder url="file://$MODULE_DIR$/vendor/chillerlan/php-qrcode" />
<excludeFolder url="file://$MODULE_DIR$/vendor/chillerlan/php-settings-container" />
<excludeFolder url="file://$MODULE_DIR$/vendor/composer" />
<excludeFolder url="file://$MODULE_DIR$/vendor/dnoegel/php-xdg-base-dir" />
<excludeFolder url="file://$MODULE_DIR$/vendor/doctrine/inflector" />
@@ -17,19 +19,23 @@
<excludeFolder url="file://$MODULE_DIR$/vendor/fideloper/proxy" />
<excludeFolder url="file://$MODULE_DIR$/vendor/filp/whoops" />
<excludeFolder url="file://$MODULE_DIR$/vendor/fzaninotto/faker" />
<excludeFolder url="file://$MODULE_DIR$/vendor/geoip2/geoip2" />
<excludeFolder url="file://$MODULE_DIR$/vendor/hamcrest/hamcrest-php" />
<excludeFolder url="file://$MODULE_DIR$/vendor/hashids/hashids" />
<excludeFolder url="file://$MODULE_DIR$/vendor/jakub-onderka/php-console-color" />
<excludeFolder url="file://$MODULE_DIR$/vendor/jakub-onderka/php-console-highlighter" />
<excludeFolder url="file://$MODULE_DIR$/vendor/jaybizzle/crawler-detect" />
<excludeFolder url="file://$MODULE_DIR$/vendor/jenssegers/agent" />
<excludeFolder url="file://$MODULE_DIR$/vendor/laracasts/flash" />
<excludeFolder url="file://$MODULE_DIR$/vendor/laravel/framework" />
<excludeFolder url="file://$MODULE_DIR$/vendor/laravel/tinker" />
<excludeFolder url="file://$MODULE_DIR$/vendor/league/flysystem" />
<excludeFolder url="file://$MODULE_DIR$/vendor/maatwebsite/excel" />
<excludeFolder url="file://$MODULE_DIR$/vendor/markbaker/complex" />
<excludeFolder url="file://$MODULE_DIR$/vendor/markbaker/matrix" />
<excludeFolder url="file://$MODULE_DIR$/vendor/maximebf/debugbar" />
<excludeFolder url="file://$MODULE_DIR$/vendor/maxmind-db/reader" />
<excludeFolder url="file://$MODULE_DIR$/vendor/maxmind/web-service-common" />
<excludeFolder url="file://$MODULE_DIR$/vendor/mobiledetect/mobiledetectlib" />
<excludeFolder url="file://$MODULE_DIR$/vendor/mockery/mockery" />
<excludeFolder url="file://$MODULE_DIR$/vendor/monolog/monolog" />
@@ -71,6 +77,7 @@
<excludeFolder url="file://$MODULE_DIR$/vendor/sebastian/recursion-context" />
<excludeFolder url="file://$MODULE_DIR$/vendor/sebastian/resource-operations" />
<excludeFolder url="file://$MODULE_DIR$/vendor/sebastian/version" />
<excludeFolder url="file://$MODULE_DIR$/vendor/snowplow/referer-parser" />
<excludeFolder url="file://$MODULE_DIR$/vendor/swiftmailer/swiftmailer" />
<excludeFolder url="file://$MODULE_DIR$/vendor/symfony/console" />
<excludeFolder url="file://$MODULE_DIR$/vendor/symfony/css-selector" />
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="LaravelPluginSettings">
<option name="pluginEnabled" value="true" />
<option name="routerNamespace" value="" />
<option name="mainLanguage" value="en" />
</component>
</project>
@@ -95,6 +95,13 @@
<path value="$PROJECT_DIR$/vendor/phpoffice/phpspreadsheet" />
<path value="$PROJECT_DIR$/vendor/maatwebsite/excel" />
<path value="$PROJECT_DIR$/vendor/markbaker/complex" />
<path value="$PROJECT_DIR$/vendor/chillerlan/php-qrcode" />
<path value="$PROJECT_DIR$/vendor/chillerlan/php-settings-container" />
<path value="$PROJECT_DIR$/vendor/laracasts/flash" />
<path value="$PROJECT_DIR$/vendor/snowplow/referer-parser" />
<path value="$PROJECT_DIR$/vendor/geoip2/geoip2" />
<path value="$PROJECT_DIR$/vendor/maxmind-db/reader" />
<path value="$PROJECT_DIR$/vendor/maxmind/web-service-common" />
</include_path>
</component>
<component name="PhpProjectSharedConfiguration" php_language_level="7.1" />
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectTasksOptions" suppressed-tasks="SCSS" />
</project>
@@ -3,6 +3,7 @@
namespace App\Exports;
use App\Visit;
use App\Link;
use Maatwebsite\Excel\Concerns\FromCollection;
class VisitsExport implements FromCollection
@@ -0,0 +1,47 @@
<?php
namespace App\Http\Controllers\Admin;
use App\Exports\LinksExport;
use App\Link;
use App\Visit;
use Carbon\Carbon;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Auth;
use Maatwebsite\Excel\Facades\Excel;
class DashboardController extends Controller
{
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct()
{
$this->middleware(['auth', 'admin']);
}
public function index()
{
$links = Link::orderBy('created_at', 'desc')->paginate(config('7ul.per-page',10));
return view('admin.dashboard.index', ['links' => $links]);
}
public function month()
{
$data = [];
$data['visits'] = [];
$data['labels'] = [];
$monthDays = Carbon::now()->daysInMonth;
for ($i = 1; $i <= $monthDays; $i++) {
$start = Carbon::create(Carbon::now()->year, Carbon::now()->month, $i, 0);
$end = Carbon::create(Carbon::now()->year, Carbon::now()->month, $i + 1, 0);
$data['labels'][] = $start->format('Y-m-d');
$data['visits'][] = Visit::whereBetween('created_at', [$start, $end])->count();
}
return response()->json($data);
}
}
@@ -7,6 +7,7 @@
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Facades\Validator;
use Illuminate\Foundation\Auth\RegistersUsers;
use Illuminate\Support\Str;
class RegisterController extends Controller
{
@@ -66,6 +67,7 @@ protected function create(array $data)
return User::create([
'name' => $data['name'],
'email' => $data['email'],
'api_token' => Str::random(60),
'password' => Hash::make($data['password']),
]);
}
@@ -4,9 +4,11 @@
use App\Exports\LinksExport;
use App\Link;
use App\Visit;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Maatwebsite\Excel\Facades\Excel;
use Carbon\Carbon;
class DashboardController extends Controller
{
@@ -35,4 +37,20 @@ public function export()
{
return Excel::download(new LinksExport(), date("Y-m-d'-").'links.xlsx');
}
public function month()
{
$data = [];
$data['visits'] = [];
$data['labels'] = [];
$monthDays = Carbon::now()->daysInMonth;
for ($i = 1; $i <= $monthDays; $i++) {
$start = Carbon::create(Carbon::now()->year, Carbon::now()->month, $i, 0);
$end = Carbon::create(Carbon::now()->year, Carbon::now()->month, $i + 1, 0);
$data['labels'][] = $start->format('Y-m-d');
$data['visits'][] = Visit::whereIn('link_id',Link::select('id')->where('user_id', auth()->user()->id)->get())->whereBetween('created_at', [$start, $end])->count();
}
return response()->json($data);
}
}
@@ -9,6 +9,7 @@
use App\Link;
use App\Visit;
use Illuminate\Http\Request;
use GeoIp2\Database\Reader;
class LinkController extends Controller
{
@@ -53,6 +54,7 @@ public function shorten(Request $request)
$link->code = $link->encode(config('7ul.code-type'));
$link->save();
}
flash(__('Done!'))->success();
return redirect()->route('manage',[$link->code, $link->password]);
}
} else {
@@ -82,35 +84,32 @@ public function shorten(Request $request)
$link->code = $link->encode(config('7ul.code-type'));
$link->save();
}
flash(__('Done!'))->success();
return redirect()->route('manage',[$link->code, $link->password]);
}
}
public function redirect($code)
{
if ($link = Link::whereCode($code)->first()) {
$data = [];
$data['HTTP_USER_AGENT'] = $_SERVER['HTTP_USER_AGENT'];
if(isset($_SERVER['HTTP_REFERER'])) {
$data['HTTP_REFERER'] = $_SERVER['HTTP_REFERER'];
}
$geo = unserialize(file_get_contents('http://www.geoplugin.net/php.gp?ip='.request()->ip()));
$agent = new Agent();
$visit = new Visit();
$country = $this->getCountry(request()->ip());
$visit->link_id = $link->id;
$visit->ip = request()->ip();
$visit->device = $agent->device();
$visit->country = $geo['geoplugin_countryName'];
$visit->country_code = $geo['geoplugin_countryCode'];
$visit->country = $country['country'];
$visit->country_code = $country['country_code'];
$visit->platform = $agent->platform();
$visit->platform_version = $agent->version($agent->platform());
$visit->browser = $agent->browser();
$visit->browser_version= $agent->version($agent->browser());
if(isset($_SERVER['HTTP_REFERER'])) {
$visit->referer = $_SERVER['HTTP_REFERER'];
}
$visit->data = $data;
$visit->geo = $geo;
$visit->save();
if($link->type == 'redirect') {
@@ -125,6 +124,21 @@ public function redirect($code)
}
}
public function getCountry($ip)
{
try {
$reader = new Reader(storage_path('geo/GeoLite2-Country.mmdb'));
$record = $reader->country($ip);
$country = $record->country->name;
$country_code = $record->country->isoCode;
return ['country' => $country, 'country_code' => $country_code];
} catch (\Exception $e) {
$country = __('Unknown');
$country_code = __('Unknown');
return ['country' => $country, 'country_code' => $country_code];
}
}
public function lastLinks()
{
$links = Link::with(['visits'])->public()->latest()->limit(config('7ul.count-last-links', 5))->get();
@@ -7,6 +7,7 @@
use App\Visit;
use Illuminate\Http\Request;
use Maatwebsite\Excel\Facades\Excel;
use Illuminate\Support\Facades\DB;
class ManageController extends Controller
{
@@ -37,6 +38,19 @@ public function export($code, $password)
}
}
public function qrcode($code, $password)
{
if ($link = Link::whereCode($code)->first()) {
if($link->password == $password) {
return Excel::download(new VisitsExport($link), date("Y-m-d-").$link->id.'-visits.xlsx');
} else {
return redirect()->route('home');
}
} else {
return redirect()->route('home');
}
}
public function visit($id, $code, $password)
{
if ($link = Link::whereCode($code)->first()) {
@@ -71,8 +85,82 @@ public function title($code, $password)
}
}
public function update()
public function country($code, $password)
{
if ($link = Link::whereCode($code)->first()) {
if($link->password == $password) {
$visit_data = array();
$visit_labels = array();
$visits = Visit::select(DB::raw('COUNT(*) AS visits, country'))
->where('link_id', $link->id)
->groupBy('country')
->get();
foreach ($visits as $visit) {
if($visit->country) {
$visit_labels[] = $visit->country;
} else {
$visit_labels[] = __('Localhost');
}
$visit_data[] = $visit->visits;
}
return response()->json(['labels' => $visit_labels ,'data' => $visit_data]);
} else {
return redirect()->route('home');
}
} else {
return redirect()->route('home');
}
}
public function browser($code, $password)
{
if ($link = Link::whereCode($code)->first()) {
if($link->password == $password) {
$visit_data = array();
$visit_labels = array();
$visits = Visit::select(DB::raw('COUNT(*) AS visits, browser'))
->where('link_id', $link->id)
->groupBy('browser')
->get();
foreach ($visits as $visit) {
$visit_labels[] = $visit->browser;
$visit_data[] = $visit->visits;
}
return response()->json(['labels' => $visit_labels ,'data' => $visit_data]);
} else {
return redirect()->route('home');
}
} else {
return redirect()->route('home');
}
}
public function platform($code, $password)
{
if ($link = Link::whereCode($code)->first()) {
if($link->password == $password) {
$visit_data = array();
$visit_labels = array();
$visits = Visit::select(DB::raw('COUNT(*) AS visits, platform'))
->where('link_id', $link->id)
->groupBy('platform')
->get();
foreach ($visits as $visit) {
$visit_labels[] = $visit->platform;
$visit_data[] = $visit->visits;
}
return response()->json(['labels' => $visit_labels ,'data' => $visit_data]);
} else {
return redirect()->route('home');
}
} else {
return redirect()->route('home');
}
}
public function update(Request $request, $code, $password)
{
return false;
}
}

0 comments on commit 9906054

Please sign in to comment.
You can’t perform that action at this time.