idx int64 0 60.3k | question stringlengths 64 4.24k | target stringlengths 5 618 |
|---|---|---|
26,700 | protected function getNamespaceKey ( array $ namespaces , $ key ) { if ( empty ( $ namespaces ) ) { return $ key ; } $ component = '' ; $ parts = array ( ) ; foreach ( $ namespaces as $ namespace ) { $ component .= $ this -> delimiter . $ namespace ; $ parts [ ] = $ this -> getVersionNumber ( substr ( $ component , 1 ) ) ; } $ newKey = implode ( $ this -> delimiter , $ parts ) . $ this -> delimiter ; $ newKey .= substr ( $ component , 1 ) . $ this -> delimiter ; $ newKey .= $ key ; return $ newKey ; } | generates the final cache identifier for the provided namespace and key |
26,701 | public function findByName ( $ name ) { $ platform = $ this -> getDbAdapter ( ) -> getPlatform ( ) ; return $ this -> findOne ( array ( new Sql \ Predicate \ Expression ( 'LOWER(' . $ platform -> quoteIdentifier ( 'name' ) . ') = ?' , mb_strtolower ( $ name , 'UTF-8' ) ) , ) ) ; } | Get tag by name |
26,702 | public function isNameExists ( $ name , $ excludeId = null ) { $ platform = $ this -> getDbAdapter ( ) -> getPlatform ( ) ; $ nameEq = new Sql \ Predicate \ Expression ( 'LOWER(' . $ platform -> quoteIdentifier ( 'name' ) . ') = ?' , mb_strtolower ( $ name , 'UTF-8' ) ) ; return $ this -> isExists ( empty ( $ excludeId ) ? array ( $ nameEq , ) : array ( $ nameEq , new Sql \ Predicate \ Operator ( 'id' , Sql \ Predicate \ Operator :: OP_NE , $ excludeId ) , ) ) ; } | Is name already exists |
26,703 | private function send ( $ path , $ method , array $ parameters = [ ] , array $ headers = [ ] , $ body = null ) { $ request = $ this -> createRequest ( $ path , $ method , $ parameters , $ headers , $ body ) ; $ event = new RequestEvent ( $ request ) ; $ this -> eventDispatcher -> dispatch ( GoogleMoviesClientEvents :: REQUEST , $ event ) ; $ this -> lastResponse = $ event -> getResponse ( ) ; if ( $ this -> lastResponse instanceof Response ) { return ( string ) $ this -> lastResponse -> getBody ( ) ; } return [ ] ; } | Create the request object and send it out to listening events . |
26,704 | public function registerDefaults ( ) { $ requestSubscriber = new RequestSubscriber ( ) ; $ this -> addSubscriber ( $ requestSubscriber ) ; $ userAgentHeaderPlugin = new UserAgentHeaderPlugin ( ) ; $ this -> addSubscriber ( $ userAgentHeaderPlugin ) ; return $ this ; } | Register the default plugins . |
26,705 | public function setDefaultLogging ( array $ parameters ) { if ( ! class_exists ( '\Monolog\Logger' ) ) { throw new \ RuntimeException ( 'Could not find any logger set and the monolog logger library was not found to provide a default, you have to set a custom logger on the client or have you forgot adding monolog to your composer.json?' ) ; } else { $ logger = new Logger ( 'google-movie-client' ) ; $ logger -> pushHandler ( $ parameters [ 'handler' ] ) ; } if ( $ this -> getAdapter ( ) instanceof GuzzleAdapter ) { $ subscriber = new LogSubscriber ( $ logger ) ; $ this -> getAdapter ( ) -> getClient ( ) -> getEmitter ( ) -> attach ( $ subscriber ) ; } return $ this ; } | Enable logging . |
26,706 | public function getStatus ( ) { if ( isset ( $ this -> _statuses [ ( int ) $ this -> status ] ) ) { return $ this -> _statuses [ ( int ) $ this -> status ] ; } throw new \ Exception ( 'Status "' . $ this -> status . '" not found for Page with id ' . $ this -> id . '.' ) ; } | Retrieve the current status of a page . |
26,707 | public function initializeContentAreas ( ) { $ content = $ this -> _getContent ( ) ; foreach ( $ content as $ contentAreaDefintion ) { $ contentArea = new ContentArea ( $ contentAreaDefintion ) ; $ this -> _contentAreas [ $ contentArea -> id ] = $ contentArea ; } } | Initialize the content areas of this page . |
26,708 | private function determineSubTypeOfIndexedContainers ( $ data ) { list ( $ allNumeric , $ inSequence ) = $ this -> detectContainerKeyFlags ( $ data ) ; if ( $ allNumeric == false ) { return "\xE2" ; } else if ( $ inSequence ) { return "\xE0" ; } else { return "\xE1" ; } } | We select the container subtype that uses the lowest number of bytes to get the job done . |
26,709 | private function detectContainerKeyFlags ( $ data ) { $ allNumeric = true ; $ inSequence = true ; $ expectedIndex = 0 ; foreach ( $ data as $ key => $ value ) { if ( $ key == $ expectedIndex ) { $ expectedIndex ++ ; } else { $ inSequence = false ; } if ( is_numeric ( $ key ) == false ) { $ allNumeric = false ; } } return [ $ allNumeric , $ inSequence ] ; } | Detect the status of keys to determine whether they are all numeric and in sequence from zero . |
26,710 | public static function checkOnDisk ( ) { $ args = func_get_args ( ) ; if ( count ( $ args ) == 2 ) $ module = $ args [ 0 ] . DIRECTORY_SEPARATOR . $ args [ 1 ] ; elseif ( count ( $ args ) == 1 ) $ module = $ args [ 1 ] ; else throw new \ Exception ( ) ; $ module = str_replace ( '\\' , DIRECTORY_SEPARATOR , $ module ) ; return ( bool ) app ( 'files' ) -> exists ( app_path ( 'Modules' ) . DIRECTORY_SEPARATOR . $ module . DIRECTORY_SEPARATOR . 'Module.php' ) ; } | check module is disk or not |
26,711 | public static function isInstalled ( $ author , $ name ) { if ( ! self :: checkOnDisk ( $ author , $ name ) ) return false ; return self :: getFromDb ( $ author , $ name ) ; } | check module is installed |
26,712 | public static function getInstance ( ) { $ args = func_get_args ( ) ; if ( count ( $ args ) == 2 ) { $ author = $ args [ 0 ] ; $ name = $ args [ 1 ] ; } elseif ( count ( $ args ) == 1 ) { list ( $ author , $ name ) = explode ( '\\' , $ args [ 0 ] ) ; } else throw new \ Exception ( ) ; if ( ! self :: checkOnDisk ( $ author , $ name ) ) return null ; if ( ! isset ( self :: $ instance [ $ author . '*' . $ name ] ) ) { $ class = strval ( \ App :: getNamespace ( ) . 'Modules\\' . $ author . '\\' . $ name . '\\Module' ) ; $ object = new $ class ; self :: $ instance [ $ author . '*' . $ name ] = $ object ; } return self :: $ instance [ $ author . '*' . $ name ] ; } | get instance of module object |
26,713 | public static function getModulesFromDisk ( ) { if ( ! app ( 'files' ) -> exists ( app_path ( 'Modules' ) ) ) app ( 'files' ) -> makeDirectory ( app_path ( 'Modules' ) ) ; $ authors = app ( 'files' ) -> directories ( app_path ( 'Modules' ) ) ; $ results = [ ] ; if ( $ authors && count ( $ authors ) ) { foreach ( $ authors as $ author ) { $ authorName = basename ( $ author ) ; $ modules = app ( 'files' ) -> directories ( $ author ) ; if ( $ modules && count ( $ modules ) ) { foreach ( $ modules as $ module ) { $ ymlPath = $ module . '/module.yml' ; if ( app ( 'files' ) -> exists ( $ ymlPath ) ) { $ detail = Yaml :: parse ( app ( 'files' ) -> get ( $ ymlPath ) ) ; $ results [ $ authorName ] [ ] = $ detail ; } } } } } return $ results ; } | get from disk |
26,714 | protected function renderConfigure ( ) { $ this -> fillValues ( ) ; $ this -> tpl_form = 'admin.helpers.form.form' ; $ this -> generateForm ( ) ; $ this -> assign -> params ( [ 'form_url' => route ( config ( 'app.admin_url' ) . '.modules.save' , [ 'author' => strtolower ( camel_case ( $ this -> author ) ) , 'name' => strtolower ( camel_case ( $ this -> name ) ) ] ) , 'route_list' => route ( config ( 'app.admin_url' ) . '.modules.index' ) , ] ) ; return view ( $ this -> tpl_form , $ this -> assign -> getViewData ( ) ) ; } | prepare and render configuration form |
26,715 | public function addCSS ( $ files ) { if ( ! is_array ( $ files ) ) $ files = [ $ files ] ; foreach ( $ files as $ key => $ file ) { $ files [ $ key ] = $ this -> mediaPath . 'css/' . $ file ; } $ this -> assign -> addCSS ( $ files , true ) ; } | add css file for module |
26,716 | public function addPlugin ( $ file ) { $ path = $ this -> mediaPath . 'plugins/' ; $ this -> assign -> addJS ( $ path . $ file . '/' . $ file . '.min.js' , true ) ; $ this -> assign -> addCSS ( $ path . $ file . '/' . $ file . '.css' , true ) ; } | add plugin file for module |
26,717 | public static function getModulesByFile ( $ file = 'Module.php' ) { $ modules = Module :: getModules ( ) ; $ source = app_path ( 'Modules' . DIRECTORY_SEPARATOR . '{author}' . DIRECTORY_SEPARATOR . '{module}' . DIRECTORY_SEPARATOR . $ file ) ; $ files = [ ] ; if ( $ modules && count ( $ modules ) ) foreach ( $ modules as $ author => $ subModules ) { foreach ( $ subModules as $ module ) { $ data = [ '{author}' => $ module [ 'author' ] , '{module}' => $ module [ 'name' ] ] ; $ real_source = str_replace ( array_keys ( $ data ) , array_values ( $ data ) , $ source ) ; if ( \ File :: exists ( $ real_source ) ) { $ files [ ] = [ 'author' => $ author , 'module' => $ module , 'name' => $ author . DIRECTORY_SEPARATOR . $ module [ 'name' ] , 'installed' => isset ( $ module [ 'installed' ] ) , ] ; } } } return $ files ; } | Get name of all modules that exists |
26,718 | public function updateVersion ( ) { \ DB :: table ( 'modules' ) -> where ( [ [ 'name' , '=' , $ this -> name ] , [ 'author' , '=' , $ this -> author ] , ] ) -> update ( [ 'version' => $ this -> version ] ) ; } | Update database version |
26,719 | public function persist ( AbstractEntity $ entity ) { if ( $ entity -> isNew ( ) ) { return $ this -> insert ( $ entity ) ; } return $ this -> update ( $ entity ) ; } | Persist this entity inserting it if new and otherwise updating it |
26,720 | protected function getPrimaryKeyWheres ( AbstractEntity $ entity ) { $ wheres = [ ] ; $ arrayCopy = $ entity -> getArrayCopy ( ) ; foreach ( $ this -> primaryKey as $ keyColumn ) { $ wheres [ $ keyColumn ] = $ arrayCopy [ $ keyColumn ] ; } return $ wheres ; } | Get a wheres array for finding the row that matches an entity |
26,721 | protected function initialize ( ) { if ( $ this -> initialized ) { return ; } if ( ! is_object ( $ this -> prototype ) ) { $ this -> prototype = new ArrayObject ; } if ( ! $ this -> hydrator instanceof HydratorInterface ) { $ this -> hydrator = new ArraySerializable ; } $ this -> initialized = true ; } | Set up the hydrator and prototype of this mapper if not yet set |
26,722 | protected function execute ( PreparableSqlInterface $ query ) { $ statement = $ this -> getSqlObject ( ) -> prepareStatementForSqlObject ( $ query ) ; $ resultSet = new HydratingResultSet ( $ this -> hydrator , $ this -> prototype ) ; return $ resultSet -> initialize ( $ statement -> execute ( ) ) ; } | Execute a given query |
26,723 | protected function executeAndGetResultsAsEntity ( PreparableSqlInterface $ query ) { $ data = $ this -> execute ( $ query ) -> current ( ) ; if ( ! $ data || count ( $ data ) === 0 ) { return false ; } return $ data ; } | Execute a given query and return the result as a single Entity object or false if no results are returned from the query . |
26,724 | protected function executeAndGetResultsAsEntityIterator ( PreparableSqlInterface $ query ) { $ entities = $ this -> execute ( $ query ) -> toEntityArray ( ) ; return new EntityIterator ( $ entities ) ; } | Execute a given query and return the result as an Entity Iterator object |
26,725 | protected function executeAndGetResultsAsArray ( PreparableSqlInterface $ query ) { $ statement = $ this -> getSqlObject ( ) -> prepareStatementForSqlObject ( $ query ) ; $ resultSet = new ResultSet ( ) ; $ resultSet -> initialize ( $ statement -> execute ( ) ) ; return $ resultSet -> toArray ( ) ; } | Execute the given query and return the result as an array of arrays |
26,726 | public function getFiles ( $ sDirectory , $ sExt = '' ) { $ aFiles = array ( ) ; if ( ! is_dir ( $ sDirectory ) ) { return null ; } foreach ( new \ DirectoryIterator ( $ sDirectory ) as $ oFileInfo ) { if ( $ oFileInfo -> isFile ( ) ) { if ( empty ( $ sExt ) || $ sExt == $ oFileInfo -> getExtension ( ) ) { $ aFiles [ ] = $ oFileInfo -> getPathname ( ) ; } } } return $ aFiles ; } | Helper function to get all files in a directory |
26,727 | public function processAuthenticate ( $ token , $ extra = null ) { try { $ token = JWT :: decode ( $ token , Security :: salt ( ) , Configure :: read ( 'Websockets.allowedAlgs' ) ) ; } catch ( Exception $ e ) { if ( Configure :: read ( 'debug' ) ) { throw $ e ; } return [ "FAILURE" ] ; } if ( $ token -> id == 'server' ) { return [ "SUCCESS" , [ "authid" => $ token -> id ] ] ; } $ fields = Configure :: read ( 'Websockets.fields' ) ; $ table = TableRegistry :: get ( Configure :: read ( 'Websockets.userModel' ) ) ; $ conditions = [ $ table -> aliasField ( $ fields [ 'id' ] ) => $ token -> id ] ; if ( ! empty ( Configure :: read ( 'Websockets.scope' ) ) ) { $ conditions = array_merge ( $ conditions , Configure :: read ( 'Websockets.scope' ) ) ; } $ result = $ table -> find ( 'all' ) -> where ( $ conditions ) -> first ( ) ; if ( empty ( $ result ) ) { return [ "FAILURE" ] ; } return [ "SUCCESS" , [ "authid" => $ result -> id ] ] ; } | Authenticate users based on their JWT . This is inspired by the method _findUser in admads JWT plugin |
26,728 | public function getShowId ( $ term ) { $ lowerTerm = strtolower ( $ term ) ; if ( isset ( $ this -> searches [ $ lowerTerm ] ) ) { return $ this -> searches [ $ lowerTerm ] ; } $ searchData = $ this -> scrapper -> search ( $ term ) ; if ( ! isset ( $ searchData -> showId ) ) { return ; } $ showId = $ searchData -> showId ; return $ this -> searches [ $ lowerTerm ] = $ showId ; } | Get show id |
26,729 | public function getShowData ( $ showId , $ season = 1 ) { if ( isset ( $ this -> shows [ $ showId ] [ $ season ] ) ) { return $ this -> shows [ $ showId ] [ $ season ] ; } $ showData = $ this -> scrapper -> show ( $ showId , $ season ) ; return $ this -> shows [ $ showId ] [ $ season ] = $ showData ; } | Get show data |
26,730 | public function encode ( ) { if ( empty ( $ this -> image ) === true ) { throw new \ RuntimeException ( 'No source image has been specified.' ) ; } $ str = '<img src="data:' . $ this -> mimeType . ';base64,' . base64_encode ( $ this -> image ) . '"' ; if ( empty ( $ this -> extraHtml ) === false ) { $ str .= ' ' . trim ( $ this -> extraHtml ) ; } $ str .= ' />' ; return $ str ; } | Encode the current image as an inline IMG tag . |
26,731 | public function setImageFromFile ( $ file ) { if ( preg_match ( '/\.([^\.]+)$/' , $ file , $ match ) === 1 ) { $ this -> setMimeType ( 'image/' . $ match [ 1 ] ) ; } return $ this -> setImageFromBlob ( file_get_contents ( $ file ) ) ; } | Set the image source from a file . |
26,732 | public static function Attach ( $ ExtensionType ) { switch ( $ ExtensionType ) { case self :: CONTEXT_APPLICATION : if ( Gdn :: ApplicationManager ( ) instanceof Gdn_ApplicationManager ) { $ EnabledApplications = Gdn :: ApplicationManager ( ) -> EnabledApplicationFolders ( ) ; foreach ( $ EnabledApplications as $ EnabledApplication ) { self :: AttachApplication ( $ EnabledApplication ) ; } } break ; case self :: CONTEXT_PLUGIN : if ( Gdn :: PluginManager ( ) instanceof Gdn_PluginManager ) { foreach ( Gdn :: PluginManager ( ) -> SearchPaths ( ) as $ SearchPath => $ SearchPathName ) { if ( $ SearchPathName === TRUE || $ SearchPathName == 1 ) $ SearchPathName = md5 ( $ SearchPath ) ; if ( Gdn :: PluginManager ( ) -> Started ( ) ) { $ Folders = Gdn :: PluginManager ( ) -> EnabledPluginFolders ( $ SearchPath ) ; foreach ( $ Folders as $ PluginFolder ) { $ FullPluginPath = CombinePaths ( array ( $ SearchPath , $ PluginFolder ) ) ; self :: RegisterMap ( self :: MAP_LIBRARY , self :: CONTEXT_PLUGIN , $ FullPluginPath , array ( 'SearchSubfolders' => TRUE , 'Extension' => $ SearchPathName , 'Structure' => Gdn_Autoloader_Map :: STRUCTURE_SPLIT , 'SplitTopic' => strtolower ( $ PluginFolder ) , 'PreWarm' => TRUE ) ) ; } $ PluginMap = self :: GetMap ( self :: MAP_LIBRARY , self :: CONTEXT_PLUGIN ) ; if ( $ PluginMap && ! $ PluginMap -> MapIsOnDisk ( ) ) Gdn :: PluginManager ( ) -> ForceAutoloaderIndex ( ) ; } } } break ; case self :: CONTEXT_THEME : break ; } } | Attach mappings for vanilla extension folders |
26,733 | public static function Map ( $ MapHash ) { if ( array_key_exists ( $ MapHash , self :: $ Maps ) ) return self :: $ Maps [ $ MapHash ] ; if ( is_null ( $ MapHash ) ) return self :: $ Maps ; return FALSE ; } | Get an Autoloader Map by hash |
26,734 | public static function GetMap ( $ MapType , $ ContextType , $ Extension = self :: CONTEXT_CORE , $ MapRootLocation = PATH_CACHE ) { $ MapHash = self :: MakeMapHash ( $ MapType , $ ContextType , $ Extension , $ MapRootLocation ) ; return self :: Map ( $ MapHash ) ; } | Lookup and return an Autoloader Map |
26,735 | public static function SmartFree ( $ ContextType = NULL , $ MapResourceArray = NULL ) { $ CacheFolder = @ opendir ( PATH_CACHE ) ; if ( ! $ CacheFolder ) return TRUE ; while ( $ File = readdir ( $ CacheFolder ) ) { $ Extension = pathinfo ( $ File , PATHINFO_EXTENSION ) ; if ( $ Extension == 'ini' && $ File != 'locale_map.ini' ) @ unlink ( CombinePaths ( array ( PATH_CACHE , $ File ) ) ) ; } } | This method frees the map storing information about the specified resource |
26,736 | public static function Start ( ) { self :: $ Prefixes = array ( self :: CONTEXT_CORE => 'c' , self :: CONTEXT_APPLICATION => 'a' , self :: CONTEXT_PLUGIN => 'p' , self :: CONTEXT_THEME => 't' ) ; self :: $ ContextOrder = array ( self :: CONTEXT_THEME , self :: CONTEXT_LOCALE , self :: CONTEXT_PLUGIN , self :: CONTEXT_APPLICATION , self :: CONTEXT_CORE ) ; self :: $ Maps = array ( ) ; self :: $ MapGroups = array ( ) ; spl_autoload_register ( array ( 'Gdn_Autoloader' , 'Lookup' ) ) ; self :: RegisterMap ( self :: MAP_LIBRARY , self :: CONTEXT_CORE , PATH_LIBRARY . '/core' ) ; self :: RegisterMap ( self :: MAP_LIBRARY , self :: CONTEXT_CORE , PATH_LIBRARY . '/database' ) ; self :: RegisterMap ( self :: MAP_LIBRARY , self :: CONTEXT_CORE , PATH_LIBRARY . '/vendors' ) ; register_shutdown_function ( array ( 'Gdn_Autoloader' , 'Shutdown' ) ) ; } | Register core mappings |
26,737 | public static function Load ( $ MapType , $ ContextType , $ MapRootLocation , $ Options ) { return new Gdn_Autoloader_Map ( $ MapType , $ ContextType , $ MapRootLocation , $ Options ) ; } | Autoloader cache static constructor |
26,738 | public function Index ( $ ExtraPaths = NULL ) { $ FileMasks = array ( sprintf ( self :: LOOKUP_CLASS_MASK , '*' ) , sprintf ( self :: LOOKUP_INTERFACE_MASK , '*' ) ) ; $ ExtraPathsRemove = NULL ; if ( ! is_null ( $ ExtraPaths ) ) { $ ExtraPathsRemove = array ( ) ; foreach ( $ ExtraPaths as $ PathOpts ) { $ ExtraPath = GetValue ( 'path' , $ PathOpts ) ; if ( array_key_exists ( $ ExtraPath , $ this -> Paths ) ) continue ; $ ExtraPathsRemove [ ] = $ ExtraPath ; $ ExtraOptions = $ this -> BuildOptions ; $ ExtraOptions [ 'SplitTopic' ] = GetValue ( 'topic' , $ PathOpts ) ; $ this -> AddPath ( $ ExtraPath , $ ExtraOptions ) ; } } foreach ( $ this -> Paths as $ Path => $ PathOptions ) { $ Recursive = GetValue ( 'recursive' , $ PathOptions ) ; $ Files = $ this -> FindFiles ( $ Path , $ FileMasks , $ Recursive ) ; if ( $ Files === FALSE ) continue ; foreach ( $ Files as $ File ) { $ SplitTopic = GetValue ( 'topic' , $ PathOptions , self :: TOPIC_DEFAULT ) ; $ ProvidedClass = $ this -> GetClassNameFromFile ( $ File ) ; if ( $ ProvidedClass ) { $ this -> Map [ $ SplitTopic ] [ $ ProvidedClass ] = $ File ; $ this -> MapInfo [ 'dirty' ] = TRUE ; } } } $ this -> Shutdown ( ) ; if ( ! is_null ( $ ExtraPathsRemove ) ) foreach ( $ ExtraPathsRemove as $ RemPath ) unset ( $ this -> Paths [ $ RemPath ] ) ; } | Try to index the entire map |
26,739 | public function renderTeaser ( ContentTeaser $ teaser , array $ parameters = array ( ) , array $ options = array ( ) ) { $ parameters [ 'teaserId' ] = $ teaser -> getId ( ) ; if ( $ this -> requestStack -> getMasterRequest ( ) -> attributes -> get ( '_preview' ) ) { $ parameters [ 'preview' ] = true ; } $ uri = $ this -> router -> generate ( 'teaser_render' , $ parameters ) ; $ strategy = isset ( $ options [ 'strategy' ] ) ? $ options [ 'strategy' ] : 'inline' ; unset ( $ options [ 'strategy' ] ) ; return $ this -> handler -> render ( $ uri , $ strategy , $ options ) ; } | Renders a teaser . |
26,740 | public function text ( $ string , $ color = null , $ bold = false ) { if ( $ color !== null ) { $ this -> colorize ( $ color , ( int ) $ bold ) ; } if ( ! empty ( $ string ) ) { $ this -> content .= $ string . ' ' ; } $ this -> normalize ( ) ; return $ this ; } | Adds texts to this line . |
26,741 | protected function colorize ( $ color , $ bold = 0 ) { if ( ! isset ( self :: $ colors [ $ color ] ) ) { throw new Exception ( "Unknown color '$color'." ) ; } $ code = self :: $ colors [ $ color ] ; $ this -> content .= "\033[{$bold};{$code}m" ; } | Adds a color code to this line . |
26,742 | public static function begin ( $ string = '' , $ color = null , $ bold = false ) { return new Line ( $ string , $ color , $ bold ) ; } | Creates a new line and returns it . |
26,743 | public function load ( ... $ sources ) { if ( ! $ sources ) { throw new \ RuntimeException ( 'Sources must not be empty' ) ; } $ this -> clear ( ) ; foreach ( $ sources as $ source ) { switch ( $ source ) { case 'query' : case 'post' : case 'files' : case 'cookie' : $ this -> data = array_merge ( $ this -> data , $ this -> request -> $ source ( ) ) ; break ; default : throw new \ RuntimeException ( 'Unknown source: ' . $ source ) ; } } if ( $ session = $ this -> session -> get ( 'input' ) ) { $ this -> session -> unset ( 'input' ) ; if ( ! $ this -> data ) { $ this -> data = $ session [ 'data' ] ?? [ ] ; $ this -> errors = $ session [ 'errors' ] ?? [ ] ; } } } | Load input from the requested sources and the session |
26,744 | public function retry ( ) { $ this -> session -> set ( 'input' , [ 'data' => $ this -> data , 'errors' => $ this -> errors , ] ) ; return Response :: redirect ( $ this -> request -> header ( 'referer' ) ) ; } | Retry the input at the referring URL |
26,745 | public function filter ( $ var , $ filters , $ type = null ) { if ( ! is_array ( $ filters ) ) { $ filters = $ filters ? explode ( '|' , $ filters ) : [ ] ; } $ value = & $ this -> data [ $ var ] ?? null ; if ( $ value === null ) { return null ; } foreach ( $ filters as $ key => $ filter ) { $ params = explode ( ':' , $ filter ) ; $ filter = is_string ( $ key ) ? $ key : array_shift ( $ params ) ; $ filter = $ this -> filters [ $ filter ] ?? function ( & $ data ) use ( $ filter , $ params ) { $ data = $ filter ( $ data , ... $ params ) ; } ; $ errors = $ filter ( $ value , ... $ params ) ; if ( $ errors ) { $ this -> errors [ $ var ] = $ errors ; break ; } if ( $ value === null ) { return null ; } } if ( $ type ) { settype ( $ value , $ type ) ; } return $ value ; } | Filter an input variable |
26,746 | public function isReadable ( ) { $ m = substr ( $ this -> mode , 0 , 1 ) ; $ p = strlen ( $ this -> mode ) > 1 ? substr ( $ this -> mode , 1 , 2 ) : "" ; return ( $ m == "r" || $ p == "+" ) ; } | Is the file readable? |
26,747 | public function write ( $ string , $ length = null ) { $ this -> assertWritable ( ) ; return $ this -> format -> write ( $ this -> file , $ string , $ length ) ; } | Write the string to file |
26,748 | public function readline ( $ length = null ) { $ this -> assertReadable ( ) ; return $ this -> format -> readline ( $ this -> file , $ length ) ; } | Read a line from the file |
26,749 | public function unlink ( ) { if ( $ this -> isOpen ( ) ) { $ this -> close ( ) ; } if ( $ this -> exists ( ) ) { if ( unlink ( $ this -> filepath ) ) { $ this -> unlinked = true ; } } } | Remove the file from the filesystem |
26,750 | public function initialize ( ExtensionManager $ extensionManager ) { $ symfonyExtension = $ extensionManager -> getExtension ( 'fob_symfony' ) ; if ( null === $ symfonyExtension ) { throw new ExtensionInitializationException ( sprintf ( 'The %s extension must be enabled for this extension to function.' , SymfonyExtension :: class ) , $ this -> getConfigKey ( ) ) ; } } | Initializes other extensions . |
26,751 | public function add ( self $ other ) : self { return self :: from ( $ this -> value + $ other -> value ) ; } | Add two Sizes and return the sum . |
26,752 | protected function getStoreTranslation ( $ key , $ locale ) { if ( ! isset ( $ this -> translations [ $ locale ] [ $ key ] ) ) { $ response = $ this -> apiRequest ( $ this -> getAttribute ( 'api_url' ) , [ 'text' => $ key , 'lang' => $ locale ] ) ; $ response = json_decode ( $ response , true ) ; $ this -> translations [ $ locale ] [ $ key ] = $ response [ 'text' ] [ 0 ] ; } return $ this -> translations [ $ locale ] [ $ key ] ; } | Get translation and cache it . |
26,753 | public static function list_columns ( $ table = null , $ like = null , $ db = null ) { return \ Database_Connection :: instance ( $ db ) -> list_columns ( $ table , $ like ) ; } | Lists all of the columns in a table . Optionally a LIKE string can be used to search for specific fields . |
26,754 | public static function rollback_transaction ( $ db = null , $ rollback_all = true ) { return \ Database_Connection :: instance ( $ db ) -> rollback_transaction ( $ rollback_all ) ; } | Rollsback pending transactional queries Rollback to the current level uses SAVEPOINT it does not work if current RDBMS does not support them . In this case system rollsback all queries and closes the transaction |
26,755 | protected function setItemType ( ? string $ itemType = null ) : void { if ( $ itemType !== null ) { $ itemType = trim ( $ itemType ) ; } $ this -> itemType = $ itemType ; } | Sets the item type |
26,756 | protected function itemTypeError ( string $ method , $ item ) : string { $ itemType = is_object ( $ item ) ? get_class ( $ item ) : gettype ( $ item ) ; return sprintf ( '%s::%s expects item type (%s); received (%s) %s' , static :: class , $ method , $ this -> itemType ( ) , $ itemType , VarPrinter :: toString ( $ item ) ) ; } | Retrieves the item type error message |
26,757 | public function execute ( InputInterface $ input , OutputInterface $ output ) { $ description = $ input -> getArgument ( 'description' ) ; $ time = date ( 'YmdHis' ) ; $ classname = $ this -> generateClassName ( $ time , $ description ) ; $ filepath = APPDIR . '/src/' . $ this -> namespaceToPath ( ) . $ classname . '.php' ; if ( ! is_dir ( dirname ( $ filepath ) ) ) { mkdir ( dirname ( $ filepath ) , 0775 , true ) ; } $ view = $ this -> newMigrationView ; $ view -> description ( $ description ) ; $ view -> classname ( $ classname ) ; $ view -> timestamp ( $ time ) ; file_put_contents ( $ filepath , ( string ) $ view ) ; $ message = ' Created migration file ' . $ filepath ; $ output -> write ( [ '' , $ message , '' ] , true ) ; } | Execute this console command in order to create a new migration |
26,758 | protected function generateClassName ( $ time , $ description ) { $ description = substr ( strtolower ( $ description ) , 0 , 30 ) ; $ description = ucwords ( $ description ) ; $ description = preg_replace ( '/[^a-zA-Z]+/' , '' , $ description ) ; return 'Migration' . $ time . $ description ; } | Get the name of the new migration class |
26,759 | protected function createCreateForm ( $ entity ) { $ form = $ this -> createForm ( $ this -> getAddFormType ( ) , $ entity , [ 'action' => $ this -> generateUrl ( $ this -> getRouteName ( ) . "Add" , $ this -> getRouteParams ( ) ) , 'method' => 'POST' , ] ) ; return $ form ; } | Creates a form to create an entity . |
26,760 | protected function createEditForm ( $ entity ) { $ form = $ this -> createForm ( $ this -> getEditFormType ( ) , $ entity , [ 'action' => $ this -> generateUrl ( $ this -> getRouteName ( ) . "Edit" , $ this -> getRouteParams ( [ 'id' => $ entity -> getId ( ) ] ) ) , 'method' => 'POST' , ] ) ; return $ form ; } | Creates a form to edit an entity . |
26,761 | public function getPermissionForId ( $ id ) { $ permission = $ this -> permissionsDataSource -> getPermissionForId ( $ id ) ; if ( $ permission instanceof \ Zepi \ Core \ AccessControl \ Entity \ Permission ) { $ accessEntity = $ this -> getAccessEntityForUuid ( $ permission -> getAccessEntityClass ( ) , $ permission -> getAccessEntityUuid ( ) ) ; if ( $ accessEntity instanceof \ Zepi \ Core \ AccessControl \ Entity \ AccessEntity ) { $ permission -> setAccessEntity ( $ accessEntity ) ; } } return $ permission ; } | Returns the permission object for the given id |
26,762 | public function updatePermissions ( AccessEntity $ accessEntity , $ accessLevels , AccessEntity $ donor ) { $ permissions = $ this -> getPermissionsRawForUuid ( $ accessEntity -> getUuid ( ) ) ; $ grantedPermissions = array_diff ( $ accessLevels , $ permissions ) ; $ revokedPermissions = array_diff ( $ permissions , $ accessLevels ) ; foreach ( $ grantedPermissions as $ accessLevel ) { if ( ! $ donor -> hasAccess ( $ accessLevel ) ) { continue ; } $ this -> grantPermission ( $ accessEntity -> getUuid ( ) , get_class ( $ accessEntity ) , $ accessLevel , $ donor -> getName ( ) ) ; } foreach ( $ revokedPermissions as $ accessLevel ) { if ( ! $ donor -> hasAccess ( $ accessLevel ) ) { continue ; } $ this -> revokePermission ( $ accessEntity -> getUuid ( ) , get_class ( $ accessEntity ) , $ accessLevel ) ; } } | Adds and removes an array with access level to the given access entity uuid . If the donor hasn t the permission for the access level no action is taken . |
26,763 | public function exportDatabases ( ) { $ exports = [ ] ; foreach ( $ this -> databases as $ db ) { $ exports [ ] = $ this -> createExport ( $ db ) ; } return $ exports ; } | Loops over the list of databases and calls createExport method . |
26,764 | private function createExport ( $ db ) { Service :: $ log -> msg ( sprintf ( 'Mongodb: exporting "%s" database.' , $ db [ 'Database' ] ) ) ; $ cmd = 'mongodump' ; if ( ! isset ( $ db [ 'Database' ] ) ) { throw new \ Exception ( sprintf ( 'Missing "Database" parameter for one of the MongoDatabases' ) ) ; } $ cmd .= ' --db ' . $ db [ 'Database' ] ; if ( ! isset ( $ db [ 'Host' ] ) ) { throw new \ Exception ( sprintf ( 'Missing "Host" parameter for "%s" database' , $ db [ 'Database' ] ) ) ; } $ host = explode ( ':' , $ db [ 'Host' ] ) ; $ cmd .= ' --host ' . $ host [ 0 ] ; if ( isset ( $ host [ 1 ] ) ) { $ cmd .= ' --port ' . $ host [ 1 ] ; } if ( isset ( $ db [ 'Username' ] ) && ! empty ( $ db [ 'Username' ] ) ) { $ cmd .= ' --username ' . $ db [ 'Username' ] ; } if ( isset ( $ db [ 'Password' ] ) && ! empty ( $ db [ 'Password' ] ) ) { $ cmd .= ' --password ' . $ db [ 'Password' ] ; if ( ! isset ( $ db [ 'AuthenticationDatabase' ] ) ) { $ cmd .= ' --authenticationDatabase admin' ; } else { $ cmd .= ' --authenticationDatabase ' . $ db [ 'AuthenticationDatabase' ] ; } } $ folderName = $ this -> tempFolder . $ db [ 'Database' ] . '-' . date ( 'Y-m-d' ) ; $ cmd .= ' --out ' . $ folderName ; if ( isset ( $ db [ 'Password' ] ) ) { $ logCommand = str_replace ( ' --password ' . $ db [ 'Password' ] , ' --password xxxxxx' , $ cmd ) ; } else { $ logCommand = $ cmd ; } Service :: $ log -> msg ( sprintf ( 'Mongodb: export command ' . $ logCommand ) ) ; $ return = system ( $ cmd ) ; Service :: $ log -> msg ( sprintf ( 'Mongodb: ' . $ return ) ) ; Service :: $ log -> msg ( sprintf ( 'Mongodb: database export done' ) ) ; Cleanup :: addToQueue ( $ folderName , Cleanup :: TYPE_DIR ) ; return $ folderName ; } | Private method that does the actual database export . |
26,765 | public function getLastCommitDate ( ) { $ process = new Process ( 'git log -n1 --pretty=%ci HEAD' , $ this -> directory ) ; if ( $ process -> run ( ) != 0 ) { throw new \ RuntimeException ( 'Can\'t run git log. You must ensure that git binary is available.' ) ; } $ date = new \ DateTime ( trim ( $ process -> getOutput ( ) ) ) ; $ date -> setTimezone ( new \ DateTimeZone ( 'UTC' ) ) ; return $ date -> format ( 'Y-m-d H:i:s' ) ; } | Get last commit date in repository . |
26,766 | public static function findGitRepository ( $ directory ) { $ process = new Process ( 'git rev-parse --show-toplevel' , $ directory ) ; $ process -> run ( ) ; if ( ! $ process -> isSuccessful ( ) ) { return false ; } $ rootPath = trim ( $ process -> getOutput ( ) ) ; return new Git ( $ rootPath ) ; } | Find a git repository . |
26,767 | public function getReferenceSoft ( $ repository , $ attr , $ key = 'id' ) { if ( isset ( $ this -> $ attr ) ) { return ( $ repository -> findSoft ( $ key , $ this -> $ attr ) ? : null ) ; } return null ; } | Retrieve a reference by foreign key ignoring soft - deleted entries . |
26,768 | public function setAmountMin ( float $ amountMin ) : self { $ this -> amountMin = ( int ) ( $ amountMin * self :: FACTOR_AMOUNT_MIN ) ; return $ this ; } | Sets the minimal amount of the product in the recipe . |
26,769 | public function setAmountMax ( float $ amountMax ) : self { $ this -> amountMax = ( int ) ( $ amountMax * self :: FACTOR_AMOUNT_MAX ) ; return $ this ; } | Sets the maximal amount of the product in the recipe . |
26,770 | public function setProbability ( float $ probability ) : self { $ this -> probability = ( int ) ( $ probability * self :: FACTOR_AMOUNT_PROBABILITY ) ; return $ this ; } | Sets the probability of the product in the recipe . |
26,771 | public static function setRevalidationTime ( string $ variableName = '_MF_SESSION_REVALIDATED_AT_' ) : bool { $ variableName = ( string ) $ variableName ; $ vHandler = Variables :: getInstance ( ) ; $ vHandler -> session -> set ( $ variableName , \ time ( ) ) ; return true ; } | Sets revalidation timestamp |
26,772 | public static function doesNeedRevalidation ( string $ variableName = '_MF_SESSION_REVALIDATED_AT_' ) : bool { static :: init ( ) ; $ variableName = ( string ) $ variableName ; $ vHandler = Variables :: getInstance ( ) ; $ validationTS = $ vHandler -> session -> get ( $ variableName , $ vHandler :: TYPE_INT ) ; return $ validationTS < \ time ( ) - static :: $ revalidationTime ? true : false ; } | Checks if session deas need revalidation |
26,773 | public static function setRevalidationCounter ( string $ variableName = '_MF_SESSION_REVALIDATION_COUNTER_' , int $ value = 0 ) : void { static :: init ( ) ; $ variableName = ( string ) $ variableName ; $ vHandler = Variables :: getInstance ( ) ; $ vHandler -> session -> set ( $ variableName , $ value ) ; } | Sets revalidation counter value |
26,774 | public static function increaseRevalidationCounter ( string $ variableName = '_MF_SESSION_REVALIDATION_COUNTER_' ) : void { static :: init ( ) ; $ variableName = ( string ) $ variableName ; $ vHandler = Variables :: getInstance ( ) ; $ vHandler -> session -> set ( $ variableName , $ vHandler -> session -> get ( $ variableName , Variables :: TYPE_INT ) + 1 ) ; } | Increases revalidation counter |
26,775 | public static function resetRevalidationCounter ( string $ variableName = '_MF_SESSION_REVALIDATION_COUNTER_' ) : void { static :: init ( ) ; $ variableName = ( string ) $ variableName ; $ vHandler = Variables :: getInstance ( ) ; if ( $ vHandler -> session -> get ( $ variableName , Variables :: TYPE_INT ) > 0 ) { $ vHandler -> session -> set ( $ variableName , 0 ) ; \ session_regenerate_id ( true ) ; } } | Resets revalidation counter & regenerates session id |
26,776 | public static function getPersonsByRole ( $ role = false ) { $ ccuc_status = CcucUserCompany :: CCUC_STATUS_SYS ; $ sys_ccmp_id = Yii :: app ( ) -> sysCompany -> getActiveCompany ( ) ; $ sql = " SELECT DISTINCT pprs_id, CONCAT( pprs_second_name, ' ', pprs_first_name ) full_name FROM AuthAssignment aa INNER JOIN `profiles` p ON aa.userid = p.user_id INNER JOIN pprs_person ON p.person_id = pprs_id INNER JOIN ccuc_user_company ON pprs_id = ccuc_person_id AND ccuc_ccmp_id = {$sys_ccmp_id} AND ccuc_status = '{$ccuc_status}' " ; $ where = '' ; if ( $ role && ! is_array ( $ role ) ) { $ where = " WHERE itemname = '{$role}' " ; } if ( $ role && is_array ( $ role ) ) { $ where = " WHERE itemname in ('" . implode ( "','" , $ role ) . "') " ; } $ sql .= $ where . " ORDER BY pprs_second_name,pprs_first_name " ; return Yii :: app ( ) -> db -> createCommand ( $ sql ) -> queryAll ( ) ; } | get users list by role roles or all |
26,777 | public static function translitStringToAscii ( $ str ) { $ LATV = array ( "ā", " Ā"," č ","Č " ,"ē" , "Ē", " ģ"," Ģ ","ī " ,"Ī" , "ķ", " Ķ"," ļ ","Ļ " ,"ņ" , "Ņ", " š"," Š ","ū " ,"Ū" , "ž", " Ž"," . ",'" ' ," ","- " ,"_" , "/" ) ; / / Latvi e šu g ari e un m $ LATIN = array ( "a" , "A" , "c" , "C" , "e" , "E" , "g" , "G" , "i" , "I" , "k" , "K" , "l" , "L" , "n" , "N" , "s" , "S" , "u" , "U" , "z" , "Z" , "" , "" , " " , "" , " " , " " ) ; return str_replace ( $ LATV , $ LATIN , $ str ) ; return $ str ; } | replace latvian special characters to latin characters |
26,778 | public function createUser ( ) { $ password = DbrLib :: rand_string ( 8 ) ; $ firstName = strtolower ( self :: translitStringToAscii ( $ this -> pprs_first_name ) ) ; $ secondName = strtolower ( self :: translitStringToAscii ( $ this -> pprs_second_name ) ) ; $ username = $ firstName . substr ( $ secondName , 0 , 1 ) ; $ i = 1 ; while ( User :: model ( ) -> findByAttributes ( [ 'username' => $ username ] ) ) { $ i ++ ; if ( $ i > strlen ( $ secondName ) ) { $ username = $ firstName . DbrLib :: rand_string ( 2 ) ; } $ username = $ firstName . substr ( $ secondName , 0 , $ i ) ; } $ contacts = $ this -> ppcnPersonContacts ; $ email = '' ; foreach ( $ contacts as $ contact ) { if ( $ contact -> ppcn_pcnt_type == PcntContactType :: TYPE_EMAIL ) { $ email = trim ( $ contact -> ppcn_value ) ; } } $ user = new User ( ) ; $ user -> username = $ username ; $ user -> password = $ password ; $ user -> email = $ email ; $ user -> status = User :: STATUS_ACTIVE ; if ( ! $ user -> validate ( ) ) { return CHtml :: errorSummary ( $ user ) ; } $ user -> save ( ) ; $ profile = new Profile ; $ profile -> user_id = $ user -> id ; $ profile -> first_name = $ this -> pprs_first_name ; $ profile -> last_name = $ this -> pprs_second_name ; $ profile -> sys_ccmp_id = Yii :: app ( ) -> sysCompany -> getActiveCompany ( ) ; $ profile -> person_id = $ this -> primaryKey ; $ profile -> save ( ) ; return true ; } | create user account from person data |
26,779 | public function guard ( $ loginRoute = null ) { $ base = Base :: instance ( ) ; $ currentPath = $ base [ 'PATH' ] ; $ this -> parseFirewalls ( ) ; if ( $ this -> firewalls [ 'pattern' ] && preg_match ( $ this -> firewalls [ 'pattern' ] , $ currentPath , $ matches ) ) { $ key = static :: pathName ( $ matches [ 'path' ] ) ; $ config = $ this -> firewalls [ 'paths' ] [ $ key ] ; if ( ! $ this -> isGranted ( $ config [ 'roles' ] ) ) { $ base -> reroute ( $ loginRoute ? : $ config [ 'login_route' ] ) ; } } return $ this ; } | Do guarding controller |
26,780 | public function isGranted ( $ roles ) { $ this -> parseRoles ( ) ; $ roles = ( array ) $ roles ; $ intersection = array_intersect ( $ roles , $ this -> roles ) ; return count ( $ intersection ) > 0 ; } | Check if user granted for roles |
26,781 | protected function parseFirewalls ( $ force = false ) { if ( null == $ this -> firewalls || $ force ) { $ firewalls = [ 'pattern' => null , 'paths' => [ ] ] ; $ pattern = '' ; foreach ( Base :: instance ( ) -> get ( 'SECURITY.firewalls' ) ? : [ ] as $ name => $ config ) { $ pattern .= ( $ pattern ? '|' : '' ) . $ config [ 'path' ] ; $ key = static :: pathName ( $ config [ 'path' ] ) ; $ firewalls [ 'paths' ] [ $ key ] = [ 'login_route' => $ config [ 'login_route' ] , 'roles' => $ config [ 'roles' ] , ] ; } if ( $ pattern ) { $ firewalls [ 'pattern' ] = '#(?<path>' . $ pattern . ')#' ; } $ this -> firewalls = $ firewalls ; } } | Parse firewalls from configuration |
26,782 | protected function parseRoles ( $ force = false ) { if ( null == $ this -> roles || $ force ) { $ user = UserManager :: instance ( ) -> getuser ( ) ; $ userRoles = $ user ? $ user -> getRoles ( ) : [ 'ROLE_ANONYMOUS' ] ; $ roleHierarchy = Base :: instance ( ) -> get ( 'SECURITY.role_hierarchy' ) ? : [ ] ; $ roles = [ ] ; foreach ( $ userRoles as $ role ) { $ roles = array_merge ( $ roles , [ $ role ] , $ this -> getHierarchy ( $ role , $ roleHierarchy ) ) ; } $ this -> roles = array_unique ( $ roles ) ; } } | Parse user roles |
26,783 | protected function getHierarchy ( $ role , array $ roleHierarchy ) { $ roles = [ ] ; if ( array_key_exists ( $ role , $ roleHierarchy ) ) { $ roleRoles = ( array ) $ roleHierarchy [ $ role ] ; foreach ( $ roleRoles as $ role ) { $ roles = array_merge ( $ roles , $ this -> getHierarchy ( $ role , $ roleHierarchy ) ) ; } $ roles = array_merge ( $ roles , $ roleRoles ) ; } return $ roles ; } | Get hierarchy for role |
26,784 | public function taxonomy_term_breadcrumbs ( $ term , $ taxonomy ) { $ term_breadcrumbs = array ( ) ; if ( ! empty ( $ term ) ) { $ term_obj = get_term ( $ term , $ taxonomy ) ; $ this -> add_breadcrumb ( $ term_breadcrumbs , array ( $ term_obj -> name , get_term_link ( $ term_obj , $ taxonomy ) ) ) ; if ( ! empty ( $ term_obj -> parent ) ) { $ parent_term_breadcrumbs = array ( ) ; $ parent_term_id = $ term_obj -> parent ; while ( $ parent_term_id ) { $ parent_term = get_term ( $ parent_term_id , $ taxonomy ) ; $ parent_term_id = $ parent_term -> parent ; $ parent_term_breadcrumbs [ ] = array ( $ parent_term -> name , get_term_link ( $ parent_term , $ taxonomy ) ) ; } $ this -> add_breadcrumbs_array ( $ term_breadcrumbs , $ parent_term_breadcrumbs ) ; } } $ term_breadcrumbs = apply_filters ( 'ctc_taxonomy_term_breadcrumbs' , $ term_breadcrumbs , $ term , $ taxonomy ) ; return $ term_breadcrumbs ; } | Get taxonomy term breadcrumbs |
26,785 | public function date_breadcrumbs ( $ base_url = false ) { $ date_breadcrumbs = array ( ) ; $ year = get_query_var ( 'year' ) ; if ( ! empty ( $ year ) ) { $ dateformatstring = _x ( 'Y' , 'breadcrumb year format' , 'church-theme-framework' ) ; if ( ! empty ( $ base_url ) ) { $ date_url = trailingslashit ( $ base_url ) . trailingslashit ( $ year ) ; } else { $ date_url = get_year_link ( $ year ) ; } $ this -> add_breadcrumb ( $ date_breadcrumbs , array ( date_i18n ( $ dateformatstring , mktime ( 0 , 0 , 0 , 1 , 1 , $ year ) ) , $ date_url ) ) ; $ month = get_query_var ( 'monthnum' ) ; if ( ! empty ( $ month ) ) { $ dateformatstring = _x ( 'F' , 'breadcrumb month format' , 'church-theme-framework' ) ; if ( ! empty ( $ base_url ) ) { $ date_url .= trailingslashit ( $ month ) ; } else { $ date_url = get_month_link ( $ year , $ month ) ; } $ this -> add_breadcrumb ( $ date_breadcrumbs , array ( date_i18n ( $ dateformatstring , mktime ( 0 , 0 , 0 , $ month , 1 , $ year ) ) , $ date_url ) ) ; $ day = get_query_var ( 'day' ) ; if ( ! empty ( $ day ) ) { $ dateformatstring = _x ( 'jS' , 'breadcrumb day format' , 'church-theme-framework' ) ; if ( ! empty ( $ base_url ) ) { $ date_url .= trailingslashit ( $ day ) ; } else { $ date_url = get_day_link ( $ year , $ month , $ day ) ; } $ this -> add_breadcrumb ( $ date_breadcrumbs , array ( date_i18n ( $ dateformatstring , mktime ( 0 , 0 , 0 , $ month , $ day , $ year ) ) , $ date_url ) ) ; } } } $ date_breadcrumbs = array_reverse ( $ date_breadcrumbs ) ; return apply_filters ( 'ctc_date_breadcrumbs' , $ date_breadcrumbs , $ base_url ) ; } | Get date breadcrumbs |
26,786 | private function buildJoins ( array $ joins ) { foreach ( $ joins as & $ join ) { foreach ( $ join [ 1 ] as & $ table ) { $ table = $ this -> escapeIdentifier ( $ table ) ; } $ join [ 1 ] = implode ( ', ' , array_filter ( $ join [ 1 ] ) ) ; if ( $ join [ 2 ] ) { $ join [ 2 ] = 'ON ' . $ join [ 2 ] ; } else { unset ( $ join [ 2 ] ) ; } foreach ( $ join [ 3 ] as & $ column ) { $ column = $ this -> escapeIdentifier ( $ column ) ; } $ join [ 3 ] = implode ( ', ' , array_filter ( $ join [ 3 ] ) ) ; if ( $ join [ 3 ] ) { $ join [ 3 ] = 'USING (' . $ join [ 3 ] . ')' ; } else { unset ( $ join [ 3 ] ) ; } $ join = implode ( ' ' , $ join ) ; } return implode ( ' ' , array_filter ( $ joins ) ) ; } | Builds a list of joins . |
26,787 | public function remove ( $ name , $ id ) { $ this -> client -> remove ( $ this -> capabilities -> get ( $ name ) -> getUrl ( ) . ( string ) $ id ) ; return $ this ; } | Delete a resource |
26,788 | public function getResources ( ) { $ keys = $ this -> capabilities -> keys ( ) ; $ definitions = [ ] ; foreach ( $ keys as $ key ) { $ definitions [ $ key ] = $ this -> capabilities -> get ( $ key ) ; } return $ definitions ; } | Return the list of resource definitions exposed via the capabilities route |
26,789 | protected function buildMessage ( EmailEntity $ email ) { $ attachments = json_decode ( $ email -> getAttachments ( ) , true ) ; $ recipientEmail = $ email -> getRecipientEmail ( ) ; $ to = [ [ 'email' => $ this -> filterThroughWhitelist ( $ recipientEmail ) , 'name' => $ email -> getRecipientName ( ) , 'type' => 'to' ] ] ; $ message = [ 'html' => $ email -> getMessage ( ) , 'subject' => $ email -> getSubject ( ) , 'from_email' => $ email -> getSenderEmail ( ) , 'from_name' => $ email -> getSenderName ( ) , 'to' => $ to , 'attachments' => $ attachments , 'headers' => json_decode ( $ email -> getHeaders ( ) , true ) , 'important' => false , 'track_opens' => true , 'track_clicks' => true , 'auto_text' => true , 'auto_html' => false , 'inline_css' => true , 'url_strip_qs' => null , 'preserve_recipients' => false , 'bcc_address' => $ email -> getBcc ( ) , 'merge' => true , ] ; return $ message ; } | Build Mandrill compatible message array from email entity |
26,790 | public function resolve ( $ value , $ default = 'value' ) { $ matches = [ ] ; if ( is_string ( $ value ) && preg_match ( '/^(' . self :: KEY_REGEX . ')' . preg_quote ( $ this -> separator ) . '(.*)/' , $ value , $ matches ) ) { if ( isset ( $ this -> filters [ $ matches [ 1 ] ] ) ) { return call_user_func_array ( $ this -> filters [ $ matches [ 1 ] ] , [ $ matches [ 2 ] ] ) ; } else if ( function_exists ( $ matches [ 1 ] ) ) { return call_user_func_array ( $ matches [ 1 ] , [ $ matches [ 2 ] ] ) ; } } return $ this -> fallback -> resolve ( $ value , $ default ) ; } | Attempts to resolve through defined filters |
26,791 | public function setFilter ( $ key , $ callable ) { if ( ! is_callable ( $ callable ) ) { throw new InvalidArgumentException ( 'Invalid callable for filter: "' . $ key . '"' ) ; } if ( ! preg_match ( '/^' . self :: KEY_REGEX . '$/' , $ key ) ) { throw new InvalidArgumentException ( 'Invalid name for filter: "' . $ key . '". The filter name can only contain alphanumeric characters and underscore.' ) ; } $ this -> filters [ $ key ] = $ callable ; return $ this ; } | Map a filter to a callable |
26,792 | public function add_element ( $ url , $ name , $ active = true , $ class = '' , $ children = array ( ) ) { $ this -> elements [ ] = ( object ) array ( 'url' => $ url , 'name' => $ name , 'active' => $ active , 'class' => $ class , 'children' => $ children , ) ; } | Add breadcrumb element into array . |
26,793 | public function draw ( ) { $ bRouter = \ Application \ BRouter :: getInstance ( ) ; $ template = $ bRouter -> templatename ; $ suffix = \ Brilliant \ HTTP \ BBrowserUseragent :: getDeviceSuffix ( ) ; $ fn = BTEMPLATESPATH . $ template . DIRECTORY_SEPARATOR . 'breadcrumbs' . $ suffix . '.php' ; if ( ! file_exists ( $ fn ) ) { $ fn = BTEMPLATESPATH . $ template . DIRECTORY_SEPARATOR . 'breadcrumbs.d.php' ; } if ( ! file_exists ( $ fn ) ) { $ fn = BTEMPLATESPATH . 'default' . DIRECTORY_SEPARATOR . 'breadcrumbs' . $ suffix . '.php' ; } if ( ! file_exists ( $ fn ) ) { $ fn = BTEMPLATESPATH . 'default' . DIRECTORY_SEPARATOR . 'breadcrumbs.d.php' ; } if ( ! file_exists ( $ fn ) ) { return '' ; } include ( $ fn ) ; } | Draw breadcrumbs HTML |
26,794 | public function getHtmlWidth ( ) { if ( is_string ( $ this -> width ) && $ this -> width === self :: WIDTH_AUTO ) { return '' ; } else if ( intval ( $ this -> width ) > 0 ) { return $ this -> width . '%' ; } return $ this -> width ; } | Returns the correct with for the html attribute |
26,795 | public function parse ( $ commentString , $ target ) { $ commentString = $ this -> stripCommentDecoration ( $ commentString ) ; $ parts = preg_split ( '/^\s*(?=@[a-zA-Z]+)/m' , $ commentString , 2 ) ; $ comment = new Comment ( trim ( $ parts [ 0 ] ) ) ; if ( ! isset ( $ parts [ 1 ] ) ) { return $ comment ; } $ trimmed = trim ( $ parts [ 1 ] ) ; if ( empty ( $ trimmed ) ) { return $ comment ; } $ pattern = '/(\'(?:\\\\.|[^\'\\\\])*\'|"(?:\\\\.|[^"\\\\])*"|[@(),={}]|\s+|(?<![:])[:](?![:]))/' ; $ flags = PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY ; $ this -> parts = preg_split ( $ pattern , $ parts [ 1 ] , - 1 , $ flags ) ; $ this -> position = - 1 ; while ( isset ( $ this -> parts [ ++ $ this -> position ] ) ) { if ( $ this -> parts [ $ this -> position ] === '@' ) { list ( $ name , $ parameters , $ isClass ) = $ this -> parseTag ( ) ; if ( $ isClass ) { $ className = $ this -> getFullyQualifiedName ( $ name ) ; $ this -> saveState ( ) ; $ comment -> addAnnotation ( $ className , $ this -> container -> readClass ( $ className , $ parameters , $ target ) ) ; $ this -> restoreState ( ) ; } else { $ comment -> add ( $ name , $ parameters ) ; } } } return $ comment ; } | Parses a documentation comment . |
26,796 | public function getDistance ( $ lat1 , $ lgn1 , $ lat2 , $ lgn2 ) { $ earth_radius = 6371 ; $ alpha = $ lat1 - $ lat2 ; $ beta = $ lgn1 - $ lgn2 ; $ h = pow ( ( sin ( deg2rad ( $ alpha / 2 ) ) ) , 2 ) + cos ( deg2rad ( $ lat1 ) ) * cos ( deg2rad ( $ lat2 ) ) * pow ( sin ( deg2rad ( $ beta / 2 ) ) , 2 ) ; $ dist = 2 * $ earth_radius * sqrt ( $ h ) ; return $ dist ; } | Get distance between two lat and lng |
26,797 | public function hourRange ( $ openingTime , $ closingTime ) { $ time1 = strtotime ( $ openingTime ) ; $ time2 = strtotime ( $ closingTime ) ; return round ( abs ( $ time2 - $ time1 ) / 3600 , 2 ) ; } | Get difference of hours between hours |
26,798 | public static function array2attrs ( $ assoc ) { $ attrs = [ ] ; foreach ( ( array ) $ assoc as $ key => $ value ) { $ attrs [ ] = is_string ( $ key ) ? "$key='$value'" : trim ( $ value ) ; } return implode ( ' ' , $ attrs ) ; } | Get array and make attributes string |
26,799 | public function __tostring ( ) { if ( ! $ this -> label ) $ this -> label = $ this -> name ; $ errors = [ ] ; foreach ( ( array ) $ this -> errors as $ error ) { $ errors [ ] = $ this -> renderError ( $ error ) ; } $ this -> errors = implode ( '' , $ errors ) ; $ this -> prepare ( ) ; $ this -> attributes = static :: array2attrs ( $ this -> attributes ) ; return $ this -> renderField ( ) ; } | Prepare some config and render element |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.