<?php

class Inline_base
{
    private $ci;
    private $show_edit = null;

    public function __construct()
    {
        $this->ci = get_instance();
        $this->ci->js_css->parse_css('inlineeditor/css/inline.css');
    }

    public function show_edit()
    {
        if (is_null($this->show_edit)) {
            $this->ci->load->library(['ciext/configurator', 'ciext/RT_user']);
            // Access check
            if (!$this->ci->rt_user->isAllowed('inlineeditor', 'edit_inlineeditor')) {
                $this->show_edit = false;
                return $this->show_edit;
            }
            $cnf = new configurator('inlineeditor');
            $this->show_edit = !empty($cnf->item('show_editor'));
        }

        return $this->show_edit;
    }

    public function admin_link($url)
    {
        return '<a href="' . $url . '" class="inline_edit_link"><i class="fa fa-edit"></i> ' . $this->ci->lang->line('Edit') . '</a>';
    }

    public function generate_url($id, $admin_segment)
    {
        return base_url($this->ci->config->item('admin_page'))
            . '/mconfig/index/inlineeditor/inline/'
            . $admin_segment . '/edit/' . $id
            . '?referer=' . base_url($this->ci->uri->uri_string());
    }

}