View source
<?php
function shortcode_embed_content_shortcode_info() {
$shortcodes['embed_content'] = array(
'title' => t('Embed content'),
'description' => t('Embed node content into the text.'),
'process callback' => 'shortcode_embed_content_shortcode_node',
'tips callback' => 'shortcode_embed_content_node_tip',
'attributes callback' => 'shortcode_embed_content_attributes',
'default settings' => array(),
);
return $shortcodes;
}
function shortcode_embed_content_attributes($form, &$form_state) {
$form['embed_content-nid'] = array(
'#title' => t('Node nid'),
'#type' => 'textfield',
'#states' => array(
'visible' => array(
':input[name="shortcode"]' => array(
'value' => 'embed_content',
),
),
),
);
$form['embed_content-class'] = array(
'#title' => t('Class'),
'#type' => 'textfield',
'#states' => array(
'visible' => array(
':input[name="shortcode"]' => array(
'value' => 'embed_content',
),
),
),
);
$form['embed_content-view_mode'] = array(
'#title' => t('View mode'),
'#type' => 'textfield',
'#states' => array(
'visible' => array(
':input[name="shortcode"]' => array(
'value' => 'embed_content',
),
),
),
);
$form['embed_content-show_title'] = array(
'#title' => t('Show title'),
'#type' => 'select',
'#options' => array(
'true' => 'True',
'false' => 'False',
),
'#states' => array(
'visible' => array(
':input[name="shortcode"]' => array(
'value' => 'embed_content',
),
),
),
);
$form['embed_content-show_submitted'] = array(
'#title' => t('Show submitted'),
'#type' => 'select',
'#options' => array(
'true' => 'True',
'false' => 'False',
),
'#states' => array(
'visible' => array(
':input[name="shortcode"]' => array(
'value' => 'embed_content',
),
),
),
);
$form['embed_content-show_meta'] = array(
'#title' => t('Show meta'),
'#type' => 'select',
'#options' => array(
'true' => 'True',
'false' => 'False',
),
'#states' => array(
'visible' => array(
':input[name="shortcode"]' => array(
'value' => 'embed_content',
),
),
),
);
$form['embed_content-show_terms'] = array(
'#title' => t('Show terms'),
'#type' => 'select',
'#options' => array(
'true' => 'True',
'false' => 'False',
),
'#states' => array(
'visible' => array(
':input[name="shortcode"]' => array(
'value' => 'embed_content',
),
),
),
);
$form['embed_content-show_links'] = array(
'#title' => t('Show links'),
'#type' => 'select',
'#options' => array(
'true' => 'True',
'false' => 'False',
),
'#states' => array(
'visible' => array(
':input[name="shortcode"]' => array(
'value' => 'embed_content',
),
),
),
);
return $form;
}
function shortcode_embed_content_shortcode_node($attrs, $text) {
$attrs = shortcode_attrs(array(
'nid' => 0,
'class' => '',
'view_mode' => 'teaser',
'show_title' => FALSE,
'show_submitted' => FALSE,
'show_meta' => FALSE,
'show_terms' => FALSE,
'show_links' => FALSE,
), $attrs);
if (!empty($attrs['nid'])) {
$node = node_load($attrs['nid']);
if (empty($node) || !$node->status || !node_access('view', $node)) {
return '';
}
$node->shortcode_embedded = TRUE;
}
else {
return '';
}
$params = new stdClass();
$params->embedded = TRUE;
$params->view_mode = $params->original_view_mode = $attrs['view_mode'];
$params->show_title = shortcode_bool($attrs['show_title']);
$params->show_meta = shortcode_bool($attrs['show_meta']);
$params->show_submitted = shortcode_bool($attrs['show_submitted']);
$params->show_terms = shortcode_bool($attrs['show_terms']);
$params->show_links = shortcode_bool($attrs['show_links']);
$params->attrs = $attrs;
$node->shortcode = $params;
if ('full' == $attrs['view_mode']) {
$params->view_mode = 'teaser';
}
$content = node_view($node, $params->view_mode);
return render($content);
}
function shortcode_embed_content_node_tip($format, $long) {
$output = '';
$output = '<p><strong>[embed_content nid=nodeid (class="additional class")][/embed_content]</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_content_preprocess_node(&$vars) {
if (isset($vars['shortcode']) && $vars['shortcode']->embedded) {
$vars['template_files'][] = "node-shortcode--default";
$vars['template_files'][] = 'node-shortcode--' . $vars['type'];
}
}