Merged older paper pi with the newer, with some recent updates.

This commit is contained in:
kplaczek
2018-04-02 22:34:15 +02:00
parent 3c0ebd26ed
commit ad53e0c861
19 changed files with 1071 additions and 160 deletions

23
.gitignore vendored
View File

@@ -7,26 +7,3 @@
Homestead.json
Homestead.yaml
.env
# ---> Laravel
vendor/
node_modules/
npm-debug.log
# Laravel 4 specific
bootstrap/compiled.php
app/storage/
# Laravel 5 & Lumen specific
public/storage
public/hot
storage/*.key
.env.*.php
.env.php
.env
Homestead.yaml
Homestead.json
# Rocketeer PHP task runner and deployment package. https://github.com/rocketeers/rocketeer
.rocketeer/

3
.htaccess Normal file
View File

@@ -0,0 +1,3 @@
<FilesMatch "\.(ico|pdf|jpg|jpeg|png|gif|html|htm|xml|txt|xsl)$">
Header set Cache-Control "max-age=31536050"
</FilesMatch>

View File

@@ -1,4 +1,40 @@
# paper-pi
<p align="center"><img src="https://laravel.com/assets/img/components/logo-laravel.svg"></p>
Webowa aplikacja napisana w PHP pozwalająca na drukowanie za pomocąpodłączonej do raspberry pi drukarki termicznej i zarządzanie zapisanymi wydrukami.
<p align="center">
<a href="https://travis-ci.org/laravel/framework"><img src="https://travis-ci.org/laravel/framework.svg" alt="Build Status"></a>
<a href="https://packagist.org/packages/laravel/framework"><img src="https://poser.pugx.org/laravel/framework/d/total.svg" alt="Total Downloads"></a>
<a href="https://packagist.org/packages/laravel/framework"><img src="https://poser.pugx.org/laravel/framework/v/stable.svg" alt="Latest Stable Version"></a>
<a href="https://packagist.org/packages/laravel/framework"><img src="https://poser.pugx.org/laravel/framework/license.svg" alt="License"></a>
</p>
## About Laravel
Laravel is a web application framework with expressive, elegant syntax. We believe development must be an enjoyable, creative experience to be truly fulfilling. Laravel attempts to take the pain out of development by easing common tasks used in the majority of web projects, such as:
- [Simple, fast routing engine](https://laravel.com/docs/routing).
- [Powerful dependency injection container](https://laravel.com/docs/container).
- Multiple back-ends for [session](https://laravel.com/docs/session) and [cache](https://laravel.com/docs/cache) storage.
- Expressive, intuitive [database ORM](https://laravel.com/docs/eloquent).
- Database agnostic [schema migrations](https://laravel.com/docs/migrations).
- [Robust background job processing](https://laravel.com/docs/queues).
- [Real-time event broadcasting](https://laravel.com/docs/broadcasting).
Laravel is accessible, yet powerful, providing tools needed for large, robust applications. A superb combination of simplicity, elegance, and innovation give you tools you need to build any application with which you are tasked.
## Learning Laravel
Laravel has the most extensive and thorough documentation and video tutorial library of any modern web application framework. The [Laravel documentation](https://laravel.com/docs) is thorough, complete, and makes it a breeze to get started learning the framework.
If you're not in the mood to read, [Laracasts](https://laracasts.com) contains over 900 video tutorials on a range of topics including Laravel, modern PHP, unit testing, JavaScript, and more. Boost the skill level of yourself and your entire team by digging into our comprehensive video library.
## Contributing
Thank you for considering contributing to the Laravel framework! The contribution guide can be found in the [Laravel documentation](http://laravel.com/docs/contributions).
## Security Vulnerabilities
If you discover a security vulnerability within Laravel, please send an e-mail to Taylor Otwell at taylor@laravel.com. All security vulnerabilities will be promptly addressed.
## License
The Laravel framework is open-sourced software licensed under the [MIT license](http://opensource.org/licenses/MIT).

View 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);
}
}
}

View 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);
}
}

View File

@@ -7,8 +7,10 @@
*/
namespace App\Http\Controllers;
set_time_limit(-1);
use App\Paper\HtmlToPos;
use App\Paper\Airly;
use App\Paper\Paper;
use Illuminate\Support\Facades\DB;
use Mike42\Escpos\PrintConnectors\FilePrintConnector;
use Mike42\Escpos\Printer;
@@ -19,6 +21,20 @@ 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)
{
@@ -103,89 +119,130 @@ class Main extends Controller
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 ORDER BY updated_at DESC');
$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')
'text' => $request->old('text'),
'icon_selected' => $request->old('icon'),
'icons' => $this->paper->getIcons()
]);
}
public function form(Request $request)
/**
* get:/airly
* @param Request $request
* @return \Illuminate\Http\RedirectResponse
*/
public function airly(Request $request)
{
return view('create', [
'title' => $request->old('title'),
'text' => $request->old('text')
]);
$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->sendPrint($note->topic, $note->text);
$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')) {
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->sendPrint($request->input('title'), $request->input('text'));
$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,
]);
}
}
public function sendPrint($title, $text)
{
$connector = new FilePrintConnector("/dev/usb/lp0");
$printer = new Printer($connector);
// $printer->setFont(Printer::FONT_B);
if (strlen($title)) {
$printer->setDoubleStrike(true);
$printer->setJustification(Printer::JUSTIFY_CENTER);
$printer->setEmphasis(true);
$printer->text($title . "\n\n");
$printer->setEmphasis(false);
$printer->setJustification(Printer::JUSTIFY_LEFT);
$printer->setDoubleStrike(false);
}
$htmlToPos = new HtmlToPos();
$printer->text($htmlToPos->convert($text));
$printer->feed(4);
$printer->close();
}
/**
* post::/
* @param Request $request
* @return $this|\Illuminate\Http\RedirectResponse
*/
public function main(Request $request)
{
if ($request->exists('save')) {
@@ -194,13 +251,28 @@ class Main extends Controller
'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->sendPrint($request->input('title'), $request->input('text'));
$this->paper->sendPrint($request->input('title'), $request->input('text'), $request->input('icon'));
return back()->withInput();
}

View 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;
}
}

