repo
stringlengths 6
63
| path
stringlengths 5
140
| func_name
stringlengths 3
151
| original_string
stringlengths 84
13k
| language
stringclasses 1
value | code
stringlengths 84
13k
| code_tokens
list | docstring
stringlengths 3
47.2k
| docstring_tokens
list | sha
stringlengths 40
40
| url
stringlengths 91
247
| partition
stringclasses 1
value |
---|---|---|---|---|---|---|---|---|---|---|---|
helsingborg-stad/Modularity | source/php/Editor.php | Editor.sanitizeModuleData | public function sanitizeModuleData($sidebars)
{
foreach ($sidebars as &$sidebar) {
if (!empty($sidebar) && is_array($sidebar)) {
foreach ($sidebar as &$module) {
$module['hidden'] = isset($module['hidden']) && $module['hidden'] == 'hidden';
}
}
}
return $sidebars;
} | php | public function sanitizeModuleData($sidebars)
{
foreach ($sidebars as &$sidebar) {
if (!empty($sidebar) && is_array($sidebar)) {
foreach ($sidebar as &$module) {
$module['hidden'] = isset($module['hidden']) && $module['hidden'] == 'hidden';
}
}
}
return $sidebars;
} | [
"public",
"function",
"sanitizeModuleData",
"(",
"$",
"sidebars",
")",
"{",
"foreach",
"(",
"$",
"sidebars",
"as",
"&",
"$",
"sidebar",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"sidebar",
")",
"&&",
"is_array",
"(",
"$",
"sidebar",
")",
")",
"{",
"foreach",
"(",
"$",
"sidebar",
"as",
"&",
"$",
"module",
")",
"{",
"$",
"module",
"[",
"'hidden'",
"]",
"=",
"isset",
"(",
"$",
"module",
"[",
"'hidden'",
"]",
")",
"&&",
"$",
"module",
"[",
"'hidden'",
"]",
"==",
"'hidden'",
";",
"}",
"}",
"}",
"return",
"$",
"sidebars",
";",
"}"
]
| Sanitize module data
@param $sidebars
@return array | [
"Sanitize",
"module",
"data"
]
| db4fcde30ba5db4fac9c8b3c3475c8229b50271d | https://github.com/helsingborg-stad/Modularity/blob/db4fcde30ba5db4fac9c8b3c3475c8229b50271d/source/php/Editor.php#L739-L750 | train |
helsingborg-stad/Modularity | plugins/acf-post-type-field/acf-posttype-select-v4.php | acf_field_posttype_select.post_type_options | private function post_type_options()
{
$args = array( 'public' => true );
$post_types = get_post_types($args, 'objects');
$output = array();
foreach ($post_types as $post_type) {
$output[] = array(
'value' => $post_type->name,
'label' => $post_type->label
);
}
return $output;
} | php | private function post_type_options()
{
$args = array( 'public' => true );
$post_types = get_post_types($args, 'objects');
$output = array();
foreach ($post_types as $post_type) {
$output[] = array(
'value' => $post_type->name,
'label' => $post_type->label
);
}
return $output;
} | [
"private",
"function",
"post_type_options",
"(",
")",
"{",
"$",
"args",
"=",
"array",
"(",
"'public'",
"=>",
"true",
")",
";",
"$",
"post_types",
"=",
"get_post_types",
"(",
"$",
"args",
",",
"'objects'",
")",
";",
"$",
"output",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"post_types",
"as",
"$",
"post_type",
")",
"{",
"$",
"output",
"[",
"]",
"=",
"array",
"(",
"'value'",
"=>",
"$",
"post_type",
"->",
"name",
",",
"'label'",
"=>",
"$",
"post_type",
"->",
"label",
")",
";",
"}",
"return",
"$",
"output",
";",
"}"
]
| Outputs Post Types in HTML option tags
@return array Array of post type names and labels | [
"Outputs",
"Post",
"Types",
"in",
"HTML",
"option",
"tags"
]
| db4fcde30ba5db4fac9c8b3c3475c8229b50271d | https://github.com/helsingborg-stad/Modularity/blob/db4fcde30ba5db4fac9c8b3c3475c8229b50271d/plugins/acf-post-type-field/acf-posttype-select-v4.php#L180-L192 | train |
helsingborg-stad/Modularity | source/php/Widget.php | Widget.widget | public function widget($args, $instance)
{
if (!isset($instance['module_id']) || !is_numeric($instance['module_id'])) {
return false;
}
$display = \Modularity\App::$display;
$columnWidth = (isset($instance['module_size'])) ? $instance['module_size'] : 'grid-md-4';
if (isset($instance['module_type']) && $instance['module_type'] == 'mod-slider') {
$columnWidth = '';
}
$columnWidth = apply_filters('Modularity/Widget/ColumnWidth', $columnWidth, $instance);
$module = \Modularity\Editor::getModule(
$instance['module_id'],
array(
'hidden' => false,
'columnWidth' => $columnWidth
)
);
$display->outputModule($module, $args);
} | php | public function widget($args, $instance)
{
if (!isset($instance['module_id']) || !is_numeric($instance['module_id'])) {
return false;
}
$display = \Modularity\App::$display;
$columnWidth = (isset($instance['module_size'])) ? $instance['module_size'] : 'grid-md-4';
if (isset($instance['module_type']) && $instance['module_type'] == 'mod-slider') {
$columnWidth = '';
}
$columnWidth = apply_filters('Modularity/Widget/ColumnWidth', $columnWidth, $instance);
$module = \Modularity\Editor::getModule(
$instance['module_id'],
array(
'hidden' => false,
'columnWidth' => $columnWidth
)
);
$display->outputModule($module, $args);
} | [
"public",
"function",
"widget",
"(",
"$",
"args",
",",
"$",
"instance",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"instance",
"[",
"'module_id'",
"]",
")",
"||",
"!",
"is_numeric",
"(",
"$",
"instance",
"[",
"'module_id'",
"]",
")",
")",
"{",
"return",
"false",
";",
"}",
"$",
"display",
"=",
"\\",
"Modularity",
"\\",
"App",
"::",
"$",
"display",
";",
"$",
"columnWidth",
"=",
"(",
"isset",
"(",
"$",
"instance",
"[",
"'module_size'",
"]",
")",
")",
"?",
"$",
"instance",
"[",
"'module_size'",
"]",
":",
"'grid-md-4'",
";",
"if",
"(",
"isset",
"(",
"$",
"instance",
"[",
"'module_type'",
"]",
")",
"&&",
"$",
"instance",
"[",
"'module_type'",
"]",
"==",
"'mod-slider'",
")",
"{",
"$",
"columnWidth",
"=",
"''",
";",
"}",
"$",
"columnWidth",
"=",
"apply_filters",
"(",
"'Modularity/Widget/ColumnWidth'",
",",
"$",
"columnWidth",
",",
"$",
"instance",
")",
";",
"$",
"module",
"=",
"\\",
"Modularity",
"\\",
"Editor",
"::",
"getModule",
"(",
"$",
"instance",
"[",
"'module_id'",
"]",
",",
"array",
"(",
"'hidden'",
"=>",
"false",
",",
"'columnWidth'",
"=>",
"$",
"columnWidth",
")",
")",
";",
"$",
"display",
"->",
"outputModule",
"(",
"$",
"module",
",",
"$",
"args",
")",
";",
"}"
]
| Outputs the widget content
@param array $args Widget arguments
@param array $instance Widget instance
@return void | [
"Outputs",
"the",
"widget",
"content"
]
| db4fcde30ba5db4fac9c8b3c3475c8229b50271d | https://github.com/helsingborg-stad/Modularity/blob/db4fcde30ba5db4fac9c8b3c3475c8229b50271d/source/php/Widget.php#L26-L51 | train |
helsingborg-stad/Modularity | source/php/Options/Archives.php | Archives.getArchiveTemplateSlugs | public static function getArchiveTemplateSlugs()
{
$archives = get_post_types(array(
'has_archive' => true
), 'names');
$templates = array();
foreach ($archives as $archive) {
$template = \Modularity\Helper\Wp::findCoreTemplates(array(
'archive-' . $archive
));
if ($template) {
$templates[] = $template;
} else {
$templates[] = 'archive';
}
}
array_unique($templates);
return $templates;
} | php | public static function getArchiveTemplateSlugs()
{
$archives = get_post_types(array(
'has_archive' => true
), 'names');
$templates = array();
foreach ($archives as $archive) {
$template = \Modularity\Helper\Wp::findCoreTemplates(array(
'archive-' . $archive
));
if ($template) {
$templates[] = $template;
} else {
$templates[] = 'archive';
}
}
array_unique($templates);
return $templates;
} | [
"public",
"static",
"function",
"getArchiveTemplateSlugs",
"(",
")",
"{",
"$",
"archives",
"=",
"get_post_types",
"(",
"array",
"(",
"'has_archive'",
"=>",
"true",
")",
",",
"'names'",
")",
";",
"$",
"templates",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"archives",
"as",
"$",
"archive",
")",
"{",
"$",
"template",
"=",
"\\",
"Modularity",
"\\",
"Helper",
"\\",
"Wp",
"::",
"findCoreTemplates",
"(",
"array",
"(",
"'archive-'",
".",
"$",
"archive",
")",
")",
";",
"if",
"(",
"$",
"template",
")",
"{",
"$",
"templates",
"[",
"]",
"=",
"$",
"template",
";",
"}",
"else",
"{",
"$",
"templates",
"[",
"]",
"=",
"'archive'",
";",
"}",
"}",
"array_unique",
"(",
"$",
"templates",
")",
";",
"return",
"$",
"templates",
";",
"}"
]
| Get list of currently available archives slugs that has a template
@return array | [
"Get",
"list",
"of",
"currently",
"available",
"archives",
"slugs",
"that",
"has",
"a",
"template"
]
| db4fcde30ba5db4fac9c8b3c3475c8229b50271d | https://github.com/helsingborg-stad/Modularity/blob/db4fcde30ba5db4fac9c8b3c3475c8229b50271d/source/php/Options/Archives.php#L75-L97 | train |
helsingborg-stad/Modularity | source/php/Helper/File.php | File.getNamespace | public static function getNamespace(string $path) : string
{
$source = file_get_contents($path);
if($source === false) {
add_action( 'admin_notices',function() use($path) {
$malfunctionalPlugin = array_pop(get_plugins( "/" . explode( '/', plugin_basename( $path ))[0]));
printf( '<div class="%1$s"><p>%2$s</p></div>', esc_attr('notice notice-error'), esc_html("ERROR: Could not find module definition (file) in " . $malfunctionalPlugin['Name']));
});
}
$tokens = token_get_all($source);
$count = count($tokens);
$i = 0;
$namespace = '';
$namespaceFound = false;
while ($i < $count) {
$token = $tokens[$i];
if (is_array($token) && $token[0] === T_NAMESPACE) {
// Found namespace declaration
while (++$i < $count) {
if ($tokens[$i] === ';') {
$namespaceFound = true;
$namespace = trim($namespace);
break;
}
$namespace .= is_array($tokens[$i]) ? $tokens[$i][1] : $tokens[$i];
}
break;
}
$i++;
}
if (!$namespaceFound) {
return '';
}
return $namespace;
} | php | public static function getNamespace(string $path) : string
{
$source = file_get_contents($path);
if($source === false) {
add_action( 'admin_notices',function() use($path) {
$malfunctionalPlugin = array_pop(get_plugins( "/" . explode( '/', plugin_basename( $path ))[0]));
printf( '<div class="%1$s"><p>%2$s</p></div>', esc_attr('notice notice-error'), esc_html("ERROR: Could not find module definition (file) in " . $malfunctionalPlugin['Name']));
});
}
$tokens = token_get_all($source);
$count = count($tokens);
$i = 0;
$namespace = '';
$namespaceFound = false;
while ($i < $count) {
$token = $tokens[$i];
if (is_array($token) && $token[0] === T_NAMESPACE) {
// Found namespace declaration
while (++$i < $count) {
if ($tokens[$i] === ';') {
$namespaceFound = true;
$namespace = trim($namespace);
break;
}
$namespace .= is_array($tokens[$i]) ? $tokens[$i][1] : $tokens[$i];
}
break;
}
$i++;
}
if (!$namespaceFound) {
return '';
}
return $namespace;
} | [
"public",
"static",
"function",
"getNamespace",
"(",
"string",
"$",
"path",
")",
":",
"string",
"{",
"$",
"source",
"=",
"file_get_contents",
"(",
"$",
"path",
")",
";",
"if",
"(",
"$",
"source",
"===",
"false",
")",
"{",
"add_action",
"(",
"'admin_notices'",
",",
"function",
"(",
")",
"use",
"(",
"$",
"path",
")",
"{",
"$",
"malfunctionalPlugin",
"=",
"array_pop",
"(",
"get_plugins",
"(",
"\"/\"",
".",
"explode",
"(",
"'/'",
",",
"plugin_basename",
"(",
"$",
"path",
")",
")",
"[",
"0",
"]",
")",
")",
";",
"printf",
"(",
"'<div class=\"%1$s\"><p>%2$s</p></div>'",
",",
"esc_attr",
"(",
"'notice notice-error'",
")",
",",
"esc_html",
"(",
"\"ERROR: Could not find module definition (file) in \"",
".",
"$",
"malfunctionalPlugin",
"[",
"'Name'",
"]",
")",
")",
";",
"}",
")",
";",
"}",
"$",
"tokens",
"=",
"token_get_all",
"(",
"$",
"source",
")",
";",
"$",
"count",
"=",
"count",
"(",
"$",
"tokens",
")",
";",
"$",
"i",
"=",
"0",
";",
"$",
"namespace",
"=",
"''",
";",
"$",
"namespaceFound",
"=",
"false",
";",
"while",
"(",
"$",
"i",
"<",
"$",
"count",
")",
"{",
"$",
"token",
"=",
"$",
"tokens",
"[",
"$",
"i",
"]",
";",
"if",
"(",
"is_array",
"(",
"$",
"token",
")",
"&&",
"$",
"token",
"[",
"0",
"]",
"===",
"T_NAMESPACE",
")",
"{",
"// Found namespace declaration",
"while",
"(",
"++",
"$",
"i",
"<",
"$",
"count",
")",
"{",
"if",
"(",
"$",
"tokens",
"[",
"$",
"i",
"]",
"===",
"';'",
")",
"{",
"$",
"namespaceFound",
"=",
"true",
";",
"$",
"namespace",
"=",
"trim",
"(",
"$",
"namespace",
")",
";",
"break",
";",
"}",
"$",
"namespace",
".=",
"is_array",
"(",
"$",
"tokens",
"[",
"$",
"i",
"]",
")",
"?",
"$",
"tokens",
"[",
"$",
"i",
"]",
"[",
"1",
"]",
":",
"$",
"tokens",
"[",
"$",
"i",
"]",
";",
"}",
"break",
";",
"}",
"$",
"i",
"++",
";",
"}",
"if",
"(",
"!",
"$",
"namespaceFound",
")",
"{",
"return",
"''",
";",
"}",
"return",
"$",
"namespace",
";",
"}"
]
| Get PHP namespace from file
@param string $source Path to file
@return string Namespace | [
"Get",
"PHP",
"namespace",
"from",
"file"
]
| db4fcde30ba5db4fac9c8b3c3475c8229b50271d | https://github.com/helsingborg-stad/Modularity/blob/db4fcde30ba5db4fac9c8b3c3475c8229b50271d/source/php/Helper/File.php#L12-L55 | train |
helsingborg-stad/Modularity | source/php/Display.php | Display.isActiveSidebar | public function isActiveSidebar($isActiveSidebar, $sidebar)
{
$widgets = wp_get_sidebars_widgets();
$widgets = array_map('array_filter', $widgets);
$visibleModules = false;
if (isset($this->modules[$sidebar]) && count($this->modules[$sidebar]) > 0) {
foreach ($this->modules[$sidebar]['modules'] as $module) {
if (!is_preview() && $module->hidden == 'true') {
continue;
}
$visibleModules = true;
}
}
$hasWidgets = !empty($widgets[$sidebar]);
$hasModules = ($visibleModules && isset($this->modules[$sidebar]) && count($this->modules[$sidebar]) > 0);
if ($hasWidgets || $hasModules) {
return true;
}
return false;
} | php | public function isActiveSidebar($isActiveSidebar, $sidebar)
{
$widgets = wp_get_sidebars_widgets();
$widgets = array_map('array_filter', $widgets);
$visibleModules = false;
if (isset($this->modules[$sidebar]) && count($this->modules[$sidebar]) > 0) {
foreach ($this->modules[$sidebar]['modules'] as $module) {
if (!is_preview() && $module->hidden == 'true') {
continue;
}
$visibleModules = true;
}
}
$hasWidgets = !empty($widgets[$sidebar]);
$hasModules = ($visibleModules && isset($this->modules[$sidebar]) && count($this->modules[$sidebar]) > 0);
if ($hasWidgets || $hasModules) {
return true;
}
return false;
} | [
"public",
"function",
"isActiveSidebar",
"(",
"$",
"isActiveSidebar",
",",
"$",
"sidebar",
")",
"{",
"$",
"widgets",
"=",
"wp_get_sidebars_widgets",
"(",
")",
";",
"$",
"widgets",
"=",
"array_map",
"(",
"'array_filter'",
",",
"$",
"widgets",
")",
";",
"$",
"visibleModules",
"=",
"false",
";",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"modules",
"[",
"$",
"sidebar",
"]",
")",
"&&",
"count",
"(",
"$",
"this",
"->",
"modules",
"[",
"$",
"sidebar",
"]",
")",
">",
"0",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"modules",
"[",
"$",
"sidebar",
"]",
"[",
"'modules'",
"]",
"as",
"$",
"module",
")",
"{",
"if",
"(",
"!",
"is_preview",
"(",
")",
"&&",
"$",
"module",
"->",
"hidden",
"==",
"'true'",
")",
"{",
"continue",
";",
"}",
"$",
"visibleModules",
"=",
"true",
";",
"}",
"}",
"$",
"hasWidgets",
"=",
"!",
"empty",
"(",
"$",
"widgets",
"[",
"$",
"sidebar",
"]",
")",
";",
"$",
"hasModules",
"=",
"(",
"$",
"visibleModules",
"&&",
"isset",
"(",
"$",
"this",
"->",
"modules",
"[",
"$",
"sidebar",
"]",
")",
"&&",
"count",
"(",
"$",
"this",
"->",
"modules",
"[",
"$",
"sidebar",
"]",
")",
">",
"0",
")",
";",
"if",
"(",
"$",
"hasWidgets",
"||",
"$",
"hasModules",
")",
"{",
"return",
"true",
";",
"}",
"return",
"false",
";",
"}"
]
| New is_active_sidebar logic which includes module check
@param boolean $isActiveSidebar Original response
@param string $sidebar Sidebar id
@return boolean | [
"New",
"is_active_sidebar",
"logic",
"which",
"includes",
"module",
"check"
]
| db4fcde30ba5db4fac9c8b3c3475c8229b50271d | https://github.com/helsingborg-stad/Modularity/blob/db4fcde30ba5db4fac9c8b3c3475c8229b50271d/source/php/Display.php#L33-L57 | train |
helsingborg-stad/Modularity | source/php/Display.php | Display.outputBefore | public function outputBefore($sidebar)
{
if (!isset($this->options[$sidebar]['hook']) || $this->options[$sidebar]['hook'] != 'before') {
return false;
}
$this->output($sidebar);
} | php | public function outputBefore($sidebar)
{
if (!isset($this->options[$sidebar]['hook']) || $this->options[$sidebar]['hook'] != 'before') {
return false;
}
$this->output($sidebar);
} | [
"public",
"function",
"outputBefore",
"(",
"$",
"sidebar",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"options",
"[",
"$",
"sidebar",
"]",
"[",
"'hook'",
"]",
")",
"||",
"$",
"this",
"->",
"options",
"[",
"$",
"sidebar",
"]",
"[",
"'hook'",
"]",
"!=",
"'before'",
")",
"{",
"return",
"false",
";",
"}",
"$",
"this",
"->",
"output",
"(",
"$",
"sidebar",
")",
";",
"}"
]
| Check if modules should be outputted before widgets
@param string $sidebar Current sidebar
@return boolean|void | [
"Check",
"if",
"modules",
"should",
"be",
"outputted",
"before",
"widgets"
]
| db4fcde30ba5db4fac9c8b3c3475c8229b50271d | https://github.com/helsingborg-stad/Modularity/blob/db4fcde30ba5db4fac9c8b3c3475c8229b50271d/source/php/Display.php#L132-L139 | train |
helsingborg-stad/Modularity | source/php/Display.php | Display.outputAfter | public function outputAfter($sidebar)
{
if (isset($this->options[$sidebar]['hook']) && $this->options[$sidebar]['hook'] != 'after') {
return false;
}
$this->output($sidebar);
} | php | public function outputAfter($sidebar)
{
if (isset($this->options[$sidebar]['hook']) && $this->options[$sidebar]['hook'] != 'after') {
return false;
}
$this->output($sidebar);
} | [
"public",
"function",
"outputAfter",
"(",
"$",
"sidebar",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"options",
"[",
"$",
"sidebar",
"]",
"[",
"'hook'",
"]",
")",
"&&",
"$",
"this",
"->",
"options",
"[",
"$",
"sidebar",
"]",
"[",
"'hook'",
"]",
"!=",
"'after'",
")",
"{",
"return",
"false",
";",
"}",
"$",
"this",
"->",
"output",
"(",
"$",
"sidebar",
")",
";",
"}"
]
| Check if modules should be outputted after widgets
@param string $sidebar Current sidebar
@return boolean|void | [
"Check",
"if",
"modules",
"should",
"be",
"outputted",
"after",
"widgets"
]
| db4fcde30ba5db4fac9c8b3c3475c8229b50271d | https://github.com/helsingborg-stad/Modularity/blob/db4fcde30ba5db4fac9c8b3c3475c8229b50271d/source/php/Display.php#L146-L153 | train |
helsingborg-stad/Modularity | source/php/Display.php | Display.output | public function output($sidebar)
{
if (!isset($this->modules[$sidebar]) || !$this->isModularitySidebarActive($sidebar)) {
return;
}
// Get modules
$modules = $this->modules[$sidebar];
// Get sidebar arguments
$sidebarArgs = $this->getSidebarArgs($sidebar);
// Loop and output modules
foreach ($modules['modules'] as $module) {
if (!is_preview() && $module->hidden == 'true') {
continue;
}
$this->outputModule($module, $sidebarArgs, \Modularity\ModuleManager::$moduleSettings[get_post_type($module)]);
}
} | php | public function output($sidebar)
{
if (!isset($this->modules[$sidebar]) || !$this->isModularitySidebarActive($sidebar)) {
return;
}
// Get modules
$modules = $this->modules[$sidebar];
// Get sidebar arguments
$sidebarArgs = $this->getSidebarArgs($sidebar);
// Loop and output modules
foreach ($modules['modules'] as $module) {
if (!is_preview() && $module->hidden == 'true') {
continue;
}
$this->outputModule($module, $sidebarArgs, \Modularity\ModuleManager::$moduleSettings[get_post_type($module)]);
}
} | [
"public",
"function",
"output",
"(",
"$",
"sidebar",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"modules",
"[",
"$",
"sidebar",
"]",
")",
"||",
"!",
"$",
"this",
"->",
"isModularitySidebarActive",
"(",
"$",
"sidebar",
")",
")",
"{",
"return",
";",
"}",
"// Get modules",
"$",
"modules",
"=",
"$",
"this",
"->",
"modules",
"[",
"$",
"sidebar",
"]",
";",
"// Get sidebar arguments",
"$",
"sidebarArgs",
"=",
"$",
"this",
"->",
"getSidebarArgs",
"(",
"$",
"sidebar",
")",
";",
"// Loop and output modules",
"foreach",
"(",
"$",
"modules",
"[",
"'modules'",
"]",
"as",
"$",
"module",
")",
"{",
"if",
"(",
"!",
"is_preview",
"(",
")",
"&&",
"$",
"module",
"->",
"hidden",
"==",
"'true'",
")",
"{",
"continue",
";",
"}",
"$",
"this",
"->",
"outputModule",
"(",
"$",
"module",
",",
"$",
"sidebarArgs",
",",
"\\",
"Modularity",
"\\",
"ModuleManager",
"::",
"$",
"moduleSettings",
"[",
"get_post_type",
"(",
"$",
"module",
")",
"]",
")",
";",
"}",
"}"
]
| Outputs the modules of a specific sidebar
@param string $sidebar Sidebar id/slug
@return void | [
"Outputs",
"the",
"modules",
"of",
"a",
"specific",
"sidebar"
]
| db4fcde30ba5db4fac9c8b3c3475c8229b50271d | https://github.com/helsingborg-stad/Modularity/blob/db4fcde30ba5db4fac9c8b3c3475c8229b50271d/source/php/Display.php#L160-L180 | train |
helsingborg-stad/Modularity | source/php/Display.php | Display.fillMissingParams | public function fillMissingParams($module, $moduleSettings)
{
// Set class properties if needed
if (empty($module->slug)) {
foreach ($moduleSettings as $key => $value) {
$module->$key = $value;
}
$module->isLegacy = true;
}
return $module;
} | php | public function fillMissingParams($module, $moduleSettings)
{
// Set class properties if needed
if (empty($module->slug)) {
foreach ($moduleSettings as $key => $value) {
$module->$key = $value;
}
$module->isLegacy = true;
}
return $module;
} | [
"public",
"function",
"fillMissingParams",
"(",
"$",
"module",
",",
"$",
"moduleSettings",
")",
"{",
"// Set class properties if needed",
"if",
"(",
"empty",
"(",
"$",
"module",
"->",
"slug",
")",
")",
"{",
"foreach",
"(",
"$",
"moduleSettings",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"$",
"module",
"->",
"$",
"key",
"=",
"$",
"value",
";",
"}",
"$",
"module",
"->",
"isLegacy",
"=",
"true",
";",
"}",
"return",
"$",
"module",
";",
"}"
]
| Fills module object with missing params if needed
@param object $module
@param array $moduleSettings
@return object | [
"Fills",
"module",
"object",
"with",
"missing",
"params",
"if",
"needed"
]
| db4fcde30ba5db4fac9c8b3c3475c8229b50271d | https://github.com/helsingborg-stad/Modularity/blob/db4fcde30ba5db4fac9c8b3c3475c8229b50271d/source/php/Display.php#L221-L233 | train |
helsingborg-stad/Modularity | source/php/Display.php | Display.outputModule | public function outputModule($module, $args = array(), $moduleSettings = array(), $echo = true)
{
if (!isset($args['id'])) {
$args['id'] = 'no-id';
}
if (!is_object($module)) {
return false;
}
$class = \Modularity\ModuleManager::$classes[$module->post_type];
$module = new $class($module, $args);
$module = $this->fillMissingParams($module, $moduleSettings);
if (!$echo || !isset($moduleSettings['cache_ttl'])) {
$moduleSettings['cache_ttl'] = 0;
}
$cache = new \Modularity\Helper\Cache($module->ID, array($module, $args['id']), $moduleSettings['cache_ttl']);
if (empty($moduleSettings['cache_ttl']) || $cache->start()) {
$moduleMarkup = $this->getModuleMarkup($module, $args);
if (isset($module->columnWidth) && !empty($module->columnWidth)) {
$moduleMarkup .= apply_filters('Modularity/Display/AfterModule', '</div>', $args, $module->post_type, $module->ID);
} elseif (isset($this->options[$args['id']]['after_module']) && !empty($this->options[$args['id']]['after_module'])) {
$moduleMarkup .= apply_filters('Modularity/Display/AfterModule', '</div>', $args, $module->post_type, $module->ID);
} elseif (isset($args['after_widget'])) {
$moduleMarkup .= apply_filters('Modularity/Display/AfterModule', $args['after_widget'], $args, $module->post_type, $module->ID);
}
$moduleMarkup = apply_filters('Modularity/Display/Markup', $moduleMarkup, $module);
$moduleMarkup = apply_filters('Modularity/Display/' . $module->post_type . '/Markup', $moduleMarkup, $module);
if (!$echo) {
return $moduleMarkup;
}
echo $moduleMarkup;
if (!empty($moduleSettings['cache_ttl'])) {
$cache->stop();
}
}
return true;
} | php | public function outputModule($module, $args = array(), $moduleSettings = array(), $echo = true)
{
if (!isset($args['id'])) {
$args['id'] = 'no-id';
}
if (!is_object($module)) {
return false;
}
$class = \Modularity\ModuleManager::$classes[$module->post_type];
$module = new $class($module, $args);
$module = $this->fillMissingParams($module, $moduleSettings);
if (!$echo || !isset($moduleSettings['cache_ttl'])) {
$moduleSettings['cache_ttl'] = 0;
}
$cache = new \Modularity\Helper\Cache($module->ID, array($module, $args['id']), $moduleSettings['cache_ttl']);
if (empty($moduleSettings['cache_ttl']) || $cache->start()) {
$moduleMarkup = $this->getModuleMarkup($module, $args);
if (isset($module->columnWidth) && !empty($module->columnWidth)) {
$moduleMarkup .= apply_filters('Modularity/Display/AfterModule', '</div>', $args, $module->post_type, $module->ID);
} elseif (isset($this->options[$args['id']]['after_module']) && !empty($this->options[$args['id']]['after_module'])) {
$moduleMarkup .= apply_filters('Modularity/Display/AfterModule', '</div>', $args, $module->post_type, $module->ID);
} elseif (isset($args['after_widget'])) {
$moduleMarkup .= apply_filters('Modularity/Display/AfterModule', $args['after_widget'], $args, $module->post_type, $module->ID);
}
$moduleMarkup = apply_filters('Modularity/Display/Markup', $moduleMarkup, $module);
$moduleMarkup = apply_filters('Modularity/Display/' . $module->post_type . '/Markup', $moduleMarkup, $module);
if (!$echo) {
return $moduleMarkup;
}
echo $moduleMarkup;
if (!empty($moduleSettings['cache_ttl'])) {
$cache->stop();
}
}
return true;
} | [
"public",
"function",
"outputModule",
"(",
"$",
"module",
",",
"$",
"args",
"=",
"array",
"(",
")",
",",
"$",
"moduleSettings",
"=",
"array",
"(",
")",
",",
"$",
"echo",
"=",
"true",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"args",
"[",
"'id'",
"]",
")",
")",
"{",
"$",
"args",
"[",
"'id'",
"]",
"=",
"'no-id'",
";",
"}",
"if",
"(",
"!",
"is_object",
"(",
"$",
"module",
")",
")",
"{",
"return",
"false",
";",
"}",
"$",
"class",
"=",
"\\",
"Modularity",
"\\",
"ModuleManager",
"::",
"$",
"classes",
"[",
"$",
"module",
"->",
"post_type",
"]",
";",
"$",
"module",
"=",
"new",
"$",
"class",
"(",
"$",
"module",
",",
"$",
"args",
")",
";",
"$",
"module",
"=",
"$",
"this",
"->",
"fillMissingParams",
"(",
"$",
"module",
",",
"$",
"moduleSettings",
")",
";",
"if",
"(",
"!",
"$",
"echo",
"||",
"!",
"isset",
"(",
"$",
"moduleSettings",
"[",
"'cache_ttl'",
"]",
")",
")",
"{",
"$",
"moduleSettings",
"[",
"'cache_ttl'",
"]",
"=",
"0",
";",
"}",
"$",
"cache",
"=",
"new",
"\\",
"Modularity",
"\\",
"Helper",
"\\",
"Cache",
"(",
"$",
"module",
"->",
"ID",
",",
"array",
"(",
"$",
"module",
",",
"$",
"args",
"[",
"'id'",
"]",
")",
",",
"$",
"moduleSettings",
"[",
"'cache_ttl'",
"]",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"moduleSettings",
"[",
"'cache_ttl'",
"]",
")",
"||",
"$",
"cache",
"->",
"start",
"(",
")",
")",
"{",
"$",
"moduleMarkup",
"=",
"$",
"this",
"->",
"getModuleMarkup",
"(",
"$",
"module",
",",
"$",
"args",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"module",
"->",
"columnWidth",
")",
"&&",
"!",
"empty",
"(",
"$",
"module",
"->",
"columnWidth",
")",
")",
"{",
"$",
"moduleMarkup",
".=",
"apply_filters",
"(",
"'Modularity/Display/AfterModule'",
",",
"'</div>'",
",",
"$",
"args",
",",
"$",
"module",
"->",
"post_type",
",",
"$",
"module",
"->",
"ID",
")",
";",
"}",
"elseif",
"(",
"isset",
"(",
"$",
"this",
"->",
"options",
"[",
"$",
"args",
"[",
"'id'",
"]",
"]",
"[",
"'after_module'",
"]",
")",
"&&",
"!",
"empty",
"(",
"$",
"this",
"->",
"options",
"[",
"$",
"args",
"[",
"'id'",
"]",
"]",
"[",
"'after_module'",
"]",
")",
")",
"{",
"$",
"moduleMarkup",
".=",
"apply_filters",
"(",
"'Modularity/Display/AfterModule'",
",",
"'</div>'",
",",
"$",
"args",
",",
"$",
"module",
"->",
"post_type",
",",
"$",
"module",
"->",
"ID",
")",
";",
"}",
"elseif",
"(",
"isset",
"(",
"$",
"args",
"[",
"'after_widget'",
"]",
")",
")",
"{",
"$",
"moduleMarkup",
".=",
"apply_filters",
"(",
"'Modularity/Display/AfterModule'",
",",
"$",
"args",
"[",
"'after_widget'",
"]",
",",
"$",
"args",
",",
"$",
"module",
"->",
"post_type",
",",
"$",
"module",
"->",
"ID",
")",
";",
"}",
"$",
"moduleMarkup",
"=",
"apply_filters",
"(",
"'Modularity/Display/Markup'",
",",
"$",
"moduleMarkup",
",",
"$",
"module",
")",
";",
"$",
"moduleMarkup",
"=",
"apply_filters",
"(",
"'Modularity/Display/'",
".",
"$",
"module",
"->",
"post_type",
".",
"'/Markup'",
",",
"$",
"moduleMarkup",
",",
"$",
"module",
")",
";",
"if",
"(",
"!",
"$",
"echo",
")",
"{",
"return",
"$",
"moduleMarkup",
";",
"}",
"echo",
"$",
"moduleMarkup",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"moduleSettings",
"[",
"'cache_ttl'",
"]",
")",
")",
"{",
"$",
"cache",
"->",
"stop",
"(",
")",
";",
"}",
"}",
"return",
"true",
";",
"}"
]
| Outputs a specific module
@param object $module The module data
@param array $args The sidebar data
@param array $moduleSettings The module configuration
@return boolean True if success otherwise false | [
"Outputs",
"a",
"specific",
"module"
]
| db4fcde30ba5db4fac9c8b3c3475c8229b50271d | https://github.com/helsingborg-stad/Modularity/blob/db4fcde30ba5db4fac9c8b3c3475c8229b50271d/source/php/Display.php#L242-L288 | train |
helsingborg-stad/Modularity | source/php/Display.php | Display.shortcodeDisplay | public function shortcodeDisplay($args)
{
$args = shortcode_atts(array(
'id' => false,
'inline' => true
), $args);
if (!is_numeric($args['id'])) {
return;
}
//Get module details
$module = \Modularity\Editor::getModule($args['id']);
//If not valid details, abort.
if (!is_object($module) || empty($module->post_type)) {
return "";
}
//Create instance
$class = \Modularity\ModuleManager::$classes[$module->post_type];
$module = new $class($module, $args);
$moduleMarkup = $this->getModuleMarkup($module, $args);
if (empty($moduleMarkup)) {
return;
}
$moduleMarkup = apply_filters('Modularity/Display/Markup', $moduleMarkup, $module);
$moduleMarkup = apply_filters('Modularity/Display/' . $module->post_type . '/Markup', $moduleMarkup, $module);
return '<div class="' . $module->post_type . '">' . $moduleMarkup . '</div>';
} | php | public function shortcodeDisplay($args)
{
$args = shortcode_atts(array(
'id' => false,
'inline' => true
), $args);
if (!is_numeric($args['id'])) {
return;
}
//Get module details
$module = \Modularity\Editor::getModule($args['id']);
//If not valid details, abort.
if (!is_object($module) || empty($module->post_type)) {
return "";
}
//Create instance
$class = \Modularity\ModuleManager::$classes[$module->post_type];
$module = new $class($module, $args);
$moduleMarkup = $this->getModuleMarkup($module, $args);
if (empty($moduleMarkup)) {
return;
}
$moduleMarkup = apply_filters('Modularity/Display/Markup', $moduleMarkup, $module);
$moduleMarkup = apply_filters('Modularity/Display/' . $module->post_type . '/Markup', $moduleMarkup, $module);
return '<div class="' . $module->post_type . '">' . $moduleMarkup . '</div>';
} | [
"public",
"function",
"shortcodeDisplay",
"(",
"$",
"args",
")",
"{",
"$",
"args",
"=",
"shortcode_atts",
"(",
"array",
"(",
"'id'",
"=>",
"false",
",",
"'inline'",
"=>",
"true",
")",
",",
"$",
"args",
")",
";",
"if",
"(",
"!",
"is_numeric",
"(",
"$",
"args",
"[",
"'id'",
"]",
")",
")",
"{",
"return",
";",
"}",
"//Get module details",
"$",
"module",
"=",
"\\",
"Modularity",
"\\",
"Editor",
"::",
"getModule",
"(",
"$",
"args",
"[",
"'id'",
"]",
")",
";",
"//If not valid details, abort.",
"if",
"(",
"!",
"is_object",
"(",
"$",
"module",
")",
"||",
"empty",
"(",
"$",
"module",
"->",
"post_type",
")",
")",
"{",
"return",
"\"\"",
";",
"}",
"//Create instance",
"$",
"class",
"=",
"\\",
"Modularity",
"\\",
"ModuleManager",
"::",
"$",
"classes",
"[",
"$",
"module",
"->",
"post_type",
"]",
";",
"$",
"module",
"=",
"new",
"$",
"class",
"(",
"$",
"module",
",",
"$",
"args",
")",
";",
"$",
"moduleMarkup",
"=",
"$",
"this",
"->",
"getModuleMarkup",
"(",
"$",
"module",
",",
"$",
"args",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"moduleMarkup",
")",
")",
"{",
"return",
";",
"}",
"$",
"moduleMarkup",
"=",
"apply_filters",
"(",
"'Modularity/Display/Markup'",
",",
"$",
"moduleMarkup",
",",
"$",
"module",
")",
";",
"$",
"moduleMarkup",
"=",
"apply_filters",
"(",
"'Modularity/Display/'",
".",
"$",
"module",
"->",
"post_type",
".",
"'/Markup'",
",",
"$",
"moduleMarkup",
",",
"$",
"module",
")",
";",
"return",
"'<div class=\"'",
".",
"$",
"module",
"->",
"post_type",
".",
"'\">'",
".",
"$",
"moduleMarkup",
".",
"'</div>'",
";",
"}"
]
| Display module with shortcode
@param array $args Args
@return string Html markup | [
"Display",
"module",
"with",
"shortcode"
]
| db4fcde30ba5db4fac9c8b3c3475c8229b50271d | https://github.com/helsingborg-stad/Modularity/blob/db4fcde30ba5db4fac9c8b3c3475c8229b50271d/source/php/Display.php#L404-L436 | train |
helsingborg-stad/Modularity | source/php/Display.php | Display.filterNestedModuleShortocde | public function filterNestedModuleShortocde($post)
{
if (is_admin()) {
return $post;
}
if (substr($post->post_type, 0, 4) != 'mod-') {
return $post;
}
$post->post_content = preg_replace('/\[modularity(.*)\]/', '', $post->post_content);
return $post;
} | php | public function filterNestedModuleShortocde($post)
{
if (is_admin()) {
return $post;
}
if (substr($post->post_type, 0, 4) != 'mod-') {
return $post;
}
$post->post_content = preg_replace('/\[modularity(.*)\]/', '', $post->post_content);
return $post;
} | [
"public",
"function",
"filterNestedModuleShortocde",
"(",
"$",
"post",
")",
"{",
"if",
"(",
"is_admin",
"(",
")",
")",
"{",
"return",
"$",
"post",
";",
"}",
"if",
"(",
"substr",
"(",
"$",
"post",
"->",
"post_type",
",",
"0",
",",
"4",
")",
"!=",
"'mod-'",
")",
"{",
"return",
"$",
"post",
";",
"}",
"$",
"post",
"->",
"post_content",
"=",
"preg_replace",
"(",
"'/\\[modularity(.*)\\]/'",
",",
"''",
",",
"$",
"post",
"->",
"post_content",
")",
";",
"return",
"$",
"post",
";",
"}"
]
| Removes nested shortcodes
@param WP_Post $post
@return WP_Post | [
"Removes",
"nested",
"shortcodes"
]
| db4fcde30ba5db4fac9c8b3c3475c8229b50271d | https://github.com/helsingborg-stad/Modularity/blob/db4fcde30ba5db4fac9c8b3c3475c8229b50271d/source/php/Display.php#L443-L455 | train |
helsingborg-stad/Modularity | source/php/Display.php | Display.addGridToSidebar | public function addGridToSidebar($markup, $module)
{
$sidebars = apply_filters('Modularity/Module/Container/Sidebars', array());
$modules = apply_filters('Modularity/Module/Container/Modules', array());
$template = apply_filters('Modularity/Module/Container/Template', '<div class="container"><div class="grid"><div class="grid-xs-12">{{module-markup}}</div></div></div>');
if (in_array($module->args['id'], $sidebars) && in_array($module->post_type, $modules)) {
return str_replace('{{module-markup}}', $markup, $template);
}
return $markup;
} | php | public function addGridToSidebar($markup, $module)
{
$sidebars = apply_filters('Modularity/Module/Container/Sidebars', array());
$modules = apply_filters('Modularity/Module/Container/Modules', array());
$template = apply_filters('Modularity/Module/Container/Template', '<div class="container"><div class="grid"><div class="grid-xs-12">{{module-markup}}</div></div></div>');
if (in_array($module->args['id'], $sidebars) && in_array($module->post_type, $modules)) {
return str_replace('{{module-markup}}', $markup, $template);
}
return $markup;
} | [
"public",
"function",
"addGridToSidebar",
"(",
"$",
"markup",
",",
"$",
"module",
")",
"{",
"$",
"sidebars",
"=",
"apply_filters",
"(",
"'Modularity/Module/Container/Sidebars'",
",",
"array",
"(",
")",
")",
";",
"$",
"modules",
"=",
"apply_filters",
"(",
"'Modularity/Module/Container/Modules'",
",",
"array",
"(",
")",
")",
";",
"$",
"template",
"=",
"apply_filters",
"(",
"'Modularity/Module/Container/Template'",
",",
"'<div class=\"container\"><div class=\"grid\"><div class=\"grid-xs-12\">{{module-markup}}</div></div></div>'",
")",
";",
"if",
"(",
"in_array",
"(",
"$",
"module",
"->",
"args",
"[",
"'id'",
"]",
",",
"$",
"sidebars",
")",
"&&",
"in_array",
"(",
"$",
"module",
"->",
"post_type",
",",
"$",
"modules",
")",
")",
"{",
"return",
"str_replace",
"(",
"'{{module-markup}}'",
",",
"$",
"markup",
",",
"$",
"template",
")",
";",
"}",
"return",
"$",
"markup",
";",
"}"
]
| Add container grid to specified modules, in specified sidebars
@param $markup The module markup
@return $module Module object | [
"Add",
"container",
"grid",
"to",
"specified",
"modules",
"in",
"specified",
"sidebars"
]
| db4fcde30ba5db4fac9c8b3c3475c8229b50271d | https://github.com/helsingborg-stad/Modularity/blob/db4fcde30ba5db4fac9c8b3c3475c8229b50271d/source/php/Display.php#L463-L474 | train |
helsingborg-stad/Modularity | source/php/Search.php | Search.getRenderedPostModules | public function getRenderedPostModules($post)
{
if (!$post) {
return;
}
if (is_array($post)) {
$postId = $post['ID'];
} else {
$postId = $post->ID;
}
$modules = \Modularity\Editor::getPostModules($postId);
$onlyModules = array();
// Normalize modules array
foreach ($modules as $sidebar => $item) {
if (!isset($item['modules']) || count($item['modules']) === 0) {
continue;
}
$onlyModules = array_merge($onlyModules, $item['modules']);
}
// Render modules and append to post content
$rendered = "<br><br>";
foreach ($onlyModules as $module) {
if ($module->post_type === 'mod-wpwidget') {
continue;
}
$markup = \Modularity\App::$display->outputModule($module, array('edit_module' => false), array(), false);
$rendered .= $markup;
}
return $rendered;
} | php | public function getRenderedPostModules($post)
{
if (!$post) {
return;
}
if (is_array($post)) {
$postId = $post['ID'];
} else {
$postId = $post->ID;
}
$modules = \Modularity\Editor::getPostModules($postId);
$onlyModules = array();
// Normalize modules array
foreach ($modules as $sidebar => $item) {
if (!isset($item['modules']) || count($item['modules']) === 0) {
continue;
}
$onlyModules = array_merge($onlyModules, $item['modules']);
}
// Render modules and append to post content
$rendered = "<br><br>";
foreach ($onlyModules as $module) {
if ($module->post_type === 'mod-wpwidget') {
continue;
}
$markup = \Modularity\App::$display->outputModule($module, array('edit_module' => false), array(), false);
$rendered .= $markup;
}
return $rendered;
} | [
"public",
"function",
"getRenderedPostModules",
"(",
"$",
"post",
")",
"{",
"if",
"(",
"!",
"$",
"post",
")",
"{",
"return",
";",
"}",
"if",
"(",
"is_array",
"(",
"$",
"post",
")",
")",
"{",
"$",
"postId",
"=",
"$",
"post",
"[",
"'ID'",
"]",
";",
"}",
"else",
"{",
"$",
"postId",
"=",
"$",
"post",
"->",
"ID",
";",
"}",
"$",
"modules",
"=",
"\\",
"Modularity",
"\\",
"Editor",
"::",
"getPostModules",
"(",
"$",
"postId",
")",
";",
"$",
"onlyModules",
"=",
"array",
"(",
")",
";",
"// Normalize modules array",
"foreach",
"(",
"$",
"modules",
"as",
"$",
"sidebar",
"=>",
"$",
"item",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"item",
"[",
"'modules'",
"]",
")",
"||",
"count",
"(",
"$",
"item",
"[",
"'modules'",
"]",
")",
"===",
"0",
")",
"{",
"continue",
";",
"}",
"$",
"onlyModules",
"=",
"array_merge",
"(",
"$",
"onlyModules",
",",
"$",
"item",
"[",
"'modules'",
"]",
")",
";",
"}",
"// Render modules and append to post content",
"$",
"rendered",
"=",
"\"<br><br>\"",
";",
"foreach",
"(",
"$",
"onlyModules",
"as",
"$",
"module",
")",
"{",
"if",
"(",
"$",
"module",
"->",
"post_type",
"===",
"'mod-wpwidget'",
")",
"{",
"continue",
";",
"}",
"$",
"markup",
"=",
"\\",
"Modularity",
"\\",
"App",
"::",
"$",
"display",
"->",
"outputModule",
"(",
"$",
"module",
",",
"array",
"(",
"'edit_module'",
"=>",
"false",
")",
",",
"array",
"(",
")",
",",
"false",
")",
";",
"$",
"rendered",
".=",
"$",
"markup",
";",
"}",
"return",
"$",
"rendered",
";",
"}"
]
| Render all modules on post
@param WP_Post $post
@return string | [
"Render",
"all",
"modules",
"on",
"post"
]
| db4fcde30ba5db4fac9c8b3c3475c8229b50271d | https://github.com/helsingborg-stad/Modularity/blob/db4fcde30ba5db4fac9c8b3c3475c8229b50271d/source/php/Search.php#L28-L64 | train |
helsingborg-stad/Modularity | source/php/Search.php | Search.addAlgoliaModuleAttribute | public function addAlgoliaModuleAttribute($attributes, $post)
{
//Get rendered data from module(s)
$rendered = strip_tags($this->getRenderedPostModules($post));
//Only add if not empty
if (!empty($rendered)) {
$attributes['modules'] = substr($rendered, 0, 7000);
}
return $attributes;
} | php | public function addAlgoliaModuleAttribute($attributes, $post)
{
//Get rendered data from module(s)
$rendered = strip_tags($this->getRenderedPostModules($post));
//Only add if not empty
if (!empty($rendered)) {
$attributes['modules'] = substr($rendered, 0, 7000);
}
return $attributes;
} | [
"public",
"function",
"addAlgoliaModuleAttribute",
"(",
"$",
"attributes",
",",
"$",
"post",
")",
"{",
"//Get rendered data from module(s)",
"$",
"rendered",
"=",
"strip_tags",
"(",
"$",
"this",
"->",
"getRenderedPostModules",
"(",
"$",
"post",
")",
")",
";",
"//Only add if not empty",
"if",
"(",
"!",
"empty",
"(",
"$",
"rendered",
")",
")",
"{",
"$",
"attributes",
"[",
"'modules'",
"]",
"=",
"substr",
"(",
"$",
"rendered",
",",
"0",
",",
"7000",
")",
";",
"}",
"return",
"$",
"attributes",
";",
"}"
]
| Add a attribute to algolia search
@param array $attributes
@param WP_Post $post
@return array | [
"Add",
"a",
"attribute",
"to",
"algolia",
"search"
]
| db4fcde30ba5db4fac9c8b3c3475c8229b50271d | https://github.com/helsingborg-stad/Modularity/blob/db4fcde30ba5db4fac9c8b3c3475c8229b50271d/source/php/Search.php#L94-L105 | train |
helsingborg-stad/Modularity | source/php/Search.php | Search.moduleSearchModuleDescription | public function moduleSearchModuleDescription($search)
{
global $wpdb;
if ($this->isModuleSearch()) {
$like = '%' . $wpdb->esc_like($_GET['s']) . '%';
$meta_description = $wpdb->prepare("OR ({$wpdb->postmeta}.meta_value LIKE %s)", $like);
// Add the meta description OR condition between one of the existing OR conditions.
$search = str_replace('OR', $meta_description . ' OR', $search);
}
return $search;
} | php | public function moduleSearchModuleDescription($search)
{
global $wpdb;
if ($this->isModuleSearch()) {
$like = '%' . $wpdb->esc_like($_GET['s']) . '%';
$meta_description = $wpdb->prepare("OR ({$wpdb->postmeta}.meta_value LIKE %s)", $like);
// Add the meta description OR condition between one of the existing OR conditions.
$search = str_replace('OR', $meta_description . ' OR', $search);
}
return $search;
} | [
"public",
"function",
"moduleSearchModuleDescription",
"(",
"$",
"search",
")",
"{",
"global",
"$",
"wpdb",
";",
"if",
"(",
"$",
"this",
"->",
"isModuleSearch",
"(",
")",
")",
"{",
"$",
"like",
"=",
"'%'",
".",
"$",
"wpdb",
"->",
"esc_like",
"(",
"$",
"_GET",
"[",
"'s'",
"]",
")",
".",
"'%'",
";",
"$",
"meta_description",
"=",
"$",
"wpdb",
"->",
"prepare",
"(",
"\"OR ({$wpdb->postmeta}.meta_value LIKE %s)\"",
",",
"$",
"like",
")",
";",
"// Add the meta description OR condition between one of the existing OR conditions.",
"$",
"search",
"=",
"str_replace",
"(",
"'OR'",
",",
"$",
"meta_description",
".",
"' OR'",
",",
"$",
"search",
")",
";",
"}",
"return",
"$",
"search",
";",
"}"
]
| Adds the OR condition to search the module description on module edit pages.
@param string $search Search SQL for WHERE clause.
@return string | [
"Adds",
"the",
"OR",
"condition",
"to",
"search",
"the",
"module",
"description",
"on",
"module",
"edit",
"pages",
"."
]
| db4fcde30ba5db4fac9c8b3c3475c8229b50271d | https://github.com/helsingborg-stad/Modularity/blob/db4fcde30ba5db4fac9c8b3c3475c8229b50271d/source/php/Search.php#L130-L142 | train |
helsingborg-stad/Modularity | source/php/Search.php | Search.isModuleSearch | public function isModuleSearch()
{
global $pagenow;
if ($pagenow == 'edit.php' && isset($_GET['s']) && $_GET['s'] !== '') {
$enabled = \Modularity\ModuleManager::$enabled;
if (in_array($_GET['post_type'], $enabled)) {
return true;
}
}
return false;
} | php | public function isModuleSearch()
{
global $pagenow;
if ($pagenow == 'edit.php' && isset($_GET['s']) && $_GET['s'] !== '') {
$enabled = \Modularity\ModuleManager::$enabled;
if (in_array($_GET['post_type'], $enabled)) {
return true;
}
}
return false;
} | [
"public",
"function",
"isModuleSearch",
"(",
")",
"{",
"global",
"$",
"pagenow",
";",
"if",
"(",
"$",
"pagenow",
"==",
"'edit.php'",
"&&",
"isset",
"(",
"$",
"_GET",
"[",
"'s'",
"]",
")",
"&&",
"$",
"_GET",
"[",
"'s'",
"]",
"!==",
"''",
")",
"{",
"$",
"enabled",
"=",
"\\",
"Modularity",
"\\",
"ModuleManager",
"::",
"$",
"enabled",
";",
"if",
"(",
"in_array",
"(",
"$",
"_GET",
"[",
"'post_type'",
"]",
",",
"$",
"enabled",
")",
")",
"{",
"return",
"true",
";",
"}",
"}",
"return",
"false",
";",
"}"
]
| Helper method to determine if a module search is performed on a module edit page.
@return bool | [
"Helper",
"method",
"to",
"determine",
"if",
"a",
"module",
"search",
"is",
"performed",
"on",
"a",
"module",
"edit",
"page",
"."
]
| db4fcde30ba5db4fac9c8b3c3475c8229b50271d | https://github.com/helsingborg-stad/Modularity/blob/db4fcde30ba5db4fac9c8b3c3475c8229b50271d/source/php/Search.php#L164-L176 | train |
helsingborg-stad/Modularity | source/php/Search.php | Search.appendToArray | public function appendToArray(array $array, $key, array $new)
{
$keys = array_keys($array);
$index = array_search($key, $keys);
$pos = false === $index ? count($array) : $index + 1;
return array_merge(array_slice($array, 0, $pos), $new, array_slice($array, $pos));
} | php | public function appendToArray(array $array, $key, array $new)
{
$keys = array_keys($array);
$index = array_search($key, $keys);
$pos = false === $index ? count($array) : $index + 1;
return array_merge(array_slice($array, 0, $pos), $new, array_slice($array, $pos));
} | [
"public",
"function",
"appendToArray",
"(",
"array",
"$",
"array",
",",
"$",
"key",
",",
"array",
"$",
"new",
")",
"{",
"$",
"keys",
"=",
"array_keys",
"(",
"$",
"array",
")",
";",
"$",
"index",
"=",
"array_search",
"(",
"$",
"key",
",",
"$",
"keys",
")",
";",
"$",
"pos",
"=",
"false",
"===",
"$",
"index",
"?",
"count",
"(",
"$",
"array",
")",
":",
"$",
"index",
"+",
"1",
";",
"return",
"array_merge",
"(",
"array_slice",
"(",
"$",
"array",
",",
"0",
",",
"$",
"pos",
")",
",",
"$",
"new",
",",
"array_slice",
"(",
"$",
"array",
",",
"$",
"pos",
")",
")",
";",
"}"
]
| Appends items to array after specific key
@param array $array The array to append to
@param string $key The key to append after
@param array $new The items to append
@return array The new array | [
"Appends",
"items",
"to",
"array",
"after",
"specific",
"key"
]
| db4fcde30ba5db4fac9c8b3c3475c8229b50271d | https://github.com/helsingborg-stad/Modularity/blob/db4fcde30ba5db4fac9c8b3c3475c8229b50271d/source/php/Search.php#L185-L192 | train |
helsingborg-stad/Modularity | source/php/Helper/Curl.php | Curl.createCacheKey | public function createCacheKey($type, $url, $data = null, $contentType = 'json', $headers = null)
{
$this->cacheKey = "curl_cache_".md5($type.$url.(is_array($data) ? implode($data, "") : $data).$contentType.(is_array($headers) ? implode($headers, "") : $headers));
return $this->cacheKey;
} | php | public function createCacheKey($type, $url, $data = null, $contentType = 'json', $headers = null)
{
$this->cacheKey = "curl_cache_".md5($type.$url.(is_array($data) ? implode($data, "") : $data).$contentType.(is_array($headers) ? implode($headers, "") : $headers));
return $this->cacheKey;
} | [
"public",
"function",
"createCacheKey",
"(",
"$",
"type",
",",
"$",
"url",
",",
"$",
"data",
"=",
"null",
",",
"$",
"contentType",
"=",
"'json'",
",",
"$",
"headers",
"=",
"null",
")",
"{",
"$",
"this",
"->",
"cacheKey",
"=",
"\"curl_cache_\"",
".",
"md5",
"(",
"$",
"type",
".",
"$",
"url",
".",
"(",
"is_array",
"(",
"$",
"data",
")",
"?",
"implode",
"(",
"$",
"data",
",",
"\"\"",
")",
":",
"$",
"data",
")",
".",
"$",
"contentType",
".",
"(",
"is_array",
"(",
"$",
"headers",
")",
"?",
"implode",
"(",
"$",
"headers",
",",
"\"\"",
")",
":",
"$",
"headers",
")",
")",
";",
"return",
"$",
"this",
"->",
"cacheKey",
";",
"}"
]
| Create Cache key
@param string $type Request type
@param string $url Request url
@param array $data Request data
@param string $contentType Content type
@param array $headers Request headers
@return string The cache key | [
"Create",
"Cache",
"key"
]
| db4fcde30ba5db4fac9c8b3c3475c8229b50271d | https://github.com/helsingborg-stad/Modularity/blob/db4fcde30ba5db4fac9c8b3c3475c8229b50271d/source/php/Helper/Curl.php#L134-L138 | train |
helsingborg-stad/Modularity | source/php/Module/Index/Index.php | Index.prepareItems | public function prepareItems($items)
{
if (is_array($items) && !empty($items)) {
foreach ($items as $key => &$item) {
//Get linked post object.
$postData = is_object($item['page']) ? $item['page'] : false;
//Linking
if ($item['link_type'] == 'external') {
$item['permalink'] = $item['link_url'];
} elseif (is_object($postData) && isset($postData->ID) && $item['link_type'] == 'internal') {
$item['permalink'] = get_permalink($postData->ID);
}
//Thumbnail
$item['thumbnail'] = $this->getThumbnail($item);
if ($postData !== false && get_post_status($postData->ID)) {
//Retrive post content & lead
if (is_object($postData) && isset($postData->ID)) {
$item['title'] = $this->switchContent($item['title'], $postData->post_title);
$item['lead'] = $this->switchContent($item['lead'], $this->parseExcerpt($postData->post_content));
}
} else {
unset($item);
}
//Removes empty/unfetchable objects from index
if($item['link_type'] == "internal" && empty($item['title']) && empty($item['lead']) && empty($item['thumbnail']) && empty($item['permalink'])) {
unset($items[$key]);
}
}
}
return $items;
} | php | public function prepareItems($items)
{
if (is_array($items) && !empty($items)) {
foreach ($items as $key => &$item) {
//Get linked post object.
$postData = is_object($item['page']) ? $item['page'] : false;
//Linking
if ($item['link_type'] == 'external') {
$item['permalink'] = $item['link_url'];
} elseif (is_object($postData) && isset($postData->ID) && $item['link_type'] == 'internal') {
$item['permalink'] = get_permalink($postData->ID);
}
//Thumbnail
$item['thumbnail'] = $this->getThumbnail($item);
if ($postData !== false && get_post_status($postData->ID)) {
//Retrive post content & lead
if (is_object($postData) && isset($postData->ID)) {
$item['title'] = $this->switchContent($item['title'], $postData->post_title);
$item['lead'] = $this->switchContent($item['lead'], $this->parseExcerpt($postData->post_content));
}
} else {
unset($item);
}
//Removes empty/unfetchable objects from index
if($item['link_type'] == "internal" && empty($item['title']) && empty($item['lead']) && empty($item['thumbnail']) && empty($item['permalink'])) {
unset($items[$key]);
}
}
}
return $items;
} | [
"public",
"function",
"prepareItems",
"(",
"$",
"items",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"items",
")",
"&&",
"!",
"empty",
"(",
"$",
"items",
")",
")",
"{",
"foreach",
"(",
"$",
"items",
"as",
"$",
"key",
"=>",
"&",
"$",
"item",
")",
"{",
"//Get linked post object.",
"$",
"postData",
"=",
"is_object",
"(",
"$",
"item",
"[",
"'page'",
"]",
")",
"?",
"$",
"item",
"[",
"'page'",
"]",
":",
"false",
";",
"//Linking",
"if",
"(",
"$",
"item",
"[",
"'link_type'",
"]",
"==",
"'external'",
")",
"{",
"$",
"item",
"[",
"'permalink'",
"]",
"=",
"$",
"item",
"[",
"'link_url'",
"]",
";",
"}",
"elseif",
"(",
"is_object",
"(",
"$",
"postData",
")",
"&&",
"isset",
"(",
"$",
"postData",
"->",
"ID",
")",
"&&",
"$",
"item",
"[",
"'link_type'",
"]",
"==",
"'internal'",
")",
"{",
"$",
"item",
"[",
"'permalink'",
"]",
"=",
"get_permalink",
"(",
"$",
"postData",
"->",
"ID",
")",
";",
"}",
"//Thumbnail",
"$",
"item",
"[",
"'thumbnail'",
"]",
"=",
"$",
"this",
"->",
"getThumbnail",
"(",
"$",
"item",
")",
";",
"if",
"(",
"$",
"postData",
"!==",
"false",
"&&",
"get_post_status",
"(",
"$",
"postData",
"->",
"ID",
")",
")",
"{",
"//Retrive post content & lead",
"if",
"(",
"is_object",
"(",
"$",
"postData",
")",
"&&",
"isset",
"(",
"$",
"postData",
"->",
"ID",
")",
")",
"{",
"$",
"item",
"[",
"'title'",
"]",
"=",
"$",
"this",
"->",
"switchContent",
"(",
"$",
"item",
"[",
"'title'",
"]",
",",
"$",
"postData",
"->",
"post_title",
")",
";",
"$",
"item",
"[",
"'lead'",
"]",
"=",
"$",
"this",
"->",
"switchContent",
"(",
"$",
"item",
"[",
"'lead'",
"]",
",",
"$",
"this",
"->",
"parseExcerpt",
"(",
"$",
"postData",
"->",
"post_content",
")",
")",
";",
"}",
"}",
"else",
"{",
"unset",
"(",
"$",
"item",
")",
";",
"}",
"//Removes empty/unfetchable objects from index",
"if",
"(",
"$",
"item",
"[",
"'link_type'",
"]",
"==",
"\"internal\"",
"&&",
"empty",
"(",
"$",
"item",
"[",
"'title'",
"]",
")",
"&&",
"empty",
"(",
"$",
"item",
"[",
"'lead'",
"]",
")",
"&&",
"empty",
"(",
"$",
"item",
"[",
"'thumbnail'",
"]",
")",
"&&",
"empty",
"(",
"$",
"item",
"[",
"'permalink'",
"]",
")",
")",
"{",
"unset",
"(",
"$",
"items",
"[",
"$",
"key",
"]",
")",
";",
"}",
"}",
"}",
"return",
"$",
"items",
";",
"}"
]
| Get additional data for index posts
@param array $items Items in index
@return array Updated items | [
"Get",
"additional",
"data",
"for",
"index",
"posts"
]
| db4fcde30ba5db4fac9c8b3c3475c8229b50271d | https://github.com/helsingborg-stad/Modularity/blob/db4fcde30ba5db4fac9c8b3c3475c8229b50271d/source/php/Module/Index/Index.php#L52-L92 | train |
helsingborg-stad/Modularity | source/php/Module/Index/Index.php | Index.parseExcerpt | public function parseExcerpt($postContent)
{
if (strpos($postContent, "<!--more-->")) {
return strip_tags(substr($postContent, 0, strpos($postContent, "<!--more-->")));
}
return wp_trim_words(strip_tags(apply_filters('get_the_excerpt', $postContent)), 55, "…");
} | php | public function parseExcerpt($postContent)
{
if (strpos($postContent, "<!--more-->")) {
return strip_tags(substr($postContent, 0, strpos($postContent, "<!--more-->")));
}
return wp_trim_words(strip_tags(apply_filters('get_the_excerpt', $postContent)), 55, "…");
} | [
"public",
"function",
"parseExcerpt",
"(",
"$",
"postContent",
")",
"{",
"if",
"(",
"strpos",
"(",
"$",
"postContent",
",",
"\"<!--more-->\"",
")",
")",
"{",
"return",
"strip_tags",
"(",
"substr",
"(",
"$",
"postContent",
",",
"0",
",",
"strpos",
"(",
"$",
"postContent",
",",
"\"<!--more-->\"",
")",
")",
")",
";",
"}",
"return",
"wp_trim_words",
"(",
"strip_tags",
"(",
"apply_filters",
"(",
"'get_the_excerpt'",
",",
"$",
"postContent",
")",
")",
",",
"55",
",",
"\"…\"",
")",
";",
"}"
]
| Parse the excerpt from the content.
@param [string] $preferdValue [The value preferd to output]
@return [string] $secondaryValue [The secondary fallback value] | [
"Parse",
"the",
"excerpt",
"from",
"the",
"content",
"."
]
| db4fcde30ba5db4fac9c8b3c3475c8229b50271d | https://github.com/helsingborg-stad/Modularity/blob/db4fcde30ba5db4fac9c8b3c3475c8229b50271d/source/php/Module/Index/Index.php#L100-L106 | train |
helsingborg-stad/Modularity | source/php/Module/Index/Index.php | Index.getThumbnail | public function getThumbnail($item)
{
if ($item['image_display'] == 'custom' || $item['link_type'] == 'external') {
return wp_get_attachment_image_src(
$item['custom_image']['ID'],
apply_filters(
'Modularity/index/image',
municipio_to_aspect_ratio('16:9', $this->thumbnailSize),
$this->args
)
);
} elseif ($item['image_display'] == 'false') {
return false;
}
return wp_get_attachment_image_src(
get_post_thumbnail_id($item['page']->ID),
apply_filters(
'Modularity/index/image',
municipio_to_aspect_ratio('16:9', $this->thumbnailSize),
$this->args
)
);
} | php | public function getThumbnail($item)
{
if ($item['image_display'] == 'custom' || $item['link_type'] == 'external') {
return wp_get_attachment_image_src(
$item['custom_image']['ID'],
apply_filters(
'Modularity/index/image',
municipio_to_aspect_ratio('16:9', $this->thumbnailSize),
$this->args
)
);
} elseif ($item['image_display'] == 'false') {
return false;
}
return wp_get_attachment_image_src(
get_post_thumbnail_id($item['page']->ID),
apply_filters(
'Modularity/index/image',
municipio_to_aspect_ratio('16:9', $this->thumbnailSize),
$this->args
)
);
} | [
"public",
"function",
"getThumbnail",
"(",
"$",
"item",
")",
"{",
"if",
"(",
"$",
"item",
"[",
"'image_display'",
"]",
"==",
"'custom'",
"||",
"$",
"item",
"[",
"'link_type'",
"]",
"==",
"'external'",
")",
"{",
"return",
"wp_get_attachment_image_src",
"(",
"$",
"item",
"[",
"'custom_image'",
"]",
"[",
"'ID'",
"]",
",",
"apply_filters",
"(",
"'Modularity/index/image'",
",",
"municipio_to_aspect_ratio",
"(",
"'16:9'",
",",
"$",
"this",
"->",
"thumbnailSize",
")",
",",
"$",
"this",
"->",
"args",
")",
")",
";",
"}",
"elseif",
"(",
"$",
"item",
"[",
"'image_display'",
"]",
"==",
"'false'",
")",
"{",
"return",
"false",
";",
"}",
"return",
"wp_get_attachment_image_src",
"(",
"get_post_thumbnail_id",
"(",
"$",
"item",
"[",
"'page'",
"]",
"->",
"ID",
")",
",",
"apply_filters",
"(",
"'Modularity/index/image'",
",",
"municipio_to_aspect_ratio",
"(",
"'16:9'",
",",
"$",
"this",
"->",
"thumbnailSize",
")",
",",
"$",
"this",
"->",
"args",
")",
")",
";",
"}"
]
| Get post thumbnail in correct size
@param [type] $item [description]
@return [type] [description] | [
"Get",
"post",
"thumbnail",
"in",
"correct",
"size"
]
| db4fcde30ba5db4fac9c8b3c3475c8229b50271d | https://github.com/helsingborg-stad/Modularity/blob/db4fcde30ba5db4fac9c8b3c3475c8229b50271d/source/php/Module/Index/Index.php#L128-L151 | train |
helsingborg-stad/Modularity | source/php/Module/Index/Index.php | Index.getImageDimension | public function getImageDimension($columnClass)
{
switch ($columnClass) {
case "grid-md-12": // 1-col
$this->thumbnailSize = array(1200, 900);
return $this->thumbnailSize;
case "grid-md-6": // 2-col
$this->thumbnailSize = array(800, 600);
return $this->thumbnailSize;
default:
$this->thumbnailSize = array(400, 300);
return $this->thumbnailSize;
}
} | php | public function getImageDimension($columnClass)
{
switch ($columnClass) {
case "grid-md-12": // 1-col
$this->thumbnailSize = array(1200, 900);
return $this->thumbnailSize;
case "grid-md-6": // 2-col
$this->thumbnailSize = array(800, 600);
return $this->thumbnailSize;
default:
$this->thumbnailSize = array(400, 300);
return $this->thumbnailSize;
}
} | [
"public",
"function",
"getImageDimension",
"(",
"$",
"columnClass",
")",
"{",
"switch",
"(",
"$",
"columnClass",
")",
"{",
"case",
"\"grid-md-12\"",
":",
"// 1-col",
"$",
"this",
"->",
"thumbnailSize",
"=",
"array",
"(",
"1200",
",",
"900",
")",
";",
"return",
"$",
"this",
"->",
"thumbnailSize",
";",
"case",
"\"grid-md-6\"",
":",
"// 2-col",
"$",
"this",
"->",
"thumbnailSize",
"=",
"array",
"(",
"800",
",",
"600",
")",
";",
"return",
"$",
"this",
"->",
"thumbnailSize",
";",
"default",
":",
"$",
"this",
"->",
"thumbnailSize",
"=",
"array",
"(",
"400",
",",
"300",
")",
";",
"return",
"$",
"this",
"->",
"thumbnailSize",
";",
"}",
"}"
]
| Get wanted image dimensions based on column class
@param string $columnClass
@return array | [
"Get",
"wanted",
"image",
"dimensions",
"based",
"on",
"column",
"class"
]
| db4fcde30ba5db4fac9c8b3c3475c8229b50271d | https://github.com/helsingborg-stad/Modularity/blob/db4fcde30ba5db4fac9c8b3c3475c8229b50271d/source/php/Module/Index/Index.php#L158-L173 | train |
helsingborg-stad/Modularity | source/php/Module/Index/Index.php | Index.postObjectQuery | public function postObjectQuery($args, $field, $post_id)
{
$post_types = array('post', 'page');
$custom_post_types = get_field('avabile_dynamic_post_types', 'option');
if (is_array($custom_post_types) && !empty($custom_post_types)) {
foreach ($custom_post_types as $post_type) {
$post_types[] = sanitize_title(substr($post_type['post_type_name'], 0, 19));
}
}
$args['post_type'] = $post_types;
return $args;
} | php | public function postObjectQuery($args, $field, $post_id)
{
$post_types = array('post', 'page');
$custom_post_types = get_field('avabile_dynamic_post_types', 'option');
if (is_array($custom_post_types) && !empty($custom_post_types)) {
foreach ($custom_post_types as $post_type) {
$post_types[] = sanitize_title(substr($post_type['post_type_name'], 0, 19));
}
}
$args['post_type'] = $post_types;
return $args;
} | [
"public",
"function",
"postObjectQuery",
"(",
"$",
"args",
",",
"$",
"field",
",",
"$",
"post_id",
")",
"{",
"$",
"post_types",
"=",
"array",
"(",
"'post'",
",",
"'page'",
")",
";",
"$",
"custom_post_types",
"=",
"get_field",
"(",
"'avabile_dynamic_post_types'",
",",
"'option'",
")",
";",
"if",
"(",
"is_array",
"(",
"$",
"custom_post_types",
")",
"&&",
"!",
"empty",
"(",
"$",
"custom_post_types",
")",
")",
"{",
"foreach",
"(",
"$",
"custom_post_types",
"as",
"$",
"post_type",
")",
"{",
"$",
"post_types",
"[",
"]",
"=",
"sanitize_title",
"(",
"substr",
"(",
"$",
"post_type",
"[",
"'post_type_name'",
"]",
",",
"0",
",",
"19",
")",
")",
";",
"}",
"}",
"$",
"args",
"[",
"'post_type'",
"]",
"=",
"$",
"post_types",
";",
"return",
"$",
"args",
";",
"}"
]
| Return results from certain post types
@param array $args the WP_Query args used to find choices
@param array $field the field array containing all attributes & settings
@param int $post_id the current post ID being edited
@return array updated WP_Query args | [
"Return",
"results",
"from",
"certain",
"post",
"types"
]
| db4fcde30ba5db4fac9c8b3c3475c8229b50271d | https://github.com/helsingborg-stad/Modularity/blob/db4fcde30ba5db4fac9c8b3c3475c8229b50271d/source/php/Module/Index/Index.php#L182-L196 | train |
helsingborg-stad/Modularity | source/php/Editor/Thickbox.php | Thickbox.addJsVariables | public function addJsVariables()
{
global $current_screen;
global $post;
global $archive;
$id = isset($post->ID) ? $post->ID : "'" . $archive . "'";
if (substr($current_screen->post_type, 0, 4) == 'mod-' && ($current_screen->action == 'add' || $current_screen->action == '')) {
echo "
<script>
var modularity_post_id = ". $id . ";
var modularity_post_action = '" . $current_screen->action . "';
</script>
";
}
} | php | public function addJsVariables()
{
global $current_screen;
global $post;
global $archive;
$id = isset($post->ID) ? $post->ID : "'" . $archive . "'";
if (substr($current_screen->post_type, 0, 4) == 'mod-' && ($current_screen->action == 'add' || $current_screen->action == '')) {
echo "
<script>
var modularity_post_id = ". $id . ";
var modularity_post_action = '" . $current_screen->action . "';
</script>
";
}
} | [
"public",
"function",
"addJsVariables",
"(",
")",
"{",
"global",
"$",
"current_screen",
";",
"global",
"$",
"post",
";",
"global",
"$",
"archive",
";",
"$",
"id",
"=",
"isset",
"(",
"$",
"post",
"->",
"ID",
")",
"?",
"$",
"post",
"->",
"ID",
":",
"\"'\"",
".",
"$",
"archive",
".",
"\"'\"",
";",
"if",
"(",
"substr",
"(",
"$",
"current_screen",
"->",
"post_type",
",",
"0",
",",
"4",
")",
"==",
"'mod-'",
"&&",
"(",
"$",
"current_screen",
"->",
"action",
"==",
"'add'",
"||",
"$",
"current_screen",
"->",
"action",
"==",
"''",
")",
")",
"{",
"echo",
"\"\n <script>\n var modularity_post_id = \"",
".",
"$",
"id",
".",
"\";\n var modularity_post_action = '\"",
".",
"$",
"current_screen",
"->",
"action",
".",
"\"';\n </script>\n \"",
";",
"}",
"}"
]
| Adds required javascript variables to the thickbox page
@return void | [
"Adds",
"required",
"javascript",
"variables",
"to",
"the",
"thickbox",
"page"
]
| db4fcde30ba5db4fac9c8b3c3475c8229b50271d | https://github.com/helsingborg-stad/Modularity/blob/db4fcde30ba5db4fac9c8b3c3475c8229b50271d/source/php/Editor/Thickbox.php#L44-L60 | train |
helsingborg-stad/Modularity | source/php/Editor/Thickbox.php | Thickbox.enqueue | public function enqueue()
{
// Script
wp_register_script('modularity-thickbox', MODULARITY_URL . '/dist/js/modularity-editor-modal.' . \Modularity\App::$assetSuffix . '.js', false, '1.0.0', true);
wp_enqueue_script('modularity-thickbox');
// Style
wp_register_style(
'modularity-thickbox',
MODULARITY_URL . '/dist/css/modularity-thickbox-edit.' . \Modularity\App::$assetSuffix . '.css',
false,
'1.0.0'
);
wp_enqueue_style('modularity-thickbox');
} | php | public function enqueue()
{
// Script
wp_register_script('modularity-thickbox', MODULARITY_URL . '/dist/js/modularity-editor-modal.' . \Modularity\App::$assetSuffix . '.js', false, '1.0.0', true);
wp_enqueue_script('modularity-thickbox');
// Style
wp_register_style(
'modularity-thickbox',
MODULARITY_URL . '/dist/css/modularity-thickbox-edit.' . \Modularity\App::$assetSuffix . '.css',
false,
'1.0.0'
);
wp_enqueue_style('modularity-thickbox');
} | [
"public",
"function",
"enqueue",
"(",
")",
"{",
"// Script",
"wp_register_script",
"(",
"'modularity-thickbox'",
",",
"MODULARITY_URL",
".",
"'/dist/js/modularity-editor-modal.'",
".",
"\\",
"Modularity",
"\\",
"App",
"::",
"$",
"assetSuffix",
".",
"'.js'",
",",
"false",
",",
"'1.0.0'",
",",
"true",
")",
";",
"wp_enqueue_script",
"(",
"'modularity-thickbox'",
")",
";",
"// Style",
"wp_register_style",
"(",
"'modularity-thickbox'",
",",
"MODULARITY_URL",
".",
"'/dist/css/modularity-thickbox-edit.'",
".",
"\\",
"Modularity",
"\\",
"App",
"::",
"$",
"assetSuffix",
".",
"'.css'",
",",
"false",
",",
"'1.0.0'",
")",
";",
"wp_enqueue_style",
"(",
"'modularity-thickbox'",
")",
";",
"}"
]
| Enqueue scripts and styles specific for the Thickbox content
@return void | [
"Enqueue",
"scripts",
"and",
"styles",
"specific",
"for",
"the",
"Thickbox",
"content"
]
| db4fcde30ba5db4fac9c8b3c3475c8229b50271d | https://github.com/helsingborg-stad/Modularity/blob/db4fcde30ba5db4fac9c8b3c3475c8229b50271d/source/php/Editor/Thickbox.php#L66-L81 | train |
helsingborg-stad/Modularity | source/php/Helper/Post.php | Post.getPostTemplate | public static function getPostTemplate($id = null, $trim = false)
{
if ($archive = self::isArchive()) {
return $archive;
}
global $post;
// If $post is empty try to fetc post from querystring
if (!$post && isset($_GET['id']) && is_numeric($_GET['id'])) {
$post = get_post($_GET['id']);
if (!$post) {
throw new \Error('The requested post was not found.');
}
}
if (!$post) {
return isset($_GET['id']) && !empty($_GET['id']) ? $_GET['id'] : $archive;
}
// If post is set, fetch the template
$template = get_page_template_slug($post->ID);
// If this is the front page and the template is set to page.php or page.blade.php default to just "page"
if ($post->ID === (int)get_option('page_on_front') && in_array($template, array('page.php', 'page.blade.php'))) {
return 'page';
}
if (!$template) {
$template = self::detectCoreTemplate($post);
}
$template = $trim ? str_replace('.blade.php', '', $template) : $template;
return $template;
} | php | public static function getPostTemplate($id = null, $trim = false)
{
if ($archive = self::isArchive()) {
return $archive;
}
global $post;
// If $post is empty try to fetc post from querystring
if (!$post && isset($_GET['id']) && is_numeric($_GET['id'])) {
$post = get_post($_GET['id']);
if (!$post) {
throw new \Error('The requested post was not found.');
}
}
if (!$post) {
return isset($_GET['id']) && !empty($_GET['id']) ? $_GET['id'] : $archive;
}
// If post is set, fetch the template
$template = get_page_template_slug($post->ID);
// If this is the front page and the template is set to page.php or page.blade.php default to just "page"
if ($post->ID === (int)get_option('page_on_front') && in_array($template, array('page.php', 'page.blade.php'))) {
return 'page';
}
if (!$template) {
$template = self::detectCoreTemplate($post);
}
$template = $trim ? str_replace('.blade.php', '', $template) : $template;
return $template;
} | [
"public",
"static",
"function",
"getPostTemplate",
"(",
"$",
"id",
"=",
"null",
",",
"$",
"trim",
"=",
"false",
")",
"{",
"if",
"(",
"$",
"archive",
"=",
"self",
"::",
"isArchive",
"(",
")",
")",
"{",
"return",
"$",
"archive",
";",
"}",
"global",
"$",
"post",
";",
"// If $post is empty try to fetc post from querystring",
"if",
"(",
"!",
"$",
"post",
"&&",
"isset",
"(",
"$",
"_GET",
"[",
"'id'",
"]",
")",
"&&",
"is_numeric",
"(",
"$",
"_GET",
"[",
"'id'",
"]",
")",
")",
"{",
"$",
"post",
"=",
"get_post",
"(",
"$",
"_GET",
"[",
"'id'",
"]",
")",
";",
"if",
"(",
"!",
"$",
"post",
")",
"{",
"throw",
"new",
"\\",
"Error",
"(",
"'The requested post was not found.'",
")",
";",
"}",
"}",
"if",
"(",
"!",
"$",
"post",
")",
"{",
"return",
"isset",
"(",
"$",
"_GET",
"[",
"'id'",
"]",
")",
"&&",
"!",
"empty",
"(",
"$",
"_GET",
"[",
"'id'",
"]",
")",
"?",
"$",
"_GET",
"[",
"'id'",
"]",
":",
"$",
"archive",
";",
"}",
"// If post is set, fetch the template",
"$",
"template",
"=",
"get_page_template_slug",
"(",
"$",
"post",
"->",
"ID",
")",
";",
"// If this is the front page and the template is set to page.php or page.blade.php default to just \"page\"",
"if",
"(",
"$",
"post",
"->",
"ID",
"===",
"(",
"int",
")",
"get_option",
"(",
"'page_on_front'",
")",
"&&",
"in_array",
"(",
"$",
"template",
",",
"array",
"(",
"'page.php'",
",",
"'page.blade.php'",
")",
")",
")",
"{",
"return",
"'page'",
";",
"}",
"if",
"(",
"!",
"$",
"template",
")",
"{",
"$",
"template",
"=",
"self",
"::",
"detectCoreTemplate",
"(",
"$",
"post",
")",
";",
"}",
"$",
"template",
"=",
"$",
"trim",
"?",
"str_replace",
"(",
"'.blade.php'",
",",
"''",
",",
"$",
"template",
")",
":",
"$",
"template",
";",
"return",
"$",
"template",
";",
"}"
]
| Gets the post template of the current editor page
@return string Template slug | [
"Gets",
"the",
"post",
"template",
"of",
"the",
"current",
"editor",
"page"
]
| db4fcde30ba5db4fac9c8b3c3475c8229b50271d | https://github.com/helsingborg-stad/Modularity/blob/db4fcde30ba5db4fac9c8b3c3475c8229b50271d/source/php/Helper/Post.php#L35-L71 | train |
helsingborg-stad/Modularity | source/php/Helper/Post.php | Post.detectCoreTemplate | public static function detectCoreTemplate($post)
{
if ((int)get_option('page_on_front') == (int)$post->ID) {
return \Modularity\Helper\Wp::findCoreTemplates(array(
'front-page',
'page'
));
}
switch ($post->post_type) {
case 'post':
return 'single';
break;
case 'page':
return 'page';
break;
default:
return \Modularity\Helper\Wp::findCoreTemplates(array(
'single-' . $post->post_type,
'single',
'page'
));
break;
}
return 'index';
} | php | public static function detectCoreTemplate($post)
{
if ((int)get_option('page_on_front') == (int)$post->ID) {
return \Modularity\Helper\Wp::findCoreTemplates(array(
'front-page',
'page'
));
}
switch ($post->post_type) {
case 'post':
return 'single';
break;
case 'page':
return 'page';
break;
default:
return \Modularity\Helper\Wp::findCoreTemplates(array(
'single-' . $post->post_type,
'single',
'page'
));
break;
}
return 'index';
} | [
"public",
"static",
"function",
"detectCoreTemplate",
"(",
"$",
"post",
")",
"{",
"if",
"(",
"(",
"int",
")",
"get_option",
"(",
"'page_on_front'",
")",
"==",
"(",
"int",
")",
"$",
"post",
"->",
"ID",
")",
"{",
"return",
"\\",
"Modularity",
"\\",
"Helper",
"\\",
"Wp",
"::",
"findCoreTemplates",
"(",
"array",
"(",
"'front-page'",
",",
"'page'",
")",
")",
";",
"}",
"switch",
"(",
"$",
"post",
"->",
"post_type",
")",
"{",
"case",
"'post'",
":",
"return",
"'single'",
";",
"break",
";",
"case",
"'page'",
":",
"return",
"'page'",
";",
"break",
";",
"default",
":",
"return",
"\\",
"Modularity",
"\\",
"Helper",
"\\",
"Wp",
"::",
"findCoreTemplates",
"(",
"array",
"(",
"'single-'",
".",
"$",
"post",
"->",
"post_type",
",",
"'single'",
",",
"'page'",
")",
")",
";",
"break",
";",
"}",
"return",
"'index'",
";",
"}"
]
| Detects core templates
@return string Template | [
"Detects",
"core",
"templates"
]
| db4fcde30ba5db4fac9c8b3c3475c8229b50271d | https://github.com/helsingborg-stad/Modularity/blob/db4fcde30ba5db4fac9c8b3c3475c8229b50271d/source/php/Helper/Post.php#L77-L105 | train |
helsingborg-stad/Modularity | source/php/Helper/Post.php | Post.isArchive | public static function isArchive()
{
global $archive;
global $post;
if (defined('DOING_AJAX') && DOING_AJAX) {
$archive = !is_numeric($_POST['id']) ? $_POST['id'] : '';
}
if (substr($archive, 0, 8) == 'archive-' || is_search()) {
return $archive;
}
if (is_archive() && (is_object($post) && $post->post_type == 'post')) {
return 'archive';
} elseif (is_search() || (is_object($post) && is_post_type_archive($post->post_type))) {
return 'archive-' . $post->post_type;
} elseif (isset($_GET['id']) && $_GET['id'] == 'author') {
return 'author';
}
return false;
} | php | public static function isArchive()
{
global $archive;
global $post;
if (defined('DOING_AJAX') && DOING_AJAX) {
$archive = !is_numeric($_POST['id']) ? $_POST['id'] : '';
}
if (substr($archive, 0, 8) == 'archive-' || is_search()) {
return $archive;
}
if (is_archive() && (is_object($post) && $post->post_type == 'post')) {
return 'archive';
} elseif (is_search() || (is_object($post) && is_post_type_archive($post->post_type))) {
return 'archive-' . $post->post_type;
} elseif (isset($_GET['id']) && $_GET['id'] == 'author') {
return 'author';
}
return false;
} | [
"public",
"static",
"function",
"isArchive",
"(",
")",
"{",
"global",
"$",
"archive",
";",
"global",
"$",
"post",
";",
"if",
"(",
"defined",
"(",
"'DOING_AJAX'",
")",
"&&",
"DOING_AJAX",
")",
"{",
"$",
"archive",
"=",
"!",
"is_numeric",
"(",
"$",
"_POST",
"[",
"'id'",
"]",
")",
"?",
"$",
"_POST",
"[",
"'id'",
"]",
":",
"''",
";",
"}",
"if",
"(",
"substr",
"(",
"$",
"archive",
",",
"0",
",",
"8",
")",
"==",
"'archive-'",
"||",
"is_search",
"(",
")",
")",
"{",
"return",
"$",
"archive",
";",
"}",
"if",
"(",
"is_archive",
"(",
")",
"&&",
"(",
"is_object",
"(",
"$",
"post",
")",
"&&",
"$",
"post",
"->",
"post_type",
"==",
"'post'",
")",
")",
"{",
"return",
"'archive'",
";",
"}",
"elseif",
"(",
"is_search",
"(",
")",
"||",
"(",
"is_object",
"(",
"$",
"post",
")",
"&&",
"is_post_type_archive",
"(",
"$",
"post",
"->",
"post_type",
")",
")",
")",
"{",
"return",
"'archive-'",
".",
"$",
"post",
"->",
"post_type",
";",
"}",
"elseif",
"(",
"isset",
"(",
"$",
"_GET",
"[",
"'id'",
"]",
")",
"&&",
"$",
"_GET",
"[",
"'id'",
"]",
"==",
"'author'",
")",
"{",
"return",
"'author'",
";",
"}",
"return",
"false",
";",
"}"
]
| Verifies if the current page is an archive or search result page
@return boolean | [
"Verifies",
"if",
"the",
"current",
"page",
"is",
"an",
"archive",
"or",
"search",
"result",
"page"
]
| db4fcde30ba5db4fac9c8b3c3475c8229b50271d | https://github.com/helsingborg-stad/Modularity/blob/db4fcde30ba5db4fac9c8b3c3475c8229b50271d/source/php/Helper/Post.php#L111-L133 | train |
helsingborg-stad/Modularity | source/php/Module/Posts/Posts.php | Posts.getSortableMetaKeys | public function getSortableMetaKeys()
{
if (!isset($_POST['posttype']) || empty($_POST['posttype'])) {
echo '0';
die();
}
$meta = \Modularity\Helper\Post::getPosttypeMetaKeys($_POST['posttype']);
$response = array(
'meta_keys' => $meta,
'sort_curr' => get_field('posts_sort_by', $_POST['post']),
'filter_curr' => get_field('posts_meta_key', $_POST['post']),
);
echo json_encode($response);
die();
} | php | public function getSortableMetaKeys()
{
if (!isset($_POST['posttype']) || empty($_POST['posttype'])) {
echo '0';
die();
}
$meta = \Modularity\Helper\Post::getPosttypeMetaKeys($_POST['posttype']);
$response = array(
'meta_keys' => $meta,
'sort_curr' => get_field('posts_sort_by', $_POST['post']),
'filter_curr' => get_field('posts_meta_key', $_POST['post']),
);
echo json_encode($response);
die();
} | [
"public",
"function",
"getSortableMetaKeys",
"(",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"_POST",
"[",
"'posttype'",
"]",
")",
"||",
"empty",
"(",
"$",
"_POST",
"[",
"'posttype'",
"]",
")",
")",
"{",
"echo",
"'0'",
";",
"die",
"(",
")",
";",
"}",
"$",
"meta",
"=",
"\\",
"Modularity",
"\\",
"Helper",
"\\",
"Post",
"::",
"getPosttypeMetaKeys",
"(",
"$",
"_POST",
"[",
"'posttype'",
"]",
")",
";",
"$",
"response",
"=",
"array",
"(",
"'meta_keys'",
"=>",
"$",
"meta",
",",
"'sort_curr'",
"=>",
"get_field",
"(",
"'posts_sort_by'",
",",
"$",
"_POST",
"[",
"'post'",
"]",
")",
",",
"'filter_curr'",
"=>",
"get_field",
"(",
"'posts_meta_key'",
",",
"$",
"_POST",
"[",
"'post'",
"]",
")",
",",
")",
";",
"echo",
"json_encode",
"(",
"$",
"response",
")",
";",
"die",
"(",
")",
";",
"}"
]
| AJAX CALLBACK
Get metakeys which we can use to sort the posts
@return void | [
"AJAX",
"CALLBACK",
"Get",
"metakeys",
"which",
"we",
"can",
"use",
"to",
"sort",
"the",
"posts"
]
| db4fcde30ba5db4fac9c8b3c3475c8229b50271d | https://github.com/helsingborg-stad/Modularity/blob/db4fcde30ba5db4fac9c8b3c3475c8229b50271d/source/php/Module/Posts/Posts.php#L384-L401 | train |
helsingborg-stad/Modularity | source/php/Module/Posts/Posts.php | Posts.getTaxonomyTypes | public function getTaxonomyTypes()
{
if (!isset($_POST['posttype']) || empty($_POST['posttype'])) {
echo '0';
die();
}
$post = $_POST['post'];
$result = array(
'types' => get_object_taxonomies($_POST['posttype'], 'object'),
'curr' => get_field('posts_taxonomy_type', $post)
);
echo json_encode($result);
die();
} | php | public function getTaxonomyTypes()
{
if (!isset($_POST['posttype']) || empty($_POST['posttype'])) {
echo '0';
die();
}
$post = $_POST['post'];
$result = array(
'types' => get_object_taxonomies($_POST['posttype'], 'object'),
'curr' => get_field('posts_taxonomy_type', $post)
);
echo json_encode($result);
die();
} | [
"public",
"function",
"getTaxonomyTypes",
"(",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"_POST",
"[",
"'posttype'",
"]",
")",
"||",
"empty",
"(",
"$",
"_POST",
"[",
"'posttype'",
"]",
")",
")",
"{",
"echo",
"'0'",
";",
"die",
"(",
")",
";",
"}",
"$",
"post",
"=",
"$",
"_POST",
"[",
"'post'",
"]",
";",
"$",
"result",
"=",
"array",
"(",
"'types'",
"=>",
"get_object_taxonomies",
"(",
"$",
"_POST",
"[",
"'posttype'",
"]",
",",
"'object'",
")",
",",
"'curr'",
"=>",
"get_field",
"(",
"'posts_taxonomy_type'",
",",
"$",
"post",
")",
")",
";",
"echo",
"json_encode",
"(",
"$",
"result",
")",
";",
"die",
"(",
")",
";",
"}"
]
| AJAX CALLBACK
Get availabel taxonomies for a post type
@return void | [
"AJAX",
"CALLBACK",
"Get",
"availabel",
"taxonomies",
"for",
"a",
"post",
"type"
]
| db4fcde30ba5db4fac9c8b3c3475c8229b50271d | https://github.com/helsingborg-stad/Modularity/blob/db4fcde30ba5db4fac9c8b3c3475c8229b50271d/source/php/Module/Posts/Posts.php#L408-L424 | train |
helsingborg-stad/Modularity | source/php/Module/Posts/Posts.php | Posts.getTaxonomyValues | public function getTaxonomyValues()
{
if (!isset($_POST['tax']) || empty($_POST['tax'])) {
echo '0';
die();
}
$taxonomy = $_POST['tax'];
$post = $_POST['post'];
$result = array(
'tax' => get_terms($taxonomy, array(
'hide_empty' => false,
)),
'curr' => get_field('posts_taxonomy_value', $post)
);
echo json_encode($result);
die();
} | php | public function getTaxonomyValues()
{
if (!isset($_POST['tax']) || empty($_POST['tax'])) {
echo '0';
die();
}
$taxonomy = $_POST['tax'];
$post = $_POST['post'];
$result = array(
'tax' => get_terms($taxonomy, array(
'hide_empty' => false,
)),
'curr' => get_field('posts_taxonomy_value', $post)
);
echo json_encode($result);
die();
} | [
"public",
"function",
"getTaxonomyValues",
"(",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"_POST",
"[",
"'tax'",
"]",
")",
"||",
"empty",
"(",
"$",
"_POST",
"[",
"'tax'",
"]",
")",
")",
"{",
"echo",
"'0'",
";",
"die",
"(",
")",
";",
"}",
"$",
"taxonomy",
"=",
"$",
"_POST",
"[",
"'tax'",
"]",
";",
"$",
"post",
"=",
"$",
"_POST",
"[",
"'post'",
"]",
";",
"$",
"result",
"=",
"array",
"(",
"'tax'",
"=>",
"get_terms",
"(",
"$",
"taxonomy",
",",
"array",
"(",
"'hide_empty'",
"=>",
"false",
",",
")",
")",
",",
"'curr'",
"=>",
"get_field",
"(",
"'posts_taxonomy_value'",
",",
"$",
"post",
")",
")",
";",
"echo",
"json_encode",
"(",
"$",
"result",
")",
";",
"die",
"(",
")",
";",
"}"
]
| AJAX CALLBACK
Gets a taxonomies available values
@return void | [
"AJAX",
"CALLBACK",
"Gets",
"a",
"taxonomies",
"available",
"values"
]
| db4fcde30ba5db4fac9c8b3c3475c8229b50271d | https://github.com/helsingborg-stad/Modularity/blob/db4fcde30ba5db4fac9c8b3c3475c8229b50271d/source/php/Module/Posts/Posts.php#L431-L450 | train |
helsingborg-stad/Modularity | source/php/Module/Posts/Posts.php | Posts.saveColumnFields | public function saveColumnFields($postId)
{
//Meta key
$metaKey = "modularity-mod-posts-expandable-list";
//Bail early if autosave
if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
return false;
}
//Bail early if cron
if (defined('DOING_CRON') && DOING_CRON) {
return false;
}
//Bail early if not a post request
if (!isset($_POST) || (is_array($_POST) && empty($_POST)) || !is_array($_POST)) {
return false;
}
//Update if nonce verification succeed
if (isset($_POST['modularity_post_columns']) && wp_verify_nonce($_POST['modularity_post_columns'],
'save_columns')) {
//Delete if not posted data
if (!isset($_POST[$metaKey])) {
delete_post_meta($postId, $metaKey);
return;
}
//Save meta data
update_post_meta($postId, $metaKey, $_POST[$metaKey]);
}
} | php | public function saveColumnFields($postId)
{
//Meta key
$metaKey = "modularity-mod-posts-expandable-list";
//Bail early if autosave
if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
return false;
}
//Bail early if cron
if (defined('DOING_CRON') && DOING_CRON) {
return false;
}
//Bail early if not a post request
if (!isset($_POST) || (is_array($_POST) && empty($_POST)) || !is_array($_POST)) {
return false;
}
//Update if nonce verification succeed
if (isset($_POST['modularity_post_columns']) && wp_verify_nonce($_POST['modularity_post_columns'],
'save_columns')) {
//Delete if not posted data
if (!isset($_POST[$metaKey])) {
delete_post_meta($postId, $metaKey);
return;
}
//Save meta data
update_post_meta($postId, $metaKey, $_POST[$metaKey]);
}
} | [
"public",
"function",
"saveColumnFields",
"(",
"$",
"postId",
")",
"{",
"//Meta key",
"$",
"metaKey",
"=",
"\"modularity-mod-posts-expandable-list\"",
";",
"//Bail early if autosave",
"if",
"(",
"defined",
"(",
"'DOING_AUTOSAVE'",
")",
"&&",
"DOING_AUTOSAVE",
")",
"{",
"return",
"false",
";",
"}",
"//Bail early if cron",
"if",
"(",
"defined",
"(",
"'DOING_CRON'",
")",
"&&",
"DOING_CRON",
")",
"{",
"return",
"false",
";",
"}",
"//Bail early if not a post request",
"if",
"(",
"!",
"isset",
"(",
"$",
"_POST",
")",
"||",
"(",
"is_array",
"(",
"$",
"_POST",
")",
"&&",
"empty",
"(",
"$",
"_POST",
")",
")",
"||",
"!",
"is_array",
"(",
"$",
"_POST",
")",
")",
"{",
"return",
"false",
";",
"}",
"//Update if nonce verification succeed",
"if",
"(",
"isset",
"(",
"$",
"_POST",
"[",
"'modularity_post_columns'",
"]",
")",
"&&",
"wp_verify_nonce",
"(",
"$",
"_POST",
"[",
"'modularity_post_columns'",
"]",
",",
"'save_columns'",
")",
")",
"{",
"//Delete if not posted data",
"if",
"(",
"!",
"isset",
"(",
"$",
"_POST",
"[",
"$",
"metaKey",
"]",
")",
")",
"{",
"delete_post_meta",
"(",
"$",
"postId",
",",
"$",
"metaKey",
")",
";",
"return",
";",
"}",
"//Save meta data",
"update_post_meta",
"(",
"$",
"postId",
",",
"$",
"metaKey",
",",
"$",
"_POST",
"[",
"$",
"metaKey",
"]",
")",
";",
"}",
"}"
]
| Saves column names if exandable list template is used
@param int $postId The id of the post
@return void | [
"Saves",
"column",
"names",
"if",
"exandable",
"list",
"template",
"is",
"used"
]
| db4fcde30ba5db4fac9c8b3c3475c8229b50271d | https://github.com/helsingborg-stad/Modularity/blob/db4fcde30ba5db4fac9c8b3c3475c8229b50271d/source/php/Module/Posts/Posts.php#L457-L489 | train |
helsingborg-stad/Modularity | source/php/Module/Posts/Posts.php | Posts.addColumnFields | public function addColumnFields()
{
global $post;
$screen = get_current_screen();
if (empty($post->post_type) || $screen->base != 'post') {
return;
}
$modules = array();
// If manually picked
if ($newModules = $this->checkIfManuallyPicked($post->ID)) {
$modules = array_merge($modules, $newModules);
}
// If post type
if ($newModules = $this->checkIfPostType($post->ID)) {
$modules = array_merge($modules, $newModules);
}
// If child
if ($newModules = $this->checkIfChild($post->ID)) {
$modules = array_merge($modules, $newModules);
}
if (empty($modules)) {
return false;
}
$modules = array_filter($modules, function ($item) {
return !wp_is_post_revision($item);
});
$fields = $this->getColumns($modules);
if (!empty($fields)) {
add_meta_box(
'modularity-mod-posts-expandable-list',
__('Modularity expandable list column values', 'modularity'),
array($this, 'columnFieldsMetaBoxContent'),
null,
'normal',
'default',
array($fields)
);
}
} | php | public function addColumnFields()
{
global $post;
$screen = get_current_screen();
if (empty($post->post_type) || $screen->base != 'post') {
return;
}
$modules = array();
// If manually picked
if ($newModules = $this->checkIfManuallyPicked($post->ID)) {
$modules = array_merge($modules, $newModules);
}
// If post type
if ($newModules = $this->checkIfPostType($post->ID)) {
$modules = array_merge($modules, $newModules);
}
// If child
if ($newModules = $this->checkIfChild($post->ID)) {
$modules = array_merge($modules, $newModules);
}
if (empty($modules)) {
return false;
}
$modules = array_filter($modules, function ($item) {
return !wp_is_post_revision($item);
});
$fields = $this->getColumns($modules);
if (!empty($fields)) {
add_meta_box(
'modularity-mod-posts-expandable-list',
__('Modularity expandable list column values', 'modularity'),
array($this, 'columnFieldsMetaBoxContent'),
null,
'normal',
'default',
array($fields)
);
}
} | [
"public",
"function",
"addColumnFields",
"(",
")",
"{",
"global",
"$",
"post",
";",
"$",
"screen",
"=",
"get_current_screen",
"(",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"post",
"->",
"post_type",
")",
"||",
"$",
"screen",
"->",
"base",
"!=",
"'post'",
")",
"{",
"return",
";",
"}",
"$",
"modules",
"=",
"array",
"(",
")",
";",
"// If manually picked",
"if",
"(",
"$",
"newModules",
"=",
"$",
"this",
"->",
"checkIfManuallyPicked",
"(",
"$",
"post",
"->",
"ID",
")",
")",
"{",
"$",
"modules",
"=",
"array_merge",
"(",
"$",
"modules",
",",
"$",
"newModules",
")",
";",
"}",
"// If post type",
"if",
"(",
"$",
"newModules",
"=",
"$",
"this",
"->",
"checkIfPostType",
"(",
"$",
"post",
"->",
"ID",
")",
")",
"{",
"$",
"modules",
"=",
"array_merge",
"(",
"$",
"modules",
",",
"$",
"newModules",
")",
";",
"}",
"// If child",
"if",
"(",
"$",
"newModules",
"=",
"$",
"this",
"->",
"checkIfChild",
"(",
"$",
"post",
"->",
"ID",
")",
")",
"{",
"$",
"modules",
"=",
"array_merge",
"(",
"$",
"modules",
",",
"$",
"newModules",
")",
";",
"}",
"if",
"(",
"empty",
"(",
"$",
"modules",
")",
")",
"{",
"return",
"false",
";",
"}",
"$",
"modules",
"=",
"array_filter",
"(",
"$",
"modules",
",",
"function",
"(",
"$",
"item",
")",
"{",
"return",
"!",
"wp_is_post_revision",
"(",
"$",
"item",
")",
";",
"}",
")",
";",
"$",
"fields",
"=",
"$",
"this",
"->",
"getColumns",
"(",
"$",
"modules",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"fields",
")",
")",
"{",
"add_meta_box",
"(",
"'modularity-mod-posts-expandable-list'",
",",
"__",
"(",
"'Modularity expandable list column values'",
",",
"'modularity'",
")",
",",
"array",
"(",
"$",
"this",
",",
"'columnFieldsMetaBoxContent'",
")",
",",
"null",
",",
"'normal'",
",",
"'default'",
",",
"array",
"(",
"$",
"fields",
")",
")",
";",
"}",
"}"
]
| Check wheather to add expandable list column fields to edit post screeen | [
"Check",
"wheather",
"to",
"add",
"expandable",
"list",
"column",
"fields",
"to",
"edit",
"post",
"screeen"
]
| db4fcde30ba5db4fac9c8b3c3475c8229b50271d | https://github.com/helsingborg-stad/Modularity/blob/db4fcde30ba5db4fac9c8b3c3475c8229b50271d/source/php/Module/Posts/Posts.php#L494-L541 | train |
helsingborg-stad/Modularity | source/php/Module/Posts/Posts.php | Posts.columnFieldsMetaBoxContent | public function columnFieldsMetaBoxContent($post, $args)
{
$fields = $args['args'][0];
$fieldValues = get_post_meta($post->ID, 'modularity-mod-posts-expandable-list', true);
foreach ($fields as $field) {
$fieldSlug = sanitize_title($field);
$value = isset($fieldValues[$fieldSlug]) && !empty($fieldValues[$fieldSlug]) ? $fieldValues[$fieldSlug] : '';
echo '
<p>
<label for="mod-' . $fieldSlug . '">' . $field . ':</label>
<input value="' . $value . '" class="widefat" type="text" name="modularity-mod-posts-expandable-list[' . sanitize_title($field) . ']" id="mod-' . sanitize_title($field) . '">
</p>
';
}
echo wp_nonce_field('save_columns', 'modularity_post_columns');
} | php | public function columnFieldsMetaBoxContent($post, $args)
{
$fields = $args['args'][0];
$fieldValues = get_post_meta($post->ID, 'modularity-mod-posts-expandable-list', true);
foreach ($fields as $field) {
$fieldSlug = sanitize_title($field);
$value = isset($fieldValues[$fieldSlug]) && !empty($fieldValues[$fieldSlug]) ? $fieldValues[$fieldSlug] : '';
echo '
<p>
<label for="mod-' . $fieldSlug . '">' . $field . ':</label>
<input value="' . $value . '" class="widefat" type="text" name="modularity-mod-posts-expandable-list[' . sanitize_title($field) . ']" id="mod-' . sanitize_title($field) . '">
</p>
';
}
echo wp_nonce_field('save_columns', 'modularity_post_columns');
} | [
"public",
"function",
"columnFieldsMetaBoxContent",
"(",
"$",
"post",
",",
"$",
"args",
")",
"{",
"$",
"fields",
"=",
"$",
"args",
"[",
"'args'",
"]",
"[",
"0",
"]",
";",
"$",
"fieldValues",
"=",
"get_post_meta",
"(",
"$",
"post",
"->",
"ID",
",",
"'modularity-mod-posts-expandable-list'",
",",
"true",
")",
";",
"foreach",
"(",
"$",
"fields",
"as",
"$",
"field",
")",
"{",
"$",
"fieldSlug",
"=",
"sanitize_title",
"(",
"$",
"field",
")",
";",
"$",
"value",
"=",
"isset",
"(",
"$",
"fieldValues",
"[",
"$",
"fieldSlug",
"]",
")",
"&&",
"!",
"empty",
"(",
"$",
"fieldValues",
"[",
"$",
"fieldSlug",
"]",
")",
"?",
"$",
"fieldValues",
"[",
"$",
"fieldSlug",
"]",
":",
"''",
";",
"echo",
"'\n <p>\n <label for=\"mod-'",
".",
"$",
"fieldSlug",
".",
"'\">'",
".",
"$",
"field",
".",
"':</label>\n <input value=\"'",
".",
"$",
"value",
".",
"'\" class=\"widefat\" type=\"text\" name=\"modularity-mod-posts-expandable-list['",
".",
"sanitize_title",
"(",
"$",
"field",
")",
".",
"']\" id=\"mod-'",
".",
"sanitize_title",
"(",
"$",
"field",
")",
".",
"'\">\n </p>\n '",
";",
"}",
"echo",
"wp_nonce_field",
"(",
"'save_columns'",
",",
"'modularity_post_columns'",
")",
";",
"}"
]
| Expandable list column value fields metabox content
@param object $post Post object
@param array $args Arguments
@return void | [
"Expandable",
"list",
"column",
"value",
"fields",
"metabox",
"content"
]
| db4fcde30ba5db4fac9c8b3c3475c8229b50271d | https://github.com/helsingborg-stad/Modularity/blob/db4fcde30ba5db4fac9c8b3c3475c8229b50271d/source/php/Module/Posts/Posts.php#L549-L566 | train |
helsingborg-stad/Modularity | source/php/Module/Posts/Posts.php | Posts.getColumns | public function getColumns($posts)
{
$columns = array();
if (is_array($posts)) {
foreach ($posts as $post) {
$values = get_field('posts_list_column_titles', $post);
if (is_array($values)) {
foreach ($values as $value) {
$columns[] = $value['column_header'];
}
}
}
}
return $columns;
} | php | public function getColumns($posts)
{
$columns = array();
if (is_array($posts)) {
foreach ($posts as $post) {
$values = get_field('posts_list_column_titles', $post);
if (is_array($values)) {
foreach ($values as $value) {
$columns[] = $value['column_header'];
}
}
}
}
return $columns;
} | [
"public",
"function",
"getColumns",
"(",
"$",
"posts",
")",
"{",
"$",
"columns",
"=",
"array",
"(",
")",
";",
"if",
"(",
"is_array",
"(",
"$",
"posts",
")",
")",
"{",
"foreach",
"(",
"$",
"posts",
"as",
"$",
"post",
")",
"{",
"$",
"values",
"=",
"get_field",
"(",
"'posts_list_column_titles'",
",",
"$",
"post",
")",
";",
"if",
"(",
"is_array",
"(",
"$",
"values",
")",
")",
"{",
"foreach",
"(",
"$",
"values",
"as",
"$",
"value",
")",
"{",
"$",
"columns",
"[",
"]",
"=",
"$",
"value",
"[",
"'column_header'",
"]",
";",
"}",
"}",
"}",
"}",
"return",
"$",
"columns",
";",
"}"
]
| Get field columns
@param array $posts Post ids
@return array Column names | [
"Get",
"field",
"columns"
]
| db4fcde30ba5db4fac9c8b3c3475c8229b50271d | https://github.com/helsingborg-stad/Modularity/blob/db4fcde30ba5db4fac9c8b3c3475c8229b50271d/source/php/Module/Posts/Posts.php#L573-L590 | train |
helsingborg-stad/Modularity | source/php/Module/Posts/Posts.php | Posts.checkIfManuallyPicked | public function checkIfManuallyPicked($id)
{
global $wpdb;
$result = $wpdb->get_results("
SELECT *
FROM $wpdb->postmeta
WHERE meta_key = 'posts_data_posts'
AND meta_value LIKE '%\"{$id}\"%'
", OBJECT);
if (count($result) === 0) {
return false;
}
$posts = array();
foreach ($result as $item) {
$posts[] = $item->post_id;
}
return $posts;
} | php | public function checkIfManuallyPicked($id)
{
global $wpdb;
$result = $wpdb->get_results("
SELECT *
FROM $wpdb->postmeta
WHERE meta_key = 'posts_data_posts'
AND meta_value LIKE '%\"{$id}\"%'
", OBJECT);
if (count($result) === 0) {
return false;
}
$posts = array();
foreach ($result as $item) {
$posts[] = $item->post_id;
}
return $posts;
} | [
"public",
"function",
"checkIfManuallyPicked",
"(",
"$",
"id",
")",
"{",
"global",
"$",
"wpdb",
";",
"$",
"result",
"=",
"$",
"wpdb",
"->",
"get_results",
"(",
"\"\n SELECT *\n FROM $wpdb->postmeta\n WHERE meta_key = 'posts_data_posts'\n AND meta_value LIKE '%\\\"{$id}\\\"%'\n \"",
",",
"OBJECT",
")",
";",
"if",
"(",
"count",
"(",
"$",
"result",
")",
"===",
"0",
")",
"{",
"return",
"false",
";",
"}",
"$",
"posts",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"result",
"as",
"$",
"item",
")",
"{",
"$",
"posts",
"[",
"]",
"=",
"$",
"item",
"->",
"post_id",
";",
"}",
"return",
"$",
"posts",
";",
"}"
]
| Check if current post is included in a manually picked data source in exapndable list
@param integer $id Post id
@return array Modules included in | [
"Check",
"if",
"current",
"post",
"is",
"included",
"in",
"a",
"manually",
"picked",
"data",
"source",
"in",
"exapndable",
"list"
]
| db4fcde30ba5db4fac9c8b3c3475c8229b50271d | https://github.com/helsingborg-stad/Modularity/blob/db4fcde30ba5db4fac9c8b3c3475c8229b50271d/source/php/Module/Posts/Posts.php#L650-L671 | train |
helsingborg-stad/Modularity | source/php/Module/Posts/Posts.php | Posts.getManualInputPosts | public static function getManualInputPosts($data)
{
$posts = array();
foreach ($data as $key => $item) {
$posts[] = array_merge((array)$item, array(
'ID' => $key,
'post_name' => $key,
'post_excerpt' => $item->post_content
));
}
$posts = json_decode(json_encode($posts));
return $posts;
} | php | public static function getManualInputPosts($data)
{
$posts = array();
foreach ($data as $key => $item) {
$posts[] = array_merge((array)$item, array(
'ID' => $key,
'post_name' => $key,
'post_excerpt' => $item->post_content
));
}
$posts = json_decode(json_encode($posts));
return $posts;
} | [
"public",
"static",
"function",
"getManualInputPosts",
"(",
"$",
"data",
")",
"{",
"$",
"posts",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"data",
"as",
"$",
"key",
"=>",
"$",
"item",
")",
"{",
"$",
"posts",
"[",
"]",
"=",
"array_merge",
"(",
"(",
"array",
")",
"$",
"item",
",",
"array",
"(",
"'ID'",
"=>",
"$",
"key",
",",
"'post_name'",
"=>",
"$",
"key",
",",
"'post_excerpt'",
"=>",
"$",
"item",
"->",
"post_content",
")",
")",
";",
"}",
"$",
"posts",
"=",
"json_decode",
"(",
"json_encode",
"(",
"$",
"posts",
")",
")",
";",
"return",
"$",
"posts",
";",
"}"
]
| "Fake" WP_POST objects for manually inputted posts
@param array $data The data to "fake"
@return array Faked data | [
"Fake",
"WP_POST",
"objects",
"for",
"manually",
"inputted",
"posts"
]
| db4fcde30ba5db4fac9c8b3c3475c8229b50271d | https://github.com/helsingborg-stad/Modularity/blob/db4fcde30ba5db4fac9c8b3c3475c8229b50271d/source/php/Module/Posts/Posts.php#L710-L725 | train |
helsingborg-stad/Modularity | source/php/Module/Posts/Posts.php | Posts.getPosts | public static function getPosts($module)
{
$fields = json_decode(json_encode(get_fields($module->ID)));
if ($fields->posts_data_source == 'input') {
return self::getManualInputPosts($fields->data);
}
return get_posts(self::getPostArgs($module->ID));
} | php | public static function getPosts($module)
{
$fields = json_decode(json_encode(get_fields($module->ID)));
if ($fields->posts_data_source == 'input') {
return self::getManualInputPosts($fields->data);
}
return get_posts(self::getPostArgs($module->ID));
} | [
"public",
"static",
"function",
"getPosts",
"(",
"$",
"module",
")",
"{",
"$",
"fields",
"=",
"json_decode",
"(",
"json_encode",
"(",
"get_fields",
"(",
"$",
"module",
"->",
"ID",
")",
")",
")",
";",
"if",
"(",
"$",
"fields",
"->",
"posts_data_source",
"==",
"'input'",
")",
"{",
"return",
"self",
"::",
"getManualInputPosts",
"(",
"$",
"fields",
"->",
"data",
")",
";",
"}",
"return",
"get_posts",
"(",
"self",
"::",
"getPostArgs",
"(",
"$",
"module",
"->",
"ID",
")",
")",
";",
"}"
]
| Get included posts
@param object $module Module object
@return array Array with post objects | [
"Get",
"included",
"posts"
]
| db4fcde30ba5db4fac9c8b3c3475c8229b50271d | https://github.com/helsingborg-stad/Modularity/blob/db4fcde30ba5db4fac9c8b3c3475c8229b50271d/source/php/Module/Posts/Posts.php#L732-L740 | train |
helsingborg-stad/Modularity | source/php/Module/Social/Feed.php | Feed.getPinterestuser | public function getPinterestuser()
{
$endpoint = 'https://api.pinterest.com/v3/pidgets/users/' . $this->args['query'] . '/pins/';
$curl = new \Modularity\Helper\Curl();
$response = $curl->request('GET', $endpoint);
return json_decode($response)->data->pins;
} | php | public function getPinterestuser()
{
$endpoint = 'https://api.pinterest.com/v3/pidgets/users/' . $this->args['query'] . '/pins/';
$curl = new \Modularity\Helper\Curl();
$response = $curl->request('GET', $endpoint);
return json_decode($response)->data->pins;
} | [
"public",
"function",
"getPinterestuser",
"(",
")",
"{",
"$",
"endpoint",
"=",
"'https://api.pinterest.com/v3/pidgets/users/'",
".",
"$",
"this",
"->",
"args",
"[",
"'query'",
"]",
".",
"'/pins/'",
";",
"$",
"curl",
"=",
"new",
"\\",
"Modularity",
"\\",
"Helper",
"\\",
"Curl",
"(",
")",
";",
"$",
"response",
"=",
"$",
"curl",
"->",
"request",
"(",
"'GET'",
",",
"$",
"endpoint",
")",
";",
"return",
"json_decode",
"(",
"$",
"response",
")",
"->",
"data",
"->",
"pins",
";",
"}"
]
| Get Pinterest user's feed
@return object Feed | [
"Get",
"Pinterest",
"user",
"s",
"feed"
]
| db4fcde30ba5db4fac9c8b3c3475c8229b50271d | https://github.com/helsingborg-stad/Modularity/blob/db4fcde30ba5db4fac9c8b3c3475c8229b50271d/source/php/Module/Social/Feed.php#L114-L122 | train |
helsingborg-stad/Modularity | source/php/Module/Social/Feed.php | Feed.getTwitterAccessToken | public function getTwitterAccessToken()
{
$consumer_key = urlencode($this->args['api_user']);
$consumer_secret = urlencode($this->args['api_secret']);
// Concatenate key and secret and base64 encode
$bearer_token = $consumer_key . ':' . $consumer_secret;
$base64_bearer_token = base64_encode($bearer_token);
// Request access token
$endpoint = 'https://api.twitter.com/oauth2/token';
// Request headers
$headers = array(
"POST /oauth2/token HTTP/1.1",
"Host: api.twitter.com",
"User-Agent: jonhurlock Twitter Application-only OAuth App v.1",
"Authorization: Basic " . $base64_bearer_token,
"Content-Type: application/x-www-form-urlencoded;charset=UTF-8"
);
// Postdata
$data = array(
'grant_type' => 'client_credentials'
);
// Curl and format response
$curl = new \Modularity\Helper\Curl();
$response = $curl->request('POST', $endpoint, $data, null, $headers);
$response = json_decode($response);
if (isset($response->errors)) {
return $response;
}
return $response->access_token;
} | php | public function getTwitterAccessToken()
{
$consumer_key = urlencode($this->args['api_user']);
$consumer_secret = urlencode($this->args['api_secret']);
// Concatenate key and secret and base64 encode
$bearer_token = $consumer_key . ':' . $consumer_secret;
$base64_bearer_token = base64_encode($bearer_token);
// Request access token
$endpoint = 'https://api.twitter.com/oauth2/token';
// Request headers
$headers = array(
"POST /oauth2/token HTTP/1.1",
"Host: api.twitter.com",
"User-Agent: jonhurlock Twitter Application-only OAuth App v.1",
"Authorization: Basic " . $base64_bearer_token,
"Content-Type: application/x-www-form-urlencoded;charset=UTF-8"
);
// Postdata
$data = array(
'grant_type' => 'client_credentials'
);
// Curl and format response
$curl = new \Modularity\Helper\Curl();
$response = $curl->request('POST', $endpoint, $data, null, $headers);
$response = json_decode($response);
if (isset($response->errors)) {
return $response;
}
return $response->access_token;
} | [
"public",
"function",
"getTwitterAccessToken",
"(",
")",
"{",
"$",
"consumer_key",
"=",
"urlencode",
"(",
"$",
"this",
"->",
"args",
"[",
"'api_user'",
"]",
")",
";",
"$",
"consumer_secret",
"=",
"urlencode",
"(",
"$",
"this",
"->",
"args",
"[",
"'api_secret'",
"]",
")",
";",
"// Concatenate key and secret and base64 encode",
"$",
"bearer_token",
"=",
"$",
"consumer_key",
".",
"':'",
".",
"$",
"consumer_secret",
";",
"$",
"base64_bearer_token",
"=",
"base64_encode",
"(",
"$",
"bearer_token",
")",
";",
"// Request access token",
"$",
"endpoint",
"=",
"'https://api.twitter.com/oauth2/token'",
";",
"// Request headers",
"$",
"headers",
"=",
"array",
"(",
"\"POST /oauth2/token HTTP/1.1\"",
",",
"\"Host: api.twitter.com\"",
",",
"\"User-Agent: jonhurlock Twitter Application-only OAuth App v.1\"",
",",
"\"Authorization: Basic \"",
".",
"$",
"base64_bearer_token",
",",
"\"Content-Type: application/x-www-form-urlencoded;charset=UTF-8\"",
")",
";",
"// Postdata",
"$",
"data",
"=",
"array",
"(",
"'grant_type'",
"=>",
"'client_credentials'",
")",
";",
"// Curl and format response",
"$",
"curl",
"=",
"new",
"\\",
"Modularity",
"\\",
"Helper",
"\\",
"Curl",
"(",
")",
";",
"$",
"response",
"=",
"$",
"curl",
"->",
"request",
"(",
"'POST'",
",",
"$",
"endpoint",
",",
"$",
"data",
",",
"null",
",",
"$",
"headers",
")",
";",
"$",
"response",
"=",
"json_decode",
"(",
"$",
"response",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"response",
"->",
"errors",
")",
")",
"{",
"return",
"$",
"response",
";",
"}",
"return",
"$",
"response",
"->",
"access_token",
";",
"}"
]
| Get Twitter Access Token
@return string Access token | [
"Get",
"Twitter",
"Access",
"Token"
]
| db4fcde30ba5db4fac9c8b3c3475c8229b50271d | https://github.com/helsingborg-stad/Modularity/blob/db4fcde30ba5db4fac9c8b3c3475c8229b50271d/source/php/Module/Social/Feed.php#L128-L164 | train |
helsingborg-stad/Modularity | source/php/Module/Social/Feed.php | Feed.getTwitterHashtag | public function getTwitterHashtag()
{
$access_token = $this->getTwitterAccessToken();
if (isset($access_token->errors[0])) {
return $access_token->errors[0];
}
$endpoint = 'https://api.twitter.com/1.1/search/tweets.json';
$data = array(
'access_token' => $access_token,
'q' => urlencode('#' . $this->args['query']),
'count' => $this->args['length'],
'exclude_replies' => true,
'include_rts ' => false,
'result_type' => 'recent',
'lang' => 'sv'
);
// Request headers
$headers = array(
"GET /1.1/search/tweets.json" . http_build_query($data) . " HTTP/1.1",
"Host: api.twitter.com",
"User-Agent: jonhurlock Twitter Application-only OAuth App v.1",
"Authorization: Bearer " . $access_token
);
// Curl
$curl = new \Modularity\Helper\Curl();
$tweets = $curl->request('GET', $endpoint, $data, 'JSON', $headers);
return json_decode($tweets)->statuses;
} | php | public function getTwitterHashtag()
{
$access_token = $this->getTwitterAccessToken();
if (isset($access_token->errors[0])) {
return $access_token->errors[0];
}
$endpoint = 'https://api.twitter.com/1.1/search/tweets.json';
$data = array(
'access_token' => $access_token,
'q' => urlencode('#' . $this->args['query']),
'count' => $this->args['length'],
'exclude_replies' => true,
'include_rts ' => false,
'result_type' => 'recent',
'lang' => 'sv'
);
// Request headers
$headers = array(
"GET /1.1/search/tweets.json" . http_build_query($data) . " HTTP/1.1",
"Host: api.twitter.com",
"User-Agent: jonhurlock Twitter Application-only OAuth App v.1",
"Authorization: Bearer " . $access_token
);
// Curl
$curl = new \Modularity\Helper\Curl();
$tweets = $curl->request('GET', $endpoint, $data, 'JSON', $headers);
return json_decode($tweets)->statuses;
} | [
"public",
"function",
"getTwitterHashtag",
"(",
")",
"{",
"$",
"access_token",
"=",
"$",
"this",
"->",
"getTwitterAccessToken",
"(",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"access_token",
"->",
"errors",
"[",
"0",
"]",
")",
")",
"{",
"return",
"$",
"access_token",
"->",
"errors",
"[",
"0",
"]",
";",
"}",
"$",
"endpoint",
"=",
"'https://api.twitter.com/1.1/search/tweets.json'",
";",
"$",
"data",
"=",
"array",
"(",
"'access_token'",
"=>",
"$",
"access_token",
",",
"'q'",
"=>",
"urlencode",
"(",
"'#'",
".",
"$",
"this",
"->",
"args",
"[",
"'query'",
"]",
")",
",",
"'count'",
"=>",
"$",
"this",
"->",
"args",
"[",
"'length'",
"]",
",",
"'exclude_replies'",
"=>",
"true",
",",
"'include_rts '",
"=>",
"false",
",",
"'result_type'",
"=>",
"'recent'",
",",
"'lang'",
"=>",
"'sv'",
")",
";",
"// Request headers",
"$",
"headers",
"=",
"array",
"(",
"\"GET /1.1/search/tweets.json\"",
".",
"http_build_query",
"(",
"$",
"data",
")",
".",
"\" HTTP/1.1\"",
",",
"\"Host: api.twitter.com\"",
",",
"\"User-Agent: jonhurlock Twitter Application-only OAuth App v.1\"",
",",
"\"Authorization: Bearer \"",
".",
"$",
"access_token",
")",
";",
"// Curl",
"$",
"curl",
"=",
"new",
"\\",
"Modularity",
"\\",
"Helper",
"\\",
"Curl",
"(",
")",
";",
"$",
"tweets",
"=",
"$",
"curl",
"->",
"request",
"(",
"'GET'",
",",
"$",
"endpoint",
",",
"$",
"data",
",",
"'JSON'",
",",
"$",
"headers",
")",
";",
"return",
"json_decode",
"(",
"$",
"tweets",
")",
"->",
"statuses",
";",
"}"
]
| Get Twitter hashtag
@return object Feed data | [
"Get",
"Twitter",
"hashtag"
]
| db4fcde30ba5db4fac9c8b3c3475c8229b50271d | https://github.com/helsingborg-stad/Modularity/blob/db4fcde30ba5db4fac9c8b3c3475c8229b50271d/source/php/Module/Social/Feed.php#L170-L202 | train |
helsingborg-stad/Modularity | source/php/Module/Social/Feed.php | Feed.getFacebookUser | public function getFacebookUser()
{
/**
* Request a token from Facebook Graph API
*/
$endpoint = 'https://graph.facebook.com/oauth/access_token';
$data = array(
'grant_type' => 'client_credentials',
'client_id' => $this->args['api_user'],
'client_secret' => $this->args['api_secret']
);
$curl = new \Modularity\Helper\Curl();
$token = $curl->request('GET', $endpoint, $data);
if (strpos($token, 'error') !== false) {
$error = json_decode($token);
return $error;
}
//Decode token
$token = json_decode($token);
/**
* Request the posts
*/
$endpoint = 'https://graph.facebook.com/' . $this->args['query'] . '/posts';
$data = array(
'access_token' => $token->access_token,
'fields' => 'from, full_picture, picture, message, created_time, object_id, link, name, caption, description, icon, type, status_type, likes'
);
$feed = $curl->request('GET', $endpoint, $data);
//Valid data object
if(isset(json_decode($feed)->data)) {
return json_decode($feed)->data;
}
//Return whatever exists, let error handler fix the rest.
return json_decode($feed);
} | php | public function getFacebookUser()
{
/**
* Request a token from Facebook Graph API
*/
$endpoint = 'https://graph.facebook.com/oauth/access_token';
$data = array(
'grant_type' => 'client_credentials',
'client_id' => $this->args['api_user'],
'client_secret' => $this->args['api_secret']
);
$curl = new \Modularity\Helper\Curl();
$token = $curl->request('GET', $endpoint, $data);
if (strpos($token, 'error') !== false) {
$error = json_decode($token);
return $error;
}
//Decode token
$token = json_decode($token);
/**
* Request the posts
*/
$endpoint = 'https://graph.facebook.com/' . $this->args['query'] . '/posts';
$data = array(
'access_token' => $token->access_token,
'fields' => 'from, full_picture, picture, message, created_time, object_id, link, name, caption, description, icon, type, status_type, likes'
);
$feed = $curl->request('GET', $endpoint, $data);
//Valid data object
if(isset(json_decode($feed)->data)) {
return json_decode($feed)->data;
}
//Return whatever exists, let error handler fix the rest.
return json_decode($feed);
} | [
"public",
"function",
"getFacebookUser",
"(",
")",
"{",
"/**\n * Request a token from Facebook Graph API\n */",
"$",
"endpoint",
"=",
"'https://graph.facebook.com/oauth/access_token'",
";",
"$",
"data",
"=",
"array",
"(",
"'grant_type'",
"=>",
"'client_credentials'",
",",
"'client_id'",
"=>",
"$",
"this",
"->",
"args",
"[",
"'api_user'",
"]",
",",
"'client_secret'",
"=>",
"$",
"this",
"->",
"args",
"[",
"'api_secret'",
"]",
")",
";",
"$",
"curl",
"=",
"new",
"\\",
"Modularity",
"\\",
"Helper",
"\\",
"Curl",
"(",
")",
";",
"$",
"token",
"=",
"$",
"curl",
"->",
"request",
"(",
"'GET'",
",",
"$",
"endpoint",
",",
"$",
"data",
")",
";",
"if",
"(",
"strpos",
"(",
"$",
"token",
",",
"'error'",
")",
"!==",
"false",
")",
"{",
"$",
"error",
"=",
"json_decode",
"(",
"$",
"token",
")",
";",
"return",
"$",
"error",
";",
"}",
"//Decode token",
"$",
"token",
"=",
"json_decode",
"(",
"$",
"token",
")",
";",
"/**\n * Request the posts\n */",
"$",
"endpoint",
"=",
"'https://graph.facebook.com/'",
".",
"$",
"this",
"->",
"args",
"[",
"'query'",
"]",
".",
"'/posts'",
";",
"$",
"data",
"=",
"array",
"(",
"'access_token'",
"=>",
"$",
"token",
"->",
"access_token",
",",
"'fields'",
"=>",
"'from, full_picture, picture, message, created_time, object_id, link, name, caption, description, icon, type, status_type, likes'",
")",
";",
"$",
"feed",
"=",
"$",
"curl",
"->",
"request",
"(",
"'GET'",
",",
"$",
"endpoint",
",",
"$",
"data",
")",
";",
"//Valid data object",
"if",
"(",
"isset",
"(",
"json_decode",
"(",
"$",
"feed",
")",
"->",
"data",
")",
")",
"{",
"return",
"json_decode",
"(",
"$",
"feed",
")",
"->",
"data",
";",
"}",
"//Return whatever exists, let error handler fix the rest. ",
"return",
"json_decode",
"(",
"$",
"feed",
")",
";",
"}"
]
| Get a Facebook user's feed
@return object Feed | [
"Get",
"a",
"Facebook",
"user",
"s",
"feed"
]
| db4fcde30ba5db4fac9c8b3c3475c8229b50271d | https://github.com/helsingborg-stad/Modularity/blob/db4fcde30ba5db4fac9c8b3c3475c8229b50271d/source/php/Module/Social/Feed.php#L245-L286 | train |
helsingborg-stad/Modularity | source/php/Module/Social/Feed.php | Feed.getInstagramProfile | private function getInstagramProfile() : array
{
if (isset($this->cache->entry_data->ProfilePage[0]->graphql->user)) {
$user = $this->cache->entry_data->ProfilePage[0]->graphql->user;
return array(
'name' => $user->full_name,
'user_name' => $user->username,
'profilepic_sd' => $user->profile_pic_url,
'profilepic' => $user->profile_pic_url_hd,
'biography' => $user->biography,
);
}
return array();
} | php | private function getInstagramProfile() : array
{
if (isset($this->cache->entry_data->ProfilePage[0]->graphql->user)) {
$user = $this->cache->entry_data->ProfilePage[0]->graphql->user;
return array(
'name' => $user->full_name,
'user_name' => $user->username,
'profilepic_sd' => $user->profile_pic_url,
'profilepic' => $user->profile_pic_url_hd,
'biography' => $user->biography,
);
}
return array();
} | [
"private",
"function",
"getInstagramProfile",
"(",
")",
":",
"array",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"cache",
"->",
"entry_data",
"->",
"ProfilePage",
"[",
"0",
"]",
"->",
"graphql",
"->",
"user",
")",
")",
"{",
"$",
"user",
"=",
"$",
"this",
"->",
"cache",
"->",
"entry_data",
"->",
"ProfilePage",
"[",
"0",
"]",
"->",
"graphql",
"->",
"user",
";",
"return",
"array",
"(",
"'name'",
"=>",
"$",
"user",
"->",
"full_name",
",",
"'user_name'",
"=>",
"$",
"user",
"->",
"username",
",",
"'profilepic_sd'",
"=>",
"$",
"user",
"->",
"profile_pic_url",
",",
"'profilepic'",
"=>",
"$",
"user",
"->",
"profile_pic_url_hd",
",",
"'biography'",
"=>",
"$",
"user",
"->",
"biography",
",",
")",
";",
"}",
"return",
"array",
"(",
")",
";",
"}"
]
| Request the user profile
@param string $username The usernanme to fetch profile of
@return array/bool The data fetched from the service api or false if none | [
"Request",
"the",
"user",
"profile"
]
| db4fcde30ba5db4fac9c8b3c3475c8229b50271d | https://github.com/helsingborg-stad/Modularity/blob/db4fcde30ba5db4fac9c8b3c3475c8229b50271d/source/php/Module/Social/Feed.php#L336-L349 | train |
helsingborg-stad/Modularity | source/php/Module/Social/Feed.php | Feed.parseInstagramMarkup | public function parseInstagramMarkup($markup)
{
//Define what to get
$startTag = '<script type="text/javascript">window._sharedData = ';
$endTag = ';</script>';
//Match string with reguklar exp
$hasMatch = preg_match(
"#" . preg_quote($startTag, "#")
. '(.*?)'
. preg_quote($endTag, "#")
. "#"
. 's', $markup, $matches);
//Return matches (if valid json)
if ($hasMatch && isset($matches[0])) {
$matches = str_replace($startTag, "", $matches[0]);
$matches = str_replace($endTag, "", $matches);
return json_decode($matches);
}
//Nothing found, return false.
return false;
} | php | public function parseInstagramMarkup($markup)
{
//Define what to get
$startTag = '<script type="text/javascript">window._sharedData = ';
$endTag = ';</script>';
//Match string with reguklar exp
$hasMatch = preg_match(
"#" . preg_quote($startTag, "#")
. '(.*?)'
. preg_quote($endTag, "#")
. "#"
. 's', $markup, $matches);
//Return matches (if valid json)
if ($hasMatch && isset($matches[0])) {
$matches = str_replace($startTag, "", $matches[0]);
$matches = str_replace($endTag, "", $matches);
return json_decode($matches);
}
//Nothing found, return false.
return false;
} | [
"public",
"function",
"parseInstagramMarkup",
"(",
"$",
"markup",
")",
"{",
"//Define what to get",
"$",
"startTag",
"=",
"'<script type=\"text/javascript\">window._sharedData = '",
";",
"$",
"endTag",
"=",
"';</script>'",
";",
"//Match string with reguklar exp",
"$",
"hasMatch",
"=",
"preg_match",
"(",
"\"#\"",
".",
"preg_quote",
"(",
"$",
"startTag",
",",
"\"#\"",
")",
".",
"'(.*?)'",
".",
"preg_quote",
"(",
"$",
"endTag",
",",
"\"#\"",
")",
".",
"\"#\"",
".",
"'s'",
",",
"$",
"markup",
",",
"$",
"matches",
")",
";",
"//Return matches (if valid json)",
"if",
"(",
"$",
"hasMatch",
"&&",
"isset",
"(",
"$",
"matches",
"[",
"0",
"]",
")",
")",
"{",
"$",
"matches",
"=",
"str_replace",
"(",
"$",
"startTag",
",",
"\"\"",
",",
"$",
"matches",
"[",
"0",
"]",
")",
";",
"$",
"matches",
"=",
"str_replace",
"(",
"$",
"endTag",
",",
"\"\"",
",",
"$",
"matches",
")",
";",
"return",
"json_decode",
"(",
"$",
"matches",
")",
";",
"}",
"//Nothing found, return false.",
"return",
"false",
";",
"}"
]
| Parse data recived
@param $markup Raw data from webpage
@return Array with raw feed data | [
"Parse",
"data",
"recived"
]
| db4fcde30ba5db4fac9c8b3c3475c8229b50271d | https://github.com/helsingborg-stad/Modularity/blob/db4fcde30ba5db4fac9c8b3c3475c8229b50271d/source/php/Module/Social/Feed.php#L356-L380 | train |
helsingborg-stad/Modularity | source/php/Module/Social/Feed.php | Feed.renderPinterest | protected function renderPinterest()
{
$int = 0;
foreach ($this->feedData as $item) {
$int++;
$this->addImage(
null,
array(
'name' => $item->pinner->full_name,
'picture' => $item->pinner->image_small_url
),
$item->images->{'237x'}->url,
isset($item->description) ? $item->description : null,
$item->link
);
if ($int == $this->args['length']) {
break;
}
}
} | php | protected function renderPinterest()
{
$int = 0;
foreach ($this->feedData as $item) {
$int++;
$this->addImage(
null,
array(
'name' => $item->pinner->full_name,
'picture' => $item->pinner->image_small_url
),
$item->images->{'237x'}->url,
isset($item->description) ? $item->description : null,
$item->link
);
if ($int == $this->args['length']) {
break;
}
}
} | [
"protected",
"function",
"renderPinterest",
"(",
")",
"{",
"$",
"int",
"=",
"0",
";",
"foreach",
"(",
"$",
"this",
"->",
"feedData",
"as",
"$",
"item",
")",
"{",
"$",
"int",
"++",
";",
"$",
"this",
"->",
"addImage",
"(",
"null",
",",
"array",
"(",
"'name'",
"=>",
"$",
"item",
"->",
"pinner",
"->",
"full_name",
",",
"'picture'",
"=>",
"$",
"item",
"->",
"pinner",
"->",
"image_small_url",
")",
",",
"$",
"item",
"->",
"images",
"->",
"{",
"'237x'",
"}",
"->",
"url",
",",
"isset",
"(",
"$",
"item",
"->",
"description",
")",
"?",
"$",
"item",
"->",
"description",
":",
"null",
",",
"$",
"item",
"->",
"link",
")",
";",
"if",
"(",
"$",
"int",
"==",
"$",
"this",
"->",
"args",
"[",
"'length'",
"]",
")",
"{",
"break",
";",
"}",
"}",
"}"
]
| Render Pinterest images
@return void | [
"Render",
"Pinterest",
"images"
]
| db4fcde30ba5db4fac9c8b3c3475c8229b50271d | https://github.com/helsingborg-stad/Modularity/blob/db4fcde30ba5db4fac9c8b3c3475c8229b50271d/source/php/Module/Social/Feed.php#L433-L455 | train |
helsingborg-stad/Modularity | source/php/Module/Social/Feed.php | Feed.renderInstagram | protected function renderInstagram()
{
$int = 0;
if (isset($this->feedData->meta->error_message) || !isset($this->feedData)) {
$msg = 'No error message, sorry about that.';
if (isset($this->feedData->meta->error_message)) {
$msg = $this->feedData->meta->error_message;
}
$this->addError($msg);
return;
}
foreach ($this->feedData as $item) {
$int++;
$this->addImage(
$item['timestamp'],
array(
'name' => $item['user_name'],
'picture' => ''
),
$item['image_large'],
isset($item['content']) ? $item['content'] : null,
$item['network_source']
);
if ($int == $this->args['length']) {
break;
}
}
} | php | protected function renderInstagram()
{
$int = 0;
if (isset($this->feedData->meta->error_message) || !isset($this->feedData)) {
$msg = 'No error message, sorry about that.';
if (isset($this->feedData->meta->error_message)) {
$msg = $this->feedData->meta->error_message;
}
$this->addError($msg);
return;
}
foreach ($this->feedData as $item) {
$int++;
$this->addImage(
$item['timestamp'],
array(
'name' => $item['user_name'],
'picture' => ''
),
$item['image_large'],
isset($item['content']) ? $item['content'] : null,
$item['network_source']
);
if ($int == $this->args['length']) {
break;
}
}
} | [
"protected",
"function",
"renderInstagram",
"(",
")",
"{",
"$",
"int",
"=",
"0",
";",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"feedData",
"->",
"meta",
"->",
"error_message",
")",
"||",
"!",
"isset",
"(",
"$",
"this",
"->",
"feedData",
")",
")",
"{",
"$",
"msg",
"=",
"'No error message, sorry about that.'",
";",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"feedData",
"->",
"meta",
"->",
"error_message",
")",
")",
"{",
"$",
"msg",
"=",
"$",
"this",
"->",
"feedData",
"->",
"meta",
"->",
"error_message",
";",
"}",
"$",
"this",
"->",
"addError",
"(",
"$",
"msg",
")",
";",
"return",
";",
"}",
"foreach",
"(",
"$",
"this",
"->",
"feedData",
"as",
"$",
"item",
")",
"{",
"$",
"int",
"++",
";",
"$",
"this",
"->",
"addImage",
"(",
"$",
"item",
"[",
"'timestamp'",
"]",
",",
"array",
"(",
"'name'",
"=>",
"$",
"item",
"[",
"'user_name'",
"]",
",",
"'picture'",
"=>",
"''",
")",
",",
"$",
"item",
"[",
"'image_large'",
"]",
",",
"isset",
"(",
"$",
"item",
"[",
"'content'",
"]",
")",
"?",
"$",
"item",
"[",
"'content'",
"]",
":",
"null",
",",
"$",
"item",
"[",
"'network_source'",
"]",
")",
";",
"if",
"(",
"$",
"int",
"==",
"$",
"this",
"->",
"args",
"[",
"'length'",
"]",
")",
"{",
"break",
";",
"}",
"}",
"}"
]
| Render Instagram images
@return void | [
"Render",
"Instagram",
"images"
]
| db4fcde30ba5db4fac9c8b3c3475c8229b50271d | https://github.com/helsingborg-stad/Modularity/blob/db4fcde30ba5db4fac9c8b3c3475c8229b50271d/source/php/Module/Social/Feed.php#L461-L495 | train |
helsingborg-stad/Modularity | source/php/Module/Social/Feed.php | Feed.renderFacebook | protected function renderFacebook()
{
$int = 0;
if (isset($this->feedData->error->message)) {
$this->addError($this->feedData->error->message);
return;
}
if (!empty($this->feedData)) {
foreach ((array) $this->feedData as $item) {
$int++;
$date = new \DateTime($item->created_time);
$timeZone = new \DateTimeZone(!empty(get_option('timezone_string')) ? get_option('timezone_string') : date_default_timezone_get());
$date->setTimezone($timeZone);
$this->addStory(
strtotime($date->format('Y-m-d H:i:s')),
array(
'name' => $item->from->name,
'picture' => '//graph.facebook.com/' . $item->from->id . '/picture?type=large'
),
isset($item->message) ? $item->message : '',
array(
'type' => isset($item->type) ? $item->type : null,
'status_type' => isset($item->status_type) ? $item->status_type : null,
'name' => isset($item->name) ? $item->name : null,
'description' => isset($item->description) ? $item->description : null,
'caption' => isset($item->caption) ? $item->caption : null,
'link' => isset($item->link) ? $item->link : null,
'full_picture' => isset($item->full_picture) ? $item->full_picture : null
)
);
if ($int == $this->args['length']) {
break;
}
}
}
} | php | protected function renderFacebook()
{
$int = 0;
if (isset($this->feedData->error->message)) {
$this->addError($this->feedData->error->message);
return;
}
if (!empty($this->feedData)) {
foreach ((array) $this->feedData as $item) {
$int++;
$date = new \DateTime($item->created_time);
$timeZone = new \DateTimeZone(!empty(get_option('timezone_string')) ? get_option('timezone_string') : date_default_timezone_get());
$date->setTimezone($timeZone);
$this->addStory(
strtotime($date->format('Y-m-d H:i:s')),
array(
'name' => $item->from->name,
'picture' => '//graph.facebook.com/' . $item->from->id . '/picture?type=large'
),
isset($item->message) ? $item->message : '',
array(
'type' => isset($item->type) ? $item->type : null,
'status_type' => isset($item->status_type) ? $item->status_type : null,
'name' => isset($item->name) ? $item->name : null,
'description' => isset($item->description) ? $item->description : null,
'caption' => isset($item->caption) ? $item->caption : null,
'link' => isset($item->link) ? $item->link : null,
'full_picture' => isset($item->full_picture) ? $item->full_picture : null
)
);
if ($int == $this->args['length']) {
break;
}
}
}
} | [
"protected",
"function",
"renderFacebook",
"(",
")",
"{",
"$",
"int",
"=",
"0",
";",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"feedData",
"->",
"error",
"->",
"message",
")",
")",
"{",
"$",
"this",
"->",
"addError",
"(",
"$",
"this",
"->",
"feedData",
"->",
"error",
"->",
"message",
")",
";",
"return",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"feedData",
")",
")",
"{",
"foreach",
"(",
"(",
"array",
")",
"$",
"this",
"->",
"feedData",
"as",
"$",
"item",
")",
"{",
"$",
"int",
"++",
";",
"$",
"date",
"=",
"new",
"\\",
"DateTime",
"(",
"$",
"item",
"->",
"created_time",
")",
";",
"$",
"timeZone",
"=",
"new",
"\\",
"DateTimeZone",
"(",
"!",
"empty",
"(",
"get_option",
"(",
"'timezone_string'",
")",
")",
"?",
"get_option",
"(",
"'timezone_string'",
")",
":",
"date_default_timezone_get",
"(",
")",
")",
";",
"$",
"date",
"->",
"setTimezone",
"(",
"$",
"timeZone",
")",
";",
"$",
"this",
"->",
"addStory",
"(",
"strtotime",
"(",
"$",
"date",
"->",
"format",
"(",
"'Y-m-d H:i:s'",
")",
")",
",",
"array",
"(",
"'name'",
"=>",
"$",
"item",
"->",
"from",
"->",
"name",
",",
"'picture'",
"=>",
"'//graph.facebook.com/'",
".",
"$",
"item",
"->",
"from",
"->",
"id",
".",
"'/picture?type=large'",
")",
",",
"isset",
"(",
"$",
"item",
"->",
"message",
")",
"?",
"$",
"item",
"->",
"message",
":",
"''",
",",
"array",
"(",
"'type'",
"=>",
"isset",
"(",
"$",
"item",
"->",
"type",
")",
"?",
"$",
"item",
"->",
"type",
":",
"null",
",",
"'status_type'",
"=>",
"isset",
"(",
"$",
"item",
"->",
"status_type",
")",
"?",
"$",
"item",
"->",
"status_type",
":",
"null",
",",
"'name'",
"=>",
"isset",
"(",
"$",
"item",
"->",
"name",
")",
"?",
"$",
"item",
"->",
"name",
":",
"null",
",",
"'description'",
"=>",
"isset",
"(",
"$",
"item",
"->",
"description",
")",
"?",
"$",
"item",
"->",
"description",
":",
"null",
",",
"'caption'",
"=>",
"isset",
"(",
"$",
"item",
"->",
"caption",
")",
"?",
"$",
"item",
"->",
"caption",
":",
"null",
",",
"'link'",
"=>",
"isset",
"(",
"$",
"item",
"->",
"link",
")",
"?",
"$",
"item",
"->",
"link",
":",
"null",
",",
"'full_picture'",
"=>",
"isset",
"(",
"$",
"item",
"->",
"full_picture",
")",
"?",
"$",
"item",
"->",
"full_picture",
":",
"null",
")",
")",
";",
"if",
"(",
"$",
"int",
"==",
"$",
"this",
"->",
"args",
"[",
"'length'",
"]",
")",
"{",
"break",
";",
"}",
"}",
"}",
"}"
]
| Renders Facebook posts
@return void | [
"Renders",
"Facebook",
"posts"
]
| db4fcde30ba5db4fac9c8b3c3475c8229b50271d | https://github.com/helsingborg-stad/Modularity/blob/db4fcde30ba5db4fac9c8b3c3475c8229b50271d/source/php/Module/Social/Feed.php#L501-L541 | train |
helsingborg-stad/Modularity | source/php/Module/Social/Feed.php | Feed.renderTwitter | protected function renderTwitter()
{
if (isset($this->feedData->message)) {
$this->addError($this->feedData->message);
return;
}
foreach ($this->feedData as $item) {
$date = new \DateTime($item->created_at);
$timeZone = new \DateTimeZone(get_option('timezone_string'));
$date->setTimezone($timeZone);
$this->addStory(
strtotime($date->format('Y-m-d H:i:s')),
array(
'name' => $item->user->name,
'picture' => $item->user->profile_image_url
),
$item->text
);
}
} | php | protected function renderTwitter()
{
if (isset($this->feedData->message)) {
$this->addError($this->feedData->message);
return;
}
foreach ($this->feedData as $item) {
$date = new \DateTime($item->created_at);
$timeZone = new \DateTimeZone(get_option('timezone_string'));
$date->setTimezone($timeZone);
$this->addStory(
strtotime($date->format('Y-m-d H:i:s')),
array(
'name' => $item->user->name,
'picture' => $item->user->profile_image_url
),
$item->text
);
}
} | [
"protected",
"function",
"renderTwitter",
"(",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"feedData",
"->",
"message",
")",
")",
"{",
"$",
"this",
"->",
"addError",
"(",
"$",
"this",
"->",
"feedData",
"->",
"message",
")",
";",
"return",
";",
"}",
"foreach",
"(",
"$",
"this",
"->",
"feedData",
"as",
"$",
"item",
")",
"{",
"$",
"date",
"=",
"new",
"\\",
"DateTime",
"(",
"$",
"item",
"->",
"created_at",
")",
";",
"$",
"timeZone",
"=",
"new",
"\\",
"DateTimeZone",
"(",
"get_option",
"(",
"'timezone_string'",
")",
")",
";",
"$",
"date",
"->",
"setTimezone",
"(",
"$",
"timeZone",
")",
";",
"$",
"this",
"->",
"addStory",
"(",
"strtotime",
"(",
"$",
"date",
"->",
"format",
"(",
"'Y-m-d H:i:s'",
")",
")",
",",
"array",
"(",
"'name'",
"=>",
"$",
"item",
"->",
"user",
"->",
"name",
",",
"'picture'",
"=>",
"$",
"item",
"->",
"user",
"->",
"profile_image_url",
")",
",",
"$",
"item",
"->",
"text",
")",
";",
"}",
"}"
]
| Renders a Twitter post item
@return void | [
"Renders",
"a",
"Twitter",
"post",
"item"
]
| db4fcde30ba5db4fac9c8b3c3475c8229b50271d | https://github.com/helsingborg-stad/Modularity/blob/db4fcde30ba5db4fac9c8b3c3475c8229b50271d/source/php/Module/Social/Feed.php#L547-L568 | train |
helsingborg-stad/Modularity | source/php/Module/Social/Feed.php | Feed.addStory | protected function addStory($createdTime, $user, $text, $attachment = false)
{
$item = '
<li>
<div class="mod-social-user">
<img src="' . $user['picture'] . '" alt="' . $user['name'] . '">
<div>
<span>' . $user['name'] . '</span>
<time>' . human_time_diff($createdTime, current_time('timestamp')) . ' ' . __('ago', 'modularity') . '</time>
</div>
</div>
<div class="mod-social-story">
' . wpautop($text) . '
</div>
';
if (is_array($attachment)) {
$item .= $this->addAttachment($attachment);
}
$item .= '</li>';
$this->markup .= apply_filters('Modularity/mod_social/story', $item, $createdTime, $user, $text);
} | php | protected function addStory($createdTime, $user, $text, $attachment = false)
{
$item = '
<li>
<div class="mod-social-user">
<img src="' . $user['picture'] . '" alt="' . $user['name'] . '">
<div>
<span>' . $user['name'] . '</span>
<time>' . human_time_diff($createdTime, current_time('timestamp')) . ' ' . __('ago', 'modularity') . '</time>
</div>
</div>
<div class="mod-social-story">
' . wpautop($text) . '
</div>
';
if (is_array($attachment)) {
$item .= $this->addAttachment($attachment);
}
$item .= '</li>';
$this->markup .= apply_filters('Modularity/mod_social/story', $item, $createdTime, $user, $text);
} | [
"protected",
"function",
"addStory",
"(",
"$",
"createdTime",
",",
"$",
"user",
",",
"$",
"text",
",",
"$",
"attachment",
"=",
"false",
")",
"{",
"$",
"item",
"=",
"'\n <li>\n <div class=\"mod-social-user\">\n <img src=\"'",
".",
"$",
"user",
"[",
"'picture'",
"]",
".",
"'\" alt=\"'",
".",
"$",
"user",
"[",
"'name'",
"]",
".",
"'\">\n <div>\n <span>'",
".",
"$",
"user",
"[",
"'name'",
"]",
".",
"'</span>\n <time>'",
".",
"human_time_diff",
"(",
"$",
"createdTime",
",",
"current_time",
"(",
"'timestamp'",
")",
")",
".",
"' '",
".",
"__",
"(",
"'ago'",
",",
"'modularity'",
")",
".",
"'</time>\n </div>\n </div>\n <div class=\"mod-social-story\">\n '",
".",
"wpautop",
"(",
"$",
"text",
")",
".",
"'\n </div>\n '",
";",
"if",
"(",
"is_array",
"(",
"$",
"attachment",
")",
")",
"{",
"$",
"item",
".=",
"$",
"this",
"->",
"addAttachment",
"(",
"$",
"attachment",
")",
";",
"}",
"$",
"item",
".=",
"'</li>'",
";",
"$",
"this",
"->",
"markup",
".=",
"apply_filters",
"(",
"'Modularity/mod_social/story'",
",",
"$",
"item",
",",
"$",
"createdTime",
",",
"$",
"user",
",",
"$",
"text",
")",
";",
"}"
]
| Adds a story
@param timestamp $createdTime Created date timestamp
@param array $user User name and picture
@param string $text The text | [
"Adds",
"a",
"story"
]
| db4fcde30ba5db4fac9c8b3c3475c8229b50271d | https://github.com/helsingborg-stad/Modularity/blob/db4fcde30ba5db4fac9c8b3c3475c8229b50271d/source/php/Module/Social/Feed.php#L613-L636 | train |
helsingborg-stad/Modularity | source/php/Options.php | Options.register | public function register($pageTitle, $menuTitle, $capability, $menuSlug, $iconUrl = null, $position = null, $parent = 'modularity')
{
add_action('admin_menu', function () use ($pageTitle, $menuTitle, $capability, $menuSlug, $iconUrl, $position, $parent) {
// Add the menu page
$this->screenHook = add_submenu_page(
$parent,
$pageTitle,
$menuTitle,
$capability,
$menuSlug,
array($this, 'optionPageTemplate')
);
// Set the slug
$this->slug = $menuSlug;
// Setup meta box support
add_action('load-' . $this->screenHook, array($this, 'save'), 1);
add_action('load-' . $this->screenHook, array($this, 'setupMetaBoxSupport'), 2);
// Hook to add the metaboxes
add_action('add_meta_boxes_' . $this->screenHook, array($this, 'addMetaBoxes'));
});
} | php | public function register($pageTitle, $menuTitle, $capability, $menuSlug, $iconUrl = null, $position = null, $parent = 'modularity')
{
add_action('admin_menu', function () use ($pageTitle, $menuTitle, $capability, $menuSlug, $iconUrl, $position, $parent) {
// Add the menu page
$this->screenHook = add_submenu_page(
$parent,
$pageTitle,
$menuTitle,
$capability,
$menuSlug,
array($this, 'optionPageTemplate')
);
// Set the slug
$this->slug = $menuSlug;
// Setup meta box support
add_action('load-' . $this->screenHook, array($this, 'save'), 1);
add_action('load-' . $this->screenHook, array($this, 'setupMetaBoxSupport'), 2);
// Hook to add the metaboxes
add_action('add_meta_boxes_' . $this->screenHook, array($this, 'addMetaBoxes'));
});
} | [
"public",
"function",
"register",
"(",
"$",
"pageTitle",
",",
"$",
"menuTitle",
",",
"$",
"capability",
",",
"$",
"menuSlug",
",",
"$",
"iconUrl",
"=",
"null",
",",
"$",
"position",
"=",
"null",
",",
"$",
"parent",
"=",
"'modularity'",
")",
"{",
"add_action",
"(",
"'admin_menu'",
",",
"function",
"(",
")",
"use",
"(",
"$",
"pageTitle",
",",
"$",
"menuTitle",
",",
"$",
"capability",
",",
"$",
"menuSlug",
",",
"$",
"iconUrl",
",",
"$",
"position",
",",
"$",
"parent",
")",
"{",
"// Add the menu page",
"$",
"this",
"->",
"screenHook",
"=",
"add_submenu_page",
"(",
"$",
"parent",
",",
"$",
"pageTitle",
",",
"$",
"menuTitle",
",",
"$",
"capability",
",",
"$",
"menuSlug",
",",
"array",
"(",
"$",
"this",
",",
"'optionPageTemplate'",
")",
")",
";",
"// Set the slug",
"$",
"this",
"->",
"slug",
"=",
"$",
"menuSlug",
";",
"// Setup meta box support",
"add_action",
"(",
"'load-'",
".",
"$",
"this",
"->",
"screenHook",
",",
"array",
"(",
"$",
"this",
",",
"'save'",
")",
",",
"1",
")",
";",
"add_action",
"(",
"'load-'",
".",
"$",
"this",
"->",
"screenHook",
",",
"array",
"(",
"$",
"this",
",",
"'setupMetaBoxSupport'",
")",
",",
"2",
")",
";",
"// Hook to add the metaboxes",
"add_action",
"(",
"'add_meta_boxes_'",
".",
"$",
"this",
"->",
"screenHook",
",",
"array",
"(",
"$",
"this",
",",
"'addMetaBoxes'",
")",
")",
";",
"}",
")",
";",
"}"
]
| Registers an options page
@param string $pageTitle Page title
@param string $menuTitle Menu title
@param string $capability Capability needed
@param string $menuSlug Menu slug
@param strin/array $function Callback function for content
@param string $iconUrl Menu icon
@param integer $position Menu position
@return void | [
"Registers",
"an",
"options",
"page"
]
| db4fcde30ba5db4fac9c8b3c3475c8229b50271d | https://github.com/helsingborg-stad/Modularity/blob/db4fcde30ba5db4fac9c8b3c3475c8229b50271d/source/php/Options.php#L30-L53 | train |
helsingborg-stad/Modularity | source/php/Options.php | Options.save | public function save()
{
if (!$this->isValidPostSave()) {
return;
}
// Get the options
global $modularityOptions;
$modularityOptions = (isset($_POST['modularity-options'])) ? $_POST['modularity-options'] : array();
// Update the options
update_option($this->slug, $modularityOptions);
do_action('Modularity/Options/Save');
// All done, send notice
$this->notice(__('Options saved successfully', 'modularity'), ['updated']);
} | php | public function save()
{
if (!$this->isValidPostSave()) {
return;
}
// Get the options
global $modularityOptions;
$modularityOptions = (isset($_POST['modularity-options'])) ? $_POST['modularity-options'] : array();
// Update the options
update_option($this->slug, $modularityOptions);
do_action('Modularity/Options/Save');
// All done, send notice
$this->notice(__('Options saved successfully', 'modularity'), ['updated']);
} | [
"public",
"function",
"save",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"isValidPostSave",
"(",
")",
")",
"{",
"return",
";",
"}",
"// Get the options",
"global",
"$",
"modularityOptions",
";",
"$",
"modularityOptions",
"=",
"(",
"isset",
"(",
"$",
"_POST",
"[",
"'modularity-options'",
"]",
")",
")",
"?",
"$",
"_POST",
"[",
"'modularity-options'",
"]",
":",
"array",
"(",
")",
";",
"// Update the options",
"update_option",
"(",
"$",
"this",
"->",
"slug",
",",
"$",
"modularityOptions",
")",
";",
"do_action",
"(",
"'Modularity/Options/Save'",
")",
";",
"// All done, send notice",
"$",
"this",
"->",
"notice",
"(",
"__",
"(",
"'Options saved successfully'",
",",
"'modularity'",
")",
",",
"[",
"'updated'",
"]",
")",
";",
"}"
]
| Saves the options
@return void | [
"Saves",
"the",
"options"
]
| db4fcde30ba5db4fac9c8b3c3475c8229b50271d | https://github.com/helsingborg-stad/Modularity/blob/db4fcde30ba5db4fac9c8b3c3475c8229b50271d/source/php/Options.php#L77-L94 | train |
helsingborg-stad/Modularity | source/php/Options.php | Options.setupMetaBoxSupport | public function setupMetaBoxSupport()
{
do_action('add_meta_boxes_' . $this->screenHook, null);
do_action('add_meta_boxes', $this->screenHook, null);
add_screen_option('layout_columns', array('max' => 2, 'default' => 2));
} | php | public function setupMetaBoxSupport()
{
do_action('add_meta_boxes_' . $this->screenHook, null);
do_action('add_meta_boxes', $this->screenHook, null);
add_screen_option('layout_columns', array('max' => 2, 'default' => 2));
} | [
"public",
"function",
"setupMetaBoxSupport",
"(",
")",
"{",
"do_action",
"(",
"'add_meta_boxes_'",
".",
"$",
"this",
"->",
"screenHook",
",",
"null",
")",
";",
"do_action",
"(",
"'add_meta_boxes'",
",",
"$",
"this",
"->",
"screenHook",
",",
"null",
")",
";",
"add_screen_option",
"(",
"'layout_columns'",
",",
"array",
"(",
"'max'",
"=>",
"2",
",",
"'default'",
"=>",
"2",
")",
")",
";",
"}"
]
| Add metabox support to the options page
@return void | [
"Add",
"metabox",
"support",
"to",
"the",
"options",
"page"
]
| db4fcde30ba5db4fac9c8b3c3475c8229b50271d | https://github.com/helsingborg-stad/Modularity/blob/db4fcde30ba5db4fac9c8b3c3475c8229b50271d/source/php/Options.php#L114-L120 | train |
helsingborg-stad/Modularity | source/php/Module/Image/Image.php | Image.maybeCropImage | public function maybeCropImage($data)
{
if (!$data['mod_image_crop']) {
return $data['mod_image_image']['sizes'][$data['mod_image_size']];
}
$imageSrc = wp_get_attachment_image_src(
$data['mod_image_image']['ID'],
apply_filters('Modularity/image/image',
municipio_to_aspect_ratio('16:9', array($data['mod_image_crop_width'], $data['mod_image_crop_height']))
)
);
return $imageSrc[0];
} | php | public function maybeCropImage($data)
{
if (!$data['mod_image_crop']) {
return $data['mod_image_image']['sizes'][$data['mod_image_size']];
}
$imageSrc = wp_get_attachment_image_src(
$data['mod_image_image']['ID'],
apply_filters('Modularity/image/image',
municipio_to_aspect_ratio('16:9', array($data['mod_image_crop_width'], $data['mod_image_crop_height']))
)
);
return $imageSrc[0];
} | [
"public",
"function",
"maybeCropImage",
"(",
"$",
"data",
")",
"{",
"if",
"(",
"!",
"$",
"data",
"[",
"'mod_image_crop'",
"]",
")",
"{",
"return",
"$",
"data",
"[",
"'mod_image_image'",
"]",
"[",
"'sizes'",
"]",
"[",
"$",
"data",
"[",
"'mod_image_size'",
"]",
"]",
";",
"}",
"$",
"imageSrc",
"=",
"wp_get_attachment_image_src",
"(",
"$",
"data",
"[",
"'mod_image_image'",
"]",
"[",
"'ID'",
"]",
",",
"apply_filters",
"(",
"'Modularity/image/image'",
",",
"municipio_to_aspect_ratio",
"(",
"'16:9'",
",",
"array",
"(",
"$",
"data",
"[",
"'mod_image_crop_width'",
"]",
",",
"$",
"data",
"[",
"'mod_image_crop_height'",
"]",
")",
")",
")",
")",
";",
"return",
"$",
"imageSrc",
"[",
"0",
"]",
";",
"}"
]
| Create a cropped image if needed
@return string | [
"Create",
"a",
"cropped",
"image",
"if",
"needed"
]
| db4fcde30ba5db4fac9c8b3c3475c8229b50271d | https://github.com/helsingborg-stad/Modularity/blob/db4fcde30ba5db4fac9c8b3c3475c8229b50271d/source/php/Module/Image/Image.php#L60-L74 | train |
helsingborg-stad/Modularity | source/php/Module/Image/Image.php | Image.appendImageSizes | public function appendImageSizes($field)
{
$sizes = get_intermediate_image_sizes();
foreach ($sizes as $size) {
$field['choices'][$size] = $size;
}
return $field;
} | php | public function appendImageSizes($field)
{
$sizes = get_intermediate_image_sizes();
foreach ($sizes as $size) {
$field['choices'][$size] = $size;
}
return $field;
} | [
"public",
"function",
"appendImageSizes",
"(",
"$",
"field",
")",
"{",
"$",
"sizes",
"=",
"get_intermediate_image_sizes",
"(",
")",
";",
"foreach",
"(",
"$",
"sizes",
"as",
"$",
"size",
")",
"{",
"$",
"field",
"[",
"'choices'",
"]",
"[",
"$",
"size",
"]",
"=",
"$",
"size",
";",
"}",
"return",
"$",
"field",
";",
"}"
]
| Creates a list of predefined sizes to choose from
@return array | [
"Creates",
"a",
"list",
"of",
"predefined",
"sizes",
"to",
"choose",
"from"
]
| db4fcde30ba5db4fac9c8b3c3475c8229b50271d | https://github.com/helsingborg-stad/Modularity/blob/db4fcde30ba5db4fac9c8b3c3475c8229b50271d/source/php/Module/Image/Image.php#L95-L103 | train |
helsingborg-stad/Modularity | source/php/Module.php | Module.adminEnqueue | public function adminEnqueue()
{
if (\Modularity\Helper\Wp::isAddOrEditOfPostType($this->moduleSlug)) {
do_action('Modularity/Module/' . $this->moduleSlug . '/enqueue');
}
} | php | public function adminEnqueue()
{
if (\Modularity\Helper\Wp::isAddOrEditOfPostType($this->moduleSlug)) {
do_action('Modularity/Module/' . $this->moduleSlug . '/enqueue');
}
} | [
"public",
"function",
"adminEnqueue",
"(",
")",
"{",
"if",
"(",
"\\",
"Modularity",
"\\",
"Helper",
"\\",
"Wp",
"::",
"isAddOrEditOfPostType",
"(",
"$",
"this",
"->",
"moduleSlug",
")",
")",
"{",
"do_action",
"(",
"'Modularity/Module/'",
".",
"$",
"this",
"->",
"moduleSlug",
".",
"'/enqueue'",
")",
";",
"}",
"}"
]
| Enqueue for admin
@return void | [
"Enqueue",
"for",
"admin"
]
| db4fcde30ba5db4fac9c8b3c3475c8229b50271d | https://github.com/helsingborg-stad/Modularity/blob/db4fcde30ba5db4fac9c8b3c3475c8229b50271d/source/php/Module.php#L170-L175 | train |
helsingborg-stad/Modularity | source/php/Module.php | Module.extractPostProperties | private function extractPostProperties(\WP_Post $post)
{
foreach ($post as $key => $value) {
$this->extractedPostProperties[] = $key;
$this->$key = $value;
$this->data[$key] = $value;
}
} | php | private function extractPostProperties(\WP_Post $post)
{
foreach ($post as $key => $value) {
$this->extractedPostProperties[] = $key;
$this->$key = $value;
$this->data[$key] = $value;
}
} | [
"private",
"function",
"extractPostProperties",
"(",
"\\",
"WP_Post",
"$",
"post",
")",
"{",
"foreach",
"(",
"$",
"post",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"$",
"this",
"->",
"extractedPostProperties",
"[",
"]",
"=",
"$",
"key",
";",
"$",
"this",
"->",
"$",
"key",
"=",
"$",
"value",
";",
"$",
"this",
"->",
"data",
"[",
"$",
"key",
"]",
"=",
"$",
"value",
";",
"}",
"}"
]
| Extracts WP_Post properties into Module properties
@param \WP_Post $post
@return void | [
"Extracts",
"WP_Post",
"properties",
"into",
"Module",
"properties"
]
| db4fcde30ba5db4fac9c8b3c3475c8229b50271d | https://github.com/helsingborg-stad/Modularity/blob/db4fcde30ba5db4fac9c8b3c3475c8229b50271d/source/php/Module.php#L182-L189 | train |
helsingborg-stad/Modularity | source/php/Module.php | Module.getOnePageModules | public function getOnePageModules() : array
{
$modules = array();
if (is_front_page() && is_plugin_active('modularity-onepage/modularity-onepage.php')) {
$postStatus = array('publish');
if (is_user_logged_in()) {
$postStatus[] = 'private';
}
$sections = get_posts(array(
'post_type' => 'onepage',
'post_status' => $postStatus,
'orderby' => 'menu_order',
'order' => 'asc',
'posts_per_page' => -1
));
foreach ($sections as $section) {
$section_modules = \Modularity\Editor::getPostModules($section->ID);
if (!isset($section_modules['onepage-sidebar'])) {
continue;
}
$section_modules = $section_modules['onepage-sidebar']['modules'];
if (is_array($section_modules) && !empty($section_modules)) {
foreach ($section_modules as $module) {
if (!$module->hidden) {
$modules[] = $module;
}
}
}
}
}
return $modules;
} | php | public function getOnePageModules() : array
{
$modules = array();
if (is_front_page() && is_plugin_active('modularity-onepage/modularity-onepage.php')) {
$postStatus = array('publish');
if (is_user_logged_in()) {
$postStatus[] = 'private';
}
$sections = get_posts(array(
'post_type' => 'onepage',
'post_status' => $postStatus,
'orderby' => 'menu_order',
'order' => 'asc',
'posts_per_page' => -1
));
foreach ($sections as $section) {
$section_modules = \Modularity\Editor::getPostModules($section->ID);
if (!isset($section_modules['onepage-sidebar'])) {
continue;
}
$section_modules = $section_modules['onepage-sidebar']['modules'];
if (is_array($section_modules) && !empty($section_modules)) {
foreach ($section_modules as $module) {
if (!$module->hidden) {
$modules[] = $module;
}
}
}
}
}
return $modules;
} | [
"public",
"function",
"getOnePageModules",
"(",
")",
":",
"array",
"{",
"$",
"modules",
"=",
"array",
"(",
")",
";",
"if",
"(",
"is_front_page",
"(",
")",
"&&",
"is_plugin_active",
"(",
"'modularity-onepage/modularity-onepage.php'",
")",
")",
"{",
"$",
"postStatus",
"=",
"array",
"(",
"'publish'",
")",
";",
"if",
"(",
"is_user_logged_in",
"(",
")",
")",
"{",
"$",
"postStatus",
"[",
"]",
"=",
"'private'",
";",
"}",
"$",
"sections",
"=",
"get_posts",
"(",
"array",
"(",
"'post_type'",
"=>",
"'onepage'",
",",
"'post_status'",
"=>",
"$",
"postStatus",
",",
"'orderby'",
"=>",
"'menu_order'",
",",
"'order'",
"=>",
"'asc'",
",",
"'posts_per_page'",
"=>",
"-",
"1",
")",
")",
";",
"foreach",
"(",
"$",
"sections",
"as",
"$",
"section",
")",
"{",
"$",
"section_modules",
"=",
"\\",
"Modularity",
"\\",
"Editor",
"::",
"getPostModules",
"(",
"$",
"section",
"->",
"ID",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"section_modules",
"[",
"'onepage-sidebar'",
"]",
")",
")",
"{",
"continue",
";",
"}",
"$",
"section_modules",
"=",
"$",
"section_modules",
"[",
"'onepage-sidebar'",
"]",
"[",
"'modules'",
"]",
";",
"if",
"(",
"is_array",
"(",
"$",
"section_modules",
")",
"&&",
"!",
"empty",
"(",
"$",
"section_modules",
")",
")",
"{",
"foreach",
"(",
"$",
"section_modules",
"as",
"$",
"module",
")",
"{",
"if",
"(",
"!",
"$",
"module",
"->",
"hidden",
")",
"{",
"$",
"modules",
"[",
"]",
"=",
"$",
"module",
";",
"}",
"}",
"}",
"}",
"}",
"return",
"$",
"modules",
";",
"}"
]
| Get modules used in one page sections
@return array Array with modules from one page sections | [
"Get",
"modules",
"used",
"in",
"one",
"page",
"sections"
]
| db4fcde30ba5db4fac9c8b3c3475c8229b50271d | https://github.com/helsingborg-stad/Modularity/blob/db4fcde30ba5db4fac9c8b3c3475c8229b50271d/source/php/Module.php#L256-L293 | train |
helsingborg-stad/Modularity | source/php/Module.php | Module.getShortcodeModules | public function getShortcodeModules($post_id) : array
{
$post = get_post($post_id);
$pattern = get_shortcode_regex();
$modules = array();
if (is_object($post) && preg_match_all( '/'. $pattern .'/s', $post->post_content, $matches)
&& array_key_exists(2, $matches)
&& in_array('modularity', $matches[2])) {
$shortcodes = preg_replace('/[^0-9]/', '', $matches[3]);
foreach ($shortcodes as $key => $shortcode) {
$modules[] = array(
'ID' => $shortcode,
'post_type' => get_post_type($shortcode)
);
}
}
return $modules;
} | php | public function getShortcodeModules($post_id) : array
{
$post = get_post($post_id);
$pattern = get_shortcode_regex();
$modules = array();
if (is_object($post) && preg_match_all( '/'. $pattern .'/s', $post->post_content, $matches)
&& array_key_exists(2, $matches)
&& in_array('modularity', $matches[2])) {
$shortcodes = preg_replace('/[^0-9]/', '', $matches[3]);
foreach ($shortcodes as $key => $shortcode) {
$modules[] = array(
'ID' => $shortcode,
'post_type' => get_post_type($shortcode)
);
}
}
return $modules;
} | [
"public",
"function",
"getShortcodeModules",
"(",
"$",
"post_id",
")",
":",
"array",
"{",
"$",
"post",
"=",
"get_post",
"(",
"$",
"post_id",
")",
";",
"$",
"pattern",
"=",
"get_shortcode_regex",
"(",
")",
";",
"$",
"modules",
"=",
"array",
"(",
")",
";",
"if",
"(",
"is_object",
"(",
"$",
"post",
")",
"&&",
"preg_match_all",
"(",
"'/'",
".",
"$",
"pattern",
".",
"'/s'",
",",
"$",
"post",
"->",
"post_content",
",",
"$",
"matches",
")",
"&&",
"array_key_exists",
"(",
"2",
",",
"$",
"matches",
")",
"&&",
"in_array",
"(",
"'modularity'",
",",
"$",
"matches",
"[",
"2",
"]",
")",
")",
"{",
"$",
"shortcodes",
"=",
"preg_replace",
"(",
"'/[^0-9]/'",
",",
"''",
",",
"$",
"matches",
"[",
"3",
"]",
")",
";",
"foreach",
"(",
"$",
"shortcodes",
"as",
"$",
"key",
"=>",
"$",
"shortcode",
")",
"{",
"$",
"modules",
"[",
"]",
"=",
"array",
"(",
"'ID'",
"=>",
"$",
"shortcode",
",",
"'post_type'",
"=>",
"get_post_type",
"(",
"$",
"shortcode",
")",
")",
";",
"}",
"}",
"return",
"$",
"modules",
";",
"}"
]
| Get modules used in shortcodes
@param string $post_id Current post id
@return array Array with module post types | [
"Get",
"modules",
"used",
"in",
"shortcodes"
]
| db4fcde30ba5db4fac9c8b3c3475c8229b50271d | https://github.com/helsingborg-stad/Modularity/blob/db4fcde30ba5db4fac9c8b3c3475c8229b50271d/source/php/Module.php#L300-L320 | train |
helsingborg-stad/Modularity | source/php/Module.php | Module.register | public function register($slug, $nameSingular, $namePlural, $description, $supports = array(), $icon = null, $plugin = null, $cache_ttl = 0, $hideTitle = false)
{
//\Modularity\Helper\Wp::deprecatedFunction('Function $module->' . __FUNCTION__ . ' is deprecated since Modularity version 2.0.0');
if (empty($slug)) {
return;
}
add_action('Modularity/Init', function ($moduleManager) use ($slug, $nameSingular, $namePlural, $description, $supports, $icon, $plugin, $cache_ttl, $hideTitle) {
$module = new \Modularity\Module();
$module->slug = $slug;
$module->nameSingular = $nameSingular;
$module->namePlural = $namePlural;
$module->description = $description;
$module->supports = $supports;
$module->icon = $icon;
$module->plugin = $plugin;
$module->cacheTtl = $cache_ttl;
$module->hideTitle = $hideTitle;
$module->isDeprecated = $this->isDeprecated;
$module->ghost = true;
$class = get_class($this);
$class = explode('\\', $class);
$moduleManager->register($module, MODULARITY_PATH . 'source/php/Module/' . end($class));
});
} | php | public function register($slug, $nameSingular, $namePlural, $description, $supports = array(), $icon = null, $plugin = null, $cache_ttl = 0, $hideTitle = false)
{
//\Modularity\Helper\Wp::deprecatedFunction('Function $module->' . __FUNCTION__ . ' is deprecated since Modularity version 2.0.0');
if (empty($slug)) {
return;
}
add_action('Modularity/Init', function ($moduleManager) use ($slug, $nameSingular, $namePlural, $description, $supports, $icon, $plugin, $cache_ttl, $hideTitle) {
$module = new \Modularity\Module();
$module->slug = $slug;
$module->nameSingular = $nameSingular;
$module->namePlural = $namePlural;
$module->description = $description;
$module->supports = $supports;
$module->icon = $icon;
$module->plugin = $plugin;
$module->cacheTtl = $cache_ttl;
$module->hideTitle = $hideTitle;
$module->isDeprecated = $this->isDeprecated;
$module->ghost = true;
$class = get_class($this);
$class = explode('\\', $class);
$moduleManager->register($module, MODULARITY_PATH . 'source/php/Module/' . end($class));
});
} | [
"public",
"function",
"register",
"(",
"$",
"slug",
",",
"$",
"nameSingular",
",",
"$",
"namePlural",
",",
"$",
"description",
",",
"$",
"supports",
"=",
"array",
"(",
")",
",",
"$",
"icon",
"=",
"null",
",",
"$",
"plugin",
"=",
"null",
",",
"$",
"cache_ttl",
"=",
"0",
",",
"$",
"hideTitle",
"=",
"false",
")",
"{",
"//\\Modularity\\Helper\\Wp::deprecatedFunction('Function $module->' . __FUNCTION__ . ' is deprecated since Modularity version 2.0.0');",
"if",
"(",
"empty",
"(",
"$",
"slug",
")",
")",
"{",
"return",
";",
"}",
"add_action",
"(",
"'Modularity/Init'",
",",
"function",
"(",
"$",
"moduleManager",
")",
"use",
"(",
"$",
"slug",
",",
"$",
"nameSingular",
",",
"$",
"namePlural",
",",
"$",
"description",
",",
"$",
"supports",
",",
"$",
"icon",
",",
"$",
"plugin",
",",
"$",
"cache_ttl",
",",
"$",
"hideTitle",
")",
"{",
"$",
"module",
"=",
"new",
"\\",
"Modularity",
"\\",
"Module",
"(",
")",
";",
"$",
"module",
"->",
"slug",
"=",
"$",
"slug",
";",
"$",
"module",
"->",
"nameSingular",
"=",
"$",
"nameSingular",
";",
"$",
"module",
"->",
"namePlural",
"=",
"$",
"namePlural",
";",
"$",
"module",
"->",
"description",
"=",
"$",
"description",
";",
"$",
"module",
"->",
"supports",
"=",
"$",
"supports",
";",
"$",
"module",
"->",
"icon",
"=",
"$",
"icon",
";",
"$",
"module",
"->",
"plugin",
"=",
"$",
"plugin",
";",
"$",
"module",
"->",
"cacheTtl",
"=",
"$",
"cache_ttl",
";",
"$",
"module",
"->",
"hideTitle",
"=",
"$",
"hideTitle",
";",
"$",
"module",
"->",
"isDeprecated",
"=",
"$",
"this",
"->",
"isDeprecated",
";",
"$",
"module",
"->",
"ghost",
"=",
"true",
";",
"$",
"class",
"=",
"get_class",
"(",
"$",
"this",
")",
";",
"$",
"class",
"=",
"explode",
"(",
"'\\\\'",
",",
"$",
"class",
")",
";",
"$",
"moduleManager",
"->",
"register",
"(",
"$",
"module",
",",
"MODULARITY_PATH",
".",
"'source/php/Module/'",
".",
"end",
"(",
"$",
"class",
")",
")",
";",
"}",
")",
";",
"}"
]
| Registers a Modularity module
@deprecated 2.0.0
@deprecated No longer used by internal code and not recommended, exists as fallback for old third party modules
@deprecated Now creates a "ghost" module class to initialize old module type
@param string $slug Module id suffix (will be prefixed with constant MODULE_PREFIX)
@param string $nameSingular Singular name of the module
@param string $namePlural Plural name of the module
@param string $description Description of the module
@param array $supports Which core post type fileds this module supports
@param string $icon
@param string $plugin
@param int $cache_ttl
@param bool $hideTitle
@return string The prefixed module id/slug | [
"Registers",
"a",
"Modularity",
"module"
]
| db4fcde30ba5db4fac9c8b3c3475c8229b50271d | https://github.com/helsingborg-stad/Modularity/blob/db4fcde30ba5db4fac9c8b3c3475c8229b50271d/source/php/Module.php#L340-L366 | train |
helsingborg-stad/Modularity | source/php/Module/WpWidget/WpWidget.php | WpWidget.displayWidget | public static function displayWidget($widget, $instance = array())
{
if (array_key_exists($widget, \Modularity\Module\WpWidget\WpWidget::getWidgetIndexList()) && class_exists($widget)) {
the_widget($widget, $instance);
} else {
echo "Error: Widget prohibited or class not found.";
}
} | php | public static function displayWidget($widget, $instance = array())
{
if (array_key_exists($widget, \Modularity\Module\WpWidget\WpWidget::getWidgetIndexList()) && class_exists($widget)) {
the_widget($widget, $instance);
} else {
echo "Error: Widget prohibited or class not found.";
}
} | [
"public",
"static",
"function",
"displayWidget",
"(",
"$",
"widget",
",",
"$",
"instance",
"=",
"array",
"(",
")",
")",
"{",
"if",
"(",
"array_key_exists",
"(",
"$",
"widget",
",",
"\\",
"Modularity",
"\\",
"Module",
"\\",
"WpWidget",
"\\",
"WpWidget",
"::",
"getWidgetIndexList",
"(",
")",
")",
"&&",
"class_exists",
"(",
"$",
"widget",
")",
")",
"{",
"the_widget",
"(",
"$",
"widget",
",",
"$",
"instance",
")",
";",
"}",
"else",
"{",
"echo",
"\"Error: Widget prohibited or class not found.\"",
";",
"}",
"}"
]
| Displays the widget
@param string $widget The widget type
@param array $instance The widget instance
@return void | [
"Displays",
"the",
"widget"
]
| db4fcde30ba5db4fac9c8b3c3475c8229b50271d | https://github.com/helsingborg-stad/Modularity/blob/db4fcde30ba5db4fac9c8b3c3475c8229b50271d/source/php/Module/WpWidget/WpWidget.php#L36-L43 | train |
helsingborg-stad/Modularity | source/php/Module/WpWidget/WpWidget.php | WpWidget.tagCloudTaxonomies | public function tagCloudTaxonomies($field)
{
$taxonomies = get_taxonomies(array('show_tagcloud' => true), 'object');
foreach ($taxonomies as $key => $value) {
$field['choices'][$key] = $value->labels->name;
}
return $field;
} | php | public function tagCloudTaxonomies($field)
{
$taxonomies = get_taxonomies(array('show_tagcloud' => true), 'object');
foreach ($taxonomies as $key => $value) {
$field['choices'][$key] = $value->labels->name;
}
return $field;
} | [
"public",
"function",
"tagCloudTaxonomies",
"(",
"$",
"field",
")",
"{",
"$",
"taxonomies",
"=",
"get_taxonomies",
"(",
"array",
"(",
"'show_tagcloud'",
"=>",
"true",
")",
",",
"'object'",
")",
";",
"foreach",
"(",
"$",
"taxonomies",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"$",
"field",
"[",
"'choices'",
"]",
"[",
"$",
"key",
"]",
"=",
"$",
"value",
"->",
"labels",
"->",
"name",
";",
"}",
"return",
"$",
"field",
";",
"}"
]
| Add taxonomies to tag cloud widget form
@param array $field
@return array | [
"Add",
"taxonomies",
"to",
"tag",
"cloud",
"widget",
"form"
]
| db4fcde30ba5db4fac9c8b3c3475c8229b50271d | https://github.com/helsingborg-stad/Modularity/blob/db4fcde30ba5db4fac9c8b3c3475c8229b50271d/source/php/Module/WpWidget/WpWidget.php#L60-L69 | train |
helsingborg-stad/Modularity | source/php/Module/Posts/PostsFilters.php | PostsFilters.doPostTaxonomyFiltering | public function doPostTaxonomyFiltering($query)
{
if (is_admin()) {
return $query;
}
$postType = $this->postType;
$filterable = $this->getEnabledTaxonomies($postType);
if (empty($filterable)) {
return $query;
}
$taxQuery = array('relation' => 'AND');
foreach ($filterable as $key => $value) {
if (!isset($_GET['filter'][$key]) || empty($_GET['filter'][$key]) || $_GET['filter'][$key] === '-1') {
continue;
}
$terms = (array)$_GET['filter'][$key];
$taxQuery[] = array(
'taxonomy' => $key,
'field' => 'slug',
'terms' => $terms,
'operator' => 'IN'
);
}
if (is_tax() || is_category() || is_tag()) {
$taxQuery = array(
'relation' => 'AND',
array(
'relation' => 'AND',
array(
'taxonomy' => get_queried_object()->taxonomy,
'field' => 'slug',
'terms' => (array)get_queried_object()->slug,
'operator' => 'IN'
)
),
$taxQuery
);
}
$query->set('tax_query', $taxQuery);
$query->set('post_type', get_field('posts_data_post_type', $this->moduleId));
return $query;
} | php | public function doPostTaxonomyFiltering($query)
{
if (is_admin()) {
return $query;
}
$postType = $this->postType;
$filterable = $this->getEnabledTaxonomies($postType);
if (empty($filterable)) {
return $query;
}
$taxQuery = array('relation' => 'AND');
foreach ($filterable as $key => $value) {
if (!isset($_GET['filter'][$key]) || empty($_GET['filter'][$key]) || $_GET['filter'][$key] === '-1') {
continue;
}
$terms = (array)$_GET['filter'][$key];
$taxQuery[] = array(
'taxonomy' => $key,
'field' => 'slug',
'terms' => $terms,
'operator' => 'IN'
);
}
if (is_tax() || is_category() || is_tag()) {
$taxQuery = array(
'relation' => 'AND',
array(
'relation' => 'AND',
array(
'taxonomy' => get_queried_object()->taxonomy,
'field' => 'slug',
'terms' => (array)get_queried_object()->slug,
'operator' => 'IN'
)
),
$taxQuery
);
}
$query->set('tax_query', $taxQuery);
$query->set('post_type', get_field('posts_data_post_type', $this->moduleId));
return $query;
} | [
"public",
"function",
"doPostTaxonomyFiltering",
"(",
"$",
"query",
")",
"{",
"if",
"(",
"is_admin",
"(",
")",
")",
"{",
"return",
"$",
"query",
";",
"}",
"$",
"postType",
"=",
"$",
"this",
"->",
"postType",
";",
"$",
"filterable",
"=",
"$",
"this",
"->",
"getEnabledTaxonomies",
"(",
"$",
"postType",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"filterable",
")",
")",
"{",
"return",
"$",
"query",
";",
"}",
"$",
"taxQuery",
"=",
"array",
"(",
"'relation'",
"=>",
"'AND'",
")",
";",
"foreach",
"(",
"$",
"filterable",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"_GET",
"[",
"'filter'",
"]",
"[",
"$",
"key",
"]",
")",
"||",
"empty",
"(",
"$",
"_GET",
"[",
"'filter'",
"]",
"[",
"$",
"key",
"]",
")",
"||",
"$",
"_GET",
"[",
"'filter'",
"]",
"[",
"$",
"key",
"]",
"===",
"'-1'",
")",
"{",
"continue",
";",
"}",
"$",
"terms",
"=",
"(",
"array",
")",
"$",
"_GET",
"[",
"'filter'",
"]",
"[",
"$",
"key",
"]",
";",
"$",
"taxQuery",
"[",
"]",
"=",
"array",
"(",
"'taxonomy'",
"=>",
"$",
"key",
",",
"'field'",
"=>",
"'slug'",
",",
"'terms'",
"=>",
"$",
"terms",
",",
"'operator'",
"=>",
"'IN'",
")",
";",
"}",
"if",
"(",
"is_tax",
"(",
")",
"||",
"is_category",
"(",
")",
"||",
"is_tag",
"(",
")",
")",
"{",
"$",
"taxQuery",
"=",
"array",
"(",
"'relation'",
"=>",
"'AND'",
",",
"array",
"(",
"'relation'",
"=>",
"'AND'",
",",
"array",
"(",
"'taxonomy'",
"=>",
"get_queried_object",
"(",
")",
"->",
"taxonomy",
",",
"'field'",
"=>",
"'slug'",
",",
"'terms'",
"=>",
"(",
"array",
")",
"get_queried_object",
"(",
")",
"->",
"slug",
",",
"'operator'",
"=>",
"'IN'",
")",
")",
",",
"$",
"taxQuery",
")",
";",
"}",
"$",
"query",
"->",
"set",
"(",
"'tax_query'",
",",
"$",
"taxQuery",
")",
";",
"$",
"query",
"->",
"set",
"(",
"'post_type'",
",",
"get_field",
"(",
"'posts_data_post_type'",
",",
"$",
"this",
"->",
"moduleId",
")",
")",
";",
"return",
"$",
"query",
";",
"}"
]
| Do taxonomy filtering
@param object $query Query object
@return object Modified query | [
"Do",
"taxonomy",
"filtering"
]
| db4fcde30ba5db4fac9c8b3c3475c8229b50271d | https://github.com/helsingborg-stad/Modularity/blob/db4fcde30ba5db4fac9c8b3c3475c8229b50271d/source/php/Module/Posts/PostsFilters.php#L47-L97 | train |
helsingborg-stad/Modularity | source/php/Module/Posts/PostsFilters.php | PostsFilters.getSearchQuery | public function getSearchQuery($where, $query)
{
if (is_admin() || $query->is_main_query()) {
return $where;
}
global $wpdb;
if (isset($_GET['search']) && !empty($_GET['search'])) {
$search = sanitize_text_field(esc_attr($_GET['search']));
$where .= " AND ($wpdb->posts.post_title LIKE '%$search%' ) OR ($wpdb->posts.post_content LIKE '%$search%' ) ";
}
return $where;
} | php | public function getSearchQuery($where, $query)
{
if (is_admin() || $query->is_main_query()) {
return $where;
}
global $wpdb;
if (isset($_GET['search']) && !empty($_GET['search'])) {
$search = sanitize_text_field(esc_attr($_GET['search']));
$where .= " AND ($wpdb->posts.post_title LIKE '%$search%' ) OR ($wpdb->posts.post_content LIKE '%$search%' ) ";
}
return $where;
} | [
"public",
"function",
"getSearchQuery",
"(",
"$",
"where",
",",
"$",
"query",
")",
"{",
"if",
"(",
"is_admin",
"(",
")",
"||",
"$",
"query",
"->",
"is_main_query",
"(",
")",
")",
"{",
"return",
"$",
"where",
";",
"}",
"global",
"$",
"wpdb",
";",
"if",
"(",
"isset",
"(",
"$",
"_GET",
"[",
"'search'",
"]",
")",
"&&",
"!",
"empty",
"(",
"$",
"_GET",
"[",
"'search'",
"]",
")",
")",
"{",
"$",
"search",
"=",
"sanitize_text_field",
"(",
"esc_attr",
"(",
"$",
"_GET",
"[",
"'search'",
"]",
")",
")",
";",
"$",
"where",
".=",
"\" AND ($wpdb->posts.post_title LIKE '%$search%' ) OR ($wpdb->posts.post_content LIKE '%$search%' ) \"",
";",
"}",
"return",
"$",
"where",
";",
"}"
]
| Returns Add where clause to post query when free text search
@return string refined Search query | [
"Returns",
"Add",
"where",
"clause",
"to",
"post",
"query",
"when",
"free",
"text",
"search"
]
| db4fcde30ba5db4fac9c8b3c3475c8229b50271d | https://github.com/helsingborg-stad/Modularity/blob/db4fcde30ba5db4fac9c8b3c3475c8229b50271d/source/php/Module/Posts/PostsFilters.php#L162-L175 | train |
helsingborg-stad/Modularity | source/php/Options/General.php | General.sidebarIncompatibility | public function sidebarIncompatibility($moduleSpecification, $modulePostType) {
$template = \Modularity\Helper\Post::getPostTemplate(null, true);
$template_sidebars = get_field($template . '_active_sidebars', 'option');
if($template_sidebars) {
$sidebarIncompatibilities = array_flip($template_sidebars);
foreach($template_sidebars as $sidebar) {
$modules = get_field($template . '-' . $sidebar, 'option');
foreach($modules as $module) {
if($modulePostType == $module['label']) {
unset($sidebarIncompatibilities[$sidebar]);
}
}
}
$moduleSpecification['sidebar_incompability'] = array_keys($sidebarIncompatibilities);
}
return $moduleSpecification;
} | php | public function sidebarIncompatibility($moduleSpecification, $modulePostType) {
$template = \Modularity\Helper\Post::getPostTemplate(null, true);
$template_sidebars = get_field($template . '_active_sidebars', 'option');
if($template_sidebars) {
$sidebarIncompatibilities = array_flip($template_sidebars);
foreach($template_sidebars as $sidebar) {
$modules = get_field($template . '-' . $sidebar, 'option');
foreach($modules as $module) {
if($modulePostType == $module['label']) {
unset($sidebarIncompatibilities[$sidebar]);
}
}
}
$moduleSpecification['sidebar_incompability'] = array_keys($sidebarIncompatibilities);
}
return $moduleSpecification;
} | [
"public",
"function",
"sidebarIncompatibility",
"(",
"$",
"moduleSpecification",
",",
"$",
"modulePostType",
")",
"{",
"$",
"template",
"=",
"\\",
"Modularity",
"\\",
"Helper",
"\\",
"Post",
"::",
"getPostTemplate",
"(",
"null",
",",
"true",
")",
";",
"$",
"template_sidebars",
"=",
"get_field",
"(",
"$",
"template",
".",
"'_active_sidebars'",
",",
"'option'",
")",
";",
"if",
"(",
"$",
"template_sidebars",
")",
"{",
"$",
"sidebarIncompatibilities",
"=",
"array_flip",
"(",
"$",
"template_sidebars",
")",
";",
"foreach",
"(",
"$",
"template_sidebars",
"as",
"$",
"sidebar",
")",
"{",
"$",
"modules",
"=",
"get_field",
"(",
"$",
"template",
".",
"'-'",
".",
"$",
"sidebar",
",",
"'option'",
")",
";",
"foreach",
"(",
"$",
"modules",
"as",
"$",
"module",
")",
"{",
"if",
"(",
"$",
"modulePostType",
"==",
"$",
"module",
"[",
"'label'",
"]",
")",
"{",
"unset",
"(",
"$",
"sidebarIncompatibilities",
"[",
"$",
"sidebar",
"]",
")",
";",
"}",
"}",
"}",
"$",
"moduleSpecification",
"[",
"'sidebar_incompability'",
"]",
"=",
"array_keys",
"(",
"$",
"sidebarIncompatibilities",
")",
";",
"}",
"return",
"$",
"moduleSpecification",
";",
"}"
]
| Filters the sidebar incompatibility list based on the restrictive
options page.
@return array Module Specification | [
"Filters",
"the",
"sidebar",
"incompatibility",
"list",
"based",
"on",
"the",
"restrictive",
"options",
"page",
"."
]
| db4fcde30ba5db4fac9c8b3c3475c8229b50271d | https://github.com/helsingborg-stad/Modularity/blob/db4fcde30ba5db4fac9c8b3c3475c8229b50271d/source/php/Options/General.php#L71-L89 | train |
helsingborg-stad/Modularity | source/php/Options/General.php | General.addMetaBoxes | public function addMetaBoxes()
{
// Publish
add_meta_box(
'modularity-mb-publish',
__('Save options', 'modularity'),
function () {
$templatePath = \Modularity\Helper\Wp::getTemplate('publish', 'options/partials');
include $templatePath;
},
$this->screenHook,
'side'
);
// Core options
add_meta_box(
'modularity-mb-core-options',
__('Core options', 'modularity'),
function () {
$templatePath = \Modularity\Helper\Wp::getTemplate('core-options', 'options/partials');
include $templatePath;
},
$this->screenHook,
'normal'
);
if (has_action('Modularity/Options/Module')) {
add_meta_box(
'modularity-mb-module-options',
__('Module options', 'modularity'),
function () {
do_action('Modularity/Options/Module');
},
$this->screenHook,
'normal'
);
}
// Modules
add_meta_box(
'modularity-mb-post-types',
__('Post types', 'modularity'),
array($this, 'metaBoxPostTypes'),
$this->screenHook,
'normal'
);
// Templates and areas
add_meta_box(
'modularity-mb-template-areas',
__('Template areas', 'modularity'),
array($this, 'metaBoxTemplateAreas'),
$this->screenHook,
'normal'
);
// Modules
add_meta_box(
'modularity-mb-modules',
__('Modules', 'modularity'),
array($this, 'metaBoxModules'),
$this->screenHook,
'normal'
);
} | php | public function addMetaBoxes()
{
// Publish
add_meta_box(
'modularity-mb-publish',
__('Save options', 'modularity'),
function () {
$templatePath = \Modularity\Helper\Wp::getTemplate('publish', 'options/partials');
include $templatePath;
},
$this->screenHook,
'side'
);
// Core options
add_meta_box(
'modularity-mb-core-options',
__('Core options', 'modularity'),
function () {
$templatePath = \Modularity\Helper\Wp::getTemplate('core-options', 'options/partials');
include $templatePath;
},
$this->screenHook,
'normal'
);
if (has_action('Modularity/Options/Module')) {
add_meta_box(
'modularity-mb-module-options',
__('Module options', 'modularity'),
function () {
do_action('Modularity/Options/Module');
},
$this->screenHook,
'normal'
);
}
// Modules
add_meta_box(
'modularity-mb-post-types',
__('Post types', 'modularity'),
array($this, 'metaBoxPostTypes'),
$this->screenHook,
'normal'
);
// Templates and areas
add_meta_box(
'modularity-mb-template-areas',
__('Template areas', 'modularity'),
array($this, 'metaBoxTemplateAreas'),
$this->screenHook,
'normal'
);
// Modules
add_meta_box(
'modularity-mb-modules',
__('Modules', 'modularity'),
array($this, 'metaBoxModules'),
$this->screenHook,
'normal'
);
} | [
"public",
"function",
"addMetaBoxes",
"(",
")",
"{",
"// Publish",
"add_meta_box",
"(",
"'modularity-mb-publish'",
",",
"__",
"(",
"'Save options'",
",",
"'modularity'",
")",
",",
"function",
"(",
")",
"{",
"$",
"templatePath",
"=",
"\\",
"Modularity",
"\\",
"Helper",
"\\",
"Wp",
"::",
"getTemplate",
"(",
"'publish'",
",",
"'options/partials'",
")",
";",
"include",
"$",
"templatePath",
";",
"}",
",",
"$",
"this",
"->",
"screenHook",
",",
"'side'",
")",
";",
"// Core options",
"add_meta_box",
"(",
"'modularity-mb-core-options'",
",",
"__",
"(",
"'Core options'",
",",
"'modularity'",
")",
",",
"function",
"(",
")",
"{",
"$",
"templatePath",
"=",
"\\",
"Modularity",
"\\",
"Helper",
"\\",
"Wp",
"::",
"getTemplate",
"(",
"'core-options'",
",",
"'options/partials'",
")",
";",
"include",
"$",
"templatePath",
";",
"}",
",",
"$",
"this",
"->",
"screenHook",
",",
"'normal'",
")",
";",
"if",
"(",
"has_action",
"(",
"'Modularity/Options/Module'",
")",
")",
"{",
"add_meta_box",
"(",
"'modularity-mb-module-options'",
",",
"__",
"(",
"'Module options'",
",",
"'modularity'",
")",
",",
"function",
"(",
")",
"{",
"do_action",
"(",
"'Modularity/Options/Module'",
")",
";",
"}",
",",
"$",
"this",
"->",
"screenHook",
",",
"'normal'",
")",
";",
"}",
"// Modules",
"add_meta_box",
"(",
"'modularity-mb-post-types'",
",",
"__",
"(",
"'Post types'",
",",
"'modularity'",
")",
",",
"array",
"(",
"$",
"this",
",",
"'metaBoxPostTypes'",
")",
",",
"$",
"this",
"->",
"screenHook",
",",
"'normal'",
")",
";",
"// Templates and areas",
"add_meta_box",
"(",
"'modularity-mb-template-areas'",
",",
"__",
"(",
"'Template areas'",
",",
"'modularity'",
")",
",",
"array",
"(",
"$",
"this",
",",
"'metaBoxTemplateAreas'",
")",
",",
"$",
"this",
"->",
"screenHook",
",",
"'normal'",
")",
";",
"// Modules",
"add_meta_box",
"(",
"'modularity-mb-modules'",
",",
"__",
"(",
"'Modules'",
",",
"'modularity'",
")",
",",
"array",
"(",
"$",
"this",
",",
"'metaBoxModules'",
")",
",",
"$",
"this",
"->",
"screenHook",
",",
"'normal'",
")",
";",
"}"
]
| Adds meta boxes to the general options page
@return void | [
"Adds",
"meta",
"boxes",
"to",
"the",
"general",
"options",
"page"
]
| db4fcde30ba5db4fac9c8b3c3475c8229b50271d | https://github.com/helsingborg-stad/Modularity/blob/db4fcde30ba5db4fac9c8b3c3475c8229b50271d/source/php/Options/General.php#L119-L183 | train |
helsingborg-stad/Modularity | source/php/Options/General.php | General.metaBoxTemplateAreas | public function metaBoxTemplateAreas()
{
global $wp_registered_sidebars;
global $modularityOptions;
usort($wp_registered_sidebars, function ($a, $b) {
return $a['name'] > $b['name'];
});
$coreTemplates = \Modularity\Helper\Wp::getCoreTemplates();
$coreTemplates = apply_filters('Modularity/CoreTemplatesInTheme', $coreTemplates);
$customTemplates = get_page_templates();
$templates = array_merge($coreTemplates, $customTemplates);
include MODULARITY_TEMPLATE_PATH . 'options/partials/modularity-template-areas.php';
} | php | public function metaBoxTemplateAreas()
{
global $wp_registered_sidebars;
global $modularityOptions;
usort($wp_registered_sidebars, function ($a, $b) {
return $a['name'] > $b['name'];
});
$coreTemplates = \Modularity\Helper\Wp::getCoreTemplates();
$coreTemplates = apply_filters('Modularity/CoreTemplatesInTheme', $coreTemplates);
$customTemplates = get_page_templates();
$templates = array_merge($coreTemplates, $customTemplates);
include MODULARITY_TEMPLATE_PATH . 'options/partials/modularity-template-areas.php';
} | [
"public",
"function",
"metaBoxTemplateAreas",
"(",
")",
"{",
"global",
"$",
"wp_registered_sidebars",
";",
"global",
"$",
"modularityOptions",
";",
"usort",
"(",
"$",
"wp_registered_sidebars",
",",
"function",
"(",
"$",
"a",
",",
"$",
"b",
")",
"{",
"return",
"$",
"a",
"[",
"'name'",
"]",
">",
"$",
"b",
"[",
"'name'",
"]",
";",
"}",
")",
";",
"$",
"coreTemplates",
"=",
"\\",
"Modularity",
"\\",
"Helper",
"\\",
"Wp",
"::",
"getCoreTemplates",
"(",
")",
";",
"$",
"coreTemplates",
"=",
"apply_filters",
"(",
"'Modularity/CoreTemplatesInTheme'",
",",
"$",
"coreTemplates",
")",
";",
"$",
"customTemplates",
"=",
"get_page_templates",
"(",
")",
";",
"$",
"templates",
"=",
"array_merge",
"(",
"$",
"coreTemplates",
",",
"$",
"customTemplates",
")",
";",
"include",
"MODULARITY_TEMPLATE_PATH",
".",
"'options/partials/modularity-template-areas.php'",
";",
"}"
]
| Template areas meta box
@return void | [
"Template",
"areas",
"meta",
"box"
]
| db4fcde30ba5db4fac9c8b3c3475c8229b50271d | https://github.com/helsingborg-stad/Modularity/blob/db4fcde30ba5db4fac9c8b3c3475c8229b50271d/source/php/Options/General.php#L189-L204 | train |
helsingborg-stad/Modularity | source/php/Ajax.php | Ajax.getPost | public function getPost()
{
if (!isset($_POST['id']) || empty($_POST['id']) || is_null($_POST['id'])) {
echo 'false';
wp_die();
}
echo json_encode(get_post($_POST['id']));
wp_die();
} | php | public function getPost()
{
if (!isset($_POST['id']) || empty($_POST['id']) || is_null($_POST['id'])) {
echo 'false';
wp_die();
}
echo json_encode(get_post($_POST['id']));
wp_die();
} | [
"public",
"function",
"getPost",
"(",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"_POST",
"[",
"'id'",
"]",
")",
"||",
"empty",
"(",
"$",
"_POST",
"[",
"'id'",
"]",
")",
"||",
"is_null",
"(",
"$",
"_POST",
"[",
"'id'",
"]",
")",
")",
"{",
"echo",
"'false'",
";",
"wp_die",
"(",
")",
";",
"}",
"echo",
"json_encode",
"(",
"get_post",
"(",
"$",
"_POST",
"[",
"'id'",
"]",
")",
")",
";",
"wp_die",
"(",
")",
";",
"}"
]
| Get a post with ajax
@return string JSON encoded object | [
"Get",
"a",
"post",
"with",
"ajax"
]
| db4fcde30ba5db4fac9c8b3c3475c8229b50271d | https://github.com/helsingborg-stad/Modularity/blob/db4fcde30ba5db4fac9c8b3c3475c8229b50271d/source/php/Ajax.php#L17-L26 | train |
Talesoft/tale-jade | Compiler.php | Compiler.addFilter | public function addFilter($name, $callback)
{
if (!is_callable($callback))
throw new \InvalidArgumentException(
"Argument 2 of addFilter must be valid callback"
);
$this->options['filters'][$name] = $callback;
return $this;
} | php | public function addFilter($name, $callback)
{
if (!is_callable($callback))
throw new \InvalidArgumentException(
"Argument 2 of addFilter must be valid callback"
);
$this->options['filters'][$name] = $callback;
return $this;
} | [
"public",
"function",
"addFilter",
"(",
"$",
"name",
",",
"$",
"callback",
")",
"{",
"if",
"(",
"!",
"is_callable",
"(",
"$",
"callback",
")",
")",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"\"Argument 2 of addFilter must be valid callback\"",
")",
";",
"$",
"this",
"->",
"options",
"[",
"'filters'",
"]",
"[",
"$",
"name",
"]",
"=",
"$",
"callback",
";",
"return",
"$",
"this",
";",
"}"
]
| Adds a filter to the compiler.
This filter can then be used inside jade with the
:<filtername> directive
The callback should have the following signature:
(\Tale\Jade\Parser\Node $node, $indent, $newLine)
where $node is the filter-Node found,
$indent is the current indentation respecting level and pretty-option
and newLine is a new-line respecting the pretty-option
It should return either a PHTML string or a Node-instance
@param string $name the name of the filter
@param callable $callback the filter handler callback
@return $this | [
"Adds",
"a",
"filter",
"to",
"the",
"compiler",
"."
]
| e9405e0f4f6b252514cbb27431e13e04cf44614e | https://github.com/Talesoft/tale-jade/blob/e9405e0f4f6b252514cbb27431e13e04cf44614e/Compiler.php#L418-L429 | train |
Talesoft/tale-jade | Compiler.php | Compiler.compileFile | public function compileFile($path)
{
$fullPath = $this->resolvePath($path);
if (!$fullPath)
$this->throwException(
"Template file [$path] could not be resolved in the following paths: [".
implode(', ', $this->options['paths']).
"], Extensions: [".implode(', ', $this->options['extensions']).
"], Include path: ".get_include_path()."]\n\n".
"Make sure the paths are configured correctly. If you're missing a path, add it with the [`paths`] ".
"option or the [`->addPath`]-method."
);
return $this->compile(file_get_contents($fullPath), $fullPath);
} | php | public function compileFile($path)
{
$fullPath = $this->resolvePath($path);
if (!$fullPath)
$this->throwException(
"Template file [$path] could not be resolved in the following paths: [".
implode(', ', $this->options['paths']).
"], Extensions: [".implode(', ', $this->options['extensions']).
"], Include path: ".get_include_path()."]\n\n".
"Make sure the paths are configured correctly. If you're missing a path, add it with the [`paths`] ".
"option or the [`->addPath`]-method."
);
return $this->compile(file_get_contents($fullPath), $fullPath);
} | [
"public",
"function",
"compileFile",
"(",
"$",
"path",
")",
"{",
"$",
"fullPath",
"=",
"$",
"this",
"->",
"resolvePath",
"(",
"$",
"path",
")",
";",
"if",
"(",
"!",
"$",
"fullPath",
")",
"$",
"this",
"->",
"throwException",
"(",
"\"Template file [$path] could not be resolved in the following paths: [\"",
".",
"implode",
"(",
"', '",
",",
"$",
"this",
"->",
"options",
"[",
"'paths'",
"]",
")",
".",
"\"], Extensions: [\"",
".",
"implode",
"(",
"', '",
",",
"$",
"this",
"->",
"options",
"[",
"'extensions'",
"]",
")",
".",
"\"], Include path: \"",
".",
"get_include_path",
"(",
")",
".",
"\"]\\n\\n\"",
".",
"\"Make sure the paths are configured correctly. If you're missing a path, add it with the [`paths`] \"",
".",
"\"option or the [`->addPath`]-method.\"",
")",
";",
"return",
"$",
"this",
"->",
"compile",
"(",
"file_get_contents",
"(",
"$",
"fullPath",
")",
",",
"$",
"fullPath",
")",
";",
"}"
]
| Compiles a file to PHTML.
The given path will automatically passed as
compile()'s $path argument
The path should always be relative to the paths-option paths
@see Compiler->compile
@param string $path the path to the jade file
@return mixed|string the compiled PHTML
@throws \Exception when the file is not found
@throws Exception when the compilation fails
@throws Parser\Exception when the parsing fails
@throws Lexer\Exception when the lexing fails | [
"Compiles",
"a",
"file",
"to",
"PHTML",
"."
]
| e9405e0f4f6b252514cbb27431e13e04cf44614e | https://github.com/Talesoft/tale-jade/blob/e9405e0f4f6b252514cbb27431e13e04cf44614e/Compiler.php#L533-L549 | train |
Talesoft/tale-jade | Compiler.php | Compiler.compileScalar | protected function compileScalar($value, $inCode = false)
{
$sequences = $this->options['escape_sequences'];
foreach ($sequences as $seq => $repl) {
$value = preg_replace('/(?<!\\\\)'.preg_quote($seq, '/').'/', $repl, $value);
}
return $this->interpolate(trim($value, '\'"'), $inCode);
} | php | protected function compileScalar($value, $inCode = false)
{
$sequences = $this->options['escape_sequences'];
foreach ($sequences as $seq => $repl) {
$value = preg_replace('/(?<!\\\\)'.preg_quote($seq, '/').'/', $repl, $value);
}
return $this->interpolate(trim($value, '\'"'), $inCode);
} | [
"protected",
"function",
"compileScalar",
"(",
"$",
"value",
",",
"$",
"inCode",
"=",
"false",
")",
"{",
"$",
"sequences",
"=",
"$",
"this",
"->",
"options",
"[",
"'escape_sequences'",
"]",
";",
"foreach",
"(",
"$",
"sequences",
"as",
"$",
"seq",
"=>",
"$",
"repl",
")",
"{",
"$",
"value",
"=",
"preg_replace",
"(",
"'/(?<!\\\\\\\\)'",
".",
"preg_quote",
"(",
"$",
"seq",
",",
"'/'",
")",
".",
"'/'",
",",
"$",
"repl",
",",
"$",
"value",
")",
";",
"}",
"return",
"$",
"this",
"->",
"interpolate",
"(",
"trim",
"(",
"$",
"value",
",",
"'\\'\"'",
")",
",",
"$",
"inCode",
")",
";",
"}"
]
| Compiles and sanitizes a scalar value.
@param string $value the scalar value
@param bool|false $inCode is this an attribute value or not
@return string | [
"Compiles",
"and",
"sanitizes",
"a",
"scalar",
"value",
"."
]
| e9405e0f4f6b252514cbb27431e13e04cf44614e | https://github.com/Talesoft/tale-jade/blob/e9405e0f4f6b252514cbb27431e13e04cf44614e/Compiler.php#L642-L653 | train |
Talesoft/tale-jade | Compiler.php | Compiler.indent | protected function indent($offset = 0)
{
return $this->isPretty()
? str_repeat($this->options['indent_style'], ($this->level + $offset) * $this->options['indent_width'])
: '';
} | php | protected function indent($offset = 0)
{
return $this->isPretty()
? str_repeat($this->options['indent_style'], ($this->level + $offset) * $this->options['indent_width'])
: '';
} | [
"protected",
"function",
"indent",
"(",
"$",
"offset",
"=",
"0",
")",
"{",
"return",
"$",
"this",
"->",
"isPretty",
"(",
")",
"?",
"str_repeat",
"(",
"$",
"this",
"->",
"options",
"[",
"'indent_style'",
"]",
",",
"(",
"$",
"this",
"->",
"level",
"+",
"$",
"offset",
")",
"*",
"$",
"this",
"->",
"options",
"[",
"'indent_width'",
"]",
")",
":",
"''",
";",
"}"
]
| Returns indentation respecting the current level and the pretty-option.
The $offset will be added to the current level
@param int $offset an offset added to the level
@return string | [
"Returns",
"indentation",
"respecting",
"the",
"current",
"level",
"and",
"the",
"pretty",
"-",
"option",
"."
]
| e9405e0f4f6b252514cbb27431e13e04cf44614e | https://github.com/Talesoft/tale-jade/blob/e9405e0f4f6b252514cbb27431e13e04cf44614e/Compiler.php#L819-L825 | train |
Talesoft/tale-jade | Compiler.php | Compiler.createCode | protected function createCode($code, $prefix = '<?php ', $suffix = '?>')
{
if (strpos($code, "\n") !== false) {
$this->level++;
$code = implode($this->newLine().$this->indent(), preg_split("/\n[\t ]*/", $code))
.$this->newLine().$this->indent(-1);
$this->level--;
}
return $prefix.$code.$suffix;
} | php | protected function createCode($code, $prefix = '<?php ', $suffix = '?>')
{
if (strpos($code, "\n") !== false) {
$this->level++;
$code = implode($this->newLine().$this->indent(), preg_split("/\n[\t ]*/", $code))
.$this->newLine().$this->indent(-1);
$this->level--;
}
return $prefix.$code.$suffix;
} | [
"protected",
"function",
"createCode",
"(",
"$",
"code",
",",
"$",
"prefix",
"=",
"'<?php '",
",",
"$",
"suffix",
"=",
"'?>'",
")",
"{",
"if",
"(",
"strpos",
"(",
"$",
"code",
",",
"\"\\n\"",
")",
"!==",
"false",
")",
"{",
"$",
"this",
"->",
"level",
"++",
";",
"$",
"code",
"=",
"implode",
"(",
"$",
"this",
"->",
"newLine",
"(",
")",
".",
"$",
"this",
"->",
"indent",
"(",
")",
",",
"preg_split",
"(",
"\"/\\n[\\t ]*/\"",
",",
"$",
"code",
")",
")",
".",
"$",
"this",
"->",
"newLine",
"(",
")",
".",
"$",
"this",
"->",
"indent",
"(",
"-",
"1",
")",
";",
"$",
"this",
"->",
"level",
"--",
";",
"}",
"return",
"$",
"prefix",
".",
"$",
"code",
".",
"$",
"suffix",
";",
"}"
]
| Creates a PHP code expression.
By default it will have <?php ? >-style
@param string $code the PHP code
@param string $prefix the PHP start tag
@param string $suffix the PHP end tag
@return string the PHP expression | [
"Creates",
"a",
"PHP",
"code",
"expression",
"."
]
| e9405e0f4f6b252514cbb27431e13e04cf44614e | https://github.com/Talesoft/tale-jade/blob/e9405e0f4f6b252514cbb27431e13e04cf44614e/Compiler.php#L838-L850 | train |
Talesoft/tale-jade | Compiler.php | Compiler.compileDoctype | protected function compileDoctype(Node $node)
{
$name = $node->name;
$value = isset($this->options['doctypes'][$name]) ? $this->options['doctypes'][$name] : '<!DOCTYPE '.$name.'>';
if ($name === 'xml') {
$this->options['mode'] = self::MODE_XML;
if ($this->options['echo_xml_doctype'])
$value = "<?='$value'?>";
} else if (in_array($name, $this->options['xhtml_modes']))
$this->options['mode'] = self::MODE_XHTML;
else
$this->options['mode'] = self::MODE_HTML;
return $value;
} | php | protected function compileDoctype(Node $node)
{
$name = $node->name;
$value = isset($this->options['doctypes'][$name]) ? $this->options['doctypes'][$name] : '<!DOCTYPE '.$name.'>';
if ($name === 'xml') {
$this->options['mode'] = self::MODE_XML;
if ($this->options['echo_xml_doctype'])
$value = "<?='$value'?>";
} else if (in_array($name, $this->options['xhtml_modes']))
$this->options['mode'] = self::MODE_XHTML;
else
$this->options['mode'] = self::MODE_HTML;
return $value;
} | [
"protected",
"function",
"compileDoctype",
"(",
"Node",
"$",
"node",
")",
"{",
"$",
"name",
"=",
"$",
"node",
"->",
"name",
";",
"$",
"value",
"=",
"isset",
"(",
"$",
"this",
"->",
"options",
"[",
"'doctypes'",
"]",
"[",
"$",
"name",
"]",
")",
"?",
"$",
"this",
"->",
"options",
"[",
"'doctypes'",
"]",
"[",
"$",
"name",
"]",
":",
"'<!DOCTYPE '",
".",
"$",
"name",
".",
"'>'",
";",
"if",
"(",
"$",
"name",
"===",
"'xml'",
")",
"{",
"$",
"this",
"->",
"options",
"[",
"'mode'",
"]",
"=",
"self",
"::",
"MODE_XML",
";",
"if",
"(",
"$",
"this",
"->",
"options",
"[",
"'echo_xml_doctype'",
"]",
")",
"$",
"value",
"=",
"\"<?='$value'?>\"",
";",
"}",
"else",
"if",
"(",
"in_array",
"(",
"$",
"name",
",",
"$",
"this",
"->",
"options",
"[",
"'xhtml_modes'",
"]",
")",
")",
"$",
"this",
"->",
"options",
"[",
"'mode'",
"]",
"=",
"self",
"::",
"MODE_XHTML",
";",
"else",
"$",
"this",
"->",
"options",
"[",
"'mode'",
"]",
"=",
"self",
"::",
"MODE_HTML",
";",
"return",
"$",
"value",
";",
"}"
]
| Compiles a doctype Node to PHTML.
@param Node $node the doctype-type node
@return string the compiled PHTML | [
"Compiles",
"a",
"doctype",
"Node",
"to",
"PHTML",
"."
]
| e9405e0f4f6b252514cbb27431e13e04cf44614e | https://github.com/Talesoft/tale-jade/blob/e9405e0f4f6b252514cbb27431e13e04cf44614e/Compiler.php#L964-L983 | train |
Talesoft/tale-jade | Compiler.php | Compiler.resolvePath | public function resolvePath($path, $extensions = null)
{
$paths = $this->options['paths'];
$exts = $extensions ? $extensions : $this->options['extensions'];
if (is_array($exts)) {
foreach ($exts as $ext)
if ($resolved = $this->resolvePath($path, $ext))
return $resolved;
return false;
}
$ext = $exts;
if (substr($path, -strlen($ext)) !== $ext)
$path .= $ext;
//Check static path
if (file_exists($path))
return $path;
if (count($paths) < 1) {
//We got no paths to search in. We use the include-path in that case
$paths = explode(\PATH_SEPARATOR, get_include_path());
}
//Add the path were currently compiling in (e.g. include, extends)
if (count($this->files) > 0)
$paths[] = dirname(end($this->files));
//Iterate paths and check file existence via realpath
foreach ($paths as $directory) {
$fullPath = realpath(rtrim($directory, '/\\').'/'.ltrim($path, '/\\'));
if ($fullPath)
return $fullPath;
}
return false;
} | php | public function resolvePath($path, $extensions = null)
{
$paths = $this->options['paths'];
$exts = $extensions ? $extensions : $this->options['extensions'];
if (is_array($exts)) {
foreach ($exts as $ext)
if ($resolved = $this->resolvePath($path, $ext))
return $resolved;
return false;
}
$ext = $exts;
if (substr($path, -strlen($ext)) !== $ext)
$path .= $ext;
//Check static path
if (file_exists($path))
return $path;
if (count($paths) < 1) {
//We got no paths to search in. We use the include-path in that case
$paths = explode(\PATH_SEPARATOR, get_include_path());
}
//Add the path were currently compiling in (e.g. include, extends)
if (count($this->files) > 0)
$paths[] = dirname(end($this->files));
//Iterate paths and check file existence via realpath
foreach ($paths as $directory) {
$fullPath = realpath(rtrim($directory, '/\\').'/'.ltrim($path, '/\\'));
if ($fullPath)
return $fullPath;
}
return false;
} | [
"public",
"function",
"resolvePath",
"(",
"$",
"path",
",",
"$",
"extensions",
"=",
"null",
")",
"{",
"$",
"paths",
"=",
"$",
"this",
"->",
"options",
"[",
"'paths'",
"]",
";",
"$",
"exts",
"=",
"$",
"extensions",
"?",
"$",
"extensions",
":",
"$",
"this",
"->",
"options",
"[",
"'extensions'",
"]",
";",
"if",
"(",
"is_array",
"(",
"$",
"exts",
")",
")",
"{",
"foreach",
"(",
"$",
"exts",
"as",
"$",
"ext",
")",
"if",
"(",
"$",
"resolved",
"=",
"$",
"this",
"->",
"resolvePath",
"(",
"$",
"path",
",",
"$",
"ext",
")",
")",
"return",
"$",
"resolved",
";",
"return",
"false",
";",
"}",
"$",
"ext",
"=",
"$",
"exts",
";",
"if",
"(",
"substr",
"(",
"$",
"path",
",",
"-",
"strlen",
"(",
"$",
"ext",
")",
")",
"!==",
"$",
"ext",
")",
"$",
"path",
".=",
"$",
"ext",
";",
"//Check static path",
"if",
"(",
"file_exists",
"(",
"$",
"path",
")",
")",
"return",
"$",
"path",
";",
"if",
"(",
"count",
"(",
"$",
"paths",
")",
"<",
"1",
")",
"{",
"//We got no paths to search in. We use the include-path in that case",
"$",
"paths",
"=",
"explode",
"(",
"\\",
"PATH_SEPARATOR",
",",
"get_include_path",
"(",
")",
")",
";",
"}",
"//Add the path were currently compiling in (e.g. include, extends)",
"if",
"(",
"count",
"(",
"$",
"this",
"->",
"files",
")",
">",
"0",
")",
"$",
"paths",
"[",
"]",
"=",
"dirname",
"(",
"end",
"(",
"$",
"this",
"->",
"files",
")",
")",
";",
"//Iterate paths and check file existence via realpath",
"foreach",
"(",
"$",
"paths",
"as",
"$",
"directory",
")",
"{",
"$",
"fullPath",
"=",
"realpath",
"(",
"rtrim",
"(",
"$",
"directory",
",",
"'/\\\\'",
")",
".",
"'/'",
".",
"ltrim",
"(",
"$",
"path",
",",
"'/\\\\'",
")",
")",
";",
"if",
"(",
"$",
"fullPath",
")",
"return",
"$",
"fullPath",
";",
"}",
"return",
"false",
";",
"}"
]
| Resolves a path respecting the paths given in the options.
The final paths for resolving are put together as follows:
when paths options not empty => Add paths of paths-option
when paths option empty => Add paths of get_include_path()
when current file stack not empty => Add directory of last file we
were compiling
We then look for a path with the given extension inside
all paths we work on currently
@param string $path the relative path to resolve
@param array|string $extensions the extensions to resolve with
@return string|false the resolved full path or false, if not found | [
"Resolves",
"a",
"path",
"respecting",
"the",
"paths",
"given",
"in",
"the",
"options",
"."
]
| e9405e0f4f6b252514cbb27431e13e04cf44614e | https://github.com/Talesoft/tale-jade/blob/e9405e0f4f6b252514cbb27431e13e04cf44614e/Compiler.php#L1003-L1047 | train |
Talesoft/tale-jade | Compiler.php | Compiler.handleImports | protected function handleImports(Node $node)
{
foreach ($node->find('import') as $importNode) {
if (!$this->options['allow_imports'])
$this->throwException(
'Imports are disabled in this Jade compiler instance through the [`allow_imports`] option. '.
'Set it to [`false`] (default) to enable imports again',
$node
);
$this->handleImport($importNode);
}
return $this;
} | php | protected function handleImports(Node $node)
{
foreach ($node->find('import') as $importNode) {
if (!$this->options['allow_imports'])
$this->throwException(
'Imports are disabled in this Jade compiler instance through the [`allow_imports`] option. '.
'Set it to [`false`] (default) to enable imports again',
$node
);
$this->handleImport($importNode);
}
return $this;
} | [
"protected",
"function",
"handleImports",
"(",
"Node",
"$",
"node",
")",
"{",
"foreach",
"(",
"$",
"node",
"->",
"find",
"(",
"'import'",
")",
"as",
"$",
"importNode",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"options",
"[",
"'allow_imports'",
"]",
")",
"$",
"this",
"->",
"throwException",
"(",
"'Imports are disabled in this Jade compiler instance through the [`allow_imports`] option. '",
".",
"'Set it to [`false`] (default) to enable imports again'",
",",
"$",
"node",
")",
";",
"$",
"this",
"->",
"handleImport",
"(",
"$",
"importNode",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
]
| Collects all imports and handles them via ->handleImport.
@param Node $node the root Node to search imports in
@return $this
@throws Exception when the allowImports-options is set to false | [
"Collects",
"all",
"imports",
"and",
"handles",
"them",
"via",
"-",
">",
"handleImport",
"."
]
| e9405e0f4f6b252514cbb27431e13e04cf44614e | https://github.com/Talesoft/tale-jade/blob/e9405e0f4f6b252514cbb27431e13e04cf44614e/Compiler.php#L1057-L1073 | train |
Talesoft/tale-jade | Compiler.php | Compiler.handleBlock | protected function handleBlock(Node $node)
{
if (!$node->name || $node->mode === 'ignore') //Will be handled through compileBlock when the loop encounters it
return $this;
//Find all other blocks with that name
foreach ($this->blocks as $block) {
if ($block === $node || $block->name !== $node->name)
continue;
$mode = $block->mode;
//detach from parent
$block->parent->remove($block);
switch ($mode) {
default:
/** @noinspection PhpMissingBreakStatementInspection */
case 'replace':
$node->children = [];
//WANTED FALLTHROUGH!
case 'append':
//Append to master block
foreach ($block->children as $child) {
$block->remove($child);
$node->append($child);
}
break;
case 'prepend':
$last = null;
foreach ($block->children as $child) {
$block->remove($child);
if (!$last) {
$node->prepend($child);
$last = $child;
continue;
}
$node->insertAfter($last, $child);
$last = $child;
}
break;
}
$block->mode = 'ignore';
}
return $this;
} | php | protected function handleBlock(Node $node)
{
if (!$node->name || $node->mode === 'ignore') //Will be handled through compileBlock when the loop encounters it
return $this;
//Find all other blocks with that name
foreach ($this->blocks as $block) {
if ($block === $node || $block->name !== $node->name)
continue;
$mode = $block->mode;
//detach from parent
$block->parent->remove($block);
switch ($mode) {
default:
/** @noinspection PhpMissingBreakStatementInspection */
case 'replace':
$node->children = [];
//WANTED FALLTHROUGH!
case 'append':
//Append to master block
foreach ($block->children as $child) {
$block->remove($child);
$node->append($child);
}
break;
case 'prepend':
$last = null;
foreach ($block->children as $child) {
$block->remove($child);
if (!$last) {
$node->prepend($child);
$last = $child;
continue;
}
$node->insertAfter($last, $child);
$last = $child;
}
break;
}
$block->mode = 'ignore';
}
return $this;
} | [
"protected",
"function",
"handleBlock",
"(",
"Node",
"$",
"node",
")",
"{",
"if",
"(",
"!",
"$",
"node",
"->",
"name",
"||",
"$",
"node",
"->",
"mode",
"===",
"'ignore'",
")",
"//Will be handled through compileBlock when the loop encounters it",
"return",
"$",
"this",
";",
"//Find all other blocks with that name",
"foreach",
"(",
"$",
"this",
"->",
"blocks",
"as",
"$",
"block",
")",
"{",
"if",
"(",
"$",
"block",
"===",
"$",
"node",
"||",
"$",
"block",
"->",
"name",
"!==",
"$",
"node",
"->",
"name",
")",
"continue",
";",
"$",
"mode",
"=",
"$",
"block",
"->",
"mode",
";",
"//detach from parent",
"$",
"block",
"->",
"parent",
"->",
"remove",
"(",
"$",
"block",
")",
";",
"switch",
"(",
"$",
"mode",
")",
"{",
"default",
":",
"/** @noinspection PhpMissingBreakStatementInspection */",
"case",
"'replace'",
":",
"$",
"node",
"->",
"children",
"=",
"[",
"]",
";",
"//WANTED FALLTHROUGH!",
"case",
"'append'",
":",
"//Append to master block",
"foreach",
"(",
"$",
"block",
"->",
"children",
"as",
"$",
"child",
")",
"{",
"$",
"block",
"->",
"remove",
"(",
"$",
"child",
")",
";",
"$",
"node",
"->",
"append",
"(",
"$",
"child",
")",
";",
"}",
"break",
";",
"case",
"'prepend'",
":",
"$",
"last",
"=",
"null",
";",
"foreach",
"(",
"$",
"block",
"->",
"children",
"as",
"$",
"child",
")",
"{",
"$",
"block",
"->",
"remove",
"(",
"$",
"child",
")",
";",
"if",
"(",
"!",
"$",
"last",
")",
"{",
"$",
"node",
"->",
"prepend",
"(",
"$",
"child",
")",
";",
"$",
"last",
"=",
"$",
"child",
";",
"continue",
";",
"}",
"$",
"node",
"->",
"insertAfter",
"(",
"$",
"last",
",",
"$",
"child",
")",
";",
"$",
"last",
"=",
"$",
"child",
";",
"}",
"break",
";",
"}",
"$",
"block",
"->",
"mode",
"=",
"'ignore'",
";",
"}",
"return",
"$",
"this",
";",
"}"
]
| Stacks blocks into each other.
The first block found is always the container,
all other blocks either to append, replace or prepend
to/the first block.
@param Node $node the block node to handle
@return $this | [
"Stacks",
"blocks",
"into",
"each",
"other",
"."
]
| e9405e0f4f6b252514cbb27431e13e04cf44614e | https://github.com/Talesoft/tale-jade/blob/e9405e0f4f6b252514cbb27431e13e04cf44614e/Compiler.php#L1198-L1253 | train |
Talesoft/tale-jade | Compiler.php | Compiler.handleMixins | protected function handleMixins(Node $node)
{
$mixins = $node->findArray('mixin');
//Save all mixins in $this->mixins for our mixinCalls to reference them
foreach ($mixins as $mixinNode) {
if (isset($this->mixins[$mixinNode->name]) && !$this->options['replace_mixins'])
$this->throwException(
"A mixin with the name [$mixinNode->name] is already defined. Rename the it or enable the".
"[`replace_mixins`]-option to be able to overwrite it",
$mixinNode
);
else if (isset($this->mixins[$mixinNode->name]))
$this->mixins[$mixinNode->name]->parent->remove($this->mixins[$mixinNode->name]);
$this->mixins[$mixinNode->name] = $mixinNode;
}
//Handle the mixins
foreach ($this->mixins as $mixinNode)
$this->handleMixin($mixinNode);
return $this;
} | php | protected function handleMixins(Node $node)
{
$mixins = $node->findArray('mixin');
//Save all mixins in $this->mixins for our mixinCalls to reference them
foreach ($mixins as $mixinNode) {
if (isset($this->mixins[$mixinNode->name]) && !$this->options['replace_mixins'])
$this->throwException(
"A mixin with the name [$mixinNode->name] is already defined. Rename the it or enable the".
"[`replace_mixins`]-option to be able to overwrite it",
$mixinNode
);
else if (isset($this->mixins[$mixinNode->name]))
$this->mixins[$mixinNode->name]->parent->remove($this->mixins[$mixinNode->name]);
$this->mixins[$mixinNode->name] = $mixinNode;
}
//Handle the mixins
foreach ($this->mixins as $mixinNode)
$this->handleMixin($mixinNode);
return $this;
} | [
"protected",
"function",
"handleMixins",
"(",
"Node",
"$",
"node",
")",
"{",
"$",
"mixins",
"=",
"$",
"node",
"->",
"findArray",
"(",
"'mixin'",
")",
";",
"//Save all mixins in $this->mixins for our mixinCalls to reference them",
"foreach",
"(",
"$",
"mixins",
"as",
"$",
"mixinNode",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"mixins",
"[",
"$",
"mixinNode",
"->",
"name",
"]",
")",
"&&",
"!",
"$",
"this",
"->",
"options",
"[",
"'replace_mixins'",
"]",
")",
"$",
"this",
"->",
"throwException",
"(",
"\"A mixin with the name [$mixinNode->name] is already defined. Rename the it or enable the\"",
".",
"\"[`replace_mixins`]-option to be able to overwrite it\"",
",",
"$",
"mixinNode",
")",
";",
"else",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"mixins",
"[",
"$",
"mixinNode",
"->",
"name",
"]",
")",
")",
"$",
"this",
"->",
"mixins",
"[",
"$",
"mixinNode",
"->",
"name",
"]",
"->",
"parent",
"->",
"remove",
"(",
"$",
"this",
"->",
"mixins",
"[",
"$",
"mixinNode",
"->",
"name",
"]",
")",
";",
"$",
"this",
"->",
"mixins",
"[",
"$",
"mixinNode",
"->",
"name",
"]",
"=",
"$",
"mixinNode",
";",
"}",
"//Handle the mixins",
"foreach",
"(",
"$",
"this",
"->",
"mixins",
"as",
"$",
"mixinNode",
")",
"$",
"this",
"->",
"handleMixin",
"(",
"$",
"mixinNode",
")",
";",
"return",
"$",
"this",
";",
"}"
]
| Finds all mixins and loops them through handleMixin.
Duplicated mixins will throw an exception if the replaceMixins-options
is false
@param Node $node the node to search mixins in
@return $this
@throws Exception when a mixin name occurs twice and replaceMixins is false | [
"Finds",
"all",
"mixins",
"and",
"loops",
"them",
"through",
"handleMixin",
"."
]
| e9405e0f4f6b252514cbb27431e13e04cf44614e | https://github.com/Talesoft/tale-jade/blob/e9405e0f4f6b252514cbb27431e13e04cf44614e/Compiler.php#L1266-L1291 | train |
Talesoft/tale-jade | Compiler.php | Compiler.compileMixins | protected function compileMixins()
{
if (count($this->mixins) < 1)
return '';
$phtml = '';
$phtml .= $this->createCode('$__mixins = [];').$this->newLine();
foreach ($this->mixins as $name => $mixin) {
//Don't compile the mixin if we dont use it (opt-out)
if (!$this->options['compile_uncalled_mixins'] && !in_array($name, $this->calledMixins, true))
continue; //Skip compilation
//Put the arguments together
$args = [];
$i = 0;
$variadicIndex = null;
$variadicName = null;
foreach ($mixin['node']->attributes as $attr) {
$attrName = $attr->name;
if (strncmp('...', $attrName, 3) === 0) {
$variadicIndex = $i;
$attrName = substr($attrName, 3);
$variadicName = $attrName;
}
$args[$attrName] = $attr->value;
$i++;
}
if ($variadicIndex !== null) {
$args[$variadicName] = "array_slice(\$__arguments, $variadicIndex)";
}
$phtml .= $this->createCode(
'$__mixins[\''.$name.'\'] = function(array $__arguments, array $__scope) {'.
'$__defaults = '.$this->exportArray($args).'; '.
'if (is_numeric(key($__arguments))) extract(array_replace($__scope, array_combine('.
'array_keys($__defaults), array_replace(array_values($__defaults)'.
', array_values($__arguments)))));'.
'else extract(array_replace($__scope, array_replace($__defaults, $__arguments)));
'
).$this->newLine();
$phtml .= $mixin['phtml'].$this->newLine();
$phtml .= $this->createCode('};').$this->newLine();
}
return $phtml;
} | php | protected function compileMixins()
{
if (count($this->mixins) < 1)
return '';
$phtml = '';
$phtml .= $this->createCode('$__mixins = [];').$this->newLine();
foreach ($this->mixins as $name => $mixin) {
//Don't compile the mixin if we dont use it (opt-out)
if (!$this->options['compile_uncalled_mixins'] && !in_array($name, $this->calledMixins, true))
continue; //Skip compilation
//Put the arguments together
$args = [];
$i = 0;
$variadicIndex = null;
$variadicName = null;
foreach ($mixin['node']->attributes as $attr) {
$attrName = $attr->name;
if (strncmp('...', $attrName, 3) === 0) {
$variadicIndex = $i;
$attrName = substr($attrName, 3);
$variadicName = $attrName;
}
$args[$attrName] = $attr->value;
$i++;
}
if ($variadicIndex !== null) {
$args[$variadicName] = "array_slice(\$__arguments, $variadicIndex)";
}
$phtml .= $this->createCode(
'$__mixins[\''.$name.'\'] = function(array $__arguments, array $__scope) {'.
'$__defaults = '.$this->exportArray($args).'; '.
'if (is_numeric(key($__arguments))) extract(array_replace($__scope, array_combine('.
'array_keys($__defaults), array_replace(array_values($__defaults)'.
', array_values($__arguments)))));'.
'else extract(array_replace($__scope, array_replace($__defaults, $__arguments)));
'
).$this->newLine();
$phtml .= $mixin['phtml'].$this->newLine();
$phtml .= $this->createCode('};').$this->newLine();
}
return $phtml;
} | [
"protected",
"function",
"compileMixins",
"(",
")",
"{",
"if",
"(",
"count",
"(",
"$",
"this",
"->",
"mixins",
")",
"<",
"1",
")",
"return",
"''",
";",
"$",
"phtml",
"=",
"''",
";",
"$",
"phtml",
".=",
"$",
"this",
"->",
"createCode",
"(",
"'$__mixins = [];'",
")",
".",
"$",
"this",
"->",
"newLine",
"(",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"mixins",
"as",
"$",
"name",
"=>",
"$",
"mixin",
")",
"{",
"//Don't compile the mixin if we dont use it (opt-out)",
"if",
"(",
"!",
"$",
"this",
"->",
"options",
"[",
"'compile_uncalled_mixins'",
"]",
"&&",
"!",
"in_array",
"(",
"$",
"name",
",",
"$",
"this",
"->",
"calledMixins",
",",
"true",
")",
")",
"continue",
";",
"//Skip compilation",
"//Put the arguments together",
"$",
"args",
"=",
"[",
"]",
";",
"$",
"i",
"=",
"0",
";",
"$",
"variadicIndex",
"=",
"null",
";",
"$",
"variadicName",
"=",
"null",
";",
"foreach",
"(",
"$",
"mixin",
"[",
"'node'",
"]",
"->",
"attributes",
"as",
"$",
"attr",
")",
"{",
"$",
"attrName",
"=",
"$",
"attr",
"->",
"name",
";",
"if",
"(",
"strncmp",
"(",
"'...'",
",",
"$",
"attrName",
",",
"3",
")",
"===",
"0",
")",
"{",
"$",
"variadicIndex",
"=",
"$",
"i",
";",
"$",
"attrName",
"=",
"substr",
"(",
"$",
"attrName",
",",
"3",
")",
";",
"$",
"variadicName",
"=",
"$",
"attrName",
";",
"}",
"$",
"args",
"[",
"$",
"attrName",
"]",
"=",
"$",
"attr",
"->",
"value",
";",
"$",
"i",
"++",
";",
"}",
"if",
"(",
"$",
"variadicIndex",
"!==",
"null",
")",
"{",
"$",
"args",
"[",
"$",
"variadicName",
"]",
"=",
"\"array_slice(\\$__arguments, $variadicIndex)\"",
";",
"}",
"$",
"phtml",
".=",
"$",
"this",
"->",
"createCode",
"(",
"'$__mixins[\\''",
".",
"$",
"name",
".",
"'\\'] = function(array $__arguments, array $__scope) {'",
".",
"'$__defaults = '",
".",
"$",
"this",
"->",
"exportArray",
"(",
"$",
"args",
")",
".",
"'; '",
".",
"'if (is_numeric(key($__arguments))) extract(array_replace($__scope, array_combine('",
".",
"'array_keys($__defaults), array_replace(array_values($__defaults)'",
".",
"', array_values($__arguments)))));'",
".",
"'else extract(array_replace($__scope, array_replace($__defaults, $__arguments)));\n '",
")",
".",
"$",
"this",
"->",
"newLine",
"(",
")",
";",
"$",
"phtml",
".=",
"$",
"mixin",
"[",
"'phtml'",
"]",
".",
"$",
"this",
"->",
"newLine",
"(",
")",
";",
"$",
"phtml",
".=",
"$",
"this",
"->",
"createCode",
"(",
"'};'",
")",
".",
"$",
"this",
"->",
"newLine",
"(",
")",
";",
"}",
"return",
"$",
"phtml",
";",
"}"
]
| Compiles found mixins under each other into a single PHTML block.
Mixins will be anonymous functions inside a $__mixins array
The mixins also pass the global $__args variables on (so that it _is_ global)
@return string The compile PHTML | [
"Compiles",
"found",
"mixins",
"under",
"each",
"other",
"into",
"a",
"single",
"PHTML",
"block",
"."
]
| e9405e0f4f6b252514cbb27431e13e04cf44614e | https://github.com/Talesoft/tale-jade/blob/e9405e0f4f6b252514cbb27431e13e04cf44614e/Compiler.php#L1334-L1387 | train |
Talesoft/tale-jade | Compiler.php | Compiler.compileBlock | protected function compileBlock(Node $node)
{
$name = $node->name;
if (!$name)
return $this->createCode(
'$__scope = \\Tale\\Jade\\Compiler\\create_scope(get_defined_vars()); '.
'echo isset($__block) && $__block instanceof \Closure ? $__block($__scope) : \'\'; '.
'unset($__scope);'
);
//At this point the code knows this block only, since handleBlock took care of the blocks previously
return $this->compileChildren($node->children, false);
} | php | protected function compileBlock(Node $node)
{
$name = $node->name;
if (!$name)
return $this->createCode(
'$__scope = \\Tale\\Jade\\Compiler\\create_scope(get_defined_vars()); '.
'echo isset($__block) && $__block instanceof \Closure ? $__block($__scope) : \'\'; '.
'unset($__scope);'
);
//At this point the code knows this block only, since handleBlock took care of the blocks previously
return $this->compileChildren($node->children, false);
} | [
"protected",
"function",
"compileBlock",
"(",
"Node",
"$",
"node",
")",
"{",
"$",
"name",
"=",
"$",
"node",
"->",
"name",
";",
"if",
"(",
"!",
"$",
"name",
")",
"return",
"$",
"this",
"->",
"createCode",
"(",
"'$__scope = \\\\Tale\\\\Jade\\\\Compiler\\\\create_scope(get_defined_vars()); '",
".",
"'echo isset($__block) && $__block instanceof \\Closure ? $__block($__scope) : \\'\\'; '",
".",
"'unset($__scope);'",
")",
";",
"//At this point the code knows this block only, since handleBlock took care of the blocks previously",
"return",
"$",
"this",
"->",
"compileChildren",
"(",
"$",
"node",
"->",
"children",
",",
"false",
")",
";",
"}"
]
| Compiles a block node into PHTML.
A single block node without a name or mode will act as a wrapper
for blocks inside mixins
@param Node $node the block node to compile
@return string The compiled PHTML | [
"Compiles",
"a",
"block",
"node",
"into",
"PHTML",
"."
]
| e9405e0f4f6b252514cbb27431e13e04cf44614e | https://github.com/Talesoft/tale-jade/blob/e9405e0f4f6b252514cbb27431e13e04cf44614e/Compiler.php#L1527-L1541 | train |
Talesoft/tale-jade | Compiler.php | Compiler.compileConditional | protected function compileConditional(Node $node)
{
$type = $node->conditionType;
$subject = $node->subject;
if ($subject === 'block')
$subject = '$__block';
if ($this->isVariable($subject))
$subject = "isset($subject) ? $subject : false";
if ($type === 'unless') {
$type = 'if';
$subject = "!($subject)";
}
$isPrevConditional = $node->prev() && $node->prev()->type === 'conditional' && $type !== 'if';
$isNextConditional = $node->next()
&& $node->next()->type === 'conditional'
&& $node->next()->conditionType !== 'if'
&& $node->next()->conditionType !== 'unless';
$prefix = $isPrevConditional ? '' : '<?php ';
$suffix = $isNextConditional ? '' : '?>';
$phtml = $type === 'else'
? $this->createCode(' else {', $prefix)
: $this->createCode("$type ($subject) {", $prefix);
$phtml .= $this->compileChildren($node->children);
$phtml .= $this->newLine().$this->indent().$this->createCode("}", '<?php ', $suffix);
return $phtml;
} | php | protected function compileConditional(Node $node)
{
$type = $node->conditionType;
$subject = $node->subject;
if ($subject === 'block')
$subject = '$__block';
if ($this->isVariable($subject))
$subject = "isset($subject) ? $subject : false";
if ($type === 'unless') {
$type = 'if';
$subject = "!($subject)";
}
$isPrevConditional = $node->prev() && $node->prev()->type === 'conditional' && $type !== 'if';
$isNextConditional = $node->next()
&& $node->next()->type === 'conditional'
&& $node->next()->conditionType !== 'if'
&& $node->next()->conditionType !== 'unless';
$prefix = $isPrevConditional ? '' : '<?php ';
$suffix = $isNextConditional ? '' : '?>';
$phtml = $type === 'else'
? $this->createCode(' else {', $prefix)
: $this->createCode("$type ($subject) {", $prefix);
$phtml .= $this->compileChildren($node->children);
$phtml .= $this->newLine().$this->indent().$this->createCode("}", '<?php ', $suffix);
return $phtml;
} | [
"protected",
"function",
"compileConditional",
"(",
"Node",
"$",
"node",
")",
"{",
"$",
"type",
"=",
"$",
"node",
"->",
"conditionType",
";",
"$",
"subject",
"=",
"$",
"node",
"->",
"subject",
";",
"if",
"(",
"$",
"subject",
"===",
"'block'",
")",
"$",
"subject",
"=",
"'$__block'",
";",
"if",
"(",
"$",
"this",
"->",
"isVariable",
"(",
"$",
"subject",
")",
")",
"$",
"subject",
"=",
"\"isset($subject) ? $subject : false\"",
";",
"if",
"(",
"$",
"type",
"===",
"'unless'",
")",
"{",
"$",
"type",
"=",
"'if'",
";",
"$",
"subject",
"=",
"\"!($subject)\"",
";",
"}",
"$",
"isPrevConditional",
"=",
"$",
"node",
"->",
"prev",
"(",
")",
"&&",
"$",
"node",
"->",
"prev",
"(",
")",
"->",
"type",
"===",
"'conditional'",
"&&",
"$",
"type",
"!==",
"'if'",
";",
"$",
"isNextConditional",
"=",
"$",
"node",
"->",
"next",
"(",
")",
"&&",
"$",
"node",
"->",
"next",
"(",
")",
"->",
"type",
"===",
"'conditional'",
"&&",
"$",
"node",
"->",
"next",
"(",
")",
"->",
"conditionType",
"!==",
"'if'",
"&&",
"$",
"node",
"->",
"next",
"(",
")",
"->",
"conditionType",
"!==",
"'unless'",
";",
"$",
"prefix",
"=",
"$",
"isPrevConditional",
"?",
"''",
":",
"'<?php '",
";",
"$",
"suffix",
"=",
"$",
"isNextConditional",
"?",
"''",
":",
"'?>'",
";",
"$",
"phtml",
"=",
"$",
"type",
"===",
"'else'",
"?",
"$",
"this",
"->",
"createCode",
"(",
"' else {'",
",",
"$",
"prefix",
")",
":",
"$",
"this",
"->",
"createCode",
"(",
"\"$type ($subject) {\"",
",",
"$",
"prefix",
")",
";",
"$",
"phtml",
".=",
"$",
"this",
"->",
"compileChildren",
"(",
"$",
"node",
"->",
"children",
")",
";",
"$",
"phtml",
".=",
"$",
"this",
"->",
"newLine",
"(",
")",
".",
"$",
"this",
"->",
"indent",
"(",
")",
".",
"$",
"this",
"->",
"createCode",
"(",
"\"}\"",
",",
"'<?php '",
",",
"$",
"suffix",
")",
";",
"return",
"$",
"phtml",
";",
"}"
]
| Compiles a conditional, either if, elseif, else if or else into PHTML.
@param Node $node the conditional node to compile
@return string The compiled PHTML | [
"Compiles",
"a",
"conditional",
"either",
"if",
"elseif",
"else",
"if",
"or",
"else",
"into",
"PHTML",
"."
]
| e9405e0f4f6b252514cbb27431e13e04cf44614e | https://github.com/Talesoft/tale-jade/blob/e9405e0f4f6b252514cbb27431e13e04cf44614e/Compiler.php#L1550-L1582 | train |
Talesoft/tale-jade | Compiler.php | Compiler.compileCase | protected function compileCase(Node $node)
{
$subject = $node->subject;
if ($this->isVariable($subject))
$subject = "isset({$subject}) ? {$subject} : null";
//Notice that we omit the "? >"
//This is because PHP doesnt allow "? ><?php" between switch and the first case
$phtml = $this->createCode("switch ({$subject}) {", '<?php ', '').$this->newLine();
$phtml .= $this->compileChildren($node->children).$this->newLine();
$phtml .= $this->indent().$this->createCode('}');
//We need to check this after compilation, since there could be when: something children
//that would be like [case children=[[something expands=[when]]] right now
$hasChild = false;
foreach ($node->children as $child) {
if ($child->type !== 'when') {
$this->throwException(
"The `case`-node (`switch`-equivalent) can only have `when`-node children (`case`-equivalent). ".
"A $child->type-node has been provided.",
$node
);
}
$hasChild = true;
}
if (!$hasChild) {
$this->throwException(
"The `case`-node needs at least one `when`-node as a child. Empty `case`-blocks are not allowed as ".
"they can't provide any functionality.",
$node
);
}
return $phtml;
} | php | protected function compileCase(Node $node)
{
$subject = $node->subject;
if ($this->isVariable($subject))
$subject = "isset({$subject}) ? {$subject} : null";
//Notice that we omit the "? >"
//This is because PHP doesnt allow "? ><?php" between switch and the first case
$phtml = $this->createCode("switch ({$subject}) {", '<?php ', '').$this->newLine();
$phtml .= $this->compileChildren($node->children).$this->newLine();
$phtml .= $this->indent().$this->createCode('}');
//We need to check this after compilation, since there could be when: something children
//that would be like [case children=[[something expands=[when]]] right now
$hasChild = false;
foreach ($node->children as $child) {
if ($child->type !== 'when') {
$this->throwException(
"The `case`-node (`switch`-equivalent) can only have `when`-node children (`case`-equivalent). ".
"A $child->type-node has been provided.",
$node
);
}
$hasChild = true;
}
if (!$hasChild) {
$this->throwException(
"The `case`-node needs at least one `when`-node as a child. Empty `case`-blocks are not allowed as ".
"they can't provide any functionality.",
$node
);
}
return $phtml;
} | [
"protected",
"function",
"compileCase",
"(",
"Node",
"$",
"node",
")",
"{",
"$",
"subject",
"=",
"$",
"node",
"->",
"subject",
";",
"if",
"(",
"$",
"this",
"->",
"isVariable",
"(",
"$",
"subject",
")",
")",
"$",
"subject",
"=",
"\"isset({$subject}) ? {$subject} : null\"",
";",
"//Notice that we omit the \"? >\"",
"//This is because PHP doesnt allow \"? ><?php\" between switch and the first case",
"$",
"phtml",
"=",
"$",
"this",
"->",
"createCode",
"(",
"\"switch ({$subject}) {\"",
",",
"'<?php '",
",",
"''",
")",
".",
"$",
"this",
"->",
"newLine",
"(",
")",
";",
"$",
"phtml",
".=",
"$",
"this",
"->",
"compileChildren",
"(",
"$",
"node",
"->",
"children",
")",
".",
"$",
"this",
"->",
"newLine",
"(",
")",
";",
"$",
"phtml",
".=",
"$",
"this",
"->",
"indent",
"(",
")",
".",
"$",
"this",
"->",
"createCode",
"(",
"'}'",
")",
";",
"//We need to check this after compilation, since there could be when: something children",
"//that would be like [case children=[[something expands=[when]]] right now",
"$",
"hasChild",
"=",
"false",
";",
"foreach",
"(",
"$",
"node",
"->",
"children",
"as",
"$",
"child",
")",
"{",
"if",
"(",
"$",
"child",
"->",
"type",
"!==",
"'when'",
")",
"{",
"$",
"this",
"->",
"throwException",
"(",
"\"The `case`-node (`switch`-equivalent) can only have `when`-node children (`case`-equivalent). \"",
".",
"\"A $child->type-node has been provided.\"",
",",
"$",
"node",
")",
";",
"}",
"$",
"hasChild",
"=",
"true",
";",
"}",
"if",
"(",
"!",
"$",
"hasChild",
")",
"{",
"$",
"this",
"->",
"throwException",
"(",
"\"The `case`-node needs at least one `when`-node as a child. Empty `case`-blocks are not allowed as \"",
".",
"\"they can't provide any functionality.\"",
",",
"$",
"node",
")",
";",
"}",
"return",
"$",
"phtml",
";",
"}"
]
| Compiles a case-node into PHTML.
This also checks if all sub-nodes of the case are
when-children, nothing else is allowed
compileCase interacts with compileWhen to skip ?><?php after the switch {
@param Node $node the case node to compile
@return string The compiled PHTML
@throws Exception | [
"Compiles",
"a",
"case",
"-",
"node",
"into",
"PHTML",
"."
]
| e9405e0f4f6b252514cbb27431e13e04cf44614e | https://github.com/Talesoft/tale-jade/blob/e9405e0f4f6b252514cbb27431e13e04cf44614e/Compiler.php#L1597-L1638 | train |
Talesoft/tale-jade | Compiler.php | Compiler.compileWhen | protected function compileWhen(Node $node)
{
if (!$node->parent || $node->parent->type !== 'case')
$this->throwException(
"A `when`-node can only be a direct descendant of a `case`-node. This one is a child of a ".
"{$node->parent->type}-node. Maybe you wanted to use `if/unless`?",
$node
);
$subject = $node->subject;
if ($subject && $this->isVariable($subject))
$subject = "isset({$subject}) ? {$subject} : null";
$first = $node->parent->indexOf($node) === 0;
//If this is the first node, we omit the prefix for the code "<?php"
//Notice that compileCase omits the ? >, so it fits together here
$phtml = $this->createCode($node->default ? 'default:' : "case $subject:", $first ? '' : '<?php ').$this->newLine();
$phtml .= $this->compileChildren($node->children).$this->newLine();
if (count($node->children) > 0)
$phtml .= $this->indent().$this->createCode('break;');
return $phtml;
} | php | protected function compileWhen(Node $node)
{
if (!$node->parent || $node->parent->type !== 'case')
$this->throwException(
"A `when`-node can only be a direct descendant of a `case`-node. This one is a child of a ".
"{$node->parent->type}-node. Maybe you wanted to use `if/unless`?",
$node
);
$subject = $node->subject;
if ($subject && $this->isVariable($subject))
$subject = "isset({$subject}) ? {$subject} : null";
$first = $node->parent->indexOf($node) === 0;
//If this is the first node, we omit the prefix for the code "<?php"
//Notice that compileCase omits the ? >, so it fits together here
$phtml = $this->createCode($node->default ? 'default:' : "case $subject:", $first ? '' : '<?php ').$this->newLine();
$phtml .= $this->compileChildren($node->children).$this->newLine();
if (count($node->children) > 0)
$phtml .= $this->indent().$this->createCode('break;');
return $phtml;
} | [
"protected",
"function",
"compileWhen",
"(",
"Node",
"$",
"node",
")",
"{",
"if",
"(",
"!",
"$",
"node",
"->",
"parent",
"||",
"$",
"node",
"->",
"parent",
"->",
"type",
"!==",
"'case'",
")",
"$",
"this",
"->",
"throwException",
"(",
"\"A `when`-node can only be a direct descendant of a `case`-node. This one is a child of a \"",
".",
"\"{$node->parent->type}-node. Maybe you wanted to use `if/unless`?\"",
",",
"$",
"node",
")",
";",
"$",
"subject",
"=",
"$",
"node",
"->",
"subject",
";",
"if",
"(",
"$",
"subject",
"&&",
"$",
"this",
"->",
"isVariable",
"(",
"$",
"subject",
")",
")",
"$",
"subject",
"=",
"\"isset({$subject}) ? {$subject} : null\"",
";",
"$",
"first",
"=",
"$",
"node",
"->",
"parent",
"->",
"indexOf",
"(",
"$",
"node",
")",
"===",
"0",
";",
"//If this is the first node, we omit the prefix for the code \"<?php\"",
"//Notice that compileCase omits the ? >, so it fits together here",
"$",
"phtml",
"=",
"$",
"this",
"->",
"createCode",
"(",
"$",
"node",
"->",
"default",
"?",
"'default:'",
":",
"\"case $subject:\"",
",",
"$",
"first",
"?",
"''",
":",
"'<?php '",
")",
".",
"$",
"this",
"->",
"newLine",
"(",
")",
";",
"$",
"phtml",
".=",
"$",
"this",
"->",
"compileChildren",
"(",
"$",
"node",
"->",
"children",
")",
".",
"$",
"this",
"->",
"newLine",
"(",
")",
";",
"if",
"(",
"count",
"(",
"$",
"node",
"->",
"children",
")",
">",
"0",
")",
"$",
"phtml",
".=",
"$",
"this",
"->",
"indent",
"(",
")",
".",
"$",
"this",
"->",
"createCode",
"(",
"'break;'",
")",
";",
"return",
"$",
"phtml",
";",
"}"
]
| Compiles a when-node into PHTML.
This also checks, if the when node is defined
on a case-parent
When interacts with compileCase to skip the first ?><?php after the switch{
@param Node $node the when-node to compile
@return string The compiled PHTML
@throws Exception | [
"Compiles",
"a",
"when",
"-",
"node",
"into",
"PHTML",
"."
]
| e9405e0f4f6b252514cbb27431e13e04cf44614e | https://github.com/Talesoft/tale-jade/blob/e9405e0f4f6b252514cbb27431e13e04cf44614e/Compiler.php#L1653-L1679 | train |
Talesoft/tale-jade | Compiler.php | Compiler.compileEach | protected function compileEach(Node $node)
{
$subject = $node->subject;
if ($this->isVariable($subject))
$subject = "isset({$subject}) ? {$subject} : []";
$as = "\${$node->itemName}";
if ($node->keyName)
$as = "\${$node->keyName} => ".$as;
$var = '$__iterator'.($this->iteratorId++);
$phtml = $this->createCode("$var = {$subject};").$this->newLine();
$phtml .= $this->indent().$this->createCode("foreach ($var as $as) {").$this->newLine();
$phtml .= $this->compileChildren($node->children).$this->newLine();
$phtml .= $this->indent().$this->createCode('}').$this->newLine();
$phtml .= $this->indent().$this->createCode("unset($var);");
return $phtml;
} | php | protected function compileEach(Node $node)
{
$subject = $node->subject;
if ($this->isVariable($subject))
$subject = "isset({$subject}) ? {$subject} : []";
$as = "\${$node->itemName}";
if ($node->keyName)
$as = "\${$node->keyName} => ".$as;
$var = '$__iterator'.($this->iteratorId++);
$phtml = $this->createCode("$var = {$subject};").$this->newLine();
$phtml .= $this->indent().$this->createCode("foreach ($var as $as) {").$this->newLine();
$phtml .= $this->compileChildren($node->children).$this->newLine();
$phtml .= $this->indent().$this->createCode('}').$this->newLine();
$phtml .= $this->indent().$this->createCode("unset($var);");
return $phtml;
} | [
"protected",
"function",
"compileEach",
"(",
"Node",
"$",
"node",
")",
"{",
"$",
"subject",
"=",
"$",
"node",
"->",
"subject",
";",
"if",
"(",
"$",
"this",
"->",
"isVariable",
"(",
"$",
"subject",
")",
")",
"$",
"subject",
"=",
"\"isset({$subject}) ? {$subject} : []\"",
";",
"$",
"as",
"=",
"\"\\${$node->itemName}\"",
";",
"if",
"(",
"$",
"node",
"->",
"keyName",
")",
"$",
"as",
"=",
"\"\\${$node->keyName} => \"",
".",
"$",
"as",
";",
"$",
"var",
"=",
"'$__iterator'",
".",
"(",
"$",
"this",
"->",
"iteratorId",
"++",
")",
";",
"$",
"phtml",
"=",
"$",
"this",
"->",
"createCode",
"(",
"\"$var = {$subject};\"",
")",
".",
"$",
"this",
"->",
"newLine",
"(",
")",
";",
"$",
"phtml",
".=",
"$",
"this",
"->",
"indent",
"(",
")",
".",
"$",
"this",
"->",
"createCode",
"(",
"\"foreach ($var as $as) {\"",
")",
".",
"$",
"this",
"->",
"newLine",
"(",
")",
";",
"$",
"phtml",
".=",
"$",
"this",
"->",
"compileChildren",
"(",
"$",
"node",
"->",
"children",
")",
".",
"$",
"this",
"->",
"newLine",
"(",
")",
";",
"$",
"phtml",
".=",
"$",
"this",
"->",
"indent",
"(",
")",
".",
"$",
"this",
"->",
"createCode",
"(",
"'}'",
")",
".",
"$",
"this",
"->",
"newLine",
"(",
")",
";",
"$",
"phtml",
".=",
"$",
"this",
"->",
"indent",
"(",
")",
".",
"$",
"this",
"->",
"createCode",
"(",
"\"unset($var);\"",
")",
";",
"return",
"$",
"phtml",
";",
"}"
]
| Compiles a each-instruction into a foreach-loop PHTML block.
the $ in the variables names are optional
@param Node $node the each-node to compile
@return string The compiled PHTML | [
"Compiles",
"a",
"each",
"-",
"instruction",
"into",
"a",
"foreach",
"-",
"loop",
"PHTML",
"block",
"."
]
| e9405e0f4f6b252514cbb27431e13e04cf44614e | https://github.com/Talesoft/tale-jade/blob/e9405e0f4f6b252514cbb27431e13e04cf44614e/Compiler.php#L1690-L1711 | train |
Talesoft/tale-jade | Compiler.php | Compiler.compileWhile | protected function compileWhile(Node $node)
{
$subject = $node->subject;
if ($this->isVariable($subject))
$subject = "isset({$subject}) ? {$subject} : null";
$hasChildren = count($node->children) > 0;
$isDoWhile = $node->prev() && $node->prev()->type === 'do';
if (!$hasChildren && !$isDoWhile)
$this->throwException(
'A while-loop without children you loop through is not valid if'
.' there\'s no do-statement before it.',
$node
);
else if ($isDoWhile && $hasChildren)
$this->throwException(
'In a do-while statement the while-part shouldn\'t have any children. Put the children in the `do`-part',
$node
);
$phtml = $this->createCode("while ({$subject})".($hasChildren ? ' {' : ''), $isDoWhile ? ' ' : '<?php ').$this->newLine();
if ($hasChildren) {
$phtml .= $this->compileChildren($node->children).$this->newLine();
$phtml .= $this->indent().$this->createCode('}').$this->newLine();
}
return $phtml;
} | php | protected function compileWhile(Node $node)
{
$subject = $node->subject;
if ($this->isVariable($subject))
$subject = "isset({$subject}) ? {$subject} : null";
$hasChildren = count($node->children) > 0;
$isDoWhile = $node->prev() && $node->prev()->type === 'do';
if (!$hasChildren && !$isDoWhile)
$this->throwException(
'A while-loop without children you loop through is not valid if'
.' there\'s no do-statement before it.',
$node
);
else if ($isDoWhile && $hasChildren)
$this->throwException(
'In a do-while statement the while-part shouldn\'t have any children. Put the children in the `do`-part',
$node
);
$phtml = $this->createCode("while ({$subject})".($hasChildren ? ' {' : ''), $isDoWhile ? ' ' : '<?php ').$this->newLine();
if ($hasChildren) {
$phtml .= $this->compileChildren($node->children).$this->newLine();
$phtml .= $this->indent().$this->createCode('}').$this->newLine();
}
return $phtml;
} | [
"protected",
"function",
"compileWhile",
"(",
"Node",
"$",
"node",
")",
"{",
"$",
"subject",
"=",
"$",
"node",
"->",
"subject",
";",
"if",
"(",
"$",
"this",
"->",
"isVariable",
"(",
"$",
"subject",
")",
")",
"$",
"subject",
"=",
"\"isset({$subject}) ? {$subject} : null\"",
";",
"$",
"hasChildren",
"=",
"count",
"(",
"$",
"node",
"->",
"children",
")",
">",
"0",
";",
"$",
"isDoWhile",
"=",
"$",
"node",
"->",
"prev",
"(",
")",
"&&",
"$",
"node",
"->",
"prev",
"(",
")",
"->",
"type",
"===",
"'do'",
";",
"if",
"(",
"!",
"$",
"hasChildren",
"&&",
"!",
"$",
"isDoWhile",
")",
"$",
"this",
"->",
"throwException",
"(",
"'A while-loop without children you loop through is not valid if'",
".",
"' there\\'s no do-statement before it.'",
",",
"$",
"node",
")",
";",
"else",
"if",
"(",
"$",
"isDoWhile",
"&&",
"$",
"hasChildren",
")",
"$",
"this",
"->",
"throwException",
"(",
"'In a do-while statement the while-part shouldn\\'t have any children. Put the children in the `do`-part'",
",",
"$",
"node",
")",
";",
"$",
"phtml",
"=",
"$",
"this",
"->",
"createCode",
"(",
"\"while ({$subject})\"",
".",
"(",
"$",
"hasChildren",
"?",
"' {'",
":",
"''",
")",
",",
"$",
"isDoWhile",
"?",
"' '",
":",
"'<?php '",
")",
".",
"$",
"this",
"->",
"newLine",
"(",
")",
";",
"if",
"(",
"$",
"hasChildren",
")",
"{",
"$",
"phtml",
".=",
"$",
"this",
"->",
"compileChildren",
"(",
"$",
"node",
"->",
"children",
")",
".",
"$",
"this",
"->",
"newLine",
"(",
")",
";",
"$",
"phtml",
".=",
"$",
"this",
"->",
"indent",
"(",
")",
".",
"$",
"this",
"->",
"createCode",
"(",
"'}'",
")",
".",
"$",
"this",
"->",
"newLine",
"(",
")",
";",
"}",
"return",
"$",
"phtml",
";",
"}"
]
| Compiles a while-loop into PHTML.
Notice that if it has no children, we assume it's a do/while loop
and don't print brackets
@param Node $node the while-node to compile
@return string The compiled PHTML | [
"Compiles",
"a",
"while",
"-",
"loop",
"into",
"PHTML",
"."
]
| e9405e0f4f6b252514cbb27431e13e04cf44614e | https://github.com/Talesoft/tale-jade/blob/e9405e0f4f6b252514cbb27431e13e04cf44614e/Compiler.php#L1723-L1755 | train |
Talesoft/tale-jade | Compiler.php | Compiler.compileFor | protected function compileFor(Node $node)
{
$subject = $node->subject;
$phtml = $this->createCode("for ({$subject}) {").$this->newLine();
$phtml .= $this->compileChildren($node->children).$this->newLine();
$phtml .= $this->indent().$this->createCode('}').$this->newLine();
return $phtml;
} | php | protected function compileFor(Node $node)
{
$subject = $node->subject;
$phtml = $this->createCode("for ({$subject}) {").$this->newLine();
$phtml .= $this->compileChildren($node->children).$this->newLine();
$phtml .= $this->indent().$this->createCode('}').$this->newLine();
return $phtml;
} | [
"protected",
"function",
"compileFor",
"(",
"Node",
"$",
"node",
")",
"{",
"$",
"subject",
"=",
"$",
"node",
"->",
"subject",
";",
"$",
"phtml",
"=",
"$",
"this",
"->",
"createCode",
"(",
"\"for ({$subject}) {\"",
")",
".",
"$",
"this",
"->",
"newLine",
"(",
")",
";",
"$",
"phtml",
".=",
"$",
"this",
"->",
"compileChildren",
"(",
"$",
"node",
"->",
"children",
")",
".",
"$",
"this",
"->",
"newLine",
"(",
")",
";",
"$",
"phtml",
".=",
"$",
"this",
"->",
"indent",
"(",
")",
".",
"$",
"this",
"->",
"createCode",
"(",
"'}'",
")",
".",
"$",
"this",
"->",
"newLine",
"(",
")",
";",
"return",
"$",
"phtml",
";",
"}"
]
| Compiles a for-loop into PHTML.
@param Node $node the while-node to compile
@return string The compiled PHTML | [
"Compiles",
"a",
"for",
"-",
"loop",
"into",
"PHTML",
"."
]
| e9405e0f4f6b252514cbb27431e13e04cf44614e | https://github.com/Talesoft/tale-jade/blob/e9405e0f4f6b252514cbb27431e13e04cf44614e/Compiler.php#L1764-L1773 | train |
Talesoft/tale-jade | Compiler.php | Compiler.compileDo | protected function compileDo(Node $node)
{
$subject = $node->subject;
if (!empty($subject))
$this->throwException(
"Do-loops can't have a subject, they only accept children to repeat.",
$node
);
if (!$node->next() || $node->next()->type !== 'while')
$this->throwException(
"A do-statement needs a while-statement with a condition following immediately, {$node->next()->type} was provided"
);
//Notice that the } wont have closing ? >, php needs this.
//Check compileWhile to see the combination of both
$phtml = $this->createCode("do {").$this->newLine();
$phtml .= $this->compileChildren($node->children).$this->newLine();
$phtml .= $this->indent().$this->createCode('}', '<?php ', '').$this->newLine();
return $phtml;
} | php | protected function compileDo(Node $node)
{
$subject = $node->subject;
if (!empty($subject))
$this->throwException(
"Do-loops can't have a subject, they only accept children to repeat.",
$node
);
if (!$node->next() || $node->next()->type !== 'while')
$this->throwException(
"A do-statement needs a while-statement with a condition following immediately, {$node->next()->type} was provided"
);
//Notice that the } wont have closing ? >, php needs this.
//Check compileWhile to see the combination of both
$phtml = $this->createCode("do {").$this->newLine();
$phtml .= $this->compileChildren($node->children).$this->newLine();
$phtml .= $this->indent().$this->createCode('}', '<?php ', '').$this->newLine();
return $phtml;
} | [
"protected",
"function",
"compileDo",
"(",
"Node",
"$",
"node",
")",
"{",
"$",
"subject",
"=",
"$",
"node",
"->",
"subject",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"subject",
")",
")",
"$",
"this",
"->",
"throwException",
"(",
"\"Do-loops can't have a subject, they only accept children to repeat.\"",
",",
"$",
"node",
")",
";",
"if",
"(",
"!",
"$",
"node",
"->",
"next",
"(",
")",
"||",
"$",
"node",
"->",
"next",
"(",
")",
"->",
"type",
"!==",
"'while'",
")",
"$",
"this",
"->",
"throwException",
"(",
"\"A do-statement needs a while-statement with a condition following immediately, {$node->next()->type} was provided\"",
")",
";",
"//Notice that the } wont have closing ? >, php needs this.",
"//Check compileWhile to see the combination of both",
"$",
"phtml",
"=",
"$",
"this",
"->",
"createCode",
"(",
"\"do {\"",
")",
".",
"$",
"this",
"->",
"newLine",
"(",
")",
";",
"$",
"phtml",
".=",
"$",
"this",
"->",
"compileChildren",
"(",
"$",
"node",
"->",
"children",
")",
".",
"$",
"this",
"->",
"newLine",
"(",
")",
";",
"$",
"phtml",
".=",
"$",
"this",
"->",
"indent",
"(",
")",
".",
"$",
"this",
"->",
"createCode",
"(",
"'}'",
",",
"'<?php '",
",",
"''",
")",
".",
"$",
"this",
"->",
"newLine",
"(",
")",
";",
"return",
"$",
"phtml",
";",
"}"
]
| Compiles a do-instruction into PHTML.
@param Node $node the do-node to compile
@return string The compiled PHTML
@throws Exception | [
"Compiles",
"a",
"do",
"-",
"instruction",
"into",
"PHTML",
"."
]
| e9405e0f4f6b252514cbb27431e13e04cf44614e | https://github.com/Talesoft/tale-jade/blob/e9405e0f4f6b252514cbb27431e13e04cf44614e/Compiler.php#L1783-L1806 | train |
Talesoft/tale-jade | Compiler.php | Compiler.compileVariable | protected function compileVariable(Node $node)
{
//Attribute-style assignment
//$variable(a=b, c=d)
if (count($node->attributes)) {
if (count($node->children))
$this->throwException(
"A variable node with attributes can't have any children. They are used for array-assignments.",
$node
);
//Attribute-based assignment
$array = [];
foreach ($node->attributes as $attr) {
$name = $attr->name;
$value = $attr->value;
if (!$name)
$array[] = $value;
else {
if (isset($array[$name])) {
if (is_array($array[$name]))
$array[$name][] = $value;
else
$array[$name] = [$array[$name], $value];
} else
$array[$name] = $value;
}
}
//In $array we have the final array to assign on the variable, sadly
//we can't just use var_export, since we might have variables inside
//the array that shouldn't be converted to strings.
//We convert it ourself
return $this->createCode(
"\$__value = ".$this->exportArray($array)."; "
."\${$node->name} = isset(\${$node->name}) ? array_replace_recursive(\${$node->name}, \$__value) : \$__value; "
."unset(\$__value);"
);
}
if (!count($node->children)) {
//No children, this is simple variable output (Escaped!)
return $this->createShortCode(
"htmlentities(\${$node->name}, \\ENT_QUOTES, '".$this->options['escape_charset']."')"
);
}
if ($node->children[0]->type !== 'expression') {
$this->throwException(
'Following a variable, you can only enter an expression or an attribute block (e.g. `$varName= \'some value\'`)',
$node
);
}
return $this->createCode("\${$node->name} = ".$node->children[0]->value);
} | php | protected function compileVariable(Node $node)
{
//Attribute-style assignment
//$variable(a=b, c=d)
if (count($node->attributes)) {
if (count($node->children))
$this->throwException(
"A variable node with attributes can't have any children. They are used for array-assignments.",
$node
);
//Attribute-based assignment
$array = [];
foreach ($node->attributes as $attr) {
$name = $attr->name;
$value = $attr->value;
if (!$name)
$array[] = $value;
else {
if (isset($array[$name])) {
if (is_array($array[$name]))
$array[$name][] = $value;
else
$array[$name] = [$array[$name], $value];
} else
$array[$name] = $value;
}
}
//In $array we have the final array to assign on the variable, sadly
//we can't just use var_export, since we might have variables inside
//the array that shouldn't be converted to strings.
//We convert it ourself
return $this->createCode(
"\$__value = ".$this->exportArray($array)."; "
."\${$node->name} = isset(\${$node->name}) ? array_replace_recursive(\${$node->name}, \$__value) : \$__value; "
."unset(\$__value);"
);
}
if (!count($node->children)) {
//No children, this is simple variable output (Escaped!)
return $this->createShortCode(
"htmlentities(\${$node->name}, \\ENT_QUOTES, '".$this->options['escape_charset']."')"
);
}
if ($node->children[0]->type !== 'expression') {
$this->throwException(
'Following a variable, you can only enter an expression or an attribute block (e.g. `$varName= \'some value\'`)',
$node
);
}
return $this->createCode("\${$node->name} = ".$node->children[0]->value);
} | [
"protected",
"function",
"compileVariable",
"(",
"Node",
"$",
"node",
")",
"{",
"//Attribute-style assignment",
"//$variable(a=b, c=d)",
"if",
"(",
"count",
"(",
"$",
"node",
"->",
"attributes",
")",
")",
"{",
"if",
"(",
"count",
"(",
"$",
"node",
"->",
"children",
")",
")",
"$",
"this",
"->",
"throwException",
"(",
"\"A variable node with attributes can't have any children. They are used for array-assignments.\"",
",",
"$",
"node",
")",
";",
"//Attribute-based assignment",
"$",
"array",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"node",
"->",
"attributes",
"as",
"$",
"attr",
")",
"{",
"$",
"name",
"=",
"$",
"attr",
"->",
"name",
";",
"$",
"value",
"=",
"$",
"attr",
"->",
"value",
";",
"if",
"(",
"!",
"$",
"name",
")",
"$",
"array",
"[",
"]",
"=",
"$",
"value",
";",
"else",
"{",
"if",
"(",
"isset",
"(",
"$",
"array",
"[",
"$",
"name",
"]",
")",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"array",
"[",
"$",
"name",
"]",
")",
")",
"$",
"array",
"[",
"$",
"name",
"]",
"[",
"]",
"=",
"$",
"value",
";",
"else",
"$",
"array",
"[",
"$",
"name",
"]",
"=",
"[",
"$",
"array",
"[",
"$",
"name",
"]",
",",
"$",
"value",
"]",
";",
"}",
"else",
"$",
"array",
"[",
"$",
"name",
"]",
"=",
"$",
"value",
";",
"}",
"}",
"//In $array we have the final array to assign on the variable, sadly",
"//we can't just use var_export, since we might have variables inside",
"//the array that shouldn't be converted to strings.",
"//We convert it ourself",
"return",
"$",
"this",
"->",
"createCode",
"(",
"\"\\$__value = \"",
".",
"$",
"this",
"->",
"exportArray",
"(",
"$",
"array",
")",
".",
"\"; \"",
".",
"\"\\${$node->name} = isset(\\${$node->name}) ? array_replace_recursive(\\${$node->name}, \\$__value) : \\$__value; \"",
".",
"\"unset(\\$__value);\"",
")",
";",
"}",
"if",
"(",
"!",
"count",
"(",
"$",
"node",
"->",
"children",
")",
")",
"{",
"//No children, this is simple variable output (Escaped!)",
"return",
"$",
"this",
"->",
"createShortCode",
"(",
"\"htmlentities(\\${$node->name}, \\\\ENT_QUOTES, '\"",
".",
"$",
"this",
"->",
"options",
"[",
"'escape_charset'",
"]",
".",
"\"')\"",
")",
";",
"}",
"if",
"(",
"$",
"node",
"->",
"children",
"[",
"0",
"]",
"->",
"type",
"!==",
"'expression'",
")",
"{",
"$",
"this",
"->",
"throwException",
"(",
"'Following a variable, you can only enter an expression or an attribute block (e.g. `$varName= \\'some value\\'`)'",
",",
"$",
"node",
")",
";",
"}",
"return",
"$",
"this",
"->",
"createCode",
"(",
"\"\\${$node->name} = \"",
".",
"$",
"node",
"->",
"children",
"[",
"0",
"]",
"->",
"value",
")",
";",
"}"
]
| Compiles a variable-node into PHTML.
@param Node $node the variable node to compile
@return string The compiled PHTML
@throws Exception | [
"Compiles",
"a",
"variable",
"-",
"node",
"into",
"PHTML",
"."
]
| e9405e0f4f6b252514cbb27431e13e04cf44614e | https://github.com/Talesoft/tale-jade/blob/e9405e0f4f6b252514cbb27431e13e04cf44614e/Compiler.php#L1816-L1880 | train |
Talesoft/tale-jade | Compiler.php | Compiler.compileFilter | protected function compileFilter(Node $node)
{
$name = $node->name;
if (!isset($this->options['filters'][$name]))
$this->throwException(
"Filter $name was not defined. Make sure to add it via the [`filters`]-option or the [`->addFilter`]-method ",
$node
);
$result = call_user_func($this->options['filters'][$name], $node, $this->indent(), $this->newLine(), $this);
return $result instanceof Node ? $this->compileNode($result) : (string)$result;
} | php | protected function compileFilter(Node $node)
{
$name = $node->name;
if (!isset($this->options['filters'][$name]))
$this->throwException(
"Filter $name was not defined. Make sure to add it via the [`filters`]-option or the [`->addFilter`]-method ",
$node
);
$result = call_user_func($this->options['filters'][$name], $node, $this->indent(), $this->newLine(), $this);
return $result instanceof Node ? $this->compileNode($result) : (string)$result;
} | [
"protected",
"function",
"compileFilter",
"(",
"Node",
"$",
"node",
")",
"{",
"$",
"name",
"=",
"$",
"node",
"->",
"name",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"options",
"[",
"'filters'",
"]",
"[",
"$",
"name",
"]",
")",
")",
"$",
"this",
"->",
"throwException",
"(",
"\"Filter $name was not defined. Make sure to add it via the [`filters`]-option or the [`->addFilter`]-method \"",
",",
"$",
"node",
")",
";",
"$",
"result",
"=",
"call_user_func",
"(",
"$",
"this",
"->",
"options",
"[",
"'filters'",
"]",
"[",
"$",
"name",
"]",
",",
"$",
"node",
",",
"$",
"this",
"->",
"indent",
"(",
")",
",",
"$",
"this",
"->",
"newLine",
"(",
")",
",",
"$",
"this",
")",
";",
"return",
"$",
"result",
"instanceof",
"Node",
"?",
"$",
"this",
"->",
"compileNode",
"(",
"$",
"result",
")",
":",
"(",
"string",
")",
"$",
"result",
";",
"}"
]
| Compiles a filter-node into PHTML.
The filters are drawn from the filters-option
@param Node $node the filter node to compile
@return string The compiled PHTML
@throws Exception | [
"Compiles",
"a",
"filter",
"-",
"node",
"into",
"PHTML",
"."
]
| e9405e0f4f6b252514cbb27431e13e04cf44614e | https://github.com/Talesoft/tale-jade/blob/e9405e0f4f6b252514cbb27431e13e04cf44614e/Compiler.php#L1892-L1906 | train |
Talesoft/tale-jade | Compiler.php | Compiler.compileChildren | protected function compileChildren(array $nodes, $indent = true, $allowInline = false)
{
$phtml = '';
$this->level += $indent ? 1 : 0;
if (count($nodes) === 1 && $allowInline) {
$compiled = $this->compileNode($nodes[0]);
$this->level--;
return trim($compiled);
}
foreach ($nodes as $idx => $node) {
// Skip empty text lines completely
if ($node->type === 'text' && trim($node->value) === '')
continue;
$phtml .= $this->newLine().$this->indent().$this->compileNode($node);
}
$this->level -= $indent ? 1 : 0;
return $phtml;
} | php | protected function compileChildren(array $nodes, $indent = true, $allowInline = false)
{
$phtml = '';
$this->level += $indent ? 1 : 0;
if (count($nodes) === 1 && $allowInline) {
$compiled = $this->compileNode($nodes[0]);
$this->level--;
return trim($compiled);
}
foreach ($nodes as $idx => $node) {
// Skip empty text lines completely
if ($node->type === 'text' && trim($node->value) === '')
continue;
$phtml .= $this->newLine().$this->indent().$this->compileNode($node);
}
$this->level -= $indent ? 1 : 0;
return $phtml;
} | [
"protected",
"function",
"compileChildren",
"(",
"array",
"$",
"nodes",
",",
"$",
"indent",
"=",
"true",
",",
"$",
"allowInline",
"=",
"false",
")",
"{",
"$",
"phtml",
"=",
"''",
";",
"$",
"this",
"->",
"level",
"+=",
"$",
"indent",
"?",
"1",
":",
"0",
";",
"if",
"(",
"count",
"(",
"$",
"nodes",
")",
"===",
"1",
"&&",
"$",
"allowInline",
")",
"{",
"$",
"compiled",
"=",
"$",
"this",
"->",
"compileNode",
"(",
"$",
"nodes",
"[",
"0",
"]",
")",
";",
"$",
"this",
"->",
"level",
"--",
";",
"return",
"trim",
"(",
"$",
"compiled",
")",
";",
"}",
"foreach",
"(",
"$",
"nodes",
"as",
"$",
"idx",
"=>",
"$",
"node",
")",
"{",
"// Skip empty text lines completely",
"if",
"(",
"$",
"node",
"->",
"type",
"===",
"'text'",
"&&",
"trim",
"(",
"$",
"node",
"->",
"value",
")",
"===",
"''",
")",
"continue",
";",
"$",
"phtml",
".=",
"$",
"this",
"->",
"newLine",
"(",
")",
".",
"$",
"this",
"->",
"indent",
"(",
")",
".",
"$",
"this",
"->",
"compileNode",
"(",
"$",
"node",
")",
";",
"}",
"$",
"this",
"->",
"level",
"-=",
"$",
"indent",
"?",
"1",
":",
"0",
";",
"return",
"$",
"phtml",
";",
"}"
]
| Compiles an array of nodes like they are children of some other node.
if $indent is true, the level will be increased
@param Node[] $nodes
@param bool $indent
@param bool $allowInline
@param bool $forceInline
@return string | [
"Compiles",
"an",
"array",
"of",
"nodes",
"like",
"they",
"are",
"children",
"of",
"some",
"other",
"node",
"."
]
| e9405e0f4f6b252514cbb27431e13e04cf44614e | https://github.com/Talesoft/tale-jade/blob/e9405e0f4f6b252514cbb27431e13e04cf44614e/Compiler.php#L1920-L1945 | train |
Talesoft/tale-jade | Compiler.php | Compiler.compileText | protected function compileText(Node $node)
{
//Dont print empty text
if ($node->escaped)
$text = $this->createShortCode(
'htmlentities('.$this->exportScalar($node->value, '\'', true).', \\ENT_QUOTES, \''.$this->options['escape_charset'].'\')'
);
else
$text = $this->interpolate($node->value);
return $text.$this->compileChildren($node->children, true, true);
} | php | protected function compileText(Node $node)
{
//Dont print empty text
if ($node->escaped)
$text = $this->createShortCode(
'htmlentities('.$this->exportScalar($node->value, '\'', true).', \\ENT_QUOTES, \''.$this->options['escape_charset'].'\')'
);
else
$text = $this->interpolate($node->value);
return $text.$this->compileChildren($node->children, true, true);
} | [
"protected",
"function",
"compileText",
"(",
"Node",
"$",
"node",
")",
"{",
"//Dont print empty text",
"if",
"(",
"$",
"node",
"->",
"escaped",
")",
"$",
"text",
"=",
"$",
"this",
"->",
"createShortCode",
"(",
"'htmlentities('",
".",
"$",
"this",
"->",
"exportScalar",
"(",
"$",
"node",
"->",
"value",
",",
"'\\''",
",",
"true",
")",
".",
"', \\\\ENT_QUOTES, \\''",
".",
"$",
"this",
"->",
"options",
"[",
"'escape_charset'",
"]",
".",
"'\\')'",
")",
";",
"else",
"$",
"text",
"=",
"$",
"this",
"->",
"interpolate",
"(",
"$",
"node",
"->",
"value",
")",
";",
"return",
"$",
"text",
".",
"$",
"this",
"->",
"compileChildren",
"(",
"$",
"node",
"->",
"children",
",",
"true",
",",
"true",
")",
";",
"}"
]
| Compiles a text-node to PTHML.
Texts get interpolated
@see Compiler->interpolate
@param Node $node the text-node to compile
@return string The compiled PHTML | [
"Compiles",
"a",
"text",
"-",
"node",
"to",
"PTHML",
"."
]
| e9405e0f4f6b252514cbb27431e13e04cf44614e | https://github.com/Talesoft/tale-jade/blob/e9405e0f4f6b252514cbb27431e13e04cf44614e/Compiler.php#L2192-L2204 | train |
Talesoft/tale-jade | Compiler.php | Compiler.compileExpression | protected function compileExpression(Node $node)
{
$code = $node->escaped ? 'htmlentities(%s, \\ENT_QUOTES, \''.$this->options['escape_charset'].'\')' : '%s';
$value = rtrim(trim($node->value), ';');
if ($this->isVariable($value) && !$node->unchecked)
$value = "isset({$value}) ? {$value} : ''";
return $this->createShortCode(sprintf($code, $value));
} | php | protected function compileExpression(Node $node)
{
$code = $node->escaped ? 'htmlentities(%s, \\ENT_QUOTES, \''.$this->options['escape_charset'].'\')' : '%s';
$value = rtrim(trim($node->value), ';');
if ($this->isVariable($value) && !$node->unchecked)
$value = "isset({$value}) ? {$value} : ''";
return $this->createShortCode(sprintf($code, $value));
} | [
"protected",
"function",
"compileExpression",
"(",
"Node",
"$",
"node",
")",
"{",
"$",
"code",
"=",
"$",
"node",
"->",
"escaped",
"?",
"'htmlentities(%s, \\\\ENT_QUOTES, \\''",
".",
"$",
"this",
"->",
"options",
"[",
"'escape_charset'",
"]",
".",
"'\\')'",
":",
"'%s'",
";",
"$",
"value",
"=",
"rtrim",
"(",
"trim",
"(",
"$",
"node",
"->",
"value",
")",
",",
"';'",
")",
";",
"if",
"(",
"$",
"this",
"->",
"isVariable",
"(",
"$",
"value",
")",
"&&",
"!",
"$",
"node",
"->",
"unchecked",
")",
"$",
"value",
"=",
"\"isset({$value}) ? {$value} : ''\"",
";",
"return",
"$",
"this",
"->",
"createShortCode",
"(",
"sprintf",
"(",
"$",
"code",
",",
"$",
"value",
")",
")",
";",
"}"
]
| Compiles an expression node and into a PHP expression.
@param Node $node the expression node to compile
@return string | [
"Compiles",
"an",
"expression",
"node",
"and",
"into",
"a",
"PHP",
"expression",
"."
]
| e9405e0f4f6b252514cbb27431e13e04cf44614e | https://github.com/Talesoft/tale-jade/blob/e9405e0f4f6b252514cbb27431e13e04cf44614e/Compiler.php#L2213-L2224 | train |
Talesoft/tale-jade | Compiler.php | Compiler.compileCode | protected function compileCode(Node $node)
{
if (!$node->block) {
return $this->createCode($node->value)
.$this->newLine()
.$this->compileChildren($node->children, true, true);
}
return $this->createCode(trim($this->compileChildren($node->children, true, true)));
} | php | protected function compileCode(Node $node)
{
if (!$node->block) {
return $this->createCode($node->value)
.$this->newLine()
.$this->compileChildren($node->children, true, true);
}
return $this->createCode(trim($this->compileChildren($node->children, true, true)));
} | [
"protected",
"function",
"compileCode",
"(",
"Node",
"$",
"node",
")",
"{",
"if",
"(",
"!",
"$",
"node",
"->",
"block",
")",
"{",
"return",
"$",
"this",
"->",
"createCode",
"(",
"$",
"node",
"->",
"value",
")",
".",
"$",
"this",
"->",
"newLine",
"(",
")",
".",
"$",
"this",
"->",
"compileChildren",
"(",
"$",
"node",
"->",
"children",
",",
"true",
",",
"true",
")",
";",
"}",
"return",
"$",
"this",
"->",
"createCode",
"(",
"trim",
"(",
"$",
"this",
"->",
"compileChildren",
"(",
"$",
"node",
"->",
"children",
",",
"true",
",",
"true",
")",
")",
")",
";",
"}"
]
| Compiles a code node and it's descending text nodes
into a single PHP code block.
@param Node $node the code node to compile
@return string | [
"Compiles",
"a",
"code",
"node",
"and",
"it",
"s",
"descending",
"text",
"nodes",
"into",
"a",
"single",
"PHP",
"code",
"block",
"."
]
| e9405e0f4f6b252514cbb27431e13e04cf44614e | https://github.com/Talesoft/tale-jade/blob/e9405e0f4f6b252514cbb27431e13e04cf44614e/Compiler.php#L2234-L2245 | train |
Talesoft/tale-jade | Compiler.php | Compiler.compileComment | protected function compileComment(Node $node)
{
$content = $this->compileChildren($node->children, true, true);
return $node->rendered ? $this->createMarkupComment($content) : $this->createPhpComment($content);
} | php | protected function compileComment(Node $node)
{
$content = $this->compileChildren($node->children, true, true);
return $node->rendered ? $this->createMarkupComment($content) : $this->createPhpComment($content);
} | [
"protected",
"function",
"compileComment",
"(",
"Node",
"$",
"node",
")",
"{",
"$",
"content",
"=",
"$",
"this",
"->",
"compileChildren",
"(",
"$",
"node",
"->",
"children",
",",
"true",
",",
"true",
")",
";",
"return",
"$",
"node",
"->",
"rendered",
"?",
"$",
"this",
"->",
"createMarkupComment",
"(",
"$",
"content",
")",
":",
"$",
"this",
"->",
"createPhpComment",
"(",
"$",
"content",
")",
";",
"}"
]
| Compiles a comment-node based on if its rendered or not.
If it's rendered, it will be compiled as a HTML-comment,
if not it will be compiled as a hidden PHP comment
@param Node $node the comment-node to compile
@return string The compiled PHTML | [
"Compiles",
"a",
"comment",
"-",
"node",
"based",
"on",
"if",
"its",
"rendered",
"or",
"not",
"."
]
| e9405e0f4f6b252514cbb27431e13e04cf44614e | https://github.com/Talesoft/tale-jade/blob/e9405e0f4f6b252514cbb27431e13e04cf44614e/Compiler.php#L2257-L2263 | train |
Talesoft/tale-jade | Compiler.php | Compiler.exportArray | protected function exportArray(array $array, $quoteStyle = '\'')
{
$pairs = [];
foreach ($array as $key => $val) {
$pair = $this->exportScalar($key, $quoteStyle).' => ';
if (is_array($val))
$pair .= $this->exportArray($val, $quoteStyle);
else if ($this->isVariable($val))
$pair .= "isset($val) ? $val : null";
else if ($this->isScalar($val) || in_array($val, [true, false, null], true))
$pair .= $this->exportScalar($val, $quoteStyle);
else
$pair .= (string)$val;
$pairs[] = $pair;
}
return '['.implode(', ', $pairs).']';
} | php | protected function exportArray(array $array, $quoteStyle = '\'')
{
$pairs = [];
foreach ($array as $key => $val) {
$pair = $this->exportScalar($key, $quoteStyle).' => ';
if (is_array($val))
$pair .= $this->exportArray($val, $quoteStyle);
else if ($this->isVariable($val))
$pair .= "isset($val) ? $val : null";
else if ($this->isScalar($val) || in_array($val, [true, false, null], true))
$pair .= $this->exportScalar($val, $quoteStyle);
else
$pair .= (string)$val;
$pairs[] = $pair;
}
return '['.implode(', ', $pairs).']';
} | [
"protected",
"function",
"exportArray",
"(",
"array",
"$",
"array",
",",
"$",
"quoteStyle",
"=",
"'\\''",
")",
"{",
"$",
"pairs",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"array",
"as",
"$",
"key",
"=>",
"$",
"val",
")",
"{",
"$",
"pair",
"=",
"$",
"this",
"->",
"exportScalar",
"(",
"$",
"key",
",",
"$",
"quoteStyle",
")",
".",
"' => '",
";",
"if",
"(",
"is_array",
"(",
"$",
"val",
")",
")",
"$",
"pair",
".=",
"$",
"this",
"->",
"exportArray",
"(",
"$",
"val",
",",
"$",
"quoteStyle",
")",
";",
"else",
"if",
"(",
"$",
"this",
"->",
"isVariable",
"(",
"$",
"val",
")",
")",
"$",
"pair",
".=",
"\"isset($val) ? $val : null\"",
";",
"else",
"if",
"(",
"$",
"this",
"->",
"isScalar",
"(",
"$",
"val",
")",
"||",
"in_array",
"(",
"$",
"val",
",",
"[",
"true",
",",
"false",
",",
"null",
"]",
",",
"true",
")",
")",
"$",
"pair",
".=",
"$",
"this",
"->",
"exportScalar",
"(",
"$",
"val",
",",
"$",
"quoteStyle",
")",
";",
"else",
"$",
"pair",
".=",
"(",
"string",
")",
"$",
"val",
";",
"$",
"pairs",
"[",
"]",
"=",
"$",
"pair",
";",
"}",
"return",
"'['",
".",
"implode",
"(",
"', '",
",",
"$",
"pairs",
")",
".",
"']'",
";",
"}"
]
| Exports an array to a PHP-string recursively.
This works similar to var_export in PHP, with the difference
that it won't try to convert PHP-expression-style strings,
e.g. variables, scalar values like null, false, true and
expressions like arrays or function calls
@param array $array the array to export
@param string $quoteStyle the quote-style used, ' by default
@return string the exported array | [
"Exports",
"an",
"array",
"to",
"a",
"PHP",
"-",
"string",
"recursively",
"."
]
| e9405e0f4f6b252514cbb27431e13e04cf44614e | https://github.com/Talesoft/tale-jade/blob/e9405e0f4f6b252514cbb27431e13e04cf44614e/Compiler.php#L2278-L2299 | train |
Talesoft/tale-jade | Compiler.php | Compiler.exportScalar | protected function exportScalar($scalar, $quoteStyle = '\'', $inCode = false)
{
if ($scalar === 'null' || $scalar === null)
return 'null';
if ($scalar === 'false' || $scalar === false)
return 'false';
if ($scalar === 'true' || $scalar === true)
return 'true';
$scalar = trim($scalar, '\'"');
if (is_numeric($scalar))
return $scalar;
return $quoteStyle.$this->compileScalar($scalar, $inCode).$quoteStyle;
} | php | protected function exportScalar($scalar, $quoteStyle = '\'', $inCode = false)
{
if ($scalar === 'null' || $scalar === null)
return 'null';
if ($scalar === 'false' || $scalar === false)
return 'false';
if ($scalar === 'true' || $scalar === true)
return 'true';
$scalar = trim($scalar, '\'"');
if (is_numeric($scalar))
return $scalar;
return $quoteStyle.$this->compileScalar($scalar, $inCode).$quoteStyle;
} | [
"protected",
"function",
"exportScalar",
"(",
"$",
"scalar",
",",
"$",
"quoteStyle",
"=",
"'\\''",
",",
"$",
"inCode",
"=",
"false",
")",
"{",
"if",
"(",
"$",
"scalar",
"===",
"'null'",
"||",
"$",
"scalar",
"===",
"null",
")",
"return",
"'null'",
";",
"if",
"(",
"$",
"scalar",
"===",
"'false'",
"||",
"$",
"scalar",
"===",
"false",
")",
"return",
"'false'",
";",
"if",
"(",
"$",
"scalar",
"===",
"'true'",
"||",
"$",
"scalar",
"===",
"true",
")",
"return",
"'true'",
";",
"$",
"scalar",
"=",
"trim",
"(",
"$",
"scalar",
",",
"'\\'\"'",
")",
";",
"if",
"(",
"is_numeric",
"(",
"$",
"scalar",
")",
")",
"return",
"$",
"scalar",
";",
"return",
"$",
"quoteStyle",
".",
"$",
"this",
"->",
"compileScalar",
"(",
"$",
"scalar",
",",
"$",
"inCode",
")",
".",
"$",
"quoteStyle",
";",
"}"
]
| Exports a scalar value to the PHP representation.
This also takes into account the PHP constants
null, false and true, makes sure that numeric-values aren't
string enclosed and utilizes interpolation for string
values.
@param mixed $scalar the scalar value to export
@param string $quoteStyle the quote-style used, ' by default
@return string the exported scalar value | [
"Exports",
"a",
"scalar",
"value",
"to",
"the",
"PHP",
"representation",
"."
]
| e9405e0f4f6b252514cbb27431e13e04cf44614e | https://github.com/Talesoft/tale-jade/blob/e9405e0f4f6b252514cbb27431e13e04cf44614e/Compiler.php#L2314-L2332 | train |
Talesoft/tale-jade | Filter.php | Filter.wrapCode | public static function wrapCode(Node $node, $indent, $newLine)
{
$text = self::filterPlain($node, $indent, $newLine);
$text = preg_replace(['/^\s*<\?php ?/i', '/\?>\s*$/'], '', $text);
return $indent.'<?php '.$newLine.$text.$newLine.$indent.'?>'.$newLine;
} | php | public static function wrapCode(Node $node, $indent, $newLine)
{
$text = self::filterPlain($node, $indent, $newLine);
$text = preg_replace(['/^\s*<\?php ?/i', '/\?>\s*$/'], '', $text);
return $indent.'<?php '.$newLine.$text.$newLine.$indent.'?>'.$newLine;
} | [
"public",
"static",
"function",
"wrapCode",
"(",
"Node",
"$",
"node",
",",
"$",
"indent",
",",
"$",
"newLine",
")",
"{",
"$",
"text",
"=",
"self",
"::",
"filterPlain",
"(",
"$",
"node",
",",
"$",
"indent",
",",
"$",
"newLine",
")",
";",
"$",
"text",
"=",
"preg_replace",
"(",
"[",
"'/^\\s*<\\?php ?/i'",
",",
"'/\\?>\\s*$/'",
"]",
",",
"''",
",",
"$",
"text",
")",
";",
"return",
"$",
"indent",
".",
"'<?php '",
".",
"$",
"newLine",
".",
"$",
"text",
".",
"$",
"newLine",
".",
"$",
"indent",
".",
"'?>'",
".",
"$",
"newLine",
";",
"}"
]
| Similar to wrapTag, but rather puts PHP-instruction-tags around the text.
This will create working PHP expressions.
If <?php or ? > are already found, they will be trimmed and re-appended
correctly to avoid failing nested expressions (<?php can't be used
_inside_ <?php)
@param Node $node the node to be wrapped
@param string $indent the indentation to use on each child
@param string $newLine the new-line to append after each line
@return string the wrapped PHP-string | [
"Similar",
"to",
"wrapTag",
"but",
"rather",
"puts",
"PHP",
"-",
"instruction",
"-",
"tags",
"around",
"the",
"text",
"."
]
| e9405e0f4f6b252514cbb27431e13e04cf44614e | https://github.com/Talesoft/tale-jade/blob/e9405e0f4f6b252514cbb27431e13e04cf44614e/Filter.php#L97-L104 | train |
Talesoft/tale-jade | Filter.php | Filter.filterPlain | public static function filterPlain(Node $node, $indent, $newLine)
{
$text = trim($node->text());
//Normalize newlines to $newLine and append our indent
$i = 0;
return implode($newLine, array_map(function ($value) use (
$indent, $newLine, &$i
) {
if (strlen($indent) < 1 && $i++ !== 0 && strlen($value) > 0) {
//Make sure we separate with at least one white-space
$indent = ' ';
}
return $indent.trim($value);
}, explode("\n", $text)));
} | php | public static function filterPlain(Node $node, $indent, $newLine)
{
$text = trim($node->text());
//Normalize newlines to $newLine and append our indent
$i = 0;
return implode($newLine, array_map(function ($value) use (
$indent, $newLine, &$i
) {
if (strlen($indent) < 1 && $i++ !== 0 && strlen($value) > 0) {
//Make sure we separate with at least one white-space
$indent = ' ';
}
return $indent.trim($value);
}, explode("\n", $text)));
} | [
"public",
"static",
"function",
"filterPlain",
"(",
"Node",
"$",
"node",
",",
"$",
"indent",
",",
"$",
"newLine",
")",
"{",
"$",
"text",
"=",
"trim",
"(",
"$",
"node",
"->",
"text",
"(",
")",
")",
";",
"//Normalize newlines to $newLine and append our indent",
"$",
"i",
"=",
"0",
";",
"return",
"implode",
"(",
"$",
"newLine",
",",
"array_map",
"(",
"function",
"(",
"$",
"value",
")",
"use",
"(",
"$",
"indent",
",",
"$",
"newLine",
",",
"&",
"$",
"i",
")",
"{",
"if",
"(",
"strlen",
"(",
"$",
"indent",
")",
"<",
"1",
"&&",
"$",
"i",
"++",
"!==",
"0",
"&&",
"strlen",
"(",
"$",
"value",
")",
">",
"0",
")",
"{",
"//Make sure we separate with at least one white-space",
"$",
"indent",
"=",
"' '",
";",
"}",
"return",
"$",
"indent",
".",
"trim",
"(",
"$",
"value",
")",
";",
"}",
",",
"explode",
"(",
"\"\\n\"",
",",
"$",
"text",
")",
")",
")",
";",
"}"
]
| A plain-text filter that just corrects indentation and new-lines.
@param Node $node the node to be wrapped
@param string $indent the indentation to use on each child
@param string $newLine the new-line to append after each line
@return string the wrapped PTHML-string | [
"A",
"plain",
"-",
"text",
"filter",
"that",
"just",
"corrects",
"indentation",
"and",
"new",
"-",
"lines",
"."
]
| e9405e0f4f6b252514cbb27431e13e04cf44614e | https://github.com/Talesoft/tale-jade/blob/e9405e0f4f6b252514cbb27431e13e04cf44614e/Filter.php#L116-L136 | train |
Talesoft/tale-jade | Filter.php | Filter.filterCode | public static function filterCode(Node $node, $indent, $newLine)
{
return self::wrapCode($node, $indent, $newLine);
} | php | public static function filterCode(Node $node, $indent, $newLine)
{
return self::wrapCode($node, $indent, $newLine);
} | [
"public",
"static",
"function",
"filterCode",
"(",
"Node",
"$",
"node",
",",
"$",
"indent",
",",
"$",
"newLine",
")",
"{",
"return",
"self",
"::",
"wrapCode",
"(",
"$",
"node",
",",
"$",
"indent",
",",
"$",
"newLine",
")",
";",
"}"
]
| Wraps the content in PHP-compiler tags and corrects indentation
and new-lines.
@param Node $node the node to be wrapped
@param string $indent the indentation to use on each child
@param string $newLine the new-line to append after each line
@return string the wrapped PHP-string | [
"Wraps",
"the",
"content",
"in",
"PHP",
"-",
"compiler",
"tags",
"and",
"corrects",
"indentation",
"and",
"new",
"-",
"lines",
"."
]
| e9405e0f4f6b252514cbb27431e13e04cf44614e | https://github.com/Talesoft/tale-jade/blob/e9405e0f4f6b252514cbb27431e13e04cf44614e/Filter.php#L180-L184 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.