-
Notifications
You must be signed in to change notification settings - Fork 1
/
ding_redia_feed.module
172 lines (154 loc) · 5.47 KB
/
ding_redia_feed.module
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
<?php
/**
* @file
* Exposes ding content to the mobile app developed by Redia, via feeds.
*/
/**
* Implements hook_menu().
*/
function ding_redia_feed_menu() {
$items = array();
$items['admin/settings/ding_redia_feed'] = array(
'title' => 'Redia feed settings',
'description' => 'Settings for the Redia feed module.',
'page callback' => 'drupal_get_form',
'page arguments' => array('ding_redia_feed_settings_form'),
'access arguments' => array('access administration pages'),
);
return $items;
}
/**
* Implements hook_perm().
*/
function ding_redia_feed_perm() {
return array('input redia app setting for nodes');
}
/**
* General settings form.
*/
function ding_redia_feed_settings_form() {
$form = array();
$form['ding_redia_feed_nodes'] = array(
'#options' => node_get_types('names'),
'#type' => 'checkboxes',
'#default_value' => variable_get('ding_redia_feed_nodes', array()),
'#title' => t('Select which node types that should use the Redia app category'),
);
// Transform the user categories data structure into something user editable
// for the form in the format id|description
$categories = ding_redia_feed_user_categories();
foreach ($categories as $id => &$description) {
$description = $id . '|' . $description;
}
$categories = implode("\n", $categories);
$form['ding_redia_feed_categories'] = array(
'#type' => 'textarea',
'#title' => t('Redia app categories'),
'#description' => t('Enter the categories used by your Redia app. Enter one categories per line and separate id and description with a | e.g. "bahgf|Mobile app quadrant 1 (Upper left). <br/><strong>Important:</strong> These values must be provided to you by Redia. The default values are only examples."'),
'#default_value' => $categories,
);
return system_settings_form($form);
}
/**
* Settings form validation.
*/
function ding_redia_feed_settings_form_validate($form, &$form_state) {
// Transform the user submitted data into the category data structure
// array('id' => 'description')
$values = explode("\n", $form_state['values']['ding_redia_feed_categories']);
$categories = array();
foreach ($values as &$category_string) {
$category_values = explode('|', $category_string);
$categories[trim($category_values[0])] = trim($category_values[1]);
}
$form_state['values']['ding_redia_feed_categories'] = $categories;
}
/**
* Utility function to get the possible node app plaement options.
*/
function ding_redia_feed_app_categories() {
return array_merge(
// Always allow standard list view
array('' => t('Standard list view')),
ding_redia_feed_user_categories()
);
}
/**
* Utility function to get the user configurable node app plaement options.
*/
function ding_redia_feed_user_categories() {
return variable_get('ding_redia_feed_categories',
// Default values are based on the Copenhagen Ding site/app
array(
'bahgf' => 'Mobil app kvadrat 1 (Øverste venstre)',
'bahgg' => 'Mobil app kvadrat 2 (Øverste højre)',
'bahgh' => 'Mobil app kvadrat 3 (Nederste venstre)',
'bahgi' => 'Mobil app kvadrat 4 (Nederste højre)',
)
);
}
/**
* Implements hook_nodeapi().
*/
function ding_redia_feed_nodeapi(&$node, $op, $teaser = NULL, $page = NULL) {
switch ($op) {
case 'load':
$cat = db_result(db_query('SELECT category FROM {ding_redia_feed_cat} WHERE nid = %d', $node->nid));
$node->ding_redia_feed_cat = $cat ? $cat : '';
break;
case 'insert':
if (!empty($node->ding_redia_feed_cat)) {
$record = array('nid' => $node->nid, 'category' => $node->ding_redia_feed_cat);
drupal_write_record('ding_redia_feed_cat', $record);
}
break;
case 'update':
if (!empty($node->ding_redia_feed_cat)) {
db_query("UPDATE {ding_redia_feed_cat} SET category = '%s' WHERE nid = %d;", $node->ding_redia_feed_cat, $node->nid);
if (!db_affected_rows()) {
$record = array('nid' => $node->nid, 'category' => $node->ding_redia_feed_cat);
drupal_write_record('ding_redia_feed_cat', $record);
}
}
break;
}
}
/**
* Implements hook_form_alter().
*/
function ding_redia_feed_form_alter(&$form, &$form_state, $form_id) {
if (strpos($form_id, 'node_form') !== FALSE) {
if (in_array($form['#node']->type, array_filter(variable_get('ding_redia_feed_nodes', array())))) {
$form['ding_redia_feed_cat'] = array(
'#type' => 'select',
'#title' => t('Select Redia app placement'),
'#options' => ding_redia_feed_app_categories(),
'#default_value' => !empty($form['#node']->ding_redia_feed_cat) ? $form['#node']->ding_redia_feed_cat : '',
'#access' => user_access('input redia app setting for nodes'),
);
}
}
}
/**
* Implementation of hook_views_plugins().
*/
function ding_redia_feed_views_plugins() {
return array(
'module' => 'views',
'row' => array(
'ding_redia_rss' => array(
'title' => t('Redia node'),
'help' => t('Display the node with standard special redia rss format.'),
'handler' => 'ding_redia_feed_plugin_row_node_rss',
'path' => drupal_get_path('module', 'ding_redia_feed') . '/plugins',
'parent' => 'node_rss',
'theme' => 'views_view_row_rss',
'base' => array('node'), // only works with 'node' as base.
'uses options' => TRUE,
'type' => 'feed',
'help topic' => 'style-node-rss',
),
),
);
}
include_once('ding_redia_feed.features.inc');