idx int64 0 241k | question stringlengths 64 6.21k | target stringlengths 5 803 |
|---|---|---|
4,200 | protected function redirectToSuccess ( array $ data ) { $ link = $ this -> link ( 'passwordsent' ) ; return $ this -> redirect ( $ this -> addBackURLParam ( $ link ) ) ; } | Avoid information disclosure by displaying the same status regardless wether the email address actually exists |
4,201 | public function unshift ( $ key , $ value ) { $ oldItems = $ this -> firstItems ; $ this -> firstItems = array ( $ key => $ value ) ; if ( $ oldItems ) { $ this -> firstItems = $ this -> firstItems + $ oldItems ; } return $ this ; } | Unshift an item onto the start of the map . |
4,202 | public function push ( $ key , $ value ) { $ oldItems = $ this -> lastItems ; $ this -> lastItems = array ( $ key => $ value ) ; if ( $ oldItems ) { $ this -> lastItems = $ this -> lastItems + $ oldItems ; } return $ this ; } | Pushes an item onto the end of the map . |
4,203 | public function getIterator ( ) { return new Map_Iterator ( $ this -> list -> getIterator ( ) , $ this -> keyField , $ this -> valueField , $ this -> firstItems , $ this -> lastItems ) ; } | Returns an Map_Iterator instance for iterating over the complete set of items in the map . |
4,204 | protected function getNameFromParent ( ) { $ base = $ this -> gridField ; $ name = array ( ) ; do { array_unshift ( $ name , $ base -> getName ( ) ) ; $ base = $ base -> getForm ( ) ; } while ( $ base && ! ( $ base instanceof Form ) ) ; return implode ( '.' , $ name ) ; } | Calculate the name of the gridfield relative to the form . |
4,205 | protected function getAuthenticator ( $ name = 'default' ) { $ authenticators = $ this -> authenticators ; if ( isset ( $ authenticators [ $ name ] ) ) { return $ authenticators [ $ name ] ; } throw new LogicException ( 'No valid authenticator found' ) ; } | Get the selected authenticator for this request |
4,206 | public function getApplicableAuthenticators ( $ service = Authenticator :: LOGIN ) { $ authenticators = $ this -> getAuthenticators ( ) ; foreach ( $ authenticators as $ name => $ authenticator ) { if ( ! ( $ authenticator -> supportedServices ( ) & $ service ) ) { unset ( $ authenticators [ $ name ] ) ; } } if ( empty ( $ authenticators ) ) { throw new LogicException ( 'No applicable authenticators found' ) ; } return $ authenticators ; } | Get all registered authenticators |
4,207 | public function getLoginForms ( ) { Deprecation :: notice ( '5.0.0' , 'Now handled by delegateToMultipleHandlers' ) ; return array_map ( function ( Authenticator $ authenticator ) { return [ $ authenticator -> getLoginHandler ( $ this -> Link ( ) ) -> loginForm ( ) ] ; } , $ this -> getApplicableAuthenticators ( ) ) ; } | Get the login forms for all available authentication methods |
4,208 | public function Link ( $ action = null ) { $ link = Controller :: join_links ( Director :: baseURL ( ) , "Security" , $ action ) ; $ this -> extend ( 'updateLink' , $ link , $ action ) ; return $ link ; } | Get a link to a security action |
4,209 | protected function preLogin ( ) { $ eventResults = $ this -> extend ( 'onBeforeSecurityLogin' ) ; if ( $ this -> redirectedTo ( ) ) { return $ this -> getResponse ( ) ; } if ( $ eventResults ) { foreach ( $ eventResults as $ result ) { if ( $ result instanceof HTTPResponse ) { return $ result ; } } } if ( ! $ this -> getSessionMessage ( ) && ( $ member = static :: getCurrentUser ( ) ) && $ member -> exists ( ) && $ this -> getRequest ( ) -> requestVar ( 'BackURL' ) ) { return $ this -> redirectBack ( ) ; } return null ; } | Perform pre - login checking and prepare a response if available prior to login |
4,210 | protected function getResponseController ( $ title ) { $ pageClass = $ this -> config ( ) -> get ( 'page_class' ) ; if ( ! $ pageClass || ! class_exists ( $ pageClass ) ) { return $ this ; } $ holderPage = Injector :: inst ( ) -> create ( $ pageClass ) ; $ holderPage -> Title = $ title ; $ holderPage -> URLSegment = 'Security' ; $ holderPage -> ID = - 1 * random_int ( 1 , 10000000 ) ; $ controller = ModelAsController :: controller_for ( $ holderPage ) ; $ controller -> setRequest ( $ this -> getRequest ( ) ) ; $ controller -> doInit ( ) ; return $ controller ; } | Prepare the controller for handling the response to this request |
4,211 | protected function generateTabbedFormSet ( $ forms ) { if ( count ( $ forms ) === 1 ) { return $ forms ; } $ viewData = new ArrayData ( [ 'Forms' => new ArrayList ( $ forms ) , ] ) ; return $ viewData -> renderWith ( $ this -> getTemplatesFor ( 'MultiAuthenticatorTabbedForms' ) ) ; } | Combine the given forms into a formset with a tabbed interface |
4,212 | public function setSessionMessage ( $ message , $ messageType = ValidationResult :: TYPE_WARNING , $ messageCast = ValidationResult :: CAST_TEXT ) { Controller :: curr ( ) -> getRequest ( ) -> getSession ( ) -> set ( "Security.Message.message" , $ message ) -> set ( "Security.Message.type" , $ messageType ) -> set ( "Security.Message.cast" , $ messageCast ) ; } | Set the next message to display for the security login page . Defaults to warning |
4,213 | public function logout ( $ request = null , $ service = Authenticator :: LOGOUT ) { $ authName = null ; if ( ! $ request ) { $ request = $ this -> getRequest ( ) ; } $ handlers = $ this -> getServiceAuthenticatorsFromRequest ( $ service , $ request ) ; $ link = $ this -> Link ( 'logout' ) ; array_walk ( $ handlers , function ( Authenticator & $ auth , $ name ) use ( $ link ) { $ auth = $ auth -> getLogoutHandler ( Controller :: join_links ( $ link , $ name ) ) ; } ) ; return $ this -> delegateToMultipleHandlers ( $ handlers , _t ( __CLASS__ . '.LOGOUT' , 'Log out' ) , $ this -> getTemplatesFor ( 'logout' ) , [ $ this , 'aggregateAuthenticatorResponses' ] ) ; } | Log the currently logged in user out |
4,214 | protected function getServiceAuthenticatorsFromRequest ( $ service , HTTPRequest $ request ) { $ authName = null ; if ( $ request -> param ( 'ID' ) ) { $ authName = $ request -> param ( 'ID' ) ; } if ( $ authName && $ this -> hasAuthenticator ( $ authName ) ) { if ( $ request ) { $ request -> shift ( ) ; } $ authenticator = $ this -> getAuthenticator ( $ authName ) ; if ( ! $ authenticator -> supportedServices ( ) & $ service ) { $ constants = array_flip ( ( new ReflectionClass ( Authenticator :: class ) ) -> getConstants ( ) ) ; $ message = 'Invalid Authenticator "' . $ authName . '" for ' ; if ( array_key_exists ( $ service , $ constants ) ) { $ message .= 'service: Authenticator::' . $ constants [ $ service ] ; } else { $ message .= 'unknown authenticator service' ; } throw new HTTPResponse_Exception ( $ message , 400 ) ; } $ handlers = [ $ authName => $ authenticator ] ; } else { $ handlers = $ this -> getApplicableAuthenticators ( $ service ) ; } return $ handlers ; } | Get authenticators for the given service optionally filtered by the ID parameter of the current request |
4,215 | protected function aggregateTabbedForms ( array $ results ) { $ forms = [ ] ; foreach ( $ results as $ authName => $ singleResult ) { if ( ! is_array ( $ singleResult ) || ! isset ( $ singleResult [ 'Form' ] ) ) { user_error ( 'Authenticator "' . $ authName . '" doesn\'t support tabbed forms' , E_USER_WARNING ) ; continue ; } $ forms [ ] = $ singleResult [ 'Form' ] ; } if ( ! $ forms ) { throw new \ LogicException ( 'No authenticators found compatible with tabbed forms' ) ; } return [ 'Forms' => ArrayList :: create ( $ forms ) , 'Form' => $ this -> generateTabbedFormSet ( $ forms ) ] ; } | Aggregate tabbed forms from each handler to fragments ready to be rendered . |
4,216 | protected function delegateToMultipleHandlers ( array $ handlers , $ title , array $ templates , callable $ aggregator ) { if ( count ( $ handlers ) === 1 ) { return $ this -> delegateToHandler ( array_values ( $ handlers ) [ 0 ] , $ title , $ templates ) ; } $ results = array_map ( function ( RequestHandler $ handler ) { return $ handler -> handleRequest ( $ this -> getRequest ( ) ) ; } , $ handlers ) ; $ response = call_user_func_array ( $ aggregator , [ $ results ] ) ; if ( is_array ( $ response ) ) { return $ this -> renderWrappedController ( $ title , $ response , $ templates ) ; } return $ response ; } | Delegate to a number of handlers and aggregate the results . This is used for example to build the log - in page where there are multiple authenticators active . |
4,217 | protected function delegateToHandler ( RequestHandler $ handler , $ title , array $ templates = [ ] ) { $ result = $ handler -> handleRequest ( $ this -> getRequest ( ) ) ; if ( is_array ( $ result ) ) { $ result = $ this -> renderWrappedController ( $ title , $ result , $ templates ) ; } return $ result ; } | Delegate to another RequestHandler rendering any fragment arrays into an appropriate . controller . |
4,218 | protected function renderWrappedController ( $ title , array $ fragments , array $ templates ) { $ controller = $ this -> getResponseController ( $ title ) ; if ( ( $ response = $ controller -> getResponse ( ) ) && $ response -> isFinished ( ) ) { return $ response ; } $ messageType = '' ; $ message = $ this -> getSessionMessage ( $ messageType ) ; static :: clearSessionMessage ( ) ; if ( $ message ) { $ messageResult = [ 'Content' => DBField :: create_field ( 'HTMLFragment' , $ message ) , 'Message' => DBField :: create_field ( 'HTMLFragment' , $ message ) , 'MessageType' => $ messageType ] ; $ fragments = array_merge ( $ fragments , $ messageResult ) ; } return $ controller -> customise ( $ fragments ) -> renderWith ( $ templates ) ; } | Render the given fragments into a security page controller with the given title . |
4,219 | public function lostpassword ( ) { $ handlers = [ ] ; $ authenticators = $ this -> getApplicableAuthenticators ( Authenticator :: RESET_PASSWORD ) ; foreach ( $ authenticators as $ authenticator ) { $ handlers [ ] = $ authenticator -> getLostPasswordHandler ( Controller :: join_links ( $ this -> Link ( ) , 'lostpassword' ) ) ; } return $ this -> delegateToMultipleHandlers ( $ handlers , _t ( 'SilverStripe\\Security\\Security.LOSTPASSWORDHEADER' , 'Lost Password' ) , $ this -> getTemplatesFor ( 'lostpassword' ) , [ $ this , 'aggregateAuthenticatorResponses' ] ) ; } | Show the lost password page |
4,220 | public function getTemplatesFor ( $ action ) { $ templates = SSViewer :: get_templates_by_class ( static :: class , "_{$action}" , __CLASS__ ) ; return array_merge ( $ templates , [ "Security_{$action}" , "Security" , $ this -> config ( ) -> get ( "template_main" ) , "BlankPage" ] ) ; } | Determine the list of templates to use for rendering the given action . |
4,221 | public static function setDefaultAdmin ( $ username , $ password ) { Deprecation :: notice ( '5.0.0' , 'Please use DefaultAdminService::setDefaultAdmin($username, $password)' ) ; DefaultAdminService :: setDefaultAdmin ( $ username , $ password ) ; return true ; } | Set a default admin in dev - mode |
4,222 | public static function logout_url ( ) { $ logoutUrl = Controller :: join_links ( Director :: baseURL ( ) , self :: config ( ) -> get ( 'logout_url' ) ) ; return SecurityToken :: inst ( ) -> addToUrl ( $ logoutUrl ) ; } | Get the URL of the logout page . |
4,223 | public function setValue ( $ value , $ obj = null ) { if ( $ obj instanceof DataObject ) { $ this -> loadFrom ( $ obj ) ; } else { parent :: setValue ( $ value ) ; } return $ this ; } | Load a value into this MultiSelectField |
4,224 | public function loadFrom ( DataObjectInterface $ record ) { $ fieldName = $ this -> getName ( ) ; if ( empty ( $ fieldName ) || empty ( $ record ) ) { return ; } $ relation = $ record -> hasMethod ( $ fieldName ) ? $ record -> $ fieldName ( ) : null ; if ( $ relation instanceof Relation ) { $ value = array_values ( $ relation -> getIDList ( ) ) ; parent :: setValue ( $ value ) ; } elseif ( $ record -> hasField ( $ fieldName ) ) { if ( $ record -> obj ( $ fieldName ) instanceof DBMultiEnum ) { $ value = $ this -> csvDecode ( $ record -> $ fieldName ) ; } else { $ value = $ this -> stringDecode ( $ record -> $ fieldName ) ; } parent :: setValue ( $ value ) ; } } | Load the value from the dataobject into this field |
4,225 | protected function stringDecode ( $ value ) { if ( empty ( $ value ) ) { return array ( ) ; } $ result = json_decode ( $ value , true ) ; if ( $ result !== false ) { return $ result ; } throw new \ InvalidArgumentException ( "Invalid string encoded value for multi select field" ) ; } | Extract a string value into an array of values |
4,226 | protected function csvEncode ( $ value ) { if ( ! $ value ) { return null ; } return implode ( ',' , array_map ( function ( $ x ) { return str_replace ( ',' , '' , $ x ) ; } , array_values ( $ value ) ) ) ; } | Encode a list of values into a string as a comma separated list . Commas will be stripped from the items passed in |
4,227 | public function getItemPath ( $ class ) { foreach ( array_reverse ( $ this -> manifests ) as $ manifest ) { $ manifestInst = $ manifest [ 'instance' ] ; if ( $ path = $ manifestInst -> getItemPath ( $ class ) ) { return $ path ; } if ( $ manifest [ 'exclusive' ] ) { break ; } } return false ; } | Returns the path for a class or interface in the currently active manifest or any previous ones if later manifests aren t set to exclusive . |
4,228 | public function init ( $ includeTests = false , $ forceRegen = false ) { foreach ( $ this -> manifests as $ manifest ) { $ instance = $ manifest [ 'instance' ] ; $ instance -> init ( $ includeTests , $ forceRegen ) ; } $ this -> registerAutoloader ( ) ; } | Initialise the class loader |
4,229 | public static function check ( $ code , $ arg = "any" , $ member = null , $ strict = true ) { if ( ! $ member ) { if ( ! Security :: getCurrentUser ( ) ) { return false ; } $ member = Security :: getCurrentUser ( ) ; } return self :: checkMember ( $ member , $ code , $ arg , $ strict ) ; } | Check that the current member has the given permission . |
4,230 | public static function permissions_for_member ( $ memberID ) { $ groupList = self :: groupList ( $ memberID ) ; if ( $ groupList ) { $ groupCSV = implode ( ", " , $ groupList ) ; $ allowed = array_unique ( DB :: query ( " SELECT \"Code\" FROM \"Permission\" WHERE \"Type\" = " . self :: GRANT_PERMISSION . " AND \"GroupID\" IN ($groupCSV) UNION SELECT \"Code\" FROM \"PermissionRoleCode\" PRC INNER JOIN \"PermissionRole\" PR ON PRC.\"RoleID\" = PR.\"ID\" INNER JOIN \"Group_Roles\" GR ON GR.\"PermissionRoleID\" = PR.\"ID\" WHERE \"GroupID\" IN ($groupCSV) " ) -> column ( ) ) ; $ denied = array_unique ( DB :: query ( " SELECT \"Code\" FROM \"Permission\" WHERE \"Type\" = " . self :: DENY_PERMISSION . " AND \"GroupID\" IN ($groupCSV) " ) -> column ( ) ) ; return array_diff ( $ allowed , $ denied ) ; } return array ( ) ; } | Get all the any permission codes available to the given member . |
4,231 | public static function groupList ( $ memberID = null ) { if ( ! $ memberID ) { $ member = Security :: getCurrentUser ( ) ; if ( $ member && isset ( $ _SESSION [ 'Permission_groupList' ] [ $ member -> ID ] ) ) { return $ _SESSION [ 'Permission_groupList' ] [ $ member -> ID ] ; } } else { $ member = DataObject :: get_by_id ( "SilverStripe\\Security\\Member" , $ memberID ) ; } if ( $ member ) { $ groups = $ member -> Groups ( ) ; $ groupList = array ( ) ; if ( $ groups ) { foreach ( $ groups as $ group ) { $ groupList [ ] = $ group -> ID ; } } if ( ! $ memberID ) { $ _SESSION [ 'Permission_groupList' ] [ $ member -> ID ] = $ groupList ; } return isset ( $ groupList ) ? $ groupList : null ; } return null ; } | Get the list of groups that the given member belongs to . |
4,232 | public static function get_members_by_permission ( $ code ) { $ toplevelGroups = self :: get_groups_by_permission ( $ code ) ; if ( ! $ toplevelGroups ) { return new ArrayList ( ) ; } $ groupIDs = array ( ) ; foreach ( $ toplevelGroups as $ group ) { $ familyIDs = $ group -> collateFamilyIDs ( ) ; if ( is_array ( $ familyIDs ) ) { $ groupIDs = array_merge ( $ groupIDs , array_values ( $ familyIDs ) ) ; } } if ( empty ( $ groupIDs ) ) { return new ArrayList ( ) ; } $ groupClause = DB :: placeholders ( $ groupIDs ) ; $ members = Member :: get ( ) -> where ( array ( "\"Group\".\"ID\" IN ($groupClause)" => $ groupIDs ) ) -> leftJoin ( "Group_Members" , '"Member"."ID" = "Group_Members"."MemberID"' ) -> leftJoin ( "Group" , '"Group_Members"."GroupID" = "Group"."ID"' ) ; return $ members ; } | Returns all members for a specific permission . |
4,233 | public static function get_groups_by_permission ( $ codes ) { $ codeParams = is_array ( $ codes ) ? $ codes : array ( $ codes ) ; $ codeClause = DB :: placeholders ( $ codeParams ) ; return Group :: get ( ) -> where ( array ( "\"PermissionRoleCode\".\"Code\" IN ($codeClause) OR \"Permission\".\"Code\" IN ($codeClause)" => array_merge ( $ codeParams , $ codeParams ) ) ) -> leftJoin ( 'Permission' , "\"Permission\".\"GroupID\" = \"Group\".\"ID\"" ) -> leftJoin ( 'Group_Roles' , "\"Group_Roles\".\"GroupID\" = \"Group\".\"ID\"" ) -> leftJoin ( 'PermissionRole' , "\"Group_Roles\".\"PermissionRoleID\" = \"PermissionRole\".\"ID\"" ) -> leftJoin ( 'PermissionRoleCode' , "\"PermissionRoleCode\".\"RoleID\" = \"PermissionRole\".\"ID\"" ) ; } | Return all of the groups that have one of the given permission codes |
4,234 | public static function sort_permissions ( $ a , $ b ) { if ( $ a [ 'sort' ] == $ b [ 'sort' ] ) { return strcmp ( $ a [ 'name' ] , $ b [ 'name' ] ) ; } else { return $ a [ 'sort' ] < $ b [ 'sort' ] ? - 1 : 1 ; } } | Sort permissions based on their sort value or name |
4,235 | public static function get_declared_permissions_list ( ) { if ( ! self :: $ declared_permissions ) { return null ; } if ( self :: $ declared_permissions_list ) { return self :: $ declared_permissions_list ; } self :: $ declared_permissions_list = array ( ) ; self :: traverse_declared_permissions ( self :: $ declared_permissions , self :: $ declared_permissions_list ) ; return self :: $ declared_permissions_list ; } | Get a linear list of the permissions in the system . |
4,236 | protected static function traverse_declared_permissions ( $ declared , & $ list ) { if ( ! is_array ( $ declared ) ) { return ; } foreach ( $ declared as $ perm => $ value ) { if ( $ value instanceof Permission_Group ) { $ list [ ] = $ value -> getName ( ) ; self :: traverse_declared_permissions ( $ value -> getPermissions ( ) , $ list ) ; } else { $ list [ $ perm ] = $ value ; } } } | Recursively traverse the nested list of declared permissions and create a linear list . |
4,237 | public function getComponentsByType ( $ type ) { $ components = new ArrayList ( ) ; foreach ( $ this -> components as $ component ) { if ( $ component instanceof $ type ) { $ components -> push ( $ component ) ; } } return $ components ; } | Returns all components extending a certain class or implementing a certain interface . |
4,238 | public function getComponentByType ( $ type ) { foreach ( $ this -> components as $ component ) { if ( $ component instanceof $ type ) { return $ component ; } } return null ; } | Returns the first available component with the given class or interface . |
4,239 | public function validate ( ) { $ this -> resetResult ( ) ; if ( $ this -> getEnabled ( ) ) { $ this -> php ( $ this -> form -> getData ( ) ) ; } return $ this -> result ; } | Returns any errors there may be . |
4,240 | public static function handle_shortcode ( $ arguments , $ content , $ parser , $ shortcode , $ extra = array ( ) ) { if ( ! empty ( $ content ) ) { $ serviceURL = $ content ; } elseif ( ! empty ( $ arguments [ 'url' ] ) ) { $ serviceURL = $ arguments [ 'url' ] ; } else { return '' ; } $ serviceArguments = [ ] ; if ( ! empty ( $ arguments [ 'width' ] ) ) { $ serviceArguments [ 'min_image_width' ] = $ arguments [ 'width' ] ; } if ( ! empty ( $ arguments [ 'height' ] ) ) { $ serviceArguments [ 'min_image_height' ] = $ arguments [ 'height' ] ; } $ embed = Injector :: inst ( ) -> create ( Embeddable :: class , $ serviceURL ) ; if ( ! empty ( $ serviceArguments ) ) { $ embed -> setOptions ( array_merge ( $ serviceArguments , ( array ) $ embed -> getOptions ( ) ) ) ; } $ dispatcher = null ; if ( isset ( $ extra [ 'resolver' ] ) ) { $ dispatcher = Injector :: inst ( ) -> create ( $ extra [ 'resolver' ] [ 'class' ] , $ serviceURL , $ extra [ 'resolver' ] [ 'config' ] ) ; } elseif ( Injector :: inst ( ) -> has ( DispatcherInterface :: class ) ) { $ dispatcher = Injector :: inst ( ) -> get ( DispatcherInterface :: class ) ; } if ( $ dispatcher ) { $ embed -> setDispatcher ( $ dispatcher ) ; } $ embed = $ embed -> getEmbed ( ) ; if ( $ embed && $ embed instanceof Adapter ) { $ result = static :: embedForTemplate ( $ embed , $ arguments ) ; if ( $ result ) { return $ result ; } } return static :: linkEmbed ( $ arguments , $ serviceURL , $ serviceURL ) ; } | Embed shortcode parser from Oembed . This is a temporary workaround . Oembed class has been replaced with the Embed external service . |
4,241 | protected static function videoEmbed ( $ arguments , $ content ) { if ( ! empty ( $ arguments [ 'width' ] ) ) { $ arguments [ 'style' ] = 'width: ' . intval ( $ arguments [ 'width' ] ) . 'px;' ; } if ( ! empty ( $ arguments [ 'caption' ] ) ) { $ xmlCaption = Convert :: raw2xml ( $ arguments [ 'caption' ] ) ; $ content .= "\n<p class=\"caption\">{$xmlCaption}</p>" ; } unset ( $ arguments [ 'width' ] ) ; unset ( $ arguments [ 'height' ] ) ; unset ( $ arguments [ 'url' ] ) ; unset ( $ arguments [ 'caption' ] ) ; return HTML :: createTag ( 'div' , $ arguments , $ content ) ; } | Build video embed tag |
4,242 | public function getSchemaDataDefaults ( ) { $ defaults = parent :: getSchemaDataDefaults ( ) ; $ children = $ this -> getChildren ( ) ; if ( $ children && $ children -> count ( ) ) { $ childSchema = [ ] ; foreach ( $ children as $ child ) { $ childSchema [ ] = $ child -> getSchemaData ( ) ; } $ defaults [ 'children' ] = $ childSchema ; } $ defaults [ 'data' ] [ 'tag' ] = $ this -> getTag ( ) ; $ defaults [ 'data' ] [ 'legend' ] = $ this -> getLegend ( ) ; $ defaults [ 'data' ] [ 'inherited' ] = [ 'data' => [ 'fieldholder' => 'small' ] , ] ; return $ defaults ; } | Merge child field data into this form |
4,243 | public function collateDataFields ( & $ list , $ saveableOnly = false ) { foreach ( $ this -> children as $ field ) { if ( ! $ field instanceof FormField ) { continue ; } if ( $ field instanceof CompositeField ) { $ field -> collateDataFields ( $ list , $ saveableOnly ) ; } if ( $ saveableOnly ) { $ isIncluded = ( $ field -> hasData ( ) && ! $ field -> isReadonly ( ) && ! $ field -> isDisabled ( ) ) ; } else { $ isIncluded = ( $ field -> hasData ( ) ) ; } if ( $ isIncluded ) { $ name = $ field -> getName ( ) ; if ( $ name ) { $ formName = ( isset ( $ this -> form ) ) ? $ this -> form -> FormName ( ) : '(unknown form)' ; if ( isset ( $ list [ $ name ] ) ) { $ fieldClass = get_class ( $ field ) ; $ otherFieldClass = get_class ( $ list [ $ name ] ) ; user_error ( "collateDataFields() I noticed that a field called '$name' appears twice in" . " your form: '{$formName}'. One is a '{$fieldClass}' and the other is a" . " '{$otherFieldClass}'" , E_USER_ERROR ) ; } $ list [ $ name ] = $ field ; } } } } | Add all of the non - composite fields contained within this field to the list . |
4,244 | public function makeFieldReadonly ( $ field ) { $ fieldName = ( $ field instanceof FormField ) ? $ field -> getName ( ) : $ field ; foreach ( $ this -> children as $ i => $ item ) { if ( $ item instanceof CompositeField ) { if ( $ item -> makeFieldReadonly ( $ fieldName ) ) { return true ; } ; } elseif ( $ item instanceof FormField && $ item -> getName ( ) == $ fieldName ) { $ this -> children -> replaceField ( $ fieldName , $ item -> transform ( new ReadonlyTransformation ( ) ) ) ; return true ; } } return false ; } | Transform the named field into a readonly feld . |
4,245 | public function renameTable ( $ old , $ new ) { $ this -> replaceText ( "`$old`" , "`$new`" ) ; $ this -> replaceText ( "\"$old\"" , "\"$new\"" ) ; $ this -> replaceText ( Convert :: symbol2sql ( $ old ) , Convert :: symbol2sql ( $ new ) ) ; } | Swap the use of one table with another . |
4,246 | public function sql ( & $ parameters = array ( ) ) { $ sql = DB :: build_sql ( $ this , $ parameters ) ; if ( empty ( $ sql ) ) { return null ; } if ( $ this -> replacementsOld ) { $ sql = str_replace ( $ this -> replacementsOld , $ this -> replacementsNew , $ sql ) ; } return $ sql ; } | Generate the SQL statement for this query . |
4,247 | protected function copyTo ( SQLExpression $ object ) { $ target = array_keys ( get_object_vars ( $ object ) ) ; foreach ( get_object_vars ( $ this ) as $ variable => $ value ) { if ( in_array ( $ variable , $ target ) ) { $ object -> $ variable = $ value ; } } } | Copies the query parameters contained in this object to another SQLExpression |
4,248 | public function getTargetMember ( ) { $ tempid = $ this -> getRequest ( ) -> requestVar ( 'tempid' ) ; if ( $ tempid ) { return Member :: member_from_tempid ( $ tempid ) ; } return null ; } | Get known logged out member |
4,249 | protected function redirectToExternalLogin ( ) { $ loginURL = Security :: create ( ) -> Link ( 'login' ) ; $ loginURLATT = Convert :: raw2att ( $ loginURL ) ; $ loginURLJS = Convert :: raw2js ( $ loginURL ) ; $ message = _t ( __CLASS__ . '.INVALIDUSER' , '<p>Invalid user. <a target="_top" href="{link}">Please re-authenticate here</a> to continue.</p>' , 'Message displayed to user if their session cannot be restored' , array ( 'link' => $ loginURLATT ) ) ; $ response = $ this -> getResponse ( ) ; $ response -> setStatusCode ( 200 ) ; $ response -> setBody ( <<<PHP<!DOCTYPE html><html><body>$message<script type="application/javascript">setTimeout(function(){top.location.href = "$loginURLJS";}, 0);</script></body></html>PHP ) ; $ this -> setResponse ( $ response ) ; return $ response ; } | Redirects the user to the external login page |
4,250 | public function success ( ) { if ( ! Security :: getCurrentUser ( ) || ! class_exists ( AdminRootController :: class ) ) { return $ this -> redirectToExternalLogin ( ) ; } $ controller = $ this -> getResponseController ( _t ( __CLASS__ . '.SUCCESS' , 'Success' ) ) ; $ backURLs = array ( $ this -> getRequest ( ) -> requestVar ( 'BackURL' ) , $ this -> getRequest ( ) -> getSession ( ) -> get ( 'BackURL' ) , Director :: absoluteURL ( AdminRootController :: config ( ) -> get ( 'url_base' ) , true ) , ) ; $ backURL = null ; foreach ( $ backURLs as $ backURL ) { if ( $ backURL && Director :: is_site_url ( $ backURL ) ) { break ; } } $ controller = $ controller -> customise ( array ( 'Content' => DBField :: create_field ( DBHTMLText :: class , _t ( __CLASS__ . '.SUCCESSCONTENT' , '<p>Login success. If you are not automatically redirected ' . '<a target="_top" href="{link}">click here</a></p>' , 'Login message displayed in the cms popup once a user has re-authenticated themselves' , array ( 'link' => Convert :: raw2att ( $ backURL ) ) ) ) ) ) ; return $ controller -> renderWith ( $ this -> getTemplatesFor ( 'success' ) ) ; } | Given a successful login tell the parent frame to close the dialog |
4,251 | protected function sendNotModified ( HTTPRequest $ request , HTTPResponse $ response ) { if ( in_array ( $ request -> httpMethod ( ) , [ 'POST' , 'DELETE' , 'PUT' ] ) ) { $ response -> setStatusCode ( 412 ) ; } else { $ response -> setStatusCode ( 304 ) ; } $ response -> setBody ( '' ) ; return $ response ; } | Sent not - modified response |
4,252 | protected function buildCurrencyField ( ) { $ name = $ this -> getName ( ) ; $ currencyValue = $ this -> fieldCurrency ? $ this -> fieldCurrency -> dataValue ( ) : null ; $ allowedCurrencies = $ this -> getAllowedCurrencies ( ) ; if ( count ( $ allowedCurrencies ) === 1 ) { $ field = HiddenField :: create ( "{$name}[Currency]" ) ; reset ( $ allowedCurrencies ) ; $ currencyValue = key ( $ allowedCurrencies ) ; } elseif ( $ allowedCurrencies ) { $ field = DropdownField :: create ( "{$name}[Currency]" , _t ( 'SilverStripe\\Forms\\MoneyField.FIELDLABELCURRENCY' , 'Currency' ) , $ allowedCurrencies ) ; } else { $ field = TextField :: create ( "{$name}[Currency]" , _t ( 'SilverStripe\\Forms\\MoneyField.FIELDLABELCURRENCY' , 'Currency' ) ) ; } $ field -> setReadonly ( $ this -> isReadonly ( ) ) ; $ field -> setDisabled ( $ this -> isDisabled ( ) ) ; if ( $ currencyValue ) { $ field -> setValue ( $ currencyValue ) ; } $ this -> fieldCurrency = $ field ; return $ field ; } | Builds a new currency field based on the allowed currencies configured |
4,253 | protected function getDBMoney ( ) { return DBMoney :: create_field ( 'Money' , [ 'Currency' => $ this -> fieldCurrency -> dataValue ( ) , 'Amount' => $ this -> fieldAmount -> dataValue ( ) ] ) -> setLocale ( $ this -> getLocale ( ) ) ; } | Get value as DBMoney object useful for formatting the number |
4,254 | public function setAllowedCurrencies ( $ currencies ) { if ( empty ( $ currencies ) ) { $ currencies = [ ] ; } elseif ( is_string ( $ currencies ) ) { $ currencies = [ $ currencies => $ currencies ] ; } elseif ( ! is_array ( $ currencies ) ) { throw new InvalidArgumentException ( "Invalid currency list" ) ; } elseif ( ! ArrayLib :: is_associative ( $ currencies ) ) { $ currencies = array_combine ( $ currencies , $ currencies ) ; } $ this -> allowedCurrencies = $ currencies ; $ this -> buildCurrencyField ( ) ; return $ this ; } | Set list of currencies . Currencies should be in the 3 - letter ISO 4217 currency code . |
4,255 | public function Breadcrumbs ( ) { $ basePath = str_replace ( Director :: protocolAndHost ( ) , '' , Director :: absoluteBaseURL ( ) ) ; $ relPath = parse_url ( substr ( $ _SERVER [ 'REQUEST_URI' ] , strlen ( $ basePath ) , strlen ( $ _SERVER [ 'REQUEST_URI' ] ) ) , PHP_URL_PATH ) ; $ parts = explode ( '/' , $ relPath ) ; $ base = Director :: absoluteBaseURL ( ) ; $ pathPart = "" ; $ pathLinks = array ( ) ; foreach ( $ parts as $ part ) { if ( $ part != '' ) { $ pathPart .= "$part/" ; $ pathLinks [ ] = "<a href=\"$base$pathPart\">$part</a>" ; } } return implode ( ' → ' , $ pathLinks ) ; } | Generate breadcrumb links to the URL path being displayed |
4,256 | public function renderHeader ( $ httpRequest = null ) { $ url = htmlentities ( $ _SERVER [ 'REQUEST_METHOD' ] . ' ' . $ _SERVER [ 'REQUEST_URI' ] , ENT_COMPAT , 'UTF-8' ) ; $ debugCSS = ModuleResourceLoader :: singleton ( ) -> resolveURL ( 'silverstripe/framework:client/styles/debug.css' ) ; $ output = '<!DOCTYPE html><html><head><title>' . $ url . '</title>' ; $ output .= '<link rel="stylesheet" type="text/css" href="' . $ debugCSS . '" />' ; $ output .= '</head>' ; $ output .= '<body>' ; return $ output ; } | Render HTML header for development views |
4,257 | public function renderError ( $ httpRequest , $ errno , $ errstr , $ errfile , $ errline ) { $ errorType = isset ( self :: $ error_types [ $ errno ] ) ? self :: $ error_types [ $ errno ] : self :: $ unknown_error ; $ httpRequestEnt = htmlentities ( $ httpRequest , ENT_COMPAT , 'UTF-8' ) ; if ( ini_get ( 'html_errors' ) ) { $ errstr = strip_tags ( $ errstr ) ; } else { $ errstr = Convert :: raw2xml ( $ errstr ) ; } $ output = '<div class="header info ' . $ errorType [ 'class' ] . '">' ; $ output .= "<h1>[" . $ errorType [ 'title' ] . '] ' . $ errstr . "</h1>" ; $ output .= "<h3>$httpRequestEnt</h3>" ; $ output .= "<p>Line <strong>$errline</strong> in <strong>$errfile</strong></p>" ; $ output .= '</div>' ; return $ output ; } | Render an error . |
4,258 | public function renderSourceFragment ( $ lines , $ errline ) { $ output = '<div class="info"><h3>Source</h3>' ; $ output .= '<pre>' ; foreach ( $ lines as $ offset => $ line ) { $ line = htmlentities ( $ line , ENT_COMPAT , 'UTF-8' ) ; if ( $ offset == $ errline ) { $ output .= "<span>$offset</span> <span class=\"error\">$line</span>" ; } else { $ output .= "<span>$offset</span> $line" ; } } $ output .= '</pre></div>' ; return $ output ; } | Render a fragment of the a source file |
4,259 | public function renderTrace ( $ trace ) { $ output = '<div class="info">' ; $ output .= '<h3>Trace</h3>' ; $ output .= Backtrace :: get_rendered_backtrace ( $ trace ) ; $ output .= '</div>' ; return $ output ; } | Render a call track |
4,260 | public function renderVariable ( $ val , $ caller ) { $ output = '<pre style="background-color:#ccc;padding:5px;font-size:14px;line-height:18px;">' ; $ output .= "<span style=\"font-size: 12px;color:#666;\">" . $ this -> formatCaller ( $ caller ) . " - </span>\n" ; if ( is_string ( $ val ) ) { $ output .= wordwrap ( $ val , self :: config ( ) -> columns ) ; } else { $ output .= var_export ( $ val , true ) ; } $ output .= '</pre>' ; return $ output ; } | Outputs a variable in a user presentable way |
4,261 | public function addFrom ( $ from ) { if ( is_array ( $ from ) ) { $ this -> from = array_merge ( $ this -> from , $ from ) ; } elseif ( ! empty ( $ from ) ) { $ this -> from [ str_replace ( array ( '"' , '`' ) , '' , $ from ) ] = $ from ; } return $ this ; } | Add a table to include in the query or update |
4,262 | public function addLeftJoin ( $ table , $ onPredicate , $ tableAlias = '' , $ order = 20 , $ parameters = array ( ) ) { if ( ! $ tableAlias ) { $ tableAlias = $ table ; } $ this -> from [ $ tableAlias ] = array ( 'type' => 'LEFT' , 'table' => $ table , 'filter' => array ( $ onPredicate ) , 'order' => $ order , 'parameters' => $ parameters ) ; return $ this ; } | Add a LEFT JOIN criteria to the tables list . |
4,263 | public function addInnerJoin ( $ table , $ onPredicate , $ tableAlias = null , $ order = 20 , $ parameters = array ( ) ) { if ( ! $ tableAlias ) { $ tableAlias = $ table ; } $ this -> from [ $ tableAlias ] = array ( 'type' => 'INNER' , 'table' => $ table , 'filter' => array ( $ onPredicate ) , 'order' => $ order , 'parameters' => $ parameters ) ; return $ this ; } | Add an INNER JOIN criteria |
4,264 | public function queriedTables ( ) { $ tables = array ( ) ; foreach ( $ this -> from as $ key => $ tableClause ) { if ( is_array ( $ tableClause ) ) { $ table = '"' . $ tableClause [ 'table' ] . '"' ; } elseif ( is_string ( $ tableClause ) && preg_match ( '/JOIN +("[^"]+") +(AS|ON) +/i' , $ tableClause , $ matches ) ) { $ table = $ matches [ 1 ] ; } else { $ table = $ tableClause ; } if ( $ this -> replacementsOld ) { $ table = str_replace ( $ this -> replacementsOld , $ this -> replacementsNew , $ table ) ; } $ tables [ ] = preg_replace ( '/^"|"$/' , '' , $ table ) ; } return $ tables ; } | Return a list of tables that this query is selecting from . |
4,265 | public function getJoins ( & $ parameters = array ( ) ) { if ( func_num_args ( ) == 0 ) { Deprecation :: notice ( '4.0' , 'SQLConditionalExpression::getJoins() now may produce parameters which are necessary to execute this query' ) ; } $ parameters = array ( ) ; $ joins = $ this -> getOrderedJoins ( $ this -> from ) ; foreach ( $ joins as $ alias => $ join ) { if ( ! is_array ( $ join ) ) { if ( empty ( $ alias ) || is_numeric ( $ alias ) ) { continue ; } if ( preg_match ( '/AS\s+(?:"[^"]+"|[A-Z0-9_]+)\s*$/i' , $ join ) ) { continue ; } $ trimmedAlias = trim ( $ alias , '"' ) ; if ( $ trimmedAlias !== trim ( $ join , '"' ) ) { $ joins [ $ alias ] = "{$join} AS \"{$trimmedAlias}\"" ; } continue ; } if ( is_string ( $ join [ 'filter' ] ) ) { $ filter = $ join [ 'filter' ] ; } elseif ( sizeof ( $ join [ 'filter' ] ) == 1 ) { $ filter = $ join [ 'filter' ] [ 0 ] ; } else { $ filter = "(" . implode ( ") AND (" , $ join [ 'filter' ] ) . ")" ; } $ table = preg_match ( '/\bSELECT\b/i' , $ join [ 'table' ] ) ? $ join [ 'table' ] : "\"{$join['table']}\"" ; $ aliasClause = ( $ alias != $ join [ 'table' ] ) ? " AS \"{$alias}\"" : "" ; $ joins [ $ alias ] = strtoupper ( $ join [ 'type' ] ) . " JOIN " . $ table . "$aliasClause ON $filter" ; if ( ! empty ( $ join [ 'parameters' ] ) ) { $ parameters = array_merge ( $ parameters , $ join [ 'parameters' ] ) ; } } return $ joins ; } | Retrieves the finalised list of joins |
4,266 | public function setWhere ( $ where ) { $ where = func_num_args ( ) > 1 ? func_get_args ( ) : $ where ; $ this -> where = array ( ) ; return $ this -> addWhere ( $ where ) ; } | Set a WHERE clause . |
4,267 | public function filtersOnID ( ) { $ regexp = '/^(.*\.)?("|`)?ID("|`)?\s?(=|IN)/' ; foreach ( $ this -> getWhereParameterised ( $ parameters ) as $ predicate ) { if ( preg_match ( $ regexp , $ predicate ) ) { return true ; } } return false ; } | Checks whether this query is for a specific ID in a table |
4,268 | protected function isAPCUSupported ( ) { static $ apcuSupported = null ; if ( null === $ apcuSupported ) { $ apcuSupported = Director :: is_cli ( ) ? ini_get ( 'apc.enable_cli' ) && ApcuAdapter :: isSupported ( ) : ApcuAdapter :: isSupported ( ) ; } return $ apcuSupported ; } | Determine if apcu is supported |
4,269 | protected function getFormatter ( ) { if ( $ this -> getHTML5 ( ) ) { $ formatter = NumberFormatter :: create ( i18n :: config ( ) -> uninherited ( 'default_locale' ) , NumberFormatter :: DECIMAL ) ; $ formatter -> setAttribute ( NumberFormatter :: GROUPING_USED , false ) ; $ formatter -> setSymbol ( NumberFormatter :: DECIMAL_SEPARATOR_SYMBOL , '.' ) ; } else { $ formatter = NumberFormatter :: create ( $ this -> getLocale ( ) , NumberFormatter :: DECIMAL ) ; } $ scale = $ this -> getScale ( ) ; if ( $ scale === 0 ) { $ formatter -> setAttribute ( NumberFormatter :: DECIMAL_ALWAYS_SHOWN , false ) ; $ formatter -> setAttribute ( NumberFormatter :: FRACTION_DIGITS , 0 ) ; } else { $ formatter -> setAttribute ( NumberFormatter :: DECIMAL_ALWAYS_SHOWN , true ) ; if ( $ scale === null ) { $ formatter -> setAttribute ( NumberFormatter :: MIN_FRACTION_DIGITS , 1 ) ; } else { $ formatter -> setAttribute ( NumberFormatter :: FRACTION_DIGITS , $ scale ) ; } } return $ formatter ; } | Get number formatter for localising this field |
4,270 | public function Value ( ) { if ( $ this -> value === null || $ this -> value === false ) { return $ this -> originalValue ; } $ formatter = $ this -> getFormatter ( ) ; return $ formatter -> format ( $ this -> value , $ this -> getNumberType ( ) ) ; } | Format value for output |
4,271 | protected function cast ( $ value ) { if ( strlen ( $ value ) === 0 ) { return null ; } if ( $ this -> getScale ( ) === 0 ) { return ( int ) $ value ; } return ( float ) $ value ; } | Helper to cast non - localised strings to their native type |
4,272 | public function setMessage ( $ message , $ messageType = ValidationResult :: TYPE_ERROR , $ messageCast = ValidationResult :: CAST_TEXT ) { if ( ! in_array ( $ messageCast , [ ValidationResult :: CAST_TEXT , ValidationResult :: CAST_HTML ] ) ) { throw new InvalidArgumentException ( "Invalid message cast type" ) ; } $ this -> message = $ message ; $ this -> messageType = $ messageType ; $ this -> messageCast = $ messageCast ; return $ this ; } | Sets the error message to be displayed on the form field . |
4,273 | public function getSchemaMessage ( ) { $ message = $ this -> getMessage ( ) ; if ( ! $ message ) { return null ; } if ( $ this -> getMessageCast ( ) === ValidationResult :: CAST_HTML ) { $ message = [ 'html' => $ message ] ; } return [ 'value' => $ message , 'type' => $ this -> getMessageType ( ) , ] ; } | Get form schema encoded message |
4,274 | protected function isTrustedProxy ( HTTPRequest $ request ) { $ trustedIPs = $ this -> getTrustedProxyIPs ( ) ; if ( empty ( $ trustedIPs ) || $ trustedIPs === 'none' ) { return false ; } if ( $ trustedIPs === '*' ) { return true ; } $ ip = $ request -> getIP ( ) ; if ( $ ip ) { return IPUtils :: checkIP ( $ ip , preg_split ( '/\s*,\s*/' , $ trustedIPs ) ) ; } return false ; } | Determine if the current request is coming from a trusted proxy |
4,275 | protected function getIPFromHeaderValue ( $ headerValue ) { $ ips = preg_split ( '/\s*,\s*/' , $ headerValue ) ; $ filters = [ FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE , FILTER_FLAG_NO_PRIV_RANGE , null ] ; foreach ( $ filters as $ filter ) { foreach ( $ ips as $ ip ) { if ( filter_var ( $ ip , FILTER_VALIDATE_IP , $ filter ) ) { return $ ip ; } } } return null ; } | Extract an IP address from a header value that has been obtained . Accepts single IP or comma separated string of IPs |
4,276 | protected function normaliseMessages ( $ messages , $ locale ) { foreach ( $ messages as $ key => $ value ) { $ messages [ $ key ] = $ this -> normaliseMessage ( $ key , $ value , $ locale ) ; } return $ messages ; } | Normalises plurals in messages from rails - yaml format to symfony . |
4,277 | protected function normaliseMessage ( $ key , $ value , $ locale ) { if ( ! is_array ( $ value ) ) { return $ value ; } if ( isset ( $ value [ 'default' ] ) ) { return $ value [ 'default' ] ; } $ pluralised = i18n :: encode_plurals ( $ value ) ; if ( $ pluralised ) { return $ pluralised ; } trigger_error ( "Localisation entity {$locale}.{$key} is invalid" , E_USER_WARNING ) ; return null ; } | Normalise rails - yaml plurals into pipe - separated rules |
4,278 | public function forForeignID ( $ id ) { if ( is_array ( $ id ) && sizeof ( $ id ) == 1 ) { $ id = reset ( $ id ) ; } $ filter = $ this -> foreignIDFilter ( $ id ) ; $ list = $ this -> alterDataQuery ( function ( DataQuery $ query ) use ( $ id , $ filter ) { $ currentFilter = $ query -> getQueryParam ( 'Foreign.Filter' ) ; if ( $ currentFilter ) { try { $ query -> removeFilterOn ( $ currentFilter ) ; } catch ( Exception $ e ) { } } $ query -> setQueryParam ( 'Foreign.ID' , $ id ) ; $ query -> setQueryParam ( 'Foreign.Filter' , $ filter ) ; $ query -> where ( $ filter ) ; } ) ; return $ list ; } | Returns a copy of this list with the ManyMany relationship linked to the given foreign ID . |
4,279 | protected function checkMatchingURL ( HTTPRequest $ request ) { $ patterns = $ this -> getURLPatterns ( ) ; if ( ! $ patterns ) { return null ; } $ relativeURL = $ request -> getURL ( true ) ; foreach ( $ patterns as $ pattern => $ result ) { if ( preg_match ( $ pattern , $ relativeURL ) ) { return $ result ; } } return null ; } | Check if global basic auth is enabled for the given request |
4,280 | protected function getListMap ( $ source ) { if ( $ source instanceof SS_List ) { $ source = $ source -> map ( ) ; } if ( $ source instanceof Map ) { $ source = $ source -> toArray ( ) ; } if ( ! is_array ( $ source ) && ! ( $ source instanceof ArrayAccess ) ) { user_error ( '$source passed in as invalid type' , E_USER_ERROR ) ; } return $ source ; } | Given a list of values extract the associative map of id = > title |
4,281 | public function isSelectedValue ( $ dataValue , $ userValue ) { if ( $ dataValue === $ userValue ) { return true ; } if ( $ dataValue === '' && $ userValue === null ) { return true ; } if ( is_array ( $ dataValue ) || is_array ( $ userValue ) ) { return false ; } if ( $ dataValue ) { return $ dataValue == $ userValue ; } return ( ( string ) $ dataValue ) === ( ( string ) $ userValue ) ; } | Determine if the current value of this field matches the given option value |
4,282 | public function castedCopy ( $ classOrCopy ) { $ field = parent :: castedCopy ( $ classOrCopy ) ; if ( $ field instanceof SelectField ) { $ field -> setSource ( $ this -> getSource ( ) ) ; } return $ field ; } | Returns another instance of this field but cast to a different class . |
4,283 | public function redirectBackToForm ( ) { $ url = $ this -> addBackURLParam ( Security :: singleton ( ) -> Link ( 'changepassword' ) ) ; return $ this -> redirect ( $ url ) ; } | Something went wrong go back to the changepassword |
4,284 | protected function checkPassword ( $ member , $ password ) { if ( empty ( $ password ) ) { return false ; } $ authenticators = Security :: singleton ( ) -> getApplicableAuthenticators ( Authenticator :: CHECK_PASSWORD ) ; foreach ( $ authenticators as $ authenticator ) { if ( ! $ authenticator -> checkPassword ( $ member , $ password ) -> isValid ( ) ) { return false ; } } return true ; } | Check if password is ok |
4,285 | public function addAssignments ( array $ assignments ) { $ assignments = $ this -> normaliseAssignments ( $ assignments ) ; $ this -> assignments = array_merge ( $ this -> assignments , $ assignments ) ; return $ this ; } | Adds assignments for a list of several fields |
4,286 | public function handleRequest ( HTTPRequest $ request ) { Injector :: inst ( ) -> registerService ( $ request , HTTPRequest :: class ) ; $ rules = Director :: config ( ) -> uninherited ( 'rules' ) ; $ this -> extend ( 'updateRules' , $ rules ) ; $ handler = function ( ) { return new HTTPResponse ( 'No URL rule was matched' , 404 ) ; } ; foreach ( $ rules as $ pattern => $ controllerOptions ) { $ arguments = $ request -> match ( $ pattern , true ) ; if ( $ arguments == false ) { continue ; } if ( is_string ( $ controllerOptions ) ) { if ( substr ( $ controllerOptions , 0 , 2 ) == '->' ) { $ controllerOptions = array ( 'Redirect' => substr ( $ controllerOptions , 2 ) ) ; } else { $ controllerOptions = array ( 'Controller' => $ controllerOptions ) ; } } $ request -> setRouteParams ( $ controllerOptions ) ; $ arguments = array_merge ( $ controllerOptions , $ arguments ) ; if ( isset ( $ controllerOptions [ '_PopTokeniser' ] ) ) { $ request -> shift ( $ controllerOptions [ '_PopTokeniser' ] ) ; } if ( isset ( $ arguments [ 'Redirect' ] ) ) { $ handler = function ( ) use ( $ arguments ) { $ response = new HTTPResponse ( ) ; $ response -> redirect ( static :: absoluteURL ( $ arguments [ 'Redirect' ] ) ) ; return $ response ; } ; break ; } $ handler = function ( HTTPRequest $ request ) use ( $ arguments ) { try { $ controllerObj = Injector :: inst ( ) -> create ( $ arguments [ 'Controller' ] ) ; return $ controllerObj -> handleRequest ( $ request ) ; } catch ( HTTPResponse_Exception $ responseException ) { return $ responseException -> getResponse ( ) ; } } ; break ; } $ response = $ this -> callMiddleware ( $ request , $ handler ) ; Injector :: inst ( ) -> unregisterNamedObject ( HTTPRequest :: class ) ; return $ response ; } | Process the given URL creating the appropriate controller and executing it . |
4,287 | public static function absoluteURL ( $ url , $ relativeParent = self :: BASE ) { if ( is_bool ( $ relativeParent ) ) { Deprecation :: notice ( '5.0' , 'Director::absoluteURL takes an explicit parent for relative url' ) ; $ relativeParent = $ relativeParent ? self :: BASE : self :: REQUEST ; } if ( preg_match ( '/^http(s?):\/\//' , $ url ) ) { return $ url ; } if ( strpos ( $ url , '//' ) === 0 ) { return self :: protocol ( ) . substr ( $ url , 2 ) ; } if ( $ relativeParent === self :: ROOT || self :: is_root_relative_url ( $ url ) ) { $ parent = self :: protocolAndHost ( ) ; } elseif ( $ relativeParent === self :: REQUEST ) { if ( ! isset ( $ _SERVER [ 'REQUEST_URI' ] ) ) { return false ; } $ parent = dirname ( $ _SERVER [ 'REQUEST_URI' ] . 'x' ) ; } else { $ parent = self :: absoluteBaseURL ( ) ; } if ( empty ( $ url ) || $ url === '.' || $ url === './' ) { $ url = '/' ; } return Controller :: join_links ( $ parent , $ url ) ; } | Turns the given URL into an absolute URL . By default non - site root relative urls will be evaluated relative to the current base_url . |
4,288 | protected static function validateUserAndPass ( $ url ) { $ parsedURL = parse_url ( $ url ) ; if ( ! empty ( $ parsedURL [ 'user' ] ) && strstr ( $ parsedURL [ 'user' ] , '\\' ) ) { return false ; } if ( ! empty ( $ parsedURL [ 'pass' ] ) && strstr ( $ parsedURL [ 'pass' ] , '\\' ) ) { return false ; } return true ; } | Validate user and password in URL disallowing slashes |
4,289 | public static function port ( HTTPRequest $ request = null ) { $ host = static :: host ( $ request ) ; return ( int ) parse_url ( $ host , PHP_URL_PORT ) ? : null ; } | Return port used for the base URL . Note this will be null if not specified in which case you should assume the default port for the current protocol . |
4,290 | public static function hostName ( HTTPRequest $ request = null ) { $ host = static :: host ( $ request ) ; return parse_url ( $ host , PHP_URL_HOST ) ? : null ; } | Return host name without port |
4,291 | public static function is_https ( HTTPRequest $ request = null ) { if ( $ baseURL = self :: config ( ) -> uninherited ( 'alternate_base_url' ) ) { $ baseURL = Injector :: inst ( ) -> convertServiceProperty ( $ baseURL ) ; $ protocol = parse_url ( $ baseURL , PHP_URL_SCHEME ) ; if ( $ protocol ) { return $ protocol === 'https' ; } } $ request = static :: currentRequest ( $ request ) ; if ( $ request && ( $ scheme = $ request -> getScheme ( ) ) ) { return $ scheme === 'https' ; } if ( $ baseURL = self :: config ( ) -> uninherited ( 'default_base_url' ) ) { $ baseURL = Injector :: inst ( ) -> convertServiceProperty ( $ baseURL ) ; $ protocol = parse_url ( $ baseURL , PHP_URL_SCHEME ) ; if ( $ protocol ) { return $ protocol === 'https' ; } } return false ; } | Return whether the site is running as under HTTPS . |
4,292 | public static function baseURL ( ) { $ alternate = self :: config ( ) -> get ( 'alternate_base_url' ) ; if ( $ alternate ) { $ alternate = Injector :: inst ( ) -> convertServiceProperty ( $ alternate ) ; return rtrim ( parse_url ( $ alternate , PHP_URL_PATH ) , '/' ) . '/' ; } $ baseURL = rtrim ( BASE_URL , '/' ) . '/' ; if ( defined ( 'BASE_SCRIPT_URL' ) ) { return $ baseURL . BASE_SCRIPT_URL ; } return $ baseURL ; } | Return the root - relative url for the baseurl |
4,293 | public static function makeRelative ( $ url ) { $ url = preg_replace ( '#([^:])//#' , '\\1/' , trim ( $ url ) ) ; if ( preg_match ( '#^(?<protocol>https?:)?//(?<hostpart>[^/]*)(?<url>(/.*)?)$#i' , $ url , $ matches ) ) { $ url = $ matches [ 'url' ] ; } if ( trim ( $ url , '\\/' ) === '' ) { return '' ; } foreach ( [ self :: publicFolder ( ) , self :: baseFolder ( ) , self :: baseURL ( ) ] as $ base ) { $ base = rtrim ( $ base , '\\/' ) ? : $ base ; if ( stripos ( $ url , $ base ) === 0 ) { return ltrim ( substr ( $ url , strlen ( $ base ) ) , '\\/' ) ; } } return $ url ; } | Turns an absolute URL or folder into one that s relative to the root of the site . This is useful when turning a URL into a filesystem reference or vice versa . |
4,294 | public static function getAbsFile ( $ file ) { if ( self :: is_absolute ( $ file ) ) { return $ file ; } if ( self :: publicDir ( ) ) { $ path = Path :: join ( self :: publicFolder ( ) , $ file ) ; if ( file_exists ( $ path ) ) { return $ path ; } } return Path :: join ( self :: baseFolder ( ) , $ file ) ; } | Given a filesystem reference relative to the site root return the full file - system path . |
4,295 | public static function absoluteBaseURLWithAuth ( HTTPRequest $ request = null ) { $ user = $ request -> getHeader ( 'PHP_AUTH_USER' ) ; if ( $ user ) { $ password = $ request -> getHeader ( 'PHP_AUTH_PW' ) ; $ login = sprintf ( "%s:%s@" , $ user , $ password ) ; } else { $ login = '' ; } return Director :: protocol ( $ request ) . $ login . static :: host ( $ request ) . Director :: baseURL ( ) ; } | Returns the Absolute URL of the site root embedding the current basic - auth credentials into the URL . |
4,296 | public static function forceSSL ( $ patterns = null , $ secureDomain = null , HTTPRequest $ request = null ) { $ handler = CanonicalURLMiddleware :: singleton ( ) -> setForceSSL ( true ) ; if ( $ patterns ) { $ handler -> setForceSSLPatterns ( $ patterns ) ; } if ( $ secureDomain ) { $ handler -> setForceSSLDomain ( $ secureDomain ) ; } $ handler -> throwRedirectIfNeeded ( $ request ) ; } | Force the site to run on SSL . |
4,297 | public static function forceWWW ( HTTPRequest $ request = null ) { $ handler = CanonicalURLMiddleware :: singleton ( ) -> setForceWWW ( true ) ; $ handler -> throwRedirectIfNeeded ( $ request ) ; } | Force a redirect to a domain starting with www . |
4,298 | public static function is_ajax ( HTTPRequest $ request = null ) { $ request = self :: currentRequest ( $ request ) ; if ( $ request ) { return $ request -> isAjax ( ) ; } return ( isset ( $ _REQUEST [ 'ajax' ] ) || ( isset ( $ _SERVER [ 'HTTP_X_REQUESTED_WITH' ] ) && $ _SERVER [ 'HTTP_X_REQUESTED_WITH' ] == "XMLHttpRequest" ) ) ; } | Checks if the current HTTP - Request is an Ajax - Request by checking for a custom header set by jQuery or whether a manually set request - parameter ajax is present . |
4,299 | protected static function currentRequest ( HTTPRequest $ request = null ) { if ( ! $ request && Injector :: inst ( ) -> has ( HTTPRequest :: class ) ) { $ request = Injector :: inst ( ) -> get ( HTTPRequest :: class ) ; } return $ request ; } | Helper to validate or check the current request object |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.