repo stringlengths 6 63 | path stringlengths 5 140 | func_name stringlengths 3 151 | original_string stringlengths 84 13k | language stringclasses 1 value | code stringlengths 84 13k | code_tokens list | docstring stringlengths 3 47.2k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 91 247 | partition stringclasses 1 value |
|---|---|---|---|---|---|---|---|---|---|---|---|
spipu/html2pdf | src/Html2Pdf.php | Html2Pdf.setMargins | protected function setMargins()
{
// prepare the margins
$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->_margeTop = $this->_defaultTop + (isset($this->_background['top']) ? $this->_background['top'] : 0);
$this->_margeBottom = $this->_defaultBottom + (isset($this->_background['bottom']) ? $this->_background['bottom'] : 0);
// set the PDF margins
$this->pdf->SetMargins($this->_margeLeft, $this->_margeTop, $this->_margeRight);
$this->pdf->SetAutoPageBreak(false, $this->_margeBottom);
// set the float Margins
$this->_pageMarges = array();
if ($this->_isInParagraph !== false) {
$this->_pageMarges[floor($this->_margeTop*100)] = array($this->_isInParagraph[0], $this->pdf->getW()-$this->_isInParagraph[1]);
} else {
$this->_pageMarges[floor($this->_margeTop*100)] = array($this->_margeLeft, $this->pdf->getW()-$this->_margeRight);
}
} | php | protected function setMargins()
{
// prepare the margins
$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->_margeTop = $this->_defaultTop + (isset($this->_background['top']) ? $this->_background['top'] : 0);
$this->_margeBottom = $this->_defaultBottom + (isset($this->_background['bottom']) ? $this->_background['bottom'] : 0);
// set the PDF margins
$this->pdf->SetMargins($this->_margeLeft, $this->_margeTop, $this->_margeRight);
$this->pdf->SetAutoPageBreak(false, $this->_margeBottom);
// set the float Margins
$this->_pageMarges = array();
if ($this->_isInParagraph !== false) {
$this->_pageMarges[floor($this->_margeTop*100)] = array($this->_isInParagraph[0], $this->pdf->getW()-$this->_isInParagraph[1]);
} else {
$this->_pageMarges[floor($this->_margeTop*100)] = array($this->_margeLeft, $this->pdf->getW()-$this->_margeRight);
}
} | [
"protected",
"function",
"setMargins",
"(",
")",
"{",
"// prepare the margins",
"$",
"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",
"->",
"_margeTop",
"=",
"$",
"this",
"->",
"_defaultTop",
"+",
"(",
"isset",
"(",
"$",
"this",
"->",
"_background",
"[",
"'top'",
"]",
")",
"?",
"$",
"this",
"->",
"_background",
"[",
"'top'",
"]",
":",
"0",
")",
";",
"$",
"this",
"->",
"_margeBottom",
"=",
"$",
"this",
"->",
"_defaultBottom",
"+",
"(",
"isset",
"(",
"$",
"this",
"->",
"_background",
"[",
"'bottom'",
"]",
")",
"?",
"$",
"this",
"->",
"_background",
"[",
"'bottom'",
"]",
":",
"0",
")",
";",
"// set the PDF margins",
"$",
"this",
"->",
"pdf",
"->",
"SetMargins",
"(",
"$",
"this",
"->",
"_margeLeft",
",",
"$",
"this",
"->",
"_margeTop",
",",
"$",
"this",
"->",
"_margeRight",
")",
";",
"$",
"this",
"->",
"pdf",
"->",
"SetAutoPageBreak",
"(",
"false",
",",
"$",
"this",
"->",
"_margeBottom",
")",
";",
"// set the float Margins",
"$",
"this",
"->",
"_pageMarges",
"=",
"array",
"(",
")",
";",
"if",
"(",
"$",
"this",
"->",
"_isInParagraph",
"!==",
"false",
")",
"{",
"$",
"this",
"->",
"_pageMarges",
"[",
"floor",
"(",
"$",
"this",
"->",
"_margeTop",
"*",
"100",
")",
"]",
"=",
"array",
"(",
"$",
"this",
"->",
"_isInParagraph",
"[",
"0",
"]",
",",
"$",
"this",
"->",
"pdf",
"->",
"getW",
"(",
")",
"-",
"$",
"this",
"->",
"_isInParagraph",
"[",
"1",
"]",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"_pageMarges",
"[",
"floor",
"(",
"$",
"this",
"->",
"_margeTop",
"*",
"100",
")",
"]",
"=",
"array",
"(",
"$",
"this",
"->",
"_margeLeft",
",",
"$",
"this",
"->",
"pdf",
"->",
"getW",
"(",
")",
"-",
"$",
"this",
"->",
"_margeRight",
")",
";",
"}",
"}"
] | set the real margin, using the default margins and the page margins | [
"set",
"the",
"real",
"margin",
"using",
"the",
"default",
"margins",
"and",
"the",
"page",
"margins"
] | 83c9bd942e8520681808b70584e01d17157335ba | https://github.com/spipu/html2pdf/blob/83c9bd942e8520681808b70584e01d17157335ba/src/Html2Pdf.php#L762-L781 | train |
spipu/html2pdf | src/Html2Pdf.php | Html2Pdf._addMargins | protected function _addMargins($float, $xLeft, $yTop, $xRight, $yBottom)
{
// get the current float margins, for top and bottom
$oldTop = $this->_getMargins($yTop);
$oldBottom = $this->_getMargins($yBottom);
// update the top float margin
if ($float === 'left' && $oldTop[0]<$xRight) {
$oldTop[0] = $xRight;
}
if ($float === 'right' && $oldTop[1]>$xLeft) {
$oldTop[1] = $xLeft;
}
$yTop = floor($yTop*100);
$yBottom = floor($yBottom*100);
// erase all the float margins that are smaller than the new one
foreach ($this->_pageMarges as $mY => $mX) {
if ($mY<$yTop) {
continue;
}
if ($mY>$yBottom) {
break;
}
if ($float === 'left' && $this->_pageMarges[$mY][0]<$xRight) {
unset($this->_pageMarges[$mY]);
}
if ($float === 'right' && $this->_pageMarges[$mY][1]>$xLeft) {
unset($this->_pageMarges[$mY]);
}
}
// save the new Top and Bottom margins
$this->_pageMarges[$yTop] = $oldTop;
$this->_pageMarges[$yBottom] = $oldBottom;
// sort the margins
ksort($this->_pageMarges);
// we are just after float
$this->_isAfterFloat = true;
} | php | protected function _addMargins($float, $xLeft, $yTop, $xRight, $yBottom)
{
// get the current float margins, for top and bottom
$oldTop = $this->_getMargins($yTop);
$oldBottom = $this->_getMargins($yBottom);
// update the top float margin
if ($float === 'left' && $oldTop[0]<$xRight) {
$oldTop[0] = $xRight;
}
if ($float === 'right' && $oldTop[1]>$xLeft) {
$oldTop[1] = $xLeft;
}
$yTop = floor($yTop*100);
$yBottom = floor($yBottom*100);
// erase all the float margins that are smaller than the new one
foreach ($this->_pageMarges as $mY => $mX) {
if ($mY<$yTop) {
continue;
}
if ($mY>$yBottom) {
break;
}
if ($float === 'left' && $this->_pageMarges[$mY][0]<$xRight) {
unset($this->_pageMarges[$mY]);
}
if ($float === 'right' && $this->_pageMarges[$mY][1]>$xLeft) {
unset($this->_pageMarges[$mY]);
}
}
// save the new Top and Bottom margins
$this->_pageMarges[$yTop] = $oldTop;
$this->_pageMarges[$yBottom] = $oldBottom;
// sort the margins
ksort($this->_pageMarges);
// we are just after float
$this->_isAfterFloat = true;
} | [
"protected",
"function",
"_addMargins",
"(",
"$",
"float",
",",
"$",
"xLeft",
",",
"$",
"yTop",
",",
"$",
"xRight",
",",
"$",
"yBottom",
")",
"{",
"// get the current float margins, for top and bottom",
"$",
"oldTop",
"=",
"$",
"this",
"->",
"_getMargins",
"(",
"$",
"yTop",
")",
";",
"$",
"oldBottom",
"=",
"$",
"this",
"->",
"_getMargins",
"(",
"$",
"yBottom",
")",
";",
"// update the top float margin",
"if",
"(",
"$",
"float",
"===",
"'left'",
"&&",
"$",
"oldTop",
"[",
"0",
"]",
"<",
"$",
"xRight",
")",
"{",
"$",
"oldTop",
"[",
"0",
"]",
"=",
"$",
"xRight",
";",
"}",
"if",
"(",
"$",
"float",
"===",
"'right'",
"&&",
"$",
"oldTop",
"[",
"1",
"]",
">",
"$",
"xLeft",
")",
"{",
"$",
"oldTop",
"[",
"1",
"]",
"=",
"$",
"xLeft",
";",
"}",
"$",
"yTop",
"=",
"floor",
"(",
"$",
"yTop",
"*",
"100",
")",
";",
"$",
"yBottom",
"=",
"floor",
"(",
"$",
"yBottom",
"*",
"100",
")",
";",
"// erase all the float margins that are smaller than the new one",
"foreach",
"(",
"$",
"this",
"->",
"_pageMarges",
"as",
"$",
"mY",
"=>",
"$",
"mX",
")",
"{",
"if",
"(",
"$",
"mY",
"<",
"$",
"yTop",
")",
"{",
"continue",
";",
"}",
"if",
"(",
"$",
"mY",
">",
"$",
"yBottom",
")",
"{",
"break",
";",
"}",
"if",
"(",
"$",
"float",
"===",
"'left'",
"&&",
"$",
"this",
"->",
"_pageMarges",
"[",
"$",
"mY",
"]",
"[",
"0",
"]",
"<",
"$",
"xRight",
")",
"{",
"unset",
"(",
"$",
"this",
"->",
"_pageMarges",
"[",
"$",
"mY",
"]",
")",
";",
"}",
"if",
"(",
"$",
"float",
"===",
"'right'",
"&&",
"$",
"this",
"->",
"_pageMarges",
"[",
"$",
"mY",
"]",
"[",
"1",
"]",
">",
"$",
"xLeft",
")",
"{",
"unset",
"(",
"$",
"this",
"->",
"_pageMarges",
"[",
"$",
"mY",
"]",
")",
";",
"}",
"}",
"// save the new Top and Bottom margins",
"$",
"this",
"->",
"_pageMarges",
"[",
"$",
"yTop",
"]",
"=",
"$",
"oldTop",
";",
"$",
"this",
"->",
"_pageMarges",
"[",
"$",
"yBottom",
"]",
"=",
"$",
"oldBottom",
";",
"// sort the margins",
"ksort",
"(",
"$",
"this",
"->",
"_pageMarges",
")",
";",
"// we are just after float",
"$",
"this",
"->",
"_isAfterFloat",
"=",
"true",
";",
"}"
] | Add margins, for a float
@access protected
@param string $float (left / right)
@param float $xLeft
@param float $yTop
@param float $xRight
@param float $yBottom | [
"Add",
"margins",
"for",
"a",
"float"
] | 83c9bd942e8520681808b70584e01d17157335ba | https://github.com/spipu/html2pdf/blob/83c9bd942e8520681808b70584e01d17157335ba/src/Html2Pdf.php#L815-L857 | train |
spipu/html2pdf | src/Html2Pdf.php | Html2Pdf._setPageHeader | 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->parsingHtml->code = $this->_subHEADER;
$this->_makeHTMLcode();
$this->_parsePos = $oldParsePos;
$this->parsingHtml->code = $oldParseCode;
} | php | 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->parsingHtml->code = $this->_subHEADER;
$this->_makeHTMLcode();
$this->_parsePos = $oldParsePos;
$this->parsingHtml->code = $oldParseCode;
} | [
"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",
"->",
"parsingHtml",
"->",
"code",
"=",
"$",
"this",
"->",
"_subHEADER",
";",
"$",
"this",
"->",
"_makeHTMLcode",
"(",
")",
";",
"$",
"this",
"->",
"_parsePos",
"=",
"$",
"oldParsePos",
";",
"$",
"this",
"->",
"parsingHtml",
"->",
"code",
"=",
"$",
"oldParseCode",
";",
"}"
] | draw the PDF header with the HTML in page_header
@access protected | [
"draw",
"the",
"PDF",
"header",
"with",
"the",
"HTML",
"in",
"page_header"
] | 83c9bd942e8520681808b70584e01d17157335ba | https://github.com/spipu/html2pdf/blob/83c9bd942e8520681808b70584e01d17157335ba/src/Html2Pdf.php#L946-L965 | train |
spipu/html2pdf | src/Html2Pdf.php | Html2Pdf._setPageFooter | 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->parsingHtml->code = $this->_subFOOTER;
$this->_isInFooter = true;
$this->_makeHTMLcode();
$this->_isInFooter = false;
$this->_parsePos = $oldParsePos;
$this->parsingHtml->code = $oldParseCode;
} | php | 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->parsingHtml->code = $this->_subFOOTER;
$this->_isInFooter = true;
$this->_makeHTMLcode();
$this->_isInFooter = false;
$this->_parsePos = $oldParsePos;
$this->parsingHtml->code = $oldParseCode;
} | [
"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",
"->",
"parsingHtml",
"->",
"code",
"=",
"$",
"this",
"->",
"_subFOOTER",
";",
"$",
"this",
"->",
"_isInFooter",
"=",
"true",
";",
"$",
"this",
"->",
"_makeHTMLcode",
"(",
")",
";",
"$",
"this",
"->",
"_isInFooter",
"=",
"false",
";",
"$",
"this",
"->",
"_parsePos",
"=",
"$",
"oldParsePos",
";",
"$",
"this",
"->",
"parsingHtml",
"->",
"code",
"=",
"$",
"oldParseCode",
";",
"}"
] | draw the PDF footer with the HTML in page_footer
@access protected | [
"draw",
"the",
"PDF",
"footer",
"with",
"the",
"HTML",
"in",
"page_footer"
] | 83c9bd942e8520681808b70584e01d17157335ba | https://github.com/spipu/html2pdf/blob/83c9bd942e8520681808b70584e01d17157335ba/src/Html2Pdf.php#L972-L993 | train |
spipu/html2pdf | src/Html2Pdf.php | Html2Pdf._setNewLine | protected function _setNewLine($h, $curr = null)
{
$this->pdf->Ln($h);
$this->_setNewPositionForNewLine($curr);
} | php | protected function _setNewLine($h, $curr = null)
{
$this->pdf->Ln($h);
$this->_setNewPositionForNewLine($curr);
} | [
"protected",
"function",
"_setNewLine",
"(",
"$",
"h",
",",
"$",
"curr",
"=",
"null",
")",
"{",
"$",
"this",
"->",
"pdf",
"->",
"Ln",
"(",
"$",
"h",
")",
";",
"$",
"this",
"->",
"_setNewPositionForNewLine",
"(",
"$",
"curr",
")",
";",
"}"
] | new line, with a specific height
@access protected
@param float $h
@param integer $curr real current position in the text, if new line in the write of a text | [
"new",
"line",
"with",
"a",
"specific",
"height"
] | 83c9bd942e8520681808b70584e01d17157335ba | https://github.com/spipu/html2pdf/blob/83c9bd942e8520681808b70584e01d17157335ba/src/Html2Pdf.php#L1002-L1006 | train |
spipu/html2pdf | src/Html2Pdf.php | Html2Pdf.createSubHTML | protected function createSubHTML()
{
// prepare the subObject, if never prepare before
if (self::$_subobj === null) {
$this->_prepareSubObj();
}
// calculate the width to use
if ($this->parsingCss->value['width']) {
$marge = $this->parsingCss->value['padding']['l'] + $this->parsingCss->value['padding']['r'];
$marge+= $this->parsingCss->value['border']['l']['width'] + $this->parsingCss->value['border']['r']['width'];
$marge = $this->pdf->getW() - $this->parsingCss->value['width'] + $marge;
} else {
$marge = $this->_margeLeft+$this->_margeRight;
}
// BUGFIX : we have to call the method, because of a bug in php 5.1.6
self::$_subobj->pdf->getPage();
// clone the sub object
$subHtml = clone self::$_subobj;
$subHtml->parsingCss->table = $this->parsingCss->table;
$subHtml->parsingCss->value = $this->parsingCss->value;
$subHtml->initSubHtml(
$this->_format,
$this->_orientation,
$marge,
$this->_page,
$this->_defList,
$this->pdf->getMyLastPageGroup(),
$this->pdf->getMyLastPageGroupNb()
);
return $subHtml;
} | php | protected function createSubHTML()
{
// prepare the subObject, if never prepare before
if (self::$_subobj === null) {
$this->_prepareSubObj();
}
// calculate the width to use
if ($this->parsingCss->value['width']) {
$marge = $this->parsingCss->value['padding']['l'] + $this->parsingCss->value['padding']['r'];
$marge+= $this->parsingCss->value['border']['l']['width'] + $this->parsingCss->value['border']['r']['width'];
$marge = $this->pdf->getW() - $this->parsingCss->value['width'] + $marge;
} else {
$marge = $this->_margeLeft+$this->_margeRight;
}
// BUGFIX : we have to call the method, because of a bug in php 5.1.6
self::$_subobj->pdf->getPage();
// clone the sub object
$subHtml = clone self::$_subobj;
$subHtml->parsingCss->table = $this->parsingCss->table;
$subHtml->parsingCss->value = $this->parsingCss->value;
$subHtml->initSubHtml(
$this->_format,
$this->_orientation,
$marge,
$this->_page,
$this->_defList,
$this->pdf->getMyLastPageGroup(),
$this->pdf->getMyLastPageGroupNb()
);
return $subHtml;
} | [
"protected",
"function",
"createSubHTML",
"(",
")",
"{",
"// prepare the subObject, if never prepare before",
"if",
"(",
"self",
"::",
"$",
"_subobj",
"===",
"null",
")",
"{",
"$",
"this",
"->",
"_prepareSubObj",
"(",
")",
";",
"}",
"// calculate the width to use",
"if",
"(",
"$",
"this",
"->",
"parsingCss",
"->",
"value",
"[",
"'width'",
"]",
")",
"{",
"$",
"marge",
"=",
"$",
"this",
"->",
"parsingCss",
"->",
"value",
"[",
"'padding'",
"]",
"[",
"'l'",
"]",
"+",
"$",
"this",
"->",
"parsingCss",
"->",
"value",
"[",
"'padding'",
"]",
"[",
"'r'",
"]",
";",
"$",
"marge",
"+=",
"$",
"this",
"->",
"parsingCss",
"->",
"value",
"[",
"'border'",
"]",
"[",
"'l'",
"]",
"[",
"'width'",
"]",
"+",
"$",
"this",
"->",
"parsingCss",
"->",
"value",
"[",
"'border'",
"]",
"[",
"'r'",
"]",
"[",
"'width'",
"]",
";",
"$",
"marge",
"=",
"$",
"this",
"->",
"pdf",
"->",
"getW",
"(",
")",
"-",
"$",
"this",
"->",
"parsingCss",
"->",
"value",
"[",
"'width'",
"]",
"+",
"$",
"marge",
";",
"}",
"else",
"{",
"$",
"marge",
"=",
"$",
"this",
"->",
"_margeLeft",
"+",
"$",
"this",
"->",
"_margeRight",
";",
"}",
"// BUGFIX : we have to call the method, because of a bug in php 5.1.6",
"self",
"::",
"$",
"_subobj",
"->",
"pdf",
"->",
"getPage",
"(",
")",
";",
"// clone the sub object",
"$",
"subHtml",
"=",
"clone",
"self",
"::",
"$",
"_subobj",
";",
"$",
"subHtml",
"->",
"parsingCss",
"->",
"table",
"=",
"$",
"this",
"->",
"parsingCss",
"->",
"table",
";",
"$",
"subHtml",
"->",
"parsingCss",
"->",
"value",
"=",
"$",
"this",
"->",
"parsingCss",
"->",
"value",
";",
"$",
"subHtml",
"->",
"initSubHtml",
"(",
"$",
"this",
"->",
"_format",
",",
"$",
"this",
"->",
"_orientation",
",",
"$",
"marge",
",",
"$",
"this",
"->",
"_page",
",",
"$",
"this",
"->",
"_defList",
",",
"$",
"this",
"->",
"pdf",
"->",
"getMyLastPageGroup",
"(",
")",
",",
"$",
"this",
"->",
"pdf",
"->",
"getMyLastPageGroupNb",
"(",
")",
")",
";",
"return",
"$",
"subHtml",
";",
"}"
] | create a sub Html2Pdf, to calculate the multi-tables
@return Html2Pdf | [
"create",
"a",
"sub",
"Html2Pdf",
"to",
"calculate",
"the",
"multi",
"-",
"tables"
] | 83c9bd942e8520681808b70584e01d17157335ba | https://github.com/spipu/html2pdf/blob/83c9bd942e8520681808b70584e01d17157335ba/src/Html2Pdf.php#L1128-L1162 | train |
spipu/html2pdf | src/Html2Pdf.php | Html2Pdf._listeArab2Rom | 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/pow(10, $i));
if ($digit>=1) {
$nbArabic -= $digit*pow(10, $i);
if ($digit<=3) {
for ($j=$digit; $j>=1; $j--) {
$nbRoman .= $nbBaseTen[$i];
}
} elseif ($digit == 9) {
$nbRoman .= $nbBaseTen[$i].$nbBaseTen[$i+1];
} elseif ($digit == 4) {
$nbRoman .= $nbBaseTen[$i].$nbBaseFive[$i];
} else {
$nbRoman .= $nbBaseFive[$i];
for ($j=$digit-5; $j>=1; $j--) {
$nbRoman .= $nbBaseTen[$i];
}
}
}
}
return $nbRoman;
} | php | 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/pow(10, $i));
if ($digit>=1) {
$nbArabic -= $digit*pow(10, $i);
if ($digit<=3) {
for ($j=$digit; $j>=1; $j--) {
$nbRoman .= $nbBaseTen[$i];
}
} elseif ($digit == 9) {
$nbRoman .= $nbBaseTen[$i].$nbBaseTen[$i+1];
} elseif ($digit == 4) {
$nbRoman .= $nbBaseTen[$i].$nbBaseFive[$i];
} else {
$nbRoman .= $nbBaseFive[$i];
for ($j=$digit-5; $j>=1; $j--) {
$nbRoman .= $nbBaseTen[$i];
}
}
}
}
return $nbRoman;
} | [
"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",
"/",
"pow",
"(",
"10",
",",
"$",
"i",
")",
")",
";",
"if",
"(",
"$",
"digit",
">=",
"1",
")",
"{",
"$",
"nbArabic",
"-=",
"$",
"digit",
"*",
"pow",
"(",
"10",
",",
"$",
"i",
")",
";",
"if",
"(",
"$",
"digit",
"<=",
"3",
")",
"{",
"for",
"(",
"$",
"j",
"=",
"$",
"digit",
";",
"$",
"j",
">=",
"1",
";",
"$",
"j",
"--",
")",
"{",
"$",
"nbRoman",
".=",
"$",
"nbBaseTen",
"[",
"$",
"i",
"]",
";",
"}",
"}",
"elseif",
"(",
"$",
"digit",
"==",
"9",
")",
"{",
"$",
"nbRoman",
".=",
"$",
"nbBaseTen",
"[",
"$",
"i",
"]",
".",
"$",
"nbBaseTen",
"[",
"$",
"i",
"+",
"1",
"]",
";",
"}",
"elseif",
"(",
"$",
"digit",
"==",
"4",
")",
"{",
"$",
"nbRoman",
".=",
"$",
"nbBaseTen",
"[",
"$",
"i",
"]",
".",
"$",
"nbBaseFive",
"[",
"$",
"i",
"]",
";",
"}",
"else",
"{",
"$",
"nbRoman",
".=",
"$",
"nbBaseFive",
"[",
"$",
"i",
"]",
";",
"for",
"(",
"$",
"j",
"=",
"$",
"digit",
"-",
"5",
";",
"$",
"j",
">=",
"1",
";",
"$",
"j",
"--",
")",
"{",
"$",
"nbRoman",
".=",
"$",
"nbBaseTen",
"[",
"$",
"i",
"]",
";",
"}",
"}",
"}",
"}",
"return",
"$",
"nbRoman",
";",
"}"
] | Convert an arabic number into a roman number
@access protected
@param integer $nbArabic
@return string $nbRoman | [
"Convert",
"an",
"arabic",
"number",
"into",
"a",
"roman",
"number"
] | 83c9bd942e8520681808b70584e01d17157335ba | https://github.com/spipu/html2pdf/blob/83c9bd942e8520681808b70584e01d17157335ba/src/Html2Pdf.php#L1182-L1216 | train |
spipu/html2pdf | src/Html2Pdf.php | Html2Pdf._listeGetLi | 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 ($im) {
return array(false, false, $im);
}
switch ($st) {
case 'none':
return array('helvetica', true, ' ');
case 'upper-alpha':
case 'lower-alpha':
$str = '';
while ($nb>26) {
$str = chr(96+$nb%26).$str;
$nb = floor($nb/26);
}
$str = chr(96+$nb).$str;
return array('helvetica', false, ($up ? strtoupper($str) : $str).'.');
case 'upper-roman':
case 'lower-roman':
$str = $this->_listeArab2Rom($nb);
return array('helvetica', false, ($up ? strtoupper($str) : $str).'.');
case 'decimal':
return array('helvetica', false, $nb.'.');
case 'square':
return array('zapfdingbats', true, chr(110));
case 'circle':
return array('zapfdingbats', true, chr(109));
case 'disc':
default:
return array('zapfdingbats', true, chr(108));
}
} | php | 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 ($im) {
return array(false, false, $im);
}
switch ($st) {
case 'none':
return array('helvetica', true, ' ');
case 'upper-alpha':
case 'lower-alpha':
$str = '';
while ($nb>26) {
$str = chr(96+$nb%26).$str;
$nb = floor($nb/26);
}
$str = chr(96+$nb).$str;
return array('helvetica', false, ($up ? strtoupper($str) : $str).'.');
case 'upper-roman':
case 'lower-roman':
$str = $this->_listeArab2Rom($nb);
return array('helvetica', false, ($up ? strtoupper($str) : $str).'.');
case 'decimal':
return array('helvetica', false, $nb.'.');
case 'square':
return array('zapfdingbats', true, chr(110));
case 'circle':
return array('zapfdingbats', true, chr(109));
case 'disc':
default:
return array('zapfdingbats', true, chr(108));
}
} | [
"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",
"(",
"$",
"im",
")",
"{",
"return",
"array",
"(",
"false",
",",
"false",
",",
"$",
"im",
")",
";",
"}",
"switch",
"(",
"$",
"st",
")",
"{",
"case",
"'none'",
":",
"return",
"array",
"(",
"'helvetica'",
",",
"true",
",",
"' '",
")",
";",
"case",
"'upper-alpha'",
":",
"case",
"'lower-alpha'",
":",
"$",
"str",
"=",
"''",
";",
"while",
"(",
"$",
"nb",
">",
"26",
")",
"{",
"$",
"str",
"=",
"chr",
"(",
"96",
"+",
"$",
"nb",
"%",
"26",
")",
".",
"$",
"str",
";",
"$",
"nb",
"=",
"floor",
"(",
"$",
"nb",
"/",
"26",
")",
";",
"}",
"$",
"str",
"=",
"chr",
"(",
"96",
"+",
"$",
"nb",
")",
".",
"$",
"str",
";",
"return",
"array",
"(",
"'helvetica'",
",",
"false",
",",
"(",
"$",
"up",
"?",
"strtoupper",
"(",
"$",
"str",
")",
":",
"$",
"str",
")",
".",
"'.'",
")",
";",
"case",
"'upper-roman'",
":",
"case",
"'lower-roman'",
":",
"$",
"str",
"=",
"$",
"this",
"->",
"_listeArab2Rom",
"(",
"$",
"nb",
")",
";",
"return",
"array",
"(",
"'helvetica'",
",",
"false",
",",
"(",
"$",
"up",
"?",
"strtoupper",
"(",
"$",
"str",
")",
":",
"$",
"str",
")",
".",
"'.'",
")",
";",
"case",
"'decimal'",
":",
"return",
"array",
"(",
"'helvetica'",
",",
"false",
",",
"$",
"nb",
".",
"'.'",
")",
";",
"case",
"'square'",
":",
"return",
"array",
"(",
"'zapfdingbats'",
",",
"true",
",",
"chr",
"(",
"110",
")",
")",
";",
"case",
"'circle'",
":",
"return",
"array",
"(",
"'zapfdingbats'",
",",
"true",
",",
"chr",
"(",
"109",
")",
")",
";",
"case",
"'disc'",
":",
"default",
":",
"return",
"array",
"(",
"'zapfdingbats'",
",",
"true",
",",
"chr",
"(",
"108",
")",
")",
";",
"}",
"}"
] | get the information of the li on the current level
@access protected
@return array(fontName, small size, string) | [
"get",
"the",
"information",
"of",
"the",
"li",
"on",
"the",
"current",
"level"
] | 83c9bd942e8520681808b70584e01d17157335ba | https://github.com/spipu/html2pdf/blob/83c9bd942e8520681808b70584e01d17157335ba/src/Html2Pdf.php#L1256-L1301 | train |
spipu/html2pdf | src/Html2Pdf.php | Html2Pdf._listeAddLevel | protected function _listeAddLevel($type = 'ul', $style = '', $img = null, $start = null)
{
// get the url of the image, if we want to use a image
if ($img) {
if (preg_match('/^url\(([^)]+)\)$/isU', trim($img), $match)) {
$img = $match[1];
} else {
$img = null;
}
} else {
$img = null;
}
// prepare the datas
if (!in_array($type, array('ul', 'ol'))) {
$type = 'ul';
}
if (!in_array($style, array('lower-alpha', 'upper-alpha', 'upper-roman', 'lower-roman', 'decimal', 'square', 'circle', 'disc', 'none'))) {
$style = '';
}
if (!$style) {
if ($type === 'ul') {
$style = 'disc';
} else {
$style = 'decimal';
}
}
if (is_null($start) || (int) $start<1) {
$start=0;
} else {
$start--;
}
// add the new level
$this->_defList[count($this->_defList)] = array('style' => $style, 'nb' => $start, 'img' => $img);
} | php | protected function _listeAddLevel($type = 'ul', $style = '', $img = null, $start = null)
{
// get the url of the image, if we want to use a image
if ($img) {
if (preg_match('/^url\(([^)]+)\)$/isU', trim($img), $match)) {
$img = $match[1];
} else {
$img = null;
}
} else {
$img = null;
}
// prepare the datas
if (!in_array($type, array('ul', 'ol'))) {
$type = 'ul';
}
if (!in_array($style, array('lower-alpha', 'upper-alpha', 'upper-roman', 'lower-roman', 'decimal', 'square', 'circle', 'disc', 'none'))) {
$style = '';
}
if (!$style) {
if ($type === 'ul') {
$style = 'disc';
} else {
$style = 'decimal';
}
}
if (is_null($start) || (int) $start<1) {
$start=0;
} else {
$start--;
}
// add the new level
$this->_defList[count($this->_defList)] = array('style' => $style, 'nb' => $start, 'img' => $img);
} | [
"protected",
"function",
"_listeAddLevel",
"(",
"$",
"type",
"=",
"'ul'",
",",
"$",
"style",
"=",
"''",
",",
"$",
"img",
"=",
"null",
",",
"$",
"start",
"=",
"null",
")",
"{",
"// get the url of the image, if we want to use a image",
"if",
"(",
"$",
"img",
")",
"{",
"if",
"(",
"preg_match",
"(",
"'/^url\\(([^)]+)\\)$/isU'",
",",
"trim",
"(",
"$",
"img",
")",
",",
"$",
"match",
")",
")",
"{",
"$",
"img",
"=",
"$",
"match",
"[",
"1",
"]",
";",
"}",
"else",
"{",
"$",
"img",
"=",
"null",
";",
"}",
"}",
"else",
"{",
"$",
"img",
"=",
"null",
";",
"}",
"// prepare the datas",
"if",
"(",
"!",
"in_array",
"(",
"$",
"type",
",",
"array",
"(",
"'ul'",
",",
"'ol'",
")",
")",
")",
"{",
"$",
"type",
"=",
"'ul'",
";",
"}",
"if",
"(",
"!",
"in_array",
"(",
"$",
"style",
",",
"array",
"(",
"'lower-alpha'",
",",
"'upper-alpha'",
",",
"'upper-roman'",
",",
"'lower-roman'",
",",
"'decimal'",
",",
"'square'",
",",
"'circle'",
",",
"'disc'",
",",
"'none'",
")",
")",
")",
"{",
"$",
"style",
"=",
"''",
";",
"}",
"if",
"(",
"!",
"$",
"style",
")",
"{",
"if",
"(",
"$",
"type",
"===",
"'ul'",
")",
"{",
"$",
"style",
"=",
"'disc'",
";",
"}",
"else",
"{",
"$",
"style",
"=",
"'decimal'",
";",
"}",
"}",
"if",
"(",
"is_null",
"(",
"$",
"start",
")",
"||",
"(",
"int",
")",
"$",
"start",
"<",
"1",
")",
"{",
"$",
"start",
"=",
"0",
";",
"}",
"else",
"{",
"$",
"start",
"--",
";",
"}",
"// add the new level",
"$",
"this",
"->",
"_defList",
"[",
"count",
"(",
"$",
"this",
"->",
"_defList",
")",
"]",
"=",
"array",
"(",
"'style'",
"=>",
"$",
"style",
",",
"'nb'",
"=>",
"$",
"start",
",",
"'img'",
"=>",
"$",
"img",
")",
";",
"}"
] | add a level to the list
@access protected
@param string $type : ul, ol
@param string $style : lower-alpha, ...
@param string $img | [
"add",
"a",
"level",
"to",
"the",
"list"
] | 83c9bd942e8520681808b70584e01d17157335ba | https://github.com/spipu/html2pdf/blob/83c9bd942e8520681808b70584e01d17157335ba/src/Html2Pdf.php#L1311-L1348 | train |
spipu/html2pdf | src/Html2Pdf.php | Html2Pdf._listeDelLevel | protected function _listeDelLevel()
{
if (count($this->_defList)) {
unset($this->_defList[count($this->_defList)-1]);
$this->_defList = array_values($this->_defList);
}
} | php | protected function _listeDelLevel()
{
if (count($this->_defList)) {
unset($this->_defList[count($this->_defList)-1]);
$this->_defList = array_values($this->_defList);
}
} | [
"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
@access protected | [
"remove",
"a",
"level",
"from",
"the",
"list"
] | 83c9bd942e8520681808b70584e01d17157335ba | https://github.com/spipu/html2pdf/blob/83c9bd942e8520681808b70584e01d17157335ba/src/Html2Pdf.php#L1355-L1361 | train |
spipu/html2pdf | src/Html2Pdf.php | Html2Pdf._makeHTMLcode | protected function _makeHTMLcode()
{
$amountHtmlCode = count($this->parsingHtml->code);
// foreach elements of the parsing
for ($this->_parsePos=0; $this->_parsePos<$amountHtmlCode; $this->_parsePos++) {
// get the action to do
$action = $this->parsingHtml->code[$this->_parsePos];
// if it is a opening of table / ul / ol
if (in_array($action->getName(), array('table', 'ul', 'ol')) && !$action->isClose()) {
// we will work as a sub HTML to calculate the size of the element
$this->_subPart = true;
// get the name of the opening tag
$tagOpen = $action->getName();
// save the actual pos on the parsing
$this->_tempPos = $this->_parsePos;
// foreach elements, while we are in the opened tag
while (isset($this->parsingHtml->code[$this->_tempPos]) && !($this->parsingHtml->code[$this->_tempPos]->getName() == $tagOpen && $this->parsingHtml->code[$this->_tempPos]->isClose())) {
// make the action
$this->_executeAction($this->parsingHtml->code[$this->_tempPos]);
$this->_tempPos++;
}
// execute the closure of the tag
if (isset($this->parsingHtml->code[$this->_tempPos])) {
$this->_executeAction($this->parsingHtml->code[$this->_tempPos]);
}
// end of the sub part
$this->_subPart = false;
}
// execute the action
$this->_executeAction($action);
}
} | php | protected function _makeHTMLcode()
{
$amountHtmlCode = count($this->parsingHtml->code);
// foreach elements of the parsing
for ($this->_parsePos=0; $this->_parsePos<$amountHtmlCode; $this->_parsePos++) {
// get the action to do
$action = $this->parsingHtml->code[$this->_parsePos];
// if it is a opening of table / ul / ol
if (in_array($action->getName(), array('table', 'ul', 'ol')) && !$action->isClose()) {
// we will work as a sub HTML to calculate the size of the element
$this->_subPart = true;
// get the name of the opening tag
$tagOpen = $action->getName();
// save the actual pos on the parsing
$this->_tempPos = $this->_parsePos;
// foreach elements, while we are in the opened tag
while (isset($this->parsingHtml->code[$this->_tempPos]) && !($this->parsingHtml->code[$this->_tempPos]->getName() == $tagOpen && $this->parsingHtml->code[$this->_tempPos]->isClose())) {
// make the action
$this->_executeAction($this->parsingHtml->code[$this->_tempPos]);
$this->_tempPos++;
}
// execute the closure of the tag
if (isset($this->parsingHtml->code[$this->_tempPos])) {
$this->_executeAction($this->parsingHtml->code[$this->_tempPos]);
}
// end of the sub part
$this->_subPart = false;
}
// execute the action
$this->_executeAction($action);
}
} | [
"protected",
"function",
"_makeHTMLcode",
"(",
")",
"{",
"$",
"amountHtmlCode",
"=",
"count",
"(",
"$",
"this",
"->",
"parsingHtml",
"->",
"code",
")",
";",
"// foreach elements of the parsing",
"for",
"(",
"$",
"this",
"->",
"_parsePos",
"=",
"0",
";",
"$",
"this",
"->",
"_parsePos",
"<",
"$",
"amountHtmlCode",
";",
"$",
"this",
"->",
"_parsePos",
"++",
")",
"{",
"// get the action to do",
"$",
"action",
"=",
"$",
"this",
"->",
"parsingHtml",
"->",
"code",
"[",
"$",
"this",
"->",
"_parsePos",
"]",
";",
"// if it is a opening of table / ul / ol",
"if",
"(",
"in_array",
"(",
"$",
"action",
"->",
"getName",
"(",
")",
",",
"array",
"(",
"'table'",
",",
"'ul'",
",",
"'ol'",
")",
")",
"&&",
"!",
"$",
"action",
"->",
"isClose",
"(",
")",
")",
"{",
"// we will work as a sub HTML to calculate the size of the element",
"$",
"this",
"->",
"_subPart",
"=",
"true",
";",
"// get the name of the opening tag",
"$",
"tagOpen",
"=",
"$",
"action",
"->",
"getName",
"(",
")",
";",
"// save the actual pos on the parsing",
"$",
"this",
"->",
"_tempPos",
"=",
"$",
"this",
"->",
"_parsePos",
";",
"// foreach elements, while we are in the opened tag",
"while",
"(",
"isset",
"(",
"$",
"this",
"->",
"parsingHtml",
"->",
"code",
"[",
"$",
"this",
"->",
"_tempPos",
"]",
")",
"&&",
"!",
"(",
"$",
"this",
"->",
"parsingHtml",
"->",
"code",
"[",
"$",
"this",
"->",
"_tempPos",
"]",
"->",
"getName",
"(",
")",
"==",
"$",
"tagOpen",
"&&",
"$",
"this",
"->",
"parsingHtml",
"->",
"code",
"[",
"$",
"this",
"->",
"_tempPos",
"]",
"->",
"isClose",
"(",
")",
")",
")",
"{",
"// make the action",
"$",
"this",
"->",
"_executeAction",
"(",
"$",
"this",
"->",
"parsingHtml",
"->",
"code",
"[",
"$",
"this",
"->",
"_tempPos",
"]",
")",
";",
"$",
"this",
"->",
"_tempPos",
"++",
";",
"}",
"// execute the closure of the tag",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"parsingHtml",
"->",
"code",
"[",
"$",
"this",
"->",
"_tempPos",
"]",
")",
")",
"{",
"$",
"this",
"->",
"_executeAction",
"(",
"$",
"this",
"->",
"parsingHtml",
"->",
"code",
"[",
"$",
"this",
"->",
"_tempPos",
"]",
")",
";",
"}",
"// end of the sub part",
"$",
"this",
"->",
"_subPart",
"=",
"false",
";",
"}",
"// execute the action",
"$",
"this",
"->",
"_executeAction",
"(",
"$",
"action",
")",
";",
"}",
"}"
] | execute the actions to convert the html
@access protected | [
"execute",
"the",
"actions",
"to",
"convert",
"the",
"html"
] | 83c9bd942e8520681808b70584e01d17157335ba | https://github.com/spipu/html2pdf/blob/83c9bd942e8520681808b70584e01d17157335ba/src/Html2Pdf.php#L1368-L1409 | train |
spipu/html2pdf | src/Html2Pdf.php | Html2Pdf._executeAction | protected function _executeAction(Node $action)
{
$name = strtoupper($action->getName());
if ($this->_firstPage && $name !== 'PAGE' && !$action->isClose()) {
$this->_setNewPage();
}
// properties of the action
$properties = $action->getParams();
// name of the action (old method)
$fnc = ($action->isClose() ? '_tag_close_' : '_tag_open_').$name;
$tagObject = $this->getTagObject($action->getName());
if (!is_null($tagObject)) {
if ($action->isClose()) {
$res = $tagObject->close($properties);
} else {
$res = $tagObject->open($properties);
}
} elseif (is_callable(array($this, $fnc))) {
$res = $this->{$fnc}($properties);
} else {
$e = new HtmlParsingException(
'The html tag ['.$action->getName().'] is not known by Html2Pdf. '.
'You can create it and push it on the Html2Pdf GitHub project.'
);
$e->setInvalidTag($action->getName());
$e->setHtmlLine($action->getLine());
throw $e;
}
// save the name of the action
$this->_previousCall = $fnc;
// return the result
return $res;
} | php | protected function _executeAction(Node $action)
{
$name = strtoupper($action->getName());
if ($this->_firstPage && $name !== 'PAGE' && !$action->isClose()) {
$this->_setNewPage();
}
// properties of the action
$properties = $action->getParams();
// name of the action (old method)
$fnc = ($action->isClose() ? '_tag_close_' : '_tag_open_').$name;
$tagObject = $this->getTagObject($action->getName());
if (!is_null($tagObject)) {
if ($action->isClose()) {
$res = $tagObject->close($properties);
} else {
$res = $tagObject->open($properties);
}
} elseif (is_callable(array($this, $fnc))) {
$res = $this->{$fnc}($properties);
} else {
$e = new HtmlParsingException(
'The html tag ['.$action->getName().'] is not known by Html2Pdf. '.
'You can create it and push it on the Html2Pdf GitHub project.'
);
$e->setInvalidTag($action->getName());
$e->setHtmlLine($action->getLine());
throw $e;
}
// save the name of the action
$this->_previousCall = $fnc;
// return the result
return $res;
} | [
"protected",
"function",
"_executeAction",
"(",
"Node",
"$",
"action",
")",
"{",
"$",
"name",
"=",
"strtoupper",
"(",
"$",
"action",
"->",
"getName",
"(",
")",
")",
";",
"if",
"(",
"$",
"this",
"->",
"_firstPage",
"&&",
"$",
"name",
"!==",
"'PAGE'",
"&&",
"!",
"$",
"action",
"->",
"isClose",
"(",
")",
")",
"{",
"$",
"this",
"->",
"_setNewPage",
"(",
")",
";",
"}",
"// properties of the action",
"$",
"properties",
"=",
"$",
"action",
"->",
"getParams",
"(",
")",
";",
"// name of the action (old method)",
"$",
"fnc",
"=",
"(",
"$",
"action",
"->",
"isClose",
"(",
")",
"?",
"'_tag_close_'",
":",
"'_tag_open_'",
")",
".",
"$",
"name",
";",
"$",
"tagObject",
"=",
"$",
"this",
"->",
"getTagObject",
"(",
"$",
"action",
"->",
"getName",
"(",
")",
")",
";",
"if",
"(",
"!",
"is_null",
"(",
"$",
"tagObject",
")",
")",
"{",
"if",
"(",
"$",
"action",
"->",
"isClose",
"(",
")",
")",
"{",
"$",
"res",
"=",
"$",
"tagObject",
"->",
"close",
"(",
"$",
"properties",
")",
";",
"}",
"else",
"{",
"$",
"res",
"=",
"$",
"tagObject",
"->",
"open",
"(",
"$",
"properties",
")",
";",
"}",
"}",
"elseif",
"(",
"is_callable",
"(",
"array",
"(",
"$",
"this",
",",
"$",
"fnc",
")",
")",
")",
"{",
"$",
"res",
"=",
"$",
"this",
"->",
"{",
"$",
"fnc",
"}",
"(",
"$",
"properties",
")",
";",
"}",
"else",
"{",
"$",
"e",
"=",
"new",
"HtmlParsingException",
"(",
"'The html tag ['",
".",
"$",
"action",
"->",
"getName",
"(",
")",
".",
"'] is not known by Html2Pdf. '",
".",
"'You can create it and push it on the Html2Pdf GitHub project.'",
")",
";",
"$",
"e",
"->",
"setInvalidTag",
"(",
"$",
"action",
"->",
"getName",
"(",
")",
")",
";",
"$",
"e",
"->",
"setHtmlLine",
"(",
"$",
"action",
"->",
"getLine",
"(",
")",
")",
";",
"throw",
"$",
"e",
";",
"}",
"// save the name of the action",
"$",
"this",
"->",
"_previousCall",
"=",
"$",
"fnc",
";",
"// return the result",
"return",
"$",
"res",
";",
"}"
] | execute the action from the parsing
@param Node $action | [
"execute",
"the",
"action",
"from",
"the",
"parsing"
] | 83c9bd942e8520681808b70584e01d17157335ba | https://github.com/spipu/html2pdf/blob/83c9bd942e8520681808b70584e01d17157335ba/src/Html2Pdf.php#L1416-L1455 | train |
spipu/html2pdf | src/Html2Pdf.php | Html2Pdf._getElementY | protected function _getElementY($h)
{
if ($this->_subPart || $this->_isSubPart || !$this->_currentH || $this->_currentH<$h) {
return 0;
}
return ($this->_currentH-$h)*0.8;
} | php | protected function _getElementY($h)
{
if ($this->_subPart || $this->_isSubPart || !$this->_currentH || $this->_currentH<$h) {
return 0;
}
return ($this->_currentH-$h)*0.8;
} | [
"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
@access protected
@param float $h
@return float | [
"get",
"the",
"position",
"of",
"the",
"element",
"on",
"the",
"current",
"line",
"depending",
"on",
"its",
"height"
] | 83c9bd942e8520681808b70584e01d17157335ba | https://github.com/spipu/html2pdf/blob/83c9bd942e8520681808b70584e01d17157335ba/src/Html2Pdf.php#L1464-L1471 | train |
spipu/html2pdf | src/Html2Pdf.php | Html2Pdf._makeBreakLine | 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, '', null, $curr);
}
} else {
$this->_setNewPositionForNewLine($curr);
}
$this->_maxH = 0;
$this->_maxE = 0;
} | php | 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, '', null, $curr);
}
} else {
$this->_setNewPositionForNewLine($curr);
}
$this->_maxH = 0;
$this->_maxE = 0;
} | [
"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",
",",
"''",
",",
"null",
",",
"$",
"curr",
")",
";",
"}",
"}",
"else",
"{",
"$",
"this",
"->",
"_setNewPositionForNewLine",
"(",
"$",
"curr",
")",
";",
"}",
"$",
"this",
"->",
"_maxH",
"=",
"0",
";",
"$",
"this",
"->",
"_maxE",
"=",
"0",
";",
"}"
] | make a break line
@access protected
@param float $h current line height
@param integer $curr real current position in the text, if new line in the write of a text | [
"make",
"a",
"break",
"line"
] | 83c9bd942e8520681808b70584e01d17157335ba | https://github.com/spipu/html2pdf/blob/83c9bd942e8520681808b70584e01d17157335ba/src/Html2Pdf.php#L1480-L1494 | train |
spipu/html2pdf | src/Html2Pdf.php | Html2Pdf._tag_close_PAGE_FOOTER_SUB | 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['mp'];
$this->_margeLeft = $this->_subSTATES['ml'];
$this->_margeRight = $this->_subSTATES['mr'];
$this->_margeTop = $this->_subSTATES['mt'];
$this->_margeBottom = $this->_subSTATES['mb'];
$this->pdf->SetMargins($this->_margeLeft, $this->_margeTop, $this->_margeRight);
$this->pdf->SetAutoPageBreak(false, $this->_margeBottom);
$this->pdf->SetXY($this->_subSTATES['x'], $this->_subSTATES['y']);
$this->parsingCss->fontSet();
$this->_maxH = 0;
return true;
} | php | 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['mp'];
$this->_margeLeft = $this->_subSTATES['ml'];
$this->_margeRight = $this->_subSTATES['mr'];
$this->_margeTop = $this->_subSTATES['mt'];
$this->_margeBottom = $this->_subSTATES['mb'];
$this->pdf->SetMargins($this->_margeLeft, $this->_margeTop, $this->_margeRight);
$this->pdf->SetAutoPageBreak(false, $this->_margeBottom);
$this->pdf->SetXY($this->_subSTATES['x'], $this->_subSTATES['y']);
$this->parsingCss->fontSet();
$this->_maxH = 0;
return true;
} | [
"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",
"[",
"'mp'",
"]",
";",
"$",
"this",
"->",
"_margeLeft",
"=",
"$",
"this",
"->",
"_subSTATES",
"[",
"'ml'",
"]",
";",
"$",
"this",
"->",
"_margeRight",
"=",
"$",
"this",
"->",
"_subSTATES",
"[",
"'mr'",
"]",
";",
"$",
"this",
"->",
"_margeTop",
"=",
"$",
"this",
"->",
"_subSTATES",
"[",
"'mt'",
"]",
";",
"$",
"this",
"->",
"_margeBottom",
"=",
"$",
"this",
"->",
"_subSTATES",
"[",
"'mb'",
"]",
";",
"$",
"this",
"->",
"pdf",
"->",
"SetMargins",
"(",
"$",
"this",
"->",
"_margeLeft",
",",
"$",
"this",
"->",
"_margeTop",
",",
"$",
"this",
"->",
"_margeRight",
")",
";",
"$",
"this",
"->",
"pdf",
"->",
"SetAutoPageBreak",
"(",
"false",
",",
"$",
"this",
"->",
"_margeBottom",
")",
";",
"$",
"this",
"->",
"pdf",
"->",
"SetXY",
"(",
"$",
"this",
"->",
"_subSTATES",
"[",
"'x'",
"]",
",",
"$",
"this",
"->",
"_subSTATES",
"[",
"'y'",
"]",
")",
";",
"$",
"this",
"->",
"parsingCss",
"->",
"fontSet",
"(",
")",
";",
"$",
"this",
"->",
"_maxH",
"=",
"0",
";",
"return",
"true",
";",
"}"
] | It is not a real tag. Do not use it directly
@param array $param
@return boolean | [
"It",
"is",
"not",
"a",
"real",
"tag",
".",
"Do",
"not",
"use",
"it",
"directly"
] | 83c9bd942e8520681808b70584e01d17157335ba | https://github.com/spipu/html2pdf/blob/83c9bd942e8520681808b70584e01d17157335ba/src/Html2Pdf.php#L2984-L3007 | train |
spipu/html2pdf | src/Html2Pdf.php | Html2Pdf._INDEX_NewPage | 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;
}
} | php | 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;
}
} | [
"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 !!!!
@param &int $page
@return integer $oldPage | [
"new",
"page",
"for",
"the",
"automatic",
"Index",
"do",
"not",
"use",
"this",
"method",
".",
"Only",
"myPdf",
"could",
"use",
"it",
"!!!!"
] | 83c9bd942e8520681808b70584e01d17157335ba | https://github.com/spipu/html2pdf/blob/83c9bd942e8520681808b70584e01d17157335ba/src/Html2Pdf.php#L6419-L6432 | train |
spipu/html2pdf | src/MyPdf.php | MyPdf.Footer | public function Footer()
{
// prepare the text from the tranlated text
$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->_footerParam['time']) {
$txt.= ($txt ? ' - ' : '').Locale::get('pdf01');
}
if (!$this->_footerParam['date'] && $this->_footerParam['time']) {
$txt.= ($txt ? ' - ' : '').Locale::get('pdf02');
}
if ($this->_footerParam['page']) {
$txt.= ($txt ? ' - ' : '').Locale::get('pdf04');
}
if (strlen($txt)>0) {
// replace some values
$toReplace = array(
'[[date_d]]' => date('d'),
'[[date_m]]' => date('m'),
'[[date_y]]' => date('Y'),
'[[date_h]]' => date('H'),
'[[date_i]]' => date('i'),
'[[date_s]]' => date('s'),
'[[page_cu]]' => $this->getMyNumPage(),
'[[page_nb]]' => $this->getMyAliasNbPages(),
);
$txt = str_replace(array_keys($toReplace), array_values($toReplace), $txt);
// draw the footer
parent::SetY(-11);
$this->SetFont('helvetica', 'I', 8);
$this->Cell(0, 10, $txt, 0, 0, 'R');
}
} | php | public function Footer()
{
// prepare the text from the tranlated text
$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->_footerParam['time']) {
$txt.= ($txt ? ' - ' : '').Locale::get('pdf01');
}
if (!$this->_footerParam['date'] && $this->_footerParam['time']) {
$txt.= ($txt ? ' - ' : '').Locale::get('pdf02');
}
if ($this->_footerParam['page']) {
$txt.= ($txt ? ' - ' : '').Locale::get('pdf04');
}
if (strlen($txt)>0) {
// replace some values
$toReplace = array(
'[[date_d]]' => date('d'),
'[[date_m]]' => date('m'),
'[[date_y]]' => date('Y'),
'[[date_h]]' => date('H'),
'[[date_i]]' => date('i'),
'[[date_s]]' => date('s'),
'[[page_cu]]' => $this->getMyNumPage(),
'[[page_nb]]' => $this->getMyAliasNbPages(),
);
$txt = str_replace(array_keys($toReplace), array_values($toReplace), $txt);
// draw the footer
parent::SetY(-11);
$this->SetFont('helvetica', 'I', 8);
$this->Cell(0, 10, $txt, 0, 0, 'R');
}
} | [
"public",
"function",
"Footer",
"(",
")",
"{",
"// prepare the text from the tranlated text",
"$",
"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",
"->",
"_footerParam",
"[",
"'time'",
"]",
")",
"{",
"$",
"txt",
".=",
"(",
"$",
"txt",
"?",
"' - '",
":",
"''",
")",
".",
"Locale",
"::",
"get",
"(",
"'pdf01'",
")",
";",
"}",
"if",
"(",
"!",
"$",
"this",
"->",
"_footerParam",
"[",
"'date'",
"]",
"&&",
"$",
"this",
"->",
"_footerParam",
"[",
"'time'",
"]",
")",
"{",
"$",
"txt",
".=",
"(",
"$",
"txt",
"?",
"' - '",
":",
"''",
")",
".",
"Locale",
"::",
"get",
"(",
"'pdf02'",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"_footerParam",
"[",
"'page'",
"]",
")",
"{",
"$",
"txt",
".=",
"(",
"$",
"txt",
"?",
"' - '",
":",
"''",
")",
".",
"Locale",
"::",
"get",
"(",
"'pdf04'",
")",
";",
"}",
"if",
"(",
"strlen",
"(",
"$",
"txt",
")",
">",
"0",
")",
"{",
"// replace some values",
"$",
"toReplace",
"=",
"array",
"(",
"'[[date_d]]'",
"=>",
"date",
"(",
"'d'",
")",
",",
"'[[date_m]]'",
"=>",
"date",
"(",
"'m'",
")",
",",
"'[[date_y]]'",
"=>",
"date",
"(",
"'Y'",
")",
",",
"'[[date_h]]'",
"=>",
"date",
"(",
"'H'",
")",
",",
"'[[date_i]]'",
"=>",
"date",
"(",
"'i'",
")",
",",
"'[[date_s]]'",
"=>",
"date",
"(",
"'s'",
")",
",",
"'[[page_cu]]'",
"=>",
"$",
"this",
"->",
"getMyNumPage",
"(",
")",
",",
"'[[page_nb]]'",
"=>",
"$",
"this",
"->",
"getMyAliasNbPages",
"(",
")",
",",
")",
";",
"$",
"txt",
"=",
"str_replace",
"(",
"array_keys",
"(",
"$",
"toReplace",
")",
",",
"array_values",
"(",
"$",
"toReplace",
")",
",",
"$",
"txt",
")",
";",
"// draw the footer",
"parent",
"::",
"SetY",
"(",
"-",
"11",
")",
";",
"$",
"this",
"->",
"SetFont",
"(",
"'helvetica'",
",",
"'I'",
",",
"8",
")",
";",
"$",
"this",
"->",
"Cell",
"(",
"0",
",",
"10",
",",
"$",
"txt",
",",
"0",
",",
"0",
",",
"'R'",
")",
";",
"}",
"}"
] | This function is call automatically by TCPDF at the end of a page
It takes no parameters
@access public | [
"This",
"function",
"is",
"call",
"automatically",
"by",
"TCPDF",
"at",
"the",
"end",
"of",
"a",
"page",
"It",
"takes",
"no",
"parameters"
] | 83c9bd942e8520681808b70584e01d17157335ba | https://github.com/spipu/html2pdf/blob/83c9bd942e8520681808b70584e01d17157335ba/src/MyPdf.php#L93-L132 | train |
spipu/html2pdf | src/MyPdf.php | MyPdf.cloneFontFrom | 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();
$this->fontkeys = &$pdf->getFontKeys();
$this->font_obj_ids = &$pdf->getFontObjIds();
$this->annotation_fonts = &$pdf->getAnnotFonts();
} | php | 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();
$this->fontkeys = &$pdf->getFontKeys();
$this->font_obj_ids = &$pdf->getFontObjIds();
$this->annotation_fonts = &$pdf->getAnnotFonts();
} | [
"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",
"(",
")",
";",
"$",
"this",
"->",
"fontkeys",
"=",
"&",
"$",
"pdf",
"->",
"getFontKeys",
"(",
")",
";",
"$",
"this",
"->",
"font_obj_ids",
"=",
"&",
"$",
"pdf",
"->",
"getFontObjIds",
"(",
")",
";",
"$",
"this",
"->",
"annotation_fonts",
"=",
"&",
"$",
"pdf",
"->",
"getAnnotFonts",
"(",
")",
";",
"}"
] | 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
@param myPdf &$pdf
@access public | [
"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"
] | 83c9bd942e8520681808b70584e01d17157335ba | https://github.com/spipu/html2pdf/blob/83c9bd942e8520681808b70584e01d17157335ba/src/MyPdf.php#L141-L152 | train |
spipu/html2pdf | src/MyPdf.php | MyPdf.isLoadedFont | public function isLoadedFont($fontKey)
{
if (isset($this->fonts[$fontKey])) {
return true;
}
if (isset($this->CoreFonts[$fontKey])) {
return true;
}
return false;
} | php | public function isLoadedFont($fontKey)
{
if (isset($this->fonts[$fontKey])) {
return true;
}
if (isset($this->CoreFonts[$fontKey])) {
return true;
}
return false;
} | [
"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
@param string Font Key
@return boolean
@access public | [
"Verify",
"that",
"a",
"Font",
"is",
"already",
"loaded"
] | 83c9bd942e8520681808b70584e01d17157335ba | https://github.com/spipu/html2pdf/blob/83c9bd942e8520681808b70584e01d17157335ba/src/MyPdf.php#L205-L216 | train |
spipu/html2pdf | src/MyPdf.php | MyPdf.setWordSpacing | public function setWordSpacing($ws = 0.)
{
$this->ws = $ws;
$this->_out(sprintf('%.3F Tw', $ws*$this->k));
} | php | public function setWordSpacing($ws = 0.)
{
$this->ws = $ws;
$this->_out(sprintf('%.3F Tw', $ws*$this->k));
} | [
"public",
"function",
"setWordSpacing",
"(",
"$",
"ws",
"=",
"0.",
")",
"{",
"$",
"this",
"->",
"ws",
"=",
"$",
"ws",
";",
"$",
"this",
"->",
"_out",
"(",
"sprintf",
"(",
"'%.3F Tw'",
",",
"$",
"ws",
"*",
"$",
"this",
"->",
"k",
")",
")",
";",
"}"
] | set the Word Spacing
@param float word spacing
@access public | [
"set",
"the",
"Word",
"Spacing"
] | 83c9bd942e8520681808b70584e01d17157335ba | https://github.com/spipu/html2pdf/blob/83c9bd942e8520681808b70584e01d17157335ba/src/MyPdf.php#L235-L239 | train |
spipu/html2pdf | src/MyPdf.php | MyPdf.setTranslate | public function setTranslate($xT, $yT)
{
// Matrix for Translate
$tm[0]=1;
$tm[1]=0;
$tm[2]=0;
$tm[3]=1;
$tm[4]=$xT*$this->k;
$tm[5]=-$yT*$this->k;
// apply the Transform Matric
$this->_out(sprintf('%.3F %.3F %.3F %.3F %.3F %.3F cm', $tm[0], $tm[1], $tm[2], $tm[3], $tm[4], $tm[5]));
} | php | public function setTranslate($xT, $yT)
{
// Matrix for Translate
$tm[0]=1;
$tm[1]=0;
$tm[2]=0;
$tm[3]=1;
$tm[4]=$xT*$this->k;
$tm[5]=-$yT*$this->k;
// apply the Transform Matric
$this->_out(sprintf('%.3F %.3F %.3F %.3F %.3F %.3F cm', $tm[0], $tm[1], $tm[2], $tm[3], $tm[4], $tm[5]));
} | [
"public",
"function",
"setTranslate",
"(",
"$",
"xT",
",",
"$",
"yT",
")",
"{",
"// Matrix for Translate",
"$",
"tm",
"[",
"0",
"]",
"=",
"1",
";",
"$",
"tm",
"[",
"1",
"]",
"=",
"0",
";",
"$",
"tm",
"[",
"2",
"]",
"=",
"0",
";",
"$",
"tm",
"[",
"3",
"]",
"=",
"1",
";",
"$",
"tm",
"[",
"4",
"]",
"=",
"$",
"xT",
"*",
"$",
"this",
"->",
"k",
";",
"$",
"tm",
"[",
"5",
"]",
"=",
"-",
"$",
"yT",
"*",
"$",
"this",
"->",
"k",
";",
"// apply the Transform Matric",
"$",
"this",
"->",
"_out",
"(",
"sprintf",
"(",
"'%.3F %.3F %.3F %.3F %.3F %.3F cm'",
",",
"$",
"tm",
"[",
"0",
"]",
",",
"$",
"tm",
"[",
"1",
"]",
",",
"$",
"tm",
"[",
"2",
"]",
",",
"$",
"tm",
"[",
"3",
"]",
",",
"$",
"tm",
"[",
"4",
"]",
",",
"$",
"tm",
"[",
"5",
"]",
")",
")",
";",
"}"
] | add a Translate transformation
@param float $Tx
@param float $Ty
@access public | [
"add",
"a",
"Translate",
"transformation"
] | 83c9bd942e8520681808b70584e01d17157335ba | https://github.com/spipu/html2pdf/blob/83c9bd942e8520681808b70584e01d17157335ba/src/MyPdf.php#L541-L553 | train |
spipu/html2pdf | src/MyPdf.php | MyPdf.setRotation | public function setRotation($angle, $xC = null, $yC = null)
{
// if no center, rotate around the current posiition
if ($xC === null) {
$xC=$this->x;
}
if ($yC === null) {
$yC=$this->y;
}
// prepare the coordinate
$yC=($this->h-$yC)*$this->k;
$xC*=$this->k;
// Matrix for Rotate
$tm[0]=cos(deg2rad($angle));
$tm[1]=sin(deg2rad($angle));
$tm[2]=-$tm[1];
$tm[3]=$tm[0];
$tm[4]=$xC+$tm[1]*$yC-$tm[0]*$xC;
$tm[5]=$yC-$tm[0]*$yC-$tm[1]*$xC;
// apply the Transform Matric
$this->_out(sprintf('%.3F %.3F %.3F %.3F %.3F %.3F cm', $tm[0], $tm[1], $tm[2], $tm[3], $tm[4], $tm[5]));
} | php | public function setRotation($angle, $xC = null, $yC = null)
{
// if no center, rotate around the current posiition
if ($xC === null) {
$xC=$this->x;
}
if ($yC === null) {
$yC=$this->y;
}
// prepare the coordinate
$yC=($this->h-$yC)*$this->k;
$xC*=$this->k;
// Matrix for Rotate
$tm[0]=cos(deg2rad($angle));
$tm[1]=sin(deg2rad($angle));
$tm[2]=-$tm[1];
$tm[3]=$tm[0];
$tm[4]=$xC+$tm[1]*$yC-$tm[0]*$xC;
$tm[5]=$yC-$tm[0]*$yC-$tm[1]*$xC;
// apply the Transform Matric
$this->_out(sprintf('%.3F %.3F %.3F %.3F %.3F %.3F cm', $tm[0], $tm[1], $tm[2], $tm[3], $tm[4], $tm[5]));
} | [
"public",
"function",
"setRotation",
"(",
"$",
"angle",
",",
"$",
"xC",
"=",
"null",
",",
"$",
"yC",
"=",
"null",
")",
"{",
"// if no center, rotate around the current posiition",
"if",
"(",
"$",
"xC",
"===",
"null",
")",
"{",
"$",
"xC",
"=",
"$",
"this",
"->",
"x",
";",
"}",
"if",
"(",
"$",
"yC",
"===",
"null",
")",
"{",
"$",
"yC",
"=",
"$",
"this",
"->",
"y",
";",
"}",
"// prepare the coordinate",
"$",
"yC",
"=",
"(",
"$",
"this",
"->",
"h",
"-",
"$",
"yC",
")",
"*",
"$",
"this",
"->",
"k",
";",
"$",
"xC",
"*=",
"$",
"this",
"->",
"k",
";",
"// Matrix for Rotate",
"$",
"tm",
"[",
"0",
"]",
"=",
"cos",
"(",
"deg2rad",
"(",
"$",
"angle",
")",
")",
";",
"$",
"tm",
"[",
"1",
"]",
"=",
"sin",
"(",
"deg2rad",
"(",
"$",
"angle",
")",
")",
";",
"$",
"tm",
"[",
"2",
"]",
"=",
"-",
"$",
"tm",
"[",
"1",
"]",
";",
"$",
"tm",
"[",
"3",
"]",
"=",
"$",
"tm",
"[",
"0",
"]",
";",
"$",
"tm",
"[",
"4",
"]",
"=",
"$",
"xC",
"+",
"$",
"tm",
"[",
"1",
"]",
"*",
"$",
"yC",
"-",
"$",
"tm",
"[",
"0",
"]",
"*",
"$",
"xC",
";",
"$",
"tm",
"[",
"5",
"]",
"=",
"$",
"yC",
"-",
"$",
"tm",
"[",
"0",
"]",
"*",
"$",
"yC",
"-",
"$",
"tm",
"[",
"1",
"]",
"*",
"$",
"xC",
";",
"// apply the Transform Matric",
"$",
"this",
"->",
"_out",
"(",
"sprintf",
"(",
"'%.3F %.3F %.3F %.3F %.3F %.3F cm'",
",",
"$",
"tm",
"[",
"0",
"]",
",",
"$",
"tm",
"[",
"1",
"]",
",",
"$",
"tm",
"[",
"2",
"]",
",",
"$",
"tm",
"[",
"3",
"]",
",",
"$",
"tm",
"[",
"4",
"]",
",",
"$",
"tm",
"[",
"5",
"]",
")",
")",
";",
"}"
] | add a Rotate transformation
@param float $angle
@param float $Cx
@param float $Cy
@access public | [
"add",
"a",
"Rotate",
"transformation"
] | 83c9bd942e8520681808b70584e01d17157335ba | https://github.com/spipu/html2pdf/blob/83c9bd942e8520681808b70584e01d17157335ba/src/MyPdf.php#L563-L587 | train |
spipu/html2pdf | src/MyPdf.php | MyPdf.svgLine | public function svgLine($x1, $y1, $x2, $y2)
{
// get the Closing operator
$op='S';
// drawing
$this->_Point($x1, $y1, true);
$this->_Line($x2, $y2, true);
$this->_out($op);
} | php | public function svgLine($x1, $y1, $x2, $y2)
{
// get the Closing operator
$op='S';
// drawing
$this->_Point($x1, $y1, true);
$this->_Line($x2, $y2, true);
$this->_out($op);
} | [
"public",
"function",
"svgLine",
"(",
"$",
"x1",
",",
"$",
"y1",
",",
"$",
"x2",
",",
"$",
"y2",
")",
"{",
"// get the Closing operator",
"$",
"op",
"=",
"'S'",
";",
"// drawing",
"$",
"this",
"->",
"_Point",
"(",
"$",
"x1",
",",
"$",
"y1",
",",
"true",
")",
";",
"$",
"this",
"->",
"_Line",
"(",
"$",
"x2",
",",
"$",
"y2",
",",
"true",
")",
";",
"$",
"this",
"->",
"_out",
"(",
"$",
"op",
")",
";",
"}"
] | SVG - make a Line
@param float $x1
@param float $y1
@param float $x2
@param float $y2
@access public | [
"SVG",
"-",
"make",
"a",
"Line"
] | 83c9bd942e8520681808b70584e01d17157335ba | https://github.com/spipu/html2pdf/blob/83c9bd942e8520681808b70584e01d17157335ba/src/MyPdf.php#L776-L785 | train |
spipu/html2pdf | src/MyPdf.php | MyPdf.svgEllipse | public function svgEllipse($x0, $y0, $rx, $ry, $style)
{
// get the Closing operator from the PDF Style
if ($style === 'F') {
$op='f';
} elseif ($style === 'FD' || $style === 'DF') {
$op='B';
} else {
$op='S';
}
// drawing
$this->_Arc($x0, $y0, $rx, $ry, 0, 2*M_PI, true, true, true);
$this->_out($op);
} | php | public function svgEllipse($x0, $y0, $rx, $ry, $style)
{
// get the Closing operator from the PDF Style
if ($style === 'F') {
$op='f';
} elseif ($style === 'FD' || $style === 'DF') {
$op='B';
} else {
$op='S';
}
// drawing
$this->_Arc($x0, $y0, $rx, $ry, 0, 2*M_PI, true, true, true);
$this->_out($op);
} | [
"public",
"function",
"svgEllipse",
"(",
"$",
"x0",
",",
"$",
"y0",
",",
"$",
"rx",
",",
"$",
"ry",
",",
"$",
"style",
")",
"{",
"// get the Closing operator from the PDF Style",
"if",
"(",
"$",
"style",
"===",
"'F'",
")",
"{",
"$",
"op",
"=",
"'f'",
";",
"}",
"elseif",
"(",
"$",
"style",
"===",
"'FD'",
"||",
"$",
"style",
"===",
"'DF'",
")",
"{",
"$",
"op",
"=",
"'B'",
";",
"}",
"else",
"{",
"$",
"op",
"=",
"'S'",
";",
"}",
"// drawing",
"$",
"this",
"->",
"_Arc",
"(",
"$",
"x0",
",",
"$",
"y0",
",",
"$",
"rx",
",",
"$",
"ry",
",",
"0",
",",
"2",
"*",
"M_PI",
",",
"true",
",",
"true",
",",
"true",
")",
";",
"$",
"this",
"->",
"_out",
"(",
"$",
"op",
")",
";",
"}"
] | SVG - make a Ellipse
@param float $x0 x Center
@param float $y0 y Center
@param float $rx x radius
@param float $ry y radius
@param string $style PDF Style
@access public | [
"SVG",
"-",
"make",
"a",
"Ellipse"
] | 83c9bd942e8520681808b70584e01d17157335ba | https://github.com/spipu/html2pdf/blob/83c9bd942e8520681808b70584e01d17157335ba/src/MyPdf.php#L797-L811 | train |
spipu/html2pdf | src/MyPdf.php | MyPdf.doTransform | public function doTransform($n = null)
{
// get the last Transformation Matrix
$nb = count($this->_transf);
if ($nb) {
$m = $this->_transf[$nb-1];
} else {
$m = array(1,0,0,1,0,0);
}
// if no transform, get the Identity Matrix
if (!$n) {
$n = array(1,0,0,1,0,0);
}
// create the new Transformation Matrix
$this->_transf[] = array(
$m[0]*$n[0]+$m[2]*$n[1],
$m[1]*$n[0]+$m[3]*$n[1],
$m[0]*$n[2]+$m[2]*$n[3],
$m[1]*$n[2]+$m[3]*$n[3],
$m[0]*$n[4]+$m[2]*$n[5]+$m[4],
$m[1]*$n[4]+$m[3]*$n[5]+$m[5]
);
} | php | public function doTransform($n = null)
{
// get the last Transformation Matrix
$nb = count($this->_transf);
if ($nb) {
$m = $this->_transf[$nb-1];
} else {
$m = array(1,0,0,1,0,0);
}
// if no transform, get the Identity Matrix
if (!$n) {
$n = array(1,0,0,1,0,0);
}
// create the new Transformation Matrix
$this->_transf[] = array(
$m[0]*$n[0]+$m[2]*$n[1],
$m[1]*$n[0]+$m[3]*$n[1],
$m[0]*$n[2]+$m[2]*$n[3],
$m[1]*$n[2]+$m[3]*$n[3],
$m[0]*$n[4]+$m[2]*$n[5]+$m[4],
$m[1]*$n[4]+$m[3]*$n[5]+$m[5]
);
} | [
"public",
"function",
"doTransform",
"(",
"$",
"n",
"=",
"null",
")",
"{",
"// get the last Transformation Matrix",
"$",
"nb",
"=",
"count",
"(",
"$",
"this",
"->",
"_transf",
")",
";",
"if",
"(",
"$",
"nb",
")",
"{",
"$",
"m",
"=",
"$",
"this",
"->",
"_transf",
"[",
"$",
"nb",
"-",
"1",
"]",
";",
"}",
"else",
"{",
"$",
"m",
"=",
"array",
"(",
"1",
",",
"0",
",",
"0",
",",
"1",
",",
"0",
",",
"0",
")",
";",
"}",
"// if no transform, get the Identity Matrix",
"if",
"(",
"!",
"$",
"n",
")",
"{",
"$",
"n",
"=",
"array",
"(",
"1",
",",
"0",
",",
"0",
",",
"1",
",",
"0",
",",
"0",
")",
";",
"}",
"// create the new Transformation Matrix",
"$",
"this",
"->",
"_transf",
"[",
"]",
"=",
"array",
"(",
"$",
"m",
"[",
"0",
"]",
"*",
"$",
"n",
"[",
"0",
"]",
"+",
"$",
"m",
"[",
"2",
"]",
"*",
"$",
"n",
"[",
"1",
"]",
",",
"$",
"m",
"[",
"1",
"]",
"*",
"$",
"n",
"[",
"0",
"]",
"+",
"$",
"m",
"[",
"3",
"]",
"*",
"$",
"n",
"[",
"1",
"]",
",",
"$",
"m",
"[",
"0",
"]",
"*",
"$",
"n",
"[",
"2",
"]",
"+",
"$",
"m",
"[",
"2",
"]",
"*",
"$",
"n",
"[",
"3",
"]",
",",
"$",
"m",
"[",
"1",
"]",
"*",
"$",
"n",
"[",
"2",
"]",
"+",
"$",
"m",
"[",
"3",
"]",
"*",
"$",
"n",
"[",
"3",
"]",
",",
"$",
"m",
"[",
"0",
"]",
"*",
"$",
"n",
"[",
"4",
"]",
"+",
"$",
"m",
"[",
"2",
"]",
"*",
"$",
"n",
"[",
"5",
"]",
"+",
"$",
"m",
"[",
"4",
"]",
",",
"$",
"m",
"[",
"1",
"]",
"*",
"$",
"n",
"[",
"4",
"]",
"+",
"$",
"m",
"[",
"3",
"]",
"*",
"$",
"n",
"[",
"5",
"]",
"+",
"$",
"m",
"[",
"5",
"]",
")",
";",
"}"
] | SVG - add a transformation Matric
@param array $n matrix
@access public | [
"SVG",
"-",
"add",
"a",
"transformation",
"Matric"
] | 83c9bd942e8520681808b70584e01d17157335ba | https://github.com/spipu/html2pdf/blob/83c9bd942e8520681808b70584e01d17157335ba/src/MyPdf.php#L1285-L1309 | train |
spipu/html2pdf | src/MyPdf.php | MyPdf.myBarcode | public function myBarcode($code, $type, $x, $y, $w, $h, $labelFontsize, $color, $dimension = '1D')
{
// the style of the barcode
$style = array(
'position' => 'S',
'text' => ($labelFontsize ? true : false),
'fgcolor' => $color,
'bgcolor' => false,
);
// build the barcode
if ($dimension === '2D') {
// PDF417, DATAMATRIX ...
$this->write2DBarcode($code, $type, $x, $y, $w, $h, '', $style, 'N');
} else {
$this->write1DBarcode($code, $type, $x, $y, $w, $h, '', $style, 'N');
}
// it Label => add the FontSize to the height
if ($labelFontsize) {
$h+= $labelFontsize;
}
// return the size of the barcode
return array($w, $h);
} | php | public function myBarcode($code, $type, $x, $y, $w, $h, $labelFontsize, $color, $dimension = '1D')
{
// the style of the barcode
$style = array(
'position' => 'S',
'text' => ($labelFontsize ? true : false),
'fgcolor' => $color,
'bgcolor' => false,
);
// build the barcode
if ($dimension === '2D') {
// PDF417, DATAMATRIX ...
$this->write2DBarcode($code, $type, $x, $y, $w, $h, '', $style, 'N');
} else {
$this->write1DBarcode($code, $type, $x, $y, $w, $h, '', $style, 'N');
}
// it Label => add the FontSize to the height
if ($labelFontsize) {
$h+= $labelFontsize;
}
// return the size of the barcode
return array($w, $h);
} | [
"public",
"function",
"myBarcode",
"(",
"$",
"code",
",",
"$",
"type",
",",
"$",
"x",
",",
"$",
"y",
",",
"$",
"w",
",",
"$",
"h",
",",
"$",
"labelFontsize",
",",
"$",
"color",
",",
"$",
"dimension",
"=",
"'1D'",
")",
"{",
"// the style of the barcode",
"$",
"style",
"=",
"array",
"(",
"'position'",
"=>",
"'S'",
",",
"'text'",
"=>",
"(",
"$",
"labelFontsize",
"?",
"true",
":",
"false",
")",
",",
"'fgcolor'",
"=>",
"$",
"color",
",",
"'bgcolor'",
"=>",
"false",
",",
")",
";",
"// build the barcode",
"if",
"(",
"$",
"dimension",
"===",
"'2D'",
")",
"{",
"// PDF417, DATAMATRIX ...",
"$",
"this",
"->",
"write2DBarcode",
"(",
"$",
"code",
",",
"$",
"type",
",",
"$",
"x",
",",
"$",
"y",
",",
"$",
"w",
",",
"$",
"h",
",",
"''",
",",
"$",
"style",
",",
"'N'",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"write1DBarcode",
"(",
"$",
"code",
",",
"$",
"type",
",",
"$",
"x",
",",
"$",
"y",
",",
"$",
"w",
",",
"$",
"h",
",",
"''",
",",
"$",
"style",
",",
"'N'",
")",
";",
"}",
"// it Label => add the FontSize to the height",
"if",
"(",
"$",
"labelFontsize",
")",
"{",
"$",
"h",
"+=",
"$",
"labelFontsize",
";",
"}",
"// return the size of the barcode",
"return",
"array",
"(",
"$",
"w",
",",
"$",
"h",
")",
";",
"}"
] | Convert a Html2Pdf barcode in a TCPDF barcode
@param string $code code to print
@param string $type type of barcode (see tcpdf/barcodes.php for supported formats)
@param int $x x position in user units
@param int $y y position in user units
@param int $w width in user units
@param int $h height in user units
@param int $labelFontsize of the Test Label. If false : no Label
@param array $color color of the foreground
@param string $dimension 1D or 2D
@access public | [
"Convert",
"a",
"Html2Pdf",
"barcode",
"in",
"a",
"TCPDF",
"barcode"
] | 83c9bd942e8520681808b70584e01d17157335ba | https://github.com/spipu/html2pdf/blob/83c9bd942e8520681808b70584e01d17157335ba/src/MyPdf.php#L1335-L1360 | train |
spipu/html2pdf | src/MyPdf.php | MyPdf.getMyAliasNbPages | 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 $new;
}
} | php | 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 $new;
}
} | [
"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",
"$",
"new",
";",
"}",
"}"
] | Returns the string alias used for the total number of pages.
@access public
@return string;
@see TCPDF::getAliasNbPages(), TCPDF::getPageGroupAlias() | [
"Returns",
"the",
"string",
"alias",
"used",
"for",
"the",
"total",
"number",
"of",
"pages",
"."
] | 83c9bd942e8520681808b70584e01d17157335ba | https://github.com/spipu/html2pdf/blob/83c9bd942e8520681808b70584e01d17157335ba/src/MyPdf.php#L1455-L1467 | train |
spipu/html2pdf | src/Parsing/HtmlLexer.php | HtmlLexer.tokenize | public function tokenize($html)
{
// initialise the array
$tokens = array();
// regexp to separate the tags from the texts
$reg = '/(<\/?\w[^<>]*>)|([^<]+|<)/is';
$commentRegex = '/(<!--.*-->)/isU';
// last match found
$str = '';
$offset = 0;
$line = 1;
$length = strlen($html);
// As it finds a match
while ($offset < $length) {
if (strpos($html, '<!--', $offset) === $offset
&& preg_match($commentRegex, $html, $match, PREG_OFFSET_CAPTURE, $offset)
) {
$line += substr_count($match[1][0], "\n");
$offset = $match[0][1] + strlen($match[0][0]);
continue;
}
preg_match($reg, $html, $parse, PREG_OFFSET_CAPTURE, $offset);
// if it is a tag
if ($parse[1][0]) {
// save the previous text if it exists
if ($str !== '') {
$tokens[] = new Token('txt', $str);
}
// save the tag, with the offset
$tokens[] = new Token('code', trim($parse[1][0]), $line);
$line += substr_count($parse[1][0], "\n");
// init the current text
$str = '';
} else { // else (if it is a text)
// add the new text to the current text
$str .= $parse[2][0];
$line += substr_count($parse[2][0], "\n");
}
// Update offset to the end of the match
$offset = $parse[0][1] + strlen($parse[0][0]);
unset($parse);
}
// if a text is present in the end, we save it
if ($str !== '') {
$tokens[] = new Token('txt', $str);
}
return $tokens;
} | php | public function tokenize($html)
{
// initialise the array
$tokens = array();
// regexp to separate the tags from the texts
$reg = '/(<\/?\w[^<>]*>)|([^<]+|<)/is';
$commentRegex = '/(<!--.*-->)/isU';
// last match found
$str = '';
$offset = 0;
$line = 1;
$length = strlen($html);
// As it finds a match
while ($offset < $length) {
if (strpos($html, '<!--', $offset) === $offset
&& preg_match($commentRegex, $html, $match, PREG_OFFSET_CAPTURE, $offset)
) {
$line += substr_count($match[1][0], "\n");
$offset = $match[0][1] + strlen($match[0][0]);
continue;
}
preg_match($reg, $html, $parse, PREG_OFFSET_CAPTURE, $offset);
// if it is a tag
if ($parse[1][0]) {
// save the previous text if it exists
if ($str !== '') {
$tokens[] = new Token('txt', $str);
}
// save the tag, with the offset
$tokens[] = new Token('code', trim($parse[1][0]), $line);
$line += substr_count($parse[1][0], "\n");
// init the current text
$str = '';
} else { // else (if it is a text)
// add the new text to the current text
$str .= $parse[2][0];
$line += substr_count($parse[2][0], "\n");
}
// Update offset to the end of the match
$offset = $parse[0][1] + strlen($parse[0][0]);
unset($parse);
}
// if a text is present in the end, we save it
if ($str !== '') {
$tokens[] = new Token('txt', $str);
}
return $tokens;
} | [
"public",
"function",
"tokenize",
"(",
"$",
"html",
")",
"{",
"// initialise the array",
"$",
"tokens",
"=",
"array",
"(",
")",
";",
"// regexp to separate the tags from the texts",
"$",
"reg",
"=",
"'/(<\\/?\\w[^<>]*>)|([^<]+|<)/is'",
";",
"$",
"commentRegex",
"=",
"'/(<!--.*-->)/isU'",
";",
"// last match found",
"$",
"str",
"=",
"''",
";",
"$",
"offset",
"=",
"0",
";",
"$",
"line",
"=",
"1",
";",
"$",
"length",
"=",
"strlen",
"(",
"$",
"html",
")",
";",
"// As it finds a match",
"while",
"(",
"$",
"offset",
"<",
"$",
"length",
")",
"{",
"if",
"(",
"strpos",
"(",
"$",
"html",
",",
"'<!--'",
",",
"$",
"offset",
")",
"===",
"$",
"offset",
"&&",
"preg_match",
"(",
"$",
"commentRegex",
",",
"$",
"html",
",",
"$",
"match",
",",
"PREG_OFFSET_CAPTURE",
",",
"$",
"offset",
")",
")",
"{",
"$",
"line",
"+=",
"substr_count",
"(",
"$",
"match",
"[",
"1",
"]",
"[",
"0",
"]",
",",
"\"\\n\"",
")",
";",
"$",
"offset",
"=",
"$",
"match",
"[",
"0",
"]",
"[",
"1",
"]",
"+",
"strlen",
"(",
"$",
"match",
"[",
"0",
"]",
"[",
"0",
"]",
")",
";",
"continue",
";",
"}",
"preg_match",
"(",
"$",
"reg",
",",
"$",
"html",
",",
"$",
"parse",
",",
"PREG_OFFSET_CAPTURE",
",",
"$",
"offset",
")",
";",
"// if it is a tag",
"if",
"(",
"$",
"parse",
"[",
"1",
"]",
"[",
"0",
"]",
")",
"{",
"// save the previous text if it exists",
"if",
"(",
"$",
"str",
"!==",
"''",
")",
"{",
"$",
"tokens",
"[",
"]",
"=",
"new",
"Token",
"(",
"'txt'",
",",
"$",
"str",
")",
";",
"}",
"// save the tag, with the offset",
"$",
"tokens",
"[",
"]",
"=",
"new",
"Token",
"(",
"'code'",
",",
"trim",
"(",
"$",
"parse",
"[",
"1",
"]",
"[",
"0",
"]",
")",
",",
"$",
"line",
")",
";",
"$",
"line",
"+=",
"substr_count",
"(",
"$",
"parse",
"[",
"1",
"]",
"[",
"0",
"]",
",",
"\"\\n\"",
")",
";",
"// init the current text",
"$",
"str",
"=",
"''",
";",
"}",
"else",
"{",
"// else (if it is a text)",
"// add the new text to the current text",
"$",
"str",
".=",
"$",
"parse",
"[",
"2",
"]",
"[",
"0",
"]",
";",
"$",
"line",
"+=",
"substr_count",
"(",
"$",
"parse",
"[",
"2",
"]",
"[",
"0",
"]",
",",
"\"\\n\"",
")",
";",
"}",
"// Update offset to the end of the match",
"$",
"offset",
"=",
"$",
"parse",
"[",
"0",
"]",
"[",
"1",
"]",
"+",
"strlen",
"(",
"$",
"parse",
"[",
"0",
"]",
"[",
"0",
"]",
")",
";",
"unset",
"(",
"$",
"parse",
")",
";",
"}",
"// if a text is present in the end, we save it",
"if",
"(",
"$",
"str",
"!==",
"''",
")",
"{",
"$",
"tokens",
"[",
"]",
"=",
"new",
"Token",
"(",
"'txt'",
",",
"$",
"str",
")",
";",
"}",
"return",
"$",
"tokens",
";",
"}"
] | Tokenize the HTML code
@param string $html HTML code to tokenize
@return Token[] | [
"Tokenize",
"the",
"HTML",
"code"
] | 83c9bd942e8520681808b70584e01d17157335ba | https://github.com/spipu/html2pdf/blob/83c9bd942e8520681808b70584e01d17157335ba/src/Parsing/HtmlLexer.php#L26-L80 | train |
spipu/html2pdf | src/Exception/ExceptionFormatter.php | ExceptionFormatter.getAdditionalData | protected function getAdditionalData(Html2PdfException $e)
{
$data = array();
// read the error
switch ($e->getCode()) {
case HtmlParsingException::ERROR_CODE:
/** @var HtmlParsingException $e */
$data['invalid tag'] = $e->getInvalidTag();
$data['html line'] = $e->getHtmlLine();
break;
case ImageException::ERROR_CODE:
/** @var ImageException $e */
$data['image src'] = $e->getImage();
break;
case LongSentenceException::ERROR_CODE:
/** @var LongSentenceException $e */
$data['sentence'] = $e->getSentence();
$data['box width'] = $e->getWidthBox();
$data['length'] = $e->getLength();
break;
case TableException::ERROR_CODE:
case Html2PdfException::ERROR_CODE:
default:
break;
}
return $data;
} | php | protected function getAdditionalData(Html2PdfException $e)
{
$data = array();
// read the error
switch ($e->getCode()) {
case HtmlParsingException::ERROR_CODE:
/** @var HtmlParsingException $e */
$data['invalid tag'] = $e->getInvalidTag();
$data['html line'] = $e->getHtmlLine();
break;
case ImageException::ERROR_CODE:
/** @var ImageException $e */
$data['image src'] = $e->getImage();
break;
case LongSentenceException::ERROR_CODE:
/** @var LongSentenceException $e */
$data['sentence'] = $e->getSentence();
$data['box width'] = $e->getWidthBox();
$data['length'] = $e->getLength();
break;
case TableException::ERROR_CODE:
case Html2PdfException::ERROR_CODE:
default:
break;
}
return $data;
} | [
"protected",
"function",
"getAdditionalData",
"(",
"Html2PdfException",
"$",
"e",
")",
"{",
"$",
"data",
"=",
"array",
"(",
")",
";",
"// read the error",
"switch",
"(",
"$",
"e",
"->",
"getCode",
"(",
")",
")",
"{",
"case",
"HtmlParsingException",
"::",
"ERROR_CODE",
":",
"/** @var HtmlParsingException $e */",
"$",
"data",
"[",
"'invalid tag'",
"]",
"=",
"$",
"e",
"->",
"getInvalidTag",
"(",
")",
";",
"$",
"data",
"[",
"'html line'",
"]",
"=",
"$",
"e",
"->",
"getHtmlLine",
"(",
")",
";",
"break",
";",
"case",
"ImageException",
"::",
"ERROR_CODE",
":",
"/** @var ImageException $e */",
"$",
"data",
"[",
"'image src'",
"]",
"=",
"$",
"e",
"->",
"getImage",
"(",
")",
";",
"break",
";",
"case",
"LongSentenceException",
"::",
"ERROR_CODE",
":",
"/** @var LongSentenceException $e */",
"$",
"data",
"[",
"'sentence'",
"]",
"=",
"$",
"e",
"->",
"getSentence",
"(",
")",
";",
"$",
"data",
"[",
"'box width'",
"]",
"=",
"$",
"e",
"->",
"getWidthBox",
"(",
")",
";",
"$",
"data",
"[",
"'length'",
"]",
"=",
"$",
"e",
"->",
"getLength",
"(",
")",
";",
"break",
";",
"case",
"TableException",
"::",
"ERROR_CODE",
":",
"case",
"Html2PdfException",
"::",
"ERROR_CODE",
":",
"default",
":",
"break",
";",
"}",
"return",
"$",
"data",
";",
"}"
] | get the additional data from the exception
@param Html2PdfException $e the exception to display
@return array | [
"get",
"the",
"additional",
"data",
"from",
"the",
"exception"
] | 83c9bd942e8520681808b70584e01d17157335ba | https://github.com/spipu/html2pdf/blob/83c9bd942e8520681808b70584e01d17157335ba/src/Exception/ExceptionFormatter.php#L74-L105 | train |
spipu/html2pdf | src/Exception/ExceptionFormatter.php | ExceptionFormatter.buildTextMessage | 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";
if (!empty($data)) {
foreach ($data as $key => $value) {
$this->message .= ' '.ucwords($key).': '.trim($value)."\n";
}
}
} | php | 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";
if (!empty($data)) {
foreach ($data as $key => $value) {
$this->message .= ' '.ucwords($key).': '.trim($value)."\n";
}
}
} | [
"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\"",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"data",
")",
")",
"{",
"foreach",
"(",
"$",
"data",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"$",
"this",
"->",
"message",
".=",
"' '",
".",
"ucwords",
"(",
"$",
"key",
")",
".",
"': '",
".",
"trim",
"(",
"$",
"value",
")",
".",
"\"\\n\"",
";",
"}",
"}",
"}"
] | Build the text message
@param Html2PdfException $e the exception of the error
@param array $data additionnal data
@return void | [
"Build",
"the",
"text",
"message"
] | 83c9bd942e8520681808b70584e01d17157335ba | https://github.com/spipu/html2pdf/blob/83c9bd942e8520681808b70584e01d17157335ba/src/Exception/ExceptionFormatter.php#L115-L127 | train |
spipu/html2pdf | src/Exception/ExceptionFormatter.php | ExceptionFormatter.buildHtmlMessage | 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->getMessage())."<br />\n";
$this->htmlMessage.= ' File: '.$e->getFile()."<br />\n";
$this->htmlMessage.= ' Line: '.$e->getLine()."<br />\n";
if (!empty($data)) {
foreach ($data as $key => $value) {
$this->htmlMessage .= ' '.ucwords($key).': '.trim(htmlentities($value))."<br />\n";
}
}
} | php | 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->getMessage())."<br />\n";
$this->htmlMessage.= ' File: '.$e->getFile()."<br />\n";
$this->htmlMessage.= ' Line: '.$e->getLine()."<br />\n";
if (!empty($data)) {
foreach ($data as $key => $value) {
$this->htmlMessage .= ' '.ucwords($key).': '.trim(htmlentities($value))."<br />\n";
}
}
} | [
"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",
"->",
"getMessage",
"(",
")",
")",
".",
"\"<br />\\n\"",
";",
"$",
"this",
"->",
"htmlMessage",
".=",
"' File: '",
".",
"$",
"e",
"->",
"getFile",
"(",
")",
".",
"\"<br />\\n\"",
";",
"$",
"this",
"->",
"htmlMessage",
".=",
"' Line: '",
".",
"$",
"e",
"->",
"getLine",
"(",
")",
".",
"\"<br />\\n\"",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"data",
")",
")",
"{",
"foreach",
"(",
"$",
"data",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"$",
"this",
"->",
"htmlMessage",
".=",
"' '",
".",
"ucwords",
"(",
"$",
"key",
")",
".",
"': '",
".",
"trim",
"(",
"htmlentities",
"(",
"$",
"value",
")",
")",
".",
"\"<br />\\n\"",
";",
"}",
"}",
"}"
] | build the html message
@param Html2PdfException $e the exception of the error
@param array $data additional data
@return void | [
"build",
"the",
"html",
"message"
] | 83c9bd942e8520681808b70584e01d17157335ba | https://github.com/spipu/html2pdf/blob/83c9bd942e8520681808b70584e01d17157335ba/src/Exception/ExceptionFormatter.php#L137-L151 | train |
spipu/html2pdf | src/Parsing/Html.php | Html.getCloneCodes | public function getCloneCodes()
{
$codes = array();
foreach ($this->code as $key => $code) {
$codes[$key] = clone $code;
}
return $codes;
} | php | public function getCloneCodes()
{
$codes = array();
foreach ($this->code as $key => $code) {
$codes[$key] = clone $code;
}
return $codes;
} | [
"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
@return Node[] | [
"Get",
"the",
"list",
"of",
"the",
"codes",
"but",
"cloned"
] | 83c9bd942e8520681808b70584e01d17157335ba | https://github.com/spipu/html2pdf/blob/83c9bd942e8520681808b70584e01d17157335ba/src/Parsing/Html.php#L62-L69 | train |
spipu/html2pdf | src/Parsing/Html.php | Html.verifyMustContain | 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 && $inMainTag > 0) {
$foundMustTag = true;
}
if ($action->getName() == $mainTag && $action->isClose()) {
if (!$foundMustTag) {
$exception = new HtmlParsingException(
"The tag [$mainTag] must contain at least one tag [$mustTag]"
);
$exception->setInvalidTag($action->getName());
$exception->setHtmlLine($action->getLine());
throw $exception;
}
$inMainTag--;
}
}
return true;
} | php | 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 && $inMainTag > 0) {
$foundMustTag = true;
}
if ($action->getName() == $mainTag && $action->isClose()) {
if (!$foundMustTag) {
$exception = new HtmlParsingException(
"The tag [$mainTag] must contain at least one tag [$mustTag]"
);
$exception->setInvalidTag($action->getName());
$exception->setHtmlLine($action->getLine());
throw $exception;
}
$inMainTag--;
}
}
return true;
} | [
"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",
"&&",
"$",
"inMainTag",
">",
"0",
")",
"{",
"$",
"foundMustTag",
"=",
"true",
";",
"}",
"if",
"(",
"$",
"action",
"->",
"getName",
"(",
")",
"==",
"$",
"mainTag",
"&&",
"$",
"action",
"->",
"isClose",
"(",
")",
")",
"{",
"if",
"(",
"!",
"$",
"foundMustTag",
")",
"{",
"$",
"exception",
"=",
"new",
"HtmlParsingException",
"(",
"\"The tag [$mainTag] must contain at least one tag [$mustTag]\"",
")",
";",
"$",
"exception",
"->",
"setInvalidTag",
"(",
"$",
"action",
"->",
"getName",
"(",
")",
")",
";",
"$",
"exception",
"->",
"setHtmlLine",
"(",
"$",
"action",
"->",
"getLine",
"(",
")",
")",
";",
"throw",
"$",
"exception",
";",
"}",
"$",
"inMainTag",
"--",
";",
"}",
"}",
"return",
"true",
";",
"}"
] | Verify some tags that must contain other tags
@param Node[] $actions
@param string $mainTag
@param string $mustTag
@return bool
@throws HtmlParsingException | [
"Verify",
"some",
"tags",
"that",
"must",
"contain",
"other",
"tags"
] | 83c9bd942e8520681808b70584e01d17157335ba | https://github.com/spipu/html2pdf/blob/83c9bd942e8520681808b70584e01d17157335ba/src/Parsing/Html.php#L195-L224 | train |
spipu/html2pdf | src/Parsing/Html.php | Html.getTextAction | protected function getTextAction(Token $token)
{
// action to use for each line of the content of a <pre> Tag
$tagPreBr = new Node('br', array('style' => array(), 'num' => 0), false);
$actions = array();
// if we are not in a <pre> tag
if (!$this->tagPreIn) {
// save the action
$actions[] = new Node('write', array('txt' => $this->textParser->prepareTxt($token->getData())), false);
} else { // else (if we are in a <pre> tag)
// prepare the text
$data = str_replace("\r", '', $token->getData());
$lines = explode("\n", $data);
// foreach line of the text
foreach ($lines as $k => $txt) {
// transform the line
$txt = str_replace("\t", self::HTML_TAB, $txt);
$txt = str_replace(' ', ' ', $txt);
// add a break line
if ($k > 0) {
$actions[] = clone $tagPreBr;
}
// save the action
$actions[] = new Node('write', array('txt' => $this->textParser->prepareTxt($txt, false)), false);
}
}
return $actions;
} | php | protected function getTextAction(Token $token)
{
// action to use for each line of the content of a <pre> Tag
$tagPreBr = new Node('br', array('style' => array(), 'num' => 0), false);
$actions = array();
// if we are not in a <pre> tag
if (!$this->tagPreIn) {
// save the action
$actions[] = new Node('write', array('txt' => $this->textParser->prepareTxt($token->getData())), false);
} else { // else (if we are in a <pre> tag)
// prepare the text
$data = str_replace("\r", '', $token->getData());
$lines = explode("\n", $data);
// foreach line of the text
foreach ($lines as $k => $txt) {
// transform the line
$txt = str_replace("\t", self::HTML_TAB, $txt);
$txt = str_replace(' ', ' ', $txt);
// add a break line
if ($k > 0) {
$actions[] = clone $tagPreBr;
}
// save the action
$actions[] = new Node('write', array('txt' => $this->textParser->prepareTxt($txt, false)), false);
}
}
return $actions;
} | [
"protected",
"function",
"getTextAction",
"(",
"Token",
"$",
"token",
")",
"{",
"// action to use for each line of the content of a <pre> Tag",
"$",
"tagPreBr",
"=",
"new",
"Node",
"(",
"'br'",
",",
"array",
"(",
"'style'",
"=>",
"array",
"(",
")",
",",
"'num'",
"=>",
"0",
")",
",",
"false",
")",
";",
"$",
"actions",
"=",
"array",
"(",
")",
";",
"// if we are not in a <pre> tag",
"if",
"(",
"!",
"$",
"this",
"->",
"tagPreIn",
")",
"{",
"// save the action",
"$",
"actions",
"[",
"]",
"=",
"new",
"Node",
"(",
"'write'",
",",
"array",
"(",
"'txt'",
"=>",
"$",
"this",
"->",
"textParser",
"->",
"prepareTxt",
"(",
"$",
"token",
"->",
"getData",
"(",
")",
")",
")",
",",
"false",
")",
";",
"}",
"else",
"{",
"// else (if we are in a <pre> tag)",
"// prepare the text",
"$",
"data",
"=",
"str_replace",
"(",
"\"\\r\"",
",",
"''",
",",
"$",
"token",
"->",
"getData",
"(",
")",
")",
";",
"$",
"lines",
"=",
"explode",
"(",
"\"\\n\"",
",",
"$",
"data",
")",
";",
"// foreach line of the text",
"foreach",
"(",
"$",
"lines",
"as",
"$",
"k",
"=>",
"$",
"txt",
")",
"{",
"// transform the line",
"$",
"txt",
"=",
"str_replace",
"(",
"\"\\t\"",
",",
"self",
"::",
"HTML_TAB",
",",
"$",
"txt",
")",
";",
"$",
"txt",
"=",
"str_replace",
"(",
"' '",
",",
"' '",
",",
"$",
"txt",
")",
";",
"// add a break line",
"if",
"(",
"$",
"k",
">",
"0",
")",
"{",
"$",
"actions",
"[",
"]",
"=",
"clone",
"$",
"tagPreBr",
";",
"}",
"// save the action",
"$",
"actions",
"[",
"]",
"=",
"new",
"Node",
"(",
"'write'",
",",
"array",
"(",
"'txt'",
"=>",
"$",
"this",
"->",
"textParser",
"->",
"prepareTxt",
"(",
"$",
"txt",
",",
"false",
")",
")",
",",
"false",
")",
";",
"}",
"}",
"return",
"$",
"actions",
";",
"}"
] | get the Text action
@param Token $token
@return array | [
"get",
"the",
"Text",
"action"
] | 83c9bd942e8520681808b70584e01d17157335ba | https://github.com/spipu/html2pdf/blob/83c9bd942e8520681808b70584e01d17157335ba/src/Parsing/Html.php#L304-L336 | train |
spipu/html2pdf | src/Parsing/Html.php | Html.prepareHtml | public function prepareHtml($html)
{
// if it is a real html page, we have to convert it
if (preg_match('/<body/isU', $html)) {
$html = $this->getHtmlFromRealPage($html);
}
// replace some constants
$html = str_replace('[[date_y]]', date('Y'), $html);
$html = str_replace('[[date_m]]', date('m'), $html);
$html = str_replace('[[date_d]]', date('d'), $html);
$html = str_replace('[[date_h]]', date('H'), $html);
$html = str_replace('[[date_i]]', date('i'), $html);
$html = str_replace('[[date_s]]', date('s'), $html);
return $html;
} | php | public function prepareHtml($html)
{
// if it is a real html page, we have to convert it
if (preg_match('/<body/isU', $html)) {
$html = $this->getHtmlFromRealPage($html);
}
// replace some constants
$html = str_replace('[[date_y]]', date('Y'), $html);
$html = str_replace('[[date_m]]', date('m'), $html);
$html = str_replace('[[date_d]]', date('d'), $html);
$html = str_replace('[[date_h]]', date('H'), $html);
$html = str_replace('[[date_i]]', date('i'), $html);
$html = str_replace('[[date_s]]', date('s'), $html);
return $html;
} | [
"public",
"function",
"prepareHtml",
"(",
"$",
"html",
")",
"{",
"// if it is a real html page, we have to convert it",
"if",
"(",
"preg_match",
"(",
"'/<body/isU'",
",",
"$",
"html",
")",
")",
"{",
"$",
"html",
"=",
"$",
"this",
"->",
"getHtmlFromRealPage",
"(",
"$",
"html",
")",
";",
"}",
"// replace some constants",
"$",
"html",
"=",
"str_replace",
"(",
"'[[date_y]]'",
",",
"date",
"(",
"'Y'",
")",
",",
"$",
"html",
")",
";",
"$",
"html",
"=",
"str_replace",
"(",
"'[[date_m]]'",
",",
"date",
"(",
"'m'",
")",
",",
"$",
"html",
")",
";",
"$",
"html",
"=",
"str_replace",
"(",
"'[[date_d]]'",
",",
"date",
"(",
"'d'",
")",
",",
"$",
"html",
")",
";",
"$",
"html",
"=",
"str_replace",
"(",
"'[[date_h]]'",
",",
"date",
"(",
"'H'",
")",
",",
"$",
"html",
")",
";",
"$",
"html",
"=",
"str_replace",
"(",
"'[[date_i]]'",
",",
"date",
"(",
"'i'",
")",
",",
"$",
"html",
")",
";",
"$",
"html",
"=",
"str_replace",
"(",
"'[[date_s]]'",
",",
"date",
"(",
"'s'",
")",
",",
"$",
"html",
")",
";",
"return",
"$",
"html",
";",
"}"
] | prepare the HTML
@param string $html
@return string | [
"prepare",
"the",
"HTML"
] | 83c9bd942e8520681808b70584e01d17157335ba | https://github.com/spipu/html2pdf/blob/83c9bd942e8520681808b70584e01d17157335ba/src/Parsing/Html.php#L418-L435 | train |
spipu/html2pdf | src/Parsing/Html.php | Html.getHtmlFromRealPage | protected function getHtmlFromRealPage($html)
{
// set body tag to lower case
$html = str_replace('<BODY', '<body', $html);
$html = str_replace('</BODY', '</body', $html);
// explode from the body tag. If no body tag => end
$res = explode('<body', $html);
// the html content is between body tag openning and closing
$content = '<page'.$res[1];
$content = explode('</body', $content);
$content = $content[0].'</page>';
// extract the link tags from the original html
// and add them before the content
preg_match_all('/<link ([^>]*)[\/]?>/isU', $html, $match);
foreach ($match[1] as $src) {
$content = '<link '.$src.'/>'.$content;
}
// extract the css style tags from the original html
// and add them before the content
preg_match_all('/<style[^>]*>(.*)<\/style[^>]*>/isU', $html, $match);
foreach ($match[0] as $src) {
$content = $src.$content;
}
return $content;
} | php | protected function getHtmlFromRealPage($html)
{
// set body tag to lower case
$html = str_replace('<BODY', '<body', $html);
$html = str_replace('</BODY', '</body', $html);
// explode from the body tag. If no body tag => end
$res = explode('<body', $html);
// the html content is between body tag openning and closing
$content = '<page'.$res[1];
$content = explode('</body', $content);
$content = $content[0].'</page>';
// extract the link tags from the original html
// and add them before the content
preg_match_all('/<link ([^>]*)[\/]?>/isU', $html, $match);
foreach ($match[1] as $src) {
$content = '<link '.$src.'/>'.$content;
}
// extract the css style tags from the original html
// and add them before the content
preg_match_all('/<style[^>]*>(.*)<\/style[^>]*>/isU', $html, $match);
foreach ($match[0] as $src) {
$content = $src.$content;
}
return $content;
} | [
"protected",
"function",
"getHtmlFromRealPage",
"(",
"$",
"html",
")",
"{",
"// set body tag to lower case",
"$",
"html",
"=",
"str_replace",
"(",
"'<BODY'",
",",
"'<body'",
",",
"$",
"html",
")",
";",
"$",
"html",
"=",
"str_replace",
"(",
"'</BODY'",
",",
"'</body'",
",",
"$",
"html",
")",
";",
"// explode from the body tag. If no body tag => end",
"$",
"res",
"=",
"explode",
"(",
"'<body'",
",",
"$",
"html",
")",
";",
"// the html content is between body tag openning and closing",
"$",
"content",
"=",
"'<page'",
".",
"$",
"res",
"[",
"1",
"]",
";",
"$",
"content",
"=",
"explode",
"(",
"'</body'",
",",
"$",
"content",
")",
";",
"$",
"content",
"=",
"$",
"content",
"[",
"0",
"]",
".",
"'</page>'",
";",
"// extract the link tags from the original html",
"// and add them before the content",
"preg_match_all",
"(",
"'/<link ([^>]*)[\\/]?>/isU'",
",",
"$",
"html",
",",
"$",
"match",
")",
";",
"foreach",
"(",
"$",
"match",
"[",
"1",
"]",
"as",
"$",
"src",
")",
"{",
"$",
"content",
"=",
"'<link '",
".",
"$",
"src",
".",
"'/>'",
".",
"$",
"content",
";",
"}",
"// extract the css style tags from the original html",
"// and add them before the content",
"preg_match_all",
"(",
"'/<style[^>]*>(.*)<\\/style[^>]*>/isU'",
",",
"$",
"html",
",",
"$",
"match",
")",
";",
"foreach",
"(",
"$",
"match",
"[",
"0",
"]",
"as",
"$",
"src",
")",
"{",
"$",
"content",
"=",
"$",
"src",
".",
"$",
"content",
";",
"}",
"return",
"$",
"content",
";",
"}"
] | convert the HTML of a real page, to a code adapted to Html2Pdf
@param string $html HTML code of a real page
@return string HTML adapted to Html2Pdf | [
"convert",
"the",
"HTML",
"of",
"a",
"real",
"page",
"to",
"a",
"code",
"adapted",
"to",
"Html2Pdf"
] | 83c9bd942e8520681808b70584e01d17157335ba | https://github.com/spipu/html2pdf/blob/83c9bd942e8520681808b70584e01d17157335ba/src/Parsing/Html.php#L443-L472 | train |
artesaos/seotools | src/SEOTools/SEOMeta.php | SEOMeta.generate | public function generate($minify = false)
{
$this->loadWebMasterTags();
$title = $this->getTitle();
$description = $this->getDescription();
$keywords = $this->getKeywords();
$metatags = $this->getMetatags();
$canonical = $this->getCanonical();
$amphtml = $this->getAmpHtml();
$prev = $this->getPrev();
$next = $this->getNext();
$languages = $this->getAlternateLanguages();
$robots = $this->getRobots();
$html = [];
if ($title) {
$html[] = "<title>$title</title>";
}
if ($description) {
$html[] = "<meta name=\"description\" content=\"{$description}\">";
}
if (!empty($keywords)) {
$keywords = implode(', ', $keywords);
$html[] = "<meta name=\"keywords\" content=\"{$keywords}\">";
}
foreach ($metatags as $key => $value) {
$name = $value[0];
$content = $value[1];
// if $content is empty jump to nest
if (empty($content)) {
continue;
}
$html[] = "<meta {$name}=\"{$key}\" content=\"{$content}\">";
}
if ($canonical) {
$html[] = "<link rel=\"canonical\" href=\"{$canonical}\"/>";
}
if ($amphtml) {
$html[] = "<link rel=\"amphtml\" href=\"{$amphtml}\"/>";
}
if ($prev) {
$html[] = "<link rel=\"prev\" href=\"{$prev}\"/>";
}
if ($next) {
$html[] = "<link rel=\"next\" href=\"{$next}\"/>";
}
foreach ($languages as $lang) {
$html[] = "<link rel=\"alternate\" hreflang=\"{$lang['lang']}\" href=\"{$lang['url']}\"/>";
}
if ($robots) {
$html[] = "<meta name=\"robots\" content=\"{$robots}\">";
}
return ($minify) ? implode('', $html) : implode(PHP_EOL, $html);
} | php | public function generate($minify = false)
{
$this->loadWebMasterTags();
$title = $this->getTitle();
$description = $this->getDescription();
$keywords = $this->getKeywords();
$metatags = $this->getMetatags();
$canonical = $this->getCanonical();
$amphtml = $this->getAmpHtml();
$prev = $this->getPrev();
$next = $this->getNext();
$languages = $this->getAlternateLanguages();
$robots = $this->getRobots();
$html = [];
if ($title) {
$html[] = "<title>$title</title>";
}
if ($description) {
$html[] = "<meta name=\"description\" content=\"{$description}\">";
}
if (!empty($keywords)) {
$keywords = implode(', ', $keywords);
$html[] = "<meta name=\"keywords\" content=\"{$keywords}\">";
}
foreach ($metatags as $key => $value) {
$name = $value[0];
$content = $value[1];
// if $content is empty jump to nest
if (empty($content)) {
continue;
}
$html[] = "<meta {$name}=\"{$key}\" content=\"{$content}\">";
}
if ($canonical) {
$html[] = "<link rel=\"canonical\" href=\"{$canonical}\"/>";
}
if ($amphtml) {
$html[] = "<link rel=\"amphtml\" href=\"{$amphtml}\"/>";
}
if ($prev) {
$html[] = "<link rel=\"prev\" href=\"{$prev}\"/>";
}
if ($next) {
$html[] = "<link rel=\"next\" href=\"{$next}\"/>";
}
foreach ($languages as $lang) {
$html[] = "<link rel=\"alternate\" hreflang=\"{$lang['lang']}\" href=\"{$lang['url']}\"/>";
}
if ($robots) {
$html[] = "<meta name=\"robots\" content=\"{$robots}\">";
}
return ($minify) ? implode('', $html) : implode(PHP_EOL, $html);
} | [
"public",
"function",
"generate",
"(",
"$",
"minify",
"=",
"false",
")",
"{",
"$",
"this",
"->",
"loadWebMasterTags",
"(",
")",
";",
"$",
"title",
"=",
"$",
"this",
"->",
"getTitle",
"(",
")",
";",
"$",
"description",
"=",
"$",
"this",
"->",
"getDescription",
"(",
")",
";",
"$",
"keywords",
"=",
"$",
"this",
"->",
"getKeywords",
"(",
")",
";",
"$",
"metatags",
"=",
"$",
"this",
"->",
"getMetatags",
"(",
")",
";",
"$",
"canonical",
"=",
"$",
"this",
"->",
"getCanonical",
"(",
")",
";",
"$",
"amphtml",
"=",
"$",
"this",
"->",
"getAmpHtml",
"(",
")",
";",
"$",
"prev",
"=",
"$",
"this",
"->",
"getPrev",
"(",
")",
";",
"$",
"next",
"=",
"$",
"this",
"->",
"getNext",
"(",
")",
";",
"$",
"languages",
"=",
"$",
"this",
"->",
"getAlternateLanguages",
"(",
")",
";",
"$",
"robots",
"=",
"$",
"this",
"->",
"getRobots",
"(",
")",
";",
"$",
"html",
"=",
"[",
"]",
";",
"if",
"(",
"$",
"title",
")",
"{",
"$",
"html",
"[",
"]",
"=",
"\"<title>$title</title>\"",
";",
"}",
"if",
"(",
"$",
"description",
")",
"{",
"$",
"html",
"[",
"]",
"=",
"\"<meta name=\\\"description\\\" content=\\\"{$description}\\\">\"",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"keywords",
")",
")",
"{",
"$",
"keywords",
"=",
"implode",
"(",
"', '",
",",
"$",
"keywords",
")",
";",
"$",
"html",
"[",
"]",
"=",
"\"<meta name=\\\"keywords\\\" content=\\\"{$keywords}\\\">\"",
";",
"}",
"foreach",
"(",
"$",
"metatags",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"$",
"name",
"=",
"$",
"value",
"[",
"0",
"]",
";",
"$",
"content",
"=",
"$",
"value",
"[",
"1",
"]",
";",
"// if $content is empty jump to nest",
"if",
"(",
"empty",
"(",
"$",
"content",
")",
")",
"{",
"continue",
";",
"}",
"$",
"html",
"[",
"]",
"=",
"\"<meta {$name}=\\\"{$key}\\\" content=\\\"{$content}\\\">\"",
";",
"}",
"if",
"(",
"$",
"canonical",
")",
"{",
"$",
"html",
"[",
"]",
"=",
"\"<link rel=\\\"canonical\\\" href=\\\"{$canonical}\\\"/>\"",
";",
"}",
"if",
"(",
"$",
"amphtml",
")",
"{",
"$",
"html",
"[",
"]",
"=",
"\"<link rel=\\\"amphtml\\\" href=\\\"{$amphtml}\\\"/>\"",
";",
"}",
"if",
"(",
"$",
"prev",
")",
"{",
"$",
"html",
"[",
"]",
"=",
"\"<link rel=\\\"prev\\\" href=\\\"{$prev}\\\"/>\"",
";",
"}",
"if",
"(",
"$",
"next",
")",
"{",
"$",
"html",
"[",
"]",
"=",
"\"<link rel=\\\"next\\\" href=\\\"{$next}\\\"/>\"",
";",
"}",
"foreach",
"(",
"$",
"languages",
"as",
"$",
"lang",
")",
"{",
"$",
"html",
"[",
"]",
"=",
"\"<link rel=\\\"alternate\\\" hreflang=\\\"{$lang['lang']}\\\" href=\\\"{$lang['url']}\\\"/>\"",
";",
"}",
"if",
"(",
"$",
"robots",
")",
"{",
"$",
"html",
"[",
"]",
"=",
"\"<meta name=\\\"robots\\\" content=\\\"{$robots}\\\">\"",
";",
"}",
"return",
"(",
"$",
"minify",
")",
"?",
"implode",
"(",
"''",
",",
"$",
"html",
")",
":",
"implode",
"(",
"PHP_EOL",
",",
"$",
"html",
")",
";",
"}"
] | Generates meta tags.
@param bool $minify
@return string | [
"Generates",
"meta",
"tags",
"."
] | 041576cfbe6c1f7aba9164bbe9d3a261fdcaf8d9 | https://github.com/artesaos/seotools/blob/041576cfbe6c1f7aba9164bbe9d3a261fdcaf8d9/src/SEOTools/SEOMeta.php#L134-L201 | train |
artesaos/seotools | src/SEOTools/SEOMeta.php | SEOMeta.getDefaultTitle | public function getDefaultTitle()
{
if (empty($this->title_default)) {
return $this->config->get('defaults.title', null);
}
return $this->title_default;
} | php | public function getDefaultTitle()
{
if (empty($this->title_default)) {
return $this->config->get('defaults.title', null);
}
return $this->title_default;
} | [
"public",
"function",
"getDefaultTitle",
"(",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"title_default",
")",
")",
"{",
"return",
"$",
"this",
"->",
"config",
"->",
"get",
"(",
"'defaults.title'",
",",
"null",
")",
";",
"}",
"return",
"$",
"this",
"->",
"title_default",
";",
"}"
] | Takes the default title.
@return string | [
"Takes",
"the",
"default",
"title",
"."
] | 041576cfbe6c1f7aba9164bbe9d3a261fdcaf8d9 | https://github.com/artesaos/seotools/blob/041576cfbe6c1f7aba9164bbe9d3a261fdcaf8d9/src/SEOTools/SEOMeta.php#L463-L470 | train |
artesaos/seotools | src/SEOTools/SEOMeta.php | SEOMeta.getDescription | public function getDescription()
{
if (false === $this->description) {
return;
}
return $this->description ?: $this->config->get('defaults.description', null);
} | php | public function getDescription()
{
if (false === $this->description) {
return;
}
return $this->description ?: $this->config->get('defaults.description', null);
} | [
"public",
"function",
"getDescription",
"(",
")",
"{",
"if",
"(",
"false",
"===",
"$",
"this",
"->",
"description",
")",
"{",
"return",
";",
"}",
"return",
"$",
"this",
"->",
"description",
"?",
":",
"$",
"this",
"->",
"config",
"->",
"get",
"(",
"'defaults.description'",
",",
"null",
")",
";",
"}"
] | Get the Meta description.
@return string|null | [
"Get",
"the",
"Meta",
"description",
"."
] | 041576cfbe6c1f7aba9164bbe9d3a261fdcaf8d9 | https://github.com/artesaos/seotools/blob/041576cfbe6c1f7aba9164bbe9d3a261fdcaf8d9/src/SEOTools/SEOMeta.php#L517-L524 | train |
artesaos/seotools | src/SEOTools/SEOMeta.php | SEOMeta.getCanonical | public function getCanonical()
{
$canonical_config = $this->config->get('defaults.canonical', false);
return $this->canonical ?: (($canonical_config === null) ? app('url')->full() : $canonical_config);
} | php | public function getCanonical()
{
$canonical_config = $this->config->get('defaults.canonical', false);
return $this->canonical ?: (($canonical_config === null) ? app('url')->full() : $canonical_config);
} | [
"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.
@return string | [
"Get",
"the",
"canonical",
"URL",
"."
] | 041576cfbe6c1f7aba9164bbe9d3a261fdcaf8d9 | https://github.com/artesaos/seotools/blob/041576cfbe6c1f7aba9164bbe9d3a261fdcaf8d9/src/SEOTools/SEOMeta.php#L531-L536 | train |
artesaos/seotools | src/SEOTools/SEOMeta.php | SEOMeta.loadWebMasterTags | 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);
}
}
} | php | 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);
}
}
} | [
"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. | [
"Load",
"webmaster",
"tags",
"from",
"configuration",
"."
] | 041576cfbe6c1f7aba9164bbe9d3a261fdcaf8d9 | https://github.com/artesaos/seotools/blob/041576cfbe6c1f7aba9164bbe9d3a261fdcaf8d9/src/SEOTools/SEOMeta.php#L624-L632 | train |
artesaos/seotools | src/SEOTools/SEOTools.php | SEOTools.setTitle | 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;
} | php | 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;
} | [
"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.
@param string $title
@param bool $appendDefault
@return \Artesaos\SEOTools\Contracts\SEOTools | [
"Setup",
"title",
"for",
"all",
"seo",
"providers",
"."
] | 041576cfbe6c1f7aba9164bbe9d3a261fdcaf8d9 | https://github.com/artesaos/seotools/blob/041576cfbe6c1f7aba9164bbe9d3a261fdcaf8d9/src/SEOTools/SEOTools.php#L50-L58 | train |
artesaos/seotools | src/SEOTools/SEOTools.php | SEOTools.setDescription | public function setDescription($description)
{
$this->metatags()->setDescription($description);
$this->opengraph()->setDescription($description);
$this->twitter()->setDescription($description);
$this->jsonLd()->setDescription($description);
return $this;
} | php | public function setDescription($description)
{
$this->metatags()->setDescription($description);
$this->opengraph()->setDescription($description);
$this->twitter()->setDescription($description);
$this->jsonLd()->setDescription($description);
return $this;
} | [
"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.
@param $description
@return \Artesaos\SEOTools\Contracts\SEOTools | [
"Setup",
"description",
"for",
"all",
"seo",
"providers",
"."
] | 041576cfbe6c1f7aba9164bbe9d3a261fdcaf8d9 | https://github.com/artesaos/seotools/blob/041576cfbe6c1f7aba9164bbe9d3a261fdcaf8d9/src/SEOTools/SEOTools.php#L67-L75 | train |
artesaos/seotools | src/SEOTools/SEOTools.php | SEOTools.getTitle | public function getTitle($session = false)
{
if ($session) {
return $this->metatags()->getTitleSession();
}
return $this->metatags()->getTitle();
} | php | public function getTitle($session = false)
{
if ($session) {
return $this->metatags()->getTitleSession();
}
return $this->metatags()->getTitle();
} | [
"public",
"function",
"getTitle",
"(",
"$",
"session",
"=",
"false",
")",
"{",
"if",
"(",
"$",
"session",
")",
"{",
"return",
"$",
"this",
"->",
"metatags",
"(",
")",
"->",
"getTitleSession",
"(",
")",
";",
"}",
"return",
"$",
"this",
"->",
"metatags",
"(",
")",
"->",
"getTitle",
"(",
")",
";",
"}"
] | Get current title from metatags.
@param bool $session
@return string | [
"Get",
"current",
"title",
"from",
"metatags",
"."
] | 041576cfbe6c1f7aba9164bbe9d3a261fdcaf8d9 | https://github.com/artesaos/seotools/blob/041576cfbe6c1f7aba9164bbe9d3a261fdcaf8d9/src/SEOTools/SEOTools.php#L118-L125 | train |
artesaos/seotools | src/SEOTools/SEOTools.php | SEOTools.generate | 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 ($minify) ? str_replace(PHP_EOL, '', $html) : $html;
} | php | 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 ($minify) ? str_replace(PHP_EOL, '', $html) : $html;
} | [
"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",
"(",
"$",
"minify",
")",
"?",
"str_replace",
"(",
"PHP_EOL",
",",
"''",
",",
"$",
"html",
")",
":",
"$",
"html",
";",
"}"
] | Generate from all seo providers.
@param bool $minify
@return string | [
"Generate",
"from",
"all",
"seo",
"providers",
"."
] | 041576cfbe6c1f7aba9164bbe9d3a261fdcaf8d9 | https://github.com/artesaos/seotools/blob/041576cfbe6c1f7aba9164bbe9d3a261fdcaf8d9/src/SEOTools/SEOTools.php#L134-L145 | train |
artesaos/seotools | src/SEOTools/OpenGraph.php | OpenGraph.generate | 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],
'musicSongProperties' => ['music', false],
'musicAlbumProperties' => ['music', false],
'musicPlaylistProperties' => ['music', false],
'musicRadioStationProperties' => ['music', false],
'videoMovieProperties' => ['video', false],
'videoEpisodeProperties' => ['video', false],
'videoTVShowProperties' => ['video', false],
'videoOtherProperties' => ['video', false],
'videoProperties' => ['video', true],
'audioProperties' => ['audio', true],
'placeProperties' => ['place', false],
'productProperties' => ['product', false],
];
foreach ($props as $prop => $options) {
$output .= $this->eachProperties(
$this->{$prop},
$options[0],
$options[1]
);
}
return ($minify) ? str_replace(PHP_EOL, '', $output) : $output;
} | php | 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],
'musicSongProperties' => ['music', false],
'musicAlbumProperties' => ['music', false],
'musicPlaylistProperties' => ['music', false],
'musicRadioStationProperties' => ['music', false],
'videoMovieProperties' => ['video', false],
'videoEpisodeProperties' => ['video', false],
'videoTVShowProperties' => ['video', false],
'videoOtherProperties' => ['video', false],
'videoProperties' => ['video', true],
'audioProperties' => ['audio', true],
'placeProperties' => ['place', false],
'productProperties' => ['product', false],
];
foreach ($props as $prop => $options) {
$output .= $this->eachProperties(
$this->{$prop},
$options[0],
$options[1]
);
}
return ($minify) ? str_replace(PHP_EOL, '', $output) : $output;
} | [
"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",
"]",
",",
"'musicSongProperties'",
"=>",
"[",
"'music'",
",",
"false",
"]",
",",
"'musicAlbumProperties'",
"=>",
"[",
"'music'",
",",
"false",
"]",
",",
"'musicPlaylistProperties'",
"=>",
"[",
"'music'",
",",
"false",
"]",
",",
"'musicRadioStationProperties'",
"=>",
"[",
"'music'",
",",
"false",
"]",
",",
"'videoMovieProperties'",
"=>",
"[",
"'video'",
",",
"false",
"]",
",",
"'videoEpisodeProperties'",
"=>",
"[",
"'video'",
",",
"false",
"]",
",",
"'videoTVShowProperties'",
"=>",
"[",
"'video'",
",",
"false",
"]",
",",
"'videoOtherProperties'",
"=>",
"[",
"'video'",
",",
"false",
"]",
",",
"'videoProperties'",
"=>",
"[",
"'video'",
",",
"true",
"]",
",",
"'audioProperties'",
"=>",
"[",
"'audio'",
",",
"true",
"]",
",",
"'placeProperties'",
"=>",
"[",
"'place'",
",",
"false",
"]",
",",
"'productProperties'",
"=>",
"[",
"'product'",
",",
"false",
"]",
",",
"]",
";",
"foreach",
"(",
"$",
"props",
"as",
"$",
"prop",
"=>",
"$",
"options",
")",
"{",
"$",
"output",
".=",
"$",
"this",
"->",
"eachProperties",
"(",
"$",
"this",
"->",
"{",
"$",
"prop",
"}",
",",
"$",
"options",
"[",
"0",
"]",
",",
"$",
"options",
"[",
"1",
"]",
")",
";",
"}",
"return",
"(",
"$",
"minify",
")",
"?",
"str_replace",
"(",
"PHP_EOL",
",",
"''",
",",
"$",
"output",
")",
":",
"$",
"output",
";",
"}"
] | Generates open graph tags.
@param bool $minify
@return string | [
"Generates",
"open",
"graph",
"tags",
"."
] | 041576cfbe6c1f7aba9164bbe9d3a261fdcaf8d9 | https://github.com/artesaos/seotools/blob/041576cfbe6c1f7aba9164bbe9d3a261fdcaf8d9/src/SEOTools/OpenGraph.php#L161-L195 | train |
artesaos/seotools | src/SEOTools/OpenGraph.php | OpenGraph.eachProperties | protected function eachProperties(
array $properties,
$prefix = null,
$ogPrefix = true
) {
$html = [];
foreach ($properties as $property => $value) {
// multiple properties
if (is_array($value)) {
$subListPrefix = (is_string($property)) ? $property : $prefix;
$subList = $this->eachProperties($value, $subListPrefix);
$html[] = $subList;
} else {
if (is_string($prefix)) {
$key = (is_string($property)) ?
$prefix.':'.$property :
$prefix;
} else {
$key = $property;
}
// if empty jump to next
if (empty($value)) {
continue;
}
$html[] = $this->makeTag($key, $value, $ogPrefix);
}
}
return implode($html);
} | php | protected function eachProperties(
array $properties,
$prefix = null,
$ogPrefix = true
) {
$html = [];
foreach ($properties as $property => $value) {
// multiple properties
if (is_array($value)) {
$subListPrefix = (is_string($property)) ? $property : $prefix;
$subList = $this->eachProperties($value, $subListPrefix);
$html[] = $subList;
} else {
if (is_string($prefix)) {
$key = (is_string($property)) ?
$prefix.':'.$property :
$prefix;
} else {
$key = $property;
}
// if empty jump to next
if (empty($value)) {
continue;
}
$html[] = $this->makeTag($key, $value, $ogPrefix);
}
}
return implode($html);
} | [
"protected",
"function",
"eachProperties",
"(",
"array",
"$",
"properties",
",",
"$",
"prefix",
"=",
"null",
",",
"$",
"ogPrefix",
"=",
"true",
")",
"{",
"$",
"html",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"properties",
"as",
"$",
"property",
"=>",
"$",
"value",
")",
"{",
"// multiple properties",
"if",
"(",
"is_array",
"(",
"$",
"value",
")",
")",
"{",
"$",
"subListPrefix",
"=",
"(",
"is_string",
"(",
"$",
"property",
")",
")",
"?",
"$",
"property",
":",
"$",
"prefix",
";",
"$",
"subList",
"=",
"$",
"this",
"->",
"eachProperties",
"(",
"$",
"value",
",",
"$",
"subListPrefix",
")",
";",
"$",
"html",
"[",
"]",
"=",
"$",
"subList",
";",
"}",
"else",
"{",
"if",
"(",
"is_string",
"(",
"$",
"prefix",
")",
")",
"{",
"$",
"key",
"=",
"(",
"is_string",
"(",
"$",
"property",
")",
")",
"?",
"$",
"prefix",
".",
"':'",
".",
"$",
"property",
":",
"$",
"prefix",
";",
"}",
"else",
"{",
"$",
"key",
"=",
"$",
"property",
";",
"}",
"// if empty jump to next",
"if",
"(",
"empty",
"(",
"$",
"value",
")",
")",
"{",
"continue",
";",
"}",
"$",
"html",
"[",
"]",
"=",
"$",
"this",
"->",
"makeTag",
"(",
"$",
"key",
",",
"$",
"value",
",",
"$",
"ogPrefix",
")",
";",
"}",
"}",
"return",
"implode",
"(",
"$",
"html",
")",
";",
"}"
] | Make list of open graph tags.
@param array $properties array of properties
@param null|string $prefix prefix of property
@param bool $ogPrefix opengraph prefix
@return string | [
"Make",
"list",
"of",
"open",
"graph",
"tags",
"."
] | 041576cfbe6c1f7aba9164bbe9d3a261fdcaf8d9 | https://github.com/artesaos/seotools/blob/041576cfbe6c1f7aba9164bbe9d3a261fdcaf8d9/src/SEOTools/OpenGraph.php#L206-L239 | train |
artesaos/seotools | src/SEOTools/OpenGraph.php | OpenGraph.makeTag | 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
);
} | php | 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
);
} | [
"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.
@param string $key meta property key
@param string $value meta property value
@param bool $ogPrefix opengraph prefix
@return string | [
"Make",
"a",
"og",
"tag",
"."
] | 041576cfbe6c1f7aba9164bbe9d3a261fdcaf8d9 | https://github.com/artesaos/seotools/blob/041576cfbe6c1f7aba9164bbe9d3a261fdcaf8d9/src/SEOTools/OpenGraph.php#L250-L259 | train |
artesaos/seotools | src/SEOTools/OpenGraph.php | OpenGraph.setupDefaults | 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 === null) {
$this->setUrl(app('url')->current());
} elseif (! empty($value) && ! array_key_exists($key, $this->properties)) {
$this->addProperty($key, $value);
}
}
} | php | 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 === null) {
$this->setUrl(app('url')->current());
} elseif (! empty($value) && ! array_key_exists($key, $this->properties)) {
$this->addProperty($key, $value);
}
}
} | [
"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",
"===",
"null",
")",
"{",
"$",
"this",
"->",
"setUrl",
"(",
"app",
"(",
"'url'",
")",
"->",
"current",
"(",
")",
")",
";",
"}",
"elseif",
"(",
"!",
"empty",
"(",
"$",
"value",
")",
"&&",
"!",
"array_key_exists",
"(",
"$",
"key",
",",
"$",
"this",
"->",
"properties",
")",
")",
"{",
"$",
"this",
"->",
"addProperty",
"(",
"$",
"key",
",",
"$",
"value",
")",
";",
"}",
"}",
"}"
] | Add or update property.
@return void | [
"Add",
"or",
"update",
"property",
"."
] | 041576cfbe6c1f7aba9164bbe9d3a261fdcaf8d9 | https://github.com/artesaos/seotools/blob/041576cfbe6c1f7aba9164bbe9d3a261fdcaf8d9/src/SEOTools/OpenGraph.php#L266-L283 | train |
artesaos/seotools | src/SEOTools/OpenGraph.php | OpenGraph.addVideo | public function addVideo($source = null, $attributes = [])
{
$validKeys = [
'url',
'secure_url',
'type',
'width',
'height',
];
$this->videoProperties[] = [
$source,
$this->cleanProperties($attributes, $validKeys),
];
return $this;
} | php | public function addVideo($source = null, $attributes = [])
{
$validKeys = [
'url',
'secure_url',
'type',
'width',
'height',
];
$this->videoProperties[] = [
$source,
$this->cleanProperties($attributes, $validKeys),
];
return $this;
} | [
"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.
@param string $source url of video source
@param array $attributes opengraph video attributes
@return OpenGraphContract | [
"Add",
"video",
"properties",
"."
] | 041576cfbe6c1f7aba9164bbe9d3a261fdcaf8d9 | https://github.com/artesaos/seotools/blob/041576cfbe6c1f7aba9164bbe9d3a261fdcaf8d9/src/SEOTools/OpenGraph.php#L603-L619 | train |
artesaos/seotools | src/SEOTools/OpenGraph.php | OpenGraph.addAudio | public function addAudio($source = null, $attributes = [])
{
$validKeys = [
'url',
'secure_url',
'type',
];
$this->audioProperties[] = [
$source,
$this->cleanProperties($attributes, $validKeys),
];
return $this;
} | php | public function addAudio($source = null, $attributes = [])
{
$validKeys = [
'url',
'secure_url',
'type',
];
$this->audioProperties[] = [
$source,
$this->cleanProperties($attributes, $validKeys),
];
return $this;
} | [
"public",
"function",
"addAudio",
"(",
"$",
"source",
"=",
"null",
",",
"$",
"attributes",
"=",
"[",
"]",
")",
"{",
"$",
"validKeys",
"=",
"[",
"'url'",
",",
"'secure_url'",
",",
"'type'",
",",
"]",
";",
"$",
"this",
"->",
"audioProperties",
"[",
"]",
"=",
"[",
"$",
"source",
",",
"$",
"this",
"->",
"cleanProperties",
"(",
"$",
"attributes",
",",
"$",
"validKeys",
")",
",",
"]",
";",
"return",
"$",
"this",
";",
"}"
] | Add audio properties.
@param string $source url for audio source
@param array $attributes opengraph audio attributes
@return OpenGraphContract | [
"Add",
"audio",
"properties",
"."
] | 041576cfbe6c1f7aba9164bbe9d3a261fdcaf8d9 | https://github.com/artesaos/seotools/blob/041576cfbe6c1f7aba9164bbe9d3a261fdcaf8d9/src/SEOTools/OpenGraph.php#L629-L643 | train |
artesaos/seotools | src/SEOTools/OpenGraph.php | OpenGraph.cleanProperties | protected function cleanProperties($attributes = [], $validKeys = [])
{
$array = [];
foreach ($attributes as $attribute => $value) {
if (in_array($attribute, $validKeys)) {
$array[$attribute] = $value;
}
}
return $array;
} | php | protected function cleanProperties($attributes = [], $validKeys = [])
{
$array = [];
foreach ($attributes as $attribute => $value) {
if (in_array($attribute, $validKeys)) {
$array[$attribute] = $value;
}
}
return $array;
} | [
"protected",
"function",
"cleanProperties",
"(",
"$",
"attributes",
"=",
"[",
"]",
",",
"$",
"validKeys",
"=",
"[",
"]",
")",
"{",
"$",
"array",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"attributes",
"as",
"$",
"attribute",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"in_array",
"(",
"$",
"attribute",
",",
"$",
"validKeys",
")",
")",
"{",
"$",
"array",
"[",
"$",
"attribute",
"]",
"=",
"$",
"value",
";",
"}",
"}",
"return",
"$",
"array",
";",
"}"
] | Clean invalid properties.
@param array $attributes attributes input
@param string[] $validKeys keys that are allowed
@return array | [
"Clean",
"invalid",
"properties",
"."
] | 041576cfbe6c1f7aba9164bbe9d3a261fdcaf8d9 | https://github.com/artesaos/seotools/blob/041576cfbe6c1f7aba9164bbe9d3a261fdcaf8d9/src/SEOTools/OpenGraph.php#L705-L716 | train |
artesaos/seotools | src/SEOTools/OpenGraph.php | OpenGraph.addImage | 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($attributes, $validKeys),
];
}
return $this;
} | php | 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($attributes, $validKeys),
];
}
return $this;
} | [
"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",
"(",
"$",
"attributes",
",",
"$",
"validKeys",
")",
",",
"]",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Add image to properties.
@param mixed $source URL of image source
@param array $attributes Object type attributes
@return OpenGraphContract | [
"Add",
"image",
"to",
"properties",
"."
] | 041576cfbe6c1f7aba9164bbe9d3a261fdcaf8d9 | https://github.com/artesaos/seotools/blob/041576cfbe6c1f7aba9164bbe9d3a261fdcaf8d9/src/SEOTools/OpenGraph.php#L765-L785 | train |
artesaos/seotools | src/SEOTools/TwitterCards.php | TwitterCards.eachValue | 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;
endif;
$this->html[] = $this->makeTag($key, $value);
endif;
endforeach;
} | php | 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;
endif;
$this->html[] = $this->makeTag($key, $value);
endif;
endforeach;
} | [
"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",
";",
"endif",
";",
"$",
"this",
"->",
"html",
"[",
"]",
"=",
"$",
"this",
"->",
"makeTag",
"(",
"$",
"key",
",",
"$",
"value",
")",
";",
"endif",
";",
"endforeach",
";",
"}"
] | Make tags.
@param array $values
@param null|string $prefix
@internal param array $properties | [
"Make",
"tags",
"."
] | 041576cfbe6c1f7aba9164bbe9d3a261fdcaf8d9 | https://github.com/artesaos/seotools/blob/041576cfbe6c1f7aba9164bbe9d3a261fdcaf8d9/src/SEOTools/TwitterCards.php#L58-L71 | train |
timber/timber | lib/Loader.php | Loader.choose_template | public function choose_template( $templates ) {
// Change $templates into array, if needed
if ( !is_array($templates) ) {
$templates = (array) $templates;
}
// Get Twig loader
$loader = $this->get_loader();
// Run through template array
foreach ( $templates as $template ) {
// Remove any whitespace around the template name
$template = trim( $template );
// Use the Twig loader to test for existance
if ( $loader->exists($template) ) {
// Return name of existing template
return $template;
}
}
// No existing template was found
return false;
} | php | public function choose_template( $templates ) {
// Change $templates into array, if needed
if ( !is_array($templates) ) {
$templates = (array) $templates;
}
// Get Twig loader
$loader = $this->get_loader();
// Run through template array
foreach ( $templates as $template ) {
// Remove any whitespace around the template name
$template = trim( $template );
// Use the Twig loader to test for existance
if ( $loader->exists($template) ) {
// Return name of existing template
return $template;
}
}
// No existing template was found
return false;
} | [
"public",
"function",
"choose_template",
"(",
"$",
"templates",
")",
"{",
"// Change $templates into array, if needed",
"if",
"(",
"!",
"is_array",
"(",
"$",
"templates",
")",
")",
"{",
"$",
"templates",
"=",
"(",
"array",
")",
"$",
"templates",
";",
"}",
"// Get Twig loader",
"$",
"loader",
"=",
"$",
"this",
"->",
"get_loader",
"(",
")",
";",
"// Run through template array",
"foreach",
"(",
"$",
"templates",
"as",
"$",
"template",
")",
"{",
"// Remove any whitespace around the template name",
"$",
"template",
"=",
"trim",
"(",
"$",
"template",
")",
";",
"// Use the Twig loader to test for existance",
"if",
"(",
"$",
"loader",
"->",
"exists",
"(",
"$",
"template",
")",
")",
"{",
"// Return name of existing template",
"return",
"$",
"template",
";",
"}",
"}",
"// No existing template was found",
"return",
"false",
";",
"}"
] | Get first existing template.
@param array|string $templates Name(s) of the Twig template(s) to choose from.
@return string|bool Name of chosen template, otherwise false. | [
"Get",
"first",
"existing",
"template",
"."
] | baaa1960193cffb5fa7c43c09114d6831764eede | https://github.com/timber/timber/blob/baaa1960193cffb5fa7c43c09114d6831764eede/lib/Loader.php#L95-L118 | train |
timber/timber | lib/Core.php | Core.import | 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 = $value;
} else if ( !empty($key) && !method_exists($this, $key) ) {
$this->$key = $value;
}
}
}
} | php | 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 = $value;
} else if ( !empty($key) && !method_exists($this, $key) ) {
$this->$key = $value;
}
}
}
} | [
"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",
"=",
"$",
"value",
";",
"}",
"else",
"if",
"(",
"!",
"empty",
"(",
"$",
"key",
")",
"&&",
"!",
"method_exists",
"(",
"$",
"this",
",",
"$",
"key",
")",
")",
"{",
"$",
"this",
"->",
"$",
"key",
"=",
"$",
"value",
";",
"}",
"}",
"}",
"}"
] | Takes an array or object and adds the properties to the parent object
@example
```php
$data = array('airplane' => '757-200', 'flight' => '5316');
$post = new Timber\Post()
$post->import(data);
echo $post->airplane; //757-200
```
@param array|object $info an object or array you want to grab data from to attach to the Timber object | [
"Takes",
"an",
"array",
"or",
"object",
"and",
"adds",
"the",
"properties",
"to",
"the",
"parent",
"object"
] | baaa1960193cffb5fa7c43c09114d6831764eede | https://github.com/timber/timber/blob/baaa1960193cffb5fa7c43c09114d6831764eede/lib/Core.php#L59-L75 | train |
timber/timber | lib/URLHelper.php | URLHelper.is_external | 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;
} | php | 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;
} | [
"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.
@param string $url Url.
@return bool true if $path is an external url, false if relative or local.
true if it's a subdomain (http://cdn.example.org = true) | [
"Checks",
"if",
"URL",
"is",
"external",
"or",
"internal",
".",
"Works",
"with",
"domains",
"subdomains",
"and",
"protocol",
"relative",
"domains",
"."
] | baaa1960193cffb5fa7c43c09114d6831764eede | https://github.com/timber/timber/blob/baaa1960193cffb5fa7c43c09114d6831764eede/lib/URLHelper.php#L325-L332 | train |
timber/timber | lib/URLHelper.php | URLHelper.remove_url_component | public static function remove_url_component( $haystack, $needle ) {
$haystack = str_replace($needle, '', $haystack);
$needle = self::swap_protocol($needle);
return str_replace($needle, '', $haystack);
} | php | public static function remove_url_component( $haystack, $needle ) {
$haystack = str_replace($needle, '', $haystack);
$needle = self::swap_protocol($needle);
return str_replace($needle, '', $haystack);
} | [
"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
@since 1.3.3
@author jarednova
@param string $haystack ex: http://example.org/wp-content/uploads/dog.jpg
@param string $needle ex: http://example.org/wp-content
@return string | [
"Removes",
"the",
"subcomponent",
"of",
"a",
"URL",
"regardless",
"of",
"protocol"
] | baaa1960193cffb5fa7c43c09114d6831764eede | https://github.com/timber/timber/blob/baaa1960193cffb5fa7c43c09114d6831764eede/lib/URLHelper.php#L355-L359 | train |
timber/timber | lib/URLHelper.php | URLHelper.swap_protocol | 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;
} | php | 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;
} | [
"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
@since 1.3.3
@author jarednova
@param string $url ex: http://example.org/wp-content/uploads/dog.jpg
@return string ex: https://example.org/wp-content/uploads/dog.jpg | [
"Swaps",
"whatever",
"protocol",
"of",
"a",
"URL",
"is",
"sent",
".",
"http",
"becomes",
"https",
"and",
"vice",
"versa"
] | baaa1960193cffb5fa7c43c09114d6831764eede | https://github.com/timber/timber/blob/baaa1960193cffb5fa7c43c09114d6831764eede/lib/URLHelper.php#L369-L377 | train |
timber/timber | lib/URLHelper.php | URLHelper.user_trailingslashit | 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'] ) {
$link = str_replace($link_parts['path'], $new_path, $link);
}
}
return $link;
} | php | 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'] ) {
$link = str_replace($link_parts['path'], $new_path, $link);
}
}
return $link;
} | [
"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'",
"]",
")",
"{",
"$",
"link",
"=",
"str_replace",
"(",
"$",
"link_parts",
"[",
"'path'",
"]",
",",
"$",
"new_path",
",",
"$",
"link",
")",
";",
"}",
"}",
"return",
"$",
"link",
";",
"}"
] | Pass links through user_trailingslashit handling query strings properly
@param string $link
@return string | [
"Pass",
"links",
"through",
"user_trailingslashit",
"handling",
"query",
"strings",
"properly"
] | baaa1960193cffb5fa7c43c09114d6831764eede | https://github.com/timber/timber/blob/baaa1960193cffb5fa7c43c09114d6831764eede/lib/URLHelper.php#L385-L400 | train |
timber/timber | lib/Twig.php | Twig.process_term_args | protected static function process_term_args( $maybe_taxonomy, $TermClass ) {
// A user could be sending a TermClass in the first arg, let's test for that ...
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_taxonomy, 'TermClass' => $TermClass);
} | php | protected static function process_term_args( $maybe_taxonomy, $TermClass ) {
// A user could be sending a TermClass in the first arg, let's test for that ...
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_taxonomy, 'TermClass' => $TermClass);
} | [
"protected",
"static",
"function",
"process_term_args",
"(",
"$",
"maybe_taxonomy",
",",
"$",
"TermClass",
")",
"{",
"// A user could be sending a TermClass in the first arg, let's test for that ...",
"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_taxonomy",
",",
"'TermClass'",
"=>",
"$",
"TermClass",
")",
";",
"}"
] | Process the arguments for handle_term_object to determine what arguments the user is sending
@since 1.5.1
@author @jarednova
@param string $maybe_taxonomy probably a taxonomy, but it could be a Timber\Term subclass
@param string $TermClass a string for the Timber\Term subclass
@return array of processed arguments | [
"Process",
"the",
"arguments",
"for",
"handle_term_object",
"to",
"determine",
"what",
"arguments",
"the",
"user",
"is",
"sending"
] | baaa1960193cffb5fa7c43c09114d6831764eede | https://github.com/timber/timber/blob/baaa1960193cffb5fa7c43c09114d6831764eede/lib/Twig.php#L165-L174 | train |
timber/timber | lib/Twig.php | Twig.add_timber_escapers | 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_Environment $env, $string ) {
return wp_kses_post($string);
});
$twig->getExtension('Twig_Extension_Core')->setEscaper('esc_html', function( \Twig_Environment $env, $string ) {
return esc_html($string);
});
$twig->getExtension('Twig_Extension_Core')->setEscaper('esc_js', function( \Twig_Environment $env, $string ) {
return esc_js($string);
});
return $twig;
} | php | 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_Environment $env, $string ) {
return wp_kses_post($string);
});
$twig->getExtension('Twig_Extension_Core')->setEscaper('esc_html', function( \Twig_Environment $env, $string ) {
return esc_html($string);
});
$twig->getExtension('Twig_Extension_Core')->setEscaper('esc_js', function( \Twig_Environment $env, $string ) {
return esc_js($string);
});
return $twig;
} | [
"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_Environment",
"$",
"env",
",",
"$",
"string",
")",
"{",
"return",
"wp_kses_post",
"(",
"$",
"string",
")",
";",
"}",
")",
";",
"$",
"twig",
"->",
"getExtension",
"(",
"'Twig_Extension_Core'",
")",
"->",
"setEscaper",
"(",
"'esc_html'",
",",
"function",
"(",
"\\",
"Twig_Environment",
"$",
"env",
",",
"$",
"string",
")",
"{",
"return",
"esc_html",
"(",
"$",
"string",
")",
";",
"}",
")",
";",
"$",
"twig",
"->",
"getExtension",
"(",
"'Twig_Extension_Core'",
")",
"->",
"setEscaper",
"(",
"'esc_js'",
",",
"function",
"(",
"\\",
"Twig_Environment",
"$",
"env",
",",
"$",
"string",
")",
"{",
"return",
"esc_js",
"(",
"$",
"string",
")",
";",
"}",
")",
";",
"return",
"$",
"twig",
";",
"}"
] | Adds escapers to Twig.
@param \Twig\Environment $twig The Twig Environment.
@return \Twig\Environment | [
"Adds",
"escapers",
"to",
"Twig",
"."
] | baaa1960193cffb5fa7c43c09114d6831764eede | https://github.com/timber/timber/blob/baaa1960193cffb5fa7c43c09114d6831764eede/lib/Twig.php#L246-L265 | train |
timber/timber | lib/FunctionWrapper.php | FunctionWrapper.add_to_twig | 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() );
} ) );
// Use empty 'catch' block and not 'finally', because finally needs PHP 5.5 to work.
} catch ( \Exception $e ) {}
return $twig;
} | php | 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() );
} ) );
// Use empty 'catch' block and not 'finally', because finally needs PHP 5.5 to work.
} catch ( \Exception $e ) {}
return $twig;
} | [
"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",
"(",
")",
")",
";",
"}",
")",
")",
";",
"// Use empty 'catch' block and not 'finally', because finally needs PHP 5.5 to work.",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"}",
"return",
"$",
"twig",
";",
"}"
] | Make function available in Twig.
When a function is added more than once, addFunction() will throw a LogicException that states that the function
is already registered. By catching this exception, we can prevent a fatal error.
@see Twig_Extension_Staging::addFunction()
@deprecated since 1.3.0
@todo remove in 1.4.0
@param \Twig_Environment $twig
@return \Twig_Environment | [
"Make",
"function",
"available",
"in",
"Twig",
"."
] | baaa1960193cffb5fa7c43c09114d6831764eede | https://github.com/timber/timber/blob/baaa1960193cffb5fa7c43c09114d6831764eede/lib/FunctionWrapper.php#L71-L83 | train |
timber/timber | lib/ImageHelper.php | ImageHelper.resize | 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($w, $h, $crop);
return self::_operate($src, $op, $force);
} | php | 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($w, $h, $crop);
return self::_operate($src, $op, $force);
} | [
"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",
"(",
"$",
"w",
",",
"$",
"h",
",",
"$",
"crop",
")",
";",
"return",
"self",
"::",
"_operate",
"(",
"$",
"src",
",",
"$",
"op",
",",
"$",
"force",
")",
";",
"}"
] | Generates a new image with the specified dimensions.
New dimensions are achieved by cropping to maintain ratio.
@api
@param string $src an URL (absolute or relative) to the original image
@param int|string $w target width(int) or WordPress image size (WP-set or user-defined).
@param int $h target height (ignored if $w is WP image size). If not set, will ignore and resize based on $w only.
@param string $crop your choices are 'default', 'center', 'top', 'bottom', 'left', 'right'
@param bool $force
@example
```twig
<img src="{{ image.src | resize(300, 200, 'top') }}" />
```
```html
<img src="http://example.org/wp-content/uploads/pic-300x200-c-top.jpg" />
```
@return string (ex: ) | [
"Generates",
"a",
"new",
"image",
"with",
"the",
"specified",
"dimensions",
".",
"New",
"dimensions",
"are",
"achieved",
"by",
"cropping",
"to",
"maintain",
"ratio",
"."
] | baaa1960193cffb5fa7c43c09114d6831764eede | https://github.com/timber/timber/blob/baaa1960193cffb5fa7c43c09114d6831764eede/lib/ImageHelper.php#L61-L72 | train |
timber/timber | lib/ImageHelper.php | ImageHelper.find_wp_dimensions | 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('thumbnail', 'medium', 'large')) ) {
$w = get_option($size.'_size_w');
$h = get_option($size.'_size_h');
}
if ( isset($w) && isset($h) && ($w || $h) ) {
return array('w' => $w, 'h' => $h);
}
return false;
} | php | 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('thumbnail', 'medium', 'large')) ) {
$w = get_option($size.'_size_w');
$h = get_option($size.'_size_h');
}
if ( isset($w) && isset($h) && ($w || $h) ) {
return array('w' => $w, 'h' => $h);
}
return false;
} | [
"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",
"(",
"'thumbnail'",
",",
"'medium'",
",",
"'large'",
")",
")",
")",
"{",
"$",
"w",
"=",
"get_option",
"(",
"$",
"size",
".",
"'_size_w'",
")",
";",
"$",
"h",
"=",
"get_option",
"(",
"$",
"size",
".",
"'_size_h'",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"w",
")",
"&&",
"isset",
"(",
"$",
"h",
")",
"&&",
"(",
"$",
"w",
"||",
"$",
"h",
")",
")",
"{",
"return",
"array",
"(",
"'w'",
"=>",
"$",
"w",
",",
"'h'",
"=>",
"$",
"h",
")",
";",
"}",
"return",
"false",
";",
"}"
] | Find the sizes of an image based on a defined image size
@param string $size the image size to search for
can be WordPress-defined ("medium")
or user-defined ("my-awesome-size")
@return false|array {
@type int w
@type int h
} | [
"Find",
"the",
"sizes",
"of",
"an",
"image",
"based",
"on",
"a",
"defined",
"image",
"size"
] | baaa1960193cffb5fa7c43c09114d6831764eede | https://github.com/timber/timber/blob/baaa1960193cffb5fa7c43c09114d6831764eede/lib/ImageHelper.php#L84-L97 | train |
timber/timber | lib/ImageHelper.php | ImageHelper.retina_resize | public static function retina_resize( $src, $multiplier = 2, $force = false ) {
$op = new Image\Operation\Retina($multiplier);
return self::_operate($src, $op, $force);
} | php | public static function retina_resize( $src, $multiplier = 2, $force = false ) {
$op = new Image\Operation\Retina($multiplier);
return self::_operate($src, $op, $force);
} | [
"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.
@param string $src
@param float $multiplier
@param boolean $force
@return string url to the new image | [
"Generates",
"a",
"new",
"image",
"with",
"increased",
"size",
"for",
"display",
"on",
"Retina",
"screens",
"."
] | baaa1960193cffb5fa7c43c09114d6831764eede | https://github.com/timber/timber/blob/baaa1960193cffb5fa7c43c09114d6831764eede/lib/ImageHelper.php#L108-L111 | train |
timber/timber | lib/ImageHelper.php | ImageHelper.is_animated_gif | public static function is_animated_gif( $file ) {
if ( strpos(strtolower($file), '.gif') === false ) {
//doesn't have .gif, bail
return false;
}
//its a gif so test
if ( !($fh = @fopen($file, 'rb')) ) {
return false;
}
$count = 0;
//an animated gif contains multiple "frames", with each frame having a
//header made up of:
// * a static 4-byte sequence (\x00\x21\xF9\x04)
// * 4 variable bytes
// * a static 2-byte sequence (\x00\x2C)
// We read through the file til we reach the end of the file, or we've found
// at least 2 frame headers
while ( !feof($fh) && $count < 2 ) {
$chunk = fread($fh, 1024 * 100); //read 100kb at a time
$count += preg_match_all('#\x00\x21\xF9\x04.{4}\x00[\x2C\x21]#s', $chunk, $matches);
}
fclose($fh);
return $count > 1;
} | php | public static function is_animated_gif( $file ) {
if ( strpos(strtolower($file), '.gif') === false ) {
//doesn't have .gif, bail
return false;
}
//its a gif so test
if ( !($fh = @fopen($file, 'rb')) ) {
return false;
}
$count = 0;
//an animated gif contains multiple "frames", with each frame having a
//header made up of:
// * a static 4-byte sequence (\x00\x21\xF9\x04)
// * 4 variable bytes
// * a static 2-byte sequence (\x00\x2C)
// We read through the file til we reach the end of the file, or we've found
// at least 2 frame headers
while ( !feof($fh) && $count < 2 ) {
$chunk = fread($fh, 1024 * 100); //read 100kb at a time
$count += preg_match_all('#\x00\x21\xF9\x04.{4}\x00[\x2C\x21]#s', $chunk, $matches);
}
fclose($fh);
return $count > 1;
} | [
"public",
"static",
"function",
"is_animated_gif",
"(",
"$",
"file",
")",
"{",
"if",
"(",
"strpos",
"(",
"strtolower",
"(",
"$",
"file",
")",
",",
"'.gif'",
")",
"===",
"false",
")",
"{",
"//doesn't have .gif, bail",
"return",
"false",
";",
"}",
"//its a gif so test",
"if",
"(",
"!",
"(",
"$",
"fh",
"=",
"@",
"fopen",
"(",
"$",
"file",
",",
"'rb'",
")",
")",
")",
"{",
"return",
"false",
";",
"}",
"$",
"count",
"=",
"0",
";",
"//an animated gif contains multiple \"frames\", with each frame having a",
"//header made up of:",
"// * a static 4-byte sequence (\\x00\\x21\\xF9\\x04)",
"// * 4 variable bytes",
"// * a static 2-byte sequence (\\x00\\x2C)",
"// We read through the file til we reach the end of the file, or we've found",
"// at least 2 frame headers",
"while",
"(",
"!",
"feof",
"(",
"$",
"fh",
")",
"&&",
"$",
"count",
"<",
"2",
")",
"{",
"$",
"chunk",
"=",
"fread",
"(",
"$",
"fh",
",",
"1024",
"*",
"100",
")",
";",
"//read 100kb at a time",
"$",
"count",
"+=",
"preg_match_all",
"(",
"'#\\x00\\x21\\xF9\\x04.{4}\\x00[\\x2C\\x21]#s'",
",",
"$",
"chunk",
",",
"$",
"matches",
")",
";",
"}",
"fclose",
"(",
"$",
"fh",
")",
";",
"return",
"$",
"count",
">",
"1",
";",
"}"
] | checks to see if the given file is an aimated gif
@param string $file local filepath to a file, not a URL
@return boolean true if it's an animated gif, false if not | [
"checks",
"to",
"see",
"if",
"the",
"given",
"file",
"is",
"an",
"aimated",
"gif"
] | baaa1960193cffb5fa7c43c09114d6831764eede | https://github.com/timber/timber/blob/baaa1960193cffb5fa7c43c09114d6831764eede/lib/ImageHelper.php#L118-L143 | train |
timber/timber | lib/ImageHelper.php | ImageHelper.is_svg | 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;
}
/**
* Try reading mime type.
*
* SVG images are not allowed by default in WordPress, so we have to pass a default mime
* type for SVG images.
*/
$mime = wp_check_filetype_and_ext( $file_path, basename( $file_path ), array(
'svg' => 'image/svg+xml',
) );
return in_array( $mime['type'], array(
'image/svg+xml',
'text/html',
'text/plain',
'image/svg',
) );
} | php | 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;
}
/**
* Try reading mime type.
*
* SVG images are not allowed by default in WordPress, so we have to pass a default mime
* type for SVG images.
*/
$mime = wp_check_filetype_and_ext( $file_path, basename( $file_path ), array(
'svg' => 'image/svg+xml',
) );
return in_array( $mime['type'], array(
'image/svg+xml',
'text/html',
'text/plain',
'image/svg',
) );
} | [
"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",
";",
"}",
"/**\n\t\t * Try reading mime type.\n\t\t *\n\t\t * SVG images are not allowed by default in WordPress, so we have to pass a default mime\n\t\t * type for SVG images.\n\t\t */",
"$",
"mime",
"=",
"wp_check_filetype_and_ext",
"(",
"$",
"file_path",
",",
"basename",
"(",
"$",
"file_path",
")",
",",
"array",
"(",
"'svg'",
"=>",
"'image/svg+xml'",
",",
")",
")",
";",
"return",
"in_array",
"(",
"$",
"mime",
"[",
"'type'",
"]",
",",
"array",
"(",
"'image/svg+xml'",
",",
"'text/html'",
",",
"'text/plain'",
",",
"'image/svg'",
",",
")",
")",
";",
"}"
] | Checks if file is an SVG.
@param string $file_path File path to check.
@return bool True if SVG, false if not SVG or file doesn't exist. | [
"Checks",
"if",
"file",
"is",
"an",
"SVG",
"."
] | baaa1960193cffb5fa7c43c09114d6831764eede | https://github.com/timber/timber/blob/baaa1960193cffb5fa7c43c09114d6831764eede/lib/ImageHelper.php#L151-L176 | train |
timber/timber | lib/ImageHelper.php | ImageHelper.letterbox | public static function letterbox( $src, $w, $h, $color = false, $force = false ) {
$op = new Letterbox($w, $h, $color);
return self::_operate($src, $op, $force);
} | php | public static function letterbox( $src, $w, $h, $color = false, $force = false ) {
$op = new Letterbox($w, $h, $color);
return self::_operate($src, $op, $force);
} | [
"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.
@param string $src
@param int $w
@param int $h
@param string $color
@param bool $force
@return string | [
"Generate",
"a",
"new",
"image",
"with",
"the",
"specified",
"dimensions",
".",
"New",
"dimensions",
"are",
"achieved",
"by",
"adding",
"colored",
"bands",
"to",
"maintain",
"ratio",
"."
] | baaa1960193cffb5fa7c43c09114d6831764eede | https://github.com/timber/timber/blob/baaa1960193cffb5fa7c43c09114d6831764eede/lib/ImageHelper.php#L189-L192 | train |
timber/timber | lib/ImageHelper.php | ImageHelper.img_to_jpg | public static function img_to_jpg( $src, $bghex = '#FFFFFF', $force = false ) {
$op = new Image\Operation\ToJpg($bghex);
return self::_operate($src, $op, $force);
} | php | public static function img_to_jpg( $src, $bghex = '#FFFFFF', $force = false ) {
$op = new Image\Operation\ToJpg($bghex);
return self::_operate($src, $op, $force);
} | [
"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
@param string $src a url or path to the image (http://example.org/wp-content/uploads/2014/image.jpg) or (/wp-content/uploads/2014/image.jpg)
@param string $bghex
@return string | [
"Generates",
"a",
"new",
"image",
"by",
"converting",
"the",
"source",
"GIF",
"or",
"PNG",
"into",
"JPG"
] | baaa1960193cffb5fa7c43c09114d6831764eede | https://github.com/timber/timber/blob/baaa1960193cffb5fa7c43c09114d6831764eede/lib/ImageHelper.php#L201-L204 | train |
timber/timber | lib/ImageHelper.php | ImageHelper.img_to_webp | public static function img_to_webp( $src, $quality = 80, $force = false ) {
$op = new Image\Operation\ToWebp($quality);
return self::_operate($src, $op, $force);
} | php | public static function img_to_webp( $src, $quality = 80, $force = false ) {
$op = new Image\Operation\ToWebp($quality);
return self::_operate($src, $op, $force);
} | [
"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
@param string $src a url or path to the image (http://example.org/wp-content/uploads/2014/image.webp)
or (/wp-content/uploads/2014/image.jpg)
If webp is not supported, a jpeg image will be generated
@param int $quality ranges from 0 (worst quality, smaller file) to 100 (best quality, biggest file)
@param bool $force | [
"Generates",
"a",
"new",
"image",
"by",
"converting",
"the",
"source",
"into",
"WEBP",
"if",
"supported",
"by",
"the",
"server"
] | baaa1960193cffb5fa7c43c09114d6831764eede | https://github.com/timber/timber/blob/baaa1960193cffb5fa7c43c09114d6831764eede/lib/ImageHelper.php#L215-L218 | train |
timber/timber | lib/ImageHelper.php | ImageHelper._delete_generated_if_image | 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);
}
}
} | php | 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);
}
}
} | [
"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
@param int $post_id an attachment post id | [
"Checks",
"if",
"attachment",
"is",
"an",
"image",
"before",
"deleting",
"generated",
"files"
] | baaa1960193cffb5fa7c43c09114d6831764eede | https://github.com/timber/timber/blob/baaa1960193cffb5fa7c43c09114d6831764eede/lib/ImageHelper.php#L265-L272 | train |
timber/timber | lib/ImageHelper.php | ImageHelper.delete_generated_files | 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::process_delete_generated_files($filename, $ext, $dir, '-[0-9999999]*', '-[0-9]*x[0-9]*-c-[a-z]*.');
self::process_delete_generated_files($filename, $ext, $dir, '-lbox-[0-9999999]*', '-lbox-[0-9]*x[0-9]*-[a-zA-Z0-9]*.');
self::process_delete_generated_files($filename, 'jpg', $dir, '-tojpg.*');
self::process_delete_generated_files($filename, 'jpg', $dir, '-tojpg-[0-9999999]*');
} | php | 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::process_delete_generated_files($filename, $ext, $dir, '-[0-9999999]*', '-[0-9]*x[0-9]*-c-[a-z]*.');
self::process_delete_generated_files($filename, $ext, $dir, '-lbox-[0-9999999]*', '-lbox-[0-9]*x[0-9]*-[a-zA-Z0-9]*.');
self::process_delete_generated_files($filename, 'jpg', $dir, '-tojpg.*');
self::process_delete_generated_files($filename, 'jpg', $dir, '-tojpg-[0-9999999]*');
} | [
"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",
"::",
"process_delete_generated_files",
"(",
"$",
"filename",
",",
"$",
"ext",
",",
"$",
"dir",
",",
"'-[0-9999999]*'",
",",
"'-[0-9]*x[0-9]*-c-[a-z]*.'",
")",
";",
"self",
"::",
"process_delete_generated_files",
"(",
"$",
"filename",
",",
"$",
"ext",
",",
"$",
"dir",
",",
"'-lbox-[0-9999999]*'",
",",
"'-lbox-[0-9]*x[0-9]*-[a-zA-Z0-9]*.'",
")",
";",
"self",
"::",
"process_delete_generated_files",
"(",
"$",
"filename",
",",
"'jpg'",
",",
"$",
"dir",
",",
"'-tojpg.*'",
")",
";",
"self",
"::",
"process_delete_generated_files",
"(",
"$",
"filename",
",",
"'jpg'",
",",
"$",
"dir",
",",
"'-tojpg-[0-9999999]*'",
")",
";",
"}"
] | Deletes the auto-generated files for resize and letterboxing created by Timber
@param string $local_file ex: /var/www/wp-content/uploads/2015/my-pic.jpg
or: http://example.org/wp-content/uploads/2015/my-pic.jpg | [
"Deletes",
"the",
"auto",
"-",
"generated",
"files",
"for",
"resize",
"and",
"letterboxing",
"created",
"by",
"Timber"
] | baaa1960193cffb5fa7c43c09114d6831764eede | https://github.com/timber/timber/blob/baaa1960193cffb5fa7c43c09114d6831764eede/lib/ImageHelper.php#L280-L292 | train |
timber/timber | lib/ImageHelper.php | ImageHelper.process_delete_generated_files | 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 ) {
$pattern = '/'.preg_quote($dir, '/').'\/'.preg_quote($filename, '/').$match_pattern.preg_quote($ext, '/').'/';
$match = preg_match($pattern, $found_file);
if ( !$match_pattern || $match ) {
unlink($found_file);
}
}
} | php | 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 ) {
$pattern = '/'.preg_quote($dir, '/').'\/'.preg_quote($filename, '/').$match_pattern.preg_quote($ext, '/').'/';
$match = preg_match($pattern, $found_file);
if ( !$match_pattern || $match ) {
unlink($found_file);
}
}
} | [
"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",
")",
"{",
"$",
"pattern",
"=",
"'/'",
".",
"preg_quote",
"(",
"$",
"dir",
",",
"'/'",
")",
".",
"'\\/'",
".",
"preg_quote",
"(",
"$",
"filename",
",",
"'/'",
")",
".",
"$",
"match_pattern",
".",
"preg_quote",
"(",
"$",
"ext",
",",
"'/'",
")",
".",
"'/'",
";",
"$",
"match",
"=",
"preg_match",
"(",
"$",
"pattern",
",",
"$",
"found_file",
")",
";",
"if",
"(",
"!",
"$",
"match_pattern",
"||",
"$",
"match",
")",
"{",
"unlink",
"(",
"$",
"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.
keeping these here so I know what the hell we're matching
$match = preg_match("/\/srv\/www\/wordpress-develop\/src\/wp-content\/uploads\/2014\/05\/$filename-[0-9]*x[0-9]*-c-[a-z]*.jpg/", $found_file);
$match = preg_match("/\/srv\/www\/wordpress-develop\/src\/wp-content\/uploads\/2014\/05\/arch-[0-9]*x[0-9]*-c-[a-z]*.jpg/", $filename);
@param string $filename ex: my-pic
@param string $ext ex: jpg
@param string $dir var/www/wp-content/uploads/2015/
@param string $search_pattern pattern of files to pluck from
@param string $match_pattern pattern of files to go forth and delete | [
"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",
"."
] | baaa1960193cffb5fa7c43c09114d6831764eede | https://github.com/timber/timber/blob/baaa1960193cffb5fa7c43c09114d6831764eede/lib/ImageHelper.php#L308-L321 | train |
timber/timber | lib/ImageHelper.php | ImageHelper.get_server_location | public static function get_server_location( $url ) {
// if we're already an absolute dir, just return.
if ( 0 === strpos($url, ABSPATH) ) {
return $url;
}
// otherwise, analyze URL then build mapping path
$au = self::analyze_url($url);
$result = self::_get_file_path($au['base'], $au['subdir'], $au['basename']);
return $result;
} | php | public static function get_server_location( $url ) {
// if we're already an absolute dir, just return.
if ( 0 === strpos($url, ABSPATH) ) {
return $url;
}
// otherwise, analyze URL then build mapping path
$au = self::analyze_url($url);
$result = self::_get_file_path($au['base'], $au['subdir'], $au['basename']);
return $result;
} | [
"public",
"static",
"function",
"get_server_location",
"(",
"$",
"url",
")",
"{",
"// if we're already an absolute dir, just return.",
"if",
"(",
"0",
"===",
"strpos",
"(",
"$",
"url",
",",
"ABSPATH",
")",
")",
"{",
"return",
"$",
"url",
";",
"}",
"// otherwise, analyze URL then build mapping path",
"$",
"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
@param string $url
@return string | [
"Determines",
"the",
"filepath",
"corresponding",
"to",
"a",
"given",
"URL"
] | baaa1960193cffb5fa7c43c09114d6831764eede | https://github.com/timber/timber/blob/baaa1960193cffb5fa7c43c09114d6831764eede/lib/ImageHelper.php#L329-L338 | train |
timber/timber | lib/ImageHelper.php | ImageHelper.get_sideloaded_file_loc | 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']) ) {
$ext = $path_parts['extension'];
}
return $dir.'/'.$basename.'.'.$ext;
} | php | 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']) ) {
$ext = $path_parts['extension'];
}
return $dir.'/'.$basename.'.'.$ext;
} | [
"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'",
"]",
")",
")",
"{",
"$",
"ext",
"=",
"$",
"path_parts",
"[",
"'extension'",
"]",
";",
"}",
"return",
"$",
"dir",
".",
"'/'",
".",
"$",
"basename",
".",
"'.'",
".",
"$",
"ext",
";",
"}"
] | Determines the filepath where a given external file will be stored.
@param string $file
@return string | [
"Determines",
"the",
"filepath",
"where",
"a",
"given",
"external",
"file",
"will",
"be",
"stored",
"."
] | baaa1960193cffb5fa7c43c09114d6831764eede | https://github.com/timber/timber/blob/baaa1960193cffb5fa7c43c09114d6831764eede/lib/ImageHelper.php#L346-L358 | train |
timber/timber | lib/ImageHelper.php | ImageHelper.sideload_image | public static function sideload_image( $file ) {
$loc = self::get_sideloaded_file_loc($file);
if ( file_exists($loc) ) {
return URLHelper::file_system_to_url($loc);
}
// Download file to temp location
if ( !function_exists('download_url') ) {
require_once ABSPATH.'/wp-admin/includes/file.php';
}
$tmp = download_url($file);
preg_match('/[^\?]+\.(jpe?g|jpe|gif|png)\b/i', $file, $matches);
$file_array = array();
$file_array['name'] = basename($matches[0]);
$file_array['tmp_name'] = $tmp;
// If error storing temporarily, unlink
if ( is_wp_error($tmp) ) {
@unlink($file_array['tmp_name']);
$file_array['tmp_name'] = '';
}
// do the validation and storage stuff
$locinfo = pathinfo($loc);
$file = wp_upload_bits($locinfo['basename'], null, file_get_contents($file_array['tmp_name']));
return $file['url'];
} | php | public static function sideload_image( $file ) {
$loc = self::get_sideloaded_file_loc($file);
if ( file_exists($loc) ) {
return URLHelper::file_system_to_url($loc);
}
// Download file to temp location
if ( !function_exists('download_url') ) {
require_once ABSPATH.'/wp-admin/includes/file.php';
}
$tmp = download_url($file);
preg_match('/[^\?]+\.(jpe?g|jpe|gif|png)\b/i', $file, $matches);
$file_array = array();
$file_array['name'] = basename($matches[0]);
$file_array['tmp_name'] = $tmp;
// If error storing temporarily, unlink
if ( is_wp_error($tmp) ) {
@unlink($file_array['tmp_name']);
$file_array['tmp_name'] = '';
}
// do the validation and storage stuff
$locinfo = pathinfo($loc);
$file = wp_upload_bits($locinfo['basename'], null, file_get_contents($file_array['tmp_name']));
return $file['url'];
} | [
"public",
"static",
"function",
"sideload_image",
"(",
"$",
"file",
")",
"{",
"$",
"loc",
"=",
"self",
"::",
"get_sideloaded_file_loc",
"(",
"$",
"file",
")",
";",
"if",
"(",
"file_exists",
"(",
"$",
"loc",
")",
")",
"{",
"return",
"URLHelper",
"::",
"file_system_to_url",
"(",
"$",
"loc",
")",
";",
"}",
"// Download file to temp location",
"if",
"(",
"!",
"function_exists",
"(",
"'download_url'",
")",
")",
"{",
"require_once",
"ABSPATH",
".",
"'/wp-admin/includes/file.php'",
";",
"}",
"$",
"tmp",
"=",
"download_url",
"(",
"$",
"file",
")",
";",
"preg_match",
"(",
"'/[^\\?]+\\.(jpe?g|jpe|gif|png)\\b/i'",
",",
"$",
"file",
",",
"$",
"matches",
")",
";",
"$",
"file_array",
"=",
"array",
"(",
")",
";",
"$",
"file_array",
"[",
"'name'",
"]",
"=",
"basename",
"(",
"$",
"matches",
"[",
"0",
"]",
")",
";",
"$",
"file_array",
"[",
"'tmp_name'",
"]",
"=",
"$",
"tmp",
";",
"// If error storing temporarily, unlink",
"if",
"(",
"is_wp_error",
"(",
"$",
"tmp",
")",
")",
"{",
"@",
"unlink",
"(",
"$",
"file_array",
"[",
"'tmp_name'",
"]",
")",
";",
"$",
"file_array",
"[",
"'tmp_name'",
"]",
"=",
"''",
";",
"}",
"// do the validation and storage stuff",
"$",
"locinfo",
"=",
"pathinfo",
"(",
"$",
"loc",
")",
";",
"$",
"file",
"=",
"wp_upload_bits",
"(",
"$",
"locinfo",
"[",
"'basename'",
"]",
",",
"null",
",",
"file_get_contents",
"(",
"$",
"file_array",
"[",
"'tmp_name'",
"]",
")",
")",
";",
"return",
"$",
"file",
"[",
"'url'",
"]",
";",
"}"
] | downloads an external image to the server and stores it on the server
@param string $file the URL to the original file
@return string the URL to the downloaded file | [
"downloads",
"an",
"external",
"image",
"to",
"the",
"server",
"and",
"stores",
"it",
"on",
"the",
"server"
] | baaa1960193cffb5fa7c43c09114d6831764eede | https://github.com/timber/timber/blob/baaa1960193cffb5fa7c43c09114d6831764eede/lib/ImageHelper.php#L366-L389 | train |
timber/timber | lib/ImageHelper.php | ImageHelper.analyze_url | public static function analyze_url( $url ) {
$result = array(
'url' => $url, // the initial url
'absolute' => URLHelper::is_absolute($url), // is the url absolute or relative (to home_url)
'base' => 0, // is the image in uploads dir, or in content dir (theme or plugin)
'subdir' => '', // the path between base (uploads or content) and file
'filename' => '', // the filename, without extension
'extension' => '', // the file extension
'basename' => '', // full file name
);
$upload_dir = wp_upload_dir();
$tmp = $url;
if ( TextHelper::starts_with($tmp, ABSPATH) || TextHelper::starts_with($tmp, '/srv/www/') ) {
// we've been given a dir, not an url
$result['absolute'] = true;
if ( TextHelper::starts_with($tmp, $upload_dir['basedir']) ) {
$result['base'] = self::BASE_UPLOADS; // upload based
$tmp = URLHelper::remove_url_component($tmp, $upload_dir['basedir']);
}
if ( TextHelper::starts_with($tmp, WP_CONTENT_DIR) ) {
$result['base'] = self::BASE_CONTENT; // content based
$tmp = URLHelper::remove_url_component($tmp, WP_CONTENT_DIR);
}
} else {
if ( !$result['absolute'] ) {
$tmp = untrailingslashit(network_home_url()).$tmp;
}
if ( URLHelper::starts_with($tmp, $upload_dir['baseurl']) ) {
$result['base'] = self::BASE_UPLOADS; // upload based
$tmp = URLHelper::remove_url_component($tmp, $upload_dir['baseurl']);
} else if ( URLHelper::starts_with($tmp, content_url()) ) {
$result['base'] = self::BASE_CONTENT; // content-based
$tmp = self::theme_url_to_dir($tmp);
$tmp = URLHelper::remove_url_component($tmp, WP_CONTENT_DIR);
}
}
$parts = pathinfo($tmp);
$result['subdir'] = ($parts['dirname'] === '/') ? '' : $parts['dirname'];
$result['filename'] = $parts['filename'];
$result['extension'] = strtolower($parts['extension']);
$result['basename'] = $parts['basename'];
return $result;
} | php | public static function analyze_url( $url ) {
$result = array(
'url' => $url, // the initial url
'absolute' => URLHelper::is_absolute($url), // is the url absolute or relative (to home_url)
'base' => 0, // is the image in uploads dir, or in content dir (theme or plugin)
'subdir' => '', // the path between base (uploads or content) and file
'filename' => '', // the filename, without extension
'extension' => '', // the file extension
'basename' => '', // full file name
);
$upload_dir = wp_upload_dir();
$tmp = $url;
if ( TextHelper::starts_with($tmp, ABSPATH) || TextHelper::starts_with($tmp, '/srv/www/') ) {
// we've been given a dir, not an url
$result['absolute'] = true;
if ( TextHelper::starts_with($tmp, $upload_dir['basedir']) ) {
$result['base'] = self::BASE_UPLOADS; // upload based
$tmp = URLHelper::remove_url_component($tmp, $upload_dir['basedir']);
}
if ( TextHelper::starts_with($tmp, WP_CONTENT_DIR) ) {
$result['base'] = self::BASE_CONTENT; // content based
$tmp = URLHelper::remove_url_component($tmp, WP_CONTENT_DIR);
}
} else {
if ( !$result['absolute'] ) {
$tmp = untrailingslashit(network_home_url()).$tmp;
}
if ( URLHelper::starts_with($tmp, $upload_dir['baseurl']) ) {
$result['base'] = self::BASE_UPLOADS; // upload based
$tmp = URLHelper::remove_url_component($tmp, $upload_dir['baseurl']);
} else if ( URLHelper::starts_with($tmp, content_url()) ) {
$result['base'] = self::BASE_CONTENT; // content-based
$tmp = self::theme_url_to_dir($tmp);
$tmp = URLHelper::remove_url_component($tmp, WP_CONTENT_DIR);
}
}
$parts = pathinfo($tmp);
$result['subdir'] = ($parts['dirname'] === '/') ? '' : $parts['dirname'];
$result['filename'] = $parts['filename'];
$result['extension'] = strtolower($parts['extension']);
$result['basename'] = $parts['basename'];
return $result;
} | [
"public",
"static",
"function",
"analyze_url",
"(",
"$",
"url",
")",
"{",
"$",
"result",
"=",
"array",
"(",
"'url'",
"=>",
"$",
"url",
",",
"// the initial url",
"'absolute'",
"=>",
"URLHelper",
"::",
"is_absolute",
"(",
"$",
"url",
")",
",",
"// is the url absolute or relative (to home_url)",
"'base'",
"=>",
"0",
",",
"// is the image in uploads dir, or in content dir (theme or plugin)",
"'subdir'",
"=>",
"''",
",",
"// the path between base (uploads or content) and file",
"'filename'",
"=>",
"''",
",",
"// the filename, without extension",
"'extension'",
"=>",
"''",
",",
"// the file extension",
"'basename'",
"=>",
"''",
",",
"// full file name",
")",
";",
"$",
"upload_dir",
"=",
"wp_upload_dir",
"(",
")",
";",
"$",
"tmp",
"=",
"$",
"url",
";",
"if",
"(",
"TextHelper",
"::",
"starts_with",
"(",
"$",
"tmp",
",",
"ABSPATH",
")",
"||",
"TextHelper",
"::",
"starts_with",
"(",
"$",
"tmp",
",",
"'/srv/www/'",
")",
")",
"{",
"// we've been given a dir, not an url",
"$",
"result",
"[",
"'absolute'",
"]",
"=",
"true",
";",
"if",
"(",
"TextHelper",
"::",
"starts_with",
"(",
"$",
"tmp",
",",
"$",
"upload_dir",
"[",
"'basedir'",
"]",
")",
")",
"{",
"$",
"result",
"[",
"'base'",
"]",
"=",
"self",
"::",
"BASE_UPLOADS",
";",
"// upload based",
"$",
"tmp",
"=",
"URLHelper",
"::",
"remove_url_component",
"(",
"$",
"tmp",
",",
"$",
"upload_dir",
"[",
"'basedir'",
"]",
")",
";",
"}",
"if",
"(",
"TextHelper",
"::",
"starts_with",
"(",
"$",
"tmp",
",",
"WP_CONTENT_DIR",
")",
")",
"{",
"$",
"result",
"[",
"'base'",
"]",
"=",
"self",
"::",
"BASE_CONTENT",
";",
"// content based",
"$",
"tmp",
"=",
"URLHelper",
"::",
"remove_url_component",
"(",
"$",
"tmp",
",",
"WP_CONTENT_DIR",
")",
";",
"}",
"}",
"else",
"{",
"if",
"(",
"!",
"$",
"result",
"[",
"'absolute'",
"]",
")",
"{",
"$",
"tmp",
"=",
"untrailingslashit",
"(",
"network_home_url",
"(",
")",
")",
".",
"$",
"tmp",
";",
"}",
"if",
"(",
"URLHelper",
"::",
"starts_with",
"(",
"$",
"tmp",
",",
"$",
"upload_dir",
"[",
"'baseurl'",
"]",
")",
")",
"{",
"$",
"result",
"[",
"'base'",
"]",
"=",
"self",
"::",
"BASE_UPLOADS",
";",
"// upload based",
"$",
"tmp",
"=",
"URLHelper",
"::",
"remove_url_component",
"(",
"$",
"tmp",
",",
"$",
"upload_dir",
"[",
"'baseurl'",
"]",
")",
";",
"}",
"else",
"if",
"(",
"URLHelper",
"::",
"starts_with",
"(",
"$",
"tmp",
",",
"content_url",
"(",
")",
")",
")",
"{",
"$",
"result",
"[",
"'base'",
"]",
"=",
"self",
"::",
"BASE_CONTENT",
";",
"// content-based",
"$",
"tmp",
"=",
"self",
"::",
"theme_url_to_dir",
"(",
"$",
"tmp",
")",
";",
"$",
"tmp",
"=",
"URLHelper",
"::",
"remove_url_component",
"(",
"$",
"tmp",
",",
"WP_CONTENT_DIR",
")",
";",
"}",
"}",
"$",
"parts",
"=",
"pathinfo",
"(",
"$",
"tmp",
")",
";",
"$",
"result",
"[",
"'subdir'",
"]",
"=",
"(",
"$",
"parts",
"[",
"'dirname'",
"]",
"===",
"'/'",
")",
"?",
"''",
":",
"$",
"parts",
"[",
"'dirname'",
"]",
";",
"$",
"result",
"[",
"'filename'",
"]",
"=",
"$",
"parts",
"[",
"'filename'",
"]",
";",
"$",
"result",
"[",
"'extension'",
"]",
"=",
"strtolower",
"(",
"$",
"parts",
"[",
"'extension'",
"]",
")",
";",
"$",
"result",
"[",
"'basename'",
"]",
"=",
"$",
"parts",
"[",
"'basename'",
"]",
";",
"return",
"$",
"result",
";",
"}"
] | 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.
@param string $url an URL (absolute or relative) pointing to an image
@return array an array (see keys in code below) | [
"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",
"."
] | baaa1960193cffb5fa7c43c09114d6831764eede | https://github.com/timber/timber/blob/baaa1960193cffb5fa7c43c09114d6831764eede/lib/ImageHelper.php#L399-L441 | train |
timber/timber | lib/ImageHelper.php | ImageHelper.theme_url_to_dir | static function theme_url_to_dir( $src ) {
$site_root = trailingslashit(get_theme_root_uri()).get_stylesheet();
$tmp = str_replace($site_root, '', $src);
//$tmp = trailingslashit(get_theme_root()).get_stylesheet().$tmp;
$tmp = get_stylesheet_directory().$tmp;
if ( realpath($tmp) ) {
return realpath($tmp);
}
return $tmp;
} | php | static function theme_url_to_dir( $src ) {
$site_root = trailingslashit(get_theme_root_uri()).get_stylesheet();
$tmp = str_replace($site_root, '', $src);
//$tmp = trailingslashit(get_theme_root()).get_stylesheet().$tmp;
$tmp = get_stylesheet_directory().$tmp;
if ( realpath($tmp) ) {
return realpath($tmp);
}
return $tmp;
} | [
"static",
"function",
"theme_url_to_dir",
"(",
"$",
"src",
")",
"{",
"$",
"site_root",
"=",
"trailingslashit",
"(",
"get_theme_root_uri",
"(",
")",
")",
".",
"get_stylesheet",
"(",
")",
";",
"$",
"tmp",
"=",
"str_replace",
"(",
"$",
"site_root",
",",
"''",
",",
"$",
"src",
")",
";",
"//$tmp = trailingslashit(get_theme_root()).get_stylesheet().$tmp;",
"$",
"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
@param string $src a URL (http://example.org/wp-content/themes/twentysixteen/images/home.jpg)
@return string full path to the file in question | [
"Converts",
"a",
"URL",
"located",
"in",
"a",
"theme",
"directory",
"into",
"the",
"raw",
"file",
"path"
] | baaa1960193cffb5fa7c43c09114d6831764eede | https://github.com/timber/timber/blob/baaa1960193cffb5fa7c43c09114d6831764eede/lib/ImageHelper.php#L448-L457 | train |
timber/timber | lib/ImageHelper.php | ImageHelper.is_in_theme_dir | 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;
}
} | php | 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;
}
} | [
"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.
@param string $path image path.
@return bool If the image is located in the theme directory it returns true.
If not or $path doesn't exits it returns false. | [
"Checks",
"if",
"uploaded",
"image",
"is",
"located",
"in",
"theme",
"."
] | baaa1960193cffb5fa7c43c09114d6831764eede | https://github.com/timber/timber/blob/baaa1960193cffb5fa7c43c09114d6831764eede/lib/ImageHelper.php#L466-L478 | train |
timber/timber | lib/ImageHelper.php | ImageHelper._get_file_url | 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 .= $subdir;
}
$url .= '/'.$filename;
if ( !$absolute ) {
$url = str_replace(site_url(), '', $url);
}
// $url = TimberURLHelper::remove_double_slashes( $url);
return $url;
} | php | 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 .= $subdir;
}
$url .= '/'.$filename;
if ( !$absolute ) {
$url = str_replace(site_url(), '', $url);
}
// $url = TimberURLHelper::remove_double_slashes( $url);
return $url;
} | [
"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",
".=",
"$",
"subdir",
";",
"}",
"$",
"url",
".=",
"'/'",
".",
"$",
"filename",
";",
"if",
"(",
"!",
"$",
"absolute",
")",
"{",
"$",
"url",
"=",
"str_replace",
"(",
"site_url",
"(",
")",
",",
"''",
",",
"$",
"url",
")",
";",
"}",
"// $url = TimberURLHelper::remove_double_slashes( $url);",
"return",
"$",
"url",
";",
"}"
] | Builds the public URL of a file based on its different components
@param int $base one of self::BASE_UPLOADS, self::BASE_CONTENT to indicate if file is an upload or a content (theme or plugin)
@param string $subdir subdirectory in which file is stored, relative to $base root folder
@param string $filename file name, including extension (but no path)
@param bool $absolute should the returned URL be absolute (include protocol+host), or relative
@return string the URL | [
"Builds",
"the",
"public",
"URL",
"of",
"a",
"file",
"based",
"on",
"its",
"different",
"components"
] | baaa1960193cffb5fa7c43c09114d6831764eede | https://github.com/timber/timber/blob/baaa1960193cffb5fa7c43c09114d6831764eede/lib/ImageHelper.php#L489-L507 | train |
timber/timber | lib/ImageHelper.php | ImageHelper._get_file_path | 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 ) {
//it is in the Uploads directory
$upload_dir = wp_upload_dir();
$path = $upload_dir['basedir'];
} else if ( self::BASE_CONTENT == $base ) {
//it is in the content directory, somewhere else ...
$path = WP_CONTENT_DIR;
}
if ( self::is_in_theme_dir(trailingslashit($subdir).$filename) ) {
//this is for weird installs when the theme folder is outside of /wp-content
return trailingslashit($subdir).$filename;
}
if ( !empty($subdir) ) {
$path = trailingslashit($path).$subdir;
}
$path = trailingslashit($path).$filename;
return URLHelper::remove_double_slashes($path);
} | php | 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 ) {
//it is in the Uploads directory
$upload_dir = wp_upload_dir();
$path = $upload_dir['basedir'];
} else if ( self::BASE_CONTENT == $base ) {
//it is in the content directory, somewhere else ...
$path = WP_CONTENT_DIR;
}
if ( self::is_in_theme_dir(trailingslashit($subdir).$filename) ) {
//this is for weird installs when the theme folder is outside of /wp-content
return trailingslashit($subdir).$filename;
}
if ( !empty($subdir) ) {
$path = trailingslashit($path).$subdir;
}
$path = trailingslashit($path).$filename;
return URLHelper::remove_double_slashes($path);
} | [
"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",
")",
"{",
"//it is in the Uploads directory",
"$",
"upload_dir",
"=",
"wp_upload_dir",
"(",
")",
";",
"$",
"path",
"=",
"$",
"upload_dir",
"[",
"'basedir'",
"]",
";",
"}",
"else",
"if",
"(",
"self",
"::",
"BASE_CONTENT",
"==",
"$",
"base",
")",
"{",
"//it is in the content directory, somewhere else ...",
"$",
"path",
"=",
"WP_CONTENT_DIR",
";",
"}",
"if",
"(",
"self",
"::",
"is_in_theme_dir",
"(",
"trailingslashit",
"(",
"$",
"subdir",
")",
".",
"$",
"filename",
")",
")",
"{",
"//this is for weird installs when the theme folder is outside of /wp-content",
"return",
"trailingslashit",
"(",
"$",
"subdir",
")",
".",
"$",
"filename",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"subdir",
")",
")",
"{",
"$",
"path",
"=",
"trailingslashit",
"(",
"$",
"path",
")",
".",
"$",
"subdir",
";",
"}",
"$",
"path",
"=",
"trailingslashit",
"(",
"$",
"path",
")",
".",
"$",
"filename",
";",
"return",
"URLHelper",
"::",
"remove_double_slashes",
"(",
"$",
"path",
")",
";",
"}"
] | Builds the absolute file system location of a file based on its different components
@param int $base one of self::BASE_UPLOADS, self::BASE_CONTENT to indicate if file is an upload or a content (theme or plugin)
@param string $subdir subdirectory in which file is stored, relative to $base root folder
@param string $filename file name, including extension (but no path)
@return string the file location | [
"Builds",
"the",
"absolute",
"file",
"system",
"location",
"of",
"a",
"file",
"based",
"on",
"its",
"different",
"components"
] | baaa1960193cffb5fa7c43c09114d6831764eede | https://github.com/timber/timber/blob/baaa1960193cffb5fa7c43c09114d6831764eede/lib/ImageHelper.php#L530-L555 | train |
timber/timber | lib/PostQuery.php | PostQuery.pagination | 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;
} | php | 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;
} | [
"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.
@param array $prefs
@return Timber\Pagination object | [
"Set",
"pagination",
"for",
"the",
"collection",
".",
"Optionally",
"could",
"be",
"used",
"to",
"get",
"pagination",
"with",
"custom",
"preferences",
"."
] | baaa1960193cffb5fa7c43c09114d6831764eede | https://github.com/timber/timber/blob/baaa1960193cffb5fa7c43c09114d6831764eede/lib/PostQuery.php#L49-L54 | train |
timber/timber | lib/Menu.php | Menu.find_parent_item_in_menu | public function find_parent_item_in_menu( $menu_items, $parent_id ) {
foreach ( $menu_items as &$item ) {
if ( $item->ID == $parent_id ) {
return $item;
}
}
} | php | public function find_parent_item_in_menu( $menu_items, $parent_id ) {
foreach ( $menu_items as &$item ) {
if ( $item->ID == $parent_id ) {
return $item;
}
}
} | [
"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.
@api
@param array $menu_items An array of menu items.
@param int $parent_id The parent ID to look for.
@return \Timber\MenuItem|bool A menu item. False if no parent was found. | [
"Find",
"a",
"parent",
"menu",
"item",
"in",
"a",
"set",
"of",
"menu",
"items",
"."
] | baaa1960193cffb5fa7c43c09114d6831764eede | https://github.com/timber/timber/blob/baaa1960193cffb5fa7c43c09114d6831764eede/lib/Menu.php#L234-L240 | train |
timber/timber | lib/Admin.php | Admin.in_plugin_update_message | 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 = self::update_message_milestone();
echo '<br />'.sprintf($message);
return;
} elseif ( $upgrade_magnitude == 'major' ) {
//major version
$message = self::update_message_major();
echo '<br />'.sprintf($message);
return;
}
$message = self::update_message_minor();
echo '<br />'.($message);
return;
} | php | 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 = self::update_message_milestone();
echo '<br />'.sprintf($message);
return;
} elseif ( $upgrade_magnitude == 'major' ) {
//major version
$message = self::update_message_major();
echo '<br />'.sprintf($message);
return;
}
$message = self::update_message_minor();
echo '<br />'.($message);
return;
} | [
"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",
"=",
"self",
"::",
"update_message_milestone",
"(",
")",
";",
"echo",
"'<br />'",
".",
"sprintf",
"(",
"$",
"message",
")",
";",
"return",
";",
"}",
"elseif",
"(",
"$",
"upgrade_magnitude",
"==",
"'major'",
")",
"{",
"//major version",
"$",
"message",
"=",
"self",
"::",
"update_message_major",
"(",
")",
";",
"echo",
"'<br />'",
".",
"sprintf",
"(",
"$",
"message",
")",
";",
"return",
";",
"}",
"$",
"message",
"=",
"self",
"::",
"update_message_minor",
"(",
")",
";",
"echo",
"'<br />'",
".",
"(",
"$",
"message",
")",
";",
"return",
";",
"}"
] | Displays an update message for plugin list screens.
Shows only the version updates from the current until the newest version
@codeCoverageIgnore
@type function
@date 4/22/16
@param {array} $plugin_data
@param {object} $r | [
"Displays",
"an",
"update",
"message",
"for",
"plugin",
"list",
"screens",
".",
"Shows",
"only",
"the",
"version",
"updates",
"from",
"the",
"current",
"until",
"the",
"newest",
"version"
] | baaa1960193cffb5fa7c43c09114d6831764eede | https://github.com/timber/timber/blob/baaa1960193cffb5fa7c43c09114d6831764eede/lib/Admin.php#L103-L121 | train |
timber/timber | lib/TextHelper.php | TextHelper.trim_characters | public static function trim_characters( $text, $num_chars = 60, $more = '…' ) {
$text = wp_strip_all_tags($text);
$text = mb_strimwidth($text, 0, $num_chars, $more);
return $text;
} | php | public static function trim_characters( $text, $num_chars = 60, $more = '…' ) {
$text = wp_strip_all_tags($text);
$text = mb_strimwidth($text, 0, $num_chars, $more);
return $text;
} | [
"public",
"static",
"function",
"trim_characters",
"(",
"$",
"text",
",",
"$",
"num_chars",
"=",
"60",
",",
"$",
"more",
"=",
"'…'",
")",
"{",
"$",
"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
@since 1.2.0
@author @CROSP
@param string $text Text to trim.
@param int $num_chars Number of characters. Default is 60.
@param string $more What to append if $text needs to be trimmed. Defaults to '…'.
@return string trimmed 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"
] | baaa1960193cffb5fa7c43c09114d6831764eede | https://github.com/timber/timber/blob/baaa1960193cffb5fa7c43c09114d6831764eede/lib/TextHelper.php#L24-L28 | train |
timber/timber | lib/LocationManager.php | LocationManager.get_calling_script_file | 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($callers);
$callers = array_values($callers);
return $callers[$offset];
} | php | 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($callers);
$callers = array_values($callers);
return $callers[$offset];
} | [
"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",
"(",
"$",
"callers",
")",
";",
"$",
"callers",
"=",
"array_values",
"(",
"$",
"callers",
")",
";",
"return",
"$",
"callers",
"[",
"$",
"offset",
"]",
";",
"}"
] | Get calling script file.
@api
@param int $offset
@return string|null | [
"Get",
"calling",
"script",
"file",
"."
] | baaa1960193cffb5fa7c43c09114d6831764eede | https://github.com/timber/timber/blob/baaa1960193cffb5fa7c43c09114d6831764eede/lib/LocationManager.php#L63-L74 | train |
timber/timber | lib/LocationManager.php | LocationManager.get_calling_script_dir | 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;
}
} | php | 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;
}
} | [
"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.
@api
@return string | [
"Get",
"calling",
"script",
"dir",
"."
] | baaa1960193cffb5fa7c43c09114d6831764eede | https://github.com/timber/timber/blob/baaa1960193cffb5fa7c43c09114d6831764eede/lib/LocationManager.php#L81-L88 | train |
timber/timber | lib/Image/Operation/Retina.php | Retina.filename | public function filename( $src_filename, $src_extension ) {
$newbase = $src_filename.'@'.$this->factor.'x'; // add @2x, @3x, @1.5x, etc.
$new_name = $newbase.'.'.$src_extension;
return $new_name;
} | php | public function filename( $src_filename, $src_extension ) {
$newbase = $src_filename.'@'.$this->factor.'x'; // add @2x, @3x, @1.5x, etc.
$new_name = $newbase.'.'.$src_extension;
return $new_name;
} | [
"public",
"function",
"filename",
"(",
"$",
"src_filename",
",",
"$",
"src_extension",
")",
"{",
"$",
"newbase",
"=",
"$",
"src_filename",
".",
"'@'",
".",
"$",
"this",
"->",
"factor",
".",
"'x'",
";",
"// add @2x, @3x, @1.5x, etc.",
"$",
"new_name",
"=",
"$",
"newbase",
".",
"'.'",
".",
"$",
"src_extension",
";",
"return",
"$",
"new_name",
";",
"}"
] | Generates the final filename based on the source's name and extension
@param string $src_filename the basename of the file (ex: my-awesome-pic)
@param string $src_extension the extension (ex: .jpg)
@return string the final filename to be used (ex: my-awesome-pic@2x.jpg) | [
"Generates",
"the",
"final",
"filename",
"based",
"on",
"the",
"source",
"s",
"name",
"and",
"extension"
] | baaa1960193cffb5fa7c43c09114d6831764eede | https://github.com/timber/timber/blob/baaa1960193cffb5fa7c43c09114d6831764eede/lib/Image/Operation/Retina.php#L38-L42 | train |
timber/timber | lib/Timber.php | Timber.get_sites | 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 $return;
} | php | 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 $return;
} | [
"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",
"$",
"return",
";",
"}"
] | Get sites.
@api
@param array|bool $blog_ids
@return array | [
"Get",
"sites",
"."
] | baaa1960193cffb5fa7c43c09114d6831764eede | https://github.com/timber/timber/blob/baaa1960193cffb5fa7c43c09114d6831764eede/lib/Timber.php#L212-L222 | train |
timber/timber | lib/Timber.php | Timber.compile | 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);
$file = $loader->choose_template($filenames);
$caller_file = LocationManager::get_calling_script_file(1);
apply_filters('timber/calling_php_file', $caller_file);
if ( $via_render ) {
$file = apply_filters('timber_render_file', $file);
} else {
$file = apply_filters('timber_compile_file', $file);
}
$output = false;
if ($file !== false) {
if ( is_null($data) ) {
$data = array();
}
if ( $via_render ) {
$data = apply_filters('timber_render_data', $data);
} else {
$data = apply_filters('timber_compile_data', $data);
}
$output = $loader->render($file, $data, $expires, $cache_mode);
}
do_action('timber_compile_done');
return $output;
} | php | 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);
$file = $loader->choose_template($filenames);
$caller_file = LocationManager::get_calling_script_file(1);
apply_filters('timber/calling_php_file', $caller_file);
if ( $via_render ) {
$file = apply_filters('timber_render_file', $file);
} else {
$file = apply_filters('timber_compile_file', $file);
}
$output = false;
if ($file !== false) {
if ( is_null($data) ) {
$data = array();
}
if ( $via_render ) {
$data = apply_filters('timber_render_data', $data);
} else {
$data = apply_filters('timber_compile_data', $data);
}
$output = $loader->render($file, $data, $expires, $cache_mode);
}
do_action('timber_compile_done');
return $output;
} | [
"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",
")",
";",
"$",
"file",
"=",
"$",
"loader",
"->",
"choose_template",
"(",
"$",
"filenames",
")",
";",
"$",
"caller_file",
"=",
"LocationManager",
"::",
"get_calling_script_file",
"(",
"1",
")",
";",
"apply_filters",
"(",
"'timber/calling_php_file'",
",",
"$",
"caller_file",
")",
";",
"if",
"(",
"$",
"via_render",
")",
"{",
"$",
"file",
"=",
"apply_filters",
"(",
"'timber_render_file'",
",",
"$",
"file",
")",
";",
"}",
"else",
"{",
"$",
"file",
"=",
"apply_filters",
"(",
"'timber_compile_file'",
",",
"$",
"file",
")",
";",
"}",
"$",
"output",
"=",
"false",
";",
"if",
"(",
"$",
"file",
"!==",
"false",
")",
"{",
"if",
"(",
"is_null",
"(",
"$",
"data",
")",
")",
"{",
"$",
"data",
"=",
"array",
"(",
")",
";",
"}",
"if",
"(",
"$",
"via_render",
")",
"{",
"$",
"data",
"=",
"apply_filters",
"(",
"'timber_render_data'",
",",
"$",
"data",
")",
";",
"}",
"else",
"{",
"$",
"data",
"=",
"apply_filters",
"(",
"'timber_compile_data'",
",",
"$",
"data",
")",
";",
"}",
"$",
"output",
"=",
"$",
"loader",
"->",
"render",
"(",
"$",
"file",
",",
"$",
"data",
",",
"$",
"expires",
",",
"$",
"cache_mode",
")",
";",
"}",
"do_action",
"(",
"'timber_compile_done'",
")",
";",
"return",
"$",
"output",
";",
"}"
] | Compile a Twig file.
Passes data to a Twig file and returns the output.
@api
@example
```php
$data = array(
'firstname' => 'Jane',
'lastname' => 'Doe',
'email' => 'jane.doe@example.org',
);
$team_member = Timber::compile( 'team-member.twig', $data );
```
@param array|string $filenames Name of the Twig file to render. If this is an array of files, Timber will
render the first file that exists.
@param array $data Optional. An array of data to use in Twig template.
@param bool|int $expires Optional. In seconds. Use false to disable cache altogether. When passed an
array, the first value is used for non-logged in visitors, the second for users.
Default false.
@param string $cache_mode Optional. Any of the cache mode constants defined in TimberLoader.
@param bool $via_render Optional. Whether to apply optional render or compile filters. Default false.
@return bool|string The returned output. | [
"Compile",
"a",
"Twig",
"file",
"."
] | baaa1960193cffb5fa7c43c09114d6831764eede | https://github.com/timber/timber/blob/baaa1960193cffb5fa7c43c09114d6831764eede/lib/Timber.php#L303-L338 | train |
timber/timber | lib/Timber.php | Timber.compile_string | 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);
} | php | 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);
} | [
"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.
@api
@example
```php
$data = array(
'username' => 'Jane Doe',
);
$welcome = Timber::compile_string( 'Hi {{ username }}, I’m a string with a custom Twig variable', $data );
```
@param string $string A string with Twig variables.
@param array $data Optional. An array of data to use in Twig template.
@return bool|string | [
"Compile",
"a",
"string",
"."
] | baaa1960193cffb5fa7c43c09114d6831764eede | https://github.com/timber/timber/blob/baaa1960193cffb5fa7c43c09114d6831764eede/lib/Timber.php#L356-L361 | train |
timber/timber | lib/Timber.php | Timber.fetch | 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;
} | php | 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;
} | [
"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.
@api
@param array|string $filenames Name of the Twig file to render. If this is an array of files, Timber will
render the first file that exists.
@param array $data Optional. An array of data to use in Twig template.
@param bool|int $expires Optional. In seconds. Use false to disable cache altogether. When passed an
array, the first value is used for non-logged in visitors, the second for users.
Default false.
@param string $cache_mode Optional. Any of the cache mode constants defined in TimberLoader.
@return bool|string The returned output. | [
"Fetch",
"function",
"."
] | baaa1960193cffb5fa7c43c09114d6831764eede | https://github.com/timber/timber/blob/baaa1960193cffb5fa7c43c09114d6831764eede/lib/Timber.php#L376-L380 | train |
timber/timber | lib/Timber.php | Timber.render_string | public static function render_string( $string, $data = array() ) {
$compiled = self::compile_string($string, $data);
echo $compiled;
return $compiled;
} | php | public static function render_string( $string, $data = array() ) {
$compiled = self::compile_string($string, $data);
echo $compiled;
return $compiled;
} | [
"public",
"static",
"function",
"render_string",
"(",
"$",
"string",
",",
"$",
"data",
"=",
"array",
"(",
")",
")",
"{",
"$",
"compiled",
"=",
"self",
"::",
"compile_string",
"(",
"$",
"string",
",",
"$",
"data",
")",
";",
"echo",
"$",
"compiled",
";",
"return",
"$",
"compiled",
";",
"}"
] | Render a string with Twig variables.
@api
@example
```php
$data = array(
'username' => 'Jane Doe',
);
Timber::render_string( 'Hi {{ username }}, I’m a string with a custom Twig variable', $data );
```
@param string $string A string with Twig variables.
@param array $data An array of data to use in Twig template.
@return bool|string | [
"Render",
"a",
"string",
"with",
"Twig",
"variables",
"."
] | baaa1960193cffb5fa7c43c09114d6831764eede | https://github.com/timber/timber/blob/baaa1960193cffb5fa7c43c09114d6831764eede/lib/Timber.php#L425-L429 | train |
timber/timber | lib/Timber.php | Timber.get_sidebar | 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);
} | php | 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);
} | [
"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.
@api
@param string $sidebar
@param array $data
@return bool|string | [
"Get",
"sidebar",
"."
] | baaa1960193cffb5fa7c43c09114d6831764eede | https://github.com/timber/timber/blob/baaa1960193cffb5fa7c43c09114d6831764eede/lib/Timber.php#L442-L447 | train |
timber/timber | lib/Timber.php | Timber.get_sidebar_from_php | 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) ) {
include trailingslashit($uri).$sidebar;
$found = true;
break;
}
}
if ( !$found ) {
Helper::error_log('error loading your sidebar, check to make sure the file exists');
}
$ret = ob_get_contents();
ob_end_clean();
return $ret;
} | php | 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) ) {
include trailingslashit($uri).$sidebar;
$found = true;
break;
}
}
if ( !$found ) {
Helper::error_log('error loading your sidebar, check to make sure the file exists');
}
$ret = ob_get_contents();
ob_end_clean();
return $ret;
} | [
"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",
")",
")",
"{",
"include",
"trailingslashit",
"(",
"$",
"uri",
")",
".",
"$",
"sidebar",
";",
"$",
"found",
"=",
"true",
";",
"break",
";",
"}",
"}",
"if",
"(",
"!",
"$",
"found",
")",
"{",
"Helper",
"::",
"error_log",
"(",
"'error loading your sidebar, check to make sure the file exists'",
")",
";",
"}",
"$",
"ret",
"=",
"ob_get_contents",
"(",
")",
";",
"ob_end_clean",
"(",
")",
";",
"return",
"$",
"ret",
";",
"}"
] | Get sidebar from PHP
@api
@param string $sidebar
@param array $data
@return string | [
"Get",
"sidebar",
"from",
"PHP"
] | baaa1960193cffb5fa7c43c09114d6831764eede | https://github.com/timber/timber/blob/baaa1960193cffb5fa7c43c09114d6831764eede/lib/Timber.php#L456-L474 | train |
timber/timber | lib/Image/Operation.php | Operation.hexrgb | 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" => 0xFF & ($int >> 0x10), "green" => 0xFF & ($int >> 0x8), "blue" => 0xFF & $int);
} | php | 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" => 0xFF & ($int >> 0x10), "green" => 0xFF & ($int >> 0x8), "blue" => 0xFF & $int);
} | [
"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\"",
"=>",
"0xFF",
"&",
"(",
"$",
"int",
">>",
"0x10",
")",
",",
"\"green\"",
"=>",
"0xFF",
"&",
"(",
"$",
"int",
">>",
"0x8",
")",
",",
"\"blue\"",
"=>",
"0xFF",
"&",
"$",
"int",
")",
";",
"}"
] | Helper method to convert hex string to rgb array
@param string $hexstr hex color string (like '#FF1455')
@return array array('red', 'green', 'blue') to int
ex: array('red' => 255, 'green' => 20, 'blue' => 85); | [
"Helper",
"method",
"to",
"convert",
"hex",
"string",
"to",
"rgb",
"array"
] | baaa1960193cffb5fa7c43c09114d6831764eede | https://github.com/timber/timber/blob/baaa1960193cffb5fa7c43c09114d6831764eede/lib/Image/Operation.php#L43-L52 | train |
timber/timber | lib/Term.php | Term.get_posts | 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_string( $numberposts_or_args) && strstr( $numberposts_or_args, '=') ) {
$args = $numberposts_or_args;
$new_args = array();
parse_str($args, $new_args);
$args = $new_args;
$args['tax_query'] = $default_tax_query;
if ( !isset($args['post_type']) ) {
$args['post_type'] = 'any';
}
if ( class_exists($post_type_or_class) ) {
$post_class = $post_type_or_class;
}
} else if ( is_array( $numberposts_or_args) ) {
//they sent us an array already baked
$args = $numberposts_or_args;
if ( !isset($args['tax_query']) ) {
$args['tax_query'] = $default_tax_query;
}
if ( class_exists($post_type_or_class) ) {
$post_class = $post_type_or_class;
}
if ( !isset($args['post_type']) ) {
$args['post_type'] = 'any';
}
} else {
$args = array(
'numberposts' => $numberposts_or_args,
'tax_query' => $default_tax_query,
'post_type' => $post_type_or_class
);
}
return Timber::get_posts($args, $post_class);
} | php | 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_string( $numberposts_or_args) && strstr( $numberposts_or_args, '=') ) {
$args = $numberposts_or_args;
$new_args = array();
parse_str($args, $new_args);
$args = $new_args;
$args['tax_query'] = $default_tax_query;
if ( !isset($args['post_type']) ) {
$args['post_type'] = 'any';
}
if ( class_exists($post_type_or_class) ) {
$post_class = $post_type_or_class;
}
} else if ( is_array( $numberposts_or_args) ) {
//they sent us an array already baked
$args = $numberposts_or_args;
if ( !isset($args['tax_query']) ) {
$args['tax_query'] = $default_tax_query;
}
if ( class_exists($post_type_or_class) ) {
$post_class = $post_type_or_class;
}
if ( !isset($args['post_type']) ) {
$args['post_type'] = 'any';
}
} else {
$args = array(
'numberposts' => $numberposts_or_args,
'tax_query' => $default_tax_query,
'post_type' => $post_type_or_class
);
}
return Timber::get_posts($args, $post_class);
} | [
"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_string",
"(",
"$",
"numberposts_or_args",
")",
"&&",
"strstr",
"(",
"$",
"numberposts_or_args",
",",
"'='",
")",
")",
"{",
"$",
"args",
"=",
"$",
"numberposts_or_args",
";",
"$",
"new_args",
"=",
"array",
"(",
")",
";",
"parse_str",
"(",
"$",
"args",
",",
"$",
"new_args",
")",
";",
"$",
"args",
"=",
"$",
"new_args",
";",
"$",
"args",
"[",
"'tax_query'",
"]",
"=",
"$",
"default_tax_query",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"args",
"[",
"'post_type'",
"]",
")",
")",
"{",
"$",
"args",
"[",
"'post_type'",
"]",
"=",
"'any'",
";",
"}",
"if",
"(",
"class_exists",
"(",
"$",
"post_type_or_class",
")",
")",
"{",
"$",
"post_class",
"=",
"$",
"post_type_or_class",
";",
"}",
"}",
"else",
"if",
"(",
"is_array",
"(",
"$",
"numberposts_or_args",
")",
")",
"{",
"//they sent us an array already baked",
"$",
"args",
"=",
"$",
"numberposts_or_args",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"args",
"[",
"'tax_query'",
"]",
")",
")",
"{",
"$",
"args",
"[",
"'tax_query'",
"]",
"=",
"$",
"default_tax_query",
";",
"}",
"if",
"(",
"class_exists",
"(",
"$",
"post_type_or_class",
")",
")",
"{",
"$",
"post_class",
"=",
"$",
"post_type_or_class",
";",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"args",
"[",
"'post_type'",
"]",
")",
")",
"{",
"$",
"args",
"[",
"'post_type'",
"]",
"=",
"'any'",
";",
"}",
"}",
"else",
"{",
"$",
"args",
"=",
"array",
"(",
"'numberposts'",
"=>",
"$",
"numberposts_or_args",
",",
"'tax_query'",
"=>",
"$",
"default_tax_query",
",",
"'post_type'",
"=>",
"$",
"post_type_or_class",
")",
";",
"}",
"return",
"Timber",
"::",
"get_posts",
"(",
"$",
"args",
",",
"$",
"post_class",
")",
";",
"}"
] | Get posts that have the current term assigned.
@internal
@param int|array $numberposts_or_args Optional. Either the number of posts or an array of
arguments for the post query that this method is going.
to perform. Default `10`.
@param string $post_type_or_class Optional. Either the post type to get or the name of
post class to use for the returned posts. Default
`any`.
@param string $post_class Optional. The name of the post class to use for the
returned posts. Default `Timber\Post`.
@return array|bool|null | [
"Get",
"posts",
"that",
"have",
"the",
"current",
"term",
"assigned",
"."
] | baaa1960193cffb5fa7c43c09114d6831764eede | https://github.com/timber/timber/blob/baaa1960193cffb5fa7c43c09114d6831764eede/lib/Term.php#L264-L306 | train |
timber/timber | lib/QueryIterator.php | QueryIterator.fix_number_posts_wp_quirk | 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;
} | php | 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;
} | [
"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 | [
"get_posts",
"users",
"numberposts"
] | baaa1960193cffb5fa7c43c09114d6831764eede | https://github.com/timber/timber/blob/baaa1960193cffb5fa7c43c09114d6831764eede/lib/QueryIterator.php#L149-L155 | train |
timber/timber | lib/QueryIterator.php | QueryIterator.fix_cat_wp_quirk | 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;
} | php | 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;
} | [
"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... | [
"get_posts",
"uses",
"category",
"WP_Query",
"uses",
"cat",
".",
"Why?",
"who",
"knows",
"..."
] | baaa1960193cffb5fa7c43c09114d6831764eede | https://github.com/timber/timber/blob/baaa1960193cffb5fa7c43c09114d6831764eede/lib/QueryIterator.php#L158-L165 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.