<?php
if (!defined('BASEPATH')) {
    exit('No direct script access allowed');
}

if (!function_exists('ehtml')) {

    /**
     * @param string $html
     * @return string
     */
    function ehtml($html, $i_id = null)
    {
        return get_instance()->load->library('inlineeditor/inline_text')
            ->set_admin_segment('html')
            ->parse($html, $i_id);
    }
}

if (!function_exists('etext')) {

    /**
     * @param string $text
     * @return string
     */
    function etext($text, $i_id = null)
    {
        return get_instance()->load->library('inlineeditor/inline_text')
            ->set_admin_segment('text')
            ->parse($text, $i_id);
    }
}

if (!function_exists('elabel')) {

    /**
     * @param string $label
     * @return string
     */
    function elabel($label, $i_id = null)
    {
        return get_instance()->load->library('inlineeditor/inline_text')
            ->set_admin_segment('label')
            ->parse($label, $i_id);
    }
}

if (!function_exists('eimg')) {

    /**
     * @param $img_full_path
     * @param array $attributes
     * @param mixed $i_id
     * @return string tag img
     */
    function eimg($img_full_path, array $attributes = [], $i_id = null)
    {
        return get_instance()->load->library('inlineeditor/inline_img')->parse($img_full_path, $attributes, $i_id);
    }
}

if (!function_exists('evideo_yt')) {

    /**
     * @param $youtube_share_link link from button share
     * @return mixed
     */
    function evideo_yt($youtube_share_link, $i_id = null, $popup = false)
    {
        return get_instance()->load->library('inlineeditor/inline_video_yt')->parse($youtube_share_link, $i_id, $popup);
    }
}

if (!function_exists('ecollection')) {

    function ecollection($collection_name, $template, $values = [], $i_id = null)
    {
        return get_instance()->load->library('inlineeditor/inline_collection')->parse($collection_name, $template, $values, $i_id);
    }
}

if (!function_exists('elink')) {

    function elink($attributes = ['href' => '#', 'text' => 'Lorem ipsum'], $i_id = null)
    {
        $attr_html = '';
        foreach (array_keys($attributes) as $key) {
            if ($key == 'text') {
                continue;
            }
            $attr_html .= $key . '="{' . $key . '}" ';
        }

        return get_instance()->load
            ->library('inlineeditor/inline_collection')
            ->parse('link', '<a ' . trim($attr_html) . '>{text}</a>', $attributes, $i_id);
    }
}