Please wait, Page is Loading...
 

Usefull function

Summary:Some of my usefull PmWiki functions
Maintainer:Dfolio
Categories:PHP | PmWiki

Description

Miscellanous useFull functions to include to your PmWiki configuration or Cookbook

Let’s note that some of CookBook provided here used/required some of this functions…

getArg($args,$names,$default)

Handle different ParseArgs() variable name

function getArg($args,$names,$default=null){
  if (is_string($names)){
    if (isset($args[$names])) return $args[$names];
    return $default;
  }
  if (is_array($names)){foreach($names as $n){if (isset($args[$n])) return $args[$n];}}
  return $default;
}

Usage

Let see a simple example. Assume you custom your own markup and you want to access to attribute with different name. For example you want to handle the width attributes with the name "width" or just with the letter "w". A solution is to follow the following code:

...
$args = ParseArgs($args);
...
$width=getArg($args,array('width','w'),"120");

PageGetContents($pagename, $auth = 'read')

The PageGetContents() function is used to retrieve the (x)HTML content of a page.

function PageGetContents($pagename, $auth = 'read'){
  global $HandleBrowseFmt, $PageStartFmt, $PageEndFmt, $PageRedirectFmt,$FmtV;
  $page = RetrieveAuthPage($pagename, $auth, true, READPAGE_CURRENT);
  if (!$page) Abort("?cannot read $pagename");
  PCache($pagename,$page);
  if (PageExists($pagename)) $text = @$page['text'];
  else { return ''; }
  $opt['redirect'] = 1; $PageRedirectFmt = '';
  $text = '(:groupheader:)'.@$text.'(:groupfooter:)';
  $FmtV['$PageText'] = MarkupToHTML($pagename, $text, $opt);
  SDV($HandleBrowseFmt,array(&$PageStartFmt, &$PageRedirectFmt, '$PageText',&$PageEndFmt));
  ob_start();
  PrintFmt($pagename,$HandleBrowseFmt);
  return ob_get_clean();
}

To use PageGetContents():

...
$contents = PageGetContents($pagename);
...


« Check Redirect | CookBook | Down »

Commentaire

Remark, suggestion post a comment:

Signer en tant qu'auteur 
Website 

Veuillez indiquer un nom d'auteur, et entrer la valeur du code (limite le spam...). Merci.


  • Add This
  • Add
  • Get
  • Google

default