imponeer/smarty-xo

Smarty template engine plugins collections based on ideas for plugins from XOOPS

v1.1.8 2023-07-01 07:12 UTC

README

License GitHub release Maintainability PHP Packagist

Smarty XO

Rewritten (due licensing issues) collection Smarty plugins that where originally written for Xoops but now can be used everywhere.

Installation

To install and use this package, we recommend to use Composer:

composer require imponeer/smarty-xo

Otherwise, you need to include manually files from src/ directory.

Registering in Smarty

If you want to use these extensions from this package in your project you need register them with registerPlugin function from Smarty. For example:

$smarty = new \Smarty();
$plugins = [
  new \Imponeer\Smarty\Extensions\XO\XOAppUrlCompiler(
    function (string $url): string { // function that converts url into path
       return $url;
    },
    function (string $url, array $params = []): string { // function that adds params to path
       return $url . '?' . http_build_query($params);
    }
  ),
  new \Imponeer\Smarty\Extensions\XO\XOPageNavFunction(
    function (string $url): string { // function that generates real url
      return $url;
    },
    $strPreviousPage = '<',
    $strNextPage = '>',
    $oldSchoolUrlMode = true
  ),
  new \Imponeer\Smarty\Extensions\XO\XOImgUrlCompiler(
     function (string $imgPath): string { // function that makes psiaudo path into real assets path
        return $imgPath;
     }
  ),
  new \Imponeer\Smarty\Extensions\XO\XOInboxCountFunction(
     function (): ?int { // function that calc unread messages in user inbox 
       return 0;
     }
  )
];
foreach ($plugins as $plugin) {
  if ($plugin instanceof \Imponeer\Contracts\Smarty\Extension\SmartyFunctionInterface) {
    $type = 'function';
  } else {
    $type = 'compiler';
  }
  $smarty->registerPlugin($type, $plugin->getName(), [$plugin, 'execute']);
}

Inspirations list

This list can be useful for comparing current plugins code with original version to see differences and find some useful data how to use these plugins.

XO Smarty plugin Original Plugin (from Xoops)
\Imponeer\Smarty\Extensions\XO\XOPageNavFunction smarty_function_xoPageNav
\Imponeer\Smarty\Extensions\XO\XOAppUrlCompiler smarty_compiler_xoAppUrl
\Imponeer\Smarty\Extensions\XO\XOImgUrlCompiler smarty_compiler_xoImgUrl
\Imponeer\Smarty\Extensions\XO\XOInboxCountFunction smarty_function_xoInboxCount

How to contribute?

If you want to add some functionality or fix bugs, you can fork, change and create pull request. If you not sure how this works, try interactive GitHub tutorial.

If you found any bug or have some questions, use issues tab and write there your questions.