Vivvo URL Handlers in General

In Vivvo URL Routing is handled by segment of the framework called URL Manager, and plays a very important role in the system.

URL Handlers are a small code snippets called by URL Manager when certain URL is invoked. They are being executed before anything else in Vivvo. We can therefore compare URL Handlers in Vivvo with .htaccess and PHP paradigm - before each action is actually executed, URL Handler checks configuration table for the handler, and if the handler exists the system executes this handler prior to executing actual action.

Each URL handlers consist of two parts - URL_HANDLER and CONTENT_HANDLER, where content_handler is optional.

  • url_handler is invoked by URL Manager and checks URL validity, sets up the system parameters, extracts params from URL (article_id, category_id, etc.)
  • content_handler is invoked by Site Manager and processes the current state of the system (executes specific action).

Each URL Handler must be registered in Vivvo configuration storage before it can be used.

Example

You can find default Vivvo URL handlers in /lib/vivvo/url_handlers/ folder, feel free to analyze them.

This is an example of URL Handler, for Vivvo's Form Builder plug-in. For those having the plugin, the actual handler can be found in /plugins/form_builder/form_builder_url_handler.php.

	function form_builder_url_handler(&$sm, $url_array){
		$um =& $sm->get_url_manager();
		require_once(dirname(__FILE__) . '/form_builder.class.php');
		$form_list =& new FormBuilderForms_list($sm);
		$form =& $form_list->get_form_by_url($url_array[0]);
		if ($form) {
			return array('url_module' => $url_array[0], 'search_fid' => $form->id);
		}
		return false;
	}
	function form_builder_content_handler(&$sm){
		$um =& $sm->get_url_manager();
		$sm->set_theme();
		$sm->_template->set_template_file(VIVVO_FS_ROOT . VIVVO_TEMPLATE_DIR . 'frame/default.tpl');
		$output = $sm->get_module_output('box_form', array('search_fid' => $um->get_param('search_fid')), $sm->_template);
		$sm->_template->assign('PAGE_CONTENT', strval($output));
	}

Default URL Handlers

List of predefined URL Handlers available by default that cover all the standard needs. You can develop and register own URL handler for any specific task at any point. Standard URL handlers mentioned here are located in /lib/vivvo/url_handlers/ directory.

  
  * Archive articles search page (http://www.example.com/archive/<year>/<month>/<day>)
  * Date page (http://www.example.com/date/<year>/<month>/<day>)
  * Authors page (http://www.example.com/author) Example: http://www.example.com/author/<author_name>
  * Tags page (http://www.example.com/tag) Example: Page for single tag: http://www.example.com/tag/<tag_name>
  * Syndication page (http://www.example.com/feed) Example: Page for main RSS: http://www.example.com/feedindex.1.rss)
  * Search page (http://www.example.com/author/search.html)
  * Registration page (http://www.example.com/login.html)
  * Vivvo version (http://www.example.com/version.html)
  * Image code for CAPTCHA (http://www.example.com/imagecode.html)
  * Cron (http://www.example.com/cron_image.html)
  * User control panel page (http://www.example.com/usercp.html)
  * Sitemap (http://www.example.com/sitemap.xml)

Additional URL handlers for various output formats

Developing Custom URL Handlers

In this example, we shall make our own my_url_handler.php file (i.e. inside Vivvo root). We will keep our custom URL handler in this file.

Making URL handler

The purpose of this example is to make url handler for existing box `box_xml_grabber`

function my_url_url_handler(&$sm, $url_array){
	return array('url_module' => 'my_url.html');
}
function my_url_content_handler(&$sm){
	$template =& $sm->get_template();
	$template->set_template_file(VIVVO_FS_TEMPLATE_ROOT . VIVVO_TEMPLATE_DIR . 'frame/default.tpl');
	$content_template = new template($sm, $template);
	$content_template->set_template_file(VIVVO_FS_TEMPLATE_ROOT . VIVVO_TEMPLATE_DIR . 'box/metalica_top_tracks.tpl');
	$template->assign('PAGE_CONTENT', $content_template->get_output());
}

Main method you need to define in my_url_content_handler function. This method will be called when you use url http://www.example.com/my_url.html.

Create new template file VIVVO_ROOT/VIVVO_TEMPLATE_DIR/box/metalica_top_tracks.tpl and put this content:

<vte:box module="box_xml_grabber">
    <vte:params>
        <vte:param name="url" value="http://ws.audioscrobbler.com/1.0/artist/Metallica/toptracks.xml" />
    </vte:params>
    <vte:template>
        <div class="box">
            <div class="box_title_holder">
                <div class="box_title">
                    <vte:foreach item="attr" from="{xml_data[_attributes]}"><vte:value select="{attr}" /></vte:foreach> @ last.fm
                </div>
            </div>
            <div class="box_body">
                <div class="box_content">
                    <ul>
                        <vte:foreach item="track" from="{xml_data[track]}" loop="10">
                            <li><vte:value select="{track[name]}" /> (<vte:value select="{track[reach]}" />)</li>
                        </vte:foreach>
                    </ul>
                </div>
            </div>
        </div>
    </vte:template>
</vte:box>

You can do pretty much anything with this in your URL handler.

 
devdoc/css.txt · Last modified: 2010/05/05 17:08 by damir
 
Except where otherwise noted, content on this wiki is licensed under the following license:CC Attribution-Noncommercial-Share Alike 3.0 Unported
Recent changes RSS feed Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki