Advertisement
christopherreay

Fix for "Cannot create type" for og_content_type_admin

May 6th, 2011
195
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 5.04 KB | None | 0 0
  1. // THIS is the ORIGINAL og_content_type_admin_menu_access function in og_content_type_admin.module:
  2. /** The necessary changes to fix the problem are lines 80-93 of this paste to replace lines 801 - 809 of the original file. There are instructions and an explanation further down
  3. *//
  4.  
  5. /**
  6.  * mnode/add access callback override. If gid is present check og_content_type access rights. Otherwise pass processing to original function
  7.  */
  8. function og_content_type_admin_menu_access() {
  9.   $args = func_get_args();
  10.   $type = array_shift($args);
  11.   $type = isset($type) ? str_replace('-', '_', $type) : NULL;
  12.   $original_callback = array_shift($args);
  13.   // First: Allow access to add a particlar type of group content
  14.   if (is_array($_GET['gids'])) {  
  15.     $gid = $_GET['gids'][0];
  16.     dsm_once("get[gids]", $_GET['gids'][0]);
  17.     $group = node_load($gid);
  18.     $sql = "SELECT octa.types_active, octa.types_allowed FROM {og_content_type_admin} octa WHERE octa.gid = %d";
  19.     //if we're keeping track of this group, get it's active types, otherwise, get the defaults
  20.     $types = db_fetch_object(db_query($sql, $gid));
  21.     if (!$types) {  
  22.       $types = db_fetch_object(db_query($sql, 0));
  23.     }
  24.     if (_og_content_type_admin_is_admin($group)) {
  25.       $active_types = unserialize($types->types_allowed);
  26.     } else {
  27.       $active_types = unserialize($types->types_active);
  28.     }
  29.     if ($active_types[$type]) {
  30.       return TRUE;
  31.     }  
  32.   }
  33.   else { // do normal processing plus 'allowed' check
  34.     $sql = "SELECT octa.types_allowed FROM {og_content_type_admin} octa WHERE octa.gid = -1";  
  35.     $types = db_fetch_object(db_query($sql));
  36.     $allowed_types = unserialize($types->types_allowed);    
  37.     if ($allowed_types[$type] && call_user_func_array($original_callback, $args)) {  
  38.       return TRUE;
  39.     }  
  40.   }
  41.   return FALSE;
  42. }
  43.  
  44.  
  45.  
  46. /** ************************  INSTRUCTIONS  *************************/
  47. /**We need to replace the last "else" block (lines 33-40)with something that does not check the og_content_type_admin table (sql statement 34). This is ok because og content type admin is not supposed to, and has no mechanism for, enforcing restrictions on ALLOWED SITEWIDE. If you check the admin page for og cta, you will see that the list of types for "ALLOWED SITEWIDE" is checkboxes which are all set to true and have all been disabled. (In fact og CTA rather unnecessarily builds a list of allowed sitewide types on installation, which breaks as soon as new types are created). Line 37 (above) contains an if statement which checks the octa database for "allowed" state and also calls "call_user_func_array($original_callback, $args)", which octa has replaced the original drupal menu access functionatlity, but kept a reference to the old funcion ($original_callback). All that is really necessary is to call this $original_callback function and return the results. Post waffle, the new og_content_type_admin_menu_access() method should be:
  48.  
  49. (If you just paste this method over the top of the old one, it will work :) ChristopherReay http://drupal.org/node/876162 )
  50. */
  51.  
  52. /**
  53.  * mnode/add access callback override. If gid is present check og_content_type access rights. Otherwise pass processing to original function
  54.  */
  55. function og_content_type_admin_menu_access() {
  56.   $args = func_get_args();
  57.   $type = array_shift($args);
  58.   $type = isset($type) ? str_replace('-', '_', $type) : NULL;
  59.   $original_callback = array_shift($args);
  60.   // First: Allow access to add a particlar type of group content
  61.   if (is_array($_GET['gids'])) {  
  62.     $gid = $_GET['gids'][0];
  63.     dsm_once("get[gids]", $_GET['gids'][0]);
  64.     $group = node_load($gid);
  65.     $sql = "SELECT octa.types_active, octa.types_allowed FROM {og_content_type_admin} octa WHERE octa.gid = %d";
  66.     //if we're keeping track of this group, get it's active types, otherwise, get the defaults
  67.     $types = db_fetch_object(db_query($sql, $gid));
  68.     if (!$types) {  
  69.       $types = db_fetch_object(db_query($sql, 0));
  70.     }
  71.     if (_og_content_type_admin_is_admin($group)) {
  72.       $active_types = unserialize($types->types_allowed);
  73.     } else {
  74.       $active_types = unserialize($types->types_active);
  75.     }
  76.     if ($active_types[$type]) {
  77.       return TRUE;
  78.     }  
  79.   }
  80.   else { // do normal processing plus 'allowed' check
  81.     // here '+' denotes lines added by ChristopherReay and '-' suggested removeals
  82.     //+ CR: here "normal processing" means the standard Drupal stuff before the octa
  83.     //+ CR:  module was installed.
  84.     //+ CR:  Actually, octa doesnt enforce any limits on "ALLOWED"
  85.     //+ CR:  types for "octa.gid = -1", which is the GroupID for "sitewide" (check sql in next line)
  86.     // - $sql = "SELECT octa.types_allowed FROM {og_content_type_admin} octa WHERE octa.gid = -1";  
  87.     // - $types = db_fetch_object(db_query($sql));
  88.     // - $allowed_types = unserialize($types->types_allowed);    
  89.     // - if ($allowed_types[$type] && call_user_func_array($original_callback, $args)) {  
  90.     // - return TRUE;
  91.     // - }  
  92.     return call_user_func_array($original_callback, $args);
  93.   }
  94.   return FALSE;
  95. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement