[phpcs] Add missing rules

- Do not add spaces after opening or before closing parenthesis

  // Wrong
  if( !is_null($var) ) {
    ...
  }

  // Right
  if(!is_null($var)) {
    ...
  }

- Add space after closing parenthesis

  // Wrong
  if(true){
    ...
  }

  // Right
  if(true) {
    ...
  }

- Add body into new line
- Close body in new line

  // Wrong
  if(true) { ... }

  // Right
  if(true) {
    ...
  }

Notice: Spaces after keywords are not detected:

  // Wrong (not detected)
  // -> space after 'if' and missing space after 'else'
  if (true) {
    ...
  } else{
    ...
  }

  // Right
  if(true) {
    ...
  } else {
    ...
  }
This commit is contained in:
logmanoriginal 2017-07-29 19:28:00 +02:00
parent 38b56bf23a
commit a4b9611e66
128 changed files with 692 additions and 694 deletions

View file

@ -24,7 +24,7 @@ class Bridge {
* @return Bridge object dedicated
*/
static public function create($nameBridge){
if(!preg_match('@^[A-Z][a-zA-Z0-9-]*$@', $nameBridge)){
if(!preg_match('@^[A-Z][a-zA-Z0-9-]*$@', $nameBridge)) {
$message = <<<EOD
'nameBridge' must start with one uppercase character followed or not by
alphanumeric or dash characters!
@ -35,14 +35,14 @@ EOD;
$nameBridge = $nameBridge . 'Bridge';
$pathBridge = self::getDir() . $nameBridge . '.php';
if(!file_exists($pathBridge)){
if(!file_exists($pathBridge)) {
throw new \Exception('The bridge you looking for does not exist. It should be at path '
. $pathBridge);
}
require_once $pathBridge;
if(Bridge::isInstantiable($nameBridge)){
if(Bridge::isInstantiable($nameBridge)) {
return new $nameBridge();
} else {
return false;
@ -50,11 +50,11 @@ EOD;
}
static public function setDir($dirBridge){
if(!is_string($dirBridge)){
if(!is_string($dirBridge)) {
throw new \InvalidArgumentException('Dir bridge must be a string.');
}
if(!file_exists($dirBridge)){
if(!file_exists($dirBridge)) {
throw new \Exception('Dir bridge does not exist.');
}
@ -64,7 +64,7 @@ EOD;
static public function getDir(){
$dirBridge = self::$dirBridge;
if(is_null($dirBridge)){
if(is_null($dirBridge)) {
throw new \LogicException(__CLASS__ . ' class need to know bridge path !');
}
@ -80,9 +80,9 @@ EOD;
$listBridge = array();
$dirFiles = scandir($pathDirBridge);
if($dirFiles !== false){
foreach($dirFiles as $fileName){
if(preg_match('@^([^.]+)Bridge\.php$@U', $fileName, $out)){
if($dirFiles !== false) {
foreach($dirFiles as $fileName) {
if(preg_match('@^([^.]+)Bridge\.php$@U', $fileName, $out)) {
$listBridge[] = $out[1];
}
}
@ -96,7 +96,7 @@ EOD;
|| in_array($name . '.php', $whitelist)
|| in_array($name . 'Bridge', $whitelist) // DEPRECATED
|| in_array($name . 'Bridge.php', $whitelist) // DEPRECATED
|| (count($whitelist) === 1 && trim($whitelist[0]) === '*')){
|| (count($whitelist) === 1 && trim($whitelist[0]) === '*')) {
return true;
} else {
return false;

View file

@ -43,9 +43,9 @@ abstract class BridgeAbstract implements BridgeInterface {
*/
protected function setInputs(array $inputs, $queriedContext){
// Import and assign all inputs to their context
foreach($inputs as $name => $value){
foreach(static::PARAMETERS as $context => $set){
if(array_key_exists($name, static::PARAMETERS[$context])){
foreach($inputs as $name => $value) {
foreach(static::PARAMETERS as $context => $set) {
if(array_key_exists($name, static::PARAMETERS[$context])) {
$this->inputs[$context][$name]['value'] = $value;
}
}
@ -53,30 +53,30 @@ abstract class BridgeAbstract implements BridgeInterface {
// Apply default values to missing data
$contexts = array($queriedContext);
if(array_key_exists('global', static::PARAMETERS)){
if(array_key_exists('global', static::PARAMETERS)) {
$contexts[] = 'global';
}
foreach($contexts as $context){
foreach(static::PARAMETERS[$context] as $name => $properties){
if(isset($this->inputs[$context][$name]['value'])){
foreach($contexts as $context) {
foreach(static::PARAMETERS[$context] as $name => $properties) {
if(isset($this->inputs[$context][$name]['value'])) {
continue;
}
$type = isset($properties['type']) ? $properties['type'] : 'text';
switch($type){
switch($type) {
case 'checkbox':
if(!isset($properties['defaultValue'])){
if(!isset($properties['defaultValue'])) {
$this->inputs[$context][$name]['value'] = false;
} else {
$this->inputs[$context][$name]['value'] = $properties['defaultValue'];
}
break;
case 'list':
if(!isset($properties['defaultValue'])){
if(!isset($properties['defaultValue'])) {
$firstItem = reset($properties['values']);
if(is_array($firstItem)){
if(is_array($firstItem)) {
$firstItem = reset($firstItem);
}
$this->inputs[$context][$name]['value'] = $firstItem;
@ -85,7 +85,7 @@ abstract class BridgeAbstract implements BridgeInterface {
}
break;
default:
if(isset($properties['defaultValue'])){
if(isset($properties['defaultValue'])) {
$this->inputs[$context][$name]['value'] = $properties['defaultValue'];
}
break;
@ -94,11 +94,11 @@ abstract class BridgeAbstract implements BridgeInterface {
}
// Copy global parameter values to the guessed context
if(array_key_exists('global', static::PARAMETERS)){
foreach(static::PARAMETERS['global'] as $name => $properties){
if(isset($inputs[$name])){
if(array_key_exists('global', static::PARAMETERS)) {
foreach(static::PARAMETERS['global'] as $name => $properties) {
if(isset($inputs[$name])) {
$value = $inputs[$name];
} elseif(isset($properties['value'])){
} elseif(isset($properties['value'])) {
$value = $properties['value'];
} else {
continue;
@ -108,7 +108,7 @@ abstract class BridgeAbstract implements BridgeInterface {
}
// Only keep guessed context parameters values
if(isset($this->inputs[$queriedContext])){
if(isset($this->inputs[$queriedContext])) {
$this->inputs = array($queriedContext => $this->inputs[$queriedContext]);
} else {
$this->inputs = array();
@ -125,15 +125,15 @@ abstract class BridgeAbstract implements BridgeInterface {
$queriedContexts = array();
// Detect matching context
foreach(static::PARAMETERS as $context => $set){
foreach(static::PARAMETERS as $context => $set) {
$queriedContexts[$context] = null;
// Check if all parameters of the context are satisfied
foreach($set as $id => $properties){
if(isset($inputs[$id]) && !empty($inputs[$id])){
foreach($set as $id => $properties) {
if(isset($inputs[$id]) && !empty($inputs[$id])) {
$queriedContexts[$context] = true;
} elseif(isset($properties['required'])
&& $properties['required'] === true){
&& $properties['required'] === true) {
$queriedContexts[$context] = false;
break;
}
@ -143,15 +143,15 @@ abstract class BridgeAbstract implements BridgeInterface {
// Abort if one of the globally required parameters is not satisfied
if(array_key_exists('global', static::PARAMETERS)
&& $queriedContexts['global'] === false){
&& $queriedContexts['global'] === false) {
return null;
}
unset($queriedContexts['global']);
switch(array_sum($queriedContexts)){
switch(array_sum($queriedContexts)) {
case 0: // Found no match, is there a context without parameters?
foreach($queriedContexts as $context => $queried){
if(is_null($queried)){
foreach($queriedContexts as $context => $queried) {
if(is_null($queried)) {
return $context;
}
}
@ -168,13 +168,13 @@ abstract class BridgeAbstract implements BridgeInterface {
* @param array array with expected bridge paramters
*/
public function setDatas(array $inputs){
if(!is_null($this->cache)){
if(!is_null($this->cache)) {
$time = $this->cache->getTime();
if($time !== false
&& (time() - static::CACHE_TIMEOUT < $time)
&& (!defined('DEBUG') || DEBUG !== true)){
&& (!defined('DEBUG') || DEBUG !== true)) {
$cached = $this->cache->loadData();
if(isset($cached['items']) && isset($cached['extraInfos'])){
if(isset($cached['items']) && isset($cached['extraInfos'])) {
$this->items = $cached['items'];
$this->extraInfos = $cached['extraInfos'];
return;
@ -182,27 +182,27 @@ abstract class BridgeAbstract implements BridgeInterface {
}
}
if(empty(static::PARAMETERS)){
if(!empty($inputs)){
if(empty(static::PARAMETERS)) {
if(!empty($inputs)) {
returnClientError('Invalid parameters value(s)');
}
$this->collectData();
if(!is_null($this->cache)){
if(!is_null($this->cache)) {
$this->cache->saveData($this->getCachable());
}
return;
}
if(!validateData($inputs, static::PARAMETERS)){
if(!validateData($inputs, static::PARAMETERS)) {
returnClientError('Invalid parameters value(s)');
}
// Guess the paramter context from input data
$this->queriedContext = $this->getQueriedContext($inputs);
if(is_null($this->queriedContext)){
if(is_null($this->queriedContext)) {
returnClientError('Required parameter(s) missing');
} elseif($this->queriedContext === false){
} elseif($this->queriedContext === false) {
returnClientError('Mixed context parameters');
}
@ -210,7 +210,7 @@ abstract class BridgeAbstract implements BridgeInterface {
$this->collectData();
if(!is_null($this->cache)){
if(!is_null($this->cache)) {
$this->cache->saveData($this->getCachable());
}
}
@ -222,7 +222,7 @@ abstract class BridgeAbstract implements BridgeInterface {
* @return mixed Returns the input value or null if the input is not defined
*/
protected function getInput($input){
if(!isset($this->inputs[$this->queriedContext][$input]['value'])){
if(!isset($this->inputs[$this->queriedContext][$input]['value'])) {
return null;
}
return $this->inputs[$this->queriedContext][$input]['value'];
@ -238,7 +238,7 @@ abstract class BridgeAbstract implements BridgeInterface {
public function getName(){
// Return cached name when bridge is using cached data
if(isset($this->extraInfos)){
if(isset($this->extraInfos)) {
return $this->extraInfos['name'];
}
@ -251,7 +251,7 @@ abstract class BridgeAbstract implements BridgeInterface {
public function getURI(){
// Return cached uri when bridge is using cached data
if(isset($this->extraInfos)){
if(isset($this->extraInfos)) {
return $this->extraInfos['uri'];
}

View file

@ -9,14 +9,14 @@ class Cache {
}
static public function create($nameCache){
if(!static::isValidNameCache($nameCache)){
if(!static::isValidNameCache($nameCache)) {
throw new \InvalidArgumentException('Name cache must be at least one
uppercase follow or not by alphanumeric or dash characters.');
}
$pathCache = self::getDir() . $nameCache . '.php';
if(!file_exists($pathCache)){
if(!file_exists($pathCache)) {
throw new \Exception('The cache you looking for does not exist.');
}
@ -26,11 +26,11 @@ class Cache {
}
static public function setDir($dirCache){
if(!is_string($dirCache)){
if(!is_string($dirCache)) {
throw new \InvalidArgumentException('Dir cache must be a string.');
}
if(!file_exists($dirCache)){
if(!file_exists($dirCache)) {
throw new \Exception('Dir cache does not exist.');
}
@ -40,7 +40,7 @@ class Cache {
static public function getDir(){
$dirCache = self::$dirCache;
if(is_null($dirCache)){
if(is_null($dirCache)) {
throw new \LogicException(__CLASS__ . ' class need to know cache path !');
}

View file

@ -7,7 +7,7 @@ abstract class FeedExpander extends BridgeAbstract {
private $feedType;
public function collectExpandableDatas($url, $maxItems = -1){
if(empty($url)){
if(empty($url)) {
returnServerError('There is no $url for this RSS expander');
}
@ -21,7 +21,7 @@ abstract class FeedExpander extends BridgeAbstract {
$rssContent = simplexml_load_string($content);
debugMessage('Detecting feed format/version');
switch(true){
switch(true) {
case isset($rssContent->item[0]):
debugMessage('Detected RSS 1.0 format');
$this->feedType = "RSS_1_0";
@ -46,7 +46,7 @@ abstract class FeedExpander extends BridgeAbstract {
protected function collect_RSS_1_0_data($rssContent, $maxItems){
$this->load_RSS_2_0_feed_data($rssContent->channel[0]);
foreach($rssContent->item as $item){
foreach($rssContent->item as $item) {
debugMessage('parsing item ' . var_export($item, true));
$tmp_item = $this->parseItem($item);
if (!empty($tmp_item)) {
@ -63,7 +63,7 @@ abstract class FeedExpander extends BridgeAbstract {
. '===========');
$this->load_RSS_2_0_feed_data($rssContent);
foreach($rssContent->item as $item){
foreach($rssContent->item as $item) {
debugMessage('parsing item ' . var_export($item, true));
$tmp_item = $this->parseItem($item);
if (!empty($tmp_item)) {
@ -75,7 +75,7 @@ abstract class FeedExpander extends BridgeAbstract {
protected function collect_ATOM_1_0_data($content, $maxItems){
$this->load_ATOM_feed_data($content);
foreach($content->entry as $item){
foreach($content->entry as $item) {
debugMessage('parsing item ' . var_export($item, true));
$tmp_item = $this->parseItem($item);
if (!empty($tmp_item)) {
@ -99,14 +99,14 @@ abstract class FeedExpander extends BridgeAbstract {
$this->name = (string)$content->title;
// Find best link (only one, or first of 'alternate')
if(!isset($content->link)){
if(!isset($content->link)) {
$this->uri = '';
} elseif (count($content->link) === 1){
} elseif (count($content->link) === 1) {
$this->uri = $content->link[0]['href'];
} else {
$this->uri = '';
foreach($content->link as $link){
if(strtolower($link['rel']) === 'alternate'){
foreach($content->link as $link) {
if(strtolower($link['rel']) === 'alternate') {
$this->uri = $link['href'];
break;
}
@ -139,7 +139,7 @@ abstract class FeedExpander extends BridgeAbstract {
$item = $this->parseRSS_0_9_1_Item($feedItem);
$namespaces = $feedItem->getNamespaces(true);
if(isset($namespaces['dc'])){
if(isset($namespaces['dc'])) {
$dc = $feedItem->children($namespaces['dc']);
if(isset($dc->date)) $item['timestamp'] = strtotime((string)$dc->date);
if(isset($dc->creator)) $item['author'] = (string)$dc->creator;
@ -155,24 +155,24 @@ abstract class FeedExpander extends BridgeAbstract {
$namespaces = $feedItem->getNamespaces(true);
if(isset($namespaces['dc'])) $dc = $feedItem->children($namespaces['dc']);
if(isset($feedItem->guid)){
foreach($feedItem->guid->attributes() as $attribute => $value){
if(isset($feedItem->guid)) {
foreach($feedItem->guid->attributes() as $attribute => $value) {
if($attribute === 'isPermaLink'
&& ($value === 'true' || filter_var($feedItem->guid, FILTER_VALIDATE_URL))){
&& ($value === 'true' || filter_var($feedItem->guid, FILTER_VALIDATE_URL))) {
$item['uri'] = (string)$feedItem->guid;
break;
}
}
}
if(isset($feedItem->pubDate)){
if(isset($feedItem->pubDate)) {
$item['timestamp'] = strtotime((string)$feedItem->pubDate);
} elseif(isset($dc->date)){
} elseif(isset($dc->date)) {
$item['timestamp'] = strtotime((string)$dc->date);
}
if(isset($feedItem->author)){
if(isset($feedItem->author)) {
$item['author'] = (string)$feedItem->author;
} elseif(isset($dc->creator)){
} elseif(isset($dc->creator)) {
$item['author'] = (string)$dc->creator;
}
return $item;
@ -184,7 +184,7 @@ abstract class FeedExpander extends BridgeAbstract {
* @return a RSS-Bridge Item, with (hopefully) the whole content)
*/
protected function parseItem($item){
switch($this->feedType){
switch($this->feedType) {
case 'RSS_1_0':
return $this->parseRSS_1_0_Item($item);
break;

View file

@ -9,7 +9,7 @@ class Format {
}
static public function create($nameFormat){
if(!preg_match('@^[A-Z][a-zA-Z]*$@', $nameFormat)){
if(!preg_match('@^[A-Z][a-zA-Z]*$@', $nameFormat)) {
throw new \InvalidArgumentException('Name format must be at least
one uppercase follow or not by alphabetic characters.');
}
@ -17,7 +17,7 @@ class Format {
$nameFormat = $nameFormat . 'Format';
$pathFormat = self::getDir() . $nameFormat . '.php';
if(!file_exists($pathFormat)){
if(!file_exists($pathFormat)) {
throw new \Exception('The format you looking for does not exist.');
}
@ -27,11 +27,11 @@ class Format {
}
static public function setDir($dirFormat){
if(!is_string($dirFormat)){
if(!is_string($dirFormat)) {
throw new \InvalidArgumentException('Dir format must be a string.');
}
if(!file_exists($dirFormat)){
if(!file_exists($dirFormat)) {
throw new \Exception('Dir format does not exist.');
}
@ -41,7 +41,7 @@ class Format {
static public function getDir(){
$dirFormat = self::$dirFormat;
if(is_null($dirFormat)){
if(is_null($dirFormat)) {
throw new \LogicException(__CLASS__ . ' class need to know format path !');
}
@ -60,9 +60,9 @@ class Format {
$searchCommonPattern = array('name');
$dirFiles = scandir($pathDirFormat);
if($dirFiles !== false){
foreach($dirFiles as $fileName){
if(preg_match('@^([^.]+)Format\.php$@U', $fileName, $out)){ // Is PHP file ?
if($dirFiles !== false) {
foreach($dirFiles as $fileName) {
if(preg_match('@^([^.]+)Format\.php$@U', $fileName, $out)) { // Is PHP file ?
$listFormat[] = $out[1];
}
}

View file

@ -56,8 +56,8 @@ abstract class FormatAbstract implements FormatInterface {
* @return this
*/
public function setExtraInfos(array $extraInfos = array()){
foreach(array('name', 'uri') as $infoName){
if( !isset($extraInfos[$infoName]) ){
foreach(array('name', 'uri') as $infoName) {
if(!isset($extraInfos[$infoName])) {
$extraInfos[$infoName] = '';
}
}
@ -72,7 +72,7 @@ abstract class FormatAbstract implements FormatInterface {
* @return array See "setExtraInfos" detail method to know what extra are disponibles
*/
public function getExtraInfos(){
if( is_null($this->extraInfos) ){ // No extra info ?
if(is_null($this->extraInfos)) { // No extra info ?
$this->setExtraInfos(); // Define with default value
}
@ -97,7 +97,7 @@ abstract class FormatAbstract implements FormatInterface {
}
protected function array_trim($elements){
foreach($elements as $key => $value){
foreach($elements as $key => $value) {
if(is_string($value))
$elements[$key] = trim($value);
}

View file

@ -21,7 +21,7 @@ require __DIR__ . '/error.php';
require __DIR__ . '/contents.php';
$vendorLibSimpleHtmlDom = __DIR__ . PATH_VENDOR . '/simplehtmldom/simple_html_dom.php';
if(!file_exists($vendorLibSimpleHtmlDom)){
if(!file_exists($vendorLibSimpleHtmlDom)) {
throw new \HttpException('"PHP Simple HTML DOM Parser" library is missing.
Get it from http://simplehtmldom.sourceforge.net and place the script "simple_html_dom.php" in '
. substr(PATH_VENDOR, 4)

View file

@ -11,21 +11,21 @@ $maxlen = null){
)
);
if(defined('PROXY_URL') && !defined('NOPROXY')){
if(defined('PROXY_URL') && !defined('NOPROXY')) {
$contextOptions['http']['proxy'] = PROXY_URL;
$contextOptions['http']['request_fulluri'] = true;
if(is_null($context)){
if(is_null($context)) {
$context = stream_context_create($contextOptions);
} else {
$prevContext = $context;
if(!stream_context_set_option($context, $contextOptions)){
if(!stream_context_set_option($context, $contextOptions)) {
$context = $prevContext;
}
}
}
if(is_null($maxlen)){
if(is_null($maxlen)) {
$content = file_get_contents($url, $use_include_path, $context, $offset);
} else {
$content = file_get_contents($url, $use_include_path, $context, $offset, $maxlen);
@ -35,9 +35,9 @@ $maxlen = null){
debugMessage('Cant\'t download ' . $url);
// handle compressed data
foreach($http_response_header as $header){
if(stristr($header, 'content-encoding')){
switch(true){
foreach($http_response_header as $header) {
if(stristr($header, 'content-encoding')) {
switch(true) {
case stristr($header, 'gzip'):
$content = gzinflate(substr($content, 10, -8));
break;
@ -113,11 +113,11 @@ $defaultSpanText = DEFAULT_SPAN_TEXT){
$time = $cache->getTime();
if($time !== false
&& (time() - $duration < $time)
&& (!defined('DEBUG') || DEBUG !== true)){ // Contents within duration
&& (!defined('DEBUG') || DEBUG !== true)) { // Contents within duration
$content = $cache->loadData();
} else { // Content not within duration
$content = getContents($url, $use_include_path, $context, $offset, $maxLen);
if($content !== false){
if($content !== false) {
$cache->saveData($content);
}
}

View file

@ -3,7 +3,7 @@ function displayBridgeCard($bridgeName, $formats, $isActive = true){
$getHelperButtonsFormat = function($formats){
$buttons = '';
foreach($formats as $name){
foreach($formats as $name) {
$buttons .= '<button type="submit" name="format" value="'
. $name
. '">'
@ -50,13 +50,13 @@ EOD;
CARD;
// If we don't have any parameter for the bridge, we print a generic form to load it.
if(count($bridge->getParameters()) == 0){
if(count($bridge->getParameters()) == 0) {
$card .= $getFormHeader($bridgeName);
$card .= $HTTPSWarning;
if($isActive){
if(defined('PROXY_URL') && PROXY_BYBRIDGE){
if($isActive) {
if(defined('PROXY_URL') && PROXY_BYBRIDGE) {
$idArg = 'arg-'
. urlencode($bridgeName)
. '-'
@ -87,11 +87,11 @@ CARD;
$hasGlobalParameter = array_key_exists('global', $bridge->getParameters());
if($hasGlobalParameter){
if($hasGlobalParameter) {
$globalParameters = $bridge->getParameters()['global'];
}
foreach($bridge->getParameters() as $parameterName => $parameter){
foreach($bridge->getParameters() as $parameterName => $parameter) {
if(!is_numeric($parameterName) && $parameterName == 'global')
continue;
@ -104,7 +104,7 @@ CARD;
$card .= $getFormHeader($bridgeName);
$card .= $HTTPSWarning;
foreach($parameter as $id => $inputEntry){
foreach($parameter as $id => $inputEntry) {
$additionalInfoString = '';
if(isset($inputEntry['required']) && $inputEntry['required'] === true)
@ -136,7 +136,7 @@ CARD;
. ' : </label>'
. PHP_EOL;
if(!isset($inputEntry['type']) || $inputEntry['type'] == 'text'){
if(!isset($inputEntry['type']) || $inputEntry['type'] == 'text') {
$card .= '<input '
. $additionalInfoString
. ' id="'
@ -149,7 +149,7 @@ CARD;
. $id
. '" /><br />'
. PHP_EOL;
} elseif($inputEntry['type'] == 'number'){
} elseif($inputEntry['type'] == 'number') {
$card .= '<input '
. $additionalInfoString
. ' id="'
@ -162,7 +162,7 @@ CARD;
. $id
. '" /><br />'
. PHP_EOL;
} else if($inputEntry['type'] == 'list'){
} else if($inputEntry['type'] == 'list') {
$card .= '<select '
. $additionalInfoString
. ' id="'
@ -171,12 +171,12 @@ CARD;
. $id
. '" >';
foreach($inputEntry['values'] as $name => $value){
if(is_array($value)){
foreach($inputEntry['values'] as $name => $value) {
if(is_array($value)) {
$card .= '<optgroup label="' . htmlentities($name) . '">';
foreach($value as $subname => $subvalue){
foreach($value as $subname => $subvalue) {
if($inputEntry['defaultValue'] === $subname
|| $inputEntry['defaultValue'] === $subvalue){
|| $inputEntry['defaultValue'] === $subvalue) {
$card .= '<option value="'
. $subvalue
. '" selected>'
@ -193,7 +193,7 @@ CARD;
$card .= '</optgroup>';
} else {
if($inputEntry['defaultValue'] === $name
|| $inputEntry['defaultValue'] === $value){
|| $inputEntry['defaultValue'] === $value) {
$card .= '<option value="'
. $value
. '" selected>'
@ -209,7 +209,7 @@ CARD;
}
}
$card .= '</select><br >';
} elseif($inputEntry['type'] == 'checkbox'){
} elseif($inputEntry['type'] == 'checkbox') {
if($inputEntry['defaultValue'] === 'checked')
$card .= '<input '
. $additionalInfoString
@ -231,8 +231,8 @@ CARD;
}
}
if($isActive){
if(defined('PROXY_URL') && PROXY_BYBRIDGE){
if($isActive) {
if(defined('PROXY_URL') && PROXY_BYBRIDGE) {
$idArg = 'arg-'
. urlencode($bridgeName)
. '-'
@ -272,13 +272,13 @@ $keptAttributes = array('title', 'href', 'src'),
$keptText = array()){
$htmlContent = str_get_html($textToSanitize);
foreach($htmlContent->find('*[!b38fd2b1fe7f4747d6b1c1254ccd055e]') as $element){
if(in_array($element->tag, $keptText)){
foreach($htmlContent->find('*[!b38fd2b1fe7f4747d6b1c1254ccd055e]') as $element) {
if(in_array($element->tag, $keptText)) {
$element->outertext = $element->plaintext;
} elseif(in_array($element->tag, $removedTags)){
} elseif(in_array($element->tag, $removedTags)) {
$element->outertext = '';
} else {
foreach($element->getAllAttributes() as $attributeName => $attribute){
foreach($element->getAllAttributes() as $attributeName => $attribute) {
if(!in_array($attributeName, $keptAttributes))
$element->removeAttribute($attributeName);
}
@ -308,14 +308,14 @@ function backgroundToImg($htmlContent) {
}
function defaultLinkTo($content, $server){
foreach($content->find('img') as $image){
foreach($content->find('img') as $image) {
if(strpos($image->src, 'http') === false
&& strpos($image->src, '//') === false
&& strpos($image->src, 'data:') === false)
$image->src = $server . $image->src;
}
foreach($content->find('a') as $anchor){
foreach($content->find('a') as $anchor) {
if(strpos($anchor->href, 'http') === false
&& strpos($anchor->href, '//') === false
&& strpos($anchor->href, '#') !== 0

View file

@ -1,7 +1,7 @@
<?php
function validateData(&$data, $parameters){
$validateTextValue = function($value, $pattern = null){
if(!is_null($pattern)){
if(!is_null($pattern)) {
$filteredValue = filter_var($value,
FILTER_VALIDATE_REGEXP,
array('options' => array(
@ -42,8 +42,8 @@ function validateData(&$data, $parameters){
if($filteredValue === false)
return null;
if(!in_array($filteredValue, $expectedValues)){ // Check sub-values?
foreach($expectedValues as $subName => $subValue){
if(!in_array($filteredValue, $expectedValues)) { // Check sub-values?
foreach($expectedValues as $subName => $subValue) {
if(is_array($subValue) && in_array($filteredValue, $subValue))
return $filteredValue;
}
@ -56,16 +56,16 @@ function validateData(&$data, $parameters){
if(!is_array($data))
return false;
foreach($data as $name => $value){
foreach($data as $name => $value) {
$registered = false;
foreach($parameters as $context => $set){
if(array_key_exists($name, $set)){
foreach($parameters as $context => $set) {
if(array_key_exists($name, $set)) {
$registered = true;
if(!isset($set[$name]['type'])){
if(!isset($set[$name]['type'])) {
$set[$name]['type'] = 'text';
}
switch($set[$name]['type']){
switch($set[$name]['type']) {
case 'number':
$data[$name] = $validateNumberValue($value);
break;
@ -77,7 +77,7 @@ function validateData(&$data, $parameters){
break;
default:
case 'text':
if(isset($set[$name]['pattern'])){
if(isset($set[$name]['pattern'])) {
$data[$name] = $validateTextValue($value, $set[$name]['pattern']);
} else {
$data[$name] = $validateTextValue($value);
@ -85,7 +85,7 @@ function validateData(&$data, $parameters){
break;
}
if(is_null($data[$name])){
if(is_null($data[$name])) {
echo 'Parameter \'' . $name . '\' is invalid!' . PHP_EOL;
return false;
}