Znaczniki Użytkownika (User Defined Tags)

Contents

Podziel się znacznikiem (UDT)

Jeżeli stworzyłeś jakiś znacznik, możesz podzielić się nim z innymi tutaj.

Wersja skrócona - UDT

Znaczniki użytkownika (User-defined tags - w skrócie UDT) są najprostszym sposobem na wstawienie kodu PHP na twoją stronę. Aby ich używać, poprostu stwórz nowy znacznik (tag) i wklej własnyk kod PHP (pomiń "<?php" i "?>" na końcu kodu). Znaczniki z wykorzystaniem smarty wywołujemy w następujący sposób: {nazwa_znacznika}
Standardowa instalacja CMS MS ma już zdefiniowany jeden znacznik, możesz go użyć w następujący sposób: {user_agent} (zgadnij co on robi :)

Parametry dla znaczników

Możesz przekazać parametry do znaczników, na przykład: "{image_link src='hedgehog'}" i kod znacznika
  echo '<a href="' . $params['src'] . '.jpg" target="_blank">';
  echo '<img src="t_' . $params['src'] . '.jpg"></a>';

Wersja rorszerzone - UDT

Jak zrobić własny znacznk (UDT)

Jak większość rzeczy w CMS Made Simple, dodanie nowego znacznika jest bardzo proste, aczkolwiek należy wykonać odrobinę czynności :).
Aby dodzać własny plugin (znacznik jest też plugin'em) wykonaj następujące kroki:
  1. The plugin editor is in the back-end so you need to login as admin, or a user with appropriate permissions.
  2. W Panelu Administratora kliknij na "Dodatki/Znaczniki Użytkownika" w rozwijanym menu.
  3. Na dole strony wybierz 'Dodaj własny znacznik'.
  4. W polu 'Nazwa' wpisz nazwę znacznika(może zawierać tylko litery, cyfry i podkreślenia). This is what you'll have to type in parenthesies to add a tag into a page so be descriptive but don't make it long.
  5. W polu 'Kod' wpisz swój kod php którym znacznik zostanie zastąpiony w chwili wywołania strony na której się znajduje. (Zobacz następną sekcję, aby zobaczyć jak to działa)
  6. Wybierz 'Zatwierdź'.

Twój Pierwszy UDT

Instead of me rambling on about every last detail of plugins and php a simple example should help you get started. Following in the footsteps of all introductions to programming we'll try a hello world script first.
Postępuj zgodnie z powyższymi krokami aby stworzyć swój plugin, 'Nazwa' to "helloworld" (pomiń cudzysłów) w polu 'Kod' wpisz/wklej następujący kod...
  echo 'Hello World!';
Wybierz 'Zatwierdź'. Aby przetestować znacznik, stwórz nową stronę typu 'Content' (zobacz Dodawanie treść), wpisz "{helloworld}" (pomiń cudzysłów) w dowolnym miejscu edytowanej strony i kliknij 'Podgląd'. Zamiast widocznego podczas edycji {helloworld} powinieneś zobaczyć "Hello World!".
The echo command just writes what's in the quotes so we can also use this to add HTML, or even DHTML or Javascript objects. Try out this code, just edit the plugin we made by clicking on the edit icon next to it on the 'Plugin Managment' page. Try this code...
  echo '<h3>Hello World!</h3>';
Test it in the same way as with the last one, you should now see something that looks a bit like this:

Hello World!

"But you can do all that with a html blob!" I hear you cry. Well, plugins get really useful when you start to add parameters. Parameters alow you to specify something in the tag. Let's say that we wanted to say hello to someone called Bob, try this code...
  echo '<h3>Hello ' . $params['name'] . '!</h3>';
This had added a parameter, "name", to the plugin, the contents of that parameter will be put there when the plugin is called from a tag in a page. Test it in the same way as before, but instead of using "{helloworld}" use "{helloworld name='Bob'}" as the tag to define the name parameter. You should see something like this...

Hello Bob!

That just about covers writing basic plugins, you can do some useful things with the echo command, parameters and a little imagination so just think what you can do if you learn a little PHP...

Passing the page content as a parameter

You can access the page content in a user defined tag by passing it as a parameter:
In your template:
  {content assign=pagecontent}
  {table_of_contents thepagecontent="$pagecontent"}
In your user defined tag named "table_of_contents":
  echo $params['thepagecontent']; // Display page content.
I use this so I can parse to the page content to automatically create a table of contents.

How to get the URL of a page from its content_id

This assumes your page content_id is in a variable named $page_content_id
  global $gCms;
  $hm =& $gCms->GetHierarchyManager();
  $curnode =& $hm->getNodeById($page_content_id);
  $curcontent =& $curnode->GetContent();
  echo 'Page URL: ' . $curcontent->GetURL();

How to Execute Smarty Tags from A User Defined Tag (UDT)

You can do it like this:
  global $gCms;
  $smarty = &$gCms->GetSmarty();
  $smarty_data = "{menu}";
  $smarty->_compile_source('temporary template', $smarty_data, $_compiled );
  @ob_start();
  $smarty->_eval('?>' . $_compiled);
  $_contents = @ob_get_contents();
  @ob_end_clean();
  echo $_contents;
This may allow you to manage multiple domains with one install of CMSMS if you did something like this:
  global $gCms;
  $smarty = &$gCms->GetSmarty();
 
  $url = $_SERVER['REQUEST_URI']; 
  if(eregi('domain1',$url))
  { 
    $smarty_data = "{menu template='cssmenu.tpl'}";
   
  }
  else if(eregi('domain2',$url))
  { 
    $smarty_data = "{menu template='cssmenu2.tpl'}";
  
  }
   $smarty->_compile_source('temporary template',    
     $smarty_data, $_compiled );
     @ob_start();
     $smarty->_eval('?>' . $_compiled);
     $_contents = @ob_get_contents();
     @ob_end_clean();
     echo $_contents;

Jak dostarczyć zmienną z UDT do twojej strony/szablonu

Sometimes you need to provide calculated or processed information via PHP variables from a UDT to a page or template. To do this add a new UDT and call it e.g. "Var" and fill in the code below

global $gCms;
$smarty = &$gCms->GetSmarty();
$foo= "test"; // Variable you want to provide
$smarty->assign('foo', $foo); // make variable "foo" visible for CMSms

Now you are able to use the variable in pages or templates via Smarty:

{Var} {* Call the UDT "Var" before using its variable(s) *}
<p>The content of the variable "foo" is {$foo}.</p>

Output:

The content of the variable "foo" is test.

In the section Share your tags here you will find a more reasonable example (see "Check for expire dates")


This page in: English - Deutsch - Español - Français - Italiano - Lietuvių - Nederlands - Norsk - Polski - Česky - Русский - Svenska - Tiếng Việt - عربي - 日本語 简体中文

User Handbook/Admin Panel/Extensions/User Defined Tags/pl

From CMSMS

A2 Hosting