idx
int64 0
60.3k
| question
stringlengths 64
4.24k
| target
stringlengths 5
618
|
|---|---|---|
46,500
|
public function mergeAction ( $ action , $ identities ) { if ( isset ( $ this -> data [ $ action ] ) ) { $ this -> data [ $ action ] -> mergeIdentities ( $ identities ) ; } else { $ this -> data [ $ action ] = new Rule ( $ identities ) ; } }
|
Merges an array of identities for an action .
|
46,501
|
public function allow ( $ action , $ identity ) { if ( isset ( $ this -> data [ $ action ] ) ) { return $ this -> data [ $ action ] -> allow ( $ identity ) ; } return null ; }
|
Checks that an action can be performed by an identity .
|
46,502
|
public function getAllowed ( $ identity ) { $ allowed = new Obj ; foreach ( $ this -> data as $ name => & $ action ) { if ( $ action -> allow ( $ identity ) ) { $ allowed -> set ( $ name , true ) ; } } return $ allowed ; }
|
Get the allowed actions for an identity .
|
46,503
|
public static function format ( $ output ) { $ output -> addString ( 'The profile log has the following format (' ) ; $ output -> addString ( '* indicates visible field' , array ( 'color' => 'blue' ) ) ; $ output -> addLine ( '):' ) ; $ i = 0 ; foreach ( static :: $ fields as $ field => $ status ) { if ( $ i != 0 ) { $ output -> addString ( ' ' ) ; } $ output -> addString ( '<' ) ; if ( $ i < 10 ) { $ output -> addString ( $ i . ':' ) ; } if ( $ status ) { $ output -> addString ( '*' . $ field , array ( 'color' => 'blue' ) ) ; } else { $ output -> addString ( $ field ) ; } $ output -> addString ( '>' ) ; $ i ++ ; } $ output -> addSpacer ( ) -> addSpacer ( ) ; }
|
Show current output format
|
46,504
|
public static function toggle ( $ field , $ status = null ) { if ( strlen ( $ field ) == 1 && is_numeric ( $ field ) ) { $ i = 0 ; foreach ( static :: $ fields as $ f => $ s ) { if ( $ i == $ field ) { if ( ! isset ( $ status ) ) { $ status = ( $ s ) ? false : true ; } static :: $ fields [ $ f ] = $ status ; return ( ( $ status ) ? 'Showing ' : 'Hiding ' ) . $ f ; } $ i ++ ; } } else if ( $ field == 'all' ) { foreach ( static :: $ fields as $ f => $ s ) { static :: $ fields [ $ f ] = $ status ; } return ( ( $ status ) ? 'Showing ' : 'Hiding ' ) . 'all fields' ; } else if ( strpos ( $ field , ',' ) ) { $ fields = explode ( ',' , $ field ) ; $ valid = array ( ) ; foreach ( $ fields as $ f ) { $ f = trim ( $ f ) ; if ( isset ( static :: $ fields [ $ f ] ) ) { $ valid [ ] = $ f ; static :: $ fields [ $ f ] = $ status ; } } $ return = ( ( $ status ) ? 'Showing ' : 'Hiding ' ) ; if ( empty ( $ valid ) ) { $ return = 'No valid fields provided' ; } else { $ return .= implode ( ', ' , $ valid ) ; } return $ return ; } else if ( isset ( static :: $ fields [ $ field ] ) ) { static :: $ fields [ $ field ] = $ status ; return ( ( $ status ) ? 'Showing ' : 'Hiding ' ) . $ field ; } else { return false ; } }
|
Toggle field visibility
|
46,505
|
public static function parse ( $ line , $ output , $ settings ) { $ bits = explode ( ' ' , $ line , count ( static :: $ fields ) ) ; $ index = 0 ; $ i_used = 0 ; $ style = null ; $ exceeded = false ; if ( is_array ( $ settings [ 'threshold' ] ) ) { foreach ( static :: $ fields as $ field => $ show ) { if ( isset ( $ settings [ 'threshold' ] [ $ field ] ) ) { $ operator = $ settings [ 'threshold' ] [ $ field ] [ 'operator' ] ; $ value = $ settings [ 'threshold' ] [ $ field ] [ 'value' ] ; switch ( $ operator ) { case '=' : $ statement = ( trim ( $ bits [ $ index ] ) == $ value ) ; break ; case '<' : $ statement = ( trim ( $ bits [ $ index ] ) < $ value ) ; break ; case '>' : default : $ statement = ( trim ( $ bits [ $ index ] ) > $ value ) ; break ; } if ( $ statement ) { $ exceeded [ ] = $ field ; } } $ index ++ ; } } $ index = 0 ; foreach ( static :: $ fields as $ field => $ show ) { if ( $ show ) { if ( $ exceeded ) { $ style = array ( 'color' => 'red' ) ; if ( in_array ( $ field , $ exceeded ) ) { $ style = 'error' ; } } if ( $ i_used != 0 ) { $ output -> addString ( ' ' ) ; } $ value = trim ( $ bits [ $ index ] ) ; if ( isset ( static :: $ dateFormat ) ) { $ d = \ DateTime :: createFromFormat ( static :: $ dateFormat , $ value ) ; if ( $ d && $ d -> format ( static :: $ dateFormat ) == $ value ) { $ value = $ d -> format ( $ settings [ 'dateFormat' ] ) ; } } if ( method_exists ( get_called_class ( ) , 'parse' . ucfirst ( $ field ) ) ) { $ method = 'parse' . ucfirst ( $ field ) ; $ value = static :: $ method ( $ value ) ; } $ output -> addString ( $ value , $ style ) ; $ i_used ++ ; } $ index ++ ; } $ output -> addSpacer ( ) ; if ( $ exceeded && ! $ settings [ 'noBeep' ] ) { $ output -> beep ( ) ; } }
|
Parse log line
|
46,506
|
public function dump ( ) { $ tables = App :: get ( 'db' ) -> getTableList ( ) ; $ prefix = App :: get ( 'db' ) -> getPrefix ( ) ; $ excludes = [ ] ; $ now = new Date ; $ exclude = '' ; $ includes = ( array ) $ this -> arguments -> getOpt ( 'include-table' , [ ] ) ; if ( ! $ this -> arguments -> getOpt ( 'all-tables' ) ) { $ this -> output -> addLine ( 'Dumping database with all prefixed tables included' ) ; foreach ( $ tables as $ table ) { if ( strpos ( $ table , $ prefix ) !== 0 && ! in_array ( str_replace ( '#__' , $ prefix , $ table ) , $ includes ) ) { $ excludes [ ] = Config :: get ( 'db' ) . '.' . $ table ; } elseif ( in_array ( str_replace ( '#__' , $ prefix , $ table ) , $ includes ) ) { $ this -> output -> addLine ( 'Also including `' . $ table . '`' ) ; } } $ exclude = '--ignore-table=' . implode ( ' --ignore-table=' , $ excludes ) ; } else { $ this -> output -> addLine ( 'Dumping database with all tables included' ) ; } $ home = getenv ( 'HOME' ) ; $ hostname = gethostname ( ) ; $ filename = tempnam ( $ home , "{$hostname}.mysql.dump." . $ now -> format ( 'Y.m.d' ) . ".sql." ) ; $ cmd = "mysqldump -u " . Config :: get ( 'user' ) . " -p'" . Config :: get ( 'password' ) . "' " . Config :: get ( 'db' ) . " --routines {$exclude} > {$filename}" ; exec ( $ cmd ) ; $ this -> output -> addLine ( 'File saved to: ' . $ filename , 'success' ) ; }
|
Dump the database
|
46,507
|
public function load ( ) { if ( ! $ infile = $ this -> arguments -> getOpt ( 3 ) ) { $ this -> output -> error ( 'Please provide an input file' ) ; } else { if ( ! is_file ( $ infile ) ) { $ this -> output -> error ( "'{$infile}' does not appear to be a valid file" ) ; } } $ params = [ ] ; $ params [ 'com_system' ] = \ Component :: params ( 'com_system' ) ; $ params [ 'com_tools' ] = \ Component :: params ( 'com_tools' ) ; $ params [ 'com_usage' ] = \ Component :: params ( 'com_usage' ) ; $ params [ 'com_users' ] = \ Component :: params ( 'com_users' ) ; $ params [ 'plg_projects_databases' ] = \ Plugin :: params ( 'projects' , 'databases' ) ; $ tables = App :: get ( 'db' ) -> getTableList ( ) ; if ( $ this -> arguments -> getOpt ( 'drop-all-tables' ) ) { $ this -> output -> addLine ( 'Dropping all tables...' ) ; foreach ( $ tables as $ table ) { App :: get ( 'db' ) -> dropTable ( $ table ) ; } } $ infile = escapeshellarg ( $ infile ) ; $ cmd = "mysql -u " . Config :: get ( 'user' ) . " -p'" . Config :: get ( 'password' ) . "' -D " . Config :: get ( 'db' ) . " < {$infile}" ; $ this -> output -> addLine ( 'Loading data from ' . $ infile . '...' ) ; exec ( $ cmd ) ; $ migration = new Migration ( App :: get ( 'db' ) ) ; foreach ( $ params as $ k => $ v ) { if ( ! empty ( $ v ) ) { $ migration -> saveParams ( $ k , $ v ) ; } } $ this -> output -> addLine ( 'Load complete!' , 'success' ) ; }
|
Load a database dump
|
46,508
|
public function set ( ) { $ options = $ this -> arguments -> getOpts ( ) ; if ( empty ( $ options ) ) { if ( $ this -> output -> isInteractive ( ) ) { $ options = array ( ) ; $ option = $ this -> output -> getResponse ( 'What do you want to configure [name|email|etc...] ?' ) ; if ( is_string ( $ option ) && ! empty ( $ option ) ) { $ options [ $ option ] = $ this -> output -> getResponse ( "What do you want your {$option} to be?" ) ; } else if ( empty ( $ option ) ) { $ this -> output -> error ( "Please specify what option you want to set." ) ; } else { $ this -> output -> error ( "The {$option} option is not currently supported." ) ; } } else { $ this -> output = $ this -> output -> getHelpOutput ( ) ; $ this -> help ( ) ; $ this -> output -> render ( ) ; return ; } } if ( Config :: save ( $ options ) ) { $ this -> output -> addLine ( 'Saved new configuration!' , 'success' ) ; } else { $ this -> output -> error ( 'Failed to save configuration' ) ; } }
|
Sets a configuration option
|
46,509
|
protected function getConnectionData ( ) { return [ $ this -> associativeLocal => $ this -> model -> getPkValue ( ) , $ this -> shifter => strtolower ( $ this -> model -> getModelName ( ) ) ] ; }
|
Generates the connection data needed to create the associative entry
|
46,510
|
public function processed ( $ number = 1 ) { $ this -> set ( 'processed' , ( int ) $ this -> get ( 'processed' , 0 ) + $ number ) ; $ this -> save ( ) ; }
|
Add to the processed number on this run
|
46,511
|
public static function add ( $ query , $ time = 0 ) { list ( $ file , $ line ) = self :: parseBacktrace ( ) ; list ( $ type ) = explode ( ' ' , $ query , 2 ) ; self :: write ( "$file $line " . strtoupper ( $ type ) . " {$time} " . str_replace ( "\n" , ' ' , $ query ) ) ; }
|
Logs queries to hubzero sql log
|
46,512
|
public static function write ( $ statement ) { $ logger = new \ Hubzero \ Log \ Writer ( new \ Monolog \ Logger ( \ Config :: get ( 'application_env' ) ) , \ Event :: getRoot ( ) ) ; $ path = ( is_dir ( self :: HZPATH ) ) ? self :: HZPATH : \ Config :: get ( 'log_path' ) ; $ logger -> useFiles ( $ path . DS . self :: FILENAME , 'info' , "%datetime% %message%\n" , "Y-m-d\TH:i:s.uP" , 0640 ) ; $ logger -> info ( $ statement ) ; }
|
Writes the log statment out
|
46,513
|
public static function parseBacktrace ( ) { $ file = '-' ; $ line = 0 ; foreach ( self :: getBacktrace ( ) as $ item ) { if ( isset ( $ item [ 'class' ] ) && ( $ item [ 'class' ] == 'Hubzero\Database\Relational' || $ item [ 'class' ] == 'Hubzero\Database\Relationship\Relationship' || $ item [ 'class' ] == 'Hubzero\Database\Rows' ) ) { $ file = ( isset ( $ item [ 'file' ] ) ) ? str_replace ( PATH_CORE , '' , $ item [ 'file' ] ) : $ file ; $ line = ( isset ( $ item [ 'line' ] ) ) ? $ item [ 'line' ] : $ line ; } } return array ( $ file , $ line ) ; }
|
Parses the debug backtrace for the applicable file and line
|
46,514
|
public function render ( & $ xmlElement , $ value , $ control_name = 'params' ) { $ name = ( string ) $ xmlElement [ 'name' ] ; $ label = ( string ) $ xmlElement [ 'label' ] ; $ descr = ( string ) $ xmlElement [ 'description' ] ; $ label = $ label ? $ label : $ name ; $ result [ 0 ] = $ this -> fetchTooltip ( $ label , $ descr , $ xmlElement , $ control_name , $ name ) ; $ result [ 1 ] = $ this -> fetchElement ( $ name , $ value , $ xmlElement , $ control_name ) ; $ result [ 2 ] = $ descr ; $ result [ 3 ] = $ label ; $ result [ 4 ] = $ value ; $ result [ 5 ] = $ name ; return $ result ; }
|
Method to render an xml element
|
46,515
|
public function fetchTooltip ( $ label , $ description , & $ xmlElement , $ control_name = '' , $ name = '' ) { $ output = '<label id="' . $ control_name . $ name . '-lbl" for="' . $ control_name . $ name . '"' ; if ( $ description ) { $ output .= ' class="hasTip" title="' . \ App :: get ( 'language' ) -> txt ( $ label ) . '::' . \ App :: get ( 'language' ) -> txt ( $ description ) . '">' ; } else { $ output .= '>' ; } $ output .= \ App :: get ( 'language' ) -> txt ( $ label ) . '</label>' ; return $ output ; }
|
Method to get a tool tip from an XML element
|
46,516
|
public function construct ( ) { $ name = null ; if ( $ this -> arguments -> getOpt ( 'n' ) || $ this -> arguments -> getOpt ( 'name' ) || $ this -> arguments -> getOpt ( 4 ) ) { $ name = ( $ this -> arguments -> getOpt ( 4 ) ) ? $ this -> arguments -> getOpt ( 4 ) : $ name ; $ name = ( $ this -> arguments -> getOpt ( 'n' ) ) ? $ this -> arguments -> getOpt ( 'n' ) : $ name ; $ name = ( $ this -> arguments -> getOpt ( 'name' ) ) ? $ this -> arguments -> getOpt ( 'name' ) : $ name ; $ name = strtolower ( $ name ) ; } else { if ( $ this -> output -> isInteractive ( ) ) { $ name = $ this -> output -> getResponse ( 'What do you want the component name to be?' ) ; } else { $ this -> output -> error ( "Error: a component name should be provided." ) ; } } $ install_dir = PATH_CORE . DS . 'components' ; if ( $ this -> arguments -> getOpt ( 'install-dir' ) && strlen ( ( $ this -> arguments -> getOpt ( 'install-dir' ) ) ) > 0 ) { $ install_dir = PATH_CORE . DS . trim ( $ this -> arguments -> getOpt ( 'install-dir' ) , DS ) . DS . 'components' ; } if ( substr ( $ name , 0 , 4 ) == 'com_' ) { $ name = substr ( $ name , 4 ) ; } if ( is_dir ( $ install_dir . DS . 'com_' . $ name ) ) { $ this -> output -> error ( "Error: the component name provided ({$name}) seems to already exists." ) ; } $ this -> addTemplateFile ( "{$this->getType()}.tmpl" , $ install_dir . DS . 'com_' . $ name ) -> addReplacement ( 'component_name' , $ name ) -> addReplacement ( 'option' , 'com_' . $ name ) -> make ( ) ; }
|
Construct new component
|
46,517
|
public static function published ( $ value , $ i , $ prefix = '' , $ checkbox = 'cb' ) { return Builder \ Grid :: published ( $ value , $ i , $ prefix , $ checkbox ) ; }
|
Method to create a clickable icon to change the state of an item
|
46,518
|
protected function getValueActions ( $ value ) { $ actions = array ( ) ; foreach ( ( array ) $ value as $ name => $ rules ) { $ actions [ ] = $ name ; } return $ actions ; }
|
Method to get the list of permission action names from the form field value .
|
46,519
|
protected function getFieldActions ( $ element ) { $ actions = array ( ) ; $ section = $ element [ 'section' ] ? ( string ) $ element [ 'section' ] : '' ; $ component = $ element [ 'component' ] ? ( string ) $ element [ 'component' ] : '' ; $ component = $ component ? \ App :: get ( 'component' ) -> path ( $ component ) . '/config/access.xml' : '' ; $ section = $ section ? "/access/section[@name='" . $ section . "']/" : '' ; $ elActions = Access :: getActionsFromFile ( $ component , $ section ) ; if ( is_array ( $ elActions ) ) { foreach ( $ elActions as $ item ) { $ actions [ ] = $ item -> name ; } } foreach ( $ element -> children ( ) as $ el ) { if ( $ el -> getName ( ) == 'action' ) { $ actions [ ] = ( string ) $ el [ 'name' ] ; } } return $ actions ; }
|
Method to get the list of possible permission action names for the form field .
|
46,520
|
public function automaticPublishUp ( $ data ) { if ( ! isset ( $ data [ 'publish_up' ] ) ) { $ data [ 'publish_up' ] = null ; } $ publish_up = $ data [ 'publish_up' ] ; if ( ! $ publish_up || $ publish_up == '0000-00-00 00:00:00' ) { $ publish_up = ( $ data [ 'id' ] ? $ this -> created : Date :: of ( 'now' ) -> toSql ( ) ) ; } return $ publish_up ; }
|
Generates automatic owned by field value
|
46,521
|
public function started ( ) { if ( $ this -> isNew ( ) ) { return false ; } if ( $ this -> get ( 'publish_up' ) && $ this -> get ( 'publish_up' ) != '0000-00-00 00:00:00' && $ this -> get ( 'publish_up' ) > Date :: toSql ( ) ) { return false ; } return true ; }
|
Has the publish window started?
|
46,522
|
public function ended ( ) { if ( $ this -> isNew ( ) ) { return true ; } if ( $ this -> get ( 'publish_down' ) && $ this -> get ( 'publish_down' ) != '0000-00-00 00:00:00' && $ this -> get ( 'publish_down' ) <= Date :: toSql ( ) ) { return true ; } return false ; }
|
Has the publish window ended?
|
46,523
|
public function belongsToObject ( $ scope , $ scope_id ) { if ( $ this -> isNew ( ) ) { return true ; } if ( $ this -> get ( 'scope' ) == ( string ) $ scope && $ this -> get ( 'scope_id' ) == ( int ) $ scope_id ) { return true ; } return false ; }
|
Method to check if announcement belongs to entity
|
46,524
|
public function published ( $ as = '' ) { if ( ! $ this -> get ( 'publish_up' ) || $ this -> get ( 'publish_up' ) == '0000-00-00 00:00:00' ) { $ this -> set ( 'publish_up' , $ this -> get ( 'created' ) ) ; } $ as = strtolower ( $ as ) ; if ( $ as ) { if ( $ as == 'date' ) { return Date :: of ( $ this -> get ( 'publish_up' ) ) -> toLocal ( Lang :: txt ( 'DATE_FORMAT_HZ1' ) ) ; } if ( $ as == 'time' ) { return Date :: of ( $ this -> get ( 'publish_up' ) ) -> toLocal ( Lang :: txt ( 'TIME_FORMAT_HZ1' ) ) ; } return Date :: of ( $ this -> get ( 'publish_up' ) ) -> toLocal ( $ as ) ; } return $ this -> get ( 'publish_up' ) ; }
|
Return a formatted timestamp
|
46,525
|
public static function title ( $ title , $ icon = 'generic.png' ) { $ icons = explode ( ' ' , $ icon ) ; foreach ( $ icons as & $ icon ) { $ icon = 'icon-48-' . preg_replace ( '#\.[^.]*$#' , '' , $ icon ) ; } $ html = '<div class="pagetitle ' . htmlspecialchars ( implode ( ' ' , $ icons ) ) . '"><h2>' . $ title . '</h2></div>' ; $ app = static :: getApplication ( ) ; $ app -> set ( 'ComponentTitle' , $ html ) ; if ( $ app -> has ( 'document' ) ) { $ app -> get ( 'document' ) -> setTitle ( $ app -> get ( 'config' ) -> get ( 'sitename' ) . ' - ' . $ app -> get ( 'language' ) -> txt ( 'JADMINISTRATION' ) . ' - ' . $ title ) ; } }
|
Title cell . For the title and toolbar to be rendered correctly this title fucntion must be called before the starttable function and the toolbars icons this is due to the nature of how the css has been used to postion the title in respect to the toolbar .
|
46,526
|
public static function custom ( $ task = '' , $ icon = '' , $ iconOver = '' , $ alt = '' , $ listSelect = true ) { $ icon = preg_replace ( '#\.[^.]*$#' , '' , $ icon ) ; static :: getRoot ( ) -> appendButton ( 'Standard' , $ icon , $ alt , $ task , $ listSelect ) ; }
|
Writes a custom option and task button for the button bar .
|
46,527
|
public static function addNew ( $ task = 'add' , $ alt = 'JTOOLBAR_NEW' , $ check = false ) { static :: getRoot ( ) -> appendButton ( 'Standard' , 'new' , $ alt , $ task , $ check ) ; }
|
Writes the common new icon for the button bar .
|
46,528
|
public static function publish ( $ task = 'publish' , $ alt = 'JTOOLBAR_PUBLISH' , $ check = false ) { static :: getRoot ( ) -> appendButton ( 'Standard' , 'publish' , $ alt , $ task , $ check ) ; }
|
Writes a common publish button .
|
46,529
|
public static function unpublish ( $ task = 'unpublish' , $ alt = 'JTOOLBAR_UNPUBLISH' , $ check = false ) { static :: getRoot ( ) -> appendButton ( 'Standard' , 'unpublish' , $ alt , $ task , $ check ) ; }
|
Writes a common unpublish button .
|
46,530
|
public static function deleteList ( $ msg = '' , $ task = 'remove' , $ alt = 'JTOOLBAR_DELETE' ) { $ bar = static :: getRoot ( ) ; if ( $ msg ) { $ bar -> appendButton ( 'Confirm' , $ msg , 'delete' , $ alt , $ task , true ) ; } else { $ bar -> appendButton ( 'Standard' , 'delete' , $ alt , $ task , true ) ; } }
|
Writes a common delete button for a list of records .
|
46,531
|
public static function trash ( $ task = 'remove' , $ alt = 'JTOOLBAR_TRASH' , $ check = true ) { static :: getRoot ( ) -> appendButton ( 'Standard' , 'trash' , $ alt , $ task , $ check , false ) ; }
|
Write a trash button that will move items to Trash Manager .
|
46,532
|
public static function checkin ( $ task = 'checkin' , $ alt = 'JTOOLBAR_CHECKIN' , $ check = true ) { static :: getRoot ( ) -> appendButton ( 'Standard' , 'checkin' , $ alt , $ task , $ check ) ; }
|
Writes a checkin button for a given option .
|
46,533
|
public static function confirm ( $ msg = '' , $ name = 'delete' , $ task = 'remove' , $ alt = 'JTOOLBAR_DELETE' , $ list = true ) { static :: getRoot ( ) -> appendButton ( 'Confirm' , $ msg , $ name , $ alt , $ task , $ list ) ; }
|
Writes a button that prompts for confirmation before executing a task
|
46,534
|
public function getMessages ( $ uid = null , $ filters = array ( ) ) { $ uid = $ uid ? : $ this -> uid ; if ( ! $ uid ) { return array ( ) ; } $ r = $ this -> getTableName ( ) ; $ m = Message :: blank ( ) -> getTableName ( ) ; $ s = Seen :: blank ( ) -> getTableName ( ) ; $ entries = $ this -> buildQuery ( $ uid , $ filters ) ; return $ entries -> select ( $ m . '.*,' . $ r . '.expires,' . $ r . '.actionid,' . $ r . '.state,' . $ s . '.whenseen' ) -> order ( $ r . '.created' , 'desc' ) -> limit ( $ filters [ 'limit' ] ) -> start ( $ filters [ 'start' ] ) -> rows ( ) ; }
|
Get records for a user based on filters passed
|
46,535
|
public function getMessagesCount ( $ uid , $ filters = array ( ) ) { if ( ! $ uid ) { return 0 ; } $ entries = $ this -> buildQuery ( $ uid , $ filters ) ; return $ entries -> total ( ) ; }
|
Get a record count for a user based on filters passed
|
46,536
|
public function getUnreadMessages ( $ uid , $ limit = null ) { if ( ! $ uid ) { return array ( ) ; } $ r = $ this -> getTableName ( ) ; $ m = Message :: blank ( ) -> getTableName ( ) ; $ s = Seen :: blank ( ) -> getTableName ( ) ; $ entries = Message :: all ( ) -> select ( $ m . '.*,' . $ r . '.expires,' . $ r . '.actionid' ) -> join ( $ r , $ m . '.id' , $ r . '.mid' , 'inner' ) -> whereEquals ( $ r . '.uid' , $ uid ) -> where ( $ r . '.state' , '!=' , 2 ) -> whereRaw ( $ m . ".id NOT IN (SELECT s.mid FROM `" . $ s . "` AS s WHERE s.uid=" . $ uid . ")" ) -> order ( $ r . '.created' , 'desc' ) ; if ( $ limit ) { $ entries -> limit ( $ limit ) ; } return $ entries -> rows ( ) ; }
|
Get a list of unread messages for a user
|
46,537
|
public function getUnreadMessagesCount ( $ uid ) { if ( ! $ uid ) { return 0 ; } $ r = $ this -> getTableName ( ) ; $ m = Message :: blank ( ) -> getTableName ( ) ; $ s = Seen :: blank ( ) -> getTableName ( ) ; $ entries = Message :: blank ( ) -> join ( $ r , $ m . '.id' , $ r . '.mid' , 'inner' ) -> whereEquals ( $ r . '.uid' , $ uid ) -> where ( $ r . '.state' , '!=' , 2 ) -> whereRaw ( $ m . ".id NOT IN (SELECT s.mid FROM `" . $ s . "` AS s WHERE s.uid=" . $ uid . ")" ) ; return $ entries -> total ( ) ; }
|
Get a count of unread messages for a user
|
46,538
|
public function setState ( $ state = 0 , $ ids = array ( ) ) { if ( count ( $ ids ) <= 0 ) { return false ; } $ ids = array_map ( 'intval' , $ ids ) ; return $ this -> update ( ) -> set ( array ( 'state' => $ state ) ) -> whereIn ( 'id' , $ ids ) -> execute ( ) ; }
|
Set the state of multiple messages
|
46,539
|
public function markAsRead ( ) { if ( ! $ this -> get ( 'id' ) ) { $ this -> addError ( 'Recipient record not found' ) ; return false ; } $ xseen = Seen :: oneByMessageAndUser ( $ this -> get ( 'mid' ) , $ this -> get ( 'uid' ) ) ; if ( $ xseen -> get ( 'whenseen' ) == '' || $ xseen -> get ( 'whenseen' ) == '0000-00-00 00:00:00' || $ xseen -> get ( 'whenseen' ) == null ) { $ dt = new Date ( 'now' ) ; $ xseen -> set ( 'mid' , $ this -> get ( 'mid' ) ) ; $ xseen -> set ( 'uid' , $ this -> get ( 'uid' ) ) ; $ xseen -> set ( 'whenseen' , $ dt -> toSql ( ) ) ; if ( ! $ xseen -> save ( ) ) { $ this -> addError ( $ xseen -> getError ( ) ) ; return false ; } } return true ; }
|
Mark a message as being read by the recipient
|
46,540
|
public function markAsUnread ( ) { if ( ! $ this -> get ( 'id' ) ) { $ this -> addError ( 'Recipient record not found' ) ; return false ; } $ xseen = Seen :: oneByMessageAndUser ( $ this -> get ( 'mid' ) , $ this -> get ( 'uid' ) ) ; if ( $ xseen -> get ( 'id' ) ) { if ( ! $ xseen -> destroy ( ) ) { $ this -> addError ( $ xseen -> getError ( ) ) ; return false ; } } return true ; }
|
Mark a message as not being read by the recipient
|
46,541
|
public static function arrayUnique ( $ myArray ) { if ( ! is_array ( $ myArray ) ) { return $ myArray ; } foreach ( $ myArray as & $ myvalue ) { $ myvalue = serialize ( $ myvalue ) ; } $ myArray = array_unique ( $ myArray ) ; foreach ( $ myArray as & $ myvalue ) { $ myvalue = unserialize ( $ myvalue ) ; } return $ myArray ; }
|
Multidimensional array safe unique test
|
46,542
|
public static function filterKeys ( $ unfiltered , $ whitelist ) { $ filtered = array_filter ( $ unfiltered , function ( $ key ) use ( $ whitelist ) { return in_array ( $ key , $ whitelist ) ; } , ARRAY_FILTER_USE_KEY ) ; return $ filtered ; }
|
Filters keys from given array based on whitelist
|
46,543
|
public static function meMatey ( $ data ) { $ pirate = array ( 'Ahoy' , 'Arrr!' , 'Bilge Rat!' , 'Feed the fishes' , 'Davy Jones\' Locker' , 'Jolly Roger' , 'Scurvy dog!' , 'Shiver me timbers!' , 'Walk the plank' , 'X Marks the spot' , 'Yo-ho-ho' ) ; $ nqs = count ( $ pirate ) ; foreach ( $ data as $ key => $ val ) { if ( is_string ( $ val ) ) { $ use = rand ( 0 , $ nqs - 1 ) ; $ val .= ' ' . $ pirate [ $ use ] ; } $ data [ $ key ] = $ val ; } return $ data ; }
|
Function to randomly append pirate phrases to strings in an array .
|
46,544
|
public function fileSpacePath ( ) { $ uploadPath = PATH_APP . DS . 'site' . DS . 'import' . DS . 'hooks' . DS . $ this -> get ( 'id' ) ; return $ uploadPath ; }
|
Return imports filespace path
|
46,545
|
public static function getInstance ( $ options = [ ] ) { $ options [ 'driver' ] = ( isset ( $ options [ 'driver' ] ) ) ? preg_replace ( '/[^A-Z0-9_\.-]/i' , '' , $ options [ 'driver' ] ) : 'mysql' ; $ options [ 'database' ] = ( isset ( $ options [ 'database' ] ) ) ? $ options [ 'database' ] : null ; $ options [ 'select' ] = ( isset ( $ options [ 'select' ] ) ) ? $ options [ 'select' ] : true ; if ( $ options [ 'driver' ] == 'pdo' ) { $ options [ 'driver' ] = 'mysql' ; } $ signature = md5 ( serialize ( $ options ) ) ; if ( ! isset ( self :: $ instances [ $ signature ] ) ) { $ class = __NAMESPACE__ . '\Driver\\' . ucfirst ( strtolower ( $ options [ 'driver' ] ) ) ; if ( ! class_exists ( $ class ) ) { throw new RuntimeException ( 'Database driver not available.' , 500 ) ; } self :: $ instances [ $ signature ] = new $ class ( $ options ) ; } return self :: $ instances [ $ signature ] ; }
|
Returns a driver instance based on the given options
|
46,546
|
public function setConnection ( $ connection ) { $ this -> connection = $ connection ; $ this -> setSyntax ( $ this -> detectSyntax ( ) ) ; return $ this ; }
|
Sets the connection
|
46,547
|
public function quoteName ( $ name , $ as = null ) { $ parts = ( strpos ( $ name , '.' ) !== false ) ? explode ( '.' , $ name ) : ( array ) $ name ; $ bits = array ( ) ; foreach ( $ parts as $ part ) { $ bits [ ] = sprintf ( $ this -> wrapper , $ part ) ; } $ string = implode ( '.' , $ bits ) ; $ string .= ( isset ( $ as ) ) ? ' AS ' . sprintf ( $ this -> wrapper , $ as ) : '' ; return $ string ; }
|
Wraps an SQL statement identifier name such as column table or database names in quotes to prevent injection risks and reserved word conflicts
|
46,548
|
public function wrap ( $ value ) { if ( strpos ( strtolower ( $ value ) , ' as ' ) !== false ) { $ parts = explode ( ' ' , $ value ) ; return $ this -> wrap ( $ parts [ 0 ] ) . ' AS ' . $ this -> wrap ( $ parts [ 2 ] ) ; } $ quoted = [ ] ; $ parts = explode ( '.' , $ value ) ; foreach ( $ parts as $ part ) { $ quoted [ ] = $ part !== '*' ? sprintf ( $ this -> wrapper , $ part ) : $ part ; } return implode ( '.' , $ quoted ) ; }
|
Quotes table names and columns in the appropriate characters
|
46,549
|
public function insertObject ( $ table , & $ object , $ key = null ) { $ fields = [ ] ; $ values = [ ] ; $ binds = [ ] ; $ statement = 'INSERT INTO ' . $ this -> quoteName ( $ table ) . ' (%s) VALUES (%s)' ; foreach ( get_object_vars ( $ object ) as $ k => $ v ) { if ( is_array ( $ v ) or is_object ( $ v ) or $ v === null ) { continue ; } if ( $ k [ 0 ] == '_' ) { continue ; } $ fields [ ] = $ this -> quoteName ( $ k ) ; $ values [ ] = '?' ; $ binds [ ] = $ v ; } $ this -> prepare ( sprintf ( $ statement , implode ( ',' , $ fields ) , implode ( ',' , $ values ) ) ) -> bind ( $ binds ) ; if ( ! $ this -> execute ( ) ) { return false ; } $ id = $ this -> insertid ( ) ; if ( $ key && $ id ) { $ object -> $ key = $ id ; } return true ; }
|
Inserts a row into a table based on an object s properties
|
46,550
|
public function loadColumn ( $ offset = 0 ) { $ column = [ ] ; if ( ! $ this -> execute ( ) ) { return null ; } while ( $ row = $ this -> fetchArray ( ) ) { $ column [ ] = $ row [ $ offset ] ; } $ this -> freeResult ( ) ; return $ column ; }
|
Gets an array of values from the offset field in each row of the result set from the database query
|
46,551
|
public function loadObject ( $ class = 'stdClass' ) { $ return = null ; if ( ! $ this -> execute ( ) ) { return null ; } if ( $ row = $ this -> fetchObject ( $ class ) ) { $ return = $ row ; } $ this -> freeResult ( ) ; return $ return ; }
|
Gets the first row of the result set from the database query as an object
|
46,552
|
public function loadResult ( ) { $ return = null ; if ( ! $ this -> execute ( ) ) { return null ; } if ( $ row = $ this -> fetchArray ( ) ) { $ return = $ row [ 0 ] ; } $ this -> freeResult ( ) ; return $ return ; }
|
Gets the first field of the first row of the result set from the database query
|
46,553
|
public function loadRow ( ) { $ return = null ; if ( ! $ this -> execute ( ) ) { return null ; } if ( $ row = $ this -> fetchArray ( ) ) { $ return = $ row ; } $ this -> freeResult ( ) ; return $ return ; }
|
Gets the first row of the result set from the database query as an array
|
46,554
|
public function loadRowList ( $ key = null ) { $ rows = [ ] ; if ( ! $ this -> execute ( ) ) { return null ; } while ( $ row = $ this -> fetchArray ( ) ) { if ( $ key !== null ) { $ rows [ $ row [ $ key ] ] = $ row ; } else { $ rows [ ] = $ row ; } } $ this -> freeResult ( ) ; return $ rows ; }
|
Gets an array of the result set rows from the database query where each row is an array . The array of objects can optionally be keyed by a field offset but defaults to a sequential numeric array .
|
46,555
|
public function loadObjectList ( $ key = '' , $ class = 'stdClass' ) { $ rows = [ ] ; if ( ! $ this -> execute ( ) ) { return null ; } while ( $ row = $ this -> fetchObject ( $ class ) ) { if ( $ key ) { $ rows [ $ row -> $ key ] = $ row ; } else { $ rows [ ] = $ row ; } } $ this -> freeResult ( ) ; return $ rows ; }
|
Gets an array of the result set rows from the database query where each row is an object . The array of objects can optionally be keyed by a field name but defaults to a sequential numeric array .
|
46,556
|
public function replacePrefix ( $ sql , $ prefix = '#__' ) { $ differential = strlen ( $ this -> tablePrefix ) - strlen ( $ prefix ) ; $ count = 0 ; foreach ( Str :: findLiteral ( $ prefix , $ sql ) as $ prefixPosition ) { $ sql = substr_replace ( $ sql , $ this -> tablePrefix , $ prefixPosition + ( $ differential * $ count ) , strlen ( $ prefix ) ) ; $ count ++ ; } return $ sql ; }
|
Replaces a string placeholder with the string held in the class variable
|
46,557
|
public static function splitSql ( $ sql ) { $ start = 0 ; $ length = strlen ( $ sql ) ; $ queries = [ ] ; foreach ( Str :: findLiteral ( ';' , $ sql ) as $ queryEndPosition ) { $ queries [ ] = trim ( substr ( $ sql , $ start , $ queryEndPosition - $ start + 1 ) ) ; $ start = $ queryEndPosition + 1 ; } if ( $ end = trim ( substr ( $ sql , $ start ) ) ) { $ queries [ ] = $ end ; } return $ queries ; }
|
Splits a string of multiple queries into an array of individual queries
|
46,558
|
protected function log ( $ time ) { $ query = $ this -> toString ( ) ; Event :: trigger ( 'database_query' , [ 'query' => $ query , 'time' => $ time ] ) ; $ this -> log [ ] = $ query ; $ this -> count ++ ; $ this -> timer += $ time ; }
|
Logs the current sql statement
|
46,559
|
public function toString ( ) { if ( is_object ( $ this -> statement ) ) { $ query = $ this -> interpolate ( $ this -> statement -> queryString , $ this -> bindings ) ; } else { $ query = $ this -> statement ; } return $ query ; }
|
Gets the string version of the query
|
46,560
|
private function interpolate ( $ query , $ bindings ) { $ offset = 0 ; $ index = 0 ; foreach ( Str :: findLiteral ( '?' , $ query ) as $ placeholder ) { $ sub = ( is_null ( $ bindings [ $ index ] ) ) ? 'NULL' : $ this -> quote ( $ bindings [ $ index ] ) ; $ query = substr_replace ( $ query , $ sub , $ placeholder + $ offset , 1 ) ; $ offset += ( strlen ( $ sub ) - 1 ) ; $ index ++ ; } return $ query ; }
|
Builds a string version of the prepared statement
|
46,561
|
public function getStatement ( ) { return ( is_object ( $ this -> statement ) ) ? $ this -> interpolate ( $ this -> statement -> queryString , $ this -> bindings ) : $ this -> statement ; }
|
Gets the current sql statement
|
46,562
|
public function render ( $ position , $ params = array ( ) , $ content = null ) { $ renderer = $ this -> doc -> loadRenderer ( 'module' ) ; $ buffer = '' ; foreach ( \ App :: get ( 'module' ) -> byPosition ( $ position ) as $ mod ) { $ buffer .= $ renderer -> render ( $ mod , $ params , $ content ) ; } return $ buffer ; }
|
Renders multiple modules script and returns the results as a string
|
46,563
|
public static function icon ( $ symbol , $ ariahidden = true ) { $ paths = array ( ) ; if ( App :: has ( 'template' ) ) { $ paths [ ] = App :: get ( 'template' ) -> path . '/html/icons/' . $ symbol . '.svg' ; } $ paths [ ] = PATH_CORE . '/assets/icons/' . $ symbol . '.svg' ; $ content = '' ; foreach ( $ paths as $ path ) { if ( file_exists ( $ path ) ) { $ atts = array ( 'class="icn icn-' . $ symbol . '"' ) ; if ( $ ariahidden ) { $ atts [ ] = 'aria-hidden="true" focusable="false"' ; } $ content = '<span ' . implode ( ' ' , $ atts ) . '>' . file_get_contents ( $ path ) . '</span>' ; break ; } } return $ content ; }
|
Load an icon s SVG representation
|
46,564
|
public function add ( ) { $ trigger = $ this -> arguments -> getOpt ( 3 ) ; $ hook = $ this -> arguments -> getOpt ( 4 ) ; $ this -> arguments -> deleteOpt ( 3 ) ; $ this -> arguments -> deleteOpt ( 4 ) ; $ this -> arguments -> setOpt ( 'hooks' , array ( $ trigger => array ( $ hook ) ) ) ; App :: get ( 'client' ) -> call ( 'configuration' , 'set' , $ this -> arguments , $ this -> output ) ; }
|
Adds a new console hook
|
46,565
|
public static function start ( $ group = 'sliders' , $ params = array ( ) ) { self :: behavior ( $ group , $ params ) ; self :: $ open = false ; return '<div id="' . $ group . '" class="pane-sliders">' ; }
|
Creates a panes and loads the javascript behavior for it .
|
46,566
|
public static function end ( ) { $ content = '' ; if ( self :: $ open ) { $ content .= '</div></div>' ; } self :: $ open = false ; $ content .= '</div>' ; return $ content ; }
|
Close the current pane .
|
46,567
|
public static function panel ( $ text , $ id ) { $ content = '' ; if ( self :: $ open ) { $ content .= '</div></div>' ; } else { self :: $ open = true ; } $ content .= '<h3 class="pane-toggler title" id="' . $ id . '"><a href="#' . $ id . '"><span>' . $ text . '</span></a></h3><div class="panel"><div class="pane-slider content">' ; return $ content ; }
|
Begins the display of a new panel .
|
46,568
|
public function automaticParentId ( $ data ) { if ( ! isset ( $ data [ 'parent_id' ] ) ) { $ data [ 'parent_id' ] = 0 ; } if ( ( ! isset ( $ data [ 'id' ] ) || ! $ data [ 'id' ] ) && ( $ data [ 'parent_id' ] == 0 ) ) { $ data [ 'parent_id' ] = self :: getRootId ( ) ; } return $ data [ 'parent_id' ] ; }
|
Generates automatic parent_id field value
|
46,569
|
public function automaticRules ( $ data ) { if ( ! isset ( $ data [ 'rules' ] ) ) { $ data [ 'rules' ] = '{}' ; } if ( ! is_string ( $ data [ 'rules' ] ) ) { $ data [ 'rules' ] = ( string ) $ data [ 'rules' ] ; } return $ data [ 'rules' ] ; }
|
Generates automatic rules field value
|
46,570
|
public static function oneByName ( $ name ) { $ model = self :: all ( ) -> whereEquals ( 'name' , $ name ) -> row ( ) ; if ( ! $ model ) { $ model = self :: blank ( ) ; } return $ model ; }
|
Method to load an asset by it s name .
|
46,571
|
public static function getRootId ( ) { $ result = self :: all ( ) -> whereEquals ( 'parent_id' , 0 ) -> row ( ) ; if ( ! $ result -> get ( 'id' ) ) { $ result = self :: all ( ) -> whereEquals ( 'lft' , 0 ) -> row ( ) ; if ( ! $ result -> get ( 'id' ) ) { $ result = self :: all ( ) -> whereEquals ( 'alias' , 'root.1' ) -> row ( ) ; } } return $ result -> get ( 'id' ) ; }
|
Method to load root node ID
|
46,572
|
public function reset ( ) { $ this -> started = $ this -> now ( ) ; $ this -> prefix = '' ; $ this -> marks = array ( ) ; $ this -> memory = memory_get_usage ( true ) ; }
|
Reset the profiler
|
46,573
|
public function mark ( $ label ) { $ this -> marks [ ] = new Mark ( $ label , $ this -> ended ( ) , $ this -> now ( ) , memory_get_usage ( true ) ) ; return $ this ; }
|
Output a time mark
|
46,574
|
public function summary ( ) { $ summary = array ( 'start' => $ this -> started ( ) , 'end' => $ this -> ended ( ) , 'total' => $ this -> duration ( ) , 'memory' => $ this -> memory ( ) ) ; return $ summary ; }
|
Returns a summary of all timer activity so far
|
46,575
|
public function render ( $ head , $ params = array ( ) , $ content = null ) { ob_start ( ) ; echo $ this -> fetchHead ( $ this -> doc ) ; $ buffer = ob_get_contents ( ) ; ob_end_clean ( ) ; return $ buffer ; }
|
Renders the document head and returns the results as a string
|
46,576
|
public function view ( $ layout , $ name = null ) { if ( $ layout instanceof AbstractView ) { return $ layout ; } $ view = new self ( array ( 'base_path' => $ this -> _basePath , 'name' => ( $ name ? $ name : $ this -> _name ) , 'layout' => $ layout ) ) ; $ view -> set ( 'option' , $ this -> option ) -> set ( 'controller' , $ this -> controller ) -> set ( 'task' , $ this -> task ) ; return $ view ; }
|
Create a component view and return it
|
46,577
|
public function check ( $ data ) { $ failure = 0 ; $ messages = array ( ) ; if ( is_string ( $ data ) ) { $ data = array ( 'text' => $ data ) ; } $ data = $ this -> prepareData ( $ data ) ; foreach ( $ this -> detectors as $ id => $ detector ) { $ spam = false ; $ msg = null ; try { if ( $ detector -> detect ( $ data ) ) { $ spam = true ; if ( $ detector -> message ( ) ) { $ messages [ ] = $ detector -> message ( ) ; } $ failure ++ ; } $ msg = $ detector -> message ( ) ; } catch ( Exception $ e ) { $ this -> setError ( $ e -> getMessage ( ) ) ; } $ this -> mark ( $ id , $ spam , $ msg ) ; } $ result = new Result ( $ failure > 0 , $ messages ) ; return $ result ; }
|
Checks if a string is spam or not
|
46,578
|
public function registerDetector ( DetectorInterface $ spamDetector ) { $ detectorId = $ this -> classSimpleName ( $ spamDetector ) ; if ( isset ( $ this -> detectors [ $ detectorId ] ) ) { throw new RuntimeException ( sprintf ( 'Spam Detector [%s] already registered' , $ detectorId ) ) ; } $ this -> detectors [ $ detectorId ] = $ spamDetector ; return $ this ; }
|
Registers a Spam Detector
|
46,579
|
protected function mark ( $ name , $ value , $ message = null ) { $ this -> report [ ] = array ( 'service' => $ name , 'is_spam' => $ value , 'message' => $ message ) ; }
|
Report the results of a spam detector
|
46,580
|
public function storage ( $ name = null ) { $ name = $ name ? : $ this -> getDefaultDriver ( ) ; return $ this -> stores [ $ name ] = ( isset ( $ this -> stores [ $ name ] ) ? $ this -> stores [ $ name ] : $ this -> resolve ( $ name ) ) ; }
|
Get a cache store instance by name .
|
46,581
|
protected function resolve ( $ name ) { $ config = $ this -> getConfig ( $ name ) ; if ( is_null ( $ config ) ) { throw new InvalidArgumentException ( 'Cache config is not defined.' ) ; } if ( ! isset ( $ config [ 'hash' ] ) ) { $ config [ 'hash' ] = $ this -> app -> hash ( '' ) ; } if ( ! isset ( $ config [ 'cachebase' ] ) ) { $ config [ 'cachebase' ] = PATH_APP . DS . 'cache' . DS . ( isset ( $ this -> app [ 'client' ] -> alias ) ? $ this -> app [ 'client' ] -> alias : $ this -> app [ 'client' ] -> name ) ; } if ( isset ( $ this -> customCreators [ $ name ] ) ) { $ config [ 'cache_handler' ] = $ name ; return $ this -> callCustomCreator ( $ config ) ; } else { $ class = __NAMESPACE__ . '\\Storage\\' . ucfirst ( $ name ) ; if ( ! class_exists ( $ class ) ) { throw new InvalidArgumentException ( "Cache store [{$name}] is not defined." ) ; } return new $ class ( ( array ) $ config ) ; } }
|
Resolve the given storage handler .
|
46,582
|
public static function getStores ( ) { $ stores = [ ] ; $ types = glob ( __DIR__ . DIRECTORY_SEPARATOR . 'Storage' . DIRECTORY_SEPARATOR . '*.php' ) ; foreach ( $ types as $ type ) { $ type = basename ( $ type ) ; $ class = __NAMESPACE__ . '\\Storage\\' . str_ireplace ( '.php' , '' , ucfirst ( trim ( $ type ) ) ) ; if ( ! class_exists ( $ class ) ) { continue ; } if ( call_user_func_array ( array ( $ class , 'isAvailable' ) , array ( ) ) ) { $ stores [ ] = str_ireplace ( '.php' , '' , $ type ) ; } } $ stores = array_map ( 'strtolower' , $ stores ) ; return $ stores ; }
|
Get a list of available cache stores .
|
46,583
|
public function createBadge ( $ data ) { if ( ! $ this -> credentialsSet ( ) ) { throw new Exception ( 'You need to set the credentials first.' ) ; } $ data [ 'IssuerId' ] = $ this -> credentials -> issuerId ; $ data = json_encode ( $ data ) ; $ accessToken = $ this -> credentials -> access_token ; $ userAgent = $ _SERVER [ 'HTTP_USER_AGENT' ] ; $ headers = [ 'Cache-Control: no-cache' , 'Content-Type: application/json' , "Authorization: Bearer $accessToken" , "user-agent: $userAgent" ] ; $ request = curl_init ( ) ; curl_setopt ( $ request , CURLOPT_HTTPHEADER , $ headers ) ; curl_setopt ( $ request , CURLOPT_URL , 'https://www.openpassport.org/1.0.0/badges' ) ; curl_setopt ( $ request , CURLOPT_POSTFIELDS , $ data ) ; curl_setopt ( $ request , CURLOPT_POST , 1 ) ; curl_setopt ( $ request , CURLOPT_RETURNTRANSFER , true ) ; curl_setopt ( $ request , CURLOPT_VERBOSE , true ) ; $ response = curl_exec ( $ request ) ; $ badge = json_decode ( $ response ) ; if ( empty ( $ badge -> Id ) || ! $ badge -> Id ) { throw new Exception ( $ badge -> message ) ; } return $ badge -> Id ; }
|
Create a new badge
|
46,584
|
public function grantBadge ( $ badge , $ users ) { if ( ! $ this -> credentialsSet ( ) ) { throw new Exception ( 'You need to set the credentials first.' ) ; } if ( ! is_array ( $ users ) ) { $ users = array ( $ users ) ; } $ assertions = array ( ) ; foreach ( $ users as $ user ) { $ data = array ( ) ; $ data [ 'BadgeId' ] = $ badge -> id ; $ data [ 'EvidenceUrl' ] = $ badge -> evidenceUrl ; $ data [ 'EmailAddress' ] = $ user ; $ data [ 'ClientId' ] = $ this -> credentials -> clientId ; $ assertions [ ] = $ data ; unset ( $ data ) ; } $ assertionsData = json_encode ( $ assertions ) ; if ( $ this -> request_type == 'oauth' && is_a ( $ this -> request , 'oauth' ) ) { $ this -> request -> setAuthType ( OAUTH_AUTH_TYPE_AUTHORIZATION ) ; try { $ this -> request -> fetch ( self :: PASSPORT_API_ENDPOINT . "assertions/" , $ assertionsData , OAUTH_HTTP_METHOD_POST , array ( 'Content-Type' => 'application/json' ) ) ; } catch ( Exception $ e ) { throw new Exception ( 'Badge grant request failed.' ) ; } $ assertion = json_decode ( $ this -> request -> getLastResponse ( ) ) ; } else if ( $ this -> request_type == 'curl' && get_resource_type ( $ this -> request ) == 'curl' ) { curl_setopt ( $ this -> request , CURLOPT_URL , self :: PASSPORT_API_ENDPOINT . "assertions/" ) ; curl_setopt ( $ this -> request , CURLOPT_POSTFIELDS , $ assertionsData ) ; curl_setopt ( $ this -> request , CURLOPT_RETURNTRANSFER , true ) ; $ response = curl_exec ( $ this -> request ) ; $ assertion = json_decode ( $ response ) ; } else { throw new Exception ( 'Unsupported request type' ) ; } foreach ( $ assertion as $ ass ) { if ( empty ( $ ass -> Id ) || ! $ ass -> Id ) { throw new Exception ( $ ass -> message ) ; } } }
|
Grant badges to users
|
46,585
|
public function getAssertionsByEmailAddress ( $ emailAddresses ) { if ( ! $ this -> credentialsSet ( ) ) { throw new Exception ( 'You need to set the credentials first.' ) ; } if ( ! is_array ( $ emailAddresses ) ) { $ emailAddresses = array ( $ emailAddresses ) ; } $ query_params = implode ( '%20' , $ emailAddresses ) ; $ url = self :: PASSPORT_API_ENDPOINT . "assertions?emailAddresses=" . $ query_params ; if ( $ this -> request_type == 'oauth' && is_a ( $ this -> request , 'oauth' ) ) { $ this -> request -> setAuthType ( OAUTH_AUTH_TYPE_URI ) ; try { $ this -> request -> fetch ( $ url , null , OAUTH_HTTP_METHOD_GET , array ( 'Content-Type' => 'application/json' ) ) ; } catch ( Exception $ e ) { throw new Exception ( 'Assertations by email request failed.' ) ; } $ response = json_decode ( $ this -> request -> getLastResponse ( ) ) ; } else if ( $ this -> request_type == 'curl' && get_resource_type ( $ this -> request ) == 'curl' ) { curl_setopt ( $ this -> request , CURLOPT_POST , false ) ; curl_setopt ( $ this -> request , CURLOPT_URL , $ url ) ; curl_setopt ( $ this -> request , CURLOPT_RETURNTRANSFER , true ) ; $ response = curl_exec ( $ this -> request ) ; $ response = json_decode ( $ response ) ; } else { throw new Exception ( 'Unsupported request type' ) ; } return $ response ; }
|
Get assertions by email address
|
46,586
|
public function buildEmailToken ( $ version , $ action , $ userid , $ id ) { $ rv = '' ; $ binaryString = pack ( "NNN" , $ userid , $ id , intval ( time ( ) ) ) ; $ hash = sha1 ( bin2hex ( pack ( "C" , $ version ) ) . bin2hex ( pack ( "C" , $ action ) ) . bin2hex ( $ binaryString ) ) ; $ hashsub = substr ( $ hash , 0 , 4 ) ; $ binaryString .= pack ( "n" , hexdec ( $ hashsub ) ) ; $ pad = $ this -> _blocksize - ( strlen ( $ binaryString ) % $ this -> _blocksize ) ; $ binaryString .= str_repeat ( chr ( $ pad ) , $ pad ) ; $ cipher = mcrypt_module_open ( MCRYPT_RIJNDAEL_128 , '' , 'cbc' , '' ) ; mcrypt_generic_init ( $ cipher , $ this -> _key , $ this -> _iv ) ; $ encrypted = mcrypt_generic ( $ cipher , $ binaryString ) ; mcrypt_generic_deinit ( $ cipher ) ; $ rv = bin2hex ( pack ( "C" , $ version ) ) . bin2hex ( pack ( "C" , $ action ) ) . bin2hex ( $ encrypted ) ; return $ rv ; }
|
Build a unique email token
|
46,587
|
public function decryptEmailToken ( $ t ) { $ rawtoken = substr ( $ t , 4 ) ; $ encrypted = hex2bin ( $ rawtoken ) ; $ cipher = mcrypt_module_open ( MCRYPT_RIJNDAEL_128 , '' , 'cbc' , '' ) ; mcrypt_generic_init ( $ cipher , $ this -> _key , $ this -> _iv ) ; $ decrypted = mdecrypt_generic ( $ cipher , $ encrypted ) ; $ arr = unpack ( "N3" , $ decrypted ) ; return array ( $ arr [ 1 ] , $ arr [ 2 ] , $ arr [ 3 ] ) ; }
|
Function to decrypt email token
|
46,588
|
public function help ( ) { if ( $ this -> type ) { $ class = __NAMESPACE__ . '\\Scaffolding\\' . ucfirst ( $ this -> type ) ; $ obj = new $ class ( $ this -> output , $ this -> arguments ) ; $ obj -> help ( ) ; } else { $ this -> output = $ this -> output -> getHelpOutput ( ) ; $ this -> output -> addOverview ( 'Create a new item scaffold. There are currently no arguments available. Type "muse scaffolding help [scaffolding type]" for more details.' ) ; $ this -> output -> render ( ) ; } }
|
Help doc for scaffolding command
|
46,589
|
public function create ( ) { $ class = __NAMESPACE__ . '\\Scaffolding\\' . ucfirst ( $ this -> type ) ; if ( class_exists ( $ class ) ) { $ obj = new $ class ( $ this -> output , $ this -> arguments ) ; } else { if ( empty ( $ this -> type ) ) { $ this -> output -> error ( 'Error: Sorry, scaffolding can\'t create nothing/everything. Try telling it what you want to create.' ) ; } else { $ this -> output -> error ( 'Error: Sorry, scaffolding doesn\'t know how to create a ' . $ this -> type ) ; } } $ user_name = Config :: get ( 'user_name' ) ; $ user_email = Config :: get ( 'user_email' ) ; if ( ! $ user_name || ! $ user_email ) { $ this -> output -> addSpacer ( ) -> addLine ( 'You can specify your name and email via:' ) -> addLine ( 'muse configuration set --user_name="John Doe"' , array ( 'indentation' => '2' , 'color' => 'blue' ) ) -> addLine ( 'muse configuration set --user_email=john.doe@gmail.com' , array ( 'indentation' => '2' , 'color' => 'blue' ) ) -> addSpacer ( ) -> error ( "Error: failed to retrieve author name and/or email." ) ; } $ obj -> addReplacement ( 'author_name' , $ user_name ) -> addReplacement ( 'author_email' , $ user_email ) ; $ obj -> construct ( ) ; }
|
Create a new item from scaffolding templates
|
46,590
|
public function copy ( ) { $ class = __NAMESPACE__ . '\\Scaffolding\\' . ucfirst ( $ this -> type ) ; if ( class_exists ( $ class ) ) { $ obj = new $ class ( $ this -> output , $ this -> arguments ) ; } else { if ( empty ( $ this -> type ) ) { $ this -> output -> error ( 'Error: Sorry, scaffolding can\'t copy nothing. Try telling it what you want to copy.' ) ; } else { $ this -> output -> error ( 'Error: Sorry, scaffolding doesn\'t know how to copy a ' . $ this -> type ) ; } } if ( ! method_exists ( $ obj , 'doCopy' ) ) { $ this -> output -> error ( 'Error: scaffolding doesn\'t know how to copy a ' . $ this -> type ) ; } $ obj -> doCopy ( ) ; }
|
Copy item and attempt to rename appropriatly
|
46,591
|
protected function addTemplateFile ( $ filename , $ destination , $ fullPath = false ) { $ this -> templateFiles [ ] = array ( 'path' => ( ( ! $ fullPath ) ? __DIR__ . DS . 'Scaffolding' . DS . 'Templates' . DS . $ filename : $ filename ) , 'destination' => $ destination ) ; return $ this ; }
|
Add a new template file
|
46,592
|
private function doReplacements ( $ contents ) { if ( isset ( $ this -> replacements ) && count ( $ this -> replacements ) > 0 ) { foreach ( $ this -> replacements as $ k => $ v ) { if ( is_array ( $ v ) ) { foreach ( $ v as $ replacement ) { foreach ( $ replacement as $ key => $ value ) { $ contents = preg_replace ( "/%={$key}=%/" , $ value , $ contents , 1 ) ; } } } else { if ( preg_match_all ( "/%={$k}\+([[:alpha:]]+)=%/" , $ contents , $ matches ) && isset ( $ matches [ 1 ] ) ) { unset ( $ matches [ 0 ] ) ; foreach ( $ matches [ 1 ] as $ match ) { switch ( $ match ) { case 'uc' : $ value = strtoupper ( $ v ) ; break ; case 'ucf' : $ value = ucfirst ( $ v ) ; break ; case 'ucfp' : $ value = ucfirst ( Inflector :: pluralize ( $ v ) ) ; break ; case 'p' : $ value = Inflector :: pluralize ( $ v ) ; break ; } $ contents = str_replace ( "%={$k}+{$match}=%" , $ value , $ contents ) ; } } $ contents = str_replace ( "%={$k}=%" , $ v , $ contents ) ; if ( $ this -> doBlindReplacements ) { $ contents = str_replace ( $ k , $ v , $ contents ) ; } } } } preg_match_all ( '/\$\^[[:alpha:]\.]*\^\$/' , $ contents , $ matches , PREG_SET_ORDER ) ; if ( isset ( $ matches ) && count ( $ matches ) > 0 ) { foreach ( $ matches as $ match ) { foreach ( $ match as $ key ) { $ keyReal = preg_replace ( '/\$\^([[:alpha:]\.]*)\^\$/' , '$1' , $ key ) ; $ subPath = __DIR__ . DS . 'Scaffolding' . DS . 'Templates' . DS . $ this -> getType ( ) . '.' . $ keyReal . '.tmpl' ; if ( ! is_file ( $ subPath ) ) { continue ; } $ subTmpl = file_get_contents ( $ subPath ) ; if ( isset ( $ this -> replacements [ $ keyReal ] ) && is_array ( $ this -> replacements [ $ keyReal ] ) ) { $ count = count ( $ this -> replacements [ $ keyReal ] ) ; $ repeat = str_repeat ( $ key , $ count ) ; $ contents = str_replace ( $ key , $ repeat , $ contents ) ; } $ contents = str_replace ( $ key , $ subTmpl , $ contents ) ; $ contents = $ this -> doReplacements ( $ contents ) ; } } } return $ contents ; }
|
Make replacements in a given content string
|
46,593
|
private function scanFolder ( $ path ) { $ files = array_diff ( scandir ( $ path ) , array ( '.' , '..' , '.DS_Store' ) ) ; if ( $ files && count ( $ files ) > 0 ) { foreach ( $ files as $ file ) { if ( is_file ( $ path . DS . $ file ) ) { $ contents = file_get_contents ( $ path . DS . $ file ) ; $ contents = $ this -> doReplacements ( $ contents ) ; $ this -> putContents ( $ path . DS . $ file , $ contents ) ; } else { if ( preg_match ( "/%=([[:alpha:]_]*)(\+[[:alpha:]]+)?=%/" , $ path . DS . $ file , $ matches ) && isset ( $ this -> replacements [ $ matches [ 1 ] ] ) ) { $ newfile = str_replace ( $ matches [ 0 ] , $ this -> replacements [ $ matches [ 1 ] ] , $ file ) ; if ( isset ( $ matches [ 2 ] ) ) { $ modifier = substr ( $ matches [ 2 ] , 1 ) ; switch ( $ modifier ) { case 'uc' : $ value = strtoupper ( $ v ) ; break ; case 'ucf' : $ newfile = ucfirst ( $ newfile ) ; break ; case 'ucfp' : $ newfile = ucfirst ( Inflector :: pluralize ( $ newfile ) ) ; break ; case 'p' : $ newfile = Inflector :: pluralize ( $ newfile ) ; break ; } } rename ( $ path . DS . $ file , $ path . DS . $ newfile ) ; $ file = $ newfile ; } $ this -> scanFolder ( $ path . DS . $ file ) ; } } } }
|
Scan template folder for files to iterate through
|
46,594
|
public function transformDetails ( ) { if ( ! isset ( $ this -> entryDetails ) ) { $ this -> entryDetails = new Registry ( $ this -> get ( 'details' ) ) ; } return $ this -> entryDetails ; }
|
Transform details into object
|
46,595
|
public function broadcast ( $ recipients = array ( ) ) { $ subscriptions = Subscription :: all ( ) -> whereEquals ( 'scope' , $ this -> get ( 'scope' ) ) -> whereEquals ( 'scope_id' , $ this -> get ( 'scope_id' ) ) -> rows ( ) ; foreach ( $ subscriptions as $ subscription ) { $ recipients [ ] = array ( 'scope' => 'user' , 'scope_id' => $ subscription -> get ( 'user_id' ) ) ; } $ sent = array ( ) ; foreach ( $ recipients as $ receiver ) { if ( ! is_array ( $ receiver ) ) { $ receiver = array ( 'scope' => 'user' , 'scope_id' => $ receiver ) ; } if ( ! isset ( $ receiver [ 'scope' ] ) || ! isset ( $ receiver [ 'scope_id' ] ) ) { $ receiver = array_values ( $ receiver ) ; $ receiver [ 'scope' ] = $ receiver [ 0 ] ; $ receiver [ 'scope_id' ] = $ receiver [ 1 ] ; } $ key = $ receiver [ 'scope' ] . '.' . $ receiver [ 'scope_id' ] ; if ( in_array ( $ key , $ sent ) ) { continue ; } $ recipient = Recipient :: blank ( ) -> set ( [ 'scope' => $ receiver [ 'scope' ] , 'scope_id' => $ receiver [ 'scope_id' ] , 'log_id' => $ this -> get ( 'id' ) , 'state' => Recipient :: STATE_PUBLISHED ] ) ; if ( ! $ recipient -> save ( ) ) { return false ; } $ sent [ ] = $ key ; } return true ; }
|
Send an activity to recipients
|
46,596
|
public static function log ( $ data = array ( ) , $ recipients = array ( ) ) { if ( is_object ( $ data ) ) { $ data = ( array ) $ data ; } if ( is_string ( $ data ) ) { $ data = array ( 'description' => $ data ) ; $ data [ 'action' ] = 'create' ; if ( substr ( strtolower ( $ data [ 'description' ] ) , 0 , 6 ) == 'update' ) { $ data [ 'action' ] = 'update' ; } if ( substr ( strtolower ( $ data [ 'description' ] ) , 0 , 6 ) == 'delete' ) { $ data [ 'action' ] = 'delete' ; } } try { $ activity = self :: blank ( ) -> set ( $ data ) ; if ( ! $ activity -> save ( ) ) { return false ; } if ( ! $ activity -> broadcast ( $ recipients ) ) { return false ; } } catch ( Exception $ e ) { return false ; } return true ; }
|
Create an activity log entry and broadcast it .
|
46,597
|
public static function allForRecipient ( $ scope , $ scope_id = 0 ) { if ( ! is_array ( $ scope ) ) { $ scope = array ( $ scope ) ; } $ logs = self :: all ( ) ; $ r = Recipient :: blank ( ) -> getTableName ( ) ; $ l = $ logs -> getTableName ( ) ; $ logs -> select ( $ l . '.*' ) -> join ( $ r , $ l . '.id' , $ r . '.log_id' ) -> whereIn ( $ r . '.scope' , $ scope ) -> whereEquals ( $ r . '.scope_id' , $ scope_id ) ; return $ logs ; }
|
Get all logs for a recipient
|
46,598
|
private function generateImage ( $ string , $ size , $ color ) { $ this -> setString ( $ string ) ; $ this -> setSize ( $ size ) ; $ image = imagecreatetruecolor ( $ this -> pixelRatio * 5 , $ this -> pixelRatio * 5 ) ; $ background = imagecolorallocate ( $ image , 0 , 0 , 0 ) ; imagecolortransparent ( $ image , $ background ) ; if ( null !== $ color ) { $ this -> setColor ( $ color ) ; } $ color = imagecolorallocate ( $ image , $ this -> color [ 0 ] , $ this -> color [ 1 ] , $ this -> color [ 2 ] ) ; foreach ( $ this -> arrayOfSquare as $ lineKey => $ lineValue ) { foreach ( $ lineValue as $ colKey => $ colValue ) { if ( true === $ colValue ) { imagefilledrectangle ( $ image , $ colKey * $ this -> pixelRatio , $ lineKey * $ this -> pixelRatio , ( $ colKey + 1 ) * $ this -> pixelRatio , ( $ lineKey + 1 ) * $ this -> pixelRatio , $ color ) ; } } } imagepng ( $ image ) ; }
|
Generate the Identicon image
|
46,599
|
public static function get ( $ key , $ default = false ) { $ instance = self :: getInstance ( ) ; return ( isset ( $ instance -> config [ $ key ] ) ) ? $ instance -> config [ $ key ] : $ default ; }
|
Gets the specified config var
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.