Ejemplo n.º 1
0
 /**
  * Configuration method.
  * @param Opt_Class $tpl 
  */
 public function configure(Opt_Class $tpl)
 {
     $tpl->parser = 'Opt_Parser_Html';
     $tpl->backwardCompatibility = true;
     $tpl->register(Opt_Class::OPT_COMPONENT, 'opt:myComponent', 'Extra_Mock_Component');
     $tpl->register(Opt_Class::OPT_BLOCK, 'opt:myBlock', 'Extra_Mock_Block');
 }
Ejemplo n.º 2
0
 /**
  * Configuration method.
  * @param Opt_Class $tpl
  */
 public function configure(Opt_Class $tpl)
 {
     $tpl->parser = 'Opt_Parser_Html';
     $tpl->useExpressionNamespaces = false;
     $tpl->register(Opt_Class::OPT_NAMESPACE, 'ns1');
     $tpl->register(Opt_Class::PHP_FUNCTION, 'ecf', 'Package_Parser_HtmlTest::testEcf');
 }
Ejemplo n.º 3
0
 /**
  * @covers Opf_Class::__construct
  */
 public function testConstructorBasic()
 {
     $this->_optMock->expects($this->atLeastOnce())->method('register');
     Opl_Registry::register('opt', $this->_optMock);
     $opf = new Opf_Class();
     $this->assertTrue(Opl_Registry::exists('opf'));
 }
Ejemplo n.º 4
0
function getCompilerEnvironment()
{
    $tpl = new Opt_Class();
    $tpl->sourceDir = './templates/';
    $tpl->compileDir = './templates_c/';
    $tpl->setup();
    $tpl->compiler = new Opt_Compiler_Class($tpl);
    return $tpl;
}
Ejemplo n.º 5
0
 /**
  * Initializes the debug console for Open Power Template by adding its
  * own information frames and tables.
  *
  * @internal
  * @static
  * @param Opt_Class $tpl The main class
  */
 public static function initDebugConsole($tpl)
 {
     Opl_Debug_Console::addList('opt_options', 'OPT Options and settings');
     Opl_Debug_Console::addList('opt_stats', 'OPT Stats');
     Opl_Debug_Console::addTable('opt_views', 'OPT: Executed views', array('#', 'View', 'Output', 'Time', 'Cached'));
     Opl_Debug_Console::addTable('opt_compiled', 'OPT: Compiled templates', array('#', 'Template', 'Estimated XML tree memory'));
     Opl_Debug_Console::addTable('opt_sections', 'OPT: Sections (Template compilation)', array('#', 'Name', 'Parent', 'Data format', 'Type'));
     Opl_Debug_Console::addListOptions('opt_options', $tpl->getConfig());
 }
Ejemplo n.º 6
0
 /**
  * Configuration method.
  * @param Opt_Class $tpl
  */
 public function configure(Opt_Class $tpl)
 {
     if ($this->_type == 0) {
         $tpl->parser = 'Opt_Parser_Html';
     } else {
         $tpl->parser = 'Opt_Parser_Xml';
     }
     $tpl->register(Opt_Class::EXPR_ENGINE, 'test', 'Extra_Mock_Expression');
 }
Ejemplo n.º 7
0
 /**
  * Registers a new stream in the inflector.
  *
  * @param string $streamName The new stream name
  * @param string $streamPath The new stream path
  * @param boolean $secure Do we secure the path by adding the ending slash?
  * @throws Opt_ObjectExists_Exception
  */
 public function addStream($streamName, $streamPath, $secure = true)
 {
     if (isset($this->_streams[(string) $streamName])) {
         throw new Opt_ObjectExists_Exception('stream', (string) $streamName, 'standard inflector');
     }
     $this->_streams[(string) $streamName] = (string) $streamPath;
     if ($secure) {
         $this->_tpl->_securePath($this->_streams[(string) $streamName]);
     }
 }
Ejemplo n.º 8
0
 public function init()
 {
     $tpl = new Opt_Class();
     $tpl->sourceDir = 'test://templates/';
     $tpl->compileDir = CPL_DIR;
     $tpl->compileMode = Opt_Class::CM_REBUILD;
     $tpl->stripWhitespaces = false;
     $tpl->prologRequired = true;
     $tpl->setup();
     $this->tpl = $tpl;
 }
