Esempio n. 1
0
 /**
  * Log the passed exception to the framework's log folder.
  */
 function log(Exception $e)
 {
     $logfile = WFWebApplication::appDirPath(WFWebApplication::DIR_LOG) . '/framework_exceptions.log';
     $smarty = new WFSmarty();
     $smarty->assign('exception', $e);
     $smarty->setTemplate(WFWebApplication::appDirPath(WFWebApplication::DIR_SMARTY) . '/app_error_log.tpl');
     $errText = $smarty->render(false);
     // append info to log
     $fs = fopen($logfile, 'a');
     fputs($fs, $errText);
     fclose($fs);
 }
Esempio n. 2
0
/** 
*  Smarty plugin to display errors from a form submission.
*
*  The error is rendered by the "form_error.tpl" template file.
*
*  Smarty Params:
*  id - The id of the WFWidget to show errors for. OPTIONAL -- if the ID is for a WFForm, will show ALL errors from form submission. 
8       NOTE: DEPRECATED: You can also leave the ID BLANK to show all errors. But this has been deprecated b/c we need the ID to make AJAX updating work.
*       NOTE: to show errors on WFDynamic-generated widgets, use WFShowErrors with the ID of the WFDynamic. The WFShowErrors tag must occur AFTER the WFDynamic tag.
*
*  @param array The params from smarty tag.
*  @param object WFSmarty object of the current tpl.
*  @return string The rendered HTML of the error.
*  @todo Need to make it not-hard-coded to get the form_error.tpl file... should be able to override this in userland.
*/
function smarty_function_WFShowErrors($params, &$smarty)
{
    static $errorSmarty = NULL;
    $page = $smarty->getPage();
    if ($page->ignoreErrors()) {
        return;
    }
    if (is_null($errorSmarty)) {
        $errorSmarty = new WFSmarty();
        $errorSmarty->setTemplate(WFWebApplication::appDirPath(WFWebApplication::DIR_SMARTY) . '/form_error.tpl');
    }
    // if the ID is a WFForm, that is the same as "all errors"
    $getErrorsForId = NULL;
    if (!empty($params['id'])) {
        if (!$page->outlet($params['id']) instanceof WFForm) {
            $getErrorsForId = $params['id'];
        }
    }
    // get error list
    if ($getErrorsForId === NULL) {
        // get all errors
        $errors = $page->errors();
    } else {
        // get errors for a specific widget
        $widget = $smarty->getCurrentWidget($params);
        if ($widget instanceof WFDynamic and !$widget->valueForKeyPath('oneShotMode')) {
            $widget = $widget->getLastRenderedWidget();
        }
        $errors = $widget->errors();
    }
    $errorHTML = '';
    $errorSmarty->assign('errorList', $errors);
    $errorSmarty->assign('id', empty($params['id']) ? NULL : $params['id']);
    $errorHTML = $errorSmarty->render(false);
    return $errorHTML;
}
Esempio n. 3
0
 /**
  * Exception handler for the WFRequestController.
  *
  * This is basically the uncaught exception handler for the request cycle.
  * We want to have this in the request object because we want the result to be displayed within our skin system.
  * This function will display the appropriate error page based on the deployment mode for this machine.
  *
  * @param Exception The exception object to handle.
  */
 function handleException(Exception $e)
 {
     // give ourselves a little more memory so we can process the exception
     ini_set('memory_limit', memory_get_usage() + 25000000);
     // grab error_get_last ASAP so that it cannot get adulterated by other things.
     // we will inject it into things downstream that want it.
     $standardErrorData = WFExceptionReporting::generatedStandardizedErrorDataFromException($e);
     // let the current module try to handle the exception
     if ($this->rootModuleInvocation) {
         $this->rootModuleInvocation->handleUncaughtException($e);
     }
     $webAppDelegate = WFWebApplication::sharedWebApplication()->delegate();
     if (is_object($webAppDelegate) && method_exists($webAppDelegate, 'handleUncaughtException')) {
         $handled = $webAppDelegate->handleUncaughtException($e);
         if ($handled) {
             return;
         }
     }
     WFExceptionReporting::log($standardErrorData);
     $exceptionPage = new WFSmarty();
     // LEGACY tpl var setup (in case there are old .tpl's that expect it
     // build stack of errors (php 5.3+)
     if (method_exists($e, 'getPrevious')) {
         $tmpE = $e;
         $allExceptions = array();
         do {
             $allExceptions[] = $tmpE;
         } while ($tmpE = $tmpE->getPrevious());
     } else {
         $allExceptions = array($e);
     }
     $exceptionPage->assign('exceptions', $allExceptions);
     $exceptionPage->assign('exceptionClass', get_class($allExceptions[0]));
     $exceptionPage->assign('home_url', WWW_ROOT . '/');
     // end LEGACY
     // modern format
     $exceptionPage->assign('location', "http://{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}");
     $exceptionPage->assign('headline', "{$standardErrorData[0]['title']}: {$standardErrorData[0]['message']}");
     $exceptionPage->assign('standardErrorData', $standardErrorData);
     $exceptionPage->assign('standardErrorDataJSON', WFJSON::encode(array('error' => $standardErrorData, '$_SERVER' => $_SERVER, '$_REQUEST' => $_REQUEST, '$_SESSION' => $_SESSION)));
     if (IS_PRODUCTION) {
         $exceptionPage->setTemplate(WFWebApplication::appDirPath(WFWebApplication::DIR_SMARTY) . '/app_error_user.tpl');
     } else {
         $exceptionPage->setTemplate(WFWebApplication::appDirPath(WFWebApplication::DIR_SMARTY) . '/app_error_developer.tpl');
     }
     // display the error
     $body_html = $exceptionPage->render(false);
     // output error info
     header("HTTP/1.0 500 Uncaught Exception");
     if ($this->isAjax()) {
         print strip_tags($body_html);
     } else {
         $skin = new WFSkin();
         $skin->setDelegateName(WFWebApplication::sharedWebApplication()->defaultSkinDelegate());
         $skin->setBody($body_html);
         $skin->setTitle("An error has occurred.");
         $skin->render();
     }
 }
