file:
/src/saInfrastructure/wpOverlay/wp-content/plugins/saW_wp.php,
78 lines,
1867 characters
line numbers
[show]
[hide]
1:<?php
2:/*
3:Plugin Name: saWikipediaWP
4:Plugin URI:
5:Description: This plugin supports a w tag, to link to wikipedia. w w="article-name" puts a hot-linked W image inline.
6:Version: 0.9
7:Author URI: http://omino.com/blog/
8:*/
9:
10:
11:if(!function_exists('add_action')){
12:?><h1>This script only useful from within WordPress</h1><?php
13:
14:return;
15:}
16:
17:if(!$saUtils)
18: include "saUtils_wp.php";
19:
20:
21:// +----------------
22:// | we count on being in the same php invocation for
23:// | possibly multiple posts on the same page,
24:// | and maintaining our state across in globals.
25:$gEmbeds = 1; // bump after each invocation
26:
27:
28:
29:
30:// +--------------------------
31:// | This is the main method -- look for tags
32:// | and go.
33:// | for testing, we can pass in the plugins base...
34:function saWikipediaWP($content,$wpPluginsUrl = "")
35:{
36: global $gEmbeds;
37: $gEmbeds++;
38:
39: $foundCount = 0;
40:
41: $newContent = "";
42:
43: while(strlen($content))
44: {
45: $slug = extractXmlSlug($content,"w");
46: if($slug == NULL)
47: {
48: $trying = 0;
49: break;
50: }
51: $foundCount++;
52:
53: # ok. we have one. Here's my ingenious replacement html.
54: {
55: $articleName = $slug["w"];
56: $articleName2 = preg_replace("! !","_",$articleName);
57: if(!$wpPluginsUrl)
58: $wpPluginsUrl = get_bloginfo('wpurl') . "/wp-content/plugins/";
59: $replacement = <<<EOP
60:<a href="http://wikipedia.org/wiki/$articleName2" title="$articleName on Wikipedia"><img style="border:none" height="7" src="{$wpPluginsUrl}w70.png" /></a>
61:EOP;
62:
63: $content = $slug["_after"];
64: $newContent .= $slug["_before"] . $replacement;
65:
66: }
67: }
68:
69: $newContent .= $content;
70:
71: return $newContent;
72:}
73:
74:# Tell wordpress what kind of a plugin it is
75:add_action('the_content', 'saWikipediaWP');
76:
77:?>
78:
formatted by saShowCode.php