View File

@@ -2,18 +2,19 @@
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Paper\CinemaMultikino;
use DiDom\Document;
use App\Paper;
use App\Paper\Paper;
class Repertoire extends Controller
{
private $main;
private $icon = '/small/film.png';
public function __construct()
{
$this->main = new Main();
$this->main = new Paper();
}
@@ -21,7 +22,7 @@ class Repertoire extends Controller
{
$date = date('d/m/Y');
$repertuarText = $this->cinemacityRepertuar($date);
$this->main->sendPrint('', $repertuarText);
$this->main->sendPrint('', $repertuarText, $this->icon, $this->icon);
return back();
}
@@ -31,7 +32,7 @@ class Repertoire extends Controller
$date = new \DateTime();
$date->modify('+1 day');
$repertuarText = $this->cinemacityRepertuar($date->format('d/m/Y'));
$this->main->sendPrint('', $repertuarText);
$this->main->sendPrint('', $repertuarText, $this->icon, $this->icon);
return back();
}
@@ -81,9 +82,10 @@ class Repertoire extends Controller
public function today_multikino()
{
$multikino = new Paper\CinemaMultikino();
$multikino = new CinemaMultikino();
$repertuarText = $multikino->convertToPrint(date('Y-m-d'), 4);
$this->main->sendPrint('', $repertuarText);
$this->main->sendPrint('', $repertuarText, $this->icon);
return back();
}
@@ -92,13 +94,12 @@ class Repertoire extends Controller
$date = new \DateTime();
$date->modify('+1 day');
$multikino = new Paper\CinemaMultikino();
$multikino = new CinemaMultikino();
$repertuarText = $multikino->convertToPrint($date->format('Y-m-d'), 4);
$this->main->sendPrint('', $repertuarText);
$this->main->sendPrint('', $repertuarText, $this->icon);
return back();
// $repertuarText = $this->multikinoRepertuar($date->format('Y-m-d'));
// $this->main->sendPrint('', $repertuarText);
// return back();
@@ -111,7 +112,7 @@ class Repertoire extends Controller
$date->modify('+1 day');
$repertuarText = $this->gdynskieCentrumFilmowe($date->format('d_m_Y'));
$this->main->sendPrint('', $repertuarText);
$this->main->sendPrint('', $repertuarText, $this->icon);
return back();
}
@@ -119,20 +120,20 @@ class Repertoire extends Controller
{
$date = date('d_m_Y');
$repertuarText = $this->gdynskieCentrumFilmowe($date);
$this->main->sendPrint('', $repertuarText);
$this->main->sendPrint('', $repertuarText, $this->icon);
return back();
}
public function today_helios()
{
$this->main->sendPrint('', $this->helios(0, 2));
$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->main->sendPrint('', $this->helios(1, 2), $this->icon);
$this->main->sendPrint('', $this->helios(1, 49));
return back();
}

