-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathspringfiles.module
More file actions
159 lines (138 loc) · 4.94 KB
/
springfiles.module
File metadata and controls
159 lines (138 loc) · 4.94 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
<?php
require_once ( dirname(__FILE__) . '/springfiles.views.inc');
//implementation of hook_menu
function springfiles_menu() {
$items = array();
$items['publisher/autocomplete'] = array(
'page callback' => 'springfiles_publisher_autocomplete',
'type' => MENU_CALLBACK,
'access arguments' => array('create file content'),
);
$items['filereference/autocomplete'] = array(
'page callback' => 'springfiles_filereference_autocomplete',
'type' => MENU_CALLBACK,
'access arguments' => array('create file content'),
);
$items['download.php'] = array(
'page callback' => 'springfiles_download_redirect',
'type' => MENU_CALLBACK,
'access arguments' => array('access content'),
);
$items['subcategory.php'] = array(
'page callback' => 'springfiles_main_redirect',
'type' => MENU_CALLBACK,
'access arguments' => array('access content'),
);
return $items;
}
//autocomplete function for content_type file author field
function springfiles_publisher_autocomplete($string = '') {
$matches = array();
if ($string) {
$result = db_query_range("SELECT name FROM {users} WHERE LOWER(name) LIKE LOWER('%%%s%%')", $string, 0, 10);
while ($data = db_fetch_object($result)) {
$matches[$data->name] = check_plain($data->name);
}
}
print drupal_to_js($matches);
exit();
}
//autocomplete function for filereference field
function springfiles_filereference_autocomplete($string = '') {
$matches = array();
if ($string) {
$result = db_query_range("SELECT filename FROM {files} WHERE LOWER(filename) LIKE LOWER('%%%s%%')", $string, 0, 10);
while ($data = db_fetch_object($result)) {
$matches[$data->name] = check_plain($data->name);
}
}
print drupal_to_js($matches);
exit();
}
//implementation of hook_form_alter
function springfiles_form_alter(&$form, &$form_state, $form_id) {
//add autocomplete for filereference field
if ($form_id == 'details_springmap_node_form')
{
$form['field_file_reference']['#default_value'][0]['value'] = arg(3);
}
//add autocomplete for file author field
if ($form_id == 'file_node_form')
{
$form['field_author'][0]['#autocomplete_path'] = 'publisher/autocomplete';
$default_author = user_load(array('uid' => $form['uid']['#value']));
$form['field_author'][0]['#default_value']['value'] = $default_author->name;
$form['field_file'][1]['#type'] = 'value';
unset($form['field_file'][1]);
$form['field_sfid'][0]['#type'] = 'value';
}
if ($form_id == 'comment_form') {
$form['comment_filter']['format'] = array();
}
if ($form['#id'] == 'views-exposed-form-categories-block-2') {
$form['title']['#size'] = 15;
$form['field_mapsizex_value']['#size'] = 10;
$form['field_mapsizey_value']['#size'] = 10;
}
if ($form['#id'] == 'views-exposed-form-front-block-3') {
$form['title']['#size'] = 15;
}
if ($form['#id'] == 'views-exposed-form-categories-block-4') {
$form['title']['#size'] = 15;
}
if ($form['#id'] == 'views-exposed-form-front-block-2') {
$form['title']['#size'] = 15;
}
}
//implementation of hook_nodeapi
//add download count info & file metadata to node object
function springfiles_nodeapi(&$node, $op, $teaser) {
global $user;
if ($node->type == 'file')
{
switch ($op) {
case 'view' :
$q = db_fetch_object(db_query("SELECT totalcount, daycount FROM {node_counter} WHERE nid = %d", $node->nid));
$node->totalcount = $q->totalcount;
$node->daycount = $q->daycount;
//add normalmap, heightmap and metalmap
$q = db_fetch_object(db_query("SELECT md5 FROM {filehash} WHERE fid = %d", $node->field_file[0]['fid']));
$content=file_get_contents("https://api.springfiles.com/json.php?metadata=on&images=on&md5=" . $q->md5);
$obj =json_decode($content);
$metadata = $obj[0];
if (isset($metadata->mapimages[0]))
{
$node->normalmap = $metadata->mapimages[0];
$node->heightmap = $metadata->mapimages[1];
$node->metalmap = $metadata->mapimages[2];
}
if (isset($metadata->splash))
{
foreach ($metadata->splash as $key => $splash)
{
$node->splash[$key] = $splash;
}
}
$node->metadata = $metadata->metadata;
break;
}
}
}
//checks if map details already exists
//returns object
function springfiles_springmap_exists ($filename)
{
$q = db_fetch_object(db_query("SELECT nid FROM {content_type_details_springmap} WHERE field_file_reference_value = '%s'", $filename));
return $q;
}
//keep support for old download links and redirect to new file location
function springfiles_download_redirect()
{
$q = db_fetch_object(db_query("SELECT filepath FROM {files} WHERE filename = '%s'", $_GET['file']));
$path = str_replace('sites/default','system', $q->filepath);
drupal_goto($path);
}
function springfiles_main_redirect()
{
drupal_goto('');
}