Ejemplo n.º 9
0
 /**
  * Does the engine add the slashes to the paths?
  */
 public function testSlashing()
 {
     $foo = new Opt_Class();
     $foo->sourceDir = './templates';
     $foo->compileDir = './templates_c';
     $foo->setup();
     if ($foo->sourceDir['file'] != './templates/' || $foo->compileDir != './templates_c/') {
         $this->fail('No ending slash in the paths. SourceDir: ' . $foo->sourceDir . '; CompileDir: ' . $foo->compileDir);
     }
     unset($foo);
 }
Ejemplo n.º 10
0
 protected function setUp()
 {
     $tpl = new Opt_Class();
     $tpl->sourceDir = 'test://templates/';
     $tpl->compileDir = CPL_DIR;
     $tpl->compileMode = Opt_Class::CM_REBUILD;
     $tpl->stripWhitespaces = false;
     $tpl->prologRequired = true;
     $tpl->register(Opt_Class::OPT_FORMAT, 'Test');
     $tpl->setup();
     $this->tpl = $tpl;
 }
Ejemplo n.º 11
0
 /**
  * Configuration method.
  * @param Opt_Class $tpl
  */
 public function configure(Opt_Class $tpl)
 {
     if ($this->_type == 0) {
         $tpl->parser = 'Opt_Parser_Html';
     } else {
         $tpl->parser = 'Opt_Parser_Xml';
     }
     $tpl->register(Opt_Class::MODIFIER, 'a', 'Extra_Mock_Modifier::modifier');
     $tpl->register(Opt_Class::MODIFIER, 'r', 'Extra_Mock_Modifier::modifier');
     $tpl->register(Opt_Class::MODIFIER, 'p', 'htmlspecialchars');
     $tpl->register(Opt_Class::MODIFIER, 'b', null);
 }
Ejemplo n.º 12
0
 protected function setUp()
 {
     $tpl = new Opt_Class();
     $tpl->sourceDir = 'test://templates/';
     $tpl->compileDir = CPL_DIR;
     $tpl->compileMode = Opt_Class::CM_REBUILD;
     $tpl->stripWhitespaces = false;
     $tpl->prologRequired = true;
     $tpl->register(Opt_Class::OPT_COMPONENT, 'opt:myComponent', 'myComponent');
     $tpl->register(Opt_Class::OPT_BLOCK, 'opt:myBlock', 'myBlock');
     $tpl->setup();
     $this->tpl = $tpl;
     Opt_View::clear();
 }
Ejemplo n.º 13
0
 /**
  * Sets the compiler instance.
  *
  * @param Opt_Compiler_Class $compiler The compiler object
  */
 public function setCompiler(Opt_Compiler_Class $compiler)
 {
     $this->_compiler = $compiler;
     $this->_tpl = Opl_Registry::get('opt');
     if ($this->_tpl->unicodeNames) {
         // Register unicode name regular expressions
         $this->_rOpeningChar = '(\\p{Lu}|\\p{Ll}|\\p{Ll}|\\p{Lt}|\\p{Lm}|\\p{Nl}|\\_|\\:)';
         $this->_rNameChar = '(\\p{Lu}|\\p{Ll}|\\p{Ll}|\\p{Lt}|\\p{Lm}|\\p{Nl}|\\p{Mc}|\\p{Me}|\\p{Mn}|\\p{Lm}|\\p{Nd}|\\_|\\:|\\.|\\-)';
         $this->_rModifiers = 'msiu';
     }
     // Register the rest of the expressions
     $this->_rNameExpression = '/(' . $this->_rOpeningChar . '?' . $this->_rNameChar . '*)/' . $this->_rModifiers;
     $this->_rXmlTagExpression = '/(\\<((\\/)?(' . $this->_rOpeningChar . '?' . $this->_rNameChar . '*)( [^\\<\\>]*)?(\\/)?)\\>)/' . $this->_rModifiers;
     $this->_rTagExpandExpression = '/^(\\/)?(' . $this->_rOpeningChar . '?' . $this->_rNameChar . '*)( [^\\<\\>]*)?(\\/)?$/' . $this->_rModifiers;
     $this->_rQuirksTagExpression = '/(\\<((\\/)?((' . implode('|', $this->_tpl->_getList('_namespaces')) . ')\\:' . $this->_rNameChar . '*)( [^\\<\\>]+)?(\\/)?)\\>)/' . $this->_rModifiers;
 }
