MiscMX

Summary: Implement miscellaneous PHP functions by means of Markup Expressions
Version: 2008-09-20
Prerequisites:
Status: Beta
Maintainer: Peter Bowers
Users: +1 (View / Edit)
Categories: Markup Expressions
Download: MiscMX.phpΔ
Discussion: MiscMX-Talk?

Questions answered by this recipe

This section is optional; use it to indicate the types of questions (if any) this recipe is intended to answer.

  • How can I "crypt" text?
  • How can I "hash" something (using sha1, md5, etc.)?
  • How can I "hash_hmac" something (using sha1, md5, etc.)?
  • How can I "crc32" text?
  • How can I encode/decode something into/from base64?
  • How can I find out a valid pagename from some text (makepagename)
  • How can I write PTVs to pages

Description

Implement miscellaneous PHP function by means of Markup Expressions.

Installation & Configuration

  • Download MiscMX.phpΔ and put it in your cookbook.
  • Put the usual include_once("$FarmD/cookbook/MiscMX.php"); line in your config.php.

Notes

Implemented MXes:

cryptRun crypt() on all arguments (imploded with space if there are multiple arguments). (accepts a salt=X or --salt:X option)
hashFirst argument must be a valid algorithm for hash() (md5, sha1, etc.). hash() will be executed on all subsequent arguments (imploded with space if there are multiple arguments). Valid arguments are
-f or --file which says that arguments are a page or a file rather than just text.
--raw which says to do a raw hash
hash_hmacIdentical to hash (above) except for a required --key:"secret" option to set the key.
preg_quoteCalls PHP's preg_quote directly. No WikiSh compatibility mode.
crc32Run crc32() on all arguments (imploded with space if there are multiple arguments). It is appropriately processed with sprint("%u"...).
base64_encodeRun base64_encode on arguments. Note that base64 encoded text often (always?) ends with a double-equals-sign. The PmWiki Markup Expression engine will interpret this as setting an option if you place this value as an argument to another MX. Thus you must be careful to protect the value with quotes, particularly if you are using base64_encode within backquotes or within a nested MX.
base64_decodeRun base64_decode on arguments.
makepagenameRun MakePageName on arguments. Recognizes REFPAGE=group.page if you want a different reference page.
trimRun trim() (or rtrim() with -r or ltrim with -l) on an expression
writeptvWrite one or more PTVs to a page in a specified format. Expects one argument which will be the pagename. Accepts an optional fmt=X to specify (hidden, section, text, deflist) format of the PTV (default=hidden). Other options (specified var=value) will result in those PTVs being written
EXAMPLE: {(writeptv MyGroup.MyPage fmt=hidden myvar=myvalue anothervar="a value with spaces" thirdvar="a value\non 3\nlines")}
NOTE: Requires Toolbox for writeptv to work

MiscMX can be used independently of WikiSh, but if it is included after WikiSh then it will allow additional functionality in a "WikiSh-Compatible" mode. The additional functionality follows:

  • Receiving input from a pipe in wikish (either as a file or as an argument via --xargs)
  • Redirecting output
  • Setting options via -x or --longx or --longx:val
  • Other general WikiSh options

Release Notes

If the recipe has multiple releases, then release notes can be placed here. Note that it's often easier for people to work with "release dates" instead of "version numbers".

  • 2008-09-20 - Added trim. Made writeptv fail silently if no page specified.
  • 2008-09-13 - Added preg_quote, added --salt:X option to crypt MX.
  • 2008-08-21 - Added writeptv.
  • 2008-08-03 - "Releaser's Remorse." I decided sendmail should really be named mailx and should be part of WikiSh. No more sendmail() here in MiscMX.
  • 2008-08-02 - Fixing some function names that were changed in the 2008-07-31 release of Wikish, adding makepagename, adding sendmail
  • 2008-05-13 - Initial Release

See Also

Contributors

Comments

See discussion at MiscMX-Talk?

User notes +1: If you use, used or reviewed this recipe, you can add your name. These statistics appear in the Cookbook listings and will help newcomers browsing through the wiki.