[pmwiki-users] Link to Pmwiki from Wordpress

Lars Eighner surname at larseighner.com
Fri Dec 16 20:17:20 CST 2011


These are some remarks about putting wiki-like links to a Pmwiki in a
Wordpress blog.

Who is this for:

a. You have to have some skill in the Wordpress theme you use to make this
work.  Don't ask me.

b. This assumes both Pmwiki and the Wordpress blog are on the same server
(file system).  It also assumes some knowledge of Wordpress themes and php. 
In fact, Wordpress does all the heavy lifting, so you don't have to mess
with the Pmwiki at all.

c. Might be instructive if you are a wizard of a different blogging system.

d. Works only on links to pages in wiki.d; not suitable for admin-type
tasks.  Will not work with action, attr, etc.  string (no
  ?action=source, etc.)

e. This may not be workable if you use the Wordpress editor-for-dummies, but
if you use the raw html plugin and regularly compose in html this should
work well for you.

Long lines are broken with \ here for mail. \ means skip the new line and
all following white space characters.

What it does:

Changes the title and styling of links to your Pmwiki depending upon whether
the linked page exists.  This may (depending on how you style the links)
make links to wiki pages that do not exist not look like links, but the
links will still be functional so someone with edit permissions can still
create the page (possibly after logging in).

What failed:

Attempts to do this with the whole body of finished Wordpress pages have met
with miserable failure.  It needs to be done on the level of entry contents.

This does not permit the raised ? in links to non-existent pages since that
cannot be done by html attributes or style.

Further investigation:

How to do something of the sort if Wordpress and Pmwiki are not on the same
file system (different servers).

Steps:

1. Links to the Pmwiki in the Wordpress blog must have a title beginning
with a keyword. The keyword used here is xxxwiki.

example: <a title="xxxwiki link" href="http://mypmwikiurl/Main/foobar/">

The title attribute must come before the href attribute, the attributes must
be double quoted, and anything between the title and the href will be lost.
There must be no spaces in title="<keyword>. Rest of the title will be lost.

I have no idea how to do this with the Wordpress editor-for-dummies, but it
isn't difficult if you use the raw html plugin and compose in html.

2. You must be able to find where the content is inserted in Wordpress pages
where you want wiki-like links to the Pmwiki wiki to work.  This will be
(more than likely) index.php, archive.php, single.php and possibly others. 
Usually this is done with the Wordpress function the_content().  It must be
within THE LOOP.  Something will be substituted for the_content(), but this
must be done after the necessary functions are in place or it will break
Wordpress.

3. add (suitably edited) to functions.php:

(Note: sample links are to an ADULT site.  Don't use/follow them.)

a. for href=\"http://xxxwiki.larseighner.com/pmwiki.php/ substitute
the url of your Pmwiki

b. for /home/users/l/yourusername/public_html/xxxwiki/wiki.d/
substitute the PATH to you wiki.d files ON YOUR SERVER. It may not
look much like this at all.

c. $mylink are attributes for the link if the Pmwiki page does not exist
and if it does exist.  You can edit the titles and styles as you see fit or
add a class attribute for styling in the appropriate Wordpress style sheet.

d. In the callback function, change xxxwiki to whatever keyword will be the
first thing in the title attribute of links to the Pmwiki

e. Of course change eighner in function definitions and calls to whatever
you use to identify your user functions in Wordpress.

function eighner_acallback($matches)
{

$myurl = $matches[2];
$myfile = str_replace("href=\"http://xxxwiki.larseighner.com/pmwiki.php/", \
 	"",$myurl);
$myfile = rtrim($myfile,'/"');
$myfile = str_replace("/",".",$myfile);
$myfile ='/home/users/l/larseighner.com-28674/public_html/xxxwiki/wiki.d/'\
  . $myfile;

if(!file_exists($myfile)){
$mylink = 'title="A xxxwiki page has not been created yet." rel="nofollow" '.
            'style="text-decoration: none; color: #600;" ' . $matches[2];
}else{
$mylink = 'title="Link to xxxwiki page" '.
            'style="font-weight: bold; text-decoration: underline; color: #060;" ' . $matches[2];
}

return $mylink;

}


function eighner_test_link($bod)
{


$bod = preg_replace_callback("@(title=\"xxxwiki.*?\").*?(href=\".*?\")@s", \
 	"eighner_acallback",$bod);


return $bod;
}


4. Suitably edited, substitute this for the_content() IN THE LOOP in the
places identified in step 2 above.

a. change eighner to whatever you used for the function in function.php
b. the text 'Read the rest etc.' is whatever text should appear where
<!--more--> occurs in the Wordpress entry.

<?php echo eighner_test_link(get_the_content('Read the rest of this \
 	entry »'));  ?>


-- 
Lars Eighner
http://www.larseighner.com/index.html
8800 N IH35 APT 1191 AUSTIN TX 78753-5266




More information about the pmwiki-users mailing list