Changeset 1165 in ExiteCMS


Ignore:
Timestamp:
12/10/07 00:01:20 (4 years ago)
Author:
hverton
Message:

upgraded the module installer, to include the localestings. also included upgrade code to convert the original wiki ACL's to CMS compliant ACL's (using user- and group ID's).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • modules/common/wiki/php-files/modules/wiki/module_installer.php

    r1161 r1165  
    1919+----------------------------------------------------*/ 
    2020$mod_title = "Wikka Wiki";                              // title or name of this module 
    21 $mod_description = "ExiteCMS embedded implementation of Wikka Wakka Wiki";  // short description of it's purpose 
     21$mod_description = "ExiteCMS embedded implementation of Wikka Wakka Wiki v1.1.6.3"; // short description of it's purpose 
    2222$mod_version = "1.0.2";                                 // module version number 
    2323$mod_developer = "WanWizard";                           // author's name 
     
    8686$localestrings['en']['420'] = "(only if IP address matches)"; 
    8787 
    88 $localestrings = array(); 
    8988$localestrings['nl'] = array(); 
    9089$localestrings['nl']['400'] = "Wiki configuratie"; 
     
    231230) ENGINE=MyISAM;"); 
    232231 
    233 // add the Wiki config variables 
    234 $mod_install_cmds[] = array('type' => 'db', 'value' => "INSERT INTO ##PREFIX##CMSconfig (cfg_name, cfg_value) VALUES ('wiki_root_page', 'HomePage')"); 
    235 $mod_install_cmds[] = array('type' => 'db', 'value' => "INSERT INTO ##PREFIX##CMSconfig (cfg_name, cfg_value) VALUES ('wiki_wakka_name', 'ExiteCMS Wiki')"); 
    236 $mod_install_cmds[] = array('type' => 'db', 'value' => "INSERT INTO ##PREFIX##CMSconfig (cfg_name, cfg_value) VALUES ('wiki_navigation_links', '[[CategoryCategory Categories]] | PageIndex |  RecentChanges | RecentlyCommented')"); 
    237 $mod_install_cmds[] = array('type' => 'db', 'value' => "INSERT INTO ##PREFIX##CMSconfig (cfg_name, cfg_value) VALUES ('wiki_logged_in_navigation_links', '[[CategoryCategory Categories]] | PageIndex | RecentChanges | RecentlyCommented | [[UserSettings Change settings]]')"); 
    238 $mod_install_cmds[] = array('type' => 'db', 'value' => "INSERT INTO ##PREFIX##CMSconfig (cfg_name, cfg_value) VALUES ('wiki_hide_comments', '0')"); 
    239 $mod_install_cmds[] = array('type' => 'db', 'value' => "INSERT INTO ##PREFIX##CMSconfig (cfg_name, cfg_value) VALUES ('wiki_require_edit_note', '0')"); 
    240 $mod_install_cmds[] = array('type' => 'db', 'value' => "INSERT INTO ##PREFIX##CMSconfig (cfg_name, cfg_value) VALUES ('wiki_anony_delete_own_comments', '1')"); 
    241 $mod_install_cmds[] = array('type' => 'db', 'value' => "INSERT INTO ##PREFIX##CMSconfig (cfg_name, cfg_value) VALUES ('wiki_external_link_new_window', '1')"); 
    242 $mod_install_cmds[] = array('type' => 'db', 'value' => "INSERT INTO ##PREFIX##CMSconfig (cfg_name, cfg_value) VALUES ('wiki_default_read_acl', 'G0')"); 
    243 $mod_install_cmds[] = array('type' => 'db', 'value' => "INSERT INTO ##PREFIX##CMSconfig (cfg_name, cfg_value) VALUES ('wiki_default_write_acl', 'G101')"); 
    244 $mod_install_cmds[] = array('type' => 'db', 'value' => "INSERT INTO ##PREFIX##CMSconfig (cfg_name, cfg_value) VALUES ('wiki_default_comment_acl', 'G101')"); 
    245 $mod_install_cmds[] = array('type' => 'db', 'value' => "INSERT INTO ##PREFIX##CMSconfig (cfg_name, cfg_value) VALUES ('wiki_admin_group', 'G103')"); 
     232// create the user groups for this module 
     233$mod_install_cmds[] = array('type' => 'db', 'value' => "INSERT INTO ##PREFIX##user_groups (group_ident, group_name, group_description, group_forumname, group_visible) VALUES ('".$mod_admin_rights."01', 'Wiki Admins', 'Wiki Admins', 'Wiki Admin', '1')"); 
     234$mod_install_cmds[] = array('type' => 'db', 'value' => "INSERT INTO ##PREFIX##user_groups (group_ident, group_name, group_description, group_forumname, group_visible) VALUES ('".$mod_admin_rights."02', 'Wiki Editors', 'Wiki Editors', 'Wiki Editor', '1')"); 
    246235 
    247236// custom module install code 
     
    278267$mod_uninstall_cmds[] = array('type' => 'db', 'value' => "DELETE FROM ##PREFIX##CMSconfig WHERE cfg_name = 'wiki_admin_group'"); 
    279268 
    280 // remove any reference to the wiki groups created at installation time by an other version 
     269// delete the user groups 
     270$mod_uninstall_cmds[] = array('type' => 'db', 'value' => "DELETE FROM ##PREFIX##user_groups WHERE group_ident = '".$mod_admin_rights."01'"); 
     271$mod_uninstall_cmds[] = array('type' => 'db', 'value' => "DELETE FROM ##PREFIX##user_groups WHERE group_ident = '".$mod_admin_rights."02'"); 
     272 
     273// custom module uninstall code 
    281274$mod_uninstall_cmds[] = array('type' => 'function', 'value' => "module_uninstall"); 
    282275 
     
    288281         
    289282        global $db_prefix, $mod_admin_rights; 
     283 
     284        // add the Wiki config variables 
     285        add_config_items(); 
    290286 
    291287        // update the default wiki pages with the name of the webmasters account 
     
    303299    } 
    304300} 
     301 
     302// add the Wiki config variables 
     303if (!function_exists('add_config_items')) { 
     304    function add_config_items() { 
     305        global $db_prefix, $mod_admin_rights; 
     306     
     307        $result = dbquery("INSERT INTO ".$db_prefix."CMSconfig( cfg_name, cfg_value ) VALUES ('wiki_root_page', 'HomePage')"); 
     308        $result = dbquery("INSERT INTO ".$db_prefix."CMSconfig( cfg_name, cfg_value ) VALUES ('wiki_wakka_name', 'ExiteCMS Wiki')"); 
     309        $result = dbquery("INSERT INTO ".$db_prefix."CMSconfig( cfg_name, cfg_value ) VALUES ('wiki_navigation_links', '[[CategoryCategory Categories]] | PageIndex | RecentChanges | RecentlyCommented')"); 
     310        $result = dbquery("INSERT INTO ".$db_prefix."CMSconfig( cfg_name, cfg_value ) VALUES ('wiki_logged_in_navigation_links', '[[CategoryCategory Categories]] | PageIndex | RecentChanges | RecentlyCommented | [[UserSettings Change settings]]')"); 
     311        $result = dbquery("INSERT INTO ".$db_prefix."CMSconfig( cfg_name, cfg_value ) VALUES ('wiki_hide_comments', '0')"); 
     312        $result = dbquery("INSERT INTO ".$db_prefix."CMSconfig( cfg_name, cfg_value ) VALUES ('wiki_require_edit_note', '0')"); 
     313        $result = dbquery("INSERT INTO ".$db_prefix."CMSconfig( cfg_name, cfg_value ) VALUES ('wiki_anony_delete_own_comments', '1')"); 
     314        $result = dbquery("INSERT INTO ".$db_prefix."CMSconfig( cfg_name, cfg_value ) VALUES ('wiki_external_link_new_window', '1')"); 
     315        $result = dbquery("INSERT INTO ".$db_prefix."CMSconfig( cfg_name, cfg_value ) VALUES ('wiki_default_read_acl', 'G0');"); 
     316        // get the group_id of the Wiki Editors group 
     317        $result = dbquery("SELECT * FROM ".$db_prefix."user_groups WHERE group_ident = '".$mod_admin_rights."01'"); 
     318        if (dbrows($result)) { 
     319            $data = dbarray($result); 
     320            $result = dbquery("INSERT INTO ".$db_prefix."CMSconfig( cfg_name, cfg_value ) VALUES ('wiki_default_write_acl', 'G".$data['group_id']."')"); 
     321            $result = dbquery("INSERT INTO ".$db_prefix."CMSconfig( cfg_name, cfg_value ) VALUES ('wiki_default_comment_acl', 'G".$data['group_id']."')"); 
     322        } else { 
     323            // can't find it? default to all members             
     324            $result = dbquery("INSERT INTO ".$db_prefix."CMSconfig( cfg_name, cfg_value ) VALUES ('wiki_default_write_acl', 'G101')"); 
     325            $result = dbquery("INSERT INTO ".$db_prefix."CMSconfig( cfg_name, cfg_value ) VALUES ('wiki_default_comment_acl', 'G101')"); 
     326        } 
     327        // get the group_id of the Wiki Admins group 
     328        $result = dbquery("SELECT * FROM ".$db_prefix."user_groups WHERE group_ident = '".$mod_admin_rights."02'"); 
     329        if (dbrows($result)) { 
     330            $data = dbarray($result); 
     331            $result = dbquery("INSERT INTO ".$db_prefix."CMSconfig( cfg_name, cfg_value ) VALUES ('wiki_admin_group', 'G".$data['group_id']."')"); 
     332        } else { 
     333            // can't find it? default to all members             
     334            $result = dbquery("INSERT INTO ".$db_prefix."CMSconfig( cfg_name, cfg_value ) VALUES ('wiki_admin_group', 'G103')"); 
     335        } 
     336    } 
     337} 
     338 
    305339/*---------------------------------------------------+ 
    306340| function for special de-installations              | 
     
    309343    function module_uninstall() { 
    310344 
    311         // code to be executed when uninstalling this module         
     345        // code to be executed when uninstalling this module 
    312346    } 
    313347} 
     
    325359 
    326360            case "1.0.1": 
    327                 // no specific changes between this version and the new one 
     361                // add the defaults to the CMSconfig table 
     362                add_config_items(); 
     363                // migrate the wiki_acls 
     364                $result = dbquery("SELECT * FROM ".$db_prefix."wiki_acls"); 
     365                while ($data = dbarray($result)) { 
     366                    $fieldarray = array('read_acl' => $data['read_acl'], 'write_acl' => $data['write_acl'], 'comment_acl' => $data['comment_acl']); 
     367                    foreach($fieldarray as $fieldname => $value) { 
     368                        $values = explode("\n", $value); 
     369                        $newacl = ""; 
     370                        foreach($values as $acl) { 
     371                            // wiki rule: Any line starting with a + or * will be treated as only having a + or * on it. 
     372                            if ($acl{0} == "*" || $acl{0} == "+") $acl = $acl{0}; 
     373                            // process the ACL 
     374                            switch ($acl) { 
     375                                case "+":   // authenticated users (members) 
     376                                    $newacl .= ($newacl == "" ? "" : "\n")."G101"; 
     377                                    break; 
     378                                case "*":   // everyone (public) 
     379                                    $newacl .= ($newacl == "" ? "" : "\n")."G0"; 
     380                                    break; 
     381                                case "!+":  // anonymous users (anonymous) 
     382                                    $newacl .= ($newacl == "" ? "" : "\n")."G100"; 
     383                                    break; 
     384                                case "!*":  // not everyone (none) 
     385                                    break; 
     386                                default: 
     387                                    // check if it's a deny 
     388                                    $deny = ($acl{0} == "!"); 
     389                                    if ($deny) $acl = substr($acl, 1); 
     390                                    // check if this is the name of a valid user 
     391                                    $result2 = dbquery("SELECT * FROM ".$db_prefix."users WHERE user_name = '".trim($acl)."'"); 
     392                                    if (dbrows($result2)) { 
     393                                        $data2 = dbarray($result2); 
     394                                        $newacl .= ($newacl == "" ? "" : "\n").$data2['user_id'];                                    
     395                                    } else { 
     396                                        echo "=> ",$acl," not found<br>"; 
     397                                    } 
     398                                    break; 
     399                            } 
     400                        } 
     401                        $fieldarray[$fieldname] = $newacl; 
     402                    } 
     403                    // update the wiki_acl 
     404                    $result = dbquery("UPDATE ".$db_prefix."wiki_acls SET read_acl = '".$fieldarray['read_acl']."', write_acl = '".$fieldarray['write_acl']."', comment_acl = '".$fieldarray['comment_acl']."' WHERE page_tag = '".$data['page_tag']."'"); 
     405                } 
    328406 
    329407            default: 
Note: See TracChangeset for help on using the changeset viewer.