function perform()
 {
     if (isset($_REQUEST['t']) && is_array($_REQUEST['t']) && sizeof($_REQUEST['t']) > 0) {
         $this->history = $_REQUEST['t'];
         $template_path = end($this->history);
     } else {
         $template_path = TEMPLATE_FOR_HACKERS;
     }
     if (substr($template_path, -5, 5) != '.html') {
         $template_path = TEMPLATE_FOR_HACKERS;
     }
     if (substr($template_path, -5, 5) != '.html') {
         return new failed_response();
     }
     if (!($source_file_path = resolve_template_source_file_name($template_path))) {
         debug::write_error('template not found', __FILE__ . ' : ' . __LINE__ . ' : ' . __FUNCTION__, array('template_path' => $this->template_path));
         $source_file_path = resolve_template_source_file_name(TEMPLATE_FOR_HACKERS);
     }
     $template_contents = file_get_contents($source_file_path);
     if (sizeof($this->history) > 1) {
         $tmp_history = $this->history;
         $from_template_path = $tmp_history[sizeof($tmp_history) - 2];
         $tmp_history = array_splice($tmp_history, 0, sizeof($tmp_history) - 1);
         $history_query = 't[]=' . implode('&t[]=', $tmp_history);
         $this->view->set('history_query', $history_query);
         $this->view->set('from_template_path', $from_template_path);
     }
     $this->view->set('template_path', $template_path);
     $this->view->set('template_content', $this->_process_template_content($template_contents));
     return new response();
 }
/**
* Compiles a template file. Uses the file scheme to location the source,
* instantiates the code_writer and root_compiler_component (as the root) component then
* instantiates the source_file_parser to parse the template.
* Creates the initialize and render functions in the compiled template.
*
* @see root_compiler_component
* @see code_writer
* @see source_file_parser
* @param string $ name of source template
* @return void
*/
function compile_template_file($filename, $resolve_path = true)
{
    global $tag_dictionary;
    if ($resolve_path) {
        if (!($sourcefile = resolve_template_source_file_name($filename))) {
            error('template file not found', __FILE__ . ' : ' . __LINE__ . ' : ' . __FUNCTION__, array('file' => $filename));
        }
    } else {
        $sourcefile = $filename;
    }
    $destfile = resolve_template_compiled_file_name($sourcefile, TMPL_INCLUDE);
    if (empty($sourcefile)) {
        error('MISSINGFILE2', __FILE__ . ' : ' . __LINE__ . ' : ' . __FUNCTION__, array('srcfile' => $filename));
    }
    $code =& new codewriter();
    $code->set_function_prefix(md5($destfile));
    $tree =& new root_compiler_component();
    $tree->source_file = $sourcefile;
    $sfp =& new source_file_parser($sourcefile, $tag_dictionary);
    $sfp->parse($tree);
    $tree->prepare();
    $render_function = $code->begin_function('(&$dataspace)');
    $tree->generate($code);
    $code->end_function();
    $construct_function = $code->begin_function('(&$dataspace)');
    $tree->generate_constructor($code);
    $code->end_function();
    $code->write_php('$GLOBALS[\'template_render\'][$this->codefile] = \'' . $render_function . '\';');
    $code->write_php('$GLOBALS[\'template_construct\'][$this->codefile] = \'' . $construct_function . '\';');
    write_template_file($destfile, $code->get_code());
}
 function perform(&$request, &$response)
 {
     if (($t = $request->get_attribute('t')) && is_array($t) && sizeof($t) > 0) {
         $this->history = $t;
         $template_path = end($this->history);
     } else {
         $template_path = TEMPLATE_FOR_HACKERS;
     }
     if (substr($template_path, -5, 5) != '.html') {
         $template_path = TEMPLATE_FOR_HACKERS;
     }
     if (substr($template_path, -5, 5) != '.html') {
         $request->set_status(REQUEST_STATUS_FAILURE);
     }
     if (!($source_file_path = resolve_template_source_file_name($template_path))) {
         debug::write_error('template not found', __FILE__ . ' : ' . __LINE__ . ' : ' . __FUNCTION__, array('template_path' => $this->template_path));
         $source_file_path = resolve_template_source_file_name(TEMPLATE_FOR_HACKERS);
     }
     $template_contents = file_get_contents($source_file_path);
     if (sizeof($this->history) > 1) {
         $tmp_history = $this->history;
         $from_template_path = $tmp_history[sizeof($tmp_history) - 2];
         $tmp_history = array_splice($tmp_history, 0, sizeof($tmp_history) - 1);
         $history_query = 't[]=' . implode('&t[]=', $tmp_history);
         $this->view->set('history_query', $history_query);
         $this->view->set('from_template_path', $from_template_path);
     }
     $this->view->set('template_path', $template_path);
     $this->view->set('template_content', $this->_process_template_content($template_contents));
 }
  /**
  *
  * @return int PARSER_FORBID_PARSING
  * @access protected
  */
  function pre_parse()
  {
    global $tag_dictionary;
    if (! array_key_exists('file', $this->attributes) ||
        empty($this->attributes['file']))
    {
      error('MISSINGREQUIREATTRIBUTE', __FILE__ . ' : ' . __LINE__ . ' : ' .  __FUNCTION__,
        array('tag' => $this->tag,
              'attribute' => 'file',
              'file' => $this->source_file,
              'line' => $this->starting_line_no));
    }
    $file = $this->attributes['file'];

    if (!$this->resolved_source_file = resolve_template_source_file_name($file))
    {
      error('MISSINGFILE', __FILE__ . ' : ' . __LINE__ . ' : ' .  __FUNCTION__,
        array('tag' => $this->tag,
              'srcfile' => $file,
              'file' => $this->source_file,
              'line' => $this->starting_line_no));
    }

    if (array_key_exists('literal', $this->attributes))
    {
      $literal_component =& new text_node(read_template_file($this->resolved_source_file));
      $this->add_child($literal_component);
    }
    else
    {
      $sfp =& new source_file_parser($this->resolved_source_file, $tag_dictionary);
      $sfp->parse($this);
    }
    return PARSER_FORBID_PARSING;
  }
