Example #1
0
 public function render()
 {
     //-------------------------------------------------------------
     // No Render?
     //-------------------------------------------------------------
     if ($this->get_data('no-render') || defined('POFW_SKIP_RENDER') && POFW_SKIP_RENDER) {
         return true;
     }
     //-------------------------------------------------------------
     // JavaScript / CSS Add-in Files
     //-------------------------------------------------------------
     if (!empty($this->js_files)) {
         $this->set_data('js_files', $this->js_files);
     }
     if (!empty($this->css_files)) {
         $this->set_data('css_files', $this->css_files);
     }
     //-------------------------------------------------------------
     // Escape Data (or not)
     //-------------------------------------------------------------
     if ($this->data_format == 'xml') {
         foreach ($this->data as $dkey => &$dval) {
             if (!isset($this->no_escape_elements[$dkey])) {
                 $dval = xml_escape_array($dval);
             }
         }
     }
     //-------------------------------------------------------------
     // Create Data
     //-------------------------------------------------------------
     if ($this->data_format == 'xml') {
         $data = array2xml($this->root_node, $this->data);
     } else {
         if ($this->data_format == 'json') {
             $data = json_encode($this->data);
         } else {
             $data = $this->data;
         }
     }
     //-------------------------------------------------------------
     // Output
     //-------------------------------------------------------------
     if ($this->show_data_only) {
         if (is_array($data)) {
             print_array($data);
         } else {
             print $data;
         }
         return true;
     } else {
         $render_function = $this->get_data('render-function');
         //----------------------------------------------------
         // XML
         //----------------------------------------------------
         if ($this->data_format == 'xml') {
             if ($render_function) {
                 return $render_function($data, $this->template);
             } else {
                 if (file_exists($this->template)) {
                     return xml_transform($data, $this->template);
                 } else {
                     if (empty($this->template)) {
                         print "No template file has been specified.";
                     } else {
                         print "Invalid template file specified.";
                     }
                 }
             }
         } else {
             if ($render_function) {
                 return $render_function($data, $this->template);
             } else {
                 print "No valid render function was specified.";
             }
         }
     }
     return false;
 }
Example #2
0
 public function display_fail_messages($xsl = false)
 {
     $xsl = trim((string) $xsl);
     //--------------------------------------------------------
     // Explicitly use the "default" template that comes
     // with phpOpenFW
     //--------------------------------------------------------
     if (strtolower($xsl) == 'default') {
         $this->xsl = $this->xsl_default;
     } else {
         if (!empty($xsl) && file_exists($xsl)) {
             $this->xsl = $xsl;
         } else {
             if (!empty($_SESSION['ssv_template']) && file_exists($_SESSION['ssv_template'])) {
                 $this->xsl = $_SESSION['ssv_template'];
             }
         }
     }
     //--------------------------------------------------------
     // Everything else uses the default template
     //--------------------------------------------------------
     // ..
     //--------------------------------------------------------
     // Create XML
     //--------------------------------------------------------
     $xml = array2xml('failed_checks', $this->fail_messages());
     //--------------------------------------------------------
     // Transform
     //--------------------------------------------------------
     xml_transform($xml, $this->xsl);
 }
