idx
int64 0
60.3k
| question
stringlengths 64
4.24k
| target
stringlengths 5
618
|
|---|---|---|
2,200
|
public function applyCookies ( $ cookies ) { $ headers = $ this -> headers ( ) ; foreach ( $ cookies as $ cookie ) { $ headers [ 'Set-Cookie' ] [ ] = $ cookie -> toString ( ) ; } return $ this ; }
|
Set the Set - Cookie header
|
2,201
|
public function cookies ( $ request ) { $ headers = $ response -> headers ( ) ; if ( ! isset ( $ headers [ 'Set-Cookie' ] ) ) { return [ ] ; } $ setCookies = [ ] ; foreach ( $ headers [ 'Set-Cookie' ] as $ setCookieHeader ) { $ setCookie = Cookie :: fromString ( $ setCookieHeader ) ; if ( ! $ setCookie -> domain ( ) ) { $ setCookie -> domain ( $ request -> hostname ( ) ) ; } if ( strpos ( $ setCookie -> path ( ) , '/' ) !== 0 ) { $ setCookie -> path ( $ this -> _pathFrom ( $ request ) ) ; } $ setCookies [ ] = $ setCookie ; } return $ setCookies ; }
|
Extract cookies .
|
2,202
|
public function redirect ( $ location , $ status = 302 ) { if ( ! $ location ) { return ; } $ this -> status ( $ status ) ; $ headers = $ this -> headers ( ) ; $ headers [ 'Location' ] = $ location ; return $ this ; }
|
Set a redirect location .
|
2,203
|
public function export ( $ options = [ ] ) { $ this -> _setContentLength ( ) ; return [ 'status' => $ this -> status ( ) , 'version' => $ this -> version ( ) , 'headers' => $ this -> headers ( ) , 'body' => $ this -> stream ( ) ] ; }
|
Exports a Response instance to an array .
|
2,204
|
public static function parse ( $ message , $ options = [ ] ) { $ parts = explode ( "\r\n\r\n" , $ message , 2 ) ; if ( count ( $ parts ) < 2 ) { throw new NetException ( "The CRLFCRLF separator between headers and body is missing." ) ; } $ response = new static ( $ options + [ 'format' => null ] ) ; list ( $ header , $ body ) = $ parts ; $ data = str_replace ( "\r" , '' , explode ( "\n" , $ header ) ) ; $ data = array_filter ( $ data ) ; preg_match ( '/HTTP\/(\d+\.\d+)\s+(\d+)(?:\s+(.*))?/i' , array_shift ( $ data ) , $ matches ) ; $ headers = $ response -> headers ( ) ; $ headers -> push ( $ data ) ; if ( $ matches ) { $ response -> version ( $ matches [ 1 ] ) ; $ response -> status ( [ $ matches [ 2 ] , isset ( $ matches [ 3 ] ) ? $ matches [ 3 ] : '' ] ) ; } if ( $ headers [ 'Transfer-Encoding' ] -> value ( ) === 'chunked' ) { $ decoded = '' ; while ( ! empty ( $ body ) ) { $ pos = strpos ( $ body , "\r\n" ) ; $ len = hexdec ( substr ( $ body , 0 , $ pos ) ) ; $ decoded .= substr ( $ body , $ pos + 2 , $ len ) ; $ body = substr ( $ body , $ pos + 2 + $ len ) ; } $ body = $ decoded ; } $ response -> body ( $ body ) ; return $ response ; }
|
Creates a response instance from an entire HTTP message including HTTP status headers and body .
|
2,205
|
public static function encode ( $ body , $ encoding , $ wrapWidth = 76 , $ le = "\r\n" , $ cut = false ) { $ encoding = strtolower ( $ encoding ) ; switch ( $ encoding ) { case 'quoted-printable' : $ body = quoted_printable_encode ( $ body ) ; return $ wrapWidth ? rtrim ( chunk_split ( $ body , $ wrapWidth , $ le ) ) : $ body ; break ; case 'base64' : $ body = base64_encode ( $ body ) ; return $ wrapWidth ? rtrim ( chunk_split ( $ body , $ wrapWidth , $ le ) ) : $ body ; break ; case '7bit' : if ( preg_match ( '~[^\x00-\x7F]~' , $ body ) ) { throw new RuntimeException ( "Can't use `'{$encoding}'` encoding, non 7 bit characters detected." ) ; } case '8bit' : case 'binary' : $ body = ltrim ( str_replace ( "\r" , '' , $ body ) , "\n" ) ; return $ wrapWidth ? wordwrap ( $ body , $ wrapWidth , "\n" , $ cut ) : $ body ; break ; default : throw new InvalidArgumentException ( "Unsupported encoding `'{$encoding}'`." ) ; break ; } }
|
Encoding method .
|
2,206
|
public static function encodeEmail ( $ email ) { if ( ( $ pos = strpos ( $ email , '@' ) ) === false ) { return ; } if ( ! preg_match ( '~[\x80-\xFF]~' , $ email ) ) { return $ email ; } $ domain = substr ( $ email , ++ $ pos ) ; return substr ( $ email , 0 , $ pos ) . idn_to_ascii ( $ domain , 0 , INTL_IDNA_VARIANT_UTS46 ) ; }
|
Punycode email address to its ASCII form also known as punycode .
|
2,207
|
public static function encodeValue ( $ value , $ wrapWidth = 998 , $ folding = "\r\n " ) { if ( ! preg_match ( '~[^\x00-\x7F]~' , $ value ) ) { $ encoding = '7bit' ; } elseif ( preg_match_all ( '/[\000-\010\013\014\016-\037\177-\377]/' , $ value ) > ( strlen ( $ value ) / 3 ) ) { $ encoding = 'base64' ; } else { $ encoding = 'quoted-printable' ; } $ encodedName = Mime :: encode ( $ value , $ encoding , $ wrapWidth , $ folding , true ) ; $ value = trim ( str_replace ( [ "\r" , "\n" ] , '' , $ value ) ) ; if ( $ encoding === 'base64' ) { $ encodedName = "=?UTF-8?B?{$encodedName}?=" ; } elseif ( $ encoding === 'quoted-printable' ) { $ encodedName = "=?UTF-8?Q?{$encodedName}?=" ; } else { $ encodedName = addcslashes ( $ encodedName , "\0..\37\177\\\"" ) ; if ( $ encodedName !== $ value || preg_match ( '/[^A-Za-z0-9!#$%&\'*+\/=?^_`{|}~ -]/' , $ value ) === 1 ) { $ encodedName = sprintf ( '"%s"' , $ encodedName ) ; } } return $ encodedName ; }
|
MIME - encode a value to its mots suitable format
|
2,208
|
function getEndpoint ( ) { $ endpoint = $ this -> endpointBase ; if ( $ this -> spaceId ) { $ endpoint .= '/' . $ this -> spaceId ; } return $ endpoint ; }
|
Get the endpoint .
|
2,209
|
function build_url ( $ resource , array $ query = array ( ) ) { $ url = $ this -> getEndpoint ( ) ; if ( $ resource && $ this -> spaceId ) $ url .= '/' ; if ( $ resource ) $ url .= $ resource ; if ( ! empty ( $ query ) ) $ url .= '?' . http_build_query ( $ query ) ; return $ url ; }
|
Build the query URL .
|
2,210
|
function buildCacheKey ( $ method , $ resource , $ url , $ headers = array ( ) , $ query = array ( ) ) { return md5 ( $ method . $ resource . $ url . json_encode ( $ query ) . json_encode ( $ headers ) ) ; }
|
Return a unique key for the query .
|
2,211
|
public function autoAddToObjects ( ) { $ modelClassName = PropertiesHelper :: classNameForApplicablePropertyModelId ( $ this -> applicable_property_model_id ) ; $ modelIdsWithoutGroup = $ modelClassName :: find ( ) -> leftJoin ( $ modelClassName :: bindedPropertyGroupsTable ( ) . ' bpg' , 'bpg.model_id = id' ) -> where ( 'bpg.model_id IS NULL' ) -> select ( 'id' ) -> column ( $ modelClassName :: getDb ( ) ) ; $ insertRows = array_map ( function ( $ item ) { return [ $ item , $ this -> id ] ; } , $ modelIdsWithoutGroup ) ; if ( count ( $ insertRows ) > 0 ) { $ modelClassName :: getDb ( ) -> createCommand ( ) -> batchInsert ( $ modelClassName :: bindedPropertyGroupsTable ( ) , [ 'model_id' , 'property_group_id' , ] , $ insertRows ) -> execute ( ) ; } }
|
Finds new applicable models and binds this group to them
|
2,212
|
public function search ( $ applicablePropertyModelId , $ params , $ showHidden = false ) { $ query = self :: find ( ) -> where ( [ 'applicable_property_model_id' => $ applicablePropertyModelId , ] ) ; $ dataProvider = new ActiveDataProvider ( [ 'query' => $ query , 'pagination' => [ 'pageSize' => 10 , ] , ] ) ; $ dataProvider -> sort -> attributes [ 'name' ] = [ 'asc' => [ 'property_group_translation.name' => SORT_ASC ] , 'desc' => [ 'property_group_translation.name' => SORT_DESC ] , ] ; if ( ! ( $ this -> load ( $ params ) ) ) { if ( $ showHidden === false ) { $ this -> is_deleted = 0 ; $ query -> andWhere ( [ 'is_deleted' => $ this -> is_deleted ] ) ; } return $ dataProvider ; } $ query -> andFilterWhere ( [ 'id' => $ this -> id ] ) ; $ query -> andFilterWhere ( [ 'like' , 'internal_name' , $ this -> internal_name ] ) ; $ query -> andFilterWhere ( [ 'is_auto_added' => $ this -> is_auto_added ] ) ; $ query -> andFilterWhere ( [ 'is_deleted' => $ this -> is_deleted ] ) ; $ query -> andFilterWhere ( [ 'like' , 'property_group_translation.name' , $ this -> name ] ) ; return $ dataProvider ; }
|
Returns ActiveDataProvider for searching PropertyGroup models
|
2,213
|
public function string ( $ str = null ) { if ( $ str !== null ) { foreach ( $ this -> childScanners as $ s ) { $ s -> string ( $ str ) ; } } return parent :: string ( $ str ) ; }
|
override string to hit the child scanners as well
|
2,214
|
public function configurationAction ( ) { $ redirect = $ this -> getRedirect ( ) ; $ installation = $ this -> getInstallation ( ) ; $ step = $ installation -> getCurrentStep ( ) ; $ member = $ step -> getCurrentMember ( ) ; $ validator = $ this -> getValidator ( ) ; if ( ! $ validator instanceof PhpIni ) { throw new DomainException ( sprintf ( $ this -> scTranslate ( "An error occurred while installing the module '%s', step '%s', member '%s'. " . "Validator must be an instance of class '%s', '%s' instead." ) , $ installation -> getModuleName ( ) , $ step -> getName ( ) , $ member -> getName ( ) , 'ScContent\Validator\Installation\PhpIni' , is_object ( $ validator ) ? get_class ( $ validator ) : gettype ( $ validator ) ) ) ; } $ failures = [ ] ; foreach ( $ member as $ requirement ) { if ( ! $ validator -> isValid ( $ requirement ) ) { if ( ! isset ( $ requirement [ 'failure_message' ] ) ) { throw new InvalidArgumentException ( sprintf ( $ this -> scTranslate ( "An error occurred while installing the module '%s', step '%s', member '%s'. " . "Missing option 'failure_message' for '%s' param." ) , $ installation -> getModuleName ( ) , $ step -> getName ( ) , $ member -> getName ( ) , $ requirement [ 'name' ] ) ) ; } $ failures [ ] = [ $ requirement [ 'name' ] , ( false === $ validator -> getValueFromCallback ( $ requirement [ 'name' ] ) ) ? 'false' : $ validator -> getValueFromCallback ( $ requirement [ 'name' ] ) , $ requirement [ 'failure_message' ] ] ; } } if ( ! empty ( $ failures ) ) { return new ViewModel ( [ 'errors' => [ 'table' => [ 'head' => [ 'Php.ini option' , 'Value' , 'Requirement' ] , 'body' => $ failures ] ] ] ) ; } return $ this -> redirect ( ) -> toUrl ( $ redirect ) ; }
|
Checks the settings in the php . ini file in accordance with the configuration of the module . If the settings are not compatible the installation process stops and displays the information message .
|
2,215
|
protected function combineTo ( Swift_Mime_SimpleMessage $ message ) { return array_merge ( ( array ) $ message -> getTo ( ) , ( array ) $ message -> getCc ( ) , ( array ) $ message -> getBcc ( ) ) ; }
|
Combine all contacts for the message .
|
2,216
|
protected function prepareTo ( Swift_Mime_SimpleMessage $ message ) { $ to = array_map ( function ( $ name , $ address ) { return $ name ? $ name . " <{$address}>" : $ address ; } , $ this -> combineTo ( $ message ) , array_keys ( $ this -> combineTo ( $ message ) ) ) ; return implode ( ',' , $ to ) ; }
|
Format the to addresses to match Mailgun message . mime format .
|
2,217
|
protected function extractToken ( ) { if ( $ this -> request -> input ( 'token' ) === false ) { if ( ! $ this -> request -> getHeader ( 'X-JS-CLIENTS-TOKEN' ) ) { return 'token' ; } return $ this -> request -> getHeader ( 'X-JS-CLIENTS-TOKEN' ) ; } return $ this -> request -> input ( 'token' ) ; }
|
extract token from form or JavaScript Clients like Axios Ajax JQuery .
|
2,218
|
public static function getInstance ( ) { if ( ! static :: $ instance instanceof self ) { static :: $ instance = $ session = new self ( ) ; if ( ! $ session -> isStarted ( ) ) { $ session -> start ( ) ; } } return static :: $ instance ; }
|
Session singleton .
|
2,219
|
public function createFlashMessage ( $ key , $ value ) { $ session = static :: getInstance ( ) ; $ session -> getFlashBag ( ) -> add ( $ key , $ value ) ; }
|
Add flash message .
|
2,220
|
public function getFlashMessage ( $ key ) { $ session = static :: getInstance ( ) ; foreach ( $ session -> getFlashBag ( ) -> get ( $ key , [ ] ) as $ message ) { return $ message ? : null ; } return '' ; }
|
Get message from flash bag .
|
2,221
|
public function getURL ( $ start_timestamp = 0 , $ calendar_guid = 0 ) { if ( ! $ start_timestamp ) { $ start_timestamp = $ this -> getNextOccurrence ( ) ; } $ url = parent :: getURL ( ) ; return elgg_http_add_url_query_elements ( $ url , array_filter ( array ( 'ts' => $ start_timestamp , 'calendar' => $ calendar_guid , ) ) ) ; }
|
Returns canonical URL with instance start time added as query element
|
2,222
|
public function getCalendars ( $ params = array ( ) , $ public = false ) { $ defaults = array ( 'type' => 'object' , 'subtype' => 'calendar' , 'relationship' => Calendar :: EVENT_CALENDAR_RELATIONSHIP , 'relationship_guid' => $ this -> guid , 'limit' => false ) ; $ options = array_merge ( $ defaults , $ params ) ; if ( $ public ) { $ options [ 'metadata_name_value_pairs' ] [ ] = array ( 'name' => '__public_calendar' , 'value' => true ) ; } if ( $ options [ 'count' ] ) { return elgg_get_entities_from_relationship ( $ options ) ; } return new ElggBatch ( 'elgg_get_entities_from_relationship' , $ options ) ; }
|
Get all calendars this event is on
|
2,223
|
public function move ( $ params ) { $ this -> all_day = elgg_extract ( 'all_day' , $ params , false ) ; $ this -> start_timestamp = $ params [ 'new_start_timestamp' ] ; $ this -> end_timestamp = $ params [ 'new_end_timestamp' ] ; $ this -> start_date = $ params [ 'new_start_date' ] ; $ this -> end_date = $ params [ 'new_end_date' ] ; $ this -> start_time = $ params [ 'new_start_time' ] ; $ this -> end_time = $ params [ 'new_end_time' ] ; $ this -> end_delta = $ params [ 'new_end_timestamp' ] - $ params [ 'new_start_timestamp' ] ; $ this -> repeat_end_timestamp = $ this -> calculateRepeatEndTimestamp ( ) ; $ time = time ( ) ; $ this -> removeReminders ( null , null , true ) ; $ this -> buildReminders ( $ time , $ time + ( Util :: SECONDS_IN_A_DAY * 2 ) ) ; return true ; }
|
Perform a move action with calculated parameters
|
2,224
|
public function resize ( $ params ) { $ this -> end_timestamp = $ params [ 'new_end_timestamp' ] ; $ this -> end_date = $ params [ 'new_end_date' ] ; $ this -> end_time = $ params [ 'new_end_time' ] ; $ this -> end_delta = $ params [ 'new_end_timestamp' ] - $ this -> getStartTimestamp ( ) ; $ this -> repeat_end_timestamp = $ this -> calculateRepeatEndTimestamp ( ) ; return true ; }
|
Extends event duration
|
2,225
|
public function getMoveParams ( $ day_delta , $ minute_delta , $ all_day = false ) { $ start_timestamp = $ this -> getStartTimestamp ( ) ; $ end_timestamp = $ this -> getEndTimestamp ( ) ; $ time_diff = $ end_timestamp - $ start_timestamp ; $ new_start_timestamp = $ start_timestamp + ( $ day_delta * Util :: SECONDS_IN_A_DAY ) + ( $ minute_delta * Util :: SECONDS_IN_A_MINUTE ) ; $ new_end_timestamp = $ new_start_timestamp + $ time_diff ; $ params = array ( 'entity' => $ this , 'new_start_timestamp' => $ new_start_timestamp , 'new_end_timestamp' => $ new_end_timestamp , 'new_start_date' => date ( 'Y-m-d' , $ new_start_timestamp ) , 'new_end_date' => date ( 'Y-m-d' , $ new_end_timestamp ) , 'new_start_time' => date ( 'g:ia' , $ new_start_timestamp ) , 'new_end_time' => date ( 'g:ia' , $ new_end_timestamp ) , 'all_day' => $ all_day ) ; return $ params ; }
|
Calculates parameters for a move action
|
2,226
|
public function getResizeParams ( $ day_delta = 0 , $ minute_delta = 0 ) { $ end_timestamp = $ this -> getEndTimestamp ( ) ; $ new_end_timestamp = $ end_timestamp + ( $ day_delta * Util :: SECONDS_IN_A_DAY ) + ( $ minute_delta * Util :: SECONDS_IN_A_MINUTE ) ; $ params = array ( 'entity' => $ this , 'new_end_timestamp' => $ new_end_timestamp , 'new_end_date' => date ( 'Y-m-d' , $ new_end_timestamp ) , 'new_end_time' => date ( 'g:ia' , $ new_end_timestamp ) ) ; return $ params ; }
|
Calculates parameters for the resize action
|
2,227
|
public function calculateRepeatEndTimestamp ( ) { switch ( $ this -> repeat_end_type ) { case Util :: REPEAT_END_ON : $ repeat_end_timestamp = strtotime ( $ this -> repeat_end_on ) ; if ( $ repeat_end_timestamp === false ) { $ repeat_end_timestamp = 0 ; } $ return = $ repeat_end_timestamp ; break ; case Util :: REPEAT_END_AFTER : $ return = $ this -> calculateEndAfterTimestamp ( $ this -> repeat_end_after ) ; break ; case Util :: REPEAT_END_NEVER : $ return = 0 ; break ; default : if ( $ this -> repeat ) { $ return = 0 ; } else { $ return = $ this -> getStartTimestamp ( ) ; } break ; } if ( $ return && $ return < $ this -> getEndTimestamp ( ) ) { $ return = $ this -> getEndTimestamp ( ) ; } return $ return ; }
|
Calculates and returns the last timestamp for event recurrences
|
2,228
|
public function getNextOccurrence ( $ after_timestamp = null ) { if ( $ after_timestamp === null ) { $ after_timestamp = time ( ) ; } $ after_timestamp = ( int ) $ after_timestamp ; $ next = false ; if ( $ this -> isRecurring ( ) ) { $ next = $ this -> calculateEndAfterTimestamp ( 1 , $ after_timestamp , false ) ; } else if ( $ after_timestamp < $ this -> getStartTimestamp ( ) ) { $ next = $ this -> getStartTimestamp ( ) ; } if ( $ this -> repeat_end_timestamp && $ this -> repeat_end_timestamp < $ next ) { return false ; } return $ next ; }
|
Returns the start timestamp of the next event occurence Returns false if there are no future occurrences
|
2,229
|
public function getLastOccurrence ( $ before_timestamp = null ) { if ( $ before_timestamp === null ) { $ before_timestamp = time ( ) ; } $ before_timestamp = ( int ) $ before_timestamp ; $ prev = false ; if ( $ this -> isRecurring ( ) ) { $ starttimes = $ this -> getStartTimes ( $ this -> getStartTimestamp ( ) , $ before_timestamp ) ; if ( $ starttimes ) { $ prev = end ( $ starttimes ) ; } } else { $ prev = $ this -> getStartTimestamp ( ) ; if ( $ prev > $ before_timestamp ) { $ prev = false ; } } return $ prev ; }
|
Returns the timestamp of the previous event occurence Returns false if there are no past occurrences
|
2,230
|
public function buildReminders ( $ starttime , $ endtime ) { if ( ! $ this -> hasReminders ( ) ) { return true ; } $ starttime = sanitize_int ( $ starttime ) ; $ endtime = sanitize_int ( $ endtime ) ; $ this -> removeReminders ( $ starttime , $ endtime ) ; $ reminders = elgg_get_metadata ( array ( 'guid' => $ this -> guid , 'metadata_name' => 'reminder' , 'limit' => false ) ) ; $ starttimes = $ this -> getStartTimes ( $ starttime , $ endtime ) ; foreach ( $ starttimes as $ s ) { foreach ( $ reminders as $ r ) { $ reminder = $ s - $ r -> value ; if ( $ reminder < time ( ) ) { continue ; } $ this -> annotate ( 'reminder' , $ s - $ r -> value , ACCESS_PUBLIC ) ; } } return true ; }
|
Creates reminder annotations for this event
|
2,231
|
public function indexAction ( ) { if ( ! $ this -> params ( ) -> fromRoute ( 'process' ) ) { return new ViewModel ( ) ; } $ installation = $ this -> getInstallation ( ) ; $ redirect = $ this -> getRedirect ( ) ; $ step = $ installation -> getCurrentStep ( ) ; $ member = $ step -> getCurrentMember ( ) ; $ service = $ this -> getService ( ) ; $ validator = $ this -> getValidator ( ) ; foreach ( $ member as $ item ) { if ( ! $ validator -> isValid ( $ item ) ) { if ( ! $ service -> process ( $ item ) ) { return new ViewModel ( [ 'errors' => $ service -> getMessages ( ) ] ) ; } } } return $ this -> redirect ( ) -> toUrl ( $ redirect ) ; }
|
Runs services specified in the configuration .
|
2,232
|
public function getAllEvents ( $ starttime = null , $ endtime = null ) { if ( is_null ( $ starttime ) ) { $ starttime = time ( ) ; } if ( is_null ( $ endtime ) ) { $ endtime = strtotime ( '+1 year' , $ starttime ) ; } $ starttime = sanitize_int ( $ starttime ) ; $ endtime = sanitize_int ( $ endtime ) ; $ relationship_name = sanitize_string ( self :: EVENT_CALENDAR_RELATIONSHIP ) ; $ dbprefix = elgg_get_config ( 'dbprefix' ) ; $ mds_name = elgg_get_metastring_id ( 'start_timestamp' ) ; $ mdre_name = elgg_get_metastring_id ( 'repeat_end_timestamp' ) ; $ options = array ( 'type' => 'object' , 'subtype' => Event :: SUBTYPE , 'joins' => array ( "JOIN {$dbprefix}entity_relationships er ON er.guid_one = e.guid" , "JOIN {$dbprefix}metadata mds ON mds.entity_guid = e.guid" , "JOIN {$dbprefix}metastrings mss ON mss.id = mds.value_id" , "JOIN {$dbprefix}metadata mdre ON mdre.entity_guid = e.guid" , "JOIN {$dbprefix}metastrings msre ON msre.id = mdre.value_id" ) , 'wheres' => array ( "er.guid_two = {$this->guid} AND er.relationship = '{$relationship_name}'" , "mds.name_id = {$mds_name}" , "mdre.name_id = {$mdre_name}" , "((CAST(mss.string AS SIGNED) < {$endtime}) AND (CAST(msre.string AS SIGNED) > {$starttime} OR CAST(msre.string AS SIGNED) = 0))" ) , 'limit' => false ) ; return new ElggBatch ( 'elgg_get_entities' , $ options ) ; }
|
Returns all event objects
|
2,233
|
public static function compareInstancesByStartTime ( $ a , $ b ) { $ start_a = $ a -> getStartTimestamp ( ) ; $ start_b = $ b -> getStartTimestamp ( ) ; if ( $ start_a == $ start_b ) { return 0 ; } return ( $ start_a < $ start_b ) ? - 1 : 1 ; }
|
Compares two event instances by start time
|
2,234
|
public function getRecurringEvents ( $ starttime = null , $ endtime = null ) { if ( is_null ( $ starttime ) ) { $ starttime = time ( ) ; } if ( is_null ( $ endtime ) ) { $ endtime = strtotime ( '+1 year' , $ starttime ) ; } $ starttime = sanitize_int ( $ starttime ) ; $ endtime = sanitize_int ( $ endtime ) ; $ relationship_name = sanitize_string ( self :: EVENT_CALENDAR_RELATIONSHIP ) ; $ dbprefix = elgg_get_config ( 'dbprefix' ) ; $ mdr_name = elgg_get_metastring_id ( 'repeat' ) ; $ mdr_val = elgg_get_metastring_id ( 1 ) ; $ mds_name = elgg_get_metastring_id ( 'start_timestamp' ) ; $ mdre_name = elgg_get_metastring_id ( 'repeat_end_timestamp' ) ; $ options = array ( 'type' => 'object' , 'subtype' => Event :: SUBTYPE , 'joins' => array ( "JOIN {$dbprefix}entity_relationships er ON er.guid_one = e.guid" , "JOIN {$dbprefix}metadata mdr ON mdr.entity_guid = e.guid" , "JOIN {$dbprefix}metadata mds ON mds.entity_guid = e.guid" , "JOIN {$dbprefix}metastrings mss ON mss.id = mds.value_id" , "JOIN {$dbprefix}metadata mdre ON mdre.entity_guid = e.guid" , "JOIN {$dbprefix}metastrings msre ON msre.id = mdre.value_id" ) , 'wheres' => array ( "er.guid_two = {$this->guid} AND er.relationship = '{$relationship_name}'" , "mdr.name_id = {$mdr_name} AND mdr.value_id = {$mdr_val}" , "mds.name_id = {$mds_name}" , "mdre.name_id = {$mdre_name}" , "((CAST(mss.string AS SIGNED) < {$endtime}) AND (CAST(msre.string AS SIGNED) > {$starttime} OR CAST(msre.string AS SIGNED) = 0))" ) , 'limit' => false ) ; $ events = new ElggBatch ( 'elgg_get_entities' , $ options ) ; $ recurring_events = array ( ) ; foreach ( $ events as $ event ) { if ( $ event -> getStartTimes ( $ starttime , $ endtime ) ) { $ recurring_events [ ] = $ event ; } } return $ recurring_events ; }
|
Returns a batch of recurring events in a given time range
|
2,235
|
public function getOneTimeEvents ( $ starttime = null , $ endtime = null ) { if ( is_null ( $ starttime ) ) { $ starttime = time ( ) ; } if ( is_null ( $ endtime ) ) { $ endtime = strtotime ( '+1 year' , $ starttime ) ; } $ starttime = sanitize_int ( $ starttime ) ; $ endtime = sanitize_int ( $ endtime ) ; $ relationship_name = sanitize_string ( self :: EVENT_CALENDAR_RELATIONSHIP ) ; $ dbprefix = elgg_get_config ( 'dbprefix' ) ; $ mdr_name = elgg_get_metastring_id ( 'repeat' ) ; $ mdr_val = elgg_get_metastring_id ( 0 ) ; $ mds_name = elgg_get_metastring_id ( 'start_timestamp' ) ; $ mde_name = elgg_get_metastring_id ( 'end_timestamp' ) ; $ options = array ( 'type' => 'object' , 'subtype' => Event :: SUBTYPE , 'joins' => array ( "JOIN {$dbprefix}entity_relationships er ON er.guid_one = e.guid" , "JOIN {$dbprefix}metadata mdr ON mdr.entity_guid = e.guid" , "JOIN {$dbprefix}metadata mds ON mds.entity_guid = e.guid" , "JOIN {$dbprefix}metastrings mss ON mss.id = mds.value_id" , "JOIN {$dbprefix}metadata mde ON mde.entity_guid = e.guid" , "JOIN {$dbprefix}metastrings mse ON mse.id = mde.value_id" ) , 'wheres' => array ( "er.guid_two = {$this->guid} AND er.relationship = '{$relationship_name}'" , "mdr.name_id = {$mdr_name} AND mdr.value_id = {$mdr_val}" , "mds.name_id = {$mds_name}" , "mde.name_id = {$mde_name}" , "((CAST(mss.string AS SIGNED) BETWEEN {$starttime} AND {$endtime}) OR (CAST(mse.string AS SIGNED) BETWEEN {$starttime} AND {$endtime}))" ) , 'limit' => false ) ; return new ElggBatch ( 'elgg_get_entities' , $ options ) ; }
|
Returns one - time events
|
2,236
|
public function hasEvent ( $ event ) { return ( bool ) check_entity_relationship ( $ event -> guid , self :: EVENT_CALENDAR_RELATIONSHIP , $ this -> guid ) ; }
|
Checks if the event is on calendar
|
2,237
|
public function getIcalURL ( $ base_url = '' , array $ params = array ( ) ) { $ user = elgg_get_logged_in_user_entity ( ) ; $ params [ 'view' ] = 'ical' ; $ params [ 'u' ] = $ user -> guid ; $ params [ 't' ] = $ this -> getUserToken ( $ user -> guid ) ; $ url = elgg_http_add_url_query_elements ( $ base_url , $ params ) ; return elgg_normalize_url ( $ url ) ; }
|
Returns a URL of the iCal feed
|
2,238
|
public function toIcal ( $ starttime = null , $ endtime = null , $ filename = 'calendar.ics' ) { if ( is_null ( $ starttime ) ) { $ starttime = time ( ) ; } if ( is_null ( $ endtime ) ) { $ endtime = strtotime ( '+1 year' , $ starttime ) ; } $ instances = $ this -> getAllEventInstances ( $ starttime , $ endtime , true , 'ical' ) ; $ config = array ( 'unique_id' => $ this -> guid , 'allowEmpty' => true , 'nl' => "\r\n" , 'format' => 'iCal' , 'delimiter' => DIRECTORY_SEPARATOR , 'filename' => $ filename , ) ; $ v = new vcalendar ( $ config ) ; $ v -> setProperty ( 'method' , 'PUBLISH' ) ; $ v -> setProperty ( "X-WR-CALNAME" , implode ( ' - ' , array ( elgg_get_config ( 'sitename' ) , $ this -> getDisplayName ( ) ) ) ) ; $ v -> setProperty ( "X-WR-CALDESC" , strip_tags ( $ this -> description ) ) ; $ v -> setProperty ( "X-WR-TIMEZONE" , Util :: UTC ) ; foreach ( $ instances as $ instance ) { $ e = & $ v -> newComponent ( 'vevent' ) ; $ organizer = elgg_extract ( 'organizer' , $ instance , array ( ) ) ; unset ( $ instance [ 'organizer' ] ) ; $ reminders = elgg_extract ( 'reminders' , $ instance , array ( ) ) ; unset ( $ instance [ 'reminders' ] ) ; foreach ( $ instance as $ property => $ value ) { $ e -> setProperty ( $ property , $ value ) ; } if ( ! empty ( $ organizer ) ) { if ( is_email_address ( $ organizer ) ) { $ e -> setProperty ( 'organizer' , $ organizer ) ; } else { $ e -> setProperty ( 'organizer' , elgg_get_site_entity ( ) -> email , array ( 'CN' => $ organizer , ) ) ; } } if ( ! empty ( $ reminders ) ) { foreach ( $ reminders as $ reminder ) { $ a = & $ e -> newComponent ( 'valarm' ) ; $ a -> setProperty ( 'action' , 'DISPLAY' ) ; $ a -> setProperty ( 'trigger' , "-PT{$reminder}S" ) ; } } } $ v -> returnCalendar ( ) ; }
|
Returns an iCal feed for this calendar
|
2,239
|
public static function createPublicCalendar ( $ container ) { if ( ! $ container instanceof ElggEntity ) { return false ; } try { $ calendar = new Calendar ( ) ; $ calendar -> access_id = ACCESS_PUBLIC ; $ calendar -> owner_guid = $ container -> guid ; $ calendar -> container_guid = $ container -> guid ; $ calendar -> __public_calendar = true ; $ ia = elgg_set_ignore_access ( true ) ; $ calendar -> save ( ) ; elgg_set_ignore_access ( $ ia ) ; elgg_log ( "Created public calendar for $container->name [$container->guid]" , 'NOTICE' ) ; } catch ( Exception $ ex ) { elgg_log ( $ ex -> getMessage ( ) , 'ERROR' ) ; } return $ calendar ; }
|
Creates a public calendar for a container
|
2,240
|
public static function getCalendars ( $ container , $ count = false ) { if ( ! $ container instanceof ElggEntity ) { return false ; } $ options = array ( 'type' => 'object' , 'subtype' => 'calendar' , 'container_guid' => $ container -> guid , 'limit' => false ) ; if ( $ count ) { $ options [ 'count' ] = true ; return elgg_get_entities ( $ options ) ; } return new ElggBatch ( 'elgg_get_entities' , $ options ) ; }
|
Retrieves all calendars for a container
|
2,241
|
public static function getPublicCalendar ( $ container ) { if ( ! $ container instanceof ElggEntity ) { return false ; } $ calendars = elgg_get_entities ( array ( 'type' => 'object' , 'subtype' => Calendar :: SUBTYPE , 'container_guid' => $ container -> guid , 'limit' => 1 , 'metadata_name_value_pairs' => array ( 'name' => '__public_calendar' , 'value' => true , ) , 'order_by' => 'e.time_created ASC' , ) ) ; return ( empty ( $ calendars ) ) ? Calendar :: createPublicCalendar ( $ container ) : $ calendars [ 0 ] ; }
|
Retrieves user s or group s public calendar
|
2,242
|
public function getMemberships ( Communicator $ communicator = null ) : ClassValidationArray { if ( $ communicator !== null ) { $ membershipJSON = $ communicator -> get ( "api/groups/" . $ this -> groupID . "/memberships" ) ; $ membershipStd = json_decode ( $ membershipJSON ) ; $ memberships = [ ] ; foreach ( $ membershipStd as $ value ) { $ memberships [ ] = RecipientFactory :: createProcessedMembershipFromStdClass ( $ value ) ; } $ this -> memberships = $ memberships ; $ this -> fetchedMemberships = true ; } return $ this -> memberships ; }
|
Returns an array of all the memberships the group is referenced in . If a communicator is not provided it will not fetch memberships from the API but return those that has been fetched if any .
|
2,243
|
public function getContacts ( Communicator $ communicator = null ) : ClassValidationArray { if ( $ communicator !== null ) { $ contactStd = $ communicator -> get ( 'api/groups/' . $ this -> groupID . '/contacts' ) ; $ contactStd = json_decode ( $ contactStd ) ; $ contacts = RecipientFactory :: createProcessedGroupsFromStdClassArray ( $ contactStd ) ; $ this -> contacts = $ contacts ; $ this -> contactsFetched = true ; } return $ this -> contacts ; }
|
Returns an array of all the Contacts that belong to the Group . If a communicator is not provided it will not fetch Contacts from the API but return those that has been fetched if any .
|
2,244
|
public function openHandler ( & $ parser , $ name , $ attrs , $ closed ) { foreach ( $ attrs as $ key => $ attr ) { $ attrs [ $ key ] = $ this -> parseData ( $ attr ) ; } if ( $ closed ) { $ this -> tokens [ ] = new HTMLPurifier_Token_Empty ( $ name , $ attrs ) ; } else { $ this -> tokens [ ] = new HTMLPurifier_Token_Start ( $ name , $ attrs ) ; } return true ; }
|
Open tag event handler interface is defined by PEAR package .
|
2,245
|
public function closeHandler ( & $ parser , $ name ) { if ( $ this -> tokens [ count ( $ this -> tokens ) - 1 ] instanceof HTMLPurifier_Token_Empty ) { return true ; } $ this -> tokens [ ] = new HTMLPurifier_Token_End ( $ name ) ; return true ; }
|
Close tag event handler interface is defined by PEAR package .
|
2,246
|
public function escapeHandler ( & $ parser , $ data ) { if ( strpos ( $ data , '--' ) === 0 ) { $ this -> tokens [ ] = new HTMLPurifier_Token_Comment ( $ data ) ; } return true ; }
|
Escaped text handler interface is defined by PEAR package .
|
2,247
|
public function findExistingWidgets ( $ theme , $ names ) { if ( ! is_array ( $ names ) ) { $ names = [ $ names ] ; } $ select = $ this -> getSql ( ) -> select ( ) -> from ( $ this -> getTable ( self :: LayoutTableAlias ) ) -> columns ( [ 'name' , ] ) -> where ( [ 'theme' => $ theme , 'name' => $ names , ] ) ; $ result = $ this -> execute ( $ select ) ; return $ this -> toList ( $ result , 'name' ) ; }
|
Returns the names of the widgets from a predefined list that are registered in the database .
|
2,248
|
private function isResolvableCallable ( Invokable $ reflectedCallable ) : bool { $ callable = $ reflectedCallable -> callable ( ) ; return $ reflectedCallable -> isFunction ( ) || is_object ( $ callable [ 0 ] ) || $ this -> isResolvableService ( $ callable [ 0 ] ) ; }
|
Verifies that provided callable can be called by service container .
|
2,249
|
private function register ( string $ id , bool $ shared , Closure $ registrationCallback ) { $ this -> validateId ( $ id ) ; $ id = $ this -> normalize ( $ id ) ; unset ( $ this -> instances [ $ id ] , $ this -> shared [ $ id ] , $ this -> keys [ $ id ] ) ; $ registrationCallback ( $ id ) ; $ this -> shared [ $ id ] = $ shared ? : null ; $ this -> keys [ $ id ] = true ; }
|
Registers binding . After this method call binding can be resolved by container .
|
2,250
|
private function validateId ( string $ id ) { if ( ! interface_exists ( $ id ) && ! class_exists ( $ id ) ) { throw new InvalidArgumentException ( sprintf ( 'Invalid service id "%s". Service id must be an existing interface or class name.' , $ id ) ) ; } }
|
Validate service identifier . Throw an Exception in case of invalid value .
|
2,251
|
private function getModelNameFromClass ( $ model_class ) { if ( ( $ pos = strrpos ( $ model_class , '\\' ) ) !== false ) { return Inflector :: pluralize ( Inflector :: tableize ( substr ( $ model_class , $ pos + 1 ) ) ) ; } else { return Inflector :: pluralize ( Inflector :: tableize ( $ model_class ) ) ; } }
|
Get model name from model class .
|
2,252
|
public static function getClassesToRead ( \ ReflectionObject $ reflectionObject ) { $ cacheId = md5 ( "classesToRead:" . $ reflectionObject -> getName ( ) ) ; $ objectClasses = self :: getFromCache ( $ cacheId ) ; if ( $ objectClasses !== null ) { return $ objectClasses ; } $ objectClasses = array ( $ reflectionObject ) ; $ objectTraits = $ reflectionObject -> getTraits ( ) ; if ( ! empty ( $ objectTraits ) ) { foreach ( $ objectTraits as $ trait ) { $ objectClasses [ ] = $ trait ; } } $ parentClass = $ reflectionObject -> getParentClass ( ) ; while ( $ parentClass ) { $ objectClasses [ ] = $ parentClass ; $ parentTraits = $ parentClass -> getTraits ( ) ; if ( ! empty ( $ parentTraits ) ) { foreach ( $ parentTraits as $ trait ) { $ objectClasses [ ] = $ trait ; } } $ parentClass = $ parentClass -> getParentClass ( ) ; } self :: saveToCache ( $ cacheId , $ objectClasses ) ; return $ objectClasses ; }
|
Get a list of classes and traits to analyze .
|
2,253
|
public static function getProperties ( $ classes ) { array_reverse ( $ classes ) ; $ properties = array ( ) ; foreach ( $ classes as $ class ) { foreach ( $ class -> getProperties ( ) as $ property ) { $ properties [ $ property -> getName ( ) ] = $ property ; } } return $ properties ; }
|
Get the properties from a list of classes .
|
2,254
|
public static function getClassInformation ( $ object ) { $ reflectionObject = new \ ReflectionObject ( $ object ) ; $ cacheId = md5 ( "classInformation:" . $ reflectionObject -> getName ( ) ) ; $ classInfo = self :: getFromCache ( $ cacheId ) ; if ( $ classInfo !== null ) { return $ classInfo ; } $ objectClasses = self :: getClassesToRead ( $ reflectionObject ) ; $ objectProperties = self :: getProperties ( $ objectClasses ) ; $ annotationReader = Configuration :: getAnnotationReader ( ) ; $ classInfo = array ( 'accessProperties' => AccessReader :: getAccessProperties ( $ objectProperties , $ annotationReader ) , 'collectionsItemNames' => CollectionsReader :: getCollectionsItemNames ( $ objectProperties , $ annotationReader ) , 'associationsList' => AssociationReader :: getAssociations ( $ objectProperties , $ annotationReader ) , 'constraintsValidationEnabled' => ConstraintsReader :: isConstraintsValidationEnabled ( $ objectClasses , $ annotationReader ) , 'initialPropertiesValues' => AutoConstructReader :: getPropertiesToInitialize ( $ objectProperties , $ annotationReader ) , 'initializationNeededArguments' => AutoConstructReader :: getConstructArguments ( $ objectClasses , $ annotationReader ) ) ; self :: saveToCache ( $ cacheId , $ classInfo ) ; return $ classInfo ; }
|
Get the information on a class from its instance .
|
2,255
|
public static function saveToCache ( $ id , $ value ) { $ arrayCache = Configuration :: getArrayCache ( ) ; $ cacheDriver = Configuration :: getCacheDriver ( ) ; $ arrayCache -> save ( $ id , $ value ) ; if ( $ cacheDriver !== null ) { $ cacheDriver -> save ( $ id , $ value ) ; } }
|
Save a value to the cache .
|
2,256
|
public static function add ( & $ set , $ args ) { self :: assertArgsNumber ( 1 , $ args ) ; $ value = $ args [ 0 ] ; foreach ( $ set as $ item ) { if ( $ item === $ value ) { return ; } } $ set [ ] = $ value ; }
|
Adds an element to the set if it is not already present .
|
2,257
|
public static function remove ( & $ set , $ args ) { self :: assertArgsNumber ( 1 , $ args ) ; foreach ( $ set as $ key => $ value ) { if ( $ value === $ args [ 0 ] ) { unset ( $ set [ $ key ] ) ; return ; } } }
|
Removes an element from the set .
|
2,258
|
public function dispatch ( ) { foreach ( $ this -> getSubscribers ( ) as $ channelIdentifier => $ subscribers ) { $ channel = $ this -> getChannelFactory ( ) -> getChannel ( $ channelIdentifier ) ; $ message = $ this -> getMessage ( $ channel ) ; $ message = $ this -> decorate ( $ message , $ channel ) ; foreach ( $ subscribers as $ subscriber ) { $ message -> decorate ( ) ; $ channel -> dispatch ( $ subscriber , $ message ) ; } } }
|
Dispatch the event to its subscribers through the subscribed channels .
|
2,259
|
public static function getParsers ( ) { $ parsers = [ ] ; $ parserClassList = ClassMapGenerator :: createMap ( base_path ( ) . '/vendor/abuseio' ) ; $ parserClassListFiltered = array_where ( array_keys ( $ parserClassList ) , function ( $ value , $ key ) { if ( strpos ( $ value , 'AbuseIO\Parsers\\' ) !== false ) { return $ value ; } return false ; } ) ; $ parserList = array_map ( 'class_basename' , $ parserClassListFiltered ) ; foreach ( $ parserList as $ parser ) { if ( ! in_array ( $ parser , [ 'Factory' , 'Parser' ] ) ) { $ parsers [ ] = $ parser ; } } return $ parsers ; }
|
Get a list of installed AbuseIO parsers and return as an array
|
2,260
|
public static function create ( $ parsedMail , $ arfMail ) { $ parsers = Factory :: getParsers ( ) ; foreach ( $ parsers as $ parserName ) { $ parserClass = 'AbuseIO\\Parsers\\' . $ parserName ; if ( config ( "parsers.{$parserName}.parser.enabled" ) === true ) { $ report_file = config ( "parsers.{$parserName}.parser.report_file" ) ; if ( $ report_file == null || ( is_string ( $ report_file ) && isValidRegex ( $ report_file ) ) ) { $ isValidReport = true ; } else { $ isValidReport = false ; Log :: warning ( 'AbuseIO\Parsers\Factory: ' . "The parser {$parserName} has an invalid value for 'report_file' (not a regex)." ) ; break ; } foreach ( config ( "parsers.{$parserName}.parser.sender_map" ) as $ senderMap ) { if ( isValidRegex ( $ senderMap ) ) { if ( preg_match ( $ senderMap , $ parsedMail -> getHeader ( 'from' ) ) && $ isValidReport ) { return new $ parserClass ( $ parsedMail , $ arfMail ) ; } } else { Log :: warning ( 'AbuseIO\Parsers\Factory: ' . "The parser {$parserName} has an invalid value for 'sender_map' (not a regex)." ) ; } } foreach ( config ( "parsers.{$parserName}.parser.body_map" ) as $ bodyMap ) { if ( isValidRegex ( $ bodyMap ) ) { if ( preg_match ( $ bodyMap , $ parsedMail -> getMessageBody ( ) ) && $ isValidReport ) { return new $ parserClass ( $ parsedMail , $ arfMail ) ; } if ( $ arfMail !== false ) { foreach ( $ arfMail as $ mailPart ) { if ( preg_match ( $ bodyMap , $ mailPart ) ) { return new $ parserClass ( $ parsedMail , $ arfMail ) ; } } } } else { Log :: warning ( 'AbuseIO\Parsers\Factory: ' . "The parser {$parserName} has an invalid value for 'body_map' (not a regex)." ) ; } } } else { Log :: info ( 'AbuseIO\Parsers\Factory: ' . "The parser {$parserName} has been disabled and will not be used for this message." ) ; } } return false ; }
|
Create and return a Parser class and it s configuration
|
2,261
|
public function getRegions ( $ themeName ) { $ translator = $ this -> getTranslator ( ) ; $ options = $ this -> getModuleOptions ( ) ; $ theme = $ options -> getThemeByName ( $ themeName ) ; $ map = [ ] ; if ( ! isset ( $ theme [ 'frontend' ] [ 'regions' ] ) || ! is_array ( $ theme [ 'frontend' ] [ 'regions' ] ) || empty ( $ theme [ 'frontend' ] [ 'regions' ] ) ) { return $ map ; } $ regions = $ theme [ 'frontend' ] [ 'regions' ] ; $ widgets = array_keys ( $ options -> getWidgets ( ) ) ; foreach ( $ regions as $ regionName => $ regionOptions ) { if ( isset ( $ regionOptions [ 'contains' ] ) && is_array ( $ regionOptions [ 'contains' ] ) ) { $ container = $ regionOptions [ 'contains' ] ; foreach ( $ container as $ widget ) { $ map [ $ widget ] = $ regionName ; } } } foreach ( $ widgets as $ widget ) { if ( ! array_key_exists ( $ widget , $ map ) ) { $ map [ $ widget ] = 'none' ; } } return $ map ; }
|
Get the existing regions from the module options .
|
2,262
|
protected static function getApplicablePropertyModelClassNames ( $ id ) { if ( isset ( static :: $ applicablePropertyModelClassNames [ $ id ] ) === false ) { $ subQuery = PropertyPropertyGroup :: find ( ) -> from ( PropertyPropertyGroup :: tableName ( ) . ' ppg' ) -> select ( 'pg.applicable_property_model_id' ) -> join ( 'INNER JOIN' , PropertyGroup :: tableName ( ) . ' pg' , 'pg.id = ppg.property_group_id' ) -> where ( [ 'ppg.property_id' => $ id ] ) -> createCommand ( ) -> getRawSql ( ) ; static :: $ applicablePropertyModelClassNames [ $ id ] = ( new Query ( ) ) -> select ( 'class_name' ) -> from ( ApplicablePropertyModels :: tableName ( ) ) -> where ( 'id IN (' . $ subQuery . ')' ) -> column ( ) ; } return static :: $ applicablePropertyModelClassNames [ $ id ] ; }
|
Get applicable property model class names by property id .
|
2,263
|
public function import ( $ name ) { $ object = null ; if ( ! isset ( $ this -> modules [ $ name ] ) ) { if ( isset ( $ this -> moduleMap [ $ name ] ) ) { $ object_class = $ this -> moduleMap [ $ name ] ; $ object = new $ object_class ( ) ; $ object -> setSystem ( $ this ) ; $ object -> setEventLoop ( $ this -> eventLoop ) ; $ this -> modules [ $ name ] = $ object ; } } else { $ object = $ this -> modules [ $ name ] ; } return $ object ; }
|
import a module based on name similar to node . js s require
|
2,264
|
public static function getLocaleFallbackList ( $ locale , $ fallbackLocale = '' ) { if ( empty ( $ locale ) ) { throw new InvalidArgumentException ( __METHOD__ . ': The given locale is empty' ) ; } $ fallbackList = [ ] ; $ fallbackList = array_merge ( $ fallbackList , self :: getFallbackList ( $ locale ) ) ; if ( $ fallbackLocale != $ locale ) { $ fallbackList = array_merge ( $ fallbackList , self :: getFallbackList ( $ fallbackLocale ) ) ; } return $ fallbackList ; }
|
Get a locale fallback list to check while translating .
|
2,265
|
protected function renderChildren ( $ def ) { $ context = new HTMLPurifier_Context ( ) ; $ ret = '' ; $ ret .= $ this -> start ( 'tr' ) ; $ elements = array ( ) ; $ attr = array ( ) ; if ( isset ( $ def -> elements ) ) { if ( $ def -> type == 'strictblockquote' ) { $ def -> validateChildren ( array ( ) , $ this -> config , $ context ) ; } $ elements = $ def -> elements ; } if ( $ def -> type == 'chameleon' ) { $ attr [ 'rowspan' ] = 2 ; } elseif ( $ def -> type == 'empty' ) { $ elements = array ( ) ; } elseif ( $ def -> type == 'table' ) { $ elements = array_flip ( array ( 'col' , 'caption' , 'colgroup' , 'thead' , 'tfoot' , 'tbody' , 'tr' ) ) ; } $ ret .= $ this -> element ( 'th' , 'Allowed children' , $ attr ) ; if ( $ def -> type == 'chameleon' ) { $ ret .= $ this -> element ( 'td' , '<em>Block</em>: ' . $ this -> escape ( $ this -> listifyTagLookup ( $ def -> block -> elements ) ) , 0 , 0 ) ; $ ret .= $ this -> end ( 'tr' ) ; $ ret .= $ this -> start ( 'tr' ) ; $ ret .= $ this -> element ( 'td' , '<em>Inline</em>: ' . $ this -> escape ( $ this -> listifyTagLookup ( $ def -> inline -> elements ) ) , 0 , 0 ) ; } elseif ( $ def -> type == 'custom' ) { $ ret .= $ this -> element ( 'td' , '<em>' . ucfirst ( $ def -> type ) . '</em>: ' . $ def -> dtd_regex ) ; } else { $ ret .= $ this -> element ( 'td' , '<em>' . ucfirst ( $ def -> type ) . '</em>: ' . $ this -> escape ( $ this -> listifyTagLookup ( $ elements ) ) , 0 , 0 ) ; } $ ret .= $ this -> end ( 'tr' ) ; return $ ret ; }
|
Renders a row describing the allowed children of an element
|
2,266
|
protected function listifyTagLookup ( $ array ) { ksort ( $ array ) ; $ list = array ( ) ; foreach ( $ array as $ name => $ discard ) { if ( $ name !== '#PCDATA' && ! isset ( $ this -> def -> info [ $ name ] ) ) continue ; $ list [ ] = $ name ; } return $ this -> listify ( $ list ) ; }
|
Listifies a tag lookup table .
|
2,267
|
protected function listifyAttr ( $ array ) { ksort ( $ array ) ; $ list = array ( ) ; foreach ( $ array as $ name => $ obj ) { if ( $ obj === false ) continue ; $ list [ ] = "$name = <i>" . $ this -> getClass ( $ obj , 'AttrDef_' ) . '</i>' ; } return $ this -> listify ( $ list ) ; }
|
Listifies a hash of attributes to AttrDef classes
|
2,268
|
public function addDimension ( $ name , $ value , $ increment = 1 ) { $ dimension = new LogDimension ( $ name , $ value ) ; $ dimension -> setIncrement ( $ increment ) ; $ this -> dimensions [ ] = $ dimension ; return $ this ; }
|
Add a dimension to the entry .
|
2,269
|
public static function classToIndex ( $ className ) { if ( false === is_string ( $ className ) ) { return '' ; } $ modelClass = strtolower ( $ className ) ; return StringHelper :: basename ( $ modelClass ) ; }
|
Builds index name according to given model class
|
2,270
|
public static function storageClassToType ( $ storageClass ) { if ( false === is_string ( $ storageClass ) ) { return '' ; } $ name = StringHelper :: basename ( $ storageClass ) ; return Inflector :: camel2id ( $ name , '_' ) ; }
|
Builds index type according to given property storage class name
|
2,271
|
public static function primaryKeysByCondition ( $ client , $ condition ) { $ primaryKeys = [ ] ; $ count = $ client -> count ( $ condition ) ; $ count = empty ( $ count [ 'count' ] ) ? 10 : $ count [ 'count' ] ; $ condition [ 'size' ] = $ count ; $ condition [ '_source' ] = true ; $ res = $ client -> search ( $ condition ) ; if ( false === empty ( $ res [ 'hits' ] [ 'hits' ] ) ) { foreach ( $ res [ 'hits' ] [ 'hits' ] as $ doc ) { if ( false === isset ( $ primaryKeys [ $ doc [ '_id' ] ] ) ) { $ primaryKeys [ $ doc [ '_id' ] ] = [ $ doc [ '_type' ] ] ; } else { if ( false === in_array ( $ doc [ '_type' ] , $ primaryKeys [ $ doc [ '_id' ] ] ) ) { $ primaryKeys [ $ doc [ '_id' ] ] [ ] = $ doc [ '_type' ] ; } } } } return $ primaryKeys ; }
|
Performs fast scan for docs ids in elasticsearch indices
|
2,272
|
public function checkScheme ( $ url = '' , $ secure = false ) { $ parsed = [ ] ; $ parsed = parse_url ( $ url ) ; $ pos = strpos ( $ url , '//' ) ; if ( empty ( $ parsed [ 'scheme' ] ) && strpos ( $ url , '//' ) !== false ) return $ url ; elseif ( empty ( $ parsed [ 'scheme' ] ) ) return 'http' . ( $ secure ? 's' : '' ) . '://' . $ url ; else return $ url ; }
|
Checks if a string contains a scheme . Adds one if necessary checks for schemaless urls .
|
2,273
|
public function jsonResponse ( $ data = [ ] ) { global $ db_show_debug ; $ json = '' ; $ result = false ; if ( empty ( $ data ) ) return false ; $ json = json_encode ( $ data ) ; $ result = json_last_error ( ) == JSON_ERROR_NONE ; if ( $ result ) { $ db_show_debug = false ; ob_end_clean ( ) ; if ( $ this -> _app -> modSetting ( 'CompressedOutput' ) ) @ ob_start ( 'ob_gzhandler' ) ; else ob_start ( ) ; header ( 'Content-Type: application/json' ) ; echo $ json ; obExit ( false ) ; } return $ result ; }
|
Outputs a json encoded string It assumes the data is a valid array .
|
2,274
|
public function parser ( $ text , $ replacements = [ ] ) : string { global $ context ; if ( empty ( $ text ) || empty ( $ replacements ) || ! is_array ( $ replacements ) ) return '' ; $ find = [ ] ; $ replace = [ ] ; foreach ( $ replacements as $ f => $ r ) { $ find [ ] = '{' . $ f . '}' ; $ replace [ ] = $ r . ( ( strpos ( $ f , 'href' ) !== false ) ? ( ';' . $ context [ 'session_var' ] . '=' . $ context [ 'session_id' ] ) : '' ) ; } return str_replace ( $ find , $ replace , $ text ) ; }
|
Parses and replace tokens by their given values . also automatically adds the session var for href tokens .
|
2,275
|
public function commaSeparated ( $ string , $ type = 'alphanumeric' , $ delimiter = ',' ) { if ( empty ( $ string ) ) return false ; $ t = isset ( $ this -> _commaCases [ $ type ] ) ? $ this -> _commaCases [ $ type ] : $ this -> _commaCases [ 'alphanumeric' ] ; return empty ( $ string ) ? false : implode ( $ delimiter , array_filter ( explode ( $ delimiter , preg_replace ( array ( '/[^' . $ t . ',]/' , '/(?<=' . $ delimiter . ')' . $ delimiter . '+/' , '/^' . $ delimiter . '+/' , '/' . $ delimiter . '+$/' ) , '' , $ string ) ) ) ) ; }
|
Checks and returns a comma separated string .
|
2,276
|
public function formatBytes ( $ bytes , $ showUnits = false , $ log = 1024 ) : string { $ units = array ( 'B' , 'KB' , 'MB' , 'GB' , 'TB' ) ; $ bytes = max ( $ bytes , 0 ) ; $ pow = floor ( ( $ bytes ? log ( $ bytes ) : 0 ) / log ( $ log ) ) ; $ pow = min ( $ pow , count ( $ units ) - 1 ) ; $ bytes /= ( 1 << ( 10 * $ pow ) ) ; return round ( $ bytes , 2 ) . ( $ showUnits ? ' ' . $ units [ $ pow ] : '' ) ; }
|
Returns a formatted string .
|
2,277
|
private function determineSourceFolder ( ) { $ this -> sourceFolder = JPATH_BASE . "/" . $ this -> getJConfig ( ) -> source ; if ( ! is_dir ( $ this -> sourceFolder ) ) { $ this -> say ( 'Warning - Directory: ' . $ this -> sourceFolder . ' is not available' ) ; } }
|
Sets the source folder
|
2,278
|
private function determineOperatingSystem ( ) { $ this -> os = strtoupper ( substr ( PHP_OS , 0 , 3 ) ) ; if ( $ this -> os === 'WIN' ) { $ this -> fileExtension = '.exe' ; } }
|
Sets the operating system
|
2,279
|
public function actionCreate ( ) { $ model = new SeoPresets ( ) ; $ model -> loadDefaultValues ( ) ; if ( $ model -> load ( Yii :: $ app -> request -> post ( ) ) && $ model -> save ( ) ) { if ( Yii :: $ app -> request -> post ( 'action' ) === 'apply' ) { return $ this -> redirect ( [ 'update' , 'id' => $ model -> id ] ) ; } else { return $ this -> redirect ( [ 'view' , 'id' => $ model -> id ] ) ; } } return $ this -> render ( 'create' , [ 'model' => $ model , ] ) ; }
|
Creates a new SeoPresets model . If creation is successful the browser will be redirected to the view page .
|
2,280
|
public function actionUpdate ( $ id ) { $ model = $ this -> findModel ( $ id ) ; $ model -> loadDefaultValues ( ) ; if ( $ model -> load ( Yii :: $ app -> request -> post ( ) ) && $ model -> save ( ) ) { if ( Yii :: $ app -> request -> post ( 'action' ) === 'apply' ) { return $ this -> redirect ( [ 'update' , 'id' => $ model -> id ] ) ; } else { return $ this -> redirect ( [ 'view' , 'id' => $ model -> id ] ) ; } } return $ this -> render ( 'update' , [ 'model' => $ model , ] ) ; }
|
Updates an existing SeoPresets model . If update is successful the browser will be redirected to the view page .
|
2,281
|
public function prepare ( TokenStream $ stream ) : void { $ this -> root = $ this -> scope = new RootNode ( ) ; $ this -> stream = $ stream ; $ this -> lastTokenIndex = max ( 0 , count ( $ this -> stream -> getTokens ( ) ) - 1 ) ; $ this -> cursor = 0 ; }
|
Prepares the parser for parsing
|
2,282
|
public function parseOutsideTag ( ) : void { if ( ! count ( $ this -> stream -> getTokens ( ) ) ) { return ; } if ( $ this -> accept ( Token :: T_TEXT ) ) { $ this -> insert ( new TextNode ( $ this -> getCurrentToken ( ) -> getValue ( ) ) ) ; $ this -> advance ( ) ; } if ( $ this -> skip ( Token :: T_OPENING_TAG ) ) { $ this -> parseStatement ( ) ; } }
|
Parses outside of tags
|
2,283
|
public function expect ( int $ type , $ value = null ) : bool { if ( ! $ this -> accept ( $ type , $ value ) ) { $ this -> syntaxError ( 'Expected ' . Token :: getStringRepresentation ( $ type , $ value ) . ' got ' . $ this -> getCurrentToken ( ) ) ; } return true ; }
|
Expects the current token to be of given type and optionally has given value
|
2,284
|
public function expectNext ( int $ type , $ value = null ) : bool { if ( ! $ this -> acceptNext ( $ type , $ value ) ) { $ this -> syntaxError ( 'Expected ' . Token :: getStringRepresentation ( $ type , $ value ) . ' got ' . $ this -> getNextToken ( ) ) ; } return true ; }
|
Expects the next token to be of given type and optionally has given value
|
2,285
|
public function skip ( int $ type , $ value = null ) : bool { if ( $ this -> accept ( $ type , $ value ) ) { $ this -> advance ( ) ; return true ; } return false ; }
|
Skips the current token if it s of given type and optionally has given value
|
2,286
|
public function accept ( int $ type , $ value = null ) : bool { if ( $ this -> getCurrentToken ( ) -> getType ( ) === $ type ) { if ( $ value ) { if ( $ this -> getCurrentToken ( ) -> getValue ( ) === $ value ) { return true ; } return false ; } return true ; } return false ; }
|
Accepts the current token if it s of given type and optionally has given value
|
2,287
|
public function acceptNext ( int $ type , $ value = null ) : bool { if ( $ this -> getNextToken ( ) -> getType ( ) === $ type ) { if ( $ value ) { if ( $ this -> getNextToken ( ) -> getValue ( ) === $ value ) { return true ; } return false ; } return true ; } return false ; }
|
Accepts the next token if it s of given type and optionally has given value
|
2,288
|
public function traverseDown ( ) : void { try { $ parent = $ this -> getScope ( ) -> getParent ( ) ; } catch ( AegisError $ e ) { throw new ParseError ( $ e -> getMessage ( ) ) ; } $ this -> setScope ( $ parent ) ; }
|
Moves outside the current scope
|
2,289
|
public function advance ( ) : void { if ( $ this -> cursor < count ( $ this -> stream -> getTokens ( ) ) - 1 ) { ++ $ this -> cursor ; } }
|
Advances the cursor
|
2,290
|
public function wrap ( Node $ node ) : void { $ last = $ this -> scope -> getLastChild ( ) ; $ this -> scope -> removeLastChild ( ) ; $ this -> insert ( $ node ) ; $ this -> traverseUp ( ) ; $ this -> insert ( $ last ) ; }
|
Wraps the last inserted node with the given node
|
2,291
|
public function setAttribute ( ) : void { $ last = $ this -> scope -> getLastChild ( ) ; $ this -> scope -> removeLastChild ( ) ; $ this -> scope -> setAttribute ( $ last ) ; }
|
Sets the last inserted node as attribute
|
2,292
|
public function insert ( Node $ node ) : void { $ node -> setParent ( $ this -> scope ) ; $ this -> scope -> insert ( $ node ) ; }
|
Inserts the given node
|
2,293
|
public function listAction ( ) { $ this -> routeParam ( ) -> mapPageTo ( $ this -> queryService ) ; $ collection = $ this -> queryService -> findUsedTags ( ) ; return $ this -> viewModelFactory ( ) -> createFor ( $ collection ) ; }
|
Tag list retrieval
|
2,294
|
public function build ( ) { $ this -> setLayout ( 'locales/index.tpl' ) ; $ this -> addModule ( 'head' , 'SharedHead' ) ; $ this -> addModule ( 'footer' , 'SharedFooter' ) ; $ this -> addModule ( 'system_messages' , 'SharedSystemMessages' ) ; $ params = $ this -> getParams ( ) ; $ action = \ Sifo \ Router :: getReversalRoute ( $ params [ 'path_parts' ] [ 0 ] ) ; $ params = $ this -> getParams ( ) ; if ( $ params [ 'params' ] !== false && in_array ( 'saved-true' , $ params [ "params" ] ) ) { \ Sifo \ FlashMessages :: set ( 'File Saved OK.' , \ Sifo \ FlashMessages :: MSG_OK ) ; } if ( $ params [ 'params' ] !== false && in_array ( 'created-true' , $ params [ "params" ] ) ) { \ Sifo \ FlashMessages :: set ( 'File Created OK.' , \ Sifo \ FlashMessages :: MSG_OK ) ; } if ( $ this -> getParsedParam ( 'instance' ) !== false ) { $ this -> assign ( 'current_instance' , $ this -> getParsedParam ( 'instance' ) ) ; $ this -> assign ( 'languages' , $ this -> getLanguagesInstance ( $ this -> getParsedParam ( 'instance' ) ) ) ; } if ( $ this -> getParsedParam ( 'language' ) !== false ) { $ this -> assign ( 'current_language' , $ this -> getParsedParam ( 'language' ) ) ; $ temp = explode ( "_" , $ this -> getParsedParam ( 'language' ) ) ; if ( is_array ( $ temp ) ) { $ this -> assign ( 'lang' , $ temp [ 1 ] ) ; } } $ instances = $ this -> getInstances ( ) ; $ this -> assign ( 'instances' , $ instances ) ; $ this -> assign ( 'params' , $ this -> getParam ( 'parsed_params' ) ) ; $ this -> assign ( 'params_definition' , $ this -> getParamsDefinition ( ) ) ; }
|
Main method controller .
|
2,295
|
public function getLanguagesInstance ( $ instance = null ) { $ languages = false ; if ( $ instance != '' ) { $ languages = $ this -> scanFiles ( ROOT_PATH . '/instances/' . $ instance . '/locale' , false ) ; if ( is_array ( $ languages ) && count ( $ languages ) > 0 ) { $ locales = array ( ) ; foreach ( $ languages as $ index => $ language ) { require_once ROOT_PATH . '/instances/' . $ instance . '/locale/' . $ language [ "id" ] ; if ( isset ( $ translations ) ) { $ locales [ $ language [ "id" ] ] [ "translations" ] = $ translations ; unset ( $ translations ) ; } else { $ locales [ $ language [ "id" ] ] [ "translations" ] = null ; } } $ translation_keys = $ this -> getUniqueTranslationKeys ( $ locales ) ; if ( is_array ( $ translation_keys ) ) natcasesort ( $ translation_keys ) ; $ this -> assign ( "translation_keys" , $ translation_keys ) ; if ( is_array ( $ translation_keys ) ) { $ total_keys = count ( $ translation_keys ) ; foreach ( $ locales as $ language => $ value ) { $ locales [ $ language ] [ "total_keys" ] = $ total_keys ; $ locales [ $ language ] [ "translated_keys" ] = count ( $ locales [ $ language ] [ "translations" ] ) ; $ locales [ $ language ] [ "translated_percentage" ] = number_format ( ( $ locales [ $ language ] [ "translated_keys" ] / $ locales [ $ language ] [ "total_keys" ] ) * 100 , 2 , "," , "." ) . "%" ; } } } } return ( $ locales ) ; }
|
Build a list with all of the languages of an instance
|
2,296
|
private function _mergeAssociated ( array $ result , array $ associated , $ refKey , $ colName ) { foreach ( $ result as $ index => $ item ) { if ( is_array ( $ item ) ) { $ refValue = $ item [ $ refKey ] ; } else { $ refValue = $ item -> { $ refKey } ; } if ( isset ( $ associated [ $ refValue ] ) ) { if ( is_array ( $ result [ $ index ] ) ) { $ result [ $ index ] [ $ colName ] = $ associated [ $ refValue ] ; } else { $ result [ $ index ] -> { $ colName } = $ associated [ $ refValue ] ; } } } return $ result ; }
|
Merge associated data with result
|
2,297
|
private function _getQueryChecksum ( ) { return md5 ( serialize ( [ "name" => $ this -> getName ( ) , "entity" => Convention :: classToName ( $ this -> reflection -> getClassName ( ) , Convention :: ENTITY_MASK ) , "limit" => $ this -> limit , "offset" => $ this -> offset , "selection" => $ this -> selection , "orderBy" => $ this -> orderBy , "adapterAssociations" => array_keys ( $ this -> adapterAssociations ) , "remoteAssociations" => array_keys ( $ this -> remoteAssociations ) , "conditions" => $ this -> filter ] ) ) ; }
|
Get a unique query checksum
|
2,298
|
protected function getRequestConfig ( array $ config ) : array { if ( ! empty ( $ this -> defaultRequestOptions ) ) { $ config = array_replace_recursive ( $ this -> defaultRequestOptions , $ config ) ; } return $ config ; }
|
Update request config with default options
|
2,299
|
private static function createBackoff ( array $ options , LoggerInterface $ logger ) { $ headerName = isset ( $ options [ 'http' ] [ 'retryHeader' ] ) ? $ options [ 'http' ] [ 'retryHeader' ] : 'Retry-After' ; $ httpRetryCodes = isset ( $ options [ 'http' ] [ 'codes' ] ) ? $ options [ 'http' ] [ 'codes' ] : [ 500 , 502 , 503 , 504 , 408 , 420 , 429 ] ; $ maxRetries = isset ( $ options [ 'maxRetries' ] ) ? ( int ) $ options [ 'maxRetries' ] : 10 ; $ curlRetryCodes = isset ( $ options [ 'curl' ] [ 'codes' ] ) ? $ options [ 'curl' ] [ 'codes' ] : [ CURLE_OPERATION_TIMEOUTED , CURLE_COULDNT_RESOLVE_HOST , CURLE_COULDNT_CONNECT , CURLE_SSL_CONNECT_ERROR , CURLE_GOT_NOTHING , CURLE_RECV_ERROR ] ; return new RetrySubscriber ( [ 'filter' => RetrySubscriber :: createChainFilter ( [ RetrySubscriber :: createStatusFilter ( $ httpRetryCodes ) , RetrySubscriber :: createCurlFilter ( $ curlRetryCodes ) ] ) , 'max' => $ maxRetries , 'delay' => function ( $ retries , AbstractTransferEvent $ event ) use ( $ headerName , $ logger ) { $ delay = self :: getRetryDelay ( $ retries , $ event , $ headerName ) ; $ errData = [ "http_code" => ! empty ( $ event -> getTransferInfo ( ) [ 'http_code' ] ) ? $ event -> getTransferInfo ( ) [ 'http_code' ] : null , "body" => is_null ( $ event -> getResponse ( ) ) ? null : ( string ) $ event -> getResponse ( ) -> getBody ( ) , "url" => ! empty ( $ event -> getTransferInfo ( ) [ 'url' ] ) ? $ event -> getTransferInfo ( ) [ 'url' ] : $ event -> getRequest ( ) -> getUrl ( ) , ] ; if ( $ event instanceof ErrorEvent ) { $ errData [ "message" ] = $ event -> getException ( ) -> getMessage ( ) ; } $ logger -> debug ( "Http request failed, retrying in {$delay}s" , $ errData ) ; return 1000 * $ delay ; } ] ) ; }
|
Create exponential backoff for GuzzleClient
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.