Not logged in. · Lost password · Register
Forum: General Help and Support Plugins RSS
plugin:bureaucracy automatic pagename
Generate sequential page-ID
Avatar
desasta #1
Member since Nov 2011 · 3 posts
Group memberships: Members
Show profile · Link to this post
Subject: plugin:bureaucracy automatic pagename
Hi,

i extended the plugin bureaucracy with an automatic generated pagename based on a defined template.

I implemented the functionality so that it works but there are still some issues (see below).

New autoinc.php in lib/plugins/bureaucracy/fields/
  1. <?php
  2. /* Automatic incremented ID based on a prefix and a @@ as a pattern for
  3. * an automatic increased number.
  4. *
  5. * e.g.: neu.txt
  6. * <form>
  7. * Action template template:bug: bugs :
  8. * Thanks "For submitting the bug"
  9. * Textbox "Description" "/^[^\/:]+$/"
  10. * autoid "BUG-ID" "=BUG-@@" "/^[^\/:]+$/" @
  11. * Submit "Send"
  12. * </form>
  13. *
  14. * with template: start.txt
  15. * ====== @@BUG-ID@@ ======
  16. * @@Description@@
  17. *
  18. * The autoiid field BUG-ID contains a template BUG-@@.
  19. * 'BUG-' is used as prefix for all new pages.
  20. * '@@' is replaced with an incremental number based on existing namespace/directory names.
  21. * e.g. BUG-1, BUG-2, BUG-15 esxist then a new page gets BUG-16 as pagename.
  22. */
  23. class syntax_plugin_bureaucracy_field_autoid extends syntax_plugin_bureaucracy_field {
  24.  
  25.     function render($params, $form) {
  26.         $this->_handlePreload();
  27.         $form->addHidden($params['name'], $this->getParam('value') . '');
  28.         return;
  29.     }
  30.    
  31.     function handle_post($value) {
  32.         if (is_null($value))
  33.           return true;
  34.         // Save pattern
  35.         $this->opt['autoidpattern'] = $value;
  36.         // Set value first to ectract the prefix
  37.         $result = $this->setVal($value);
  38.         // Extract prefix and automatic incremented pagename
  39.         $this->getParam('pagename');
  40.         return $result;
  41.     }
  42.    
  43.     function getParam($name) {
  44.         if (!isset($this->opt[$name]) || $name === 'value' && $this->hidden) {
  45.             return null;
  46.         }
  47.         if ($name === 'pagename') {
  48.             // Pattern e.g. BUG-@@
  49.             $value = $this->getParam('value');
  50.             if (is_null($value)) {
  51.                 return null;
  52.             }
  53.            
  54.             // Extract prefix 'BUG-'
  55.             $prefix = strstr($this->opt['autoidpattern'], "@@", true);
  56.             // Get all directories starting with the prefix in the current namespace               
  57.             global $ID;
  58.             global $conf;
  59.             $ns = cleanID(getNS($ID));
  60.             $dir = utf8_encodeFN(str_replace(':', '/', $ns));
  61.             $data = array();
  62.             $opts2=array();
  63.             $opts2['listdirs'] = true;
  64.             $opts2['listfiles'] = false;
  65.             $opts2['depth'] = 0;
  66.             $opts2['dirmatch'] = "\/" . strtolower($prefix);
  67.             search($data, $conf['datadir'] . '/' . $dir, 'search_universal', $opts2, '', 0);
  68.             // Get highest ID number of found directories
  69.             $maxid = 1;
  70.             foreach($data as $i){
  71.                 $current = substr($i['id'], strlen($prefix));
  72.                 if (!is_null($current) && is_numeric($current))
  73.                   $maxid = max(array($maxid, $current));
  74.             }
  75.             // Construct pagename
  76.             $value = $prefix . ($maxid + 1);
  77.             // Set value to be replaced in template 
  78.             $this->setVal($value);
  79.        
  80.             if (is_null($value)) {
  81.                 return null;
  82.             }
  83.             global $conf;
  84.             if($conf['useslash']) $value = str_replace('/',' ',$value);
  85.             return str_replace(':',' ',$value);
  86.         }
  87.         return $this->opt[$name];
  88.     }
  89.    
  90.    
  91. }


I have some open questions:
1. Is the above code usable and ok? I have no experience with dokuwiki and only limited knowledge with php.
2. How do i disable a resending of the form data on a refresh?
   Currently every refresh creates a new page.
   Redirecting is not possible with header(), because the headers were already sent and a javascript version is dangerous because javascript must be enabled/allowed.
Avatar
andyboeh #2
Member since Sep 2014 · 4 posts
Group memberships: Members
Show profile · Link to this post
Although this is a very old thread, it might be useful to know that I fixed the autoid.php file to be compatible with Ponder Stibbons and sort-of solved the Reload-Problem.

You can find the code in my HG repository: www.aboehler.at/hg/autoid

Regards
Close Smaller – Larger + Reply to this post:
Verification code: VeriCode Please enter the word from the image into the text field below. (Type the letters only, lower case is okay.)
Smileys: :-) ;-) :-D :-p :blush: :cool: :rolleyes: :huh: :-/ <_< :-( :'( :#: :scared: 8-( :nuts: :-O
Special characters:
Go to forum
Imprint
This board is powered by the Unclassified NewsBoard software, 20150713-dev, © 2003-2015 by Yves Goergen
Current time: 2019-02-19, 20:27:44 (UTC +01:00)