<!DOCTYPE html>
<html>
<head>
<script src="https://cloud.tinymce.com/stable/tinymce.min.js"></script>
<script>tinymce.init({ selector:'textarea' });</script>
</head>
<body>
<textarea>Pole edytora</textarea>
</body>
</html>
Autor: jornathan
cake pdf szablony
Templates/Layout/pdf/default.ctp
countdown plugin
<html>
<head>
<link rel="stylesheet" href="/css/flipclock.css">
</head>
<body>
<div class="your-clock"></div>
<script src="/js/libs/jquery.js"></script>
<script src="/js/flipclock/flipclock.min.js"></script>
</body>
</html>
var clock = $('.your-clock').FlipClock({
// ... your options here
});
updateAll – expression
Aktualizuje wiele rekordów
function publishAllUnpublished()
{
$this->updateAll(
[ // fields
'published' => true,
'publish_date' => FrozenTime::now()
],
[ // conditions
'published' => false
]
);
}
.htaccess – mapowanie adresów
# Wymuszanie https:
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RichFilemanager
Instalacja cake
# php composer.phar create-project --prefer-dist cakephp/app media77
debug
echo "<pre>". print_r($query, 1) ."</pre>"; exit;
Zmiana bazy danych
class ArticlesTable extends Table
{
public static function defaultConnectionName() {
return 'replica_db' ;
}
}
iptables.sh
#!/bin/sh IPTABLES=/sbin/iptables MODEPROBE=/sbin/modprobe INT_NET=10.1.0.0/16 INT_IN=eno2 INT_OUT=eno1
Virtual host + certyfikat + SSL
Utworzenie wirtualnego hosta /etc/apache2/sites-available/000-default.conf
<VirtualHost 81.137.4.24:80> ServerAdmin webmaster@localhost DocumentRoot /var/www/html/example ServerName example.pl </VirtualHost>
LetsEncrypt – rozszerzenie domeny
Można dodać/usunąć domenę do certyfikatu już istniejącego np. o nazwie example.com:
# certbot certonly --cert-name example.com -d example.org,www.example.org
Nowy certyfikat będzie zawierał teraz dwie nazwy example.org oraz www.example.org
Instalacja php 7.2
# apt install ca-certificates apt-transport-https
LetsEncrypt – webroot
https://certbot.eff.org/docs/using.html
# certbot certonly --webroot -w /var/www/rewita/webroot -d tmp.rewita.pl -d crm.rewita.pl
Odnowienie certyfikatu
Odnowienie co 60 dni poprzez moduł wykorzystujący crona
Odnawia wszystkie certyfikaty, które zbliżają się do wygaśnięcia <= 30 dni do końca. Komendę można wydawać codziennie lub raz na tydzień, można dodać do crona.
# certbot renew
Tylko sprawdza działania –dry-run
# certbot renew --dry-run
Zmiana długości klucza z 2048 na 4096
# certbot renew --rsa-key-size 4096
Certyfikaty wildcard
DNS plugin musi być zainstalowany dla dostawcy dns
# certbot -a <dns-plugin> -i apache -d "*.example.com" -d example.com --server https://acme-v02.api.letsencrypt.org/directory
Ręczna konfiguracja certyfikatów
Ręczna konfiguracja certyfikatów:
# certbot certonly --authenticator standalone
Przed zainstalowaniem trzeba zatrzymać serwer ręcznie lub za pomocą skryptów:
# certbot certonly --authenticator standalone --pre-hook "apache2ctl -k stop" --post-hook "apache2ctl -k start"
Certbot
https://certbot.eff.org/lets-encrypt/debianstretch-apache
# apt-get install python-certbot-apache -t stretch-backports
# certbot --authenticator webroot --installer apache
cakePHP – logowanie autoryzacji
app.php w sekcji Log => [
'auth' => [ 'className' => 'Cake\Log\Engine\FileLog', 'path' => LOGS, 'file' => 'auth', 'url' => env('LOG_AUTH_URL', null), 'scopes' => ['auth'], ],
Przedłużenie sesji PHP
.htaccess – 14 dni czas sesji
php_value session.gc_maxlifetime 1209600
reachFileManager plugin
https://github.com/servocoder/RichFilemanager/wiki/Configuration-options
Instalacja projektu w katalogu filemanager
# composer create-project --prefer-dist servocoder/richfilemanager filemanager
# chown -R www-data.www-data filemanager/userdata
– ustawienie virtualnego serwera np. https://mymanager.pl
– dostęp poprzez podany URL
Zmiana userfiles na media
# nano filemanager/connectors/php/filemanager.php
$local->setRoot('media', true, true);
Dostęp do pliku
https://mymanager.pl/media/dir/file.png
Konfiguracja static IP
# apt-get -y install ifupdown resolvconf # ifconfig
Obecna konfiguracja DHCP
enp0s3: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.1.6 netmask 255.255.255.0 broadcast 192.168.1.255
# nano /etc/network/interfaces
debian dns slave server
Master
nano /etc/bind/named.conf.local
debian bind 9
https://www.itzgeek.com/debian/configure-dns-server-on-debian-9.html
Instalacja bind9
# apt-get install -y bind9 bind9utils bind9-doc dnsutils
Globalna konfiguracja
# cd /etc/bind/ # less named.conf - nie zmieniany # nano named.conf.local - plik do edycji
cakephp PDF wkhtmltopdf
https://wkhtmltopdf.org
https://github.com/FriendsOfCake/CakePdf
Pobrać plik instalacyjny silnika ze strony i zainstalować
# dpkg -i wkhtmltox_0.12.5-1.stretch_amd64.deb
Podlinkować do domyślnej lokalizacji
# ln -s /usr/local/bin/wkhtmltopdf /usr/bin/wkhtmltopdf
cakePHP updateAll
use Cake\Database\Expression\QueryExpression; ... function incrementCounters() { $expression = new QueryExpression('view_count=view_count +1'); $this->updateAll([$expression], ['published' => true]); }
cakephp buildRules
// In src/Model/Table/OrdersTable.php public function buildRules(RulesChecker $rules) { $check = function($order) { if($order->shipping_mode !== 'free') { return true; } return $order->price >= 100; }; $rules->add($check, [ 'errorField' => 'shipping_mode' , 'message' => 'Nie ma bezpłatnej dostawy poniżej 100zł' ]); return $rules; } // W kontrolerze $order->price = 50; $order->shipping_mode = 'free' ; $ordersTable->save($order); // Returns false
cakePHP validator password compare
// In src/Model/Table/UsersTable.php public function validatePasswords($validator) { $validator->add('password2', 'no-misspelling' , [ 'rule' => [ 'compareWith' , 'password' ], 'message' => 'Hasła nie są takie same.' , ]); ... return $validator; }
CakePHP – loadInto() – lazy loading
Dołączenie modeli do pobranego już zasobu
$articles = $this->Articles->find()->all(); $withMore = $this->Articles->loadInto($articles, ['Comments', 'Users']);
TinyMCE config
Plik konfiguracyjny tinyMce
CakePHP – CounterCache
Przechowuje w tabeli ilość rekordów podrzędnych (dzieci). Definiowany jest na tabeli podrzędnej ( belongsTo() ). Tabela nadrzędna musi mieć kolumnę typu int (np. comment_count)
class CommentsTable extends Table
{
public function initialize(array $config)
{
$this->belongsTo('Articles');
$this->addBehavior('CounterCache' , [
'Articles' => [ 'comment_count' ]
]);
}
}
Można zastosować CounterCache w powiązaniach belongsToMany() tylko z opcją through. Wówczas behaviour definiuje się w tabeli łączącej gdyż posiada powiązania belongsTo().
Wprowadzenie warunku – zlicza tylko komentarze bez spamu
$this->addBehavior('CounterCache' , [
'Articles' => [
'comment_count' => [
'conditions' => [ 'Comments.spam' => false]
]
]
]);