diff options
author | cash <cash.costello@gmail.com> | 2011-11-12 14:28:52 -0500 |
---|---|---|
committer | cash <cash.costello@gmail.com> | 2011-11-16 19:53:04 -0500 |
commit | 11aacb4f048e659d1b86a6ba229438444a186142 (patch) | |
tree | d35da1535860f8883e5c92d3571fa2090890d85a /documentation/examples | |
parent | 08a2fc293a9ecb92caa778d32689b595bee1d68d (diff) | |
download | elgg-11aacb4f048e659d1b86a6ba229438444a186142.tar.gz elgg-11aacb4f048e659d1b86a6ba229438444a186142.tar.bz2 |
added better plugin skeleton and added documentation to some of the examples
Diffstat (limited to 'documentation/examples')
-rw-r--r-- | documentation/examples/actions/basic.php | 22 | ||||
-rw-r--r-- | documentation/examples/actions/manual_tokens.php | 6 | ||||
-rw-r--r-- | documentation/examples/events/advanced.php | 7 | ||||
-rw-r--r-- | documentation/examples/events/all.php | 16 | ||||
-rw-r--r-- | documentation/examples/events/basic.php | 14 | ||||
-rw-r--r-- | documentation/examples/events/emit.php | 7 | ||||
-rw-r--r-- | documentation/examples/events/trigger.php | 11 | ||||
-rw-r--r-- | documentation/examples/plugins/README.txt | 3 | ||||
-rw-r--r-- | documentation/examples/plugins/actions/.gitignore (renamed from documentation/examples/plugins/skeleton/start.php) | 0 | ||||
-rw-r--r-- | documentation/examples/plugins/languages/en.php | 24 | ||||
-rw-r--r-- | documentation/examples/plugins/manifest.xml (renamed from documentation/examples/plugins/skeleton/manifest.xml) | 0 | ||||
-rw-r--r-- | documentation/examples/plugins/manifest_options/manifest.xml | 95 | ||||
-rw-r--r-- | documentation/examples/plugins/start.php | 0 | ||||
-rw-r--r-- | documentation/examples/plugins/views/default/.gitignore | 0 |
14 files changed, 85 insertions, 120 deletions
diff --git a/documentation/examples/actions/basic.php b/documentation/examples/actions/basic.php new file mode 100644 index 000000000..926e11b79 --- /dev/null +++ b/documentation/examples/actions/basic.php @@ -0,0 +1,22 @@ +<?php +/** + * Demonstrates adding an annotation through an action + * + * This action adds a rating annotation to an entity. If this was coming from + * a five-star rating tool, the rating would be a number between 0 and 5. The + * GUID of the entity being rating is also submitted to the action. + */ + +$rating = get_input('rating'); +$guid = get_input('guid'); + +$entity = get_entity($guid); +if (!$entity) { + register_error(elgg_echo('rating:failure')); + forward(REFERER); +} + +$entity->annotate('rating', $rating); + +system_message(elgg_echo('rating:success')); +forward(REFERER); diff --git a/documentation/examples/actions/manual_tokens.php b/documentation/examples/actions/manual_tokens.php deleted file mode 100644 index 8dcf61fb1..000000000 --- a/documentation/examples/actions/manual_tokens.php +++ /dev/null @@ -1,6 +0,0 @@ -<?php - -$ts = time(); -$token = generate_action_token($ts); - -var_dump($ts, $token); diff --git a/documentation/examples/events/advanced.php b/documentation/examples/events/advanced.php index 22a407579..73edea9da 100644 --- a/documentation/examples/events/advanced.php +++ b/documentation/examples/events/advanced.php @@ -1,10 +1,13 @@ <?php +/** + * This snippets demonstrates how returning false changes the normal operation + * of Elgg. + */ elgg_register_event_handler('create', 'object', 'example_event_handler'); -function example_event_handler($event, $type, $params) { +function example_event_handler($event, $type, $object) { // Don't allow any non-admin users to create objects // Returning false from this function will halt the creation of the object. return elgg_is_admin_logged_in(); } - diff --git a/documentation/examples/events/all.php b/documentation/examples/events/all.php index 238178312..0ad02c1d4 100644 --- a/documentation/examples/events/all.php +++ b/documentation/examples/events/all.php @@ -1,17 +1,24 @@ <?php +/** + * If you register an 'all' string for the event name, the handler function will + * be called for all events with that name, regardless of event type. The same + * can be done for the event type argument. Registering 'all' for both + * argyuments results in a handler being called for every event. + */ elgg_register_event_handler('all', 'object', 'example_event_handler'); // This function will be called for any event of type 'object' -function example_event_handler($event, $type, $params) { +function example_event_handler($event, $type, $object) { // check what sort of object is passed - if ($params instanceof ElggObject) { - $subtype = $params->getSubtype(); + if ($object instanceof ElggObject) { + $subtype = $object->getSubtype(); - switch($subtype) { + switch ($subtype) { case 'blog': case 'thewire': case 'pages': + // prevent these object subtypes from being saved or changed return false; default: return true; @@ -21,4 +28,3 @@ function example_event_handler($event, $type, $params) { return true; } - diff --git a/documentation/examples/events/basic.php b/documentation/examples/events/basic.php index 91704e60b..ca2762344 100644 --- a/documentation/examples/events/basic.php +++ b/documentation/examples/events/basic.php @@ -1,13 +1,17 @@ <?php +/** + * This snippet demonstrates how to register for an event. It dumps the + * parameters that the handler receives to the screen. The third argument + * of the handler function is an object that is related to the event. For + * the 'init', 'system' eveny, it is null. + */ elgg_register_event_handler('init', 'system', 'example_event_handler'); -function example_event_handler($event, $type, $params) { +function example_event_handler($event, $type, $object) { var_dump($event); - var_dump($object_type); - var_dump($params); + var_dump($type); + var_dump($object); return true; } - - diff --git a/documentation/examples/events/emit.php b/documentation/examples/events/emit.php deleted file mode 100644 index b917c6dc0..000000000 --- a/documentation/examples/events/emit.php +++ /dev/null @@ -1,7 +0,0 @@ -<?php - -$params = new ElggObject(); -elgg_trigger_event('test', 'example', $params); - -// handlers would be registered by saying -elgg_register_event_handler('test', 'example', 'example_event_handler'); diff --git a/documentation/examples/events/trigger.php b/documentation/examples/events/trigger.php new file mode 100644 index 000000000..6ce3a76f0 --- /dev/null +++ b/documentation/examples/events/trigger.php @@ -0,0 +1,11 @@ +<?php +/** + * These two snippets demonstrates triggering an event and how to register for + * that event. + */ + +$object = new ElggObject(); +elgg_trigger_event('test', 'example', $object); + +// elsewhere a handler could be registered by saying +elgg_register_event_handler('test', 'example', 'example_event_handler'); diff --git a/documentation/examples/plugins/README.txt b/documentation/examples/plugins/README.txt new file mode 100644 index 000000000..9eb04391d --- /dev/null +++ b/documentation/examples/plugins/README.txt @@ -0,0 +1,3 @@ +Plugin Skeleton +========================= + diff --git a/documentation/examples/plugins/skeleton/start.php b/documentation/examples/plugins/actions/.gitignore index e69de29bb..e69de29bb 100644 --- a/documentation/examples/plugins/skeleton/start.php +++ b/documentation/examples/plugins/actions/.gitignore diff --git a/documentation/examples/plugins/languages/en.php b/documentation/examples/plugins/languages/en.php new file mode 100644 index 000000000..35f838560 --- /dev/null +++ b/documentation/examples/plugins/languages/en.php @@ -0,0 +1,24 @@ +<?php +/** + * The core language file is in /languages/en.php and each plugin has its + * language files in a languages directory. To change a string, copy the + * mapping into this file. + * + * For example, to change the blog Tools menu item + * from "Blog" to "Rantings", copy this pair: + * 'blog' => "Blog", + * into the $mapping array so that it looks like: + * 'blog' => "Rantings", + * + * Follow this pattern for any other string you want to change. Make sure this + * plugin is lower in the plugin list than any plugin that it is modifying. + * + * If you want to add languages other than English, name the file according to + * the language's ISO 639-1 code: http://en.wikipedia.org/wiki/List_of_ISO_639-1_codes + */ + +$mapping = array( + 'string:here' => 'Display string here', +); + +add_translation('en', $mapping); diff --git a/documentation/examples/plugins/skeleton/manifest.xml b/documentation/examples/plugins/manifest.xml index e31624432..e31624432 100644 --- a/documentation/examples/plugins/skeleton/manifest.xml +++ b/documentation/examples/plugins/manifest.xml diff --git a/documentation/examples/plugins/manifest_options/manifest.xml b/documentation/examples/plugins/manifest_options/manifest.xml deleted file mode 100644 index baa6cc3fa..000000000 --- a/documentation/examples/plugins/manifest_options/manifest.xml +++ /dev/null @@ -1,95 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<plugin_manifest xmlns="http://www.elgg.org/plugin_manifest/1.8"> - <name>My Plugin</name> - <author>Elgg</author> - <version>1.0</version> - <blurb>A concise description.</blurb> - <description>This is a longer, more interesting description of my plugin, its features, and other important information.</description> - <website>http://www.elgg.org/</website> - <copyright>(C) Elgg 2011</copyright> - <license>GNU General Public License version 2</license> - - <requires> - <type>elgg_version</type> - <version>2009030802</version> - </requires> - - <requires> - <type>elgg_release</type> - <version>1.8</version> - </requires> - - <screenshot> - <description>An example screenshot</description> - <path>graphics/plugin_ss1.png</path> - </screenshot> - - <screenshot> - <description>Another screenshot</description> - <path>graphics/plugin_ss2.png</path> - </screenshot> - - <category>admin</category> - <category>api</category> - - <requires> - <type>php_extension</type> - <name>gd</name> - </requires> - - <requires> - <type>php_ini</type> - <name>short_open_tag</name> - <value>off</value> - </requires> - - <requires> - <type>php_extension</type> - <name>made_up</name> - <version>1.0</version> - </requires> - - <requires> - <type>plugin</type> - <name>fake_plugin</name> - <version>1.0</version> - </requires> - - <requires> - <type>plugin</type> - <name>profile</name> - <version>1.0</version> - </requires> - - <requires> - <type>plugin</type> - <name>profile_api</name> - <version>1.3</version> - <comparison>lt</comparison> - </requires> - - <requires> - <type>priority</type> - <priority>after</priority> - <plugin>blog</plugin> - </requires> - - <conflicts> - <type>plugin</type> - <name>profile_api</name> - <version>1.0</version> - </conflicts> - - <provides> - <type>plugin</type> - <name>profile_api</name> - <version>1.3</version> - </provides> - - <provides> - <type>php_extension</type> - <name>curl</name> - <version>1.0</version> - </provides> - -</plugin_manifest> diff --git a/documentation/examples/plugins/start.php b/documentation/examples/plugins/start.php new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/documentation/examples/plugins/start.php diff --git a/documentation/examples/plugins/views/default/.gitignore b/documentation/examples/plugins/views/default/.gitignore new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/documentation/examples/plugins/views/default/.gitignore |