Example #5
0
  /**
  *
  * @return int PARSER_FORBID_PARSING
  * @access protected
  */
  function pre_parse()
  {
    global $tag_dictionary;
    $file = $this->attributes['file'];
    if (empty($file))
    {
      error('MISSINGENCLOSURE', __FILE__ . ' : ' . __LINE__ . ' : ' .  __FUNCTION__, array('tag' => $this->tag,
          'attribute' => 'file',
          'enclosing_tag' => 'pager:navigator',
          'file' => $this->source_file,
          'line' => $this->starting_line_no));
    }

    if (!$this->resolved_source_file = resolve_template_source_file_name($file))
    {
      error('MISSINGFILE', __FILE__ . ' : ' . __LINE__ . ' : ' .  __FUNCTION__, array('tag' => $this->tag,
          'srcfile' => $file,
          'file' => $this->source_file,
          'line' => $this->starting_line_no));
    }

    $sfp =& new source_file_parser($this->resolved_source_file, $tag_dictionary);
    $sfp->parse($this);
    return PARSER_FORBID_PARSING;
  }
 /**
  * Constructs template
  * 
  * @param string $ name of (source) template file (relative or full path)
  * @access public 
  */
 function template($file, $resolve_path = true)
 {
     $this->file = $file;
     if ($resolve_path) {
         if (!($srcfile = resolve_template_source_file_name($file))) {
             error('template file not found', __FILE__ . ' : ' . __LINE__ . ' : ' . __FUNCTION__, array('file' => $file));
         }
     } else {
         $srcfile = $file;
     }
     $this->codefile = resolve_template_compiled_file_name($srcfile, TMPL_INCLUDE);
     if (!isset($GLOBALS['template_render'][$this->codefile])) {
         if (get_ini_option('config.ini', 'templates', 'force_compile')) {
             compile_template_file($file, $resolve_path);
         }
         if (!file_exists($this->codefile)) {
             compile_template_file($file, $resolve_path);
         }
         $errorlevel = error_reporting();
         error_reporting($errorlevel & ~E_WARNING);
         $parse_error = (include_once $this->codefile);
         error_reporting($errorlevel);
     }
     $this->render_function = $GLOBALS['template_render'][$this->codefile];
     $func = $GLOBALS['template_construct'][$this->codefile];
     $func($this);
 }
  function _find_template()
  {
    if(!$this->template_path)
      return null;

    include_once(LIMB_DIR . '/core/template/fileschemes/simpleroot/compiler_support.inc.php');
    return resolve_template_source_file_name($this->template_path);
  }
