Esempio n. 1
0
 /**
  * @override
  */
 function WdfRender()
 {
     $attr = array();
     foreach ($this->_attributes as $name => $value) {
         if ($name[0] != "_") {
             $attr[] = "{$name}=\"" . str_replace("\"", """, $value) . "\"";
         }
     }
     foreach ($this->_data_attributes as $name => $value) {
         $attr[] = "data-{$name}='" . str_replace("'", "\\'", $value) . "'";
     }
     $content = system_render_object_tree($this->_content);
     if (isset($GLOBALS['html_skip_if_empty'][$this->Tag])) {
         if (trim(implode(" ", $content)) == "") {
             return "";
         }
     }
     $css = array();
     foreach ($this->_css as $key => $val) {
         $css[] = "{$key}:{$val};";
     }
     $attr = count($attr) > 0 ? " " . implode(" ", $attr) : "";
     $css = count($css) > 0 ? " style=\"" . implode(" ", $css) . "\"" : "";
     $content = count($content) > 0 ? implode("", $content) : "";
     if ($this->Tag) {
         if ($content || $this->CloseTagNeeded()) {
             $res = "<{$this->Tag}{$attr}{$css}>{$content}</{$this->Tag}>";
         } else {
             $res = "<{$this->Tag}{$attr}{$css}/>";
         }
     } else {
         $res = "{$content}";
     }
     if (system_is_ajax_call() && count($this->_script) > 0) {
         $res .= "<script> " . implode("\n", $this->_script) . "</script>";
     }
     return $res;
 }
 /**
  * @override
  */
 function WdfRender()
 {
     $tempvars = system_render_object_tree($this->get_vars());
     foreach ($GLOBALS as $key => &$val) {
         ${$key} = $val;
     }
     $buf = array();
     foreach ($tempvars as $key => &$val) {
         if (isset(${$key})) {
             $buf[$key] = ${$key};
         }
         ${$key} = $val;
     }
     if ($this instanceof HtmlPage && stripos($this->file, "htmlpage.tpl.php") !== false) {
         $__template_file = __autoload__template($this, $this->SubTemplate ? $this->SubTemplate : "");
         if ($__template_file === false) {
             WdfException::Raise("SubTemplate for class '" . get_class($this) . "' not found: " . $this->file, $this->SubTemplate);
         }
         if (stripos($__template_file, "htmlpage.tpl.php") === false) {
             ob_start();
             require $__template_file;
             $sub_template_content = ob_get_contents();
             ob_end_clean();
         }
         $this->file = __DIR__ . "/htmlpage.tpl.php";
     }
     $__template_file = __autoload__template($this, $this->file);
     if ($__template_file === false) {
         WdfException::Raise("Template for class '" . get_class($this) . "' not found: " . $this->file);
     }
     ob_start();
     require $__template_file;
     $contents = ob_get_contents();
     ob_end_clean();
     foreach ($tempvars as $key => &$val) {
         unset(${$key});
     }
     foreach ($buf as $key => &$val) {
         ${$key} = $val;
     }
     if (system_is_ajax_call() && count($this->_script) > 0) {
         $contents .= "<script> " . implode("\n", $this->_script) . "</script>";
     }
     return $contents;
 }
Esempio n. 3
0
/**
 * Renders a complete object tree.
 * 
 * This means that the tree is checked for Renderable objects, arrays and so on
 * and all the needed actions are triggered recursively.
 * @param array $array_of_objects Array of objects
 * @return mixed An array containing the rendered strings
 */
function system_render_object_tree($array_of_objects)
{
    if (!isset($GLOBALS['system_render_object_tree_stack'])) {
        $GLOBALS['system_render_object_tree_stack'] = array();
    }
    $res = array();
    foreach ($array_of_objects as $key => &$val) {
        if ($val instanceof Renderable) {
            if (in_array($val, $GLOBALS['system_render_object_tree_stack'])) {
                log_debug("XREF in object tree! Object already rendered elsewhere:", $val);
                continue;
            }
            $GLOBALS['system_render_object_tree_stack'][] = $val;
            $res[$key] = $val->WdfRender();
        } elseif (is_array($val)) {
            $res[$key] = system_render_object_tree($val);
        } elseif ($val instanceof DateTime) {
            $res[$key] = $val->format("Y-m-d H:i:s");
        } else {
            $res[$key] = system_encode_for_output($val, true);
        }
    }
    return $res;
}