function encode_xml($v, $desc, $path = '')
{
    switch (gettype($v)) {
        case 'boolean':
            return $v ? 'true' : 'false';
        case 'int':
            return $v;
        case 'array':
            // test for numeric indices (based on json code)
            if (count($v) && array_keys($v) !== range(0, sizeof($v) - 1)) {
                // it's a hash
                $keys = array();
                $h_desc = $desc['content'];
                foreach ($v as $k => $kv) {
                    array_push($keys, "<{$k}>" . encode_xml($kv, $h_desc[$k], "{$path}/{$k}") . "</{$k}>");
                }
                return implode("", $keys);
            } else {
                // it's an array
                $items = array();
                $a_desc = $desc['item'];
                foreach ($v as $i) {
                    array_push($items, "<item>" . encode_xml($i, $a_desc, "{$path}/item") . "</item>");
                }
                return implode("", $items);
            }
            break;
        default:
            return htmlspecialchars($v);
    }
}
function smarty_function_mtcclicenserdf($args, &$ctx)
{
    // status: complete
    // parameters: none
    $blog = $ctx->stash('blog');
    $cc = $blog['blog_cc_license'];
    if (empty($cc)) {
        return '';
    }
    require_once "cc_lib.php";
    require_once "MTUtil.php";
    $cc_url = cc_url($cc);
    $rdf = <<<RDF
<!--
<rdf:RDF xmlns="http://web.resource.org/cc/"
         xmlns:dc="http://purl.org/dc/elements/1.1/"
         xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">

RDF;
    ## SGML comments cannot contain double hyphens, so we convert
    ## any double hyphens to single hyphens.
    $entry = $ctx->stash('entry');
    if ($entry) {
        $permalink = $ctx->tag('EntryPermalink');
        $title = encode_xml(strip_hyphen($entry['entry_title']));
        $desc = encode_xml(strip_hyphen($ctx->tag('EntryExcerpt')));
        $creator = encode_xml(strip_hyphen($entry['entry_author_id'] ? $entry['author_nickname'] : ''));
        $date = $ctx->_hdlr_date(array('format' => "%Y-%m-%dT%H:%M:%S"), $ctx) . $ctx->tag('BlogTimezone');
        $rdf .= <<<RDF
<Work rdf:about="{$permalink}">
<dc:title>{$title}</dc:title>
<dc:description>{$desc}</dc:description>
<dc:creator>{$creator}</dc:creator>
<dc:date>{$date}</dc:date>
<license rdf:resource="{$cc_url}" />
</Work>

RDF;
    } else {
        $site_url = $blog['blog_site_url'];
        if (!preg_match('!/$!', $site_url)) {
            $site_url .= '/';
        }
        $title = encode_xml(strip_hyphen($blog['blog_name']));
        $desc = encode_xml(strip_hyphen($blog['blog_description']));
        $rdf .= <<<RDF
<Work rdf:about="{$site_url}">
<dc:title>{$title}</dc:title>
<dc:description>{$desc}</dc:description>
<license rdf:resource="{$cc_url}" />
</Work>

RDF;
    }
    $rdf .= cc_rdf($cc) . "</rdf:RDF>\n-->\n";
    return $rdf;
}
function smarty_function_mtentrytrackbackdata($args, &$ctx)
{
    $e = $ctx->stash('entry');
    $tb = $e->trackback();
    if (empty($tb)) {
        return '';
    }
    if ($tb->trackback_is_disabled) {
        return '';
    }
    $blog = $ctx->stash('blog');
    $entry = $ctx->stash('entry');
    $blog_accepted = $blog->blog_allow_pings && $ctx->mt->config('AllowPings');
    if ($entry) {
        $accepted = $blog_accepted && $entry->entry_allow_pings;
    } else {
        $accepted = $blog_accepted;
    }
    if (!$accepted) {
        return '';
    }
    require_once "function.mtcgipath.php";
    $path = smarty_function_mtcgipath($args, $ctx);
    $path .= $ctx->mt->config('TrackbackScript') . '/' . $tb->trackback_id;
    $at = $ctx->stash('current_archive_type');
    if ($at) {
        $at = ArchiverFactory::get_archiver($at);
    }
    if ($at && !$at instanceof IndividualArchiver) {
        $url = $ctx->tag('ArchiveLink');
        $url .= '#entry-' . sprintf("%06d", $e->entry_id);
    } else {
        $url = $ctx->tag($e->entry_class . 'Permalink', array('archive_type' => 'Individual'));
    }
    $rdf = '';
    $comment_wrap = isset($args['comment_wrap']) ? $args['comment_wrap'] : 1;
    if ($comment_wrap) {
        $rdf .= "<!--\n";
    }
    require_once "MTUtil.php";
    ## SGML comments cannot contain double hyphens, so we convert
    ## any double hyphens to single hyphens.
    $title = encode_xml(strip_hyphen($e->entry_title), 1);
    $subject = encode_xml(strip_hyphen($ctx->tag('EntryCategory')), 1);
    $excerpt = encode_xml(strip_hyphen($ctx->tag('EntryExcerpt')), 1);
    $creator = encode_xml(strip_hyphen($ctx->tag('EntryAuthorDisplayName')), 1);
    $date = $ctx->_hdlr_date(array('format' => '%Y-%m-%dT%H:%M:%S'), $ctx) . $ctx->tag('BlogTimezone');
    $rdf .= <<<RDF
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
         xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/"
         xmlns:dc="http://purl.org/dc/elements/1.1/">
<rdf:Description
    rdf:about="{$url}"
    trackback:ping="{$path}"
    dc:title="{$title}"
    dc:identifier="{$url}"
    dc:subject="{$subject}"
    dc:description="{$excerpt}"
    dc:creator="{$creator}"
    dc:date="{$date}" />
</rdf:RDF>

RDF;
    if ($comment_wrap) {
        $rdf .= "-->\n";
    }
    return $rdf;
}
function save_form_data($record, $fields)
{
    $xml = new SimpleXMLElement('<form_data/>');
    foreach ($fields as $key => $value) {
        $xml->addChild($key, encode_xml($value));
    }
    $record->data = $xml->asXML();
    return write_form_data($record);
}
function smarty_modifier_encode_xml($text)
{
    require_once "MTUtil.php";
    return encode_xml($text);
}
function pack_supplement_data($fields)
{
    $xml = new SimpleXMLElement('<supplement_data/>');
    foreach ($fields as $key => $value) {
        $xml->addChild($key, encode_xml($value));
    }
    return $xml->asXML();
}
Beispiel #7
0
function putPost($cur)
{
    global $pun_config;
    echo "<item>\n";
    echo "<title>" . entity_to_decimal_value(htmlspecialchars($cur['subject'] . ' in ' . $cur['cat_name'] . ' : ' . $cur['forum_name'])) . "</title>\n";
    $link = $pun_config['o_base_url'] . '/viewtopic.php?pid=' . strval($cur['id']) . '#' . strval($cur['id']);
    echo "<link>" . entity_to_decimal_value(htmlspecialchars($link)) . "</link>\n";
    echo '<guid isPermaLink="false">' . strval($cur['id']) . '@' . $pun_config['o_base_url'] . '</guid>' . "\n";
    $data = "Topic: " . parse_message($cur['subject'], 0) . "\n\nMessage: " . parse_message($cur['message'], 0);
    echo "<description>" . encode_xml($data) . "</description>\n";
    //	echo "<content:encoded><![CDATA[".$data."]]></content:encoded>\n";
    echo "<pubDate>" . strval(date("r", $cur['postposted'])) . "</pubDate>\n";
    echo "</item>\n";
}