idx int64 0 60.3k | question stringlengths 99 4.85k | target stringlengths 5 718 |
|---|---|---|
2,800 | public static function determineFilterType ( $ value ) { $ pattern = '/(\s+\+\s+)|(\+\+\+)/' ; return preg_match ( $ pattern , $ value ) === 1 ? Datasource :: FILTER_AND : Datasource :: FILTER_OR ; } | By default all Symphony filters are considering to be OR and + filters are used for AND . They are all used and Entries must match each filter to be included . It is possible to use OR filtering in a field by using an to separate the values . |
2,801 | public static function splitFilter ( $ filter_type , $ value ) { $ pattern = $ filter_type === Datasource :: FILTER_AND ? '\+' : '(?<!\\\\),' ; $ value = preg_split ( '/\s*' . $ pattern . '\s*/' , $ value , - 1 , PREG_SPLIT_NO_EMPTY ) ; $ value = array_map ( 'trim' , $ value ) ; $ value = array_map ( array ( 'Datasourc... | Splits the filter string value into an array . |
2,802 | public static function findParameterInEnv ( $ needle , $ env ) { if ( isset ( $ env [ 'env' ] [ 'url' ] [ $ needle ] ) ) { return $ env [ 'env' ] [ 'url' ] [ $ needle ] ; } if ( isset ( $ env [ 'env' ] [ 'pool' ] [ $ needle ] ) ) { return $ env [ 'env' ] [ 'pool' ] [ $ needle ] ; } if ( isset ( $ env [ 'param' ] [ $ ne... | Parameters can exist in three different facets of Symphony ; in the URL in the parameter pool or as an Symphony param . This function will attempt to find a parameter in those three areas and return the value . If it is not found null is returned |
2,803 | public static function compare ( $ input , $ hash , $ isHash = false ) { $ salt = self :: extractSalt ( $ hash ) ; $ iterations = self :: extractIterations ( $ hash ) ; $ keylength = strlen ( base64_decode ( self :: extractHash ( $ hash ) ) ) ; return $ hash === self :: hash ( $ input , $ salt , $ iterations , $ keylen... | Compares a given hash with a cleantext password . Also extracts the salt from the hash . |
2,804 | public function getChild ( $ position ) { if ( ! isset ( $ this -> _children [ $ this -> getRealIndex ( $ position ) ] ) ) { return null ; } return $ this -> _children [ $ this -> getRealIndex ( $ position ) ] ; } | Retrieves a child - element by position |
2,805 | public function getChildByName ( $ name , $ position ) { $ result = array_values ( $ this -> getChildrenByName ( $ name ) ) ; if ( ! isset ( $ result [ $ position ] ) ) { return null ; } return $ result [ $ position ] ; } | Retrieves child - element by name and position . If no child is found NULL will be returned . |
2,806 | public function setValue ( $ value ) { if ( is_array ( $ value ) ) { $ value = implode ( ', ' , $ value ) ; } if ( ! is_null ( $ value ) ) { $ this -> _value = $ value ; $ this -> appendChild ( $ value ) ; } } | Sets the value of the XMLElement . Checks to see whether the value should be prepended or appended to the children . |
2,807 | public function replaceValue ( $ value ) { foreach ( $ this -> _children as $ i => $ child ) { if ( $ child instanceof XMLElement ) { continue ; } unset ( $ this -> _children [ $ i ] ) ; } $ this -> setValue ( $ value ) ; } | This function will remove all text attributes from the XMLElement node and replace them with the given value . |
2,808 | public function setAttributeArray ( array $ attributes = null ) { if ( ! is_array ( $ attributes ) || empty ( $ attributes ) ) { return ; } foreach ( $ attributes as $ name => $ value ) { $ this -> setAttribute ( $ name , $ value ) ; } } | A convenience method to quickly add multiple attributes to an XMLElement |
2,809 | public function appendChildArray ( array $ children = null ) { if ( is_array ( $ children ) && ! empty ( $ children ) ) { foreach ( $ children as $ child ) { $ this -> appendChild ( $ child ) ; } } } | A convenience method to add children to an XMLElement quickly . |
2,810 | public function addClass ( $ class ) { $ current = preg_split ( '%\s+%' , $ this -> getAttribute ( 'class' ) , 0 , PREG_SPLIT_NO_EMPTY ) ; $ added = preg_split ( '%\s+%' , $ class , 0 , PREG_SPLIT_NO_EMPTY ) ; $ current = array_merge ( $ current , $ added ) ; $ classes = implode ( ' ' , $ current ) ; $ this -> setAttri... | A convenience method to quickly add a CSS class to this XMLElement s existing class attribute . If the attribute does not exist it will be created . |
2,811 | public function removeClass ( $ class ) { $ classes = preg_split ( '%\s+%' , $ this -> getAttribute ( 'class' ) , 0 , PREG_SPLIT_NO_EMPTY ) ; $ removed = preg_split ( '%\s+%' , $ class , 0 , PREG_SPLIT_NO_EMPTY ) ; $ classes = array_diff ( $ classes , $ removed ) ; $ classes = implode ( ' ' , $ classes ) ; $ this -> se... | A convenience method to quickly remove a CSS class from an XMLElement s existing class attribute . If the attribute does not exist this method will do nothing . |
2,812 | public function replaceChildAt ( $ index , XMLElement $ child = null ) { if ( ! is_numeric ( $ index ) ) { return false ; } $ this -> validateChild ( $ child ) ; $ index = $ this -> getRealIndex ( $ index ) ; if ( ! isset ( $ this -> _children [ $ index ] ) ) { return false ; } $ this -> _children [ $ index ] = $ child... | Given the position of the child to replace and an XMLElement of the replacement child this function will replace one child with another |
2,813 | public static function stripInvalidXMLCharacters ( $ value ) { if ( Lang :: isUnicodeCompiled ( ) ) { return preg_replace ( '/[^\x{0009}\x{000a}\x{000d}\x{0020}-\x{D7FF}\x{E000}-\x{FFFD}]+/u' , ' ' , $ value ) ; } else { $ ret = '' ; if ( empty ( $ value ) ) { return $ ret ; } $ length = strlen ( $ value ) ; for ( $ i ... | This function strips characters that are not allowed in XML |
2,814 | public function generate ( $ indent = false , $ tab_depth = 0 , $ has_parent = false ) { $ result = null ; $ newline = ( $ indent ? PHP_EOL : null ) ; if ( ! $ has_parent ) { if ( $ this -> _includeHeader ) { $ result .= sprintf ( '<?xml version="%s" encoding="%s" ?>%s' , $ this -> _version , $ this -> _encoding , $ ne... | This function will turn the XMLElement into a string representing the element as it would appear in the markup . The result is valid XML . |
2,815 | public static function convertFromXMLString ( $ root_element , $ xml ) { $ doc = new DOMDocument ( '1.0' , 'utf-8' ) ; $ doc -> loadXML ( $ xml ) ; return self :: convertFromDOMDocument ( $ root_element , $ doc ) ; } | Given a string of XML this function will convert it to an XMLElement object and return the result . |
2,816 | public static function convertFromDOMDocument ( $ root_element , DOMDocument $ doc ) { $ xpath = new DOMXPath ( $ doc ) ; $ root = new XMLElement ( $ root_element ) ; foreach ( $ xpath -> query ( '.' ) as $ node ) { self :: convertNode ( $ root , $ node ) ; } return $ root ; } | Given a DOMDocument this function will convert it to an XMLElement object and return the result . |
2,817 | private static function convertNode ( XMLElement $ element , DOMNode $ node ) { if ( $ node -> hasAttributes ( ) ) { foreach ( $ node -> attributes as $ name => $ attrEl ) { $ element -> setAttribute ( $ name , General :: sanitize ( $ attrEl -> value ) ) ; } } if ( $ node -> hasChildNodes ( ) ) { foreach ( $ node -> ch... | Given a DOMNode this function will help replicate it as an XMLElement object |
2,818 | public function retrieve ( $ index = null ) { return ! is_null ( $ index ) ? Profiler :: $ _samples [ $ index ] : Profiler :: $ _samples ; } | Given an index return the sample at that position otherwise just return all samples . |
2,819 | public function retrieveGroup ( $ group ) { $ result = array ( ) ; foreach ( Profiler :: $ _samples as $ record ) { if ( $ record [ 3 ] == $ group ) { $ result [ ] = $ record ; } } return $ result ; } | Returns all the samples that belong to a particular group . |
2,820 | public function retrieveTotalMemoryUsage ( ) { $ base = $ this -> retrieve ( 0 ) ; $ total = $ last = 0 ; foreach ( $ this -> retrieve ( ) as $ item ) { $ total += max ( 0 , ( ( $ item [ 5 ] - $ base [ 5 ] ) - $ last ) ) ; $ last = $ item [ 5 ] - $ base [ 5 ] ; } return $ total ; } | Returns the total memory usage from all samples taken by comparing each sample to the base memory sample . |
2,821 | public static function getSessionToken ( ) { $ token = null ; if ( isset ( $ _SESSION [ __SYM_COOKIE_PREFIX__ ] [ 'xsrf-token' ] ) ) { $ token = $ _SESSION [ __SYM_COOKIE_PREFIX__ ] [ 'xsrf-token' ] ; } if ( is_array ( $ token ) ) { $ token = key ( $ token ) ; } return is_null ( $ token ) ? null : $ token ; } | Return s the location of the XSRF tokens in the Session |
2,822 | public static function formToken ( ) { $ obj = new XMLElement ( "input" ) ; $ obj -> setAttribute ( "type" , "hidden" ) ; $ obj -> setAttribute ( "name" , "xsrf" ) ; $ obj -> setAttribute ( "value" , self :: getToken ( ) ) ; return $ obj ; } | Creates the form input to use to house the token |
2,823 | public static function validateRequest ( $ silent = false ) { if ( count ( $ _POST ) > 0 ) { if ( ! self :: validateToken ( $ _POST [ "xsrf" ] ) ) { if ( ! $ silent ) { self :: throwXSRFException ( ) ; } else { return false ; } } } } | This will validate a request has a good token . |
2,824 | public static function setFetchSortingDirection ( $ direction ) { $ direction = strtoupper ( $ direction ) ; if ( $ direction == 'RANDOM' ) { $ direction = 'RAND' ; } self :: $ _fetchSortDirection = ( in_array ( $ direction , array ( 'RAND' , 'ASC' , 'DESC' ) ) ? $ direction : null ) ; } | Setter function for the default sorting direction of the Fetch function . Available options are RAND ASC or DESC . |
2,825 | protected static function saveFieldData ( $ entry_id , $ field_id , $ field ) { if ( empty ( $ field_id ) ) { return ; } if ( ! is_array ( $ field ) ) { $ field = array ( ) ; } $ did_lock = false ; $ exception = null ; try { $ table_name = 'tbl_entries_data_' . General :: intval ( $ field_id ) ; if ( ! Symphony :: Data... | Executes the SQL queries need to save a field s data for the specified entry id . |
2,826 | public static function add ( Entry $ entry ) { $ fields = $ entry -> get ( ) ; Symphony :: Database ( ) -> insert ( $ fields , 'tbl_entries' ) ; if ( ! $ entry_id = Symphony :: Database ( ) -> getInsertID ( ) ) { return false ; } foreach ( $ entry -> getData ( ) as $ field_id => $ field ) { static :: saveFieldData ( $ ... | Given an Entry object iterate over all of the fields in that object an insert them into their relevant entry tables . |
2,827 | public static function edit ( Entry $ entry ) { Symphony :: Database ( ) -> update ( array ( 'modification_author_id' => $ entry -> get ( 'modification_author_id' ) , 'modification_date' => $ entry -> get ( 'modification_date' ) , 'modification_date_gmt' => $ entry -> get ( 'modification_date_gmt' ) ) , 'tbl_entries' ,... | Update an existing Entry object given an Entry object |
2,828 | public static function fetchCount ( $ section_id = null , $ where = null , $ joins = null , $ group = false ) { if ( is_null ( $ section_id ) ) { return false ; } $ section = SectionManager :: fetch ( $ section_id ) ; if ( ! is_object ( $ section ) ) { return false ; } return Symphony :: Database ( ) -> fetchVar ( 'cou... | Return the count of the number of entries in a particular section . |
2,829 | private function __process ( XsltProcessor $ XSLProc , $ xml , $ xsl , array $ parameters = array ( ) ) { $ xmlDoc = new DomDocument ; $ xslDoc = new DomDocument ; if ( function_exists ( 'ini_set' ) ) { $ ehOLD = ini_set ( 'html_errors' , false ) ; } set_error_handler ( array ( $ this , 'trapXMLError' ) ) ; $ elOLD = l... | Uses DomDocument to transform the document . Any errors that occur are trapped by custom error handlers trapXMLError or trapXSLError . |
2,830 | public function trapXMLError ( $ errno , $ errstr , $ errfile , $ errline ) { $ this -> __error ( $ errno , str_replace ( 'DOMDocument::' , null , $ errstr ) , $ errfile , $ errline , 'xml' ) ; } | A custom error handler especially for XML errors . |
2,831 | public static function create ( $ gateway = null ) { $ email_gateway_manager = new EmailGatewayManager ; if ( $ gateway ) { return $ email_gateway_manager -> create ( $ gateway ) ; } else { return $ email_gateway_manager -> create ( $ email_gateway_manager -> getDefaultGateway ( ) ) ; } } | Returns the EmailGateway to send emails with . Calling this function multiple times will return unique objects . |
2,832 | public static function isTextFormatterUsed ( $ text_formatter_handle ) { $ fields = Symphony :: Database ( ) -> fetchCol ( 'type' , "SELECT DISTINCT `type` FROM `tbl_fields` WHERE `type` NOT IN ('author', 'checkbox', 'date', 'input', 'select', 'taglist', 'upload')" ) ; if ( ! empty ( $ fields ) ) { foreach ( $ fields a... | Check if a specific text formatter is used by a Field |
2,833 | protected function serializeArray ( array $ arr , $ indentation = 0 , $ tab = self :: TAB ) { $ tabs = '' ; $ closeTabs = '' ; for ( $ i = 0 ; $ i < $ indentation ; $ i ++ ) { $ tabs .= $ tab ; if ( $ i < $ indentation - 1 ) { $ closeTabs .= $ tab ; } } $ string = 'array(' ; foreach ( $ arr as $ key => $ value ) { $ ke... | The serializeArray function will properly format and indent multidimensional arrays using recursivity . |
2,834 | public function checkElementsInHead ( $ path , $ attribute ) { foreach ( $ this -> _head as $ element ) { if ( basename ( $ element -> getAttribute ( $ attribute ) ) == basename ( $ path ) ) { return true ; } } return false ; } | Determines if two elements are duplicates based on an attribute and value |
2,835 | public function canProcessSystemParameters ( ) { if ( ! is_array ( $ this -> dsParamPARAMOUTPUT ) ) { return false ; } foreach ( self :: $ _system_parameters as $ system_parameter ) { if ( in_array ( $ system_parameter , $ this -> dsParamPARAMOUTPUT ) === true ) { return true ; } } return false ; } | If this Datasource requires System Parameters to be output this function will return true otherwise false . |
2,836 | public function processRecordGroup ( $ element , array $ group ) { $ xGroup = new XMLElement ( $ element , null , $ group [ 'attr' ] ) ; if ( is_array ( $ group [ 'records' ] ) && ! empty ( $ group [ 'records' ] ) ) { if ( isset ( $ group [ 'records' ] [ 0 ] ) ) { $ data = $ group [ 'records' ] [ 0 ] -> getData ( ) ; $... | Given a name for the group and an associative array that contains three keys attr records and groups . Grouping of Entries is done by the grouping Field at a PHP level not through the Database . |
2,837 | public function processEntry ( Entry $ entry ) { $ data = $ entry -> getData ( ) ; $ xEntry = new XMLElement ( 'entry' ) ; $ xEntry -> setAttribute ( 'id' , $ entry -> get ( 'id' ) ) ; if ( ! empty ( $ this -> _associated_sections ) ) { $ this -> setAssociatedEntryCounts ( $ xEntry , $ entry ) ; } if ( $ this -> _can_p... | Given an Entry object this function will generate an XML representation of the Entry to be returned . It will also add any parameters selected by this datasource to the parameter pool . |
2,838 | public function getPreferencesPane ( ) { parent :: getPreferencesPane ( ) ; $ group = new XMLElement ( 'fieldset' ) ; $ group -> setAttribute ( 'class' , 'settings condensed pickable' ) ; $ group -> setAttribute ( 'id' , 'sendmail' ) ; $ group -> appendChild ( new XMLElement ( 'legend' , __ ( 'Email: Sendmail' ) ) ) ; ... | Builds the preferences pane shown in the symphony backend . |
2,839 | public static function run ( $ function , $ existing_version = null ) { static :: $ existing_version = $ existing_version ; try { $ canProceed = static :: $ function ( ) ; return ( $ canProceed === false ) ? false : true ; } catch ( DatabaseException $ e ) { Symphony :: Log ( ) -> pushToLog ( 'Could not complete upgrad... | While we are supporting PHP5 . 2 we can t do this neatly as 5 . 2 lacks late static binding . self will always refer to Migration not the calling class ie . Migration_202 . In Symphony 2 . 4 we will support PHP5 . 3 only and we can have this efficiency! |
2,840 | public static function compare ( $ input , $ hash , $ isHash = false ) { $ version = substr ( $ hash , 0 , 8 ) ; if ( $ isHash === true ) { return $ input == $ hash ; } elseif ( $ version == 'PBKDF2v1' ) { return PBKDF2 :: compare ( $ input , $ hash ) ; } elseif ( strlen ( $ hash ) == 40 ) { return SHA1 :: compare ( $ ... | Compares a given hash with a clean text password by figuring out the algorithm that has been used and then calling the appropriate sub - class |
2,841 | public static function generateSalt ( $ length ) { mt_srand ( intval ( microtime ( true ) * 100000 + memory_get_usage ( true ) ) ) ; return substr ( sha1 ( uniqid ( mt_rand ( ) , true ) ) , 0 , $ length ) ; } | Generates a salt to be used in message digestation . |
2,842 | public function checkCoreForUpdates ( ) { if ( $ this -> isInstallerAvailable ( ) === false ) { return false ; } try { if ( $ this -> isUpgradeAvailable ( ) ) { $ message = __ ( 'An update has been found in your installation to upgrade Symphony to %s.' , array ( $ this -> getMigrationVersion ( ) ) ) . ' <a href="' . UR... | Scan the install directory to look for new migrations that can be applied to update this version of Symphony . If one if found a new Alert is added to the page . |
2,843 | public function checkExtensionsForUpdates ( ) { $ extensions = Symphony :: ExtensionManager ( ) -> listInstalledHandles ( ) ; if ( is_array ( $ extensions ) && ! empty ( $ extensions ) ) { foreach ( $ extensions as $ name ) { $ about = Symphony :: ExtensionManager ( ) -> about ( $ name ) ; if ( array_key_exists ( 'stat... | Checks all installed extensions to see any have an outstanding update . If any do an Alert will be added to the current page directing the Author to the Extension page |
2,844 | private function __canAccessAlerts ( ) { if ( $ this -> Page instanceof AdministrationPage && self :: isLoggedIn ( ) && Symphony :: Author ( ) -> isDeveloper ( ) ) { return true ; } return false ; } | This function determines whether an administrative alert can be displayed on the current page . It ensures that the page exists and the user is logged in and a developer |
2,845 | public function display ( $ page ) { Symphony :: Profiler ( ) -> sample ( 'Page build process started' ) ; Symphony :: ExtensionManager ( ) -> notifyMembers ( 'AdminPagePreBuild' , '/backend/' , array ( 'page' => $ page ) ) ; $ this -> __buildPage ( $ page ) ; if ( self :: isXSRFEnabled ( ) && isset ( $ this -> Page ->... | Called by index . php this function is responsible for rendering the current page on the Frontend . Two delegates are fired AdminPagePreGenerate and AdminPagePostGenerate . This function runs the Profiler for the page build process . |
2,846 | public static function start ( $ lifetime = 0 , $ path = '/' , $ domain = null , $ httpOnly = true , $ secure = false ) { if ( ! self :: $ _initialized ) { if ( ! is_object ( Symphony :: Database ( ) ) || ! Symphony :: Database ( ) -> isConnected ( ) ) { return false ; } if ( session_id ( ) == '' ) { ini_set ( 'session... | Starts a Session object only if one doesn t already exist . This function maps the Session Handler functions to this classes methods by reading the default information from the PHP ini file . |
2,847 | protected static function createCookieSafePath ( $ path ) { $ path = array_filter ( explode ( '/' , $ path ) ) ; if ( empty ( $ path ) ) { return '/' ; } $ path = array_map ( 'rawurlencode' , $ path ) ; return '/' . implode ( '/' , $ path ) ; } | Returns a properly formatted ascii string for the cookie path . Browsers are notoriously bad at parsing the cookie path . They do not respect the content - encoding header . So we must be careful when dealing with setups with special characters in their paths . |
2,848 | public static function getDomain ( ) { if ( HTTP_HOST != null ) { if ( preg_match ( '/(localhost|127\.0\.0\.1)/' , HTTP_HOST ) ) { return null ; } return preg_replace ( '/(^www\.|:\d+$)/i' , null , HTTP_HOST ) ; } return null ; } | Returns the current domain for the Session to be saved to if the installation is on localhost this returns null and just allows PHP to take care of setting the valid domain for the Session otherwise it will return the non - www version of the domain host . |
2,849 | private static function unserialize ( $ data ) { $ hasBuffer = isset ( $ _SESSION ) ; $ buffer = $ _SESSION ; session_decode ( $ data ) ; $ session = $ _SESSION ; if ( $ hasBuffer ) { $ _SESSION = $ buffer ; } else { unset ( $ _SESSION ) ; } return $ session ; } | Given raw session data return the unserialized array . Used to check if the session is really empty before writing . |
2,850 | public static function read ( $ id ) { return ( string ) Symphony :: Database ( ) -> fetchVar ( 'session_data' , 0 , sprintf ( "SELECT `session_data` FROM `tbl_sessions` WHERE `session` = '%s' LIMIT 1" , Symphony :: Database ( ) -> cleanValue ( $ id ) ) ) ; } | Given a session s ID return it s row from tbl_sessions |
2,851 | public static function destroy ( $ id ) { return Symphony :: Database ( ) -> query ( sprintf ( "DELETE FROM `tbl_sessions` WHERE `session` = '%s'" , Symphony :: Database ( ) -> cleanValue ( $ id ) ) ) ; } | Given a session s ID remove it s row from tbl_sessions |
2,852 | public static function validateString ( $ string , $ rule ) { if ( ! is_array ( $ rule ) && ( $ rule == '' || $ rule == null ) ) { return true ; } if ( ! is_array ( $ string ) && ( $ string == '' || $ rule == null ) ) { return true ; } if ( ! is_array ( $ rule ) ) { $ rule = array ( $ rule ) ; } if ( ! is_array ( $ str... | Validate a string against a set of regular expressions . |
2,853 | public static function validateXML ( $ data , & $ errors , $ isFile = true , $ xsltProcessor = null , $ encoding = 'UTF-8' ) { $ _data = ( $ isFile ) ? file_get_contents ( $ data ) : $ data ; $ _data = preg_replace ( '/<!DOCTYPE[-.:"\'\/\\w\\s]+>/' , null , $ _data ) ; if ( strpos ( $ _data , '<?xml' ) === false ) { $ ... | Checks an xml document for well - formedness . |
2,854 | public static function validateURL ( $ url = null ) { $ url = trim ( $ url ) ; if ( is_null ( $ url ) || $ url == '' ) { return $ url ; } if ( ! preg_match ( '#^http[s]?:\/\/#i' , $ url ) ) { $ url = 'http://' . $ url ; } include TOOLKIT . '/util.validators.php' ; if ( ! preg_match ( $ validators [ 'URI' ] , $ url ) ) ... | Check that a string is a valid URL . |
2,855 | public static function cleanArray ( array & $ arr ) { foreach ( $ arr as $ k => $ v ) { if ( is_array ( $ v ) ) { self :: cleanArray ( $ arr [ $ k ] ) ; } else { $ arr [ $ k ] = stripslashes ( $ v ) ; } } } | Strip any slashes from all array values . |
2,856 | public static function strpos ( $ haystack , $ needle , $ offset = 0 ) { if ( function_exists ( 'mb_strpos' ) ) { return mb_strpos ( $ haystack , $ needle , $ offset , 'utf-8' ) ; } return strpos ( $ haystack , $ needle , $ offset ) ; } | Finds position of the first occurrence of a string in a string . This function will attempt to use PHP s mbstring functions if they are available . This function also forces utf - 8 encoding for mbstring . |
2,857 | public static function substr ( $ str , $ start , $ length = null ) { if ( function_exists ( 'mb_substr' ) ) { return mb_substr ( $ str , $ start , $ length , 'utf-8' ) ; } if ( $ length === null ) { return substr ( $ str , $ start ) ; } return substr ( $ str , $ start , $ length ) ; } | Creates a sub string . This function will attempt to use PHP s mbstring functions if they are available . This function also forces utf - 8 encoding . |
2,858 | public static function realiseDirectory ( $ path , $ mode = 0755 , $ silent = true ) { if ( is_dir ( $ path ) ) { return true ; } try { $ current_umask = umask ( 0 ) ; $ success = @ mkdir ( $ path , intval ( $ mode , 8 ) , true ) ; umask ( $ current_umask ) ; return $ success ; } catch ( Exception $ ex ) { if ( $ silen... | Create all the directories as specified by the input path . If the current directory already exists this function will return true . |
2,859 | public static function in_array_multi ( $ needle , $ haystack ) { if ( $ needle == $ haystack ) { return true ; } if ( is_array ( $ haystack ) ) { foreach ( $ haystack as $ key => $ val ) { if ( is_array ( $ val ) ) { if ( self :: in_array_multi ( $ needle , $ val ) ) { return true ; } } elseif ( ! strcmp ( $ needle , ... | Search a multi - dimensional array for a value . |
2,860 | public static function in_array_all ( $ needles , $ haystack ) { foreach ( $ needles as $ n ) { if ( ! in_array ( $ n , $ haystack ) ) { return false ; } } return true ; } | Search an array for multiple values . |
2,861 | public static function array_find_available_index ( $ array , $ seed = null ) { if ( ! is_null ( $ seed ) ) { $ index = $ seed ; } else { $ keys = array_keys ( $ array ) ; sort ( $ keys ) ; $ index = array_pop ( $ keys ) ; } if ( isset ( $ array [ $ index ] ) ) { do { $ index ++ ; } while ( isset ( $ array [ $ index ] ... | Find the next available index in an array . Works best with numeric keys . The next available index is the minimum integer such that the array does not have a mapping for that index . Uses the increment operator on the index type of the input array whatever that may do . |
2,862 | public static function in_iarray ( $ needle , array $ haystack ) { foreach ( $ haystack as $ key => $ value ) { if ( strcasecmp ( $ value , $ needle ) == 0 ) { return true ; } } return false ; } | Test whether a value is in an array based on string comparison ignoring the case of the values . |
2,863 | public static function array_iunique ( array $ array ) { $ tmp = array ( ) ; foreach ( $ array as $ key => $ value ) { if ( ! self :: in_iarray ( $ value , $ tmp ) ) { $ tmp [ $ key ] = $ value ; } } return $ tmp ; } | Filter the input array for duplicates treating each element in the array as a string and comparing them using a case insensitive comparison function . |
2,864 | public static function array_map_recursive ( $ function , array $ array ) { $ tmp = array ( ) ; foreach ( $ array as $ key => $ value ) { if ( is_array ( $ value ) ) { $ tmp [ $ key ] = self :: array_map_recursive ( $ function , $ value ) ; } else { $ tmp [ $ key ] = call_user_func ( $ function , $ value ) ; } } return... | Function recursively apply a function to an array s values . This will not touch the keys just the values . |
2,865 | public static function array_to_xml ( XMLElement $ parent , array $ data , $ validate = false ) { foreach ( $ data as $ element_name => $ value ) { if ( ! is_numeric ( $ value ) && empty ( $ value ) ) { continue ; } if ( is_int ( $ element_name ) ) { $ child = new XMLElement ( 'item' ) ; $ child -> setAttribute ( 'inde... | Convert an array into an XML fragment and append it to an existing XML element . Any arrays contained as elements in the input array will also be recursively formatted and appended to the input XML fragment . The input XML element will be modified as a result of calling this . |
2,866 | public static function checkFile ( $ file ) { if ( Symphony :: Log ( ) ) { Symphony :: Log ( ) -> pushDeprecateWarningToLog ( 'General::checkFile()' , '`General::checkFileWritable()' ) ; } clearstatcache ( ) ; $ dir = dirname ( $ file ) ; if ( ( ! is_writable ( $ dir ) || ! is_readable ( $ dir ) ) || ( file_exists ( $ ... | Checks that the file and its folder are readable and writable . |
2,867 | public function getMimeType ( $ file ) { if ( ! empty ( $ file ) ) { if ( PHP_VERSION_ID >= 50300 && function_exists ( 'finfo_open' ) ) { $ finfo = finfo_open ( FILEINFO_MIME_TYPE ) ; $ mime_type = finfo_file ( $ finfo , $ file ) ; finfo_close ( $ finfo ) ; } else { $ mimetypes = array ( 'txt' => 'text/plain' , 'csv' =... | Gets mime type of a file . |
2,868 | public static function listDirStructure ( $ dir = '.' , $ filter = null , $ recurse = true , $ strip_root = null , $ exclude = array ( ) , $ ignore_hidden = true ) { if ( ! is_dir ( $ dir ) ) { return null ; } $ files = array ( ) ; foreach ( scandir ( $ dir ) as $ file ) { if ( ( $ file == '.' || $ file == '..' ) || ( ... | Construct a multi - dimensional array that reflects the directory structure of a given path . |
2,869 | public static function listStructure ( $ dir = "." , $ filters = array ( ) , $ recurse = true , $ sort = "asc" , $ strip_root = null , $ exclude = array ( ) , $ ignore_hidden = true ) { if ( ! is_dir ( $ dir ) ) { return null ; } if ( is_array ( $ filters ) && ! empty ( $ filters ) ) { $ filter_type = 'file' ; } elseif... | Construct a multi - dimensional array that reflects the directory structure of a given path grouped into directory and file keys matching any input constraints . |
2,870 | public static function createXMLDateObject ( $ timestamp , $ element = 'date' , $ date_format = 'Y-m-d' , $ time_format = 'H:i' , $ namespace = null ) { if ( ! class_exists ( 'XMLElement' ) ) { return false ; } if ( empty ( $ date_format ) ) { $ date_format = DateTimeObj :: getSetting ( 'date_format' ) ; } if ( empty (... | Construct an XML fragment that reflects the structure of the input timestamp . |
2,871 | public static function buildPaginationElement ( $ total_entries = 0 , $ total_pages = 0 , $ entries_per_page = 1 , $ current_page = 1 ) { $ pageinfo = new XMLElement ( 'pagination' ) ; $ pageinfo -> setAttribute ( 'total-entries' , $ total_entries ) ; $ pageinfo -> setAttribute ( 'total-pages' , $ total_pages ) ; $ pag... | Construct an XML fragment that describes a pagination structure . |
2,872 | public static function hash ( $ input , $ algorithm = 'sha1' ) { switch ( $ algorithm ) { case 'sha1' : return SHA1 :: hash ( $ input ) ; case 'md5' : return MD5 :: hash ( $ input ) ; case 'pbkdf2' : default : return Crytography :: hash ( $ input , $ algorithm ) ; } } | Uses SHA1 or MD5 to create a hash based on some input This function is currently very basic but would allow future expansion . Salting the hash comes to mind . |
2,873 | public static function wrapInCDATA ( $ value ) { if ( empty ( $ value ) ) { return $ value ; } $ startRegExp = '/^' . preg_quote ( CDATA_BEGIN ) . '/' ; $ endRegExp = '/' . preg_quote ( CDATA_END ) . '$/' ; if ( ! preg_match ( $ startRegExp , $ value ) ) { $ value = CDATA_BEGIN . $ value ; } if ( ! preg_match ( $ endRe... | Wrap a value in CDATA tags for XSL output of non encoded data only if not already wrapped . |
2,874 | public static function add ( array $ fields ) { if ( ! Symphony :: Database ( ) -> insert ( $ fields , 'tbl_authors' ) ) { return false ; } $ author_id = Symphony :: Database ( ) -> getInsertID ( ) ; return $ author_id ; } | Given an associative array of fields insert them into the database returning the resulting Author ID if successful or false if there was an error |
2,875 | public static function fetch ( $ sortby = 'id' , $ sortdirection = 'ASC' , $ limit = null , $ start = null , $ where = null , $ joins = null ) { $ sortby = is_null ( $ sortby ) ? 'id' : Symphony :: Database ( ) -> cleanValue ( $ sortby ) ; $ sortdirection = $ sortdirection === 'ASC' ? 'ASC' : 'DESC' ; $ records = Symph... | The fetch method returns all Authors from Symphony with the option to sort or limit the output . This method returns an array of Author objects . |
2,876 | public static function deactivateAuthToken ( $ author_id ) { if ( ! is_int ( $ author_id ) ) { return false ; } return Symphony :: Database ( ) -> query ( sprintf ( "UPDATE `tbl_authors` SET `auth_token_active` = 'no' WHERE `id` = %d" , $ author_id ) ) ; } | This function will remove the ability for an Author to sign into Symphony by using their authentication token |
2,877 | public function setHeader ( $ header , $ value ) { if ( is_array ( $ value ) ) { throw new SMTPException ( __ ( 'Header fields can only contain strings' ) ) ; } $ this -> _header_fields [ $ header ] = $ value ; } | Sets a header to be sent in the email . |
2,878 | public function mail ( $ from ) { if ( $ this -> _helo == false ) { throw new SMTPException ( __ ( 'Must call EHLO (or HELO) before calling MAIL' ) ) ; } elseif ( $ this -> _mail !== false ) { throw new SMTPException ( __ ( 'Only one call to MAIL may be made at a time.' ) ) ; } $ this -> _send ( 'MAIL FROM:<' . $ from ... | Calls the MAIL command on the server . |
2,879 | public function rcpt ( $ to ) { if ( $ this -> _mail == false ) { throw new SMTPException ( __ ( 'Must call MAIL before calling RCPT' ) ) ; } $ this -> _send ( 'RCPT TO:<' . $ to . '>' ) ; $ this -> _expect ( array ( 250 , 251 ) , 300 ) ; $ this -> _rcpt = true ; } | Calls the RCPT command on the server . May be called multiple times for more than one recipient . |
2,880 | public function data ( $ data ) { if ( $ this -> _rcpt == false ) { throw new SMTPException ( __ ( 'Must call RCPT before calling DATA' ) ) ; } $ this -> _send ( 'DATA' ) ; $ this -> _expect ( 354 , 120 ) ; foreach ( $ this -> _header_fields as $ name => $ body ) { if ( ! is_array ( $ body ) ) { $ body = array ( $ body... | Calls the data command on the server . Also includes header fields in the command . |
2,881 | protected function _auth ( ) { if ( $ this -> _helo == false ) { throw new SMTPException ( __ ( 'Must call EHLO (or HELO) before calling AUTH' ) ) ; } elseif ( $ this -> _auth !== false ) { throw new SMTPException ( __ ( 'Can not call AUTH again.' ) ) ; } $ this -> _send ( 'AUTH LOGIN' ) ; $ this -> _expect ( 334 ) ; $... | Authenticates to the server . Currently supports the AUTH LOGIN command . May be extended if more methods are needed . |
2,882 | protected function _tls ( ) { if ( $ this -> _secure == 'tls' ) { $ this -> _send ( 'STARTTLS' ) ; $ this -> _expect ( 220 , 180 ) ; if ( ! stream_socket_enable_crypto ( $ this -> _connection , true , STREAM_CRYPTO_METHOD_TLS_CLIENT ) ) { throw new SMTPException ( __ ( 'Unable to connect via TLS' ) ) ; } $ this -> _ehl... | Encrypts the current session with TLS . |
2,883 | protected function _send ( $ request ) { $ this -> checkConnection ( ) ; $ result = fwrite ( $ this -> _connection , $ request . "\r\n" ) ; if ( $ result === false ) { throw new SMTPException ( __ ( 'Could not send request: %s' , array ( $ request ) ) ) ; } return $ result ; } | Send a request to the host appends the request with a line break . |
2,884 | protected function _expect ( $ code , $ timeout = null ) { $ this -> _response = array ( ) ; $ cmd = '' ; $ more = '' ; $ msg = '' ; $ errMsg = '' ; if ( ! is_array ( $ code ) ) { $ code = array ( $ code ) ; } do { $ result = $ this -> _receive ( $ timeout ) ; list ( $ cmd , $ more , $ msg ) = preg_split ( '/([\s-]+)/'... | Parse server response for successful codes |
2,885 | protected function _connect ( $ host , $ port ) { $ errorNum = 0 ; $ errorStr = '' ; $ remoteAddr = $ this -> _transport . '://' . $ host . ':' . $ port ; if ( ! is_resource ( $ this -> _connection ) ) { $ this -> _connection = @ stream_socket_client ( $ remoteAddr , $ errorNum , $ errorStr , self :: TIMEOUT ) ; if ( $... | Connect to the host and perform basic functions like helo and auth . |
2,886 | public static function getInstance ( $ name ) { return ( isset ( self :: $ _pool [ $ name ] ) ? self :: $ _pool [ $ name ] : self :: create ( $ name ) ) ; } | This function returns an instance of an extension from it s name |
2,887 | public static function fetchStatus ( $ about ) { $ return = array ( ) ; self :: __buildExtensionList ( ) ; if ( isset ( $ about [ 'handle' ] ) && array_key_exists ( $ about [ 'handle' ] , self :: $ _extensions ) ) { if ( self :: $ _extensions [ $ about [ 'handle' ] ] [ 'status' ] == 'enabled' ) { $ return [ ] = Extensi... | Returns the status of an Extension given an associative array containing the Extension handle and version where the version is the file version not the installed version . This function returns an array which may include a maximum of two statuses . |
2,888 | public static function fetchInstalledVersion ( $ name ) { self :: __buildExtensionList ( ) ; return ( isset ( self :: $ _extensions [ $ name ] ) ? self :: $ _extensions [ $ name ] [ 'version' ] : null ) ; } | A convenience method that returns an extension version from it s name . |
2,889 | private static function __requiresInstallation ( $ name ) { self :: __buildExtensionList ( ) ; $ id = self :: $ _extensions [ $ name ] [ 'id' ] ; return ( is_numeric ( $ id ) ? false : true ) ; } | Determines whether the current extension is installed or not by checking for an id in tbl_extensions |
2,890 | private static function __requiresUpdate ( $ name , $ file_version ) { $ installed_version = self :: fetchInstalledVersion ( $ name ) ; if ( is_null ( $ installed_version ) ) { return false ; } return ( version_compare ( $ installed_version , $ file_version , '<' ) ? $ installed_version : false ) ; } | Determines whether an extension needs to be updated or not using PHP s version_compare function . This function will return the installed version if the extension requires an update or false otherwise . |
2,891 | public static function enable ( $ name ) { $ obj = self :: getInstance ( $ name ) ; if ( self :: __requiresInstallation ( $ name ) && $ obj -> install ( ) === false ) { $ obj -> uninstall ( ) ; return false ; } elseif ( ( $ about = self :: about ( $ name ) ) && ( $ previousVersion = self :: __requiresUpdate ( $ name , ... | Enabling an extension will re - register all it s delegates with Symphony . It will also install or update the extension if needs be by calling the extensions respective install and update methods . The enable method is of the extension object is finally called . |
2,892 | public static function registerDelegates ( $ name ) { $ obj = self :: getInstance ( $ name ) ; $ id = self :: fetchExtensionID ( $ name ) ; if ( ! $ id ) { return false ; } Symphony :: Database ( ) -> delete ( 'tbl_extensions_delegates' , sprintf ( " `extension_id` = %d " , $ id ) ) ; $ delegates = $ obj -> ... | This functions registers an extensions delegates in tbl_extensions_delegates . |
2,893 | public static function listInstalledHandles ( ) { if ( empty ( self :: $ _enabled_extensions ) && Symphony :: Database ( ) -> isConnected ( ) ) { self :: $ _enabled_extensions = Symphony :: Database ( ) -> fetchCol ( 'name' , "SELECT `name` FROM `tbl_extensions` WHERE `status` = 'enabled'" ) ; } return self :: $ _enabl... | Returns an array of all the enabled extensions available |
2,894 | public static function listAll ( $ filter = '/^((?![-^?%:*|"<>]).)*$/' ) { $ result = array ( ) ; $ extensions = General :: listDirStructure ( EXTENSIONS , $ filter , false , EXTENSIONS ) ; if ( is_array ( $ extensions ) && ! empty ( $ extensions ) ) { foreach ( $ extensions as $ extension ) { $ e = trim ( $ extension ... | Will return an associative array of all extensions and their about information |
2,895 | private static function sortByAuthor ( $ a , $ b , $ i = 0 ) { $ first = $ a ; $ second = $ b ; if ( isset ( $ a [ $ i ] ) ) { $ first = $ a [ $ i ] ; } if ( isset ( $ b [ $ i ] ) ) { $ second = $ b [ $ i ] ; } if ( $ first == $ a && $ second == $ b && $ first [ 'name' ] == $ second [ 'name' ] ) { return 1 ; } elseif (... | Custom user sorting function used inside fetch to recursively sort authors by their names . |
2,896 | public static function create ( $ name ) { if ( ! isset ( self :: $ _pool [ $ name ] ) ) { $ classname = self :: __getClassName ( $ name ) ; $ path = self :: __getDriverPath ( $ name ) ; if ( ! is_file ( $ path ) ) { $ errMsg = __ ( 'Could not find extension %s at location %s.' , array ( '<code>' . $ name . '</code>' ,... | Creates an instance of a given class and returns it |
2,897 | public static function cleanupDatabase ( ) { $ rows = Symphony :: Database ( ) -> fetch ( "SELECT `name` FROM `tbl_extensions`" ) ; if ( is_array ( $ rows ) && ! empty ( $ rows ) ) { foreach ( $ rows as $ r ) { $ name = $ r [ 'name' ] ; $ status = isset ( $ r [ 'status' ] ) ? $ r [ 'status' ] : null ; $ path = self :: ... | A utility function that is used by the ExtensionManager to ensure stray delegates are not in tbl_extensions_delegates . It is called when a new Delegate is added or removed . |
2,898 | private function __init ( ) { $ this -> _session = Session :: start ( $ this -> _timeout , $ this -> _path , $ this -> _domain , $ this -> _httpOnly , $ this -> _secure ) ; if ( ! $ this -> _session ) { return false ; } if ( ! isset ( $ _SESSION [ $ this -> _index ] ) ) { $ _SESSION [ $ this -> _index ] = array ( ) ; }... | Initialises a new Session instance using this cookie s params |
2,899 | public static function hash ( $ input ) { if ( Symphony :: Log ( ) ) { Symphony :: Log ( ) -> pushDeprecateWarningToLog ( 'SHA1::hash()' , 'PBKDF2::hash()' , array ( 'message-format' => __ ( 'The use of `%s` is strongly discouraged due to severe security flaws.' ) , ) ) ; } return sha1 ( $ input ) ; } | Uses SHA1 to create a hash based on some input |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.