issue #1 reset form resets selected icon to empty
This commit is contained in:
40
app/Console/Kernel.php
Normal file
40
app/Console/Kernel.php
Normal file
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console;
|
||||
|
||||
use Illuminate\Console\Scheduling\Schedule;
|
||||
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
|
||||
|
||||
class Kernel extends ConsoleKernel
|
||||
{
|
||||
/**
|
||||
* The Artisan commands provided by your application.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $commands = [
|
||||
//
|
||||
];
|
||||
|
||||
/**
|
||||
* Define the application's command schedule.
|
||||
*
|
||||
* @param \Illuminate\Console\Scheduling\Schedule $schedule
|
||||
* @return void
|
||||
*/
|
||||
protected function schedule(Schedule $schedule)
|
||||
{
|
||||
// $schedule->command('inspire')
|
||||
// ->hourly();
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the Closure based commands for the application.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function commands()
|
||||
{
|
||||
require base_path('routes/console.php');
|
||||
}
|
||||
}
|
||||
65
app/Exceptions/Handler.php
Normal file
65
app/Exceptions/Handler.php
Normal file
@@ -0,0 +1,65 @@
|
||||
<?php
|
||||
|
||||
namespace App\Exceptions;
|
||||
|
||||
use Exception;
|
||||
use Illuminate\Auth\AuthenticationException;
|
||||
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
|
||||
|
||||
class Handler extends ExceptionHandler
|
||||
{
|
||||
/**
|
||||
* A list of the exception types that should not be reported.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $dontReport = [
|
||||
\Illuminate\Auth\AuthenticationException::class,
|
||||
\Illuminate\Auth\Access\AuthorizationException::class,
|
||||
\Symfony\Component\HttpKernel\Exception\HttpException::class,
|
||||
\Illuminate\Database\Eloquent\ModelNotFoundException::class,
|
||||
\Illuminate\Session\TokenMismatchException::class,
|
||||
\Illuminate\Validation\ValidationException::class,
|
||||
];
|
||||
|
||||
/**
|
||||
* Report or log an exception.
|
||||
*
|
||||
* This is a great spot to send exceptions to Sentry, Bugsnag, etc.
|
||||
*
|
||||
* @param \Exception $exception
|
||||
* @return void
|
||||
*/
|
||||
public function report(Exception $exception)
|
||||
{
|
||||
parent::report($exception);
|
||||
}
|
||||
|
||||
/**
|
||||
* Render an exception into an HTTP response.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param \Exception $exception
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function render($request, Exception $exception)
|
||||
{
|
||||
return parent::render($request, $exception);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert an authentication exception into an unauthenticated response.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param \Illuminate\Auth\AuthenticationException $exception
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
protected function unauthenticated($request, AuthenticationException $exception)
|
||||
{
|
||||
if ($request->expectsJson()) {
|
||||
return response()->json(['error' => 'Unauthenticated.'], 401);
|
||||
}
|
||||
|
||||
return redirect()->guest('login');
|
||||
}
|
||||
}
|
||||
32
app/Http/Controllers/Auth/ForgotPasswordController.php
Normal file
32
app/Http/Controllers/Auth/ForgotPasswordController.php
Normal file
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Auth;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Foundation\Auth\SendsPasswordResetEmails;
|
||||
|
||||
class ForgotPasswordController extends Controller
|
||||
{
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Password Reset Controller
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This controller is responsible for handling password reset emails and
|
||||
| includes a trait which assists in sending these notifications from
|
||||
| your application to your users. Feel free to explore this trait.
|
||||
|
|
||||
*/
|
||||
|
||||
use SendsPasswordResetEmails;
|
||||
|
||||
/**
|
||||
* Create a new controller instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->middleware('guest');
|
||||
}
|
||||
}
|
||||
39
app/Http/Controllers/Auth/LoginController.php
Normal file
39
app/Http/Controllers/Auth/LoginController.php
Normal file
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Auth;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Foundation\Auth\AuthenticatesUsers;
|
||||
|
||||
class LoginController extends Controller
|
||||
{
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Login Controller
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This controller handles authenticating users for the application and
|
||||
| redirecting them to your home screen. The controller uses a trait
|
||||
| to conveniently provide its functionality to your applications.
|
||||
|
|
||||
*/
|
||||
|
||||
use AuthenticatesUsers;
|
||||
|
||||
/**
|
||||
* Where to redirect users after login.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $redirectTo = '/home';
|
||||
|
||||
/**
|
||||
* Create a new controller instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->middleware('guest', ['except' => 'logout']);
|
||||
}
|
||||
}
|
||||
71
app/Http/Controllers/Auth/RegisterController.php
Normal file
71
app/Http/Controllers/Auth/RegisterController.php
Normal file
@@ -0,0 +1,71 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Auth;
|
||||
|
||||
use App\User;
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
use Illuminate\Foundation\Auth\RegistersUsers;
|
||||
|
||||
class RegisterController extends Controller
|
||||
{
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Register Controller
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This controller handles the registration of new users as well as their
|
||||
| validation and creation. By default this controller uses a trait to
|
||||
| provide this functionality without requiring any additional code.
|
||||
|
|
||||
*/
|
||||
|
||||
use RegistersUsers;
|
||||
|
||||
/**
|
||||
* Where to redirect users after registration.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $redirectTo = '/home';
|
||||
|
||||
/**
|
||||
* Create a new controller instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->middleware('guest');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a validator for an incoming registration request.
|
||||
*
|
||||
* @param array $data
|
||||
* @return \Illuminate\Contracts\Validation\Validator
|
||||
*/
|
||||
protected function validator(array $data)
|
||||
{
|
||||
return Validator::make($data, [
|
||||
'name' => 'required|max:255',
|
||||
'email' => 'required|email|max:255|unique:users',
|
||||
'password' => 'required|min:6|confirmed',
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new user instance after a valid registration.
|
||||
*
|
||||
* @param array $data
|
||||
* @return User
|
||||
*/
|
||||
protected function create(array $data)
|
||||
{
|
||||
return User::create([
|
||||
'name' => $data['name'],
|
||||
'email' => $data['email'],
|
||||
'password' => bcrypt($data['password']),
|
||||
]);
|
||||
}
|
||||
}
|
||||
39
app/Http/Controllers/Auth/ResetPasswordController.php
Normal file
39
app/Http/Controllers/Auth/ResetPasswordController.php
Normal file
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Auth;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Foundation\Auth\ResetsPasswords;
|
||||
|
||||
class ResetPasswordController extends Controller
|
||||
{
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Password Reset Controller
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This controller is responsible for handling password reset requests
|
||||
| and uses a simple trait to include this behavior. You're free to
|
||||
| explore this trait and override any methods you wish to tweak.
|
||||
|
|
||||
*/
|
||||
|
||||
use ResetsPasswords;
|
||||
|
||||
/**
|
||||
* Where to redirect users after resetting their password.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $redirectTo = '/home';
|
||||
|
||||
/**
|
||||
* Create a new controller instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->middleware('guest');
|
||||
}
|
||||
}
|
||||
42
app/Http/Controllers/ClosedShops.php
Normal file
42
app/Http/Controllers/ClosedShops.php
Normal file
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Paper\Paper;
|
||||
|
||||
class ClosedShops extends Controller
|
||||
{
|
||||
|
||||
private $icon = 'frown-o';
|
||||
private $daysClosed = ['11-03','18-03',
|
||||
'01-04','02-04','08-04','15-04','22-04',
|
||||
'01-05','03-05','13-05','20-05','31-05',
|
||||
'10-06','17-06',
|
||||
'08-07','15-07','22-07',
|
||||
'12-08','15-08','19-08',
|
||||
'09-09','16-09','23-09',
|
||||
'14-10','21-10',
|
||||
'01-11','11-11','18-11',
|
||||
'09-12','16-12','25-12','16-12'
|
||||
];
|
||||
|
||||
private $paper;
|
||||
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->paper = new Paper();
|
||||
}
|
||||
|
||||
|
||||
public function tomorrow()
|
||||
{
|
||||
$today = new \DateTime();
|
||||
$tomorrow = $today->modify('+1 day');
|
||||
if(in_array($tomorrow->format('d-m'), $this->daysClosed)){
|
||||
$this->paper->sendPrint('Jutro sklepy są zamknięte.', "Jutrzejszy dzień jest dniem \nwolnym od handlu ponieważ jutro \njest święto albo niedziela wolna \nod handlu\n\n".$tomorrow->format('d-m-Y'), $this->icon);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
13
app/Http/Controllers/Controller.php
Normal file
13
app/Http/Controllers/Controller.php
Normal file
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Illuminate\Foundation\Bus\DispatchesJobs;
|
||||
use Illuminate\Routing\Controller as BaseController;
|
||||
use Illuminate\Foundation\Validation\ValidatesRequests;
|
||||
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
|
||||
|
||||
class Controller extends BaseController
|
||||
{
|
||||
use AuthorizesRequests, DispatchesJobs, ValidatesRequests;
|
||||
}
|
||||
26
app/Http/Controllers/Keyboard.php
Normal file
26
app/Http/Controllers/Keyboard.php
Normal file
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Paper\CinemaMultikino;
|
||||
use DiDom\Query;
|
||||
use Illuminate\Http\Request;
|
||||
use DiDom\Document;
|
||||
use App\Paper\Paper;
|
||||
|
||||
class Keyboard extends Controller
|
||||
{
|
||||
|
||||
private $paper;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->paper = new Paper();
|
||||
}
|
||||
|
||||
public function press($key)
|
||||
{
|
||||
$this->paper->sendPrint($key);
|
||||
}
|
||||
|
||||
}
|
||||
281
app/Http/Controllers/Main.php
Normal file
281
app/Http/Controllers/Main.php
Normal file
@@ -0,0 +1,281 @@
|
||||
<?php
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: k
|
||||
* Date: 10.02.2017
|
||||
* Time: 20:10
|
||||
*/
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
set_time_limit(-1);
|
||||
|
||||
use App\Paper\Airly;
|
||||
use App\Paper\Paper;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Mike42\Escpos\PrintConnectors\FilePrintConnector;
|
||||
use Mike42\Escpos\Printer;
|
||||
use Intervention\Image\ImageManagerStatic as Image;
|
||||
use Mike42\Escpos\EscposImage;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class Main extends Controller
|
||||
{
|
||||
|
||||
private $paper = null;
|
||||
const TEMPLATE = 'template';
|
||||
const NOTE = 'note';
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->paper = new Paper();
|
||||
}
|
||||
|
||||
/**
|
||||
* post::/printImage
|
||||
* @param Request $request
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function imagePrint(Request $request)
|
||||
{
|
||||
|
||||
if ($request->hasFile('photo')) {
|
||||
$file = $request->photo;
|
||||
} else {
|
||||
$file = $request->input('url');
|
||||
}
|
||||
|
||||
$image = Image::make($file);
|
||||
if ($image->width() > $image->height()) {
|
||||
$image->rotate(90);
|
||||
}
|
||||
|
||||
|
||||
$image = $image->greyscale()
|
||||
->resize(300, null, function ($constraint) {
|
||||
$constraint->aspectRatio();
|
||||
$constraint->upsize();
|
||||
});
|
||||
|
||||
|
||||
$fileName = storage_path('temp.png');
|
||||
$image->save($fileName, 100);
|
||||
|
||||
|
||||
$img = imagecreatefrompng($fileName);
|
||||
// imagefilter($img, IMG_FILTER_GRAYSCALE);
|
||||
$width = imagesx($img);
|
||||
$height = imagesy($img);
|
||||
$img_arr = array();
|
||||
|
||||
// Parse image (can be combined with dither stage, but combining them is slower.)
|
||||
|
||||
for ($y = 0; $y < $height; $y++) {
|
||||
for ($x = 0; $x < $width; $x++) {
|
||||
$img_arr[$x][$y] = imagecolorat($img, $x, $y);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// make a b/w output image.
|
||||
$output = imagecreate($width, $height);
|
||||
$black = imagecolorallocate($output, 0, 0, 0); //background color.
|
||||
$white = imagecolorallocate($output, 0xff, 0xff, 0xff);
|
||||
|
||||
|
||||
for ($y = 1; $y < $height - 3; $y++) {
|
||||
for ($x = 1; $x < $width - 3; $x++) {
|
||||
$old = $img_arr[$x][$y];
|
||||
if ($old > 0xffffff * .5) { // This is the b/w threshold. Currently @ halfway between white and black.
|
||||
$new = 0xffffff;
|
||||
imagesetpixel($output, $x, $y, $white); // Only setting white pixels, because the image is already black.
|
||||
} else {
|
||||
$new = 0x000000;
|
||||
}
|
||||
$quant_error = $old - $new;
|
||||
$error_diffusion = (1 / 8) * $quant_error; //I can do this because this dither uses 1 value for the applied error diffusion.
|
||||
//dithering here.
|
||||
$img_arr[$x + 1][$y] += $error_diffusion;
|
||||
$img_arr[$x + 2][$y] += $error_diffusion;
|
||||
$img_arr[$x - 1][$y + 1] += $error_diffusion;
|
||||
$img_arr[$x][$y + 1] += $error_diffusion;
|
||||
$img_arr[$x + 1][$y + 1] += $error_diffusion;
|
||||
$img_arr[$x][$y + 2] += $error_diffusion;
|
||||
}
|
||||
}
|
||||
|
||||
// plop out a png of the dithered image.
|
||||
|
||||
// Header("Content-type: image/png");
|
||||
imagepng($output, $fileName, 9); //to print to screen
|
||||
|
||||
|
||||
$connector = new FilePrintConnector("/dev/usb/lp0");
|
||||
$printer = new Printer($connector);
|
||||
$img = EscposImage::load($fileName, false);
|
||||
$printer->bitImage($img);
|
||||
|
||||
$printer->feed(4);
|
||||
|
||||
return back();
|
||||
}
|
||||
|
||||
/**
|
||||
* get:/
|
||||
* @param Request $request
|
||||
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
|
||||
*/
|
||||
public function listView(Request $request)
|
||||
{
|
||||
$notes = DB::select('SELECT * FROM note WHERE type = "note" ORDER BY updated_at DESC');
|
||||
$templates = DB::select('SELECT * FROM note WHERE type = "template" ORDER BY updated_at DESC');
|
||||
return view('list', [
|
||||
'notes' => $notes,
|
||||
'templates' => $templates,
|
||||
'title' => $request->old('title'),
|
||||
'text' => $request->old('text'),
|
||||
'icon_selected' => $request->old('icon'),
|
||||
'icons' => $this->paper->getIcons()
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* get:/airly
|
||||
* @param Request $request
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function airly(Request $request)
|
||||
{
|
||||
$airly = new Airly();
|
||||
$this->paper->sendImagePrint('cloud.png');
|
||||
$this->paper->sendHeaderPrint('Jakość powietrza:' . PHP_EOL . date('H:i d-m-Y'));
|
||||
foreach ($airly->getStations() as $stationId) {
|
||||
$stationInfo = $airly->getStationInfo($stationId);
|
||||
$this->paper->sendHeaderPrint($stationInfo['address']['locality'] . ' ' . $stationInfo['address']['route']);
|
||||
$dataText = $airly->getInformationText($stationId);
|
||||
$this->paper->sendPrint('', $dataText);
|
||||
}
|
||||
return back();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* post::/print/{id}
|
||||
* @param $id
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function printText($id)
|
||||
{
|
||||
$note = DB::table('note')->where('id', $id)->first();
|
||||
$this->paper->sendPrint($note->topic, $note->text, $note->icon);
|
||||
return back();
|
||||
}
|
||||
|
||||
private function templateReplace($input){
|
||||
|
||||
return str_replace(['[d]', '[m]', '[y]', '[h]', '[i]', '[s]'],
|
||||
[date('d'), date('m'), date('Y'), date('H'), date('i'), date('s')],
|
||||
$input);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* get::/edit/{id}/{slug}
|
||||
* post::/edit/{id}/{slug}
|
||||
* @param Request $request
|
||||
* @param $id
|
||||
* @param $slug
|
||||
* @return \Illuminate\Contracts\View\Factory|\Illuminate\Http\RedirectResponse|\Illuminate\View\View
|
||||
*/
|
||||
public function edit(Request $request, $id, $slug)
|
||||
{
|
||||
$note = DB::table('note')->where('id', $id)->first();
|
||||
if ($request->isMethod('post')) {
|
||||
if ($request->exists('save') ||
|
||||
$request->exists('save_template')) {
|
||||
if ($note->type == $this::TEMPLATE) {
|
||||
$id = DB::table('note')
|
||||
->insertGetId([
|
||||
'topic' => $this->templateReplace($request->input('title')),
|
||||
'topic_slug' => str_slug($request->input('title'), '_'),
|
||||
'text' => $this->templateReplace($request->input('text')),
|
||||
'icon' => $request->input('icon'),
|
||||
'type' => self::NOTE,
|
||||
'created_at' => time(),
|
||||
'updated_at' => time()
|
||||
]);
|
||||
$note = DB::table('note')->where('id', $id)->first();
|
||||
} else {
|
||||
DB::table('note')
|
||||
->where('id', $note->id)
|
||||
->update([
|
||||
'topic' => $request->input('title'),
|
||||
'topic_slug' => str_slug($request->input('title'), '_'),
|
||||
'text' => $request->input('text'),
|
||||
'icon' => $request->input('icon'),
|
||||
'updated_at' => time(),
|
||||
]);
|
||||
}
|
||||
} elseif ($request->exists('delete')) {
|
||||
DB::table('note')
|
||||
->where('id', $note->id)
|
||||
->delete();
|
||||
return redirect()->route('list');
|
||||
} elseif ($request->exists('print')) {
|
||||
$this->paper->sendPrint($request->input('title'), $request->input('text'), $request->input('icon'));
|
||||
}
|
||||
return redirect()->route('edit', ['id' => $note->id, 'slug' => $note->topic_slug]);
|
||||
} else {
|
||||
return view('edit', [
|
||||
'title' => $note->topic,
|
||||
'text' => $note->text,
|
||||
'icon_selected' => $note->icon,
|
||||
'type' => $note->type,
|
||||
'id' => $note->id,
|
||||
'icons' => $this->paper->getIcons(),
|
||||
'topic_slug' => $note->topic_slug,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* post::/
|
||||
* @param Request $request
|
||||
* @return $this|\Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function main(Request $request)
|
||||
{
|
||||
if ($request->exists('save')) {
|
||||
$id = DB::table('note')
|
||||
->insertGetId([
|
||||
'topic' => $request->input('title'),
|
||||
'topic_slug' => str_slug($request->input('title'), '_'),
|
||||
'text' => $request->input('text'),
|
||||
'icon' => $request->input('icon'),
|
||||
'type' => self::NOTE,
|
||||
'created_at' => time(),
|
||||
'updated_at' => time()
|
||||
]);
|
||||
$note = DB::table('note')->where('id', $id)->first();
|
||||
return redirect()->route('edit', ['id' => $note->id, 'slug' => $note->topic_slug]);
|
||||
} elseif ($request->exists('save_template')) {
|
||||
$id = DB::table('note')
|
||||
->insertGetId([
|
||||
'topic' => $request->input('title'),
|
||||
'topic_slug' => str_slug($request->input('title'), '_'),
|
||||
'text' => $request->input('text'),
|
||||
'icon' => $request->input('icon'),
|
||||
'type' => self::TEMPLATE,
|
||||
'created_at' => time(),
|
||||
'updated_at' => time()
|
||||
]);
|
||||
$note = DB::table('note')->where('id', $id)->first();
|
||||
return redirect()->route('edit', ['id' => $note->id, 'slug' => $note->topic_slug]);
|
||||
} else {
|
||||
$this->paper->sendPrint($request->input('title'), $request->input('text'), $request->input('icon'));
|
||||
return back()->withInput();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
110
app/Http/Controllers/PacktPub.php
Normal file
110
app/Http/Controllers/PacktPub.php
Normal file
@@ -0,0 +1,110 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Paper\CinemaMultikino;
|
||||
use DiDom\Query;
|
||||
use Illuminate\Http\Request;
|
||||
use DiDom\Document;
|
||||
use App\Paper\Paper;
|
||||
|
||||
class PacktPub extends Controller
|
||||
{
|
||||
|
||||
private $main;
|
||||
private $icon = '/small/book.png';
|
||||
|
||||
private $freeBook = 'https://www.packtpub.com/packt/offers/free-learning';
|
||||
|
||||
|
||||
private $loginData;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->paper = new Paper();
|
||||
$this->loginData = array(
|
||||
'email' => 'krzysiej@gmail.com',
|
||||
'password' => 'korki1korki1',
|
||||
'op' => 'Login',
|
||||
'form_build_id' => '',
|
||||
'form_id' => 'packt_user_login_form',
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
|
||||
public function today()
|
||||
{
|
||||
|
||||
$data = file_get_contents($this->freeBook);
|
||||
$document = new Document($data);
|
||||
|
||||
// list(,,$id,)= explode('/', $document->first('//form[@id="free-learning-form"]/@action', Query::TYPE_XPATH));
|
||||
$id = $document->first('//input[@id="free-learning-register-claim-title-nid"]/@value', Query::TYPE_XPATH);
|
||||
|
||||
$myBooksRaw = $this->c('https://www.packtpub.com/account/my-ebooks', $this->loginData);
|
||||
|
||||
print_r($myBooksRaw);
|
||||
$myBooks = new Document($myBooksRaw);
|
||||
|
||||
// $x = $myBooks->first('//div[@nid="' . $id . '"]', Query::TYPE_XPATH);
|
||||
|
||||
var_dump($id);
|
||||
|
||||
var_dump('//div[@nid="' . $id . '"]');
|
||||
$isOwnd = (bool)$myBooks->first('//div[@nid="' . $id . '"]', Query::TYPE_XPATH);
|
||||
|
||||
var_dump($isOwnd);
|
||||
die();
|
||||
$titleNode = $document->first('.dotd-title h2');
|
||||
|
||||
if ($titleNode) {
|
||||
$title = trim($titleNode->text());
|
||||
}
|
||||
|
||||
$descriptionNodes = $document->find('//div[contains(@class,"dotd-main-book-summary")]/div[not(@class)]', Query::TYPE_XPATH);
|
||||
$descriptionText = '';
|
||||
if ($descriptionNodes) {
|
||||
foreach ($descriptionNodes as $node) {
|
||||
$descriptionText .= trim($node->text()) . "\n";
|
||||
}
|
||||
}
|
||||
|
||||
$descriptionText .= "\n\n" . (($isOwnd) ? 'Masz już tę książkę w biblioteczce.' : 'Nie masz jeszcze tej książki.');
|
||||
$descriptionText .= "\n\n" . date('Y-m-d');
|
||||
|
||||
|
||||
$imageNode = $document->first('//div[contains(@class, "dotd-main-book")]//img[contains(@class, "bookimage")]/@src', Query::TYPE_XPATH);
|
||||
if ($imageNode) {
|
||||
$imageNode = str_replace(' ', '%20', $imageNode);
|
||||
|
||||
$this->paper->sendPrint($title, $descriptionText, 'https:' . $imageNode, false);
|
||||
}
|
||||
}
|
||||
|
||||
private function c($url, $postArray = null)
|
||||
{
|
||||
$cookie = __DIR__ . '/cookie.txt';
|
||||
$ch = curl_init();
|
||||
$useragent = "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.6) Gecko/20070725 Firefox/2.0.0.6";
|
||||
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
|
||||
curl_setopt($ch, CURLOPT_FAILONERROR, TRUE);
|
||||
curl_setopt($ch, CURLOPT_COOKIESESSION, TRUE);
|
||||
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
|
||||
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie);
|
||||
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie);
|
||||
curl_setopt($ch, CURLOPT_USERAGENT, $useragent);
|
||||
curl_setopt($ch, CURLOPT_URL, $url);
|
||||
if (!is_null($postArray)) {
|
||||
curl_setopt($ch, CURLOPT_POST, TRUE);
|
||||
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($postArray));
|
||||
}
|
||||
$result = curl_exec($ch);
|
||||
|
||||
curl_close($ch);
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
219
app/Http/Controllers/Repertoire.php
Normal file
219
app/Http/Controllers/Repertoire.php
Normal file
@@ -0,0 +1,219 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Paper\CinemaMultikino;
|
||||
use DiDom\Document;
|
||||
use App\Paper\Paper;
|
||||
|
||||
class Repertoire extends Controller
|
||||
{
|
||||
|
||||
private $main;
|
||||
private $icon = '/small/film.png';
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->main = new Paper();
|
||||
}
|
||||
|
||||
|
||||
public function today_cinemacity()
|
||||
{
|
||||
$date = date('d/m/Y');
|
||||
$repertuarText = $this->cinemacityRepertuar($date);
|
||||
$this->main->sendPrint('', $repertuarText, $this->icon, $this->icon);
|
||||
return back();
|
||||
}
|
||||
|
||||
|
||||
public function tomorrow_cinemacity()
|
||||
{
|
||||
$date = new \DateTime();
|
||||
$date->modify('+1 day');
|
||||
$repertuarText = $this->cinemacityRepertuar($date->format('d/m/Y'));
|
||||
$this->main->sendPrint('', $repertuarText, $this->icon, $this->icon);
|
||||
return back();
|
||||
}
|
||||
|
||||
public function cinemacityRepertuar($date)
|
||||
{
|
||||
$url = 'https://www.cinema-city.pl/scheduleInfo?locationId=1010308&date=' . $date . '&venueTypeId=0&hideSite=false&openedFromPopup=1';
|
||||
|
||||
$document = new Document($url, true);
|
||||
$text = "Repertuar Cinema-City\n";
|
||||
$text .= str_replace('/', '-', $date) . "\n\n";
|
||||
|
||||
$movies = $document->find('table tbody tr');
|
||||
foreach ($movies as $movie) {
|
||||
// dump($movie);
|
||||
$text .= $movie->find('.featureLink')[0]->text() . "\n";
|
||||
$hours = [];
|
||||
foreach ($movie->find('.prsnt a') as $projection) {
|
||||
$hours[] = trim($projection->text());
|
||||
}
|
||||
$text .= implode(', ', $hours) . "\n\n";
|
||||
}
|
||||
return $text;
|
||||
}
|
||||
|
||||
|
||||
private function multikinoRepertuar($date)
|
||||
{
|
||||
|
||||
$text = '';
|
||||
$repertuar = json_decode(file_get_contents('https://multikino.pl/pl/repertoire/cinema/seances?id=4&from=' . $date));
|
||||
$text .= "Repertuar Multikino Gdańsk\n";
|
||||
$text .= $date . "\n\n";
|
||||
|
||||
foreach ($repertuar->results as $movie) {
|
||||
$text .= $movie->title . "\n";
|
||||
$text .= $movie->print_version . "\n";
|
||||
|
||||
$hours = [];
|
||||
foreach ($movie->seances as $seans) {
|
||||
$hours[] = date('H:i', strtotime($seans->beginning_date));
|
||||
}
|
||||
$text .= implode(', ', $hours) . "\n\n";
|
||||
}
|
||||
|
||||
return $text;
|
||||
}
|
||||
|
||||
public function today_multikino()
|
||||
{
|
||||
$multikino = new CinemaMultikino();
|
||||
|
||||
$repertuarText = $multikino->convertToPrint(date('Y-m-d'), 4);
|
||||
$this->main->sendPrint('', $repertuarText, $this->icon);
|
||||
return back();
|
||||
}
|
||||
|
||||
public function tomorrow_multikino()
|
||||
{
|
||||
$date = new \DateTime();
|
||||
$date->modify('+1 day');
|
||||
|
||||
$multikino = new CinemaMultikino();
|
||||
$repertuarText = $multikino->convertToPrint($date->format('Y-m-d'), 4);
|
||||
$this->main->sendPrint('', $repertuarText, $this->icon);
|
||||
return back();
|
||||
|
||||
|
||||
// $repertuarText = $this->multikinoRepertuar($date->format('Y-m-d'));
|
||||
// $this->main->sendPrint('', $repertuarText);
|
||||
// return back();
|
||||
}
|
||||
|
||||
|
||||
public function tomorrow_gdynskiecentrumfilmowe()
|
||||
{
|
||||
$date = new \DateTime();
|
||||
$date->modify('+1 day');
|
||||
|
||||
$repertuarText = $this->gdynskieCentrumFilmowe($date->format('d_m_Y'));
|
||||
$this->main->sendPrint('', $repertuarText, $this->icon);
|
||||
return back();
|
||||
}
|
||||
|
||||
public function today_gdynskiecentrumfilmowe()
|
||||
{
|
||||
$date = date('d_m_Y');
|
||||
$repertuarText = $this->gdynskieCentrumFilmowe($date);
|
||||
$this->main->sendPrint('', $repertuarText, $this->icon);
|
||||
return back();
|
||||
}
|
||||
|
||||
public function today_helios()
|
||||
{
|
||||
$this->main->sendPrint('', $this->helios(0, 2), $this->icon);
|
||||
$this->main->sendPrint('', $this->helios(0, 49));
|
||||
return back();
|
||||
}
|
||||
|
||||
public function tomorrow_helios()
|
||||
{
|
||||
$this->main->sendPrint('', $this->helios(1, 2), $this->icon);
|
||||
$this->main->sendPrint('', $this->helios(1, 49));
|
||||
return back();
|
||||
}
|
||||
|
||||
public function today_repertoire()
|
||||
{
|
||||
|
||||
$this->today_multikino();
|
||||
$this->today_cinemacity();
|
||||
$this->today_helios();
|
||||
$this->today_gdynskiecentrumfilmowe();
|
||||
|
||||
}
|
||||
|
||||
public function tomorrow_repertoire()
|
||||
{
|
||||
|
||||
$this->tomorrow_multikino();
|
||||
$this->tomorrow_cinemacity();
|
||||
$this->tomorrow_helios();
|
||||
$this->tomorrow_gdynskiecentrumfilmowe();
|
||||
}
|
||||
|
||||
private function helios($day, $cinemaId)
|
||||
{
|
||||
$url = 'http://www.helios.pl/2,Gdansk/Repertuar/axRepertoire/?dzien=' . $day . '&kino=' . $cinemaId;
|
||||
|
||||
|
||||
$data = json_decode(file_get_contents($url));
|
||||
$document = new Document();
|
||||
$data->html = str_replace(["\n", "\t"], '', $data->html);
|
||||
$document->loadHtml($data->html);
|
||||
|
||||
|
||||
$cinemas = [2 => 'Helios Alfa', 49 => 'Helios Metropolia'];
|
||||
|
||||
$text = '';
|
||||
$text .= "Repertuar $cinemas[$cinemaId]\n";
|
||||
|
||||
$date = new \DateTime();
|
||||
$date->modify('+' . $day . ' day');
|
||||
|
||||
$text .= $date->format('d-m-Y') . "\n\n";
|
||||
|
||||
|
||||
foreach ($document->find('.seance') as $seans) {
|
||||
$text .= trim($seans->find('.movie-title')[0]->text()) . "\n";
|
||||
$hours = [];
|
||||
foreach ($seans->find('.time li') as $hour) {
|
||||
$hours[] = $hour->text();
|
||||
}
|
||||
$text .= implode(', ', array_unique($hours)) . "\n\n";
|
||||
}
|
||||
|
||||
return $text;
|
||||
}
|
||||
|
||||
|
||||
private function gdynskieCentrumFilmowe($date)
|
||||
{
|
||||
|
||||
|
||||
$url = 'http://www.gdynskiecentrumfilmowe.pl/kino_studyjne/repertuar/,' . strtotime($date) . ',_' . $date . '.html';
|
||||
$document = new Document($url, true);
|
||||
$text = '';
|
||||
$text .= "Repertuar Gdyńskie Centrum Filmowe\n";
|
||||
$text .= str_replace('_', '-', $date) . "\n\n";
|
||||
|
||||
$movies = $document->find('.articles .article-item');
|
||||
foreach ($movies as $movie) {
|
||||
|
||||
$text .= $movie->find('.item-title-int')[0]->text() . "\n";
|
||||
$hours = [];
|
||||
foreach ($movie->find('.projection span') as $projection) {
|
||||
$hours[] = $projection->innerHtml();
|
||||
}
|
||||
$text .= implode(', ', array_unique($hours)) . "\n\n";
|
||||
}
|
||||
|
||||
return $text;
|
||||
}
|
||||
|
||||
}
|
||||
60
app/Http/Kernel.php
Normal file
60
app/Http/Kernel.php
Normal file
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http;
|
||||
|
||||
use Illuminate\Foundation\Http\Kernel as HttpKernel;
|
||||
|
||||
class Kernel extends HttpKernel
|
||||
{
|
||||
/**
|
||||
* The application's global HTTP middleware stack.
|
||||
*
|
||||
* These middleware are run during every request to your application.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $middleware = [
|
||||
\Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode::class,
|
||||
\Illuminate\Foundation\Http\Middleware\ValidatePostSize::class,
|
||||
\App\Http\Middleware\TrimStrings::class,
|
||||
\Illuminate\Foundation\Http\Middleware\ConvertEmptyStringsToNull::class,
|
||||
];
|
||||
|
||||
/**
|
||||
* The application's route middleware groups.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $middlewareGroups = [
|
||||
'web' => [
|
||||
\App\Http\Middleware\EncryptCookies::class,
|
||||
\Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
|
||||
\Illuminate\Session\Middleware\StartSession::class,
|
||||
// \Illuminate\Session\Middleware\AuthenticateSession::class,
|
||||
\Illuminate\View\Middleware\ShareErrorsFromSession::class,
|
||||
\App\Http\Middleware\VerifyCsrfToken::class,
|
||||
\Illuminate\Routing\Middleware\SubstituteBindings::class,
|
||||
],
|
||||
|
||||
'api' => [
|
||||
'throttle:60,1',
|
||||
'bindings',
|
||||
],
|
||||
];
|
||||
|
||||
/**
|
||||
* The application's route middleware.
|
||||
*
|
||||
* These middleware may be assigned to groups or used individually.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $routeMiddleware = [
|
||||
'auth' => \Illuminate\Auth\Middleware\Authenticate::class,
|
||||
'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class,
|
||||
'bindings' => \Illuminate\Routing\Middleware\SubstituteBindings::class,
|
||||
'can' => \Illuminate\Auth\Middleware\Authorize::class,
|
||||
'guest' => \App\Http\Middleware\RedirectIfAuthenticated::class,
|
||||
'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class,
|
||||
];
|
||||
}
|
||||
17
app/Http/Middleware/EncryptCookies.php
Normal file
17
app/Http/Middleware/EncryptCookies.php
Normal file
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Illuminate\Cookie\Middleware\EncryptCookies as BaseEncrypter;
|
||||
|
||||
class EncryptCookies extends BaseEncrypter
|
||||
{
|
||||
/**
|
||||
* The names of the cookies that should not be encrypted.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $except = [
|
||||
//
|
||||
];
|
||||
}
|
||||
26
app/Http/Middleware/RedirectIfAuthenticated.php
Normal file
26
app/Http/Middleware/RedirectIfAuthenticated.php
Normal file
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Closure;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
class RedirectIfAuthenticated
|
||||
{
|
||||
/**
|
||||
* Handle an incoming request.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param \Closure $next
|
||||
* @param string|null $guard
|
||||
* @return mixed
|
||||
*/
|
||||
public function handle($request, Closure $next, $guard = null)
|
||||
{
|
||||
if (Auth::guard($guard)->check()) {
|
||||
return redirect('/home');
|
||||
}
|
||||
|
||||
return $next($request);
|
||||
}
|
||||
}
|
||||
18
app/Http/Middleware/TrimStrings.php
Normal file
18
app/Http/Middleware/TrimStrings.php
Normal file
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Illuminate\Foundation\Http\Middleware\TrimStrings as BaseTrimmer;
|
||||
|
||||
class TrimStrings extends BaseTrimmer
|
||||
{
|
||||
/**
|
||||
* The names of the attributes that should not be trimmed.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $except = [
|
||||
'password',
|
||||
'password_confirmation',
|
||||
];
|
||||
}
|
||||
17
app/Http/Middleware/VerifyCsrfToken.php
Normal file
17
app/Http/Middleware/VerifyCsrfToken.php
Normal file
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Illuminate\Foundation\Http\Middleware\VerifyCsrfToken as BaseVerifier;
|
||||
|
||||
class VerifyCsrfToken extends BaseVerifier
|
||||
{
|
||||
/**
|
||||
* The URIs that should be excluded from CSRF verification.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $except = [
|
||||
//
|
||||
];
|
||||
}
|
||||
78
app/Paper/Airly.php
Normal file
78
app/Paper/Airly.php
Normal file
@@ -0,0 +1,78 @@
|
||||
<?php
|
||||
|
||||
namespace App\Paper;
|
||||
|
||||
|
||||
class Airly
|
||||
{
|
||||
|
||||
private $apiKey = '8b6d77b2950e4e018b0684912bf7b9ed';
|
||||
|
||||
|
||||
private $stations = ['2210', '2256', '2180'];
|
||||
private $airlyApi = 'https://airapi.airly.eu/v1';
|
||||
|
||||
|
||||
public function getStations()
|
||||
{
|
||||
return $this->stations;
|
||||
}
|
||||
|
||||
function getStationInfo($stationId)
|
||||
{
|
||||
return json_decode(file_get_contents(sprintf('%s/sensors/%d?apikey=%s', $this->airlyApi, $stationId, $this->apiKey)), 1);
|
||||
}
|
||||
|
||||
function getStationMeasurements($stationId)
|
||||
{
|
||||
return json_decode(file_get_contents(sprintf('%s/sensor/measurements?sensorId=%d&apikey=%s', $this->airlyApi, $stationId, $this->apiKey)), 1);
|
||||
}
|
||||
|
||||
public function getPollutionLevelToText($pollutionLevel)
|
||||
{
|
||||
return ["Wspaniałe powietrze! Idealny dzień na aktywność na świeżym powietrzu",
|
||||
"Dobre powietrze. Możesz bez obaw wyjść na zewnątrz i cieszyć się dniem",
|
||||
"Bywało lepiej… To nie jest najlepszy dzień na aktywność poza domem",
|
||||
"Zła jakość powietrza! Lepiej zostań dzisiaj w domu",
|
||||
"Zła jakość powietrza! Lepiej zostań dzisiaj w domu",
|
||||
"Bardzo zła jakość powietrza! Zostań dziś w domu"][$pollutionLevel - 1];
|
||||
}
|
||||
|
||||
|
||||
public function getInformationText($stationId)
|
||||
{
|
||||
$stationMeasurements = $this->getStationMeasurements($stationId);
|
||||
|
||||
if ($stationMeasurements['currentMeasurements'] === []) {
|
||||
$dataText = 'Brak aktualnych danych ze stacji';
|
||||
} else {
|
||||
$dataText = "Aktualne warunki:" . PHP_EOL;
|
||||
if (isset($stationMeasurements['currentMeasurements']['temperature'])) {
|
||||
$dataText .= "Temperatura: " . round((int)$stationMeasurements['currentMeasurements']['temperature'], 0) . "°C" . PHP_EOL;
|
||||
}
|
||||
if (isset($stationMeasurements['currentMeasurements']['pressure'])) {
|
||||
$dataText .= "Ciśnienie: " . round(((float)$stationMeasurements['currentMeasurements']['pressure'] / 100), 2) . "hPa" . PHP_EOL;
|
||||
}
|
||||
if (isset($stationMeasurements['currentMeasurements']['humidity'])) {
|
||||
$dataText .= "Wilgotność: " . round((int)$stationMeasurements['currentMeasurements']['humidity'], 2) . "%" . PHP_EOL . PHP_EOL;
|
||||
}
|
||||
if (isset($stationMeasurements['currentMeasurements']['pm1'])) {
|
||||
$dataText .= "PMI 1: " . (int)$stationMeasurements['currentMeasurements']['pm1'] . "ppm" . PHP_EOL;
|
||||
}
|
||||
if (isset($stationMeasurements['currentMeasurements']['pm25'])) {
|
||||
$dataText .= "PMI 2.5: " . (int)$stationMeasurements['currentMeasurements']['pm25'] . "ppm / " . round((int)$stationMeasurements['currentMeasurements']['pm25'] / 0.25, 0) . '%' . PHP_EOL;
|
||||
}
|
||||
if (isset($stationMeasurements['currentMeasurements']['pm10'])) {
|
||||
$dataText .= "PMI 10: " . (int)$stationMeasurements['currentMeasurements']['pm10'] . "ppm / " . round((int)$stationMeasurements['currentMeasurements']['pm10'] / 0.50, 0) . '%' . PHP_EOL;
|
||||
}
|
||||
if (isset($stationMeasurements['currentMeasurements']['airQualityIndex'])) {
|
||||
$dataText .= "Ogólna jakość powietrza: " . (int)$stationMeasurements['currentMeasurements']['airQualityIndex'] . '/100' . PHP_EOL;
|
||||
}
|
||||
if (isset($stationMeasurements['currentMeasurements']['pollutionLevel'])) {
|
||||
$dataText .= "Stopień zanieczyszczeń: " . (int)$stationMeasurements['currentMeasurements']['pollutionLevel'] . '/6' . PHP_EOL;
|
||||
$dataText .= $this->getPollutionLevelToText((int)$stationMeasurements['currentMeasurements']['pollutionLevel']);
|
||||
}
|
||||
}
|
||||
return $dataText;
|
||||
}
|
||||
}
|
||||
80
app/Paper/CinemaMultikino.php
Normal file
80
app/Paper/CinemaMultikino.php
Normal file
@@ -0,0 +1,80 @@
|
||||
<?php
|
||||
|
||||
namespace App\Paper;
|
||||
|
||||
|
||||
use App\Paper\Interfaces\Cinema;
|
||||
|
||||
class CinemaMultikino implements Cinema
|
||||
{
|
||||
|
||||
|
||||
function fetchRepertorire($day, $cinemaId = null)
|
||||
{
|
||||
$moviePath = 'https://multikino.pl/data/filmswithshowings/' . $cinemaId;
|
||||
$movieContent = file_get_contents($moviePath);
|
||||
print_r($movieContent);
|
||||
$movieJson = json_decode($movieContent, 0);
|
||||
return $movieJson;
|
||||
}
|
||||
|
||||
function parseRepertoire($day, $cinemaId = null)
|
||||
{
|
||||
$movieJson = $this->fetchRepertorire($day, $cinemaId);
|
||||
|
||||
echo $day;
|
||||
// print_r($movieJson);
|
||||
$filmy = [];
|
||||
foreach ($movieJson->films as $movie) {
|
||||
$film = [];
|
||||
$film['id'] = $movie->id;
|
||||
$film['title'] = $movie->title;
|
||||
$film['times'] = [];
|
||||
$film['date'] = $day;
|
||||
$film['runningtime'] = $movie->info_runningtime;
|
||||
$film['genres'] = [];
|
||||
$film['synopsis_short'] = str_replace(["\r\n", " "], [" "], $movie->synopsis_short);
|
||||
if ($movie->original_s_count > 0 && $movie->show_showings) {
|
||||
foreach ($movie->showings as $shoving) {
|
||||
if ($shoving->date_time == $day) {
|
||||
foreach ($shoving->times as $time) {
|
||||
$film['times'][] = $time->time . " " . $time->screen_type;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($movie->genres->names as $genre) {
|
||||
$film['genres'][] = $genre->name;
|
||||
}
|
||||
|
||||
if (count($film['times'])) {
|
||||
$filmy[] = $film;
|
||||
}
|
||||
}
|
||||
|
||||
// print_r($filmy);
|
||||
die();
|
||||
return $filmy;
|
||||
}
|
||||
|
||||
function convertToPrint($day, $cinemaId = null)
|
||||
{
|
||||
$filmy = $this->parseRepertoire($day, $cinemaId);
|
||||
|
||||
$text = '';
|
||||
$text .= "Repertuar Multikino Gdańsk\n";
|
||||
$text .= $day . "\n\n";
|
||||
|
||||
foreach ($filmy as $movie) {
|
||||
$text .= $movie['title']. "\n";
|
||||
$text .= '('.$movie['runningtime']. ")\n";
|
||||
$text .= implode(', ', $movie['genres']) . "\n\n";
|
||||
$text .= $movie['synopsis_short'] . "\n\n";
|
||||
|
||||
$text .= implode(', ', $movie['times']) . "\n";
|
||||
$text .= "--------------------------------\n\n";
|
||||
}
|
||||
return $text;
|
||||
}
|
||||
}
|
||||
21
app/Paper/HtmlToPos.php
Normal file
21
app/Paper/HtmlToPos.php
Normal file
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace App\Paper;
|
||||
|
||||
|
||||
class HtmlToPos
|
||||
{
|
||||
|
||||
|
||||
private function handleNewLine($text)
|
||||
{
|
||||
return str_replace(['<br>', '<br/>', '<br />'], "\n", $text);
|
||||
}
|
||||
|
||||
public function convert($html = '')
|
||||
{
|
||||
$posText = $this->handleNewLine($html);
|
||||
return $posText;
|
||||
}
|
||||
|
||||
}
|
||||
20
app/Paper/Interfaces/Cinema.php
Normal file
20
app/Paper/Interfaces/Cinema.php
Normal file
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace App\Paper\Interfaces;
|
||||
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: k
|
||||
* Date: 28.05.2017
|
||||
* Time: 20:14
|
||||
*/
|
||||
interface Cinema
|
||||
{
|
||||
function fetchRepertorire($day, $cinemaId = null);
|
||||
|
||||
function parseRepertoire($day, $cinemaId = null);
|
||||
|
||||
function convertToPrint($day, $cinemaId = null);
|
||||
|
||||
}
|
||||
104
app/Paper/Paper.php
Normal file
104
app/Paper/Paper.php
Normal file
@@ -0,0 +1,104 @@
|
||||
<?php
|
||||
|
||||
namespace App\Paper;
|
||||
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Mike42\Escpos\PrintConnectors\FilePrintConnector;
|
||||
use Mike42\Escpos\Printer;
|
||||
use Mike42\Escpos\EscposImage;
|
||||
use Mockery\Exception;
|
||||
|
||||
class Paper
|
||||
{
|
||||
private $imageDirectory = 'large/';
|
||||
private $imageDirectorySmall = 'small/';
|
||||
|
||||
|
||||
private $printer;
|
||||
private $connector;
|
||||
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
try {
|
||||
$this->connector = new FilePrintConnector("/dev/usb/lp0");
|
||||
$this->printer = new Printer($this->connector);
|
||||
} catch (Exception $e) {
|
||||
die($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function sendHeaderPrint($title)
|
||||
{
|
||||
if (strlen($title)) {
|
||||
$this->printer->setDoubleStrike(true);
|
||||
$this->printer->setJustification(Printer::JUSTIFY_CENTER);
|
||||
$this->printer->setEmphasis(true);
|
||||
$this->printer->text($title . "\n\n");
|
||||
$this->printer->setEmphasis(false);
|
||||
$this->printer->setJustification(Printer::JUSTIFY_LEFT);
|
||||
$this->printer->setDoubleStrike(false);
|
||||
}
|
||||
}
|
||||
|
||||
public function sendImagePrint($image, $imageLocal = true)
|
||||
{
|
||||
if ($image) {
|
||||
if ($imageLocal) {
|
||||
$img = EscposImage::load($this->imageDirectory . basename($image) . '.png');
|
||||
} else { //image not local so then remote image
|
||||
$extension = strtolower(pathinfo($image, PATHINFO_EXTENSION));
|
||||
|
||||
$tmpFile = storage_path() . '/image_packt.' . $extension;
|
||||
file_put_contents($tmpFile, file_get_contents($image));
|
||||
$img = EscposImage::load($tmpFile);
|
||||
}
|
||||
$this->printer->setJustification(Printer::JUSTIFY_CENTER);
|
||||
$this->printer->bitImageColumnFormat($img);
|
||||
$this->printer->feed(2);
|
||||
$this->printer->setJustification(Printer::JUSTIFY_LEFT);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function sendPrint($title, $text = '', $image = false, $imageLocal = true)
|
||||
{
|
||||
$this->sendImagePrint($image, $imageLocal);
|
||||
|
||||
$this->sendHeaderPrint($title);
|
||||
$htmlToPos = new HtmlToPos();
|
||||
$this->printer->text($htmlToPos->convert($text));
|
||||
|
||||
$this->printer->feed(4);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* pobieranie ikon z bazy w kolejności ilości użyć, ikon z dysku a następnie
|
||||
* usunięcie pozdbioru ikon z bazy ze wszystkich ikon a następnie dodanie
|
||||
* ich na początek listy ikon
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getIcons()
|
||||
{
|
||||
// $icons = array_diff(scandir($this->imageDirectorySmall), ['.', '..']);
|
||||
|
||||
$icons = ["address-card-o", "anchor", "archive-3", "at", "balance-scale", "ban", "bar-chart-o", "barcode", "battery-empty", "battery-full", "battery-half", "battery-quarter", "battery-three-quarters", "bed", "beer", "bell-o", "bell-slash-o", "bicycle", "birthday-cake", "bolt", "bomb", "book", "bug", "building-o", "bullhorn", "bus", "camera", "car", "chain", "chat-2", "check", "cloud", "code", "coffee", "cog", "cutlery", "dashboard", "database", "diamond", "dollar", "dribbble", "envelope-o", "envira", "exclamation-triangle", "female", "file-text-o", "film", "fingerprint", "fire-extinguisher", "fire", "flag-o", "flask", "floppy-o", "folder-o", "folder-open-o", "frown-o", "gamepad", "gift", "git", "glass", "graduation-cap", "grav", "group", "hand-o-left", "heart-o", "home", "lemon-o", "lightbulb-o", "list-alt", "location-arrow", "lock", "male", "map-1", "map-marker", "microchip", "money", "moon-o", "music", "paper-plane", "paperclip", "paw", "pencil", "phone", "pie-chart", "piggy-bank", "plane", "question-circle-o", "rocket", "search", "ship", "shopping-cart", "smile-o", "snowflake-o", "steam", "subway", "success", "support", "thermometer-2", "thumbs-o-down", "thumbs-o-up", "ticket", "times", "trash-o", "tree", "trophy", "truck", "umbrella", "usd", "warning", "wifi", "wpexplorer", "wrench", "youtube-play"];
|
||||
|
||||
|
||||
$iconsDatabase = [];
|
||||
$iconsDb = DB::select('SELECT icon FROM note WHERE icon is not null group by icon ORDER BY count(icon) DESC ');
|
||||
foreach ($iconsDb as $icon) {
|
||||
$iconsDatabase[] = pathinfo(basename($icon->icon), PATHINFO_FILENAME);
|
||||
}
|
||||
return (array_merge($iconsDatabase, array_diff($icons, $iconsDatabase)));
|
||||
}
|
||||
|
||||
public function __destruct()
|
||||
{
|
||||
$this->printer->close();
|
||||
}
|
||||
|
||||
}
|
||||
28
app/Providers/AppServiceProvider.php
Normal file
28
app/Providers/AppServiceProvider.php
Normal file
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace App\Providers;
|
||||
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
|
||||
class AppServiceProvider extends ServiceProvider
|
||||
{
|
||||
/**
|
||||
* Bootstrap any application services.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function boot()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Register any application services.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function register()
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
||||
30
app/Providers/AuthServiceProvider.php
Normal file
30
app/Providers/AuthServiceProvider.php
Normal file
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace App\Providers;
|
||||
|
||||
use Illuminate\Support\Facades\Gate;
|
||||
use Illuminate\Foundation\Support\Providers\AuthServiceProvider as ServiceProvider;
|
||||
|
||||
class AuthServiceProvider extends ServiceProvider
|
||||
{
|
||||
/**
|
||||
* The policy mappings for the application.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $policies = [
|
||||
'App\Model' => 'App\Policies\ModelPolicy',
|
||||
];
|
||||
|
||||
/**
|
||||
* Register any authentication / authorization services.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function boot()
|
||||
{
|
||||
$this->registerPolicies();
|
||||
|
||||
//
|
||||
}
|
||||
}
|
||||
21
app/Providers/BroadcastServiceProvider.php
Normal file
21
app/Providers/BroadcastServiceProvider.php
Normal file
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace App\Providers;
|
||||
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
use Illuminate\Support\Facades\Broadcast;
|
||||
|
||||
class BroadcastServiceProvider extends ServiceProvider
|
||||
{
|
||||
/**
|
||||
* Bootstrap any application services.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function boot()
|
||||
{
|
||||
Broadcast::routes();
|
||||
|
||||
require base_path('routes/channels.php');
|
||||
}
|
||||
}
|
||||
32
app/Providers/EventServiceProvider.php
Normal file
32
app/Providers/EventServiceProvider.php
Normal file
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace App\Providers;
|
||||
|
||||
use Illuminate\Support\Facades\Event;
|
||||
use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider;
|
||||
|
||||
class EventServiceProvider extends ServiceProvider
|
||||
{
|
||||
/**
|
||||
* The event listener mappings for the application.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $listen = [
|
||||
'App\Events\SomeEvent' => [
|
||||
'App\Listeners\EventListener',
|
||||
],
|
||||
];
|
||||
|
||||
/**
|
||||
* Register any events for your application.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function boot()
|
||||
{
|
||||
parent::boot();
|
||||
|
||||
//
|
||||
}
|
||||
}
|
||||
73
app/Providers/RouteServiceProvider.php
Normal file
73
app/Providers/RouteServiceProvider.php
Normal file
@@ -0,0 +1,73 @@
|
||||
<?php
|
||||
|
||||
namespace App\Providers;
|
||||
|
||||
use Illuminate\Support\Facades\Route;
|
||||
use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider;
|
||||
|
||||
class RouteServiceProvider extends ServiceProvider
|
||||
{
|
||||
/**
|
||||
* This namespace is applied to your controller routes.
|
||||
*
|
||||
* In addition, it is set as the URL generator's root namespace.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $namespace = 'App\Http\Controllers';
|
||||
|
||||
/**
|
||||
* Define your route model bindings, pattern filters, etc.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function boot()
|
||||
{
|
||||
//
|
||||
|
||||
parent::boot();
|
||||
}
|
||||
|
||||
/**
|
||||
* Define the routes for the application.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function map()
|
||||
{
|
||||
$this->mapApiRoutes();
|
||||
|
||||
$this->mapWebRoutes();
|
||||
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Define the "web" routes for the application.
|
||||
*
|
||||
* These routes all receive session state, CSRF protection, etc.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function mapWebRoutes()
|
||||
{
|
||||
Route::middleware('web')
|
||||
->namespace($this->namespace)
|
||||
->group(base_path('routes/web.php'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Define the "api" routes for the application.
|
||||
*
|
||||
* These routes are typically stateless.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function mapApiRoutes()
|
||||
{
|
||||
Route::prefix('api')
|
||||
->middleware('api')
|
||||
->namespace($this->namespace)
|
||||
->group(base_path('routes/api.php'));
|
||||
}
|
||||
}
|
||||
29
app/User.php
Normal file
29
app/User.php
Normal file
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace App;
|
||||
|
||||
use Illuminate\Notifications\Notifiable;
|
||||
use Illuminate\Foundation\Auth\User as Authenticatable;
|
||||
|
||||
class User extends Authenticatable
|
||||
{
|
||||
use Notifiable;
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $fillable = [
|
||||
'name', 'email', 'password',
|
||||
];
|
||||
|
||||
/**
|
||||
* The attributes that should be hidden for arrays.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $hidden = [
|
||||
'password', 'remember_token',
|
||||
];
|
||||
}
|
||||
Reference in New Issue
Block a user