/products/photocrati_nextgen/modules/ngglegacy/admin/roles.php

  1. <?php 
  2.  
  3. if(preg_match('#' . basename(__FILE__) . '#', $_SERVER['PHP_SELF'])) { die('You are not allowed to call this page directly.'); } 
  4.  
  5. function nggallery_admin_roles() { 
  6.  
  7. if ( !empty($_POST) ) { 
  8.  
  9. check_admin_referer('ngg_addroles'); 
  10.  
  11. // now set or remove the capability 
  12. ngg_set_capability($_POST['general'], "NextGEN Gallery overview"); 
  13. ngg_set_capability($_POST['tinymce'], "NextGEN Use TinyMCE"); 
  14. ngg_set_capability($_POST['add_gallery'], "NextGEN Upload images"); 
  15. ngg_set_capability($_POST['manage_gallery'], "NextGEN Manage gallery"); 
  16. ngg_set_capability($_POST['manage_others'], "NextGEN Manage others gallery"); 
  17. ngg_set_capability($_POST['manage_tags'], "NextGEN Manage tags"); 
  18. ngg_set_capability($_POST['edit_album'], "NextGEN Edit album"); 
  19. ngg_set_capability($_POST['change_style'], "NextGEN Change style"); 
  20. ngg_set_capability($_POST['change_options'], "NextGEN Change options"); 
  21. ngg_set_capability($_POST['attach_interface'], "NextGEN Attach Interface"); 
  22.  
  23. ?> 
  24. <div class="wrap"> 
  25. <p> 
  26. <?php _e('Select the lowest role which should be able to access the following capabilities. NextGEN Gallery supports the standard roles from WordPress.', 'nggallery') ?> <br /> 
  27. </p> 
  28. <?php wp_nonce_field('ngg_addroles') ?> 
  29. <table class="form-table"> 
  30. <tr valign="top"> 
  31. <th scope="row"><?php _e('Main NextGEN Gallery overview', 'nggallery') ;?>:</th> 
  32. <td><label for="general"><select name="general" id="general"><?php wp_dropdown_roles( ngg_get_role('NextGEN Gallery overview') ); ?></select></label></td> 
  33. </tr> 
  34. <tr valign="top"> 
  35. <th scope="row"><?php _e('Use TinyMCE Button / Upload tab', 'nggallery') ;?>:</th> 
  36. <td><label for="tinymce"><select name="tinymce" id="tinymce"><?php wp_dropdown_roles( ngg_get_role('NextGEN Use TinyMCE') ); ?></select></label></td> 
  37. </tr> 
  38. <tr valign="top"> 
  39. <th scope="row"><?php _e('Add gallery / Upload images', 'nggallery') ;?>:</th> 
  40. <td><label for="add_gallery"><select name="add_gallery" id="add_gallery"><?php wp_dropdown_roles( ngg_get_role('NextGEN Upload images') ); ?></select></label></td> 
  41. </tr> 
  42. <tr valign="top"> 
  43. <th scope="row"><?php _e('Manage gallery', 'nggallery') ;?>:</th> 
  44. <td><label for="manage_gallery"><select name="manage_gallery" id="manage_gallery"><?php wp_dropdown_roles( ngg_get_role('NextGEN Manage gallery') ); ?></select></label></td> 
  45. </tr> 
  46. <tr valign="top"> 
  47. <th scope="row"><?php _e('Manage others gallery', 'nggallery') ;?>:</th> 
  48. <td><label for="manage_others"><select name="manage_others" id="manage_others"><?php wp_dropdown_roles( ngg_get_role('NextGEN Manage others gallery') ); ?></select></label></td> 
  49. </tr> 
  50. <tr valign="top"> 
  51. <th scope="row"><?php _e('Manage tags', 'nggallery') ;?>:</th> 
  52. <td><label for="manage_tags"><select name="manage_tags" id="manage_tags"><?php wp_dropdown_roles( ngg_get_role('NextGEN Manage tags') ); ?></select></label></td> 
  53. </tr> 
  54. <tr valign="top"> 
  55. <th scope="row"><?php _e('Edit Album', 'nggallery') ;?>:</th> 
  56. <td><label for="edit_album"><select name="edit_album" id="edit_album"><?php wp_dropdown_roles( ngg_get_role('NextGEN Edit album') ); ?></select></label></td> 
  57. </tr> 
  58. <tr valign="top"> 
  59. <th scope="row"><?php _e('Change style', 'nggallery') ;?>:</th> 
  60. <td><label for="change_style"><select name="change_style" id="change_style"><?php wp_dropdown_roles( ngg_get_role('NextGEN Change style') ); ?></select></label></td> 
  61. </tr> 
  62. <tr valign="top"> 
  63. <th scope="row"><?php _e('Change options', 'nggallery') ;?>:</th> 
  64. <td><label for="change_options"><select name="change_options" id="change_options"><?php wp_dropdown_roles( ngg_get_role('NextGEN Change options') ); ?></select></label></td> 
  65. </tr> 
  66. <tr valign="top"> 
  67. <th scope="row"><?php _e('NextGEN Attach Interface', 'nggallery') ;?>:</th> 
  68. <td><label for="attach_interface"><select name="attach_interface" id="attach_interface"><?php wp_dropdown_roles( ngg_get_role('NextGEN Attach Interface') ); ?></select></label></td> 
  69. </tr> 
  70. </table> 
  71. </div> 
  72. <?php 
  73.  
  74.  
  75. function ngg_get_sorted_roles() { 
  76. // This function returns all roles, sorted by user level (lowest to highest) 
  77. global $wp_roles; 
  78. $roles = $wp_roles->role_objects; 
  79. $sorted = array(); 
  80.  
  81. if( class_exists('RoleManager') ) { 
  82. foreach( $roles as $role_key => $role_name ) { 
  83. $role = get_role($role_key); 
  84. if( empty($role) ) continue; 
  85. $role_user_level = array_reduce(array_keys($role->capabilities), array('WP_User', 'level_reduction'), 0); 
  86. $sorted[$role_user_level] = $role; 
  87. $sorted = array_values($sorted); 
  88. } else { 
  89. $role_order = array("subscriber", "contributor", "author", "editor", "administrator"); 
  90. foreach($role_order as $role_key) { 
  91. $sorted[$role_key] = get_role($role_key); 
  92. return $sorted; 
  93.  
  94. function ngg_get_role($capability) { 
  95. // This function return the lowest roles which has the capabilities 
  96. $check_order = ngg_get_sorted_roles(); 
  97.  
  98. $args = array_slice(func_get_args(), 1); 
  99. $args = array_merge(array($capability), $args); 
  100.  
  101. foreach ($check_order as $check_role) { 
  102. if ( empty($check_role) ) 
  103. return false; 
  104.  
  105. if (call_user_func_array(array(&$check_role, 'has_cap'), $args)) 
  106. return $check_role->name; 
  107. return false; 
  108.  
  109. function ngg_set_capability($lowest_role, $capability) { 
  110. // This function set or remove the $capability 
  111. $check_order = ngg_get_sorted_roles(); 
  112.  
  113. $add_capability = false; 
  114.  
  115. foreach ($check_order as $the_role) { 
  116. $role = $the_role->name; 
  117.  
  118. if ( $lowest_role == $role ) 
  119. $add_capability = true; 
  120.  
  121. // If you rename the roles, then please use a role manager plugin 
  122.  
  123. if ( empty($the_role) ) 
  124. continue; 
  125.  
  126. $add_capability ? $the_role->add_cap($capability) : $the_role->remove_cap($capability) ; 
  127.  
  128. ?> 
.