<?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; Footnotes</title>
	<atom:link href="http://stargrads.net/blogs/davinci/tag/footnotes/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>
		<item>
		<title>Using the Ajaxified Expand Post Now plug-in with Rob Miller&#8217;s Footnotes plug-in</title>
		<link>http://stargrads.net/blogs/davinci/2009/08/using-the-ajaxified-expand-post-now-plugin-with-rob-millers-footnotes-plugin/</link>
		<comments>http://stargrads.net/blogs/davinci/2009/08/using-the-ajaxified-expand-post-now-plugin-with-rob-millers-footnotes-plugin/#comments</comments>
		<pubDate>Sat, 01 Aug 2009 04:38:27 +0000</pubDate>
		<dc:creator>davinci</dc:creator>
				<category><![CDATA[★grads.net]]></category>
		<category><![CDATA[programming and technical issues]]></category>
		<category><![CDATA[AEPN]]></category>
		<category><![CDATA[Ajaxified Expand Post NOW]]></category>
		<category><![CDATA[Footnotes]]></category>
		<category><![CDATA[integration]]></category>
		<category><![CDATA[mashup]]></category>
		<category><![CDATA[plug-ins]]></category>
		<category><![CDATA[plugins]]></category>
		<category><![CDATA[Rob Miller]]></category>
		<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://stargrads.net/blogs/davinci/?p=1077</guid>
		<description><![CDATA[
A technical post on how to use the Ajaxified Expand Post NOW plug-in and Rob Miller's Footnotes plug-in for WordPress together.
]]></description>
			<content:encoded><![CDATA[<p>This is a little technical post for anyone who is interested in using the Ajaxified Expand Post NOW plug-in<sup><a class='footnote' id='note-1077-1' href='#footnote-1077-aepn'>[1]</a></sup> and Rob Miller&#8217;s Footnotes plug-in<sup><a class='footnote' id='note-1077-2' href='#footnote-1077-footnotes'>[2]</a></sup> together.  On <a href="http://stargrads.net">this</a> website, I&#8217;m running AEPN version 0.7 beta 7, Footnotes version 1.2.1, and WordPress<sup>&mu;</sup> version 2.8.2, which are the latest versions as of this writing.  </p>
<p>The AEPN plug-in truncates a post and appends an<span id="more-1077"></span> &#8220;[Expand post]&#8221; button, whenever it is displayed other than on a single page by itself.  Clicking on the button fetches and displays the rest of the post.  The Footnotes plug-in should be self-explanatory.</p>
<p>The problem with using these two plug-ins together is that if any citations are made before the fold (i.e., the <code>&lt;!--more--&gt;</code> tag), the corresponding footnotes will appear at the bottom of the (collapsed) post.  When the post is subsequently expanded, those footnotes will appear again at the end of the expansion, so that they are displayed twice.</p>
<p>The fix for this is rather simple.  In the &#8220;footnotes.php&#8221; file, surround the final if-else block with a test to see if a single post is being displayed.  If so, execute the block as before.  Otherwise, return the post&#8217;s content without the accompanying footer.  The code should look like this:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span> is_single<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</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;">strpos</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$content</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'&amp;lt;references /&amp;gt;'</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">===</span> <span style="color: #009900; font-weight: bold;">false</span> <span style="color: #009900;">&#41;</span>
        <span style="color: #b1b100;">return</span> <span style="color: #000088;">$content</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$footer</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">else</span>
        <span style="color: #b1b100;">return</span> <span style="color: #990000;">str_replace</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'&amp;lt;references /&amp;gt;'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$footer</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: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">return</span> <span style="color: #000088;">$content</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>When the AEPN plug-in fetches a post to expand it, it is treated as a single post, and so the footnotes will show up correctly &#8212; once, at the bottom of the expansion.</p>
<p>In the &#8220;ajaxified-expand-post-now.php&#8221; file, add the following lines to the top of the &#8220;getPost&#8221; function:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">global</span> <span style="color: #000088;">$post</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$post</span><span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>ID <span style="color: #339933;">=</span> <span style="color: #000088;">$id</span><span style="color: #339933;">;</span></pre></div></div>

<p>This is needed so that the names for the footnote anchors in the expanded portion of the post are generated correctly.  Citations made before the fold will link to the post&#8217;s single page, whereas citations made after it<sup><a class='footnote' id='note-1077-3' href='#footnote-1077-example'>[3]</a></sup> will link to the footnotes section at the bottom of the expansion, on the current page.</p>
<p>Finally, it may be necessary to use a so-called &#8220;<a href="http://mu.wordpress.org/forums/tags/kses">kses</a> hack&#8221; to prevent the &#8220;ref&#8221; and &#8220;references&#8221; tags needed by the Footnotes plug-in from being stripped by WordPress<sup>&mu;</sup>.  How to do this is beyond the scope of this post.</p>
<p>See also <a href="http://stargrads.net/blogs/davinci/2009/06/using-jsmath-with-wordpress-bbpress-and-wikindx/">this previous post</a> for an example of how the Footnotes plug-in can be used with the <a href="http://wikindx.sourceforge.net/"><span style="font-variant: small-caps">Wikindx</span></a> bibliographical management system to create a bibliographical citation. </p>
<p>&#8211; davinci</p>
<img src="http://stargrads.net/blogs/davinci/?ak_action=api_record_view&id=1077&type=feed" alt="" /><p>Related posts:<ol>
<li><a href='http://stargrads.net/blogs/davinci/2009/09/wikindx-macro-plug-in-for-wordpress/' rel='bookmark' title='Wikindx macro plug-in for WordPress'>Wikindx macro plug-in for WordPress</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>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://stargrads.net/blogs/davinci/2009/08/using-the-ajaxified-expand-post-now-plugin-with-rob-millers-footnotes-plugin/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
	</channel>
</rss>

