Webdesign

Adobe a grafika 35 Google 27 PHP 78 Webdesign, CMS 304

Co je nového v PHP 5 (díl 4/5)

V tomto díle se podíváme na další objektová rozšíření PHP 5. Jedním z nich je podpora pro konstanty v rámci třídy. Příklad?

class _trida{
 const constant = "constant";
}
echo "_trida::constant = " . _trida::constant . "\n";

V PHP 5 je možno odkazovat v návratových typech funkcí na metody instancí tříd, což v PHP 4 možno není. Příklad?

class _prvni{
 function doSomething() {
  print "prvni\n";
 }
}
class _druhy{
 function doSomething() {
  print "druhy\n";
 }
}
function _cislo($cislo) {
 switch ($cislo) {
  case "prvni": return new _prvni();
  case "druhy": return new _druhy();
 }
}
_cislo("prvni")->doSomething();
_cislo("druhy")->doSomething();
Celý článek 0 komentářů

Co je nového v PHP 5 (díl 3/5)

Se slušnou podporou objektů v PHP 5 souvisí i podpora pro lepší typovou kontrolu tříd. Konečně! Nicméně, není to podpora ve fázi kompilace, ale pochopitelně ve fázi runtime, tedy běhu programu. Tento příklad nám ilustruje "class hints":

