idx
int64
0
241k
question
stringlengths
64
6.21k
target
stringlengths
5
803
7,900
protected function setMargins ( ) { $ this -> _margeLeft = $ this -> _defaultLeft + ( isset ( $ this -> _background [ 'left' ] ) ? $ this -> _background [ 'left' ] : 0 ) ; $ this -> _margeRight = $ this -> _defaultRight + ( isset ( $ this -> _background [ 'right' ] ) ? $ this -> _background [ 'right' ] : 0 ) ; $ this -...
set the real margin using the default margins and the page margins
7,901
protected function _addMargins ( $ float , $ xLeft , $ yTop , $ xRight , $ yBottom ) { $ oldTop = $ this -> _getMargins ( $ yTop ) ; $ oldBottom = $ this -> _getMargins ( $ yBottom ) ; if ( $ float === 'left' && $ oldTop [ 0 ] < $ xRight ) { $ oldTop [ 0 ] = $ xRight ; } if ( $ float === 'right' && $ oldTop [ 1 ] > $ x...
Add margins for a float
7,902
protected function _setPageHeader ( ) { if ( ! count ( $ this -> _subHEADER ) ) { return false ; } if ( in_array ( $ this -> pdf -> getPage ( ) , $ this -> _hideHeader ) ) { return false ; } $ oldParsePos = $ this -> _parsePos ; $ oldParseCode = $ this -> parsingHtml -> code ; $ this -> _parsePos = 0 ; $ this -> parsin...
draw the PDF header with the HTML in page_header
7,903
protected function _setPageFooter ( ) { if ( ! count ( $ this -> _subFOOTER ) ) { return false ; } if ( in_array ( $ this -> pdf -> getPage ( ) , $ this -> _hideFooter ) ) { return false ; } $ oldParsePos = $ this -> _parsePos ; $ oldParseCode = $ this -> parsingHtml -> code ; $ this -> _parsePos = 0 ; $ this -> parsin...
draw the PDF footer with the HTML in page_footer
7,904
protected function _setNewLine ( $ h , $ curr = null ) { $ this -> pdf -> Ln ( $ h ) ; $ this -> _setNewPositionForNewLine ( $ curr ) ; }
new line with a specific height
7,905
protected function createSubHTML ( ) { if ( self :: $ _subobj === null ) { $ this -> _prepareSubObj ( ) ; } if ( $ this -> parsingCss -> value [ 'width' ] ) { $ marge = $ this -> parsingCss -> value [ 'padding' ] [ 'l' ] + $ this -> parsingCss -> value [ 'padding' ] [ 'r' ] ; $ marge += $ this -> parsingCss -> value [ ...
create a sub Html2Pdf to calculate the multi - tables
7,906
protected function _listeArab2Rom ( $ nbArabic ) { $ nbBaseTen = array ( 'I' , 'X' , 'C' , 'M' ) ; $ nbBaseFive = array ( 'V' , 'L' , 'D' ) ; $ nbRoman = '' ; if ( $ nbArabic < 1 ) { return $ nbArabic ; } if ( $ nbArabic > 3999 ) { return $ nbArabic ; } for ( $ i = 3 ; $ i >= 0 ; $ i -- ) { $ digit = floor ( $ nbArabic...
Convert an arabic number into a roman number
7,907
protected function _listeGetLi ( ) { $ im = $ this -> _defList [ count ( $ this -> _defList ) - 1 ] [ 'img' ] ; $ st = $ this -> _defList [ count ( $ this -> _defList ) - 1 ] [ 'style' ] ; $ nb = $ this -> _defList [ count ( $ this -> _defList ) - 1 ] [ 'nb' ] ; $ up = ( substr ( $ st , 0 , 6 ) === 'upper-' ) ; if ( $ ...
get the information of the li on the current level
7,908
protected function _listeAddLevel ( $ type = 'ul' , $ style = '' , $ img = null , $ start = null ) { if ( $ img ) { if ( preg_match ( '/^url\(([^)]+)\)$/isU' , trim ( $ img ) , $ match ) ) { $ img = $ match [ 1 ] ; } else { $ img = null ; } } else { $ img = null ; } if ( ! in_array ( $ type , array ( 'ul' , 'ol' ) ) ) ...
add a level to the list
7,909
protected function _listeDelLevel ( ) { if ( count ( $ this -> _defList ) ) { unset ( $ this -> _defList [ count ( $ this -> _defList ) - 1 ] ) ; $ this -> _defList = array_values ( $ this -> _defList ) ; } }
remove a level from the list
7,910
protected function _makeHTMLcode ( ) { $ amountHtmlCode = count ( $ this -> parsingHtml -> code ) ; for ( $ this -> _parsePos = 0 ; $ this -> _parsePos < $ amountHtmlCode ; $ this -> _parsePos ++ ) { $ action = $ this -> parsingHtml -> code [ $ this -> _parsePos ] ; if ( in_array ( $ action -> getName ( ) , array ( 'ta...
execute the actions to convert the html
7,911
protected function _executeAction ( Node $ action ) { $ name = strtoupper ( $ action -> getName ( ) ) ; if ( $ this -> _firstPage && $ name !== 'PAGE' && ! $ action -> isClose ( ) ) { $ this -> _setNewPage ( ) ; } $ properties = $ action -> getParams ( ) ; $ fnc = ( $ action -> isClose ( ) ? '_tag_close_' : '_tag_open_...
execute the action from the parsing
7,912
protected function _getElementY ( $ h ) { if ( $ this -> _subPart || $ this -> _isSubPart || ! $ this -> _currentH || $ this -> _currentH < $ h ) { return 0 ; } return ( $ this -> _currentH - $ h ) * 0.8 ; }
get the position of the element on the current line depending on its height
7,913
protected function _makeBreakLine ( $ h , $ curr = null ) { if ( $ h ) { if ( ( $ this -> pdf -> GetY ( ) + $ h < $ this -> pdf -> getH ( ) - $ this -> pdf -> getbMargin ( ) ) || $ this -> _isInOverflow || $ this -> _isInFooter ) { $ this -> _setNewLine ( $ h , $ curr ) ; } else { $ this -> _setNewPage ( null , '' , nu...
make a break line
7,914
protected function _tag_close_PAGE_FOOTER_SUB ( $ param ) { if ( $ this -> _isForOneLine ) { return false ; } $ this -> parsingCss -> load ( ) ; $ this -> parsingCss -> value = $ this -> _subSTATES [ 's' ] ; $ this -> parsingCss -> table = $ this -> _subSTATES [ 't' ] ; $ this -> _pageMarges = $ this -> _subSTATES [ 'm...
It is not a real tag . Do not use it directly
7,915
public function _INDEX_NewPage ( & $ page ) { if ( $ page ) { $ oldPage = $ this -> pdf -> getPage ( ) ; $ this -> pdf -> setPage ( $ page ) ; $ this -> pdf -> SetXY ( $ this -> _margeLeft , $ this -> _margeTop ) ; $ this -> _maxH = 0 ; $ page ++ ; return $ oldPage ; } else { $ this -> _setNewPage ( ) ; return null ; }...
new page for the automatic Index do not use this method . Only myPdf could use it !!!!
7,916
public function Footer ( ) { $ txt = '' ; if ( $ this -> _footerParam [ 'form' ] ) { $ txt = Locale :: get ( 'pdf05' ) ; } if ( $ this -> _footerParam [ 'date' ] && $ this -> _footerParam [ 'time' ] ) { $ txt .= ( $ txt ? ' - ' : '' ) . Locale :: get ( 'pdf03' ) ; } if ( $ this -> _footerParam [ 'date' ] && ! $ this ->...
This function is call automatically by TCPDF at the end of a page It takes no parameters
7,917
public function cloneFontFrom ( & $ pdf ) { $ this -> n = & $ pdf -> getN ( ) ; $ this -> fonts = & $ pdf -> getFonts ( ) ; $ this -> FontFiles = & $ pdf -> getFontFiles ( ) ; $ this -> diffs = & $ pdf -> getDiffs ( ) ; $ this -> fontlist = & $ pdf -> getFontList ( ) ; $ this -> numfonts = & $ pdf -> getNumFonts ( ) ; ...
after cloning a object we does not want to clone all the front informations because it take a lot a time and a lot of memory = > we use reference
7,918
public function isLoadedFont ( $ fontKey ) { if ( isset ( $ this -> fonts [ $ fontKey ] ) ) { return true ; } if ( isset ( $ this -> CoreFonts [ $ fontKey ] ) ) { return true ; } return false ; }
Verify that a Font is already loaded
7,919
public function setWordSpacing ( $ ws = 0. ) { $ this -> ws = $ ws ; $ this -> _out ( sprintf ( '%.3F Tw' , $ ws * $ this -> k ) ) ; }
set the Word Spacing
7,920
public function setTranslate ( $ xT , $ yT ) { $ tm [ 0 ] = 1 ; $ tm [ 1 ] = 0 ; $ tm [ 2 ] = 0 ; $ tm [ 3 ] = 1 ; $ tm [ 4 ] = $ xT * $ this -> k ; $ tm [ 5 ] = - $ yT * $ this -> k ; $ this -> _out ( sprintf ( '%.3F %.3F %.3F %.3F %.3F %.3F cm' , $ tm [ 0 ] , $ tm [ 1 ] , $ tm [ 2 ] , $ tm [ 3 ] , $ tm [ 4 ] , $ tm [...
add a Translate transformation
7,921
public function setRotation ( $ angle , $ xC = null , $ yC = null ) { if ( $ xC === null ) { $ xC = $ this -> x ; } if ( $ yC === null ) { $ yC = $ this -> y ; } $ yC = ( $ this -> h - $ yC ) * $ this -> k ; $ xC *= $ this -> k ; $ tm [ 0 ] = cos ( deg2rad ( $ angle ) ) ; $ tm [ 1 ] = sin ( deg2rad ( $ angle ) ) ; $ tm...
add a Rotate transformation
7,922
public function svgLine ( $ x1 , $ y1 , $ x2 , $ y2 ) { $ op = 'S' ; $ this -> _Point ( $ x1 , $ y1 , true ) ; $ this -> _Line ( $ x2 , $ y2 , true ) ; $ this -> _out ( $ op ) ; }
SVG - make a Line
7,923
public function svgEllipse ( $ x0 , $ y0 , $ rx , $ ry , $ style ) { if ( $ style === 'F' ) { $ op = 'f' ; } elseif ( $ style === 'FD' || $ style === 'DF' ) { $ op = 'B' ; } else { $ op = 'S' ; } $ this -> _Arc ( $ x0 , $ y0 , $ rx , $ ry , 0 , 2 * M_PI , true , true , true ) ; $ this -> _out ( $ op ) ; }
SVG - make a Ellipse
7,924
public function doTransform ( $ n = null ) { $ nb = count ( $ this -> _transf ) ; if ( $ nb ) { $ m = $ this -> _transf [ $ nb - 1 ] ; } else { $ m = array ( 1 , 0 , 0 , 1 , 0 , 0 ) ; } if ( ! $ n ) { $ n = array ( 1 , 0 , 0 , 1 , 0 , 0 ) ; } $ this -> _transf [ ] = array ( $ m [ 0 ] * $ n [ 0 ] + $ m [ 2 ] * $ n [ 1 ]...
SVG - add a transformation Matric
7,925
public function myBarcode ( $ code , $ type , $ x , $ y , $ w , $ h , $ labelFontsize , $ color , $ dimension = '1D' ) { $ style = array ( 'position' => 'S' , 'text' => ( $ labelFontsize ? true : false ) , 'fgcolor' => $ color , 'bgcolor' => false , ) ; if ( $ dimension === '2D' ) { $ this -> write2DBarcode ( $ code , ...
Convert a Html2Pdf barcode in a TCPDF barcode
7,926
public function getMyAliasNbPages ( ) { if ( $ this -> _myLastPageGroupNb == 0 ) { return $ this -> getAliasNbPages ( ) ; } else { $ old = $ this -> currpagegroup ; $ this -> currpagegroup = '{nb' . $ this -> _myLastPageGroupNb . '}' ; $ new = $ this -> getPageGroupAlias ( ) ; $ this -> currpagegroup = $ old ; return $...
Returns the string alias used for the total number of pages .
7,927
public function tokenize ( $ html ) { $ tokens = array ( ) ; $ reg = '/(<\/?\w[^<>]*>)|([^<]+|<)/is' ; $ commentRegex = '/(<!--.* ; $ str = '' ; $ offset = 0 ; $ line = 1 ; $ length = strlen ( $ html ) ; while ( $ offset < $ length ) { if ( strpos ( $ html , '<!--' , $ offset ) === $ offset && preg_match ( $ commentReg...
Tokenize the HTML code
7,928
protected function getAdditionalData ( Html2PdfException $ e ) { $ data = array ( ) ; switch ( $ e -> getCode ( ) ) { case HtmlParsingException :: ERROR_CODE : $ data [ 'invalid tag' ] = $ e -> getInvalidTag ( ) ; $ data [ 'html line' ] = $ e -> getHtmlLine ( ) ; break ; case ImageException :: ERROR_CODE : $ data [ 'im...
get the additional data from the exception
7,929
protected function buildTextMessage ( Html2PdfException $ e , $ data ) { $ this -> message = 'Html2Pdf Error [' . $ e -> getCode ( ) . ']' . "\n" ; $ this -> message .= $ e -> getMessage ( ) . "\n" ; $ this -> message .= ' File: ' . $ e -> getFile ( ) . "\n" ; $ this -> message .= ' Line: ' . $ e -> getLine ( ) . "\n" ...
Build the text message
7,930
protected function buildHtmlMessage ( Html2PdfException $ e , $ data ) { $ this -> htmlMessage = '<span style="color: #A00; font-weight: bold;">' ; $ this -> htmlMessage .= 'Html2Pdf Error [' . $ e -> getCode ( ) . ']' ; $ this -> htmlMessage .= '</span><br />' . "\n" ; $ this -> htmlMessage .= htmlentities ( $ e -> ge...
build the html message
7,931
public function getCloneCodes ( ) { $ codes = array ( ) ; foreach ( $ this -> code as $ key => $ code ) { $ codes [ $ key ] = clone $ code ; } return $ codes ; }
Get the list of the codes but cloned
7,932
protected function verifyMustContain ( & $ actions , $ mainTag , $ mustTag ) { $ inMainTag = 0 ; $ foundMustTag = false ; foreach ( $ actions as $ action ) { if ( $ action -> getName ( ) == $ mainTag && ! $ action -> isClose ( ) ) { $ inMainTag ++ ; $ foundMustTag = false ; } if ( $ action -> getName ( ) == $ mustTag &...
Verify some tags that must contain other tags
7,933
protected function getTextAction ( Token $ token ) { $ tagPreBr = new Node ( 'br' , array ( 'style' => array ( ) , 'num' => 0 ) , false ) ; $ actions = array ( ) ; if ( ! $ this -> tagPreIn ) { $ actions [ ] = new Node ( 'write' , array ( 'txt' => $ this -> textParser -> prepareTxt ( $ token -> getData ( ) ) ) , false ...
get the Text action
7,934
public function prepareHtml ( $ html ) { if ( preg_match ( '/<body/isU' , $ html ) ) { $ html = $ this -> getHtmlFromRealPage ( $ html ) ; } $ html = str_replace ( '[[date_y]]' , date ( 'Y' ) , $ html ) ; $ html = str_replace ( '[[date_m]]' , date ( 'm' ) , $ html ) ; $ html = str_replace ( '[[date_d]]' , date ( 'd' ) ...
prepare the HTML
7,935
protected function getHtmlFromRealPage ( $ html ) { $ html = str_replace ( '<BODY' , '<body' , $ html ) ; $ html = str_replace ( '</BODY' , '</body' , $ html ) ; $ res = explode ( '<body' , $ html ) ; $ content = '<page' . $ res [ 1 ] ; $ content = explode ( '</body' , $ content ) ; $ content = $ content [ 0 ] . '</pag...
convert the HTML of a real page to a code adapted to Html2Pdf
7,936
public function generate ( $ minify = false ) { $ this -> loadWebMasterTags ( ) ; $ title = $ this -> getTitle ( ) ; $ description = $ this -> getDescription ( ) ; $ keywords = $ this -> getKeywords ( ) ; $ metatags = $ this -> getMetatags ( ) ; $ canonical = $ this -> getCanonical ( ) ; $ amphtml = $ this -> getAmpHtm...
Generates meta tags .
7,937
public function getDefaultTitle ( ) { if ( empty ( $ this -> title_default ) ) { return $ this -> config -> get ( 'defaults.title' , null ) ; } return $ this -> title_default ; }
Takes the default title .
7,938
public function getDescription ( ) { if ( false === $ this -> description ) { return ; } return $ this -> description ? : $ this -> config -> get ( 'defaults.description' , null ) ; }
Get the Meta description .
7,939
public function getCanonical ( ) { $ canonical_config = $ this -> config -> get ( 'defaults.canonical' , false ) ; return $ this -> canonical ? : ( ( $ canonical_config === null ) ? app ( 'url' ) -> full ( ) : $ canonical_config ) ; }
Get the canonical URL .
7,940
protected function loadWebMasterTags ( ) { foreach ( $ this -> config -> get ( 'webmaster_tags' , [ ] ) as $ name => $ value ) { if ( ! empty ( $ value ) ) { $ meta = array_get ( $ this -> webmasterTags , $ name , $ name ) ; $ this -> addMeta ( $ meta , $ value ) ; } } }
Load webmaster tags from configuration .
7,941
public function setTitle ( $ title , $ appendDefault = true ) { $ this -> metatags ( ) -> setTitle ( $ title , $ appendDefault ) ; $ this -> opengraph ( ) -> setTitle ( $ title ) ; $ this -> twitter ( ) -> setTitle ( $ title ) ; $ this -> jsonLd ( ) -> setTitle ( $ title ) ; return $ this ; }
Setup title for all seo providers .
7,942
public function setDescription ( $ description ) { $ this -> metatags ( ) -> setDescription ( $ description ) ; $ this -> opengraph ( ) -> setDescription ( $ description ) ; $ this -> twitter ( ) -> setDescription ( $ description ) ; $ this -> jsonLd ( ) -> setDescription ( $ description ) ; return $ this ; }
Setup description for all seo providers .
7,943
public function getTitle ( $ session = false ) { if ( $ session ) { return $ this -> metatags ( ) -> getTitleSession ( ) ; } return $ this -> metatags ( ) -> getTitle ( ) ; }
Get current title from metatags .
7,944
public function generate ( $ minify = false ) { $ html = $ this -> metatags ( ) -> generate ( ) ; $ html .= PHP_EOL ; $ html .= $ this -> opengraph ( ) -> generate ( ) ; $ html .= PHP_EOL ; $ html .= $ this -> twitter ( ) -> generate ( ) ; $ html .= PHP_EOL ; $ html .= $ this -> jsonLd ( ) -> generate ( ) ; return ( $ ...
Generate from all seo providers .
7,945
public function generate ( $ minify = false ) { $ this -> setupDefaults ( ) ; $ output = $ this -> eachProperties ( $ this -> properties ) ; $ props = [ 'images' => [ 'image' , true ] , 'articleProperties' => [ 'article' , false ] , 'profileProperties' => [ 'profile' , false ] , 'bookProperties' => [ 'book' , false ] ,...
Generates open graph tags .
7,946
protected function eachProperties ( array $ properties , $ prefix = null , $ ogPrefix = true ) { $ html = [ ] ; foreach ( $ properties as $ property => $ value ) { if ( is_array ( $ value ) ) { $ subListPrefix = ( is_string ( $ property ) ) ? $ property : $ prefix ; $ subList = $ this -> eachProperties ( $ value , $ su...
Make list of open graph tags .
7,947
protected function makeTag ( $ key = null , $ value = null , $ ogPrefix = false ) { return sprintf ( '<meta property="%s%s" content="%s" />%s' , $ ogPrefix ? $ this -> og_prefix : '' , strip_tags ( $ key ) , strip_tags ( $ value ) , PHP_EOL ) ; }
Make a og tag .
7,948
protected function setupDefaults ( ) { $ defaults = ( isset ( $ this -> config [ 'defaults' ] ) ) ? $ this -> config [ 'defaults' ] : [ ] ; foreach ( $ defaults as $ key => $ value ) { if ( $ key == 'images' ) { if ( empty ( $ this -> images ) ) { $ this -> images = $ value ; } } elseif ( $ key == 'url' && $ value === ...
Add or update property .
7,949
public function addVideo ( $ source = null , $ attributes = [ ] ) { $ validKeys = [ 'url' , 'secure_url' , 'type' , 'width' , 'height' , ] ; $ this -> videoProperties [ ] = [ $ source , $ this -> cleanProperties ( $ attributes , $ validKeys ) , ] ; return $ this ; }
Add video properties .
7,950
public function addAudio ( $ source = null , $ attributes = [ ] ) { $ validKeys = [ 'url' , 'secure_url' , 'type' , ] ; $ this -> audioProperties [ ] = [ $ source , $ this -> cleanProperties ( $ attributes , $ validKeys ) , ] ; return $ this ; }
Add audio properties .
7,951
protected function cleanProperties ( $ attributes = [ ] , $ validKeys = [ ] ) { $ array = [ ] ; foreach ( $ attributes as $ attribute => $ value ) { if ( in_array ( $ attribute , $ validKeys ) ) { $ array [ $ attribute ] = $ value ; } } return $ array ; }
Clean invalid properties .
7,952
public function addImage ( $ source = null , $ attributes = [ ] ) { $ validKeys = [ 'url' , 'secure_url' , 'type' , 'width' , 'height' , ] ; if ( is_array ( $ source ) ) { $ this -> images [ ] = $ this -> cleanProperties ( $ source , $ validKeys ) ; } else { $ this -> images [ ] = [ $ source , $ this -> cleanProperties...
Add image to properties .
7,953
protected function eachValue ( array $ values , $ prefix = null ) { foreach ( $ values as $ key => $ value ) : if ( is_array ( $ value ) ) : $ this -> eachValue ( $ value , $ key ) ; else : if ( is_numeric ( $ key ) ) : $ key = $ prefix . $ key ; elseif ( is_string ( $ prefix ) ) : $ key = $ prefix . ':' . $ key ; endi...
Make tags .
7,954
public function choose_template ( $ templates ) { if ( ! is_array ( $ templates ) ) { $ templates = ( array ) $ templates ; } $ loader = $ this -> get_loader ( ) ; foreach ( $ templates as $ template ) { $ template = trim ( $ template ) ; if ( $ loader -> exists ( $ template ) ) { return $ template ; } } return false ;...
Get first existing template .
7,955
public function import ( $ info , $ force = false ) { if ( is_object ( $ info ) ) { $ info = get_object_vars ( $ info ) ; } if ( is_array ( $ info ) ) { foreach ( $ info as $ key => $ value ) { if ( $ key === '' || ord ( $ key [ 0 ] ) === 0 ) { continue ; } if ( ! empty ( $ key ) && $ force ) { $ this -> $ key = $ valu...
Takes an array or object and adds the properties to the parent object
7,956
public static function is_external ( $ url ) { $ has_http = strstr ( strtolower ( $ url ) , 'http' ) || strstr ( strtolower ( $ url ) , '//' ) ; $ on_domain = strstr ( $ url , self :: get_host ( ) ) ; if ( $ has_http && ! $ on_domain ) { return true ; } return false ; }
Checks if URL is external or internal . Works with domains subdomains and protocol relative domains .
7,957
public static function remove_url_component ( $ haystack , $ needle ) { $ haystack = str_replace ( $ needle , '' , $ haystack ) ; $ needle = self :: swap_protocol ( $ needle ) ; return str_replace ( $ needle , '' , $ haystack ) ; }
Removes the subcomponent of a URL regardless of protocol
7,958
public static function swap_protocol ( $ url ) { if ( stristr ( $ url , 'http:' ) ) { return str_replace ( 'http:' , 'https:' , $ url ) ; } if ( stristr ( $ url , 'https:' ) ) { return str_replace ( 'https:' , 'http:' , $ url ) ; } return $ url ; }
Swaps whatever protocol of a URL is sent . http becomes https and vice versa
7,959
public static function user_trailingslashit ( $ link ) { $ link_parts = parse_url ( $ link ) ; if ( ! $ link_parts ) { return $ link ; } if ( isset ( $ link_parts [ 'path' ] ) && $ link_parts [ 'path' ] != '/' ) { $ new_path = user_trailingslashit ( $ link_parts [ 'path' ] ) ; if ( $ new_path != $ link_parts [ 'path' ]...
Pass links through user_trailingslashit handling query strings properly
7,960
protected static function process_term_args ( $ maybe_taxonomy , $ TermClass ) { if ( class_exists ( $ maybe_taxonomy ) ) { $ tc = new $ maybe_taxonomy ; if ( is_subclass_of ( $ tc , 'Timber\Term' ) ) { return array ( 'taxonomy' => '' , 'TermClass' => $ maybe_taxonomy ) ; } } return array ( 'taxonomy' => $ maybe_taxono...
Process the arguments for handle_term_object to determine what arguments the user is sending
7,961
public function add_timber_escapers ( $ twig ) { $ twig -> getExtension ( 'Twig_Extension_Core' ) -> setEscaper ( 'esc_url' , function ( \ Twig_Environment $ env , $ string ) { return esc_url ( $ string ) ; } ) ; $ twig -> getExtension ( 'Twig_Extension_Core' ) -> setEscaper ( 'wp_kses_post' , function ( \ Twig_Environ...
Adds escapers to Twig .
7,962
public function add_to_twig ( $ twig ) { $ wrapper = $ this ; try { $ twig -> addFunction ( new Twig_Function ( $ this -> _function , function ( ) use ( $ wrapper ) { return call_user_func_array ( array ( $ wrapper , 'call' ) , func_get_args ( ) ) ; } ) ) ; } catch ( \ Exception $ e ) { } return $ twig ; }
Make function available in Twig .
7,963
public static function resize ( $ src , $ w , $ h = 0 , $ crop = 'default' , $ force = false ) { if ( ! is_numeric ( $ w ) && is_string ( $ w ) ) { if ( $ sizes = self :: find_wp_dimensions ( $ w ) ) { $ w = $ sizes [ 'w' ] ; $ h = $ sizes [ 'h' ] ; } else { return $ src ; } } $ op = new Image \ Operation \ Resize ( $ ...
Generates a new image with the specified dimensions . New dimensions are achieved by cropping to maintain ratio .
7,964
private static function find_wp_dimensions ( $ size ) { global $ _wp_additional_image_sizes ; if ( isset ( $ _wp_additional_image_sizes [ $ size ] ) ) { $ w = $ _wp_additional_image_sizes [ $ size ] [ 'width' ] ; $ h = $ _wp_additional_image_sizes [ $ size ] [ 'height' ] ; } else if ( in_array ( $ size , array ( 'thumb...
Find the sizes of an image based on a defined image size
7,965
public static function retina_resize ( $ src , $ multiplier = 2 , $ force = false ) { $ op = new Image \ Operation \ Retina ( $ multiplier ) ; return self :: _operate ( $ src , $ op , $ force ) ; }
Generates a new image with increased size for display on Retina screens .
7,966
public static function is_animated_gif ( $ file ) { if ( strpos ( strtolower ( $ file ) , '.gif' ) === false ) { return false ; } if ( ! ( $ fh = @ fopen ( $ file , 'rb' ) ) ) { return false ; } $ count = 0 ; while ( ! feof ( $ fh ) && $ count < 2 ) { $ chunk = fread ( $ fh , 1024 * 100 ) ; $ count += preg_match_all ( ...
checks to see if the given file is an aimated gif
7,967
public static function is_svg ( $ file_path ) { if ( ! isset ( $ file_path ) || '' === $ file_path || ! file_exists ( $ file_path ) ) { return false ; } if ( TextHelper :: ends_with ( strtolower ( $ file_path ) , '.svg' ) ) { return true ; } $ mime = wp_check_filetype_and_ext ( $ file_path , basename ( $ file_path ) , ...
Checks if file is an SVG .
7,968
public static function letterbox ( $ src , $ w , $ h , $ color = false , $ force = false ) { $ op = new Letterbox ( $ w , $ h , $ color ) ; return self :: _operate ( $ src , $ op , $ force ) ; }
Generate a new image with the specified dimensions . New dimensions are achieved by adding colored bands to maintain ratio .
7,969
public static function img_to_jpg ( $ src , $ bghex = '#FFFFFF' , $ force = false ) { $ op = new Image \ Operation \ ToJpg ( $ bghex ) ; return self :: _operate ( $ src , $ op , $ force ) ; }
Generates a new image by converting the source GIF or PNG into JPG
7,970
public static function img_to_webp ( $ src , $ quality = 80 , $ force = false ) { $ op = new Image \ Operation \ ToWebp ( $ quality ) ; return self :: _operate ( $ src , $ op , $ force ) ; }
Generates a new image by converting the source into WEBP if supported by the server
7,971
public static function _delete_generated_if_image ( $ post_id ) { if ( wp_attachment_is_image ( $ post_id ) ) { $ attachment = new Image ( $ post_id ) ; if ( $ attachment -> file_loc ) { ImageHelper :: delete_generated_files ( $ attachment -> file_loc ) ; } } }
Checks if attachment is an image before deleting generated files
7,972
static function delete_generated_files ( $ local_file ) { if ( URLHelper :: is_absolute ( $ local_file ) ) { $ local_file = URLHelper :: url_to_file_system ( $ local_file ) ; } $ info = pathinfo ( $ local_file ) ; $ dir = $ info [ 'dirname' ] ; $ ext = $ info [ 'extension' ] ; $ filename = $ info [ 'filename' ] ; self ...
Deletes the auto - generated files for resize and letterboxing created by Timber
7,973
protected static function process_delete_generated_files ( $ filename , $ ext , $ dir , $ search_pattern , $ match_pattern = null ) { $ searcher = '/' . $ filename . $ search_pattern ; $ files = glob ( $ dir . $ searcher ) ; if ( $ files === false || empty ( $ files ) ) { return ; } foreach ( $ files as $ found_file ) ...
Deletes resized versions of the supplied file name . So if passed a value like my - pic . jpg this function will delete my - pic - 500x200 - c - left . jpg my - pic - 400x400 - c - default . jpg etc .
7,974
public static function get_server_location ( $ url ) { if ( 0 === strpos ( $ url , ABSPATH ) ) { return $ url ; } $ au = self :: analyze_url ( $ url ) ; $ result = self :: _get_file_path ( $ au [ 'base' ] , $ au [ 'subdir' ] , $ au [ 'basename' ] ) ; return $ result ; }
Determines the filepath corresponding to a given URL
7,975
public static function get_sideloaded_file_loc ( $ file ) { $ upload = wp_upload_dir ( ) ; $ dir = $ upload [ 'path' ] ; $ filename = $ file ; $ file = parse_url ( $ file ) ; $ path_parts = pathinfo ( $ file [ 'path' ] ) ; $ basename = md5 ( $ filename ) ; $ ext = 'jpg' ; if ( isset ( $ path_parts [ 'extension' ] ) ) {...
Determines the filepath where a given external file will be stored .
7,976
public static function sideload_image ( $ file ) { $ loc = self :: get_sideloaded_file_loc ( $ file ) ; if ( file_exists ( $ loc ) ) { return URLHelper :: file_system_to_url ( $ loc ) ; } if ( ! function_exists ( 'download_url' ) ) { require_once ABSPATH . '/wp-admin/includes/file.php' ; } $ tmp = download_url ( $ file...
downloads an external image to the server and stores it on the server
7,977
public static function analyze_url ( $ url ) { $ result = array ( 'url' => $ url , 'absolute' => URLHelper :: is_absolute ( $ url ) , 'base' => 0 , 'subdir' => '' , 'filename' => '' , 'extension' => '' , 'basename' => '' , ) ; $ upload_dir = wp_upload_dir ( ) ; $ tmp = $ url ; if ( TextHelper :: starts_with ( $ tmp , A...
Takes in an URL and breaks it into components that will then be used in the different steps of image processing . The image is expected to be either part of a theme plugin or an upload .
7,978
static function theme_url_to_dir ( $ src ) { $ site_root = trailingslashit ( get_theme_root_uri ( ) ) . get_stylesheet ( ) ; $ tmp = str_replace ( $ site_root , '' , $ src ) ; $ tmp = get_stylesheet_directory ( ) . $ tmp ; if ( realpath ( $ tmp ) ) { return realpath ( $ tmp ) ; } return $ tmp ; }
Converts a URL located in a theme directory into the raw file path
7,979
protected static function is_in_theme_dir ( $ path ) { $ root = realpath ( get_stylesheet_directory ( ) ) ; if ( false === $ root ) { return false ; } if ( 0 === strpos ( $ path , ( string ) $ root ) ) { return true ; } else { return false ; } }
Checks if uploaded image is located in theme .
7,980
private static function _get_file_url ( $ base , $ subdir , $ filename , $ absolute ) { $ url = '' ; if ( self :: BASE_UPLOADS == $ base ) { $ upload_dir = wp_upload_dir ( ) ; $ url = $ upload_dir [ 'baseurl' ] ; } if ( self :: BASE_CONTENT == $ base ) { $ url = content_url ( ) ; } if ( ! empty ( $ subdir ) ) { $ url ....
Builds the public URL of a file based on its different components
7,981
private static function _get_file_path ( $ base , $ subdir , $ filename ) { if ( URLHelper :: is_url ( $ subdir ) ) { $ subdir = URLHelper :: url_to_file_system ( $ subdir ) ; } $ subdir = self :: maybe_realpath ( $ subdir ) ; $ path = '' ; if ( self :: BASE_UPLOADS == $ base ) { $ upload_dir = wp_upload_dir ( ) ; $ pa...
Builds the absolute file system location of a file based on its different components
7,982
public function pagination ( $ prefs = array ( ) ) { if ( ! $ this -> pagination && is_a ( $ this -> queryIterator , 'Timber\QueryIterator' ) ) { $ this -> pagination = $ this -> queryIterator -> get_pagination ( $ prefs , $ this -> get_query ( ) ) ; } return $ this -> pagination ; }
Set pagination for the collection . Optionally could be used to get pagination with custom preferences .
7,983
public function find_parent_item_in_menu ( $ menu_items , $ parent_id ) { foreach ( $ menu_items as & $ item ) { if ( $ item -> ID == $ parent_id ) { return $ item ; } } }
Find a parent menu item in a set of menu items .
7,984
public static function in_plugin_update_message ( $ plugin_data , $ r ) { $ current_version = $ plugin_data [ 'Version' ] ; $ new_version = $ plugin_data [ 'new_version' ] ; $ upgrade_magnitude = self :: get_upgrade_magnitude ( $ current_version , $ new_version ) ; if ( $ upgrade_magnitude == 'milestone' ) { $ message ...
Displays an update message for plugin list screens . Shows only the version updates from the current until the newest version
7,985
public static function trim_characters ( $ text , $ num_chars = 60 , $ more = '&hellip;' ) { $ text = wp_strip_all_tags ( $ text ) ; $ text = mb_strimwidth ( $ text , 0 , $ num_chars , $ more ) ; return $ text ; }
Trims text to a certain number of characters . This function can be useful for excerpt of the post As opposed to wp_trim_words trims characters that makes text to take the same amount of space in each post for example
7,986
public static function get_calling_script_file ( $ offset = 0 ) { $ callers = array ( ) ; $ backtrace = debug_backtrace ( ) ; foreach ( $ backtrace as $ trace ) { if ( array_key_exists ( 'file' , $ trace ) && $ trace [ 'file' ] != __FILE__ ) { $ callers [ ] = $ trace [ 'file' ] ; } } $ callers = array_unique ( $ caller...
Get calling script file .
7,987
public static function get_calling_script_dir ( $ offset = 0 ) { $ caller = self :: get_calling_script_file ( $ offset ) ; if ( ! is_null ( $ caller ) ) { $ pathinfo = pathinfo ( $ caller ) ; $ dir = $ pathinfo [ 'dirname' ] ; return $ dir ; } }
Get calling script dir .
7,988
public function filename ( $ src_filename , $ src_extension ) { $ newbase = $ src_filename . '@' . $ this -> factor . 'x' ; $ new_name = $ newbase . '.' . $ src_extension ; return $ new_name ; }
Generates the final filename based on the source s name and extension
7,989
public static function get_sites ( $ blog_ids = false ) { if ( ! is_array ( $ blog_ids ) ) { global $ wpdb ; $ blog_ids = $ wpdb -> get_col ( "SELECT blog_id FROM $wpdb->blogs ORDER BY blog_id ASC" ) ; } $ return = array ( ) ; foreach ( $ blog_ids as $ blog_id ) { $ return [ ] = new Site ( $ blog_id ) ; } return $ retu...
Get sites .
7,990
public static function compile ( $ filenames , $ data = array ( ) , $ expires = false , $ cache_mode = Loader :: CACHE_USE_DEFAULT , $ via_render = false ) { if ( ! defined ( 'TIMBER_LOADED' ) ) { self :: init ( ) ; } $ caller = LocationManager :: get_calling_script_dir ( 1 ) ; $ loader = new Loader ( $ caller ) ; $ fi...
Compile a Twig file .
7,991
public static function compile_string ( $ string , $ data = array ( ) ) { $ dummy_loader = new Loader ( ) ; $ twig = $ dummy_loader -> get_twig ( ) ; $ template = $ twig -> createTemplate ( $ string ) ; return $ template -> render ( $ data ) ; }
Compile a string .
7,992
public static function fetch ( $ filenames , $ data = array ( ) , $ expires = false , $ cache_mode = Loader :: CACHE_USE_DEFAULT ) { $ output = self :: compile ( $ filenames , $ data , $ expires , $ cache_mode , true ) ; $ output = apply_filters ( 'timber_compile_result' , $ output ) ; return $ output ; }
Fetch function .
7,993
public static function render_string ( $ string , $ data = array ( ) ) { $ compiled = self :: compile_string ( $ string , $ data ) ; echo $ compiled ; return $ compiled ; }
Render a string with Twig variables .
7,994
public static function get_sidebar ( $ sidebar = 'sidebar.php' , $ data = array ( ) ) { if ( strstr ( strtolower ( $ sidebar ) , '.php' ) ) { return self :: get_sidebar_from_php ( $ sidebar , $ data ) ; } return self :: compile ( $ sidebar , $ data ) ; }
Get sidebar .
7,995
public static function get_sidebar_from_php ( $ sidebar = '' , $ data ) { $ caller = LocationManager :: get_calling_script_dir ( 1 ) ; $ uris = LocationManager :: get_locations ( $ caller ) ; ob_start ( ) ; $ found = false ; foreach ( $ uris as $ uri ) { if ( file_exists ( trailingslashit ( $ uri ) . $ sidebar ) ) { in...
Get sidebar from PHP
7,996
public static function hexrgb ( $ hexstr ) { if ( ! strstr ( $ hexstr , '#' ) ) { $ hexstr = '#' . $ hexstr ; } if ( strlen ( $ hexstr ) == 4 ) { $ hexstr = '#' . $ hexstr [ 1 ] . $ hexstr [ 1 ] . $ hexstr [ 2 ] . $ hexstr [ 2 ] . $ hexstr [ 3 ] . $ hexstr [ 3 ] ; } $ int = hexdec ( $ hexstr ) ; return array ( "red" =>...
Helper method to convert hex string to rgb array
7,997
public function get_posts ( $ numberposts_or_args = 10 , $ post_type_or_class = 'any' , $ post_class = '' ) { if ( ! strlen ( $ post_class ) ) { $ post_class = $ this -> PostClass ; } $ default_tax_query = array ( array ( 'field' => 'term_id' , 'terms' => $ this -> ID , 'taxonomy' => $ this -> taxonomy , ) ) ; if ( is_...
Get posts that have the current term assigned .
7,998
public static function fix_number_posts_wp_quirk ( $ query ) { if ( isset ( $ query -> query ) && isset ( $ query -> query [ 'numberposts' ] ) && ! isset ( $ query -> query [ 'posts_per_page' ] ) ) { $ query -> set ( 'posts_per_page' , $ query -> query [ 'numberposts' ] ) ; } return $ query ; }
get_posts users numberposts
7,999
public static function fix_cat_wp_quirk ( $ query ) { if ( isset ( $ query -> query ) && isset ( $ query -> query [ 'category' ] ) && ! isset ( $ query -> query [ 'cat' ] ) ) { $ query -> set ( 'cat' , $ query -> query [ 'category' ] ) ; unset ( $ query -> query [ 'category' ] ) ; } return $ query ; }
get_posts uses category WP_Query uses cat . Why? who knows ...