summaryrefslogtreecommitdiffstats
path: root/articleenhancer
diff options
context:
space:
mode:
authorBernhard Posselt <dev@bernhard-posselt.com>2014-10-21 18:19:23 +0200
committerBernhard Posselt <dev@bernhard-posselt.com>2014-10-21 18:19:23 +0200
commit66c73a96ac2dda076bcfe0dc0a1ca2a7e169149d (patch)
treedc0318fa459e4f313217ee38e4bc63524513d721 /articleenhancer
parentf5e64d35c05b14016eb4fffff7199386a97a9b43 (diff)
first try to set indention limit at 80 characters in php
Diffstat (limited to 'articleenhancer')
-rw-r--r--articleenhancer/globalarticleenhancer.php3
-rw-r--r--articleenhancer/xpatharticleenhancer.php26
2 files changed, 18 insertions, 11 deletions
diff --git a/articleenhancer/globalarticleenhancer.php b/articleenhancer/globalarticleenhancer.php
index b556a285a..4c01a238c 100644
--- a/articleenhancer/globalarticleenhancer.php
+++ b/articleenhancer/globalarticleenhancer.php
@@ -49,7 +49,8 @@ class GlobalArticleEnhancer implements ArticleEnhancer {
// src needs to be matched against regex to prevent false positives
// and because theres no XPath matches function available
$src = $element->getAttribute('src');
- $regex = '%^(http://|https://|//)(www\.)?youtube.com/.*\?.*autoplay=1.*%i';
+ $regex = '%^(http://|https://|//)(www\.)?youtube.com/' .
+ '.*\?.*autoplay=1.*%i';
if (preg_match($regex, $src)) {
$replaced = str_replace('autoplay=1', 'autoplay=0', $src);
diff --git a/articleenhancer/xpatharticleenhancer.php b/articleenhancer/xpatharticleenhancer.php
index 7d80868f5..7dcb9a340 100644
--- a/articleenhancer/xpatharticleenhancer.php
+++ b/articleenhancer/xpatharticleenhancer.php
@@ -64,8 +64,10 @@ class XPathArticleEnhancer implements ArticleEnhancer {
$contentType = $file->headers['content-type'];
$body = $file->body;
- if( preg_match( '/(?<=charset=)[^;]*/', $contentType, $matches ) ) {
- $body = mb_convert_encoding($body, 'HTML-ENTITIES', $matches[0]);
+ if(preg_match('/(?<=charset=)[^;]*/', $contentType, $matches)) {
+ $encoding = $matches[0];
+ $body = mb_convert_encoding($body, 'HTML-ENTITIES',
+ $encoding);
}
$dom = new DOMDocument();
@@ -86,7 +88,9 @@ class XPathArticleEnhancer implements ArticleEnhancer {
$xpathResult = trim($xpathResult);
// convert all relative to absolute URLs
- $xpathResult = $this->substituteRelativeLinks($xpathResult, $item->getUrl());
+ $xpathResult = $this->substituteRelativeLinks(
+ $xpathResult, $item->getUrl()
+ );
if($xpathResult) {
$item->setBody($xpathResult);
@@ -108,8 +112,10 @@ class XPathArticleEnhancer implements ArticleEnhancer {
/**
* Method which converts all relative "href" and "src" URLs of
* a HTML snippet with their absolute equivalent
- * @param string $xmlString a HTML snippet as string with the relative URLs to be replaced
- * @param string $absoluteUrl the approptiate absolute url of the HTML snippet
+ * @param string $xmlString a HTML snippet as string with the relative URLs
+ * to be replaced
+ * @param string $absoluteUrl the approptiate absolute url of the HTML
+ * snippet
* @return string the result HTML snippet as a string
*/
protected function substituteRelativeLinks($xmlString, $absoluteUrl) {
@@ -136,14 +142,17 @@ class XPathArticleEnhancer implements ArticleEnhancer {
"and not(starts-with(@" . $attribute . ", '//'))]");
foreach ($xpathResult as $linkNode) {
$urlElement = $linkNode->attributes->getNamedItem($attribute);
- $abs = $this->relativeToAbsoluteUrl($urlElement->nodeValue, $absoluteUrl);
+ $abs = $this->relativeToAbsoluteUrl(
+ $urlElement->nodeValue, $absoluteUrl
+ );
$urlElement->nodeValue = htmlspecialchars($abs);
}
}
$xmlString = $dom->saveHTML();
- // domdocument spoils the string with line breaks between the elements. strip them.
+ // domdocument spoils the string with line breaks between the elements
+ // strip them
$xmlString = str_replace("\n", '', $xmlString);
return $xmlString;
@@ -153,9 +162,6 @@ class XPathArticleEnhancer implements ArticleEnhancer {
/**
* Method which builds a URL by taking a relative URL and its corresponding
* absolute URL
- * For example relative URL "../example/path/file.php?a=1#anchor" and
- * absolute URL "https://username:password@www.website.com/subfolder/index.html"
- * will result in "https://username:password@www.website.com/example/path/file.php?a=1#anchor"
* @param string $relativeUrl the relative URL
* @param string $absoluteUrl the absolute URL with at least scheme and host
* @return string the resulting absolute URL