Adding /Editing / Deleting existing code using an install script in PHP - php

I have wanted to create a PBBG creator. (Primarily text based games) However, I couldn't think of a system that efficiently allowed people to have the base code, then install modules into the game adding new features.
For example, the base code would consist of a simple home page and bare bones admin panel. Then you would install a registration module which would add new code and new database tables and a login module that would use the registration module's tables. Then from there you could install a Stats Module adding Health, Mana, etc., that would add more columns in the database for users. This would go on till you had a fully operating game made up of several different modules made by several different people.
What I want to know is if this idea is a good one. What are some issues that might appear? And how would I go about making it easy to add, edit, and delete code. Like if a Combat Module had a Module that modified the combat system, how would I go about determining what to change from an install script?
Also, are there any other open source projects using this system I can study to grasp the idea better.
I hope I explained everything well enough, if not please let me know so I can correct that. :)
Thanks!

It seems like you're describing code generation. If your question, then, is whether this is a good idea or not, code generation is a widely accepted "pattern" and should not be considered harmful.
Modifying existing generated code would increase complexity significantly, so what you probably want is some sort of intermediate representation of the code between when the user configures the PBBG and when it is generated. The intermediate representation should be a easily-modifiable full description of the system - modifying this would be a lot easier than writing a script to parse existing code and edit that.
Hope this helps, and good luck!

Related

Drupal crud applications

Thanks in advance.
Learning Drupal right now as recommended by many people and I cannot get a straight answer to this question:
What are the steps to setting up a CRUD application using Drupal?
(I'll explain further. But that is the premise.)
Working on an application that will do reporting and help out a small sales company with their prospecting and data analysis. Excel right? nope. Their clients will also be needing to access some of their data live via a webapp, so there will need to be different logins with levels of access (clients will see specific data related to their account, sales people will see their accounts, and management will see everything). Here's the real kicker they would like to eventually make it into a native app for android or IOS.
Originally I was going to build it in Codeigniter... which seemed easier, but it was recommended to me that I could cut down on my workload and utilized the "services" module later to do what I am looking to get done now and in the future.
Ignoring the project, I haven't even been able to figure out how to create a form for inputing data (I was assuming "Webforms"). Have that stored to a database, and then displayed in a sortable table.
I have searched around and can't really find a guide to building a simple CRUD application using Drupal as a CMS. I am totally willing to figure out how to put it together if someone could just tell me what modules/ things I need to do.
Example (INCORRECT)
1) Install these modules: Webform, views, CCK, Webform MySQL Views)
2) Activate the modules
3) Configure _ to interact with a specific database Table
4) Et Cetera
In all fairness, I'm still learning how to use Drupal and Doing CRUD (Create, Read, Update, Delete) type interactions might now be possible. If it isn't possible then I apologize for your reading all the way down.
Cheers + Happy Summer
Make sure you're using Drupal 7 (which has CCK built in). Then create one or more content types for the things people will see. Install Views and use that to build the displays for each role (Views is pretty powerful). You'll need to research which node access module would help you best restrict add/edit/delete privileges.
However, you said CodeIgniter is an option (ignoring the fact that CI is not maintained anymore). Any reason why Drupal was recommended instead of another PHP framework like Silex/Yii/Symfony/ZF2/LAravel? Depending on client needs (and how flexible they are) you may find yourself fighting against how Drupal wants to do certain things. If they eventually want to power more than a website via an API, seems like a non-Drupal solution could be better fit. (Until Drupal 8 is out and changes things up a bit)

Migrating Silverstripe to Wordpress - Change web platforms

