Changeset 1063263
- Timestamp:
- 01/08/2015 05:16:47 PM (11 years ago)
- Location:
- enzymes/trunk/src
- Files:
-
- 1 added
- 2 edited
-
Enzymes3.php (modified) (8 diffs)
-
EnzymesCapabilities.php (added)
-
EnzymesPlugin.php (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
enzymes/trunk/src/Enzymes3.php
r1063182 r1063263 2 2 require_once dirname(ENZYMES_FILENAME) . '/vendor/Ando/Regex.php'; 3 3 require_once 'EnzymesSequence.php'; 4 require_once 'EnzymesCapabilities.php'; 5 require_once 'EnzymesOption.php'; 4 6 5 7 class Enzymes3 … … 7 9 const PREFIX = 'enzymes.'; 8 10 9 static public 10 function capabilities() 11 { 12 //@Formatter:off 13 $result = array( 14 self::PREFIX . 'inject' => 'It allows a user to inject enzymes into her posts.', 15 self::PREFIX . 'use_own_attributes' => 'It allows a user to make her enzymes with her own attributes.', 16 self::PREFIX . 'use_others_attributes' => 'It allows a user to make her enzymes with others\' attributes.', 17 self::PREFIX . 'use_own_custom_fields' => 'It allows a user to make her enzymes with her own custom fields.', 18 self::PREFIX . 'use_others_custom_fields' => 'It allows a user to make her enzymes with others\' custom fields.', 19 self::PREFIX . 'create_static_custom_fields' => 'It allows a user to create enzymes from non-evaluated custom fields.', 20 self::PREFIX . 'create_dynamic_custom_fields' => 'It allows a user to create enzymes from evaluated custom fields.', 21 self::PREFIX . 'share_static_custom_fields' => 'It allows a user to share her enzymes from non-evaluated custom fields.', 22 self::PREFIX . 'share_dynamic_custom_fields' => 'It allows a user to share her enzymes from evaluated custom fields.', 23 ); 24 //@Formatter:on 25 return $result; 26 } 11 /** 12 * @var EnzymesOption 13 */ 14 protected $options; 27 15 28 16 /** … … 291 279 $this->init_grammar(); 292 280 $this->init_expressions(); 281 $this->options = new EnzymesOption(self::PREFIX); 293 282 } 294 283 … … 517 506 function execute_code( $code, $arguments, $post_object ) 518 507 { 519 if ( author_can($post_object, self::PREFIX . 'create_dynamic_custom_fields') &&508 if ( author_can($post_object, EnzymesCapabilities::create_dynamic_custom_fields) && 520 509 ($this->belongs_to_current_author($post_object) || 521 author_can($post_object, self::PREFIX . 'share_dynamic_custom_fields') &&522 author_can($this->current_post, self::PREFIX . 'use_others_custom_fields'))510 author_can($post_object, EnzymesCapabilities::share_dynamic_custom_fields) && 511 author_can($this->current_post, EnzymesCapabilities::use_others_custom_fields)) 523 512 ) { 524 513 list($result,) = $this->safe_eval($code, $arguments); … … 635 624 function transclude_code( $code, $post_object ) 636 625 { 637 if ( author_can($post_object, self::PREFIX . 'create_dynamic_custom_fields') &&626 if ( author_can($post_object, EnzymesCapabilities::create_dynamic_custom_fields) && 638 627 ($this->belongs_to_current_author($post_object) || 639 author_can($post_object, self::PREFIX . 'share_dynamic_custom_fields') &&640 author_can($this->current_post, self::PREFIX . 'use_others_custom_fields'))628 author_can($post_object, EnzymesCapabilities::share_dynamic_custom_fields) && 629 author_can($this->current_post, EnzymesCapabilities::use_others_custom_fields)) 641 630 ) { 642 631 list(, $output) = $this->safe_eval(" ?>$code<?php "); 643 } elseif ( author_can($post_object, self::PREFIX . 'create_static_custom_fields') &&632 } elseif ( author_can($post_object, EnzymesCapabilities::create_static_custom_fields) && 644 633 ($this->belongs_to_current_author($post_object) || 645 author_can($post_object, self::PREFIX . 'share_static_custom_fields') &&646 author_can($this->current_post, self::PREFIX . 'use_others_custom_fields'))634 author_can($post_object, EnzymesCapabilities::share_static_custom_fields) && 635 author_can($this->current_post, EnzymesCapabilities::use_others_custom_fields)) 647 636 ) { 648 637 $output = $code; … … 710 699 $this->debug_print('transcluding post_attr'); 711 700 $same_author = $this->belongs_to_current_author($post_object); 712 if ( $same_author && author_can($post_object, self::PREFIX . 'use_own_attributes') ||713 ! $same_author && author_can($this->current_post, self::PREFIX . 'use_others_attributes')701 if ( $same_author && author_can($post_object, EnzymesCapabilities::use_own_attributes) || 702 ! $same_author && author_can($this->current_post, EnzymesCapabilities::use_others_attributes) 714 703 ) { 715 704 $expression = $this->grammar['post_attr']->wrapper_set('@@') … … 737 726 $this->debug_print('transcluding author_attr'); 738 727 $same_author = $this->belongs_to_current_author($post_object); 739 if ( $same_author && author_can($post_object, self::PREFIX . 'use_own_attributes') ||740 ! $same_author && author_can($this->current_post, self::PREFIX . 'use_others_attributes')728 if ( $same_author && author_can($post_object, EnzymesCapabilities::use_own_attributes) || 729 ! $same_author && author_can($this->current_post, EnzymesCapabilities::use_others_attributes) 741 730 ) { 742 731 $expression = $this->grammar['author_attr']->wrapper_set('@@') … … 917 906 return $content; 918 907 } 919 if ( ! author_can($this->current_post, self::PREFIX . 'inject') ) {908 if ( ! author_can($this->current_post, EnzymesCapabilities::inject) ) { 920 909 return $content; 921 910 } -
enzymes/trunk/src/EnzymesPlugin.php
r1063182 r1063263 53 53 function on_activation() 54 54 { 55 self::add_plugin_options(); 55 56 self::add_roles_and_capabilities(); 56 57 return true; … … 82 83 //------------------------------------------------------------------------------------------------------------------ 83 84 85 86 static protected 87 function save_activation_time() 88 { 89 // self::engine() 90 } 91 92 static protected 93 function delete_activation_time() 94 { 95 96 } 97 84 98 static protected 85 99 function add_roles_and_capabilities() 86 100 { 87 $caps = array_keys(Enzymes3::capabilities()); 88 $no_role_capabilities = array_fill_keys($caps, false); 101 self::remove_roles_and_capabilities(); 89 102 //@formatter:off 90 remove_role(Enzymes3::PREFIX . 'User'); 91 $user_role = add_role( 92 Enzymes3::PREFIX . 'User', __('Enzymes User'), array_merge($no_role_capabilities, array( 93 Enzymes3::PREFIX . 'inject' => true, 94 Enzymes3::PREFIX . 'use_own_attributes' => true, 95 Enzymes3::PREFIX . 'use_own_custom_fields' => true, 96 Enzymes3::PREFIX . 'create_static_custom_fields' => true, 97 ))); 98 99 remove_role(Enzymes3::PREFIX . 'PrivilegedUser'); 100 $privileged_user_role = add_role( 101 Enzymes3::PREFIX . 'PrivilegedUser', __('Enzymes Privileged User'), array_merge($user_role->capabilities, array( 102 Enzymes3::PREFIX . 'use_others_custom_fields' => true, 103 ))); 104 105 remove_role(Enzymes3::PREFIX . 'TrustedUser'); 106 $trusted_user_role = add_role( 107 Enzymes3::PREFIX . 'TrustedUser', __('Enzymes Trusted User'), array_merge($privileged_user_role->capabilities, array( 108 Enzymes3::PREFIX . 'share_static_custom_fields' => true, 109 ))); 110 111 remove_role(Enzymes3::PREFIX . 'Coder'); 112 $coder_role = add_role( 113 Enzymes3::PREFIX . 'Coder', __('Enzymes Coder'), array_merge($trusted_user_role->capabilities, array( 114 Enzymes3::PREFIX . 'create_dynamic_custom_fields' => true, 115 ))); 116 117 remove_role(Enzymes3::PREFIX . 'TrustedCoder'); 118 $trusted_coder_role = add_role( 119 Enzymes3::PREFIX . 'TrustedCoder', __('Enzymes Trusted Coder'), array_merge($coder_role->capabilities, array( 120 Enzymes3::PREFIX . 'share_dynamic_custom_fields' => true, 121 ))); 103 add_role(EnzymesCapabilities::User, __('Enzymes User'), EnzymesCapabilities::for_User() ); 104 add_role(EnzymesCapabilities::PrivilegedUser, __('Enzymes Privileged User'), EnzymesCapabilities::for_PrivilegedUser() ); 105 add_role(EnzymesCapabilities::TrustedUser, __('Enzymes Trusted User'), EnzymesCapabilities::for_TrustedUser() ); 106 add_role(EnzymesCapabilities::Coder, __('Enzymes Coder'), EnzymesCapabilities::for_Coder() ); 107 add_role(EnzymesCapabilities::TrustedCoder, __('Enzymes Trusted Coder'), EnzymesCapabilities::for_TrustedCoder() ); 122 108 //@formatter:on 123 109 124 110 global $wp_roles; 125 111 /* @var $wp_roles WP_Roles */ 126 foreach ($caps as $cap) { 112 113 foreach (EnzymesCapabilities::all() as $cap) { 127 114 $wp_roles->add_cap('administrator', $cap); 128 115 } 129 116 } 130 117 118 /** 119 * Remove roles and capabilities by prefix. 120 */ 131 121 static protected 132 122 function remove_roles_and_capabilities() … … 141 131 } 142 132 143 $caps = array_keys(Enzymes3::capabilities()); 144 foreach ($caps as $cap) { 145 $wp_roles->remove_cap('administrator', $cap); 133 foreach (EnzymesCapabilities::all() as $cap) { 134 if ( 0 === strpos($cap, Enzymes3::PREFIX) ) { 135 $wp_roles->remove_cap('administrator', $cap); 136 } 146 137 } 147 138 }
Note: See TracChangeset
for help on using the changeset viewer.