[TASK] CGL Cleanup: Fix OpeningFunctionBraceKernighanRitchie-Sniff
[Packages/TYPO3.CMS.git] / typo3 / sysext / statictemplates / media / scripts / example_callfunction.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 1999-2011 Kasper Skårhøj (kasperYYYY@typo3.com)
6 * All rights reserved
7 *
8 * This script is part of the TYPO3 project. The TYPO3 project is
9 * free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * The GNU General Public License can be found at
15 * http://www.gnu.org/copyleft/gpl.html.
16 * A copy is found in the textfile GPL.txt and important notices to the license
17 * from the author is found in LICENSE.txt distributed with these scripts.
18 *
19 *
20 * This script is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
24 *
25 * This copyright notice MUST APPEAR in all copies of the script!
26 ***************************************************************/
27 /**
28 * USER cObject EXAMPLE FILE
29 *
30 * This is an example of how to use your own functions and classes
31 * directly from TYPO3.
32 * Used in the "testsite" package
33 *
34 * Revised for TYPO3 3.6 June/2003 by Kasper Skårhøj
35 * XHTML compliant
36 *
37 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
38 */
39 /**
40 * Call custom function from TypoScript for data processing
41 *
42 * Example can be found in the testsite package at the page-path
43 * "/Intro/TypoScript examples/Custom Dynamic Co.../Passing a string.../"
44 * This TypoScript configuration will also demonstrate it:
45 *
46 * includeLibs.something = media/scripts/example_callfunction.php
47 * page = PAGE
48 * page.10 = TEXT
49 * page.10 {
50 * value = Hello World
51 * preUserFunc = user_reverseString
52 * preUserFunc.uppercase = 1
53 * }
54 *
55 * @param string $content When custom functions are used for data processing the $content variable will hold the value to be processed. When functions are meant to just return some generated content this variable is empty.
56 * @param array $conf TypoScript properties passed on to this function.
57 * @return string The input string reversed. If the TypoScript property "uppercase" was set it will also be in uppercase.
58 */
59 function user_reverseString($content, $conf) {
60 $content = strrev($content);
61 if ($conf['uppercase']) {
62 $content = strtoupper($content);
63 }
64 return $content;
65 }
66 /**
67 * Simply outputting the current time in red letters.
68 *
69 * Example can be found in the testsite package at the page-path "/Intro/TypoScript examples/Custom Dynamic Co.../Mixing cached and.../"
70 * This TypoScript configuration will also demonstrate it:
71 *
72 * includeLibs.something = media/scripts/example_callfunction.php
73 * page = PAGE
74 * page.10 = USER_INT
75 * page.10 {
76 * userFunc = user_printTime
77 * }
78 *
79 * @param string $content Empty string (no content to process)
80 * @param array $conf TypoScript configuration
81 * @return string HTML output, showing the current server time.
82 */
83 function user_printTime($content, $conf) {
84 return '<font color="red">Dynamic time: ' . date('H:i:s') . '</font><br />';
85 }
86 /**
87 * Example of calling a method in a PHP class from TypoScript
88 */
89 class user_various {
90
91 // Reference to the parent (calling) cObj set from TypoScript
92 /**
93 * @todo Define visibility
94 */
95 public $cObj;
96
97 /**
98 * Doing the same as user_reverseString() but with a class. Also demonstrates how this gives us the ability to use methods in the parent object.
99 *
100 * @param string $content String to process (from stdWrap)
101 * @param array $conf TypoScript properties passed on to this method.
102 * @return string The input string reversed. If the TypoScript property "uppercase" was set it will also be in uppercase. May also be linked.
103 * @see user_reverseString()
104 * @todo Define visibility
105 */
106 public function reverseString($content, $conf) {
107 $content = strrev($content);
108 if ($conf['uppercase']) {
109 $content = $this->cObj->caseshift($content, 'upper');
110 }
111 if ($conf['typolink']) {
112 $content = $this->cObj->getTypoLink($content, $conf['typolink']);
113 }
114 return $content;
115 }
116
117 /**
118 * Testing USER cObject:
119 *
120 * Example can be found in the testsite package at the page-path "/Intro/TypoScript examples/Custom Dynamic Co.../Calling a method.../"
121 * This TypoScript configuration will also demonstrate it:
122 *
123 * includeLibs.something = media/scripts/example_callfunction.php
124 * page = PAGE
125 * page.30 = USER
126 * page.30 {
127 * userFunc = user_various->listContentRecordsOnPage
128 * reverseOrder = 1
129 * }
130 *
131 * @param string $content Empty string (no content to process)
132 * @param array $conf TypoScript configuration
133 * @return string HTML output, showing content elements (in reverse order if configured.)
134 * @todo Define visibility
135 */
136 public function listContentRecordsOnPage($content, $conf) {
137 $query = $GLOBALS['TYPO3_DB']->SELECTquery('header', 'tt_content', 'pid=' . intval($GLOBALS['TSFE']->id) . $this->cObj->enableFields('tt_content'), '', 'sorting' . ($conf['reverseOrder'] ? ' DESC' : ''));
138 $output = 'This is the query: <strong>' . $query . '</strong><br /><br />';
139 return $output . $this->selectThem($query);
140 }
141
142 /**
143 * Selecting the records by input $query and returning the header field values
144 *
145 * @param string $query SQL query selecting the content elements.
146 * @return string The header field values of the content elements imploded by a <br /> tag
147 * @access private
148 * @todo Define visibility
149 */
150 public function selectThem($query) {
151 $res = $GLOBALS['TYPO3_DB']->sql_query($query);
152 $output = array();
153 while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
154 $output[] = $row['header'];
155 }
156 return implode($output, '<br />');
157 }
158
159 }
160
161 ?>