";
Markup('reflectionserror', ' $ref");
return FALSE;
}
function CacheReflectionsData($ref) {
# typically called as CacheReflectionsData($_SERVER["HTTP_REFERER"]);
global $MDLcachedir, $MDLdiscussion, $MDLcollection, $MDLpointer, $MDLtype;
if (CheckReflectionsUrl($ref)) {
$collection = $MDLcollection;
$pointer = $MDLpointer;
$type = $MDLtype;
$title = "";
$id = "";
$harvest = "http://reflections.mndigital.org/cdm4/item_viewer.php?CISOROOT=/$collection&CISOPTR=$pointer";
$link = "http://reflections.mndigital.org/cdm4/$type.php?CISOROOT=/$collection&CISOPTR=$pointer";
$cachefile = "$MDLcachedir/$collection/$collection-$pointer.xml";
MDLerror("Cache file is:
$cachefile");
MDLerror("hm");
if (!is_readable($cachefile)) {
// ini_set('auto_detect_line_endings', '1'); /* broke in Oct 2008, not sure why line endings changed inside the +++ content +++ area */
MDLerror("opening file");
if ($handle = fopen($harvest,"r")) {
# we look for the title in the src of an image link to a getimage.exe
# $pattern = '/getimage\.exe.*title="([^"]*)"/';
# we look for the title in the headline of the item view page
$pattern = '
';
while (!feof($handle)) {
$buffer = fgets($handle);
# if (preg_match($pattern, $buffer, $matches)) {
# $title = $matches[1];
# break;
# }
if (stripos($buffer, $pattern) !== false) {
$pattern = ' | ';
while (!feof($handle)) {
$buffer = fgets($handle);
if (stripos($buffer, $pattern) !== false) {
break 2;
}
$title = $title . $buffer;
}
break;
}
}
MDLerror("closing file");
fclose($handle);
} else {
MDLerror("could not open the referrer:
$harvest");
return FALSE;
}
$xml = new SimpleXMLElement("");
$xml->addChild("collection", urlencode($collection));
$xml->addChild("pointer", urlencode($pointer));
$xml->addChild("target", urlencode($link));
$xml->addChild("type", urlencode($type));
$xml->addChild("title", urlencode(trim($title)));
$xml->addChild("imageurl", urlencode("http://reflections.mndigital.org/cgi-bin/thumbnail.exe?CISOROOT=/$collection&CISOPTR=$pointer&SILLY=.jpg"));
$xml->addChild("mdlid", urlencode($id));
if (!WriteFile($cachefile, $xml->asXML())) {
MDLerror("could not write to cache:\n $cachefile");
return FALSE;
}
}
MDLerror("done with readability");
return MakePageName("","$MDLdiscussion.$collection-$pointer");
}
MDLerror("could not find collection and pointer in:
$ref");
return FALSE;
}
function ReadFromCache($collection, $pointer) {
global $MDLcachedir;
MDLerror("$MDLcachedir/$collection/$collection-$pointer.xml");
return FALSE;
return simplexml_load_file("$MDLcachedir/$collection/$collection-$pointer.xml");
}
function EscapeQuotes($text) {
# if there are quotes, we need them escaped
# in this case, we just turn them to single quotes
return str_replace('"', "'", $text);
}
function SetMarkup() {
# SetMarkup is a very PmWiki-centric function
# It basically creates some wiki-markup syntax so that terms like (:reflectionsTitle:)
# can be replaced by the actual title of an item. How this markup gets used depends on
# the pages (and headers or footers) we create in the wiki itself.
global $ReflectionsTitle, $ReflectionsThumbnail, $ReflectionsLinkedThumbnail,
$ReflectionsTarget, $ReflectionsType, $ReflectionsID,
$ReflectionsCollection, $ReflectionsPointer, $Conditions;
Markup('reflectionstitle', ' $MDLcachedir/$collection/$collection-$pointer.xml");
return FALSE;
}
SDV($ReflectionsTitle, urldecode($xml->title));
SDV($ReflectionsTarget, urldecode($xml->target));
SDV($ReflectionsThumbnail, urldecode($xml->imageurl));
SDV($ReflectionsLinkedThumbnail,'');
SDV($ReflectionsType, urldecode($xml->type));
SDV($ReflectionsID, urldecode($xml->mdlid));
SDV($ReflectionsCollection, $collection);
SDV($ReflectionsPointer, $pointer);
SetMarkup();
return TRUE;
}
if (!defined('PmWiki')) {
# this is just used as part of testing this code outside the context of PmWiki
echo "hi\n";
if ($pagename = CacheReflectionsData("http://reflections.mndigital.org/cdm4/item_viewer.php?CISOROOT=/mhs&CISOPTR=503")) {
echo "$pagename\n";
} else {
echo "false\n";
}
if (DefineReflectionsMarkup("http://views.mndigital.org/Discuss/Mhs-503")) {
echo "Title=$ReflectionsTitle\n Thumb=$ReflectionsThumbnail\n LThumb=$ReflectionsLinkedThumbnail\n Target=$ReflectionsTarget\n Type=$ReflectionsType\n ID=$ReflectionsID\n Coll=$ReflectionsCollection\n Ptr=$ReflectionsPointer\n";
} else {
echo "false\n";
}
echo $MDLerr;
}