| 1 |
<?php |
<?php |
| 2 |
// $Id: mmedia_nodes.module,v 1.3 2008/12/16 15:11:47 rhys Exp $ |
// $Id: mmedia_nodes.module,v 1.4 2009/01/27 18:45:56 rhys Exp $ |
| 3 |
|
|
| 4 |
require_once(drupal_get_path('module', 'mmedia_nodes') .'/api.inc'); |
require_once(drupal_get_path('module', 'mmedia_nodes') .'/api.inc'); |
| 5 |
|
|
| 23 |
} |
} |
| 24 |
|
|
| 25 |
/** |
/** |
| 26 |
|
* Implementation of hook_perm(). |
| 27 |
|
*/ |
| 28 |
|
function mmedia_nodes_perm() { |
| 29 |
|
$perms = array(); |
| 30 |
|
|
| 31 |
|
foreach (mapi_type_list() as $type) { |
| 32 |
|
$perms[] = 'access media_'. $type; |
| 33 |
|
$perms[] = 'create media_'. $type; |
| 34 |
|
$perms[] = 'edit any media_'. $type; |
| 35 |
|
$perms[] = 'edit own media_'. $type; |
| 36 |
|
$perms[] = 'delete any media_'. $type; |
| 37 |
|
$perms[] = 'delete own media_'. $type; |
| 38 |
|
} |
| 39 |
|
|
| 40 |
|
return $perms; |
| 41 |
|
} |
| 42 |
|
|
| 43 |
|
/** |
| 44 |
|
* Implementation of hook_access(). |
| 45 |
|
*/ |
| 46 |
|
function mmedia_nodes_access($op, $node, $account) { |
| 47 |
|
// node must be a valid type for this to handle it |
| 48 |
|
$type = is_object($node) ? $node->type : $node; |
| 49 |
|
if (!in_array(substr($type, 6), mapi_type_list())) { |
| 50 |
|
return FALSE; |
| 51 |
|
} |
| 52 |
|
|
| 53 |
|
switch ($op) { |
| 54 |
|
case 'create': |
| 55 |
|
return user_access('create '. $type, $account); |
| 56 |
|
case 'update': |
| 57 |
|
return user_access('edit any '. $type, $account) || (user_access('edit own '. $type, $account) && ($account->uid == $node->uid)); |
| 58 |
|
case 'delete': |
| 59 |
|
return user_access('delete any '. $type, $account) || (user_access('delete own '. $type, $account) && ($account->uid == $node->uid)); |
| 60 |
|
case 'view': |
| 61 |
|
return user_access('access '. $type, $account); |
| 62 |
|
} |
| 63 |
|
return FALSE; |
| 64 |
|
} |
| 65 |
|
|
| 66 |
|
/** |
| 67 |
* Implementation of hook_nodeapi(). |
* Implementation of hook_nodeapi(). |
| 68 |
*/ |
*/ |
| 69 |
function mmedia_nodes_nodeapi(&$node, $op, $teaser = NULL, $page = NULL) { |
function mmedia_nodes_nodeapi(&$node, $op, $teaser = NULL, $page = NULL) { |