Skip to content

Commit

Permalink
Fix CS
Browse files Browse the repository at this point in the history
  • Loading branch information
Mark Scherer committed Feb 15, 2016
1 parent eeb9483 commit cfb7667
Show file tree
Hide file tree
Showing 10 changed files with 99 additions and 55 deletions.
10 changes: 10 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,18 +1,28 @@
language: php

sudo: false

php:
- 5.4
- 5.5
- 5.6
- 7.0
- hhvm

matrix:
fast_finish: true

include:
- php: 5.6
env: PHPCS=1 DEFAULT=0

before_script:
- composer self-update
- composer install --prefer-dist --no-interaction

script:
- phpunit
- sh -c "if [ '$PHPCS' = '1' ]; then vendor/bin/phpcs -p --extensions=php --standard=vendor/fig-r/psr2r-sniffer/PSR2R/ruleset.xml --ignore=vendor --ignore=tests/test_files/ . ; fi"

matrix:
allow_failures:
Expand Down
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) 2016 Mark Scherer

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
40 changes: 22 additions & 18 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,20 +1,24 @@
{
"name": "dereuromark/media-embed",
"description": "A PHP library to deal with all those media services around, parsing their URLs and embedding their audio/video content in websites.",
"keywords": ["media", "embed", "PHP", "iframe", "video", "audio"],
"license": "MIT",
"authors": [
{
"name": "Mark Scherer",
"email": "euromark@web.de"
}
],
"autoload": {
"psr-0": {
"": "src/"
}
},
"require": {
"php": ">=5.4"
}
"name": "dereuromark/media-embed",
"description": "A PHP library to deal with all those media services around, parsing their URLs and embedding their audio/video content in websites.",
"keywords": ["media", "embed", "PHP", "iframe", "video", "audio"],
"license": "MIT",
"authors": [
{
"name": "Mark Scherer",
"role": "Author",
"homepage": "http://www.dereuromark.de"
}
],
"autoload": {
"psr-0": {
"": "src/"
}
},
"require": {
"php": ">=5.4"
},
"require-dev":{
"fig-r/psr2r-sniffer": "dev-master"
}
}
2 changes: 1 addition & 1 deletion examples/bbcode.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,4 @@

<p>
If there are outdated (not working) example URLs or missing types, let me know or provide a PR in <a href="https://github.com/dereuromark/MediaEmbed" target="_blank">GitHub</a> to fix this.
</p>
</p>
14 changes: 7 additions & 7 deletions examples/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,10 @@

