ich hab da ein steiles teil entdeckt:
http://warpedvisions.org/projects/simplelink/
PHP
<?php
# -- WordPress Plugin Interface -----------------------------------------------
/*
Plugin Name: SimpleLink
Plugin URI: http://warpedvisions.org/projects/simplelink/
Description: A simplified linking tool that plays well with Markdown
Version: 0.4
Author: Bruce Alderson
Author URI: http://warpedvisions.org
Changes:
*/
if (isset($wp_version)) {
add_filter('the_content', 'SimpleLink', 5);
add_filter('the_excerpt', 'SimpleLink', 5);
add_filter('the_excerpt_rss', 'SimpleLink', 5);
add_filter('comment_text', 'SimpleLink', 5);
}
function SimpleLink($content) {
return preg_replace_callback("/\[(.*?)\](.|)/",'process_links',$content);
}
function process_links($match) {
// Configuration (to move to DB in a future release)
$SL_site_url = 'http://www.sternengarten.info/garten/';
$SL_amazon_id = '';
$SL_image_real_root = '/home/madmaxx/warpedvisions.org/images/';
$SL_image_web_root = '/images/';
$SL_thumb_prefix = 'thumb-';
$SL_flickr_id = 'warpedvisions';
// open external links in new windows?
$SL_open_in_new = true;
$fulltext = $match[1];
$after = $match[2] or '';
// Ignore markdown tags
if (preg_match("/[\(:\[]/", $after)) // TODO: should by str match (array) instead
return $match[0];
if (preg_match("/^\!\!(.*)/", $fulltext, $parts)) {
// Escaped tag [!!text] (TODO: find a better format)
return "[$parts[1]]$after";
} elseif (preg_match("/^(.*?)\|(.*?)$/i", $fulltext, $parts)) {
// MediaWiki-style external link [url|text]
$text = $parts[2];
$uri = $parts[1];
} elseif (preg_match("/^(http:\/\/|ftp:\/\/|\/)(.*)/", $fulltext, $parts)) {
// MediaWiki-style external link [url] (no text)
$text = $parts[2];
$uri = "$parts[1]$parts[2]";
} elseif (preg_match("/^google: (.*)/", $fulltext, $parts)) {
// Google search [google: search terms]
$text = $parts[1];
$target = strtolower(preg_replace('/[\s-,.\']+/', "+", $text));
$uri = "http://google.de/search?q=$target&";
[B][I][U]} elseif (preg_match("/^gpix: (.*)/", $fulltext, $parts)) {
// Google pix search [gpix: search terms]
$text = $parts[1];
$target = strtolower(preg_replace('/[\s-,.\']+/', "+", $text));
$uri = "http://images.google.com/imghp?q=$target&hl=de&btnG=Bilder-Suche;";
[/U][/I][/B]
} elseif (preg_match("/^foldoc: (.*)/", $fulltext, $parts)) {
// FOLDOC term search [foldoc: search terms]
$text = $parts[1];
$target = strtolower(preg_replace('/[\s-,.\']+/', "+", $text));
$uri = "http://foldoc.doc.ic.ac.uk/foldoc/foldoc.cgi?query=$target&action=Search";
} elseif (preg_match("/^imdb: (.*)/", $fulltext, $parts)) {
// IMDB term search [imdb: search terms]
$text = $parts[1];
$target = strtolower(preg_replace('/[\s-,.\']+/', "\%20", $text));
$uri = "http://imdb.com/find?q=$target;tt=on;nm=on;mx=20";
} elseif (preg_match("/^perldoc: (.*)/", $fulltext, $parts)) {
// Perldoc term search [perldoc: search terms]
$text = $parts[1];
$target = strtolower(preg_replace('/[\s-,.\']+/', "\%20", $text));
$uri = "http://perldoc.com/cgi-bin/htsearch?words=$target&restrict=perl5.8.0";
} elseif (preg_match("/^asin: (.*)/", $fulltext, $parts)) {
// Amazon term search with image thumbnail [asin: search terms]
// (no rel= attribute, as it's just an image based on an asbn)
$target = $parts[1];
$uri = "http://www.amazon.de/exec/obidos/ASIN/$target/$SL_amazon_id";
$text = '<div class="thumb"><img src="http://images.amazon.com/images/P/' .
$target . '.01.MZZZZZZZ.jpg" alt="['.$target.']" /></div>';
// note the div-wrapped thumbnail, allows for special overflow styling
return "<div class='amazon'><a href=\"$uri\">$text</a></div>$after";
} elseif (preg_match("/^here: (.*)/", $fulltext, $parts)) {
// Local term search [here: search terms]
$text = $parts[1];
$target = strtolower(preg_replace('/[\s-,.\']+/', "+", $text));
$uri = "$SL_site_url/index.php?s=$target&submit=Search";
} elseif (preg_match("/^wiki: (.*)/", $fulltext, $parts)) {
// Wiki term search [wiki: search terms]
$text = $parts[1];
$target = ucfirst(strtolower(preg_replace('/[\s-,.\']+/', "_ -", $text)));
$uri = "http://de.wikipedia.org/wiki/$target";
} elseif (preg_match("/^tag: (.*)/", $fulltext, $parts)) {
// Tag search at Technocrati [tag: search terms]
$text = $parts[1];
$target = strtolower(preg_replace('/[\s\-,.\']+/', "%20", $text));
$uri = "http://www.technorati.com/tag/$target";
} elseif (preg_match("/^techno: (.*)/", $fulltext, $parts)) {
// Regular search at Technocrati [techno: search terms]
$text = $parts[1];
$target = strtolower(preg_replace('/[\s\-,.\']+/', "+", $text));
$uri = "http://www.technorati.com/cosmos/search.html?rank=&url=$target";
} elseif (preg_match("/^flickr: (.*?) (.*?) (.*)/", $fulltext, $parts)) {
// Link to flickr images [flickr: picture thumb sizecode]
$picture = $parts[1];
$thumb = $parts[2];
$size = $parts[3];
$align = 'alignleft';
$text = "<a href=\"http://www.flickr.com/photos/$SL_flickr_id/$picture/\"><img class=\"$align\" src=\"http://photos7.flickr.com/{$picture}_{$thumb}_{$size}.jpg\" alt=\"$picture\" /></a>";
return "$text$after";
// Tools ---------- -------------------------------------------------------
} elseif (preg_match("/^image: (.*)/", $fulltext, $parts)) {
// Embed images [image: search terms]
$filename = $parts[1];
$thumbnail = $SL_thumb_prefix . $parts[1];
$alt = strtolower($filename);
$uri = $SL_image_web_root . $filename;
$text = "<img class=\"pic\" src=\"$SL_image_web_root$thumbnail\" alt=\"$alt\" />";
if (file_exists("{$SL_image_real_root}{$filename}") and
file_exists("{$SL_image_real_root}{$thumbnail}")) {
$text = "<img class=\"pic\" src=\"$SL_image_web_root$thumbnail\" alt=\"$alt\" />";
return "<a href=\"$uri\">$text</a>$after";
} elseif (file_exists("$SL_image_real_root$filename")) {
$text = "<img class=\"pic\" src=\"$uri\" alt=\"$alt\" />";
return "$text$after";
} else {
if (_is_author())
$text = <<<UPLOAD
$filename <span class="upload"><form action="/wp-admin/upload.php" method="post" enctype="multipart/form-data">
<input type="file" name="img1" id="img1" size="10" class="uploadform" />
w/thumb <input type="text" name="imgthumbsizecustom" size="4" value="120" /> px
<input type="hidden" name="MAX_FILE_SIZE" value="4194304" />
<input type="hidden" name="thumbsize" value="custom" id="thumbsize_custom" />
<input type="submit" name="submit" value="Upload" />
</form></span>
UPLOAD;
else
$text = '';
return "$text$after";
}
// Handy/stylish tags -------------------------------------------------------
} elseif (preg_match("/^note: (.*)/", $fulltext, $parts)) {
return "<div class=\"note\">$parts[1]</div>$after";
} elseif (preg_match("/^abbr: (.*?) \- (.*)/", $fulltext, $parts)) {
return "<abbr title=\"$parts[2]\" >$parts[1]</abbr>$after";
} elseif (preg_match("/^comment: (.*)/", $fulltext, $parts)) {
return "<div class=\"comment\">$parts[1]</div>$after";
} elseif (preg_match("/^tip: (.*)/", $fulltext, $parts)) {
return "<div class=\"tip\">$parts[1]</div>$after";
} elseif (preg_match("/^warning: (.*)/", $fulltext, $parts)) {
return "<div class=\"warning\">$parts[1]</div>$after";
// DEFAULT ------------------------------------------------------------------
} else {
// Default 'lucky' google search [search terms]
$text = $fulltext;
$target = strtolower(preg_replace('/[\s-,.\']+/', "\%20", $text));
$uri = "http://google.com/search?q=$target&btnI=";
}
$here = str_replace('/', '\/', $SL_site_url);
if (!preg_match("/{$here}/", $url) and $SL_open_in_new)
return "<a rel=\"tag\" target=\"_new\" href=\"$uri\">$text</a>$after";
else
return "<a rel=\"tag\" href=\"$uri\">$text</a>$after";
}
function _is_author() {
global $user_level;
get_currentuserinfo();
if ($user_level > 4) return true;
return false;
}
?>
Alles anzeigen
ich möchte da noch die google-bildersuche einbinden, mit dem code:
PHP
} elseif (preg_match("/^gpix: (.*)/", $fulltext, $parts)) {
// Google pix search [gpix: search terms]
$text = $parts[1];
$target = strtolower(preg_replace('/[\s-,.\']+/', "+", $text));
$uri = "http://images.google.com/imghp?q=$target&hl=de&btnG=Bilder-Suche;";
} elseif (preg_match("/^foldoc: (.*)/", $fulltext, $parts)) {
allerdings lande ich da nicht auf der ergebnisseite.
any sugestions?