interface _prvni { function a(_prvni $_prvni); }
interface _druhy { function b(_druhy $_druhy); }
class _treti implements _prvni, _druhy {
 function a(_prvni $_prvni) { // ... }
 function b(_druhy $_druhy) { // ... }
}
$a = new _treti;
$b = new _treti;
$a->a($b);
$a->b($b);
Celý článek 0 komentářů

Co je nového v PHP 5 (díl 2/5)

Ve druhém díle se podíváme na další rozšíření objektové koncepce PHP 5. Jedním z dalších podstatných rozšíření jsou abstraktní metody třídy (abstract), s tím, že třída, která obsahuje abstraktní metody (není definována jejich implemetace), musí být také typu abstract.

Je pochopitelné, že není možné vytvořit instanci abstract třídy, je nutné vytvořit návaznou třídu, která danou metodu již implemetuje, a zde vytvoříme instanci. Příklad?

abstract class AbstractClass {
  abstract public function test();
}
class ImplementedClass extends AbstractClass {
 public function test() {
   echo "ImplementedClass::test() called\n";
 }
}
$o = new ImplementedClass;
$o->test();
Celý článek 0 komentářů

Co je nového v PHP 5 (díl 1/5)

PHP 5 přináší spoustu výborných změn. Jedná se hlavně o změnu jeho objektové koncepce. Většině "taky-programátorů" to bude jedno, nevyužívají ani potenciálu PHP 4, nicméně, lidem jako já, co znají výborně C++, sedne PHP 5 mnohem lépe. Jeho implementace objektů se totiž zjevně nechala inspirovat C++ a Javou.

Třída bude mít konsktruktory (což má nakonec částečně již teď) a desktruktory:

class _metodaA {
 var $x;
 function __construct($x) {
   $this->x = $x;
 }
 function display() {
   print($this->x);
 }
 function __destruct() {
   print("bye bye");
 }
}
$o1 = new _metodaA(4);
$o1->display();

Třída bude mít protected (je k nim umožněn přístup i přímým potomkům) a private (přístup k nim mají jen třídy samotné, v nichž jsou definovány) proměnné a rovněž metody. Dosavadní kód (PHP 4) je považován, jako by všechny metody byly typu public.

class Foo {
 private function aPrivateMethod() {
  echo "Foo::aPrivateMethod() called\n";
 }
 protected function aProtectedMethod() {
  echo "Foo::aProtectedMethod() called\n";
  $this->aPrivateMethod();
 }
}
class Bar extends Foo {
  public function aPublicMethod() {
   echo "Bar::aPublicMethod() called\n";
   $this->aProtectedMethod();
  }
}
$o = new Bar;
$o->aPublicMethod();
0 komentářů

TrackBack 1.5 a AutoDiscovery pro Nucleus XE

TeRaxEX a Admun připravili update pluginu NP_TrackBack, včetně plně automatické AutoTrackBack funkce (vkládá do článků RDF kód, který podporující systémy použijí pro automatické vytvoření TrackBacku; není tedy již nutné ručně "pingat"). Takto automaticky vytvořený TrackBack se samozřejmě nepublikuje ihned, ale až po Vašem schválení. Toto schválení je možné provádět při editaci článku.

Připravil jsem úpravu NP_TrackBack verze 1.5 pro češtinu (zejména automatické rozpoznání kódování pingu), a dodělal taky pár dalších změn.

Použití? V šabloně "hlavička článku" uveďte následující kód pro vložení AutoTrackBack kódu:

<%TrackBack(tbcode)%>

Dále v patičce článku uveďte následující pro výpis aktuálních TrackBacků:

<%TrackBack(list)%>

Používat můžete i následující parametry pro zobrazení formuláře pro manuální ping a pro manuální přidání (třeba omylem smazaného) TrackBacku:

<%TrackBack(pingformlink)%>
a
<%TrackBack(manualpingformlink)%>

Soubor ke stažení: NP_TrackBack.php.

0 komentářů

NP_Cache v1.2 - mix static and dynamic content

ferrari

I have upgraded my "Plugin-Of-The-Year Winner" (as moraes denoted it), aka NP_Cache, to fully support partial caching. This gives you the ability to cache (statically) most of your page, while still allowing dynamic content plugins like NP_WIE, NP_Views, comment form, and few others to work as they should.

And not only this! Partial cache subscribes to pre-edit / delete / add item and comment events, add / delete category events, and blog events, and clears the item, index, and archive pages as necessary.

NP_Cache is a plugin that creates static pages on request, and it does it fully automatically. What does this mean? If page, or part of it, is requested for the first time, it will capture the output, save it into a static XHTML file, and when it is requested for the second time, it will output this static page in microseconds, without doing tens of SQL queries. It will speed-up your system 10 to 500-times.

NP_Cache allows you to specify which pages should be completely static (i.e. they will be completely saved, with no dynamic content, and refreshed only after a specified cache lifeTime, or, of course, after an event is triggered, like adding an item or a comment), or use special keywords to cache parts of pages that will be cached.

Celý článek 0 komentářů

Jak zrychlit Váš web 10x? (konkrétní návod)

Uvedené řešení předpokládá, že Váš web je generován dynamicky, v tomto případě docílíte skutečně cca 10-ti násobného zrychlení Vašeho webu, nicméně, díky zde uvedeným algoritmům je zrychlení 3-4 násobné i po statické XHTML stránky.

V čem spočívá tento algoritmus? Nejdříve, proveďte kompresi Vašeho CSS a JavaScriptu, jak píšu v předchozím článku.

Následně přistoupíme ke kompresi online generovaných PHP stránek, a k vytváření XHTML statických variant stránek, a to plně automaticky.

Pro 10x rychlejší web Vám potom postačí, když na začátku Vaší stránky uvedete následující:

<?php
$statickeXHTML = new Cache();
$statickeXHTML->start();
?>

A na konci následující:

<?php 
$statickeXHTML->finish();
?> 

Jednoduché, ne?

Celý článek 0 komentářů

NP_Cache - static pages for Nucleus CMS

Fast!

NP_Cache is a new plugin for Nucleus CMS, compatible with version Nucleus 2.0 and above, including its standard, eXtreme Edition, and Light Edition distributions. It creates static pages real-time, automatically, refreshes them as needed. It also calculates some statistics as well. It is based on Cache_Lite PHP class.

Without this plugin, it takes about 0.2 seconds to create a homepage of this blog. With this plugin installed, it takes only 0.0007 seconds! Quite a difference 😉

NP_Cache will cache following Nucleus pages and keep them updated as needed:

  • index page.
  • item pages.
  • archivelist pages.
  • archive pages.
  • member pages.
Celý článek 0 komentářů

NP_ExtraSkin - even better than sliced bread

With NP_Table and NP_ExtraSkin plugins, you now have an extremely easy way to include extra pages (like favourite links, contact info, personal pages, projects, etc.), to Nucleus CMS.

You can also edit all this information through user-friendly interface in Nucleus CMS Admin Area. So, no more using <%phpinclude%>, no more using external files, and FTP file transfers! With this extension, Nucleus becomes a true CMS!

And not only that! NP_ExtraSkin supports also "FancyURLs", user defined, they are in a form of http://your.domain/extra/my-fancy-url-title. E.g. http://your.domain/extra/contact! Each ExtraSkin can have FancyURL defined. If it does not, you can still call it as a skinVar, from your current skins, or even templateVar by using syntax <%ExtraSkin(skinname)%>.

And, last, but not least, NP_ExtraSkin enables you to include calls to plugins and skinVars in your template. So, you can use. e.g., NP_Table plugin to maintain a list of links, and NP_ExtraSkin plugin to display it on your webpage, by specifying <%Table(links)%> in ExtraSkin's skin 🙂

No more you have to create files like header.inc and footer.inc. You will create ExtraSkins, called header and footer, and place <%ExtraSkin(header)%> and <%ExtraSkin(footer)%> at start / beginnig of each skin. And Admins will be able to edit this in Nucleus CMS Admin Area.

Possibilities are limitless...

Download at: https://myego.cz/other/NP_ExtraSkin.zip (18kB).

0 komentářů

NP_Table - tool for automatic creation of tables and lists

forms

NP_Table is a new plugin for Nucleus CMS. And I believe, and immensely useful one! It allows to create, in a very user-friendly way, a table, assign a name and description to this table, add, edit and delete items, and, also, create templates (header, footer, odd item, even item), that will display this table in your skin (skinVar) or even in your article (by subscribing to PreItem event)!

Of course, you can create as much tables as you like! And, because of templating system for each "table", they do not have to look like <table>s, but, e.g., like lists ( <ul>, .. <li> ), or separated by <br />.

How it can be used? Imagine, e.g., that you wrote 10 articles about Nucleus. Now, you would like, for each article, to include an updated list of links to few sites that inspired you. Support forums, and such. With NP_Table, you will create a new "table", called, e.g., nucleuslinks. You will, in Nucleus admin interface, add items to this table. And change them, any time. And by calling % ++Table(nucleuslinks)++ % (no spaces inside) in your articles body, NP_Table will automatically display this table, or list, or whatever (as each "table" has its own template) in all your articles.

You can also create a list of your favourite links, bookmarks (and maintain this in a very user-friendly way from admin interface) and display it on you homepage, by using a skinVar called <%Table(nucleuslinks)%>.

Possibilities for usage are unlimited… Phone numbers, email lists, come to mind…

Celý článek 0 komentářů