LiveURL

LiveWhale uses URLs starting with /live (we call them LiveURLs) to manage various API endpoints, whether they are out-of-the-box (/live/news, /live/profiles, etc.) or custom.

You can create your own custom LiveURL plugin to create myschool.edu/live/my-custom-endpoint/ and use it to provide API requests, special feeds or pages, or anything else you can dream up and create.

Creating your own LiveURL plugin

  1. Go to the client modules directory via SFTP (/livewhale/client/modules) and create a new module subdirectory describing the project. For example: /livewhale/client/modules/my_plugins.
    ​2. Then create a subdirectory live/ for that module, which will contain any LiveURL plugins you want to make: /livewhale/client/modules/my_plugins/live.
  2. Next, create a plugin file in the directory created in step 2. If you wish to access your plugin via /live/my_data_feed, then name the file my_data_feed.php. The full path will result in: /livewhale/client/modules/my_plugins/live/my_data_feed.php
  3. Now edit the file in step 3 and write your own custom PHP code. Once you are finished, you will be able to access your plugin at myschool.edu/live/my_data_feed

Note: The LiveURL plugin does not automatically include the CMS application, and therefore does not initially have access to the LiveWhale framework functions. If you need this functionality, then your plugin can load the app: require ‘/path/to/web/root/livewhale/frontend.php’. (For example, if you wanted to use the $_LW->read object to perform database requests against the LiveWhale database.)

Passing argument to your LiveURL plugin

Your LiveURL plugin has access to an array of arguments passed to the request. These are stored in $LIVE_URL[‘REQUEST’].

In the following example, $LIVE_URL[‘REQUEST’] would be an array containing “id” and “1”. You can then have your LiveURL plugin respond to specific commands this way.

http://www.myschool.edu/live/my_data_feed/id/1

Example LiveURL Plugin

/livewhale/client/modules/my_module/live/my_liveurl_plugin.php

<?php
require $_SERVER['DOCUMENT_ROOT'].'/livewhale/nocache.php'; // load LW functions

if (!empty($LIVE_URL['REQUEST'])) { // if valid request
        $request=array_shift($LIVE_URL['REQUEST']); // get command name
        switch($request) {
                case 'example':
                        // This code runs at /live/my_liveurl_plugin/example
                        // Example: Show some saved JSON result from LiveWhale
                        $token = $_LW->getVariable('my_plugin_token');
                        if (!empty($token)) {
                                echo json_encode(['token'=>$token]);
                        } else {
                                echo json_encode([]);
                        }
                        break;
                case 'example2':
                        // This code runs at /live/my_liveurl_plugin/example2
                        // Example: Redirect
                        die($_LW->redirectUrl('/some-other-page'));
                        break;
                case 'example3':
                        // This code runs at /live/my_liveurl_plugin/example3
                        break;
        };
};
exit;

?>

On this page