Exemple #1
0
 /**
  * Gets an article id from the given article path
  *
  * @param string $path
  *
  * @return integer the database identifier corresponding to the given
  *                  article path or null if no such identifier exists.
  */
 protected function getArticleId($path)
 {
     // don't try to find articles with invalid UTF-8 in the path
     if (!SwatString::validateUtf8($path)) {
         require_once 'Site/exceptions/SitePathInvalidUtf8Exception.php';
         throw new SitePathInvalidUtf8Exception(sprintf('Path is not valid UTF-8: ‘%s’', SwatString::escapeBinary($path)), 0, $path);
     }
     // don't try to find articles with more than 254 characters in the path
     if (strlen($path) > 254) {
         require_once 'Site/exceptions/SitePathTooLongException.php';
         throw new SitePathTooLongException(sprintf('Path is too long: ‘%s’', $path));
     }
     $instance_id = $this->app->getInstanceId();
     return SwatDB::executeStoredProcOne($this->app->db, 'findArticle', array($this->app->db->quote($path, 'text'), $this->app->db->quote($instance_id, 'integer')));
 }
Exemple #2
0
 /**
  * Normalizes filenames in ZIP archives to UTF-8 encoding
  *
  * The ZIP file specification specifies that filenames are encoded using
  * IBM Code Page 437. In 2008, an addition to the specification was made to
  * also allow UTF-8 encoded filenames. This method checks if the filename
  * is UTF-8 and if not, converts from IBM Code Page 437 to UTF-8.
  *
  * @param string $filename
  *
  * @return string
  */
 protected static function normalizeArchiveFileFilename($filename)
 {
     // if not UTF-8, convert from IBM CP 437
     if (!SwatString::validateUtf8($filename)) {
         $filename = iconv('CP437', 'UTF-8', $filename);
     }
     return $filename;
 }