Вход Регистрация
Файл: sngine-v2.8/Script/includes/libs/Embed/Adapters/Github.php
Строк: 61
<?php

namespace EmbedAdapters;

use 
EmbedHttpResponse;
use 
EmbedProvidersApi;

/**
 * Adapter to get the embed code from gist.github.com.
 */
class Github extends Webpage
{
    
/**
     * {@inheritdoc}
     */
    
public static function check(Response $response)
    {
        return 
$response->isValid() && $response->getUrl()->match([
            
'gist.github.com/*/*',
            
'github.com/*',
        ]);
    }

    
/**
     * {@inheritdoc}
     */
    
protected function init()
    {
        
parent::init();

        if (
$this->getResponse()->getUrl()->getHost() === 'gist.github.com') {
            
$this->providers = ['gist' => new ApiGist($this)] + $this->providers;
        }
    }

    
/**
     * {@inheritdoc}
     */
    
public function getUrl()
    {
        
//Open graph returns as canonical url the main repo url, instead the file
        
return (string) $this->getResponse()->getUrl();
    }

    
/**
     * {@inheritdoc}
     */
    
public function getCode()
    {
        
$this->width null;
        
$this->height null;

        
$url $this->getResponse()->getUrl();

        if (
$url->match('github.com/*/*/blob/*')) {
            
$username $url->getDirectoryPosition(0);
            
$repo $url->getDirectoryPosition(1);
            
$ref $url->getDirectoryPosition(3);
            
$path_to_file implode('/'$url->getSlicePath(4));

            switch (
$url->getExtension()) {
                case 
'geojson':
                    
//https://help.github.com/articles/mapping-geojson-files-on-github/#embedding-your-map-elsewhere
                    
return "<script src="https://embed.githubusercontent.com/view/geojson/{$username}/{$repo}/{$ref}/{$path_to_file}"></script>";

                
case 'stl':
                    
//https://help.github.com/articles/3d-file-viewer/#embedding-your-model-elsewhere
                    
return "<script src="https://embed.githubusercontent.com/view/3d/{$username}/{$repo}/{$ref}/{$path_to_file}"></script>";
            
}
        }

        return 
parent::getCode();
    }
}
Онлайн: 0
Реклама