Advertisement
Pr4w

permissionsConverter

Aug 25th, 2011
261
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.34 KB | None | 0 0
  1. <?php
  2. /*
  3.  @Filename : permissionsConverter.php
  4.  @Description : Tool to convert a permission file to a different type
  5.  Will support P2, P3 and PermissionsBukkit
  6.  @Dependencies : Spyc.php
  7.  @Author : Pr4w
  8.  @Special thanks to all the cool guys at bukkit.org
  9.  
  10.  @Usage : convertP2toP3("world.yml", "users.yml", "groups.yml");
  11.  Have fun :)
  12. */
  13. require('spyc.php');
  14.  
  15. function convertP2toP3($file, $userfile, $groupfile) {
  16.  
  17.     // Get the Yaml file
  18.     $yaml = Spyc::YAMLLoad(@file_get_contents($file));
  19.    
  20.     // Fix users array
  21.     $users = array ('users' => $yaml['users']);
  22.    
  23.     // Fix groups array
  24.     $groups = array ('groups' => $yaml['groups']);
  25.    
  26.     // Dump the YAML of both users and groups
  27.     $users = Spyc::YAMLDump($users, 4);
  28.     $groups = Spyc::YAMLDump($groups, 4);
  29.    
  30.     // Perform transformation to Permission 3 format
  31.     $users = str_replace("group:", "groups:
  32.        -", $users);
  33.    
  34.     // Write users to a file
  35.     $write = fopen($userfile, "w")
  36.         or die ( "Could not open file !" );
  37.     $write = fwrite($write, $users)
  38.         or die ( "Could not write to file !" );
  39.        
  40.     // Write groups to a file
  41.     $write = fopen($groupfile, "w")
  42.         or die ( "Could not open file !");
  43.     $write = fwrite($write, $groups)
  44.         or die ( "Could not write to file !" );
  45.        
  46.    
  47.    
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement