function ajaxFormSubmitNormal($page, $params, $senderId, $eventName) { $result = 'You said: "' . $page->outlet('textField')->value() . '" and "' . $page->outlet('textField2')->value() . '".'; if (WFRequestController::sharedRequestController()->isAjax()) { return WFActionResponsePhocoaUIUpdater::WFActionResponsePhocoaUIUpdater()->addUpdateHTML('ajaxFormResult', $result); } else { $page->assign('formResult', $result); } }
/** * Smarty plugin to allow inclusion of WFModule invocations from the skin. * * Smarty Params: * invocationPath - The invocationPath for the module. See {@link WFModuleInvocation}. Required. * targetRootModule - If you want to customize the value of {@link WFModuleInvocation::$targetRootModule}, specify it in the param. * BOOLEAN, but remember that in smarty targetRootModule="false" passing the STRING false, so do targetRootModule=false * respondsToForms - Controls whether or not the instance of the module will "respond" to form submissions. Default: FALSE. This is useful when using WFSkinModuleView to embed functions like login or search into skins. * * IMPORTANT!!!! WFSkinModuleView is intended for use only from skin template files. Results if used from a WFModule/Page are UNPREDICTABLE -- basically some functions will mistake the "root" module for the root of the skin rather than the root of the current WFModuleInvocation hierarchy when programmiatcally invoking WFModuleInvocations. * * @param array The params from smarty tag * @param object WFSmarty object of the current tpl * @return string The HTML snippet from the WFModule. * @throws Exception if the module cannot be found or no invocationPath is specified. */ function smarty_function_WFSkinModuleView($params, $smarty) { if (empty($params['invocationPath'])) { throw new Exception("InvocationPath is required."); } $respondsToForms = isset($params['respondsToForms']) ? $params['respondsToForms'] : false; $rc = WFRequestController::sharedRequestController(); // if there is no root invocation, then something bad has happened (probably an exception has been thrown during the main WFModuleInvocation setup), so just bail on any sub-modules. $rootInv = $rc->rootModuleInvocation(); if (!$rootInv) { return NULL; } $modInvocation = new WFModuleInvocation($params['invocationPath'], $rootInv); $modInvocation->setRespondsToForms($respondsToForms); if (isset($params['targetRootModule'])) { $modInvocation->setTargetRootModule($params['targetRootModule']); } return $modInvocation->execute(); }
/** * Smarty plugin to get a relative url to the given module. * * Smarty Params: * module - The module path to link to. * page - The page name to link to. * * NOTE: 'action' is a deprecated alias of the 'page' parameter. * * @param array The params from smarty tag. * @param object WFSmarty object of the current tpl. * @return string The url, appropriate for a src or href etc. Add '/' to the end if you need to add parameters. */ function smarty_function_WFURL($params, &$smarty) { // determine module $modulePath = NULL; if (!empty($params['module'])) { $modulePath = $params['module']; } // if no module name is specified, use the one from the current module, if available if (empty($modulePath) and $smarty->getPage()) { $modulePath = $smarty->getPage()->module()->invocation()->modulePath(); } if (!empty($params['page'])) { $page = $params['page']; } else { if (!empty($params['action'])) { $page = $params['action']; } } $rc = WFRequestController::sharedRequestController(); return $rc->WFURL($modulePath, $page); }
function regexRun($page, $params) { $showResult = "No matches."; $matches = array(); switch ($page->outlet('regexMatchType')->value()) { case 'preg_match_all': if (preg_match_all('/' . $page->outlet('regexExpression')->value() . '/', $page->outlet('regexTarget')->value(), $matches)) { $showResult = "<pre>"; //$showResult .= print_r($matches, true); for ($j = 0; $j < count($matches[0]); $j++) { $showResult .= "\n\nMatched: {$matches[0][$j]}"; for ($i = 0; $i < count($matches); $i++) { $showResult .= "\n{$i}: {$matches[$i][$j]}"; } } $showResult .= "</pre>"; } break; case 'preg_match': if (preg_match('/' . $page->outlet('regexExpression')->value() . '/', $page->outlet('regexTarget')->value(), $matches)) { $showResult = "<pre>"; for ($i = 0; $i < count($matches); $i++) { if ($i == 0) { $showResult .= "\nMatched: {$matches[0]}\n\n"; } else { $showResult .= "\n{$i}: {$matches[$i]}"; } } $showResult .= "</pre>"; } break; } if (WFRequestController::sharedRequestController()->isAjax()) { return WFActionResponsePhocoaUIUpdater::WFActionResponsePhocoaUIUpdater()->addUpdateHTML('regexResult', $showResult); } else { print $showResult; exit; } }
/** * Get a reference to this WFRequestController's skin object. * * @static * @return object A reference to the {@link WFSkin} object. * @deprecated Use $module->rootSkin() */ public static function sharedSkin() { $rc = WFRequestController::sharedRequestController(); $rootInv = $rc->rootModuleInvocation(); if (!$rootInv) { throw new Exception("No root invocation, thus no shared skin.."); } return $rootInv->skin(); }
/** * Get a URL that will take you to the current requestPage of the module, with the current state. * Only meaningful when called on the requestPage of the module. * @return string A URL to load the current page with the current state, but NOT send the current action. Useful for * things like a "modify search" link. * @throws If called on the responseView, as it is not meaningful. */ function urlToState() { if ($this->module->requestPage() !== $this) { throw new Exception("urlToState called on a page other than the requestPage."); } $rc = WFRequestController::sharedRequestController(); $url = $_SERVER['PHP_SELF'] . '?'; foreach ($_REQUEST as $k => $v) { if (strncmp($k, 'action|', 7) != 0) { $url .= $k . '=' . $v . '&'; } } return $url; }
/** * Execute the checking of security clearance for the user and the module. * * NOTE: This function may issue an HTTP 302 and redirect the user to the login page, then halt script execution. * * @throws WFException if anything unexpected happens. */ private function runSecurityCheck() { try { // check security, but only for the root invocation if ($this->invocation->isRootInvocation()) { $authInfo = WFAuthorizationManager::sharedAuthorizationManager()->authorizationInfo(); $access = $this->checkSecurity($authInfo); if (!in_array($access, array(WFAuthorizationManager::ALLOW, WFAuthorizationManager::DENY, WFAuthorizationManager::PROMPT))) { throw new WFException("Unexpected return code from checkSecurity."); } // if access is denied, see if there is a logged in user. If so, then DENY. If not, then allow login. if ($access == WFAuthorizationManager::DENY) { if ($authInfo->isLoggedIn()) { // if no one is logged in, allow login, otherwise deny. throw new WFAuthorizationException("Access denied.", WFAuthorizationException::DENY); } else { // if no one is logged in, allow login, otherwise deny. throw new WFAuthorizationException("Try logging in.", WFAuthorizationException::TRY_LOGIN); } } else { if ($access == WFAuthorizationManager::PROMPT) { if (!$authInfo->isLoggedIn()) { throw new WFException("WFAuthorizationManager::PROMPT is not a valid response when no one is logged in."); } else { // if no one is logged in, allow login, otherwise deny. throw new WFAuthorizationException("Please re-login to access this secure area.", WFAuthorizationException::TRY_PROMPT); } } } } } catch (WFAuthorizationException $e) { if (php_sapi_name() === 'cli') { throw new WFException($e->getMessage()); } if (WFRequestController::sharedRequestController()->isAjax()) { throw new WFRequestController_HTTPException("Not authorized.", 403); } switch ($e->getCode()) { case WFAuthorizationException::TRY_PROMPT: WFAuthorizationManager::sharedAuthorizationManager()->doLoginRedirect($_SERVER['REQUEST_URI'], true); break; case WFAuthorizationException::TRY_LOGIN: WFAuthorizationManager::sharedAuthorizationManager()->doLoginRedirect($_SERVER['REQUEST_URI']); break; case WFAuthorizationException::DENY: header("Location: " . WFRequestController::WFURL('login', 'notAuthorized')); exit; break; } } }
/** * Bootstrap control of the application to the RequestController. * * The web framework's normal cycle is to instantiate the WFWebApplication then pass control to the WFRequestController to handle the request. */ function runWebApplication() { $rc = WFRequestController::sharedRequestController(); $rc->handleHTTPRequest(); }
/** * Cause the visitor to be re-directed to the login page. * * OPTIONAL: "continueURL" support. * * This will issue a 302 redirect and exit the current request execution. * * @param string The URL of the page to go to after successful login. Note that this should be a PLAIN URL, but it WILL BE base64-encoded before being passed to the login module. * @param boolean TRUE to force the login screen even if already logged in (used for forcing re-auth of secure areas). */ function doLoginRedirect($continueURL, $reauthorizeEvenIfLoggedIn = false) { $reauthorizeEvenIfLoggedInSuffix = $reauthorizeEvenIfLoggedIn ? "/1" : NULL; $loginInvocationPath = $this->loginInvocationPath(); if (WFRequestController::sharedRequestController()->isAjax()) { header("HTTP/1.0 401 Login Required"); print WWW_ROOT . "/{$loginInvocationPath}/" . WFWebApplication::serializeURL($continueURL) . $reauthorizeEvenIfLoggedInSuffix; } else { header("Location: " . WWW_ROOT . "/{$loginInvocationPath}/" . WFWebApplication::serializeURL($continueURL) . $reauthorizeEvenIfLoggedInSuffix); } exit; }
/** * Cause the visitor to be re-directed to the login page. * * OPTIONAL: "continueURL" support. * * This will issue a 302 redirect and exit the current request execution. * * @param string The URL of the page to go to after successful login. Note that this should be a PLAIN URL, but it WILL BE base64-encoded before being passed to the login module. */ function doLoginRedirect($continueURL) { $loginInvocationPath = $this->loginInvocationPath(); if (WFRequestController::sharedRequestController()->isAjax()) { header("HTTP/1.0 401 Login Required"); print WWW_ROOT . "/{$loginInvocationPath}/" . WFWebApplication::serializeURL($continueURL); } else { header("Location: " . WWW_ROOT . "/{$loginInvocationPath}/" . WFWebApplication::serializeURL($continueURL)); } exit; }
function ajaxButton3($page, $params) { $page->assign('ajaxButtonPressed', 'Third button'); if (WFRequestController::sharedRequestController()->isAjax()) { return WFActionResponsePhocoaUIUpdater::WFActionResponsePhocoaUIUpdater()->addUpdateHTML('ajaxButtonPressed', 'Third Button'); } }