<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="pl">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<meta name="robots" content="all" />
<title>Introduction to plugins - Open Power Template</title>
<link rel="stylesheet" type="text/css" href="design/generic.css" media="all" />
<link rel="stylesheet" type="text/css" href="design/print.css" media="print" />
<!--[if lte IE 6]><link rel="stylesheet" href="design/ie.css" type="text/css" /><![endif]-->
<!--[if IE 7]><link rel="stylesheet" href="design/ie7.css" type="text/css" /><![endif]-->
</head>
<body>
<div id="wrap">
<div id="header">
<h1>Open Power Template 2.0</h1>
<h2>Introduction to plugins</h2>
<p class="generated">@ 02.09.2010</p>
<p class="location"><a href="index.html"><strong>User manual</strong></a> » <a href="extending.html">Extending OPT</a> » <a href="extending.plugins.html">Introduction to plugins</a></p>
</div>
<div id="content"><dl class="location"><dt><a href="extending.html">5. Extending OPT</a><br/>5.1. Introduction to plugins</dt><dd class="prev">5. Extending OPT<br/><a href="extending.html">« Previous</a></dd><dd class="next">5.2. New functions<br/><a href="extending.functions.html">Next »</a></dd></dl> <h1>5.1. Introduction to plugins</h1><p>Open Power Template provides a plugin architecture that allows you to install new extensions easily. To initialize the plugins, you need two extra directories pointed by the directives:</p>
<ul>
<li><code>pluginDir</code> - a single directory or a list of directories with plugins.</li>
<li><code>pluginDataDir</code> - a directory, where OPT will save some data that speed up plugin loading. This can be the same directory, as <code>compileDir</code>, if you do not wish to multiply the directories with the write access.</li>
</ul>
<p>For example:</p>
<pre class="php"><span style="color: #000088;">$tpl</span><span style="color: #339933;">-></span><span style="color: #004000;">sourceDir</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'./templates/'</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$tpl</span><span style="color: #339933;">-></span><span style="color: #004000;">compileDir</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'./templates_c/'</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$tpl</span><span style="color: #339933;">-></span><span style="color: #004000;">pluginDataDir</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'./templates_c/'</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$tpl</span><span style="color: #339933;">-></span><span style="color: #004000;">pluginDir</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'./plugins/'</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$tpl</span><span style="color: #339933;">-></span><span style="color: #004000;">setup</span><span style="color: #009900;">(</span><span style="color: #009900;">)</span><span style="color: #339933;">;</span></pre>
<p>The <code>setup()</code> method will load the plugins automatically. Alternatively, you may load them manually earlier with <code>Opt_Class::loadPlugins()</code>.</p>
<h2>Writing plugins</h2>
<p>The plugins are normal PHP files. They have an access to the contents of your <code>Opt_Class</code> object, so they can request registering various items in OPT. A single plugin can add several new items to your library. The only types of content that require a strict structure are instructions and data formats. Writing plugins for them is described later. Below, you can find a sample plugin file:</p>
<pre class="php"><span style="color: #000000; font-weight: bold;"><?php</span>
<span style="color: #000000; font-weight: bold;">function</span> myFunction<span style="color: #009900;">(</span><span style="color: #009900;">)</span>
<span style="color: #009900;">{</span>
<span style="color: #b1b100;">return</span> <span style="color: #0000ff;">'Hi universe!'</span><span style="color: #339933;">;</span>
<span style="color: #009900;">}</span> <span style="color: #666666; font-style: italic;">// end myFunction();</span>
<span style="color: #000088;">$this</span><span style="color: #339933;">-></span><span style="color: #004000;">register</span><span style="color: #009900;">(</span>Opt_Class<span style="color: #339933;">::</span><span style="color: #004000;">PHP_FUNCTION</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'myFunction'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'myFunction'</span><span style="color: #009900;">)</span><span style="color: #339933;">;</span></pre>
<p>The file name does not matter in this case. Simple, isn't it? Now you can save the file in your plugin directory.</p>
<dl class="location location-bottom"><dt>5.1. Introduction to plugins<br/><a href="extending.html">5. Extending OPT</a></dt><dd class="prev"><a href="extending.html">« Previous</a><br/>5. Extending OPT</dd><dd class="next"><a href="extending.functions.html">Next »</a><br/>5.2. New functions</dd></dl> </div>
<div id="footer">
<p>Copyright © <a href="http://www.invenzzia.org/">Invenzzia Group 2008-2009</a></p>
<p>Available under the terms of license: <a href="http://www.gnu.org/licenses/fdl.html">GNU Free Documentation License 1.2</a></p>
<p>Generated by <strong>TypeFriendly 0.1.4</strong> by <a href="http://www.invenzzia.org/">Invenzzia</a></p>
</div>
</div>
</body>
</html>