<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>davinci’s notebook &#187; regex</title>
	<atom:link href="http://stargrads.net/blogs/davinci/tag/regex/feed/" rel="self" type="application/rss+xml" />
	<link>http://stargrads.net/blogs/davinci</link>
	<description>everything is an experiment</description>
	<lastBuildDate>Mon, 21 Mar 2011 18:31:14 +0000</lastBuildDate>
	<language>fa</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
		<item>
		<title>Wikindx macro plug-in for WordPress</title>
		<link>http://stargrads.net/blogs/davinci/2009/09/wikindx-macro-plug-in-for-wordpress/</link>
		<comments>http://stargrads.net/blogs/davinci/2009/09/wikindx-macro-plug-in-for-wordpress/#comments</comments>
		<pubDate>Mon, 14 Sep 2009 16:20:11 +0000</pubDate>
		<dc:creator>davinci</dc:creator>
				<category><![CDATA[★grads.net]]></category>
		<category><![CDATA[programming and technical issues]]></category>
		<category><![CDATA[Footnotes]]></category>
		<category><![CDATA[macro]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[plug-in]]></category>
		<category><![CDATA[plug-ins]]></category>
		<category><![CDATA[plugin]]></category>
		<category><![CDATA[plugins]]></category>
		<category><![CDATA[regex]]></category>
		<category><![CDATA[regular expression]]></category>
		<category><![CDATA[regular expressions]]></category>
		<category><![CDATA[Rob Miller]]></category>
		<category><![CDATA[WIKINDX]]></category>
		<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://stargrads.net/blogs/davinci/?p=1860</guid>
		<description><![CDATA[
A small plug-in for WordPress, which adds a macro for inserting bibliography information from WIKINDX.
]]></description>
			<content:encoded><![CDATA[<p>In <a href="http://stargrads.net/blogs/davinci/2009/06/using-jsmath-with-wordpress-bbpress-and-wikindx/">this previous post</a>, I had actually made use of a small plug-in I had written for <a href="http://wordpress.org/">WordPress</a>, which creates a macro for pulling bibliographical information from <a href="http://wikindx.sourceforge.net/"><span style="font-variant: small-caps">Wikindx</span></a>, which I use to manage my <a href="http://stargrads.net/bibliography/">bibliography</a>.</p>
<p>The plug-in is rather simple, but since a web search turned up nothing similar (which is kind of surprising), and someone might find it useful, I thought I&#8217;d post it here<span id="more-1860"></span>.</p>
<p>Here is the code for &#8220;wikindx.php&#8221;:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #339933;">&amp;</span>lt<span style="color: #339933;">;</span>?php
<span style="color: #666666; font-style: italic;">/* 
Plugin Name: Wikindx
Plugin URL: http://stargrads.net/blogs/davinci/2009/09/wikindx-macro-plug-in-for-wordpress
Description: Adds a macro to WordPress to insert bibliography information from Wikindx.
Author: D. L. Yonge-Mallo
Version: 1.0
Author URI: http://stargrads.net/blogs/davinci/
*/</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> parse_wikindx<span style="color: #009900;">&#40;</span><span style="color: #000088;">$content</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$WikindxPath</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;http://path.to/wikindx/&quot;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #990000;">preg_match_all</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'#&amp;lt;wikindx( resource=&quot;([ \w]+)&quot;)?(&amp;gt;(.*)&amp;lt;/wikindx&amp;gt;| ?/&amp;gt;)#Usi'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$content</span><span style="color: #339933;">,</span> <span style="color: #000088;">$wikindxs</span><span style="color: #339933;">,</span> PREG_SET_ORDER<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #990000;">count</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$wikindxs</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;</span>gt<span style="color: #339933;">;</span> <span style="color: #cc66cc;">0</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">array</span><span style="color: #009900;">&#41;</span> <span style="color: #000088;">$wikindxs</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$wikindx</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span> <span style="color: #990000;">empty</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$wikindx</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                <span style="color: #000088;">$output</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;ERROR: WIKINDX MISSING RESOURCE ARGUMENT&quot;</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
                <span style="color: #000088;">$resourceId</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$wikindx</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
                <span style="color: #000088;">$string</span> <span style="color: #339933;">=</span> <span style="color: #990000;">file_get_contents</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;<span style="color: #006699; font-weight: bold;">{$WikindxPath}</span>cmsprint.php?action=getResource&amp;amp;id=<span style="color: #006699; font-weight: bold;">{$resourceId}</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$string</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                    <span style="color: #000088;">$array</span> <span style="color: #339933;">=</span> <span style="color: #990000;">unserialize</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">base64_decode</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$string</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                    <span style="color: #000088;">$output</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$array</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$resourceId</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot; ([<span style="color: #006699; font-weight: bold;">{$WikindxPath}</span>index.php?action=resourceView&amp;amp;id=<span style="color: #006699; font-weight: bold;">{$resourceId}</span> details])&quot;</span><span style="color: #339933;">;</span>
&nbsp;
                <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
                    <span style="color: #000088;">$output</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;ERROR: WIKINDX RESOURCE &quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$resourceId</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot; NOT FOUND&quot;</span><span style="color: #339933;">;</span>
                <span style="color: #009900;">&#125;</span>
            <span style="color: #009900;">&#125;</span>
            <span style="color: #000088;">$content</span> <span style="color: #339933;">=</span> <span style="color: #990000;">str_replace</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$wikindx</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$output</span><span style="color: #339933;">,</span> <span style="color: #000088;">$content</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #b1b100;">return</span> <span style="color: #000088;">$content</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
add_filter<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'the_content'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'parse_wikindx'</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">2</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
?<span style="color: #339933;">&amp;</span>gt<span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>Replace &ldquo;<a href="http://path.to/wikindx/">http://path.to/wikindx/</a>&rdquo; in the above with the URL to your installation of <span style="font-variant: small-caps">Wikindx</span>, obviously.  For example, mine is &ldquo;<a href="http://stargrads.net/bibliography/">http://stargrads.net/bibliography/</a>&rdquo;.</p>
<p>Put the file into the &#8220;plugins&#8221; directory on WordPress, or if you are using <a href="http://mu.wordpress.org/">WordPress<sup>&mu;</sup></a>, then into its &#8220;mu-plugins&#8221; directory.</p>
<p>The plug-in creates a new macro &#8220;wikindx&#8221; with one parameter &#8220;resource&#8221;, which can be used inside WordPress posts like this:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #339933;">&amp;</span>lt<span style="color: #339933;">;</span>wikindx resource<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;68&quot;</span> <span style="color: #339933;">/&amp;</span>gt<span style="color: #339933;">;</span></pre></div></div>

<p>Replace &#8220;68&#8243; in the example with the resource ID of the bibliography entry whose information you want.  (This ID can be found in the URL of the resource&#8217;s page on <span style="font-variant: small-caps">Wikindx</span>.)  The result is that the macro is replaced by the bibliographical information for that resource.  For the above example, this would be:</p>
<blockquote><p>R. Cleve, D. Gavinsky, and D. L. Yonge-Mallo, “Quantum Algorithms for Evaluating Min-Max Trees,” in <em>Proc. TQC 2008</em>, Tokyo, Japan, 2008, (<a href="http://stargrads.net/bibliography/index.php?action=resourceView&#038;id=68">details</a>)</p></blockquote>
<p>This plug-in can be used to good effect with <a href="http://robm.me.uk/projects/plugins/wordpress/footnotes">Rob Miller&#8217;s Footnotes plug-in for WordPress</a>, like this:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #339933;">&amp;</span>lt<span style="color: #339933;">;</span>ref name<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;CGMSY08&quot;</span><span style="color: #339933;">&amp;</span>gt<span style="color: #339933;">;&amp;</span>lt<span style="color: #339933;">;</span>wikindx resource<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;206&quot;</span> <span style="color: #339933;">/&amp;</span>gt<span style="color: #339933;">;&amp;</span>lt<span style="color: #339933;">;/</span>ref<span style="color: #339933;">&amp;</span>gt<span style="color: #339933;">;</span></pre></div></div>

<p>The result<sup><a class='footnote' id='note-1860-1' href='#footnote-1860-CGMSY08'>[1]</a></sup> can be seen in the footnote below.</p>
<p>&#8211; davinci 11780</p>
<hr />
<p><b>Update (Sept. 15, 2009):</b> I&#8217;ve added the plug-in to the <a href="http://wordpress.org/extend/plugins/wikindx-macro-plug-in-for-wordpress/">WordPress Plugin Directory</a>.</p>
<img src="http://stargrads.net/blogs/davinci/?ak_action=api_record_view&id=1860&type=feed" alt="" /><p>Related posts:<ol>
<li><a href='http://stargrads.net/blogs/davinci/2009/08/using-the-ajaxified-expand-post-now-plugin-with-rob-millers-footnotes-plugin/' rel='bookmark' title='Using the Ajaxified Expand Post Now plug-in with Rob Miller&#8217;s Footnotes plug-in'>Using the Ajaxified Expand Post Now plug-in with Rob Miller&#8217;s Footnotes plug-in</a></li>
<li><a href='http://stargrads.net/blogs/davinci/2009/09/annotate-with-jarnal-plug-in-module-for-wikindx/' rel='bookmark' title='Annotate With Jarnal Plug-In Module for Wikindx'>Annotate With Jarnal Plug-In Module for Wikindx</a></li>
<li><a href='http://stargrads.net/blogs/davinci/2009/06/using-jsmath-with-wordpress-bbpress-and-wikindx/' rel='bookmark' title='Using jsMath with WordPress, bbPress, and Wikindx'>Using jsMath with WordPress, bbPress, and Wikindx</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://stargrads.net/blogs/davinci/2009/09/wikindx-macro-plug-in-for-wordpress/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

