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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
bestit/PHP_CodeSniffer | src/Standards/BestIt/CodeSniffer/AbstractFileDecorator.php | AbstractFileDecorator.addMessage | protected function addMessage($error, $message, $line, $column, $code, $data, $severity, $fixable)
{
return $this->__call(__FUNCTION__, func_get_args());
} | php | protected function addMessage($error, $message, $line, $column, $code, $data, $severity, $fixable)
{
return $this->__call(__FUNCTION__, func_get_args());
} | [
"protected",
"function",
"addMessage",
"(",
"$",
"error",
",",
"$",
"message",
",",
"$",
"line",
",",
"$",
"column",
",",
"$",
"code",
",",
"$",
"data",
",",
"$",
"severity",
",",
"$",
"fixable",
")",
"{",
"return",
"$",
"this",
"->",
"__call",
"("... | Adds an error to the error stack.
@param boolean $error Is this an error message?
@param string $message The text of the message.
@param int $line The line on which the message occurred.
@param int $column The column at which the message occurred.
@param string $code A violation code unique to the sniff message.
@param array $data Replacements for the message.
@param int $severity The severity level for this message. A value of 0
will be converted into the default severity level.
@param boolean $fixable Can the problem be fixed by the sniff?
@return boolean | [
"Adds",
"an",
"error",
"to",
"the",
"error",
"stack",
"."
] | a80e1f24642858a0ad20301661037c321128d021 | https://github.com/bestit/PHP_CodeSniffer/blob/a80e1f24642858a0ad20301661037c321128d021/src/Standards/BestIt/CodeSniffer/AbstractFileDecorator.php#L161-L164 | train |
bestit/PHP_CodeSniffer | src/Standards/BestIt/CodeSniffer/AbstractFileDecorator.php | AbstractFileDecorator.findFirstOnLine | public function findFirstOnLine($types, $start, $exclude = false, $value = null)
{
return $this->__call(__FUNCTION__, func_get_args());
} | php | public function findFirstOnLine($types, $start, $exclude = false, $value = null)
{
return $this->__call(__FUNCTION__, func_get_args());
} | [
"public",
"function",
"findFirstOnLine",
"(",
"$",
"types",
",",
"$",
"start",
",",
"$",
"exclude",
"=",
"false",
",",
"$",
"value",
"=",
"null",
")",
"{",
"return",
"$",
"this",
"->",
"__call",
"(",
"__FUNCTION__",
",",
"func_get_args",
"(",
")",
")",... | Returns the position of the first token on a line, matching given type.
Returns false if no token can be found.
@param int|array $types The type(s) of tokens to search for.
@param int $start The position to start searching from in the
token stack. The first token matching on
this line before this token will be returned.
@param bool $exclude If true, find the token that is NOT of
the types specified in $types.
@param string $value The value that the token must be equal to.
If value is omitted, tokens with any value will
be returned.
@return int | bool | [
"Returns",
"the",
"position",
"of",
"the",
"first",
"token",
"on",
"a",
"line",
"matching",
"given",
"type",
"."
] | a80e1f24642858a0ad20301661037c321128d021 | https://github.com/bestit/PHP_CodeSniffer/blob/a80e1f24642858a0ad20301661037c321128d021/src/Standards/BestIt/CodeSniffer/AbstractFileDecorator.php#L277-L280 | train |
bestit/PHP_CodeSniffer | src/Standards/BestIt/CodeSniffer/AbstractFileDecorator.php | AbstractFileDecorator.takeProperties | private function takeProperties(File $baseFile): void
{
$baseProps = get_object_vars($baseFile);
array_walk($baseProps, function ($value, $key) {
$this->$key = $value;
});
} | php | private function takeProperties(File $baseFile): void
{
$baseProps = get_object_vars($baseFile);
array_walk($baseProps, function ($value, $key) {
$this->$key = $value;
});
} | [
"private",
"function",
"takeProperties",
"(",
"File",
"$",
"baseFile",
")",
":",
"void",
"{",
"$",
"baseProps",
"=",
"get_object_vars",
"(",
"$",
"baseFile",
")",
";",
"array_walk",
"(",
"$",
"baseProps",
",",
"function",
"(",
"$",
"value",
",",
"$",
"ke... | We need to clone the properties of the base file to this. A magic getter on inherited props does not work.
@param File $baseFile
@return void | [
"We",
"need",
"to",
"clone",
"the",
"properties",
"of",
"the",
"base",
"file",
"to",
"this",
".",
"A",
"magic",
"getter",
"on",
"inherited",
"props",
"does",
"not",
"work",
"."
] | a80e1f24642858a0ad20301661037c321128d021 | https://github.com/bestit/PHP_CodeSniffer/blob/a80e1f24642858a0ad20301661037c321128d021/src/Standards/BestIt/CodeSniffer/AbstractFileDecorator.php#L761-L768 | train |
bestit/PHP_CodeSniffer | src/Standards/BestIt/CodeSniffer/Helper/LineHelper.php | LineHelper.removeLine | public function removeLine(int $line): void
{
foreach ($this->file->getTokens() as $tagPtr => $tagToken) {
if ($tagToken['line'] !== $line) {
continue;
}
$this->fixer->replaceToken($tagPtr, '');
if ($tagToken['line'] > $line) {
break;
}
}
} | php | public function removeLine(int $line): void
{
foreach ($this->file->getTokens() as $tagPtr => $tagToken) {
if ($tagToken['line'] !== $line) {
continue;
}
$this->fixer->replaceToken($tagPtr, '');
if ($tagToken['line'] > $line) {
break;
}
}
} | [
"public",
"function",
"removeLine",
"(",
"int",
"$",
"line",
")",
":",
"void",
"{",
"foreach",
"(",
"$",
"this",
"->",
"file",
"->",
"getTokens",
"(",
")",
"as",
"$",
"tagPtr",
"=>",
"$",
"tagToken",
")",
"{",
"if",
"(",
"$",
"tagToken",
"[",
"'lin... | Removes the given line.
@param int $line The line which is to be removed
@return void | [
"Removes",
"the",
"given",
"line",
"."
] | a80e1f24642858a0ad20301661037c321128d021 | https://github.com/bestit/PHP_CodeSniffer/blob/a80e1f24642858a0ad20301661037c321128d021/src/Standards/BestIt/CodeSniffer/Helper/LineHelper.php#L57-L70 | train |
bestit/PHP_CodeSniffer | src/Standards/BestIt/CodeSniffer/Helper/LineHelper.php | LineHelper.removeLines | public function removeLines(int $startLine, int $endLine): void
{
for ($line = $startLine; $line <= $endLine; $line++) {
$this->removeLine($line);
}
} | php | public function removeLines(int $startLine, int $endLine): void
{
for ($line = $startLine; $line <= $endLine; $line++) {
$this->removeLine($line);
}
} | [
"public",
"function",
"removeLines",
"(",
"int",
"$",
"startLine",
",",
"int",
"$",
"endLine",
")",
":",
"void",
"{",
"for",
"(",
"$",
"line",
"=",
"$",
"startLine",
";",
"$",
"line",
"<=",
"$",
"endLine",
";",
"$",
"line",
"++",
")",
"{",
"$",
"... | Removes lines by given start and end.
@param int $startLine The first line which is to be removed
@param int $endLine The last line which is to be removed
@return void | [
"Removes",
"lines",
"by",
"given",
"start",
"and",
"end",
"."
] | a80e1f24642858a0ad20301661037c321128d021 | https://github.com/bestit/PHP_CodeSniffer/blob/a80e1f24642858a0ad20301661037c321128d021/src/Standards/BestIt/CodeSniffer/Helper/LineHelper.php#L80-L85 | train |
bestit/PHP_CodeSniffer | src/Standards/BestIt/Sniffs/Comparisons/EqualOperatorSniff.php | EqualOperatorSniff.replaceToken | private function replaceToken(): void
{
$file = $this->getFile();
$file->fixer->beginChangeset();
$file->fixer->replaceToken($this->getStackPos(), '===');
$file->fixer->endChangeset();
} | php | private function replaceToken(): void
{
$file = $this->getFile();
$file->fixer->beginChangeset();
$file->fixer->replaceToken($this->getStackPos(), '===');
$file->fixer->endChangeset();
} | [
"private",
"function",
"replaceToken",
"(",
")",
":",
"void",
"{",
"$",
"file",
"=",
"$",
"this",
"->",
"getFile",
"(",
")",
";",
"$",
"file",
"->",
"fixer",
"->",
"beginChangeset",
"(",
")",
";",
"$",
"file",
"->",
"fixer",
"->",
"replaceToken",
"("... | Replace token with the T_IS_IDENTIAL token.
@return void | [
"Replace",
"token",
"with",
"the",
"T_IS_IDENTIAL",
"token",
"."
] | a80e1f24642858a0ad20301661037c321128d021 | https://github.com/bestit/PHP_CodeSniffer/blob/a80e1f24642858a0ad20301661037c321128d021/src/Standards/BestIt/Sniffs/Comparisons/EqualOperatorSniff.php#L88-L95 | train |
bestit/PHP_CodeSniffer | src/Standards/BestIt/Sniffs/DocTags/ReturnTagSniff.php | ReturnTagSniff.checkForMissingDesc | private function checkForMissingDesc(string $type, array $returnParts): void
{
if (!in_array($type, $this->excludedTypes) && (count($returnParts) <= 1) && $this->descAsWarning) {
throw (new CodeWarning(
static::CODE_MISSING_RETURN_DESC,
self::MESSAGE_MISSING_RETURN_DESC,
$this->stackPos
))->setToken($this->token);
}
} | php | private function checkForMissingDesc(string $type, array $returnParts): void
{
if (!in_array($type, $this->excludedTypes) && (count($returnParts) <= 1) && $this->descAsWarning) {
throw (new CodeWarning(
static::CODE_MISSING_RETURN_DESC,
self::MESSAGE_MISSING_RETURN_DESC,
$this->stackPos
))->setToken($this->token);
}
} | [
"private",
"function",
"checkForMissingDesc",
"(",
"string",
"$",
"type",
",",
"array",
"$",
"returnParts",
")",
":",
"void",
"{",
"if",
"(",
"!",
"in_array",
"(",
"$",
"type",
",",
"$",
"this",
"->",
"excludedTypes",
")",
"&&",
"(",
"count",
"(",
"$",... | Throws a code warning if you have no description.
@throws CodeWarning
@param string $type
@param array $returnParts
@return void | [
"Throws",
"a",
"code",
"warning",
"if",
"you",
"have",
"no",
"description",
"."
] | a80e1f24642858a0ad20301661037c321128d021 | https://github.com/bestit/PHP_CodeSniffer/blob/a80e1f24642858a0ad20301661037c321128d021/src/Standards/BestIt/Sniffs/DocTags/ReturnTagSniff.php#L67-L76 | train |
bestit/PHP_CodeSniffer | src/Standards/BestIt/Sniffs/DocTags/ReturnTagSniff.php | ReturnTagSniff.checkForMixedType | private function checkForMixedType(string $type): self
{
if (strtolower($type) === 'mixed') {
throw (new CodeWarning(static::CODE_MIXED_TYPE, self::MESSAGE_MIXED_TYPE, $this->stackPos))
->setToken($this->token);
}
return $this;
} | php | private function checkForMixedType(string $type): self
{
if (strtolower($type) === 'mixed') {
throw (new CodeWarning(static::CODE_MIXED_TYPE, self::MESSAGE_MIXED_TYPE, $this->stackPos))
->setToken($this->token);
}
return $this;
} | [
"private",
"function",
"checkForMixedType",
"(",
"string",
"$",
"type",
")",
":",
"self",
"{",
"if",
"(",
"strtolower",
"(",
"$",
"type",
")",
"===",
"'mixed'",
")",
"{",
"throw",
"(",
"new",
"CodeWarning",
"(",
"static",
"::",
"CODE_MIXED_TYPE",
",",
"s... | Throws a warning if you declare a mixed type.
@param string $type
@throws CodeWarning
@return $this | [
"Throws",
"a",
"warning",
"if",
"you",
"declare",
"a",
"mixed",
"type",
"."
] | a80e1f24642858a0ad20301661037c321128d021 | https://github.com/bestit/PHP_CodeSniffer/blob/a80e1f24642858a0ad20301661037c321128d021/src/Standards/BestIt/Sniffs/DocTags/ReturnTagSniff.php#L86-L94 | train |
bestit/PHP_CodeSniffer | src/Standards/BestIt/Sniffs/DocPosProviderTrait.php | DocPosProviderTrait.getDocCommentPos | protected function getDocCommentPos(): ?int
{
if ($this->docCommentPos === -1) {
$this->docCommentPos = $this->loadDocCommentPos();
}
return $this->docCommentPos;
} | php | protected function getDocCommentPos(): ?int
{
if ($this->docCommentPos === -1) {
$this->docCommentPos = $this->loadDocCommentPos();
}
return $this->docCommentPos;
} | [
"protected",
"function",
"getDocCommentPos",
"(",
")",
":",
"?",
"int",
"{",
"if",
"(",
"$",
"this",
"->",
"docCommentPos",
"===",
"-",
"1",
")",
"{",
"$",
"this",
"->",
"docCommentPos",
"=",
"$",
"this",
"->",
"loadDocCommentPos",
"(",
")",
";",
"}",
... | Returns the position of the doc block if there is one.
@return int|null | [
"Returns",
"the",
"position",
"of",
"the",
"doc",
"block",
"if",
"there",
"is",
"one",
"."
] | a80e1f24642858a0ad20301661037c321128d021 | https://github.com/bestit/PHP_CodeSniffer/blob/a80e1f24642858a0ad20301661037c321128d021/src/Standards/BestIt/Sniffs/DocPosProviderTrait.php#L37-L44 | train |
bestit/PHP_CodeSniffer | src/Standards/BestIt/Sniffs/DocPosProviderTrait.php | DocPosProviderTrait.getDocHelper | protected function getDocHelper(): DocHelper
{
if ($this->docHelper === null) {
$this->docHelper = new DocHelper($this->getFile()->getBaseFile(), $this->getStackPos());
}
return $this->docHelper;
} | php | protected function getDocHelper(): DocHelper
{
if ($this->docHelper === null) {
$this->docHelper = new DocHelper($this->getFile()->getBaseFile(), $this->getStackPos());
}
return $this->docHelper;
} | [
"protected",
"function",
"getDocHelper",
"(",
")",
":",
"DocHelper",
"{",
"if",
"(",
"$",
"this",
"->",
"docHelper",
"===",
"null",
")",
"{",
"$",
"this",
"->",
"docHelper",
"=",
"new",
"DocHelper",
"(",
"$",
"this",
"->",
"getFile",
"(",
")",
"->",
... | Returns the helper for the doc block.
@return DocHelper | [
"Returns",
"the",
"helper",
"for",
"the",
"doc",
"block",
"."
] | a80e1f24642858a0ad20301661037c321128d021 | https://github.com/bestit/PHP_CodeSniffer/blob/a80e1f24642858a0ad20301661037c321128d021/src/Standards/BestIt/Sniffs/DocPosProviderTrait.php#L51-L58 | train |
bestit/PHP_CodeSniffer | src/Standards/BestIt/Sniffs/DocPosProviderTrait.php | DocPosProviderTrait.loadDocCommentPos | protected function loadDocCommentPos(): ?int
{
$docHelper = $this->getDocHelper();
return $docHelper->hasDocBlock() ? $docHelper->getBlockStartPosition() : null;
} | php | protected function loadDocCommentPos(): ?int
{
$docHelper = $this->getDocHelper();
return $docHelper->hasDocBlock() ? $docHelper->getBlockStartPosition() : null;
} | [
"protected",
"function",
"loadDocCommentPos",
"(",
")",
":",
"?",
"int",
"{",
"$",
"docHelper",
"=",
"$",
"this",
"->",
"getDocHelper",
"(",
")",
";",
"return",
"$",
"docHelper",
"->",
"hasDocBlock",
"(",
")",
"?",
"$",
"docHelper",
"->",
"getBlockStartPos... | Loads the position of the doc comment.
@return int|null | [
"Loads",
"the",
"position",
"of",
"the",
"doc",
"comment",
"."
] | a80e1f24642858a0ad20301661037c321128d021 | https://github.com/bestit/PHP_CodeSniffer/blob/a80e1f24642858a0ad20301661037c321128d021/src/Standards/BestIt/Sniffs/DocPosProviderTrait.php#L79-L84 | train |
bestit/PHP_CodeSniffer | src/Standards/BestIt/Sniffs/DocTags/PackageTagSniff.php | PackageTagSniff.fixWrongPackage | private function fixWrongPackage(string $currentNamespace): void
{
$this->file->getFixer()->replaceToken(
TokenHelper::findNext($this->file->getBaseFile(), [T_DOC_COMMENT_STRING], $this->stackPos),
$currentNamespace
);
} | php | private function fixWrongPackage(string $currentNamespace): void
{
$this->file->getFixer()->replaceToken(
TokenHelper::findNext($this->file->getBaseFile(), [T_DOC_COMMENT_STRING], $this->stackPos),
$currentNamespace
);
} | [
"private",
"function",
"fixWrongPackage",
"(",
"string",
"$",
"currentNamespace",
")",
":",
"void",
"{",
"$",
"this",
"->",
"file",
"->",
"getFixer",
"(",
")",
"->",
"replaceToken",
"(",
"TokenHelper",
"::",
"findNext",
"(",
"$",
"this",
"->",
"file",
"->"... | Fixes the wrong package and replaces it with the correct namespace.
@param string $currentNamespace
@return void | [
"Fixes",
"the",
"wrong",
"package",
"and",
"replaces",
"it",
"with",
"the",
"correct",
"namespace",
"."
] | a80e1f24642858a0ad20301661037c321128d021 | https://github.com/bestit/PHP_CodeSniffer/blob/a80e1f24642858a0ad20301661037c321128d021/src/Standards/BestIt/Sniffs/DocTags/PackageTagSniff.php#L37-L43 | train |
bestit/PHP_CodeSniffer | src/Standards/BestIt/CodeSniffer/Helper/DocHelper.php | DocHelper.getBlockEndPosition | public function getBlockEndPosition(): ?int
{
if ($this->blockEndPosition === false) {
$this->blockEndPosition = $this->loadBlockEndPosition();
}
return $this->blockEndPosition;
} | php | public function getBlockEndPosition(): ?int
{
if ($this->blockEndPosition === false) {
$this->blockEndPosition = $this->loadBlockEndPosition();
}
return $this->blockEndPosition;
} | [
"public",
"function",
"getBlockEndPosition",
"(",
")",
":",
"?",
"int",
"{",
"if",
"(",
"$",
"this",
"->",
"blockEndPosition",
"===",
"false",
")",
"{",
"$",
"this",
"->",
"blockEndPosition",
"=",
"$",
"this",
"->",
"loadBlockEndPosition",
"(",
")",
";",
... | Returns position to the class comment end.
@return int|null Position to the class comment end. | [
"Returns",
"position",
"to",
"the",
"class",
"comment",
"end",
"."
] | a80e1f24642858a0ad20301661037c321128d021 | https://github.com/bestit/PHP_CodeSniffer/blob/a80e1f24642858a0ad20301661037c321128d021/src/Standards/BestIt/CodeSniffer/Helper/DocHelper.php#L67-L74 | train |
bestit/PHP_CodeSniffer | src/Standards/BestIt/CodeSniffer/Helper/DocHelper.php | DocHelper.getBlockEndToken | public function getBlockEndToken(): array
{
if (!$this->hasDocBlock()) {
throw new DomainException(
sprintf('Missing doc block for position %s of file %s.', $this->stackPos, $this->file->getFilename())
);
}
return $this->tokens[$this->getBlockEndPosition()];
} | php | public function getBlockEndToken(): array
{
if (!$this->hasDocBlock()) {
throw new DomainException(
sprintf('Missing doc block for position %s of file %s.', $this->stackPos, $this->file->getFilename())
);
}
return $this->tokens[$this->getBlockEndPosition()];
} | [
"public",
"function",
"getBlockEndToken",
"(",
")",
":",
"array",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"hasDocBlock",
"(",
")",
")",
"{",
"throw",
"new",
"DomainException",
"(",
"sprintf",
"(",
"'Missing doc block for position %s of file %s.'",
",",
"$",
"t... | Returns token data of the evaluated class comment end.
@return array Token data of the comment end. | [
"Returns",
"token",
"data",
"of",
"the",
"evaluated",
"class",
"comment",
"end",
"."
] | a80e1f24642858a0ad20301661037c321128d021 | https://github.com/bestit/PHP_CodeSniffer/blob/a80e1f24642858a0ad20301661037c321128d021/src/Standards/BestIt/CodeSniffer/Helper/DocHelper.php#L81-L90 | train |
bestit/PHP_CodeSniffer | src/Standards/BestIt/CodeSniffer/Helper/DocHelper.php | DocHelper.isMultiLine | public function isMultiLine(): bool
{
$openingToken = $this->getBlockStartToken();
$closingToken = $this->getBlockEndToken();
return $openingToken['line'] < $closingToken['line'];
} | php | public function isMultiLine(): bool
{
$openingToken = $this->getBlockStartToken();
$closingToken = $this->getBlockEndToken();
return $openingToken['line'] < $closingToken['line'];
} | [
"public",
"function",
"isMultiLine",
"(",
")",
":",
"bool",
"{",
"$",
"openingToken",
"=",
"$",
"this",
"->",
"getBlockStartToken",
"(",
")",
";",
"$",
"closingToken",
"=",
"$",
"this",
"->",
"getBlockEndToken",
"(",
")",
";",
"return",
"$",
"openingToken"... | Returns true if this doc block is a multi line comment.
@return bool | [
"Returns",
"true",
"if",
"this",
"doc",
"block",
"is",
"a",
"multi",
"line",
"comment",
"."
] | a80e1f24642858a0ad20301661037c321128d021 | https://github.com/bestit/PHP_CodeSniffer/blob/a80e1f24642858a0ad20301661037c321128d021/src/Standards/BestIt/CodeSniffer/Helper/DocHelper.php#L131-L137 | train |
bestit/PHP_CodeSniffer | src/Standards/BestIt/CodeSniffer/Helper/DocHelper.php | DocHelper.loadBlockEndPosition | private function loadBlockEndPosition(): ?int
{
$endPos = $this->file->findPrevious(
[T_DOC_COMMENT_CLOSE_TAG],
$this->stackPos - 1,
// Search till the next method, property, etc ...
TokenHelper::findPreviousExcluding(
$this->file,
TokenHelper::$ineffectiveTokenCodes + Tokens::$methodPrefixes,
$this->stackPos - 1
)
);
return ((int) $endPos) > 0 ? $endPos : null;
} | php | private function loadBlockEndPosition(): ?int
{
$endPos = $this->file->findPrevious(
[T_DOC_COMMENT_CLOSE_TAG],
$this->stackPos - 1,
// Search till the next method, property, etc ...
TokenHelper::findPreviousExcluding(
$this->file,
TokenHelper::$ineffectiveTokenCodes + Tokens::$methodPrefixes,
$this->stackPos - 1
)
);
return ((int) $endPos) > 0 ? $endPos : null;
} | [
"private",
"function",
"loadBlockEndPosition",
"(",
")",
":",
"?",
"int",
"{",
"$",
"endPos",
"=",
"$",
"this",
"->",
"file",
"->",
"findPrevious",
"(",
"[",
"T_DOC_COMMENT_CLOSE_TAG",
"]",
",",
"$",
"this",
"->",
"stackPos",
"-",
"1",
",",
"// Search till... | Returns the position of the token for the doc block end.
@return int|null | [
"Returns",
"the",
"position",
"of",
"the",
"token",
"for",
"the",
"doc",
"block",
"end",
"."
] | a80e1f24642858a0ad20301661037c321128d021 | https://github.com/bestit/PHP_CodeSniffer/blob/a80e1f24642858a0ad20301661037c321128d021/src/Standards/BestIt/CodeSniffer/Helper/DocHelper.php#L144-L158 | train |
bestit/PHP_CodeSniffer | src/Standards/BestIt/Sniffs/Commenting/EmptyLinesDocSniff.php | EmptyLinesDocSniff.removeUnnecessaryLines | private function removeUnnecessaryLines(File $phpcsFile, array $nextToken, array $currentToken): void
{
$movement = 2;
if ($nextToken['code'] === T_DOC_COMMENT_CLOSE_TAG) {
$movement = 1;
}
$phpcsFile->fixer->beginChangeset();
(new LineHelper($this->file))->removeLines(
$currentToken['line'] + $movement,
$nextToken['line'] - 1
);
$phpcsFile->fixer->endChangeset();
} | php | private function removeUnnecessaryLines(File $phpcsFile, array $nextToken, array $currentToken): void
{
$movement = 2;
if ($nextToken['code'] === T_DOC_COMMENT_CLOSE_TAG) {
$movement = 1;
}
$phpcsFile->fixer->beginChangeset();
(new LineHelper($this->file))->removeLines(
$currentToken['line'] + $movement,
$nextToken['line'] - 1
);
$phpcsFile->fixer->endChangeset();
} | [
"private",
"function",
"removeUnnecessaryLines",
"(",
"File",
"$",
"phpcsFile",
",",
"array",
"$",
"nextToken",
",",
"array",
"$",
"currentToken",
")",
":",
"void",
"{",
"$",
"movement",
"=",
"2",
";",
"if",
"(",
"$",
"nextToken",
"[",
"'code'",
"]",
"==... | Remove unnecessary lines from doc block.
@param File $phpcsFile
@param array $nextToken
@param array $currentToken
@return void | [
"Remove",
"unnecessary",
"lines",
"from",
"doc",
"block",
"."
] | a80e1f24642858a0ad20301661037c321128d021 | https://github.com/bestit/PHP_CodeSniffer/blob/a80e1f24642858a0ad20301661037c321128d021/src/Standards/BestIt/Sniffs/Commenting/EmptyLinesDocSniff.php#L74-L90 | train |
bestit/PHP_CodeSniffer | src/Standards/BestIt/Sniffs/Commenting/EmptyLinesDocSniff.php | EmptyLinesDocSniff.searchEmptyLines | private function searchEmptyLines(File $phpcsFile, int $searchPosition): void
{
$endOfDoc = $phpcsFile->findEndOfStatement($searchPosition);
do {
$currentToken = $phpcsFile->getTokens()[$searchPosition];
$nextTokenPosition = (int) $phpcsFile->findNext(
[T_DOC_COMMENT_WHITESPACE, T_DOC_COMMENT_STAR],
$searchPosition + 1,
$endOfDoc,
true
);
if ($hasToken = ($nextTokenPosition > 0)) {
$nextToken = $phpcsFile->getTokens()[$nextTokenPosition];
$hasTooManyLines = ($nextToken['line'] - $currentToken['line']) > 2;
if ($hasTooManyLines) {
$isFixing = $phpcsFile->addFixableError(
self::ERROR_EMPTY_LINES_FOUND,
$nextTokenPosition,
static::CODE_EMPTY_LINES_FOUND
);
if ($isFixing) {
$this->removeUnnecessaryLines($phpcsFile, $nextToken, $currentToken);
}
}
$phpcsFile->recordMetric(
$searchPosition,
'DocBlock has too many lines',
$hasTooManyLines ? 'yes' : 'no'
);
$searchPosition = $nextTokenPosition;
}
} while ($hasToken);
} | php | private function searchEmptyLines(File $phpcsFile, int $searchPosition): void
{
$endOfDoc = $phpcsFile->findEndOfStatement($searchPosition);
do {
$currentToken = $phpcsFile->getTokens()[$searchPosition];
$nextTokenPosition = (int) $phpcsFile->findNext(
[T_DOC_COMMENT_WHITESPACE, T_DOC_COMMENT_STAR],
$searchPosition + 1,
$endOfDoc,
true
);
if ($hasToken = ($nextTokenPosition > 0)) {
$nextToken = $phpcsFile->getTokens()[$nextTokenPosition];
$hasTooManyLines = ($nextToken['line'] - $currentToken['line']) > 2;
if ($hasTooManyLines) {
$isFixing = $phpcsFile->addFixableError(
self::ERROR_EMPTY_LINES_FOUND,
$nextTokenPosition,
static::CODE_EMPTY_LINES_FOUND
);
if ($isFixing) {
$this->removeUnnecessaryLines($phpcsFile, $nextToken, $currentToken);
}
}
$phpcsFile->recordMetric(
$searchPosition,
'DocBlock has too many lines',
$hasTooManyLines ? 'yes' : 'no'
);
$searchPosition = $nextTokenPosition;
}
} while ($hasToken);
} | [
"private",
"function",
"searchEmptyLines",
"(",
"File",
"$",
"phpcsFile",
",",
"int",
"$",
"searchPosition",
")",
":",
"void",
"{",
"$",
"endOfDoc",
"=",
"$",
"phpcsFile",
"->",
"findEndOfStatement",
"(",
"$",
"searchPosition",
")",
";",
"do",
"{",
"$",
"c... | Process method for tokens within scope and also outside scope.
@param File $phpcsFile The sniffed file.
@param int $searchPosition
@return void | [
"Process",
"method",
"for",
"tokens",
"within",
"scope",
"and",
"also",
"outside",
"scope",
"."
] | a80e1f24642858a0ad20301661037c321128d021 | https://github.com/bestit/PHP_CodeSniffer/blob/a80e1f24642858a0ad20301661037c321128d021/src/Standards/BestIt/Sniffs/Commenting/EmptyLinesDocSniff.php#L100-L138 | train |
bestit/PHP_CodeSniffer | src/Standards/BestIt/Sniffs/Formatting/SpaceAroundConcatSniff.php | SpaceAroundConcatSniff.fixDefaultProblem | protected function fixDefaultProblem(CodeWarning $warning): void
{
$newContent = '';
if (!$this->prevIsWhitespace) {
$newContent = ' ';
}
$newContent .= '.';
if (!$this->nextIsWhitespace) {
$newContent .= ' ';
}
$fixer = $this->getFile()->fixer;
$fixer->beginChangeset();
$fixer->replaceToken($this->stackPos, $newContent);
$fixer->endChangeset();
} | php | protected function fixDefaultProblem(CodeWarning $warning): void
{
$newContent = '';
if (!$this->prevIsWhitespace) {
$newContent = ' ';
}
$newContent .= '.';
if (!$this->nextIsWhitespace) {
$newContent .= ' ';
}
$fixer = $this->getFile()->fixer;
$fixer->beginChangeset();
$fixer->replaceToken($this->stackPos, $newContent);
$fixer->endChangeset();
} | [
"protected",
"function",
"fixDefaultProblem",
"(",
"CodeWarning",
"$",
"warning",
")",
":",
"void",
"{",
"$",
"newContent",
"=",
"''",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"prevIsWhitespace",
")",
"{",
"$",
"newContent",
"=",
"' '",
";",
"}",
"$",
"... | Adds whitespace around the concats.
@param CodeWarning $warning
@return void | [
"Adds",
"whitespace",
"around",
"the",
"concats",
"."
] | a80e1f24642858a0ad20301661037c321128d021 | https://github.com/bestit/PHP_CodeSniffer/blob/a80e1f24642858a0ad20301661037c321128d021/src/Standards/BestIt/Sniffs/Formatting/SpaceAroundConcatSniff.php#L56-L75 | train |
helsingborg-stad/Municipio | library/Theme/ColorScheme.php | ColorScheme.colorPickerDefaultPalette | public function colorPickerDefaultPalette() {
if (!get_field('color_scheme', 'options')) {
return;
}
if (!get_option($this->optionName) || !is_array(get_option($this->optionName)) || empty(get_option($this->optionName))) {
$this->getRemoteColorScheme(get_field('color_scheme', 'options'));
}
$colors = (array) apply_filters( 'Municipio/Theme/ColorPickerDefaultPalette', get_option($this->optionName));
wp_localize_script( 'helsingborg-se-admin', 'themeColorPalette', [
'colors' => $colors,
]);
} | php | public function colorPickerDefaultPalette() {
if (!get_field('color_scheme', 'options')) {
return;
}
if (!get_option($this->optionName) || !is_array(get_option($this->optionName)) || empty(get_option($this->optionName))) {
$this->getRemoteColorScheme(get_field('color_scheme', 'options'));
}
$colors = (array) apply_filters( 'Municipio/Theme/ColorPickerDefaultPalette', get_option($this->optionName));
wp_localize_script( 'helsingborg-se-admin', 'themeColorPalette', [
'colors' => $colors,
]);
} | [
"public",
"function",
"colorPickerDefaultPalette",
"(",
")",
"{",
"if",
"(",
"!",
"get_field",
"(",
"'color_scheme'",
",",
"'options'",
")",
")",
"{",
"return",
";",
"}",
"if",
"(",
"!",
"get_option",
"(",
"$",
"this",
"->",
"optionName",
")",
"||",
"!",... | Localize theme colors to set color picker default colors
@return void | [
"Localize",
"theme",
"colors",
"to",
"set",
"color",
"picker",
"default",
"colors"
] | 923ca84eafa775237b97221e73a9b381fa6ddcba | https://github.com/helsingborg-stad/Municipio/blob/923ca84eafa775237b97221e73a9b381fa6ddcba/library/Theme/ColorScheme.php#L24-L39 | train |
helsingborg-stad/Municipio | library/Theme/ColorScheme.php | ColorScheme.getRemoteColorScheme | public function getRemoteColorScheme($manifestId = "") : bool
{
if (!defined('MUNICIPIO_STYLEGUIDE_URI')) {
return false;
}
if (empty($manifestId)) {
$manifestId = apply_filters('Municipio/theme/key', get_field('color_scheme', 'option'));
}
$args = (defined('DEV_MODE') && DEV_MODE == true) ? ['sslverify' => false] : array();
//Get remote data
$request = wp_remote_get("https:" . MUNICIPIO_STYLEGUIDE_URI . "vars/" . $manifestId . '.json', $args);
//Store if valid response
if (wp_remote_retrieve_response_code($request) == 200) {
if (!empty($response = json_decode(wp_remote_retrieve_body($request)))) {
$this->storeColorScheme($response);
}
return true;
}
//Not updated
return false;
} | php | public function getRemoteColorScheme($manifestId = "") : bool
{
if (!defined('MUNICIPIO_STYLEGUIDE_URI')) {
return false;
}
if (empty($manifestId)) {
$manifestId = apply_filters('Municipio/theme/key', get_field('color_scheme', 'option'));
}
$args = (defined('DEV_MODE') && DEV_MODE == true) ? ['sslverify' => false] : array();
//Get remote data
$request = wp_remote_get("https:" . MUNICIPIO_STYLEGUIDE_URI . "vars/" . $manifestId . '.json', $args);
//Store if valid response
if (wp_remote_retrieve_response_code($request) == 200) {
if (!empty($response = json_decode(wp_remote_retrieve_body($request)))) {
$this->storeColorScheme($response);
}
return true;
}
//Not updated
return false;
} | [
"public",
"function",
"getRemoteColorScheme",
"(",
"$",
"manifestId",
"=",
"\"\"",
")",
":",
"bool",
"{",
"if",
"(",
"!",
"defined",
"(",
"'MUNICIPIO_STYLEGUIDE_URI'",
")",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"empty",
"(",
"$",
"manifestId",
... | Get remote colorsheme from styleguide etc
@param string $manifestId. A identifier that represents the id of the theme configuration (filename on server)
@return bool | [
"Get",
"remote",
"colorsheme",
"from",
"styleguide",
"etc"
] | 923ca84eafa775237b97221e73a9b381fa6ddcba | https://github.com/helsingborg-stad/Municipio/blob/923ca84eafa775237b97221e73a9b381fa6ddcba/library/Theme/ColorScheme.php#L46-L72 | train |
helsingborg-stad/Municipio | library/Theme/ColorScheme.php | ColorScheme.storeColorScheme | public function storeColorScheme($colors) : bool
{
if (!is_array($colors) && !is_object($colors)) {
$colors = array();
}
return update_option($this->optionName, (array) $this->sanitizeColorSheme($colors), false);
} | php | public function storeColorScheme($colors) : bool
{
if (!is_array($colors) && !is_object($colors)) {
$colors = array();
}
return update_option($this->optionName, (array) $this->sanitizeColorSheme($colors), false);
} | [
"public",
"function",
"storeColorScheme",
"(",
"$",
"colors",
")",
":",
"bool",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"colors",
")",
"&&",
"!",
"is_object",
"(",
"$",
"colors",
")",
")",
"{",
"$",
"colors",
"=",
"array",
"(",
")",
";",
"}",
... | Stores the colorsheme details in the database for use by other plugins
@param string $colors. Contains a flat array of colors HEX to store.
@return bool | [
"Stores",
"the",
"colorsheme",
"details",
"in",
"the",
"database",
"for",
"use",
"by",
"other",
"plugins"
] | 923ca84eafa775237b97221e73a9b381fa6ddcba | https://github.com/helsingborg-stad/Municipio/blob/923ca84eafa775237b97221e73a9b381fa6ddcba/library/Theme/ColorScheme.php#L80-L87 | train |
helsingborg-stad/Municipio | library/Theme/ColorScheme.php | ColorScheme.sanitizeColorSheme | public function sanitizeColorSheme($colors)
{
//Make array keyless
$colors = array_values(array_unique((array) $colors));
//Check if value is valid HEX
foreach ($colors as $colorKey => $color) {
if (preg_match('/^#[a-f0-9]{6}$/i', $color)) {
continue;
}
unset($colors[$colorKey]);
}
//Sort (base colors at the end)
usort($colors, function ($a, $b) {
return strlen($b)-strlen($a);
});
return $colors;
} | php | public function sanitizeColorSheme($colors)
{
//Make array keyless
$colors = array_values(array_unique((array) $colors));
//Check if value is valid HEX
foreach ($colors as $colorKey => $color) {
if (preg_match('/^#[a-f0-9]{6}$/i', $color)) {
continue;
}
unset($colors[$colorKey]);
}
//Sort (base colors at the end)
usort($colors, function ($a, $b) {
return strlen($b)-strlen($a);
});
return $colors;
} | [
"public",
"function",
"sanitizeColorSheme",
"(",
"$",
"colors",
")",
"{",
"//Make array keyless",
"$",
"colors",
"=",
"array_values",
"(",
"array_unique",
"(",
"(",
"array",
")",
"$",
"colors",
")",
")",
";",
"//Check if value is valid HEX",
"foreach",
"(",
"$",... | Remove duplicates etc and make the array stored keyless
@param array/object $colors A unsanitized arry of colors (must be flat)
@return array | [
"Remove",
"duplicates",
"etc",
"and",
"make",
"the",
"array",
"stored",
"keyless"
] | 923ca84eafa775237b97221e73a9b381fa6ddcba | https://github.com/helsingborg-stad/Municipio/blob/923ca84eafa775237b97221e73a9b381fa6ddcba/library/Theme/ColorScheme.php#L105-L125 | train |
helsingborg-stad/Municipio | library/Helper/Html.php | Html.getHtmlTags | public static function getHtmlTags($content, $closeTags = true)
{
if ($closeTags == true) {
$re = '@<[^>]*>@';
} else {
$re = '@<[^>/]*>@';
}
preg_match_all($re, $content, $matches, PREG_SET_ORDER, 0);
if (isset($matches) && !empty($matches)) {
$tags = array();
foreach ($matches as $match) {
$tags[] = $match[0];
}
$tags = array_unique($tags);
return $tags;
}
return;
} | php | public static function getHtmlTags($content, $closeTags = true)
{
if ($closeTags == true) {
$re = '@<[^>]*>@';
} else {
$re = '@<[^>/]*>@';
}
preg_match_all($re, $content, $matches, PREG_SET_ORDER, 0);
if (isset($matches) && !empty($matches)) {
$tags = array();
foreach ($matches as $match) {
$tags[] = $match[0];
}
$tags = array_unique($tags);
return $tags;
}
return;
} | [
"public",
"static",
"function",
"getHtmlTags",
"(",
"$",
"content",
",",
"$",
"closeTags",
"=",
"true",
")",
"{",
"if",
"(",
"$",
"closeTags",
"==",
"true",
")",
"{",
"$",
"re",
"=",
"'@<[^>]*>@'",
";",
"}",
"else",
"{",
"$",
"re",
"=",
"'@<[^>/]*>@'... | Get HTML Tags
@param string $content String to get HTML tags from
@param boolean $closeTags Set to false to exclude closing tags
@return array Htmltags | [
"Get",
"HTML",
"Tags"
] | 923ca84eafa775237b97221e73a9b381fa6ddcba | https://github.com/helsingborg-stad/Municipio/blob/923ca84eafa775237b97221e73a9b381fa6ddcba/library/Helper/Html.php#L13-L35 | train |
helsingborg-stad/Municipio | library/Helper/Html.php | Html.attributesToString | public static function attributesToString($attributesArray)
{
if (!is_array($attributesArray) || empty($attributesArray)) {
return false;
}
$attributes = array();
foreach ($attributesArray as $attribute => $value) {
if (!is_array($value) && !is_string($value) || !$value || empty($value)) {
continue;
}
$values = (is_array($value)) ? implode(' ', array_unique($value)) : $value;
$attributes[] = $attribute . '="' . $values . '"';
}
return implode(' ', $attributes);
} | php | public static function attributesToString($attributesArray)
{
if (!is_array($attributesArray) || empty($attributesArray)) {
return false;
}
$attributes = array();
foreach ($attributesArray as $attribute => $value) {
if (!is_array($value) && !is_string($value) || !$value || empty($value)) {
continue;
}
$values = (is_array($value)) ? implode(' ', array_unique($value)) : $value;
$attributes[] = $attribute . '="' . $values . '"';
}
return implode(' ', $attributes);
} | [
"public",
"static",
"function",
"attributesToString",
"(",
"$",
"attributesArray",
")",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"attributesArray",
")",
"||",
"empty",
"(",
"$",
"attributesArray",
")",
")",
"{",
"return",
"false",
";",
"}",
"$",
"attribu... | Turn an array of HTML attributes into a string
@param string $content String to get HTML attributes from
@return array Attributes | [
"Turn",
"an",
"array",
"of",
"HTML",
"attributes",
"into",
"a",
"string"
] | 923ca84eafa775237b97221e73a9b381fa6ddcba | https://github.com/helsingborg-stad/Municipio/blob/923ca84eafa775237b97221e73a9b381fa6ddcba/library/Helper/Html.php#L42-L60 | train |
helsingborg-stad/Municipio | library/Helper/Html.php | Html.getHtmlAttributes | public static function getHtmlAttributes($content)
{
$content = self::getHtmlTags($content, false);
if (!is_array($content) || empty($content)) {
return;
}
$content = implode($content);
$re = '@(\s+)(\S+)=["\']?((?:.(?!["\']?\s+(?:\S+)=|[>]))+.)["\']?@';
preg_match_all($re, $content, $matches, PREG_SET_ORDER, 0);
$atts = array();
if ($matches) {
foreach ($matches as $match) {
$atts[$match[2]] = $match[0];
}
return $atts;
}
return;
} | php | public static function getHtmlAttributes($content)
{
$content = self::getHtmlTags($content, false);
if (!is_array($content) || empty($content)) {
return;
}
$content = implode($content);
$re = '@(\s+)(\S+)=["\']?((?:.(?!["\']?\s+(?:\S+)=|[>]))+.)["\']?@';
preg_match_all($re, $content, $matches, PREG_SET_ORDER, 0);
$atts = array();
if ($matches) {
foreach ($matches as $match) {
$atts[$match[2]] = $match[0];
}
return $atts;
}
return;
} | [
"public",
"static",
"function",
"getHtmlAttributes",
"(",
"$",
"content",
")",
"{",
"$",
"content",
"=",
"self",
"::",
"getHtmlTags",
"(",
"$",
"content",
",",
"false",
")",
";",
"if",
"(",
"!",
"is_array",
"(",
"$",
"content",
")",
"||",
"empty",
"(",... | Get HTML attributes from string
@param string $content String to get HTML attributes from
@return array Attributes | [
"Get",
"HTML",
"attributes",
"from",
"string"
] | 923ca84eafa775237b97221e73a9b381fa6ddcba | https://github.com/helsingborg-stad/Municipio/blob/923ca84eafa775237b97221e73a9b381fa6ddcba/library/Helper/Html.php#L67-L91 | train |
helsingborg-stad/Municipio | library/Helper/Html.php | Html.stripTagsAndAtts | public static function stripTagsAndAtts($content, $allowedTags = '', $allowedAtts = '')
{
if (isset($allowedTags) && is_array($allowedTags)) {
$content = strip_tags($content, implode($allowedTags));
} else {
$content = strip_tags($content);
}
//Strip attributes
$atts = \Municipio\Helper\Html::getHtmlAttributes($content);
if ($atts && !empty($atts)) {
if (isset($allowedAtts) && is_array($allowedAtts)) {
foreach ($allowedAtts as $attribute) {
unset($atts[$attribute]);
}
}
foreach ($atts as $att) {
$content = str_replace($att, "", $content);
}
}
return $content;
} | php | public static function stripTagsAndAtts($content, $allowedTags = '', $allowedAtts = '')
{
if (isset($allowedTags) && is_array($allowedTags)) {
$content = strip_tags($content, implode($allowedTags));
} else {
$content = strip_tags($content);
}
//Strip attributes
$atts = \Municipio\Helper\Html::getHtmlAttributes($content);
if ($atts && !empty($atts)) {
if (isset($allowedAtts) && is_array($allowedAtts)) {
foreach ($allowedAtts as $attribute) {
unset($atts[$attribute]);
}
}
foreach ($atts as $att) {
$content = str_replace($att, "", $content);
}
}
return $content;
} | [
"public",
"static",
"function",
"stripTagsAndAtts",
"(",
"$",
"content",
",",
"$",
"allowedTags",
"=",
"''",
",",
"$",
"allowedAtts",
"=",
"''",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"allowedTags",
")",
"&&",
"is_array",
"(",
"$",
"allowedTags",
")",
... | Strip tags & attributes from String
@param string $content String to get HTML attributes from
@return array Attributes | [
"Strip",
"tags",
"&",
"attributes",
"from",
"String"
] | 923ca84eafa775237b97221e73a9b381fa6ddcba | https://github.com/helsingborg-stad/Municipio/blob/923ca84eafa775237b97221e73a9b381fa6ddcba/library/Helper/Html.php#L98-L122 | train |
helsingborg-stad/Municipio | library/Theme/Enqueue.php | Enqueue.adminStyle | public function adminStyle()
{
wp_register_style('helsingborg-se-admin', get_template_directory_uri(). '/assets/dist/' . \Municipio\Helper\CacheBust::name('css/admin.min.css'));
wp_enqueue_style('helsingborg-se-admin');
wp_register_script('helsingborg-se-admin', get_template_directory_uri() . '/assets/dist/' . \Municipio\Helper\CacheBust::name('js/admin.js'));
wp_enqueue_script('helsingborg-se-admin');
} | php | public function adminStyle()
{
wp_register_style('helsingborg-se-admin', get_template_directory_uri(). '/assets/dist/' . \Municipio\Helper\CacheBust::name('css/admin.min.css'));
wp_enqueue_style('helsingborg-se-admin');
wp_register_script('helsingborg-se-admin', get_template_directory_uri() . '/assets/dist/' . \Municipio\Helper\CacheBust::name('js/admin.js'));
wp_enqueue_script('helsingborg-se-admin');
} | [
"public",
"function",
"adminStyle",
"(",
")",
"{",
"wp_register_style",
"(",
"'helsingborg-se-admin'",
",",
"get_template_directory_uri",
"(",
")",
".",
"'/assets/dist/'",
".",
"\\",
"Municipio",
"\\",
"Helper",
"\\",
"CacheBust",
"::",
"name",
"(",
"'css/admin.min.... | Enqueue admin style
@return void | [
"Enqueue",
"admin",
"style"
] | 923ca84eafa775237b97221e73a9b381fa6ddcba | https://github.com/helsingborg-stad/Municipio/blob/923ca84eafa775237b97221e73a9b381fa6ddcba/library/Theme/Enqueue.php#L73-L80 | train |
helsingborg-stad/Municipio | library/Theme/Enqueue.php | Enqueue.waitForPrime | public function waitForPrime()
{
$wp_scripts = wp_scripts();
if (!is_admin() && isset($wp_scripts->registered)) {
foreach ($wp_scripts->registered as $key => $item) {
if (is_array($item->deps) && !empty($item->deps)) {
foreach ($item->deps as $depkey => $depencency) {
$item->deps[$depkey] = str_replace("jquery", $this->defaultPrimeName, strtolower($depencency));
}
}
}
}
} | php | public function waitForPrime()
{
$wp_scripts = wp_scripts();
if (!is_admin() && isset($wp_scripts->registered)) {
foreach ($wp_scripts->registered as $key => $item) {
if (is_array($item->deps) && !empty($item->deps)) {
foreach ($item->deps as $depkey => $depencency) {
$item->deps[$depkey] = str_replace("jquery", $this->defaultPrimeName, strtolower($depencency));
}
}
}
}
} | [
"public",
"function",
"waitForPrime",
"(",
")",
"{",
"$",
"wp_scripts",
"=",
"wp_scripts",
"(",
")",
";",
"if",
"(",
"!",
"is_admin",
"(",
")",
"&&",
"isset",
"(",
"$",
"wp_scripts",
"->",
"registered",
")",
")",
"{",
"foreach",
"(",
"$",
"wp_scripts",... | Change jquery deps to hbgprime deps
@return void | [
"Change",
"jquery",
"deps",
"to",
"hbgprime",
"deps"
] | 923ca84eafa775237b97221e73a9b381fa6ddcba | https://github.com/helsingborg-stad/Municipio/blob/923ca84eafa775237b97221e73a9b381fa6ddcba/library/Theme/Enqueue.php#L263-L276 | train |
helsingborg-stad/Municipio | library/Helper/Styleguide.php | Styleguide._getBaseUri | private static function _getBaseUri()
{
if (defined('MUNICIPIO_STYLEGUIDE_URI') && MUNICIPIO_STYLEGUIDE_URI != "") {
$uri = MUNICIPIO_STYLEGUIDE_URI;
} else {
$uri = self::$_uri;
}
$uri = rtrim(apply_filters('Municipio/theme/styleguide_uri', $uri), '/');
if (defined('STYLEGUIDE_VERSION') && STYLEGUIDE_VERSION != "") {
$uri .= '/' . STYLEGUIDE_VERSION;
}
return $uri;
} | php | private static function _getBaseUri()
{
if (defined('MUNICIPIO_STYLEGUIDE_URI') && MUNICIPIO_STYLEGUIDE_URI != "") {
$uri = MUNICIPIO_STYLEGUIDE_URI;
} else {
$uri = self::$_uri;
}
$uri = rtrim(apply_filters('Municipio/theme/styleguide_uri', $uri), '/');
if (defined('STYLEGUIDE_VERSION') && STYLEGUIDE_VERSION != "") {
$uri .= '/' . STYLEGUIDE_VERSION;
}
return $uri;
} | [
"private",
"static",
"function",
"_getBaseUri",
"(",
")",
"{",
"if",
"(",
"defined",
"(",
"'MUNICIPIO_STYLEGUIDE_URI'",
")",
"&&",
"MUNICIPIO_STYLEGUIDE_URI",
"!=",
"\"\"",
")",
"{",
"$",
"uri",
"=",
"MUNICIPIO_STYLEGUIDE_URI",
";",
"}",
"else",
"{",
"$",
"uri... | Returns the base URI of the styleguide.
@return string | [
"Returns",
"the",
"base",
"URI",
"of",
"the",
"styleguide",
"."
] | 923ca84eafa775237b97221e73a9b381fa6ddcba | https://github.com/helsingborg-stad/Municipio/blob/923ca84eafa775237b97221e73a9b381fa6ddcba/library/Helper/Styleguide.php#L27-L42 | train |
helsingborg-stad/Municipio | library/Helper/Styleguide.php | Styleguide.getStylePath | public static function getStylePath($isBem = false)
{
$directory = $isBem ? 'css-bem' : 'css';
$extension = self::_isDevMode() ? 'dev' : 'min';
$theme = self::_getTheme();
return self::getPath($directory . "/". "hbg-prime-" . $theme . "." . $extension . ".css");
} | php | public static function getStylePath($isBem = false)
{
$directory = $isBem ? 'css-bem' : 'css';
$extension = self::_isDevMode() ? 'dev' : 'min';
$theme = self::_getTheme();
return self::getPath($directory . "/". "hbg-prime-" . $theme . "." . $extension . ".css");
} | [
"public",
"static",
"function",
"getStylePath",
"(",
"$",
"isBem",
"=",
"false",
")",
"{",
"$",
"directory",
"=",
"$",
"isBem",
"?",
"'css-bem'",
":",
"'css'",
";",
"$",
"extension",
"=",
"self",
"::",
"_isDevMode",
"(",
")",
"?",
"'dev'",
":",
"'min'"... | Returns the complete style path.
@param bool $isBem Set to get a BEM theme.
@return string | [
"Returns",
"the",
"complete",
"style",
"path",
"."
] | 923ca84eafa775237b97221e73a9b381fa6ddcba | https://github.com/helsingborg-stad/Municipio/blob/923ca84eafa775237b97221e73a9b381fa6ddcba/library/Helper/Styleguide.php#L79-L86 | train |
helsingborg-stad/Municipio | library/Admin/TinyMce/PluginClass.php | PluginClass.setupTinymcePlugin | public function setupTinymcePlugin()
{
if (! current_user_can('edit_posts') && ! current_user_can('edit_pages')) {
return;
}
// Check if the logged in WordPress User has the Visual Editor enabled
// If not, don't register our TinyMCE plugin
if (get_user_option('rich_editing') !== 'true') {
return;
}
$this->init();
if (!$this->pluginSlug || !$this->pluginSlug) {
return;
}
//Change button row placement if buttonRow is defined
if (isset($this->buttonRow) && is_numeric($this->buttonRow) && $this->buttonRow > 1) {
$this->buttonFilter .= '_' . $this->buttonRow;
}
//LocalizeData (if any)
if (is_array($this->data) && !empty($this->data)) {
add_action('admin_head', array($this, 'localizeScript'));
}
add_filter('mce_external_plugins', array($this, 'addTinyMcePlugin'));
add_filter($this->buttonFilter, array($this, 'addTinymceToolbarButton' ));
} | php | public function setupTinymcePlugin()
{
if (! current_user_can('edit_posts') && ! current_user_can('edit_pages')) {
return;
}
// Check if the logged in WordPress User has the Visual Editor enabled
// If not, don't register our TinyMCE plugin
if (get_user_option('rich_editing') !== 'true') {
return;
}
$this->init();
if (!$this->pluginSlug || !$this->pluginSlug) {
return;
}
//Change button row placement if buttonRow is defined
if (isset($this->buttonRow) && is_numeric($this->buttonRow) && $this->buttonRow > 1) {
$this->buttonFilter .= '_' . $this->buttonRow;
}
//LocalizeData (if any)
if (is_array($this->data) && !empty($this->data)) {
add_action('admin_head', array($this, 'localizeScript'));
}
add_filter('mce_external_plugins', array($this, 'addTinyMcePlugin'));
add_filter($this->buttonFilter, array($this, 'addTinymceToolbarButton' ));
} | [
"public",
"function",
"setupTinymcePlugin",
"(",
")",
"{",
"if",
"(",
"!",
"current_user_can",
"(",
"'edit_posts'",
")",
"&&",
"!",
"current_user_can",
"(",
"'edit_pages'",
")",
")",
"{",
"return",
";",
"}",
"// Check if the logged in WordPress User has the Visual Edi... | Check if the current user can edit Posts or Pages, and is using the Visual Editor
If so, add some filters so we can register our plugin | [
"Check",
"if",
"the",
"current",
"user",
"can",
"edit",
"Posts",
"or",
"Pages",
"and",
"is",
"using",
"the",
"Visual",
"Editor",
"If",
"so",
"add",
"some",
"filters",
"so",
"we",
"can",
"register",
"our",
"plugin"
] | 923ca84eafa775237b97221e73a9b381fa6ddcba | https://github.com/helsingborg-stad/Municipio/blob/923ca84eafa775237b97221e73a9b381fa6ddcba/library/Admin/TinyMce/PluginClass.php#L46-L76 | train |
helsingborg-stad/Municipio | library/Search/General.php | General.searchAttachmentPermalink | public function searchAttachmentPermalink($permalink, $post)
{
if (isset($post->post_type) && $post->post_type == 'attachment') {
return wp_get_attachment_url($post->ID);
} else {
return $permalink;
}
} | php | public function searchAttachmentPermalink($permalink, $post)
{
if (isset($post->post_type) && $post->post_type == 'attachment') {
return wp_get_attachment_url($post->ID);
} else {
return $permalink;
}
} | [
"public",
"function",
"searchAttachmentPermalink",
"(",
"$",
"permalink",
",",
"$",
"post",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"post",
"->",
"post_type",
")",
"&&",
"$",
"post",
"->",
"post_type",
"==",
"'attachment'",
")",
"{",
"return",
"wp_get_atta... | Get attachment permalink for search result
@param string $permalink
@param WP_Post $post
@return string Url | [
"Get",
"attachment",
"permalink",
"for",
"search",
"result"
] | 923ca84eafa775237b97221e73a9b381fa6ddcba | https://github.com/helsingborg-stad/Municipio/blob/923ca84eafa775237b97221e73a9b381fa6ddcba/library/Search/General.php#L19-L26 | train |
helsingborg-stad/Municipio | library/Helper/Ajax.php | Ajax.localize | public function localize($var, $handle = null)
{
if(! isset($this->data) || ! $this->data || is_string($var) == false) {
return false;
}
if($handle !== null) {
$this->handle = $handle;
}
$this->var = $var;
add_action( 'wp_enqueue_scripts', array($this, '_localize') );
return true;
} | php | public function localize($var, $handle = null)
{
if(! isset($this->data) || ! $this->data || is_string($var) == false) {
return false;
}
if($handle !== null) {
$this->handle = $handle;
}
$this->var = $var;
add_action( 'wp_enqueue_scripts', array($this, '_localize') );
return true;
} | [
"public",
"function",
"localize",
"(",
"$",
"var",
",",
"$",
"handle",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"data",
")",
"||",
"!",
"$",
"this",
"->",
"data",
"||",
"is_string",
"(",
"$",
"var",
")",
"==",
"fa... | Localize - Pass data from PHP to JS
@param $var - Define variable name used in JS file
@param $handle - Specify script handle (optional)
@return boolean | [
"Localize",
"-",
"Pass",
"data",
"from",
"PHP",
"to",
"JS"
] | 923ca84eafa775237b97221e73a9b381fa6ddcba | https://github.com/helsingborg-stad/Municipio/blob/923ca84eafa775237b97221e73a9b381fa6ddcba/library/Helper/Ajax.php#L19-L34 | train |
helsingborg-stad/Municipio | library/Helper/Ajax.php | Ajax.hook | public function hook($functionName, $private = true)
{
if(! method_exists($this, $functionName) || is_bool($private) == false) {
return false;
}
switch ($private) {
case false:
add_action( 'wp_ajax_nopriv_'.$functionName, array($this,$functionName) );
break;
default:
add_action( 'wp_ajax_'.$functionName, array($this,$functionName) );
break;
}
add_action( 'wp_ajax_'.$functionName, array($this,$functionName) );
return true;
} | php | public function hook($functionName, $private = true)
{
if(! method_exists($this, $functionName) || is_bool($private) == false) {
return false;
}
switch ($private) {
case false:
add_action( 'wp_ajax_nopriv_'.$functionName, array($this,$functionName) );
break;
default:
add_action( 'wp_ajax_'.$functionName, array($this,$functionName) );
break;
}
add_action( 'wp_ajax_'.$functionName, array($this,$functionName) );
return true;
} | [
"public",
"function",
"hook",
"(",
"$",
"functionName",
",",
"$",
"private",
"=",
"true",
")",
"{",
"if",
"(",
"!",
"method_exists",
"(",
"$",
"this",
",",
"$",
"functionName",
")",
"||",
"is_bool",
"(",
"$",
"private",
")",
"==",
"false",
")",
"{",
... | Hook - Hook function to WP ajax
@param string $functionName - Name of existing function within the class
@param boolean $private - Hook fires only for logged-in users, set to false for to fire for everyone
@return boolean | [
"Hook",
"-",
"Hook",
"function",
"to",
"WP",
"ajax"
] | 923ca84eafa775237b97221e73a9b381fa6ddcba | https://github.com/helsingborg-stad/Municipio/blob/923ca84eafa775237b97221e73a9b381fa6ddcba/library/Helper/Ajax.php#L47-L67 | train |
helsingborg-stad/Municipio | library/Content/CustomTaxonomy.php | CustomTaxonomy.populatePostTypeSelect | public function populatePostTypeSelect($field)
{
$choices = array_map('trim', get_post_types());
$choices = array_diff($choices, array('revision','acf-field-group','acf-field','nav_menu_item'));
if (is_array($choices)) {
foreach ($choices as $choice) {
$field['choices'][ $choice ] = $choice;
}
}
return $field;
} | php | public function populatePostTypeSelect($field)
{
$choices = array_map('trim', get_post_types());
$choices = array_diff($choices, array('revision','acf-field-group','acf-field','nav_menu_item'));
if (is_array($choices)) {
foreach ($choices as $choice) {
$field['choices'][ $choice ] = $choice;
}
}
return $field;
} | [
"public",
"function",
"populatePostTypeSelect",
"(",
"$",
"field",
")",
"{",
"$",
"choices",
"=",
"array_map",
"(",
"'trim'",
",",
"get_post_types",
"(",
")",
")",
";",
"$",
"choices",
"=",
"array_diff",
"(",
"$",
"choices",
",",
"array",
"(",
"'revision'"... | Adds value to acf post type filed
@param array $field Acf field
@return void | [
"Adds",
"value",
"to",
"acf",
"post",
"type",
"filed"
] | 923ca84eafa775237b97221e73a9b381fa6ddcba | https://github.com/helsingborg-stad/Municipio/blob/923ca84eafa775237b97221e73a9b381fa6ddcba/library/Content/CustomTaxonomy.php#L76-L89 | train |
helsingborg-stad/Municipio | library/Template.php | Template.initCustomTemplates | public function initCustomTemplates()
{
$directory = MUNICIPIO_PATH . 'library/Controller/';
foreach (@glob($directory . "*.php") as $file) {
$class = '\Municipio\Controller\\' . basename($file, '.php');
if (!class_exists($class)) {
continue;
}
if (!method_exists($class, 'registerTemplate')) {
continue;
}
$class::registerTemplate();
unset($class);
}
} | php | public function initCustomTemplates()
{
$directory = MUNICIPIO_PATH . 'library/Controller/';
foreach (@glob($directory . "*.php") as $file) {
$class = '\Municipio\Controller\\' . basename($file, '.php');
if (!class_exists($class)) {
continue;
}
if (!method_exists($class, 'registerTemplate')) {
continue;
}
$class::registerTemplate();
unset($class);
}
} | [
"public",
"function",
"initCustomTemplates",
"(",
")",
"{",
"$",
"directory",
"=",
"MUNICIPIO_PATH",
".",
"'library/Controller/'",
";",
"foreach",
"(",
"@",
"glob",
"(",
"$",
"directory",
".",
"\"*.php\"",
")",
"as",
"$",
"file",
")",
"{",
"$",
"class",
"=... | Initializes custom templates
@return void | [
"Initializes",
"custom",
"templates"
] | 923ca84eafa775237b97221e73a9b381fa6ddcba | https://github.com/helsingborg-stad/Municipio/blob/923ca84eafa775237b97221e73a9b381fa6ddcba/library/Template.php#L75-L93 | train |
helsingborg-stad/Municipio | library/Template.php | Template.getSearchForm | public function getSearchForm($searchform)
{
if ($view = \Municipio\Helper\Template::locateTemplate('searchform.blade.php')) {
$view = $this->cleanViewPath($view);
$this->loadController($view);
$this->render($view);
return false;
}
return $searchform;
} | php | public function getSearchForm($searchform)
{
if ($view = \Municipio\Helper\Template::locateTemplate('searchform.blade.php')) {
$view = $this->cleanViewPath($view);
$this->loadController($view);
$this->render($view);
return false;
}
return $searchform;
} | [
"public",
"function",
"getSearchForm",
"(",
"$",
"searchform",
")",
"{",
"if",
"(",
"$",
"view",
"=",
"\\",
"Municipio",
"\\",
"Helper",
"\\",
"Template",
"::",
"locateTemplate",
"(",
"'searchform.blade.php'",
")",
")",
"{",
"$",
"view",
"=",
"$",
"this",
... | Get searchform template
@param string $searchform Original markup
@return mixed | [
"Get",
"searchform",
"template"
] | 923ca84eafa775237b97221e73a9b381fa6ddcba | https://github.com/helsingborg-stad/Municipio/blob/923ca84eafa775237b97221e73a9b381fa6ddcba/library/Template.php#L100-L110 | train |
helsingborg-stad/Municipio | library/Template.php | Template.load | public function load($template)
{
if ((is_page() || is_single() || is_front_page()) && !empty(get_page_template_slug()) && get_page_template_slug() != $template) {
if (\Municipio\Helper\Template::locateTemplate(get_page_template_slug())) {
$template = get_page_template_slug();
}
}
if (!\Municipio\Helper\Template::isBlade($template)) {
$path = $template;
// Return path if file exists, else default to page.blade.php
if (file_exists($path)) {
return $path;
} else {
if (current_user_can('administrator')) {
\Municipio\Helper\Notice::add('<strong>' . __('Admin notice', 'municipio') . ':</strong> ' . sprintf(__('View [%s] was not found. Defaulting to [page.blade.php].', 'municipio'), $template), 'warning', 'pricon pricon-notice-warning');
}
$template = \Municipio\Helper\Template::locateTemplate('views/page.blade.php');
}
}
// Clean the view path
$view = $this->cleanViewPath($template);
// Load view controller
$controller = $this->loadController($view);
// Render the view
$data = null;
if ($controller) {
$data = $controller->getData();
}
$this->render($view, $data);
return false;
} | php | public function load($template)
{
if ((is_page() || is_single() || is_front_page()) && !empty(get_page_template_slug()) && get_page_template_slug() != $template) {
if (\Municipio\Helper\Template::locateTemplate(get_page_template_slug())) {
$template = get_page_template_slug();
}
}
if (!\Municipio\Helper\Template::isBlade($template)) {
$path = $template;
// Return path if file exists, else default to page.blade.php
if (file_exists($path)) {
return $path;
} else {
if (current_user_can('administrator')) {
\Municipio\Helper\Notice::add('<strong>' . __('Admin notice', 'municipio') . ':</strong> ' . sprintf(__('View [%s] was not found. Defaulting to [page.blade.php].', 'municipio'), $template), 'warning', 'pricon pricon-notice-warning');
}
$template = \Municipio\Helper\Template::locateTemplate('views/page.blade.php');
}
}
// Clean the view path
$view = $this->cleanViewPath($template);
// Load view controller
$controller = $this->loadController($view);
// Render the view
$data = null;
if ($controller) {
$data = $controller->getData();
}
$this->render($view, $data);
return false;
} | [
"public",
"function",
"load",
"(",
"$",
"template",
")",
"{",
"if",
"(",
"(",
"is_page",
"(",
")",
"||",
"is_single",
"(",
")",
"||",
"is_front_page",
"(",
")",
")",
"&&",
"!",
"empty",
"(",
"get_page_template_slug",
"(",
")",
")",
"&&",
"get_page_temp... | Load controller and view
@param string $template Template
@return mixed Exception or false, false to make sure no
standard template file from wordpres is beeing included | [
"Load",
"controller",
"and",
"view"
] | 923ca84eafa775237b97221e73a9b381fa6ddcba | https://github.com/helsingborg-stad/Municipio/blob/923ca84eafa775237b97221e73a9b381fa6ddcba/library/Template.php#L118-L156 | train |
helsingborg-stad/Municipio | library/Template.php | Template.loadController | public function loadController($template)
{
$template = basename($template) . '.php';
do_action('Municipio/blade/before_load_controller');
if (basename($template) == '404.php') {
$template = 'e404.php';
}
switch ($template) {
case 'author.php':
if (!defined('MUNICIPIO_BLOCK_AUTHOR_PAGES') || MUNICIPIO_BLOCK_AUTHOR_PAGES) {
$template = 'archive.php';
}
break;
}
$controller = \Municipio\Helper\Controller::locateController($template);
if (!$controller) {
$controller = \Municipio\Helper\Controller::locateController('BaseController');
}
$controller = apply_filters('Municipio/blade/controller', $controller);
require_once $controller;
$namespace = \Municipio\Helper\Controller::getNamespace($controller);
$class = '\\' . $namespace . '\\' . basename($controller, '.php');
do_action('Municipio/blade/after_load_controller');
return new $class();
} | php | public function loadController($template)
{
$template = basename($template) . '.php';
do_action('Municipio/blade/before_load_controller');
if (basename($template) == '404.php') {
$template = 'e404.php';
}
switch ($template) {
case 'author.php':
if (!defined('MUNICIPIO_BLOCK_AUTHOR_PAGES') || MUNICIPIO_BLOCK_AUTHOR_PAGES) {
$template = 'archive.php';
}
break;
}
$controller = \Municipio\Helper\Controller::locateController($template);
if (!$controller) {
$controller = \Municipio\Helper\Controller::locateController('BaseController');
}
$controller = apply_filters('Municipio/blade/controller', $controller);
require_once $controller;
$namespace = \Municipio\Helper\Controller::getNamespace($controller);
$class = '\\' . $namespace . '\\' . basename($controller, '.php');
do_action('Municipio/blade/after_load_controller');
return new $class();
} | [
"public",
"function",
"loadController",
"(",
"$",
"template",
")",
"{",
"$",
"template",
"=",
"basename",
"(",
"$",
"template",
")",
".",
"'.php'",
";",
"do_action",
"(",
"'Municipio/blade/before_load_controller'",
")",
";",
"if",
"(",
"basename",
"(",
"$",
... | Loads controller for view template
@param string $template Path to template
@return bool True if controller loaded, else false | [
"Loads",
"controller",
"for",
"view",
"template"
] | 923ca84eafa775237b97221e73a9b381fa6ddcba | https://github.com/helsingborg-stad/Municipio/blob/923ca84eafa775237b97221e73a9b381fa6ddcba/library/Template.php#L163-L196 | train |
helsingborg-stad/Municipio | library/Comment/CommentsFilters.php | CommentsFilters.stripTags | public function stripTags($comment_text, $comment)
{
$allowedTags = array(
"<h1>", "<h2>", "<h3>", "<h4>",
"<strong>","<b>",
"<br>", "<hr>",
"<em>",
"<ol>","<ul>","<li>",
"<p>", "<span>", "<a>", "<img>",
"<del>", "<ins>",
"<blockquote>"
);
$allowedAttributes = array('href', 'class', 'rel', 'id', 'src');
return \Municipio\Helper\Html::stripTagsAndAtts($comment_text, $allowedTags, $allowedAttributes);
} | php | public function stripTags($comment_text, $comment)
{
$allowedTags = array(
"<h1>", "<h2>", "<h3>", "<h4>",
"<strong>","<b>",
"<br>", "<hr>",
"<em>",
"<ol>","<ul>","<li>",
"<p>", "<span>", "<a>", "<img>",
"<del>", "<ins>",
"<blockquote>"
);
$allowedAttributes = array('href', 'class', 'rel', 'id', 'src');
return \Municipio\Helper\Html::stripTagsAndAtts($comment_text, $allowedTags, $allowedAttributes);
} | [
"public",
"function",
"stripTags",
"(",
"$",
"comment_text",
",",
"$",
"comment",
")",
"{",
"$",
"allowedTags",
"=",
"array",
"(",
"\"<h1>\"",
",",
"\"<h2>\"",
",",
"\"<h3>\"",
",",
"\"<h4>\"",
",",
"\"<strong>\"",
",",
"\"<b>\"",
",",
"\"<br>\"",
",",
"\"... | Strip html from comment | [
"Strip",
"html",
"from",
"comment"
] | 923ca84eafa775237b97221e73a9b381fa6ddcba | https://github.com/helsingborg-stad/Municipio/blob/923ca84eafa775237b97221e73a9b381fa6ddcba/library/Comment/CommentsFilters.php#L17-L33 | train |
helsingborg-stad/Municipio | library/Comment/CommentsFilters.php | CommentsFilters.validateReCaptcha | public function validateReCaptcha()
{
if (is_user_logged_in()) {
return;
}
$response = isset($_POST['g-recaptcha-response']) ? esc_attr($_POST['g-recaptcha-response']) : '';
$reCaptcha = \Municipio\Helper\ReCaptcha::controlReCaptcha($response);
if (!$reCaptcha) {
wp_die(sprintf('<strong>%s</strong>: %s', __('Error', 'municipio'), __('reCaptcha verification failed', 'municipio')));
}
return;
} | php | public function validateReCaptcha()
{
if (is_user_logged_in()) {
return;
}
$response = isset($_POST['g-recaptcha-response']) ? esc_attr($_POST['g-recaptcha-response']) : '';
$reCaptcha = \Municipio\Helper\ReCaptcha::controlReCaptcha($response);
if (!$reCaptcha) {
wp_die(sprintf('<strong>%s</strong>: %s', __('Error', 'municipio'), __('reCaptcha verification failed', 'municipio')));
}
return;
} | [
"public",
"function",
"validateReCaptcha",
"(",
")",
"{",
"if",
"(",
"is_user_logged_in",
"(",
")",
")",
"{",
"return",
";",
"}",
"$",
"response",
"=",
"isset",
"(",
"$",
"_POST",
"[",
"'g-recaptcha-response'",
"]",
")",
"?",
"esc_attr",
"(",
"$",
"_POST... | Check reCaptcha before comment is saved to post
@return void | [
"Check",
"reCaptcha",
"before",
"comment",
"is",
"saved",
"to",
"post"
] | 923ca84eafa775237b97221e73a9b381fa6ddcba | https://github.com/helsingborg-stad/Municipio/blob/923ca84eafa775237b97221e73a9b381fa6ddcba/library/Comment/CommentsFilters.php#L52-L66 | train |
helsingborg-stad/Municipio | library/Controller/BaseController.php | BaseController.layout | public function layout()
{
$this->data['layout']['content'] = 'grid-xs-12 order-xs-1 order-md-2';
$this->data['layout']['sidebarLeft'] = 'grid-xs-12 grid-md-4 grid-lg-3 order-xs-2 order-md-1';
$this->data['layout']['sidebarRight'] = 'grid-xs-12 grid-md-4 grid-lg-3 hidden-xs hidden-sm hidden-md order-md-3';
$sidebarLeft = false;
$sidebarRight = false;
if (get_field('archive_' . sanitize_title(get_post_type()) . '_show_sidebar_navigation', 'option') && is_post_type_archive(get_post_type())) {
$sidebarLeft = true;
}
//Has child or is parent and nav_sub is enabled
if (get_field('nav_sub_enable', 'option') && is_singular() &&
!empty(get_children(['post_parent' => get_queried_object_id(), 'numberposts' => 1], ARRAY_A))
|| get_field('nav_sub_enable', 'option') && is_singular() &&
count(get_children(['post_parent' => get_queried_object_id(), 'numberposts' => 1], ARRAY_A)) > 0) {
$sidebarLeft = true;
}
if (is_active_sidebar('left-sidebar') || is_active_sidebar('left-sidebar-bottom')) {
$sidebarLeft = true;
}
if (is_active_sidebar('right-sidebar')) {
$sidebarRight = true;
}
if ($sidebarLeft && $sidebarRight) {
$this->data['layout']['content'] = 'grid-xs-12 grid-md-8 grid-lg-6 order-xs-1 order-md-2';
} elseif ($sidebarLeft || $sidebarRight) {
$this->data['layout']['content'] = 'grid-xs-12 grid-md-8 grid-lg-9 order-xs-1 order-md-2';
}
if (!$sidebarLeft && $sidebarRight) {
$this->data['layout']['sidebarLeft'] .= ' hidden-lg';
}
if (is_front_page()) {
$this->data['layout']['content'] = 'grid-xs-12';
}
$this->data['layout'] = apply_filters('Municipio/Controller/BaseController/Layout', $this->data['layout'], $sidebarLeft, $sidebarRight);
} | php | public function layout()
{
$this->data['layout']['content'] = 'grid-xs-12 order-xs-1 order-md-2';
$this->data['layout']['sidebarLeft'] = 'grid-xs-12 grid-md-4 grid-lg-3 order-xs-2 order-md-1';
$this->data['layout']['sidebarRight'] = 'grid-xs-12 grid-md-4 grid-lg-3 hidden-xs hidden-sm hidden-md order-md-3';
$sidebarLeft = false;
$sidebarRight = false;
if (get_field('archive_' . sanitize_title(get_post_type()) . '_show_sidebar_navigation', 'option') && is_post_type_archive(get_post_type())) {
$sidebarLeft = true;
}
//Has child or is parent and nav_sub is enabled
if (get_field('nav_sub_enable', 'option') && is_singular() &&
!empty(get_children(['post_parent' => get_queried_object_id(), 'numberposts' => 1], ARRAY_A))
|| get_field('nav_sub_enable', 'option') && is_singular() &&
count(get_children(['post_parent' => get_queried_object_id(), 'numberposts' => 1], ARRAY_A)) > 0) {
$sidebarLeft = true;
}
if (is_active_sidebar('left-sidebar') || is_active_sidebar('left-sidebar-bottom')) {
$sidebarLeft = true;
}
if (is_active_sidebar('right-sidebar')) {
$sidebarRight = true;
}
if ($sidebarLeft && $sidebarRight) {
$this->data['layout']['content'] = 'grid-xs-12 grid-md-8 grid-lg-6 order-xs-1 order-md-2';
} elseif ($sidebarLeft || $sidebarRight) {
$this->data['layout']['content'] = 'grid-xs-12 grid-md-8 grid-lg-9 order-xs-1 order-md-2';
}
if (!$sidebarLeft && $sidebarRight) {
$this->data['layout']['sidebarLeft'] .= ' hidden-lg';
}
if (is_front_page()) {
$this->data['layout']['content'] = 'grid-xs-12';
}
$this->data['layout'] = apply_filters('Municipio/Controller/BaseController/Layout', $this->data['layout'], $sidebarLeft, $sidebarRight);
} | [
"public",
"function",
"layout",
"(",
")",
"{",
"$",
"this",
"->",
"data",
"[",
"'layout'",
"]",
"[",
"'content'",
"]",
"=",
"'grid-xs-12 order-xs-1 order-md-2'",
";",
"$",
"this",
"->",
"data",
"[",
"'layout'",
"]",
"[",
"'sidebarLeft'",
"]",
"=",
"'grid-x... | Set main layout columns
@return void | [
"Set",
"main",
"layout",
"columns"
] | 923ca84eafa775237b97221e73a9b381fa6ddcba | https://github.com/helsingborg-stad/Municipio/blob/923ca84eafa775237b97221e73a9b381fa6ddcba/library/Controller/BaseController.php#L71-L115 | train |
helsingborg-stad/Municipio | library/Controller/BaseController.php | BaseController.getSocialShareUrl | public function getSocialShareUrl()
{
//Get the post id
if(!$postId = get_the_ID()) {
global $post;
$postId = $post->ID;
}
//Return share url
return urlencode(get_home_url(null, '?socialShareId=' . $postId, null));
} | php | public function getSocialShareUrl()
{
//Get the post id
if(!$postId = get_the_ID()) {
global $post;
$postId = $post->ID;
}
//Return share url
return urlencode(get_home_url(null, '?socialShareId=' . $postId, null));
} | [
"public",
"function",
"getSocialShareUrl",
"(",
")",
"{",
"//Get the post id",
"if",
"(",
"!",
"$",
"postId",
"=",
"get_the_ID",
"(",
")",
")",
"{",
"global",
"$",
"post",
";",
"$",
"postId",
"=",
"$",
"post",
"->",
"ID",
";",
"}",
"//Return share url",
... | Get the social share url
@return string | [
"Get",
"the",
"social",
"share",
"url"
] | 923ca84eafa775237b97221e73a9b381fa6ddcba | https://github.com/helsingborg-stad/Municipio/blob/923ca84eafa775237b97221e73a9b381fa6ddcba/library/Controller/BaseController.php#L154-L164 | train |
helsingborg-stad/Municipio | library/Controller/BaseController.php | BaseController.customizerHeader | public function customizerHeader()
{
if (get_field('header_layout', 'options') !== 'customizer') {
return;
}
$customizerHeader = new \Municipio\Customizer\Source\CustomizerRepeaterInput('customizer__header_sections', 'options', 'id');
$this->data['headerLayout']['classes'] = 's-site-header';
$this->data['headerLayout']['template'] = 'customizer';
if ($customizerHeader->hasItems) {
foreach ($customizerHeader->repeater as $headerData) {
$this->data['headerLayout']['headers'][] = new \Municipio\Customizer\Header($headerData);
}
}
} | php | public function customizerHeader()
{
if (get_field('header_layout', 'options') !== 'customizer') {
return;
}
$customizerHeader = new \Municipio\Customizer\Source\CustomizerRepeaterInput('customizer__header_sections', 'options', 'id');
$this->data['headerLayout']['classes'] = 's-site-header';
$this->data['headerLayout']['template'] = 'customizer';
if ($customizerHeader->hasItems) {
foreach ($customizerHeader->repeater as $headerData) {
$this->data['headerLayout']['headers'][] = new \Municipio\Customizer\Header($headerData);
}
}
} | [
"public",
"function",
"customizerHeader",
"(",
")",
"{",
"if",
"(",
"get_field",
"(",
"'header_layout'",
",",
"'options'",
")",
"!==",
"'customizer'",
")",
"{",
"return",
";",
"}",
"$",
"customizerHeader",
"=",
"new",
"\\",
"Municipio",
"\\",
"Customizer",
"... | Sends necessary data to the view for customizer header
@return void | [
"Sends",
"necessary",
"data",
"to",
"the",
"view",
"for",
"customizer",
"header"
] | 923ca84eafa775237b97221e73a9b381fa6ddcba | https://github.com/helsingborg-stad/Municipio/blob/923ca84eafa775237b97221e73a9b381fa6ddcba/library/Controller/BaseController.php#L179-L194 | train |
helsingborg-stad/Municipio | library/Controller/BaseController.php | BaseController.customizerFooter | public function customizerFooter()
{
if (get_field('footer_layout', 'options') !== 'customizer') {
return;
}
$customizerFooter = new \Municipio\Customizer\Source\CustomizerRepeaterInput('customizer__footer_sections', 'options', 'id');
$classes = array();
$classes[] = 's-site-footer';
$classes[] = 'hidden-print';
$classes[] = (get_field('scroll_elevator_enabled', 'option')) ? 'scroll-elevator-toggle' : '';
$this->data['footerLayout']['template'] = 'customizer';
$this->data['footerLayout']['classes'] = implode(' ', $classes);
if ($customizerFooter->hasItems) {
foreach ($customizerFooter->repeater as $footerData) {
$this->data['footerSections'][] = new \Municipio\Customizer\Footer($footerData);
}
}
} | php | public function customizerFooter()
{
if (get_field('footer_layout', 'options') !== 'customizer') {
return;
}
$customizerFooter = new \Municipio\Customizer\Source\CustomizerRepeaterInput('customizer__footer_sections', 'options', 'id');
$classes = array();
$classes[] = 's-site-footer';
$classes[] = 'hidden-print';
$classes[] = (get_field('scroll_elevator_enabled', 'option')) ? 'scroll-elevator-toggle' : '';
$this->data['footerLayout']['template'] = 'customizer';
$this->data['footerLayout']['classes'] = implode(' ', $classes);
if ($customizerFooter->hasItems) {
foreach ($customizerFooter->repeater as $footerData) {
$this->data['footerSections'][] = new \Municipio\Customizer\Footer($footerData);
}
}
} | [
"public",
"function",
"customizerFooter",
"(",
")",
"{",
"if",
"(",
"get_field",
"(",
"'footer_layout'",
",",
"'options'",
")",
"!==",
"'customizer'",
")",
"{",
"return",
";",
"}",
"$",
"customizerFooter",
"=",
"new",
"\\",
"Municipio",
"\\",
"Customizer",
"... | Sends necessary data to the view for customizer footer
@return void | [
"Sends",
"necessary",
"data",
"to",
"the",
"view",
"for",
"customizer",
"footer"
] | 923ca84eafa775237b97221e73a9b381fa6ddcba | https://github.com/helsingborg-stad/Municipio/blob/923ca84eafa775237b97221e73a9b381fa6ddcba/library/Controller/BaseController.php#L200-L221 | train |
helsingborg-stad/Municipio | library/Oembed/YouTube.php | YouTube.getPlaylist | public function getPlaylist() : array
{
if (!defined('MUNICIPIO_GOOGLEAPIS_KEY') || !MUNICIPIO_GOOGLEAPIS_KEY || !isset($this->params['list'])) {
return array();
}
$theEnd = false;
$nextPageToken = true;
$items = array();
while ($nextPageToken) {
$endpointUrl = 'https://www.googleapis.com/youtube/v3/playlistItems?playlistId=' . $this->params['list'] . '&part=snippet&maxResults=50&key=' . MUNICIPIO_GOOGLEAPIS_KEY;
if (is_string($nextPageToken) && !empty($nextPageToken)) {
$endpointUrl .= '&pageToken=' . $nextPageToken;
}
$response = wp_remote_get($endpointUrl);
// If response code is bad return
if (wp_remote_retrieve_response_code($response) !== 200) {
return array();
}
$result = json_decode(wp_remote_retrieve_body($response));
$items = array_merge($items, $result->items);
$nextPageToken = isset($result->nextPageToken) ? $result->nextPageToken : false;
}
return $items;
} | php | public function getPlaylist() : array
{
if (!defined('MUNICIPIO_GOOGLEAPIS_KEY') || !MUNICIPIO_GOOGLEAPIS_KEY || !isset($this->params['list'])) {
return array();
}
$theEnd = false;
$nextPageToken = true;
$items = array();
while ($nextPageToken) {
$endpointUrl = 'https://www.googleapis.com/youtube/v3/playlistItems?playlistId=' . $this->params['list'] . '&part=snippet&maxResults=50&key=' . MUNICIPIO_GOOGLEAPIS_KEY;
if (is_string($nextPageToken) && !empty($nextPageToken)) {
$endpointUrl .= '&pageToken=' . $nextPageToken;
}
$response = wp_remote_get($endpointUrl);
// If response code is bad return
if (wp_remote_retrieve_response_code($response) !== 200) {
return array();
}
$result = json_decode(wp_remote_retrieve_body($response));
$items = array_merge($items, $result->items);
$nextPageToken = isset($result->nextPageToken) ? $result->nextPageToken : false;
}
return $items;
} | [
"public",
"function",
"getPlaylist",
"(",
")",
":",
"array",
"{",
"if",
"(",
"!",
"defined",
"(",
"'MUNICIPIO_GOOGLEAPIS_KEY'",
")",
"||",
"!",
"MUNICIPIO_GOOGLEAPIS_KEY",
"||",
"!",
"isset",
"(",
"$",
"this",
"->",
"params",
"[",
"'list'",
"]",
")",
")",
... | Get playlist items
@return array Playlist | [
"Get",
"playlist",
"items"
] | 923ca84eafa775237b97221e73a9b381fa6ddcba | https://github.com/helsingborg-stad/Municipio/blob/923ca84eafa775237b97221e73a9b381fa6ddcba/library/Oembed/YouTube.php#L131-L163 | train |
helsingborg-stad/Municipio | library/Comment/HoneyPot.php | HoneyPot.honeyPotValidateFieldContent | public function honeyPotValidateFieldContent($data)
{
if (isset($_POST[$this->field_name.'_fi']) && isset($_POST[$this->field_name.'_bl'])) {
if (empty($_POST[$this->field_name.'_bl']) && $_POST[$this->field_name.'_fi'] == $this->field_content) {
return $data;
}
wp_die(__("Could not verify that you are human (some hidden form fields are manipulated).", 'municipio'));
}
wp_die(__("Could not verify that you are human (some form fields are missing).", 'municipio'));
} | php | public function honeyPotValidateFieldContent($data)
{
if (isset($_POST[$this->field_name.'_fi']) && isset($_POST[$this->field_name.'_bl'])) {
if (empty($_POST[$this->field_name.'_bl']) && $_POST[$this->field_name.'_fi'] == $this->field_content) {
return $data;
}
wp_die(__("Could not verify that you are human (some hidden form fields are manipulated).", 'municipio'));
}
wp_die(__("Could not verify that you are human (some form fields are missing).", 'municipio'));
} | [
"public",
"function",
"honeyPotValidateFieldContent",
"(",
"$",
"data",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"_POST",
"[",
"$",
"this",
"->",
"field_name",
".",
"'_fi'",
"]",
")",
"&&",
"isset",
"(",
"$",
"_POST",
"[",
"$",
"this",
"->",
"field_name... | Validate honeypot fields before saving comment
@param array $data The comment data
@return array Comment data or die | [
"Validate",
"honeypot",
"fields",
"before",
"saving",
"comment"
] | 923ca84eafa775237b97221e73a9b381fa6ddcba | https://github.com/helsingborg-stad/Municipio/blob/923ca84eafa775237b97221e73a9b381fa6ddcba/library/Comment/HoneyPot.php#L64-L75 | train |
helsingborg-stad/Municipio | library/Helper/Query.php | Query.getPaginationData | public static function getPaginationData()
{
global $wp_query;
$data = array();
$data['postType'] = $wp_query->query['post_type'];
$data['postCount'] = $wp_query->post_count;
$data['postTotal'] = $wp_query->found_posts;
$data['pageIndex'] = ($wp_query->query['paged']) ? intval($wp_query->query['paged']) : 1;
$data['pageTotal'] = $wp_query->max_num_pages;
return $data;
} | php | public static function getPaginationData()
{
global $wp_query;
$data = array();
$data['postType'] = $wp_query->query['post_type'];
$data['postCount'] = $wp_query->post_count;
$data['postTotal'] = $wp_query->found_posts;
$data['pageIndex'] = ($wp_query->query['paged']) ? intval($wp_query->query['paged']) : 1;
$data['pageTotal'] = $wp_query->max_num_pages;
return $data;
} | [
"public",
"static",
"function",
"getPaginationData",
"(",
")",
"{",
"global",
"$",
"wp_query",
";",
"$",
"data",
"=",
"array",
"(",
")",
";",
"$",
"data",
"[",
"'postType'",
"]",
"=",
"$",
"wp_query",
"->",
"query",
"[",
"'post_type'",
"]",
";",
"$",
... | Get pagination data from main query
@return array Pagination data | [
"Get",
"pagination",
"data",
"from",
"main",
"query"
] | 923ca84eafa775237b97221e73a9b381fa6ddcba | https://github.com/helsingborg-stad/Municipio/blob/923ca84eafa775237b97221e73a9b381fa6ddcba/library/Helper/Query.php#L11-L24 | train |
helsingborg-stad/Municipio | library/Helper/Controller.php | Controller.locateController | public static function locateController($controller)
{
preg_match_all('/^(single|archive)-/i', $controller, $matches);
$controllers = array(
str_replace('.blade.php', '', self::camelCase(basename($controller, '.php')))
);
if (isset($matches[1][0])) {
$controllers[] = self::camelCase($matches[1][0]);
}
$searchPaths = array(
get_stylesheet_directory() . '/library/Controller',
get_template_directory() . '/library/Controller',
);
/**
* Apply filter to $searchPaths
* @since 0.1.0
* @var array
*/
$searchPaths = apply_filters('Municipio/blade/controllers_search_paths', $searchPaths);
foreach ($searchPaths as $path) {
foreach ($controllers as $controller) {
$file = $path . '/' . $controller . '.php';
if (!file_exists($file)) {
continue;
}
return $file;
}
}
return false;
} | php | public static function locateController($controller)
{
preg_match_all('/^(single|archive)-/i', $controller, $matches);
$controllers = array(
str_replace('.blade.php', '', self::camelCase(basename($controller, '.php')))
);
if (isset($matches[1][0])) {
$controllers[] = self::camelCase($matches[1][0]);
}
$searchPaths = array(
get_stylesheet_directory() . '/library/Controller',
get_template_directory() . '/library/Controller',
);
/**
* Apply filter to $searchPaths
* @since 0.1.0
* @var array
*/
$searchPaths = apply_filters('Municipio/blade/controllers_search_paths', $searchPaths);
foreach ($searchPaths as $path) {
foreach ($controllers as $controller) {
$file = $path . '/' . $controller . '.php';
if (!file_exists($file)) {
continue;
}
return $file;
}
}
return false;
} | [
"public",
"static",
"function",
"locateController",
"(",
"$",
"controller",
")",
"{",
"preg_match_all",
"(",
"'/^(single|archive)-/i'",
",",
"$",
"controller",
",",
"$",
"matches",
")",
";",
"$",
"controllers",
"=",
"array",
"(",
"str_replace",
"(",
"'.blade.php... | Tries to locate a controller
@param string $controller Controller name
@return string Controller path | [
"Tries",
"to",
"locate",
"a",
"controller"
] | 923ca84eafa775237b97221e73a9b381fa6ddcba | https://github.com/helsingborg-stad/Municipio/blob/923ca84eafa775237b97221e73a9b381fa6ddcba/library/Helper/Controller.php#L12-L49 | train |
helsingborg-stad/Municipio | library/Helper/Controller.php | Controller.getNamespace | public static function getNamespace($classPath)
{
$src = file_get_contents($classPath);
if (preg_match('/namespace\s+(.+?);/', $src, $m)) {
return $m[1];
}
return null;
} | php | public static function getNamespace($classPath)
{
$src = file_get_contents($classPath);
if (preg_match('/namespace\s+(.+?);/', $src, $m)) {
return $m[1];
}
return null;
} | [
"public",
"static",
"function",
"getNamespace",
"(",
"$",
"classPath",
")",
"{",
"$",
"src",
"=",
"file_get_contents",
"(",
"$",
"classPath",
")",
";",
"if",
"(",
"preg_match",
"(",
"'/namespace\\s+(.+?);/'",
",",
"$",
"src",
",",
"$",
"m",
")",
")",
"{"... | Get a class's namespace
@param string $classPath Path to the class php file
@return string Namespace or null | [
"Get",
"a",
"class",
"s",
"namespace"
] | 923ca84eafa775237b97221e73a9b381fa6ddcba | https://github.com/helsingborg-stad/Municipio/blob/923ca84eafa775237b97221e73a9b381fa6ddcba/library/Helper/Controller.php#L80-L89 | train |
helsingborg-stad/Municipio | library/Widget/Source/HeaderWidget.php | HeaderWidget.implodeWrapperClass | protected function implodeWrapperClass()
{
if (is_array($this->data['widgetWrapperClass'])) {
$this->data['widgetWrapperClass'] = implode(' ', $this->data['widgetWrapperClass']);
}
$re = '/class="(.*)"/';
$str = $this->data['args']['before_widget'];
preg_match_all($re, $str, $matches, PREG_SET_ORDER, 0);
if (isset($matches[0][1])) {
$widgetClass = 'c-navbar__widget widget widget_' . $this->config['id'] . ' ' . $this->data['widgetWrapperClass'];
$oldClasses = $matches[0][1];
$this->data['args']['before_widget'] = str_replace($oldClasses, $widgetClass, $this->data['args']['before_widget']);
}
} | php | protected function implodeWrapperClass()
{
if (is_array($this->data['widgetWrapperClass'])) {
$this->data['widgetWrapperClass'] = implode(' ', $this->data['widgetWrapperClass']);
}
$re = '/class="(.*)"/';
$str = $this->data['args']['before_widget'];
preg_match_all($re, $str, $matches, PREG_SET_ORDER, 0);
if (isset($matches[0][1])) {
$widgetClass = 'c-navbar__widget widget widget_' . $this->config['id'] . ' ' . $this->data['widgetWrapperClass'];
$oldClasses = $matches[0][1];
$this->data['args']['before_widget'] = str_replace($oldClasses, $widgetClass, $this->data['args']['before_widget']);
}
} | [
"protected",
"function",
"implodeWrapperClass",
"(",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"this",
"->",
"data",
"[",
"'widgetWrapperClass'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"data",
"[",
"'widgetWrapperClass'",
"]",
"=",
"implode",
"(",
"' '",
... | Method to convert wrapper class array to string
@return void | [
"Method",
"to",
"convert",
"wrapper",
"class",
"array",
"to",
"string"
] | 923ca84eafa775237b97221e73a9b381fa6ddcba | https://github.com/helsingborg-stad/Municipio/blob/923ca84eafa775237b97221e73a9b381fa6ddcba/library/Widget/Source/HeaderWidget.php#L86-L102 | train |
helsingborg-stad/Municipio | library/Widget/Source/HeaderWidget.php | HeaderWidget.visibilityClasses | protected function visibilityClasses()
{
if (!$this->get_field('widget_header_visibility') || !is_array($this->get_field('widget_header_visibility')) || empty($this->get_field('widget_header_visibility'))) {
return false;
}
$options = array(
'xs' => 'hidden-xs',
'sm' => 'hidden-sm',
'md' => 'hidden-md',
'lg' => 'hidden-lg'
);
$options = apply_filters('Municipio/Widget/Source/NavigationWidget/visibilityClasses', $options);
$classes = array();
foreach ($this->get_field('widget_header_visibility') as $device) {
if (isset($options[$device])) {
$classes[] = $options[$device];
}
}
if (!empty($classes)) {
$this->data['widgetWrapperClass'] = array_merge($this->data['widgetWrapperClass'], $classes);
return true;
}
return false;
} | php | protected function visibilityClasses()
{
if (!$this->get_field('widget_header_visibility') || !is_array($this->get_field('widget_header_visibility')) || empty($this->get_field('widget_header_visibility'))) {
return false;
}
$options = array(
'xs' => 'hidden-xs',
'sm' => 'hidden-sm',
'md' => 'hidden-md',
'lg' => 'hidden-lg'
);
$options = apply_filters('Municipio/Widget/Source/NavigationWidget/visibilityClasses', $options);
$classes = array();
foreach ($this->get_field('widget_header_visibility') as $device) {
if (isset($options[$device])) {
$classes[] = $options[$device];
}
}
if (!empty($classes)) {
$this->data['widgetWrapperClass'] = array_merge($this->data['widgetWrapperClass'], $classes);
return true;
}
return false;
} | [
"protected",
"function",
"visibilityClasses",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"get_field",
"(",
"'widget_header_visibility'",
")",
"||",
"!",
"is_array",
"(",
"$",
"this",
"->",
"get_field",
"(",
"'widget_header_visibility'",
")",
")",
"||",
... | Method to add visibility classes to widget wrapper based on ACF field
@return void | [
"Method",
"to",
"add",
"visibility",
"classes",
"to",
"widget",
"wrapper",
"based",
"on",
"ACF",
"field"
] | 923ca84eafa775237b97221e73a9b381fa6ddcba | https://github.com/helsingborg-stad/Municipio/blob/923ca84eafa775237b97221e73a9b381fa6ddcba/library/Widget/Source/HeaderWidget.php#L108-L138 | train |
helsingborg-stad/Municipio | library/Admin/General.php | General.removeUnwantedModuleMetaboxes | public function removeUnwantedModuleMetaboxes($postType)
{
$publicPostTypes = array_keys(\Municipio\Helper\PostType::getPublic());
$publicPostTypes[] = 'page';
if (!in_array($postType, $publicPostTypes)) {
// Navigation settings
remove_meta_box('acf-group_56d83cff12bb3', $postType, 'side');
// Display settings
remove_meta_box('acf-group_56c33cf1470dc', $postType, 'side');
}
} | php | public function removeUnwantedModuleMetaboxes($postType)
{
$publicPostTypes = array_keys(\Municipio\Helper\PostType::getPublic());
$publicPostTypes[] = 'page';
if (!in_array($postType, $publicPostTypes)) {
// Navigation settings
remove_meta_box('acf-group_56d83cff12bb3', $postType, 'side');
// Display settings
remove_meta_box('acf-group_56c33cf1470dc', $postType, 'side');
}
} | [
"public",
"function",
"removeUnwantedModuleMetaboxes",
"(",
"$",
"postType",
")",
"{",
"$",
"publicPostTypes",
"=",
"array_keys",
"(",
"\\",
"Municipio",
"\\",
"Helper",
"\\",
"PostType",
"::",
"getPublic",
"(",
")",
")",
";",
"$",
"publicPostTypes",
"[",
"]",... | Removes unwanted metaboxes from the module post types
@param string $postType Post type
@return void | [
"Removes",
"unwanted",
"metaboxes",
"from",
"the",
"module",
"post",
"types"
] | 923ca84eafa775237b97221e73a9b381fa6ddcba | https://github.com/helsingborg-stad/Municipio/blob/923ca84eafa775237b97221e73a9b381fa6ddcba/library/Admin/General.php#L73-L85 | train |
helsingborg-stad/Municipio | library/Admin/General.php | General.renamePrivate | public function renamePrivate()
{
if (!is_admin()) {
return;
}
if (get_current_screen()->action !== '' && get_current_screen()->action !== 'add') {
return;
}
add_filter('gettext', function ($translation, $text, $domain) {
if ($text !== 'Private') {
return $translation;
}
return __('Only for logged in users', 'municipio');
}, 10, 3);
} | php | public function renamePrivate()
{
if (!is_admin()) {
return;
}
if (get_current_screen()->action !== '' && get_current_screen()->action !== 'add') {
return;
}
add_filter('gettext', function ($translation, $text, $domain) {
if ($text !== 'Private') {
return $translation;
}
return __('Only for logged in users', 'municipio');
}, 10, 3);
} | [
"public",
"function",
"renamePrivate",
"(",
")",
"{",
"if",
"(",
"!",
"is_admin",
"(",
")",
")",
"{",
"return",
";",
"}",
"if",
"(",
"get_current_screen",
"(",
")",
"->",
"action",
"!==",
"''",
"&&",
"get_current_screen",
"(",
")",
"->",
"action",
"!==... | Renames the "private" post visibility to "only for logged in users"
@return void | [
"Renames",
"the",
"private",
"post",
"visibility",
"to",
"only",
"for",
"logged",
"in",
"users"
] | 923ca84eafa775237b97221e73a9b381fa6ddcba | https://github.com/helsingborg-stad/Municipio/blob/923ca84eafa775237b97221e73a9b381fa6ddcba/library/Admin/General.php#L91-L108 | train |
helsingborg-stad/Municipio | library/Admin/General.php | General.pageForPostsDropdown | public function pageForPostsDropdown($output, $r, $pages)
{
if ($r['name'] !== 'page_for_posts') {
return $output;
}
$r['post_status'] = array('publish', 'private');
$pages = get_pages($r);
$class = '';
if (! empty($r['class'])) {
$class = " class='" . esc_attr($r['class']) . "'";
}
$output = "<select name='" . esc_attr($r['name']) . "'" . $class . " id='" . esc_attr($r['id']) . "'>\n";
if ($r['show_option_no_change']) {
$output .= "\t<option value=\"-1\">" . $r['show_option_no_change'] . "</option>\n";
}
if ($r['show_option_none']) {
$output .= "\t<option value=\"" . esc_attr($r['option_none_value']) . '">' . $r['show_option_none'] . "</option>\n";
}
add_filter('list_pages', array($this, 'listPagesTitle'), 100, 2);
$output .= walk_page_dropdown_tree($pages, $r['depth'], $r);
remove_filter('list_pages', array($this, 'listPagesTitle'), 100);
$output .= "</select>\n";
return $output;
} | php | public function pageForPostsDropdown($output, $r, $pages)
{
if ($r['name'] !== 'page_for_posts') {
return $output;
}
$r['post_status'] = array('publish', 'private');
$pages = get_pages($r);
$class = '';
if (! empty($r['class'])) {
$class = " class='" . esc_attr($r['class']) . "'";
}
$output = "<select name='" . esc_attr($r['name']) . "'" . $class . " id='" . esc_attr($r['id']) . "'>\n";
if ($r['show_option_no_change']) {
$output .= "\t<option value=\"-1\">" . $r['show_option_no_change'] . "</option>\n";
}
if ($r['show_option_none']) {
$output .= "\t<option value=\"" . esc_attr($r['option_none_value']) . '">' . $r['show_option_none'] . "</option>\n";
}
add_filter('list_pages', array($this, 'listPagesTitle'), 100, 2);
$output .= walk_page_dropdown_tree($pages, $r['depth'], $r);
remove_filter('list_pages', array($this, 'listPagesTitle'), 100);
$output .= "</select>\n";
return $output;
} | [
"public",
"function",
"pageForPostsDropdown",
"(",
"$",
"output",
",",
"$",
"r",
",",
"$",
"pages",
")",
"{",
"if",
"(",
"$",
"r",
"[",
"'name'",
"]",
"!==",
"'page_for_posts'",
")",
"{",
"return",
"$",
"output",
";",
"}",
"$",
"r",
"[",
"'post_statu... | Show private pages in the "page for posts" dropdown
@param string $output Dropdown markup
@param array $r Arguments
@param array $pages Default pages
@return string New dropdown markup | [
"Show",
"private",
"pages",
"in",
"the",
"page",
"for",
"posts",
"dropdown"
] | 923ca84eafa775237b97221e73a9b381fa6ddcba | https://github.com/helsingborg-stad/Municipio/blob/923ca84eafa775237b97221e73a9b381fa6ddcba/library/Admin/General.php#L117-L149 | train |
helsingborg-stad/Municipio | library/Walker/SidebarMenu.php | SidebarMenu.getChildOf | public function getChildOf($current_page, $elements)
{
$child_of = 0;
if (is_a($current_page, '\WP_Post')) {
$current_page = $current_page->ID;
}
foreach ($elements as $key => $element) {
if (isset($element->ID) && isset($current_page) && $element->ID == $current_page) {
$child_of = $element->ID;
unset($elements[$key]);
if (intval($element->menu_item_parent) > 0) {
$child_of = $this->getChildOf(intval($element->menu_item_parent), $elements);
}
break;
}
}
return $child_of;
} | php | public function getChildOf($current_page, $elements)
{
$child_of = 0;
if (is_a($current_page, '\WP_Post')) {
$current_page = $current_page->ID;
}
foreach ($elements as $key => $element) {
if (isset($element->ID) && isset($current_page) && $element->ID == $current_page) {
$child_of = $element->ID;
unset($elements[$key]);
if (intval($element->menu_item_parent) > 0) {
$child_of = $this->getChildOf(intval($element->menu_item_parent), $elements);
}
break;
}
}
return $child_of;
} | [
"public",
"function",
"getChildOf",
"(",
"$",
"current_page",
",",
"$",
"elements",
")",
"{",
"$",
"child_of",
"=",
"0",
";",
"if",
"(",
"is_a",
"(",
"$",
"current_page",
",",
"'\\WP_Post'",
")",
")",
"{",
"$",
"current_page",
"=",
"$",
"current_page",
... | Find which the top parent for the current page
@param integer $current_page Current page menu id
@param array $elements Menu elements
@return integer Menu parent id (child_of) | [
"Find",
"which",
"the",
"top",
"parent",
"for",
"the",
"current",
"page"
] | 923ca84eafa775237b97221e73a9b381fa6ddcba | https://github.com/helsingborg-stad/Municipio/blob/923ca84eafa775237b97221e73a9b381fa6ddcba/library/Walker/SidebarMenu.php#L79-L101 | train |
helsingborg-stad/Municipio | library/Helper/Acf.php | Acf.getFieldKey | public static function getFieldKey($fieldName, $fieldId)
{
if (isset(get_field_objects($fieldId)[$fieldName]['key'])) {
return get_field_objects($fieldId)[$fieldName]['key'];
}
return false;
} | php | public static function getFieldKey($fieldName, $fieldId)
{
if (isset(get_field_objects($fieldId)[$fieldName]['key'])) {
return get_field_objects($fieldId)[$fieldName]['key'];
}
return false;
} | [
"public",
"static",
"function",
"getFieldKey",
"(",
"$",
"fieldName",
",",
"$",
"fieldId",
")",
"{",
"if",
"(",
"isset",
"(",
"get_field_objects",
"(",
"$",
"fieldId",
")",
"[",
"$",
"fieldName",
"]",
"[",
"'key'",
"]",
")",
")",
"{",
"return",
"get_fi... | Get ACF field key by fieldname, has to be run at action 'init' or later
@param string $fieldName The field name
@param string $fieldId Field ID can be post id, widget id, 'options' etc
@return boolean/string | [
"Get",
"ACF",
"field",
"key",
"by",
"fieldname",
"has",
"to",
"be",
"run",
"at",
"action",
"init",
"or",
"later"
] | 923ca84eafa775237b97221e73a9b381fa6ddcba | https://github.com/helsingborg-stad/Municipio/blob/923ca84eafa775237b97221e73a9b381fa6ddcba/library/Helper/Acf.php#L13-L20 | train |
helsingborg-stad/Municipio | library/Helper/Image.php | Image.resize | public static function resize($originalImage, $width, $height, $crop = true)
{
$imagePath = false;
// Image from attachment id
if (is_numeric($originalImage)) {
$imagePath = wp_get_attachment_url($originalImage);
} elseif (in_array(substr($originalImage, 0, 7), array('https:/', 'http://'))) {
$imagePath = self::urlToPath($originalImage);
}
if (!$imagePath) {
return false;
}
$imagePath = self::removeImageSize($imagePath);
if (!file_exists($imagePath)) {
return false;
}
$imagePathInfo = pathinfo($imagePath);
$ext = $imagePathInfo['extension'];
$suffix = "{$width}x{$height}";
$destPath = "{$imagePathInfo['dirname']}/{$imagePathInfo['filename']}-{$suffix}.{$ext}";
if (file_exists($destPath)) {
return self::pathToUrl($destPath);
}
if (image_make_intermediate_size($imagePath, $width, $height, $crop)) {
return self::pathToUrl($destPath);
}
return $originalImage;
} | php | public static function resize($originalImage, $width, $height, $crop = true)
{
$imagePath = false;
// Image from attachment id
if (is_numeric($originalImage)) {
$imagePath = wp_get_attachment_url($originalImage);
} elseif (in_array(substr($originalImage, 0, 7), array('https:/', 'http://'))) {
$imagePath = self::urlToPath($originalImage);
}
if (!$imagePath) {
return false;
}
$imagePath = self::removeImageSize($imagePath);
if (!file_exists($imagePath)) {
return false;
}
$imagePathInfo = pathinfo($imagePath);
$ext = $imagePathInfo['extension'];
$suffix = "{$width}x{$height}";
$destPath = "{$imagePathInfo['dirname']}/{$imagePathInfo['filename']}-{$suffix}.{$ext}";
if (file_exists($destPath)) {
return self::pathToUrl($destPath);
}
if (image_make_intermediate_size($imagePath, $width, $height, $crop)) {
return self::pathToUrl($destPath);
}
return $originalImage;
} | [
"public",
"static",
"function",
"resize",
"(",
"$",
"originalImage",
",",
"$",
"width",
",",
"$",
"height",
",",
"$",
"crop",
"=",
"true",
")",
"{",
"$",
"imagePath",
"=",
"false",
";",
"// Image from attachment id",
"if",
"(",
"is_numeric",
"(",
"$",
"o... | Resizes an image to a specified size
@param integer|string $originalImage Attachment id, path or url
@param integer $width Target width
@param integer $height Target height
@param boolean $crop Crop or not?
@return string Image url | [
"Resizes",
"an",
"image",
"to",
"a",
"specified",
"size"
] | 923ca84eafa775237b97221e73a9b381fa6ddcba | https://github.com/helsingborg-stad/Municipio/blob/923ca84eafa775237b97221e73a9b381fa6ddcba/library/Helper/Image.php#L15-L51 | train |
helsingborg-stad/Municipio | library/Helper/CacheBust.php | CacheBust.getRevManifest | public static function getRevManifest($childTheme = false)
{
$themePath = ($childTheme == true) ? get_stylesheet_directory() : get_template_directory();
$jsonPath = $themePath . apply_filters('Municipio/Helper/CacheBust/RevManifestPath', '/assets/dist/rev-manifest.json');
if (file_exists($jsonPath)) {
return json_decode(file_get_contents($jsonPath), true);
} elseif (WP_DEBUG) {
echo '<div style="color:red">Error: Assets not built. Go to ' . $themePath . ' and run gulp. See '. $themePath . '/README.md for more info.</div>';
}
} | php | public static function getRevManifest($childTheme = false)
{
$themePath = ($childTheme == true) ? get_stylesheet_directory() : get_template_directory();
$jsonPath = $themePath . apply_filters('Municipio/Helper/CacheBust/RevManifestPath', '/assets/dist/rev-manifest.json');
if (file_exists($jsonPath)) {
return json_decode(file_get_contents($jsonPath), true);
} elseif (WP_DEBUG) {
echo '<div style="color:red">Error: Assets not built. Go to ' . $themePath . ' and run gulp. See '. $themePath . '/README.md for more info.</div>';
}
} | [
"public",
"static",
"function",
"getRevManifest",
"(",
"$",
"childTheme",
"=",
"false",
")",
"{",
"$",
"themePath",
"=",
"(",
"$",
"childTheme",
"==",
"true",
")",
"?",
"get_stylesheet_directory",
"(",
")",
":",
"get_template_directory",
"(",
")",
";",
"$",
... | Decode assets json to array
@param boolean $childTheme Set child or parent theme path (defaults to parent)
@return array containg assets filenames | [
"Decode",
"assets",
"json",
"to",
"array"
] | 923ca84eafa775237b97221e73a9b381fa6ddcba | https://github.com/helsingborg-stad/Municipio/blob/923ca84eafa775237b97221e73a9b381fa6ddcba/library/Helper/CacheBust.php#L45-L55 | train |
helsingborg-stad/Municipio | library/Helper/NavigationTree.php | NavigationTree.getTopLevelPages | protected function getTopLevelPages()
{
$topLevelQuery = new \WP_Query(array(
'post_parent' => 0,
'post_type' => 'page',
'post_status' => $this->postStatuses,
'orderby' => 'menu_order post_title',
'order' => 'asc',
'posts_per_page' => -1,
'meta_query' => array(
'relation' => 'AND',
array(
'relation' => 'OR',
array(
'key' => 'hide_in_menu',
'compare' => 'NOT EXISTS'
),
array(
'key' => 'hide_in_menu',
'value' => '0',
'compare' => '='
)
)
)
));
$this->topLevelPages = $topLevelQuery->posts;
return $this->topLevelPages;
} | php | protected function getTopLevelPages()
{
$topLevelQuery = new \WP_Query(array(
'post_parent' => 0,
'post_type' => 'page',
'post_status' => $this->postStatuses,
'orderby' => 'menu_order post_title',
'order' => 'asc',
'posts_per_page' => -1,
'meta_query' => array(
'relation' => 'AND',
array(
'relation' => 'OR',
array(
'key' => 'hide_in_menu',
'compare' => 'NOT EXISTS'
),
array(
'key' => 'hide_in_menu',
'value' => '0',
'compare' => '='
)
)
)
));
$this->topLevelPages = $topLevelQuery->posts;
return $this->topLevelPages;
} | [
"protected",
"function",
"getTopLevelPages",
"(",
")",
"{",
"$",
"topLevelQuery",
"=",
"new",
"\\",
"WP_Query",
"(",
"array",
"(",
"'post_parent'",
"=>",
"0",
",",
"'post_type'",
"=>",
"'page'",
",",
"'post_status'",
"=>",
"$",
"this",
"->",
"postStatuses",
... | Gets top level pages
@return void | [
"Gets",
"top",
"level",
"pages"
] | 923ca84eafa775237b97221e73a9b381fa6ddcba | https://github.com/helsingborg-stad/Municipio/blob/923ca84eafa775237b97221e73a9b381fa6ddcba/library/Helper/NavigationTree.php#L130-L158 | train |
helsingborg-stad/Municipio | library/Helper/NavigationTree.php | NavigationTree.getSecondLevelPages | protected function getSecondLevelPages()
{
$secondLevel = array();
foreach ($this->topLevelPages as $topLevelPage) {
$pages = get_posts(array(
'post_parent' => $topLevelPage->ID,
'post_type' => 'page',
'orderby' => 'menu_order post_title',
'order' => 'asc',
'posts_per_page' => -1
));
$secondLevel[$topLevelPage->ID] = $pages;
}
$this->secondLevelPages = $secondLevel;
return $secondLevel;
} | php | protected function getSecondLevelPages()
{
$secondLevel = array();
foreach ($this->topLevelPages as $topLevelPage) {
$pages = get_posts(array(
'post_parent' => $topLevelPage->ID,
'post_type' => 'page',
'orderby' => 'menu_order post_title',
'order' => 'asc',
'posts_per_page' => -1
));
$secondLevel[$topLevelPage->ID] = $pages;
}
$this->secondLevelPages = $secondLevel;
return $secondLevel;
} | [
"protected",
"function",
"getSecondLevelPages",
"(",
")",
"{",
"$",
"secondLevel",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"topLevelPages",
"as",
"$",
"topLevelPage",
")",
"{",
"$",
"pages",
"=",
"get_posts",
"(",
"array",
"(",
"'... | Gets second level pages
@return array | [
"Gets",
"second",
"level",
"pages"
] | 923ca84eafa775237b97221e73a9b381fa6ddcba | https://github.com/helsingborg-stad/Municipio/blob/923ca84eafa775237b97221e73a9b381fa6ddcba/library/Helper/NavigationTree.php#L164-L182 | train |
helsingborg-stad/Municipio | library/Helper/NavigationTree.php | NavigationTree.walk | protected function walk($pages, $depth = 1, $classes = null)
{
$this->currentDepth = $depth;
if ($this->args['sublevel']) {
$this->startWrapper($classes, $depth === 1);
}
if (!is_array($pages)) {
return;
}
foreach ($pages as $page) {
$pageId = $this->getPageId($page);
$attributes = array();
$attributes['class'] = array();
$output = true;
if (is_numeric($page)) {
$page = get_post($page);
}
if ($this->isAncestors($pageId)) {
$attributes['class'][] = 'current-node current-menu-ancestor';
if (count($this->getChildren($pageId)) > 0) {
$attributes['class'][] = 'is-expanded';
}
}
if ($this->getPageId($this->currentPage) == $pageId) {
$attributes['class'][] = 'current current-menu-item';
if (count($this->getChildren($this->currentPage->ID)) > 0 && $depth != $this->args['depth']) {
$attributes['class'][] = 'is-expanded';
}
}
if (($this->isAjaxParent && $depth === 1) || $depth < $this->args['start_depth']) {
$output = false;
}
$this->item($page, $depth, $attributes, $output);
}
if ($this->args['sublevel']) {
$this->endWrapper($depth === 1);
}
} | php | protected function walk($pages, $depth = 1, $classes = null)
{
$this->currentDepth = $depth;
if ($this->args['sublevel']) {
$this->startWrapper($classes, $depth === 1);
}
if (!is_array($pages)) {
return;
}
foreach ($pages as $page) {
$pageId = $this->getPageId($page);
$attributes = array();
$attributes['class'] = array();
$output = true;
if (is_numeric($page)) {
$page = get_post($page);
}
if ($this->isAncestors($pageId)) {
$attributes['class'][] = 'current-node current-menu-ancestor';
if (count($this->getChildren($pageId)) > 0) {
$attributes['class'][] = 'is-expanded';
}
}
if ($this->getPageId($this->currentPage) == $pageId) {
$attributes['class'][] = 'current current-menu-item';
if (count($this->getChildren($this->currentPage->ID)) > 0 && $depth != $this->args['depth']) {
$attributes['class'][] = 'is-expanded';
}
}
if (($this->isAjaxParent && $depth === 1) || $depth < $this->args['start_depth']) {
$output = false;
}
$this->item($page, $depth, $attributes, $output);
}
if ($this->args['sublevel']) {
$this->endWrapper($depth === 1);
}
} | [
"protected",
"function",
"walk",
"(",
"$",
"pages",
",",
"$",
"depth",
"=",
"1",
",",
"$",
"classes",
"=",
"null",
")",
"{",
"$",
"this",
"->",
"currentDepth",
"=",
"$",
"depth",
";",
"if",
"(",
"$",
"this",
"->",
"args",
"[",
"'sublevel'",
"]",
... | Walks pages in the menu
@param array $pages Pages to walk
@return void | [
"Walks",
"pages",
"in",
"the",
"menu"
] | 923ca84eafa775237b97221e73a9b381fa6ddcba | https://github.com/helsingborg-stad/Municipio/blob/923ca84eafa775237b97221e73a9b381fa6ddcba/library/Helper/NavigationTree.php#L189-L236 | train |
helsingborg-stad/Municipio | library/Helper/NavigationTree.php | NavigationTree.getCurrentPage | protected function getCurrentPage()
{
if (is_post_type_archive()) {
$pageForPostType = get_option('page_for_' . get_post_type());
return get_post($pageForPostType);
}
global $post;
if (!is_object($post)) {
return get_queried_object();
}
return $post;
} | php | protected function getCurrentPage()
{
if (is_post_type_archive()) {
$pageForPostType = get_option('page_for_' . get_post_type());
return get_post($pageForPostType);
}
global $post;
if (!is_object($post)) {
return get_queried_object();
}
return $post;
} | [
"protected",
"function",
"getCurrentPage",
"(",
")",
"{",
"if",
"(",
"is_post_type_archive",
"(",
")",
")",
"{",
"$",
"pageForPostType",
"=",
"get_option",
"(",
"'page_for_'",
".",
"get_post_type",
"(",
")",
")",
";",
"return",
"get_post",
"(",
"$",
"pageFor... | Gets the current page object
@return object | [
"Gets",
"the",
"current",
"page",
"object"
] | 923ca84eafa775237b97221e73a9b381fa6ddcba | https://github.com/helsingborg-stad/Municipio/blob/923ca84eafa775237b97221e73a9b381fa6ddcba/library/Helper/NavigationTree.php#L281-L295 | train |
helsingborg-stad/Municipio | library/Helper/NavigationTree.php | NavigationTree.getChildren | protected function getChildren($parent)
{
$key = array_search($parent, $this->getPageForPostTypeIds());
if ($key && is_post_type_hierarchical($key)) {
$inMenu = false;
foreach (get_field('avabile_dynamic_post_types', 'options') as $type) {
if (sanitize_title(substr($type['post_type_name'], 0, 19)) !== $key) {
continue;
}
$inMenu = $type['show_posts_in_sidebar_menu'];
}
if ($inMenu) {
return get_posts(array(
'post_type' => $key,
'post_status' => $this->postStatuses,
'post_parent' => 0,
'orderby' => 'menu_order post_title',
'order' => 'asc',
'posts_per_page' => -1,
'meta_query' => array(
'relation' => 'OR',
array(
'key' => 'hide_in_menu',
'compare' => 'NOT EXISTS'
),
array(
'key' => 'hide_in_menu',
'value' => '0',
'compare' => '='
)
)
), 'OBJECT');
}
return array();
}
return get_posts(array(
'post_parent' => $parent,
'post_type' => get_post_type($parent),
'post_status' => $this->postStatuses,
'orderby' => 'menu_order post_title',
'order' => 'asc',
'posts_per_page' => -1,
'meta_query' => array(
'relation' => 'AND',
array(
'relation' => 'OR',
array(
'key' => 'hide_in_menu',
'compare' => 'NOT EXISTS'
),
array(
'key' => 'hide_in_menu',
'value' => '0',
'compare' => '='
)
)
)
), 'OBJECT');
} | php | protected function getChildren($parent)
{
$key = array_search($parent, $this->getPageForPostTypeIds());
if ($key && is_post_type_hierarchical($key)) {
$inMenu = false;
foreach (get_field('avabile_dynamic_post_types', 'options') as $type) {
if (sanitize_title(substr($type['post_type_name'], 0, 19)) !== $key) {
continue;
}
$inMenu = $type['show_posts_in_sidebar_menu'];
}
if ($inMenu) {
return get_posts(array(
'post_type' => $key,
'post_status' => $this->postStatuses,
'post_parent' => 0,
'orderby' => 'menu_order post_title',
'order' => 'asc',
'posts_per_page' => -1,
'meta_query' => array(
'relation' => 'OR',
array(
'key' => 'hide_in_menu',
'compare' => 'NOT EXISTS'
),
array(
'key' => 'hide_in_menu',
'value' => '0',
'compare' => '='
)
)
), 'OBJECT');
}
return array();
}
return get_posts(array(
'post_parent' => $parent,
'post_type' => get_post_type($parent),
'post_status' => $this->postStatuses,
'orderby' => 'menu_order post_title',
'order' => 'asc',
'posts_per_page' => -1,
'meta_query' => array(
'relation' => 'AND',
array(
'relation' => 'OR',
array(
'key' => 'hide_in_menu',
'compare' => 'NOT EXISTS'
),
array(
'key' => 'hide_in_menu',
'value' => '0',
'compare' => '='
)
)
)
), 'OBJECT');
} | [
"protected",
"function",
"getChildren",
"(",
"$",
"parent",
")",
"{",
"$",
"key",
"=",
"array_search",
"(",
"$",
"parent",
",",
"$",
"this",
"->",
"getPageForPostTypeIds",
"(",
")",
")",
";",
"if",
"(",
"$",
"key",
"&&",
"is_post_type_hierarchical",
"(",
... | Get page children
@param integer $parent The parent page ID
@return object Page objects for children | [
"Get",
"page",
"children"
] | 923ca84eafa775237b97221e73a9b381fa6ddcba | https://github.com/helsingborg-stad/Municipio/blob/923ca84eafa775237b97221e73a9b381fa6ddcba/library/Helper/NavigationTree.php#L302-L366 | train |
helsingborg-stad/Municipio | library/Helper/NavigationTree.php | NavigationTree.isAncestors | protected function isAncestors($id)
{
$ancestors = $this->ancestors;
$baseParent = $this->getAncestors($this->currentPage);
if (is_array($baseParent) && !empty($baseParent)) {
$ancestors = array_merge($ancestors, $baseParent);
}
return in_array($id, $ancestors);
} | php | protected function isAncestors($id)
{
$ancestors = $this->ancestors;
$baseParent = $this->getAncestors($this->currentPage);
if (is_array($baseParent) && !empty($baseParent)) {
$ancestors = array_merge($ancestors, $baseParent);
}
return in_array($id, $ancestors);
} | [
"protected",
"function",
"isAncestors",
"(",
"$",
"id",
")",
"{",
"$",
"ancestors",
"=",
"$",
"this",
"->",
"ancestors",
";",
"$",
"baseParent",
"=",
"$",
"this",
"->",
"getAncestors",
"(",
"$",
"this",
"->",
"currentPage",
")",
";",
"if",
"(",
"is_arr... | Checks if a specific id is in the ancestors array
@param integer $id
@return boolean | [
"Checks",
"if",
"a",
"specific",
"id",
"is",
"in",
"the",
"ancestors",
"array"
] | 923ca84eafa775237b97221e73a9b381fa6ddcba | https://github.com/helsingborg-stad/Municipio/blob/923ca84eafa775237b97221e73a9b381fa6ddcba/library/Helper/NavigationTree.php#L413-L422 | train |
helsingborg-stad/Municipio | library/Helper/NavigationTree.php | NavigationTree.startItem | protected function startItem($item, $attributes = array(), $hasChildren = false)
{
if (!$this->shouldBeIncluded($item) || !is_object($item)) {
return;
}
$this->itemCount++;
$outputSubmenuToggle = false;
$attributes['class'][] = 'page-' . $item->ID;
if ($hasChildren && ($this->args['depth'] === -1 || $this->currentDepth < $this->args['depth'] + 1)) {
$outputSubmenuToggle = true;
if (array_search('has-children', $attributes['class']) > -1) {
unset($attributes['class'][array_search('has-children', $attributes['class'])]);
}
}
$title = isset($item->post_title) ? $item->post_title : '';
$objId = $this->getPageId($item);
if (isset($item->post_type) && $item->post_type == 'nav_menu_item') {
$title = $item->title;
}
if (!empty(get_field('custom_menu_title', $objId))) {
$title = get_field('custom_menu_title', $objId);
}
$href = get_permalink($objId);
if (isset($item->type) && $item->type == 'custom') {
$href = $item->url;
}
if ($outputSubmenuToggle) {
$this->addOutput(sprintf(
'<li%1$s><a href="%2$s">%3$s</a>',
$this->attributes($attributes),
$href,
$title
));
$this->addOutput('<button data-load-submenu="' . $objId . '"><span class="sr-only">' . __('Show submenu', 'municipio') . '</span><span class="icon"></span></button>');
} else {
$this->addOutput(sprintf(
'<li%1$s><a href="%2$s">%3$s</a>',
$this->attributes($attributes),
$href,
$title
));
}
} | php | protected function startItem($item, $attributes = array(), $hasChildren = false)
{
if (!$this->shouldBeIncluded($item) || !is_object($item)) {
return;
}
$this->itemCount++;
$outputSubmenuToggle = false;
$attributes['class'][] = 'page-' . $item->ID;
if ($hasChildren && ($this->args['depth'] === -1 || $this->currentDepth < $this->args['depth'] + 1)) {
$outputSubmenuToggle = true;
if (array_search('has-children', $attributes['class']) > -1) {
unset($attributes['class'][array_search('has-children', $attributes['class'])]);
}
}
$title = isset($item->post_title) ? $item->post_title : '';
$objId = $this->getPageId($item);
if (isset($item->post_type) && $item->post_type == 'nav_menu_item') {
$title = $item->title;
}
if (!empty(get_field('custom_menu_title', $objId))) {
$title = get_field('custom_menu_title', $objId);
}
$href = get_permalink($objId);
if (isset($item->type) && $item->type == 'custom') {
$href = $item->url;
}
if ($outputSubmenuToggle) {
$this->addOutput(sprintf(
'<li%1$s><a href="%2$s">%3$s</a>',
$this->attributes($attributes),
$href,
$title
));
$this->addOutput('<button data-load-submenu="' . $objId . '"><span class="sr-only">' . __('Show submenu', 'municipio') . '</span><span class="icon"></span></button>');
} else {
$this->addOutput(sprintf(
'<li%1$s><a href="%2$s">%3$s</a>',
$this->attributes($attributes),
$href,
$title
));
}
} | [
"protected",
"function",
"startItem",
"(",
"$",
"item",
",",
"$",
"attributes",
"=",
"array",
"(",
")",
",",
"$",
"hasChildren",
"=",
"false",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"shouldBeIncluded",
"(",
"$",
"item",
")",
"||",
"!",
"is_obje... | Opens a menu item
@param object $item The menu item
@param array $classes Classes
@return void | [
"Opens",
"a",
"menu",
"item"
] | 923ca84eafa775237b97221e73a9b381fa6ddcba | https://github.com/helsingborg-stad/Municipio/blob/923ca84eafa775237b97221e73a9b381fa6ddcba/library/Helper/NavigationTree.php#L444-L497 | train |
helsingborg-stad/Municipio | library/Helper/NavigationTree.php | NavigationTree.shouldBeIncluded | public function shouldBeIncluded($item)
{
if (!is_object($item)) {
return false;
}
$pageId = $this->getPageId($item);
$showInMenu = get_field('hide_in_menu', $pageId) ? !get_field('hide_in_menu', $pageId) : true;
$isNotTopLevelItem = !($item->post_type === 'page' && isset($item->post_parent) && $item->post_parent === 0);
$showTopLevel = $this->args['include_top_level'];
return ($showTopLevel || $isNotTopLevelItem) && $showInMenu;
} | php | public function shouldBeIncluded($item)
{
if (!is_object($item)) {
return false;
}
$pageId = $this->getPageId($item);
$showInMenu = get_field('hide_in_menu', $pageId) ? !get_field('hide_in_menu', $pageId) : true;
$isNotTopLevelItem = !($item->post_type === 'page' && isset($item->post_parent) && $item->post_parent === 0);
$showTopLevel = $this->args['include_top_level'];
return ($showTopLevel || $isNotTopLevelItem) && $showInMenu;
} | [
"public",
"function",
"shouldBeIncluded",
"(",
"$",
"item",
")",
"{",
"if",
"(",
"!",
"is_object",
"(",
"$",
"item",
")",
")",
"{",
"return",
"false",
";",
"}",
"$",
"pageId",
"=",
"$",
"this",
"->",
"getPageId",
"(",
"$",
"item",
")",
";",
"$",
... | Datermines if page should be included in the menu or not
@param object $item The menu item
@return boolean | [
"Datermines",
"if",
"page",
"should",
"be",
"included",
"in",
"the",
"menu",
"or",
"not"
] | 923ca84eafa775237b97221e73a9b381fa6ddcba | https://github.com/helsingborg-stad/Municipio/blob/923ca84eafa775237b97221e73a9b381fa6ddcba/library/Helper/NavigationTree.php#L592-L604 | train |
helsingborg-stad/Municipio | library/Helper/ReCaptcha.php | ReCaptcha.controlReCaptcha | public static function controlReCaptcha($response) : bool
{
$g_recaptcha_secret = defined('G_RECAPTCHA_SECRET') ? G_RECAPTCHA_SECRET : '';
// Make a GET request to the Google reCAPTCHA server
$request = wp_remote_get('https://www.google.com/recaptcha/api/siteverify?secret=' . $g_recaptcha_secret . '&response=' . $response . '&remoteip=' . $_SERVER["REMOTE_ADDR"]);
// Get the request response body
$response_body = wp_remote_retrieve_body($request);
$result = json_decode($response_body, true);
return $result['success'];
} | php | public static function controlReCaptcha($response) : bool
{
$g_recaptcha_secret = defined('G_RECAPTCHA_SECRET') ? G_RECAPTCHA_SECRET : '';
// Make a GET request to the Google reCAPTCHA server
$request = wp_remote_get('https://www.google.com/recaptcha/api/siteverify?secret=' . $g_recaptcha_secret . '&response=' . $response . '&remoteip=' . $_SERVER["REMOTE_ADDR"]);
// Get the request response body
$response_body = wp_remote_retrieve_body($request);
$result = json_decode($response_body, true);
return $result['success'];
} | [
"public",
"static",
"function",
"controlReCaptcha",
"(",
"$",
"response",
")",
":",
"bool",
"{",
"$",
"g_recaptcha_secret",
"=",
"defined",
"(",
"'G_RECAPTCHA_SECRET'",
")",
"?",
"G_RECAPTCHA_SECRET",
":",
"''",
";",
"// Make a GET request to the Google reCAPTCHA server... | Check if Google reCaptcha request is valid
@param string $response Google reCaptcha response
@return bool If valid or not | [
"Check",
"if",
"Google",
"reCaptcha",
"request",
"is",
"valid"
] | 923ca84eafa775237b97221e73a9b381fa6ddcba | https://github.com/helsingborg-stad/Municipio/blob/923ca84eafa775237b97221e73a9b381fa6ddcba/library/Helper/ReCaptcha.php#L12-L24 | train |
helsingborg-stad/Municipio | library/Helper/PostType.php | PostType.getPublic | public static function getPublic($filter = array())
{
$postTypes = array();
foreach (get_post_types() as $key => $postType) {
$args = get_post_type_object($postType);
if (!$args->public || $args->name === 'page') {
continue;
}
$postTypes[$postType] = $args;
}
if (!empty($filter)) {
$postTypes = array_filter($postTypes, function ($item) use ($filter) {
if (substr($item, 0, 4) === 'mod-') {
return false;
}
return !in_array($item, $filter);
});
}
return $postTypes;
} | php | public static function getPublic($filter = array())
{
$postTypes = array();
foreach (get_post_types() as $key => $postType) {
$args = get_post_type_object($postType);
if (!$args->public || $args->name === 'page') {
continue;
}
$postTypes[$postType] = $args;
}
if (!empty($filter)) {
$postTypes = array_filter($postTypes, function ($item) use ($filter) {
if (substr($item, 0, 4) === 'mod-') {
return false;
}
return !in_array($item, $filter);
});
}
return $postTypes;
} | [
"public",
"static",
"function",
"getPublic",
"(",
"$",
"filter",
"=",
"array",
"(",
")",
")",
"{",
"$",
"postTypes",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"get_post_types",
"(",
")",
"as",
"$",
"key",
"=>",
"$",
"postType",
")",
"{",
"$",
"a... | Get public post types
@param array $filter Don't get these
@return array | [
"Get",
"public",
"post",
"types"
] | 923ca84eafa775237b97221e73a9b381fa6ddcba | https://github.com/helsingborg-stad/Municipio/blob/923ca84eafa775237b97221e73a9b381fa6ddcba/library/Helper/PostType.php#L12-L37 | train |
helsingborg-stad/Municipio | library/Helper/PostType.php | PostType.postTypeRestUrl | public static function postTypeRestUrl($postType = null)
{
$restUrl = null;
$postType = !$postType ? get_post_type() : $postType;
$postTypeObj = get_post_type_object($postType);
if ($postTypeObj && !empty($postTypeObj->show_in_rest) && !empty($postTypeObj->rest_base)) {
$restUrl = esc_url_raw(get_rest_url() . 'wp/v2/' . $postTypeObj->rest_base);
}
return $restUrl;
} | php | public static function postTypeRestUrl($postType = null)
{
$restUrl = null;
$postType = !$postType ? get_post_type() : $postType;
$postTypeObj = get_post_type_object($postType);
if ($postTypeObj && !empty($postTypeObj->show_in_rest) && !empty($postTypeObj->rest_base)) {
$restUrl = esc_url_raw(get_rest_url() . 'wp/v2/' . $postTypeObj->rest_base);
}
return $restUrl;
} | [
"public",
"static",
"function",
"postTypeRestUrl",
"(",
"$",
"postType",
"=",
"null",
")",
"{",
"$",
"restUrl",
"=",
"null",
";",
"$",
"postType",
"=",
"!",
"$",
"postType",
"?",
"get_post_type",
"(",
")",
":",
"$",
"postType",
";",
"$",
"postTypeObj",
... | Get post type REST URL
@param string|null $postType Post type slug
@return string Post types REST URL | [
"Get",
"post",
"type",
"REST",
"URL"
] | 923ca84eafa775237b97221e73a9b381fa6ddcba | https://github.com/helsingborg-stad/Municipio/blob/923ca84eafa775237b97221e73a9b381fa6ddcba/library/Helper/PostType.php#L44-L55 | train |
helsingborg-stad/Municipio | library/Search/Algolia.php | Algolia.excludeFromSearchCheckbox | public function excludeFromSearchCheckbox()
{
global $post;
//Only show if not set to not index
if (!$this->shouldIndexPost(true, $post, false)) {
return false;
}
if (is_object($post) && isset($post->ID)) {
$checked = checked(true, get_post_meta($post->ID, 'exclude_from_search', true), false);
echo '
<div class="misc-pub-section">
<label><input type="checkbox" name="algolia-exclude-from-search" value="true" ' . $checked . '> ' . __('Exclude from search', 'municipio') . '</label>
</div>
';
}
} | php | public function excludeFromSearchCheckbox()
{
global $post;
//Only show if not set to not index
if (!$this->shouldIndexPost(true, $post, false)) {
return false;
}
if (is_object($post) && isset($post->ID)) {
$checked = checked(true, get_post_meta($post->ID, 'exclude_from_search', true), false);
echo '
<div class="misc-pub-section">
<label><input type="checkbox" name="algolia-exclude-from-search" value="true" ' . $checked . '> ' . __('Exclude from search', 'municipio') . '</label>
</div>
';
}
} | [
"public",
"function",
"excludeFromSearchCheckbox",
"(",
")",
"{",
"global",
"$",
"post",
";",
"//Only show if not set to not index",
"if",
"(",
"!",
"$",
"this",
"->",
"shouldIndexPost",
"(",
"true",
",",
"$",
"post",
",",
"false",
")",
")",
"{",
"return",
"... | Adds form field for exclude from search
@return void | [
"Adds",
"form",
"field",
"for",
"exclude",
"from",
"search"
] | 923ca84eafa775237b97221e73a9b381fa6ddcba | https://github.com/helsingborg-stad/Municipio/blob/923ca84eafa775237b97221e73a9b381fa6ddcba/library/Search/Algolia.php#L35-L52 | train |
helsingborg-stad/Municipio | library/Search/Algolia.php | Algolia.saveExcludeFromSearch | public function saveExcludeFromSearch($postId)
{
if (!isset($_POST['algolia-exclude-from-search']) || $_POST['algolia-exclude-from-search'] != 'true') {
delete_post_meta($postId, 'exclude_from_search');
return;
}
update_post_meta($postId, 'exclude_from_search', true);
} | php | public function saveExcludeFromSearch($postId)
{
if (!isset($_POST['algolia-exclude-from-search']) || $_POST['algolia-exclude-from-search'] != 'true') {
delete_post_meta($postId, 'exclude_from_search');
return;
}
update_post_meta($postId, 'exclude_from_search', true);
} | [
"public",
"function",
"saveExcludeFromSearch",
"(",
"$",
"postId",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"_POST",
"[",
"'algolia-exclude-from-search'",
"]",
")",
"||",
"$",
"_POST",
"[",
"'algolia-exclude-from-search'",
"]",
"!=",
"'true'",
")",
"{",
... | Saves the "exclude from search" value
@param int $postId The post id
@return void | [
"Saves",
"the",
"exclude",
"from",
"search",
"value"
] | 923ca84eafa775237b97221e73a9b381fa6ddcba | https://github.com/helsingborg-stad/Municipio/blob/923ca84eafa775237b97221e73a9b381fa6ddcba/library/Search/Algolia.php#L60-L67 | train |
helsingborg-stad/Municipio | library/Search/Google.php | Google.search | public function search($keyword = null, $startingIndex = 1)
{
// Handle if keyword is null or empty string
if ($keyword === null || $keyword === '') {
return false;
}
$url = 'https://www.googleapis.com/customsearch/v1?key=' . $this->apiKey .
'&cx=' . $this->apiCx .
'&q=' . urlencode($keyword) .
'&hl=sv&siteSearchFilter=i&alt=json&start=' . $startingIndex;
$results = $this->request($url);
return $results;
} | php | public function search($keyword = null, $startingIndex = 1)
{
// Handle if keyword is null or empty string
if ($keyword === null || $keyword === '') {
return false;
}
$url = 'https://www.googleapis.com/customsearch/v1?key=' . $this->apiKey .
'&cx=' . $this->apiCx .
'&q=' . urlencode($keyword) .
'&hl=sv&siteSearchFilter=i&alt=json&start=' . $startingIndex;
$results = $this->request($url);
return $results;
} | [
"public",
"function",
"search",
"(",
"$",
"keyword",
"=",
"null",
",",
"$",
"startingIndex",
"=",
"1",
")",
"{",
"// Handle if keyword is null or empty string",
"if",
"(",
"$",
"keyword",
"===",
"null",
"||",
"$",
"keyword",
"===",
"''",
")",
"{",
"return",
... | Perform a search with the Google Custom Search API
@param string $keyword The search query/keyword
@param integer $start Starting search result index (used for pagination)
@return object The search results | [
"Perform",
"a",
"search",
"with",
"the",
"Google",
"Custom",
"Search",
"API"
] | 923ca84eafa775237b97221e73a9b381fa6ddcba | https://github.com/helsingborg-stad/Municipio/blob/923ca84eafa775237b97221e73a9b381fa6ddcba/library/Search/Google.php#L35-L49 | train |
helsingborg-stad/Municipio | library/Search/Google.php | Google.request | public function request($url)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
curl_setopt($ch, CURLOPT_REFERER, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
$result = curl_exec($ch);
curl_close($ch);
return json_decode($result);
} | php | public function request($url)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
curl_setopt($ch, CURLOPT_REFERER, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
$result = curl_exec($ch);
curl_close($ch);
return json_decode($result);
} | [
"public",
"function",
"request",
"(",
"$",
"url",
")",
"{",
"$",
"ch",
"=",
"curl_init",
"(",
")",
";",
"curl_setopt",
"(",
"$",
"ch",
",",
"CURLOPT_URL",
",",
"$",
"url",
")",
";",
"curl_setopt",
"(",
"$",
"ch",
",",
"CURLOPT_SSL_VERIFYHOST",
",",
"... | Curl the Google API to get the search results
@param string $url The url to curl
@return object The result | [
"Curl",
"the",
"Google",
"API",
"to",
"get",
"the",
"search",
"results"
] | 923ca84eafa775237b97221e73a9b381fa6ddcba | https://github.com/helsingborg-stad/Municipio/blob/923ca84eafa775237b97221e73a9b381fa6ddcba/library/Search/Google.php#L56-L70 | train |
helsingborg-stad/Municipio | library/Search/Google.php | Google.getModifiedDate | public function getModifiedDate($item)
{
if (!isset($item->pagemap)) {
return null;
}
$meta = $item->pagemap->metatags[0];
$dateMod = null;
if (isset($meta->moddate)) {
$dateMod = $meta->moddate;
} elseif (isset($meta->pubdate)) {
$dateMod = $meta->pubdate;
} elseif (isset($meta->{'last-modified'})) {
$dateMod = $meta->{'last-modified'};
}
$dateMod = $this->convertDate($dateMod);
return $dateMod;
} | php | public function getModifiedDate($item)
{
if (!isset($item->pagemap)) {
return null;
}
$meta = $item->pagemap->metatags[0];
$dateMod = null;
if (isset($meta->moddate)) {
$dateMod = $meta->moddate;
} elseif (isset($meta->pubdate)) {
$dateMod = $meta->pubdate;
} elseif (isset($meta->{'last-modified'})) {
$dateMod = $meta->{'last-modified'};
}
$dateMod = $this->convertDate($dateMod);
return $dateMod;
} | [
"public",
"function",
"getModifiedDate",
"(",
"$",
"item",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"item",
"->",
"pagemap",
")",
")",
"{",
"return",
"null",
";",
"}",
"$",
"meta",
"=",
"$",
"item",
"->",
"pagemap",
"->",
"metatags",
"[",
"0",
... | Gets the modified date for an item
@param object $item The item
@return string The modified date | [
"Gets",
"the",
"modified",
"date",
"for",
"an",
"item"
] | 923ca84eafa775237b97221e73a9b381fa6ddcba | https://github.com/helsingborg-stad/Municipio/blob/923ca84eafa775237b97221e73a9b381fa6ddcba/library/Search/Google.php#L99-L119 | train |
helsingborg-stad/Municipio | library/Helper/Cache.php | Cache.start | public function start()
{
if (!$this->isActive()) {
return true;
}
if (!$this->hasCache()) {
ob_start();
return true;
}
$this->getCache(true);
return false;
} | php | public function start()
{
if (!$this->isActive()) {
return true;
}
if (!$this->hasCache()) {
ob_start();
return true;
}
$this->getCache(true);
return false;
} | [
"public",
"function",
"start",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"isActive",
"(",
")",
")",
"{",
"return",
"true",
";",
"}",
"if",
"(",
"!",
"$",
"this",
"->",
"hasCache",
"(",
")",
")",
"{",
"ob_start",
"(",
")",
";",
"return",... | Starts the "cache engine"
@return boolean Returns true if engine started or inactivated, returns false if previous cache is loaded | [
"Starts",
"the",
"cache",
"engine"
] | 923ca84eafa775237b97221e73a9b381fa6ddcba | https://github.com/helsingborg-stad/Municipio/blob/923ca84eafa775237b97221e73a9b381fa6ddcba/library/Helper/Cache.php#L94-L107 | train |
helsingborg-stad/Municipio | library/Helper/Cache.php | Cache.stop | public function stop()
{
if (!$this->isActive() || $this->hasCache()) {
return false;
}
// Get output buffer and save to cache
$return_data = ob_get_clean();
if (!empty($return_data)) {
$cacheArray = (array) wp_cache_get($this->postId, self::getKeyGroup());
$cacheArray[$this->hash] = $return_data.$this->fragmentTag();
wp_cache_delete($this->postId, self::getKeyGroup());
wp_cache_add($this->postId, array_filter($cacheArray), self::getKeyGroup(), $this->ttl);
}
echo $return_data;
return true;
} | php | public function stop()
{
if (!$this->isActive() || $this->hasCache()) {
return false;
}
// Get output buffer and save to cache
$return_data = ob_get_clean();
if (!empty($return_data)) {
$cacheArray = (array) wp_cache_get($this->postId, self::getKeyGroup());
$cacheArray[$this->hash] = $return_data.$this->fragmentTag();
wp_cache_delete($this->postId, self::getKeyGroup());
wp_cache_add($this->postId, array_filter($cacheArray), self::getKeyGroup(), $this->ttl);
}
echo $return_data;
return true;
} | [
"public",
"function",
"stop",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"isActive",
"(",
")",
"||",
"$",
"this",
"->",
"hasCache",
"(",
")",
")",
"{",
"return",
"false",
";",
"}",
"// Get output buffer and save to cache",
"$",
"return_data",
"=",... | Stops the cache engine and saves the output buffer to the cache
@return boolean | [
"Stops",
"the",
"cache",
"engine",
"and",
"saves",
"the",
"output",
"buffer",
"to",
"the",
"cache"
] | 923ca84eafa775237b97221e73a9b381fa6ddcba | https://github.com/helsingborg-stad/Municipio/blob/923ca84eafa775237b97221e73a9b381fa6ddcba/library/Helper/Cache.php#L113-L134 | train |
helsingborg-stad/Municipio | library/Helper/Cache.php | Cache.createShortHash | private function createShortHash($input, $keysOnly = false)
{
if ($keysOnly === true && (is_array($input) || is_object($input))) {
$input = array_keys($input);
}
if (is_array($input) || is_object($input)) {
$input = substr(base_convert(md5(serialize($input)), 16, 32), 0, 12);
return $input;
}
$input = substr(base_convert(md5($input), 16, 32), 0, 12);
return $input;
} | php | private function createShortHash($input, $keysOnly = false)
{
if ($keysOnly === true && (is_array($input) || is_object($input))) {
$input = array_keys($input);
}
if (is_array($input) || is_object($input)) {
$input = substr(base_convert(md5(serialize($input)), 16, 32), 0, 12);
return $input;
}
$input = substr(base_convert(md5($input), 16, 32), 0, 12);
return $input;
} | [
"private",
"function",
"createShortHash",
"(",
"$",
"input",
",",
"$",
"keysOnly",
"=",
"false",
")",
"{",
"if",
"(",
"$",
"keysOnly",
"===",
"true",
"&&",
"(",
"is_array",
"(",
"$",
"input",
")",
"||",
"is_object",
"(",
"$",
"input",
")",
")",
")",
... | Create a short hash from a value
@param string $input Key
@param boolean $keysOnly Set to true for keys only
@return string Hash | [
"Create",
"a",
"short",
"hash",
"from",
"a",
"value"
] | 923ca84eafa775237b97221e73a9b381fa6ddcba | https://github.com/helsingborg-stad/Municipio/blob/923ca84eafa775237b97221e73a9b381fa6ddcba/library/Helper/Cache.php#L197-L210 | train |
helsingborg-stad/Municipio | library/Content/PostFilters.php | PostFilters.getPostType | public function getPostType()
{
global $wp_query;
// If taxonomy or category page and post type not isset then it's the "post" post type
if (is_home() || ((is_tax() || is_category() || is_tag()) && is_a(get_queried_object(),
'WP_Term') && !get_post_type())) {
return 'post';
}
$postType = isset($wp_query->query['post_type']) ? $wp_query->query['post_type'] : false;
if (!$postType && isset($wp_query->query['category_name']) && !empty($wp_query->query['category_name'])) {
$postType = 'post';
}
if (is_array($postType)) {
$postType = end($postType);
}
return $postType;
} | php | public function getPostType()
{
global $wp_query;
// If taxonomy or category page and post type not isset then it's the "post" post type
if (is_home() || ((is_tax() || is_category() || is_tag()) && is_a(get_queried_object(),
'WP_Term') && !get_post_type())) {
return 'post';
}
$postType = isset($wp_query->query['post_type']) ? $wp_query->query['post_type'] : false;
if (!$postType && isset($wp_query->query['category_name']) && !empty($wp_query->query['category_name'])) {
$postType = 'post';
}
if (is_array($postType)) {
$postType = end($postType);
}
return $postType;
} | [
"public",
"function",
"getPostType",
"(",
")",
"{",
"global",
"$",
"wp_query",
";",
"// If taxonomy or category page and post type not isset then it's the \"post\" post type",
"if",
"(",
"is_home",
"(",
")",
"||",
"(",
"(",
"is_tax",
"(",
")",
"||",
"is_category",
"("... | Get post type
@return string | [
"Get",
"post",
"type"
] | 923ca84eafa775237b97221e73a9b381fa6ddcba | https://github.com/helsingborg-stad/Municipio/blob/923ca84eafa775237b97221e73a9b381fa6ddcba/library/Content/PostFilters.php#L26-L46 | train |
helsingborg-stad/Municipio | library/Content/PostFilters.php | PostFilters.initFilters | public function initFilters()
{
//Only run on frontend
if (is_admin()) {
return;
}
global $wp_query;
if ((is_category() || is_tax() || is_tag()) && !get_post_type()) {
$postType = 'post';
}
$postType = get_post_type();
if (!$postType && isset($wp_query->query['post_type'])) {
$postType = $wp_query->query['post_type'];
}
if (!$postType) {
return;
}
$queriedObject = get_queried_object();
$objectId = null;
if (isset($queriedObject->ID)) {
$objectId = $queriedObject->ID;
}
$pageForPosts = get_option('page_for_' . get_post_type());
if (($pageForPosts !== $objectId && !is_archive() && !is_post_type_archive() && !is_home() && !is_category() && !is_tax() && !is_tag()) || is_admin()) {
return;
}
add_action('Municipio/viewData', function ($data) use ($wp_query, $postType) {
//Get current post type enabledTaxonomyFilters
if (!isset($data['postType']) || !$data['postType']) {
$data['postType'] = $postType;
}
//Get header filters
if ($enabledHeaderFilters = get_field('archive_' . $data['postType'] . '_post_filters_header', 'option')) {
$data['enabledHeaderFilters'] = $enabledHeaderFilters;
} else {
$data['enabledHeaderFilters'] = array();
}
//Get taxonomy filters
if ($enabledTaxonomyFilters = $this->getEnabledTaxonomies($data['postType'])) {
$data['enabledTaxonomyFilters'] = $enabledTaxonomyFilters;
} else {
$data['enabledTaxonomyFilters'] = array();
}
//Is query string present?
$data['queryString'] = (isset($_SERVER['QUERY_STRING']) && !empty($_SERVER['QUERY_STRING'])) ? true : false;
//The archive url
$data['archiveUrl'] = $this->getArchiveSlug($postType);
$data['searchQuery'] = $this->getSearchQuery();
return $data;
});
} | php | public function initFilters()
{
//Only run on frontend
if (is_admin()) {
return;
}
global $wp_query;
if ((is_category() || is_tax() || is_tag()) && !get_post_type()) {
$postType = 'post';
}
$postType = get_post_type();
if (!$postType && isset($wp_query->query['post_type'])) {
$postType = $wp_query->query['post_type'];
}
if (!$postType) {
return;
}
$queriedObject = get_queried_object();
$objectId = null;
if (isset($queriedObject->ID)) {
$objectId = $queriedObject->ID;
}
$pageForPosts = get_option('page_for_' . get_post_type());
if (($pageForPosts !== $objectId && !is_archive() && !is_post_type_archive() && !is_home() && !is_category() && !is_tax() && !is_tag()) || is_admin()) {
return;
}
add_action('Municipio/viewData', function ($data) use ($wp_query, $postType) {
//Get current post type enabledTaxonomyFilters
if (!isset($data['postType']) || !$data['postType']) {
$data['postType'] = $postType;
}
//Get header filters
if ($enabledHeaderFilters = get_field('archive_' . $data['postType'] . '_post_filters_header', 'option')) {
$data['enabledHeaderFilters'] = $enabledHeaderFilters;
} else {
$data['enabledHeaderFilters'] = array();
}
//Get taxonomy filters
if ($enabledTaxonomyFilters = $this->getEnabledTaxonomies($data['postType'])) {
$data['enabledTaxonomyFilters'] = $enabledTaxonomyFilters;
} else {
$data['enabledTaxonomyFilters'] = array();
}
//Is query string present?
$data['queryString'] = (isset($_SERVER['QUERY_STRING']) && !empty($_SERVER['QUERY_STRING'])) ? true : false;
//The archive url
$data['archiveUrl'] = $this->getArchiveSlug($postType);
$data['searchQuery'] = $this->getSearchQuery();
return $data;
});
} | [
"public",
"function",
"initFilters",
"(",
")",
"{",
"//Only run on frontend",
"if",
"(",
"is_admin",
"(",
")",
")",
"{",
"return",
";",
"}",
"global",
"$",
"wp_query",
";",
"if",
"(",
"(",
"is_category",
"(",
")",
"||",
"is_tax",
"(",
")",
"||",
"is_ta... | Initialize the post filter UI
@return void | [
"Initialize",
"the",
"post",
"filter",
"UI"
] | 923ca84eafa775237b97221e73a9b381fa6ddcba | https://github.com/helsingborg-stad/Municipio/blob/923ca84eafa775237b97221e73a9b381fa6ddcba/library/Content/PostFilters.php#L52-L119 | train |
helsingborg-stad/Municipio | library/Content/PostFilters.php | PostFilters.getSearchQuery | public function getSearchQuery()
{
$searchQuery = '';
if (!empty(get_search_query())) {
$searchQuery = get_search_query();
} elseif (!empty($_GET['s'])) {
$searchQuery = esc_attr($_GET['s']);
}
return $searchQuery;
} | php | public function getSearchQuery()
{
$searchQuery = '';
if (!empty(get_search_query())) {
$searchQuery = get_search_query();
} elseif (!empty($_GET['s'])) {
$searchQuery = esc_attr($_GET['s']);
}
return $searchQuery;
} | [
"public",
"function",
"getSearchQuery",
"(",
")",
"{",
"$",
"searchQuery",
"=",
"''",
";",
"if",
"(",
"!",
"empty",
"(",
"get_search_query",
"(",
")",
")",
")",
"{",
"$",
"searchQuery",
"=",
"get_search_query",
"(",
")",
";",
"}",
"elseif",
"(",
"!",
... | Returns escaped search query
@return string Search query | [
"Returns",
"escaped",
"search",
"query"
] | 923ca84eafa775237b97221e73a9b381fa6ddcba | https://github.com/helsingborg-stad/Municipio/blob/923ca84eafa775237b97221e73a9b381fa6ddcba/library/Content/PostFilters.php#L125-L135 | train |
helsingborg-stad/Municipio | library/Content/PostFilters.php | PostFilters.sortTerms | public static function sortTerms($terms)
{
$sort_terms = array();
foreach ($terms as $term) {
$sort_terms[$term->name] = $term;
}
uksort($sort_terms, 'strnatcmp');
return $sort_terms;
} | php | public static function sortTerms($terms)
{
$sort_terms = array();
foreach ($terms as $term) {
$sort_terms[$term->name] = $term;
}
uksort($sort_terms, 'strnatcmp');
return $sort_terms;
} | [
"public",
"static",
"function",
"sortTerms",
"(",
"$",
"terms",
")",
"{",
"$",
"sort_terms",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"terms",
"as",
"$",
"term",
")",
"{",
"$",
"sort_terms",
"[",
"$",
"term",
"->",
"name",
"]",
"=",
"$",
... | Trying to sort terms natural
@param $terms
@return array | [
"Trying",
"to",
"sort",
"terms",
"natural"
] | 923ca84eafa775237b97221e73a9b381fa6ddcba | https://github.com/helsingborg-stad/Municipio/blob/923ca84eafa775237b97221e73a9b381fa6ddcba/library/Content/PostFilters.php#L157-L166 | train |
helsingborg-stad/Municipio | library/Content/PostFilters.php | PostFilters.enablePostTypeArchiveSearch | public function enablePostTypeArchiveSearch($template)
{
$template = \Municipio\Helper\Template::locateTemplate($template);
if ((is_post_type_archive() || is_category() || is_date() || is_tax() || is_tag()) && is_search()) {
$archiveTemplate = \Municipio\Helper\Template::locateTemplate('archive-' . get_post_type() . '.blade.php');
if (!$archiveTemplate) {
$archiveTemplate = \Municipio\Helper\Template::locateTemplate('archive.blade.php');
}
$template = $archiveTemplate;
}
return $template;
} | php | public function enablePostTypeArchiveSearch($template)
{
$template = \Municipio\Helper\Template::locateTemplate($template);
if ((is_post_type_archive() || is_category() || is_date() || is_tax() || is_tag()) && is_search()) {
$archiveTemplate = \Municipio\Helper\Template::locateTemplate('archive-' . get_post_type() . '.blade.php');
if (!$archiveTemplate) {
$archiveTemplate = \Municipio\Helper\Template::locateTemplate('archive.blade.php');
}
$template = $archiveTemplate;
}
return $template;
} | [
"public",
"function",
"enablePostTypeArchiveSearch",
"(",
"$",
"template",
")",
"{",
"$",
"template",
"=",
"\\",
"Municipio",
"\\",
"Helper",
"\\",
"Template",
"::",
"locateTemplate",
"(",
"$",
"template",
")",
";",
"if",
"(",
"(",
"is_post_type_archive",
"(",... | Use correct template when filtering a post type archive
@param string $template Template path
@return string Template path | [
"Use",
"correct",
"template",
"when",
"filtering",
"a",
"post",
"type",
"archive"
] | 923ca84eafa775237b97221e73a9b381fa6ddcba | https://github.com/helsingborg-stad/Municipio/blob/923ca84eafa775237b97221e73a9b381fa6ddcba/library/Content/PostFilters.php#L327-L342 | train |
helsingborg-stad/Municipio | library/Content/PostFilters.php | PostFilters.doPostTaxonomyFiltering | public function doPostTaxonomyFiltering($query)
{
// Do not execute this in admin view
if (is_admin() || !(is_archive() || is_home() || is_category() || is_tax() || is_tag()) || !$query->is_main_query()) {
return $query;
}
$postType = $this->getPostType();
$filterable = $this->getEnabledTaxonomies($postType, false);
if (empty($filterable)) {
return $query;
}
$taxQuery = array('relation' => 'AND');
foreach ($filterable as $key => $value) {
if (!isset($_GET['filter'][$key]) || empty($_GET['filter'][$key]) || $_GET['filter'][$key] === '-1') {
continue;
}
$terms = (array)$_GET['filter'][$key];
$taxQuery[] = array(
'taxonomy' => $key,
'field' => 'slug',
'terms' => $terms,
'operator' => 'IN'
);
}
if (is_tax() || is_category() || is_tag()) {
$taxQuery = array(
'relation' => 'AND',
array(
'relation' => 'AND',
array(
'taxonomy' => get_queried_object()->taxonomy,
'field' => 'slug',
'terms' => (array)get_queried_object()->slug,
'operator' => 'IN'
)
),
$taxQuery
);
}
$taxQuery = apply_filters('Municipio/archive/tax_query', $taxQuery, $query);
$query->set('tax_query', $taxQuery);
return $query;
} | php | public function doPostTaxonomyFiltering($query)
{
// Do not execute this in admin view
if (is_admin() || !(is_archive() || is_home() || is_category() || is_tax() || is_tag()) || !$query->is_main_query()) {
return $query;
}
$postType = $this->getPostType();
$filterable = $this->getEnabledTaxonomies($postType, false);
if (empty($filterable)) {
return $query;
}
$taxQuery = array('relation' => 'AND');
foreach ($filterable as $key => $value) {
if (!isset($_GET['filter'][$key]) || empty($_GET['filter'][$key]) || $_GET['filter'][$key] === '-1') {
continue;
}
$terms = (array)$_GET['filter'][$key];
$taxQuery[] = array(
'taxonomy' => $key,
'field' => 'slug',
'terms' => $terms,
'operator' => 'IN'
);
}
if (is_tax() || is_category() || is_tag()) {
$taxQuery = array(
'relation' => 'AND',
array(
'relation' => 'AND',
array(
'taxonomy' => get_queried_object()->taxonomy,
'field' => 'slug',
'terms' => (array)get_queried_object()->slug,
'operator' => 'IN'
)
),
$taxQuery
);
}
$taxQuery = apply_filters('Municipio/archive/tax_query', $taxQuery, $query);
$query->set('tax_query', $taxQuery);
return $query;
} | [
"public",
"function",
"doPostTaxonomyFiltering",
"(",
"$",
"query",
")",
"{",
"// Do not execute this in admin view",
"if",
"(",
"is_admin",
"(",
")",
"||",
"!",
"(",
"is_archive",
"(",
")",
"||",
"is_home",
"(",
")",
"||",
"is_category",
"(",
")",
"||",
"is... | Do taxonomy fitering
@param object $query Query object
@return object Modified query | [
"Do",
"taxonomy",
"fitering"
] | 923ca84eafa775237b97221e73a9b381fa6ddcba | https://github.com/helsingborg-stad/Municipio/blob/923ca84eafa775237b97221e73a9b381fa6ddcba/library/Content/PostFilters.php#L349-L400 | train |
helsingborg-stad/Municipio | library/Content/PostFilters.php | PostFilters.doPostOrdering | public function doPostOrdering($query)
{
// Do not execute this in admin view
if (is_admin() || !(is_archive() || is_home()) || !$query->is_main_query()) {
return $query;
}
$isMetaQuery = false;
$posttype = $query->get('post_type');
if (empty($posttype)) {
$posttype = 'post';
}
// Get orderby key, default to post_date
$orderby = (isset($_GET['orderby']) && !empty($_GET['orderby'])) ? sanitize_text_field($_GET['orderby']) : get_field('archive_' . sanitize_title($posttype) . '_sort_key',
'option');
if (empty($orderby)) {
$orderby = 'post_date';
}
if (in_array($orderby, array('post_date', 'post_modified', 'post_title'))) {
$orderby = str_replace('post_', '', $orderby);
} else {
$isMetaQuery = true;
}
// Get orderby order, default to desc
$order = (isset($_GET['order']) && !empty($_GET['order'])) ? sanitize_text_field($_GET['order']) : get_field('archive_' . sanitize_title($posttype) . '_sort_order',
'option');
if (empty($order) || !in_array(strtolower($order), array('asc', 'desc'))) {
$order = 'desc';
}
$query->set('order', $order);
// Return if not meta query
if (!$isMetaQuery) {
$query->set('orderby', $orderby);
return $query;
}
if (isset($_GET['orderby']) && $_GET['orderby'] == 'meta_key' && isset($_GET['meta_key']) && !empty($_GET['meta_key'])) {
$orderby = sanitize_text_field($_GET['meta_key']);
}
// Continue if meta query
$query->set('meta_key', $orderby);
$query->set('orderby', 'meta_value');
return $query;
} | php | public function doPostOrdering($query)
{
// Do not execute this in admin view
if (is_admin() || !(is_archive() || is_home()) || !$query->is_main_query()) {
return $query;
}
$isMetaQuery = false;
$posttype = $query->get('post_type');
if (empty($posttype)) {
$posttype = 'post';
}
// Get orderby key, default to post_date
$orderby = (isset($_GET['orderby']) && !empty($_GET['orderby'])) ? sanitize_text_field($_GET['orderby']) : get_field('archive_' . sanitize_title($posttype) . '_sort_key',
'option');
if (empty($orderby)) {
$orderby = 'post_date';
}
if (in_array($orderby, array('post_date', 'post_modified', 'post_title'))) {
$orderby = str_replace('post_', '', $orderby);
} else {
$isMetaQuery = true;
}
// Get orderby order, default to desc
$order = (isset($_GET['order']) && !empty($_GET['order'])) ? sanitize_text_field($_GET['order']) : get_field('archive_' . sanitize_title($posttype) . '_sort_order',
'option');
if (empty($order) || !in_array(strtolower($order), array('asc', 'desc'))) {
$order = 'desc';
}
$query->set('order', $order);
// Return if not meta query
if (!$isMetaQuery) {
$query->set('orderby', $orderby);
return $query;
}
if (isset($_GET['orderby']) && $_GET['orderby'] == 'meta_key' && isset($_GET['meta_key']) && !empty($_GET['meta_key'])) {
$orderby = sanitize_text_field($_GET['meta_key']);
}
// Continue if meta query
$query->set('meta_key', $orderby);
$query->set('orderby', 'meta_value');
return $query;
} | [
"public",
"function",
"doPostOrdering",
"(",
"$",
"query",
")",
"{",
"// Do not execute this in admin view",
"if",
"(",
"is_admin",
"(",
")",
"||",
"!",
"(",
"is_archive",
"(",
")",
"||",
"is_home",
"(",
")",
")",
"||",
"!",
"$",
"query",
"->",
"is_main_qu... | Do post ordering for archives
@param object $query Query
@return object Modified query | [
"Do",
"post",
"ordering",
"for",
"archives"
] | 923ca84eafa775237b97221e73a9b381fa6ddcba | https://github.com/helsingborg-stad/Municipio/blob/923ca84eafa775237b97221e73a9b381fa6ddcba/library/Content/PostFilters.php#L446-L497 | train |
helsingborg-stad/Municipio | library/Helper/Navigation.php | Navigation.sidebarMenu | public function sidebarMenu()
{
if (get_field('nav_sub_enable', 'option') === false) {
return '';
}
if (get_field('nav_primary_type', 'option') == 'wp' && in_array(get_field('nav_sub_type', 'option'), array('sub', 'wp'))) {
return $this->sidebarMenuWP();
} else {
return $this->sidebarMenuAuto();
}
return '';
} | php | public function sidebarMenu()
{
if (get_field('nav_sub_enable', 'option') === false) {
return '';
}
if (get_field('nav_primary_type', 'option') == 'wp' && in_array(get_field('nav_sub_type', 'option'), array('sub', 'wp'))) {
return $this->sidebarMenuWP();
} else {
return $this->sidebarMenuAuto();
}
return '';
} | [
"public",
"function",
"sidebarMenu",
"(",
")",
"{",
"if",
"(",
"get_field",
"(",
"'nav_sub_enable'",
",",
"'option'",
")",
"===",
"false",
")",
"{",
"return",
"''",
";",
"}",
"if",
"(",
"get_field",
"(",
"'nav_primary_type'",
",",
"'option'",
")",
"==",
... | Finds out which type of menu to use for the sidebar menu
@return mixed | [
"Finds",
"out",
"which",
"type",
"of",
"menu",
"to",
"use",
"for",
"the",
"sidebar",
"menu"
] | 923ca84eafa775237b97221e73a9b381fa6ddcba | https://github.com/helsingborg-stad/Municipio/blob/923ca84eafa775237b97221e73a9b381fa6ddcba/library/Helper/Navigation.php#L32-L45 | train |
helsingborg-stad/Municipio | library/Helper/Navigation.php | Navigation.mobileMenu | public function mobileMenu()
{
if (get_field('nav_mobile_enable', 'option') === false) {
return '';
}
if (get_field('nav_primary_enable', 'option') === false && get_field('nav_sub_enable', 'option') === false) {
return '';
}
if (get_field('nav_primary_type', 'option') == 'wp' && (!get_field('nav_sub_type', 'option') || in_array(get_field('nav_sub_type', 'option'), array('sub', 'wp')))) {
return $this->mobileMenuWP();
} else {
return $this->mobileMenuAuto();
}
} | php | public function mobileMenu()
{
if (get_field('nav_mobile_enable', 'option') === false) {
return '';
}
if (get_field('nav_primary_enable', 'option') === false && get_field('nav_sub_enable', 'option') === false) {
return '';
}
if (get_field('nav_primary_type', 'option') == 'wp' && (!get_field('nav_sub_type', 'option') || in_array(get_field('nav_sub_type', 'option'), array('sub', 'wp')))) {
return $this->mobileMenuWP();
} else {
return $this->mobileMenuAuto();
}
} | [
"public",
"function",
"mobileMenu",
"(",
")",
"{",
"if",
"(",
"get_field",
"(",
"'nav_mobile_enable'",
",",
"'option'",
")",
"===",
"false",
")",
"{",
"return",
"''",
";",
"}",
"if",
"(",
"get_field",
"(",
"'nav_primary_enable'",
",",
"'option'",
")",
"===... | Get the mobile menu
@return string Mobile menu html | [
"Get",
"the",
"mobile",
"menu"
] | 923ca84eafa775237b97221e73a9b381fa6ddcba | https://github.com/helsingborg-stad/Municipio/blob/923ca84eafa775237b97221e73a9b381fa6ddcba/library/Helper/Navigation.php#L51-L66 | train |
helsingborg-stad/Municipio | library/Helper/Navigation.php | Navigation.mainMenuWP | public function mainMenuWP()
{
$classes = array('nav');
if (!empty(get_field('nav_primary_align', 'option'))) {
$classes[] = 'nav-' . get_field('nav_primary_align', 'option');
}
$args = array(
'echo' => false,
'depth' => 1,
'theme_location' => 'main-menu',
'container' => false,
'container_class' => 'menu-{menu-slug}-container',
'container_id' => '',
'menu_id' => 'main-menu',
'before' => '',
'after' => '',
'link_before' => '',
'link_after' => '',
'items_wrap' => '<ul id="%1$s" class="%2$s">%3$s</ul>',
'fallback_cb' => '__return_false'
);
if (get_field('nav_primariy_second_level', 'option')) {
$classes[] = 'nav-multilevel';
$args['depth'] = 2;
$args['walker'] = new \Municipio\Walker\MainMenuSecondary();
$args['items_section_wrap'] = $args['items_wrap'];
$args['items_wrap'] = '%3$s';
}
$args['menu_class'] = implode(' ', apply_filters('Municipio/main_menu_classes', $classes)) . ' ' . apply_filters('Municipio/desktop_menu_breakpoint', 'hidden-xs hidden-sm');
return wp_nav_menu($args);
} | php | public function mainMenuWP()
{
$classes = array('nav');
if (!empty(get_field('nav_primary_align', 'option'))) {
$classes[] = 'nav-' . get_field('nav_primary_align', 'option');
}
$args = array(
'echo' => false,
'depth' => 1,
'theme_location' => 'main-menu',
'container' => false,
'container_class' => 'menu-{menu-slug}-container',
'container_id' => '',
'menu_id' => 'main-menu',
'before' => '',
'after' => '',
'link_before' => '',
'link_after' => '',
'items_wrap' => '<ul id="%1$s" class="%2$s">%3$s</ul>',
'fallback_cb' => '__return_false'
);
if (get_field('nav_primariy_second_level', 'option')) {
$classes[] = 'nav-multilevel';
$args['depth'] = 2;
$args['walker'] = new \Municipio\Walker\MainMenuSecondary();
$args['items_section_wrap'] = $args['items_wrap'];
$args['items_wrap'] = '%3$s';
}
$args['menu_class'] = implode(' ', apply_filters('Municipio/main_menu_classes', $classes)) . ' ' . apply_filters('Municipio/desktop_menu_breakpoint', 'hidden-xs hidden-sm');
return wp_nav_menu($args);
} | [
"public",
"function",
"mainMenuWP",
"(",
")",
"{",
"$",
"classes",
"=",
"array",
"(",
"'nav'",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"get_field",
"(",
"'nav_primary_align'",
",",
"'option'",
")",
")",
")",
"{",
"$",
"classes",
"[",
"]",
"=",
"'nav-... | Get WP main menu
@return string Markuo | [
"Get",
"WP",
"main",
"menu"
] | 923ca84eafa775237b97221e73a9b381fa6ddcba | https://github.com/helsingborg-stad/Municipio/blob/923ca84eafa775237b97221e73a9b381fa6ddcba/library/Helper/Navigation.php#L72-L107 | train |
helsingborg-stad/Municipio | library/Helper/Navigation.php | Navigation.mainMenuAuto | public function mainMenuAuto()
{
$markup = null;
$menu = false;
$classes = array('nav');
if (!$menu || !is_string($menu) || (isset($_GET['menu_cache']) && $_GET['menu_cache'] == 'false')) {
if (!empty(get_field('nav_primary_align', 'option'))) {
$classes[] = 'nav-' . get_field('nav_primary_align', 'option');
}
$menu = new \Municipio\Helper\NavigationTree(array(
'theme_location' => 'main-menu',
'include_top_level' => true,
'render' => get_field('nav_primary_render', 'option'),
'depth' => 1,
'sublevel' => get_field('nav_primariy_second_level', 'option'),
'classes' => implode(' ', apply_filters('Municipio/main_menu_classes', $classes)) . ' ' . apply_filters('Municipio/desktop_menu_breakpoint', 'hidden-xs hidden-sm')
));
if (isset($menu) && $menu->itemCount() > 0) {
$markup = apply_filters('Municipio/main_menu/items', $menu->render(false));
}
return $markup;
}
return $menu;
} | php | public function mainMenuAuto()
{
$markup = null;
$menu = false;
$classes = array('nav');
if (!$menu || !is_string($menu) || (isset($_GET['menu_cache']) && $_GET['menu_cache'] == 'false')) {
if (!empty(get_field('nav_primary_align', 'option'))) {
$classes[] = 'nav-' . get_field('nav_primary_align', 'option');
}
$menu = new \Municipio\Helper\NavigationTree(array(
'theme_location' => 'main-menu',
'include_top_level' => true,
'render' => get_field('nav_primary_render', 'option'),
'depth' => 1,
'sublevel' => get_field('nav_primariy_second_level', 'option'),
'classes' => implode(' ', apply_filters('Municipio/main_menu_classes', $classes)) . ' ' . apply_filters('Municipio/desktop_menu_breakpoint', 'hidden-xs hidden-sm')
));
if (isset($menu) && $menu->itemCount() > 0) {
$markup = apply_filters('Municipio/main_menu/items', $menu->render(false));
}
return $markup;
}
return $menu;
} | [
"public",
"function",
"mainMenuAuto",
"(",
")",
"{",
"$",
"markup",
"=",
"null",
";",
"$",
"menu",
"=",
"false",
";",
"$",
"classes",
"=",
"array",
"(",
"'nav'",
")",
";",
"if",
"(",
"!",
"$",
"menu",
"||",
"!",
"is_string",
"(",
"$",
"menu",
")"... | Get navigation tree main menu
@return string Markup | [
"Get",
"navigation",
"tree",
"main",
"menu"
] | 923ca84eafa775237b97221e73a9b381fa6ddcba | https://github.com/helsingborg-stad/Municipio/blob/923ca84eafa775237b97221e73a9b381fa6ddcba/library/Helper/Navigation.php#L113-L142 | train |
helsingborg-stad/Municipio | library/Helper/Navigation.php | Navigation.mobileMenuAuto | public function mobileMenuAuto()
{
//Create common hash for 404 & search
if(is_search()) {
$transientHash = "is_search";
$cacheTtl = 60*60*168; //Cache for a week
} elseif(is_404()) {
$transientHash = "is_404";
$cacheTtl = 60*60*168; //Cache for a week
} else {
$transientHash = \Municipio\Helper\Hash::short(\Municipio\Helper\Url::getCurrent());
$cacheTtl = 60*30; //Cache for an hour
}
//Toggle between logged out / logged in
$transientType = '';
if (is_user_logged_in()) {
$transientType = '_loggedin';
}
//Get menu cached value
$menu = wp_cache_get($transientHash, 'municipioMenuCache' . $transientType);
if (!$menu || (isset($_GET['menu_cache']) && $_GET['menu_cache'] == 'false')) {
$mobileMenuArgs = array(
'include_top_level' => true
);
if (get_field('nav_primary_type', 'option') == 'wp') {
$mobileMenuArgs['top_level_type'] = 'mobile';
}
//Render menu
$menu = new \Municipio\Helper\NavigationTree($mobileMenuArgs);
//Add to cache
wp_cache_add($transientHash, $menu, 'municipioMenuCache' . $transientType, $cacheTtl);
}
if ($menu->itemCount === 0) {
return '';
}
return '<ul class="nav-mobile">' . apply_filters( 'Municipio/Helper/Navigation/MobileMenuAutoItems', $menu->render(false) ) . '</ul>';
} | php | public function mobileMenuAuto()
{
//Create common hash for 404 & search
if(is_search()) {
$transientHash = "is_search";
$cacheTtl = 60*60*168; //Cache for a week
} elseif(is_404()) {
$transientHash = "is_404";
$cacheTtl = 60*60*168; //Cache for a week
} else {
$transientHash = \Municipio\Helper\Hash::short(\Municipio\Helper\Url::getCurrent());
$cacheTtl = 60*30; //Cache for an hour
}
//Toggle between logged out / logged in
$transientType = '';
if (is_user_logged_in()) {
$transientType = '_loggedin';
}
//Get menu cached value
$menu = wp_cache_get($transientHash, 'municipioMenuCache' . $transientType);
if (!$menu || (isset($_GET['menu_cache']) && $_GET['menu_cache'] == 'false')) {
$mobileMenuArgs = array(
'include_top_level' => true
);
if (get_field('nav_primary_type', 'option') == 'wp') {
$mobileMenuArgs['top_level_type'] = 'mobile';
}
//Render menu
$menu = new \Municipio\Helper\NavigationTree($mobileMenuArgs);
//Add to cache
wp_cache_add($transientHash, $menu, 'municipioMenuCache' . $transientType, $cacheTtl);
}
if ($menu->itemCount === 0) {
return '';
}
return '<ul class="nav-mobile">' . apply_filters( 'Municipio/Helper/Navigation/MobileMenuAutoItems', $menu->render(false) ) . '</ul>';
} | [
"public",
"function",
"mobileMenuAuto",
"(",
")",
"{",
"//Create common hash for 404 & search",
"if",
"(",
"is_search",
"(",
")",
")",
"{",
"$",
"transientHash",
"=",
"\"is_search\"",
";",
"$",
"cacheTtl",
"=",
"60",
"*",
"60",
"*",
"168",
";",
"//Cache for a ... | Get navigation tree mobile menu
@return [type] [description] | [
"Get",
"navigation",
"tree",
"mobile",
"menu"
] | 923ca84eafa775237b97221e73a9b381fa6ddcba | https://github.com/helsingborg-stad/Municipio/blob/923ca84eafa775237b97221e73a9b381fa6ddcba/library/Helper/Navigation.php#L148-L193 | train |
helsingborg-stad/Municipio | library/Helper/Navigation.php | Navigation.sidebarMenuWP | public function sidebarMenuWP()
{
if (get_field('nav_sub_type', 'option') == 'sub') {
return wp_nav_menu(array(
'theme_location' => 'main-menu',
'container' => 'nav',
'container_class' => 'sidebar-menu',
'container_id' => 'sidebar-menu',
'menu_class' => 'nav-aside hidden-xs hidden-sm',
'menu_id' => '',
'echo' => false,
'before' => '',
'after' => '',
'link_before' => '',
'link_after' => '',
'items_wrap' => '<ul id="%1$s" class="%2$s">%3$s</ul>',
'fallback_cb' => '__return_false',
'walker' => new \Municipio\Walker\SidebarMenu(),
'child_menu' => true
));
}
return wp_nav_menu(array(
'theme_location' => 'sidebar-menu',
'container' => 'nav',
'container_class' => 'sidebar-menu',
'container_id' => 'sidebar-menu',
'menu_class' => 'nav-aside hidden-xs hidden-sm',
'menu_id' => '',
'echo' => false,
'before' => '',
'after' => '',
'link_before' => '',
'link_after' => '',
'items_wrap' => '<ul id="%1$s" class="%2$s">%3$s</ul>',
'fallback_cb' => '__return_false'
));
} | php | public function sidebarMenuWP()
{
if (get_field('nav_sub_type', 'option') == 'sub') {
return wp_nav_menu(array(
'theme_location' => 'main-menu',
'container' => 'nav',
'container_class' => 'sidebar-menu',
'container_id' => 'sidebar-menu',
'menu_class' => 'nav-aside hidden-xs hidden-sm',
'menu_id' => '',
'echo' => false,
'before' => '',
'after' => '',
'link_before' => '',
'link_after' => '',
'items_wrap' => '<ul id="%1$s" class="%2$s">%3$s</ul>',
'fallback_cb' => '__return_false',
'walker' => new \Municipio\Walker\SidebarMenu(),
'child_menu' => true
));
}
return wp_nav_menu(array(
'theme_location' => 'sidebar-menu',
'container' => 'nav',
'container_class' => 'sidebar-menu',
'container_id' => 'sidebar-menu',
'menu_class' => 'nav-aside hidden-xs hidden-sm',
'menu_id' => '',
'echo' => false,
'before' => '',
'after' => '',
'link_before' => '',
'link_after' => '',
'items_wrap' => '<ul id="%1$s" class="%2$s">%3$s</ul>',
'fallback_cb' => '__return_false'
));
} | [
"public",
"function",
"sidebarMenuWP",
"(",
")",
"{",
"if",
"(",
"get_field",
"(",
"'nav_sub_type'",
",",
"'option'",
")",
"==",
"'sub'",
")",
"{",
"return",
"wp_nav_menu",
"(",
"array",
"(",
"'theme_location'",
"=>",
"'main-menu'",
",",
"'container'",
"=>",
... | Get WP or sub sidebar menu
@return string Markuo | [
"Get",
"WP",
"or",
"sub",
"sidebar",
"menu"
] | 923ca84eafa775237b97221e73a9b381fa6ddcba | https://github.com/helsingborg-stad/Municipio/blob/923ca84eafa775237b97221e73a9b381fa6ddcba/library/Helper/Navigation.php#L223-L260 | train |
helsingborg-stad/Municipio | library/Helper/Navigation.php | Navigation.sidebarMenuAuto | public function sidebarMenuAuto()
{
$menu = false;
if (!$menu || (isset($_GET['menu_cache']) && $_GET['menu_cache'] == 'false')) {
$menu = new \Municipio\Helper\NavigationTree(array(
'include_top_level' => !empty(get_field('nav_sub_include_top_level', 'option')) ? get_field('nav_sub_include_top_level', 'option') : false,
'render' => get_field('nav_sub_render', 'option'),
'depth' => get_field('nav_sub_depth', 'option') ? get_field('nav_sub_depth', 'option') : -1,
'start_depth' => get_field('nav_primariy_second_level', 'option') ? 3 : 1,
'classes' => 'nav-aside hidden-xs hidden-sm',
'sidebar' => true
));
}
if ($menu->itemCount === 0) {
return '';
}
return '<nav id="sidebar-menu">
' . $menu->render(false) . '
</nav>';
} | php | public function sidebarMenuAuto()
{
$menu = false;
if (!$menu || (isset($_GET['menu_cache']) && $_GET['menu_cache'] == 'false')) {
$menu = new \Municipio\Helper\NavigationTree(array(
'include_top_level' => !empty(get_field('nav_sub_include_top_level', 'option')) ? get_field('nav_sub_include_top_level', 'option') : false,
'render' => get_field('nav_sub_render', 'option'),
'depth' => get_field('nav_sub_depth', 'option') ? get_field('nav_sub_depth', 'option') : -1,
'start_depth' => get_field('nav_primariy_second_level', 'option') ? 3 : 1,
'classes' => 'nav-aside hidden-xs hidden-sm',
'sidebar' => true
));
}
if ($menu->itemCount === 0) {
return '';
}
return '<nav id="sidebar-menu">
' . $menu->render(false) . '
</nav>';
} | [
"public",
"function",
"sidebarMenuAuto",
"(",
")",
"{",
"$",
"menu",
"=",
"false",
";",
"if",
"(",
"!",
"$",
"menu",
"||",
"(",
"isset",
"(",
"$",
"_GET",
"[",
"'menu_cache'",
"]",
")",
"&&",
"$",
"_GET",
"[",
"'menu_cache'",
"]",
"==",
"'false'",
... | Get navigation tree sidebar menu
@return string Menu markup | [
"Get",
"navigation",
"tree",
"sidebar",
"menu"
] | 923ca84eafa775237b97221e73a9b381fa6ddcba | https://github.com/helsingborg-stad/Municipio/blob/923ca84eafa775237b97221e73a9b381fa6ddcba/library/Helper/Navigation.php#L266-L288 | train |
helsingborg-stad/Municipio | library/Helper/Navigation.php | Navigation.getMenuNameByLocation | public static function getMenuNameByLocation($location)
{
if(!has_nav_menu($location)) return false;
$menus = get_nav_menu_locations();
$menuTitle = wp_get_nav_menu_object($menus[$location])->name;
return $menuTitle;
} | php | public static function getMenuNameByLocation($location)
{
if(!has_nav_menu($location)) return false;
$menus = get_nav_menu_locations();
$menuTitle = wp_get_nav_menu_object($menus[$location])->name;
return $menuTitle;
} | [
"public",
"static",
"function",
"getMenuNameByLocation",
"(",
"$",
"location",
")",
"{",
"if",
"(",
"!",
"has_nav_menu",
"(",
"$",
"location",
")",
")",
"return",
"false",
";",
"$",
"menus",
"=",
"get_nav_menu_locations",
"(",
")",
";",
"$",
"menuTitle",
"... | Get menu name by menu location
@param mixed $location slug or ID of registered menu
@return string menu name | [
"Get",
"menu",
"name",
"by",
"menu",
"location"
] | 923ca84eafa775237b97221e73a9b381fa6ddcba | https://github.com/helsingborg-stad/Municipio/blob/923ca84eafa775237b97221e73a9b381fa6ddcba/library/Helper/Navigation.php#L295-L301 | train |
helsingborg-stad/Municipio | library/Admin/Roles/General.php | General.addMissingRoles | public function addMissingRoles()
{
if (!get_role('author')) {
add_role(
'author',
'Author',
array(
'upload_files' => true,
'edit_posts' => true,
'edit_published_posts' => true,
'publish_posts' => true,
'read' => true,
'level_2' => true,
'level_1' => true,
'level_0' => true,
'delete_posts' => true,
'delete_published_posts' => true
)
);
delete_option('_author_role_bkp');
}
} | php | public function addMissingRoles()
{
if (!get_role('author')) {
add_role(
'author',
'Author',
array(
'upload_files' => true,
'edit_posts' => true,
'edit_published_posts' => true,
'publish_posts' => true,
'read' => true,
'level_2' => true,
'level_1' => true,
'level_0' => true,
'delete_posts' => true,
'delete_published_posts' => true
)
);
delete_option('_author_role_bkp');
}
} | [
"public",
"function",
"addMissingRoles",
"(",
")",
"{",
"if",
"(",
"!",
"get_role",
"(",
"'author'",
")",
")",
"{",
"add_role",
"(",
"'author'",
",",
"'Author'",
",",
"array",
"(",
"'upload_files'",
"=>",
"true",
",",
"'edit_posts'",
"=>",
"true",
",",
"... | Adds back missing author role | [
"Adds",
"back",
"missing",
"author",
"role"
] | 923ca84eafa775237b97221e73a9b381fa6ddcba | https://github.com/helsingborg-stad/Municipio/blob/923ca84eafa775237b97221e73a9b381fa6ddcba/library/Admin/Roles/General.php#L27-L49 | train |
helsingborg-stad/Municipio | library/Admin/Roles/General.php | General.removeUnusedRoles | public function removeUnusedRoles()
{
$removeRoles = array(
'contributor'
);
foreach ($removeRoles as $role) {
if (!get_role($role)) {
continue;
}
update_option('_' . $role . '_role_bkp', get_role('author'));
remove_role($role);
}
} | php | public function removeUnusedRoles()
{
$removeRoles = array(
'contributor'
);
foreach ($removeRoles as $role) {
if (!get_role($role)) {
continue;
}
update_option('_' . $role . '_role_bkp', get_role('author'));
remove_role($role);
}
} | [
"public",
"function",
"removeUnusedRoles",
"(",
")",
"{",
"$",
"removeRoles",
"=",
"array",
"(",
"'contributor'",
")",
";",
"foreach",
"(",
"$",
"removeRoles",
"as",
"$",
"role",
")",
"{",
"if",
"(",
"!",
"get_role",
"(",
"$",
"role",
")",
")",
"{",
... | Remove unwanted roles
@return void | [
"Remove",
"unwanted",
"roles"
] | 923ca84eafa775237b97221e73a9b381fa6ddcba | https://github.com/helsingborg-stad/Municipio/blob/923ca84eafa775237b97221e73a9b381fa6ddcba/library/Admin/Roles/General.php#L55-L69 | train |
helsingborg-stad/Municipio | library/Theme/Sidebars.php | Sidebars.moduleClasses | public function moduleClasses($classes, $moduleType, $sidebarArgs)
{
// Box panel in content area and content area bottom
if (in_array($sidebarArgs['id'], array('content-area', 'content-area-bottom')) && in_array('box-panel', $classes) && !is_front_page()) {
$classes[] = 'box-panel-secondary';
}
// Inline box panels
if (is_numeric($sidebarArgs['id']) && in_array('box-panel', $classes)) {
$classes[] = 'box-panel-secondary';
}
// Sidebar box-panel (should be filled)
if (in_array($sidebarArgs['id'], array('left-sidebar-bottom', 'left-sidebar', 'right-sidebar')) && in_array('box-panel', $classes)) {
unset($classes[array_search('box-panel', $classes)]);
$classes[] = 'box-filled';
}
// Sidebar box-index (should be filled)
if (in_array($sidebarArgs['id'], array('left-sidebar-bottom', 'left-sidebar', 'right-sidebar')) && in_array('box-index', $classes)) {
unset($classes[array_search('box-index', $classes)]);
$classes[] = 'box-filled';
}
// Sidebar box-news-horizontal (should be only box-news in sidebar)
if (in_array($sidebarArgs['id'], array('left-sidebar-bottom', 'left-sidebar', 'right-sidebar')) && in_array('box-news-horizontal', $classes)) {
unset($classes[array_search('box-news-horizontal', $classes)]);
}
return $classes;
} | php | public function moduleClasses($classes, $moduleType, $sidebarArgs)
{
// Box panel in content area and content area bottom
if (in_array($sidebarArgs['id'], array('content-area', 'content-area-bottom')) && in_array('box-panel', $classes) && !is_front_page()) {
$classes[] = 'box-panel-secondary';
}
// Inline box panels
if (is_numeric($sidebarArgs['id']) && in_array('box-panel', $classes)) {
$classes[] = 'box-panel-secondary';
}
// Sidebar box-panel (should be filled)
if (in_array($sidebarArgs['id'], array('left-sidebar-bottom', 'left-sidebar', 'right-sidebar')) && in_array('box-panel', $classes)) {
unset($classes[array_search('box-panel', $classes)]);
$classes[] = 'box-filled';
}
// Sidebar box-index (should be filled)
if (in_array($sidebarArgs['id'], array('left-sidebar-bottom', 'left-sidebar', 'right-sidebar')) && in_array('box-index', $classes)) {
unset($classes[array_search('box-index', $classes)]);
$classes[] = 'box-filled';
}
// Sidebar box-news-horizontal (should be only box-news in sidebar)
if (in_array($sidebarArgs['id'], array('left-sidebar-bottom', 'left-sidebar', 'right-sidebar')) && in_array('box-news-horizontal', $classes)) {
unset($classes[array_search('box-news-horizontal', $classes)]);
}
return $classes;
} | [
"public",
"function",
"moduleClasses",
"(",
"$",
"classes",
",",
"$",
"moduleType",
",",
"$",
"sidebarArgs",
")",
"{",
"// Box panel in content area and content area bottom",
"if",
"(",
"in_array",
"(",
"$",
"sidebarArgs",
"[",
"'id'",
"]",
",",
"array",
"(",
"'... | Modify module classes in different areas
@param array $classes Default classes
@param string $moduleType Module type
@param array $sidebarArgs Sidebar arguments
@return array Modified list of classes | [
"Modify",
"module",
"classes",
"in",
"different",
"areas"
] | 923ca84eafa775237b97221e73a9b381fa6ddcba | https://github.com/helsingborg-stad/Municipio/blob/923ca84eafa775237b97221e73a9b381fa6ddcba/library/Theme/Sidebars.php#L44-L74 | train |
helsingborg-stad/Municipio | library/Theme/Sidebars.php | Sidebars.moduleSidebarIncompability | public function moduleSidebarIncompability($moduleSpecification, $modulePostType) : array
{
switch ($modulePostType) {
case "mod-section-featured":
case "mod-section-full":
case "mod-section-split":
$moduleSpecification['sidebar_incompability'] = array("right-sidebar", "left-sidebar", "left-sidebar-bottom", "footer-area", "content-area-bottom", "content-area", "content-area-top", "footer-area");
break;
case "mod-slider":
case "mod-video":
$moduleSpecification['sidebar_incompability'] = array("right-sidebar", "left-sidebar", "left-sidebar-bottom", "footer-area");
break;
case "mod-table":
case "mod-gallery":
case "mod-guide":
case "mod-alarms":
case "mod-interactive-map":
$moduleSpecification['sidebar_incompability'] = array("right-sidebar", "left-sidebar", "left-sidebar-bottom", "footer-area", "slider-area", "bottom-sidebar", "top-sidebar");
break;
case "mod-posts":
case "mod-location":
case "mod-social":
case "mod-dictionary":
case "mod-contacts":
case "mod-fileslist":
case "mod-g-calendar":
case "mod-index":
case "mod-inlaylist":
$moduleSpecification['sidebar_incompability'] = array("footer-area", "slider-area", "bottom-sidebar", "top-sidebar");
break;
case "mod-rss":
case "mod-script":
case "mod-notice":
case "mod-iframe":
case "mod-event":
case "mod-form":
case "mod-location":
case "mod-text":
$moduleSpecification['sidebar_incompability'] = array("slider-area", "bottom-sidebar", "top-sidebar");
break;
}
return $moduleSpecification;
} | php | public function moduleSidebarIncompability($moduleSpecification, $modulePostType) : array
{
switch ($modulePostType) {
case "mod-section-featured":
case "mod-section-full":
case "mod-section-split":
$moduleSpecification['sidebar_incompability'] = array("right-sidebar", "left-sidebar", "left-sidebar-bottom", "footer-area", "content-area-bottom", "content-area", "content-area-top", "footer-area");
break;
case "mod-slider":
case "mod-video":
$moduleSpecification['sidebar_incompability'] = array("right-sidebar", "left-sidebar", "left-sidebar-bottom", "footer-area");
break;
case "mod-table":
case "mod-gallery":
case "mod-guide":
case "mod-alarms":
case "mod-interactive-map":
$moduleSpecification['sidebar_incompability'] = array("right-sidebar", "left-sidebar", "left-sidebar-bottom", "footer-area", "slider-area", "bottom-sidebar", "top-sidebar");
break;
case "mod-posts":
case "mod-location":
case "mod-social":
case "mod-dictionary":
case "mod-contacts":
case "mod-fileslist":
case "mod-g-calendar":
case "mod-index":
case "mod-inlaylist":
$moduleSpecification['sidebar_incompability'] = array("footer-area", "slider-area", "bottom-sidebar", "top-sidebar");
break;
case "mod-rss":
case "mod-script":
case "mod-notice":
case "mod-iframe":
case "mod-event":
case "mod-form":
case "mod-location":
case "mod-text":
$moduleSpecification['sidebar_incompability'] = array("slider-area", "bottom-sidebar", "top-sidebar");
break;
}
return $moduleSpecification;
} | [
"public",
"function",
"moduleSidebarIncompability",
"(",
"$",
"moduleSpecification",
",",
"$",
"modulePostType",
")",
":",
"array",
"{",
"switch",
"(",
"$",
"modulePostType",
")",
"{",
"case",
"\"mod-section-featured\"",
":",
"case",
"\"mod-section-full\"",
":",
"ca... | Appends compability support
@param array $moduleSpecification Original module settings
@return array | [
"Appends",
"compability",
"support"
] | 923ca84eafa775237b97221e73a9b381fa6ddcba | https://github.com/helsingborg-stad/Municipio/blob/923ca84eafa775237b97221e73a9b381fa6ddcba/library/Theme/Sidebars.php#L209-L253 | train |
helsingborg-stad/Municipio | library/Theme/Sidebars.php | Sidebars.registerModulesWithContainerSupport | public function registerModulesWithContainerSupport($modules)
{
$modules[] = "mod-posts";
$modules[] = "mod-location";
$modules[] = "mod-social";
$modules[] = "mod-contacts";
$modules[] = "mod-fileslist";
$modules[] = "mod-index";
$modules[] = "mod-inlaylist";
$modules[] = "mod-form";
$modules[] = "mod-text";
$modules[] = "mod-guide";
$modules[] = "mod-table";
$modules[] = "mod-gallery";
$modules[] = "mod-video";
$modules[] = "mod-notice";
$modules[] = "mod-g-calendar";
return $modules;
} | php | public function registerModulesWithContainerSupport($modules)
{
$modules[] = "mod-posts";
$modules[] = "mod-location";
$modules[] = "mod-social";
$modules[] = "mod-contacts";
$modules[] = "mod-fileslist";
$modules[] = "mod-index";
$modules[] = "mod-inlaylist";
$modules[] = "mod-form";
$modules[] = "mod-text";
$modules[] = "mod-guide";
$modules[] = "mod-table";
$modules[] = "mod-gallery";
$modules[] = "mod-video";
$modules[] = "mod-notice";
$modules[] = "mod-g-calendar";
return $modules;
} | [
"public",
"function",
"registerModulesWithContainerSupport",
"(",
"$",
"modules",
")",
"{",
"$",
"modules",
"[",
"]",
"=",
"\"mod-posts\"",
";",
"$",
"modules",
"[",
"]",
"=",
"\"mod-location\"",
";",
"$",
"modules",
"[",
"]",
"=",
"\"mod-social\"",
";",
"$"... | Add container grid to some modules placed in full-width widget areas
@return array | [
"Add",
"container",
"grid",
"to",
"some",
"modules",
"placed",
"in",
"full",
"-",
"width",
"widget",
"areas"
] | 923ca84eafa775237b97221e73a9b381fa6ddcba | https://github.com/helsingborg-stad/Municipio/blob/923ca84eafa775237b97221e73a9b381fa6ddcba/library/Theme/Sidebars.php#L272-L291 | train |
helsingborg-stad/Municipio | library/Admin/UI/Editor.php | Editor.allowedHtmlTags | public function allowedHtmlTags($init)
{
$extend = 'div[*], style[*], script[*], iframe[*], span[*], section[*], article[*], header[*], footer[*]';
if (isset($init['extended_valid_elements']) && !empty($init['extended_valid_elements'])) {
$init['extended_valid_elements'] .= ', ' . $extend;
} else {
$init['extended_valid_elements'] = $extend;
}
return $init;
} | php | public function allowedHtmlTags($init)
{
$extend = 'div[*], style[*], script[*], iframe[*], span[*], section[*], article[*], header[*], footer[*]';
if (isset($init['extended_valid_elements']) && !empty($init['extended_valid_elements'])) {
$init['extended_valid_elements'] .= ', ' . $extend;
} else {
$init['extended_valid_elements'] = $extend;
}
return $init;
} | [
"public",
"function",
"allowedHtmlTags",
"(",
"$",
"init",
")",
"{",
"$",
"extend",
"=",
"'div[*], style[*], script[*], iframe[*], span[*], section[*], article[*], header[*], footer[*]'",
";",
"if",
"(",
"isset",
"(",
"$",
"init",
"[",
"'extended_valid_elements'",
"]",
")... | Extend valid html-elements for wp editor
@param array $init
@return array | [
"Extend",
"valid",
"html",
"-",
"elements",
"for",
"wp",
"editor"
] | 923ca84eafa775237b97221e73a9b381fa6ddcba | https://github.com/helsingborg-stad/Municipio/blob/923ca84eafa775237b97221e73a9b381fa6ddcba/library/Admin/UI/Editor.php#L30-L41 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.