We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 21841
    • 36 Posts
    This is an auto-generated support/comment thread for extMemberCheck.

    Use this forum to post any comments about this addition or any questions you have regarding its use.

    Brief Description:
    Extended version of MemberCheck. Checks a logged in user's group membership and displays a chunk. Can be used multiple times on a page
      • 11429
      • 90 Posts
      is this one different from the existing membercheck?
        • 7923
        • 4,213 Posts
        Yes, like the name and description says.


          "He can have a lollipop any time he wants to. That's what it means to be a programmer."
          • 24719
          • 194 Posts
          I’ve added support for including snippets. Just use the new ’snippets’ parameter in the same way as for ’chunk’, e.g.

          [!extMemberCheck? &groups=`staff` &snippets=`StaffSnippet` &debug=`true`!]
            • 28033
            • 925 Posts
            When I tried using this snippet, I got an error saying that the second datatype mismatched, or something to that degree, using this snippet call...

            [!extMemberCheck? &groups=`Registered Users, Administrators` &chunk=`regUser, adminUser`!]


            I know that both groups and chunks exist. The "normal" MemberCheck snippet works, but I was wanting to use this one this one.

            Anyway, here’s the error I get with extMC...

            « MODx Parse Error »MODx encountered the following error while attempting to parse the requested resource:
            « PHP Parse Error »
             
            PHP error debug
              Error: 	array_search(): Wrong datatype for second argument	 
              Error type/ Nr.: 	Warning - 2	 
              File: 	/hsphere/local/home/symphoni/symphonicheaven.com/manager/includes/document.parser.class.inc.php(769) : eval()'d code	 
              Line: 	117	 
             
            Parser timing
              MySQL: 	0.0095 s	(9 Requests)
              PHP: 	0.2004 s	 
              Total: 	0.2099 s
              My Snippets
              -> PopUpChunk v1.0
              • 19164
              • 1,215 Posts
              Use PHx insteed.
                DirectResize 0.9 beta. PHPThumb, sets of configurations, configuration, binded to specific path. No backward compatibility. | DirectResize 0.9. PHPThumb, наборы параметров, параметры, привязанные к определенным путям. Без обратной совместимости.

                Unfortunately, DirectResize project is closed. If you want to continue development, PM me for access to project page on Google Code. К сожалению, проект DirectResize закрыт. Если вы желаете продолжить разработки, обращайтесь через ПМ для получения доступа к репозиторию на Google Code.

                [PLUGIN] DirectResize - as Maxigallery but for single images :: Download :: [url=http://modxcms.com/forums/index.php/topic,21490]
                • 28033
                • 925 Posts
                Quote from: Metaller at Dec 14, 2007, 09:45 AM

                Use PHx insteed.

                Would I have to? A script that I uses clashes w/ PHx.
                  My Snippets
                  -> PopUpChunk v1.0
                  • 7231
                  • 4,205 Posts
                  Just an idea, could it be a problem with the spaces in the chunk and group names? Try `Registered_Users` instead and see if it gives the error.

                  Also it seems to have debug mode, turn it on and see if you get any useful info.

                  I am not sure if the correct syntax would be &debug=`true` or &debug=`1`
                    [font=Verdana]Shane Sponagle | [wiki] Snippet Call Anatomy | MODx Developer Blog | [nettuts] Working With a Content Management Framework: MODx

                    Something is happening here, but you don't know what it is.
                    Do you, Mr. Jones? - [bob dylan]
                    • 28033
                    • 925 Posts
                    Quote from: dev_cw at Dec 14, 2007, 02:25 PM

                    Just an idea, could it be a problem with the spaces in the chunk and group names? Try `Registered_Users` instead and see if it gives the error.

                    Also it seems to have debug mode, turn it on and see if you get any useful info.

                    I am not sure if the correct syntax would be &debug=`true` or &debug=`1`

                    I’ll try the space idea. I do know that adding the debug part did nothing to change that error...
                      My Snippets
                      -> PopUpChunk v1.0
                      • 12684
                      • 118 Posts
                      I have been trying to add the default variable from MemberCheck http://modxcms.com/forums/index.php?topic=5481

                      but I am having troubles with this one. Could some one please show me the way.

                      Here is what I have done

                      <?php
                      #::::::::::::::::::::::::::::::::::::::::
                      # Snippet name: extMemberCheck
                      # Short Desc: checks logged in groups and displays a chunk
                      # Version: 1.0
                      # Created By Richard Pugh from the MemberCheck 1.0 snippet
                      # MemberCheck Created By    Ryan Thrash (vertexworks.com)
                      #             Sanitized By  Jason Coward (opengeek.com)
                      #
                      # Date: February 5th, 2007
                      #
                      # Changelog:
                      # Feb 05, 07 -- initial release
                      #
                      #::::::::::::::::::::::::::::::::::::::::
                      # Description:
                      #   Checks to see if users belong to a certain group and
                      #   displays the specified chunk if they do. Performs
                      #   several sanity checks and allows multiple uses on a page.
                      #
                      #   Two modes of use are possible, if only one output chunk
                      #   is specified then this snippet functions as the original
                      #   MemberCheck returning the chunk if the user is in ANY
                      #   of the groups specified.
                      #
                      #   If several chunks are specified there must be a one to one
                      #   correspondence between groups and chunks, i.e. there must be
                      #   as many values specified in groups as in chunks. The snippet
                      #   then checks if the user is in the groups one by one and
                      #   outputs the corresponding chunk, i.e. if the user is part of
                      #   group2 then chunk2 will be output. If you have a hierarchy
                      #   of user groups please ensure that they are placed in
                      #   descending order of importance in the group array as the
                      #   first matching value found is always returned.
                      #
                      # Params:
                      #   &groups [array] (REQUIRED)
                      #       array of webuser group-names to check against
                      #
                      #   &chunk [array] (REQUIRED)
                      #       name of the chunk to use if passes the check
                      #
                      #   &ph [string] (optional)
                      #       name of the placeholder to set instead of directly returning chunk
                      #
                      #   &debug [boolean] (optional | false)
                      #       turn on debug mode for extra troubleshooting
                      #
                      # Example Usage:
                      #
                      #   [[extMemberCheck? &groups=`group1, group2` &chunk=`chunk1, chunk2` &ph=`putItHere` &debug=`true`]]
                      #
                      #   This would place the chunk 'chunk1' into a placeholder (called 'putItHere') if the user
                      #   is logged in as a webuser and is a member of the 'group1' group. If he is a member of the
                      #   'group2' group, then 'chunk2' will be returned.
                      #
                      #   If the chunk array contains only one value, then if the user is in either 'group1' OR 'group2'
                      #   then the value of 'chunk1' is returned ( as in the original MemberCheck ).
                      #
                      #   The optional debug parameter can be used to display informative error messages
                      #   when configuring this snippet for your site. For example, if the developer had
                      #   mistakenly typed 'groupX' for the first group, and none existed with debug mode on,
                      #   it would have returned the error message: The group 'groupX' could not be found....
                      #
                      #::::::::::::::::::::::::::::::::::::::::
                      
                      # debug parameter
                      $debug = isset ($debug) ? $debug : false;
                      
                      # check if inside manager
                      if ($m = $modx->insideManager()) {
                          return ''; # don't go any further when inside manager
                      }
                      
                      if (!isset ($groups)) {
                          return $debug ? '<p>Error: No Group(s) Specified</p>' : '';
                      }
                      
                      if (!isset ($chunk)) {
                          return $debug ? '<p>Error: No Chunk(s) Specified</p>' : '';
                      }
                      
                      # check if default is set, if not sets value
                      $default = (isset($default))? $default : '';
                      
                      # turn comma-delimited list of groups into an array
                      $groups = explode(',', $groups);
                      $chunk = explode(',', $chunk);
                      
                      if (!class_exists('extMemberCheck')) {
                          class extMemberCheck {
                              var $allGroups = NULL;
                              var $debug;
                      
                              function getInstance($debug) {
                                  static $instance;
                                  if (!isset ($instance)) {
                                      $instance = new extMemberCheck($debug);
                                  }
                                  return $instance;
                              }
                      
                              function extMemberCheck($debug = false) {
                                  global $modx;
                      
                                  $this->debug = $debug;
                                  if ($debug) {
                                      $this->allGroups = array ();
                                      $tableName = $modx->getFullTableName('webgroup_names');
                                      $sql = "SELECT name FROM $tableName";
                                      if ($rs = $modx->db->query($sql)) {
                                          while ($row = $modx->db->getRow($rs)) {
                                              array_push($this->allGroups, stripslashes($row['name']));
                                          }
                                      }
                                  }
                              }
                      
                              function isValidGroup($groupName) {
                                  $isValid = !(array_search($groupName, $this->allGroups) === false);
                                  return $isValid;
                              }
                      
                              function getMemberChunk(& $groups, $chunk, $default) {
                                  global $modx;
                                  $o = '';
                                  if (!is_array($chunk)) {
                                      $o .= "<p>No chunk names were specified!</p>";
                                      return $o;
                                  }
                                  if (!is_array($groups)) {
                                      $o .= "<p>No group names were specified!</p>";
                                      return $o;
                                  }
                          
                                  if (count($groups) != count($chunk)) {
                                      if (count($chunk) != 1) {
                                          $o .= "<p>Number of group names and chunks must be the same!</p>";
                                       return $o;
                                      }
                                  }
                      
                                  for ($i = 0; $i < count($groups); $i++) {
                                      $groups[$i] = trim($groups[$i]);                $chnk = trim($chunk[$i]);
                                     		   if ($this->isValidGroup($groups[$i])) {
                                          if (count($chunk) != 1) {
                                              $group = array($groups[$i]);
                                              $check = $modx->isMemberOfWebGroup($group);
                                              if ($check) {
                                                  $chunkcheck = $modx->getChunk($chnk);
                                                  $o = ($chunkcheck) ? $chunkcheck : '';
                                                  if (!$chunkcheck)
                                                      $o .= $this->debug ? "<p>The chunk <strong>$chnk</strong> not found...</p>" : '';
                                                  return $o;
                                              } 
                                          } 
                                              $check = $modx->isMemberOfWebGroup($groups);
                                              $chunkcheck = $modx->getChunk($chnk);
                      						$defaultcheck = $modx->getChunk($default);
                      						
                                              $o .= ($check && $chunkcheck) ? $chunkcheck : '';
                                              if (!$chunkcheck)
                                                  $o .= $this->debug ? "<p>The chunk <strong>$chnk</strong> not found...</p>" : '';
                                          }
                      				else
                      				{
                      					if ($defaultcheck && (strlen($default) >= 1)) {
                      						$o .= ($defaultcheck) ? $defaultcheck : '';
                      					}
                      					if (!$defaultcheck && (strlen($default) >= 1)) {
                      						$o .= $this->debug ? "<p>The default chunk <strong>$default</strong> not found...</p>" : '';
                      					}
                      				}
                                  
                                     {
                                          if ($this->debug) {
                                              return "<p>The group <strong>" . $groups[$i] . "</strong> could not be found...</p>";
                                          }
                      					return $o;
                                      }
                                  }
                              }
                          }
                      }
                      
                      $memberCheck = extMemberCheck :: getInstance($debug);
                      
                      if (!isset ($ph)) {
                          echo htmlentities(var_dump($memberCheck));
                          return $memberCheck->getMemberChunk($groups, $chunk, $default);
                      } else {
                          $modx->setPlaceholder($ph, $memberCheck->getMemberChunk($groups, $chunk, $default));
                          return '';
                      }
                      ?>



                      I added the echo htmlentities(var_dump($memberCheck)); to see if it would help but all it is echoing is
                      object(extmembercheck)(2) { ["allGroups"]=> array(5) { [0]=> string(11) "Blank Group" [1]=> string(6) "Brides" [2]=> string(7) "Editors" [3]=> string(7) "Vendors" [4]=> string(8) "VendorsB" } ["debug"]=> string(4) "true" }

                      The group Vendors could not be found...