Пример #1
0
 function dspSkinCSS_PageDidLoad()
 {
     // determine skin type/skin/theme
     $cssTemplate = $skinName = $skinThemeName = NULL;
     @(list(, , , $cssTemplate, $skinTypeName, $skinName, $skinThemeName) = split('/', $_SERVER['PATH_INFO']));
     $cssFilePath = WFWebApplication::appDirPath(WFWebApplication::DIR_SKINS) . '/' . $skinTypeName . '/' . $skinName . '/' . $cssTemplate;
     if (!file_exists($cssFilePath)) {
         header("HTTP/1.0 404 Not Found");
         print "No css file at: {$cssFilePath}";
         exit;
     }
     // set the skin's wrapper information
     $skin = $this->invocation->rootSkin();
     $skin->setDelegateName($skinTypeName);
     $skin->setSkin($skinName);
     $skin->setTemplateType(WFSkin::SKIN_WRAPPER_TYPE_RAW);
     $skin->setValueForKey($skinThemeName, 'skinThemeName');
     // load the theme vars into our smarty for this module
     $this->requestPage->assign('skinThemeVars', $skin->valueForKey('skinManifestDelegate')->loadTheme($skinThemeName));
     $this->requestPage->assign('cssFilePath', $cssFilePath);
     $this->requestPage->assign('skinDir', $skin->getSkinDir());
     $this->requestPage->assign('skinDirShared', $skin->getSkinDirShared());
     header("Content-Type: text/css");
     // make CSS cacheable for a day at least
     $seconds = 24 * 60 * 60;
     // cache control - we can certainly safely cache the search results for 15 minutes
     header('Pragma: ');
     // php adds Pragma: nocache by default, so we have to disable it
     header('Cache-Control: max-age=' . $seconds);
     // Format: Fri, 30 Oct 1998 14:19:41 GMT
     header('Expires: ' . gmstrftime("%a, %d %b %Y %T ", time() + $seconds) . ' GMT');
 }
Пример #2
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);
 }
Пример #3
0
 function __construct()
 {
     parent::Smarty();
     $this->template = NULL;
     // by default, no template!
     // smarty stuff
     // runtime directories
     $this->compile_dir = WFWebApplication::appDirPath(WFWebApplication::DIR_RUNTIME) . '/smarty/templates_c/';
     $this->cache_dir = WFWebApplication::appDirPath(WFWebApplication::DIR_RUNTIME) . '/smarty/cache/';
     // default directories
     $this->template_dir = WFWebApplication::appDirPath(WFWebApplication::DIR_SMARTY) . '/templates/';
     $this->config_dir = WFWebApplication::appDirPath(WFWebApplication::DIR_SMARTY) . '/configs/';
     // add a local plugins dir
     array_push($this->plugins_dir, FRAMEWORK_DIR . '/smarty/plugins/');
     // GLOBAL variables for all smarty templates
     $this->assign('WWW_ROOT', WWW_ROOT);
 }
Пример #4
0
 function dspSkinCSS_PageDidLoad()
 {
     // determine skin type/skin/theme
     $cssTemplate = $skinName = $skinThemeName = NULL;
     @(list(, , , $cssTemplate, $skinTypeName, $skinName, $skinThemeName) = split('/', $_SERVER['PATH_INFO']));
     $cssFilePath = WFWebApplication::appDirPath(WFWebApplication::DIR_SKINS) . '/' . $skinTypeName . '/' . $skinName . '/' . $cssTemplate;
     if (!file_exists($cssFilePath)) {
         header("HTTP/1.0 404 Not Found");
         exit;
     }
     // set the skin's wrapper information
     $skin =& WFRequestController::sharedSkin();
     $skin->setDelegateName($skinTypeName);
     $skin->setSkin($skinName);
     $skin->setTemplateType(SKIN_WRAPPER_TYPE_RAW);
     $skin->setValueForKey($skinThemeName, 'skinThemeName');
     // load the theme vars into our smarty for this module
     $this->requestPage->assign('skinThemeVars', $skin->valueForKey('skinManifestDelegate')->loadTheme($skinThemeName));
     $this->requestPage->assign('cssFilePath', $cssFilePath);
     $this->requestPage->assign('skinDir', $skin->getSkinDir());
     $this->requestPage->assign('skinDirShared', $skin->getSkinDirShared());
     header("Content-Type: text/css");
 }
