It All Starts Again (or partially)
After coming to a few dead-ends in code i’ve realised how freaken distgusting some of the coding was and how it could be fixed up alot. A var_dump() of one of the main objects in the source resulted in 4,400 lines of text which is far too much. I fixed a little thing in that and reduced significantly by 2/3. That was alot but still not enough and the 4,400 would of been almost 6,000 if the language files were implemented properly too.
Since looking at that i’ve looked at more efficient methods by using patterns such as the Factory or Singleton. These are new to me but still seem like a much better way to do it all, plus I can use more of the PHP5 Object-Orientated features which are sweet.
Previously the way the code worked (and was stupidly done) was that the index page was called and based on the users action (”act=profile” etc) a class file and module were loaded. The module then determined through the users sub-action (”s=friends” etc) what section of code to execute. With this though it worked well initially until when querying something from the database I had use something like $this->sn->db->sql_query() which doesn’t seem necessary. On top of that in the print out for the object $sn, sn had been duplicated so many times it wasn’t funny (maybe 10 times on some pages). Yuck !!
(i’m still pretty newb to coding as this is my learning curve)
After looking around I decided to utilise more of the OOP stuff such as extends etc with some classes. The new way results in probaby have the code and faster loading as there is alot less crap. For the displaying of a page the users action is run through a switch which determines which class to load such as if the action is profile then it’s something like new profile; and there is no need to have all those module files. All stuff needed is then retrieved and manipulated for display then passed back and compiled with the templating system and then displayed on the screen. So it’s now like $controller->compile() and then $controller->display() and all done. The index.php where everything is called from is 1/3 of it’s original size and alot cleaner.
I can barely explain it.
When I can explain it properly i’ll post it.
Peace out.
Query Reduction
Being on a shared host (only at the moment) I have to start thinking of ways to reduce the amount of queries I have to keep the host happy. That means restricting the queries to no more than 50,000 per hour which seems like alot but in reality is barely anything. Just say about an average of 10 queries per page equals about 5000 pages. If there are 200 users on the with active accounts that comes to about 25 pages per user in their session. Thats not including guests though.
From recent code checking i’ve discovered I can save basically 1 query per page for profile access permissions as well as in various other locations. The way it’ll work is that it’ll store your access from your session in your session data and it’ll only need to query your access on your first visit to your profile. This seems that it’ll work well but there are some issues, such as if the user accepts you as a friend. A work-around for that will need to be found before such a thing is implemented and it shouldn’t be so hard.
More to come…
Social Network - Development Pt. 7
Social-Network Version Update: 0.0.5a (alpha)
Only a few minor updates on this version.
Fixes/Improvements
- Redirect on Login (either to previous page or ucp) - needs tweaking
- Homepage Loading Fix
- Request Check Fixed
- Friend Reqesting Fixed (optimized aswell)
- [UCP] - Code Optimization
- [UCP] - Friend Status now shown
- [UCP] - Design Alterations / Improvements
- Tidying up of xHtml and CSS for various pages
Background/Framework
- [Class LOG] - Logging of Errors
Additional Features
- News Page in Content Section
- Added Comment Count
- [UCP] - Blog Posting and Viewing
- [Profile] - Partial: Blog Viewing
The New User Control Panel:

Many many updates will be in the next version. They do not appear in this version as the vast majority of them are still in an incomplete status. The lines of code may only slightly increase although there will be several additions, this is because of more code optimization.
Some modifications to the template system will also be made to reduce un-necessary code in the module files. Urls for profiles and the ucp will also become friendly. Admin view details will also be improved as well as some query reduction.
Peace out.
Current Lines of Code: 9709
Current Version: 0.0.5a (Alpha)