function export($type, $title, $bbcode, $codeid = '', $attach = true, $break_on_empty = true)
{
    global $formats;
    if (isset($formats[$type])) {
        $fmt = $formats[$type];
        require_once 'mapbbcode.php';
        $data = mapbbcode_to_array($bbcode);
        $data['title'] = $title;
        if (!is_array($data['objs'])) {
            $data['objs'] = array();
        }
        if (count($data['objs']) > 0 || isset($data['zoom'])) {
            $content = $fmt->export($data);
            if (!$break_on_empty || strlen($content) > 0) {
                $basename = trim(preg_replace('/[^ 0-9a-z_.,!()-]+/i', '', iconv('UTF-8', 'ASCII//TRANSLIT', $title)));
                if ($basename == '') {
                    $basename = preg_match('/^\\w+$/', $codeid) ? $codeid : 'shared';
                }
                header("Cache-Control: no-cache, must-revalidate");
                header("Expires: Sat, 26 Jul 1997 05:00:00 GMT");
                header('Content-Type: ' . (isset($fmt->mime) ? $fmt->mime : 'text/plain'));
                if ($attach) {
                    header('Content-Disposition: attachment; filename=' . $basename . '.' . (isset($fmt->ext) ? $fmt->ext : $type));
                }
                header('Content-Length: ' . mb_strlen($content, '8bit'));
                print $content;
                return CONVERT_OK;
            }
        }
        return CONVERT_EMPTY;
    }
    return CONVERT_NOT_SUPPORTED;
}
Example #2
0
 public function import_str($str)
 {
     $bbpos = strpos($str, '[/map]');
     if ($bbpos === false) {
         $title = $str;
         $bbcode = '';
     } else {
         $title = substr($str, $bbpos + 6);
         $bbcode = substr($str, 0, $bbpos + 6);
     }
     $res = mapbbcode_to_array($bbcode);
     if (strlen($title) > 0) {
         $res['title'] = str_replace('[ /map]', '[/map]', $title);
     }
     return $res;
 }