diff --git a/cookbook/memory_management.php b/cookbook/memory_management.php new file mode 100644 index 0000000..f80e9ce --- /dev/null +++ b/cookbook/memory_management.php @@ -0,0 +1,180 @@ + support of preparation + modify it to accept exp as default -> support of memory-recipe +*/ + +## Recipe version information +$RecipeInfo['MemoryManagement']['Version'] = '2011-06-20'; + +## Add action for pagefeed +SDV($HandleActions['memorizationMM'], 'MemorizationMM'); +SDV($HandleActions['recallMM'], 'BehaviorRecallMM'); +SDV($HandleActions['preparationMM'], 'PreparationMM'); + +# 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'); + $content .= MarkupToHTML($pagename, $text); + return "<$tag>"; +} + +function MemorizationMM($pagename, $auth = 'read'){ GenerateFeed(title,description,feedfile,timedirection,pattern); } +function BehaviorRecallMM($pagename, $auth = 'read'){ GenerateFeed(); } +function PreparationMM($pagename, $auth = 'read'){ GenerateFeed(); } + +## Create feed from page history +function GenerateFeed() { +# consider defaults : exp, +, ... + global $FarmD, $WikiTitle, $ScriptUrl; + + #### location of the resulting feed + $feedfile = $FarmD."/pub/memoryfeeds/recallfeed.xml"; #change to a pattern when support arguments + #$feedfile = $FarmD."/pub/memoryfeeds/memorizationfeed.xml"; #change to a pattern when support arguments + #$feedfile = $FarmD."/pub/memoryfeeds/preparationfeed.xml"; #change to a pattern when support arguments + 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 = ''; + + #### patterns to use + $exponential_pattern = array(1,10,30,60,120,350,700,1500,3000,7000,15000,30000,100000); //exp + $monthly_pattern = array(1,30,60,90,120,150,180,210,240,270,300); //mod30 + $weekly_pattern = array(1,7,14,21,28,35,43,50,57,64,71,78,85,93,100,101,107,114,121,128,135,143,150,157,164,171,178,185,193,200); //mod7 + $daily_pattern = array(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); //mod1 + + #### variables to check value of + $varname='recall'; + #$varname='startrecall'; + #$varname='startprepare'; + + + $pages = ListPages(); + + # 2 loops can be probably optimized since they are ordered by date + foreach ($pages as $page) { + if ( isset(PageTextVar($page,$varname)) ) { + $params = explode(" ",$recall); + $patternrecall = $params[1]; + $daterecall = $params[0]; + switch($patternrecall){ + case "daily": $datestorecall = $daily_pattern; break; + case "weekly": $datestorecall = $weekly_pattern; break; + case "monthly": $datestorecall = $monthly_pattern; break; + default: $datestorecall = $exponential_pattern; break; + } + $current_unix_day = strtotime(date("Y-m-d")); + $sign = "+"; + # else $sign = "-"; + foreach ($datestorecall as $day) { + $checkdate = strtotime((preg_replace("/(\d+)\/(\d+)\/(\d+)/",'$3-$2-$1',$daterecall)." $sign $day days")); + # print $daterecall . " + " . $day . " (" . $checkdate . ") == " . date("d/m/Y"); + if ($checkdate==$current_unix_day) + { + # generate GUID + $item_GUID = $page.'_'.date("Y-m-d"); + # if not present in file using a regex on the GUID + if (preg_match("/$item_GUID/",$feed_oldcontent) == 0) + { + # generate date + $feed_newitemdate = date(DATE_RSS, time()); + # transform line to XML format + $cleaned_page_name = str_replace(".","/",$page); + global $FmtV; + $pagecontent = FmtPageName($FmtV, $page); + # does this actually work?! + + $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"; +/* + Day $day recall for page $page started at $daterecall + $ScriptUrl/$cleaned_page_name#MemorizationDay$day" + FeedText($page,$page,"description") + + 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! +*/ + + $feed_newitem = "\n + $ItemTitle + $ItemLink + $ItemDescription + $item_GUID + $feed_newitemdate\n"; + + # appending the item + $feed_newcontent .= $feed_newitem; + } + break; #we can't have 2 days at the same time, move on to the next page + } + # print "
"; + } # 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()); + $ChannelTitle = "BehaviorRecall"; + #$ChannelTitle="Memorization"; + #$ChannelTitle="Preparation"; + $feed_header = "\n + + $ChannelTitle feed for $WikiTitle . + $ScriptUrl + Receive links as reminded to periodic behaviors you want to transform to habits. + $feed_newdate"; + + $feed_footer = "\n\n"; + + print $feed_header; + print $feed_oldcontent; + print $feed_newcontent; + + print $feed_footer; + + $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; + } + } +} +