Révision dd54aff9
Ajouté par Assos Assos il y a plus de 10 ans
htmltest/sites/all/modules/entity/modules/callbacks.inc | ||
---|---|---|
23 | 23 |
if (!isset($node->book['bid'])) { |
24 | 24 |
throw new EntityMetadataWrapperException('This node is no book page.'); |
25 | 25 |
} |
26 |
return $node->book['bid']; |
|
26 |
switch ($name) { |
|
27 |
case 'book': |
|
28 |
return $node->book['bid']; |
|
29 |
|
|
30 |
case 'book_ancestors': |
|
31 |
$ancestors = array(); |
|
32 |
while (!empty($node->book['plid'])) { |
|
33 |
$link = book_link_load($node->book['plid']); |
|
34 |
array_unshift($ancestors, $link['nid']); |
|
35 |
$node = node_load($link['nid']); |
|
36 |
} |
|
37 |
return $ancestors; |
|
38 |
} |
|
27 | 39 |
} |
28 | 40 |
|
29 | 41 |
/** |
... | ... | |
125 | 137 |
|
126 | 138 |
case 'edit_url': |
127 | 139 |
return url('node/' . $node->nid . '/edit', $options); |
140 |
|
|
141 |
case 'author': |
|
142 |
return !empty($node->uid) ? $node->uid : drupal_anonymous_user(); |
|
128 | 143 |
} |
129 | 144 |
} |
130 | 145 |
|
... | ... | |
191 | 206 |
} |
192 | 207 |
} |
193 | 208 |
|
209 |
/** |
|
210 |
* Access callback for restricted node statistics properties. |
|
211 |
*/ |
|
212 |
function entity_metadata_statistics_properties_access($op, $property, $entity = NULL, $account = NULL) { |
|
213 |
if ($property == 'views' && user_access('view post access counter', $account)) { |
|
214 |
return TRUE; |
|
215 |
} |
|
216 |
return user_access('access statistics', $account); |
|
217 |
} |
|
218 |
|
|
194 | 219 |
/** |
195 | 220 |
* Callback for getting site-wide properties. |
196 | 221 |
* @see entity_metadata_system_entity_info_alter() |
... | ... | |
612 | 637 |
* |
613 | 638 |
* This function does not implement hook_node_access(), thus it may not be |
614 | 639 |
* called entity_metadata_node_access(). |
640 |
* |
|
641 |
* @see entity_access() |
|
642 |
* |
|
643 |
* @param $op |
|
644 |
* The operation being performed. One of 'view', 'update', 'create' or |
|
645 |
* 'delete'. |
|
646 |
* @param $node |
|
647 |
* A node to check access for. Must be a node object. Must have nid, |
|
648 |
* except in the case of 'create' operations. |
|
649 |
* @param $account |
|
650 |
* The user to check for. Leave it to NULL to check for the global user. |
|
651 |
* |
|
652 |
* @throws EntityMalformedException |
|
653 |
* |
|
654 |
* @return boolean |
|
655 |
* TRUE if access is allowed, FALSE otherwise. |
|
615 | 656 |
*/ |
616 | 657 |
function entity_metadata_no_hook_node_access($op, $node = NULL, $account = NULL) { |
658 |
// First deal with the case where a $node is provided. |
|
617 | 659 |
if (isset($node)) { |
660 |
if ($op == 'create') { |
|
661 |
if (isset($node->type)) { |
|
662 |
return node_access($op, $node->type, $account); |
|
663 |
} |
|
664 |
else { |
|
665 |
throw new EntityMalformedException('Permission to create a node was requested but no node type was given.'); |
|
666 |
} |
|
667 |
} |
|
618 | 668 |
// If a non-default revision is given, incorporate revision access. |
619 | 669 |
$default_revision = node_load($node->nid); |
620 |
if ($node->vid != $default_revision->vid) { |
|
621 |
return _node_revision_access($node, $op); |
|
670 |
if ($node->vid !== $default_revision->vid) {
|
|
671 |
return _node_revision_access($node, $op, $account);
|
|
622 | 672 |
} |
623 | 673 |
else { |
624 | 674 |
return node_access($op, $node, $account); |
625 | 675 |
} |
626 | 676 |
} |
627 |
// Is access to all nodes allowed? |
|
677 |
// No node is provided. Check for access to all nodes. |
|
678 |
if (user_access('bypass node access', $account)) { |
|
679 |
return TRUE; |
|
680 |
} |
|
628 | 681 |
if (!user_access('access content', $account)) { |
629 | 682 |
return FALSE; |
630 | 683 |
} |
631 |
if (user_access('bypass node access', $account) || (!isset($account) && $op == 'view' && node_access_view_all_nodes())) {
|
|
684 |
if ($op == 'view' && node_access_view_all_nodes($account)) {
|
|
632 | 685 |
return TRUE; |
633 | 686 |
} |
634 | 687 |
return FALSE; |
... | ... | |
690 | 743 |
return FALSE; |
691 | 744 |
} |
692 | 745 |
} |
746 |
|
|
747 |
// Comment administrators are allowed to perform all operations on all |
|
748 |
// comments. |
|
749 |
if (user_access('administer comments', $account)) { |
|
750 |
return TRUE; |
|
751 |
} |
|
752 |
|
|
753 |
// Unpublished comments can never be accessed by non-admins. |
|
754 |
if (isset($entity->status) && $entity->status == COMMENT_NOT_PUBLISHED) { |
|
755 |
return FALSE; |
|
756 |
} |
|
757 |
|
|
693 | 758 |
if (isset($entity) && $op == 'update') { |
694 | 759 |
// Because 'comment_access' only checks the current user, we need to do our |
695 | 760 |
// own access checking if an account was specified. |
... | ... | |
697 | 762 |
return comment_access('edit', $entity); |
698 | 763 |
} |
699 | 764 |
else { |
700 |
return ($account->uid && $account->uid == $entity->uid && $entity->status == COMMENT_PUBLISHED && user_access('edit own comments', $account)) || user_access('administer comments', $account);
|
|
765 |
return $account->uid && $account->uid == $entity->uid && user_access('edit own comments', $account);
|
|
701 | 766 |
} |
702 | 767 |
} |
703 |
if (user_access('administer comments', $account) || user_access('access comments', $account) && $op == 'view') {
|
|
768 |
if (user_access('access comments', $account) && $op == 'view') { |
|
704 | 769 |
return TRUE; |
705 | 770 |
} |
706 | 771 |
return FALSE; |
707 | 772 |
} |
708 | 773 |
|
774 |
/** |
|
775 |
* Access callback for restricted comment properties. |
|
776 |
*/ |
|
777 |
function entity_metadata_comment_properties_access($op, $property, $entity = NULL, $account = NULL) { |
|
778 |
return user_access('administer comments', $account); |
|
779 |
} |
|
780 |
|
|
709 | 781 |
/** |
710 | 782 |
* Access callback for the taxonomy entities. |
711 | 783 |
*/ |
... | ... | |
912 | 984 |
/** |
913 | 985 |
* Callback to get the form of a vocabulary. |
914 | 986 |
*/ |
915 |
function entity_metadata_form_taxonomy_vocabulary($term) {
|
|
987 |
function entity_metadata_form_taxonomy_vocabulary($vocab) {
|
|
916 | 988 |
// Pre-populate the form-state with the right form include. |
917 |
$form_state['build_info']['args'] = array($term);
|
|
989 |
$form_state['build_info']['args'] = array($vocab);
|
|
918 | 990 |
form_load_include($form_state, 'inc', 'taxonomy', 'taxonomy.admin'); |
919 |
return drupal_build_form('taxonomy_form_term', $form_state);
|
|
991 |
return drupal_build_form('taxonomy_form_vocabulary', $form_state);
|
|
920 | 992 |
} |
921 | 993 |
|
922 | 994 |
/** |
... | ... | |
972 | 1044 |
$result = $query->execute(); |
973 | 1045 |
return !empty($result[$entity_type]) ? array_keys($result[$entity_type]) : array(); |
974 | 1046 |
} |
1047 |
|
|
1048 |
/** |
|
1049 |
* Implements entity_uri() callback for file entities. |
|
1050 |
*/ |
|
1051 |
function entity_metadata_uri_file($file) { |
|
1052 |
return array( |
|
1053 |
'path' => file_create_url($file->uri), |
|
1054 |
); |
|
1055 |
} |
Formats disponibles : Unified diff
Weekly update of contrib modules