Fakoli Framework
StringTypeRenderer Class Reference
+ Inheritance diagram for StringTypeRenderer:
+ Collaboration diagram for StringTypeRenderer:

Public Member Functions

 StringTypeRenderer ()
 
- Public Member Functions inherited from AbstractTypeRenderer
 AbstractTypeRenderer ()
 

Static Public Member Functions

static format ($value, $template="")
 
static phone ($phone)
 
- Static Public Member Functions inherited from AbstractTypeRenderer
static format ($value, $template="")
 
static translationDateTemplate ($template, $includeTime=true)
 

Detailed Description

Definition at line 37 of file string_type_renderer.inc.

Member Function Documentation

◆ format()

static StringTypeRenderer::format (   $value,
  $template = "" 
)
static

Definition at line 43 of file string_type_renderer.inc.

44  {
45  if (!$template) return $value;
46 
47  if ($template[0] == '/')
48  {
49  $clauses = array();
50  if (preg_match("/(\\/.*?\\/)(.*?)\\//", $template, $clauses))
51  {
52  return preg_replace($clauses[1], $clauses[2], $value);
53  }
54  }
55 
56  if ($template[0] == '|')
57  {
58  $clauses = array();
59  if (preg_match("/(|.*?|)(.*?)|/", $template, $clauses))
60  {
61  return preg_replace($clauses[1], $clauses[2], $value);
62  }
63  }
64 
65  switch($template)
66  {
67  case "codify":
68  return codify($value);
69 
70  case "prettify":
71  return prettify($value);
72 
73  case "upper":
74  return strtoupper($value);
75 
76  case "lower":
77  return strtolower($value);
78 
79  case "ucfirst":
80  return ucfirst($value);
81 
82  case "lcfirst":
83  return lcfirst($value);
84 
85  case "ucwords":
86  return ucwords(strtolower($value));
87 
88  case "stripHTML":
89  return stripHTML($value);
90 
91  case "jsSafe":
92  return jsSafe($value);
93 
94  case "html":
95  return formatAsHTML($value);
96 
97  case "xml":
98  return xmlEntities($value);
99 
100  case "xmlSafe":
101  return xmlEntities(stripHTML($value));
102 
103  case "url":
104  return urlencode($value);
105 
106  case "phone":
107  return StringTypeRenderer::phone($value);
108 
109  case "firstSentence":
110  return firstSentence($value);
111 
112  default:
113 
114  if (is_numeric($template))
115  {
116  return ellipsis(stripHTML($value), $template, true);
117  }
118  else if (strpos($template, "|") !== false)
119  {
120  $options = explode("|", $template);
121  return $value ? $options[0] : $options[1];
122  }
123  }
124 
125  return $value;
126  }
ellipsis($txt, $max, $wholeWord=false)
Truncate the supplied text at the given maximum length.
Definition: functions.inc:706
formatAsHTML($text)
Takes a string and formats it for display as HTML, removing any HTML tags it contains, and converting carriage returns to br tags.
Definition: functions.inc:1405
xmlEntities($string)
Function to provide html to XML entity renaming.
Definition: functions.inc:1842
firstSentence($text)
Returns the first sentence of the supplied text.
Definition: functions.inc:801
prettify($name)
Takes a variable or field name and converts it into a human-readable version (assuming that the origi...
Definition: functions.inc:1362
codify($name)
Takes a text string and converts it into a code-compliant format, suitable for use as a variable name...
Definition: functions.inc:1348
stripHTML($text)
Definition: functions.inc:809
jsSafe($str, $escapeEntities=false)
Utility function to escape a string correctly for use in a Javascript client-side call...
Definition: functions.inc:434

◆ phone()

static StringTypeRenderer::phone (   $phone)
static

Definition at line 138 of file string_type_renderer.inc.

139  {
140  $phone = preg_replace("/[^0-9]/", "", $phone);
141 
142  if(strlen($phone) == 7)
143  return preg_replace("/([0-9]{3})([0-9]{4})/", "$1-$2", $phone);
144  elseif(strlen($phone) == 10)
145  return preg_replace("/([0-9]{3})([0-9]{3})([0-9]{4})/", "($1) $2-$3", $phone);
146  else
147  return $phone;
148  }

◆ StringTypeRenderer()

StringTypeRenderer::StringTypeRenderer ( )

Definition at line 39 of file string_type_renderer.inc.

40  {
41  }

The documentation for this class was generated from the following file: