Пример #1
0
 function Init($args, $locations)
 {
     foreach ($args as $k => $v) {
         $this->{$k} = $v;
     }
     if (!empty($args["name"]) && !empty($args["component"]) && !isset(self::$templates[$args["name"]])) {
         self::$templates[$args["name"]] = ComponentManager::fetch($args["component"], $args["componentargs"]);
         DependencyManager::add(array("type" => "component", "name" => "tplmgr.tplmgr", "priority" => 2));
     }
 }
Пример #2
0
 public function controller_404($args, $output = "inline")
 {
     if ($output == "inline") {
         $componentname = any(ConfigManager::get("page.missing"), NULL);
     } else {
         $componentname = any(ConfigManager::get("page.404"), NULL);
     }
     if (!empty($componentname)) {
         return ComponentManager::fetch($componentname, $args, $output);
     }
     return $this->GetComponentResponse("./404.tpl", $args);
 }
Пример #3
0
 function controller_componentdetails($args)
 {
     $vars["root"] = any($args["root"], true);
     $vars["id"] = any($args["id"], false);
     if (!empty($args["component"])) {
         $components = ComponentManager::fetch("utils.componentlist", array("tree" => true), "data");
         $key = str_replace(".", ".components.", $args["component"]);
         $vars["component"] = array_get($components["components"], $key);
         $vars["componentargs"] = any($args["componentargs"], array());
         $vars["events"] = any($args["events"], array());
     }
     return $this->GetComponentResponse("./componentdetails.tpl", $vars);
 }
Пример #4
0
 function getOutput($type)
 {
     $ret = array("text/html", NULL);
     $tplmgr = TemplateManager::singleton();
     switch ($type) {
         case 'ajax':
             $ret = array("application/xml", $tplmgr->GenerateXML($this->data));
             break;
         case 'json':
         case 'jsonp':
             $jsonp = any($_REQUEST["jsonp"], "elation.ajax.processResponse");
             //$ret = array("application/javascript", $jsonp . "(" . json_encode($this->data) . ");");
             $ret = array("application/javascript", $tplmgr->GenerateJavascript($this->data, $jsonp));
             break;
         case 'js':
             $ret = array("application/javascript", @json_encode($this) . "\n");
             break;
         case 'jsi':
             $ret = array("application/javascript", json_indent(@json_encode($this)) . "\n");
             break;
         case 'txt':
             $ret = array("text/plain", $tplmgr->GenerateHTML($tplmgr->GetTemplate($this->template, NULL, $this->data)));
             break;
         case 'xml':
             $ret = array("application/xml", object_to_xml($this, "response"));
             break;
         case 'data':
             $ret = array("", $this->data);
             break;
         case 'componentresponse':
             $ret = array("", $this);
             break;
         case 'popup':
             // Popup is same as HTML, but we only use the bare-minimum html.page frame
             $vars["content"] = $this;
             $ret = array("text/html", ComponentManager::fetch("html.page", $vars, "inline"));
             break;
         case 'snip':
         case 'inline':
         case 'commandline':
             $ret = array("text/html", $tplmgr->GetTemplate($this->template, NULL, $this->data));
             break;
         case 'html':
         case 'fhtml':
         default:
             $cfg = ConfigManager::singleton();
             $framecomponent = any(ConfigManager::get("page.frame"), array_get($cfg->servers, "page.frame"), "html.page");
             // If framecomponent is false/0, just return the raw content
             $ret = array("text/html", empty($framecomponent) ? $this->data["content"] : ComponentManager::fetch($framecomponent, array("content" => $this), "inline"));
             //$ret = array("text/html", $tplmgr->GetTemplate($this->template, NULL, $this->data));
             break;
     }
     if (!empty($this->prefix)) {
         $ret[1] = $this->prefix . $ret[1];
     }
     return $ret;
 }
Пример #5
0
 function PostProcess(&$output, $simpledebug = false)
 {
     global $webapp;
     Profiler::StartTimer("TemplateManager::PostProcess()");
     $matchregex = "/\\[\\[(\\w[^\\[\\]{}:|]*)(?:[:|](.*?))?\\]\\]/";
     if (!is_array($output)) {
         // FIXME - we should probably still postprocess if we're returning XML
         if (preg_match_all($matchregex, $output, $matches, PREG_SET_ORDER)) {
             $search = $replace = array();
             foreach ($matches as $m) {
                 $search[] = $m[0];
                 $replace[] = !empty($this->varreplace[$m[1]]) ? htmlspecialchars($this->varreplace[$m[1]]) : (!empty($m[2]) ? $m[2] : "");
             }
             $pos = array_search("[[debug]]", $search);
             if ($pos !== false) {
                 // if there are errors, check for access and force debug
                 $show_debug = $webapp->debug;
                 /*
                 if (Logger::hasErrors()) {
                   $user = User::singleton();
                   if ($user->HasRole("DEBUG") || $user->HasRole("ADMIN") || $user->HasRole("QA")) {
                     $show_debug = true;
                   }
                 }
                 */
                 if ($show_debug) {
                     //$replace[$pos] = $this->GetTemplate("debug.tpl");
                     $replace[$pos] = $simpledebug ? Logger::Display(E_ALL) : ComponentManager::fetch("elation.debug");
                 } else {
                     $replace[$pos] = "";
                 }
             }
             if (($pos = array_search("[[dependencies]]", $search)) !== false) {
                 $replace[$pos] = DependencyManager::display();
                 // Sometimes dependencies also use postprocessing variables, so parse those and add them to the list too
                 // FIXME - could be cleaner, this is copy-pasta of the first parsing pass above
                 if (preg_match_all($matchregex, $replace[$pos], $submatches, PREG_SET_ORDER)) {
                     foreach ($submatches as $sm) {
                         $search[] = $sm[0];
                         $replace[] = !empty($this->varreplace[$sm[1]]) ? htmlspecialchars($this->varreplace[$sm[1]]) : (!empty($sm[2]) ? $sm[2] : "");
                     }
                 }
             }
             $output = str_replace($search, $replace, $output);
         }
     }
     Profiler::StopTimer("TemplateManager::PostProcess()");
     return $output;
 }
