repository_name stringlengths 5 67 | func_path_in_repository stringlengths 4 234 | func_name stringlengths 0 314 | whole_func_string stringlengths 52 3.87M | language stringclasses 6 values | func_code_string stringlengths 52 3.87M | func_code_tokens listlengths 15 672k | func_documentation_string stringlengths 1 47.2k | func_documentation_tokens listlengths 1 3.92k | split_name stringclasses 1 value | func_code_url stringlengths 85 339 |
|---|---|---|---|---|---|---|---|---|---|---|
TYPO3/Surf | src/Task/TYPO3/CMS/SetUpExtensionsTask.php | SetUpExtensionsTask.execute | public function execute(Node $node, Application $application, Deployment $deployment, array $options = [])
{
$this->ensureApplicationIsTypo3Cms($application);
try {
$scriptFileName = $this->getConsoleScriptFileName($node, $application, $deployment, $options);
} catch (InvalidConfigurationException $e) {
$deployment->getLogger()->warning('TYPO3 Console script (' . $options['scriptFileName'] . ') was not found! Make sure it is available in your project, you set the "scriptFileName" option correctly or remove this task (' . __CLASS__ . ') in your deployment configuration!');
return;
}
$options = $this->configureOptions($options);
$commandArguments = [$scriptFileName];
if (empty($options['extensionKeys'])) {
$commandArguments[] = 'extension:setupactive';
} else {
$commandArguments[] = 'extension:setup';
$commandArguments[] = implode(',', $options['extensionKeys']);
}
$this->executeCliCommand(
$commandArguments,
$node,
$application,
$deployment,
$options
);
} | php | public function execute(Node $node, Application $application, Deployment $deployment, array $options = [])
{
$this->ensureApplicationIsTypo3Cms($application);
try {
$scriptFileName = $this->getConsoleScriptFileName($node, $application, $deployment, $options);
} catch (InvalidConfigurationException $e) {
$deployment->getLogger()->warning('TYPO3 Console script (' . $options['scriptFileName'] . ') was not found! Make sure it is available in your project, you set the "scriptFileName" option correctly or remove this task (' . __CLASS__ . ') in your deployment configuration!');
return;
}
$options = $this->configureOptions($options);
$commandArguments = [$scriptFileName];
if (empty($options['extensionKeys'])) {
$commandArguments[] = 'extension:setupactive';
} else {
$commandArguments[] = 'extension:setup';
$commandArguments[] = implode(',', $options['extensionKeys']);
}
$this->executeCliCommand(
$commandArguments,
$node,
$application,
$deployment,
$options
);
} | [
"public",
"function",
"execute",
"(",
"Node",
"$",
"node",
",",
"Application",
"$",
"application",
",",
"Deployment",
"$",
"deployment",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"this",
"->",
"ensureApplicationIsTypo3Cms",
"(",
"$",
"app... | Execute this task
@param \TYPO3\Surf\Domain\Model\Node $node
@param CMS|\TYPO3\Surf\Domain\Model\Application $application
@param \TYPO3\Surf\Domain\Model\Deployment $deployment
@param array $options
@throws \TYPO3\Surf\Exception\InvalidConfigurationException | [
"Execute",
"this",
"task"
] | train | https://github.com/TYPO3/Surf/blob/0292b88a0cd21dd96174f3306deb98952a0c03a7/src/Task/TYPO3/CMS/SetUpExtensionsTask.php#L35-L63 |
TYPO3/Surf | src/Application/Neos/Flow.php | Flow.registerTasks | public function registerTasks(Workflow $workflow, Deployment $deployment)
{
parent::registerTasks($workflow, $deployment);
$workflow
->addTask(CreateDirectoriesTask::class, 'initialize', $this)
->afterStage('update', [
SymlinkDataTask::class,
SymlinkConfigurationTask::class,
CopyConfigurationTask::class
], $this)
->addTask(MigrateTask::class, 'migrate', $this)
->addTask(PublishResourcesTask::class, 'finalize', $this);
} | php | public function registerTasks(Workflow $workflow, Deployment $deployment)
{
parent::registerTasks($workflow, $deployment);
$workflow
->addTask(CreateDirectoriesTask::class, 'initialize', $this)
->afterStage('update', [
SymlinkDataTask::class,
SymlinkConfigurationTask::class,
CopyConfigurationTask::class
], $this)
->addTask(MigrateTask::class, 'migrate', $this)
->addTask(PublishResourcesTask::class, 'finalize', $this);
} | [
"public",
"function",
"registerTasks",
"(",
"Workflow",
"$",
"workflow",
",",
"Deployment",
"$",
"deployment",
")",
"{",
"parent",
"::",
"registerTasks",
"(",
"$",
"workflow",
",",
"$",
"deployment",
")",
";",
"$",
"workflow",
"->",
"addTask",
"(",
"CreateDi... | Register tasks for this application
@param Workflow $workflow
@param Deployment $deployment | [
"Register",
"tasks",
"for",
"this",
"application"
] | train | https://github.com/TYPO3/Surf/blob/0292b88a0cd21dd96174f3306deb98952a0c03a7/src/Application/Neos/Flow.php#L54-L67 |
TYPO3/Surf | src/Application/Neos/Flow.php | Flow.registerTasksForUpdateMethod | protected function registerTasksForUpdateMethod(Workflow $workflow, $updateMethod)
{
switch ($updateMethod) {
case 'composer':
$workflow->addTask(InstallTask::class, 'update', $this);
break;
default:
parent::registerTasksForUpdateMethod($workflow, $updateMethod);
break;
}
} | php | protected function registerTasksForUpdateMethod(Workflow $workflow, $updateMethod)
{
switch ($updateMethod) {
case 'composer':
$workflow->addTask(InstallTask::class, 'update', $this);
break;
default:
parent::registerTasksForUpdateMethod($workflow, $updateMethod);
break;
}
} | [
"protected",
"function",
"registerTasksForUpdateMethod",
"(",
"Workflow",
"$",
"workflow",
",",
"$",
"updateMethod",
")",
"{",
"switch",
"(",
"$",
"updateMethod",
")",
"{",
"case",
"'composer'",
":",
"$",
"workflow",
"->",
"addTask",
"(",
"InstallTask",
"::",
... | Add support for updateMethod "composer"
@param Workflow $workflow
@param string $updateMethod | [
"Add",
"support",
"for",
"updateMethod",
"composer"
] | train | https://github.com/TYPO3/Surf/blob/0292b88a0cd21dd96174f3306deb98952a0c03a7/src/Application/Neos/Flow.php#L75-L85 |
TYPO3/Surf | src/Application/Neos/Flow.php | Flow.buildCommand | public function buildCommand($targetPath, $command, array $arguments = [])
{
return 'cd ' . $targetPath . ' && FLOW_CONTEXT=' . $this->getContext() .
' ./' . $this->getFlowScriptName() . ' ' . $this->getCommandPackageKey($command) . ':' . $command . ' '
. implode(' ', array_map('escapeshellarg', $arguments));
} | php | public function buildCommand($targetPath, $command, array $arguments = [])
{
return 'cd ' . $targetPath . ' && FLOW_CONTEXT=' . $this->getContext() .
' ./' . $this->getFlowScriptName() . ' ' . $this->getCommandPackageKey($command) . ':' . $command . ' '
. implode(' ', array_map('escapeshellarg', $arguments));
} | [
"public",
"function",
"buildCommand",
"(",
"$",
"targetPath",
",",
"$",
"command",
",",
"array",
"$",
"arguments",
"=",
"[",
"]",
")",
"{",
"return",
"'cd '",
".",
"$",
"targetPath",
".",
"' && FLOW_CONTEXT='",
".",
"$",
"this",
"->",
"getContext",
"(",
... | Returns a executable flow command including the context
@param string $targetPath the path where the command should be executed
@param string $command the actual command for example `cache:flush`
@param array $arguments list of arguments which will be appended to the command
@return string | [
"Returns",
"a",
"executable",
"flow",
"command",
"including",
"the",
"context"
] | train | https://github.com/TYPO3/Surf/blob/0292b88a0cd21dd96174f3306deb98952a0c03a7/src/Application/Neos/Flow.php#L180-L185 |
TYPO3/Surf | src/Task/LocalShellTask.php | LocalShellTask.execute | public function execute(Node $node, Application $application, Deployment $deployment, array $options = [])
{
$replacePaths = [];
$replacePaths['{workspacePath}'] = escapeshellarg($deployment->getWorkspacePath($application));
if (!isset($options['command'])) {
throw new InvalidConfigurationException('Missing "command" option for LocalShellTask', 1311168045);
}
$command = $options['command'];
$command = str_replace(array_keys($replacePaths), $replacePaths, $command);
$ignoreErrors = isset($options['ignoreErrors']) && $options['ignoreErrors'] === true;
$logOutput = !(isset($options['logOutput']) && $options['logOutput'] === false);
$localhost = new Node('localhost');
$localhost->onLocalhost();
$this->shell->executeOrSimulate($command, $localhost, $deployment, $ignoreErrors, $logOutput);
} | php | public function execute(Node $node, Application $application, Deployment $deployment, array $options = [])
{
$replacePaths = [];
$replacePaths['{workspacePath}'] = escapeshellarg($deployment->getWorkspacePath($application));
if (!isset($options['command'])) {
throw new InvalidConfigurationException('Missing "command" option for LocalShellTask', 1311168045);
}
$command = $options['command'];
$command = str_replace(array_keys($replacePaths), $replacePaths, $command);
$ignoreErrors = isset($options['ignoreErrors']) && $options['ignoreErrors'] === true;
$logOutput = !(isset($options['logOutput']) && $options['logOutput'] === false);
$localhost = new Node('localhost');
$localhost->onLocalhost();
$this->shell->executeOrSimulate($command, $localhost, $deployment, $ignoreErrors, $logOutput);
} | [
"public",
"function",
"execute",
"(",
"Node",
"$",
"node",
",",
"Application",
"$",
"application",
",",
"Deployment",
"$",
"deployment",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"replacePaths",
"=",
"[",
"]",
";",
"$",
"replacePaths",
... | Execute this task
@param \TYPO3\Surf\Domain\Model\Node $node
@param \TYPO3\Surf\Domain\Model\Application $application
@param \TYPO3\Surf\Domain\Model\Deployment $deployment
@param array $options
@throws \TYPO3\Surf\Exception\InvalidConfigurationException | [
"Execute",
"this",
"task"
] | train | https://github.com/TYPO3/Surf/blob/0292b88a0cd21dd96174f3306deb98952a0c03a7/src/Task/LocalShellTask.php#L50-L68 |
TYPO3/Surf | src/Task/LocalShellTask.php | LocalShellTask.rollback | public function rollback(Node $node, Application $application, Deployment $deployment, array $options = [])
{
$replacePaths = [];
$replacePaths['{workspacePath}'] = escapeshellarg($deployment->getWorkspacePath($application));
if (!isset($options['rollbackCommand'])) {
return;
}
$command = $options['rollbackCommand'];
$command = str_replace(array_keys($replacePaths), $replacePaths, $command);
$localhost = new Node('localhost');
$localhost->onLocalhost();
$this->shell->execute($command, $localhost, $deployment, true);
} | php | public function rollback(Node $node, Application $application, Deployment $deployment, array $options = [])
{
$replacePaths = [];
$replacePaths['{workspacePath}'] = escapeshellarg($deployment->getWorkspacePath($application));
if (!isset($options['rollbackCommand'])) {
return;
}
$command = $options['rollbackCommand'];
$command = str_replace(array_keys($replacePaths), $replacePaths, $command);
$localhost = new Node('localhost');
$localhost->onLocalhost();
$this->shell->execute($command, $localhost, $deployment, true);
} | [
"public",
"function",
"rollback",
"(",
"Node",
"$",
"node",
",",
"Application",
"$",
"application",
",",
"Deployment",
"$",
"deployment",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"replacePaths",
"=",
"[",
"]",
";",
"$",
"replacePaths",... | Rollback this task
@param \TYPO3\Surf\Domain\Model\Node $node
@param \TYPO3\Surf\Domain\Model\Application $application
@param \TYPO3\Surf\Domain\Model\Deployment $deployment
@param array $options | [
"Rollback",
"this",
"task"
] | train | https://github.com/TYPO3/Surf/blob/0292b88a0cd21dd96174f3306deb98952a0c03a7/src/Task/LocalShellTask.php#L91-L106 |
TYPO3/Surf | src/Task/Generic/CreateSymlinksTask.php | CreateSymlinksTask.execute | public function execute(Node $node, Application $application, Deployment $deployment, array $options = [])
{
$options = $this->configureOptions($options);
if (empty($options['symlinks'])) {
return;
}
$baseDirectory = $options['genericSymlinksBaseDir'] ?: $deployment->getApplicationReleasePath($application);
$commands = [
'cd ' . $baseDirectory,
];
foreach ($options['symlinks'] as $linkPath => $sourcePath) {
$commands[] = sprintf('ln -s %s %s', $sourcePath, $linkPath);
}
$this->shell->executeOrSimulate($commands, $node, $deployment);
} | php | public function execute(Node $node, Application $application, Deployment $deployment, array $options = [])
{
$options = $this->configureOptions($options);
if (empty($options['symlinks'])) {
return;
}
$baseDirectory = $options['genericSymlinksBaseDir'] ?: $deployment->getApplicationReleasePath($application);
$commands = [
'cd ' . $baseDirectory,
];
foreach ($options['symlinks'] as $linkPath => $sourcePath) {
$commands[] = sprintf('ln -s %s %s', $sourcePath, $linkPath);
}
$this->shell->executeOrSimulate($commands, $node, $deployment);
} | [
"public",
"function",
"execute",
"(",
"Node",
"$",
"node",
",",
"Application",
"$",
"application",
",",
"Deployment",
"$",
"deployment",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"options",
"=",
"$",
"this",
"->",
"configureOptions",
"(... | Execute this task
@param \TYPO3\Surf\Domain\Model\Node $node
@param \TYPO3\Surf\Domain\Model\Application $application
@param \TYPO3\Surf\Domain\Model\Deployment $deployment
@param array $options | [
"Execute",
"this",
"task"
] | train | https://github.com/TYPO3/Surf/blob/0292b88a0cd21dd96174f3306deb98952a0c03a7/src/Task/Generic/CreateSymlinksTask.php#L47-L66 |
TYPO3/Surf | src/Task/CreateDirectoriesTask.php | CreateDirectoriesTask.execute | public function execute(Node $node, Application $application, Deployment $deployment, array $options = [])
{
$deploymentPath = $application->getDeploymentPath();
$sharedPath = $application->getSharedPath();
$releasesPath = $application->getReleasesPath();
$releaseIdentifier = $deployment->getReleaseIdentifier();
$releasePath = $deployment->getApplicationReleasePath($application);
$result = $this->shell->execute('test -d ' . $deploymentPath, $node, $deployment, true);
if ($result === false) {
throw new TaskExecutionException('Deployment directory "' . $deploymentPath . '" does not exist on node ' . $node->getName(), 1311003253);
}
$commands = [
'mkdir -p ' . $releasesPath,
'mkdir -p ' . $sharedPath,
'mkdir -p ' . $releasePath,
'cd ' . $releasesPath . ';ln -snf ./' . $releaseIdentifier . ' next'
];
$this->shell->executeOrSimulate($commands, $node, $deployment);
} | php | public function execute(Node $node, Application $application, Deployment $deployment, array $options = [])
{
$deploymentPath = $application->getDeploymentPath();
$sharedPath = $application->getSharedPath();
$releasesPath = $application->getReleasesPath();
$releaseIdentifier = $deployment->getReleaseIdentifier();
$releasePath = $deployment->getApplicationReleasePath($application);
$result = $this->shell->execute('test -d ' . $deploymentPath, $node, $deployment, true);
if ($result === false) {
throw new TaskExecutionException('Deployment directory "' . $deploymentPath . '" does not exist on node ' . $node->getName(), 1311003253);
}
$commands = [
'mkdir -p ' . $releasesPath,
'mkdir -p ' . $sharedPath,
'mkdir -p ' . $releasePath,
'cd ' . $releasesPath . ';ln -snf ./' . $releaseIdentifier . ' next'
];
$this->shell->executeOrSimulate($commands, $node, $deployment);
} | [
"public",
"function",
"execute",
"(",
"Node",
"$",
"node",
",",
"Application",
"$",
"application",
",",
"Deployment",
"$",
"deployment",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"deploymentPath",
"=",
"$",
"application",
"->",
"getDeploy... | Executes this task
@param \TYPO3\Surf\Domain\Model\Node $node
@param \TYPO3\Surf\Domain\Model\Application $application
@param \TYPO3\Surf\Domain\Model\Deployment $deployment
@param array $options
@throws \TYPO3\Surf\Exception\TaskExecutionException | [
"Executes",
"this",
"task"
] | train | https://github.com/TYPO3/Surf/blob/0292b88a0cd21dd96174f3306deb98952a0c03a7/src/Task/CreateDirectoriesTask.php#L44-L62 |
TYPO3/Surf | src/Task/Composer/AbstractComposerTask.php | AbstractComposerTask.buildComposerCommands | protected function buildComposerCommands($manifestPath, array $options)
{
if (!isset($options['composerCommandPath'])) {
throw new TaskExecutionException('Composer command not found. Set the composerCommandPath option.', 1349163257);
}
$additionalArguments = [];
if (isset($options['additionalArguments'])) {
$additionalArguments = (array)$options['additionalArguments'];
}
$arguments = array_merge(
[escapeshellcmd($options['composerCommandPath']), $this->command],
$this->arguments,
array_map('escapeshellarg', $additionalArguments),
$this->suffix
);
$script = implode(' ', $arguments);
return [
'cd ' . escapeshellarg($manifestPath),
$script,
];
} | php | protected function buildComposerCommands($manifestPath, array $options)
{
if (!isset($options['composerCommandPath'])) {
throw new TaskExecutionException('Composer command not found. Set the composerCommandPath option.', 1349163257);
}
$additionalArguments = [];
if (isset($options['additionalArguments'])) {
$additionalArguments = (array)$options['additionalArguments'];
}
$arguments = array_merge(
[escapeshellcmd($options['composerCommandPath']), $this->command],
$this->arguments,
array_map('escapeshellarg', $additionalArguments),
$this->suffix
);
$script = implode(' ', $arguments);
return [
'cd ' . escapeshellarg($manifestPath),
$script,
];
} | [
"protected",
"function",
"buildComposerCommands",
"(",
"$",
"manifestPath",
",",
"array",
"$",
"options",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"options",
"[",
"'composerCommandPath'",
"]",
")",
")",
"{",
"throw",
"new",
"TaskExecutionException",
"(",
... | Build the composer command in the given $path.
@param string $manifestPath
@param array $options
@return array
@throws \TYPO3\Surf\Exception\TaskExecutionException | [
"Build",
"the",
"composer",
"command",
"in",
"the",
"given",
"$path",
"."
] | train | https://github.com/TYPO3/Surf/blob/0292b88a0cd21dd96174f3306deb98952a0c03a7/src/Task/Composer/AbstractComposerTask.php#L101-L124 |
TYPO3/Surf | src/Task/Composer/AbstractComposerTask.php | AbstractComposerTask.composerManifestExists | protected function composerManifestExists($path, Node $node, Deployment $deployment)
{
// In dry run mode, no checkout is there, this we must not assume a composer.json is there!
if ($deployment->isDryRun()) {
return false;
}
$composerJsonPath = Files::concatenatePaths([$path, 'composer.json']);
$composerJsonExists = $this->shell->executeOrSimulate('test -f ' . escapeshellarg($composerJsonPath), $node, $deployment, true);
if ($composerJsonExists === false) {
$deployment->getLogger()->debug('No composer.json found in path "' . $composerJsonPath . '"');
return false;
}
return true;
} | php | protected function composerManifestExists($path, Node $node, Deployment $deployment)
{
// In dry run mode, no checkout is there, this we must not assume a composer.json is there!
if ($deployment->isDryRun()) {
return false;
}
$composerJsonPath = Files::concatenatePaths([$path, 'composer.json']);
$composerJsonExists = $this->shell->executeOrSimulate('test -f ' . escapeshellarg($composerJsonPath), $node, $deployment, true);
if ($composerJsonExists === false) {
$deployment->getLogger()->debug('No composer.json found in path "' . $composerJsonPath . '"');
return false;
}
return true;
} | [
"protected",
"function",
"composerManifestExists",
"(",
"$",
"path",
",",
"Node",
"$",
"node",
",",
"Deployment",
"$",
"deployment",
")",
"{",
"// In dry run mode, no checkout is there, this we must not assume a composer.json is there!",
"if",
"(",
"$",
"deployment",
"->",
... | Checks if a composer manifest exists in the directory at the given path.
If no manifest exists, a log message is recorded.
@param string $path
@param \TYPO3\Surf\Domain\Model\Node $node
@param \TYPO3\Surf\Domain\Model\Deployment $deployment
@return bool | [
"Checks",
"if",
"a",
"composer",
"manifest",
"exists",
"in",
"the",
"directory",
"at",
"the",
"given",
"path",
"."
] | train | https://github.com/TYPO3/Surf/blob/0292b88a0cd21dd96174f3306deb98952a0c03a7/src/Task/Composer/AbstractComposerTask.php#L136-L150 |
TYPO3/Surf | src/Cli/Symfony/Logger/ConsoleFormatter.php | ConsoleFormatter.format | public function format(array $record)
{
if ($record['level'] >= Logger::ERROR) {
$record['start_tag'] = '<error>';
$record['end_tag'] = '</error>';
} elseif ($record['level'] >= Logger::NOTICE) {
$record['start_tag'] = '<comment>';
$record['end_tag'] = '</comment>';
} elseif ($record['level'] >= Logger::INFO) {
$record['start_tag'] = '<info>';
$record['end_tag'] = '</info>';
} else {
$record['start_tag'] = '<debug>';
$record['end_tag'] = '</debug>';
}
return parent::format($record);
} | php | public function format(array $record)
{
if ($record['level'] >= Logger::ERROR) {
$record['start_tag'] = '<error>';
$record['end_tag'] = '</error>';
} elseif ($record['level'] >= Logger::NOTICE) {
$record['start_tag'] = '<comment>';
$record['end_tag'] = '</comment>';
} elseif ($record['level'] >= Logger::INFO) {
$record['start_tag'] = '<info>';
$record['end_tag'] = '</info>';
} else {
$record['start_tag'] = '<debug>';
$record['end_tag'] = '</debug>';
}
return parent::format($record);
} | [
"public",
"function",
"format",
"(",
"array",
"$",
"record",
")",
"{",
"if",
"(",
"$",
"record",
"[",
"'level'",
"]",
">=",
"Logger",
"::",
"ERROR",
")",
"{",
"$",
"record",
"[",
"'start_tag'",
"]",
"=",
"'<error>'",
";",
"$",
"record",
"[",
"'end_ta... | {@inheritdoc} | [
"{"
] | train | https://github.com/TYPO3/Surf/blob/0292b88a0cd21dd96174f3306deb98952a0c03a7/src/Cli/Symfony/Logger/ConsoleFormatter.php#L27-L44 |
TYPO3/Surf | src/Task/Git/TagTask.php | TagTask.execute | public function execute(Node $node, Application $application, Deployment $deployment, array $options = [])
{
$this->validateOptions($options);
$options = $this->processOptions($options, $deployment);
$targetPath = $deployment->getApplicationReleasePath($application);
$this->shell->executeOrSimulate(sprintf('cd ' . $targetPath . '; git tag -f -a -m %s %s', escapeshellarg($options['description']), escapeshellarg($options['tagName'])), $node, $deployment);
if (isset($options['recurseIntoSubmodules']) && $options['recurseIntoSubmodules'] === true) {
$submoduleCommand = escapeshellarg(sprintf('git tag -f -a -m %s %s', escapeshellarg($options['description']), escapeshellarg($options['submoduleTagNamePrefix'] . $options['tagName'])));
$this->shell->executeOrSimulate(sprintf('cd ' . $targetPath . '; git submodule foreach %s', $submoduleCommand), $node, $deployment);
}
if (isset($options['pushTag']) && $options['pushTag'] === true) {
$this->shell->executeOrSimulate(sprintf('cd ' . $targetPath . '; git push %s %s', escapeshellarg($options['remote']), escapeshellarg($options['tagName'])), $node, $deployment);
if (isset($options['recurseIntoSubmodules']) && $options['recurseIntoSubmodules'] === true) {
$submoduleCommand = escapeshellarg(sprintf('git push %s %s', escapeshellarg($options['remote']), escapeshellarg($options['submoduleTagNamePrefix'] . $options['tagName'])));
$this->shell->executeOrSimulate(sprintf('cd ' . $targetPath . '; git submodule foreach %s', $submoduleCommand), $node, $deployment);
}
}
} | php | public function execute(Node $node, Application $application, Deployment $deployment, array $options = [])
{
$this->validateOptions($options);
$options = $this->processOptions($options, $deployment);
$targetPath = $deployment->getApplicationReleasePath($application);
$this->shell->executeOrSimulate(sprintf('cd ' . $targetPath . '; git tag -f -a -m %s %s', escapeshellarg($options['description']), escapeshellarg($options['tagName'])), $node, $deployment);
if (isset($options['recurseIntoSubmodules']) && $options['recurseIntoSubmodules'] === true) {
$submoduleCommand = escapeshellarg(sprintf('git tag -f -a -m %s %s', escapeshellarg($options['description']), escapeshellarg($options['submoduleTagNamePrefix'] . $options['tagName'])));
$this->shell->executeOrSimulate(sprintf('cd ' . $targetPath . '; git submodule foreach %s', $submoduleCommand), $node, $deployment);
}
if (isset($options['pushTag']) && $options['pushTag'] === true) {
$this->shell->executeOrSimulate(sprintf('cd ' . $targetPath . '; git push %s %s', escapeshellarg($options['remote']), escapeshellarg($options['tagName'])), $node, $deployment);
if (isset($options['recurseIntoSubmodules']) && $options['recurseIntoSubmodules'] === true) {
$submoduleCommand = escapeshellarg(sprintf('git push %s %s', escapeshellarg($options['remote']), escapeshellarg($options['submoduleTagNamePrefix'] . $options['tagName'])));
$this->shell->executeOrSimulate(sprintf('cd ' . $targetPath . '; git submodule foreach %s', $submoduleCommand), $node, $deployment);
}
}
} | [
"public",
"function",
"execute",
"(",
"Node",
"$",
"node",
",",
"Application",
"$",
"application",
",",
"Deployment",
"$",
"deployment",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"this",
"->",
"validateOptions",
"(",
"$",
"options",
")"... | Execute this task
@param \TYPO3\Surf\Domain\Model\Node $node
@param \TYPO3\Surf\Domain\Model\Application $application
@param \TYPO3\Surf\Domain\Model\Deployment $deployment
@param array $options
@throws \TYPO3\Surf\Exception\InvalidConfigurationException | [
"Execute",
"this",
"task"
] | train | https://github.com/TYPO3/Surf/blob/0292b88a0cd21dd96174f3306deb98952a0c03a7/src/Task/Git/TagTask.php#L53-L72 |
TYPO3/Surf | src/Task/Git/TagTask.php | TagTask.processOptions | protected function processOptions(array $options, Deployment $deployment)
{
foreach (['tagName', 'description'] as $optionName) {
$options[$optionName] = str_replace(
[
'{releaseIdentifier}',
'{deploymentName}'
],
[
$deployment->getReleaseIdentifier(),
$deployment->getName()
],
$options[$optionName]
);
}
if (!isset($options['submoduleTagNamePrefix'])) {
$options['submoduleTagNamePrefix'] = '';
}
if (!isset($options['remote'])) {
$options['remote'] = 'origin';
return $options;
}
return $options;
} | php | protected function processOptions(array $options, Deployment $deployment)
{
foreach (['tagName', 'description'] as $optionName) {
$options[$optionName] = str_replace(
[
'{releaseIdentifier}',
'{deploymentName}'
],
[
$deployment->getReleaseIdentifier(),
$deployment->getName()
],
$options[$optionName]
);
}
if (!isset($options['submoduleTagNamePrefix'])) {
$options['submoduleTagNamePrefix'] = '';
}
if (!isset($options['remote'])) {
$options['remote'] = 'origin';
return $options;
}
return $options;
} | [
"protected",
"function",
"processOptions",
"(",
"array",
"$",
"options",
",",
"Deployment",
"$",
"deployment",
")",
"{",
"foreach",
"(",
"[",
"'tagName'",
",",
"'description'",
"]",
"as",
"$",
"optionName",
")",
"{",
"$",
"options",
"[",
"$",
"optionName",
... | Replace placeholders in option values and set default values
@param array $options
@param \TYPO3\Surf\Domain\Model\Deployment $deployment
@return array | [
"Replace",
"placeholders",
"in",
"option",
"values",
"and",
"set",
"default",
"values"
] | train | https://github.com/TYPO3/Surf/blob/0292b88a0cd21dd96174f3306deb98952a0c03a7/src/Task/Git/TagTask.php#L109-L134 |
TYPO3/Surf | src/Task/Php/WebOpcacheResetExecuteTask.php | WebOpcacheResetExecuteTask.execute | public function execute(Node $node, Application $application, Deployment $deployment, array $options = [])
{
$options = $this->configureOptions($options);
$scriptUrl = sprintf('%s/surf-opcache-reset-%s.php', $options['baseUrl'], $options['scriptIdentifier']);
$result = $this->filesystem->get($scriptUrl, false, $options['stream_context']);
if ($result !== 'success') {
if ($options['throwErrorOnWebOpCacheResetExecuteTask']) {
throw TaskExecutionException::webOpcacheResetExecuteTaskDidNotReturnExpectedResult($scriptUrl);
}
$deployment->getLogger()->warning(sprintf('Executing PHP opcache reset script at "%s" did not return expected result', $scriptUrl));
}
} | php | public function execute(Node $node, Application $application, Deployment $deployment, array $options = [])
{
$options = $this->configureOptions($options);
$scriptUrl = sprintf('%s/surf-opcache-reset-%s.php', $options['baseUrl'], $options['scriptIdentifier']);
$result = $this->filesystem->get($scriptUrl, false, $options['stream_context']);
if ($result !== 'success') {
if ($options['throwErrorOnWebOpCacheResetExecuteTask']) {
throw TaskExecutionException::webOpcacheResetExecuteTaskDidNotReturnExpectedResult($scriptUrl);
}
$deployment->getLogger()->warning(sprintf('Executing PHP opcache reset script at "%s" did not return expected result', $scriptUrl));
}
} | [
"public",
"function",
"execute",
"(",
"Node",
"$",
"node",
",",
"Application",
"$",
"application",
",",
"Deployment",
"$",
"deployment",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"options",
"=",
"$",
"this",
"->",
"configureOptions",
"(... | Execute this task
@param \TYPO3\Surf\Domain\Model\Node $node
@param \TYPO3\Surf\Domain\Model\Application $application
@param \TYPO3\Surf\Domain\Model\Deployment $deployment
@param array $options Supported options: "baseUrl" (required) and "scriptIdentifier" (is passed by the create script task)
@throws \TYPO3\Surf\Exception\InvalidConfigurationException
@throws \TYPO3\Surf\Exception\TaskExecutionException | [
"Execute",
"this",
"task"
] | train | https://github.com/TYPO3/Surf/blob/0292b88a0cd21dd96174f3306deb98952a0c03a7/src/Task/Php/WebOpcacheResetExecuteTask.php#L77-L92 |
larapack/voyager-hooks | src/VoyagerHooksServiceProvider.php | VoyagerHooksServiceProvider.register | public function register()
{
$configPath = dirname(__DIR__).'/publishable/config/voyager-hooks.php';
$this->mergeConfigFrom($configPath, 'voyager-hooks');
// Register the HooksServiceProvider
$this->app->register(HooksServiceProvider::class);
if (!$this->enabled()) {
return;
}
if ($this->app->runningInConsole()) {
$this->publishes(
[$configPath => config_path('voyager-hooks.php')],
'voyager-hooks-config'
);
}
// Load views
$this->loadViewsFrom(__DIR__.'/../resources/views', 'voyager-hooks');
} | php | public function register()
{
$configPath = dirname(__DIR__).'/publishable/config/voyager-hooks.php';
$this->mergeConfigFrom($configPath, 'voyager-hooks');
// Register the HooksServiceProvider
$this->app->register(HooksServiceProvider::class);
if (!$this->enabled()) {
return;
}
if ($this->app->runningInConsole()) {
$this->publishes(
[$configPath => config_path('voyager-hooks.php')],
'voyager-hooks-config'
);
}
// Load views
$this->loadViewsFrom(__DIR__.'/../resources/views', 'voyager-hooks');
} | [
"public",
"function",
"register",
"(",
")",
"{",
"$",
"configPath",
"=",
"dirname",
"(",
"__DIR__",
")",
".",
"'/publishable/config/voyager-hooks.php'",
";",
"$",
"this",
"->",
"mergeConfigFrom",
"(",
"$",
"configPath",
",",
"'voyager-hooks'",
")",
";",
"// Regi... | Register the application services. | [
"Register",
"the",
"application",
"services",
"."
] | train | https://github.com/larapack/voyager-hooks/blob/5de5a5f06c8359c7f09fb1bb9acd84b3f5379506/src/VoyagerHooksServiceProvider.php#L19-L41 |
larapack/voyager-hooks | src/VoyagerHooksServiceProvider.php | VoyagerHooksServiceProvider.boot | public function boot(Dispatcher $events)
{
if (!$this->enabled()) {
return;
}
if (config('voyager-hooks.add-route', true)) {
$events->listen('voyager.admin.routing', [$this, 'addHookRoute']);
}
if (config('voyager-hooks.add-hook-menu-item', true)) {
$events->listen(Setup::class, [$this, 'addHookMenuItem']);
}
if (config('voyager-hooks.add-hook-permissions', true)) {
$events->listen(Setup::class, [$this, 'addHookPermissions']);
}
if (config('voyager-hooks.publish-vendor-files', true)) {
$events->listen(Setup::class, [$this, 'publishVendorFiles']);
}
} | php | public function boot(Dispatcher $events)
{
if (!$this->enabled()) {
return;
}
if (config('voyager-hooks.add-route', true)) {
$events->listen('voyager.admin.routing', [$this, 'addHookRoute']);
}
if (config('voyager-hooks.add-hook-menu-item', true)) {
$events->listen(Setup::class, [$this, 'addHookMenuItem']);
}
if (config('voyager-hooks.add-hook-permissions', true)) {
$events->listen(Setup::class, [$this, 'addHookPermissions']);
}
if (config('voyager-hooks.publish-vendor-files', true)) {
$events->listen(Setup::class, [$this, 'publishVendorFiles']);
}
} | [
"public",
"function",
"boot",
"(",
"Dispatcher",
"$",
"events",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"enabled",
"(",
")",
")",
"{",
"return",
";",
"}",
"if",
"(",
"config",
"(",
"'voyager-hooks.add-route'",
",",
"true",
")",
")",
"{",
"$",
... | Bootstrap the application services.
@param \Illuminate\Events\Dispatcher $events | [
"Bootstrap",
"the",
"application",
"services",
"."
] | train | https://github.com/larapack/voyager-hooks/blob/5de5a5f06c8359c7f09fb1bb9acd84b3f5379506/src/VoyagerHooksServiceProvider.php#L48-L69 |
tuupola/base62 | src/Base62/BcmathEncoder.php | BcmathEncoder.baseConvert | public function baseConvert(array $source, int $sourceBase, int $targetBase): array
{
$result = [];
while ($count = count($source)) {
$quotient = [];
$remainder = "0";
$sourceBase = (string) $sourceBase;
$targetBase = (string) $targetBase;
for ($i = 0; $i !== $count; $i++) {
$accumulator = bcadd((string) $source[$i], bcmul($remainder, $sourceBase));
$digit = bcdiv($accumulator, $targetBase, 0);
$remainder = bcmod($accumulator, $targetBase);
if (count($quotient) || $digit) {
array_push($quotient, $digit);
};
}
array_unshift($result, $remainder);
$source = $quotient;
}
return $result;
} | php | public function baseConvert(array $source, int $sourceBase, int $targetBase): array
{
$result = [];
while ($count = count($source)) {
$quotient = [];
$remainder = "0";
$sourceBase = (string) $sourceBase;
$targetBase = (string) $targetBase;
for ($i = 0; $i !== $count; $i++) {
$accumulator = bcadd((string) $source[$i], bcmul($remainder, $sourceBase));
$digit = bcdiv($accumulator, $targetBase, 0);
$remainder = bcmod($accumulator, $targetBase);
if (count($quotient) || $digit) {
array_push($quotient, $digit);
};
}
array_unshift($result, $remainder);
$source = $quotient;
}
return $result;
} | [
"public",
"function",
"baseConvert",
"(",
"array",
"$",
"source",
",",
"int",
"$",
"sourceBase",
",",
"int",
"$",
"targetBase",
")",
":",
"array",
"{",
"$",
"result",
"=",
"[",
"]",
";",
"while",
"(",
"$",
"count",
"=",
"count",
"(",
"$",
"source",
... | Convert an integer between artbitrary bases
@see http://codegolf.stackexchange.com/a/21672 | [
"Convert",
"an",
"integer",
"between",
"artbitrary",
"bases"
] | train | https://github.com/tuupola/base62/blob/7ffb639cb8031cf75953eda943494fc609ed67b3/src/Base62/BcmathEncoder.php#L47-L68 |
tuupola/base62 | src/Base62/BaseEncoder.php | BaseEncoder.encode | public function encode(string $data): string
{
$data = str_split($data);
$data = array_map("ord", $data);
$leadingZeroes = 0;
while (!empty($data) && 0 === $data[0]) {
$leadingZeroes++;
array_shift($data);
}
$converted = $this->baseConvert($data, 256, 62);
if (0 < $leadingZeroes) {
$converted = array_merge(
array_fill(0, $leadingZeroes, 0),
$converted
);
}
return implode("", array_map(function ($index) {
return $this->options["characters"][$index];
}, $converted));
} | php | public function encode(string $data): string
{
$data = str_split($data);
$data = array_map("ord", $data);
$leadingZeroes = 0;
while (!empty($data) && 0 === $data[0]) {
$leadingZeroes++;
array_shift($data);
}
$converted = $this->baseConvert($data, 256, 62);
if (0 < $leadingZeroes) {
$converted = array_merge(
array_fill(0, $leadingZeroes, 0),
$converted
);
}
return implode("", array_map(function ($index) {
return $this->options["characters"][$index];
}, $converted));
} | [
"public",
"function",
"encode",
"(",
"string",
"$",
"data",
")",
":",
"string",
"{",
"$",
"data",
"=",
"str_split",
"(",
"$",
"data",
")",
";",
"$",
"data",
"=",
"array_map",
"(",
"\"ord\"",
",",
"$",
"data",
")",
";",
"$",
"leadingZeroes",
"=",
"0... | Encode given data to a base62 string | [
"Encode",
"given",
"data",
"to",
"a",
"base62",
"string"
] | train | https://github.com/tuupola/base62/blob/7ffb639cb8031cf75953eda943494fc609ed67b3/src/Base62/BaseEncoder.php#L58-L78 |
tuupola/base62 | src/Base62/BaseEncoder.php | BaseEncoder.decode | public function decode(string $data): string
{
$this->validateInput($data);
$data = str_split($data);
$data = array_map(function ($character) {
return strpos($this->options["characters"], $character);
}, $data);
$leadingZeroes = 0;
while (!empty($data) && 0 === $data[0]) {
$leadingZeroes++;
array_shift($data);
}
$converted = $this->baseConvert($data, 62, 256);
if (0 < $leadingZeroes) {
$converted = array_merge(
array_fill(0, $leadingZeroes, 0),
$converted
);
}
return implode("", array_map("chr", $converted));
} | php | public function decode(string $data): string
{
$this->validateInput($data);
$data = str_split($data);
$data = array_map(function ($character) {
return strpos($this->options["characters"], $character);
}, $data);
$leadingZeroes = 0;
while (!empty($data) && 0 === $data[0]) {
$leadingZeroes++;
array_shift($data);
}
$converted = $this->baseConvert($data, 62, 256);
if (0 < $leadingZeroes) {
$converted = array_merge(
array_fill(0, $leadingZeroes, 0),
$converted
);
}
return implode("", array_map("chr", $converted));
} | [
"public",
"function",
"decode",
"(",
"string",
"$",
"data",
")",
":",
"string",
"{",
"$",
"this",
"->",
"validateInput",
"(",
"$",
"data",
")",
";",
"$",
"data",
"=",
"str_split",
"(",
"$",
"data",
")",
";",
"$",
"data",
"=",
"array_map",
"(",
"fun... | Decode given a base62 string back to data | [
"Decode",
"given",
"a",
"base62",
"string",
"back",
"to",
"data"
] | train | https://github.com/tuupola/base62/blob/7ffb639cb8031cf75953eda943494fc609ed67b3/src/Base62/BaseEncoder.php#L83-L108 |
tuupola/base62 | src/Base62/BaseEncoder.php | BaseEncoder.encodeInteger | public function encodeInteger(int $data): string
{
$data = [$data];
$converted = $this->baseConvert($data, 256, 62);
return implode("", array_map(function ($index) {
return $this->options["characters"][$index];
}, $converted));
} | php | public function encodeInteger(int $data): string
{
$data = [$data];
$converted = $this->baseConvert($data, 256, 62);
return implode("", array_map(function ($index) {
return $this->options["characters"][$index];
}, $converted));
} | [
"public",
"function",
"encodeInteger",
"(",
"int",
"$",
"data",
")",
":",
"string",
"{",
"$",
"data",
"=",
"[",
"$",
"data",
"]",
";",
"$",
"converted",
"=",
"$",
"this",
"->",
"baseConvert",
"(",
"$",
"data",
",",
"256",
",",
"62",
")",
";",
"re... | Encode given integer to a base62 string | [
"Encode",
"given",
"integer",
"to",
"a",
"base62",
"string"
] | train | https://github.com/tuupola/base62/blob/7ffb639cb8031cf75953eda943494fc609ed67b3/src/Base62/BaseEncoder.php#L127-L136 |
tuupola/base62 | src/Base62/BaseEncoder.php | BaseEncoder.decodeInteger | public function decodeInteger(string $data): int
{
$this->validateInput($data);
$data = str_split($data);
$data = array_map(function ($character) {
return strpos($this->options["characters"], $character);
}, $data);
$converted = $this->baseConvert($data, 62, 10);
return (integer) implode("", $converted);
} | php | public function decodeInteger(string $data): int
{
$this->validateInput($data);
$data = str_split($data);
$data = array_map(function ($character) {
return strpos($this->options["characters"], $character);
}, $data);
$converted = $this->baseConvert($data, 62, 10);
return (integer) implode("", $converted);
} | [
"public",
"function",
"decodeInteger",
"(",
"string",
"$",
"data",
")",
":",
"int",
"{",
"$",
"this",
"->",
"validateInput",
"(",
"$",
"data",
")",
";",
"$",
"data",
"=",
"str_split",
"(",
"$",
"data",
")",
";",
"$",
"data",
"=",
"array_map",
"(",
... | Decode given base62 string back to an integer | [
"Decode",
"given",
"base62",
"string",
"back",
"to",
"an",
"integer"
] | train | https://github.com/tuupola/base62/blob/7ffb639cb8031cf75953eda943494fc609ed67b3/src/Base62/BaseEncoder.php#L141-L152 |
tuupola/base62 | src/Base62/PhpEncoder.php | PhpEncoder.baseConvert | public function baseConvert(array $source, int $sourceBase, int $targetBase): array
{
$result = [];
while ($count = count($source)) {
$quotient = [];
$remainder = 0;
for ($i = 0; $i !== $count; $i++) {
$accumulator = $source[$i] + $remainder * $sourceBase;
/* Same as PHP 7 intdiv($accumulator, $targetBase) */
$digit = ($accumulator - ($accumulator % $targetBase)) / $targetBase;
$remainder = $accumulator % $targetBase;
if (count($quotient) || $digit) {
$quotient[] = $digit;
}
}
array_unshift($result, $remainder);
$source = $quotient;
}
return $result;
} | php | public function baseConvert(array $source, int $sourceBase, int $targetBase): array
{
$result = [];
while ($count = count($source)) {
$quotient = [];
$remainder = 0;
for ($i = 0; $i !== $count; $i++) {
$accumulator = $source[$i] + $remainder * $sourceBase;
/* Same as PHP 7 intdiv($accumulator, $targetBase) */
$digit = ($accumulator - ($accumulator % $targetBase)) / $targetBase;
$remainder = $accumulator % $targetBase;
if (count($quotient) || $digit) {
$quotient[] = $digit;
}
}
array_unshift($result, $remainder);
$source = $quotient;
}
return $result;
} | [
"public",
"function",
"baseConvert",
"(",
"array",
"$",
"source",
",",
"int",
"$",
"sourceBase",
",",
"int",
"$",
"targetBase",
")",
":",
"array",
"{",
"$",
"result",
"=",
"[",
"]",
";",
"while",
"(",
"$",
"count",
"=",
"count",
"(",
"$",
"source",
... | Convert an integer between artbitrary bases
@see http://codegolf.stackexchange.com/a/21672 | [
"Convert",
"an",
"integer",
"between",
"artbitrary",
"bases"
] | train | https://github.com/tuupola/base62/blob/7ffb639cb8031cf75953eda943494fc609ed67b3/src/Base62/PhpEncoder.php#L47-L67 |
justintadlock/hybrid-core | src/View/ViewServiceProvider.php | ViewServiceProvider.register | public function register() {
$this->app->bind( ViewContract::class, View::class );
$this->app->alias( ViewContract::class, 'view' );
} | php | public function register() {
$this->app->bind( ViewContract::class, View::class );
$this->app->alias( ViewContract::class, 'view' );
} | [
"public",
"function",
"register",
"(",
")",
"{",
"$",
"this",
"->",
"app",
"->",
"bind",
"(",
"ViewContract",
"::",
"class",
",",
"View",
"::",
"class",
")",
";",
"$",
"this",
"->",
"app",
"->",
"alias",
"(",
"ViewContract",
"::",
"class",
",",
"'vie... | Binds the implementation of the view contract to the container.
@since 5.0.0
@access public
@return void | [
"Binds",
"the",
"implementation",
"of",
"the",
"view",
"contract",
"to",
"the",
"container",
"."
] | train | https://github.com/justintadlock/hybrid-core/blob/20f15f3235505ed7d11f121f45b2ef226bc0c88f/src/View/ViewServiceProvider.php#L37-L42 |
justintadlock/hybrid-core | src/View/View.php | View.hierarchy | protected function hierarchy() {
// Uses the slugs to build a hierarchy.
foreach ( $this->slugs as $slug ) {
$templates[] = "{$this->name}/{$slug}.php";
}
// Add in a `default.php` template.
if ( ! in_array( 'default', $this->slugs ) ) {
$templates[] = "{$this->name}/default.php";
}
// Fallback to `{$name}.php` as a last resort.
$templates[] = "{$this->name}.php";
// Allow developers to overwrite the hierarchy.
return apply_filters( "hybrid/view/{$this->name}/hierarchy", $templates, $this->slugs );
} | php | protected function hierarchy() {
// Uses the slugs to build a hierarchy.
foreach ( $this->slugs as $slug ) {
$templates[] = "{$this->name}/{$slug}.php";
}
// Add in a `default.php` template.
if ( ! in_array( 'default', $this->slugs ) ) {
$templates[] = "{$this->name}/default.php";
}
// Fallback to `{$name}.php` as a last resort.
$templates[] = "{$this->name}.php";
// Allow developers to overwrite the hierarchy.
return apply_filters( "hybrid/view/{$this->name}/hierarchy", $templates, $this->slugs );
} | [
"protected",
"function",
"hierarchy",
"(",
")",
"{",
"// Uses the slugs to build a hierarchy.",
"foreach",
"(",
"$",
"this",
"->",
"slugs",
"as",
"$",
"slug",
")",
"{",
"$",
"templates",
"[",
"]",
"=",
"\"{$this->name}/{$slug}.php\"",
";",
"}",
"// Add in a `defau... | Uses the array of template slugs to build a hierarchy of potential
templates that can be used.
@since 5.0.0
@access protected
@return array | [
"Uses",
"the",
"array",
"of",
"template",
"slugs",
"to",
"build",
"a",
"hierarchy",
"of",
"potential",
"templates",
"that",
"can",
"be",
"used",
"."
] | train | https://github.com/justintadlock/hybrid-core/blob/20f15f3235505ed7d11f121f45b2ef226bc0c88f/src/View/View.php#L117-L136 |
justintadlock/hybrid-core | src/View/View.php | View.template | public function template() {
if ( is_null( $this->template ) ) {
$this->template = $this->locate();
}
return $this->template;
} | php | public function template() {
if ( is_null( $this->template ) ) {
$this->template = $this->locate();
}
return $this->template;
} | [
"public",
"function",
"template",
"(",
")",
"{",
"if",
"(",
"is_null",
"(",
"$",
"this",
"->",
"template",
")",
")",
"{",
"$",
"this",
"->",
"template",
"=",
"$",
"this",
"->",
"locate",
"(",
")",
";",
"}",
"return",
"$",
"this",
"->",
"template",
... | Returns the located template.
@since 5.0.0
@access public
@return string | [
"Returns",
"the",
"located",
"template",
"."
] | train | https://github.com/justintadlock/hybrid-core/blob/20f15f3235505ed7d11f121f45b2ef226bc0c88f/src/View/View.php#L157-L164 |
justintadlock/hybrid-core | src/View/View.php | View.display | public function display() {
// Compatibility with core WP's template parts.
$this->templatePartCompat();
if ( $this->template() ) {
// Maybe remove core WP's `prepend_attachment`.
$this->maybeShiftAttachment();
// Make the `$data` variable available to the template.
$data = $this->data;
// Extract the data into individual variables. Each of
// these variables will be available in the template.
if ( $this->data instanceof Collection ) {
extract( $this->data->all() );
}
// Load the template.
include( $this->template() );
}
} | php | public function display() {
// Compatibility with core WP's template parts.
$this->templatePartCompat();
if ( $this->template() ) {
// Maybe remove core WP's `prepend_attachment`.
$this->maybeShiftAttachment();
// Make the `$data` variable available to the template.
$data = $this->data;
// Extract the data into individual variables. Each of
// these variables will be available in the template.
if ( $this->data instanceof Collection ) {
extract( $this->data->all() );
}
// Load the template.
include( $this->template() );
}
} | [
"public",
"function",
"display",
"(",
")",
"{",
"// Compatibility with core WP's template parts.",
"$",
"this",
"->",
"templatePartCompat",
"(",
")",
";",
"if",
"(",
"$",
"this",
"->",
"template",
"(",
")",
")",
"{",
"// Maybe remove core WP's `prepend_attachment`.",
... | Sets up data to be passed to the template and renders it.
@since 5.0.0
@access public
@return void | [
"Sets",
"up",
"data",
"to",
"be",
"passed",
"to",
"the",
"template",
"and",
"renders",
"it",
"."
] | train | https://github.com/justintadlock/hybrid-core/blob/20f15f3235505ed7d11f121f45b2ef226bc0c88f/src/View/View.php#L173-L195 |
justintadlock/hybrid-core | src/View/View.php | View.templatePartCompat | protected function templatePartCompat() {
// The slug is a string in WP and we have an array. So, we're
// just going to use the first item of the array in this case.
$slug = $this->slugs ? reset( $this->slugs ) : null;
// Compat with `get_header|footer|sidebar()`.
if ( in_array( $this->name, [ 'header', 'footer', 'sidebar' ] ) ) {
do_action( "get_{$this->name}", $slug );
// Compat with `get_template_part()`.
} else {
do_action( "get_template_part_{$this->name}", $this->name, $slug );
}
} | php | protected function templatePartCompat() {
// The slug is a string in WP and we have an array. So, we're
// just going to use the first item of the array in this case.
$slug = $this->slugs ? reset( $this->slugs ) : null;
// Compat with `get_header|footer|sidebar()`.
if ( in_array( $this->name, [ 'header', 'footer', 'sidebar' ] ) ) {
do_action( "get_{$this->name}", $slug );
// Compat with `get_template_part()`.
} else {
do_action( "get_template_part_{$this->name}", $this->name, $slug );
}
} | [
"protected",
"function",
"templatePartCompat",
"(",
")",
"{",
"// The slug is a string in WP and we have an array. So, we're",
"// just going to use the first item of the array in this case.",
"$",
"slug",
"=",
"$",
"this",
"->",
"slugs",
"?",
"reset",
"(",
"$",
"this",
"->",... | Fires the core WP action hooks for template parts.
Note that WP refers to `$name` and `$slug` differently than we do.
They're the opposite of what we use in our function.
@since 5.0.0
@access protected
@return void | [
"Fires",
"the",
"core",
"WP",
"action",
"hooks",
"for",
"template",
"parts",
"."
] | train | https://github.com/justintadlock/hybrid-core/blob/20f15f3235505ed7d11f121f45b2ef226bc0c88f/src/View/View.php#L221-L237 |
justintadlock/hybrid-core | src/View/View.php | View.maybeShiftAttachment | protected function maybeShiftAttachment() {
if ( ! in_the_loop() || 'attachment' !== get_post_type() ) {
return;
}
if ( in_array( $this->name, [ 'entry', 'post', 'entry/archive', 'entry/single' ] ) ) {
remove_filter( 'the_content', 'prepend_attachment' );
} elseif ( 'embed' === $this->name ) {
remove_filter( 'the_content', 'prepend_attachment' );
remove_filter( 'the_excerpt_embed', 'wp_embed_excerpt_attachment' );
}
} | php | protected function maybeShiftAttachment() {
if ( ! in_the_loop() || 'attachment' !== get_post_type() ) {
return;
}
if ( in_array( $this->name, [ 'entry', 'post', 'entry/archive', 'entry/single' ] ) ) {
remove_filter( 'the_content', 'prepend_attachment' );
} elseif ( 'embed' === $this->name ) {
remove_filter( 'the_content', 'prepend_attachment' );
remove_filter( 'the_excerpt_embed', 'wp_embed_excerpt_attachment' );
}
} | [
"protected",
"function",
"maybeShiftAttachment",
"(",
")",
"{",
"if",
"(",
"!",
"in_the_loop",
"(",
")",
"||",
"'attachment'",
"!==",
"get_post_type",
"(",
")",
")",
"{",
"return",
";",
"}",
"if",
"(",
"in_array",
"(",
"$",
"this",
"->",
"name",
",",
"... | Removes core WP's `prepend_attachment` filter whenever a theme is
building custom attachment templates. We'll assume that the theme
author will handle the appropriate output in the template itself.
@since 5.0.0
@access protected
@return void | [
"Removes",
"core",
"WP",
"s",
"prepend_attachment",
"filter",
"whenever",
"a",
"theme",
"is",
"building",
"custom",
"attachment",
"templates",
".",
"We",
"ll",
"assume",
"that",
"the",
"theme",
"author",
"will",
"handle",
"the",
"appropriate",
"output",
"in",
... | train | https://github.com/justintadlock/hybrid-core/blob/20f15f3235505ed7d11f121f45b2ef226bc0c88f/src/View/View.php#L248-L263 |
justintadlock/hybrid-core | src/Attr/Attr.php | Attr.render | public function render() {
$html = '';
foreach ( $this->all() as $name => $value ) {
$esc_value = '';
// If the value is a link `href`, use `esc_url()`.
if ( $value !== false && 'href' === $name ) {
$esc_value = esc_url( $value );
} elseif ( $value !== false ) {
$esc_value = esc_attr( $value );
}
$html .= false !== $value ? sprintf( ' %s="%s"', esc_html( $name ), $esc_value ) : esc_html( " {$name}" );
}
return trim( $html );
} | php | public function render() {
$html = '';
foreach ( $this->all() as $name => $value ) {
$esc_value = '';
// If the value is a link `href`, use `esc_url()`.
if ( $value !== false && 'href' === $name ) {
$esc_value = esc_url( $value );
} elseif ( $value !== false ) {
$esc_value = esc_attr( $value );
}
$html .= false !== $value ? sprintf( ' %s="%s"', esc_html( $name ), $esc_value ) : esc_html( " {$name}" );
}
return trim( $html );
} | [
"public",
"function",
"render",
"(",
")",
"{",
"$",
"html",
"=",
"''",
";",
"foreach",
"(",
"$",
"this",
"->",
"all",
"(",
")",
"as",
"$",
"name",
"=>",
"$",
"value",
")",
"{",
"$",
"esc_value",
"=",
"''",
";",
"// If the value is a link `href`, use `e... | Returns an escaped string of attributes for use in HTML.
@since 5.0.0
@access public
@return string | [
"Returns",
"an",
"escaped",
"string",
"of",
"attributes",
"for",
"use",
"in",
"HTML",
"."
] | train | https://github.com/justintadlock/hybrid-core/blob/20f15f3235505ed7d11f121f45b2ef226bc0c88f/src/Attr/Attr.php#L114-L134 |
justintadlock/hybrid-core | src/Attr/Attr.php | Attr.get | public function get( $name ) {
$attr = $this->all();
return isset( $attr[ $name ] ) ? $attr[ $name ] : '';
} | php | public function get( $name ) {
$attr = $this->all();
return isset( $attr[ $name ] ) ? $attr[ $name ] : '';
} | [
"public",
"function",
"get",
"(",
"$",
"name",
")",
"{",
"$",
"attr",
"=",
"$",
"this",
"->",
"all",
"(",
")",
";",
"return",
"isset",
"(",
"$",
"attr",
"[",
"$",
"name",
"]",
")",
"?",
"$",
"attr",
"[",
"$",
"name",
"]",
":",
"''",
";",
"}... | Returns a single, unescaped attribute's value.
@since 5.0.0
@access public
@param string $name
@return string | [
"Returns",
"a",
"single",
"unescaped",
"attribute",
"s",
"value",
"."
] | train | https://github.com/justintadlock/hybrid-core/blob/20f15f3235505ed7d11f121f45b2ef226bc0c88f/src/Attr/Attr.php#L144-L149 |
justintadlock/hybrid-core | src/Attr/Attr.php | Attr.all | public function all() {
// If we already have attributes, let's return them and bail.
if ( $this->attr ) {
return $this->attr;
}
$defaults = [];
// If the a class was input, we want to go ahead and set that as
// the default class. That way, filters can know early on that
// a class has already been declared. Any filters on the defaults
// should, ideally, respect any classes that already exist.
if ( isset( $this->input['class'] ) ) {
$defaults['class'] = $this->input['class'];
// This is kind of a hacky way to keep the class input
// from overwriting everything later.
unset( $this->input['class'] );
// If no class was input, let's build a custom default.
} else {
$defaults['class'] = $this->context ? "{$this->name} {$this->name}--{$this->context}" : $this->name;
}
// Compatibility with core WP attributes.
if ( method_exists( $this, $this->name ) ) {
$method = $this->name;
$defaults = $this->$method( $defaults );
}
// Filter the default attributes.
$defaults = apply_filters( "hybrid/attr/{$this->name}/defaults", $defaults, $this->context, $this );
// Merge the attributes with the defaults.
$this->attr = wp_parse_args( $this->input, $defaults );
// Apply filters to the parsed attributes.
$this->attr = apply_filters( 'hybrid/attr', $this->attr, $this->name, $this->context );
$this->attr = apply_filters( "hybrid/attr/{$this->name}", $this->attr, $this->context );
// Provide a filter hook for the class attribute directly. The
// classes are split up into an array for easier filtering. Note
// that theme authors should still utilize the core WP body,
// post, and comment class filter hooks. This should only be
// used for custom attributes.
$hook = "hybrid/attr/{$this->name}/class";
if ( isset( $this->attr['class'] ) && has_filter( $hook ) ) {
$classes = apply_filters( $hook, explode( ' ', $this->attr['class'] ), $this->context );
$this->attr['class'] = join( ' ', array_unique( $classes ) );
}
return $this->attr;
} | php | public function all() {
// If we already have attributes, let's return them and bail.
if ( $this->attr ) {
return $this->attr;
}
$defaults = [];
// If the a class was input, we want to go ahead and set that as
// the default class. That way, filters can know early on that
// a class has already been declared. Any filters on the defaults
// should, ideally, respect any classes that already exist.
if ( isset( $this->input['class'] ) ) {
$defaults['class'] = $this->input['class'];
// This is kind of a hacky way to keep the class input
// from overwriting everything later.
unset( $this->input['class'] );
// If no class was input, let's build a custom default.
} else {
$defaults['class'] = $this->context ? "{$this->name} {$this->name}--{$this->context}" : $this->name;
}
// Compatibility with core WP attributes.
if ( method_exists( $this, $this->name ) ) {
$method = $this->name;
$defaults = $this->$method( $defaults );
}
// Filter the default attributes.
$defaults = apply_filters( "hybrid/attr/{$this->name}/defaults", $defaults, $this->context, $this );
// Merge the attributes with the defaults.
$this->attr = wp_parse_args( $this->input, $defaults );
// Apply filters to the parsed attributes.
$this->attr = apply_filters( 'hybrid/attr', $this->attr, $this->name, $this->context );
$this->attr = apply_filters( "hybrid/attr/{$this->name}", $this->attr, $this->context );
// Provide a filter hook for the class attribute directly. The
// classes are split up into an array for easier filtering. Note
// that theme authors should still utilize the core WP body,
// post, and comment class filter hooks. This should only be
// used for custom attributes.
$hook = "hybrid/attr/{$this->name}/class";
if ( isset( $this->attr['class'] ) && has_filter( $hook ) ) {
$classes = apply_filters( $hook, explode( ' ', $this->attr['class'] ), $this->context );
$this->attr['class'] = join( ' ', array_unique( $classes ) );
}
return $this->attr;
} | [
"public",
"function",
"all",
"(",
")",
"{",
"// If we already have attributes, let's return them and bail.",
"if",
"(",
"$",
"this",
"->",
"attr",
")",
"{",
"return",
"$",
"this",
"->",
"attr",
";",
"}",
"$",
"defaults",
"=",
"[",
"]",
";",
"// If the a class ... | Filters and returns the array of attributes.
@since 5.0.0
@access protected
@return void | [
"Filters",
"and",
"returns",
"the",
"array",
"of",
"attributes",
"."
] | train | https://github.com/justintadlock/hybrid-core/blob/20f15f3235505ed7d11f121f45b2ef226bc0c88f/src/Attr/Attr.php#L158-L214 |
justintadlock/hybrid-core | src/Attr/Attr.php | Attr.html | protected function html( $attr ) {
$attr = [];
$parts = wp_kses_hair( get_language_attributes(), [ 'http', 'https' ] );
if ( $parts ) {
foreach ( $parts as $part ) {
$attr[ $part['name'] ] = $part['value'];
}
}
return $attr;
} | php | protected function html( $attr ) {
$attr = [];
$parts = wp_kses_hair( get_language_attributes(), [ 'http', 'https' ] );
if ( $parts ) {
foreach ( $parts as $part ) {
$attr[ $part['name'] ] = $part['value'];
}
}
return $attr;
} | [
"protected",
"function",
"html",
"(",
"$",
"attr",
")",
"{",
"$",
"attr",
"=",
"[",
"]",
";",
"$",
"parts",
"=",
"wp_kses_hair",
"(",
"get_language_attributes",
"(",
")",
",",
"[",
"'http'",
",",
"'https'",
"]",
")",
";",
"if",
"(",
"$",
"parts",
"... | `<html>` element attributes.
@since 5.0.0
@access protected
@param array $attr
@return array | [
"<html",
">",
"element",
"attributes",
"."
] | train | https://github.com/justintadlock/hybrid-core/blob/20f15f3235505ed7d11f121f45b2ef226bc0c88f/src/Attr/Attr.php#L224-L239 |
justintadlock/hybrid-core | src/Attr/Attr.php | Attr.body | protected function body( $attr ) {
$class = isset( $attr['class'] ) && 'body' !== $attr['class'] ? $attr['class'] : '';
$attr['class'] = join( ' ', get_body_class( $class ) );
$attr['dir'] = is_rtl() ? 'rtl' : 'ltr';
return $attr;
} | php | protected function body( $attr ) {
$class = isset( $attr['class'] ) && 'body' !== $attr['class'] ? $attr['class'] : '';
$attr['class'] = join( ' ', get_body_class( $class ) );
$attr['dir'] = is_rtl() ? 'rtl' : 'ltr';
return $attr;
} | [
"protected",
"function",
"body",
"(",
"$",
"attr",
")",
"{",
"$",
"class",
"=",
"isset",
"(",
"$",
"attr",
"[",
"'class'",
"]",
")",
"&&",
"'body'",
"!==",
"$",
"attr",
"[",
"'class'",
"]",
"?",
"$",
"attr",
"[",
"'class'",
"]",
":",
"''",
";",
... | `<body>` element attributes.
@since 5.0.0
@access protected
@param array $attr
@return array | [
"<body",
">",
"element",
"attributes",
"."
] | train | https://github.com/justintadlock/hybrid-core/blob/20f15f3235505ed7d11f121f45b2ef226bc0c88f/src/Attr/Attr.php#L249-L257 |
justintadlock/hybrid-core | src/Attr/Attr.php | Attr.post | protected function post( $attr ) {
$post = get_post();
$class = isset( $attr['class'] ) ? $attr['class'] : '';
$attr['id'] = ! empty( $post ) ? sprintf( 'post-%d', get_the_ID() ) : 'post-0';
$attr['class'] = join( ' ', get_post_class( $class ) );
return $attr;
} | php | protected function post( $attr ) {
$post = get_post();
$class = isset( $attr['class'] ) ? $attr['class'] : '';
$attr['id'] = ! empty( $post ) ? sprintf( 'post-%d', get_the_ID() ) : 'post-0';
$attr['class'] = join( ' ', get_post_class( $class ) );
return $attr;
} | [
"protected",
"function",
"post",
"(",
"$",
"attr",
")",
"{",
"$",
"post",
"=",
"get_post",
"(",
")",
";",
"$",
"class",
"=",
"isset",
"(",
"$",
"attr",
"[",
"'class'",
"]",
")",
"?",
"$",
"attr",
"[",
"'class'",
"]",
":",
"''",
";",
"$",
"attr"... | Post `<article>` element attributes.
@since 5.0.0
@access protected
@param array $attr
@return array | [
"Post",
"<article",
">",
"element",
"attributes",
"."
] | train | https://github.com/justintadlock/hybrid-core/blob/20f15f3235505ed7d11f121f45b2ef226bc0c88f/src/Attr/Attr.php#L267-L276 |
justintadlock/hybrid-core | src/Attr/Attr.php | Attr.comment | protected function comment( $attr ) {
$class = isset( $attr['class'] ) ? $attr['class'] : '';
$attr['id'] = 'comment-' . get_comment_ID();
$attr['class'] = join( ' ', get_comment_class( $class ) );
return $attr;
} | php | protected function comment( $attr ) {
$class = isset( $attr['class'] ) ? $attr['class'] : '';
$attr['id'] = 'comment-' . get_comment_ID();
$attr['class'] = join( ' ', get_comment_class( $class ) );
return $attr;
} | [
"protected",
"function",
"comment",
"(",
"$",
"attr",
")",
"{",
"$",
"class",
"=",
"isset",
"(",
"$",
"attr",
"[",
"'class'",
"]",
")",
"?",
"$",
"attr",
"[",
"'class'",
"]",
":",
"''",
";",
"$",
"attr",
"[",
"'id'",
"]",
"=",
"'comment-'",
".",
... | Comment wrapper attributes.
@since 5.0.0
@access protected
@param array $attr
@return array | [
"Comment",
"wrapper",
"attributes",
"."
] | train | https://github.com/justintadlock/hybrid-core/blob/20f15f3235505ed7d11f121f45b2ef226bc0c88f/src/Attr/Attr.php#L299-L307 |
justintadlock/hybrid-core | src/Util/Title.php | Title.current | public static function current() {
$title = '';
if ( is_front_page() ) {
$title = static::frontPage();
} elseif ( is_home() || is_singular() ) {
$title = static::post();
} elseif ( is_archive() ) {
$title = static::archive();
} elseif ( is_search() ) {
$title = static::search();
} elseif ( is_404() ) {
$title = static::error();
}
return $title;
} | php | public static function current() {
$title = '';
if ( is_front_page() ) {
$title = static::frontPage();
} elseif ( is_home() || is_singular() ) {
$title = static::post();
} elseif ( is_archive() ) {
$title = static::archive();
} elseif ( is_search() ) {
$title = static::search();
} elseif ( is_404() ) {
$title = static::error();
}
return $title;
} | [
"public",
"static",
"function",
"current",
"(",
")",
"{",
"$",
"title",
"=",
"''",
";",
"if",
"(",
"is_front_page",
"(",
")",
")",
"{",
"$",
"title",
"=",
"static",
"::",
"frontPage",
"(",
")",
";",
"}",
"elseif",
"(",
"is_home",
"(",
")",
"||",
... | Retrieve the current page title.
@since 5.0.0
@access public
@return string | [
"Retrieve",
"the",
"current",
"page",
"title",
"."
] | train | https://github.com/justintadlock/hybrid-core/blob/20f15f3235505ed7d11f121f45b2ef226bc0c88f/src/Util/Title.php#L33-L54 |
justintadlock/hybrid-core | src/Util/Title.php | Title.archive | public static function archive() {
$title = '';
if ( is_category() || is_tag() || is_tax() ) {
$title = static::term();
} elseif ( is_post_type_archive() ) {
$title = static::postTypeArchive();
} elseif ( is_author() ) {
$title = static::author();
} elseif ( get_query_var( 'minute' ) && get_query_var( 'hour' ) ) {
$title = static::minuteHour();
} elseif ( get_query_var( 'minute' ) ) {
$title = static::minute();
} elseif ( get_query_var( 'hour' ) ) {
$title = static::hour();
} elseif ( is_day() ) {
$title = static::day();
} elseif ( get_query_var( 'w' ) ) {
$title = static::week();
} elseif ( is_month() ) {
$title = static::month();
} elseif ( is_year() ) {
$title = static::year();
} else {
$title = esc_html__( 'Archives', 'hybrid-core' );
}
return $title;
} | php | public static function archive() {
$title = '';
if ( is_category() || is_tag() || is_tax() ) {
$title = static::term();
} elseif ( is_post_type_archive() ) {
$title = static::postTypeArchive();
} elseif ( is_author() ) {
$title = static::author();
} elseif ( get_query_var( 'minute' ) && get_query_var( 'hour' ) ) {
$title = static::minuteHour();
} elseif ( get_query_var( 'minute' ) ) {
$title = static::minute();
} elseif ( get_query_var( 'hour' ) ) {
$title = static::hour();
} elseif ( is_day() ) {
$title = static::day();
} elseif ( get_query_var( 'w' ) ) {
$title = static::week();
} elseif ( is_month() ) {
$title = static::month();
} elseif ( is_year() ) {
$title = static::year();
} else {
$title = esc_html__( 'Archives', 'hybrid-core' );
}
return $title;
} | [
"public",
"static",
"function",
"archive",
"(",
")",
"{",
"$",
"title",
"=",
"''",
";",
"if",
"(",
"is_category",
"(",
")",
"||",
"is_tag",
"(",
")",
"||",
"is_tax",
"(",
")",
")",
"{",
"$",
"title",
"=",
"static",
"::",
"term",
"(",
")",
";",
... | Retrieve the general archive title.
@since 5.0.0
@access public
@return string | [
"Retrieve",
"the",
"general",
"archive",
"title",
"."
] | train | https://github.com/justintadlock/hybrid-core/blob/20f15f3235505ed7d11f121f45b2ef226bc0c88f/src/Util/Title.php#L63-L101 |
justintadlock/hybrid-core | src/Media/Grabber.php | Grabber.locate | protected function locate() {
// Don't return a link if embeds don't work. Need media or nothing at all.
add_filter( 'embed_maybe_make_link', '__return_false' );
// Get the media if the post type is an attachment.
if ( 'attachment' === get_post_type( $this->post_id ) ) {
$this->media = $this->locateSelfMedia();
}
// Find media in the post content based on WordPress' media-related shortcodes.
if ( ! $this->media && $this->shortcodes ) {
$this->media = $this->locateShortcodeMedia();
}
// If no media is found and autoembeds are enabled, check for autoembeds.
if ( ! $this->media && get_option( 'embed_autourls' ) && $this->autoembeds ) {
$this->media = $this->locateAutoembedMedia();
}
// If no media is found, check for media HTML within the post content.
if ( ! $this->media && $this->embedded ) {
$this->media = $this->locatedEmbeddedMedia();
}
// If no media is found, check for media attached to the post.
if ( ! $this->media && $this->attached ) {
$this->media = $this->locateAttachedMedia();
}
// If media is found, let's run a few things.
if ( $this->media ) {
// Split the media from the content.
if ( true === $this->split && ! empty( $this->original_media ) ) {
add_filter( 'the_content', [ $this, 'split' ], 5 );
}
// Filter the media dimensions and add the before/after HTML.
$this->media = $this->before . $this->filterDimensions( $this->media ) . $this->after;
}
// Remove our filter from earlier.
remove_filter( 'embed_maybe_make_link', '__return_false' );
return $this->media;
} | php | protected function locate() {
// Don't return a link if embeds don't work. Need media or nothing at all.
add_filter( 'embed_maybe_make_link', '__return_false' );
// Get the media if the post type is an attachment.
if ( 'attachment' === get_post_type( $this->post_id ) ) {
$this->media = $this->locateSelfMedia();
}
// Find media in the post content based on WordPress' media-related shortcodes.
if ( ! $this->media && $this->shortcodes ) {
$this->media = $this->locateShortcodeMedia();
}
// If no media is found and autoembeds are enabled, check for autoembeds.
if ( ! $this->media && get_option( 'embed_autourls' ) && $this->autoembeds ) {
$this->media = $this->locateAutoembedMedia();
}
// If no media is found, check for media HTML within the post content.
if ( ! $this->media && $this->embedded ) {
$this->media = $this->locatedEmbeddedMedia();
}
// If no media is found, check for media attached to the post.
if ( ! $this->media && $this->attached ) {
$this->media = $this->locateAttachedMedia();
}
// If media is found, let's run a few things.
if ( $this->media ) {
// Split the media from the content.
if ( true === $this->split && ! empty( $this->original_media ) ) {
add_filter( 'the_content', [ $this, 'split' ], 5 );
}
// Filter the media dimensions and add the before/after HTML.
$this->media = $this->before . $this->filterDimensions( $this->media ) . $this->after;
}
// Remove our filter from earlier.
remove_filter( 'embed_maybe_make_link', '__return_false' );
return $this->media;
} | [
"protected",
"function",
"locate",
"(",
")",
"{",
"// Don't return a link if embeds don't work. Need media or nothing at all.",
"add_filter",
"(",
"'embed_maybe_make_link'",
",",
"'__return_false'",
")",
";",
"// Get the media if the post type is an attachment.",
"if",
"(",
"'attac... | Tries several methods to find media related to the post. Returns the
found media.
@since 5.0.0
@access protected
@return string | [
"Tries",
"several",
"methods",
"to",
"find",
"media",
"related",
"to",
"the",
"post",
".",
"Returns",
"the",
"found",
"media",
"."
] | train | https://github.com/justintadlock/hybrid-core/blob/20f15f3235505ed7d11f121f45b2ef226bc0c88f/src/Media/Grabber.php#L282-L328 |
justintadlock/hybrid-core | src/Media/Grabber.php | Grabber.locateSelfMedia | protected function locateSelfMedia() {
$url = esc_url( wp_get_attachment_url( $this->post_id ) );
$mime = get_post_mime_type( $this->post_id );
list( $type, $subtype ) = false !== strpos( $mime, '/' ) ? explode( '/', $mime ) : [ $mime, '' ];
return in_array( $type, [ 'audio', 'video' ] )
? call_user_func( "wp_{$type}_shortcode", [ 'src' => $url ] )
: '';
} | php | protected function locateSelfMedia() {
$url = esc_url( wp_get_attachment_url( $this->post_id ) );
$mime = get_post_mime_type( $this->post_id );
list( $type, $subtype ) = false !== strpos( $mime, '/' ) ? explode( '/', $mime ) : [ $mime, '' ];
return in_array( $type, [ 'audio', 'video' ] )
? call_user_func( "wp_{$type}_shortcode", [ 'src' => $url ] )
: '';
} | [
"protected",
"function",
"locateSelfMedia",
"(",
")",
"{",
"$",
"url",
"=",
"esc_url",
"(",
"wp_get_attachment_url",
"(",
"$",
"this",
"->",
"post_id",
")",
")",
";",
"$",
"mime",
"=",
"get_post_mime_type",
"(",
"$",
"this",
"->",
"post_id",
")",
";",
"l... | If the post type itself is an attachment, call the shortcode wrapper
function for handling the media.
@since 5.0.0
@access protected
@return string | [
"If",
"the",
"post",
"type",
"itself",
"is",
"an",
"attachment",
"call",
"the",
"shortcode",
"wrapper",
"function",
"for",
"handling",
"the",
"media",
"."
] | train | https://github.com/justintadlock/hybrid-core/blob/20f15f3235505ed7d11f121f45b2ef226bc0c88f/src/Media/Grabber.php#L338-L348 |
justintadlock/hybrid-core | src/Media/Grabber.php | Grabber.locateShortcodeMedia | protected function locateShortcodeMedia() {
// Finds matches for shortcodes in the content.
preg_match_all( '/' . get_shortcode_regex() . '/s', $this->content, $matches, PREG_SET_ORDER );
if ( empty( $matches ) ) {
return '';
}
// Create a list of allowed shortcodes.
$shortcodes = is_array( $this->shortcodes ) ? $this->shortcodes : [];
// We need to add any known shortcodes for the given type.
$property = "{$this->type}_shortcodes";
if ( property_exists( $this, $property ) ) {
$shortcodes = array_merge(
$shortcodes,
apply_filters(
"hybrid/media/grabber/shortcodes/{$this->type}",
$this->{$property}
)
);
}
// Loops through all of the shortcode matches. If we find one of
// our shortcodes, run it.
foreach ( $matches as $shortcode ) {
if ( in_array( $shortcode[2], $shortcodes ) ) {
$this->original_media = array_shift( $shortcode );
return $this->doShortcode( $shortcode[2], $this->original_media );
}
}
return '';
} | php | protected function locateShortcodeMedia() {
// Finds matches for shortcodes in the content.
preg_match_all( '/' . get_shortcode_regex() . '/s', $this->content, $matches, PREG_SET_ORDER );
if ( empty( $matches ) ) {
return '';
}
// Create a list of allowed shortcodes.
$shortcodes = is_array( $this->shortcodes ) ? $this->shortcodes : [];
// We need to add any known shortcodes for the given type.
$property = "{$this->type}_shortcodes";
if ( property_exists( $this, $property ) ) {
$shortcodes = array_merge(
$shortcodes,
apply_filters(
"hybrid/media/grabber/shortcodes/{$this->type}",
$this->{$property}
)
);
}
// Loops through all of the shortcode matches. If we find one of
// our shortcodes, run it.
foreach ( $matches as $shortcode ) {
if ( in_array( $shortcode[2], $shortcodes ) ) {
$this->original_media = array_shift( $shortcode );
return $this->doShortcode( $shortcode[2], $this->original_media );
}
}
return '';
} | [
"protected",
"function",
"locateShortcodeMedia",
"(",
")",
"{",
"// Finds matches for shortcodes in the content.",
"preg_match_all",
"(",
"'/'",
".",
"get_shortcode_regex",
"(",
")",
".",
"'/s'",
",",
"$",
"this",
"->",
"content",
",",
"$",
"matches",
",",
"PREG_SET... | Searches for shortcodes in the post content and sets the generated
shortcode output if one is found.
@since 5.0.0
@access protected
@return string | [
"Searches",
"for",
"shortcodes",
"in",
"the",
"post",
"content",
"and",
"sets",
"the",
"generated",
"shortcode",
"output",
"if",
"one",
"is",
"found",
"."
] | train | https://github.com/justintadlock/hybrid-core/blob/20f15f3235505ed7d11f121f45b2ef226bc0c88f/src/Media/Grabber.php#L358-L397 |
justintadlock/hybrid-core | src/Media/Grabber.php | Grabber.locateAutoembedMedia | protected function locateAutoembedMedia() {
// Searches for URLs on a line by themselves in the post content.
preg_match_all( '|^\s*(https?://[^\s"]+)\s*$|im', $this->content, $matches, PREG_SET_ORDER );
if ( empty( $matches ) || ! is_array( $matches ) ) {
return '';
}
foreach ( $matches as $value ) {
// Let WP work its magic with the 'autoembed' method.
$embed = $GLOBALS['wp_embed']->autoembed( $value[0] );
if ( $embed ) {
// If we're given a shortcode, roll with it.
if ( preg_match( "/\[{$this->type}\s/", $embed ) ) {
$this->original_media = $value[0];
return $this->doShortcode( $this->type, $embed );
}
}
}
return '';
} | php | protected function locateAutoembedMedia() {
// Searches for URLs on a line by themselves in the post content.
preg_match_all( '|^\s*(https?://[^\s"]+)\s*$|im', $this->content, $matches, PREG_SET_ORDER );
if ( empty( $matches ) || ! is_array( $matches ) ) {
return '';
}
foreach ( $matches as $value ) {
// Let WP work its magic with the 'autoembed' method.
$embed = $GLOBALS['wp_embed']->autoembed( $value[0] );
if ( $embed ) {
// If we're given a shortcode, roll with it.
if ( preg_match( "/\[{$this->type}\s/", $embed ) ) {
$this->original_media = $value[0];
return $this->doShortcode( $this->type, $embed );
}
}
}
return '';
} | [
"protected",
"function",
"locateAutoembedMedia",
"(",
")",
"{",
"// Searches for URLs on a line by themselves in the post content.",
"preg_match_all",
"(",
"'|^\\s*(https?://[^\\s\"]+)\\s*$|im'",
",",
"$",
"this",
"->",
"content",
",",
"$",
"matches",
",",
"PREG_SET_ORDER",
"... | Uses WordPress' autoembed feature to automatically to handle media
that's just input as a URL.
@since 5.0.0
@access protected
@return string | [
"Uses",
"WordPress",
"autoembed",
"feature",
"to",
"automatically",
"to",
"handle",
"media",
"that",
"s",
"just",
"input",
"as",
"a",
"URL",
"."
] | train | https://github.com/justintadlock/hybrid-core/blob/20f15f3235505ed7d11f121f45b2ef226bc0c88f/src/Media/Grabber.php#L407-L434 |
justintadlock/hybrid-core | src/Media/Grabber.php | Grabber.locatedEmbeddedMedia | protected function locatedEmbeddedMedia() {
$embedded_media = get_media_embedded_in_content( $this->content );
if ( $embedded_media ) {
return $this->original_media = array_shift( $embedded_media );
}
return '';
} | php | protected function locatedEmbeddedMedia() {
$embedded_media = get_media_embedded_in_content( $this->content );
if ( $embedded_media ) {
return $this->original_media = array_shift( $embedded_media );
}
return '';
} | [
"protected",
"function",
"locatedEmbeddedMedia",
"(",
")",
"{",
"$",
"embedded_media",
"=",
"get_media_embedded_in_content",
"(",
"$",
"this",
"->",
"content",
")",
";",
"if",
"(",
"$",
"embedded_media",
")",
"{",
"return",
"$",
"this",
"->",
"original_media",
... | Grabs media embbeded into the content within <iframe>, <object>,
<embed>, and other HTML methods for embedding media.
@since 5.0.0
@access protected
@return string | [
"Grabs",
"media",
"embbeded",
"into",
"the",
"content",
"within",
"<iframe",
">",
"<object",
">",
"<embed",
">",
"and",
"other",
"HTML",
"methods",
"for",
"embedding",
"media",
"."
] | train | https://github.com/justintadlock/hybrid-core/blob/20f15f3235505ed7d11f121f45b2ef226bc0c88f/src/Media/Grabber.php#L444-L453 |
justintadlock/hybrid-core | src/Media/Grabber.php | Grabber.locateAttachedMedia | protected function locateAttachedMedia() {
// Gets media attached to the post by mime type.
$attached_media = get_attached_media( $this->type, $this->post_id );
// If media is found.
if ( $attached_media ) {
// Get the first attachment/post object found for the post.
$post = array_shift( $attached_media );
// Gets the URI for the attachment (the media file).
$url = esc_url( wp_get_attachment_url( $post->ID ) );
// Run the media as a shortcode using WordPress' built-in
// [audio] and [video] shortcodes.
if ( in_array( $this->type, [ 'audio', 'video' ] ) ) {
return call_user_func( "wp_{$this->type}_shortcode", [ 'src' => $url ] );
}
}
return '';
} | php | protected function locateAttachedMedia() {
// Gets media attached to the post by mime type.
$attached_media = get_attached_media( $this->type, $this->post_id );
// If media is found.
if ( $attached_media ) {
// Get the first attachment/post object found for the post.
$post = array_shift( $attached_media );
// Gets the URI for the attachment (the media file).
$url = esc_url( wp_get_attachment_url( $post->ID ) );
// Run the media as a shortcode using WordPress' built-in
// [audio] and [video] shortcodes.
if ( in_array( $this->type, [ 'audio', 'video' ] ) ) {
return call_user_func( "wp_{$this->type}_shortcode", [ 'src' => $url ] );
}
}
return '';
} | [
"protected",
"function",
"locateAttachedMedia",
"(",
")",
"{",
"// Gets media attached to the post by mime type.",
"$",
"attached_media",
"=",
"get_attached_media",
"(",
"$",
"this",
"->",
"type",
",",
"$",
"this",
"->",
"post_id",
")",
";",
"// If media is found.",
"... | Gets media attached to the post. Then, uses the WordPress [audio] or
[video] shortcode to handle the HTML output of the media.
@since 5.0.0
@access protected
@return string | [
"Gets",
"media",
"attached",
"to",
"the",
"post",
".",
"Then",
"uses",
"the",
"WordPress",
"[",
"audio",
"]",
"or",
"[",
"video",
"]",
"shortcode",
"to",
"handle",
"the",
"HTML",
"output",
"of",
"the",
"media",
"."
] | train | https://github.com/justintadlock/hybrid-core/blob/20f15f3235505ed7d11f121f45b2ef226bc0c88f/src/Media/Grabber.php#L463-L486 |
justintadlock/hybrid-core | src/Media/Grabber.php | Grabber.doShortcode | protected function doShortcode( $tag, $shortcode ) {
if ( 'embed' === $tag ) {
return $GLOBALS['wp_embed']->run_shortcode( $shortcode );
} elseif ( 'video' === $tag ) {
// Need to filter dimensions here to overwrite WP's
// `<div>` surrounding the [video] shortcode.
return do_shortcode( $this->filterDimensions( $shortcode ) );
}
return do_shortcode( $shortcode );
} | php | protected function doShortcode( $tag, $shortcode ) {
if ( 'embed' === $tag ) {
return $GLOBALS['wp_embed']->run_shortcode( $shortcode );
} elseif ( 'video' === $tag ) {
// Need to filter dimensions here to overwrite WP's
// `<div>` surrounding the [video] shortcode.
return do_shortcode( $this->filterDimensions( $shortcode ) );
}
return do_shortcode( $shortcode );
} | [
"protected",
"function",
"doShortcode",
"(",
"$",
"tag",
",",
"$",
"shortcode",
")",
"{",
"if",
"(",
"'embed'",
"===",
"$",
"tag",
")",
"{",
"return",
"$",
"GLOBALS",
"[",
"'wp_embed'",
"]",
"->",
"run_shortcode",
"(",
"$",
"shortcode",
")",
";",
"}",
... | Helper function for running a shortcode.
@since 5.0.0
@access protected
@param string $tag
@param string $shortcode
@return string | [
"Helper",
"function",
"for",
"running",
"a",
"shortcode",
"."
] | train | https://github.com/justintadlock/hybrid-core/blob/20f15f3235505ed7d11f121f45b2ef226bc0c88f/src/Media/Grabber.php#L497-L511 |
justintadlock/hybrid-core | src/Media/Grabber.php | Grabber.split | public function split( $content ) {
if ( get_the_ID() === (int) $this->post_id ) {
$content = str_replace( $this->original_media, '', $content );
$content = wp_kses_post( $content );
}
return $content;
} | php | public function split( $content ) {
if ( get_the_ID() === (int) $this->post_id ) {
$content = str_replace( $this->original_media, '', $content );
$content = wp_kses_post( $content );
}
return $content;
} | [
"public",
"function",
"split",
"(",
"$",
"content",
")",
"{",
"if",
"(",
"get_the_ID",
"(",
")",
"===",
"(",
"int",
")",
"$",
"this",
"->",
"post_id",
")",
"{",
"$",
"content",
"=",
"str_replace",
"(",
"$",
"this",
"->",
"original_media",
",",
"''",
... | Removes the found media from the content. The purpose of this is so
that themes can retrieve the media from the content and display it
elsewhere on the page based on its design.
@since 5.0.0
@access public
@param string $content
@return string | [
"Removes",
"the",
"found",
"media",
"from",
"the",
"content",
".",
"The",
"purpose",
"of",
"this",
"is",
"so",
"that",
"themes",
"can",
"retrieve",
"the",
"media",
"from",
"the",
"content",
"and",
"display",
"it",
"elsewhere",
"on",
"the",
"page",
"based",... | train | https://github.com/justintadlock/hybrid-core/blob/20f15f3235505ed7d11f121f45b2ef226bc0c88f/src/Media/Grabber.php#L523-L532 |
justintadlock/hybrid-core | src/Media/Grabber.php | Grabber.filterDimensions | protected function filterDimensions( $html ) {
$media_atts = [];
$_html = strip_tags( $html, '<object><embed><iframe><video>' );
// Find the attributes of the media.
$atts = wp_kses_hair( $_html, [ 'http', 'https' ] );
// Loop through the media attributes and add them in key/value pairs.
foreach ( $atts as $att ) {
$media_atts[ $att['name'] ] = $att['value'];
}
// If no dimensions are found, just return the HTML.
if ( empty( $media_atts ) || ! isset( $media_atts['width'] ) || ! isset( $media_atts['height'] ) ) {
return $html;
}
// Set the max width.
$max_width = $this->width;
// Set the max height based on the max width and original width/height ratio.
$max_height = round( $max_width / ( $media_atts['width'] / $media_atts['height'] ) );
// Fix for Spotify embeds.
if ( ! empty( $media_atts['src'] ) && preg_match( '#https?://(embed)\.spotify\.com/.*#i', $media_atts['src'], $matches ) ) {
list( $max_width, $max_height ) = $this->spotifyDimensions( $media_atts );
}
// Calculate new media dimensions.
$dimensions = wp_expand_dimensions(
$media_atts['width'],
$media_atts['height'],
$max_width,
$max_height
);
// Allow devs to filter the final width and height of the media.
list( $width, $height ) = apply_filters(
'hybrid/media/grabber/dimensions',
$dimensions, // width/height array
$media_atts, // media HTML attributes
$this // media grabber object
);
// Set up the patterns for the 'width' and 'height' attributes.
$patterns = [
'/(width=[\'"]).+?([\'"])/i',
'/(height=[\'"]).+?([\'"])/i',
'/(<div.+?style=[\'"].*?width:.+?).+?(px;.+?[\'"].*?>)/i',
'/(<div.+?style=[\'"].*?height:.+?).+?(px;.+?[\'"].*?>)/i'
];
// Set up the replacements for the 'width' and 'height' attributes.
$replacements = [
'${1}' . $width . '${2}',
'${1}' . $height . '${2}',
'${1}' . $width . '${2}',
'${1}' . $height . '${2}',
];
// Filter the dimensions and return the media HTML.
return preg_replace( $patterns, $replacements, $html );
} | php | protected function filterDimensions( $html ) {
$media_atts = [];
$_html = strip_tags( $html, '<object><embed><iframe><video>' );
// Find the attributes of the media.
$atts = wp_kses_hair( $_html, [ 'http', 'https' ] );
// Loop through the media attributes and add them in key/value pairs.
foreach ( $atts as $att ) {
$media_atts[ $att['name'] ] = $att['value'];
}
// If no dimensions are found, just return the HTML.
if ( empty( $media_atts ) || ! isset( $media_atts['width'] ) || ! isset( $media_atts['height'] ) ) {
return $html;
}
// Set the max width.
$max_width = $this->width;
// Set the max height based on the max width and original width/height ratio.
$max_height = round( $max_width / ( $media_atts['width'] / $media_atts['height'] ) );
// Fix for Spotify embeds.
if ( ! empty( $media_atts['src'] ) && preg_match( '#https?://(embed)\.spotify\.com/.*#i', $media_atts['src'], $matches ) ) {
list( $max_width, $max_height ) = $this->spotifyDimensions( $media_atts );
}
// Calculate new media dimensions.
$dimensions = wp_expand_dimensions(
$media_atts['width'],
$media_atts['height'],
$max_width,
$max_height
);
// Allow devs to filter the final width and height of the media.
list( $width, $height ) = apply_filters(
'hybrid/media/grabber/dimensions',
$dimensions, // width/height array
$media_atts, // media HTML attributes
$this // media grabber object
);
// Set up the patterns for the 'width' and 'height' attributes.
$patterns = [
'/(width=[\'"]).+?([\'"])/i',
'/(height=[\'"]).+?([\'"])/i',
'/(<div.+?style=[\'"].*?width:.+?).+?(px;.+?[\'"].*?>)/i',
'/(<div.+?style=[\'"].*?height:.+?).+?(px;.+?[\'"].*?>)/i'
];
// Set up the replacements for the 'width' and 'height' attributes.
$replacements = [
'${1}' . $width . '${2}',
'${1}' . $height . '${2}',
'${1}' . $width . '${2}',
'${1}' . $height . '${2}',
];
// Filter the dimensions and return the media HTML.
return preg_replace( $patterns, $replacements, $html );
} | [
"protected",
"function",
"filterDimensions",
"(",
"$",
"html",
")",
"{",
"$",
"media_atts",
"=",
"[",
"]",
";",
"$",
"_html",
"=",
"strip_tags",
"(",
"$",
"html",
",",
"'<object><embed><iframe><video>'",
")",
";",
"// Find the attributes of the media.",
"$",
"at... | Method for filtering the media's 'width' and 'height' attributes so
that the theme can handle the dimensions how it sees fit.
@since 5.0.0
@access protected
@param string $html
@return string | [
"Method",
"for",
"filtering",
"the",
"media",
"s",
"width",
"and",
"height",
"attributes",
"so",
"that",
"the",
"theme",
"can",
"handle",
"the",
"dimensions",
"how",
"it",
"sees",
"fit",
"."
] | train | https://github.com/justintadlock/hybrid-core/blob/20f15f3235505ed7d11f121f45b2ef226bc0c88f/src/Media/Grabber.php#L543-L607 |
justintadlock/hybrid-core | src/Media/Grabber.php | Grabber.spotifyDimensions | protected function spotifyDimensions( $media_atts ) {
$max_width = $media_atts['width'];
$max_height = $media_atts['height'];
if ( 80 == $media_atts['height'] ) {
$max_width = $this->width;
}
return [ $max_width, $max_height ];
} | php | protected function spotifyDimensions( $media_atts ) {
$max_width = $media_atts['width'];
$max_height = $media_atts['height'];
if ( 80 == $media_atts['height'] ) {
$max_width = $this->width;
}
return [ $max_width, $max_height ];
} | [
"protected",
"function",
"spotifyDimensions",
"(",
"$",
"media_atts",
")",
"{",
"$",
"max_width",
"=",
"$",
"media_atts",
"[",
"'width'",
"]",
";",
"$",
"max_height",
"=",
"$",
"media_atts",
"[",
"'height'",
"]",
";",
"if",
"(",
"80",
"==",
"$",
"media_a... | Fix for Spotify embeds because they're the only embeddable service
that doesn't work that well with custom-sized embeds. So, we need to
adjust this the best we can. Right now, the only embed size that
works for full-width embeds is the "compact" player (height of 80).
@since 5.0.0
@access protected
@param array $media_atts
@return array | [
"Fix",
"for",
"Spotify",
"embeds",
"because",
"they",
"re",
"the",
"only",
"embeddable",
"service",
"that",
"doesn",
"t",
"work",
"that",
"well",
"with",
"custom",
"-",
"sized",
"embeds",
".",
"So",
"we",
"need",
"to",
"adjust",
"this",
"the",
"best",
"w... | train | https://github.com/justintadlock/hybrid-core/blob/20f15f3235505ed7d11f121f45b2ef226bc0c88f/src/Media/Grabber.php#L620-L630 |
justintadlock/hybrid-core | src/Attr/AttrServiceProvider.php | AttrServiceProvider.register | public function register() {
$this->app->bind( Attributes::class, Attr::class );
$this->app->alias( Attributes::class, 'attr' );
} | php | public function register() {
$this->app->bind( Attributes::class, Attr::class );
$this->app->alias( Attributes::class, 'attr' );
} | [
"public",
"function",
"register",
"(",
")",
"{",
"$",
"this",
"->",
"app",
"->",
"bind",
"(",
"Attributes",
"::",
"class",
",",
"Attr",
"::",
"class",
")",
";",
"$",
"this",
"->",
"app",
"->",
"alias",
"(",
"Attributes",
"::",
"class",
",",
"'attr'",... | Binds the implementation of the attributes contract to the container.
@since 5.0.0
@access public
@return void | [
"Binds",
"the",
"implementation",
"of",
"the",
"attributes",
"contract",
"to",
"the",
"container",
"."
] | train | https://github.com/justintadlock/hybrid-core/blob/20f15f3235505ed7d11f121f45b2ef226bc0c88f/src/Attr/AttrServiceProvider.php#L37-L42 |
justintadlock/hybrid-core | src/Pagination/Pagination.php | Pagination.postsArgs | protected function postsArgs() {
global $wp_query, $wp_rewrite;
// Setting up default values based on the current URL.
$pagenum_link = html_entity_decode( get_pagenum_link() );
$this->url_parts = explode( '?', $pagenum_link );
// Get total number of pages.
$total = isset( $wp_query->max_num_pages ) ? $wp_query->max_num_pages : 1;
// Get the current page.
$current = get_query_var( 'paged' ) ? intval( get_query_var( 'paged' ) ) : 1;
// Append the format placeholder to the base URL.
$base = trailingslashit( $this->url_parts[0] ) . '%_%';
// URL base depends on permalink settings.
$format = $wp_rewrite->using_index_permalinks() && ! strpos( $pagenum_link, 'index.php' ) ? 'index.php/' : '';
$format .= $wp_rewrite->using_permalinks() ? user_trailingslashit( $wp_rewrite->pagination_base . '/%#%', 'paged' ) : '?paged=%#%';
return [
'base' => $base,
'format' => $format,
'total' => $total,
'current' => $current
];
} | php | protected function postsArgs() {
global $wp_query, $wp_rewrite;
// Setting up default values based on the current URL.
$pagenum_link = html_entity_decode( get_pagenum_link() );
$this->url_parts = explode( '?', $pagenum_link );
// Get total number of pages.
$total = isset( $wp_query->max_num_pages ) ? $wp_query->max_num_pages : 1;
// Get the current page.
$current = get_query_var( 'paged' ) ? intval( get_query_var( 'paged' ) ) : 1;
// Append the format placeholder to the base URL.
$base = trailingslashit( $this->url_parts[0] ) . '%_%';
// URL base depends on permalink settings.
$format = $wp_rewrite->using_index_permalinks() && ! strpos( $pagenum_link, 'index.php' ) ? 'index.php/' : '';
$format .= $wp_rewrite->using_permalinks() ? user_trailingslashit( $wp_rewrite->pagination_base . '/%#%', 'paged' ) : '?paged=%#%';
return [
'base' => $base,
'format' => $format,
'total' => $total,
'current' => $current
];
} | [
"protected",
"function",
"postsArgs",
"(",
")",
"{",
"global",
"$",
"wp_query",
",",
"$",
"wp_rewrite",
";",
"// Setting up default values based on the current URL.",
"$",
"pagenum_link",
"=",
"html_entity_decode",
"(",
"get_pagenum_link",
"(",
")",
")",
";",
"$",
"... | Returns custom arguments for normal, posts pagination.
@since 5.0.0
@access protected
@global object $wp_query
@global object $wp_rewrite
@return array | [
"Returns",
"custom",
"arguments",
"for",
"normal",
"posts",
"pagination",
"."
] | train | https://github.com/justintadlock/hybrid-core/blob/20f15f3235505ed7d11f121f45b2ef226bc0c88f/src/Pagination/Pagination.php#L225-L251 |
justintadlock/hybrid-core | src/Pagination/Pagination.php | Pagination.postArgs | protected function postArgs() {
global $page, $numpages, $more, $wp_rewrite;
// Split the current URL between the base and query string.
$this->url_parts = explode( '?', html_entity_decode( get_permalink() ) );
// Build the base without the query string.
$base = trailingslashit( $this->url_parts[0] ) . '%_%';
// Build URL format.
$format = $wp_rewrite->using_index_permalinks() && ! strpos( $base, 'index.php' ) ? 'index.php/' : '';
$format .= $wp_rewrite->using_permalinks() ? user_trailingslashit( '%#%' ) : '?page=%#%';
return [
'base' => $base,
'format' => $format,
'current' => ! $more && 1 === $page ? 0 : $page,
'total' => $numpages
];
} | php | protected function postArgs() {
global $page, $numpages, $more, $wp_rewrite;
// Split the current URL between the base and query string.
$this->url_parts = explode( '?', html_entity_decode( get_permalink() ) );
// Build the base without the query string.
$base = trailingslashit( $this->url_parts[0] ) . '%_%';
// Build URL format.
$format = $wp_rewrite->using_index_permalinks() && ! strpos( $base, 'index.php' ) ? 'index.php/' : '';
$format .= $wp_rewrite->using_permalinks() ? user_trailingslashit( '%#%' ) : '?page=%#%';
return [
'base' => $base,
'format' => $format,
'current' => ! $more && 1 === $page ? 0 : $page,
'total' => $numpages
];
} | [
"protected",
"function",
"postArgs",
"(",
")",
"{",
"global",
"$",
"page",
",",
"$",
"numpages",
",",
"$",
"more",
",",
"$",
"wp_rewrite",
";",
"// Split the current URL between the base and query string.",
"$",
"this",
"->",
"url_parts",
"=",
"explode",
"(",
"'... | Returns custom arguments for singular post pagination.
@since 5.0.0
@access protected
@global int $page
@global int $numpages
@global bool $more
@global object $wp_rewrite
@return array | [
"Returns",
"custom",
"arguments",
"for",
"singular",
"post",
"pagination",
"."
] | train | https://github.com/justintadlock/hybrid-core/blob/20f15f3235505ed7d11f121f45b2ef226bc0c88f/src/Pagination/Pagination.php#L264-L283 |
justintadlock/hybrid-core | src/Pagination/Pagination.php | Pagination.commentsArgs | protected function commentsArgs() {
global $wp_rewrite;
$base = add_query_arg( 'cpage', '%#%' );
// Split the current URL between the base and query string.
$this->url_parts = explode( '?', html_entity_decode( get_pagenum_link() ) );
if ( $wp_rewrite->using_permalinks() ) {
$base = user_trailingslashit( trailingslashit( get_permalink() ) . $wp_rewrite->comments_pagination_base . '-%#%', 'commentpaged' );
}
return [
'base' => $base,
'format' => '',
'total' => get_comment_pages_count(),
'current' => get_query_var( 'cpage' ) ?: 1,
'add_fragment' => '#comments'
];
} | php | protected function commentsArgs() {
global $wp_rewrite;
$base = add_query_arg( 'cpage', '%#%' );
// Split the current URL between the base and query string.
$this->url_parts = explode( '?', html_entity_decode( get_pagenum_link() ) );
if ( $wp_rewrite->using_permalinks() ) {
$base = user_trailingslashit( trailingslashit( get_permalink() ) . $wp_rewrite->comments_pagination_base . '-%#%', 'commentpaged' );
}
return [
'base' => $base,
'format' => '',
'total' => get_comment_pages_count(),
'current' => get_query_var( 'cpage' ) ?: 1,
'add_fragment' => '#comments'
];
} | [
"protected",
"function",
"commentsArgs",
"(",
")",
"{",
"global",
"$",
"wp_rewrite",
";",
"$",
"base",
"=",
"add_query_arg",
"(",
"'cpage'",
",",
"'%#%'",
")",
";",
"// Split the current URL between the base and query string.",
"$",
"this",
"->",
"url_parts",
"=",
... | Returns custom arguments for comments pagination.
@since 5.0.0
@access protected
@global object $wp_rewrite
@return array | [
"Returns",
"custom",
"arguments",
"for",
"comments",
"pagination",
"."
] | train | https://github.com/justintadlock/hybrid-core/blob/20f15f3235505ed7d11f121f45b2ef226bc0c88f/src/Pagination/Pagination.php#L292-L311 |
justintadlock/hybrid-core | src/Pagination/Pagination.php | Pagination.render | public function render() {
$title = $list = $template = '';
if ( $this->items ) {
// If there's title text, format it.
if ( $this->args['title_text'] ) {
$title = sprintf(
'<%1$s class="%2$s">%3$s</%1$s>',
tag_escape( $this->args['title_tag'] ),
esc_attr( $this->args['title_class'] ),
esc_html( $this->args['title_text'] )
);
}
// Loop through each of the items and format each into
// an HTML string.
foreach ( $this->items as $item ) {
$list .= $this->formatItem( $item );
}
// Format the list.
$list = sprintf(
'<%1$s class="%2$s">%3$s</%1$s>',
tag_escape( $this->args['list_tag'] ),
esc_attr( $this->args['list_class'] ),
$list
);
// Format the nav wrapper.
$template = sprintf(
'<%1$s class="%2$s" role="navigation">%3$s%4$s</%1$s>',
tag_escape( $this->args['container_tag'] ),
esc_attr( sprintf( $this->args['container_class'], $this->context ) ),
$title,
$list
);
}
return apply_filters( "hybrid/pagination/{$this->context}", $template, $this->args );
} | php | public function render() {
$title = $list = $template = '';
if ( $this->items ) {
// If there's title text, format it.
if ( $this->args['title_text'] ) {
$title = sprintf(
'<%1$s class="%2$s">%3$s</%1$s>',
tag_escape( $this->args['title_tag'] ),
esc_attr( $this->args['title_class'] ),
esc_html( $this->args['title_text'] )
);
}
// Loop through each of the items and format each into
// an HTML string.
foreach ( $this->items as $item ) {
$list .= $this->formatItem( $item );
}
// Format the list.
$list = sprintf(
'<%1$s class="%2$s">%3$s</%1$s>',
tag_escape( $this->args['list_tag'] ),
esc_attr( $this->args['list_class'] ),
$list
);
// Format the nav wrapper.
$template = sprintf(
'<%1$s class="%2$s" role="navigation">%3$s%4$s</%1$s>',
tag_escape( $this->args['container_tag'] ),
esc_attr( sprintf( $this->args['container_class'], $this->context ) ),
$title,
$list
);
}
return apply_filters( "hybrid/pagination/{$this->context}", $template, $this->args );
} | [
"public",
"function",
"render",
"(",
")",
"{",
"$",
"title",
"=",
"$",
"list",
"=",
"$",
"template",
"=",
"''",
";",
"if",
"(",
"$",
"this",
"->",
"items",
")",
"{",
"// If there's title text, format it.",
"if",
"(",
"$",
"this",
"->",
"args",
"[",
"... | Returns the pagination output.
@since 5.0.0
@access public
@return string | [
"Returns",
"the",
"pagination",
"output",
"."
] | train | https://github.com/justintadlock/hybrid-core/blob/20f15f3235505ed7d11f121f45b2ef226bc0c88f/src/Pagination/Pagination.php#L332-L375 |
justintadlock/hybrid-core | src/Pagination/Pagination.php | Pagination.make | public function make() {
if ( 2 <= $this->total ) {
$this->prevItem();
for ( $n = 1; $n <= $this->total; $n++ ) {
$this->pageItem( $n );
}
$this->nextItem();
}
return $this;
} | php | public function make() {
if ( 2 <= $this->total ) {
$this->prevItem();
for ( $n = 1; $n <= $this->total; $n++ ) {
$this->pageItem( $n );
}
$this->nextItem();
}
return $this;
} | [
"public",
"function",
"make",
"(",
")",
"{",
"if",
"(",
"2",
"<=",
"$",
"this",
"->",
"total",
")",
"{",
"$",
"this",
"->",
"prevItem",
"(",
")",
";",
"for",
"(",
"$",
"n",
"=",
"1",
";",
"$",
"n",
"<=",
"$",
"this",
"->",
"total",
";",
"$"... | Builds the pagination `$items` array.
@since 5.0.0
@access public
@return PaginationContract | [
"Builds",
"the",
"pagination",
"$items",
"array",
"."
] | train | https://github.com/justintadlock/hybrid-core/blob/20f15f3235505ed7d11f121f45b2ef226bc0c88f/src/Pagination/Pagination.php#L384-L398 |
justintadlock/hybrid-core | src/Pagination/Pagination.php | Pagination.formatItem | private function formatItem( $item ) {
$is_link = isset( $item['url'] );
$attr = [];
$esc_attr = '';
// Add the anchor/span class attribute.
$attr['class'] = sprintf(
$this->args['anchor_class'],
$is_link ? 'link' : $item['type']
);
// If this is a link, add the URL.
if ( $is_link ) {
$attr['href'] = $item['url'];
}
// If this is the current item, add the `aria-current` attribute.
if ( 'current' === $item['type'] ) {
$attr['aria-current'] = $this->args['aria_current'];
}
// Loop through the attributes and format them into a string.
foreach ( $attr as $name => $value ) {
$esc_attr .= sprintf(
' %s="%s"',
esc_html( $name ),
'href' === $name ? esc_url( $value ) : esc_attr( $value )
);
}
// Builds and formats the list item.
return sprintf(
'<%1$s class="%2$s"><%3$s %4$s>%5$s</%3$s></%1$s>',
tag_escape( $this->args['item_tag'] ),
esc_attr( sprintf( $this->args['item_class'], $item['type'] ) ),
$is_link ? 'a' : 'span',
trim( $esc_attr ),
$item['content']
);
} | php | private function formatItem( $item ) {
$is_link = isset( $item['url'] );
$attr = [];
$esc_attr = '';
// Add the anchor/span class attribute.
$attr['class'] = sprintf(
$this->args['anchor_class'],
$is_link ? 'link' : $item['type']
);
// If this is a link, add the URL.
if ( $is_link ) {
$attr['href'] = $item['url'];
}
// If this is the current item, add the `aria-current` attribute.
if ( 'current' === $item['type'] ) {
$attr['aria-current'] = $this->args['aria_current'];
}
// Loop through the attributes and format them into a string.
foreach ( $attr as $name => $value ) {
$esc_attr .= sprintf(
' %s="%s"',
esc_html( $name ),
'href' === $name ? esc_url( $value ) : esc_attr( $value )
);
}
// Builds and formats the list item.
return sprintf(
'<%1$s class="%2$s"><%3$s %4$s>%5$s</%3$s></%1$s>',
tag_escape( $this->args['item_tag'] ),
esc_attr( sprintf( $this->args['item_class'], $item['type'] ) ),
$is_link ? 'a' : 'span',
trim( $esc_attr ),
$item['content']
);
} | [
"private",
"function",
"formatItem",
"(",
"$",
"item",
")",
"{",
"$",
"is_link",
"=",
"isset",
"(",
"$",
"item",
"[",
"'url'",
"]",
")",
";",
"$",
"attr",
"=",
"[",
"]",
";",
"$",
"esc_attr",
"=",
"''",
";",
"// Add the anchor/span class attribute.",
"... | Format an item's HTML output.
@since 5.0.0
@access private
@param array $item
@return string | [
"Format",
"an",
"item",
"s",
"HTML",
"output",
"."
] | train | https://github.com/justintadlock/hybrid-core/blob/20f15f3235505ed7d11f121f45b2ef226bc0c88f/src/Pagination/Pagination.php#L408-L449 |
justintadlock/hybrid-core | src/Pagination/Pagination.php | Pagination.prevItem | protected function prevItem() {
if ( $this->args['prev_next'] && $this->current && 1 < $this->current ) {
$this->items[] = [
'type' => 'prev',
'url' => $this->buildUrl( 2 == $this->current ? '' : $this->args['format'], $this->current - 1 ),
'content' => $this->args['prev_text']
];
}
} | php | protected function prevItem() {
if ( $this->args['prev_next'] && $this->current && 1 < $this->current ) {
$this->items[] = [
'type' => 'prev',
'url' => $this->buildUrl( 2 == $this->current ? '' : $this->args['format'], $this->current - 1 ),
'content' => $this->args['prev_text']
];
}
} | [
"protected",
"function",
"prevItem",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"args",
"[",
"'prev_next'",
"]",
"&&",
"$",
"this",
"->",
"current",
"&&",
"1",
"<",
"$",
"this",
"->",
"current",
")",
"{",
"$",
"this",
"->",
"items",
"[",
"]",
"... | Builds the previous item.
@since 5.0.0
@access protected
@return void | [
"Builds",
"the",
"previous",
"item",
"."
] | train | https://github.com/justintadlock/hybrid-core/blob/20f15f3235505ed7d11f121f45b2ef226bc0c88f/src/Pagination/Pagination.php#L458-L468 |
justintadlock/hybrid-core | src/Pagination/Pagination.php | Pagination.nextItem | protected function nextItem() {
if ( $this->args['prev_next'] && $this->current && $this->current < $this->total ) {
$this->items[] = [
'type' => 'next',
'url' => $this->buildUrl( $this->args['format'], $this->current + 1 ),
'content' => $this->args['next_text']
];
}
} | php | protected function nextItem() {
if ( $this->args['prev_next'] && $this->current && $this->current < $this->total ) {
$this->items[] = [
'type' => 'next',
'url' => $this->buildUrl( $this->args['format'], $this->current + 1 ),
'content' => $this->args['next_text']
];
}
} | [
"protected",
"function",
"nextItem",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"args",
"[",
"'prev_next'",
"]",
"&&",
"$",
"this",
"->",
"current",
"&&",
"$",
"this",
"->",
"current",
"<",
"$",
"this",
"->",
"total",
")",
"{",
"$",
"this",
"->",... | Builds the next item.
@since 5.0.0
@access protected
@return void | [
"Builds",
"the",
"next",
"item",
"."
] | train | https://github.com/justintadlock/hybrid-core/blob/20f15f3235505ed7d11f121f45b2ef226bc0c88f/src/Pagination/Pagination.php#L477-L487 |
justintadlock/hybrid-core | src/Pagination/Pagination.php | Pagination.pageItem | protected function pageItem( $n ) {
// If the current item we're building is for the current page
// being viewed.
if ( $n === $this->current ) {
$this->items[] = [
'type' => 'current',
'content' => $this->args['before_page_number'] . number_format_i18n( $n ) . $this->args['after_page_number']
];
$this->dots = true;
// If showing a linked number or dots.
} else {
if ( $this->args['show_all'] || ( $n <= $this->end_size || ( $this->current && $n >= $this->current - $this->mid_size && $n <= $this->current + $this->mid_size ) || $n > $this->total - $this->end_size ) ) {
$this->items[] = [
'type' => 'number',
'url' => $this->buildUrl( 1 == $n ? '' : $this->args['format'], $n ),
'content' => $this->args['before_page_number'] . number_format_i18n( $n ) . $this->args['after_page_number']
];
$this->dots = true;
} elseif ( $this->dots && ! $this->args['show_all'] ) {
$this->items[] = [
'type' => 'dots',
'content' => __( '…', 'hybrid-core' )
];
$this->dots = false;
}
}
} | php | protected function pageItem( $n ) {
// If the current item we're building is for the current page
// being viewed.
if ( $n === $this->current ) {
$this->items[] = [
'type' => 'current',
'content' => $this->args['before_page_number'] . number_format_i18n( $n ) . $this->args['after_page_number']
];
$this->dots = true;
// If showing a linked number or dots.
} else {
if ( $this->args['show_all'] || ( $n <= $this->end_size || ( $this->current && $n >= $this->current - $this->mid_size && $n <= $this->current + $this->mid_size ) || $n > $this->total - $this->end_size ) ) {
$this->items[] = [
'type' => 'number',
'url' => $this->buildUrl( 1 == $n ? '' : $this->args['format'], $n ),
'content' => $this->args['before_page_number'] . number_format_i18n( $n ) . $this->args['after_page_number']
];
$this->dots = true;
} elseif ( $this->dots && ! $this->args['show_all'] ) {
$this->items[] = [
'type' => 'dots',
'content' => __( '…', 'hybrid-core' )
];
$this->dots = false;
}
}
} | [
"protected",
"function",
"pageItem",
"(",
"$",
"n",
")",
"{",
"// If the current item we're building is for the current page",
"// being viewed.",
"if",
"(",
"$",
"n",
"===",
"$",
"this",
"->",
"current",
")",
"{",
"$",
"this",
"->",
"items",
"[",
"]",
"=",
"[... | Builds the numeric page link, current item, and dots item.
@since 5.0.0
@access protected
@return void | [
"Builds",
"the",
"numeric",
"page",
"link",
"current",
"item",
"and",
"dots",
"item",
"."
] | train | https://github.com/justintadlock/hybrid-core/blob/20f15f3235505ed7d11f121f45b2ef226bc0c88f/src/Pagination/Pagination.php#L496-L532 |
justintadlock/hybrid-core | src/Pagination/Pagination.php | Pagination.buildUrl | protected function buildUrl( $format, $number ) {
$link = str_replace( '%_%', $format, $this->args['base'] );
$link = str_replace( '%#%', $number, $link );
// Adds any existing or new query vars to the URL.
if ( $this->args['add_args'] ) {
$link = add_query_arg( $this->args['add_args'], $link );
}
// Appends a fragment to the end of the URL.
$link .= $this->args['add_fragment'];
// Applies the core WP `paginate_links` filter hook.
return apply_filters( 'paginate_links', $link );
} | php | protected function buildUrl( $format, $number ) {
$link = str_replace( '%_%', $format, $this->args['base'] );
$link = str_replace( '%#%', $number, $link );
// Adds any existing or new query vars to the URL.
if ( $this->args['add_args'] ) {
$link = add_query_arg( $this->args['add_args'], $link );
}
// Appends a fragment to the end of the URL.
$link .= $this->args['add_fragment'];
// Applies the core WP `paginate_links` filter hook.
return apply_filters( 'paginate_links', $link );
} | [
"protected",
"function",
"buildUrl",
"(",
"$",
"format",
",",
"$",
"number",
")",
"{",
"$",
"link",
"=",
"str_replace",
"(",
"'%_%'",
",",
"$",
"format",
",",
"$",
"this",
"->",
"args",
"[",
"'base'",
"]",
")",
";",
"$",
"link",
"=",
"str_replace",
... | Builds and formats a page link URL.
@since 5.0.0
@access protected
@param string $format
@param int $number
@return string | [
"Builds",
"and",
"formats",
"a",
"page",
"link",
"URL",
"."
] | train | https://github.com/justintadlock/hybrid-core/blob/20f15f3235505ed7d11f121f45b2ef226bc0c88f/src/Pagination/Pagination.php#L543-L558 |
justintadlock/hybrid-core | src/Core/Application.php | Application.registerDefaultBindings | protected function registerDefaultBindings() {
// Add the instance of this application.
$this->instance( 'app', $this );
// Adds the directory path for the framework.
$this->instance( 'path', untrailingslashit( HYBRID_DIR ) );
// Add the version for the framework.
$this->instance( 'version', static::VERSION );
} | php | protected function registerDefaultBindings() {
// Add the instance of this application.
$this->instance( 'app', $this );
// Adds the directory path for the framework.
$this->instance( 'path', untrailingslashit( HYBRID_DIR ) );
// Add the version for the framework.
$this->instance( 'version', static::VERSION );
} | [
"protected",
"function",
"registerDefaultBindings",
"(",
")",
"{",
"// Add the instance of this application.",
"$",
"this",
"->",
"instance",
"(",
"'app'",
",",
"$",
"this",
")",
";",
"// Adds the directory path for the framework.",
"$",
"this",
"->",
"instance",
"(",
... | Registers the default bindings we need to run the framework.
@since 5.0.0
@access protected
@return void | [
"Registers",
"the",
"default",
"bindings",
"we",
"need",
"to",
"run",
"the",
"framework",
"."
] | train | https://github.com/justintadlock/hybrid-core/blob/20f15f3235505ed7d11f121f45b2ef226bc0c88f/src/Core/Application.php#L103-L113 |
justintadlock/hybrid-core | src/Core/Application.php | Application.registerDefaultProviders | protected function registerDefaultProviders() {
array_map( function( $provider ) {
$this->provider( $provider );
}, [
AttrServiceProvider::class,
LanguageServiceProvider::class,
MetaServiceProvider::class,
TemplatesServiceProvider::class,
HierarchyServiceProvider::class,
ViewServiceProvider::class
] );
} | php | protected function registerDefaultProviders() {
array_map( function( $provider ) {
$this->provider( $provider );
}, [
AttrServiceProvider::class,
LanguageServiceProvider::class,
MetaServiceProvider::class,
TemplatesServiceProvider::class,
HierarchyServiceProvider::class,
ViewServiceProvider::class
] );
} | [
"protected",
"function",
"registerDefaultProviders",
"(",
")",
"{",
"array_map",
"(",
"function",
"(",
"$",
"provider",
")",
"{",
"$",
"this",
"->",
"provider",
"(",
"$",
"provider",
")",
";",
"}",
",",
"[",
"AttrServiceProvider",
"::",
"class",
",",
"Lang... | Adds the default service providers for the framework.
@since 5.0.0
@access protected
@return void | [
"Adds",
"the",
"default",
"service",
"providers",
"for",
"the",
"framework",
"."
] | train | https://github.com/justintadlock/hybrid-core/blob/20f15f3235505ed7d11f121f45b2ef226bc0c88f/src/Core/Application.php#L122-L134 |
justintadlock/hybrid-core | src/Core/Application.php | Application.provider | public function provider( $provider ) {
if ( is_string( $provider ) ) {
$provider = $this->resolveProvider( $provider );
}
$this->providers[] = $provider;
} | php | public function provider( $provider ) {
if ( is_string( $provider ) ) {
$provider = $this->resolveProvider( $provider );
}
$this->providers[] = $provider;
} | [
"public",
"function",
"provider",
"(",
"$",
"provider",
")",
"{",
"if",
"(",
"is_string",
"(",
"$",
"provider",
")",
")",
"{",
"$",
"provider",
"=",
"$",
"this",
"->",
"resolveProvider",
"(",
"$",
"provider",
")",
";",
"}",
"$",
"this",
"->",
"provid... | Adds a service provider.
@since 5.0.0
@access public
@param string|object $provider
@return void | [
"Adds",
"a",
"service",
"provider",
"."
] | train | https://github.com/justintadlock/hybrid-core/blob/20f15f3235505ed7d11f121f45b2ef226bc0c88f/src/Core/Application.php#L168-L175 |
justintadlock/hybrid-core | src/Core/Application.php | Application.registerProxies | protected function registerProxies() {
Proxy::setContainer( $this );
foreach ( $this->proxies as $class => $alias ) {
class_alias( $class, $alias );
}
} | php | protected function registerProxies() {
Proxy::setContainer( $this );
foreach ( $this->proxies as $class => $alias ) {
class_alias( $class, $alias );
}
} | [
"protected",
"function",
"registerProxies",
"(",
")",
"{",
"Proxy",
"::",
"setContainer",
"(",
"$",
"this",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"proxies",
"as",
"$",
"class",
"=>",
"$",
"alias",
")",
"{",
"class_alias",
"(",
"$",
"class",
",",... | Registers the static proxy classes.
@since 5.0.0
@access protected
@return void | [
"Registers",
"the",
"static",
"proxy",
"classes",
"."
] | train | https://github.com/justintadlock/hybrid-core/blob/20f15f3235505ed7d11f121f45b2ef226bc0c88f/src/Core/Application.php#L282-L289 |
justintadlock/hybrid-core | src/Lang/Language.php | Language.boot | public function boot() {
// Load the locale functions files.
add_action( 'after_setup_theme', [ $this, 'loadLocaleFunctions' ], ~PHP_INT_MAX );
// Load framework textdomain.
add_action( 'after_setup_theme', [ $this, 'loadTextdomain' ], 95 );
// Overrides the load textdomain function for the 'hybrid-core' domain.
add_filter( 'override_load_textdomain', [ $this, 'overrideLoadTextdomain' ], 5, 3 );
// Filter the textdomain mofile to allow child themes to load the parent theme translation.
add_filter( 'load_textdomain_mofile', [ $this, 'loadTextdomainMofile' ], 10, 2 );
} | php | public function boot() {
// Load the locale functions files.
add_action( 'after_setup_theme', [ $this, 'loadLocaleFunctions' ], ~PHP_INT_MAX );
// Load framework textdomain.
add_action( 'after_setup_theme', [ $this, 'loadTextdomain' ], 95 );
// Overrides the load textdomain function for the 'hybrid-core' domain.
add_filter( 'override_load_textdomain', [ $this, 'overrideLoadTextdomain' ], 5, 3 );
// Filter the textdomain mofile to allow child themes to load the parent theme translation.
add_filter( 'load_textdomain_mofile', [ $this, 'loadTextdomainMofile' ], 10, 2 );
} | [
"public",
"function",
"boot",
"(",
")",
"{",
"// Load the locale functions files.",
"add_action",
"(",
"'after_setup_theme'",
",",
"[",
"$",
"this",
",",
"'loadLocaleFunctions'",
"]",
",",
"~",
"PHP_INT_MAX",
")",
";",
"// Load framework textdomain.",
"add_action",
"(... | Adds the class' actions and filters.
@since 5.0.0
@access public
@return void | [
"Adds",
"the",
"class",
"actions",
"and",
"filters",
"."
] | train | https://github.com/justintadlock/hybrid-core/blob/20f15f3235505ed7d11f121f45b2ef226bc0c88f/src/Lang/Language.php#L96-L109 |
justintadlock/hybrid-core | src/Lang/Language.php | Language.loadLocaleFunctions | public function loadLocaleFunctions() {
// Get the site's locale.
$locale = is_admin() ? get_user_locale() : get_locale();
$locale = strtolower( str_replace( '_', '-', $locale ) );
// Define locale functions files.
$child_func = $this->childPath( "{$locale}.php" );
$theme_func = $this->parentPath( "{$locale}.php" );
// If file exists in child theme.
if ( is_child_theme() && file_exists( $child_func ) ) {
require_once( $child_func );
}
// If file exists in parent theme.
if ( file_exists( $theme_func ) ) {
require_once( $theme_func );
}
} | php | public function loadLocaleFunctions() {
// Get the site's locale.
$locale = is_admin() ? get_user_locale() : get_locale();
$locale = strtolower( str_replace( '_', '-', $locale ) );
// Define locale functions files.
$child_func = $this->childPath( "{$locale}.php" );
$theme_func = $this->parentPath( "{$locale}.php" );
// If file exists in child theme.
if ( is_child_theme() && file_exists( $child_func ) ) {
require_once( $child_func );
}
// If file exists in parent theme.
if ( file_exists( $theme_func ) ) {
require_once( $theme_func );
}
} | [
"public",
"function",
"loadLocaleFunctions",
"(",
")",
"{",
"// Get the site's locale.",
"$",
"locale",
"=",
"is_admin",
"(",
")",
"?",
"get_user_locale",
"(",
")",
":",
"get_locale",
"(",
")",
";",
"$",
"locale",
"=",
"strtolower",
"(",
"str_replace",
"(",
... | Loads a `/{$langpath}/{$locale}.php` file for specific locales.
`$locale` should be an all lowercase and hyphenated (as opposed to
an underscore) file name. So, an `en_US` locale would be `en-us.php`.
Also note that the child theme locale file will load **before** the
parent theme locale file. This is standard practice in core WP for
allowing pluggable functions if a theme author so desires.
@since 5.0.0
@access public
@return void | [
"Loads",
"a",
"/",
"{",
"$langpath",
"}",
"/",
"{",
"$locale",
"}",
".",
"php",
"file",
"for",
"specific",
"locales",
".",
"$locale",
"should",
"be",
"an",
"all",
"lowercase",
"and",
"hyphenated",
"(",
"as",
"opposed",
"to",
"an",
"underscore",
")",
"f... | train | https://github.com/justintadlock/hybrid-core/blob/20f15f3235505ed7d11f121f45b2ef226bc0c88f/src/Lang/Language.php#L181-L200 |
justintadlock/hybrid-core | src/Lang/Language.php | Language.overrideLoadTextdomain | public function overrideLoadTextdomain( $override, $domain, $mofile ) {
global $l10n;
// Check if the domain is one of our framework domains.
if ( 'hybrid-core' === $domain ) {
// Get the theme's textdomain.
$theme_textdomain = $this->parentTextdomain();
// If the theme's textdomain is loaded, use its translations instead.
if ( $theme_textdomain && isset( $l10n[ $theme_textdomain ] ) ) {
$l10n[ $domain ] = $l10n[ $theme_textdomain ];
}
// Always override. We only want the theme to handle translations.
$override = true;
}
return $override;
} | php | public function overrideLoadTextdomain( $override, $domain, $mofile ) {
global $l10n;
// Check if the domain is one of our framework domains.
if ( 'hybrid-core' === $domain ) {
// Get the theme's textdomain.
$theme_textdomain = $this->parentTextdomain();
// If the theme's textdomain is loaded, use its translations instead.
if ( $theme_textdomain && isset( $l10n[ $theme_textdomain ] ) ) {
$l10n[ $domain ] = $l10n[ $theme_textdomain ];
}
// Always override. We only want the theme to handle translations.
$override = true;
}
return $override;
} | [
"public",
"function",
"overrideLoadTextdomain",
"(",
"$",
"override",
",",
"$",
"domain",
",",
"$",
"mofile",
")",
"{",
"global",
"$",
"l10n",
";",
"// Check if the domain is one of our framework domains.",
"if",
"(",
"'hybrid-core'",
"===",
"$",
"domain",
")",
"{... | Overrides the load textdomain functionality when `hybrid-core` is
the domain in use. The purpose of this is to allow theme translations
to handle the framework's strings. What this function does is sets
the `hybrid-core` domain's translations to the theme's. That way,
we're not loading multiple of the same MO files.
@since 5.0.0
@access public
@global array $l10n
@param bool $override
@param string $domain
@param string $mofile
@return bool | [
"Overrides",
"the",
"load",
"textdomain",
"functionality",
"when",
"hybrid",
"-",
"core",
"is",
"the",
"domain",
"in",
"use",
".",
"The",
"purpose",
"of",
"this",
"is",
"to",
"allow",
"theme",
"translations",
"to",
"handle",
"the",
"framework",
"s",
"strings... | train | https://github.com/justintadlock/hybrid-core/blob/20f15f3235505ed7d11f121f45b2ef226bc0c88f/src/Lang/Language.php#L231-L251 |
justintadlock/hybrid-core | src/Lang/Language.php | Language.loadTextdomainMofile | public function loadTextdomainMofile( $mofile, $domain ) {
// If the `$domain` is for the parent or child theme, search for
// a `$domain-$locale.mo` file.
if ( $domain == $this->parentTextdomain() || $domain == $this->childTextdomain() ) {
// Get the locale.
$locale = is_admin() ? get_user_locale() : get_locale();
// Define locale functions files.
$child_mofile = $this->childPath( "{$domain}-{$locale}.mo" );
$theme_mofile = $this->parentPath( "{$domain}-{$locale}.mo" );
// Overwrite the mofile if it exists.
if ( is_child_theme() && file_exists( $child_mofile ) ) {
$mofile = $child_mofile;
} elseif ( file_exists( $theme_mofile ) ) {
$mofile = $theme_mofile;
}
}
return $mofile;
} | php | public function loadTextdomainMofile( $mofile, $domain ) {
// If the `$domain` is for the parent or child theme, search for
// a `$domain-$locale.mo` file.
if ( $domain == $this->parentTextdomain() || $domain == $this->childTextdomain() ) {
// Get the locale.
$locale = is_admin() ? get_user_locale() : get_locale();
// Define locale functions files.
$child_mofile = $this->childPath( "{$domain}-{$locale}.mo" );
$theme_mofile = $this->parentPath( "{$domain}-{$locale}.mo" );
// Overwrite the mofile if it exists.
if ( is_child_theme() && file_exists( $child_mofile ) ) {
$mofile = $child_mofile;
} elseif ( file_exists( $theme_mofile ) ) {
$mofile = $theme_mofile;
}
}
return $mofile;
} | [
"public",
"function",
"loadTextdomainMofile",
"(",
"$",
"mofile",
",",
"$",
"domain",
")",
"{",
"// If the `$domain` is for the parent or child theme, search for",
"// a `$domain-$locale.mo` file.",
"if",
"(",
"$",
"domain",
"==",
"$",
"this",
"->",
"parentTextdomain",
"(... | Filters the `load_textdomain_mofile` filter hook so that we can
prepend the theme textdomain to the mofile filename. This also allows
child themes to house a copy of the parent theme translations so that
it doesn't get overwritten when a parent theme is updated.
@since 5.0.0
@access public
@param string $mofile File name of the .mo file.
@param string $domain The textdomain currently being filtered.
@return string | [
"Filters",
"the",
"load_textdomain_mofile",
"filter",
"hook",
"so",
"that",
"we",
"can",
"prepend",
"the",
"theme",
"textdomain",
"to",
"the",
"mofile",
"filename",
".",
"This",
"also",
"allows",
"child",
"themes",
"to",
"house",
"a",
"copy",
"of",
"the",
"p... | train | https://github.com/justintadlock/hybrid-core/blob/20f15f3235505ed7d11f121f45b2ef226bc0c88f/src/Lang/Language.php#L265-L290 |
justintadlock/hybrid-core | src/Template/HierarchyServiceProvider.php | HierarchyServiceProvider.register | public function register() {
$this->app->singleton( TemplateHierarchy::class, Hierarchy::class );
$this->app->alias( TemplateHierarchy::class, 'template/hierarchy' );
} | php | public function register() {
$this->app->singleton( TemplateHierarchy::class, Hierarchy::class );
$this->app->alias( TemplateHierarchy::class, 'template/hierarchy' );
} | [
"public",
"function",
"register",
"(",
")",
"{",
"$",
"this",
"->",
"app",
"->",
"singleton",
"(",
"TemplateHierarchy",
"::",
"class",
",",
"Hierarchy",
"::",
"class",
")",
";",
"$",
"this",
"->",
"app",
"->",
"alias",
"(",
"TemplateHierarchy",
"::",
"cl... | Registration callback that adds a single instance of the template
hierarchy to the container.
@since 5.0.0
@access public
@return void | [
"Registration",
"callback",
"that",
"adds",
"a",
"single",
"instance",
"of",
"the",
"template",
"hierarchy",
"to",
"the",
"container",
"."
] | train | https://github.com/justintadlock/hybrid-core/blob/20f15f3235505ed7d11f121f45b2ef226bc0c88f/src/Template/HierarchyServiceProvider.php#L36-L41 |
justintadlock/hybrid-core | src/Container/Container.php | Container.bind | public function bind( $abstract, $concrete = null, $shared = false ) {
unset( $this->instances[ $abstract ] );
if ( is_null( $concrete ) ) {
$concrete = $abstract;
}
$this->bindings[ $abstract ] = compact( 'concrete', 'shared' );
$this->extensions[ $abstract ] = [];
} | php | public function bind( $abstract, $concrete = null, $shared = false ) {
unset( $this->instances[ $abstract ] );
if ( is_null( $concrete ) ) {
$concrete = $abstract;
}
$this->bindings[ $abstract ] = compact( 'concrete', 'shared' );
$this->extensions[ $abstract ] = [];
} | [
"public",
"function",
"bind",
"(",
"$",
"abstract",
",",
"$",
"concrete",
"=",
"null",
",",
"$",
"shared",
"=",
"false",
")",
"{",
"unset",
"(",
"$",
"this",
"->",
"instances",
"[",
"$",
"abstract",
"]",
")",
";",
"if",
"(",
"is_null",
"(",
"$",
... | Add a binding. The abstract should be a key, abstract class name, or
interface name. The concrete should be the concrete implementation of
the abstract. If no concrete is given, its assumed the abstract
handles the concrete implementation.
@since 5.0.0
@access public
@param string $abstract
@param mixed $concrete
@param bool $shared
@return void | [
"Add",
"a",
"binding",
".",
"The",
"abstract",
"should",
"be",
"a",
"key",
"abstract",
"class",
"name",
"or",
"interface",
"name",
".",
"The",
"concrete",
"should",
"be",
"the",
"concrete",
"implementation",
"of",
"the",
"abstract",
".",
"If",
"no",
"concr... | train | https://github.com/justintadlock/hybrid-core/blob/20f15f3235505ed7d11f121f45b2ef226bc0c88f/src/Container/Container.php#L98-L108 |
justintadlock/hybrid-core | src/Container/Container.php | Container.resolve | public function resolve( $abstract, array $parameters = [] ) {
// Get the true abstract name.
$abstract = $this->getAbstract( $abstract );
// If this is being managed as an instance and we already have
// the instance, return it now.
if ( isset( $this->instances[ $abstract ] ) ) {
return $this->instances[ $abstract ];
}
// Get the concrete implementation.
$concrete = $this->getConcrete( $abstract );
// If we can't build an object, assume we should return the value.
if ( ! $this->isBuildable( $concrete ) ) {
// If we don't actually have this, return false.
if ( ! $this->has( $abstract ) ) {
return false;
}
return $concrete;
}
// Build the object.
$object = $this->build( $concrete, $parameters );
if ( ! $this->has( $abstract ) ) {
return $object;
}
// If shared instance, make sure to store it in the instances
// array so that we're not creating new objects later.
if ( $this->bindings[ $abstract ]['shared'] && ! isset( $this->instances[ $abstract ] ) ) {
$this->instances[ $abstract ] = $object;
}
// Run through each of the extensions for the object.
foreach ( $this->extensions[ $abstract ] as $extension ) {
$object = new $extension( $object, $this );
}
// Return the object.
return $object;
} | php | public function resolve( $abstract, array $parameters = [] ) {
// Get the true abstract name.
$abstract = $this->getAbstract( $abstract );
// If this is being managed as an instance and we already have
// the instance, return it now.
if ( isset( $this->instances[ $abstract ] ) ) {
return $this->instances[ $abstract ];
}
// Get the concrete implementation.
$concrete = $this->getConcrete( $abstract );
// If we can't build an object, assume we should return the value.
if ( ! $this->isBuildable( $concrete ) ) {
// If we don't actually have this, return false.
if ( ! $this->has( $abstract ) ) {
return false;
}
return $concrete;
}
// Build the object.
$object = $this->build( $concrete, $parameters );
if ( ! $this->has( $abstract ) ) {
return $object;
}
// If shared instance, make sure to store it in the instances
// array so that we're not creating new objects later.
if ( $this->bindings[ $abstract ]['shared'] && ! isset( $this->instances[ $abstract ] ) ) {
$this->instances[ $abstract ] = $object;
}
// Run through each of the extensions for the object.
foreach ( $this->extensions[ $abstract ] as $extension ) {
$object = new $extension( $object, $this );
}
// Return the object.
return $object;
} | [
"public",
"function",
"resolve",
"(",
"$",
"abstract",
",",
"array",
"$",
"parameters",
"=",
"[",
"]",
")",
"{",
"// Get the true abstract name.",
"$",
"abstract",
"=",
"$",
"this",
"->",
"getAbstract",
"(",
"$",
"abstract",
")",
";",
"// If this is being mana... | Resolve and return the binding.
@since 5.0.0
@access public
@param string $abstract
@param array $parameters
@return mixed | [
"Resolve",
"and",
"return",
"the",
"binding",
"."
] | train | https://github.com/justintadlock/hybrid-core/blob/20f15f3235505ed7d11f121f45b2ef226bc0c88f/src/Container/Container.php#L150-L198 |
justintadlock/hybrid-core | src/Container/Container.php | Container.getConcrete | protected function getConcrete( $abstract ) {
$concrete = false;
$abstract = $this->getAbstract( $abstract );
if ( $this->has( $abstract ) ) {
$concrete = $this->bindings[ $abstract ]['concrete'];
}
return $concrete ?: $abstract;
} | php | protected function getConcrete( $abstract ) {
$concrete = false;
$abstract = $this->getAbstract( $abstract );
if ( $this->has( $abstract ) ) {
$concrete = $this->bindings[ $abstract ]['concrete'];
}
return $concrete ?: $abstract;
} | [
"protected",
"function",
"getConcrete",
"(",
"$",
"abstract",
")",
"{",
"$",
"concrete",
"=",
"false",
";",
"$",
"abstract",
"=",
"$",
"this",
"->",
"getAbstract",
"(",
"$",
"abstract",
")",
";",
"if",
"(",
"$",
"this",
"->",
"has",
"(",
"$",
"abstra... | Gets the concrete of an abstract.
@since 5.0.0
@access protected
@param string $abstract
@return mixed | [
"Gets",
"the",
"concrete",
"of",
"an",
"abstract",
"."
] | train | https://github.com/justintadlock/hybrid-core/blob/20f15f3235505ed7d11f121f45b2ef226bc0c88f/src/Container/Container.php#L315-L325 |
justintadlock/hybrid-core | src/Container/Container.php | Container.build | protected function build( $concrete, array $parameters = [] ) {
if ( $concrete instanceof Closure ) {
return $concrete( $this, $parameters );
}
$reflect = new ReflectionClass( $concrete );
$constructor = $reflect->getConstructor();
if ( ! $constructor ) {
return new $concrete();
}
return $reflect->newInstanceArgs(
$this->resolveDependencies( $constructor->getParameters(), $parameters )
);
} | php | protected function build( $concrete, array $parameters = [] ) {
if ( $concrete instanceof Closure ) {
return $concrete( $this, $parameters );
}
$reflect = new ReflectionClass( $concrete );
$constructor = $reflect->getConstructor();
if ( ! $constructor ) {
return new $concrete();
}
return $reflect->newInstanceArgs(
$this->resolveDependencies( $constructor->getParameters(), $parameters )
);
} | [
"protected",
"function",
"build",
"(",
"$",
"concrete",
",",
"array",
"$",
"parameters",
"=",
"[",
"]",
")",
"{",
"if",
"(",
"$",
"concrete",
"instanceof",
"Closure",
")",
"{",
"return",
"$",
"concrete",
"(",
"$",
"this",
",",
"$",
"parameters",
")",
... | Builds the concrete implementation. If a closure, we'll simply return
the closure and pass the included parameters. Otherwise, we'll resolve
the dependencies for the class and return a new object.
@since 5.0.0
@access protected
@param mixed $concrete
@param array $parameters
@return object | [
"Builds",
"the",
"concrete",
"implementation",
".",
"If",
"a",
"closure",
"we",
"ll",
"simply",
"return",
"the",
"closure",
"and",
"pass",
"the",
"included",
"parameters",
".",
"Otherwise",
"we",
"ll",
"resolve",
"the",
"dependencies",
"for",
"the",
"class",
... | train | https://github.com/justintadlock/hybrid-core/blob/20f15f3235505ed7d11f121f45b2ef226bc0c88f/src/Container/Container.php#L353-L370 |
justintadlock/hybrid-core | src/Container/Container.php | Container.resolveDependencies | protected function resolveDependencies( array $dependencies, array $parameters ) {
$args = [];
foreach ( $dependencies as $dependency ) {
// If a dependency is set via the parameters passed in, use it.
if ( isset( $parameters[ $dependency->getName() ] ) ) {
$args[] = $parameters[ $dependency->getName() ];
// If the parameter is a class, resolve it.
} elseif ( ! is_null( $dependency->getClass() ) ) {
$args[] = $this->resolve( $dependency->getClass()->getName() );
// Else, use the default parameter value.
} elseif ( $dependency->isDefaultValueAvailable() ) {
$args[] = $dependency->getDefaultValue();
}
}
return $args;
} | php | protected function resolveDependencies( array $dependencies, array $parameters ) {
$args = [];
foreach ( $dependencies as $dependency ) {
// If a dependency is set via the parameters passed in, use it.
if ( isset( $parameters[ $dependency->getName() ] ) ) {
$args[] = $parameters[ $dependency->getName() ];
// If the parameter is a class, resolve it.
} elseif ( ! is_null( $dependency->getClass() ) ) {
$args[] = $this->resolve( $dependency->getClass()->getName() );
// Else, use the default parameter value.
} elseif ( $dependency->isDefaultValueAvailable() ) {
$args[] = $dependency->getDefaultValue();
}
}
return $args;
} | [
"protected",
"function",
"resolveDependencies",
"(",
"array",
"$",
"dependencies",
",",
"array",
"$",
"parameters",
")",
"{",
"$",
"args",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"dependencies",
"as",
"$",
"dependency",
")",
"{",
"// If a dependency is set vi... | Resolves the dependencies for a method's parameters.
@todo Handle errors when we can't solve a dependency.
@since 5.0.0
@access protected
@param array $dependencies
@param array $parameters
@return array | [
"Resolves",
"the",
"dependencies",
"for",
"a",
"method",
"s",
"parameters",
"."
] | train | https://github.com/justintadlock/hybrid-core/blob/20f15f3235505ed7d11f121f45b2ef226bc0c88f/src/Container/Container.php#L383-L407 |
justintadlock/hybrid-core | src/Lang/LanguageServiceProvider.php | LanguageServiceProvider.register | public function register() {
$this->app->singleton( LanguageContract::class, Language::class );
$this->app->alias( LanguageContract::class, 'language' );
} | php | public function register() {
$this->app->singleton( LanguageContract::class, Language::class );
$this->app->alias( LanguageContract::class, 'language' );
} | [
"public",
"function",
"register",
"(",
")",
"{",
"$",
"this",
"->",
"app",
"->",
"singleton",
"(",
"LanguageContract",
"::",
"class",
",",
"Language",
"::",
"class",
")",
";",
"$",
"this",
"->",
"app",
"->",
"alias",
"(",
"LanguageContract",
"::",
"class... | Registration callback that adds a single instance of the language
system to the container.
@since 5.0.0
@access public
@return void | [
"Registration",
"callback",
"that",
"adds",
"a",
"single",
"instance",
"of",
"the",
"language",
"system",
"to",
"the",
"container",
"."
] | train | https://github.com/justintadlock/hybrid-core/blob/20f15f3235505ed7d11f121f45b2ef226bc0c88f/src/Lang/LanguageServiceProvider.php#L36-L41 |
justintadlock/hybrid-core | src/Template/Hierarchy.php | Hierarchy.boot | public function boot() {
// Filter the front page template.
add_filter( 'frontpage_template_hierarchy', [ $this, 'frontPage' ], 5 );
// Filter the single, page, and attachment templates.
add_filter( 'single_template_hierarchy', [ $this, 'single' ], 5 );
add_filter( 'page_template_hierarchy', [ $this, 'single' ], 5 );
add_filter( 'attachment_template_hierarchy', [ $this, 'single' ], 5 );
// Filter taxonomy templates.
add_filter( 'taxonomy_template_hierarchy', [ $this, 'taxonomy' ], 5 );
add_filter( 'category_template_hierarchy', [ $this, 'taxonomy' ], 5 );
add_filter( 'tag_template_hierarchy', [ $this, 'taxonomy' ], 5 );
// Filter the author template.
add_filter( 'author_template_hierarchy', [ $this, 'author' ], 5 );
// Filter the date template.
add_filter( 'date_template_hierarchy', [ $this, 'date' ], 5 );
// System for capturing the template hierarchy.
foreach ( $this->types as $type ) {
// Capture the template hierarchy for each type.
add_filter( "{$type}_template_hierarchy", [ $this, 'templateHierarchy' ], PHP_INT_MAX );
// Capture the located template.
add_filter( "{$type}_template", [ $this, 'template' ], PHP_INT_MAX );
}
// Re-add the located template.
add_filter( 'template_include', [ $this, 'templateInclude' ], PHP_INT_MAX );
} | php | public function boot() {
// Filter the front page template.
add_filter( 'frontpage_template_hierarchy', [ $this, 'frontPage' ], 5 );
// Filter the single, page, and attachment templates.
add_filter( 'single_template_hierarchy', [ $this, 'single' ], 5 );
add_filter( 'page_template_hierarchy', [ $this, 'single' ], 5 );
add_filter( 'attachment_template_hierarchy', [ $this, 'single' ], 5 );
// Filter taxonomy templates.
add_filter( 'taxonomy_template_hierarchy', [ $this, 'taxonomy' ], 5 );
add_filter( 'category_template_hierarchy', [ $this, 'taxonomy' ], 5 );
add_filter( 'tag_template_hierarchy', [ $this, 'taxonomy' ], 5 );
// Filter the author template.
add_filter( 'author_template_hierarchy', [ $this, 'author' ], 5 );
// Filter the date template.
add_filter( 'date_template_hierarchy', [ $this, 'date' ], 5 );
// System for capturing the template hierarchy.
foreach ( $this->types as $type ) {
// Capture the template hierarchy for each type.
add_filter( "{$type}_template_hierarchy", [ $this, 'templateHierarchy' ], PHP_INT_MAX );
// Capture the located template.
add_filter( "{$type}_template", [ $this, 'template' ], PHP_INT_MAX );
}
// Re-add the located template.
add_filter( 'template_include', [ $this, 'templateInclude' ], PHP_INT_MAX );
} | [
"public",
"function",
"boot",
"(",
")",
"{",
"// Filter the front page template.",
"add_filter",
"(",
"'frontpage_template_hierarchy'",
",",
"[",
"$",
"this",
",",
"'frontPage'",
"]",
",",
"5",
")",
";",
"// Filter the single, page, and attachment templates.",
"add_filter... | Sets up template hierarchy filters.
@since 5.0.0
@access public
@return void | [
"Sets",
"up",
"template",
"hierarchy",
"filters",
"."
] | train | https://github.com/justintadlock/hybrid-core/blob/20f15f3235505ed7d11f121f45b2ef226bc0c88f/src/Template/Hierarchy.php#L86-L119 |
justintadlock/hybrid-core | src/Template/Hierarchy.php | Hierarchy.frontPage | public function frontPage( $templates ) {
$templates = [];
if ( ! is_home() ) {
$custom = get_page_template_slug( get_queried_object_id() );
if ( $custom ) {
$templates[] = $custom;
}
$templates[] = 'front-page.php';
}
// Return the template hierarchy.
return $templates;
} | php | public function frontPage( $templates ) {
$templates = [];
if ( ! is_home() ) {
$custom = get_page_template_slug( get_queried_object_id() );
if ( $custom ) {
$templates[] = $custom;
}
$templates[] = 'front-page.php';
}
// Return the template hierarchy.
return $templates;
} | [
"public",
"function",
"frontPage",
"(",
"$",
"templates",
")",
"{",
"$",
"templates",
"=",
"[",
"]",
";",
"if",
"(",
"!",
"is_home",
"(",
")",
")",
"{",
"$",
"custom",
"=",
"get_page_template_slug",
"(",
"get_queried_object_id",
"(",
")",
")",
";",
"if... | Fix for the front page template handling in WordPress core. Its
handling is not logical because it forces devs to account for both a
page on the front page and posts on the front page. Theme devs must
handle both scenarios if they've created a "front-page.php" template.
This filter overwrites that and disables the `front-page.php` template
if posts are to be shown on the front page. This way, the
`front-page.php` template will only ever be used if an actual page is
supposed to be shown on the front.
Additionally, this filter allows the user to override the front page
via the standard page template. User choice should always trump
developer choice.
@since 5.0.0
@access public
@param array $templates
@return array | [
"Fix",
"for",
"the",
"front",
"page",
"template",
"handling",
"in",
"WordPress",
"core",
".",
"Its",
"handling",
"is",
"not",
"logical",
"because",
"it",
"forces",
"devs",
"to",
"account",
"for",
"both",
"a",
"page",
"on",
"the",
"front",
"page",
"and",
... | train | https://github.com/justintadlock/hybrid-core/blob/20f15f3235505ed7d11f121f45b2ef226bc0c88f/src/Template/Hierarchy.php#L152-L169 |
justintadlock/hybrid-core | src/Template/Hierarchy.php | Hierarchy.single | public function single( $templates ) {
$templates = [];
// Get the queried post.
$post = get_queried_object();
// Decode the post name.
$name = urldecode( $post->post_name );
// Check for a custom post template.
$custom = get_page_template_slug( $post->ID );
if ( $custom ) {
$templates[] = $custom;
}
// If viewing an attachment page, handle the files by mime type.
if ( is_attachment() ) {
// Split the mime type into two distinct parts.
$type = get_post_mime_type( $post );
$subtype = '';
if ( false !== strpos( $type, '/' ) ) {
list( $type, $subtype ) = explode( '/', $type );
}
if ( $subtype ) {
$templates[] = "attachment-{$type}-{$subtype}.php";
$templates[] = "attachment-{$subtype}.php";
}
$templates[] = "attachment-{$type}.php";
// If not viewing an attachment page.
} else {
// Add a post ID template.
$templates[] = "single-{$post->post_type}-{$post->ID}.php";
$templates[] = "{$post->post_type}-{$post->ID}.php";
// Add a post name (slug) template.
$templates[] = "single-{$post->post_type}-{$name}.php";
$templates[] = "{$post->post_type}-{$name}.php";
}
// Add a template based off the post type name.
$templates[] = "single-{$post->post_type}.php";
$templates[] = "{$post->post_type}.php";
// Allow for WP standard 'single' template.
$templates[] = 'single.php';
// Return the template hierarchy.
return $templates;
} | php | public function single( $templates ) {
$templates = [];
// Get the queried post.
$post = get_queried_object();
// Decode the post name.
$name = urldecode( $post->post_name );
// Check for a custom post template.
$custom = get_page_template_slug( $post->ID );
if ( $custom ) {
$templates[] = $custom;
}
// If viewing an attachment page, handle the files by mime type.
if ( is_attachment() ) {
// Split the mime type into two distinct parts.
$type = get_post_mime_type( $post );
$subtype = '';
if ( false !== strpos( $type, '/' ) ) {
list( $type, $subtype ) = explode( '/', $type );
}
if ( $subtype ) {
$templates[] = "attachment-{$type}-{$subtype}.php";
$templates[] = "attachment-{$subtype}.php";
}
$templates[] = "attachment-{$type}.php";
// If not viewing an attachment page.
} else {
// Add a post ID template.
$templates[] = "single-{$post->post_type}-{$post->ID}.php";
$templates[] = "{$post->post_type}-{$post->ID}.php";
// Add a post name (slug) template.
$templates[] = "single-{$post->post_type}-{$name}.php";
$templates[] = "{$post->post_type}-{$name}.php";
}
// Add a template based off the post type name.
$templates[] = "single-{$post->post_type}.php";
$templates[] = "{$post->post_type}.php";
// Allow for WP standard 'single' template.
$templates[] = 'single.php';
// Return the template hierarchy.
return $templates;
} | [
"public",
"function",
"single",
"(",
"$",
"templates",
")",
"{",
"$",
"templates",
"=",
"[",
"]",
";",
"// Get the queried post.",
"$",
"post",
"=",
"get_queried_object",
"(",
")",
";",
"// Decode the post name.",
"$",
"name",
"=",
"urldecode",
"(",
"$",
"po... | Overrides the default single (singular post) template for all post
types, including pages and attachments.
@since 5.0.0
@access public
@param array $templates
@return array | [
"Overrides",
"the",
"default",
"single",
"(",
"singular",
"post",
")",
"template",
"for",
"all",
"post",
"types",
"including",
"pages",
"and",
"attachments",
"."
] | train | https://github.com/justintadlock/hybrid-core/blob/20f15f3235505ed7d11f121f45b2ef226bc0c88f/src/Template/Hierarchy.php#L180-L236 |
justintadlock/hybrid-core | src/Template/Hierarchy.php | Hierarchy.taxonomy | public function taxonomy( $template ) {
$templates = [];
// Get the queried term object.
$term = get_queried_object();
$slug = urldecode( $term->slug );
// Remove 'post-format' from the slug.
if ( 'post_format' === $term->taxonomy ) {
$slug = str_replace( 'post-format-', '', $slug );
}
// Slug-based template.
$templates[] = "taxonomy-{$term->taxonomy}-{$slug}.php";
// Taxonomy-specific template.
$templates[] = "taxonomy-{$term->taxonomy}.php";
// Default template.
$templates[] = 'taxonomy.php';
// Return the template hierarchy.
return $templates;
} | php | public function taxonomy( $template ) {
$templates = [];
// Get the queried term object.
$term = get_queried_object();
$slug = urldecode( $term->slug );
// Remove 'post-format' from the slug.
if ( 'post_format' === $term->taxonomy ) {
$slug = str_replace( 'post-format-', '', $slug );
}
// Slug-based template.
$templates[] = "taxonomy-{$term->taxonomy}-{$slug}.php";
// Taxonomy-specific template.
$templates[] = "taxonomy-{$term->taxonomy}.php";
// Default template.
$templates[] = 'taxonomy.php';
// Return the template hierarchy.
return $templates;
} | [
"public",
"function",
"taxonomy",
"(",
"$",
"template",
")",
"{",
"$",
"templates",
"=",
"[",
"]",
";",
"// Get the queried term object.",
"$",
"term",
"=",
"get_queried_object",
"(",
")",
";",
"$",
"slug",
"=",
"urldecode",
"(",
"$",
"term",
"->",
"slug",... | Overrides WP's default template for taxonomy-based archives. This
allows better organization of taxonomy template files by making
categories and post tags work the same way as other taxonomies.
@since 5.0.0
@access public
@param array $templates
@return array | [
"Overrides",
"WP",
"s",
"default",
"template",
"for",
"taxonomy",
"-",
"based",
"archives",
".",
"This",
"allows",
"better",
"organization",
"of",
"taxonomy",
"template",
"files",
"by",
"making",
"categories",
"and",
"post",
"tags",
"work",
"the",
"same",
"way... | train | https://github.com/justintadlock/hybrid-core/blob/20f15f3235505ed7d11f121f45b2ef226bc0c88f/src/Template/Hierarchy.php#L248-L272 |
justintadlock/hybrid-core | src/Template/Hierarchy.php | Hierarchy.author | public function author( $templates ) {
$templates = [];
// Get the user nicename.
$name = get_the_author_meta( 'user_nicename', get_query_var( 'author' ) );
// Get the user object.
$user = new WP_User( absint( get_query_var( 'author' ) ) );
// Add the user nicename template.
$templates[] = "user-{$name}.php";
// Add role-based templates for the user.
if ( is_array( $user->roles ) ) {
foreach ( $user->roles as $role ) {
$templates[] = "user-role-{$role}.php";
}
}
// Add a basic user/author template.
$templates[] = 'user.php';
$templates[] = 'author.php';
// Return the template hierarchy.
return $templates;
} | php | public function author( $templates ) {
$templates = [];
// Get the user nicename.
$name = get_the_author_meta( 'user_nicename', get_query_var( 'author' ) );
// Get the user object.
$user = new WP_User( absint( get_query_var( 'author' ) ) );
// Add the user nicename template.
$templates[] = "user-{$name}.php";
// Add role-based templates for the user.
if ( is_array( $user->roles ) ) {
foreach ( $user->roles as $role ) {
$templates[] = "user-role-{$role}.php";
}
}
// Add a basic user/author template.
$templates[] = 'user.php';
$templates[] = 'author.php';
// Return the template hierarchy.
return $templates;
} | [
"public",
"function",
"author",
"(",
"$",
"templates",
")",
"{",
"$",
"templates",
"=",
"[",
"]",
";",
"// Get the user nicename.",
"$",
"name",
"=",
"get_the_author_meta",
"(",
"'user_nicename'",
",",
"get_query_var",
"(",
"'author'",
")",
")",
";",
"// Get t... | Overrides WP's default template for author-based archives. Better
abstraction of templates than `is_author()` allows by allowing themes
to specify templates for a specific author.
@since 5.0.0
@access public
@param array $templates
@return array | [
"Overrides",
"WP",
"s",
"default",
"template",
"for",
"author",
"-",
"based",
"archives",
".",
"Better",
"abstraction",
"of",
"templates",
"than",
"is_author",
"()",
"allows",
"by",
"allowing",
"themes",
"to",
"specify",
"templates",
"for",
"a",
"specific",
"a... | train | https://github.com/justintadlock/hybrid-core/blob/20f15f3235505ed7d11f121f45b2ef226bc0c88f/src/Template/Hierarchy.php#L284-L311 |
justintadlock/hybrid-core | src/Template/Hierarchy.php | Hierarchy.date | public function date( $templates ) {
$templates = [];
// If viewing a time-based archive.
if ( is_time() ) {
// If viewing a minutely archive.
if ( get_query_var( 'minute' ) ) {
$templates[] = 'minute.php';
// If viewing an hourly archive.
} elseif ( get_query_var( 'hour' ) ) {
$templates[] = 'hour.php';
}
// Catchall for any time-based archive.
$templates[] = 'time.php';
// If viewing a daily archive.
} elseif ( is_day() ) {
$templates[] = 'day.php';
// If viewing a weekly archive.
} elseif ( get_query_var( 'w' ) ) {
$templates[] = 'week.php';
// If viewing a monthly archive.
} elseif ( is_month() ) {
$templates[] = 'month.php';
// If viewing a yearly archive.
} elseif ( is_year() ) {
$templates[] = 'year.php';
}
// Catchall template for date-based archives.
$templates[] = 'date.php';
// Return the template hierarchy.
return $templates;
} | php | public function date( $templates ) {
$templates = [];
// If viewing a time-based archive.
if ( is_time() ) {
// If viewing a minutely archive.
if ( get_query_var( 'minute' ) ) {
$templates[] = 'minute.php';
// If viewing an hourly archive.
} elseif ( get_query_var( 'hour' ) ) {
$templates[] = 'hour.php';
}
// Catchall for any time-based archive.
$templates[] = 'time.php';
// If viewing a daily archive.
} elseif ( is_day() ) {
$templates[] = 'day.php';
// If viewing a weekly archive.
} elseif ( get_query_var( 'w' ) ) {
$templates[] = 'week.php';
// If viewing a monthly archive.
} elseif ( is_month() ) {
$templates[] = 'month.php';
// If viewing a yearly archive.
} elseif ( is_year() ) {
$templates[] = 'year.php';
}
// Catchall template for date-based archives.
$templates[] = 'date.php';
// Return the template hierarchy.
return $templates;
} | [
"public",
"function",
"date",
"(",
"$",
"templates",
")",
"{",
"$",
"templates",
"=",
"[",
"]",
";",
"// If viewing a time-based archive.",
"if",
"(",
"is_time",
"(",
")",
")",
"{",
"// If viewing a minutely archive.",
"if",
"(",
"get_query_var",
"(",
"'minute'"... | Overrides WP's default template for date-based archives. Better
abstraction of templates than `is_date()` allows by checking for the
year, month, week, day, hour, and minute.
@since 5.0.0
@access public
@param array $templates
@return array | [
"Overrides",
"WP",
"s",
"default",
"template",
"for",
"date",
"-",
"based",
"archives",
".",
"Better",
"abstraction",
"of",
"templates",
"than",
"is_date",
"()",
"allows",
"by",
"checking",
"for",
"the",
"year",
"month",
"week",
"day",
"hour",
"and",
"minute... | train | https://github.com/justintadlock/hybrid-core/blob/20f15f3235505ed7d11f121f45b2ef226bc0c88f/src/Template/Hierarchy.php#L323-L368 |
justintadlock/hybrid-core | src/Template/Hierarchy.php | Hierarchy.templateHierarchy | public function templateHierarchy( $templates ) {
// WooCommerce kind of does its own thing on `template_include`.
// It's top-level `woocommerce.php` template isn't added to the
// hierarchy until then. So, we're going prepend it to the
// hierarchy here to make the `woocommerce.php` template available.
if ( function_exists( 'is_woocommerce' ) && is_woocommerce() && ! in_array( 'woocommerce', $this->hierarchy ) ) {
$templates = [ 'woocommerce.php' ] + $templates;
}
// Merge the current template's hierarchy with the overall
// hierarchy array.
$this->hierarchy = array_merge(
$this->hierarchy,
array_map( function( $template ) {
// Strip extension from file name.
return substr(
$template,
0,
strlen( $template ) - strlen( strrchr( $template, '.' ) )
);
}, $templates )
);
// Make sure there are no duplicates in the hierarchy.
$this->hierarchy = array_unique( $this->hierarchy );
return filter_templates( $templates );
} | php | public function templateHierarchy( $templates ) {
// WooCommerce kind of does its own thing on `template_include`.
// It's top-level `woocommerce.php` template isn't added to the
// hierarchy until then. So, we're going prepend it to the
// hierarchy here to make the `woocommerce.php` template available.
if ( function_exists( 'is_woocommerce' ) && is_woocommerce() && ! in_array( 'woocommerce', $this->hierarchy ) ) {
$templates = [ 'woocommerce.php' ] + $templates;
}
// Merge the current template's hierarchy with the overall
// hierarchy array.
$this->hierarchy = array_merge(
$this->hierarchy,
array_map( function( $template ) {
// Strip extension from file name.
return substr(
$template,
0,
strlen( $template ) - strlen( strrchr( $template, '.' ) )
);
}, $templates )
);
// Make sure there are no duplicates in the hierarchy.
$this->hierarchy = array_unique( $this->hierarchy );
return filter_templates( $templates );
} | [
"public",
"function",
"templateHierarchy",
"(",
"$",
"templates",
")",
"{",
"// WooCommerce kind of does its own thing on `template_include`.",
"// It's top-level `woocommerce.php` template isn't added to the",
"// hierarchy until then. So, we're going prepend it to the",
"// hierarchy here to... | Filters a queried template hierarchy for each type of template and
looks templates within `resources/views`.
@since 5.0.0
@access public
@return array | [
"Filters",
"a",
"queried",
"template",
"hierarchy",
"for",
"each",
"type",
"of",
"template",
"and",
"looks",
"templates",
"within",
"resources",
"/",
"views",
"."
] | train | https://github.com/justintadlock/hybrid-core/blob/20f15f3235505ed7d11f121f45b2ef226bc0c88f/src/Template/Hierarchy.php#L378-L408 |
justintadlock/hybrid-core | src/Media/Meta.php | Meta.get | public function get( $key ) {
// `filesize` is correct, but `file_size` matches up with the
// other `file_*` meta names, so let's support both.
if ( 'filesize' === $key ) {
$key = 'file_size';
}
// Create the method name based on the given key.
$method = str_replace( '_', '', lcfirst( ucwords( $key, '_' ) ) );
// If we have a method for handling the particular meta, use it.
// Otherwise, fall back to the raw data and escape.
$value = method_exists( $this, $method ) ? $this->$method() : esc_html( $this->raw( $key ) );
return apply_filters( "hybrid/media/meta/{$key}", $value );
} | php | public function get( $key ) {
// `filesize` is correct, but `file_size` matches up with the
// other `file_*` meta names, so let's support both.
if ( 'filesize' === $key ) {
$key = 'file_size';
}
// Create the method name based on the given key.
$method = str_replace( '_', '', lcfirst( ucwords( $key, '_' ) ) );
// If we have a method for handling the particular meta, use it.
// Otherwise, fall back to the raw data and escape.
$value = method_exists( $this, $method ) ? $this->$method() : esc_html( $this->raw( $key ) );
return apply_filters( "hybrid/media/meta/{$key}", $value );
} | [
"public",
"function",
"get",
"(",
"$",
"key",
")",
"{",
"// `filesize` is correct, but `file_size` matches up with the",
"// other `file_*` meta names, so let's support both.",
"if",
"(",
"'filesize'",
"===",
"$",
"key",
")",
"{",
"$",
"key",
"=",
"'file_size'",
";",
"}... | Returns the escaped and formatted media meta.
@since 5.0.0
@access public
@param string $key
@return string | [
"Returns",
"the",
"escaped",
"and",
"formatted",
"media",
"meta",
"."
] | train | https://github.com/justintadlock/hybrid-core/blob/20f15f3235505ed7d11f121f45b2ef226bc0c88f/src/Media/Meta.php#L69-L85 |
justintadlock/hybrid-core | src/Media/Meta.php | Meta.raw | protected function raw( $key ) {
$value = '';
// If the property exists in the meta array.
if ( isset( $this->meta[ $key ] ) ) {
$value = $this->meta[ $key ];
// If the property exists in the image meta array.
} elseif ( isset( $this->meta['image_meta'] ) && isset( $this->meta['image_meta'][ $key ] ) ) {
$value = $this->meta['image_meta'][ $key ];
// If the property exists in the video's audio meta array.
} elseif ( isset( $this->meta['audio'] ) && isset( $this->meta['audio'][ $key ] ) ) {
$value = $this->meta['audio'][ $key ];
}
return $value;
} | php | protected function raw( $key ) {
$value = '';
// If the property exists in the meta array.
if ( isset( $this->meta[ $key ] ) ) {
$value = $this->meta[ $key ];
// If the property exists in the image meta array.
} elseif ( isset( $this->meta['image_meta'] ) && isset( $this->meta['image_meta'][ $key ] ) ) {
$value = $this->meta['image_meta'][ $key ];
// If the property exists in the video's audio meta array.
} elseif ( isset( $this->meta['audio'] ) && isset( $this->meta['audio'][ $key ] ) ) {
$value = $this->meta['audio'][ $key ];
}
return $value;
} | [
"protected",
"function",
"raw",
"(",
"$",
"key",
")",
"{",
"$",
"value",
"=",
"''",
";",
"// If the property exists in the meta array.",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"meta",
"[",
"$",
"key",
"]",
")",
")",
"{",
"$",
"value",
"=",
"$",
... | Returns raw data from the media meta.
@since 5.0.0
@access protected
@param string $key
@return mixed | [
"Returns",
"raw",
"data",
"from",
"the",
"media",
"meta",
"."
] | train | https://github.com/justintadlock/hybrid-core/blob/20f15f3235505ed7d11f121f45b2ef226bc0c88f/src/Media/Meta.php#L95-L116 |
justintadlock/hybrid-core | src/Media/Meta.php | Meta.aperture | protected function aperture() {
$aperture = $this->raw( 'aperture' );
if ( $aperture ) {
$aperture = sprintf(
'<sup>f</sup>⁄<sub>%s</sub>',
absint( $aperture )
);
}
return $aperture;
} | php | protected function aperture() {
$aperture = $this->raw( 'aperture' );
if ( $aperture ) {
$aperture = sprintf(
'<sup>f</sup>⁄<sub>%s</sub>',
absint( $aperture )
);
}
return $aperture;
} | [
"protected",
"function",
"aperture",
"(",
")",
"{",
"$",
"aperture",
"=",
"$",
"this",
"->",
"raw",
"(",
"'aperture'",
")",
";",
"if",
"(",
"$",
"aperture",
")",
"{",
"$",
"aperture",
"=",
"sprintf",
"(",
"'<sup>f</sup>⁄<sub>%s</sub>'",
",",
"absint"... | Returns the camera aperture for an image.
@since 5.0.0
@access protected
@return string | [
"Returns",
"the",
"camera",
"aperture",
"for",
"an",
"image",
"."
] | train | https://github.com/justintadlock/hybrid-core/blob/20f15f3235505ed7d11f121f45b2ef226bc0c88f/src/Media/Meta.php#L125-L138 |
justintadlock/hybrid-core | src/Media/Meta.php | Meta.createdTimestamp | protected function createdTimestamp() {
$timestamp = $this->raw( 'created_timestamp' );
if ( $timestamp ) {
$timestamp = date_i18n(
get_option( 'date_format' ),
strip_tags( $timestamp )
);
}
return $timestamp;
} | php | protected function createdTimestamp() {
$timestamp = $this->raw( 'created_timestamp' );
if ( $timestamp ) {
$timestamp = date_i18n(
get_option( 'date_format' ),
strip_tags( $timestamp )
);
}
return $timestamp;
} | [
"protected",
"function",
"createdTimestamp",
"(",
")",
"{",
"$",
"timestamp",
"=",
"$",
"this",
"->",
"raw",
"(",
"'created_timestamp'",
")",
";",
"if",
"(",
"$",
"timestamp",
")",
"{",
"$",
"timestamp",
"=",
"date_i18n",
"(",
"get_option",
"(",
"'date_for... | Returns the created timestamp for an image.
@since 5.0.0
@access protected
@return string | [
"Returns",
"the",
"created",
"timestamp",
"for",
"an",
"image",
"."
] | train | https://github.com/justintadlock/hybrid-core/blob/20f15f3235505ed7d11f121f45b2ef226bc0c88f/src/Media/Meta.php#L147-L160 |
justintadlock/hybrid-core | src/Media/Meta.php | Meta.dimensions | protected function dimensions() {
$dimensions = '';
$width = $this->raw( 'width' );
$height = $this->raw( 'height' );
if ( ! empty( $width ) && ! empty( $height ) ) {
$dimensions = sprintf(
// Translators: Media dimensions - 1 is width and 2 is height.
esc_html__( '%1$s × %2$s', 'hybrid-core' ),
number_format_i18n( absint( $width ) ),
number_format_i18n( absint( $height ) )
);
}
return $dimensions;
} | php | protected function dimensions() {
$dimensions = '';
$width = $this->raw( 'width' );
$height = $this->raw( 'height' );
if ( ! empty( $width ) && ! empty( $height ) ) {
$dimensions = sprintf(
// Translators: Media dimensions - 1 is width and 2 is height.
esc_html__( '%1$s × %2$s', 'hybrid-core' ),
number_format_i18n( absint( $width ) ),
number_format_i18n( absint( $height ) )
);
}
return $dimensions;
} | [
"protected",
"function",
"dimensions",
"(",
")",
"{",
"$",
"dimensions",
"=",
"''",
";",
"$",
"width",
"=",
"$",
"this",
"->",
"raw",
"(",
"'width'",
")",
";",
"$",
"height",
"=",
"$",
"this",
"->",
"raw",
"(",
"'height'",
")",
";",
"if",
"(",
"!... | Returns the media dimensions (width/height).
@since 5.0.0
@access protected
@return string | [
"Returns",
"the",
"media",
"dimensions",
"(",
"width",
"/",
"height",
")",
"."
] | train | https://github.com/justintadlock/hybrid-core/blob/20f15f3235505ed7d11f121f45b2ef226bc0c88f/src/Media/Meta.php#L169-L186 |
justintadlock/hybrid-core | src/Media/Meta.php | Meta.fileName | protected function fileName() {
$filename = basename( get_attached_file( $this->post->ID ) );
if ( $filename ) {
$filename = sprintf(
'<a href="%s">%s</a>',
esc_url( wp_get_attachment_url( $this->post->ID ) ),
$filename
);
}
return $filename;
} | php | protected function fileName() {
$filename = basename( get_attached_file( $this->post->ID ) );
if ( $filename ) {
$filename = sprintf(
'<a href="%s">%s</a>',
esc_url( wp_get_attachment_url( $this->post->ID ) ),
$filename
);
}
return $filename;
} | [
"protected",
"function",
"fileName",
"(",
")",
"{",
"$",
"filename",
"=",
"basename",
"(",
"get_attached_file",
"(",
"$",
"this",
"->",
"post",
"->",
"ID",
")",
")",
";",
"if",
"(",
"$",
"filename",
")",
"{",
"$",
"filename",
"=",
"sprintf",
"(",
"'<... | Returns the media file name, linked to the original media file.
@since 5.0.0
@access protected
@return string | [
"Returns",
"the",
"media",
"file",
"name",
"linked",
"to",
"the",
"original",
"media",
"file",
"."
] | train | https://github.com/justintadlock/hybrid-core/blob/20f15f3235505ed7d11f121f45b2ef226bc0c88f/src/Media/Meta.php#L195-L209 |
justintadlock/hybrid-core | src/Media/Meta.php | Meta.fileSize | protected function fileSize() {
$filesize = isset( $this->meta['filesize'] ) ? $this->meta['filesize'] : '';
if ( ! $filesize ) {
$file = get_attached_file( $this->post->ID );
if ( file_exists( $file ) ) {
$filesize = filesize( $file );
}
}
if ( $filesize ) {
$filesize = size_format( strip_tags( $filesize ), 2 );
}
return $filesize;
} | php | protected function fileSize() {
$filesize = isset( $this->meta['filesize'] ) ? $this->meta['filesize'] : '';
if ( ! $filesize ) {
$file = get_attached_file( $this->post->ID );
if ( file_exists( $file ) ) {
$filesize = filesize( $file );
}
}
if ( $filesize ) {
$filesize = size_format( strip_tags( $filesize ), 2 );
}
return $filesize;
} | [
"protected",
"function",
"fileSize",
"(",
")",
"{",
"$",
"filesize",
"=",
"isset",
"(",
"$",
"this",
"->",
"meta",
"[",
"'filesize'",
"]",
")",
"?",
"$",
"this",
"->",
"meta",
"[",
"'filesize'",
"]",
":",
"''",
";",
"if",
"(",
"!",
"$",
"filesize",... | Returns the media file size.
@since 5.0.0
@access protected
@return string | [
"Returns",
"the",
"media",
"file",
"size",
"."
] | train | https://github.com/justintadlock/hybrid-core/blob/20f15f3235505ed7d11f121f45b2ef226bc0c88f/src/Media/Meta.php#L218-L236 |
justintadlock/hybrid-core | src/Media/Meta.php | Meta.fileType | protected function fileType() {
$type = '';
if ( preg_match( '/^.*?\.(\w+)$/', get_attached_file( $this->post->ID ), $matches ) ) {
$type = $matches[1];
}
return $type ? esc_html( strtoupper( $type ) ) : '';
} | php | protected function fileType() {
$type = '';
if ( preg_match( '/^.*?\.(\w+)$/', get_attached_file( $this->post->ID ), $matches ) ) {
$type = $matches[1];
}
return $type ? esc_html( strtoupper( $type ) ) : '';
} | [
"protected",
"function",
"fileType",
"(",
")",
"{",
"$",
"type",
"=",
"''",
";",
"if",
"(",
"preg_match",
"(",
"'/^.*?\\.(\\w+)$/'",
",",
"get_attached_file",
"(",
"$",
"this",
"->",
"post",
"->",
"ID",
")",
",",
"$",
"matches",
")",
")",
"{",
"$",
"... | Returns the media file type.
@since 5.0.0
@access protected
@return string | [
"Returns",
"the",
"media",
"file",
"type",
"."
] | train | https://github.com/justintadlock/hybrid-core/blob/20f15f3235505ed7d11f121f45b2ef226bc0c88f/src/Media/Meta.php#L245-L255 |
justintadlock/hybrid-core | src/Media/Meta.php | Meta.focalLength | protected function focalLength() {
$focal_length = $this->raw( 'focal_length' );
if ( $focal_length ) {
// Translators: %s is the focal length of a camera.
$focal_length = sprintf(
__( '%s mm', 'hybrid-core' ),
absint( $focal_length )
);
}
return $focal_length;
} | php | protected function focalLength() {
$focal_length = $this->raw( 'focal_length' );
if ( $focal_length ) {
// Translators: %s is the focal length of a camera.
$focal_length = sprintf(
__( '%s mm', 'hybrid-core' ),
absint( $focal_length )
);
}
return $focal_length;
} | [
"protected",
"function",
"focalLength",
"(",
")",
"{",
"$",
"focal_length",
"=",
"$",
"this",
"->",
"raw",
"(",
"'focal_length'",
")",
";",
"if",
"(",
"$",
"focal_length",
")",
"{",
"// Translators: %s is the focal length of a camera.",
"$",
"focal_length",
"=",
... | Returns the camera focal length for an image.
@since 5.0.0
@access protected
@return string | [
"Returns",
"the",
"camera",
"focal",
"length",
"for",
"an",
"image",
"."
] | train | https://github.com/justintadlock/hybrid-core/blob/20f15f3235505ed7d11f121f45b2ef226bc0c88f/src/Media/Meta.php#L264-L278 |
justintadlock/hybrid-core | src/Media/Meta.php | Meta.lyrics | protected function lyrics() {
$lyrics = '';
// Look for the 'unsynchronised_lyric' tag.
if ( isset( $this->meta['unsynchronised_lyric'] ) ) {
$lyrics = $this->meta['unsynchronised_lyric'];
// Seen this misspelling of the id3 tag.
} elseif ( isset( $this->meta['unsychronised_lyric'] ) ) {
$lyrics = $this->meta['unsychronised_lyric'];
}
if ( $lyrics ) {
$lyrics = strip_tags( $lyrics );
$lyrics = wptexturize( $lyrics );
$lyrics = convert_chars( $lyrics );
$lyrics = wpautop( $lyrics );
}
return $lyrics;
} | php | protected function lyrics() {
$lyrics = '';
// Look for the 'unsynchronised_lyric' tag.
if ( isset( $this->meta['unsynchronised_lyric'] ) ) {
$lyrics = $this->meta['unsynchronised_lyric'];
// Seen this misspelling of the id3 tag.
} elseif ( isset( $this->meta['unsychronised_lyric'] ) ) {
$lyrics = $this->meta['unsychronised_lyric'];
}
if ( $lyrics ) {
$lyrics = strip_tags( $lyrics );
$lyrics = wptexturize( $lyrics );
$lyrics = convert_chars( $lyrics );
$lyrics = wpautop( $lyrics );
}
return $lyrics;
} | [
"protected",
"function",
"lyrics",
"(",
")",
"{",
"$",
"lyrics",
"=",
"''",
";",
"// Look for the 'unsynchronised_lyric' tag.",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"meta",
"[",
"'unsynchronised_lyric'",
"]",
")",
")",
"{",
"$",
"lyrics",
"=",
"$",
... | Returns the lyrics for an audio file.
@since 5.0.0
@access protected
@return string | [
"Returns",
"the",
"lyrics",
"for",
"an",
"audio",
"file",
"."
] | train | https://github.com/justintadlock/hybrid-core/blob/20f15f3235505ed7d11f121f45b2ef226bc0c88f/src/Media/Meta.php#L287-L308 |
justintadlock/hybrid-core | src/Media/Meta.php | Meta.mimeType | protected function mimeType() {
$mime_type = get_post_mime_type( $this->post );
if ( ! $mime_type ) {
$mime_type = $this->raw( 'mime_type' );
}
return $mime_type ? esc_html( $mime_type ) : '';
} | php | protected function mimeType() {
$mime_type = get_post_mime_type( $this->post );
if ( ! $mime_type ) {
$mime_type = $this->raw( 'mime_type' );
}
return $mime_type ? esc_html( $mime_type ) : '';
} | [
"protected",
"function",
"mimeType",
"(",
")",
"{",
"$",
"mime_type",
"=",
"get_post_mime_type",
"(",
"$",
"this",
"->",
"post",
")",
";",
"if",
"(",
"!",
"$",
"mime_type",
")",
"{",
"$",
"mime_type",
"=",
"$",
"this",
"->",
"raw",
"(",
"'mime_type'",
... | Returns the media file mime type.
@since 5.0.0
@access protected
@return string | [
"Returns",
"the",
"media",
"file",
"mime",
"type",
"."
] | train | https://github.com/justintadlock/hybrid-core/blob/20f15f3235505ed7d11f121f45b2ef226bc0c88f/src/Media/Meta.php#L317-L326 |
justintadlock/hybrid-core | src/Media/Meta.php | Meta.shutterSpeed | protected function shutterSpeed() {
$shutter = $this->raw( 'shutter_speed' );
// If a shutter speed is given, format the float into a fraction.
if ( $shutter ) {
$shutter = $speed = floatval( strip_tags( $shutter ) );
if ( ( 1 / $speed ) > 1 ) {
$shutter = sprintf( '<sup>%s</sup>⁄', number_format_i18n( 1 ) );
if ( number_format( ( 1 / $speed ), 1 ) == number_format( ( 1 / $speed ), 0 ) ) {
$shutter .= sprintf(
'<sub>%s</sub>',
number_format_i18n( ( 1 / $speed ), 0, '.', '' )
);
} else {
$shutter .= sprintf(
'<sub>%s</sub>',
number_format_i18n( ( 1 / $speed ), 1, '.', '' )
);
}
}
// Translators: %s is the shutter speed of a camera.
$shutter = sprintf( __( '%s sec', 'hybrid-core' ), $shutter );
}
return $shutter;
} | php | protected function shutterSpeed() {
$shutter = $this->raw( 'shutter_speed' );
// If a shutter speed is given, format the float into a fraction.
if ( $shutter ) {
$shutter = $speed = floatval( strip_tags( $shutter ) );
if ( ( 1 / $speed ) > 1 ) {
$shutter = sprintf( '<sup>%s</sup>⁄', number_format_i18n( 1 ) );
if ( number_format( ( 1 / $speed ), 1 ) == number_format( ( 1 / $speed ), 0 ) ) {
$shutter .= sprintf(
'<sub>%s</sub>',
number_format_i18n( ( 1 / $speed ), 0, '.', '' )
);
} else {
$shutter .= sprintf(
'<sub>%s</sub>',
number_format_i18n( ( 1 / $speed ), 1, '.', '' )
);
}
}
// Translators: %s is the shutter speed of a camera.
$shutter = sprintf( __( '%s sec', 'hybrid-core' ), $shutter );
}
return $shutter;
} | [
"protected",
"function",
"shutterSpeed",
"(",
")",
"{",
"$",
"shutter",
"=",
"$",
"this",
"->",
"raw",
"(",
"'shutter_speed'",
")",
";",
"// If a shutter speed is given, format the float into a fraction.",
"if",
"(",
"$",
"shutter",
")",
"{",
"$",
"shutter",
"=",
... | Returns the camera shutter speed for an image.
@since 5.0.0
@access protected
@return string | [
"Returns",
"the",
"camera",
"shutter",
"speed",
"for",
"an",
"image",
"."
] | train | https://github.com/justintadlock/hybrid-core/blob/20f15f3235505ed7d11f121f45b2ef226bc0c88f/src/Media/Meta.php#L335-L368 |
justintadlock/hybrid-core | src/Template/Manager.php | Manager.postTemplates | public function postTemplates( $templates, $theme, $post, $post_type ) {
foreach ( $this->templates->all() as $template ) {
if ( $template->forPostType( $post_type ) ) {
$templates[ $template->filename() ] = esc_html( $template->label() );
}
}
return $templates;
} | php | public function postTemplates( $templates, $theme, $post, $post_type ) {
foreach ( $this->templates->all() as $template ) {
if ( $template->forPostType( $post_type ) ) {
$templates[ $template->filename() ] = esc_html( $template->label() );
}
}
return $templates;
} | [
"public",
"function",
"postTemplates",
"(",
"$",
"templates",
",",
"$",
"theme",
",",
"$",
"post",
",",
"$",
"post_type",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"templates",
"->",
"all",
"(",
")",
"as",
"$",
"template",
")",
"{",
"if",
"(",
"... | Filter used on `theme_templates` to add custom templates to the template
drop-down.
Note that this method is `public` because of WP's hook callback
system. See the implemented contract for publicly-available methods.
@since 5.0.0
@access public
@param array $templates
@param object $theme
@param object $post
@param string $post_type
@return array | [
"Filter",
"used",
"on",
"theme_templates",
"to",
"add",
"custom",
"templates",
"to",
"the",
"template",
"drop",
"-",
"down",
"."
] | train | https://github.com/justintadlock/hybrid-core/blob/20f15f3235505ed7d11f121f45b2ef226bc0c88f/src/Template/Manager.php#L96-L107 |
phptal/PHPTAL | classes/PHPTAL/Php/Attribute/TAL/Attributes.php | PHPTAL_Php_Attribute_TAL_Attributes.prepareAttributeUnconditional | private function prepareAttributeUnconditional(PHPTAL_Php_CodeWriter $codewriter, $qname, $code)
{
// regular attribute which value is the evaluation of $code
$attkey = $this->getVarName($qname, $codewriter);
if ($this->_echoType == PHPTAL_Php_Attribute::ECHO_STRUCTURE) {
$value = $codewriter->stringifyCode($code);
} else {
$value = $codewriter->escapeCode($code);
}
$codewriter->doSetVar($attkey, $value);
$this->phpelement->getOrCreateAttributeNode($qname)->overwriteValueWithVariable($attkey);
} | php | private function prepareAttributeUnconditional(PHPTAL_Php_CodeWriter $codewriter, $qname, $code)
{
// regular attribute which value is the evaluation of $code
$attkey = $this->getVarName($qname, $codewriter);
if ($this->_echoType == PHPTAL_Php_Attribute::ECHO_STRUCTURE) {
$value = $codewriter->stringifyCode($code);
} else {
$value = $codewriter->escapeCode($code);
}
$codewriter->doSetVar($attkey, $value);
$this->phpelement->getOrCreateAttributeNode($qname)->overwriteValueWithVariable($attkey);
} | [
"private",
"function",
"prepareAttributeUnconditional",
"(",
"PHPTAL_Php_CodeWriter",
"$",
"codewriter",
",",
"$",
"qname",
",",
"$",
"code",
")",
"{",
"// regular attribute which value is the evaluation of $code",
"$",
"attkey",
"=",
"$",
"this",
"->",
"getVarName",
"(... | attribute will be output regardless of its evaluated value. NULL behaves just like "". | [
"attribute",
"will",
"be",
"output",
"regardless",
"of",
"its",
"evaluated",
"value",
".",
"NULL",
"behaves",
"just",
"like",
"."
] | train | https://github.com/phptal/PHPTAL/blob/40e0cdbebfa1c5bfca7b722037ea41fee7362946/classes/PHPTAL/Php/Attribute/TAL/Attributes.php#L95-L106 |
phptal/PHPTAL | classes/PHPTAL/Php/Attribute/TAL/Attributes.php | PHPTAL_Php_Attribute_TAL_Attributes.prepareAttributeConditional | private function prepareAttributeConditional(PHPTAL_Php_CodeWriter $codewriter, $qname, $code)
{
// regular attribute which value is the evaluation of $code
$attkey = $this->getVarName($qname, $codewriter);
$codewriter->doIf("null !== ($attkey = ($code))");
if ($this->_echoType !== PHPTAL_Php_Attribute::ECHO_STRUCTURE)
$codewriter->doSetVar($attkey, $codewriter->str(" $qname=\"").".".$codewriter->escapeCode($attkey).".'\"'");
else
$codewriter->doSetVar($attkey, $codewriter->str(" $qname=\"").".".$codewriter->stringifyCode($attkey).".'\"'");
$codewriter->doElse();
$codewriter->doSetVar($attkey, "''");
$codewriter->doEnd('if');
$this->phpelement->getOrCreateAttributeNode($qname)->overwriteFullWithVariable($attkey);
} | php | private function prepareAttributeConditional(PHPTAL_Php_CodeWriter $codewriter, $qname, $code)
{
// regular attribute which value is the evaluation of $code
$attkey = $this->getVarName($qname, $codewriter);
$codewriter->doIf("null !== ($attkey = ($code))");
if ($this->_echoType !== PHPTAL_Php_Attribute::ECHO_STRUCTURE)
$codewriter->doSetVar($attkey, $codewriter->str(" $qname=\"").".".$codewriter->escapeCode($attkey).".'\"'");
else
$codewriter->doSetVar($attkey, $codewriter->str(" $qname=\"").".".$codewriter->stringifyCode($attkey).".'\"'");
$codewriter->doElse();
$codewriter->doSetVar($attkey, "''");
$codewriter->doEnd('if');
$this->phpelement->getOrCreateAttributeNode($qname)->overwriteFullWithVariable($attkey);
} | [
"private",
"function",
"prepareAttributeConditional",
"(",
"PHPTAL_Php_CodeWriter",
"$",
"codewriter",
",",
"$",
"qname",
",",
"$",
"code",
")",
"{",
"// regular attribute which value is the evaluation of $code",
"$",
"attkey",
"=",
"$",
"this",
"->",
"getVarName",
"(",... | If evaluated value of attribute is NULL, it will not be output at all. | [
"If",
"evaluated",
"value",
"of",
"attribute",
"is",
"NULL",
"it",
"will",
"not",
"be",
"output",
"at",
"all",
"."
] | train | https://github.com/phptal/PHPTAL/blob/40e0cdbebfa1c5bfca7b722037ea41fee7362946/classes/PHPTAL/Php/Attribute/TAL/Attributes.php#L111-L128 |
phptal/PHPTAL | classes/PHPTAL/Dom/XmlnsState.php | PHPTAL_Dom_XmlnsState.newElement | public function newElement(array $nodeAttributes)
{
$prefix_to_uri = $this->prefix_to_uri;
$current_default = $this->current_default;
$changed = false;
foreach ($nodeAttributes as $qname => $value) {
if (preg_match('/^xmlns:(.+)$/', $qname, $m)) {
$changed = true;
list(, $prefix) = $m;
$prefix_to_uri[$prefix] = $value;
}
if ($qname == 'xmlns') {$changed=true;$current_default = $value;}
}
if ($changed) {
return new PHPTAL_Dom_XmlnsState($prefix_to_uri, $current_default);
} else {
return $this;
}
} | php | public function newElement(array $nodeAttributes)
{
$prefix_to_uri = $this->prefix_to_uri;
$current_default = $this->current_default;
$changed = false;
foreach ($nodeAttributes as $qname => $value) {
if (preg_match('/^xmlns:(.+)$/', $qname, $m)) {
$changed = true;
list(, $prefix) = $m;
$prefix_to_uri[$prefix] = $value;
}
if ($qname == 'xmlns') {$changed=true;$current_default = $value;}
}
if ($changed) {
return new PHPTAL_Dom_XmlnsState($prefix_to_uri, $current_default);
} else {
return $this;
}
} | [
"public",
"function",
"newElement",
"(",
"array",
"$",
"nodeAttributes",
")",
"{",
"$",
"prefix_to_uri",
"=",
"$",
"this",
"->",
"prefix_to_uri",
";",
"$",
"current_default",
"=",
"$",
"this",
"->",
"current_default",
";",
"$",
"changed",
"=",
"false",
";",
... | Returns a new XmlnsState inheriting of $this if $nodeAttributes contains
xmlns attributes, returns $this otherwise.
This method is used by the PHPTAL parser to keep track of xmlns fluctuation for
each encountered node. | [
"Returns",
"a",
"new",
"XmlnsState",
"inheriting",
"of",
"$this",
"if",
"$nodeAttributes",
"contains",
"xmlns",
"attributes",
"returns",
"$this",
"otherwise",
"."
] | train | https://github.com/phptal/PHPTAL/blob/40e0cdbebfa1c5bfca7b722037ea41fee7362946/classes/PHPTAL/Dom/XmlnsState.php#L66-L87 |
phptal/PHPTAL | classes/PHPTAL/Dom/Element.php | PHPTAL_Dom_Element.replaceTextWithCDATA | private function replaceTextWithCDATA()
{
$isCDATAelement = PHPTAL_Dom_Defs::getInstance()->isCDATAElementInHTML($this->getNamespaceURI(), $this->getLocalName());
if (!$isCDATAelement) {
return;
}
$valueEscaped = ''; // sometimes parser generates split text nodes. "normalisation" is needed.
$value = '';
foreach ($this->childNodes as $node) {
// leave it alone if there is CDATA, comment, or anything else.
if (!$node instanceof PHPTAL_Dom_Text) return;
$value .= $node->getValue();
$valueEscaped .= $node->getValueEscaped();
$encoding = $node->getEncoding(); // encoding of all nodes is the same
}
// only add cdata if there are entities
// and there's no ${structure} (because it may rely on cdata syntax)
if (false === strpos($valueEscaped, '&') || preg_match('/<\?|\${structure/', $value)) {
return;
}
$this->childNodes = array();
// appendChild sets parent
$this->appendChild(new PHPTAL_Dom_Text('/*', $encoding));
$this->appendChild(new PHPTAL_Dom_CDATASection('*/'.$value.'/*', $encoding));
$this->appendChild(new PHPTAL_Dom_Text('*/', $encoding));
} | php | private function replaceTextWithCDATA()
{
$isCDATAelement = PHPTAL_Dom_Defs::getInstance()->isCDATAElementInHTML($this->getNamespaceURI(), $this->getLocalName());
if (!$isCDATAelement) {
return;
}
$valueEscaped = ''; // sometimes parser generates split text nodes. "normalisation" is needed.
$value = '';
foreach ($this->childNodes as $node) {
// leave it alone if there is CDATA, comment, or anything else.
if (!$node instanceof PHPTAL_Dom_Text) return;
$value .= $node->getValue();
$valueEscaped .= $node->getValueEscaped();
$encoding = $node->getEncoding(); // encoding of all nodes is the same
}
// only add cdata if there are entities
// and there's no ${structure} (because it may rely on cdata syntax)
if (false === strpos($valueEscaped, '&') || preg_match('/<\?|\${structure/', $value)) {
return;
}
$this->childNodes = array();
// appendChild sets parent
$this->appendChild(new PHPTAL_Dom_Text('/*', $encoding));
$this->appendChild(new PHPTAL_Dom_CDATASection('*/'.$value.'/*', $encoding));
$this->appendChild(new PHPTAL_Dom_Text('*/', $encoding));
} | [
"private",
"function",
"replaceTextWithCDATA",
"(",
")",
"{",
"$",
"isCDATAelement",
"=",
"PHPTAL_Dom_Defs",
"::",
"getInstance",
"(",
")",
"->",
"isCDATAElementInHTML",
"(",
"$",
"this",
"->",
"getNamespaceURI",
"(",
")",
",",
"$",
"this",
"->",
"getLocalName",... | Replace <script> foo > bar </script>
with <script>/*<![CDATA[* / foo > bar /*]]>* /</script>
This avoids gotcha in text/html.
Note that PHPTAL_Dom_CDATASection::generate() does reverse operation, if needed!
@return void | [
"Replace",
"<script",
">",
"foo",
">",
";",
"bar",
"<",
"/",
"script",
">",
"with",
"<script",
">",
"/",
"*",
"<!",
"[",
"CDATA",
"[",
"*",
"/",
"foo",
">",
"bar",
"/",
"*",
"]]",
">",
"*",
"/",
"<",
"/",
"script",
">",
"This",
"avoids",
"g... | train | https://github.com/phptal/PHPTAL/blob/40e0cdbebfa1c5bfca7b722037ea41fee7362946/classes/PHPTAL/Dom/Element.php#L85-L117 |
phptal/PHPTAL | classes/PHPTAL/Dom/Element.php | PHPTAL_Dom_Element.hasAttribute | public function hasAttribute($qname)
{
foreach($this->attribute_nodes as $attr) if ($attr->getQualifiedName() == $qname) return true;
return false;
} | php | public function hasAttribute($qname)
{
foreach($this->attribute_nodes as $attr) if ($attr->getQualifiedName() == $qname) return true;
return false;
} | [
"public",
"function",
"hasAttribute",
"(",
"$",
"qname",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"attribute_nodes",
"as",
"$",
"attr",
")",
"if",
"(",
"$",
"attr",
"->",
"getQualifiedName",
"(",
")",
"==",
"$",
"qname",
")",
"return",
"true",
";",... | Returns true if the element contains specified PHPTAL attribute. | [
"Returns",
"true",
"if",
"the",
"element",
"contains",
"specified",
"PHPTAL",
"attribute",
"."
] | train | https://github.com/phptal/PHPTAL/blob/40e0cdbebfa1c5bfca7b722037ea41fee7362946/classes/PHPTAL/Dom/Element.php#L213-L217 |
phptal/PHPTAL | classes/PHPTAL/Dom/Element.php | PHPTAL_Dom_Element.getOrCreateAttributeNode | public function getOrCreateAttributeNode($qname)
{
if ($attr = $this->getAttributeNode($qname)) return $attr;
$attr = new PHPTAL_Dom_Attr($qname, "", null, 'UTF-8'); // FIXME: should find namespace and encoding
$this->attribute_nodes[] = $attr;
return $attr;
} | php | public function getOrCreateAttributeNode($qname)
{
if ($attr = $this->getAttributeNode($qname)) return $attr;
$attr = new PHPTAL_Dom_Attr($qname, "", null, 'UTF-8'); // FIXME: should find namespace and encoding
$this->attribute_nodes[] = $attr;
return $attr;
} | [
"public",
"function",
"getOrCreateAttributeNode",
"(",
"$",
"qname",
")",
"{",
"if",
"(",
"$",
"attr",
"=",
"$",
"this",
"->",
"getAttributeNode",
"(",
"$",
"qname",
")",
")",
"return",
"$",
"attr",
";",
"$",
"attr",
"=",
"new",
"PHPTAL_Dom_Attr",
"(",
... | If possible, use getAttributeNodeNS and setAttributeNS.
NB: This method doesn't handle namespaces properly. | [
"If",
"possible",
"use",
"getAttributeNodeNS",
"and",
"setAttributeNS",
"."
] | train | https://github.com/phptal/PHPTAL/blob/40e0cdbebfa1c5bfca7b722037ea41fee7362946/classes/PHPTAL/Dom/Element.php#L253-L260 |
phptal/PHPTAL | classes/PHPTAL/Dom/Element.php | PHPTAL_Dom_Element.getAttributeNS | public function getAttributeNS($namespace_uri, $localname)
{
if ($n = $this->getAttributeNodeNS($namespace_uri, $localname)) {
return $n->getValue();
}
return '';
} | php | public function getAttributeNS($namespace_uri, $localname)
{
if ($n = $this->getAttributeNodeNS($namespace_uri, $localname)) {
return $n->getValue();
}
return '';
} | [
"public",
"function",
"getAttributeNS",
"(",
"$",
"namespace_uri",
",",
"$",
"localname",
")",
"{",
"if",
"(",
"$",
"n",
"=",
"$",
"this",
"->",
"getAttributeNodeNS",
"(",
"$",
"namespace_uri",
",",
"$",
"localname",
")",
")",
"{",
"return",
"$",
"n",
... | Returns textual (unescaped) value of specified element attribute. | [
"Returns",
"textual",
"(",
"unescaped",
")",
"value",
"of",
"specified",
"element",
"attribute",
"."
] | train | https://github.com/phptal/PHPTAL/blob/40e0cdbebfa1c5bfca7b722037ea41fee7362946/classes/PHPTAL/Dom/Element.php#L263-L269 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.