idx int64 0 60.3k | question stringlengths 101 6.21k | target stringlengths 7 803 |
|---|---|---|
25,500 | public function modelJoin ( $ relationships , $ operator = '=' , $ type = 'left' , $ where = false ) { if ( ! is_array ( $ relationships ) ) { $ relationships = [ $ relationships ] ; } if ( empty ( $ this -> query -> columns ) ) { $ this -> query -> selectRaw ( 'DISTINCT ' . $ this -> model -> getTable ( ) . '.*' ) ; } foreach ( $ relationships as $ relation_name => $ load_relationship ) { $ model = Arr :: get ( $ this -> relationships , $ relation_name . '.model' ) ; $ method = Arr :: get ( $ this -> relationships , $ relation_name . '.method' ) ; $ table = Arr :: get ( $ this -> relationships , $ relation_name . '.table' ) ; $ parent_key = Arr :: get ( $ this -> relationships , $ relation_name . '.parent_key' ) ; $ foreign_key = Arr :: get ( $ this -> relationships , $ relation_name . '.foreign_key' ) ; $ this -> query -> join ( $ table , $ parent_key , $ operator , $ foreign_key , $ type , $ where ) ; if ( $ method === 'BelongsToMany' ) { $ related_foreign_key = $ model -> getQualifiedRelatedKeyName ( ) ; $ related_relation = $ model -> getRelated ( ) ; $ related_table = $ related_relation -> getTable ( ) ; $ related_qualified_key_name = $ related_relation -> getQualifiedKeyName ( ) ; $ this -> query -> join ( $ related_table , $ related_qualified_key_name , $ operator , $ related_foreign_key , $ type , $ where ) ; } } $ this -> query -> groupBy ( $ this -> model -> getQualifiedKeyName ( ) ) ; } | This determines the foreign key relations automatically to prevent the need to figure out the columns . |
25,501 | private static function applySearch ( & $ query , $ search ) { foreach ( $ search as $ name => $ filters ) { foreach ( $ filters as $ filter ) { self :: applySearchFilter ( $ query , $ filter ) ; } } } | Apply search items to the query . |
25,502 | private static function applySearchFilter ( & $ query , $ filter ) { $ filter_type = Arr :: get ( $ filter , 'settings.filter' ) ; $ method = Arr :: get ( $ filter , 'method' ) ; $ arguments = Arr :: get ( $ filter , 'arguments' ) ; $ attributes = Arr :: get ( $ filter , 'settings.attributes' ) ; $ positive = Arr :: get ( $ filter , 'positive' ) ; if ( $ filter_type !== 'scope' && is_array ( $ arguments ) ) { array_unshift ( $ arguments , '' ) ; } $ query -> where ( function ( $ query ) use ( $ filter_type , $ attributes , $ method , $ arguments , $ positive ) { $ count = 0 ; foreach ( $ attributes as $ attribute_name ) { if ( $ filter_type !== 'scope' && is_array ( $ arguments ) ) { $ arguments [ 0 ] = $ attribute_name ; } elseif ( ! is_array ( $ arguments ) ) { $ arguments = [ sprintf ( $ arguments , self :: quoteIdentifier ( $ attribute_name ) ) ] ; } if ( $ filter_type === 'scope' ) { $ arguments [ ] = $ positive ; } $ query -> $ method ( ... $ arguments ) ; if ( $ filter_type !== 'scope' && $ count === 0 && $ positive ) { $ method = 'or' . Str :: studly ( $ method ) ; } $ count ++ ; } } ) ; } | Apply the filter item . |
25,503 | public static function getOperator ( $ type , $ operator ) { $ operators = self :: getOperators ( $ type ) ; return Arr :: get ( $ operators , $ operator , [ ] ) ; } | Get an operators details . |
25,504 | public static function getOperators ( $ type ) { if ( ! in_array ( $ type , self :: getTypes ( ) ) ) { return [ ] ; } $ source = snake_case ( $ type ) . '_operators' ; return self :: $ $ source ; } | Get an string|number|date operators as array|string . |
25,505 | private static function getListFromString ( $ value ) { if ( is_string ( $ value_array = $ value ) ) { $ value = str_replace ( [ ',' , ' ' ] , ';' , $ value ) ; $ value_array = explode ( ';' , $ value ) ; } if ( is_array ( $ value_array ) ) { return array_filter ( array_map ( 'trim' , $ value_array ) ) ; } return [ ] ; } | Get array of values from an input string . |
25,506 | public function compileTemplateSource ( ) { if ( ! $ this -> source -> recompiled ) { $ this -> properties [ 'file_dependency' ] = array ( ) ; if ( $ this -> source -> components ) { } else { $ this -> properties [ 'file_dependency' ] [ $ this -> source -> uid ] = array ( $ this -> source -> filepath , $ this -> source -> timestamp , $ this -> source -> type ) ; } } if ( $ this -> smarty -> compile_locking && ! $ this -> source -> recompiled ) { if ( $ saved_timestamp = $ this -> compiled -> timestamp ) { touch ( $ this -> compiled -> filepath ) ; } } try { $ code = $ this -> compiler -> compileTemplate ( $ this ) ; } catch ( Exception $ e ) { if ( $ this -> smarty -> compile_locking && ! $ this -> source -> recompiled && $ saved_timestamp ) { touch ( $ this -> compiled -> filepath , $ saved_timestamp ) ; } throw $ e ; } if ( ! $ this -> source -> recompiled && $ this -> compiler -> write_compiled_code ) { $ _filepath = $ this -> compiled -> filepath ; if ( $ _filepath === false ) { throw new SmartyException ( 'getCompiledFilepath() did not return a destination to save the compiled template to' ) ; } Smarty_Internal_Write_File :: writeFile ( $ _filepath , $ code , $ this -> smarty ) ; $ this -> compiled -> exists = true ; $ this -> compiled -> isCompiled = true ; } unset ( $ this -> compiler ) ; } | Compiles the template If the template is not evaluated the compiled template is saved on disk |
25,507 | public function getSubTemplate ( $ template , $ cache_id , $ compile_id , $ caching , $ cache_lifetime , $ data , $ parent_scope ) { if ( $ this -> smarty -> allow_ambiguous_resources ) { $ _templateId = Smarty_Resource :: getUniqueTemplateName ( $ this , $ template ) . $ cache_id . $ compile_id ; } else { $ _templateId = $ this -> smarty -> joined_template_dir . '#' . $ template . $ cache_id . $ compile_id ; } if ( isset ( $ _templateId [ 150 ] ) ) { $ _templateId = sha1 ( $ _templateId ) ; } if ( isset ( $ this -> smarty -> template_objects [ $ _templateId ] ) ) { $ tpl = clone $ this -> smarty -> template_objects [ $ _templateId ] ; $ tpl -> parent = $ this ; $ tpl -> caching = $ caching ; $ tpl -> cache_lifetime = $ cache_lifetime ; } else { $ tpl = new $ this -> smarty -> template_class ( $ template , $ this -> smarty , $ this , $ cache_id , $ compile_id , $ caching , $ cache_lifetime ) ; } if ( $ parent_scope == Smarty :: SCOPE_LOCAL ) { $ tpl -> tpl_vars = $ this -> tpl_vars ; $ tpl -> tpl_vars [ 'smarty' ] = clone $ this -> tpl_vars [ 'smarty' ] ; } elseif ( $ parent_scope == Smarty :: SCOPE_PARENT ) { $ tpl -> tpl_vars = & $ this -> tpl_vars ; } elseif ( $ parent_scope == Smarty :: SCOPE_GLOBAL ) { $ tpl -> tpl_vars = & Smarty :: $ global_tpl_vars ; } elseif ( ( $ scope_ptr = $ this -> getScopePointer ( $ parent_scope ) ) == null ) { $ tpl -> tpl_vars = & $ this -> tpl_vars ; } else { $ tpl -> tpl_vars = & $ scope_ptr -> tpl_vars ; } $ tpl -> config_vars = $ this -> config_vars ; if ( ! empty ( $ data ) ) { foreach ( $ data as $ _key => $ _val ) { $ tpl -> tpl_vars [ $ _key ] = new Smarty_variable ( $ _val ) ; } } \ Dark \ SmartyView \ SmartyEngine :: integrateViewComposers ( $ tpl , $ template ) ; return $ tpl -> fetch ( null , null , null , null , false , false , true ) ; } | Template code runtime function to get subtemplate content |
25,508 | public function createServerRequestFromArray ( ? array $ server ) { global $ app ; $ method = isset ( $ server [ 'REQUEST_METHOD' ] ) ? $ server [ 'REQUEST_METHOD' ] : 'GET' ; $ headers = \ function_exists ( 'getallheaders' ) ? \ getallheaders ( ) : [ ] ; $ uri = ServerRequest :: getUriFromGlobals ( ) ; $ body = new LazyOpenStream ( 'php://input' , 'r+' ) ; $ protocol = isset ( $ server [ 'SERVER_PROTOCOL' ] ) ? \ str_replace ( 'HTTP/' , '' , $ server [ 'SERVER_PROTOCOL' ] ) : '1.1' ; $ serverRequest = new ServerRequest ( $ method , $ uri , $ headers , $ body , $ protocol , $ server ) ; \ logger ( ) -> debug ( 'Created PSR-7 ServerRequest("' . $ method . '","' . $ uri . '") from array (Guzzle)' ) ; return $ serverRequest -> withCookieParams ( $ _COOKIE ) -> withQueryParams ( $ _GET ) -> withParsedBody ( $ _POST ) -> withUploadedFiles ( ServerRequest :: normalizeFiles ( $ _FILES ) ) ; } | Create a new server request from server variables array |
25,509 | public static function payment ( $ amount , $ localTrxID = null ) { $ impl = new PayPal ( ) ; $ registration = $ impl -> registerTransaction ( $ amount , $ impl -> storeLocalTrx ( $ localTrxID ) ) ; Session :: instance ( ) -> set ( self :: SESSION_TOKEN , $ registration -> id ) ; foreach ( $ registration -> links as $ link ) { if ( $ link -> rel == 'approval_url' ) { HTTP :: redirect ( $ link -> href ) ; exit ; } } throw new PayPal_Exception_InvalidResponse ( 'Missing approval URL' ) ; } | Start pyament processing through Paypal . This method never returns . |
25,510 | public function registerTransaction ( $ amount , $ localTrxID ) { $ token = $ this -> authenticate ( ) ; if ( ! is_string ( $ amount ) ) $ amount = sprintf ( "%0.2f" , $ amount ) ; $ a = ( object ) [ "amount" => ( object ) [ "total" => $ amount , "currency" => $ this -> currency , ] ] ; $ route = Route :: get ( 'paypal_response' ) ; $ base = URL :: base ( true ) ; $ payment_data = ( object ) [ 'intent' => "sale" , 'redirect_urls' => ( object ) [ 'return_url' => $ base . $ route -> uri ( [ 'action' => 'complete' , 'trxid' => $ localTrxID ] ) , 'cancel_url' => $ base . $ route -> uri ( [ 'action' => 'cancel' , 'trxid' => $ localTrxID ] ) , ] , 'payer' => ( object ) [ 'payment_method' => 'paypal' , ] , "transactions" => [ $ a ] , ] ; $ request = $ this -> genRequest ( 'payments/payment' , $ payment_data , $ token ) ; return $ this -> call ( $ request ) ; } | Register the transaction with PayPal |
25,511 | private function storeLocalTrx ( $ localTrxID ) { if ( is_null ( $ localTrxID ) ) return $ localTrxID ; $ trxco = sha1 ( time ( ) . "" . serialize ( $ localTrxID ) ) ; $ this -> cache -> set ( $ trxco , $ localTrxID , self :: MAX_SESSION_LENGTH ) ; return $ trxco ; } | Store the local transaction data in the cache so I don t have to pass it through the client |
25,512 | private function retrieveLocalTrx ( $ localTrxHash ) { if ( is_null ( $ localTrxHash ) ) return $ localTrxHash ; $ trxid = $ this -> cache -> get ( $ localTrxHash , false ) ; if ( $ trxid === false ) throw new Exception ( "Failed to retrieve local data for " . $ localTrxHash ) ; return $ trxid ; } | retrieve the local transaction data from the cache . |
25,513 | private function extractSales ( $ transactions ) { $ out = [ ] ; foreach ( $ transactions as $ trx ) { foreach ( $ trx -> related_resources as $ src ) { if ( isset ( $ src -> sale ) ) { $ out [ ] = $ src -> sale ; } } } return $ out ; } | Parse PayPal transactions list from execution approval call and extract the sale objects which contain the refund URLs |
25,514 | private function getRefundURL ( $ paymentDetails ) { if ( ! is_object ( $ paymentDetails ) ) throw new Exception ( "Invalid payment details in getRefundURL" ) ; if ( ! is_array ( $ paymentDetails -> transactions ) ) throw new Exception ( "Invalid transaction list in getRefundURL" ) ; foreach ( $ paymentDetails -> transactions as $ transact ) { if ( ! is_array ( $ transact -> related_resources ) ) throw new Exception ( "Invalid related resources in getRefundURL" ) ; foreach ( $ transact -> related_resources as $ res ) { if ( ! is_array ( $ res -> sale -> links ) ) throw new Exception ( "Invalid related links in getRefundURL" ) ; foreach ( $ res -> sale -> links as $ link ) { if ( $ link -> rel == 'refund' ) return $ link -> href ; } } } throw new Exception ( "Missing refund URL in getRefundURL" ) ; } | Process a JSON parsed payment object and locate the refund URL for that payment |
25,515 | protected function genRequest ( $ address , $ data = [ ] , $ token = null , $ get = false ) { if ( strstr ( $ address , 'https://' ) ) $ url = $ address ; else $ url = $ this -> endpoint . '/v1/' . $ address ; $ method = ( is_null ( $ data ) || $ get ) ? 'GET' : 'POST' ; self :: debug ( "PayPal Auth: " . $ token -> token_type . ' ' . $ token -> access_token ) ; $ req = ( new Request ( $ url ) ) -> method ( $ method ) -> headers ( 'Accept' , 'application/json' ) -> headers ( 'Accept-Language' , 'en_US' ) -> headers ( 'Authorization' , is_null ( $ token ) ? 'Basic ' . base64_encode ( $ this -> clientID . ":" . $ this -> secret ) : $ token -> token_type . ' ' . $ token -> access_token ) -> headers ( 'Content-Type' , ( is_array ( $ data ) && $ method == 'POST' ) ? 'application/x-www-form-urlencoded' : 'application/json' ) ; if ( is_null ( $ data ) ) { self :: debug ( "Sending message to $url" ) ; return $ req ; } if ( is_array ( $ data ) ) { $ req = $ req -> post ( $ data ) ; self :: debug ( "Sending POST message to $url :" , $ data ) ; return $ req ; } if ( ! is_object ( $ data ) ) throw new PayPal_Exception ( "Invalid data type in PayPal::genRequest" ) ; $ data = json_encode ( $ data ) ; $ req = $ req -> body ( $ data ) ; self :: debug ( "Sending JSON message to $url : $data" ) ; return $ req ; } | Generate a PayPal v1 API request |
25,516 | protected function call ( Request $ request ) { $ response = $ request -> execute ( ) ; if ( ! $ response -> isSuccess ( ) ) { self :: debug ( "Error in PayPal call" , $ response ) ; throw new PayPal_Exception_InvalidResponse ( "Error " . $ response -> status ( ) . " in PayPal call (" . $ response -> body ( ) . ")" ) ; } $ res = json_decode ( $ response -> body ( ) ) ; if ( isset ( $ res -> error ) ) { self :: error ( "Error in PayPal call: " . print_r ( $ res , true ) ) ; throw new PayPal_Exception_InvalidResponse ( 'PayPal: ' . $ res -> error_description . ' [' . $ res -> error . '] while calling ' . $ request -> uri ( ) ) ; } return $ res ; } | Execute a PayPal v1 API request |
25,517 | public function getBase64 ( ) { if ( $ this -> owner -> exists ( ) ) { $ file = $ this -> owner -> getFullPath ( ) ; $ mime = mime_content_type ( $ file ) ; $ fileContent = file_get_contents ( $ file ) ; return "data://$mime;base64," . base64_encode ( $ fileContent ) ; } return null ; } | Get a base 64 encoded variant of the image |
25,518 | public function set_var ( $ key , $ value ) { if ( null === $ this -> wp_query -> get ( $ key , null ) ) { $ this -> vars [ $ key ] = $ value ; $ this -> wp_query -> set ( $ key , $ value ) ; } } | Sets a variable |
25,519 | public function render ( ) { $ html = '' ; ob_start ( ) ; if ( $ this -> _is_root_template ( ) ) { $ this -> _root_get_template_part ( ) ; } else { get_template_part ( $ this -> slug , $ this -> name ) ; } $ html = ob_get_clean ( ) ; echo apply_filters ( 'inc2734_view_controller_template_part_render' , $ html , $ this -> slug , $ this -> name , $ this -> vars ) ; foreach ( $ this -> vars as $ key => $ value ) { unset ( $ value ) ; $ this -> wp_query -> set ( $ key , null ) ; } } | Rendering the template part |
25,520 | protected function _is_root_template ( ) { $ hierarchy = [ ] ; $ root = apply_filters ( 'inc2734_view_controller_template_part_root' , '' , $ this -> slug , $ this -> name , $ this -> vars ) ; if ( $ root ) { $ hierarchy [ ] = $ root ; } $ hierarchy = apply_filters ( 'inc2734_view_controller_template_part_root_hierarchy' , $ hierarchy , $ this -> slug , $ this -> name , $ this -> vars ) ; $ hierarchy = array_unique ( $ hierarchy ) ; foreach ( $ hierarchy as $ root ) { $ is_root = $ this -> _is_root ( $ root ) ; if ( $ is_root ) { return $ is_root ; } } return false ; } | Return true when the template exists in each roots |
25,521 | protected function _is_root ( $ root ) { $ this -> root = $ root ; $ is_root = ( bool ) $ this -> _root_locate_template ( ) ; if ( ! $ is_root ) { $ this -> root = '' ; } return $ is_root ; } | Return true when the template exists in the root |
25,522 | protected function _get_root_template_part_slugs ( ) { if ( ! $ this -> root ) { return [ ] ; } if ( $ this -> name ) { $ templates [ ] = trailingslashit ( $ this -> root ) . $ this -> slug . '-' . $ this -> name . '.php' ; } $ templates [ ] = trailingslashit ( $ this -> root ) . $ this -> slug . '.php' ; return $ templates ; } | Return candidate file names of the root template part |
25,523 | public function getData ( $ page ) { $ this -> loadData ( ) ; $ start = ( $ page - 1 ) * $ this -> pageSize ; return array_slice ( $ this -> filteredData , $ start , $ this -> pageSize ) ; } | Get the data that needs to be added on a certain page . |
25,524 | public function getLastPageNumber ( ) { $ this -> loadData ( ) ; $ count = count ( $ this -> filteredData ) ; return ceil ( $ count / $ this -> pageSize ) ; } | Get the number of the last page . |
25,525 | public function setFiltersAndSort ( $ filters , $ sortField = null , $ sortOrder = "ASC" ) { $ this -> reset ( ) ; $ this -> filters = $ filters ; if ( $ sortField && $ sortOrder ) { $ this -> sort = [ $ sortField , $ sortOrder ] ; } return $ this ; } | Set filters & sorting to apply to the data . |
25,526 | public function setDataByIndex ( $ line , $ data ) { $ this -> data [ $ line ] = $ data ; $ this -> filteredData = null ; } | sets new data to line |
25,527 | public function reset ( ) { $ this -> filteredData = null ; $ this -> filters = [ ] ; $ this -> sort = null ; return $ this ; } | Reset current filters & sorting . |
25,528 | protected function loadData ( ) { if ( is_null ( $ this -> filteredData ) ) { $ this -> filteredData = $ this -> filterHelper -> filterData ( $ this -> data , $ this -> filters , FilterInterface :: FILTER_LOGIC_OR ) ; if ( ! is_null ( $ this -> sort ) ) { $ sort = $ this -> sort ; uasort ( $ this -> filteredData , function ( $ a , $ b ) use ( $ sort ) { if ( is_numeric ( $ a [ $ sort [ 0 ] ] ) ) { $ comp = ( $ a [ $ sort [ 0 ] ] < $ b [ $ sort [ 0 ] ] ) ? - 1 : 1 ; } else { $ comp = ( strcmp ( $ a [ $ sort [ 0 ] ] , $ b [ $ sort [ 0 ] ] ) ) ; } if ( $ sort [ 1 ] == "DESC" ) { return - 1 * $ comp ; } else { return $ comp ; } } ) ; } } } | Filter & sort the data . |
25,529 | public function isProviderCompatible ( $ provider , $ title , $ mode , $ script , Map $ map ) { return ! is_null ( $ this -> getCompatibleProviderId ( $ provider , $ title , $ mode , $ script , $ map ) ) ; } | Check of a provider is compatible |
25,530 | public function registerPlugin ( $ provider , $ pluginId , $ title , $ mode , $ script , Map $ map ) { $ providerId = $ this -> getCompatibleProviderId ( $ provider , $ title , $ mode , $ script , $ map ) ; if ( empty ( $ providerId ) ) { return ; } $ providerService = $ this -> container -> get ( $ providerId ) ; $ pluginService = $ this -> container -> get ( $ pluginId ) ; $ interface = $ this -> providerInterfaces [ $ provider ] ; if ( $ pluginService instanceof $ interface ) { $ this -> deletePlugin ( $ provider , $ pluginId ) ; $ providerService -> registerPlugin ( $ pluginId , $ pluginService ) ; } else { throw new UncompatibleException ( "Plugin $pluginId isn't compatible with $provider. Should be instance of $interface" ) ; } $ this -> logger -> info ( "Plugin '$pluginId' will use data provider '$provider' : '$providerId'" ) ; } | Register a plugin to the DataProviders . |
25,531 | public function deletePlugin ( $ provider , $ pluginId ) { foreach ( $ this -> providersByCompatibility [ $ provider ] as $ titleProviders ) { foreach ( $ titleProviders as $ modeProviders ) { foreach ( $ modeProviders as $ providerId ) { $ providerService = $ this -> container -> get ( $ providerId ) ; $ providerService -> deletePlugin ( $ pluginId ) ; } } } } | Provider to delete a plugin from . |
25,532 | public function dispatch ( $ eventName , $ params ) { if ( isset ( $ this -> enabledProviderListeners [ $ eventName ] ) ) { foreach ( $ this -> enabledProviderListeners [ $ eventName ] as $ callback ) { call_user_func_array ( $ callback , $ params ) ; } } } | Dispatch event to the data providers . |
25,533 | public function makeBoletoAsHTML ( $ codigoBanco , $ boleto ) { $ boleto = new Boleto ( $ boleto ) ; $ factory = new BoletoFactory ( $ this -> config ) ; return $ factory -> makeBoletoAsHTML ( $ codigoBanco , $ boleto -> toArray ( ) ) ; } | Gera um boleto como html |
25,534 | protected function ipv4For ( $ country ) { $ country = self :: toUpper ( $ country ) ; if ( ! isset ( self :: $ ipv4Ranges [ $ country ] ) ) { return '' ; } return static :: randomElement ( self :: $ ipv4Ranges [ $ country ] ) . mt_rand ( 1 , 254 ) ; } | Generate an IPv4 for country |
25,535 | protected function delete ( array $ keys ) { foreach ( $ keys as $ k ) { $ k = sha1 ( $ k ) ; $ this -> memcache -> delete ( $ k ) ; } return true ; } | Remove values from cache |
25,536 | public function initSession ( ) { $ sessionManager = new SessionManager ( ) ; $ sessionManager -> start ( ) ; Container :: setDefaultManager ( $ sessionManager ) ; $ container = new Container ( 'melisinstaller' ) ; } | Create module s session container |
25,537 | public function getEditable ( $ is_create = true ) { return ( $ this -> getParent ( ) -> getEditable ( ) || $ this -> getParent ( ) -> getRequired ( ) ) && ! $ this -> getField ( ) -> getCalculated ( ) && ! $ this -> getField ( ) -> getAutoNumber ( ) && ( $ is_create && $ this -> getField ( ) -> getCreateable ( ) || ! $ is_create && $ this -> getField ( ) -> getUpdateable ( ) ) ; } | Returns true if the field is editable as specified on the page layout . |
25,538 | public function forceContainerSize ( $ x , $ y ) { $ this -> force = true ; $ this -> _X = $ x ; $ this -> _Y = $ y ; } | Forces container size . |
25,539 | public static function nextStep ( $ step ) { $ steps = self :: getSteps ( ) ; $ key = self :: getStepIndex ( $ step ) + 1 ; if ( key_exists ( $ key , $ steps ) ) { return $ steps [ $ key ] ; } else { return null ; } } | Return the next step |
25,540 | public static function get ( CheckoutStepController $ controller ) { $ list = new ArrayList ( ) ; $ steps = self :: getSteps ( ) ; foreach ( $ steps as $ step ) { $ data = new ViewableData ( ) ; $ data -> Link = $ controller -> Link ( $ step ) ; $ data -> Title = _t ( "CheckoutSteps.$step" , ucfirst ( $ step ) ) ; $ data -> InPast = self :: inPast ( $ step , $ controller ) ; $ data -> InFuture = self :: inFuture ( $ step , $ controller ) ; $ data -> Current = self :: current ( $ step , $ controller ) ; $ list -> add ( $ data ) ; } return $ list ; } | Get the formatted steps |
25,541 | private static function inPast ( $ step , CheckoutStepController $ controller ) { $ currentStep = $ controller -> getURLParams ( ) [ 'Action' ] ; return self :: getStepIndex ( $ step ) < self :: getStepIndex ( $ currentStep ) ; } | Check if the step is in the past |
25,542 | private static function inFuture ( $ step , CheckoutStepController $ controller ) { $ currentStep = $ controller -> getURLParams ( ) [ 'Action' ] ; return self :: getStepIndex ( $ step ) > self :: getStepIndex ( $ currentStep ) ; } | Check if the step is in the future |
25,543 | private static function current ( $ step , CheckoutStepController $ controller ) { $ currentStep = $ controller -> getURLParams ( ) [ 'Action' ] ; return self :: getStepIndex ( $ step ) === self :: getStepIndex ( $ currentStep ) ; } | Check at the current step |
25,544 | protected function dispatchMapEvent ( $ eventName , $ params ) { $ map = $ this -> mapStorage -> getMap ( $ params [ 'map' ] [ 'uid' ] ) ; $ this -> dispatch ( $ eventName , [ $ params [ 'count' ] , isset ( $ params [ 'time' ] ) ? $ params [ 'time' ] : time ( ) , isset ( $ params [ 'restarted' ] ) ? $ params [ 'restarted' ] : false , $ map , ] ) ; } | Dispatch map event . |
25,545 | public static function doDelete ( $ values , ConnectionInterface $ con = null ) { if ( null === $ con ) { $ con = Propel :: getServiceContainer ( ) -> getWriteConnection ( MapratingTableMap :: DATABASE_NAME ) ; } if ( $ values instanceof Criteria ) { $ criteria = $ values ; } elseif ( $ values instanceof \ eXpansion \ Bundle \ LocalMapRatings \ Model \ Maprating ) { $ criteria = $ values -> buildPkeyCriteria ( ) ; } else { $ criteria = new Criteria ( MapratingTableMap :: DATABASE_NAME ) ; $ criteria -> add ( MapratingTableMap :: COL_ID , ( array ) $ values , Criteria :: IN ) ; } $ query = MapratingQuery :: create ( ) -> mergeWith ( $ criteria ) ; if ( $ values instanceof Criteria ) { MapratingTableMap :: clearInstancePool ( ) ; } elseif ( ! is_object ( $ values ) ) { foreach ( ( array ) $ values as $ singleval ) { MapratingTableMap :: removeInstanceFromPool ( $ singleval ) ; } } return $ query -> delete ( $ con ) ; } | Performs a DELETE on the database given a Maprating or Criteria object OR a primary key value . |
25,546 | protected function formUserInfo ( ) { $ form = new XmlFormCollection ( $ this -> _context , $ this -> _url , $ this -> _myWords -> Value ( "UPDATETITLE" ) ) ; $ this -> _paragraph -> addXmlnukeObject ( $ form ) ; $ hidden = new XmlInputHidden ( "action" , "update" ) ; $ form -> addXmlnukeObject ( $ hidden ) ; $ labelField = new XmlInputLabelField ( $ this -> _myWords -> Value ( "LABEL_LOGIN" ) , $ this -> _user -> getField ( $ this -> _users -> getUserTable ( ) -> username ) ) ; $ form -> addXmlnukeObject ( $ labelField ) ; $ textBox = new XmlInputTextBox ( $ this -> _myWords -> Value ( "LABEL_NAME" ) , "name" , $ this -> _user -> getField ( $ this -> _users -> getUserTable ( ) -> name ) ) ; $ form -> addXmlnukeObject ( $ textBox ) ; $ textBox = new XmlInputTextBox ( $ this -> _myWords -> Value ( "LABEL_EMAIL" ) , "email" , $ this -> _user -> getField ( $ this -> _users -> getUserTable ( ) -> email ) ) ; $ form -> addXmlnukeObject ( $ textBox ) ; $ button = new XmlInputButtons ( ) ; $ button -> addSubmit ( $ this -> _myWords -> Value ( "TXT_UPDATE" ) , "" ) ; $ form -> addXmlnukeObject ( $ button ) ; } | Show the info of user in the form |
25,547 | protected function formPasswordInfo ( ) { $ form = new XmlFormCollection ( $ this -> _context , $ this -> _url , $ this -> _myWords -> Value ( "CHANGEPASSTITLE" ) ) ; $ this -> _paragraph -> addXmlnukeObject ( $ form ) ; $ hidden = new XmlInputHidden ( "action" , "changepassword" ) ; $ form -> addXmlnukeObject ( $ hidden ) ; $ textbox = new XmlInputTextBox ( $ this -> _myWords -> Value ( "CHANGEPASSOLDPASS" ) , "oldpassword" , "" ) ; $ textbox -> setInputTextBoxType ( InputTextBoxType :: PASSWORD ) ; $ form -> addXmlnukeObject ( $ textbox ) ; $ textbox = new XmlInputTextBox ( $ this -> _myWords -> Value ( "CHANGEPASSNEWPASS" ) , "newpassword" , "" ) ; $ textbox -> setInputTextBoxType ( InputTextBoxType :: PASSWORD ) ; $ form -> addXmlnukeObject ( $ textbox ) ; $ textbox = new XmlInputTextBox ( $ this -> _myWords -> Value ( "CHANGEPASSNEWPASS2" ) , "newpassword2" , "" ) ; $ textbox -> setInputTextBoxType ( InputTextBoxType :: PASSWORD ) ; $ form -> addXmlnukeObject ( $ textbox ) ; $ button = new XmlInputButtons ( ) ; $ button -> addSubmit ( $ this -> _myWords -> Value ( "TXT_CHANGE" ) , "" ) ; $ form -> addXmlnukeObject ( $ button ) ; } | Form Password Info |
25,548 | protected function formRolesInfo ( ) { $ form = new XmlFormCollection ( $ this -> _context , $ this -> _url , $ this -> _myWords -> Value ( "OTHERTITLE" ) ) ; $ this -> _paragraph -> addXmlnukeObject ( $ form ) ; $ easyList = new XmlEasyList ( EasyListType :: SELECTLIST , "" , $ this -> _myWords -> Value ( "OTHERROLE" ) , $ this -> _users -> returnUserProperty ( $ this -> _context -> authenticatedUserId ( ) , UserProperty :: Role ) ) ; $ form -> addXmlnukeObject ( $ easyList ) ; } | Form Roles Info |
25,549 | public function ReservationForm ( ) { $ reservationForm = new ReservationForm ( $ this , 'ReservationForm' , ReservationSession :: get ( ) ) ; $ reservationForm -> setNextStep ( CheckoutSteps :: nextStep ( $ this -> step ) ) ; return $ reservationForm ; } | Get the reservation form |
25,550 | public static function generate ( ) : string { return sprintf ( '%04x%04x-%04x-%04x-%04x-%04x%04x%04x' , \ mt_rand ( 0 , 0xffff ) , \ mt_rand ( 0 , 0xffff ) , \ mt_rand ( 0 , 0xffff ) , \ mt_rand ( 0 , 0x0fff ) | 0x4000 , \ mt_rand ( 0 , 0x3fff ) | 0x8000 , \ mt_rand ( 0 , 0xffff ) , \ mt_rand ( 0 , 0xffff ) , \ mt_rand ( 0 , 0xffff ) ) ; } | Generate v4 UUID |
25,551 | public function setInput ( $ input ) { $ this -> input = $ input ; $ this -> pos = 0 ; $ this -> line = 0 ; $ this -> linePos = 0 ; $ this -> tokenType = TokenType :: BOF ; $ this -> tokenValue = null ; $ this -> length = strlen ( $ this -> input ) ; } | Sets the input string resets the tokenizer ... |
25,552 | private function nextChar ( ) { if ( ! $ this -> isEOF ( ) ) { $ this -> linePos ++ ; return $ this -> input [ $ this -> pos ++ ] ; } return null ; } | Returns current char then moves pointer . |
25,553 | public static function init ( ) { $ instance = self :: getInstance ( ) ; $ instance -> _environments = $ instance -> _loadEnvironment ( $ instance -> _envPath . DS . 'config.php' ) ; if ( ! isset ( $ instance -> _environments [ 'local' ] ) ) { $ instance -> _environments [ 'local' ] = [ ] ; } $ instance -> _current = $ instance -> _getEnvironment ( ) ; if ( $ instance -> _current !== null && isset ( $ instance -> _environments [ $ instance -> _current ] ) ) { $ instance -> _loadEnvironment ( $ instance -> _envPath . DS . 'environment.' . $ instance -> _current . '.php' ) ; } } | Initialize an Environments singleton with all available environments . |
25,554 | protected function _loadEnvironment ( $ envFilePath ) { if ( file_exists ( $ envFilePath ) ) { include $ envFilePath ; if ( isset ( $ configure ) && is_array ( $ configure ) && ! empty ( $ configure ) ) { $ config = Hash :: merge ( Configure :: read ( ) , Hash :: expand ( $ configure ) ) ; Configure :: write ( $ config ) ; } if ( isset ( $ availableEnvironments ) && empty ( $ this -> _environments ) ) { return $ availableEnvironments ; } } return [ ] ; } | Load the specified environment file . |
25,555 | protected function _getEnvironment ( ) { $ environment = self :: $ forceEnvironment ; if ( $ environment !== null ) { if ( ! isset ( $ this -> _environments [ $ environment ] ) ) { throw new Exception ( 'Environment configuration for "' . $ environment . '" could not be found.' ) ; } } if ( $ environment === null && ! empty ( $ _SERVER [ 'HTTP_HOST' ] ) ) { $ host = ( string ) $ _SERVER [ 'HTTP_HOST' ] ; foreach ( $ this -> _environments as $ env => $ envConfig ) { if ( isset ( $ envConfig [ 'domain' ] ) && in_array ( $ host , $ envConfig [ 'domain' ] ) ) { $ environment = $ env ; break ; } } } if ( $ environment === null && ! empty ( $ _SERVER [ 'SERVER_NAME' ] ) ) { $ host = ( string ) $ _SERVER [ 'SERVER_NAME' ] ; foreach ( $ this -> _environments as $ env => $ envConfig ) { if ( isset ( $ envConfig [ 'domain' ] ) && in_array ( $ host , $ envConfig [ 'domain' ] ) ) { $ environment = $ env ; break ; } } } if ( $ environment === null && ( $ serverPath = $ this -> _getRealAppPath ( ) ) ) { foreach ( $ this -> _environments as $ env => $ envConfig ) { if ( isset ( $ envConfig [ 'path' ] ) && in_array ( $ serverPath , $ envConfig [ 'path' ] ) ) { $ environment = $ env ; break ; } } } if ( ! $ environment ) { $ environment = 'local' ; } return $ environment ; } | Detect the environment and return its name . |
25,556 | protected function _getRealAppPath ( ) { $ path = realpath ( APP ) ; if ( substr ( $ path , - 1 , 1 ) !== DS ) { $ path .= DS ; } return $ path ; } | Wrapper to get the absolute environment path . Handles symlinks properly as well . |
25,557 | public function initialize ( array $ config ) { $ config += $ this -> _defaultConfig ; $ this -> config ( 'fields' , $ this -> _resolveFields ( $ config [ 'fields' ] ) ) ; $ this -> config ( 'strategy' , $ this -> _resolveStrategy ( $ config [ 'strategy' ] ) ) ; } | Initialize behavior configuration . |
25,558 | public function beforeSave ( Event $ event , EntityInterface $ entity ) { $ driver = $ this -> _table -> connection ( ) -> driver ( ) ; foreach ( $ this -> config ( 'fields' ) as $ field => $ type ) { if ( ! $ entity -> has ( $ field ) ) { continue ; } $ raw = $ entity -> get ( $ field ) ; $ plain = Type :: build ( $ type ) -> toDatabase ( $ raw , $ driver ) ; $ entity -> set ( $ field , $ this -> encrypt ( $ plain ) ) ; } } | Event listener to encrypt data . |
25,559 | public function findDecrypted ( Query $ query , array $ options ) { $ options += [ 'fields' => [ ] ] ; $ mapper = function ( $ row ) use ( $ options ) { $ driver = $ this -> _table -> connection ( ) -> driver ( ) ; foreach ( $ this -> config ( 'fields' ) as $ field => $ type ) { if ( ( $ options [ 'fields' ] && ! in_array ( $ field , ( array ) $ options [ 'fields' ] ) ) || ! ( $ row instanceof EntityInterface ) || ! $ row -> has ( $ field ) ) { continue ; } $ cipher = $ row -> get ( $ field ) ; $ plain = $ this -> decrypt ( $ cipher ) ; $ row -> set ( $ field , Type :: build ( $ type ) -> toPHP ( $ plain , $ driver ) ) ; } return $ row ; } ; $ formatter = function ( $ results ) use ( $ mapper ) { return $ results -> map ( $ mapper ) ; } ; return $ query -> formatResults ( $ formatter ) ; } | Custom finder to retrieve decrypted values . |
25,560 | public function beforeFind ( Event $ event , Query $ query , ArrayObject $ options , $ primary ) { $ query -> find ( 'decrypted' ) ; } | Decrypts value after every find operation ONLY IF it was added to the implemented events . |
25,561 | public function decrypt ( $ cipher ) { if ( is_resource ( $ cipher ) ) { $ cipher = stream_get_contents ( $ cipher ) ; } return $ this -> config ( 'strategy' ) -> decrypt ( $ cipher ) ; } | Decrypts a value using the defined key . |
25,562 | protected function _resolveStrategy ( $ strategy ) { $ key = Security :: salt ( ) ; if ( ! $ strategy ) { $ class = self :: DEFAULT_STRATEGY ; $ strategy = new $ class ( $ key ) ; } if ( is_string ( $ strategy ) && class_exists ( $ strategy ) ) { $ strategy = new $ strategy ( $ key ) ; } if ( ! ( $ strategy instanceof StrategyInterface ) ) { throw new Exception ( 'Invalid "strategy" configuration.' ) ; } return $ strategy ; } | Resolves configured strategy . |
25,563 | protected function _resolveFields ( $ fields ) { if ( is_string ( $ fields ) ) { $ fields = [ $ fields ] ; } if ( ! is_array ( $ fields ) ) { throw new Exception ( 'Invalid "fields" configuration.' ) ; } $ types = array_keys ( Type :: map ( ) ) ; foreach ( $ fields as $ field => $ type ) { if ( is_numeric ( $ field ) && is_string ( $ type ) ) { unset ( $ fields [ $ field ] ) ; $ field = $ type ; $ type = self :: DEFAULT_TYPE ; $ fields [ $ field ] = $ type ; } if ( ! in_array ( $ type , $ types ) ) { throw new Exception ( sprintf ( 'The field "%s" mapped type "%s" was not found.' , $ field , $ type ) ) ; } } return $ fields ; } | Resolves configured fields . |
25,564 | protected function _get_title ( $ content ) { preg_match ( '/<meta +?property=["\']og:title["\'][^\/>]*? content=["\']([^"\']+?)["\'].*?\/?>/si' , $ content , $ reg ) ; if ( ! empty ( $ reg [ 1 ] ) ) { return $ reg [ 1 ] ; } preg_match ( '/<title>([^"\']+?)<\/title>/si' , $ content , $ reg ) ; if ( ! empty ( $ reg [ 1 ] ) ) { return $ reg [ 1 ] ; } } | Return page title of the page you want to blog card |
25,565 | protected function _get_permalink ( $ content ) { preg_match ( '/<meta +?property=["\']og:url["\'][^\/>]*? content=["\']([^"\']+?)["\'].*?\/?>/si' , $ content , $ reg ) ; if ( ! empty ( $ reg [ 1 ] ) ) { return $ reg [ 1 ] ; } return $ this -> url ; } | Return URL of the page you want to blog card |
25,566 | protected function _get_description ( $ content ) { preg_match ( '/<meta +?property=["\']og:description["\'][^\/>]*? content=["\']([^"\']+?)["\'].*?\/?>/si' , $ content , $ reg ) ; if ( ! empty ( $ reg [ 1 ] ) ) { return $ reg [ 1 ] ; } preg_match ( '/<meta +?name=["\']description["\'][^\/>]*? content=["\']([^"\']+?)["\'].*?\/?>/si' , $ content , $ reg ) ; if ( ! empty ( $ reg [ 1 ] ) ) { return $ reg [ 1 ] ; } } | Return page description of the page you want to blog card |
25,567 | protected function _get_domain ( $ content ) { $ permalink = $ this -> get_permalink ( ) ; if ( ! $ permalink ) { $ permalink = $ this -> _get_permalink ( $ content ) ; } preg_match ( '/https?:\/\/([^\/]+)/' , $ permalink , $ reg ) ; if ( ! empty ( $ reg [ 1 ] ) ) { return $ reg [ 1 ] ; } } | Return domain of the page you want to blog card |
25,568 | protected function _get_favicon ( $ content ) { preg_match ( '/<link +?rel=["\']shortcut icon["\'][^\/>]*? href=["\']([^"\']+?)["\'][^\/>]*?\/?>/si' , $ content , $ reg ) ; if ( empty ( $ reg [ 1 ] ) ) { preg_match ( '/<link +?rel=["\']icon["\'][^\/>]*? href=["\']([^"\']+?)["\'][^\/>]*?\/?>/si' , $ content , $ reg ) ; } if ( empty ( $ reg [ 1 ] ) ) { return ; } $ favicon = $ reg [ 1 ] ; $ favicon = $ this -> _relative_path_to_url ( $ favicon , $ content ) ; if ( is_ssl ( ) ) { $ favicon = preg_replace ( '|^http:|' , 'https:' , $ favicon ) ; } $ requester = new Requester ( $ favicon ) ; $ response = $ requester -> request ( $ favicon ) ; if ( is_wp_error ( $ response ) ) { return ; } $ status_code = $ requester -> get_status_code ( ) ; if ( 200 != $ status_code && 304 != $ status_code ) { return ; } return $ favicon ; } | Return favicon of the page you want to blog card |
25,569 | protected function _get_thumbnail ( $ content ) { preg_match ( '/<meta +?property=["\']og:image["\'][^\/>]*? content=["\']([^"\']+?)["\'].*?\/?>/si' , $ content , $ reg ) ; if ( empty ( $ reg [ 1 ] ) ) { return ; } $ thumbnail = $ reg [ 1 ] ; $ thumbnail = $ this -> _relative_path_to_url ( $ thumbnail , $ content ) ; if ( is_ssl ( ) ) { $ thumbnail = preg_replace ( '|^http:|' , 'https:' , $ thumbnail ) ; } $ requester = new Requester ( $ thumbnail ) ; $ response = $ requester -> request ( $ thumbnail ) ; if ( is_wp_error ( $ response ) ) { return ; } $ status_code = $ requester -> get_status_code ( ) ; if ( 200 != $ status_code && 304 != $ status_code ) { return ; } return $ thumbnail ; } | Return thumbnail of the page you want to blog card |
25,570 | protected function _relative_path_to_url ( $ path , $ content ) { if ( wp_http_validate_url ( $ path ) ) { return $ path ; } $ permalink = $ this -> get_permalink ( ) ; if ( ! $ permalink ) { $ permalink = $ this -> _get_permalink ( $ content ) ; } preg_match ( '/(https?:\/\/[^\/]+)/' , $ permalink , $ reg ) ; if ( empty ( $ reg [ 0 ] ) ) { return false ; } return trailingslashit ( $ reg [ 0 ] ) . $ path ; } | Return url that converted from relative path |
25,571 | public function findWithLetter ( $ letter , $ locale ) { $ query = $ this -> createQueryBuilder ( 'g' ) -> addSelect ( 'translation' ) ; if ( $ letter === '0' ) { $ query -> innerJoin ( 'g.translations' , 'translation' ) -> where ( 'SUBSTRING(translation.name , 1, 1) NOT IN (:list)' ) -> setParameter ( 'list' , range ( 'a' , 'z' ) ) ; } else { $ query -> innerJoin ( 'g.translations' , 'translation' ) -> where ( 'SUBSTRING(translation.name , 1, 1) = :letter' ) -> setParameter ( 'letter' , $ letter ) ; } $ query -> andWhere ( 'translation.locale = :locale' ) -> setParameter ( 'locale' , $ locale ) -> orderBy ( 'translation.name' , 'ASC' ) ; $ this -> onlyActive ( $ query ) ; $ this -> withPlatforms ( $ query ) ; return $ query -> getQuery ( ) ; } | Finds games begining with a letter . |
25,572 | public function findSerieGames ( $ idSerie ) { $ query = $ this -> createQueryBuilder ( 'g' ) ; $ query -> where ( 'g.idSerie = :idSerie' ) -> setParameter ( 'idSerie' , $ idSerie ) ; $ this -> onlyActive ( $ query ) ; $ this -> withPlatforms ( $ query ) ; return $ query -> getQuery ( ) -> getResult ( ) ; } | Finds games in the given series . |
25,573 | public function getProductName ( $ productId ) : ? string { $ product = $ this -> productRepository -> find ( $ productId ) ; if ( ! $ product instanceof ProductInterface ) { return null ; } return $ product -> getName ( ) ; } | Returns the product name . |
25,574 | public function getTaxonPath ( $ taxonId ) : ? array { $ taxon = $ this -> taxonRepository -> find ( $ taxonId ) ; if ( ! $ taxon instanceof TaxonInterface ) { return null ; } $ parts = [ $ taxon -> getName ( ) ] ; while ( $ taxon -> getParent ( ) instanceof TaxonInterface ) { $ taxon = $ taxon -> getParent ( ) ; $ parts [ ] = $ taxon -> getName ( ) ; } return array_reverse ( $ parts ) ; } | Returns the taxon path . |
25,575 | public static function separator ( $ char = '=' , $ repeat = 50 ) { if ( self :: isCli ( ) ) { echo str_repeat ( $ char , $ repeat ) . "\n" ; } else { echo "<div class=\"debug-separator\">" . str_repeat ( $ char , $ repeat ) . "</div>\n" ; } } | Print separator . |
25,576 | public function export ( $ id = null , $ type = 'docx' ) { $ type = mb_strtolower ( $ type ) ; if ( ! empty ( $ type ) && ! $ this -> _controller -> RequestHandler -> prefers ( $ type ) ) { throw new BadRequestException ( __d ( 'view_extension' , 'Invalid request' ) ) ; } if ( ! method_exists ( $ this -> _model , 'generateExportFile' ) || ! method_exists ( $ this -> _model , 'getExportFilename' ) ) { throw new InternalErrorException ( __d ( 'view_extension' , 'Export method not found' ) ) ; } $ tempFile = $ this -> _model -> generateExportFile ( $ id ) ; if ( empty ( $ tempFile ) ) { throw new InternalErrorException ( __d ( 'view_extension' , 'Invalid generated file' ) ) ; } $ exportFile = pathinfo ( $ tempFile , PATHINFO_FILENAME ) ; return $ this -> download ( $ id , $ exportFile ) ; } | Export file from server |
25,577 | public function preview ( $ id = null ) { if ( ! method_exists ( $ this -> _model , 'generateExportFile' ) ) { throw new InternalErrorException ( __d ( 'view_extension' , 'Method "%s" is not exists in model "%s"' , 'generateExportFile()' , $ this -> _model -> name ) ) ; } if ( ! method_exists ( $ this -> _model , 'getExportFilename' ) ) { throw new InternalErrorException ( __d ( 'view_extension' , 'Method "%s" is not exists in model "%s"' , 'getExportFilename()' , $ this -> _model -> name ) ) ; } $ tempFile = $ this -> _model -> generateExportFile ( $ id ) ; if ( empty ( $ tempFile ) ) { throw new InternalErrorException ( __d ( 'view_extension' , 'Invalid generated file' ) ) ; } $ previewFile = $ tempFile ; $ exportPath = $ this -> _getExportDir ( ) ; $ pdfTempFile = $ exportPath . uniqid ( ) . '.pdf' ; if ( $ this -> _convertFileToPdf ( $ tempFile , $ pdfTempFile ) ) { $ previewFile = $ pdfTempFile ; } $ exportFileName = $ this -> _model -> getExportFilename ( $ id , false ) ; $ preview = $ this -> _createImgPreview ( $ previewFile ) ; $ orig = pathinfo ( $ tempFile , PATHINFO_FILENAME ) ; $ pdf = null ; if ( ! empty ( $ pdfTempFile ) ) { $ pdf = pathinfo ( $ pdfTempFile , PATHINFO_FILENAME ) ; } $ download = compact ( 'orig' , 'pdf' ) ; $ result = compact ( 'exportFileName' , 'preview' , 'download' ) ; return $ result ; } | Generate preview images of exported file |
25,578 | protected function _convertFileToPdf ( $ inputFile = null , $ outputFile = null ) { $ cfgUnoconv = $ this -> _getUnoconvConfig ( ) ; if ( $ cfgUnoconv === false ) { throw new InternalErrorException ( __d ( 'view_extension' , 'Unoconv is not configured' ) ) ; } if ( ! file_exists ( $ inputFile ) ) { throw new InternalErrorException ( __d ( 'view_extension' , 'Invalid input file for converting to PDF' ) ) ; } if ( empty ( $ outputFile ) ) { throw new InternalErrorException ( __d ( 'view_extension' , 'Invalid output file for converting to PDF' ) ) ; } if ( mime_content_type ( $ inputFile ) === 'application/pdf' ) { return false ; } extract ( $ cfgUnoconv ) ; if ( $ timeout <= 0 ) { $ timeout = 60 ; } $ unoconvOpt = [ 'timeout' => $ timeout , 'unoconv.binaries' => $ binaries , ] ; $ unoconv = Unoconv \ Unoconv :: create ( $ unoconvOpt ) ; $ unoconv -> transcode ( $ inputFile , 'pdf' , $ outputFile ) ; if ( ! file_exists ( $ outputFile ) ) { throw new InternalErrorException ( __d ( 'view_extension' , 'Error on creation PDF file' ) ) ; } return true ; } | Converting input file into PDf file |
25,579 | protected function _createImgPreview ( $ inputFile = null ) { $ result = [ ] ; if ( empty ( $ inputFile ) || ! file_exists ( $ inputFile ) ) { return $ result ; } $ previewFullPath = $ this -> _getPreviewDir ( ) ; $ wwwRoot = Configure :: read ( 'App.www_root' ) ; if ( empty ( $ wwwRoot ) ) { throw new InternalErrorException ( __d ( 'view_extension' , 'Invalid path to "www_root" directory' ) ) ; } $ wwwRootPos = mb_stripos ( $ previewFullPath , $ wwwRoot ) ; if ( $ wwwRootPos !== 0 ) { throw new InternalErrorException ( __d ( 'view_extension' , 'Path to preview directory is not contain path to "www_root" directory' ) ) ; } $ previewWebRootPath = mb_substr ( $ previewFullPath , mb_strlen ( $ wwwRoot ) - 1 ) ; if ( empty ( $ previewWebRootPath ) ) { throw new InternalErrorException ( __d ( 'view_extension' , 'Invalid path to preview directory' ) ) ; } $ jpgTempFile = uniqid ( ) ; $ im = new Imagick ( ) ; $ im -> setResolution ( 150 , 150 ) ; if ( ! $ im -> readimage ( $ inputFile ) ) { $ im -> clear ( ) ; $ im -> destroy ( ) ; return $ result ; } $ numPages = $ im -> getNumberImages ( ) ; for ( $ page = 0 ; $ page < $ numPages ; $ page ++ ) { $ postfix = '[' . $ page . ']' ; $ previewFile = $ jpgTempFile . $ postfix . '.jpg' ; if ( ! $ im -> readimage ( $ inputFile . $ postfix ) ) { continue ; } $ im -> setImageFormat ( 'jpeg' ) ; $ im -> setImageCompressionQuality ( 90 ) ; if ( $ im -> writeImage ( $ previewFullPath . $ previewFile ) ) { $ result [ ] = $ previewWebRootPath . $ previewFile ; } } $ im -> clear ( ) ; $ im -> destroy ( ) ; if ( ! empty ( $ result ) && ( DIRECTORY_SEPARATOR === '\\' ) ) { foreach ( $ result as & $ resultItem ) { $ resultItem = mb_ereg_replace ( '\\\\' , '/' , $ resultItem ) ; } } return $ result ; } | Creating images of every page for preview file |
25,580 | protected function _setExportDir ( $ path = null ) { $ path = ( string ) $ path ; if ( file_exists ( $ path ) ) { $ this -> _pathExportDir = $ path ; } } | Set path to export directory |
25,581 | protected function _setPreviewDir ( $ path = null ) { $ path = ( string ) $ path ; if ( file_exists ( $ path ) ) { $ this -> _pathPreviewDir = $ path ; } } | Set path to preview directory |
25,582 | protected function _setStorageTimeExport ( $ time = null ) { $ time = ( int ) $ time ; if ( $ time > 0 ) { $ this -> _storageTimeExport = $ time ; } } | Set time for storage old exported files |
25,583 | protected function _setStorageTimePreview ( $ time = null ) { $ time = ( int ) $ time ; if ( $ time > 0 ) { $ this -> _storageTimePreview = $ time ; } } | Set time for storage old preview files |
25,584 | public function download ( $ id = null , $ file = null ) { $ type = $ this -> _controller -> RequestHandler -> prefers ( ) ; $ exportFileName = null ; if ( method_exists ( $ this -> _model , 'getExportFilename' ) ) { $ exportFileName = $ this -> _model -> getExportFilename ( $ id , true ) ; } $ exportPath = $ this -> _getExportDir ( ) ; $ downloadFile = $ exportPath . $ file ; if ( ! empty ( $ type ) ) { $ downloadFile .= '.' . $ type ; } if ( ! file_exists ( $ downloadFile ) ) { throw new InternalErrorException ( __d ( 'view_extension' , 'Invalid file for downloading' ) ) ; } if ( ! empty ( $ type ) && ! empty ( $ exportFileName ) ) { $ this -> _controller -> response -> type ( $ type ) ; $ exportFileName .= '.' . $ type ; } $ responseOpt = [ 'download' => true , ] ; if ( ! empty ( $ exportFileName ) ) { if ( $ this -> _controller -> request -> is ( 'msie' ) ) { $ exportFileName = rawurlencode ( $ exportFileName ) ; } $ responseOpt [ 'name' ] = $ exportFileName ; } $ this -> _controller -> response -> file ( $ downloadFile , $ responseOpt ) ; return $ this -> _controller -> response ; } | Downloading preview file |
25,585 | protected function _clearDir ( $ type = null , $ timeNow = null ) { switch ( mb_strtolower ( $ type ) ) { case 'export' : $ clearPath = $ this -> _getExportDir ( ) ; $ storageTime = $ this -> _getStorageTimeExport ( ) ; break ; case 'preview' : $ clearPath = $ this -> _getPreviewDir ( ) ; $ storageTime = $ this -> _getStorageTimePreview ( ) ; break ; default : return false ; } $ result = true ; $ oFolder = new Folder ( $ clearPath , true ) ; $ exportFiles = $ oFolder -> find ( '.*' , false ) ; if ( empty ( $ exportFiles ) ) { return $ result ; } if ( ! empty ( $ timeNow ) ) { $ timeNow = ( int ) $ timeNow ; } else { $ timeNow = time ( ) ; } $ exportFilesPath = $ oFolder -> pwd ( ) ; foreach ( $ exportFiles as $ exportFile ) { $ oFile = new File ( $ exportFilesPath . DS . $ exportFile ) ; $ lastChangeTime = $ oFile -> lastChange ( ) ; if ( $ lastChangeTime === false ) { continue ; } if ( ( $ timeNow - $ lastChangeTime ) > $ storageTime ) { if ( ! $ oFile -> delete ( ) ) { $ result = false ; } } } return true ; } | Cleanup the export directory from old files |
25,586 | protected function _getUnoconvConfig ( ) { $ cfgUnoconv = $ this -> _modelConfigTheme -> getUnoconvConfig ( ) ; if ( empty ( $ cfgUnoconv ) ) { return false ; } $ timeout = ( int ) Hash :: get ( $ cfgUnoconv , 'timeout' ) ; $ binaries = ( string ) Hash :: get ( $ cfgUnoconv , 'binaries' ) ; $ result = compact ( 'timeout' , 'binaries' ) ; return $ result ; } | Return configuration of Unoconv |
25,587 | public function isUnoconvReady ( ) { $ cfgUnoconv = $ this -> _getUnoconvConfig ( ) ; if ( $ cfgUnoconv === false ) { return false ; } if ( ! file_exists ( $ cfgUnoconv [ 'binaries' ] ) ) { return false ; } return true ; } | Readiness check use the configuration Unoconv |
25,588 | public function fetchTemplate ( Request $ request , $ template ) { if ( ! $ this -> view instanceof Twig ) { throw new Exception ( "Twig provider not registered." ) ; } foreach ( $ this -> settings [ 'view' ] [ 'global' ] as $ key => $ map ) { $ key = is_numeric ( $ key ) ? $ map : $ key ; switch ( $ key ) { case 'request' : $ value = $ request ; break ; default : $ value = isset ( $ this -> container [ $ key ] ) ? $ this -> container [ $ key ] : null ; break ; } $ this -> view -> getEnvironment ( ) -> addGlobal ( $ map , $ value ) ; } $ result = $ this -> view -> fetch ( $ template . $ this -> settings [ 'view' ] [ 'extension' ] , $ this -> data -> all ( ) ) ; return $ result ; } | Fetches template with previous set data . |
25,589 | public function renderTemplate ( Request $ request , Response $ response , $ template , $ status = null ) { $ response -> getBody ( ) -> write ( $ this -> fetchTemplate ( $ request , $ template ) ) ; if ( $ status ) { $ response = $ response -> withStatus ( $ status ) ; } return $ response ; } | Renders template with previous set data . |
25,590 | public static function isAccessibleBy ( $ document , $ user ) { $ result = null ; switch ( Convertor :: baseClassName ( $ user ) ) { case 'User' : $ result = true ; break ; case 'Customer' : $ result = ( self :: getDocumentCompany ( $ document ) == self :: getCustomerCompany ( $ user ) ) ; break ; case 'Anonym' : $ result = false ; break ; } return $ result ; } | Is document accessible by user ? |
25,591 | public static function getDocumentCompany ( $ document ) { return $ document -> getDataValue ( 'firma' ) ? \ FlexiPeeHP \ FlexiBeeRO :: uncode ( $ document -> getDataValue ( 'firma' ) ) : null ; } | Get Company code for document |
25,592 | public static function getCustomerCompany ( $ customer ) { return $ customer -> adresar -> getDataValue ( 'kod' ) ? \ FlexiPeeHP \ FlexiBeeRO :: uncode ( $ customer -> adresar -> getDataValue ( 'kod' ) ) : null ; } | Obtain customer company code |
25,593 | protected function redirect ( string $ ref , array $ params = [ ] , string $ schema = null ) { $ url = $ this -> link ( $ ref , $ params , $ schema ) ; $ response = new Response ( ) ; $ response -> setCode ( Response :: CODE_REDIRECT_SEE_OTHER ) ; $ response -> addHeader ( 'Location' , $ url ) ; return $ response ; } | Creates a redirect response . |
25,594 | public function getDefaultValue ( ) { if ( $ this -> hasOption ( self :: OPTION_DEFAULT_VALUE ) ) { return $ this -> getSanitizedValue ( $ this -> getOption ( self :: OPTION_DEFAULT_VALUE , $ this -> getNullValue ( ) ) ) ; } return $ this -> getNullValue ( ) ; } | Returns the default value of the attribute . |
25,595 | public function getValidator ( ) { if ( ! $ this -> validator ) { $ default_validator_class = Validator :: CLASS ; $ validator_implementor = $ this -> getOption ( self :: OPTION_VALIDATOR , $ default_validator_class ) ; if ( ! class_exists ( $ validator_implementor , true ) ) { throw new InvalidConfigException ( sprintf ( "Unable to resolve validator implementor '%s' given for attribute '%s' on entity type '%s'." , $ validator_implementor , $ this -> getName ( ) , $ this -> getType ( ) -> getName ( ) ) ) ; } $ validator = new $ validator_implementor ( $ this -> getName ( ) , $ this -> buildValidationRules ( ) ) ; if ( ! $ validator instanceof ValidatorInterface ) { throw new InvalidTypeException ( sprintf ( "Invalid validator implementor '%s' given for attribute '%s' on entity type '%s'. " . "Make sure to implement '%s'." , $ validator_implementor , $ this -> getName ( ) , $ this -> getType ( ) ? $ this -> getType ( ) -> getName ( ) : 'undefined' , ValidatorInterface :: CLASS ) ) ; } $ this -> validator = $ validator ; } return $ this -> validator ; } | Returns the ValidatorInterface implementation to use when validating values for this attribute . Override this method if you want inject your own implementation . |
25,596 | public function createValueHolder ( $ apply_default_values = false ) { if ( ! $ this -> value_holder_implementor ) { $ implementor = $ this -> hasOption ( self :: OPTION_VALUE_HOLDER ) ? $ this -> getOption ( self :: OPTION_VALUE_HOLDER ) : $ this -> buildDefaultValueHolderClassName ( ) ; if ( ! class_exists ( $ implementor ) ) { throw new InvalidConfigException ( sprintf ( "Invalid valueholder implementor '%s' configured for attribute '%s' on entity '%s'." , $ implementor , $ this -> getName ( ) , $ this -> getType ( ) ? $ this -> getType ( ) -> getName ( ) : 'undefined' ) ) ; } $ test_value_holder = new $ implementor ( $ this ) ; if ( ! $ test_value_holder instanceof ValueHolderInterface ) { throw new InvalidTypeException ( sprintf ( "Invalid valueholder implementation '%s' given for attribute '%s' on entity type '%s'. " . "Make sure to implement '%s'." , $ implementor , $ this -> getName ( ) , $ this -> getType ( ) ? $ this -> getType ( ) -> getName ( ) : 'undefined' , ValueHolderInterface :: CLASS ) ) ; } $ this -> value_holder_implementor = $ implementor ; } $ value_holder = new $ this -> value_holder_implementor ( $ this ) ; if ( $ apply_default_values === true ) { $ value_holder -> setValue ( $ this -> getDefaultValue ( ) ) ; } elseif ( $ apply_default_values === false ) { $ value_holder -> setValue ( $ this -> getNullValue ( ) ) ; } else { throw new InvalidTypeException ( sprintf ( "Only boolean arguments are acceptable for attribute '%s' on entity type '%s'. " , $ this -> getName ( ) , $ this -> getType ( ) ? $ this -> getType ( ) -> getName ( ) : 'undefined' ) ) ; } return $ value_holder ; } | Creates a ValueHolderInterface that is specific to the current attribute instance . |
25,597 | public function init ( OutputInterface $ consoleOutput , $ dispatcher ) { $ this -> consoleOutput = $ consoleOutput ; $ this -> dispatcher = $ dispatcher ; $ this -> sfStyleOutput = new SymfonyStyle ( new StringInput ( '' ) , $ consoleOutput ) ; } | Initialize service with the console output . |
25,598 | public function getSfStyleOutput ( ) : SymfonyStyle { if ( is_null ( $ this -> sfStyleOutput ) ) { $ this -> sfStyleOutput = new SymfonyStyle ( new StringInput ( '' ) , new NullOutput ( ) ) ; } return $ this -> sfStyleOutput ; } | Get symfony style output . |
25,599 | function getRequestToken ( $ args = array ( ) ) { $ r = $ this -> oAuthRequest ( $ this -> requestTokenURL ( ) , $ args ) ; $ token = $ this -> oAuthParseResponse ( $ r ) ; $ this -> token = new OAuthConsumer ( $ token [ 'oauth_token' ] , $ token [ 'oauth_token_secret' ] ) ; return $ token ; } | Get a request_token from OAuth server |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.