<?php
/*
Generated by OutputBooks Team
*/

class Format
{
    protected $_data = array();
    protected $_from_type = null;
    public function factory($data, $from_type = null)
    {
        $class = __CLASS__;
        return new $class($data, $from_type);
    }
    public function __construct($data = null, $from_type = null)
    {
        goto DfQ3m;
        dmo_K:
        $this->_data = $data;
        goto ysDzO;
        DfQ3m:
        get_instance()->load->helper("\151\156\x66\x6c\145\x63\x74\x6f\x72");
        goto YHEV6;
        YHEV6:
        if ($from_type !== null) {
            if (method_exists($this, "\137\146\x72\x6f\155\x5f" . $from_type)) {
                $data = call_user_func(array($this, "\137\x66\x72\x6f\x6d\137" . $from_type), $data);
            } else {
                throw new Exception("\x46\157\162\x6d\x61\164\40\x63\154\141\x73\x73\x20\x64\157\x65\163\40\156\x6f\x74\x20\x73\x75\160\x70\157\x72\x74\40\x63\157\x6e\166\x65\x72\163\151\x6f\x6e\x20\146\x72\x6f\x6d\40\x22" . $from_type . "\x22\x2e");
            }
        }
        goto dmo_K;
        ysDzO:
    }
    public function to_array($data = null)
    {
        goto aLvP6;
        aLvP6:
        if ($data === null and !func_num_args()) {
            $data = $this->_data;
        }
        goto DRvDJ;
        DRvDJ:
        $array = array();
        goto DeXAP;
        DeXAP:
        foreach ((array) $data as $key => $value) {
            if (is_object($value) or is_array($value)) {
                $array[$key] = $this->to_array($value);
            } else {
                $array[$key] = $value;
            }
            u3Y4i:
        }
        goto JD1VI;
        JD1VI:
        f35XV:
        goto yPz7L;
        yPz7L:
        return $array;
        goto snfeR;
        snfeR:
    }
    public function to_xml($data = null, $structure = null, $basenode = "\x78\x6d\x6c")
    {
        goto kMVG9;
        Ap3Mj:
        if (ini_get("\x7a\145\156\144\x2e\172\x65\x31\137\143\x6f\x6d\x70\x61\x74\x69\x62\151\x6c\151\x74\x79\137\155\157\144\145") == 1) {
            ini_set("\x7a\145\156\x64\56\x7a\x65\61\137\x63\x6f\155\x70\x61\164\151\x62\151\154\x69\x74\171\137\155\x6f\x64\145", 0);
        }
        goto UBw4_;
        nyL1e:
        YZise:
        goto mgHdD;
        UBw4_:
        if ($structure === null) {
            $structure = simplexml_load_string("\x3c\x3f\170\x6d\x6c\x20\x76\145\162\x73\x69\x6f\x6e\75\47\x31\56\60\47\x20\x65\156\x63\157\x64\151\x6e\x67\x3d\47\x75\x74\146\55\70\47\77\76\74{$basenode}\x20\57\x3e");
        }
        goto c0kyT;
        mgHdD:
        return $structure->asXML();
        goto OMutU;
        CVPC0:
        foreach ($data as $key => $value) {
            goto EwN43;
            EwN43:
            if (is_bool($value)) {
                $value = (int) $value;
            }
            goto Bczbi;
            YWDih:
            if ($key === "\x5f\141\x74\x74\162\151\x62\x75\x74\x65\x73" && (is_array($value) || is_object($value))) {
                goto vBXep;
                nu6XC:
                MqM1d:
                goto wohOd;
                Spumo:
                if (is_object($attributes)) {
                    $attributes = get_object_vars($attributes);
                }
                goto el132;
                el132:
                foreach ($attributes as $attributeName => $attributeValue) {
                    $structure->addAttribute($attributeName, $attributeValue);
                    vEYxs:
                }
                goto nu6XC;
                vBXep:
                $attributes = $value;
                goto Spumo;
                wohOd:
            } else {
                if (is_array($value) || is_object($value)) {
                    $node = $structure->addChild($key);
                    $this->to_xml($value, $node, $key);
                } else {
                    $value = htmlspecialchars(html_entity_decode($value, ENT_QUOTES, "\x55\124\106\x2d\70"), ENT_QUOTES, "\x55\x54\106\55\x38");
                    $structure->addChild($key, $value);
                }
            }
            goto IDBOh;
            Bczbi:
            if (is_numeric($key)) {
                $key = singular($basenode) != $basenode ? singular($basenode) : "\x69\164\x65\x6d";
            }
            goto Em5aR;
            IDBOh:
            MNgKC:
            goto gj0uz;
            Em5aR:
            $key = preg_replace("\x2f\133\x5e\141\55\x7a\137\134\55\60\55\71\135\x2f\151", '', $key);
            goto YWDih;
            gj0uz:
        }
        goto nyL1e;
        c0kyT:
        if (!is_array($data) and !is_object($data)) {
            $data = (array) $data;
        }
        goto CVPC0;
        kMVG9:
        if ($data === null and !func_num_args()) {
            $data = $this->_data;
        }
        goto Ap3Mj;
        OMutU:
    }
    public function to_html()
    {
        goto fiCFj;
        jLkT0:
        foreach ($data as &$row) {
            $ci->table->add_row($row);
            HKrrx:
        }
        goto XteZZ;
        oEC4Y:
        $ci = get_instance();
        goto Ph39X;
        Ddozh:
        $ci->table->set_heading($headings);
        goto jLkT0;
        deSmL:
        return $ci->table->generate();
        goto h9LDo;
        Ph39X:
        $ci->load->library("\x74\141\x62\154\145");
        goto Ddozh;
        XSAxH:
        if (isset($data[0]) && is_array($data[0])) {
            $headings = array_keys($data[0]);
        } else {
            $headings = array_keys($data);
            $data = array($data);
        }
        goto oEC4Y;
        fiCFj:
        $data = (array) $this->_data;
        goto XSAxH;
        XteZZ:
        B3_yK:
        goto deSmL;
        h9LDo:
    }
    public function to_csv()
    {
        goto MpBYj;
        TT0P6:
        foreach ($data as &$row) {
            if (is_array($row)) {
                throw new Exception("\106\157\162\155\141\164\x20\143\154\141\163\163\40\144\x6f\x65\163\40\x6e\x6f\164\x20\x73\165\x70\x70\157\162\164\40\155\x75\x6c\x74\151\55\144\151\155\145\156\163\151\x6f\x6e\141\154\40\141\x72\162\141\171\163");
            } else {
                $row = str_replace("\x22", "\x22\x22", $row);
                $output .= "\42" . implode("\x22\x2c\42", $row) . "\x22" . PHP_EOL;
            }
            Z1HPx:
        }
        goto L4Npi;
        g3nvE:
        return $output;
        goto QjpOK;
        xmO_P:
        if (isset($data[0]) && is_array($data[0])) {
            $headings = array_keys($data[0]);
        } else {
            $headings = array_keys($data);
            $data = array($data);
        }
        goto VxvQs;
        MpBYj:
        $data = (array) $this->_data;
        goto xmO_P;
        L4Npi:
        Beqt8:
        goto g3nvE;
        VxvQs:
        $output = "\42" . implode("\x22\54\x22", $headings) . "\42" . PHP_EOL;
        goto TT0P6;
        QjpOK:
    }
    public function to_json()
    {
        $callback = isset($_GET["\143\141\x6c\154\142\x61\143\x6b"]) ? $_GET["\143\x61\154\x6c\142\x61\x63\153"] : '';
        if ($callback === '') {
            return json_encode($this->_data);
        } else {
            if (preg_match("\x2f\136\x5b\x61\x2d\x7a\x5f\x5c\44\x5d\x5b\141\x2d\x7a\x30\x2d\71\134\x24\x5f\135\x2a\x28\x5c\x2e\133\x61\x2d\x7a\137\134\44\x5d\133\x61\x2d\172\x30\55\71\x5c\x24\137\x5d\x2a\x29\52\44\x2f\151", $callback)) {
                header("\x43\157\x6e\x74\145\x6e\164\x2d\x54\171\x70\x65\x3a\x20\x61\160\x70\154\x69\143\x61\x74\151\157\x6e\x2f\x6a\141\x76\141\x73\143\x72\151\x70\164");
                return $callback . "\x28" . json_encode($this->_data) . "\x29\x3b";
            } else {
                $this->_data["\x77\141\162\x6e\x69\156\147"] = "\x69\156\166\x61\x6c\x69\x64\40\152\x73\x6f\x6e\160\x20\x63\141\x6c\x6c\142\141\x63\153\x20\160\162\x6f\166\x69\x64\x65\x64\72\x20" . $callback;
                return json_encode($this->_data);
            }
        }
    }
    public function to_serialized()
    {
        return serialize($this->_data);
    }
    public function to_php()
    {
        return var_export($this->_data, TRUE);
    }
    protected function _from_xml($string)
    {
        return $string ? (array) simplexml_load_string($string, "\x53\151\x6d\x70\154\x65\130\115\x4c\x45\x6c\x65\155\x65\x6e\x74", LIBXML_NOCDATA) : array();
    }
    protected function _from_csv($string)
    {
        goto GG21y;
        MwdXn:
        foreach ($rows as $row) {
            goto FzAWu;
            bVVh_:
            L8HaA:
            goto EgC17;
            FzAWu:
            $data_fields = explode("\42\54\x22", trim(substr($row, 1, -1)));
            goto u33it;
            u33it:
            if (count($data_fields) == count($headings)) {
                $data[] = array_combine($headings, $data_fields);
            }
            goto bVVh_;
            EgC17:
        }
        goto V91KE;
        hzPEU:
        return $data;
        goto xsgdk;
        V91KE:
        pgTYo:
        goto hzPEU;
        GG21y:
        $data = array();
        goto Ds462;
        Ds462:
        $rows = explode("\xa", trim($string));
        goto pi2pT;
        pi2pT:
        $headings = explode("\x2c", array_shift($rows));
        goto MwdXn;
        xsgdk:
    }
    private function _from_json($string)
    {
        return json_decode(trim($string));
    }
    private function _from_php($string)
    {
        return json_decode(trim($string));
    }
    private function _from_serialize($string)
    {
        return unserialize(trim($string));
    }
}
