<?php 
/*
* @package   YouTech Shortcodes
* @author    YouTech Company http://smartaddons.com/
* @copyright Copyright (C) 2015 YouTech Company
* @license   http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL
*/
defined('_JEXEC') or die;use Joomla\CMS\Language\Text;use Joomla\CMS\Factory;
use Joomla\CMS\Uri\Uri;
use Joomla\CMS\HTML\HTMLHelper;
function flickrYTShortcode($atts = null, $content = null) {
        $atts = ytshortcode_atts(array(
            'id_flickr'       => '95572727@N00',
            'limit'    => '9',
            'lightbox' => 'no',
            'radius'   => '0px',
            'class'    => ''
                ), $atts, 'yt_flickr');
        $rounded = ($atts['radius']) ? 'border-radius: ' . $atts['radius'] . ';' : '';

        $image = ($atts['lightbox'] == 'yes') ? '<a class="yt-lightbox" data-mfp-type="image" href="{{image_b}}" title="{{title}}"> ' : '';
        $image .= '<img src="{{image_s}}" alt="{{title}}" />';
        $image .= ($atts['lightbox'] == 'yes') ? '</a> ' : '';

        $unique_id = uniqid("ytflickr_").rand().time();
		HTMLHelper::_('jquery.framework');
        if ($atts['lightbox'] == 'yes') {
            $atts['class'] .= ' yt-flickr-lightbox';
            HTMLHelper::_('stylesheet', Uri::base() . "plugins/system/ytshortcodes/assets/css/magnific-popup.css");
            HTMLHelper::script(Uri::base()."plugins/system/ytshortcodes/assets/js/magnific-popup.js");
           	HTMLHelper::script(Uri::base()."plugins/system/ytshortcodes/shortcodes/flickr/js/flickr-lightbox.js");
        }
        HTMLHelper::_('stylesheet', Uri::base() . "plugins/system/ytshortcodes/shortcodes/flickr/css/flickr.css");
        HTMLHelper::script(Uri::base()."plugins/system/ytshortcodes/shortcodes/flickr/js/flickr.js");
        $return = "<ul id='".$unique_id."' class='flickrfeed ".$atts['class']."'></ul> <div class='clear'></div>";

        echo "<script type='text/javascript'>
              jQuery(document).ready(function() {
                      jQuery('#".$unique_id."').jflickrfeed({
                        limit: " . $atts['limit'] . ", qstrings: {
                          id: '" . $atts['id_flickr'] . "'},
                          itemTemplate: '<li>" . addslashes($image) . "</li>' });
                    });
              </script> ";
		if($atts['radius']){
			$css = '';
			$css .= "#".$unique_id." a,#".$unique_id." img{".$rounded."}";
			
			$doc = Factory::getDocument();
			$doc->addStyleDeclaration($css);
		}
		
        return $return;
    }
?>