idx int64 0 60.3k | question stringlengths 64 4.24k | target stringlengths 5 618 |
|---|---|---|
31,400 | static public function icon ( $ name , $ value = null , $ settings = [ ] ) { $ settings [ 'media_type' ] = 'icon' ; $ settings [ 'with_input' ] = 'hidden' ; if ( ! isset ( $ settings [ 'readonly' ] ) ) $ settings [ 'readonly' ] = "readonly" ; if ( ! isset ( $ settings [ 'modal_url' ] ) ) $ settings [ 'modal_url' ] = Ioc :: url ( 'common/data/select/icon' ) ; return static :: select ( $ name , $ value , $ settings ) ; } | icon select form |
31,401 | static public function url ( $ name , $ value = null , $ settings = [ ] ) { $ settings [ 'media_type' ] = 'url' ; $ settings [ 'with_input' ] = isset ( $ settings [ 'with_input' ] ) ? $ settings [ 'with_input' ] : 'text' ; return static :: select ( $ name , $ value , $ settings ) ; } | url input form |
31,402 | static public function area ( $ name , $ value = null , $ settings = [ ] ) { $ name || $ name = 'row[area_id]' ; if ( ! isset ( $ settings [ 'modal_url' ] ) ) $ settings [ 'modal_url' ] = Ioc :: url ( 'common/data/select/area' ) ; return static :: select ( $ name , $ value , $ settings ) ; } | select area form |
31,403 | static public function fieldForm ( $ field , $ name , $ value = null , $ settings = [ ] ) { $ field = \ Wslim \ Cms \ FieldHelper :: formatField ( $ field ) ; if ( ! $ name ) { $ name = 'row[' . $ field [ 'field_name' ] . ']' ; } foreach ( $ field as $ k => $ v ) { if ( strpos ( $ k , 'form_' ) === 0 ) { $ sk = $ k == 'form_type' ? $ k : str_replace ( 'form_' , '' , $ k ) ; if ( ! isset ( $ settings [ $ sk ] ) ) $ settings [ $ sk ] = $ v ; } } return static :: auto ( $ name , $ value , $ settings ) ; } | field form detect by form type |
31,404 | static public function token ( $ name = null , $ data = null ) { if ( ! is_null ( $ name ) && is_null ( $ data ) && ( is_numeric ( $ name ) || is_array ( $ name ) || $ name == '' ) ) { $ data = $ name ; $ name = null ; } return ( new FormToken ( ) ) -> form ( $ name , $ data ) ; } | get form_token html |
31,405 | public function show ( $ id ) { $ filters = [ ] ; $ response = new ResponseModel ( ) ; try { $ response -> setMessage ( $ this -> getTrans ( 'show' , 'successful' ) ) ; array_push ( $ filters , [ $ this -> model -> getKeyName ( ) , '=' , $ id ] ) ; $ data = $ this -> model -> where ( $ filters ) -> get ( ) ; $ response -> setData ( $ data ) ; } catch ( Exception $ exception ) { $ response -> setError ( $ exception -> getCode ( ) ) ; $ response -> setMessage ( $ this -> getTrans ( 'show' , 'failed' ) ) ; $ response -> setStatus ( false ) ; if ( env ( 'APP_DEBUG' , false ) ) { $ response -> setData ( collect ( $ exception -> getMessage ( ) ) ) ; } } return SmartResponse :: response ( $ response ) ; } | Display the specdefaultied resource . |
31,406 | public function getFilters ( Request $ request ) : Request { if ( isset ( $ request [ 'filters' ] ) ) { $ filters = json_decode ( $ request [ 'filters' ] , true ) ; } else { $ filters = [ ] ; } $ request [ $ this -> getRequestTagName ( 'filter' ) ] = $ filters ; return $ request ; } | get filter if exist |
31,407 | public static function fromFocalLength ( $ focalLength ) { if ( ! is_string ( $ focalLength ) ) { throw new InvalidArgumentException ( 'focalLength must be a string' ) ; } if ( ! preg_match ( '#^f/([0-9]*\.[0-9]+|[0-9]*)$#' , $ focalLength , $ matches ) ) { throw new RuntimeException ( 'Given focalLength is not in a valid format. Need: "f/<number>"' ) ; } $ fNumber = $ matches [ 1 ] ; if ( ( $ filtered = filter_var ( $ fNumber , FILTER_VALIDATE_INT ) ) !== false ) { $ fNumber = $ filtered ; } else { $ fNumber = ( float ) $ fNumber ; } return new self ( $ fNumber ) ; } | Creates new instance from given Focal Length format |
31,408 | protected function normalizeLevel ( $ level ) { if ( isset ( $ this -> logLevelMap [ $ level ] ) ) { return $ this -> logLevelMap [ $ level ] ; } return strtolower ( $ level ) ; } | Normalize log level argument |
31,409 | public function setRemoteSyslog ( $ host , $ port = 514 , $ protocol = 'udp' ) { $ this -> syslogHost = $ host ; $ this -> syslogPort = $ port ; $ this -> syslogProtocol = $ protocol ; } | Set values for remote syslog |
31,410 | protected function syslogRemote ( $ message ) { $ context = array ( 'skip_remote' => true ) ; try { $ socket = $ this -> getSyslogSocket ( ) ; $ socket = socket_create ( AF_INET , SOCK_STREAM , SOL_TCP ) ; socket_set_option ( $ socket , SOL_SOCKET , SO_SNDTIMEO , array ( 'sec' => 5 , 'usec' => 0 ) ) ; if ( ! socket_connect ( $ socket , $ this -> syslogHost , $ this -> syslogPort ) ) { $ this -> debug ( 'Unable to connect to ' . $ this -> syslogHost . ':' . $ this -> syslogPort . ' for remote logging. Error: ' . socket_last_error ( ) , $ context ) ; } socket_write ( $ socket , $ message ) ; socket_close ( $ socket ) ; } catch ( \ Exception $ ex ) { $ this -> debug ( $ ex -> getMessage ( ) , $ context ) ; } return true ; } | Send message to remote syslog |
31,411 | private function stackTrace ( $ stack ) { $ counter = count ( $ stack ) ; $ lines = array ( ) ; foreach ( $ stack as $ frame ) { $ ret = 'Frame #' . $ counter . ' - ' ; $ line = isset ( $ frame [ 'line' ] ) ? $ frame [ 'line' ] : 0 ; $ file = isset ( $ frame [ 'file' ] ) ? $ frame [ 'file' ] : 'Unknown file' ; $ args = isset ( $ frame [ 'args' ] ) ? $ frame [ 'args' ] : array ( ) ; $ ret .= 'File ' . $ file . ', Line ' . $ line . ', function ' . $ this -> frameToFunction ( $ frame ) ; $ lines [ ] = $ ret ; $ counter -- ; } return $ lines ; } | Convert a stack trace array into readable text |
31,412 | public function setTranslator ( $ class ) { if ( is_string ( $ class ) ) { $ this -> _translator = new $ class ; } else { $ this -> _translator = $ class ; } if ( ! is_a ( $ this -> _translator , '\\mpf\\interfaces\\TranslatorInterface' ) ) { $ this -> _translator = null ; throw new Exception ( "Invalid translator $class! Must implement \\mpf\\interfaces\\TranslatorInterface!" ) ; } $ this -> translator = $ class ; } | Set a new translator . Can be sent as class name or class instance ; |
31,413 | public function getTranslator ( ) { if ( ! $ this -> _translator ) { if ( $ this -> translator ) { $ class = $ this -> translator ; $ this -> _translator = $ class :: get ( ) ; if ( ! is_a ( $ this -> _translator , '\\mpf\\interfaces\\TranslatorInterface' ) ) { $ this -> _translator = null ; $ this -> translator = '' ; throw new Exception ( "Invalid translator $class! Must implement \\mpf\\interfaces\\TranslatorInterface!" ) ; } } } return $ this -> _translator ; } | Return instance to translator |
31,414 | public function get ( $ request , $ match ) { $ userId = $ match [ 'userId' ] ; $ profileDoc = User_Views_CProfile :: get_profile_document ( $ userId ) ; $ docMap = User_Views_CProfile :: getDocumentMap ( $ profileDoc ) ; $ docMap [ 'user' ] = $ userId ; return new Pluf_HTTP_Response_Json ( $ docMap ) ; } | Returns profile information of specified user . Data model of profile can be different in each system . Also loading information of user is lazy so profile is not loaded until a request occure . |
31,415 | public function update ( $ request , $ match ) { $ currentUser = $ request -> user ; $ user = Pluf_Shortcuts_GetObjectOr404 ( 'User' , $ match [ 'userId' ] ) ; if ( $ currentUser -> getId ( ) === $ user -> getId ( ) || User_Precondition :: ownerRequired ( $ request ) ) { $ profileDoc = User_Views_CProfile :: get_profile_document ( $ user -> id ) ; User_Views_CProfile :: putDocumentMap ( $ profileDoc , $ request -> REQUEST ) ; $ docMap = User_Views_CProfile :: getDocumentMap ( $ profileDoc ) ; $ docMap [ 'user' ] = $ user -> id ; return new Pluf_HTTP_Response_Json ( $ docMap ) ; } throw new Pluf_Exception_PermissionDenied ( "Permission is denied" ) ; } | Update profile of specified user . |
31,416 | static function get_profile_document ( $ userId ) { $ user = Pluf_Shortcuts_GetObjectOr404 ( 'User' , $ userId ) ; $ collection = Collection_Shortcuts_GetCollectionByName ( User_Constants :: PROFILE_COLLECTION_NAME ) ; if ( $ collection === null ) { $ collection = new Collection_Collection ( ) ; $ collection -> name = User_Constants :: PROFILE_COLLECTION_NAME ; $ collection -> title = 'Collection for saving profile of users' ; $ collection -> create ( ) ; } $ cprofile = new Profile ( ) ; $ cprofile = $ cprofile -> getOne ( 'user = ' . $ userId ) ; if ( $ cprofile === null ) { $ document = new Collection_Document ( ) ; $ document -> collection = $ collection ; $ document -> create ( ) ; $ cprofile = new Profile ( ) ; $ cprofile -> user = $ user ; $ cprofile -> profile = $ document ; $ cprofile -> create ( ) ; } $ profileDoc = new Collection_Document ( $ cprofile -> profile ) ; return $ profileDoc ; } | Fetch profile of the user |
31,417 | static function getDocumentMap ( $ document ) { $ attr = new Collection_Attribute ( ) ; $ map = $ attr -> getList ( array ( 'filter' => 'document=' . $ document -> id ) ) ; $ result = array ( ) ; $ iterator = $ map -> getIterator ( ) ; while ( $ iterator -> valid ( ) ) { $ attr = $ iterator -> current ( ) ; $ result [ $ attr -> key ] = $ attr -> value ; $ iterator -> next ( ) ; } $ result [ 'id' ] = $ document -> id ; $ result [ 'collection' ] = $ document -> collection ; return $ result ; } | Gets all attributes of a document and return as map |
31,418 | public function readRecipe ( ) : callable { return function ( RecipeInterface $ recipe ) : ChefInterface { $ this -> recipe = $ recipe -> train ( $ this ) ; $ this -> updateStates ( ) ; return $ this ; } ; } | To read and lean a recipe . |
31,419 | public function followStepsRecipe ( ) : callable { return function ( array $ steps , array $ onError ) : ChefInterface { $ this -> steps = \ array_values ( $ steps ) ; $ this -> stepsNames = \ array_flip ( \ array_keys ( $ steps ) ) ; $ this -> onError = $ onError ; $ this -> updateStates ( ) ; return $ this ; } ; } | To learn steps in the recipe in the good order |
31,420 | public static function register ( $ slug , $ name ) { if ( version_compare ( floatval ( get_bloginfo ( 'version' ) ) , '4.7' , '<' ) ) { self :: old_register ( $ slug , $ name ) ; } else { self :: $ templates [ $ slug ] = $ name ; add_filter ( 'theme_page_templates' , [ __CLASS__ , 'register_template' ] ) ; } } | Register a page template |
31,421 | public function setConfig ( $ config ) { $ this -> config = $ config ; $ this -> routes = $ config [ 'routes' ] ; $ this -> options = $ config [ 'options' ] ; return $ this ; } | Set the AccountController config |
31,422 | public function create ( ) { $ pluginClient = new PluginClient ( $ this -> httpClient , [ new BaseUriPlugin ( $ this -> uriFactory -> createUri ( $ this -> api_url ) , [ 'replace' => true ] ) , new AuthenticationPlugin ( new BasicAuth ( $ this -> api_key , '' ) ) , new ErrorPlugin ( ) , new ContentTypePlugin ( ) , ] ) ; return new Client ( $ pluginClient , $ this -> apiRequestFactory ) ; } | Creates the API client with needed configuration . |
31,423 | public function script ( $ script ) { $ md5 = md5 ( $ script ) ; if ( in_array ( $ md5 , self :: $ cssScriptHistory ) ) return '' ; self :: $ cssScriptHistory [ ] = $ md5 ; return "<script type=\"text/javascript\">\n/*<![CDATA[*/\n{$script}\n/*]]>*/\n</script>" ; } | Register inline script . You can choose to insert a script only once and then if the same script is detected then it won t be inserted again . |
31,424 | public function scriptFile ( $ path ) { if ( $ this -> skipOtherScriptFiles ) return "" ; if ( 'http' != substr ( $ path , 0 , 4 ) ) { $ path = \ mpf \ WebApp :: get ( ) -> request ( ) -> getWebRoot ( ) . $ path ; } $ md5 = md5 ( $ path ) ; if ( in_array ( $ md5 , self :: $ cssScriptHistory ) ) return '' ; self :: $ cssScriptHistory [ ] = $ md5 ; return '<script type="text/javascript" src="' . self :: encode ( $ path ) . '"></script>' ; } | Returns a script tag that links to the specified file |
31,425 | public function cssFile ( $ path , $ media = '' ) { if ( 'http' != substr ( $ path , 0 , 4 ) ) { $ path = \ mpf \ WebApp :: get ( ) -> request ( ) -> getWebRoot ( ) . $ path ; } $ md5 = md5 ( $ path ) ; if ( in_array ( $ md5 , self :: $ cssScriptHistory ) ) return '' ; self :: $ cssScriptHistory [ ] = $ md5 ; if ( $ media !== '' ) $ media = ' media="' . $ media . '"' ; return '<link rel="stylesheet" type="text/css" href="' . self :: encode ( $ path ) . '"' . $ media . ' />' ; } | Returns a link tag to a css file . |
31,426 | public function encodeArray ( $ data ) { $ d = array ( ) ; foreach ( $ data as $ key => $ value ) { if ( is_string ( $ key ) ) $ key = htmlspecialchars ( $ key ) ; if ( is_string ( $ value ) ) $ value = htmlspecialchars ( $ value ) ; elseif ( is_array ( $ value ) ) $ value = self :: encodeArray ( $ value ) ; $ d [ $ key ] = $ value ; } return $ d ; } | Encodes an array of strings . |
31,427 | public function tag ( $ name , $ content , $ htmlOptions = array ( ) ) { $ element = "<$name " ; foreach ( $ htmlOptions as $ k => $ v ) { $ element .= "$k=\"" . self :: encode ( $ v ) . "\" " ; } return $ element . '>' . $ content . '</' . $ name . '>' ; } | Generates a HTML element with selected tag content and options . |
31,428 | public function link ( $ href , $ text , $ htmlOptions = [ ] , $ checkAccess = true ) { if ( $ checkAccess && is_array ( $ href ) ) { $ module = isset ( $ href [ 3 ] ) ? $ href [ 3 ] : ( ( isset ( $ href [ 2 ] ) && is_string ( $ href [ 2 ] ) ) ? $ href [ 2 ] : null ) ; if ( ! WebApp :: get ( ) -> hasAccessTo ( $ href [ 0 ] , isset ( $ href [ 1 ] ) ? $ href [ 1 ] : null , $ module ) ) { return "" ; } } if ( is_array ( $ href ) ) { $ module = isset ( $ href [ 3 ] ) ? $ href [ 3 ] : ( ( isset ( $ href [ 2 ] ) && is_string ( $ href [ 2 ] ) ) ? $ href [ 2 ] : null ) ; $ href = WebApp :: get ( ) -> request ( ) -> createURL ( $ href [ 0 ] , isset ( $ href [ 1 ] ) ? $ href [ 1 ] : null , ( isset ( $ href [ 2 ] ) && is_array ( $ href [ 2 ] ) ) ? $ href [ 2 ] : [ ] , $ module ) ; } $ htmlOptions [ 'href' ] = $ href ; return $ this -> tag ( 'a' , $ text , $ htmlOptions ) ; } | Returns a HTML link to selected URL . |
31,429 | public function postLink ( $ url , $ text , $ postData = [ ] , $ htmlOptions = [ ] , $ checkAccess = true , $ confirm = false ) { if ( $ checkAccess && is_array ( $ url ) ) { $ module = isset ( $ url [ 3 ] ) ? $ url [ 3 ] : ( ( isset ( $ url [ 2 ] ) && is_string ( $ url [ 2 ] ) ) ? $ url [ 2 ] : null ) ; if ( ! WebApp :: get ( ) -> hasAccessTo ( $ url [ 0 ] , isset ( $ url [ 1 ] ) ? $ url [ 1 ] : null , $ module ) ) { return "" ; } } if ( is_array ( $ url ) ) { $ module = isset ( $ url [ 3 ] ) ? $ url [ 3 ] : ( ( isset ( $ url [ 2 ] ) && is_string ( $ url [ 2 ] ) ) ? $ url [ 2 ] : null ) ; $ url = WebApp :: get ( ) -> request ( ) -> createURL ( $ url [ 0 ] , isset ( $ url [ 1 ] ) ? $ url [ 1 ] : null , ( isset ( $ url [ 2 ] ) && is_array ( $ url [ 2 ] ) ) ? $ url [ 2 ] : [ ] , $ module ) ; } $ uniqueID = uniqid ( "post-link-form" ) ; $ htmlOptions [ 'onclick' ] = ( isset ( $ htmlOptions [ 'onclick' ] ) ? $ htmlOptions [ 'onclick' ] . ' ' : '' ) . 'document.getElementById(\'' . $ uniqueID . '\').submit(); return false;' ; if ( $ confirm ) { $ htmlOptions [ 'onclick' ] = "if (confirm('$confirm')) { $htmlOptions[onclick] }; return false;" ; } $ r = $ this -> link ( $ url , $ text , $ htmlOptions , false ) ; $ r .= Form :: get ( ) -> openForm ( [ 'style' => 'display:none;' , 'method' => 'post' , 'id' => $ uniqueID , 'action' => $ url ] ) ; foreach ( $ postData as $ name => $ value ) { $ r .= Form :: get ( ) -> hiddenInput ( $ name , $ value ) ; } $ r .= Form :: get ( ) -> closeForm ( ) ; return $ r ; } | It creates a link and a hidden form . That form will be submitted where the link is setup as URL . |
31,430 | protected function sendNotifyException ( $ exception ) { $ adminEmail = Main \ Config \ Option :: get ( 'main' , 'email_from' ) ; $ logFile = Application :: getDocumentRoot ( ) . $ this -> __path . '/' . $ this -> exceptionLog ; if ( ! is_file ( $ logFile ) && $ adminEmail ) { $ this -> lang = new Lang ( get_class ( ) ) ; $ date = date ( 'Y-m-d H:m:s' ) ; bxmail ( $ adminEmail , $ this -> lang -> getMessage ( 'BBC_COMPONENT_EXCEPTION_EMAIL_SUBJECT' , array ( '#SITE_URL#' => SITE_SERVER_NAME ) ) , $ this -> lang -> getMessage ( 'BBC_COMPONENT_EXCEPTION_EMAIL_TEXT' , array ( '#URL#' => 'http://' . SITE_SERVER_NAME . Main \ Context :: getCurrent ( ) -> getRequest ( ) -> getRequestedPage ( ) , '#DATE#' => $ date , '#EXCEPTION_MESSAGE#' => $ exception -> getMessage ( ) , '#EXCEPTION#' => $ exception , ) ) , 'Content-Type: text/html; charset=utf-8' ) ; $ log = fopen ( $ logFile , 'w' ) ; fwrite ( $ log , '[' . $ date . '] Catch exception: ' . PHP_EOL . $ exception ) ; fclose ( $ log ) ; } } | Send error message to the admin email |
31,431 | protected function showExceptionUser ( \ Exception $ exception ) { $ this -> lang = new Lang ( get_class ( ) ) ; ShowError ( $ this -> lang -> getMessage ( 'BBC_COMPONENT_CATCH_EXCEPTION' ) ) ; } | Display of the error for user |
31,432 | public function saveTranslations ( ) { $ res = true ; foreach ( $ this -> _models as $ model ) { $ dirty = $ model -> getDirtyAttributes ( ) ; if ( empty ( $ dirty ) ) { continue ; } $ relation = $ this -> owner -> getRelation ( $ this -> relation ) ; $ model -> { key ( $ relation -> link ) } = $ this -> owner -> getPrimaryKey ( ) ; if ( ! $ this -> isTranslationActive ( $ model ) ) { $ this -> deleteTranslation ( $ model ) ; continue ; } if ( ! $ model -> save ( ) ) { $ res = false ; } } return $ res ; } | Saves all translations models |
31,433 | private function loadTranslations ( ) { if ( $ related = $ this -> owner -> { $ this -> relation } ) { if ( is_array ( $ related ) ) { foreach ( $ related as $ model ) { $ this -> _models [ $ model -> getAttribute ( $ this -> languageAttribute ) ] = $ model ; } } else { $ model = $ related ; $ this -> _models [ $ model -> getAttribute ( $ this -> languageAttribute ) ] = $ model ; } return true ; } return false ; } | Loads relation to models |
31,434 | public function setRestInputParams ( $ data ) { $ oldValue = $ this -> registry -> registry ( self :: REG_REST_INPUT ) ; if ( ! is_null ( $ oldValue ) ) { $ this -> registry -> unregister ( self :: REG_REST_INPUT ) ; } $ this -> registry -> register ( self :: REG_REST_INPUT , $ data ) ; } | Save REST input parameters into Magento registry . |
31,435 | public function generateNav ( $ result ) { if ( $ this -> arParams [ 'DISPLAY_BOTTOM_PAGER' ] === 'Y' || $ this -> arParams [ 'DISPLAY_TOP_PAGER' ] === 'Y' ) { $ this -> arResult [ 'NAV_STRING' ] = $ result -> GetPageNavStringEx ( $ navComponentObject , $ this -> arParams [ 'PAGER_TITLE' ] , $ this -> arParams [ 'PAGER_TEMPLATE' ] , $ this -> arParams [ 'PAGER_SHOW_ALWAYS' ] ) ; $ this -> arResult [ 'NAV_CACHED_DATA' ] = $ navComponentObject -> GetTemplateCachedData ( ) ; $ this -> arResult [ 'NAV_RESULT' ] = $ result ; } } | Generate navigation string |
31,436 | public static function getShortLink ( $ fullLink ) { $ prefix = 'http://' . SITE_SERVER_NAME . '/' ; $ rsShortLink = \ CBXShortUri :: GetList ( [ ] , [ 'URI' => $ fullLink , ] ) ; if ( $ shortLink = $ rsShortLink -> Fetch ( ) ) { return $ prefix . $ shortLink [ 'SHORT_URI' ] ; } $ shortLink = \ CBXShortUri :: GenerateShortUri ( ) ; $ id = \ CBXShortUri :: Add ( [ 'URI' => $ fullLink , 'SHORT_URI' => $ shortLink , 'STATUS' => '301' , ] ) ; if ( $ id ) { return $ prefix . $ shortLink ; } } | Returns short link |
31,437 | public function getParamsSort ( $ additionalFields = [ ] ) { $ this -> arParams [ 'SORT_BY_1' ] = trim ( $ this -> arParams [ 'SORT_BY_1' ] ) ; if ( strlen ( $ this -> arParams [ 'SORT_BY_1' ] ) <= 0 ) { $ this -> arParams [ 'SORT_BY_1' ] = 'ACTIVE_FROM' ; } if ( ! preg_match ( '/^(asc|desc|nulls)(,asc|,desc|,nulls){0,1}$/i' , $ this -> arParams [ 'SORT_ORDER_1' ] ) ) { $ this -> arParams [ 'SORT_ORDER_1' ] = 'DESC' ; } if ( strlen ( $ this -> arParams [ 'SORT_BY_2' ] ) <= 0 ) { $ this -> arParams [ 'SORT_BY_2' ] = 'SORT' ; } if ( ! preg_match ( '/^(asc|desc|nulls)(,asc|,desc|,nulls){0,1}$/i' , $ this -> arParams [ 'SORT_ORDER_2' ] ) ) { $ this -> arParams [ 'SORT_ORDER_2' ] = 'ASC' ; } $ fields = [ $ this -> arParams [ 'SORT_BY_1' ] => $ this -> arParams [ 'SORT_ORDER_1' ] , $ this -> arParams [ 'SORT_BY_2' ] => $ this -> arParams [ 'SORT_ORDER_2' ] , ] ; if ( is_array ( $ additionalFields ) && ! empty ( $ additionalFields ) ) { $ fields = array_merge ( $ fields , $ additionalFields ) ; } return $ fields ; } | Returns prepare parameters of sort of the component |
31,438 | public function isValidUsingSimplePurchasableValidation ( PurchasableInterface $ purchasable , $ stockRequired , $ useStock ) { if ( $ useStock ) { if ( ! $ purchasable -> isEnabled ( ) || $ stockRequired <= 0 || ( $ useStock && $ purchasable -> getStock ( ) <= 0 ) ) { return false ; } if ( $ purchasable -> getStock ( ) < $ stockRequired ) { return $ purchasable -> getStock ( ) ; } } return true ; } | Make a simple validation of a Purchasable instance . |
31,439 | protected static function LT ( DBInterfaces \ IDatabaseConnection $ connection , Selectable $ field , Selectable $ value ) { $ op = '<' ; return self :: CreateElementary ( $ connection , $ field , $ value , $ op ) ; } | Less than condition |
31,440 | private function Combine ( Condition $ cond , $ combiner ) { $ statement = '(' . $ this -> statement . ') ' . $ combiner . ' (' . $ cond -> statement . ')' ; return new self ( $ this -> connection , $ statement ) ; } | Combines this condition with the given . |
31,441 | private static function CreateElementary ( DBInterfaces \ IDatabaseConnection $ connection , Selectable $ field , Selectable $ value , $ operator ) { return new self ( $ connection , $ field . ' ' . $ operator . ' ' . $ value ) ; } | Returns an elementary condition . |
31,442 | public function SetMyFooter ( $ page = false , $ date = false , $ hour = false , $ form = false ) { $ page = ( $ page ? true : false ) ; $ date = ( $ date ? true : false ) ; $ hour = ( $ hour ? true : false ) ; $ form = ( $ form ? true : false ) ; $ this -> _footerParam = array ( 'page' => $ page , 'date' => $ date , 'hour' => $ hour , 'form' => $ form ) ; } | Set the parameters for the automatic footer |
31,443 | public function SetY ( $ y , $ resetx = true , $ rtloff = false ) { if ( $ resetx ) $ this -> x = $ this -> lMargin ; $ this -> y = $ y ; } | we redifine the original SetY method because we don t want the automatic treatment . It is HTML2PDF that make the treatment |
31,444 | public function SetXY ( $ x , $ y , $ rtloff = false ) { $ this -> x = $ x ; $ this -> y = $ y ; } | we redifine the original SetXY method because we don t want the automatic treatment . It is HTML2PDF that make the treatment |
31,445 | public function svgRect ( $ x , $ y , $ w , $ h , $ style ) { $ x1 = $ x ; $ x2 = $ x + $ w ; $ x3 = $ x + $ w ; $ x4 = $ x ; $ y1 = $ y ; $ y2 = $ y ; $ y3 = $ y + $ h ; $ y4 = $ y + $ h ; if ( $ style == 'F' ) $ op = 'f' ; elseif ( $ style == 'FD' || $ style == 'DF' ) $ op = 'B' ; else $ op = 'S' ; $ this -> _Point ( $ x1 , $ y1 , true ) ; $ this -> _Line ( $ x2 , $ y2 , true ) ; $ this -> _Line ( $ x3 , $ y3 , true ) ; $ this -> _Line ( $ x4 , $ y4 , true ) ; $ this -> _Line ( $ x1 , $ y1 , true ) ; $ this -> _out ( $ op ) ; } | SVG - make a Rectangle |
31,446 | protected function _Arc ( $ xc , $ yc , $ rx , $ ry , $ angleBegin , $ angleEnd , $ direction = true , $ drawFirst = true , $ trans = false ) { if ( ! $ direction ) $ angleBegin += M_PI * 2. ; $ dt = ( $ angleEnd - $ angleBegin ) / self :: ARC_NB_SEGMENT ; $ dtm = $ dt / 3 ; $ x0 = $ xc ; $ y0 = $ yc ; $ t1 = $ angleBegin ; $ a0 = $ x0 + ( $ rx * cos ( $ t1 ) ) ; $ b0 = $ y0 + ( $ ry * sin ( $ t1 ) ) ; $ c0 = - $ rx * sin ( $ t1 ) ; $ d0 = $ ry * cos ( $ t1 ) ; if ( $ drawFirst ) $ this -> _Point ( $ a0 , $ b0 , $ trans ) ; for ( $ i = 1 ; $ i <= self :: ARC_NB_SEGMENT ; $ i ++ ) { $ t1 = ( $ i * $ dt ) + $ angleBegin ; $ a1 = $ x0 + ( $ rx * cos ( $ t1 ) ) ; $ b1 = $ y0 + ( $ ry * sin ( $ t1 ) ) ; $ c1 = - $ rx * sin ( $ t1 ) ; $ d1 = $ ry * cos ( $ t1 ) ; $ this -> _Curve ( $ a0 + ( $ c0 * $ dtm ) , $ b0 + ( $ d0 * $ dtm ) , $ a1 - ( $ c1 * $ dtm ) , $ b1 - ( $ d1 * $ dtm ) , $ a1 , $ b1 , $ trans ) ; $ a0 = $ a1 ; $ b0 = $ b1 ; $ c0 = $ c1 ; $ d0 = $ d1 ; } } | SVG - make a arc with Center Radius from angleBegin to angleEnd |
31,447 | public static function normalize ( string $ path ) : string { if ( ! ( false === strpos ( $ path , '://' ) ) ) { $ ex = explode ( "://" , $ path ) ; return $ ex [ 0 ] . "://" . "/" . ltrim ( Util :: normalizePath ( "/" . ltrim ( $ ex [ 1 ] , "/" ) ) ) ; } return "/" . ltrim ( Util :: normalizePath ( $ path ) , "/" ) ; } | Normalize a path |
31,448 | public static function getPath ( string $ path ) : string { $ e = explode ( "/" , $ path ) ; unset ( $ e [ count ( $ e ) - 1 ] ) ; return implode ( "/" , $ e ) ; } | get path without file name |
31,449 | public static function getFile ( string $ path ) : string { $ e = explode ( "/" , rtrim ( $ path , "/" ) ) ; return $ e [ count ( $ e ) - 1 ] ; } | get file name form full file path |
31,450 | private function invalidIdentifierTypeErrorMessage ( string $ method , $ id ) : string { $ tpl = 'Argument 1 passed to %s::%s method must be of the type string, %s given' ; return sprintf ( $ tpl , Container :: class , $ method , gettype ( $ id ) ) ; } | Return the message of the exception thrown when an identifier is not a string . |
31,451 | protected function parseToEnglish ( string $ value ) : string { if ( ctype_digit ( $ value ) ) { return $ value ; } $ localeConv = $ this -> getLocaleInfo ( ) ; $ replacements = [ $ localeConv [ 'thousands_sep' ] , $ localeConv [ 'currency_symbol' ] , ' ' , "\t" ] ; $ value = $ this -> numberToEnglish ( str_replace ( $ replacements , '' , $ value ) ) ; return ( ! is_numeric ( $ value ) ) ? '0' : $ value ; } | Remove the thousands separator currency symbol and white spaces . Returns the resulting string if is numeric otherwise returns 0 |
31,452 | protected function numberToEnglish ( string $ value ) : string { if ( '.' !== $ this -> getDecimalPoint ( ) ) { return str_replace ( $ this -> getDecimalPoint ( ) , '.' , $ value ) ; } return $ value ; } | Change decimal point to a real point |
31,453 | public function execute ( Observer $ observer ) { if ( ! $ layout = $ observer -> getData ( 'layout' ) ) { return ; } if ( ! $ update = $ layout -> getUpdate ( ) ) { return ; } $ update -> addHandle ( $ this -> _getFooterHandleName ( ) ) ; $ update -> addHandle ( $ this -> _getHeaderHandleName ( ) ) ; if ( $ this -> _shouldApplyProductListItemHandle ( ) ) { $ update -> addHandle ( $ this -> _getProductListItemHandleName ( ) ) ; } if ( $ this -> _shouldApplyBannerHandle ( ) ) { $ update -> addHandle ( $ this -> _getBannerHandleName ( ) ) ; } $ update -> addHandle ( self :: THEME_CUSOMIZATION_HANDLE_NAME ) ; } | Applies update handles based on config settings |
31,454 | protected function _getFooterHandleName ( ) { $ handleCode = $ this -> _scopeConfig -> getValue ( self :: FOOTER_LAYOUT_CONFIG_PATH , ScopeInterface :: SCOPE_STORE ) ; if ( ! $ handleCode ) { $ handleCode = 1 ; } return self :: FOOTER_LAYOUT_HANDLE_PREFIX . $ handleCode ; } | Returns footer update handle name based on config setting |
31,455 | protected function _getHeaderHandleName ( ) { $ handleCode = $ this -> _scopeConfig -> getValue ( self :: HEADER_LAYOUT_CONFIG_PATH , ScopeInterface :: SCOPE_STORE ) ; if ( ! $ handleCode ) { $ handleCode = 1 ; } return self :: HEADER_LAYOUT_HANDLE_PREFIX . $ handleCode ; } | Returns header update handle name based on config setting |
31,456 | protected function _getProductListItemHandleName ( ) { $ handleCode = $ this -> _scopeConfig -> getValue ( self :: PRODUCTLISTITEM_LAYOUT_CONFIG_PATH , ScopeInterface :: SCOPE_STORE ) ; if ( ! $ handleCode ) { $ handleCode = 1 ; } if ( $ this -> _isSearch ( ) ) { $ return = self :: PRODUCTSEARCHITEM_LAYOUT_HANDLE_PREFIX . $ handleCode ; } else { $ return = self :: PRODUCTLISTITEM_LAYOUT_HANDLE_PREFIX . $ handleCode ; } return $ return ; } | Returns productListItem update handle name based on config setting |
31,457 | protected function _getFullActionName ( ) { if ( $ this -> _fullActionName == null ) { $ this -> _fullActionName = $ this -> _request -> getFullActionName ( ) ; } return $ this -> _fullActionName ; } | Returns current action full name |
31,458 | protected function _getBannerHandleName ( ) { $ handleCode = $ this -> _scopeConfig -> getValue ( self :: BANNER_LAYOUT_CONFIG_PATH , ScopeInterface :: SCOPE_STORE ) ; if ( ! $ handleCode ) { $ handleCode = 1 ; } return self :: BANNER_LAYOUT_HANDLE_PREFIX . $ handleCode ; } | Returns banner template name name based on config setting - Temporary until we have a banners module |
31,459 | public function initializeManager ( ) { $ handlers = $ this -> handlerObjectBackend -> loadObject ( ) ; if ( ! is_array ( $ handlers ) ) { $ handlers = array ( ) ; } $ this -> handlers = $ handlers ; } | Initializes the event system . The function loads all saved events from the object backend . |
31,460 | public function executeFilter ( $ eventName , $ value = null ) { return $ this -> executeItems ( self :: FILTER , $ eventName , $ value ) ; } | Executes the filter for the given filter name |
31,461 | protected function executeItems ( $ type , $ name , $ value = null ) { if ( ! isset ( $ this -> handlers [ $ type ] [ $ name ] ) ) { return $ value ; } $ request = $ this -> framework -> getRequest ( ) ; foreach ( $ this -> filterHandlers ( $ type , $ name , $ request ) as $ handlerName ) { $ handler = $ this -> framework -> getInstance ( $ handlerName ) ; $ response = $ this -> framework -> getResponse ( ) ; $ response -> setData ( '_executedType' , $ type ) ; $ response -> setData ( '_executedName' , $ name ) ; $ handlerResult = $ handler -> execute ( $ this -> framework , $ this -> framework -> getRequest ( ) , $ response , $ value ) ; if ( $ type === self :: FILTER ) { $ value = $ handlerResult ; } } if ( $ type === self :: FILTER ) { return $ value ; } } | Executes the given event handlers . Every event handler will be initialized and executed . |
31,462 | protected function filterHandlers ( $ type , $ name , RequestAbstract $ request ) { $ filteredHandlers = array ( ) ; foreach ( $ this -> handlers [ $ type ] [ $ name ] as $ priority => $ handlers ) { foreach ( $ handlers as $ handlerName ) { if ( $ type === self :: EVENT && ! $ this -> compareRequestWithInterface ( $ request , $ handlerName ) ) { continue ; } $ filteredHandlers [ ] = $ handlerName ; } } return array_unique ( $ filteredHandlers ) ; } | Filters the handler and returns an single array with all queued handlers |
31,463 | public function addEventHandler ( $ eventName , $ eventHandlerName , $ priority = 50 ) { $ this -> addHandler ( self :: EVENT , $ eventName , $ eventHandlerName , $ priority ) ; } | Adds an event handler |
31,464 | public function addFilterHandler ( $ filterName , $ filterHandlerName , $ priority = 50 ) { $ this -> addHandler ( self :: FILTER , $ filterName , $ filterHandlerName , $ priority ) ; } | Adds an filter handler |
31,465 | protected function addHandler ( $ type , $ name , $ handlerName , $ priority ) { if ( ! isset ( $ this -> handlers [ $ type ] [ $ name ] [ $ priority ] ) ) { $ this -> handlers [ $ type ] [ $ name ] [ $ priority ] = array ( ) ; ksort ( $ this -> handlers [ $ type ] [ $ name ] ) ; } if ( in_array ( $ handlerName , $ this -> handlers [ $ type ] [ $ name ] [ $ priority ] ) ) { return ; } $ this -> handlers [ $ type ] [ $ name ] [ $ priority ] [ ] = $ handlerName ; $ this -> saveHandlers ( ) ; } | Adds a new handler |
31,466 | public function removeEventHandler ( $ eventName , $ eventHandlerName , $ priority = 50 ) { $ this -> removeHandler ( self :: EVENT , $ eventName , $ eventHandlerName , $ priority ) ; } | Removes an event handler |
31,467 | public function removeFilterHandler ( $ filterName , $ filterHandlerName , $ priority = 50 ) { $ this -> removeHandler ( self :: FILTER , $ filterName , $ filterHandlerName , $ priority ) ; } | Removes an filter handler |
31,468 | protected function removeHandler ( $ type , $ name , $ handlerName , $ priority ) { if ( ! isset ( $ this -> handlers [ $ type ] [ $ name ] [ $ priority ] ) ) { return ; } if ( ! in_array ( $ handlerName , $ this -> handlers [ $ type ] [ $ name ] [ $ priority ] ) ) { return ; } $ index = array_search ( $ handlerName , $ this -> handlers [ $ type ] [ $ name ] [ $ priority ] ) ; unset ( $ this -> handlers [ $ type ] [ $ name ] [ $ priority ] [ $ index ] ) ; $ this -> saveHandlers ( ) ; } | Removes an handler |
31,469 | public function clearCache ( $ reactivateModules = true ) { $ this -> handlers = array ( ) ; if ( $ reactivateModules ) { $ this -> framework -> getModuleManager ( ) -> reactivateModules ( ) ; } } | Clears the handlers cache and reactivates the modules to rebuild the cache . |
31,470 | private function getLimit ( ? int $ limit = null ) : ? int { if ( is_int ( $ limit ) && $ limit >= 0 ) { return $ limit ; } return null ; } | Return filtered limit value to use . |
31,471 | static function ParseFullName ( $ fullName ) { $ fullName = strtolower ( $ fullName ) ; $ name = $ fullName ; $ length = 0 ; $ set = array ( ) ; $ modifiers = '' ; $ bracePos1 = strpos ( $ fullName , '(' ) ; $ bracePos2 = 0 ; if ( $ bracePos1 > 0 ) { $ name = trim ( substr ( $ fullName , 0 , $ bracePos1 ) ) ; $ bracePos2 = strpos ( $ fullName , ')' , $ bracePos1 ) ; } if ( $ bracePos1 && $ bracePos2 ) { $ inBrace = trim ( substr ( $ fullName , $ bracePos1 + 1 , $ bracePos2 - $ bracePos1 - 1 ) ) ; self :: ParseInBrace ( $ inBrace , $ set , $ length ) ; if ( $ bracePos2 < strlen ( $ fullName ) - 1 ) { $ modifiers = trim ( strtolower ( substr ( $ fullName , $ bracePos2 + 1 ) ) ) ; } } $ type = self :: CalcType ( $ name , $ length ) ; return new self ( $ name , $ type , $ set , $ length , $ modifiers ) ; } | Parses pure parse name and set or length from full type name . |
31,472 | public function addRowRenderer ( RowRendererInterface $ renderer ) : void { $ required_columns = $ renderer -> getRequiredColumns ( ) ; foreach ( $ required_columns as $ column ) { if ( ! $ this -> exists ( $ column ) ) { $ cls = get_class ( $ renderer ) ; $ msg = "Renderer '$cls' requires column '$column' to be present in column model." ; throw new Exception \ MissingColumnException ( __METHOD__ . ': ' . $ msg ) ; } } $ this -> row_renderers -> append ( $ renderer ) ; } | Add a row renderer . |
31,473 | public function getUniqueFormatters ( bool $ include_excluded_columns = false ) : ArrayObject { $ unique = new ArrayObject ( ) ; $ formatters = $ this -> getFormatters ( ) ; foreach ( $ formatters as $ column => $ formatter ) { if ( $ include_excluded_columns || ! $ this -> get ( $ column ) -> isExcluded ( ) ) { $ hash = spl_object_hash ( $ formatter ) ; if ( ! $ unique -> offsetExists ( $ hash ) ) { $ tmp = new ArrayObject ( [ 'formatter' => $ formatter , 'columns' => new ArrayObject ( [ $ column ] ) ] ) ; $ unique -> offsetSet ( $ hash , $ tmp ) ; } else { $ unique -> offsetGet ( $ hash ) -> offsetGet ( 'columns' ) -> append ( $ column ) ; } } } return $ unique ; } | This method returns unique formatters set in the column model in an ArrayObject . |
31,474 | public function add ( Column $ column , string $ after_column = null , string $ mode = self :: ADD_COLUMN_AFTER ) : self { $ name = $ column -> getName ( ) ; if ( $ this -> exists ( $ name ) ) { $ msg = "Cannot add column '$name', it's already present in column model" ; throw new Exception \ DuplicateColumnException ( __METHOD__ . ': ' . $ msg ) ; } if ( $ after_column !== null ) { if ( ! $ this -> exists ( $ after_column ) ) { $ msg = "Cannot add column '$name' after '$after_column', column does not exists." ; throw new Exception \ ColumnNotFoundException ( __METHOD__ . ': ' . $ msg ) ; } if ( ! in_array ( $ mode , [ self :: ADD_COLUMN_BEFORE , self :: ADD_COLUMN_AFTER ] , true ) ) { $ msg = "Cannot add column '$name', invalid mode specified '$mode'" ; throw new Exception \ InvalidArgumentException ( __METHOD__ . ': ' . $ msg ) ; } $ new_columns = new ArrayObject ( ) ; foreach ( $ this -> columns as $ key => $ col ) { if ( $ mode === self :: ADD_COLUMN_BEFORE && $ key === $ after_column ) { $ new_columns -> offsetSet ( $ name , $ column ) ; } $ new_columns -> offsetSet ( $ key , $ col ) ; if ( $ mode === self :: ADD_COLUMN_AFTER && $ key === $ after_column ) { $ new_columns -> offsetSet ( $ name , $ column ) ; } } $ this -> columns -> exchangeArray ( $ new_columns ) ; } else { $ this -> columns -> offsetSet ( $ name , $ column ) ; } return $ this ; } | Add a new column to the column model . |
31,475 | public function exists ( string $ column ) : bool { if ( trim ( $ column ) === '' ) { throw new Exception \ InvalidArgumentException ( __METHOD__ . ' Column name cannot be empty' ) ; } return $ this -> columns -> offsetExists ( $ column ) ; } | Tells whether a column exists . |
31,476 | public function get ( $ column ) : Column { if ( ! $ this -> exists ( $ column ) ) { throw new Exception \ ColumnNotFoundException ( __METHOD__ . " Column '$column' not present in column model." ) ; } return $ this -> columns -> offsetGet ( $ column ) ; } | Return column from identifier name . |
31,477 | public function sort ( array $ sorted_columns ) : self { $ diff = array_diff_assoc ( $ sorted_columns , array_unique ( $ sorted_columns ) ) ; if ( count ( $ diff ) > 0 ) { $ cols = implode ( ',' , $ diff ) ; throw new Exception \ DuplicateColumnException ( __METHOD__ . " Duplicate column found in paramter sorted_columns : '$cols'" ) ; } $ columns = [ ] ; foreach ( $ sorted_columns as $ idx => $ column ) { if ( ! $ this -> exists ( $ column ) ) { throw new Exception \ InvalidArgumentException ( __METHOD__ . " Column '$column' does not exists." ) ; } $ columns [ $ column ] = $ this -> get ( $ column ) ; } $ columns = array_merge ( $ columns , ( array ) $ this -> columns ) ; $ this -> columns -> exchangeArray ( $ columns ) ; return $ this ; } | Sort columns in the order specified columns that exists in the dataset but not in the sorted_columns will be appended to the end . |
31,478 | public function getColumns ( $ include_excluded_columns = false ) : ArrayObject { $ arr = new ArrayObject ( ) ; foreach ( $ this -> columns as $ key => $ column ) { if ( $ include_excluded_columns || ! $ column -> isExcluded ( ) ) { $ arr -> offsetSet ( $ key , $ column ) ; } } return $ arr ; } | Return columns . |
31,479 | public function setFormatter ( FormatterInterface $ formatter , array $ columns ) : self { $ this -> search ( ) -> in ( $ columns ) -> setFormatter ( $ formatter ) ; return $ this ; } | Set formatter to specific columns . |
31,480 | public function handleUninstall ( PackageEvent $ event ) : void { if ( ! $ this -> enabled ) { return ; } $ operation = $ event -> getOperation ( ) ; if ( $ operation instanceof UninstallOperation ) { $ package = $ operation -> getPackage ( ) ; if ( in_array ( $ package -> getName ( ) , $ this -> excluded ) ) { $ this -> io -> write ( sprintf ( '<info>Rikudou installer: Package %s ignored in composer settings</info>' , $ package -> getName ( ) ) ) ; return ; } $ this -> projectType = ProjectTypeGetter :: get ( $ this -> composer ) ; if ( is_null ( $ this -> projectType ) ) { return ; } $ handler = new PackageHandler ( $ package , $ this -> projectType , $ this -> composer ) ; if ( $ handler -> canBeHandled ( ) ) { $ this -> io -> write ( '<comment>=== [Rikudou Installer] ===</comment>' ) ; foreach ( $ handler -> handleUninstall ( ) as $ operationResult ) { foreach ( $ operationResult -> getMessagesCollection ( ) -> getGenerator ( ) as $ message ) { if ( $ message -> isStatusMessage ( ) || $ message -> isWarningMessage ( ) ) { $ this -> io -> write ( $ message -> getMessage ( ) ) ; } else { $ this -> io -> writeError ( $ message -> getMessage ( ) ) ; } } } $ this -> io -> write ( '<comment>=== [Rikudou Installer] ===</comment>' ) ; } } } | Tries to uninstall the package |
31,481 | private function preload ( ) : void { $ iterator = new \ RecursiveIteratorIterator ( new \ RecursiveDirectoryIterator ( __DIR__ ) ) ; foreach ( $ iterator as $ file ) { if ( $ file -> isFile ( ) && $ file -> getExtension ( ) === 'php' ) { require_once $ file -> getRealPath ( ) ; } } $ definedClasses = get_declared_classes ( ) ; foreach ( $ definedClasses as $ definedClass ) { try { $ reflection = new \ ReflectionClass ( $ definedClass ) ; if ( $ reflection -> implementsInterface ( PreloadInterface :: class ) ) { $ callback = [ $ definedClass , 'preload' ] ; assert ( is_callable ( $ callback ) ) ; call_user_func ( $ callback , $ this -> composer ) ; } } catch ( \ ReflectionException $ e ) { continue ; } } } | Preloads all classes |
31,482 | public function login ( $ username , $ password ) { $ credentials = array ( 'lgname' => $ username , 'lgpassword' => $ password ) ; $ firstlogin = $ this -> client -> login ( $ credentials ) ; $ this -> failOnError ( "Wiki login failed." , $ firstlogin ) ; $ resultMsg = $ firstlogin [ 'login' ] [ 'result' ] ; if ( $ resultMsg != "NeedToken" && $ resultMsg != "Success" ) { throw new SessionException ( "Wiki login failed: $resultMsg" ) ; } if ( $ resultMsg == "NeedToken" ) { $ secondLogin = $ this -> client -> login ( array_merge ( array ( 'lgtoken' => $ firstlogin [ 'login' ] [ 'token' ] ) , $ credentials ) ) ; $ this -> failOnError ( "Wiki login failed." , $ secondLogin ) ; $ resultMsg = $ secondLogin [ 'login' ] [ 'result' ] ; if ( $ resultMsg != "Success" ) { throw new SessionException ( "Wiki login failed: $resultMsg" ) ; } $ this -> tokencache [ 'login' ] = $ firstlogin [ 'login' ] [ 'token' ] ; } } | Perform API login |
31,483 | public function getToken ( $ type , $ allowCache = true ) { $ tokenName = $ type . 'token' ; if ( ! empty ( $ this -> tokencache [ $ tokenName ] ) && $ allowCache ) { return $ this -> tokencache [ $ tokenName ] ; } $ tokens = $ this -> getTokens ( array ( $ type ) ) ; return $ tokens [ $ tokenName ] ; } | Get a single token from API or from cache if one was already fetched . |
31,484 | public function clear ( ) { $ this -> statement = null ; $ this -> clearUsingModel ( ) ; $ this -> query -> clear ( ) ; $ this -> grammar -> clear ( ) ; } | Clear statement PDO and query builder |
31,485 | function MoveTo ( $ targetFolder , $ targetFilename = '' ) { if ( ! $ targetFilename ) $ targetFilename = $ this -> Filename ( ) ; $ destination = Path :: Combine ( $ targetFolder , $ targetFilename ) ; $ result = @ move_uploaded_file ( $ this -> TempPath ( ) , $ destination ) ; if ( ! $ result ) throw new \ Exception ( 'Uploaded file could not be moved to target' ) ; } | moves the temporary uploaded file to another destination |
31,486 | private function _generateInitialResponse ( $ authcid , $ authzid ) { $ gs2_cbind_flag = 'n,' ; $ this -> gs2_header = $ gs2_cbind_flag . ( ! empty ( $ authzid ) ? 'a=' . $ authzid : '' ) . ',' ; $ this -> cnonce = $ this -> _getCnonce ( ) ; $ this -> first_message_bare = 'n=' . $ authcid . ',r=' . $ this -> cnonce ; return $ this -> gs2_header . $ this -> first_message_bare ; } | Generate the initial response which can be either sent directly in the first message or as a response to an empty server challenge . |
31,487 | private function _generateResponse ( $ challenge , $ password ) { $ matches = [ ] ; $ server_message_regexp = "#^r=([\x21-\x2B\x2D-\x7E]+),s=((?:[A-Za-z0-9/+]{4})*(?:[A-Za-z0-9]{3}=|[A-Xa-z0-9]{2}==)?),i=([0-9]*)(,[A-Za-z]=[^,])*$#" ; if ( ! isset ( $ this -> cnonce , $ this -> gs2_header ) || ! preg_match ( $ server_message_regexp , $ challenge , $ matches ) ) { return false ; } $ nonce = $ matches [ 1 ] ; $ salt = base64_decode ( $ matches [ 2 ] ) ; if ( ! $ salt ) { return false ; } $ i = intval ( $ matches [ 3 ] ) ; $ cnonce = substr ( $ nonce , 0 , strlen ( $ this -> cnonce ) ) ; if ( $ cnonce <> $ this -> cnonce ) { return false ; } $ channel_binding = 'c=' . base64_encode ( $ this -> gs2_header ) ; $ final_message = $ channel_binding . ',r=' . $ nonce ; $ saltedPassword = $ this -> hi ( $ password , $ salt , $ i ) ; $ this -> saltedPassword = $ saltedPassword ; $ clientKey = call_user_func ( $ this -> hmac , $ saltedPassword , "Client Key" , TRUE ) ; $ storedKey = call_user_func ( $ this -> hash , $ clientKey , TRUE ) ; $ authMessage = $ this -> first_message_bare . ',' . $ challenge . ',' . $ final_message ; $ this -> authMessage = $ authMessage ; $ clientSignature = call_user_func ( $ this -> hmac , $ storedKey , $ authMessage , TRUE ) ; $ clientProof = $ clientKey ^ $ clientSignature ; $ proof = ',p=' . base64_encode ( $ clientProof ) ; return $ final_message . $ proof ; } | Parses and verifies a non - empty SCRAM challenge . |
31,488 | public function processOutcome ( $ data ) { $ verifier_regexp = '#^v=((?:[A-Za-z0-9/+]{4})*(?:[A-Za-z0-9]{3}=|[A-Xa-z0-9]{2}==)?)$#' ; $ matches = [ ] ; if ( ! isset ( $ this -> saltedPassword , $ this -> authMessage ) || ! preg_match ( $ verifier_regexp , $ data , $ matches ) ) { return false ; } $ verifier = $ matches [ 1 ] ; $ proposed_serverSignature = base64_decode ( $ verifier ) ; $ serverKey = call_user_func ( $ this -> hmac , $ this -> saltedPassword , "Server Key" , true ) ; $ serverSignature = call_user_func ( $ this -> hmac , $ serverKey , $ this -> authMessage , TRUE ) ; return ( $ proposed_serverSignature === $ serverSignature ) ; } | SCRAM has also a server verification step . On a successful outcome it will send additional data which must absolutely be checked against this function . If this fails the entity which we are communicating with is probably not the server as it has not access to your ServerKey . |
31,489 | private function discoverRoutes ( ) { $ parentRoutes = $ this -> config -> paths -> theme -> parent -> routes ; $ childRoutes = $ this -> config -> paths -> theme -> child -> routes ; $ files = $ this -> finder -> createFinder ( ) -> files ( ) -> name ( '*.php' ) -> in ( $ parentRoutes ) ; if ( $ parentRoutes != $ childRoutes && is_dir ( $ childRoutes ) ) { $ files = $ files -> in ( $ childRoutes ) ; } $ splFiles = [ ] ; foreach ( $ files as $ file ) $ splFiles [ ] = $ file ; $ orderedFiles = Linq :: from ( $ splFiles ) -> orderBy ( '$v' , function ( $ a , $ b ) { return strnatcasecmp ( $ a -> getBasename ( '.php' ) , $ b -> getBasename ( '.php' ) ) ; } ) ; foreach ( $ orderedFiles as $ file ) { $ route = import ( $ file -> getRealPath ( ) , [ 'route' => $ this -> routes ] ) ; if ( is_callable ( $ route ) ) { $ this -> container -> call ( $ route , [ 'config' => $ this -> config ] ) ; } } } | Finds all theme route files and adds the routes to the RouteCollection . |
31,490 | public function buildLocalFilterRegistries ( ContainerBuilder $ container ) { $ filters = $ container -> findTaggedServiceIds ( 'spray_persistence.entity_filter' ) ; foreach ( $ filters as $ filterId => $ filterOptions ) { foreach ( array_filter ( $ filterOptions , array ( $ this , 'filterLocalFilterOptions' ) ) as $ options ) { $ registryId = $ this -> determineRegistryIdForRepositoryId ( $ options [ 'repository' ] ) ; $ this -> attachFilterToRegistry ( $ this -> locateFilterRegistry ( $ container , $ registryId ) , $ filterId , $ options ) ; $ this -> attachRegistryToRepository ( $ container , $ registryId , $ options [ 'repository' ] ) ; } } } | Build all local filter registries |
31,491 | public function attachRegistryToRepository ( ContainerBuilder $ container , $ registryId , $ repositoryId ) { $ registry = $ container -> getDefinition ( $ registryId ) ; $ repository = $ container -> getDefinition ( $ repositoryId ) ; if ( ! $ registry -> hasTag ( 'spray_persistence.filter_registry' ) ) { $ registry -> addTag ( 'spray_persistence.filter_registry' ) ; } if ( ! $ repository -> hasMethodCall ( 'setFilterLocator' ) ) { $ repository -> addMethodCall ( 'setFilterLocator' , array ( new Reference ( $ registryId ) ) ) ; } } | Attached filter registry to a repository by its id |
31,492 | public function cron ( ) { ini_set ( 'memory_limit' , "512M" ) ; ini_set ( 'max_execution_time' , 60 * 60 * 60 ) ; require_once ( ABSPATH . 'wp-admin/includes/user.php' ) ; $ createAccounts = $ this -> diffUserAccounts ( true ) ; $ deleteAccounts = $ this -> diffUserAccounts ( false ) ; $ maxDeleteLimit = isset ( $ _GET [ 'maxDeletelimit' ] ) ? ( int ) $ _GET [ 'maxDeletelimit' ] : 100 ; if ( count ( $ deleteAccounts ) > $ maxDeleteLimit ) { if ( is_main_site ( ) ) { if ( get_transient ( 'ad_api_too_many_deletions' ) !== 1 ) { wp_mail ( get_option ( 'admin_email' ) , "Ad-integration plugin" , __ ( "To many user deletions in queue (" . count ( $ deleteAccounts ) . "/" . $ maxDeleteLimit . ") add https://test.dev/wp-admin/?adbulkimport&maxDeleteLimit=100 to your query to allow number of required deletions." , "adintegration" ) ) ; error_log ( "Ad-integration plugin: To many user deletions in queue (" . count ( $ deleteAccounts ) . "/" . $ maxDeleteLimit . ") add https://test.dev/wp-admin/?adbulkimport&maxDeleteLimit=100 to your query to allow number of required deletions." ) ; set_transient ( 'ad_api_too_many_deletions' , 1 , 23 * HOUR_IN_SECONDS ) ; } } } else { if ( is_array ( $ deleteAccounts ) && ! empty ( $ deleteAccounts ) ) { foreach ( ( array ) $ deleteAccounts as $ accountName ) { $ this -> deleteAccount ( $ accountName ) ; } } } if ( is_array ( $ createAccounts ) && ! empty ( $ createAccounts ) ) { foreach ( ( array ) $ createAccounts as $ accountName ) { if ( ! in_array ( $ accountName , $ deleteAccounts ) ) { $ this -> createAccount ( $ accountName ) ; } } } $ this -> scheduleUpdateProfiles ( ) ; } | Cron function run this class |
31,493 | private function bulkEnabled ( ) { if ( ! ( defined ( 'AD_BULK_IMPORT' ) || ( defined ( 'AD_BULK_IMPORT' ) && AD_BULK_IMPORT !== true ) ) ) { return false ; } if ( ! defined ( 'AD_BULK_IMPORT_USER' ) || ! defined ( 'AD_BULK_IMPORT_PASSWORD' ) ) { return false ; } return true ; } | Check if all details that are neeeded to run this function is defined . |
31,494 | public function getLocalAccounts ( ) { if ( ! is_null ( $ this -> localAccountCache ) ) { return $ this -> localAccountCache ; } return $ this -> localAccountCache = array_map ( 'strtolower' , $ this -> db -> get_col ( "SELECT user_login FROM " . $ this -> db -> users . " ORDER BY RAND()" ) ) ; } | Return all local accountnames |
31,495 | public function getAdAccounts ( ) { $ data = array ( 'username' => AD_BULK_IMPORT_USER , 'password' => AD_BULK_IMPORT_PASSWORD ) ; $ index = $ this -> curl -> request ( 'POST' , rtrim ( AD_INTEGRATION_URL , "/" ) . '/user/index' , $ data , 'json' , array ( 'Content-Type: application/json' ) ) ; if ( $ this -> response :: isJsonError ( $ index ) || ! json_decode ( $ index ) ) { return false ; } if ( json_last_error ( ) != JSON_ERROR_NONE ) { error_log ( "Ad integration: Could not read index due to the fact that the response wasen't a valid json string." ) ; exit ; } return array_map ( 'strtolower' , json_decode ( $ index ) ) ; } | Returns all accountnames registered in the ad index |
31,496 | public function diffUserAccounts ( $ getMissingAccountsLocally = true ) { $ ad = $ this -> getAdAccounts ( ) ; $ local = $ this -> getLocalAccounts ( ) ; if ( $ getMissingAccountsLocally === true ) { return array_diff ( ( array ) $ ad , ( array ) $ local ) ; } else { return array_diff ( ( array ) $ local , ( array ) $ ad ) ; } } | Get all usernames as an array that dosent exist in either enviroment |
31,497 | public function createAccount ( $ userNames ) { if ( ! is_array ( $ userNames ) ) { $ userNames = array ( $ userNames ) ; } foreach ( $ userNames as $ userName ) { if ( empty ( $ userName ) ) { continue ; } if ( ! in_array ( $ userName , $ this -> getLocalAccounts ( ) ) ) { if ( $ this -> userNameExists ( $ userName ) === false ) { try { $ userId = wp_insert_user ( array ( 'user_login' => $ userName , 'user_pass' => wp_generate_password ( ) , 'user_nicename' => $ userName , 'user_email' => $ this -> createFakeEmail ( $ userName ) , 'user_registered' => date ( 'Y-m-d H:i:s' ) , 'role' => $ this -> defaultRole ) ) ; } catch ( \ Exception $ e ) { error_log ( "Error: Could not create a new user using bulk data (ad-api-integration)." ) ; } } else { $ userId = null ; } if ( is_numeric ( $ userId ) ) { $ this -> setUserRole ( $ userId ) ; } } } } | Creates a single user if it not exists . |
31,498 | private function setUserRole ( $ userId ) { if ( is_multisite ( ) ) { if ( is_null ( $ this -> sites ) ) { $ this -> initSites ( ) ; } if ( is_super_admin ( $ userId ) ) { $ role = "administrator" ; } else { $ role = $ this -> defaultRole ; } if ( defined ( 'AD_BULK_IMPORT_PROPAGATE' ) && AD_BULK_IMPORT_PROPAGATE === true ) { foreach ( $ this -> sites as $ site ) { if ( is_user_member_of_blog ( $ userId , $ site -> blog_id ) === true ) { continue ; } add_user_to_blog ( $ site -> blog_id , $ userId , $ role ) ; } } elseif ( is_user_member_of_blog ( $ userId , get_current_blog_id ( ) ) !== true ) { add_user_to_blog ( get_current_blog_id ( ) , $ userId , $ role ) ; } } else { if ( isset ( get_userdata ( $ userId ) -> roles ) && ! empty ( get_userdata ( $ userId ) -> roles ) ) { return false ; } wp_update_user ( array ( 'ID' => $ userId , 'role' => $ this -> defaultRole ) ) ; } } | Update role if account is newly created . If is multiste assign to all sites . |
31,499 | public function deleteAccount ( $ userToDelete ) { if ( $ userId = $ this -> userNameExists ( $ userToDelete ) ) { if ( is_multisite ( ) ) { if ( $ reassign = $ this -> reassignToUserId ( ) ) { foreach ( $ this -> sites as $ site ) { remove_user_from_blog ( $ userId , $ site -> blog_id , $ reassign ) ; } $ this -> db -> delete ( $ this -> db -> users , array ( 'ID' => $ userId ) ) ; } } else { if ( $ reassign = $ this -> reassignToUserId ( ) ) { wp_delete_user ( $ userId , $ reassign ) ; } } } } | Delete and reassign content to user id defined by reassignToUserId function . |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.