Mapper

Baru di tambah mapper dari blog lama (pas masih pake wp) ke blog yg skr. Code nya sederhana:

public function __call($method, $args)
{
    $id = false;

    if (sizeof($args) == 0)
    {
        if (preg_match('!(d+).(d+).html!i', $method, $match)
         OR preg_match('!(d+),(d+),(d+),(d+)!i', $method, $match)
         OR preg_match('!page_id=(d+)!i', $method, $match)
        ){
            $id = $match[1];
        }
    }
    if ($id)
    {
        $m = new Mapper_Model($id);
        if ($m->id > 0)
        {
            $p = ORM::factory('post')
                 ->where('url_title', $m->post_name)
                 ->find();
            if ($p->loaded == true)
            {
                url::redirect(($p->get_type() == 'page'
                    ? $p->url_title
                    : "blog/{$p->url_title}"), 301);
            }
        }
    }
    url::redirect();
}

Ini gw bikin, soalna dulu gw pake permalink macem itu.. /%post_id%.%day%.html, selain itu, gw redirect ke halaman depan aja :D