78
app/Paper/Airly.php Normal file
View 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;
}
}

View File

@@ -13,6 +13,7 @@ class CinemaMultikino implements Cinema
{
$moviePath = 'https://multikino.pl/data/filmswithshowings/' . $cinemaId;
$movieContent = file_get_contents($moviePath);
print_r($movieContent);
$movieJson = json_decode($movieContent, 0);
return $movieJson;
}
@@ -21,6 +22,8 @@ class CinemaMultikino implements Cinema
{
$movieJson = $this->fetchRepertorire($day, $cinemaId);
echo $day;
// print_r($movieJson);
$filmy = [];
foreach ($movieJson->films as $movie) {
$film = [];
@@ -49,6 +52,9 @@ class CinemaMultikino implements Cinema
$filmy[] = $film;
}
}
// print_r($filmy);
die();
return $filmy;
}

View File

@@ -12,17 +12,10 @@ class HtmlToPos
return str_replace(['<br>', '<br/>', '<br />'], "\n", $text);
}
public function convert($html)
public function convert($html = '')
{
$posText = $this->handleNewLine($html);
// print_r($posText);
// die();
return $posText;
}
}

105
app/Paper/Paper.php Normal file
View File

@@ -0,0 +1,105 @@
<?php
namespace App\Paper;
use Illuminate\Support\Facades\DB;
use Mike42\Escpos\PrintConnectors\FilePrintConnector;
use Mike42\Escpos\Printer;
use App\Paper\HtmlToPos;
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();
}
}

389
public/css/app.css vendored
View File

