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] |
02 Aug 2002 22:09:38 | postnuke_official/html/modules/template | pnadmin.php,1.16,1.17 pnuser.php,1.16,1.17 | Mike |
some more changes in template coding |
Update of /home/cvsroot/postnuke_official/html/modules/template In directory ns7.hostnuke.net:/tmp/cvs-serv29966 Modified Files: pnadmin.php pnuser.php Log Message: some more changes in template coding Index: pnadmin.php =================================================================== RCS file: /home/cvsroot/postnuke_official/html/modules/template/pnadmin.php,v retrieving revision 1.16 retrieving revision 1.17 diff -C2 -d -r1.16 -r1.17 *** pnadmin.php 1 Aug 2002 21:10:51 -0000 1.16 --- pnadmin.php 2 Aug 2002 22:09:35 -0000 1.17 *************** *** 42,60 **** // either 'edit' or 'delete' if (!pnSecAuthAction(0, 'Template::Item', '::', ACCESS_EDIT)) { ! // FIXME: should this become pnMLByKey('NO_PERMISSION','Template admin') ? ! $msg = pnML('Not authorized to access #(1) module administration', ! 'Template'); ! pnExceptionSet(PN_SYSTEM_EXCEPTION, 'NO_PERMISSION', ! new SystemException($msg)); ! return; } ! // Get menu variables - it helps if all of the module pages have a standard ! // menu at their head to aid in navigation ! //$menu = template_admin_menu('main'); // Return the template variables defined in this function ! //return array('menu' => $menu); ! return array(); } --- 42,210 ---- // either 'edit' or 'delete' if (!pnSecAuthAction(0, 'Template::Item', '::', ACCESS_EDIT)) { ! return _TEMPLATENOAUTH; } ! // If you want to go directly to some default function, instead of ! // having a separate main function, you can simply call it here, and ! // use the same template for admin-main.pnd as for admin-view.pnd ! // return template_admin_view(); ! ! // Initialise the $data variable that will hold the data to be used in ! // the blocklayout template, and get the common menu configuration - it ! // helps if all of the module pages have a standard menu at the top to ! // support easy navigation ! $data = template_admin_menu(); ! ! // Specify some other variables used in the blocklayout template ! $data['welcome'] = pnML('Welcome to the administration part of this Example module...'); // Return the template variables defined in this function ! return $data; ! ! // Note : instead of using the $data variable, you could also specify ! // the different template variables directly in your return statement : ! // ! // return array('menutitle' => ..., ! // 'welcome' => ..., ! // ... => ...); ! } ! ! /** ! * view items ! */ ! function template_admin_view() ! { ! // Get parameters from whatever input we need. All arguments to this ! // function should be obtained from pnVarCleanFromInput(), getting them ! // from other places such as the environment is not allowed, as that makes ! // assumptions that will not hold in future versions of PostNuke ! $startnum = pnVarCleanFromInput('startnum'); ! ! // Initialise the $data variable that will hold the data to be used in ! // the blocklayout template, and get the common menu configuration - it ! // helps if all of the module pages have a standard menu at the top to ! // support easy navigation ! $data = template_admin_menu(); ! ! // Initialise the variable that will hold the items, so that the template ! // doesn't need to be adapted in case of errors ! $data['items'] = array(); ! ! // Specify some labels for display ! $data['namelabel'] = pnVarPrepForDisplay(_TEMPLATENAME); ! $data['numberlabel'] = pnVarPrepForDisplay(_TEMPLATENUMBER); ! $data['optionslabel'] = pnVarPrepForDisplay(_TEMPLATEOPTIONS); ! $data['pager'] = ''; ! ! // Security check - important to do this as early as possible to avoid ! // potential security holes or just too much wasted processing ! if (!pnSecAuthAction(0, 'Template::', '::', ACCESS_EDIT)) { ! // Fill in some status variable to be shown in the blocklayout template ! $data['status'] = _TEMPLATENOAUTH; ! // Return the template variables defined in this function ! return $data; ! } ! ! // Load API. Note that this is loading the user API, that is because the ! // user API contains the function to obtain item information which is the ! // first thing that we need to do. If the API fails to load an appropriate ! // error message is posted and the function returns ! if (!pnModAPILoad('template', 'user')) { ! // Fill in the status variable with the status to be shown ! $data['status'] = _LOADFAILED; ! // Return the template variables defined in this function ! return $data; ! } ! ! // The user API function is called. This takes the number of items ! // required and the first number in the list of all items, which we ! // obtained from the input and gets us the information on the appropriate ! // items. ! $items = pnModAPIFunc('template', ! 'user', ! 'getall', ! array('startnum' => $startnum, ! 'numitems' => pnModGetVar('template', ! 'itemsperpage'))); ! ! // The return value of the function is checked here, and if the function ! // failed then an appropriate message is posted here. Note that if the ! // API function gave an error, then it should raise an exception that ! // you can handle here... ! if ($items == false) { ! // Throw back any system exceptions (e.g. database failure) ! if (pnExceptionMajor() == PN_SYSTEM_EXCEPTION) { ! return; // throw back ! } ! // Handle the user exceptions yourself ! $data['status'] = pnML('No items available'); ! // Possibly handle different exception IDs in specific ways : ! // if (pnExceptionId() == 'BAD_PARAM') { ! // /* do something */ ! // } elseif (pnExceptionId() == 'NO_PERMISSION') { ! // /* do something else */ ! // } elseif (pnExceptionId() == 'MyException1') { ! // /* do some other thing */ ! // } else { ! // /* default handling */ ! // } ! // Get the information about the exception (in HTML or string format) ! // $reason = pnExceptionValueHTML(); ! $reason = pnExceptionValueString(); ! if (!empty($reason)) { ! $data['status'] .= '<br /><br />'. pnML('Reason') .' : '. $reason; ! } ! // Free the exception to tell PostNuke that you handled it ! pnExceptionFree(); ! // Return the template variables defined in this function ! return $data; ! } ! ! // Check individual permissions for Edit / Delete ! // Note : we could use a foreach ($items as $item) here as well, as ! // shown in pnuser.php, but as an example, we'll adapt the $items array ! // 'in place', and *then* pass the complete items array to $data ! for ($i = 0; $i < count($items); $i++) { ! $item = $items[$i]; ! if (pnSecAuthAction(0, 'Template::', "$item[name]::$item[tid]", ACCESS_EDIT)) { ! $items[$i]['editurl'] = pnModURL('template', ! 'admin', ! 'modify', ! array('tid' => $item['tid'])); ! } else { ! $items[$i]['editurl'] = ''; ! } ! $items[$i]['edittitle'] = pnML('Edit'); ! if (pnSecAuthAction(0, 'Template::', "$item[name]::$item[tid]", ACCESS_DELETE)) { ! $items[$i]['deleteurl'] = pnModURL('template', ! 'admin', ! 'delete', ! array('tid' => $item['tid'])); ! } else { ! $items[$i]['deleteurl'] = ''; ! } ! $items[$i]['deletetitle'] = pnML('Delete'); ! } ! ! // Add the array of items to the template variables ! $data['items'] = $items; ! ! // Specify some labels for display ! $data['namelabel'] = pnVarPrepForDisplay(_TEMPLATENAME); ! $data['numberlabel'] = pnVarPrepForDisplay(_TEMPLATENUMBER); ! $data['optionslabel'] = pnVarPrepForDisplay(_TEMPLATEOPTIONS); ! ! // TODO : add a pager (once it exists in BL) ! $data['pager'] = ''; ! ! // Return the template variables defined in this function ! return $data; ! ! // Note : instead of using the $data variable, you could also specify ! // the different template variables directly in your return statement : ! // ! // return array('items' => ..., ! // 'namelabel' => ..., ! // ... => ...); } *************** *** 66,88 **** function template_admin_new() { // Security check - important to do this as early as possible to avoid // potential security holes or just too much wasted processing ! if (!pnSecAuthAction(0, 'Template::Item', '::', ACCESS_ADD)) { ! $msg = pnML('Not authorized to add new #(1) items', ! 'Template'); ! pnExceptionSet(PN_SYSTEM_EXCEPTION, 'NO_PERMISSION', ! new SystemException($msg)); ! return; } ! // Get menu variables - it helps if all of the module pages have a standard ! // menu at their head to aid in navigation ! //$menu = template_admin_menu('main'); ! // Return the template variables defined in this function ! return array('authid' => pnSecGenAuthKey(), ! 'namelabel' => pnVarPrepForDisplay(_TEMPLATENAME), ! 'numberlabel' => pnVarPrepForDisplay(_TEMPLATENUMBER), ! 'addbutton' => pnVarPrepForDisplay(_TEMPLATEADD)); } --- 216,244 ---- function template_admin_new() { + // Initialise the $data variable that will hold the data to be used in + // the blocklayout template, and get the common menu configuration - it + // helps if all of the module pages have a standard menu at the top to + // support easy navigation + $data = template_admin_menu(); + // Security check - important to do this as early as possible to avoid // potential security holes or just too much wasted processing ! if (!pnSecAuthAction(0, 'Template::', '::', ACCESS_EDIT)) { ! // Fill in some status variable to be shown in the blocklayout template ! $data['status'] = _TEMPLATENOAUTH; ! // Return the template variables defined in this function ! return $data; } ! // Generate a one-time authorisation code for this operation ! $data['authid'] = pnSecGenAuthKey(); ! ! // Specify some labels for display ! $data['namelabel'] = pnVarPrepForDisplay(_TEMPLATENAME); ! $data['numberlabel'] = pnVarPrepForDisplay(_TEMPLATENUMBER); ! $data['addbutton'] = pnVarPrepForDisplay(_TEMPLATEADD); ! // Return the template variables defined in this function ! return $data; } *************** *** 152,159 **** // function did not succeed then the API function should have already // posted a failure message so no action is required ! if ($tid != false) { ! // Success ! //TODO replace with exception? ! pnSessionSetVar('statusmsg', _TEMPLATECREATED); } --- 308,322 ---- // function did not succeed then the API function should have already // posted a failure message so no action is required ! if ($tid == false) { ! // $msg = pnML('Unable to create #(1) item', ! // 'Template'); ! // pnExceptionSet(PN_SYSTEM_EXCEPTION, 'NO_PERMISSION', ! // new SystemException($msg)); ! // return; ! } else { ! ! // Success ! //TODO replace with no exception? ! pnSessionSetVar('statusmsg', _TEMPLATECREATED); } *************** *** 208,216 **** // error message is posted and the function returns if (!pnModAPILoad('template', 'user')) { ! $msg = pnML('Unable to load #(1) user API', 'Template'); - pnExceptionSet(PN_SYSTEM_EXCEPTION, 'NO_PERMISSION', - new SystemException($msg)); - return; } --- 371,376 ---- // error message is posted and the function returns if (!pnModAPILoad('template', 'user')) { ! return pnML('Unable to load #(1) user API', 'Template'); } *************** *** 225,233 **** if ($item == false) { ! $msg = pnML('Unable to find #(1) item #(2)', 'Template', pnVarPrepForDisplay($tid)); - pnExceptionSet(PN_SYSTEM_EXCEPTION, 'NO_PERMISSION', - new SystemException($msg)); - return; } --- 385,390 ---- if ($item == false) { ! return pnML('Unable to find #(1) item #(2)', 'Template', pnVarPrepForDisplay($tid)); } *************** *** 238,246 **** // do the check if (!pnSecAuthAction(0, 'Template::Item', "$item[name]::$tid", ACCESS_EDIT)) { ! $msg = pnML('Not authorized to modify #(1) item #(2)', 'Template', pnVarPrepForDisplay($tid)); - pnExceptionSet(PN_SYSTEM_EXCEPTION, 'NO_PERMISSION', - new SystemException($msg)); - return; } --- 395,400 ---- // do the check if (!pnSecAuthAction(0, 'Template::Item', "$item[name]::$tid", ACCESS_EDIT)) { ! return pnML('Not authorized to modify #(1) item #(2)', 'Template', pnVarPrepForDisplay($tid)); } *************** *** 366,370 **** * developer * @param 'tid' the id of the item to be deleted ! * @param 'confirmation' confirmation that this item can be deleted */ function template_admin_delete($args) --- 520,524 ---- * developer * @param 'tid' the id of the item to be deleted ! * @param 'confirm' confirm that this item can be deleted */ function template_admin_delete($args) *************** *** 376,382 **** list($tid, $objectid, ! $confirmation) = pnVarCleanFromInput('tid', ! 'objectid', ! 'confirmation'); --- 530,536 ---- list($tid, $objectid, ! $confirm) = pnVarCleanFromInput('tid', ! 'objectid', ! 'confirm'); *************** *** 444,465 **** // Check for confirmation. ! if (empty($confirmation)) { // No confirmation yet - display a suitable form to obtain confirmation // of this action from the user ! // Create output variable - this variable will store all of our output so ! // that we can return it easily when required ! $out = ''; ! // Add menu to output - it helps if all of the module pages have a ! // standard menu at their head to aid in navigation ! $out = template_admin_menu(); ! //Call the appropriate template. Here we do pass arguments into the template ! //TODO fill $args ! $out .= pnModTemplate('template','admin','delete',$args); ! ! // Return the output that has been generated by this function ! return $out; } --- 598,626 ---- // Check for confirmation. ! if (empty($confirm)) { // No confirmation yet - display a suitable form to obtain confirmation // of this action from the user ! // Initialise the $data variable that will hold the data to be used in ! // the blocklayout template, and get the common menu configuration - it ! // helps if all of the module pages have a standard menu at the top to ! // support easy navigation ! $data = template_admin_menu(); ! // Specify for which item you want confirmation ! $data['tid'] = $tid; ! // Add some other data you'll want to display in the template ! $data['confirmtext'] = pnML('Confirm deleting this item ?'); ! $data['itemid'] = pnML('Item ID'); ! $data['namelabel'] = _TEMPLATENAME; ! $data['namevalue'] = pnVarPrepForDisplay($item['name']); ! $data['confirmbutton'] = pnML('Confirm'); ! ! // Generate a one-time authorisation code for this operation ! $data['authid'] = pnSecGenAuthKey(); ! ! // Return the template variables defined in this function ! return $data; } *************** *** 517,602 **** /** - * view items - */ - function template_admin_view() - { - // Get parameters from whatever input we need. All arguments to this - // function should be obtained from pnVarCleanFromInput(), getting them - // from other places such as the environment is not allowed, as that makes - // assumptions that will not hold in future versions of PostNuke - $startnum = pnVarCleanFromInput('startnum'); - - if (!pnSecAuthAction(0, 'Template::', '::', ACCESS_EDIT)) { - $msg = pnML('Not authorized to view #(1) items', - 'Template'); - pnExceptionSet(PN_SYSTEM_EXCEPTION, 'NO_PERMISSION', - new SystemException($msg)); - return; - } - - // Load API. Note that this is loading the user API, that is because the - // user API contains the function to obtain item information which is the - // first thing that we need to do. If the API fails to load an appropriate - // error message is posted and the function returns - if (!pnModAPILoad('template', 'user')) { - $msg = pnML('Unable to load #(1) user API', - 'Template'); - pnExceptionSet(PN_SYSTEM_EXCEPTION, 'NO_PERMISSION', - new SystemException($msg)); - return; - } - - // The user API function is called. This takes the number of items - // required and the first number in the list of all items, which we - // obtained from the input and gets us the information on the appropriate - // items. - $items = pnModAPIFunc('template', - 'user', - 'getall', - array('startnum' => $startnum, - 'numitems' => pnModGetVar('template', - 'itemsperpage'))); - // TODO: error recovery - if (empty($items)) { - $items = array(); - } - - // Get menu variables - it helps if all of the module pages have a standard - // menu at their head to aid in navigation - //$menu = template_admin_menu('modify'); - - // Check individual permissions for Edit / Delete - for ($i = 0; $i < count($items); $i++) { - $item = $items[$i]; - if (pnSecAuthAction(0, 'Template::', "$item[name]::$item[tid]", ACCESS_EDIT)) { - $items[$i]['editurl'] = pnModURL('template', - 'admin', - 'modify', - array('tid' => $item['tid'])); - } else { - $items[$i]['editurl'] = ''; - } - $items[$i]['edittitle'] = pnML('Edit'); - if (pnSecAuthAction(0, 'Template::', "$item[name]::$item[tid]", ACCESS_DELETE)) { - $items[$i]['deleteurl'] = pnModURL('template', - 'admin', - 'delete', - array('tid' => $item['tid'])); - } else { - $items[$i]['deleteurl'] = ''; - } - $items[$i]['deletetitle'] = pnML('Delete'); - } - - // TODO : add pager (once it exists in BL) - // Return the template variables defined in this function - return array('authid' => pnSecGenAuthKey(), - 'namelabel' => pnVarPrepForDisplay(_TEMPLATENAME), - 'numberlabel' => pnVarPrepForDisplay(_TEMPLATENUMBER), - 'optionslabel' => pnVarPrepForDisplay(_TEMPLATEOPTIONS), - 'items' => $items); - } - - /** * This is a standard function to modify the configuration parameters of the * module --- 678,681 ---- *************** *** 604,634 **** function template_admin_modifyconfig() { // Security check - important to do this as early as possible to avoid // potential security holes or just too much wasted processing - if (!pnSecAuthAction(0, 'Template::', '::', ACCESS_ADMIN)) { ! $msg = pnML('Not authorized to modify #(1) configuration settings', ! 'Template'); ! pnExceptionSet(PN_SYSTEM_EXCEPTION, 'NO_PERMISSION', ! new SystemException($msg)); ! return; } ! // Get menu variables - it helps if all of the module pages have a standard ! // menu at their head to aid in navigation ! //$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'), ! 'updatebutton' => pnVarPrepForDisplay(_TEMPLATEUPDATE)); } --- 683,721 ---- function template_admin_modifyconfig() { + // Initialise the $data variable that will hold the data to be used in + // the blocklayout template, and get the common menu configuration - it + // helps if all of the module pages have a standard menu at the top to + // support easy navigation + $data = template_admin_menu(); + // Security check - important to do this as early as possible to avoid // potential security holes or just too much wasted processing if (!pnSecAuthAction(0, 'Template::', '::', ACCESS_ADMIN)) { ! // Fill in some status variable to be shown in the blocklayout template ! $data['status'] = pnML('Not authorized to modify #(1) configuration settings', ! 'Template'); ! // Return the template variables defined in this function ! return $data; } ! // Generate a one-time authorisation code for this operation ! $data['authid'] = pnSecGenAuthKey(); ! ! // Specify some labels and values for display ! $data['boldlabel'] = pnVarPrepForDisplay(_TEMPLATEDISPLAYBOLD); ! $data['boldchecked'] = pnModGetVar('template','bold') ? 'checked' : ''; ! $data['itemslabel'] = pnVarPrepForDisplay(_TEMPLATEITEMSPERPAGE); ! $data['itemsvalue'] = pnModGetVar('template', 'itemsperpage'); ! $data['updatebutton'] = pnVarPrepForDisplay(pnML('Update Configuration')); ! ! // Note : if you don't plan on providing encode/decode functions for ! // short URLs (see pnuserapi.php), you should remove these from your ! // admin-modifyconfig.pnd template ! ! $data['shorturlslabel'] = pnML('Enable short URLs'); ! $data['shorturlschecked'] = pnModGetVar('template','SupportShortURLs') ? ! 'checked' : ''; // Return the template variables defined in this function ! return $data; } *************** *** 670,674 **** pnModSetVar('template', 'bold', $bold); ! if (!isset($itemsperpage)) { $itemsperpage = 10; } --- 757,761 ---- pnModSetVar('template', 'bold', $bold); ! if (!isset($itemsperpage) || !is_numeric($itemsperpage)) { $itemsperpage = 10; } *************** *** 689,719 **** /** ! * Main administration menu (obsolete - now defined directly in templates) */ ! function template_admin_menu($func = '') { ! // Define the different menu links for administration ! $link['new'] = array('url' => pnModURL('template','admin','new'), ! 'title' => _NEWTEMPLATE); ! $link['view'] = array('url' => pnModURL('template','admin','view'), ! 'title' => _VIEWTEMPLATE); ! $link['modifyconfig'] = array('url' => pnModURL('template','admin','modifyconfig'), ! 'title' => _EDITTEMPLATECONFIG); ! // Fill in the links array depending on the current function ! $links = array(); ! foreach ($link as $name => $definition) { ! if ($name == $func) { ! $definition['url'] = ''; ! } ! $links[] = $definition; ! } ! // Fill in the rest of the menu variables ! $menu = array('links' => $links, ! 'linkcount' => count($links), ! 'header' => pnML('Template Administration')); ! // Return the menu array return $menu; } --- 776,832 ---- /** ! * generate the common admin menu configuration */ ! function template_admin_menu() ! { ! // Initialise the array that will hold the menu configuration ! $menu = array(); ! // Specify the menu title to be used in your blocklayout template ! $menu['menutitle'] = pnML('Template Administration'); ! // Specify the menu labels to be used in your blocklayout template ! $menu['menulabel_new'] = _NEWTEMPLATE; ! $menu['menulabel_view'] = _VIEWTEMPLATE; ! $menu['menulabel_config'] = _TEMPLATEMODIFYCONFIG; ! // Preset some status variable ! $menu['status'] = ''; ! // Note : you could also specify the menu links here, and pass them ! // on to the template as variables ! // $menu['menulink_view'] = pnModURL('template','admin','view'); ! ! // Note : you could also put all menu items in a $menu['menuitems'] array ! // ! // Initialise the array that will hold the different menu items ! // $menu['menuitems'] = array(); ! // ! // Define a menu item ! // $item = array(); ! // $item['menulabel'] = _TEMPLATEVIEW; ! // $item['menulink'] = pnModURL('template','user','view'); ! // ! // Add it to the array of menu items ! // $menu['menuitems'][] = $item; ! // ! // Add more menu items to the array ! // ... ! // ! // Then you can let the blocklayout template create the different ! // menu items *dynamically*, e.g. by using something like : ! // ! // <pnt:loop name="menuitems"> ! // <td><a href="&pnt-var-menulink;">&pnt-var-menulabel;</a></td> ! // </pnt:loop> ! // ! // in the templates of your module. Or you could even pass an argument ! // to the admin_menu() function to turn links on/off automatically ! // depending on which function is currently called... ! // ! // But most people will prefer to specify all this manually in each ! // blocklayout template anyway :-) ! ! // Return the array containing the menu configuration return $menu; } Index: pnuser.php =================================================================== RCS file: /home/cvsroot/postnuke_official/html/modules/template/pnuser.php,v retrieving revision 1.16 retrieving revision 1.17 diff -C2 -d -r1.16 -r1.17 *** pnuser.php 2 Aug 2002 16:26:28 -0000 1.16 --- pnuser.php 2 Aug 2002 22:09:35 -0000 1.17 *************** *** 45,49 **** // If you want to go directly to some default function, instead of ! // having a separate main function, you can simply use this : // return template_user_view(); --- 45,50 ---- // If you want to go directly to some default function, instead of ! // having a separate main function, you can simply call it here, and ! // use the same template for user-main.pnd as for user-view.pnd // return template_user_view();
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 |