/** * Returns the HTML output from a template, but doesn't render it * * @param string $template the template name * @param array $params template parameters * * @return boolean */ public static function returnTemplateHTML($template, $params = array()) { $current_content = ob_get_clean(); ob_start(); echo TBGActionComponent::includeTemplate($template, $params); $template_content = ob_get_clean(); ob_start(); echo $current_content; return $template_content; }
/** * Includes a component with specified parameters * * @param string $component name of component to load, or module/component to load * @param array $params key => value pairs of parameters for the template */ function include_component($component, $params = array()) { return TBGActionComponent::includeComponent($component, $params); }
public function listen_quicksearchDropdownFoundItems(TBGEvent $event) { $searchterm = $event->getSubject(); list($resultcount, $articles) = TBGWikiArticle::findByArticleNameAndProject($searchterm, TBGContext::getCurrentProject()); TBGActionComponent::includeTemplate('publish/quicksearch_dropdown_founditems', array('searchterm' => $searchterm, 'articles' => $articles, 'resultcount' => $resultcount)); }
public function listen_viewissue_panel(TBGEvent $event) { if (TBGContext::getModule('vcs_integration')->getSetting('vcs_mode_' . TBGContext::getCurrentProject()->getID()) == TBGVCSIntegration::MODE_DISABLED) { return; } $links = TBGVCSIntegrationIssueLink::getCommitsByIssue($event->getSubject()); TBGActionComponent::includeTemplate('vcs_integration/viewissue_commits', array('links' => $links, 'projectId' => $event->getSubject()->getProject()->getID())); }
/** * Performs an action * * @param string $action Name of the action * @param string $method Name of the action method to run */ public static function performAction($action, $method) { // Set content variable $content = null; // Set the template to be used when rendering the html (or other) output $templatePath = THEBUGGENIE_MODULES_PATH . $action . DS . 'templates' . DS; // Construct the action class and method name, including any pre- action(s) $actionClassName = $action . 'Actions'; $actionToRunName = 'run' . ucfirst($method); $preActionToRunName = 'pre' . ucfirst($method); // Set up the response object, responsible for controlling any output self::getResponse()->setPage(self::getRouting()->getCurrentRouteName()); self::getResponse()->setTemplate(strtolower($method) . '.' . TBGContext::getRequest()->getRequestedFormat() . '.php'); self::getResponse()->setupResponseContentType(self::getRequest()->getRequestedFormat()); self::setCurrentProject(null); // Set up the action object $actionObject = new $actionClassName(); // Run the specified action method set if it exists if (method_exists($actionObject, $actionToRunName)) { // Turning on output buffering ob_start(); ob_implicit_flush(0); if (self::getRouting()->isCurrentRouteCSRFenabled()) { // If the csrf check fails, don't proceed if (!self::checkCSRFtoken(true)) { return true; } } if (self::$debug_mode) { $time = explode(' ', microtime()); $pretime = $time[1] + $time[0]; } if ($content === null) { TBGLogging::log('Running main pre-execute action'); // Running any overridden preExecute() method defined for that module // or the default empty one provided by TBGAction if ($pre_action_retval = $actionObject->preExecute(self::getRequest(), $method)) { $content = ob_get_clean(); TBGLogging::log('preexecute method returned something, skipping further action'); if (self::$debug_mode) { $visited_templatename = "{$actionClassName}::preExecute()"; } } } if ($content === null) { $action_retval = null; if (self::getResponse()->getHttpStatus() == 200) { // Checking for and running action-specific preExecute() function if // it exists if (method_exists($actionObject, $preActionToRunName)) { TBGLogging::log('Running custom pre-execute action'); $actionObject->{$preActionToRunName}(self::getRequest(), $method); } // Running main route action TBGLogging::log('Running route action ' . $actionToRunName . '()'); if (self::$debug_mode) { $time = explode(' ', microtime()); $action_pretime = $time[1] + $time[0]; } $action_retval = $actionObject->{$actionToRunName}(self::getRequest()); if (self::$debug_mode) { $time = explode(' ', microtime()); $action_posttime = $time[1] + $time[0]; TBGContext::visitPartial("{$actionClassName}::{$actionToRunName}", $action_posttime - $action_pretime); } } if (self::getResponse()->getHttpStatus() == 200 && $action_retval) { // If the action returns *any* output, we're done, and collect the // output to a variable to be outputted in context later $content = ob_get_clean(); TBGLogging::log('...done'); } elseif (!$action_retval) { // If the action doesn't return any output (which it usually doesn't) // we continue on to rendering the template file for that specific action TBGLogging::log('...done'); TBGLogging::log('Displaying template'); // Check to see if we have a translated version of the template if (($templateName = self::getI18n()->hasTranslatedTemplate(self::getResponse()->getTemplate())) === false) { // Check to see if the template has been changed, and whether it's in a // different module, specified by "module/templatename" if (strpos(self::getResponse()->getTemplate(), '/')) { $newPath = explode('/', self::getResponse()->getTemplate()); $templateName = THEBUGGENIE_MODULES_PATH . $newPath[0] . DS . 'templates' . DS . $newPath[1] . '.' . TBGContext::getRequest()->getRequestedFormat() . '.php'; } else { $templateName = $templatePath . self::getResponse()->getTemplate(); } } // Check to see if the template exists and throw an exception otherwise if (!file_exists($templateName)) { TBGLogging::log('The template file for the ' . $method . ' action ("' . self::getResponse()->getTemplate() . '") does not exist', 'core', TBGLogging::LEVEL_FATAL); throw new TBGTemplateNotFoundException('The template file for the ' . $method . ' action ("' . self::getResponse()->getTemplate() . '") does not exist'); } self::loadLibrary('common'); // Present template for current action TBGActionComponent::presentTemplate($templateName, $actionObject->getParameterHolder()); $content = ob_get_clean(); TBGLogging::log('...completed'); } } elseif (self::$debug_mode) { $time = explode(' ', microtime()); $posttime = $time[1] + $time[0]; TBGContext::visitPartial($visited_templatename, $posttime - $pretime); } if (!isset($tbg_response)) { /** * @global TBGRequest The request object */ $tbg_request = self::getRequest(); /** * @global TBGUser The user object */ $tbg_user = self::getUser(); /** * @global TBGResponse The action object */ $tbg_response = self::getResponse(); // Load the "ui" library, since this is used a lot self::loadLibrary('ui'); } self::loadLibrary('common'); // Render header template if any, and store the output in a variable ob_start(); ob_implicit_flush(0); if (!self::getRequest()->isAjaxCall() && self::getResponse()->doDecorateHeader()) { TBGLogging::log('decorating with header'); if (!file_exists(self::getResponse()->getHeaderDecoration())) { throw new TBGTemplateNotFoundException('Can not find header decoration: ' . self::getResponse()->getHeaderDecoration()); } require self::getResponse()->getHeaderDecoration(); $decoration_header = ob_get_clean(); } // Set up the run summary, and store it in a variable ob_start(); ob_implicit_flush(0); $load_time = self::getLoadtime(); if (B2DB::isInitialized()) { $tbg_summary['db_queries'] = B2DB::getSQLHits(); $tbg_summary['db_timing'] = B2DB::getSQLTiming(); } $tbg_summary['load_time'] = $load_time >= 1 ? round($load_time, 2) . ' seconds' : round($load_time * 1000, 1) . 'ms'; $tbg_summary['scope_id'] = self::getScope() instanceof TBGScope ? self::getScope()->getID() : 'unknown'; self::ping(); // Render footer template if any, and store the output in a variable if (!self::getRequest()->isAjaxCall() && self::getResponse()->doDecorateFooter()) { TBGLogging::log('decorating with footer'); require self::getResponse()->getFooterDecoration(); $decoration_footer = ob_get_clean(); } TBGLogging::log('...done'); TBGLogging::log('rendering content'); // Render output in correct order self::getResponse()->renderHeaders(); if (isset($decoration_header)) { echo $decoration_header; } echo $content; if (isset($decoration_footer)) { echo $decoration_footer; } TBGLogging::log('...done (rendering content)'); if (self::isDebugMode()) { self::getI18n()->addMissingStringsToStringsFile(); } return true; } else { TBGLogging::log("Cannot find the method {$actionToRunName}() in class {$actionClassName}.", 'core', TBGLogging::LEVEL_FATAL); throw new TBGActionNotFoundException("Cannot find the method {$actionToRunName}() in class {$actionClassName}. Make sure the method exists."); } }
?> </label></td> <td><input type="text" class="required" id="email_address" name="email_address" style="width: 200px;"></td> </tr> <tr> <td><label class="login_fieldheader" for="email_confirm">* <?php echo __('Confirm e-mail'); ?> </label></td> <td><input type="text" class="required" id="email_confirm" name="email_confirm" style="width: 200px;"></td> </tr> </table> <br> <?php TBGActionComponent::includeComponent('captcha'); ?> <br><b><?php echo __('Enter the above number in this box'); ?> </b><br><br> <label class="login_fieldheader" for="verification_no">* <?php echo __('Security check'); ?> </label> <input type="text" class="required" id="verification_no" name="verification_no" maxlength="6" style="width: 100px;"><br><br> <input type="submit" id="register2_button" value="<?php echo __('Register'); ?> ">
/** * Performs an action * * @param string $module Name of the action module * @param string $method Name of the action method to run */ public static function performAction($action, $module, $method) { // Set content variable $content = null; // Set the template to be used when rendering the html (or other) output $templatePath = THEBUGGENIE_MODULES_PATH . $module . DS . 'templates' . DS; $actionClassName = get_class($action); $actionToRunName = 'run' . ucfirst($method); $preActionToRunName = 'pre' . ucfirst($method); // Set up the response object, responsible for controlling any output self::getResponse()->setPage(self::getRouting()->getCurrentRouteName()); self::getResponse()->setTemplate(mb_strtolower($method) . '.' . TBGContext::getRequest()->getRequestedFormat() . '.php'); self::getResponse()->setupResponseContentType(self::getRequest()->getRequestedFormat()); self::setCurrentProject(null); // Run the specified action method set if it exists if (method_exists($action, $actionToRunName)) { // Turning on output buffering ob_start('mb_output_handler'); ob_implicit_flush(0); if (self::getRouting()->isCurrentRouteCSRFenabled()) { // If the csrf check fails, don't proceed if (!self::checkCSRFtoken(true)) { return true; } } if (self::$_debug_mode) { $time = explode(' ', microtime()); $pretime = $time[1] + $time[0]; } if ($content === null) { TBGLogging::log('Running main pre-execute action'); // Running any overridden preExecute() method defined for that module // or the default empty one provided by TBGAction if ($pre_action_retval = $action->preExecute(self::getRequest(), $method)) { $content = ob_get_clean(); TBGLogging::log('preexecute method returned something, skipping further action'); if (self::$_debug_mode) { $visited_templatename = "{$actionClassName}::preExecute()"; } } } if ($content === null) { $action_retval = null; if (self::getResponse()->getHttpStatus() == 200) { // Checking for and running action-specific preExecute() function if // it exists if (method_exists($action, $preActionToRunName)) { TBGLogging::log('Running custom pre-execute action'); $action->{$preActionToRunName}(self::getRequest(), $method); } // Running main route action TBGLogging::log('Running route action ' . $actionToRunName . '()'); if (self::$_debug_mode) { $time = explode(' ', microtime()); $action_pretime = $time[1] + $time[0]; } $action_retval = $action->{$actionToRunName}(self::getRequest()); if (self::$_debug_mode) { $time = explode(' ', microtime()); $action_posttime = $time[1] + $time[0]; TBGContext::visitPartial("{$actionClassName}::{$actionToRunName}", $action_posttime - $action_pretime); } } if (self::getResponse()->getHttpStatus() == 200 && $action_retval) { // If the action returns *any* output, we're done, and collect the // output to a variable to be outputted in context later $content = ob_get_clean(); TBGLogging::log('...done'); } elseif (!$action_retval) { // If the action doesn't return any output (which it usually doesn't) // we continue on to rendering the template file for that specific action TBGLogging::log('...done'); TBGLogging::log('Displaying template'); // Check to see if we have a translated version of the template if ($method != 'notFound' && (!self::isReadySetup() || ($templateName = self::getI18n()->hasTranslatedTemplate(self::getResponse()->getTemplate())) === false)) { // Check to see if any modules provide an alternate template $event = TBGEvent::createNew('core', "TBGContext::performAction::renderTemplate")->triggerUntilProcessed(array('class' => $actionClassName, 'action' => $actionToRunName)); if ($event->isProcessed()) { $templateName = $event->getReturnValue(); } // Check to see if the template has been changed, and whether it's in a // different module, specified by "module/templatename" if (mb_strpos(self::getResponse()->getTemplate(), '/')) { $newPath = explode('/', self::getResponse()->getTemplate()); $templateName = THEBUGGENIE_MODULES_PATH . $newPath[0] . DS . 'templates' . DS . $newPath[1] . '.' . TBGContext::getRequest()->getRequestedFormat() . '.php'; } else { $templateName = $templatePath . self::getResponse()->getTemplate(); } } // Check to see if the template exists and throw an exception otherwise if (!file_exists($templateName)) { TBGLogging::log('The template file for the ' . $method . ' action ("' . self::getResponse()->getTemplate() . '") does not exist', 'core', TBGLogging::LEVEL_FATAL); throw new TBGTemplateNotFoundException('The template file for the ' . $method . ' action ("' . self::getResponse()->getTemplate() . '") does not exist'); } self::loadLibrary('common'); // Present template for current action TBGActionComponent::presentTemplate($templateName, $action->getParameterHolder()); $content = ob_get_clean(); TBGLogging::log('...completed'); } } elseif (self::$_debug_mode) { $time = explode(' ', microtime()); $posttime = $time[1] + $time[0]; TBGContext::visitPartial($visited_templatename, $posttime - $pretime); } if (!isset($tbg_response)) { /** * @global TBGRequest The request object */ $tbg_request = self::getRequest(); /** * @global TBGUser The user object */ $tbg_user = self::getUser(); /** * @global TBGResponse The action object */ $tbg_response = self::getResponse(); // Load the "ui" library, since this is used a lot self::loadLibrary('ui'); } self::loadLibrary('common'); TBGLogging::log('rendering final content'); if (TBGSettings::isMaintenanceModeEnabled() && !mb_strstr(self::getRouting()->getCurrentRouteName(), 'configure')) { if (!file_exists(THEBUGGENIE_CORE_PATH . 'templates/offline.inc.php')) { throw new TBGTemplateNotFoundException('Can not find offline mode template'); } ob_start('mb_output_handler'); ob_implicit_flush(0); require THEBUGGENIE_CORE_PATH . 'templates/offline.inc.php'; $content = ob_get_clean(); } // Render output in correct order self::getResponse()->renderHeaders(); if (self::getResponse()->getDecoration() == TBGResponse::DECORATE_DEFAULT && !self::getRequest()->isAjaxCall()) { ob_start('mb_output_handler'); ob_implicit_flush(0); require THEBUGGENIE_CORE_PATH . 'templates/layout.php'; ob_flush(); } else { // Render header template if any, and store the output in a variable if (!self::getRequest()->isAjaxCall() && self::getResponse()->doDecorateHeader()) { TBGLogging::log('decorating with header'); if (!file_exists(self::getResponse()->getHeaderDecoration())) { throw new TBGTemplateNotFoundException('Can not find header decoration: ' . self::getResponse()->getHeaderDecoration()); } require self::getResponse()->getHeaderDecoration(); } echo $content; TBGLogging::log('...done (rendering content)'); // Render footer template if any if (!self::getRequest()->isAjaxCall() && self::getResponse()->doDecorateFooter()) { TBGLogging::log('decorating with footer'); if (!file_exists(self::getResponse()->getFooterDecoration())) { throw new TBGTemplateNotFoundException('Can not find footer decoration: ' . self::getResponse()->getFooterDecoration()); } require self::getResponse()->getFooterDecoration(); } TBGLogging::log('...done'); } TBGLogging::log('done (rendering final content)'); if (self::isReadySetup() && self::isDebugMode()) { self::getI18n()->addMissingStringsToStringsFile(); } return true; } else { TBGLogging::log("Cannot find the method {$actionToRunName}() in class {$actionClassName}.", 'core', TBGLogging::LEVEL_FATAL); throw new TBGActionNotFoundException("Cannot find the method {$actionToRunName}() in class {$actionClassName}. Make sure the method exists."); } }
public function listen_viewissue_panel(TBGEvent $event) { $web_path = $this->getSetting('web_path_' . $event->getSubject()->getProject()->getID()); $web_repo = $this->getSetting('web_repo_' . $event->getSubject()->getProject()->getID()); if (empty($web_repo) || empty($web_path)) { return; } $data = TBGVCSIntegrationTable::getTable()->getCommitsByIssue($event->getSubject()->getId()); if (!is_array($data)) { TBGActionComponent::includeTemplate('vcs_integration/viewissue_commits_top', array('items' => false)); } else { TBGActionComponent::includeTemplate('vcs_integration/viewissue_commits_top', array('items' => true)); /* Now produce each box */ foreach ($data as $revno => $entry) { $revision = $revno; /* Build correct URLs */ switch ($this->getSetting('web_type_' . $event->getSubject()->getProject()->getID())) { case 'viewvc': $link_rev = $web_path . '/' . '?root=' . $web_repo . '&view=rev&revision=' . $revision; break; case 'viewvc_repo': $link_rev = $web_path . '/' . '?view=rev&revision=' . $revision; break; case 'websvn': $link_rev = $web_path . '/revision.php?repname=' . $web_repo . '&isdir=1&rev=' . $revision; break; case 'websvn_mv': $link_rev = $web_path . '/' . '?repname=' . $web_repo . '&op=log&isdir=1&rev=' . $revision; break; case 'loggerhead': $link_rev = $web_path . '/' . $web_repo . '/revision/' . $revision; break; case 'gitweb': $link_rev = $web_path . '/' . '?p=' . $web_repo . ';a=commitdiff;h=' . $revision; break; case 'cgit': $link_rev = $web_path . '/' . $web_repo . '/commit/?id=' . $revision; break; case 'hgweb': $link_rev = $web_path . '/' . $web_repo . '/rev/' . $revision; break; case 'github': $link_rev = 'http://github.com/' . $web_repo . '/commit/' . $revision; break; case 'gitorious': $link_rev = $web_path . '/' . $web_repo . '/commit/' . $revision; break; } /* Now we have everything, render the template */ include_template('vcs_integration/commitbox', array("projectId" => $event->getSubject()->getProject()->getID(), "id" => $entry[0][0], "revision" => $revision, "author" => $entry[0][1], "date" => $entry[0][2], "log" => $entry[0][3], "files" => $entry[1])); } TBGActionComponent::includeTemplate('vcs_integration/viewissue_commits_bottom'); } }
public function runSpecialArticle(TBGRequest $request) { $this->component = null; if (TBGActionComponent::doesComponentExist("publish/special{$this->article_name}", false)) { $this->component = $this->article_name; $this->projectnamespace = $this->selected_project instanceof TBGProject ? ucfirst($this->selected_project->getKey()) . ':' : ''; } }
public function listen_loginTab(TBGEvent $event) { if ($this->isOutgoingNotificationsEnabled()) { TBGActionComponent::includeComponent('mailing/forgotPasswordTab', $event->getParameters()); } }
public function listen_projectconfig_panel(TBGEvent $event) { TBGActionComponent::includeTemplate('mailing/projectconfig_panel', array('selected_tab' => $event->getParameter('selected_tab'), 'access_level' => $event->getParameter('access_level'), 'project' => $event->getParameter('project'))); }
/** * Returns the HTML output from a template, but doesn't render it * * @param string $template the template name * @param array $params template parameters * * @return boolean */ public static function returnTemplateHTML($template, $params = array()) { $current_content = ob_get_clean(); TBGContext::isCLI() ? ob_start() : ob_start('mb_output_handler'); echo TBGActionComponent::includeTemplate($template, $params); $template_content = ob_get_clean(); TBGContext::isCLI() ? ob_start() : ob_start('mb_output_handler'); echo $current_content; return $template_content; }