mirror of
https://github.com/joomla-extensions/jedchecker.git
synced 2024-09-28 04:59:04 +00:00
apply code style (spaces to tabs)
This commit is contained in:
parent
4d67fe0602
commit
75d8daa931
@ -27,132 +27,132 @@ require_once JPATH_COMPONENT_ADMINISTRATOR . '/models/rule.php';
|
|||||||
*/
|
*/
|
||||||
class JedcheckerRulesLanguage extends JEDcheckerRule
|
class JedcheckerRulesLanguage extends JEDcheckerRule
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* The formal ID of this rule. For example: SE1.
|
* The formal ID of this rule. For example: SE1.
|
||||||
*
|
*
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
protected $id = 'LANG';
|
protected $id = 'LANG';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The title or caption of this rule.
|
* The title or caption of this rule.
|
||||||
*
|
*
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
protected $title = 'COM_JEDCHECKER_LANG';
|
protected $title = 'COM_JEDCHECKER_LANG';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The description of this rule.
|
* The description of this rule.
|
||||||
*
|
*
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
protected $description = 'COM_JEDCHECKER_LANG_DESC';
|
protected $description = 'COM_JEDCHECKER_LANG_DESC';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initiates the search and check
|
* Initiates the search and check
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function check()
|
public function check()
|
||||||
{
|
{
|
||||||
// Find all INI files of the extension (in the format tag.extension.ini or tag.extension.sys.ini)
|
// Find all INI files of the extension (in the format tag.extension.ini or tag.extension.sys.ini)
|
||||||
$files = JFolder::files($this->basedir, '^[a-z]{2,3}-[A-Z]{2}\.\w+(?:\.sys)?\.ini$', true, true);
|
$files = JFolder::files($this->basedir, '^[a-z]{2,3}-[A-Z]{2}\.\w+(?:\.sys)?\.ini$', true, true);
|
||||||
|
|
||||||
// Iterate through all the ini files
|
// Iterate through all the ini files
|
||||||
foreach ($files as $file)
|
foreach ($files as $file)
|
||||||
{
|
{
|
||||||
// Try to validate the file
|
// Try to validate the file
|
||||||
$this->find($file);
|
$this->find($file);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reads and validates an ini file
|
* Reads and validates an ini file
|
||||||
*
|
*
|
||||||
* @param string $file - The path to the file
|
* @param string $file - The path to the file
|
||||||
*
|
*
|
||||||
* @return bool True on success, otherwise False.
|
* @return bool True on success, otherwise False.
|
||||||
*/
|
*/
|
||||||
protected function find($file)
|
protected function find($file)
|
||||||
{
|
{
|
||||||
$lines = file($file);
|
$lines = file($file);
|
||||||
foreach ($lines as $lineno => $line)
|
foreach ($lines as $lineno => $line)
|
||||||
{
|
{
|
||||||
$line = trim($line);
|
$line = trim($line);
|
||||||
if ($line === '' || $line[0] === ';' || $line[0] === '[')
|
if ($line === '' || $line[0] === ';' || $line[0] === '[')
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if ($line[0] === '#')
|
if ($line[0] === '#')
|
||||||
{
|
{
|
||||||
$this->report->addError($file, JText::_('COM_JEDCHECKER_LANG_INCORRECT_COMMENT') .
|
$this->report->addError($file, JText::_('COM_JEDCHECKER_LANG_INCORRECT_COMMENT') .
|
||||||
'<br>' . htmlspecialchars($line), $lineno);
|
'<br>' . htmlspecialchars($line), $lineno);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (strpos($line, '=') === false)
|
if (strpos($line, '=') === false)
|
||||||
{
|
{
|
||||||
$this->report->addError($file, JText::_('COM_JEDCHECKER_LANG_WRONG_LINE') .
|
$this->report->addError($file, JText::_('COM_JEDCHECKER_LANG_WRONG_LINE') .
|
||||||
'<br>' . htmlspecialchars($line), $lineno);
|
'<br>' . htmlspecialchars($line), $lineno);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
list ($key, $value) = explode('=', $line, 2);
|
list ($key, $value) = explode('=', $line, 2);
|
||||||
|
|
||||||
$key = rtrim($key);
|
$key = rtrim($key);
|
||||||
if ($key === '')
|
if ($key === '')
|
||||||
{
|
{
|
||||||
$this->report->addError($file, JText::_('COM_JEDCHECKER_LANG_KEY_EMPTY') .
|
$this->report->addError($file, JText::_('COM_JEDCHECKER_LANG_KEY_EMPTY') .
|
||||||
'<br>' . htmlspecialchars($line), $lineno);
|
'<br>' . htmlspecialchars($line), $lineno);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (strpos($key, ' ') !== false)
|
if (strpos($key, ' ') !== false)
|
||||||
{
|
{
|
||||||
$this->report->addError($file, JText::_('COM_JEDCHECKER_LANG_KEY_WHITESPACE') .
|
$this->report->addError($file, JText::_('COM_JEDCHECKER_LANG_KEY_WHITESPACE') .
|
||||||
'<br>' . htmlspecialchars($line), $lineno);
|
'<br>' . htmlspecialchars($line), $lineno);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (strpbrk($key, '{}|&~![()^"') !== false)
|
if (strpbrk($key, '{}|&~![()^"') !== false)
|
||||||
{
|
{
|
||||||
$this->report->addError($file, JText::_('COM_JEDCHECKER_LANG_KEY_INVALID_CHARACTER') .
|
$this->report->addError($file, JText::_('COM_JEDCHECKER_LANG_KEY_INVALID_CHARACTER') .
|
||||||
'<br>' . htmlspecialchars($line), $lineno);
|
'<br>' . htmlspecialchars($line), $lineno);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (in_array($key, array('null', 'yes', 'no', 'true', 'false', 'on', 'off', 'none'), true))
|
if (in_array($key, array('null', 'yes', 'no', 'true', 'false', 'on', 'off', 'none'), true))
|
||||||
{
|
{
|
||||||
$this->report->addError($file, JText::_('COM_JEDCHECKER_LANG_KEY_RESERVED') .
|
$this->report->addError($file, JText::_('COM_JEDCHECKER_LANG_KEY_RESERVED') .
|
||||||
'<br>' . htmlspecialchars($line), $lineno);
|
'<br>' . htmlspecialchars($line), $lineno);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
$value = ltrim($value);
|
$value = ltrim($value);
|
||||||
if (strlen($value) <2 || $value[0] !== '"' || substr($value, -1) !== '"')
|
if (strlen($value) <2 || $value[0] !== '"' || substr($value, -1) !== '"')
|
||||||
{
|
{
|
||||||
$this->report->addError($file, JText::_('COM_JEDCHECKER_LANG_TRANSLATION_QUOTES') .
|
$this->report->addError($file, JText::_('COM_JEDCHECKER_LANG_TRANSLATION_QUOTES') .
|
||||||
'<br>' . htmlspecialchars($line), $lineno);
|
'<br>' . htmlspecialchars($line), $lineno);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if ($value === '""')
|
if ($value === '""')
|
||||||
{
|
{
|
||||||
$this->report->addWarning($file, JText::_('COM_JEDCHECKER_LANG_TRANSLATION_EMPTY') .
|
$this->report->addWarning($file, JText::_('COM_JEDCHECKER_LANG_TRANSLATION_EMPTY') .
|
||||||
'<br>' . htmlspecialchars($line), $lineno);
|
'<br>' . htmlspecialchars($line), $lineno);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
$value = substr($value, 1, -1);
|
$value = substr($value, 1, -1);
|
||||||
if (strpos($value, '"_QQ_"') !== false)
|
if (strpos($value, '"_QQ_"') !== false)
|
||||||
{
|
{
|
||||||
$this->report->addInfo($file, JText::_('COM_JEDCHECKER_LANG_QQ_DEPRECATED') .
|
$this->report->addInfo($file, JText::_('COM_JEDCHECKER_LANG_QQ_DEPRECATED') .
|
||||||
'<br>' . htmlspecialchars($line), $lineno);
|
'<br>' . htmlspecialchars($line), $lineno);
|
||||||
}
|
}
|
||||||
|
|
||||||
$count1 = preg_match_all('/(?<=^|[^%])%(?=[-+0 ]?\w)/', $value);
|
$count1 = preg_match_all('/(?<=^|[^%])%(?=[-+0 ]?\w)/', $value);
|
||||||
$count2 = preg_match_all('/(?<=^|[^%])%\d+\$/', $value);
|
$count2 = preg_match_all('/(?<=^|[^%])%\d+\$/', $value);
|
||||||
if ($count1 > 1 && $count2 < $count1) {
|
if ($count1 > 1 && $count2 < $count1) {
|
||||||
// @todo It's not mentioned in docs
|
// @todo It's not mentioned in docs
|
||||||
$this->report->addInfo($file, JText::_('COM_JEDCHECKER_LANG_RECOMMEND_ARGNUM') .
|
$this->report->addInfo($file, JText::_('COM_JEDCHECKER_LANG_RECOMMEND_ARGNUM') .
|
||||||
'<br>' . htmlspecialchars($line), $lineno);
|
'<br>' . htmlspecialchars($line), $lineno);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// All checks passed. Return true
|
// All checks passed. Return true
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user