Page 1 of 1

Thinking about designing a CMS sort of system...

Posted: Fri Sep 10, 2004 6:44 am
by timhortons
Well i've been a member here for a long time, havent really posted a lot, dunno why... anyways, one of my aspirations is to design a nice "CMS" for myself, and others (if they're interested). So yeah, "wow" another CMS... well, the only reason i want to take on the task of writing my own, is because I think i can improve some areas that really seem to be quite simple in CMS's that are already available. I want to include better theme support, more interactivity, and better member permissions... or easier to use anyways.

So, where i think this fits in with "advanced topics" is the member permission setup I have going. I think it will work, but I could use some expert opinions and advice.

My Idea for member permissions:

Group Table:
group_id int
permission_id int
group_name text

Permission Table:
permission_id int
group_id int
permission_array text

Member Table (applicable fields)
group_id int
preferences_id int (this is for site preferences, etc)

Preference Table:
preference_id int
preference_array text

So with this setup, i've contemplated that you can assign a user to a specific group... then that group is linked to a set of permissions... then as they go through the site, their permissions are determined... one thing though, if i need to give one user a specific, unique set of permissions... then i have to make one group especially for them... unless, i go around the group table, and assign a permission id instead of a group id, but then, it may become a bit confusing as it really goes around the way i've designed it.

thoughts and ideas about permissions setup?

anyways, for my theme stuff... i'm not going to be sharing a whole bunch, but i'm just wondering what you all think the preferred methods would be. As of now, i've created my own parsing functions. The parsing function reads a template file... looks for special XML-like tags, snatches them out and constructs an array of the values for it. I'm not having a problem with it, but I'm wondering if there'd be a better way to do themes, or if you have any links, or suggestions about "ideal" theme handling in PHP.

Anyways, with this bit said, I'd like to show you some of my progress on a test i've been working on to deal with menus and themes it would give you an idea of some of the stuff i'm trying to accomplish... so the main page: http://scripts.joshstmarie.com/menu.test/

theme test one: http://scripts.joshstmarie.com/menu.test/?theme.1

theme test two: http://scripts.joshstmarie.com/menu.test/?theme.2

menu movement test: http://scripts.joshstmarie.com/menu.tes ... oveLinks.1

source code to my functions file which handles pretty much everything (just for general interest... it's really chunky.. but Dreamweaver messed up the tabs!!)

http://scripts.joshstmarie.com/menu.test/Functions.phps

anyways yeah, thoughts and opinions on what i'm trying to do would be appreciated... (and yes, i know my code is messy as hell, but it's a working version... and i'm still trying to work it all out in my head :P)

PS: i've looked at viewtopic.php?t=25565&postdays=0&postorder=asc&start=0 for ideas on my permission setup too.. just so you know it's not like i'm not looking around :P

Posted: Fri Sep 10, 2004 7:11 am
by Weirdan
what for there's permission_id column in Group table?

Posted: Fri Sep 10, 2004 7:42 am
by kettle_drum
For my permission system i only ever use one table and each permission has a keyword, or is left blank if the permission is a group.

Code: Select all

id
tag
name
description
privs
So for example you want to only allow certain people to vote on the site poll. You create a permission in the table with the tag "vote_in_poll" and give it a description and a name to make it easy to locate and find in a web interface - you leave the privs empty as thats only for groups.

Then you make a group in the table and name it, leave the tag empty, and fill in the privs field with the id of the individual privlidge id numbers - note these can also be the number of groups - so you get recursive groups - solving the problem of when you want used to have the same privledges with just one or two differences.

Then of course you assign the user to the group id. Then when you load the page you get the id of the privledge group the user is in and run it through a function to get all the possible privledge id's that the user has.

Now when the poll loads, you have an if statment to check a function:

Code: Select all

if(check_privs('vote_in_poll')){
   ...
}
This function queries the database to get the id that "vote_in_poll" is the tag for, and then checks to see if the user has that privledge.

Since this system works on using the id numbers to check the privs it means that they dont have to be in any order and are dynamic, which leads itself for a cms with modules which include privledges. All the modules have to do is insert its keywords into the privledge database and it doesnt matter what other modules are installed as there wont be any clashes - they just get given an unique id number which relates to like "module_bobs_forum" etc.

I also find that since its done in this dynamic form you tend to add more privledges and so provide the user with more options to restrict access and make a much more powerful, customisable site.

Hope that all made sense.

Posted: Tue Sep 14, 2004 5:43 am
by timhortons
thanks for the help... i've adjusted some things, and i'm continuing to work it out... i think i've got a better setup... but it still takes two queries to get the permissions array with the way i have it, unless i could do sub-queries... but that's out of the question since MySQL 4.1.1 is hardly used on hosts yet, it wouldnt be really compatible.

anywho, i'll be posting more around here sometime

Posted: Tue Sep 14, 2004 9:34 am
by kettle_drum
Yeah keep me up todate with your progress (Interested in this type of thing).

Posted: Tue Sep 14, 2004 9:44 am
by timvw
currently i have [user] 1 - 1 [groups] 1 - n [groupscripts] n - 1 [scripts]

groupscripts:
group_id int FK
script_id int FK
property varchar
primary key (group_id, script_id, property)

A property is "something" (usually a database field) that is allowed to be seen/modified whatever.

To get all those properties i query like:

Code: Select all

SELECT script_id, property
FROM groupscripts
INNER JOIN users ON users.group_id=groupscripts.group_id 
WHERE users.user_id={$db->qstr($credentialsї'name'])} 
AND users.password={$db->qstr($credentialsї'password'])}

