idx
int64
0
60.3k
question
stringlengths
64
4.24k
target
stringlengths
5
618
46,200
public function toContent ( $ contents , $ format , $ options = array ( ) ) { if ( ! ( $ contents instanceof Registry ) ) { $ contents = new Registry ( $ contents ) ; } return $ contents -> toString ( $ format , $ options ) ; }
Turn contents into a string of the correct format
46,201
public function map ( $ record , $ callbacks , $ dryRun ) { foreach ( $ callbacks as $ callback ) { if ( is_callable ( $ callback ) ) { $ record = $ callback ( $ record , $ dryRun ) ; } } return $ record ; }
Run Callbacks on Record
46,202
public function addTasks ( $ command ) { $ this -> addSection ( 'Tasks' ) ; $ class = new \ ReflectionClass ( $ command ) ; $ tasks = $ class -> getMethods ( \ ReflectionMethod :: IS_PUBLIC ) ; if ( $ tasks && count ( $ tasks ) > 0 ) { $ list = [ ] ; $ max = 0 ; foreach ( $ tasks as $ task ) { if ( ! $ task -> isConstructor ( ) && $ task -> name != 'execute' && $ task -> name != 'help' ) { $ comment = $ task -> getDocComment ( ) ; $ description = 'no description available' ; preg_match ( '/@museDescription ([[:alnum:] ,\.()\-\'\/]*)/' , $ comment , $ matched ) ; if ( $ matched && isset ( $ matched [ 1 ] ) ) { $ description = trim ( $ matched [ 1 ] ) ; } $ list [ ] = [ 'name' => $ task -> name , 'description' => $ description ] ; $ max = ( $ max > strlen ( $ task -> name ) ) ? $ max : strlen ( $ task -> name ) ; } } if ( count ( $ list ) > 0 ) { foreach ( $ list as $ item ) { $ this -> addString ( $ item [ 'name' ] , [ 'color' => 'blue' , 'indentation' => 2 ] ) ; $ this -> addString ( str_repeat ( ' ' , ( $ max - strlen ( $ item [ 'name' ] ) ) ) . ' ' ) ; $ this -> addLine ( $ item [ 'description' ] ) ; } } else { $ this -> addLine ( 'There are no tasks available for this command' , [ 'color' => 'red' , 'indentation' => 2 ] ) ; } } $ this -> addSpacer ( ) ; return $ this ; }
Adds help output tasks section
46,203
public function addArgument ( $ argument , $ details = null , $ example = null , $ required = false ) { if ( ! $ this -> hasArgumentsSection ) { $ this -> addSection ( 'Arguments' ) ; $ this -> hasArgumentsSection = true ; } $ this -> addLine ( $ argument . ( ( $ required ) ? ' (*required)' : '' ) , array ( 'color' => ( ( $ required ) ? 'red' : 'blue' ) , 'indentation' => 2 ) ) ; if ( isset ( $ details ) ) { $ this -> addParagraph ( $ details , array ( 'indentation' => 4 ) ) ; if ( ! isset ( $ example ) ) { $ this -> addSpacer ( ) ; } } if ( isset ( $ example ) ) { $ this -> addLine ( $ example , array ( 'color' => 'green' , 'indentation' => 4 ) ) -> addSpacer ( ) ; } return $ this ; }
Add an argument entry to the help doc
46,204
public function prepare ( $ statement ) { $ this -> statement = $ this -> connection -> prepare ( $ this -> replacePrefix ( $ statement ) ) ; return $ this ; }
Prepares a query for binding
46,205
public function bind ( $ bindings , $ type = [ ] ) { $ idx = 1 ; $ this -> bindings = $ bindings ; foreach ( $ bindings as $ binding ) { $ this -> statement -> bindValue ( $ idx , $ binding , isset ( $ type [ $ idx ] ) ? $ this -> translateType ( $ type [ $ idx ] ) : $ this -> inferType ( $ binding ) ) ; $ idx ++ ; } return $ this ; }
Binds the given bindings to the prepared statement
46,206
private function inferType ( $ binding ) { if ( is_bool ( $ binding ) ) { $ type = \ PDO :: PARAM_BOOL ; } elseif ( is_null ( $ binding ) ) { $ type = \ PDO :: PARAM_NULL ; } elseif ( is_int ( $ binding ) ) { $ type = \ PDO :: PARAM_INT ; } else { $ type = \ PDO :: PARAM_STR ; } return $ type ; }
Infers the variable type from the variable itself
46,207
public function execute ( ) { $ this -> hasConnectionOrFail ( ) ; $ start = microtime ( true ) ; try { $ this -> statement -> execute ( ) ; } catch ( \ PDOException $ e ) { throw new QueryFailedException ( $ e -> getMessage ( ) , 500 , $ e ) ; } if ( $ this -> debug ) { $ this -> log ( microtime ( true ) - $ start ) ; } return $ this ; }
Executes the SQL statement
46,208
public function getCollation ( ) { $ this -> setQuery ( 'SHOW VARIABLES LIKE "collation_database"' ) ; $ result = $ this -> loadObject ( ) ; if ( property_exists ( $ result , 'Value' ) ) { return $ result -> Value ; } return false ; }
Gets the database collation in use
46,209
public function tableExists ( $ table ) { $ query = 'SHOW TABLES LIKE ' . str_replace ( '#__' , $ this -> tablePrefix , $ this -> quote ( $ table , false ) ) ; $ this -> setQuery ( $ query ) -> execute ( ) ; return ( $ this -> getAffectedRows ( ) > 0 ) ? true : false ; }
Checks for the existance of a table
46,210
public function tableHasField ( $ table , $ field ) { $ this -> setQuery ( 'SHOW FIELDS FROM ' . $ table ) ; $ fields = $ this -> loadObjectList ( 'Field' ) ; if ( ! is_array ( $ fields ) ) { return false ; } return ( in_array ( $ field , array_keys ( $ fields ) ) ) ? true : false ; }
Returns whether or not the given table has a given field
46,211
public function tableHaskey ( $ table , $ key ) { $ keys = $ this -> getTableKeys ( $ table ) ; if ( ! is_array ( $ keys ) ) { return false ; } return isset ( $ keys [ $ key ] ) ; }
Returns whether or not the given table has a given key
46,212
public function getPrimaryKey ( $ table ) { $ keys = $ this -> getTableKeys ( $ table ) ; $ key = false ; if ( $ keys && count ( $ keys ) > 0 ) { foreach ( $ keys as $ k ) { if ( $ k -> Key_name == 'PRIMARY' ) { $ key = $ k -> Column_name ; } } } return $ key ; }
Gets the primary key of a table
46,213
public function getEngine ( $ table ) { $ this -> setQuery ( 'SHOW TABLE STATUS WHERE Name = ' . str_replace ( '#__' , $ this -> tablePrefix , $ this -> quote ( $ table , false ) ) ) ; return ( $ info = $ this -> loadObjectList ( ) ) ? $ info [ 0 ] -> Engine : false ; }
Gets the database engine of the given table
46,214
public function setEngine ( $ table , $ engine ) { $ supported = [ 'innodb' , 'myisam' , 'archive' , 'merge' , 'memory' , 'csv' , 'federated' ] ; if ( ! in_array ( strtolower ( $ engine ) , $ supported ) ) { throw new UnsupportedEngineException ( sprintf ( 'Unsupported engine type of "%s" specified. Engine type must be one of %s' , $ engine , implode ( ', ' , $ supported ) ) ) ; } $ this -> setQuery ( 'ALTER TABLE ' . str_replace ( '#__' , $ this -> tablePrefix , $ this -> quote ( $ table , false ) ) . " ENGINE = " . $ this -> quote ( $ engine ) ) ; return $ this -> db -> query ( ) ; }
Set the database engine of the given table
46,215
public function getAutoIncrement ( $ table ) { $ create = $ this -> getTableCreate ( $ table ) ; preg_match ( '/AUTO_INCREMENT=([0-9]*)/' , $ create [ $ table ] , $ matches ) ; return ( isset ( $ matches [ 1 ] ) ) ? $ matches [ 1 ] : false ; }
Gets the auto - increment value for the given table
46,216
public function select ( $ database ) { if ( empty ( $ database ) ) { return false ; } $ this -> connection -> exec ( 'USE ' . $ this -> quoteName ( $ database ) ) ; $ this -> database = $ database ; return true ; }
Selects a database for use
46,217
public function setSize ( $ size ) { $ this -> size = $ size ; $ this -> pixelRatio = round ( $ size / 5 ) ; return $ this ; }
Set the image size
46,218
public function setString ( $ string ) { if ( null === $ string ) { throw new Exception ( 'The string cannot be null.' ) ; } $ this -> string = $ string ; $ this -> hash = md5 ( $ string ) ; $ this -> convertHash ( ) ; return $ this ; }
Generate a hash fron the original string
46,219
public function authorise ( $ response , $ options = array ( ) ) { $ this -> app [ 'plugin' ] -> byType ( 'user' ) ; $ this -> app [ 'plugin' ] -> byType ( 'authentication' ) ; return $ this -> app [ 'dispatcher' ] -> trigger ( 'onUserAuthorisation' , array ( $ response , $ options ) ) ; }
Authorises that a particular user should be able to login
46,220
public function gc ( ) { $ hash = $ this -> options [ 'hash' ] ; $ allinfo = $ this -> apcu ? apcu_cache_info ( ) : apc_cache_info ( 'user' ) ; $ keys = $ allinfo [ 'cache_list' ] ; foreach ( $ allinfo [ 'cache_list' ] as $ key ) { if ( strpos ( $ key [ 'info' ] , $ hash . '-cache-' ) ) { $ this -> apcu ? apcu_fetch ( $ key [ 'info' ] ) : apc_fetch ( $ key [ 'info' ] ) ; } } }
Force garbage collect expired cache data as items are removed only on fetch!
46,221
private static function _init ( ) { ini_set ( 'memory_limit' , '1024M' ) ; if ( getenv ( 'COMPOSER_HOME' ) != PATH_APP ) { putenv ( 'COMPOSER_HOME=' . PATH_APP ) ; } if ( getcwd ( ) != PATH_APP ) { chdir ( PATH_APP ) ; } if ( ! self :: $ io ) { self :: $ io = new NullIO ( ) ; } if ( ! self :: $ factory ) { self :: $ factory = new Factory ( ) ; } if ( ! self :: $ composer ) { self :: $ composer = self :: $ factory -> createComposer ( self :: $ io , PATH_APP . '/composer.json' , false , PATH_APP , true ) ; } return true ; }
Initialize a composer object and set the environment so composer can find its configuration We currently assume PATH_APP for all composer operations
46,222
private static function _resetComposer ( ) { self :: $ composer = null ; self :: $ factory = null ; self :: $ repositoryManager = null ; self :: $ localRepository = null ; self :: $ remoteRepositories = null ; self :: $ io = null ; self :: $ installer = null ; self :: $ dispatcher = null ; return self :: _init ( ) ; }
Reset and reinitialize Composer . This is required for doing most update and remove operations
46,223
private static function _getRepositoryManager ( ) { self :: _init ( ) ; if ( ! self :: $ repositoryManager ) { self :: $ repositoryManager = self :: $ composer -> getRepositoryManager ( ) ; } return self :: $ repositoryManager ; }
Return the repository manager
46,224
private static function _getRemoteRepositories ( ) { self :: _init ( ) ; if ( ! self :: $ remoteRepositories ) { self :: $ remoteRepositories = self :: _getRepositoryManager ( ) -> getRepositories ( ) ; } return self :: $ remoteRepositories ; }
Return an array of repositories containing remote packages
46,225
private static function _getInstaller ( ) { self :: _init ( ) ; if ( ! self :: $ installer ) { self :: $ installer = Installer :: create ( self :: _getIO ( ) , self :: _getComposer ( ) ) ; } return self :: $ installer ; }
Return the installer after ensuring Composer is set up
46,226
private static function _getDispatcher ( ) { self :: _init ( ) ; if ( ! self :: $ dispatcher ) { self :: $ dispatcher = self :: _getComposer ( ) -> getEventDispatcher ( ) ; } return self :: $ dispatcher ; }
Return the dispatcher in use by composer
46,227
private static function _getComposerJson ( ) { self :: _init ( ) ; if ( ! self :: $ json ) { $ file = self :: _getFactory ( ) -> getComposerFile ( ) ; self :: $ json = new JsonFile ( $ file ) ; } return self :: $ json ; }
Return the JSON file object representing the composer . json file in use
46,228
private static function _dispatch ( $ command ) { $ dispatcher = self :: _getDispatcher ( ) ; $ commandEvent = new CommandEvent ( PluginEvents :: COMMAND , $ command , self :: _getIO ( ) , self :: _getIO ( ) ) ; $ dispatcher -> dispatch ( $ commandEvent -> getName ( ) , $ commandEvent ) ; }
Dispatch an event to composer
46,229
private static function _unrequirePackage ( $ packageName ) { if ( empty ( $ packageName ) ) { return false ; } self :: _init ( ) ; self :: _dispatch ( 'remove' ) ; $ json = self :: _getComposerJson ( ) ; $ contents = file_get_contents ( $ json -> getPath ( ) ) ; $ manipulator = new JsonManipulator ( $ contents ) ; if ( ! $ manipulator -> removeSubNode ( 'require' , $ packageName , false ) ) { return false ; } file_put_contents ( $ json -> getPath ( ) , $ manipulator -> getContents ( ) ) ; return true ; }
Unrequire a package by manipulating the composer . json file
46,230
private static function _updatePackage ( $ packageName ) { self :: _init ( ) ; self :: _dispatch ( 'update' ) ; if ( is_null ( $ packageName ) ) { $ package = array ( ) ; } elseif ( is_string ( $ packageName ) ) { $ package = array ( $ packageName ) ; } else { $ package = $ packageName ; } $ installer = self :: _getInstaller ( ) ; $ installer -> setUpdate ( true ) -> setUpdateWhitelist ( $ package ) ; return $ installer -> run ( ) ; }
Update a package or list of packages
46,231
public static function installPackage ( $ packageName , $ constraint = 'dev-master' ) { if ( self :: _requirePackage ( $ packageName , $ constraint ) ) { self :: _resetComposer ( ) ; return self :: _updatePackage ( $ packageName ) ; } return false ; }
Install a package as a specific version
46,232
public static function getRemotePackages ( ) { $ remoteRepos = self :: _getRemoteRepositories ( ) ; $ remotePackages = array ( ) ; foreach ( $ remoteRepos as $ repo ) { if ( method_exists ( $ repo , "getRepoConfig" ) ) { $ config = $ repo -> getRepoConfig ( ) ; if ( is_array ( $ config ) && isset ( $ config [ 'type' ] ) && $ config [ 'type' ] != 'composer' ) { $ packages = $ repo -> getPackages ( ) ; foreach ( $ packages as $ package ) { $ remotePackages [ $ package -> getName ( ) ] = $ package ; } } } } return $ remotePackages ; }
Get a list of remote packages
46,233
public static function getAvailablePackages ( ) { $ availablePackages = self :: getRemotePackages ( ) ; $ localPackages = self :: getLocalPackages ( ) ; foreach ( $ localPackages as $ installedPackage ) { unset ( $ availablePackages [ $ installedPackage -> getName ( ) ] ) ; } return $ availablePackages ; }
Get a list of available packages
46,234
public static function getRepositoryByUrl ( $ url ) { $ remoteRepos = self :: _getRemoteRepositories ( ) ; foreach ( $ remoteRepos as $ repo ) { $ config = $ repo -> getRepoConfig ( ) ; if ( $ config [ 'url' ] == $ url ) { return $ repo ; } } return null ; }
Get a single repository by URL
46,235
public static function getRepositoryConfigByAlias ( $ alias ) { $ config = self :: _getConfig ( ) ; $ repos = self :: getRepositoryConfigs ( ) ; if ( isset ( $ repos [ $ alias ] ) ) { return $ repos [ $ alias ] ; } return null ; }
Return the configuration of a repository by its alias
46,236
public static function findRemotePackages ( $ packageName , $ versionConstraint ) { $ repoManager = self :: _getRepositoryManager ( ) ; return $ repoManager -> findPackages ( $ packageName , $ versionConstraint ) ; }
Find available packages matching the given constraints
46,237
public static function findLocalPackages ( $ packageName , $ versionConstraint = null ) { $ localRepo = self :: _getLocalRepository ( ) ; return $ localRepo -> findPackages ( $ packageName , $ versionConstraint ) ; }
Find an installed package matching given the constraints
46,238
public static function addRepository ( $ alias , $ json ) { $ config = self :: _getConfig ( ) ; $ configSource = $ config -> getConfigSource ( ) ; $ value = JsonFile :: parseJson ( $ json ) ; $ configSource -> addRepository ( $ alias , $ value ) ; }
Add a repository to the composer . json file
46,239
public static function removeRepository ( $ alias ) { $ config = self :: _getConfig ( ) ; $ configSource = $ config -> getConfigSource ( ) ; $ configSource -> removeRepository ( $ alias ) ; }
Remove a repository from the composer . json file
46,240
public function fetchElement ( $ name , $ value , & $ node , $ control_name ) { $ extension = ( string ) $ node [ 'extension' ] ; $ class = ( string ) $ node [ 'class' ] ; $ filter = explode ( ',' , ( string ) $ node [ 'filter' ] ) ; if ( ! isset ( $ extension ) ) { $ extension = ( string ) $ node [ 'scope' ] ; if ( ! isset ( $ extension ) ) { $ extension = 'com_content' ; } } if ( ! $ class ) { $ class = "inputbox" ; } if ( count ( $ filter ) < 1 ) { $ filter = null ; } return Builder \ Select :: genericlist ( Builder \ Category :: options ( $ extension ) , $ control_name . '[' . $ name . ']' , array ( 'class' => $ class ) , 'value' , 'text' , ( int ) $ value , $ control_name . $ name ) ; }
Fetch the element
46,241
private function parseThresholds ( $ thresholds ) { $ log = $ this -> log ; if ( strpos ( $ thresholds , ',' ) ) { $ thresholds = explode ( ',' , $ thresholds ) ; } else { $ thresholds = ( array ) $ thresholds ; } $ threshold = array ( ) ; foreach ( $ thresholds as $ t ) { preg_match ( '/([[:alpha:]]+)[\s]*([=|>|<])[\s]*([[:alnum:]\.]+)/' , $ t , $ params ) ; if ( isset ( $ params [ 1 ] ) && isset ( $ params [ 2 ] ) && isset ( $ params [ 3 ] ) && $ log :: isField ( trim ( $ params [ 1 ] ) ) ) { $ threshold [ trim ( $ params [ 1 ] ) ] = [ 'key' => $ params [ 1 ] , 'operator' => $ params [ 2 ] , 'value' => $ params [ 3 ] ] ; } } return $ threshold ; }
Parse thresholds from user input to array
46,242
private function mapDateFormat ( $ name ) { switch ( $ name ) { case 'full' : $ log = $ this -> log ; $ format = $ log :: getDateFormat ( ) ; break ; case 'long' : $ format = "Y-m-d H:i:s" ; break ; case 'short' : $ format = "h:i:sa" ; break ; default : $ format = "D h:i:sa" ; break ; } return $ format ; }
Map date format keyword to php date format string
46,243
public function setRenderer ( $ renderer ) { if ( is_string ( $ renderer ) ) { $ cName = $ this -> scrub ( $ renderer ) ; $ invokable = __NAMESPACE__ . '\\Dumper\\' . ucfirst ( $ cName ) ; if ( ! class_exists ( $ invokable ) ) { throw new RendererNotFoundException ( sprintf ( '%s: failed retrieving renderer via invokable class "%s"; class does not exist' , __CLASS__ . '::' . __FUNCTION__ , $ invokable ) ) ; } $ renderer = new $ invokable ; } if ( ! ( $ renderer instanceof Renderable ) ) { throw new InvalidArgumentException ( sprintf ( '%s was unable to fetch renderer or renderer was not an instance of %s' , get_class ( $ this ) . '::' . __FUNCTION__ , __NAMESPACE__ . '\\Dumper\\Renderable' ) ) ; } $ this -> _renderer = $ renderer ; return $ this ; }
Sets the renderer
46,244
public function messages ( ) { $ messages = $ this -> _messages ; usort ( $ messages , function ( $ a , $ b ) { if ( $ a [ 'time' ] === $ b [ 'time' ] ) { return 0 ; } return $ a [ 'time' ] < $ b [ 'time' ] ? - 1 : 1 ; } ) ; return $ messages ; }
Get a list of messages
46,245
public static function dump ( $ var , $ to = null ) { $ console = self :: getInstance ( ) ; $ console -> addVar ( $ var ) ; echo $ console -> render ( $ to ) ; $ console -> clear ( ) ; }
Dumps a var
46,246
public function setup ( ) { $ this -> addRule ( 'ip' , function ( $ data ) { if ( isset ( $ data [ 'ip' ] ) && ! Validate :: ip ( $ data [ 'ip' ] ) ) { return Lang :: txt ( 'Invalid IP address' ) ; } return false ; } ) ; }
Runs extra setup code when creating a new model
46,247
public function automaticItemType ( $ data ) { if ( isset ( $ data [ 'item_type' ] ) ) { $ data [ 'item_type' ] = strtolower ( preg_replace ( "/[^a-zA-Z0-9\-]/" , '' , trim ( $ data [ 'item_type' ] ) ) ) ; } return $ data [ 'item_type' ] ; }
Generates automatic item type value
46,248
public function hasVoted ( $ item_type , $ item_id , $ user_id = null , $ ip = null ) { return self :: oneByScope ( $ item_type , $ item_id , $ user_id , $ ip ) -> get ( 'id' ) ; }
Check if a user has voted
46,249
public static function getInstance ( $ uri = 'SERVER' ) { if ( empty ( self :: $ instances [ $ uri ] ) ) { if ( $ uri == 'SERVER' ) { if ( isset ( $ _SERVER [ 'HTTPS' ] ) && ! empty ( $ _SERVER [ 'HTTPS' ] ) && ( strtolower ( $ _SERVER [ 'HTTPS' ] ) != 'off' ) ) { $ https = 's://' ; } else { $ https = '://' ; } if ( ! empty ( $ _SERVER [ 'PHP_SELF' ] ) && ! empty ( $ _SERVER [ 'REQUEST_URI' ] ) ) { $ theURI = 'http' . $ https . $ _SERVER [ 'HTTP_HOST' ] . $ _SERVER [ 'REQUEST_URI' ] ; } else { $ theURI = 'http' . $ https . $ _SERVER [ 'HTTP_HOST' ] . $ _SERVER [ 'SCRIPT_NAME' ] ; if ( isset ( $ _SERVER [ 'QUERY_STRING' ] ) && ! empty ( $ _SERVER [ 'QUERY_STRING' ] ) ) { $ theURI .= '?' . $ _SERVER [ 'QUERY_STRING' ] ; } } $ _SERVER [ 'REQUEST_URI' ] = str_replace ( array ( "'" , '"' , '<' , '>' ) , array ( '%27' , '%22' , '%3C' , '%3E' ) , $ _SERVER [ 'REQUEST_URI' ] ) ; $ theURI = str_replace ( array ( "'" , '"' , '<' , '>' ) , array ( '%27' , '%22' , '%3C' , '%3E' ) , $ theURI ) ; } else { $ theURI = $ uri ; } self :: $ instances [ $ uri ] = new self ( $ theURI ) ; } return self :: $ instances [ $ uri ] ; }
Returns the global URI object only creating it if it doesn t already exist .
46,250
public function root ( $ pathonly = false , $ path = null ) { $ prefix = $ this -> toString ( array ( 'scheme' , 'host' , 'port' ) ) ; if ( ! isset ( $ path ) ) { $ path = rtrim ( $ this -> toString ( array ( 'path' ) ) , '/\\' ) ; } return $ pathonly === false ? $ prefix . $ path . '/' : $ path ; }
Returns the root URI
46,251
public static function isInternal ( $ url ) { $ current = self :: getInstance ( ) -> toString ( [ 'scheme' , 'host' ] ) ; $ given = self :: getInstance ( $ url ) ; $ base = $ given -> toString ( [ 'scheme' , 'host' , 'path' ] ) ; $ host = $ given -> toString ( [ 'scheme' , 'host' ] ) ; if ( stripos ( $ base , $ current ) !== 0 && ! empty ( $ host ) ) { return false ; } return true ; }
Checks if the supplied URL is internal
46,252
public function currentRun ( ) { if ( ! $ this -> _currentRun ) { $ this -> _currentRun = $ this -> runs ( ) -> whereEquals ( 'import_id' , $ this -> get ( 'id' ) ) -> ordered ( ) -> row ( ) ; } return $ this -> _currentRun ; }
Get most current run
46,253
public function getDataPath ( ) { if ( ! $ file = $ this -> get ( 'file' ) ) { throw new Exception ( __METHOD__ . '(); ' . Lang :: txt ( 'Missing required data file.' ) ) ; } $ filePath = $ this -> fileSpacePath ( ) . DS . $ file ; if ( ! file_exists ( $ filePath ) ) { throw new Exception ( __METHOD__ . '(); ' . Lang :: txt ( 'Data file does not exist at path: %s.' , $ filePath ) ) ; } if ( ! is_readable ( $ filePath ) ) { throw new Exception ( __METHOD__ . '(); ' . Lang :: txt ( 'Data file not readable.' ) ) ; } return $ filePath ; }
Return path to imports data file
46,254
public function markRun ( $ dryRun = 1 ) { $ run = Run :: blank ( ) ; $ run -> set ( 'import_id' , $ this -> get ( 'id' ) ) -> set ( 'count' , $ this -> get ( 'count' ) ) -> set ( 'ran_by' , User :: get ( 'id' ) ) -> set ( 'ran_at' , Date :: toSql ( ) ) -> set ( 'dry_run' , $ dryRun ) -> save ( ) ; }
Mark Import Run
46,255
public function add ( ) { $ name = $ this -> arguments -> getOpt ( 3 ) ; $ path = $ this -> arguments -> getOpt ( 4 ) ; $ this -> arguments -> deleteOpt ( 3 ) ; $ this -> arguments -> deleteOpt ( 4 ) ; $ this -> arguments -> setOpt ( 'aliases' , array ( $ name => $ path ) ) ; App :: get ( 'client' ) -> call ( 'configuration' , 'set' , $ this -> arguments , $ this -> output ) ; }
Adds a new console alias
46,256
public static function urlForClient ( $ client , $ url , $ xhtml = true , $ ssl = null ) { if ( ! $ client ) { return static :: getRoot ( ) -> url ( $ url , $ xhtml , $ ssl ) ; } return self :: $ app [ 'router' ] -> client ( $ client ) -> url ( $ url , $ xhtml , $ ssl ) ; }
Get the router for a specific client
46,257
public static function instance ( $ type ) { $ type = strtolower ( preg_replace ( '/[^A-Z0-9_]/i' , '' , $ type ) ) ; if ( ! isset ( self :: $ instances [ $ type ] ) ) { $ class = __NAMESPACE__ . '\\Processor\\' . ucfirst ( $ type ) ; if ( ! class_exists ( $ class ) ) { foreach ( self :: all ( ) as $ inst ) { if ( in_array ( $ type , $ inst -> getSupportedExtensions ( ) ) ) { $ class = get_class ( $ inst ) ; } } if ( ! class_exists ( $ class ) ) { throw new InvalidArgumentException ( sprintf ( 'Unable to load format class for format "%s"' , $ type ) , 500 ) ; } } self :: $ instances [ $ type ] = new $ class ; } return self :: $ instances [ $ type ] ; }
Returns a reference to a Processor object only creating it if it doesn t already exist .
46,258
public static function all ( ) { foreach ( glob ( __DIR__ . DIRECTORY_SEPARATOR . 'Processor' . DIRECTORY_SEPARATOR . '*.php' ) as $ path ) { $ type = strtolower ( basename ( $ path , '.php' ) ) ; if ( ! isset ( self :: $ instances [ $ type ] ) ) { $ class = __NAMESPACE__ . '\\Processor\\' . ucfirst ( $ type ) ; if ( ! class_exists ( $ class ) ) { include_once $ path ; } self :: $ instances [ $ type ] = new $ class ; } } return self :: $ instances ; }
Return a list of all available processors .
46,259
public function byPosition ( $ position ) { $ position = strtolower ( $ position ) ; $ result = array ( ) ; $ modules = $ this -> all ( ) ; $ total = count ( $ modules ) ; for ( $ i = 0 ; $ i < $ total ; $ i ++ ) { if ( $ modules [ $ i ] -> position == $ position ) { $ result [ ] = & $ modules [ $ i ] ; } } if ( count ( $ result ) == 0 ) { if ( $ this -> outline ( ) ) { $ result [ 0 ] = $ this -> byName ( 'mod_' . $ position ) ; $ result [ 0 ] -> title = $ position ; $ result [ 0 ] -> content = $ position ; $ result [ 0 ] -> position = $ position ; } } return $ result ; }
Get modules by position
46,260
public function isEnabled ( $ module ) { $ result = $ this -> byName ( $ module ) ; return ( is_object ( $ result ) && $ result -> id ) ; }
Checks if a module is enabled
46,261
public function position ( $ position , $ style = 'none' ) { if ( ! is_array ( $ style ) ) { $ style = array ( 'style' => $ style ) ; } $ contents = '' ; foreach ( $ this -> byPosition ( $ position ) as $ mod ) { $ contents .= $ this -> render ( $ mod , $ style ) ; } return $ contents ; }
Render modules for a position
46,262
public function name ( $ name , $ style = 'none' ) { if ( ! is_array ( $ style ) ) { $ style = array ( 'style' => $ style ) ; } return $ this -> render ( $ this -> byName ( $ name ) , $ style ) ; }
Render module by name
46,263
protected function outline ( ) { if ( $ this -> app [ 'request' ] -> getBool ( 'tp' ) && $ this -> app [ 'component' ] -> params ( 'com_templates' ) -> get ( 'template_positions_display' ) ) { return true ; } return false ; }
Determine if module position outlining is enabled
46,264
public function params ( $ id ) { $ params = '' ; if ( $ this -> app -> has ( 'db' ) ) { $ db = $ this -> app [ 'db' ] ; $ query = $ db -> getQuery ( ) -> select ( 'params' ) -> from ( '#__modules' ) -> whereEquals ( 'published' , 1 ) ; if ( is_numeric ( $ id ) ) { $ query -> whereEquals ( 'id' , ( int ) $ id ) ; } else { $ query -> whereEquals ( 'module' , $ id ) ; } $ db -> setQuery ( $ query -> toString ( ) ) ; $ params = $ db -> loadResult ( ) ; } return new Registry ( $ params ) ; }
Get the parameters for a module
46,265
public function canonical ( $ module ) { $ module = preg_replace ( '/[^A-Z0-9_\.-]/i' , '' , $ module ) ; if ( substr ( $ module , 0 , strlen ( 'mod_' ) ) != 'mod_' ) { $ module = 'mod_' . $ module ; } return $ module ; }
Make sure module name follows naming conventions
46,266
public function path ( $ module ) { $ module = $ this -> canonical ( $ module ) ; $ prefixed = $ module ; $ unprefixed = substr ( $ module , 4 ) ; $ paths = array ( PATH_APP . DS . 'modules' . DS . $ unprefixed . DS . $ unprefixed . '.php' , PATH_APP . DS . 'modules' . DS . $ prefixed . DS . $ prefixed . '.php' , PATH_CORE . DS . 'modules' . DS . $ unprefixed . DS . $ unprefixed . '.php' , PATH_CORE . DS . 'modules' . DS . $ prefixed . DS . $ prefixed . '.php' ) ; foreach ( $ paths as $ path ) { if ( file_exists ( $ path ) ) { return $ path ; } } return '' ; }
Get the path to a module
46,267
public static function pad ( $ value , $ length = 5 , $ prfx = 0 ) { $ pre = '' ; if ( is_numeric ( $ value ) && $ value < 0 ) { $ pre = 'n' ; $ value = abs ( $ value ) ; } while ( strlen ( $ value ) < $ length ) { $ value = $ prfx . "$value" ; } return $ pre . $ value ; }
Format a number by prefixing a character to a specificed length .
46,268
public static function auth ( $ message ) { $ instance = static :: getRoot ( ) ; if ( $ instance -> has ( 'auth' ) ) { $ logger = $ instance -> logger ( 'auth' ) ; } else { $ logger = $ instance -> logger ( ) ; } return $ logger -> info ( $ message ) ; }
Log an entry to the auth logger
46,269
public static function spam ( $ message ) { $ instance = static :: getRoot ( ) ; if ( $ instance -> has ( 'spam' ) ) { $ logger = $ instance -> logger ( 'spam' ) ; } else { $ logger = $ instance -> logger ( ) ; } return $ logger -> info ( $ message ) ; }
Log an entry to the spam logger
46,270
public function init ( $ initMessage = null , $ type = 'percentage' , $ total = null ) { $ this -> makeInteractive ( ) ; if ( isset ( $ initMessage ) ) { $ this -> addString ( $ initMessage ) ; $ this -> initMessageLength = strlen ( $ initMessage ) ; } switch ( $ type ) { case 'ratio' : $ this -> setProgress ( 0 , $ total ) ; break ; case 'percentage' : default : $ this -> setProgress ( '0' ) ; break ; } }
Initialize progress counter
46,271
public function setProgress ( $ val , $ tot = null ) { if ( $ this -> contentLength > 0 ) { $ this -> backspace ( $ this -> contentLength ) ; } if ( ! is_null ( $ tot ) ) { $ content = "({$val}/{$tot})" ; } else { $ content = "{$val}%" ; } $ this -> contentLength = strlen ( $ content ) ; $ this -> addString ( $ content ) ; }
Set the current progress val
46,272
public function done ( ) { $ length = $ this -> contentLength + $ this -> initMessageLength ; $ this -> backspace ( $ length , true ) ; $ this -> contentLength = 0 ; $ this -> initMessageLength = 0 ; }
Finish progress output
46,273
public function seek ( $ index ) { $ this -> rewind ( ) ; while ( $ this -> _pos < $ index && $ this -> valid ( ) ) { $ this -> next ( ) ; } if ( ! $ this -> valid ( ) ) { throw new \ OutOfBoundsException ( \ Lang :: txt ( 'Invalid seek position' ) ) ; } }
Seek to an absolute position
46,274
public function offsetSet ( $ offset , $ item ) { if ( $ offset === null ) { $ this -> _data [ ] = $ item ; $ this -> _total = count ( $ this -> _data ) ; } else { $ this -> _data [ $ offset ] = $ item ; } }
Append a new item
46,275
public function merge ( ) { foreach ( func_get_args ( ) as $ list ) { if ( $ list instanceof self ) { $ this -> _data = array_merge ( $ this -> _data , $ list -> _data ) ; } } return new static ( $ this -> _data ) ; }
Merge Item Lists
46,276
public function rows ( ) { $ rows = parent :: rows ( ) ; foreach ( $ rows as $ row ) { $ associatives = new \ stdClass ( ) ; foreach ( $ row -> getAttributes ( ) as $ k => $ v ) { if ( strpos ( $ k , 'associative_' ) === 0 ) { $ key = substr ( $ k , 12 ) ; $ associatives -> $ key = $ v ; $ row -> removeAttribute ( $ k ) ; } } if ( ! empty ( $ associatives ) ) { $ row -> associated = $ associatives ; } } return $ rows ; }
Fetches the results of relationship
46,277
public function connect ( $ ids ) { if ( is_array ( $ ids ) && count ( $ ids ) > 0 ) { foreach ( $ ids as $ id => $ associative ) { $ id = ( is_array ( $ associative ) ) ? $ id : $ associative ; $ data = array_merge ( $ this -> getConnectionData ( ) , [ $ this -> associativeRelated => $ id ] ) ; if ( is_array ( $ associative ) ) { $ data = array_merge ( $ data , $ associative ) ; } $ query = $ this -> model -> getQuery ( ) -> push ( $ this -> associativeTable , $ data , true ) ; } } return $ this ; }
Connects the provided identifiers back to the parent model by way of associative entities
46,278
public function sync ( $ ids ) { if ( is_array ( $ ids ) ) { $ query = $ this -> model -> getQuery ( ) ; $ localKeyValue = $ this -> model -> getPkValue ( ) ; $ existing = $ query -> select ( $ this -> associativeRelated ) -> from ( $ this -> associativeTable ) -> whereEquals ( $ this -> associativeLocal , $ localKeyValue ) -> fetch ( 'column' ) ; $ deletes = array_diff ( $ existing , $ ids ) ; if ( ! empty ( $ deletes ) ) { $ query -> delete ( $ this -> associativeTable ) -> whereEquals ( $ this -> associativeLocal , $ localKeyValue ) -> whereIn ( $ this -> associativeRelated , $ deletes ) -> execute ( ) ; } $ inserts = array_diff ( $ ids , $ existing ) ; $ this -> connect ( $ inserts ) ; } return $ this ; }
Syncs the provided identifiers back to the parent model by way of associative entities deleting ones that should no longer be there and adding ones that are missing .
46,279
public function render ( $ name , $ params = array ( ) , $ content = null ) { $ buffer = array ( ) ; $ lists = array ( ) ; $ messages = \ App :: get ( 'notification' ) -> messages ( ) ; if ( is_array ( $ messages ) && ! empty ( $ messages ) ) { foreach ( $ messages as $ msg ) { if ( isset ( $ msg [ 'type' ] ) && isset ( $ msg [ 'message' ] ) ) { $ lists [ $ msg [ 'type' ] ] [ ] = $ msg [ 'message' ] ; } } } $ lnEnd = $ this -> doc -> _getLineEnd ( ) ; $ tab = $ this -> doc -> _getTab ( ) ; $ buffer [ ] = '<div id="system-message-container">' ; if ( ! empty ( $ lists ) ) { $ buffer [ ] = $ tab . '<dl id="system-message">' ; foreach ( $ lists as $ type => $ msgs ) { if ( count ( $ msgs ) ) { $ buffer [ ] = $ tab . $ tab . '<dt class="' . strtolower ( $ type ) . '">' . \ App :: get ( 'language' ) -> txt ( $ type ) . '</dt>' ; $ buffer [ ] = $ tab . $ tab . '<dd class="' . strtolower ( $ type ) . ' message">' ; $ buffer [ ] = $ tab . $ tab . $ tab . '<ul>' ; foreach ( $ msgs as $ msg ) { $ buffer [ ] = $ tab . $ tab . $ tab . $ tab . '<li>' . $ msg . '</li>' ; } $ buffer [ ] = $ tab . $ tab . $ tab . '</ul>' ; $ buffer [ ] = $ tab . $ tab . '</dd>' ; } } $ buffer [ ] = $ tab . '</dl>' ; } $ buffer [ ] = '</div>' ; return implode ( $ lnEnd , $ buffer ) ; }
Renders the error stack and returns the results as a string
46,280
public static function client ( $ id = null , $ byName = false ) { if ( self :: $ _clients === null ) { self :: $ _clients = array ( ) ; include_once __DIR__ . DIRECTORY_SEPARATOR . 'Client' . DIRECTORY_SEPARATOR . 'ClientInterface.php' ; $ dirIterator = new \ DirectoryIterator ( __DIR__ . DIRECTORY_SEPARATOR . 'Client' ) ; foreach ( $ dirIterator as $ file ) { if ( $ file -> isDot ( ) || $ file -> isDir ( ) ) { continue ; } $ client = preg_replace ( '#\.[^.]*$#' , '' , $ file -> getFilename ( ) ) ; if ( $ client == 'ClientInterface' ) { continue ; } $ cls = __NAMESPACE__ . '\\Client\\' . ucfirst ( strtolower ( $ client ) ) ; if ( ! class_exists ( $ cls ) ) { include_once $ file -> getPathname ( ) ; if ( ! class_exists ( $ cls ) ) { throw new \ InvalidArgumentException ( sprintf ( 'Invalid client type of "%s".' , $ client ) ) ; } } $ obj = new $ cls ; self :: $ _clients [ $ obj -> id ] = $ obj ; } ksort ( self :: $ _clients ) ; } if ( is_null ( $ id ) ) { return self :: $ _clients ; } if ( ! $ byName ) { if ( isset ( self :: $ _clients [ $ id ] ) ) { return self :: $ _clients [ $ id ] ; } } else { foreach ( self :: $ _clients as $ client ) { if ( $ client -> name == strtolower ( $ id ) ) { return $ client ; } } } return null ; }
Gets information on a specific client id . This method will be useful in future versions when we start mapping applications in the database .
46,281
public static function modify ( $ client , $ property , $ value ) { if ( $ cl = self :: client ( $ client ) ) { $ cl -> $ property = $ value ; } }
Modify information on a client .
46,282
public static function append ( $ client ) { if ( is_array ( $ client ) ) { $ client = ( object ) $ client ; } if ( ! is_object ( $ client ) ) { return false ; } $ info = self :: client ( ) ; if ( ! isset ( $ client -> id ) ) { $ client -> id = count ( $ info ) ; } self :: $ _clients [ $ client -> id ] = clone $ client ; return true ; }
Adds information for a client .
46,283
public function render ( & $ definition ) { $ class = null ; $ style = null ; $ class = ( empty ( $ definition [ 1 ] ) ) ? 'spacer' : $ definition [ 1 ] ; $ style = ( empty ( $ definition [ 2 ] ) ) ? null : ' style="width:' . intval ( $ definition [ 2 ] ) . 'px;"' ; return '<li class="' . $ class . '"' . $ style . ">\n</li>\n" ; }
Get the HTML for a separator in the toolbar
46,284
public static function createSiteList ( $ pathToXml , $ selected = null ) { $ list = array ( ) ; $ xml = false ; if ( ! empty ( $ pathToXml ) ) { libxml_use_internal_errors ( true ) ; $ xml = simplexml_load_file ( $ pathToXml ) ; } if ( ! $ xml ) { $ option [ 'text' ] = 'English (US) hubzero.org' ; $ option [ 'value' ] = 'http://hubzero.org/documentation' ; $ list [ ] = $ option ; } else { $ option = array ( ) ; foreach ( $ xml -> sites -> site as $ site ) { $ option [ 'text' ] = ( string ) $ site ; $ option [ 'value' ] = ( string ) $ site -> attributes ( ) -> url ; $ list [ ] = $ option ; } } return $ list ; }
Builds a list of the help sites which can be used in a select option .
46,285
public function consumerHandler ( ) { $ db = \ App :: get ( 'db' ) ; if ( ! is_object ( $ db ) ) { return OAUTH_ERR_INTERNAL_ERROR ; } $ db -> setQuery ( "SELECT * FROM `#__oauthp_consumers` WHERE token=" . $ db -> quote ( $ this -> _provider -> consumer_key ) . " LIMIT 1;" ) ; $ result = $ db -> loadObject ( ) ; if ( $ result === false ) { return OAUTH_ERR_INTERNAL_ERROR ; } if ( empty ( $ result ) ) { return OAUTH_CONSUMER_KEY_UNKNOWN ; } if ( $ result -> state != 1 ) { return OAUTH_CONSUMER_KEY_REFUSED ; } $ this -> _consumer_data = $ result ; $ this -> _provider -> consumer_secret = $ result -> secret ; return OAUTH_OK ; }
OAuthProvider consumerHandler Callback
46,286
public function timestampNonceHandler ( ) { $ timediff = abs ( time ( ) - $ this -> _provider -> timestamp ) ; if ( $ timediff > 600 ) { return OAUTH_BAD_TIMESTAMP ; } $ db = \ App :: get ( 'db' ) ; if ( ! is_object ( $ db ) ) { return OAUTH_ERR_INTERNAL_ERROR ; } $ db -> setQuery ( "INSERT INTO `#__oauthp_nonces` (nonce,stamp,created) " . " VALUES (" . $ db -> quote ( $ this -> _provider -> nonce ) . "," . $ db -> quote ( $ this -> _provider -> timestamp ) . ", UTC_TIMESTAMP());" ) ; if ( ( $ db -> query ( ) === false ) && ( $ db -> getErrorNum ( ) != 1062 ) ) { return OAUTH_ERR_INTERNAL_ERROR ; } if ( $ db -> getAffectedRows ( ) < 1 ) { return OAUTH_BAD_NONCE ; } return OAUTH_OK ; }
OAuthProvider timestampNonceHandler Callback
46,287
public function tokenHandler ( ) { $ db = \ App :: get ( 'db' ) ; if ( ! is_object ( $ db ) ) { return OAUTH_ERR_INTERNAL_ERROR ; } $ db -> setQuery ( "SELECT * FROM `#__oauthp_tokens` WHERE token=" . $ db -> quote ( $ this -> _provider -> token ) . " LIMIT 1;" ) ; $ result = $ db -> loadObject ( ) ; if ( $ result === false ) { return OAUTH_ERR_INTERNAL_ERROR ; } if ( empty ( $ result ) ) { return OAUTH_TOKEN_REJECTED ; } if ( $ result -> state != '1' ) { return OAUTH_TOKEN_REJECTED ; } if ( $ result -> user_id == '0' ) { if ( $ result -> verifier != $ this -> _provider -> verifier ) { return OAUTH_VERIFIER_INVALID ; } } $ this -> _token_data = $ result ; $ this -> _provider -> token_secret = $ result -> token_secret ; return OAUTH_OK ; }
OAuthProvider tokenHandler Callback
46,288
public function process ( Import $ import , array $ callbacks , $ dryRun ) { $ iterator = new Reader ( $ import -> getDatapath ( ) , $ this -> delimiter ) ; $ options = new Parameter ( $ import -> get ( 'params' ) ) ; $ mode = $ import -> get ( 'mode' , 'UPDATE' ) ; foreach ( $ iterator as $ index => $ record ) { if ( $ record === null ) { continue ; } $ data = array_map ( 'trim' , ( array ) $ record ) ; if ( ! array_filter ( $ data ) ) { continue ; } $ record = $ this -> map ( $ record , $ callbacks [ 'postparse' ] , $ dryRun ) ; $ entry = $ import -> getRecord ( $ record , $ options -> toArray ( ) , $ mode ) ; $ entry = $ this -> map ( $ entry , $ callbacks [ 'postmap' ] , $ dryRun ) ; $ entry -> check ( ) -> store ( $ dryRun ) ; $ entry = $ this -> map ( $ entry , $ callbacks [ 'postconvert' ] , $ dryRun ) ; array_push ( $ this -> data , $ entry ) ; $ import -> currentRun ( ) -> processed ( 1 ) ; } return $ this -> data ; }
Process Import data
46,289
public static function bake ( $ namespace , $ lifetime , $ data = array ( ) ) { $ hash = \ App :: hash ( \ App :: get ( 'client' ) -> name . ':' . $ namespace ) ; $ key = \ App :: hash ( '' ) ; $ crypt = new \ Hubzero \ Encryption \ Encrypter ( new \ Hubzero \ Encryption \ Cipher \ Simple , new \ Hubzero \ Encryption \ Key ( 'simple' , $ key , $ key ) ) ; $ cookie = $ crypt -> encrypt ( serialize ( $ data ) ) ; $ secure = false ; $ forceSsl = \ Config :: get ( 'force_ssl' , false ) ; if ( \ App :: isAdmin ( ) && $ forceSsl >= 1 ) { $ secure = true ; } else if ( \ App :: isSite ( ) && $ forceSsl == 2 ) { $ secure = true ; } setcookie ( $ hash , $ cookie , $ lifetime , '/' , '' , $ secure , true ) ; }
Drop a cookie
46,290
public static function eat ( $ namespace ) { $ hash = \ App :: hash ( \ App :: get ( 'client' ) -> name . ':' . $ namespace ) ; $ key = \ App :: hash ( '' ) ; $ crypt = new \ Hubzero \ Encryption \ Encrypter ( new \ Hubzero \ Encryption \ Cipher \ Simple , new \ Hubzero \ Encryption \ Key ( 'simple' , $ key , $ key ) ) ; if ( $ str = \ App :: get ( 'request' ) -> getString ( $ hash , '' , 'cookie' ) ) { $ sstr = $ crypt -> decrypt ( $ str ) ; $ cookie = @ unserialize ( $ sstr ) ; return ( object ) $ cookie ; } return false ; }
Retrieve a cookie
46,291
public static function paranoid ( $ string , $ allowed = array ( ) ) { $ allow = null ; if ( ! empty ( $ allowed ) ) { foreach ( $ allowed as $ value ) { $ allow .= "\\$value" ; } } if ( ! is_array ( $ string ) ) { return preg_replace ( "/[^{$allow}a-zA-Z0-9]/" , '' , $ string ) ; } $ cleaned = array ( ) ; foreach ( $ string as $ key => $ clean ) { $ cleaned [ $ key ] = preg_replace ( "/[^{$allow}a-zA-Z0-9]/" , '' , $ clean ) ; } return $ cleaned ; }
Removes any non - alphanumeric characters .
46,292
public static function cleanMsChar ( $ text , $ quotesOnly = false ) { $ y = array ( "\x7f" => '' , "\x80" => '&#8364;' , "\x81" => '' , "\x83" => '&#402;' , "\x85" => '&#8230;' , "\x86" => '&#8224;' , "\x87" => '&#8225;' , "\x88" => '&#710;' , "\x89" => '&#8240;' , "\x8a" => '&#352;' , "\x8b" => '&#8249;' , "\x8c" => '&#338;' , "\x8d" => '' , "\x8e" => '&#381;' , "\x8f" => '' , "\x90" => '' , "\x95" => '&#8226;' , "\x96" => '&#8211;' , "\x97" => '&#8212;' , "\x98" => '&#732;' , "\x99" => '&#8482;' , "\x9a" => '&#353;' , "\x9b" => '&#8250;' , "\x9c" => '&#339;' , "\x9d" => '' , "\x9e" => '&#382;' , "\x9f" => '&#376;' , ) ; $ x = array ( "\x82" => '\'' , "\x84" => '"' , "\x91" => '\'' , "\x92" => '\'' , "\x93" => '"' , "\x94" => '"' ) ; if ( ! $ quotesOnly ) { $ x = $ y + $ x ; } $ text = strtr ( $ text , $ x ) ; return $ text ; }
Replace discouraged characters introduced by Microsoft Word
46,293
public static function html ( $ text , $ options = [ ] ) { $ config = self :: _buildHtmlPurifierConfig ( $ options ) ; $ htmlPurifierWhitelist = $ config -> getHTMLDefinition ( true ) ; self :: _addElementsToHtmlPurifierWhitelist ( $ htmlPurifierWhitelist ) ; self :: _addAttributesToHtmlPurifierWhitelist ( $ htmlPurifierWhitelist ) ; $ purifier = new \ HTMLPurifier ( $ config ) ; return $ purifier -> purify ( $ text ) ; }
Run HTML through a purifier
46,294
protected static function _buildHtmlPurifierConfig ( $ options ) { $ config = \ HTMLPurifier_Config :: createDefault ( ) ; $ root = str_replace ( [ 'http://' , 'https://' , '.' ] , [ '' , '' , '\.' ] , \ App :: get ( 'request' ) -> root ( ) ) ; $ defaultSettings = [ 'AutoFormat.Linkify' => false , 'AutoFormat.RemoveEmpty' => true , 'AutoFormat.RemoveEmpty.RemoveNbsp' => false , 'Output.CommentScriptContents' => false , 'Output.TidyFormat' => true , 'Attr.AllowedFrameTargets' => [ '_blank' ] , 'Attr.EnableID' => true , 'HTML.AllowedCommentsRegexp' => '/./' , 'HTML.SafeIframe' => true , 'URI.SafeIframeRegexp' => "%^(https?:)?//(www\.youtube(?:-nocookie)?\.com/embed/|player\.vimeo\.com/video/|$root)%" , ] ; $ combinedSettings = array_merge ( $ defaultSettings , $ options ) ; self :: _findOrCreateClientSerializerDirectory ( $ combinedSettings ) ; foreach ( $ combinedSettings as $ setting => $ value ) { $ config -> set ( $ setting , $ value ) ; } return $ config ; }
Builds HTML purification configuration
46,295
protected static function _findOrCreateClientSerializerDirectory ( $ purifierConfigSettings ) { $ client = \ App :: get ( 'client' ) ; $ clientAlias = isset ( $ client -> alias ) ? $ client -> alias : $ client -> name ; $ clientSerializerPath = PATH_APP . "/cache/$clientAlias/htmlpurifier" ; if ( ! is_dir ( $ clientSerializerPath ) ) { \ App :: get ( 'filesystem' ) -> makeDirectory ( $ clientSerializerPath ) ; } if ( is_dir ( $ clientSerializerPath ) ) { $ purifierConfigSettings [ 'Cache.SerializerPath' ] = $ clientSerializerPath ; } }
Finds or creates client serializer directory
46,296
protected static function _addElementsToHtmlPurifierWhitelist ( $ htmlPurifierWhitelist ) { $ styleElement = [ 'name' => 'style' , 'contentSet' => 'Block' , 'allowedChildren' => 'Flow' , 'attributeCollection' => 'Common' , 'attributes' => [ ] , 'excludes' => [ ] ] ; $ mapElement = [ 'name' => 'map' , 'contentSet' => 'Block' , 'allowedChildren' => 'Flow' , 'attributeCollection' => 'Common' , 'attributes' => [ 'name' => 'CDATA' , 'id' => 'ID' , 'title' => 'CDATA' , ] , 'excludes' => [ 'map' => true ] ] ; $ areaElement = [ 'name' => 'area' , 'contentSet' => 'Block' , 'allowedChildren' => 'Empty' , 'attributeCollection' => 'Common' , 'attributes' => [ 'name' => 'CDATA' , 'id' => 'ID' , 'alt' => 'Text' , 'coords' => 'CDATA' , 'accesskey' => 'Character' , 'nohref' => new \ HTMLPurifier_AttrDef_Enum ( [ 'nohref' ] ) , 'href' => 'URI' , 'shape' => new \ HTMLPurifier_AttrDef_Enum ( [ 'rect' , 'circle' , 'poly' , 'default' ] ) , 'tabindex' => 'Number' , 'target' => new \ HTMLPurifier_AttrDef_Enum ( [ '_blank' , '_self' , '_target' , '_top' ] ) ] , 'excludes' => [ 'area' => true ] ] ; $ elementSettings = [ $ styleElement , $ mapElement , $ areaElement ] ; foreach ( $ elementSettings as $ settings ) { $ element = $ htmlPurifierWhitelist -> addElement ( $ settings [ 'name' ] , $ settings [ 'contentSet' ] , $ settings [ 'allowedChildren' ] , $ settings [ 'attributeCollection' ] , $ settings [ 'attributes' ] ) ; $ element -> excludes = $ settings [ 'excludes' ] ; } }
Adds elements to HTML purifier whitelist
46,297
public function getTableList ( ) { $ query = $ this -> getQuery ( ) -> select ( 'table_name' ) -> from ( 'information_schema.tables' ) -> whereEquals ( 'table_type' , 'BASE TABLE' ) -> whereNotIn ( 'table_schema' , [ 'pg_catalog' , 'information_schema' ] ) -> order ( 'table_name' , 'asc' ) -> toString ( ) ; $ this -> setQuery ( $ query ) ; $ tables = $ this -> loadColumn ( ) ; return $ tables ; }
Gets an array of all tables in the database
46,298
public function renameTable ( $ oldTable , $ newTable , $ backup = null , $ prefix = null ) { $ tableList = $ this -> getTableList ( ) ; if ( ! in_array ( $ oldTable , $ tableList , true ) ) { throw new \ RuntimeException ( 'Table not found in Postgres database.' ) ; } $ subQuery = $ this -> getQuery ( ) -> select ( 'indexrelid' ) -> from ( 'pg_index' ) -> join ( 'pg_class' , 'pg_class.oid' , 'pg_index.indrelid' ) -> whereEquals ( 'pg_class.relname' , $ oldTable ) -> toString ( ) ; $ this -> setQuery ( $ this -> getQuery ( ) -> select ( 'relname' ) -> from ( 'pg_class' ) -> whereRaw ( 'oid IN (' . ( string ) $ subQuery . ')' ) -> toString ( ) ) ; $ oldIndexes = $ this -> loadColumn ( ) ; foreach ( $ oldIndexes as $ oldIndex ) { $ changedIdxName = str_replace ( $ oldTable , $ newTable , $ oldIndex ) ; $ this -> setQuery ( 'ALTER INDEX ' . $ this -> escape ( $ oldIndex ) . ' RENAME TO ' . $ this -> escape ( $ changedIdxName ) ) -> execute ( ) ; } $ subQuery = $ this -> getQuery ( ) -> select ( 'oid' ) -> from ( 'pg_namespace' ) -> whereNotLike ( 'nspname' , 'pg_%' ) -> where ( 'nspname' , '!=' , 'information_schema' ) -> toString ( ) ; $ this -> setQuery ( $ this -> getQuery ( ) -> select ( 'relname' ) -> from ( 'pg_class' ) -> whereEquals ( 'relkind' , 'S' ) -> whereRaw ( 'relnamespace IN (' . ( string ) $ subQuery . ')' ) -> whereLike ( 'relname' , "%$oldTable%" ) -> toString ( ) ) ; $ oldSequences = $ this -> loadColumn ( ) ; foreach ( $ oldSequences as $ oldSequence ) { $ changedSequenceName = str_replace ( $ oldTable , $ newTable , $ oldSequence ) ; $ this -> setQuery ( 'ALTER SEQUENCE ' . $ this -> escape ( $ oldSequence ) . ' RENAME TO ' . $ this -> escape ( $ changedSequenceName ) ) -> execute ( ) ; } $ this -> setQuery ( 'ALTER TABLE ' . $ this -> escape ( $ oldTable ) . ' RENAME TO ' . $ this -> escape ( $ newTable ) ) -> execute ( ) ; return true ; }
Renames a table in the database
46,299
public static function oneByScope ( $ scope , $ scope_id ) { return self :: all ( ) -> whereEquals ( 'scope' , $ scope ) -> whereEquals ( 'scope_id' , $ scope_id ) -> ordered ( ) -> row ( ) ; }
Load a record by scope and scope_id