1
jordi_rc
Merge Xoops with Bytehoard
  • 2006/11/23 22:35

  • jordi_rc

  • Not too shy to talk

  • Posts: 114

  • Since: 2006/8/21


Hello!

In the site I am developing I needed a way for users to easilly upload files to their own folder in a visual way, in order to host their files. I needed a way so each user has his/her own folder created when they get promoted to a certain group and enters the file application for first time. The user cannot (and mustn't) reach other users folders.

I found the perfect GPL solution: it is called Bytehoard.
(http://www.bytehoard.org/)

This is the way to merge XOOPS with Bytehoard:

1) We suppose you have XOOPS installed, your website is called "myweb" and bytehoard is installed in a folder called "bytehoard" just inside your XOOPS root folder.

2) Create a custom group of users based in regular users.

3) Create a custom block in Xoops. Give the admin and the group created in point 1) access to this block, and not the others.

4) In the block, select as type of content PHP. Paste this code:
global $xoopsUser;

$uid=$xoopsUser->getVar('uid');

echo
"<a href='http://localhost/myweb/fileaccess.php?uid=$uid'>Build your website and files<br></a>";


5) Create a file in your XOOPS root folder called fileaccess.php with this code:

<?php

// include all needed files

include '../mainfile.php';
include_once 
XOOPS_ROOT_PATH.'/class/module.textsanitizer.php';

include_once 
XOOPS_ROOT_PATH .'/modules/system/constants.php';

include_once 
XOOPS_ROOT_PATH.'/bytehoard/config.inc.php';

$uid intval($_GET['uid']); 

// prevent empty uid

if ($uid <= 0) { 
    
redirect_header('../index.php'3'You are not allowed to enter here');
    exit();
}

// test if it is XOOPS user

if (is_object($xoopsUser)) { 

// test if he is of group 4 of xoops, or the admin, as they are the only with files access

$groups is_object($xoopsUser) ? $xoopsUser->getGroups() : array(XOOPS_GROUP_ANONYMOUS);
if ( 
in_array("4"$groups) || in_array("1"$groups) ) {

// test if he sends his own uid

if ($uid == $xoopsUser->getVar('uid')) { 

// extra test if uid is not empty

if (!empty($_GET['uid'])) { 

                        
// get XOOPS data of the user
                        
$uid $_GET['uid'];
        
                        
mysql_connect(XOOPS_DB_HOSTXOOPS_DB_USERXOOPS_DB_PASS) or die(mysql_error());
                        
mysql_select_db(XOOPS_DB_NAME) or die(mysql_error());
                        
$member mysql_fetch_assoc(mysql_query("SELECT uid, uname, pass, email, name FROM xoops_users WHERE uid=$uid"));

                        
$muname=$member[uname];
                        
$memail=$member[email];
                        
$mname=$member[name];
                        
$mpass=$member[pass];

                            
mysql_connect($dbconfig['host'], $dbconfig['username'], $dbconfig['password']) or die(mysql_error());
                            
mysql_select_db($dbconfig['db']) or die(mysql_error());
                            
$worldbuilderExiste mysql_fetch_assoc(mysql_query("SELECT * FROM bh2_users WHERE username='$muname'"));
                            
                            
// si el usuario ya existe lo manda al login. Si no, crea su cuenta.
                            
                            
if ($worldbuilderExiste) { 
                            
header 'Location: http://localhost/myweb/bytehoard/' ); exit; }
                            
                            else{ 
                                                
                            echo 
"<br><br>ahora eres worldbuilder";
                            
// creates bytehoard user
                        
$homedir "/".$muname;
                        
$quota round(30*1024*1024); // first number is the space in mb
            
mysql_connect($dbconfig['host'], $dbconfig['username'], $dbconfig['password']) or die(mysql_error());
            
mysql_select_db($dbconfig['db']) or die(mysql_error());
            
mysql_query("INSERT INTO bh2_users (username, password, type, homedir, quota) VALUES('$muname', '$mpass', 'normal', '$homedir', '$quota' )") or die(mysql_error());
            
mysql_query("INSERT INTO bh2_userinfo (username, itemname, itemcontent) VALUES('$muname', 'fullname', '$mname') ") or die(mysql_error());
            
mysql_query("INSERT INTO bh2_userinfo (username, itemname, itemcontent) VALUES('$muname', 'email', '$memail') ") or die(mysql_error());
                            
            
header 'Location: http://localhost/myweb/bytehoard/' ); exit; 
                            
            }
            } 
    else {    
redirect_header('../index.php'3'You are not allowed to enter this way'); exit(); }
    } 
    else {    
redirect_header('../index.php'3'You are not allowed to enter this way'); exit(); }
    } 
    else {    
redirect_header('../index.php'3'You must have file upload permission to enter here'); exit(); }
    } 
    else {    
redirect_header('../index.php'3'You are not allowed to enter this way'); exit(); }
?>


-------------

That's all. Now when the user gets promoted to the group with id 4 he gets access to the block, clics the link and the account is created in bytehoard. He logs in and can upload files to his folder.

---
Please tell me if I must add something for security reasons.

I think XOOPS and Bytehoard do a nice couple.


Jordi
"Battles are fought by those with the courage to believe. They are won by those who find the heart to share." -MANOWAR

Login

Who's Online

132 user(s) are online (84 user(s) are browsing Support Forums)


Members: 0


Guests: 132


more...

Donat-O-Meter

Stats
Goal: $100.00
Due Date: May 31
Gross Amount: $0.00
Net Balance: $0.00
Left to go: $100.00
Make donations with PayPal!

Latest GitHub Commits