/**
* Compiles a var file and calls write_template_file
*/
function compile_var_file($filename)
{
    $destfile = resolve_template_compiled_file_name($filename, TMPL_IMPORT);
    if (!($sourcefile = resolve_template_source_file_name($filename))) {
        error('MISSINGFILE2', __FILE__ . ' : ' . __LINE__ . ' : ' . __FUNCTION__, array('srcfile' => $filename));
    }
    $text = serialize(parse_var_file($sourcefile));
    write_template_file($destfile, $text);
}
Example #9
0
 /**
  * 
  * @return int PARSER_FORBID_PARSING
  * @access protected 
  */
 function pre_parse()
 {
     if (!array_key_exists('file', $this->attributes) || empty($this->attributes['file'])) {
         error('MISSINGREQUIREATTRIBUTE', __FILE__ . ' : ' . __LINE__ . ' : ' . __FUNCTION__, array('tag' => $this->tag, 'attribute' => 'file', 'file' => $this->source_file, 'line' => $this->starting_line_no));
     }
     $file = $this->attributes['file'];
     if (!($sourcefile = resolve_template_source_file_name($file))) {
         error('MISSINGFILE', __FILE__ . ' : ' . __LINE__ . ' : ' . __FUNCTION__, array('tag' => $this->tag, 'srcfile' => $file, 'file' => $this->source_file, 'line' => $this->starting_line_no));
     }
     $dataspace =& $this->get_dataspace();
     $dataspace->vars += parse_var_file($sourcefile);
     return PARSER_FORBID_PARSING;
 }
 function redirect($path)
 {
     include_once LIMB_DIR . 'core/template/fileschemes/simpleroot/compiler_support.inc.php';
     $message = strings::get('redirect_message');
     //???
     $message = str_replace('%path%', $path, $message);
     if ($template = resolve_template_source_file_name('/redirect_template.html')) {
         $content = file_get_contents($template);
         $content = str_replace('{$path}', $path, $content);
         $content = str_replace('{$message}', $message, $content);
         $this->response_string = $content;
     } else {
         $this->response_string = "<html><head><meta http-equiv=refresh content='0;url={$path}'></head><body bgcolor=white>{$message}</body></html>";
     }
 }
 /**
  * Constructs template
  * 
  * @param string $ name of (source) template file (relative or full path)
  * @access public 
  */
 function template($file)
 {
     $this->file = $file;
     $srcfile = resolve_template_source_file_name($file, TMPL_INCLUDE);
     $this->codefile = resolve_template_compiled_file_name($srcfile, TMPL_INCLUDE);
     if (!isset($GLOBALS['template_render'][$this->codefile])) {
         if (get_ini_option('config.ini', 'templates', 'force_compile')) {
             compile_template_file($file);
         }
         if (!file_exists($this->codefile)) {
             compile_template_file($file);
         }
         $errorlevel = error_reporting();
         error_reporting($errorlevel & ~E_WARNING);
         $parse_error = (include_once $this->codefile);
         error_reporting($errorlevel);
     }
     $this->render_function = $GLOBALS['template_render'][$this->codefile];
     $func = $GLOBALS['template_construct'][$this->codefile];
     $func($this);
 }
 function _check_controller($controller)
 {
     $definitions = $controller->get_actions_definitions();
     $controller_class = get_class($controller);
     foreach ($definitions as $action => $data) {
         $this->assertTrue(isset($data['permissions_required']), 'controller: "' . $controller_class . '" permissions_required property for action "' . $action . '"not set');
         $this->assertTrue(in_array($data['permissions_required'], array('r', 'w', 'rw')), 'controller: "' . $controller_class . '" permissions_required property for action "' . $action . '"not valid');
         if (isset($data['template_path'])) {
             resolve_template_source_file_name($data['template_path']);
         }
         //throws error if no such a file
         if (isset($data['action_path'])) {
             $action_obj = action_factory::create($data['action_path']);
             $this->assertNotNull($action_obj, 'controller: "' . $controller_class . '" action object for action "' . $action . '"not found');
         }
         if (isset($data['action_name'])) {
             $this->assertTrue($data['action_name'], 'controller: "' . $controller_class . '" action_name property for action "' . $action . '" is empty - check strings');
         }
     }
     $action = $controller->get_default_action();
     $this->assertTrue(isset($definitions[$action]), 'controller: "' . $controller_class . '" default action "' . $action . '" doesnt exist');
 }