| 1 |
<?php
|
| 2 |
/* $Id */
|
| 3 |
|
| 4 |
/* An iterface which ideally belongs in flexinode
|
| 5 |
* @return an array of 'ctype_id' -> $name
|
| 6 |
*/
|
| 7 |
function flexinode_content_types_array() {
|
| 8 |
static $types;
|
| 9 |
if (!isset($types)) {
|
| 10 |
$types = array();
|
| 11 |
$result = db_query('SELECT * FROM {flexinode_type}');
|
| 12 |
while ($type = db_fetch_object($result)) {
|
| 13 |
$types[$type->ctype_id] = $type->name;
|
| 14 |
}
|
| 15 |
}
|
| 16 |
return $types;
|
| 17 |
}
|
| 18 |
|
| 19 |
function filebrowser_flexinode_type() {
|
| 20 |
$ctype_id=variable_get('filebrowser_flexinode_ctype', NULL);
|
| 21 |
if(isset($ctype_id)){
|
| 22 |
return 'flexinode-'.$ctype_id;
|
| 23 |
}
|
| 24 |
}
|
| 25 |
|
| 26 |
/**
|
| 27 |
* a settings mixin.
|
| 28 |
*/
|
| 29 |
function filebrowser_flexinode_settings() {
|
| 30 |
if (module_exist('flexinode')) {
|
| 31 |
$ctype=variable_get('filebrowser_flexinode_ctype', NULL);
|
| 32 |
$types = flexinode_content_types_array();
|
| 33 |
$output = form_select(t('File type'), 'filebrowser_flexinode_ctype', $ctype, $types, t('The flexinode type to browse'));
|
| 34 |
} else {
|
| 35 |
$output = "Please install th flexinode module";
|
| 36 |
}
|
| 37 |
return $output;
|
| 38 |
}//filebrowser settings
|
| 39 |
|
| 40 |
|
| 41 |
/* flexinode mixin for filebrowser
|
| 42 |
*/
|
| 43 |
function flexinode_filebrowser($tid=0) {
|
| 44 |
$output = '';
|
| 45 |
//mostly copied from flexinode_page_table
|
| 46 |
//substitute to select the flexinode type in the settings page
|
| 47 |
$ctype_id=variable_get('filebrowser_flexinode_ctype', 1);
|
| 48 |
$ctype = flexinode_load_content_type($ctype_id);
|
| 49 |
|
| 50 |
// Build the query.
|
| 51 |
$fields_to_select = array();
|
| 52 |
$table_joins = array();
|
| 53 |
$where_clauses = array();
|
| 54 |
|
| 55 |
foreach ($ctype->fields as $field) {
|
| 56 |
$fieldname = 'flexinode_'. $field->field_id;
|
| 57 |
|
| 58 |
$fields_to_select[] = flexinode_invoke('db_select', $field);
|
| 59 |
$table_joins[] = 'LEFT JOIN {flexinode_data} '. $fieldname .' ON n.nid = '. $fieldname.'.nid';
|
| 60 |
$where_clauses[] = $fieldname .'.field_id = '. $field->field_id;
|
| 61 |
}
|
| 62 |
|
| 63 |
$table_joins[]= taxonomy_term_node_join();
|
| 64 |
|
| 65 |
if($tnw = taxonomy_term_node_where($tid)) {
|
| 66 |
$where_clauses[] = $tnw;
|
| 67 |
}
|
| 68 |
|
| 69 |
$type = 'flexinode-' . check_query($ctype_id);
|
| 70 |
$extra_fields = count($fields_to_select) > 0 ? ', ' . implode(', ', $fields_to_select) : '';
|
| 71 |
$extra_where = count($where_clauses) > 0 ? ' AND ' . implode(' AND ', $where_clauses) : '';
|
| 72 |
$sql = 'SELECT n.title, n.nid'. $extra_fields .' FROM {node} n '. node_access_join_sql() .' '. implode(' ', $table_joins) .' WHERE n.status = 1 AND '. node_access_where_sql() ." AND n.type = '$type'". $extra_where;
|
| 73 |
|
| 74 |
|
| 75 |
// Build the columns.
|
| 76 |
$header[] = array('data' => t('title'), 'field' => 'n.title');
|
| 77 |
foreach ($ctype->fields as $field) {
|
| 78 |
if ($field->show_table) {
|
| 79 |
$fieldname = 'flexinode_'. $field->field_id;
|
| 80 |
|
| 81 |
$sort_column = flexinode_invoke('db_sort_column', $field);
|
| 82 |
if ($sort_column) {
|
| 83 |
$header[] = array('data' => t($field->label), 'field' => $sort_column);
|
| 84 |
}
|
| 85 |
else {
|
| 86 |
$header[] = array('data' => t($field->label));
|
| 87 |
}
|
| 88 |
}
|
| 89 |
}
|
| 90 |
|
| 91 |
$sql .= tablesort_sql($header);
|
| 92 |
|
| 93 |
// Build the rows.
|
| 94 |
$rows = array();
|
| 95 |
$nodes = pager_query($sql, 20);
|
| 96 |
while ($node = db_fetch_object($nodes)) {
|
| 97 |
$row = array(l($node->title, 'node/' . $node->nid));
|
| 98 |
foreach ($ctype->fields as $field) {
|
| 99 |
if ($field->show_table) {
|
| 100 |
$data = flexinode_invoke('format', $field, $node, TRUE);
|
| 101 |
$row[] = $data ? $data : '';
|
| 102 |
}
|
| 103 |
}
|
| 104 |
$rows[] = $row;
|
| 105 |
}
|
| 106 |
|
| 107 |
return array('header'=>$header,'rows'=>$rows);
|
| 108 |
}
|
| 109 |
?>
|