[dokuwiki] Re: embedding a wiki article into a standalone php page

  • From: WC -Sx-Jones <aif-list@xxxxxxxxxxxxxx>
  • To: dokuwiki@xxxxxxxxxxxxx
  • Date: Mon, 23 Aug 2010 17:39:31 -0400

Do you mean the rendering methods or just reinvent what Doku is already doing?

// Available export types are:
//      export_raw:     Export as wiki markup (Uncooked, Raw)
//      export_xhtml:   Export as XHTML (Cooked, shows with Wiki Markup)
//      export_xhtmlbody: Export XHTML-body only (Plain XHTML, hopes
the XHTML is valid...)
// In most cases export_xhtmlbody should be the a good choice.
// ............................................................


If you want to just pick out a page - attached is something I have
been kicking around; please let me know if you have any suggestions
about it.

HTH/Bill




On Mon, Aug 23, 2010 at 11:23 AM, Xavier <err.network@xxxxxxxxx> wrote:
> Hello,
>
> I was told on IRC that there was recent discussion here on the list
> about this issue but I couldn't find it. I apologize in advance and
> request a pointer if that is the case. What I'm trying to do is embed
> a wiki entry into a standalone PHP page -- basically, I want to run
> the article through the dokuwiki parser and spit it out minus any of
> the niceties like a navbar, etc. Is there a way to do this?
>
> Here is what I envision doing something similar to:
>
> <?php include_once('some_dokuwiki_lib_file.php');
> print_wiki_article('start'); ?>
>
> Thanks,
> Xavier
> --
> DokuWiki mailing list - more info at
> http://www.dokuwiki.org/mailinglist
>
��<?php

// Top-level directories to URL fix-ups ...

//

//      /home/www-hosted/client equals http://$myserver/

//      /home/dokuwiki-hosted/client equals http://$myserver/$client-doc/

/////////////////////////////////////////////////////////////////////////



// Please only set this section -

// ............................................................

// You only need to set the 'resource' page and 'export type'

// Originally written by WC -Sx- Jones; All Rights Reserved...



// The below vars MUST be included on the 'calling' page --wcj

// $dwresource = "";

// $export_type = ""; // export_xhtmlbody is the default



// Available export types are:

//      export_raw:     Export as wiki markup (Uncooked, Raw)

//      export_xhtml:   Export as XHTML (Cooked, shows with Wiki Markup)

//      export_xhtmlbody: Export XHTML-body only (Plain XHTML, hopes the XHTML 
is valid...)

// In most cases export_xhtmlbody should be the a good choice.

// ............................................................





/////////////////////////////////////////////////////////////////////////

/////////////////////////////////////////////////////////////////////////

//

// No changes below here  ...  --wcj

//

/////////////////////////////////////////////////////////////////////////



// Grab some sanity first ...

        ini_set ('user_agent', $_SERVER['HTTP_USER_AGENT']);

// --wcj $myserver       = $_SERVER["HTTP_HOST"];

        $myserver       = '127.0.0.1';

        $dirlocation    = getcwd();

// --wcj $client         = end(explode("/", $dirlocation));

        $clientdw       = "dokuwiki"; // Set manually  --wcj



// Debug? print "<html>My Server: $myserver :: My Directory: $dirlocation :: My 
Client: $client<p><p>&nbsp;";

// Debug? $targeturl = 
"http://$myserver/dokuwiki/doku.php?id=start&do=export_xhtmlbody";



 $targeturl = "http://" . $myserver . "/" .

                $clientdw . "/doku.php?id=$dwresource&do=" . $export_type;



/////////////////////////////////////////////////////////////////////////

// Now run thru the exported DW page (called $dwresource above ...)

  $lines = file($targeturl);

  $start = false;



if (!$skip) {

  // Looking for HTML </body> tag to end --wcj

  foreach ($lines as $line_num => $line) {



        if (preg_match('/<\/html>/i',$line)) {

          $line = "";

        } elseif (preg_match('/<html>/i',$line)) {

          $line = "";

        }



        if (preg_match('/<\/body>/i',$line)) {

          $start = false;

        }



        if ($start) {

                if (preg_match('/\{\{\:?(.+)\|?\}\}/',$line,$matched)) {



                // There is likely a better way, but I am learning PHP still...

                $mediamatch = $matched[0];

                $frontpart  = explode("{{:", $mediamatch);

                $filepart   = explode("|}}", $frontpart[1]);

                $extpart    = explode(".", $filepart[0]);

                $mediafile  = $filepart[0];

                $myext      = $extpart[1];



                switch ($myext) {

                        case "PDF":

                        case "pdf":

 $medialine = "<a href=http://$myserver/$clientdw/data/media/" . $mediafile . 
">" . $mediafile . '</a>';

                                break;

                        default:

 $medialine = "<img src=\"http://$myserver/$clientdw/lib/exe/fetch.php?media=" .

                $mediafile . '" />';

                }

                        print $medialine;

                        $medialine = ''; // clean it :P

                } else {

                        print $line;

                }

        }



        // Looking for HTML <body> tag to start --wcj

        if (preg_match('/<body>/i',$line)) {

                $start = true;

        }

  }

} else { foreach ($lines as $line_num => $line) { print $line; } }

?>

Other related posts: