ShowRecentChangesMindMapAction


This is the development page for the ShowRecentChangesMindMap action

Please feel free to make changes or leave comments!



<?php

/*
Action to display recent changes in a mindmap. It will
    gather changes (up to a specified maximum)
    write them into a file if this is a registered user.
    launch mindmap to display them

Usage:
{{recentchangesmindmap max="50" height="1000"}}

Parameters
(optional)  max: Number of changes to display.
            If not specified, will use value from user settings
            If not specified, will use 50

(optional)  height: Height of frame within which the mindmap will be displayed.
            If not specified, will use 1000.

Comments/changes are most welcome

Nick Damoulakis

*/


// Only create a file with the mindmap, if the user is logged in
$user = $this->GetUser();
if ($user)
{
    $filename = "recent_changes_for_".$this->GetUserName().".mm";
}

// If this is the 1st pass over the page then create the mindmap XML and store it in a file
if (!$_SESSION["mnprinted"] || $_SESSION["mnprinted"] == "")
{
    $xml = "<map version=\"0.7.1\">\n";
    $xml .= "<node TEXT=\"Recent Changes\">\n";
    $xml .= "<node TEXT=\"Date\" POSITION=\"right\">\n";

    if ($pages = $this->LoadRecentlyChanged())
    {
        $users = array();
        $curday = "";

        // Check for any params supplied with the action
        if (is_array($vars))
        {
            foreach ($vars as $param => $value)
            {
                if ($param == 'max') {$max = $this->htmlspecialchars_ent($vars['max']);}
            }
        }

        $user = $this->GetUser();

        // If no max was specified, use either that defined at login or default to 50
        if (!$max) {$max = ( $user ? $user["changescount"] : 50);}

        $c = 0;
        foreach ($pages as $page)
        {
            $c++;
            if (($c <= $max) || !$max)
            {
                $pageuser = $page["user"];
                $pagetag = $page["tag"];

                // day header
                list($day, $time) = explode(" ", $page["time"]);
                if ($day != $curday)
                {
                    $dateformatted = date("D, d M Y", strtotime($day));
                    if ($curday) $xml .= "</node>\n";
                    $xml .= "<node TEXT=\"$dateformatted\">\n";
                    $curday = $day;
                }

                $pagelink = $this->config["base_url"].$pagetag;
                $xml .= "<node LINK=\"$pagelink\" TEXT=\"$pagetag\" FOLDED=\"true\">\n";
                $timeformatted = date("H:i T", strtotime($page["time"]));
                $xml .= "<node LINK=\"$pagelink/revisions\" TEXT=\"Revision time: $timeformatted\"/>\n";
                if ($pagenote = $page["note"])
                {
                    $xml .= "<node TEXT=\"$pageuser: $pagenote\"/>\n";
                } else
                {
                    $xml .= "<node TEXT=\"Author: $pageuser\"/>\n";
                }


                $xml .= "<node LINK=\"$pagelink/history\" TEXT=\"View History\"/>\n";
                $xml .= "</node>\n";
                // $xml .= "<arrowlink ENDARROW=\"Default\" DESTINATION=\"Freemind_Link_".$page["user"]."\" STARTARROW=\"None\"/>\n";
                if (is_array($users[$pageuser]))
                {
                    $u_count = count($users[$pageuser]);
                    $users[$pageuser][$u_count] = $pagetag;
                } else
                {
                    $users[$pageuser][0] = $pageuser;
                    $users[$pageuser][1] = $pagetag;
                }

            }
        }

        $xml .= "</node></node><node TEXT=\"Author\" POSITION=\"left\">\n";
        foreach ($users as $user)
        {
            $start_loop = true;
            foreach ($user as $user_page)
            {
                if (!$start_loop)
                {
                    $xml .= "<node TEXT=\"".$user_page."\"/>\n";
                } else
                {
                    $xml .= "<node TEXT=\"$user_page\">\n";
                    $start_loop = false;
                }
            }
            $xml .= "</node>\n";
            // $xml .= "<node ID=\"Freemind_Link_".$user["user"]."\" TEXT=\"".$page["user"]."\"/>\n";
        }
    }
    else
    {
        $xml .= "<item>\n";
        $xml .= "<title>Error</title>\n";
        $xml .= "<link>".$this->Href("show")."</link>\n";
        $xml .= "<description>You're not allowed to access this information.</description>\n";
        $xml .= "</item>\n";
    }

    $xml .= "</node></node>\n";
    $xml .= "</map>\n";

    // If this user is a logged in user (thus a defined filename from above)
    if ($filename != "")
    {
        $fp = @fopen($filename, "w");
        fwrite($fp, $xml);
        fclose($fp);
    }

    // Set the flag to say we've already done the map generation work
    $_SESSION["mnprinted"] = "printed";

    // and reload this page
    $this->Redirect($this->Href());
}
else
{
    // This must then be the 2nd pass, so lets zap the flag.
    $_SESSION["mnprinted"] = null;

    // Set up a URL for the mindmap
    // NOTE!!! WAKKA_HOST is a *new* config variable!

    echo "<br>This page will show the ".$max." most recent changes to this Wikki</br><br>";

    // Extract host info from base_url. It is assumed that wikka.php will always be the starting php file...
    $baseurl = $this->config["base_url"];
    $pos = strpos($baseurl, "wikka.php");
    if ($pos > 1)
    {
        $host = substr($baseurl, 0, $pos - 1);
    }
    else
    {
        // Force the error msg below to be shown
        $host = null;
    }

    if (!$host || $host == "")
    {
        echo "Could not derive hostname. Is the base_url variable in wikka.config.php defined?";
    }
    else
    {
        $mindmap_url = $host."/".$filename;
        $mindmap_url = $this->cleanUrl(trim($mindmap_url));

        if (is_array($vars))
        {
            foreach ($vars as $param => $value)
            {
                if ($param == 'height') {$height = $this->htmlspecialchars_ent($vars['height']);}
            }
        }

        if (!$height)
            {
                $height = "500";
            }

        $mindmap_url_fullscreen = "3rdparty/plugins/freemind/fullscreen.php?url=$mindmap_url";

        $output =
        "<script type=\"text/javascript\" language=\"JavaScript\">\n".
        "<!--\n".
        "    if(!navigator.javaEnabled()) {\n".
        "        document.write('Please install a <a href=\"http://www.java.com/\">Java Runtime Environment</a> on your computer.');\n".
        "    }\n".
        "function popup(mylink, windowname)\n".
        "{\n".
        "if (! window.focus)return true;\n".
        "var href;\n".
        "if (typeof(mylink) == 'string')\n".
        "   href=mylink;\n".
        "else\n".
        "   href=mylink.href;\n".
        "window.open(href, windowname, ',type=fullWindow,fullscreen,scrollbars=yes');\n".
        "return false;\n".
        "}\n".
        "//-->\n".
        "</script>\n".
        "<applet code=\"freemind.main.FreeMindApplet.class\" archive=\"3rdparty/plugins/freemind/freemindbrowser.jar\" width=\"100%\" height=\"$height\">\n".
        "   <param name=\"type\" value=\"application/x-java-applet;version=1.4\" />\n".
        "   <param name=\"scriptable\" value=\"false\" />\n".
        "   <param name=\"modes\" value=\"freemind.modes.browsemode.BrowseMode\" />\n".
        "   <param name=\"browsemode_initial_map\" value=\"$mindmap_url\" />\n".
        "   <param name=\"initial_mode\" value=\"Browse\" />\n".
        "   <param name=\"selection_method\" value=\"selection_method_direct\" />\n".
        "</applet>\n".
        "<br />\n".
        "<span class=\"floatr\"><a href=\"$mindmap_url\">Download this mind map</a> :: Use <a href=\"http://freemind.sourceforge.net/\">Freemind</a> to edit it :: <a href=\"$mindmap_url_fullscreen\" onclick=\"return popup(this,'fullmindmap')\">Open fullscreen</a></span><div style=\"clear:both;\"></div>\n";

        print($output);
    }
}

?>



Categories

CategoryUserContributions

There are no comments on this page.
Valid XHTML :: Valid CSS: :: Powered by WikkaWiki