Пример #5
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;
}
Пример #6
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();
     }
 }
Пример #7
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();
 }
Пример #8
0
 /**
  *  Parses the invocationPath, looks for the module, instantiates the module, etc.
  *
  *  This is where {@link WFAuthorizationManager module security} is applied. If the page requies login to continue, the system will redirect to a login page,
  *  and will redirect back to the initial page upon successful login.
  *
  *  NOTE: Will convert WFNull params into NULL values.
  *
  *  @throws Various exceptions in setting up the module.
  *  @todo This doesn't seem super-clean... I don't understand needsRedirect, and throwing exceptions for redir causes problems with quickModule() not being able to use shorthand invocation paths, and it doesn't trip the !isRootInvocation() check...
  */
 private function extractComponentsFromInvocationPath()
 {
     // walk path looking for the module -- keep "blank" entry when "//" encountered.
     $pathInfoParts = preg_split('/\\//', trim($this->invocationPath, '/'), -1);
     $modulesDirPath = WFWebApplication::appDirPath(WFWebApplication::DIR_MODULES);
     foreach (WFWebApplication::sharedWebApplication()->modulePaths() as $prefix => $dir) {
         if (strpos($this->invocationPath, $prefix) === 0) {
             $modulesDirPath = realpath($dir . '/..');
         }
     }
     // this block determines modulePath, moduleName, and pageName [optionally]
     //print "URI: {$this->invocationPath}<BR>";
     //print_r($pathInfoParts);
     $foundModule = false;
     $modulePath = $possibleModulePath = '';
     $moduleName = NULL;
     $pageName = NULL;
     $partsUsedBeforeModule = 0;
     foreach ($pathInfoParts as $part) {
         // recurse into directories until there are no more dirs to drop into
         $possibleModulePath .= '/' . $part;
         $possibleSubModule = $modulesDirPath . $possibleModulePath;
         //print "Testing to see if there is a directory at: '$possibleSubModule' ($possibleModulePath).<BR>";
         if (is_dir($possibleSubModule)) {
             //print "Directory found<br>";
             $modulePath .= '/' . $part;
             $moduleName = $part;
             $partsUsedBeforeModule++;
             continue;
         } else {
             $pageName = $part;
             //print "No Directory found... will look for module<br>";
             break;
         }
     }
     //print "Only POssible ModulePath: $modulePath<Br />";
     if ($partsUsedBeforeModule < 1) {
         $possibleModuleFilePath = NULL;
     } else {
         $possibleModuleFilePath = $modulesDirPath . $modulePath . '/' . $pathInfoParts[$partsUsedBeforeModule - 1] . '.php';
     }
     if (file_exists($possibleModuleFilePath)) {
         //print "Found module at $possibleModuleFilePath<BR>";
         $foundModule = true;
         $this->modulePath = ltrim($modulePath, '/');
         $this->moduleName = $moduleName;
         $this->pageName = $pageName;
         $this->setModulesDir($modulesDirPath);
     }
     //print "MP: {$this->modulePath}<br>Mod:{$this->moduleName}<BR>Page: {$this->pageName}<BR>Params:" . print_r($this->invocationParameters,true) . "<BR>";
     if (!$foundModule) {
         throw new WFRequestController_NotFoundException("Module 404: invocation path '{$this->invocationPath}' could not be found.");
     }
     if (empty($this->moduleName) or empty($this->pageName)) {
         // test - i don't think !$moduleName can happen. can refactor needsRedirect to if (empty(pageName)) if true...
         if (empty($this->moduleName)) {
             throw new WFException("empty moduleName - don't expect that this can even happen.");
         }
         // also, the only need for needsRedirect I *think* is if the URL is "/<moduleName>/?" and NO extra info. it's basically just a simple shortcut to redirect to "default" page.
         // it only kicks in if allPages() is not set up. With allPages() defined, then I don't think it can happen.
         // @todo there may be a better way to handle this case. consider refactoring.
         $needsRedirect = true;
     } else {
         $needsRedirect = false;
     }
     // i don't think this line ever can execture...
     if (empty($this->moduleName)) {
         throw new WFRequestController_NotFoundException("Module 404: No module name could be determined from {$this->invocationPath}.");
     }
     // if we get here, we're guaranteed that a modulePath is valid.
     // load module instance
     $this->module = WFModule::factory($this);
     // Calculate Parameters for the page
     // test to see if what we think is the page name IS a page in the module. If so, proceed as normal. If not, assume it's the first parameter of the default page.
     if ($this->pageName) {
         $params = array();
         $modulePages = $this->module->allPages();
         if (count($modulePages) == 0 or in_array($this->pageName, $modulePages)) {
             // a page was detected; skip one pathpart to get to params
             if (count($pathInfoParts) > 2) {
                 $params = array_slice($pathInfoParts, $partsUsedBeforeModule + 1);
             }
         } else {
             // no page detected; params start now; send to default page
             $this->pageName = $this->module->defaultPage();
             if (count($pathInfoParts) > 1) {
                 $params = array_slice($pathInfoParts, $partsUsedBeforeModule);
             }
         }
         // parse out parameter data from URL
         if (count($params)) {
             foreach ($params as $k => $v) {
                 if ($v === WFModuleInvocation::PARAMETER_NULL_VALUE) {
                     $params[$k] = NULL;
                 } else {
                     $params[$k] = urldecode($v);
                 }
             }
             $this->invocationParameters = $params;
         }
     }
     // determine default page
     if (empty($this->pageName)) {
         $this->pageName = $this->module->defaultPage();
     }
     if (empty($this->pageName)) {
         throw new WFException("No page could be determined. Make sure you are supplying an page in the invocation path or have your module supply a defaultPage.");
     }
     // redirect as needed - this doesn't make sense inside of WFModuleInvocation...
     // of course cannot have invocationParameters from invocationPath unless module and pageName are specified
     if ($needsRedirect) {
         if ($this->isRootInvocation()) {
             // should be internal redirect to preserve pretty urls
             throw new WFRequestController_InternalRedirectException(WFRequestController::WFURL($this->modulePath, $this->pageName));
             //header('Location: ' . WFRequestController::WFURL($this->modulePath, $this->pageName));
             //exit;
         } else {
             throw new WFException("You must specify a complete invocationPath.");
         }
     }
 }
