idx int64 0 60.3k | question stringlengths 64 4.24k | target stringlengths 5 618 |
|---|---|---|
27,700 | public function getProductCategoriesForASIN ( $ request ) { if ( ! ( $ request instanceof MarketplaceWebServiceProducts_Model_GetProductCategoriesForASINRequest ) ) { require_once ( dirname ( __FILE__ ) . '/Model/GetProductCategoriesForASINRequest.php' ) ; $ request = new MarketplaceWebServiceProducts_Model_GetProductCategoriesForASINRequest ( $ request ) ; } $ parameters = $ request -> toQueryParameterArray ( ) ; $ parameters [ 'Action' ] = 'GetProductCategoriesForASIN' ; $ httpResponse = $ this -> _invoke ( $ parameters ) ; require_once ( dirname ( __FILE__ ) . '/Model/GetProductCategoriesForASINResponse.php' ) ; $ response = MarketplaceWebServiceProducts_Model_GetProductCategoriesForASINResponse :: fromXML ( $ httpResponse [ 'ResponseBody' ] ) ; $ response -> setResponseHeaderMetadata ( $ httpResponse [ 'ResponseHeaderMetadata' ] ) ; return $ response ; } | Get Product Categories For ASIN Gets categories information for a product identified by the MarketplaceId and ASIN . |
27,701 | private function _convertGetProductCategoriesForASIN ( $ request ) { $ parameters = array ( ) ; $ parameters [ 'Action' ] = 'GetProductCategoriesForASIN' ; if ( $ request -> isSetSellerId ( ) ) { $ parameters [ 'SellerId' ] = $ request -> getSellerId ( ) ; } if ( $ request -> isSetMWSAuthToken ( ) ) { $ parameters [ 'MWSAuthToken' ] = $ request -> getMWSAuthToken ( ) ; } if ( $ request -> isSetMarketplaceId ( ) ) { $ parameters [ 'MarketplaceId' ] = $ request -> getMarketplaceId ( ) ; } if ( $ request -> isSetASIN ( ) ) { $ parameters [ 'ASIN' ] = $ request -> getASIN ( ) ; } return $ parameters ; } | Convert GetProductCategoriesForASINRequest to name value pairs |
27,702 | public function getProductCategoriesForSKU ( $ request ) { if ( ! ( $ request instanceof MarketplaceWebServiceProducts_Model_GetProductCategoriesForSKURequest ) ) { require_once ( dirname ( __FILE__ ) . '/Model/GetProductCategoriesForSKURequest.php' ) ; $ request = new MarketplaceWebServiceProducts_Model_GetProductCategoriesForSKURequest ( $ request ) ; } $ parameters = $ request -> toQueryParameterArray ( ) ; $ parameters [ 'Action' ] = 'GetProductCategoriesForSKU' ; $ httpResponse = $ this -> _invoke ( $ parameters ) ; require_once ( dirname ( __FILE__ ) . '/Model/GetProductCategoriesForSKUResponse.php' ) ; $ response = MarketplaceWebServiceProducts_Model_GetProductCategoriesForSKUResponse :: fromXML ( $ httpResponse [ 'ResponseBody' ] ) ; $ response -> setResponseHeaderMetadata ( $ httpResponse [ 'ResponseHeaderMetadata' ] ) ; return $ response ; } | Get Product Categories For SKU Gets categories information for a product identified by the SellerId and SKU . |
27,703 | private function _convertGetProductCategoriesForSKU ( $ request ) { $ parameters = array ( ) ; $ parameters [ 'Action' ] = 'GetProductCategoriesForSKU' ; if ( $ request -> isSetSellerId ( ) ) { $ parameters [ 'SellerId' ] = $ request -> getSellerId ( ) ; } if ( $ request -> isSetMWSAuthToken ( ) ) { $ parameters [ 'MWSAuthToken' ] = $ request -> getMWSAuthToken ( ) ; } if ( $ request -> isSetMarketplaceId ( ) ) { $ parameters [ 'MarketplaceId' ] = $ request -> getMarketplaceId ( ) ; } if ( $ request -> isSetSellerSKU ( ) ) { $ parameters [ 'SellerSKU' ] = $ request -> getSellerSKU ( ) ; } return $ parameters ; } | Convert GetProductCategoriesForSKURequest to name value pairs |
27,704 | public function getServiceStatus ( $ request ) { if ( ! ( $ request instanceof MarketplaceWebServiceProducts_Model_GetServiceStatusRequest ) ) { require_once ( dirname ( __FILE__ ) . '/Model/GetServiceStatusRequest.php' ) ; $ request = new MarketplaceWebServiceProducts_Model_GetServiceStatusRequest ( $ request ) ; } $ parameters = $ request -> toQueryParameterArray ( ) ; $ parameters [ 'Action' ] = 'GetServiceStatus' ; $ httpResponse = $ this -> _invoke ( $ parameters ) ; require_once ( dirname ( __FILE__ ) . '/Model/GetServiceStatusResponse.php' ) ; $ response = MarketplaceWebServiceProducts_Model_GetServiceStatusResponse :: fromXML ( $ httpResponse [ 'ResponseBody' ] ) ; $ response -> setResponseHeaderMetadata ( $ httpResponse [ 'ResponseHeaderMetadata' ] ) ; return $ response ; } | Get Service Status Returns the service status of a particular MWS API section . The operation takes no input . All API sections within the API are required to implement this operation . |
27,705 | public function listMatchingProducts ( $ request ) { if ( ! ( $ request instanceof MarketplaceWebServiceProducts_Model_ListMatchingProductsRequest ) ) { require_once ( dirname ( __FILE__ ) . '/Model/ListMatchingProductsRequest.php' ) ; $ request = new MarketplaceWebServiceProducts_Model_ListMatchingProductsRequest ( $ request ) ; } $ parameters = $ request -> toQueryParameterArray ( ) ; $ parameters [ 'Action' ] = 'ListMatchingProducts' ; $ httpResponse = $ this -> _invoke ( $ parameters ) ; require_once ( dirname ( __FILE__ ) . '/Model/ListMatchingProductsResponse.php' ) ; $ response = MarketplaceWebServiceProducts_Model_ListMatchingProductsResponse :: fromXML ( $ httpResponse [ 'ResponseBody' ] ) ; $ response -> setResponseHeaderMetadata ( $ httpResponse [ 'ResponseHeaderMetadata' ] ) ; return $ response ; } | List Matching Products ListMatchingProducts can be used to find products that match the given criteria . |
27,706 | private function _convertListMatchingProducts ( $ request ) { $ parameters = array ( ) ; $ parameters [ 'Action' ] = 'ListMatchingProducts' ; if ( $ request -> isSetSellerId ( ) ) { $ parameters [ 'SellerId' ] = $ request -> getSellerId ( ) ; } if ( $ request -> isSetMWSAuthToken ( ) ) { $ parameters [ 'MWSAuthToken' ] = $ request -> getMWSAuthToken ( ) ; } if ( $ request -> isSetMarketplaceId ( ) ) { $ parameters [ 'MarketplaceId' ] = $ request -> getMarketplaceId ( ) ; } if ( $ request -> isSetQuery ( ) ) { $ parameters [ 'Query' ] = $ request -> getQuery ( ) ; } if ( $ request -> isSetQueryContextId ( ) ) { $ parameters [ 'QueryContextId' ] = $ request -> getQueryContextId ( ) ; } return $ parameters ; } | Convert ListMatchingProductsRequest to name value pairs |
27,707 | public function send ( $ method , $ endpoint , $ data = [ ] ) { $ method = strtolower ( $ method ) ; if ( $ method !== 'get' && $ this -> isUserLoggedIn ( ) ) { $ this -> generateCSRFToken ( ) ; } $ csfrToken = '-' ; $ cookies = $ this -> client -> getConfig ( ) [ 'cookies' ] ; foreach ( $ cookies -> toArray ( ) as $ cookie ) { if ( $ cookie [ 'Name' ] === 'CSRF_TOKEN' ) { $ csfrToken = $ cookie [ 'Value' ] ; break ; } } $ options = [ 'body' => $ method === 'post' || $ method === 'put' ? json_encode ( $ data ) : null , 'headers' => [ 'Content-Type' => 'application/json' , 'Cookie' => 'CSRF_TOKEN=' . $ csfrToken , 'X-CSRF-TOKEN' => $ csfrToken , ] ] ; return $ this -> client -> $ method ( $ endpoint , $ options ) ; } | Send request to Endomondo API . |
27,708 | public function onLogEvent ( LogEvent $ event ) { $ context = $ event -> getContext ( ) ; $ context [ 'event.name' ] = $ event -> getEventNameContext ( ) ; $ eventSubscriberClassName = get_class ( $ event -> getEventSubscriberContext ( ) ) ; if ( strrpos ( $ eventSubscriberClassName , '\\' ) !== false ) { $ eventSubscriberClassName = substr ( $ eventSubscriberClassName , strrpos ( $ eventSubscriberClassName , '\\' ) + 1 ) ; } $ context [ 'event.task.name' ] = $ eventSubscriberClassName ; $ this -> logger -> log ( $ event -> getLevel ( ) , $ event -> getMessage ( ) , $ context ) ; } | Logs the LogEvent to the logger instance . |
27,709 | public function onPrepareReleaseConstructReleaseInstance ( PrepareReleaseEvent $ event ) { if ( ( $ event -> getRelease ( ) instanceof Release ) === false ) { $ release = new Release ( $ event -> getVersion ( ) ) ; $ event -> getWorkspace ( ) -> addRelease ( $ release ) ; $ event -> setRelease ( $ release ) ; } } | Creates a Release instance when not already available . |
27,710 | public function onPrepareReleaseCheckoutRepository ( PrepareReleaseEvent $ event , $ eventName , EventDispatcherInterface $ eventDispatcher ) { $ context = array ( 'repositoryUrl' => $ this -> repositoryUrl , 'version' => $ event -> getRelease ( ) -> getVersion ( ) , 'event.task.action' => TaskInterface :: ACTION_IN_PROGRESS ) ; $ connection = $ this -> ensureConnection ( $ event -> getRelease ( ) -> getWorkspace ( ) -> getHost ( ) ) ; $ processExecutor = new ConnectionAdapterProcessExecutor ( $ connection ) ; $ eventDispatcher -> dispatch ( AccompliEvents :: LOG , new LogEvent ( LogLevel :: NOTICE , 'Creating checkout of repository "{repositoryUrl}" for version "{version}".' , $ eventName , $ this , $ context ) ) ; $ repository = new Repository ( $ this -> repositoryUrl , $ event -> getRelease ( ) -> getPath ( ) , $ processExecutor ) ; if ( $ repository -> checkout ( $ event -> getRelease ( ) -> getVersion ( ) ) ) { $ context [ 'event.task.action' ] = TaskInterface :: ACTION_COMPLETED ; $ context [ 'output.resetLine' ] = true ; $ eventDispatcher -> dispatch ( AccompliEvents :: LOG , new LogEvent ( LogLevel :: NOTICE , 'Created checkout of repository "{repositoryUrl}" for version "{version}".' , $ eventName , $ this , $ context ) ) ; } else { throw new TaskCommandExecutionException ( sprintf ( 'Failed to checkout version "%s" from repository "%s".' , $ event -> getRelease ( ) -> getVersion ( ) , $ this -> repositoryUrl ) , $ processExecutor -> getLastProcessExecutionResult ( ) , $ this ) ; } } | Creates a checkout of the repository for the release . |
27,711 | protected function bulkAttachmentUpsert ( array $ nodes ) { $ nids = [ ] ; $ params = [ ] ; $ this -> totalSizeBytes = 0 ; foreach ( $ nodes as $ node ) { try { $ attachments = $ this -> getEncodedAttachments ( $ node ) ; } catch ( MaxSizeAttachmentExceedException $ e ) { watchdog ( 'ucms_search_attachment' , '!nid attachments not indexed because max file size is exceed' , [ '!nid' => $ node -> nid ] , WATCHDOG_NOTICE ) ; continue ; } $ nids [ ] = $ node -> id ( ) ; if ( $ attachments ) { $ params [ 'body' ] [ ] = [ 'index' => [ '_index' => $ this -> indexRealname , '_id' => $ node -> id ( ) , '_type' => 'node' , ] , ] ; $ params [ 'body' ] [ ] = [ 'attachment' => $ attachments , ] ; } } if ( $ params ) { $ this -> client -> bulk ( $ params ) ; } if ( $ nids ) { $ this -> db -> update ( 'ucms_search_status' ) -> fields ( [ 'needs_attachments_reindex' => 0 ] ) -> condition ( 'nid' , $ nids ) -> condition ( 'index_key' , $ this -> index ) -> execute ( ) ; } } | Update ES documents with attachments . Multiple attachments per document is allowed but be careful with memory usage! |
27,712 | public function getSortStructure ( ) { $ sort = [ $ this -> getField ( ) => ( object ) [ 'order' => $ this -> getOrder ( ) ] ] ; if ( $ this -> getMode ( ) ) { $ sort [ $ this -> getField ( ) ] -> mode = $ this -> getMode ( ) ; } if ( $ this -> getMissing ( ) ) { $ sort [ $ this -> getField ( ) ] -> missing = $ this -> getMissing ( ) ; } return ( object ) $ sort ; } | Get sort structure . |
27,713 | public function onEvent ( Event $ event , $ eventName , EventDispatcherInterface $ eventDispatcher ) { if ( in_array ( $ eventName , $ this -> events ) ) { if ( $ event instanceof ReleaseEvent ) { $ release = $ event -> getRelease ( ) ; $ host = $ release -> getWorkspace ( ) -> getHost ( ) ; $ path = $ release -> getPath ( ) ; } else { $ host = $ event -> getWorkspace ( ) -> getHost ( ) ; $ path = $ host -> getPath ( ) ; } $ connection = $ this -> ensureConnection ( $ host ) ; $ currentWorkingDirectory = $ connection -> getWorkingDirectory ( ) ; $ eventDispatcher -> dispatch ( AccompliEvents :: LOG , new LogEvent ( LogLevel :: NOTICE , 'Executing command "{command}".' , $ eventName , $ this , array ( 'command' => $ this -> command , 'event.task.action' => TaskInterface :: ACTION_IN_PROGRESS ) ) ) ; $ connection -> changeWorkingDirectory ( $ path ) ; $ result = $ connection -> executeCommand ( $ this -> command , $ this -> arguments ) ; $ connection -> changeWorkingDirectory ( $ currentWorkingDirectory ) ; if ( $ result -> isSuccessful ( ) ) { $ eventDispatcher -> dispatch ( AccompliEvents :: LOG , new LogEvent ( LogLevel :: NOTICE , 'Executed command "{command}".' , $ eventName , $ this , array ( 'command' => $ this -> command , 'event.task.action' => TaskInterface :: ACTION_COMPLETED , 'output.resetLine' => true ) ) ) ; $ eventDispatcher -> dispatch ( AccompliEvents :: LOG , new LogEvent ( LogLevel :: DEBUG , "{separator} Command output:{separator}\n{command.result}{separator}" , $ eventName , $ this , array ( 'command.result' => $ result -> getOutput ( ) , 'separator' => "\n=================\n" ) ) ) ; } else { throw new TaskCommandExecutionException ( sprintf ( 'Failed executing command "%s".' , $ this -> command ) , $ result , $ this ) ; } } } | Executes the configured command . |
27,714 | public function addValidators ( ) { \ Validator :: extendImplicit ( 'gallery_required' , function ( $ attribute , $ value , $ parameters , $ validator ) { if ( class_exists ( $ parameters [ 0 ] ) ) { $ model = new $ parameters [ 0 ] ; $ model -> fill ( request ( ) -> all ( ) ) ; if ( method_exists ( $ model , 'getRequiredImages' ) ) { return $ model -> hasFieldValue ( $ attribute ) ; } } return false ; } , trans ( 'validation.required' ) ) ; } | Add custom validators . |
27,715 | public static function checkIP ( $ UserIP = false ) { if ( $ UserIP === false ) { if ( \ Environment :: get ( 'ip' ) ) { if ( strpos ( \ Environment :: get ( 'ip' ) , ',' ) !== false ) { $ UserIP = trim ( substr ( \ Environment :: get ( 'ip' ) , 0 , strpos ( \ Environment :: get ( 'ip' ) , ',' ) ) ) ; } else { $ UserIP = trim ( \ Environment :: get ( 'ip' ) ) ; } } else { return false ; } if ( true === static :: checkPrivateIP ( $ UserIP ) && false === empty ( $ _SERVER [ 'HTTP_X_FORWARDED_FOR' ] ) ) { $ HTTPXFF = $ _SERVER [ 'HTTP_X_FORWARDED_FOR' ] ; $ _SERVER [ 'HTTP_X_FORWARDED_FOR' ] = '' ; $ UserIP = \ Environment :: get ( 'ip' ) ; if ( strpos ( $ UserIP , ',' ) !== false ) { $ UserIP = trim ( substr ( $ UserIP , 0 , strpos ( $ UserIP , ',' ) ) ) ; } $ _SERVER [ 'HTTP_X_FORWARDED_FOR' ] = $ HTTPXFF ; } } switch ( static :: getIpVersion ( $ UserIP ) ) { case "IPv4" : if ( static :: checkBotIPv4 ( $ UserIP , static :: getBotIpv4List ( ) ) === true ) { return true ; } break ; case "IPv6" : if ( static :: checkBotIPv6 ( $ UserIP , static :: getBotIpv6List ( ) ) === true ) { return true ; } break ; default : return false ; break ; } return false ; } | Spider Bot IP Check Detect the IP version and calls the method checkBotIPv4 respectively checkBotIPv6 . |
27,716 | protected static function checkBotIPv4 ( $ UserIP = false , $ Bot_IPv4_List = false ) { if ( false === $ Bot_IPv4_List ) { return false ; } if ( $ UserIP === false ) { if ( \ Environment :: get ( 'remoteAddr' ) ) { if ( strpos ( \ Environment :: get ( 'remoteAddr' ) , ',' ) !== false ) { $ UserIP = trim ( substr ( \ Environment :: get ( 'remoteAddr' ) , 0 , strpos ( \ Environment :: get ( 'remoteAddr' ) , ',' ) ) ) ; } else { $ UserIP = trim ( \ Environment :: get ( 'remoteAddr' ) ) ; } } else { return false ; } } if ( file_exists ( $ Bot_IPv4_List ) ) { $ source = file ( $ Bot_IPv4_List ) ; foreach ( $ source as $ line ) { if ( $ line [ 0 ] === '#' ) { continue ; } $ lineleft = explode ( "#" , $ line ) ; $ network = explode ( "/" , trim ( $ lineleft [ 0 ] ) ) ; if ( ! isset ( $ network [ 1 ] ) ) { $ network [ 1 ] = 32 ; } if ( static :: checkIp4InNetwork ( $ UserIP , $ network [ 0 ] , $ network [ 1 ] ) ) { return true ; } } } if ( isset ( $ GLOBALS [ 'BOTDETECTION' ] [ 'BOT_IP' ] ) ) { foreach ( $ GLOBALS [ 'BOTDETECTION' ] [ 'BOT_IP' ] as $ lineleft ) { $ network = explode ( "/" , trim ( $ lineleft ) ) ; if ( ! isset ( $ network [ 1 ] ) ) { $ network [ 1 ] = 32 ; } if ( static :: checkIp4InNetwork ( $ UserIP , $ network [ 0 ] , $ network [ 1 ] ) ) { return true ; } } } return false ; } | Spider Bot IP Check for IPv4 |
27,717 | protected static function checkBotIPv6 ( $ UserIP = false , $ Bot_IPv6_List = false ) { if ( false === $ Bot_IPv6_List ) { return false ; } if ( $ UserIP === false ) { if ( \ Environment :: get ( 'remoteAddr' ) ) { if ( strpos ( \ Environment :: get ( 'remoteAddr' ) , ',' ) !== false ) { $ UserIP = trim ( substr ( \ Environment :: get ( 'remoteAddr' ) , 0 , strpos ( \ Environment :: get ( 'remoteAddr' ) , ',' ) ) ) ; } else { $ UserIP = trim ( \ Environment :: get ( 'remoteAddr' ) ) ; } } else { return false ; } } if ( file_exists ( $ Bot_IPv6_List ) ) { $ source = file ( $ Bot_IPv6_List ) ; foreach ( $ source as $ line ) { if ( $ line [ 0 ] === '#' ) { continue ; } $ lineleft = explode ( "#" , $ line ) ; $ network = explode ( "/" , trim ( $ lineleft [ 0 ] ) ) ; if ( ! isset ( $ network [ 1 ] ) ) { $ network [ 1 ] = 128 ; } if ( static :: checkIp6InNetwork ( $ UserIP , $ network [ 0 ] , $ network [ 1 ] ) ) { return true ; } } } if ( isset ( $ GLOBALS [ 'BOTDETECTION' ] [ 'BOT_IPV6' ] ) ) { foreach ( $ GLOBALS [ 'BOTDETECTION' ] [ 'BOT_IPV6' ] as $ lineleft ) { $ network = explode ( "/" , trim ( $ lineleft ) ) ; if ( ! isset ( $ network [ 1 ] ) ) { $ network [ 1 ] = 128 ; } if ( static :: checkIp6InNetwork ( $ UserIP , $ network [ 0 ] , $ network [ 1 ] ) ) { return true ; } } } return false ; } | Spider Bot IP Check for IPv6 |
27,718 | protected static function getIpVersion ( $ ip ) { if ( ip2long ( $ ip ) !== false ) { return "IPv4" ; } if ( substr_count ( $ ip , ":" ) < 2 ) return false ; if ( substr_count ( $ ip , "::" ) > 1 ) return false ; $ groups = explode ( ':' , $ ip ) ; $ num_groups = count ( $ groups ) ; if ( ( $ num_groups > 8 ) || ( $ num_groups < 3 ) ) return false ; $ empty_groups = 0 ; foreach ( $ groups as $ group ) { $ group = trim ( $ group ) ; if ( ! empty ( $ group ) && ! ( is_numeric ( $ group ) && ( $ group == 0 ) ) ) { if ( ! preg_match ( '#([a-fA-F0-9]{0,4})#' , $ group ) ) return false ; } else { ++ $ empty_groups ; } } if ( $ empty_groups < $ num_groups ) { return "IPv6" ; } return false ; } | Helperfunction IP = IPv4 or IPv6 ? |
27,719 | public function viewInfoAction ( AccountInterface $ account ) { $ table = $ this -> createAdminTable ( 'ucms_user_profile' , [ 'user' => $ account ] ) ; $ table -> addHeader ( $ this -> t ( "Details" ) ) ; $ table -> addRow ( $ this -> t ( "Created at" ) , format_date ( $ account -> created ) ) ; $ latestConnection = $ account -> getLastAccessedTime ( ) ; if ( $ latestConnection ) { $ latestConnection = format_date ( $ latestConnection ) ; } else { $ latestConnection = $ this -> t ( "Never" ) ; } $ table -> addRow ( $ this -> t ( "Last connection at" ) , $ latestConnection ) ; $ access = $ this -> getSiteManager ( ) -> getAccess ( ) ; $ roles = array_map ( function ( $ roleId ) use ( $ access ) { return check_plain ( $ access -> getRelativeRoleName ( $ roleId ) ) ; } , $ account -> getRoles ( true ) ) ; $ table -> addRow ( $ this -> t ( "Roles" ) , implode ( '<br/>' , $ roles ) ) ; return $ table -> render ( ) ; } | User details display |
27,720 | public static function hashTransaction ( $ transaction ) { $ salt = 'SALT' ; if ( $ salt != null ) { $ s = $ salt . microtime ( ) . $ transaction -> date . $ transaction -> description . $ transaction -> value ; $ hash = hash ( 'sha512' , $ s , false ) ; } else { throw new Exception ( "TransactionPersistance.hash_salt setting empty" ) ; } return $ hash ; } | Generate transaction hash |
27,721 | public static function deleteTransaction ( $ hash ) { $ transaction = Transaction :: find ( ) -> withTransactionPartAndHash ( $ hash ) -> one ( ) ; if ( $ transaction === null ) { throw new Exception ( "Transaction with hash " . $ hash . " not found." ) ; } $ dbTransaction = \ Yii :: $ app -> db -> beginTransaction ( ) ; try { foreach ( $ transaction -> transactionParts as $ tp ) { TransactionPersistance :: setAccountBalance ( $ tp -> account_id , $ tp -> accountside_id , $ tp -> value , true ) ; } $ id = $ transaction -> transaction_id ; TransactionPart :: deleteAll ( [ 'transaction_id' => $ transaction -> transaction_id ] ) ; Transaction :: deleteAll ( [ 'transaction_id' => $ transaction -> transaction_id ] ) ; $ dbTransaction -> commit ( ) ; return $ id ; } catch ( Exception $ e ) { $ dbTransaction -> rollBack ( ) ; throw $ e ; } } | Delete a Transaction |
27,722 | private static function persistTransactionPart ( $ transactionPart , $ transaction_id ) { $ transactionPart -> transaction_id = $ transaction_id ; TransactionPersistance :: setAccountBalance ( $ transactionPart -> account_id , $ transactionPart -> accountSide , $ transactionPart -> value ) ; if ( ! $ transactionPart -> save ( false ) ) { throw new Exception ( "TransactionPart could not be saved. Data: " . print_r ( $ transactionPart -> attributes , true ) ) ; } } | Save a transaction part |
27,723 | public function create_credential ( $ recipient_name , $ recipient_email , $ course_id , $ issued_on = null , $ expired_on = null , $ custom_attributes = null ) { $ data = array ( "credential" => array ( "group_id" => $ course_id , "recipient" => array ( "name" => $ recipient_name , "email" => $ recipient_email ) , "issued_on" => $ issued_on , "expired_on" => $ expired_on , "custom_attributes" => $ custom_attributes ) ) ; $ client = new \ GuzzleHttp \ Client ( ) ; $ params = array ( 'Authorization' => 'Token token="' . $ this -> getAPIKey ( ) . '"' ) ; $ response = $ client -> post ( $ this -> api_endpoint . 'credentials' , array ( 'headers' => $ params , 'json' => $ data ) ) ; $ result = json_decode ( $ response -> getBody ( ) ) ; return $ result ; } | Creates a Credential given an existing Group |
27,724 | public function create_credential_legacy ( $ recipient_name , $ recipient_email , $ achievement_name , $ issued_on = null , $ expired_on = null , $ course_name = null , $ course_description = null , $ course_link = null , $ custom_attributes = null ) { $ data = array ( "credential" => array ( "group_name" => $ achievement_name , "recipient" => array ( "name" => $ recipient_name , "email" => $ recipient_email ) , "issued_on" => $ issued_on , "expired_on" => $ expired_on , "custom_attributes" => $ custom_attributes , "name" => $ course_name , "description" => $ course_description , "course_link" => $ course_link ) ) ; $ client = new \ GuzzleHttp \ Client ( ) ; $ params = array ( 'Authorization' => 'Token token="' . $ this -> getAPIKey ( ) . '"' ) ; $ response = $ client -> post ( $ this -> api_endpoint . 'credentials' , array ( 'headers' => $ params , 'json' => $ data ) ) ; $ result = json_decode ( $ response -> getBody ( ) ) ; return $ result ; } | Creates a Credential given an existing Group . This legacy method uses achievement names rather than group IDs . |
27,725 | public function update_credential ( $ id , $ recipient_name = null , $ recipient_email = null , $ course_id = null , $ issued_on = null , $ expired_on = null , $ custom_attributes = null ) { $ data = array ( "credential" => array ( "group_id" => $ course_id , "recipient" => array ( "name" => $ recipient_name , "email" => $ recipient_email ) , "issued_on" => $ issued_on , "expired_on" => $ expired_on , "custom_attributes" => $ custom_attributes ) ) ; $ data = $ this -> strip_empty_keys ( $ data ) ; $ client = new \ GuzzleHttp \ Client ( ) ; $ params = array ( 'Authorization' => 'Token token="' . $ this -> getAPIKey ( ) . '"' ) ; $ response = $ client -> put ( $ this -> api_endpoint . 'credentials/' . $ id , array ( 'headers' => $ params , 'json' => $ data ) ) ; $ result = json_decode ( $ response -> getBody ( ) ) ; return $ result ; } | Updates a Credential |
27,726 | public function get_group ( $ id ) { $ client = new \ GuzzleHttp \ Client ( ) ; $ response = $ client -> get ( $ this -> api_endpoint . 'issuer/groups/' . $ id , array ( 'headers' => array ( 'Authorization' => 'Token token="' . $ this -> getAPIKey ( ) . '"' ) ) ) ; $ result = json_decode ( $ response -> getBody ( ) ) ; return $ result ; } | Get a Group |
27,727 | public function get_groups ( $ page_size = nil , $ page = 1 ) { $ client = new \ GuzzleHttp \ Client ( ) ; $ response = $ client -> get ( $ this -> api_endpoint . 'issuer/all_groups?page_size=' . $ page_size . '&page=' . $ page , array ( 'headers' => array ( 'Authorization' => 'Token token="' . $ this -> getAPIKey ( ) . '"' ) ) ) ; $ result = json_decode ( $ response -> getBody ( ) ) ; return $ result ; } | Get all Groups |
27,728 | public function update_group ( $ id , $ name = null , $ course_name = null , $ course_description = null , $ course_link = null , $ design_id = null ) { $ data = array ( "group" => array ( "name" => $ name , "course_name" => $ course_name , "course_description" => $ course_description , "course_link" => $ course_link , "design_id" => $ design_id ) ) ; $ data = $ this -> strip_empty_keys ( $ data ) ; $ client = new \ GuzzleHttp \ Client ( ) ; $ response = $ client -> put ( $ this -> api_endpoint . 'issuer/groups/' . $ id , array ( 'headers' => array ( 'Authorization' => 'Token token="' . $ this -> getAPIKey ( ) . '"' ) , 'json' => $ data ) ) ; $ result = json_decode ( $ response -> getBody ( ) ) ; return $ result ; } | Update a Group |
27,729 | public function delete_group ( $ id ) { $ client = new \ GuzzleHttp \ Client ( ) ; $ response = $ client -> delete ( $ this -> api_endpoint . 'issuer/groups/' . $ id , array ( 'headers' => array ( 'Authorization' => 'Token token="' . $ this -> getAPIKey ( ) . '"' ) ) ) ; $ result = json_decode ( $ response -> getBody ( ) ) ; return $ result ; } | Delete a Group |
27,730 | public function create_evidence_item ( $ evidence_item , $ credential_id ) { $ client = new \ GuzzleHttp \ Client ( ) ; $ response = $ client -> post ( $ this -> api_endpoint . 'credentials/' . $ credential_id . '/evidence_items' , array ( 'headers' => array ( 'Authorization' => 'Token token="' . $ this -> getAPIKey ( ) . '"' ) , 'json' => $ evidence_item ) ) ; $ result = json_decode ( $ response -> getBody ( ) ) ; return $ result ; } | Creates an evidence item on a given credential . This is a general method used by more specific evidence item creations . |
27,731 | public function create_evidence_item_transcript ( $ transcript , $ credential_id , $ hidden = false ) { $ transcript_items = array ( ) ; foreach ( $ transcript as $ key => $ value ) { array_push ( $ transcript_items , array ( 'category' => $ key , 'percent' => $ value ) ) ; } $ evidence_item = array ( "evidence_item" => array ( "description" => 'Course Transcript' , "category" => "transcript" , "string_object" => json_encode ( $ transcript_items ) , "hidden" => $ hidden ) ) ; $ result = $ this -> create_evidence_item ( $ evidence_item , $ credential_id ) ; return $ result ; } | Creates a Transcript evidence item on a given credential . |
27,732 | public function recipient_sso_link ( $ credential_id = null , $ recipient_id = null , $ recipient_email = null , $ wallet_view = null , $ group_id = null , $ redirect_to = null ) { $ data = array ( "credential_id" => $ credential_id , "recipient_id" => $ recipient_id , "recipient_email" => $ recipient_email , "wallet_view" => $ wallet_view , "group_id" => $ group_id , "redirect_to" => $ redirect_to , ) ; $ data = $ this -> strip_empty_keys ( $ data ) ; $ client = new \ GuzzleHttp \ Client ( ) ; $ response = $ client -> post ( $ this -> api_endpoint . 'sso/generate_link' , array ( 'headers' => array ( 'Authorization' => 'Token token="' . $ this -> getAPIKey ( ) . '"' ) , 'json' => $ data ) ) ; $ result = json_decode ( $ response -> getBody ( ) ) ; return $ result ; } | Generaate a Single Sign On Link for a recipient for a particular credential . |
27,733 | public function send_batch_requests ( $ requests ) { $ client = new \ GuzzleHttp \ Client ( ) ; $ response = $ client -> post ( $ this -> api_endpoint . 'batch' , array ( 'headers' => array ( 'Authorization' => 'Token token="' . $ this -> getAPIKey ( ) . '"' ) , 'json' => array ( "ops" => $ requests , "sequential" => true ) ) ) ; $ result = json_decode ( $ response -> getBody ( ) ) ; return $ result ; } | Send an array of batch requests |
27,734 | private function prepareReplacements ( ) { $ usesString = '' ; foreach ( $ this -> modelReplacements [ ':uses' ] as $ use ) { $ usesString .= 'use ' . $ use . ';' . PHP_EOL ; } $ this -> modelReplacements [ ':uses' ] = $ usesString ; $ this -> modelReplacements [ ':implementations' ] = ! empty ( $ this -> modelReplacements [ ':implementations' ] ) ? 'implements ' . implode ( ', ' , $ this -> modelReplacements [ ':implementations' ] ) : '' ; $ this -> modelReplacements [ ':traits' ] = ! empty ( $ this -> modelReplacements [ ':traits' ] ) ? 'use ' . implode ( ', ' , $ this -> modelReplacements [ ':traits' ] ) . ';' : '' ; } | Prepare Replacements . |
27,735 | public function addAt ( Item $ item , $ position = null ) { if ( 0 === $ position ) { array_unshift ( $ this -> items , $ item ) ; } else if ( null === $ position ) { $ this -> items [ ] = $ item ; } else if ( count ( $ this -> items ) <= $ position ) { $ this -> items [ ] = $ item ; } else { array_splice ( $ this -> items , $ position , 0 , [ $ item ] ) ; } $ this -> isUpdated = true ; return $ this ; } | Add item at the specified position |
27,736 | public function removeAt ( $ position ) { if ( ! is_numeric ( $ position ) || $ position < 0 ) { throw new \ InvalidArgumentException ( ) ; } if ( $ position < count ( $ this -> items ) ) { array_splice ( $ this -> items , $ position , 1 ) ; } $ this -> isUpdated = true ; return $ this ; } | Remove item at specified position |
27,737 | public function getAllNodeIds ( ) { $ ret = [ ] ; foreach ( $ this -> items as $ item ) { $ ret [ ] = $ item -> getNodeId ( ) ; } return $ ret ; } | Get all node identifiers |
27,738 | public function hasAccessToken ( array $ param = [ ] ) { if ( ! $ this -> hasStoredToken ( ) ) { $ this -> logger -> debug ( __CLASS__ , 'has' , sprintf ( 'No access token found in %s' , $ this -> getFilePath ( ) ) ) ; return false ; } if ( $ this -> isNotExpired ( ) ) { $ this -> logger -> debug ( __CLASS__ , 'has' , 'Valid access token found' ) ; return true ; } $ this -> logger -> debug ( __CLASS__ , 'has' , sprintf ( 'No valid access token found in %s' , $ this -> getFilePath ( ) ) ) ; return false ; } | Tell if there is a valid stored Access Token It must answer false if there is one but it is expired |
27,739 | public function storeAccessTokenForSeconds ( $ access_token , $ seconds , array $ param = [ ] ) { $ time = time ( ) + ( int ) $ seconds - 1 ; if ( $ this -> save ( $ access_token , $ time ) === true ) { $ this -> logger -> info ( __CLASS__ , 'store' , sprintf ( 'Access token stored for %ss' , $ seconds ) ) ; } return true ; } | Store an access token for a amount of time |
27,740 | public function getAccessToken ( array $ param = [ ] ) { if ( ! $ this -> hasStoredToken ( ) ) { return null ; } if ( $ this -> isNotExpired ( ) ) { $ this -> logger -> debug ( __CLASS__ , 'get' , 'Access token retrieved from file' ) ; return $ this -> loadAccessToken ( ) ; } return null ; } | Get a stored Access Token It must answer only if the Access Token is valid and not expired |
27,741 | public function cleanAccessTokens ( array $ param = [ ] ) { $ count = 0 ; foreach ( $ this -> getAllStoredAccessTokenFiles ( ) as $ file ) { $ expires_at = $ this -> loadTimestamp ( $ file ) ; if ( is_integer ( $ expires_at ) ) { if ( $ expires_at < time ( ) ) { unlink ( $ file ) ; $ count ++ ; } } } return $ count ; } | Remove all expired Access Tokens |
27,742 | public function deleteAllAccessTokens ( array $ param = [ ] ) { $ count = 0 ; foreach ( $ this -> getAllStoredAccessTokenFiles ( ) as $ file ) { unlink ( $ file ) ; $ count ++ ; } return $ count ; } | Try to delete all stored Access Token |
27,743 | private function load ( ) { if ( ! isset ( $ this -> runtime_file_content ) ) { $ this -> runtime_file_content = json_decode ( @ file_get_contents ( $ this -> getFilePath ( ) ) , true ) ; } return $ this -> runtime_file_content ; } | Load the saved file as array |
27,744 | private function save ( $ access_token , $ time ) { unset ( $ this -> runtime_file_content ) ; $ bytes = @ file_put_contents ( $ this -> getFilePath ( ) , json_encode ( [ 'a' => $ access_token , 'e' => $ time ] ) ) ; if ( $ bytes === false ) { $ this -> logger -> fatal ( __CLASS__ , 'store' , sprintf ( 'Unable to store access token in %s' , $ this -> getFilePath ( ) ) ) ; } $ this -> logger -> debug ( __CLASS__ , 'store' , sprintf ( 'Access token stored in %s' , $ this -> getFilePath ( ) ) ) ; return true ; } | Save AT and timestamp in file |
27,745 | public function download ( $ req , $ res , $ args ) { $ repoList = Container :: get ( 'remote' ) -> getExtensionsInfoList ( ) ; $ category = Utils :: recursiveArraySearch ( $ args [ 'name' ] , $ repoList ) ; $ plugKey = Utils :: recursiveArraySearch ( $ args [ 'name' ] , $ repoList [ $ category ] ) ; $ plug = $ repoList [ $ category ] [ $ plugKey ] ; return View :: setPageInfo ( [ 'admin_console' => true , 'active_page' => 'admin' , 'package' => $ plug [ 'package' ] , 'stability' => $ plug [ 'stability' ] , 'category' => $ category , 'pluginInfo' => base64_encode ( json_encode ( $ plug ) ) , 'title' => [ Utils :: escape ( ForumSettings :: get ( 'o_board_title' ) ) , __ ( 'Admin' ) , __ ( 'Extension' ) ] , ] ) -> display ( '@forum/misc/modal' , false ) ; } | Download a plugin unzip it and rename it |
27,746 | public function info ( $ req , $ res , $ args ) { $ formattedPluginName = str_replace ( ' ' , '' , str_replace ( [ '-' , '_' ] , ' ' , $ args [ 'name' ] ) ) ; $ plugins = $ this -> model -> getList ( true ) ; $ plugKey = Utils :: recursiveArraySearch ( $ formattedPluginName , $ plugins ) ; if ( $ plugKey !== false ) { $ p = explode ( '\\' , $ plugins [ $ plugKey ] [ 'class' ] ) ; $ plug = '\\' . $ p [ 0 ] . '\\Controller\\' . $ p [ 1 ] ; if ( class_exists ( $ plug ) ) { $ plugin = new $ plug ; if ( method_exists ( $ plugin , 'info' ) ) { AdminUtils :: generateAdminMenu ( $ args [ 'name' ] ) ; return $ plugin -> info ( $ req , $ res , $ args ) ; } else { throw new RunBBException ( 'Not found `info` method in class: ' . $ plug , 400 ) ; } } else { throw new RunBBException ( 'Not found extension class: ' . $ plug , 400 ) ; } } else { throw new RunBBException ( 'Not found in extensions: ' . $ formattedPluginName , 400 ) ; } } | Load plugin info if it exists |
27,747 | public function render ( ) { $ this -> output -> writeln ( array ( '' , sprintf ( '<title>%s</>' , $ this -> message ) , sprintf ( '<title>%s</>' , str_repeat ( '=' , Helper :: strlenWithoutDecoration ( $ this -> output -> getFormatter ( ) , $ this -> message ) ) ) , '' , ) ) ; } | Renders the title to output . |
27,748 | function line ( $ line = '' ) { $ value = ( $ line == '' OR ! isset ( $ this -> language [ $ line ] ) ) ? FALSE : $ this -> language [ $ line ] ; if ( $ value === FALSE ) { log_message ( 'error' , 'Could not find the language line "' . $ line . '"' ) ; } return $ value ; } | Fetch a single line of text from the language array |
27,749 | public function ensureConnection ( Host $ host ) { if ( $ host -> hasConnection ( ) ) { $ connection = $ host -> getConnection ( ) ; if ( $ connection -> isConnected ( ) === false && $ connection -> connect ( ) === false ) { throw new ConnectionException ( sprintf ( 'Could not connect to "%s" through "%s".' , $ host -> getHostname ( ) , $ host -> getConnectionType ( ) ) ) ; } return $ connection ; } throw new ConnectionException ( sprintf ( 'No connection adapter of type "%s" found on host.' , $ host -> getConnectionType ( ) ) ) ; } | Ensures a connected connection adapter for a host . Returns the connection adapter instance . |
27,750 | protected function init ( ) { try { $ lastUpdate = $ this -> initFromFiles ( ) ; } catch ( ShopgateLibraryException $ e ) { return ; } if ( $ this -> disableUpdate || ! $ this -> expired ( $ lastUpdate ) ) { return ; } try { $ this -> update ( ) ; } catch ( Exception $ e ) { $ this -> saveAllKeywordsToFiles ( $ newUpdateTimestamp = ( time ( ) - ( $ this -> cacheTimeout * 3600 ) ) + 300 ) ; } } | Initializes the whitelist and blacklist from the Shopgate Merchant API or cache files . |
27,751 | protected function saveAllKeywordsToFiles ( $ lastUpdate = null ) { if ( $ lastUpdate === null ) { $ lastUpdate = time ( ) ; } $ this -> saveKeywordsToFile ( $ this -> whitelist , $ this -> whitelistCacheFilePath , $ lastUpdate ) ; $ this -> saveKeywordsToFile ( $ this -> blacklist , $ this -> blacklistCacheFilePath , $ lastUpdate ) ; } | Saves the internal black and white lists to files . |
27,752 | public function matchTerm ( $ field = null , $ term , $ boost = null , $ fuzzyness = null ) { $ this -> createTerm ( ) -> setValue ( $ term ) -> setFuzzyness ( $ fuzzyness ) -> setBoost ( $ boost ) -> setField ( $ field ) ; return $ this ; } | Match single term to this query |
27,753 | public function requireDateRange ( $ field = null , $ start = null , $ stop = null , $ inclusive = true ) { $ this -> createDateRange ( ) -> setInclusive ( $ inclusive ) -> setRange ( $ start , $ stop ) -> setField ( $ field ) ; return $ this ; } | Require date range |
27,754 | public function requireTerm ( $ field = null , $ term ) { $ this -> createTerm ( ) -> setValue ( $ term ) -> setExclusion ( self :: OP_REQUIRE ) -> setField ( $ field ) ; return $ this ; } | Require single term to this query |
27,755 | public function prohibitTerm ( $ field = null , $ term ) { $ this -> createTerm ( ) -> setValue ( $ term ) -> setField ( $ field ) -> setExclusion ( self :: OP_PROHIBIT ) ; return $ this ; } | Prohibit single term to this query |
27,756 | public function changes ( ) { if ( ! Config :: inst ( ) -> get ( VersionFeed :: class , 'changes_enabled' ) || ! $ this -> owner -> PublicHistory || $ this -> owner -> Version == '' ) { return $ this -> owner -> httpError ( 404 , 'Page history not viewable' ) ; } $ target = $ this -> owner ; $ key = implode ( '_' , array ( 'changes' , $ target -> ID , $ target -> Version ) ) ; $ entries = $ this -> filterContent ( $ key , function ( ) use ( $ target ) { return $ target -> getDiffList ( null , Config :: inst ( ) -> get ( VersionFeed :: class , 'changes_limit' ) ) ; } ) ; $ title = _t ( 'SilverStripe\\VersionFeed\\VersionFeed.SINGLEPAGEFEEDTITLE' , 'Updates to {title} page' , [ 'title' => $ this -> owner -> Title ] ) ; $ rss = new RSSFeed ( $ entries , $ this -> owner -> request -> getURL ( ) , $ title , '' , 'Title' , '' , null ) ; $ rss -> setTemplate ( 'Page_changes_rss' ) ; return $ rss -> outputToBrowser ( ) ; } | Get page - specific changes in a RSS feed . |
27,757 | public function allchanges ( ) { if ( ! Config :: inst ( ) -> get ( VersionFeed :: class , 'allchanges_enabled' ) || ! SiteConfig :: current_site_config ( ) -> AllChangesEnabled ) { return $ this -> owner -> httpError ( 404 , 'Global history not viewable' ) ; } $ limit = ( int ) Config :: inst ( ) -> get ( VersionFeed :: class , 'allchanges_limit' ) ; $ latestChanges = DB :: query ( ' SELECT * FROM "SiteTree_Versions" WHERE "WasPublished" = \'1\' AND "CanViewType" IN (\'Anyone\', \'Inherit\') AND "ShowInSearch" = 1 AND ("PublicHistory" IS NULL OR "PublicHistory" = \'1\') ORDER BY "LastEdited" DESC LIMIT ' . $ limit ) ; $ lastChange = $ latestChanges -> record ( ) ; $ latestChanges -> rewind ( ) ; if ( $ lastChange ) { $ key = 'allchanges' . preg_replace ( '#[^a-zA-Z0-9_]#' , '' , $ lastChange [ 'LastEdited' ] ) . ( Security :: getCurrentUser ( ) ? Security :: getCurrentUser ( ) -> ID : 'public' ) ; $ changeList = $ this -> filterContent ( $ key , function ( ) use ( $ latestChanges ) { $ changeList = new ArrayList ( ) ; $ canView = array ( ) ; foreach ( $ latestChanges as $ record ) { $ id = $ record [ 'RecordID' ] ; if ( ! isset ( $ canView [ $ id ] ) ) { $ page = DataObject :: get_by_id ( SiteTree :: class , $ id ) ; $ canView [ $ id ] = $ page && $ page -> canView ( Security :: getCurrentUser ( ) ) ; } if ( ! $ canView [ $ id ] ) { continue ; } $ record [ 'ID' ] = $ record [ 'RecordID' ] ; $ version = SiteTree :: create ( $ record ) ; if ( $ diff = $ version -> getDiff ( ) ) { $ changeList -> push ( $ diff ) ; } } return $ changeList ; } ) ; } else { $ changeList = new ArrayList ( ) ; } $ url = $ this -> owner -> getRequest ( ) -> getURL ( ) ; $ rss = new RSSFeed ( $ changeList , $ url , $ this -> linkToAllSitesRSSFeedTitle ( ) , '' , 'Title' , '' , null ) ; $ rss -> setTemplate ( 'Page_allchanges_rss' ) ; return $ rss -> outputToBrowser ( ) ; } | Get all changes from the site in a RSS feed . |
27,758 | public function linkToPageRSSFeed ( ) { if ( ! Config :: inst ( ) -> get ( VersionFeed :: class , 'changes_enabled' ) || ! $ this -> owner -> PublicHistory ) { return ; } RSSFeed :: linkToFeed ( $ this -> owner -> Link ( 'changes' ) , _t ( 'SilverStripe\\VersionFeed\\VersionFeed.SINGLEPAGEFEEDTITLE' , 'Updates to {title} page' , [ 'title' => $ this -> owner -> Title ] ) ) ; } | Generates and embeds the RSS header link for the page - specific version rss feed |
27,759 | public function linkToAllSiteRSSFeed ( ) { if ( ! Config :: inst ( ) -> get ( VersionFeed :: class , 'allchanges_enabled' ) || ! SiteConfig :: current_site_config ( ) -> AllChangesEnabled ) { return ; } $ title = Convert :: raw2xml ( $ this -> linkToAllSitesRSSFeedTitle ( ) ) ; $ url = $ this -> owner -> getSiteRSSLink ( ) ; Requirements :: insertHeadTags ( '<link rel="alternate" type="application/rss+xml" title="' . $ title . '" href="' . $ url . '" />' ) ; } | Generates and embeds the RSS header link for the global version rss feed |
27,760 | public static function checkNamespace ( $ value ) { $ value = static :: check ( $ value ) ; if ( 0 === strpos ( $ value , '\\' ) || '\\' === substr ( $ value , - 1 ) ) { throw new \ InvalidArgumentException ( 'Invalid namespace.' ) ; } return $ value ; } | Checks that namespace has no leading or trailing backslashes |
27,761 | protected static function formatContainer ( $ container ) { if ( ! is_array ( $ container ) ) { $ container = [ $ container ] ; } $ instance = array_shift ( $ container ) ; if ( ! $ method = array_shift ( $ container ) ) { if ( $ instance instanceof \ ArrayAccess ) { $ method = 'offsetGet' ; } else { $ method = 'get' ; } } return [ $ instance , $ method ] ; } | Formats a container param as a callable . |
27,762 | protected static function formatNamespaceGroup ( array $ namespace , $ group ) { $ group = static :: checkGroup ( $ group ) ; if ( 'any' === $ group ) { $ namespace = [ '*' ] ; } else { foreach ( $ namespace as & $ value ) { $ value = static :: checkNamespace ( $ value ) ; if ( 'path' === $ group ) { $ value .= '\\*' ; } } } return $ namespace ; } | Formats and returns a namespace param . |
27,763 | public function initialize ( ) { $ this -> initializeStreamWrapper ( ) ; $ this -> initializeContainer ( ) ; $ this -> initializeEventListeners ( ) ; $ this -> dispatch ( AccompliEvents :: INITIALIZE ) ; } | Initializes Accompli . |
27,764 | public function initializeStreamWrapper ( ) { $ stream = new Stream ( 'accompli' , array ( 'recipe' => realpath ( __DIR__ . '/Resources/recipe' ) , ) , false ) ; StreamManager :: create ( ) -> registerStream ( $ stream ) ; } | Initializes the stream wrapper to load recipes within the Accompli package . |
27,765 | public function initializeEventListeners ( ) { $ configuration = $ this -> getConfiguration ( ) ; $ eventDispatcher = $ this -> getContainer ( ) -> get ( 'event_dispatcher' ) ; foreach ( $ configuration -> getEventListeners ( ) as $ eventName => $ listeners ) { foreach ( $ listeners as $ listener ) { list ( $ listenerClassName , $ listenerMethodName ) = explode ( '::' , $ listener ) ; $ listenerInstance = ObjectFactory :: getInstance ( ) -> newInstance ( $ listenerClassName ) ; if ( $ listenerInstance !== null ) { $ eventDispatcher -> addListener ( $ eventName , array ( $ listenerInstance , $ listenerMethodName ) ) ; } } } foreach ( $ configuration -> getEventSubscribers ( ) as $ subscriber ) { $ subscriberInstance = ObjectFactory :: getInstance ( ) -> newInstance ( $ subscriber [ 'class' ] , $ subscriber ) ; if ( $ subscriberInstance instanceof EventSubscriberInterface ) { $ eventDispatcher -> addSubscriber ( $ subscriberInstance ) ; } } } | Initializes the event listeners and subscribers configured in the configuration . |
27,766 | public function install ( $ version , $ stage = null ) { $ deploymentStrategy = $ this -> getContainer ( ) -> get ( 'deployment_strategy' ) ; $ result = $ deploymentStrategy -> install ( $ version , $ stage ) ; $ this -> dispatch ( AccompliEvents :: INSTALL_COMMAND_COMPLETE ) ; return $ result ; } | Triggers the install on the configured deployment strategy . |
27,767 | public function deploy ( $ version , $ stage ) { $ deploymentStrategy = $ this -> getContainer ( ) -> get ( 'deployment_strategy' ) ; $ result = $ deploymentStrategy -> deploy ( $ version , $ stage ) ; $ this -> dispatch ( AccompliEvents :: DEPLOY_COMMAND_COMPLETE ) ; return $ result ; } | Triggers the deployment on the configured deployment strategy . |
27,768 | public function saveFiles ( ) { $ fileFields = $ this -> getFileFields ( ) ; foreach ( $ fileFields as $ fieldName => $ options ) { $ file = Request :: file ( $ fieldName ) ; if ( $ file instanceof UploadedFile && $ file -> isValid ( ) ) { $ filename = $ file -> getClientOriginalName ( ) ; $ fileSavePath = $ this -> getFileSavePath ( $ options [ 'dirName' ] ) ; $ file -> move ( $ fileSavePath , $ filename ) ; $ this -> attributes [ $ fieldName ] = $ fileSavePath . $ filename ; } } } | Save file method . |
27,769 | public function return_value_map ( $ mapOfArgsToValues ) { if ( count ( $ mapOfArgsToValues ) < 1 ) { throw new \ InvalidArgumentException ( 'Must specify at least one return value' ) ; } ; $ limit = count ( $ mapOfArgsToValues ) ; $ this -> frequency = new CountOfTimes ( $ limit , $ this -> methodName ) ; $ mapping = [ ] ; foreach ( $ mapOfArgsToValues as $ paramsAndReturn ) { $ parameterSet = array_slice ( $ paramsAndReturn , 0 , count ( $ paramsAndReturn ) - 1 ) ; $ returnVal = $ paramsAndReturn [ count ( $ paramsAndReturn ) - 1 ] ; $ mapping [ ] = [ $ parameterSet , $ returnVal ] ; } foreach ( $ this -> policies as $ policy ) { foreach ( $ mapping as $ paramsWithReturn ) { $ policy -> check_method_parameters ( $ this -> className , $ this -> methodName , $ paramsWithReturn [ 0 ] , $ this -> isStatic ( ) ) ; $ policy -> check_method_return_value ( $ this -> className , $ this -> methodName , $ paramsWithReturn [ 1 ] , $ this -> isStatic ( ) ) ; } } $ this -> will = function ( $ invocation ) use ( $ mapping ) { $ args = $ invocation -> parameters ; foreach ( $ mapping as $ map ) { list ( $ possibleArgs , $ possibleRet ) = $ map ; if ( $ possibleArgs === $ args ) { return $ possibleRet ; } } $ differ = new \ SebastianBergmann \ Diff \ Differ ( ) ; $ diffSoFar = null ; foreach ( $ mapping as $ map ) { $ possibleArgs = $ map [ 0 ] ; $ nextDiff = $ differ -> diff ( print_r ( $ possibleArgs , true ) , print_r ( $ args , true ) ) ; if ( $ diffSoFar === null || strlen ( $ nextDiff ) < strlen ( $ diffSoFar ) ) { $ diffSoFar = $ nextDiff ; } } throw new \ PHPUnit_Framework_AssertionFailedError ( sprintf ( "Did not expect to be called with args %s, diff with closest match is\n%s" , print_r ( $ args , true ) , $ diffSoFar ) ) ; } ; return $ this ; } | An order - agnostic set of return values given a set of inputs . |
27,770 | public function throw_exception ( $ e = null ) { $ e = $ e ? : new \ Exception ( ) ; foreach ( $ this -> policies as $ policy ) { $ policy -> check_method_throws ( $ this -> className , $ this -> methodName , $ e , true ) ; } $ this -> will ( function ( ) use ( $ e ) { throw $ e ; } ) ; return $ this ; } | Throws an exception on invocation . |
27,771 | public function return_consecutively ( $ array_of_values , $ keep_returning_last_value = false ) { foreach ( $ this -> policies as $ policy ) { foreach ( $ array_of_values as $ value ) { $ policy -> check_method_return_value ( $ this -> className , $ this -> methodName , $ value , true ) ; } } $ this -> will = function ( ) use ( $ array_of_values , $ keep_returning_last_value ) { static $ counter = - 1 ; $ counter ++ ; if ( $ counter == count ( $ array_of_values ) ) { if ( $ keep_returning_last_value ) { return $ array_of_values [ count ( $ array_of_values ) - 1 ] ; } } else { return $ array_of_values [ $ counter ] ; } } ; if ( ! $ keep_returning_last_value ) { $ this -> times ( count ( $ array_of_values ) ) ; } return $ this ; } | Specifies that each subsequent invocation of this method will take the subsequent value from the array as the return value . |
27,772 | public function addRole ( $ rrid , $ label ) { if ( ! is_integer ( $ rrid ) ) { throw new \ InvalidArgumentException ( "The relative role identifier must be an integer." ) ; } if ( isset ( $ this -> roles [ $ rrid ] ) ) { throw new \ LogicException ( sprintf ( "This relative role identifier is already used (%d)." , $ rrid ) ) ; } $ this -> roles [ $ rrid ] = $ label ; return $ this ; } | Add a relative role . |
27,773 | public function getPageHead ( ) { Container :: get ( 'hooks' ) -> fire ( 'model.index.get_page_head_start' ) ; if ( ForumSettings :: get ( 'o_feed_type' ) == '1' ) { $ page_head = [ 'feed' => '<link rel="alternate" type="application/rss+xml" href="' . Router :: pathFor ( 'extern' ) . '?action=feed&type=rss" title="' . __ ( 'RSS active topics feed' ) . '" />' ] ; } elseif ( ForumSettings :: get ( 'o_feed_type' ) == '2' ) { $ page_head = [ 'feed' => '<link rel="alternate" type="application/atom+xml" href="' . Router :: pathFor ( 'extern' ) . '?action=feed&type=atom" title="' . __ ( 'Atom active topics feed' ) . '" />' ] ; } $ page_head = Container :: get ( 'hooks' ) -> fire ( 'model.index.get_page_head' , $ page_head ) ; return $ page_head ; } | Returns page head |
27,774 | protected function getNewPosts ( ) { Container :: get ( 'hooks' ) -> fire ( 'model.index.get_new_posts_start' ) ; $ query [ 'select' ] = [ 'f.id' , 'f.last_post' ] ; $ query [ 'where' ] = [ [ 'fp.read_forum' => 'IS NULL' ] , [ 'fp.read_forum' => '1' ] ] ; $ query = DB :: forTable ( 'forums' ) -> table_alias ( 'f' ) -> select_many ( $ query [ 'select' ] ) -> left_outer_join ( DB :: prefix ( ) . 'forum_perms' , '(`fp`.`forum_id`=`f`.`id` AND `fp`.`group_id`=' . User :: get ( ) -> g_id . ')' , 'fp' ) -> where_raw ( '(fp.read_forum IS NULL OR fp.read_forum = 1)' ) -> where_gt ( 'f.last_post' , User :: get ( ) -> last_visit ) ; $ query = Container :: get ( 'hooks' ) -> fireDB ( 'model.index.query_get_new_posts' , $ query ) ; $ query = $ query -> find_result_set ( ) ; $ forums = $ new_topics = [ ] ; $ tracked_topics = Track :: getTrackedTopics ( ) ; foreach ( $ query as $ cur_forum ) { if ( ! isset ( $ tracked_topics [ 'forums' ] [ $ cur_forum -> id ] ) || $ tracked_topics [ 'forums' ] [ $ cur_forum -> id ] < $ cur_forum -> last_post ) { $ forums [ $ cur_forum -> id ] = $ cur_forum -> last_post ; } } if ( ! empty ( $ forums ) ) { if ( empty ( $ tracked_topics [ 'topics' ] ) ) { $ new_topics = $ forums ; } else { $ query [ 'select' ] = [ 'forum_id' , 'id' , 'last_post' ] ; $ query = DB :: forTable ( 'topics' ) -> select_many ( $ query [ 'select' ] ) -> where_in ( 'forum_id' , array_keys ( $ forums ) ) -> where_gt ( 'last_post' , User :: get ( ) -> last_visit ) -> where_null ( 'moved_to' ) ; $ query = Container :: get ( 'hooks' ) -> fireDB ( 'model.index.get_new_posts_query' , $ query ) ; $ query = $ query -> find_result_set ( ) ; foreach ( $ query as $ cur_topic ) { if ( ! isset ( $ new_topics [ $ cur_topic -> forum_id ] ) && ( ! isset ( $ tracked_topics [ 'forums' ] [ $ cur_topic -> forum_id ] ) || $ tracked_topics [ 'forums' ] [ $ cur_topic -> forum_id ] < $ forums [ $ cur_topic -> forum_id ] ) && ( ! isset ( $ tracked_topics [ 'topics' ] [ $ cur_topic -> id ] ) || $ tracked_topics [ 'topics' ] [ $ cur_topic -> id ] < $ cur_topic -> last_post ) ) { $ new_topics [ $ cur_topic -> forum_id ] = $ forums [ $ cur_topic -> forum_id ] ; } } } } $ new_topics = Container :: get ( 'hooks' ) -> fire ( 'model.index.get_new_posts' , $ new_topics ) ; return $ new_topics ; } | Detects if a new icon has to be displayed |
27,775 | public function collectStats ( ) { Container :: get ( 'hooks' ) -> fire ( 'model.index.collect_stats_start' ) ; if ( ! Container :: get ( 'cache' ) -> isCached ( 'users_info' ) ) { Container :: get ( 'cache' ) -> store ( 'users_info' , Cache :: getUsersInfo ( ) ) ; } $ stats = Container :: get ( 'cache' ) -> retrieve ( 'users_info' ) ; $ query = DB :: forTable ( 'forums' ) -> select_expr ( 'SUM(num_topics)' , 'total_topics' ) -> select_expr ( 'SUM(num_posts)' , 'total_posts' ) ; $ query = Container :: get ( 'hooks' ) -> fireDB ( 'model.index.collect_stats_query' , $ query ) ; $ query = $ query -> find_one ( ) ; $ stats [ 'total_topics' ] = Utils :: numberFormat ( ( int ) $ query [ 'total_topics' ] ) ; $ stats [ 'total_posts' ] = Utils :: numberFormat ( ( int ) $ query [ 'total_posts' ] ) ; if ( User :: get ( ) -> g_view_users == '1' ) { $ stats [ 'newest_user' ] = '<a href="' . Router :: pathFor ( 'userProfile' , [ 'id' => $ stats [ 'last_user' ] [ 'id' ] ] ) . '">' . Utils :: escape ( $ stats [ 'last_user' ] [ 'username' ] ) . '</a>' ; } else { $ stats [ 'newest_user' ] = Utils :: escape ( $ stats [ 'last_user' ] [ 'username' ] ) ; } $ stats [ 'total_users' ] = Utils :: numberFormat ( ( int ) $ stats [ 'total_users' ] ) ; $ stats = Container :: get ( 'hooks' ) -> fire ( 'model.index.collect_stats' , $ stats ) ; return $ stats ; } | Returns the elements needed to display stats |
27,776 | public function fetchUsersOnline ( ) { Container :: get ( 'hooks' ) -> fire ( 'model.index.fetch_users_online_start' ) ; $ online = [ ] ; $ online [ 'num_guests' ] = 0 ; $ query [ 'select' ] = [ 'user_id' , 'ident' ] ; $ query [ 'where' ] = [ 'idle' => '0' ] ; $ query = DB :: forTable ( 'online' ) -> select_many ( $ query [ 'select' ] ) -> where ( $ query [ 'where' ] ) -> orderByExpr ( 'ident' ) ; $ query = Container :: get ( 'hooks' ) -> fireDB ( 'model.index.query_fetch_users_online' , $ query ) ; $ query = $ query -> find_result_set ( ) ; foreach ( $ query as $ user_online ) { if ( $ user_online -> user_id > 1 ) { if ( User :: get ( ) -> g_view_users == '1' ) { $ online [ 'users' ] [ ] = "\n\t\t\t\t" . '<dd><a href="' . Router :: pathFor ( 'userProfile' , [ 'id' => $ user_online -> user_id ] ) . '">' . Utils :: escape ( $ user_online -> ident ) . '</a>' ; } else { $ online [ 'users' ] [ ] = "\n\t\t\t\t" . '<dd>' . Utils :: escape ( $ user_online -> ident ) ; } } else { ++ $ online [ 'num_guests' ] ; } } if ( isset ( $ online [ 'users' ] ) ) { $ online [ 'num_users' ] = count ( $ online [ 'users' ] ) ; } else { $ online [ 'num_users' ] = 0 ; } $ online = Container :: get ( 'hooks' ) -> fire ( 'model.index.fetch_users_online' , $ online ) ; return $ online ; } | Returns the elements needed to display users online |
27,777 | public function add ( $ element ) { if ( $ element instanceof TermQuery ) { parent :: add ( $ element ) ; } else { parent :: add ( ( new TermQuery ( ) ) -> setValue ( $ element ) ) ; } return $ this ; } | Add a term |
27,778 | public function get ( $ key , $ default = null ) { $ key = $ this -> normalizeKey ( $ key ) ; if ( ! $ this -> existsNormalized ( $ key ) ) { return $ default ; } return $ this -> server [ $ key ] ; } | Get value or if missing return a default one |
27,779 | public function getRequired ( $ key ) { $ key = $ this -> normalizeKey ( $ key ) ; if ( ! $ this -> existsNormalized ( $ key ) ) { throw new \ PHPixie \ HTTP \ Exception ( "server variable '$key' is not set" ) ; } return $ this -> server [ $ key ] ; } | Get value or if missing throw an exception |
27,780 | public function getAllNodeIdentifiers ( ) { $ ret = [ ] ; if ( $ this -> isSuccessful ) { foreach ( $ this -> rawResponse [ 'hits' ] [ 'hits' ] as $ document ) { $ ret [ ] = $ document [ '_id' ] ; } } return $ ret ; } | Aggregate all node identifiers and return the array |
27,781 | protected function parseAggregations ( ) { if ( ! $ this -> isSuccessful ( ) ) { return ; } foreach ( $ this -> search -> getAggregations ( ) as $ agg ) { $ agg -> parseResponse ( $ this -> search , $ this , $ this -> rawResponse ) ; } } | Parse aggregation results and update the current facet instances states |
27,782 | public function getAggregationCounts ( ) { $ counts = [ ] ; if ( ! isset ( $ this -> rawResponse [ 'aggregations' ] ) ) { return $ counts ; } foreach ( $ this -> rawResponse [ 'aggregations' ] as $ name => $ aggregation ) { if ( empty ( $ aggregation [ 'buckets' ] ) ) { continue ; } foreach ( $ aggregation [ 'buckets' ] as $ bucket ) { $ counts [ $ name ] [ $ bucket [ 'key' ] ] = $ bucket [ 'doc_count' ] ; } } return $ counts ; } | Return aggregation counts |
27,783 | public function nextSpec ( $ methodName ) { if ( $ this -> pointer >= count ( $ this -> chain ) ) { throw new \ PHPUnit_Framework_AssertionFailedError ( "There are no more method calls expected given assigned ordering" ) ; } if ( $ this -> pointer + 1 < count ( $ this -> chain ) ) { $ next = $ this -> chain [ $ this -> pointer + 1 ] ; if ( $ next [ 0 ] === $ methodName ) { $ this -> pointer ++ ; return $ next [ 1 ] ; } } if ( $ this -> pointer === - 1 ) { throw new \ PHPUnit_Framework_AssertionFailedError ( sprintf ( "Unexpected method invocation %s at call index %s, haven't seen any method calls yet" , $ methodName , $ this -> pointer , true ) ) ; } $ current = $ this -> chain [ $ this -> pointer ] ; if ( $ current [ 0 ] !== $ methodName ) { $ methodsSoFar = [ ] ; for ( $ i = 0 ; $ i <= $ this -> pointer ; $ i ++ ) { $ methodsSoFar [ ] = $ this -> chain [ $ i ] [ 0 ] ; } throw new \ PHPUnit_Framework_AssertionFailedError ( sprintf ( "Unexpected method invocation %s at call index %s, seen method calls so far: %s" , $ methodName , $ this -> pointer , print_r ( implode ( $ methodsSoFar , "\n" ) , true ) ) ) ; } return $ current [ 1 ] ; } | This naive implementation of ordering will ignore frequency requirements . |
27,784 | public static function delete ( $ topic_id ) { $ where_delete_topic = [ [ 'id' => $ topic_id ] , [ 'moved_to' => $ topic_id ] ] ; DB :: forTable ( 'topics' ) -> where_any_is ( $ where_delete_topic ) -> delete_many ( ) ; DB :: forTable ( 'posts' ) -> where ( 'topic_id' , $ topic_id ) -> delete_many ( ) ; DB :: forTable ( 'topic_subscriptions' ) -> where ( 'topic_id' , $ topic_id ) -> delete_many ( ) ; } | Delete a topic and all of its posts |
27,785 | public function redirectToPost ( $ post_id ) { $ post_id = Container :: get ( 'hooks' ) -> fire ( 'model.topic.redirect_to_post' , $ post_id ) ; $ result [ 'select' ] = [ 'topic_id' , 'posted' ] ; $ result = DB :: forTable ( 'posts' ) -> select_many ( $ result [ 'select' ] ) -> where ( 'id' , $ post_id ) ; $ result = Container :: get ( 'hooks' ) -> fireDB ( 'model.topic.redirect_to_post_query' , $ result ) ; $ result = $ result -> find_one ( ) ; if ( ! $ result ) { throw new RunBBException ( __ ( 'Bad request' ) , 404 ) ; } $ post [ 'topic_id' ] = $ result [ 'topic_id' ] ; $ posted = $ result [ 'posted' ] ; $ num_posts = DB :: forTable ( 'posts' ) -> where ( 'topic_id' , $ post [ 'topic_id' ] ) -> where_lt ( 'posted' , $ posted ) -> count ( 'id' ) ; $ num_posts = Container :: get ( 'hooks' ) -> fire ( 'model.topic.redirect_to_post_num' , $ num_posts ) ; $ post [ 'get_p' ] = ceil ( ( $ num_posts + 1 ) / User :: get ( ) -> disp_posts ) ; $ post = Container :: get ( 'hooks' ) -> fire ( 'model.topic.redirect_to_post' , $ post ) ; return $ post ; } | Redirect to a post in particular |
27,786 | public function handleActions ( $ topic_id , $ action ) { $ action = Container :: get ( 'hooks' ) -> fire ( 'model.topic.handle_actions_start' , $ action , $ topic_id ) ; if ( $ action == 'new' ) { if ( ! User :: get ( ) -> is_guest ) { $ tracked_topics = Track :: getTrackedTopics ( ) ; $ last_viewed = isset ( $ tracked_topics [ 'topics' ] [ $ topic_id ] ) ? $ tracked_topics [ 'topics' ] [ $ topic_id ] : User :: get ( ) -> last_visit ; $ first_new_post_id = DB :: forTable ( 'posts' ) -> where ( 'topic_id' , $ topic_id ) -> where_gt ( 'posted' , $ last_viewed ) -> min ( 'id' ) ; $ first_new_post_id = Container :: get ( 'hooks' ) -> fire ( 'model.topic.handle_actions_first_new' , $ first_new_post_id ) ; if ( $ first_new_post_id ) { return Router :: redirect ( Router :: pathFor ( 'viewPost' , [ 'pid' => $ first_new_post_id ] ) . '#p' . $ first_new_post_id ) ; } } $ action = 'last' ; } if ( $ action == 'last' ) { $ last_post_id = DB :: forTable ( 'posts' ) -> where ( 'topic_id' , $ topic_id ) -> max ( 'id' ) ; $ last_post_id = Container :: get ( 'hooks' ) -> fire ( 'model.topic.handle_actions_last_post' , $ last_post_id ) ; if ( $ last_post_id ) { return Router :: redirect ( Router :: pathFor ( 'viewPost' , [ 'pid' => $ last_post_id ] ) . '#p' . $ last_post_id ) ; } } Container :: get ( 'hooks' ) -> fire ( 'model.topic.handle_actions' , $ action , $ topic_id ) ; } | Redirect to new posts or last post |
27,787 | public function getInfoTopic ( $ id ) { $ where = '(fp.read_forum IS NULL OR fp.read_forum=1)' ; if ( ! User :: get ( ) -> is_guest ) { $ select_get_info_topic = [ 't.subject' , 't.closed' , 't.num_replies' , 't.sticky' , 't.first_post_id' , 'forum_id' => 'f.id' , 'f.forum_name' , 'f.moderators' , 'fp.post_replies' , 'is_subscribed' => 's.user_id' ] ; $ cur_topic = DB :: forTable ( 'topics' ) -> table_alias ( 't' ) -> select_many ( $ select_get_info_topic ) -> inner_join ( DB :: prefix ( ) . 'forums' , [ 'f.id' , '=' , 't.forum_id' ] , 'f' ) -> left_outer_join ( DB :: prefix ( ) . 'topic_subscriptions' , '(t.id=s.topic_id AND s.user_id= ' . User :: get ( ) -> id . ')' , 's' ) -> left_outer_join ( DB :: prefix ( ) . 'forum_perms' , '(fp.forum_id=f.id AND fp.group_id=' . User :: get ( ) -> g_id . ')' , 'fp' ) -> where_raw ( $ where ) -> where ( 't.id' , $ id ) -> where_null ( 't.moved_to' ) ; } else { $ select_get_info_topic = [ 't.subject' , 't.closed' , 't.num_replies' , 't.sticky' , 't.first_post_id' , 'forum_id' => 'f.id' , 'f.forum_name' , 'f.moderators' , 'fp.post_replies' ] ; $ cur_topic = DB :: forTable ( 'topics' ) -> table_alias ( 't' ) -> select_many ( $ select_get_info_topic ) -> select_expr ( 0 , 'is_subscribed' ) -> inner_join ( DB :: prefix ( ) . 'forums' , [ 'f.id' , '=' , 't.forum_id' ] , 'f' ) -> left_outer_join ( DB :: prefix ( ) . 'forum_perms' , '(fp.forum_id = f.id AND fp.group_id = ' . User :: get ( ) -> g_id . ')' , 'fp' ) -> where_raw ( $ where ) -> where ( 't.id' , $ id ) -> where_null ( 't.moved_to' ) ; } $ cur_topic = Container :: get ( 'hooks' ) -> fireDB ( 'model.topic.get_info_topic_query' , $ cur_topic ) ; $ cur_topic = $ cur_topic -> find_one ( ) ; if ( ! $ cur_topic ) { throw new RunBBException ( __ ( 'Bad request' ) , 404 ) ; } $ cur_topic = Container :: get ( 'hooks' ) -> fire ( 'model.topic.get_info_topic' , $ cur_topic ) ; return $ cur_topic ; } | Gets some info about the topic |
27,788 | public function getPostLink ( $ topic_id , $ closed , $ post_replies , $ is_admmod ) { $ closed = Container :: get ( 'hooks' ) -> fire ( 'model.topic.getPostLinkStart' , $ closed , $ topic_id , $ post_replies , $ is_admmod ) ; if ( $ closed == '0' ) { if ( ( $ post_replies == '' && User :: get ( ) -> g_post_replies == '1' ) || $ post_replies == '1' || $ is_admmod ) { $ post_link = "\t\t\t" . '<p class="postlink conr"><a class="btn btn-primary btn-sm" href="' . Router :: pathFor ( 'newReply' , [ 'tid' => $ topic_id ] ) . '">' . __ ( 'Post reply' ) . '</a></p>' . "\n" ; } else { $ post_link = '' ; } } else { $ post_link = __ ( 'Topic closed' ) ; if ( $ is_admmod ) { $ post_link .= ' / <a class="btn btn-primary btn-sm" href="' . Router :: pathFor ( 'newReply' , [ 'tid' => $ topic_id ] ) . '">' . __ ( 'Post reply' ) . '</a>' ; } $ post_link = "\t\t\t" . '<p class="postlink conr">' . $ post_link . '</p>' . "\n" ; } $ post_link = Container :: get ( 'hooks' ) -> fire ( 'model.topic.getPostLinkFinish' , $ post_link , $ topic_id , $ closed , $ post_replies , $ is_admmod ) ; return $ post_link ; } | Generates the post link |
27,789 | public function isQuickpost ( $ post_replies , $ closed , $ is_admmod ) { $ quickpost = false ; if ( ForumSettings :: get ( 'o_quickpost' ) == '1' && ( $ post_replies == '1' || ( $ post_replies == '' && User :: get ( ) -> g_post_replies == '1' ) ) && ( $ closed == '0' || $ is_admmod ) ) { $ required_fields = [ 'req_message' => __ ( 'Message' ) ] ; if ( User :: get ( ) -> is_guest ) { $ required_fields [ 'req_username' ] = __ ( 'Guest name' ) ; if ( ForumSettings :: get ( 'p_force_guest_email' ) == '1' ) { $ required_fields [ 'req_email' ] = __ ( 'Email' ) ; } } $ quickpost = true ; } $ quickpost = Container :: get ( 'hooks' ) -> fire ( 'model.topic.isQuickpost' , $ quickpost , $ post_replies , $ closed , $ is_admmod ) ; return $ quickpost ; } | Should we display the quickpost? |
27,790 | public function getTopicInfo ( $ fid , $ tid ) { $ cur_topic [ 'select' ] = [ 'forum_id' => 'f.id' , 'f.forum_name' , 't.subject' , 't.num_replies' , 't.first_post_id' ] ; $ cur_topic [ 'where' ] = [ [ 'fp.read_forum' => 'IS NULL' ] , [ 'fp.read_forum' => '1' ] ] ; $ cur_topic = DB :: forTable ( 'topics' ) -> table_alias ( 't' ) -> select_many ( $ cur_topic [ 'select' ] ) -> inner_join ( DB :: prefix ( ) . 'forums' , [ 'f.id' , '=' , 't.forum_id' ] , 'f' ) -> left_outer_join ( DB :: prefix ( ) . 'forum_perms' , '(fp.forum_id = f.id AND fp.group_id = ' . User :: get ( ) -> g_id . ')' , 'fp' ) -> where_raw ( '(fp.read_forum IS NULL OR fp.read_forum=1)' ) -> where ( 'f.id' , $ fid ) -> where ( 't.id' , $ tid ) -> where_null ( 't.moved_to' ) ; $ cur_topic = Container :: get ( 'hooks' ) -> fireDB ( 'model.topic.get_topic_info' , $ cur_topic ) ; $ cur_topic = $ cur_topic -> find_one ( ) ; if ( ! $ cur_topic ) { throw new RunBBException ( __ ( 'Bad request' ) , 404 ) ; } return $ cur_topic ; } | Fetch some info about the topic |
27,791 | protected function parse ( $ token ) { $ result = new \ stdClass ( ) ; $ result -> violations = [ ] ; $ result -> payload = null ; $ segments = explode ( '.' , $ token ) ; if ( count ( $ segments ) !== 2 ) { $ result -> violations [ ] = new \ InvalidArgumentException ( 'Wrong number of segments' ) ; return $ result ; } list ( $ payloadBase64 , $ signature ) = $ segments ; $ sign = $ this -> sign ; if ( $ signature !== $ sign ( $ payloadBase64 ) ) { $ result -> violations [ ] = new \ InvalidArgumentException ( 'Signature verification failed' ) ; } $ result -> payload = json_decode ( $ this -> base64url -> decode ( $ payloadBase64 ) ) ; if ( ! ( $ result -> payload instanceof \ stdClass ) ) { $ result -> violations [ ] = new \ InvalidArgumentException ( 'Invalid payload encoding' ) ; } return $ result ; } | Parse a CSRF token . |
27,792 | protected function validatePayload ( $ nonce , \ stdClass $ payload , $ now = null , $ leeway = 0 ) { $ now = $ now ? : time ( ) ; $ violations = [ ] ; if ( $ payload -> exp + $ leeway <= $ now ) { $ exp = date ( \ DateTime :: ISO8601 , $ payload -> exp ) ; $ violations [ ] = new \ InvalidArgumentException ( 'Token already expired at ' . $ exp ) ; } if ( $ now + $ leeway < $ payload -> iat ) { $ issuedAt = date ( \ DateTime :: ISO8601 , $ payload -> iat ) ; $ violations [ ] = new \ InvalidArgumentException ( 'Cannot handle token prior to ' . $ issuedAt ) ; } if ( $ payload -> nonce !== $ nonce ) { $ violations [ ] = new \ InvalidArgumentException ( 'Nonce mismatch' ) ; } return $ violations ; } | Validate the payload of a CSRF token . |
27,793 | public function getAuthUser ( ) { $ user = null ; if ( $ this -> api_auth ( ) -> check ( ) ) { $ user = $ this -> api_auth ( ) -> user ( ) ; } else if ( \ Auth :: check ( ) ) { $ user = \ Auth :: user ( ) ; } return $ user ; } | Get current auth user |
27,794 | public function getAuthUserId ( ) { $ user_id = null ; $ user = $ this -> getAuthUser ( ) ; if ( $ user ) { $ user_id = $ user -> user_id ; } return $ user_id ; } | Get current auth user_id |
27,795 | protected function updateIps ( ) { $ ip = smart_get_client_ip ( ) ; if ( ! $ this -> isDirty ( 'updated_ip' ) ) { $ this -> updated_ip = $ ip ; } if ( ! $ this -> exists && ! $ this -> isDirty ( 'created_ip' ) ) { $ this -> created_ip = $ ip ; } } | Update the creation and update ips . |
27,796 | protected function updateUsers ( ) { $ user_id = $ this -> getAuthUserId ( ) ; if ( ! ( $ user_id > 0 ) ) { return ; } if ( ! $ this -> isDirty ( 'updated_by' ) ) { $ this -> updated_by = $ user_id ; } if ( ! $ this -> exists && ! $ this -> isDirty ( 'created_by' ) ) { $ this -> created_by = $ user_id ; } } | Update the creation and update by users . |
27,797 | public function getAuthUserDateTimezone ( ) { $ user = $ this -> getAuthUser ( ) ; if ( $ user && ! empty ( $ user -> timezone ) ) { return $ user -> timezone ; } else { return app_timezone ( ) ; } } | Return a timezone for all Datetime objects |
27,798 | public function parse ( ) { if ( ! empty ( $ this -> transformed_data ) ) { return ; } $ data = $ this -> data ; if ( count ( $ data ) === 1 && ! isset ( $ data [ 'src' ] ) && isset ( $ data [ 0 ] ) ) { $ data = array ( 'src' => $ data [ 0 ] ) ; } $ data = array_merge ( self :: $ defaults , $ data ) ; $ src = $ data [ 'src' ] ; if ( ! empty ( $ src ) ) { if ( substr_count ( $ src , ':' ) ) { unset ( $ data [ 'src' ] ) ; $ substrs = explode ( ':' , $ src ) ; if ( count ( $ substrs ) > 4 ) { throw new \ Exception ( sprintf ( 'Statement css of preset "%s" is malformed (%s)!' , $ this -> preset -> getName ( ) , $ src ) ) ; } foreach ( $ substrs as $ substr ) { switch ( $ substr ) { case 'min' : $ data [ 'minified' ] = true ; break ; case 'first' : $ data [ 'position' ] = Preset :: FILES_STACK_FIRST ; break ; case 'last' : $ data [ 'position' ] = Preset :: FILES_STACK_LAST ; break ; default : if ( is_numeric ( $ substr ) ) { if ( ! ( ( - 1 <= $ substr ) && ( 100 >= $ substr ) ) ) { throw new \ Exception ( sprintf ( 'A position must be in range [-1;100] for css statement of preset "%s" (got %s)!' , $ this -> preset -> getName ( ) , $ substr ) ) ; } $ data [ 'position' ] = $ substr ; } else { if ( empty ( $ data [ 'src' ] ) ) { $ data [ 'src' ] = $ substr ; } else { $ data [ 'media' ] = $ substr ; } } break ; } } } } else { throw new \ Exception ( sprintf ( 'No source file defined for statement css of preset "%s"!' , $ this -> preset -> getName ( ) ) ) ; } $ this -> transformed_data = $ data ; if ( ! \ AssetsManager \ Loader :: isUrl ( $ this -> transformed_data [ 'src' ] ) ) { $ this -> transformed_data [ 'src' ] = $ this -> preset -> findInPackage ( $ this -> transformed_data [ 'src' ] ) ; } } | Parse and transform the preset statement to a ready - to - use information |
27,799 | public function getScore ( ) { $ ipLkup = $ this -> get ( 'ipLkup' , [ 'ip' => $ this -> ip ] ) ; $ score = $ ipLkup [ 'response' ] [ $ this -> ip ] ; if ( $ score ) { return ( string ) $ score ; } else { return 'unknown' ; } } | Get the threat score . |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.