Ejemplo n.º 14
0
 /**
  * @covers Opt_Class::setCache
  * @covers Opt_Class::getCache
  */
 public function testCacheReset()
 {
     $this->_tpl->setCache($obj = $this->getMock('Opt_Caching_Interface'));
     $this->assertSame($obj, $this->_tpl->getCache());
     $this->_tpl->setCache();
     $this->assertEquals(null, $this->_tpl->getCache());
     return true;
 }
Ejemplo n.º 15
0
 /**
  * Compiles a language variable.
  * @param string $group The group name
  * @param string $id The message ID name
  * @param int $weight The token weight
  * @return SplFixedArray
  */
 public function _compileLanguageVar($group, $id, $weight)
 {
     if ($this->_tpl->getTranslationInterface() == null) {
         throw new Opt_NotSupported_Exception('language variable call', 'no translation interface installed');
     }
     $array = new SplFixedArray(4);
     $array[0] = '$this->_tf->_(\'' . $group . '\',\'' . $id . '\')';
     $array[1] = $weight;
     $array[2] = 'Scalar';
     $array[3] = 0;
     return $array;
 }
Ejemplo n.º 16
0
 /**
  * The compilation launcher. It executes the proper compilation steps
  * according to the inheritance rules etc.
  *
  * @param String $code The source code to be compiled.
  * @param String $filename The source template filename.
  * @param String $compiledFilename The output template filename.
  * @param Int $mode The compilation mode.
  */
 public function compile($code, $filename, $compiledFilename, $mode)
 {
     $manager = $this->getCdfManager();
     // Initialize the context.
     $this->_contextStack->push(new Opt_Compiler_Context($this, Opt_Compiler_Context::TEMPLATE_CTX, $filename));
     try {
         // First, we select a parser.
         if (!isset($this->_parsers[$mode])) {
             $this->_parsers[$mode] = new $mode();
             if (!$this->_parsers[$mode] instanceof Opt_Parser_Interface) {
                 throw new Opt_InvalidParser_Exception($mode);
             }
         }
         $parser = $this->_parsers[$mode];
         $parser->setCompiler($this);
         // We cannot compile two templates at the same time
         if (!is_null($this->_template)) {
             throw new Opt_CompilerLocked_Exception($filename, $this->_template);
         }
         // Detecting recursive inclusion
         if (is_null(self::$_recursionDetector)) {
             self::$_recursionDetector = array(0 => $filename);
             $weFree = true;
         } else {
             if (in_array($filename, self::$_recursionDetector)) {
                 $exception = new Opt_CompilerRecursion_Exception($filename);
                 $exception->setData(self::$_recursionDetector);
                 throw $exception;
             }
             self::$_recursionDetector[] = $filename;
             $weFree = false;
         }
         // Cleaning up the processors
         foreach ($this->_processors as $proc) {
             $proc->reset();
         }
         // Initializing the template launcher
         $this->set('template', $this->_template = $filename);
         $this->set('mode', $mode);
         $this->set('currentTemplate', $this->_template);
         array_push(self::$_templates, $filename);
         $this->_stack = new SplStack();
         $i = 0;
         $extend = $filename;
         $memory = 0;
         // The inheritance loop
         do {
             // Stage 1 - code compilation
             if ($this->_tpl->debugConsole) {
                 $initial = memory_get_usage();
                 $tree = $parser->parse($extend, $code);
                 // Migration stage - only if backwards compatibility is on
                 if ($this->_tpl->backwardCompatibility) {
                     $tree = $this->_migrate($tree);
                 }
                 // Stage 2 - PHP tree processing
                 $this->_stack = null;
                 $this->_stage2($tree);
                 $this->set('escape', NULL);
                 unset($this->_stack);
                 $memory += memory_get_usage() - $initial;
                 unset($code);
             } else {
                 $tree = $parser->parse($extend, $code);
                 unset($code);
                 // Migration stage - only if backward compatibility is on
                 if ($this->_tpl->backwardCompatibility) {
                     $this->_migrate($tree);
                 }
                 // Stage 2 - PHP tree processing
                 $this->_stack = array();
                 $this->_stage2($tree);
                 $this->set('escape', NULL);
                 unset($this->_stack);
             }
             // if the template extends something, load it and also process
             if (isset($extend) && $extend != $filename) {
                 $this->addDependantTemplate($extend);
             }
             if (!is_null($snippet = $tree->get('snippet'))) {
                 $tree->dispose();
                 unset($tree);
                 // Change the specified snippet into a root node.
                 $tree = new Opt_Xml_Root();
                 $attribute = new Opt_Xml_Attribute('opt:use', $snippet);
                 $this->processor('snippet')->processAttribute($tree, $attribute);
                 $this->processor('snippet')->postprocessAttribute($tree, $attribute);
                 $this->_stage2($tree, true);
                 break;
             }
             if (!is_null($extend = $tree->get('extend'))) {
                 $tree->dispose();
                 unset($tree);
                 $this->set('currentTemplate', $extend);
                 array_pop(self::$_templates);
                 array_push(self::$_templates, $extend);
                 $code = $this->_tpl->_getSource($extend);
             }
             $i++;
         } while (!is_null($extend));
         // There are some dependant templates. We must add a suitable PHP code
         // to the output.
         if (sizeof($this->_dependencies) > 0) {
             $this->_addDependencies($tree);
         }
         if ($this->_tpl->debugConsole) {
             Opt_Support::addCompiledTemplate($this->_template, $memory);
         }
         // Stage 3 - linking the last tree
         if (!is_null($compiledFilename)) {
             $this->_output = '';
             $this->_newQueue = null;
             $this->_dynamicBlocks = array();
             $this->_stage3($output, $tree);
             $tree->dispose();
             unset($tree);
             $this->_output = str_replace('?><' . '?php', '', $this->_output);
             // Build the directories, if needed.
             if (($pos = strrpos($compiledFilename, '/')) !== false) {
                 $path = $this->_tpl->compileDir . substr($compiledFilename, 0, $pos);
                 if (!is_dir($path)) {
                     mkdir($path, 0750, true);
                 }
             }
             // Save the file
             if (sizeof($this->_dynamicBlocks) > 0) {
                 file_put_contents($this->_tpl->compileDir . $compiledFilename . '.dyn', serialize($this->_dynamicBlocks));
             }
             file_put_contents($this->_tpl->compileDir . $compiledFilename, $this->_output);
             $this->_output = '';
             $this->_dynamicBlocks = null;
         } else {
             $tree->dispose();
         }
         array_pop(self::$_templates);
         $this->_inheritance = array();
         if ($weFree) {
             // Do the cleanup.
             $this->_dependencies = array();
             self::$_recursionDetector = NULL;
             foreach ($this->_processors as $processor) {
                 $processor->reset();
             }
         }
         $this->_template = NULL;
         $manager->clearLocals();
         // Free the context.
         while ($this->_contextStack->count() > 0) {
             $ctx = $this->_contextStack->pop();
             $ctx->dispose();
         }
         // Run the new garbage collector, if it is available.
         /*	if(version_compare(PHP_VERSION, '5.3.0', '>='))
         			{
         				gc_collect_cycles();
         			}*/
     } catch (Exception $e) {
         // Free the context
         while ($this->_contextStack->count() > 0) {
             $ctx = $this->_contextStack->pop();
             $ctx->dispose();
         }
         // Free the memory
         if (isset($tree)) {
             $tree->dispose();
         }
         // Clean the compiler state in case of exception
         $this->_template = NULL;
         $this->_dependencies = array();
         self::$_recursionDetector = NULL;
         foreach ($this->_processors as $processor) {
             $processor->reset();
         }
         $manager->clearLocals();
         // And throw it forward.
         throw $e;
     }
 }