Posted: Tue Sep 14, 2004 11:29 am
by timhortons
I think i found a solution of how to select the permissions to a specific user in one query using joins! i dont like using joins, as they're generally confusing to me, but i think this will work!

Code: Select all

# Using the username timhortons as an example...

SELECT p.permission_id, p.permission_array, g.group_id FROM tests_member_groups as g INNER JOIN tests_member_permissions as p ON g.group_id = p.group_id LEFT JOIN tests_members as m ON m.group_name = g.group_name WHERE m.username = 'timhortons';
My database tables structure is now:

member_groups
-group_id int,
-group_name varchar

member_permissions
-permission_id int,
-group_id int,
-permission_array text

members (applicable fields)
-username varchar
-group_name varchar

So now with this new query using joins, i can get the user's permissions in one go! And if I need to give the user custom permissions that are one-of-a-kind to that specific user, i'll just create a group_name unique to them and tie their permissions to that group...

anywho, i'm going to keep working on it... but i think it's coming together now[/b]

Posted: Thu Sep 16, 2004 10:49 am
by timhortons
Well i've finished a bit more on my system, as it turns out i dont need one query to get a permission array after all! I've switched my system all around... now members can belong to more than one group!

for an example:
http://renascence.joshstmarie.com/?user.the_crop <- This user belongs to the group user, which has no permissions, then the user is assigned to moderator, which has access to all the news options.

so far, the order of groups is an issue... the group with least permissions is first, then the next group would be the one with more permissions.

another user is
http://renascence.joshstmarie.com/?user.guest
and
http://renascence.joshstmarie.com/?user.timhortons

Posted: Thu Sep 16, 2004 12:43 pm
by timvw
ah, referring to my other post

i can easily expaned from [users] 1 - 1 [ groups]
to [users] 1 - n [ usergroups] n - 1 [ groups]

only requires me to extend the query a little

Code: Select all

SELECT *
FROM groupscripts
INNER JOIN usergroups ON usergroups.group_id=groupscripts.group_id
INNER JOIN users ON users.user_id=usergroups.user_id
WHERE ....
Allows me to build an array that contains all the properties per script. (and cache it in the session)

Posted: Sat Oct 02, 2004 5:53 pm
by JasonMichael
I've been working on my own CMS for quite awhile now. I'm starting to write a tutorial about it on my website. Anyway, I pretty much do the same thing - have group and member permissions, but also add the ability for Role permissions, which takes precedant over group and member information.

Jason