I'm going to re-design and develop a new site for my client (they prefer wordpress as the new platform). They have got an existing big site with membership (with paypal), member portfolios and directories (with search) which are largely done manually in php associated with Silverstripe CMS.
I need some directions on how I best target this task with changing platforms from Silverstripe to Wordpress.
1) They want to keep their membership, directories data and migrate it to wordpress without members have to re-enter it again manually, is this possible, how can this be achieved?
2) For their membership, portfolios and directories, is it best to re-use the code, or is it too different between those two platforms? Or shall I search for some plugins to best match it and then manually add extra php code to match the existing site?
Which would be a better approach?
3) I've found some migrating companies who do migrations from Silverstripe to Wordpress with a cost, is the end product as logical as the original site? Or is it better to build it yourself in wordpress?
Anyone had experience of changing platforms, any suggestions are appreciated.
Thank you.
EDIT:
Sorry I've been away, thank you so much for your answers, Colyba, Cam and Zauberfisch, it is hard to choose one to be the answer. A little update, my client is more towards staying with Silverstripe after I used some of your knowledge, thank you.
Now I just found out they have got an offline Miscrosot Access to keep the membership details as well, my first thought was to just use the website and ditch MS Access, but their admin person has been using this MS Access for a long time even before the site was built, so I am just wondering is there anyway to synchronise both data?
I know the SS website membership database and MS Access membership database structures are set up differently, so I am just wondering is there any way to automatically update the offline MS Access membership when the SS website membership database is updated online? so they don't have to double add member details onto the offline MS Access. Any security issues? See question here, any suggestions are appreciated. Thank you very much!
I think what it comes down to is asking the client what the vision of the future or business direction is, also who will be responsible for maintaining the code base once the work is done?
I find WP has a lot of updates that need regular attention otherwise it is common to get hacked. If the client is aware of this and actions those that is good. Also does the business not have any intention of building further custom functionality other than what they currently offer to customers? if not, and the functionally is mostly commodity based stuff then sometimes WP can be the right tool for the job (even though you could do it in SilverStripe too).
However... if you are already on SilverStripe (perhaps an older 2.4 version) you could look at upgrading them to version 3 (assuming you are on 2.4) which has a much more user friendly admin interface (dare I say it more Wordpress-ish in layout) This might be more familiar to your client. If you do go this direction spend some time running your client through how to use the CMS as part of the project. I have found that helped me sell the benefits of SilverStripe when I was working as a freelancer.
SilverStripe will give you a great set of tools for future flexibility of the website (and the business). I usually feel pretty confident that when the business, say in a years time, asks for a very custom new feature to make their customers happy. I know that it can be easily built using SilverStripe's framework and made simple for CMS users to interact with that data through SilverStripe's extendable CMS interface. Also, of consideration is the licensing (we use BSD at SilverStripe), if strategically important and valuable code related intellectual property is being created, BSD allows retention of this while leveraging the SilverStripe platform. See http://www.silverstripe.org/bsd-license
So you can take more than just a technical approach in your discussions with a client.
There was this article which I quite liked http://www.chromatix.com.au/blog/wordpress-vs-silverstripe/ too.
Again, you will want to have a discussion with your client about the business plans going forward to ensure something gets put in place that can cater to those future needs. Sometimes if clients are not well educated about strategically thinking about their site it can lead to plugin bloat (just bolting on any shiny functionality without considering why) and ultimately their WP site falling over in the long term.
People are creatures of habit, they like to stick with what they know and what might have worked before... we just need to be careful not to extrapolate what used to work versus what will give you the flexibility to change in the future given we are in a very dynamic and chaotic business environment :) And particularly given that many IT systems being off the shelf commodities don't give a business any sustained competitive advantage (unique functionality and the capability to build very custom things to align with customer needs however is where business can better compete). If you and your competitor are both on WP you can both simply click a button and get the same features... how are you adding value for your customers if this is the case?
After all, value from information systems is realised through business objectives and making customers happy, and competing in business is about having something unique that others don't.
Hope my ramble helps in your decisions :) Granted I may be perceived as having a bias (after all I am the SilverStripe 'Community Awesomeness Manager' for full disclosure). When I was a freelancer, I have carried out projects in both WP and SS over the years, selecting the right tool for the job while considering the longer term needs of your clients is key. Does your client need a frozen microwave dinner or are they wanting to serve up some fresh home cooked goodness? Both can achieve the objective of being feed ;)
I fully agree with what colymba said in the comments.
what ever the reason may be, it is a bad idea to switch to WordPress with your type of content.
WordPress is a blog system, and its great at it, but doing custom stuff can quickly become rather painful.
Also, as cam pointed out, SilverStripe 3.x has great improvements over SilverStripe 2.x, so if you are still on 2.x, you should consider an update to SilverStripe 3 as alternative to WordPress (updating to SilverStripe also involves some work, as there have been many changes to how SilverStripe works, but its a lot less than migrating to another System)
Even though I strongly discourage your plan of action, I will still attempt to answer your questions (however I have not used WordPress for a complex Site, so I can't really speak to the internal workings of WordPress for this use case):
SilverStripe stores the passwords salted and hashed.
From what I can see WordPress does also salt and hash, but it looks slightly different, you might need to customize the WordPress password hasher to continue using the existing Passwords form SilverStripe.
All other Member data should be possible, just a matter of importing.
But it is for sure that you can't simply export and import your data, the schema of SilverStripe differs quiet a lot from WordPress, so you probably have to write your own import/data migrator.
Again, the architecture and data schema of SilverStripe is quiet different from the one of WordPress, so I am pretty sure you would need to rewrite the major part of your application.
Migration companies usually provide basic migration of standard data (Pages, Files and Users without any special features). your site seems to have a lot of custom features, and thus I am not sure if a company that offers migration will be what you are looking for here.
Plugins ... maybe you find one that does what you need. But the problem with WordPress plugins is that they usually do something, and if you want it slightly different, you are out of luck, so you might loose features that you previously had.
Also, a plugin (eg. for portfolio) does not solve your data migration problem.
overall, I would say its possible to do it.
However it will require advanced programming skills and a deeper understanding of how WordPress works internally.
So I recommend careful consideration before making a decision.

Looking for a easy integration PHP forum

I'm building a website with codeigniter (PHP) and I'm looking for a forum easy to integrate with my current database so users don't have to register twice. Moreover, I need to use the same html head and styles that in my website, placing the forum inside a div of <body>
Could anyone recommend me any simple forum application for my situation? Thanks.
I'm not aware of CI-specific solutions, but I've used a couple times MyBB and I can say it's really easy to integrate anywhere, as (at least in the 1.6 release, I haven't use it for some time) it's structure is easily moddable. I integrated it in a Joomla! website and in a custom one, and in both ways it's just a matter of reading the mybb_users table for access; it's quite a detailed table, so you can find almost anything you need for a registration table, like salt,password,timestamp of registration,email, and so on, so you just need to query that table and you're set.
As for the integration with CI I think the best way would be to place the whole forum folder and access it there; for the header, footer and other website parts you just change the relative forum template (layout are divided into subsets of templates, so you can change it easily and in details) and the user would not notice they are different applications.
You can also try and build a CI library for communicatin with the forum; they don't have an official API, but in functions.php and a couple other files I don't remember now (yes, 1.6 was mostly procedural, hope they have changed it now) you'll find all the relevant MyBB core, so building an API is straightforward; I once built own for Joomla! and was really easy. Moreover, there's This guy who wrote an integration for MyBB which is, in fact, a nice API; I don't know how updated it is, just check, but It's not difficult to port those files to a Codeigniter custom library, in case.
For database integration you're not going to find a forum that uses the same DB architecture as CodeIgnitor. What you can do, however, is alter your PHP registration scripts (for both CodeIgnitor and your forum) to add an entry in both member records.
Depending on your database you can also use Database Triggers to automatically update the other table when one is updated.
As for your layout, anything can be modified. Open source options will be the simplest, so I'd recommend phpBB for simplicity sake.
For more information on Database Triggers in MySQL, see here: http://dev.mysql.com/doc/refman/5.0/en/triggers.html
I would suggest using PHPBB forum or Wordpress with the BuddyPress plug-in.
I'm not quite sure how the integration with your codeigniter would be, but seeing as PHP is open-source, it shouldn't be too hard to crack open and find out.

