shortcode_embed_contents.module in Shortcode 6
File
shortcode_embed_contents/shortcode_embed_contents.module
View source
<?php
function shortcode_embed_contents_shortcodes($op, $format = 1, $long = FALSE) {
switch ($op) {
case 'list':
return array(
'node' => t('Embed a node into the text.'),
);
break;
case 'tips':
$output = shortcode_embed_contents_node_tip($format, $long);
return $output;
break;
default:
break;
}
}
function shortcode_embed_contents_shortcode_node($attrs, $text) {
extract(shortcode_attrs(array(
'nid' => 0,
'class' => '',
'teaser' => FALSE,
'show_title' => FALSE,
'show_submitted' => FALSE,
'show_terms' => FALSE,
'show_links' => FALSE,
), $attrs));
if (is_numeric($nid) && $nid) {
$node = node_load($nid);
$node->shortcode_embedded = TRUE;
if (!$node->status || !node_access('view', $node)) {
return '';
}
}
else {
return '';
}
$params = new stdClass();
$params->embedded = TRUE;
$params->teaser = shortcode_bool($teaser);
$params->show_title = shortcode_bool($show_title);
$params->show_meta = shortcode_bool($show_meta);
$params->show_submitted = shortcode_bool($show_submitted);
$params->show_terms = shortcode_bool($show_terms);
$params->show_links = shortcode_bool($show_links);
$params->attrs = $attrs;
$node->shortcode = $params;
$output = node_view($node, $params->teaser);
return $output;
}
function shortcode_embed_contents_node_tip($format, $long) {
$output = '';
if (shortcode_shortcode_is_enabled('highlight', $format)) {
$output = '<p><strong>[node nid=nodeid (class="additional class")/]</strong>';
if ($long) {
$output .= ' Embed a node by nid into the text. Additional class names can be added by the <em>class</em> parameter.</p>';
}
else {
$output .= ' Embed a node by nid into the text. Additional class names can be added by the <em>class</em> parameter.</p>';
}
}
return $output;
}
function shortcode_embed_contents_preprocess_node(&$vars) {
if (isset($vars['shortcode']) && $vars['shortcode']->embedded) {
$vars['template_files'][] = "node-shortcode--default";
$vars['template_files'][] = 'node-shortcode--' . $vars['type'];
}
}
function shortcode_embed_contents_theme_registry_alter(&$theme_registry) {
$paths = $theme_registry['node']['theme paths'];
$theme = $theme_registry['page']['theme path'];
$key = array_search($theme, $paths);
if ($key === FALSE) {
$theme_registry['node']['theme paths'][] = drupal_get_path('module', 'shortcode_embed_contents') . "/theme";
}
else {
$paths = array();
$first = TRUE;
foreach ($theme_registry['node']['theme paths'] as $path) {
if ($first && preg_match('!themes!', $path)) {
$paths[] = drupal_get_path('module', 'shortcode_embed_contents') . "/theme";
$first = FALSE;
}
$paths[] = $path;
}
$theme_registry['node']['theme paths'] = $paths;
}
}