function toolsetInit() { global $tpl, $view, $config; $tpl = new optClass(); $tpl->root = DIR_TPL; $tpl->compile = DIR_TPLC; $tpl->charset = 'utf-8'; $tpl->xmlsyntaxMode = true; $tpl->httpHeaders(OPT_XHTML); $view = new view(); $config = new config(); }
<?php require './common.php'; require OPT_DIR . 'opt.class.php'; require OPF_DIR . 'opf.class.php'; try { $tpl = new optClass(); $tpl->loadConfig('./config.php'); $validator = new opfValidator(); $opf = new opfClass($tpl, $validator->defaultParams()); $tpl->httpHeaders(OPT_HTML); $tpl->assign('ip', $opf->visit->ip); $tpl->assign('address', $opf->visit->currentAddress); $tpl->assign('ssl', $opf->visit->secure ? 'Yes' : 'No'); $tpl->assign('browser', $opf->visit->friendly('browser')); $tpl->assign('os', $opf->visit->friendly('os')); $tpl->assign('languages', $opf->visit->languages); $tpl->assign('settings', $opf->visit->settings); $tpl->parse('test_visit_1.tpl'); } catch (optException $exception) { optErrorHandler($exception); } catch (opfException $exception) { opfErrorHandler($exception); }
<?php define('OPT_DIR', '../lib/'); require OPT_DIR . 'opt.class.php'; try { $tpl = new optClass(); $tpl->root = './templates/'; $tpl->compile = './templates_c/'; $tpl->charset = 'iso-8859-2'; $tpl->debugConsole = true; $tpl->alwaysRebuild = true; $tpl->httpHeaders(OPT_HTML); $tpl->assign('mytree', array(0 => array('title' => 'Main category 1', 'depth' => 0), array('title' => 'Main category 2', 'depth' => 0), array('title' => 'Subcategory 2.1', 'depth' => 1), array('title' => 'Main category 3', 'depth' => 0), array('title' => 'Subcategory 3.1', 'depth' => 1), array('title' => 'Item 3.1.1', 'depth' => 2), array('title' => 'Item 3.1.2', 'depth' => 2), array('title' => 'Item 3.1.3', 'depth' => 2), array('title' => 'Subcategory 3.2', 'depth' => 1), array('title' => 'Subcategory 3.3', 'depth' => 1), array('title' => 'Item 3.3.1', 'depth' => 2), array('title' => 'Main category 4', 'depth' => 0), array('title' => 'Subcategory 4.1', 'depth' => 1), array('title' => 'Item 4.1.1', 'depth' => 2))); $tpl->parse('example18.tpl'); } catch (optException $exception) { optErrorHandler($exception); }
switch ($this->validator->type) { case 1: $component = new opfInput('value'); break; case 2: $component = new opfSelect('value'); // Provide the data source for the selection list $this->setDatasource(array('valueValues' => $itemList->getItems())); } $this->tpl->assign('value', $component); $this->tpl->parse('test_forms_4_2.tpl'); } } try { require './include.php'; $tpl = new optClass(); $tpl->loadConfig('./config.php'); $tpl->setMasterPage('master.tpl'); $validator = new opfValidator(); $opf = new opfClass($tpl, $validator->defaultParams()); $opf->createI18n('./'); $itemList = new itemList(); $typeList = new typeList(); $form1 = new myForm1($opf, 'form'); $form2 = new myForm2($opf, 'form'); $form1->nextStep($form2); if ($form1->execute()) { $tpl->assign('type', $typeList->getType($opf->validator->type)); switch ($opf->validator->type) { case 1: $tpl->assign('value', $opf->validator->value);
<?php define('OPT_DIR', '../lib/'); require '../lib/opt.class.php'; require '../lib/opt.components.php'; try { $tpl = new optClass(); $tpl->root = './templates/'; $tpl->compile = './templates_c/'; $tpl->gzipCompression = 1; $tpl->compileCacheDisabled = 1; $tpl->httpHeaders(OPT_HTML); require 'db_connect.php'; $r = mysql_query('SELECT id, name FROM categories ORDER BY id'); $list = array(0 => array('value' => 0, 'desc' => '---SELECT---', 'selected' => false)); while ($row = mysql_fetch_assoc($r)) { // add the next item $list[] = array('value' => $row['id'], 'desc' => $row['name'], 'selected' => false); } if (isset($_GET['selected'])) { $tpl->assign('selected', $_GET['selected']); if ($_GET['selected'] == 0) { $tpl->assign('message', 'Invalid choice!'); } } else { $tpl->assign('selected', 0); } $tpl->assign('list', $list); $tpl->parse('example7.tpl'); mysql_close(); } catch (optException $exception) {
<?php define('OPT_DIR', '../lib/'); require '../lib/opt.class.php'; try { $tpl = new optClass(); $tpl->root = './templates/'; $tpl->compile = './templates_c/'; $tpl->gzipCompression = 1; $tpl->httpHeaders(OPT_HTML); require 'db_connect.php'; $r = mysql_query('SELECT id, name FROM categories ORDER BY id'); $categories = array(); while ($row = mysql_fetch_assoc($r)) { $categories[$row['id']] = array('name' => $row['name']); } $r = mysql_query('SELECT id, name, description, category FROM products ORDER BY category, id'); $products = array(); while ($row = mysql_fetch_assoc($r)) { // add the next item $products[$row['category']][] = array('id' => $row['id'], 'name' => $row['name'], 'description' => $row['description']); } $tpl->assign('categories', $categories); $tpl->assign('products', $products); $tpl->parse('example13.tpl'); mysql_close(); } catch (optException $exception) { optErrorHandler($exception); }
public function apply($group, $text_id) { $args = func_get_args(); unset($args[0]); unset($args[1]); $this->replacements[$group][$text_id] = vsprintf($this->data[$group][$text_id], $args); } // end apply(); public function putApply($group, $text_id) { $args = func_get_args(); unset($args[0]); unset($args[1]); return vsprintf($this->data[$group][$text_id], $args); } } try { $tpl = new optClass(); $tpl->root = './templates/'; $tpl->compile = './templates_c/'; $tpl->gzipCompression = 1; $tpl->httpHeaders(OPT_HTML); // create an instance of the i18n system $i18n = i18n::getInstance(); // pass it to the parser $tpl->setObjectI18n($i18n); $tpl->assign('current_date', date('d.m.Y')); $tpl->parse('example5.tpl'); } catch (optException $exception) { optErrorHandler($exception); }
<?php require './common.php'; require OPT_DIR . 'opt.class.php'; require OPF_DIR . 'opf.class.php'; class myRouter implements iopfRouter { public function createURL($vars) { return var_export($vars, true); } } try { require './include.php'; $tpl = new optClass(); $tpl->loadConfig('./config.php'); $tpl->setMasterPage('master.tpl'); $validator = new opfValidator(); $opf = new opfClass($tpl, $validator->defaultParams()); $opf->createI18n('./'); $opf->setRouter(new myRouter()); $tpl->assign('vars', array('somevar' => 'somevalue')); $tpl->parse('test_router_1.tpl'); } catch (opfException $exception) { opfErrorHandler($exception); } catch (optException $exception) { optErrorHandler($exception); }
<?php define('OPT_DIR', '../lib/'); require '../lib/opt.class.php'; try { $tpl = new optClass(); $tpl->root = './templates/'; $tpl->compile = './templates_c/'; $tpl->cache = './cache/'; $tpl->gzipCompression = 1; $tpl->httpHeaders(OPT_HTML); $tpl->assign('current_date', date('d.m.Y, H:i:s')); // cache this template result for 30 seconds $tpl->cacheStatus(true, 30); $tpl->parse('example9.tpl'); } catch (optException $exception) { optErrorHandler($exception); }
if (!is_array($_POST['sel'])) { $view->message('No data provided.', 'compiler.php'); } foreach ($_POST['sel'] as $file) { $cplFile = optCompileFilename($file); if (is_file($config->cplDir . $cplFile)) { unlink($config->cplDir . $cplFile); } } $view->message('The selected compiled templates have been removed.', 'compiler.php'); } if (isset($_POST['csel'])) { if (!is_array($_POST['sel'])) { $view->message('No data provided.', 'compiler.php'); } $parser = new optClass(); $parser->root = $config->splDir; $parser->compile = $config->cplDir; $parser->showWarnings = false; $parser->xmlsyntaxMode = (bool) $config->xmlDir; if ($config->plgDir != '') { $parser->plugins = $config->plgDir; $parser->loadPlugins(); } if ($config->masDir != '') { $parser->setMasterTemplate($config->masDir); } require_once OPT_DIR . 'opt.compiler.php'; $parser->compiler = new optCompiler($parser); $current = ''; try {
$this->map('content', new opfStandardContainer(new opfConstraint(MAP_TYPE, TYPE_TEXT), new opfConstraint(MAP_LEN_GT, 10)), OPF_REQUIRED); } // end create(); public function process() { global $userTable; if (isset($userTable[$this->validator->username]) && $userTable[$this->validator->username] == $this->validator->password) { return true; } $this->setError('username', 'opf', 'invaliduser'); return false; } } try { require './include.php'; $tpl = new optClass(); $tpl->loadConfig('./config.php'); $tpl->setMasterPage('master.tpl'); $validator = new opfValidator(); $opf = new opfClass($tpl, $validator->defaultParams()); $opf->createI18n('./'); $form = new myForm($opf, 'form1'); if ($form->execute()) { $tpl->assign('username', $validator->username); $tpl->assign('email', $validator->email); $tpl->assign('age', $validator->age); $tpl->assign('content', $validator->content); $tpl->parse('report.tpl'); } else { if ($form->invalid()) { $tpl->assign('error_msg', 1);
<?php define('OPT_DIR', '../lib/'); require '../lib/opt.class.php'; try { $tpl = new optClass(); $tpl->root = './templates/'; $tpl->compile = './templates_c/'; $tpl->gzipCompression = 1; $tpl->httpHeaders(OPT_HTML); $tpl->assign('current_date', date('d.m.Y, H:i')); $tpl->parse('example1.tpl'); } catch (optException $exception) { optErrorHandler($exception); }
public function __construct(optClass $tpl, iopfValidator $validator) { $this->router = NULL; $this->design = new opfDesign(); $this->visit = new opfVisit(); $this->tpl = $tpl; $this->validator = $validator; // Object configuration $tpl->opf = $this; $tpl->control[] = 'opfCall'; $tpl->control[] = 'opfUrl'; $tpl->control[] = 'opfForm'; $tpl->control[] = 'opfJavascript'; $tpl->components['opfInput'] = 1; $tpl->components['opfPassword'] = 1; $tpl->components['opfTextarea'] = 1; $tpl->components['opfQuestion'] = 1; $tpl->components['opfLabel'] = 1; $tpl->components['opfSelect'] = 1; $tpl->components['opfRadio'] = 1; $tpl->components['opfFile'] = 1; $tpl->components['opfRetypePassword'] = 1; $tpl->components['opfCheckQuestion'] = 1; $tpl->instructionFiles[] = OPF_DIR . 'opf.template.php'; $tpl->registerNamespace('opf'); $tpl->assign('opfDesign', $this->design); $tpl->opf = $this; $validator->setOpfInstance($this); }
<?php define('OPT_DIR', '../lib/'); require '../lib/opt.class.php'; try { $tpl = new optClass(); $tpl->root = './templates/'; $tpl->compile = './templates_c/'; $tpl->gzipCompression = 1; $tpl->httpHeaders(OPT_HTML); $tpl->parse('example15.tpl'); } catch (optException $exception) { optErrorHandler($exception); }
<?php define('ITEM_NUM', 300); define('PAGE_SIZE', '10'); define('OPT_DIR', '../lib/'); require OPT_DIR . 'opt.class.php'; require './pagesystem.php'; try { $tpl = new optClass(); $tpl->root = './templates/'; $tpl->compile = './templates_c/'; $tpl->charset = 'iso-8859-2'; $tpl->debugConsole = true; $tpl->alwaysRebuild = true; $tpl->httpHeaders(OPT_HTML); $data = array(); // Create data array for ($i = 1; $i <= ITEM_NUM; $i++) { $data[] = 'Item ' . $i; } $ps = new pagesystem(ITEM_NUM, PAGE_SIZE, 'example19.php'); $rows = array(); for ($i = $ps->startPos(); $i <= $ps->endPos(); $i++) { if (isset($data[$i])) { $rows[] = array('item' => $data[$i]); } else { break; } } $tpl->assign('list', $rows); $tpl->assign('ps', $ps);
<?php define('OPT_DIR', '../lib/'); require '../lib/opt.class.php'; try { $tpl = new optClass(); $tpl->root = './templates/'; $tpl->compile = './templates_c/'; $tpl->gzipCompression = 1; // Enable XML-style delimiters $tpl->xmlsyntaxMode = 1; // Enable strict XML syntax for the instructions $tpl->strictSyntax = 1; $tpl->httpHeaders(OPT_HTML); require 'db_connect.php'; $r = mysql_query('SELECT id, name, description FROM products ORDER BY id'); $list = array(); while ($row = mysql_fetch_row($r)) { // add the next item $list[] = array('id' => $row[0], 'name' => $row[1], 'description' => $row[2]); } $tpl->assign('products', $list); if (rand(0, 10) < 5) { $tpl->assign('border', 'border="1"'); } $tpl->parse('example11.tpl'); mysql_close(); } catch (optException $exception) { optErrorHandler($exception); }
<?php define('OPT_DIR', '../lib/'); require '../lib/opt.class.php'; try { $tpl = new optClass(); $tpl->root = './templates/'; $tpl->compile = './templates_c/'; $tpl->cache = './cache/'; $tpl->gzipCompression = 1; $tpl->httpHeaders(OPT_HTML); $tpl->cacheStatus(true, 30); if (!$tpl->isCached('example10.tpl')) { require 'db_connect.php'; $r = mysql_query('SELECT id, name, description FROM products ORDER BY id'); $list = array(); while ($row = mysql_fetch_assoc($r)) { // add the next item $list[] = array('id' => $row['id'], 'name' => $row['name'], 'description' => $row['description']); } $tpl->assign('products', $list); mysql_close(); } // cache this template result for 30 seconds $tpl->parse('example10.tpl'); } catch (optException $exception) { optErrorHandler($exception); }
<?php define('OPT_DIR', '../lib/'); require '../lib/opt.class.php'; require '../lib/opt.components.php'; try { $tpl = new optClass(); $tpl->root = './templates/'; $tpl->compile = './templates_c/'; $tpl->gzipCompression = 1; $tpl->httpHeaders(OPT_HTML); require 'db_connect.php'; $selector = new selectComponent(); $selector->set('name', 'selected'); $selector->push(0, '---SELECT---'); $r = mysql_query('SELECT id, name FROM categories ORDER BY id'); while ($row = mysql_fetch_assoc($r)) { // add the next item $selector->push($row['id'], $row['name']); } if (isset($_GET['selected'])) { $selector->set('selected', $_GET['selected']); if ($_GET['selected'] == 0) { $selector->set('message', 'Invalid choice!'); } } else { $selector->set('selected', 0); } $tpl->assign('selector', $selector); $tpl->parse('example8.tpl'); mysql_close();
<?php define('OPT_DIR', '../lib/'); require '../lib/opt.class.php'; try { $tpl = new optClass(); $tpl->root = './templates/'; $tpl->compile = './templates_c/'; $tpl->gzipCompression = 1; $tpl->httpHeaders(OPT_HTML); require 'db_connect.php'; $r = mysql_query('SELECT id, name, description FROM products ORDER BY id'); $list = array(); while ($row = mysql_fetch_row($r)) { // add the next item $list[] = array('id' => $row[0], 'name' => $row[1], 'description' => $row[2]); } $tpl->assign('products', $list); $tpl->parse('example2.tpl'); mysql_close(); } catch (optException $exception) { optErrorHandler($exception); }
<?php define('OPT_DIR', '../lib/'); require '../lib/opt.class.php'; function optResourceDatabase(optClass $tpl, $title, $compiledTime = NULL) { if (is_null($compiledTime)) { $r = mysql_query('SELECT `code` FROM `templates` WHERE `title` = \'' . $title . '\''); } else { $r = mysql_query('SELECT `code` FROM `templates` WHERE `title` = \'' . $title . '\' AND `lastmod` > \'' . $compiledTime . '\''); } if ($row = mysql_fetch_row($r)) { return $row[0]; } return false; } // end optResourceDatabase(); try { require 'db_connect.php'; $tpl = new optClass(); $tpl->compile = './templates_c/'; $tpl->gzipCompression = 1; $tpl->httpHeaders(OPT_HTML); $tpl->registerResource('db', 'Database'); $tpl->assign('current_date', date('d.m.Y')); $tpl->parse('db:example17'); } catch (optException $exception) { optErrorHandler($exception); }
<?php define('OPT_DIR', '../lib/'); require '../lib/opt.class.php'; try { $tpl = new optClass(); $tpl->root = './templates/'; $tpl->compile = './templates_c/'; $tpl->gzipCompression = 1; require 'db_connect.php'; $tpl->httpHeaders(OPT_HTML); if (isset($_POST['yes'])) { die('Thank you for your submission, ' . $_POST['username'] . '!'); } else { if (isset($_POST['ok'])) { $username = new textLabelComponent(); $username->set('name', 'username'); $username->set('value', $_POST['username']); $username->set('message', 'Is this correct?'); $actions = array(0 => array('name' => 'yes', 'value' => 'Yes', 'type' => 'submit'), array('name' => 'no', 'value' => 'No', 'type' => 'submit')); } else { $username = new textInputComponent(); $username->set('name', 'username'); if (isset($_POST['username'])) { $username->set('value', $_POST['username']); } $actions = array(0 => array('name' => 'ok', 'value' => 'OK', 'type' => 'submit')); } } $tpl->assign('name', $username); $tpl->assign('actions', $actions);
} $this->setError('username', 'opf', 'invaliduser'); return false; } // end process(); public function view() { if ($this->invalid()) { $this->tpl->assign('error_msg', 1); } $this->tpl->parse('test_forms_3.tpl'); } } try { require './include.php'; $tpl = new optClass(); $tpl->loadConfig('./config.php'); $tpl->setMasterPage('master.tpl'); $validator = new opfValidator(); $opf = new opfClass($tpl, $validator->defaultParams()); $opf->createI18n('./'); $form = new myForm($opf, 'form1'); if ($form->execute()) { $tpl->assign('username', $opf->validator->username); $tpl->assign('email', $opf->validator->email); $tpl->assign('age', $opf->validator->age); $tpl->assign('content', $opf->validator->content); $tpl->parse('report.tpl'); } } catch (opfException $exception) { opfErrorHandler($exception);
$datasource = array('day' => $this->validator->day, 'month' => $this->validator->month, 'year' => $this->validator->year, 'user' => $this->validator->user); $datasource['dayValues'] = array(0 => '---'); for ($i = 1; $i <= 31; $i++) { $datasource['dayValues'][] = $i; } $datasource['monthValues'] = array(0 => '---Choose---', 'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'); $datasource['yearValues'] = array(0 => '---'); for ($i = 2006; $i <= 2012; $i++) { $datasource['yearValues'][$i] = $i; } $this->setDatasource($datasource); } } try { require './include.php'; $tpl = new optClass(); $tpl->loadConfig('./config.php'); $tpl->setMasterPage('master.tpl'); $validator = new opfValidator(); $opf = new opfClass($tpl, $validator->defaultParams()); $opf->createI18n('./'); $form = new calendarForm($opf, 'calendarForm'); $form->display(); if (checkdate($opf->validator->month, $opf->validator->day, $opf->validator->year)) { $tpl->assign('date', 1); $tpl->assign('day', $opf->validator->day); $tpl->assign('month', $opf->validator->month); $tpl->assign('year', $opf->validator->year); } $tpl->parse('test_opt_forms_1.tpl'); } catch (opfException $exception) {
{ $this->map('someText', new opfStandardContainer(new opfConstraint(MAP_TYPE, TYPE_STRING), new opfConstraint(MAP_LEN_GT, 3)), OPF_REQUIRED); } // end create(); public function view() { if ($this->invalid()) { $this->tpl->assign('form2_error', 1); } // The displaying command should be located in the last processed form $this->tpl->parse('test_multiple_1_1.tpl'); } } try { require './include.php'; $tpl = new optClass(); $tpl->loadConfig('./config.php'); $tpl->setMasterPage('master.tpl'); $validator = new opfValidator(); $opf = new opfClass($tpl, $validator->defaultParams()); $opf->createI18n('./'); $form1 = new form1($opf, 'form1'); if ($form1->execute()) { $tpl->assign('fill_form1', 1); $tpl->assign('text', $opf->validator->someText); $tpl->parse('test_multiple_1_2.tpl'); } else { $form2 = new form2($opf, 'form2'); if ($form2->execute()) { $tpl->assign('fill_form2', 1); $tpl->assign('text', $opf->validator->someText);
<?php define('OPT_DIR', '../lib/'); require '../lib/opt.class.php'; $lang = array('global' => array('text1' => 'This is text one', 'text2' => 'This is text two', 'text3' => 'This is text three', 'date' => 'Today is %s, good day for fishing')); try { $tpl = new optClass(); $tpl->root = './templates/'; $tpl->compile = './templates_c/'; $tpl->gzipCompression = 1; $tpl->httpHeaders(OPT_HTML); // init default i18n system $tpl->setDefaultI18n($lang); $tpl->assign('current_date', date('d.m.Y')); $tpl->parse('example4.tpl'); } catch (optException $exception) { optErrorHandler($exception); }