scs.theme.inc in Simplenews Content Selection 6.2
Same filename and directory in other branches
Select Drupal content to create a newsletter
File
scs.theme.incView source
<?php
/**
* @file
* Select Drupal content to create a newsletter
*/
/**
* Theme the node selection form
*/
function theme_scs_node_selection($form) {
if ($form['step']['#value'] == 1) {
$headers = array(
'',
t('Nid'),
t('Title'),
t('Created'),
);
//Headers
$headers = array(
'',
array(
'data' => t('Nid'),
'field' => 'nid',
'sort' => 'asc',
),
array(
'data' => t('Title'),
'field' => 'title',
),
array(
'data' => t('Created'),
'field' => 'created',
),
);
$return = _scs_get_nodes($headers);
$nodes = $return['nodes'];
$data = array();
$explain = '';
if (user_access('administer scs')) {
$explain = '<div class="form-item">' . t('Want to select more nodes? Add more content types ') . l('here', 'admin/settings/simplenews/scs') . '.' . '</div>';
}
foreach ($nodes as $node) {
if (array_key_exists('nid_' . $node->nid, $form)) {
$nodearray = array();
$nodearray[] = drupal_render($form['nid_' . $node->nid]);
$nodearray[] = $node->nid;
$nodearray[] = $node->title;
$nodearray[] = $node->created;
$data[] = $nodearray;
}
}
return drupal_render($form['newsletter_title']) . drupal_render($form['newsletter_toc']) . drupal_render($form['newsletter_type']) . drupal_render($form['newsletter_content_type']) . $explain . drupal_render($form['filters']) . theme('table', $headers, $data) . $return['pager'] . drupal_render($form);
}
else {
return theme('scs_sort_nodes', $form);
}
}
/**
* Each selected node goes true this function to create a nice body
*/
function theme_scs_node_output($node) {
$output = '';
$output = '<div id="node_' . $node->nid . '">';
$output .= '<h1>' . $node->title . '</h1>';
$output .= '<p>' . node_teaser($node->body) . '</p>';
$output .= '<p>' . l(t('Read more'), 'node/' . $node->nid) . '</p>';
$output .= '</div>';
return $output;
}
/**
* Theme the node sort form into a table
*/
function theme_scs_sort_nodes($form) {
$headers = array(
t('Node title'),
t('Weight'),
);
$rows = array();
foreach ($form as $name => $field) {
if (ereg('weight_', $name)) {
$nid = explode('_', $name);
$nid = $nid[1];
if (is_numeric($nid)) {
$title = db_result(db_query('SELECT title FROM {node} WHERE nid = %d', $nid));
unset($form[$name]['#title']);
$row = array();
$row[] = $title;
$row[] = drupal_render($form[$name]);
$rows[] = array(
'data' => $row,
'class' => 'draggable tabledrag-leaf',
);
}
}
}
//Starting output
$output = '';
$output .= drupal_render($form['newsletter_title']);
$output .= drupal_render($form['newsletter_toc']);
$output .= drupal_render($form['newsletter_content_type']);
$output .= drupal_render($form['newsletter_type']);
//Sections
for ($i = 0; $i < 10; $i++) {
$caption = t('Section') . ' ' . $i + 1;
$output .= theme('table', $headers, $sectionrows, array(
'id' => 'scs_node_sort_table_section_' . $i + 1,
), $caption);
drupal_add_tabledrag('my-module-table', 'order', 'sibling', 'scs_weight', 'scs_weight_' . $i + 1);
}
$output .= theme('table', $headers, $rows, array(
'id' => 'scs_node_sort_table',
));
$output .= drupal_render($form);
drupal_add_tabledrag('scs_node_sort_table', 'order', 'sibling', 'scs_weight');
return $output;
}
/**
* Theme function to add the titles of the selected nodes at top of the newsletter
*/
function theme_scs_node_titles($titles) {
if (variable_get('scs_format', 'plain') == 'plain') {
return implode("\n", $titles);
}
else {
return '<div id="toc">' . theme('item_list', $titles) . '</div>';
}
}
/**
* Theme a complete newsletter.
*/
function theme_scs_newsletter_output($options) {
$body = '';
$titles = array();
$nodes = $options['nodes'];
$format = variable_get('scs_format', 'plain');
if (count($nodes) == 1) {
$nodes = array_shift($nodes);
// Node information
foreach ($nodes as $node) {
if ($options['toc']) {
if ($format == 'plain') {
$titles[] = $node->title;
}
else {
$titles[] = '<a href="#node_' . $node->nid . '">' . $node->title . '</a>';
}
}
$body .= theme(array(
'scs_node_output__' . $options['type'],
'scs_node_output',
), $node);
}
}
else {
foreach ($nodes as $region => $elements) {
$regioncontent = '';
foreach ($elements as $node) {
if ($format == 'plain') {
$titles[] = $node->title;
}
else {
$titles[] = '<a href="#node_' . $node->nid . '">' . $node->title . '</a>';
}
$regioncontent .= theme(array(
'scs_node_output__region-' . $region . '_' . $options['type'],
'scs_node_output__region_' . $region,
'scs_node_output__' . $options['type'],
'scs_node_output',
), $node);
}
$body .= theme(array(
'scs_region_output__' . $region,
'scs_region_output',
), $region, $regioncontent);
}
}
// ToC (if required)
if ($options['toc']) {
$body = theme('scs_node_titles', $titles) . $body;
}
// Complete newsletter body
return $body;
}
/**
* Theme a region block
*/
function theme_scs_region_output($regionid, $content) {
$output = '';
$output .= sprintf('<div class="region" id="region-%d">', $regionid);
$output .= '<h1>Region ' . $regionid . '</h1>';
$output .= $content;
$output .= sprintf('</div>');
return $output;
}
Functions
Name![]() |
Description |
---|---|
theme_scs_newsletter_output | Theme a complete newsletter. |
theme_scs_node_output | Each selected node goes true this function to create a nice body |
theme_scs_node_selection | Theme the node selection form |
theme_scs_node_titles | Theme function to add the titles of the selected nodes at top of the newsletter |
theme_scs_region_output | Theme a region block |
theme_scs_sort_nodes | Theme the node sort form into a table |