idx
int64 0
60.3k
| question
stringlengths 64
4.24k
| target
stringlengths 5
618
|
|---|---|---|
11,500
|
public static function recursiveCopy ( $ src , $ dst ) { if ( is_dir ( $ src ) ) { if ( ! is_dir ( $ dst ) && ! mkdir ( $ dst ) ) { throw new IOException ( "Cannot mkdir '$dst'" , 0 , null , $ path ) ; } $ files = scandir ( $ src ) ; foreach ( $ files as $ file ) { if ( $ file != "." && $ file != ".." ) { self :: recursiveCopy ( "$src/$file" , "$dst/$file" ) ; } } } elseif ( file_exists ( $ src ) ) { if ( ! copy ( $ src , $ dst ) ) { throw new IOException ( "Cannot copy '$src' to '$dst'" , 0 , null , $ src ) ; } } }
|
cp - r
|
11,501
|
public function loadClassMetadata ( LoadClassMetadataEventArgs $ eventArgs ) { $ metadata = $ eventArgs -> getClassMetadata ( ) ; $ reflectionClass = $ metadata -> getReflectionClass ( ) ; if ( ! $ reflectionClass || ! $ this -> hasTrait ( $ reflectionClass , 'Blast\BaseEntitiesBundle\Entity\Traits\Timestampable' ) ) { return ; } foreach ( $ metadata -> parentClasses as $ parent ) { if ( $ this -> classAnalyzer -> hasTrait ( $ parent , 'Blast\BaseEntitiesBundle\Entity\Traits\Timestampable' ) ) { return ; } } $ this -> logger -> debug ( '[TimestampableListener] Entering TimestampableListener for « loadClassMetadata » event' ) ; $ metadata -> mapField ( [ 'fieldName' => 'createdAt' , 'type' => 'datetime' , ] ) ; $ metadata -> mapField ( [ 'fieldName' => 'updatedAt' , 'type' => 'datetime' , ] ) ; $ this -> logger -> debug ( '[TimestampableListener] Added Timestampable mapping metadata to Entity' , [ 'class' => $ metadata -> getName ( ) ] ) ; }
|
define Timestampable mapping at runtime .
|
11,502
|
public function disconnect ( ) { if ( $ this -> state != self :: STATE_NOT_CONNECTED ) { $ this -> connection -> sendData ( 'QUIT' ) ; $ this -> connection -> getLine ( ) ; $ this -> state = self :: STATE_UPDATE ; $ this -> connection -> close ( ) ; $ this -> connection = null ; $ this -> state = self :: STATE_NOT_CONNECTED ; } }
|
Disconnects the transport from the POP3 server .
|
11,503
|
public function listMessages ( ) { if ( $ this -> state != self :: STATE_TRANSACTION ) { throw new ezcMailTransportException ( "Can't call listMessages() on the POP3 transport when not successfully logged in." ) ; } $ this -> connection -> sendData ( "LIST" ) ; $ response = $ this -> connection -> getLine ( ) ; if ( ! $ this -> isPositiveResponse ( $ response ) ) { throw new ezcMailTransportException ( "The POP3 server sent a negative response to the LIST command: {$response}." ) ; } $ messages = array ( ) ; while ( ( $ response = $ this -> connection -> getLine ( true ) ) !== "." ) { list ( $ num , $ size ) = explode ( ' ' , $ response ) ; $ messages [ $ num ] = $ size ; } return $ messages ; }
|
Returns an array of the message numbers on the server and the size of the messages in bytes .
|
11,504
|
public function listUniqueIdentifiers ( $ msgNum = null ) { if ( $ this -> state != self :: STATE_TRANSACTION ) { throw new ezcMailTransportException ( "Can't call ListUniqueIdentifiers() on the POP3 transport when not successfully logged in." ) ; } $ result = array ( ) ; if ( $ msgNum !== null ) { $ this -> connection -> sendData ( "UIDL {$msgNum}" ) ; $ response = $ this -> connection -> getLine ( true ) ; if ( $ this -> isPositiveResponse ( $ response ) ) { list ( $ dummy , $ num , $ id ) = explode ( ' ' , $ response ) ; $ result [ ( int ) $ num ] = $ id ; } else { throw new ezcMailTransportException ( "The POP3 server sent a negative response to the UIDL command: {$response}." ) ; } } else { $ this -> connection -> sendData ( "UIDL" ) ; $ response = $ this -> connection -> getLine ( ) ; if ( $ this -> isPositiveResponse ( $ response ) ) { while ( ( $ response = $ this -> connection -> getLine ( true ) ) !== "." ) { list ( $ num , $ id ) = explode ( ' ' , $ response ) ; $ result [ ( int ) $ num ] = $ id ; } } else { throw new ezcMailTransportException ( "The POP3 server sent a negative response to the UIDL command: {$response}." ) ; } } return $ result ; }
|
Returns the unique identifiers for messages on the POP3 server .
|
11,505
|
public function status ( & $ numMessages , & $ sizeMessages ) { if ( $ this -> state != self :: STATE_TRANSACTION ) { throw new ezcMailTransportException ( "Can't call status() on the POP3 transport when not successfully logged in." ) ; } $ this -> connection -> sendData ( "STAT" ) ; $ response = $ this -> connection -> getLine ( ) ; if ( $ this -> isPositiveResponse ( $ response ) ) { list ( $ dummy , $ numMessages , $ sizeMessages ) = explode ( ' ' , $ response ) ; $ numMessages = ( int ) $ numMessages ; $ sizeMessages = ( int ) $ sizeMessages ; } else { throw new ezcMailTransportException ( "The POP3 server did not respond with a status message: {$response}." ) ; } }
|
Returns information about the messages on the server .
|
11,506
|
public function fetchAll ( $ deleteFromServer = false ) { $ messages = $ this -> listMessages ( ) ; return new ezcMailPop3Set ( $ this -> connection , array_keys ( $ messages ) , $ deleteFromServer ) ; }
|
Returns an ezcMailPop3Set with all the messages on the server .
|
11,507
|
public function getLine ( $ trim = false ) { $ data = '' ; $ line = '' ; if ( is_resource ( $ this -> connection ) ) { while ( strpos ( $ data , self :: CRLF ) === false ) { $ line = fgets ( $ this -> connection , 512 ) ; if ( $ line === false ) { $ this -> connection = null ; throw new ezcMailTransportException ( 'Could not read from the stream. It was probably terminated by the host.' ) ; } $ data .= $ line ; } if ( $ trim == false ) { return $ data ; } else { return rtrim ( $ data , "\r\n" ) ; } } throw new ezcMailTransportException ( 'Could not read from the stream. It was probably terminated by the host.' ) ; }
|
Returns one line of data from the stream .
|
11,508
|
public function clear ( ) { $ files = glob ( ERDIKO_VAR . "/cache/*" ) ; foreach ( $ files as $ file ) { if ( is_file ( $ file ) ) { parent :: delete ( basename ( $ file ) ) ; } } }
|
Delete all keys
|
11,509
|
private function verifyElementsType ( array $ elements ) : void { $ allowedType = $ this -> getAllowedType ( ) ; if ( $ allowedType !== DTO :: class && ( ! \ class_exists ( $ allowedType ) || ! \ in_array ( DTO :: class , \ class_implements ( $ allowedType ) , true ) ) ) { throw new InvalidCollectionTypeException ( \ sprintf ( 'Allowed class type for %s should be a %s, %s given' , static :: class , DTO :: class , $ allowedType ) ) ; } foreach ( $ elements as $ element ) { if ( ! \ is_object ( $ element ) || ! \ is_a ( $ element , $ allowedType ) ) { throw new InvalidParameterException ( \ sprintf ( 'All elements of %s should be instances of %s, %s given' , static :: class , $ allowedType , \ is_object ( $ element ) ? \ get_class ( $ element ) : \ gettype ( $ element ) ) ) ; } } }
|
Verify collection elements type .
|
11,510
|
function beforeSave ( Model $ Model , $ options = array ( ) ) { if ( ! array_key_exists ( 'Media' , $ Model -> belongsTo ) ) { $ Model -> bindModel ( array ( 'belongsTo' => array ( 'Media' => array ( 'className' => 'Risto.Media' ) ) ) ) ; } if ( isset ( $ Model -> data [ $ Model -> alias ] [ $ this -> _form_field_name ] ) && isset ( $ Model -> data [ $ Model -> alias ] [ $ this -> _form_field_name ] [ 'error' ] ) && $ Model -> data [ $ Model -> alias ] [ $ this -> _form_field_name ] [ 'error' ] == 0 ) { $ data = array ( 'Media' => $ Model -> data [ $ Model -> alias ] [ $ this -> _form_field_name ] ) ; $ data [ 'Media' ] [ 'file' ] = file_get_contents ( $ Model -> data [ $ Model -> alias ] [ $ this -> _form_field_name ] [ 'tmp_name' ] ) ; $ data [ 'Media' ] [ 'model' ] = $ Model -> name ; $ Model -> Media -> create ( ) ; if ( ! $ Model -> Media -> save ( $ data ) ) { $ Model -> validationErrors [ $ this -> _form_field_name ] = $ Model -> Media -> validationErrors ; return false ; } $ Model -> data [ $ Model -> alias ] [ $ this -> _form_fk ] = $ Model -> Media -> id ; } return true ; }
|
beforeSave if a file is found upload it and then save the filename according to the settings
|
11,511
|
public static function create ( $ postType , $ config , $ throwExceptionOnInvalidWriter = false ) { $ className = 'Fillet\\Writer\\' . ucfirst ( $ postType ) . 'Writer' ; if ( class_exists ( $ className ) ) { $ writer = new $ className ( $ config [ 'destinationFolders' ] [ $ postType ] , $ config ) ; return $ writer ; } if ( $ throwExceptionOnInvalidWriter ) { throw new \ Exception ( 'There is no writer for ' . $ postType ) ; } }
|
Create a new instance of a writer based on the post type
|
11,512
|
public function styles ( ) { $ assets = array ( ) ; foreach ( $ this -> assets as $ asset ) { if ( 'css' !== $ asset [ 'ext' ] && 'less' !== $ asset [ 'ext' ] ) { continue ; } $ assets [ ] = $ this -> route ? $ asset : $ this -> process ( $ asset ) ; } if ( empty ( $ assets ) ) { return '' ; } if ( $ this -> route ) { return $ this -> prepareForController ( $ assets , 'style' ) ; } if ( $ this -> combine ) { $ assets = $ this -> combine ( $ assets , 'style' ) ; } $ links = array ( ) ; foreach ( $ assets as $ asset ) { $ url = $ this -> cdn ? $ this -> cdn . $ asset [ 'url' ] : $ asset [ 'url' ] ; $ links [ ] = HTML :: style ( $ url , $ asset [ 'attributes' ] ) ; } return implode ( '' , $ links ) ; }
|
Get the HTML links to all of the registered CSS assets .
|
11,513
|
public function scripts ( ) { $ assets = array ( ) ; foreach ( $ this -> assets as $ asset ) { if ( 'js' !== $ asset [ 'ext' ] ) { continue ; } $ assets [ ] = $ this -> route ? $ asset : $ this -> process ( $ asset ) ; } if ( empty ( $ assets ) ) { return '' ; } if ( $ this -> route ) { return $ this -> prepareForController ( $ assets , 'script' ) ; } if ( $ this -> combine ) { $ assets = $ this -> combine ( $ assets , 'script' ) ; } $ links = array ( ) ; foreach ( $ assets as $ asset ) { $ url = $ this -> cdn ? $ this -> cdn . $ asset [ 'url' ] : $ asset [ 'url' ] ; $ links [ ] = HTML :: script ( $ url , $ asset [ 'attributes' ] ) ; } return implode ( '' , $ links ) ; }
|
Get the HTML links to all of the registered JavaScript assets .
|
11,514
|
public function prepareForController ( $ assets , $ type ) { $ controller_url = $ this -> cdn ? $ this -> cdn . '/' : '/' ; $ controller_url .= $ this -> route . '/' . $ type ; $ controller_url .= '?c=' . urlencode ( $ this -> name ) ; $ links = array ( ) ; foreach ( $ assets as & $ asset ) { $ attributes = $ asset [ 'attributes' ] ; unset ( $ asset [ 'attributes' ] ) ; unset ( $ asset [ 'ext' ] ) ; if ( empty ( $ asset [ 'dependencies' ] ) ) { unset ( $ asset [ 'dependencies' ] ) ; } if ( ! $ this -> combine ) { $ url = $ controller_url . '&files=' . base64_encode ( json_encode ( array ( $ asset ) ) ) ; $ url .= $ this -> version ? '&v=' . $ this -> version : '' ; if ( 'style' == $ type ) { $ links [ ] = HTML :: style ( $ url , $ attributes ) ; } else { $ links [ ] = HTML :: script ( $ url , $ attributes ) ; } } } if ( $ this -> combine ) { $ url = $ controller_url . '&files=' . base64_encode ( json_encode ( $ assets ) ) ; $ url .= $ this -> version ? '&v=' . $ this -> version : '' ; if ( 'style' == $ type ) { $ links [ ] = HTML :: style ( $ url ) ; } else { $ links [ ] = HTML :: script ( $ url ) ; } } return implode ( '' , $ links ) ; }
|
Prepare the given assets to be rendered to call the Casset controller and return the HTML link to that resource .
|
11,515
|
public function content ( $ type ) { $ assets = array ( ) ; foreach ( $ this -> assets as $ asset ) { if ( 'style' == $ type && 'css' !== $ asset [ 'ext' ] && 'less' !== $ asset [ 'ext' ] ) { continue ; } else if ( 'script' == $ type && 'js' !== $ asset [ 'ext' ] ) { continue ; } $ assets [ ] = $ this -> process ( $ asset ) ; } if ( empty ( $ assets ) ) { return '' ; } if ( count ( $ assets ) > 1 || $ this -> minify ) { $ assets = $ this -> combine ( $ assets , $ type ) ; } $ content = array ( ) ; foreach ( $ assets as $ asset ) { $ content [ ] = File :: get ( array_get ( $ asset , 'path' ) ) ; } return implode ( "\n\n" , $ content ) ; }
|
Process and return the contents for this container for the requested file type .
|
11,516
|
public function image ( $ source , $ alt = null , $ attributes = array ( ) ) { $ url = $ source ; if ( false === strstr ( $ source , '://' ) && '//' !== substr ( $ source , 0 , 2 ) ) { $ url = $ this -> cdn ( $ source ) ; } return HTML :: image ( $ url , $ alt , $ attributes ) ; }
|
Add an image asset to the container .
|
11,517
|
public function cdn ( $ source ) { $ url = str_ireplace ( $ this -> public_path , '' , $ this -> assets_path . '/' . ltrim ( $ source , '/' ) ) ; $ url = $ this -> cdn ? $ this -> cdn . $ url : $ url ; return $ url ; }
|
Get the URL to the CDN for an asset .
|
11,518
|
public function needsProcessing ( array $ asset ) { if ( isset ( static :: $ needs_processing [ $ asset [ 'source' ] ] ) ) { return static :: $ needs_processing [ $ asset [ 'source' ] ] ; } $ path = $ this -> path ( $ asset [ 'source' ] ) ; $ is_public = ( bool ) stristr ( $ path , $ this -> public_path ) ; $ compiled_exts = array ( 'less' ) ; $ dependencies = isset ( $ asset [ 'dependencies' ] ) ? $ asset [ 'dependencies' ] : array ( ) ; $ dependencies = array_unique ( array_merge ( array_get ( $ this -> dependencies , $ asset [ 'ext' ] , array ( ) ) , $ dependencies ) ) ; if ( ! empty ( $ dependencies ) ) { foreach ( $ dependencies as $ dep_source ) { if ( ! empty ( static :: $ needs_processing [ $ dep_source ] ) ) { return static :: $ needs_processing [ $ asset [ 'source' ] ] = true ; } } } if ( $ is_public && ! in_array ( $ asset [ 'ext' ] , $ compiled_exts ) ) { return static :: $ needs_processing [ $ asset [ 'source' ] ] = false ; } $ cache_path = $ this -> publicPath ( $ asset ) ; if ( ! File :: exists ( $ cache_path ) ) { return static :: $ needs_processing [ $ asset [ 'source' ] ] = true ; } if ( File :: lastModified ( $ cache_path ) >= File :: lastModified ( $ path ) ) { return static :: $ needs_processing [ $ asset [ 'source' ] ] = false ; } if ( $ f = fopen ( $ cache_path , 'r' ) ) { $ line = ( string ) fgets ( $ f ) ; fclose ( $ f ) ; if ( false !== strstr ( $ line , '*/' ) ) { $ md5 = trim ( str_replace ( array ( '/*' , '*/' ) , '' , $ line ) ) ; if ( 32 == strlen ( $ md5 ) ) { $ file_md5 = md5_file ( $ path ) ; if ( $ file_md5 === $ md5 ) { touch ( $ cache_path ) ; return false ; } } } } return static :: $ needs_processing [ $ asset [ 'source' ] ] = true ; }
|
Returns whether or not a file needs to be processed .
|
11,519
|
public function compile ( $ path ) { switch ( pathinfo ( $ path , PATHINFO_EXTENSION ) ) { case 'less' : $ less = new Less_Parser ; $ content = '/*' . md5 ( File :: get ( $ path ) ) . "*/\n" . $ less -> parseFile ( $ path ) -> getCss ( ) ; break ; default : $ content = File :: get ( $ path ) ; } return $ content ; }
|
Compile and return the content for the given asset according to it s extension .
|
11,520
|
public function combine ( array $ assets , $ type ) { $ paths = array ( ) ; $ lastmod = 0 ; foreach ( $ assets as $ asset ) { $ paths [ ] = $ asset [ 'path' ] ; $ mod = File :: lastModified ( $ asset [ 'path' ] ) ; if ( $ mod > $ lastmod ) { $ lastmod = $ mod ; } } $ file = $ this -> cache_path . '/casset-' . md5 ( implode ( ',' , $ paths ) . $ lastmod ) . '-' . $ this -> name ; $ file .= ( 'script' === $ type ) ? '.js' : '.css' ; $ combine = false ; if ( ! File :: exists ( $ file ) ) { $ combine = true ; } else if ( File :: lastModified ( $ file ) < $ lastmod ) { $ combine = true ; } if ( $ combine ) { $ content = '' ; foreach ( $ assets as $ asset ) { if ( ! File :: exists ( $ asset [ 'path' ] ) ) { continue ; } $ c = File :: get ( $ asset [ 'path' ] ) ; if ( $ this -> minify && ! ( stripos ( $ asset [ 'source' ] , '.min' ) || stripos ( $ asset [ 'source' ] , '-min' ) ) ) { switch ( $ type ) { case 'style' : $ c = Compressors \ Css :: process ( $ c ) ; break ; case 'script' : $ c = Compressors \ Js :: minify ( $ c ) ; break ; } } $ content .= "/* {$asset['source']} */\n$c\n\n" ; } File :: put ( $ file , $ content ) ; } return array ( array ( 'path' => $ file , 'attributes' => array ( ) , 'url' => str_ireplace ( $ this -> public_path , '' , $ file ) , ) ) ; }
|
Combine the given array of assets . Minify if enabled . Returns new array containing one asset .
|
11,521
|
protected function fetchContentOptions ( $ model , $ key , $ index ) { $ options = parent :: fetchContentOptions ( $ model , $ key , $ index ) ; if ( ! empty ( $ this -> columnOptions ) ) { foreach ( $ this -> columnOptions as $ option => $ value ) { $ options [ 'data-column-' . $ option ] = $ value ; } } return $ options ; }
|
Parses and fetches updated content options for grid visibility and format
|
11,522
|
public function getValue ( ) { $ values = [ ] ; foreach ( $ this -> values as $ key => $ value ) { $ values [ $ key ] = $ value -> getValue ( ) ; } return $ values ; }
|
returns the value . the value maybe invalid .
|
11,523
|
public function getValidValue ( ) { $ values = [ ] ; foreach ( $ this -> values as $ key => $ value ) { if ( $ this -> isValidValue ( $ value ) ) { $ values [ $ key ] = $ value -> getValidValue ( ) ; } } return $ values ; }
|
return the validated value . returns false if validation fails .
|
11,524
|
public function query ( $ key = null , $ default = null ) { $ queries = $ this -> getQueryParams ( ) ; return is_null ( $ key ) ? $ queries : data_get ( $ queries , $ key , $ default ) ; }
|
Retrieve a query string item from the request .
|
11,525
|
public function post ( $ key = null , $ default = null ) { $ posts = $ this -> getPostParams ( ) ; return is_null ( $ key ) ? $ posts : data_get ( $ posts , $ key , $ default ) ; }
|
Retrieve a post data item from the request .
|
11,526
|
public function server ( $ key = null , $ default = null ) { $ servers = $ this -> getServerParams ( ) ; return is_null ( $ key ) ? $ servers : data_get ( $ servers , $ key , $ default ) ; }
|
Retrieve a server variable from the request .
|
11,527
|
public function cookie ( $ key = null , $ default = null ) { $ cookies = $ this -> getCookieParams ( ) ; return is_null ( $ key ) ? $ cookies : data_get ( $ cookies , $ key , $ default ) ; }
|
Retrieve a cookie from the request .
|
11,528
|
public function loadConfigurationFile ( Module $ module ) { $ finder = ( new Finder ) -> name ( '#customer[-_\.]?group\.xml#i' ) -> in ( $ module -> getAbsoluteConfigPath ( ) ) ; $ count = $ finder -> count ( ) ; if ( $ count > 1 ) { throw new InvalidConfigurationException ( 'Too many configuration file.' ) ; } else { foreach ( $ finder as $ file ) { if ( strtolower ( pathinfo ( $ file , PATHINFO_EXTENSION ) ) === 'xml' ) { $ moduleConfig = $ this -> parseXml ( $ file ) ; } else { $ moduleConfig = $ this -> parseYml ( $ file ) ; } $ this -> applyConfig ( $ moduleConfig ) ; } } }
|
Find parse and load customer group configuration file for module
|
11,529
|
protected function applyConfig ( array $ moduleConfiguration ) { foreach ( $ moduleConfiguration [ 'customer_group' ] as $ customerGroupData ) { if ( CustomerGroupQuery :: create ( ) -> findOneByCode ( $ customerGroupData [ 'code' ] ) === null ) { $ customerGroup = ( new CustomerGroup ) -> setCode ( $ customerGroupData [ 'code' ] ) ; foreach ( $ customerGroupData [ 'descriptive' ] as $ descriptiveData ) { $ customerGroup -> setLocale ( $ descriptiveData [ 'locale' ] ) -> setTitle ( $ descriptiveData [ 'title' ] ) -> setDescription ( $ descriptiveData [ 'description' ] ) ; } $ customerGroup -> save ( ) ; } } if ( $ moduleConfiguration [ 'default' ] ) { $ customerGroup = CustomerGroupQuery :: create ( ) -> findOneByCode ( $ moduleConfiguration [ 'default' ] ) ; if ( $ customerGroup !== null ) { $ this -> resetDefault ( ) ; $ customerGroup -> setIsDefault ( true ) -> save ( ) ; } } }
|
Save new customer group to database
|
11,530
|
protected function resetDefault ( ) { $ defaultGroups = CustomerGroupQuery :: create ( ) -> filterByIsDefault ( true ) -> find ( ) ; foreach ( $ defaultGroups as $ defaultGroup ) { $ defaultGroup -> setIsDefault ( false ) -> save ( ) ; } }
|
Remove is_default flag
|
11,531
|
public function generate ( WorkPackage $ work ) { $ description = $ work -> getTaskDescription ( ) ; $ command = $ description -> getCommand ( ) ; if ( ! $ this -> isValidCommand ( $ command ) ) { throw new TaskCommandGeneratorException ( "This command is not usable '{$command}' is not valid" ) ; } $ cmd = escapeshellarg ( $ command ) ; $ cmd .= $ this -> generateArguments ( $ description ) ; $ cmd .= $ this -> generateOptions ( $ description ) ; return $ cmd ; }
|
Generates a symfony2 console command to execute from the task
|
11,532
|
private function generateArguments ( TaskDescriptionInterface $ description ) { $ cmdPart = '' ; $ arguments = $ description -> getArguments ( ) ; if ( ! is_array ( $ arguments ) ) { return $ cmdPart ; } foreach ( $ arguments as $ argumentValue ) { if ( is_string ( $ argumentValue ) || is_integer ( $ argumentValue ) ) { $ cmdPart .= ' ' . escapeshellarg ( $ argumentValue ) ; } } return $ cmdPart ; }
|
Generates the argument part of the command
|
11,533
|
private function generateOptions ( TaskDescriptionInterface $ description ) { $ cmdPart = '' ; $ options = $ description -> getOptions ( ) ; if ( ! is_array ( $ options ) ) { return $ cmdPart ; } foreach ( $ options as $ optionName => $ optionValue ) { if ( ! $ this -> isValidOptionName ( $ optionName ) ) { continue ; } if ( is_bool ( $ optionValue ) && $ optionValue ) { $ cmdPart .= ' --' . $ optionName ; } elseif ( is_string ( $ optionValue ) || is_integer ( $ optionValue ) ) { $ cmdPart .= ' --' . $ optionName . '=' . escapeshellarg ( $ optionValue ) ; } } return $ cmdPart ; }
|
Generates the options part of the command
|
11,534
|
public function getTheme ( $ themeName ) { if ( empty ( $ themeName ) ) { throw new \ InvalidArgumentException ( 'The theme name must not be empty.' ) ; } elseif ( ! $ this -> hasTheme ( $ themeName ) ) { throw new \ LogicException ( sprintf ( 'Unable to retrieve definition for theme "%s".' , $ themeName ) ) ; } if ( ! isset ( $ this -> instances [ $ themeName ] ) ) { $ theme = $ this -> themeFactory -> create ( $ themeName , $ this -> themeDefinitions [ $ themeName ] ) ; $ this -> instances [ $ themeName ] = $ this -> mergePageTemplates ( $ theme ) ; } return $ this -> instances [ $ themeName ] ; }
|
Gets theme model instance
|
11,535
|
protected function getRequiredModule ( string $ className ) { if ( \ array_key_exists ( $ className , $ this -> modules ) ) { return $ this -> modules [ $ className ] ; } else { throw new ConfigurationException ( __CLASS__ . ' tried to request module ' . $ className . ', but it was not listed as a dependency or has not yet added.' ) ; } }
|
Returns a module that has been set as required . This is only available after the constructor has finished .
|
11,536
|
public function updated ( Option $ model ) { $ option = Option :: query ( ) -> firstOrNew ( [ 'name' => 'notifications_remove_after_days' ] ) ; $ option -> value = input ( 'days' ) ; return $ option -> save ( ) ; }
|
Save notifications configuration
|
11,537
|
static function countWithSubscriberID ( $ subscriberID , $ languageID = false , $ enabled = false ) { $ cond = array ( ) ; $ cond [ 'subscriber_id' ] = $ subscriberID ; if ( $ enabled !== false ) { $ cond [ 'enabled' ] = $ enabled ; } if ( $ languageID !== false ) { $ cond [ 'language_id' ] = $ languageID ; } $ count = eZPersistentObject :: count ( self :: definition ( ) , $ cond ) ; return $ count ; }
|
get the count of subscription in a subscriber ID
|
11,538
|
public function contentObject ( ) { $ contentID = $ this -> attribute ( 'content_id' ) ; $ languageID = $ this -> attribute ( 'language_id' ) ; return eZContentObject :: fetch ( $ contentID ) ; }
|
get the content of the subscription
|
11,539
|
static function exists ( $ contentID , $ languageID , $ subscriptionType , $ email = null , $ enabled = false ) { $ emailString = '' ; if ( ! is_null ( $ email ) ) { $ emailString = " WHERE email = '$email'" ; } $ countArray = null ; $ db = eZDB :: instance ( ) ; if ( $ enabled === false ) { $ countArray = $ db -> arrayQuery ( "SELECT count(*) AS count" . " FROM ezcomment_subscription" . " WHERE " . " content_id = $contentID" . " AND language_id = $languageID" . " AND subscription_type = '$subscriptionType'" . " AND subscriber_id IN" . "( SELECT id FROM ezcomment_subscriber" . "$emailString )" ) ; } else if ( $ enabled === 1 || $ enabled === 0 ) { $ enabledString = "enabled = $enabled" ; if ( $ emailString != '' ) { $ enabledString = " AND " . $ enabledString ; } else { $ enabledString = " WHERE " . $ enabledString ; } $ countArray = $ db -> arrayQuery ( "SELECT count(*) AS count" . " FROM ezcomment_subscription" . " WHERE" . " content_id = $contentID" . " AND language_id = $languageID" . " AND subscription_type = '$subscriptionType'" . " AND subscriber_id IN" . " ( SELECT id FROM ezcomment_subscriber" . $ emailString . "$enabledString )" ) ; } else { return null ; } $ totalCount = $ countArray [ 0 ] [ 'count' ] ; if ( $ totalCount === '0' ) { return false ; } else { return true ; } }
|
Check if the subscription exists by a given contentID
|
11,540
|
public function render ( ) { Merchant :: script ( $ this -> script ( ) ) ; view ( ) -> share ( [ 'path' => $ this -> path , 'keyName' => $ this -> model -> getKeyName ( ) , 'branchView' => $ this -> view [ 'branch' ] , 'branchCallback' => $ this -> branchCallback , ] ) ; return view ( $ this -> view [ 'tree' ] , $ this -> variables ( ) ) -> render ( ) ; }
|
Render a tree .
|
11,541
|
public function send ( $ data ) { $ pieces = [ $ this -> config [ 'apiKey' ] , $ this -> config [ 'prefix' ] , $ data . ' ' . time ( ) , ] ; $ message = implode ( '.' , $ pieces ) . PHP_EOL ; return $ this -> sendData ( $ this -> config [ 'host' ] , $ this -> config [ 'port' ] , $ message ) ; }
|
Data to send to Graphite host
|
11,542
|
public static function __callstatic ( $ name , $ arguments ) { $ services = Client :: getServices ( isset ( $ arguments [ 'context' ] ) ? $ arguments [ 'context' ] : null ) ; if ( array_key_exists ( $ name , $ services ) ) { $ service = $ services [ $ name ] ; switch ( $ service [ 'type' ] ) { case 'collection' : return new Cursor ( $ service , Client :: getInstance ( ) , isset ( $ arguments [ 'context' ] ) ? $ arguments [ 'context' ] : null ) ; break ; case 'entity' : return new Entity ( $ service , Client :: getInstance ( ) , isset ( $ arguments [ 0 ] ) ? $ arguments [ 0 ] : null ) ; break ; case 'action' : return new Action ( $ service , $ arguments [ 'context' ] , Client :: getInstance ( ) ) ; break ; default : throw new \ Exception ( "Don't know of any service type named '$name'" ) ; break ; } } else { throw new \ Exception ( "can't find service definition for '$name'" ) ; } }
|
Magic method for static calls
|
11,543
|
public function getTagAndSetLocale ( $ name , $ locale = null ) { $ tag = $ this -> getTag ( $ name ) ; $ locale = $ locale ? : $ tag -> getLocaleForName ( $ name ) ; set_app_locale ( $ locale ) ; return $ tag ; }
|
Returns a tag by name and sets the locale
|
11,544
|
private function createCreateForm ( Episode $ entity ) { $ form = $ this -> createForm ( EpisodeType :: class , $ entity , array ( 'action' => $ this -> generateUrl ( 'oktolab_episode_create' ) , 'method' => 'POST' , ) ) ; $ form -> add ( 'submit' , SubmitType :: class , [ 'label' => 'oktolab_media.new_episode_create_button' , 'attr' => [ 'class' => 'btn btn-primary' ] ] ) ; return $ form ; }
|
Creates a form to create a Episode entity .
|
11,545
|
public function newAction ( Request $ request ) { $ entity = new Episode ( ) ; $ form = $ this -> createCreateForm ( $ entity ) ; return [ 'entity' => $ entity , 'form' => $ form -> createView ( ) , ] ; }
|
Displays a form to create a new Episode entity .
|
11,546
|
private function createEditForm ( Episode $ entity ) { $ form = $ this -> createForm ( new EpisodeType ( ) , $ entity , [ 'action' => $ this -> generateUrl ( 'oktolab_episode_update' , [ 'id' => $ entity -> getId ( ) ] ) , 'method' => 'POST' ] ) ; $ form -> add ( 'submit' , 'submit' , [ 'label' => 'oktolab_media.edit_episode_button' ] ) ; return $ form ; }
|
Creates a form to edit a Episode entity .
|
11,547
|
public function deleteAction ( Request $ request , $ id ) { $ form = $ this -> createDeleteForm ( $ id ) ; $ form -> handleRequest ( $ request ) ; if ( $ form -> isValid ( ) ) { $ em = $ this -> getDoctrine ( ) -> getManager ( ) ; $ entity = $ em -> getRepository ( 'OktolabMediaBundle:Episode' ) -> find ( $ id ) ; if ( ! $ entity ) { throw $ this -> createNotFoundException ( 'Unable to find Episode entity.' ) ; } $ this -> get ( 'oktolab_media_helper' ) -> deleteEpisode ( $ episode ) ; } return $ this -> redirect ( $ this -> generateUrl ( 'oktolab_episode' ) ) ; }
|
Deletes a Episode entity .
|
11,548
|
function Image_Toolbox ( ) { $ args = func_get_args ( ) ; $ argc = func_num_args ( ) ; $ gd_info = function_exists ( 'gd_info' ) ? gd_info ( ) : $ this -> _gd_info ( ) ; preg_match ( "/\A[\D]*([\d+\.]*)[\D]*\Z/" , $ gd_info [ 'GD Version' ] , $ matches ) ; list ( $ this -> _gd_version_string , $ this -> _gd_version_number ) = $ matches ; $ this -> _gd_version = substr ( $ this -> _gd_version_number , 0 , strpos ( $ this -> _gd_version_number , '.' ) ) ; if ( $ this -> _gd_version >= 2 ) { $ this -> _imagecreatefunction = 'imagecreatetruecolor' ; $ this -> _resize_function = 'imagecopyresampled' ; } else { $ this -> _imagecreatefunction = 'imagecreate' ; $ this -> _resize_function = 'imagecopyresized' ; } $ this -> _gd_ttf = $ gd_info [ 'FreeType Support' ] ; $ this -> _gd_ps = $ gd_info [ 'T1Lib Support' ] ; if ( isset ( $ gd_info [ 'GIF Read Support' ] ) ) { $ this -> _types [ 1 ] [ 'supported' ] = 1 ; if ( $ gd_info [ 'GIF Create Support' ] ) { $ this -> _types [ 1 ] [ 'supported' ] = 2 ; } } if ( isset ( $ gd_info [ 'JPEG Support' ] ) || isset ( $ gd_info [ 'JPG Support' ] ) ) { $ this -> _types [ 2 ] [ 'supported' ] = 2 ; } if ( isset ( $ gd_info [ 'PNG Support' ] ) ) { $ this -> _types [ 3 ] [ 'supported' ] = 2 ; } if ( $ argc == 0 ) { return true ; } else { if ( $ this -> _addImage ( $ argc , $ args ) ) { foreach ( $ this -> _img [ 'operator' ] as $ key => $ value ) { $ this -> _img [ 'main' ] [ $ key ] = $ value ; } $ this -> _img [ 'main' ] [ 'output_type' ] = $ this -> _img [ 'main' ] [ 'type' ] ; unset ( $ this -> _img [ 'operator' ] ) ; return true ; } else { return null ; } } }
|
The class constructor .
|
11,549
|
function getServerFeatures ( ) { $ features = array ( ) ; $ features [ 'gd_version' ] = $ this -> _gd_version_number ; $ features [ 'gif' ] = $ this -> _types [ 1 ] [ 'supported' ] ; $ features [ 'jpg' ] = $ this -> _types [ 2 ] [ 'supported' ] ; $ features [ 'png' ] = $ this -> _types [ 3 ] [ 'supported' ] ; $ features [ 'ttf' ] = $ this -> _gd_ttf ; return $ features ; }
|
Returns an assocative array with information about the image features of this server
|
11,550
|
function newImage ( ) { $ args = func_get_args ( ) ; $ argc = func_num_args ( ) ; if ( $ this -> _addImage ( $ argc , $ args ) ) { foreach ( $ this -> _img [ 'operator' ] as $ key => $ value ) { $ this -> _img [ 'main' ] [ $ key ] = $ value ; } $ this -> _img [ 'main' ] [ 'output_type' ] = $ this -> _img [ 'main' ] [ 'type' ] ; unset ( $ this -> _img [ 'operator' ] ) ; return true ; } else { return null ; } }
|
Flush all image resources and init a new one
|
11,551
|
function _hexToPHPColor ( $ hex ) { $ length = strlen ( $ hex ) ; $ dr = hexdec ( substr ( $ hex , $ length - 6 , 2 ) ) ; $ dg = hexdec ( substr ( $ hex , $ length - 4 , 2 ) ) ; $ db = hexdec ( substr ( $ hex , $ length - 2 , 2 ) ) ; $ color = ( $ dr << 16 ) + ( $ dg << 8 ) + $ db ; return $ color ; }
|
Convert a color defined in hexvalues to the PHP color format
|
11,552
|
function _hexToDecColor ( $ hex ) { $ length = strlen ( $ hex ) ; $ color [ 'red' ] = hexdec ( substr ( $ hex , $ length - 6 , 2 ) ) ; $ color [ 'green' ] = hexdec ( substr ( $ hex , $ length - 4 , 2 ) ) ; $ color [ 'blue' ] = hexdec ( substr ( $ hex , $ length - 2 , 2 ) ) ; return $ color ; }
|
Convert a color defined in hexvalues to corresponding dezimal values
|
11,553
|
function _addImage ( $ argc , $ args ) { if ( ( $ argc == 2 || $ argc == 3 ) && is_int ( $ args [ 0 ] ) && is_int ( $ args [ 1 ] ) && ( is_string ( $ args [ 2 ] ) || ! isset ( $ args [ 2 ] ) ) ) { $ this -> _img [ 'operator' ] [ 'width' ] = $ args [ 0 ] ; $ this -> _img [ 'operator' ] [ 'height' ] = $ args [ 1 ] ; ( $ this -> _img [ 'operator' ] [ 'width' ] >= $ this -> _img [ 'operator' ] [ 'height' ] ) ? ( $ this -> _img [ 'operator' ] [ 'bias' ] = IMAGE_TOOLBOX_BIAS_HORIZONTAL ) : ( $ this -> _img [ 'operator' ] [ 'bias' ] = IMAGE_TOOLBOX_BIAS_VERTICAL ) ; $ this -> _img [ 'operator' ] [ 'aspectratio' ] = $ this -> _img [ 'operator' ] [ 'width' ] / $ this -> _img [ 'operator' ] [ 'height' ] ; $ this -> _img [ 'operator' ] [ 'indexedcolors' ] = 0 ; $ functionname = $ this -> _imagecreatefunction ; $ this -> _img [ 'operator' ] [ 'resource' ] = $ functionname ( $ this -> _img [ 'operator' ] [ 'width' ] , $ this -> _img [ 'operator' ] [ 'height' ] ) ; $ this -> _img [ 'operator' ] [ 'type' ] = 2 ; if ( isset ( $ args [ 2 ] ) && is_string ( $ args [ 2 ] ) ) { $ fillcolor = $ this -> _hexToPHPColor ( $ args [ 2 ] ) ; imagefill ( $ this -> _img [ 'operator' ] [ 'resource' ] , 0 , 0 , $ fillcolor ) ; $ this -> _img [ 'operator' ] [ 'color' ] = $ fillcolor ; } else { $ this -> _img [ 'operator' ] [ 'color' ] = 0 ; } } elseif ( $ argc == 1 && is_string ( $ args [ 0 ] ) ) { $ this -> _img [ 'operator' ] = $ this -> _loadFile ( $ args [ 0 ] ) ; $ this -> _img [ 'operator' ] [ 'indexedcolors' ] = imagecolorstotal ( $ this -> _img [ 'operator' ] [ 'resource' ] ) ; $ this -> _img [ 'operator' ] [ 'color' ] = - 1 ; } else { return false ; } return true ; }
|
Generate a new image resource based on the given parameters
|
11,554
|
function _loadFile ( $ filename ) { if ( file_exists ( $ filename ) ) { $ info = getimagesize ( $ filename ) ; $ filedata [ 'width' ] = $ info [ 0 ] ; $ filedata [ 'height' ] = $ info [ 1 ] ; ( $ filedata [ 'width' ] >= $ filedata [ 'height' ] ) ? ( $ filedata [ 'bias' ] = IMAGE_TOOLBOX_BIAS_HORIZONTAL ) : ( $ filedata [ 'bias' ] = IMAGE_TOOLBOX_BIAS_VERTICAL ) ; $ filedata [ 'aspectratio' ] = $ filedata [ 'width' ] / $ filedata [ 'height' ] ; $ filedata [ 'type' ] = $ info [ 2 ] ; if ( $ this -> _types [ $ filedata [ 'type' ] ] [ 'supported' ] < 1 ) { return null ; } switch ( $ filedata [ 'type' ] ) { case 1 : $ dummy = imagecreatefromgif ( $ filename ) ; $ functionname = $ this -> _imagecreatefunction ; $ filedata [ 'resource' ] = $ functionname ( $ filedata [ 'width' ] , $ filedata [ 'height' ] ) ; imagecopy ( $ filedata [ 'resource' ] , $ dummy , 0 , 0 , 0 , 0 , $ filedata [ 'width' ] , $ filedata [ 'height' ] ) ; imagedestroy ( $ dummy ) ; break ; case 2 : $ filedata [ 'resource' ] = imagecreatefromjpeg ( $ filename ) ; break ; case 3 : $ dummy = imagecreatefrompng ( $ filename ) ; if ( imagecolorstotal ( $ dummy ) != 0 ) { $ functionname = $ this -> _imagecreatefunction ; $ filedata [ 'resource' ] = $ functionname ( $ filedata [ 'width' ] , $ filedata [ 'height' ] ) ; imagecopy ( $ filedata [ 'resource' ] , $ dummy , 0 , 0 , 0 , 0 , $ filedata [ 'width' ] , $ filedata [ 'height' ] ) ; } else { $ filedata [ 'resource' ] = $ dummy ; } unset ( $ dummy ) ; break ; default : return null ; } return $ filedata ; } else { return null ; } }
|
Loads a image file
|
11,555
|
function setResizeMethod ( $ method ) { switch ( $ method ) { case 1 : case 'resize' : $ this -> _resize_function = 'imagecopyresized' ; break ; case 2 : case 'resample' : if ( ! function_exists ( 'imagecopyresampled' ) ) { return null ; } $ this -> _resize_function = 'imagecopyresampled' ; break ; case 3 : case 'resample_workaround' : case 'workaround' : case 'bicubic' : $ this -> _resize_function = '$this->_imageCopyResampledWorkaround' ; break ; case 4 : case 'resample_workaround2' : case 'workaround2' : case 'bicubic2' : $ this -> _resize_function = '$this->_imageCopyResampledWorkaround2' ; break ; default : return null ; } return true ; }
|
Sets the resize method of choice
|
11,556
|
function addImage ( ) { $ args = func_get_args ( ) ; $ argc = func_num_args ( ) ; if ( $ this -> _addImage ( $ argc , $ args ) ) { return true ; } else { return false ; } }
|
Adds a new image resource based on the given parameters .
|
11,557
|
function addText ( $ text , $ font , $ size , $ color , $ x , $ y , $ angle = 0 ) { global $ HTTP_SERVER_VARS ; if ( substr ( $ font , 0 , 1 ) == DIRECTORY_SEPARATOR || ( substr ( $ font , 1 , 1 ) == ":" && ( substr ( $ font , 2 , 1 ) == "\\" || substr ( $ font , 2 , 1 ) == "/" ) ) ) { $ prepath = '' ; } else { $ prepath = substr ( $ HTTP_SERVER_VARS [ 'SCRIPT_FILENAME' ] , 0 , strrpos ( $ HTTP_SERVER_VARS [ 'SCRIPT_FILENAME' ] , DIRECTORY_SEPARATOR ) ) . DIRECTORY_SEPARATOR ; } $ text = $ this -> _iso2uni ( $ text ) ; if ( is_string ( $ x ) || is_string ( $ y ) ) { $ textsize = imagettfbbox ( $ size , $ angle , $ prepath . $ font , $ text ) ; $ textwidth = abs ( $ textsize [ 2 ] ) ; $ textheight = abs ( $ textsize [ 7 ] ) ; list ( $ xalign , $ xalign_offset ) = explode ( " " , $ x ) ; list ( $ yalign , $ yalign_offset ) = explode ( " " , $ y ) ; } if ( is_string ( $ x ) ) { switch ( $ xalign ) { case 'left' : $ x = 0 + $ xalign_offset ; break ; case 'right' : $ x = ( $ this -> _img [ 'main' ] [ 'width' ] - $ textwidth ) + $ xalign_offset ; break ; case 'middle' : case 'center' : $ x = ( ( $ this -> _img [ 'main' ] [ 'width' ] - $ textwidth ) / 2 ) + $ xalign_offset ; break ; } } if ( is_string ( $ y ) ) { switch ( $ yalign ) { case 'top' : $ y = ( 0 + $ textheight ) + $ yalign_offset ; break ; case 'bottom' : $ y = ( $ this -> _img [ 'main' ] [ 'height' ] ) + $ yalign_offset ; break ; case 'middle' : case 'center' : $ y = ( ( ( $ this -> _img [ 'main' ] [ 'height' ] - $ textheight ) / 2 ) + $ textheight ) + $ yalign_offset ; break ; } } imagettftext ( $ this -> _img [ 'main' ] [ 'resource' ] , $ size , $ angle , $ x , $ y , $ this -> _hexToPHPColor ( $ color ) , $ prepath . $ font , $ text ) ; return true ; }
|
Writes text over the image
|
11,558
|
function _imageCopyResampledWorkaround ( & $ dst_img , & $ src_img , $ dst_x , $ dst_y , $ src_x , $ src_y , $ dst_w , $ dst_h , $ src_w , $ src_h ) { $ scaleX = ( $ src_w - 1 ) / $ dst_w ; $ scaleY = ( $ src_h - 1 ) / $ dst_h ; $ scaleX2 = $ scaleX / 2.0 ; $ scaleY2 = $ scaleY / 2.0 ; for ( $ j = $ src_y ; $ j < $ src_y + $ dst_h ; $ j ++ ) { $ sY = $ j * $ scaleY ; for ( $ i = $ src_x ; $ i < $ src_x + $ dst_w ; $ i ++ ) { $ sX = $ i * $ scaleX ; $ c1 = ImageColorsForIndex ( $ src_img , ImageColorAt ( $ src_img , ( int ) $ sX , ( int ) $ sY + $ scaleY2 ) ) ; $ c2 = ImageColorsForIndex ( $ src_img , ImageColorAt ( $ src_img , ( int ) $ sX , ( int ) $ sY ) ) ; $ c3 = ImageColorsForIndex ( $ src_img , ImageColorAt ( $ src_img , ( int ) $ sX + $ scaleX2 , ( int ) $ sY + $ scaleY2 ) ) ; $ c4 = ImageColorsForIndex ( $ src_img , ImageColorAt ( $ src_img , ( int ) $ sX + $ scaleX2 , ( int ) $ sY ) ) ; $ red = ( integer ) ( ( $ c1 [ 'red' ] + $ c2 [ 'red' ] + $ c3 [ 'red' ] + $ c4 [ 'red' ] ) / 4 ) ; $ green = ( integer ) ( ( $ c1 [ 'green' ] + $ c2 [ 'green' ] + $ c3 [ 'green' ] + $ c4 [ 'green' ] ) / 4 ) ; $ blue = ( integer ) ( ( $ c1 [ 'blue' ] + $ c2 [ 'blue' ] + $ c3 [ 'blue' ] + $ c4 [ 'blue' ] ) / 4 ) ; $ color = ImageColorClosest ( $ dst_img , $ red , $ green , $ blue ) ; ImageSetPixel ( $ dst_img , $ dst_x + $ i - $ src_x , $ dst_y + $ j - $ src_y , $ color ) ; } } }
|
workaround function for bicubic resizing . works well for downsizing only . VERY slow . taken from php . net comments
|
11,559
|
function _imageCopyResampledWorkaround2 ( & $ dst_img , & $ src_img , $ dst_x , $ dst_y , $ src_x , $ src_y , $ dst_w , $ dst_h , $ src_w , $ src_h ) { ImagePaletteCopy ( $ dst_img , $ src_img ) ; $ rX = $ src_w / $ dst_w ; $ rY = $ src_h / $ dst_h ; $ w = 0 ; for ( $ y = $ dst_y ; $ y < $ dst_h ; $ y ++ ) { $ ow = $ w ; $ w = round ( ( $ y + 1 ) * $ rY ) ; $ t = 0 ; for ( $ x = $ dst_x ; $ x < $ dst_w ; $ x ++ ) { $ r = $ g = $ b = 0 ; $ a = 0 ; $ ot = $ t ; $ t = round ( ( $ x + 1 ) * $ rX ) ; for ( $ u = 0 ; $ u < ( $ w - $ ow ) ; $ u ++ ) { for ( $ p = 0 ; $ p < ( $ t - $ ot ) ; $ p ++ ) { $ c = ImageColorsForIndex ( $ src_img , ImageColorAt ( $ src_img , $ ot + $ p , $ ow + $ u ) ) ; $ r += $ c [ 'red' ] ; $ g += $ c [ 'green' ] ; $ b += $ c [ 'blue' ] ; $ a ++ ; } } ImageSetPixel ( $ dst_img , $ x , $ y , ImageColorClosest ( $ dst_img , $ r / $ a , $ g / $ a , $ b / $ a ) ) ; } } }
|
alternative workaround function for bicubic resizing . works well for downsizing and upsizing . VERY VERY slow . taken from php . net comments
|
11,560
|
public static function fromString ( $ headerString ) { $ headerString = trim ( $ headerString ) ; list ( $ name , $ value ) = explode ( ': ' , trim ( $ headerString ) , 2 ) ; return new self ( $ name , $ value ) ; }
|
Creates a header from a string representing a single header .
|
11,561
|
protected function installDotEnv ( PackageInterface $ package ) { $ templatePath = $ this -> getTempPath ( $ package ) . '/.env.template' ; $ dotEnvPath = $ this -> getInstallPath ( $ package ) . '/.env' ; $ dotEnvExamplePath = $ this -> getInstallPath ( $ package ) . '/.env.example' ; if ( ! file_exists ( $ templatePath ) ) { return ; } $ saltKeys = [ 'AUTH_KEY' , 'SECURE_AUTH_KEY' , 'LOGGED_IN_KEY' , 'NONCE_KEY' , 'AUTH_SALT' , 'SECURE_AUTH_SALT' , 'LOGGED_IN_SALT' , 'NONCE_SALT' , ] ; $ envExample = [ 'APP_PUBLIC' => 'public' ] ; foreach ( $ saltKeys as $ salt ) { $ envExample [ $ salt ] = 'YOUR_' . $ salt . '_GOES_HERE' ; } $ this -> compileTemplate ( $ templatePath , $ dotEnvExamplePath , $ envExample ) ; if ( file_exists ( $ dotEnvPath ) ) { return ; } $ env = [ 'APP_PUBLIC' => $ this -> plugin -> getPublicDirectory ( ) ] ; foreach ( $ saltKeys as $ salt ) { $ env [ $ salt ] = $ this -> generateSalt ( ) ; } $ this -> compileTemplate ( $ templatePath , $ dotEnvPath , $ env ) ; }
|
Set up the . env file .
|
11,562
|
protected function checkWordPressInstallation ( ) { $ defaultWpInstallDir = $ this -> plugin -> getRootDirectory ( ) . '/wordpress' ; $ wpInstallDir = $ this -> getComposerConfigurator ( ) -> getWordPressInstallDirectory ( ) ; if ( file_exists ( $ defaultWpInstallDir ) && is_dir ( $ defaultWpInstallDir ) ) { if ( ! is_dir ( $ wpInstallDir ) ) { if ( file_exists ( $ wpInstallDir ) ) { unlink ( $ wpInstallDir ) ; } rename ( $ defaultWpInstallDir , $ wpInstallDir ) ; } else { rmdir ( $ defaultWpInstallDir ) ; } } }
|
Check if WordPress is installed in the correct directory and move it there if it is not .
|
11,563
|
protected function selectPreferredLanguageOnWordPressInstall ( ) { $ wpInstallScriptPath = $ this -> getComposerConfigurator ( ) -> getWordPressInstallDirectory ( ) . '/wp-admin/install.php' ; if ( file_exists ( $ wpInstallScriptPath ) ) { $ wpInstallScript = file_get_contents ( $ wpInstallScriptPath ) ; $ wpInstallScript = preg_replace ( '/<\\/body>\\n<\\/html>\\s*$/' , '<script>' . PHP_EOL . 'if (jQuery(\'#language\').find(\'option[value="en_GB"]\').length) {' . PHP_EOL . ' jQuery(\'#language\').val(\'en_GB\').change();' . PHP_EOL . '}' . PHP_EOL . '</script>' . PHP_EOL . '</body>' . PHP_EOL . '</html>' . PHP_EOL , $ wpInstallScript ) ; file_put_contents ( $ wpInstallScriptPath , $ wpInstallScript ) ; } }
|
Select the preferred en_GB option in the WordPress installation language form .
|
11,564
|
protected function installFiles ( $ installPath , $ downloadPath , $ publicPath , $ files = [ ] ) { foreach ( $ files as $ file => $ overwrite ) { if ( $ overwrite || ( ! $ overwrite && ! file_exists ( $ installPath . '/' . $ file ) ) ) { if ( ! file_exists ( $ downloadPath . '/' . $ file ) ) { throw new FilesystemException ( 'The file ' . $ file . ' could not be found. Please report to cupoftea/wordpress.' ) ; } $ installFile = $ installPath . '/' . $ file ; if ( $ publicPath != 'public' ) { $ installFile = $ installPath . '/' . preg_replace ( '/^public/' , $ publicPath , $ file ) ; } if ( preg_match ( '/\\/$/' , $ file ) ) { $ this -> filesystem -> ensureDirectoryExists ( $ installFile ) ; continue ; } $ this -> filesystem -> rename ( $ downloadPath . '/' . $ file , $ installFile ) ; } } }
|
Install files .
|
11,565
|
private function compileTemplate ( $ templatePath , $ destinationPath , $ data = null ) { if ( $ data == null ) { $ data = $ destinationPath ; $ destinationPath = null ; } if ( ! isset ( $ this -> templates [ $ templatePath ] ) ) { $ this -> templates [ $ templatePath ] = file_get_contents ( $ templatePath ) ; } $ compiled = preg_replace_callback ( '/{{\s*([A-z0-9_-]+)\s*}}/' , function ( $ matches ) use ( $ data ) { if ( isset ( $ data [ $ matches [ 1 ] ] ) ) { return $ data [ $ matches [ 1 ] ] ; } return $ matches [ 0 ] ; } , $ this -> templates [ $ templatePath ] ) ; if ( $ destinationPath ) { file_put_contents ( $ destinationPath , $ compiled ) ; } return $ compiled ; }
|
Compile a template file .
|
11,566
|
private function sortRules ( & $ rules ) { sort ( $ rules ) ; usort ( $ rules , function ( $ a , $ b ) { return strlen ( $ a ) - strlen ( $ b ) ; } ) ; }
|
Sort gitignore rules .
|
11,567
|
private function generateSalt ( ) { $ str = '' ; $ length = 64 ; $ chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*(){}[]/|`,.?+-_=:;<> ' ; $ count = strlen ( $ chars ) ; while ( $ length -- ) { $ str .= $ chars [ mt_rand ( 0 , $ count - 1 ) ] ; } return 'base64:' . base64_encode ( $ str ) ; }
|
Generate a Salt Key .
|
11,568
|
public function removeElementClass ( $ class ) { $ delClass = [ ] ; if ( is_string ( $ class ) || is_array ( $ class ) ) { $ delClass = ( array ) $ class ; } foreach ( $ delClass as $ del ) { if ( ( $ key = array_search ( $ del , $ this -> elementClass ) ) ) { unset ( $ this -> elementClass [ $ key ] ) ; } } return $ this ; }
|
Remove element class .
|
11,569
|
public function getView ( ) { if ( ! empty ( $ this -> view ) ) { return $ this -> view ; } $ class = explode ( '\\' , get_called_class ( ) ) ; return 'merchant::form.' . strtolower ( end ( $ class ) ) ; }
|
Get view of this field .
|
11,570
|
public function updateComment ( $ comment , $ user = null , $ time = null , $ notified = null ) { if ( $ time === null ) { $ time = time ( ) ; } $ beforeUpdating = $ this -> beforeUpdatingComment ( $ comment , $ notified , $ time ) ; if ( $ beforeUpdating !== true ) { return $ beforeUpdating ; } $ comment -> store ( ) ; $ afterUpdating = $ this -> afterUpdatingComment ( $ comment , $ notified , $ time ) ; if ( $ afterUpdating !== true ) { return $ afterUpdating ; } return true ; }
|
Update the comment
|
11,571
|
public static function instance ( ) { if ( ! isset ( self :: $ instance ) ) { $ ini = eZINI :: instance ( 'ezcomments.ini' ) ; $ className = $ ini -> variable ( 'ManagerClasses' , 'CommentManagerClass' ) ; self :: $ instance = new $ className ( ) ; } return self :: $ instance ; }
|
create an instance of ezcomCommentManager
|
11,572
|
protected static function staticRequest ( $ method , $ url , $ params ) { $ requestor = new ApiRequestor ( ) ; list ( $ response , $ code ) = $ requestor -> request ( $ method , $ url , $ params ) ; return array ( $ response , $ code ) ; }
|
Make the http GET or POST request
|
11,573
|
public function xml ( ) { try { $ xml = new \ SimpleXMLElement ( ( string ) $ this -> body ? : '<root />' ) ; } catch ( \ Exception $ e ) { throw new RuntimeException ( 'Unable to parse response body into XML: ' . $ e -> getMessage ( ) ) ; } return $ xml ; }
|
Parse the XML response body and return a SimpleXMLElement
|
11,574
|
public static function mergeConfigurations ( $ target , $ source ) { foreach ( [ 'attributes' , 'entities' , 'relationships' , 'autocode' , 'languages' , 'frameworks' , 'orms' ] as $ configurationPart ) { if ( isset ( $ source [ $ configurationPart ] ) ) { $ target [ $ configurationPart ] = self :: mergeArrays ( $ target [ $ configurationPart ] , $ source [ $ configurationPart ] ) ; } } return $ target ; }
|
Complete the different configuration sections on the target array with those ones found on the source array
|
11,575
|
public static function loadConfiguration ( ) { $ defaultsFile = __DIR__ . '/../../../../app/config/defaults.yml' ; $ draggyFile = __DIR__ . '/../../../../app/config/draggy.yml' ; $ userFile = __DIR__ . '/../../../../app/config/user.yml' ; $ defaultsArray = Yaml :: parse ( $ defaultsFile ) ; $ configurationArray = is_file ( $ userFile ) ? Yaml :: parse ( $ userFile ) : Yaml :: parse ( $ draggyFile ) ; $ mergedArray = self :: mergeConfigurations ( $ defaultsArray , $ configurationArray ) ; return $ mergedArray ; }
|
Load the model configuration merge it onto the default one and return the result array
|
11,576
|
public function build ( ) { $ soapClient = ( new Factory ) -> getClient ( $ this -> getEndpoint ( ) , $ this -> getSoapOptions ( ) ) ; $ params [ 'user_id' ] = $ this -> userId ; $ params [ 'agent_code' ] = $ this -> agentCode ; $ params [ 'agent_seq' ] = $ this -> agentSeq ; $ client = new $ this -> client ( $ soapClient , $ params ) ; if ( $ this -> log ) { } return $ client ; }
|
Build a new client s instance
|
11,577
|
protected function parseResponse ( $ string ) { $ exp = explode ( Driver :: SEP , $ string ) ; if ( $ exp [ 0 ] != 0 ) { throw new HSException ( isset ( $ exp [ 2 ] ) ? $ exp [ 2 ] : '' , $ exp [ 0 ] ) ; } array_shift ( $ exp ) ; $ numCols = intval ( array_shift ( $ exp ) ) ; $ exp = array_map ( [ $ this -> socket , 'decode' ] , $ exp ) ; return array_chunk ( $ exp , $ numCols ) ; }
|
Parse response from server
|
11,578
|
private function connect ( ) { if ( ! $ this -> socket -> isOpened ( ) ) { $ this -> socket -> open ( ) ; if ( $ this -> secret ) { $ this -> socket -> send ( join ( Driver :: SEP , [ 'A' , 1 , Driver :: encode ( $ this -> secret ) ] ) . Driver :: EOL ) ; } } }
|
Connect to Handler Socket
|
11,579
|
public function moveSortableItemAction ( Request $ request ) { $ admin = $ this -> container -> get ( 'sonata.admin.pool' ) -> getInstance ( $ request -> get ( 'admin_code' ) ) ; $ class = $ admin -> getClass ( ) ; $ id = $ request -> get ( 'id' ) ; $ prev_rank = ( int ) $ request -> get ( 'prev_rank' ) ; $ next_rank = ( int ) $ request -> get ( 'next_rank' ) ; $ em = $ this -> getDoctrine ( ) -> getEntityManager ( ) ; $ meta = new ClassMetadata ( $ class ) ; $ repo = new SortableRepository ( $ em , $ meta ) ; if ( $ prev_rank ) { $ new_rank = $ repo -> moveObjectAfter ( $ id , $ prev_rank ) ; } elseif ( $ next_rank ) { $ new_rank = $ repo -> moveObjectBefore ( $ id , $ next_rank ) ; } return new JsonResponse ( array ( 'status' => $ new_rank ? 'OK' : 'KO' , 'new_rank' => $ new_rank , 'class' => $ admin -> getClass ( ) , ) ) ; }
|
Move a sortable item .
|
11,580
|
function bump ( $ user_id = 0 ) { global $ db , $ user ; $ current_time = time ( ) ; if ( $ user_id == 0 ) $ user_id = $ user -> data [ 'user_id' ] ; $ db -> sql_transaction ( 'begin' ) ; $ sql = 'UPDATE ' . POSTS_TABLE . " SET post_time = $current_time WHERE post_id = {$this->topic_last_post_id} AND topic_id = {$this->topic_id}" ; $ db -> sql_query ( $ sql ) ; $ this -> topic_bumped = 1 ; $ this -> topic_bumper = $ user_id ; $ this -> topic_last_post_time = $ current_time ; $ sql = 'UPDATE ' . TOPICS_TABLE . " SET topic_last_post_time = $current_time, topic_bumped = 1, topic_bumper = $user_id WHERE topic_id = $topic_id" ; $ db -> sql_query ( $ sql ) ; update_post_information ( 'forum' , $ this -> forum_id ) ; $ sql = 'UPDATE ' . USERS_TABLE . " SET user_lastpost_time = $current_time WHERE user_id = $user_id" ; $ db -> sql_query ( $ sql ) ; $ db -> sql_transaction ( 'commit' ) ; markread ( 'post' , $ this -> forum_id , $ this -> topic_id , $ current_time , $ user_id ) ; add_log ( 'mod' , $ this -> forum_id , $ this -> topic_id , 'LOG_BUMP_TOPIC' , $ this -> topic_title ) ; }
|
bumps the topic
|
11,581
|
public function version ( ) { $ json = ( string ) $ this -> client -> request ( 'GET' , '/' ) -> getBody ( ) ; $ value = JSONEncoder :: decode ( $ json ) ; return $ value [ 'version' ] ; }
|
Get the couchdb version .
|
11,582
|
public function listDatabases ( ) { $ json = ( string ) $ this -> client -> request ( 'GET' , '/_all_dbs' ) -> getBody ( ) ; $ databases = JSONEncoder :: decode ( $ json ) ; return $ databases ; }
|
Show all databases .
|
11,583
|
public function dropDatabase ( $ name ) { if ( $ this -> eventManager -> hasListeners ( Events :: PRE_DROP_DATABASE ) ) { $ this -> eventManager -> dispatchEvent ( Events :: PRE_DROP_DATABASE , new EventArgs ( $ this , $ name ) ) ; } $ response = $ this -> client -> request ( 'DELETE' , sprintf ( '/%s/' , urlencode ( $ name ) ) ) ; if ( 404 === $ response -> getStatusCode ( ) ) { throw new Exception ( sprintf ( 'The database "%s" does not exist' , $ name ) ) ; } $ json = ( string ) $ response -> getBody ( ) ; $ status = JSONEncoder :: decode ( $ json ) ; if ( $ this -> eventManager -> hasListeners ( Events :: POST_DROP_DATABASE ) ) { $ this -> eventManager -> dispatchEvent ( Events :: POST_DROP_DATABASE , new EventArgs ( $ this , $ name ) ) ; } return isset ( $ status [ 'ok' ] ) && $ status [ 'ok' ] === true ; }
|
Drop a database .
|
11,584
|
public function removeListener ( string $ eventName , $ listener ) : void { $ this -> dispatcher -> removeListener ( $ eventName , $ listener ) ; }
|
Remove event listener
|
11,585
|
public function removeListeners ( string $ eventName ) : void { foreach ( $ this -> dispatcher -> getListeners ( $ eventName ) as $ listener ) { $ this -> removeListener ( $ eventName , $ listener ) ; } }
|
Remove all event listeners
|
11,586
|
public function setTo ( $ to ) { $ attr = $ this -> createAttribute ( 'to' ) ; $ this -> doc -> appendChild ( $ attr ) ; $ attr -> appendChild ( $ this -> createTextNode ( $ to ) ) ; }
|
Sets the to jid of the message
|
11,587
|
public function setFrom ( $ from ) { $ attr = $ this -> createAttribute ( 'from' ) ; $ this -> doc -> appendChild ( $ attr ) ; $ attr -> appendChild ( $ this -> createTextNode ( $ from ) ) ; }
|
Sets the from jid of the message
|
11,588
|
public function addXML ( $ xml ) { $ next_elem = $ this -> createDocumentFragment ( ) ; $ next_elem -> appendXML ( $ xml ) ; $ this -> doc -> appendChild ( $ next_elem ) ; }
|
Adds an arbitrary XML string to the packet s root node
|
11,589
|
public function findBy ( array $ conditions ) { $ s = $ this -> selector ( ) ; foreach ( $ conditions as $ column => $ value ) { $ s -> where ( $ column , '=' , $ value ) ; } return $ s -> execute ( ) ; }
|
Select entities matching an array of conditions .
|
11,590
|
public function findOneBy ( array $ conditions ) { $ s = $ this -> selector ( ) -> one ( ) ; foreach ( $ conditions as $ column => $ value ) { $ s -> where ( $ column , '=' , $ value ) ; } return $ s -> execute ( ) ; }
|
Select a single entity matching an array of conditions .
|
11,591
|
public function captureMessage ( $ message , $ params = [ ] , $ data = [ ] , $ stack = false , $ vars = null ) { if ( ! Configure :: read ( 'CakeMonitor.Sentry.enabled' ) || error_reporting ( ) === 0 ) { return false ; } if ( is_callable ( Configure :: read ( 'CakeMonitor.Sentry.extraDataCallback' ) ) ) { $ data [ 'extra' ] [ 'extraDataCallback' ] = call_user_func ( Configure :: read ( 'CakeMonitor.Sentry.extraDataCallback' ) ) ; } return $ this -> _ravenClient -> captureMessage ( $ message , $ params , $ data , $ stack , $ vars ) ; }
|
Capture a message via sentry
|
11,592
|
protected function validate ( GeneratorData $ data ) { $ source = $ data -> getSource ( ) ; if ( ! ( is_array ( $ source ) && isset ( $ source [ self :: NODE_ACTIONS ] ) && is_array ( $ source [ self :: NODE_ACTIONS ] ) ) ) { throw new SyntaxException ( sprintf ( 'expected array with "%s" node' , self :: NODE_ACTIONS ) , $ source ) ; } $ actions = $ source [ self :: NODE_ACTIONS ] ; foreach ( $ actions as $ nodeNo => $ actionDefinition ) { if ( isset ( $ actionDefinition [ self :: PATH_ATTR ] ) ) { $ path = $ actionDefinition [ self :: PATH_ATTR ] ; unset ( $ actionDefinition [ self :: PATH_ATTR ] ) ; } else { $ path = self :: NODE_ACTIONS . '.' . $ nodeNo ; } if ( ! is_array ( $ actionDefinition ) ) { throw new SyntaxException ( 'expected array with action name as key' , $ actionDefinition , $ path ) ; } $ actionName = key ( $ actionDefinition ) ; $ arguments = is_array ( $ actionDefinition [ $ actionName ] ) ? $ actionDefinition [ $ actionName ] : [ $ actionDefinition [ $ actionName ] ] ; if ( strpos ( $ actionName , '@' ) !== 0 ) { throw new SyntaxException ( sprintf ( 'action name should start with "@" symbol, current name "%s"' , $ actionName ) , $ actionDefinition , $ path ) ; } $ this -> normalizeActionName ( $ actionName ) ; if ( ! $ this -> getHelper ( ) -> hasMethod ( $ actionName ) ) { throw new SyntaxException ( sprintf ( 'unknown action "%s", should be one of LayoutManipulatorInterface\'s methods' , $ actionName ) , $ actionDefinition , $ path ) ; } if ( ! $ this -> getHelper ( ) -> isValidArguments ( $ actionName , $ arguments ) ) { throw new SyntaxException ( $ this -> getHelper ( ) -> getLastError ( ) , $ actionDefinition , $ path ) ; } } }
|
Validates given resource data checks that actions node exists and consist valid actions .
|
11,593
|
private function flash ( $ type , $ message ) { $ flash = Session :: has ( $ type ) ? Session :: get ( $ type ) : array ( ) ; if ( ! in_array ( $ message , $ flash ) ) $ flash [ ] = $ message ; Session :: flash ( $ type , $ flash ) ; }
|
Flashes a Message to the Session .
|
11,594
|
public function mbox_exists ( $ name ) { if ( $ this -> is_connected ( ) && ! empty ( $ name ) ) { $ names = $ this -> get_all_names_mboxes ( ) ; if ( ! empty ( $ names ) && \ in_array ( $ name , $ names ) ) { return true ; } } return false ; }
|
Check if a mailbox exists
|
11,595
|
public function issueCreate ( $ title , $ description , $ assignee_email , $ labels = '' ) { $ post = [ 'id' => $ this -> id , 'title' => $ title , 'description' => $ description ] ; if ( $ assignee_email ) { $ user = new \ sb \ Gitlab \ User ( $ assignee_email , $ this -> _client ) ; $ post [ 'assignee_id' ] = $ user -> id ; } $ response = $ this -> _client -> get ( '/projects/' . $ this -> id . '/issues' , $ post ) ; if ( $ response ) { return \ sb \ Gitlab \ Issue :: fromObject ( $ response ) ; } }
|
Adds an issue to a git repository
|
11,596
|
public function issueClose ( \ sb \ Gitlab \ Issue $ issue ) { $ response = $ this -> _client -> get ( "/projects/" . $ this -> id . "/issues/" . $ issue -> id , [ 'state_event' => 'close' ] , 'PUT' ) ; if ( is_object ( $ response ) && isset ( $ response -> message ) ) { throw new \ Exception ( "Could not close issue " . $ issue -> id . " on project " . $ this -> id . ": " . json_encode ( $ response ) ) ; } return $ response ; }
|
Closes an issue by id within the project
|
11,597
|
public static function fromObject ( $ object ) { $ issue = new \ sb \ Gitlab \ P ( ) ; foreach ( get_object_vars ( $ object ) as $ k => $ v ) { switch ( $ k ) { case 'assignee' : case 'author' : if ( ! is_object ( $ v ) ) { $ issue -> { $ k } = $ v ; break ; } $ user = new \ sb \ Gitlab \ User ( ) ; foreach ( get_object_vars ( $ v ) as $ uk => $ uv ) { $ user -> { $ uk } = $ uv ; } $ issue -> { $ k } = $ user ; break ; default : $ issue -> { $ k } = $ v ; } } return $ issue ; }
|
Convert stdClass Object to actual \ sb \ Gitlab \ Issue
|
11,598
|
public function put ( $ url , $ params = null ) { $ this -> params = $ params ; $ this -> method = 'PUT' ; $ this -> url = $ url ; return $ this -> request ( ) ; }
|
Make a PUT query
|
11,599
|
public function post ( $ url , $ params = null ) { $ this -> params = $ params ; $ this -> method = 'POST' ; $ this -> url = $ url ; return $ this -> request ( ) ; }
|
Make a POST query
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.