echo '<h2>"' . $_GET['type'] . '"</h2>';
echo '<p>Video URL: ' . $videoUrl . '</p>';
if($videoAttributes) {
if ($videoAttributes) {
echo '<p>Video Attributes: <pre>' . print_r($videoAttributes, 1) . '</pre></p>';
}
if($videoParams) {
if ($videoParams) {
echo '<p>Video Params: <pre>' . print_r($videoParams, 1) . '</pre></p>';
}

Expand All @@ -86,19 +86,19 @@

echo '<h3>Embedded Media</h3>';
//adding attributes
if($videoAttributes) {
if ($videoAttributes) {
$Object->setAttribute($videoAttributes);
}
//adding params
if($videoParams) {
if ($videoParams) {
$Object->setParam($videoParams);
}
$embed = $Object->getEmbedCode();
// or
//$embed = (string)$result;
echo $embed;

echo '<div><h3>Embed code:</h3><textarea>'. htmlspecialchars($embed) . '</textarea></div>';
echo '<div><h3>Embed code:</h3><textarea>' . htmlspecialchars($embed) . '</textarea></div>';


echo '</td><td>';
Expand All @@ -116,7 +116,7 @@

echo $embed;

echo '<div><h3>Embed code:</h3><textarea>'. htmlspecialchars($embed) . '</textarea></div>';
echo '<div><h3>Embed code:</h3><textarea>' . htmlspecialchars($embed) . '</textarea></div>';
}

echo '</td></tr></table>';
Expand All @@ -126,4 +126,4 @@

<p>
If there are outdated (not working) example URLs or missing types, let me know or provide a PR in <a href="https://github.com/dereuromark/MediaEmbed" target="_blank">GitHub</a> to fix this.
</p>
</p>
2 changes: 1 addition & 1 deletion examples/lib/MediaEmbedBehavior.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,4 @@ protected function _processVideo($params) {
return $result;
}

}
}
2 changes: 1 addition & 1 deletion examples/lib/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ function getVideos($file) {
}
}
return $videos;
}
}
12 changes: 7 additions & 5 deletions src/MediaEmbed/MediaEmbed.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public function parseId($id, $host, $config = []) {
*
* It will return an object if the url contains valid/supported video.
*
* @param $url string - href to check for embeded video
* @param string $url Href to check for embeded video
* @param array $config
* @return \MediaEmbed\Object\MediaObject|null
*/
Expand Down Expand Up @@ -121,6 +121,10 @@ protected function _matchUrl($url, array $regexRules) {

/**
* Attempt to parse the embed id from a given URL
*
* @param string $url
* @param string $regex
* @return bool
*/
protected function _parseLink($url, $regex) {
$context = stream_context_create(
Expand All @@ -139,7 +143,7 @@ protected function _parseLink($url, $regex) {
* Set custom stubs overwriting the default ones.
*
* @param array $stubs Same format as in the stubs.php file.
* @param array $reset If default ones should be resetted/removed.
* @param bool $reset If default ones should be resetted/removed.
* @return $this
*/
public function setHosts(array $stubs, $reset = false) {
Expand Down Expand Up @@ -188,7 +192,7 @@ public function getHost($alias) {
/**
* Create the embed code for a local file
*
* @param $file string - the file we are wanting to embed
* @param string $file The file we are wanting to embed
* @return bool Whether or not the url contains valid/supported video
*/
public function embedLocal($file) {
Expand Down Expand Up @@ -233,8 +237,6 @@ protected function _slug($text) {
return $text;
}

/* deprecated */

/**
* Contains the preg info
* DOES NOT contain width/height etc
Expand Down
49 changes: 28 additions & 21 deletions src/MediaEmbed/Object/MediaObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ public function __construct(array $stub, array $config) {
* Getter/setter for stub
*
* @param string $property - (optional) the specific
* property of the stub to be returned. If
* omitted, array of all properties are returned.
* property of the stub to be returned. If
* omitted, array of all properties are returned.
*
* @return array|string|$this
*/
Expand All @@ -99,16 +99,17 @@ public function stub($property = null, $value = null) {
*/
public function id() {
$res = $this->_match;
$count = count($res);

if (empty($this->_stub['id'])) {
if (empty($res[count($res) - 1])) {
if (empty($res[$count - 1])) {
return '';
}
$this->_stub['id'] = $res[count($res) - 1];
$this->_stub['id'] = $res[$count - 1];
}
$id = $this->_stub['id'];

for ($i = 1; $i <= count($res); $i++) {
for ($i = 1; $i <= $count; $i++) {
$id = str_ireplace('$' . $i, $res[$i - 1], $id);
}
return $id;
Expand All @@ -126,13 +127,14 @@ public function slug() {
*/
public function name() {
$res = $this->_match;
$count = count($res);

if (empty($this->_stub['name'])) {
return '';
}
$name = $this->_stub['name'];

for ($i = 1; $i <= count($res); $i++) {
for ($i = 1; $i <= $count; $i++) {
$name = str_ireplace('$' . $i, $res[$i - 1], $name);
}
return $name;
Expand All @@ -150,12 +152,12 @@ public function website() {
/**
* Returns a png img
*
* @return Resource or null if not available
* @return resource|null Resource or null if not available
*/
public function icon() {
$url = $this->_stub['website'];
if (!$url) {
return;
return null;
}

$pieces = parse_url($url);
Expand All @@ -177,15 +179,15 @@ public function icon() {

/**
* @param string $location Absolute path with trailing slash
* @param binary $icon Icon data
* @param string $icon Icon data
* @return string|null $filename
*/
public function saveIcon($location = null, $icon = null) {
if ($icon === null) {
$icon = $this->icon();
}
if (!$icon) {
return;
return null;
}
if (!$location) {
$location = IMAGES . 'content' . DS . 'video_types';
Expand All @@ -197,17 +199,17 @@ public function saveIcon($location = null, $icon = null) {
$filename = $this->slug() . '.png';
$file = $location . $filename;
if (!file_put_contents($file, $icon)) {
return;
return null;
}
return $filename;
}

/**
* Override a default object param value
*
* @param $param mixed - the name of the param to be set
* @param mixed $param The name of the param to be set
* or an array of multiple params to set
* @param $value string - (optional) the value to set the param to
* @param string $value (optional) the value to set the param to
* if only one param is being set
*
* @return $this
Expand Down Expand Up @@ -238,9 +240,9 @@ public function setParam($param, $value = null) {
/**
* Override a default object attribute value
*
* @param $param mixed - the name of the attribute to be set
* @param mixed $param The name of the attribute to be set
* or an array of multiple attribs to be set
* @param $value string - (optional) the value to set the param to
* @param string $value (optional) the value to set the param to
* if only one param is being set
* @return $this
*/
Expand Down Expand Up @@ -427,10 +429,10 @@ protected function _getObjectSrc($type = 'embed-src') {
*/
public function getImageSrc() {
if (empty($this->_stub['id'])) {
return;
return null;
}
if (empty($this->_stub['image-src'])) {
return;
return null;
}

$stubImgSrc = $this->_stub['image-src'];
Expand All @@ -454,7 +456,8 @@ public function image() {
}
$thumb = $this->_stub['image-src'];

for ($i = 1; $i <= count($this->_match); $i++) {
$count = count($this->_match);
for ($i = 1; $i <= $count; $i++) {
$thumb = str_ireplace('$' . $i, $this->_match[$i - 1], $thumb);
}

Expand Down Expand Up @@ -499,15 +502,18 @@ protected function _buildObject() {
*/
protected function _buildIframe() {
$source = $this->_stub['iframe-player'];
$count = count($this->_match);

for ($i = 1; $i <= count($this->_match); $i++) {
for ($i = 1; $i <= $count; $i++) {
$source = str_ireplace('$' . $i, $this->_match[$i - 1], $source);
}

//add custom params
if ($this->_iframeParams) {
$c = '?';
if (strpos($source, '?') !== false) $c = '&amp;';
if (strpos($source, '?') !== false) {
$c = '&amp;';
}
$source .= $c . http_build_query($this->_iframeParams, '', '&amp;');
}
$attributes = '';
Expand Down Expand Up @@ -535,8 +541,9 @@ protected function _buildIframe() {
protected function _setDefaultParams($stub) {
$source = $stub['embed-src'];
$flashvars = (isset($stub['flashvars'])) ? $stub['flashvars'] : null;
$count = count($this->_match);

for ($i = 1; $i <= count($this->_match); $i++) {
for ($i = 1; $i <= $count; $i++) {
$source = str_ireplace('$' . $i, $this->_match[$i - 1], $source);
$flashvars = str_ireplace('$' . $i, $this->_match[$i - 1], $flashvars);
}
Expand Down
2 changes: 1 addition & 1 deletion tests/MediaEmbed/MediaEmbedTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ class MediaEmbedTest extends \PHPUnit_Framework_TestCase {
'http://www.ustream.tv/channel/16962149' => '16962149',

'http://example.wistia.com/medias/1voyrefhy9' => '1voyrefhy9',

'http://rutube.ru/video/c1b3c6c6ee77def7a8e54553c1fabbb8/' => 'c1b3c6c6ee77def7a8e54553c1fabbb8',

// Not available anymore
Expand Down

0 comments on commit cfb7667

Please sign in to comment.