コード例 #1
0
    }
    // 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);
} catch (optException $exception) {
    optErrorHandler($exception);
}
コード例 #2
0
<?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);
}
コード例 #3
0
<?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);
}
コード例 #4
0
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();
} catch (optException $exception) {
    optErrorHandler($exception);
}
コード例 #5
0
    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);
}
コード例 #6
0
    }
}
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);
                break;
            case 2:
                $tpl->assign('value', $itemList->getItem($opf->validator->value));
        }
        $tpl->parse('test_forms_4_3.tpl');
    }
} catch (opfException $exception) {
    opfErrorHandler($exception);
} catch (optException $exception) {
    optErrorHandler($exception);
}
コード例 #7
0
<?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);
}
コード例 #8
0
<?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('example6.tpl');
} catch (optException $exception) {
    optErrorHandler($exception);
}
コード例 #9
0
<?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);
}
コード例 #10
0
    $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);
    $tpl->parse('example12.tpl');
    mysql_close();
} catch (optException $exception) {
    optErrorHandler($exception);
}
コード例 #11
0
        }
        $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) {
    opfErrorHandler($exception);
} catch (optException $exception) {
    optErrorHandler($exception);
}
コード例 #12
0
<?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);
}
コード例 #13
0
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);
    $tpl->parse('example19.tpl');
} catch (optException $exception) {
    optErrorHandler($exception);
}
コード例 #14
0
        }
        $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);
        }
        $tpl->parse('test_forms_1.tpl');
    }
} catch (opfException $exception) {
    opfErrorHandler($exception);
} catch (optException $exception) {
    optErrorHandler($exception);
}
コード例 #15
0
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) {
    optErrorHandler($exception);
}
コード例 #16
0
<?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);
}
コード例 #17
0
        }
        // 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);
            $tpl->parse('test_multiple_1_2.tpl');
        }
    }
} catch (opfException $exception) {
    opfErrorHandler($exception);
} catch (optException $exception) {
    optErrorHandler($exception);
}
コード例 #18
0
<?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);
}