Esempio n. 4
0
 private function sendPageErrorsOverAjax()
 {
     // Collect all errors and send them back in a WFActionResponseWFErrorsException
     $errorSmarty = new WFSmarty();
     $errorSmarty->setTemplate(WFWebApplication::appDirPath(WFWebApplication::DIR_SMARTY) . '/form_error.tpl');
     $uiUpdates = new WFActionResponseWFErrorsException();
     foreach ($this->widgets() as $id => $obj) {
         $errors = $obj->errors();
         if (count($errors)) {
             $errorSmarty->assign('errorList', $errors);
             $errorSmarty->assign('id', $id);
             $errId = "phocoaWFFormError_{$id}";
             $uiUpdates->addReplaceHTML($errId, $errorSmarty->render(false));
         }
     }
     // put "all errors" in the submitted form err handler
     $errorSmarty->assign('errorList', $this->errors());
     $errorSmarty->assign('id', $this->submittedFormName());
     $errId = "phocoaWFFormError_" . $this->submittedFormName();
     $uiUpdates->addReplaceHTML($errId, $errorSmarty->render(false));
     $uiUpdates->send();
 }
Esempio n. 5
0
 /**
  * Exception handler for the WFRequestController.
  *
  * This is basically the uncaught exception handler for the request cycle.
  * We want to have this in the request object because we want the result to be displayed within our skin system.
  * This function will display the appropriate error page based on the deployment mode for this machine, then exit.
  *
  * @param Exception The exception object to handle.
  */
 function handleException(Exception $e)
 {
     // give ourselves a little more memory so we can process the exception
     ini_set('memory_limit', memory_get_usage() + 25000000);
     $webAppDelegate = WFWebApplication::sharedWebApplication()->delegate();
     if (is_object($webAppDelegate) && method_exists($webAppDelegate, 'handleUncaughtException')) {
         $handled = $webAppDelegate->handleUncaughtException($e);
         if ($handled) {
             return;
         }
     }
     WFExceptionReporting::log($e);
     // build stack of errors (php 5.3+)
     if (method_exists($e, 'getPrevious')) {
         $allExceptions = array();
         do {
             $allExceptions[] = $e;
         } while ($e = $e->getPrevious());
     } else {
         $allExceptions = array($e);
     }
     $exceptionPage = new WFSmarty();
     $exceptionPage->assign('exceptions', $allExceptions);
     $exceptionPage->assign('exceptionClass', get_class($allExceptions[0]));
     $exceptionPage->assign('home_url', WWW_ROOT . '/');
     if (IS_PRODUCTION) {
         $exceptionPage->setTemplate(WFWebApplication::appDirPath(WFWebApplication::DIR_SMARTY) . '/app_error_user.tpl');
     } else {
         $exceptionPage->setTemplate(WFWebApplication::appDirPath(WFWebApplication::DIR_SMARTY) . '/app_error_developer.tpl');
     }
     // display the error and exit
     $body_html = $exceptionPage->render(false);
     // output error info
     header("HTTP/1.0 500 Uncaught Exception");
     if ($this->isAjax()) {
         print strip_tags($body_html);
     } else {
         $skin = new WFSkin();
         $skin->setDelegateName(WFWebApplication::sharedWebApplication()->defaultSkinDelegate());
         $skin->setBody($body_html);
         $skin->setTitle("An error has occurred.");
         $skin->render();
     }
     exit;
 }
