idx
int64
0
60.3k
question
stringlengths
101
6.21k
target
stringlengths
7
803
21,100
function group_del_group ( $ parent , $ child ) { $ parent_group = $ this -> group_info ( $ parent , array ( "cn" ) ) ; if ( $ parent_group [ 0 ] [ "dn" ] == NULL ) { return ( false ) ; } $ parent_dn = $ parent_group [ 0 ] [ "dn" ] ; $ child_group = $ this -> group_info ( $ child , array ( "cn" ) ) ; if ( $ child_group [ 0 ] [ "dn" ] == NULL ) { return ( false ) ; } $ child_dn = $ child_group [ 0 ] [ "dn" ] ; $ del = array ( ) ; $ del [ "member" ] = $ child_dn ; $ result = @ ldap_mod_del ( $ this -> _conn , $ parent_dn , $ del ) ; if ( $ result == false ) { return ( false ) ; } return ( true ) ; }
Remove a group from a group
21,101
function group_del_user ( $ group , $ user ) { $ group_info = $ this -> group_info ( $ group , array ( "cn" ) ) ; if ( $ group_info [ 0 ] [ "dn" ] == NULL ) { return ( false ) ; } $ group_dn = $ group_info [ 0 ] [ "dn" ] ; $ user_info = $ this -> user_info ( $ user , array ( "cn" ) ) ; if ( $ user_info [ 0 ] [ "dn" ] == NULL ) { return ( false ) ; } $ user_dn = $ user_info [ 0 ] [ "dn" ] ; $ del = array ( ) ; $ del [ "member" ] = $ user_dn ; $ result = @ ldap_mod_del ( $ this -> _conn , $ group_dn , $ del ) ; if ( $ result == false ) { return ( false ) ; } return ( true ) ; }
Remove a user from a group
21,102
function group_info ( $ group_name , $ fields = NULL ) { if ( $ group_name == NULL ) { return ( false ) ; } if ( ! $ this -> _bind ) { return ( false ) ; } $ filter = "(&(objectCategory=group)(" . $ this -> _group_cn_identifier . "=" . $ this -> ldap_search_encode ( $ group_name ) . "))" ; if ( $ fields == NULL ) { $ fields = array ( "member" , $ this -> _group_attribute , "cn" , "description" , "distinguishedname" , "objectcategory" , $ this -> _group_cn_identifier ) ; } $ sr = @ ldap_search ( $ this -> _conn , $ this -> _base_dn , $ filter , $ fields ) ; if ( FALSE === $ sr ) { $ this -> _warning_message = "group_info: ldap_search error " . ldap_errno ( $ this -> _conn ) . ": " . ldap_error ( $ this -> _conn ) ; echo "DEBUG: " . $ this -> _warning_message . "\n" ; } $ entries = $ this -> ldap_get_entries_raw ( $ sr ) ; if ( 0 == count ( $ entries ) ) { $ this -> _warning_message = "group_info: No entry for the specified filter $filter" ; echo "DEBUG: " . $ this -> _warning_message . "\n" ; } return ( $ entries ) ; }
Returns an array of information for a specified group
21,103
function group_users ( $ group_name = NUL ) { $ result = array ( ) ; if ( $ group_name == NULL ) { return ( false ) ; } if ( ! $ this -> _bind ) { return ( false ) ; } $ filter = "(&(|(objectClass=posixGroup)(objectClass=groupofNames))(" . $ this -> _group_cn_identifier . "=" . $ this -> ldap_search_encode ( $ group_name ) . "))" ; $ fields = array ( "member" , "memberuid" ) ; $ sr = ldap_search ( $ this -> _conn , $ this -> _base_dn , $ filter , $ fields ) ; $ entries = $ this -> ldap_get_entries_raw ( $ sr ) ; if ( 0 == count ( $ entries ) ) { $ this -> _warning_message = "group_users: No entry for the specified filter $filter" ; echo "DEBUG: " . $ this -> _warning_message ; } if ( isset ( $ entries [ 0 ] [ "member" ] [ 0 ] ) ) { $ result = $ this -> nice_names ( $ entries [ 0 ] [ "member" ] ) ; } elseif ( isset ( $ entries [ 0 ] [ "memberuid" ] [ 0 ] ) ) { $ result = $ this -> nice_names ( $ entries [ 0 ] [ "memberuid" ] ) ; } else { $ result = array ( ) ; } return ( $ result ) ; }
Returns an array of users that are members of a group
21,104
function user_groups ( $ username , $ recursive = NULL ) { if ( $ username == NULL ) { return ( false ) ; } if ( $ recursive == NULL ) { $ recursive = $ this -> _recursive_groups ; } if ( ! $ this -> _bind ) { return ( false ) ; } $ info = @ $ this -> user_info ( $ username , array ( $ this -> _group_attribute , "member" , "primarygroupid" ) ) ; $ groups = $ this -> nice_names ( $ info [ 0 ] [ $ this -> _group_attribute ] ) ; if ( $ recursive ) { foreach ( $ groups as $ id => $ group_name ) { $ extra_groups = $ this -> recursive_groups ( $ group_name ) ; $ groups = array_merge ( $ groups , $ extra_groups ) ; } } return ( $ groups ) ; }
Returns an array of groups that a user is a member off
21,105
function user_all_groups ( $ username , $ groups_filtering = '' ) { if ( $ username == NULL ) { return ( false ) ; } if ( ! $ this -> _bind ) { return ( false ) ; } $ filter = "(&(objectCategory=group)(member:1.2.840.113556.1.4.1941:=" . $ username . ")" . $ groups_filtering . ")" ; $ fields = array ( "cn" ) ; $ sr = ldap_search ( $ this -> _conn , $ this -> _base_dn , $ filter , $ fields ) ; $ group_entries = $ this -> rCountRemover ( ldap_get_entries ( $ this -> _conn , $ sr ) ) ; $ group_array = array ( ) ; foreach ( $ group_entries as $ group_entry ) { $ group_array [ ] = $ group_entry [ 'cn' ] [ 0 ] ; } return ( $ group_array ) ; }
New function for enhanced Active Directory
21,106
function users_info ( $ username = NULL , $ fields = NULL , $ groups_filtering = '' ) { $ entries = array ( ) ; $ entries [ 'count' ] = 0 ; $ i = 0 ; if ( $ result = $ this -> one_user_info ( TRUE , $ username , $ fields , FALSE , $ groups_filtering ) ) { do { $ entries [ $ i ] = $ result ; $ i ++ ; } while ( $ result = $ this -> one_user_info ( ) ) ; } $ entries [ 'count' ] = $ i ; return ( $ entries ) ; }
Returns an array of information for filtered users
21,107
function user_ingroup ( $ username , $ group , $ recursive = NULL ) { if ( $ username == NULL ) { return ( false ) ; } if ( $ group == NULL ) { return ( false ) ; } if ( ! $ this -> _bind ) { return ( false ) ; } if ( $ recursive == NULL ) { $ recursive = $ this -> _recursive_groups ; } $ groups = $ this -> user_groups ( $ username , array ( $ this -> _group_attribute ) , $ recursive ) ; if ( in_array ( $ group , $ groups ) ) { return ( true ) ; } return ( false ) ; }
Returns true if the user is a member of the group
21,108
function user_modify ( $ username , $ attributes ) { if ( $ username == NULL ) { return ( "Missing compulsory field [username]" ) ; } if ( array_key_exists ( "password" , $ attributes ) && ! $ this -> _use_ssl ) { echo ( "FATAL: SSL must be configured on your webserver and enabled in the class to set passwords." ) ; exit ( ) ; } $ user = $ this -> user_info ( $ username , array ( "cn" ) ) ; if ( $ user [ 0 ] [ "dn" ] == NULL ) { return ( false ) ; } $ user_dn = $ user [ 0 ] [ "dn" ] ; $ mod = $ this -> adldap_schema ( $ attributes ) ; if ( ! $ mod ) { return ( false ) ; } if ( array_key_exists ( "enabled" , $ attributes ) ) { if ( $ attributes [ "enabled" ] ) { $ control_options = array ( "NORMAL_ACCOUNT" ) ; } else { $ control_options = array ( "NORMAL_ACCOUNT" , "ACCOUNTDISABLE" ) ; } $ mod [ "userAccountControl" ] [ 0 ] = $ this -> account_control ( $ control_options ) ; } $ result = ldap_modify ( $ this -> _conn , $ user_dn , $ mod ) ; if ( $ result == false ) { return ( false ) ; } return ( true ) ; }
modify a user
21,109
function user_password ( $ username , $ password ) { if ( $ username == NULL ) { return ( false ) ; } if ( $ password == NULL ) { return ( false ) ; } if ( ! $ this -> _bind ) { return ( false ) ; } if ( ! $ this -> _use_ssl ) { echo ( "FATAL: SSL must be configured on your webserver and enabled in the class to set passwords." ) ; exit ( ) ; } $ user = $ this -> user_info ( $ username , array ( "cn" ) ) ; if ( $ user [ 0 ] [ "dn" ] == NULL ) { return ( false ) ; } $ user_dn = $ user [ 0 ] [ "dn" ] ; $ add = array ( ) ; $ add [ "unicodePwd" ] [ 0 ] = $ this -> encode_password ( $ password ) ; $ result = ldap_mod_replace ( $ this -> _conn , $ user_dn , $ add ) ; if ( $ result == false ) { return ( false ) ; } return ( true ) ; }
Set the password of a user
21,110
function computer_info ( $ computer_name , $ fields = NULL ) { if ( $ computer_name == NULL ) { return ( false ) ; } if ( ! $ this -> _bind ) { return ( false ) ; } $ filter = "(&(objectClass=computer)(cn=" . $ computer_name . "))" ; if ( $ fields == NULL ) { $ fields = array ( $ this -> _group_attribute , "cn" , "displayname" , "dnshostname" , "distinguishedname" , "objectcategory" , "operatingsystem" , "operatingsystemservicepack" , "operatingsystemversion" ) ; } $ sr = ldap_search ( $ this -> _conn , $ this -> _base_dn , $ filter , $ fields ) ; $ entries = $ this -> ldap_get_entries_raw ( $ sr ) ; return ( $ entries ) ; }
Returns an array of information for a specific computer
21,111
function all_users ( $ include_desc = false , $ search = "*" , $ sorted = true ) { if ( ! $ this -> _bind ) { return ( false ) ; } $ filter = "(&(objectClass=user)(samaccounttype=" . ADLDAP_NORMAL_ACCOUNT . ")(objectCategory=person)(cn=" . $ search . "))" ; $ fields = array ( $ this -> _cn_identifier , "displayname" ) ; $ sr = ldap_search ( $ this -> _conn , $ this -> _base_dn , $ filter , $ fields ) ; $ entries = $ this -> ldap_get_entries_raw ( $ sr ) ; $ users_array = array ( ) ; for ( $ i = 0 ; $ i < $ entries [ "count" ] ; $ i ++ ) { if ( $ include_desc && strlen ( $ entries [ $ i ] [ "displayname" ] [ 0 ] ) > 0 ) { $ users_array [ $ entries [ $ i ] [ $ this -> _cn_identifier ] [ 0 ] ] = $ entries [ $ i ] [ "displayname" ] [ 0 ] ; } elseif ( $ include_desc ) { $ users_array [ $ entries [ $ i ] [ $ this -> _cn_identifier ] [ 0 ] ] = $ entries [ $ i ] [ $ this -> _cn_identifier ] [ 0 ] ; } else { array_push ( $ users_array , $ entries [ $ i ] [ $ this -> _cn_identifier ] [ 0 ] ) ; } } if ( $ sorted ) { asort ( $ users_array ) ; } return ( $ users_array ) ; }
Returns all AD users
21,112
function encode_password ( $ password ) { $ password = "\"" . $ password . "\"" ; $ encoded = "" ; for ( $ i = 0 ; $ i < strlen ( $ password ) ; $ i ++ ) { $ encoded .= "{$password{$i}}\000" ; } return ( $ encoded ) ; }
Encode a password for transmission over LDAP
21,113
function ldap_slashes ( $ str ) { $ illegal = array ( "(" , ")" , "#" ) ; $ legal = array ( ) ; foreach ( $ illegal as $ id => $ char ) { $ legal [ $ id ] = "\\" . $ char ; } $ str = str_replace ( $ illegal , $ legal , $ str ) ; return ( $ str ) ; }
this is just a list of characters with known problems and I m trying not to strip out other languages
21,114
public function getValueSelectOptions ( ) { if ( ! $ this -> hasData ( 'value_select_options' ) ) { $ this -> setData ( 'value_select_options' , $ this -> sourceYesno -> toOptionArray ( ) ) ; } return $ this -> getData ( 'value_select_options' ) ; }
Get value select options
21,115
public function validate ( \ Magento \ Framework \ Model \ AbstractModel $ model ) { $ isShopgateOrder = ( int ) in_array ( $ model -> getData ( self :: CLIENT_ATTRIBUTE ) , self :: APP_CLIENTS ) ; $ model -> setData ( self :: IS_SHOPGATE_ORDER , $ isShopgateOrder ) ; return parent :: validate ( $ model ) ; }
Validate App Rule Condition
21,116
public static function getCustomFields ( $ findResults , $ getById = false ) { if ( is_array ( $ findResults ) ) { if ( count ( $ findResults ) == 1 && $ getById ) { $ findResults = [ $ findResults ] ; } } $ results = [ ] ; $ classReflection = ( new \ ReflectionClass ( $ findResults [ 0 ] ) ) ; $ className = $ classReflection -> getShortName ( ) ; $ classNamespace = $ classReflection -> getNamespaceName ( ) ; $ module = Modules :: findFirstByName ( $ className ) ; if ( $ module ) { $ model = $ classNamespace . '\\' . ucfirst ( $ module -> name ) . 'CustomFields' ; $ modelId = strtolower ( $ module -> name ) . '_id' ; $ customFields = CustomFields :: findByModulesId ( $ module -> id ) ; if ( is_array ( $ findResults ) ) { $ findResults [ 0 ] = $ findResults [ 0 ] -> toArray ( ) ; } else { $ findResults = $ findResults -> toArray ( ) ; } foreach ( $ findResults as $ result ) { foreach ( $ customFields as $ customField ) { $ result [ 'custom_fields' ] [ $ customField -> name ] = '' ; $ values = [ ] ; $ moduleValues = $ model :: find ( [ $ modelId . ' = ?0 AND custom_fields_id = ?1' , 'bind' => [ $ result [ 'id' ] , $ customField -> id ] ] ) ; if ( $ moduleValues -> count ( ) ) { $ result [ 'custom_fields' ] [ $ customField -> name ] = $ moduleValues [ 0 ] -> value ; } } $ results [ ] = $ result ; } return $ getById ? $ results [ 0 ] : $ results ; } return $ getById ? $ findResults [ 0 ] -> toArray ( ) : $ findResults ; }
Get a models custom fields
21,117
public function getAllCustomFields ( array $ fields = [ ] ) { if ( ! $ models = Modules :: findFirstByName ( $ this -> getSource ( ) ) ) { return ; } $ conditions = [ ] ; $ fieldsIn = null ; if ( ! empty ( $ fields ) ) { $ fieldsIn = " and name in ('" . implode ( "','" , $ fields ) . ')' ; } $ conditions = 'modules_id = ? ' . $ fieldsIn ; $ bind = [ $ this -> getId ( ) , $ models -> getId ( ) ] ; $ customFieldsValueTable = $ this -> getSource ( ) . '_custom_fields' ; $ result = $ this -> getReadConnection ( ) -> prepare ( "SELECT l.{$this->getSource()}_id, c.id as field_id, c.name, l.value , c.users_id, l.created_at, l.updated_at FROM {$customFieldsValueTable} l, custom_fields c WHERE c.id = l.custom_fields_id AND l.leads_id = ? AND c.modules_id = ? " ) ; $ result -> execute ( $ bind ) ; $ listOfCustomFields = [ ] ; while ( $ row = $ result -> fetch ( \ PDO :: FETCH_OBJ ) ) { $ listOfCustomFields [ $ row -> name ] = $ row -> value ; } return $ listOfCustomFields ; }
Get all custom fields of the given object
21,118
protected function saveCustomFields ( ) : bool { if ( ! $ module = Modules :: findFirstByName ( $ this -> getSource ( ) ) ) { return false ; } $ reflector = new \ ReflectionClass ( $ this ) ; $ classNameWithNameSpace = $ reflector -> getNamespaceName ( ) . '\\' . $ reflector -> getShortName ( ) . 'CustomFields' ; foreach ( $ this -> customFields as $ key => $ value ) { $ customModel = new $ classNameWithNameSpace ( ) ; if ( $ customField = CustomFields :: findFirst ( [ 'conditions' => 'name = ?0 and modules_id = ?1' , 'bind' => [ $ key , $ module -> id ] ] ) ) { $ customModel -> setCustomId ( $ this -> getId ( ) ) ; $ customModel -> custom_fields_id = $ customField -> id ; $ customModel -> value = $ value ; $ customModel -> created_at = date ( 'Y-m-d H:i:s' ) ; if ( ! $ customModel -> save ( ) ) { throw new Exception ( 'Custome ' . $ key . ' - ' . $ this -> customModel -> getMessages ( ) [ 0 ] ) ; } } } unset ( $ this -> customFields ) ; return true ; }
Create new custom fields
21,119
public function cleanCustomFields ( int $ id ) : bool { $ reflector = new \ ReflectionClass ( $ this ) ; $ classNameWithNameSpace = $ reflector -> getNamespaceName ( ) . '\\' . $ reflector -> getShortName ( ) . 'CustomFields' ; $ customModel = new $ classNameWithNameSpace ( ) ; $ result = $ this -> getReadConnection ( ) -> prepare ( "DELETE FROM {$customModel->getSource()} WHERE " . $ this -> getSource ( ) . '_id = ?' ) ; return $ result -> execute ( [ $ id ] ) ; }
Remove all the custom fields from the entity
21,120
public function afterUpdate ( ) { if ( ! empty ( $ this -> customFields ) ) { $ allCustomFields = $ this -> getAllCustomFields ( ) ; if ( is_array ( $ allCustomFields ) ) { foreach ( $ this -> customFields as $ key => $ value ) { $ allCustomFields [ $ key ] = $ value ; } } $ this -> setCustomFields ( $ allCustomFields ) ; $ this -> cleanCustomFields ( $ this -> getId ( ) ) ; $ this -> saveCustomFields ( ) ; } }
After the model was update we need to update its custom fields
21,121
protected function compare ( AlphabeticalTreeNodeInterface $ a , AlphabeticalTreeNodeInterface $ b ) { $ pathA = AlphabeticalTreeNodeHelper :: getPath ( $ a ) ; $ pathB = AlphabeticalTreeNodeHelper :: getPath ( $ b ) ; $ count = count ( $ pathA ) ; for ( $ i = 0 ; $ i < $ count ; ++ $ i ) { $ itemA = $ pathA [ $ i ] ; $ itemB = true === isset ( $ pathB [ $ i ] ) ? $ pathB [ $ i ] : null ; if ( $ itemA !== $ itemB ) { return null !== $ itemB ? strcasecmp ( $ itemA -> getAlphabeticalTreeNodeLabel ( ) , $ itemB -> getAlphabeticalTreeNodeLabel ( ) ) : 1 ; } } return 0 ; }
Compare two nodes .
21,122
public function flash ( $ key , $ value = true ) { if ( is_array ( $ key ) ) $ this -> flashMany ( $ key ) ; else $ this -> session -> flash ( $ key , $ value ) ; }
Flash a message to the session .
21,123
public function getConnection ( ) { if ( null === $ this -> connection ) { $ this -> connection = $ this -> connect ( ) ; } return $ this -> connection ; }
Get the connection .
21,124
public function prepareBinding ( array $ fields ) { $ output = [ ] ; foreach ( $ fields as $ current ) { $ output [ $ current ] = ":" . $ current ; } return $ output ; }
Prepare a binding .
21,125
public function prepareInsert ( $ table , array $ values ) { $ query = [ ] ; $ query [ ] = "INSERT INTO " ; $ query [ ] = $ table ; $ query [ ] = " (`" ; $ query [ ] = implode ( "`, `" , array_keys ( $ values ) ) ; $ query [ ] = "`) VALUES (" ; $ query [ ] = implode ( ", " , array_values ( $ values ) ) ; $ query [ ] = ")" ; return implode ( "" , $ query ) ; }
Prepare an INSERT SQL query .
21,126
public function prepareUpdate ( $ table , array $ values ) { $ set = [ ] ; foreach ( $ values as $ k => $ v ) { $ set [ ] = "`" . $ k . "` = " . $ v ; } $ query = [ ] ; $ query [ ] = "UPDATE " ; $ query [ ] = $ table ; $ query [ ] = " SET " ; $ query [ ] = implode ( ", " , $ set ) ; return implode ( "" , $ query ) ; }
Prepare an UPDATE SQL query .
21,127
public function parseEntity ( User $ entity ) { $ output = [ $ this -> encodeInteger ( $ entity -> getUserNumber ( ) , 9 ) , $ this -> encodeInteger ( $ entity -> getCustomerNumber ( ) , 9 ) , $ this -> encodeString ( $ entity -> getTitle ( ) , 10 ) , $ this -> encodeString ( $ entity -> getSurname ( ) , 25 ) , $ this -> encodeString ( $ entity -> getFirstname ( ) , 25 ) , $ this -> encodeDate ( $ entity -> getDateBirth ( ) ) , $ this -> encodeString ( $ entity -> getParkingSpace ( ) , 5 ) , $ this -> encodeString ( $ entity -> getRemarks ( ) , 50 ) , $ this -> encodeDateTime ( $ entity -> getDatetimeLastModification ( ) ) , $ this -> encodeBoolean ( $ entity -> getDeletedRecord ( ) ) , $ this -> encodeString ( $ entity -> getIdentificationNumber ( ) , 20 ) , $ this -> encodeBoolean ( $ entity -> getCheckLicensePlate ( ) ) , $ this -> encodeBoolean ( $ entity -> getPassageLicensePlatePermitted ( ) ) , $ this -> encodeBoolean ( $ entity -> getExcessTimesCreditCard ( ) ) , $ this -> encodeString ( $ entity -> getCreditCardNumber ( ) , 20 ) , $ this -> encodeDate ( $ entity -> getExpiryDate ( ) ) , $ this -> encodeString ( $ entity -> getRemarks2 ( ) , 50 ) , $ this -> encodeString ( $ entity -> getRemarks3 ( ) , 50 ) , $ this -> encodeString ( $ entity -> getDivision ( ) , 50 ) , $ this -> encodeString ( $ entity -> getEmail ( ) , 120 ) , $ this -> encodeBoolean ( $ entity -> getGroupCounting ( ) ) , $ this -> encodeInteger ( $ entity -> getETicketTypeP ( ) , 1 ) , $ this -> encodeString ( $ entity -> getETicketEmailTelephone ( ) , 120 ) , $ this -> encodeInteger ( $ entity -> getETicketAuthentication ( ) , 1 ) , $ this -> encodeInteger ( $ entity -> getETicketServiceTyp ( ) , 1 ) , $ this -> encodeInteger ( $ entity -> getETicketServiceArt ( ) , 1 ) , ] ; return implode ( ";" , $ output ) ; }
Parse a user entity .
21,128
public function handle ( MessageSending $ sending ) : void { $ message = $ sending -> message ; $ converter = new CssToInlineStyles ( ) ; if ( $ message -> getContentType ( ) === 'text/html' || ( $ message -> getContentType ( ) === 'multipart/alternative' && $ message -> getBody ( ) ) ) { $ message -> setBody ( $ converter -> convert ( $ message -> getBody ( ) ) ) ; } foreach ( $ message -> getChildren ( ) as $ part ) { if ( Str :: contains ( $ part -> getContentType ( ) , 'text/html' ) ) { $ part -> setBody ( $ converter -> convert ( $ part -> getBody ( ) ) ) ; } } }
Handle converting to inline CSS .
21,129
public function append ( $ lines , $ newline = true , $ indentOffset = 0 ) { $ this -> _buffer [ ] = trim ( $ lines ) ? ( $ this -> _getIndentationString ( $ indentOffset ) . $ lines ) : $ lines ; if ( $ newline ) { $ this -> _buffer [ ] = $ this -> newLineStr ; } return $ this ; }
Appends lines to buffer
21,130
public function getType ( $ item ) { switch ( $ this -> getProductType ( $ item ) ) { case Bundle :: TYPE_CODE : return $ this -> bundle -> create ( ) -> setItem ( $ item ) ; case Grouped :: TYPE_CODE : return $ this -> grouped -> create ( ) -> setItem ( $ item ) ; case Configurable :: TYPE_CODE : return $ this -> configurable -> create ( ) -> setItem ( $ item ) ; default : return $ this -> generic -> create ( ) -> setItem ( $ item ) ; } }
Retrieves the correct type of product helper based on passed item object
21,131
public function save ( array $ attributes = array ( ) , $ prefix = self :: DEFAULT_FILESTORE_PREFIX ) { $ this -> error_code = $ this -> error ; $ this -> error = $ this -> getError ( ) ; $ this -> filesize = $ this -> size ; $ this -> path = $ this -> tmp_name ; $ this -> mimetype = $ this -> detectMimeType ( ) ; $ this -> simpletype = $ this -> parseSimpleType ( ) ; if ( ! $ this -> isSuccessful ( ) ) { return $ this ; } $ prefix = trim ( $ prefix , '/' ) ; if ( ! $ prefix ) { $ prefix = self :: DEFAULT_FILESTORE_PREFIX ; } $ id = elgg_strtolower ( time ( ) . $ this -> name ) ; $ filename = implode ( '/' , array ( $ prefix , $ id ) ) ; $ type = elgg_extract ( 'type' , $ attributes , 'object' ) ; $ subtype = elgg_extract ( 'subtype' , $ attributes , 'file' ) ; $ class = get_subtype_class ( $ type , $ subtype ) ; if ( ! $ class ) { $ class = '\\ElggFile' ; } try { $ filehandler = new $ class ( ) ; foreach ( $ attributes as $ key => $ value ) { $ filehandler -> $ key = $ value ; } $ filehandler -> setFilename ( $ filename ) ; $ filehandler -> title = $ this -> name ; $ filehandler -> originalfilename = $ this -> name ; $ filehandler -> filesize = $ this -> size ; $ filehandler -> mimetype = $ this -> mimetype ; $ filehandler -> simpletype = $ this -> simpletype ; $ filehandler -> open ( "write" ) ; $ filehandler -> close ( ) ; if ( $ this -> simpletype == 'image' ) { $ img = new \ hypeJunction \ Files \ Image ( $ this -> tmp_name ) ; $ img -> save ( $ filehandler -> getFilenameOnFilestore ( ) , hypeApps ( ) -> config -> getSrcCompressionOpts ( ) ) ; } else { move_uploaded_file ( $ this -> tmp_name , $ filehandler -> getFilenameOnFilestore ( ) ) ; } if ( $ filehandler -> save ( ) ) { $ this -> guid = $ filehandler -> getGUID ( ) ; $ this -> file = $ filehandler ; } } catch ( \ Exception $ ex ) { elgg_log ( $ ex -> getMessage ( ) , 'ERROR' ) ; $ this -> error = elgg_echo ( 'upload:error:unknown' ) ; } return $ this ; }
Saves uploaded file to ElggFile with given attributes
21,132
public function getError ( ) { switch ( $ this -> error_code ) { case UPLOAD_ERR_OK : return false ; case UPLOAD_ERR_NO_FILE : $ error = 'upload:error:no_file' ; case UPLOAD_ERR_INI_SIZE : case UPLOAD_ERR_FORM_SIZE : $ error = 'upload:error:file_size' ; default : $ error = 'upload:error:unknown' ; } return elgg_echo ( $ error ) ; }
Get human readable upload error
21,133
public function parseSimpleType ( ) { if ( is_callable ( 'elgg_get_file_simple_type' ) ) { return elgg_get_file_simple_type ( $ this -> detectMimeType ( ) ) ; } $ mime_type = $ this -> detectMimeType ( ) ; switch ( $ mime_type ) { case "application/msword" : case "application/vnd.openxmlformats-officedocument.wordprocessingml.document" : case "application/pdf" : return "document" ; case "application/ogg" : return "audio" ; } if ( preg_match ( '~^(audio|image|video)/~' , $ mime_type , $ m ) ) { return $ m [ 1 ] ; } if ( 0 === strpos ( $ mime_type , 'text/' ) || false !== strpos ( $ mime_type , 'opendocument' ) ) { return "document" ; } return "general" ; }
Parses simple type of the upload
21,134
public function describeStorage ( $ name , $ schema = false ) { if ( ! $ schema ) { $ schema = $ this -> connector -> getSchema ( ) ; } return $ this -> describeTable ( $ name , $ schema ) ; }
Creates the descriptor from an existent MySQL storage .
21,135
private function describeTable ( $ name , $ schema ) { $ data = $ this -> connector -> getQueryAsSingleRow ( 'SELECT t.table_schema AS table_schema, t.table_name AS table_name, t.engine AS engine, t.auto_increment AS auto_increment, t.table_collation AS table_collation, t.table_comment AS table_comment, cs.character_set_name AS table_charset, t.create_options AS create_options FROM information_schema.tables t, information_schema.character_sets cs WHERE t.table_schema=\'%schema$s\' AND t.table_name = \'%table$s\' AND t.table_collation = cs.default_collate_name' , array ( 'schema' => $ schema , 'table' => $ name ) ) ; if ( is_array ( $ data ) ) { $ fields = $ this -> describeTableFields ( $ name , $ schema ) ; $ table [ 'schema' ] = $ data [ 'table_schema' ] ; $ table [ 'name' ] = $ data [ 'table_name' ] ; $ table [ 'engine' ] = $ data [ 'engine' ] ; $ table [ 'type' ] = CMySQLConnector :: TYPE_TABLE ; $ table [ 'autoincrement' ] = $ this -> validateAutoIncrement ( $ data [ 'auto_increment' ] , $ fields ) ; $ table [ 'charset' ] = $ data [ 'table_charset' ] ; $ table [ 'collation' ] = $ data [ 'table_collation' ] ; $ table [ 'create_options' ] = $ data [ 'create_options' ] ; $ table [ 'comment' ] = $ data [ 'table_comment' ] ; $ table [ 'fields' ] = $ fields ; $ table [ 'constraints' ] = $ this -> describeTableConstraints ( $ name , $ table [ 'fields' ] , $ schema ) ; $ descriptor = new CMySQLDescriptor ( $ this -> connector , $ table ) ; } else { $ descriptor = null ; } return $ descriptor ; }
Creates the descriptor from an existent MySQL table .
21,136
public static function getHooks ( $ classpath , $ namespace , $ classname = null , $ extends = null , $ method = null ) { $ hooks = [ ] ; $ filenames = FileHelper :: getFileNames ( $ classpath , ".php" ) ; foreach ( $ filenames as $ filename ) { if ( null !== $ classname && 0 === preg_match ( $ classname , $ filename ) ) { continue ; } try { require_once $ classpath . "/" . $ filename ; } catch ( Error $ ex ) { throw new SyntaxErrorException ( $ classpath . "/" . $ filename ) ; } $ completeClassname = $ namespace . basename ( $ filename , ".php" ) ; try { $ rc = new ReflectionClass ( $ completeClassname ) ; } catch ( Exception $ ex ) { throw new ClassNotFoundException ( $ completeClassname , $ ex ) ; } if ( false === ( null === $ extends || true === $ rc -> isSubclassOf ( $ extends ) ) ) { continue ; } $ hook = [ ] ; $ hook [ "classpath" ] = $ classpath ; $ hook [ "namespace" ] = $ namespace ; $ hook [ "filename" ] = $ filename ; $ hook [ "class" ] = $ rc ; $ hook [ "method" ] = null ; $ hooks [ ] = $ hook ; if ( null === $ method ) { continue ; } try { $ rm = $ rc -> getMethod ( $ method ) ; $ hooks [ count ( $ hooks ) - 1 ] [ "method" ] = $ rm ; } catch ( ReflectionException $ ex ) { throw new MethodNotFoundException ( $ method , $ ex ) ; } } return $ hooks ; }
Get the hooks .
21,137
public static function urlEncodeShortName ( $ object ) { $ classname = static :: getShortName ( $ object ) ; $ explode = preg_replace ( "/([a-z]{1})([A-Z]{1})/" , "$1-$2" , $ classname ) ; return strtolower ( $ explode ) ; }
URL encode a short name .
21,138
public function put ( $ account , $ action , $ parameters = null , $ httpHeadersToSet = array ( ) ) { return $ this -> sendRequest ( 'PUT' , $ account , $ action , $ parameters , null , null , $ httpHeadersToSet ) ; }
Sends a PUT HTTP request .
21,139
public function delete ( $ account , $ action = '' , $ parameters = null ) { return $ this -> sendRequest ( 'DELETE' , $ account , $ action , $ parameters ) ; }
Sends a DELETE HTTP request .
21,140
public static function getPageOffsetAndLimit ( $ pageNumber , $ divider , $ total = - 1 ) { if ( $ pageNumber < 0 || $ divider < 0 ) { return - 1 ; } $ offset = $ pageNumber * $ divider ; $ limit = $ divider ; if ( 0 <= $ total && ( $ total < $ offset || $ total < ( $ offset + $ limit ) ) ) { $ offset = ( static :: getPagesCount ( $ total , $ divider ) - 1 ) * $ divider ; $ limit = $ total - $ offset ; } return [ $ offset , $ limit ] ; }
Get a page offset and limit .
21,141
public static function getPagesCount ( $ linesNumber , $ divider ) { if ( $ linesNumber < 0 || $ divider < 0 ) { return - 1 ; } $ pagesCount = intval ( $ linesNumber / $ divider ) ; if ( 0 < ( $ linesNumber % $ divider ) ) { ++ $ pagesCount ; } return $ pagesCount ; }
Get a pages count .
21,142
public function createAndSave ( $ mageOrderId ) { $ order = $ this -> orderFactory -> create ( ) -> setOrderId ( $ mageOrderId ) -> setStoreId ( $ this -> config -> getStoreViewId ( ) ) -> setShopgateOrderNumber ( $ this -> sgOrder -> getOrderNumber ( ) ) -> setIsShippingBlocked ( $ this -> sgOrder -> getIsShippingBlocked ( ) ) -> setIsPaid ( $ this -> sgOrder -> getIsPaid ( ) ) -> setIsTest ( $ this -> sgOrder -> getIsTest ( ) ) -> setIsCustomerInvoiceBlocked ( $ this -> sgOrder -> getIsCustomerInvoiceBlocked ( ) ) ; try { $ order -> setReceivedData ( \ Zend_Json_Encoder :: encode ( $ this -> sgOrder -> toArray ( ) ) ) ; } catch ( \ InvalidArgumentException $ exception ) { $ this -> sgLogger -> error ( $ exception -> getMessage ( ) ) ; } $ order -> save ( ) ; }
Requires magento object & Base order to be loaded globally
21,143
public function update ( Order $ order ) { if ( $ this -> sgOrder -> getUpdatePayment ( ) ) { $ order -> setIsPaid ( $ this -> sgOrder -> getIsPaid ( ) ) ; } if ( $ this -> sgOrder -> getUpdateShipping ( ) ) { $ order -> setIsShippingBlocked ( $ this -> sgOrder -> getIsShippingBlocked ( ) ) ; } }
Updates isPaid and isShippingBlocked settings using the loaded SG Base class
21,144
public function actionJson ( ) { $ response = \ Yii :: $ app -> getResponse ( ) ; if ( ! is_readable ( $ this -> module -> swaggerPath ) ) { throw new NotFoundHttpException ( ) ; } $ json = file_get_contents ( $ this -> module -> swaggerPath ) ; if ( is_array ( $ this -> module -> swaggerReplace ) ) { foreach ( $ this -> module -> swaggerReplace as $ find => $ replace ) { if ( is_callable ( $ replace ) ) { $ replaceText = call_user_func ( $ replace ) ; } else { $ replaceText = ( string ) $ replace ; } $ json = mb_ereg_replace ( ( string ) $ find , $ replaceText , $ json ) ; } } $ response -> format = Response :: FORMAT_RAW ; $ response -> getHeaders ( ) -> set ( 'Content-Type' , 'application/json; charset=UTF-8' ) ; $ event = new BeforeJsonEvent ; $ event -> responseText = $ json ; $ this -> module -> trigger ( self :: EVENT_BEFORE_JSON , $ event ) ; return $ event -> responseText ; }
Parse swagger . json file do replacements and return json
21,145
public static function createChoices ( array $ choices ) { $ output = [ ] ; $ sorter = new AlphabeticalTreeSort ( $ choices ) ; $ sorter -> sort ( ) ; foreach ( $ sorter -> getNodes ( ) as $ current ) { $ path = static :: getPath ( $ current ) ; if ( false === array_key_exists ( $ path [ 0 ] -> getAlphabeticalTreeNodeLabel ( ) , $ output ) ) { $ output [ $ current -> getAlphabeticalTreeNodeLabel ( ) ] = [ ] ; } if ( 1 === count ( $ path ) ) { continue ; } $ output [ $ path [ 0 ] -> getAlphabeticalTreeNodeLabel ( ) ] [ ] = $ current ; } return $ output ; }
Create a choices .
21,146
public static function removeOrphan ( array & $ nodes = [ ] ) { do { $ found = false ; foreach ( $ nodes as $ k => $ v ) { if ( false === ( $ v instanceof AlphabeticalTreeNodeInterface ) || null === $ v -> getAlphabeticalTreeNodeParent ( ) || true === in_array ( $ v -> getAlphabeticalTreeNodeParent ( ) , $ nodes ) ) { continue ; } unset ( $ nodes [ $ k ] ) ; $ found = true ; } } while ( true === $ found ) ; }
Remove orphan .
21,147
public function getTwig ( ) : \ Twig_Environment { if ( is_null ( $ this -> twig ) ) { $ this -> twigLoader = new \ Twig_Loader_Filesystem ( ) ; $ this -> twig = new \ Twig_Environment ( $ this -> twigLoader ) ; } return $ this -> twig ; }
Get Twig .
21,148
public function all ( ) { if ( ! isset ( $ this -> settings ) ) { $ this -> settings = array_merge ( $ this -> getDefaults ( ) , $ this -> plugin -> getAllSettings ( ) ) ; } return $ this -> settings ; }
Returns all plugin settings
21,149
public function fetchRequestToken ( & $ request ) { $ this -> getVersion ( $ request ) ; $ consumer = $ this -> getConsumer ( $ request ) ; $ token = null ; $ this -> checkSignature ( $ request , $ consumer , $ token ) ; $ callback = $ request -> getParameter ( 'oauth_callback' ) ; $ new_token = $ this -> data_store -> newRequestToken ( $ consumer , $ callback ) ; return $ new_token ; }
Process a request_token request
21,150
public function fetchAccessToken ( & $ request ) { $ this -> getVersion ( $ request ) ; $ consumer = $ this -> getConsumer ( $ request ) ; $ token = $ this -> getToken ( $ request , $ consumer , "request" ) ; $ this -> checkSignature ( $ request , $ consumer , $ token ) ; $ verifier = $ request -> getParameter ( 'oauth_verifier' ) ; $ new_token = $ this -> data_store -> newAccessToken ( $ token , $ consumer , $ verifier ) ; return $ new_token ; }
Process an access_token request .
21,151
protected function getSignatureMethod ( & $ request ) { $ signature_method = @ $ request -> getParameter ( "oauth_signature_method" ) ; if ( ! $ signature_method ) { throw new OAuthException ( 'No signature method parameter. This parameter is required' ) ; } if ( ! in_array ( $ signature_method , array_keys ( $ this -> signature_methods ) ) ) { throw new OAuthException ( "Signature method '$signature_method' not supported " . "try one of the following: " . implode ( ", " , array_keys ( $ this -> signature_methods ) ) ) ; } return $ this -> signature_methods [ $ signature_method ] ; }
Figure out the signature with some defaults .
21,152
protected function getConsumer ( & $ request ) { $ consumer_key = @ $ request -> getParameter ( "oauth_consumer_key" ) ; if ( ! $ consumer_key ) { throw new OAuthException ( "Invalid consumer key" ) ; } $ consumer = $ this -> data_store -> lookupConsumer ( $ consumer_key ) ; if ( ! $ consumer ) { throw new OAuthException ( "Invalid consumer" ) ; } return $ consumer ; }
Try to find the consumer for the provided request s consumer key
21,153
protected function getToken ( & $ request , $ consumer , $ token_type = "access" ) { $ token_field = @ $ request -> getParameter ( 'oauth_token' ) ; $ token = $ this -> data_store -> lookupToken ( $ consumer , $ token_type , $ token_field ) ; if ( ! $ token ) { throw new OAuthException ( "Invalid $token_type token: $token_field" ) ; } return $ token ; }
Try to find the token for the provided request s token key .
21,154
protected function checkNonce ( $ consumer , $ token , $ nonce , $ timestamp ) { if ( ! $ nonce ) { throw new OAuthException ( 'Missing nonce parameter. The parameter is required' ) ; } $ found = $ this -> data_store -> lookupNonce ( $ consumer , $ token , $ nonce , $ timestamp ) ; if ( $ found ) { throw new OAuthException ( "Nonce already used: $nonce" ) ; } }
check that the nonce is not repeated
21,155
protected function convert_to_date_time ( $ value ) { if ( $ value instanceof \ DateTimeInterface ) { return $ value ; } switch ( gettype ( $ value ) ) { case 'string' : return $ this -> convert_string ( $ value ) ; case 'integer' : return $ this -> convert_integer ( $ value ) ; case 'double' : return $ this -> convert_double ( $ value ) ; case 'array' : return $ this -> convert_array ( $ value ) ; } $ this -> error_code = Error \ ErrorLoggerInterface :: INVALID_TYPE_NON_DATE ; return FALSE ; }
Attempts to convert an int string or array to a DateTime object .
21,156
protected function convert_string ( $ value ) { $ format = $ this -> input_data [ 'format' ] ; $ date = \ DateTime :: createFromFormat ( $ format , $ value ) ; $ errors = \ DateTime :: getLastErrors ( ) ; if ( $ errors [ 'warning_count' ] > 0 ) { $ this -> error_code = Error \ ErrorLoggerInterface :: INVALID_DATE_FORMAT ; return FALSE ; } return $ date ; }
Attempts to convert a string into a DateTime object .
21,157
public function getStereoType ( \ DOMElement $ diaObject ) { $ xpath = $ diaObject -> getNodePath ( ) . '/dia:attribute[@name="stereotype"]/dia:string' ; $ nodeList = $ this -> engine -> query ( $ xpath ) ; if ( $ nodeList -> length == 1 ) { $ stereoType = str_replace ( '#' , '' , $ nodeList -> item ( 0 ) -> nodeValue ) ; return $ stereoType ; } return false ; }
Getter for retrieving the stereotype from a DIA object structure .
21,158
public function getAttributes ( \ DOMElement $ diaObject ) { $ xpath = $ diaObject -> getNodePath ( ) . '/dia:attribute[@name="attributes"]/*' ; $ nodeList = $ this -> engine -> query ( $ xpath ) ; if ( $ nodeList -> length > 0 ) { return $ nodeList ; } return false ; }
Getter for retrieving all attributes from a DIA object structure
21,159
public function getElement ( \ DOMElement $ nodeList , $ level = 0 , $ showPaths = false ) { $ tabs = str_repeat ( "\t" , $ level ) ; $ output = '' ; if ( ! $ showPaths ) { $ output = "" ; foreach ( $ nodeList as $ attribute ) { $ output .= $ tabs . $ attribute -> nodeName . " = " . $ attribute -> nodeValue . "\n" ; } $ output .= $ tabs . $ nodeList -> nodeName . " = " . $ nodeList -> nodeValue . "\n" ; } else { $ output .= $ nodeList -> getNodePath ( ) . "\n" ; } foreach ( $ nodeList -> childNodes as $ childObject ) { if ( $ childObject instanceof \ DOMElement ) { $ output .= $ this -> getElement ( $ childObject , $ level + 1 , $ showPaths ) ; } elseif ( $ showPaths ) { $ output .= $ childObject -> getNodePath ( ) . "\n" ; } } return $ output ; }
Getter for retrieving all elements from a DIA object structure
21,160
public function getPaths ( \ DOMElement $ nodeList , $ level = 0 ) { $ output = $ nodeList -> getNodePath ( ) ; foreach ( $ nodeList -> childNodes as $ childObject ) { $ output .= $ childObject -> getNodePath ( ) . "\n" ; if ( $ childObject instanceof \ DOMElement ) { $ output .= $ this -> getElement ( $ childObject , $ level + 1 , true ) ; } } return $ output ; }
Getter for retrieving xpath from a DOMElement
21,161
public function retriveAttributeType ( \ DOMElement $ element ) { $ name = $ this -> engine -> query ( $ element -> getNodePath ( ) . '/dia:attribute[@name="type"]/dia:string' ) ; return $ this -> cleanString ( $ name -> item ( 0 ) -> nodeValue ) ; }
Retrieve attribute type
21,162
public function retriveAttributeVisibility ( \ DOMElement $ element ) { $ name = $ this -> engine -> query ( $ element -> getNodePath ( ) . '/dia:attribute[@name="visibility"]/dia:enum' ) ; $ propertyVisibility = $ name -> item ( 0 ) -> attributes -> getNamedItem ( 'val' ) -> nodeValue ; return self :: $ propertyVisibilityTypes [ $ propertyVisibility ] ; }
Retrieve attribute visibility
21,163
public function retriveLayerObjects ( ) { $ classes = [ ] ; foreach ( $ this -> engine -> query ( '//dia:diagram/dia:layer' ) as $ layer ) { if ( $ layer -> nodeName == 'dia:layer' ) { foreach ( $ layer -> childNodes as $ elementObject ) { if ( $ elementObject -> nodeName == 'dia:object' ) { foreach ( $ elementObject -> childNodes as $ childNodesAttributes ) { if ( $ childNodesAttributes -> nodeName == 'dia:attribute' && $ childNodesAttributes -> attributes -> getNamedItem ( "name" ) -> nodeValue == 'name' ) { $ name = str_replace ( [ '#' ] , [ '' ] , $ childNodesAttributes -> childNodes -> item ( 1 ) -> nodeValue ) ; $ classes [ $ name ] = $ elementObject ; } } } } } } return $ classes ; }
Retrieve layer objects
21,164
private function mergeHeaders ( ) { $ mergedHeaders = [ ] ; foreach ( array_merge ( $ this -> getConfiguration ( ) -> getHeaders ( ) , $ this -> getHeaders ( ) ) as $ key => $ value ) { $ mergedHeaders [ ] = implode ( ": " , [ $ key , $ value ] ) ; } return $ mergedHeaders ; }
Merge the headers .
21,165
private function mergeURL ( ) { $ mergedURL = [ ] ; $ mergedURL [ ] = $ this -> getConfiguration ( ) -> getHost ( ) ; if ( null !== $ this -> getResourcePath ( ) && "" !== $ this -> getResourcePath ( ) ) { $ mergedURL [ ] = $ this -> getResourcePath ( ) ; } return implode ( "/" , $ mergedURL ) ; }
Merge the URL .
21,166
private function parseHeader ( $ rawHeader ) { $ headers = [ ] ; $ key = "" ; foreach ( explode ( "\n" , $ rawHeader ) as $ h ) { $ h = explode ( ":" , $ h , 2 ) ; if ( true === isset ( $ h [ 1 ] ) ) { if ( false === isset ( $ headers [ $ h [ 0 ] ] ) ) { $ headers [ $ h [ 0 ] ] = trim ( $ h [ 1 ] ) ; } elseif ( true === is_array ( $ headers [ $ h [ 0 ] ] ) ) { $ headers [ $ h [ 0 ] ] = array_merge ( $ headers [ $ h [ 0 ] ] , [ trim ( $ h [ 1 ] ) ] ) ; } else { $ headers [ $ h [ 0 ] ] = array_merge ( [ $ headers [ $ h [ 0 ] ] ] , [ trim ( $ h [ 1 ] ) ] ) ; } $ key = $ h [ 0 ] ; } else { if ( "\t" === substr ( $ h [ 0 ] , 0 , 1 ) ) { $ headers [ $ key ] .= "\r\n\t" . trim ( $ h [ 0 ] ) ; } elseif ( ! $ key ) { $ headers [ 0 ] = trim ( $ h [ 0 ] ) ; } trim ( $ h [ 0 ] ) ; } } return $ headers ; }
Parse the raw header .
21,167
public function registerNamespace ( $ prefix , $ uri ) { $ this -> initializeXPath ( ) ; $ this -> xpath -> registerNamespace ( $ prefix , $ uri ) ; }
Register a prefix and uri to the xpath namespace .
21,168
public function getSpecification ( $ element = '' ) { if ( isset ( $ element ) && $ element !== '' ) { $ spec = $ this -> pattern -> specification [ $ this -> getOption ( 'doctype' ) ] [ $ element ] ; } else { $ spec = $ this -> pattern -> specification [ $ this -> getOption ( 'doctype' ) ] ; } return $ spec ; }
TESTING Getter for retriving the specification in the current context .
21,169
public function run ( $ data = '' , $ load = 'string' , $ type = 'html' ) { if ( ! empty ( $ data ) ) { $ this -> $ type = $ type ; if ( file_exists ( $ data ) ) { $ pathHash = md5 ( $ data ) ; $ this -> views [ $ pathHash ] = $ data ; } switch ( $ load . '.' . $ type ) { default : return false ; case 'string.html' : if ( @ $ this -> loadHTML ( $ data ) ) { $ objectName = 'Fabrication\\Html' ; $ this -> pattern = new $ objectName ( $ this ) ; $ this -> mapSymbols ( ) ; return true ; } else { return false ; } case 'file.html' : if ( @ $ this -> loadHTMLFile ( $ data ) ) { $ this -> mapSymbols ( ) ; return true ; } else { return false ; } case 'string.xml' : if ( $ this -> loadXML ( $ data ) ) { $ this -> mapSymbols ( ) ; return true ; } else { return false ; } case 'file.xml' : $ contents = file_get_contents ( $ data ) ; if ( @ $ this -> loadXML ( $ contents ) ) { $ this -> mapSymbols ( ) ; return true ; } else { return false ; } } } return ; }
Run method once the all input have been set . Then you will have a valid document with a searchable path .
21,170
public function mapSymbols ( ) { foreach ( $ this -> input as $ key => $ input ) { foreach ( $ this -> symbols as $ skey => $ svalue ) { if ( substr ( $ key , 0 , 1 ) == $ svalue ) { $ keyWithoutSymbol = str_replace ( $ svalue , '' , $ key ) ; if ( is_string ( $ input ) ) { $ this -> setElementBy ( $ skey , $ keyWithoutSymbol , $ input ) ; } if ( is_array ( $ input ) ) { $ this -> setElementBy ( $ skey , $ keyWithoutSymbol , $ input ) ; } if ( is_object ( $ input ) ) { $ this -> setElementBy ( $ skey , $ keyWithoutSymbol , $ input ) ; } } } } }
Symbol mapper for engine input symbolic values to engine element attribute values for a basic mapping sub - system .
21,171
public function saveHTML ( $ path = '' , $ trim = true ) { if ( is_string ( $ path ) && $ path !== '' ) { $ this -> output [ 'raw' ] = $ this -> view ( $ path ) ; } else { $ this -> output [ 'raw' ] = parent :: saveHTML ( ) ; } $ this -> outputProcess ( ) ; $ raw = $ this -> output [ 'raw' ] ; return $ trim ? trim ( $ raw ) : $ raw ; }
Extend the native saveHTML method . Allow path search functionality .
21,172
public function saveFabric ( $ type = 'html' ) { switch ( $ type ) { case 'html' : $ this -> output [ 'raw' ] = parent :: saveHTML ( ) ; break ; case 'xml' : $ this -> output [ 'raw' ] = parent :: saveXML ( ) ; break ; } $ this -> outputProcess ( ) ; return $ this -> getDoctype ( ) . trim ( $ this -> output [ 'raw' ] ) ; }
Return the engine output html view .
21,173
public function outputProcess ( ) { $ this -> output [ 'raw' ] = preg_replace ( '/^<!DOCTYPE[^>]+>/U' , '' , $ this -> output [ 'raw' ] ) ; if ( $ this -> outputProcess && $ this -> getOption ( 'process' ) ) { $ this -> output [ 'raw' ] = $ this -> getDoctype ( ) . $ this -> output [ 'raw' ] ; if ( $ this -> getOption ( 'process.body.image' ) ) { $ this -> output [ 'raw' ] = preg_replace ( '/<img(.*)>/sU' , '<img\\1 />' , $ this -> output [ 'raw' ] ) ; } if ( $ this -> getOption ( 'process.body.br' ) ) { $ this -> output [ 'raw' ] = preg_replace ( '/<br(.*)>/sU' , '<br\\1 />' , $ this -> output [ 'raw' ] ) ; } if ( $ this -> getOption ( 'process.body.hr' ) ) { $ this -> output [ 'raw' ] = preg_replace ( '/<hr(.*)>/sU' , '<hr\\1 />' , $ this -> output [ 'raw' ] ) ; } $ this -> output [ 'raw' ] = trim ( $ this -> output [ 'raw' ] ) ; return $ this -> outputProcess ; } return $ this -> outputProcess ; }
Time to sort out the plethora of DOMDocument bugs .
21,174
public static function dump ( $ data , $ return = false ) { $ result = '' ; if ( Fabrication :: isCli ( ) ) { $ end = "\n" ; } else { $ end = "<br />\n" ; } if ( is_object ( $ data ) ) { $ classname = get_class ( $ data ) ; $ result = str_repeat ( '-' , 80 ) . $ end . "\t" . __METHOD__ . ' Type: ' . gettype ( $ data ) . "\tReturn:" . var_export ( $ return , true ) . $ end . str_repeat ( '-' , 80 ) . $ end . "Object Instance: $classname: $end" . "Object Methods $end" ; $ class_methods = get_class_methods ( $ data ) ; if ( count ( $ class_methods ) > 0 ) { foreach ( $ class_methods as $ method ) { $ result .= "\t" . $ method . $ end ; } } else { $ result .= "No methods found.$end" ; } $ result .= $ end ; $ result .= "Object XPath:$end" ; $ result .= $ end ; switch ( $ classname ) { case 'DOMAttr' : $ result .= "DOMAttr XPath: {$data->getNodePath()}$end" . $ data -> ownerDocument -> saveXML ( $ data ) ; break ; case 'DOMDocument' : $ result .= "DOMDocument XPath: {$data->getNodePath()}$end" . $ data -> saveXML ( $ data ) ; break ; case 'DOMElement' : $ result .= "DOMElement XPath: {$data->getNodePath()}$end" . $ data -> ownerDocument -> saveXML ( $ data ) ; break ; case 'DOMNodeList' : for ( $ i = 0 ; $ i < $ data -> length ; $ i ++ ) { $ result .= "DOMNodeList Item #$i, " . "XPath: {$data->item($i)->getNodePath()}$end" . "{$data->item($i)->ownerDocument->saveXML($data->item($i))}$end" ; } break ; default : $ result .= var_export ( $ data , true ) ; } } if ( is_array ( $ data ) ) { $ result = $ end . $ end . str_repeat ( '-' , 80 ) . $ end . "| DUMP Type:" . gettype ( $ data ) . "\tReturn:" . var_export ( $ return , true ) . $ end . str_repeat ( '-' , 80 ) . $ end . $ end ; } if ( is_string ( $ data ) ) { $ result = var_export ( $ data , true ) ; } if ( is_int ( $ data ) ) { $ result = var_export ( $ data , true ) ; } if ( $ return ) { return $ result . $ end ; } else { echo $ result . $ end ; } }
Return a string representation of the data .
21,175
public function createPattern ( $ name = 'html' , $ attributes = array ( ) , $ data = array ( ) ) { $ patternName = ucfirst ( $ name ) ; $ objectName = 'Library\Pattern\\' . $ patternName ; $ pattern = new $ objectName ( $ this , $ attributes , $ data ) ; return $ pattern ; }
Pattern method for fabrication - framework standardized patterns .
21,176
public function specification ( $ pattern = 'html' , $ value = '' , $ attributes = [ ] , $ contract = [ ] ) { if ( ! is_array ( $ contract ) ) { return ; } $ this -> appendChild ( $ this -> create ( $ pattern , $ value , $ attributes , $ contract ) ) ; return $ this ; }
Document specification pattern .
21,177
public function template ( $ pattern , $ dataset = array ( ) , $ map = 'id' ) { if ( count ( $ dataset ) == 0 ) { return false ; } try { $ template = '' ; if ( is_string ( $ pattern ) ) { $ engine = new FabricationEngine ( ) ; $ engine -> setOption ( 'doctype' , 'html.5' ) ; $ engine -> loadHTML ( $ pattern ) ; $ templateDiv = $ engine -> getDiv ( ) ; if ( $ templateDiv ) { $ template = $ templateDiv -> item ( 0 ) ; } } if ( is_object ( $ pattern ) ) { $ template = $ pattern ; } if ( is_object ( $ template ) ) { $ container = $ this -> create ( $ template -> nodeName , $ template -> nodeValue ) ; foreach ( $ dataset as $ key => $ row ) { foreach ( $ template -> childNodes as $ child ) { if ( $ child -> nodeName == '#text' ) { continue ; } if ( is_object ( $ child -> attributes -> getNamedItem ( $ map ) ) ) { $ mappedName = $ child -> attributes -> getNamedItem ( $ map ) -> nodeName ; $ mappedValue = $ child -> attributes -> getNamedItem ( $ map ) -> nodeValue ; $ nodeAttributes = array ( ) ; foreach ( $ child -> attributes as $ attribute ) { $ nodeAttributes [ $ attribute -> nodeName ] = $ attribute -> nodeValue ; } if ( in_array ( $ mappedValue , array_keys ( $ row ) ) ) { $ nodeAttributes [ $ mappedName ] = $ mappedValue . '_' . ( $ key + 1 ) ; $ node = $ this -> create ( $ child -> nodeName , $ row [ $ mappedValue ] , $ nodeAttributes ) ; $ container -> appendChild ( $ node ) ; } } } } return $ container ; } return false ; } catch ( \ Exception $ ex ) { echo $ ex -> getMessage ( ) ; } }
Template method allows for an element and its children to be used as the pattern for an array dataset the default map for the element children atrribute is id
21,178
public function view ( $ path = '' , $ trim = true , $ return = true ) { if ( ! empty ( $ path ) ) { $ results = $ this -> query ( $ path ) ; $ template = new FabricationEngine ( ) ; foreach ( $ results as $ result ) { $ node = $ template -> importNode ( $ result , true ) ; $ template -> appendChild ( $ node ) ; } if ( $ trim ) { $ buffer = trim ( $ template -> saveHTML ( ) ) ; } else { $ buffer = $ template -> saveHTML ( ) ; } } else { if ( $ trim ) { $ buffer = trim ( $ this -> saveHTML ( ) ) ; } else { $ buffer = $ this -> saveHTML ( ) ; } } if ( $ return ) { return $ buffer ; } echo $ buffer ; }
View the DOMTree in HTML either in full or search using XPath for the first argument also trim return and change the output type html xml .
21,179
public function query ( $ path ) { $ this -> initializeXPath ( ) ; if ( $ path ) { return $ this -> xpath -> query ( $ path ) ; } return false ; }
Main XPath query method .
21,180
public function output ( $ key = '' , $ query = '' , $ options = array ( ) ) { if ( empty ( $ query ) && isset ( $ this -> input [ $ key ] ) ) { return $ this -> input [ $ key ] ; } if ( empty ( $ options ) ) { $ options = array ( 'return' => true , 'tags' => true , 'echo' => false ) ; } $ output = $ this -> templateTextElement ( $ key , $ query , $ options ) ; if ( array_key_exists ( 'return' , $ options ) ) { if ( $ options [ 'return' ] ) { return $ output ; } } else { return false ; } }
Output key value from the input array .
21,181
public function convert ( $ data ) { $ data = trim ( $ data ) ; try { $ engine = new FabricationEngine ; $ engine -> run ( $ data ) ; if ( $ engine -> getBody ( ) -> item ( 0 ) == null ) { $ node = $ engine -> getHead ( ) -> item ( 0 ) -> childNodes -> item ( 0 ) ; return $ this -> importNode ( $ node , true ) ; } if ( $ engine -> getBody ( ) -> item ( 0 ) !== null ) { $ node = $ engine -> getBody ( ) -> item ( 0 ) -> childNodes -> item ( 0 ) ; return $ this -> importNode ( $ node , true ) ; } return false ; } catch ( \ Exception $ e ) { return ( 'FabricationEngine :: convert : ' . $ e -> getMessage ( ) ) ; } }
Helper to allow the import of a html string into the current engine without causing DOM hierarchy errors .
21,182
public function htmlToElement ( $ html ) { $ fabrication = new FabricationEngine ; $ fabrication -> run ( $ html ) ; $ element = $ this -> query ( '//html/body' ) -> item ( 0 ) ; $ element -> appendChild ( $ this -> importNode ( $ fabrication -> query ( $ this -> xpath . '/*' ) -> item ( 0 ) , true ) ) ; return $ element ; }
Import a html string into the current engine without causing DOM hierarchy errors .
21,183
public function setElementBy ( $ element , $ value , $ nodeValue ) { $ xql = "//*[@$element='$value']" ; if ( is_object ( $ nodeValue ) ) { $ result = $ this -> query ( $ xql ) -> item ( 0 ) -> appendChild ( $ this -> importNode ( $ nodeValue , true ) ) ; } else { $ result = $ this -> query ( $ xql ) -> item ( 0 ) -> nodeValue = $ nodeValue ; } return $ result ; }
Setter for changing a element
21,184
public function setHtml ( $ q , $ value ) { $ this -> getHtml ( $ q ) -> item ( 0 ) -> nodeValue = "$value" ; return $ this -> getHtml ( $ q ) -> item ( 0 ) ; }
Setter for changing HTML element .
21,185
public function timeTaken ( ) { $ timeStop = microtime ( true ) ; $ timeTaken = ( float ) substr ( - ( $ this -> timeStarted - $ timeStop ) , 0 , 5 ) ; return $ timeTaken ; }
Generate the amount of time taken since the object was contructed .
21,186
public static function getFields ( string $ module ) { $ modules = Modules :: findFirstByName ( $ module ) ; if ( $ modules ) { return self :: find ( [ 'modules_id = ?0' , 'bind' => [ $ modules -> id ] , 'columns' => 'name, label, type' ] ) ; } return null ; }
Get the felds of this custom field module
21,187
public function addNode ( AbstractNode $ node ) { $ node -> parent = $ this ; $ this -> index [ $ node -> id ] = count ( $ this -> nodes ) ; $ this -> nodes [ ] = $ node ; return $ this ; }
Add a children node .
21,188
public function getNodeAt ( $ position ) { if ( 0 <= $ position && $ position <= count ( $ this -> nodes ) - 1 ) { return $ this -> nodes [ $ position ] ; } return null ; }
Get a node at position .
21,189
public function getNodeById ( $ id , $ recursively = false ) { $ found = null ; if ( true === array_key_exists ( $ id , $ this -> index ) ) { $ found = $ this -> getNodeAt ( $ this -> index [ $ id ] ) ; } if ( null === $ found && true === $ recursively ) { foreach ( $ this -> nodes as $ current ) { $ found = $ current -> getNodeById ( $ id , $ recursively ) ; if ( null !== $ found ) { break ; } } } return $ found ; }
Get a node by id .
21,190
public function removeNode ( AbstractNode $ node ) { if ( true === array_key_exists ( $ node -> id , $ this -> index ) ) { unset ( $ this -> nodes [ $ this -> index [ $ node -> id ] ] ) ; unset ( $ this -> index [ $ node -> id ] ) ; $ node -> parent = null ; } return $ this ; }
Remove a node .
21,191
public static function getDocBlockFactory ( ) : DocBlockFactory { if ( is_null ( self :: $ docBlockFactory ) ) { self :: $ docBlockFactory = DocBlockFactory :: createInstance ( ) ; } return self :: $ docBlockFactory ; }
Get DockBlockFactory object to read doc block .
21,192
private function getHttpMethod ( ) : string { if ( ! empty ( $ _SERVER [ 'HTTP_X_HTTP_METHOD_OVERRIDE' ] ) ) { $ method = mb_strtoupper ( $ _SERVER [ 'HTTP_X_HTTP_METHOD_OVERRIDE' ] ) ; } else { $ method = mb_strtoupper ( $ _SERVER [ 'REQUEST_METHOD' ] ) ; } switch ( $ method ) { case 'GET' : return static :: HTTP_METHOD_GET ; case 'HEAD' : return static :: HTTP_METHOD_HEAD ; case 'POST' : return static :: HTTP_METHOD_POST ; case 'OPTIONS' : return static :: HTTP_METHOD_OPTIONS ; case 'CONNECT' : return static :: HTTP_METHOD_CONNECT ; case 'TRACE' : return static :: HTTP_METHOD_TRACE ; case 'PUT' : return static :: HTTP_METHOD_PUT ; case 'DELETE' : return static :: HTTP_METHOD_DELETE ; default : return static :: HTTP_METHOD_UNKNOWN ; } }
Get HTTP method of request .
21,193
private function getHttpPath ( ) : ? string { $ path = null ; if ( isset ( $ _SERVER [ 'REQUEST_URI' ] ) ) { $ path = parse_url ( $ _SERVER [ 'REQUEST_URI' ] , PHP_URL_PATH ) ; } return $ path ; }
Get HTTP path of request .
21,194
protected function getHttpHeaders ( string $ prefix = null ) : array { $ headers = [ ] ; if ( function_exists ( '\getallheaders' ) ) { $ headers = \ getallheaders ( ) ? : [ ] ; } else { foreach ( $ _SERVER as $ name => $ value ) { if ( substr ( $ name , 0 , 5 ) == 'HTTP_' ) { $ headers [ str_replace ( ' ' , '-' , ucwords ( strtolower ( str_replace ( '_' , ' ' , substr ( $ name , 5 ) ) ) ) ) ] = $ value ; } else { if ( $ name === 'CONTENT_TYPE' ) { $ headers [ 'Content-Type' ] = $ value ; } } } } if ( ! empty ( $ prefix ) ) { $ prefixLength = mb_strlen ( $ prefix ) ; $ headers = array_filter ( $ headers , function ( $ key ) use ( $ prefix , $ prefixLength ) { return substr ( $ key , 0 , $ prefixLength ) == $ prefix ; } , ARRAY_FILTER_USE_KEY ) ; } return $ headers ; }
Get HTTP headers .
21,195
public function getNodeInSparqlFormat ( Node $ node , $ var = null ) { if ( $ node -> isConcrete ( ) ) { return $ node -> toNQuads ( ) ; } if ( null !== $ var ) { return '?' . $ var ; } else { return '?' . uniqid ( 'tempVar' ) ; } }
Returns given Node instance in SPARQL format which is in NQuads or as Variable .
21,196
public function getQueryType ( $ query ) { $ adaptedQuery = preg_replace ( '/PREFIX\s+[a-z0-9\-]+\:\s*\<[a-z0-9\:\/\.\#\-\~\_]+\>/si' , '' , $ query ) ; $ adaptedQuery = preg_replace ( "/(^[\r\n]*|[\r\n]+)[\s\t]*[\r\n]+/" , '' , trim ( $ adaptedQuery ) ) ; $ adaptedQuery = strtolower ( $ adaptedQuery ) ; $ firstPart = substr ( $ adaptedQuery , 0 , 3 ) ; switch ( $ firstPart ) { case 'ask' : return 'askQuery' ; case 'con' : return 'constructQuery' ; case 'des' : return 'describeQuery' ; default : $ firstPart = substr ( $ adaptedQuery , 0 , 6 ) ; switch ( $ firstPart ) { case 'clear ' : return 'graphQuery' ; case 'create' : return 'graphQuery' ; case 'delete' : return 'updateQuery' ; case 'drop g' : return 'graphQuery' ; case 'drop s' : return 'graphQuery' ; case 'insert' : return 'updateQuery' ; case 'select' : return 'selectQuery' ; default : if ( false !== strpos ( $ adaptedQuery , 'with' ) && false !== strpos ( $ adaptedQuery , 'delete' ) && false !== strpos ( $ adaptedQuery , 'where' ) ) { return 'updateQuery' ; } elseif ( false !== strpos ( $ adaptedQuery , 'with' ) && false !== strpos ( $ adaptedQuery , 'delete' ) ) { return 'updateQuery' ; } } } throw new \ Exception ( 'Unknown query type "' . $ firstPart . '" for query: ' . $ adaptedQuery ) ; }
Get type for a given SPARQL query .
21,197
public function _afterLoad ( ) { $ value = $ this -> getValue ( ) ; $ this -> setValue ( empty ( $ value ) ? false : $ this -> encoder -> decode ( $ value ) ) ; parent :: _afterLoad ( ) ; }
Converts pre v2 . 2 . 0 serialized database data to display properly
21,198
public function removeDuplicates ( $ values ) { foreach ( $ values as $ key => $ option ) { $ value = $ this -> getCmsPageValue ( $ option ) ; if ( $ value ) { if ( $ this -> listHasValue ( $ value ) ) { unset ( $ values [ $ key ] ) ; } else { $ this -> setListValue ( $ value ) ; } } } return $ values ; }
Searches for duplicate CMS pages before saving
21,199
public function createParserFor ( $ serialization ) { if ( ! in_array ( $ serialization , $ this -> getSupportedSerializations ( ) ) ) { throw new \ Exception ( 'Requested serialization ' . $ serialization . ' is not available in: ' . implode ( ', ' , $ this -> getSupportedSerializations ( ) ) ) ; } return new ParserHardf ( $ this -> nodeFactory , $ this -> statementFactory , $ this -> statementIteratorFactory , $ this -> RdfHelpers , $ serialization ) ; }
Creates a Parser instance for a given serialization if available .