Example #1
0
 /**
  * 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;
 }
Example #2
0
 /**
  * Enregistre $row dans le fichier log déterminé à partir des paramètres $type, $name et $archive
  *
  * @param string $type Dossier dans lequel sera enregistré le fichier de log
  * @param string $name Nom du fichier de log
  * @param string $row Texte à ajouter au fichier de log
  * @param string $archive Archive : LOG_VOID, LOG_MONTH ou LOG_YEAR
  *
  * @return bool
  */
 public function log($type, $name, $row, $archive = self::LOG_YEAR)
 {
     /**
      * Instance dateformat
      */
     $date = new date_dateformat();
     # Contrôle des arguments
     if (!isset($type) || empty($name) || empty($row)) {
         trigger_error("Params is not defined", E_USER_WARNING);
         return false;
     }
     $logfile = $this->path($type, $name, $archive);
     if ($logfile === false) {
         trigger_error("Unable to save the log", E_USER_WARNING);
         return false;
     }
     # Ajout de la date et de l'heure au début de la ligne
     $row = $date->dateDefine('d/m/Y H:i:s') . ' ' . $row;
     # Ajout du retour chariot de fin de ligne si il n'y en a pas
     if (!preg_match('#\\n$#', $row)) {
         $row .= "\n";
     }
     $this->write($logfile, $row);
     # Firephp
     $firephp = new debug_firephp();
     if ($firephp instanceof debug_firephp) {
         $firephp->error($row);
     }
 }
Example #3
0
 /**
  * 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;
         }
     }
 }