Converting site to Drupal -- the nightmare has begun

I'm trying to convert site www.mircscripts.org to Drupal, and researching more and more about migration I've been getting more and more confused.
There are various modules that supposidly will help with the migration process, but these are nothing but confusing and all lack in either a. documentation (listen up Migrate module!) or b. only support Drupal 6.
The Migration Module you seem to have to dive into PHP code and create some "mappings" to your old table data and Drupal. First off, I would ideally like a GUI (Table Wizard only supports Drupal 6 it seems, and the superseded Data module only Drupal 6 too). I also want to import data into Drupal and not use "mappings." I want to be able to disable the Migrate module after all the data has been "converted" to be Drupal node compatible.
If you take a look at the site above, you can pretty much see the scale of data, forum, comments, etc and get an idea of how the database tables look, just your usual stuff; users, comments, and more custom stuff like "files" which stores all the different scripts uploaded by users.
Any suggestions on how I would I go about converting the site?
Cheers
Gary
edit: I forgot to mention the site is almost entirely custom made. The code for it looks like my nan on her way to bingo -- a complete mess. There is an interesting bit of code available at http://drupal.org/node/261066 if you scroll down, although I don't feel like doing node_save() 60,000 times for every record, for just one table. It sounds evil.
The migration module comes with an example migration module and some documentation to facilitate content migrations. Dozens of sites have utilized this to achieve migration. It is not a GUI point and click but very flexible and can be tested repeatedly.
I've written my own modules before to do custom migrations prior to this, and its not as bad as it sounds. You just need to know how the schema relates and map it on paper, then pseudocode and test.
For www.dogfish.com, I migrated 12,000 some nodes. For a band site I am trying to relaunch, I have migrated 75,000+ nodes. Both methods I utilized a db connection and cron to get the next X results. I could have also used BatchAPI but that seemed slower.
Migrate module is the way to go.
Take a look at feeds. It's a GUI importer thing that allows you to map fields in a file to objects like nodes.
http://drupal.org/project/feeds
There's nothing evil about node_save over all the rows in your table. That's essentially what any import module should do anyway. I worked on a huge d5 project where we imported millions of nodes that way. It works fine.
Some people have recommended saving to the database directly. Never do that. It's just not the right way to create nodes. Use the Drupal API!
As i have spent years on drupal. I did not see any full fledged module for migration. Its better you start coding, it will save time and that the smart idea :)

