You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
185 lines
7.0 KiB
185 lines
7.0 KiB
14 years ago
|
<?php if (!defined('PmWiki')) exit();
|
||
|
/*
|
||
|
Mainly based on PageFeed by Daniel Roesler (diafygi)
|
||
|
http://www.pmwiki.org/wiki/Cookbook/PageFeed
|
||
|
|
||
|
http://fabien.benetou.fr/Wiki/MemoryRecipe
|
||
|
|
||
|
TODO
|
||
|
support the regex syntax function calls as done in groupkeypages.php
|
||
|
test with the W3C that feeds generated are proper
|
||
|
note that if backward compability of files is important the 3 formers can remain empty
|
||
|
but ideally the local/config.php file should be modified
|
||
|
weighting for the composite function should read local PTV
|
||
|
if unsset then use the default behavior
|
||
|
make the content of description easier to change
|
||
|
create a variable at the head of the script
|
||
14 years ago
|
option to regenerate the fields
|
||
|
since a specified date or the first found markup
|
||
|
make sure to check against https://secure.wikimedia.org/wikipedia/en/wiki/Code_smell
|
||
14 years ago
|
*/
|
||
|
|
||
|
## Recipe version information
|
||
14 years ago
|
$RecipeInfo['MemoryManagement']['Version'] = '2011-06-28';
|
||
14 years ago
|
|
||
|
## Add action for pagefeed
|
||
|
SDV($HandleActions['memorizationMM'], 'MemorizationMM');
|
||
|
SDV($HandleActions['recallMM'], 'BehaviorRecallMM');
|
||
|
SDV($HandleActions['preparationMM'], 'PreparationMM');
|
||
|
|
||
14 years ago
|
|
||
|
function MemorizationMM($pagename, $auth = 'read'){
|
||
|
GenerateFeed("startrecall", "memorization.xml", false,
|
||
|
"Memorization", "Receive links as reminded to piece of information you want to consolidate as long-term."
|
||
|
);
|
||
|
}
|
||
|
function BehaviorRecallMM($pagename, $auth = 'read'){
|
||
|
GenerateFeed("recall", "recall.xml", false,
|
||
|
"BehaviorRecall", "Receive links as reminded to periodic behaviors you want to transform to habits."
|
||
|
/*
|
||
|
"Day $day recall for page $page started at $daterecall"
|
||
|
"$ScriptUrl/$cleaned_page_name#MemorizationDay$day"
|
||
|
FeedText($page,$page,"description")
|
||
|
*/
|
||
|
);
|
||
|
}
|
||
|
|
||
|
function PreparationMM($pagename, $auth = 'read'){
|
||
|
GenerateFeed("startprepare", "preparation.xml", true,
|
||
|
"Preparation", "Receive links as reminded for consequent events you want to prepare."
|
||
|
/*
|
||
|
"Day $day of preparation for page $page started at $dateprepare"
|
||
|
"$ScriptUrl/$page"
|
||
|
"This is to improve preparation of things you will have to produce. Also don't forget to improve those instructions to be more and more efficient!"
|
||
|
*/
|
||
|
);
|
||
|
}
|
||
|
|
||
|
|
||
|
function mod_pattern_test($day,$timeforward,$step){
|
||
|
$current_unix_day = strtotime(date("Y-m-d"));
|
||
|
$checkdate = strtotime(preg_replace("/(\d+)\/(\d+)\/(\d+)/",'$3-$2-$1',$day));
|
||
|
if ($timeforward)
|
||
|
return (($current_unix_day - $checkdate) % 7*(24*60*60) == 0);
|
||
|
return (($current_unix_day + $checkdate) % $step *(24*60*60) == 0);
|
||
|
}
|
||
|
|
||
|
function exponential_pattern_test($day,$timeforward){
|
||
|
$exponential_pattern = array(1,10,30,60,120,350,700,1500,3000,7000,15000,30000,100000); //exp
|
||
|
#consider comparing the value with its log
|
||
|
$current_unix_day = strtotime(date("Y-m-d"));
|
||
|
$checkdate = strtotime(preg_replace("/(\d+)\/(\d+)\/(\d+)/",'$3-$2-$1',$day));
|
||
|
if ($timeforward)
|
||
|
return in_array(($current_unix_day - $checkdate),$exponential_pattern);
|
||
|
return in_array(($checkdate - $current_unix_day),$exponential_pattern);
|
||
|
}
|
||
|
|
||
14 years ago
|
# from http://www.pmwiki.org/wiki/PmWiki/Functions
|
||
|
function FeedTextMM($pagename, &$page, $tag) {
|
||
|
$text = RetrieveAuthSection("ReadingNotes.GroupHeader","");
|
||
|
$content = MarkupToHTML($pagename, $text);
|
||
|
$text = RetrieveAuthSection($pagename, '##Chapter2');
|
||
14 years ago
|
// note that if this boundary if not found, the entire page is converted
|
||
14 years ago
|
$content .= MarkupToHTML($pagename, $text);
|
||
|
return "<$tag><![CDATA[$content]]></$tag>";
|
||
|
}
|
||
|
|
||
|
## Create feed from page history
|
||
14 years ago
|
function GenerateFeed($varname,$targetfile,$timeforward,$ChannelTitle,$ChannelDescription) {
|
||
|
# GenerateFeed(FeedTitle,FeedDescription,ItemTitle,ItemDescription,Feedfile,Timedirection,Pattern)
|
||
14 years ago
|
# consider defaults : exp, +, ...
|
||
|
global $FarmD, $WikiTitle, $ScriptUrl;
|
||
|
|
||
14 years ago
|
$feeds = "/pub/memoryfeeds/" ;
|
||
14 years ago
|
#### location of the resulting feed
|
||
14 years ago
|
$feedfile = $FarmD.$feeds.$targetfile;
|
||
14 years ago
|
if (!file_exists($feedfile)){
|
||
|
if (!touch($feedfile)){
|
||
|
print "Creation of the feed file fails, check write permissions for pmWiki and $feedfile.\nMake sure the target directory exists and with the right write permissions.";
|
||
|
return;
|
||
|
}
|
||
|
}
|
||
|
# open $feed as read
|
||
|
$feed_oldcontent = file_get_contents($feedfile);
|
||
|
$feed_newcontent = '';
|
||
|
|
||
14 years ago
|
# this can probably be optimized by removing pages that are sure not to have varname
|
||
14 years ago
|
$pages = ListPages();
|
||
|
|
||
|
# 2 loops can be probably optimized since they are ordered by date
|
||
|
foreach ($pages as $page) {
|
||
14 years ago
|
$params = PageTextVar($page,$varname);
|
||
|
if ( isset($params) ) {
|
||
14 years ago
|
$params = explode(" ",$recall);
|
||
14 years ago
|
#XXX make sure params does contain the date even when " " is not found
|
||
14 years ago
|
$daterecall = $params[0];
|
||
14 years ago
|
if ($daterecall=="") break;
|
||
14 years ago
|
switch($patternrecall){
|
||
14 years ago
|
case "daily": $pattern_matched = true; break;
|
||
|
case "weekly": $pattern_matched = mod_pattern_test($daterecall,$timeforward,7); break;
|
||
|
case "monthly": $pattern_matched = mod_pattern_test($daterecall,$timeforward,30); break;
|
||
|
default: $pattern_matched = exponential_pattern_test($daterecall,$timeforward); break;
|
||
14 years ago
|
}
|
||
14 years ago
|
if ($pattern_matched) {
|
||
14 years ago
|
# generate GUID
|
||
|
$item_GUID = $page.'_'.date("Y-m-d");
|
||
14 years ago
|
# if not present in file (using a regex on the GUID)
|
||
|
if (preg_match("/$item_GUID/",$feed_oldcontent) == 0){
|
||
14 years ago
|
# generate date
|
||
|
$feed_newitemdate = date(DATE_RSS, time());
|
||
|
$cleaned_page_name = str_replace(".","/",$page);
|
||
|
global $FmtV;
|
||
|
$pagecontent = FmtPageName($FmtV, $page);
|
||
14 years ago
|
# does this actually work?! check FeedText() instead
|
||
14 years ago
|
|
||
14 years ago
|
$ItemTitle = "Day $day recall for page $page started at $daterecall";
|
||
|
$ItemLink = "$ScriptUrl/$cleaned_page_name#BehaviorRecallDay$day";
|
||
|
$ItemDescription = "This is to improve behaviors you decided yourself were valuable. Also don't forget to improve those instructions to be more and more efficient! $pagecontent";
|
||
14 years ago
|
|
||
14 years ago
|
# NOTE $ChannelTitle."Day" could be use but that's not really a proper name...
|
||
14 years ago
|
|
||
|
$feed_newitem = "<item>\n
|
||
14 years ago
|
<title>$ItemTitle</title>
|
||
|
<link>$ItemLink</link>
|
||
|
<description>$ItemDescription</description>
|
||
14 years ago
|
<guid>$item_GUID</guid>
|
||
|
<pubDate>$feed_newitemdate</pubDate>\n</item>";
|
||
|
|
||
|
# appending the item
|
||
|
$feed_newcontent .= $feed_newitem;
|
||
|
}
|
||
|
} # check if the next recall day is today
|
||
|
} # check if the next page is tagged
|
||
|
}
|
||
|
# feed should be properly updated
|
||
|
|
||
|
$feed_newdate = date(DATE_RSS, time());
|
||
|
$feed_header = "<?xml version=\"1.0\"?>\n<rss version=\"2.0\">
|
||
|
<channel>
|
||
|
<title>$ChannelTitle feed for $WikiTitle .</title>
|
||
|
<link>$ScriptUrl</link>
|
||
14 years ago
|
<description>$ChannelTitle</description>
|
||
14 years ago
|
<lastBuildDate>$feed_newdate</lastBuildDate>";
|
||
|
$feed_footer = "\n</channel>\n</rss>";
|
||
|
|
||
|
print $feed_header;
|
||
|
print $feed_oldcontent;
|
||
|
print $feed_newcontent;
|
||
|
print $feed_footer;
|
||
|
|
||
14 years ago
|
if (strlen($feed_newcontent)==0)
|
||
|
return;
|
||
|
|
||
14 years ago
|
$write_result = file_put_contents($feedfile,$feed_oldcontent.$feed_newcontent);
|
||
|
if (!$write_result){
|
||
|
if (strlen($feed_oldcontent.$feed_newcontent)>0){
|
||
|
print "Creation of the feed file fails, check write permissions for pmWiki and $feedfile.";
|
||
|
return;
|
||
|
} else {
|
||
|
print "No item to generate, did you correctly tag your pages?";
|
||
|
return;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|