_mediaFeed.php 3.48 KB
<?php
/**
 * @var SportController $this
 */
?>
<?php if ($this->sportRoot->video_stream): ?>
<p class="section-title"><?php echo Yii::t('site', 'Видеолента');?></p>

<div class="photofeed-box">
    <?php
    $photo = null;
    while (!$photo) {
        /** @var $album Album */
        $album = Album::model()->with('i18n')->find(array('order' => 'rand()'));
        /** @var $photo GalleryPhoto */
        $photo = GalleryPhoto::model()->with('i18n')->find(
            array(
                'condition' => 'gallery_id = :gal_id',
                'order' => 'rand()',
                'params' => array(
                    ':gal_id' => $album->video_gallery_id
                )
            ));
    }
    $url = $photo->i18n->link;
    $matches = array();
    preg_match('#(?<=(?:v|i)=)[a-zA-Z0-9-]+(?=&)|(?<=(?:v|i)\/)[^&\n]+|(?<=embed\/)[^"&\n]+|(?<=(?:v|i)=)[^&\n]+|(?<=youtu.be\/)[^&\n]+#', $url, $matches);
    if (count($matches) > 0) {
        $videoId = $matches[0];
        $url = 'http://www.youtube.com/embed/' . $videoId . '?feature=player_detailpage';

    }
    ?>
    <div class="photofeed-image">
        <?php echo CHtml::link(CHtml::image($photo->getUrl('small'), $photo->i18n->name), $url,array('rel'=>'video-feed','class'=>'iframe'))?>
        <div class="overlay"><a class="play-btn iframe" href="<?php echo CHtml::encode($url)?>" rel="video-feed"></a></div>
    </div>
    <?php echo CHtml::link($album->i18n->name, $url,array('rel'=>'video-feed','class'=>'iframe'));?>
</div>
<?php else: ?>
<p class="section-title"><?php echo Yii::t('site', 'Фотолента');?></p>

<div class="photofeed-box">
    <?php
    $photo = null;
    while (!$photo) {
        /** @var $album Album */
        $album = Album::model()->with('i18n')->find(array('order' => 'rand()'));
        /** @var $photo GalleryPhoto */
        $photo = GalleryPhoto::model()->with('i18n')->find(
            array(
                'condition' => 'gallery_id = :gal_id',
                'order' => 'rand()',
                'params' => array(
                    ':gal_id' => $album->photo_gallery_id
                )
            ));
    }
    $url = $this->createUrl('albumsSection/album', array('link' => $album->link,'node_id'=>Node::idByDataId('albumsSection',$album->albums_section_id)));
    ?>
    <div class="photofeed-image">
        <?php echo CHtml::link(CHtml::image($photo->getUrl('small'), $photo->i18n->name), $url)?>
    </div>
    <?php echo CHtml::link($album->i18n->name, $url);?>
</div>

<?php endif; ?>
<?php
    $cs = Yii::app()->clientScript;
    $cs->registerCoreScript('jquery');
//$cs->registerScriptFile(Yii::app()->baseUrl . '/js/fancybox/jquery.mousewheel-3.0.4.pack.js');
    $cs->registerScriptFile(Yii::app()->baseUrl . '/js/fancybox/jquery.fancybox-1.3.4.pack.js');
    $cs->registerCssFile(Yii::app()->baseUrl . '/js/fancybox/jquery.fancybox-1.3.4.css');
$src = <<<JS
$("a[rel=video-feed]").fancybox({
	'transitionIn'	: 'none',
	'type'			: 'iframe',
	'transitionOut'	: 'none',
	'titlePosition' : 'over',
	'titleFormat'	: function(title, currentArray, currentIndex, currentOpts) {

	    var name = $(currentArray[currentIndex]).data('name'), r = '';
	    var description = $(currentArray[currentIndex]).data('description');
	    name = name?name:''; description = description?description:'';
	    if(name.length) r+='<b>'+name+'</b> ';
		if(description.length) r+=description;
		if(r.length) return '<span id="fancybox-title-over">'+r+'</span>';
        else return '';
	}
});
JS;
$cs->registerScript('video-feed',$src);
?>