Framework  3.9
text_type_renderer.inc
Go to the documentation of this file.
1 <?php
6 /**************************************************************
7 
8  Copyright (c) 2007-2010 Sonjara, Inc
9 
10  Permission is hereby granted, free of charge, to any person
11  obtaining a copy of this software and associated documentation
12  files (the "Software"), to deal in the Software without
13  restriction, including without limitation the rights to use,
14  copy, modify, merge, publish, distribute, sublicense, and/or sell
15  copies of the Software, and to permit persons to whom the
16  Software is furnished to do so, subject to the following
17  conditions:
18 
19  The above copyright notice and this permission notice shall be
20  included in all copies or substantial portions of the Software.
21 
22  Except as contained in this notice, the name(s) of the above
23  copyright holders shall not be used in advertising or otherwise
24  to promote the sale, use or other dealings in this Software
25  without prior written authorization.
26 
27  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
28  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
29  OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
30  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
31  HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
32  WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
33  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
34  OTHER DEALINGS IN THE SOFTWARE.
35 
36 *****************************************************************/
37 
38 require_once realpath(dirname(__FILE__)."/abstract_type_renderer.inc");
39 
41 {
42  function TextTypeRenderer()
43  {
44  }
45 
46  static function format($value, $template = "")
47  {
48  if (!$template) return $value;
49 
50 
51  if ($template[0] == '/')
52  {
53  $clauses = array();
54  if (preg_match("/(\\/.*?\\/)(.*?)\\//", $template, $clauses))
55  {
56  return preg_replace($clauses[1], $clauses[2], $value);
57  }
58  }
59 
60  if ($template[0] == '|')
61  {
62  $clauses = array();
63  if (preg_match("/(|.*?|)(.*?)|/", $template, $clauses))
64  {
65  return preg_replace($clauses[1], $clauses[2], $value);
66  }
67  }
68 
69  switch($template)
70  {
71  case "codify":
72  return codify($value);
73 
74  case "prettify":
75  return prettify($value);
76 
77  case "upper":
78  return strtoupper($value);
79 
80  case "lower":
81  return strtolower($value);
82 
83  case "ucfirst":
84  return ucfirst($value);
85 
86  case "lcfirst":
87  return lcfirst($value);
88 
89  case "ucwords":
90  return ucwords(strtolower($value));
91 
92  case "stripHTML":
93  return stripHTML($value);
94 
95  case "jsSafe":
96  return jsSafe($value);
97 
98  case "html":
99  return formatAsHTML($value);
100 
101  case "htmlSafe":
102  return htmlsafe($value);
103 
104  case "HTML":
105  return formatAsHtml($value);
106 
107  case "xml":
108  return xmlEntities($value);
109 
110  case "xmlSafe":
111  return xmlEntities(stripHTML($value));
112 
113  case "firstSentence":
114  return firstSentence($value);
115 
116  default:
117 
118  if (is_numeric($template))
119  {
120  return ellipsis(stripHTML($value), $template, true);
121  }
122  }
123 
124  return $value;
125  }
126 }
127 
static format($value, $template="")
codify($name)
Takes a text string and converts it into a code-compliant format, suitable for use as a variable name...
Definition: functions.inc:1399
xmlEntities($string)
Function to provide html to XML entity renaming.
Definition: functions.inc:1903
stripHTML($text)
Definition: functions.inc:847
firstSentence($text)
Returns the first sentence of the supplied text.
Definition: functions.inc:839
jsSafe($str, $escapeEntities=false)
Utility function to escape a string correctly for use in a Javascript client-side call.
Definition: functions.inc:434
formatAsHTML($text)
Takes a string and formats it for display as HTML, removing any HTML tags it contains,...
Definition: functions.inc:1456
ellipsis($txt, $max, $wholeWord=false)
Truncate the supplied text at the given maximum length.
Definition: functions.inc:779
prettify($name)
Takes a variable or field name and converts it into a human-readable version (assuming that the origi...
Definition: functions.inc:1413
htmlsafe($str)
Definition: functions.inc:451