[pmwiki-users] replacing spaces with plusses

Jon Haupt jhaupt at gmail.com
Thu Mar 8 20:47:26 CST 2007


On 3/8/07, Petko Yotov <5ko at free.fr> wrote:
> On Thursday 08 March 2007 16:34, Jon Haupt wrote:
> > On 2/4/07, Jon Haupt <jhaupt at gmail.com> wrote:
> > > I'm trying to create custom page variables that show the wiki title
> > > and the page title with plusses instead of spaces.  In other words,
> > > instead of {$Titlespaced}, I want {$Titleplussed}, with the result
> > > showing PmWiki/DocumentationIndex as Documentation+Index.
> > >
> > > The wiki title part I found to be pretty easy, and I accomplished it
> > > with this code:
> > >
> > > # PlusIt converts all spaces in a string into plusses.
> > > function PlusIt($text) {
> > >  $text = preg_replace('/\s+/', '+', $text);
> > >  return $text;
> > >  }
> > > # page variable
> > > $FmtPV['$WikiTitlePlussed'] = 'PlusIt($GLOBALS["WikiTitle"])';
> > >
> > > However, {$TitlePlussed} is more difficult, or at least I haven't been
> > > able to figure it out.  Can I do something similar in order to put the
> > > contents of {$Titlespaced} through my PlusIt function?  Also, could I
> > > have accomplished the above in an easier way?
> > >
> > > Thanks,
> > >
> > > Jon
> >
> > I never received a response to this message, so I thought I'd resend
> > it.  I still haven't been able to figure out why it's harder to do
> > $TitlePlussed than $WikiTitlePlussed.  If I can get this solved, I can
> > release a useful social bookmarking links recipe.  Thanks,
> >
>
> I am not sure if you can access the title variable this way, but you can have
> a function that will work even for pagelists and any other case, like this:
>
>
> Markup('fmtplus', '>textvar:',"/\\(:fmtplus(.*?):\\)/ie","FmtPlus(\$pagename,
> PSS('$1'))");
> function FmtPlus($pagename, $what){return str_replace(" ","+",trim($what));}
>
> (this is in config.php)
>
> Then, in the page you write:
> (:fmtplus This is a test:)
> will output This+is+a+test
>
> Or in pagelists:
> (:fmtplus {=$Title}:)
>
> Or even this:
> (:title (:fmtplus This is a test:):)
>
> Or [[http://google.com/search?q=(:fmtplus My page title:) | Search Google]]
>
> (for the latter you should probably use urlencode instead of str_replace).
>
> Have fun,
> Petko
>

Thanks very much, Petko.  For my purposes (dynamically creating urls
for social bookmarking links) what I really needed was, as you just
suggested, something like

Markup('urlencodetext', '>textvar:',"/\\(:urlencode
(.*?):\\)/ie","UrlEncodeText(\$pagename, PSS('$1'))");
function UrlEncodeText($pagename, $what){return urlencode($what);}

because then I can do the following to have, for example, a link to
post to del.icio.us:

[[http://del.icio.us/post?url=(:urlencode
{*$PageUrl}:)&title=(:urlencode {*$WikiTitle}:)+:+(:urlencode
{*$Titlespaced}:) | Attach:Site/delicious.png"Save to del.icio.us"]]

and in a pagelist, (:urlencode {=$Titlespaced}:), etc.

Jon



More information about the pmwiki-users mailing list