예제 #1
0
 public function listen_configCreateuserEmail(framework\Event $event)
 {
     framework\ActionComponent::includeComponent('mailing/configcreateuseremail');
 }
예제 #2
0
 public function runSpecialArticle(framework\Request $request)
 {
     $this->component = null;
     if (framework\ActionComponent::doesComponentExist("publish/special{$this->article_name}", false)) {
         $this->component = $this->article_name;
         $this->projectnamespace = $this->selected_project instanceof \thebuggenie\core\entities\Project ? ucfirst($this->selected_project->getKey()) . ':' : '';
     }
 }
예제 #3
0
 /**
  * Performs an action.
  *
  * @param $action
  * @param string $module Name of the action module
  * @param string $method Name of the action method to run
  *
  * @return bool
  * @throws \Exception
  */
 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
     $templateBasePath = self::isInternalModule($module) ? THEBUGGENIE_INTERNAL_MODULES_PATH : THEBUGGENIE_MODULES_PATH;
     $templatePath = $templateBasePath . $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) . '.' . self::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()) {
                 return true;
             }
         }
         if (self::$_debug_mode) {
             $time = explode(' ', microtime());
             $pretime = $time[1] + $time[0];
         }
         if ($content === null) {
             Logging::log('Running main pre-execute action');
             // Running any overridden preExecute() method defined for that module
             // or the default empty one provided by \thebuggenie\core\framework\Action
             if ($pre_action_retval = $action->preExecute(self::getRequest(), $method)) {
                 $content = ob_get_clean();
                 Logging::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)) {
                     Logging::log('Running custom pre-execute action');
                     $action->{$preActionToRunName}(self::getRequest(), $method);
                 }
                 // Running main route action
                 Logging::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];
                     self::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();
                 Logging::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
                 Logging::log('...done');
                 Logging::log('Displaying template');
                 // Check to see if we have a translated version of the template
                 if ($method == 'notFound' && $module == 'main') {
                     $templateName = $templatePath . self::getResponse()->getTemplate();
                 } elseif (!self::isReadySetup() || ($templateName = self::getI18n()->hasTranslatedTemplate(self::getResponse()->getTemplate())) === false) {
                     // Check to see if any modules provide an alternate template
                     $event = Event::createNew('core', "self::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 = self::isInternalModule($newPath[0]) ? THEBUGGENIE_INTERNAL_MODULES_PATH : THEBUGGENIE_MODULES_PATH;
                         $templateName .= $newPath[0] . DS . 'templates' . DS . $newPath[1] . '.' . self::getRequest()->getRequestedFormat() . '.php';
                     } else {
                         $templateName = $templatePath . self::getResponse()->getTemplate();
                     }
                 }
                 // Check to see if the template exists and throw an exception otherwise
                 if (!isset($templateName) || !file_exists($templateName)) {
                     Logging::log('The template file for the ' . $method . ' action ("' . self::getResponse()->getTemplate() . '") does not exist', 'core', Logging::LEVEL_FATAL);
                     Logging::log('Trying to load file "' . $templateName . '"', 'core', Logging::LEVEL_FATAL);
                     throw new exceptions\TemplateNotFoundException('The template file for the ' . $method . ' action ("' . self::getResponse()->getTemplate() . '") does not exist');
                 }
                 self::loadLibrary('common');
                 // Present template for current action
                 ActionComponent::presentTemplate($templateName, $action->getParameterHolder());
                 $content = ob_get_clean();
                 Logging::log('...completed');
             }
         } elseif (self::$_debug_mode) {
             $time = explode(' ', microtime());
             $posttime = $time[1] + $time[0];
             self::visitPartial($visited_templatename, $posttime - $pretime);
         }
         Logging::log('rendering final content');
         // Set core layout path
         self::getResponse()->setLayoutPath(THEBUGGENIE_CORE_PATH . 'templates');
         // Trigger event for rendering (so layout path can be overwritten)
         \thebuggenie\core\framework\Event::createNew('core', '\\thebuggenie\\core\\framework\\Context::renderBegins')->trigger();
         if (Settings::isMaintenanceModeEnabled() && !mb_strstr(self::getRouting()->getCurrentRouteName(), 'configure')) {
             if (!file_exists(self::getResponse()->getLayoutPath() . DS . 'offline.inc.php')) {
                 throw new exceptions\TemplateNotFoundException('Can not find offline mode template');
             }
             ob_start('mb_output_handler');
             ob_implicit_flush(0);
             ActionComponent::presentTemplate(self::getResponse()->getLayoutPath() . DS . 'offline.inc.php');
             $content = ob_get_clean();
         }
         // Render output in correct order
         self::getResponse()->renderHeaders();
         if (self::getResponse()->getDecoration() == Response::DECORATE_DEFAULT && !self::getRequest()->isAjaxCall()) {
             if (!file_exists(self::getResponse()->getLayoutPath() . DS . 'layout.php')) {
                 throw new exceptions\TemplateNotFoundException('Can not find layout template');
             }
             ob_start('mb_output_handler');
             ob_implicit_flush(0);
             $layoutproperties = self::setupLayoutProperties($content);
             ActionComponent::presentTemplate(self::getResponse()->getLayoutPath() . DS . 'layout.php', $layoutproperties);
             ob_flush();
         } else {
             // Render header template if any, and store the output in a variable
             if (!self::getRequest()->isAjaxCall() && self::getResponse()->doDecorateHeader()) {
                 Logging::log('decorating with header');
                 if (!file_exists(self::getResponse()->getHeaderDecoration())) {
                     throw new exceptions\TemplateNotFoundException('Can not find header decoration: ' . self::getResponse()->getHeaderDecoration());
                 }
                 ActionComponent::presentTemplate(self::getResponse()->getHeaderDecoration());
             }
             echo $content;
             // Trigger event for ending the rendering
             \thebuggenie\core\framework\Event::createNew('core', '\\thebuggenie\\core\\framework\\Context::renderEnds')->trigger();
             Logging::log('...done (rendering content)');
             // Render footer template if any
             if (!self::getRequest()->isAjaxCall() && self::getResponse()->doDecorateFooter()) {
                 Logging::log('decorating with footer');
                 if (!file_exists(self::getResponse()->getFooterDecoration())) {
                     throw new exceptions\TemplateNotFoundException('Can not find footer decoration: ' . self::getResponse()->getFooterDecoration());
                 }
                 ActionComponent::presentTemplate(self::getResponse()->getFooterDecoration());
             }
             Logging::log('...done');
         }
         Logging::log('done (rendering final content)');
         return true;
     } else {
         Logging::log("Cannot find the method {$actionToRunName}() in class {$actionClassName}.", 'core', Logging::LEVEL_FATAL);
         throw new exceptions\ActionNotFoundException("Cannot find the method {$actionToRunName}() in class {$actionClassName}. Make sure the method exists.");
     }
 }
예제 #4
0
 public function listen_quicksearchDropdownFoundItems(framework\Event $event)
 {
     $searchterm = $event->getSubject();
     list($resultcount, $articles) = Article::findArticlesByContentAndProject($searchterm, framework\Context::getCurrentProject());
     framework\ActionComponent::includeComponent('publish/quicksearch_dropdown_founditems', array('searchterm' => $searchterm, 'articles' => $articles, 'resultcount' => $resultcount));
 }
예제 #5
0
/**
 * 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 ActionComponent::includeComponent($component, $params);
}
예제 #6
0
 /**
  * Header "Agile" menu and board list
  *
  * @Listener(module="core", identifier="templates/headermainmenu::projectmenulinks")
  *
  * @param \thebuggenie\core\framework\Event $event
  */
 public function headerMenuProjectLinks(framework\Event $event)
 {
     if (framework\Context::isProjectContext()) {
         $boards = \thebuggenie\modules\agile\entities\AgileBoard::getB2DBTable()->getAvailableProjectBoards(framework\Context::getUser()->getID(), framework\Context::getCurrentProject()->getID());
         framework\ActionComponent::includeComponent('agile/headermenuprojectlinks', array('project' => $event->getSubject(), 'boards' => $boards));
     }
 }