<?php

class CTLPPU_Controllers_Menu extends CTLPPU_Classes_FrontController
{


    public function hookInit()
    {


        /* add the plugin menu in admin */
        if (current_user_can('manage_options')) {
            //check if activated
            if (get_transient('ctlppu_activate') == 1) {
                // Delete the redirect transient
                delete_transient('ctlppu_activate');

                wp_safe_redirect(admin_url('admin.php?page=ctlppu_posts'));
                exit();
            }
        }
    }

    /**
     * Creates the Setting menu in Wordpress
     */
    public function hookMenu()
    {
        /* add the plugin menu in admin */

        $this->model->addMenu(array(ucfirst(_CTLPPU_NAME_),
            'Website Analysis Ultimate',
            'edit_posts',
            'ctlppu_posts',
            null,
            _CTLPPU_THEME_URL_ . 'img/logo/ctlppu_menu_icon_16.png'
        ));

        $this->model->addSubmenu(array('ctlppu_posts',
            ucfirst(_CTLPPU_NAME_) . __(' dashboard', _CTLPPU_PLUGIN_NAME_),
            (__('Posts', _CTLPPU_PLUGIN_NAME_)),
            'edit_posts',
            'ctlppu_posts',
            array(CTLPPU_Classes_ObjController::getClass('CTLPPU_Controllers_Posts'), 'init')
        ));

        if (CTLPPU_Classes_ObjController::getClass('CTLPPU_Models_User')->isSynced()) {
            $this->model->addSubmenu(array('ctlppu_posts',
                ucfirst(_CTLPPU_NAME_) . __(' dashboard', _CTLPPU_PLUGIN_NAME_),
                (__('Settings', _CTLPPU_PLUGIN_NAME_)),
                'edit_posts',
                'ctlppu_settings',
                array(CTLPPU_Classes_ObjController::getClass('CTLPPU_Controllers_Settings'), 'show')
            ));
        }

        $this->model->addSubmenu(array('ctlppu_posts',
            ucfirst(_CTLPPU_NAME_) . __(' dashboard', _CTLPPU_PLUGIN_NAME_),
            (__('Credits', _CTLPPU_PLUGIN_NAME_)),
            'edit_posts',
            'ctlppu_credits',
            array(CTLPPU_Classes_ObjController::getClass('CTLPPU_Controllers_Credits'), 'show')
        ));
    }


}