Note: this list is kept only as a demonstration for CVSNotice. For the latest CVS notices, see the Xaraya and Postnuke sites
View Statistics - Next Notice - Previous NoticeDirectory filter : [ all ] / postnuke_official / html / modules / template [ view in CVS ]
Date | Directory [filter] | File(s) [view] | Author [filter] |
01 Aug 2002 21:10:53 | postnuke_official/html/modules/template | pnadmin.php,1.15,1.16 pninit.php,1.11,1.12 pnuserapi.php,1.7,1.8 | Mike |
add support for short URLs |
Update of /home/cvsroot/postnuke_official/html/modules/template In directory ns7.hostnuke.net:/tmp/cvs-serv5598 Modified Files: pnadmin.php pninit.php pnuserapi.php Log Message: add support for short URLs Index: pnadmin.php =================================================================== RCS file: /home/cvsroot/postnuke_official/html/modules/template/pnadmin.php,v retrieving revision 1.15 retrieving revision 1.16 diff -C2 -d -r1.15 -r1.16 *** pnadmin.php 28 Jul 2002 13:24:12 -0000 1.15 --- pnadmin.php 1 Aug 2002 21:10:51 -0000 1.16 *************** *** 619,627 **** //$menu = template_admin_menu('modifyconfig'); ! $checked = pnModGetVar('template','bold') ? 'checked' : ''; // Return the template variables defined in this function return array('authid' => pnSecGenAuthKey(), 'boldlabel' => pnVarPrepForDisplay(_TEMPLATEDISPLAYBOLD), ! 'boldchecked' => $checked, 'itemslabel' => pnVarPrepForDisplay(_TEMPLATEITEMSPERPAGE), 'itemsvalue' => pnModGetVar('template', 'itemsperpage'), --- 619,631 ---- //$menu = template_admin_menu('modifyconfig'); ! $boldchecked = pnModGetVar('template','bold') ? 'checked' : ''; ! $shorturlschecked = pnModGetVar('template','SupportShortURLs') ? 'checked' ! : ''; // Return the template variables defined in this function return array('authid' => pnSecGenAuthKey(), 'boldlabel' => pnVarPrepForDisplay(_TEMPLATEDISPLAYBOLD), ! 'boldchecked' => $boldchecked, ! 'shorturlslabel' => pnML('Enable short URLs'), ! 'shorturlschecked' => $shorturlschecked, 'itemslabel' => pnVarPrepForDisplay(_TEMPLATEITEMSPERPAGE), 'itemsvalue' => pnModGetVar('template', 'itemsperpage'), *************** *** 640,645 **** // assumptions that will not hold in future versions of PostNuke list($bold, ! $itemsperpage) = pnVarCleanFromInput('bold', ! 'itemsperpage'); // Confirm authorisation code. This checks that the form had a valid --- 644,651 ---- // assumptions that will not hold in future versions of PostNuke list($bold, ! $itemsperpage, ! $shorturls) = pnVarCleanFromInput('bold', ! 'itemsperpage', ! 'shorturls'); // Confirm authorisation code. This checks that the form had a valid *************** *** 668,671 **** --- 674,682 ---- } pnModSetVar('template', 'itemsperpage', $itemsperpage); + + if (!isset($shorturls)) { + $shorturls = 0; + } + pnModSetVar('template', 'SupportShortURLs', $shorturls); // This function generated no output, and so now it is complete we redirect Index: pninit.php =================================================================== RCS file: /home/cvsroot/postnuke_official/html/modules/template/pninit.php,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** pninit.php 28 Jul 2002 13:22:04 -0000 1.11 --- pninit.php 1 Aug 2002 21:10:51 -0000 1.12 *************** *** 118,146 **** // module master category cid and child subcids if(pnModAvailable('categories') && pnModAPILoad('categories', 'admin')) ! { ! $templatecid = pnModAPIFunc('categories', ! 'admin', ! 'create', ! Array('name' => 'examples', ! 'description' => 'Example Categories', ! 'parent_id' => 0)); ! pnModSetVar('template', 'mastercid', $templatecid); ! $templatecategories = array(); ! $templatecategories[] = array('name' => "one", ! 'description' => "description one"); ! $templatecategories[] = array('name' => "two", ! 'description' => "description two"); ! $templatecategories[] = array('name' => "three", ! 'description' => "description three"); ! foreach($templatecategories as $subcat) ! { ! $templatesubcid = pnModAPIFunc('categories', ! 'admin', ! 'create', ! Array('name' => $subcat['name'], ! 'description' => $subcat['description'], ! 'parent_id' => $templatecid)); } - } --- 118,147 ---- // module master category cid and child subcids if(pnModAvailable('categories') && pnModAPILoad('categories', 'admin')) ! { ! $templatecid = pnModAPIFunc('categories', ! 'admin', ! 'create', ! Array('name' => 'examples', ! 'description' => 'Example Categories', ! 'parent_id' => 0)); ! // Note: you can have more than 1 mastercid (cfr. articles module) ! pnModSetVar('template', 'mastercid', $templatecid); ! $templatecategories = array(); ! $templatecategories[] = array('name' => "one", ! 'description' => "description one"); ! $templatecategories[] = array('name' => "two", ! 'description' => "description two"); ! $templatecategories[] = array('name' => "three", ! 'description' => "description three"); ! foreach($templatecategories as $subcat) ! { ! $templatesubcid = pnModAPIFunc('categories', ! 'admin', ! 'create', ! Array('name' => $subcat['name'], ! 'description' => ! $subcat['description'], ! 'parent_id' => $templatecid)); } } *************** *** 152,155 **** --- 153,160 ---- pnModSetVar('template', 'bold', 0); pnModSetVar('template', 'itemsperpage', 10); + + // If your module supports short URLs, the website administrator should + // be able to turn it on or off in your module administration + pnModSetVar('template', 'SupportShortURLs', 0); // Initialisation successful Index: pnuserapi.php =================================================================== RCS file: /home/cvsroot/postnuke_official/html/modules/template/pnuserapi.php,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** pnuserapi.php 1 Aug 2002 15:05:20 -0000 1.7 --- pnuserapi.php 1 Aug 2002 21:10:51 -0000 1.8 *************** *** 290,292 **** --- 290,513 ---- } + /* + * Support for short URLs (user functions) + * + * The following two functions encode module parameters into some + * virtual path that will be added to index.php, and decode a virtual + * path back to the original module parameters. + * + * The result is that people (and search engines) can use URLs like : + * + * - http://mysite.com/index.php/template/ (main function) + * - http://mysite.com/index.php/template/list.html (view function) + * - http://mysite.com/index.php/template/123.html (display function) + * + * in addition to the 'normal' PostNuke URLs that look like : + * + * - http://mysite.com/index.php?module=template&func=display&tid=123 + * + * You can also combine the two, e.g. for less frequently-used parameters : + * + * - http://mysite.com/index.php/template/list.html?startnum=21 + * + * + * Module developers who wish to support this feature are strongly + * recommended to create virtual paths that are 'semantically meaningful', + * so that people navigating in your module can understand at a glance what + * the short URLs mean, and how they could e.g. display item 234 simply + * by changing the 123.html into 234.html. + * + * For older modules with many different optional parameters and functions, + * this generally implies re-thinking which parameters could easily be set + * to some default to cover the most frequently-used cases, and rethinking + * how each function could be represented inside some "virtual directory + * structure". E.g. .../archive/2002/05/, .../forums/12/345.html, ../recent.html + * or .../<categoryname>/123.html + * + * The same kind of encoding/decoding can be done for admin functions as well, + * except that by default, the URLs will start with index.php/admin/template. + * The encode/decode functions for admin functions are in pnadminapi.php. + * + */ + + /** + * return the path for a short URL to pnModURL for this module + * @param $args the function and arguments passed to pnModURL + * @returns string + * @return path to be added to index.php for a short URL, or empty if failed + */ + function template_userapi_encode_shorturl($args) + { + // Get arguments from argument array + extract($args); + + // Check if we have something to work with + if (!isset($func)) { + return; + } + + // Note : make sure you don't pass the following variables as arguments in + // your module too - adapt here if necessary + + // default path is empty -> no short URL + $path = ''; + // if we want to add some common arguments as URL parameters below + $join = '?'; + // we can't rely on pnModGetName() here -> you must specify the modname ! + $module = 'template'; + + // specify some short URLs relevant to your module + if ($func == 'main') { + $path = '/' . $module . '/'; + + // Note : if your main function calls some other function by default, + // you should set the path to directly to that other function + + } elseif ($func == 'view') { + $path = '/' . $module . '/list.html'; + + // we'll add the optional $startnum parameter below, as a regular + // URL parameter + + // you might have some additional parameter that you want to use to + // create different virtual paths here - for example a category name + // if (!empty($cid) && is_numeric($cid)) { + // // use a cache to avoid re-querying for each URL in the same cat + // static $catcache = array(); + // if (pnModAPILoad('categories','user')) { + // if (isset($catcache[$cid])) { + // $cat = $catcache[$cid]; + // } else { + // $cat = pnModAPIFunc('categories','user','getcatinfo', + // array('cid' => $cid)); + // // put the category in cache + // $catcache[$cid] = $cat; + // } + // if (!empty($cat) && !empty($cat['name'])) { + // // use the category name as part of the path here + // $path = '/' . $module . '/' . rawurlencode($cat['name']); + // } + // } + // } + + // if you have some additional parameters that you want to keep as + // regular URL parameters - example for an array : + // if (isset($other) && is_array($other) && count($other) > 0) { + // foreach ($other as $id => $val) { + // $path .= $join . 'other['.$id.']='.$val; + // // change the join character (once would be enough) + // $join = '&'; + // } + // } + + } elseif ($func == 'display') { + // check for required parameters + if (isset($tid) && is_numeric($tid)) { + $path = '/' . $module . '/' . $tid . '.html'; + + // you might have some additional parameter that you want to use to + // create different virtual paths here - for example a category name + // See above for an example... + + } else { + // we don't know how to handle that -> don't create a path here + + // Note : this generally means that someone tried to create a + // link to your module, but used invalid parameters for pnModURL + // -> you might want to provide a default path to return to + // $path = '/' . $module . '/list.html'; + } + + } else { + // anything else that you haven't defined a short URL equivalent for + // -> don't create a path here + } + + // add some other module arguments as standard URL parameters + if (!empty($path) && isset($startnum)) { + $path .= $join . 'startnum=' . $startnum; + } + + return $path; + } + + /** + * extract function and arguments from short URLs for this module, and pass + * them back to pnGetRequestInfo() + * @param $params array containing the different elements of the virtual path + * @returns array + * @return array containing func the function to be called and args the query + * string arguments, or empty if it failed + */ + function template_userapi_decode_shorturl($params) + { + // Initialise the argument list we will return + $args = array(); + + // Analyse the different parts of the virtual path + // $params[1] contains the first part after index.php/template + + // In general, you should be strict in encoding URLs, but as liberal + // as possible in trying to decode them... + + if (empty($params[1])) { + // nothing specified -> we'll go to the main function + return array('main', $args); + + } elseif (preg_match('/^index/i',$params[1])) { + // some search engine/someone tried using index.html (or similar) + // -> we'll go to the main function + return array('main', $args); + + } elseif (preg_match('/^list/i',$params[1])) { + // something that starts with 'list' is probably for the view function + // Note : make sure your encoding/decoding is consistent ! :-) + return array('view', $args); + + } elseif (preg_match('/^(\d+)/',$params[1],$matches)) { + // something that starts with a number must be for the display function + // Note : make sure your encoding/decoding is consistent ! :-) + $tid = $matches[1]; + $args['tid'] = $tid; + return array('display', $args); + + } else { + // the first part might be something variable like a category name + // In order to match that, you'll have to retrieve all relevant + // categories for this module, and compare against them... + // $cid = pnModGetVar('template','mastercid'); + // if (pnModAPILoad('categories','user')) { + // $cats = pnModAPIFunc('categories', + // 'user', + // 'getcat', + // array('cid' => $cid, + // 'return_itself' => true, + // 'getchildren' => true)); + // // lower-case for fanciful search engines/people + // $params[1] = strtolower($params[1]); + // $foundcid = 0; + // foreach ($cats as $cat) { + // if ($params[1] == strtolower($cat['name'])) { + // $foundcid = $cat['cid']; + // break; + // } + // } + // // check if we found a matching category + // if (!empty($foundcid)) { + // $args['cid'] = $foundcid; + // // TODO: now analyse $params[2] for index, list, \d+ etc. + // // and return array('whatever', $args); + // } + // } + + // we have no idea what this virtual path could be, so we'll just + // forget about trying to decode this thing + + // you *could* return the main function here if you want to + // return array('main', $args); + } + + // default : return nothing -> no short URL decoded + } + ?>
View Statistics - Next Notice - Previous Notice
Visit Developer Site - Browse CVS Repository |
Syndicate via backend.rss (max. once per hour please) | Powered by CVSNotice 0.1.3 |