@@ -1,7 +1,15 @@
textarea { font-family: monospace }
textarea.content { font-family: monospace; word-wrap: break-word; word-break: break-all; }
#editor {
border: 1px solid rgba(34,36,38,.15);
textarea {
font-family: monospace
}
textarea.content {
font-family: monospace;
word-wrap: break-word;
word-break: break-all;
}
#editor {
border: 1px solid rgba(34, 36, 38, .15);
padding: 15px;
font-family: monospace;
word-wrap: break-word;
@@ -10,10 +18,379 @@ textarea.content { font-family: monospace; word-wrap: break-word; word-break: b
white-space: pre-wrap;
box-sizing: content-box;
}
}
form {margin-bottom: 0;}
form {
margin-bottom: 0;
}
.ui.file.input input[type="file"] {
display: none;
}
.icon {
cursor: pointer;
height: 25px;
width: 25px;
display: inline-block;
background: url(/small/iconsmall.png);
margin: 2px;
}
.icon:hover {
background-color: #1e90ff4d;
}
.icon.empty {
height: 25px;
width: 25px;
background-image: none;
}
.icon.selected {
border: 2px solid dodgerblue;
border-radius: 3px;
background-color: #1e90ff4d;
width: 29px;
height: 29px;
margin: 0;
}
.icon.address-card-o {
background-position-x: -0px;
}
.icon.anchor {
background-position-x: -25px;
}
.icon.archive-3 {
background-position-x: -50px;
}
.icon.at {
background-position-x: -75px;
}
.icon.balance-scale {
background-position-x: -100px;
}
.icon.ban {
background-position-x: -125px;
}
.icon.bar-chart-o {
background-position-x: -150px;
}
.icon.barcode {
background-position-x: -175px;
}
.icon.battery-empty {
background-position-x: -200px;
}
.icon.battery-full {
background-position-x: -225px;
}
.icon.battery-half {
background-position-x: -250px;
}
.icon.battery-quarter {
background-position-x: -275px;
}
.icon.battery-three-quarters {
background-position-x: -300px;
}
.icon.bed {
background-position-x: -325px;
}
.icon.beer {
background-position-x: -350px;
}
.icon.bell-o {
background-position-x: -375px;
}
.icon.bell-slash-o {
background-position-x: -400px;
}
.icon.bicycle {
background-position-x: -425px;
}
.icon.birthday-cake {
background-position-x: -450px;
}
.icon.bolt {
background-position-x: -475px;
}
.icon.bomb {
background-position-x: -500px;
}
.icon.book {
background-position-x: -525px;
}
.icon.bug {
background-position-x: -550px;
}
.icon.building-o {
background-position-x: -575px;
}
.icon.bullhorn {
background-position-x: -600px;
}
.icon.bus {
background-position-x: -625px;
}
.icon.camera {
background-position-x: -650px;
}
.icon.car {
background-position-x: -675px;
}
.icon.chain {
background-position-x: -700px;
}
.icon.chat-2 {
background-position-x: -725px;
}
.icon.check {
background-position-x: -750px;
}
.icon.cloud {
background-position-x: -775px;
}
.icon.code {
background-position-x: -800px;
}
.icon.coffee {
background-position-x: -825px;
}
.icon.cog {
background-position-x: -850px;
}
.icon.cutlery {
background-position-x: -875px;
}
.icon.dashboard {
background-position-x: -900px;
}
.icon.database {
background-position-x: -925px;
}
.icon.diamond {
background-position-x: -950px;
}
.icon.dollar {
background-position-x: -975px;
}
.icon.dribbble {
background-position-x: -1000px;
}
.icon.envelope-o {
background-position-x: -1025px;
}
.icon.envira {
background-position-x: -1050px;
}
.icon.exclamation-triangle {
background-position-x: -1075px;
}
.icon.female {
background-position-x: -1100px;
}
.icon.file-text-o {
background-position-x: -1125px;
}
.icon.film {
background-position-x: -1150px;
}
.icon.fingerprint {
background-position-x: -1175px;
}
.icon.fire-extinguisher {
background-position-x: -1200px;
}
.icon.fire {
background-position-x: -1225px;
}
.icon.flag-o {
background-position-x: -1250px;
}
.icon.flask {
background-position-x: -1275px;
}
.icon.floppy-o {
background-position-x: -1300px;
}
.icon.folder-o {
background-position-x: -1325px;
}
.icon.folder-open-o {
background-position-x: -1350px;
}
.icon.frown-o {
background-position-x: -1375px;
}
.icon.gamepad {
background-position-x: -1400px;
}
.icon.gift {
background-position-x: -1425px;
}
.icon.git {
background-position-x: -1450px;
}
.icon.glass {
background-position-x: -1475px;
}
.icon.graduation-cap {
background-position-x: -1500px;
}
.icon.grav {
background-position-x: -1525px;
}
.icon.group {
background-position-x: -1550px;
}
.icon.hand-o-left {
background-position-x: -1575px;
}
.icon.heart-o {
background-position-x: -1600px;
}
.icon.home {
background-position-x: -1625px;
}
.icon.lemon-o {
background-position-x: -1650px;
}
.icon.lightbulb-o {
background-position-x: -1675px;
}
.icon.list-alt {
background-position-x: -1700px;
}
.icon.location-arrow {
background-position-x: -1725px;
}
.icon.lock {
background-position-x: -1750px;
}
.icon.male {
background-position-x: -1775px;
}
.icon.map-1 {
background-position-x: -1800px;
}
.icon.map-marker {
background-position-x: -1825px;
}
.icon.microchip {
background-position-x: -1850px;
}
.icon.money {
background-position-x: -1875px;
}
.icon.moon-o {
background-position-x: -1900px;
}
.icon.music {
background-position-x: -1925px;
}
.icon.paper-plane {
background-position-x: -1950px;
}
.icon.paperclip {
background-position-x: -1975px;
}
.icon.paw {
background-position-x: -2000px;
}
.icon.pencil {
background-position-x: -2025px;
}
.icon.phone {
background-position-x: -2050px;
}
.icon.pie-chart {
background-position-x: -2075px;
}
.icon.piggy-bank {
background-position-x: -2100px;
}
.icon.plane {
background-position-x: -2125px;
}
.icon.question-circle-o {
background-position-x: -2150px;
}
.icon.rocket {
background-position-x: -2175px;
}
.icon.search {
background-position-x: -2200px;
}
.icon.ship {
background-position-x: -2225px;
}
.icon.shopping-cart {
background-position-x: -2250px;
}
.icon.smile-o {
background-position-x: -2275px;
}
.icon.snowflake-o {
background-position-x: -2300px;
}
.icon.steam {
background-position-x: -2325px;
}
.icon.subway {
background-position-x: -2350px;
}
.icon.success {
background-position-x: -2375px;
}
.icon.support {
background-position-x: -2400px;
}
.icon.thermometer-2 {
background-position-x: -2425px;
}
.icon.thumbs-o-down {
background-position-x: -2450px;
}
.icon.thumbs-o-up {
background-position-x: -2475px;
}
.icon.ticket {
background-position-x: -2500px;
}
.icon.times {
background-position-x: -2525px;
}
.icon.trash-o {
background-position-x: -2550px;
}
.icon.tree {
background-position-x: -2575px;
}
.icon.trophy {
background-position-x: -2600px;
}
.icon.truck {
background-position-x: -2625px;
}
.icon.umbrella {
background-position-x: -2650px;
}
.icon.usd {
background-position-x: -2675px;
}
.icon.warning {
background-position-x: -2700px;
}
.icon.wifi {
background-position-x: -2725px;
}
.icon.wpexplorer {
background-position-x: -2750px;
}
.icon.wrench {
background-position-x: -2775px;
}
.icon.youtube-play {
background-position-x: -2800px;
}

