Difference between revisions of "Cchost/Developers"
Fourstones (talk | contribs) (New page: Category:ccHost Category:ccMixter Category:Developer Category:Software Category:Technology {{cchost_head}} {{lowercase}} = Source Code = * [http://code.creativecommons...) |
(update source repo link) |
||
(10 intermediate revisions by 2 users not shown) | |||
Line 6: | Line 6: | ||
{{cchost_head}} | {{cchost_head}} | ||
{{lowercase}} | {{lowercase}} | ||
+ | =External APIs= | ||
+ | [[cchost/concepts/APIs|APIs]] | ||
= Source Code = | = Source Code = | ||
− | * [ | + | * [https://github.com/cc-archive/cchost Browsable Source Code (Anonymous)] |
− | + | ||
− | |||
**Specifically for ccHost: | **Specifically for ccHost: | ||
*** Log in as administrator on your ccHost installation | *** Log in as administrator on your ccHost installation | ||
*** '''Then''' do your svn update | *** '''Then''' do your svn update | ||
*** Browse to <nowiki>http://your_installation?update=1</nowiki> | *** Browse to <nowiki>http://your_installation?update=1</nowiki> | ||
− | |||
− | |||
− | |||
− | |||
− | |||
=When to make changes to ccHost core= | =When to make changes to ccHost core= | ||
Line 108: | Line 104: | ||
<nowiki>?></nowiki> | <nowiki>?></nowiki> | ||
− | + | =Useful Reading= | |
These pages have important developer information and code samples: | These pages have important developer information and code samples: | ||
Line 117: | Line 113: | ||
*[[cchost/admin/config customize|Configuration files]] | *[[cchost/admin/config customize|Configuration files]] | ||
*[[cchost/Custom Query Templates|Custom Query Templates]] | *[[cchost/Custom Query Templates|Custom Query Templates]] | ||
− | + | *[[Cchost/Developers/Victor's_Dev_Setup|Victor's Dev Setup]] | |
These pages are developer specific: | These pages are developer specific: | ||
Line 125: | Line 121: | ||
*[[cchost/developer/Hooking Page Render|Hooking Page Render]] | *[[cchost/developer/Hooking Page Render|Hooking Page Render]] | ||
*[[cchost/developer/Hooking the User Profile|Hooking the User Profile]] | *[[cchost/developer/Hooking the User Profile|Hooking the User Profile]] | ||
+ | ==Tutorials== | ||
*[[cchost/developer/tutorial/Hooking File Events|Tutorial: Hooking File Events]] | *[[cchost/developer/tutorial/Hooking File Events|Tutorial: Hooking File Events]] | ||
*[[Cchost/developer/tutorial/Replacing the File Verifier|Tutorial: Replacing the File Verifier]] | *[[Cchost/developer/tutorial/Replacing the File Verifier|Tutorial: Replacing the File Verifier]] | ||
*[[Cchost/developer/tutorial/Ultimate Template|Tutorial: Ultimate Template]] | *[[Cchost/developer/tutorial/Ultimate Template|Tutorial: Ultimate Template]] | ||
+ | *[[Cchost/developer/tutorial/Remix_Me|Tutorial: ccMixter's "Remix Me" Feature]] Covers custom templates, embedded custom dataview, 'publicize', popup window, nested templates, feature page | ||
+ | *[[cchost/developer/tutorial/Featured_Playlist|Tutorial: ccMixter's Featured Playlist]] Covers content topics, database insert, command menus, event handling. |
Latest revision as of 03:20, 30 September 2014
Docs Home | Install | Upgrade | Troubleshoot | Customize | Admins | Devs | Content | Query | Templates | Commands | Skins |
Contents
External APIs
Source Code
-
- Specifically for ccHost:
- Log in as administrator on your ccHost installation
- Then do your svn update
- Browse to http://your_installation?update=1
- Specifically for ccHost:
When to make changes to ccHost core
Never.
Seriously
Never.
Oh, that's different. Definitely submit a patch! But before going too far down this road you definitely want to hop on the dev mailing list. If you are shy ask to speak with Victor or Jon in private.
Bugs and Feature Requests
Make sure to use the 'ccHost' category when filing bugs. Also, please use a real email so that we can followup on any bugs posted. Be descriptive when posting and commenting on bugs (every bit counts).
Coding in ccHost
ccHost's Model for a 'Module'
There is no formalized higher level model for a 'module' or 'plugin' in ccHost. The model is the same as PHP: a source file. All files with a .PHP extension that reside in the <local_files>/lib directory will be parsed and executed for every page request to a ccHost installation. Where <local_files> is the name of the directory the administrator specified during installation as to where site customizations reside (also editable from admin/paths)
Because of the automatic loading you should be aware of some performance and timing considerations.
Keep Per Page Execution at a Minimum
You should have no significant code that executes outside of functions. You module will be loaded on each every page (and AJAX) request so (other than registering for ccHost events) you should keep all your code in functions that get called in response to ccHost events.
<? for( $i = 0; $i < 52; $i++ ) { $deck[] = rand() % 52; } // this is bad ?>
Instead of the above, you would do:
<? function start_my_shuffle() { global $deck; for( $i = 0; $i < 52; $i++ ) { $deck[] = rand() % 52; } } // no we only do the shuffle once after ever upload CCEvents::AddHandler( CC_EVENT_UPLOAD_DONE, 'start_my_shuffle' ); ?>
Wait for Initialization
It is rare that you will want to do anything before the environment is fully initialized and we know who the currently logged in user really is.
If you really need to do some calculation on each page hit, register for the 'APP_INIT' event and perform it then:
<? CCEvents::AddHandler( CC_EVENT_APP_INIT, 'my_app_init_func' ); function my_app_init_func() { global $CC_GLOBALS; if( CCUser::IsLoggedIn() ) { $CC_GLOBALS['welcome-message'] = 'Hello ' . CCUser::CurrentUserName() . '!'; } } ?>
Keep Per Page Code Size at a Minimum
If you plan on having a lot of extensibility code it would be wise for performance reasons to consider what has to go into the .PHP files and what can be put into other files (e.g. '.inc') and loaded on demand.
The typical way to handle this is to put the event registrations in the PHP module and the code in a INC file. You can specify a script module in the third parameter of AddHandler. Assuming this file is <local_files>/lib/my_event_hooks.php
<? CCEvents::AddHandler( CC_EVENT_APP_INIT, 'my_app_init_func', dir(__FILE__) . '/my_code.inc' ); ?>
Then you create <local_files>/lib/my_code.inc:
<? function my_app_init_func() { global $CC_GLOBALS; if( CCUser::IsLoggedIn() ) { $CC_GLOBALS['my-welcome-message'] = 'Hello ' . CCUser::CurrentUserName() . '!'; } } ?>
Useful Reading
These pages have important developer information and code samples:
- Customize <--- Always check here first
- Variable dumps
- Static Pages
- Configuration files
- Custom Query Templates
- Victor's Dev Setup
These pages are developer specific:
Tutorials
- Tutorial: Hooking File Events
- Tutorial: Replacing the File Verifier
- Tutorial: Ultimate Template
- Tutorial: ccMixter's "Remix Me" Feature Covers custom templates, embedded custom dataview, 'publicize', popup window, nested templates, feature page
- Tutorial: ccMixter's Featured Playlist Covers content topics, database insert, command menus, event handling.