When to develop a new drupal module vs. work with what exists?

This can probably apply to other extensible content management systems, but I've been working with Drupal. Specifically I created an image sharing web application whose functionality relied on more original code than Drupal core code. I used the WebForm module and point its forms at Custom Pages with hard coded php to have nodes created programmatically and other strange voodoo.
Just before I was done I realized I perhaps should have just made my own module, or should I have?
Even in retrospect it's difficult to tell.
What do you use to decide when a new module needs to be written and when the functionality you're seeking can just be kludged together from what's available?
I have a strong opinion on this, which is that all custom coding should be done within custom modules, with only one possible exception (see below):
I discern three cases:
Completely new functionality - this obviously calls for a custom module that encapsulates the new functionality. It makes it reusable and can even turn into an 'official' contributed Drupal module, if the functionality meets popular demand.
Tweaking existing functionality - for every site, I immediately setup a blank, custom module (named after the site). All custom code used for tweaking existing functionality (be it from core or contributed modules) happens within this module. That way, all my customizations are cleanly separated, which makes it much easier to update the core or other modules without constantly having to reapply my customizations to the updated code (of course one has to check if the customizations still work after the update and adjust or remove them as needed).
Fixing bugs/adding missing features - this is the possible exception mentioned above. If my changes are just a bug fix or an addition of an obvious, but missing feature, I might just do that within the original code, submitting my changes as a patch to the original module, hoping that they will get incorporated in a future release, thus making my changes obsolete.
In my experience, the 'overhead' of separating the customizations from the original code isn't really an 'overhead', as the 'one-off' tweaks & fixes usually stick around much longer than anticipated, and have a tendency to grow over the lifetime of a site. Having them separated from the start saves a lot off troubles down the road in maintenance, as applying updates & security fixes, as well as extending the tweaks will be much easier.
Make a new module when you want to share or reuse the functionality easily. There is overhead in doing so, so if it's a one-off it's not worth it.
What i prefer doing is a full-on search on drupal.org for any/all modules that have the functionality that I require. I search drupal.org & groups.drupal.org (& maybe even the forums) with that module(s) name to see what other folks are saying about it. Lastly, I always check drupalmodules.com to see what others in the community are saying about it.
If I can't find exactly what I need, I roll out my own module. Plynx is right also, if you plan to reuse the functionality, create a new module IF it's unique enough to not exist yet.

Categories