logo       


CVS: phpwiki/lib WikiGroup.php,1.6,1.7: msg#00042

Subject: CVS: phpwiki/lib WikiGroup.php,1.6,1.7
Update of /cvsroot/phpwiki/phpwiki/lib
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv17155

Modified Files:
        WikiGroup.php 
Log Message:
added GroupDB and GroupFile classes


Index: WikiGroup.php
===================================================================
RCS file: /cvsroot/phpwiki/phpwiki/lib/WikiGroup.php,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -2 -b -p -d -r1.6 -r1.7
--- WikiGroup.php       7 Dec 2003 19:29:11 -0000       1.6
+++ WikiGroup.php       26 Jan 2004 16:52:40 -0000      1.7
@@ -21,4 +21,14 @@ rcs_id('$Id$');
  */
 
+if (!defined('GROUP_NONE')) {
+    $group_method = 0; 
+    define('GROUP_NONE',       $group_method++);
+    define('GROUP_WIKIPAGE',   $group_method++); 
+    define('GROUP_DB',         $group_method++);
+    define('GROUP_FILE',       $group_method++);
+    define('GROUP_LDAP',       $group_method++);
+}
+if (!defined('GROUP_METHOD')) define('GROUP_METHOD', GROUP_WIKIPAGE);
+
 /**
  * WikiGroup is an abstract class to provide the base functions for determining
@@ -75,5 +85,5 @@ class WikiGroup{
      */ 
     function getGroup($request){
-        switch(GROUP_METHOD){
+        switch (GROUP_METHOD){
             case GROUP_NONE: 
                 return new GroupNone($request);
@@ -82,12 +92,15 @@ class WikiGroup{
                 return new GroupWikiPage($request);
                 break;
-#            case GROUP_DB: 
-#                return new GroupDB($user, $request);
-#                break;
+            case GROUP_DB:
+                return new GroupDB($request);
+                break;
+            case GROUP_FILE: 
+                return new GroupFile($request);
+                break;
 #            case GROUP_LDAP: 
-#                return new GroupLDAP($user, $request);
+#                return new GroupLDAP($request);
 #                break;
             default:
-                trigger_error("No GROUP_METHOD defined", E_USER_WARNING);
+                trigger_error(_("No GROUP_METHOD defined"), E_USER_WARNING);
                 return new WikiGroup($request);
         }
@@ -278,5 +291,5 @@ class GroupWikiPage extends WikiGroup{
         if ($group_revision->hasDefaultContents()) {
             $group = $group_page->getName();
-            trigger_error("Group $group does not exist", E_USER_WARNING);
+            trigger_error(sprintf(_("Group %s does not exist"),$group), 
E_USER_WARNING);
             return false;
         }
@@ -304,5 +317,5 @@ class GroupWikiPage extends WikiGroup{
         $membership = array();
         $dbh = &$request->getDbh();
-        $master_page = $request->getPage('CategeoryGroups');
+        $master_page = $request->getPage('CategoryGroups');
         $master_list = $master_page->getLinks(true);
         while($group_page = $master_list->next()){
@@ -354,5 +367,209 @@ class GroupWikiPage extends WikiGroup{
 }
 
+/**
+ * GroupDb is configured by $DbAuthParams[] statements
+ * 
+ * @author ReiniUrban
+ */ 
+class GroupDb extends WikiGroup {
+    
+    /**
+     * Constructor
+     * 
+     * @param object $request The global WikiRequest object.
+     */ 
+    function GroupDb(&$request){
+        $this->request = &$request;
+        $this->username = null;
+        $this->membership = array();
+
+        if (empty($DBAuthParams['group_members']) or 
empty($DBAuthParams['user_groups'])) {
+            trigger_error(_("No GROUP_DB statements defined"), E_USER_WARNING);
+            return false;
+        }
+        $dbh = _PassUser::getAuthDbh();
+        $this->_is_member = 
$dbh->_backend->prepare(preg_replace(array('"$userid"','"$groupname"'),array('?','?'),$DBAuthParams['is_member']));
+        $this->_group_members = 
$dbh->_backend->prepare(preg_replace('"$groupname"','?',$DBAuthParams['group_members']));
+        $this->_user_groups = 
$dbh->_backend->prepare(preg_replace('"$userid"','?',$DBAuthParams['user_groups']));
+    }
+
+    /**
+     * Determines if the current user is a member of a group.
+     * 
+     * To determine membership in a particular group, this method checks the 
+     * superclass instance variable $membership to see if membership has 
+     * already been determined.  If not, then the group page is parsed to 
+     * determine membership.
+     * @param string $group Name of the group to check for membership.
+     * @return boolean True if user is a member, else false.
+     */ 
+    function isMember($group) {
+        $request = $this->request;
+        $username = $this->_getUserName();
+        if (isset($this->membership[$group])) {
+            return $this->membership[$group];
+        }
+        $dbh = _PassUser::getAuthDbh();
+        $db_result = 
$dbh->_backend->execute($this->_is_member,$username,$group);
+        if ($db_result->numRows() > 0) {
+            $this->membership[$group] = true;
+            return true;
+        }
+        $this->membership[$group] = false;
+        return false;
+    }
+    
+    /**
+     * Determines all of the groups of which the current user is a member.
+     * 
+     * then checks each group to see if the current user is a member.
+     * @param string $group Name of the group to check for membership.
+     * @return array Array of groups to which the user belongs.
+     */ 
+    function getAllGroupsIn(){
+        $request = &$this->request;
+        $username = $this->_getUserName();
+        $membership = array();
+
+        $dbh = _PassUser::getAuthDbh();
+        $db_result = $dbh->_backend->execute($this->_user_groups,$username);
+        if ($db_result->numRows() > 0) {
+            while (list($group) = $db_result->fetchRow()) {
+                $membership[] = $group;
+            }
+        }
+        $this->membership = $membership;
+        return $membership;
+    }
+
+    /**
+     * Determines all of the members of a particular group.
+     * 
+     * Checks a group's page to return all the current members.  Currently this
+     * method is disabled and triggers an error and returns an empty array.
+     * @param string $group Name of the group to get the full membership list 
of.
+     * @return array Array of usernames that have joined the group.
+     */ 
+    function getMembersOf($group){
+        $request = &$this->request;
+        $username = $this->_getUserName();
+        $members = array();
+
+        $dbh = _PassUser::getAuthDbh();
+        $db_result = $dbh->_backend->execute($this->_group_members,$group);
+        if ($db_result->numRows() > 0) {
+            while (list($userid) = $db_result->fetchRow()) {
+                $members[] = $userid;
+            }
+        }
+        return $members;
+    }
+}
+
+/**
+ * GroupFile is configured by AUTH_GROUP_FILE
+ * groupname: user1 user2 ...
+ * 
+ * @author ReiniUrban
+ */ 
+class GroupFile extends WikiGroup {
+    
+    /**
+     * Constructor
+     * 
+     * @param object $request The global WikiRequest object.
+     */ 
+    function GroupFile(&$request){
+        $this->request = &$request;
+        $this->username = null;
+        $this->membership = array();
+
+        if (!defined('AUTH_GROUP_FILE')) {
+            trigger_error(_("AUTH_GROUP_FILE not defined"), E_USER_WARNING);
+            return false;
+        }
+        if (!file_exists(AUTH_GROUP_FILE)) {
+            trigger_error(sprintf(_("Cannot open AUTH_GROUP_FILE %s"), 
AUTH_GROUP_FILE), E_USER_WARNING);
+            return false;
+        }
+        require 'lib/pear/File_Passwd.php';
+        $this->_file = File_Passwd($file);
+    }
+
+    /**
+     * Determines if the current user is a member of a group.
+     * 
+     * To determine membership in a particular group, this method checks the 
+     * superclass instance variable $membership to see if membership has 
+     * already been determined.  If not, then the group file is parsed to 
+     * determine membership.
+     * @param string $group Name of the group to check for membership.
+     * @return boolean True if user is a member, else false.
+     */ 
+    function isMember($group) {
+        $request = $this->request;
+        $username = $this->_getUserName();
+        if (isset($this->membership[$group])) {
+            return $this->membership[$group];
+        }
+
+        foreach ($this->_file->users[] as $g => $u) {
+            $users = explode(' ',$u);
+            if (in_array($username,$users)) {
+                $this->membership[$group] = true;
+                return true;
+            }
+        }
+        $this->membership[$group] = false;
+        return false;
+    }
+    
+    /**
+     * Determines all of the groups of which the current user is a member.
+     * 
+     * then checks each group to see if the current user is a member.
+     * @param string $group Name of the group to check for membership.
+     * @return array Array of groups to which the user belongs.
+     */ 
+    function getAllGroupsIn(){
+        $request = &$this->request;
+        $username = $this->_getUserName();
+        $membership = array();
+
+        foreach ($this->_file->users[] as $group => $u) {
+            $users = explode(' ',$u);
+            if (in_array($username,$users)) {
+                $this->membership[$group] = true;
+                $membership[] = $group;
+            }
+        }
+        $this->membership = $membership;
+        return $membership;
+    }
+
+    /**
+     * Determines all of the members of a particular group.
+     * 
+     * Checks a group's page to return all the current members.  Currently this
+     * method is disabled and triggers an error and returns an empty array.
+     * @param string $group Name of the group to get the full membership list 
of.
+     * @return array Array of usernames that have joined the group.
+     */ 
+    function getMembersOf($group){
+        $request = &$this->request;
+        $username = $this->_getUserName();
+        $members = array();
+
+        if (!empty($this->_file->users[$group])) {
+            return explode(' ',$this->_file->users[$group]);
+        }
+        return $members;
+    }
+}
+
 // $Log$
+// Revision 1.7  2004/01/26 16:52:40  rurban
+// added GroupDB and GroupFile classes
+//
 // Revision 1.6  2003/12/07 19:29:11  carstenklapp
 // Code Housecleaning: fixed syntax errors. (php -l *.php)



-------------------------------------------------------
The SF.Net email is sponsored by EclipseCon 2004
Premiere Conference on Open Tools Development and Integration
See the breadth of Eclipse activity. February 3-5 in Anaheim, CA.
http://www.eclipsecon.org/osdn


Ruby Jobs
Java Jobs
Jobs in California
more...
what
job title, keywords
where
city, state, zip
jobs by job search
Search:
Java, servers, webhosting, windows, cisco ...
more...
<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

Recently Viewed:
encryption.gpg....    ietf.rfc822/199...    freebsd.devel.i...    lang.haskell.li...    mail.squirrelma...    web.zope.plone....    yellowdog.gener...    text.xml.xalan....    recreation.phot...    kde.devel.educa...    hardware.bus.ca...    printing.ghosts...    voip.peering/20...    assembly/2006-0...    org.user-groups...    culture.interne...    network.i2p/200...    boot-loaders.ya...    xfree86.render/...    qnx.openqnx.dev...    jakarta.velocit...    user-groups.pal...   
Home | blog view | USPTO Patent Archive | advertise | OSDir is an inevitable website. super tiny logo

Free Magazines

Cisco News
Receive a free quarterly e-newsletter with exclusive articles on how Cisco IT uses its own products and solutions to enable the business.
subscribe

Systems Management News, the newspaper for IT systems administration and data center managers! Each issue of Systems Management News is chock-full of news and analysis to help you understand what's happening in your field.
subscribe

The Enterprise Newsweekly eWeek is the essential technology information source for builders of e-business.
subscribe

Oracle Magazine Oracle Magazine contains technology strategy articles, sample code, tips, Oracle and partner news, how to articles for developers and DBAs, and more. Oracle (NASDAQ: ORCL) is the world's largest enterprise software company.
subscribe

Total Telecom Total Telecom is "The Economist of the communications industry".
subscribe