Example #3
0
 public function content_constructor()
 {
     $this->content_xml = array();
     //============================================================
     // Pre-module Include Script (pre_module.inc.php)
     //============================================================
     $pre_mod_inc = "{$this->file_path}/{$this->mods_dir}/pre_module.inc.php";
     if (file_exists($pre_mod_inc)) {
         require_once $pre_mod_inc;
     }
     //============================================================
     // Was the intended module controller found?
     //============================================================
     $this->content_xml[] = new gen_element('mod_controller_found', $this->mod_controller_found);
     //============================================================
     // Current Module Parameters
     //============================================================
     $this->content_xml[] = new gen_element('current_module', $this->mod);
     if ($this->mod == '-1') {
         $tmp_mod_args = array('-1');
     } else {
         $ex_chr = $this->nav_xml_format == 'rewrite' ? '/' : '-';
         $tmp_mod_args = explode($ex_chr, $this->mod);
     }
     //============================================================
     // Current Module Depth
     //============================================================
     $curr_mod_depth = count($tmp_mod_args);
     $this->content_xml[] = new gen_element('current_module_depth', $curr_mod_depth);
     //============================================================
     // Current Module Arguments
     //============================================================
     $tmp = new gen_element('current_module_args');
     $tmp->display_tree();
     foreach ($tmp_mod_args as $key => $arg) {
         $index_key = $key + 1;
         $tmp->add_child(new gen_element('module_arg', $arg, array('index' => $index_key)));
     }
     $this->content_xml[] = $tmp;
     //============================================================
     // Start Content Block
     //============================================================
     $content_node = new gen_element('content');
     $content_node->display_tree();
     //============================================================
     // Section Title
     //============================================================
     $local_inc = $this->local_file_path . 'local.inc.php';
     if (file_exists($local_inc)) {
         include $local_inc;
     }
     if (isset($mod_title)) {
         $tmp2 = new gen_element('section_title');
         $tmp2->display_tree();
         $tmp2->add_child(new gen_element('linkhref', $this->page_url));
         $tmp2->add_child(new gen_element('desc', $mod_title));
         $content_node->add_child($tmp2);
     }
     //============================================================
     // Controller Exists
     //============================================================
     if (file_exists($this->mod_controller)) {
         //--------------------------------------------------------
         // Module Exists
         //--------------------------------------------------------
         $content_node->add_child(new gen_element('controller_exists', 1));
         define('CONTROLLER_EXISTS', true);
         //--------------------------------------------------------
         // Set $_GET and $_POST arrays to local variables
         // GET first, then POST to prevent GET variables over writing POST variables
         //--------------------------------------------------------
         extract($_GET, EXTR_PREFIX_SAME, "GET_");
         extract($_POST, EXTR_PREFIX_SAME, "POST_");
         //--------------------------------------------------------
         // Include local controller
         //--------------------------------------------------------
         ob_start();
         if (!$this->skip_mod_controller) {
             require_once $this->mod_controller;
         }
         //--------------------------------------------------------
         // Perform an XML Transformation if necessary
         //--------------------------------------------------------
         if (isset($this->content_xsl) && !empty($this->content_xsl)) {
             $tmp_xml = ob_get_clean();
             ob_start();
             xml_transform($tmp_xml, $this->content_xsl);
         }
         $tmp_content = ob_get_clean();
         $content_node->add_child(new gen_element('content_data', xml_escape($tmp_content)));
         $this->content_xml[] = $content_node;
     } else {
         $content_node->add_child(new gen_element('controller_exists', 0));
         define('CONTROLLER_EXISTS', false);
     }
     //============================================================
     // Post-module Include Script (post_module.inc.php)
     //============================================================
     $post_mod_inc = "{$this->file_path}/{$this->mods_dir}/post_module.inc.php";
     if (file_exists($post_mod_inc)) {
         require_once $post_mod_inc;
     }
 }
Example #4
0
 public function render($buffer = false)
 {
     if ($buffer) {
         ob_start();
     }
     $el_cont = '';
     // Tabs
     $tabs = '';
     for ($i = 0; $i < $this->tabs; $i++) {
         $tabs .= "\t";
     }
     //***************************************
     // Child Nodes OR Inset Text
     //***************************************
     if ($this->child_nodes) {
         // Child Nodes
         foreach ($this->child_nodes as $node) {
             if (is_object($node) && get_class($node) == 'gen_element') {
                 $node->set_tabs($this->tabs + 1);
             }
             $el_cont .= $node;
         }
     } else {
         if ($this->inset_val !== false && $this->inset_val !== '') {
             // Inset Value
             $el_cont .= $this->style == 'tree' ? "\t{$tabs}" . $this->inset_val . "\n" : $this->inset_val;
         }
     }
     //***************************************
     // Opening Tag
     //***************************************
     $this->element_xml = "{$tabs}<{$this->element}";
     if (isset($this->attributes)) {
         foreach ($this->attributes as $key => $value) {
             $this->element_xml .= " {$key}=\"{$value}\"";
         }
     }
     //***************************************
     // Build Closing Tag
     //***************************************
     $close_tag = "</{$this->element}>\n";
     if ($this->style == 'tree') {
         $close_tag = $tabs . $close_tag;
     }
     //***************************************
     // Content / Closing Tag
     //***************************************
     if ($el_cont !== false && $el_cont !== '') {
         if ($this->style == 'tree') {
             $this->element_xml .= ">\n" . $el_cont . $close_tag;
         } else {
             $this->element_xml .= '>' . $el_cont . $close_tag;
         }
     } else {
         if ($this->endtag) {
             $this->element_xml .= ">{$close_tag}";
         } else {
             $this->element_xml .= " />\n";
         }
     }
     //***************************************
     // Perform XML Transformation
     //***************************************
     $sxoe = isset($_SESSION['show_xml_on_error']) && $_SESSION['show_xml_on_error'] == 1 ? true : false;
     xml_transform($this->element_xml, $this->xsl_template, $sxoe);
     if ($buffer) {
         return ob_get_clean();
     }
 }
Example #5
0
 public function render($buffer = false)
 {
     //---------------------------------------------------
     // Buffer?
     //---------------------------------------------------
     if ((bool) $buffer) {
         ob_start();
     }
     //---------------------------------------------------
     // Data Order
     //---------------------------------------------------
     $order = array();
     foreach ($this->data_outline as $key => $val) {
         array_push($order, $key);
     }
     //---------------------------------------------------
     // Start Table Buffering if NOT Grouping
     //---------------------------------------------------
     ob_start();
     if (!$this->group_by) {
         $table_label = $this->label;
         ob_start();
     }
     //---------------------------------------------------
     // Loop Through Rows
     //---------------------------------------------------
     $row_count = 0;
     $gbv = NULL;
     foreach ($this->record_set as $row_key => $row) {
         //---------------------------------------------------
         // Set row_key to string
         //---------------------------------------------------
         settype($row_key, 'string');
         //---------------------------------------------------
         // Start Group By Table (if group_by being used)
         //---------------------------------------------------
         if ($this->group_by && isset($row[$this->group_by]) && $gbv !== $row[$this->group_by]) {
             //---------------------------------------------------
             // End Current Table
             //---------------------------------------------------
             if (!is_null($gbv)) {
                 print $this->table(ob_get_clean(), $table_label, $row_count);
             }
             //---------------------------------------------------
             // Start New Table
             //---------------------------------------------------
             ob_start();
             $table_label = isset($this->group_by_vals[$row[$this->group_by]]) ? $this->group_by_vals[$row[$this->group_by]] : $row[$this->group_by];
             $row_count = 0;
             $gbv = $row[$this->group_by];
         }
         //---------------------------------------------------
         // Start Row Content
         //---------------------------------------------------
         ob_start();
         //---------------------------------------------------
         // Loop through Row Cells
         //---------------------------------------------------
         $cell_count = 0;
         foreach ($order as $key => $val) {
             //---------------------------------------------------
             // Print Cell
             //---------------------------------------------------
             print $this->body_cell($row_key, $val, $row[$val]);
             $cell_count++;
         }
         //---------------------------------------------------
         // Print Row
         //---------------------------------------------------
         print $this->body_row($row_key, $row_count, ob_get_clean());
         $row_count++;
     }
     //---------------------------------------------------
     // End Table
     //---------------------------------------------------
     print $this->table(ob_get_clean(), $table_label, $row_count);
     $this->xml = ob_get_clean();
     //---------------------------------------------------
     // Table Group
     //---------------------------------------------------
     if ($this->group_by) {
         $this->xml = xhe('table_group', $this->xml);
     }
     //---------------------------------------------------
     // Perform XML Transformation
     //---------------------------------------------------
     $sxoe = !empty($_SESSION['show_xml_on_error']) ? true : false;
     xml_transform($this->xml, $this->xsl_template, $sxoe);
     //---------------------------------------------------
     // Buffer? Return Content
     //---------------------------------------------------
     if ($buffer) {
         return ob_get_clean();
     }
 }
Example #6
0
 protected function render()
 {
     //===========================================================
     // Skip the Render Process?
     //===========================================================
     if ($this->skip_render || defined('POFW_SKIP_RENDER') && POFW_SKIP_RENDER) {
         return false;
     }
     //===========================================================
     // Set Master XSL Template File
     //===========================================================
     if (!$this->xsl_template) {
         $xslt_stylesheet = "{$this->templates_dir}/{$this->page_type}.xsl";
         $this->set_xsl_template($xslt_stylesheet);
     }
     //===========================================================
     // Start Page
     //===========================================================
     $page = new gen_element('page');
     $page->display_tree();
     //===========================================================
     // Start Page and set basic values
     //===========================================================
     $page->add_child(new gen_element('html_path', $this->html_path));
     $page->add_child(new gen_element('page_type', $this->page_type));
     //===========================================================
     // CSS files
     //===========================================================
     $tmp = new gen_element('css_files');
     $tmp->display_tree();
     foreach ($this->css_files as $file_attrs) {
         $tmp2 = new gen_element('css_file');
         $tmp2->display_tree();
         foreach ($file_attrs as $attr_key => $attr_val) {
             $tmp3 = new gen_element($attr_key, $attr_val);
             $tmp2->add_child($tmp3);
         }
         $tmp->add_child($tmp2);
     }
     $page->add_child($tmp);
     //===========================================================
     // Theme CSS files
     //===========================================================
     if ($this->theme_css_files) {
         $tmp = new gen_element('theme_css_files');
         $tmp->display_tree();
         foreach ($this->theme_css_files as $file_attrs) {
             $tmp2 = new gen_element('theme_css_file');
             $tmp2->display_tree();
             foreach ($file_attrs as $attr_key => $attr_val) {
                 $tmp3 = new gen_element($attr_key, $attr_val);
                 $tmp2->add_child($tmp3);
             }
             $tmp->add_child($tmp2);
         }
         $page->add_child($tmp);
     }
     //===========================================================
     // Javascript files
     //===========================================================
     $tmp = new gen_element('js_files');
     $tmp->display_tree();
     foreach ($this->js_files as $js_file) {
         $tmp->add_child(new gen_element('js_file', $js_file));
     }
     $page->add_child($tmp);
     //===========================================================
     // Theme Javascript files
     //===========================================================
     if ($this->theme_js_files) {
         $tmp = new gen_element('theme_js_files');
         $tmp->display_tree();
         foreach ($this->theme_js_files as $js_file) {
             $tmp->add_child(new gen_element('theme_js_file', $js_file));
         }
         $page->add_child($tmp);
     }
     //===========================================================
     // Copyright
     //===========================================================
     $curr_year = date('Y');
     $page->add_child(new gen_element('copyright', "{$curr_year} {$this->creator}"));
     //===========================================================
     // Account Name
     //===========================================================
     if ($this->account_name) {
         $page->add_child(new gen_element('account_name', $this->account_name));
     }
     //===========================================================
     // Site XML
     //===========================================================
     if ($this->site_xml) {
         if (is_array($this->site_xml)) {
             $tmp_site_xml = array2xml('site_data', $this->site_xml);
             $page->add_child("{$tmp_site_xml}\n");
         } else {
             $page->add_child(new gen_element('site_data', $this->site_xml));
         }
     }
     //===========================================================
     // Application XML
     //===========================================================
     if (count($this->app_xml) > 0) {
         $tmp = new gen_element('application_data');
         $tmp->display_tree();
         foreach ($this->app_xml as $xml_line) {
             if (is_array($xml_line[1])) {
                 $new_xml_line = array2xml($xml_line[0], $xml_line[1]);
                 $tmp->add_child("{$new_xml_line}\n");
             } else {
                 $tmp->add_child(new gen_element($xml_line[0], $xml_line[1]));
             }
         }
         $page->add_child($tmp);
     }
     //===========================================================
     // If Logged in
     //===========================================================
     if (isset($_SESSION['userid'])) {
         // User Info
         $tmp = new gen_element('user');
         $tmp->display_tree();
         $tmp->add_child(new gen_element('userid', $_SESSION['userid']));
         if (!isset($_SESSION['name'])) {
             $_SESSION['name'] = '';
         }
         $tmp->add_child(new gen_element('name', xml_escape($_SESSION['name'])));
         $page->add_child($tmp);
         // Special links (logout)
         $exit_phrase = 'Logout';
         if ($_SESSION['auth_data_type'] == 'none') {
             $exit_phrase = 'Quit';
         }
         $tmp = new gen_element('userlinks');
         $tmp->display_tree();
         $tmp2 = new gen_element('link');
         $tmp2->display_tree();
         $tmp2->add_child(new gen_element('linkdesc', $exit_phrase));
         $tmp2->add_child(new gen_element('linkhref', "{$this->html_path}/?mod=logout"));
         $tmp->add_child($tmp2);
         $page->add_child($tmp);
     }
     //===========================================================
     // Menu
     //===========================================================
     if (isset($this->menu_xml)) {
         $page->add_child($this->menu_xml);
     }
     //===========================================================
     // Content
     //===========================================================
     if (isset($this->content_xml) && is_array($this->content_xml) && $this->content_xml) {
         foreach ($this->content_xml as $node) {
             $page->add_child($node);
         }
     }
     //===========================================================
     // Render Page
     //===========================================================
     $this->page_xml = $page;
     //===========================================================
     // Determine output type
     //===========================================================
     if ($this->output_type == 'xml') {
         $this->xsl_template = '';
     }
     //===========================================================
     // Transform the page content
     //===========================================================
     ob_start();
     $sxoe = isset($_SESSION['show_xml_on_error']) && $_SESSION['show_xml_on_error'] == 1 ? true : false;
     xml_transform($this->page_xml, $this->xsl_template, $sxoe);
     $page_content = ob_get_clean();
     //===========================================================
     // Finally!! Output the results!!
     //===========================================================
     echo $page_content;
     //===========================================================
     // Post-page Include Script (post_page.inc.php)
     //===========================================================
     $post_page_inc = "{$this->file_path}/{$this->mods_dir}/post_page.inc.php";
     if (file_exists($post_page_inc)) {
         require_once $post_page_inc;
     }
 }