27 Kwi 2016

Obliczanie różnicy czasu i obliczanie nowej daty

error_reporting(E_ALL ^ E_WARNING ^ E_PARSE ^ E_NOTICE);
//date_default_timezone_set ("PL/PL");
date_default_timezone_set ("Europe/Warsaw");

class date_check {
static public function check_on($data) {
$day_ts = 86400;

$date_order = $data['date_order'];
$roznica = (strtotime($date_order)-strtotime(date('Y-m-d')));

$roznica_day = floor($roznica/$day_ts);

echo $date_order."";
echo $roznica."";
echo $roznica_day."";

if($roznica_day<12) {

$date_start = date('Y-m-d', strtotime("1 day"));
$date_stop = date('Y-m-d', strtotime("21 day"));

} else {

$day_back = -10;
$day_next = 10;

$date_start = date('Y-m-d', strtotime($date_order." ".$day_back." day"));
$date_stop = date('Y-m-d', strtotime($date_order." ".$day_next." day"));
}

return array('date_start'=>$date_start, 'date_stop'=>$date_stop);
}
}

$data_back = date_check::check_on(array('date_order'=>'2016-04-18'));

echo $data_back['date_start']."";
echo $data_back['date_stop']."";

$data_back = date_check::check_on(array('date_order'=>'2016-04-11'));

echo $data_back['date_start']."";
echo $data_back['date_stop']."";

$data_back = date_check::check_on(array('date_order'=>'2016-04-26'));

echo $data_back['date_start']."";
echo $data_back['date_stop']."";

Wynik działania:

2016-04-18
-777600
-9
2016-04-28
2016-05-18

2016-04-11
-1382400
-16
2016-04-28
2016-05-18

2016-04-26
-86400
-1
2016-04-28
2016-05-18

24 Lut 2016

Parsowanie adresu uri strony

$urls = array (
'http://kody.wig.pl/file.php?key=9emixire&ampexpires=1456358400&amp;signature=76f289',
'http://kody.wig.pl/file.php?key=9emixire&expires=1456358400&signature=76f289');
$arr_url = parse_url($urls[0]);
parse_str($arr_url['query'], $arr_query);
print_r($arr_url);
print_r($arr_query);

Wynik:

Array
(
[scheme] =&gt; http
[host] =&gt; kody.wig.pl
[path] =&gt; /file.php
[query] =&gt; key=9emixire&amp;expires=1456358400&amp;signature=76f289
)
Array
(
[key] =&gt; 9emixire
[expires] =&gt; 1456358400
[signature] =&gt; 76f289
)
1 Sty 2016

Optymalizacja wordpress

Poniżej kilka trików które pozwoliły mi przyspieszyć bloga z 32/22 w PageSpeed Insigth do 90/100 - oczywiście to zależy od strony, ilości zdjęć, szybkości serwera itp, wszystko ma znaczenie.
I to jest blog ze zdjęciami (blog.grzegorztomicki.pl), jak dla mnie bardzo zacnie 🙂

1. Będziemy potrzebować dostęp do .htaccess
W którym dodajemy (nie będę opisywał co dokładnie jest w nim robione bo wszystko można znaleźć opisane w internecie)

<ifmodule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
#</ifmodule>



<ifmodule mod_deflate.c>
  # Compress HTML, CSS, JavaScript, Text, XML and fonts
  AddOutputFilterByType DEFLATE application/javascript
  AddOutputFilterByType DEFLATE application/rss+xml
  AddOutputFilterByType DEFLATE application/vnd.ms-fontobject
  AddOutputFilterByType DEFLATE application/x-font
  AddOutputFilterByType DEFLATE application/x-font-opentype
  AddOutputFilterByType DEFLATE application/x-font-otf
  AddOutputFilterByType DEFLATE application/x-font-truetype
  AddOutputFilterByType DEFLATE application/x-font-ttf
  AddOutputFilterByType DEFLATE application/x-javascript
  AddOutputFilterByType DEFLATE application/xhtml+xml
  AddOutputFilterByType DEFLATE application/xml
  AddOutputFilterByType DEFLATE font/opentype
  AddOutputFilterByType DEFLATE font/otf
  AddOutputFilterByType DEFLATE font/ttf
  AddOutputFilterByType DEFLATE image/svg+xml
  AddOutputFilterByType DEFLATE image/x-icon
  AddOutputFilterByType DEFLATE text/css
  AddOutputFilterByType DEFLATE text/html
  AddOutputFilterByType DEFLATE text/javascript
  AddOutputFilterByType DEFLATE text/plain
  AddOutputFilterByType DEFLATE text/xml

  # Remove browser bugs (only needed for really old browsers)
  BrowserMatch ^Mozilla/4 gzip-only-text/html
  BrowserMatch ^Mozilla/4\.0[678] no-gzip
  BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
  Header append Vary User-Agent
</ifmodule>

<ifmodule mod_expires.c>
  ExpiresActive on

# Perhaps better to whitelist expires rules? Perhaps.
  ExpiresDefault                          "access plus 1 month"

# cache.appcache needs re-requests in FF 3.6 (thx Remy ~Introducing HTML5)
  ExpiresByType text/cache-manifest       "access plus 0 seconds"



# Your document html
  ExpiresByType text/html                 "access plus 0 seconds"

# Data
  ExpiresByType text/xml                  "access plus 0 seconds"
  ExpiresByType application/xml           "access plus 0 seconds"
  ExpiresByType application/json          "access plus 0 seconds"

# RSS feed
  ExpiresByType application/rss+xml       "access plus 1 hour"

# Favicon (cannot be renamed)
  ExpiresByType image/x-icon              "access plus 1 week" 

# Media: images, video, audio
  ExpiresByType image/gif                 "access plus 1 month"
  ExpiresByType image/png                 "access plus 1 month"
  ExpiresByType image/jpg                 "access plus 1 month"
  ExpiresByType image/jpeg                "access plus 1 month"
  ExpiresByType video/ogg                 "access plus 1 month"
  ExpiresByType audio/ogg                 "access plus 1 month"
  ExpiresByType video/mp4                 "access plus 1 month"
  ExpiresByType video/webm                "access plus 1 month"

# HTC files  (css3pie)
  ExpiresByType text/x-component          "access plus 1 month"

# Webfonts
  ExpiresByType font/truetype             "access plus 1 month"
  ExpiresByType font/opentype             "access plus 1 month"
  ExpiresByType application/x-font-woff   "access plus 1 month"
  ExpiresByType image/svg+xml             "access plus 1 month"
  ExpiresByType application/vnd.ms-fontobject "access plus 1 month"

# CSS and JavaScript
  ExpiresByType text/css                  "access plus 1 year"
  ExpiresByType application/javascript    "access plus 1 year"
  ExpiresByType text/javascript           "access plus 1 year"

  </ifmodule><ifmodule mod_headers.c>
    Header append Cache-Control "public"
    Header unset ETag
    FileETag None
  </ifmodule>