Dataset Viewer
Auto-converted to Parquet Duplicate
idx
int64
0
60.3k
question
stringlengths
92
4.62k
target
stringlengths
7
635
0
private function traceCLI ( array $ trace , $ label ) { foreach ( $ trace as $ k => $ v ) { $ func = $ loc = $ line = '' ; $ argsPresent = isset ( $ v [ 'args' ] ) && ! empty ( $ v [ 'args' ] ) ; self :: formatTraceLine ( $ v , $ func , $ loc , $ line ) ; $ this -> console -> write ( '<' . $ label . 'b>#' . $ k . ': </>' ) -> write ( '<' . $ label . '>' . ( $ loc ? $ loc : '<<unknown file>>' ) . '</> ' ) -> write ( '<' . $ label . '>(' . ( $ line ? 'line ' . $ line : 'unknown line' ) . ')</>' ) -> write ( '<' . $ label . '> | </>' ) -> write ( '<' . $ label . '>' . $ func . '</>' , true ) ; if ( $ argsPresent ) { $ this -> console -> write ( '<' . $ label . 'b>Arguments:</>' , true ) ; VarDumper :: dump ( $ v [ 'args' ] ) ; } $ this -> console -> writeln ( '' ) ; } }
CLI output of the debug backtrace
1
private static function formatTraceLine ( array $ traceLine , & $ method , & $ file , & $ line ) { $ method = $ file = $ line = '' ; if ( isset ( $ traceLine [ 'class' ] ) ) { $ method = $ traceLine [ 'class' ] ; } if ( isset ( $ traceLine [ 'type' ] ) ) { $ method .= $ traceLine [ 'type' ] ; } if ( isset ( $ traceLine [ 'function' ] ) ) { $ method .= $ traceLine [ 'function' ] . '()' ; } if ( ! $ method ) { $ method = '[unknown]' ; } if ( isset ( $ traceLine [ 'file' ] ) ) { $ file = '[...]' . implode ( DIRECTORY_SEPARATOR , array_slice ( explode ( DIRECTORY_SEPARATOR , $ traceLine [ 'file' ] ) , - 4 ) ) ; } if ( array_key_exists ( 'line' , $ traceLine ) ) { $ line = $ traceLine [ 'line' ] ; } }
Formats the debug backtrace row
2
private function traceHTML ( array $ trace ) { ?> <table class="table" border="1"> <thead> <tr> <th>#</th> <th>Method</th> <th>Args</th> <th>File</th> <th>Line</th> </tr> </thead> <tbody> <?php foreach ( $ trace as $ k => $ v ) { $ func = $ loc = $ line = '' ; self :: formatTraceLine ( $ v , $ func , $ loc , $ line ) ; if ( isset ( $ v [ 'args' ] ) && ! empty ( $ v [ 'args' ] ) ) { $ args = Dump :: html ( $ v [ 'args' ] ) ; } else { $ args = '<span class="label label-default">[none]</span>' ; } ?> <tr> <td> <?= $ k ?> </td> <td> <?= $ func ?> </td> <td class="text-center"> <?= $ args ?> </td> <td> <?= $ loc ? $ loc : '<span class="label label-default">???</label>' ?> </td> <td> <?= ( $ line == 0 || trim ( $ line ) ) ? $ line : '<span class="label label-default">???</span>' ?> </td> </tr> <?php } ?> </tbody> </table> <?php }
Echoes a HTML debug backtrace
3
public static function isValid ( string $ mediaType ) : bool { return ( bool ) preg_match ( self :: REGEX , trim ( $ mediaType ) ) ; }
Checks if the given string is a valid media type .
4
public static function fromExtension ( string $ extension ) : MediaType { if ( ! self :: isKnownExtension ( $ extension ) ) { throw new \ InvalidArgumentException ( sprintf ( 'Unknown extension "%s" given.' , $ extension ) ) ; } return new self ( self :: $ knownTypes [ strtolower ( $ extension ) ] ) ; }
Constructs a new media type object from the given extension .
5
private static function isCommandAvailable ( string $ command ) : bool { if ( ! is_callable ( 'shell_exec' ) || stripos ( ini_get ( 'disable_functions' ) , 'shell_exec' ) !== false ) { return false ; } $ result = null ; if ( strtoupper ( substr ( PHP_OS , 0 , 3 ) ) != 'WIN' ) { $ result = @ shell_exec ( 'which ' . $ command ) ; } return ! empty ( $ result ) ; }
Checks if the given command is callable on the command line .
6
private static function guessFromFileCommand ( string $ filename ) : string { $ result = 'application/octet-stream' ; if ( ! self :: isCommandAvailable ( 'file' ) ) { return $ result ; } $ info = trim ( shell_exec ( 'file -bi ' . escapeshellarg ( $ filename ) ) ) ; return $ info != '' ? $ info : $ result ; }
Uses the unix file command to guess the media type .
7
private static function guessFromFinfo ( string $ filename ) : string { $ result = 'application/octet-stream' ; if ( ! function_exists ( 'finfo_file' ) ) { return $ result ; } $ handle = finfo_open ( FILEINFO_MIME ) ; if ( $ handle === false ) { return $ result ; } $ info = finfo_file ( $ handle , $ filename ) ; finfo_close ( $ handle ) ; return $ info !== false ? $ info : $ result ; }
Uses finfo_file to guess the media type .
8
public static function fromFile ( string $ filename , bool $ allowGuessByExtension ) : MediaType { $ result = 'application/octet-stream' ; if ( ! @ is_file ( $ filename ) || ! @ is_readable ( $ filename ) ) { return new self ( $ result ) ; } $ result = self :: guessFromFinfo ( $ filename ) ; if ( self :: isFallback ( $ result ) ) { $ result = self :: guessFromFileCommand ( $ filename ) ; } if ( $ allowGuessByExtension && self :: isFallback ( $ result ) ) { $ extension = pathinfo ( $ filename , PATHINFO_EXTENSION ) ; if ( self :: isKnownExtension ( $ extension ) ) { return self :: fromExtension ( $ extension ) ; } } $ result = str_replace ( [ 'charset=binary' , 'charset=us-ascii' ] , [ '' , '' ] , strtolower ( $ result ) ) ; $ result = rtrim ( $ result , '; ' ) ; return new self ( $ result ) ; }
Constructs a new media type object for the given file name .
9
protected function getOutputResponse ( ServerRequestInterface $ request , ResponseInterface $ response ) : ResponseInterface { ob_start ( ) ; switch ( $ this -> determineOutputType ( ) ) { case self :: TYPE_JSON : $ this -> renderJSON ( $ request , $ response ) ; break ; case self :: TYPE_XML : $ this -> renderXML ( $ request , $ response ) ; break ; case self :: TYPE_PLAIN : $ this -> renderPlainText ( $ request , $ response ) ; break ; default : $ this -> renderHTML ( $ request , $ response ) ; break ; } $ output = ob_get_clean ( ) ; $ body = new RequestBody ( ) ; $ body -> write ( $ output ) ; return $ response -> withStatus ( 404 ) -> withBody ( $ body ) ; }
Getting Output For Response
10
protected function setupRootNode ( ) { $ builder = new TreeBuilder ( ) ; $ this -> rootNode = $ builder -> root ( $ this -> getBundleName ( ) ) ; return $ this ; }
Sets up the root node of TreeBuilder .
11
protected function init ( ) { global $ wpdb ; $ this -> wpdb = $ wpdb ; $ this -> queryGrammar = new MySqlGrammar ( ) ; $ this -> postProcessor = new MySqlProcessor ( ) ; }
Method to be started
12
protected function getOrCreateType ( Index $ index , $ typeName ) { Assertion :: minLength ( $ typeName , 1 , 'Type name must be at least one char long' ) ; if ( ! empty ( $ this -> types [ $ index -> getName ( ) ] [ $ typeName ] ) ) { return $ this -> types [ $ index -> getName ( ) ] [ $ typeName ] ; } if ( ! $ this -> typeExists ( $ index , $ typeName ) ) { $ this -> createType ( $ index , $ typeName ) ; } return $ this -> types [ $ index -> getName ( ) ] [ $ typeName ] = $ index -> getType ( $ typeName ) ; }
Returns a elastic search type for specified index and type name .
13
protected function typeExists ( Index $ index , $ typeName ) { Assertion :: minLength ( $ typeName , 1 , 'Type name must be at least one char long' ) ; $ mapping = $ index -> getMapping ( ) ; return ! empty ( $ mapping [ $ index -> getName ( ) ] [ $ typeName ] ) ; }
Returns true if specified type exists in the index false otherwise .
14
protected function createType ( Index $ index , $ typeName ) { Assertion :: minLength ( $ typeName , 1 , 'Type name must be at least one char long' ) ; $ type = $ index -> getType ( $ typeName ) ; $ options = $ this -> mergeDefaultOptions ( ) ; $ mappingObject = new Mapping ( ) ; if ( ! empty ( $ options [ 'mapping' ] ) ) { $ mappingObject -> setProperties ( $ options [ 'mapping' ] ) ; } if ( ! empty ( $ options [ '_source' ] ) ) { $ mappingObject -> setSource ( $ options [ '_source' ] ) ; } if ( ! empty ( $ options [ 'mapping' ] ) || ! empty ( $ options [ '_source' ] ) ) { $ type -> setMapping ( $ mappingObject ) ; } }
Creates a new type with specified name in specified index .
15
public function getIndex ( $ indexName , array $ indexOptions = array ( ) , $ specials = null ) { $ indexName = strtolower ( $ indexName ) ; if ( empty ( $ this -> indexes [ $ indexName ] ) ) { $ client = $ this -> getClient ( ) ; $ this -> indexes [ $ indexName ] = $ client -> getIndex ( $ indexName ) ; if ( ! $ this -> indexes [ $ indexName ] -> exists ( ) ) { $ this -> indexes [ $ indexName ] -> create ( $ this -> mergeDefaultOptions ( $ indexOptions ) , $ specials ) ; } } return $ this -> indexes [ $ indexName ] ; }
Provides an elasticsearch index to attach documents to .
16
protected function transcodeDataToDocument ( $ document , $ identifier ) { if ( ! $ document instanceof Document ) { if ( is_object ( $ document ) ) { if ( get_class ( $ document ) == 'stdClass' ) { $ document = ( array ) $ document ; } else { if ( $ document instanceof \ JsonSerializable ) { $ document = json_encode ( $ document ) ; } elseif ( method_exists ( $ document , 'toArray' ) ) { $ document = $ document -> toArray ( ) ; } else { throw new \ LogicException ( 'The given object representing a document value eihter have to implement the JsonSerializable' . 'interface or a toArray() method in order to be stored it in elasticsearch.' , AdaptorException :: DATA_UNSERIALIZABLE ) ; } } } $ document = $ this -> decorator -> normalizeValue ( $ document ) ; Assertion :: notEmpty ( $ document , 'The document data may not be empty.' ) ; $ document = new Document ( $ identifier , $ document ) ; } return $ document ; }
Makes sure that the given data is an Elastica \ Document
17
public function removeDocuments ( array $ ids , $ index , $ type = '' ) { if ( empty ( $ type ) ) { $ type = $ this -> typeName ; } $ client = $ this -> getClient ( ) ; $ index = $ client -> getIndex ( $ index ) ; $ client -> deleteIds ( $ ids , $ index , $ type ) ; $ index -> refresh ( ) ; }
Removes a document from the index .
18
public function updateDocument ( $ id , $ data , $ indexName , $ typeName = '' ) { $ index = $ this -> getIndex ( $ indexName ) ; $ client = $ index -> getClient ( ) ; $ type = $ index -> getType ( empty ( $ typeName ) ? $ this -> typeName : $ typeName ) ; $ rawData = array ( 'doc' => $ this -> decorator -> normalizeValue ( $ data ) ) ; $ response = $ client -> updateDocument ( $ id , $ rawData , $ index -> getName ( ) , $ type -> getName ( ) ) ; if ( $ response -> hasError ( ) ) { $ error = $ this -> normalizeError ( $ response -> getError ( ) ) ; throw new AdaptorException ( $ error -> getMessage ( ) , $ error -> getCode ( ) , $ error ) ; } $ type -> getIndex ( ) -> refresh ( ) ; return $ type -> getDocument ( $ id ) ; }
Updates a elsaticsearch document .
19
public function normalizeError ( $ error ) { if ( $ error instanceof \ Exception ) { return new AdaptorException ( $ error -> getMessage ( ) , $ error -> getCode ( ) , $ error ) ; } return new AdaptorException ( sprintf ( 'An error accord: %s' , print_r ( $ error , true ) ) , AdaptorException :: UNKNOWN_ERROR ) ; }
determines if the risen error is of type Exception .
20
public function getDocument ( $ id , $ indexName , $ typeName = '' ) { $ index = $ this -> getIndex ( $ indexName ) ; $ type = $ index -> getType ( empty ( $ typeName ) ? $ this -> typeName : $ typeName ) ; $ data = $ this -> decorator -> denormalizeValue ( array ( $ id => $ type -> getDocument ( $ id ) -> getData ( ) ) ) ; return $ data [ $ id ] ; }
Fetches the requested document from the index .
21
public function getDocuments ( $ index , $ limit = 10 ) { Assertion :: isInstanceOf ( $ index , '\Elastica\Index' , 'The given index must be of type \Elastica\Index !' ) ; if ( empty ( $ limit ) ) { $ limit = self :: ALL_DOCUMENTS ; } $ search = new Search ( $ index -> getClient ( ) ) ; $ search -> addIndex ( $ index ) ; $ query = new Query ( new MatchAll ( ) ) ; $ query -> setSize ( $ limit ) ; $ resultSet = $ search -> search ( $ query ) ; $ results = $ resultSet -> getResults ( ) ; return $ this -> decorator -> denormalizeValue ( $ this -> extractData ( $ results ) ) ; }
Provides a list of all documents of the given index .
22
protected function extractData ( array $ data ) { $ converted = array ( ) ; foreach ( $ data as $ value ) { if ( $ value instanceof Result ) { $ converted [ $ value -> getId ( ) ] = $ value -> getData ( ) ; } } return $ converted ; }
Extracts information from a nested result set .
23
public function deleteIndex ( $ name ) { $ client = $ this -> getClient ( ) ; $ index = $ client -> getIndex ( $ name ) ; $ index -> close ( ) ; $ index -> delete ( ) ; }
Deletes the named index from the cluster .
24
public function deleteType ( $ indexName , $ typeName ) { $ client = $ this -> getClient ( ) ; $ index = $ client -> getIndex ( $ indexName ) ; $ type = $ index -> getType ( $ typeName ) ; return $ type -> delete ( ) ; }
Deletes the named type from a named index from the cluster .
25
public function getTypeCount ( $ indexName , $ typeName , $ query = '' ) { $ index = $ this -> getIndex ( $ indexName ) ; $ type = $ index -> getType ( $ typeName ) ; return $ type -> count ( $ query ) ; }
Does a count query on given type and index .
26
public function getTypeMapping ( $ indexName , $ typeName ) { $ index = $ this -> getIndex ( $ indexName ) ; $ type = $ index -> getType ( $ typeName ) ; return $ type -> getMapping ( ) ; }
Returns current mapping for the given type and index .
27
public function render ( \ Throwable $ e ) { list ( $ file , $ line ) = Util :: caller ( 0 ) ; $ title = 'CharcoalPHP: Exception List' ; if ( $ this -> clear_buffer ) { ob_clean ( ) ; } echo $ this -> _output ( $ e , $ title , $ file , $ line ) ; }
Render debug trace
28
public function getVideoFeed ( $ location = null ) { if ( $ location == null ) { $ uri = self :: VIDEO_URI ; } else if ( $ location instanceof Zend_Gdata_Query ) { $ uri = $ location -> getQueryUrl ( $ this -> getMajorProtocolVersion ( ) ) ; } else { $ uri = $ location ; } return parent :: getFeed ( $ uri , 'Zend_Gdata_YouTube_VideoFeed' ) ; }
Retrieves a feed of videos .
29
public function getVideoEntry ( $ videoId = null , $ location = null , $ fullEntry = false ) { if ( $ videoId !== null ) { if ( $ fullEntry ) { return $ this -> getFullVideoEntry ( $ videoId ) ; } else { $ uri = self :: VIDEO_URI . "/" . $ videoId ; } } else if ( $ location instanceof Zend_Gdata_Query ) { $ uri = $ location -> getQueryUrl ( $ this -> getMajorProtocolVersion ( ) ) ; } else { $ uri = $ location ; } return parent :: getEntry ( $ uri , 'Zend_Gdata_YouTube_VideoEntry' ) ; }
Retrieves a specific video entry .
30
public function getFullVideoEntry ( $ videoId ) { $ uri = self :: USER_URI . "/default/" . self :: UPLOADS_URI_SUFFIX . "/$videoId" ; return parent :: getEntry ( $ uri , 'Zend_Gdata_YouTube_VideoEntry' ) ; }
Retrieves a video entry from the user s upload feed .
31
public function getMostViewedVideoFeed ( $ location = null ) { $ standardFeedUri = self :: STANDARD_MOST_VIEWED_URI ; if ( $ this -> getMajorProtocolVersion ( ) == 2 ) { $ standardFeedUri = self :: STANDARD_MOST_VIEWED_URI_V2 ; } if ( $ location == null ) { $ uri = $ standardFeedUri ; } else if ( $ location instanceof Zend_Gdata_Query ) { if ( $ location instanceof Zend_Gdata_YouTube_VideoQuery ) { if ( ! isset ( $ location -> url ) ) { $ location -> setFeedType ( 'most viewed' ) ; } } $ uri = $ location -> getQueryUrl ( $ this -> getMajorProtocolVersion ( ) ) ; } else { $ uri = $ location ; } return parent :: getFeed ( $ uri , 'Zend_Gdata_YouTube_VideoFeed' ) ; }
Retrieves a feed of the most viewed videos .
32
public function getRecentlyFeaturedVideoFeed ( $ location = null ) { $ standardFeedUri = self :: STANDARD_RECENTLY_FEATURED_URI ; if ( $ this -> getMajorProtocolVersion ( ) == 2 ) { $ standardFeedUri = self :: STANDARD_RECENTLY_FEATURED_URI_V2 ; } if ( $ location == null ) { $ uri = $ standardFeedUri ; } else if ( $ location instanceof Zend_Gdata_Query ) { if ( $ location instanceof Zend_Gdata_YouTube_VideoQuery ) { if ( ! isset ( $ location -> url ) ) { $ location -> setFeedType ( 'recently featured' ) ; } } $ uri = $ location -> getQueryUrl ( $ this -> getMajorProtocolVersion ( ) ) ; } else { $ uri = $ location ; } return parent :: getFeed ( $ uri , 'Zend_Gdata_YouTube_VideoFeed' ) ; }
Retrieves a feed of recently featured videos .
33
public function getPlaylistListFeed ( $ user = null , $ location = null ) { if ( $ user !== null ) { $ uri = self :: USER_URI . '/' . $ user . '/playlists' ; } else if ( $ location instanceof Zend_Gdata_Query ) { $ uri = $ location -> getQueryUrl ( $ this -> getMajorProtocolVersion ( ) ) ; } else { $ uri = $ location ; } return parent :: getFeed ( $ uri , 'Zend_Gdata_YouTube_PlaylistListFeed' ) ; }
Retrieves a feed which lists a user s playlist
34
public function getPlaylistVideoFeed ( $ location ) { if ( $ location instanceof Zend_Gdata_Query ) { $ uri = $ location -> getQueryUrl ( $ this -> getMajorProtocolVersion ( ) ) ; } else { $ uri = $ location ; } return parent :: getFeed ( $ uri , 'Zend_Gdata_YouTube_PlaylistVideoFeed' ) ; }
Retrieves a feed of videos in a particular playlist
35
public function getUserProfile ( $ user = null , $ location = null ) { if ( $ user !== null ) { $ uri = self :: USER_URI . '/' . $ user ; } else if ( $ location instanceof Zend_Gdata_Query ) { $ uri = $ location -> getQueryUrl ( $ this -> getMajorProtocolVersion ( ) ) ; } else { $ uri = $ location ; } return parent :: getEntry ( $ uri , 'Zend_Gdata_YouTube_UserProfileEntry' ) ; }
Retrieves a user s profile as an entry
36
public static function parseFormUploadTokenResponse ( $ response ) { @ ini_set ( 'track_errors' , 1 ) ; $ doc = new DOMDocument ( ) ; $ doc = @ Zend_Xml_Security :: scan ( $ response , $ doc ) ; @ ini_restore ( 'track_errors' ) ; if ( ! $ doc ) { require_once 'Zend/Gdata/App/Exception.php' ; throw new Zend_Gdata_App_Exception ( "Zend_Gdata_YouTube::parseFormUploadTokenResponse - " . "DOMDocument cannot parse XML: $php_errormsg" ) ; } $ responseElement = $ doc -> getElementsByTagName ( 'response' ) -> item ( 0 ) ; $ urlText = null ; $ tokenText = null ; if ( $ responseElement != null ) { $ urlElement = $ responseElement -> getElementsByTagName ( 'url' ) -> item ( 0 ) ; $ tokenElement = $ responseElement -> getElementsByTagName ( 'token' ) -> item ( 0 ) ; if ( $ urlElement && $ urlElement -> hasChildNodes ( ) && $ tokenElement && $ tokenElement -> hasChildNodes ( ) ) { $ urlText = $ urlElement -> firstChild -> nodeValue ; $ tokenText = $ tokenElement -> firstChild -> nodeValue ; } } if ( $ tokenText != null && $ urlText != null ) { return array ( 'token' => $ tokenText , 'url' => $ urlText ) ; } else { require_once 'Zend/Gdata/App/Exception.php' ; throw new Zend_Gdata_App_Exception ( 'Form upload token not found in response' ) ; } }
Helper function for parsing a YouTube token response
37
public function getFormUploadToken ( $ videoEntry , $ url = 'https://gdata.youtube.com/action/GetUploadToken' ) { if ( $ url != null && is_string ( $ url ) ) { $ response = $ this -> post ( $ videoEntry , $ url ) ; return self :: parseFormUploadTokenResponse ( $ response -> getBody ( ) ) ; } else { require_once 'Zend/Gdata/App/Exception.php' ; throw new Zend_Gdata_App_Exception ( 'Url must be provided as a string URL' ) ; } }
Retrieves a YouTube token
38
public function getActivityForUser ( $ username ) { if ( $ this -> getMajorProtocolVersion ( ) == 1 ) { require_once 'Zend/Gdata/App/VersionException.php' ; throw new Zend_Gdata_App_VersionException ( 'User activity feeds ' . 'are not available in API version 1.' ) ; } $ uri = null ; if ( $ username instanceof Zend_Gdata_Query ) { $ uri = $ username -> getQueryUrl ( $ this -> getMajorProtocolVersion ( ) ) ; } else { if ( count ( explode ( ',' , $ username ) ) > self :: ACTIVITY_FEED_MAX_USERS ) { require_once 'Zend/Gdata/App/InvalidArgumentException.php' ; throw new Zend_Gdata_App_InvalidArgumentException ( 'Activity feed can only retrieve for activity for up to ' . self :: ACTIVITY_FEED_MAX_USERS . ' users per request' ) ; } $ uri = self :: ACTIVITY_FEED_URI . '?author=' . $ username ; } return parent :: getFeed ( $ uri , 'Zend_Gdata_YouTube_ActivityFeed' ) ; }
Retrieves the activity feed for users
39
public function sendVideoMessage ( $ body , $ videoEntry = null , $ videoId = null , $ recipientUserName ) { if ( ! $ videoId && ! $ videoEntry ) { require_once 'Zend/Gdata/App/InvalidArgumentException.php' ; throw new Zend_Gdata_App_InvalidArgumentException ( 'Expecting either a valid videoID or a videoEntry object in ' . 'Zend_Gdata_YouTube->sendVideoMessage().' ) ; } $ messageEntry = new Zend_Gdata_YouTube_InboxEntry ( ) ; if ( $ this -> getMajorProtocolVersion ( ) == null || $ this -> getMajorProtocolVersion ( ) == 1 ) { if ( ! $ videoId ) { $ videoId = $ videoEntry -> getVideoId ( ) ; } elseif ( strlen ( $ videoId ) < 12 ) { $ videoId = self :: VIDEO_URI . '/' . $ videoId ; } $ messageEntry -> setId ( $ this -> newId ( $ videoId ) ) ; $ messageEntry -> setDescription ( new Zend_Gdata_YouTube_Extension_Description ( $ body ) ) ; } else { if ( ! $ videoId ) { $ videoId = $ videoEntry -> getVideoId ( ) ; $ videoId = substr ( $ videoId , strrpos ( $ videoId , ':' ) ) ; } $ messageEntry -> setId ( $ this -> newId ( $ videoId ) ) ; $ messageEntry -> setSummary ( $ this -> newSummary ( $ body ) ) ; } $ insertUrl = 'https://gdata.youtube.com/feeds/api/users/' . $ recipientUserName . '/inbox' ; $ response = $ this -> insertEntry ( $ messageEntry , $ insertUrl , 'Zend_Gdata_YouTube_InboxEntry' ) ; return $ response ; }
Send a video message .
40
public function replyToCommentEntry ( $ commentEntry , $ commentText ) { $ newComment = $ this -> newCommentEntry ( ) ; $ newComment -> content = $ this -> newContent ( ) -> setText ( $ commentText ) ; $ commentId = $ commentEntry -> getId ( ) ; $ commentIdArray = explode ( ':' , $ commentId ) ; $ inReplyToLinkHref = self :: VIDEO_URI . '/' . $ commentIdArray [ 3 ] . '/comments/' . $ commentIdArray [ 5 ] ; $ inReplyToLink = $ this -> newLink ( $ inReplyToLinkHref , self :: IN_REPLY_TO_SCHEME , $ type = "application/atom+xml" ) ; $ links = $ newComment -> getLink ( ) ; $ links [ ] = $ inReplyToLink ; $ newComment -> setLink ( $ links ) ; $ commentFeedPostUrl = self :: VIDEO_URI . '/' . $ commentIdArray [ 3 ] . '/comments' ; return $ this -> insertEntry ( $ newComment , $ commentFeedPostUrl , 'Zend_Gdata_YouTube_CommentEntry' ) ; }
Post a comment in reply to an existing comment
41
protected function signRequest ( HttpRequest $ request , $ username , $ timestamp , $ secretKey ) { $ message = $ username . $ timestamp . $ this -> getRequestMessage ( $ request ) ; return $ this -> algorithm -> sign ( $ message , $ secretKey ) ; }
Create request signature
42
public function regenerate ( ) { $ this -> guid = self :: make ( $ this -> lowerCase , $ this -> wrap ) ; return $ this ; }
Regenerated Guid value
43
public static function make ( $ lowerCase = true , $ wrap = false ) { $ charid = strtoupper ( md5 ( uniqid ( rand ( ) , true ) ) ) ; $ hyphen = chr ( 45 ) ; $ uuid = ( $ wrap ? "{" : "" ) . substr ( $ charid , 0 , 8 ) . $ hyphen . substr ( $ charid , 8 , 4 ) . $ hyphen . substr ( $ charid , 12 , 4 ) . $ hyphen . substr ( $ charid , 16 , 4 ) . $ hyphen . substr ( $ charid , 20 , 12 ) . ( $ wrap ? "}" : "" ) ; return $ lowerCase ? strtolower ( $ uuid ) : $ uuid ; }
Generates guid string
44
public function getElapsedTime ( $ format = false ) { $ elapsed = microtime ( true ) - $ this -> startTime ; if ( $ format && $ elapsed >= 1 ) { $ elapsed = gmdate ( "H:i:s" , $ elapsed ) ; } return $ elapsed ; }
Gets the total time elapsed since the timer started .
45
public function setOptions ( array $ options ) { foreach ( $ options as $ index => $ val ) { if ( property_exists ( $ this , $ index ) ) { $ this -> { $ index } = $ val ; } } return $ this ; }
Set the object options like property = > value
46
protected function _buildClassesNames ( $ names , array $ masks ) { if ( ! is_array ( $ names ) ) { $ names = array ( $ names ) ; } $ return_names = array ( ) ; foreach ( $ names as $ _name ) { foreach ( $ masks as $ _mask ) { $ return_names [ ] = sprintf ( $ _mask , TextHelper :: toCamelCase ( $ _name ) ) ; } } return $ return_names ; }
Build the class name filling a set of masks
47
protected function _addNamespaces ( $ names , array $ namespaces , array & $ logs = array ( ) ) { if ( ! is_array ( $ names ) ) { $ names = array ( $ names ) ; } $ return_names = array ( ) ; foreach ( $ names as $ _name ) { foreach ( $ namespaces as $ _namespace ) { if ( CodeHelper :: namespaceExists ( $ _namespace ) ) { $ tmp_namespace = rtrim ( TextHelper :: toCamelCase ( $ _namespace ) , '\\' ) . '\\' ; $ return_names [ ] = $ tmp_namespace . str_replace ( $ tmp_namespace , '' , TextHelper :: toCamelCase ( $ _name ) ) ; } else { $ logs [ ] = $ this -> _getErrorMessage ( 'Namespace "%s" not found!' , $ _namespace ) ; } } } return $ return_names ; }
Add a set of namespaces to a list of class names
48
protected function _classesImplements ( $ names , array $ interfaces , $ must_implement_all = false , array & $ logs = array ( ) ) { if ( ! is_array ( $ names ) ) { $ names = array ( $ names ) ; } $ ok = false ; foreach ( $ names as $ _name ) { foreach ( $ interfaces as $ _interface ) { if ( interface_exists ( $ _interface ) ) { if ( CodeHelper :: impelementsInterface ( $ _name , $ _interface ) ) { $ ok = true ; } elseif ( $ must_implement_all ) { $ ok = false ; } } else { $ logs [ ] = $ this -> _getErrorMessage ( 'Interface "%s" not found!' , $ _interface ) ; } } } return $ ok ; }
Test if a set of class names implements a list of interfaces
49
protected function _classesExtends ( $ names , array $ classes , array & $ logs = array ( ) ) { if ( ! is_array ( $ names ) ) { $ names = array ( $ names ) ; } foreach ( $ names as $ _name ) { foreach ( $ classes as $ _class ) { if ( class_exists ( $ _class ) ) { if ( CodeHelper :: extendsClass ( $ _name , $ _class ) ) { return true ; } } else { $ logs [ ] = $ this -> _getErrorMessage ( 'Class "%s" not found!' , $ _class ) ; } } } return false ; }
Test if a set of class names extends a list of classes
50
protected function _classesInNamespaces ( $ names , array $ namespaces , array & $ logs = array ( ) ) { if ( ! is_array ( $ names ) ) { $ names = array ( $ names ) ; } foreach ( $ names as $ _name ) { foreach ( $ namespaces as $ _namespace ) { if ( CodeHelper :: namespaceExists ( $ _namespace ) ) { $ tmp_namespace = rtrim ( TextHelper :: toCamelCase ( $ _namespace ) , '\\' ) . '\\' ; if ( substr_count ( TextHelper :: toCamelCase ( $ _name ) , $ tmp_namespace ) > 0 ) { return $ _name ; } } else { $ logs [ ] = $ this -> _getErrorMessage ( 'Namespace "%s" not found!' , $ _namespace ) ; } } } return false ; }
Test if a classes names set is in a set of namespaces
51
public function get ( $ section , $ key ) { if ( ! isset ( $ this -> configValues [ $ section ] [ $ key ] ) ) { return false ; } return $ this -> configValues [ $ section ] [ $ key ] ; }
Haalt een config waarde op . False als deze niet ingesteld is .
52
public function getSection ( $ section ) { if ( ! isset ( $ this -> configValues [ $ section ] ) ) { return null ; } return $ this -> configValues [ $ section ] ; }
Return a config section
53
public function updateCMSFields ( FieldList $ fields ) { $ kapostRefID = $ this -> owner -> KapostRefID ; if ( ! empty ( $ kapostRefID ) ) { if ( CMSPageEditController :: has_extension ( 'KapostPageEditControllerExtension' ) ) { $ messageContent = _t ( 'KapostSiteTreeExtension.KAPOST_CONTENT_WARNING_RO' , '_This Page\'s content is being populated by Kapost, some fields are not editable.' ) ; } else { $ messageContent = _t ( 'KapostSiteTreeExtension.KAPOST_CONTENT_WARNING' , '_This Page\'s content is being populated by Kapost.' ) ; } $ kapostBase = KapostAdmin :: config ( ) -> kapost_base_url ; if ( ! empty ( $ kapostBase ) ) { $ messageContent .= ' <a href="' . Controller :: join_links ( $ kapostBase , 'posts' , $ kapostRefID ) . '" target="_blank">' . _t ( 'KapostSiteTreeExtension.KAPOST_CONTENT_EDIT_LABEL' , '_Click here to edit in Kapost' ) . '</a>' ; } $ fields -> insertBefore ( new LiteralField ( 'KapostContentWarning' , '<div class="message warning">' . $ messageContent . '</div>' ) , 'Title' ) ; if ( Permission :: check ( 'CMS_ACCESS_KapostAdmin' ) ) { $ incoming = KapostObject :: get ( ) -> filter ( 'IsKapostPreview' , 0 ) -> filter ( 'KapostRefID' , Convert :: raw2sql ( $ kapostRefID ) ) ; if ( $ incoming -> count ( ) >= 1 ) { $ link = Controller :: join_links ( AdminRootController :: config ( ) -> url_base , KapostAdmin :: config ( ) -> url_segment , 'KapostObject/EditForm/field/KapostObject/item' , $ incoming -> first ( ) -> ID , 'edit' ) ; $ messageContent = _t ( 'KapostSiteTreeExtension.KAPOST_INCOMING' , '_There are incoming changes from Kapost waiting for this page.' ) . ' ' . '<a href="' . $ link . '" class="cms-panel-link">' . _t ( 'KapostSiteTreeExtension.KAPOST_INCOMING_VIEW' , '_Click here to view the changes' ) . '</a>' ; $ fields -> insertBefore ( new LiteralField ( 'KapostIncomingWarning' , '<div class="message warning">' . $ messageContent . '</div>' ) , 'Title' ) ; } } } $ fields -> removeByName ( 'KapostRefID' ) ; }
Updates the CMS fields adding the fields defined in this extension
54
public function select ( ) { $ this -> stmt [ 'action' ] = 'SELECT' ; if ( func_num_args ( ) !== 0 ) $ this -> stmt [ 'cols' ] = array_unique ( array_merge ( $ this -> stmt [ 'cols' ] , $ this -> buildArrayOfArgs ( func_get_args ( ) ) ) ) ; return $ this ; }
Specifies the number of database table columns to run select on . Accepts several args at once or can be called multiple times for appending field names . Can be chained with other calls .
55
public function order ( ) { $ this -> stmt [ 'order' ] = array_unique ( array_merge ( $ this -> stmt [ 'order' ] , $ this -> buildArrayOfArgs ( func_get_args ( ) ) ) ) ; return $ this ; }
Specifies the field to order by . Accepts several args at once or can be called multiple times for appending field names . Can be chained with other calls .
56
public function group ( ) { $ this -> stmt [ 'group' ] = array_unique ( array_merge ( $ this -> stmt [ 'group' ] , $ this -> buildArrayOfArgs ( func_get_args ( ) ) ) ) ; return $ this ; }
Specifies the field to group by . Accepts several args at once or can be called multiple times for appending field names . Can be chained with other calls .
57
public function insert ( $ data ) { $ this -> stmt [ 'action' ] = 'INSERT' ; $ this -> stmt [ 'cols' ] = array_merge ( $ this -> stmt [ 'cols' ] , $ data ) ; return $ this ; }
Specifies columns and their values to be inserted into a database . Can be chained with other calls .
58
public function update ( $ data ) { $ this -> stmt [ 'action' ] = 'UPDATE' ; $ this -> stmt [ 'cols' ] = array_merge ( $ this -> stmt [ 'cols' ] , $ data ) ; return $ this ; }
Specifies columns and their values to be updated into a database . Can be chained with other calls .
59
private function get_content ( ) { $ input_char = '' ; $ content = array ( ) ; $ space = false ; while ( isset ( $ this -> input [ $ this -> pos ] ) && $ this -> input [ $ this -> pos ] !== '<' ) { if ( $ this -> pos >= $ this -> input_length ) { return count ( $ content ) ? implode ( '' , $ content ) : array ( '' , 'TK_EOF' ) ; } if ( $ this -> traverse_whitespace ( ) ) { if ( count ( $ content ) ) { $ space = true ; } continue ; } $ input_char = $ this -> input [ $ this -> pos ] ; $ this -> pos ++ ; if ( $ space ) { if ( $ this -> line_char_count >= $ this -> options [ 'wrap_line_length' ] ) { $ this -> print_newline ( false , $ content ) ; $ this -> print_indentation ( $ content ) ; } else { $ this -> line_char_count ++ ; $ content [ ] = ' ' ; } $ space = false ; } $ this -> line_char_count ++ ; $ content [ ] = $ input_char ; } return count ( $ content ) ? implode ( '' , $ content ) : '' ; }
function to capture regular content between tags
60
private function get_contents_to ( $ name ) { if ( $ this -> pos === $ this -> input_length ) { return array ( '' , 'TK_EOF' ) ; } $ input_char = '' ; $ content = '' ; $ reg_array = array ( ) ; preg_match ( '#</' . preg_quote ( $ name , '#' ) . '\\s*>#im' , $ this -> input , $ reg_array , PREG_OFFSET_CAPTURE , $ this -> pos ) ; $ end_script = $ reg_array ? ( $ reg_array [ 0 ] [ 1 ] ) : $ this -> input_length ; if ( $ this -> pos < $ end_script ) { $ content = substr ( $ this -> input , $ this -> pos , max ( $ end_script - $ this -> pos , 0 ) ) ; $ this -> pos = $ end_script ; } return $ content ; }
get the full content of a script or style to pass to js_beautify
61
private function record_tag ( $ tag ) { if ( isset ( $ this -> tags [ $ tag . 'count' ] ) ) { $ this -> tags [ $ tag . 'count' ] ++ ; $ this -> tags [ $ tag . $ this -> tags [ $ tag . 'count' ] ] = $ this -> indent_level ; } else { $ this -> tags [ $ tag . 'count' ] = 1 ; $ this -> tags [ $ tag . $ this -> tags [ $ tag . 'count' ] ] = $ this -> indent_level ; } $ this -> tags [ $ tag . $ this -> tags [ $ tag . 'count' ] . 'parent' ] = $ this -> tags [ 'parent' ] ; $ this -> tags [ 'parent' ] = $ tag . $ this -> tags [ $ tag . 'count' ] ; }
function to record a tag and its parent in this . tags Object
62
private function retrieve_tag ( $ tag ) { if ( isset ( $ this -> tags [ $ tag . 'count' ] ) ) { $ temp_parent = $ this -> tags [ 'parent' ] ; while ( $ temp_parent ) { if ( $ tag . $ this -> tags [ $ tag . 'count' ] === $ temp_parent ) { break ; } $ temp_parent = isset ( $ this -> tags [ $ temp_parent . 'parent' ] ) ? $ this -> tags [ $ temp_parent . 'parent' ] : '' ; } if ( $ temp_parent ) { $ this -> indent_level = $ this -> tags [ $ tag . $ this -> tags [ $ tag . 'count' ] ] ; $ this -> tags [ 'parent' ] = $ this -> tags [ $ temp_parent . 'parent' ] ; } unset ( $ this -> tags [ $ tag . $ this -> tags [ $ tag . 'count' ] . 'parent' ] ) ; unset ( $ this -> tags [ $ tag . $ this -> tags [ $ tag . 'count' ] ] ) ; if ( $ this -> tags [ $ tag . 'count' ] === 1 ) { unset ( $ this -> tags [ $ tag . 'count' ] ) ; } else { $ this -> tags [ $ tag . 'count' ] -- ; } } }
function to retrieve the opening tag to the corresponding closer
63
private function get_comment ( $ start_pos ) { $ comment = '' ; $ delimiter = '>' ; $ matched = false ; $ this -> pos = $ start_pos ; $ input_char = $ this -> input [ $ this -> pos ] ; $ this -> pos ++ ; while ( $ this -> pos <= $ this -> input_length ) { $ comment .= $ input_char ; if ( $ comment [ strlen ( $ comment ) - 1 ] === $ delimiter [ strlen ( $ delimiter ) - 1 ] && strpos ( $ comment , $ delimiter ) !== false ) { break ; } if ( ! $ matched && strlen ( $ comment ) < 10 ) { if ( strpos ( $ comment , '<![if' ) === 0 ) { $ delimiter = '<![endif]>' ; $ matched = true ; } else if ( strpos ( $ comment , '<![cdata[' ) === 0 ) { $ delimiter = ']]>' ; $ matched = true ; } else if ( strpos ( $ comment , '<![' ) === 0 ) { $ delimiter = ']>' ; $ matched = true ; } else if ( strpos ( $ comment , '<!--' ) === 0 ) { $ delimiter = ' ; $ matched = true ; } } $ input_char = $ this -> input [ $ this -> pos ] ; $ this -> pos ++ ; } return $ comment ; }
function to return comment content in its entirety
64
private function get_unformatted ( $ delimiter , $ orig_tag = false ) { if ( $ orig_tag && strpos ( strtolower ( $ orig_tag ) , $ delimiter ) !== false ) { return '' ; } $ input_char = '' ; $ content = '' ; $ min_index = 0 ; $ space = true ; do { if ( $ this -> pos >= $ this -> input_length ) { return $ content ; } $ input_char = $ this -> input [ $ this -> pos ] ; $ this -> pos ++ ; if ( in_array ( $ input_char , $ this -> whitespace ) ) { if ( ! $ space ) { $ this -> line_char_count -- ; continue ; } if ( $ input_char === "\n" || $ input_char === "\r" ) { $ content .= "\n" ; $ this -> line_char_count = 0 ; continue ; } } $ content .= $ input_char ; $ this -> line_char_count ++ ; $ space = true ; } while ( strpos ( strtolower ( $ content ) , $ delimiter , $ min_index ) === false ) ; return $ content ; }
function to return unformatted content in its entirety
65
private function get_token ( ) { if ( $ this -> last_token === 'TK_TAG_SCRIPT' || $ this -> last_token === 'TK_TAG_STYLE' ) { $ type = substr ( $ this -> last_token , 7 ) ; $ token = $ this -> get_contents_to ( $ type ) ; if ( ! is_string ( $ token ) ) { return $ token ; } return array ( $ token , 'TK_' . $ type ) ; } if ( $ this -> current_mode === 'CONTENT' ) { $ token = $ this -> get_content ( ) ; if ( ! is_string ( $ token ) ) { return $ token ; } else { return array ( $ token , 'TK_CONTENT' ) ; } } if ( $ this -> current_mode === 'TAG' ) { $ token = $ this -> get_tag ( ) ; if ( ! is_string ( $ token ) ) { return $ token ; } else { $ tag_name_type = 'TK_TAG_' . $ this -> tag_type ; return array ( $ token , $ tag_name_type ) ; } } }
initial handler for token - retrieval
66
protected function getMailer ( ) { $ transport = null ; if ( $ this -> configurationManager -> getSetting ( 'mailer.type' ) === 'sendmail' ) { $ transport = \ Swift_SendmailTransport :: newInstance ( $ this -> configurationManager -> getSetting ( 'mailer.sendmailCommand' ) ) ; } else if ( $ this -> configurationManager -> getSetting ( 'mailer.type' ) === 'smtp' ) { $ host = $ this -> configurationManager -> getSetting ( 'mailer.smtpHost' ) ; $ port = $ this -> configurationManager -> getSetting ( 'mailer.smtpPort' ) ; $ username = $ this -> configurationManager -> getSetting ( 'mailer.smtpUsername' ) ; $ password = $ this -> configurationManager -> getSetting ( 'mailer.smtpPassword' ) ; $ transport = \ Swift_SmtpTransport :: newInstance ( $ host , $ port ) ; $ transport -> setUsername ( $ username ) ; $ transport -> setPassword ( $ password ) ; } if ( $ transport === null ) { throw new Exception ( 'No mail transport defined. Please check your configuration.' ) ; } return \ Swift_Mailer :: newInstance ( $ transport ) ; }
Returns the mailer object
67
public function sendMail ( $ recipient , $ subject , $ htmlBody , $ textBody = false ) { $ message = \ Swift_Message :: newInstance ( ) ; $ message -> setSubject ( $ subject ) ; $ fromEmail = $ this -> configurationManager -> getSetting ( 'mailer.sendFrom' ) ; $ fromName = $ this -> configurationManager -> getSetting ( 'mailer.sendFromName' ) ; $ message -> setFrom ( array ( $ fromEmail => $ fromName ) ) ; $ message -> setTo ( $ recipient ) ; $ message -> setBody ( $ htmlBody , 'text/html' ) ; if ( $ textBody === false ) { $ textBody = $ this -> createTextBody ( $ htmlBody ) ; } $ message -> addPart ( $ textBody , 'text/plain' ) ; $ mailer = $ this -> getMailer ( ) ; return $ mailer -> send ( $ message ) ; }
Sends a email
68
public static function setBaseUrl ( string $ url = "" ) : string { if ( $ url === "" || $ url === null ) { if ( self :: $ _baseUrl === "" ) throw new \ Exception ( "[MVQN\REST\ResClient] " . "'baseUrl' must be set by RestClient::baseUrl() before calling any RestClient methods!" ) ; } else { self :: $ _baseUrl = $ url ; } return self :: $ _baseUrl ; }
Gets or sets the base URL to be used with all REST calls .
69
private static function curl ( string $ endpoint ) { $ baseUrl = self :: $ _baseUrl ; $ curl = curl_init ( ) ; curl_setopt ( $ curl , CURLOPT_URL , $ baseUrl . $ endpoint ) ; curl_setopt ( $ curl , CURLOPT_RETURNTRANSFER , true ) ; curl_setopt ( $ curl , CURLOPT_HEADER , false ) ; curl_setopt ( $ curl , CURLOPT_SSL_VERIFYHOST , 2 ) ; curl_setopt ( $ curl , CURLOPT_SSL_VERIFYPEER , 1 ) ; curl_setopt ( $ curl , CURLOPT_HTTPHEADER , self :: $ _headers ) ; return $ curl ; }
Creates a cURL session with the necessary options headers and endpoint to communicate with the UCRM Server .
70
public static function get ( string $ endpoint ) : array { $ curl = self :: curl ( $ endpoint ) ; $ response = curl_exec ( $ curl ) ; if ( ! $ response ) throw new \ Exception ( "[MVQN\REST\ResClient] The REST request failed with the following error(s): " . curl_error ( $ curl ) ) ; curl_close ( $ curl ) ; return json_decode ( $ response , true ) ; }
Sends a HTTP GET Request to the specified endpoint of the base URL .
71
public static function post ( string $ endpoint , array $ data ) : array { $ curl = self :: curl ( $ endpoint ) ; curl_setopt ( $ curl , CURLOPT_POST , true ) ; curl_setopt ( $ curl , CURLOPT_POSTFIELDS , json_encode ( $ data , self :: JSON_OPTIONS ) ) ; $ response = curl_exec ( $ curl ) ; if ( ! $ response ) throw new \ Exception ( "[MVQN\REST\ResClient] The REST request failed with the following error(s): " . curl_error ( $ curl ) ) ; curl_close ( $ curl ) ; return json_decode ( $ response , true ) ; }
Sends a HTTP POST Requests to the specified endpoint of the base URL .
72
public function itemsFilter ( $ params ) { if ( DEBUG_LOG_BITEMS ) { BLog :: addToLog ( '[BItems.' . $ this -> tableName . '] itemsFilter(' . var_export ( $ params , true ) . ')' ) ; } $ ids = $ this -> itemsFilterIds ( $ params ) ; if ( DEBUG_LOG_BITEMS ) { BLog :: addToLog ( '[BItems.' . $ this -> tableName . '] itemsFilter got IDs: ' . var_export ( $ ids , true ) ) ; } if ( empty ( $ ids ) ) { return array ( ) ; } $ result = $ this -> itemsGet ( $ ids ) ; if ( DEBUG_LOG_BITEMS ) { BLog :: addToLog ( '[BItems.' . $ this -> tableName . '] Got items!' ) ; } return $ result ; }
Get Items by params
73
public function itemsFilterFirst ( $ params ) { $ params2 = $ params ; $ params2 [ 'limit' ] = 1 ; $ list = $ this -> itemsFilter ( $ params2 ) ; if ( empty ( $ list ) ) { return NULL ; } $ item = reset ( $ list ) ; return $ item ; }
Get First Item by params
74
public function itemsFilterSql ( $ params , & $ wh , & $ jn ) { $ wh = array ( ) ; $ jn = array ( ) ; if ( isset ( $ params [ 'exclude' ] ) && ( is_array ( $ params [ 'exclude' ] ) ) ) { $ wh [ ] = '(`' . $ this -> primaryKeyName . '` not in (' . implode ( ',' , $ params [ 'exclude' ] ) . '))' ; } return true ; }
Get items filter
75
public function itemsFilterHash ( $ params ) { $ itemshash = $ this -> tableName . ':list' ; if ( isset ( $ params [ 'exclude' ] ) && ( is_array ( $ params [ 'exclude' ] ) ) ) { $ itemshash .= ':exclude-' . implode ( '-' , $ params [ 'exclude' ] ) ; } if ( isset ( $ params [ 'orderby' ] ) && ( is_array ( $ params [ 'orderby' ] ) ) ) { $ orderdir = isset ( $ params [ 'orderdir' ] ) ? '-' . $ params [ 'orderdir' ] : '' ; $ itemshash .= ':orderby-' . $ params [ 'orderby' ] . $ orderdir ; } if ( ! empty ( $ params [ 'limit' ] ) ) { $ limit = ( int ) $ params [ 'limit' ] ; $ offset = ( int ) $ params [ 'offset' ] ; $ itemshash .= ':limit-' . $ limit ; if ( $ offset ) { $ itemshash .= ':offset-' . $ offset ; } } return $ itemshash ; }
Items list cache hash .
76
public function itemsDelete ( $ ids ) { $ db = BFactory :: getDBO ( ) ; if ( empty ( $ db ) ) { return false ; } $ qr = 'DELETE FROM `' . $ this -> tableName . '` WHERE (`' . $ this -> primaryKeyName . '` in (' . implode ( ',' , $ ids ) . '))' ; $ q = $ db -> Query ( $ qr ) ; if ( empty ( $ q ) ) { return false ; } return true ; }
Delete item from database
77
public function hitItem ( $ id ) { if ( empty ( $ this -> hitsKey ) ) { return false ; } $ db = BFactory :: getDBO ( ) ; if ( empty ( $ db ) ) { return false ; } $ qr = 'UPDATE `' . $ this -> tableName . '` SET `hits`=`hits`+1 WHERE (`' . $ this -> primaryKeyName . '`=' . $ id . ')' ; $ q = $ db -> Query ( $ qr ) ; if ( empty ( $ q ) ) { return false ; } return true ; }
Hit the item .
78
public function truncateAll ( ) { $ qr = 'truncate `' . $ this -> tableName . '`' ; $ db = BFactory :: getDBO ( ) ; if ( empty ( $ db ) ) { return false ; } $ q = $ db -> Query ( $ qr ) ; if ( empty ( $ q ) ) { return false ; } return true ; }
Delete all data in table .
79
public static function cygpath ( $ path ) { $ path = parent :: normalizePath ( $ path , '/' ) ; $ path = preg_replace ( '|^([a-z]):/|i' , '/cygdrive/$1/' , $ path , 1 ) ; return $ path ; }
Convert path into Cygwin - like style .
80
public function get ( $ conditions = [ ] , $ order_by = '' ) { if ( is_scalar ( $ conditions ) ) $ conditions = [ 'id' => $ conditions ] ; $ where = $ this -> _createWhere ( $ conditions ) ; $ order_by = $ this -> _createOrderBy ( $ order_by ) ; $ conditions = ! empty ( $ where ) ? array_values ( $ conditions ) : [ ] ; $ sql = $ this -> _db -> get ( " SELECT *, >id FROM {$this->_table} {$where} {$order_by} " , $ conditions ) ; return $ sql [ 'RESULT' ] ; }
Retrieves data from the database .
81
public function delete ( $ conditions ) { if ( is_scalar ( $ conditions ) ) $ conditions = [ 'id' => $ conditions ] ; $ where = $ this -> _createWhere ( $ conditions ) ; return $ this -> _db -> delete ( $ this -> _table , "{$where}" , array_values ( $ conditions ) ) ; }
Deletes a table row in the database .
82
protected function _createWhere ( array $ conditions ) { $ where = [ ] ; foreach ( $ conditions as $ field => $ value ) { $ where [ ] = $ field . '=?' ; } $ where = implode ( ' AND ' , $ where ) ; if ( ! empty ( $ where ) ) $ where = 'WHERE ' . $ where ; return $ where ; }
Creates a where string of conditions to use in a SQL query .
83
protected function loadEntity ( $ key ) { $ content = $ this -> getFileManager ( ) -> read ( $ key ) ; if ( $ content ) { return unserialize ( $ content ) ; } return null ; }
Load an entity by key
84
protected function persist ( $ object ) { if ( ! $ object -> getId ( ) ) { $ object -> setId ( $ this -> getNextId ( ) ) ; } $ key = $ this -> getHash ( ) . $ object -> getId ( ) ; $ content = serialize ( $ object ) ; $ this -> getFileManager ( ) -> write ( $ key , $ content , true ) ; }
Save an object entity
85
protected function getNextId ( ) { $ keys = $ this -> getFileManager ( ) -> keys ( ) ; $ ids = array ( ) ; foreach ( $ keys as $ key ) { if ( preg_match ( '/^' . $ this -> getHash ( ) . '/' , $ key ) ) { $ ids [ ] = str_replace ( $ this -> getHash ( ) , '' , $ key ) ; } } if ( empty ( $ ids ) ) { return 1 ; } $ maxId = max ( $ ids ) ; return $ maxId + 1 ; }
Get next ID for an object class
86
public function GetID ( $ MessageID ) { if ( Gdn :: Cache ( ) -> ActiveEnabled ( ) ) return self :: Messages ( $ MessageID ) ; else return parent :: GetID ( $ MessageID ) ; }
Returns a single message object for the specified id or FALSE if not found .
87
public function DefineLocation ( $ Message ) { $ Controller = GetValue ( 'Controller' , $ Message ) ; $ Application = GetValue ( 'Application' , $ Message ) ; $ Method = GetValue ( 'Method' , $ Message ) ; if ( in_array ( $ Controller , $ this -> _SpecialLocations ) ) { SetValue ( 'Location' , $ Message , $ Controller ) ; } else { SetValue ( 'Location' , $ Message , $ Application ) ; if ( ! StringIsNullOrEmpty ( $ Controller ) ) SetValue ( 'Location' , $ Message , GetValue ( 'Location' , $ Message ) . '/' . $ Controller ) ; if ( ! StringIsNullOrEmpty ( $ Method ) ) SetValue ( 'Location' , $ Message , GetValue ( 'Location' , $ Message ) . '/' . $ Method ) ; } return $ Message ; }
Build the Message s Location property and add it .
88
public function GetEnabledLocations ( ) { $ Data = $ this -> SQL -> Select ( 'Application,Controller,Method' ) -> From ( 'Message' ) -> Where ( 'Enabled' , '1' ) -> GroupBy ( 'Application,Controller,Method' ) -> Get ( ) ; $ Locations = array ( ) ; foreach ( $ Data as $ Row ) { if ( in_array ( $ Row -> Controller , $ this -> _SpecialLocations ) ) { $ Locations [ ] = $ Row -> Controller ; } else { $ Location = $ Row -> Application ; if ( $ Row -> Controller != '' ) $ Location .= '/' . $ Row -> Controller ; if ( $ Row -> Method != '' ) $ Location .= '/' . $ Row -> Method ; $ Locations [ ] = $ Location ; } } return $ Locations ; }
Returns a distinct array of controllers that have enabled messages .
89
public function getMetaTags ( $ model ) { $ lang = Yii :: $ app -> language ; if ( Yii :: $ app -> id === 'app-backend' ) { $ lang = Yii :: $ app -> wavecms -> editedLanguage ; } return $ this -> andWhere ( [ 'model' => $ model , 'language' => $ lang ] ) ; }
Return array of meta tags
90
public function getAssetUrl ( $ raw = false ) { if ( $ this -> assetUrl === null ) { $ this -> assetUrl = Yii :: $ app -> assetManager -> publish ( $ this -> getBasePath ( ) . '/' . $ this -> distDir ) ; } return $ raw ? $ this -> assetUrl : $ this -> assetUrl [ 1 ] ; }
Get path to assets of theme .
91
protected function quote ( $ value ) { if ( is_string ( $ value ) || is_int ( $ value ) ) { $ escaped = $ this -> connector -> escape ( $ value ) ; return "'{$escaped}'" ; } elseif ( is_array ( $ value ) ) { $ buffer = array ( ) ; foreach ( $ value as $ i ) { array_push ( $ buffer , $ this -> quote ( $ i ) ) ; $ buffer = join ( ", " , $ buffer ) ; return "({$buffer})" ; } } elseif ( is_null ( $ value ) ) { return 'NULL' ; } elseif ( is_bool ( $ value ) ) { return ( int ) $ value ; } elseif ( empty ( $ value ) ) { return "' '" ; } else return $ this -> connector -> escape ( $ value ) ; }
This method quotes input data according to how MySQL woudl expect it .
92
public function setTable ( $ table ) { try { if ( empty ( $ table ) ) { throw new MySQLException ( "Invalid argument passed for table name" , 1 ) ; } } catch ( MySQLException $ MySQLExceptionObject ) { $ MySQLExceptionObject -> errorShow ( ) ; } $ this -> froms = $ table ; if ( ! isset ( $ this -> fields [ $ table ] ) ) $ this -> fields [ $ table ] = array ( "*" ) ; return $ this ; }
This method sets the table name to be selected
93
public function setFields ( $ table , $ fields = array ( "*" ) ) { try { if ( empty ( $ table ) ) { throw new MySQLException ( "Invalid argument passed for table name" , 1 ) ; } } catch ( MySQLException $ MySQLExceptionObject ) { $ MySQLExceptionObject -> errorShow ( ) ; } $ this -> froms = $ table ; $ this -> fields [ $ table ] = $ fields ; }
This method sets the columns for a table to be selected
94
public function leftJoin ( $ table , $ condition , $ fields = array ( "*" ) ) { try { if ( empty ( $ table ) ) { throw new MySQLException ( "Invalid table argument $table passed for the leftJoin Clause" , 1 ) ; } if ( empty ( $ condition ) ) { throw new MySQLException ( "Invalid argument $condition passed for the leftJoin Clause" , 1 ) ; } } catch ( MySQLException $ MySQLExceptionObject ) { $ MySQLExceptionObject -> errorShow ( ) ; } $ this -> fields += array ( $ table => $ fields ) ; $ this -> joins [ 'tables' ] [ ] = $ table ; $ this -> joins [ 'conditions' ] [ ] = $ condition ; return $ this ; }
This method builds query string for joining tables in query .
95
public function limit ( $ limit , $ page = 1 ) { try { if ( empty ( $ limit ) ) { throw new MySQLException ( "Empty argument passed for $limit in method limit()" , 1 ) ; } } catch ( MySQLException $ MySQLExceptionObject ) { $ MySQLExceptionObject -> errorShow ( ) ; } $ this -> limits = $ limit ; $ this -> offset = ( int ) $ limit * ( $ page - 1 ) ; return $ this ; }
This method sets the limit for the number of rows to return .
96
public function order ( $ order , $ direction = 'asc' ) { try { if ( empty ( $ order ) ) { throw new MySQLException ( "Empty value passed for parameter $order in order() method" , 1 ) ; } } catch ( MySQLException $ MySQLExceptionObject ) { $ MySQLExceptionObject -> errorShow ( ) ; } $ this -> orders = $ order ; $ this -> directions = $ direction ; return $ this ; }
This method sets the order in which to sort the query results .
97
public function where ( $ arguments ) { try { if ( is_float ( sizeof ( $ arguments ) / 2 ) ) { throw new MySQLException ( "No arguments passed for the where clause" ) ; } } catch ( MySQLException $ MySQLExceptionObject ) { $ MySQLExceptionObject -> errorShow ( ) ; } if ( sizeof ( $ arguments ) == 2 ) { $ arguments [ 0 ] = preg_replace ( "#\?#" , "%s" , $ arguments [ 0 ] ) ; $ arguments [ 1 ] = $ this -> quote ( $ arguments [ 1 ] ) ; $ this -> wheres [ ] = call_user_func_array ( "sprintf" , $ arguments ) ; return $ this ; } else { $ count = sizeof ( $ arguments ) / 2 ; for ( $ i = 0 ; $ i < $ count ; $ i ++ ) { $ argumentsPair = array_splice ( $ arguments , 0 , 2 ) ; $ argumentsPair [ 0 ] = preg_replace ( "#\?#" , "%s" , $ argumentsPair [ 0 ] ) ; $ argumentsPair [ 1 ] = $ this -> quote ( $ argumentsPair [ 1 ] ) ; $ this -> wheres [ ] = call_user_func_array ( "sprintf" , $ argumentsPair ) ; } return $ this ; } }
This method defines the where parameters of the query string .
98
protected function buildSelect ( ) { $ fields = array ( ) ; $ where = $ order = $ limit = $ join = "" ; $ template = "SELECT %s %s FROM %s %s %s %s %s" ; foreach ( $ this -> fields as $ table => $ tableFields ) { foreach ( $ tableFields as $ field => $ alias ) { if ( is_string ( $ field ) && $ field != 'COUNT(1)' ) { $ fields [ ] = "{$table}.{$field} AS {$alias}" ; } elseif ( is_string ( $ field ) && $ field == 'COUNT(1)' ) { $ fields [ ] = "{$field} AS {$alias}" ; } else { $ fields [ ] = "{$table}.{$alias}" ; } } } $ fields = join ( ", " , $ fields ) ; $ queryJoin = $ this -> joins ; if ( ! empty ( $ queryJoin ) ) { $ joinTables = "(" . join ( ", " , $ queryJoin [ 'tables' ] ) . ")" ; $ joinConditions = "(" . join ( " AND " , $ queryJoin [ 'conditions' ] ) . ")" ; $ join = " LEFT JOIN $joinTables ON $joinConditions" ; } $ queryWhere = $ this -> wheres ; if ( ! empty ( $ queryWhere ) ) { $ joined = join ( " AND " , $ queryWhere ) ; $ where = "WHERE {$joined}" ; } $ queryOrder = $ this -> orders ; if ( ! empty ( $ queryOrder ) ) { $ orderDirection = $ this -> directions ; $ order = "ORDER BY {$queryOrder} {$orderDirection}" ; } $ queryLimit = $ this -> limits ; if ( ! empty ( $ queryLimit ) ) { $ limitOffset = $ this -> offset ; if ( $ limitOffset ) { $ limit = "LIMIT {$limitOffset}, {$queryLimit}" ; } else { $ limit = "LIMIT {$queryLimit}" ; } } return sprintf ( $ template , $ this -> distinct , $ fields , $ this -> froms , $ join , $ where , $ order , $ limit ) ; }
This method builds a select query string .
99
protected function buildInsert ( $ data , $ set_timestamps ) { $ fields = array ( ) ; $ values = array ( ) ; $ template = "INSERT INTO %s (%s) VALUES (%s)" ; if ( $ set_timestamps ) $ data [ 'date_created' ] = date ( 'Y-m-d h:i:s' ) ; foreach ( $ data as $ field => $ value ) { $ fields [ ] = $ field ; $ values [ ] = $ this -> quote ( $ value ) ; } $ fields = join ( ", " , $ fields ) ; $ values = join ( ", " , $ values ) ; return sprintf ( $ template , $ this -> froms , $ fields , $ values ) ; }
This method builds the query string for inserting one row of records into the database .
End of preview. Expand in Data Studio

No dataset card yet

Downloads last month
18