<?php
#
# Copyright 2003 James Seng. See LICENSE for the Software License.
#

class opml_base extends pong_base {
    function tempfile($class) {
        global $conf_dbdir;
        return $conf_dbdir . $class . ".temp";
    }

    function filename($class) {
        global $conf_dbdir;
        return $conf_dbdir . $class . ".opml";
    }

    function opml_header($title) {
        global $config;

        $datecreated = $config->get('datecreated');
        if (strlen($datecreated)<=0) {
            $datecreated = long_datetime();
            $config->set('datecreated',$datecreated);
        }
        $datemodified = long_datetime();
        $ownername = $config->get('ownername');
        $owneremail = $config->get('owneremail');

        return <<<_HEAD_
<?xml version="1.0" encoding="utf-8"?>
<opml version="1.0">
  <head>
    <title>$title</title>
    <dateCreated>$datecreated</dateCreated>
    <dateModified>$datemodified</dateModified>
    <ownerName>$ownername</ownerName>
    <ownerEmail>$owneremail</ownerEmail>
    </head>
  <body>

_HEAD_;
    }

    function opml_footer() {
        return <<<_FOOT_
    </body>
  </opml>

_FOOT_;
    }

    function opml_outline_key_start($type,$indent = 2) {
        $type = htmlspecialchars($type);
        $space1 = str_pad("",$indent*2);
        return "$space1<outline text=\"$type\">\n";
    }

    function opml_outline_end($type = "", $indent = 2) {
        $space2 = str_pad("",$indent*2+2);
        return  "$space2</outline>\n";
    }

    function opml_outline_kv($key,$value,$indent = 2) {
        $key = htmlspecialchars($key);
        $value = htmlspecialchars($value);
        $space1 = str_pad("",$indent*2);
        $space2 = str_pad("",$indent*2+2);

        $str  = "$space1<outline text=\"$key\">\n";
        $str .= "$space2<outline text=\"$value\" />\n";
        $str .= "$space2</outline>\n";
        return $str;
    }
}

?>
