<?php

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

class Social_networks extends MX_Controller
{

    /**
     * Build social block of likes 
     * 
     * @param string $img
     * @param string $link 
     * @param string $template
     * 
     * @return string 
     */
    function build_block_likes($img = '', $link = '', $template = '', $title = '', $description = '')
    {
        $this->load->config('social_networks/config');

        $img = (!empty($img)) ? $img : $this->config->item('vk_image');

        // check link
        if (empty($link)) {
            $link = current_url();
        }

        // check template
        if (empty($template)) {
            $template = $this->config->item('template');
        }

        $content = array(
            'g1_image'    => $img,
            'url'         => str_replace('www.', '', rtrim($link, '/')),
            'vk_image'    => $img,
            'vk_noparse'  => $this->config->item('vk_noparse'),
            'vk_type'     => $this->config->item('vk_type'),
            'vk_text'     => $this->config->item('vk_text'),
            'title'       => str_replace(PHP_EOL, '', $title),
            'description' => str_replace(PHP_EOL, '', $description),
        );

        $head = '';
        $head = '<meta itemprop="image" content="' . $img . '">';
        if (!empty($title)) {
            $head .= '<meta property="og:title" content="' . $title . '" />';
        }
        if (!empty($description)) {
            $head .= '<meta property="og:description" content="' . $description . '" />';
        }
        if (!empty($link)) {
            $head .= '<meta property="og:url" content="' . $link . '" />';
        }
        if (!empty($img)) {
            $head .= '<meta property="og:image" content="' . $img . '" />';
            $head .= '<link rel="image_src" href="' . $img . '" />';
            $head .= '<meta itemprop="image" content="' . $img . '">';
        }

        $this->core_model->add_head_data($head);

        return $this->parser->parse('social_networks/' . $template . '.php', $content, TRUE);
    }

}
