idx
int64
0
60.3k
question
stringlengths
64
4.24k
target
stringlengths
5
618
8,200
private function handleFilters ( ExportInterface $ export , QueryBuilder $ qb , $ data , array $ centers ) { $ filters = $ this -> retrieveUsedFilters ( $ data ) ; foreach ( $ filters as $ alias => $ filter ) { if ( $ this -> isGrantedForElement ( $ filter , $ export , $ centers ) === false ) { throw new UnauthorizedHttpException ( "You are not authorized to " . "use the filter " . $ filter -> getTitle ( ) ) ; } $ formData = $ data [ $ alias ] ; $ this -> logger -> debug ( 'alter query by filter ' . $ alias , array ( 'class' => self :: class , 'function' => __FUNCTION__ ) ) ; $ filter -> alterQuery ( $ qb , $ formData [ 'form' ] ) ; } }
alter the query with selected filters .
8,201
private function handleAggregators ( ExportInterface $ export , QueryBuilder $ qb , $ data , array $ center ) { $ aggregators = $ this -> retrieveUsedAggregators ( $ data ) ; foreach ( $ aggregators as $ alias => $ aggregator ) { $ formData = $ data [ $ alias ] ; $ aggregator -> alterQuery ( $ qb , $ formData [ 'form' ] ) ; } }
Alter the query with selected aggregators
8,202
public static function side ( $ items , $ htmlOptions = array ( ) ) { ArrayHelper :: addValue ( 'class' , Enum :: NAV_SIDE , $ htmlOptions ) ; ob_start ( ) ; echo \ CHtml :: openTag ( 'ul' , $ htmlOptions ) ; foreach ( $ items as $ item ) { if ( is_string ( $ item ) ) echo \ CHtml :: tag ( 'li' , array ( 'class' => Enum :: NAV_DIVIDER ) ) ; else { $ itemOptions = ArrayHelper :: getValue ( $ item , 'itemOptions' , array ( ) ) ; $ linkOptions = ArrayHelper :: getValue ( $ item , 'linkOptions' , array ( ) ) ; $ label = ArrayHelper :: getValue ( $ item , 'label' , 'Item' ) ; $ url = ArrayHelper :: getValue ( $ item , 'url' , '#' ) ; echo \ CHtml :: openTag ( 'li' , $ itemOptions ) ; echo \ CHtml :: link ( $ label , $ url , $ linkOptions ) ; echo \ CHtml :: closeTag ( 'li' ) ; } } echo \ CHtml :: closeTag ( 'ul' ) ; return ob_get_clean ( ) ; }
Generates a side nav
8,203
public static function sub ( $ items , $ htmlOptions = array ( ) ) { ArrayHelper :: addValue ( 'class' , Enum :: NAV_SUB , $ htmlOptions ) ; ob_start ( ) ; echo \ CHtml :: openTag ( 'dl' , $ htmlOptions ) ; foreach ( $ items as $ item ) { $ itemOptions = ArrayHelper :: getValue ( $ item , 'itemOptions' , array ( ) ) ; $ linkOptions = ArrayHelper :: getValue ( $ item , 'linkOptions' , array ( ) ) ; $ label = ArrayHelper :: getValue ( $ item , 'label' , 'Item' ) ; $ url = ArrayHelper :: getValue ( $ item , 'url' , '#' ) ; echo \ CHtml :: openTag ( 'dt' , $ itemOptions ) ; echo \ CHtml :: link ( $ label , $ url , $ linkOptions ) ; echo \ CHtml :: closeTag ( 'dt' ) ; } echo \ CHtml :: closeTag ( 'dl' ) ; return ob_get_clean ( ) ; }
Generates a foundation sub nav
8,204
public function boot ( ) { if ( ! $ this -> booted ) { foreach ( $ this -> container -> getProviders ( ) as $ provider ) { $ provider -> boot ( $ this ) ; } $ this -> booted = true ; } }
Boots of the all providers of the application
8,205
public function getAppDir ( ) { if ( null === $ this -> container -> getAppDir ( ) ) { $ r = new \ ReflectionObject ( $ this ) ; $ this -> container -> setAppDir ( str_replace ( '\\' , '/' , dirname ( $ r -> getFileName ( ) ) ) ) ; } return $ this -> container -> getAppDir ( ) ; }
Get Application Dir
8,206
public static function getInstance ( array $ userSettings = array ( ) ) { if ( ! self :: $ instance ) { self :: $ instance = new self ( $ userSettings ) ; } return self :: $ instance ; }
Get instance of MVC
8,207
public function group ( ) { $ args = func_get_args ( ) ; $ route = array_shift ( $ args ) ; $ callable = array_pop ( $ args ) ; if ( is_string ( $ route ) && is_callable ( $ callable ) ) { call_user_func ( $ callable , $ route ) ; } }
Add Group routes
8,208
public function ajax ( $ patternUri , $ action , $ name ) { $ route = new Route ( "ajax" , $ patternUri , $ action , $ name ) ; $ this -> container -> addRoute ( $ route ) ; return $ route ; }
Add AJAX route
8,209
public function registerProvider ( Provider $ provider ) { $ provider -> register ( $ this ) ; $ this -> container -> addProvider ( $ provider ) ; return $ this ; }
Register the providers
8,210
public function setRoutes ( ) { $ routesJsonFile = $ this -> getAppDir ( ) . '/config/routes.json' ; $ routesPhpFile = $ this -> getAppDir ( ) . '/config/routes.php' ; $ routes = array ( ) ; if ( file_exists ( $ routesJsonFile ) ) { $ routes [ ] = json_decode ( file_get_contents ( $ routesJsonFile ) , true ) ; } elseif ( file_exists ( $ routesPhpFile ) ) { $ routes [ ] = require_once $ routesPhpFile ; } foreach ( $ this -> container -> getModules ( ) as $ module ) { $ extension = $ module -> getModuleExtension ( ) ; if ( is_object ( $ extension ) && $ extension instanceof Injection \ Extension ) { $ routes [ ] = $ extension -> loadRoutes ( ) ; } } return $ routes ; }
Set Routes from JSON|PHP File
8,211
public static function share ( $ callable ) { if ( ! is_object ( $ callable ) || ! method_exists ( $ callable , '__invoke' ) ) { throw new InvalidArgumentException ( 'Callable is not a Closure or invokable object.' ) ; } return function ( $ c ) use ( $ callable ) { static $ object ; if ( null === $ object ) { $ object = $ callable ( $ c ) ; } return $ object ; } ; }
Share a clousure object or callback object
8,212
public function urlFor ( $ path , $ type_name = 'asset' , array $ params = array ( ) ) { switch ( $ type_name ) { case 'asset' : return $ this -> container -> getRequest ( ) -> getRootUri ( ) . $ path ; break ; case 'route' : $ routeUrl = $ this -> container -> getRequest ( ) -> getRootUri ( $ this -> getSetting ( 'debug' ) ) . $ this -> container -> getRoute ( $ path ) -> getPatternUri ( ) ; return ( ! empty ( $ params ) ) ? $ routeUrl . '?' . http_build_query ( $ params ) : $ routeUrl ; break ; } }
Return the url for the path given
8,213
public function data ( $ json = false ) { return ( $ json ) ? $ this -> container -> getRequest ( ) -> data -> JSON : $ this -> container -> getRequest ( ) -> data ; }
Get the data of request
8,214
function addAttachment ( $ data , $ filename = '' , $ contenttype = 'application/octet-stream' , $ cid = FALSE ) { if ( ! $ cid ) { $ cid = md5 ( uniqid ( time ( ) ) ) ; } $ info [ 'data' ] = $ data ; $ info [ 'filename' ] = $ filename ; $ info [ 'contenttype' ] = $ contenttype ; $ info [ 'cid' ] = $ cid ; $ this -> requestAttachments [ ] = $ info ; return $ cid ; }
adds a MIME attachment to the current request .
8,215
public function execute ( $ type ) { switch ( strtolower ( $ type ) ) { case 'markup' : $ curlOptArray = $ this -> getMarkupOpts ( ) ; break ; case 'file' : $ curlOptArray = $ this -> getFileOpts ( ) ; break ; case 'url' : $ curlOptArray = $ this -> getUrlOpts ( ) ; break ; default : throw new \ PHPUnit_Framework_Exception ( 'Invalid type: ' . $ type ) ; break ; } $ curlOptArray = $ curlOptArray + array ( CURLOPT_RETURNTRANSFER => true , CURLOPT_TIMEOUT => 10 , ) ; Throttle :: delay ( get_class ( $ this ) ) ; $ curl = curl_init ( ) ; curl_setopt_array ( $ curl , $ curlOptArray ) ; if ( ! $ response = curl_exec ( $ curl ) ) { throw new \ PHPUnit_Framework_Exception ( 'Unable to validate. Error: ' . curl_error ( $ curl ) ) ; } curl_close ( $ curl ) ; return $ response ; }
Will execute a cURL request .
8,216
protected function bindInstallCommand ( ) { $ this -> app [ 'package.install' ] = $ this -> app -> share ( function ( $ app ) { return $ app -> make ( 'Terion\PackageInstaller\PackageInstallCommand' ) ; } ) ; $ this -> app [ 'package.process' ] = $ this -> app -> share ( function ( $ app ) { return $ app -> make ( 'Terion\PackageInstaller\PackageProcessCommand' ) ; } ) ; }
Bind command to IoC
8,217
public function declareField ( string $ field , string $ type , string $ source , string $ origin = null ) { $ schema = $ this -> constant ( 'SCHEMA' ) -> getValue ( ) ; $ setters = $ this -> constant ( 'SETTERS' ) -> getValue ( ) ; $ validates = $ this -> constant ( 'VALIDATES' ) -> getValue ( ) ; if ( ! isset ( $ this -> mapping [ $ type ] ) ) { $ schema [ $ field ] = $ source . ':' . ( $ origin ? $ origin : $ field ) ; $ this -> constant ( 'SCHEMA' ) -> setValue ( $ schema ) ; return ; } $ definition = $ this -> mapping [ $ type ] ; $ source = $ definition [ 'source' ] ; $ schema [ $ field ] = $ source . ':' . ( $ origin ? $ origin : $ field ) ; if ( ! empty ( $ definition [ 'setter' ] ) ) { $ setters [ $ field ] = $ definition [ 'setter' ] ; } if ( ! empty ( $ definition [ 'validates' ] ) ) { $ validates [ $ field ] = $ definition [ 'validates' ] ; } $ this -> constant ( 'SCHEMA' ) -> setValue ( $ schema ) ; $ this -> constant ( 'SETTERS' ) -> setValue ( $ setters ) ; $ this -> constant ( 'VALIDATES' ) -> setValue ( $ validates ) ; }
Add new field to request and generate default filters and validations if type presented in mapping .
8,218
public function route ( ) { $ uri = clone JUri :: getInstance ( ) ; $ router = $ this -> getRouter ( ) ; $ result = $ router -> parse ( $ uri ) ; foreach ( $ result as $ key => $ value ) { $ this -> input -> def ( $ key , $ value ) ; } JPluginHelper :: importPlugin ( 'system' ) ; $ this -> triggerEvent ( 'onAfterRoute' ) ; }
Route the application .
8,219
public function dispatch ( $ component = null ) { $ document = JFactory :: getDocument ( ) ; $ contents = JComponentHelper :: renderComponent ( $ component ) ; $ document -> setBuffer ( $ contents , 'component' ) ; JPluginHelper :: importPlugin ( 'system' ) ; $ this -> triggerEvent ( 'onAfterDispatch' ) ; }
Dispatch the application .
8,220
public function render ( ) { $ template = $ this -> getTemplate ( true ) ; $ params = array ( 'template' => $ template -> template , 'file' => 'index.php' , 'directory' => JPATH_THEMES , 'params' => $ template -> params ) ; $ document = JFactory :: getDocument ( ) ; $ document -> parse ( $ params ) ; JPluginHelper :: importPlugin ( 'system' ) ; $ this -> triggerEvent ( 'onBeforeRender' ) ; $ caching = ( $ this -> getCfg ( 'caching' ) >= 2 ) ? true : false ; JResponse :: setBody ( $ document -> render ( $ caching , $ params ) ) ; $ this -> triggerEvent ( 'onAfterRender' ) ; }
Render the application .
8,221
public function getName ( ) { $ name = $ this -> _name ; if ( empty ( $ name ) ) { $ r = null ; if ( ! preg_match ( '/J(.*)/i' , get_class ( $ this ) , $ r ) ) { JLog :: add ( JText :: _ ( 'JLIB_APPLICATION_ERROR_APPLICATION_GET_NAME' ) , JLog :: WARNING , 'jerror' ) ; } $ name = strtolower ( $ r [ 1 ] ) ; } return $ name ; }
Method to get the application name .
8,222
public function getTemplate ( $ params = false ) { $ template = new stdClass ; $ template -> template = 'system' ; $ template -> params = new Registry ; if ( $ params ) { return $ template ; } return $ template -> template ; }
Gets the name of the current template .
8,223
protected function _createConfiguration ( $ file ) { JLoader :: register ( 'JConfig' , $ file ) ; $ config = new JConfig ; $ registry = JFactory :: getConfig ( ) ; $ registry -> loadObject ( $ config ) ; return $ config ; }
Create the configuration registry .
8,224
public function checkSession ( ) { $ db = JFactory :: getDbo ( ) ; $ session = JFactory :: getSession ( ) ; $ user = JFactory :: getUser ( ) ; $ query = $ db -> getQuery ( true ) -> select ( $ db -> quoteName ( 'session_id' ) ) -> from ( $ db -> quoteName ( '#__users_sessions' ) ) -> where ( $ db -> quoteName ( 'session_id' ) . ' = ' . $ db -> quote ( $ session -> getId ( ) ) ) ; $ db -> setQuery ( $ query , 0 , 1 ) ; $ exists = $ db -> loadResult ( ) ; if ( ! $ exists ) { $ query -> clear ( ) ; if ( $ session -> isNew ( ) ) { $ query -> insert ( $ db -> quoteName ( '#__users_sessions' ) ) -> columns ( $ db -> quoteName ( 'session_id' ) . ', ' . $ db -> quoteName ( 'client_id' ) . ', ' . $ db -> quoteName ( 'time' ) ) -> values ( $ db -> quote ( $ session -> getId ( ) ) . ', ' . ( int ) $ this -> getClientId ( ) . ', ' . $ db -> quote ( ( int ) time ( ) ) ) ; $ db -> setQuery ( $ query ) ; } else { $ query -> insert ( $ db -> quoteName ( '#__users_sessions' ) ) -> columns ( $ db -> quoteName ( 'session_id' ) . ', ' . $ db -> quoteName ( 'client_id' ) . ', ' . $ db -> quoteName ( 'guest' ) . ', ' . $ db -> quoteName ( 'time' ) . ', ' . $ db -> quoteName ( 'userid' ) . ', ' . $ db -> quoteName ( 'username' ) ) -> values ( $ db -> quote ( $ session -> getId ( ) ) . ', ' . ( int ) $ this -> getClientId ( ) . ', ' . ( int ) $ user -> get ( 'guest' ) . ', ' . $ db -> quote ( ( int ) $ session -> get ( 'session.timer.start' ) ) . ', ' . ( int ) $ user -> get ( 'id' ) . ', ' . $ db -> quote ( $ user -> get ( 'username' ) ) ) ; $ db -> setQuery ( $ query ) ; } try { $ db -> execute ( ) ; } catch ( RuntimeException $ e ) { jexit ( $ e -> getMessage ( ) ) ; } } }
Checks the user session .
8,225
public function afterSessionStart ( ) { $ session = JFactory :: getSession ( ) ; if ( $ session -> isNew ( ) ) { $ session -> set ( 'registry' , new Registry ( 'session' ) ) ; $ session -> set ( 'user' , new JUser ) ; } }
After the session has been started we need to populate it with some default values .
8,226
public function getColumnByName ( $ strColumnName ) { if ( $ this -> objColumnArray ) { foreach ( $ this -> objColumnArray as $ objColumn ) { if ( $ objColumn -> Name == $ strColumnName ) return $ objColumn ; } } return null ; }
return the SqlColumn object related to that column name
8,227
public function toArray ( ) { $ data = array ( 'added' => $ this -> getAdded ( true ) , 'api' => $ this -> getApi ( ) , 'cwd' => $ this -> getCwd ( true ) , 'debug' => $ this -> getDebug ( ) , 'files' => $ this -> getFiles ( true ) , 'list' => $ this -> getList ( ) , 'netDrivers' => $ this -> getNetDrivers ( ) , 'options' => $ this -> getOptions ( ) , 'removed' => $ this -> getRemoved ( true ) , 'tree' => $ this -> getTree ( true ) , 'uplMaxSize' => $ this -> getUplMaxSize ( ) , 'content' => $ this -> getContent ( ) , 'size' => $ this -> getSize ( ) , 'error' => $ this -> getError ( ) , 'dim' => $ this -> getDim ( ) , ) ; return array_filter ( $ data , function ( $ var ) { return ! is_null ( $ var ) ; } ) ; }
get response as array .
8,228
public function getAdded ( $ asArray = true ) { $ return = array ( ) ; if ( $ asArray && $ this -> added ) { foreach ( $ this -> added as $ file ) { $ return [ ] = $ file -> toArray ( ) ; } } return $ asArray ? $ return : $ this -> added ; }
get Added .
8,229
public function getCwd ( $ asArray = false ) { return $ this -> cwd && $ asArray ? $ this -> cwd -> toArray ( ) : $ this -> cwd ; }
get Current Working Directory .
8,230
public function getFiles ( $ asArray = false ) { $ return = array ( ) ; if ( $ asArray && $ this -> files ) { foreach ( $ this -> files as $ file ) { $ return [ ] = $ file -> toArray ( ) ; } } return $ asArray ? $ return : $ this -> files ; }
get Files .
8,231
public function getTree ( $ asArray = false ) { $ return = array ( ) ; if ( $ asArray && $ this -> tree ) { foreach ( $ this -> tree as $ file ) { $ return [ ] = $ file -> toArray ( ) ; } } return $ asArray ? $ return : $ this -> tree ; }
get Tree .
8,232
public static function register ( $ jsFile , $ alias = NULL , Array $ dependencies = array ( ) ) { return self :: getManager ( ) -> register ( $ jsFile , $ alias , $ dependencies ) ; }
Macht dem Standard JS Manager eine JS Datei bekannt
8,233
function getPlayer ( ) { $ player = self :: $ persistance -> getVariable ( 'player' ) ; if ( ! $ player ) { if ( $ this -> getAccessToken ( ) ) { $ player = $ this -> executeOAuth2 ( 'GET' , '/player/' ) ; self :: $ persistance -> setVariable ( 'player' , $ player ) ; } } return $ player ; }
This is the first method to call when you have an authorization code . It will retrieve an access token if possible and then call the service to retrieve a basic object about the authentified player .
8,234
public function renderAlert ( ) { $ user = \ Yii :: app ( ) -> user ; if ( count ( $ user -> getFlashes ( false ) ) == 0 ) { return ; } $ alerts = array ( ) ; foreach ( $ this -> config as $ style => $ config ) { if ( $ user -> hasFlash ( $ style ) ) { $ options = ArrayHelper :: getValue ( $ config , 'htmlOptions' , array ( ) ) ; Html :: addCssClass ( $ options , $ style ) ; $ close = ArrayHelper :: getValue ( $ config , 'close' , '×' ) ; $ alerts [ ] = \ foundation \ helpers \ Alert :: alert ( $ user -> getFlash ( $ style ) , $ options , $ close ) ; } } $ this -> registerEvents ( "#{$this->htmlOptions['id']} > .alert-box" , $ this -> events ) ; return \ CHtml :: tag ( 'div' , $ this -> htmlOptions , implode ( "\n" , $ alerts ) ) ; }
Renders the alert
8,235
public static function recursiveMkdir ( string $ dir , int $ loops = 0 ) { if ( $ loops > 20 ) throw new UtilException ( 'No more than 20 directories in a row' ) ; if ( ! file_exists ( $ newdir = dirname ( $ dir ) ) ) self :: recursiveMkdir ( $ newdir ) ; @ mkdir ( $ dir ) ; @ chmod ( $ dir , 0777 ) ; }
Warning! Ignoring warnings
8,236
public function locate ( $ entity , Request $ request , $ template = null ) { if ( ! $ template ) { $ template = 'TenelevenGeolocatorBundle::results.html.twig' ; } $ provider = $ this -> getLocationProvider ( $ entity ) ; $ form = $ this -> get ( 'form.factory' ) -> createNamed ( '' , $ provider -> getFilterFormType ( ) , null , array ( 'method' => 'GET' , 'csrf_protection' => false , 'allow_extra_fields' => true , ) ) ; foreach ( $ request -> query -> all ( ) as $ key => $ value ) { if ( $ form -> has ( $ key ) ) { continue ; } $ form -> add ( $ key , HiddenType :: class , [ 'data' => $ value , ] ) ; } try { $ form -> handleRequest ( $ request ) ; } catch ( QuotaExceeded $ e ) { $ this -> get ( 'logger' ) -> error ( $ e -> getMessage ( ) ) ; $ this -> get ( 'session' ) -> getFlashBag ( ) -> add ( 'error' , 'Sorry, this locator has exceeded the quota for location look-ups. Please try again at a later time.' ) ; } if ( ! $ form -> isValid ( ) ) { return $ this -> render ( $ template , array ( 'map' => $ map = $ this -> getMap ( ) , 'form' => $ form -> createView ( ) ) ) ; } $ result = $ provider -> findLocations ( $ form ) ; $ map = $ this -> buildMap ( $ template , $ result ) ; return $ this -> render ( $ template , array ( 'form' => $ form -> createView ( ) , 'result' => $ result , 'map' => $ map ) ) ; }
Displays a geo - locator screen with map form and locations
8,237
protected function buildMap ( $ template , Search $ result ) { $ map = $ this -> getMap ( ) ; if ( ! $ result -> hasResults ( ) ) { $ map -> setCenter ( new Coordinate ( $ result -> getCenter ( ) -> getLatitude ( ) , $ result -> getCenter ( ) -> getLongitude ( ) ) ) ; return $ map ; } $ twigTemplate = $ this -> get ( 'twig' ) -> loadTemplate ( $ template ) ; $ map -> setAutoZoom ( true ) ; foreach ( $ result -> getResults ( ) as $ result ) { $ location = $ result -> location ; if ( ! $ location instanceof GeolocatableInterface ) { continue ; } $ marker = new Marker ( new Coordinate ( $ location -> getLatitude ( ) , $ location -> getLongitude ( ) ) ) ; if ( $ twigTemplate -> hasBlock ( 'teneleven_geolocator_item_window' , [ ] ) ) { $ infoWindow = new InfoWindow ( $ twigTemplate -> renderBlock ( 'teneleven_geolocator_item_window' , array ( 'result' => $ result ) ) ) ; $ marker -> setInfoWindow ( $ infoWindow ) ; $ result -> mapWindowId = $ infoWindow -> getVariable ( ) ; } $ result -> mapMarkerId = $ marker -> getVariable ( ) ; $ map -> getOverlayManager ( ) -> addMarker ( $ marker ) ; } return $ map ; }
Builds a map of locations
8,238
public function validate ( $ value ) : void { switch ( $ this -> sqlType ) { case 'ENUM' : case 'SET' : break ; default : $ common = self :: TYPES [ $ this -> sqlType ] ; if ( ! $ this -> size ) $ this -> size = $ common ; else $ this -> size = min ( $ this -> size , $ common ) ; $ this -> getValidator ( ) :: apply ( 'strlen' , $ value , $ this -> size ) ; } }
Checks if the type is correspondent
8,239
protected function renderNavigation ( ) { $ nav = array ( ) ; if ( ! empty ( $ this -> wrapperOptions ) ) { $ nav [ ] = \ CHtml :: openTag ( 'div' , $ this -> wrapperOptions ) ; } $ nav [ ] = \ CHtml :: openTag ( 'nav' , $ this -> htmlOptions ) ; $ nav [ ] = $ this -> renderTitle ( ) ; $ nav [ ] = $ this -> renderItems ( ) ; $ nav [ ] = \ CHtml :: closeTag ( 'nav' ) ; if ( ! empty ( $ this -> wrapperOptions ) ) { $ nav [ ] = \ CHtml :: closeTag ( 'div' ) ; } return implode ( "\n" , $ nav ) ; }
Renders the navigation
8,240
protected function renderTitle ( ) { $ items = array ( ) ; $ title = \ CHtml :: tag ( 'h1' , array ( ) , \ CHtml :: link ( $ this -> title , $ this -> titleUrl , $ this -> titleOptions ) ) ; $ items [ ] = \ CHtml :: tag ( 'li' , array ( 'class' => 'name' ) , $ title ) ; $ items [ ] = \ CHtml :: tag ( 'li' , array ( 'class' => 'toggle-topbar menu-icon' ) , \ CHtml :: link ( '<span>Menu</span>' , '#' ) ) ; return \ CHtml :: tag ( 'ul' , array ( 'class' => 'title-area' ) , implode ( "\n" , $ items ) ) ; }
Renders the title of navigation
8,241
protected function renderItems ( ) { $ items = array ( ) ; if ( ! empty ( $ this -> leftItems ) ) { $ tItems = array ( ) ; foreach ( $ this -> leftItems as $ item ) { $ tItems [ ] = $ this -> renderItem ( $ item ) ; } $ items [ ] = \ CHtml :: openTag ( 'ul' , array ( 'class' => Enum :: POS_LEFT ) ) . implode ( "\n" , $ tItems ) . \ CHtml :: closeTag ( 'ul' ) ; } if ( ! empty ( $ this -> rightItems ) ) { $ tItems = array ( ) ; foreach ( $ this -> rightItems as $ item ) { $ tItems [ ] = $ this -> renderItem ( $ item ) ; } $ items [ ] = \ CHtml :: openTag ( 'ul' , array ( 'class' => Enum :: POS_RIGHT ) ) . implode ( "\n" , $ tItems ) . \ CHtml :: closeTag ( 'ul' ) ; } return \ CHtml :: tag ( 'section' , array ( 'class' => 'top-bar-section' ) , implode ( "\n" , $ items ) , true ) ; }
Renders widget s items .
8,242
protected function renderItem ( $ item ) { if ( is_string ( $ item ) ) { return $ item ; } if ( ! isset ( $ item [ 'label' ] ) ) { throw new InvalidConfigException ( "The 'label' option is required." ) ; } $ label = $ this -> encodeLabels ? \ CHtml :: encode ( $ item [ 'label' ] ) : $ item [ 'label' ] ; $ options = ArrayHelper :: getValue ( $ item , 'options' , array ( ) ) ; $ items = ArrayHelper :: getValue ( $ item , 'items' ) ; $ url = \ CHtml :: normalizeUrl ( ArrayHelper :: getValue ( $ item , 'url' , '#' ) ) ; $ linkOptions = ArrayHelper :: getValue ( $ item , 'linkOptions' , array ( ) ) ; if ( ArrayHelper :: getValue ( $ item , Enum :: STATE_ACTIVE ) ) { ArrayHelper :: addValue ( 'class' , Enum :: STATE_ACTIVE , $ options ) ; } if ( $ items !== null ) { Html :: addCssClass ( $ options , Enum :: DROPDOWN_HAS ) ; if ( is_array ( $ items ) ) { $ items = Nav :: dropdown ( $ items , $ this -> encodeLabels ) ; } } return \ CHtml :: tag ( 'li' , $ options , \ CHtml :: link ( $ label , $ url , $ linkOptions ) . $ items ) ; }
Renders a widget s item
8,243
function menu ( $ menus ) { $ user = Auth :: user ( ) ; $ templates = [ "menu" => ' <ul class="sidebar-menu" data-widget="tree"> %s </ul> ' , "menu_row" => ' <li class="%s"> %s </li> ' , "menu_caret" => ' <span class="pull-right-container"> <i class="fa fa-angle-left pull-right"></i> </span>' , "menu_subrow" => ' <ul class="treeview-menu"> %s </ul> ' , "menu_link" => ' <a href="%s"><i class="%s text-red"></i><span>%s</span>%s</a> ' ] ; $ traverse = function ( $ rows ) use ( & $ traverse , $ templates , $ user ) { $ menuString = "" ; $ hasActive = false ; foreach ( $ rows as $ menu ) { if ( ! empty ( $ menu -> permission ) and ! $ user -> hasPermission ( $ menu -> permission ) ) { continue ; } $ hasActive = false ; $ submenu = "" ; $ authorized = true ; if ( $ menu -> children -> count ( ) > 0 ) { list ( $ submenuString , $ hasActive ) = $ traverse ( $ menu -> children ) ; $ submenu = "" ; if ( ! empty ( $ submenuString ) ) { $ submenu = sprintf ( $ templates [ 'menu_subrow' ] , $ submenuString ) ; } else { $ authorized = false ; } } $ menu_caret = ( ! empty ( $ submenu ) ? $ templates [ 'menu_caret' ] : '' ) ; $ link = sprintf ( $ templates [ 'menu_link' ] , ( ! empty ( $ menu -> route ) ? url ( $ menu -> route ) : '#' ) , ( ! empty ( $ menu -> icon ) ? $ menu -> icon : 'fa fa-circle-o' ) , \ Lang :: has ( 'back-project::menu.' . $ menu -> title ) ? __ ( 'back-project::menu.' . $ menu -> title ) : $ menu -> title , $ menu_caret ) ; $ class = ( ! empty ( $ submenu ) ? 'treeview' : '' ) ; $ current_url = \ Route :: current ( ) -> uri ( ) ; if ( $ authorized ) { $ menuString .= sprintf ( $ templates [ 'menu_row' ] , $ class , $ link . $ submenu ) ; } } return [ $ menuString , $ hasActive ] ; } ; list ( $ menu , $ hasActive ) = $ traverse ( $ menus ) ; return sprintf ( $ templates [ 'menu' ] , $ menu ) ; }
Format an AdminLTE Menu
8,244
public function prepareCriteria ( $ criteria ) { if ( is_null ( $ criteria ) ) { $ criteria = array ( ) ; } if ( array_key_exists ( '$id' , $ criteria ) ) { $ criteria [ 'id' ] = $ criteria [ '$id' ] ; unset ( $ criteria [ '$id' ] ) ; } return $ criteria ? : array ( ) ; }
comment for other criteria
8,245
public function getQueryReference ( $ key = '' , $ foreign = '' , $ foreignLabel = '' , $ foreignKey = '' , & $ i ) { $ model = Norm :: factory ( $ foreign ) ; $ refSchemes = $ model -> schema ( ) ; $ foreignKey = $ foreignKey ? : 'id' ; if ( $ foreignKey == '$id' ) { $ foreignKey = 'id' ; } $ query = $ key . ' IN (SELECT ' . $ foreignKey . ' FROM ' . strtolower ( $ foreign ) . ' WHERE ' . $ foreignLabel . ' LIKE :f' . $ i . ') ' ; $ i ++ ; return $ query ; }
Find reference of a foreign key .
8,246
public function replaceContents ( Array $ replacements ) { $ this -> writeContents ( str_replace ( array_keys ( $ replacements ) , array_values ( $ replacements ) , $ this -> getContents ( ) ) ) ; return $ this ; }
Replaces the contents of the file
8,247
private function set_field_names ( ) { foreach ( $ this -> config -> fields as $ field ) { $ field -> init_name = $ field -> name ; } }
Since the widget s form sets custom names and ids to each field the original field name must be stored seperately using this function .
8,248
public function form ( $ instance ) { foreach ( $ this -> config -> fields as $ field ) { $ field -> name = $ field -> init_name ; } $ this -> form -> updater -> set_new_instance ( $ instance ) ; $ this -> form -> updater -> update ( ) ; foreach ( $ this -> config -> fields as $ field ) { $ field -> id = $ this -> get_field_id ( $ field -> init_name ) ; $ field -> name = $ this -> get_field_name ( $ field -> init_name ) ; } $ this -> form -> render ( true ) ; }
Generates the administration form for the widget
8,249
public function update ( $ new_instance , $ old_instance ) { $ this -> form -> updater -> set_new_instance ( $ new_instance ) ; return $ this -> form -> updater -> update ( $ old_instance ) ; }
Processes the widget s options to be saved .
8,250
private function validate_components ( $ components ) { foreach ( $ components as $ component ) { if ( ! $ component instanceof UI \ AbstractComponent ) { throw new WrongTypeException ( \ gettype ( $ component ) ) ; } if ( $ component instanceof UI \ Components \ Composite ) { $ this -> validate_components ( $ component -> components ) ; continue ; } if ( $ component instanceof UI \ ValueComponentInterface && in_array ( $ component -> name , $ this -> names ) ) { throw new DuplicateNameException ( $ component -> name ) ; } $ this -> names [ ] = $ component -> name ; } }
Internally used to validate each form component .
8,251
public function generateCommands ( array $ classes = [ ] ) { $ classes = $ this -> readApis ( $ classes ) ; $ token = $ this -> token -> read ( ) ; $ commands = [ ] ; foreach ( $ classes as $ class ) { $ api = new \ ReflectionClass ( $ class ) ; foreach ( $ api -> getMethods ( \ ReflectionMethod :: IS_PUBLIC ) as $ method ) { if ( 0 !== strpos ( $ method -> getName ( ) , '__' ) ) { $ command = $ this -> generateCommand ( $ api -> getShortName ( ) , $ method , $ token ) ; $ commands [ $ command -> getName ( ) ] = $ command ; } } } return $ commands ; }
generates Commands from all Api Methods .
8,252
private function buildDefinition ( \ ReflectionMethod $ method , $ token = null ) { $ definition = new InputDefinition ( ) ; foreach ( $ method -> getParameters ( ) as $ parameter ) { if ( $ parameter -> isDefaultValueAvailable ( ) ) { $ definition -> addOption ( new InputOption ( $ parameter -> getName ( ) , null , InputOption :: VALUE_REQUIRED , null , $ parameter -> isDefaultValueAvailable ( ) ? $ parameter -> getDefaultValue ( ) : null ) ) ; } else { $ definition -> addArgument ( new InputArgument ( $ parameter -> getName ( ) , InputArgument :: REQUIRED , null , null ) ) ; } } $ definition -> addOption ( new InputOption ( 'token' , null , InputOption :: VALUE_REQUIRED , 'the auth token to use' , $ token ) ) ; $ definition -> addOption ( new InputOption ( 'debug' , null , InputOption :: VALUE_NONE , 'display raw response' ) ) ; return $ definition ; }
builds the Input Definition based upon Api Method Parameters .
8,253
public static function handle ( ) { $ args = func_get_args ( ) ; $ key = array_shift ( $ args ) ; return call_user_func_array ( array ( static :: $ builder , 'build_' . $ key ) , $ args ) ; }
Handle a build request
8,254
static function getInstance ( $ methods , $ patternUri , $ action , $ name = null ) { if ( ! self :: $ instance ) { self :: $ instance = new self ( $ methods , $ patternUri , $ action , $ name ) ; } return self :: $ instance ; }
Get Route instance
8,255
public function setAction ( $ action ) { if ( ! is_string ( $ action ) && ! is_callable ( $ action ) ) { throw new \ LogicException ( sprintf ( 'Route action given "%s" is invalid. String or Callable expected.' , gettype ( $ action ) ) ) ; } $ this -> action = $ action ; return $ this ; }
Set action callback
8,256
protected function configure ( ) { $ sAppName = SystemSettings :: get ( 'app_name' ) ; $ this -> setName ( $ sAppName . ':remote:cron' ) -> addOption ( 'app' , null , InputOption :: VALUE_REQUIRED , 'run only for specific remote app' , false ) -> addOption ( 'force' , null , InputOption :: VALUE_NONE , 'force to run remote app / ignore cron settings' ) -> setDescription ( 'Run/Crawl registered remote apps' ) ; }
configure cli command for making api calls
8,257
private function _parseCrontab ( $ sDatetime , $ sCrontab ) { $ aTime = explode ( ' ' , date ( 'i G j n w' , strtotime ( $ sDatetime ) ) ) ; $ sCrontab = explode ( ' ' , $ sCrontab ) ; foreach ( $ sCrontab as $ k => & $ v ) { $ v = explode ( ',' , $ v ) ; foreach ( $ v as & $ v1 ) { $ v1 = preg_replace ( array ( '/^\*$/' , '/^\d+$/' , '/^(\d+)\-(\d+)$/' , '/^\*\/(\d+)$/' ) , array ( 'true' , intval ( $ aTime [ $ k ] ) . '===\0' , '(\1<=' . intval ( $ aTime [ $ k ] ) . ' and ' . intval ( $ aTime [ $ k ] ) . '<=\2)' , intval ( $ aTime [ $ k ] ) . '%\1===0' ) , $ v1 ) ; } $ v = '(' . implode ( ' or ' , $ v ) . ')' ; } $ sCrontab = implode ( ' and ' , $ sCrontab ) ; return eval ( 'return ' . $ sCrontab . ';' ) ; }
Parse cron time string
8,258
private function _makeCall ( $ oRemoteApp ) { $ this -> getContainer ( ) -> get ( 'API' ) ; Api :: $ _container = $ this -> getContainer ( ) ; $ aReturn = Api :: call ( 'getData' , array ( array ( 'log' => $ oRemoteApp -> getIncludelog ( ) , 'format' => 'json' ) ) , $ oRemoteApp -> getFullApiUrl ( ) , $ oRemoteApp -> getPublicKey ( ) , $ oRemoteApp ) ; $ sStatuscode = $ aReturn [ 'statuscode' ] ; $ aReturn = json_decode ( $ aReturn [ 'result' ] , true ) ; if ( ! isset ( $ aReturn [ 'status' ] ) ) { $ aReturn [ 'status' ] = true ; } $ aReturn [ 'statuscode' ] = $ sStatuscode ; if ( $ sStatuscode != 200 ) { $ this -> getContainer ( ) -> get ( 'logger' ) -> error ( "ERROR in " . __FILE__ . " on line " . __LINE__ . " - " . json_encode ( $ aReturn ) , array ( "Method" => __METHOD__ , "RemoteApp" => $ oRemoteApp -> getName ( ) , "RemoteURL" => $ oRemoteApp -> getFullApiUrl ( ) ) ) ; } return $ aReturn ; }
perform api call
8,259
private function _saveResponse ( $ aResponse , $ oRemoteApp ) { $ sClassName = '\Slashworks\AppBundle\Model\RemoteHistory' . ucfirst ( $ oRemoteApp -> getType ( ) ) ; $ sQueryClassName = '\Slashworks\AppBundle\Model\RemoteHistory' . ucfirst ( $ oRemoteApp -> getType ( ) . 'Query' ) ; if ( class_exists ( $ sClassName ) ) { $ aHistories = $ sQueryClassName :: create ( ) -> findByRemoteAppId ( $ oRemoteApp -> getId ( ) ) ; $ oRemoteHistoryClass = new $ sClassName ( ) ; $ oRemoteHistoryClass -> setRemoteApp ( $ oRemoteApp ) ; $ oRemoteHistoryClass -> setData ( $ aResponse ) ; $ aNewHistory = $ oRemoteHistoryClass -> toArray ( ) ; $ aNewHistory [ 'Extensions' ] = $ aNewHistory [ 'Extensions' ] -> getArrayCopy ( ) ; if ( is_object ( $ aNewHistory [ 'Log' ] ) ) { $ aNewHistory [ 'Log' ] = $ aNewHistory [ 'Log' ] -> getArrayCopy ( ) ; } else { $ aNewHistory [ 'Log' ] = array ( ) ; } unset ( $ aNewHistory [ 'Id' ] ) ; foreach ( $ aHistories as $ oHistory ) { $ aHistory = $ oHistory -> toArray ( ) ; $ aHistory [ 'Extensions' ] = $ aHistory [ 'Extensions' ] -> getArrayCopy ( ) ; if ( is_object ( $ aHistory [ 'Log' ] ) ) { $ aHistory [ 'Log' ] = $ aHistory [ 'Log' ] -> getArrayCopy ( ) ; } else { $ aHistory [ 'Log' ] = array ( ) ; } unset ( $ aHistory [ 'Id' ] ) ; if ( $ aResponse [ 'statuscode' ] != 200 ) { if ( $ oRemoteApp -> checkNotificationSetting ( "NotificationError" ) ) { $ this -> _sendErrorNotification ( $ oRemoteApp , $ aResponse ) ; } } else { $ aNew = $ this -> arrayRecursiveDiff ( $ aNewHistory , $ aHistory ) ; if ( ! empty ( $ aNew ) && $ oRemoteApp -> checkNotificationSetting ( "NotificationChange" ) ) { $ aOld = $ this -> arrayRecursiveDiff ( $ aHistory , $ aNewHistory ) ; $ this -> _sendNotification ( array ( 'old' => $ aOld , 'new' => $ aNew ) , $ oRemoteApp , $ aNewHistory ) ; } } $ oHistory -> delete ( ) ; } $ oRemoteHistoryClass -> save ( ) ; $ oRemoteApp -> setLastRun ( time ( ) ) ; $ oRemoteApp -> save ( ) ; } else { $ this -> getContainer ( ) -> get ( 'logger' ) -> error ( 'Class \'' . $ sClassName . '\' not found... ' , array ( "Method" => __METHOD__ , "RemoteApp" => $ oRemoteApp -> getName ( ) , "RemoteURL" => $ oRemoteApp -> getFullApiUrl ( ) ) ) ; throw new \ Exception ( 'Class \'' . $ sClassName . '\' not found... ' ) ; } }
Save response to database
8,260
private function _sendErrorNotification ( & $ oRemoteApp , $ aResponse ) { $ iStatusCode = $ aResponse [ 'statuscode' ] ; if ( $ iStatusCode === 404 ) { $ sHtml = $ this -> getContainer ( ) -> get ( 'templating' ) -> render ( 'SlashworksAppBundle:Email:cron_error_404_notification.html.twig' , array ( 'remote_app' => $ oRemoteApp , 'response' => $ aResponse , 'controlurl' => $ this -> _getSiteURL ( ) ) ) ; } elseif ( $ iStatusCode === 500 ) { $ sHtml = $ this -> getContainer ( ) -> get ( 'templating' ) -> render ( 'SlashworksAppBundle:Email:cron_error_500_notification.html.twig' , array ( 'remote_app' => $ oRemoteApp , 'response' => $ aResponse , 'controlurl' => $ this -> _getSiteURL ( ) ) ) ; } elseif ( $ iStatusCode === 403 ) { $ sHtml = $ this -> getContainer ( ) -> get ( 'templating' ) -> render ( 'SlashworksAppBundle:Email:cron_error_403_notification.html.twig' , array ( 'remote_app' => $ oRemoteApp , 'response' => $ aResponse , 'controlurl' => $ this -> _getSiteURL ( ) ) ) ; } else { $ sHtml = $ this -> getContainer ( ) -> get ( 'templating' ) -> render ( 'SlashworksAppBundle:Email:cron_error_notification.html.twig' , array ( 'remote_app' => $ oRemoteApp , 'response' => $ aResponse , 'controlurl' => $ this -> _getSiteURL ( ) ) ) ; } $ sSubject = $ this -> getContainer ( ) -> get ( 'translator' ) -> trans ( 'system.email.error.' . $ iStatusCode . '.subject' ) ; $ sRecipient = $ oRemoteApp -> getNotificationRecipient ( ) ; $ sSender = $ oRemoteApp -> getNotificationSender ( ) ; $ sMessage = \ Swift_Message :: newInstance ( ) -> setSubject ( $ sSubject ) -> setFrom ( $ sSender ) -> setTo ( $ sRecipient ) -> setContentType ( 'text/html' ) -> setBody ( $ sHtml , 'text/html' ) -> addPart ( $ sHtml , 'text/html' ) ; $ this -> getContainer ( ) -> get ( 'mailer' ) -> send ( $ sMessage ) ; }
Send Error - Notification to user
8,261
private function _sendNotification ( $ aDiff , & $ oRemoteApp , $ aNewHistory ) { $ sHtml = $ this -> getContainer ( ) -> get ( 'templating' ) -> render ( 'SlashworksAppBundle:Email:cron_notification.html.twig' , array ( 'diff' => $ aDiff , 'log' => $ aNewHistory [ 'Log' ] , 'remote_app' => $ oRemoteApp , 'controlurl' => $ this -> _getSiteURL ( ) ) ) ; $ sRecipient = $ oRemoteApp -> getNotificationRecipient ( ) ; $ sSender = $ oRemoteApp -> getNotificationSender ( ) ; $ sMessage = \ Swift_Message :: newInstance ( ) -> setSubject ( $ this -> getContainer ( ) -> get ( 'translator' ) -> trans ( 'system.email.change.subject' ) ) -> setFrom ( $ sSender ) -> setTo ( $ sRecipient ) -> setContentType ( 'text/html' ) -> setBody ( $ sHtml , 'text/html' ) -> addPart ( $ sHtml , 'text/html' ) ; $ this -> getContainer ( ) -> get ( 'mailer' ) -> send ( $ sMessage ) ; }
Send Notification to user
8,262
public function isExpired ( ) { if ( ! FS :: isFile ( $ this -> _resultFile ) ) { return true ; } $ fileAge = abs ( time ( ) - filemtime ( $ this -> _resultFile ) ) ; if ( $ fileAge >= $ this -> _cache_ttl ) { return true ; } $ firstLine = trim ( FS :: firstLine ( $ this -> _resultFile ) ) ; $ expected = trim ( $ this -> _getHeader ( ) ) ; if ( $ expected === $ firstLine ) { return false ; } return true ; }
Check is current cache is expired
8,263
public function save ( $ content ) { $ content = $ this -> _getHeader ( ) . $ content ; $ result = file_put_contents ( $ this -> _resultFile , $ content ) ; if ( ! $ result ) { throw new Exception ( 'JBZoo/Less: File not save - ' . $ this -> _resultFile ) ; } }
Save result to cache
8,264
public function subscribe ( Forum $ forum , User $ user , $ selfActivation = true ) { $ this -> om -> startFlushSuite ( ) ; $ notification = new Notification ( ) ; $ notification -> setUser ( $ user ) ; $ notification -> setForum ( $ forum ) ; $ notification -> setSelfActivation ( $ selfActivation ) ; $ this -> om -> persist ( $ notification ) ; $ this -> dispatch ( new SubscribeForumEvent ( $ forum ) ) ; $ this -> om -> endFlushSuite ( ) ; }
Subscribe a user to a forum . A mail will be sent to the user each time a message is posted .
8,265
public function sendMessageNotification ( Message $ message , User $ user ) { $ forum = $ message -> getSubject ( ) -> getCategory ( ) -> getForum ( ) ; $ notifications = $ this -> notificationRepo -> findBy ( array ( 'forum' => $ forum ) ) ; $ users = array ( ) ; foreach ( $ notifications as $ notification ) { $ users [ ] = $ notification -> getUser ( ) ; } $ title = $ this -> translator -> trans ( 'forum_new_message' , array ( '%forum%' => $ forum -> getResourceNode ( ) -> getName ( ) , '%subject%' => $ message -> getSubject ( ) -> getTitle ( ) , '%author%' => $ message -> getCreator ( ) -> getUsername ( ) ) , 'forum' ) ; $ url = $ this -> router -> generate ( 'claro_forum_subjects' , array ( 'category' => $ message -> getSubject ( ) -> getCategory ( ) -> getId ( ) ) , true ) ; $ body = "<a href='{$url}'>{$title}</a><hr>{$message->getContent()}" ; $ this -> mailManager -> send ( $ title , $ body , $ users ) ; }
Send a notification to a user about a message .
8,266
public function moveMessage ( Message $ message , Subject $ newSubject ) { $ this -> om -> startFlushSuite ( ) ; $ oldSubject = $ message -> getSubject ( ) ; $ message -> setSubject ( $ newSubject ) ; $ this -> om -> persist ( $ message ) ; $ this -> dispatch ( new MoveMessageEvent ( $ message , $ oldSubject , $ newSubject ) ) ; $ this -> om -> endFlushSuite ( ) ; }
Move a message to an other subject .
8,267
public function moveSubject ( Subject $ subject , Category $ newCategory ) { $ this -> om -> startFlushSuite ( ) ; $ oldCategory = $ subject -> getCategory ( ) ; $ subject -> setCategory ( $ newCategory ) ; $ this -> om -> persist ( $ subject ) ; $ this -> dispatch ( new MoveSubjectEvent ( $ subject , $ oldCategory , $ newCategory ) ) ; $ this -> om -> endFlushSuite ( ) ; }
Move a subject to an other category .
8,268
public function stickSubject ( Subject $ subject ) { $ this -> om -> startFlushSuite ( ) ; $ subject -> setIsSticked ( true ) ; $ this -> om -> persist ( $ subject ) ; $ this -> dispatch ( new StickSubjectEvent ( $ subject ) ) ; $ this -> om -> endFlushSuite ( ) ; }
Stick a subject at the top of the subject list .
8,269
public function unstickSubject ( Subject $ subject ) { $ this -> om -> startFlushSuite ( ) ; $ subject -> setIsSticked ( false ) ; $ this -> om -> persist ( $ subject ) ; $ this -> dispatch ( new UnstickSubjectEvent ( $ subject ) ) ; $ this -> om -> endFlushSuite ( ) ; }
Unstick a subject from the top of the subject list .
8,270
public function closeSubject ( Subject $ subject ) { $ this -> om -> startFlushSuite ( ) ; $ subject -> setIsClosed ( true ) ; $ this -> om -> persist ( $ subject ) ; $ this -> dispatch ( new CloseSubjectEvent ( $ subject ) ) ; $ this -> om -> endFlushSuite ( ) ; }
Close a subject and no one can write in it .
8,271
public function openSubject ( Subject $ subject ) { $ this -> om -> startFlushSuite ( ) ; $ subject -> setIsClosed ( false ) ; $ this -> om -> persist ( $ subject ) ; $ this -> dispatch ( new OpenSubjectEvent ( $ subject ) ) ; $ this -> om -> endFlushSuite ( ) ; }
Open a subject .
8,272
public function getSubjectsPager ( Category $ category , $ page = 1 , $ max = 20 ) { $ subjects = $ this -> forumRepo -> findSubjects ( $ category ) ; return $ this -> pagerFactory -> createPagerFromArray ( $ subjects , $ page , $ max ) ; }
Get the pager for the subject list of a category .
8,273
public function getMessagesPager ( Subject $ subject , $ page = 1 , $ max = 20 ) { $ messages = $ this -> messageRepo -> findBySubject ( $ subject ) ; return $ this -> pagerFactory -> createPagerFromArray ( $ messages , $ page , $ max ) ; }
Get the pager for the message list of a subject .
8,274
public function searchPager ( Forum $ forum , $ search , $ page ) { $ query = $ this -> forumRepo -> search ( $ forum , $ search ) ; return $ this -> pagerFactory -> createPager ( $ query , $ page ) ; }
Get the pager for the forum search .
8,275
protected function _prepareHeaders ( ) { $ headers = array ( ) ; if ( ! isset ( $ this -> headers [ 'host' ] ) ) { $ host = $ this -> uri -> getHost ( ) ; if ( ! ( ( $ this -> uri -> getScheme ( ) == 'http' && $ this -> uri -> getPort ( ) == 80 ) || ( $ this -> uri -> getScheme ( ) == 'https' && $ this -> uri -> getPort ( ) == 443 ) ) ) { $ host .= ':' . $ this -> uri -> getPort ( ) ; } $ headers [ ] = "Host: {$host}" ; } if ( ! isset ( $ this -> headers [ 'connection' ] ) ) { if ( ! $ this -> config [ 'keepalive' ] ) { $ headers [ ] = "Connection: close" ; } } if ( ! isset ( $ this -> headers [ 'accept-encoding' ] ) ) { if ( function_exists ( 'gzinflate' ) ) { $ headers [ ] = 'Accept-encoding: gzip, deflate' ; } else { $ headers [ ] = 'Accept-encoding: identity' ; } } if ( $ this -> method == self :: POST && ( ! isset ( $ this -> headers [ strtolower ( self :: CONTENT_TYPE ) ] ) && isset ( $ this -> enctype ) ) ) { $ headers [ ] = self :: CONTENT_TYPE . ': ' . $ this -> enctype ; } if ( ! isset ( $ this -> headers [ 'user-agent' ] ) && isset ( $ this -> config [ 'useragent' ] ) ) { $ headers [ ] = "User-Agent: {$this->config['useragent']}" ; } if ( is_array ( $ this -> auth ) ) { $ auth = self :: encodeAuthHeader ( $ this -> auth [ 'user' ] , $ this -> auth [ 'password' ] , $ this -> auth [ 'type' ] ) ; $ headers [ ] = "Authorization: {$auth}" ; } if ( isset ( $ this -> cookiejar ) ) { $ cookstr = $ this -> cookiejar -> getMatchingCookies ( $ this -> uri , true , Zend_Http_CookieJar :: COOKIE_STRING_CONCAT ) ; if ( $ cookstr ) { $ headers [ ] = "Cookie: {$cookstr}" ; } } foreach ( $ this -> headers as $ header ) { list ( $ name , $ value ) = $ header ; if ( is_array ( $ value ) ) { $ value = implode ( ', ' , $ value ) ; } $ headers [ ] = "$name: $value" ; } return $ headers ; }
Prepare the request headers
8,276
protected function resolve ( $ action , $ params ) { if ( $ action instanceof Closure ) { return $ action ( $ params ) ; } list ( $ controller , $ method ) = $ action ; $ reflect = new ReflectionClass ( $ controller ) ; foreach ( array_filter ( $ reflect -> getMethod ( $ method ) -> getParameters ( ) , $ this -> getParams ( ) ) as $ param ) { array_unshift ( $ params , $ this -> registry -> make ( $ param -> getClass ( ) -> getName ( ) ) ) ; } return $ reflect -> getMethod ( $ method ) -> invokeArgs ( $ this -> registry -> make ( $ controller ) , $ params ) ; }
Method injection resolver
8,277
public function compile ( Report $ report , bool $ skipExec = false ) { $ sourceFullPath = $ report -> getSourceFile ( ) ; $ compiledPath = $ this -> compiledPath ; $ this -> shellCommand = $ this -> executablePath . " cp -o $compiledPath $sourceFullPath" ; if ( ! $ skipExec ) { $ oldcwd = getcwd ( ) ; chdir ( $ this -> sourcePath ) ; $ error = shell_exec ( escapeshellcmd ( $ this -> shellCommand ) ) ; chdir ( $ oldcwd ) ; if ( ! empty ( $ error ) ) { throw new \ Exception ( $ error ) ; } } return $ compiledPath ; }
Compile JRXML files into JASPER for processing .
8,278
public function process ( Report $ report , bool $ skipExec = false ) { $ compiledFullPath = $ this -> compiledPath . DIRECTORY_SEPARATOR . pathinfo ( $ report -> getSourceFile ( ) , PATHINFO_FILENAME ) . '.jasper' ; $ processedFullPath = $ this -> processedPath . DIRECTORY_SEPARATOR . uniqid ( 'ASB' ) ; $ format = ' -f ' . $ report -> getTargetType ( ) ; $ value = empty ( $ report -> getDataSource ( ) ) ? $ this -> getDataSource ( ) : $ report -> getDataSource ( ) ; $ type = "-t $value " ; $ datafile = '' ; if ( ! empty ( $ report -> getFile ( 'file' ) ) ) { $ datafile .= $ this -> processCsvFileOptions ( $ report ) ; } $ database = $ this -> processDatabaseOptions ( $ report ) ; $ parameters = $ this -> processReportParameters ( $ report ) ; $ this -> shellCommand = $ this -> executablePath . " pr -o $processedFullPath $compiledFullPath $format $type $database $datafile $parameters" ; if ( ! $ skipExec ) { $ oldcwd = getcwd ( ) ; chdir ( $ this -> sourcePath ) ; $ error = shell_exec ( escapeshellcmd ( $ this -> shellCommand ) ) ; chdir ( $ oldcwd ) ; if ( ! empty ( $ error ) ) { throw new \ Exception ( $ error ) ; } } return $ processedFullPath . '.' . $ report -> getTargetType ( ) ; }
Process JASPER file into PDF or similar output format .
8,279
protected function processCsvFileOptions ( Report $ report ) { $ value = $ report -> getFile ( 'file' ) ; $ csvSwitch = "--data-file $value " ; $ value = $ report -> getCsvfile ( 'columnHeaderNames' ) ; if ( empty ( $ value ) ) { $ csvSwitch .= '--csv-first-row ' ; } else { $ csvSwitch .= "--csv-columns " . implode ( ',' , $ value ) . ' ' ; } $ value = $ report -> getCsvfile ( 'charSet' ) ; $ database = "--csv-charset $value " ; $ value = $ report -> getCsvfile ( 'delimField' ) ; $ database = "--csv-field-del $value " ; $ value = $ report -> getCsvfile ( 'delimNewLine' ) ; $ database = "--csv-record-del $value " ; return $ csvSwitch ; }
Process CSV file details
8,280
public static function getRoot ( ) { if ( ! isset ( self :: $ root ) ) { try { $ root = getenv ( 'PSC_CMS' ) ; if ( ! empty ( $ root ) ) { return self :: $ root = new Dir ( $ root ) ; } } catch ( \ Webforge \ Common \ System \ Exception $ e ) { } throw MissingEnvironmentVariableException :: factory ( 'PSC_CMS' , 'The variable should reference a directory, where the host-config.php can live. Use trailing slash/backslash.' ) ; } return self :: $ root ; }
Returns the root directory of the host where the host - config lives
8,281
public static function createKey ( ? string $ msgid , ? string $ msgctxt = null , ? string $ msgid_plural = null ) : string { $ key = '' ; if ( ! empty ( $ msgctxt ) ) { $ key .= $ msgctxt . '|' ; } $ key .= ( string ) $ msgid ; if ( ! empty ( $ msgid_plural ) ) { $ key .= '|' . $ msgid_plural ; } return $ key ; }
Build the internal entries array key from id context and plural id
8,282
public function createKeyFromEntry ( PoEntry $ entry ) : string { return $ this -> createKey ( $ entry -> getAsString ( PoTokens :: MESSAGE ) , $ entry -> getAsString ( PoTokens :: CONTEXT ) , $ entry -> getAsString ( PoTokens :: PLURAL ) ) ; }
Build an internal entries array key from a PoEntry
8,283
public function addEntry ( PoEntry $ entry , bool $ replace = true ) : bool { $ key = $ this -> createKeyFromEntry ( $ entry ) ; if ( empty ( $ key ) ) { $ this -> unkeyedEntries [ ] = $ entry ; return true ; } if ( isset ( $ this -> entries [ $ key ] ) && ! $ replace ) { return false ; } else { $ this -> entries [ $ key ] = $ entry ; return true ; } }
Add an entry to the PoFile using internal key
8,284
public function mergeEntry ( PoEntry $ newEntry ) : bool { $ key = $ this -> createKeyFromEntry ( $ newEntry ) ; if ( empty ( $ key ) ) { return false ; } if ( isset ( $ this -> entries [ $ key ] ) ) { $ existingEntry = $ this -> entries [ $ key ] ; $ mergeTokens = array ( PoTokens :: REFERENCE , PoTokens :: EXTRACTED_COMMENTS ) ; foreach ( $ mergeTokens as $ type ) { $ toMerge = $ newEntry -> get ( $ type ) ; if ( ! empty ( $ toMerge ) ) { $ toMerge = is_array ( $ toMerge ) ? $ toMerge : array ( $ toMerge ) ; foreach ( $ toMerge as $ value ) { $ existingEntry -> add ( $ type , $ value ) ; } } } } else { $ this -> entries [ $ key ] = $ newEntry ; } return true ; }
Merge an entry with any existing entry with the same key . If the key does not exist add the entry otherwise merge comments references and flags .
8,285
public function findEntry ( string $ msgid , ? string $ msgctxt = null , ? string $ msgid_plural = null ) : ? PoEntry { $ key = $ this -> createKey ( $ msgid , $ msgctxt , $ msgid_plural ) ; $ entry = null ; if ( ! empty ( $ key ) && isset ( $ this -> entries [ $ key ] ) ) { $ entry = $ this -> entries [ $ key ] ; } return $ entry ; }
Get an entry based on key values - msgid msgctxt and msgid_plural
8,286
public function removeEntry ( PoEntry $ entry ) : bool { $ key = $ this -> createKeyFromEntry ( $ entry ) ; if ( ! empty ( $ key ) && isset ( $ this -> entries [ $ key ] ) ) { if ( $ entry === $ this -> entries [ $ key ] ) { unset ( $ this -> entries [ $ key ] ) ; return true ; } } foreach ( $ this -> entries as $ key => $ value ) { if ( $ entry === $ value ) { unset ( $ this -> entries [ $ key ] ) ; return true ; } } foreach ( $ this -> unkeyedEntries as $ key => $ value ) { if ( $ entry === $ value ) { unset ( $ this -> unkeyedEntries [ $ key ] ) ; return true ; } } return false ; }
Remove an entry from the PoFile
8,287
public function writePoFile ( string $ file ) : void { $ source = $ this -> dumpString ( ) ; $ testName = file_exists ( $ file ) ? $ file : dirname ( $ file ) ; $ status = is_writable ( $ testName ) ; if ( $ status === true ) { $ status = file_put_contents ( $ file , $ source ) ; } if ( false === $ status ) { throw new FileNotWritableException ( $ file ) ; } }
Write any current contents to a po file
8,288
public function dumpString ( ) : string { if ( $ this -> header === null ) { $ this -> header = new PoHeader ; $ this -> header -> buildDefaultHeader ( ) ; } $ output = '' ; $ output .= $ this -> header -> dumpEntry ( ) ; foreach ( $ this -> entries as $ entry ) { $ output .= $ entry -> dumpEntry ( ) ; } foreach ( $ this -> unkeyedEntries as $ entry ) { $ output .= $ entry -> dumpEntry ( ) ; } $ output .= "\n" ; return $ output ; }
Dump the current contents in PO format to a string
8,289
public function readPoFile ( string $ file , ? resource $ context = null ) : void { $ oldEr = error_reporting ( E_ALL ^ E_WARNING ) ; $ source = file_get_contents ( $ file , false , $ context ) ; error_reporting ( $ oldEr ) ; if ( false === $ source ) { throw new FileNotReadableException ( $ file ) ; } $ this -> parsePoSource ( $ source ) ; }
Replace any current contents with entries from a file
8,290
public function addTemplatePath ( $ path ) { if ( is_array ( $ this -> templatesPath ) ) { if ( array_search ( $ path , $ this -> templatesPath ) ) { throw new \ LogicException ( sprintf ( 'Templates path "%s" exists.' , $ path ) ) ; } else { $ this -> templatesPath [ ] = $ path ; } } else if ( is_string ( $ this -> templatesPath ) ) { $ lastTemplate = $ this -> templatesPath ; $ this -> templatesPath = array ( $ lastTemplate , $ path ) ; } }
Add Template Path
8,291
public function render ( $ file , $ vars = null ) { $ template = '' ; if ( is_null ( $ this -> templatesPath ) ) { throw new \ LogicException ( 'Variable "templatesPath" can\'t be NULL.' ) ; } else if ( is_string ( $ this -> templatesPath ) && ! file_exists ( $ this -> templatesPath ) ) { throw new \ LogicException ( sprintf ( 'Folder "%s" don\'t exists.' , $ this -> templatesPath ) ) ; } else if ( is_array ( $ this -> templatesPath ) ) { foreach ( $ this -> templatesPath as $ folderPath ) { if ( file_exists ( $ template = "$folderPath/{$file}" ) ) { break ; } } } if ( ! $ template ) { $ template = "$this->templatesPath/{$file}" ; } if ( ! file_exists ( $ template ) ) { throw new \ LogicException ( sprintf ( 'View "%s" don\'t exists.' , $ template ) ) ; } if ( is_array ( $ vars ) ) { extract ( $ vars ) ; foreach ( $ vars as $ key => $ value ) { $ key = $ value ; } } ob_start ( ) ; require $ template ; return ob_get_clean ( ) ; }
Renders a given file with the supplied variables .
8,292
public function setMode ( $ arg ) { $ this -> mode = strtolower ( $ arg ) == self :: LIVE ? self :: LIVE : self :: SANDBOX ; return $ this ; }
IS TEST OR LIVE
8,293
public function registr ( $ place , $ controller ) { if ( preg_match ( '/^[a-z0-9]+:[a-z0-9]+:[_a-z0-9]+$/i' , $ controller ) ) { if ( ! isset ( $ this -> widgets [ $ place ] ) ) { $ this -> widgets [ $ place ] [ ] = $ controller ; } elseif ( ! in_array ( $ controller , $ this -> widgets [ $ place ] ) ) { $ this -> widgets [ $ place ] [ ] = $ controller ; } return true ; } return false ; }
Regist widget .
8,294
private function hash_equals ( $ knownString , $ userString ) { if ( function_exists ( '\hash_equals' ) ) { return \ hash_equals ( $ knownString , $ userString ) ; } if ( strlen ( $ knownString ) !== strlen ( $ userString ) ) { return false ; } $ len = strlen ( $ knownString ) ; $ result = 0 ; for ( $ i = 0 ; $ i < $ len ; $ i ++ ) { $ result |= ( ord ( $ knownString [ $ i ] ) ^ ord ( $ userString [ $ i ] ) ) ; } return 0 === $ result ; }
Prevent timing attack
8,295
public function getParserFactory ( ) : ? ParserFactory { if ( ! $ this -> hasParserFactory ( ) ) { $ this -> setParserFactory ( $ this -> getDefaultParserFactory ( ) ) ; } return $ this -> parserFactory ; }
Get parser factory
8,296
public function render ( $ model , array $ fields = [ ] , $ element = self :: DEFAULT_ELEMENT , array $ data = [ ] ) { $ data = Hash :: merge ( [ 'clearUrl' => [ ] , 'model' => $ model , 'formFields' => $ fields , ] , $ data ) ; return $ this -> _View -> element ( $ element , $ data ) ; }
Render filter element .
8,297
public function executeProcedure ( $ strProcName , $ params = null ) { $ strParams = '' ; if ( $ params ) { $ a = array_map ( function ( $ val ) { return $ this -> sqlVariable ( $ val ) ; } , $ params ) ; $ strParams = implode ( ',' , $ a ) ; } $ strSql = "call {$strProcName}({$strParams})" ; return $ this -> multiQuery ( $ strSql ) ; }
Generic stored procedure executor . For Mysql 5 you can have your stored procedure return results by SELECT ing the results . The results will be returned as an array .
8,298
public function addField ( string $ name , $ value ) { $ schema = $ this -> constant ( 'SCHEMA' ) -> getValue ( ) ; $ schema [ $ name ] = $ value ; $ this -> constant ( 'SCHEMA' ) -> setValue ( $ schema ) ; }
Add field into schema .
8,299
public function boot ( Container $ app ) { $ toBoot = ( array ) $ app [ 'config' ] -> get ( 'bootstrap' , [ ] ) ; foreach ( $ toBoot as $ bootstrapClass ) { $ app -> make ( $ bootstrapClass ) -> boot ( $ app ) ; } }
Call any other bootstraps defined by config .