idx int64 0 60.3k | question stringlengths 101 6.21k | target stringlengths 7 803 |
|---|---|---|
48,400 | private function setToken ( array $ token ) { if ( is_a ( $ this -> container , '\\ArrayAccess' ) ) { $ this -> container [ 'token' ] = $ token ; return ; } $ this -> container -> set ( 'token' , $ token ) ; } | Helper method to set the token value in the container instance . |
48,401 | private function formatScopes ( array $ scopes ) { if ( empty ( $ scopes ) ) { return [ null ] ; } array_walk ( $ scopes , function ( & $ scope ) { if ( is_array ( $ scope ) ) { $ scope = implode ( ' ' , $ scope ) ; } } ) ; return $ scopes ; } | Helper method to ensure given scopes are formatted properly . |
48,402 | public function setPagination ( $ nextURL = null , $ previousURL = null , $ firstURL = null , $ lastURL = null ) { if ( empty ( $ nextURL ) && empty ( $ previousURL ) && empty ( $ firstURL ) && empty ( $ lastURL ) ) throw new \ LogicException ( 'At least one URL must be specified for pagination to work.' ) ; if ( ! empty ( $ nextURL ) ) $ this -> setAtomLink ( $ nextURL , 'next' ) ; if ( ! empty ( $ previousURL ) ) $ this -> setAtomLink ( $ previousURL , 'previous' ) ; if ( ! empty ( $ firstURL ) ) $ this -> setAtomLink ( $ firstURL , 'first' ) ; if ( ! empty ( $ lastURL ) ) $ this -> setAtomLink ( $ lastURL , 'last' ) ; return $ this ; } | Set the URLs for feed pagination . |
48,403 | public function addGenerator ( ) { if ( $ this -> version == Feed :: ATOM ) $ this -> setChannelElement ( 'atom:generator' , 'FeedWriter' , array ( 'uri' => 'https://github.com/mibe/FeedWriter' ) ) ; else if ( $ this -> version == Feed :: RSS2 ) $ this -> setChannelElement ( 'generator' , 'FeedWriter' ) ; else throw new InvalidOperationException ( 'The generator element is not supported in RSS1 feeds.' ) ; return $ this ; } | Add a channel element indicating the program used to generate the feed . |
48,404 | public function addNamespace ( $ prefix , $ uri ) { if ( empty ( $ prefix ) ) throw new \ InvalidArgumentException ( 'The prefix may not be emtpy or NULL.' ) ; if ( empty ( $ uri ) ) throw new \ InvalidArgumentException ( 'The uri may not be empty or NULL.' ) ; $ this -> namespaces [ $ prefix ] = $ uri ; return $ this ; } | Add a XML namespace to the internal list of namespaces . After that custom channel elements can be used properly to generate a valid feed . |
48,405 | public function setChannelElement ( $ elementName , $ content , array $ attributes = null , $ multiple = false ) { if ( empty ( $ elementName ) ) throw new \ InvalidArgumentException ( 'The element name may not be empty or NULL.' ) ; if ( ! is_string ( $ elementName ) ) throw new \ InvalidArgumentException ( 'The element name must be a string.' ) ; $ entity [ 'content' ] = $ content ; $ entity [ 'attributes' ] = $ attributes ; if ( $ multiple === TRUE ) $ this -> channels [ $ elementName ] [ ] = $ entity ; else $ this -> channels [ $ elementName ] = $ entity ; return $ this ; } | Add a channel element to the feed . |
48,406 | public function setChannelElementsFromArray ( array $ elementArray ) { foreach ( $ elementArray as $ elementName => $ content ) { $ this -> setChannelElement ( $ elementName , $ content ) ; } return $ this ; } | Set multiple channel elements from an array . Array elements should be channelName = > channelContent format . |
48,407 | public function getMIMEType ( ) { switch ( $ this -> version ) { case Feed :: RSS2 : $ mimeType = "application/rss+xml" ; break ; case Feed :: RSS1 : $ mimeType = "application/rdf+xml" ; break ; case Feed :: ATOM : $ mimeType = "application/atom+xml" ; break ; default : $ mimeType = "text/xml" ; } return $ mimeType ; } | Get the appropriate MIME type string for the current feed . |
48,408 | public function addItem ( Item $ feedItem ) { if ( $ feedItem -> getVersion ( ) != $ this -> version ) { $ msg = sprintf ( 'Feed type mismatch: This instance can handle %s feeds only, but item for %s feeds given.' , $ this -> version , $ feedItem -> getVersion ( ) ) ; throw new \ InvalidArgumentException ( $ msg ) ; } $ this -> items [ ] = $ feedItem ; return $ this ; } | Add a FeedItem to the main class |
48,409 | public function setEncoding ( $ encoding ) { if ( empty ( $ encoding ) ) throw new \ InvalidArgumentException ( 'The encoding may not be empty or NULL.' ) ; if ( ! is_string ( $ encoding ) ) throw new \ InvalidArgumentException ( 'The encoding must be a string.' ) ; $ this -> encoding = $ encoding ; return $ this ; } | Set the encoding attribute in the XML prolog . |
48,410 | public function setDate ( $ date ) { if ( $ this -> version == Feed :: RSS1 ) throw new InvalidOperationException ( 'The publication date is not supported in RSS1 feeds.' ) ; $ format = $ this -> version == Feed :: ATOM ? \ DATE_ATOM : \ DATE_RSS ; if ( $ date instanceof DateTime ) $ date = $ date -> format ( $ format ) ; else if ( is_numeric ( $ date ) && $ date >= 0 ) $ date = date ( $ format , $ date ) ; else if ( is_string ( $ date ) ) { $ timestamp = strtotime ( $ date ) ; if ( $ timestamp === FALSE ) throw new \ InvalidArgumentException ( 'The given date was not parseable.' ) ; $ date = date ( $ format , $ timestamp ) ; } else throw new \ InvalidArgumentException ( 'The given date is not an instance of DateTime, a UNIX timestamp or a date string.' ) ; if ( $ this -> version == Feed :: ATOM ) $ this -> setChannelElement ( 'updated' , $ date ) ; else $ this -> setChannelElement ( 'lastBuildDate' , $ date ) ; return $ this ; } | Set the date when the feed was lastly updated . |
48,411 | public function setDescription ( $ description ) { if ( $ this -> version != Feed :: ATOM ) $ this -> setChannelElement ( 'description' , $ description ) ; else $ this -> setChannelElement ( 'subtitle' , $ description ) ; return $ this ; } | Set a phrase or sentence describing the feed . |
48,412 | public function setLink ( $ link ) { if ( $ this -> version == Feed :: ATOM ) $ this -> setAtomLink ( $ link ) ; else $ this -> setChannelElement ( 'link' , $ link ) ; return $ this ; } | Set the link channel element |
48,413 | public function setAtomLink ( $ href , $ rel = null , $ type = null , $ hreflang = null , $ title = null , $ length = null ) { $ data = array ( 'href' => $ href ) ; if ( $ rel != null ) { if ( ! is_string ( $ rel ) || empty ( $ rel ) ) throw new \ InvalidArgumentException ( 'rel parameter must be a string and a valid relation identifier.' ) ; $ data [ 'rel' ] = $ rel ; } if ( $ type != null ) { if ( ! is_string ( $ type ) || preg_match ( '/.+\/.+/' , $ type ) != 1 ) throw new \ InvalidArgumentException ( 'type parameter must be a string and a MIME type.' ) ; $ data [ 'type' ] = $ type ; } if ( $ hreflang != null ) { if ( ! is_string ( $ hreflang ) || preg_match ( '/[A-Za-z]{1,8}(-[A-Za-z0-9]{1,8})*/' , $ hreflang ) != 1 ) throw new \ InvalidArgumentException ( 'hreflang parameter must be a string and a valid language code.' ) ; $ data [ 'hreflang' ] = $ hreflang ; } if ( $ title != null ) { if ( ! is_string ( $ title ) || empty ( $ title ) ) throw new \ InvalidArgumentException ( 'title parameter must be a string and not empty.' ) ; $ data [ 'title' ] = $ title ; } if ( $ length != null ) { if ( ! is_int ( $ length ) || $ length < 0 ) throw new \ InvalidArgumentException ( 'length parameter must be a positive integer.' ) ; $ data [ 'length' ] = ( string ) $ length ; } if ( $ this -> version == Feed :: ATOM ) { foreach ( $ this -> channels as $ key => $ value ) { if ( $ key != 'atom:link' ) continue ; foreach ( $ value as $ linkItem ) { $ attrib = $ linkItem [ 'attributes' ] ; if ( @ $ attrib [ 'rel' ] == 'alternate' && @ $ attrib [ 'hreflang' ] == $ hreflang && @ $ attrib [ 'type' ] == $ type ) throw new InvalidOperationException ( 'The feed must not contain more than one link element with a' . ' relation of "alternate" that has the same combination of type and hreflang attribute values.' ) ; } } } return $ this -> setChannelElement ( 'atom:link' , '' , $ data , true ) ; } | Set custom link channel elements . |
48,414 | public function setImage ( $ url , $ title = null , $ link = null ) { if ( ! is_string ( $ url ) || empty ( $ url ) ) throw new \ InvalidArgumentException ( 'url parameter must be a string and may not be empty or NULL.' ) ; if ( $ this -> version != Feed :: ATOM ) { if ( ! is_string ( $ title ) || empty ( $ title ) ) throw new \ InvalidArgumentException ( 'title parameter must be a string and may not be empty or NULL.' ) ; if ( ! is_string ( $ link ) || empty ( $ link ) ) throw new \ InvalidArgumentException ( 'link parameter must be a string and may not be empty or NULL.' ) ; $ data = array ( 'title' => $ title , 'link' => $ link , 'url' => $ url ) ; $ name = 'image' ; } else { $ name = 'logo' ; $ data = $ url ; } if ( $ this -> version == Feed :: RSS1 ) { $ this -> data [ 'Image' ] = $ data ; return $ this -> setChannelElement ( $ name , '' , array ( 'rdf:resource' => $ url ) , false ) ; } else return $ this -> setChannelElement ( $ name , $ data ) ; } | Set the image channel element |
48,415 | public static function uuid ( $ key = null , $ prefix = '' ) { $ key = ( $ key == null ) ? uniqid ( rand ( ) ) : $ key ; $ chars = md5 ( $ key ) ; $ uuid = substr ( $ chars , 0 , 8 ) . '-' ; $ uuid .= substr ( $ chars , 8 , 4 ) . '-' ; $ uuid .= substr ( $ chars , 12 , 4 ) . '-' ; $ uuid .= substr ( $ chars , 16 , 4 ) . '-' ; $ uuid .= substr ( $ chars , 20 , 12 ) ; return $ prefix . $ uuid ; } | Generate an UUID . |
48,416 | public static function filterInvalidXMLChars ( $ string , $ replacement = '_' ) { $ result = preg_replace ( '/[^\x{0009}\x{000a}\x{000d}\x{0020}-\x{D7FF}\x{E000}-\x{FFFD}\x{10000}-\x{10FFFF}]+/u' , $ replacement , $ string ) ; if ( $ result == NULL && preg_last_error ( ) == PREG_BAD_UTF8_ERROR ) $ result = preg_replace ( '/[^\x09\x0a\x0d\x20-\xFF]+/' , $ replacement , $ string ) ; if ( $ result == NULL ) $ result = $ string ; return $ result ; } | Replace invalid XML characters . |
48,417 | private function makeHeader ( ) { $ out = '<?xml version="1.0" encoding="' . $ this -> encoding . '" ?>' . PHP_EOL ; $ prefixes = $ this -> getNamespacePrefixes ( ) ; $ attributes = array ( ) ; $ tagName = '' ; $ defaultNamespace = '' ; if ( $ this -> version == Feed :: RSS2 ) { $ tagName = 'rss' ; $ attributes [ 'version' ] = '2.0' ; } elseif ( $ this -> version == Feed :: RSS1 ) { $ tagName = 'rdf:RDF' ; $ prefixes [ ] = 'rdf' ; $ defaultNamespace = $ this -> namespaces [ 'rss1' ] ; } elseif ( $ this -> version == Feed :: ATOM ) { $ tagName = 'feed' ; $ defaultNamespace = $ this -> namespaces [ 'atom' ] ; $ prefixes = array_flip ( $ prefixes ) ; unset ( $ prefixes [ 'atom' ] ) ; $ prefixes = array_flip ( $ prefixes ) ; } foreach ( $ prefixes as $ prefix ) { if ( ! isset ( $ this -> namespaces [ $ prefix ] ) ) throw new InvalidOperationException ( 'Unknown XML namespace prefix: \'' . $ prefix . '\'.' . ' Use the addNamespace method to add support for this prefix.' ) ; else $ attributes [ 'xmlns:' . $ prefix ] = $ this -> namespaces [ $ prefix ] ; } if ( ! empty ( $ defaultNamespace ) ) $ attributes [ 'xmlns' ] = $ defaultNamespace ; $ out .= $ this -> makeNode ( $ tagName , '' , $ attributes , true ) ; return $ out ; } | Returns the XML header and root element depending on the feed type . |
48,418 | private function makeFooter ( ) { if ( $ this -> version == Feed :: RSS2 ) { return '</channel>' . PHP_EOL . '</rss>' ; } elseif ( $ this -> version == Feed :: RSS1 ) { return '</rdf:RDF>' ; } elseif ( $ this -> version == Feed :: ATOM ) { return '</feed>' ; } } | Closes the open tags at the end of file |
48,419 | private function makeNode ( $ tagName , $ tagContent , array $ attributes = null , $ omitEndTag = false ) { $ nodeText = '' ; $ attrText = '' ; if ( $ attributes != null ) { foreach ( $ attributes as $ key => $ value ) { $ value = self :: filterInvalidXMLChars ( $ value ) ; $ value = htmlspecialchars ( $ value ) ; $ attrText .= " $key=\"$value\"" ; } } $ attrText .= ( in_array ( $ tagName , $ this -> CDATAEncoding ) && $ this -> version == Feed :: ATOM ) ? ' type="html"' : '' ; $ nodeText .= "<{$tagName}{$attrText}>" ; $ nodeText .= ( in_array ( $ tagName , $ this -> CDATAEncoding ) ) ? '<![CDATA[' : '' ; if ( is_array ( $ tagContent ) ) { foreach ( $ tagContent as $ key => $ value ) { if ( is_array ( $ value ) ) { $ nodeText .= PHP_EOL ; foreach ( $ value as $ subValue ) { $ nodeText .= $ this -> makeNode ( $ key , $ subValue ) ; } } else if ( is_string ( $ value ) ) { $ nodeText .= $ this -> makeNode ( $ key , $ value ) ; } else { throw new \ InvalidArgumentException ( "Unknown node-value type for $key" ) ; } } } else { $ tagContent = self :: filterInvalidXMLChars ( $ tagContent ) ; $ nodeText .= ( in_array ( $ tagName , $ this -> CDATAEncoding ) ) ? $ this -> sanitizeCDATA ( $ tagContent ) : htmlspecialchars ( $ tagContent ) ; } $ nodeText .= ( in_array ( $ tagName , $ this -> CDATAEncoding ) ) ? ']]>' : '' ; if ( ! $ omitEndTag ) $ nodeText .= "</$tagName>" ; $ nodeText .= PHP_EOL ; return $ nodeText ; } | Creates a single node in XML format |
48,420 | private function makeChannels ( ) { $ out = '' ; switch ( $ this -> version ) { case Feed :: RSS2 : $ out .= '<channel>' . PHP_EOL ; break ; case Feed :: RSS1 : $ out .= ( isset ( $ this -> data [ 'ChannelAbout' ] ) ) ? "<channel rdf:about=\"{$this->data['ChannelAbout']}\">" : "<channel rdf:about=\"{$this->channels['link']['content']}\">" ; break ; } foreach ( $ this -> channels as $ key => $ value ) { if ( $ this -> version == Feed :: ATOM && strncmp ( $ key , 'atom' , 4 ) == 0 ) { $ key = substr ( $ key , 5 ) ; } if ( ! array_key_exists ( 'content' , $ value ) ) { foreach ( $ value as $ singleElement ) { $ out .= $ this -> makeNode ( $ key , $ singleElement [ 'content' ] , $ singleElement [ 'attributes' ] ) ; } } else { $ out .= $ this -> makeNode ( $ key , $ value [ 'content' ] , $ value [ 'attributes' ] ) ; } } if ( $ this -> version == Feed :: RSS1 ) { $ out .= "<items>" . PHP_EOL . "<rdf:Seq>" . PHP_EOL ; foreach ( $ this -> items as $ item ) { $ thisItems = $ item -> getElements ( ) ; $ out .= "<rdf:li resource=\"{$thisItems['link']['content']}\"/>" . PHP_EOL ; } $ out .= "</rdf:Seq>" . PHP_EOL . "</items>" . PHP_EOL . "</channel>" . PHP_EOL ; if ( array_key_exists ( 'image' , $ this -> data ) ) $ out .= $ this -> makeNode ( 'image' , $ this -> data [ 'Image' ] , array ( 'rdf:about' => $ this -> data [ 'Image' ] [ 'url' ] ) ) ; } else if ( $ this -> version == Feed :: ATOM ) { $ out .= $ this -> makeNode ( 'id' , Feed :: uuid ( $ this -> channels [ 'title' ] [ 'content' ] , 'urn:uuid:' ) ) ; } return $ out ; } | Make the channels . |
48,421 | private function endItem ( ) { if ( $ this -> version == Feed :: RSS2 || $ this -> version == Feed :: RSS1 ) { return '</item>' . PHP_EOL ; } elseif ( $ this -> version == Feed :: ATOM ) { return '</entry>' . PHP_EOL ; } } | Closes feed item tag |
48,422 | public function getElements ( ) { if ( $ this -> version == Feed :: ATOM ) { if ( ! array_key_exists ( 'id' , $ this -> elements ) ) $ this -> setId ( Feed :: uuid ( $ this -> elements [ 'title' ] [ 'content' ] , 'urn:uuid:' ) ) ; if ( ! array_key_exists ( 'content' , $ this -> elements ) && ! array_key_exists ( 'link' , $ this -> elements ) ) throw new InvalidOperationException ( 'ATOM feed entries need a link or a content element. Call the setLink or setContent method.' ) ; } else if ( $ this -> version == Feed :: RSS1 ) { if ( ! array_key_exists ( 'title' , $ this -> elements ) ) throw new InvalidOperationException ( 'RSS1 feed entries need a title element. Call the setTitle method.' ) ; if ( ! array_key_exists ( 'link' , $ this -> elements ) ) throw new InvalidOperationException ( 'RSS1 feed entries need a link element. Call the setLink method.' ) ; } return $ this -> elements ; } | Return the collection of elements in this feed item |
48,423 | public function setContent ( $ content ) { if ( $ this -> version != Feed :: ATOM ) throw new InvalidOperationException ( 'The content element is supported in ATOM feeds only.' ) ; return $ this -> addElement ( 'content' , $ content , array ( 'type' => 'html' ) ) ; } | Set the content element of the feed item For ATOM feeds only |
48,424 | public function setDate ( $ date ) { if ( ! is_numeric ( $ date ) ) { if ( $ date instanceof DateTime ) $ date = $ date -> getTimestamp ( ) ; else { $ date = strtotime ( $ date ) ; if ( $ date === FALSE ) throw new \ InvalidArgumentException ( 'The given date string was not parseable.' ) ; } } elseif ( $ date < 0 ) throw new \ InvalidArgumentException ( 'The given date is not an UNIX timestamp.' ) ; if ( $ this -> version == Feed :: ATOM ) { $ tag = 'updated' ; $ value = date ( \ DATE_ATOM , $ date ) ; } elseif ( $ this -> version == Feed :: RSS2 ) { $ tag = 'pubDate' ; $ value = date ( \ DATE_RSS , $ date ) ; } else { $ tag = 'dc:date' ; $ value = date ( "Y-m-d" , $ date ) ; } return $ this -> addElement ( $ tag , $ value ) ; } | Set the date element of the feed item . |
48,425 | public function addEnclosure ( $ url , $ length , $ type , $ multiple = TRUE ) { if ( $ this -> version == Feed :: RSS1 ) throw new InvalidOperationException ( 'Media attachment is not supported in RSS1 feeds.' ) ; if ( ! is_numeric ( $ length ) || $ length < 0 ) throw new \ InvalidArgumentException ( 'The length parameter must be an integer and greater or equals to zero.' ) ; if ( ! is_string ( $ type ) || preg_match ( '/.+\/.+/' , $ type ) != 1 ) throw new \ InvalidArgumentException ( 'type parameter must be a string and a MIME type.' ) ; $ attributes = array ( 'length' => $ length , 'type' => $ type ) ; if ( $ this -> version == Feed :: RSS2 ) { $ attributes [ 'url' ] = $ url ; $ this -> addElement ( 'enclosure' , '' , $ attributes , FALSE , $ multiple ) ; } else { $ attributes [ 'href' ] = $ url ; $ attributes [ 'rel' ] = 'enclosure' ; $ this -> addElement ( 'atom:link' , '' , $ attributes , FALSE , $ multiple ) ; } return $ this ; } | Attach a external media to the feed item . Not supported in RSS 1 . 0 feeds . |
48,426 | public function setAuthor ( $ author , $ email = null , $ uri = null ) { if ( $ this -> version == Feed :: RSS1 ) throw new InvalidOperationException ( 'The author element is not supported in RSS1 feeds.' ) ; if ( $ email != null && preg_match ( '/.+@.+/' , $ email ) != 1 ) throw new \ InvalidArgumentException ( 'The email address is syntactically incorrect.' ) ; if ( $ this -> version == Feed :: RSS2 ) { if ( $ email != null ) $ author = $ email . ' (' . $ author . ')' ; $ this -> addElement ( 'author' , $ author ) ; } else { $ elements = array ( 'name' => $ author ) ; if ( $ email != null ) $ elements [ 'email' ] = $ email ; if ( $ uri != null ) $ elements [ 'uri' ] = $ uri ; $ this -> addElement ( 'author' , $ elements ) ; } return $ this ; } | Set the author element of feed item . Not supported in RSS 1 . 0 feeds . |
48,427 | public function setId ( $ id , $ permaLink = false ) { if ( $ this -> version == Feed :: RSS2 ) { if ( ! is_bool ( $ permaLink ) ) throw new \ InvalidArgumentException ( 'The permaLink parameter must be boolean.' ) ; $ permaLink = $ permaLink ? 'true' : 'false' ; $ this -> addElement ( 'guid' , $ id , array ( 'isPermaLink' => $ permaLink ) ) ; } elseif ( $ this -> version == Feed :: ATOM ) { $ validSchemes = array ( 'aaa' , 'aaas' , 'about' , 'acap' , 'acct' , 'cap' , 'cid' , 'coap' , 'coaps' , 'crid' , 'data' , 'dav' , 'dict' , 'dns' , 'example' , 'fax' , 'file' , 'filesystem' , 'ftp' , 'geo' , 'go' , 'gopher' , 'h323' , 'http' , 'https' , 'iax' , 'icap' , 'im' , 'imap' , 'info' , 'ipp' , 'ipps' , 'iris' , 'iris.beep' , 'iris.lwz' , 'iris.xpc' , 'iris.xpcs' , 'jabber' , 'ldap' , 'mailserver' , 'mailto' , 'mid' , 'modem' , 'msrp' , 'msrps' , 'mtqp' , 'mupdate' , 'news' , 'nfs' , 'ni' , 'nih' , 'nntp' , 'opaquelocktoken' , 'pack' , 'pkcs11' , 'pop' , 'pres' , 'prospero' , 'reload' , 'rtsp' , 'rtsps' , 'rtspu' , 'service' , 'session' , 'shttp' , 'sieve' , 'sip' , 'sips' , 'sms' , 'snews' , 'snmp' , 'soap.beep' , 'soap.beeps' , 'stun' , 'stuns' , 'tag' , 'tel' , 'telnet' , 'tftp' , 'thismessage' , 'tip' , 'tn3270' , 'turn' , 'turns' , 'tv' , 'urn' , 'vemmi' , 'videotex' , 'vnc' , 'wais' , 'ws' , 'wss' , 'xcon' , 'xcon-userid' , 'xmlrpc.beep' , 'xmlrpc.beeps' , 'xmpp' , 'z39.50' , 'z39.50r' , 'z39.50s' ) ; $ found = FALSE ; $ checkId = strtolower ( $ id ) ; foreach ( $ validSchemes as $ scheme ) if ( strrpos ( $ checkId , $ scheme . ':' , - strlen ( $ checkId ) ) !== FALSE ) { $ found = TRUE ; break ; } if ( ! $ found ) throw new \ InvalidArgumentException ( "The ID must begin with an IANA-registered URI scheme." ) ; $ this -> addElement ( 'id' , $ id , NULL , TRUE ) ; } else throw new InvalidOperationException ( 'A unique ID is not supported in RSS1 feeds.' ) ; return $ this ; } | Set the unique identifier of the feed item |
48,428 | protected function compileMinify ( $ value ) { if ( $ this -> shouldMinify ( $ value ) ) { $ replace = array ( '/<!--[^\[](.*?)[^\]] => '' , "/<\?php/" => '<?php ' , "/\n([\S])/" => ' $1' , "/\r/" => '' , "/\n/" => '' , "/\t/" => ' ' , "/ +/" => ' ' , ) ; return preg_replace ( array_keys ( $ replace ) , array_values ( $ replace ) , $ value ) ; } else { return $ value ; } } | Compress the HTML output before saving it |
48,429 | public function filterAutocomplete ( GetFilterConditionEvent $ event ) : void { $ expr = $ event -> getFilterQuery ( ) -> getExpr ( ) ; $ values = $ event -> getValues ( ) ; if ( '' !== $ values [ 'value' ] && null !== $ values [ 'value' ] ) { $ paramName = str_replace ( '.' , '_' , $ event -> getField ( ) ) ; $ event -> setCondition ( $ expr -> eq ( $ event -> getField ( ) , ':' . $ paramName ) , [ $ paramName => $ values [ 'value' ] ] ) ; } } | Apply a filter for a filter_autcomplete type . This method should work whih both ORM and DBAL query builder . |
48,430 | public function save_options ( ) { if ( ! filter_input ( INPUT_POST , 'submit' ) ) { return false ; } if ( ! wp_verify_nonce ( filter_input ( INPUT_POST , '_wpnonce' ) , 'update-permalink' ) ) { return false ; } if ( false === strpos ( filter_input ( INPUT_POST , '_wp_http_referer' ) , 'options-permalink.php' ) ) { return false ; } $ post_types = CPTP_Util :: get_post_types ( ) ; foreach ( $ post_types as $ post_type ) : $ structure = trim ( esc_attr ( filter_input ( INPUT_POST , $ post_type . '_structure' ) ) ) ; if ( ! $ structure ) { $ structure = CPTP_DEFAULT_PERMALINK ; } $ structure = str_replace ( '//' , '/' , '/' . $ structure ) ; $ lastString = substr ( trim ( esc_attr ( filter_input ( INPUT_POST , 'permalink_structure' ) ) ) , - 1 ) ; $ structure = rtrim ( $ structure , '/' ) ; if ( '/' === $ lastString ) { $ structure = $ structure . '/' ; } update_option ( $ post_type . '_structure' , $ structure ) ; endforeach ; $ no_taxonomy_structure = ! filter_input ( INPUT_POST , 'no_taxonomy_structure' ) ; $ add_post_type_for_tax = filter_input ( INPUT_POST , 'add_post_type_for_tax' ) ; update_option ( 'no_taxonomy_structure' , $ no_taxonomy_structure ) ; update_option ( 'add_post_type_for_tax' , $ add_post_type_for_tax ) ; update_option ( 'cptp_permalink_checked' , CPTP_VERSION ) ; } | Save Options . |
48,431 | public function upgrader_process_complete ( $ wp_upgrader , $ options ) { if ( empty ( $ options [ 'plugins' ] ) ) { return ; } if ( ! is_array ( $ options [ 'plugins' ] ) ) { return ; } if ( 'update' === $ options [ 'action' ] && 'plugin' === $ options [ 'type' ] ) { $ plugin_path = plugin_basename ( CPTP_PLUGIN_FILE ) ; if ( in_array ( $ plugin_path , $ options [ 'plugins' ] , true ) ) { add_option ( 'no_taxonomy_structure' , false ) ; } } } | After update complete . |
48,432 | public function getarchives_where ( $ where , $ r ) { $ this -> get_archives_where_r = $ r ; if ( isset ( $ r [ 'post_type' ] ) ) { if ( ! in_array ( $ r [ 'post_type' ] , CPTP_Util :: get_post_types ( ) , true ) ) { return $ where ; } $ post_type = get_post_type_object ( $ r [ 'post_type' ] ) ; if ( ! $ post_type ) { return $ where ; } if ( ! $ post_type -> has_archive ) { return $ where ; } $ where = str_replace ( '\'post\'' , '\'' . $ r [ 'post_type' ] . '\'' , $ where ) ; } if ( isset ( $ r [ 'taxonomy' ] ) && is_array ( $ r [ 'taxonomy' ] ) ) { global $ wpdb ; $ where = $ where . " AND $wpdb->term_taxonomy.taxonomy = '" . $ r [ 'taxonomy' ] [ 'name' ] . "' AND $wpdb->term_taxonomy.term_id = '" . $ r [ 'taxonomy' ] [ 'termid' ] . "'" ; } return $ where ; } | Get archive where . |
48,433 | public function activate ( ) { foreach ( $ this -> modules as $ module ) { $ module -> activation_hook ( ) ; } register_uninstall_hook ( CPTP_PLUGIN_FILE , array ( __CLASS__ , 'uninstall' ) ) ; } | Activation Hooks This function will browse initialized modules and execute their activation_hook methods . It will also set the uninstall_hook to the cptp_uninstall function which behaves the same way as this one . |
48,434 | public static function uninstall ( ) { $ cptp = CPTP :: get_instance ( ) ; foreach ( $ cptp -> modules as $ module ) { $ module -> uninstall_hook ( ) ; } } | Uninstall Hooks This function will browse initialized modules and execute their uninstall_hook methods . |
48,435 | public static function get_post_types ( ) { $ param = array ( '_builtin' => false , 'public' => true , ) ; $ post_type = get_post_types ( $ param ) ; return array_filter ( $ post_type , array ( __CLASS__ , 'is_rewrite_supported_by' ) ) ; } | Get filtered post type . |
48,436 | private static function is_rewrite_supported_by ( $ post_type ) { $ post_type_object = get_post_type_object ( $ post_type ) ; if ( false === $ post_type_object -> rewrite ) { $ support = false ; } else { $ support = true ; } $ support = apply_filters ( "CPTP_is_rewrite_supported_by_${post_type}" , $ support ) ; return apply_filters ( 'CPTP_is_rewrite_supported' , $ support , $ post_type ) ; } | Check post type support rewrite . |
48,437 | public static function get_taxonomies ( $ objects = false ) { if ( $ objects ) { $ output = 'objects' ; } else { $ output = 'names' ; } return get_taxonomies ( array ( 'public' => true , '_builtin' => false , ) , $ output ) ; } | Get taxonomies . |
48,438 | public static function get_taxonomy_parents_slug ( $ term , $ taxonomy = 'category' , $ separator = '/' , $ nicename = false , $ visited = array ( ) ) { $ chain = '' ; $ parent = get_term ( $ term , $ taxonomy ) ; if ( is_wp_error ( $ parent ) ) { return $ parent ; } if ( $ nicename ) { $ name = $ parent -> slug ; } else { $ name = $ parent -> name ; } if ( $ parent -> parent && ( $ parent -> parent !== $ parent -> term_id ) && ! in_array ( $ parent -> parent , $ visited , true ) ) { $ visited [ ] = $ parent -> parent ; $ chain .= CPTP_Util :: get_taxonomy_parents_slug ( $ parent -> parent , $ taxonomy , $ separator , $ nicename , $ visited ) ; } $ chain .= $ name . $ separator ; return $ chain ; } | Get Custom Taxonomies parents slug . |
48,439 | public static function get_taxonomy_parents ( $ term , $ taxonomy = 'category' , $ link = false , $ separator = '/' , $ nicename = false , $ visited = array ( ) ) { $ chain = '' ; $ parent = get_term ( $ term , $ taxonomy ) ; if ( is_wp_error ( $ parent ) ) { return $ parent ; } if ( $ nicename ) { $ name = $ parent -> slug ; } else { $ name = $ parent -> name ; } if ( $ parent -> parent && ( $ parent -> parent !== $ parent -> term_id ) && ! in_array ( $ parent -> parent , $ visited , true ) ) { $ visited [ ] = $ parent -> parent ; $ chain .= CPTP_Util :: get_taxonomy_parents ( $ parent -> parent , $ taxonomy , $ link , $ separator , $ nicename , $ visited ) ; } if ( $ link ) { $ chain .= '<a href="' . get_term_link ( $ parent -> term_id , $ taxonomy ) . '" title="' . esc_attr ( sprintf ( __ ( 'View all posts in %s' ) , $ parent -> name ) ) . '">' . esc_html ( $ name ) . '</a>' . esc_html ( $ separator ) ; } else { $ chain .= $ name . $ separator ; } return $ chain ; } | Get Custom Taxonomies parents . |
48,440 | public static function get_permalink_structure ( $ post_type ) { if ( is_string ( $ post_type ) ) { $ post_type = get_post_type_object ( $ post_type ) ; } if ( ! empty ( $ post_type -> cptp ) && ! empty ( $ post_type -> cptp [ 'permalink_structure' ] ) ) { $ structure = $ post_type -> cptp -> permalink_structure ; } else if ( ! empty ( $ post_type -> cptp_permalink_structure ) ) { $ structure = $ post_type -> cptp_permalink_structure ; } else { $ structure = get_option ( $ post_type -> name . '_structure' , '%postname%' ) ; } $ structure = '/' . ltrim ( $ structure , '/' ) ; return apply_filters ( 'CPTP_' . $ post_type -> name . '_structure' , $ structure ) ; } | Get permalink structure . |
48,441 | public static function get_post_type_date_archive_support ( $ post_type ) { if ( is_string ( $ post_type ) ) { $ post_type = get_post_type_object ( $ post_type ) ; } if ( ! empty ( $ post_type -> cptp ) && isset ( $ post_type -> cptp [ 'date_archive' ] ) ) { return ! ! $ post_type -> cptp [ 'date_archive' ] ; } return true ; } | Check support date archive . |
48,442 | public static function get_post_type_author_archive_support ( $ post_type ) { if ( is_string ( $ post_type ) ) { $ post_type = get_post_type_object ( $ post_type ) ; } if ( ! empty ( $ post_type -> cptp ) && isset ( $ post_type -> cptp [ 'author_archive' ] ) ) { return ! ! $ post_type -> cptp [ 'author_archive' ] ; } return true ; } | Check support author archive . |
48,443 | public static function get_date_front ( $ post_type ) { $ structure = CPTP_Util :: get_permalink_structure ( $ post_type ) ; $ front = '' ; preg_match_all ( '/%.+?%/' , $ structure , $ tokens ) ; $ tok_index = 1 ; foreach ( ( array ) $ tokens [ 0 ] as $ token ) { if ( '%post_id%' === $ token && ( $ tok_index <= 3 ) ) { $ front = '/date' ; break ; } $ tok_index ++ ; } return apply_filters ( 'CPTP_date_front' , $ front , $ post_type , $ structure ) ; } | Get permalink structure front for date archive . |
48,444 | public static function sort_terms ( $ terms , $ orderby = 'term_id' , $ order = 'ASC' ) { if ( function_exists ( 'wp_list_sort' ) ) { $ terms = wp_list_sort ( $ terms , 'term_id' , 'ASC' ) ; } else { if ( 'name' === $ orderby ) { usort ( $ terms , '_usort_terms_by_name' ) ; } else { usort ( $ terms , '_usort_terms_by_ID' ) ; } if ( 'DESC' === $ order ) { $ terms = array_reverse ( $ terms ) ; } } return $ terms ; } | Sort Terms . |
48,445 | public function add_hook ( ) { add_filter ( 'post_type_link' , array ( $ this , 'post_type_link' ) , apply_filters ( 'cptp_post_type_link_priority' , 0 ) , 4 ) ; add_filter ( 'term_link' , array ( $ this , 'term_link' ) , apply_filters ( 'cptp_term_link_priority' , 0 ) , 3 ) ; add_filter ( 'attachment_link' , array ( $ this , 'attachment_link' ) , apply_filters ( 'cptp_attachment_link_priority' , 20 ) , 2 ) ; } | Add Filter Hooks . |
48,446 | private function create_taxonomy_replace_tag ( $ post_id , $ permalink ) { $ search = array ( ) ; $ replace = array ( ) ; $ taxonomies = CPTP_Util :: get_taxonomies ( true ) ; foreach ( $ taxonomies as $ taxonomy => $ objects ) { if ( false !== strpos ( $ permalink , '%' . $ taxonomy . '%' ) ) { $ terms = get_the_terms ( $ post_id , $ taxonomy ) ; if ( $ terms && ! is_wp_error ( $ terms ) ) { $ parents = array_map ( array ( __CLASS__ , 'get_term_parent' ) , $ terms ) ; $ newTerms = array ( ) ; foreach ( $ terms as $ key => $ term ) { if ( ! in_array ( $ term -> term_id , $ parents , true ) ) { $ newTerms [ ] = $ term ; } } $ term_obj = reset ( $ newTerms ) ; $ term_slug = $ term_obj -> slug ; if ( isset ( $ term_obj -> parent ) && $ term_obj -> parent ) { $ term_slug = CPTP_Util :: get_taxonomy_parents_slug ( $ term_obj -> parent , $ taxonomy , '/' , true ) . $ term_slug ; } } if ( isset ( $ term_slug ) ) { $ search [ ] = '%' . $ taxonomy . '%' ; $ replace [ ] = $ term_slug ; } } } return array ( 'search' => $ search , 'replace' => $ replace , ) ; } | Create %tax% - > term |
48,447 | public function attachment_link ( $ link , $ post_id ) { global $ wp_rewrite ; if ( ! $ wp_rewrite -> permalink_structure ) { return $ link ; } $ post = get_post ( $ post_id ) ; if ( ! $ post -> post_parent ) { return $ link ; } $ post_parent = get_post ( $ post -> post_parent ) ; if ( ! $ post_parent ) { return $ link ; } $ pt_object = get_post_type_object ( $ post_parent -> post_type ) ; if ( empty ( $ pt_object -> rewrite ) ) { return $ link ; } if ( ! in_array ( $ post -> post_type , CPTP_Util :: get_post_types ( ) , true ) ) { return $ link ; } $ permalink = CPTP_Util :: get_permalink_structure ( $ post_parent -> post_type ) ; $ post_type = get_post_type_object ( $ post_parent -> post_type ) ; if ( empty ( $ post_type -> _builtin ) ) { if ( strpos ( $ permalink , '%postname%' ) < strrpos ( $ permalink , '%post_id%' ) && false === strrpos ( $ link , 'attachment/' ) ) { $ link = str_replace ( $ post -> post_name , 'attachment/' . $ post -> post_name , $ link ) ; } } return $ link ; } | Fix attachment output |
48,448 | public function term_link ( $ termlink , $ term , $ taxonomy ) { global $ wp_rewrite ; if ( ! $ wp_rewrite -> permalink_structure ) { return $ termlink ; } if ( CPTP_Util :: get_no_taxonomy_structure ( ) ) { return $ termlink ; } $ taxonomy = get_taxonomy ( $ taxonomy ) ; if ( empty ( $ taxonomy ) ) { return $ termlink ; } if ( $ taxonomy -> _builtin ) { return $ termlink ; } if ( ! $ taxonomy -> public ) { return $ termlink ; } $ wp_home = rtrim ( home_url ( ) , '/' ) ; if ( in_array ( get_post_type ( ) , $ taxonomy -> object_type , true ) ) { $ post_type = get_post_type ( ) ; } else { $ post_type = $ taxonomy -> object_type [ 0 ] ; } $ front = substr ( $ wp_rewrite -> front , 1 ) ; $ termlink = str_replace ( $ front , '' , $ termlink ) ; $ post_type_obj = get_post_type_object ( $ post_type ) ; if ( empty ( $ post_type_obj ) ) { return $ termlink ; } $ slug = $ post_type_obj -> rewrite [ 'slug' ] ; $ with_front = $ post_type_obj -> rewrite [ 'with_front' ] ; if ( $ with_front ) { $ slug = $ front . $ slug ; } if ( ! empty ( $ slug ) ) { $ termlink = str_replace ( $ wp_home , $ wp_home . '/' . $ slug , $ termlink ) ; } if ( ! $ taxonomy -> rewrite [ 'hierarchical' ] ) { $ termlink = str_replace ( $ term -> slug . '/' , CPTP_Util :: get_taxonomy_parents_slug ( $ term -> term_id , $ taxonomy -> name , '/' , true ) , $ termlink ) ; } return $ termlink ; } | Fix taxonomy link outputs . |
48,449 | public function update_rules ( ) { $ post_types = CPTP_Util :: get_post_types ( ) ; foreach ( $ post_types as $ post_type ) { add_action ( 'update_option_' . $ post_type . '_structure' , array ( __CLASS__ , 'queue_flush_rules' ) , 10 , 2 ) ; } add_action ( 'update_option_no_taxonomy_structure' , array ( __CLASS__ , 'queue_flush_rules' ) , 10 , 2 ) ; } | Add hook flush_rules |
48,450 | public function setting_section_callback_function ( ) { $ sptp_link = admin_url ( 'plugin-install.php?s=simple-post-type-permalinks&tab=search&type=term' ) ; $ sptp_template = __ ( 'If you need post type permalink only, you should use <a href="%s">Simple Post Type Permalinks</a>.' , 'custom-post-type-permalinks' ) ; ?> <p> <strong> <?php $ allowed_html = array ( 'a' => array ( 'href' => true , ) , ) ; echo wp_kses ( sprintf ( $ sptp_template , esc_url ( $ sptp_link ) ) , $ allowed_html ) ; ?> </strong> </p> <?php $ allowed_html_code_tag = array ( 'code' => array ( ) , ) ; ?> <p> <?php echo wp_kses ( __ ( 'The tags you can use are WordPress Structure Tags and <code>%"custom_taxonomy_slug"%</code> (e.g. <code>%actors%</code> or <code>%movie_actors%</code>).' , 'custom-post-type-permalinks' ) , $ allowed_html_code_tag ) ; ?> <?php echo wp_kses ( __ ( '<code>%"custom_taxonomy_slug"%</code> is replaced by the term of taxonomy.' , 'custom-post-type-permalinks' ) , $ allowed_html_code_tag ) ; ?> </p> <p> <?php esc_html_e ( "Presence of the trailing '/' is unified into a standard permalink structure setting." , 'custom-post-type-permalinks' ) ; ?> <p> <?php echo wp_kses ( __ ( 'If <code>has_archive</code> is true, add permalinks for custom post type archive.' , 'custom-post-type-permalinks' ) , $ allowed_html_code_tag ) ; ?> </p> <?php } | Setting section view . |
48,451 | public function setting_structure_callback_function ( $ option ) { $ post_type = $ option [ 'post_type' ] ; $ name = $ option [ 'label_for' ] ; $ pt_object = get_post_type_object ( $ post_type ) ; $ slug = $ pt_object -> rewrite [ 'slug' ] ; $ with_front = $ pt_object -> rewrite [ 'with_front' ] ; $ value = CPTP_Util :: get_permalink_structure ( $ post_type ) ; $ disabled = false ; if ( isset ( $ pt_object -> cptp_permalink_structure ) && $ pt_object -> cptp_permalink_structure ) { $ disabled = true ; } if ( ! $ value ) { $ value = CPTP_DEFAULT_PERMALINK ; } global $ wp_rewrite ; $ front = substr ( $ wp_rewrite -> front , 1 ) ; if ( $ front && $ with_front ) { $ slug = $ front . $ slug ; } ?> <p> <code> <?php echo esc_html ( home_url ( ) . ( $ slug ? '/' : '' ) . $ slug ) ; ?> </code> <input name=" <?php echo esc_attr ( $ name ) ; ?> " id=" <?php echo esc_attr ( $ name ) ; ?> " type="text" class="regular-text code " value=" <?php echo esc_attr ( $ value ) ; ?> " <?php disabled ( $ disabled , true , true ) ; ?> /> </p> <p>has_archive: <code> <?php echo esc_html ( $ pt_object -> has_archive ? 'true' : 'false' ) ; ?> </code> / with_front: <code> <?php echo esc_html ( $ pt_object -> rewrite [ 'with_front' ] ? 'true' : 'false' ) ; ?> </code></p> <?php } | Show setting structure input . |
48,452 | public function setting_no_tax_structure_callback_function ( ) { $ no_taxonomy_structure = CPTP_Util :: get_no_taxonomy_structure ( ) ; echo '<input name="no_taxonomy_structure" id="no_taxonomy_structure" type="checkbox" value="1" class="code" ' . checked ( false , $ no_taxonomy_structure , false ) . ' /> ' ; $ txt = __ ( "If you check this, the custom taxonomy's permalinks will be <code>%s/post_type/taxonomy/term</code>." , 'custom-post-type-permalinks' ) ; echo sprintf ( wp_kses ( $ txt , array ( 'code' => array ( ) ) ) , esc_html ( home_url ( ) ) ) ; } | Show checkbox no tax . |
48,453 | public function enqueue_css_js ( ) { $ pointer_name = 'custom-post-type-permalinks-settings' ; if ( ! is_network_admin ( ) ) { $ dismissed = explode ( ',' , get_user_meta ( get_current_user_id ( ) , 'dismissed_wp_pointers' , true ) ) ; if ( false === array_search ( $ pointer_name , $ dismissed , true ) ) { $ content = '' ; $ content .= '<h3>' . __ ( 'Custom Post Type Permalinks' , 'custom-post-type-permalinks' ) . '</h3>' ; $ content .= '<p>' . __ ( 'You can setting permalink for post type in <a href="options-permalink.php">Permalinks</a>.' , 'custom-post-type-permalinks' ) . '</p>' ; wp_enqueue_style ( 'wp-pointer' ) ; wp_enqueue_script ( 'wp-pointer' ) ; wp_enqueue_script ( 'custom-post-type-permalinks-pointer' , plugins_url ( 'assets/settings-pointer.js' , CPTP_PLUGIN_FILE ) , array ( 'wp-pointer' ) , CPTP_VERSION ) ; wp_localize_script ( 'custom-post-type-permalinks-pointer' , 'CPTP_Settings_Pointer' , array ( 'content' => $ content , 'name' => $ pointer_name , ) ) ; } } } | Enqueue css and js |
48,454 | public function admin_notices ( ) { if ( version_compare ( get_option ( 'cptp_permalink_checked' ) , '3.0.0' , '<' ) ) { $ format = __ ( '[Custom Post Type Permalinks] <a href="%s"><strong>Please check your permalink settings!</strong></a>' , 'custom-post-type-permalinks' ) ; $ message = sprintf ( $ format , admin_url ( 'options-permalink.php' ) ) ; echo sprintf ( '<div class="notice notice-warning"><p>%s</p></div>' , wp_kses ( $ message , wp_kses_allowed_html ( 'post' ) ) ) ; } } | Admin notice for update permalink settings! |
48,455 | public function mailPassword ( $ to , $ subject , $ data ) { $ this -> mail -> send ( 'blogify::mails.password' , [ 'data' => $ data ] , function ( $ message ) use ( $ to , $ subject ) { $ message -> to ( $ to ) -> subject ( $ subject ) ; } ) ; } | Mail the generated password to the newly created user |
48,456 | public function mailReviewer ( $ to , $ subject , $ data ) { $ this -> mail -> send ( 'blogify::mails.notifyReviewer' , [ 'data' => $ data ] , function ( $ message ) use ( $ to , $ subject ) { $ message -> to ( $ to ) -> subject ( $ subject ) ; } ) ; } | Send a notification mail to the assigned reviewer |
48,457 | public function boot ( ) { include __DIR__ . '/routes.php' ; $ this -> publish ( ) ; $ this -> loadViewsFrom ( __DIR__ . '/../views' , 'blogify' ) ; $ this -> loadViewsFrom ( __DIR__ . '/../Example/Views' , 'blogifyPublic' ) ; $ this -> mergeConfigFrom ( __DIR__ . '/../config/blogify.php' , 'blogify' ) ; $ this -> loadTranslationsFrom ( __DIR__ . '/../lang/' , 'blogify' ) ; $ this -> registerCommands ( ) ; $ this -> app [ 'validator' ] -> resolver ( function ( $ translator , $ data , $ rules , $ messages = array ( ) , $ customAttributes = array ( ) ) { return new Validation ( $ translator , $ data , $ rules , $ messages , $ customAttributes ) ; } ) ; } | Load the resources |
48,458 | public function generateUniqueUsername ( $ lastname , $ firstname , $ iteration = 0 ) { $ username = strtolower ( str_replace ( ' ' , '' , $ lastname ) . substr ( $ firstname , 0 , 1 ) ) ; if ( $ iteration != 0 ) { $ username = $ username . $ iteration ; } $ usernames = count ( $ this -> db -> table ( 'users' ) -> where ( 'username' , '=' , $ username ) -> get ( ) ) ; if ( $ usernames > 0 ) { return $ this -> generateUniqueUsername ( $ lastname , $ firstname , $ iteration + 1 ) ; } return $ username ; } | Generate a unique username with the users lastname and firstname |
48,459 | private function storeOrUpdateCategory ( $ request ) { $ cat = $ this -> category -> whereName ( $ request -> name ) -> first ( ) ; if ( count ( $ cat ) > 0 ) { $ category = $ cat ; } else { $ category = new Category ; $ category -> hash = $ this -> blogify -> makeHash ( 'categories' , 'hash' , true ) ; } $ category -> name = $ request -> name ; $ category -> save ( ) ; return $ category ; } | Save the given category in the db |
48,460 | public function sort ( $ table , $ column , $ order , $ trashed = false , DatabaseManager $ db ) { $ db = $ db -> connection ( ) ; $ data = $ db -> table ( $ table ) ; $ data = $ trashed ? $ data -> whereNotNull ( 'deleted_at' ) : $ data -> whereNull ( 'deleted_at' ) ; if ( $ table == 'users' ) { $ data = $ data -> join ( 'roles' , 'users.role_id' , '=' , 'roles.id' ) ; } if ( $ table == 'posts' ) { $ data = $ data -> join ( 'statuses' , 'posts.status_id' , '=' , 'statuses.id' ) ; } $ data = $ data -> orderBy ( $ column , $ order ) -> paginate ( $ this -> config -> items_per_page ) ; return $ data ; } | Order the data of a given table on the given column and the given order |
48,461 | public function checkIfSlugIsUnique ( $ slug ) { $ i = 0 ; $ this -> base_slug = $ slug ; while ( $ this -> post -> whereSlug ( $ slug ) -> get ( ) -> count ( ) > 0 ) { $ i ++ ; $ slug = "$this->base_slug-$i" ; } return $ slug ; } | Check if a given slug already exists and when it exists generate a new one |
48,462 | public function autoSave ( Cache $ cache , Request $ request ) { try { $ hash = $ this -> auth_user -> hash ; $ cache -> put ( "autoSavedPost-$hash" , $ request -> all ( ) , Carbon :: now ( ) -> addHours ( 2 ) ) ; } catch ( BlogifyException $ exception ) { return response ( ) -> json ( [ false , date ( 'd-m-Y H:i:s' ) ] ) ; } return response ( ) -> json ( [ true , date ( 'd-m-Y H:i:s' ) ] ) ; } | Save the current post in the cache |
48,463 | private function createUsersTable ( ) { Schema :: create ( 'users' , function ( $ table ) { foreach ( $ this -> fields as $ field => $ value ) { $ query = $ table -> $ value [ 'type' ] ( $ field ) ; if ( isset ( $ value [ 'extra' ] ) ) { $ query -> $ value [ 'extra' ] ( ) ; } } $ table -> foreign ( 'role_id' ) -> references ( 'id' ) -> on ( 'roles' ) ; $ table -> timestamps ( ) ; $ table -> softDeletes ( ) ; } ) ; } | Create a new Users table with all the required fields |
48,464 | private function updateUsersTable ( ) { Schema :: table ( 'users' , function ( $ table ) { foreach ( $ this -> fields as $ field => $ value ) { if ( ! Schema :: hasColumn ( 'users' , $ field ) ) { $ type = $ value [ 'type' ] ; $ query = $ table -> $ type ( $ field ) ; if ( isset ( $ value [ 'extra' ] ) ) { $ extra = $ value [ 'extra' ] ; $ query -> $ extra ( ) ; } if ( $ field == 'role_id' ) { $ table -> foreign ( 'role_id' ) -> references ( 'id' ) -> on ( 'roles' ) ; } } } if ( ! Schema :: hasColumn ( 'users' , 'created_at' ) && ! Schema :: hasColumn ( 'users' , 'updated_at' ) ) { $ table -> timestamps ( ) ; } if ( ! Schema :: hasColumn ( 'users' , 'deleted_at' ) ) { $ table -> softDeletes ( ) ; } } ) ; } | Add the not existing columns to the existing users table |
48,465 | public function store ( PostRequest $ request ) { $ this -> data = objectify ( $ request -> except ( [ '_token' , 'newCategory' , 'newTags' ] ) ) ; if ( ! empty ( $ this -> data -> tags ) ) { $ this -> buildTagsArray ( ) ; } $ post = $ this -> storeOrUpdatePost ( ) ; if ( $ this -> status -> byHash ( $ this -> data -> status ) -> name == 'Pending review' ) { $ this -> mailReviewer ( $ post ) ; } $ action = ( $ request -> hash == '' ) ? 'created' : 'updated' ; $ this -> tracert -> log ( 'posts' , $ post -> id , $ this -> auth_user -> id , $ action ) ; $ message = trans ( 'blogify::notify.success' , [ 'model' => 'Post' , 'name' => $ post -> title , 'action' => $ action ] ) ; session ( ) -> flash ( 'notify' , [ 'success' , $ message ] ) ; $ hash = $ this -> auth_user -> hash ; $ this -> cache -> forget ( "autoSavedPost-$hash" ) ; return redirect ( ) -> route ( 'admin.posts.index' ) ; } | Store or update a post |
48,466 | public function uploadImage ( ImageUploadRequest $ request ) { $ image_name = $ this -> resizeAndSaveImage ( $ request -> file ( 'upload' ) ) ; $ path = config ( 'app.url' ) . '/uploads/posts/' . $ image_name ; $ func = $ request -> get ( 'CKEditorFuncNum' ) ; $ result = "<script>window.parent.CKEDITOR.tools.callFunction($func, '$path', 'Image has been uploaded')</script>" ; return $ result ; } | Function to upload images using the SKEditor |
48,467 | public function cancel ( $ hash = null ) { if ( ! isset ( $ hash ) ) { return redirect ( ) -> route ( 'admin.posts.index' ) ; } $ userHash = $ this -> auth_user -> hash ; if ( $ this -> cache -> has ( "autoSavedPost-$userHash" ) ) { $ this -> cache -> forget ( "autoSavedPost-$userHash" ) ; } $ post = $ this -> post -> byHash ( $ hash ) ; $ post -> being_edited_by = null ; $ post -> save ( ) ; $ this -> tracert -> log ( 'posts' , $ post -> id , $ this -> auth_user -> id , 'canceled' ) ; $ message = trans ( 'blogify::notify.success' , [ 'model' => 'Post' , 'name' => $ post -> name , 'action' => 'canceled' ] ) ; session ( ) -> flash ( 'notify' , [ 'success' , $ message ] ) ; return redirect ( ) -> route ( 'admin.posts.index' ) ; } | Cancel changes in a post and set being_edited_by back to null |
48,468 | private function getViewData ( $ post = null ) { return [ 'reviewers' => $ this -> user -> reviewers ( ) , 'statuses' => $ this -> status -> all ( ) , 'categories' => $ this -> category -> all ( ) , 'visibility' => $ this -> visibility -> all ( ) , 'publish_date' => Carbon :: now ( ) -> format ( 'd-m-Y H:i' ) , 'post' => $ post , ] ; } | Get the default data for the create and edit view |
48,469 | private function buildPostObject ( ) { $ hash = $ this -> auth_user -> hash ; $ cached_post = $ this -> cache -> get ( "autoSavedPost-$hash" ) ; $ post = [ ] ; $ post [ 'hash' ] = '' ; $ post [ 'title' ] = $ cached_post [ 'title' ] ; $ post [ 'slug' ] = $ cached_post [ 'slug' ] ; $ post [ 'content' ] = $ cached_post [ 'content' ] ; $ post [ 'publish_date' ] = $ cached_post [ 'publishdate' ] ; $ post [ 'status_id' ] = $ this -> status -> byHash ( $ cached_post [ 'status' ] ) -> id ; $ post [ 'visibility_id' ] = $ this -> visibility -> byHash ( $ cached_post [ 'visibility' ] ) -> id ; $ post [ 'reviewer_id' ] = $ this -> user -> byHash ( $ cached_post [ 'reviewer' ] ) -> id ; $ post [ 'category_id' ] = $ this -> category -> byHash ( $ cached_post [ 'category' ] ) -> id ; $ post [ 'tag' ] = $ this -> buildTagsArrayForPostObject ( $ cached_post [ 'tags' ] ) ; return objectify ( $ post ) ; } | Build a post object when there is a cached post so we can put the data back in the form |
48,470 | public function getApp ( ) { if ( ! self :: $ _app instanceof Application ) { self :: $ _app = new Application ( Yii :: $ app -> params [ 'WECHAT' ] ) ; } return self :: $ _app ; } | single instance of EasyWeChat \ Foundation \ Application |
48,471 | protected function getOptions ( ) { $ this -> options [ 'allowOutsideClick' ] = ArrayHelper :: getValue ( $ this -> options , 'allowOutsideClick' , $ this -> allowOutsideClick ) ; $ this -> options [ 'timer' ] = ArrayHelper :: getValue ( $ this -> options , 'timer' , $ this -> timer ) ; $ this -> options [ 'type' ] = ArrayHelper :: getValue ( $ this -> options , 'type' , $ this -> type ) ; return Json :: encode ( $ this -> options ) ; } | Get plugin options |
48,472 | public function fill ( array $ attributes ) { foreach ( $ attributes as $ key => $ value ) { if ( array_search ( $ key , $ this -> fillable ) !== false ) { $ this -> { $ key } = $ value ; } } } | Fills the part with attributes . |
48,473 | public function isRequired ( ) : bool { return ( $ this -> docBlockUtility -> getConstraint ( $ this -> property , NotBlank :: class ) || $ this -> docBlockUtility -> getConstraint ( $ this -> property , NotNull :: class ) ) ; } | Get whether the param is required . |
48,474 | public function isArray ( ) : bool { return ( bool ) $ this -> docBlockUtility -> getConstraint ( $ this -> property , All :: class , false ) ; } | Get whether the param is an array ; having an All Constraint . |
48,475 | public function getRegex ( ) { if ( $ constraint = $ this -> docBlockUtility -> getConstraint ( $ this -> property , ApiRegex :: class ) ) { return $ constraint -> pattern ; } } | Get the Regex assertion pattern if it exists . |
48,476 | public function getChoices ( ) { if ( $ constraint = $ this -> docBlockUtility -> getConstraint ( $ this -> property , ApiChoice :: class ) ) { return $ constraint -> choices ; } } | Get the array of choices from the Choices assertion if it exists . |
48,477 | public function getUuid ( ) { if ( $ constraint = $ this -> docBlockUtility -> getConstraint ( $ this -> property , Uuid :: class ) ) { return ( $ constraint -> strict ) ? self :: UUID_CONSTRAINT_STRICT_VALUE : self :: UUID_CONSTRAINT_NON_STRICT_VALUE ; } } | Get the UUID type from the Uuid assertion if it exists . |
48,478 | public static function getStringValue ( $ value ) : string { if ( $ value instanceof \ DateTime ) { return $ value -> format ( self :: DEFAULT_DATETIME_FORMAT ) ; } elseif ( is_bool ( $ value ) ) { return $ value ? 'true' : 'false' ; } elseif ( is_array ( $ value ) ) { return implode ( ', ' , array_map ( 'self::getStringValue' , $ value ) ) ; } return ( string ) $ value ; } | Get string output based on the value . |
48,479 | public static function getStringValueAsCode ( $ value ) : string { if ( $ value instanceof \ DateTime ) { return "new \DateTime('" . $ value -> format ( self :: DEFAULT_DATETIME_FORMAT ) . "')" ; } elseif ( is_bool ( $ value ) ) { return $ value ? 'true' : 'false' ; } elseif ( is_array ( $ value ) ) { return '[' . implode ( ', ' , array_map ( 'self::getStringValueAsCode' , array_filter ( $ value ) ) ) . ']' ; } elseif ( is_null ( $ value ) ) { return 'null' ; } elseif ( is_int ( $ value ) || is_float ( $ value ) ) { return ( string ) $ value ; } return "'" . ( string ) $ value . "'" ; } | Get string display output for showing code based on the value . |
48,480 | public function getAllRequestClasses ( ) : array { $ allRequestClasses = [ ] ; foreach ( $ this -> getDomainNames ( ) as $ domainName ) { foreach ( $ this -> getSectionNames ( $ domainName ) as $ sectionName ) { foreach ( $ this -> getCategoryNames ( $ domainName , $ sectionName ) as $ categoryName ) { foreach ( $ this -> getFqcnRequestNames ( $ domainName , $ sectionName , $ categoryName ) as $ fqcnRequestName ) { $ allRequestClasses [ ] = $ fqcnRequestName ; } } } } return $ allRequestClasses ; } | Similar to retrieving all requests but simply returns a single array of all request FQCNs . |
48,481 | public function getRequestInfo ( $ domain , $ section , $ category , $ requestName ) : array { $ allRequests = $ this -> getAllRequests ( ) ; if ( ! isset ( $ allRequests [ $ domain ] [ $ section ] [ $ category ] [ $ requestName ] ) ) { throw new \ Exception ( 'Request not found for given domain, section, and category' ) ; } return $ allRequests [ $ domain ] [ $ section ] [ $ category ] [ $ requestName ] ; } | Get information about a particular request given the domain section category and request name . |
48,482 | public function getGuildsAttribute ( ) { $ response = $ this -> discord -> request ( 'GET' , $ this -> discord -> getGuildsEndpoint ( ) , $ this -> token ) ; $ collection = new Collection ( ) ; foreach ( $ response as $ raw ) { $ collection -> push ( $ this -> discord -> buildPart ( Guild :: class , $ this -> token , $ raw ) ) ; } return $ collection ; } | Gets the guilds attribute . |
48,483 | public function getConnectionsAttribute ( ) { $ response = $ this -> discord -> request ( 'GET' , $ this -> discord -> getConnectionsEndpoint ( ) , $ this -> token ) ; $ collection = new Collection ( ) ; foreach ( $ response as $ raw ) { $ collection -> push ( $ this -> discord -> buildPart ( Connection :: class , $ this -> token , $ raw ) ) ; } return $ collection ; } | Gets the connections attribute . |
48,484 | public function acceptInvite ( $ invite ) { if ( preg_match ( '/https:\/\/discord.gg\/(.+)/' , $ invite , $ matches ) ) { $ invite = $ matches [ 1 ] ; } $ response = $ this -> discord -> request ( 'POST' , $ this -> discord -> getInviteEndpoint ( $ invite ) , $ this -> token ) ; return $ this -> discord -> buildPart ( Invite :: class , $ this -> token , $ response ) ; } | Accepts an invite . |
48,485 | public static function getValue ( $ propertyName , $ methodName ) { $ requestClass = static :: class ; $ abstractParamClass = static :: BASE_PARAM_CLASS ; $ requestValues = $ requestClass :: { $ methodName . 's' } ( ) ; if ( array_key_exists ( $ propertyName , $ requestValues ) ) { return $ requestValues [ $ propertyName ] ; } $ requestTypeParamClass = $ abstractParamClass :: getRequestTypeParamClass ( $ requestClass :: getDomain ( ) , $ propertyName ) ; if ( class_exists ( $ requestTypeParamClass ) && is_subclass_of ( $ requestTypeParamClass , $ abstractParamClass ) ) { $ requestTypeValue = $ requestTypeParamClass :: $ methodName ( ) ; if ( ! is_null ( $ requestTypeValue ) ) { return $ requestTypeValue ; } } $ paramClass = $ abstractParamClass :: getParamClass ( $ propertyName ) ; if ( class_exists ( $ paramClass ) && is_subclass_of ( $ paramClass , $ abstractParamClass ) ) { $ value = $ paramClass :: $ methodName ( ) ; if ( ! is_null ( $ value ) ) { return $ value ; } } } | Get the value of a parameter according to the priority stopping when a value at that priority is found . Note that each param class does not have to specifically define this function ; it rolls up to the base class . |
48,486 | public function getFullUrl ( ) : string { $ queryString = $ this -> getQueryString ( ) ; return sprintf ( '%s%s%s' , static :: getBaseUri ( ) , $ this -> getEndpoint ( ) , ( $ queryString ) ? '/?' . $ queryString : '' ) ; } | Get the full URL endpoint with all parameters and placeholders . |
48,487 | public function getParamNames ( ) : array { $ names = [ ] ; foreach ( $ this -> getPublicProperties ( ) as $ param ) { $ names [ ] = $ param -> getName ( ) ; } return $ names ; } | Get all parameter names which are simply the names of the public properties . |
48,488 | public function getParamsInfo ( ) : array { $ paramsInfo = [ ] ; foreach ( $ this -> getParamNames ( ) as $ paramName ) { $ paramsInfo [ $ paramName ] = $ this -> getParamInfo ( $ paramName ) ; } return $ paramsInfo ; } | Get the meta information for all parameters . |
48,489 | public function getParamInfo ( $ paramName ) { $ propertyUtility = new RequestPropertyUtility ( $ this , $ paramName ) ; return [ 'is_required' => $ propertyUtility -> isRequired ( ) , 'is_array' => $ propertyUtility -> isArray ( ) , 'is_not_blank' => $ propertyUtility -> getNotBlank ( ) , 'is_not_null' => $ propertyUtility -> getNotNull ( ) , 'description' => $ propertyUtility -> getDescription ( ) , 'type' => $ propertyUtility -> getType ( ) , 'default_value' => $ propertyUtility -> getDefaultValue ( ) , 'example_value' => $ propertyUtility -> getExampleValue ( ) , 'default_value_string' => $ propertyUtility -> getDefaultValueAsString ( ) , 'example_value_string' => $ propertyUtility -> getExampleValueAsString ( ) , 'default_value_code' => $ propertyUtility -> getDefaultValueAsCode ( ) , 'example_value_code' => $ propertyUtility -> getExampleValueAsCode ( ) , 'choices' => $ propertyUtility -> getChoices ( ) , 'regex' => $ propertyUtility -> getRegex ( ) , 'range' => $ propertyUtility -> getRange ( ) , 'count' => $ propertyUtility -> getCount ( ) , 'uuid' => $ propertyUtility -> getUuid ( ) , ] ; } | Get the meta information for a single parameter . |
48,490 | public function getParamsAsCode ( ) : array { $ paramsAsCode = [ ] ; foreach ( $ this -> getParamNames ( ) as $ paramName ) { $ paramsAsCode [ $ paramName ] = RequestPropertyUtility :: getStringValueAsCode ( $ this -> $ paramName ) ; } return $ paramsAsCode ; } | Get the parameters converting the values to the code equivalent . |
48,491 | protected function convertParamValueToString ( $ propertyName ) { $ abstractParamClass = static :: BASE_PARAM_CLASS ; $ requestTypeParamClass = $ abstractParamClass :: getRequestTypeParamClass ( $ this :: getDomain ( ) , $ propertyName ) ; if ( class_exists ( $ requestTypeParamClass ) && is_subclass_of ( $ requestTypeParamClass , $ abstractParamClass ) && method_exists ( $ requestTypeParamClass , static :: CONVERT_TO_STRING_METHOD ) ) { return $ requestTypeParamClass :: { static :: CONVERT_TO_STRING_METHOD } ( $ this -> $ propertyName ) ; } $ paramClass = $ abstractParamClass :: getParamClass ( $ propertyName ) ; if ( class_exists ( $ paramClass ) && is_subclass_of ( $ paramClass , $ abstractParamClass ) && method_exists ( $ paramClass , static :: CONVERT_TO_STRING_METHOD ) ) { return $ paramClass :: { static :: CONVERT_TO_STRING_METHOD } ( $ this -> $ propertyName ) ; } return RequestPropertyUtility :: getStringValue ( $ this -> $ propertyName ) ; } | Get the string value of a parameter according to the priority stopping when a value is converted . Note that each param class does not have to specifically define this function ; it rolls up to the base class . |
48,492 | public static function getStringValue ( $ dateTime ) : string { if ( ! $ dateTime ) { return '' ; } if ( ! $ dateTime instanceof \ DateTime ) { return ( new \ DateTime ( $ dateTime ) ) -> format ( static :: DATE_FORMAT ) ; } return $ dateTime -> format ( static :: DATE_FORMAT ) ; } | Take a \ DateTime value and convert it to the string date format that the API expects . |
48,493 | public function getDescription ( $ docComment ) : string { $ docComment = ( string ) $ docComment ; $ description = [ ] ; foreach ( preg_split ( self :: REGEX_SPLIT_BY_NEWLINE , $ docComment ) as $ line ) { if ( ! preg_match ( self :: REGEX_LINE_HAS_CONTENT , $ line , $ matches ) ) { continue ; } $ info = trim ( preg_replace ( self :: REGEX_REMOVE_LEADING_ASTERISK , '' , trim ( $ matches [ 1 ] ) ) ) ; $ addInfo = true ; foreach ( self :: DESCRIPTION_SKIP_TAGS as $ skipTag ) { if ( substr ( $ info , 0 , strlen ( $ skipTag ) ) === $ skipTag ) { $ addInfo = false ; } } if ( $ addInfo ) { $ description [ ] = $ info ; } } return implode ( "\n" , $ description ) ; } | Get the description from a doc comment ; new lines are split by \ n . |
48,494 | public function getConstraint ( \ ReflectionProperty $ reflectionProperty , $ constraintClass , $ getFromAll = true ) { if ( ( $ constraint = $ this -> reader -> getPropertyAnnotation ( $ reflectionProperty , $ constraintClass ) ) && $ constraint instanceof Constraint ) { return $ constraint ; } if ( ! $ getFromAll ) { return ; } if ( ( $ allConstraint = $ this -> getConstraintFromAll ( $ reflectionProperty , $ constraintClass ) ) && $ allConstraint instanceof Constraint ) { return $ allConstraint ; } } | Retrieve a specific constraint of a property ; defaults to retrieving from the All constraint if that exists . |
48,495 | public function getConstraintFromAll ( \ ReflectionProperty $ reflectionProperty , $ constraintClass ) { if ( ! ( $ allConstraint = $ this -> getConstraint ( $ reflectionProperty , All :: class , false ) ) ) { return ; } foreach ( $ allConstraint -> constraints as $ constraint ) { if ( $ constraint instanceof $ constraintClass ) { return $ constraint ; } } } | Retrieve a specific Symfony Constraint from within a Symfony All Constraint . |
48,496 | private function getConfig ( $ key = null , $ args = null ) { if ( $ key != null ) { $ value = null ; if ( isset ( $ this -> _config [ $ key ] ) ) { $ value = $ this -> _config [ $ key ] ; } elseif ( isset ( $ this -> _updateConfig [ $ key ] ) ) { $ value = $ this -> _updateConfig [ $ key ] ; } if ( isset ( $ args [ "returnAsArray" ] ) && $ args [ "returnAsArray" ] ) { if ( is_array ( $ value ) ) { return $ value ; } } elseif ( is_array ( $ value ) ) { $ to_return = CheckoutApi_Lib_Factory :: getInstance ( 'CheckoutApi_Lib_RespondObj' ) ; $ to_return -> setConfig ( $ value ) ; return $ to_return ; } return $ value ; } if ( $ key == null ) { return $ this -> _config ; } return null ; } | This method return value from the attribute config |
48,497 | public static function getSingletonInstance ( $ className , array $ arguments = array ( ) ) { $ registerKey = $ className ; if ( ! isset ( self :: $ _registry [ $ registerKey ] ) ) { if ( class_exists ( $ className ) ) { self :: $ _registry [ $ registerKey ] = new $ className ( $ arguments ) ; } else { throw new Exception ( 'Invalid class name:: ' . $ className . "(" . print_r ( $ arguments , 1 ) . ')' ) ; } } return self :: $ _registry [ $ registerKey ] ; } | This helper method create a singleton object given the name of the class |
48,498 | public static function isEmpty ( $ var ) { $ toReturn = false ; if ( is_array ( $ var ) && empty ( $ var ) ) { $ toReturn = true ; } if ( is_string ( $ var ) && ( $ var == '' || is_null ( $ var ) ) ) { $ toReturn = true ; } if ( is_integer ( $ var ) && ( $ var == '' || is_null ( $ var ) ) ) { $ toReturn = true ; } if ( is_float ( $ var ) && ( $ var == '' || is_null ( $ var ) ) ) { $ toReturn = true ; } return $ toReturn ; } | A helper method that check if variable is empty |
48,499 | public function getCardToken ( array $ param ) { $ hasError = false ; $ param [ 'postedParam' ] [ 'type' ] = CheckoutApi_Client_Constant :: TOKEN_CARD_TYPE ; $ postedParam = $ param [ 'postedParam' ] ; $ this -> flushState ( ) ; $ isEmailValid = CheckoutApi_Client_Validation_GW3 :: isEmailValid ( $ postedParam ) ; $ isCardValid = CheckoutApi_Client_Validation_GW3 :: isCardValid ( $ postedParam ) ; $ uri = $ this -> getUriToken ( ) . '/card' ; return $ this -> request ( $ uri , $ param , ! $ hasError ) ; } | Create Card Token |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.