publishcontent.api.php 3.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. <?php
  2. /**
  3. * @file
  4. * Describe hooks provided by the publishcontent module.
  5. */
  6. /**
  7. * Allow other modules the ability to modify access to the publish controls.
  8. *
  9. * Modules may implement this hook if they want to have a say in whether or not
  10. * a given user has access to perform publish action on a node.
  11. *
  12. * @param node $node
  13. * A node object being checked
  14. * @param user $account
  15. * The user wanting to publish the node.
  16. *
  17. * @return bool|NULL
  18. * PUBLISHCONTENT_ACCESS_ALLOW - if the account can publish the node
  19. * PUBLISHCONTENT_ACCESS_DENY - if the user definetley can not publish
  20. * PUBLISHCONTENT_ACCESS_IGNORE - This module wan't change the outcome.
  21. * It is typically better to return IGNORE than DENY. If no module returns
  22. * ALLOW then the account will be denied publish access. If one module
  23. * returns DENY then the user will denied even if another module returns
  24. * ALLOW.
  25. */
  26. function hook_publishcontent_publish_access($node, $account) {
  27. $access = !$node->status &&
  28. (user_access('administer nodes')
  29. || user_access('publish any content')
  30. || (user_access('publish own content') && $account->uid == $node->uid)
  31. || (user_access('publish editable content') && node_access('update', $node))
  32. || (user_access('publish own ' . check_plain($node->type) . ' content', $account) && $account->uid == $node->uid)
  33. || user_access('publish any ' . check_plain($node->type) . ' content')
  34. || (user_access('publish editable ' . check_plain($node->type) . ' content') && node_access('update', $node))
  35. );
  36. if ($access) {
  37. // The user can publish the node according to this hook.
  38. // If another hook denys access they will be denied.
  39. return PUBLISHCONTENT_ACCESS_ALLOW;
  40. }
  41. // This function does not believe they can publish but is
  42. // not explicitly denying access to publish. If no other hooks
  43. // allow it then the user will be denied.
  44. return PUBLISHCONTENT_ACCESS_IGNORE;
  45. }
  46. /**
  47. * Allow other modules the ability to modify access to the unpublish controls.
  48. *
  49. * Modules may implement this hook if they want to have a say in whether or not
  50. * a given user has access to perform unpublish action on a node.
  51. *
  52. * @param node $node
  53. * A node object being checked
  54. * @param user $account
  55. * The user wanting to unpublish the node.
  56. *
  57. * @return bool|NULL
  58. * PUBLISHCONTENT_ACCESS_ALLOW - if the user can unpublish the node.
  59. * PUBLISHCONTENT_ACCESS_DENY - if the user definetley cannot unpublish.
  60. * PUBLISHCONTENT_ACCESS_IGNORE - This module wan't change the outcome.
  61. * It is typically better to return IGNORE than DENY. If no module returns
  62. * ALLOW then the user will be denied access. If one module returns
  63. * DENY then the user will denied even if another module returns
  64. * ALLOW.
  65. */
  66. function hook_publishcontent_unpublish_access($node, $account) {
  67. $access = $node->status &&
  68. (user_access('administer nodes')
  69. || user_access('unpublish any content')
  70. || (user_access('unpublish own content') && $user->uid == $node->uid)
  71. || (user_access('unpublish editable content') && node_access('update', $node))
  72. || (user_access('unpublish own ' . check_plain($node->type) . ' content', $user) && $user->uid == $node->uid)
  73. || user_access('unpublish any ' . check_plain($node->type) . ' content')
  74. || (user_access('unpublish editable ' . check_plain($node->type) . ' content') && node_access('update', $node))
  75. );
  76. if ($access) {
  77. // The user is allowed to unpublish the node according to this hook.
  78. // If another hook denys access they will be denied.
  79. return PUBLISHCONTENT_ACCESS_ALLOW;
  80. }
  81. // This function does not believe they can publish but is
  82. // not explicitly denying access to publish. If no other hooks
  83. // allow it then the user will be denied.
  84. return PUBLISHCONTENT_ACCESS_IGNORE;
  85. }