Fix simplexml calls

This commit is contained in:
Romain Neutron
2012-11-05 18:52:40 +01:00
parent 66c0e83ee7
commit da6f7a00c0
23 changed files with 56 additions and 66 deletions

View File

@@ -87,7 +87,7 @@ class Prod extends Helper
if ( ! $user->ACL()->has_right_on_sbas($sbas_id, 'bas_modif_th')) if ( ! $user->ACL()->has_right_on_sbas($sbas_id, 'bas_modif_th'))
continue; continue;
if (simplexml_load_string($databox->get_cterms())) { if (false !== simplexml_load_string($databox->get_cterms())) {
$bases[$sbas_id]['cterms'] = true; $bases[$sbas_id]['cterms'] = true;
} }
} }

View File

@@ -314,7 +314,7 @@ class Edit extends RecordHelper
$T_sgval['b' . $base_id] = array(); $T_sgval['b' . $base_id] = array();
$collection = \collection::get_from_base_id($base_id); $collection = \collection::get_from_base_id($base_id);
if ($sxe = simplexml_load_string($collection->get_prefs())) { if (false !== $sxe = simplexml_load_string($collection->get_prefs())) {
$z = $sxe->xpath('/baseprefs/sugestedValues'); $z = $sxe->xpath('/baseprefs/sugestedValues');
if ( ! $z || ! is_array($z)) if ( ! $z || ! is_array($z))

View File

@@ -354,8 +354,9 @@ class PDF
$collection = \collection::get_from_base_id($rec->get_base_id()); $collection = \collection::get_from_base_id($rec->get_base_id());
$vn = ""; $vn = "";
if ($str = simplexml_load_string($collection->get_prefs())) if (false !== $str = simplexml_load_string($collection->get_prefs())) {
$vn = (string) ($str->pdfPrintappear); $vn = (string) ($str->pdfPrintappear);
}
if ($vn == "" || $vn == "1") { if ($vn == "" || $vn == "1") {
$RIGHT_TEXT = \phrasea::bas_names($rec->get_base_id()); $RIGHT_TEXT = \phrasea::bas_names($rec->get_base_id());

View File

@@ -631,7 +631,7 @@ class Bridge_Api_Youtube extends Bridge_Api_Abstract implements Bridge_Api_Inter
$xml = simplexml_load_string($string); $xml = simplexml_load_string($string);
libxml_clear_errors(); libxml_clear_errors();
if ( ! $xml) { if (false === $xml) {
return false; return false;
} }
@@ -723,10 +723,9 @@ class Bridge_Api_Youtube extends Bridge_Api_Abstract implements Bridge_Api_Inter
$cat = array(); $cat = array();
$url_cat = sprintf('%s?hl=%s', self::CATEGORY_URL, $this->get_locale()); $url_cat = sprintf('%s?hl=%s', self::CATEGORY_URL, $this->get_locale());
$cxml = @simplexml_load_file($url_cat); if (false === $cxml = simplexml_load_file($url_cat)) {
if ( ! $cxml)
throw new Bridge_Exception_ApiConnectorRequestFailed('Failed to retrive youtube categories'); throw new Bridge_Exception_ApiConnectorRequestFailed('Failed to retrive youtube categories');
}
$cxml->registerXPathNamespace('atom', 'http://www.w3.org/2005/Atom'); $cxml->registerXPathNamespace('atom', 'http://www.w3.org/2005/Atom');
$categories = $cxml->xpath('//atom:category'); $categories = $cxml->xpath('//atom:category');

View File

@@ -397,10 +397,9 @@ abstract class base implements cache_cacheableInterface
return $this; return $this;
} }
$structure = simplexml_load_file(__DIR__ . "/../../lib/conf.d/bases_structure.xml"); if (false === $structure = simplexml_load_file(__DIR__ . "/../../lib/conf.d/bases_structure.xml")) {
if ( ! $structure)
throw new Exception('Unable to load schema'); throw new Exception('Unable to load schema');
}
if ($this->get_base_type() === self::APPLICATION_BOX) if ($this->get_base_type() === self::APPLICATION_BOX)
$this->schema = $structure->appbox; $this->schema = $structure->appbox;

View File

@@ -1040,7 +1040,7 @@ class databox extends base
$thesaurus = $this->get_thesaurus(); $thesaurus = $this->get_thesaurus();
if ($thesaurus && ($tmp = simplexml_load_string($thesaurus)) !== false) if ($thesaurus && false !== $tmp = simplexml_load_string($thesaurus))
self::$_sxml_thesaurus[$sbas_id] = $tmp; self::$_sxml_thesaurus[$sbas_id] = $tmp;
else else
self::$_sxml_thesaurus[$sbas_id] = false; self::$_sxml_thesaurus[$sbas_id] = false;
@@ -1205,7 +1205,7 @@ class databox extends base
$structure = $this->get_structure(); $structure = $this->get_structure();
if ($structure && ($tmp = simplexml_load_string($structure)) !== false) if ($structure && false !== $tmp = simplexml_load_string($structure))
$this->_sxml_structure = $tmp; $this->_sxml_structure = $tmp;
else else
$this->_sxml_structure = false; $this->_sxml_structure = false;

View File

@@ -75,7 +75,7 @@ class databox_status
$xmlpref = $databox->get_structure(); $xmlpref = $databox->get_structure();
$sxe = simplexml_load_string($xmlpref); $sxe = simplexml_load_string($xmlpref);
if ($sxe) { if ($sxe !== false) {
foreach ($sxe->statbits->bit as $sb) { foreach ($sxe->statbits->bit as $sb) {
$bit = (int) ($sb["n"]); $bit = (int) ($sb["n"]);

View File

@@ -111,7 +111,7 @@ function giveMeBases($usr = null)
$collInscript = $baseInscript; $collInscript = $baseInscript;
$defined = false; $defined = false;
$cguSpec = false; $cguSpec = false;
if ($xml = simplexml_load_string($collection->get_prefs())) { if (false !== $xml = simplexml_load_string($collection->get_prefs())) {
$defined = true; $defined = true;
foreach ($xml->xpath('/baseprefs/caninscript') as $caninscript) { foreach ($xml->xpath('/baseprefs/caninscript') as $caninscript) {
$tmp = (string) $caninscript; $tmp = (string) $caninscript;

View File

@@ -22,7 +22,7 @@ class geonames
$sxe = simplexml_load_string($xml); $sxe = simplexml_load_string($xml);
if ($sxe && ($geoname = $sxe->geoname)) { if ($sxe !== false && ($geoname = $sxe->geoname)) {
$ret = (string) $geoname->city . ', ' . (string) $geoname->country; $ret = (string) $geoname->city . ', ' . (string) $geoname->country;
} }
} }
@@ -46,7 +46,7 @@ class geonames
if ($xml) { if ($xml) {
$sxe = simplexml_load_string($xml); $sxe = simplexml_load_string($xml);
if ($sxe && ($geoname = $sxe->geoname)) { if ($sxe !== false && ($geoname = $sxe->geoname)) {
$ret = (string) $geoname->country; $ret = (string) $geoname->country;
} }
} }
@@ -67,7 +67,7 @@ class geonames
if ($xml) { if ($xml) {
$sxe = simplexml_load_string($xml); $sxe = simplexml_load_string($xml);
if ($sxe && ($geoname = $sxe->geoname)) { if ($sxe !== false && ($geoname = $sxe->geoname)) {
$ret = (string) $geoname->country_code; $ret = (string) $geoname->country_code;
} }
} }
@@ -150,7 +150,7 @@ class geonames
$xml = http_query::getUrl($url); $xml = http_query::getUrl($url);
if ($xml) { if ($xml) {
$sxe = simplexml_load_string($xml); $sxe = simplexml_load_string($xml);
if ($sxe && $sxe->geoname) { if ($sxe !== false && $sxe->geoname) {
$output['city'] = (string) $sxe->geoname->city; $output['city'] = (string) $sxe->geoname->city;
$output['country_code'] = (string) $sxe->geoname->country_code; $output['country_code'] = (string) $sxe->geoname->country_code;
$output['country'] = (string) $sxe->geoname->country; $output['country'] = (string) $sxe->geoname->country;

View File

@@ -81,7 +81,7 @@ class patch_370a8 implements patchInterface
* migrating task 'workflow01' or 'task_period_ftv' * migrating task 'workflow01' or 'task_period_ftv'
*/ */
$x = $task['settings']; $x = $task['settings'];
if (($sx = simplexml_load_string($x)) !== FALSE) { if (false !== $sx = simplexml_load_string($x)) {
$period = (int) ($sx->period); $period = (int) ($sx->period);
if ( ! array_key_exists('_' . $period, $tdom)) { if ( ! array_key_exists('_' . $period, $tdom)) {

View File

@@ -39,8 +39,8 @@ class queries
} }
$cssTopics = ''; $cssTopics = '';
if ($xmlTopics && ($sxTopics = simplexml_load_file($xmlTopics))) { if ($xmlTopics && false !== $sxTopics = simplexml_load_file($xmlTopics)) {
$cssTopics = (string) ($sxTopics->display->css); $cssTopics = (string) $sxTopics->display->css;
} }
$out .= '<style type="text/css"> $out .= '<style type="text/css">
@@ -108,7 +108,7 @@ class queries
$jsTopics = 'null'; $jsTopics = 'null';
$maxdepth = 0; $maxdepth = 0;
if (($sxTopics = simplexml_load_file($xmlTopics))) { if (false !== $sxTopics = simplexml_load_file($xmlTopics)) {
$jsTopics = self::topicsAsJS($sxTopics->topics, 0, $maxdepth); $jsTopics = self::topicsAsJS($sxTopics->topics, 0, $maxdepth);
} }

View File

@@ -617,7 +617,7 @@ class searchEngine_adapter_phrasea_engine extends searchEngine_adapter_abstract
$sxe = simplexml_load_string($res['xml']); $sxe = simplexml_load_string($res['xml']);
foreach ($fields as $name => $field) { foreach ($fields as $name => $field) {
if ($sxe && $sxe->description && $sxe->description->$name) { if (false !== $sxe && $sxe->description && $sxe->description->$name) {
$val = array(); $val = array();
foreach ($sxe->description->$name as $value) { foreach ($sxe->description->$name as $value) {
$val[] = str_replace(array('[[em]]', '[[/em]]'), array('<em>', '</em>'), (string) $value); $val[] = str_replace(array('[[em]]', '[[/em]]'), array('<em>', '</em>'), (string) $value);

View File

@@ -778,9 +778,7 @@ class setup
public static function rollback(connection_pdo $conn, connection_pdo $connbas = null) public static function rollback(connection_pdo $conn, connection_pdo $connbas = null)
{ {
$structure = simplexml_load_file(__DIR__ . "/../../lib/conf.d/bases_structure.xml"); if (false === $structure = simplexml_load_file(__DIR__ . "/../../lib/conf.d/bases_structure.xml")) {
if (!$structure) {
throw new Exception('Unable to load schema'); throw new Exception('Unable to load schema');
} }

View File

@@ -227,7 +227,7 @@ abstract class task_abstract
*/ */
public function setSettings($settings) public function setSettings($settings)
{ {
if (@simplexml_load_string($settings) === FALSE) { if (false === $sxe = simplexml_load_string($settings)) {
throw new Exception_InvalidArgument('Bad XML'); throw new Exception_InvalidArgument('Bad XML');
} }
@@ -240,7 +240,7 @@ abstract class task_abstract
$this->settings = $settings; $this->settings = $settings;
$this->loadSettings(simplexml_load_string($settings)); $this->loadSettings($sxe);
return $this; return $this;
} }
@@ -360,8 +360,8 @@ abstract class task_abstract
$this->completed_percentage = (int) $row['completed']; $this->completed_percentage = (int) $row['completed'];
$this->settings = $row['settings']; $this->settings = $row['settings'];
$sx = @simplexml_load_string($this->settings); $sx = simplexml_load_string($this->settings);
if ($sx) { if ($sx !== false) {
$this->loadSettings($sx); $this->loadSettings($sx);
} }
} }

View File

@@ -95,8 +95,7 @@ class task_period_RecordMover extends task_appboxAbstract
*/ */
public function xml2graphic($xml, $form) public function xml2graphic($xml, $form)
{ {
if (($sxml = simplexml_load_string($xml))) { // in fact XML IS always valid here... if (false !== $sxml = simplexml_load_string($xml)) {
// ... but we could check for safe values
if ((int) ($sxml->period) < 10) if ((int) ($sxml->period) < 10)
$sxml->period = 10; $sxml->period = 10;
elseif ((int) ($sxml->period) > 1440) // 1 jour elseif ((int) ($sxml->period) > 1440) // 1 jour
@@ -336,8 +335,8 @@ class task_period_RecordMover extends task_appboxAbstract
protected function retrieveContent(appbox $appbox) protected function retrieveContent(appbox $appbox)
{ {
$this->maxrecs = 1000; $this->maxrecs = 1000;
$this->sxTaskSettings = @simplexml_load_string($this->getSettings()); $this->sxTaskSettings = simplexml_load_string($this->getSettings());
if ( ! $this->sxTaskSettings || !$this->sxTaskSettings->tasks) { if (false === $this->sxTaskSettings || !$this->sxTaskSettings->tasks) {
return array(); return array();
} }

View File

@@ -144,8 +144,7 @@ class task_period_archive extends task_abstract
*/ */
public function xml2graphic($xml, $form) public function xml2graphic($xml, $form)
{ {
// XML should always be valid here... if (false !== $sxml = simplexml_load_string($xml)) {
if ( ($sxml = simplexml_load_string($xml)) ) {
// sanitize values // sanitize values
if ((int) ($sxml->period) < 10) { if ((int) ($sxml->period) < 10) {
$sxml->period = 10; $sxml->period = 10;
@@ -298,7 +297,7 @@ class task_period_archive extends task_abstract
$this->period = 60; $this->period = 60;
$this->cold = 30; $this->cold = 30;
if ( ($this->sxBasePrefs = simplexml_load_string($collection->get_prefs())) ) { if (false !== $this->sxBasePrefs = @simplexml_load_string($collection->get_prefs())) {
$this->sxBasePrefs["id"] = $base_id; $this->sxBasePrefs["id"] = $base_id;
$this->period = (int) ($this->sxTaskSettings->period); $this->period = (int) ($this->sxTaskSettings->period);
@@ -397,7 +396,7 @@ class task_period_archive extends task_abstract
$this->setLastExecTime(); $this->setLastExecTime();
try { try {
if ( !($this->sxTaskSettings = @simplexml_load_string($this->getSettings())) ) { if (false === $this->sxTaskSettings = simplexml_load_string($this->getSettings())) {
throw new Exception(sprintf('Error fetching or reading settings of the task \'%d\'', $this->getID())); throw new Exception(sprintf('Error fetching or reading settings of the task \'%d\'', $this->getID()));
} else { } else {
// copy settings to task, so it's easier to get later // copy settings to task, so it's easier to get later
@@ -693,7 +692,7 @@ class task_period_archive extends task_abstract
try { try {
$listFolder = new CListFolder($path); $listFolder = new CListFolder($path);
if ( ($sxDotPhrasea = @simplexml_load_file($path . '/.phrasea.xml')) ) { if (false !== $sxDotPhrasea = @simplexml_load_file($path . '/.phrasea.xml')) {
// test for magic file // test for magic file
if (($magicfile = trim((string) ($sxDotPhrasea->magicfile))) != '') { if (($magicfile = trim((string) ($sxDotPhrasea->magicfile))) != '') {
@@ -800,7 +799,7 @@ class task_period_archive extends task_abstract
$xp = new DOMXPath($dom); $xp = new DOMXPath($dom);
if ( ($sxDotPhrasea = @simplexml_load_file($path . '/.phrasea.xml')) ) { if (false !== $sxDotPhrasea = @simplexml_load_file($path . '/.phrasea.xml')) {
// test magicfile // test magicfile
if (($magicfile = trim((string) ($sxDotPhrasea->magicfile))) != '') { if (($magicfile = trim((string) ($sxDotPhrasea->magicfile))) != '') {
@@ -1576,7 +1575,7 @@ class task_period_archive extends task_abstract
// a .grouping.xml must stay in place // a .grouping.xml must stay in place
// -- don't do, done in phase4 // -- don't do, done in phase4
$sxGrouping = simplexml_load_file($groupingFile); $sxGrouping = @simplexml_load_file($groupingFile);
$grp_rid = $sxGrouping['grouping']; $grp_rid = $sxGrouping['grouping'];
$this->archiveFilesToGrp($dom, $node, $path . '/' . $grpFolder $this->archiveFilesToGrp($dom, $node, $path . '/' . $grpFolder
@@ -1628,7 +1627,7 @@ class task_period_archive extends task_abstract
if ($captionFile !== null && true === $this->filesystem->exists($captionFile)) { if ($captionFile !== null && true === $this->filesystem->exists($captionFile)) {
$caption = $this->readXMLForDatabox($metadatasStructure, $captionFile); $caption = $this->readXMLForDatabox($metadatasStructure, $captionFile);
$captionStatus = $this->parseStatusBit(simplexml_load_file($captionFile)); $captionStatus = $this->parseStatusBit(@simplexml_load_file($captionFile));
if ($captionStatus) { if ($captionStatus) {
$status = databox_status::operation_or($status, $captionStatus); $status = databox_status::operation_or($status, $captionStatus);
@@ -1694,7 +1693,7 @@ class task_period_archive extends task_abstract
if ($captionFile !== null && true === $this->filesystem->exists($captionFile)) { if ($captionFile !== null && true === $this->filesystem->exists($captionFile)) {
$caption = $this->readXMLForDatabox($metadatasStructure, $captionFile); $caption = $this->readXMLForDatabox($metadatasStructure, $captionFile);
$captionStatus = $this->parseStatusBit(simplexml_load_file($captionFile)); $captionStatus = $this->parseStatusBit(@simplexml_load_file($captionFile));
if ($captionStatus) { if ($captionStatus) {
$status = databox_status::operation_or($status, $captionStatus); $status = databox_status::operation_or($status, $captionStatus);
@@ -2200,9 +2199,7 @@ class task_period_archive extends task_abstract
throw new \InvalidArgumentException(sprintf('file %s does not exists', $pathfile)); throw new \InvalidArgumentException(sprintf('file %s does not exists', $pathfile));
} }
$sxcaption = @simplexml_load_file($pathfile); if (false === $sxcaption = @simplexml_load_file($pathfile)) {
if ( ! $sxcaption) {
throw new \InvalidArgumentException(sprintf('Invalid XML file %s', $pathfile)); throw new \InvalidArgumentException(sprintf('Invalid XML file %s', $pathfile));
} }
@@ -2252,15 +2249,17 @@ class task_period_archive extends task_abstract
* @param \SimpleXMLElement $sxcaption The SimpleXML related to the XML * @param \SimpleXMLElement $sxcaption The SimpleXML related to the XML
* @return string * @return string
*/ */
protected function parseStatusBit(\SimpleXMLElement $sxcaption) protected function parseStatusBit($sxcaption)
{ {
$statBit = null; if (!$sxcaption instanceof SimpleXMLElement) {
return null;
if ('' !== $inStatus = (string) $sxcaption->status) {
$statBit = $inStatus;
} }
return $statBit; if ('' !== $inStatus = (string) $sxcaption->status) {
return $inStatus;
}
return null;
} }
} }

View File

@@ -168,7 +168,7 @@ class task_period_cindexer extends task_abstract
*/ */
public function xml2graphic($xml, $form) public function xml2graphic($xml, $form)
{ {
if (($sxml = simplexml_load_string($xml)) != FALSE) { // in fact XML IS always valid here... if (false !== $sxml = simplexml_load_string($xml)) {
?> ?>
<script type="text/javascript"> <script type="text/javascript">
<?php echo $form ?>.binpath.value = "<?php echo p4string::MakeString($sxml->binpath, "js", '"') ?>"; <?php echo $form ?>.binpath.value = "<?php echo p4string::MakeString($sxml->binpath, "js", '"') ?>";

View File

@@ -91,8 +91,7 @@ class task_period_ftp extends task_appboxAbstract
*/ */
public function xml2graphic($xml, $form) public function xml2graphic($xml, $form)
{ {
if (($sxml = simplexml_load_string($xml)) != FALSE) { // in fact XML IS always valid here... if (false !== $sxml = simplexml_load_string($xml)) {
// ... but we could check for safe values (ex. 0 < period < 3600)
?> ?>
<script type="text/javascript"> <script type="text/javascript">
<?php echo $form ?>.proxy.value = "<?php echo p4string::MakeString($sxml->proxy, "js", '"') ?>"; <?php echo $form ?>.proxy.value = "<?php echo p4string::MakeString($sxml->proxy, "js", '"') ?>";

View File

@@ -80,8 +80,7 @@ class task_period_ftpPull extends task_appboxAbstract
public function xml2graphic($xml, $form) public function xml2graphic($xml, $form)
{ {
if (($sxml = simplexml_load_string($xml)) != FALSE) { // in fact XML IS always valid here... if (false !== $sxml = simplexml_load_string($xml)) {
// ... but we could check for safe values (ex. 0 < period < 3600)
?> ?>
<script type="text/javascript"> <script type="text/javascript">
<?php echo $form ?>.proxy.value = "<?php echo p4string::MakeString($sxml->proxy, "js", '"') ?>"; <?php echo $form ?>.proxy.value = "<?php echo p4string::MakeString($sxml->proxy, "js", '"') ?>";

View File

@@ -106,8 +106,7 @@ class task_period_outofdate extends task_abstract
// ==================================================================== // ====================================================================
public function xml2graphic($xml, $form) public function xml2graphic($xml, $form)
{ {
if (($sxml = simplexml_load_string($xml)) != FALSE) { // in fact XML IS always valid here... if (false !== $sxml = simplexml_load_string($xml)) {
// ... but we could check for safe values
if ((int) ($sxml->period) < 10) { if ((int) ($sxml->period) < 10) {
$sxml->period = 10; $sxml->period = 10;
} elseif ((int) ($sxml->period) > 1440) { // 1 jour } elseif ((int) ($sxml->period) > 1440) { // 1 jour
@@ -492,7 +491,7 @@ class task_period_outofdate extends task_abstract
$ret = self::STATUS_STOPPED; $ret = self::STATUS_STOPPED;
$this->running = false; $this->running = false;
} else { } else {
if (($this->sxTaskSettings = simplexml_load_string($row['settings'])) != FALSE) { if (false !== $this->sxTaskSettings = simplexml_load_string($row['settings'])) {
$period = (int) ($this->sxTaskSettings->period); $period = (int) ($this->sxTaskSettings->period);
if ($period <= 0 || $period >= 24 * 60) { if ($period <= 0 || $period >= 24 * 60) {
$period = 60; $period = 60;

View File

@@ -108,7 +108,7 @@ class task_period_subdef extends task_databoxAbstract
*/ */
public function xml2graphic($xml, $form) public function xml2graphic($xml, $form)
{ {
if (($sxml = simplexml_load_string($xml)) != FALSE) { if (false !== $sxml = simplexml_load_string($xml)) {
if ((int) ($sxml->period) < 10) { if ((int) ($sxml->period) < 10) {
$sxml->period = 10; $sxml->period = 10;
} elseif ((int) ($sxml->period) > 300) { } elseif ((int) ($sxml->period) > 300) {

View File

@@ -79,8 +79,7 @@ class task_period_workflow01 extends task_databoxAbstract
public function xml2graphic($xml, $form) public function xml2graphic($xml, $form)
{ {
if (($sxml = simplexml_load_string($xml)) != FALSE) { // in fact XML IS always valid here... if (false !== $sxml = simplexml_load_string($xml)) {
// ... but we could check for safe values
if ((int) ($sxml->period) < 1) { if ((int) ($sxml->period) < 1) {
$sxml->period = 1; $sxml->period = 1;
} elseif ((int) ($sxml->period) > 1440) { // 1 jour } elseif ((int) ($sxml->period) > 1440) { // 1 jour

View File

@@ -87,8 +87,7 @@ class task_period_writemeta extends task_databoxAbstract
public function xml2graphic($xml, $form) public function xml2graphic($xml, $form)
{ {
if (($sxml = simplexml_load_string($xml)) != FALSE) { // in fact XML IS always valid here... if (false !== $sxml = simplexml_load_string($xml)) {
// ... but we could check for safe values (ex. 0 < period < 3600)
if ((int) ($sxml->period) < 10) { if ((int) ($sxml->period) < 10) {
$sxml->period = 10; $sxml->period = 10;
} elseif ((int) ($sxml->period) > 300) { } elseif ((int) ($sxml->period) > 300) {