Auto Description

This recipe tries to get a line from the wiki page where probably there is a initital description of page and then it creates a description meta tag inside the xhtml header section... It can be html5 some day. :-)

It is still a little bit ugly, it was a kick hack just to get it started and will eventually be improved.

V1


$RecipeInfo['AutoDescription']['Version'] = '20120908';

$PostConfig['AutoDescription'] = 1;

function AutoDescription($pn){
global $HTMLHeaderFmt;

if($pn == '') exit();

$pn = ResolvePageName($pn);

  if(PageExists($pn)){
    if(CondAuth($pn,'read')){
       $p = ReadPage($pn,READPAGE_CURRENT);
       $pt = $p['text'];
      if(!preg_match('/\\(\\:description/i',$pt)){
        $t = preg_match('/(.*)\\./',$pt,$m);
        $s = array('(',')',':',"'",'"','/',"\\",'[',']','%','{','}','',
                   '$','=','&','?','+','&','*','#','@','!','~',':',';');
        $t = str_replace($s,' ',$m[1]);
        $t = preg_replace('/\\s+/',' ',$t);
        $t = strip_tags($t);
        $HTMLHeaderFmt['AutoDescription'] = 
               "\n<meta name='description' content='".$t."' />";
      }
    }
  }
}