Esempio n. 6
0
 /**
  * Render the skin.
  * @param boolean TRUE to display the results to the output buffer, FALSE to return them in a variable. DEFAULT: TRUE.
  * @return string The rendered view. NULL if displaying.
  * @todo convert the DIR_SMARTY calls to use a new WFWebApplication::getResource($path) infrastructure that will allow for userland overloads of these templates
  */
 function render($display = true)
 {
     $this->loadSkin();
     $skinTemplatesDir = $this->getSkinTemplatesDir();
     $smarty = new WFSmarty();
     $smarty->assign('skin', $this);
     // add variables to smarty
     $themeVars = $this->skinManifestDelegate->loadTheme($this->skinThemeName);
     $smarty->assign('skinThemeVars', $themeVars);
     $smarty->assign('skinTitle', $this->title);
     $smarty->assign('skinMetaKeywords', join(',', $this->metaKeywords));
     $smarty->assign('skinMetaDescription', $this->metaDescription);
     $smarty->assign('skinCharset', $this->charset);
     $smarty->assign('skinBody', $this->body);
     $smarty->assign('skinHeadStrings', join("\n", array_values($this->headStrings)));
     $smarty->assign('phocoaDebug', WFWebApplication::sharedWebApplication()->debug());
     // set up shared directory URLs
     // deprecated
     $smarty->assign('skinDir', $this->getSkinDir());
     $smarty->assign('skinDirShared', $this->getSkinDirShared());
     // new names
     $smarty->assign('skinTypeAssetsDir', $this->getSkinTypeAssetsDir());
     $smarty->assign('skinSharedAssetsDir', $this->getSkinSharedAssetsDir());
     $smarty->assign('skinThemeAssetsDir', $this->getSkinThemeAssetsDir());
     // FS paths of things
     $smarty->assign('skinTemplatesDir', $skinTemplatesDir);
     $smarty->assign('skinTypeDir', $this->getSkinTypeDir());
     // build the <head> section
     $smarty->assign('skinPhocoaHeadTpl', WFWebApplication::appDirPath(WFWebApplication::DIR_SMARTY) . '/head.tpl');
     $smarty->assign('skinHead', $smarty->fetch($this->headTemplate));
     // set the template
     if ($this->templateType == WFSkin::SKIN_WRAPPER_TYPE_RAW) {
         $smarty->setTemplate(WFWebApplication::appDirPath(WFWebApplication::DIR_SMARTY) . '/template_raw.tpl');
     } else {
         $smarty->setTemplate($skinTemplatesDir . '/template_' . $this->templateType . '.tpl');
     }
     // pre-render callback
     $this->willRender();
     // render smarty
     if ($display) {
         $smarty->render();
     } else {
         return $smarty->render(false);
     }
 }