| 1 |
<?php |
<?php |
| 2 |
// $Id: mmedia.module,v 1.1.2.3 2008/12/16 15:14:05 rhys Exp $ |
// $Id: mmedia.module,v 1.1.2.4 2009/02/02 12:13:27 casey Exp $ |
|
|
|
|
|
|
|
// This module allows for the creation and management of media. |
|
| 3 |
|
|
| 4 |
|
/** |
| 5 |
|
* @file |
| 6 |
|
* Media Management Module that allows the creation and management of media as files. |
| 7 |
|
*/ |
| 8 |
|
|
| 9 |
// For specific media |
// For specific media |
| 10 |
define('MMEDIA_PATH', trim(variable_get('mmedia_url', 'media'), '/')); |
define('MEDIA_PATH', trim(variable_get('mmedia_url', 'media'), '/')); |
| 11 |
define('MMEDIA_ARG', count(explode('/', MMEDIA_PATH)) - 1); |
define('MEDIA_ARG', count(explode('/', MMEDIA_PATH)) - 1); |
| 12 |
|
|
| 13 |
// For specific folders |
// For specific folders |
| 14 |
define('MMEDIA_FOLDER_PATH', trim(variable_get('mmedia_folder_url', 'folder'), '/')); |
define('FOLDER_PATH', trim(variable_get('mmedia_folder_url', 'folder'), '/')); |
| 15 |
define('MMEDIA_FOLDER_ARG', count(explode('/', MMEDIA_FOLDER_PATH)) - 1); |
define('FOLDER_ARG', count(explode('/', FOLDER_PATH)) - 1); |
| 16 |
|
|
| 17 |
// Install the API immediately |
// Install the API immediately |
| 18 |
$path = drupal_get_path('module', 'mmedia'); |
$path = drupal_get_path('module', 'mmedia'); |
| 19 |
require_once($path .'/API/hooks.inc'); |
require_once $path .'/API/hooks.inc'; |
| 20 |
require_once($path .'/API/media.inc'); |
require_once $path .'/API/media.inc'; |
| 21 |
require_once($path .'/API/file.inc'); |
require_once $path .'/API/file.inc'; |
| 22 |
require_once($path .'/API/folder.inc'); |
require_once $path .'/API/folder.inc'; |
| 23 |
require_once($path .'/API/form.inc'); |
require_once $path .'/API/form.inc'; |
| 24 |
|
|
| 25 |
/** |
/** |
| 26 |
* Implementation of hook_init(). |
* Implementation of hook_init(). |
| 62 |
return array( |
return array( |
| 63 |
'media_view' => array( |
'media_view' => array( |
| 64 |
'template' => 'media-view', |
'template' => 'media-view', |
| 65 |
'arguments' => array('display' => '', 'filename' => null, 'media' => null), |
'arguments' => array('display' => '', 'filename' => NULL, 'media' => NULL), |
| 66 |
), |
), |
| 67 |
); |
); |
| 68 |
} |
} |
| 85 |
$temp = file_directory_path() .'/'. variable_get('mmedia_dir_temp', 'temp'); |
$temp = file_directory_path() .'/'. variable_get('mmedia_dir_temp', 'temp'); |
| 86 |
|
|
| 87 |
// check that base directory exists |
// check that base directory exists |
| 88 |
if (!is_dir($base) && !mapi_directory_check($base, array('create' => true))) { |
if (!is_dir($base) && !mapi_directory_check($base, array('create' => TRUE))) { |
| 89 |
mapi_error('Unable to create directory %dir.', array('%dir' => $base)); |
mapi_error('Unable to create directory %dir.', array('%dir' => $base)); |
| 90 |
} |
} |
| 91 |
|
|
| 92 |
// check that the temporary directory exists |
// check that the temporary directory exists |
| 93 |
if (!is_dir($temp) && !mapi_directory_check($temp, array('create' => true))) { |
if (!is_dir($temp) && !mapi_directory_check($temp, array('create' => TRUE))) { |
| 94 |
mapi_error('Unable to create directory %dir.', array('%dir' => $temp)); |
mapi_error('Unable to create directory %dir.', array('%dir' => $temp)); |
| 95 |
} |
} |
| 96 |
|
|
| 97 |
$dirs = array('base' => $base, 'temp' => $temp); |
$dirs = array('base' => $base, 'temp' => $temp); |
| 98 |
|
|
| 99 |
// check the private directory |
// check the private directory |
| 100 |
if (variable_get('mmedia_private', false)) { |
if (variable_get('mmedia_private', FALSE)) { |
| 101 |
$private = variable_get('mmedia_dir_private', '../media'); |
$private = variable_get('mmedia_dir_private', '../media'); |
| 102 |
if (!is_dir($private) && !is_writeable($private)) { |
if (!is_dir($private) && !is_writeable($private)) { |
| 103 |
mapi_error('Unable to locate a writeable directory %dir.', array('%dir' => $private)); |
mapi_error('Unable to locate a writeable directory %dir.', array('%dir' => $private)); |
| 197 |
// load the entire sequence of folders for the parent |
// load the entire sequence of folders for the parent |
| 198 |
$list = array( |
$list = array( |
| 199 |
l(t('Home'), NULL), |
l(t('Home'), NULL), |
| 200 |
l(t('Folders'), MMEDIA_FOLDER_PATH), |
l(t('Folders'), FOLDER_PATH), |
| 201 |
); |
); |
| 202 |
|
|
| 203 |
$parents = array_filter(explode('/', $parent->lineage)); |
$parents = array_filter(explode('/', $parent->lineage)); |
| 204 |
$paths = array_filter(explode('/', $parent->path)); |
$paths = array_filter(explode('/', $parent->path)); |
| 205 |
while ($fid = array_shift($parents)) { |
while ($fid = array_shift($parents)) { |
| 206 |
$name = array_shift($paths); |
$name = array_shift($paths); |
| 207 |
$list[] = l($name, MMEDIA_FOLDER_PATH .'/'. $fid); |
$list[] = l($name, FOLDER_PATH .'/'. $fid); |
| 208 |
} |
} |
| 209 |
if ($parent->fid) { |
if ($parent->fid) { |
| 210 |
$list[] = l($parent->name, MMEDIA_FOLDER_PATH .'/'. $parent->fid); |
$list[] = l($parent->name, FOLDER_PATH .'/'. $parent->fid); |
| 211 |
} |
} |
| 212 |
|
|
| 213 |
return $list; |
return $list; |
| 218 |
*/ |
*/ |
| 219 |
function _mmedia_access($media, $type) { |
function _mmedia_access($media, $type) { |
| 220 |
if (user_access('administer media')) { |
if (user_access('administer media')) { |
| 221 |
return true; |
return TRUE; |
| 222 |
} |
} |
| 223 |
|
|
| 224 |
global $user; |
global $user; |
| 229 |
break; |
break; |
| 230 |
case 'manage': |
case 'manage': |
| 231 |
if (user_access('manage own media') && $media->uid == $user->uid) { |
if (user_access('manage own media') && $media->uid == $user->uid) { |
| 232 |
return true; |
return TRUE; |
| 233 |
} |
} |
| 234 |
return user_access('manage media'); |
return user_access('manage media'); |
| 235 |
break; |
break; |
| 244 |
*/ |
*/ |
| 245 |
function _mmedia_folder_access($folder, $type) { |
function _mmedia_folder_access($folder, $type) { |
| 246 |
if (user_access('administer media')) { |
if (user_access('administer media')) { |
| 247 |
return true; |
return TRUE; |
| 248 |
} |
} |
| 249 |
|
|
| 250 |
global $user; |
global $user; |
| 255 |
break; |
break; |
| 256 |
case 'manage': |
case 'manage': |
| 257 |
if (user_access('manage own media folder') && $folder->uid == $user->uid) { |
if (user_access('manage own media folder') && $folder->uid == $user->uid) { |
| 258 |
return true; |
return TRUE; |
| 259 |
} |
} |
| 260 |
return user_access('manage media folder'); |
return user_access('manage media folder'); |
| 261 |
break; |
break; |