| 1 |
<?php
|
| 2 |
// $Id: media.forms.inc,v 1.3 2008/12/16 15:11:46 rhys Exp $
|
| 3 |
|
| 4 |
/**
|
| 5 |
* The View media form
|
| 6 |
*/
|
| 7 |
function mmedia_view_form(&$form_state, $media) {
|
| 8 |
// allow various other modules to do things to view
|
| 9 |
$profile = variable_get('mmedia_view_profile', NULL);
|
| 10 |
$profile = ($profile && in_array($profile, mapi_profile_list()) ? array('profile' => $profile) : array());
|
| 11 |
|
| 12 |
drupal_set_title(t($media->title));
|
| 13 |
$breadcrumbs = _mmedia_set_breadcrumb(mmedia_folder_load($media->fid));
|
| 14 |
drupal_set_breadcrumb($breadcrumbs);
|
| 15 |
|
| 16 |
// allows for overriding the view form easily
|
| 17 |
$form['#media'] = $media;
|
| 18 |
|
| 19 |
// display the result
|
| 20 |
$form['display'] = array(
|
| 21 |
'#prefix' => '<div class="media-content">',
|
| 22 |
'#value' => mapi_display(media_filename($media), $profile),
|
| 23 |
'#suffix' => '</div>',
|
| 24 |
);
|
| 25 |
|
| 26 |
$display = media_invoke_metadata('view', media_metadata_load($media->mid));
|
| 27 |
if ($display) {
|
| 28 |
$form['metadata'] = array(
|
| 29 |
'#prefix' => '<div class="media-content">',
|
| 30 |
'#suffix' => '</div>',
|
| 31 |
);
|
| 32 |
|
| 33 |
$form['metadata'] = array_merge($form['metadata'], $display);
|
| 34 |
}
|
| 35 |
|
| 36 |
return $form;
|
| 37 |
}
|
| 38 |
|
| 39 |
/**
|
| 40 |
* The Edit/Add media form
|
| 41 |
*/
|
| 42 |
function mmedia_edit_form(&$form_state, $media, $type = NULL) {
|
| 43 |
// useful for editing the details of a media file.
|
| 44 |
$edit = $media;
|
| 45 |
if (is_null($edit)) {
|
| 46 |
$edit = new stdClass;
|
| 47 |
$edit->type = NULL;
|
| 48 |
if (in_array($type, mapi_type_list($type))) {
|
| 49 |
$edit->type = $type;
|
| 50 |
}
|
| 51 |
}
|
| 52 |
else {
|
| 53 |
$media->filename = media_filename($media);
|
| 54 |
$media->metadata = media_metadata_load($media->mid);
|
| 55 |
}
|
| 56 |
|
| 57 |
$breadcrumbs = _mmedia_set_breadcrumb(mmedia_folder_load($media->fid));
|
| 58 |
if ($media) {
|
| 59 |
$breadcrumbs[] = l($media->title, MEDIA_PATH .'/'. $media->mid);
|
| 60 |
}
|
| 61 |
drupal_set_breadcrumb($breadcrumbs);
|
| 62 |
|
| 63 |
// generate the form give the correct
|
| 64 |
$form = _mmedia_form($edit);
|
| 65 |
|
| 66 |
// add the buttons
|
| 67 |
if (is_null($media)) {
|
| 68 |
$form['preview'] = array('#type' => 'button', '#value' => t('Preview'));
|
| 69 |
}
|
| 70 |
$form['submit'] = array('#type' => 'submit', '#value' => $media->mid ? t('Update') : t('Create'));
|
| 71 |
if (!is_null($media)) {
|
| 72 |
$form['delete'] = array('#type' => 'button', '#value' => t('Delete'));
|
| 73 |
}
|
| 74 |
|
| 75 |
return $form;
|
| 76 |
}
|
| 77 |
|
| 78 |
/**
|
| 79 |
* Validation of the media form
|
| 80 |
*/
|
| 81 |
function mmedia_edit_form_validate($form, &$form_state) {
|
| 82 |
$values = $form_state['values'];
|
| 83 |
if ($values['op'] == t('Delete')) {
|
| 84 |
drupal_goto(MEDIA_PATH .'/'. $values['mid'] .'/delete');
|
| 85 |
exit();
|
| 86 |
}
|
| 87 |
_mmedia_form_process($values);
|
| 88 |
}
|
| 89 |
|
| 90 |
/**
|
| 91 |
* Submission for the Edit Form
|
| 92 |
*/
|
| 93 |
function mmedia_edit_form_submit($form, &$form_state) {
|
| 94 |
$values = $form_state['values'];
|
| 95 |
$media = _mmedia_form_post($values);
|
| 96 |
if ($media->mid) {
|
| 97 |
$form_state['mid'] = $media->mid;
|
| 98 |
$form_state['redirect'] = MEDIA_PATH .'/'. $media->mid;
|
| 99 |
}
|
| 100 |
}
|
| 101 |
|
| 102 |
/**
|
| 103 |
* Deletion of media form.
|
| 104 |
*/
|
| 105 |
function mmedia_delete_form($form_state, $media) {
|
| 106 |
// load the media item
|
| 107 |
$breadcrumbs = _mmedia_set_breadcrumb(mmedia_folder_load($media->fid));
|
| 108 |
$breadcrumbs[] = l($media->title, MEDIA_PATH .'/'. $media->mid);
|
| 109 |
drupal_set_breadcrumb($breadcrumbs);
|
| 110 |
|
| 111 |
// remember for confirmation of the media
|
| 112 |
$form['mid'] = array('#type' => 'value', '#value' => $media->mid);
|
| 113 |
|
| 114 |
// provide user interaction
|
| 115 |
$notice = t('This action cannot be undone.');
|
| 116 |
|
| 117 |
$form = confirm_form($form,
|
| 118 |
t('Are you sure you want to delete %title?', array('%title' => $media->title)),
|
| 119 |
isset($_GET['destination']) ? $_GET['destination'] : MEDIA_PATH ."/{$mid}/view",
|
| 120 |
$notice,
|
| 121 |
t('Delete'), t('Cancel'));
|
| 122 |
|
| 123 |
return $form;
|
| 124 |
}
|
| 125 |
|
| 126 |
/**
|
| 127 |
* Submission for media delete
|
| 128 |
*/
|
| 129 |
function mmedia_delete_form_submit($form, &$form_state) {
|
| 130 |
$values = $form_state['values'];
|
| 131 |
if ($values['confirm'] == 1) {
|
| 132 |
$mid = $values['mid'];
|
| 133 |
media_delete($mid);
|
| 134 |
}
|
| 135 |
|
| 136 |
$form_state['redirect'] = '<front>';
|
| 137 |
}
|
| 138 |
|
| 139 |
/**
|
| 140 |
* Move media from one folder to another.
|
| 141 |
*/
|
| 142 |
function mmedia_move_form(&$form_state, $media) {
|
| 143 |
drupal_add_css(drupal_get_path('module', 'mmedia') .'/mmedia.css');
|
| 144 |
|
| 145 |
$breadcrumbs = _mmedia_set_breadcrumb(mmedia_folder_load($media->fid));
|
| 146 |
$breadcrumbs[] = l($media->title, MEDIA_PATH .'/'. $media->mid);
|
| 147 |
drupal_set_breadcrumb($breadcrumbs);
|
| 148 |
|
| 149 |
$folders = _mmedia_folder_cache();
|
| 150 |
|
| 151 |
// add everything else
|
| 152 |
$current = 0;
|
| 153 |
$lines = $folders['line'];
|
| 154 |
foreach ($lines as $line => $fid) {
|
| 155 |
$depth = (count(explode('/', $line)) - FOLDER_PATH_ARG - 1);
|
| 156 |
|
| 157 |
// add the appropriate boundaries for accordian viewing
|
| 158 |
$prefix = '';
|
| 159 |
while ($depth > $current++) {
|
| 160 |
$prefix .= '<div class="folder-level">';
|
| 161 |
}
|
| 162 |
while ($current > $depth + 1) {
|
| 163 |
$prefix .= '</div>';
|
| 164 |
$current--;
|
| 165 |
}
|
| 166 |
|
| 167 |
// generate the radio buttons for the various items
|
| 168 |
$form['radios'][$line] = array(
|
| 169 |
'#prefix' => $prefix .'<div class="folder-level-'. $depth .'">',
|
| 170 |
'#type' => 'radio',
|
| 171 |
'#title' => $folders[$fid]['name'],
|
| 172 |
'#return_value' => $fid,
|
| 173 |
'#default_value' => ($fid == $media->fid ? $fid : FALSE),
|
| 174 |
'#parents' => array('folder'),
|
| 175 |
'#suffix' => '</div>'
|
| 176 |
);
|
| 177 |
$current = $depth;
|
| 178 |
}
|
| 179 |
$form['radios']['#suffix'] = '';
|
| 180 |
while ($current > 0) {
|
| 181 |
$form['radios']['#suffix'] .= '</div>';
|
| 182 |
$current--;
|
| 183 |
}
|
| 184 |
|
| 185 |
$form['submit'] = array('#type' => 'submit', '#value' => t('Move'));
|
| 186 |
$form['mid'] = array('#type' => 'value', '#value' => $media->mid);
|
| 187 |
|
| 188 |
return $form;
|
| 189 |
}
|
| 190 |
|
| 191 |
/**
|
| 192 |
* Submission for the move form
|
| 193 |
*/
|
| 194 |
function mmedia_move_form_submit($form, &$form_state) {
|
| 195 |
$values = $form_state['values'];
|
| 196 |
if ($values['op'] == t('Move')) {
|
| 197 |
media_move($values['mid'], $values['folder']);
|
| 198 |
}
|
| 199 |
}
|
| 200 |
|