adding system check for address parsing
[civicrm-core.git] / CRM / Utils / ICalendar.php
index d765b80f8482f45b123774a744206444083de226..bfec1e37b48838d4078aa61388b842f59949c7be 100644 (file)
@@ -3,7 +3,7 @@
  +--------------------------------------------------------------------+
  | CiviCRM version 4.7                                                |
  +--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2016                                |
+ | Copyright CiviCRM LLC (c) 2004-2017                                |
  +--------------------------------------------------------------------+
  | This file is a part of CiviCRM.                                    |
  |                                                                    |
@@ -28,7 +28,7 @@
 /**
  *
  * @package CRM
- * @copyright CiviCRM LLC (c) 2004-2016
+ * @copyright CiviCRM LLC (c) 2004-2017
  */
 
 /**
@@ -42,23 +42,38 @@ class CRM_Utils_ICalendar {
   /**
    * Escape text elements for safe ICalendar use.
    *
-   * @param $text
+   * @param string $text
    *   Text to escape.
    *
    * @return string
-   *   Escaped text
    */
   public static function formatText($text) {
     $text = strip_tags($text);
-    $text = str_replace("\"", "DQUOTE", $text);
     $text = str_replace("\\", "\\\\", $text);
-    $text = str_replace(",", "\,", $text);
-    $text = str_replace(";", "\;", $text);
+    $text = str_replace(',', '\,', $text);
+    $text = str_replace(';', '\;', $text);
     $text = str_replace(array("\r\n", "\n", "\r"), "\\n ", $text);
     $text = implode("\n ", str_split($text, 50));
     return $text;
   }
 
+  /**
+   * Restore iCal formatted text to normal.
+   *
+   * @param string $text
+   *   Text to unescape.
+   *
+   * @return string
+   */
+  public static function unformatText($text) {
+    $text = str_replace('\n ', "\n", $text);
+    $text = str_replace('\;', ';', $text);
+    $text = str_replace('\,', ',', $text);
+    $text = str_replace("\\\\", "\\", $text);
+    $text = str_replace("DQUOTE", "\"", $text);
+    return $text;
+  }
+
   /**
    * Escape date elements for safe ICalendar use.
    *