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
j0k3r/graby
src/SiteConfig/SiteConfig.php
SiteConfig.prune
public function prune($use_default = true) { if ($use_default) { return isset($this->prune) ? $this->prune : $this->default_prune; } return $this->prune; }
php
public function prune($use_default = true) { if ($use_default) { return isset($this->prune) ? $this->prune : $this->default_prune; } return $this->prune; }
[ "public", "function", "prune", "(", "$", "use_default", "=", "true", ")", "{", "if", "(", "$", "use_default", ")", "{", "return", "isset", "(", "$", "this", "->", "prune", ")", "?", "$", "this", "->", "prune", ":", "$", "this", "->", "default_prune",...
Clean up content block - attempt to remove elements that appear to be superfluous. @param bool $use_default @return bool|null
[ "Clean", "up", "content", "block", "-", "attempt", "to", "remove", "elements", "that", "appear", "to", "be", "superfluous", "." ]
6c1506f19d1bb876fb26bfc11e3e11a993eb7fe8
https://github.com/j0k3r/graby/blob/6c1506f19d1bb876fb26bfc11e3e11a993eb7fe8/src/SiteConfig/SiteConfig.php#L174-L181
train
j0k3r/graby
src/Graby.php
Graby.setLogger
public function setLogger(LoggerInterface $logger) { $this->logger = $logger; $this->extractor->setLogger($logger); $this->httpClient->setLogger($logger); }
php
public function setLogger(LoggerInterface $logger) { $this->logger = $logger; $this->extractor->setLogger($logger); $this->httpClient->setLogger($logger); }
[ "public", "function", "setLogger", "(", "LoggerInterface", "$", "logger", ")", "{", "$", "this", "->", "logger", "=", "$", "logger", ";", "$", "this", "->", "extractor", "->", "setLogger", "(", "$", "logger", ")", ";", "$", "this", "->", "httpClient", ...
Redefine all loggers. @param LoggerInterface $logger
[ "Redefine", "all", "loggers", "." ]
6c1506f19d1bb876fb26bfc11e3e11a993eb7fe8
https://github.com/j0k3r/graby/blob/6c1506f19d1bb876fb26bfc11e3e11a993eb7fe8/src/Graby.php#L122-L127
train
j0k3r/graby
src/Graby.php
Graby.getConfig
public function getConfig($key) { if (!isset($this->config[$key])) { throw new \Exception(sprintf('No config found for key: "%s"', $key)); } return $this->config[$key]; }
php
public function getConfig($key) { if (!isset($this->config[$key])) { throw new \Exception(sprintf('No config found for key: "%s"', $key)); } return $this->config[$key]; }
[ "public", "function", "getConfig", "(", "$", "key", ")", "{", "if", "(", "!", "isset", "(", "$", "this", "->", "config", "[", "$", "key", "]", ")", ")", "{", "throw", "new", "\\", "Exception", "(", "sprintf", "(", "'No config found for key: \"%s\"'", "...
Return a config. @param string $key @return mixed
[ "Return", "a", "config", "." ]
6c1506f19d1bb876fb26bfc11e3e11a993eb7fe8
https://github.com/j0k3r/graby/blob/6c1506f19d1bb876fb26bfc11e3e11a993eb7fe8/src/Graby.php#L146-L153
train
j0k3r/graby
src/Graby.php
Graby.fetchContent
public function fetchContent($url) { $this->logger->info('Graby is ready to fetch'); $infos = $this->doFetchContent($url); // generate summary $infos['summary'] = $this->getExcerpt($infos['html']); return $infos; }
php
public function fetchContent($url) { $this->logger->info('Graby is ready to fetch'); $infos = $this->doFetchContent($url); // generate summary $infos['summary'] = $this->getExcerpt($infos['html']); return $infos; }
[ "public", "function", "fetchContent", "(", "$", "url", ")", "{", "$", "this", "->", "logger", "->", "info", "(", "'Graby is ready to fetch'", ")", ";", "$", "infos", "=", "$", "this", "->", "doFetchContent", "(", "$", "url", ")", ";", "// generate summary"...
Fetch content from the given url and return a readable content. @param string $url @return array With keys html, title, url & summary
[ "Fetch", "content", "from", "the", "given", "url", "and", "return", "a", "readable", "content", "." ]
6c1506f19d1bb876fb26bfc11e3e11a993eb7fe8
https://github.com/j0k3r/graby/blob/6c1506f19d1bb876fb26bfc11e3e11a993eb7fe8/src/Graby.php#L162-L172
train
j0k3r/graby
src/Graby.php
Graby.cleanupHtml
public function cleanupHtml($contentBlock, $url) { $originalContentBlock = $contentBlock; // if content is pure html, convert it if (!$contentBlock instanceof \DOMElement) { $this->extractor->process($contentBlock, $url); $contentBlock = $this->extractor->getContent(); } // in case of extractor failed if (null === $contentBlock) { $this->logger->info('Cleanup html failed. Return given content (a bit cleaned)'); return trim($this->cleanupXss($originalContentBlock)); } $this->extractor->readability->clean($contentBlock, 'select'); if ($this->config['rewrite_relative_urls']) { $this->makeAbsolute($url, $contentBlock); } // footnotes if ('footnotes' === $this->config['content_links'] && false === strpos($url, 'wikipedia.org')) { $this->extractor->readability->addFootnotes($contentBlock); } // normalise $contentBlock->normalize(); // remove empty text nodes foreach ($contentBlock->childNodes as $n) { if (XML_TEXT_NODE === $n->nodeType && '' === trim($n->textContent)) { $contentBlock->removeChild($n); } } // remove nesting: <div><div><div><p>test</p></div></div></div> = <p>test</p> while (1 === $contentBlock->childNodes->length && XML_ELEMENT_NODE === $contentBlock->firstChild->nodeType) { // only follow these tag names if (!\in_array(strtolower($contentBlock->tagName), ['div', 'article', 'section', 'header', 'footer'], true)) { break; } $contentBlock = $contentBlock->firstChild; } // convert content block to HTML string // Need to preserve things like body: //img[@id='feature'] if (\in_array(strtolower($contentBlock->tagName), ['div', 'article', 'section', 'header', 'footer', 'li', 'td'], true)) { $html = $contentBlock->innerHTML; } else { $html = $contentBlock->ownerDocument->saveXML($contentBlock); // essentially outerHTML } // post-processing cleanup $html = preg_replace('!<p>[\s\h\v]*</p>!u', '', $html); if ('remove' === $this->config['content_links']) { $html = preg_replace('!</?a[^>]*>!', '', $html); } $this->logger->debug('Body after cleanupHtml, before cleanupXss', ['html' => $html]); return trim($this->cleanupXss($html)); }
php
public function cleanupHtml($contentBlock, $url) { $originalContentBlock = $contentBlock; // if content is pure html, convert it if (!$contentBlock instanceof \DOMElement) { $this->extractor->process($contentBlock, $url); $contentBlock = $this->extractor->getContent(); } // in case of extractor failed if (null === $contentBlock) { $this->logger->info('Cleanup html failed. Return given content (a bit cleaned)'); return trim($this->cleanupXss($originalContentBlock)); } $this->extractor->readability->clean($contentBlock, 'select'); if ($this->config['rewrite_relative_urls']) { $this->makeAbsolute($url, $contentBlock); } // footnotes if ('footnotes' === $this->config['content_links'] && false === strpos($url, 'wikipedia.org')) { $this->extractor->readability->addFootnotes($contentBlock); } // normalise $contentBlock->normalize(); // remove empty text nodes foreach ($contentBlock->childNodes as $n) { if (XML_TEXT_NODE === $n->nodeType && '' === trim($n->textContent)) { $contentBlock->removeChild($n); } } // remove nesting: <div><div><div><p>test</p></div></div></div> = <p>test</p> while (1 === $contentBlock->childNodes->length && XML_ELEMENT_NODE === $contentBlock->firstChild->nodeType) { // only follow these tag names if (!\in_array(strtolower($contentBlock->tagName), ['div', 'article', 'section', 'header', 'footer'], true)) { break; } $contentBlock = $contentBlock->firstChild; } // convert content block to HTML string // Need to preserve things like body: //img[@id='feature'] if (\in_array(strtolower($contentBlock->tagName), ['div', 'article', 'section', 'header', 'footer', 'li', 'td'], true)) { $html = $contentBlock->innerHTML; } else { $html = $contentBlock->ownerDocument->saveXML($contentBlock); // essentially outerHTML } // post-processing cleanup $html = preg_replace('!<p>[\s\h\v]*</p>!u', '', $html); if ('remove' === $this->config['content_links']) { $html = preg_replace('!</?a[^>]*>!', '', $html); } $this->logger->debug('Body after cleanupHtml, before cleanupXss', ['html' => $html]); return trim($this->cleanupXss($html)); }
[ "public", "function", "cleanupHtml", "(", "$", "contentBlock", ",", "$", "url", ")", "{", "$", "originalContentBlock", "=", "$", "contentBlock", ";", "// if content is pure html, convert it", "if", "(", "!", "$", "contentBlock", "instanceof", "\\", "DOMElement", "...
Cleanup HTML from a DOMElement or a string. @param string|\DOMElement $contentBlock @param string $url @return string
[ "Cleanup", "HTML", "from", "a", "DOMElement", "or", "a", "string", "." ]
6c1506f19d1bb876fb26bfc11e3e11a993eb7fe8
https://github.com/j0k3r/graby/blob/6c1506f19d1bb876fb26bfc11e3e11a993eb7fe8/src/Graby.php#L182-L248
train
j0k3r/graby
src/Graby.php
Graby.validateUrl
private function validateUrl($url) { // Check for feed URL $url = trim($url); if ('feed://' === strtolower(substr($url, 0, 7))) { $url = 'http://' . substr($url, 7); } if (!preg_match('!^https?://.+!i', $url)) { $url = 'http://' . $url; } // explode url to convert accents $parsedUrl = parse_url($url); if (false === $parsedUrl) { throw new \Exception(sprintf('Url "%s" is not valid.', $url)); } if (isset($parsedUrl['host']) && preg_match('/[\x80-\xff]/', $parsedUrl['host'])) { $parsedUrl['host'] = $this->punycode->encode($parsedUrl['host']); } if (isset($parsedUrl['path']) && preg_match('/[\x80-\xff]/', $parsedUrl['path'])) { $path = []; foreach (explode('/', $parsedUrl['path']) as $value) { $path[] = urlencode($value); } $parsedUrl['path'] = implode('/', $path); } // everything should be converted, rebuild the final url $url = $this->unparseUrl($parsedUrl); if (false === filter_var($url, FILTER_VALIDATE_URL)) { throw new \Exception(sprintf('Url "%s" is not valid.', $url)); } $url = filter_var($url, FILTER_SANITIZE_URL); if (false === $this->isUrlAllowed($url)) { throw new \Exception(sprintf('Url "%s" is not allowed to be parsed.', $url)); } return $url; }
php
private function validateUrl($url) { // Check for feed URL $url = trim($url); if ('feed://' === strtolower(substr($url, 0, 7))) { $url = 'http://' . substr($url, 7); } if (!preg_match('!^https?://.+!i', $url)) { $url = 'http://' . $url; } // explode url to convert accents $parsedUrl = parse_url($url); if (false === $parsedUrl) { throw new \Exception(sprintf('Url "%s" is not valid.', $url)); } if (isset($parsedUrl['host']) && preg_match('/[\x80-\xff]/', $parsedUrl['host'])) { $parsedUrl['host'] = $this->punycode->encode($parsedUrl['host']); } if (isset($parsedUrl['path']) && preg_match('/[\x80-\xff]/', $parsedUrl['path'])) { $path = []; foreach (explode('/', $parsedUrl['path']) as $value) { $path[] = urlencode($value); } $parsedUrl['path'] = implode('/', $path); } // everything should be converted, rebuild the final url $url = $this->unparseUrl($parsedUrl); if (false === filter_var($url, FILTER_VALIDATE_URL)) { throw new \Exception(sprintf('Url "%s" is not valid.', $url)); } $url = filter_var($url, FILTER_SANITIZE_URL); if (false === $this->isUrlAllowed($url)) { throw new \Exception(sprintf('Url "%s" is not allowed to be parsed.', $url)); } return $url; }
[ "private", "function", "validateUrl", "(", "$", "url", ")", "{", "// Check for feed URL", "$", "url", "=", "trim", "(", "$", "url", ")", ";", "if", "(", "'feed://'", "===", "strtolower", "(", "substr", "(", "$", "url", ",", "0", ",", "7", ")", ")", ...
Validate & clean the given url. @param string $url @return string
[ "Validate", "&", "clean", "the", "given", "url", "." ]
6c1506f19d1bb876fb26bfc11e3e11a993eb7fe8
https://github.com/j0k3r/graby/blob/6c1506f19d1bb876fb26bfc11e3e11a993eb7fe8/src/Graby.php#L445-L490
train
j0k3r/graby
src/Graby.php
Graby.getMimeActionInfo
private function getMimeActionInfo(array $headers) { $contentType = isset($headers['content-type']) ? strtolower($headers['content-type']) : ''; // check if action defined for returned Content-Type $info = [ 'mime' => '', ]; if (preg_match('!\s*(([-\w]+)/([-\w\+]+))!im', $contentType, $match)) { // look for full mime type (e.g. image/jpeg) or just type (e.g. image) // match[1] = full mime type, e.g. image/jpeg // match[2] = first part, e.g. image // match[3] = last part, e.g. jpeg $info['mime'] = trim($match[1]); $info['type'] = trim($match[2]); $info['subtype'] = trim($match[3]); foreach ([$info['mime'], $info['type']] as $mime) { if (isset($this->config['content_type_exc'][$mime])) { $info['action'] = $this->config['content_type_exc'][$mime]['action']; $info['name'] = $this->config['content_type_exc'][$mime]['name']; break; } } } return $info; }
php
private function getMimeActionInfo(array $headers) { $contentType = isset($headers['content-type']) ? strtolower($headers['content-type']) : ''; // check if action defined for returned Content-Type $info = [ 'mime' => '', ]; if (preg_match('!\s*(([-\w]+)/([-\w\+]+))!im', $contentType, $match)) { // look for full mime type (e.g. image/jpeg) or just type (e.g. image) // match[1] = full mime type, e.g. image/jpeg // match[2] = first part, e.g. image // match[3] = last part, e.g. jpeg $info['mime'] = trim($match[1]); $info['type'] = trim($match[2]); $info['subtype'] = trim($match[3]); foreach ([$info['mime'], $info['type']] as $mime) { if (isset($this->config['content_type_exc'][$mime])) { $info['action'] = $this->config['content_type_exc'][$mime]['action']; $info['name'] = $this->config['content_type_exc'][$mime]['name']; break; } } } return $info; }
[ "private", "function", "getMimeActionInfo", "(", "array", "$", "headers", ")", "{", "$", "contentType", "=", "isset", "(", "$", "headers", "[", "'content-type'", "]", ")", "?", "strtolower", "(", "$", "headers", "[", "'content-type'", "]", ")", ":", "''", ...
Based on content-type http header, decide what to do. @param array $headers All headers from the response @return array With keys: 'mime', 'type', 'subtype', 'action', 'name' e.g. array('mime'=>'image/jpeg', 'type'=>'image', 'subtype'=>'jpeg', 'action'=>'link', 'name'=>'Image')
[ "Based", "on", "content", "-", "type", "http", "header", "decide", "what", "to", "do", "." ]
6c1506f19d1bb876fb26bfc11e3e11a993eb7fe8
https://github.com/j0k3r/graby/blob/6c1506f19d1bb876fb26bfc11e3e11a993eb7fe8/src/Graby.php#L522-L551
train
j0k3r/graby
src/Graby.php
Graby.getSinglePage
private function getSinglePage($html, $url) { $this->logger->info('Looking for site config files to see if single page link exists'); $siteConfig = $this->configBuilder->buildFromUrl($url); // no single page found? if (empty($siteConfig->single_page_link)) { $this->logger->info('No "single_page_link" config found'); return false; } // Build DOM tree from HTML $readability = new Readability($html, $url); $xpath = new \DOMXPath($readability->dom); // Loop through single_page_link xpath expressions $singlePageUrl = null; foreach ($siteConfig->single_page_link as $pattern) { // Do we have conditions? $condition = $siteConfig->getIfPageContainsCondition('single_page_link', $pattern); if ($condition) { $elems = $xpath->evaluate($condition, $readability->dom); // move on to next single_page_link XPath in case condition isn't met if (!($elems instanceof \DOMNodeList && $elems->length > 0)) { continue; } } $elems = $xpath->evaluate($pattern, $readability->dom); if (\is_string($elems)) { $singlePageUrl = trim($elems); break; } elseif ($elems instanceof \DOMNodeList && $elems->length > 0) { foreach ($elems as $item) { if ($item instanceof \DOMElement && $item->hasAttribute('href')) { $singlePageUrl = $item->getAttribute('href'); break 2; } elseif ($item instanceof \DOMAttr && $item->value) { $singlePageUrl = $item->value; break 2; } } } } if (!$singlePageUrl) { $this->logger->info('No single page url found'); return false; } // try to resolve against $url $singlePageUrl = $this->makeAbsoluteStr($url, $singlePageUrl); // check it's not what we have already! if (false !== $singlePageUrl && $singlePageUrl !== $url) { // it's not, so let's try to fetch it... $response = $this->httpClient->fetch($singlePageUrl, false, $siteConfig->http_header); if ($response['status'] < 300) { $this->logger->info('Single page content found with url', ['url' => $singlePageUrl]); return $response; } } $this->logger->info('No content found with url', ['url' => $singlePageUrl]); return false; }
php
private function getSinglePage($html, $url) { $this->logger->info('Looking for site config files to see if single page link exists'); $siteConfig = $this->configBuilder->buildFromUrl($url); // no single page found? if (empty($siteConfig->single_page_link)) { $this->logger->info('No "single_page_link" config found'); return false; } // Build DOM tree from HTML $readability = new Readability($html, $url); $xpath = new \DOMXPath($readability->dom); // Loop through single_page_link xpath expressions $singlePageUrl = null; foreach ($siteConfig->single_page_link as $pattern) { // Do we have conditions? $condition = $siteConfig->getIfPageContainsCondition('single_page_link', $pattern); if ($condition) { $elems = $xpath->evaluate($condition, $readability->dom); // move on to next single_page_link XPath in case condition isn't met if (!($elems instanceof \DOMNodeList && $elems->length > 0)) { continue; } } $elems = $xpath->evaluate($pattern, $readability->dom); if (\is_string($elems)) { $singlePageUrl = trim($elems); break; } elseif ($elems instanceof \DOMNodeList && $elems->length > 0) { foreach ($elems as $item) { if ($item instanceof \DOMElement && $item->hasAttribute('href')) { $singlePageUrl = $item->getAttribute('href'); break 2; } elseif ($item instanceof \DOMAttr && $item->value) { $singlePageUrl = $item->value; break 2; } } } } if (!$singlePageUrl) { $this->logger->info('No single page url found'); return false; } // try to resolve against $url $singlePageUrl = $this->makeAbsoluteStr($url, $singlePageUrl); // check it's not what we have already! if (false !== $singlePageUrl && $singlePageUrl !== $url) { // it's not, so let's try to fetch it... $response = $this->httpClient->fetch($singlePageUrl, false, $siteConfig->http_header); if ($response['status'] < 300) { $this->logger->info('Single page content found with url', ['url' => $singlePageUrl]); return $response; } } $this->logger->info('No content found with url', ['url' => $singlePageUrl]); return false; }
[ "private", "function", "getSinglePage", "(", "$", "html", ",", "$", "url", ")", "{", "$", "this", "->", "logger", "->", "info", "(", "'Looking for site config files to see if single page link exists'", ")", ";", "$", "siteConfig", "=", "$", "this", "->", "config...
returns single page response, or false if not found. @param string $html @param string $url @return false|array From httpClient fetch
[ "returns", "single", "page", "response", "or", "false", "if", "not", "found", "." ]
6c1506f19d1bb876fb26bfc11e3e11a993eb7fe8
https://github.com/j0k3r/graby/blob/6c1506f19d1bb876fb26bfc11e3e11a993eb7fe8/src/Graby.php#L658-L732
train
j0k3r/graby
src/Graby.php
Graby.makeAbsolute
private function makeAbsolute($base, \DOMNode $elem) { $base = new \SimplePie_IRI($base); // remove '//' in URL path (used to prevent URLs from resolving properly) if (isset($base->ipath)) { $base->ipath = str_replace('//', '/', $base->ipath); } foreach (['a' => 'href', 'img' => 'src', 'iframe' => 'src'] as $tag => $attr) { $elems = $elem->getElementsByTagName($tag); for ($i = $elems->length - 1; $i >= 0; --$i) { $e = $elems->item($i); $this->makeAbsoluteAttr($base, $e, $attr); } if (strtolower($elem->nodeName) === $tag) { $this->makeAbsoluteAttr($base, $elem, $attr); } } }
php
private function makeAbsolute($base, \DOMNode $elem) { $base = new \SimplePie_IRI($base); // remove '//' in URL path (used to prevent URLs from resolving properly) if (isset($base->ipath)) { $base->ipath = str_replace('//', '/', $base->ipath); } foreach (['a' => 'href', 'img' => 'src', 'iframe' => 'src'] as $tag => $attr) { $elems = $elem->getElementsByTagName($tag); for ($i = $elems->length - 1; $i >= 0; --$i) { $e = $elems->item($i); $this->makeAbsoluteAttr($base, $e, $attr); } if (strtolower($elem->nodeName) === $tag) { $this->makeAbsoluteAttr($base, $elem, $attr); } } }
[ "private", "function", "makeAbsolute", "(", "$", "base", ",", "\\", "DOMNode", "$", "elem", ")", "{", "$", "base", "=", "new", "\\", "SimplePie_IRI", "(", "$", "base", ")", ";", "// remove '//' in URL path (used to prevent URLs from resolving properly)", "if", "("...
Make an absolute url from an element. @param string $base The base url @param \DOMNode $elem Element on which we'll retrieve the attribute
[ "Make", "an", "absolute", "url", "from", "an", "element", "." ]
6c1506f19d1bb876fb26bfc11e3e11a993eb7fe8
https://github.com/j0k3r/graby/blob/6c1506f19d1bb876fb26bfc11e3e11a993eb7fe8/src/Graby.php#L740-L761
train
j0k3r/graby
src/Graby.php
Graby.getExcerpt
private function getExcerpt($text, $length = 250, $separator = ' &hellip;') { // use regex instead of strip_tags to left some spaces when removing tags $text = preg_replace('#<[^>]+>#', ' ', $text); // trim whitespace at beginning or end of string // See: http://stackoverflow.com/a/4167053/569101 $text = preg_replace('/^[\pZ\pC]+|[\pZ\pC]+$/u', '', $text); // clean new lines and tabs $text = trim(preg_replace("/[\n\r\t ]+/", ' ', $text), ' '); if (mb_strlen($text) > $length) { // If breakpoint is on the last word, return the text without separator. if (false === ($breakpoint = mb_strpos($text, ' ', $length))) { return $text; } $length = $breakpoint; return rtrim(mb_substr($text, 0, $length)) . $separator; } return $text; }
php
private function getExcerpt($text, $length = 250, $separator = ' &hellip;') { // use regex instead of strip_tags to left some spaces when removing tags $text = preg_replace('#<[^>]+>#', ' ', $text); // trim whitespace at beginning or end of string // See: http://stackoverflow.com/a/4167053/569101 $text = preg_replace('/^[\pZ\pC]+|[\pZ\pC]+$/u', '', $text); // clean new lines and tabs $text = trim(preg_replace("/[\n\r\t ]+/", ' ', $text), ' '); if (mb_strlen($text) > $length) { // If breakpoint is on the last word, return the text without separator. if (false === ($breakpoint = mb_strpos($text, ' ', $length))) { return $text; } $length = $breakpoint; return rtrim(mb_substr($text, 0, $length)) . $separator; } return $text; }
[ "private", "function", "getExcerpt", "(", "$", "text", ",", "$", "length", "=", "250", ",", "$", "separator", "=", "' &hellip;'", ")", "{", "// use regex instead of strip_tags to left some spaces when removing tags", "$", "text", "=", "preg_replace", "(", "'#<[^>]+>#'...
Truncate text. @see https://github.com/twigphp/Twig-extensions/blob/449e3c8a9ffad7c2479c7864557275a32b037499/lib/Twig/Extensions/Extension/Text.php#L40 @param string $text @param int $length @param string $separator @return string
[ "Truncate", "text", "." ]
6c1506f19d1bb876fb26bfc11e3e11a993eb7fe8
https://github.com/j0k3r/graby/blob/6c1506f19d1bb876fb26bfc11e3e11a993eb7fe8/src/Graby.php#L832-L854
train
j0k3r/graby
src/Graby.php
Graby.extractOpenGraph
private function extractOpenGraph($html, $baseUrl) { if ('' === trim($html)) { return []; } libxml_use_internal_errors(true); $doc = new \DomDocument(); $doc->loadHTML($html); libxml_use_internal_errors(false); $xpath = new \DOMXPath($doc); $query = '//*/meta[starts-with(@property, \'og:\')]'; $metas = $xpath->query($query); $rmetas = []; foreach ($metas as $meta) { $property = str_replace(':', '_', $meta->getAttribute('property')); if ('og_image' === $property) { // avoid image data:uri to avoid sending too much data // also, take the first og:image which is usually the best one if (0 === stripos($meta->getAttribute('content'), 'data:image') || !empty($rmetas[$property])) { continue; } $rmetas[$property] = $this->makeAbsoluteStr($baseUrl, $meta->getAttribute('content')); continue; } $rmetas[$property] = $meta->getAttribute('content'); } return $rmetas; }
php
private function extractOpenGraph($html, $baseUrl) { if ('' === trim($html)) { return []; } libxml_use_internal_errors(true); $doc = new \DomDocument(); $doc->loadHTML($html); libxml_use_internal_errors(false); $xpath = new \DOMXPath($doc); $query = '//*/meta[starts-with(@property, \'og:\')]'; $metas = $xpath->query($query); $rmetas = []; foreach ($metas as $meta) { $property = str_replace(':', '_', $meta->getAttribute('property')); if ('og_image' === $property) { // avoid image data:uri to avoid sending too much data // also, take the first og:image which is usually the best one if (0 === stripos($meta->getAttribute('content'), 'data:image') || !empty($rmetas[$property])) { continue; } $rmetas[$property] = $this->makeAbsoluteStr($baseUrl, $meta->getAttribute('content')); continue; } $rmetas[$property] = $meta->getAttribute('content'); } return $rmetas; }
[ "private", "function", "extractOpenGraph", "(", "$", "html", ",", "$", "baseUrl", ")", "{", "if", "(", "''", "===", "trim", "(", "$", "html", ")", ")", "{", "return", "[", "]", ";", "}", "libxml_use_internal_errors", "(", "true", ")", ";", "$", "doc"...
Extract OpenGraph data from the response. @param string $html @param string $baseUrl Used to make the og:image absolute @return array @see http://stackoverflow.com/a/7454737/569101
[ "Extract", "OpenGraph", "data", "from", "the", "response", "." ]
6c1506f19d1bb876fb26bfc11e3e11a993eb7fe8
https://github.com/j0k3r/graby/blob/6c1506f19d1bb876fb26bfc11e3e11a993eb7fe8/src/Graby.php#L866-L903
train
j0k3r/graby
src/Graby.php
Graby.unparseUrl
private function unparseUrl($data) { $scheme = isset($data['scheme']) ? $data['scheme'] . '://' : ''; $host = isset($data['host']) ? $data['host'] : ''; $port = isset($data['port']) ? ':' . $data['port'] : ''; $user = isset($data['user']) ? $data['user'] : ''; $pass = isset($data['pass']) ? ':' . $data['pass'] : ''; $pass = ($user || $pass) ? "$pass@" : ''; $path = isset($data['path']) ? $data['path'] : ''; $query = isset($data['query']) ? '?' . $data['query'] : ''; $fragment = isset($data['fragment']) ? '#' . $data['fragment'] : ''; return "$scheme$user$pass$host$port$path$query$fragment"; }
php
private function unparseUrl($data) { $scheme = isset($data['scheme']) ? $data['scheme'] . '://' : ''; $host = isset($data['host']) ? $data['host'] : ''; $port = isset($data['port']) ? ':' . $data['port'] : ''; $user = isset($data['user']) ? $data['user'] : ''; $pass = isset($data['pass']) ? ':' . $data['pass'] : ''; $pass = ($user || $pass) ? "$pass@" : ''; $path = isset($data['path']) ? $data['path'] : ''; $query = isset($data['query']) ? '?' . $data['query'] : ''; $fragment = isset($data['fragment']) ? '#' . $data['fragment'] : ''; return "$scheme$user$pass$host$port$path$query$fragment"; }
[ "private", "function", "unparseUrl", "(", "$", "data", ")", "{", "$", "scheme", "=", "isset", "(", "$", "data", "[", "'scheme'", "]", ")", "?", "$", "data", "[", "'scheme'", "]", ".", "'://'", ":", "''", ";", "$", "host", "=", "isset", "(", "$", ...
Rebuild an url using the response from parse_url. Useful to rebuild an url after editing only the host, for example. @param array $data @return array
[ "Rebuild", "an", "url", "using", "the", "response", "from", "parse_url", ".", "Useful", "to", "rebuild", "an", "url", "after", "editing", "only", "the", "host", "for", "example", "." ]
6c1506f19d1bb876fb26bfc11e3e11a993eb7fe8
https://github.com/j0k3r/graby/blob/6c1506f19d1bb876fb26bfc11e3e11a993eb7fe8/src/Graby.php#L913-L926
train
j0k3r/graby
src/Graby.php
Graby.cleanupXss
private function cleanupXss($html) { if (false === $this->config['xss_filter']) { return $html; } $this->logger->info('Filtering HTML to remove XSS'); return htmLawed( $html, [ 'safe' => 1, // *+iframe: do not remove iframe elements 'elements' => '*+iframe-meta', 'deny_attribute' => 'style', 'comment' => 1, 'cdata' => 1, ] ); }
php
private function cleanupXss($html) { if (false === $this->config['xss_filter']) { return $html; } $this->logger->info('Filtering HTML to remove XSS'); return htmLawed( $html, [ 'safe' => 1, // *+iframe: do not remove iframe elements 'elements' => '*+iframe-meta', 'deny_attribute' => 'style', 'comment' => 1, 'cdata' => 1, ] ); }
[ "private", "function", "cleanupXss", "(", "$", "html", ")", "{", "if", "(", "false", "===", "$", "this", "->", "config", "[", "'xss_filter'", "]", ")", "{", "return", "$", "html", ";", "}", "$", "this", "->", "logger", "->", "info", "(", "'Filtering ...
Try to cleanup XSS using htmLawed. @param string $html @return string
[ "Try", "to", "cleanup", "XSS", "using", "htmLawed", "." ]
6c1506f19d1bb876fb26bfc11e3e11a993eb7fe8
https://github.com/j0k3r/graby/blob/6c1506f19d1bb876fb26bfc11e3e11a993eb7fe8/src/Graby.php#L1048-L1067
train
j0k3r/graby
src/Extractor/ContentExtractor.php
ContentExtractor.findHostUsingFingerprints
public function findHostUsingFingerprints($html) { foreach ($this->config['fingerprints'] as $metaPattern => $host) { if (1 === preg_match($metaPattern, $html)) { return $host; } } return false; }
php
public function findHostUsingFingerprints($html) { foreach ($this->config['fingerprints'] as $metaPattern => $host) { if (1 === preg_match($metaPattern, $html)) { return $host; } } return false; }
[ "public", "function", "findHostUsingFingerprints", "(", "$", "html", ")", "{", "foreach", "(", "$", "this", "->", "config", "[", "'fingerprints'", "]", "as", "$", "metaPattern", "=>", "$", "host", ")", "{", "if", "(", "1", "===", "preg_match", "(", "$", ...
Try to find a host depending on a meta that can be in the html. It allow to determine if a website is generated using Wordpress, Blogger, etc .. @param string $html @return string|false
[ "Try", "to", "find", "a", "host", "depending", "on", "a", "meta", "that", "can", "be", "in", "the", "html", ".", "It", "allow", "to", "determine", "if", "a", "website", "is", "generated", "using", "Wordpress", "Blogger", "etc", ".." ]
6c1506f19d1bb876fb26bfc11e3e11a993eb7fe8
https://github.com/j0k3r/graby/blob/6c1506f19d1bb876fb26bfc11e3e11a993eb7fe8/src/Extractor/ContentExtractor.php#L112-L121
train
j0k3r/graby
src/Extractor/ContentExtractor.php
ContentExtractor.removeElements
private function removeElements(\DOMNodeList $elems, $logMessage = null) { if (false === $this->hasElements($elems)) { return; } if (null !== $logMessage) { $this->logger->info($logMessage, ['length' => $elems->length]); } for ($i = $elems->length - 1; $i >= 0; --$i) { if ($elems->item($i)->parentNode) { $elems->item($i)->parentNode->removeChild($elems->item($i)); } } }
php
private function removeElements(\DOMNodeList $elems, $logMessage = null) { if (false === $this->hasElements($elems)) { return; } if (null !== $logMessage) { $this->logger->info($logMessage, ['length' => $elems->length]); } for ($i = $elems->length - 1; $i >= 0; --$i) { if ($elems->item($i)->parentNode) { $elems->item($i)->parentNode->removeChild($elems->item($i)); } } }
[ "private", "function", "removeElements", "(", "\\", "DOMNodeList", "$", "elems", ",", "$", "logMessage", "=", "null", ")", "{", "if", "(", "false", "===", "$", "this", "->", "hasElements", "(", "$", "elems", ")", ")", "{", "return", ";", "}", "if", "...
Remove elements. @param \DOMNodeList $elems @param string $logMessage
[ "Remove", "elements", "." ]
6c1506f19d1bb876fb26bfc11e3e11a993eb7fe8
https://github.com/j0k3r/graby/blob/6c1506f19d1bb876fb26bfc11e3e11a993eb7fe8/src/Extractor/ContentExtractor.php#L735-L750
train
j0k3r/graby
src/Extractor/ContentExtractor.php
ContentExtractor.removeAttributes
private function removeAttributes(\DOMNodeList $elems, $logMessage = null) { if (null !== $logMessage) { $this->logger->info($logMessage, ['length' => $elems->length]); } foreach ($elems as $el) { $owner = $el->ownerElement; $owner->removeAttributeNode($el); } }
php
private function removeAttributes(\DOMNodeList $elems, $logMessage = null) { if (null !== $logMessage) { $this->logger->info($logMessage, ['length' => $elems->length]); } foreach ($elems as $el) { $owner = $el->ownerElement; $owner->removeAttributeNode($el); } }
[ "private", "function", "removeAttributes", "(", "\\", "DOMNodeList", "$", "elems", ",", "$", "logMessage", "=", "null", ")", "{", "if", "(", "null", "!==", "$", "logMessage", ")", "{", "$", "this", "->", "logger", "->", "info", "(", "$", "logMessage", ...
Remove attribute from owners. @param \DOMNodeList $elems @param string $logMessage
[ "Remove", "attribute", "from", "owners", "." ]
6c1506f19d1bb876fb26bfc11e3e11a993eb7fe8
https://github.com/j0k3r/graby/blob/6c1506f19d1bb876fb26bfc11e3e11a993eb7fe8/src/Extractor/ContentExtractor.php#L758-L768
train
j0k3r/graby
src/Extractor/ContentExtractor.php
ContentExtractor.extractEntityFromQuery
private function extractEntityFromQuery($entity, $detectEntity, $xpathExpression, \DOMNode $node, $logMessage, $returnCallback = null) { if (false === $detectEntity) { return false; } // we define the default callback here if (!\is_callable($returnCallback)) { $returnCallback = function ($element) { return trim($element); }; } // check for given css class // shut up operator as there is no pre-validation possible. $elems = @$this->xpath->query($xpathExpression, $node); if (false === $elems || false === $this->hasElements($elems)) { return true; } $this->{$entity} = $returnCallback( $elems->item(0)->textContent, $this->{$entity} ); $this->logger->info($logMessage, [$entity => $this->{$entity}]); // remove entity from document try { $elems->item(0)->parentNode->removeChild($elems->item(0)); } catch (\DOMException $e) { // do nothing } return false; }
php
private function extractEntityFromQuery($entity, $detectEntity, $xpathExpression, \DOMNode $node, $logMessage, $returnCallback = null) { if (false === $detectEntity) { return false; } // we define the default callback here if (!\is_callable($returnCallback)) { $returnCallback = function ($element) { return trim($element); }; } // check for given css class // shut up operator as there is no pre-validation possible. $elems = @$this->xpath->query($xpathExpression, $node); if (false === $elems || false === $this->hasElements($elems)) { return true; } $this->{$entity} = $returnCallback( $elems->item(0)->textContent, $this->{$entity} ); $this->logger->info($logMessage, [$entity => $this->{$entity}]); // remove entity from document try { $elems->item(0)->parentNode->removeChild($elems->item(0)); } catch (\DOMException $e) { // do nothing } return false; }
[ "private", "function", "extractEntityFromQuery", "(", "$", "entity", ",", "$", "detectEntity", ",", "$", "xpathExpression", ",", "\\", "DOMNode", "$", "node", ",", "$", "logMessage", ",", "$", "returnCallback", "=", "null", ")", "{", "if", "(", "false", "=...
Extract entity for a given CSS class a node. The $entity argument is used as the name of the property to set in the current ContentExtractor instance (variable reference) and as the name to use in log messages Example: extractEntityFromQuery('title', $detectEntity, $xpathExpression, $node, $log, $returnCallback) will search for expression and set the found value in $this->title @param string $entity Entity to look for ('title', 'date') @param bool $detectEntity Do we have to detect entity? @param string $xpathExpression XPath query to look for @param \DOMNode $node DOMNode to look into @param string $logMessage @param \Closure $returnCallback Function to cleanup the current value found @return bool Telling if we have to detect entity again or not
[ "Extract", "entity", "for", "a", "given", "CSS", "class", "a", "node", "." ]
6c1506f19d1bb876fb26bfc11e3e11a993eb7fe8
https://github.com/j0k3r/graby/blob/6c1506f19d1bb876fb26bfc11e3e11a993eb7fe8/src/Extractor/ContentExtractor.php#L789-L824
train
j0k3r/graby
src/Extractor/ContentExtractor.php
ContentExtractor.extractTitle
private function extractTitle($detectTitle, $cssClass, \DOMNode $node, $logMessage) { return $this->extractEntityFromQuery( 'title', $detectTitle, ".//*[contains(concat(' ',normalize-space(@class),' '),' " . $cssClass . " ')]", $node, $logMessage ); }
php
private function extractTitle($detectTitle, $cssClass, \DOMNode $node, $logMessage) { return $this->extractEntityFromQuery( 'title', $detectTitle, ".//*[contains(concat(' ',normalize-space(@class),' '),' " . $cssClass . " ')]", $node, $logMessage ); }
[ "private", "function", "extractTitle", "(", "$", "detectTitle", ",", "$", "cssClass", ",", "\\", "DOMNode", "$", "node", ",", "$", "logMessage", ")", "{", "return", "$", "this", "->", "extractEntityFromQuery", "(", "'title'", ",", "$", "detectTitle", ",", ...
Extract title for a given CSS class a node. @param bool $detectTitle Do we have to detect title ? @param string $cssClass CSS class to look for @param \DOMNode $node DOMNode to look into @param string $logMessage @return bool Telling if we have to detect title again or not
[ "Extract", "title", "for", "a", "given", "CSS", "class", "a", "node", "." ]
6c1506f19d1bb876fb26bfc11e3e11a993eb7fe8
https://github.com/j0k3r/graby/blob/6c1506f19d1bb876fb26bfc11e3e11a993eb7fe8/src/Extractor/ContentExtractor.php#L836-L845
train
j0k3r/graby
src/Extractor/ContentExtractor.php
ContentExtractor.extractDate
private function extractDate($detectDate, $cssClass, \DOMNode $node, $logMessage) { return $this->extractEntityFromQuery( 'date', $detectDate, ".//time[@pubdate or @pubDate] | .//abbr[contains(concat(' ',normalize-space(@class),' '),' " . $cssClass . " ')]", $node, $logMessage ); }
php
private function extractDate($detectDate, $cssClass, \DOMNode $node, $logMessage) { return $this->extractEntityFromQuery( 'date', $detectDate, ".//time[@pubdate or @pubDate] | .//abbr[contains(concat(' ',normalize-space(@class),' '),' " . $cssClass . " ')]", $node, $logMessage ); }
[ "private", "function", "extractDate", "(", "$", "detectDate", ",", "$", "cssClass", ",", "\\", "DOMNode", "$", "node", ",", "$", "logMessage", ")", "{", "return", "$", "this", "->", "extractEntityFromQuery", "(", "'date'", ",", "$", "detectDate", ",", "\"....
Extract date for a given CSS class a node. @param bool $detectDate Do we have to detect date ? @param string $cssClass CSS class to look for @param \DOMNode $node DOMNode to look into @param string $logMessage @return bool Telling if we have to detect date again or not
[ "Extract", "date", "for", "a", "given", "CSS", "class", "a", "node", "." ]
6c1506f19d1bb876fb26bfc11e3e11a993eb7fe8
https://github.com/j0k3r/graby/blob/6c1506f19d1bb876fb26bfc11e3e11a993eb7fe8/src/Extractor/ContentExtractor.php#L857-L866
train
j0k3r/graby
src/Extractor/ContentExtractor.php
ContentExtractor.extractAuthor
private function extractAuthor($detectAuthor, \DOMNode $node) { if (false === $detectAuthor) { return false; } // check for time element with pubdate attribute $elems = $this->xpath->query(".//*[contains(concat(' ',normalize-space(@class),' '),' vcard ') and (contains(concat(' ',normalize-space(@class),' '),' author ') or contains(concat(' ',normalize-space(@class),' '),' byline '))]", $node); if ($elems && $elems->length > 0) { $author = $elems->item(0); $fns = $this->xpath->query(".//*[contains(concat(' ',normalize-space(@class),' '),' fn ')]", $author); if ($fns && $fns->length > 0) { foreach ($fns as $fn) { if ('' !== trim($fn->textContent)) { $this->addAuthor($fn->textContent); $this->logger->info('hNews: found author: ' . trim($fn->textContent)); } } } else { if ('' !== trim($author->textContent)) { $this->addAuthor($author->textContent); $this->logger->info('hNews: found author: ' . trim($author->textContent)); } } return empty($this->authors); } return true; }
php
private function extractAuthor($detectAuthor, \DOMNode $node) { if (false === $detectAuthor) { return false; } // check for time element with pubdate attribute $elems = $this->xpath->query(".//*[contains(concat(' ',normalize-space(@class),' '),' vcard ') and (contains(concat(' ',normalize-space(@class),' '),' author ') or contains(concat(' ',normalize-space(@class),' '),' byline '))]", $node); if ($elems && $elems->length > 0) { $author = $elems->item(0); $fns = $this->xpath->query(".//*[contains(concat(' ',normalize-space(@class),' '),' fn ')]", $author); if ($fns && $fns->length > 0) { foreach ($fns as $fn) { if ('' !== trim($fn->textContent)) { $this->addAuthor($fn->textContent); $this->logger->info('hNews: found author: ' . trim($fn->textContent)); } } } else { if ('' !== trim($author->textContent)) { $this->addAuthor($author->textContent); $this->logger->info('hNews: found author: ' . trim($author->textContent)); } } return empty($this->authors); } return true; }
[ "private", "function", "extractAuthor", "(", "$", "detectAuthor", ",", "\\", "DOMNode", "$", "node", ")", "{", "if", "(", "false", "===", "$", "detectAuthor", ")", "{", "return", "false", ";", "}", "// check for time element with pubdate attribute", "$", "elems"...
Extract author. @param bool $detectAuthor Do we have to detect author ? @param \DOMNode $node DOMNode to look into @return bool Telling if we have to detect author again or not
[ "Extract", "author", "." ]
6c1506f19d1bb876fb26bfc11e3e11a993eb7fe8
https://github.com/j0k3r/graby/blob/6c1506f19d1bb876fb26bfc11e3e11a993eb7fe8/src/Extractor/ContentExtractor.php#L876-L907
train
j0k3r/graby
src/Extractor/ContentExtractor.php
ContentExtractor.extractBody
private function extractBody($detectBody, $xpathExpression, \DOMNode $node, $type) { if (false === $detectBody) { return false; } // shut up operator as there is no pre-validation possible. $elems = @$this->xpath->query($xpathExpression, $node); if (false === $elems || false === $this->hasElements($elems)) { return $detectBody; } $this->logger->info($type . ': found "' . $elems->length . '" with ' . $xpathExpression); if (1 === $elems->length) { // body can't be an attribute if ($elems->item(0) instanceof \DOMAttr) { $this->logger->info('Body can not be an attribute'); return true; } $this->body = $elems->item(0); // prune (clean up elements that may not be content) if ($this->siteConfig->prune()) { $this->logger->info('Pruning content'); $this->readability->prepArticle($this->body); } return false; } $this->body = $this->readability->dom->createElement('div'); $this->logger->info('{nb} body elems found', ['nb' => $elems->length]); $len = 0; foreach ($elems as $elem) { if (!isset($elem->parentNode)) { continue; } $isDescendant = false; foreach ($this->body->childNodes as $parent) { $node = $elem->parentNode; while (null !== $node) { if ($node->isSameNode($parent)) { $isDescendant = true; break 2; } $node = $node->parentNode; } } if ($isDescendant) { $this->logger->info('...element is child of another body element, skipping.'); } else { // prune (clean up elements that may not be content) if ($this->siteConfig->prune()) { $this->logger->info('...pruning content'); $this->readability->prepArticle($elem); } if ($elem) { ++$len; $this->body->appendChild($elem); } } } $this->logger->info('...{len} elements added to body', ['len' => $len]); return false; }
php
private function extractBody($detectBody, $xpathExpression, \DOMNode $node, $type) { if (false === $detectBody) { return false; } // shut up operator as there is no pre-validation possible. $elems = @$this->xpath->query($xpathExpression, $node); if (false === $elems || false === $this->hasElements($elems)) { return $detectBody; } $this->logger->info($type . ': found "' . $elems->length . '" with ' . $xpathExpression); if (1 === $elems->length) { // body can't be an attribute if ($elems->item(0) instanceof \DOMAttr) { $this->logger->info('Body can not be an attribute'); return true; } $this->body = $elems->item(0); // prune (clean up elements that may not be content) if ($this->siteConfig->prune()) { $this->logger->info('Pruning content'); $this->readability->prepArticle($this->body); } return false; } $this->body = $this->readability->dom->createElement('div'); $this->logger->info('{nb} body elems found', ['nb' => $elems->length]); $len = 0; foreach ($elems as $elem) { if (!isset($elem->parentNode)) { continue; } $isDescendant = false; foreach ($this->body->childNodes as $parent) { $node = $elem->parentNode; while (null !== $node) { if ($node->isSameNode($parent)) { $isDescendant = true; break 2; } $node = $node->parentNode; } } if ($isDescendant) { $this->logger->info('...element is child of another body element, skipping.'); } else { // prune (clean up elements that may not be content) if ($this->siteConfig->prune()) { $this->logger->info('...pruning content'); $this->readability->prepArticle($elem); } if ($elem) { ++$len; $this->body->appendChild($elem); } } } $this->logger->info('...{len} elements added to body', ['len' => $len]); return false; }
[ "private", "function", "extractBody", "(", "$", "detectBody", ",", "$", "xpathExpression", ",", "\\", "DOMNode", "$", "node", ",", "$", "type", ")", "{", "if", "(", "false", "===", "$", "detectBody", ")", "{", "return", "false", ";", "}", "// shut up ope...
Extract body from a given CSS for a node. @param bool $detectBody Do we have to detect body ? @param string $xpathExpression XPath expression to extract body @param \DOMNode $node DOMNode to look into @param string $type Format type we are looking for, only used for log message @return bool Telling if we have to detect body again or not
[ "Extract", "body", "from", "a", "given", "CSS", "for", "a", "node", "." ]
6c1506f19d1bb876fb26bfc11e3e11a993eb7fe8
https://github.com/j0k3r/graby/blob/6c1506f19d1bb876fb26bfc11e3e11a993eb7fe8/src/Extractor/ContentExtractor.php#L919-L993
train
j0k3r/graby
src/Extractor/ContentExtractor.php
ContentExtractor.getReadability
private function getReadability($html, $url, $parser, $enableTidy) { $readability = new Readability($html, $url, $parser, $enableTidy); if (isset($this->config['readability']['pre_filters']) && \is_array($this->config['readability']['pre_filters'])) { foreach ($this->config['readability']['pre_filters'] as $filter => $replacer) { $readability->addPreFilter($filter, $replacer); } } if (isset($this->config['readability']['post_filters']) && \is_array($this->config['readability']['post_filters'])) { foreach ($this->config['readability']['post_filters'] as $filter => $replacer) { $readability->addPostFilter($filter, $replacer); } } return $readability; }
php
private function getReadability($html, $url, $parser, $enableTidy) { $readability = new Readability($html, $url, $parser, $enableTidy); if (isset($this->config['readability']['pre_filters']) && \is_array($this->config['readability']['pre_filters'])) { foreach ($this->config['readability']['pre_filters'] as $filter => $replacer) { $readability->addPreFilter($filter, $replacer); } } if (isset($this->config['readability']['post_filters']) && \is_array($this->config['readability']['post_filters'])) { foreach ($this->config['readability']['post_filters'] as $filter => $replacer) { $readability->addPostFilter($filter, $replacer); } } return $readability; }
[ "private", "function", "getReadability", "(", "$", "html", ",", "$", "url", ",", "$", "parser", ",", "$", "enableTidy", ")", "{", "$", "readability", "=", "new", "Readability", "(", "$", "html", ",", "$", "url", ",", "$", "parser", ",", "$", "enableT...
Return an instance of Readability with pre & post filters added. @param string $html HTML to make readable from Readability lib @param string $url URL of the content @param string $parser Parser to use @param bool $enableTidy Should it use tidy extension? @return Readability
[ "Return", "an", "instance", "of", "Readability", "with", "pre", "&", "post", "filters", "added", "." ]
6c1506f19d1bb876fb26bfc11e3e11a993eb7fe8
https://github.com/j0k3r/graby/blob/6c1506f19d1bb876fb26bfc11e3e11a993eb7fe8/src/Extractor/ContentExtractor.php#L1005-L1022
train
j0k3r/graby
src/Extractor/ContentExtractor.php
ContentExtractor.extractEntityFromPattern
private function extractEntityFromPattern($entity, $pattern, $returnCallback = null) { // we define the default callback here if (!\is_callable($returnCallback)) { $returnCallback = function ($e) { return trim($e); }; } $elems = $this->xpath->evaluate($pattern, $this->readability->dom); $entityValue = null; if (\is_string($elems) && '' !== trim($elems)) { $entityValue = $returnCallback($elems); $this->logger->info("{$entity} expression evaluated as string: {{$entity}}", [$entity => $entityValue]); $this->logger->info('...XPath match: {pattern}', ['pattern', $pattern]); } elseif ($elems instanceof \DOMNodeList && $elems->length > 0) { $entityValue = $returnCallback($elems->item(0)->textContent); $this->logger->info("{$entity} matched: {{$entity}}", [$entity => $entityValue]); $this->logger->info('...XPath match: {pattern}', ['pattern', $pattern]); // remove entity from document try { $elems->item(0)->parentNode->removeChild($elems->item(0)); } catch (\DOMException $e) { // do nothing } } if (null !== $entityValue) { $this->{$entity} = $entityValue; return true; } return false; }
php
private function extractEntityFromPattern($entity, $pattern, $returnCallback = null) { // we define the default callback here if (!\is_callable($returnCallback)) { $returnCallback = function ($e) { return trim($e); }; } $elems = $this->xpath->evaluate($pattern, $this->readability->dom); $entityValue = null; if (\is_string($elems) && '' !== trim($elems)) { $entityValue = $returnCallback($elems); $this->logger->info("{$entity} expression evaluated as string: {{$entity}}", [$entity => $entityValue]); $this->logger->info('...XPath match: {pattern}', ['pattern', $pattern]); } elseif ($elems instanceof \DOMNodeList && $elems->length > 0) { $entityValue = $returnCallback($elems->item(0)->textContent); $this->logger->info("{$entity} matched: {{$entity}}", [$entity => $entityValue]); $this->logger->info('...XPath match: {pattern}', ['pattern', $pattern]); // remove entity from document try { $elems->item(0)->parentNode->removeChild($elems->item(0)); } catch (\DOMException $e) { // do nothing } } if (null !== $entityValue) { $this->{$entity} = $entityValue; return true; } return false; }
[ "private", "function", "extractEntityFromPattern", "(", "$", "entity", ",", "$", "pattern", ",", "$", "returnCallback", "=", "null", ")", "{", "// we define the default callback here", "if", "(", "!", "\\", "is_callable", "(", "$", "returnCallback", ")", ")", "{...
Extract and apply a callback to an entity according to a pattern. The $entity argument is used as the name of the property to set in the current ContentExtractor instance (variable reference) and as the name to use in log messages Example: extractEntityFromPattern('title', $pattern) will search for pattern and set the found value in $this->title @param string $entity Entity to look for ('title', 'date') @param string $pattern Pattern to look for @param callable $returnCallback Function to apply on the value @return bool Telling if the entity has been found
[ "Extract", "and", "apply", "a", "callback", "to", "an", "entity", "according", "to", "a", "pattern", "." ]
6c1506f19d1bb876fb26bfc11e3e11a993eb7fe8
https://github.com/j0k3r/graby/blob/6c1506f19d1bb876fb26bfc11e3e11a993eb7fe8/src/Extractor/ContentExtractor.php#L1040-L1078
train
j0k3r/graby
src/Extractor/ContentExtractor.php
ContentExtractor.extractJsonLdInformation
private function extractJsonLdInformation($html) { preg_match_all('/<script type\=\"application\/ld\+json\"\>([\s\S]*?)<\/script>/i', $html, $matches); if (!isset($matches[1])) { return; } $ignoreNames = []; $candidateNames = []; foreach ($matches[1] as $matche) { $data = json_decode(trim($matche), true); if (isset($data['@type']) && \in_array($data['@type'], ['Organization', 'WebSite', 'Person'], true)) { if (isset($data['name'])) { $ignoreNames[] = $data['name']; } continue; } $this->logger->info('JSON-LD data: {JsonLdData}', ['JsonLdData' => $data]); // just in case datePublished isn't defined, we use the modified one at first if (isset($data['dateModified'])) { $this->date = $data['dateModified']; } if (isset($data['datePublished'])) { $this->date = $data['datePublished']; } // sometimes the date is an array if (\is_array($this->date)) { $this->date = reset($this->date); } // body should be a DOMNode if (isset($data['articlebody'])) { $dom = new \DOMDocument('1.0', 'utf-8'); $this->body = $dom->createElement('p', htmlspecialchars(trim($data['articlebody']))); } if (isset($data['headline'])) { $candidateNames[] = $data['headline']; } if (isset($data['name'])) { $candidateNames[] = $data['name']; } if (isset($data['author']['name'])) { $authors = $data['author']['name']; if (false === \is_array($authors)) { $authors = [$authors]; } foreach ($authors as $author) { $this->addAuthor($author); } } } if (\is_array($candidateNames) && \count($candidateNames) > 0) { foreach ($candidateNames as $name) { if (!\in_array($name, $ignoreNames, true)) { $this->title = $name; } } } }
php
private function extractJsonLdInformation($html) { preg_match_all('/<script type\=\"application\/ld\+json\"\>([\s\S]*?)<\/script>/i', $html, $matches); if (!isset($matches[1])) { return; } $ignoreNames = []; $candidateNames = []; foreach ($matches[1] as $matche) { $data = json_decode(trim($matche), true); if (isset($data['@type']) && \in_array($data['@type'], ['Organization', 'WebSite', 'Person'], true)) { if (isset($data['name'])) { $ignoreNames[] = $data['name']; } continue; } $this->logger->info('JSON-LD data: {JsonLdData}', ['JsonLdData' => $data]); // just in case datePublished isn't defined, we use the modified one at first if (isset($data['dateModified'])) { $this->date = $data['dateModified']; } if (isset($data['datePublished'])) { $this->date = $data['datePublished']; } // sometimes the date is an array if (\is_array($this->date)) { $this->date = reset($this->date); } // body should be a DOMNode if (isset($data['articlebody'])) { $dom = new \DOMDocument('1.0', 'utf-8'); $this->body = $dom->createElement('p', htmlspecialchars(trim($data['articlebody']))); } if (isset($data['headline'])) { $candidateNames[] = $data['headline']; } if (isset($data['name'])) { $candidateNames[] = $data['name']; } if (isset($data['author']['name'])) { $authors = $data['author']['name']; if (false === \is_array($authors)) { $authors = [$authors]; } foreach ($authors as $author) { $this->addAuthor($author); } } } if (\is_array($candidateNames) && \count($candidateNames) > 0) { foreach ($candidateNames as $name) { if (!\in_array($name, $ignoreNames, true)) { $this->title = $name; } } } }
[ "private", "function", "extractJsonLdInformation", "(", "$", "html", ")", "{", "preg_match_all", "(", "'/<script type\\=\\\"application\\/ld\\+json\\\"\\>([\\s\\S]*?)<\\/script>/i'", ",", "$", "html", ",", "$", "matches", ")", ";", "if", "(", "!", "isset", "(", "$", ...
Extract data from JSON-LD information. @param string $html Full page HTML @see https://json-ld.org/spec/latest/json-ld/
[ "Extract", "data", "from", "JSON", "-", "LD", "information", "." ]
6c1506f19d1bb876fb26bfc11e3e11a993eb7fe8
https://github.com/j0k3r/graby/blob/6c1506f19d1bb876fb26bfc11e3e11a993eb7fe8/src/Extractor/ContentExtractor.php#L1140-L1211
train
j0k3r/graby
src/Extractor/HttpClient.php
HttpClient.cleanupUrl
private function cleanupUrl($url) { // rewrite part of urls to something more readable foreach ($this->config['rewrite_url'] as $find => $action) { if (false !== strpos($url, $find) && \is_array($action)) { $url = strtr($url, $action); } } // convert fragment to actual query parameters if ($fragmentPos = strpos($url, '#!')) { $fragment = parse_url($url, PHP_URL_FRAGMENT); // strip '!' $fragment = substr($fragment, 1); $query = ['_escaped_fragment_' => $fragment]; // url without fragment $url = substr($url, 0, $fragmentPos); $url .= parse_url($url, PHP_URL_QUERY) ? '&' : '?'; // needed for some sites $url .= str_replace('%2F', '/', http_build_query($query)); } // remove fragment if ($pos = strpos($url, '#')) { $url = substr($url, 0, $pos); } return $url; }
php
private function cleanupUrl($url) { // rewrite part of urls to something more readable foreach ($this->config['rewrite_url'] as $find => $action) { if (false !== strpos($url, $find) && \is_array($action)) { $url = strtr($url, $action); } } // convert fragment to actual query parameters if ($fragmentPos = strpos($url, '#!')) { $fragment = parse_url($url, PHP_URL_FRAGMENT); // strip '!' $fragment = substr($fragment, 1); $query = ['_escaped_fragment_' => $fragment]; // url without fragment $url = substr($url, 0, $fragmentPos); $url .= parse_url($url, PHP_URL_QUERY) ? '&' : '?'; // needed for some sites $url .= str_replace('%2F', '/', http_build_query($query)); } // remove fragment if ($pos = strpos($url, '#')) { $url = substr($url, 0, $pos); } return $url; }
[ "private", "function", "cleanupUrl", "(", "$", "url", ")", "{", "// rewrite part of urls to something more readable", "foreach", "(", "$", "this", "->", "config", "[", "'rewrite_url'", "]", "as", "$", "find", "=>", "$", "action", ")", "{", "if", "(", "false", ...
Cleanup URL and retrieve the final url to be called. @param string $url @return string
[ "Cleanup", "URL", "and", "retrieve", "the", "final", "url", "to", "be", "called", "." ]
6c1506f19d1bb876fb26bfc11e3e11a993eb7fe8
https://github.com/j0k3r/graby/blob/6c1506f19d1bb876fb26bfc11e3e11a993eb7fe8/src/Extractor/HttpClient.php#L244-L273
train
j0k3r/graby
src/Extractor/HttpClient.php
HttpClient.checkNumberRedirects
private function checkNumberRedirects($url) { ++self::$nbRedirect; // keep initial url in case of endless redirect if ('' === self::$initialUrl) { self::$initialUrl = $url; } if (self::$nbRedirect > $this->config['max_redirect']) { $this->logger->warning('Endless redirect: ' . self::$nbRedirect . ' on "{url}"', ['url' => $url]); return false; } return true; }
php
private function checkNumberRedirects($url) { ++self::$nbRedirect; // keep initial url in case of endless redirect if ('' === self::$initialUrl) { self::$initialUrl = $url; } if (self::$nbRedirect > $this->config['max_redirect']) { $this->logger->warning('Endless redirect: ' . self::$nbRedirect . ' on "{url}"', ['url' => $url]); return false; } return true; }
[ "private", "function", "checkNumberRedirects", "(", "$", "url", ")", "{", "++", "self", "::", "$", "nbRedirect", ";", "// keep initial url in case of endless redirect", "if", "(", "''", "===", "self", "::", "$", "initialUrl", ")", "{", "self", "::", "$", "init...
Check if number of redirect count isn't reach. @param string $url @return bool true: it's ok, false: we need to stop
[ "Check", "if", "number", "of", "redirect", "count", "isn", "t", "reach", "." ]
6c1506f19d1bb876fb26bfc11e3e11a993eb7fe8
https://github.com/j0k3r/graby/blob/6c1506f19d1bb876fb26bfc11e3e11a993eb7fe8/src/Extractor/HttpClient.php#L282-L298
train
j0k3r/graby
src/Extractor/HttpClient.php
HttpClient.possibleUnsupportedType
private function possibleUnsupportedType($url) { $ext = strtolower(trim(pathinfo($url, PATHINFO_EXTENSION))); if (!$ext) { return false; } return \in_array($ext, $this->config['header_only_clues'], true); }
php
private function possibleUnsupportedType($url) { $ext = strtolower(trim(pathinfo($url, PATHINFO_EXTENSION))); if (!$ext) { return false; } return \in_array($ext, $this->config['header_only_clues'], true); }
[ "private", "function", "possibleUnsupportedType", "(", "$", "url", ")", "{", "$", "ext", "=", "strtolower", "(", "trim", "(", "pathinfo", "(", "$", "url", ",", "PATHINFO_EXTENSION", ")", ")", ")", ";", "if", "(", "!", "$", "ext", ")", "{", "return", ...
Try to determine if the url is a direct link to a binary resource by checking the extension. @param string $url Absolute url @return bool
[ "Try", "to", "determine", "if", "the", "url", "is", "a", "direct", "link", "to", "a", "binary", "resource", "by", "checking", "the", "extension", "." ]
6c1506f19d1bb876fb26bfc11e3e11a993eb7fe8
https://github.com/j0k3r/graby/blob/6c1506f19d1bb876fb26bfc11e3e11a993eb7fe8/src/Extractor/HttpClient.php#L323-L332
train
j0k3r/graby
src/Extractor/HttpClient.php
HttpClient.getUserAgent
private function getUserAgent($url, $httpHeader = []) { $ua = $this->config['ua_browser']; if (!empty($httpHeader['user-agent'])) { $this->logger->info('Found user-agent "{user-agent}" for url "{url}" from site config', ['user-agent' => $httpHeader['user-agent'], 'url' => $url]); return $httpHeader['user-agent']; } $host = parse_url($url, PHP_URL_HOST); if ('www.' === strtolower(substr($host, 0, 4))) { $host = substr($host, 4); } $try = [$host]; $split = explode('.', $host); if (\count($split) > 1) { // remove first subdomain array_shift($split); $try[] = '.' . implode('.', $split); } foreach ($try as $h) { if (isset($this->config['user_agents'][$h])) { $this->logger->info('Found user-agent "{user-agent}" for url "{url}" from config', ['user-agent' => $this->config['user_agents'][$h], 'url' => $url]); return $this->config['user_agents'][$h]; } } $this->logger->info('Use default user-agent "{user-agent}" for url "{url}"', ['user-agent' => $ua, 'url' => $url]); return $ua; }
php
private function getUserAgent($url, $httpHeader = []) { $ua = $this->config['ua_browser']; if (!empty($httpHeader['user-agent'])) { $this->logger->info('Found user-agent "{user-agent}" for url "{url}" from site config', ['user-agent' => $httpHeader['user-agent'], 'url' => $url]); return $httpHeader['user-agent']; } $host = parse_url($url, PHP_URL_HOST); if ('www.' === strtolower(substr($host, 0, 4))) { $host = substr($host, 4); } $try = [$host]; $split = explode('.', $host); if (\count($split) > 1) { // remove first subdomain array_shift($split); $try[] = '.' . implode('.', $split); } foreach ($try as $h) { if (isset($this->config['user_agents'][$h])) { $this->logger->info('Found user-agent "{user-agent}" for url "{url}" from config', ['user-agent' => $this->config['user_agents'][$h], 'url' => $url]); return $this->config['user_agents'][$h]; } } $this->logger->info('Use default user-agent "{user-agent}" for url "{url}"', ['user-agent' => $ua, 'url' => $url]); return $ua; }
[ "private", "function", "getUserAgent", "(", "$", "url", ",", "$", "httpHeader", "=", "[", "]", ")", "{", "$", "ua", "=", "$", "this", "->", "config", "[", "'ua_browser'", "]", ";", "if", "(", "!", "empty", "(", "$", "httpHeader", "[", "'user-agent'",...
Find a UserAgent for this url. Based on the config, it will try to find a UserAgent from an host. Otherwise it will use the default one. @param string $url Absolute url @param array $httpHeader Custom HTTP Headers from SiteConfig @return string
[ "Find", "a", "UserAgent", "for", "this", "url", ".", "Based", "on", "the", "config", "it", "will", "try", "to", "find", "a", "UserAgent", "from", "an", "host", ".", "Otherwise", "it", "will", "use", "the", "default", "one", "." ]
6c1506f19d1bb876fb26bfc11e3e11a993eb7fe8
https://github.com/j0k3r/graby/blob/6c1506f19d1bb876fb26bfc11e3e11a993eb7fe8/src/Extractor/HttpClient.php#L344-L380
train
j0k3r/graby
src/Extractor/HttpClient.php
HttpClient.getReferer
private function getReferer($url, $httpHeader = []) { $default_referer = $this->config['default_referer']; if (!empty($httpHeader['referer'])) { $this->logger->info('Found referer "{referer}" for url "{url}" from site config', ['referer' => $httpHeader['referer'], 'url' => $url]); return $httpHeader['referer']; } $this->logger->info('Use default referer "{referer}" for url "{url}"', ['referer' => $default_referer, 'url' => $url]); return $default_referer; }
php
private function getReferer($url, $httpHeader = []) { $default_referer = $this->config['default_referer']; if (!empty($httpHeader['referer'])) { $this->logger->info('Found referer "{referer}" for url "{url}" from site config', ['referer' => $httpHeader['referer'], 'url' => $url]); return $httpHeader['referer']; } $this->logger->info('Use default referer "{referer}" for url "{url}"', ['referer' => $default_referer, 'url' => $url]); return $default_referer; }
[ "private", "function", "getReferer", "(", "$", "url", ",", "$", "httpHeader", "=", "[", "]", ")", "{", "$", "default_referer", "=", "$", "this", "->", "config", "[", "'default_referer'", "]", ";", "if", "(", "!", "empty", "(", "$", "httpHeader", "[", ...
Find a Referer for this url. Based on the site config, it will return the Referer if any. Otherwise it will use the default one. @param string $url Absolute url @param array $httpHeader Custom HTTP Headers from SiteConfig @return string
[ "Find", "a", "Referer", "for", "this", "url", ".", "Based", "on", "the", "site", "config", "it", "will", "return", "the", "Referer", "if", "any", ".", "Otherwise", "it", "will", "use", "the", "default", "one", "." ]
6c1506f19d1bb876fb26bfc11e3e11a993eb7fe8
https://github.com/j0k3r/graby/blob/6c1506f19d1bb876fb26bfc11e3e11a993eb7fe8/src/Extractor/HttpClient.php#L392-L405
train
j0k3r/graby
src/Extractor/HttpClient.php
HttpClient.getCookie
private function getCookie($url, $httpHeader = []) { if (!empty($httpHeader['cookie'])) { $this->logger->info('Found cookie "{cookie}" for url "{url}" from site config', ['cookie' => $httpHeader['cookie'], 'url' => $url]); $cookies = []; $pieces = array_filter(array_map('trim', explode(';', $httpHeader['cookie']))); foreach ($pieces as $part) { $cookieParts = explode('=', $part, 2); $key = trim($cookieParts[0]); if (1 === \count($cookieParts)) { // Can be a single value (e.g. secure, httpOnly) $value = true; } else { // Be sure to strip wrapping quotes $value = trim($cookieParts[1], " \n\r\t\0\x0B\""); } $cookies[$key] = $value; } return $cookies; } return false; }
php
private function getCookie($url, $httpHeader = []) { if (!empty($httpHeader['cookie'])) { $this->logger->info('Found cookie "{cookie}" for url "{url}" from site config', ['cookie' => $httpHeader['cookie'], 'url' => $url]); $cookies = []; $pieces = array_filter(array_map('trim', explode(';', $httpHeader['cookie']))); foreach ($pieces as $part) { $cookieParts = explode('=', $part, 2); $key = trim($cookieParts[0]); if (1 === \count($cookieParts)) { // Can be a single value (e.g. secure, httpOnly) $value = true; } else { // Be sure to strip wrapping quotes $value = trim($cookieParts[1], " \n\r\t\0\x0B\""); } $cookies[$key] = $value; } return $cookies; } return false; }
[ "private", "function", "getCookie", "(", "$", "url", ",", "$", "httpHeader", "=", "[", "]", ")", "{", "if", "(", "!", "empty", "(", "$", "httpHeader", "[", "'cookie'", "]", ")", ")", "{", "$", "this", "->", "logger", "->", "info", "(", "'Found cook...
Find a cookie for this url. Based on the site config, it will return the cookie if any. @param string $url Absolute url @param array $httpHeader Custom HTTP Headers from SiteConfig @return array|false
[ "Find", "a", "cookie", "for", "this", "url", ".", "Based", "on", "the", "site", "config", "it", "will", "return", "the", "cookie", "if", "any", "." ]
6c1506f19d1bb876fb26bfc11e3e11a993eb7fe8
https://github.com/j0k3r/graby/blob/6c1506f19d1bb876fb26bfc11e3e11a993eb7fe8/src/Extractor/HttpClient.php#L416-L443
train
j0k3r/graby
src/Extractor/HttpClient.php
HttpClient.getAccept
private function getAccept($url, $httpHeader = []) { if (!empty($httpHeader['accept'])) { $this->logger->info('Found accept header "{accept}" for url "{url}" from site config', ['accept' => $httpHeader['accept'], 'url' => $url]); return $httpHeader['accept']; } return false; }
php
private function getAccept($url, $httpHeader = []) { if (!empty($httpHeader['accept'])) { $this->logger->info('Found accept header "{accept}" for url "{url}" from site config', ['accept' => $httpHeader['accept'], 'url' => $url]); return $httpHeader['accept']; } return false; }
[ "private", "function", "getAccept", "(", "$", "url", ",", "$", "httpHeader", "=", "[", "]", ")", "{", "if", "(", "!", "empty", "(", "$", "httpHeader", "[", "'accept'", "]", ")", ")", "{", "$", "this", "->", "logger", "->", "info", "(", "'Found acce...
Find an accept header for this url. Based on the site config, it will return the accept if any. Otherwise it will return false. @param string $url Absolute url @param array $httpHeader Custom HTTP Headers from SiteConfig @return string|false
[ "Find", "an", "accept", "header", "for", "this", "url", ".", "Based", "on", "the", "site", "config", "it", "will", "return", "the", "accept", "if", "any", ".", "Otherwise", "it", "will", "return", "false", "." ]
6c1506f19d1bb876fb26bfc11e3e11a993eb7fe8
https://github.com/j0k3r/graby/blob/6c1506f19d1bb876fb26bfc11e3e11a993eb7fe8/src/Extractor/HttpClient.php#L455-L464
train
j0k3r/graby
src/Extractor/HttpClient.php
HttpClient.getMetaRefreshURL
private function getMetaRefreshURL($url, $html) { if ('' === $html) { return false; } // <meta HTTP-EQUIV="REFRESH" content="0; url=http://www.bernama.com/bernama/v6/newsindex.php?id=943513"> if (!preg_match('!<meta http-equiv=["\']?refresh["\']? content=["\']?[0-9];\s*url=["\']?([^"\'>]+)["\']?!i', $html, $match)) { return false; } $redirectUrl = str_replace('&amp;', '&', trim($match[1])); if (preg_match('!^https?://!i', $redirectUrl)) { // already absolute $this->logger->info('Meta refresh redirect found (http-equiv="refresh"), new URL: ' . $redirectUrl); return $redirectUrl; } // absolutize redirect URL $base = new \SimplePie_IRI($url); // remove '//' in URL path (causes URLs not to resolve properly) if (isset($base->ipath)) { $base->ipath = str_replace('//', '/', $base->ipath); } if ($absolute = \SimplePie_IRI::absolutize($base, $redirectUrl)) { $this->logger->info('Meta refresh redirect found (http-equiv="refresh"), new URL: ' . $absolute); return $absolute->get_iri(); } return false; }
php
private function getMetaRefreshURL($url, $html) { if ('' === $html) { return false; } // <meta HTTP-EQUIV="REFRESH" content="0; url=http://www.bernama.com/bernama/v6/newsindex.php?id=943513"> if (!preg_match('!<meta http-equiv=["\']?refresh["\']? content=["\']?[0-9];\s*url=["\']?([^"\'>]+)["\']?!i', $html, $match)) { return false; } $redirectUrl = str_replace('&amp;', '&', trim($match[1])); if (preg_match('!^https?://!i', $redirectUrl)) { // already absolute $this->logger->info('Meta refresh redirect found (http-equiv="refresh"), new URL: ' . $redirectUrl); return $redirectUrl; } // absolutize redirect URL $base = new \SimplePie_IRI($url); // remove '//' in URL path (causes URLs not to resolve properly) if (isset($base->ipath)) { $base->ipath = str_replace('//', '/', $base->ipath); } if ($absolute = \SimplePie_IRI::absolutize($base, $redirectUrl)) { $this->logger->info('Meta refresh redirect found (http-equiv="refresh"), new URL: ' . $absolute); return $absolute->get_iri(); } return false; }
[ "private", "function", "getMetaRefreshURL", "(", "$", "url", ",", "$", "html", ")", "{", "if", "(", "''", "===", "$", "html", ")", "{", "return", "false", ";", "}", "// <meta HTTP-EQUIV=\"REFRESH\" content=\"0; url=http://www.bernama.com/bernama/v6/newsindex.php?id=9435...
Try to find the refresh url from the meta. @param string $url Absolute url @param string $html First characters of the response (hopefully it'll be enough to find some meta) @return false|string
[ "Try", "to", "find", "the", "refresh", "url", "from", "the", "meta", "." ]
6c1506f19d1bb876fb26bfc11e3e11a993eb7fe8
https://github.com/j0k3r/graby/blob/6c1506f19d1bb876fb26bfc11e3e11a993eb7fe8/src/Extractor/HttpClient.php#L502-L535
train
j0k3r/graby
src/Extractor/HttpClient.php
HttpClient.formatHeaders
private function formatHeaders($response) { $headers = []; foreach ($response->getHeaders() as $name => $value) { $headers[strtolower($name)] = \is_array($value) ? implode(', ', $value) : $value; } return $headers; }
php
private function formatHeaders($response) { $headers = []; foreach ($response->getHeaders() as $name => $value) { $headers[strtolower($name)] = \is_array($value) ? implode(', ', $value) : $value; } return $headers; }
[ "private", "function", "formatHeaders", "(", "$", "response", ")", "{", "$", "headers", "=", "[", "]", ";", "foreach", "(", "$", "response", "->", "getHeaders", "(", ")", "as", "$", "name", "=>", "$", "value", ")", "{", "$", "headers", "[", "strtolow...
Format all headers to avoid unecessary array level. Also lower the header name. @param Response $response @return array
[ "Format", "all", "headers", "to", "avoid", "unecessary", "array", "level", ".", "Also", "lower", "the", "header", "name", "." ]
6c1506f19d1bb876fb26bfc11e3e11a993eb7fe8
https://github.com/j0k3r/graby/blob/6c1506f19d1bb876fb26bfc11e3e11a993eb7fe8/src/Extractor/HttpClient.php#L582-L590
train
pods-framework/pods
classes/PodsRESTFields.php
PodsRESTFields.set_pod
private function set_pod( $pod ) { if ( is_string( $pod ) ) { $pod = pods( $pod, null, true ); $this->set_pod( $pod ); } else { $type = $pod->pod_data['type']; $supported_pod_types = array( 'post_type', 'taxonomy', 'media', 'user', 'comment', ); if ( in_array( $type, $supported_pod_types, true ) ) { $this->pod = $pod; } else { $this->pod = false; } }//end if }
php
private function set_pod( $pod ) { if ( is_string( $pod ) ) { $pod = pods( $pod, null, true ); $this->set_pod( $pod ); } else { $type = $pod->pod_data['type']; $supported_pod_types = array( 'post_type', 'taxonomy', 'media', 'user', 'comment', ); if ( in_array( $type, $supported_pod_types, true ) ) { $this->pod = $pod; } else { $this->pod = false; } }//end if }
[ "private", "function", "set_pod", "(", "$", "pod", ")", "{", "if", "(", "is_string", "(", "$", "pod", ")", ")", "{", "$", "pod", "=", "pods", "(", "$", "pod", ",", "null", ",", "true", ")", ";", "$", "this", "->", "set_pod", "(", "$", "pod", ...
Set the Pods object @since 2.5.6 @access protected @param string|Pods $pod Pods object or name of Pods object
[ "Set", "the", "Pods", "object" ]
fd9a07c5c81ccbfcb21c5a0b2166f96c31d0826c
https://github.com/pods-framework/pods/blob/fd9a07c5c81ccbfcb21c5a0b2166f96c31d0826c/classes/PodsRESTFields.php#L54-L78
train
pods-framework/pods
classes/PodsRESTFields.php
PodsRESTFields.field_allowed_to_extend
public static function field_allowed_to_extend( $field_name, $pod, $mode = 'read' ) { $allowed = false; if ( is_object( $pod ) ) { $field = $pod->fields( $field_name ); if ( $field ) { $pod_options = $pod->pod_data['options']; $read_all = (int) pods_v( 'read_all', $pod_options, 0 ); $write_all = (int) pods_v( 'write_all', $pod_options, 0 ); if ( 'read' === $mode && 1 === $read_all ) { $allowed = true; } elseif ( 'write' === $mode && 1 === $write_all ) { $allowed = true; } else { $rest_read = (int) $pod->fields( $field_name, 'rest_read' ); $rest_write = (int) $pod->fields( $field_name, 'rest_write' ); if ( 'read' === $mode && 1 === $rest_read ) { $allowed = true; } elseif ( 'write' === $mode && 1 === $rest_write ) { $allowed = true; } } }//end if }//end if return $allowed; }
php
public static function field_allowed_to_extend( $field_name, $pod, $mode = 'read' ) { $allowed = false; if ( is_object( $pod ) ) { $field = $pod->fields( $field_name ); if ( $field ) { $pod_options = $pod->pod_data['options']; $read_all = (int) pods_v( 'read_all', $pod_options, 0 ); $write_all = (int) pods_v( 'write_all', $pod_options, 0 ); if ( 'read' === $mode && 1 === $read_all ) { $allowed = true; } elseif ( 'write' === $mode && 1 === $write_all ) { $allowed = true; } else { $rest_read = (int) $pod->fields( $field_name, 'rest_read' ); $rest_write = (int) $pod->fields( $field_name, 'rest_write' ); if ( 'read' === $mode && 1 === $rest_read ) { $allowed = true; } elseif ( 'write' === $mode && 1 === $rest_write ) { $allowed = true; } } }//end if }//end if return $allowed; }
[ "public", "static", "function", "field_allowed_to_extend", "(", "$", "field_name", ",", "$", "pod", ",", "$", "mode", "=", "'read'", ")", "{", "$", "allowed", "=", "false", ";", "if", "(", "is_object", "(", "$", "pod", ")", ")", "{", "$", "field", "=...
Check if a field supports read or write via the REST API. @since 2.5.6 @param string $field_name The field name. @param Pods $pod Pods object. @param string $mode Are we checking read or write? @return bool If supports, true, else false.
[ "Check", "if", "a", "field", "supports", "read", "or", "write", "via", "the", "REST", "API", "." ]
fd9a07c5c81ccbfcb21c5a0b2166f96c31d0826c
https://github.com/pods-framework/pods/blob/fd9a07c5c81ccbfcb21c5a0b2166f96c31d0826c/classes/PodsRESTFields.php#L160-L192
train
pods-framework/pods
components/I18n/I18n.php
Pods_Component_I18n.admin_assets
public function admin_assets() { wp_enqueue_script( 'pods-admin-i18n', PODS_URL . 'components/I18n/pods-admin-i18n.js', array( 'jquery', 'pods-i18n', ), '1.0', true ); $localize_script = array(); if ( ! empty( $this->languages ) ) { foreach ( $this->languages as $lang => $lang_data ) { $lang_label = $this->create_lang_label( $lang_data ); if ( ! empty( $lang_label ) ) { $lang_label = $lang . ' (' . $lang_label . ')'; } else { $lang_label = $lang; } $localize_script[ $lang ] = $lang_label; } } wp_localize_script( 'pods-admin-i18n', 'pods_admin_i18n_strings', $localize_script ); // Add strings to the i18n js object add_filter( 'pods_localized_strings', array( $this, 'localize_assets' ) ); }
php
public function admin_assets() { wp_enqueue_script( 'pods-admin-i18n', PODS_URL . 'components/I18n/pods-admin-i18n.js', array( 'jquery', 'pods-i18n', ), '1.0', true ); $localize_script = array(); if ( ! empty( $this->languages ) ) { foreach ( $this->languages as $lang => $lang_data ) { $lang_label = $this->create_lang_label( $lang_data ); if ( ! empty( $lang_label ) ) { $lang_label = $lang . ' (' . $lang_label . ')'; } else { $lang_label = $lang; } $localize_script[ $lang ] = $lang_label; } } wp_localize_script( 'pods-admin-i18n', 'pods_admin_i18n_strings', $localize_script ); // Add strings to the i18n js object add_filter( 'pods_localized_strings', array( $this, 'localize_assets' ) ); }
[ "public", "function", "admin_assets", "(", ")", "{", "wp_enqueue_script", "(", "'pods-admin-i18n'", ",", "PODS_URL", ".", "'components/I18n/pods-admin-i18n.js'", ",", "array", "(", "'jquery'", ",", "'pods-i18n'", ",", ")", ",", "'1.0'", ",", "true", ")", ";", "$...
Load assets for this component @since 0.1.0
[ "Load", "assets", "for", "this", "component" ]
fd9a07c5c81ccbfcb21c5a0b2166f96c31d0826c
https://github.com/pods-framework/pods/blob/fd9a07c5c81ccbfcb21c5a0b2166f96c31d0826c/components/I18n/I18n.php#L175-L203
train
pods-framework/pods
components/I18n/I18n.php
Pods_Component_I18n.localize_assets
public function localize_assets( $str ) { $str['Add translation'] = __( 'Add translation', 'pods' ); $str['Toggle translations'] = __( 'Toggle translations', 'pods' ); $str['Show translations'] = __( 'Show translations', 'pods' ); $str['Hide translations'] = __( 'Hide translations', 'pods' ); $str['Select'] = __( 'Select', 'pods' ); return $str; }
php
public function localize_assets( $str ) { $str['Add translation'] = __( 'Add translation', 'pods' ); $str['Toggle translations'] = __( 'Toggle translations', 'pods' ); $str['Show translations'] = __( 'Show translations', 'pods' ); $str['Hide translations'] = __( 'Hide translations', 'pods' ); $str['Select'] = __( 'Select', 'pods' ); return $str; }
[ "public", "function", "localize_assets", "(", "$", "str", ")", "{", "$", "str", "[", "'Add translation'", "]", "=", "__", "(", "'Add translation'", ",", "'pods'", ")", ";", "$", "str", "[", "'Toggle translations'", "]", "=", "__", "(", "'Toggle translations'...
Localize the assets @param array $str Existing strings @return array
[ "Localize", "the", "assets" ]
fd9a07c5c81ccbfcb21c5a0b2166f96c31d0826c
https://github.com/pods-framework/pods/blob/fd9a07c5c81ccbfcb21c5a0b2166f96c31d0826c/components/I18n/I18n.php#L212-L221
train
pods-framework/pods
components/I18n/I18n.php
Pods_Component_I18n.is_translatable_field
public function is_translatable_field( $name ) { $translatable_fields = $this->get_translatable_fields(); // All fields that start with "label" if ( strpos( $name, 'label' ) === 0 ) { return true; } // All translatable fields if ( in_array( $name, $translatable_fields, true ) ) { return true; } // Custom fields data, the name must begin with field_data[ if ( strpos( $name, 'field_data[' ) === 0 ) { $name = str_replace( 'field_data[', '', $name ); $name = rtrim( $name, ']' ); $name = explode( '][', $name ); $name = end( $name ); // All translatable fields from field_data[ (int) ][ $name ] if ( in_array( $name, $translatable_fields, true ) ) { return true; } } return false; }
php
public function is_translatable_field( $name ) { $translatable_fields = $this->get_translatable_fields(); // All fields that start with "label" if ( strpos( $name, 'label' ) === 0 ) { return true; } // All translatable fields if ( in_array( $name, $translatable_fields, true ) ) { return true; } // Custom fields data, the name must begin with field_data[ if ( strpos( $name, 'field_data[' ) === 0 ) { $name = str_replace( 'field_data[', '', $name ); $name = rtrim( $name, ']' ); $name = explode( '][', $name ); $name = end( $name ); // All translatable fields from field_data[ (int) ][ $name ] if ( in_array( $name, $translatable_fields, true ) ) { return true; } } return false; }
[ "public", "function", "is_translatable_field", "(", "$", "name", ")", "{", "$", "translatable_fields", "=", "$", "this", "->", "get_translatable_fields", "(", ")", ";", "// All fields that start with \"label\"", "if", "(", "strpos", "(", "$", "name", ",", "'label'...
Check is a field name is set for translation @since 0.1.0 @param string $name @return bool
[ "Check", "is", "a", "field", "name", "is", "set", "for", "translation" ]
fd9a07c5c81ccbfcb21c5a0b2166f96c31d0826c
https://github.com/pods-framework/pods/blob/fd9a07c5c81ccbfcb21c5a0b2166f96c31d0826c/components/I18n/I18n.php#L232-L257
train
pods-framework/pods
components/I18n/I18n.php
Pods_Component_I18n.fields_ui_label_text_i18n
public function fields_ui_label_text_i18n( $label, $name, $help, $options ) { return (string) $this->get_value_translation( $label, 'label', $options ); }
php
public function fields_ui_label_text_i18n( $label, $name, $help, $options ) { return (string) $this->get_value_translation( $label, 'label', $options ); }
[ "public", "function", "fields_ui_label_text_i18n", "(", "$", "label", ",", "$", "name", ",", "$", "help", ",", "$", "options", ")", "{", "return", "(", "string", ")", "$", "this", "->", "get_value_translation", "(", "$", "label", ",", "'label'", ",", "$"...
Returns the translated label if available @since 0.1.0 @see PodsForm.php >> 'pods_form_ui_label_text' (filter) @param string $label The default label @param string $name The field name @param string $help The help text @param array $options The field options @return string
[ "Returns", "the", "translated", "label", "if", "available" ]
fd9a07c5c81ccbfcb21c5a0b2166f96c31d0826c
https://github.com/pods-framework/pods/blob/fd9a07c5c81ccbfcb21c5a0b2166f96c31d0826c/components/I18n/I18n.php#L334-L337
train
pods-framework/pods
components/I18n/I18n.php
Pods_Component_I18n.field_pick_data_i18n
public function field_pick_data_i18n( $data, $name, $value, $options, $pod, $id ) { if ( isset( $data[''] ) && isset( $options['pick_select_text'] ) ) { $locale = $this->locale; if ( isset( $options[ 'pick_select_text_' . $locale ] ) && array_key_exists( $locale, $this->languages ) && $this->obj_is_language_enabled( $locale, $pod ) ) { $data[''] = $options[ 'pick_select_text_' . $locale ]; } } return $data; }
php
public function field_pick_data_i18n( $data, $name, $value, $options, $pod, $id ) { if ( isset( $data[''] ) && isset( $options['pick_select_text'] ) ) { $locale = $this->locale; if ( isset( $options[ 'pick_select_text_' . $locale ] ) && array_key_exists( $locale, $this->languages ) && $this->obj_is_language_enabled( $locale, $pod ) ) { $data[''] = $options[ 'pick_select_text_' . $locale ]; } } return $data; }
[ "public", "function", "field_pick_data_i18n", "(", "$", "data", ",", "$", "name", ",", "$", "value", ",", "$", "options", ",", "$", "pod", ",", "$", "id", ")", "{", "if", "(", "isset", "(", "$", "data", "[", "''", "]", ")", "&&", "isset", "(", ...
Replaces the default selected text with a translation if available @since 0.1.0 @see pick.php >> 'pods_field_pick_data' (filter) @param array $data The default data of the field @param string $name The field name @param string $value The field value @param array $options The field options @param array $pod The Pod @param int $id The field ID @return array
[ "Replaces", "the", "default", "selected", "text", "with", "a", "translation", "if", "available" ]
fd9a07c5c81ccbfcb21c5a0b2166f96c31d0826c
https://github.com/pods-framework/pods/blob/fd9a07c5c81ccbfcb21c5a0b2166f96c31d0826c/components/I18n/I18n.php#L371-L381
train
pods-framework/pods
components/I18n/I18n.php
Pods_Component_I18n.form_ui_field_options_i18n
public function form_ui_field_options_i18n( $options, $name, $value, $pod, $id ) { foreach ( $this->get_translatable_fields() as $field ) { $locale = $this->locale; if ( isset( $options[ $field . '_' . $locale ] ) && array_key_exists( $locale, $this->languages ) && $this->obj_is_language_enabled( $locale, $pod ) ) { $options[ $field ] = $options[ $field . '_' . $locale ]; } } return $options; }
php
public function form_ui_field_options_i18n( $options, $name, $value, $pod, $id ) { foreach ( $this->get_translatable_fields() as $field ) { $locale = $this->locale; if ( isset( $options[ $field . '_' . $locale ] ) && array_key_exists( $locale, $this->languages ) && $this->obj_is_language_enabled( $locale, $pod ) ) { $options[ $field ] = $options[ $field . '_' . $locale ]; } } return $options; }
[ "public", "function", "form_ui_field_options_i18n", "(", "$", "options", ",", "$", "name", ",", "$", "value", ",", "$", "pod", ",", "$", "id", ")", "{", "foreach", "(", "$", "this", "->", "get_translatable_fields", "(", ")", "as", "$", "field", ")", "{...
Replaces the default values with a translation if available @since 0.1.0 @see PodsForm.php >> 'pods_form_ui_field_' . $type . '_options' (filter) @param array $options The field options @param string $name The field name @param string $value The field value @param array $pod The Pod @param int $id The field ID @return array
[ "Replaces", "the", "default", "values", "with", "a", "translation", "if", "available" ]
fd9a07c5c81ccbfcb21c5a0b2166f96c31d0826c
https://github.com/pods-framework/pods/blob/fd9a07c5c81ccbfcb21c5a0b2166f96c31d0826c/components/I18n/I18n.php#L397-L407
train
pods-framework/pods
components/I18n/I18n.php
Pods_Component_I18n.admin_save
public function admin_save() { $this->languages_available = get_available_languages(); /** * format: array( language, version, updated, english_name, native_name, package, iso, strings ) */ require_once ABSPATH . 'wp-admin/includes/translation-install.php'; $this->languages_translated = wp_get_available_translations(); $new_languages = array(); if ( isset( $_POST['pods_i18n_enabled_languages'] ) && is_array( $_POST['pods_i18n_enabled_languages'] ) ) { foreach ( $_POST['pods_i18n_enabled_languages'] as $locale ) { $locale = sanitize_text_field( $locale ); if ( in_array( $locale, $this->languages_available, true ) ) { $new_languages[ $locale ] = array(); if ( isset( $this->languages_translated[ $locale ]['language'] ) ) { $new_languages[ $locale ]['language'] = $this->languages_translated[ $locale ]['language']; } if ( isset( $this->languages_translated[ $locale ]['english_name'] ) ) { $new_languages[ $locale ]['english_name'] = $this->languages_translated[ $locale ]['english_name']; } if ( isset( $this->languages_translated[ $locale ]['native_name'] ) ) { $new_languages[ $locale ]['native_name'] = $this->languages_translated[ $locale ]['native_name']; } } } }//end if $this->languages = $new_languages; $this->settings['enabled_languages'] = $new_languages; update_option( $this->option_key, $this->settings ); }
php
public function admin_save() { $this->languages_available = get_available_languages(); /** * format: array( language, version, updated, english_name, native_name, package, iso, strings ) */ require_once ABSPATH . 'wp-admin/includes/translation-install.php'; $this->languages_translated = wp_get_available_translations(); $new_languages = array(); if ( isset( $_POST['pods_i18n_enabled_languages'] ) && is_array( $_POST['pods_i18n_enabled_languages'] ) ) { foreach ( $_POST['pods_i18n_enabled_languages'] as $locale ) { $locale = sanitize_text_field( $locale ); if ( in_array( $locale, $this->languages_available, true ) ) { $new_languages[ $locale ] = array(); if ( isset( $this->languages_translated[ $locale ]['language'] ) ) { $new_languages[ $locale ]['language'] = $this->languages_translated[ $locale ]['language']; } if ( isset( $this->languages_translated[ $locale ]['english_name'] ) ) { $new_languages[ $locale ]['english_name'] = $this->languages_translated[ $locale ]['english_name']; } if ( isset( $this->languages_translated[ $locale ]['native_name'] ) ) { $new_languages[ $locale ]['native_name'] = $this->languages_translated[ $locale ]['native_name']; } } } }//end if $this->languages = $new_languages; $this->settings['enabled_languages'] = $new_languages; update_option( $this->option_key, $this->settings ); }
[ "public", "function", "admin_save", "(", ")", "{", "$", "this", "->", "languages_available", "=", "get_available_languages", "(", ")", ";", "/**\n\t\t * format: array( language, version, updated, english_name, native_name, package, iso, strings )\n\t\t */", "require_once", "ABSPATH...
Save component settings @since 0.1.0
[ "Save", "component", "settings" ]
fd9a07c5c81ccbfcb21c5a0b2166f96c31d0826c
https://github.com/pods-framework/pods/blob/fd9a07c5c81ccbfcb21c5a0b2166f96c31d0826c/components/I18n/I18n.php#L549-L588
train
pods-framework/pods
components/I18n/I18n.php
Pods_Component_I18n.meta_box
public function meta_box() { $pod = $this->cur_pod; if ( ! empty( $this->languages ) ) { ?> <p><?php esc_html_e( 'Enable/Disable languages for this Pod', 'pods' ); ?></p> <p> <small class="description"><?php esc_html_e( 'This overwrites the defaults set in the component admin.', 'pods' ); ?></small> </p> <div class="pods-field-enable-disable-language"> <?php foreach ( $this->languages as $locale => $lang_data ) { if ( ! isset( $pod['options']['enable_i18n'][ $locale ] ) ) { // Enabled by default $pod['options']['enable_i18n'][ $locale ] = 1; } ?> <div class="pods-field-option pods-enable-disable-language" data-locale="<?php echo esc_attr( $locale ); ?>"> <?php echo PodsForm::field( 'enable_i18n[' . $locale . ']', $pod['options']['enable_i18n'][ $locale ], 'boolean', array( 'boolean_yes_label' => '<code>' . $locale . '</code> ' . $this->create_lang_label( $lang_data ), 'boolean_no_label' => '', ) ); ?> </div> <?php } ?> </div> <hr> <p> <button id="toggle_i18n" class="button-secondary"><?php esc_html_e( 'Toggle translation visibility', 'pods' ); ?></button> </p> <?php }//end if }
php
public function meta_box() { $pod = $this->cur_pod; if ( ! empty( $this->languages ) ) { ?> <p><?php esc_html_e( 'Enable/Disable languages for this Pod', 'pods' ); ?></p> <p> <small class="description"><?php esc_html_e( 'This overwrites the defaults set in the component admin.', 'pods' ); ?></small> </p> <div class="pods-field-enable-disable-language"> <?php foreach ( $this->languages as $locale => $lang_data ) { if ( ! isset( $pod['options']['enable_i18n'][ $locale ] ) ) { // Enabled by default $pod['options']['enable_i18n'][ $locale ] = 1; } ?> <div class="pods-field-option pods-enable-disable-language" data-locale="<?php echo esc_attr( $locale ); ?>"> <?php echo PodsForm::field( 'enable_i18n[' . $locale . ']', $pod['options']['enable_i18n'][ $locale ], 'boolean', array( 'boolean_yes_label' => '<code>' . $locale . '</code> ' . $this->create_lang_label( $lang_data ), 'boolean_no_label' => '', ) ); ?> </div> <?php } ?> </div> <hr> <p> <button id="toggle_i18n" class="button-secondary"><?php esc_html_e( 'Toggle translation visibility', 'pods' ); ?></button> </p> <?php }//end if }
[ "public", "function", "meta_box", "(", ")", "{", "$", "pod", "=", "$", "this", "->", "cur_pod", ";", "if", "(", "!", "empty", "(", "$", "this", "->", "languages", ")", ")", "{", "?>\n\t\t\t<p><?php", "esc_html_e", "(", "'Enable/Disable languages for this Pod...
The i18n metabox. @todo Store enabled languages serialized instead of separate inputs @since 0.1.0
[ "The", "i18n", "metabox", "." ]
fd9a07c5c81ccbfcb21c5a0b2166f96c31d0826c
https://github.com/pods-framework/pods/blob/fd9a07c5c81ccbfcb21c5a0b2166f96c31d0826c/components/I18n/I18n.php#L808-L850
train
pods-framework/pods
components/I18n/I18n.php
Pods_Component_I18n.add_i18n_inputs
public function add_i18n_inputs( $output, $name, $value, $options, $pod, $id ) { if ( ! empty( $pod ) || empty( $name ) || ! $this->is_translatable_field( $name ) ) { return $output; } $pod = $this->cur_pod; // print_r( $pod ); if ( empty( $pod ) ) { // Setting the $pod var to a non-empty value is mandatory to prevent a loop $pod = true; } $output .= '<br clear="both" />'; $output .= '<div class="pods-i18n-field">'; foreach ( $this->languages as $locale => $lang_data ) { if ( ! $this->obj_is_language_enabled( $locale, (array) $pod ) ) { continue; } // Our own shiny label with language information $lang_code = '<code style="font-size: 1em;">' . $locale . '</code>'; /* $lang_label = $this->create_lang_label( $lang_data ); if ( ! empty( $lang_label ) ) { $lang_label = $lang_code . ' ('. $lang_label .')'; } else {*/ $lang_label = $lang_code; // } $lang_label = '<small>' . $lang_label . '</small>'; $style = ''; // Add language data to name for normal strings and array formatted strings if ( strpos( $name, ']' ) !== false ) { // Hide the i18n options for fields by default if they are empty $field_value = pods_v( $name, $pod ); if ( strpos( $name, 'field_data' ) !== false && empty( $field_value ) ) { $style = ' style="display: none;"'; } $field_name = rtrim( $name, ']' ); $field_name .= '_' . $locale . ']'; } else { $field_name = $name . '_' . $locale; } // Add the translation fields $output .= '<div class="pods-i18n-input pods-i18n-input-' . $locale . '" data-locale="' . $locale . '" ' . $style . '>'; $output .= PodsForm::label( $field_name, $lang_label ); $output .= PodsForm::field( $field_name, pods_v( $field_name, $pod ), 'text', null, $pod ); $output .= '</div>'; }//end foreach $output .= '</div>'; return $output; }
php
public function add_i18n_inputs( $output, $name, $value, $options, $pod, $id ) { if ( ! empty( $pod ) || empty( $name ) || ! $this->is_translatable_field( $name ) ) { return $output; } $pod = $this->cur_pod; // print_r( $pod ); if ( empty( $pod ) ) { // Setting the $pod var to a non-empty value is mandatory to prevent a loop $pod = true; } $output .= '<br clear="both" />'; $output .= '<div class="pods-i18n-field">'; foreach ( $this->languages as $locale => $lang_data ) { if ( ! $this->obj_is_language_enabled( $locale, (array) $pod ) ) { continue; } // Our own shiny label with language information $lang_code = '<code style="font-size: 1em;">' . $locale . '</code>'; /* $lang_label = $this->create_lang_label( $lang_data ); if ( ! empty( $lang_label ) ) { $lang_label = $lang_code . ' ('. $lang_label .')'; } else {*/ $lang_label = $lang_code; // } $lang_label = '<small>' . $lang_label . '</small>'; $style = ''; // Add language data to name for normal strings and array formatted strings if ( strpos( $name, ']' ) !== false ) { // Hide the i18n options for fields by default if they are empty $field_value = pods_v( $name, $pod ); if ( strpos( $name, 'field_data' ) !== false && empty( $field_value ) ) { $style = ' style="display: none;"'; } $field_name = rtrim( $name, ']' ); $field_name .= '_' . $locale . ']'; } else { $field_name = $name . '_' . $locale; } // Add the translation fields $output .= '<div class="pods-i18n-input pods-i18n-input-' . $locale . '" data-locale="' . $locale . '" ' . $style . '>'; $output .= PodsForm::label( $field_name, $lang_label ); $output .= PodsForm::field( $field_name, pods_v( $field_name, $pod ), 'text', null, $pod ); $output .= '</div>'; }//end foreach $output .= '</div>'; return $output; }
[ "public", "function", "add_i18n_inputs", "(", "$", "output", ",", "$", "name", ",", "$", "value", ",", "$", "options", ",", "$", "pod", ",", "$", "id", ")", "{", "if", "(", "!", "empty", "(", "$", "pod", ")", "||", "empty", "(", "$", "name", ")...
Adds translation inputs to fields @since 0.1.0 @see PodsForm.php >> 'pods_form_ui_field_' . $type (filter) @param string $output The default output of the field @param string $name The field name @param string $value The field value @param array $options The field options @param array $pod The Pod @param int $id The field ID @return string
[ "Adds", "translation", "inputs", "to", "fields" ]
fd9a07c5c81ccbfcb21c5a0b2166f96c31d0826c
https://github.com/pods-framework/pods/blob/fd9a07c5c81ccbfcb21c5a0b2166f96c31d0826c/components/I18n/I18n.php#L867-L924
train
pods-framework/pods
components/I18n/I18n.php
Pods_Component_I18n.obj_is_language_enabled
public function obj_is_language_enabled( $locale, $data ) { // If the locale isn't enabled in the global scope from the component it's always disabled if ( ! array_key_exists( $locale, $this->languages ) ) { return false; } $data = (array) $data; $options = ( isset( $data['options'] ) ) ? $data['options'] : $data; // If it doesn't exist in the object data then use the default (enabled) if ( isset( $options['enable_i18n'][ $locale ] ) && false === (bool) $options['enable_i18n'][ $locale ] ) { return false; } return true; }
php
public function obj_is_language_enabled( $locale, $data ) { // If the locale isn't enabled in the global scope from the component it's always disabled if ( ! array_key_exists( $locale, $this->languages ) ) { return false; } $data = (array) $data; $options = ( isset( $data['options'] ) ) ? $data['options'] : $data; // If it doesn't exist in the object data then use the default (enabled) if ( isset( $options['enable_i18n'][ $locale ] ) && false === (bool) $options['enable_i18n'][ $locale ] ) { return false; } return true; }
[ "public", "function", "obj_is_language_enabled", "(", "$", "locale", ",", "$", "data", ")", "{", "// If the locale isn't enabled in the global scope from the component it's always disabled", "if", "(", "!", "array_key_exists", "(", "$", "locale", ",", "$", "this", "->", ...
Check if a language is get to enabled for an object @since 0.1.0 @param string $locale The locale to validate @param array $data Object data @return bool
[ "Check", "if", "a", "language", "is", "get", "to", "enabled", "for", "an", "object" ]
fd9a07c5c81ccbfcb21c5a0b2166f96c31d0826c
https://github.com/pods-framework/pods/blob/fd9a07c5c81ccbfcb21c5a0b2166f96c31d0826c/components/I18n/I18n.php#L936-L950
train
pods-framework/pods
components/I18n/I18n.php
Pods_Component_I18n.create_lang_label
public function create_lang_label( $lang_data ) { $english_name = ''; $native_name = ''; if ( isset( $lang_data['english_name'] ) ) { $english_name = $lang_data['english_name']; } if ( isset( $lang_data['native_name'] ) ) { $native_name = $lang_data['native_name']; } if ( ! empty( $native_name ) && ! empty( $english_name ) ) { if ( $native_name == $english_name ) { return $english_name; } else { return $english_name . ' / ' . $native_name; } } else { if ( ! empty( $english_name ) ) { return $english_name; } if ( ! empty( $native_name ) ) { return $native_name; } } return ''; }
php
public function create_lang_label( $lang_data ) { $english_name = ''; $native_name = ''; if ( isset( $lang_data['english_name'] ) ) { $english_name = $lang_data['english_name']; } if ( isset( $lang_data['native_name'] ) ) { $native_name = $lang_data['native_name']; } if ( ! empty( $native_name ) && ! empty( $english_name ) ) { if ( $native_name == $english_name ) { return $english_name; } else { return $english_name . ' / ' . $native_name; } } else { if ( ! empty( $english_name ) ) { return $english_name; } if ( ! empty( $native_name ) ) { return $native_name; } } return ''; }
[ "public", "function", "create_lang_label", "(", "$", "lang_data", ")", "{", "$", "english_name", "=", "''", ";", "$", "native_name", "=", "''", ";", "if", "(", "isset", "(", "$", "lang_data", "[", "'english_name'", "]", ")", ")", "{", "$", "english_name"...
Create a label with the english and native name combined @since 0.1.0 @param array $lang_data @return string
[ "Create", "a", "label", "with", "the", "english", "and", "native", "name", "combined" ]
fd9a07c5c81ccbfcb21c5a0b2166f96c31d0826c
https://github.com/pods-framework/pods/blob/fd9a07c5c81ccbfcb21c5a0b2166f96c31d0826c/components/I18n/I18n.php#L961-L989
train
pods-framework/pods
deprecated/deprecated.php
Pod.__isset
public function __isset( $name ) { $name = (string) $name; if ( in_array( $name, array( '_data', 'data', 'total', 'total_rows', 'zebra' ), true ) ) { return true; } elseif ( in_array( $name, array( 'meta', 'meta_properties', 'meta_extra' ), true ) ) { return true; } else { return isset( $this->new->{$name} ); } }
php
public function __isset( $name ) { $name = (string) $name; if ( in_array( $name, array( '_data', 'data', 'total', 'total_rows', 'zebra' ), true ) ) { return true; } elseif ( in_array( $name, array( 'meta', 'meta_properties', 'meta_extra' ), true ) ) { return true; } else { return isset( $this->new->{$name} ); } }
[ "public", "function", "__isset", "(", "$", "name", ")", "{", "$", "name", "=", "(", "string", ")", "$", "name", ";", "if", "(", "in_array", "(", "$", "name", ",", "array", "(", "'_data'", ",", "'data'", ",", "'total'", ",", "'total_rows'", ",", "'z...
Handle variables that have been deprecated @since 2.0.0 @param string $name Property name. @return bool
[ "Handle", "variables", "that", "have", "been", "deprecated" ]
fd9a07c5c81ccbfcb21c5a0b2166f96c31d0826c
https://github.com/pods-framework/pods/blob/fd9a07c5c81ccbfcb21c5a0b2166f96c31d0826c/deprecated/deprecated.php#L242-L253
train
pods-framework/pods
classes/fields/datetime.php
PodsField_DateTime.format_date
public function format_date( $options, $js = false ) { switch ( (string) pods_v( static::$type . '_type', $options, 'format', true ) ) { case 'wp': $format = get_option( 'date_format' ); if ( $js ) { $format = $this->convert_format( $format, array( 'source' => 'php' ) ); } break; case 'custom': if ( ! $js ) { $format = pods_v( static::$type . '_format_custom', $options, '' ); } else { $format = pods_v( static::$type . '_format_custom_js', $options, '' ); if ( empty( $format ) ) { $format = pods_v( static::$type . '_format_custom', $options, '' ); $format = $this->convert_format( $format, array( 'source' => 'php' ) ); } } break; default: $date_format = $this->get_date_formats( $js ); $format = $date_format[ pods_v( static::$type . '_format', $options, 'ymd_dash', true ) ]; break; }//end switch return $format; }
php
public function format_date( $options, $js = false ) { switch ( (string) pods_v( static::$type . '_type', $options, 'format', true ) ) { case 'wp': $format = get_option( 'date_format' ); if ( $js ) { $format = $this->convert_format( $format, array( 'source' => 'php' ) ); } break; case 'custom': if ( ! $js ) { $format = pods_v( static::$type . '_format_custom', $options, '' ); } else { $format = pods_v( static::$type . '_format_custom_js', $options, '' ); if ( empty( $format ) ) { $format = pods_v( static::$type . '_format_custom', $options, '' ); $format = $this->convert_format( $format, array( 'source' => 'php' ) ); } } break; default: $date_format = $this->get_date_formats( $js ); $format = $date_format[ pods_v( static::$type . '_format', $options, 'ymd_dash', true ) ]; break; }//end switch return $format; }
[ "public", "function", "format_date", "(", "$", "options", ",", "$", "js", "=", "false", ")", "{", "switch", "(", "(", "string", ")", "pods_v", "(", "static", "::", "$", "type", ".", "'_type'", ",", "$", "options", ",", "'format'", ",", "true", ")", ...
Build date format string based on options @since 2.7.0 @param array $options Field options. @param bool $js Whether to return format for jQuery UI. @return string
[ "Build", "date", "format", "string", "based", "on", "options" ]
fd9a07c5c81ccbfcb21c5a0b2166f96c31d0826c
https://github.com/pods-framework/pods/blob/fd9a07c5c81ccbfcb21c5a0b2166f96c31d0826c/classes/fields/datetime.php#L459-L486
train
pods-framework/pods
classes/fields/datetime.php
PodsField_DateTime.get_date_formats
public function get_date_formats( $js = false ) { $date_format = array( 'mdy' => 'm/d/Y', 'mdy_dash' => 'm-d-Y', 'mdy_dot' => 'm.d.Y', 'dmy' => 'd/m/Y', 'dmy_dash' => 'd-m-Y', 'dmy_dot' => 'd.m.Y', 'ymd_slash' => 'Y/m/d', 'ymd_dash' => 'Y-m-d', 'ymd_dot' => 'Y.m.d', 'dMy' => 'd/M/Y', 'dMy_dash' => 'd-M-Y', 'fjy' => 'F j, Y', 'fjsy' => 'F jS, Y', 'y' => 'Y', ); $filter = 'pods_form_ui_field_date_formats'; if ( $js ) { // @todo Method parameters? (Not supported by array_map) $date_format = array_map( array( $this, 'convert_format' ), $date_format ); $filter = 'pods_form_ui_field_date_js_formats'; } return apply_filters( $filter, $date_format ); }
php
public function get_date_formats( $js = false ) { $date_format = array( 'mdy' => 'm/d/Y', 'mdy_dash' => 'm-d-Y', 'mdy_dot' => 'm.d.Y', 'dmy' => 'd/m/Y', 'dmy_dash' => 'd-m-Y', 'dmy_dot' => 'd.m.Y', 'ymd_slash' => 'Y/m/d', 'ymd_dash' => 'Y-m-d', 'ymd_dot' => 'Y.m.d', 'dMy' => 'd/M/Y', 'dMy_dash' => 'd-M-Y', 'fjy' => 'F j, Y', 'fjsy' => 'F jS, Y', 'y' => 'Y', ); $filter = 'pods_form_ui_field_date_formats'; if ( $js ) { // @todo Method parameters? (Not supported by array_map) $date_format = array_map( array( $this, 'convert_format' ), $date_format ); $filter = 'pods_form_ui_field_date_js_formats'; } return apply_filters( $filter, $date_format ); }
[ "public", "function", "get_date_formats", "(", "$", "js", "=", "false", ")", "{", "$", "date_format", "=", "array", "(", "'mdy'", "=>", "'m/d/Y'", ",", "'mdy_dash'", "=>", "'m-d-Y'", ",", "'mdy_dot'", "=>", "'m.d.Y'", ",", "'dmy'", "=>", "'d/m/Y'", ",", ...
Get the date formats. @since 2.7.0 @param bool $js Whether to return format for jQuery UI. @return array
[ "Get", "the", "date", "formats", "." ]
fd9a07c5c81ccbfcb21c5a0b2166f96c31d0826c
https://github.com/pods-framework/pods/blob/fd9a07c5c81ccbfcb21c5a0b2166f96c31d0826c/classes/fields/datetime.php#L548-L577
train
pods-framework/pods
classes/fields/datetime.php
PodsField_DateTime.createFromFormat
public function createFromFormat( $format, $date, $return_timestamp = false ) { $datetime = null; try { if ( method_exists( 'DateTime', 'createFromFormat' ) ) { $timezone = get_option( 'timezone_string' ); if ( empty( $timezone ) ) { $timezone = timezone_name_from_abbr( '', get_option( 'gmt_offset' ) * HOUR_IN_SECONDS, 0 ); } if ( ! empty( $timezone ) ) { $datetimezone = new DateTimeZone( $timezone ); $datetime = DateTime::createFromFormat( $format, (string) $date, $datetimezone ); if ( false === $datetime ) { $datetime = DateTime::createFromFormat( static::$storage_format, (string) $date, $datetimezone ); } if ( false !== $datetime && $return_timestamp ) { return $datetime; } } }//end if if ( in_array( $datetime, array( null, false ), true ) ) { if ( empty( $date ) ) { $timestamp = time(); } else { $timestamp = strtotime( (string) $date ); if ( $return_timestamp ) { return $timestamp; } } if ( $timestamp ) { $datetime = new DateTime( date_i18n( static::$storage_format, $timestamp ) ); } } } catch ( Exception $e ) { // There is no saving this time value, it's an exception to the rule. } return apply_filters( 'pods_form_ui_field_datetime_formatter', $datetime, $format, $date ); }
php
public function createFromFormat( $format, $date, $return_timestamp = false ) { $datetime = null; try { if ( method_exists( 'DateTime', 'createFromFormat' ) ) { $timezone = get_option( 'timezone_string' ); if ( empty( $timezone ) ) { $timezone = timezone_name_from_abbr( '', get_option( 'gmt_offset' ) * HOUR_IN_SECONDS, 0 ); } if ( ! empty( $timezone ) ) { $datetimezone = new DateTimeZone( $timezone ); $datetime = DateTime::createFromFormat( $format, (string) $date, $datetimezone ); if ( false === $datetime ) { $datetime = DateTime::createFromFormat( static::$storage_format, (string) $date, $datetimezone ); } if ( false !== $datetime && $return_timestamp ) { return $datetime; } } }//end if if ( in_array( $datetime, array( null, false ), true ) ) { if ( empty( $date ) ) { $timestamp = time(); } else { $timestamp = strtotime( (string) $date ); if ( $return_timestamp ) { return $timestamp; } } if ( $timestamp ) { $datetime = new DateTime( date_i18n( static::$storage_format, $timestamp ) ); } } } catch ( Exception $e ) { // There is no saving this time value, it's an exception to the rule. } return apply_filters( 'pods_form_ui_field_datetime_formatter', $datetime, $format, $date ); }
[ "public", "function", "createFromFormat", "(", "$", "format", ",", "$", "date", ",", "$", "return_timestamp", "=", "false", ")", "{", "$", "datetime", "=", "null", ";", "try", "{", "if", "(", "method_exists", "(", "'DateTime'", ",", "'createFromFormat'", "...
PHP backwards compatibility for createFromFormat. @param string $format Format string. @param string $date Defaults to time() if empty. @param boolean $return_timestamp Whether to return the strtotime() or createFromFormat result or not. @return DateTime|null|int|false
[ "PHP", "backwards", "compatibility", "for", "createFromFormat", "." ]
fd9a07c5c81ccbfcb21c5a0b2166f96c31d0826c
https://github.com/pods-framework/pods/blob/fd9a07c5c81ccbfcb21c5a0b2166f96c31d0826c/classes/fields/datetime.php#L652-L699
train
pods-framework/pods
classes/fields/datetime.php
PodsField_DateTime.convert_date
public function convert_date( $value, $new_format, $original_format = '', $return_timestamp = false ) { if ( empty( $original_format ) ) { $original_format = static::$storage_format; } $date = ''; if ( ! empty( $value ) && ! in_array( $value, array( '0000-00-00', '0000-00-00 00:00:00', '00:00:00' ), true ) ) { $date = $this->createFromFormat( $original_format, (string) $value, $return_timestamp ); if ( $date instanceof DateTime ) { $value = $date->format( $new_format ); } elseif ( false !== $date ) { $date = strtotime( (string) $value ); $value = date_i18n( $new_format, $date ); } } else { $value = date_i18n( $new_format ); } // Return timestamp conversion result instead if ( $return_timestamp ) { return $date; } return $value; }
php
public function convert_date( $value, $new_format, $original_format = '', $return_timestamp = false ) { if ( empty( $original_format ) ) { $original_format = static::$storage_format; } $date = ''; if ( ! empty( $value ) && ! in_array( $value, array( '0000-00-00', '0000-00-00 00:00:00', '00:00:00' ), true ) ) { $date = $this->createFromFormat( $original_format, (string) $value, $return_timestamp ); if ( $date instanceof DateTime ) { $value = $date->format( $new_format ); } elseif ( false !== $date ) { $date = strtotime( (string) $value ); $value = date_i18n( $new_format, $date ); } } else { $value = date_i18n( $new_format ); } // Return timestamp conversion result instead if ( $return_timestamp ) { return $date; } return $value; }
[ "public", "function", "convert_date", "(", "$", "value", ",", "$", "new_format", ",", "$", "original_format", "=", "''", ",", "$", "return_timestamp", "=", "false", ")", "{", "if", "(", "empty", "(", "$", "original_format", ")", ")", "{", "$", "original_...
Convert a date from one format to another. @param string $value Field value. @param string $new_format New format string. @param string $original_format Original format string (if known). @param boolean $return_timestamp Whether to return the strtotime() or createFromFormat result or not. @return string|int|boolean|DateTime
[ "Convert", "a", "date", "from", "one", "format", "to", "another", "." ]
fd9a07c5c81ccbfcb21c5a0b2166f96c31d0826c
https://github.com/pods-framework/pods/blob/fd9a07c5c81ccbfcb21c5a0b2166f96c31d0826c/classes/fields/datetime.php#L711-L739
train
pods-framework/pods
classes/fields/datetime.php
PodsField_DateTime.convert_format
public function convert_format( $source_format, $args = array() ) { // @todo Improve source/target logic. $args = array_merge( array( 'source' => 'php', // 'jquery_ui' for reverse. ), $args ); // Keep keys and values sorted by string length. $symbols = array( // Day 'd' => 'dd', 'l' => 'DD', 'D' => 'D', 'j' => 'd', 'N' => '', 'S' => '', 'w' => '', 'z' => 'o', // Week 'W' => '', // Month 'F' => 'MM', 'm' => 'mm', 'M' => 'M', 'n' => 'm', 't' => '', // Year 'L' => '', 'o' => '', 'Y' => 'yy', 'y' => 'y', // AM/PM 'a' => 'tt', 'A' => 'TT', // Swatch internet time (not supported) 'B' => '', // Hour 'h' => 'hh', 'H' => 'HH', 'g' => 'h', 'G' => 'H', // Minute 'i' => 'mm', // Second 's' => 'ss', // Microsecond 'u' => 'c', ); if ( version_compare( PHP_VERSION, '7.0.0' ) >= 0 ) { // Millisecond $symbols['v'] = 'l'; } if ( 'jquery_ui' === $args['source'] ) { // Remove empty values. $symbols = array_filter( $symbols ); $symbols = array_flip( $symbols ); } $new_format = ''; $escaping = false; $source_format_length = strlen( $source_format ); for ( $i = 0; $i < $source_format_length; $i ++ ) { $char = $source_format[ $i ]; // PHP date format escaping character // @todo Do we want to support non-format characters? if ( '\\' === $char ) { $i ++; if ( $escaping ) { $new_format .= $source_format[ $i ]; } else { $new_format .= '\'' . $source_format[ $i ]; } $escaping = true; } else { if ( $escaping ) { $new_format .= "'"; $escaping = false; } $symbol_key = false; if ( isset( $source_format[ $i + 1 ] ) ) { $symbol_key = $char . $source_format[ $i + 1 ]; } // Support 2 characters. if ( $symbol_key && isset( $symbols[ $symbol_key ] ) ) { $new_format .= $symbols[ $symbol_key ]; $i ++; } elseif ( isset( $symbols[ $char ] ) ) { $new_format .= $symbols[ $char ]; } else { $new_format .= $char; } }//end if }//end for return $new_format; }
php
public function convert_format( $source_format, $args = array() ) { // @todo Improve source/target logic. $args = array_merge( array( 'source' => 'php', // 'jquery_ui' for reverse. ), $args ); // Keep keys and values sorted by string length. $symbols = array( // Day 'd' => 'dd', 'l' => 'DD', 'D' => 'D', 'j' => 'd', 'N' => '', 'S' => '', 'w' => '', 'z' => 'o', // Week 'W' => '', // Month 'F' => 'MM', 'm' => 'mm', 'M' => 'M', 'n' => 'm', 't' => '', // Year 'L' => '', 'o' => '', 'Y' => 'yy', 'y' => 'y', // AM/PM 'a' => 'tt', 'A' => 'TT', // Swatch internet time (not supported) 'B' => '', // Hour 'h' => 'hh', 'H' => 'HH', 'g' => 'h', 'G' => 'H', // Minute 'i' => 'mm', // Second 's' => 'ss', // Microsecond 'u' => 'c', ); if ( version_compare( PHP_VERSION, '7.0.0' ) >= 0 ) { // Millisecond $symbols['v'] = 'l'; } if ( 'jquery_ui' === $args['source'] ) { // Remove empty values. $symbols = array_filter( $symbols ); $symbols = array_flip( $symbols ); } $new_format = ''; $escaping = false; $source_format_length = strlen( $source_format ); for ( $i = 0; $i < $source_format_length; $i ++ ) { $char = $source_format[ $i ]; // PHP date format escaping character // @todo Do we want to support non-format characters? if ( '\\' === $char ) { $i ++; if ( $escaping ) { $new_format .= $source_format[ $i ]; } else { $new_format .= '\'' . $source_format[ $i ]; } $escaping = true; } else { if ( $escaping ) { $new_format .= "'"; $escaping = false; } $symbol_key = false; if ( isset( $source_format[ $i + 1 ] ) ) { $symbol_key = $char . $source_format[ $i + 1 ]; } // Support 2 characters. if ( $symbol_key && isset( $symbols[ $symbol_key ] ) ) { $new_format .= $symbols[ $symbol_key ]; $i ++; } elseif ( isset( $symbols[ $char ] ) ) { $new_format .= $symbols[ $char ]; } else { $new_format .= $char; } }//end if }//end for return $new_format; }
[ "public", "function", "convert_format", "(", "$", "source_format", ",", "$", "args", "=", "array", "(", ")", ")", "{", "// @todo Improve source/target logic.", "$", "args", "=", "array_merge", "(", "array", "(", "'source'", "=>", "'php'", ",", "// 'jquery_ui' fo...
Matches each symbol of PHP date format standard with jQuery equivalent codeword. @link http://stackoverflow.com/questions/16702398/convert-a-php-date-format-to-a-jqueryui-datepicker-date-format @link https://api.jqueryui.com/datepicker/ @link http://trentrichardson.com/examples/timepicker/ @since 2.7.0 @param string $source_format Source format string. @param array $args Format arguments. @return string
[ "Matches", "each", "symbol", "of", "PHP", "date", "format", "standard", "with", "jQuery", "equivalent", "codeword", "." ]
fd9a07c5c81ccbfcb21c5a0b2166f96c31d0826c
https://github.com/pods-framework/pods/blob/fd9a07c5c81ccbfcb21c5a0b2166f96c31d0826c/classes/fields/datetime.php#L755-L864
train
pods-framework/pods
classes/fields/currency.php
PodsField_Currency.get_max_decimals
public function get_max_decimals( $options ) { $length = (int) pods_v( static::$type . '_max_length', $options, 12, true ); if ( $length < 1 || 64 < $length ) { $length = 64; } $decimals = (int) pods_v( static::$type . '_decimals', $options, 2 ); if ( $decimals < 1 ) { $decimals = 0; } elseif ( 30 < $decimals ) { $decimals = 30; } if ( $length < $decimals ) { $decimals = $length; } return $decimals; }
php
public function get_max_decimals( $options ) { $length = (int) pods_v( static::$type . '_max_length', $options, 12, true ); if ( $length < 1 || 64 < $length ) { $length = 64; } $decimals = (int) pods_v( static::$type . '_decimals', $options, 2 ); if ( $decimals < 1 ) { $decimals = 0; } elseif ( 30 < $decimals ) { $decimals = 30; } if ( $length < $decimals ) { $decimals = $length; } return $decimals; }
[ "public", "function", "get_max_decimals", "(", "$", "options", ")", "{", "$", "length", "=", "(", "int", ")", "pods_v", "(", "static", "::", "$", "type", ".", "'_max_length'", ",", "$", "options", ",", "12", ",", "true", ")", ";", "if", "(", "$", "...
Get the max allowed decimals. Overwrites the default value of Number field. 2 decimals instead of 0. @since 2.7.0 @param array $options Field options. @return int
[ "Get", "the", "max", "allowed", "decimals", ".", "Overwrites", "the", "default", "value", "of", "Number", "field", ".", "2", "decimals", "instead", "of", "0", "." ]
fd9a07c5c81ccbfcb21c5a0b2166f96c31d0826c
https://github.com/pods-framework/pods/blob/fd9a07c5c81ccbfcb21c5a0b2166f96c31d0826c/classes/fields/currency.php#L642-L663
train
pods-framework/pods
components/Roles/Roles.php
Pods_Roles.ajax_add
public function ajax_add( $params ) { global $wp_roles; $role_name = pods_var_raw( 'role_name', $params ); $role_label = pods_var_raw( 'role_label', $params ); $params->capabilities = (array) pods_var_raw( 'capabilities', $params, array() ); $params->custom_capabilities = (array) pods_var_raw( 'custom_capabilities', $params, array() ); $params->custom_capabilities = array_filter( array_unique( $params->custom_capabilities ) ); $capabilities = array(); foreach ( $params->capabilities as $capability => $x ) { if ( empty( $capability ) || true !== (boolean) $x ) { continue; } $capabilities[ esc_attr( $capability ) ] = true; } foreach ( $params->custom_capabilities as $x => $capability ) { if ( empty( $capability ) || '--1' === $x ) { continue; } $capabilities[ esc_attr( $capability ) ] = true; } if ( empty( $role_name ) ) { return pods_error( __( 'Role name is required', 'pods' ) ); } if ( empty( $role_label ) ) { return pods_error( __( 'Role label is required', 'pods' ) ); } return add_role( $role_name, $role_label, $capabilities ); }
php
public function ajax_add( $params ) { global $wp_roles; $role_name = pods_var_raw( 'role_name', $params ); $role_label = pods_var_raw( 'role_label', $params ); $params->capabilities = (array) pods_var_raw( 'capabilities', $params, array() ); $params->custom_capabilities = (array) pods_var_raw( 'custom_capabilities', $params, array() ); $params->custom_capabilities = array_filter( array_unique( $params->custom_capabilities ) ); $capabilities = array(); foreach ( $params->capabilities as $capability => $x ) { if ( empty( $capability ) || true !== (boolean) $x ) { continue; } $capabilities[ esc_attr( $capability ) ] = true; } foreach ( $params->custom_capabilities as $x => $capability ) { if ( empty( $capability ) || '--1' === $x ) { continue; } $capabilities[ esc_attr( $capability ) ] = true; } if ( empty( $role_name ) ) { return pods_error( __( 'Role name is required', 'pods' ) ); } if ( empty( $role_label ) ) { return pods_error( __( 'Role label is required', 'pods' ) ); } return add_role( $role_name, $role_label, $capabilities ); }
[ "public", "function", "ajax_add", "(", "$", "params", ")", "{", "global", "$", "wp_roles", ";", "$", "role_name", "=", "pods_var_raw", "(", "'role_name'", ",", "$", "params", ")", ";", "$", "role_label", "=", "pods_var_raw", "(", "'role_label'", ",", "$", ...
Handle the Add Role AJAX @param $params @return mixed|void
[ "Handle", "the", "Add", "Role", "AJAX" ]
fd9a07c5c81ccbfcb21c5a0b2166f96c31d0826c
https://github.com/pods-framework/pods/blob/fd9a07c5c81ccbfcb21c5a0b2166f96c31d0826c/components/Roles/Roles.php#L281-L320
train
pods-framework/pods
components/Roles/Roles.php
Pods_Roles.ajax_edit
public function ajax_edit( $params ) { global $wp_roles; $capabilities = $this->get_capabilities(); $params->capabilities = (array) pods_var_raw( 'capabilities', $params, array() ); $params->custom_capabilities = (array) pods_var_raw( 'custom_capabilities', $params, array() ); $params->custom_capabilities = array_filter( array_unique( $params->custom_capabilities ) ); if ( ! isset( $params->id ) || empty( $params->id ) || ! isset( $wp_roles->role_objects[ $params->id ] ) ) { return pods_error( __( 'Role not found, cannot edit it.', 'pods' ) ); } /** * @var $role WP_Role */ $role = $wp_roles->role_objects[ $params->id ]; $role_name = $params->id; $role_label = $wp_roles->role_names[ $params->id ]; $role_capabilities = $role->capabilities; $new_capabilities = array(); foreach ( $params->capabilities as $capability => $x ) { if ( empty( $capability ) || true !== (boolean) $x ) { continue; } $new_capabilities[] = esc_attr( $capability ); if ( ! $role->has_cap( $capability ) ) { $role->add_cap( $capability ); } } foreach ( $params->custom_capabilities as $x => $capability ) { if ( empty( $capability ) ) { continue; } if ( in_array( $capability, $new_capabilities, true ) ) { continue; } $new_capabilities[] = esc_attr( $capability ); if ( ! $role->has_cap( $capability ) ) { $role->add_cap( $capability ); } } foreach ( $role_capabilities as $capability => $x ) { if ( ! in_array( $capability, $new_capabilities, true ) && false === strpos( $capability, 'level_' ) ) { $role->remove_cap( $capability ); } } return true; }
php
public function ajax_edit( $params ) { global $wp_roles; $capabilities = $this->get_capabilities(); $params->capabilities = (array) pods_var_raw( 'capabilities', $params, array() ); $params->custom_capabilities = (array) pods_var_raw( 'custom_capabilities', $params, array() ); $params->custom_capabilities = array_filter( array_unique( $params->custom_capabilities ) ); if ( ! isset( $params->id ) || empty( $params->id ) || ! isset( $wp_roles->role_objects[ $params->id ] ) ) { return pods_error( __( 'Role not found, cannot edit it.', 'pods' ) ); } /** * @var $role WP_Role */ $role = $wp_roles->role_objects[ $params->id ]; $role_name = $params->id; $role_label = $wp_roles->role_names[ $params->id ]; $role_capabilities = $role->capabilities; $new_capabilities = array(); foreach ( $params->capabilities as $capability => $x ) { if ( empty( $capability ) || true !== (boolean) $x ) { continue; } $new_capabilities[] = esc_attr( $capability ); if ( ! $role->has_cap( $capability ) ) { $role->add_cap( $capability ); } } foreach ( $params->custom_capabilities as $x => $capability ) { if ( empty( $capability ) ) { continue; } if ( in_array( $capability, $new_capabilities, true ) ) { continue; } $new_capabilities[] = esc_attr( $capability ); if ( ! $role->has_cap( $capability ) ) { $role->add_cap( $capability ); } } foreach ( $role_capabilities as $capability => $x ) { if ( ! in_array( $capability, $new_capabilities, true ) && false === strpos( $capability, 'level_' ) ) { $role->remove_cap( $capability ); } } return true; }
[ "public", "function", "ajax_edit", "(", "$", "params", ")", "{", "global", "$", "wp_roles", ";", "$", "capabilities", "=", "$", "this", "->", "get_capabilities", "(", ")", ";", "$", "params", "->", "capabilities", "=", "(", "array", ")", "pods_var_raw", ...
Handle the Edit Role AJAX @todo allow rename role_label @param $params @return bool|mixed|void
[ "Handle", "the", "Edit", "Role", "AJAX" ]
fd9a07c5c81ccbfcb21c5a0b2166f96c31d0826c
https://github.com/pods-framework/pods/blob/fd9a07c5c81ccbfcb21c5a0b2166f96c31d0826c/components/Roles/Roles.php#L331-L391
train
pods-framework/pods
components/Roles/Roles.php
Pods_Roles.count_users
public function count_users( $role ) { $count_users = count_users(); $avail_roles = array(); foreach ( $count_users['avail_roles'] as $count_role => $count ) { $avail_roles[ $count_role ] = $count; } if ( empty( $role ) ) { return $avail_roles; } if ( ! isset( $avail_roles[ $role ] ) ) { $avail_roles[ $role ] = 0; } return $avail_roles[ $role ]; }
php
public function count_users( $role ) { $count_users = count_users(); $avail_roles = array(); foreach ( $count_users['avail_roles'] as $count_role => $count ) { $avail_roles[ $count_role ] = $count; } if ( empty( $role ) ) { return $avail_roles; } if ( ! isset( $avail_roles[ $role ] ) ) { $avail_roles[ $role ] = 0; } return $avail_roles[ $role ]; }
[ "public", "function", "count_users", "(", "$", "role", ")", "{", "$", "count_users", "=", "count_users", "(", ")", ";", "$", "avail_roles", "=", "array", "(", ")", ";", "foreach", "(", "$", "count_users", "[", "'avail_roles'", "]", "as", "$", "count_role...
Basic logic from Members plugin, it counts users of a specific role @param $role @return array
[ "Basic", "logic", "from", "Members", "plugin", "it", "counts", "users", "of", "a", "specific", "role" ]
fd9a07c5c81ccbfcb21c5a0b2166f96c31d0826c
https://github.com/pods-framework/pods/blob/fd9a07c5c81ccbfcb21c5a0b2166f96c31d0826c/components/Roles/Roles.php#L400-L419
train
pods-framework/pods
components/Templates/includes/auto-template/Pods_Templates_Auto_Template_Front_End.php
Pods_Templates_Auto_Template_Front_End.get_pod_filter
public function get_pod_filter( $current_post_type = '', $possible_pods = array() ) { $filter = 'the_content'; if ( ! $current_post_type ) { // get the current post type $current_post_type = $this->current_post_type(); } if ( ! $possible_pods ) { //now use other methods in class to build array to search in/ use $possible_pods = $this->auto_pods(); } //check if $current_post_type is the key of the array of possible pods if ( isset( $possible_pods[ $current_post_type ] ) ) { $this_pod = $possible_pods[ $current_post_type ]; if ( is_singular( $current_post_type ) ) { $filter = pods_v( 'single_filter', $this_pod, $filter, true ); } elseif ( is_post_type_archive( $current_post_type ) ) { $filter = pods_v( 'archive_filter', $this_pod, $filter, true ); } elseif ( is_home() && $current_post_type === 'post' ) { $filter = pods_v( 'archive_filter', $this_pod, $filter, true ); } elseif ( is_tax( $current_post_type ) ) { $filter = pods_v( 'archive_filter', $this_pod, $filter, true ); } } return $filter; }
php
public function get_pod_filter( $current_post_type = '', $possible_pods = array() ) { $filter = 'the_content'; if ( ! $current_post_type ) { // get the current post type $current_post_type = $this->current_post_type(); } if ( ! $possible_pods ) { //now use other methods in class to build array to search in/ use $possible_pods = $this->auto_pods(); } //check if $current_post_type is the key of the array of possible pods if ( isset( $possible_pods[ $current_post_type ] ) ) { $this_pod = $possible_pods[ $current_post_type ]; if ( is_singular( $current_post_type ) ) { $filter = pods_v( 'single_filter', $this_pod, $filter, true ); } elseif ( is_post_type_archive( $current_post_type ) ) { $filter = pods_v( 'archive_filter', $this_pod, $filter, true ); } elseif ( is_home() && $current_post_type === 'post' ) { $filter = pods_v( 'archive_filter', $this_pod, $filter, true ); } elseif ( is_tax( $current_post_type ) ) { $filter = pods_v( 'archive_filter', $this_pod, $filter, true ); } } return $filter; }
[ "public", "function", "get_pod_filter", "(", "$", "current_post_type", "=", "''", ",", "$", "possible_pods", "=", "array", "(", ")", ")", "{", "$", "filter", "=", "'the_content'", ";", "if", "(", "!", "$", "current_post_type", ")", "{", "// get the current p...
Get the filter used for a Pod. @since 1.7.2 @param string $current_post_type @param array $possible_pods @return string
[ "Get", "the", "filter", "used", "for", "a", "Pod", "." ]
fd9a07c5c81ccbfcb21c5a0b2166f96c31d0826c
https://github.com/pods-framework/pods/blob/fd9a07c5c81ccbfcb21c5a0b2166f96c31d0826c/components/Templates/includes/auto-template/Pods_Templates_Auto_Template_Front_End.php#L33-L62
train
pods-framework/pods
components/Templates/includes/auto-template/Pods_Templates_Auto_Template_Front_End.php
Pods_Templates_Auto_Template_Front_End.hook_content
public function hook_content(){ $filter = $this->get_pod_filter(); /** * Allows plugin to append/replace the_excerpt * * Default is false, set to true to enable. */ if ( ! defined( 'PFAT_USE_ON_EXCERPT' ) ) { define( 'PFAT_USE_ON_EXCERPT', false ); } add_filter( $filter, array( $this, 'front' ), 10.5 ); if ( PFAT_USE_ON_EXCERPT ) { add_filter( 'the_excerpt', array( $this, 'front' ) ); } }
php
public function hook_content(){ $filter = $this->get_pod_filter(); /** * Allows plugin to append/replace the_excerpt * * Default is false, set to true to enable. */ if ( ! defined( 'PFAT_USE_ON_EXCERPT' ) ) { define( 'PFAT_USE_ON_EXCERPT', false ); } add_filter( $filter, array( $this, 'front' ), 10.5 ); if ( PFAT_USE_ON_EXCERPT ) { add_filter( 'the_excerpt', array( $this, 'front' ) ); } }
[ "public", "function", "hook_content", "(", ")", "{", "$", "filter", "=", "$", "this", "->", "get_pod_filter", "(", ")", ";", "/**\n\t\t * Allows plugin to append/replace the_excerpt\n\t\t *\n\t\t * Default is false, set to true to enable.\n\t\t */", "if", "(", "!", "defined",...
Add hooks for output @since 2.6.6
[ "Add", "hooks", "for", "output" ]
fd9a07c5c81ccbfcb21c5a0b2166f96c31d0826c
https://github.com/pods-framework/pods/blob/fd9a07c5c81ccbfcb21c5a0b2166f96c31d0826c/components/Templates/includes/auto-template/Pods_Templates_Auto_Template_Front_End.php#L69-L87
train
pods-framework/pods
components/Templates/includes/auto-template/Pods_Templates_Auto_Template_Front_End.php
Pods_Templates_Auto_Template_Front_End.the_pods
public function the_pods() { // use the cached results $key = '_pods_pfat_the_pods'; $the_pods = pods_transient_get( $key ); // check if we already have the results cached & use it if we can. if ( false === $the_pods ) { // get all post type pods $the_pods = pods_api()->load_pods( array( 'type' => array( 'taxonomy', 'post_type', ), 'names' => true, ) ); // cache the results pods_transient_set( $key, $the_pods ); } return $the_pods; }
php
public function the_pods() { // use the cached results $key = '_pods_pfat_the_pods'; $the_pods = pods_transient_get( $key ); // check if we already have the results cached & use it if we can. if ( false === $the_pods ) { // get all post type pods $the_pods = pods_api()->load_pods( array( 'type' => array( 'taxonomy', 'post_type', ), 'names' => true, ) ); // cache the results pods_transient_set( $key, $the_pods ); } return $the_pods; }
[ "public", "function", "the_pods", "(", ")", "{", "// use the cached results", "$", "key", "=", "'_pods_pfat_the_pods'", ";", "$", "the_pods", "=", "pods_transient_get", "(", "$", "key", ")", ";", "// check if we already have the results cached & use it if we can.", "if", ...
Get all post type and taxonomy Pods @since 2.4.5 @return array Of Pod names.
[ "Get", "all", "post", "type", "and", "taxonomy", "Pods" ]
fd9a07c5c81ccbfcb21c5a0b2166f96c31d0826c
https://github.com/pods-framework/pods/blob/fd9a07c5c81ccbfcb21c5a0b2166f96c31d0826c/components/Templates/includes/auto-template/Pods_Templates_Auto_Template_Front_End.php#L96-L122
train
pods-framework/pods
components/Templates/includes/auto-template/Pods_Templates_Auto_Template_Front_End.php
Pods_Templates_Auto_Template_Front_End.auto_pods
public function auto_pods() { /** * Filter to override all settings for which templates are used. * * Note: If this filter does not return null, all back-end settings are ignored. To add to settings with a filter, use 'pods_pfat_auto_pods'; * * @param array $auto_pods Array of parameters to use instead of those from settings. * * @return array Settings arrays for each post type. * * @since 2.4.5 */ $auto_pods = apply_filters( 'pods_pfat_auto_pods_override', null ); if ( ! is_null( $auto_pods ) ) { return $auto_pods; } // try to get cached results of this method $key = '_pods_pfat_auto_pods'; $auto_pods = pods_transient_get( $key ); // check if we already have the results cached & use it if we can. if ( $auto_pods === false ) { // get possible pods $the_pods = $this->the_pods(); // start output array empty $auto_pods = array(); // get pods api class $api = pods_api(); // loop through each to see if auto templates is enabled foreach ( $the_pods as $the_pod => $the_pod_label ) { // get this Pods' data. $pod_data = $api->load_pod( array( 'name' => $the_pod ) ); // if auto template is enabled add info about Pod to array if ( 1 == pods_v( 'pfat_enable', $pod_data['options'] ) ) { // check if pfat_single and pfat_archive are set $single = pods_v( 'pfat_single', $pod_data['options'], false, true ); $archive = pods_v( 'pfat_archive', $pod_data['options'], false, true ); $single_append = pods_v( 'pfat_append_single', $pod_data['options'], true, true ); $archive_append = pods_v( 'pfat_append_archive', $pod_data['options'], true, true ); $single_filter = pods_v( 'pfat_filter_single', $pod_data['options'], 'the_content', true ); $archive_filter = pods_v( 'pfat_filter_archive', $pod_data['options'], 'the_content', true ); $run_outside_loop = pods_v( 'pfat_run_outside_loop', $pod_data['options'], false, true ); $type = pods_v( 'type', $pod_data, false, true ); // check if it's a post type that has an archive if ( $type === 'post_type' && $the_pod !== 'post' || $the_pod !== 'page' ) { $has_archive = pods_v( 'has_archive', $pod_data['options'], false, true ); } else { $has_archive = true; } if ( empty( $single_filter ) ) { $single_filter = 'the_content'; } if ( empty( $archive_filter ) ) { $archive_filter = 'the_content'; } // build output array $auto_pods[ $the_pod ] = array( 'name' => $the_pod, 'label' => $the_pod_label, 'single' => $single, 'archive' => $archive, 'single_append' => $single_append, 'archive_append' => $archive_append, 'has_archive' => $has_archive, 'single_filter' => $single_filter, 'archive_filter' => $archive_filter, 'run_outside_loop' => $run_outside_loop, 'type' => $type, ); }//end if }//end foreach // cache the results pods_transient_set( $key, $auto_pods ); }//end if /** * Add to or change settings. * * Use this filter to change or add to the settings set in the back-end for this plugin. Has no effect if 'pods_pfat_auto_pods_override' filter is being used. * * @param array $auto_pods Array of parameters to use instead of those from settings. * * @return array Settings arrays for each post type. * * @since 2.4.5 */ $auto_pods = apply_filters( 'pods_pfat_auto_pods', $auto_pods ); return $auto_pods; }
php
public function auto_pods() { /** * Filter to override all settings for which templates are used. * * Note: If this filter does not return null, all back-end settings are ignored. To add to settings with a filter, use 'pods_pfat_auto_pods'; * * @param array $auto_pods Array of parameters to use instead of those from settings. * * @return array Settings arrays for each post type. * * @since 2.4.5 */ $auto_pods = apply_filters( 'pods_pfat_auto_pods_override', null ); if ( ! is_null( $auto_pods ) ) { return $auto_pods; } // try to get cached results of this method $key = '_pods_pfat_auto_pods'; $auto_pods = pods_transient_get( $key ); // check if we already have the results cached & use it if we can. if ( $auto_pods === false ) { // get possible pods $the_pods = $this->the_pods(); // start output array empty $auto_pods = array(); // get pods api class $api = pods_api(); // loop through each to see if auto templates is enabled foreach ( $the_pods as $the_pod => $the_pod_label ) { // get this Pods' data. $pod_data = $api->load_pod( array( 'name' => $the_pod ) ); // if auto template is enabled add info about Pod to array if ( 1 == pods_v( 'pfat_enable', $pod_data['options'] ) ) { // check if pfat_single and pfat_archive are set $single = pods_v( 'pfat_single', $pod_data['options'], false, true ); $archive = pods_v( 'pfat_archive', $pod_data['options'], false, true ); $single_append = pods_v( 'pfat_append_single', $pod_data['options'], true, true ); $archive_append = pods_v( 'pfat_append_archive', $pod_data['options'], true, true ); $single_filter = pods_v( 'pfat_filter_single', $pod_data['options'], 'the_content', true ); $archive_filter = pods_v( 'pfat_filter_archive', $pod_data['options'], 'the_content', true ); $run_outside_loop = pods_v( 'pfat_run_outside_loop', $pod_data['options'], false, true ); $type = pods_v( 'type', $pod_data, false, true ); // check if it's a post type that has an archive if ( $type === 'post_type' && $the_pod !== 'post' || $the_pod !== 'page' ) { $has_archive = pods_v( 'has_archive', $pod_data['options'], false, true ); } else { $has_archive = true; } if ( empty( $single_filter ) ) { $single_filter = 'the_content'; } if ( empty( $archive_filter ) ) { $archive_filter = 'the_content'; } // build output array $auto_pods[ $the_pod ] = array( 'name' => $the_pod, 'label' => $the_pod_label, 'single' => $single, 'archive' => $archive, 'single_append' => $single_append, 'archive_append' => $archive_append, 'has_archive' => $has_archive, 'single_filter' => $single_filter, 'archive_filter' => $archive_filter, 'run_outside_loop' => $run_outside_loop, 'type' => $type, ); }//end if }//end foreach // cache the results pods_transient_set( $key, $auto_pods ); }//end if /** * Add to or change settings. * * Use this filter to change or add to the settings set in the back-end for this plugin. Has no effect if 'pods_pfat_auto_pods_override' filter is being used. * * @param array $auto_pods Array of parameters to use instead of those from settings. * * @return array Settings arrays for each post type. * * @since 2.4.5 */ $auto_pods = apply_filters( 'pods_pfat_auto_pods', $auto_pods ); return $auto_pods; }
[ "public", "function", "auto_pods", "(", ")", "{", "/**\n\t\t * Filter to override all settings for which templates are used.\n\t\t *\n\t\t * Note: If this filter does not return null, all back-end settings are ignored. To add to settings with a filter, use 'pods_pfat_auto_pods';\n\t\t *\n\t\t * @param a...
Get all Pods with auto template enable and its settings @return array With info about auto template settings per post type @since 2.4.5
[ "Get", "all", "Pods", "with", "auto", "template", "enable", "and", "its", "settings" ]
fd9a07c5c81ccbfcb21c5a0b2166f96c31d0826c
https://github.com/pods-framework/pods/blob/fd9a07c5c81ccbfcb21c5a0b2166f96c31d0826c/components/Templates/includes/auto-template/Pods_Templates_Auto_Template_Front_End.php#L131-L231
train
pods-framework/pods
components/Templates/includes/auto-template/Pods_Templates_Auto_Template_Front_End.php
Pods_Templates_Auto_Template_Front_End.current_post_type
public function current_post_type() { // start by getting current post or stdClass object global $wp_query; $obj = $wp_query->get_queried_object(); // see if we are on a post type and if so, set $current_post_type to post type if ( isset( $obj->post_type ) ) { $current_post_type = $obj->post_type; } elseif ( isset( $obj->taxonomy ) ) { $current_post_type = $obj->taxonomy; } elseif ( isset( $obj->name ) ) { $current_post_type = $obj->name; } elseif ( is_home() ) { $current_post_type = 'post'; } else { $current_post_type = false; } return $current_post_type; }
php
public function current_post_type() { // start by getting current post or stdClass object global $wp_query; $obj = $wp_query->get_queried_object(); // see if we are on a post type and if so, set $current_post_type to post type if ( isset( $obj->post_type ) ) { $current_post_type = $obj->post_type; } elseif ( isset( $obj->taxonomy ) ) { $current_post_type = $obj->taxonomy; } elseif ( isset( $obj->name ) ) { $current_post_type = $obj->name; } elseif ( is_home() ) { $current_post_type = 'post'; } else { $current_post_type = false; } return $current_post_type; }
[ "public", "function", "current_post_type", "(", ")", "{", "// start by getting current post or stdClass object", "global", "$", "wp_query", ";", "$", "obj", "=", "$", "wp_query", "->", "get_queried_object", "(", ")", ";", "// see if we are on a post type and if so, set $cur...
Fetches the current post type. @return string current post type. @since 2.4.5
[ "Fetches", "the", "current", "post", "type", "." ]
fd9a07c5c81ccbfcb21c5a0b2166f96c31d0826c
https://github.com/pods-framework/pods/blob/fd9a07c5c81ccbfcb21c5a0b2166f96c31d0826c/components/Templates/includes/auto-template/Pods_Templates_Auto_Template_Front_End.php#L240-L261
train
pods-framework/pods
components/Templates/includes/auto-template/Pods_Templates_Auto_Template_Front_End.php
Pods_Templates_Auto_Template_Front_End.front
public function front( $content ) { // get the current post type $current_post_type = $this->current_post_type(); // now use other methods in class to build array to search in/ use $possible_pods = $this->auto_pods(); // check if $current_post_type is the key of the array of possible pods if ( isset( $possible_pods[ $current_post_type ] ) ) { // get array for the current post type $this_pod = $possible_pods[ $current_post_type ]; $filter = $this->get_pod_filter( $current_post_type, $possible_pods ); if ( current_filter() !== $filter ) { return $content; } if ( ! in_the_loop() && ! pods_v( 'run_outside_loop', $this_pod, false ) ) { // If outside of the loop, exit quickly return $content; } // build Pods object for current item global $post; $pods = pods( $current_post_type, $post->ID ); if ( $this_pod['single'] && is_singular( $current_post_type ) ) { // load the template $content = $this->load_template( $this_pod['single'], $content, $pods, $this_pod['single_append'] ); } //end if // check if we are on an archive of the post type elseif ( $this_pod['archive'] && is_post_type_archive( $current_post_type ) ) { // load the template $content = $this->load_template( $this_pod['archive'], $content, $pods, $this_pod['archive_append'] ); } elseif ( is_home() && $this_pod['archive'] && $current_post_type === 'post' ) { // if pfat_archive was set and we're in the blog index, try to append template // append the template $content = $this->load_template( $this_pod['archive'], $content, $pods, $this_pod['archive_append'] ); } elseif ( is_tax( $current_post_type ) ) { // if is taxonomy archive of the selected taxonomy // if pfat_single was set try to use that template if ( $this_pod['archive'] ) { // append the template $content = $this->load_template( $this_pod['archive'], $content, $pods, $this_pod['archive_append'] ); } } }//end if return $content; }
php
public function front( $content ) { // get the current post type $current_post_type = $this->current_post_type(); // now use other methods in class to build array to search in/ use $possible_pods = $this->auto_pods(); // check if $current_post_type is the key of the array of possible pods if ( isset( $possible_pods[ $current_post_type ] ) ) { // get array for the current post type $this_pod = $possible_pods[ $current_post_type ]; $filter = $this->get_pod_filter( $current_post_type, $possible_pods ); if ( current_filter() !== $filter ) { return $content; } if ( ! in_the_loop() && ! pods_v( 'run_outside_loop', $this_pod, false ) ) { // If outside of the loop, exit quickly return $content; } // build Pods object for current item global $post; $pods = pods( $current_post_type, $post->ID ); if ( $this_pod['single'] && is_singular( $current_post_type ) ) { // load the template $content = $this->load_template( $this_pod['single'], $content, $pods, $this_pod['single_append'] ); } //end if // check if we are on an archive of the post type elseif ( $this_pod['archive'] && is_post_type_archive( $current_post_type ) ) { // load the template $content = $this->load_template( $this_pod['archive'], $content, $pods, $this_pod['archive_append'] ); } elseif ( is_home() && $this_pod['archive'] && $current_post_type === 'post' ) { // if pfat_archive was set and we're in the blog index, try to append template // append the template $content = $this->load_template( $this_pod['archive'], $content, $pods, $this_pod['archive_append'] ); } elseif ( is_tax( $current_post_type ) ) { // if is taxonomy archive of the selected taxonomy // if pfat_single was set try to use that template if ( $this_pod['archive'] ) { // append the template $content = $this->load_template( $this_pod['archive'], $content, $pods, $this_pod['archive_append'] ); } } }//end if return $content; }
[ "public", "function", "front", "(", "$", "content", ")", "{", "// get the current post type", "$", "current_post_type", "=", "$", "this", "->", "current_post_type", "(", ")", ";", "// now use other methods in class to build array to search in/ use", "$", "possible_pods", ...
Outputs templates after the content as needed. @param string $content Post content @uses 'the_content' filter @return string Post content with the template appended if appropriate. @since 2.4.5
[ "Outputs", "templates", "after", "the", "content", "as", "needed", "." ]
fd9a07c5c81ccbfcb21c5a0b2166f96c31d0826c
https://github.com/pods-framework/pods/blob/fd9a07c5c81ccbfcb21c5a0b2166f96c31d0826c/components/Templates/includes/auto-template/Pods_Templates_Auto_Template_Front_End.php#L274-L328
train
pods-framework/pods
components/Templates/includes/auto-template/Pods_Templates_Auto_Template_Front_End.php
Pods_Templates_Auto_Template_Front_End.set_frontier_style_script
public function set_frontier_style_script() { if ( ! class_exists( 'Pods_Frontier' ) ) { return; } // cet the current post type $current_post_type = $this->current_post_type(); // now use other methods in class to build array to search in/ use $possible_pods = $this->auto_pods(); if ( isset( $possible_pods[ $current_post_type ] ) ) { $this_pod = $possible_pods[ $current_post_type ]; if ( $this_pod['single'] && is_singular( $current_post_type ) ) { // set template $template = $this_pod['single']; } elseif ( $this_pod['archive'] && is_post_type_archive( $current_post_type ) ) { // if pfat_archive was set try to use that template // check if we are on an archive of the post type // set template $template = $this_pod['archive']; } elseif ( is_home() && $this_pod['archive'] && $current_post_type === 'post' ) { // if pfat_archive was set and we're in the blog index, try to append template // set template $template = $this_pod['archive']; } elseif ( is_tax( $current_post_type ) ) { // if is taxonomy archive of the selected taxonomy // if pfat_single was set try to use that template if ( $this_pod['archive'] ) { // set template $template = $this_pod['archive']; } }//end if if ( isset( $template ) ) { global $frontier_styles, $frontier_scripts; $template_post = pods()->api->load_template( array( 'name' => $template ) ); if ( ! empty( $template_post['id'] ) ) { // got a template - check for styles & scripts $meta = get_post_meta( $template_post['id'], 'view_template', true ); $frontier = new Pods_Frontier(); if ( ! empty( $meta['css'] ) ) { $frontier_styles .= $meta['css']; } if ( ! empty( $meta['js'] ) ) { $frontier_scripts .= $meta['js']; } } } }//end if }
php
public function set_frontier_style_script() { if ( ! class_exists( 'Pods_Frontier' ) ) { return; } // cet the current post type $current_post_type = $this->current_post_type(); // now use other methods in class to build array to search in/ use $possible_pods = $this->auto_pods(); if ( isset( $possible_pods[ $current_post_type ] ) ) { $this_pod = $possible_pods[ $current_post_type ]; if ( $this_pod['single'] && is_singular( $current_post_type ) ) { // set template $template = $this_pod['single']; } elseif ( $this_pod['archive'] && is_post_type_archive( $current_post_type ) ) { // if pfat_archive was set try to use that template // check if we are on an archive of the post type // set template $template = $this_pod['archive']; } elseif ( is_home() && $this_pod['archive'] && $current_post_type === 'post' ) { // if pfat_archive was set and we're in the blog index, try to append template // set template $template = $this_pod['archive']; } elseif ( is_tax( $current_post_type ) ) { // if is taxonomy archive of the selected taxonomy // if pfat_single was set try to use that template if ( $this_pod['archive'] ) { // set template $template = $this_pod['archive']; } }//end if if ( isset( $template ) ) { global $frontier_styles, $frontier_scripts; $template_post = pods()->api->load_template( array( 'name' => $template ) ); if ( ! empty( $template_post['id'] ) ) { // got a template - check for styles & scripts $meta = get_post_meta( $template_post['id'], 'view_template', true ); $frontier = new Pods_Frontier(); if ( ! empty( $meta['css'] ) ) { $frontier_styles .= $meta['css']; } if ( ! empty( $meta['js'] ) ) { $frontier_scripts .= $meta['js']; } } } }//end if }
[ "public", "function", "set_frontier_style_script", "(", ")", "{", "if", "(", "!", "class_exists", "(", "'Pods_Frontier'", ")", ")", "{", "return", ";", "}", "// cet the current post type", "$", "current_post_type", "=", "$", "this", "->", "current_post_type", "(",...
Sets Styles and Scripts from the Frontier template addons. @since 2.4.5
[ "Sets", "Styles", "and", "Scripts", "from", "the", "Frontier", "template", "addons", "." ]
fd9a07c5c81ccbfcb21c5a0b2166f96c31d0826c
https://github.com/pods-framework/pods/blob/fd9a07c5c81ccbfcb21c5a0b2166f96c31d0826c/components/Templates/includes/auto-template/Pods_Templates_Auto_Template_Front_End.php#L385-L444
train
pods-framework/pods
classes/Pods.php
Pods.valid
public function valid() { if ( empty( $this->pod_id ) ) { return false; } if ( $this->iterator ) { return isset( $this->rows[ $this->row_number ] ); } return true; }
php
public function valid() { if ( empty( $this->pod_id ) ) { return false; } if ( $this->iterator ) { return isset( $this->rows[ $this->row_number ] ); } return true; }
[ "public", "function", "valid", "(", ")", "{", "if", "(", "empty", "(", "$", "this", "->", "pod_id", ")", ")", "{", "return", "false", ";", "}", "if", "(", "$", "this", "->", "iterator", ")", "{", "return", "isset", "(", "$", "this", "->", "rows",...
Whether this Pod object is valid or not @return bool @since 2.0.0
[ "Whether", "this", "Pod", "object", "is", "valid", "or", "not" ]
fd9a07c5c81ccbfcb21c5a0b2166f96c31d0826c
https://github.com/pods-framework/pods/blob/fd9a07c5c81ccbfcb21c5a0b2166f96c31d0826c/classes/Pods.php#L396-L407
train
pods-framework/pods
classes/Pods.php
Pods.input
public function input( $field, $input_name = null, $value = '__null' ) { if ( is_array( $field ) ) { // Field data override. $field_data = $field; $field = pods_v( 'name', $field ); } else { // Get field data from field name. $field_data = $this->fields( $field ); } if ( ! empty( $field_data ) ) { $field_type = pods_v( 'type', $field_data ); if ( empty( $input_name ) ) { $input_name = $field; } if ( '__null' === $value ) { $value = $this->field( array( 'name' => $field, 'in_form' => true, ) ); } return PodsForm::field( $input_name, $value, $field_type, $field_data, $this, $this->id() ); } return ''; }
php
public function input( $field, $input_name = null, $value = '__null' ) { if ( is_array( $field ) ) { // Field data override. $field_data = $field; $field = pods_v( 'name', $field ); } else { // Get field data from field name. $field_data = $this->fields( $field ); } if ( ! empty( $field_data ) ) { $field_type = pods_v( 'type', $field_data ); if ( empty( $input_name ) ) { $input_name = $field; } if ( '__null' === $value ) { $value = $this->field( array( 'name' => $field, 'in_form' => true, ) ); } return PodsForm::field( $input_name, $value, $field_type, $field_data, $this, $this->id() ); } return ''; }
[ "public", "function", "input", "(", "$", "field", ",", "$", "input_name", "=", "null", ",", "$", "value", "=", "'__null'", ")", "{", "if", "(", "is_array", "(", "$", "field", ")", ")", "{", "// Field data override.", "$", "field_data", "=", "$", "field...
Return a field input for a specific field @param string|array $field Field name or Field data array. @param string|array|null $input_name Input field name to use (overrides default name). @param mixed $value Current value to use. @return string Field Input HTML @since 2.3.10
[ "Return", "a", "field", "input", "for", "a", "specific", "field" ]
fd9a07c5c81ccbfcb21c5a0b2166f96c31d0826c
https://github.com/pods-framework/pods/blob/fd9a07c5c81ccbfcb21c5a0b2166f96c31d0826c/classes/Pods.php#L549-L580
train
pods-framework/pods
classes/Pods.php
Pods.fields
public function fields( $field = null, $option = null ) { $field_data = null; if ( empty( $this->fields ) ) { // No fields found. $field_data = array(); } elseif ( empty( $field ) ) { // Return all fields. $field_data = (array) $this->fields; } elseif ( ! isset( $this->fields[ $field ] ) && ! isset( $this->pod_data['object_fields'][ $field ] ) ) { // Field not found. $field_data = array(); } elseif ( empty( $option ) ) { // Return all field data. if ( isset( $this->fields[ $field ] ) ) { $field_data = $this->fields[ $field ]; } elseif ( isset( $this->pod_data['object_fields'] ) ) { $field_data = $this->pod_data['object_fields'][ $field ]; } } else { $options = array(); // Merge options. if ( isset( $this->fields[ $field ] ) ) { $options = array_merge( $this->fields[ $field ], $this->fields[ $field ]['options'] ); } elseif ( isset( $this->pod_data['object_fields'] ) ) { $options = array_merge( $this->pod_data['object_fields'][ $field ], $this->pod_data['object_fields'][ $field ]['options'] ); } if ( 'data' === $option && in_array( pods_v( 'type', $options ), PodsForm::tableless_field_types(), true ) ) { // Get a list of available items from a relationship field. $field_data = PodsForm::field_method( 'pick', 'get_field_data', $options ); } elseif ( isset( $options[ $option ] ) ) { // Return option. $field_data = $options[ $option ]; } }//end if /** * Modify the field data before returning * * @since unknown * * @param array $field_data The data for the field. * @param string|null $field The specific field that data is being return for, if set when method is called or null. * @param string|null $option Value of option param when method was called. Can be used to get a list of available items from a relationship field. * @param Pods|object $this The current Pods class instance. */ return apply_filters( 'pods_pods_fields', $field_data, $field, $option, $this ); }
php
public function fields( $field = null, $option = null ) { $field_data = null; if ( empty( $this->fields ) ) { // No fields found. $field_data = array(); } elseif ( empty( $field ) ) { // Return all fields. $field_data = (array) $this->fields; } elseif ( ! isset( $this->fields[ $field ] ) && ! isset( $this->pod_data['object_fields'][ $field ] ) ) { // Field not found. $field_data = array(); } elseif ( empty( $option ) ) { // Return all field data. if ( isset( $this->fields[ $field ] ) ) { $field_data = $this->fields[ $field ]; } elseif ( isset( $this->pod_data['object_fields'] ) ) { $field_data = $this->pod_data['object_fields'][ $field ]; } } else { $options = array(); // Merge options. if ( isset( $this->fields[ $field ] ) ) { $options = array_merge( $this->fields[ $field ], $this->fields[ $field ]['options'] ); } elseif ( isset( $this->pod_data['object_fields'] ) ) { $options = array_merge( $this->pod_data['object_fields'][ $field ], $this->pod_data['object_fields'][ $field ]['options'] ); } if ( 'data' === $option && in_array( pods_v( 'type', $options ), PodsForm::tableless_field_types(), true ) ) { // Get a list of available items from a relationship field. $field_data = PodsForm::field_method( 'pick', 'get_field_data', $options ); } elseif ( isset( $options[ $option ] ) ) { // Return option. $field_data = $options[ $option ]; } }//end if /** * Modify the field data before returning * * @since unknown * * @param array $field_data The data for the field. * @param string|null $field The specific field that data is being return for, if set when method is called or null. * @param string|null $option Value of option param when method was called. Can be used to get a list of available items from a relationship field. * @param Pods|object $this The current Pods class instance. */ return apply_filters( 'pods_pods_fields', $field_data, $field, $option, $this ); }
[ "public", "function", "fields", "(", "$", "field", "=", "null", ",", "$", "option", "=", "null", ")", "{", "$", "field_data", "=", "null", ";", "if", "(", "empty", "(", "$", "this", "->", "fields", ")", ")", "{", "// No fields found.", "$", "field_da...
Return field array from a Pod, a field's data, or a field option @param null $field Field name. @param null $option Option name. @return bool|mixed @since 2.0.0
[ "Return", "field", "array", "from", "a", "Pod", "a", "field", "s", "data", "or", "a", "field", "option" ]
fd9a07c5c81ccbfcb21c5a0b2166f96c31d0826c
https://github.com/pods-framework/pods/blob/fd9a07c5c81ccbfcb21c5a0b2166f96c31d0826c/classes/Pods.php#L592-L643
train
pods-framework/pods
classes/Pods.php
Pods.has
public function has( $field, $value, $id = null ) { $pod =& $this; if ( null === $id ) { $id = $this->id(); // @codingStandardsIgnoreLine. } elseif ( $id != $this->id() ) { $pod = pods( $this->pod, $id ); } $this->do_hook( 'has', $field, $value, $id ); if ( ! isset( $this->fields[ $field ] ) ) { return false; } // Tableless fields. if ( in_array( $this->fields[ $field ]['type'], PodsForm::tableless_field_types(), true ) ) { if ( ! is_array( $value ) ) { $value = explode( ',', $value ); } if ( 'pick' === $this->fields[ $field ]['type'] && in_array( $this->fields[ $field ]['pick_object'], PodsForm::simple_tableless_objects(), true ) ) { $current_value = $pod->raw( $field ); if ( ! empty( $current_value ) ) { $current_value = (array) $current_value; } foreach ( $current_value as $v ) { // @codingStandardsIgnoreLine. if ( in_array( $v, $value ) ) { return true; } } } else { $related_ids = $this->api->lookup_related_items( $this->fields[ $field ]['id'], $this->pod_data['id'], $id, $this->fields[ $field ], $this->pod_data ); foreach ( $value as $k => $v ) { if ( ! preg_match( '/[^\D]/', $v ) ) { $value[ $k ] = (int) $v; } // @todo Convert slugs into IDs. } foreach ( $related_ids as $v ) { // @codingStandardsIgnoreLine. if ( in_array( $v, $value ) ) { return true; } } }//end if } elseif ( in_array( $this->fields[ $field ]['type'], PodsForm::text_field_types(), true ) ) { // Text fields. $current_value = $pod->raw( $field ); if ( 0 < strlen( $current_value ) ) { return stripos( $current_value, $value ); } } else { // All other fields. return $this->is( $field, $value, $id ); }//end if return false; }
php
public function has( $field, $value, $id = null ) { $pod =& $this; if ( null === $id ) { $id = $this->id(); // @codingStandardsIgnoreLine. } elseif ( $id != $this->id() ) { $pod = pods( $this->pod, $id ); } $this->do_hook( 'has', $field, $value, $id ); if ( ! isset( $this->fields[ $field ] ) ) { return false; } // Tableless fields. if ( in_array( $this->fields[ $field ]['type'], PodsForm::tableless_field_types(), true ) ) { if ( ! is_array( $value ) ) { $value = explode( ',', $value ); } if ( 'pick' === $this->fields[ $field ]['type'] && in_array( $this->fields[ $field ]['pick_object'], PodsForm::simple_tableless_objects(), true ) ) { $current_value = $pod->raw( $field ); if ( ! empty( $current_value ) ) { $current_value = (array) $current_value; } foreach ( $current_value as $v ) { // @codingStandardsIgnoreLine. if ( in_array( $v, $value ) ) { return true; } } } else { $related_ids = $this->api->lookup_related_items( $this->fields[ $field ]['id'], $this->pod_data['id'], $id, $this->fields[ $field ], $this->pod_data ); foreach ( $value as $k => $v ) { if ( ! preg_match( '/[^\D]/', $v ) ) { $value[ $k ] = (int) $v; } // @todo Convert slugs into IDs. } foreach ( $related_ids as $v ) { // @codingStandardsIgnoreLine. if ( in_array( $v, $value ) ) { return true; } } }//end if } elseif ( in_array( $this->fields[ $field ]['type'], PodsForm::text_field_types(), true ) ) { // Text fields. $current_value = $pod->raw( $field ); if ( 0 < strlen( $current_value ) ) { return stripos( $current_value, $value ); } } else { // All other fields. return $this->is( $field, $value, $id ); }//end if return false; }
[ "public", "function", "has", "(", "$", "field", ",", "$", "value", ",", "$", "id", "=", "null", ")", "{", "$", "pod", "=", "&", "$", "this", ";", "if", "(", "null", "===", "$", "id", ")", "{", "$", "id", "=", "$", "this", "->", "id", "(", ...
Check if an item field has a specific value in it @param string $field Field name. @param mixed $value Value to check. @param int $id (optional) ID of the pod item to check. @return bool Whether the value was found @since 2.3.3
[ "Check", "if", "an", "item", "field", "has", "a", "specific", "value", "in", "it" ]
fd9a07c5c81ccbfcb21c5a0b2166f96c31d0826c
https://github.com/pods-framework/pods/blob/fd9a07c5c81ccbfcb21c5a0b2166f96c31d0826c/classes/Pods.php#L1955-L2022
train
pods-framework/pods
classes/Pods.php
Pods.id
public function id() { if ( isset( $this->data->row, $this->data->row['id'] ) ) { // If we already have data loaded return that ID. return $this->data->row['id']; } return $this->field( $this->data->field_id ); }
php
public function id() { if ( isset( $this->data->row, $this->data->row['id'] ) ) { // If we already have data loaded return that ID. return $this->data->row['id']; } return $this->field( $this->data->field_id ); }
[ "public", "function", "id", "(", ")", "{", "if", "(", "isset", "(", "$", "this", "->", "data", "->", "row", ",", "$", "this", "->", "data", "->", "row", "[", "'id'", "]", ")", ")", "{", "// If we already have data loaded return that ID.", "return", "$", ...
Return the item ID @return int @since 2.0.0
[ "Return", "the", "item", "ID" ]
fd9a07c5c81ccbfcb21c5a0b2166f96c31d0826c
https://github.com/pods-framework/pods/blob/fd9a07c5c81ccbfcb21c5a0b2166f96c31d0826c/classes/Pods.php#L2153-L2161
train
pods-framework/pods
classes/Pods.php
Pods.next_id
public function next_id( $id = null, $params_override = null ) { if ( null === $id ) { $id = $this->id(); } $id = (int) $id; $params = array( 'select' => "`t`.`{$this->data->field_id}`", 'where' => "{$id} < `t`.`{$this->data->field_id}`", 'orderby' => "`t`.`{$this->data->field_id}` ASC", 'limit' => 1, ); if ( ! empty( $params_override ) || ! empty( $this->params ) ) { if ( ! empty( $params_override ) ) { $params = $params_override; } elseif ( ! empty( $this->params ) ) { $params = $this->params; } if ( is_object( $params ) ) { $params = get_object_vars( $params ); } if ( 0 < $id ) { if ( isset( $params['where'] ) && ! empty( $params['where'] ) ) { $params['where'] = (array) $params['where']; $params['where'][] = "{$id} < `t`.`{$this->data->field_id}`"; } else { $params['where'] = "{$id} < `t`.`{$this->data->field_id}`"; } } elseif ( ! isset( $params['offset'] ) ) { if ( ! empty( $this->params ) && - 1 < $this->row_number ) { $params['offset'] = $this->row_number + 1; } else { $params['offset'] = 1; } } else { $params['offset'] ++; } $params['select'] = "`t`.`{$this->data->field_id}`"; $params['limit'] = 1; }//end if $pod = pods( $this->pod, $params ); $new_id = 0; if ( $pod->fetch() ) { $new_id = $pod->id(); } $new_id = $this->do_hook( 'next_id', $new_id, $id, $pod, $params_override ); return $new_id; }
php
public function next_id( $id = null, $params_override = null ) { if ( null === $id ) { $id = $this->id(); } $id = (int) $id; $params = array( 'select' => "`t`.`{$this->data->field_id}`", 'where' => "{$id} < `t`.`{$this->data->field_id}`", 'orderby' => "`t`.`{$this->data->field_id}` ASC", 'limit' => 1, ); if ( ! empty( $params_override ) || ! empty( $this->params ) ) { if ( ! empty( $params_override ) ) { $params = $params_override; } elseif ( ! empty( $this->params ) ) { $params = $this->params; } if ( is_object( $params ) ) { $params = get_object_vars( $params ); } if ( 0 < $id ) { if ( isset( $params['where'] ) && ! empty( $params['where'] ) ) { $params['where'] = (array) $params['where']; $params['where'][] = "{$id} < `t`.`{$this->data->field_id}`"; } else { $params['where'] = "{$id} < `t`.`{$this->data->field_id}`"; } } elseif ( ! isset( $params['offset'] ) ) { if ( ! empty( $this->params ) && - 1 < $this->row_number ) { $params['offset'] = $this->row_number + 1; } else { $params['offset'] = 1; } } else { $params['offset'] ++; } $params['select'] = "`t`.`{$this->data->field_id}`"; $params['limit'] = 1; }//end if $pod = pods( $this->pod, $params ); $new_id = 0; if ( $pod->fetch() ) { $new_id = $pod->id(); } $new_id = $this->do_hook( 'next_id', $new_id, $id, $pod, $params_override ); return $new_id; }
[ "public", "function", "next_id", "(", "$", "id", "=", "null", ",", "$", "params_override", "=", "null", ")", "{", "if", "(", "null", "===", "$", "id", ")", "{", "$", "id", "=", "$", "this", "->", "id", "(", ")", ";", "}", "$", "id", "=", "(",...
Return the next item ID, loops at the first id to return the last @param int|null $id ID to start from. @param array|object|null $params_override Override the find() parameters. @return int @since 2.0.0
[ "Return", "the", "next", "item", "ID", "loops", "at", "the", "first", "id", "to", "return", "the", "last" ]
fd9a07c5c81ccbfcb21c5a0b2166f96c31d0826c
https://github.com/pods-framework/pods/blob/fd9a07c5c81ccbfcb21c5a0b2166f96c31d0826c/classes/Pods.php#L2261-L2319
train
pods-framework/pods
classes/Pods.php
Pods.first_id
public function first_id( $params_override = null ) { $params = array( 'select' => "`t`.`{$this->data->field_id}`", 'orderby' => "`t`.`{$this->data->field_id}` ASC", 'limit' => 1, ); if ( ! empty( $params_override ) || ! empty( $this->params ) ) { if ( ! empty( $params_override ) ) { $params = $params_override; } elseif ( ! empty( $this->params ) ) { $params = $this->params; } if ( is_object( $params ) ) { $params = get_object_vars( $params ); } $params['select'] = "`t`.`{$this->data->field_id}`"; $params['offset'] = 0; $params['limit'] = 1; } $pod = pods( $this->pod, $params ); $new_id = 0; if ( $pod->fetch() ) { $new_id = $pod->id(); } $new_id = $this->do_hook( 'first_id', $new_id, $pod, $params_override ); return $new_id; }
php
public function first_id( $params_override = null ) { $params = array( 'select' => "`t`.`{$this->data->field_id}`", 'orderby' => "`t`.`{$this->data->field_id}` ASC", 'limit' => 1, ); if ( ! empty( $params_override ) || ! empty( $this->params ) ) { if ( ! empty( $params_override ) ) { $params = $params_override; } elseif ( ! empty( $this->params ) ) { $params = $this->params; } if ( is_object( $params ) ) { $params = get_object_vars( $params ); } $params['select'] = "`t`.`{$this->data->field_id}`"; $params['offset'] = 0; $params['limit'] = 1; } $pod = pods( $this->pod, $params ); $new_id = 0; if ( $pod->fetch() ) { $new_id = $pod->id(); } $new_id = $this->do_hook( 'first_id', $new_id, $pod, $params_override ); return $new_id; }
[ "public", "function", "first_id", "(", "$", "params_override", "=", "null", ")", "{", "$", "params", "=", "array", "(", "'select'", "=>", "\"`t`.`{$this->data->field_id}`\"", ",", "'orderby'", "=>", "\"`t`.`{$this->data->field_id}` ASC\"", ",", "'limit'", "=>", "1",...
Return the first item ID @param array|object|null $params_override Override the find() parameters. @return int @since 2.3.0
[ "Return", "the", "first", "item", "ID" ]
fd9a07c5c81ccbfcb21c5a0b2166f96c31d0826c
https://github.com/pods-framework/pods/blob/fd9a07c5c81ccbfcb21c5a0b2166f96c31d0826c/classes/Pods.php#L2329-L2364
train
pods-framework/pods
classes/Pods.php
Pods.add
public function add( $data = null, $value = null ) { if ( null !== $value ) { $data = array( $data => $value ); } $data = (array) $this->do_hook( 'add', $data ); if ( empty( $data ) ) { return 0; } $params = array( 'pod' => $this->pod, 'data' => $data, 'allow_custom_fields' => true, ); return $this->api->save_pod_item( $params ); }
php
public function add( $data = null, $value = null ) { if ( null !== $value ) { $data = array( $data => $value ); } $data = (array) $this->do_hook( 'add', $data ); if ( empty( $data ) ) { return 0; } $params = array( 'pod' => $this->pod, 'data' => $data, 'allow_custom_fields' => true, ); return $this->api->save_pod_item( $params ); }
[ "public", "function", "add", "(", "$", "data", "=", "null", ",", "$", "value", "=", "null", ")", "{", "if", "(", "null", "!==", "$", "value", ")", "{", "$", "data", "=", "array", "(", "$", "data", "=>", "$", "value", ")", ";", "}", "$", "data...
Add an item to a Pod by giving an array of field data or set a specific field to a specific value if you're just wanting to add a new item but only set one field. You may be looking for save() in most cases where you're setting a specific field. @see PodsAPI::save_pod_item @param array|string $data Either an associative array of field information or a field name. @param mixed $value (optional) Value of the field, if $data is a field name. @return int The item ID @since 2.0.0 @link https://pods.io/docs/add/
[ "Add", "an", "item", "to", "a", "Pod", "by", "giving", "an", "array", "of", "field", "data", "or", "set", "a", "specific", "field", "to", "a", "specific", "value", "if", "you", "re", "just", "wanting", "to", "add", "a", "new", "item", "but", "only", ...
fd9a07c5c81ccbfcb21c5a0b2166f96c31d0826c
https://github.com/pods-framework/pods/blob/fd9a07c5c81ccbfcb21c5a0b2166f96c31d0826c/classes/Pods.php#L2901-L2920
train
pods-framework/pods
classes/Pods.php
Pods.save
public function save( $data = null, $value = null, $id = null, $params = null ) { if ( null !== $data && ! is_array( $data ) ) { $data = array( $data => $value ); } $fetch = false; // @codingStandardsIgnoreLine if ( null === $id || ( $this->row && $id == $this->id() ) ) { $fetch = true; if ( null === $id ) { $id = $this->id(); } } $data = (array) $this->do_hook( 'save', $data, $id ); if ( empty( $data ) && empty( $params['is_new_item'] ) ) { return $id; } $default = array(); if ( ! empty( $params ) && is_array( $params ) ) { $default = $params; } $params = array( 'pod' => $this->pod, 'id' => $id, 'data' => $data, 'allow_custom_fields' => true, 'clear_slug_cache' => false, ); if ( ! empty( $default ) ) { $params = array_merge( $params, $default ); } $id = $this->api->save_pod_item( $params ); if ( 0 < $id && $fetch ) { // Clear local var cache of field values. $this->data->row = array(); $this->fetch( $id, false ); } if ( ! empty( $this->pod_data['field_slug'] ) ) { if ( 0 < $id && $fetch ) { $slug = $this->field( $this->pod_data['field_slug'] ); } else { $slug = pods( $this->pod, $id )->field( $this->pod_data['field_slug'] ); } if ( 0 < strlen( $slug ) ) { pods_cache_clear( $slug, 'pods_items_' . $this->pod ); } } return $id; }
php
public function save( $data = null, $value = null, $id = null, $params = null ) { if ( null !== $data && ! is_array( $data ) ) { $data = array( $data => $value ); } $fetch = false; // @codingStandardsIgnoreLine if ( null === $id || ( $this->row && $id == $this->id() ) ) { $fetch = true; if ( null === $id ) { $id = $this->id(); } } $data = (array) $this->do_hook( 'save', $data, $id ); if ( empty( $data ) && empty( $params['is_new_item'] ) ) { return $id; } $default = array(); if ( ! empty( $params ) && is_array( $params ) ) { $default = $params; } $params = array( 'pod' => $this->pod, 'id' => $id, 'data' => $data, 'allow_custom_fields' => true, 'clear_slug_cache' => false, ); if ( ! empty( $default ) ) { $params = array_merge( $params, $default ); } $id = $this->api->save_pod_item( $params ); if ( 0 < $id && $fetch ) { // Clear local var cache of field values. $this->data->row = array(); $this->fetch( $id, false ); } if ( ! empty( $this->pod_data['field_slug'] ) ) { if ( 0 < $id && $fetch ) { $slug = $this->field( $this->pod_data['field_slug'] ); } else { $slug = pods( $this->pod, $id )->field( $this->pod_data['field_slug'] ); } if ( 0 < strlen( $slug ) ) { pods_cache_clear( $slug, 'pods_items_' . $this->pod ); } } return $id; }
[ "public", "function", "save", "(", "$", "data", "=", "null", ",", "$", "value", "=", "null", ",", "$", "id", "=", "null", ",", "$", "params", "=", "null", ")", "{", "if", "(", "null", "!==", "$", "data", "&&", "!", "is_array", "(", "$", "data",...
Save an item by giving an array of field data or set a specific field to a specific value. Though this function has the capacity to add new items, best practice should direct you to use add() for that instead. @see PodsAPI::save_pod_item @param array|string $data Either an associative array of field information or a field name. @param mixed $value (optional) Value of the field, if $data is a field name. @param int $id (optional) ID of the pod item to update. @param array $params (optional) Additional params to send to save_pod_item. @return int The item ID @since 2.0.0 @link https://pods.io/docs/save/
[ "Save", "an", "item", "by", "giving", "an", "array", "of", "field", "data", "or", "set", "a", "specific", "field", "to", "a", "specific", "value", "." ]
fd9a07c5c81ccbfcb21c5a0b2166f96c31d0826c
https://github.com/pods-framework/pods/blob/fd9a07c5c81ccbfcb21c5a0b2166f96c31d0826c/classes/Pods.php#L3194-L3257
train
pods-framework/pods
classes/Pods.php
Pods.duplicate
public function duplicate( $id = null ) { if ( null === $id ) { $id = $this->id(); } $id = (int) $this->do_hook( 'duplicate', $id ); if ( empty( $id ) ) { return false; } $params = array( 'pod' => $this->pod, 'id' => $id, ); return $this->api->duplicate_pod_item( $params ); }
php
public function duplicate( $id = null ) { if ( null === $id ) { $id = $this->id(); } $id = (int) $this->do_hook( 'duplicate', $id ); if ( empty( $id ) ) { return false; } $params = array( 'pod' => $this->pod, 'id' => $id, ); return $this->api->duplicate_pod_item( $params ); }
[ "public", "function", "duplicate", "(", "$", "id", "=", "null", ")", "{", "if", "(", "null", "===", "$", "id", ")", "{", "$", "id", "=", "$", "this", "->", "id", "(", ")", ";", "}", "$", "id", "=", "(", "int", ")", "$", "this", "->", "do_ho...
Duplicate an item @see PodsAPI::duplicate_pod_item @param int $id ID of the pod item to duplicate. @return int|bool ID of the new pod item @since 2.0.0 @link https://pods.io/docs/duplicate/
[ "Duplicate", "an", "item" ]
fd9a07c5c81ccbfcb21c5a0b2166f96c31d0826c
https://github.com/pods-framework/pods/blob/fd9a07c5c81ccbfcb21c5a0b2166f96c31d0826c/classes/Pods.php#L3326-L3344
train
pods-framework/pods
classes/Pods.php
Pods.export
public function export( $fields = null, $id = null, $format = null ) { $params = array( 'pod' => $this->pod, 'id' => $id, 'fields' => null, 'depth' => 2, 'flatten' => false, 'context' => null, 'format' => $format, ); if ( is_array( $fields ) && ( isset( $fields['fields'] ) || isset( $fields['depth'] ) ) ) { $params = array_merge( $params, $fields ); } else { $params['fields'] = $fields; } if ( isset( $params['fields'] ) && is_array( $params['fields'] ) && ! in_array( $this->pod_data['field_id'], $params['fields'], true ) ) { $params['fields'] = array_merge( array( $this->pod_data['field_id'] ), $params['fields'] ); } if ( null === $params['id'] ) { $params['id'] = $this->id(); } $params = (array) $this->do_hook( 'export', $params ); if ( empty( $params['id'] ) ) { return false; } $data = $this->api->export_pod_item( $params ); if ( ! empty( $params['format'] ) && 'json' === $params['format'] ) { $data = wp_json_encode( (array) $data ); } return $data; }
php
public function export( $fields = null, $id = null, $format = null ) { $params = array( 'pod' => $this->pod, 'id' => $id, 'fields' => null, 'depth' => 2, 'flatten' => false, 'context' => null, 'format' => $format, ); if ( is_array( $fields ) && ( isset( $fields['fields'] ) || isset( $fields['depth'] ) ) ) { $params = array_merge( $params, $fields ); } else { $params['fields'] = $fields; } if ( isset( $params['fields'] ) && is_array( $params['fields'] ) && ! in_array( $this->pod_data['field_id'], $params['fields'], true ) ) { $params['fields'] = array_merge( array( $this->pod_data['field_id'] ), $params['fields'] ); } if ( null === $params['id'] ) { $params['id'] = $this->id(); } $params = (array) $this->do_hook( 'export', $params ); if ( empty( $params['id'] ) ) { return false; } $data = $this->api->export_pod_item( $params ); if ( ! empty( $params['format'] ) && 'json' === $params['format'] ) { $data = wp_json_encode( (array) $data ); } return $data; }
[ "public", "function", "export", "(", "$", "fields", "=", "null", ",", "$", "id", "=", "null", ",", "$", "format", "=", "null", ")", "{", "$", "params", "=", "array", "(", "'pod'", "=>", "$", "this", "->", "pod", ",", "'id'", "=>", "$", "id", ",...
Export an item's data @see PodsAPI::export_pod_item @param array $fields (optional) Fields to export. @param int $id (optional) ID of the pod item to export. @param null|string $format (optional) The format of the export (php | json). @return array|bool Data array of the exported pod item @since 2.0.0 @link https://pods.io/docs/export/
[ "Export", "an", "item", "s", "data" ]
fd9a07c5c81ccbfcb21c5a0b2166f96c31d0826c
https://github.com/pods-framework/pods/blob/fd9a07c5c81ccbfcb21c5a0b2166f96c31d0826c/classes/Pods.php#L3378-L3417
train
pods-framework/pods
classes/Pods.php
Pods.export_data
public function export_data( $params = null ) { $defaults = array( 'fields' => null, 'depth' => 2, 'params' => null, ); if ( empty( $params ) ) { $params = $defaults; } else { $params = array_merge( $defaults, (array) $params ); } return $this->api->export( $this, $params ); }
php
public function export_data( $params = null ) { $defaults = array( 'fields' => null, 'depth' => 2, 'params' => null, ); if ( empty( $params ) ) { $params = $defaults; } else { $params = array_merge( $defaults, (array) $params ); } return $this->api->export( $this, $params ); }
[ "public", "function", "export_data", "(", "$", "params", "=", "null", ")", "{", "$", "defaults", "=", "array", "(", "'fields'", "=>", "null", ",", "'depth'", "=>", "2", ",", "'params'", "=>", "null", ",", ")", ";", "if", "(", "empty", "(", "$", "pa...
Export data from all items @see PodsAPI::export @param array $params An associative array of parameters. @return array Data arrays of all exported pod items @since 2.3.0
[ "Export", "data", "from", "all", "items" ]
fd9a07c5c81ccbfcb21c5a0b2166f96c31d0826c
https://github.com/pods-framework/pods/blob/fd9a07c5c81ccbfcb21c5a0b2166f96c31d0826c/classes/Pods.php#L3430-L3445
train
pods-framework/pods
classes/Pods.php
Pods.pagination
public function pagination( $params = null ) { if ( empty( $params ) ) { $params = array(); } elseif ( ! is_array( $params ) ) { $params = array( 'label' => $params ); } $this->page_var = pods_v( 'page_var', $params, $this->page_var ); $url = pods_query_arg( null, null, $this->page_var ); $append = '?'; if ( false !== strpos( $url, '?' ) ) { $append = '&'; } $defaults = array( 'type' => 'advanced', 'label' => __( 'Go to page:', 'pods' ), 'show_label' => true, 'first_text' => __( '&laquo; First', 'pods' ), 'prev_text' => __( '&lsaquo; Previous', 'pods' ), 'next_text' => __( 'Next &rsaquo;', 'pods' ), 'last_text' => __( 'Last &raquo;', 'pods' ), 'prev_next' => true, 'first_last' => true, 'limit' => (int) $this->limit, 'offset' => (int) $this->offset, 'page' => max( 1, (int) $this->page ), 'mid_size' => 2, 'end_size' => 1, 'total_found' => $this->total_found(), 'page_var' => $this->page_var, 'base' => "{$url}{$append}%_%", 'format' => "{$this->page_var}=%#%", 'class' => '', 'link_class' => '', ); if ( is_object( $params ) ) { $params = get_object_vars( $params ); } $params = (object) array_merge( $defaults, (array) $params ); $params->total = $this->total_pages( $params->limit, $params->offset, $params->total_found ); if ( $params->limit < 1 || $params->total_found < 1 || 1 === $params->total || $params->total_found <= $params->offset ) { return $this->do_hook( 'pagination', $this->do_hook( 'pagination_' . $params->type, '', $params ), $params ); } $pagination = $params->type; if ( ! in_array( $params->type, array( 'simple', 'advanced', 'paginate', 'list' ), true ) ) { $pagination = 'advanced'; } ob_start(); pods_view( PODS_DIR . 'ui/front/pagination/' . $pagination . '.php', compact( array_keys( get_defined_vars() ) ) ); $output = ob_get_clean(); return $this->do_hook( 'pagination', $this->do_hook( 'pagination_' . $params->type, $output, $params ), $params ); }
php
public function pagination( $params = null ) { if ( empty( $params ) ) { $params = array(); } elseif ( ! is_array( $params ) ) { $params = array( 'label' => $params ); } $this->page_var = pods_v( 'page_var', $params, $this->page_var ); $url = pods_query_arg( null, null, $this->page_var ); $append = '?'; if ( false !== strpos( $url, '?' ) ) { $append = '&'; } $defaults = array( 'type' => 'advanced', 'label' => __( 'Go to page:', 'pods' ), 'show_label' => true, 'first_text' => __( '&laquo; First', 'pods' ), 'prev_text' => __( '&lsaquo; Previous', 'pods' ), 'next_text' => __( 'Next &rsaquo;', 'pods' ), 'last_text' => __( 'Last &raquo;', 'pods' ), 'prev_next' => true, 'first_last' => true, 'limit' => (int) $this->limit, 'offset' => (int) $this->offset, 'page' => max( 1, (int) $this->page ), 'mid_size' => 2, 'end_size' => 1, 'total_found' => $this->total_found(), 'page_var' => $this->page_var, 'base' => "{$url}{$append}%_%", 'format' => "{$this->page_var}=%#%", 'class' => '', 'link_class' => '', ); if ( is_object( $params ) ) { $params = get_object_vars( $params ); } $params = (object) array_merge( $defaults, (array) $params ); $params->total = $this->total_pages( $params->limit, $params->offset, $params->total_found ); if ( $params->limit < 1 || $params->total_found < 1 || 1 === $params->total || $params->total_found <= $params->offset ) { return $this->do_hook( 'pagination', $this->do_hook( 'pagination_' . $params->type, '', $params ), $params ); } $pagination = $params->type; if ( ! in_array( $params->type, array( 'simple', 'advanced', 'paginate', 'list' ), true ) ) { $pagination = 'advanced'; } ob_start(); pods_view( PODS_DIR . 'ui/front/pagination/' . $pagination . '.php', compact( array_keys( get_defined_vars() ) ) ); $output = ob_get_clean(); return $this->do_hook( 'pagination', $this->do_hook( 'pagination_' . $params->type, $output, $params ), $params ); }
[ "public", "function", "pagination", "(", "$", "params", "=", "null", ")", "{", "if", "(", "empty", "(", "$", "params", ")", ")", "{", "$", "params", "=", "array", "(", ")", ";", "}", "elseif", "(", "!", "is_array", "(", "$", "params", ")", ")", ...
Display the pagination controls, types supported by default are simple, paginate and advanced. The base and format parameters are used only for the paginate view. @param array|object $params Associative array of parameters. @return string Pagination HTML @since 2.0.0 @link https://pods.io/docs/pagination/
[ "Display", "the", "pagination", "controls", "types", "supported", "by", "default", "are", "simple", "paginate", "and", "advanced", ".", "The", "base", "and", "format", "parameters", "are", "used", "only", "for", "the", "paginate", "view", "." ]
fd9a07c5c81ccbfcb21c5a0b2166f96c31d0826c
https://github.com/pods-framework/pods/blob/fd9a07c5c81ccbfcb21c5a0b2166f96c31d0826c/classes/Pods.php#L3458-L3525
train
pods-framework/pods
classes/Pods.php
Pods.view
public function view( $fields = null ) { $pod =& $this; // Convert comma separated list of fields to an array. if ( null !== $fields && ! is_array( $fields ) && 0 < strlen( $fields ) ) { $fields = explode( ',', $fields ); } $object_fields = (array) pods_v( 'object_fields', $this->pod_data, array(), true ); if ( empty( $fields ) ) { // Add core object fields if $fields is empty. $fields = array_merge( $object_fields, $this->fields ); } // Temporary. $view_fields = $fields; $fields = array(); foreach ( $view_fields as $name => $field ) { $defaults = array( 'name' => $name, ); if ( ! is_array( $field ) ) { $name = $field; $field = array( 'name' => $name, ); } // @codingStandardsIgnoreLine. $field = array_merge( $defaults, $field ); $field['name'] = trim( $field['name'] ); if ( empty( $field['name'] ) ) { $field['name'] = trim( $name ); } if ( isset( $object_fields[ $field['name'] ] ) ) { // @codingStandardsIgnoreLine. $field = array_merge( $field, $object_fields[ $field['name'] ] ); } elseif ( isset( $this->fields[ $field['name'] ] ) ) { // @codingStandardsIgnoreLine. $field = array_merge( $this->fields[ $field['name'] ], $field ); } if ( pods_v( 'hidden', $field, false, true ) || 'hidden' === $field['type'] ) { continue; } elseif ( ! PodsForm::permission( $field['type'], $field['name'], $field['options'], $fields, $pod, $pod->id() ) ) { continue; } $fields[ $field['name'] ] = $field; }//end foreach // Cleanup. unset( $view_fields ); $output = pods_view( PODS_DIR . 'ui/front/view.php', compact( array_keys( get_defined_vars() ) ), false, 'cache', true ); return $this->do_hook( 'view', $output, $fields, $this->id() ); }
php
public function view( $fields = null ) { $pod =& $this; // Convert comma separated list of fields to an array. if ( null !== $fields && ! is_array( $fields ) && 0 < strlen( $fields ) ) { $fields = explode( ',', $fields ); } $object_fields = (array) pods_v( 'object_fields', $this->pod_data, array(), true ); if ( empty( $fields ) ) { // Add core object fields if $fields is empty. $fields = array_merge( $object_fields, $this->fields ); } // Temporary. $view_fields = $fields; $fields = array(); foreach ( $view_fields as $name => $field ) { $defaults = array( 'name' => $name, ); if ( ! is_array( $field ) ) { $name = $field; $field = array( 'name' => $name, ); } // @codingStandardsIgnoreLine. $field = array_merge( $defaults, $field ); $field['name'] = trim( $field['name'] ); if ( empty( $field['name'] ) ) { $field['name'] = trim( $name ); } if ( isset( $object_fields[ $field['name'] ] ) ) { // @codingStandardsIgnoreLine. $field = array_merge( $field, $object_fields[ $field['name'] ] ); } elseif ( isset( $this->fields[ $field['name'] ] ) ) { // @codingStandardsIgnoreLine. $field = array_merge( $this->fields[ $field['name'] ], $field ); } if ( pods_v( 'hidden', $field, false, true ) || 'hidden' === $field['type'] ) { continue; } elseif ( ! PodsForm::permission( $field['type'], $field['name'], $field['options'], $fields, $pod, $pod->id() ) ) { continue; } $fields[ $field['name'] ] = $field; }//end foreach // Cleanup. unset( $view_fields ); $output = pods_view( PODS_DIR . 'ui/front/view.php', compact( array_keys( get_defined_vars() ) ), false, 'cache', true ); return $this->do_hook( 'view', $output, $fields, $this->id() ); }
[ "public", "function", "view", "(", "$", "fields", "=", "null", ")", "{", "$", "pod", "=", "&", "$", "this", ";", "// Convert comma separated list of fields to an array.", "if", "(", "null", "!==", "$", "fields", "&&", "!", "is_array", "(", "$", "fields", "...
Render a singular view for the Pod item content. @param array|string|null $fields (optional) Fields to show in the view, defaults to all fields. @return mixed @since 2.3.10
[ "Render", "a", "singular", "view", "for", "the", "Pod", "item", "content", "." ]
fd9a07c5c81ccbfcb21c5a0b2166f96c31d0826c
https://github.com/pods-framework/pods/blob/fd9a07c5c81ccbfcb21c5a0b2166f96c31d0826c/classes/Pods.php#L4036-L4103
train
pods-framework/pods
components/Pages.php
Pods_Pages.shortcode
public function shortcode( $tags, $content = null ) { if ( ! isset( $tags['page'] ) || empty( $tags['page'] ) ) { $tags['page'] = null; } $pods_page = self::exists( $tags['page'] ); if ( empty( $pods_page ) ) { return '<p>Pods Page not found</p>'; } return self::content( true, $pods_page ); }
php
public function shortcode( $tags, $content = null ) { if ( ! isset( $tags['page'] ) || empty( $tags['page'] ) ) { $tags['page'] = null; } $pods_page = self::exists( $tags['page'] ); if ( empty( $pods_page ) ) { return '<p>Pods Page not found</p>'; } return self::content( true, $pods_page ); }
[ "public", "function", "shortcode", "(", "$", "tags", ",", "$", "content", "=", "null", ")", "{", "if", "(", "!", "isset", "(", "$", "tags", "[", "'page'", "]", ")", "||", "empty", "(", "$", "tags", "[", "'page'", "]", ")", ")", "{", "$", "tags"...
Pod Page Content Shortcode support for use anywhere that supports WP Shortcodes @param array $tags An associative array of shortcode properties @param string $content Not currently used @return string @since 2.3.9
[ "Pod", "Page", "Content", "Shortcode", "support", "for", "use", "anywhere", "that", "supports", "WP", "Shortcodes" ]
fd9a07c5c81ccbfcb21c5a0b2166f96c31d0826c
https://github.com/pods-framework/pods/blob/fd9a07c5c81ccbfcb21c5a0b2166f96c31d0826c/components/Pages.php#L159-L172
train
pods-framework/pods
components/Pages.php
Pods_Pages.fix_filters
public function fix_filters( $data, $pod = null, $id = null, $groups = null, $post = null ) { remove_filter( 'content_save_pre', 'balanceTags', 50 ); }
php
public function fix_filters( $data, $pod = null, $id = null, $groups = null, $post = null ) { remove_filter( 'content_save_pre', 'balanceTags', 50 ); }
[ "public", "function", "fix_filters", "(", "$", "data", ",", "$", "pod", "=", "null", ",", "$", "id", "=", "null", ",", "$", "groups", "=", "null", ",", "$", "post", "=", "null", ")", "{", "remove_filter", "(", "'content_save_pre'", ",", "'balanceTags'"...
Fix filters, specifically removing balanceTags @since 2.0.1 @param $data @param null $pod @param null $id @param null $groups @param null $post
[ "Fix", "filters", "specifically", "removing", "balanceTags" ]
fd9a07c5c81ccbfcb21c5a0b2166f96c31d0826c
https://github.com/pods-framework/pods/blob/fd9a07c5c81ccbfcb21c5a0b2166f96c31d0826c/components/Pages.php#L258-L261
train
pods-framework/pods
components/Pages.php
Pods_Pages.remove_row_actions
public function remove_row_actions( $actions, $post ) { global $current_screen; if ( ! is_object( $current_screen ) || $this->object_type != $current_screen->post_type ) { return $actions; } if ( isset( $actions['view'] ) ) { unset( $actions['view'] ); } if ( isset( $actions['inline hide-if-no-js'] ) ) { unset( $actions['inline hide-if-no-js'] ); } // W3 Total Cache if ( isset( $actions['pgcache_purge'] ) ) { unset( $actions['pgcache_purge'] ); } return $actions; }
php
public function remove_row_actions( $actions, $post ) { global $current_screen; if ( ! is_object( $current_screen ) || $this->object_type != $current_screen->post_type ) { return $actions; } if ( isset( $actions['view'] ) ) { unset( $actions['view'] ); } if ( isset( $actions['inline hide-if-no-js'] ) ) { unset( $actions['inline hide-if-no-js'] ); } // W3 Total Cache if ( isset( $actions['pgcache_purge'] ) ) { unset( $actions['pgcache_purge'] ); } return $actions; }
[ "public", "function", "remove_row_actions", "(", "$", "actions", ",", "$", "post", ")", "{", "global", "$", "current_screen", ";", "if", "(", "!", "is_object", "(", "$", "current_screen", ")", "||", "$", "this", "->", "object_type", "!=", "$", "current_scr...
Remove unused row actions @since 2.0.5 @param $actions @param $post @return
[ "Remove", "unused", "row", "actions" ]
fd9a07c5c81ccbfcb21c5a0b2166f96c31d0826c
https://github.com/pods-framework/pods/blob/fd9a07c5c81ccbfcb21c5a0b2166f96c31d0826c/components/Pages.php#L273-L295
train
pods-framework/pods
components/Pages.php
Pods_Pages.post_type_link
public function post_type_link( $post_link, $post ) { if ( empty( $post ) || $this->object_type != $post->post_type ) { return $post_link; } $post_link = get_site_url() . '/'; if ( false === strpos( $post->post_title, '*' ) ) { $post_link .= trim( $post->post_title, '/ ' ) . '/'; } return $post_link; }
php
public function post_type_link( $post_link, $post ) { if ( empty( $post ) || $this->object_type != $post->post_type ) { return $post_link; } $post_link = get_site_url() . '/'; if ( false === strpos( $post->post_title, '*' ) ) { $post_link .= trim( $post->post_title, '/ ' ) . '/'; } return $post_link; }
[ "public", "function", "post_type_link", "(", "$", "post_link", ",", "$", "post", ")", "{", "if", "(", "empty", "(", "$", "post", ")", "||", "$", "this", "->", "object_type", "!=", "$", "post", "->", "post_type", ")", "{", "return", "$", "post_link", ...
Filter permalinks and adjust for pod pages @param $post_link @param $post @return mixed
[ "Filter", "permalinks", "and", "adjust", "for", "pod", "pages" ]
fd9a07c5c81ccbfcb21c5a0b2166f96c31d0826c
https://github.com/pods-framework/pods/blob/fd9a07c5c81ccbfcb21c5a0b2166f96c31d0826c/components/Pages.php#L395-L408
train
pods-framework/pods
components/Pages.php
Pods_Pages.get_meta
public function get_meta( $_null, $post_ID = null, $meta_key = null, $single = false ) { if ( 'code' === $meta_key ) { $post = get_post( $post_ID ); if ( is_object( $post ) && $this->object_type == $post->post_type ) { return $post->post_content; } } return $_null; }
php
public function get_meta( $_null, $post_ID = null, $meta_key = null, $single = false ) { if ( 'code' === $meta_key ) { $post = get_post( $post_ID ); if ( is_object( $post ) && $this->object_type == $post->post_type ) { return $post->post_content; } } return $_null; }
[ "public", "function", "get_meta", "(", "$", "_null", ",", "$", "post_ID", "=", "null", ",", "$", "meta_key", "=", "null", ",", "$", "single", "=", "false", ")", "{", "if", "(", "'code'", "===", "$", "meta_key", ")", "{", "$", "post", "=", "get_post...
Get the fields @param null $_null @param int $post_ID @param string $meta_key @param bool $single @return array|bool|int|mixed|null|string|void
[ "Get", "the", "fields" ]
fd9a07c5c81ccbfcb21c5a0b2166f96c31d0826c
https://github.com/pods-framework/pods/blob/fd9a07c5c81ccbfcb21c5a0b2166f96c31d0826c/components/Pages.php#L619-L630
train
pods-framework/pods
components/Pages.php
Pods_Pages.save_meta
public function save_meta( $_null, $post_ID = null, $meta_key = null, $meta_value = null ) { if ( 'code' === $meta_key ) { $post = get_post( $post_ID ); if ( is_object( $post ) && $this->object_type == $post->post_type ) { $postdata = array( 'ID' => $post_ID, 'post_content' => $meta_value, ); remove_filter( current_filter(), array( $this, __FUNCTION__ ) ); $revisions = false; if ( has_action( 'pre_post_update', 'wp_save_post_revision' ) ) { remove_action( 'pre_post_update', 'wp_save_post_revision' ); $revisions = true; } wp_update_post( (object) $postdata ); // objects will be automatically sanitized if ( $revisions ) { add_action( 'pre_post_update', 'wp_save_post_revision' ); } return true; }//end if }//end if return $_null; }
php
public function save_meta( $_null, $post_ID = null, $meta_key = null, $meta_value = null ) { if ( 'code' === $meta_key ) { $post = get_post( $post_ID ); if ( is_object( $post ) && $this->object_type == $post->post_type ) { $postdata = array( 'ID' => $post_ID, 'post_content' => $meta_value, ); remove_filter( current_filter(), array( $this, __FUNCTION__ ) ); $revisions = false; if ( has_action( 'pre_post_update', 'wp_save_post_revision' ) ) { remove_action( 'pre_post_update', 'wp_save_post_revision' ); $revisions = true; } wp_update_post( (object) $postdata ); // objects will be automatically sanitized if ( $revisions ) { add_action( 'pre_post_update', 'wp_save_post_revision' ); } return true; }//end if }//end if return $_null; }
[ "public", "function", "save_meta", "(", "$", "_null", ",", "$", "post_ID", "=", "null", ",", "$", "meta_key", "=", "null", ",", "$", "meta_value", "=", "null", ")", "{", "if", "(", "'code'", "===", "$", "meta_key", ")", "{", "$", "post", "=", "get_...
Save the fields @param $_null @param int $post_ID @param string $meta_key @param null $meta_value @return bool|int|null
[ "Save", "the", "fields" ]
fd9a07c5c81ccbfcb21c5a0b2166f96c31d0826c
https://github.com/pods-framework/pods/blob/fd9a07c5c81ccbfcb21c5a0b2166f96c31d0826c/components/Pages.php#L642-L674
train
pods-framework/pods
components/Pages.php
Pods_Pages.flush_rewrites
public static function flush_rewrites() { $args = array( 'post_type' => '_pods_page', 'nopaging' => true, 'posts_per_page' => - 1, 'post_status' => 'publish', 'order' => 'ASC', 'orderby' => 'title', ); $pod_pages = get_posts( $args ); $pod_page_rewrites = array(); foreach ( $pod_pages as $pod_page ) { $pod_page_rewrites[ $pod_page->ID ] = $pod_page->post_title; } uksort( $pod_page_rewrites, 'pods_page_length_sort' ); pods_transient_set( 'pods_object_page_rewrites', $pod_page_rewrites ); $pod_page_rewrites = array_flip( $pod_page_rewrites ); return $pod_page_rewrites; }
php
public static function flush_rewrites() { $args = array( 'post_type' => '_pods_page', 'nopaging' => true, 'posts_per_page' => - 1, 'post_status' => 'publish', 'order' => 'ASC', 'orderby' => 'title', ); $pod_pages = get_posts( $args ); $pod_page_rewrites = array(); foreach ( $pod_pages as $pod_page ) { $pod_page_rewrites[ $pod_page->ID ] = $pod_page->post_title; } uksort( $pod_page_rewrites, 'pods_page_length_sort' ); pods_transient_set( 'pods_object_page_rewrites', $pod_page_rewrites ); $pod_page_rewrites = array_flip( $pod_page_rewrites ); return $pod_page_rewrites; }
[ "public", "static", "function", "flush_rewrites", "(", ")", "{", "$", "args", "=", "array", "(", "'post_type'", "=>", "'_pods_page'", ",", "'nopaging'", "=>", "true", ",", "'posts_per_page'", "=>", "-", "1", ",", "'post_status'", "=>", "'publish'", ",", "'or...
Flush Pod Page Rewrite cache @return array Pod Page Rewrites @since 2.3.4
[ "Flush", "Pod", "Page", "Rewrite", "cache" ]
fd9a07c5c81ccbfcb21c5a0b2166f96c31d0826c
https://github.com/pods-framework/pods/blob/fd9a07c5c81ccbfcb21c5a0b2166f96c31d0826c/components/Pages.php#L683-L709
train
pods-framework/pods
components/Pages.php
Pods_Pages.page_check
public function page_check() { if ( self::$checked ) { return; } global $pods; // Fix any global confusion wherever this runs if ( isset( $pods ) && ! isset( $GLOBALS['pods'] ) ) { $GLOBALS['pods'] =& $pods; } elseif ( ! isset( $pods ) && isset( $GLOBALS['pods'] ) ) { $pods =& $GLOBALS['pods']; } if ( ! defined( 'PODS_DISABLE_POD_PAGE_CHECK' ) || ! PODS_DISABLE_POD_PAGE_CHECK ) { if ( null === self::$exists ) { self::$exists = pod_page_exists(); } if ( false !== self::$exists ) { $pods = apply_filters( 'pods_global', $pods, self::$exists ); if ( ! is_wp_error( $pods ) && ( is_object( $pods ) || 404 != $pods ) ) { add_action( 'template_redirect', array( $this, 'template_redirect' ) ); add_filter( 'redirect_canonical', '__return_false' ); add_action( 'wp_head', array( $this, 'wp_head' ) ); add_filter( 'wp_title', array( $this, 'wp_title' ), 0, 3 ); add_filter( 'body_class', array( $this, 'body_class' ), 0, 1 ); add_filter( 'status_header', array( $this, 'status_header' ) ); add_action( 'after_setup_theme', array( $this, 'precode' ) ); add_action( 'wp', array( $this, 'silence_404' ), 1 ); // Genesis theme integration add_action( 'genesis_loop', 'pods_content', 11 ); } } self::$checked = true; }//end if }
php
public function page_check() { if ( self::$checked ) { return; } global $pods; // Fix any global confusion wherever this runs if ( isset( $pods ) && ! isset( $GLOBALS['pods'] ) ) { $GLOBALS['pods'] =& $pods; } elseif ( ! isset( $pods ) && isset( $GLOBALS['pods'] ) ) { $pods =& $GLOBALS['pods']; } if ( ! defined( 'PODS_DISABLE_POD_PAGE_CHECK' ) || ! PODS_DISABLE_POD_PAGE_CHECK ) { if ( null === self::$exists ) { self::$exists = pod_page_exists(); } if ( false !== self::$exists ) { $pods = apply_filters( 'pods_global', $pods, self::$exists ); if ( ! is_wp_error( $pods ) && ( is_object( $pods ) || 404 != $pods ) ) { add_action( 'template_redirect', array( $this, 'template_redirect' ) ); add_filter( 'redirect_canonical', '__return_false' ); add_action( 'wp_head', array( $this, 'wp_head' ) ); add_filter( 'wp_title', array( $this, 'wp_title' ), 0, 3 ); add_filter( 'body_class', array( $this, 'body_class' ), 0, 1 ); add_filter( 'status_header', array( $this, 'status_header' ) ); add_action( 'after_setup_theme', array( $this, 'precode' ) ); add_action( 'wp', array( $this, 'silence_404' ), 1 ); // Genesis theme integration add_action( 'genesis_loop', 'pods_content', 11 ); } } self::$checked = true; }//end if }
[ "public", "function", "page_check", "(", ")", "{", "if", "(", "self", "::", "$", "checked", ")", "{", "return", ";", "}", "global", "$", "pods", ";", "// Fix any global confusion wherever this runs", "if", "(", "isset", "(", "$", "pods", ")", "&&", "!", ...
Check if a Pod Page exists
[ "Check", "if", "a", "Pod", "Page", "exists" ]
fd9a07c5c81ccbfcb21c5a0b2166f96c31d0826c
https://github.com/pods-framework/pods/blob/fd9a07c5c81ccbfcb21c5a0b2166f96c31d0826c/components/Pages.php#L865-L905
train
pods-framework/pods
components/Pages.php
Pods_Pages.content
public static function content( $return = false, $pods_page = false ) { if ( empty( $pods_page ) ) { $pods_page = self::$exists; } $content = false; if ( $pods_page == self::$exists && self::$content_called ) { return $content; } if ( ! empty( $pods_page ) ) { /** * @var $pods \Pods */ global $pods; // Fix any global confusion wherever this runs if ( isset( $pods ) && ! isset( $GLOBALS['pods'] ) ) { $GLOBALS['pods'] =& $pods; } elseif ( ! isset( $pods ) && isset( $GLOBALS['pods'] ) ) { $pods =& $GLOBALS['pods']; } if ( 0 < strlen( trim( $pods_page['code'] ) ) ) { $content = trim( $pods_page['code'] ); } ob_start(); do_action( 'pods_content_pre', $pods_page, $content ); if ( 0 < strlen( $content ) ) { if ( false !== strpos( $content, '<?' ) && ( ! defined( 'PODS_DISABLE_EVAL' ) || ! PODS_DISABLE_EVAL ) ) { pods_deprecated( 'Pod Page PHP code has been deprecated, please use WP Page Templates or hook into the pods_content filter instead of embedding PHP.', '2.1' ); eval( "?>$content" ); } elseif ( is_object( $pods ) && ! empty( $pods->id ) ) { echo $pods->do_magic_tags( $content ); } else { echo $content; } } do_action( 'pods_content_post', $pods_page, $content ); $content = ob_get_clean(); if ( $pods_page == self::$exists ) { self::$content_called = true; } }//end if $content = apply_filters( 'pods_content', $content, $pods_page ); if ( $return ) { return $content; } echo $content; }
php
public static function content( $return = false, $pods_page = false ) { if ( empty( $pods_page ) ) { $pods_page = self::$exists; } $content = false; if ( $pods_page == self::$exists && self::$content_called ) { return $content; } if ( ! empty( $pods_page ) ) { /** * @var $pods \Pods */ global $pods; // Fix any global confusion wherever this runs if ( isset( $pods ) && ! isset( $GLOBALS['pods'] ) ) { $GLOBALS['pods'] =& $pods; } elseif ( ! isset( $pods ) && isset( $GLOBALS['pods'] ) ) { $pods =& $GLOBALS['pods']; } if ( 0 < strlen( trim( $pods_page['code'] ) ) ) { $content = trim( $pods_page['code'] ); } ob_start(); do_action( 'pods_content_pre', $pods_page, $content ); if ( 0 < strlen( $content ) ) { if ( false !== strpos( $content, '<?' ) && ( ! defined( 'PODS_DISABLE_EVAL' ) || ! PODS_DISABLE_EVAL ) ) { pods_deprecated( 'Pod Page PHP code has been deprecated, please use WP Page Templates or hook into the pods_content filter instead of embedding PHP.', '2.1' ); eval( "?>$content" ); } elseif ( is_object( $pods ) && ! empty( $pods->id ) ) { echo $pods->do_magic_tags( $content ); } else { echo $content; } } do_action( 'pods_content_post', $pods_page, $content ); $content = ob_get_clean(); if ( $pods_page == self::$exists ) { self::$content_called = true; } }//end if $content = apply_filters( 'pods_content', $content, $pods_page ); if ( $return ) { return $content; } echo $content; }
[ "public", "static", "function", "content", "(", "$", "return", "=", "false", ",", "$", "pods_page", "=", "false", ")", "{", "if", "(", "empty", "(", "$", "pods_page", ")", ")", "{", "$", "pods_page", "=", "self", "::", "$", "exists", ";", "}", "$",...
Output Pod Page Content @param bool $return Whether to return or not (default is to echo) @param bool $pods_page @return string
[ "Output", "Pod", "Page", "Content" ]
fd9a07c5c81ccbfcb21c5a0b2166f96c31d0826c
https://github.com/pods-framework/pods/blob/fd9a07c5c81ccbfcb21c5a0b2166f96c31d0826c/components/Pages.php#L916-L977
train
pods-framework/pods
classes/PodsTermSplitting.php
Pods_Term_Splitting.get_pod_info
private function get_pod_info() { $pod_info = null; if ( pods_api()->pod_exists( $this->taxonomy ) ) { // Load the taxonomy Pod $params = array( 'name' => $this->taxonomy, 'table_info' => true, ); $pod_info = pods_api()->load_pod( $params, false ); } return $pod_info; }
php
private function get_pod_info() { $pod_info = null; if ( pods_api()->pod_exists( $this->taxonomy ) ) { // Load the taxonomy Pod $params = array( 'name' => $this->taxonomy, 'table_info' => true, ); $pod_info = pods_api()->load_pod( $params, false ); } return $pod_info; }
[ "private", "function", "get_pod_info", "(", ")", "{", "$", "pod_info", "=", "null", ";", "if", "(", "pods_api", "(", ")", "->", "pod_exists", "(", "$", "this", "->", "taxonomy", ")", ")", "{", "// Load the taxonomy Pod", "$", "params", "=", "array", "(",...
Return the Pod information for the specified taxonomy, or null if the taxonomy isn't a Pod @return array|bool|mixed|null
[ "Return", "the", "Pod", "information", "for", "the", "specified", "taxonomy", "or", "null", "if", "the", "taxonomy", "isn", "t", "a", "Pod" ]
fd9a07c5c81ccbfcb21c5a0b2166f96c31d0826c
https://github.com/pods-framework/pods/blob/fd9a07c5c81ccbfcb21c5a0b2166f96c31d0826c/classes/PodsTermSplitting.php#L76-L92
train
pods-framework/pods
classes/PodsTermSplitting.php
Pods_Term_Splitting.update_relationships_to_term
private function update_relationships_to_term() { // Loop through all Pods $all_pods = pods_api()->load_pods(); if ( ! is_array( $all_pods ) ) { return; } foreach ( $all_pods as $this_pod_id => $this_pod ) { // Loop through all fields in this Pod foreach ( $this_pod['fields'] as $this_field_name => $this_field ) { // Ignore everything except relationship fields to this taxonomy if ( 'pick' !== $this_field['type'] || 'taxonomy' !== $this_field['pick_object'] || $this->taxonomy != $this_field['pick_val'] ) { continue; } // Update the term ID in podsrel everywhere it is the value for this field $this->update_podsrel_related_term( $this_field['id'] ); // Fix-up any special-case relationships that store term IDs in their own meta table and/or serialized switch ( $this_pod['type'] ) { case 'post_type': $this->update_postmeta( $this_pod['name'], $this_field_name ); break; case 'comment': $this->update_commentmeta( $this_field_name ); break; case 'user': $this->update_usermeta( $this_field_name ); break; case 'settings': $this->update_setting_meta( $this_pod['name'], $this_field_name ); break; } }//end foreach }//end foreach }
php
private function update_relationships_to_term() { // Loop through all Pods $all_pods = pods_api()->load_pods(); if ( ! is_array( $all_pods ) ) { return; } foreach ( $all_pods as $this_pod_id => $this_pod ) { // Loop through all fields in this Pod foreach ( $this_pod['fields'] as $this_field_name => $this_field ) { // Ignore everything except relationship fields to this taxonomy if ( 'pick' !== $this_field['type'] || 'taxonomy' !== $this_field['pick_object'] || $this->taxonomy != $this_field['pick_val'] ) { continue; } // Update the term ID in podsrel everywhere it is the value for this field $this->update_podsrel_related_term( $this_field['id'] ); // Fix-up any special-case relationships that store term IDs in their own meta table and/or serialized switch ( $this_pod['type'] ) { case 'post_type': $this->update_postmeta( $this_pod['name'], $this_field_name ); break; case 'comment': $this->update_commentmeta( $this_field_name ); break; case 'user': $this->update_usermeta( $this_field_name ); break; case 'settings': $this->update_setting_meta( $this_pod['name'], $this_field_name ); break; } }//end foreach }//end foreach }
[ "private", "function", "update_relationships_to_term", "(", ")", "{", "// Loop through all Pods", "$", "all_pods", "=", "pods_api", "(", ")", "->", "load_pods", "(", ")", ";", "if", "(", "!", "is_array", "(", "$", "all_pods", ")", ")", "{", "return", ";", ...
Track down all fields related to the target taxonomy and update stored term IDs as necessary
[ "Track", "down", "all", "fields", "related", "to", "the", "target", "taxonomy", "and", "update", "stored", "term", "IDs", "as", "necessary" ]
fd9a07c5c81ccbfcb21c5a0b2166f96c31d0826c
https://github.com/pods-framework/pods/blob/fd9a07c5c81ccbfcb21c5a0b2166f96c31d0826c/classes/PodsTermSplitting.php#L148-L192
train
pods-framework/pods
classes/PodsTermSplitting.php
Pods_Term_Splitting.update_postmeta
private function update_postmeta( $pod_name, $field_name ) { /** @global wpdb $wpdb */ global $wpdb; // Fix up the unserialized data $task = "update_postmeta_{$pod_name}_{$field_name}_unserialized"; if ( ! $this->have_done( $task ) ) { $wpdb->query( $wpdb->prepare( " UPDATE {$wpdb->postmeta} AS meta LEFT JOIN {$wpdb->posts} AS t ON meta.post_id = t.ID SET meta_value = %s WHERE meta_key = %s AND meta_value = %s AND t.post_type = %s ", $this->new_term_id, $field_name, $this->term_id, $pod_name ) ); $this->append_progress( $task ); }//end if // Fix up the serialized data $task = "update_postmeta_{$pod_name}_{$field_name}_serialized"; if ( ! $this->have_done( $task ) ) { $meta_key = sprintf( '_pods_%s', $field_name ); $target_serialized = sprintf( ';i:%s;', $this->term_id ); $replace_serialized = sprintf( ';i:%s;', $this->new_term_id ); $wpdb->query( $wpdb->prepare( " UPDATE {$wpdb->postmeta} AS meta LEFT JOIN {$wpdb->posts} AS t ON meta.post_id = t.ID SET meta.meta_value = REPLACE( meta.meta_value, %s, %s ) WHERE meta.meta_key = %s AND t.post_type = %s AND meta_value LIKE '%%%s%%' ", $target_serialized, $replace_serialized, $meta_key, $pod_name, pods_sanitize_like( $target_serialized ) ) ); $this->append_progress( $task ); }//end if }
php
private function update_postmeta( $pod_name, $field_name ) { /** @global wpdb $wpdb */ global $wpdb; // Fix up the unserialized data $task = "update_postmeta_{$pod_name}_{$field_name}_unserialized"; if ( ! $this->have_done( $task ) ) { $wpdb->query( $wpdb->prepare( " UPDATE {$wpdb->postmeta} AS meta LEFT JOIN {$wpdb->posts} AS t ON meta.post_id = t.ID SET meta_value = %s WHERE meta_key = %s AND meta_value = %s AND t.post_type = %s ", $this->new_term_id, $field_name, $this->term_id, $pod_name ) ); $this->append_progress( $task ); }//end if // Fix up the serialized data $task = "update_postmeta_{$pod_name}_{$field_name}_serialized"; if ( ! $this->have_done( $task ) ) { $meta_key = sprintf( '_pods_%s', $field_name ); $target_serialized = sprintf( ';i:%s;', $this->term_id ); $replace_serialized = sprintf( ';i:%s;', $this->new_term_id ); $wpdb->query( $wpdb->prepare( " UPDATE {$wpdb->postmeta} AS meta LEFT JOIN {$wpdb->posts} AS t ON meta.post_id = t.ID SET meta.meta_value = REPLACE( meta.meta_value, %s, %s ) WHERE meta.meta_key = %s AND t.post_type = %s AND meta_value LIKE '%%%s%%' ", $target_serialized, $replace_serialized, $meta_key, $pod_name, pods_sanitize_like( $target_serialized ) ) ); $this->append_progress( $task ); }//end if }
[ "private", "function", "update_postmeta", "(", "$", "pod_name", ",", "$", "field_name", ")", "{", "/** @global wpdb $wpdb */", "global", "$", "wpdb", ";", "// Fix up the unserialized data", "$", "task", "=", "\"update_postmeta_{$pod_name}_{$field_name}_unserialized\"", ";",...
Called for all fields related to the target taxonomy that are in a post_type @param string $pod_name @param string $field_name
[ "Called", "for", "all", "fields", "related", "to", "the", "target", "taxonomy", "that", "are", "in", "a", "post_type" ]
fd9a07c5c81ccbfcb21c5a0b2166f96c31d0826c
https://github.com/pods-framework/pods/blob/fd9a07c5c81ccbfcb21c5a0b2166f96c31d0826c/classes/PodsTermSplitting.php#L229-L286
train
pods-framework/pods
classes/PodsTermSplitting.php
Pods_Term_Splitting.update_commentmeta
private function update_commentmeta( $field_name ) { /** @global wpdb $wpdb */ global $wpdb; // Fix up the unserialized data $task = "update_commentmeta_{$field_name}_unserialized"; if ( ! $this->have_done( $task ) ) { $table = $wpdb->commentmeta; $data = array( 'meta_value' => $this->new_term_id ); $where = array( 'meta_key' => $field_name, 'meta_value' => $this->term_id, ); $format = '%s'; $where_format = array( '%s', '%s' ); $wpdb->update( $table, $data, $where, $format, $where_format ); $this->append_progress( $task ); } // Fix up the serialized data $task = "update_commentmeta_{$field_name}_serialized"; if ( ! $this->have_done( $task ) ) { $meta_key = sprintf( '_pods_%s', $field_name ); $target_serialized = sprintf( ';i:%s;', $this->term_id ); $replace_serialized = sprintf( ';i:%s;', $this->new_term_id ); $wpdb->query( $wpdb->prepare( " UPDATE {$wpdb->commentmeta} SET meta_value = REPLACE( meta_value, %s, %s ) WHERE meta_key = %s AND meta_value LIKE '%%%s%%' ", $target_serialized, $replace_serialized, $meta_key, pods_sanitize_like( $target_serialized ) ) ); $this->append_progress( $task ); }//end if }
php
private function update_commentmeta( $field_name ) { /** @global wpdb $wpdb */ global $wpdb; // Fix up the unserialized data $task = "update_commentmeta_{$field_name}_unserialized"; if ( ! $this->have_done( $task ) ) { $table = $wpdb->commentmeta; $data = array( 'meta_value' => $this->new_term_id ); $where = array( 'meta_key' => $field_name, 'meta_value' => $this->term_id, ); $format = '%s'; $where_format = array( '%s', '%s' ); $wpdb->update( $table, $data, $where, $format, $where_format ); $this->append_progress( $task ); } // Fix up the serialized data $task = "update_commentmeta_{$field_name}_serialized"; if ( ! $this->have_done( $task ) ) { $meta_key = sprintf( '_pods_%s', $field_name ); $target_serialized = sprintf( ';i:%s;', $this->term_id ); $replace_serialized = sprintf( ';i:%s;', $this->new_term_id ); $wpdb->query( $wpdb->prepare( " UPDATE {$wpdb->commentmeta} SET meta_value = REPLACE( meta_value, %s, %s ) WHERE meta_key = %s AND meta_value LIKE '%%%s%%' ", $target_serialized, $replace_serialized, $meta_key, pods_sanitize_like( $target_serialized ) ) ); $this->append_progress( $task ); }//end if }
[ "private", "function", "update_commentmeta", "(", "$", "field_name", ")", "{", "/** @global wpdb $wpdb */", "global", "$", "wpdb", ";", "// Fix up the unserialized data", "$", "task", "=", "\"update_commentmeta_{$field_name}_unserialized\"", ";", "if", "(", "!", "$", "t...
Called for all fields related to the target taxonomy that are in a comment Pod @param string $field_name
[ "Called", "for", "all", "fields", "related", "to", "the", "target", "taxonomy", "that", "are", "in", "a", "comment", "Pod" ]
fd9a07c5c81ccbfcb21c5a0b2166f96c31d0826c
https://github.com/pods-framework/pods/blob/fd9a07c5c81ccbfcb21c5a0b2166f96c31d0826c/classes/PodsTermSplitting.php#L293-L340
train
pods-framework/pods
classes/PodsTermSplitting.php
Pods_Term_Splitting.update_setting_meta
private function update_setting_meta( $pod_name, $field_name ) { /** @global wpdb $wpdb */ global $wpdb; $option_name = "{$pod_name}_{$field_name}"; // Fix up the unserialized data $task = "update_setting_meta_{$pod_name}_{$field_name}_unserialized"; if ( ! $this->have_done( $task ) ) { // UPDATE {$wpdb->options} SET option_value = '{$new_term_id}' WHERE option_name = '{$pod_name}_{$field_name}' AND option_value = '{$term_id}' $table = $wpdb->options; $data = array( 'option_value' => $this->new_term_id ); $where = array( 'option_name' => $option_name, 'option_value' => $this->term_id, ); $format = '%s'; $where_format = array( '%s', '%s' ); $wpdb->update( $table, $data, $where, $format, $where_format ); $this->append_progress( $task ); } // Fix up the serialized data $task = "update_setting_meta_{$pod_name}_{$field_name}_serialized"; if ( ! $this->have_done( $task ) ) { $target_serialized = sprintf( ';i:%s;', $this->term_id ); $replace_serialized = sprintf( ';i:%s;', $this->new_term_id ); $wpdb->query( $wpdb->prepare( " UPDATE {$wpdb->options} SET option_value = REPLACE( option_value, %s, %s ) WHERE option_name = %s AND option_value LIKE '%%%s%%' ", $target_serialized, $replace_serialized, $option_name, pods_sanitize_like( $target_serialized ) ) ); $this->append_progress( $task ); }//end if }
php
private function update_setting_meta( $pod_name, $field_name ) { /** @global wpdb $wpdb */ global $wpdb; $option_name = "{$pod_name}_{$field_name}"; // Fix up the unserialized data $task = "update_setting_meta_{$pod_name}_{$field_name}_unserialized"; if ( ! $this->have_done( $task ) ) { // UPDATE {$wpdb->options} SET option_value = '{$new_term_id}' WHERE option_name = '{$pod_name}_{$field_name}' AND option_value = '{$term_id}' $table = $wpdb->options; $data = array( 'option_value' => $this->new_term_id ); $where = array( 'option_name' => $option_name, 'option_value' => $this->term_id, ); $format = '%s'; $where_format = array( '%s', '%s' ); $wpdb->update( $table, $data, $where, $format, $where_format ); $this->append_progress( $task ); } // Fix up the serialized data $task = "update_setting_meta_{$pod_name}_{$field_name}_serialized"; if ( ! $this->have_done( $task ) ) { $target_serialized = sprintf( ';i:%s;', $this->term_id ); $replace_serialized = sprintf( ';i:%s;', $this->new_term_id ); $wpdb->query( $wpdb->prepare( " UPDATE {$wpdb->options} SET option_value = REPLACE( option_value, %s, %s ) WHERE option_name = %s AND option_value LIKE '%%%s%%' ", $target_serialized, $replace_serialized, $option_name, pods_sanitize_like( $target_serialized ) ) ); $this->append_progress( $task ); }//end if }
[ "private", "function", "update_setting_meta", "(", "$", "pod_name", ",", "$", "field_name", ")", "{", "/** @global wpdb $wpdb */", "global", "$", "wpdb", ";", "$", "option_name", "=", "\"{$pod_name}_{$field_name}\"", ";", "// Fix up the unserialized data", "$", "task", ...
Called for all fields related to the target taxonomy that are in a user Pod @param string $pod_name @param string $field_name
[ "Called", "for", "all", "fields", "related", "to", "the", "target", "taxonomy", "that", "are", "in", "a", "user", "Pod" ]
fd9a07c5c81ccbfcb21c5a0b2166f96c31d0826c
https://github.com/pods-framework/pods/blob/fd9a07c5c81ccbfcb21c5a0b2166f96c31d0826c/classes/PodsTermSplitting.php#L402-L451
train
pods-framework/pods
classes/cli/PodsAPI_CLI_Command.php
PodsAPI_CLI_Command.add_pod
public function add_pod( $args, $assoc_args ) { // Don't allow id to be set. if ( isset( $assoc_args['id'] ) ) { unset( $assoc_args['id'] ); } $api = pods_api(); $id = 0; try { $id = $api->save_pod( $assoc_args ); } catch ( Exception $e ) { WP_CLI::error( sprintf( __( 'Error saving pod: %s', 'pods' ), $e->getMessage() ) ); } if ( 0 < $id ) { WP_CLI::success( __( 'Pod added.', 'pods' ) ); WP_CLI::line( sprintf( __( 'New ID: %s', 'pods' ), $id ) ); } else { WP_CLI::error( __( 'Pod not added.', 'pods' ) ); } }
php
public function add_pod( $args, $assoc_args ) { // Don't allow id to be set. if ( isset( $assoc_args['id'] ) ) { unset( $assoc_args['id'] ); } $api = pods_api(); $id = 0; try { $id = $api->save_pod( $assoc_args ); } catch ( Exception $e ) { WP_CLI::error( sprintf( __( 'Error saving pod: %s', 'pods' ), $e->getMessage() ) ); } if ( 0 < $id ) { WP_CLI::success( __( 'Pod added.', 'pods' ) ); WP_CLI::line( sprintf( __( 'New ID: %s', 'pods' ), $id ) ); } else { WP_CLI::error( __( 'Pod not added.', 'pods' ) ); } }
[ "public", "function", "add_pod", "(", "$", "args", ",", "$", "assoc_args", ")", "{", "// Don't allow id to be set.", "if", "(", "isset", "(", "$", "assoc_args", "[", "'id'", "]", ")", ")", "{", "unset", "(", "$", "assoc_args", "[", "'id'", "]", ")", ";...
Add a pod. ## OPTIONS --name=<name> : The pod name, the default type is post_type. [--<field>=<value>] : The field => value pair(s) to save. ## EXAMPLES wp pods-api add-pod --name=book wp pods-api add-pod --name=book --type=post_type wp pods-api add-pod --name=book --type=post_type --label=Books --singular_label=Book wp pods-api add-pod --name=genre --type=taxonomy --label=Genres --singular_label=Genre @subcommand add-pod @param $args @param $assoc_args
[ "Add", "a", "pod", "." ]
fd9a07c5c81ccbfcb21c5a0b2166f96c31d0826c
https://github.com/pods-framework/pods/blob/fd9a07c5c81ccbfcb21c5a0b2166f96c31d0826c/classes/cli/PodsAPI_CLI_Command.php#L31-L55
train
pods-framework/pods
classes/cli/PodsAPI_CLI_Command.php
PodsAPI_CLI_Command.reset_pod
public function reset_pod( $args, $assoc_args ) { $api = pods_api(); $reset = false; try { $pod = $api->load_pod( $assoc_args['name'] ); if ( ! $pod ) { WP_CLI::error( sprintf( __( 'Pod "%s" does not exist.', 'pods' ), $assoc_args['name'] ) ); } $reset = $api->reset_pod( $assoc_args ); } catch ( Exception $e ) { WP_CLI::error( sprintf( __( 'Error resetting pod: %s', 'pods' ), $e->getMessage() ) ); } if ( $reset ) { WP_CLI::success( __( 'Pod content reset.', 'pods' ) ); } else { WP_CLI::error( __( 'Pod content not reset.', 'pods' ) ); } }
php
public function reset_pod( $args, $assoc_args ) { $api = pods_api(); $reset = false; try { $pod = $api->load_pod( $assoc_args['name'] ); if ( ! $pod ) { WP_CLI::error( sprintf( __( 'Pod "%s" does not exist.', 'pods' ), $assoc_args['name'] ) ); } $reset = $api->reset_pod( $assoc_args ); } catch ( Exception $e ) { WP_CLI::error( sprintf( __( 'Error resetting pod: %s', 'pods' ), $e->getMessage() ) ); } if ( $reset ) { WP_CLI::success( __( 'Pod content reset.', 'pods' ) ); } else { WP_CLI::error( __( 'Pod content not reset.', 'pods' ) ); } }
[ "public", "function", "reset_pod", "(", "$", "args", ",", "$", "assoc_args", ")", "{", "$", "api", "=", "pods_api", "(", ")", ";", "$", "reset", "=", "false", ";", "try", "{", "$", "pod", "=", "$", "api", "->", "load_pod", "(", "$", "assoc_args", ...
Reset a pod which will delete all pod items. ## OPTIONS --name=<name> : The pod name. ## EXAMPLES wp pods-api reset-pod --name=book @subcommand reset-pod @param $args @param $assoc_args
[ "Reset", "a", "pod", "which", "will", "delete", "all", "pod", "items", "." ]
fd9a07c5c81ccbfcb21c5a0b2166f96c31d0826c
https://github.com/pods-framework/pods/blob/fd9a07c5c81ccbfcb21c5a0b2166f96c31d0826c/classes/cli/PodsAPI_CLI_Command.php#L185-L209
train
pods-framework/pods
classes/cli/PodsAPI_CLI_Command.php
PodsAPI_CLI_Command.delete_pod
public function delete_pod( $args, $assoc_args ) { $api = pods_api(); // Handle prettified arg name if ( ! empty( $assoc_args['delete-all'] ) ) { $assoc_args['delete_all'] = true; unset( $assoc_args['delete-all'] ); } $deleted = false; try { $pod = $api->load_pod( $assoc_args['name'] ); if ( ! $pod ) { WP_CLI::error( sprintf( __( 'Pod "%s" does not exist.', 'pods' ), $assoc_args['name'] ) ); } $deleted = $api->delete_pod( $assoc_args ); } catch ( Exception $e ) { WP_CLI::error( sprintf( __( 'Error deleting pod: %s', 'pods' ), $e->getMessage() ) ); } if ( $deleted ) { WP_CLI::success( __( 'Pod deleted.', 'pods' ) ); } else { WP_CLI::error( __( 'Pod not deleted.', 'pods' ) ); } }
php
public function delete_pod( $args, $assoc_args ) { $api = pods_api(); // Handle prettified arg name if ( ! empty( $assoc_args['delete-all'] ) ) { $assoc_args['delete_all'] = true; unset( $assoc_args['delete-all'] ); } $deleted = false; try { $pod = $api->load_pod( $assoc_args['name'] ); if ( ! $pod ) { WP_CLI::error( sprintf( __( 'Pod "%s" does not exist.', 'pods' ), $assoc_args['name'] ) ); } $deleted = $api->delete_pod( $assoc_args ); } catch ( Exception $e ) { WP_CLI::error( sprintf( __( 'Error deleting pod: %s', 'pods' ), $e->getMessage() ) ); } if ( $deleted ) { WP_CLI::success( __( 'Pod deleted.', 'pods' ) ); } else { WP_CLI::error( __( 'Pod not deleted.', 'pods' ) ); } }
[ "public", "function", "delete_pod", "(", "$", "args", ",", "$", "assoc_args", ")", "{", "$", "api", "=", "pods_api", "(", ")", ";", "// Handle prettified arg name", "if", "(", "!", "empty", "(", "$", "assoc_args", "[", "'delete-all'", "]", ")", ")", "{",...
Delete a pod, which will NOT delete all pod items by default. ## OPTIONS --name=<name> : The pod name. [--delete-all] : Delete all pod content for the pod. ## EXAMPLES wp pods-api delete-pod --name=book wp pods-api delete-pod --name=book --delete_all @subcommand delete-pod @param $args @param $assoc_args
[ "Delete", "a", "pod", "which", "will", "NOT", "delete", "all", "pod", "items", "by", "default", "." ]
fd9a07c5c81ccbfcb21c5a0b2166f96c31d0826c
https://github.com/pods-framework/pods/blob/fd9a07c5c81ccbfcb21c5a0b2166f96c31d0826c/classes/cli/PodsAPI_CLI_Command.php#L232-L263
train
pods-framework/pods
classes/cli/PodsAPI_CLI_Command.php
PodsAPI_CLI_Command.deactivate_component
public function deactivate_component( $args, $assoc_args ) { if ( ! class_exists( 'PodsInit' ) ) { WP_CLI::error( __( 'PodsInit not available', 'pods' ) ); return; } $component = $assoc_args['component']; $active = PodsInit::$components->is_component_active( $component ); if ( ! $active ) { WP_CLI::error( sprintf( __( 'Component %s is not active.', 'pods' ), $component ) ); } else { PodsInit::$components->deactivate_component( $component ); WP_CLI::success( __( 'Component deactivated.', 'pods' ) ); } }
php
public function deactivate_component( $args, $assoc_args ) { if ( ! class_exists( 'PodsInit' ) ) { WP_CLI::error( __( 'PodsInit not available', 'pods' ) ); return; } $component = $assoc_args['component']; $active = PodsInit::$components->is_component_active( $component ); if ( ! $active ) { WP_CLI::error( sprintf( __( 'Component %s is not active.', 'pods' ), $component ) ); } else { PodsInit::$components->deactivate_component( $component ); WP_CLI::success( __( 'Component deactivated.', 'pods' ) ); } }
[ "public", "function", "deactivate_component", "(", "$", "args", ",", "$", "assoc_args", ")", "{", "if", "(", "!", "class_exists", "(", "'PodsInit'", ")", ")", "{", "WP_CLI", "::", "error", "(", "__", "(", "'PodsInit not available'", ",", "'pods'", ")", ")"...
Deactivate a component. ## OPTIONS --component=<component> : The component identifier. ## EXAMPLES wp pods-api deactivate-component --component=templates @subcommand deactivate-component @param $args @param $assoc_args
[ "Deactivate", "a", "component", "." ]
fd9a07c5c81ccbfcb21c5a0b2166f96c31d0826c
https://github.com/pods-framework/pods/blob/fd9a07c5c81ccbfcb21c5a0b2166f96c31d0826c/classes/cli/PodsAPI_CLI_Command.php#L321-L341
train
pods-framework/pods
classes/cli/PodsAPI_CLI_Command.php
PodsAPI_CLI_Command.export_pod
public function export_pod( $args, $assoc_args ) { if ( ! PodsInit::$components->is_component_active( 'migrate-packages' ) ) { WP_CLI::error( sprintf( __( 'Migrate Package is not activated. Try activating it: %s', 'pods' ), 'wp pods-api activate-component --component=migrate-packages' ) ); } $params = array( 'pods' => true, ); if ( PodsInit::$components->is_component_active( 'templates' ) ) { $params['templates'] = true; } if ( PodsInit::$components->is_component_active( 'pages' ) ) { $params['pages'] = true; } $file = $assoc_args['file']; unset( $assoc_args['file'] ); $params = array_merge( $params, $assoc_args ); $data = false; try { $data = Pods_Migrate_Packages::export( $params ); } catch ( Exception $e ) { WP_CLI::error( sprintf( __( 'Error exporting Pods Package: %s', 'pods' ), $e->getMessage() ) ); } if ( ! empty( $data ) ) { // Load PodsMigrate class file for use. pods_migrate(); // Only JSON format is supported for export. if ( false === strpos( $file, '.json' ) ) { $file .= '.json'; } $export_file = PodsMigrate::export_data_to_file( $file, $data, true ); if ( $export_file ) { WP_CLI::success( sprintf( __( 'Pods Package exported: %s', 'pods' ), $export_file ) ); } else { WP_CLI::error( __( 'Pods Package not exported.', 'pods' ) ); } } else { WP_CLI::error( __( 'No Pods Package data found.', 'pods' ) ); } }
php
public function export_pod( $args, $assoc_args ) { if ( ! PodsInit::$components->is_component_active( 'migrate-packages' ) ) { WP_CLI::error( sprintf( __( 'Migrate Package is not activated. Try activating it: %s', 'pods' ), 'wp pods-api activate-component --component=migrate-packages' ) ); } $params = array( 'pods' => true, ); if ( PodsInit::$components->is_component_active( 'templates' ) ) { $params['templates'] = true; } if ( PodsInit::$components->is_component_active( 'pages' ) ) { $params['pages'] = true; } $file = $assoc_args['file']; unset( $assoc_args['file'] ); $params = array_merge( $params, $assoc_args ); $data = false; try { $data = Pods_Migrate_Packages::export( $params ); } catch ( Exception $e ) { WP_CLI::error( sprintf( __( 'Error exporting Pods Package: %s', 'pods' ), $e->getMessage() ) ); } if ( ! empty( $data ) ) { // Load PodsMigrate class file for use. pods_migrate(); // Only JSON format is supported for export. if ( false === strpos( $file, '.json' ) ) { $file .= '.json'; } $export_file = PodsMigrate::export_data_to_file( $file, $data, true ); if ( $export_file ) { WP_CLI::success( sprintf( __( 'Pods Package exported: %s', 'pods' ), $export_file ) ); } else { WP_CLI::error( __( 'Pods Package not exported.', 'pods' ) ); } } else { WP_CLI::error( __( 'No Pods Package data found.', 'pods' ) ); } }
[ "public", "function", "export_pod", "(", "$", "args", ",", "$", "assoc_args", ")", "{", "if", "(", "!", "PodsInit", "::", "$", "components", "->", "is_component_active", "(", "'migrate-packages'", ")", ")", "{", "WP_CLI", "::", "error", "(", "sprintf", "("...
Export a Pods Package to a file. ## OPTIONS --file=<file> : The file to save to including path (defaults to current path). [--pods=<pods>] : A comma-separated list of Pods IDs to export (default is all Pods). [--templates=<templates>] : A comma-separated list of Pod Template IDs to export (default is all Templates). [--pages=<pages>] : A comma-separated list of Pod Page IDs to export (default is all Pod Pages). ## EXAMPLES wp pods-api export-pod --file="pods-package.json" wp pods-api export-pod --file="pods-package.json" --pods="book,genre" wp pods-api export-pod --file="/path/to/pods-package.json" --pods="book,genre" wp pods-api export-pod --templates="book-single,book-list" --file="pods-package.json" wp pods-api export-pod --pod-pages="books,books/*" --file="pods-package.json" wp pods-api export-pod --pods="book,genre" --templates="book-single,book-list" --pod-pages="books,books/*" --file="pods-package.json" @subcommand export-pod
[ "Export", "a", "Pods", "Package", "to", "a", "file", "." ]
fd9a07c5c81ccbfcb21c5a0b2166f96c31d0826c
https://github.com/pods-framework/pods/blob/fd9a07c5c81ccbfcb21c5a0b2166f96c31d0826c/classes/cli/PodsAPI_CLI_Command.php#L388-L440
train
pods-framework/pods
classes/cli/PodsAPI_CLI_Command.php
PodsAPI_CLI_Command.import_pod
public function import_pod( $args, $assoc_args ) { if ( ! PodsInit::$components->is_component_active( 'migrate-packages' ) ) { WP_CLI::error( sprintf( __( 'Migrate Package is not activated. Try activating it: %s', 'pods' ), 'wp pods-api activate-component --component=migrate-packages' ) ); } $replace = false; if ( ! empty( $assoc_args['replace'] ) ) { $replace = true; } $file = $assoc_args['file']; $imported = false; try { // Load PodsMigrate class file for use. pods_migrate(); // Only JSON format is supported for import. if ( false === strpos( $file, '.json' ) ) { WP_CLI::error( sprintf( __( 'Invalid file format, the file must use the .json extension: %s', 'pods' ), $file ) ); } $data = PodsMigrate::get_data_from_file( $file, true ); if ( empty( $data ) ) { WP_CLI::error( __( 'No Pods Package data found.', 'pods' ) ); } $imported = Pods_Migrate_Packages::import( $data, $replace ); } catch ( Exception $e ) { WP_CLI::error( sprintf( __( 'Error exporting Pods Package: %s', 'pods' ), $e->getMessage() ) ); } if ( ! empty( $imported ) ) { WP_CLI::success( __( 'Pods Package imported.', 'pods' ) ); } else { WP_CLI::error( __( 'Pods Package not imported.', 'pods' ) ); } }
php
public function import_pod( $args, $assoc_args ) { if ( ! PodsInit::$components->is_component_active( 'migrate-packages' ) ) { WP_CLI::error( sprintf( __( 'Migrate Package is not activated. Try activating it: %s', 'pods' ), 'wp pods-api activate-component --component=migrate-packages' ) ); } $replace = false; if ( ! empty( $assoc_args['replace'] ) ) { $replace = true; } $file = $assoc_args['file']; $imported = false; try { // Load PodsMigrate class file for use. pods_migrate(); // Only JSON format is supported for import. if ( false === strpos( $file, '.json' ) ) { WP_CLI::error( sprintf( __( 'Invalid file format, the file must use the .json extension: %s', 'pods' ), $file ) ); } $data = PodsMigrate::get_data_from_file( $file, true ); if ( empty( $data ) ) { WP_CLI::error( __( 'No Pods Package data found.', 'pods' ) ); } $imported = Pods_Migrate_Packages::import( $data, $replace ); } catch ( Exception $e ) { WP_CLI::error( sprintf( __( 'Error exporting Pods Package: %s', 'pods' ), $e->getMessage() ) ); } if ( ! empty( $imported ) ) { WP_CLI::success( __( 'Pods Package imported.', 'pods' ) ); } else { WP_CLI::error( __( 'Pods Package not imported.', 'pods' ) ); } }
[ "public", "function", "import_pod", "(", "$", "args", ",", "$", "assoc_args", ")", "{", "if", "(", "!", "PodsInit", "::", "$", "components", "->", "is_component_active", "(", "'migrate-packages'", ")", ")", "{", "WP_CLI", "::", "error", "(", "sprintf", "("...
Import a Pods Package from a file. ## OPTIONS --file=<file> : The file to save to including path (defaults to current path). [--replace] : Overwrite imported items if they already exist (defaults to false). ## EXAMPLES wp pods-api import-pod --file="pods-package.json" wp pods-api import-pod --file="/path/to/pods-package.json" wp pods-api import-pod --file="pods-package.json" --replace @subcommand import-pod
[ "Import", "a", "Pods", "Package", "from", "a", "file", "." ]
fd9a07c5c81ccbfcb21c5a0b2166f96c31d0826c
https://github.com/pods-framework/pods/blob/fd9a07c5c81ccbfcb21c5a0b2166f96c31d0826c/classes/cli/PodsAPI_CLI_Command.php#L461-L503
train
pods-framework/pods
classes/fields/time.php
PodsField_Time.format_time
public function format_time( $options, $js = false ) { switch ( (string) pods_v( static::$type . '_type', $options, '12', true ) ) { case '12': $time_format = $this->get_time_formats( $js ); $format = $time_format[ pods_v( static::$type . '_format', $options, 'hh_mm', true ) ]; break; case '24': $time_format_24 = $this->get_time_formats_24( $js ); $format = $time_format_24[ pods_v( static::$type . '_format_24', $options, 'hh_mm', true ) ]; break; case 'custom': if ( ! $js ) { $format = pods_v( static::$type . '_format_custom', $options, '' ); } else { $format = pods_v( static::$type . '_format_custom_js', $options, '' ); if ( empty( $format ) ) { $format = pods_v( static::$type . '_format_custom', $options, '' ); $format = $this->convert_format( $format, array( 'source' => 'php' ) ); } } break; default: $format = get_option( 'time_format' ); if ( $js ) { $format = $this->convert_format( $format, array( 'source' => 'php' ) ); } break; }//end switch return $format; }
php
public function format_time( $options, $js = false ) { switch ( (string) pods_v( static::$type . '_type', $options, '12', true ) ) { case '12': $time_format = $this->get_time_formats( $js ); $format = $time_format[ pods_v( static::$type . '_format', $options, 'hh_mm', true ) ]; break; case '24': $time_format_24 = $this->get_time_formats_24( $js ); $format = $time_format_24[ pods_v( static::$type . '_format_24', $options, 'hh_mm', true ) ]; break; case 'custom': if ( ! $js ) { $format = pods_v( static::$type . '_format_custom', $options, '' ); } else { $format = pods_v( static::$type . '_format_custom_js', $options, '' ); if ( empty( $format ) ) { $format = pods_v( static::$type . '_format_custom', $options, '' ); $format = $this->convert_format( $format, array( 'source' => 'php' ) ); } } break; default: $format = get_option( 'time_format' ); if ( $js ) { $format = $this->convert_format( $format, array( 'source' => 'php' ) ); } break; }//end switch return $format; }
[ "public", "function", "format_time", "(", "$", "options", ",", "$", "js", "=", "false", ")", "{", "switch", "(", "(", "string", ")", "pods_v", "(", "static", "::", "$", "type", ".", "'_type'", ",", "$", "options", ",", "'12'", ",", "true", ")", ")"...
Build time format string based on options @param array $options Field options. @param bool $js Return formatted from jQuery UI format? (only for custom formats). @return string @since 2.7.0
[ "Build", "time", "format", "string", "based", "on", "options" ]
fd9a07c5c81ccbfcb21c5a0b2166f96c31d0826c
https://github.com/pods-framework/pods/blob/fd9a07c5c81ccbfcb21c5a0b2166f96c31d0826c/classes/fields/time.php#L233-L264
train
pods-framework/pods
classes/fields/oembed.php
PodsField_OEmbed.get_providers
public function get_providers() { // Return class property if already set if ( ! empty( $this->providers ) ) { return $this->providers; } if ( file_exists( ABSPATH . WPINC . '/class-oembed.php' ) ) { require_once ABSPATH . WPINC . '/class-oembed.php'; } // Return an empty array if no providers could be found $providers = array(); if ( function_exists( '_wp_oembed_get_object' ) ) { $wp_oembed = _wp_oembed_get_object(); $providers = $wp_oembed->providers; foreach ( $providers as $key => $provider ) { $url = wp_parse_url( $provider[0] ); $host = $url['host']; $tmp = explode( '.', $host ); if ( count( $tmp ) === 3 ) { // Take domain names like .co.uk in consideration if ( ! in_array( 'co', $tmp, true ) ) { unset( $tmp[0] ); } } elseif ( count( $tmp ) === 4 ) { // Take domain names like .co.uk in consideration unset( $tmp[0] ); } $host = implode( '.', $tmp ); $providers[ $key ]['host'] = $host; } $this->providers = $providers; }//end if return $providers; }
php
public function get_providers() { // Return class property if already set if ( ! empty( $this->providers ) ) { return $this->providers; } if ( file_exists( ABSPATH . WPINC . '/class-oembed.php' ) ) { require_once ABSPATH . WPINC . '/class-oembed.php'; } // Return an empty array if no providers could be found $providers = array(); if ( function_exists( '_wp_oembed_get_object' ) ) { $wp_oembed = _wp_oembed_get_object(); $providers = $wp_oembed->providers; foreach ( $providers as $key => $provider ) { $url = wp_parse_url( $provider[0] ); $host = $url['host']; $tmp = explode( '.', $host ); if ( count( $tmp ) === 3 ) { // Take domain names like .co.uk in consideration if ( ! in_array( 'co', $tmp, true ) ) { unset( $tmp[0] ); } } elseif ( count( $tmp ) === 4 ) { // Take domain names like .co.uk in consideration unset( $tmp[0] ); } $host = implode( '.', $tmp ); $providers[ $key ]['host'] = $host; } $this->providers = $providers; }//end if return $providers; }
[ "public", "function", "get_providers", "(", ")", "{", "// Return class property if already set", "if", "(", "!", "empty", "(", "$", "this", "->", "providers", ")", ")", "{", "return", "$", "this", "->", "providers", ";", "}", "if", "(", "file_exists", "(", ...
Get a list of available providers from the WP_oEmbed class @see wp-includes/class-oembed.php @return array $providers { Array of provider data with regex as key @type string URL for this provider @type int @type string Hostname for this provider } @since 2.7.0
[ "Get", "a", "list", "of", "available", "providers", "from", "the", "WP_oEmbed", "class" ]
fd9a07c5c81ccbfcb21c5a0b2166f96c31d0826c
https://github.com/pods-framework/pods/blob/fd9a07c5c81ccbfcb21c5a0b2166f96c31d0826c/classes/fields/oembed.php#L341-L384
train
pods-framework/pods
classes/fields/oembed.php
PodsField_OEmbed.get_provider
public function get_provider( $url ) { $provider = false; foreach ( $this->providers as $matchmask => $data ) { if ( isset( $data['host'] ) ) { unset( $data['host'] ); } reset( $data ); list( $providerurl, $regex ) = $data; $match = $matchmask; // Turn the asterisk-type provider URLs into regex if ( ! $regex ) { $matchmask = '#' . str_replace( '___wildcard___', '(.+)', preg_quote( str_replace( '*', '___wildcard___', $matchmask ), '#' ) ) . '#i'; $matchmask = preg_replace( '|^#http\\\://|', '#https?\://', $matchmask ); } if ( preg_match( $matchmask, $url ) ) { $provider = $match; break; } }//end foreach return $provider; }
php
public function get_provider( $url ) { $provider = false; foreach ( $this->providers as $matchmask => $data ) { if ( isset( $data['host'] ) ) { unset( $data['host'] ); } reset( $data ); list( $providerurl, $regex ) = $data; $match = $matchmask; // Turn the asterisk-type provider URLs into regex if ( ! $regex ) { $matchmask = '#' . str_replace( '___wildcard___', '(.+)', preg_quote( str_replace( '*', '___wildcard___', $matchmask ), '#' ) ) . '#i'; $matchmask = preg_replace( '|^#http\\\://|', '#https?\://', $matchmask ); } if ( preg_match( $matchmask, $url ) ) { $provider = $match; break; } }//end foreach return $provider; }
[ "public", "function", "get_provider", "(", "$", "url", ")", "{", "$", "provider", "=", "false", ";", "foreach", "(", "$", "this", "->", "providers", "as", "$", "matchmask", "=>", "$", "data", ")", "{", "if", "(", "isset", "(", "$", "data", "[", "'h...
Takes a URL and returns the corresponding oEmbed provider's URL, if there is one. This function is ripped from WP since Pods has support from 3.8 and in the WP core this function is 4.0+ We've stripped the autodiscover part from this function to keep it basic @since 2.7.0 @access public @see WP_oEmbed::get_provider() @param string $url The URL to the content. @return false|string False on failure, otherwise the oEmbed provider URL.
[ "Takes", "a", "URL", "and", "returns", "the", "corresponding", "oEmbed", "provider", "s", "URL", "if", "there", "is", "one", ".", "This", "function", "is", "ripped", "from", "WP", "since", "Pods", "has", "support", "from", "3", ".", "8", "and", "in", "...
fd9a07c5c81ccbfcb21c5a0b2166f96c31d0826c
https://github.com/pods-framework/pods/blob/fd9a07c5c81ccbfcb21c5a0b2166f96c31d0826c/classes/fields/oembed.php#L400-L428
train