/** * Validation des éléments pour la création d'un sitemap * @param null $loc * @param null $lastmod * @param null $changefreq * @param null $priority * @return bool * @throws Exception */ protected function validElement($loc = null, $lastmod = null, $changefreq = null, $priority = null) { if (form_inputFilter::isURL($loc) == false) { throw new Exception('Loc is invalid format'); } if ($lastmod && !date_dateformat::isW3CValid($lastmod)) { throw new Exception('Invalid format for lastmod'); } if ($changefreq && !in_array($changefreq, $this->changeFreqControl)) { throw new Exception('Invalid format for changefreq'); } if ($priority && (!form_inputFilter::isNumeric($priority) || $priority < 0 || $priority > 1)) { throw new Exception('Invalid format for priority 0.0 > 1.0'); } elseif ($priority) { $priority = sprintf('%0.1f', $priority); } return true; }
/** * Ecriture des noeuds du sitemap XML * @param array $setConfig */ public function writeNode($setConfig = array('type' => 'child', 'loc' => '', 'image' => false, 'lastmod' => '', 'changefreq' => '', 'priority' => '')) { if (is_array($setConfig)) { if (array_key_exists($setConfig, 'loc')) { $loc = $setConfig['loc']; } else { $loc = ''; } if (array_key_exists($setConfig, 'lastmod')) { $lastmod = $setConfig['lastmod']; } else { $lastmod = ''; } if (array_key_exists($setConfig, 'changefreq')) { $changefreq = $setConfig['changefreq']; } else { $changefreq = ''; } if (array_key_exists($setConfig, 'priority')) { $priority = $setConfig['priority']; } else { $priority = ''; } switch ($setConfig['type']) { case 'parent': $this->xmlWriter()->startElement('sitemap'); // [2] Second Node $this->xmlWriter()->writeElement('loc', form_inputFilter::isURL($loc)); $this->xmlWriter()->writeElement('lastmod', date_dateformat::isW3CValid($lastmod)); $this->xmlWriter()->endElement(); break; case 'child': $this->xmlWriter()->startElement('url'); // [2] Second Node $this->xmlWriter()->writeElement('loc', form_inputFilter::isURL($loc)); $this->xmlWriter()->writeElement('lastmod', date_dateformat::isW3CValid($lastmod)); $this->xmlWriter()->writeElement('changefreq', $changefreq); $this->xmlWriter()->writeElement('priority', $priority); $this->xmlWriter()->endElement(); break; case 'image': $this->xmlWriter()->startElement('url'); // [2] Second Node $this->xmlWriter()->writeElement('loc', form_inputFilter::isURL($loc)); if (array_key_exists($setConfig, 'image')) { if ($setConfig['image'] != '' and $setConfig['image'] != false and is_array($setConfig['image'])) { if (is_array($setConfig['image']['forimage'])) { foreach ($setConfig['image']['forimage'] as $img) { if ($setConfig['image']['imageloc'] != NULL) { $this->xmlWriter()->startElement('image:image'); // [2] Second Node $this->xmlWriter()->writeElement('image:loc', form_inputFilter::isURL($setConfig['image']['url'] . $setConfig['image']['imageloc'])); $this->xmlWriter()->endElement(); } } } } } break; } } }