"; } ## Create feed from page history function GenerateFeed($varname,$targetfile,$timeforward,$ChannelTitle,$ChannelDescription) { # GenerateFeed(FeedTitle,FeedDescription,ItemTitle,ItemDescription,Feedfile,Timedirection,Pattern) # consider defaults : exp, +, ... global $FarmD, $WikiTitle, $ScriptUrl; $feeds = "/pub/memoryfeeds/" ; #### location of the resulting feed $feedfile = $FarmD.$feeds.$targetfile; 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 = ''; # this can probably be optimized by removing pages that are sure not to have varname $pages = ListPages(); # 2 loops can be probably optimized since they are ordered by date foreach ($pages as $page) { $params = PageTextVar($page,$varname); if ( isset($params) ) { $params = explode(" ",$recall); #XXX make sure params does contain the date even when " " is not found $daterecall = $params[0]; if ($daterecall=="") break; switch($patternrecall){ 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; } if ($pattern_matched) { # 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()); $cleaned_page_name = str_replace(".","/",$page); global $FmtV; $pagecontent = FmtPageName($FmtV, $page); # does this actually work?! check FeedText() instead $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"; # NOTE $ChannelTitle."Day" could be use but that's not really a proper name... $feed_newitem = "\n $ItemTitle $ItemLink $ItemDescription $item_GUID $feed_newitemdate\n"; # 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 = "\n $ChannelTitle feed for $WikiTitle . $ScriptUrl $ChannelTitle $feed_newdate"; $feed_footer = "\n\n"; print $feed_header; print $feed_oldcontent; print $feed_newcontent; print $feed_footer; if (strlen($feed_newcontent)==0) return; $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; } } }