Пример #6
0
 function controller_panel($args, $output = "inline")
 {
     $ret = "";
     $selected = $args["selected"];
     $vars["placement"] = $args["placement"];
     // FIXME - we currently don't do anything with placements
     $vars["panel"]["parent"] = any($args["parent"], "");
     if (!empty($vars["panel"]["parent"]) && !empty($args["panelname"])) {
         $vars["panel"]["name"] = $vars["panel"]["parent"] . "." . $args["panelname"];
     } else {
         $vars["panel"]["name"] = $args["type"];
     }
     $vars["panel"]["cfg"] = $this->PanelSort(any($args["panel"], ConfigManager::get("panels.types.{$vars["panel"]["name"]}")));
     $vars["panel"]["id"] = any($args["id"], $vars["panel"]["cfg"]["id"], "tf_utils_panel_" . str_replace(".", "_", $vars["panel"]["name"]));
     $vars["panel"]["type"] = any($args["type"], "panel");
     $vars["panel"]["enabled"] = any($args["enabled"], isset($vars["panel"]["cfg"]["enabled"]) ? $vars["panel"]["cfg"]["enabled"] : true);
     $vars["panel"]["args"] = any($args["panelargs"], array());
     $vars["panel"]["info"] = array("type", $vars["panel"]["type"], "id" => $vars["panel"]["id"], "name" => $vars["panel"]["name"]);
     $vars["panel"]["json_include"] = any($args["json_include"], $vars["panel"]["cfg"]["json_include"], 0);
     $vars["panel"]["json_only"] = any($args["json_only"], $vars["panel"]["cfg"]["json_only"], 0);
     $vars["panel"]["noclear"] = any($vars["panel"]["cfg"]["noclear"], 0);
     $items = $vars["panel"]["cfg"]["items"];
     // If the apicomponent option is set for this panel, execute the specified component
     if (!empty($vars["panel"]["cfg"]["apicomponent"])) {
         $apicomponentargs = array_merge_recursive(any($vars["panel"]["cfg"]["apicomponentargs"], array()), $args);
         if ($output != "html" && $output != "inline" && $output != "popup" && $output != "snip") {
             $ret = ComponentManager::fetch($vars["panel"]["cfg"]["apicomponent"], $apicomponentargs, $output);
         } else {
             $vars["apicomponentoutput"] = ComponentManager::fetch($vars["panel"]["cfg"]["apicomponent"], $apicomponentargs, "data");
         }
     }
     if ($selected && $items[$selected]) {
         foreach ($items as $k => $v) {
             unset($items[$k]["selected"]);
         }
         $items[$selected]["selected"] = "true";
         $vars["panel"]["cfg"]["items"] = $items;
         //print_pre($items);
     }
     if ($args['uid']) {
         $vars['panel']['uid'] = $args['uid'];
         $vars['panel']['cfg']['targetid'] = $vars['panel']['cfg']['targetid'] . '_' . $args['uid'];
     }
     if ($output == "ajax") {
         $ret = array();
         $ajaxpanels = self::PanelFilterAjax($vars["panel"]["cfg"]);
         foreach ($ajaxpanels as $k => $p) {
             if ($p["component"] == "utils.panel") {
                 // Execute subpanels as AJAX requests and merge their results in with ours
                 $subret = ComponentManager::fetch($p["component"], $p["componentargs"], "ajax");
                 $ret = array_merge($ret, $subret);
             } else {
                 $ret[$vars["panel"]["id"] . "_" . $k] = ComponentManager::fetch($p["component"], $p["componentargs"]);
             }
         }
     } else {
         if (empty($ret)) {
             if (!empty($vars["panel"]["enabled"])) {
                 $ret = $this->GetTemplate("./panel.tpl", $vars);
             }
         }
     }
     return $ret;
 }
Пример #7
0
 public function controller_header($args)
 {
     $cfg = ConfigManager::singleton();
     $header = ConfigManager::get("page.header", array_get($cfg->servers, "page.header"), null);
     if (!empty($header)) {
         return ComponentManager::fetch($header);
     } else {
         if ($header !== null) {
             return "";
         }
     }
     return $this->GetComponentResponse("./header.tpl", $vars);
 }
Пример #8
0
 function HandlePayload(&$args, $output = "inline")
 {
     /*
     if (($path = file_exists_in_path("templates/404.tpl", true)) !== false) {
       return $this->GetTemplate($path . "/templates/404.tpl", $this);
     }
     return $this->GetTemplate("404.tpl", $this);
     */
     return ComponentManager::fetch("elation.404", array("name" => $this->fullname), $output);
 }
Пример #9
0
 /**
  * Renders the form. If $context is null or a Zend_View it'll render it
  * normally. Otherwise, it passes the form object to a component for further
  * processing. Note, even if passed to a second controller, it's still 
  * possible to render the form in traditional Zend style with {$form}
  * 
  * @param object $context [optional]
  * @param object $args [optional]
  * @return string HTML output
  */
 public function render($context = NULL, $args = array())
 {
     if ($context == NULL) {
         $context = new Zend_View();
     }
     if ($context instanceof Zend_View_Interface) {
         return parent::render($context);
     } else {
         $args = array_merge($args, array('form' => $this));
         $componentOutput = ComponentManager::fetch($context, $args);
         return $componentOutput;
     }
 }