Exemplo n.º 1
0
 public function __construct()
 {
     parent::__construct();
     $compiler = new Dwoo_Compiler();
     $compiler->setDelimiters('<?', '?>');
     // add preprocessor
     // add custom plugins, functions, blocks, etc
     $this->setCompiler($compiler);
     $this->setCompileDir(PROJECT_RUNTIME . '/' . $type . '_c');
     $this->assign('this', $page);
     $this->assign('context', $context);
 }
Exemplo n.º 2
0
$g_objAdmin->checkEditViewAccess();
$objView = AROView::finder()->byPK($_REQUEST['id']);
$szViewFile = PROJECT_VIEWS . '/' . $objView->id . '.php';
if (!empty($_GET['deleteme'])) {
    $objView->delete();
    unlink($szViewFile);
    header('Location: ../');
    exit;
} else {
    if (isset($_POST['title'], $_POST['content'], $_POST['type'])) {
        require_once PROJECT_INCLUDE . '/Dwoo-1.1.1/Dwoo/dwooAutoload.php';
        $template_source = $_POST['content'];
        $template = new Dwoo_Template_String($template_source);
        $dwoo = new Dwoo();
        $compiler = new Dwoo_Compiler();
        $compiler->setDelimiters('<?', '?>');
        $dwoo->setCompiler($compiler);
        try {
            $compiled_template_source = $dwoo->testTemplate($template);
            //	echo '<pre>'.htmlspecialchars($template_source).'</pre>';
            //	echo '<p>is a valid template:</p>';
            //	exit('<pre>'.htmlspecialchars(file_get_contents($compiled_template_source)).'</pre>');
        } catch (Dwoo_Exception $exc) {
            echo '<pre style="background-color:pink;">' . htmlspecialchars($template_source) . '</pre>';
            echo '<p>is NOT a valid template:</p>';
            exit('<pre style="background-color:pink;">' . $exc->getMessage() . '</pre>');
        }
        $objView->title = $_POST['title'];
        $objView->type = implode(',', $_POST['type']);
        $objView->save();
        file_put_contents($szViewFile, $_POST['content']);
Exemplo n.º 3
0
    /**
     *  Parse
     *
     * Parses pseudo-variables contained in the specified template,
     * replacing them with the data in the second param
     *
     * @access	public
     * @param	string
     * @param	array
     * @param	bool
     * @param	string
     * @return	string
     */
    public function _parse_compiled($string, $data, $return = FALSE, $cache_id = NULL)
    {
        // Start benchmark
        $this->_ci->benchmark->mark('dwoo_parse_start');
        // Convert from object to array
        if (!is_array($data)) {
            $data = (array) $data;
        }
        $data = array_merge($this->_ci->load->get_vars(), $data);
        foreach ($this->_parser_assign_refs as $ref) {
            $data[$ref] =& $this->_ci->{$ref};
        }
        // Object containing data
        $dwoo_data = new Dwoo_Data();
        $dwoo_data->setData($data);
        $parsed_string = '';
        try {
            // Object of the template
            $tpl = new Dwoo_Template_String($string, NULL, $cache_id, NULL);
            $dwoo = !isset($this->_dwoo) ? self::spawn() : $this->_dwoo;
            // check for existence of dwoo object... may not be there if folder is not writable
            // added by David McReynolds @ Daylight Studio 1/20/11
            if (!empty($dwoo)) {
                // Create the compiler instance
                $compiler = new Dwoo_Compiler();
                // added by David McReynolds @ Daylight Studio 1/22/12
                $compiler->setDelimiters($this->l_delim, $this->r_delim);
                //Add a pre-processor to help fix javascript {}
                // added by David McReynolds @ Daylight Studio 11/04/10
                $callback = create_function('$compiler', '
					$string = $compiler->getTemplateSource();
					
					$callback = create_function(\'$matches\',
						\'if (isset($matches[1]))
						{
							$str = "<script";
							$str .= preg_replace("#\\' . $this->l_delim . '([^s])#ms", "' . $this->l_delim . ' $1", $matches[1]);
							$str .= "</script>";
							return $str;
						}
						else
						{
							return $matches[0];
						}
						\'
						);

					$string = preg_replace_callback("#<script(.+)</script>#Ums", $callback, $string);
					$compiler->setTemplateSource($string);
					return $string;
				');
                $compiler->addPreProcessor($callback);
                // render the template
                $parsed_string = $dwoo->get($tpl, $dwoo_data, $compiler);
            } else {
                // load FUEL language file because it has the proper error
                // added by David McReynolds @ Daylight Studio 1/20/11
                $this->_ci->load->module_language(FUEL_FOLDER, 'fuel');
                throw new Exception(lang('error_folder_not_writable', $this->_ci->config->item('cache_path')));
            }
        } catch (Exception $e) {
            if (strtolower(get_class($e)) == 'dwoo_exception') {
                echo '<div class="error">' . $e->getMessage() . '</div>';
            } else {
                show_error($e->getMessage());
            }
        }
        // Finish benchmark
        $this->_ci->benchmark->mark('dwoo_parse_end');
        // Return results or not ?
        if (!$return) {
            $this->_ci->output->append_output($parsed_string);
            return;
        }
        return $parsed_string;
    }