Пример #9
0
 function render($blockContent = NULL)
 {
     if ($this->activeTab == NULL) {
         $this->setActiveTabID($this->defaultTabID);
     }
     $template = $this->page->template();
     $template->assign('__tabView', $this);
     if ($this->onePageMode) {
         $tabTplFile = WFWebApplication::appDirPath(WFWebApplication::DIR_SMARTY) . '/onepage_tabs.tpl';
     } else {
         $tabTplFile = WFWebApplication::appDirPath(WFWebApplication::DIR_SMARTY) . '/multipage_tabs.tpl';
         throw new Exception("Non-onePage mode not yet implemented.");
     }
     return $template->fetch($tabTplFile);
 }
Пример #10
0
 /**
  *  Get an absolute filesystem path to the www dir for graphics for this widget in the current project.
  *
  *  @return string The path to directory containing www items for this widget.
  */
 function getWidgetDir()
 {
     return WFWebApplication::appDirPath(WFWebApplication::DIR_WWW) . '/framework/widgets/' . get_class($this);
 }
Пример #11
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;
 }
Пример #12
0
 /**
  * Get a list of all installed skins for the current Skin Type.
  *
  * @return array Skins that are installed.
  */
 function installedSkins()
 {
     $skins = array();
     $skinsDir = WFWebApplication::appDirPath(WFWebApplication::DIR_SKINS);
     $skinDirPath = $skinsDir . '/' . $this->delegateName;
     $dh = opendir($skinDirPath);
     if ($dh) {
         while (($file = readdir($dh)) !== false) {
             if (is_dir($skinDirPath . '/' . $file) and !in_array($file, array('.', '..'))) {
                 array_push($skins, $file);
             }
         }
         closedir($dh);
     }
     return $skins;
 }