forked from artesis/ding_content
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathding_content.admin.inc
More file actions
204 lines (172 loc) · 6.32 KB
/
ding_content.admin.inc
File metadata and controls
204 lines (172 loc) · 6.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
<?php
/**
* @file
* Admin page callbacks for the ding_content module.
*/
/**
* AJAX Callback function to return a list of media files
*
* More or less a copy of the media_browser_list callback.
* @see media_browser_list()
*/
function ding_content_media_browser_list() {
module_load_include('inc', 'media', 'includes/media.browser');
global $user;
$params = drupal_get_query_parameters();
// How do we validate these? I don't know.
// I think PDO should protect them, but I'm not 100% certain.
array_walk_recursive($params, '_media_recursive_check_plain');
$types = isset($params['types']) ? $params['types'] : NULL;
$url_include_patterns = isset($params['url_include_patterns']) ? $params['url_include_patterns'] : NULL;
$url_exclude_patterns = isset($params['url_exclude_patterns']) ? $params['url_exclude_patterns'] : NULL;
$start = isset($params['start']) ? $params['start'] : 0;
$limit = isset($params['limit']) ? $params['limit'] : media_variable_get('browser_pager_limit');
$query = db_select('file_managed', 'f');
$query->fields('f', array('fid'));
$query->range($start, $limit);
$query->orderBy('f.fid', 'DESC');
// Add conditions based on file type *or* allowed extensions.
$condition = $query;
if (!empty($types) && !empty($params['file_extensions'])) {
$condition = db_or();
}
if (!empty($types)) {
$condition->condition('f.type', $types, 'IN');
}
if (!empty($params['file_extensions'])) {
$extensions = array_filter(explode(' ', $params['file_extensions']));
foreach ($extensions as $extension) {
$condition->condition('f.uri', '%' . db_like('.' . $extension), 'LIKE');
}
}
if ($condition instanceof DatabaseCondition) {
$query->condition($condition);
}
if ($url_include_patterns) {
$query->condition('f.uri', '%' . db_like($v) . '%', 'LIKE');
// Insert stream related restrictions here.
}
if ($url_exclude_patterns) {
$query->condition('f.uri', '%' . db_like($v) . '%', 'NOT LIKE');
}
// @todo Implement granular editorial access: http://drupal.org/node/696970.
// In the meantime, protect information about private files from being
// discovered by unprivileged users. See also media_view_page().
if (!user_access('administer media')) {
$query->condition('f.uri', db_like('private://') . '%', 'NOT LIKE');
}
$query->condition('f.status', FILE_STATUS_PERMANENT);
$query->condition('f.uid', $user->uid);
foreach (array_keys(media_get_hidden_stream_wrappers()) as $name) {
$query->condition('f.uri', db_like($name . '://') . '%', 'NOT LIKE');
}
$fids = $query->execute()->fetchCol();
dd('test');
dd($fids);
$files = file_load_multiple($fids);
foreach ($files as $file) {
media_browser_build_media_item($file);
}
drupal_json_output(array('media' => array_values($files)));
exit();
}
/**
* Category foldable menu settings form.
*/
function ding_content_foldable_menu_admin($form, $form_state) {
$voc = taxonomy_vocabulary_machine_name_load('category');
if (is_object($voc)) {
$tree = taxonomy_get_tree($voc->vid);
$range = range(1, 10);
$form['category_hits'] = array(
'#type' => 'select',
'#title' => t('Number of nodes shows in expanded area'),
'#options' => array_combine($range, $range),
'#default_value' => variable_get('category_hits', 4),
);
$form['category_empty'] = array(
'#type' => 'checkbox',
'#title' => t('Show empty categories'),
'#default_value' => variable_get('category_empty', FALSE),
'#description' => t('Show also the categories with no nodes attached to it.'),
);
$form['category_foldable_enabled'] = array(
'#type' => 'checkbox',
'#title' => t('Foldable category menu'),
'#description' => t('Enable the collapsible category menu feature.'),
'#default_value' => variable_get('category_foldable_enabled', FALSE),
);
$form['category_tree'] = array(
'#tree' => TRUE,
'#theme' => 'ding_content_category_table',
);
$defaults = variable_get('category_tree', array());
$c = count($tree);
for ($i = 0; $i < $c; $i++) {
$form['category_tree'][$i]['category_name'] = array(
'#type' => 'textfield',
'#value' => $tree[$i]->name,
'#disabled' => TRUE,
);
$form['category_tree'][$i]['category_expanded'] = array(
'#type' => 'checkbox',
'#default_value' => isset($defaults[$i]['category_expanded']) ? $defaults[$i]['category_expanded'] : FALSE,
);
$form['category_tree'][$i]['category_disabled'] = array(
'#type' => 'checkbox',
'#default_value' => isset($defaults[$i]['category_disabled']) ? $defaults[$i]['category_disabled'] : FALSE,
);
$form['category_tree'][$i]['category_weight'] = array(
'#type' => 'weight',
'#delta' => 10,
'#default_value' => isset($defaults[$i]['category_weight']) ? $defaults[$i]['category_weight'] : 0,
'#attributes' => array(
'class' => array('category-weight'),
)
);
$form['category_tree'][$i]['category_tid'] = array(
'#type' => 'hidden',
'#value' => $tree[$i]->tid,
);
}
}
else {
drupal_set_message(t('Seems there is no vocabulary with machine name `category`.'), 'error');
}
return system_settings_form($form);
}
/**
* Custom renderer for categroy menu admin form.
*
* Create a drag'n'drop weighted table.
*
* @see ding_content_foldable_menu_admin()
*/
function theme_ding_content_category_table($vars) {
$element = $vars['element'];
$rows = array();
$ch = array();
foreach (element_children($element) as $key) {
$ch[] = $element[$key];
}
usort($ch, '_ding_content_category_sort');
foreach ($ch as $ele) {
$rows[] = array(
'data' => array(
array('data' => render($ele['category_name'])),
array('data' => render($ele['category_expanded'])),
array('data' => render($ele['category_weight'])),
array('data' => render($ele['category_disabled'])),
),
'class' => array('draggable'),
);
}
$header = array(
t('Category'),
t('Expanded'),
t('Weight'),
t('Hidden'),
);
drupal_add_tabledrag('ding-content-category-foldable', 'order', 'sibling', 'category-weight');
return theme('table', array('header' => $header, 'rows' => $rows, 'attributes' => array('id' => 'ding-content-category-foldable')));
}