forked from Bynder/drupal-media-bynder
-
Notifications
You must be signed in to change notification settings - Fork 0
/
media_bynder.module
179 lines (158 loc) · 4.48 KB
/
media_bynder.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
173
174
175
176
177
178
179
<?php
/**
* @file
* A block module that displays recent blog and forum posts.
*/
/**
* load configuration settings
*/
include_once dirname(__FILE__) . '/includes/media_bynder.utils.inc';
// Hooks and callbacks for integrating with File Entity module for display.
require_once dirname(__FILE__) . '/includes/media_bynder.formatters.inc';
require_once dirname(__FILE__) . '/includes/media_bynder.admin.inc';
/**
* Implements hook_stream_wrappers().
*/
function media_bynder_stream_wrappers() {
return array(
'bynder' => array(
'name' => t('Bynder media'),
'class' => 'MediaBynderStreamWrapper',
'description' => t('Media provided by Bynder.'),
'type' => STREAM_WRAPPERS_READ_VISIBLE | STREAM_WRAPPERS_WRITE_VISIBLE
)
);
}
/**
* Implements hook_media_browser_plugin_info().
*/
function media_bynder_media_browser_plugin_info() {
$info['media_bynder'] = array(
'title' => t('Bynder'),
'class' => 'MediaBynderBrowser'
);
return $info;
}
/**
* Implements hook_help().
*
* Displays help and module information.
*/
function media_bynder_help($path, $arg) {
switch ($path) {
case "admin/advanced_help#media_bynder":
return '<p>' . t("Advanced Help: Displays links to nodes created on this date") . '</p>';
case "admin/help#media_bynder":
return '<p>' . t("Help: Displays links to nodes created on this date") . '</p>';
}
}
/**
* Implements hook_permission().
*/
function media_bynder_permission() {
return array(
'administer media bynder' => array(
'title' => t('Administer Media: Bynder'),
'description' => t('Configure Bynder API connection settings.'),
),
);
}
/**
* Implements hook menu().
*/
function media_bynder_menu() {
$items = array();
$items['admin/config/media/media_bynder'] = array(
'title' => 'Bynder Settings',
'description' => 'Configuration for media bynder module',
'page callback' => 'drupal_get_form',
'page arguments' => array(
'media_bynder_form'
),
'access arguments' => array(
'administer media bynder'
),
'file' => 'includes/media_bynder.admin.inc',
'type' => MENU_NORMAL_ITEM
);
$items['media_bynder'] = array(
'title' => 'Media',
'page callback' => '_media_bynder_page',
'access arguments' => array(
'access media_bynder content'
),
// Will appear in Navigation menu.
'type' => MENU_NORMAL_ITEM
);
$items['media/add/media_bynder'] = array(
'title' => 'Add media from Bynder',
'page callback' => 'drupal_get_form',
'page arguments' => array(
'media_bynder_add'
),
'access arguments' => array(
'administer site configuration'
),
'type' => MENU_LOCAL_ACTION,
'file' => 'includes/media_bynder.admin.inc',
'weight' => -1
);
$items['admin/content/media/add/media_bynder'] = $items['media/add/media_bynder'];
return $items;
}
/**
* Implements hook_library().
*/
function media_bynder_library() {
$path = drupal_get_path('module', 'media_bynder');
$info = system_get_info('module', 'media_bynder');
$common = array(
'website' => 'http://www.getbynder.com',
'version' => !empty($info['version']) ? $info['version'] : '7.x-1.x',
);
// Powers the 'Add media from Bynder' page.
$libraries['media_bynder_administration'] = array(
'title' => 'Media: Bynder Administration',
'js' => array(
$path . '/js/media_bynder.js' => array(
'group' => JS_LIBRARY,
'weight' => -5,
),
),
'css' => array(
$path . '/media_bynder.css' => array(),
),
'dependencies' => array(
array('media_bynder', 'spin'),
),
);
// Generates animated CSS3 loading spinners.
$libraries['spin'] = array(
'title' => 'Spin',
'js' => array(
$path . '/js/spin.min.js' => array(
'group' => JS_DEFAULT,
),
),
);
// Add common information to each library.
foreach ($libraries as &$library) {
$library += $common;
}
return $libraries;
}
/**
* Before saving the file.
*
* @param unknown $file
* the file
*/
function media_bynder_file_presave($file) {
if (stristr($file->uri, 'bynder://')) {
if (($file->type) == 'image') {
$file->filemime = 'image/bynder';
} elseif (($file->type) == 'video') {
$file->filemime = 'video/bynder';
}
}
}