SMF Community Helpers > Mod Development

[WIP] Forum Powered Website

(1/5) > >>

RabidShepherd:
Forum Powered Website Mod
Version: Beta 12.10.24
This is a work in progress, do not use on a live site.

License
Mozilla Public License, v. 2.0

History
I wanted to make a HTML5 based website, so I began by researching the best way to code one. I concluded the best way to build a secure and easily customizable site was to code functions and layout separately, basically a template system. I got to work coding a sessions and login system. After I got all that working on a basic site, I began my search for a forum to add to it. That's when I ran into the problem of integrating SMF with my site.

I realized SMF was built exactly how I wanted to build my site; uses a template system, sources and settings can be installed above document root, has a good login and sessions system. So, I scrapped what I already coded and began digging into SMF. That's how FPW Mod began.

Description
This mod allows you to build a website powered completely by SMF. You can create new pages and place them anywhere on your server, even in sub-domains. The pages you create can be loaded directly, or by using the source/template system that SMF employs. The mod adds menu buttons for all your pages that you can place anywhere you wish within the menubar. You can even have up to two levels of sub-buttons. Any pages you create also have permissions, so you can choose what members can view what pages.

For SMF 2.0.2 only.

Language
English

The mod is basically finished. I occasionally run into minor bugs, but nothing show stopping. It'd be great if the community could give the mod a workout so I can get this approved to full-fledged mod status soon. Hope you enjoy.

Suki:
OK, doing a quick check, didn't check the functionality, just the standard SMF coding guidelines :)

on fpw_db_install:

Check if SSI.php has ben loaded yet:


--- Code: --- if (file_exists(dirname(__FILE__) . '/SSI.php') && !defined('SMF'))
require_once(dirname(__FILE__) . '/SSI.php');

--- End code ---
Use updateMemberData() rather than a direct query.
Globalize $smcFunc.

Always check your $modSettings, $context and superglobal vars before use them, example:  !empty($modSettings['fpw_homepage_title']) ? $modSettings['fpw_homepage_title'] : ''  or doing an if before an echo.

You have some hardcoded text but I guess they are remains of debuggin stuff.

On ManageFpwSettings, you don't need to load your general settings with a query, SMF does that for you and uses the cache when avaliable, you just need to globalize $modSettings.
For your queries on updating and inserting data, please use the casting array rather than putting the values directly to the query, an example of an insert query: http://www.simplemachines.org/community/index.php?topic=224166.0#post_db_insert.

On packge-info.xml please specify a version for both the install and uninstall tags, this will prevent your mod from been installed on incompatible SMF versions, more info: http://www.simplemachines.org/community/index.php?topic=299669.0

RabidShepherd:
Thanks for the input.


--- Quote ---Use updateMemberData() rather than a direct query.
--- End quote ---
Where should I use this? That function appears to be used to update member data, I don't recall that I'm doing that anywhere.


--- Quote ---You have some hardcoded text but I guess they are remains of debuggin stuff.
--- End quote ---
Yeah, I got a lot of cleaning up to do still. Plus, more to add yet.


--- Quote ---On ManageFpwSettings, you don't need to load your general settings with a query, SMF does that for you and uses the cache when avaliable, you just need to globalize $modSettings.
--- End quote ---
Thanks, that page has gone through a ton of changes as I learned how SMF functioned... it probably will get altered many more times.


--- Quote ---For your queries on updating and inserting data, please use the casting array rather than putting the values directly to the query,
--- End quote ---
Don't get me started on that, I had major problems getting db queries working. The direct way was the only way I was successful. But then again, quotes mess me up in queries too  :o
I'll work on them though.


--- Quote ---On packge-info.xml please specify a version for both the install and uninstall tags
--- End quote ---
Oops, on my version, that's there. I must of zipped up an old version by mistake.

Thanks again for taking a look at it. I'll get working on correcting what you mentioned.

Suki:

--- Quote ---Where should I use this? That function appears to be used to update member data, I don't recall that I'm doing that anywhere.
--- End quote ---

On fpw_db_install.php but you are actually inserting data rather than updating it, either way, SMF creates the proper settings for you when the admin uses your mod settings for the first time.


--- Quote ---Don't get me started on that, I had major problems getting db queries working. The direct way was the only way I was successful. But then again, quotes mess me up in queries too 
I'll work on them though.
--- End quote ---

I had a hard time learning it too and at this point I still have to check SMF's code from time to time, on this particular case, inserting:


--- Code: ---$smcFunc['db_query']('', '
INSERT INTO {db_prefix}fpw_pages
VALUES (' . $newData['newpage']['page_id'] . ', "' . $newData['newpage']['page_title'] . '", "' . $newData['newpage']['action'] . '", "' . $newData['newpage']['permissions'] . '")'       
    );

--- End code ---

could be changed to this:


--- Code: --- $smcFunc['db_insert']('',
'{db_prefix}fpw_pages',
array(
'page_id' => 'int', 'page_title' => 'string-255', 'action' => 'string-255', 'permissions' => 'string-255',
),
$newData['newpage'],
array('page_id')
);
--- End code ---

or manually specify each value in the array:   array($newData['newpage']['page_id'], $newData['newpage']['page_title'], etc)

for updating is basically the same thing:


--- Code: --- $smcFunc['db_query']('', '
UPDATE {db_prefix}fpw_pages
SET page_id = {int:page_id}, page_title = {string:page_title}, action = {string:action}, permissions = {string::permissions}
WHERE page_id = {int:key}',
array(
'page_id' => $newData['newpage']['page_id'],
'page_title' => $newData['newpage']['page_title'],
'actions' => $newData['newpage']['actions'],
'permissions' => $newData['newpage']['permissions'],
'key' => $key,

)
);
--- End code ---

Single quotes must be escaped \' to avoid php errors.

RabidShepherd:
I'm working on your suggestions and starting to get a handle on that smcFunc casting array. Your one example works great...

--- Code: --- $smcFunc['db_insert']('',
'{db_prefix}fpw_pages',
array(
'page_id' => 'int', 'page_title' => 'string-255', 'action' => 'string-255', 'permissions' => 'string-255',
),
$newData['newpage'],
array('page_id')
);
--- End code ---
But what is array('page_id') for? The code works if it's in there or not... Oh wait, I just reread the description of the function, that's the keys right? From function description...

--- Quote ---Keys is supposed to hold the tables key information, only appears to affect sqlite and postrgresql (when using "replace") versions.
--- End quote ---
Do I have to have that in there? If I'm not doing a replace can I leave it out?

Thanks for your help

Navigation

[0] Message Index

[#] Next page

Go to full version