<?php

/**
 * iCMS - i Content Management System
 * Copyright (c) 2007-2017 iCMSdev.com. All rights reserved.
 *
 * @author icmsdev <master@icmsdev.com>
 * @site https://www.icmsdev.com
 * @licence https://www.icmsdev.com/LICENSE.html
 */
class IndexApp
{
    public function __construct()
    {
        Index::init();
    }
    public function do_iCMS()
    {
        return $this->display();
    }
    public function API_iCMS()
    {
        return $this->display($a);
    }
    public function display()
    {
        $index_name = $a[1] ?: Config::get('template.index.name');
        $index_name or $index_name = 'index';
        $index_tpl  = $a[0] ?: View::$config['template']['index'];
        $rule = '{PHP}';
        if (View::$gateway == "html" || Config::get('template.index.rewrite')) {
            $rule = $index_name . Config::get('route.ext');
        }
        $iurl = (array) Route::get('index', array('rule' => $rule));
        $rule == '{PHP}' or Route::getPageUrl($iurl);

        if (Config::get('template.index.mode') && iPHP_DEVICE == "desktop") {
            AppsApp::redirectToHtml($iurl);
        }

        View::setGlobal($iurl, 'iURL');
        $view = View::render($index_tpl, 'index');
        if ($view) return array($view, $iurl);
    }
}