Ejemplo n.º 17
0
    }
    // end onInit();
    public function onAccept()
    {
        $view = $this->getView();
        $view->setTemplate('results2.tpl');
        $results = array();
        foreach ($this->getValue() as $name => $value) {
            $results[] = array('name' => $name, 'value' => $value);
        }
        $view->results = $results;
    }
}
// end GeneralForm;
try {
    $tpl = new Opt_Class();
    $opf = new Opf_Class($tpl);
    $tpl->sourceDir = './templates/';
    $tpl->compileDir = './templates_c/';
    $tpl->compileMode = Opt_Class::CM_REBUILD;
    $tpl->stripWhitespaces = false;
    $tpl->gzipCompression = false;
    $tpl->register(Opt_Class::PHP_FUNCTION, 'dump', 'var_dump');
    $tpl->setup();
    $translate = new Opc_Translate(new Opc_Translate_Adapter_Ini(array('directory' => './lang/')));
    $translate->setLanguage('en');
    $opf->setTranslationInterface($translate);
    $view = new Opt_View('situation_5.tpl');
    $view->devFile = 'situation_5.php';
    $form = new GeneralForm('form5');
    $form->setView($view);
Ejemplo n.º 18
0
<?php

// OPL Initialization
$config = parse_ini_file('../paths.ini', true);
require $config['libraries']['Opl'] . 'Base.php';
Opl_Loader::loadPaths($config);
Opl_Loader::setCheckFileExists(false);
Opl_Loader::register();
Opl_Registry::setState('opl_debug_console', false);
Opl_Registry::setState('opl_extended_errors', true);
try {
    $tpl = new Opt_Class();
    $tpl->sourceDir = './templates/';
    $tpl->compileDir = './templates_c/';
    $tpl->charset = 'utf-8';
    $tpl->compileMode = Opt_Class::CM_REBUILD;
    $tpl->stripWhitespaces = false;
    //$tpl->register(Opt_Class::OPT_FORMAT, 'Paginator', 'Opc_Paginator_DataFormat');
    $tpl->setup();
    $opc = new Opc_Class();
    $pager = Opc_Paginator::create(1000, 13);
    // returns Opc_Paginator_Pager;
    $pager->all = 1000;
    $pager->page = isset($_GET['page']) ? $_GET['page'] : 1;
    $view = new Opt_View('paginator_opt.tpl');
    $view->pager = $pager;
    //$view->setFormat('pager', 'Paginator');
    $view->setFormat('pager', 'Objective/Array');
    $view->setFormat('pager.decorator', 'Objective');
    $out = new Opt_Output_Http();
    $out->setContentType(Opt_Output_Http::HTML);
Ejemplo n.º 19
0
 /**
  * Configures the test case.
  */
 public function setUp()
 {
     $tpl = new Opt_Class();
     $tpl->sourceDir = '/';
     $tpl->sourceDir = 'php://memory';
     $tpl->compileDir = dirname(__FILE__) . '/../../Cache/';
     $tpl->escape = false;
     $tpl->allowArrays = true;
     $tpl->allowObjects = true;
     $tpl->allowObjectCreation = true;
     $tpl->register(Opt_Class::PHP_FUNCTION, '_', '_');
     $tpl->register(Opt_Class::PHP_FUNCTION, 'foo', 'foo');
     $tpl->register(Opt_Class::PHP_FUNCTION, 'bar', 'bar');
     $tpl->register(Opt_Class::PHP_FUNCTION, 'joe', 'joe');
     $tpl->register(Opt_Class::PHP_FUNCTION, 'lol', 'lol');
     $tpl->register(Opt_Class::PHP_FUNCTION, 'funct', 'funct');
     $tpl->register(Opt_Class::PHP_FUNCTION, 'rotfl', 'rotfl');
     $tpl->register(Opt_Class::PHP_FUNCTION, 'lmao1', '#1#lmao');
     $tpl->register(Opt_Class::PHP_FUNCTION, 'lmao2', '#2,1#lmao');
     $tpl->register(Opt_Class::PHP_FUNCTION, 'lmao3', '#3,1,2:null#lmao');
     $tpl->register(Opt_Class::PHP_CLASS, 'class', '_class');
     $tpl->register(Opt_Class::PHP_CLASS, 'e', 'e');
     $tpl->register(Opt_Class::PHP_CLASS, 'u', 'u');
     $tpl->register(Opt_Class::PHP_CLASS, 'a', 'a');
     Opl_Registry::register('opl_translate', $this->getMock('Opl_Translation_Interface'));
     $tpl->setup();
     $this->tpl = $tpl;
     $this->cpl = new Opt_Compiler_Class($tpl);
 }
Ejemplo n.º 20
0
 /**
  * Compiles the specified template and returns the current
  * time.
  *
  * @internal
  * @param String $filename The file name.
  * @return Integer
  */
 public function _compile($filename)
 {
     $compiled = $this->_tpl->getInflector()->getCompiledPath($filename, $this->_inheritance);
     $compiler = $this->_tpl->getCompiler();
     $compiler->setInheritance($this->_inheritance);
     $compiler->setFormatList(array_merge($this->_formatInfo, self::$_globalFormatInfo));
     $compiler->set('branch', $this->_branch);
     $compiler->compile($this->_tpl->_getSource($filename), $filename, $compiled, $this->_mode);
     return time();
 }
Ejemplo n.º 21
0
 /**
  * Creates a new instance of OPF.
  *
  * @param Opt_Class $opt Open Power Template instance.
  */
 public function __construct(Opt_Class $opt)
 {
     Opl_Registry::set('opf', $this);
     $opt->register(Opt_Class::OPT_NAMESPACE, 'opf');
     $opt->register(Opt_Class::OPT_INSTRUCTION, 'Form', 'Opf_View_Instruction_Form');
     $opt->register(Opt_Class::OPT_FORMAT, 'Form', 'Opf_View_Format_Form');
     $opt->register(Opt_Class::OPT_FORMAT, 'Design', 'Opf_View_Format_Design');
     $opt->register(Opt_Class::OPT_FORMAT, 'FormRepeater', 'Opf_View_Format_FormRepeater');
     $opt->register(Opt_Class::OPT_COMPONENT, 'opf:input', 'Opf_Widget_Input');
     $opt->register(Opt_Class::OPT_COMPONENT, 'opf:textarea', 'Opf_Widget_Textarea');
     $opt->register(Opt_Class::OPT_COMPONENT, 'opf:password', 'Opf_Widget_Password');
     $opt->register(Opt_Class::OPT_COMPONENT, 'opf:yesno', 'Opf_Widget_Yesno');
     $opt->register(Opt_Class::OPT_COMPONENT, 'opf:select', 'Opf_Widget_Select');
     $opt->register(Opt_Class::OPT_COMPONENT, 'opf:collection', 'Opf_Widget_Collection');
     Opt_View::setFormatGlobal('design', 'Design', false);
 }
Ejemplo n.º 22
0
<?php

// OPL Initialization
$config = parse_ini_file('../paths.ini', true);
require $config['libraries']['Opl'] . 'Base.php';
Opl_Loader::loadPaths($config);
Opl_Loader::setCheckFileExists(false);
Opl_Loader::register();
Opl_Registry::setState('opl_debug_console', false);
Opl_Registry::setState('opl_extended_errors', true);
try {
    Opl_Loader::setHandleUnknownLibraries(false);
    $viewSettings = array('sourceDir' => './templates/', 'compileDir' => './templates_c/', 'prologRequired' => true, 'stripWhitespaces' => false, 'gzipCompression' => true, 'contentType' => 0, 'charset' => 'utf-8');
    $opc = new Opc_Class();
    $tpl = new Opt_Class();
    $tpl->setup($viewSettings);
    $iniOptions = array('directory' => './langs/', 'fileExistsCheck' => false);
    $yamlOptions = array('directory' => './langs/', 'fileExistsCheck' => true, 'compileResult' => true, 'compileResultDirectory' => './cache/');
    $xmlOptions = array('directory' => './langs/', 'fileExistsCheck' => false, 'compileResult' => true, 'compileResultDirectory' => './cache/');
    $adapterIni = new Opc_Translate_Adapter_Ini($iniOptions);
    $adapterYaml = new Opc_Translate_Adapter_Yaml($yamlOptions);
    $adapterXml = new Opc_Translate_Adapter_Xml($xmlOptions);
    $translate = new Opc_Translate($adapterIni);
    $tpl->setTranslationInterface($translate);
    $translate->setLanguage('en');
    $translate->setGroupAdapter('pl', $adapterYaml);
    $translate->setGroupLanguage('pl', 'pl');
    $translate->setGroupAdapter('de', $adapterXml);
    $translate->setGroupLanguage('de', 'de');
    $view = new Opt_View('translate.tpl');
    $view->pagetitle = 'Translation test';
Ejemplo n.º 23
0
$config = parse_ini_file('../../paths.ini', true);
require $config['libraries']['Opl'] . 'Base.php';
Opl_Loader::loadPaths($config);
Opl_Loader::setCheckFileExists(false);
Opl_Loader::register();
Opl_Registry::setState('opl_extended_errors', true);
if (!file_exists('./config.php')) {
    die('Please create the config.php file from config.sample.php!');
}
require './config.php';
require './includes/forms.php';
require './components/base.php';
require './components/input.php';
require './components/textarea.php';
try {
    $tpl = new Opt_Class();
    // Load the configuration
    $tpl->loadConfig($config['opt']);
    // Register the components
    $tpl->register(Opt_Class::OPT_COMPONENT, 'opt:input', 'InputComponent');
    $tpl->register(Opt_Class::OPT_COMPONENT, 'opt:textarea', 'TextareaComponent');
    $tpl->setup();
    Opt_View::assignGlobal('baseHref', $config['script']['baseHref']);
    // Connect to the database.
    $pdo = new PDO($config['db']['dsn'], $config['db']['user'], $config['db']['password']);
    $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    $pdo->query('SET NAMES `' . $config['db']['charset'] . '`');
    // Load and execute the action.
    $action = 'list';
    if (isset($_GET['action']) && ctype_alpha($_GET['action'])) {
        $action = $_GET['action'];
Ejemplo n.º 24
0
 /**
  * Configuration method.
  * @param Opt_Class $tpl
  */
 public function configure(Opt_Class $tpl)
 {
     $tpl->parser = 'Opt_Parser_Xml';
     $tpl->useExpressionNamespaces = false;
     $tpl->register(Opt_Class::OPT_NAMESPACE, 'ns1');
 }
Ejemplo n.º 25
0
<?php

// OPL Initialization
$config = parse_ini_file('../paths.ini', true);
require $config['libraries']['Opl'] . 'Base.php';
Opl_Loader::loadPaths($config);
Opl_Loader::setCheckFileExists(false);
Opl_Loader::register();
Opl_Registry::setState('opl_debug_console', false);
Opl_Registry::setState('opl_extended_errors', true);
try {
    Opl_Loader::setHandleUnknownLibraries(false);
    $viewSettings = array('sourceDir' => './templates/', 'compileDir' => './templates_c/', 'prologRequired' => true, 'stripWhitespaces' => false, 'gzipCompression' => true, 'contentType' => 0, 'charset' => 'utf-8');
    $tpl = new Opt_Class();
    $tpl->setup($viewSettings);
    $opc = new Opc_Class();
    $viewCacheOptions = array('cacheDir' => './cache/', 'expiryTime' => 120, 'key' => null);
    $viewCache = new Opc_View_Cache($viewCacheOptions);
    $tpl->setCache($viewCache);
    $view = new Opt_View('caching_test_dynamic.tpl');
    $view->pagetitle = 'Caching system test';
    $view->dynamic = 'Dynamic3';
    $out = new Opt_Output_Http();
    $out->setContentType();
    $out->render($view);
} catch (Opc_Exception $exception) {
    $handler = new Opc_ErrorHandler();
    $handler->display($exception);
}
Ejemplo n.º 26
0
 protected function setUp()
 {
     $tpl = new Opt_Class();
     $tpl->sourceDir = '/';
     $tpl->sourceDir = './templates/';
     $tpl->compileDir = './templates_c/';
     $tpl->escape = false;
     $tpl->register(Opt_Class::PHP_FUNCTION, '_', '_');
     $tpl->register(Opt_Class::PHP_FUNCTION, 'foo', 'foo');
     $tpl->register(Opt_Class::PHP_FUNCTION, 'bar', 'bar');
     $tpl->register(Opt_Class::PHP_FUNCTION, 'joe', 'joe');
     $tpl->register(Opt_Class::PHP_FUNCTION, 'lol', 'lol');
     $tpl->register(Opt_Class::PHP_FUNCTION, 'funct', 'funct');
     $tpl->register(Opt_Class::PHP_FUNCTION, 'rotfl', 'rotfl');
     $tpl->register(Opt_Class::PHP_FUNCTION, 'lmao1', '#1#lmao');
     $tpl->register(Opt_Class::PHP_FUNCTION, 'lmao2', '#2,1#lmao');
     $tpl->register(Opt_Class::PHP_FUNCTION, 'lmao3', '#3,1,2:null#lmao');
     $tpl->register(Opt_Class::PHP_CLASS, 'class', '_class');
     $tpl->register(Opt_Class::PHP_CLASS, 'e', 'e');
     $tpl->register(Opt_Class::PHP_CLASS, 'u', 'u');
     $tpl->register(Opt_Class::PHP_CLASS, 'a', 'a');
     Opl_Registry::register('opl_translate', new tl());
     $tpl->setup();
     $this->tpl = $tpl;
     $this->cpl = new Opt_Compiler_Class($tpl);
 }
Ejemplo n.º 27
0
 /**
  * @covers Opt_View::__construct
  * @covers Opt_View::getCache
  */
 public function testConstructorGetsCacheFromOpt()
 {
     $this->_tpl->setCache($obj = $this->getMock('Opt_Caching_Interface'));
     $view = new Opt_View('template.tpl');
     $this->assertSame($obj, $view->getCache());
 }