function _scs_get_nodes in Simplenews Content Selection 6.2
Same name and namespace in other branches
- 6 scs.module \_scs_get_nodes()
Get nodes avaiable for selection
2 calls to _scs_get_nodes()
- scs_node_selection in ./
scs.pages.inc - theme_scs_node_selection in ./
scs.theme.inc - Theme the node selection form
File
- ./
scs.module, line 148 - Select Drupal content to create a newsletter
Code
function _scs_get_nodes($headers = array(), $filters = array()) {
$nodes = array();
$content_types = variable_get('scs_content_types', array());
$content_types = array_filter($content_types);
$content_types = implode('\', \'', $content_types);
if (count($content_types) != 0) {
//Filters
if (!empty($filters)) {
$filtersql = array();
if (array_key_exists('nid', $filters)) {
$filtersql[] = sprintf('nid=%d', $filters['nid']);
}
if (array_key_exists('title', $filters)) {
$filtersql[] = "title LIKE '" . $filters['title'] . "%'";
}
if (array_key_exists('type', $filters)) {
$content_types = array(
$filters['type'],
);
}
$prefix = '';
if (!empty($filtersql)) {
$prefix = ' AND ';
}
$filtersql = $prefix . implode(' AND ', $filtersql);
}
$p = db_placeholders($content_types, 'varchar');
//Table sort
if (!empty($headers)) {
$tablesortsql = tablesort_sql($headers);
}
else {
if (isset($_GET['sort']) && isset($_GET['order'])) {
switch ($_GET['order']) {
case t('Nid'):
$field = 'nid';
break;
case t('Title'):
$field = 'title';
break;
case t('Created'):
$field = 'created';
break;
}
$tablesortsql = sprintf('ORDER BY %s %s', $field, strtoupper($_GET['sort']));
}
else {
$tablesortsql = 'ORDER BY nid ASC';
}
}
$query = "SELECT nid, title, created FROM {node} WHERE ({node}.status <> 0) AND type IN ('{$content_types}'){$filtersql} {$tablesortsql}";
$result = pager_query($query, 25, 0);
$pager = theme('pager');
while ($node = db_fetch_object($result)) {
$node->created = date('Y-m-d H:i:s', $node->created);
$nodes[] = $node;
}
}
return array(
'nodes' => $nodes,
'pager' => $pager,
);
}