View File

@@ -8,41 +8,63 @@ var Printer = function () {
this.delete = document.querySelector('.js-delete');
content = this.content = document.querySelector('.js-content');
preview = this.preview = document.querySelector('#editor');
// preview = this.preview = document.querySelector('#editor');
selfPrinter = this;
this.reset.addEventListener('click', this.clear);
this.content.addEventListener('keypress', this.printPreview);
this.preview.addEventListener('keyup', this.divToTextbox);
// this.content.addEventListener('keypress', this.printPreview);
// this.preview.addEventListener('keyup', this.divToTextbox);
content.addEventListener("mouseup", this.contentResize);
if(this.delete != null){
this.restoreContentHeight();
if (this.delete != null) {
this.delete.addEventListener('click', this.confirmDelete);
}
this.commandCenter = document.querySelector('.icon.command.center');
this.commandLeft = document.querySelector('.icon.command.left');
this.commandRight = document.querySelector('.icon.command.right');
this.commandBold = document.querySelector('.icon.command.bold');
this.commandItalic = document.querySelector('.icon.command.italic');
this.commandUnderline = document.querySelector('.icon.command.underline');
this.commandCenter.addEventListener('click', function(){document.execCommand('justifyCenter', false);});
this.commandLeft.addEventListener('click', function(){document.execCommand('justifyLeft', false);});
this.commandRight.addEventListener('click', function(){document.execCommand('justifyRight', false);});
document.querySelectorAll('.icon').forEach(function (e) {
e.addEventListener('click', function () {
document.querySelectorAll('.icon').forEach(function (e, i) {
e.classList.remove('selected');
});
document.querySelector('#icon').value = this.title;
this.classList.add('selected');
});
})
this.commandBold.addEventListener('click', function(){document.execCommand('bold', false);});
this.commandItalic.addEventListener('click', function(){document.execCommand('italic', false);});
this.commandUnderline.addEventListener('click', function(){document.execCommand('underline', false);});
// this.commandCenter = document.querySelector('.icon.command.center');
// this.commandLeft = document.querySelector('.icon.command.left');
// this.commandRight = document.querySelector('.icon.command.right');
// this.commandBold = document.querySelector('.icon.command.bold');
// this.commandItalic = document.querySelector('.icon.command.italic');
// this.commandUnderline = document.querySelector('.icon.command.underline');
// this.commandCenter.addEventListener('click', function(){document.execCommand('justifyCenter', false);});
// this.commandLeft.addEventListener('click', function(){document.execCommand('justifyLeft', false);});
// this.commandRight.addEventListener('click', function(){document.execCommand('justifyRight', false);});
// this.commandBold.addEventListener('click', function(){document.execCommand('bold', false);});
// this.commandItalic.addEventListener('click', function(){document.execCommand('italic', false);});
// this.commandUnderline.addEventListener('click', function(){document.execCommand('underline', false);});
};
this.printPreview = function(){
preview.innerText = content.value;
// this.printPreview = function(){
// preview.innerText = content.value;
// };
this.restoreContentHeight = function () {
if(!!localStorage.getItem('contentHeight')){
document.querySelector('.js-content').style.height = localStorage.getItem('contentHeight')
}
};
this.divToTextbox = function(){
this.contentResize = function () {
localStorage.setItem('contentHeight', this.style.height);
};
this.divToTextbox = function () {
content.value = preview.innerHTML;
};
@@ -51,7 +73,7 @@ var Printer = function () {
};
this.confirmDelete = function (e) {
if(!confirm('Usunąć wpis?')){
if (!confirm('Usunąć wpis?')) {
e.preventDefault();
return false;
}

View File

@@ -8,7 +8,11 @@
<div class="ui container">
<div class="ui one column middle aligned stackable grid">
<div class="ui column">
@if($type == 'template')
<h2><a href="/">Lista</a> &raquo; Edycja szablonu</h2>
@else
<h2><a href="/">Lista</a> &raquo; Edycja notatki</h2>
@endif
@include('form.create')
<br><br>
</div>

View File

@@ -8,22 +8,38 @@
<div class="field">
<label>Treść</label>
{{--width: 284px; height: 400px;--}}
<textarea class="js-content content"
name="text">{{ $text }}</textarea>
<i class="align left icon command" title="left"></i>
<i class="align center icon command" title="center"></i>
<i class="align right icon command" title="right"></i>
<i class="bold icon command" title="bold"></i>
<i class="italic icon command" title="italic"></i>
<i class="underline icon command" title="underline"></i>
<div id="editor" contenteditable="true" id="editor">{{ $text }}</div>
<input type="hidden" name="icon" id="icon" value="{{ $icon_selected }}"/>
<div class="icons">
<span class="icon @if(!isset($icon_selected) ) selected @endif empty" title="empty"></span>
@foreach ($icons as $icon)<span
class="icon {{ str_before($icon, '.') }} @if(isset($icon_selected) && $icon == basename($icon_selected)) selected @endif " title="{{ $icon }}">
</span>@endforeach
</div>
</div>
@if(isset($type) && $type == 'template')
<button class="ui submit button yellow" type="submit" name="save">Zapisz jako notatkę</button>
<button class="ui submit button orange" type="submit" name="save_template">Zapisz szablon</button>
@else
<button class="ui submit button yellow" type="submit" name="save">Zapisz</button>
<button class="ui submit button orange" type="submit" name="save_template">Zapisz jako szablon</button>
@endif
<button class="ui submit button primary" type="submit" name="print">Drukuj</button>
<button class="ui reset button js-reset" type="reset">Wyczyść</button>
@if(isset($id))
<button class="ui delete button js-delete red" type="submit" name="delete">Usuń</button>
@endif
</form>

View File

@@ -17,13 +17,16 @@
<div class="field">
<label for="photo">Plik do wydrukowania:</label>
<div class="ui fluid file input action">
<input type="text" class="url" name="url" placeholder="Wklej link do zdjęcia, albo wybierz plik z dysku obok">
<input type="text" class="url" name="url"
placeholder="Wklej link do zdjęcia, albo wybierz plik z dysku obok">
<input type="text" readonly>
<input type="file" id="photo" name="photo" autocomplete="off" accept=".jpg,.png,.gif,.jpeg,.bmp">
<input type="file" id="photo" name="photo" autocomplete="off"
accept=".jpg,.png,.gif,.jpeg,.bmp">
<div class="ui button trigger">
Wybierz plik...
</div>
<button class="ui submit button primary" type="submit" name="print-image">Drukuj</button>
<button class="ui submit button primary" type="submit" name="print-image">Drukuj
</button>
</div>
</div>
</form>
@@ -32,15 +35,11 @@
</div>
</div>
<div class="ui container">
<h1 class="ui header">Lista notatek</h1>
<div class="ui middle aligned divided list">
@foreach($notes as $note)
<div class="item">
<div class="right floated content">
<form method="post" action="/print/{{ $note->id }}">
@@ -49,13 +48,26 @@
</form>
</div>
<div class="content">
<a href="/edit/{{ $note->id }}/{{ $note->topic_slug?$note->topic_slug:str_limit($note->text, 30, '...') }}"> {{ $note->topic?$note->topic:str_limit($note->text, 30, '...') }} </a>
<a href="/edit/{{ $note->id }}/{{ $note->topic_slug?$note->topic_slug:str_limit($note->text, 30, '...') }}"><span
class="icon {{ $note->icon }} "
title="{{ $note->icon }}"></span>{{ $note->topic?$note->topic:str_limit($note->text, 30, '...') }}
</a>
</div>
</div>
@endforeach
</div>
<h1 class="ui header">Szablony notatek</h1>
<div class="ui middle aligned divided list">
@foreach($templates as $template)
<div class="item">
<div class="content">
<a href="/edit/{{ $template->id }}/{{ $template->topic_slug?$template->topic_slug:str_limit($template->text, 30, '...') }}"><span
class="icon {{ $template->icon }} "
title="{{ $template->icon }}"></span> {{ $template->topic?$template->topic:str_limit($template->text, 30, '...') }}
</a>
</div>
</div>
@endforeach
</div>
<div class="ui teal tiny buttons">
@@ -83,6 +95,9 @@
</div>
</div>
</div>
<div class="ui teal tiny buttons pointing top left">
<a class="ui button" href="/airly">Airly</a>
</div>
</div>

View File

@@ -0,0 +1,19 @@
@extends('layouts.base')
@section('content')
<style>
body .column .ui.form textarea:not([rows]) {max-height: inherit; height: 20em}
</style>
<div class="ui container">
<div class="ui one column middle aligned stackable grid">
<div class="ui column">
<h2><a href="/">Lista</a> &raquo; Edycja notatki</h2>
@include('form.create')
<br><br>
</div>
</div>
</div>
@endsection

View File

@@ -12,13 +12,20 @@
*/
Route::get('/', 'Main@listView')->name('list');
Route::post('/', 'Main@listView');
Route::get('/new', 'Main@form')->name('form');
//Route::post('/', 'Main@listView');
Route::get('/edit/{id}/{slug}', 'Main@edit')->name('edit');
Route::post('/print/{id}/', 'Main@printText')->name('print');
Route::post('/edit/{id}/{slug}', 'Main@edit');
Route::post('/printImage', 'Main@imagePrint');
Route::post('/', 'Main@main');
Route::get('/airly', 'Main@airly');
Route::get('/multikino/today', 'Repertoire@today_multikino');
Route::get('/multikino/tomorrow', 'Repertoire@tomorrow_multikino');
@@ -37,6 +44,8 @@ Route::get('/helios/tomorrow', 'Repertoire@tomorrow_helios');
Route::get('/repertoire/today', 'Repertoire@today_repertoire');
Route::get('/repertoire/tomorrow', 'Repertoire@tomorrow_repertoire');
Route::post('/printImage', 'Main@imagePrint');
Route::post('/', 'Main@main');
Route::get('/packtpub/today', 'PacktPub@today');
Route::get('/keyboard/{key}', 'Keyboard@press');
Route::get('/closedshops/tomorrow', 'ClosedShops@tomorrow');