├── .github ├── FUNDING.yml └── workflows │ └── main.yml ├── README.md └── webtor.php /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | # These are supported funding model platforms 2 | 3 | github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2] 4 | patreon: pavel_tatarskiy 5 | open_collective: # Replace with a single Open Collective username 6 | ko_fi: # Replace with a single Ko-fi username 7 | tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel 8 | community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry 9 | liberapay: # Replace with a single Liberapay username 10 | issuehunt: # Replace with a single IssueHunt username 11 | otechie: # Replace with a single Otechie username 12 | custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2'] 13 | -------------------------------------------------------------------------------- /.github/workflows/main.yml: -------------------------------------------------------------------------------- 1 | # This is a basic workflow to help you get started with Actions 2 | 3 | name: CI 4 | 5 | # Controls when the workflow will run 6 | on: 7 | push: 8 | tags: 9 | - '*' 10 | 11 | # A workflow run is made up of one or more jobs that can run sequentially or in parallel 12 | jobs: 13 | # This workflow contains a single job called "build" 14 | build: 15 | # The type of runner that the job will run on 16 | runs-on: ubuntu-latest 17 | 18 | # Steps represent a sequence of tasks that will be executed as part of the job 19 | steps: 20 | - uses: actions/checkout@master 21 | - name: Zip Release 22 | uses: TheDoctor0/zip-release@0.6.0 23 | with: 24 | type: 'zip' 25 | filename: 'webtor.zip' 26 | exclusions: '*.git*' 27 | - name: Upload Release 28 | uses: ncipollo/release-action@v1 29 | with: 30 | artifacts: "webtor.zip" 31 | token: ${{ secrets.GITHUB_TOKEN }} 32 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Webtor Wordpress Plugin 2 | 3 | Embeds webtor player to WordPress with a shortcode 4 | 5 | ## How to Install 6 | 7 | Go to the [releases](https://github.com/webtor-io/wordpress-plugin/releases) section of the repository and download the most recent release. 8 | 9 | Then, from your WordPress administration panel, go to `Plugins > Add New` and click the `Upload Plugin` button at the top of the page. 10 | 11 | ## Examples 12 | 13 | The very simple example: 14 | ``` 15 | [webtor src="magnet:?xt=urn:btih:08ada5a7a6183aae1e09d831df6748d566095a10&dn=Sintel"] 16 | ``` 17 | 18 | More serious one with custom subtitles and title. 19 | ``` 20 | [webtor src="magnet:?xt=urn:btih:08ada5a7a6183aae1e09d831df6748d566095a10&dn=Sintel" data-title="Sintel" track-en-src="https://raw.githubusercontent.com/andreyvit/subtitle-tools/master/sample.srt" track-en-default="true" track-en-label="English"] 21 | ``` 22 | 23 | Full list of attributes can be found [here](https://github.com/webtor-io/embed-sdk-js#video-element-attributes-streaming). 24 | -------------------------------------------------------------------------------- /webtor.php: -------------------------------------------------------------------------------- 1 | true, 16 | 'width' => '100%', 17 | ); 18 | 19 | function generateAttrs($args) { 20 | $attrs = array(); 21 | foreach ($args as $k => $v) { 22 | if ($k == 'controls') { 23 | if ($v) $attrs[] = 'controls'; 24 | } else { 25 | $attrs[] = "$k=\"$v\""; 26 | } 27 | } 28 | return implode(' ', $attrs); 29 | } 30 | 31 | function splitArgs($args) { 32 | $attrs = array(); 33 | $tracks = array(); 34 | foreach ($args as $k => $v) { 35 | if (strpos($k, 'track') === 0) { 36 | $tracks[$k] = $v; 37 | } else { 38 | $attrs[$k] = $v; 39 | } 40 | } 41 | return array($attrs, $tracks); 42 | } 43 | 44 | function generateTracks($args) { 45 | $tracks = array(); 46 | foreach ($args as $k => $v) { 47 | $parts = explode('-', $k); 48 | $lang = 'en'; 49 | if (sizeof($parts) == 2) { 50 | $attr = $parts[1]; 51 | } else if (sizeof($parts) == 3) { 52 | $lang = $parts[1]; 53 | $attr = $parts[2]; 54 | } else { 55 | continue; 56 | } 57 | $tracks[$lang][$attr] = $v; 58 | } 59 | foreach ($tracks as $k => $v) { 60 | $tracks[$k]['srclang'] = $k; 61 | if (!isset($tracks[$k]['label'])) $tracks[$k]['label'] = $k; 62 | } 63 | $res = []; 64 | foreach ($tracks as $t) { 65 | $attrs = $this->generateAttrs($t); 66 | $res[] = ""; 67 | } 68 | return implode('', $res); 69 | } 70 | 71 | function shortcode($args) { 72 | $args = array_merge($this->defaults, $args); 73 | if (!isset($args['src'])) { 74 | return '

"src" attribute required!

'; 75 | } 76 | list($args, $tracks) = $this->splitArgs($args); 77 | $attrs = $this->generateAttrs($args); 78 | $tracks = $this->generateTracks($tracks); 79 | $res = ""; 80 | $res = '

'.$res.'

'; 81 | if (!$this->scriptInjected) { 82 | $res .= ''; 83 | $this->scriptInjected = true; 84 | } 85 | return $res; 86 | } 87 | } 88 | $webtor = new Webtor(); 89 | 90 | add_shortcode('webtor', array($webtor, 'shortcode')); 91 | ?> --------------------------------------------------------------------------------