| 1: | <?php |
| 2: | |
| 3: | /** |
| 4: | * Hello World example module set. |
| 5: | * @package modules |
| 6: | * @subpackage helloworld |
| 7: | * |
| 8: | * This module set is intented to give developers an overview of |
| 9: | * the module system. Most of what it does is silly and consists of printing "Hello |
| 10: | * World" in different ways. You can enable this module by adding it to the modules |
| 11: | * value in the config/app.php file. |
| 12: | */ |
| 13: | |
| 14: | /** |
| 15: | * All requests should flow through the main index.php file of the program. The following |
| 16: | * line insures this file is not loaded directly in the browser. All PHP files should |
| 17: | * start with it. If someone tries to load the file directly it just quits immediately. |
| 18: | */ |
| 19: | if (!defined('DEBUG_MODE')) { die(); } |
| 20: | |
| 21: | /** |
| 22: | * If you need to include additional code this is a good place to do so. Use the APP_PATH constant |
| 23: | * which is an absolute path to the top level directory of the installation: |
| 24: | * |
| 25: | * require APP_PATH.'modules/hello_world/your_file_name.php'; |
| 26: | */ |
| 27: | |
| 28: | /** |
| 29: | * This is an example of a handler module. This one is assigned to the hello_world page identifier |
| 30: | * and will run after user data is loaded (this is done in the setup.php file). It sends a string |
| 31: | * to the output modules for this page called "hello_world_data" |
| 32: | * @subpackage helloworld/handler |
| 33: | */ |
| 34: | class Hm_Handler_hello_world_page_handler extends Hm_Handler_Module { |
| 35: | public function process() { |
| 36: | /** |
| 37: | * This is one of the ways handler modules send data to output modules. By default |
| 38: | * this value is immutable and cannot be overridden by other modules |
| 39: | */ |
| 40: | $this->out('hello_world_data', 'Hello World!'); |
| 41: | } |
| 42: | } |
| 43: | |
| 44: | /** |
| 45: | * This is an output module assigned to the hello_world page identifier (this is done in the setup.php |
| 46: | * file). This looks for the data sent from the Hm_Handler_hello_world_page_handler module and outputs |
| 47: | * it after the content_section_start module |
| 48: | * @subpackage helloworld/output |
| 49: | */ |
| 50: | class Hm_Output_hello_world_page_content extends Hm_Output_Module { |
| 51: | protected function output() { |
| 52: | /** |
| 53: | * $this->format is either HTML5 or AJAX. $this->get() attempts to fetch data sent to the output |
| 54: | * modules by handler modules $this->get has an optional second argument to set a default |
| 55: | * return value if the name is not found. |
| 56: | */ |
| 57: | if ($this->format == 'HTML5' && $this->get('hello_world_data')) { |
| 58: | /** |
| 59: | * $this->trans() will try to find a translation in the user's current langauge for |
| 60: | * the supplied string. It also sanitizes output. If you don't want to translate you |
| 61: | * and just sanitize, use $this->html_safe(). |
| 62: | */ |
| 63: | return '<div class="hwpage">'.$this->trans($this->get('hello_world_data')). |
| 64: | '<br /><a class="hw_ajax_link">AJAX Example</a></div>'; |
| 65: | } |
| 66: | } |
| 67: | } |
| 68: | |
| 69: | /** |
| 70: | * This is an output modules that was assigned to the "home" page id. It outputs after |
| 71: | * the content_section_start core module, and outputs a div with "hello world" as a link |
| 72: | * to the hello world page |
| 73: | * @subpackage helloworld/output |
| 74: | */ |
| 75: | class Hm_Output_hello_world_home_page extends Hm_Output_Module { |
| 76: | protected function output() { |
| 77: | /** |
| 78: | * $this->trans() will try to find a translation in the user's current langauge for |
| 79: | * the supplied string. It also sanitizes output. If you don't want to translate you |
| 80: | * and just sanitize, use $this->html_safe(). |
| 81: | */ |
| 82: | $output = '<div class="hw"><a href="?page=hello_world">'.$this->trans('hello world').'</a></div>'; |
| 83: | return $output; |
| 84: | } |
| 85: | } |
| 86: | |
| 87: | /** |
| 88: | * Another output module, this one is called from an AJAX request in site.js. AJAX requests need |
| 89: | * to use $this->out('name', 'value') to add to the JSON response. They name used must be whitelisted |
| 90: | * in the setup.php file under 'allowed_output'. |
| 91: | * @subpackage helloworld/output |
| 92: | */ |
| 93: | class Hm_Output_hello_world_ajax_content extends Hm_Output_Module { |
| 94: | protected function output() { |
| 95: | $this->out('hello_world_ajax_result', $this->trans('Hello World Again!')); |
| 96: | } |
| 97: | } |
| 98: |