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); } }
/** * The namedContent mechanism for our skin. Here is the catalog: * * mainMenu - An associative array of links ('link name' => 'link url') for the header area. * copyright - a copyright notice, as a string. * */ function namedContent($name, $options = NULL) { switch ($name) { case 'mainMenu': return array('Widget Examples Reference' => WFRequestController::WFURL('examples/widgets/toc'), 'Email' => WFRequestController::WFURL('examples/emailform'), 'phpinfo' => WFRequestController::WFURL('examples/phpinfo'), 'Skin Info' => WFRequestController::WFURL('examples/skininfo')); break; case 'copyright': return "Copyright (c) 2005 Open Development. All Rights Reserved."; break; } }
/** * The namedContent mechanism for our skin. Here is the catalog: * * mainMenu - An associative array of links ('link name' => 'link url') for the header area. * copyright - a copyright notice, as a string. * */ function namedContent($name, $options = NULL) { switch ($name) { case 'mainMenu': return array('Widget Examples Reference' => WFRequestController::WFURL('examples/widgets/toc'), 'Email' => WFRequestController::WFURL('examples/emailform'), 'phpinfo' => WFRequestController::WFURL('examples/phpinfo'), 'Skin Info' => WFRequestController::WFURL('examples/skininfo')); break; case 'copyright': return "© 2005-" . date('Y') . " Alan Pinstein. All Rights Reserved."; break; } }
/** * @todo Build a resource plugin that creates the {WFLabel id="XXX"} on the fly so we can use bindings etc. * @todo also eventually we will have a convention for calling certain methods to get metadata about all discoverable properties. */ function browse_PageDidLoad($page, $params) { $tName = $params['objectName']; try { $tMap = $this->propelDBMap->getTable($tName); } catch (Exception $e) { header("Location: " . WFRequestController::WFURL($this->invocation()->modulePath(), 'objects')); exit; } $peerMethod = $tMap->getPhpName() . "Peer"; // set up paginator; query for data // set up sort links $cols = array(); $sortOptions = array(); $defaultSortKeys = array(); $dynamicWidgetIDs = array(); $primaryKeys = array(); foreach ($tMap->getColumns() as $col) { $cols[$col->getColumnName()] = $col->getPhpName(); $sortOptions['+' . $col->getFullyQualifiedName()] = $col->getPhpName(); $sortOptions['-' . $col->getFullyQualifiedName()] = $col->getPhpName(); if ($col->isPrimaryKey()) { $defaultSortKeys[] = '+' . $col->getFullyQualifiedName(); $primaryKeys[] = $col->getPhpName(); } // create sort widget $sw = new WFPaginatorSortLink("sortLink_" . $col->getPhpName(), $page); $sw->setPaginator($this->paginator); $sw->setValue($col->getFullyQualifiedName()); $dynamicWidgetIDs[$col->getPhpName()]['sortLink'] = $sw->id(); // create label widget via WFDynamic $lw = new WFDynamic("label_" . $col->getPhpName(), $page); $lw->setWidgetClass('WFLabel'); $lw->setArrayController($this->records); $lw->setSimpleBindKeyPath($col->getPhpName()); $labelConfig = array('ellipsisAfterChars' => array('custom' => array('iterate' => false, 'value' => 50))); $lw->setWidgetConfig($labelConfig); $dynamicWidgetIDs[$col->getPhpName()]['label'] = $lw->id(); } $this->paginator->setSortOptions($sortOptions); $this->paginator->setDefaultSortKeys($defaultSortKeys); $this->paginator->setDataDelegate(new WFPagedPropelQuery(new Criteria(), $peerMethod)); $this->paginator->setPaginatorState($params['paginatorState']); $result = $this->paginator->currentItems(); // set up controller $this->records->setClass($tMap->getPhpName()); $this->records->setClassIdentifiers($primaryKeys); $this->records->setContent($result); $page->assign('dynamicWidgetIDs', $dynamicWidgetIDs); $page->assign('tableMap', $tMap); $page->assign('columns', $cols); $page->assign('objects', $result); $this->browseTableName = $tMap->getName(); }
function promptLogin_doLogin_Action($page) { $ac = WFAuthorizationManager::sharedAuthorizationManager(); $ok = $ac->login($page->outlet('username')->value(), $page->outlet('password')->value()); if ($ok) { if ($page->outlet('continueURL')->value()) { header("Location: " . base64_decode($page->outlet('continueURL')->value())); } else { header("Location: " . WFRequestController::WFURL('login', 'showLoginSuccess')); } exit; } else { $page->addError(new WFError("Login username or password is not valid.")); } }
/** * 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(); }
function skinTypes_PageDidLoad($page, $parameters) { $skinTypes = WFSkin::installedSkinTypes(); $page->assign('skinTypes', $skinTypes); $skin = WFRequestController::sharedSkin(); if (!empty($parameters['skinTypeName'])) { $skin->setDelegateName($parameters['skinTypeName']); } $page->assign('currentSkinType', $skin->delegateName()); // show the info for the current skin delegate $contentInfo = array(); foreach ($skin->namedContentList() as $contentName) { $contentInfo[$contentName] = print_r($skin->namedContent($contentName), true); } // get skin list for current skin type $skins = $skin->installedSkins(); $page->assign('skins', $skins); $page->assign('namedContentInfo', $contentInfo); $page->assign('skinDelegateClassName', get_class($skin->valueForKey('delegate'))); }
/** * 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; } }
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"); }
/** * 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(); }
function doForgotPassword_PageDidLoad($page, $params) { // IE sometimes lower-cases URLs for some reason. Help it out. if (!$page->hasOutlet('username')) { throw new WFRequestController_RedirectException(WFRequestController::WFURL($page->module()->moduleName(), 'doForgotPassword')); } $ac = WFAuthorizationManager::sharedAuthorizationManager(); $page->outlet('username')->setValue($params['username']); $page->assign('usernameLabel', $ac->usernameLabel()); }
function ajaxButton3($page, $params) { $page->assign('ajaxButtonPressed', 'Third button'); if (WFRequestController::sharedRequestController()->isAjax()) { return WFActionResponsePhocoaUIUpdater::WFActionResponsePhocoaUIUpdater()->addUpdateHTML('ajaxButtonPressed', 'Third Button'); } }
/** * 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; }
/** * 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(); }
/** * The message to display to a use on unsuccessful login. * * Will call the login delegate method. * * @param string The username that the attempted login was for. * @return mixed string: The message to display on failed login. array of strings; Multiple messages to display (as list items). DEFAULT: string:"Login username or password is not valid." * @see WFAuthorizationDelegate::loginFailedMessage() */ function loginFailedMessage($username) { if (!$this->authorizationDelegate) { throw new Exception("WFAuthorizationDelegate required for loginFailedMessage."); } $loginFailedMessage = 'Login failed for ' . $this->usernameLabel() . ' "' . $username . '". Please check your ' . $this->usernameLabel() . ' and password and try again.'; if ($this->shouldEnableForgottenPasswordReset()) { $loginFailedMessage .= " If you have forgotten your password, <a href=\"" . WFRequestController::WFURL('login', 'doForgotPassword') . '/' . $username . "\">click here</a>."; } if (method_exists($this->authorizationDelegate, 'loginFailedMessage')) { $loginFailedMessage = $this->authorizationDelegate->loginFailedMessage($username); } return $loginFailedMessage; }