<?php
/**
 * Random Controller
 */
class Random extends Controller
{
    /**
     * Process
     */
    public function process()
    {    

		$AuthUser		= $this->getVariable("AuthUser");
		$Route			= $this->getVariable("Route");
        $Settings       = $this->getVariable("Settings");

        $Config['title']        = get($Settings,'data.title','seo');
        $Config['description']  = get($Settings,'data.description','seo');
        $Config['cache']        = 'true';

        // Listing
        $Listing = $this->db->from(null,'SELECT posts.id, posts.self FROM `posts` ORDER BY RAND()')->first(); 
        if(empty($Listing['id'])) {
            header('location:'.APP.'/404');
            exit();
        }

        header('location:'.play($Listing['id'],$Listing['self']));
     
        $this->setVariable("Config", $Config);  
        $this->setVariable("Listing", $Listing);  
        
    }
}