[pmwiki-users] Include specific lines of text on a page

wiki question wiki_questions at yahoo.com
Mon Jan 21 11:41:16 CST 2008


Hans,
   
  I cut and pasted your exact syntax into my config.php and something is not correct on my side..
   
  The only thing that show up on my page is the syntax.  I also downloaded the Grep.php and I am having the same results.  Does somthing need to be enable at the server level for this to work?
   
  In my config I placed the following at the end
  ####Test GREP
include_once("$FarmD/cookbook/grep.php");
   
  and
  $MarkupExpr['textrows'] = 'ExtractTextRows($pagename, @$args[0],
 @$args[1])';
function ExtractTextRows($pagename, $str, $source) {
        if ($str=='' || $source=='') return '';
        $pn = MakePageName($pagename, $source);
        if ($pn==$pagename) return '';
        $page = RetrieveAuthPage($pn, 'read', true);
        $text = $page['text'];
        $section = TextSection($text, $source);
        $textrows = explode("\n",$section);
        $newrows = array();
        foreach ($textrows as $row) {
                if (strstr($row, $str))
                        $newrows[] = $row;
        }
        return implode("\n", $newrows);


   
  My Syntax:
  {(grep Complete Wiki.TestA suffix=STRING )} 
   
  {(textrows Complete Wiki.TestA)} 
   
  My Test page Content:
    Test A Complete
Test B Complete
Test C Pending 

  
   
  Wiki Version: pmwiki-2.1.27
  Skin: FixFlow
   
   
  Thanks for all of your help on this,
  Ben
  

Hans <design5 at softflow.co.uk> wrote:
  Friday, January 18, 2008, 8:24:52 PM, wiki question wrote:

> Maybe -- Can you explain how page text variable work.
> A simplified example of what I am trying to accomplish:

> Page basically contains:

> TEST_NAME TEST_STATUS
> Test A Complete
> Test B Not Started
> Test C In Progress
> Test D Complete
> Test E In Progress
> ... 
> ...
> ..

> I want to display, on a seperate page, only those tests that are completed and
> have it refresh when the main page is updated.

> So in the current state Test A and D will display

This is a tricky problem. I don't think page text variables are the
best answer, but I will explain it a bit, before offering a different
solution:

Page text variables (PTVs) can be defined in various ways, but the variable
name cannot contain spaces and has to start with a letter.
So your MainPage could contain this, which will automatically defines
PTVs:

TEST_NAME: TEST_STATUS
Test_A: Complete
Test_B: Not Started
Test_C: In Progress
Test_D: Complete
Test_E: In Progress

Each PTV can be referred to as {$:Var}, i.e. {$:Test_A}, which
displays its value, i.e. 'Complete'.
>From a different page it can be referred to with
{PageName$:Var}, i.e {MainPage$:Test_A}
And importantly PTVs can be used in conditional markup.
So your page can contain this:

!!Completed Tests:
(:if {MainPage$:Test_A} 'Complete':)Test A
(:if {MainPage$:Test_B} 'Complete':)Test B
etc.
(:ifend:)

This may give you an idea how to work with PTVs.
It may even be good enough for your problem.

A different approach, I thought, would be to extract text rows from
a page which contain a certain string. Here is a definition of a markup
expression which does this. It should be added to config.php:

# {(textrows 'STRING' PAGENAME)} displays textrows from page PAGENAME which
# have STRING in them (as a substring). STRING is case sensitive.
# {(textrows 'STRING' PAGENAME#section)} displays textrows with STRING from
# section #section of PAGENAME.
# The current page cannot be a source for textrow extraction.
$MarkupExpr['textrows'] = 'ExtractTextRows($pagename, @$args[0], @$args[1])';
function ExtractTextRows($pagename, $str, $source) {
if ($str=='' || $source=='') return '';
$pn = MakePageName($pagename, $source);
if ($pn==$pagename) return '';
$page = RetrieveAuthPage($pn, 'read', true);
$text = $page['text'];
$section = TextSection($text, $source);
$textrows = explode("\n",$section);
$newrows = array();
foreach ($textrows as $row) {
if (strstr($row, $str))
$newrows[] = $row;
}
return implode("\n", $newrows);
}


So with this you could put into the page:

{(textrows Complete MainPage)}

and it will display:

Test A Complete
Test D Complete

Note it displays whole text rows, not just Test A, Test B.
It is a text extraction tool, and can be sourced from a whole page or
a page section.

I suppose it could be easily modified, for your case, to remove the
STRING from the textrows, by changing in the function this:

foreach ($textrows as $row) {
if (strstr($row, $str))
$newrows[] = $row;
}

with this:

foreach ($textrows as $row) {
if (strstr($row, $str)) {
$row = substr_replace($row, '', strpos($row, $str), strlen($str));
$newrows[] = $row;
}
}


~Hans



       
---------------------------------
Be a better friend, newshound, and know-it-all with Yahoo! Mobile.  Try it now.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: /pipermail/pmwiki-users/attachments/20080121/9e6a4e3a/attachment.html 


More information about the pmwiki-users mailing list